comctl32: Unify the implementation of TOOLTIPS_Show and TOOLTIPS_TrackShow to give tracked tooltips balloon support.

This commit is contained in:
Rob Shearman 2007-11-19 15:29:48 +00:00 committed by Alexandre Julliard
parent c02b46d987
commit 5ff8e6d7e1
1 changed files with 148 additions and 154 deletions

View File

@ -515,7 +515,7 @@ TOOLTIPS_CalcTipSize (HWND hwnd, const TOOLTIPS_INFO *infoPtr, LPSIZE lpSize)
static void
TOOLTIPS_Show (HWND hwnd, TOOLTIPS_INFO *infoPtr)
TOOLTIPS_Show (HWND hwnd, TOOLTIPS_INFO *infoPtr, BOOL track_activate)
{
TTTOOL_INFO *toolPtr;
HMONITOR monitor;
@ -525,25 +525,40 @@ TOOLTIPS_Show (HWND hwnd, TOOLTIPS_INFO *infoPtr)
NMHDR hdr;
int ptfx = 0;
DWORD style = GetWindowLongW(hwnd, GWL_STYLE);
INT nTool;
if (infoPtr->nTool == -1) {
TRACE("invalid tool (-1)!\n");
return;
if (track_activate)
{
if (infoPtr->nTrackTool == -1)
{
TRACE("invalid tracking tool (-1)!\n");
return;
}
nTool = infoPtr->nTrackTool;
}
else
{
if (infoPtr->nTool == -1)
{
TRACE("invalid tool (-1)!\n");
return;
}
nTool = infoPtr->nTool;
}
infoPtr->nCurrentTool = infoPtr->nTool;
TRACE("Show tooltip pre %d! (%p)\n", nTool, hwnd);
TRACE("Show tooltip pre %d! (%p)\n", infoPtr->nTool, hwnd);
TOOLTIPS_GetTipText (hwnd, infoPtr, nTool);
TOOLTIPS_GetTipText (hwnd, infoPtr, infoPtr->nCurrentTool);
if (infoPtr->szTipText[0] == '\0')
return;
if (infoPtr->szTipText[0] == '\0') {
infoPtr->nCurrentTool = -1;
return;
}
toolPtr = &infoPtr->tools[nTool];
TRACE("Show tooltip %d!\n", infoPtr->nCurrentTool);
toolPtr = &infoPtr->tools[infoPtr->nCurrentTool];
if (!track_activate)
infoPtr->nCurrentTool = infoPtr->nTool;
TRACE("Show tooltip %d!\n", nTool);
hdr.hwndFrom = hwnd;
hdr.idFrom = toolPtr->uId;
@ -556,61 +571,128 @@ TOOLTIPS_Show (HWND hwnd, TOOLTIPS_INFO *infoPtr)
TOOLTIPS_CalcTipSize (hwnd, infoPtr, &size);
TRACE("size %d x %d\n", size.cx, size.cy);
if (toolPtr->uFlags & TTF_CENTERTIP) {
RECT rc;
if (track_activate)
{
if (toolPtr->uFlags & TTF_ABSOLUTE)
{
rect.left = infoPtr->xTrackPos;
rect.top = infoPtr->yTrackPos;
ptfx = rect.left;
if (toolPtr->uFlags & TTF_IDISHWND)
GetWindowRect ((HWND)toolPtr->uId, &rc);
else {
rc = toolPtr->rect;
MapWindowPoints (toolPtr->hwnd, NULL, (LPPOINT)&rc, 2);
}
rect.left = (rc.left + rc.right - size.cx) / 2;
if (style & TTS_BALLOON)
{
ptfx = rc.left + ((rc.right - rc.left) / 2);
/* CENTERTIP ballon tooltips default to below the field
if they fit on the screen */
if(rc.bottom + size.cy > GetSystemMetrics(SM_CYSCREEN))
{
rect.top = rc.top - size.cy;
infoPtr->bToolBelow = FALSE;
}
else
{
if (toolPtr->uFlags & TTF_CENTERTIP)
{
rect.left -= (size.cx / 2);
if (!(style & TTS_BALLOON))
rect.top -= (size.cy / 2);
}
infoPtr->bToolBelow = TRUE;
rect.top = rc.bottom;
}
rect.left = max(0, rect.left - BALLOON_STEMINDENT);
}
else
{
rect.top = rc.bottom + 2;
infoPtr->bToolBelow = TRUE;
RECT rcTool;
GetCursorPos ((LPPOINT)&rect);
if (style & TTS_BALLOON)
{
ptfx = rect.left;
if (rect.top - size.cy >= 0)
{
rect.top -= size.cy;
infoPtr->bToolBelow = FALSE;
}
else
{
infoPtr->bToolBelow = TRUE;
rect.top += 20;
}
rect.left = max(0, rect.left - BALLOON_STEMINDENT);
}
else
{
rect.top += 20;
infoPtr->bToolBelow = TRUE;
}
if (toolPtr->uFlags & TTF_CENTERTIP)
{
rect.left -= (size.cx / 2);
rect.top -= (size.cy / 2);
}
if (toolPtr->uFlags & TTF_IDISHWND)
GetWindowRect ((HWND)toolPtr->uId, &rcTool);
else
{
rcTool = toolPtr->rect;
MapWindowPoints (toolPtr->hwnd, NULL, (LPPOINT)&rcTool, 2);
}
/* smart placement */
if ((rect.left + size.cx > rcTool.left) && (rect.left < rcTool.right) &&
(rect.top + size.cy > rcTool.top) && (rect.top < rcTool.bottom))
rect.left = rcTool.right;
}
}
else {
GetCursorPos ((LPPOINT)&rect);
if (style & TTS_BALLOON)
{
ptfx = rect.left;
if(rect.top - size.cy >= 0)
else
{
if (toolPtr->uFlags & TTF_CENTERTIP)
{
RECT rc;
if (toolPtr->uFlags & TTF_IDISHWND)
GetWindowRect ((HWND)toolPtr->uId, &rc);
else {
rc = toolPtr->rect;
MapWindowPoints (toolPtr->hwnd, NULL, (LPPOINT)&rc, 2);
}
rect.left = (rc.left + rc.right - size.cx) / 2;
if (style & TTS_BALLOON)
{
rect.top -= size.cy;
infoPtr->bToolBelow = FALSE;
ptfx = rc.left + ((rc.right - rc.left) / 2);
/* CENTERTIP ballon tooltips default to below the field
* if they fit on the screen */
if (rc.bottom + size.cy > GetSystemMetrics(SM_CYSCREEN))
{
rect.top = rc.top - size.cy;
infoPtr->bToolBelow = FALSE;
}
else
{
infoPtr->bToolBelow = TRUE;
rect.top = rc.bottom;
}
rect.left = max(0, rect.left - BALLOON_STEMINDENT);
}
else
{
infoPtr->bToolBelow = TRUE;
rect.top += 20;
rect.top = rc.bottom + 2;
infoPtr->bToolBelow = TRUE;
}
rect.left = max(0, rect.left - BALLOON_STEMINDENT);
}
else
{
rect.top += 20;
infoPtr->bToolBelow = TRUE;
GetCursorPos ((LPPOINT)&rect);
if (style & TTS_BALLOON)
{
ptfx = rect.left;
if(rect.top - size.cy >= 0)
{
rect.top -= size.cy;
infoPtr->bToolBelow = FALSE;
}
else
{
infoPtr->bToolBelow = TRUE;
rect.top += 20;
}
rect.left = max(0, rect.left - BALLOON_STEMINDENT);
}
else
{
rect.top += 20;
infoPtr->bToolBelow = TRUE;
}
}
}
@ -708,10 +790,13 @@ TOOLTIPS_Show (HWND hwnd, TOOLTIPS_INFO *infoPtr)
InvalidateRect(hwnd, NULL, TRUE);
UpdateWindow(hwnd);
SetTimer (hwnd, ID_TIMERPOP, infoPtr->nAutoPopTime, 0);
TRACE("timer 2 started!\n");
SetTimer (hwnd, ID_TIMERLEAVE, infoPtr->nReshowTime, 0);
TRACE("timer 3 started!\n");
if (!track_activate)
{
SetTimer (hwnd, ID_TIMERPOP, infoPtr->nAutoPopTime, 0);
TRACE("timer 2 started!\n");
SetTimer (hwnd, ID_TIMERLEAVE, infoPtr->nReshowTime, 0);
TRACE("timer 3 started!\n");
}
}
@ -745,98 +830,7 @@ TOOLTIPS_Hide (HWND hwnd, TOOLTIPS_INFO *infoPtr)
static void
TOOLTIPS_TrackShow (HWND hwnd, TOOLTIPS_INFO *infoPtr)
{
TTTOOL_INFO *toolPtr;
RECT rect;
SIZE size;
NMHDR hdr;
if (infoPtr->nTrackTool == -1) {
TRACE("invalid tracking tool (-1)!\n");
return;
}
TRACE("show tracking tooltip pre %d!\n", infoPtr->nTrackTool);
TOOLTIPS_GetTipText (hwnd, infoPtr, infoPtr->nTrackTool);
if (infoPtr->szTipText[0] == '\0') {
infoPtr->nTrackTool = -1;
return;
}
TRACE("show tracking tooltip %d!\n", infoPtr->nTrackTool);
toolPtr = &infoPtr->tools[infoPtr->nTrackTool];
hdr.hwndFrom = hwnd;
hdr.idFrom = toolPtr->uId;
hdr.code = TTN_SHOW;
SendMessageW (toolPtr->hwnd, WM_NOTIFY,
(WPARAM)toolPtr->uId, (LPARAM)&hdr);
TRACE("%s\n", debugstr_w(infoPtr->szTipText));
TOOLTIPS_CalcTipSize (hwnd, infoPtr, &size);
TRACE("size %d x %d\n", size.cx, size.cy);
if (toolPtr->uFlags & TTF_ABSOLUTE) {
rect.left = infoPtr->xTrackPos;
rect.top = infoPtr->yTrackPos;
if (toolPtr->uFlags & TTF_CENTERTIP) {
rect.left -= (size.cx / 2);
rect.top -= (size.cy / 2);
}
}
else {
RECT rcTool;
if (toolPtr->uFlags & TTF_IDISHWND)
GetWindowRect ((HWND)toolPtr->uId, &rcTool);
else {
rcTool = toolPtr->rect;
MapWindowPoints (toolPtr->hwnd, NULL, (LPPOINT)&rcTool, 2);
}
GetCursorPos ((LPPOINT)&rect);
rect.top += 20;
if (toolPtr->uFlags & TTF_CENTERTIP) {
rect.left -= (size.cx / 2);
rect.top -= (size.cy / 2);
}
/* smart placement */
if ((rect.left + size.cx > rcTool.left) && (rect.left < rcTool.right) &&
(rect.top + size.cy > rcTool.top) && (rect.top < rcTool.bottom))
rect.left = rcTool.right;
}
TRACE("pos %d - %d\n", rect.left, rect.top);
rect.right = rect.left + size.cx;
rect.bottom = rect.top + size.cy;
AdjustWindowRectEx (&rect, GetWindowLongW (hwnd, GWL_STYLE),
FALSE, GetWindowLongW (hwnd, GWL_EXSTYLE));
if (GetWindowLongW(hwnd, GWL_STYLE) & TTS_BALLOON)
{
HRGN hRgn;
/* FIXME: need to add pointy bit using CreatePolyRgn & CombinRgn */
hRgn = CreateRoundRectRgn(0, 0, rect.right - rect.left, rect.bottom - rect.top, BALLOON_ROUNDEDNESS, BALLOON_ROUNDEDNESS);
SetWindowRgn(hwnd, hRgn, FALSE);
/* we don't free the region handle as the system deletes it when
* it is no longer needed */
}
SetWindowPos (hwnd, HWND_TOP, rect.left, rect.top,
rect.right - rect.left, rect.bottom - rect.top,
SWP_SHOWWINDOW | SWP_NOACTIVATE );
InvalidateRect(hwnd, NULL, TRUE);
UpdateWindow(hwnd);
TOOLTIPS_Show(hwnd, infoPtr, TRUE);
}
@ -2133,7 +2127,7 @@ TOOLTIPS_SetToolInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
if (infoPtr->szTipText[0] == 0)
TOOLTIPS_Hide(hwnd, infoPtr);
else
TOOLTIPS_Show (hwnd, infoPtr);
TOOLTIPS_Show (hwnd, infoPtr, FALSE);
}
return 0;
@ -2255,7 +2249,7 @@ TOOLTIPS_UpdateTipTextA (HWND hwnd, WPARAM wParam, LPARAM lParam)
if(infoPtr->nCurrentTool == -1) return 0;
/* force repaint */
if (infoPtr->bActive)
TOOLTIPS_Show (hwnd, infoPtr);
TOOLTIPS_Show (hwnd, infoPtr, FALSE);
else if (infoPtr->bTrackActive)
TOOLTIPS_TrackShow (hwnd, infoPtr);
@ -2311,9 +2305,9 @@ TOOLTIPS_UpdateTipTextW (HWND hwnd, WPARAM wParam, LPARAM lParam)
if(infoPtr->nCurrentTool == -1) return 0;
/* force repaint */
if (infoPtr->bActive)
TOOLTIPS_Show (hwnd, infoPtr);
TOOLTIPS_Show (hwnd, infoPtr, FALSE);
else if (infoPtr->bTrackActive)
TOOLTIPS_TrackShow (hwnd, infoPtr);
TOOLTIPS_Show (hwnd, infoPtr, TRUE);
return 0;
}
@ -2570,7 +2564,7 @@ TOOLTIPS_Timer (HWND hwnd, WPARAM wParam, LPARAM lParam)
KillTimer (hwnd, ID_TIMERSHOW);
nOldTool = infoPtr->nTool;
if ((infoPtr->nTool = TOOLTIPS_CheckTool (hwnd, TRUE)) == nOldTool)
TOOLTIPS_Show (hwnd, infoPtr);
TOOLTIPS_Show (hwnd, infoPtr, FALSE);
break;
case ID_TIMERPOP: