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.
18 * One important point to remember is that tools don't necessarily get
19 * a WM_MOUSEMOVE once the cursor leaves the tool, an example is when
20 * a tool sets TTF_IDISHWND (i.e. an entire window is a tool) because
21 * here WM_MOUSEMOVEs only get sent when the cursor is inside the
22 * client area. Therefore the only reliable way to know that the
23 * cursor has left a tool is to keep a timer running and check the
24 * position every time it expires. This is the role of timer
28 * On entering a tool (detected in a relayed WM_MOUSEMOVE) we start
29 * ID_TIMERSHOW, if this times out and we're still in the tool we show
30 * the tip. On showing a tip we start both ID_TIMERPOP and
31 * ID_TIMERLEAVE. On hiding a tooltip we kill ID_TIMERPOP.
32 * ID_TIMERPOP is restarted on every relayed WM_MOUSEMOVE. If
33 * ID_TIMERPOP expires the tool is hidden and ID_TIMERPOP is killed.
34 * ID_TIMERLEAVE remains running - this is important as we need to
35 * determine when the cursor leaves the tool.
37 * When ID_TIMERLEAVE expires or on a relayed WM_MOUSEMOVE if we're
38 * still in the tool do nothing (apart from restart ID_TIMERPOP if
39 * this is a WM_MOUSEMOVE) (ID_TIMERLEAVE remains running). If we've
40 * left the tool and entered another one then hide the tip and start
41 * ID_TIMERSHOW with time ReshowTime and kill ID_TIMERLEAVE. If we're
42 * outside all tools hide the tip and kill ID_TIMERLEAVE. On Relayed
43 * mouse button messages hide the tip but leave ID_TIMERLEAVE running,
44 * this again will let us keep track of when the cursor leaves the
48 * infoPtr->nTool is the tool the mouse was on on the last relayed MM
49 * or timer expiry or -1 if the mouse was not on a tool.
51 * infoPtr->nCurrentTool is the tool for which the tip is currently
52 * displaying text for or -1 if the tip is not shown. Actually this
53 * will only ever be infoPtr-nTool or -1, so it could be changed to a
63 #include "wine/unicode.h"
65 #include "debugtools.h"
67 DEFAULT_DEBUG_CHANNEL(tooltips
);
74 } TT_SUBCLASS_INFO
, *LPTT_SUBCLASS_INFO
;
91 WCHAR szTipText
[INFOTIPSIZE
];
113 #define ID_TIMERSHOW 1 /* show delay timer */
114 #define ID_TIMERPOP 2 /* auto pop timer */
115 #define ID_TIMERLEAVE 3 /* tool leave timer */
118 extern LPSTR COMCTL32_aSubclass
; /* global subclassing atom */
120 /* property name of tooltip window handle */
121 /*#define TT_SUBCLASS_PROP "CC32SubclassInfo" */
123 #define TOOLTIPS_GetInfoPtr(hWindow) ((TOOLTIPS_INFO *)GetWindowLongA (hWindow, 0))
127 TOOLTIPS_SubclassProc (HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
);
131 TOOLTIPS_Refresh (HWND hwnd
, HDC hdc
)
133 TOOLTIPS_INFO
*infoPtr
= TOOLTIPS_GetInfoPtr(hwnd
);
138 UINT uFlags
= DT_EXTERNALLEADING
;
140 if (infoPtr
->nMaxTipWidth
> -1)
141 uFlags
|= DT_WORDBREAK
;
142 if (GetWindowLongA (hwnd
, GWL_STYLE
) & TTS_NOPREFIX
)
143 uFlags
|= DT_NOPREFIX
;
144 GetClientRect (hwnd
, &rc
);
146 /* fill the background */
147 hBrush
= CreateSolidBrush (infoPtr
->clrBk
);
148 FillRect (hdc
, &rc
, hBrush
);
149 DeleteObject (hBrush
);
151 /* calculate text rectangle */
152 rc
.left
+= (2 + infoPtr
->rcMargin
.left
);
153 rc
.top
+= (2 + infoPtr
->rcMargin
.top
);
154 rc
.right
-= (2 + infoPtr
->rcMargin
.right
);
155 rc
.bottom
-= (2 + infoPtr
->rcMargin
.bottom
);
158 oldBkMode
= SetBkMode (hdc
, TRANSPARENT
);
159 SetTextColor (hdc
, infoPtr
->clrText
);
160 hOldFont
= SelectObject (hdc
, infoPtr
->hFont
);
161 DrawTextW (hdc
, infoPtr
->szTipText
, -1, &rc
, uFlags
);
162 SelectObject (hdc
, hOldFont
);
163 if (oldBkMode
!= TRANSPARENT
)
164 SetBkMode (hdc
, oldBkMode
);
169 TOOLTIPS_GetTipText (HWND hwnd
, TOOLTIPS_INFO
*infoPtr
, INT nTool
)
171 TTTOOL_INFO
*toolPtr
= &infoPtr
->tools
[nTool
];
173 if ((toolPtr
->hinst
) && (HIWORD((UINT
)toolPtr
->lpszText
) == 0)) {
174 /* load a resource */
175 TRACE("load res string %x %x\n",
176 toolPtr
->hinst
, (int)toolPtr
->lpszText
);
177 LoadStringW (toolPtr
->hinst
, (UINT
)toolPtr
->lpszText
,
178 infoPtr
->szTipText
, INFOTIPSIZE
);
180 else if (toolPtr
->lpszText
) {
181 if (toolPtr
->lpszText
== LPSTR_TEXTCALLBACKW
) {
182 NMTTDISPINFOA ttnmdi
;
184 /* fill NMHDR struct */
185 ZeroMemory (&ttnmdi
, sizeof(NMTTDISPINFOA
));
186 ttnmdi
.hdr
.hwndFrom
= hwnd
;
187 ttnmdi
.hdr
.idFrom
= toolPtr
->uId
;
188 ttnmdi
.hdr
.code
= TTN_GETDISPINFOA
;
189 ttnmdi
.lpszText
= (LPSTR
)&ttnmdi
.szText
;
190 ttnmdi
.uFlags
= toolPtr
->uFlags
;
191 ttnmdi
.lParam
= toolPtr
->lParam
;
193 TRACE("hdr.idFrom = %x\n", ttnmdi
.hdr
.idFrom
);
194 SendMessageA (toolPtr
->hwnd
, WM_NOTIFY
,
195 (WPARAM
)toolPtr
->uId
, (LPARAM
)&ttnmdi
);
197 if ((ttnmdi
.hinst
) && (HIWORD((UINT
)ttnmdi
.lpszText
) == 0)) {
198 LoadStringW (ttnmdi
.hinst
, (UINT
)ttnmdi
.lpszText
,
199 infoPtr
->szTipText
, INFOTIPSIZE
);
200 if (ttnmdi
.uFlags
& TTF_DI_SETITEM
) {
201 toolPtr
->hinst
= ttnmdi
.hinst
;
202 toolPtr
->lpszText
= (LPWSTR
)ttnmdi
.lpszText
;
205 else if (ttnmdi
.szText
[0]) {
206 MultiByteToWideChar(CP_ACP
, 0, ttnmdi
.szText
, 80,
207 infoPtr
->szTipText
, INFOTIPSIZE
);
208 if (ttnmdi
.uFlags
& TTF_DI_SETITEM
) {
209 INT len
= MultiByteToWideChar(CP_ACP
, 0, ttnmdi
.szText
,
212 toolPtr
->lpszText
= COMCTL32_Alloc (len
* sizeof(WCHAR
));
213 MultiByteToWideChar(CP_ACP
, 0, ttnmdi
.szText
, 80,
214 toolPtr
->lpszText
, len
);
217 else if (ttnmdi
.lpszText
== 0) {
218 /* no text available */
219 infoPtr
->szTipText
[0] = L
'\0';
221 else if (ttnmdi
.lpszText
!= LPSTR_TEXTCALLBACKA
) {
222 MultiByteToWideChar(CP_ACP
, 0, ttnmdi
.lpszText
, -1,
223 infoPtr
->szTipText
, INFOTIPSIZE
);
224 if (ttnmdi
.uFlags
& TTF_DI_SETITEM
) {
225 INT len
= MultiByteToWideChar(CP_ACP
, 0, ttnmdi
.lpszText
,
228 toolPtr
->lpszText
= COMCTL32_Alloc (len
* sizeof(WCHAR
));
229 MultiByteToWideChar(CP_ACP
, 0, ttnmdi
.lpszText
, -1,
230 toolPtr
->lpszText
, len
);
234 ERR("recursive text callback!\n");
235 infoPtr
->szTipText
[0] = '\0';
239 /* the item is a usual (unicode) text */
240 lstrcpynW (infoPtr
->szTipText
, toolPtr
->lpszText
, INFOTIPSIZE
);
244 /* no text available */
245 infoPtr
->szTipText
[0] = L
'\0';
248 TRACE("%s\n", debugstr_w(infoPtr
->szTipText
));
253 TOOLTIPS_CalcTipSize (HWND hwnd
, TOOLTIPS_INFO
*infoPtr
, LPSIZE lpSize
)
257 UINT uFlags
= DT_EXTERNALLEADING
| DT_CALCRECT
;
258 RECT rc
= {0, 0, 0, 0};
260 if (infoPtr
->nMaxTipWidth
> -1) {
261 rc
.right
= infoPtr
->nMaxTipWidth
;
262 uFlags
|= DT_WORDBREAK
;
264 if (GetWindowLongA (hwnd
, GWL_STYLE
) & TTS_NOPREFIX
)
265 uFlags
|= DT_NOPREFIX
;
266 TRACE("%s\n", debugstr_w(infoPtr
->szTipText
));
269 hOldFont
= SelectObject (hdc
, infoPtr
->hFont
);
270 DrawTextW (hdc
, infoPtr
->szTipText
, -1, &rc
, uFlags
);
271 SelectObject (hdc
, hOldFont
);
272 ReleaseDC (hwnd
, hdc
);
274 lpSize
->cx
= rc
.right
- rc
.left
+ 4 +
275 infoPtr
->rcMargin
.left
+ infoPtr
->rcMargin
.right
;
276 lpSize
->cy
= rc
.bottom
- rc
.top
+ 4 +
277 infoPtr
->rcMargin
.bottom
+ infoPtr
->rcMargin
.top
;
282 TOOLTIPS_Show (HWND hwnd
, TOOLTIPS_INFO
*infoPtr
)
284 TTTOOL_INFO
*toolPtr
;
289 if (infoPtr
->nTool
== -1) {
290 TRACE("invalid tool (-1)!\n");
294 infoPtr
->nCurrentTool
= infoPtr
->nTool
;
296 TRACE("Show tooltip pre %d! (%04x)\n", infoPtr
->nTool
, hwnd
);
298 TOOLTIPS_GetTipText (hwnd
, infoPtr
, infoPtr
->nCurrentTool
);
300 if (infoPtr
->szTipText
[0] == L
'\0') {
301 infoPtr
->nCurrentTool
= -1;
305 TRACE("Show tooltip %d!\n", infoPtr
->nCurrentTool
);
306 toolPtr
= &infoPtr
->tools
[infoPtr
->nCurrentTool
];
309 hdr
.idFrom
= toolPtr
->uId
;
311 SendMessageA (toolPtr
->hwnd
, WM_NOTIFY
,
312 (WPARAM
)toolPtr
->uId
, (LPARAM
)&hdr
);
314 TRACE("%s\n", debugstr_w(infoPtr
->szTipText
));
316 TOOLTIPS_CalcTipSize (hwnd
, infoPtr
, &size
);
317 TRACE("size %ld x %ld\n", size
.cx
, size
.cy
);
319 if (toolPtr
->uFlags
& TTF_CENTERTIP
) {
322 if (toolPtr
->uFlags
& TTF_IDISHWND
)
323 GetWindowRect ((HWND
)toolPtr
->uId
, &rc
);
326 MapWindowPoints (toolPtr
->hwnd
, (HWND
)0, (LPPOINT
)&rc
, 2);
328 rect
.left
= (rc
.left
+ rc
.right
- size
.cx
) / 2;
329 rect
.top
= rc
.bottom
+ 2;
332 GetCursorPos ((LPPOINT
)&rect
);
336 TRACE("pos %d - %d\n", rect
.left
, rect
.top
);
338 rect
.right
= rect
.left
+ size
.cx
;
339 rect
.bottom
= rect
.top
+ size
.cy
;
342 wndrect
.right
= GetSystemMetrics( SM_CXSCREEN
);
343 if( rect
.right
> wndrect
.right
) {
344 rect
.left
-= rect
.right
- wndrect
.right
+ 2;
345 rect
.right
= wndrect
.right
- 2;
347 wndrect
.bottom
= GetSystemMetrics( SM_CYSCREEN
);
348 if( rect
.bottom
> wndrect
.bottom
) {
351 if (toolPtr
->uFlags
& TTF_IDISHWND
)
352 GetWindowRect ((HWND
)toolPtr
->uId
, &rc
);
355 MapWindowPoints (toolPtr
->hwnd
, (HWND
)0, (LPPOINT
)&rc
, 2);
357 rect
.bottom
= rc
.top
- 2;
358 rect
.top
= rect
.bottom
- size
.cy
;
361 AdjustWindowRectEx (&rect
, GetWindowLongA (hwnd
, GWL_STYLE
),
362 FALSE
, GetWindowLongA (hwnd
, GWL_EXSTYLE
));
364 SetWindowPos (hwnd
, HWND_TOP
, rect
.left
, rect
.top
,
365 rect
.right
- rect
.left
, rect
.bottom
- rect
.top
,
366 SWP_SHOWWINDOW
| SWP_NOACTIVATE
);
368 /* repaint the tooltip */
369 InvalidateRect(hwnd
, NULL
, TRUE
);
372 SetTimer (hwnd
, ID_TIMERPOP
, infoPtr
->nAutoPopTime
, 0);
373 TRACE("timer 2 started!\n");
374 SetTimer (hwnd
, ID_TIMERLEAVE
, infoPtr
->nReshowTime
, 0);
375 TRACE("timer 3 started!\n");
380 TOOLTIPS_Hide (HWND hwnd
, TOOLTIPS_INFO
*infoPtr
)
382 TTTOOL_INFO
*toolPtr
;
385 TRACE("Hide tooltip %d! (%04x)\n", infoPtr
->nCurrentTool
, hwnd
);
387 if (infoPtr
->nCurrentTool
== -1)
390 toolPtr
= &infoPtr
->tools
[infoPtr
->nCurrentTool
];
391 KillTimer (hwnd
, ID_TIMERPOP
);
394 hdr
.idFrom
= toolPtr
->uId
;
396 SendMessageA (toolPtr
->hwnd
, WM_NOTIFY
,
397 (WPARAM
)toolPtr
->uId
, (LPARAM
)&hdr
);
399 infoPtr
->nCurrentTool
= -1;
401 SetWindowPos (hwnd
, HWND_TOP
, 0, 0, 0, 0,
402 SWP_NOZORDER
| SWP_HIDEWINDOW
| SWP_NOACTIVATE
);
407 TOOLTIPS_TrackShow (HWND hwnd
, TOOLTIPS_INFO
*infoPtr
)
409 TTTOOL_INFO
*toolPtr
;
414 if (infoPtr
->nTrackTool
== -1) {
415 TRACE("invalid tracking tool (-1)!\n");
419 TRACE("show tracking tooltip pre %d!\n", infoPtr
->nTrackTool
);
421 TOOLTIPS_GetTipText (hwnd
, infoPtr
, infoPtr
->nTrackTool
);
423 if (infoPtr
->szTipText
[0] == L
'\0') {
424 infoPtr
->nTrackTool
= -1;
428 TRACE("show tracking tooltip %d!\n", infoPtr
->nTrackTool
);
429 toolPtr
= &infoPtr
->tools
[infoPtr
->nTrackTool
];
432 hdr
.idFrom
= toolPtr
->uId
;
434 SendMessageA (toolPtr
->hwnd
, WM_NOTIFY
,
435 (WPARAM
)toolPtr
->uId
, (LPARAM
)&hdr
);
437 TRACE("%s\n", debugstr_w(infoPtr
->szTipText
));
439 TOOLTIPS_CalcTipSize (hwnd
, infoPtr
, &size
);
440 TRACE("size %ld x %ld\n", size
.cx
, size
.cy
);
442 if (toolPtr
->uFlags
& TTF_ABSOLUTE
) {
443 rect
.left
= infoPtr
->xTrackPos
;
444 rect
.top
= infoPtr
->yTrackPos
;
446 if (toolPtr
->uFlags
& TTF_CENTERTIP
) {
447 rect
.left
-= (size
.cx
/ 2);
448 rect
.top
-= (size
.cy
/ 2);
454 if (toolPtr
->uFlags
& TTF_IDISHWND
)
455 GetWindowRect ((HWND
)toolPtr
->uId
, &rcTool
);
457 rcTool
= toolPtr
->rect
;
458 MapWindowPoints (toolPtr
->hwnd
, (HWND
)0, (LPPOINT
)&rcTool
, 2);
461 GetCursorPos ((LPPOINT
)&rect
);
464 if (toolPtr
->uFlags
& TTF_CENTERTIP
) {
465 rect
.left
-= (size
.cx
/ 2);
466 rect
.top
-= (size
.cy
/ 2);
469 /* smart placement */
470 if ((rect
.left
+ size
.cx
> rcTool
.left
) && (rect
.left
< rcTool
.right
) &&
471 (rect
.top
+ size
.cy
> rcTool
.top
) && (rect
.top
< rcTool
.bottom
))
472 rect
.left
= rcTool
.right
;
475 TRACE("pos %d - %d\n", rect
.left
, rect
.top
);
477 rect
.right
= rect
.left
+ size
.cx
;
478 rect
.bottom
= rect
.top
+ size
.cy
;
480 AdjustWindowRectEx (&rect
, GetWindowLongA (hwnd
, GWL_STYLE
),
481 FALSE
, GetWindowLongA (hwnd
, GWL_EXSTYLE
));
483 SetWindowPos (hwnd
, HWND_TOP
, rect
.left
, rect
.top
,
484 rect
.right
- rect
.left
, rect
.bottom
- rect
.top
,
485 SWP_SHOWWINDOW
| SWP_NOACTIVATE
);
487 InvalidateRect(hwnd
, NULL
, TRUE
);
493 TOOLTIPS_TrackHide (HWND hwnd
, TOOLTIPS_INFO
*infoPtr
)
495 TTTOOL_INFO
*toolPtr
;
498 if (infoPtr
->nTrackTool
== -1)
501 toolPtr
= &infoPtr
->tools
[infoPtr
->nTrackTool
];
502 TRACE("hide tracking tooltip %d!\n", infoPtr
->nTrackTool
);
505 hdr
.idFrom
= toolPtr
->uId
;
507 SendMessageA (toolPtr
->hwnd
, WM_NOTIFY
,
508 (WPARAM
)toolPtr
->uId
, (LPARAM
)&hdr
);
510 SetWindowPos (hwnd
, HWND_TOP
, 0, 0, 0, 0,
511 SWP_NOZORDER
| SWP_HIDEWINDOW
| SWP_NOACTIVATE
);
516 TOOLTIPS_GetToolFromInfoA (TOOLTIPS_INFO
*infoPtr
, LPTTTOOLINFOA lpToolInfo
)
518 TTTOOL_INFO
*toolPtr
;
521 for (nTool
= 0; nTool
< infoPtr
->uNumTools
; nTool
++) {
522 toolPtr
= &infoPtr
->tools
[nTool
];
524 if (!(toolPtr
->uFlags
& TTF_IDISHWND
) &&
525 (lpToolInfo
->hwnd
== toolPtr
->hwnd
) &&
526 (lpToolInfo
->uId
== toolPtr
->uId
))
530 for (nTool
= 0; nTool
< infoPtr
->uNumTools
; nTool
++) {
531 toolPtr
= &infoPtr
->tools
[nTool
];
533 if ((toolPtr
->uFlags
& TTF_IDISHWND
) &&
534 (lpToolInfo
->uId
== toolPtr
->uId
))
543 TOOLTIPS_GetToolFromInfoW (TOOLTIPS_INFO
*infoPtr
, LPTTTOOLINFOW lpToolInfo
)
545 TTTOOL_INFO
*toolPtr
;
548 for (nTool
= 0; nTool
< infoPtr
->uNumTools
; nTool
++) {
549 toolPtr
= &infoPtr
->tools
[nTool
];
551 if (!(toolPtr
->uFlags
& TTF_IDISHWND
) &&
552 (lpToolInfo
->hwnd
== toolPtr
->hwnd
) &&
553 (lpToolInfo
->uId
== toolPtr
->uId
))
557 for (nTool
= 0; nTool
< infoPtr
->uNumTools
; nTool
++) {
558 toolPtr
= &infoPtr
->tools
[nTool
];
560 if ((toolPtr
->uFlags
& TTF_IDISHWND
) &&
561 (lpToolInfo
->uId
== toolPtr
->uId
))
570 TOOLTIPS_GetToolFromPoint (TOOLTIPS_INFO
*infoPtr
, HWND hwnd
, LPPOINT lpPt
)
572 TTTOOL_INFO
*toolPtr
;
575 for (nTool
= 0; nTool
< infoPtr
->uNumTools
; nTool
++) {
576 toolPtr
= &infoPtr
->tools
[nTool
];
578 if (!(toolPtr
->uFlags
& TTF_IDISHWND
)) {
579 if (hwnd
!= toolPtr
->hwnd
)
581 if (!PtInRect (&toolPtr
->rect
, *lpPt
))
587 for (nTool
= 0; nTool
< infoPtr
->uNumTools
; nTool
++) {
588 toolPtr
= &infoPtr
->tools
[nTool
];
590 if (toolPtr
->uFlags
& TTF_IDISHWND
) {
591 if ((HWND
)toolPtr
->uId
== hwnd
)
601 TOOLTIPS_IsWindowActive (HWND hwnd
)
603 HWND hwndActive
= GetActiveWindow ();
606 if (hwndActive
== hwnd
)
608 return IsChild (hwndActive
, hwnd
);
613 TOOLTIPS_CheckTool (HWND hwnd
, BOOL bShowTest
)
615 TOOLTIPS_INFO
*infoPtr
= TOOLTIPS_GetInfoPtr (hwnd
);
621 hwndTool
= SendMessageA (hwnd
, TTM_WINDOWFROMPOINT
, 0, (LPARAM
)&pt
);
625 ScreenToClient (hwndTool
, &pt
);
626 nTool
= TOOLTIPS_GetToolFromPoint (infoPtr
, hwndTool
, &pt
);
630 if (!(GetWindowLongA (hwnd
, GWL_STYLE
) & TTS_ALWAYSTIP
) && bShowTest
) {
631 if (!TOOLTIPS_IsWindowActive (GetWindow (hwnd
, GW_OWNER
)))
635 TRACE("tool %d\n", nTool
);
642 TOOLTIPS_Activate (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
644 TOOLTIPS_INFO
*infoPtr
= TOOLTIPS_GetInfoPtr (hwnd
);
646 infoPtr
->bActive
= (BOOL
)wParam
;
648 if (infoPtr
->bActive
)
649 TRACE("activate!\n");
651 if (!(infoPtr
->bActive
) && (infoPtr
->nCurrentTool
!= -1))
652 TOOLTIPS_Hide (hwnd
, infoPtr
);
659 TOOLTIPS_AddToolA (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
661 TOOLTIPS_INFO
*infoPtr
= TOOLTIPS_GetInfoPtr (hwnd
);
662 LPTTTOOLINFOA lpToolInfo
= (LPTTTOOLINFOA
)lParam
;
663 TTTOOL_INFO
*toolPtr
;
665 if (lpToolInfo
== NULL
)
667 if (lpToolInfo
->cbSize
< TTTOOLINFO_V1_SIZEA
)
670 TRACE("add tool (%x) %x %d%s!\n",
671 hwnd
, lpToolInfo
->hwnd
, lpToolInfo
->uId
,
672 (lpToolInfo
->uFlags
& TTF_IDISHWND
) ? " TTF_IDISHWND" : "");
674 if (infoPtr
->uNumTools
== 0) {
675 infoPtr
->tools
= COMCTL32_Alloc (sizeof(TTTOOL_INFO
));
676 toolPtr
= infoPtr
->tools
;
679 TTTOOL_INFO
*oldTools
= infoPtr
->tools
;
681 COMCTL32_Alloc (sizeof(TTTOOL_INFO
) * (infoPtr
->uNumTools
+ 1));
682 memcpy (infoPtr
->tools
, oldTools
,
683 infoPtr
->uNumTools
* sizeof(TTTOOL_INFO
));
684 COMCTL32_Free (oldTools
);
685 toolPtr
= &infoPtr
->tools
[infoPtr
->uNumTools
];
688 infoPtr
->uNumTools
++;
691 toolPtr
->uFlags
= lpToolInfo
->uFlags
;
692 toolPtr
->hwnd
= lpToolInfo
->hwnd
;
693 toolPtr
->uId
= lpToolInfo
->uId
;
694 toolPtr
->rect
= lpToolInfo
->rect
;
695 toolPtr
->hinst
= lpToolInfo
->hinst
;
697 if ((lpToolInfo
->hinst
) && (HIWORD((INT
)lpToolInfo
->lpszText
) == 0)) {
698 TRACE("add string id %x!\n", (int)lpToolInfo
->lpszText
);
699 toolPtr
->lpszText
= (LPWSTR
)lpToolInfo
->lpszText
;
701 else if (lpToolInfo
->lpszText
) {
702 if (lpToolInfo
->lpszText
== LPSTR_TEXTCALLBACKA
) {
703 TRACE("add CALLBACK!\n");
704 toolPtr
->lpszText
= LPSTR_TEXTCALLBACKW
;
707 INT len
= MultiByteToWideChar(CP_ACP
, 0, lpToolInfo
->lpszText
, -1,
709 TRACE("add text \"%s\"!\n", lpToolInfo
->lpszText
);
710 toolPtr
->lpszText
= COMCTL32_Alloc (len
* sizeof(WCHAR
));
711 MultiByteToWideChar(CP_ACP
, 0, lpToolInfo
->lpszText
, -1,
712 toolPtr
->lpszText
, len
);
716 if (lpToolInfo
->cbSize
>= sizeof(TTTOOLINFOA
))
717 toolPtr
->lParam
= lpToolInfo
->lParam
;
719 /* install subclassing hook */
720 if (toolPtr
->uFlags
& TTF_SUBCLASS
) {
721 if (toolPtr
->uFlags
& TTF_IDISHWND
) {
722 LPTT_SUBCLASS_INFO lpttsi
=
723 (LPTT_SUBCLASS_INFO
)GetPropA ((HWND
)toolPtr
->uId
, COMCTL32_aSubclass
);
724 if (lpttsi
== NULL
) {
726 (LPTT_SUBCLASS_INFO
)COMCTL32_Alloc (sizeof(TT_SUBCLASS_INFO
));
728 (WNDPROC
)SetWindowLongA ((HWND
)toolPtr
->uId
,
729 GWL_WNDPROC
,(LONG
)TOOLTIPS_SubclassProc
);
730 lpttsi
->hwndToolTip
= hwnd
;
732 SetPropA ((HWND
)toolPtr
->uId
, COMCTL32_aSubclass
,
736 WARN("A window tool must only be listed once!\n");
739 LPTT_SUBCLASS_INFO lpttsi
=
740 (LPTT_SUBCLASS_INFO
)GetPropA (toolPtr
->hwnd
, COMCTL32_aSubclass
);
741 if (lpttsi
== NULL
) {
743 (LPTT_SUBCLASS_INFO
)COMCTL32_Alloc (sizeof(TT_SUBCLASS_INFO
));
745 (WNDPROC
)SetWindowLongA (toolPtr
->hwnd
,
746 GWL_WNDPROC
,(LONG
)TOOLTIPS_SubclassProc
);
747 lpttsi
->hwndToolTip
= hwnd
;
749 SetPropA (toolPtr
->hwnd
, COMCTL32_aSubclass
, (HANDLE
)lpttsi
);
754 TRACE("subclassing installed!\n");
762 TOOLTIPS_AddToolW (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
764 TOOLTIPS_INFO
*infoPtr
= TOOLTIPS_GetInfoPtr (hwnd
);
765 LPTTTOOLINFOW lpToolInfo
= (LPTTTOOLINFOW
)lParam
;
766 TTTOOL_INFO
*toolPtr
;
768 if (lpToolInfo
== NULL
)
770 if (lpToolInfo
->cbSize
< TTTOOLINFO_V1_SIZEW
)
773 TRACE("add tool (%x) %x %d%s!\n",
774 hwnd
, lpToolInfo
->hwnd
, lpToolInfo
->uId
,
775 (lpToolInfo
->uFlags
& TTF_IDISHWND
) ? " TTF_IDISHWND" : "");
777 if (infoPtr
->uNumTools
== 0) {
778 infoPtr
->tools
= COMCTL32_Alloc (sizeof(TTTOOL_INFO
));
779 toolPtr
= infoPtr
->tools
;
782 TTTOOL_INFO
*oldTools
= infoPtr
->tools
;
784 COMCTL32_Alloc (sizeof(TTTOOL_INFO
) * (infoPtr
->uNumTools
+ 1));
785 memcpy (infoPtr
->tools
, oldTools
,
786 infoPtr
->uNumTools
* sizeof(TTTOOL_INFO
));
787 COMCTL32_Free (oldTools
);
788 toolPtr
= &infoPtr
->tools
[infoPtr
->uNumTools
];
791 infoPtr
->uNumTools
++;
794 toolPtr
->uFlags
= lpToolInfo
->uFlags
;
795 toolPtr
->hwnd
= lpToolInfo
->hwnd
;
796 toolPtr
->uId
= lpToolInfo
->uId
;
797 toolPtr
->rect
= lpToolInfo
->rect
;
798 toolPtr
->hinst
= lpToolInfo
->hinst
;
800 if ((lpToolInfo
->hinst
) && (HIWORD((INT
)lpToolInfo
->lpszText
) == 0)) {
801 TRACE("add string id %x!\n", (int)lpToolInfo
->lpszText
);
802 toolPtr
->lpszText
= (LPWSTR
)lpToolInfo
->lpszText
;
804 else if (lpToolInfo
->lpszText
) {
805 if (lpToolInfo
->lpszText
== LPSTR_TEXTCALLBACKW
) {
806 TRACE("add CALLBACK!\n");
807 toolPtr
->lpszText
= LPSTR_TEXTCALLBACKW
;
810 INT len
= lstrlenW (lpToolInfo
->lpszText
);
811 TRACE("add text %s!\n",
812 debugstr_w(lpToolInfo
->lpszText
));
813 toolPtr
->lpszText
= COMCTL32_Alloc ((len
+ 1)*sizeof(WCHAR
));
814 strcpyW (toolPtr
->lpszText
, lpToolInfo
->lpszText
);
818 if (lpToolInfo
->cbSize
>= sizeof(TTTOOLINFOW
))
819 toolPtr
->lParam
= lpToolInfo
->lParam
;
821 /* install subclassing hook */
822 if (toolPtr
->uFlags
& TTF_SUBCLASS
) {
823 if (toolPtr
->uFlags
& TTF_IDISHWND
) {
824 LPTT_SUBCLASS_INFO lpttsi
=
825 (LPTT_SUBCLASS_INFO
)GetPropA ((HWND
)toolPtr
->uId
, COMCTL32_aSubclass
);
826 if (lpttsi
== NULL
) {
828 (LPTT_SUBCLASS_INFO
)COMCTL32_Alloc (sizeof(TT_SUBCLASS_INFO
));
830 (WNDPROC
)SetWindowLongA ((HWND
)toolPtr
->uId
,
831 GWL_WNDPROC
,(LONG
)TOOLTIPS_SubclassProc
);
832 lpttsi
->hwndToolTip
= hwnd
;
834 SetPropA ((HWND
)toolPtr
->uId
, COMCTL32_aSubclass
,
838 WARN("A window tool must only be listed once!\n");
841 LPTT_SUBCLASS_INFO lpttsi
=
842 (LPTT_SUBCLASS_INFO
)GetPropA (toolPtr
->hwnd
, COMCTL32_aSubclass
);
843 if (lpttsi
== NULL
) {
845 (LPTT_SUBCLASS_INFO
)COMCTL32_Alloc (sizeof(TT_SUBCLASS_INFO
));
847 (WNDPROC
)SetWindowLongA (toolPtr
->hwnd
,
848 GWL_WNDPROC
,(LONG
)TOOLTIPS_SubclassProc
);
849 lpttsi
->hwndToolTip
= hwnd
;
851 SetPropA (toolPtr
->hwnd
, COMCTL32_aSubclass
, (HANDLE
)lpttsi
);
856 TRACE("subclassing installed!\n");
864 TOOLTIPS_DelToolA (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
866 TOOLTIPS_INFO
*infoPtr
= TOOLTIPS_GetInfoPtr (hwnd
);
867 LPTTTOOLINFOA lpToolInfo
= (LPTTTOOLINFOA
)lParam
;
868 TTTOOL_INFO
*toolPtr
;
871 if (lpToolInfo
== NULL
)
873 if (lpToolInfo
->cbSize
< TTTOOLINFO_V1_SIZEA
)
875 if (infoPtr
->uNumTools
== 0)
878 nTool
= TOOLTIPS_GetToolFromInfoA (infoPtr
, lpToolInfo
);
879 if (nTool
== -1) return 0;
881 TRACE("tool %d\n", nTool
);
883 /* make sure the tooltip has disappeared before deleting it */
884 TOOLTIPS_Hide(hwnd
, infoPtr
);
886 /* delete text string */
887 toolPtr
= &infoPtr
->tools
[nTool
];
888 if ((toolPtr
->hinst
) && (toolPtr
->lpszText
)) {
889 if ( (toolPtr
->lpszText
!= LPSTR_TEXTCALLBACKW
) &&
890 (HIWORD((INT
)toolPtr
->lpszText
) != 0) )
891 COMCTL32_Free (toolPtr
->lpszText
);
894 /* remove subclassing */
895 if (toolPtr
->uFlags
& TTF_SUBCLASS
) {
896 if (toolPtr
->uFlags
& TTF_IDISHWND
) {
897 LPTT_SUBCLASS_INFO lpttsi
=
898 (LPTT_SUBCLASS_INFO
)GetPropA ((HWND
)toolPtr
->uId
, COMCTL32_aSubclass
);
900 SetWindowLongA ((HWND
)toolPtr
->uId
, GWL_WNDPROC
,
901 (LONG
)lpttsi
->wpOrigProc
);
902 RemovePropA ((HWND
)toolPtr
->uId
, COMCTL32_aSubclass
);
903 COMCTL32_Free (&lpttsi
);
906 ERR("Invalid data handle!\n");
909 LPTT_SUBCLASS_INFO lpttsi
=
910 (LPTT_SUBCLASS_INFO
)GetPropA (toolPtr
->hwnd
, COMCTL32_aSubclass
);
912 if (lpttsi
->uRefCount
== 1) {
913 SetWindowLongA ((HWND
)toolPtr
->hwnd
, GWL_WNDPROC
,
914 (LONG
)lpttsi
->wpOrigProc
);
915 RemovePropA ((HWND
)toolPtr
->hwnd
, COMCTL32_aSubclass
);
916 COMCTL32_Free (&lpttsi
);
922 ERR("Invalid data handle!\n");
926 /* delete tool from tool list */
927 if (infoPtr
->uNumTools
== 1) {
928 COMCTL32_Free (infoPtr
->tools
);
929 infoPtr
->tools
= NULL
;
932 TTTOOL_INFO
*oldTools
= infoPtr
->tools
;
934 COMCTL32_Alloc (sizeof(TTTOOL_INFO
) * (infoPtr
->uNumTools
- 1));
937 memcpy (&infoPtr
->tools
[0], &oldTools
[0],
938 nTool
* sizeof(TTTOOL_INFO
));
940 if (nTool
< infoPtr
->uNumTools
- 1)
941 memcpy (&infoPtr
->tools
[nTool
], &oldTools
[nTool
+ 1],
942 (infoPtr
->uNumTools
- nTool
- 1) * sizeof(TTTOOL_INFO
));
944 COMCTL32_Free (oldTools
);
947 /* destroying tool that mouse was on on last relayed mouse move */
948 if (infoPtr
->nTool
== nTool
)
950 /* no current tool (0 means first tool) */
954 infoPtr
->uNumTools
--;
961 TOOLTIPS_DelToolW (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
963 TOOLTIPS_INFO
*infoPtr
= TOOLTIPS_GetInfoPtr (hwnd
);
964 LPTTTOOLINFOW lpToolInfo
= (LPTTTOOLINFOW
)lParam
;
965 TTTOOL_INFO
*toolPtr
;
968 if (lpToolInfo
== NULL
)
970 if (lpToolInfo
->cbSize
< TTTOOLINFO_V1_SIZEW
)
972 if (infoPtr
->uNumTools
== 0)
975 nTool
= TOOLTIPS_GetToolFromInfoW (infoPtr
, lpToolInfo
);
976 if (nTool
== -1) return 0;
978 TRACE("tool %d\n", nTool
);
980 /* make sure the tooltip has disappeared before deleting it */
981 TOOLTIPS_Hide(hwnd
, infoPtr
);
983 /* delete text string */
984 toolPtr
= &infoPtr
->tools
[nTool
];
985 if ((toolPtr
->hinst
) && (toolPtr
->lpszText
)) {
986 if ( (toolPtr
->lpszText
!= LPSTR_TEXTCALLBACKW
) &&
987 (HIWORD((INT
)toolPtr
->lpszText
) != 0) )
988 COMCTL32_Free (toolPtr
->lpszText
);
991 /* remove subclassing */
992 if (toolPtr
->uFlags
& TTF_SUBCLASS
) {
993 if (toolPtr
->uFlags
& TTF_IDISHWND
) {
994 LPTT_SUBCLASS_INFO lpttsi
=
995 (LPTT_SUBCLASS_INFO
)GetPropA ((HWND
)toolPtr
->uId
, COMCTL32_aSubclass
);
997 SetWindowLongA ((HWND
)toolPtr
->uId
, GWL_WNDPROC
,
998 (LONG
)lpttsi
->wpOrigProc
);
999 RemovePropA ((HWND
)toolPtr
->uId
, COMCTL32_aSubclass
);
1000 COMCTL32_Free (&lpttsi
);
1003 ERR("Invalid data handle!\n");
1006 LPTT_SUBCLASS_INFO lpttsi
=
1007 (LPTT_SUBCLASS_INFO
)GetPropA (toolPtr
->hwnd
, COMCTL32_aSubclass
);
1009 if (lpttsi
->uRefCount
== 1) {
1010 SetWindowLongA ((HWND
)toolPtr
->hwnd
, GWL_WNDPROC
,
1011 (LONG
)lpttsi
->wpOrigProc
);
1012 RemovePropA ((HWND
)toolPtr
->hwnd
, COMCTL32_aSubclass
);
1013 COMCTL32_Free (&lpttsi
);
1016 lpttsi
->uRefCount
--;
1019 ERR("Invalid data handle!\n");
1023 /* delete tool from tool list */
1024 if (infoPtr
->uNumTools
== 1) {
1025 COMCTL32_Free (infoPtr
->tools
);
1026 infoPtr
->tools
= NULL
;
1029 TTTOOL_INFO
*oldTools
= infoPtr
->tools
;
1031 COMCTL32_Alloc (sizeof(TTTOOL_INFO
) * (infoPtr
->uNumTools
- 1));
1034 memcpy (&infoPtr
->tools
[0], &oldTools
[0],
1035 nTool
* sizeof(TTTOOL_INFO
));
1037 if (nTool
< infoPtr
->uNumTools
- 1)
1038 memcpy (&infoPtr
->tools
[nTool
], &oldTools
[nTool
+ 1],
1039 (infoPtr
->uNumTools
- nTool
- 1) * sizeof(TTTOOL_INFO
));
1041 COMCTL32_Free (oldTools
);
1044 /* destroying tool that mouse was on on last relayed mouse move */
1045 if (infoPtr
->nTool
== nTool
)
1047 /* no current tool (0 means first tool) */
1048 infoPtr
->nTool
= -1;
1051 infoPtr
->uNumTools
--;
1058 TOOLTIPS_EnumToolsA (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
1060 TOOLTIPS_INFO
*infoPtr
= TOOLTIPS_GetInfoPtr (hwnd
);
1061 UINT uIndex
= (UINT
)wParam
;
1062 LPTTTOOLINFOA lpToolInfo
= (LPTTTOOLINFOA
)lParam
;
1063 TTTOOL_INFO
*toolPtr
;
1065 if (lpToolInfo
== NULL
)
1067 if (lpToolInfo
->cbSize
< TTTOOLINFO_V1_SIZEA
)
1069 if (uIndex
>= infoPtr
->uNumTools
)
1072 TRACE("index=%u\n", uIndex
);
1074 toolPtr
= &infoPtr
->tools
[uIndex
];
1076 /* copy tool data */
1077 lpToolInfo
->uFlags
= toolPtr
->uFlags
;
1078 lpToolInfo
->hwnd
= toolPtr
->hwnd
;
1079 lpToolInfo
->uId
= toolPtr
->uId
;
1080 lpToolInfo
->rect
= toolPtr
->rect
;
1081 lpToolInfo
->hinst
= toolPtr
->hinst
;
1082 /* lpToolInfo->lpszText = toolPtr->lpszText; */
1083 lpToolInfo
->lpszText
= NULL
; /* FIXME */
1085 if (lpToolInfo
->cbSize
>= sizeof(TTTOOLINFOA
))
1086 lpToolInfo
->lParam
= toolPtr
->lParam
;
1093 TOOLTIPS_EnumToolsW (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
1095 TOOLTIPS_INFO
*infoPtr
= TOOLTIPS_GetInfoPtr (hwnd
);
1096 UINT uIndex
= (UINT
)wParam
;
1097 LPTTTOOLINFOW lpToolInfo
= (LPTTTOOLINFOW
)lParam
;
1098 TTTOOL_INFO
*toolPtr
;
1100 if (lpToolInfo
== NULL
)
1102 if (lpToolInfo
->cbSize
< TTTOOLINFO_V1_SIZEW
)
1104 if (uIndex
>= infoPtr
->uNumTools
)
1107 TRACE("index=%u\n", uIndex
);
1109 toolPtr
= &infoPtr
->tools
[uIndex
];
1111 /* copy tool data */
1112 lpToolInfo
->uFlags
= toolPtr
->uFlags
;
1113 lpToolInfo
->hwnd
= toolPtr
->hwnd
;
1114 lpToolInfo
->uId
= toolPtr
->uId
;
1115 lpToolInfo
->rect
= toolPtr
->rect
;
1116 lpToolInfo
->hinst
= toolPtr
->hinst
;
1117 /* lpToolInfo->lpszText = toolPtr->lpszText; */
1118 lpToolInfo
->lpszText
= NULL
; /* FIXME */
1120 if (lpToolInfo
->cbSize
>= sizeof(TTTOOLINFOW
))
1121 lpToolInfo
->lParam
= toolPtr
->lParam
;
1128 TOOLTIPS_GetCurrentToolA (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
1130 TOOLTIPS_INFO
*infoPtr
= TOOLTIPS_GetInfoPtr (hwnd
);
1131 LPTTTOOLINFOA lpToolInfo
= (LPTTTOOLINFOA
)lParam
;
1132 TTTOOL_INFO
*toolPtr
;
1134 if (lpToolInfo
== NULL
)
1136 if (lpToolInfo
->cbSize
< TTTOOLINFO_V1_SIZEA
)
1140 if (infoPtr
->nCurrentTool
> -1) {
1141 toolPtr
= &infoPtr
->tools
[infoPtr
->nCurrentTool
];
1143 /* copy tool data */
1144 lpToolInfo
->uFlags
= toolPtr
->uFlags
;
1145 lpToolInfo
->rect
= toolPtr
->rect
;
1146 lpToolInfo
->hinst
= toolPtr
->hinst
;
1147 /* lpToolInfo->lpszText = toolPtr->lpszText; */
1148 lpToolInfo
->lpszText
= NULL
; /* FIXME */
1150 if (lpToolInfo
->cbSize
>= sizeof(TTTOOLINFOA
))
1151 lpToolInfo
->lParam
= toolPtr
->lParam
;
1159 return (infoPtr
->nCurrentTool
!= -1);
1166 TOOLTIPS_GetCurrentToolW (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
1168 TOOLTIPS_INFO
*infoPtr
= TOOLTIPS_GetInfoPtr (hwnd
);
1169 LPTTTOOLINFOW lpToolInfo
= (LPTTTOOLINFOW
)lParam
;
1170 TTTOOL_INFO
*toolPtr
;
1172 if (lpToolInfo
== NULL
)
1174 if (lpToolInfo
->cbSize
< TTTOOLINFO_V1_SIZEW
)
1178 if (infoPtr
->nCurrentTool
> -1) {
1179 toolPtr
= &infoPtr
->tools
[infoPtr
->nCurrentTool
];
1181 /* copy tool data */
1182 lpToolInfo
->uFlags
= toolPtr
->uFlags
;
1183 lpToolInfo
->rect
= toolPtr
->rect
;
1184 lpToolInfo
->hinst
= toolPtr
->hinst
;
1185 /* lpToolInfo->lpszText = toolPtr->lpszText; */
1186 lpToolInfo
->lpszText
= NULL
; /* FIXME */
1188 if (lpToolInfo
->cbSize
>= sizeof(TTTOOLINFOW
))
1189 lpToolInfo
->lParam
= toolPtr
->lParam
;
1197 return (infoPtr
->nCurrentTool
!= -1);
1204 TOOLTIPS_GetDelayTime (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
1206 TOOLTIPS_INFO
*infoPtr
= TOOLTIPS_GetInfoPtr (hwnd
);
1210 return infoPtr
->nReshowTime
;
1213 return infoPtr
->nAutoPopTime
;
1216 case TTDT_AUTOMATIC
: /* Apparently TTDT_AUTOMATIC returns TTDT_INITIAL */
1217 return infoPtr
->nInitialTime
;
1220 WARN("Invalid wParam %x\n", wParam
);
1229 TOOLTIPS_GetMargin (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
1231 TOOLTIPS_INFO
*infoPtr
= TOOLTIPS_GetInfoPtr (hwnd
);
1232 LPRECT lpRect
= (LPRECT
)lParam
;
1234 lpRect
->left
= infoPtr
->rcMargin
.left
;
1235 lpRect
->right
= infoPtr
->rcMargin
.right
;
1236 lpRect
->bottom
= infoPtr
->rcMargin
.bottom
;
1237 lpRect
->top
= infoPtr
->rcMargin
.top
;
1243 inline static LRESULT
1244 TOOLTIPS_GetMaxTipWidth (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
1246 TOOLTIPS_INFO
*infoPtr
= TOOLTIPS_GetInfoPtr (hwnd
);
1248 return infoPtr
->nMaxTipWidth
;
1253 TOOLTIPS_GetTextA (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
1255 TOOLTIPS_INFO
*infoPtr
= TOOLTIPS_GetInfoPtr (hwnd
);
1256 LPTTTOOLINFOA lpToolInfo
= (LPTTTOOLINFOA
)lParam
;
1259 if (lpToolInfo
== NULL
)
1261 if (lpToolInfo
->cbSize
< TTTOOLINFO_V1_SIZEA
)
1264 nTool
= TOOLTIPS_GetToolFromInfoA (infoPtr
, lpToolInfo
);
1265 if (nTool
== -1) return 0;
1267 /* NB this API is broken, there is no way for the app to determine
1268 what size buffer it requires nor a way to specify how long the
1269 one it supplies is. We'll assume it's upto INFOTIPSIZE */
1271 WideCharToMultiByte(CP_ACP
, 0, infoPtr
->tools
[nTool
].lpszText
, -1,
1272 lpToolInfo
->lpszText
, INFOTIPSIZE
, NULL
, NULL
);
1279 TOOLTIPS_GetTextW (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
1281 TOOLTIPS_INFO
*infoPtr
= TOOLTIPS_GetInfoPtr (hwnd
);
1282 LPTTTOOLINFOW lpToolInfo
= (LPTTTOOLINFOW
)lParam
;
1285 if (lpToolInfo
== NULL
)
1287 if (lpToolInfo
->cbSize
< TTTOOLINFO_V1_SIZEW
)
1290 nTool
= TOOLTIPS_GetToolFromInfoW (infoPtr
, lpToolInfo
);
1291 if (nTool
== -1) return 0;
1293 strcpyW (lpToolInfo
->lpszText
, infoPtr
->tools
[nTool
].lpszText
);
1299 inline static LRESULT
1300 TOOLTIPS_GetTipBkColor (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
1302 TOOLTIPS_INFO
*infoPtr
= TOOLTIPS_GetInfoPtr (hwnd
);
1303 return infoPtr
->clrBk
;
1307 inline static LRESULT
1308 TOOLTIPS_GetTipTextColor (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
1310 TOOLTIPS_INFO
*infoPtr
= TOOLTIPS_GetInfoPtr (hwnd
);
1311 return infoPtr
->clrText
;
1315 inline static LRESULT
1316 TOOLTIPS_GetToolCount (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
1318 TOOLTIPS_INFO
*infoPtr
= TOOLTIPS_GetInfoPtr (hwnd
);
1319 return infoPtr
->uNumTools
;
1324 TOOLTIPS_GetToolInfoA (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
1326 TOOLTIPS_INFO
*infoPtr
= TOOLTIPS_GetInfoPtr (hwnd
);
1327 LPTTTOOLINFOA lpToolInfo
= (LPTTTOOLINFOA
)lParam
;
1328 TTTOOL_INFO
*toolPtr
;
1331 if (lpToolInfo
== NULL
)
1333 if (lpToolInfo
->cbSize
< TTTOOLINFO_V1_SIZEA
)
1335 if (infoPtr
->uNumTools
== 0)
1338 nTool
= TOOLTIPS_GetToolFromInfoA (infoPtr
, lpToolInfo
);
1342 TRACE("tool %d\n", nTool
);
1344 toolPtr
= &infoPtr
->tools
[nTool
];
1346 /* copy tool data */
1347 lpToolInfo
->uFlags
= toolPtr
->uFlags
;
1348 lpToolInfo
->rect
= toolPtr
->rect
;
1349 lpToolInfo
->hinst
= toolPtr
->hinst
;
1350 /* lpToolInfo->lpszText = toolPtr->lpszText; */
1351 lpToolInfo
->lpszText
= NULL
; /* FIXME */
1353 if (lpToolInfo
->cbSize
>= sizeof(TTTOOLINFOA
))
1354 lpToolInfo
->lParam
= toolPtr
->lParam
;
1361 TOOLTIPS_GetToolInfoW (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
1363 TOOLTIPS_INFO
*infoPtr
= TOOLTIPS_GetInfoPtr (hwnd
);
1364 LPTTTOOLINFOW lpToolInfo
= (LPTTTOOLINFOW
)lParam
;
1365 TTTOOL_INFO
*toolPtr
;
1368 if (lpToolInfo
== NULL
)
1370 if (lpToolInfo
->cbSize
< TTTOOLINFO_V1_SIZEW
)
1372 if (infoPtr
->uNumTools
== 0)
1375 nTool
= TOOLTIPS_GetToolFromInfoW (infoPtr
, lpToolInfo
);
1379 TRACE("tool %d\n", nTool
);
1381 toolPtr
= &infoPtr
->tools
[nTool
];
1383 /* copy tool data */
1384 lpToolInfo
->uFlags
= toolPtr
->uFlags
;
1385 lpToolInfo
->rect
= toolPtr
->rect
;
1386 lpToolInfo
->hinst
= toolPtr
->hinst
;
1387 /* lpToolInfo->lpszText = toolPtr->lpszText; */
1388 lpToolInfo
->lpszText
= NULL
; /* FIXME */
1390 if (lpToolInfo
->cbSize
>= sizeof(TTTOOLINFOW
))
1391 lpToolInfo
->lParam
= toolPtr
->lParam
;
1398 TOOLTIPS_HitTestA (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
1400 TOOLTIPS_INFO
*infoPtr
= TOOLTIPS_GetInfoPtr (hwnd
);
1401 LPTTHITTESTINFOA lptthit
= (LPTTHITTESTINFOA
)lParam
;
1402 TTTOOL_INFO
*toolPtr
;
1408 nTool
= TOOLTIPS_GetToolFromPoint (infoPtr
, lptthit
->hwnd
, &lptthit
->pt
);
1412 TRACE("tool %d!\n", nTool
);
1414 /* copy tool data */
1415 if (lptthit
->ti
.cbSize
>= sizeof(TTTOOLINFOA
)) {
1416 toolPtr
= &infoPtr
->tools
[nTool
];
1418 lptthit
->ti
.uFlags
= toolPtr
->uFlags
;
1419 lptthit
->ti
.hwnd
= toolPtr
->hwnd
;
1420 lptthit
->ti
.uId
= toolPtr
->uId
;
1421 lptthit
->ti
.rect
= toolPtr
->rect
;
1422 lptthit
->ti
.hinst
= toolPtr
->hinst
;
1423 /* lptthit->ti.lpszText = toolPtr->lpszText; */
1424 lptthit
->ti
.lpszText
= NULL
; /* FIXME */
1425 lptthit
->ti
.lParam
= toolPtr
->lParam
;
1433 TOOLTIPS_HitTestW (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
1435 TOOLTIPS_INFO
*infoPtr
= TOOLTIPS_GetInfoPtr (hwnd
);
1436 LPTTHITTESTINFOW lptthit
= (LPTTHITTESTINFOW
)lParam
;
1437 TTTOOL_INFO
*toolPtr
;
1443 nTool
= TOOLTIPS_GetToolFromPoint (infoPtr
, lptthit
->hwnd
, &lptthit
->pt
);
1447 TRACE("tool %d!\n", nTool
);
1449 /* copy tool data */
1450 if (lptthit
->ti
.cbSize
>= sizeof(TTTOOLINFOW
)) {
1451 toolPtr
= &infoPtr
->tools
[nTool
];
1453 lptthit
->ti
.uFlags
= toolPtr
->uFlags
;
1454 lptthit
->ti
.hwnd
= toolPtr
->hwnd
;
1455 lptthit
->ti
.uId
= toolPtr
->uId
;
1456 lptthit
->ti
.rect
= toolPtr
->rect
;
1457 lptthit
->ti
.hinst
= toolPtr
->hinst
;
1458 /* lptthit->ti.lpszText = toolPtr->lpszText; */
1459 lptthit
->ti
.lpszText
= NULL
; /* FIXME */
1460 lptthit
->ti
.lParam
= toolPtr
->lParam
;
1468 TOOLTIPS_NewToolRectA (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
1470 TOOLTIPS_INFO
*infoPtr
= TOOLTIPS_GetInfoPtr (hwnd
);
1471 LPTTTOOLINFOA lpti
= (LPTTTOOLINFOA
)lParam
;
1476 if (lpti
->cbSize
< TTTOOLINFO_V1_SIZEA
)
1479 nTool
= TOOLTIPS_GetToolFromInfoA (infoPtr
, lpti
);
1480 if (nTool
== -1) return 0;
1482 infoPtr
->tools
[nTool
].rect
= lpti
->rect
;
1489 TOOLTIPS_NewToolRectW (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
1491 TOOLTIPS_INFO
*infoPtr
= TOOLTIPS_GetInfoPtr (hwnd
);
1492 LPTTTOOLINFOW lpti
= (LPTTTOOLINFOW
)lParam
;
1497 if (lpti
->cbSize
< TTTOOLINFO_V1_SIZEW
)
1500 nTool
= TOOLTIPS_GetToolFromInfoW (infoPtr
, lpti
);
1501 if (nTool
== -1) return 0;
1503 infoPtr
->tools
[nTool
].rect
= lpti
->rect
;
1509 inline static LRESULT
1510 TOOLTIPS_Pop (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
1512 TOOLTIPS_INFO
*infoPtr
= TOOLTIPS_GetInfoPtr (hwnd
);
1513 TOOLTIPS_Hide (hwnd
, infoPtr
);
1520 TOOLTIPS_RelayEvent (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
1522 TOOLTIPS_INFO
*infoPtr
= TOOLTIPS_GetInfoPtr (hwnd
);
1523 LPMSG lpMsg
= (LPMSG
)lParam
;
1528 ERR("lpMsg == NULL!\n");
1532 switch (lpMsg
->message
) {
1533 case WM_LBUTTONDOWN
:
1535 case WM_MBUTTONDOWN
:
1537 case WM_RBUTTONDOWN
:
1539 TOOLTIPS_Hide (hwnd
, infoPtr
);
1543 pt
.x
= LOWORD(lpMsg
->lParam
);
1544 pt
.y
= HIWORD(lpMsg
->lParam
);
1545 nOldTool
= infoPtr
->nTool
;
1546 infoPtr
->nTool
= TOOLTIPS_GetToolFromPoint(infoPtr
, lpMsg
->hwnd
,
1548 TRACE("tool (%x) %d %d %d\n", hwnd
, nOldTool
,
1549 infoPtr
->nTool
, infoPtr
->nCurrentTool
);
1550 TRACE("WM_MOUSEMOVE (%04x %ld %ld)\n", hwnd
, pt
.x
, pt
.y
);
1552 if (infoPtr
->nTool
!= nOldTool
) {
1553 if(infoPtr
->nTool
== -1) { /* Moved out of all tools */
1554 TOOLTIPS_Hide(hwnd
, infoPtr
);
1555 KillTimer(hwnd
, ID_TIMERLEAVE
);
1556 } else if (nOldTool
== -1) { /* Moved from outside */
1557 if(infoPtr
->bActive
) {
1558 SetTimer(hwnd
, ID_TIMERSHOW
, infoPtr
->nInitialTime
, 0);
1559 TRACE("timer 1 started!\n");
1561 } else { /* Moved from one to another */
1562 TOOLTIPS_Hide (hwnd
, infoPtr
);
1563 KillTimer(hwnd
, ID_TIMERLEAVE
);
1564 if(infoPtr
->bActive
) {
1565 SetTimer (hwnd
, ID_TIMERSHOW
, infoPtr
->nReshowTime
, 0);
1566 TRACE("timer 1 started!\n");
1569 } else if(infoPtr
->nCurrentTool
!= -1) { /* restart autopop */
1570 KillTimer(hwnd
, ID_TIMERPOP
);
1571 SetTimer(hwnd
, ID_TIMERPOP
, infoPtr
->nAutoPopTime
, 0);
1572 TRACE("timer 2 restarted\n");
1582 TOOLTIPS_SetDelayTime (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
1584 TOOLTIPS_INFO
*infoPtr
= TOOLTIPS_GetInfoPtr (hwnd
);
1585 INT nTime
= (INT
)LOWORD(lParam
);
1588 case TTDT_AUTOMATIC
:
1590 nTime
= GetDoubleClickTime();
1591 infoPtr
->nReshowTime
= nTime
/ 5;
1592 infoPtr
->nAutoPopTime
= nTime
* 10;
1593 infoPtr
->nInitialTime
= nTime
;
1598 nTime
= GetDoubleClickTime() / 5;
1599 infoPtr
->nReshowTime
= nTime
;
1604 nTime
= GetDoubleClickTime() * 10;
1605 infoPtr
->nAutoPopTime
= nTime
;
1610 nTime
= GetDoubleClickTime();
1611 infoPtr
->nInitialTime
= nTime
;
1615 WARN("Invalid wParam %x\n", wParam
);
1624 TOOLTIPS_SetMargin (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
1626 TOOLTIPS_INFO
*infoPtr
= TOOLTIPS_GetInfoPtr (hwnd
);
1627 LPRECT lpRect
= (LPRECT
)lParam
;
1629 infoPtr
->rcMargin
.left
= lpRect
->left
;
1630 infoPtr
->rcMargin
.right
= lpRect
->right
;
1631 infoPtr
->rcMargin
.bottom
= lpRect
->bottom
;
1632 infoPtr
->rcMargin
.top
= lpRect
->top
;
1638 inline static LRESULT
1639 TOOLTIPS_SetMaxTipWidth (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
1641 TOOLTIPS_INFO
*infoPtr
= TOOLTIPS_GetInfoPtr (hwnd
);
1642 INT nTemp
= infoPtr
->nMaxTipWidth
;
1644 infoPtr
->nMaxTipWidth
= (INT
)lParam
;
1650 inline static LRESULT
1651 TOOLTIPS_SetTipBkColor (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
1653 TOOLTIPS_INFO
*infoPtr
= TOOLTIPS_GetInfoPtr (hwnd
);
1655 infoPtr
->clrBk
= (COLORREF
)wParam
;
1661 inline static LRESULT
1662 TOOLTIPS_SetTipTextColor (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
1664 TOOLTIPS_INFO
*infoPtr
= TOOLTIPS_GetInfoPtr (hwnd
);
1666 infoPtr
->clrText
= (COLORREF
)wParam
;
1673 TOOLTIPS_SetToolInfoA (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
1675 TOOLTIPS_INFO
*infoPtr
= TOOLTIPS_GetInfoPtr (hwnd
);
1676 LPTTTOOLINFOA lpToolInfo
= (LPTTTOOLINFOA
)lParam
;
1677 TTTOOL_INFO
*toolPtr
;
1680 if (lpToolInfo
== NULL
)
1682 if (lpToolInfo
->cbSize
< TTTOOLINFO_V1_SIZEA
)
1685 nTool
= TOOLTIPS_GetToolFromInfoA (infoPtr
, lpToolInfo
);
1686 if (nTool
== -1) return 0;
1688 TRACE("tool %d\n", nTool
);
1690 toolPtr
= &infoPtr
->tools
[nTool
];
1692 /* copy tool data */
1693 toolPtr
->uFlags
= lpToolInfo
->uFlags
;
1694 toolPtr
->hwnd
= lpToolInfo
->hwnd
;
1695 toolPtr
->uId
= lpToolInfo
->uId
;
1696 toolPtr
->rect
= lpToolInfo
->rect
;
1697 toolPtr
->hinst
= lpToolInfo
->hinst
;
1699 if ((lpToolInfo
->hinst
) && (HIWORD((INT
)lpToolInfo
->lpszText
) == 0)) {
1700 TRACE("set string id %x!\n", (INT
)lpToolInfo
->lpszText
);
1701 toolPtr
->lpszText
= (LPWSTR
)lpToolInfo
->lpszText
;
1703 else if (lpToolInfo
->lpszText
) {
1704 if (lpToolInfo
->lpszText
== LPSTR_TEXTCALLBACKA
)
1705 toolPtr
->lpszText
= LPSTR_TEXTCALLBACKW
;
1707 if ( (toolPtr
->lpszText
) &&
1708 (HIWORD((INT
)toolPtr
->lpszText
) != 0) ) {
1709 COMCTL32_Free (toolPtr
->lpszText
);
1710 toolPtr
->lpszText
= NULL
;
1712 if (lpToolInfo
->lpszText
) {
1713 INT len
= MultiByteToWideChar(CP_ACP
, 0, lpToolInfo
->lpszText
,
1715 toolPtr
->lpszText
= COMCTL32_Alloc (len
* sizeof(WCHAR
));
1716 MultiByteToWideChar(CP_ACP
, 0, lpToolInfo
->lpszText
, -1,
1717 toolPtr
->lpszText
, len
);
1722 if (lpToolInfo
->cbSize
>= sizeof(TTTOOLINFOA
))
1723 toolPtr
->lParam
= lpToolInfo
->lParam
;
1730 TOOLTIPS_SetToolInfoW (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
1732 TOOLTIPS_INFO
*infoPtr
= TOOLTIPS_GetInfoPtr (hwnd
);
1733 LPTTTOOLINFOW lpToolInfo
= (LPTTTOOLINFOW
)lParam
;
1734 TTTOOL_INFO
*toolPtr
;
1737 if (lpToolInfo
== NULL
)
1739 if (lpToolInfo
->cbSize
< TTTOOLINFO_V1_SIZEW
)
1742 nTool
= TOOLTIPS_GetToolFromInfoW (infoPtr
, lpToolInfo
);
1743 if (nTool
== -1) return 0;
1745 TRACE("tool %d\n", nTool
);
1747 toolPtr
= &infoPtr
->tools
[nTool
];
1749 /* copy tool data */
1750 toolPtr
->uFlags
= lpToolInfo
->uFlags
;
1751 toolPtr
->hwnd
= lpToolInfo
->hwnd
;
1752 toolPtr
->uId
= lpToolInfo
->uId
;
1753 toolPtr
->rect
= lpToolInfo
->rect
;
1754 toolPtr
->hinst
= lpToolInfo
->hinst
;
1756 if ((lpToolInfo
->hinst
) && (HIWORD((INT
)lpToolInfo
->lpszText
) == 0)) {
1757 TRACE("set string id %x!\n", (INT
)lpToolInfo
->lpszText
);
1758 toolPtr
->lpszText
= lpToolInfo
->lpszText
;
1760 else if (lpToolInfo
->lpszText
) {
1761 if (lpToolInfo
->lpszText
== LPSTR_TEXTCALLBACKW
)
1762 toolPtr
->lpszText
= LPSTR_TEXTCALLBACKW
;
1764 if ( (toolPtr
->lpszText
) &&
1765 (HIWORD((INT
)toolPtr
->lpszText
) != 0) ) {
1766 COMCTL32_Free (toolPtr
->lpszText
);
1767 toolPtr
->lpszText
= NULL
;
1769 if (lpToolInfo
->lpszText
) {
1770 INT len
= lstrlenW (lpToolInfo
->lpszText
);
1771 toolPtr
->lpszText
= COMCTL32_Alloc ((len
+1)*sizeof(WCHAR
));
1772 strcpyW (toolPtr
->lpszText
, lpToolInfo
->lpszText
);
1777 if (lpToolInfo
->cbSize
>= sizeof(TTTOOLINFOW
))
1778 toolPtr
->lParam
= lpToolInfo
->lParam
;
1785 TOOLTIPS_TrackActivate (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
1787 TOOLTIPS_INFO
*infoPtr
= TOOLTIPS_GetInfoPtr (hwnd
);
1788 LPTTTOOLINFOA lpToolInfo
= (LPTTTOOLINFOA
)lParam
;
1790 if (lpToolInfo
== NULL
)
1792 if (lpToolInfo
->cbSize
< TTTOOLINFO_V1_SIZEA
)
1797 infoPtr
->nTrackTool
= TOOLTIPS_GetToolFromInfoA (infoPtr
, lpToolInfo
);
1798 if (infoPtr
->nTrackTool
!= -1) {
1799 TRACE("activated!\n");
1800 infoPtr
->bTrackActive
= TRUE
;
1801 TOOLTIPS_TrackShow (hwnd
, infoPtr
);
1806 TOOLTIPS_TrackHide (hwnd
, infoPtr
);
1808 infoPtr
->bTrackActive
= FALSE
;
1809 infoPtr
->nTrackTool
= -1;
1811 TRACE("deactivated!\n");
1819 TOOLTIPS_TrackPosition (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
1821 TOOLTIPS_INFO
*infoPtr
= TOOLTIPS_GetInfoPtr (hwnd
);
1823 infoPtr
->xTrackPos
= (INT
)LOWORD(lParam
);
1824 infoPtr
->yTrackPos
= (INT
)HIWORD(lParam
);
1826 if (infoPtr
->bTrackActive
) {
1828 infoPtr
->xTrackPos
, infoPtr
->yTrackPos
);
1830 TOOLTIPS_TrackShow (hwnd
, infoPtr
);
1838 TOOLTIPS_Update (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
1840 TOOLTIPS_INFO
*infoPtr
= TOOLTIPS_GetInfoPtr (hwnd
);
1842 if (infoPtr
->nCurrentTool
!= -1)
1843 UpdateWindow (hwnd
);
1850 TOOLTIPS_UpdateTipTextA (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
1852 TOOLTIPS_INFO
*infoPtr
= TOOLTIPS_GetInfoPtr (hwnd
);
1853 LPTTTOOLINFOA lpToolInfo
= (LPTTTOOLINFOA
)lParam
;
1854 TTTOOL_INFO
*toolPtr
;
1857 if (lpToolInfo
== NULL
)
1859 if (lpToolInfo
->cbSize
< TTTOOLINFO_V1_SIZEA
)
1862 nTool
= TOOLTIPS_GetToolFromInfoA (infoPtr
, lpToolInfo
);
1863 if (nTool
== -1) return 0;
1865 TRACE("tool %d\n", nTool
);
1867 toolPtr
= &infoPtr
->tools
[nTool
];
1869 /* copy tool text */
1870 toolPtr
->hinst
= lpToolInfo
->hinst
;
1872 if ((lpToolInfo
->hinst
) && (HIWORD((INT
)lpToolInfo
->lpszText
) == 0)){
1873 toolPtr
->lpszText
= (LPWSTR
)lpToolInfo
->lpszText
;
1875 else if (lpToolInfo
->lpszText
) {
1876 if (lpToolInfo
->lpszText
== LPSTR_TEXTCALLBACKA
)
1877 toolPtr
->lpszText
= LPSTR_TEXTCALLBACKW
;
1879 if ( (toolPtr
->lpszText
) &&
1880 (HIWORD((INT
)toolPtr
->lpszText
) != 0) ) {
1881 COMCTL32_Free (toolPtr
->lpszText
);
1882 toolPtr
->lpszText
= NULL
;
1884 if (lpToolInfo
->lpszText
) {
1885 INT len
= MultiByteToWideChar(CP_ACP
, 0, lpToolInfo
->lpszText
,
1887 toolPtr
->lpszText
= COMCTL32_Alloc (len
* sizeof(WCHAR
));
1888 MultiByteToWideChar(CP_ACP
, 0, lpToolInfo
->lpszText
, -1,
1889 toolPtr
->lpszText
, len
);
1894 if(infoPtr
->nCurrentTool
== -1) return 0;
1896 if (infoPtr
->bActive
)
1897 TOOLTIPS_Show (hwnd
, infoPtr
);
1898 else if (infoPtr
->bTrackActive
)
1899 TOOLTIPS_TrackShow (hwnd
, infoPtr
);
1906 TOOLTIPS_UpdateTipTextW (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
1908 TOOLTIPS_INFO
*infoPtr
= TOOLTIPS_GetInfoPtr (hwnd
);
1909 LPTTTOOLINFOW lpToolInfo
= (LPTTTOOLINFOW
)lParam
;
1910 TTTOOL_INFO
*toolPtr
;
1913 if (lpToolInfo
== NULL
)
1915 if (lpToolInfo
->cbSize
< TTTOOLINFO_V1_SIZEW
)
1918 nTool
= TOOLTIPS_GetToolFromInfoW (infoPtr
, lpToolInfo
);
1922 TRACE("tool %d\n", nTool
);
1924 toolPtr
= &infoPtr
->tools
[nTool
];
1926 /* copy tool text */
1927 toolPtr
->hinst
= lpToolInfo
->hinst
;
1929 if ((lpToolInfo
->hinst
) && (HIWORD((INT
)lpToolInfo
->lpszText
) == 0)){
1930 toolPtr
->lpszText
= lpToolInfo
->lpszText
;
1932 else if (lpToolInfo
->lpszText
) {
1933 if (lpToolInfo
->lpszText
== LPSTR_TEXTCALLBACKW
)
1934 toolPtr
->lpszText
= LPSTR_TEXTCALLBACKW
;
1936 if ( (toolPtr
->lpszText
) &&
1937 (HIWORD((INT
)toolPtr
->lpszText
) != 0) ) {
1938 COMCTL32_Free (toolPtr
->lpszText
);
1939 toolPtr
->lpszText
= NULL
;
1941 if (lpToolInfo
->lpszText
) {
1942 INT len
= lstrlenW (lpToolInfo
->lpszText
);
1943 toolPtr
->lpszText
= COMCTL32_Alloc ((len
+1)*sizeof(WCHAR
));
1944 strcpyW (toolPtr
->lpszText
, lpToolInfo
->lpszText
);
1949 if(infoPtr
->nCurrentTool
== -1) return 0;
1951 if (infoPtr
->bActive
)
1952 TOOLTIPS_Show (hwnd
, infoPtr
);
1953 else if (infoPtr
->bTrackActive
)
1954 TOOLTIPS_TrackShow (hwnd
, infoPtr
);
1961 TOOLTIPS_WindowFromPoint (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
1963 return WindowFromPoint (*((LPPOINT
)lParam
));
1969 TOOLTIPS_Create (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
1971 TOOLTIPS_INFO
*infoPtr
;
1972 NONCLIENTMETRICSA nclm
;
1975 /* allocate memory for info structure */
1976 infoPtr
= (TOOLTIPS_INFO
*)COMCTL32_Alloc (sizeof(TOOLTIPS_INFO
));
1977 SetWindowLongA (hwnd
, 0, (DWORD
)infoPtr
);
1979 /* initialize info structure */
1980 infoPtr
->bActive
= TRUE
;
1981 infoPtr
->bTrackActive
= FALSE
;
1982 infoPtr
->clrBk
= GetSysColor (COLOR_INFOBK
);
1983 infoPtr
->clrText
= GetSysColor (COLOR_INFOTEXT
);
1985 nclm
.cbSize
= sizeof(NONCLIENTMETRICSA
);
1986 SystemParametersInfoA (SPI_GETNONCLIENTMETRICS
, 0, &nclm
, 0);
1987 infoPtr
->hFont
= CreateFontIndirectA (&nclm
.lfStatusFont
);
1989 infoPtr
->nMaxTipWidth
= -1;
1990 infoPtr
->nTool
= -1;
1991 infoPtr
->nCurrentTool
= -1;
1992 infoPtr
->nTrackTool
= -1;
1994 TOOLTIPS_SetDelayTime(hwnd
, TTDT_AUTOMATIC
, 0L);
1996 nResult
= (INT
) SendMessageA (GetParent (hwnd
), WM_NOTIFYFORMAT
,
1997 (WPARAM
)hwnd
, (LPARAM
)NF_QUERY
);
1998 if (nResult
== NFR_ANSI
) {
1999 infoPtr
->bNotifyUnicode
= FALSE
;
2000 TRACE(" -- WM_NOTIFYFORMAT returns: NFR_ANSI\n");
2002 else if (nResult
== NFR_UNICODE
) {
2003 infoPtr
->bNotifyUnicode
= TRUE
;
2004 TRACE(" -- WM_NOTIFYFORMAT returns: NFR_UNICODE\n");
2007 ERR (" -- WM_NOTIFYFORMAT returns: error!\n");
2010 SetWindowPos (hwnd
, HWND_TOP
, 0, 0, 0, 0, SWP_NOZORDER
| SWP_HIDEWINDOW
| SWP_NOACTIVATE
);
2017 TOOLTIPS_Destroy (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
2019 TOOLTIPS_INFO
*infoPtr
= TOOLTIPS_GetInfoPtr (hwnd
);
2020 TTTOOL_INFO
*toolPtr
;
2024 if (infoPtr
->tools
) {
2025 for (i
= 0; i
< infoPtr
->uNumTools
; i
++) {
2026 toolPtr
= &infoPtr
->tools
[i
];
2027 if ((toolPtr
->hinst
) && (toolPtr
->lpszText
)) {
2028 if ( (toolPtr
->lpszText
!= LPSTR_TEXTCALLBACKW
) &&
2029 (HIWORD((INT
)toolPtr
->lpszText
) != 0) )
2031 COMCTL32_Free (toolPtr
->lpszText
);
2032 toolPtr
->lpszText
= NULL
;
2036 /* remove subclassing */
2037 if (toolPtr
->uFlags
& TTF_SUBCLASS
) {
2038 LPTT_SUBCLASS_INFO lpttsi
;
2040 if (toolPtr
->uFlags
& TTF_IDISHWND
) {
2041 lpttsi
= (LPTT_SUBCLASS_INFO
)GetPropA ((HWND
)toolPtr
->uId
, COMCTL32_aSubclass
);
2043 SetWindowLongA ((HWND
)toolPtr
->uId
, GWL_WNDPROC
,
2044 (LONG
)lpttsi
->wpOrigProc
);
2045 RemovePropA ((HWND
)toolPtr
->uId
, COMCTL32_aSubclass
);
2046 COMCTL32_Free (&lpttsi
);
2050 lpttsi
= (LPTT_SUBCLASS_INFO
)GetPropA (toolPtr
->hwnd
, COMCTL32_aSubclass
);
2052 SetWindowLongA ((HWND
)toolPtr
->hwnd
, GWL_WNDPROC
,
2053 (LONG
)lpttsi
->wpOrigProc
);
2054 RemovePropA ((HWND
)toolPtr
->hwnd
, COMCTL32_aSubclass
);
2055 COMCTL32_Free (&lpttsi
);
2060 COMCTL32_Free (infoPtr
->tools
);
2064 DeleteObject (infoPtr
->hFont
);
2066 /* free tool tips info data */
2067 COMCTL32_Free (infoPtr
);
2068 SetWindowLongA(hwnd
, 0, 0);
2074 TOOLTIPS_EraseBackground (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
2076 TOOLTIPS_INFO
*infoPtr
= TOOLTIPS_GetInfoPtr (hwnd
);
2080 hBrush
= CreateSolidBrush (infoPtr
->clrBk
);
2081 GetClientRect (hwnd
, &rect
);
2082 FillRect ((HDC
)wParam
, &rect
, hBrush
);
2083 DeleteObject (hBrush
);
2090 TOOLTIPS_GetFont (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
2092 TOOLTIPS_INFO
*infoPtr
= TOOLTIPS_GetInfoPtr (hwnd
);
2094 return infoPtr
->hFont
;
2099 TOOLTIPS_MouseMessage (HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
2101 TOOLTIPS_INFO
*infoPtr
= TOOLTIPS_GetInfoPtr (hwnd
);
2103 TOOLTIPS_Hide (hwnd
, infoPtr
);
2110 TOOLTIPS_NCCreate (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
2112 DWORD dwStyle
= GetWindowLongA (hwnd
, GWL_STYLE
);
2114 dwStyle
&= 0x0000FFFF;
2115 dwStyle
|= (WS_POPUP
| WS_BORDER
| WS_CLIPSIBLINGS
);
2116 SetWindowLongA (hwnd
, GWL_STYLE
, dwStyle
);
2123 TOOLTIPS_NCHitTest (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
2125 TOOLTIPS_INFO
*infoPtr
= TOOLTIPS_GetInfoPtr (hwnd
);
2126 INT nTool
= (infoPtr
->bTrackActive
) ? infoPtr
->nTrackTool
: infoPtr
->nTool
;
2128 TRACE(" nTool=%d\n", nTool
);
2130 if ((nTool
> -1) && (nTool
< infoPtr
->uNumTools
)) {
2131 if (infoPtr
->tools
[nTool
].uFlags
& TTF_TRANSPARENT
) {
2132 TRACE("-- in transparent mode!\n");
2133 return HTTRANSPARENT
;
2137 return DefWindowProcA (hwnd
, WM_NCHITTEST
, wParam
, lParam
);
2142 TOOLTIPS_NotifyFormat (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
2144 FIXME ("hwnd=%x wParam=%x lParam=%lx\n", hwnd
, wParam
, lParam
);
2151 TOOLTIPS_Paint (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
2156 hdc
= (wParam
== 0) ? BeginPaint (hwnd
, &ps
) : (HDC
)wParam
;
2157 TOOLTIPS_Refresh (hwnd
, hdc
);
2159 EndPaint (hwnd
, &ps
);
2165 TOOLTIPS_SetFont (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
2167 TOOLTIPS_INFO
*infoPtr
= TOOLTIPS_GetInfoPtr (hwnd
);
2169 infoPtr
->hFont
= (HFONT
)wParam
;
2171 if ((LOWORD(lParam
)) & (infoPtr
->nCurrentTool
!= -1)) {
2172 FIXME("full redraw needed!\n");
2177 /******************************************************************
2178 * TOOLTIPS_OnWMGetTextLength
2180 * This function is called when the tooltip receive a
2181 * WM_GETTEXTLENGTH message.
2185 * returns the length, in characters, of the tip text
2186 ******************************************************************/
2188 TOOLTIPS_OnWMGetTextLength(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
2190 TOOLTIPS_INFO
*infoPtr
= TOOLTIPS_GetInfoPtr (hwnd
);
2191 return lstrlenW(infoPtr
->szTipText
);
2194 /******************************************************************
2195 * TOOLTIPS_OnWMGetText
2197 * This function is called when the tooltip receive a
2198 * WM_GETTEXT message.
2199 * wParam : specifies the maximum number of characters to be copied
2200 * lParam : is the pointer to the buffer that will receive
2203 * returns the number of characters copied
2204 ******************************************************************/
2206 TOOLTIPS_OnWMGetText (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
2208 TOOLTIPS_INFO
*infoPtr
= TOOLTIPS_GetInfoPtr (hwnd
);
2210 if(!infoPtr
|| !(infoPtr
->szTipText
))
2213 return WideCharToMultiByte(CP_ACP
, 0, infoPtr
->szTipText
, -1,
2214 (LPSTR
)lParam
, wParam
, NULL
, NULL
);
2218 TOOLTIPS_Timer (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
2220 TOOLTIPS_INFO
*infoPtr
= TOOLTIPS_GetInfoPtr (hwnd
);
2223 TRACE("timer %d (%x) expired!\n", wParam
, hwnd
);
2227 KillTimer (hwnd
, ID_TIMERSHOW
);
2228 nOldTool
= infoPtr
->nTool
;
2229 if ((infoPtr
->nTool
= TOOLTIPS_CheckTool (hwnd
, TRUE
)) == nOldTool
)
2230 TOOLTIPS_Show (hwnd
, infoPtr
);
2234 TOOLTIPS_Hide (hwnd
, infoPtr
);
2238 nOldTool
= infoPtr
->nTool
;
2239 infoPtr
->nTool
= TOOLTIPS_CheckTool (hwnd
, FALSE
);
2240 TRACE("tool (%x) %d %d %d\n", hwnd
, nOldTool
,
2241 infoPtr
->nTool
, infoPtr
->nCurrentTool
);
2242 if (infoPtr
->nTool
!= nOldTool
) {
2243 if(infoPtr
->nTool
== -1) { /* Moved out of all tools */
2244 TOOLTIPS_Hide(hwnd
, infoPtr
);
2245 KillTimer(hwnd
, ID_TIMERLEAVE
);
2246 } else if (nOldTool
== -1) { /* Moved from outside */
2247 ERR("How did this happen?\n");
2248 } else { /* Moved from one to another */
2249 TOOLTIPS_Hide (hwnd
, infoPtr
);
2250 KillTimer(hwnd
, ID_TIMERLEAVE
);
2251 if(infoPtr
->bActive
) {
2252 SetTimer (hwnd
, ID_TIMERSHOW
, infoPtr
->nReshowTime
, 0);
2253 TRACE("timer 1 started!\n");
2260 ERR("Unknown timer id %d\n", wParam
);
2268 TOOLTIPS_WinIniChange (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
2270 TOOLTIPS_INFO
*infoPtr
= TOOLTIPS_GetInfoPtr (hwnd
);
2271 NONCLIENTMETRICSA nclm
;
2273 infoPtr
->clrBk
= GetSysColor (COLOR_INFOBK
);
2274 infoPtr
->clrText
= GetSysColor (COLOR_INFOTEXT
);
2276 DeleteObject (infoPtr
->hFont
);
2277 nclm
.cbSize
= sizeof(NONCLIENTMETRICSA
);
2278 SystemParametersInfoA (SPI_GETNONCLIENTMETRICS
, 0, &nclm
, 0);
2279 infoPtr
->hFont
= CreateFontIndirectA (&nclm
.lfStatusFont
);
2286 TOOLTIPS_SubclassProc (HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
2288 LPTT_SUBCLASS_INFO lpttsi
=
2289 (LPTT_SUBCLASS_INFO
)GetPropA (hwnd
, COMCTL32_aSubclass
);
2294 case WM_LBUTTONDOWN
:
2296 case WM_MBUTTONDOWN
:
2298 case WM_RBUTTONDOWN
:
2302 msg
.wParam
= wParam
;
2303 msg
.lParam
= lParam
;
2304 TOOLTIPS_RelayEvent(lpttsi
->hwndToolTip
, 0, (LPARAM
)&msg
);
2310 return CallWindowProcA (lpttsi
->wpOrigProc
, hwnd
, uMsg
, wParam
, lParam
);
2314 static LRESULT CALLBACK
2315 TOOLTIPS_WindowProc (HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
2317 TRACE("hwnd=%x msg=%x wparam=%x lParam=%lx\n", hwnd
, uMsg
, wParam
, lParam
);
2318 if (!TOOLTIPS_GetInfoPtr(hwnd
) && (uMsg
!= WM_CREATE
) && (uMsg
!= WM_NCCREATE
))
2319 return DefWindowProcA (hwnd
, uMsg
, wParam
, lParam
);
2323 return TOOLTIPS_Activate (hwnd
, wParam
, lParam
);
2326 return TOOLTIPS_AddToolA (hwnd
, wParam
, lParam
);
2329 return TOOLTIPS_AddToolW (hwnd
, wParam
, lParam
);
2332 return TOOLTIPS_DelToolA (hwnd
, wParam
, lParam
);
2335 return TOOLTIPS_DelToolW (hwnd
, wParam
, lParam
);
2337 case TTM_ENUMTOOLSA
:
2338 return TOOLTIPS_EnumToolsA (hwnd
, wParam
, lParam
);
2340 case TTM_ENUMTOOLSW
:
2341 return TOOLTIPS_EnumToolsW (hwnd
, wParam
, lParam
);
2343 case TTM_GETCURRENTTOOLA
:
2344 return TOOLTIPS_GetCurrentToolA (hwnd
, wParam
, lParam
);
2346 case TTM_GETCURRENTTOOLW
:
2347 return TOOLTIPS_GetCurrentToolW (hwnd
, wParam
, lParam
);
2349 case TTM_GETDELAYTIME
:
2350 return TOOLTIPS_GetDelayTime (hwnd
, wParam
, lParam
);
2353 return TOOLTIPS_GetMargin (hwnd
, wParam
, lParam
);
2355 case TTM_GETMAXTIPWIDTH
:
2356 return TOOLTIPS_GetMaxTipWidth (hwnd
, wParam
, lParam
);
2359 return TOOLTIPS_GetTextA (hwnd
, wParam
, lParam
);
2362 return TOOLTIPS_GetTextW (hwnd
, wParam
, lParam
);
2364 case TTM_GETTIPBKCOLOR
:
2365 return TOOLTIPS_GetTipBkColor (hwnd
, wParam
, lParam
);
2367 case TTM_GETTIPTEXTCOLOR
:
2368 return TOOLTIPS_GetTipTextColor (hwnd
, wParam
, lParam
);
2370 case TTM_GETTOOLCOUNT
:
2371 return TOOLTIPS_GetToolCount (hwnd
, wParam
, lParam
);
2373 case TTM_GETTOOLINFOA
:
2374 return TOOLTIPS_GetToolInfoA (hwnd
, wParam
, lParam
);
2376 case TTM_GETTOOLINFOW
:
2377 return TOOLTIPS_GetToolInfoW (hwnd
, wParam
, lParam
);
2380 return TOOLTIPS_HitTestA (hwnd
, wParam
, lParam
);
2383 return TOOLTIPS_HitTestW (hwnd
, wParam
, lParam
);
2385 case TTM_NEWTOOLRECTA
:
2386 return TOOLTIPS_NewToolRectA (hwnd
, wParam
, lParam
);
2388 case TTM_NEWTOOLRECTW
:
2389 return TOOLTIPS_NewToolRectW (hwnd
, wParam
, lParam
);
2392 return TOOLTIPS_Pop (hwnd
, wParam
, lParam
);
2394 case TTM_RELAYEVENT
:
2395 return TOOLTIPS_RelayEvent (hwnd
, wParam
, lParam
);
2397 case TTM_SETDELAYTIME
:
2398 return TOOLTIPS_SetDelayTime (hwnd
, wParam
, lParam
);
2401 return TOOLTIPS_SetMargin (hwnd
, wParam
, lParam
);
2403 case TTM_SETMAXTIPWIDTH
:
2404 return TOOLTIPS_SetMaxTipWidth (hwnd
, wParam
, lParam
);
2406 case TTM_SETTIPBKCOLOR
:
2407 return TOOLTIPS_SetTipBkColor (hwnd
, wParam
, lParam
);
2409 case TTM_SETTIPTEXTCOLOR
:
2410 return TOOLTIPS_SetTipTextColor (hwnd
, wParam
, lParam
);
2412 case TTM_SETTOOLINFOA
:
2413 return TOOLTIPS_SetToolInfoA (hwnd
, wParam
, lParam
);
2415 case TTM_SETTOOLINFOW
:
2416 return TOOLTIPS_SetToolInfoW (hwnd
, wParam
, lParam
);
2418 case TTM_TRACKACTIVATE
:
2419 return TOOLTIPS_TrackActivate (hwnd
, wParam
, lParam
);
2421 case TTM_TRACKPOSITION
:
2422 return TOOLTIPS_TrackPosition (hwnd
, wParam
, lParam
);
2425 return TOOLTIPS_Update (hwnd
, wParam
, lParam
);
2427 case TTM_UPDATETIPTEXTA
:
2428 return TOOLTIPS_UpdateTipTextA (hwnd
, wParam
, lParam
);
2430 case TTM_UPDATETIPTEXTW
:
2431 return TOOLTIPS_UpdateTipTextW (hwnd
, wParam
, lParam
);
2433 case TTM_WINDOWFROMPOINT
:
2434 return TOOLTIPS_WindowFromPoint (hwnd
, wParam
, lParam
);
2438 return TOOLTIPS_Create (hwnd
, wParam
, lParam
);
2441 return TOOLTIPS_Destroy (hwnd
, wParam
, lParam
);
2444 return TOOLTIPS_EraseBackground (hwnd
, wParam
, lParam
);
2447 return TOOLTIPS_GetFont (hwnd
, wParam
, lParam
);
2450 return TOOLTIPS_OnWMGetText (hwnd
, wParam
, lParam
);
2452 case WM_GETTEXTLENGTH
:
2453 return TOOLTIPS_OnWMGetTextLength (hwnd
, wParam
, lParam
);
2456 case WM_LBUTTONDOWN
:
2458 case WM_MBUTTONDOWN
:
2460 case WM_RBUTTONDOWN
:
2463 return TOOLTIPS_MouseMessage (hwnd
, uMsg
, wParam
, lParam
);
2466 return TOOLTIPS_NCCreate (hwnd
, wParam
, lParam
);
2469 return TOOLTIPS_NCHitTest (hwnd
, wParam
, lParam
);
2471 case WM_NOTIFYFORMAT
:
2472 return TOOLTIPS_NotifyFormat (hwnd
, wParam
, lParam
);
2475 return TOOLTIPS_Paint (hwnd
, wParam
, lParam
);
2478 return TOOLTIPS_SetFont (hwnd
, wParam
, lParam
);
2481 return TOOLTIPS_Timer (hwnd
, wParam
, lParam
);
2483 case WM_WININICHANGE
:
2484 return TOOLTIPS_WinIniChange (hwnd
, wParam
, lParam
);
2487 if (uMsg
>= WM_USER
)
2488 ERR("unknown msg %04x wp=%08x lp=%08lx\n",
2489 uMsg
, wParam
, lParam
);
2490 return DefWindowProcA (hwnd
, uMsg
, wParam
, lParam
);
2497 TOOLTIPS_Register (void)
2501 ZeroMemory (&wndClass
, sizeof(WNDCLASSA
));
2502 wndClass
.style
= CS_GLOBALCLASS
| CS_DBLCLKS
| CS_SAVEBITS
;
2503 wndClass
.lpfnWndProc
= (WNDPROC
)TOOLTIPS_WindowProc
;
2504 wndClass
.cbClsExtra
= 0;
2505 wndClass
.cbWndExtra
= sizeof(TOOLTIPS_INFO
*);
2506 wndClass
.hCursor
= LoadCursorA (0, IDC_ARROWA
);
2507 wndClass
.hbrBackground
= 0;
2508 wndClass
.lpszClassName
= TOOLTIPS_CLASSA
;
2510 RegisterClassA (&wndClass
);
2515 TOOLTIPS_Unregister (void)
2517 UnregisterClassA (TOOLTIPS_CLASSA
, (HINSTANCE
)NULL
);