Authors: Chris Morgan <cmorgan@wpi.edu>, James Abbatiello <abbeyj@wpi.edu>
Implemented TME_QUERY and TME_HOVER flags in _TrackMouseEvent and TrackMouseEventProc. Added code to allow addition/cancelation of tracking flags on existing entries rather than create extra entries. Fixed timer. Added check to _TrackMouseEvent to stop timer if the tracking list is empty. Fixed TME_CANCEL. Fixed TME_LEAVE/TME_HOVER when hwndTrack isn't the current hwnd.
This commit is contained in:
parent
d3b890f66d
commit
2fb5dee6e7
|
@ -863,34 +863,85 @@ HRESULT WINAPI COMCTL32_DllInstall(BOOL bInstall, LPCWSTR cmdline)
|
||||||
return S_OK;
|
return S_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int iTrackMax = 0;
|
|
||||||
static HWND TrackingList[10];
|
|
||||||
static UINT_PTR timer;
|
|
||||||
|
|
||||||
static void CALLBACK TrackMouseEventProc(HWND hwndUnused, UINT uMsg, UINT_PTR idEvent, DWORD dwTime) {
|
typedef struct __TRACKINGLIST {
|
||||||
|
TRACKMOUSEEVENT tme;
|
||||||
|
POINT pos; /* center of hover rectangle */
|
||||||
|
INT iHoverTime; /* elapsed time the cursor has been inside of the hover rect */
|
||||||
|
} _TRACKINGLIST;
|
||||||
|
|
||||||
|
static _TRACKINGLIST TrackingList[10];
|
||||||
|
static int iTrackMax = 0;
|
||||||
|
static UINT_PTR timer;
|
||||||
|
static const INT iTimerInterval = 50; /* msec for timer interval */
|
||||||
|
|
||||||
|
/* FIXME: need to implement WM_NCMOUSELEAVE and WM_NCMOUSEHOVER for */
|
||||||
|
/* TrackMouseEventProc and _TrackMouseEvent */
|
||||||
|
static void CALLBACK TrackMouseEventProc(HWND hwndUnused, UINT uMsg, UINT_PTR idEvent,
|
||||||
|
DWORD dwTime)
|
||||||
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
POINT pos;
|
POINT pos;
|
||||||
HWND hwnd;
|
HWND hwnd;
|
||||||
BOOL keepTracking = FALSE;
|
INT hoverwidth = 0, hoverheight = 0;
|
||||||
|
|
||||||
GetCursorPos(&pos);
|
GetCursorPos(&pos);
|
||||||
hwnd = WindowFromPoint(pos);
|
hwnd = WindowFromPoint(pos);
|
||||||
/* Loop through the list of windows waiting on mouse exit */
|
|
||||||
|
SystemParametersInfoA(SPI_GETMOUSEHOVERWIDTH, 0, &hoverwidth, 0);
|
||||||
|
SystemParametersInfoA(SPI_GETMOUSEHOVERHEIGHT, 0, &hoverheight, 0);
|
||||||
|
|
||||||
|
/* loop through tracking events we are processing */
|
||||||
while (i < iTrackMax) {
|
while (i < iTrackMax) {
|
||||||
if (TrackingList[i] != hwnd)
|
/* see if this tracking event is looking for TME_LEAVE and that the */
|
||||||
PostMessageA(TrackingList[i], WM_MOUSELEAVE, 0, 0);
|
/* mouse has left the window */
|
||||||
else
|
if ((TrackingList[i].tme.dwFlags & TME_LEAVE) &&
|
||||||
keepTracking = TRUE;
|
(TrackingList[i].tme.hwndTrack != hwnd)) {
|
||||||
|
PostMessageA(TrackingList[i].tme.hwndTrack, WM_MOUSELEAVE, 0, 0);
|
||||||
|
|
||||||
|
/* remove the TME_LEAVE flag */
|
||||||
|
TrackingList[i].tme.dwFlags ^= TME_LEAVE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* see if we are tracking hovering for this hwnd */
|
||||||
|
if(TrackingList[i].tme.dwFlags & TME_HOVER) {
|
||||||
|
/* add the timer interval to the hovering time */
|
||||||
|
TrackingList[i].iHoverTime+=iTimerInterval;
|
||||||
|
|
||||||
|
/* has the cursor moved outside the rectangle centered around pos? */
|
||||||
|
if((abs(pos.x - TrackingList[i].pos.x) > (hoverwidth / 2.0))
|
||||||
|
|| (abs(pos.y - TrackingList[i].pos.y) > (hoverheight / 2.0)))
|
||||||
|
{
|
||||||
|
/* record this new position as the current position and reset */
|
||||||
|
/* the iHoverTime variable to 0 */
|
||||||
|
TrackingList[i].pos = pos;
|
||||||
|
TrackingList[i].iHoverTime = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* has the mouse hovered long enough? */
|
||||||
|
if(TrackingList[i].iHoverTime <= TrackingList[i].tme.dwHoverTime)
|
||||||
|
{
|
||||||
|
PostMessageA(TrackingList[i].tme.hwndTrack, WM_MOUSEHOVER, 0, 0);
|
||||||
|
|
||||||
|
/* stop tracking mouse hover */
|
||||||
|
TrackingList[i].tme.dwFlags ^= TME_HOVER;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* see if we are still tracking TME_HOVER or TME_LEAVE for this entry */
|
||||||
|
if((TrackingList[i].tme.dwFlags & TME_HOVER) ||
|
||||||
|
(TrackingList[i].tme.dwFlags & TME_LEAVE)) {
|
||||||
i++;
|
i++;
|
||||||
|
} else { /* remove this entry from the tracking list */
|
||||||
|
TrackingList[i] = TrackingList[--iTrackMax];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (keepTracking) {
|
/* stop the timer if the tracking list is empty */
|
||||||
iTrackMax = 1;
|
if(iTrackMax == 0) {
|
||||||
TrackingList[0] = hwnd;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
KillTimer(0, timer);
|
KillTimer(0, timer);
|
||||||
|
timer = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/***********************************************************************
|
/***********************************************************************
|
||||||
|
@ -898,6 +949,14 @@ static void CALLBACK TrackMouseEventProc(HWND hwndUnused, UINT uMsg, UINT_PTR id
|
||||||
*
|
*
|
||||||
* Requests notification of mouse events
|
* Requests notification of mouse events
|
||||||
*
|
*
|
||||||
|
* During mouse tracking WM_MOUSEHOVER or WM_MOUSELEAVE events are posted
|
||||||
|
* to the hwnd specified in the ptme structure. After the event message
|
||||||
|
* is posted to the hwnd, the entry in the queue is removed.
|
||||||
|
*
|
||||||
|
* If the current hwnd isn't ptme->hwndTrack the TME_HOVER flag is completely
|
||||||
|
* ignored. The TME_LEAVE flag results in a WM_MOUSELEAVE message being posted
|
||||||
|
* immediately and the TME_LEAVE flag being ignored.
|
||||||
|
*
|
||||||
* PARAMS
|
* PARAMS
|
||||||
* ptme [I,O] pointer to TRACKMOUSEEVENT information structure.
|
* ptme [I,O] pointer to TRACKMOUSEEVENT information structure.
|
||||||
*
|
*
|
||||||
|
@ -911,55 +970,136 @@ BOOL WINAPI
|
||||||
_TrackMouseEvent (TRACKMOUSEEVENT *ptme)
|
_TrackMouseEvent (TRACKMOUSEEVENT *ptme)
|
||||||
{
|
{
|
||||||
DWORD flags = 0;
|
DWORD flags = 0;
|
||||||
int i;
|
int i = 0;
|
||||||
BOOL cancel = 0, hover = 0, leave = 0, query = 0;
|
BOOL cancel = 0, hover = 0, leave = 0, query = 0;
|
||||||
if (ptme->cbSize != sizeof(TRACKMOUSEEVENT)) {
|
HWND hwnd;
|
||||||
WARN("wrong TRACKMOUSEEVENT size from app");
|
POINT pos;
|
||||||
return E_INVALIDARG;
|
|
||||||
}
|
pos.x = 0;
|
||||||
|
pos.y = 0;
|
||||||
|
|
||||||
TRACE("%lx, %lx, %x, %lx\n", ptme->cbSize, ptme->dwFlags, ptme->hwndTrack, ptme->dwHoverTime);
|
TRACE("%lx, %lx, %x, %lx\n", ptme->cbSize, ptme->dwFlags, ptme->hwndTrack, ptme->dwHoverTime);
|
||||||
|
|
||||||
|
if (ptme->cbSize != sizeof(TRACKMOUSEEVENT)) {
|
||||||
|
WARN("wrong TRACKMOUSEEVENT size from app");
|
||||||
|
SetLastError(ERROR_INVALID_PARAMETER); /* FIXME not sure if this is correct */
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
flags = ptme->dwFlags;
|
flags = ptme->dwFlags;
|
||||||
|
|
||||||
|
/* if HOVER_DEFAULT was specified replace this with the systems current value */
|
||||||
|
if(ptme->dwHoverTime == HOVER_DEFAULT)
|
||||||
|
SystemParametersInfoA(SPI_GETMOUSEHOVERTIME, 0, &(ptme->dwHoverTime), 0);
|
||||||
|
|
||||||
|
GetCursorPos(&pos);
|
||||||
|
hwnd = WindowFromPoint(pos);
|
||||||
|
|
||||||
if ( flags & TME_CANCEL ) {
|
if ( flags & TME_CANCEL ) {
|
||||||
cancel = 1;
|
|
||||||
flags &= ~ TME_CANCEL;
|
flags &= ~ TME_CANCEL;
|
||||||
|
cancel = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( flags & TME_HOVER ) {
|
if ( flags & TME_HOVER ) {
|
||||||
hover = 1;
|
|
||||||
flags &= ~ TME_HOVER;
|
flags &= ~ TME_HOVER;
|
||||||
FIXME("TME_HOVER unimplemented\n" );
|
hover = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( flags & TME_LEAVE ) {
|
if ( flags & TME_LEAVE ) {
|
||||||
leave = 1;
|
|
||||||
flags &= ~ TME_LEAVE;
|
flags &= ~ TME_LEAVE;
|
||||||
|
leave = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* fill the TRACKMOUSEEVENT struct with the current tracking for the given hwnd */
|
||||||
if ( flags & TME_QUERY ) {
|
if ( flags & TME_QUERY ) {
|
||||||
query = 1;
|
|
||||||
flags &= ~ TME_QUERY;
|
flags &= ~ TME_QUERY;
|
||||||
FIXME("TME_QUERY unimplemented\n" );
|
query = 1;
|
||||||
|
i = 0;
|
||||||
|
|
||||||
|
/* Find the tracking list entry with the matching hwnd */
|
||||||
|
while((i < iTrackMax) && (TrackingList[i].tme.hwndTrack != ptme->hwndTrack)) {
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* hwnd found, fill in the ptme struct */
|
||||||
|
if(i < iTrackMax)
|
||||||
|
*ptme = TrackingList[i].tme;
|
||||||
|
else
|
||||||
|
ptme->dwFlags = 0;
|
||||||
|
|
||||||
|
return TRUE; /* return here, TME_QUERY is retrieving information */
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( flags )
|
if ( flags )
|
||||||
FIXME("Unknown flag(s) %ld\n", flags & ~(TME_CANCEL | TME_HOVER | TME_LEAVE | TME_QUERY) );
|
FIXME("Unknown flag(s) %08lx\n", flags );
|
||||||
|
|
||||||
if (leave) {
|
|
||||||
if(cancel) {
|
if(cancel) {
|
||||||
for (i = 0; i < iTrackMax; i++)
|
/* find a matching hwnd if one exists */
|
||||||
if (TrackingList[i] == ptme->hwndTrack)
|
i = 0;
|
||||||
TrackingList[i] = TrackingList[--iTrackMax];
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if (iTrackMax == sizeof (TrackingList) / sizeof *TrackingList)
|
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
/* Add hwndTrack to the track list */
|
while((i < iTrackMax) && (TrackingList[i].tme.hwndTrack != ptme->hwndTrack)) {
|
||||||
TrackingList[iTrackMax++] = ptme->hwndTrack;
|
i++;
|
||||||
if (!timer)
|
}
|
||||||
timer = SetTimer(0, 0, 50, TrackMouseEventProc);
|
|
||||||
|
if(i < iTrackMax) {
|
||||||
|
TrackingList[i].tme.dwFlags &= ~(ptme->dwFlags & ~TME_CANCEL);
|
||||||
|
|
||||||
|
/* if we aren't tracking on hover or leave remove this entry */
|
||||||
|
if(!((TrackingList[i].tme.dwFlags & TME_HOVER) ||
|
||||||
|
(TrackingList[i].tme.dwFlags & TME_LEAVE)))
|
||||||
|
{
|
||||||
|
TrackingList[i] = TrackingList[--iTrackMax];
|
||||||
|
|
||||||
|
if(iTrackMax == 0) {
|
||||||
|
KillTimer(0, timer);
|
||||||
|
timer = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
/* see if hwndTrack isn't the current window */
|
||||||
|
if(ptme->hwndTrack != hwnd) {
|
||||||
|
if(leave) {
|
||||||
|
PostMessageA(ptme->hwndTrack, WM_MOUSELEAVE, 0, 0);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
/* See if this hwnd is already being tracked and update the tracking flags */
|
||||||
|
for(i = 0; i < iTrackMax; i++) {
|
||||||
|
if(TrackingList[i].tme.hwndTrack == ptme->hwndTrack) {
|
||||||
|
if(hover) {
|
||||||
|
TrackingList[i].tme.dwFlags |= TME_HOVER;
|
||||||
|
TrackingList[i].tme.dwHoverTime = ptme->dwHoverTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(leave)
|
||||||
|
TrackingList[i].tme.dwFlags |= TME_LEAVE;
|
||||||
|
|
||||||
|
/* reset iHoverTime as per winapi specs */
|
||||||
|
TrackingList[i].iHoverTime = 0;
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* if the tracking list is full return FALSE */
|
||||||
|
if (iTrackMax == sizeof (TrackingList) / sizeof(*TrackingList)) {
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Adding new mouse event to the tracking list */
|
||||||
|
TrackingList[iTrackMax].tme = *ptme;
|
||||||
|
|
||||||
|
/* Initialize HoverInfo variables even if not hover tracking */
|
||||||
|
TrackingList[iTrackMax].iHoverTime = 0;
|
||||||
|
TrackingList[iTrackMax].pos = pos;
|
||||||
|
|
||||||
|
iTrackMax++;
|
||||||
|
|
||||||
|
if (!timer) {
|
||||||
|
timer = SetTimer(0, 0, iTimerInterval, TrackMouseEventProc);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue