4 * Copyright 1998, 1999 Eric Kohl
7 * - Unicode support (started).
8 * - Custom draw support.
11 * - Run tests using Waite Group Windows95 API Bible Volume 2.
12 * The second cdrom (chapter 3) contains executables activate.exe,
13 * curtool.exe, deltool.exe, enumtools.exe, getinfo.exe, getiptxt.exe,
14 * hittest.exe, needtext.exe, newrect.exe, updtext.exe and winfrpt.exe.
22 #include "debugtools.h"
24 DEFAULT_DEBUG_CHANNEL(tooltips)
26 #define ID_TIMERSHOW 1 /* show delay timer */
27 #define ID_TIMERPOP 2 /* auto pop timer */
28 #define ID_TIMERLEAVE 3 /* tool leave timer */
31 extern LPSTR COMCTL32_aSubclass; /* global subclassing atom */
33 /* property name of tooltip window handle */
34 /*#define TT_SUBCLASS_PROP "CC32SubclassInfo" */
36 #define TOOLTIPS_GetInfoPtr(hWindow) ((TOOLTIPS_INFO *)GetWindowLongA (hWindow, 0))
40 TOOLTIPS_SubclassProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
44 TOOLTIPS_Refresh (HWND hwnd, HDC hdc)
46 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr(hwnd);
51 UINT uFlags = DT_EXTERNALLEADING;
53 if (infoPtr->nMaxTipWidth > -1)
54 uFlags |= DT_WORDBREAK;
55 if (GetWindowLongA (hwnd, GWL_STYLE) & TTS_NOPREFIX)
56 uFlags |= DT_NOPREFIX;
57 GetClientRect (hwnd, &rc);
59 /* fill the background */
60 hBrush = CreateSolidBrush (infoPtr->clrBk);
61 FillRect (hdc, &rc, hBrush);
62 DeleteObject (hBrush);
64 /* calculate text rectangle */
65 rc.left += (2 + infoPtr->rcMargin.left);
66 rc.top += (2 + infoPtr->rcMargin.top);
67 rc.right -= (2 + infoPtr->rcMargin.right);
68 rc.bottom -= (2 + infoPtr->rcMargin.bottom);
71 oldBkMode = SetBkMode (hdc, TRANSPARENT);
72 SetTextColor (hdc, infoPtr->clrText);
73 hOldFont = SelectObject (hdc, infoPtr->hFont);
74 DrawTextW (hdc, infoPtr->szTipText, -1, &rc, uFlags);
75 SelectObject (hdc, hOldFont);
76 if (oldBkMode != TRANSPARENT)
77 SetBkMode (hdc, oldBkMode);
82 TOOLTIPS_GetTipText (HWND hwnd, TOOLTIPS_INFO *infoPtr, INT nTool)
84 TTTOOL_INFO *toolPtr = &infoPtr->tools[nTool];
86 if ((toolPtr->hinst) && (HIWORD((UINT)toolPtr->lpszText) == 0)) {
88 TRACE("load res string %x %x\n",
89 toolPtr->hinst, (int)toolPtr->lpszText);
90 LoadStringW (toolPtr->hinst, (UINT)toolPtr->lpszText,
91 infoPtr->szTipText, INFOTIPSIZE);
93 else if (toolPtr->lpszText) {
94 if (toolPtr->lpszText == LPSTR_TEXTCALLBACKW) {
97 /* fill NMHDR struct */
98 ZeroMemory (&ttnmdi, sizeof(NMTTDISPINFOA));
99 ttnmdi.hdr.hwndFrom = hwnd;
100 ttnmdi.hdr.idFrom = toolPtr->uId;
101 ttnmdi.hdr.code = TTN_GETDISPINFOA;
102 ttnmdi.lpszText = (LPSTR)&ttnmdi.szText;
103 ttnmdi.uFlags = toolPtr->uFlags;
104 ttnmdi.lParam = toolPtr->lParam;
106 TRACE("hdr.idFrom = %x\n", ttnmdi.hdr.idFrom);
107 SendMessageA (toolPtr->hwnd, WM_NOTIFY,
108 (WPARAM)toolPtr->uId, (LPARAM)&ttnmdi);
110 if ((ttnmdi.hinst) && (HIWORD((UINT)ttnmdi.lpszText) == 0)) {
111 LoadStringW (ttnmdi.hinst, (UINT)ttnmdi.lpszText,
112 infoPtr->szTipText, INFOTIPSIZE);
113 if (ttnmdi.uFlags & TTF_DI_SETITEM) {
114 toolPtr->hinst = ttnmdi.hinst;
115 toolPtr->lpszText = (LPWSTR)ttnmdi.lpszText;
118 else if (ttnmdi.szText[0]) {
119 lstrcpynAtoW (infoPtr->szTipText, ttnmdi.szText, 80);
120 if (ttnmdi.uFlags & TTF_DI_SETITEM) {
121 INT len = lstrlenA (ttnmdi.szText);
123 toolPtr->lpszText = COMCTL32_Alloc ((len+1)* sizeof(WCHAR));
124 lstrcpyAtoW (toolPtr->lpszText, ttnmdi.szText);
127 else if (ttnmdi.lpszText == 0) {
128 /* no text available */
129 infoPtr->szTipText[0] = L'\0';
131 else if (ttnmdi.lpszText != LPSTR_TEXTCALLBACKA) {
132 lstrcpynAtoW (infoPtr->szTipText, ttnmdi.lpszText, INFOTIPSIZE);
133 if (ttnmdi.uFlags & TTF_DI_SETITEM) {
134 INT len = lstrlenA (ttnmdi.lpszText);
136 toolPtr->lpszText = COMCTL32_Alloc ((len+1)*sizeof(WCHAR));
137 lstrcpyAtoW (toolPtr->lpszText, ttnmdi.lpszText);
141 ERR("recursive text callback!\n");
142 infoPtr->szTipText[0] = '\0';
146 /* the item is a usual (unicode) text */
147 lstrcpynW (infoPtr->szTipText, toolPtr->lpszText, INFOTIPSIZE);
151 /* no text available */
152 infoPtr->szTipText[0] = L'\0';
155 TRACE("%s\n", debugstr_w(infoPtr->szTipText));
160 TOOLTIPS_CalcTipSize (HWND hwnd, TOOLTIPS_INFO *infoPtr, LPSIZE lpSize)
164 UINT uFlags = DT_EXTERNALLEADING | DT_CALCRECT;
165 RECT rc = {0, 0, 0, 0};
167 if (infoPtr->nMaxTipWidth > -1) {
168 rc.right = infoPtr->nMaxTipWidth;
169 uFlags |= DT_WORDBREAK;
171 if (GetWindowLongA (hwnd, GWL_STYLE) & TTS_NOPREFIX)
172 uFlags |= DT_NOPREFIX;
173 TRACE("%s\n", debugstr_w(infoPtr->szTipText));
176 hOldFont = SelectObject (hdc, infoPtr->hFont);
177 DrawTextW (hdc, infoPtr->szTipText, -1, &rc, uFlags);
178 SelectObject (hdc, hOldFont);
179 ReleaseDC (hwnd, hdc);
181 lpSize->cx = rc.right - rc.left + 4 +
182 infoPtr->rcMargin.left + infoPtr->rcMargin.right;
183 lpSize->cy = rc.bottom - rc.top + 4 +
184 infoPtr->rcMargin.bottom + infoPtr->rcMargin.top;
189 TOOLTIPS_Show (HWND hwnd, TOOLTIPS_INFO *infoPtr)
191 TTTOOL_INFO *toolPtr;
197 if (infoPtr->nTool == -1) {
198 TRACE("invalid tool (-1)!\n");
202 infoPtr->nCurrentTool = infoPtr->nTool;
204 TRACE("Show tooltip pre %d!\n", infoPtr->nTool);
206 TOOLTIPS_GetTipText (hwnd, infoPtr, infoPtr->nCurrentTool);
208 if (infoPtr->szTipText[0] == L'\0') {
209 infoPtr->nCurrentTool = -1;
213 TRACE("Show tooltip %d!\n", infoPtr->nCurrentTool);
214 toolPtr = &infoPtr->tools[infoPtr->nCurrentTool];
217 hdr.idFrom = toolPtr->uId;
219 SendMessageA (toolPtr->hwnd, WM_NOTIFY,
220 (WPARAM)toolPtr->uId, (LPARAM)&hdr);
222 TRACE("%s\n", debugstr_w(infoPtr->szTipText));
224 TOOLTIPS_CalcTipSize (hwnd, infoPtr, &size);
225 TRACE("size %d - %d\n", size.cx, size.cy);
227 if (toolPtr->uFlags & TTF_CENTERTIP) {
230 if (toolPtr->uFlags & TTF_IDISHWND)
231 GetWindowRect ((HWND)toolPtr->uId, &rc);
234 MapWindowPoints (toolPtr->hwnd, (HWND)0, (LPPOINT)&rc, 2);
236 rect.left = (rc.left + rc.right - size.cx) / 2;
237 rect.top = rc.bottom + 2;
240 GetCursorPos ((LPPOINT)&rect);
244 TRACE("pos %d - %d\n", rect.left, rect.top);
246 rect.right = rect.left + size.cx;
247 rect.bottom = rect.top + size.cy;
250 wndrect.right = GetSystemMetrics( SM_CXSCREEN );
251 if( rect.right > wndrect.right ) {
252 rect.left -= rect.right - wndrect.right + 2;
253 rect.right = wndrect.right - 2;
255 wndrect.bottom = GetSystemMetrics( SM_CYSCREEN );
256 if( rect.bottom > wndrect.bottom ) {
259 if (toolPtr->uFlags & TTF_IDISHWND)
260 GetWindowRect ((HWND)toolPtr->uId, &rc);
263 MapWindowPoints (toolPtr->hwnd, (HWND)0, (LPPOINT)&rc, 2);
265 rect.bottom = rc.top - 2;
266 rect.top = rect.bottom - size.cy;
269 AdjustWindowRectEx (&rect, GetWindowLongA (hwnd, GWL_STYLE),
270 FALSE, GetWindowLongA (hwnd, GWL_EXSTYLE));
272 SetWindowPos (hwnd, HWND_TOP, rect.left, rect.top,
273 rect.right - rect.left, rect.bottom - rect.top,
274 SWP_SHOWWINDOW | SWP_NOACTIVATE);
276 /* repaint the tooltip */
278 TOOLTIPS_Refresh (hwnd, hdc);
279 ReleaseDC (hwnd, hdc);
281 SetTimer (hwnd, ID_TIMERPOP, infoPtr->nAutoPopTime, 0);
286 TOOLTIPS_Hide (HWND hwnd, TOOLTIPS_INFO *infoPtr)
288 TTTOOL_INFO *toolPtr;
291 if (infoPtr->nCurrentTool == -1)
294 toolPtr = &infoPtr->tools[infoPtr->nCurrentTool];
295 TRACE("Hide tooltip %d!\n", infoPtr->nCurrentTool);
296 KillTimer (hwnd, ID_TIMERPOP);
299 hdr.idFrom = toolPtr->uId;
301 SendMessageA (toolPtr->hwnd, WM_NOTIFY,
302 (WPARAM)toolPtr->uId, (LPARAM)&hdr);
304 infoPtr->nCurrentTool = -1;
306 SetWindowPos (hwnd, HWND_TOP, 0, 0, 0, 0,
307 SWP_NOZORDER | SWP_HIDEWINDOW | SWP_NOACTIVATE);
312 TOOLTIPS_TrackShow (HWND hwnd, TOOLTIPS_INFO *infoPtr)
314 TTTOOL_INFO *toolPtr;
320 if (infoPtr->nTrackTool == -1) {
321 TRACE("invalid tracking tool (-1)!\n");
325 TRACE("show tracking tooltip pre %d!\n", infoPtr->nTrackTool);
327 TOOLTIPS_GetTipText (hwnd, infoPtr, infoPtr->nTrackTool);
329 if (infoPtr->szTipText[0] == L'\0') {
330 infoPtr->nTrackTool = -1;
334 TRACE("show tracking tooltip %d!\n", infoPtr->nTrackTool);
335 toolPtr = &infoPtr->tools[infoPtr->nTrackTool];
338 hdr.idFrom = toolPtr->uId;
340 SendMessageA (toolPtr->hwnd, WM_NOTIFY,
341 (WPARAM)toolPtr->uId, (LPARAM)&hdr);
343 TRACE("%s\n", debugstr_w(infoPtr->szTipText));
345 TOOLTIPS_CalcTipSize (hwnd, infoPtr, &size);
346 TRACE("size %d - %d\n", size.cx, size.cy);
348 if (toolPtr->uFlags & TTF_ABSOLUTE) {
349 rect.left = infoPtr->xTrackPos;
350 rect.top = infoPtr->yTrackPos;
352 if (toolPtr->uFlags & TTF_CENTERTIP) {
353 rect.left -= (size.cx / 2);
354 rect.top -= (size.cy / 2);
360 if (toolPtr->uFlags & TTF_IDISHWND)
361 GetWindowRect ((HWND)toolPtr->uId, &rcTool);
363 rcTool = toolPtr->rect;
364 MapWindowPoints (toolPtr->hwnd, (HWND)0, (LPPOINT)&rcTool, 2);
367 GetCursorPos ((LPPOINT)&rect);
370 if (toolPtr->uFlags & TTF_CENTERTIP) {
371 rect.left -= (size.cx / 2);
372 rect.top -= (size.cy / 2);
375 /* smart placement */
376 if ((rect.left + size.cx > rcTool.left) && (rect.left < rcTool.right) &&
377 (rect.top + size.cy > rcTool.top) && (rect.top < rcTool.bottom))
378 rect.left = rcTool.right;
381 TRACE("pos %d - %d\n", rect.left, rect.top);
383 rect.right = rect.left + size.cx;
384 rect.bottom = rect.top + size.cy;
386 AdjustWindowRectEx (&rect, GetWindowLongA (hwnd, GWL_STYLE),
387 FALSE, GetWindowLongA (hwnd, GWL_EXSTYLE));
389 SetWindowPos (hwnd, HWND_TOP, rect.left, rect.top,
390 rect.right - rect.left, rect.bottom - rect.top,
391 SWP_SHOWWINDOW | SWP_NOACTIVATE );
394 TOOLTIPS_Refresh (hwnd, hdc);
395 ReleaseDC (hwnd, hdc);
400 TOOLTIPS_TrackHide (HWND hwnd, TOOLTIPS_INFO *infoPtr)
402 TTTOOL_INFO *toolPtr;
405 if (infoPtr->nTrackTool == -1)
408 toolPtr = &infoPtr->tools[infoPtr->nTrackTool];
409 TRACE("hide tracking tooltip %d!\n", infoPtr->nTrackTool);
412 hdr.idFrom = toolPtr->uId;
414 SendMessageA (toolPtr->hwnd, WM_NOTIFY,
415 (WPARAM)toolPtr->uId, (LPARAM)&hdr);
417 SetWindowPos (hwnd, HWND_TOP, 0, 0, 0, 0,
418 SWP_NOZORDER | SWP_HIDEWINDOW | SWP_NOACTIVATE);
423 TOOLTIPS_GetToolFromInfoA (TOOLTIPS_INFO *infoPtr, LPTTTOOLINFOA lpToolInfo)
425 TTTOOL_INFO *toolPtr;
428 for (nTool = 0; nTool < infoPtr->uNumTools; nTool++) {
429 toolPtr = &infoPtr->tools[nTool];
431 if (!(toolPtr->uFlags & TTF_IDISHWND) &&
432 (lpToolInfo->hwnd == toolPtr->hwnd) &&
433 (lpToolInfo->uId == toolPtr->uId))
437 for (nTool = 0; nTool < infoPtr->uNumTools; nTool++) {
438 toolPtr = &infoPtr->tools[nTool];
440 if ((toolPtr->uFlags & TTF_IDISHWND) &&
441 (lpToolInfo->uId == toolPtr->uId))
450 TOOLTIPS_GetToolFromInfoW (TOOLTIPS_INFO *infoPtr, LPTTTOOLINFOW lpToolInfo)
452 TTTOOL_INFO *toolPtr;
455 for (nTool = 0; nTool < infoPtr->uNumTools; nTool++) {
456 toolPtr = &infoPtr->tools[nTool];
458 if (!(toolPtr->uFlags & TTF_IDISHWND) &&
459 (lpToolInfo->hwnd == toolPtr->hwnd) &&
460 (lpToolInfo->uId == toolPtr->uId))
464 for (nTool = 0; nTool < infoPtr->uNumTools; nTool++) {
465 toolPtr = &infoPtr->tools[nTool];
467 if ((toolPtr->uFlags & TTF_IDISHWND) &&
468 (lpToolInfo->uId == toolPtr->uId))
477 TOOLTIPS_GetToolFromPoint (TOOLTIPS_INFO *infoPtr, HWND hwnd, LPPOINT lpPt)
479 TTTOOL_INFO *toolPtr;
482 for (nTool = 0; nTool < infoPtr->uNumTools; nTool++) {
483 toolPtr = &infoPtr->tools[nTool];
485 if (!(toolPtr->uFlags & TTF_IDISHWND)) {
486 if (hwnd != toolPtr->hwnd)
488 if (!PtInRect (&toolPtr->rect, *lpPt))
494 for (nTool = 0; nTool < infoPtr->uNumTools; nTool++) {
495 toolPtr = &infoPtr->tools[nTool];
497 if (toolPtr->uFlags & TTF_IDISHWND) {
498 if ((HWND)toolPtr->uId == hwnd)
508 TOOLTIPS_GetToolFromMessage (TOOLTIPS_INFO *infoPtr, HWND hwndTool)
513 dwPos = GetMessagePos ();
514 pt.x = (INT)LOWORD(dwPos);
515 pt.y = (INT)HIWORD(dwPos);
516 ScreenToClient (hwndTool, &pt);
518 return TOOLTIPS_GetToolFromPoint (infoPtr, hwndTool, &pt);
523 TOOLTIPS_IsWindowActive (HWND hwnd)
525 HWND hwndActive = GetActiveWindow ();
528 if (hwndActive == hwnd)
530 return IsChild (hwndActive, hwnd);
535 TOOLTIPS_CheckTool (HWND hwnd, BOOL bShowTest)
537 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
543 hwndTool = SendMessageA (hwnd, TTM_WINDOWFROMPOINT, 0, (LPARAM)&pt);
547 ScreenToClient (hwndTool, &pt);
548 nTool = TOOLTIPS_GetToolFromPoint (infoPtr, hwndTool, &pt);
552 if (!(GetWindowLongA (hwnd, GWL_STYLE) & TTS_ALWAYSTIP) && bShowTest) {
553 if (!TOOLTIPS_IsWindowActive (GetWindow (hwnd, GW_OWNER)))
557 TRACE("tool %d\n", nTool);
564 TOOLTIPS_Activate (HWND hwnd, WPARAM wParam, LPARAM lParam)
566 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
568 infoPtr->bActive = (BOOL)wParam;
570 if (infoPtr->bActive)
571 TRACE("activate!\n");
573 if (!(infoPtr->bActive) && (infoPtr->nCurrentTool != -1))
574 TOOLTIPS_Hide (hwnd, infoPtr);
581 TOOLTIPS_AddToolA (HWND hwnd, WPARAM wParam, LPARAM lParam)
583 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
584 LPTTTOOLINFOA lpToolInfo = (LPTTTOOLINFOA)lParam;
585 TTTOOL_INFO *toolPtr;
587 if (lpToolInfo == NULL)
589 if (lpToolInfo->cbSize < TTTOOLINFO_V1_SIZEA)
592 TRACE("add tool (%x) %x %d%s!\n",
593 hwnd, lpToolInfo->hwnd, lpToolInfo->uId,
594 (lpToolInfo->uFlags & TTF_IDISHWND) ? " TTF_IDISHWND" : "");
596 if (infoPtr->uNumTools == 0) {
597 infoPtr->tools = COMCTL32_Alloc (sizeof(TTTOOL_INFO));
598 toolPtr = infoPtr->tools;
601 TTTOOL_INFO *oldTools = infoPtr->tools;
603 COMCTL32_Alloc (sizeof(TTTOOL_INFO) * (infoPtr->uNumTools + 1));
604 memcpy (infoPtr->tools, oldTools,
605 infoPtr->uNumTools * sizeof(TTTOOL_INFO));
606 COMCTL32_Free (oldTools);
607 toolPtr = &infoPtr->tools[infoPtr->uNumTools];
610 infoPtr->uNumTools++;
613 toolPtr->uFlags = lpToolInfo->uFlags;
614 toolPtr->hwnd = lpToolInfo->hwnd;
615 toolPtr->uId = lpToolInfo->uId;
616 toolPtr->rect = lpToolInfo->rect;
617 toolPtr->hinst = lpToolInfo->hinst;
619 if ((lpToolInfo->hinst) && (HIWORD((INT)lpToolInfo->lpszText) == 0)) {
620 TRACE("add string id %x!\n", (int)lpToolInfo->lpszText);
621 toolPtr->lpszText = (LPWSTR)lpToolInfo->lpszText;
623 else if (lpToolInfo->lpszText) {
624 if (lpToolInfo->lpszText == LPSTR_TEXTCALLBACKA) {
625 TRACE("add CALLBACK!\n");
626 toolPtr->lpszText = LPSTR_TEXTCALLBACKW;
629 INT len = lstrlenA (lpToolInfo->lpszText);
630 TRACE("add text \"%s\"!\n", lpToolInfo->lpszText);
631 toolPtr->lpszText = COMCTL32_Alloc ((len + 1)*sizeof(WCHAR));
632 lstrcpyAtoW (toolPtr->lpszText, lpToolInfo->lpszText);
636 if (lpToolInfo->cbSize >= sizeof(TTTOOLINFOA))
637 toolPtr->lParam = lpToolInfo->lParam;
639 /* install subclassing hook */
640 if (toolPtr->uFlags & TTF_SUBCLASS) {
641 if (toolPtr->uFlags & TTF_IDISHWND) {
642 LPTT_SUBCLASS_INFO lpttsi =
643 (LPTT_SUBCLASS_INFO)GetPropA ((HWND)toolPtr->uId, COMCTL32_aSubclass);
644 if (lpttsi == NULL) {
646 (LPTT_SUBCLASS_INFO)COMCTL32_Alloc (sizeof(TT_SUBCLASS_INFO));
648 (WNDPROC)SetWindowLongA ((HWND)toolPtr->uId,
649 GWL_WNDPROC,(LONG)TOOLTIPS_SubclassProc);
650 lpttsi->hwndToolTip = hwnd;
652 SetPropA ((HWND)toolPtr->uId, COMCTL32_aSubclass,
656 WARN("A window tool must only be listed once!\n");
659 LPTT_SUBCLASS_INFO lpttsi =
660 (LPTT_SUBCLASS_INFO)GetPropA (toolPtr->hwnd, COMCTL32_aSubclass);
661 if (lpttsi == NULL) {
663 (LPTT_SUBCLASS_INFO)COMCTL32_Alloc (sizeof(TT_SUBCLASS_INFO));
665 (WNDPROC)SetWindowLongA (toolPtr->hwnd,
666 GWL_WNDPROC,(LONG)TOOLTIPS_SubclassProc);
667 lpttsi->hwndToolTip = hwnd;
669 SetPropA (toolPtr->hwnd, COMCTL32_aSubclass, (HANDLE)lpttsi);
674 TRACE("subclassing installed!\n");
682 TOOLTIPS_AddToolW (HWND hwnd, WPARAM wParam, LPARAM lParam)
684 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
685 LPTTTOOLINFOW lpToolInfo = (LPTTTOOLINFOW)lParam;
686 TTTOOL_INFO *toolPtr;
688 if (lpToolInfo == NULL)
690 if (lpToolInfo->cbSize < TTTOOLINFO_V1_SIZEW)
693 TRACE("add tool (%x) %x %d%s!\n",
694 hwnd, lpToolInfo->hwnd, lpToolInfo->uId,
695 (lpToolInfo->uFlags & TTF_IDISHWND) ? " TTF_IDISHWND" : "");
697 if (infoPtr->uNumTools == 0) {
698 infoPtr->tools = COMCTL32_Alloc (sizeof(TTTOOL_INFO));
699 toolPtr = infoPtr->tools;
702 TTTOOL_INFO *oldTools = infoPtr->tools;
704 COMCTL32_Alloc (sizeof(TTTOOL_INFO) * (infoPtr->uNumTools + 1));
705 memcpy (infoPtr->tools, oldTools,
706 infoPtr->uNumTools * sizeof(TTTOOL_INFO));
707 COMCTL32_Free (oldTools);
708 toolPtr = &infoPtr->tools[infoPtr->uNumTools];
711 infoPtr->uNumTools++;
714 toolPtr->uFlags = lpToolInfo->uFlags;
715 toolPtr->hwnd = lpToolInfo->hwnd;
716 toolPtr->uId = lpToolInfo->uId;
717 toolPtr->rect = lpToolInfo->rect;
718 toolPtr->hinst = lpToolInfo->hinst;
720 if ((lpToolInfo->hinst) && (HIWORD((INT)lpToolInfo->lpszText) == 0)) {
721 TRACE("add string id %x!\n", (int)lpToolInfo->lpszText);
722 toolPtr->lpszText = (LPWSTR)lpToolInfo->lpszText;
724 else if (lpToolInfo->lpszText) {
725 if (lpToolInfo->lpszText == LPSTR_TEXTCALLBACKW) {
726 TRACE("add CALLBACK!\n");
727 toolPtr->lpszText = LPSTR_TEXTCALLBACKW;
730 INT len = lstrlenW (lpToolInfo->lpszText);
731 TRACE("add text %s!\n",
732 debugstr_w(lpToolInfo->lpszText));
733 toolPtr->lpszText = COMCTL32_Alloc ((len + 1)*sizeof(WCHAR));
734 lstrcpyW (toolPtr->lpszText, lpToolInfo->lpszText);
738 if (lpToolInfo->cbSize >= sizeof(TTTOOLINFOW))
739 toolPtr->lParam = lpToolInfo->lParam;
741 /* install subclassing hook */
742 if (toolPtr->uFlags & TTF_SUBCLASS) {
743 if (toolPtr->uFlags & TTF_IDISHWND) {
744 LPTT_SUBCLASS_INFO lpttsi =
745 (LPTT_SUBCLASS_INFO)GetPropA ((HWND)toolPtr->uId, COMCTL32_aSubclass);
746 if (lpttsi == NULL) {
748 (LPTT_SUBCLASS_INFO)COMCTL32_Alloc (sizeof(TT_SUBCLASS_INFO));
750 (WNDPROC)SetWindowLongA ((HWND)toolPtr->uId,
751 GWL_WNDPROC,(LONG)TOOLTIPS_SubclassProc);
752 lpttsi->hwndToolTip = hwnd;
754 SetPropA ((HWND)toolPtr->uId, COMCTL32_aSubclass,
758 WARN("A window tool must only be listed once!\n");
761 LPTT_SUBCLASS_INFO lpttsi =
762 (LPTT_SUBCLASS_INFO)GetPropA (toolPtr->hwnd, COMCTL32_aSubclass);
763 if (lpttsi == NULL) {
765 (LPTT_SUBCLASS_INFO)COMCTL32_Alloc (sizeof(TT_SUBCLASS_INFO));
767 (WNDPROC)SetWindowLongA (toolPtr->hwnd,
768 GWL_WNDPROC,(LONG)TOOLTIPS_SubclassProc);
769 lpttsi->hwndToolTip = hwnd;
771 SetPropA (toolPtr->hwnd, COMCTL32_aSubclass, (HANDLE)lpttsi);
776 TRACE("subclassing installed!\n");
784 TOOLTIPS_DelToolA (HWND hwnd, WPARAM wParam, LPARAM lParam)
786 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
787 LPTTTOOLINFOA lpToolInfo = (LPTTTOOLINFOA)lParam;
788 TTTOOL_INFO *toolPtr;
791 if (lpToolInfo == NULL)
793 if (lpToolInfo->cbSize < TTTOOLINFO_V1_SIZEA)
795 if (infoPtr->uNumTools == 0)
798 nTool = TOOLTIPS_GetToolFromInfoA (infoPtr, lpToolInfo);
799 if (nTool == -1) return 0;
801 TRACE("tool %d\n", nTool);
803 /* delete text string */
804 toolPtr = &infoPtr->tools[nTool];
805 if ((toolPtr->hinst) && (toolPtr->lpszText)) {
806 if ( (toolPtr->lpszText != LPSTR_TEXTCALLBACKW) &&
807 (HIWORD((INT)toolPtr->lpszText) != 0) )
808 COMCTL32_Free (toolPtr->lpszText);
811 /* remove subclassing */
812 if (toolPtr->uFlags & TTF_SUBCLASS) {
813 if (toolPtr->uFlags & TTF_IDISHWND) {
814 LPTT_SUBCLASS_INFO lpttsi =
815 (LPTT_SUBCLASS_INFO)GetPropA ((HWND)toolPtr->uId, COMCTL32_aSubclass);
817 SetWindowLongA ((HWND)toolPtr->uId, GWL_WNDPROC,
818 (LONG)lpttsi->wpOrigProc);
819 RemovePropA ((HWND)toolPtr->uId, COMCTL32_aSubclass);
820 COMCTL32_Free (&lpttsi);
823 ERR("Invalid data handle!\n");
826 LPTT_SUBCLASS_INFO lpttsi =
827 (LPTT_SUBCLASS_INFO)GetPropA (toolPtr->hwnd, COMCTL32_aSubclass);
829 if (lpttsi->uRefCount == 1) {
830 SetWindowLongA ((HWND)toolPtr->uId, GWL_WNDPROC,
831 (LONG)lpttsi->wpOrigProc);
832 RemovePropA ((HWND)toolPtr->uId, COMCTL32_aSubclass);
833 COMCTL32_Free (&lpttsi);
839 ERR("Invalid data handle!\n");
843 /* delete tool from tool list */
844 if (infoPtr->uNumTools == 1) {
845 COMCTL32_Free (infoPtr->tools);
846 infoPtr->tools = NULL;
849 TTTOOL_INFO *oldTools = infoPtr->tools;
851 COMCTL32_Alloc (sizeof(TTTOOL_INFO) * (infoPtr->uNumTools - 1));
854 memcpy (&infoPtr->tools[0], &oldTools[0],
855 nTool * sizeof(TTTOOL_INFO));
857 if (nTool < infoPtr->uNumTools - 1)
858 memcpy (&infoPtr->tools[nTool], &oldTools[nTool + 1],
859 (infoPtr->uNumTools - nTool - 1) * sizeof(TTTOOL_INFO));
861 COMCTL32_Free (oldTools);
864 infoPtr->uNumTools--;
871 TOOLTIPS_DelToolW (HWND hwnd, WPARAM wParam, LPARAM lParam)
873 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
874 LPTTTOOLINFOW lpToolInfo = (LPTTTOOLINFOW)lParam;
875 TTTOOL_INFO *toolPtr;
878 if (lpToolInfo == NULL)
880 if (lpToolInfo->cbSize < TTTOOLINFO_V1_SIZEW)
882 if (infoPtr->uNumTools == 0)
885 nTool = TOOLTIPS_GetToolFromInfoW (infoPtr, lpToolInfo);
886 if (nTool == -1) return 0;
888 TRACE("tool %d\n", nTool);
890 /* delete text string */
891 toolPtr = &infoPtr->tools[nTool];
892 if ((toolPtr->hinst) && (toolPtr->lpszText)) {
893 if ( (toolPtr->lpszText != LPSTR_TEXTCALLBACKW) &&
894 (HIWORD((INT)toolPtr->lpszText) != 0) )
895 COMCTL32_Free (toolPtr->lpszText);
898 /* remove subclassing */
899 if (toolPtr->uFlags & TTF_SUBCLASS) {
900 if (toolPtr->uFlags & TTF_IDISHWND) {
901 LPTT_SUBCLASS_INFO lpttsi =
902 (LPTT_SUBCLASS_INFO)GetPropA ((HWND)toolPtr->uId, COMCTL32_aSubclass);
904 SetWindowLongA ((HWND)toolPtr->uId, GWL_WNDPROC,
905 (LONG)lpttsi->wpOrigProc);
906 RemovePropA ((HWND)toolPtr->uId, COMCTL32_aSubclass);
907 COMCTL32_Free (&lpttsi);
910 ERR("Invalid data handle!\n");
913 LPTT_SUBCLASS_INFO lpttsi =
914 (LPTT_SUBCLASS_INFO)GetPropA (toolPtr->hwnd, COMCTL32_aSubclass);
916 if (lpttsi->uRefCount == 1) {
917 SetWindowLongA ((HWND)toolPtr->uId, GWL_WNDPROC,
918 (LONG)lpttsi->wpOrigProc);
919 RemovePropA ((HWND)toolPtr->uId, COMCTL32_aSubclass);
920 COMCTL32_Free (&lpttsi);
926 ERR("Invalid data handle!\n");
930 /* delete tool from tool list */
931 if (infoPtr->uNumTools == 1) {
932 COMCTL32_Free (infoPtr->tools);
933 infoPtr->tools = NULL;
936 TTTOOL_INFO *oldTools = infoPtr->tools;
938 COMCTL32_Alloc (sizeof(TTTOOL_INFO) * (infoPtr->uNumTools - 1));
941 memcpy (&infoPtr->tools[0], &oldTools[0],
942 nTool * sizeof(TTTOOL_INFO));
944 if (nTool < infoPtr->uNumTools - 1)
945 memcpy (&infoPtr->tools[nTool], &oldTools[nTool + 1],
946 (infoPtr->uNumTools - nTool - 1) * sizeof(TTTOOL_INFO));
948 COMCTL32_Free (oldTools);
951 infoPtr->uNumTools--;
958 TOOLTIPS_EnumToolsA (HWND hwnd, WPARAM wParam, LPARAM lParam)
960 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
961 UINT uIndex = (UINT)wParam;
962 LPTTTOOLINFOA lpToolInfo = (LPTTTOOLINFOA)lParam;
963 TTTOOL_INFO *toolPtr;
965 if (lpToolInfo == NULL)
967 if (lpToolInfo->cbSize < TTTOOLINFO_V1_SIZEA)
969 if (uIndex >= infoPtr->uNumTools)
972 TRACE("index=%u\n", uIndex);
974 toolPtr = &infoPtr->tools[uIndex];
977 lpToolInfo->uFlags = toolPtr->uFlags;
978 lpToolInfo->hwnd = toolPtr->hwnd;
979 lpToolInfo->uId = toolPtr->uId;
980 lpToolInfo->rect = toolPtr->rect;
981 lpToolInfo->hinst = toolPtr->hinst;
982 /* lpToolInfo->lpszText = toolPtr->lpszText; */
983 lpToolInfo->lpszText = NULL; /* FIXME */
985 if (lpToolInfo->cbSize >= sizeof(TTTOOLINFOA))
986 lpToolInfo->lParam = toolPtr->lParam;
993 TOOLTIPS_EnumToolsW (HWND hwnd, WPARAM wParam, LPARAM lParam)
995 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
996 UINT uIndex = (UINT)wParam;
997 LPTTTOOLINFOW lpToolInfo = (LPTTTOOLINFOW)lParam;
998 TTTOOL_INFO *toolPtr;
1000 if (lpToolInfo == NULL)
1002 if (lpToolInfo->cbSize < TTTOOLINFO_V1_SIZEW)
1004 if (uIndex >= infoPtr->uNumTools)
1007 TRACE("index=%u\n", uIndex);
1009 toolPtr = &infoPtr->tools[uIndex];
1011 /* copy tool data */
1012 lpToolInfo->uFlags = toolPtr->uFlags;
1013 lpToolInfo->hwnd = toolPtr->hwnd;
1014 lpToolInfo->uId = toolPtr->uId;
1015 lpToolInfo->rect = toolPtr->rect;
1016 lpToolInfo->hinst = toolPtr->hinst;
1017 /* lpToolInfo->lpszText = toolPtr->lpszText; */
1018 lpToolInfo->lpszText = NULL; /* FIXME */
1020 if (lpToolInfo->cbSize >= sizeof(TTTOOLINFOW))
1021 lpToolInfo->lParam = toolPtr->lParam;
1028 TOOLTIPS_GetCurrentToolA (HWND hwnd, WPARAM wParam, LPARAM lParam)
1030 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1031 LPTTTOOLINFOA lpToolInfo = (LPTTTOOLINFOA)lParam;
1032 TTTOOL_INFO *toolPtr;
1034 if (lpToolInfo == NULL)
1036 if (lpToolInfo->cbSize < TTTOOLINFO_V1_SIZEA)
1040 if (infoPtr->nCurrentTool > -1) {
1041 toolPtr = &infoPtr->tools[infoPtr->nCurrentTool];
1043 /* copy tool data */
1044 lpToolInfo->uFlags = toolPtr->uFlags;
1045 lpToolInfo->rect = toolPtr->rect;
1046 lpToolInfo->hinst = toolPtr->hinst;
1047 /* lpToolInfo->lpszText = toolPtr->lpszText; */
1048 lpToolInfo->lpszText = NULL; /* FIXME */
1050 if (lpToolInfo->cbSize >= sizeof(TTTOOLINFOA))
1051 lpToolInfo->lParam = toolPtr->lParam;
1059 return (infoPtr->nCurrentTool != -1);
1066 TOOLTIPS_GetCurrentToolW (HWND hwnd, WPARAM wParam, LPARAM lParam)
1068 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1069 LPTTTOOLINFOW lpToolInfo = (LPTTTOOLINFOW)lParam;
1070 TTTOOL_INFO *toolPtr;
1072 if (lpToolInfo == NULL)
1074 if (lpToolInfo->cbSize < TTTOOLINFO_V1_SIZEW)
1078 if (infoPtr->nCurrentTool > -1) {
1079 toolPtr = &infoPtr->tools[infoPtr->nCurrentTool];
1081 /* copy tool data */
1082 lpToolInfo->uFlags = toolPtr->uFlags;
1083 lpToolInfo->rect = toolPtr->rect;
1084 lpToolInfo->hinst = toolPtr->hinst;
1085 /* lpToolInfo->lpszText = toolPtr->lpszText; */
1086 lpToolInfo->lpszText = NULL; /* FIXME */
1088 if (lpToolInfo->cbSize >= sizeof(TTTOOLINFOW))
1089 lpToolInfo->lParam = toolPtr->lParam;
1097 return (infoPtr->nCurrentTool != -1);
1104 TOOLTIPS_GetDelayTime (HWND hwnd, WPARAM wParam, LPARAM lParam)
1106 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1109 case TTDT_AUTOMATIC:
1110 return infoPtr->nAutomaticTime;
1113 return infoPtr->nReshowTime;
1116 return infoPtr->nAutoPopTime;
1119 return infoPtr->nInitialTime;
1127 TOOLTIPS_GetMargin (HWND hwnd, WPARAM wParam, LPARAM lParam)
1129 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1130 LPRECT lpRect = (LPRECT)lParam;
1132 lpRect->left = infoPtr->rcMargin.left;
1133 lpRect->right = infoPtr->rcMargin.right;
1134 lpRect->bottom = infoPtr->rcMargin.bottom;
1135 lpRect->top = infoPtr->rcMargin.top;
1141 inline static LRESULT
1142 TOOLTIPS_GetMaxTipWidth (HWND hwnd, WPARAM wParam, LPARAM lParam)
1144 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1146 return infoPtr->nMaxTipWidth;
1151 TOOLTIPS_GetTextA (HWND hwnd, WPARAM wParam, LPARAM lParam)
1153 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1154 LPTTTOOLINFOA lpToolInfo = (LPTTTOOLINFOA)lParam;
1157 if (lpToolInfo == NULL)
1159 if (lpToolInfo->cbSize < TTTOOLINFO_V1_SIZEA)
1162 nTool = TOOLTIPS_GetToolFromInfoA (infoPtr, lpToolInfo);
1163 if (nTool == -1) return 0;
1165 lstrcpyWtoA (lpToolInfo->lpszText, infoPtr->tools[nTool].lpszText);
1172 TOOLTIPS_GetTextW (HWND hwnd, WPARAM wParam, LPARAM lParam)
1174 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1175 LPTTTOOLINFOW lpToolInfo = (LPTTTOOLINFOW)lParam;
1178 if (lpToolInfo == NULL)
1180 if (lpToolInfo->cbSize < TTTOOLINFO_V1_SIZEW)
1183 nTool = TOOLTIPS_GetToolFromInfoW (infoPtr, lpToolInfo);
1184 if (nTool == -1) return 0;
1186 lstrcpyW (lpToolInfo->lpszText, infoPtr->tools[nTool].lpszText);
1192 inline static LRESULT
1193 TOOLTIPS_GetTipBkColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
1195 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1196 return infoPtr->clrBk;
1200 inline static LRESULT
1201 TOOLTIPS_GetTipTextColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
1203 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1204 return infoPtr->clrText;
1208 inline static LRESULT
1209 TOOLTIPS_GetToolCount (HWND hwnd, WPARAM wParam, LPARAM lParam)
1211 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1212 return infoPtr->uNumTools;
1217 TOOLTIPS_GetToolInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
1219 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1220 LPTTTOOLINFOA lpToolInfo = (LPTTTOOLINFOA)lParam;
1221 TTTOOL_INFO *toolPtr;
1224 if (lpToolInfo == NULL)
1226 if (lpToolInfo->cbSize < TTTOOLINFO_V1_SIZEA)
1228 if (infoPtr->uNumTools == 0)
1231 nTool = TOOLTIPS_GetToolFromInfoA (infoPtr, lpToolInfo);
1235 TRACE("tool %d\n", nTool);
1237 toolPtr = &infoPtr->tools[nTool];
1239 /* copy tool data */
1240 lpToolInfo->uFlags = toolPtr->uFlags;
1241 lpToolInfo->rect = toolPtr->rect;
1242 lpToolInfo->hinst = toolPtr->hinst;
1243 /* lpToolInfo->lpszText = toolPtr->lpszText; */
1244 lpToolInfo->lpszText = NULL; /* FIXME */
1246 if (lpToolInfo->cbSize >= sizeof(TTTOOLINFOA))
1247 lpToolInfo->lParam = toolPtr->lParam;
1254 TOOLTIPS_GetToolInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
1256 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1257 LPTTTOOLINFOW lpToolInfo = (LPTTTOOLINFOW)lParam;
1258 TTTOOL_INFO *toolPtr;
1261 if (lpToolInfo == NULL)
1263 if (lpToolInfo->cbSize < TTTOOLINFO_V1_SIZEW)
1265 if (infoPtr->uNumTools == 0)
1268 nTool = TOOLTIPS_GetToolFromInfoW (infoPtr, lpToolInfo);
1272 TRACE("tool %d\n", nTool);
1274 toolPtr = &infoPtr->tools[nTool];
1276 /* copy tool data */
1277 lpToolInfo->uFlags = toolPtr->uFlags;
1278 lpToolInfo->rect = toolPtr->rect;
1279 lpToolInfo->hinst = toolPtr->hinst;
1280 /* lpToolInfo->lpszText = toolPtr->lpszText; */
1281 lpToolInfo->lpszText = NULL; /* FIXME */
1283 if (lpToolInfo->cbSize >= sizeof(TTTOOLINFOW))
1284 lpToolInfo->lParam = toolPtr->lParam;
1291 TOOLTIPS_HitTestA (HWND hwnd, WPARAM wParam, LPARAM lParam)
1293 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1294 LPTTHITTESTINFOA lptthit = (LPTTHITTESTINFOA)lParam;
1295 TTTOOL_INFO *toolPtr;
1301 nTool = TOOLTIPS_GetToolFromPoint (infoPtr, lptthit->hwnd, &lptthit->pt);
1305 TRACE("tool %d!\n", nTool);
1307 /* copy tool data */
1308 if (lptthit->ti.cbSize >= sizeof(TTTOOLINFOA)) {
1309 toolPtr = &infoPtr->tools[nTool];
1311 lptthit->ti.uFlags = toolPtr->uFlags;
1312 lptthit->ti.hwnd = toolPtr->hwnd;
1313 lptthit->ti.uId = toolPtr->uId;
1314 lptthit->ti.rect = toolPtr->rect;
1315 lptthit->ti.hinst = toolPtr->hinst;
1316 /* lptthit->ti.lpszText = toolPtr->lpszText; */
1317 lptthit->ti.lpszText = NULL; /* FIXME */
1318 lptthit->ti.lParam = toolPtr->lParam;
1326 TOOLTIPS_HitTestW (HWND hwnd, WPARAM wParam, LPARAM lParam)
1328 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1329 LPTTHITTESTINFOW lptthit = (LPTTHITTESTINFOW)lParam;
1330 TTTOOL_INFO *toolPtr;
1336 nTool = TOOLTIPS_GetToolFromPoint (infoPtr, lptthit->hwnd, &lptthit->pt);
1340 TRACE("tool %d!\n", nTool);
1342 /* copy tool data */
1343 if (lptthit->ti.cbSize >= sizeof(TTTOOLINFOW)) {
1344 toolPtr = &infoPtr->tools[nTool];
1346 lptthit->ti.uFlags = toolPtr->uFlags;
1347 lptthit->ti.hwnd = toolPtr->hwnd;
1348 lptthit->ti.uId = toolPtr->uId;
1349 lptthit->ti.rect = toolPtr->rect;
1350 lptthit->ti.hinst = toolPtr->hinst;
1351 /* lptthit->ti.lpszText = toolPtr->lpszText; */
1352 lptthit->ti.lpszText = NULL; /* FIXME */
1353 lptthit->ti.lParam = toolPtr->lParam;
1361 TOOLTIPS_NewToolRectA (HWND hwnd, WPARAM wParam, LPARAM lParam)
1363 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1364 LPTTTOOLINFOA lpti = (LPTTTOOLINFOA)lParam;
1369 if (lpti->cbSize < TTTOOLINFO_V1_SIZEA)
1372 nTool = TOOLTIPS_GetToolFromInfoA (infoPtr, lpti);
1373 if (nTool == -1) return 0;
1375 infoPtr->tools[nTool].rect = lpti->rect;
1382 TOOLTIPS_NewToolRectW (HWND hwnd, WPARAM wParam, LPARAM lParam)
1384 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1385 LPTTTOOLINFOW lpti = (LPTTTOOLINFOW)lParam;
1390 if (lpti->cbSize < TTTOOLINFO_V1_SIZEW)
1393 nTool = TOOLTIPS_GetToolFromInfoW (infoPtr, lpti);
1394 if (nTool == -1) return 0;
1396 infoPtr->tools[nTool].rect = lpti->rect;
1402 inline static LRESULT
1403 TOOLTIPS_Pop (HWND hwnd, WPARAM wParam, LPARAM lParam)
1405 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1408 * Need to set nCurrentTool to nOldTool so we hide the tool.
1409 * nTool and nOldTool values change when the mouse leaves the window.
1410 * If using TTM_UPDATETIPTEXT we can end up with an nCurrentTool = -1 if the
1411 * text can't be found, thus the tooltip would never be hidden.
1413 if (infoPtr->nTool != infoPtr->nOldTool)
1414 infoPtr->nCurrentTool = infoPtr->nOldTool;
1416 TOOLTIPS_Hide (hwnd, infoPtr);
1423 TOOLTIPS_RelayEvent (HWND hwnd, WPARAM wParam, LPARAM lParam)
1425 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1426 LPMSG lpMsg = (LPMSG)lParam;
1430 ERR("lpMsg == NULL!\n");
1434 switch (lpMsg->message) {
1435 case WM_LBUTTONDOWN:
1437 case WM_MBUTTONDOWN:
1439 case WM_RBUTTONDOWN:
1442 ScreenToClient (lpMsg->hwnd, &pt);
1443 infoPtr->nOldTool = infoPtr->nTool;
1444 infoPtr->nTool = TOOLTIPS_GetToolFromPoint (infoPtr, lpMsg->hwnd, &pt);
1445 TRACE("tool (%x) %d %d\n",
1446 hwnd, infoPtr->nOldTool, infoPtr->nTool);
1447 TOOLTIPS_Hide (hwnd, infoPtr);
1452 ScreenToClient (lpMsg->hwnd, &pt);
1453 infoPtr->nOldTool = infoPtr->nTool;
1454 infoPtr->nTool = TOOLTIPS_GetToolFromPoint (infoPtr, lpMsg->hwnd, &pt);
1455 TRACE("tool (%x) %d %d\n",
1456 hwnd, infoPtr->nOldTool, infoPtr->nTool);
1457 TRACE("WM_MOUSEMOVE (%04x %ld %ld)\n",
1459 if ((infoPtr->bActive) && (infoPtr->nTool != infoPtr->nOldTool)) {
1460 if (infoPtr->nOldTool == -1) {
1461 SetTimer (hwnd, ID_TIMERSHOW, infoPtr->nInitialTime, 0);
1462 TRACE("timer 1 started!\n");
1466 * Need to set nCurrentTool to nOldTool so we hide the tool.
1467 * nTool and nOldTool values change when the mouse leaves the window.
1468 * If using TTM_UPDATETIPTEXT we can end up with an nCurrentTool = -1 if the
1469 * text can't be found, thus the tooltip would never be hidden.
1471 if (infoPtr->nTool != infoPtr->nOldTool)
1472 infoPtr->nCurrentTool = infoPtr->nOldTool;
1473 TOOLTIPS_Hide (hwnd, infoPtr);
1474 SetTimer (hwnd, ID_TIMERSHOW, infoPtr->nReshowTime, 0);
1475 TRACE("timer 2 started!\n");
1478 if (infoPtr->nCurrentTool != -1) {
1479 SetTimer (hwnd, ID_TIMERLEAVE, 100, 0);
1480 TRACE("timer 3 started!\n");
1490 TOOLTIPS_SetDelayTime (HWND hwnd, WPARAM wParam, LPARAM lParam)
1492 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1493 INT nTime = (INT)LOWORD(lParam);
1496 case TTDT_AUTOMATIC:
1498 infoPtr->nAutomaticTime = 500;
1499 infoPtr->nReshowTime = 100;
1500 infoPtr->nAutoPopTime = 5000;
1501 infoPtr->nInitialTime = 500;
1504 infoPtr->nAutomaticTime = nTime;
1505 infoPtr->nReshowTime = nTime / 5;
1506 infoPtr->nAutoPopTime = nTime * 10;
1507 infoPtr->nInitialTime = nTime;
1512 infoPtr->nReshowTime = nTime;
1516 infoPtr->nAutoPopTime = nTime;
1520 infoPtr->nInitialTime = nTime;
1529 TOOLTIPS_SetMargin (HWND hwnd, WPARAM wParam, LPARAM lParam)
1531 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1532 LPRECT lpRect = (LPRECT)lParam;
1534 infoPtr->rcMargin.left = lpRect->left;
1535 infoPtr->rcMargin.right = lpRect->right;
1536 infoPtr->rcMargin.bottom = lpRect->bottom;
1537 infoPtr->rcMargin.top = lpRect->top;
1543 inline static LRESULT
1544 TOOLTIPS_SetMaxTipWidth (HWND hwnd, WPARAM wParam, LPARAM lParam)
1546 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1547 INT nTemp = infoPtr->nMaxTipWidth;
1549 infoPtr->nMaxTipWidth = (INT)lParam;
1555 inline static LRESULT
1556 TOOLTIPS_SetTipBkColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
1558 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1560 infoPtr->clrBk = (COLORREF)wParam;
1566 inline static LRESULT
1567 TOOLTIPS_SetTipTextColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
1569 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1571 infoPtr->clrText = (COLORREF)wParam;
1578 TOOLTIPS_SetToolInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
1580 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1581 LPTTTOOLINFOA lpToolInfo = (LPTTTOOLINFOA)lParam;
1582 TTTOOL_INFO *toolPtr;
1585 if (lpToolInfo == NULL)
1587 if (lpToolInfo->cbSize < TTTOOLINFO_V1_SIZEA)
1590 nTool = TOOLTIPS_GetToolFromInfoA (infoPtr, lpToolInfo);
1591 if (nTool == -1) return 0;
1593 TRACE("tool %d\n", nTool);
1595 toolPtr = &infoPtr->tools[nTool];
1597 /* copy tool data */
1598 toolPtr->uFlags = lpToolInfo->uFlags;
1599 toolPtr->hwnd = lpToolInfo->hwnd;
1600 toolPtr->uId = lpToolInfo->uId;
1601 toolPtr->rect = lpToolInfo->rect;
1602 toolPtr->hinst = lpToolInfo->hinst;
1604 if ((lpToolInfo->hinst) && (HIWORD((INT)lpToolInfo->lpszText) == 0)) {
1605 TRACE("set string id %x!\n", (INT)lpToolInfo->lpszText);
1606 toolPtr->lpszText = (LPWSTR)lpToolInfo->lpszText;
1608 else if (lpToolInfo->lpszText) {
1609 if (lpToolInfo->lpszText == LPSTR_TEXTCALLBACKA)
1610 toolPtr->lpszText = LPSTR_TEXTCALLBACKW;
1612 if ( (toolPtr->lpszText) &&
1613 (HIWORD((INT)toolPtr->lpszText) != 0) ) {
1614 COMCTL32_Free (toolPtr->lpszText);
1615 toolPtr->lpszText = NULL;
1617 if (lpToolInfo->lpszText) {
1618 INT len = lstrlenA (lpToolInfo->lpszText);
1619 toolPtr->lpszText = COMCTL32_Alloc ((len+1)*sizeof(WCHAR));
1620 lstrcpyAtoW (toolPtr->lpszText, lpToolInfo->lpszText);
1625 if (lpToolInfo->cbSize >= sizeof(TTTOOLINFOA))
1626 toolPtr->lParam = lpToolInfo->lParam;
1633 TOOLTIPS_SetToolInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
1635 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1636 LPTTTOOLINFOW lpToolInfo = (LPTTTOOLINFOW)lParam;
1637 TTTOOL_INFO *toolPtr;
1640 if (lpToolInfo == NULL)
1642 if (lpToolInfo->cbSize < TTTOOLINFO_V1_SIZEW)
1645 nTool = TOOLTIPS_GetToolFromInfoW (infoPtr, lpToolInfo);
1646 if (nTool == -1) return 0;
1648 TRACE("tool %d\n", nTool);
1650 toolPtr = &infoPtr->tools[nTool];
1652 /* copy tool data */
1653 toolPtr->uFlags = lpToolInfo->uFlags;
1654 toolPtr->hwnd = lpToolInfo->hwnd;
1655 toolPtr->uId = lpToolInfo->uId;
1656 toolPtr->rect = lpToolInfo->rect;
1657 toolPtr->hinst = lpToolInfo->hinst;
1659 if ((lpToolInfo->hinst) && (HIWORD((INT)lpToolInfo->lpszText) == 0)) {
1660 TRACE("set string id %x!\n", (INT)lpToolInfo->lpszText);
1661 toolPtr->lpszText = lpToolInfo->lpszText;
1663 else if (lpToolInfo->lpszText) {
1664 if (lpToolInfo->lpszText == LPSTR_TEXTCALLBACKW)
1665 toolPtr->lpszText = LPSTR_TEXTCALLBACKW;
1667 if ( (toolPtr->lpszText) &&
1668 (HIWORD((INT)toolPtr->lpszText) != 0) ) {
1669 COMCTL32_Free (toolPtr->lpszText);
1670 toolPtr->lpszText = NULL;
1672 if (lpToolInfo->lpszText) {
1673 INT len = lstrlenW (lpToolInfo->lpszText);
1674 toolPtr->lpszText = COMCTL32_Alloc ((len+1)*sizeof(WCHAR));
1675 lstrcpyW (toolPtr->lpszText, lpToolInfo->lpszText);
1680 if (lpToolInfo->cbSize >= sizeof(TTTOOLINFOW))
1681 toolPtr->lParam = lpToolInfo->lParam;
1688 TOOLTIPS_TrackActivate (HWND hwnd, WPARAM wParam, LPARAM lParam)
1690 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1691 LPTTTOOLINFOA lpToolInfo = (LPTTTOOLINFOA)lParam;
1693 if (lpToolInfo == NULL)
1695 if (lpToolInfo->cbSize < TTTOOLINFO_V1_SIZEA)
1700 infoPtr->nTrackTool = TOOLTIPS_GetToolFromInfoA (infoPtr, lpToolInfo);
1701 if (infoPtr->nTrackTool != -1) {
1702 TRACE("activated!\n");
1703 infoPtr->bTrackActive = TRUE;
1704 TOOLTIPS_TrackShow (hwnd, infoPtr);
1709 TOOLTIPS_TrackHide (hwnd, infoPtr);
1711 infoPtr->bTrackActive = FALSE;
1712 infoPtr->nTrackTool = -1;
1714 TRACE("deactivated!\n");
1722 TOOLTIPS_TrackPosition (HWND hwnd, WPARAM wParam, LPARAM lParam)
1724 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1726 infoPtr->xTrackPos = (INT)LOWORD(lParam);
1727 infoPtr->yTrackPos = (INT)HIWORD(lParam);
1729 if (infoPtr->bTrackActive) {
1731 infoPtr->xTrackPos, infoPtr->yTrackPos);
1733 TOOLTIPS_TrackShow (hwnd, infoPtr);
1741 TOOLTIPS_Update (HWND hwnd, WPARAM wParam, LPARAM lParam)
1743 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1745 if (infoPtr->nCurrentTool != -1)
1746 UpdateWindow (hwnd);
1753 TOOLTIPS_UpdateTipTextA (HWND hwnd, WPARAM wParam, LPARAM lParam)
1755 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1756 LPTTTOOLINFOA lpToolInfo = (LPTTTOOLINFOA)lParam;
1757 TTTOOL_INFO *toolPtr;
1760 if (lpToolInfo == NULL)
1762 if (lpToolInfo->cbSize < TTTOOLINFO_V1_SIZEA)
1765 nTool = TOOLTIPS_GetToolFromInfoA (infoPtr, lpToolInfo);
1766 if (nTool == -1) return 0;
1768 TRACE("tool %d\n", nTool);
1770 toolPtr = &infoPtr->tools[nTool];
1772 /* copy tool text */
1773 toolPtr->hinst = lpToolInfo->hinst;
1775 if ((lpToolInfo->hinst) && (HIWORD((INT)lpToolInfo->lpszText) == 0)){
1776 toolPtr->lpszText = (LPWSTR)lpToolInfo->lpszText;
1778 else if (lpToolInfo->lpszText) {
1779 if (lpToolInfo->lpszText == LPSTR_TEXTCALLBACKA)
1780 toolPtr->lpszText = LPSTR_TEXTCALLBACKW;
1782 if ( (toolPtr->lpszText) &&
1783 (HIWORD((INT)toolPtr->lpszText) != 0) ) {
1784 COMCTL32_Free (toolPtr->lpszText);
1785 toolPtr->lpszText = NULL;
1787 if (lpToolInfo->lpszText) {
1788 INT len = lstrlenA (lpToolInfo->lpszText);
1789 toolPtr->lpszText = COMCTL32_Alloc ((len+1)*sizeof(WCHAR));
1790 lstrcpyAtoW (toolPtr->lpszText, lpToolInfo->lpszText);
1796 if (infoPtr->bActive)
1797 TOOLTIPS_Show (hwnd, infoPtr);
1798 else if (infoPtr->bTrackActive)
1799 TOOLTIPS_TrackShow (hwnd, infoPtr);
1806 TOOLTIPS_UpdateTipTextW (HWND hwnd, WPARAM wParam, LPARAM lParam)
1808 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1809 LPTTTOOLINFOW lpToolInfo = (LPTTTOOLINFOW)lParam;
1810 TTTOOL_INFO *toolPtr;
1813 if (lpToolInfo == NULL)
1815 if (lpToolInfo->cbSize < TTTOOLINFO_V1_SIZEW)
1818 nTool = TOOLTIPS_GetToolFromInfoW (infoPtr, lpToolInfo);
1822 TRACE("tool %d\n", nTool);
1824 toolPtr = &infoPtr->tools[nTool];
1826 /* copy tool text */
1827 toolPtr->hinst = lpToolInfo->hinst;
1829 if ((lpToolInfo->hinst) && (HIWORD((INT)lpToolInfo->lpszText) == 0)){
1830 toolPtr->lpszText = lpToolInfo->lpszText;
1832 else if (lpToolInfo->lpszText) {
1833 if (lpToolInfo->lpszText == LPSTR_TEXTCALLBACKW)
1834 toolPtr->lpszText = LPSTR_TEXTCALLBACKW;
1836 if ( (toolPtr->lpszText) &&
1837 (HIWORD((INT)toolPtr->lpszText) != 0) ) {
1838 COMCTL32_Free (toolPtr->lpszText);
1839 toolPtr->lpszText = NULL;
1841 if (lpToolInfo->lpszText) {
1842 INT len = lstrlenW (lpToolInfo->lpszText);
1843 toolPtr->lpszText = COMCTL32_Alloc ((len+1)*sizeof(WCHAR));
1844 lstrcpyW (toolPtr->lpszText, lpToolInfo->lpszText);
1850 if (infoPtr->bActive)
1851 TOOLTIPS_Show (hwnd, infoPtr);
1852 else if (infoPtr->bTrackActive)
1853 TOOLTIPS_TrackShow (hwnd, infoPtr);
1860 TOOLTIPS_WindowFromPoint (HWND hwnd, WPARAM wParam, LPARAM lParam)
1862 return WindowFromPoint (*((LPPOINT)lParam));
1868 TOOLTIPS_Create (HWND hwnd, WPARAM wParam, LPARAM lParam)
1870 TOOLTIPS_INFO *infoPtr;
1871 NONCLIENTMETRICSA nclm;
1874 /* allocate memory for info structure */
1875 infoPtr = (TOOLTIPS_INFO *)COMCTL32_Alloc (sizeof(TOOLTIPS_INFO));
1876 SetWindowLongA (hwnd, 0, (DWORD)infoPtr);
1878 /* initialize info structure */
1879 infoPtr->bActive = TRUE;
1880 infoPtr->bTrackActive = FALSE;
1881 infoPtr->clrBk = GetSysColor (COLOR_INFOBK);
1882 infoPtr->clrText = GetSysColor (COLOR_INFOTEXT);
1884 nclm.cbSize = sizeof(NONCLIENTMETRICSA);
1885 SystemParametersInfoA (SPI_GETNONCLIENTMETRICS, 0, &nclm, 0);
1886 infoPtr->hFont = CreateFontIndirectA (&nclm.lfStatusFont);
1888 infoPtr->nMaxTipWidth = -1;
1889 infoPtr->nTool = -1;
1890 infoPtr->nOldTool = -1;
1891 infoPtr->nCurrentTool = -1;
1892 infoPtr->nTrackTool = -1;
1894 infoPtr->nAutomaticTime = 500;
1895 infoPtr->nReshowTime = 100;
1896 infoPtr->nAutoPopTime = 5000;
1897 infoPtr->nInitialTime = 500;
1899 nResult = (INT) SendMessageA (GetParent (hwnd), WM_NOTIFYFORMAT,
1900 (WPARAM)hwnd, (LPARAM)NF_QUERY);
1901 if (nResult == NFR_ANSI) {
1902 infoPtr->bNotifyUnicode = FALSE;
1903 TRACE(" -- WM_NOTIFYFORMAT returns: NFR_ANSI\n");
1905 else if (nResult == NFR_UNICODE) {
1906 infoPtr->bNotifyUnicode = TRUE;
1907 TRACE(" -- WM_NOTIFYFORMAT returns: NFR_UNICODE\n");
1910 ERR (" -- WM_NOTIFYFORMAT returns: error!\n");
1913 SetWindowPos (hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOZORDER | SWP_HIDEWINDOW | SWP_NOACTIVATE);
1920 TOOLTIPS_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
1922 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1923 TTTOOL_INFO *toolPtr;
1927 if (infoPtr->tools) {
1928 for (i = 0; i < infoPtr->uNumTools; i++) {
1929 toolPtr = &infoPtr->tools[i];
1930 if ((toolPtr->hinst) && (toolPtr->lpszText)) {
1931 if ( (toolPtr->lpszText != LPSTR_TEXTCALLBACKW) &&
1932 (HIWORD((INT)toolPtr->lpszText) != 0) )
1934 COMCTL32_Free (toolPtr->lpszText);
1935 toolPtr->lpszText = NULL;
1939 /* remove subclassing */
1940 if (toolPtr->uFlags & TTF_SUBCLASS) {
1941 LPTT_SUBCLASS_INFO lpttsi;
1943 if (toolPtr->uFlags & TTF_IDISHWND)
1944 lpttsi = (LPTT_SUBCLASS_INFO)GetPropA ((HWND)toolPtr->uId, COMCTL32_aSubclass);
1946 lpttsi = (LPTT_SUBCLASS_INFO)GetPropA (toolPtr->hwnd, COMCTL32_aSubclass);
1949 SetWindowLongA ((HWND)toolPtr->uId, GWL_WNDPROC,
1950 (LONG)lpttsi->wpOrigProc);
1951 RemovePropA ((HWND)toolPtr->uId, COMCTL32_aSubclass);
1952 COMCTL32_Free (&lpttsi);
1956 COMCTL32_Free (infoPtr->tools);
1960 DeleteObject (infoPtr->hFont);
1962 /* free tool tips info data */
1963 COMCTL32_Free (infoPtr);
1964 SetWindowLongA(hwnd, 0, 0);
1970 TOOLTIPS_EraseBackground (HWND hwnd, WPARAM wParam, LPARAM lParam)
1972 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1976 hBrush = CreateSolidBrush (infoPtr->clrBk);
1977 GetClientRect (hwnd, &rect);
1978 FillRect ((HDC)wParam, &rect, hBrush);
1979 DeleteObject (hBrush);
1986 TOOLTIPS_GetFont (HWND hwnd, WPARAM wParam, LPARAM lParam)
1988 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1990 return infoPtr->hFont;
1995 TOOLTIPS_MouseMessage (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1997 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1999 TOOLTIPS_Hide (hwnd, infoPtr);
2006 TOOLTIPS_NCCreate (HWND hwnd, WPARAM wParam, LPARAM lParam)
2008 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
2010 dwStyle &= 0x0000FFFF;
2011 dwStyle |= (WS_POPUP | WS_BORDER | WS_CLIPSIBLINGS);
2012 SetWindowLongA (hwnd, GWL_STYLE, dwStyle);
2019 TOOLTIPS_NCHitTest (HWND hwnd, WPARAM wParam, LPARAM lParam)
2021 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
2022 INT nTool = (infoPtr->bTrackActive) ? infoPtr->nTrackTool : infoPtr->nTool;
2024 TRACE(" nTool=%d\n", nTool);
2026 if ((nTool > -1) && (nTool < infoPtr->uNumTools)) {
2027 if (infoPtr->tools[nTool].uFlags & TTF_TRANSPARENT) {
2028 TRACE("-- in transparent mode!\n");
2029 return HTTRANSPARENT;
2033 return DefWindowProcA (hwnd, WM_NCHITTEST, wParam, lParam);
2038 TOOLTIPS_NotifyFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
2040 FIXME ("hwnd=%x wParam=%x lParam=%lx\n", hwnd, wParam, lParam);
2047 TOOLTIPS_Paint (HWND hwnd, WPARAM wParam, LPARAM lParam)
2052 hdc = (wParam == 0) ? BeginPaint (hwnd, &ps) : (HDC)wParam;
2053 TOOLTIPS_Refresh (hwnd, hdc);
2055 EndPaint (hwnd, &ps);
2061 TOOLTIPS_SetFont (HWND hwnd, WPARAM wParam, LPARAM lParam)
2063 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
2065 infoPtr->hFont = (HFONT)wParam;
2067 if ((LOWORD(lParam)) & (infoPtr->nCurrentTool != -1)) {
2068 FIXME("full redraw needed!\n");
2073 /******************************************************************
2074 * TOOLTIPS_OnWMGetTextLength
2076 * This function is called when the tooltip receive a
2077 * WM_GETTEXTLENGTH message.
2081 * returns the length, in characters, of the tip text
2082 ******************************************************************/
2084 TOOLTIPS_OnWMGetTextLength(HWND hwnd, WPARAM wParam, LPARAM lParam)
2086 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
2087 return lstrlenW(infoPtr->szTipText);
2090 /******************************************************************
2091 * TOOLTIPS_OnWMGetText
2093 * This function is called when the tooltip receive a
2094 * WM_GETTEXT message.
2095 * wParam : specifies the maximum number of characters to be copied
2096 * lParam : is the pointer to the buffer that will receive
2099 * returns the number of characters copied
2100 ******************************************************************/
2102 TOOLTIPS_OnWMGetText (HWND hwnd, WPARAM wParam, LPARAM lParam)
2104 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
2107 if(!infoPtr || !(infoPtr->szTipText))
2110 length = lstrlenW(infoPtr->szTipText);
2111 /* When wParam is smaller than the lenght of the tip text
2112 copy wParam characters of the tip text and return wParam */
2115 lstrcpynWtoA((LPSTR)lParam, infoPtr->szTipText,(UINT)wParam);
2118 lstrcpyWtoA((LPSTR)lParam, infoPtr->szTipText);
2123 TOOLTIPS_Timer (HWND hwnd, WPARAM wParam, LPARAM lParam)
2125 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
2127 TRACE("timer %d (%x) expired!\n", wParam, hwnd);
2132 KillTimer (hwnd, ID_TIMERSHOW);
2133 if (TOOLTIPS_CheckTool (hwnd, TRUE) == infoPtr->nTool)
2134 TOOLTIPS_Show (hwnd, infoPtr);
2138 TOOLTIPS_Hide (hwnd, infoPtr);
2142 KillTimer (hwnd, ID_TIMERLEAVE);
2143 if (TOOLTIPS_CheckTool (hwnd, FALSE) == -1) {
2144 infoPtr->nTool = -1;
2145 infoPtr->nOldTool = -1;
2146 TOOLTIPS_Hide (hwnd, infoPtr);
2155 TOOLTIPS_WinIniChange (HWND hwnd, WPARAM wParam, LPARAM lParam)
2157 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
2158 NONCLIENTMETRICSA nclm;
2160 infoPtr->clrBk = GetSysColor (COLOR_INFOBK);
2161 infoPtr->clrText = GetSysColor (COLOR_INFOTEXT);
2163 DeleteObject (infoPtr->hFont);
2164 nclm.cbSize = sizeof(NONCLIENTMETRICSA);
2165 SystemParametersInfoA (SPI_GETNONCLIENTMETRICS, 0, &nclm, 0);
2166 infoPtr->hFont = CreateFontIndirectA (&nclm.lfStatusFont);
2173 TOOLTIPS_SubclassProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2175 LPTT_SUBCLASS_INFO lpttsi =
2176 (LPTT_SUBCLASS_INFO)GetPropA (hwnd, COMCTL32_aSubclass);
2177 TOOLTIPS_INFO *infoPtr;
2181 case WM_LBUTTONDOWN:
2183 case WM_MBUTTONDOWN:
2185 case WM_RBUTTONDOWN:
2187 infoPtr = TOOLTIPS_GetInfoPtr(lpttsi->hwndToolTip);
2190 nTool = TOOLTIPS_GetToolFromMessage (infoPtr, hwnd);
2192 TRACE("subclassed mouse message %04x\n", uMsg);
2193 infoPtr->nOldTool = infoPtr->nTool;
2194 infoPtr->nTool = nTool;
2195 TOOLTIPS_Hide (lpttsi->hwndToolTip, infoPtr);
2199 infoPtr = TOOLTIPS_GetInfoPtr (lpttsi->hwndToolTip);
2202 nTool = TOOLTIPS_GetToolFromMessage (infoPtr, hwnd);
2204 TRACE("subclassed WM_MOUSEMOVE\n");
2205 infoPtr->nOldTool = infoPtr->nTool;
2206 infoPtr->nTool = nTool;
2208 if ((infoPtr->bActive) &&
2209 (infoPtr->nTool != infoPtr->nOldTool)) {
2210 if (infoPtr->nOldTool == -1) {
2211 SetTimer (hwnd, ID_TIMERSHOW,
2212 infoPtr->nInitialTime, 0);
2213 TRACE("timer 1 started!\n");
2216 TOOLTIPS_Hide (lpttsi->hwndToolTip, infoPtr);
2217 SetTimer (hwnd, ID_TIMERSHOW,
2218 infoPtr->nReshowTime, 0);
2219 TRACE("timer 2 started!\n");
2222 if (infoPtr->nCurrentTool != -1) {
2223 SetTimer (hwnd, ID_TIMERLEAVE, 100, 0);
2224 TRACE("timer 3 started!\n");
2229 return CallWindowProcA (lpttsi->wpOrigProc, hwnd, uMsg, wParam, lParam);
2233 static LRESULT CALLBACK
2234 TOOLTIPS_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2236 TRACE("hwnd=%x msg=%x wparam=%x lParam=%lx\n", hwnd, uMsg, wParam, lParam);
2237 if (!TOOLTIPS_GetInfoPtr(hwnd) && (uMsg != WM_CREATE) && (uMsg != WM_NCCREATE))
2238 return DefWindowProcA (hwnd, uMsg, wParam, lParam);
2242 return TOOLTIPS_Activate (hwnd, wParam, lParam);
2245 return TOOLTIPS_AddToolA (hwnd, wParam, lParam);
2248 return TOOLTIPS_AddToolW (hwnd, wParam, lParam);
2251 return TOOLTIPS_DelToolA (hwnd, wParam, lParam);
2254 return TOOLTIPS_DelToolW (hwnd, wParam, lParam);
2256 case TTM_ENUMTOOLSA:
2257 return TOOLTIPS_EnumToolsA (hwnd, wParam, lParam);
2259 case TTM_ENUMTOOLSW:
2260 return TOOLTIPS_EnumToolsW (hwnd, wParam, lParam);
2262 case TTM_GETCURRENTTOOLA:
2263 return TOOLTIPS_GetCurrentToolA (hwnd, wParam, lParam);
2265 case TTM_GETCURRENTTOOLW:
2266 return TOOLTIPS_GetCurrentToolW (hwnd, wParam, lParam);
2268 case TTM_GETDELAYTIME:
2269 return TOOLTIPS_GetDelayTime (hwnd, wParam, lParam);
2272 return TOOLTIPS_GetMargin (hwnd, wParam, lParam);
2274 case TTM_GETMAXTIPWIDTH:
2275 return TOOLTIPS_GetMaxTipWidth (hwnd, wParam, lParam);
2278 return TOOLTIPS_GetTextA (hwnd, wParam, lParam);
2281 return TOOLTIPS_GetTextW (hwnd, wParam, lParam);
2283 case TTM_GETTIPBKCOLOR:
2284 return TOOLTIPS_GetTipBkColor (hwnd, wParam, lParam);
2286 case TTM_GETTIPTEXTCOLOR:
2287 return TOOLTIPS_GetTipTextColor (hwnd, wParam, lParam);
2289 case TTM_GETTOOLCOUNT:
2290 return TOOLTIPS_GetToolCount (hwnd, wParam, lParam);
2292 case TTM_GETTOOLINFOA:
2293 return TOOLTIPS_GetToolInfoA (hwnd, wParam, lParam);
2295 case TTM_GETTOOLINFOW:
2296 return TOOLTIPS_GetToolInfoW (hwnd, wParam, lParam);
2299 return TOOLTIPS_HitTestA (hwnd, wParam, lParam);
2302 return TOOLTIPS_HitTestW (hwnd, wParam, lParam);
2304 case TTM_NEWTOOLRECTA:
2305 return TOOLTIPS_NewToolRectA (hwnd, wParam, lParam);
2307 case TTM_NEWTOOLRECTW:
2308 return TOOLTIPS_NewToolRectW (hwnd, wParam, lParam);
2311 return TOOLTIPS_Pop (hwnd, wParam, lParam);
2313 case TTM_RELAYEVENT:
2314 return TOOLTIPS_RelayEvent (hwnd, wParam, lParam);
2316 case TTM_SETDELAYTIME:
2317 return TOOLTIPS_SetDelayTime (hwnd, wParam, lParam);
2320 return TOOLTIPS_SetMargin (hwnd, wParam, lParam);
2322 case TTM_SETMAXTIPWIDTH:
2323 return TOOLTIPS_SetMaxTipWidth (hwnd, wParam, lParam);
2325 case TTM_SETTIPBKCOLOR:
2326 return TOOLTIPS_SetTipBkColor (hwnd, wParam, lParam);
2328 case TTM_SETTIPTEXTCOLOR:
2329 return TOOLTIPS_SetTipTextColor (hwnd, wParam, lParam);
2331 case TTM_SETTOOLINFOA:
2332 return TOOLTIPS_SetToolInfoA (hwnd, wParam, lParam);
2334 case TTM_SETTOOLINFOW:
2335 return TOOLTIPS_SetToolInfoW (hwnd, wParam, lParam);
2337 case TTM_TRACKACTIVATE:
2338 return TOOLTIPS_TrackActivate (hwnd, wParam, lParam);
2340 case TTM_TRACKPOSITION:
2341 return TOOLTIPS_TrackPosition (hwnd, wParam, lParam);
2344 return TOOLTIPS_Update (hwnd, wParam, lParam);
2346 case TTM_UPDATETIPTEXTA:
2347 return TOOLTIPS_UpdateTipTextA (hwnd, wParam, lParam);
2349 case TTM_UPDATETIPTEXTW:
2350 return TOOLTIPS_UpdateTipTextW (hwnd, wParam, lParam);
2352 case TTM_WINDOWFROMPOINT:
2353 return TOOLTIPS_WindowFromPoint (hwnd, wParam, lParam);
2357 return TOOLTIPS_Create (hwnd, wParam, lParam);
2360 return TOOLTIPS_Destroy (hwnd, wParam, lParam);
2363 return TOOLTIPS_EraseBackground (hwnd, wParam, lParam);
2366 return TOOLTIPS_GetFont (hwnd, wParam, lParam);
2369 return TOOLTIPS_OnWMGetText (hwnd, wParam, lParam);
2371 case WM_GETTEXTLENGTH:
2372 return TOOLTIPS_OnWMGetTextLength (hwnd, wParam, lParam);
2375 case WM_LBUTTONDOWN:
2377 case WM_MBUTTONDOWN:
2379 case WM_RBUTTONDOWN:
2382 return TOOLTIPS_MouseMessage (hwnd, uMsg, wParam, lParam);
2385 return TOOLTIPS_NCCreate (hwnd, wParam, lParam);
2388 return TOOLTIPS_NCHitTest (hwnd, wParam, lParam);
2390 case WM_NOTIFYFORMAT:
2391 return TOOLTIPS_NotifyFormat (hwnd, wParam, lParam);
2394 return TOOLTIPS_Paint (hwnd, wParam, lParam);
2397 return TOOLTIPS_SetFont (hwnd, wParam, lParam);
2400 return TOOLTIPS_Timer (hwnd, wParam, lParam);
2402 case WM_WININICHANGE:
2403 return TOOLTIPS_WinIniChange (hwnd, wParam, lParam);
2406 if (uMsg >= WM_USER)
2407 ERR("unknown msg %04x wp=%08x lp=%08lx\n",
2408 uMsg, wParam, lParam);
2409 return DefWindowProcA (hwnd, uMsg, wParam, lParam);
2416 TOOLTIPS_Register (void)
2420 ZeroMemory (&wndClass, sizeof(WNDCLASSA));
2421 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS | CS_SAVEBITS;
2422 wndClass.lpfnWndProc = (WNDPROC)TOOLTIPS_WindowProc;
2423 wndClass.cbClsExtra = 0;
2424 wndClass.cbWndExtra = sizeof(TOOLTIPS_INFO *);
2425 wndClass.hCursor = LoadCursorA (0, IDC_ARROWA);
2426 wndClass.hbrBackground = 0;
2427 wndClass.lpszClassName = TOOLTIPS_CLASSA;
2429 RegisterClassA (&wndClass);
2434 TOOLTIPS_Unregister (void)
2436 UnregisterClassA (TOOLTIPS_CLASSA, (HINSTANCE)NULL);