4 * Copyright 1998, 1999 Eric Kohl
5 * Copyright 2004 Robert Shearman
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 * This code was audited for completeness against the documented features
24 * of Comctl32.dll version 6.0 on Sep. 08, 2004, by Robert Shearman.
26 * Unless otherwise noted, we believe this code to be complete, as per
27 * the specification mentioned above.
28 * If you discover missing features or bugs please note them below.
31 * - Custom draw support.
45 * - Run tests using Waite Group Windows95 API Bible Volume 2.
46 * The second cdrom (chapter 3) contains executables activate.exe,
47 * curtool.exe, deltool.exe, enumtools.exe, getinfo.exe, getiptxt.exe,
48 * hittest.exe, needtext.exe, newrect.exe, updtext.exe and winfrpt.exe.
52 * One important point to remember is that tools don't necessarily get
53 * a WM_MOUSEMOVE once the cursor leaves the tool, an example is when
54 * a tool sets TTF_IDISHWND (i.e. an entire window is a tool) because
55 * here WM_MOUSEMOVEs only get sent when the cursor is inside the
56 * client area. Therefore the only reliable way to know that the
57 * cursor has left a tool is to keep a timer running and check the
58 * position every time it expires. This is the role of timer
62 * On entering a tool (detected in a relayed WM_MOUSEMOVE) we start
63 * ID_TIMERSHOW, if this times out and we're still in the tool we show
64 * the tip. On showing a tip we start both ID_TIMERPOP and
65 * ID_TIMERLEAVE. On hiding a tooltip we kill ID_TIMERPOP.
66 * ID_TIMERPOP is restarted on every relayed WM_MOUSEMOVE. If
67 * ID_TIMERPOP expires the tool is hidden and ID_TIMERPOP is killed.
68 * ID_TIMERLEAVE remains running - this is important as we need to
69 * determine when the cursor leaves the tool.
71 * When ID_TIMERLEAVE expires or on a relayed WM_MOUSEMOVE if we're
72 * still in the tool do nothing (apart from restart ID_TIMERPOP if
73 * this is a WM_MOUSEMOVE) (ID_TIMERLEAVE remains running). If we've
74 * left the tool and entered another one then hide the tip and start
75 * ID_TIMERSHOW with time ReshowTime and kill ID_TIMERLEAVE. If we're
76 * outside all tools hide the tip and kill ID_TIMERLEAVE. On Relayed
77 * mouse button messages hide the tip but leave ID_TIMERLEAVE running,
78 * this again will let us keep track of when the cursor leaves the
82 * infoPtr->nTool is the tool the mouse was on on the last relayed MM
83 * or timer expiry or -1 if the mouse was not on a tool.
85 * infoPtr->nCurrentTool is the tool for which the tip is currently
86 * displaying text for or -1 if the tip is not shown. Actually this
87 * will only ever be infoPtr-nTool or -1, so it could be changed to a
102 #include "commctrl.h"
103 #include "comctl32.h"
104 #include "wine/debug.h"
106 WINE_DEFAULT_DEBUG_CHANNEL(tooltips
);
108 static HICON hTooltipIcons
[TTI_ERROR
+1];
127 WCHAR szTipText
[INFOTIPSIZE
];
138 INT nTool
; /* tool that mouse was on on last relayed mouse move */
152 #define ID_TIMERSHOW 1 /* show delay timer */
153 #define ID_TIMERPOP 2 /* auto pop timer */
154 #define ID_TIMERLEAVE 3 /* tool leave timer */
157 #define TOOLTIPS_GetInfoPtr(hWindow) ((TOOLTIPS_INFO *)GetWindowLongPtrW (hWindow, 0))
159 /* offsets from window edge to start of text */
160 #define NORMAL_TEXT_MARGIN 2
161 #define BALLOON_TEXT_MARGIN (NORMAL_TEXT_MARGIN+8)
162 /* value used for CreateRoundRectRgn that specifies how much
163 * each corner is curved */
164 #define BALLOON_ROUNDEDNESS 20
165 #define BALLOON_STEMHEIGHT 13
166 #define BALLOON_STEMWIDTH 10
167 #define BALLOON_STEMINDENT 20
169 #define BALLOON_ICON_TITLE_SPACING 8 /* horizontal spacing between icon and title */
170 #define BALLOON_TITLE_TEXT_SPACING 8 /* vertical spacing between icon/title and main text */
171 #define ICON_HEIGHT 16
172 #define ICON_WIDTH 16
174 #define MAX_TEXT_SIZE_A 80 /* maximum retrieving text size by ANSI message */
176 static LRESULT CALLBACK
177 TOOLTIPS_SubclassProc (HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
, UINT_PTR uId
, DWORD_PTR dwRef
);
179 static inline UINT_PTR
180 TOOLTIPS_GetTitleIconIndex(HICON hIcon
)
183 for (i
= 0; i
<= TTI_ERROR
; i
++)
184 if (hTooltipIcons
[i
] == hIcon
)
186 return (UINT_PTR
)hIcon
;
190 TOOLTIPS_InitSystemSettings (TOOLTIPS_INFO
*infoPtr
)
192 NONCLIENTMETRICSW nclm
;
194 infoPtr
->clrBk
= comctl32_color
.clrInfoBk
;
195 infoPtr
->clrText
= comctl32_color
.clrInfoText
;
197 DeleteObject (infoPtr
->hFont
);
198 nclm
.cbSize
= sizeof(nclm
);
199 SystemParametersInfoW (SPI_GETNONCLIENTMETRICS
, sizeof(nclm
), &nclm
, 0);
200 infoPtr
->hFont
= CreateFontIndirectW (&nclm
.lfStatusFont
);
202 DeleteObject (infoPtr
->hTitleFont
);
203 nclm
.lfStatusFont
.lfWeight
= FW_BOLD
;
204 infoPtr
->hTitleFont
= CreateFontIndirectW (&nclm
.lfStatusFont
);
207 /* Custom draw routines */
209 TOOLTIPS_customdraw_fill(const TOOLTIPS_INFO
*infoPtr
, NMTTCUSTOMDRAW
*lpnmttcd
,
210 HDC hdc
, const RECT
*rcBounds
, UINT uFlags
)
212 ZeroMemory(lpnmttcd
, sizeof(NMTTCUSTOMDRAW
));
213 lpnmttcd
->uDrawFlags
= uFlags
;
214 lpnmttcd
->nmcd
.hdr
.hwndFrom
= infoPtr
->hwndSelf
;
215 lpnmttcd
->nmcd
.hdr
.code
= NM_CUSTOMDRAW
;
216 if (infoPtr
->nCurrentTool
!= -1) {
217 TTTOOL_INFO
*toolPtr
= &infoPtr
->tools
[infoPtr
->nCurrentTool
];
218 lpnmttcd
->nmcd
.hdr
.idFrom
= toolPtr
->uId
;
220 lpnmttcd
->nmcd
.hdc
= hdc
;
221 lpnmttcd
->nmcd
.rc
= *rcBounds
;
222 /* FIXME - dwItemSpec, uItemState, lItemlParam */
226 TOOLTIPS_notify_customdraw (DWORD dwDrawStage
, NMTTCUSTOMDRAW
*lpnmttcd
)
229 lpnmttcd
->nmcd
.dwDrawStage
= dwDrawStage
;
231 TRACE("Notifying stage %d, flags %x, id %x\n", lpnmttcd
->nmcd
.dwDrawStage
,
232 lpnmttcd
->uDrawFlags
, lpnmttcd
->nmcd
.hdr
.code
);
234 result
= SendMessageW(GetParent(lpnmttcd
->nmcd
.hdr
.hwndFrom
), WM_NOTIFY
,
235 0, (LPARAM
)lpnmttcd
);
237 TRACE("Notify result %x\n", (unsigned int)result
);
243 TOOLTIPS_Refresh (const TOOLTIPS_INFO
*infoPtr
, HDC hdc
)
249 UINT uFlags
= DT_EXTERNALLEADING
;
251 DWORD dwStyle
= GetWindowLongW(infoPtr
->hwndSelf
, GWL_STYLE
);
252 NMTTCUSTOMDRAW nmttcd
;
255 if (infoPtr
->nMaxTipWidth
> -1)
256 uFlags
|= DT_WORDBREAK
;
257 if (GetWindowLongW (infoPtr
->hwndSelf
, GWL_STYLE
) & TTS_NOPREFIX
)
258 uFlags
|= DT_NOPREFIX
;
259 GetClientRect (infoPtr
->hwndSelf
, &rc
);
261 hBrush
= CreateSolidBrush(infoPtr
->clrBk
);
263 oldBkMode
= SetBkMode (hdc
, TRANSPARENT
);
264 SetTextColor (hdc
, infoPtr
->clrText
);
265 hOldFont
= SelectObject (hdc
, infoPtr
->hFont
);
267 /* Custom draw - Call PrePaint once initial properties set up */
268 /* Note: Contrary to MSDN, CDRF_SKIPDEFAULT still draws a tooltip */
269 TOOLTIPS_customdraw_fill(infoPtr
, &nmttcd
, hdc
, &rc
, uFlags
);
270 cdmode
= TOOLTIPS_notify_customdraw(CDDS_PREPAINT
, &nmttcd
);
271 uFlags
= nmttcd
.uDrawFlags
;
273 if (dwStyle
& TTS_BALLOON
)
275 /* create a region to store result into */
276 hRgn
= CreateRectRgn(0, 0, 0, 0);
278 GetWindowRgn(infoPtr
->hwndSelf
, hRgn
);
280 /* fill the background */
281 FillRgn(hdc
, hRgn
, hBrush
);
282 DeleteObject(hBrush
);
287 /* fill the background */
288 FillRect(hdc
, &rc
, hBrush
);
289 DeleteObject(hBrush
);
293 if ((dwStyle
& TTS_BALLOON
) || infoPtr
->pszTitle
)
295 /* calculate text rectangle */
296 rc
.left
+= (BALLOON_TEXT_MARGIN
+ infoPtr
->rcMargin
.left
);
297 rc
.top
+= (BALLOON_TEXT_MARGIN
+ infoPtr
->rcMargin
.top
);
298 rc
.right
-= (BALLOON_TEXT_MARGIN
+ infoPtr
->rcMargin
.right
);
299 rc
.bottom
-= (BALLOON_TEXT_MARGIN
+ infoPtr
->rcMargin
.bottom
);
300 if(infoPtr
->bToolBelow
) rc
.top
+= BALLOON_STEMHEIGHT
;
302 if (infoPtr
->pszTitle
)
304 RECT rcTitle
= {rc
.left
, rc
.top
, rc
.right
, rc
.bottom
};
310 icon_present
= infoPtr
->hTitleIcon
&&
311 DrawIconEx(hdc
, rc
.left
, rc
.top
, infoPtr
->hTitleIcon
,
312 ICON_WIDTH
, ICON_HEIGHT
, 0, NULL
, DI_NORMAL
);
314 rcTitle
.left
+= ICON_WIDTH
+ BALLOON_ICON_TITLE_SPACING
;
316 rcTitle
.bottom
= rc
.top
+ ICON_HEIGHT
;
318 /* draw title text */
319 prevFont
= SelectObject (hdc
, infoPtr
->hTitleFont
);
320 height
= DrawTextW(hdc
, infoPtr
->pszTitle
, -1, &rcTitle
, DT_BOTTOM
| DT_SINGLELINE
| DT_NOPREFIX
);
321 SelectObject (hdc
, prevFont
);
322 rc
.top
+= height
+ BALLOON_TITLE_TEXT_SPACING
;
327 /* calculate text rectangle */
328 rc
.left
+= (NORMAL_TEXT_MARGIN
+ infoPtr
->rcMargin
.left
);
329 rc
.top
+= (NORMAL_TEXT_MARGIN
+ infoPtr
->rcMargin
.top
);
330 rc
.right
-= (NORMAL_TEXT_MARGIN
+ infoPtr
->rcMargin
.right
);
331 rc
.bottom
-= (NORMAL_TEXT_MARGIN
+ infoPtr
->rcMargin
.bottom
);
335 DrawTextW (hdc
, infoPtr
->szTipText
, -1, &rc
, uFlags
);
337 /* Custom draw - Call PostPaint after drawing */
338 if (cdmode
& CDRF_NOTIFYPOSTPAINT
) {
339 TOOLTIPS_notify_customdraw(CDDS_POSTPAINT
, &nmttcd
);
342 /* be polite and reset the things we changed in the dc */
343 SelectObject (hdc
, hOldFont
);
344 SetBkMode (hdc
, oldBkMode
);
346 if (dwStyle
& TTS_BALLOON
)
348 /* frame region because default window proc doesn't do it */
349 INT width
= GetSystemMetrics(SM_CXDLGFRAME
) - GetSystemMetrics(SM_CXEDGE
);
350 INT height
= GetSystemMetrics(SM_CYDLGFRAME
) - GetSystemMetrics(SM_CYEDGE
);
352 hBrush
= GetSysColorBrush(COLOR_WINDOWFRAME
);
353 FrameRgn(hdc
, hRgn
, hBrush
, width
, height
);
360 static void TOOLTIPS_GetDispInfoA(const TOOLTIPS_INFO
*infoPtr
, TTTOOL_INFO
*toolPtr
, WCHAR
*buffer
)
362 NMTTDISPINFOA ttnmdi
;
364 /* fill NMHDR struct */
365 ZeroMemory (&ttnmdi
, sizeof(NMTTDISPINFOA
));
366 ttnmdi
.hdr
.hwndFrom
= infoPtr
->hwndSelf
;
367 ttnmdi
.hdr
.idFrom
= toolPtr
->uId
;
368 ttnmdi
.hdr
.code
= TTN_GETDISPINFOA
; /* == TTN_NEEDTEXTA */
369 ttnmdi
.lpszText
= ttnmdi
.szText
;
370 ttnmdi
.uFlags
= toolPtr
->uFlags
;
371 ttnmdi
.lParam
= toolPtr
->lParam
;
373 TRACE("hdr.idFrom = %lx\n", ttnmdi
.hdr
.idFrom
);
374 SendMessageW(toolPtr
->hwnd
, WM_NOTIFY
, toolPtr
->uId
, (LPARAM
)&ttnmdi
);
376 if (IS_INTRESOURCE(ttnmdi
.lpszText
)) {
377 LoadStringW(ttnmdi
.hinst
, LOWORD(ttnmdi
.lpszText
),
378 buffer
, INFOTIPSIZE
);
379 if (ttnmdi
.uFlags
& TTF_DI_SETITEM
) {
380 toolPtr
->hinst
= ttnmdi
.hinst
;
381 toolPtr
->lpszText
= (LPWSTR
)ttnmdi
.lpszText
;
384 else if (ttnmdi
.lpszText
== 0) {
387 else if (ttnmdi
.lpszText
!= LPSTR_TEXTCALLBACKA
) {
388 Str_GetPtrAtoW(ttnmdi
.lpszText
, buffer
, INFOTIPSIZE
);
389 if (ttnmdi
.uFlags
& TTF_DI_SETITEM
) {
391 toolPtr
->lpszText
= NULL
;
392 Str_SetPtrW(&toolPtr
->lpszText
, buffer
);
396 ERR("recursive text callback\n");
400 /* no text available - try calling parent instead as per native */
401 /* FIXME: Unsure if SETITEM should save the value or not */
402 if (buffer
[0] == 0x00) {
404 SendMessageW(GetParent(toolPtr
->hwnd
), WM_NOTIFY
, toolPtr
->uId
, (LPARAM
)&ttnmdi
);
406 if (IS_INTRESOURCE(ttnmdi
.lpszText
)) {
407 LoadStringW(ttnmdi
.hinst
, LOWORD(ttnmdi
.lpszText
),
408 buffer
, INFOTIPSIZE
);
409 } else if (ttnmdi
.lpszText
&&
410 ttnmdi
.lpszText
!= LPSTR_TEXTCALLBACKA
) {
411 Str_GetPtrAtoW(ttnmdi
.lpszText
, buffer
, INFOTIPSIZE
);
416 static void TOOLTIPS_GetDispInfoW(const TOOLTIPS_INFO
*infoPtr
, TTTOOL_INFO
*toolPtr
, WCHAR
*buffer
)
418 NMTTDISPINFOW ttnmdi
;
420 /* fill NMHDR struct */
421 ZeroMemory (&ttnmdi
, sizeof(NMTTDISPINFOW
));
422 ttnmdi
.hdr
.hwndFrom
= infoPtr
->hwndSelf
;
423 ttnmdi
.hdr
.idFrom
= toolPtr
->uId
;
424 ttnmdi
.hdr
.code
= TTN_GETDISPINFOW
; /* == TTN_NEEDTEXTW */
425 ttnmdi
.lpszText
= ttnmdi
.szText
;
426 ttnmdi
.uFlags
= toolPtr
->uFlags
;
427 ttnmdi
.lParam
= toolPtr
->lParam
;
429 TRACE("hdr.idFrom = %lx\n", ttnmdi
.hdr
.idFrom
);
430 SendMessageW(toolPtr
->hwnd
, WM_NOTIFY
, toolPtr
->uId
, (LPARAM
)&ttnmdi
);
432 if (IS_INTRESOURCE(ttnmdi
.lpszText
)) {
433 LoadStringW(ttnmdi
.hinst
, LOWORD(ttnmdi
.lpszText
),
434 buffer
, INFOTIPSIZE
);
435 if (ttnmdi
.uFlags
& TTF_DI_SETITEM
) {
436 toolPtr
->hinst
= ttnmdi
.hinst
;
437 toolPtr
->lpszText
= ttnmdi
.lpszText
;
440 else if (ttnmdi
.lpszText
== 0) {
443 else if (ttnmdi
.lpszText
!= LPSTR_TEXTCALLBACKW
) {
444 Str_GetPtrW(ttnmdi
.lpszText
, buffer
, INFOTIPSIZE
);
445 if (ttnmdi
.uFlags
& TTF_DI_SETITEM
) {
447 toolPtr
->lpszText
= NULL
;
448 Str_SetPtrW(&toolPtr
->lpszText
, buffer
);
452 ERR("recursive text callback\n");
456 /* no text available - try calling parent instead as per native */
457 /* FIXME: Unsure if SETITEM should save the value or not */
458 if (buffer
[0] == 0x00) {
460 SendMessageW(GetParent(toolPtr
->hwnd
), WM_NOTIFY
, toolPtr
->uId
, (LPARAM
)&ttnmdi
);
462 if (IS_INTRESOURCE(ttnmdi
.lpszText
)) {
463 LoadStringW(ttnmdi
.hinst
, LOWORD(ttnmdi
.lpszText
),
464 buffer
, INFOTIPSIZE
);
465 } else if (ttnmdi
.lpszText
&&
466 ttnmdi
.lpszText
!= LPSTR_TEXTCALLBACKW
) {
467 Str_GetPtrW(ttnmdi
.lpszText
, buffer
, INFOTIPSIZE
);
474 TOOLTIPS_GetTipText (const TOOLTIPS_INFO
*infoPtr
, INT nTool
, WCHAR
*buffer
)
476 TTTOOL_INFO
*toolPtr
= &infoPtr
->tools
[nTool
];
478 if (IS_INTRESOURCE(toolPtr
->lpszText
)) {
479 /* load a resource */
480 TRACE("load res string %p %x\n",
481 toolPtr
->hinst
, LOWORD(toolPtr
->lpszText
));
482 if (!LoadStringW (toolPtr
->hinst
, LOWORD(toolPtr
->lpszText
), buffer
, INFOTIPSIZE
))
485 else if (toolPtr
->lpszText
) {
486 if (toolPtr
->lpszText
== LPSTR_TEXTCALLBACKW
) {
487 if (toolPtr
->bNotifyUnicode
)
488 TOOLTIPS_GetDispInfoW(infoPtr
, toolPtr
, buffer
);
490 TOOLTIPS_GetDispInfoA(infoPtr
, toolPtr
, buffer
);
493 /* the item is a usual (unicode) text */
494 lstrcpynW (buffer
, toolPtr
->lpszText
, INFOTIPSIZE
);
498 /* no text available */
502 if (!(GetWindowLongW(infoPtr
->hwndSelf
, GWL_STYLE
) & TTS_NOPREFIX
)) {
504 if ((ptrW
= wcschr(buffer
, '\t')))
508 TRACE("%s\n", debugstr_w(buffer
));
513 TOOLTIPS_CalcTipSize (const TOOLTIPS_INFO
*infoPtr
, LPSIZE lpSize
)
517 DWORD style
= GetWindowLongW(infoPtr
->hwndSelf
, GWL_STYLE
);
518 UINT uFlags
= DT_EXTERNALLEADING
| DT_CALCRECT
;
519 RECT rc
= {0, 0, 0, 0};
522 if (infoPtr
->nMaxTipWidth
> -1) {
523 rc
.right
= infoPtr
->nMaxTipWidth
;
524 uFlags
|= DT_WORDBREAK
;
526 if (style
& TTS_NOPREFIX
)
527 uFlags
|= DT_NOPREFIX
;
528 TRACE("%s\n", debugstr_w(infoPtr
->szTipText
));
530 hdc
= GetDC (infoPtr
->hwndSelf
);
531 if (infoPtr
->pszTitle
)
533 RECT rcTitle
= {0, 0, 0, 0};
534 TRACE("title %s\n", debugstr_w(infoPtr
->pszTitle
));
535 if (infoPtr
->hTitleIcon
)
537 title
.cx
= ICON_WIDTH
;
538 title
.cy
= ICON_HEIGHT
;
540 if (title
.cx
!= 0) title
.cx
+= BALLOON_ICON_TITLE_SPACING
;
541 hOldFont
= SelectObject (hdc
, infoPtr
->hTitleFont
);
542 DrawTextW(hdc
, infoPtr
->pszTitle
, -1, &rcTitle
, DT_SINGLELINE
| DT_NOPREFIX
| DT_CALCRECT
);
543 SelectObject (hdc
, hOldFont
);
544 title
.cy
= max(title
.cy
, rcTitle
.bottom
- rcTitle
.top
) + BALLOON_TITLE_TEXT_SPACING
;
545 title
.cx
+= (rcTitle
.right
- rcTitle
.left
);
547 hOldFont
= SelectObject (hdc
, infoPtr
->hFont
);
548 DrawTextW (hdc
, infoPtr
->szTipText
, -1, &rc
, uFlags
);
549 SelectObject (hdc
, hOldFont
);
550 ReleaseDC (infoPtr
->hwndSelf
, hdc
);
552 if ((style
& TTS_BALLOON
) || infoPtr
->pszTitle
)
554 lpSize
->cx
= max(rc
.right
- rc
.left
, title
.cx
) + 2*BALLOON_TEXT_MARGIN
+
555 infoPtr
->rcMargin
.left
+ infoPtr
->rcMargin
.right
;
556 lpSize
->cy
= title
.cy
+ rc
.bottom
- rc
.top
+ 2*BALLOON_TEXT_MARGIN
+
557 infoPtr
->rcMargin
.bottom
+ infoPtr
->rcMargin
.top
+
562 lpSize
->cx
= rc
.right
- rc
.left
+ 2*NORMAL_TEXT_MARGIN
+
563 infoPtr
->rcMargin
.left
+ infoPtr
->rcMargin
.right
;
564 lpSize
->cy
= rc
.bottom
- rc
.top
+ 2*NORMAL_TEXT_MARGIN
+
565 infoPtr
->rcMargin
.bottom
+ infoPtr
->rcMargin
.top
;
571 TOOLTIPS_Show (TOOLTIPS_INFO
*infoPtr
, BOOL track_activate
)
573 TTTOOL_INFO
*toolPtr
;
575 MONITORINFO mon_info
;
580 DWORD style
= GetWindowLongW(infoPtr
->hwndSelf
, GWL_STYLE
);
585 if (infoPtr
->nTrackTool
== -1)
587 TRACE("invalid tracking tool %d\n", infoPtr
->nTrackTool
);
590 nTool
= infoPtr
->nTrackTool
;
594 if (infoPtr
->nTool
== -1)
596 TRACE("invalid tool %d\n", infoPtr
->nTool
);
599 nTool
= infoPtr
->nTool
;
602 TRACE("Show tooltip pre %d, %p\n", nTool
, infoPtr
->hwndSelf
);
604 current
= infoPtr
->nCurrentTool
;
606 infoPtr
->nCurrentTool
= infoPtr
->nTool
;
608 TOOLTIPS_GetTipText (infoPtr
, nTool
, infoPtr
->szTipText
);
610 if (infoPtr
->szTipText
[0] == '\0')
612 infoPtr
->nCurrentTool
= current
;
616 toolPtr
= &infoPtr
->tools
[nTool
];
617 TOOLTIPS_CalcTipSize (infoPtr
, &size
);
619 TRACE("Show tooltip %d, %s, size %d x %d\n", nTool
, debugstr_w(infoPtr
->szTipText
),
622 if (track_activate
&& (toolPtr
->uFlags
& TTF_TRACK
))
624 rect
.left
= infoPtr
->xTrackPos
;
625 rect
.top
= infoPtr
->yTrackPos
;
628 if (toolPtr
->uFlags
& TTF_CENTERTIP
)
630 rect
.left
-= (size
.cx
/ 2);
631 if (!(style
& TTS_BALLOON
))
632 rect
.top
-= (size
.cy
/ 2);
634 if (!(infoPtr
->bToolBelow
= (infoPtr
->yTrackPos
+ size
.cy
<= GetSystemMetrics(SM_CYSCREEN
))))
637 if (!(toolPtr
->uFlags
& TTF_ABSOLUTE
))
639 if (style
& TTS_BALLOON
)
640 rect
.left
-= BALLOON_STEMINDENT
;
645 if (toolPtr
->uFlags
& TTF_IDISHWND
)
646 GetWindowRect ((HWND
)toolPtr
->uId
, &rcTool
);
649 rcTool
= toolPtr
->rect
;
650 MapWindowPoints (toolPtr
->hwnd
, NULL
, (LPPOINT
)&rcTool
, 2);
653 /* smart placement */
654 if ((rect
.left
+ size
.cx
> rcTool
.left
) && (rect
.left
< rcTool
.right
) &&
655 (rect
.top
+ size
.cy
> rcTool
.top
) && (rect
.top
< rcTool
.bottom
))
656 rect
.left
= rcTool
.right
;
662 if (toolPtr
->uFlags
& TTF_CENTERTIP
)
666 if (toolPtr
->uFlags
& TTF_IDISHWND
)
667 GetWindowRect ((HWND
)toolPtr
->uId
, &rc
);
670 MapWindowPoints (toolPtr
->hwnd
, NULL
, (LPPOINT
)&rc
, 2);
672 rect
.left
= (rc
.left
+ rc
.right
- size
.cx
) / 2;
673 if (style
& TTS_BALLOON
)
675 ptfx
= rc
.left
+ ((rc
.right
- rc
.left
) / 2);
677 /* CENTERTIP ballon tooltips default to below the field
678 * if they fit on the screen */
679 if (rc
.bottom
+ size
.cy
> GetSystemMetrics(SM_CYSCREEN
))
681 rect
.top
= rc
.top
- size
.cy
;
682 infoPtr
->bToolBelow
= FALSE
;
686 infoPtr
->bToolBelow
= TRUE
;
687 rect
.top
= rc
.bottom
;
689 rect
.left
= max(0, rect
.left
- BALLOON_STEMINDENT
);
693 rect
.top
= rc
.bottom
+ 2;
694 infoPtr
->bToolBelow
= TRUE
;
699 GetCursorPos ((LPPOINT
)&rect
);
700 if (style
& TTS_BALLOON
)
703 if(rect
.top
- size
.cy
>= 0)
706 infoPtr
->bToolBelow
= FALSE
;
710 infoPtr
->bToolBelow
= TRUE
;
713 rect
.left
= max(0, rect
.left
- BALLOON_STEMINDENT
);
718 infoPtr
->bToolBelow
= TRUE
;
723 TRACE("pos %d - %d\n", rect
.left
, rect
.top
);
725 rect
.right
= rect
.left
+ size
.cx
;
726 rect
.bottom
= rect
.top
+ size
.cy
;
730 monitor
= MonitorFromRect( &rect
, MONITOR_DEFAULTTOPRIMARY
);
731 mon_info
.cbSize
= sizeof(mon_info
);
732 GetMonitorInfoW( monitor
, &mon_info
);
734 if( rect
.right
> mon_info
.rcWork
.right
) {
735 rect
.left
-= rect
.right
- mon_info
.rcWork
.right
+ 2;
736 rect
.right
= mon_info
.rcWork
.right
- 2;
738 if (rect
.left
< mon_info
.rcWork
.left
) rect
.left
= mon_info
.rcWork
.left
;
740 if( rect
.bottom
> mon_info
.rcWork
.bottom
) {
743 if (toolPtr
->uFlags
& TTF_IDISHWND
)
744 GetWindowRect ((HWND
)toolPtr
->uId
, &rc
);
747 MapWindowPoints (toolPtr
->hwnd
, NULL
, (LPPOINT
)&rc
, 2);
749 rect
.bottom
= rc
.top
- 2;
750 rect
.top
= rect
.bottom
- size
.cy
;
753 AdjustWindowRectEx (&rect
, GetWindowLongW (infoPtr
->hwndSelf
, GWL_STYLE
),
754 FALSE
, GetWindowLongW (infoPtr
->hwndSelf
, GWL_EXSTYLE
));
756 if (style
& TTS_BALLOON
)
764 if(infoPtr
->bToolBelow
)
768 pts
[1].x
= max(BALLOON_STEMINDENT
, ptfx
- (BALLOON_STEMWIDTH
/ 2));
769 pts
[1].y
= BALLOON_STEMHEIGHT
;
770 pts
[2].x
= pts
[1].x
+ BALLOON_STEMWIDTH
;
772 if(pts
[2].x
> (rect
.right
- rect
.left
) - BALLOON_STEMINDENT
)
774 pts
[2].x
= (rect
.right
- rect
.left
) - BALLOON_STEMINDENT
;
775 pts
[1].x
= pts
[2].x
- BALLOON_STEMWIDTH
;
780 pts
[0].x
= max(BALLOON_STEMINDENT
, ptfx
- (BALLOON_STEMWIDTH
/ 2));
781 pts
[0].y
= (rect
.bottom
- rect
.top
) - BALLOON_STEMHEIGHT
;
782 pts
[1].x
= pts
[0].x
+ BALLOON_STEMWIDTH
;
785 pts
[2].y
= (rect
.bottom
- rect
.top
);
786 if(pts
[1].x
> (rect
.right
- rect
.left
) - BALLOON_STEMINDENT
)
788 pts
[1].x
= (rect
.right
- rect
.left
) - BALLOON_STEMINDENT
;
789 pts
[0].x
= pts
[1].x
- BALLOON_STEMWIDTH
;
793 hrStem
= CreatePolygonRgn(pts
, ARRAY_SIZE(pts
), ALTERNATE
);
795 hRgn
= CreateRoundRectRgn(0,
796 (infoPtr
->bToolBelow
? BALLOON_STEMHEIGHT
: 0),
797 rect
.right
- rect
.left
,
798 (infoPtr
->bToolBelow
? rect
.bottom
- rect
.top
: rect
.bottom
- rect
.top
- BALLOON_STEMHEIGHT
),
799 BALLOON_ROUNDEDNESS
, BALLOON_ROUNDEDNESS
);
801 CombineRgn(hRgn
, hRgn
, hrStem
, RGN_OR
);
802 DeleteObject(hrStem
);
804 SetWindowRgn(infoPtr
->hwndSelf
, hRgn
, FALSE
);
805 /* we don't free the region handle as the system deletes it when
806 * it is no longer needed */
809 SetWindowPos (infoPtr
->hwndSelf
, NULL
, rect
.left
, rect
.top
,
810 rect
.right
- rect
.left
, rect
.bottom
- rect
.top
, SWP_NOZORDER
| SWP_NOACTIVATE
);
812 hdr
.hwndFrom
= infoPtr
->hwndSelf
;
813 hdr
.idFrom
= toolPtr
->uId
;
815 SendMessageW (toolPtr
->hwnd
, WM_NOTIFY
, toolPtr
->uId
, (LPARAM
)&hdr
);
817 SetWindowPos (infoPtr
->hwndSelf
, HWND_TOPMOST
, 0, 0, 0, 0,
818 SWP_NOSIZE
| SWP_NOMOVE
| SWP_SHOWWINDOW
| SWP_NOACTIVATE
);
820 /* repaint the tooltip */
821 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
822 UpdateWindow(infoPtr
->hwndSelf
);
826 SetTimer (infoPtr
->hwndSelf
, ID_TIMERPOP
, infoPtr
->nAutoPopTime
, 0);
827 TRACE("timer 2 started\n");
828 SetTimer (infoPtr
->hwndSelf
, ID_TIMERLEAVE
, infoPtr
->nReshowTime
, 0);
829 TRACE("timer 3 started\n");
835 TOOLTIPS_Hide (TOOLTIPS_INFO
*infoPtr
)
837 TTTOOL_INFO
*toolPtr
;
840 TRACE("Hide tooltip %d, %p.\n", infoPtr
->nCurrentTool
, infoPtr
->hwndSelf
);
842 if (infoPtr
->nCurrentTool
== -1)
845 toolPtr
= &infoPtr
->tools
[infoPtr
->nCurrentTool
];
846 KillTimer (infoPtr
->hwndSelf
, ID_TIMERPOP
);
848 hdr
.hwndFrom
= infoPtr
->hwndSelf
;
849 hdr
.idFrom
= toolPtr
->uId
;
851 SendMessageW (toolPtr
->hwnd
, WM_NOTIFY
, toolPtr
->uId
, (LPARAM
)&hdr
);
853 infoPtr
->nCurrentTool
= -1;
855 SetWindowPos (infoPtr
->hwndSelf
, HWND_TOP
, 0, 0, 0, 0,
856 SWP_NOZORDER
| SWP_HIDEWINDOW
| SWP_NOACTIVATE
);
861 TOOLTIPS_TrackShow (TOOLTIPS_INFO
*infoPtr
)
863 TOOLTIPS_Show(infoPtr
, TRUE
);
868 TOOLTIPS_TrackHide (const TOOLTIPS_INFO
*infoPtr
)
870 TTTOOL_INFO
*toolPtr
;
873 TRACE("hide tracking tooltip %d\n", infoPtr
->nTrackTool
);
875 if (infoPtr
->nTrackTool
== -1)
878 toolPtr
= &infoPtr
->tools
[infoPtr
->nTrackTool
];
880 hdr
.hwndFrom
= infoPtr
->hwndSelf
;
881 hdr
.idFrom
= toolPtr
->uId
;
883 SendMessageW (toolPtr
->hwnd
, WM_NOTIFY
, toolPtr
->uId
, (LPARAM
)&hdr
);
885 SetWindowPos (infoPtr
->hwndSelf
, HWND_TOP
, 0, 0, 0, 0,
886 SWP_NOZORDER
| SWP_HIDEWINDOW
| SWP_NOACTIVATE
);
889 /* Structure layout is the same for TTTOOLINFOW and TTTOOLINFOA,
890 this helper is used in both cases. */
892 TOOLTIPS_GetToolFromInfoT (const TOOLTIPS_INFO
*infoPtr
, const TTTOOLINFOW
*lpToolInfo
)
894 TTTOOL_INFO
*toolPtr
;
897 for (nTool
= 0; nTool
< infoPtr
->uNumTools
; nTool
++) {
898 toolPtr
= &infoPtr
->tools
[nTool
];
900 if (!(toolPtr
->uFlags
& TTF_IDISHWND
) &&
901 (lpToolInfo
->hwnd
== toolPtr
->hwnd
) &&
902 (lpToolInfo
->uId
== toolPtr
->uId
))
906 for (nTool
= 0; nTool
< infoPtr
->uNumTools
; nTool
++) {
907 toolPtr
= &infoPtr
->tools
[nTool
];
909 if ((toolPtr
->uFlags
& TTF_IDISHWND
) &&
910 (lpToolInfo
->uId
== toolPtr
->uId
))
919 TOOLTIPS_GetToolFromPoint (const TOOLTIPS_INFO
*infoPtr
, HWND hwnd
, const POINT
*lpPt
)
921 TTTOOL_INFO
*toolPtr
;
924 for (nTool
= 0; nTool
< infoPtr
->uNumTools
; nTool
++) {
925 toolPtr
= &infoPtr
->tools
[nTool
];
927 if (!(toolPtr
->uFlags
& TTF_IDISHWND
)) {
928 if (hwnd
!= toolPtr
->hwnd
)
930 if (!PtInRect (&toolPtr
->rect
, *lpPt
))
936 for (nTool
= 0; nTool
< infoPtr
->uNumTools
; nTool
++) {
937 toolPtr
= &infoPtr
->tools
[nTool
];
939 if (toolPtr
->uFlags
& TTF_IDISHWND
) {
940 if ((HWND
)toolPtr
->uId
== hwnd
)
949 TOOLTIPS_CopyInfoT (const TOOLTIPS_INFO
*infoPtr
, INT index
, TTTOOLINFOW
*ti
, BOOL isW
)
951 const TTTOOL_INFO
*toolPtr
= &infoPtr
->tools
[index
];
953 ti
->uFlags
= toolPtr
->uFlags
;
954 ti
->hwnd
= toolPtr
->hwnd
;
955 ti
->uId
= toolPtr
->uId
;
956 ti
->rect
= toolPtr
->rect
;
957 ti
->hinst
= toolPtr
->hinst
;
960 if (toolPtr
->lpszText
== NULL
||
961 IS_INTRESOURCE(toolPtr
->lpszText
) ||
962 toolPtr
->lpszText
== LPSTR_TEXTCALLBACKW
)
963 ti
->lpszText
= toolPtr
->lpszText
;
965 lstrcpyW (ti
->lpszText
, toolPtr
->lpszText
);
967 /* ANSI version, the buffer is maximum 80 bytes without null. */
968 WideCharToMultiByte(CP_ACP
, 0, toolPtr
->lpszText
, -1,
969 (LPSTR
)ti
->lpszText
, MAX_TEXT_SIZE_A
, NULL
, NULL
);
972 if (ti
->cbSize
>= TTTOOLINFOW_V2_SIZE
)
973 ti
->lParam
= toolPtr
->lParam
;
975 /* lpReserved is intentionally not set. */
979 TOOLTIPS_IsWindowActive (HWND hwnd
)
981 HWND hwndActive
= GetActiveWindow ();
984 if (hwndActive
== hwnd
)
986 return IsChild (hwndActive
, hwnd
);
991 TOOLTIPS_CheckTool (const TOOLTIPS_INFO
*infoPtr
, BOOL bShowTest
)
998 hwndTool
= (HWND
)SendMessageW (infoPtr
->hwndSelf
, TTM_WINDOWFROMPOINT
, 0, (LPARAM
)&pt
);
1002 ScreenToClient (hwndTool
, &pt
);
1003 nTool
= TOOLTIPS_GetToolFromPoint (infoPtr
, hwndTool
, &pt
);
1007 if (!(GetWindowLongW (infoPtr
->hwndSelf
, GWL_STYLE
) & TTS_ALWAYSTIP
) && bShowTest
)
1009 TTTOOL_INFO
*ti
= &infoPtr
->tools
[nTool
];
1010 HWND hwnd
= (ti
->uFlags
& TTF_IDISHWND
) ? (HWND
)ti
->uId
: ti
->hwnd
;
1012 if (!TOOLTIPS_IsWindowActive(hwnd
))
1014 TRACE("not active: hwnd %p, parent %p, active %p\n",
1015 hwnd
, GetParent(hwnd
), GetActiveWindow());
1020 TRACE("tool %d\n", nTool
);
1027 TOOLTIPS_Activate (TOOLTIPS_INFO
*infoPtr
, BOOL activate
)
1029 infoPtr
->bActive
= activate
;
1031 TRACE("activate %d\n", activate
);
1033 if (!(infoPtr
->bActive
) && (infoPtr
->nCurrentTool
!= -1))
1034 TOOLTIPS_Hide (infoPtr
);
1041 TOOLTIPS_AddToolT (TOOLTIPS_INFO
*infoPtr
, const TTTOOLINFOW
*ti
, BOOL isW
)
1043 TTTOOL_INFO
*toolPtr
;
1046 if (!ti
) return FALSE
;
1048 TRACE("add tool (%p) %p %ld%s\n", infoPtr
->hwndSelf
, ti
->hwnd
, ti
->uId
,
1049 (ti
->uFlags
& TTF_IDISHWND
) ? " TTF_IDISHWND" : "");
1051 if (ti
->cbSize
> TTTOOLINFOW_V3_SIZE
&& isW
)
1054 if (infoPtr
->uNumTools
== 0) {
1055 infoPtr
->tools
= Alloc (sizeof(TTTOOL_INFO
));
1056 toolPtr
= infoPtr
->tools
;
1059 TTTOOL_INFO
*oldTools
= infoPtr
->tools
;
1061 Alloc (sizeof(TTTOOL_INFO
) * (infoPtr
->uNumTools
+ 1));
1062 memcpy (infoPtr
->tools
, oldTools
,
1063 infoPtr
->uNumTools
* sizeof(TTTOOL_INFO
));
1065 toolPtr
= &infoPtr
->tools
[infoPtr
->uNumTools
];
1068 infoPtr
->uNumTools
++;
1070 /* copy tool data */
1071 toolPtr
->uFlags
= ti
->uFlags
;
1072 toolPtr
->uInternalFlags
= (ti
->uFlags
& (TTF_SUBCLASS
| TTF_IDISHWND
));
1073 toolPtr
->hwnd
= ti
->hwnd
;
1074 toolPtr
->uId
= ti
->uId
;
1075 toolPtr
->rect
= ti
->rect
;
1076 toolPtr
->hinst
= ti
->hinst
;
1078 if (ti
->cbSize
>= TTTOOLINFOW_V1_SIZE
) {
1079 if (IS_INTRESOURCE(ti
->lpszText
)) {
1080 TRACE("add string id %x\n", LOWORD(ti
->lpszText
));
1081 toolPtr
->lpszText
= ti
->lpszText
;
1083 else if (ti
->lpszText
) {
1084 if (ti
->lpszText
== LPSTR_TEXTCALLBACKW
) {
1085 TRACE("add CALLBACK\n");
1086 toolPtr
->lpszText
= LPSTR_TEXTCALLBACKW
;
1089 INT len
= lstrlenW (ti
->lpszText
);
1090 TRACE("add text %s\n", debugstr_w(ti
->lpszText
));
1091 toolPtr
->lpszText
= Alloc ((len
+ 1)*sizeof(WCHAR
));
1092 lstrcpyW (toolPtr
->lpszText
, ti
->lpszText
);
1095 INT len
= MultiByteToWideChar(CP_ACP
, 0, (LPSTR
)ti
->lpszText
, -1, NULL
, 0);
1096 TRACE("add text \"%s\"\n", debugstr_a((char *)ti
->lpszText
));
1097 toolPtr
->lpszText
= Alloc (len
* sizeof(WCHAR
));
1098 MultiByteToWideChar(CP_ACP
, 0, (LPSTR
)ti
->lpszText
, -1, toolPtr
->lpszText
, len
);
1103 if (ti
->cbSize
>= TTTOOLINFOW_V2_SIZE
)
1104 toolPtr
->lParam
= ti
->lParam
;
1106 /* install subclassing hook */
1107 if (toolPtr
->uInternalFlags
& TTF_SUBCLASS
) {
1108 if (toolPtr
->uInternalFlags
& TTF_IDISHWND
) {
1109 SetWindowSubclass((HWND
)toolPtr
->uId
, TOOLTIPS_SubclassProc
, 1,
1110 (DWORD_PTR
)infoPtr
->hwndSelf
);
1113 SetWindowSubclass(toolPtr
->hwnd
, TOOLTIPS_SubclassProc
, 1,
1114 (DWORD_PTR
)infoPtr
->hwndSelf
);
1116 TRACE("subclassing installed\n");
1119 nResult
= SendMessageW (toolPtr
->hwnd
, WM_NOTIFYFORMAT
,
1120 (WPARAM
)infoPtr
->hwndSelf
, NF_QUERY
);
1121 if (nResult
== NFR_ANSI
) {
1122 toolPtr
->bNotifyUnicode
= FALSE
;
1123 TRACE(" -- WM_NOTIFYFORMAT returns: NFR_ANSI\n");
1124 } else if (nResult
== NFR_UNICODE
) {
1125 toolPtr
->bNotifyUnicode
= TRUE
;
1126 TRACE(" -- WM_NOTIFYFORMAT returns: NFR_UNICODE\n");
1128 TRACE (" -- WM_NOTIFYFORMAT returns: %d\n", nResult
);
1134 static void TOOLTIPS_ResetSubclass (const TTTOOL_INFO
*toolPtr
)
1136 /* Reset subclassing data. */
1137 if (toolPtr
->uInternalFlags
& TTF_SUBCLASS
)
1138 SetWindowSubclass(toolPtr
->uInternalFlags
& TTF_IDISHWND
? (HWND
)toolPtr
->uId
: toolPtr
->hwnd
,
1139 TOOLTIPS_SubclassProc
, 1, 0);
1142 static void TOOLTIPS_FreeToolText(TTTOOL_INFO
*toolPtr
)
1144 if (toolPtr
->lpszText
)
1146 if (!IS_INTRESOURCE(toolPtr
->lpszText
) && toolPtr
->lpszText
!= LPSTR_TEXTCALLBACKW
)
1147 Free(toolPtr
->lpszText
);
1148 toolPtr
->lpszText
= NULL
;
1152 static void TOOLTIPS_SetToolText(TTTOOL_INFO
*toolPtr
, WCHAR
*text
, BOOL is_unicode
)
1156 TOOLTIPS_FreeToolText (toolPtr
);
1158 if (IS_INTRESOURCE(text
))
1159 toolPtr
->lpszText
= text
;
1160 else if (text
== LPSTR_TEXTCALLBACKW
)
1161 toolPtr
->lpszText
= LPSTR_TEXTCALLBACKW
;
1166 len
= lstrlenW(text
);
1167 toolPtr
->lpszText
= Alloc ((len
+ 1) * sizeof(WCHAR
));
1168 if (toolPtr
->lpszText
)
1169 lstrcpyW (toolPtr
->lpszText
, text
);
1173 len
= MultiByteToWideChar(CP_ACP
, 0, (char *)text
, -1, NULL
, 0);
1174 toolPtr
->lpszText
= Alloc (len
* sizeof(WCHAR
));
1175 if (toolPtr
->lpszText
)
1176 MultiByteToWideChar(CP_ACP
, 0, (char *)text
, -1, toolPtr
->lpszText
, len
);
1182 TOOLTIPS_DelToolT (TOOLTIPS_INFO
*infoPtr
, const TTTOOLINFOW
*ti
, BOOL isW
)
1184 TTTOOL_INFO
*toolPtr
;
1188 if (isW
&& ti
->cbSize
> TTTOOLINFOW_V2_SIZE
&&
1189 ti
->cbSize
!= TTTOOLINFOW_V3_SIZE
)
1191 if (infoPtr
->uNumTools
== 0)
1194 nTool
= TOOLTIPS_GetToolFromInfoT (infoPtr
, ti
);
1196 TRACE("tool %d\n", nTool
);
1201 /* make sure the tooltip has disappeared before deleting it */
1202 TOOLTIPS_Hide(infoPtr
);
1204 toolPtr
= &infoPtr
->tools
[nTool
];
1205 TOOLTIPS_FreeToolText (toolPtr
);
1206 TOOLTIPS_ResetSubclass (toolPtr
);
1208 /* delete tool from tool list */
1209 if (infoPtr
->uNumTools
== 1) {
1210 Free (infoPtr
->tools
);
1211 infoPtr
->tools
= NULL
;
1214 TTTOOL_INFO
*oldTools
= infoPtr
->tools
;
1216 Alloc (sizeof(TTTOOL_INFO
) * (infoPtr
->uNumTools
- 1));
1219 memcpy (&infoPtr
->tools
[0], &oldTools
[0],
1220 nTool
* sizeof(TTTOOL_INFO
));
1222 if (nTool
< infoPtr
->uNumTools
- 1)
1223 memcpy (&infoPtr
->tools
[nTool
], &oldTools
[nTool
+ 1],
1224 (infoPtr
->uNumTools
- nTool
- 1) * sizeof(TTTOOL_INFO
));
1229 /* update any indices affected by delete */
1231 /* destroying tool that mouse was on on last relayed mouse move */
1232 if (infoPtr
->nTool
== nTool
)
1233 /* -1 means no current tool (0 means first tool) */
1234 infoPtr
->nTool
= -1;
1235 else if (infoPtr
->nTool
> nTool
)
1238 if (infoPtr
->nTrackTool
== nTool
)
1239 /* -1 means no current tool (0 means first tool) */
1240 infoPtr
->nTrackTool
= -1;
1241 else if (infoPtr
->nTrackTool
> nTool
)
1242 infoPtr
->nTrackTool
--;
1244 if (infoPtr
->nCurrentTool
== nTool
)
1245 /* -1 means no current tool (0 means first tool) */
1246 infoPtr
->nCurrentTool
= -1;
1247 else if (infoPtr
->nCurrentTool
> nTool
)
1248 infoPtr
->nCurrentTool
--;
1250 infoPtr
->uNumTools
--;
1256 TOOLTIPS_EnumToolsT (const TOOLTIPS_INFO
*infoPtr
, UINT uIndex
, TTTOOLINFOW
*ti
,
1259 if (!ti
|| ti
->cbSize
< TTTOOLINFOW_V1_SIZE
)
1261 if (uIndex
>= infoPtr
->uNumTools
)
1264 TRACE("index=%u\n", uIndex
);
1266 TOOLTIPS_CopyInfoT (infoPtr
, uIndex
, ti
, isW
);
1272 TOOLTIPS_GetBubbleSize (const TOOLTIPS_INFO
*infoPtr
, const TTTOOLINFOW
*lpToolInfo
)
1277 if (lpToolInfo
== NULL
)
1279 if (lpToolInfo
->cbSize
< TTTOOLINFOW_V1_SIZE
)
1282 nTool
= TOOLTIPS_GetToolFromInfoT (infoPtr
, lpToolInfo
);
1283 if (nTool
== -1) return 0;
1285 TRACE("tool %d\n", nTool
);
1287 TOOLTIPS_CalcTipSize (infoPtr
, &size
);
1288 TRACE("size %d x %d\n", size
.cx
, size
.cy
);
1290 return MAKELRESULT(size
.cx
, size
.cy
);
1294 TOOLTIPS_GetCurrentToolT (const TOOLTIPS_INFO
*infoPtr
, TTTOOLINFOW
*ti
, BOOL isW
)
1297 if (ti
->cbSize
< TTTOOLINFOW_V1_SIZE
)
1300 if (infoPtr
->nCurrentTool
!= -1)
1301 TOOLTIPS_CopyInfoT (infoPtr
, infoPtr
->nCurrentTool
, ti
, isW
);
1304 return infoPtr
->nCurrentTool
!= -1;
1309 TOOLTIPS_GetDelayTime (const TOOLTIPS_INFO
*infoPtr
, DWORD duration
)
1313 return infoPtr
->nReshowTime
;
1316 return infoPtr
->nAutoPopTime
;
1319 case TTDT_AUTOMATIC
: /* Apparently TTDT_AUTOMATIC returns TTDT_INITIAL */
1320 return infoPtr
->nInitialTime
;
1323 WARN("Invalid duration flag %x\n", duration
);
1332 TOOLTIPS_GetMargin (const TOOLTIPS_INFO
*infoPtr
, RECT
*rect
)
1335 *rect
= infoPtr
->rcMargin
;
1341 static inline LRESULT
1342 TOOLTIPS_GetMaxTipWidth (const TOOLTIPS_INFO
*infoPtr
)
1344 return infoPtr
->nMaxTipWidth
;
1349 TOOLTIPS_GetTextT (const TOOLTIPS_INFO
*infoPtr
, TTTOOLINFOW
*ti
, BOOL isW
)
1354 if (ti
->cbSize
< TTTOOLINFOW_V1_SIZE
)
1357 nTool
= TOOLTIPS_GetToolFromInfoT (infoPtr
, ti
);
1358 if (nTool
== -1) return 0;
1360 if (infoPtr
->tools
[nTool
].lpszText
== NULL
)
1364 ti
->lpszText
[0] = '\0';
1365 TOOLTIPS_GetTipText(infoPtr
, nTool
, ti
->lpszText
);
1368 WCHAR buffer
[INFOTIPSIZE
];
1370 /* NB this API is broken, there is no way for the app to determine
1371 what size buffer it requires nor a way to specify how long the
1372 one it supplies is. According to the test result, it's up to
1373 80 bytes by the ANSI version. */
1376 TOOLTIPS_GetTipText(infoPtr
, nTool
, buffer
);
1377 WideCharToMultiByte(CP_ACP
, 0, buffer
, -1, (LPSTR
)ti
->lpszText
,
1378 MAX_TEXT_SIZE_A
, NULL
, NULL
);
1385 static inline LRESULT
1386 TOOLTIPS_GetTipBkColor (const TOOLTIPS_INFO
*infoPtr
)
1388 return infoPtr
->clrBk
;
1392 static inline LRESULT
1393 TOOLTIPS_GetTipTextColor (const TOOLTIPS_INFO
*infoPtr
)
1395 return infoPtr
->clrText
;
1399 static inline LRESULT
1400 TOOLTIPS_GetToolCount (const TOOLTIPS_INFO
*infoPtr
)
1402 return infoPtr
->uNumTools
;
1407 TOOLTIPS_GetToolInfoT (const TOOLTIPS_INFO
*infoPtr
, TTTOOLINFOW
*ti
, BOOL isW
)
1412 if (!ti
) return FALSE
;
1413 if (ti
->cbSize
< TTTOOLINFOW_V1_SIZE
)
1415 if (infoPtr
->uNumTools
== 0)
1418 nTool
= TOOLTIPS_GetToolFromInfoT (infoPtr
, ti
);
1422 TRACE("tool %d\n", nTool
);
1425 TOOLTIPS_CopyInfoT (infoPtr
, nTool
, ti
, isW
);
1433 TOOLTIPS_HitTestT (const TOOLTIPS_INFO
*infoPtr
, LPTTHITTESTINFOW lptthit
,
1441 nTool
= TOOLTIPS_GetToolFromPoint (infoPtr
, lptthit
->hwnd
, &lptthit
->pt
);
1445 TRACE("tool %d\n", nTool
);
1447 /* copy tool data */
1448 if (lptthit
->ti
.cbSize
>= TTTOOLINFOW_V1_SIZE
)
1449 TOOLTIPS_CopyInfoT (infoPtr
, nTool
, &lptthit
->ti
, isW
);
1456 TOOLTIPS_NewToolRectT (TOOLTIPS_INFO
*infoPtr
, const TTTOOLINFOW
*ti
)
1461 if (ti
->cbSize
< TTTOOLINFOW_V1_SIZE
)
1464 nTool
= TOOLTIPS_GetToolFromInfoT (infoPtr
, ti
);
1466 TRACE("nTool = %d, rect = %s\n", nTool
, wine_dbgstr_rect(&ti
->rect
));
1468 if (nTool
== -1) return 0;
1470 infoPtr
->tools
[nTool
].rect
= ti
->rect
;
1476 static inline LRESULT
1477 TOOLTIPS_Pop (TOOLTIPS_INFO
*infoPtr
)
1479 TOOLTIPS_Hide (infoPtr
);
1486 TOOLTIPS_RelayEvent (TOOLTIPS_INFO
*infoPtr
, LPMSG lpMsg
)
1492 ERR("lpMsg == NULL\n");
1496 switch (lpMsg
->message
) {
1497 case WM_LBUTTONDOWN
:
1499 case WM_MBUTTONDOWN
:
1501 case WM_RBUTTONDOWN
:
1503 TOOLTIPS_Hide (infoPtr
);
1507 pt
.x
= (short)LOWORD(lpMsg
->lParam
);
1508 pt
.y
= (short)HIWORD(lpMsg
->lParam
);
1509 nOldTool
= infoPtr
->nTool
;
1510 infoPtr
->nTool
= TOOLTIPS_GetToolFromPoint(infoPtr
, lpMsg
->hwnd
,
1512 TRACE("tool (%p) %d %d %d\n", infoPtr
->hwndSelf
, nOldTool
,
1513 infoPtr
->nTool
, infoPtr
->nCurrentTool
);
1514 TRACE("WM_MOUSEMOVE (%p %s)\n", infoPtr
->hwndSelf
, wine_dbgstr_point(&pt
));
1516 if (infoPtr
->nTool
!= nOldTool
) {
1517 if(infoPtr
->nTool
== -1) { /* Moved out of all tools */
1518 TOOLTIPS_Hide(infoPtr
);
1519 KillTimer(infoPtr
->hwndSelf
, ID_TIMERLEAVE
);
1520 } else if (nOldTool
== -1) { /* Moved from outside */
1521 if(infoPtr
->bActive
) {
1522 SetTimer(infoPtr
->hwndSelf
, ID_TIMERSHOW
, infoPtr
->nInitialTime
, 0);
1523 TRACE("timer 1 started\n");
1525 } else { /* Moved from one to another */
1526 TOOLTIPS_Hide (infoPtr
);
1527 KillTimer(infoPtr
->hwndSelf
, ID_TIMERLEAVE
);
1528 if(infoPtr
->bActive
) {
1529 SetTimer (infoPtr
->hwndSelf
, ID_TIMERSHOW
, infoPtr
->nReshowTime
, 0);
1530 TRACE("timer 1 started\n");
1533 } else if(infoPtr
->nCurrentTool
!= -1) { /* restart autopop */
1534 KillTimer(infoPtr
->hwndSelf
, ID_TIMERPOP
);
1535 SetTimer(infoPtr
->hwndSelf
, ID_TIMERPOP
, infoPtr
->nAutoPopTime
, 0);
1536 TRACE("timer 2 restarted\n");
1537 } else if(infoPtr
->nTool
!= -1 && infoPtr
->bActive
) {
1538 /* previous show attempt didn't result in tooltip so try again */
1539 SetTimer(infoPtr
->hwndSelf
, ID_TIMERSHOW
, infoPtr
->nInitialTime
, 0);
1540 TRACE("timer 1 started\n");
1550 TOOLTIPS_SetDelayTime (TOOLTIPS_INFO
*infoPtr
, DWORD duration
, INT nTime
)
1553 case TTDT_AUTOMATIC
:
1555 nTime
= GetDoubleClickTime();
1556 infoPtr
->nReshowTime
= nTime
/ 5;
1557 infoPtr
->nAutoPopTime
= nTime
* 10;
1558 infoPtr
->nInitialTime
= nTime
;
1563 nTime
= GetDoubleClickTime() / 5;
1564 infoPtr
->nReshowTime
= nTime
;
1569 nTime
= GetDoubleClickTime() * 10;
1570 infoPtr
->nAutoPopTime
= nTime
;
1575 nTime
= GetDoubleClickTime();
1576 infoPtr
->nInitialTime
= nTime
;
1580 WARN("Invalid duration flag %x\n", duration
);
1589 TOOLTIPS_SetMargin (TOOLTIPS_INFO
*infoPtr
, const RECT
*rect
)
1592 infoPtr
->rcMargin
= *rect
;
1598 static inline LRESULT
1599 TOOLTIPS_SetMaxTipWidth (TOOLTIPS_INFO
*infoPtr
, INT MaxWidth
)
1601 INT nTemp
= infoPtr
->nMaxTipWidth
;
1603 infoPtr
->nMaxTipWidth
= MaxWidth
;
1609 static inline LRESULT
1610 TOOLTIPS_SetTipBkColor (TOOLTIPS_INFO
*infoPtr
, COLORREF clrBk
)
1612 infoPtr
->clrBk
= clrBk
;
1618 static inline LRESULT
1619 TOOLTIPS_SetTipTextColor (TOOLTIPS_INFO
*infoPtr
, COLORREF clrText
)
1621 infoPtr
->clrText
= clrText
;
1628 TOOLTIPS_SetTitleT (TOOLTIPS_INFO
*infoPtr
, UINT_PTR uTitleIcon
, LPCWSTR pszTitle
,
1633 TRACE("hwnd = %p, title = %s, icon = %p\n", infoPtr
->hwndSelf
, debugstr_w(pszTitle
),
1636 Free(infoPtr
->pszTitle
);
1642 size
= (lstrlenW(pszTitle
)+1)*sizeof(WCHAR
);
1643 infoPtr
->pszTitle
= Alloc(size
);
1644 if (!infoPtr
->pszTitle
)
1646 memcpy(infoPtr
->pszTitle
, pszTitle
, size
);
1650 size
= sizeof(WCHAR
)*MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)pszTitle
, -1, NULL
, 0);
1651 infoPtr
->pszTitle
= Alloc(size
);
1652 if (!infoPtr
->pszTitle
)
1654 MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)pszTitle
, -1, infoPtr
->pszTitle
, size
/sizeof(WCHAR
));
1658 infoPtr
->pszTitle
= NULL
;
1660 if (uTitleIcon
<= TTI_ERROR
)
1661 infoPtr
->hTitleIcon
= hTooltipIcons
[uTitleIcon
];
1663 infoPtr
->hTitleIcon
= CopyIcon((HICON
)uTitleIcon
);
1665 TRACE("icon = %p\n", infoPtr
->hTitleIcon
);
1671 TOOLTIPS_SetToolInfoT (TOOLTIPS_INFO
*infoPtr
, const TTTOOLINFOW
*ti
, BOOL isW
)
1673 TTTOOL_INFO
*toolPtr
;
1677 if (ti
->cbSize
< TTTOOLINFOW_V1_SIZE
)
1680 nTool
= TOOLTIPS_GetToolFromInfoT (infoPtr
, ti
);
1681 if (nTool
== -1) return 0;
1683 TRACE("tool %d\n", nTool
);
1685 toolPtr
= &infoPtr
->tools
[nTool
];
1687 /* copy tool data */
1688 toolPtr
->uFlags
= ti
->uFlags
;
1689 toolPtr
->hwnd
= ti
->hwnd
;
1690 toolPtr
->uId
= ti
->uId
;
1691 toolPtr
->rect
= ti
->rect
;
1692 toolPtr
->hinst
= ti
->hinst
;
1694 TOOLTIPS_SetToolText (toolPtr
, ti
->lpszText
, isW
);
1696 if (ti
->cbSize
>= TTTOOLINFOW_V2_SIZE
)
1697 toolPtr
->lParam
= ti
->lParam
;
1699 if (infoPtr
->nCurrentTool
== nTool
)
1701 TOOLTIPS_GetTipText (infoPtr
, infoPtr
->nCurrentTool
, infoPtr
->szTipText
);
1703 if (infoPtr
->szTipText
[0] == 0)
1704 TOOLTIPS_Hide(infoPtr
);
1706 TOOLTIPS_Show (infoPtr
, FALSE
);
1714 TOOLTIPS_TrackActivate (TOOLTIPS_INFO
*infoPtr
, BOOL track_activate
, const TTTOOLINFOA
*ti
)
1716 if (track_activate
) {
1719 if (ti
->cbSize
< TTTOOLINFOA_V1_SIZE
)
1723 infoPtr
->nTrackTool
= TOOLTIPS_GetToolFromInfoT (infoPtr
, (const TTTOOLINFOW
*)ti
);
1724 if (infoPtr
->nTrackTool
!= -1) {
1725 TRACE("activated\n");
1726 infoPtr
->bTrackActive
= TRUE
;
1727 TOOLTIPS_TrackShow (infoPtr
);
1732 TOOLTIPS_TrackHide (infoPtr
);
1734 infoPtr
->bTrackActive
= FALSE
;
1735 infoPtr
->nTrackTool
= -1;
1737 TRACE("deactivated\n");
1745 TOOLTIPS_TrackPosition (TOOLTIPS_INFO
*infoPtr
, LPARAM coord
)
1747 infoPtr
->xTrackPos
= (INT
)LOWORD(coord
);
1748 infoPtr
->yTrackPos
= (INT
)HIWORD(coord
);
1750 if (infoPtr
->bTrackActive
) {
1752 infoPtr
->xTrackPos
, infoPtr
->yTrackPos
);
1754 TOOLTIPS_TrackShow (infoPtr
);
1762 TOOLTIPS_Update (TOOLTIPS_INFO
*infoPtr
)
1764 if (infoPtr
->nCurrentTool
!= -1)
1765 UpdateWindow (infoPtr
->hwndSelf
);
1772 TOOLTIPS_UpdateTipTextT (TOOLTIPS_INFO
*infoPtr
, const TTTOOLINFOW
*ti
, BOOL isW
)
1774 TTTOOL_INFO
*toolPtr
;
1778 if (ti
->cbSize
< TTTOOLINFOW_V1_SIZE
)
1781 nTool
= TOOLTIPS_GetToolFromInfoT (infoPtr
, ti
);
1785 TRACE("tool %d\n", nTool
);
1787 toolPtr
= &infoPtr
->tools
[nTool
];
1789 toolPtr
->hinst
= ti
->hinst
;
1791 TOOLTIPS_SetToolText(toolPtr
, ti
->lpszText
, isW
);
1793 if(infoPtr
->nCurrentTool
== -1) return 0;
1795 if (infoPtr
->bActive
)
1796 TOOLTIPS_Show (infoPtr
, FALSE
);
1797 else if (infoPtr
->bTrackActive
)
1798 TOOLTIPS_Show (infoPtr
, TRUE
);
1805 TOOLTIPS_Create (HWND hwnd
)
1807 TOOLTIPS_INFO
*infoPtr
;
1809 /* allocate memory for info structure */
1810 infoPtr
= Alloc (sizeof(TOOLTIPS_INFO
));
1811 SetWindowLongPtrW (hwnd
, 0, (DWORD_PTR
)infoPtr
);
1813 /* initialize info structure */
1814 infoPtr
->bActive
= TRUE
;
1815 infoPtr
->bTrackActive
= FALSE
;
1817 infoPtr
->nMaxTipWidth
= -1;
1818 infoPtr
->nTool
= -1;
1819 infoPtr
->nCurrentTool
= -1;
1820 infoPtr
->nTrackTool
= -1;
1821 infoPtr
->hwndSelf
= hwnd
;
1823 /* initialize colours and fonts */
1824 TOOLTIPS_InitSystemSettings(infoPtr
);
1826 TOOLTIPS_SetDelayTime(infoPtr
, TTDT_AUTOMATIC
, 0);
1828 SetWindowPos (hwnd
, HWND_TOP
, 0, 0, 0, 0, SWP_NOZORDER
| SWP_HIDEWINDOW
| SWP_NOACTIVATE
);
1835 TOOLTIPS_Destroy (TOOLTIPS_INFO
*infoPtr
)
1837 TTTOOL_INFO
*toolPtr
;
1840 for (i
= 0; i
< infoPtr
->uNumTools
; i
++)
1842 toolPtr
= &infoPtr
->tools
[i
];
1844 TOOLTIPS_FreeToolText (toolPtr
);
1845 TOOLTIPS_ResetSubclass (toolPtr
);
1848 Free (infoPtr
->tools
);
1850 /* free title string */
1851 Free (infoPtr
->pszTitle
);
1852 /* free title icon if not a standard one */
1853 if (TOOLTIPS_GetTitleIconIndex(infoPtr
->hTitleIcon
) > TTI_ERROR
)
1854 DeleteObject(infoPtr
->hTitleIcon
);
1857 DeleteObject (infoPtr
->hFont
);
1858 DeleteObject (infoPtr
->hTitleFont
);
1860 /* free tool tips info data */
1861 SetWindowLongPtrW(infoPtr
->hwndSelf
, 0, 0);
1868 static inline LRESULT
1869 TOOLTIPS_GetFont (const TOOLTIPS_INFO
*infoPtr
)
1871 return (LRESULT
)infoPtr
->hFont
;
1876 TOOLTIPS_MouseMessage (TOOLTIPS_INFO
*infoPtr
)
1878 TOOLTIPS_Hide (infoPtr
);
1885 TOOLTIPS_NCCreate (HWND hwnd
)
1887 DWORD dwStyle
= GetWindowLongW (hwnd
, GWL_STYLE
);
1888 DWORD dwExStyle
= GetWindowLongW (hwnd
, GWL_EXSTYLE
);
1890 dwStyle
&= ~(WS_CHILD
| /*WS_MAXIMIZE |*/ WS_BORDER
| WS_DLGFRAME
);
1891 dwStyle
|= (WS_POPUP
| WS_BORDER
| WS_CLIPSIBLINGS
);
1893 /* WS_BORDER only draws a border round the window rect, not the
1894 * window region, therefore it is useless to us in balloon mode */
1895 if (dwStyle
& TTS_BALLOON
) dwStyle
&= ~WS_BORDER
;
1897 SetWindowLongW (hwnd
, GWL_STYLE
, dwStyle
);
1899 dwExStyle
|= WS_EX_TOOLWINDOW
;
1900 SetWindowLongW (hwnd
, GWL_EXSTYLE
, dwExStyle
);
1907 TOOLTIPS_NCHitTest (const TOOLTIPS_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
1909 INT nTool
= (infoPtr
->bTrackActive
) ? infoPtr
->nTrackTool
: infoPtr
->nTool
;
1911 TRACE(" nTool=%d\n", nTool
);
1913 if ((nTool
> -1) && (nTool
< infoPtr
->uNumTools
)) {
1914 if (infoPtr
->tools
[nTool
].uFlags
& TTF_TRANSPARENT
) {
1915 TRACE("-- in transparent mode\n");
1916 return HTTRANSPARENT
;
1920 return DefWindowProcW (infoPtr
->hwndSelf
, WM_NCHITTEST
, wParam
, lParam
);
1925 TOOLTIPS_NotifyFormat (TOOLTIPS_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
1927 FIXME ("hwnd=%p wParam=%lx lParam=%lx\n", infoPtr
->hwndSelf
, wParam
, lParam
);
1934 TOOLTIPS_Paint (const TOOLTIPS_INFO
*infoPtr
, HDC hDC
)
1939 hdc
= (hDC
== NULL
) ? BeginPaint (infoPtr
->hwndSelf
, &ps
) : hDC
;
1940 TOOLTIPS_Refresh (infoPtr
, hdc
);
1942 EndPaint (infoPtr
->hwndSelf
, &ps
);
1948 TOOLTIPS_SetFont (TOOLTIPS_INFO
*infoPtr
, HFONT hFont
, BOOL redraw
)
1952 if(!GetObjectW(hFont
, sizeof(lf
), &lf
))
1955 DeleteObject (infoPtr
->hFont
);
1956 infoPtr
->hFont
= CreateFontIndirectW(&lf
);
1958 DeleteObject (infoPtr
->hTitleFont
);
1959 lf
.lfWeight
= FW_BOLD
;
1960 infoPtr
->hTitleFont
= CreateFontIndirectW(&lf
);
1962 if (redraw
&& infoPtr
->nCurrentTool
!= -1)
1963 FIXME("full redraw needed\n");
1968 /******************************************************************
1969 * TOOLTIPS_GetTextLength
1971 * This function is called when the tooltip receive a
1972 * WM_GETTEXTLENGTH message.
1974 * returns the length, in characters, of the tip text
1976 static inline LRESULT
1977 TOOLTIPS_GetTextLength(const TOOLTIPS_INFO
*infoPtr
)
1979 return lstrlenW(infoPtr
->szTipText
);
1982 /******************************************************************
1983 * TOOLTIPS_OnWMGetText
1985 * This function is called when the tooltip receive a
1986 * WM_GETTEXT message.
1987 * wParam : specifies the maximum number of characters to be copied
1988 * lParam : is the pointer to the buffer that will receive
1991 * returns the number of characters copied
1994 TOOLTIPS_OnWMGetText (const TOOLTIPS_INFO
*infoPtr
, WPARAM size
, LPWSTR pszText
)
2001 res
= min(lstrlenW(infoPtr
->szTipText
)+1, size
);
2002 memcpy(pszText
, infoPtr
->szTipText
, res
*sizeof(WCHAR
));
2003 pszText
[res
-1] = '\0';
2008 TOOLTIPS_Timer (TOOLTIPS_INFO
*infoPtr
, INT iTimer
)
2012 TRACE("timer %d (%p) expired\n", iTimer
, infoPtr
->hwndSelf
);
2016 KillTimer (infoPtr
->hwndSelf
, ID_TIMERSHOW
);
2017 nOldTool
= infoPtr
->nTool
;
2018 if ((infoPtr
->nTool
= TOOLTIPS_CheckTool (infoPtr
, TRUE
)) == nOldTool
)
2019 TOOLTIPS_Show (infoPtr
, FALSE
);
2023 TOOLTIPS_Hide (infoPtr
);
2027 nOldTool
= infoPtr
->nTool
;
2028 infoPtr
->nTool
= TOOLTIPS_CheckTool (infoPtr
, FALSE
);
2029 TRACE("tool (%p) %d %d %d\n", infoPtr
->hwndSelf
, nOldTool
,
2030 infoPtr
->nTool
, infoPtr
->nCurrentTool
);
2031 if (infoPtr
->nTool
!= nOldTool
) {
2032 if(infoPtr
->nTool
== -1) { /* Moved out of all tools */
2033 TOOLTIPS_Hide(infoPtr
);
2034 KillTimer(infoPtr
->hwndSelf
, ID_TIMERLEAVE
);
2035 } else if (nOldTool
== -1) { /* Moved from outside */
2036 ERR("How did this happen?\n");
2037 } else { /* Moved from one to another */
2038 TOOLTIPS_Hide (infoPtr
);
2039 KillTimer(infoPtr
->hwndSelf
, ID_TIMERLEAVE
);
2040 if(infoPtr
->bActive
) {
2041 SetTimer (infoPtr
->hwndSelf
, ID_TIMERSHOW
, infoPtr
->nReshowTime
, 0);
2042 TRACE("timer 1 started!\n");
2049 ERR("Unknown timer id %d\n", iTimer
);
2057 TOOLTIPS_WinIniChange (TOOLTIPS_INFO
*infoPtr
)
2059 TOOLTIPS_InitSystemSettings (infoPtr
);
2065 static LRESULT CALLBACK
2066 TOOLTIPS_SubclassProc (HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
, UINT_PTR uID
, DWORD_PTR dwRef
)
2068 TOOLTIPS_INFO
*infoPtr
= TOOLTIPS_GetInfoPtr ((HWND
)dwRef
);
2074 case WM_LBUTTONDOWN
:
2076 case WM_MBUTTONDOWN
:
2078 case WM_RBUTTONDOWN
:
2083 msg
.message
= message
;
2084 msg
.wParam
= wParam
;
2085 msg
.lParam
= lParam
;
2086 TOOLTIPS_RelayEvent(infoPtr
, &msg
);
2090 RemoveWindowSubclass(hwnd
, TOOLTIPS_SubclassProc
, 1);
2096 return DefSubclassProc(hwnd
, message
, wParam
, lParam
);
2100 static LRESULT CALLBACK
2101 TOOLTIPS_WindowProc (HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
2103 TOOLTIPS_INFO
*infoPtr
= TOOLTIPS_GetInfoPtr (hwnd
);
2105 TRACE("hwnd=%p msg=%x wparam=%lx lParam=%lx\n", hwnd
, uMsg
, wParam
, lParam
);
2106 if (!infoPtr
&& (uMsg
!= WM_CREATE
) && (uMsg
!= WM_NCCREATE
))
2107 return DefWindowProcW (hwnd
, uMsg
, wParam
, lParam
);
2111 return TOOLTIPS_Activate (infoPtr
, (BOOL
)wParam
);
2115 return TOOLTIPS_AddToolT (infoPtr
, (LPTTTOOLINFOW
)lParam
, uMsg
== TTM_ADDTOOLW
);
2119 return TOOLTIPS_DelToolT (infoPtr
, (LPTOOLINFOW
)lParam
,
2120 uMsg
== TTM_DELTOOLW
);
2121 case TTM_ENUMTOOLSA
:
2122 case TTM_ENUMTOOLSW
:
2123 return TOOLTIPS_EnumToolsT (infoPtr
, (UINT
)wParam
, (LPTTTOOLINFOW
)lParam
,
2124 uMsg
== TTM_ENUMTOOLSW
);
2125 case TTM_GETBUBBLESIZE
:
2126 return TOOLTIPS_GetBubbleSize (infoPtr
, (LPTTTOOLINFOW
)lParam
);
2128 case TTM_GETCURRENTTOOLA
:
2129 case TTM_GETCURRENTTOOLW
:
2130 return TOOLTIPS_GetCurrentToolT (infoPtr
, (LPTTTOOLINFOW
)lParam
,
2131 uMsg
== TTM_GETCURRENTTOOLW
);
2133 case TTM_GETDELAYTIME
:
2134 return TOOLTIPS_GetDelayTime (infoPtr
, (DWORD
)wParam
);
2137 return TOOLTIPS_GetMargin (infoPtr
, (LPRECT
)lParam
);
2139 case TTM_GETMAXTIPWIDTH
:
2140 return TOOLTIPS_GetMaxTipWidth (infoPtr
);
2144 return TOOLTIPS_GetTextT (infoPtr
, (LPTTTOOLINFOW
)lParam
,
2145 uMsg
== TTM_GETTEXTW
);
2147 case TTM_GETTIPBKCOLOR
:
2148 return TOOLTIPS_GetTipBkColor (infoPtr
);
2150 case TTM_GETTIPTEXTCOLOR
:
2151 return TOOLTIPS_GetTipTextColor (infoPtr
);
2153 case TTM_GETTOOLCOUNT
:
2154 return TOOLTIPS_GetToolCount (infoPtr
);
2156 case TTM_GETTOOLINFOA
:
2157 case TTM_GETTOOLINFOW
:
2158 return TOOLTIPS_GetToolInfoT (infoPtr
, (LPTTTOOLINFOW
)lParam
,
2159 uMsg
== TTM_GETTOOLINFOW
);
2163 return TOOLTIPS_HitTestT (infoPtr
, (LPTTHITTESTINFOW
)lParam
,
2164 uMsg
== TTM_HITTESTW
);
2165 case TTM_NEWTOOLRECTA
:
2166 case TTM_NEWTOOLRECTW
:
2167 return TOOLTIPS_NewToolRectT (infoPtr
, (LPTTTOOLINFOW
)lParam
);
2170 return TOOLTIPS_Pop (infoPtr
);
2172 case TTM_RELAYEVENT
:
2173 return TOOLTIPS_RelayEvent (infoPtr
, (LPMSG
)lParam
);
2175 case TTM_SETDELAYTIME
:
2176 return TOOLTIPS_SetDelayTime (infoPtr
, (DWORD
)wParam
, (INT
)LOWORD(lParam
));
2179 return TOOLTIPS_SetMargin (infoPtr
, (LPRECT
)lParam
);
2181 case TTM_SETMAXTIPWIDTH
:
2182 return TOOLTIPS_SetMaxTipWidth (infoPtr
, (INT
)lParam
);
2184 case TTM_SETTIPBKCOLOR
:
2185 return TOOLTIPS_SetTipBkColor (infoPtr
, (COLORREF
)wParam
);
2187 case TTM_SETTIPTEXTCOLOR
:
2188 return TOOLTIPS_SetTipTextColor (infoPtr
, (COLORREF
)wParam
);
2192 return TOOLTIPS_SetTitleT (infoPtr
, (UINT_PTR
)wParam
, (LPCWSTR
)lParam
,
2193 uMsg
== TTM_SETTITLEW
);
2195 case TTM_SETTOOLINFOA
:
2196 case TTM_SETTOOLINFOW
:
2197 return TOOLTIPS_SetToolInfoT (infoPtr
, (LPTTTOOLINFOW
)lParam
,
2198 uMsg
== TTM_SETTOOLINFOW
);
2200 case TTM_TRACKACTIVATE
:
2201 return TOOLTIPS_TrackActivate (infoPtr
, (BOOL
)wParam
, (LPTTTOOLINFOA
)lParam
);
2203 case TTM_TRACKPOSITION
:
2204 return TOOLTIPS_TrackPosition (infoPtr
, lParam
);
2207 return TOOLTIPS_Update (infoPtr
);
2209 case TTM_UPDATETIPTEXTA
:
2210 case TTM_UPDATETIPTEXTW
:
2211 return TOOLTIPS_UpdateTipTextT (infoPtr
, (LPTTTOOLINFOW
)lParam
,
2212 uMsg
== TTM_UPDATETIPTEXTW
);
2214 case TTM_WINDOWFROMPOINT
:
2215 return (LRESULT
)WindowFromPoint (*((LPPOINT
)lParam
));
2218 return TOOLTIPS_Create (hwnd
);
2221 return TOOLTIPS_Destroy (infoPtr
);
2224 /* we draw the background in WM_PAINT */
2228 return TOOLTIPS_GetFont (infoPtr
);
2231 return TOOLTIPS_OnWMGetText (infoPtr
, wParam
, (LPWSTR
)lParam
);
2233 case WM_GETTEXTLENGTH
:
2234 return TOOLTIPS_GetTextLength (infoPtr
);
2236 case WM_LBUTTONDOWN
:
2238 case WM_MBUTTONDOWN
:
2240 case WM_RBUTTONDOWN
:
2243 return TOOLTIPS_MouseMessage (infoPtr
);
2246 return TOOLTIPS_NCCreate (hwnd
);
2249 return TOOLTIPS_NCHitTest (infoPtr
, wParam
, lParam
);
2251 case WM_NOTIFYFORMAT
:
2252 return TOOLTIPS_NotifyFormat (infoPtr
, wParam
, lParam
);
2254 case WM_PRINTCLIENT
:
2256 return TOOLTIPS_Paint (infoPtr
, (HDC
)wParam
);
2259 return TOOLTIPS_SetFont (infoPtr
, (HFONT
)wParam
, LOWORD(lParam
));
2261 case WM_SYSCOLORCHANGE
:
2262 COMCTL32_RefreshSysColors();
2266 return TOOLTIPS_Timer (infoPtr
, (INT
)wParam
);
2268 case WM_WININICHANGE
:
2269 return TOOLTIPS_WinIniChange (infoPtr
);
2272 if ((uMsg
>= WM_USER
) && (uMsg
< WM_APP
) && !COMCTL32_IsReflectedMessage(uMsg
))
2273 ERR("unknown msg %04x wp=%08lx lp=%08lx\n",
2274 uMsg
, wParam
, lParam
);
2275 return DefWindowProcW (hwnd
, uMsg
, wParam
, lParam
);
2281 TOOLTIPS_Register (void)
2285 ZeroMemory (&wndClass
, sizeof(WNDCLASSW
));
2286 wndClass
.style
= CS_GLOBALCLASS
| CS_DBLCLKS
| CS_SAVEBITS
;
2287 wndClass
.lpfnWndProc
= TOOLTIPS_WindowProc
;
2288 wndClass
.cbClsExtra
= 0;
2289 wndClass
.cbWndExtra
= sizeof(TOOLTIPS_INFO
*);
2290 wndClass
.hCursor
= LoadCursorW (0, (LPWSTR
)IDC_ARROW
);
2291 wndClass
.hbrBackground
= 0;
2292 wndClass
.lpszClassName
= TOOLTIPS_CLASSW
;
2294 RegisterClassW (&wndClass
);
2296 hTooltipIcons
[TTI_NONE
] = NULL
;
2297 hTooltipIcons
[TTI_INFO
] = LoadImageW(COMCTL32_hModule
,
2298 (LPCWSTR
)MAKEINTRESOURCE(IDI_TT_INFO_SM
), IMAGE_ICON
, 0, 0, 0);
2299 hTooltipIcons
[TTI_WARNING
] = LoadImageW(COMCTL32_hModule
,
2300 (LPCWSTR
)MAKEINTRESOURCE(IDI_TT_WARN_SM
), IMAGE_ICON
, 0, 0, 0);
2301 hTooltipIcons
[TTI_ERROR
] = LoadImageW(COMCTL32_hModule
,
2302 (LPCWSTR
)MAKEINTRESOURCE(IDI_TT_ERROR_SM
), IMAGE_ICON
, 0, 0, 0);
2307 TOOLTIPS_Unregister (void)
2310 for (i
= TTI_INFO
; i
<= TTI_ERROR
; i
++)
2311 DestroyIcon(hTooltipIcons
[i
]);
2312 UnregisterClassW (TOOLTIPS_CLASSW
, NULL
);