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
99 #include "wine/unicode.h"
103 #include "commctrl.h"
104 #include "comctl32.h"
105 #include "wine/debug.h"
107 WINE_DEFAULT_DEBUG_CHANNEL(tooltips
);
109 static HICON hTooltipIcons
[TTI_ERROR
+1];
128 WCHAR szTipText
[INFOTIPSIZE
];
139 INT nTool
; /* tool that mouse was on on last relayed mouse move */
153 #define ID_TIMERSHOW 1 /* show delay timer */
154 #define ID_TIMERPOP 2 /* auto pop timer */
155 #define ID_TIMERLEAVE 3 /* tool leave timer */
158 #define TOOLTIPS_GetInfoPtr(hWindow) ((TOOLTIPS_INFO *)GetWindowLongPtrW (hWindow, 0))
160 /* offsets from window edge to start of text */
161 #define NORMAL_TEXT_MARGIN 2
162 #define BALLOON_TEXT_MARGIN (NORMAL_TEXT_MARGIN+8)
163 /* value used for CreateRoundRectRgn that specifies how much
164 * each corner is curved */
165 #define BALLOON_ROUNDEDNESS 20
166 #define BALLOON_STEMHEIGHT 13
167 #define BALLOON_STEMWIDTH 10
168 #define BALLOON_STEMINDENT 20
170 #define BALLOON_ICON_TITLE_SPACING 8 /* horizontal spacing between icon and title */
171 #define BALLOON_TITLE_TEXT_SPACING 8 /* vertical spacing between icon/title and main text */
172 #define ICON_HEIGHT 16
173 #define ICON_WIDTH 16
175 #define MAX_TEXT_SIZE_A 80 /* maximum retrieving text size by ANSI message */
177 static LRESULT CALLBACK
178 TOOLTIPS_SubclassProc (HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
, UINT_PTR uId
, DWORD_PTR dwRef
);
180 static inline UINT_PTR
181 TOOLTIPS_GetTitleIconIndex(HICON hIcon
)
184 for (i
= 0; i
<= TTI_ERROR
; i
++)
185 if (hTooltipIcons
[i
] == hIcon
)
187 return (UINT_PTR
)hIcon
;
191 TOOLTIPS_InitSystemSettings (TOOLTIPS_INFO
*infoPtr
)
193 NONCLIENTMETRICSW nclm
;
195 infoPtr
->clrBk
= comctl32_color
.clrInfoBk
;
196 infoPtr
->clrText
= comctl32_color
.clrInfoText
;
198 DeleteObject (infoPtr
->hFont
);
199 nclm
.cbSize
= sizeof(nclm
);
200 SystemParametersInfoW (SPI_GETNONCLIENTMETRICS
, sizeof(nclm
), &nclm
, 0);
201 infoPtr
->hFont
= CreateFontIndirectW (&nclm
.lfStatusFont
);
203 DeleteObject (infoPtr
->hTitleFont
);
204 nclm
.lfStatusFont
.lfWeight
= FW_BOLD
;
205 infoPtr
->hTitleFont
= CreateFontIndirectW (&nclm
.lfStatusFont
);
208 /* Custom draw routines */
210 TOOLTIPS_customdraw_fill(const TOOLTIPS_INFO
*infoPtr
, NMTTCUSTOMDRAW
*lpnmttcd
,
211 HDC hdc
, const RECT
*rcBounds
, UINT uFlags
)
213 ZeroMemory(lpnmttcd
, sizeof(NMTTCUSTOMDRAW
));
214 lpnmttcd
->uDrawFlags
= uFlags
;
215 lpnmttcd
->nmcd
.hdr
.hwndFrom
= infoPtr
->hwndSelf
;
216 lpnmttcd
->nmcd
.hdr
.code
= NM_CUSTOMDRAW
;
217 if (infoPtr
->nCurrentTool
!= -1) {
218 TTTOOL_INFO
*toolPtr
= &infoPtr
->tools
[infoPtr
->nCurrentTool
];
219 lpnmttcd
->nmcd
.hdr
.idFrom
= toolPtr
->uId
;
221 lpnmttcd
->nmcd
.hdc
= hdc
;
222 lpnmttcd
->nmcd
.rc
= *rcBounds
;
223 /* FIXME - dwItemSpec, uItemState, lItemlParam */
227 TOOLTIPS_notify_customdraw (DWORD dwDrawStage
, NMTTCUSTOMDRAW
*lpnmttcd
)
230 lpnmttcd
->nmcd
.dwDrawStage
= dwDrawStage
;
232 TRACE("Notifying stage %d, flags %x, id %x\n", lpnmttcd
->nmcd
.dwDrawStage
,
233 lpnmttcd
->uDrawFlags
, lpnmttcd
->nmcd
.hdr
.code
);
235 result
= SendMessageW(GetParent(lpnmttcd
->nmcd
.hdr
.hwndFrom
), WM_NOTIFY
,
236 0, (LPARAM
)lpnmttcd
);
238 TRACE("Notify result %x\n", (unsigned int)result
);
244 TOOLTIPS_Refresh (const TOOLTIPS_INFO
*infoPtr
, HDC hdc
)
250 UINT uFlags
= DT_EXTERNALLEADING
;
252 DWORD dwStyle
= GetWindowLongW(infoPtr
->hwndSelf
, GWL_STYLE
);
253 NMTTCUSTOMDRAW nmttcd
;
256 if (infoPtr
->nMaxTipWidth
> -1)
257 uFlags
|= DT_WORDBREAK
;
258 if (GetWindowLongW (infoPtr
->hwndSelf
, GWL_STYLE
) & TTS_NOPREFIX
)
259 uFlags
|= DT_NOPREFIX
;
260 GetClientRect (infoPtr
->hwndSelf
, &rc
);
262 hBrush
= CreateSolidBrush(infoPtr
->clrBk
);
264 oldBkMode
= SetBkMode (hdc
, TRANSPARENT
);
265 SetTextColor (hdc
, infoPtr
->clrText
);
266 hOldFont
= SelectObject (hdc
, infoPtr
->hFont
);
268 /* Custom draw - Call PrePaint once initial properties set up */
269 /* Note: Contrary to MSDN, CDRF_SKIPDEFAULT still draws a tooltip */
270 TOOLTIPS_customdraw_fill(infoPtr
, &nmttcd
, hdc
, &rc
, uFlags
);
271 cdmode
= TOOLTIPS_notify_customdraw(CDDS_PREPAINT
, &nmttcd
);
272 uFlags
= nmttcd
.uDrawFlags
;
274 if (dwStyle
& TTS_BALLOON
)
276 /* create a region to store result into */
277 hRgn
= CreateRectRgn(0, 0, 0, 0);
279 GetWindowRgn(infoPtr
->hwndSelf
, hRgn
);
281 /* fill the background */
282 FillRgn(hdc
, hRgn
, hBrush
);
283 DeleteObject(hBrush
);
288 /* fill the background */
289 FillRect(hdc
, &rc
, hBrush
);
290 DeleteObject(hBrush
);
294 if ((dwStyle
& TTS_BALLOON
) || infoPtr
->pszTitle
)
296 /* calculate text rectangle */
297 rc
.left
+= (BALLOON_TEXT_MARGIN
+ infoPtr
->rcMargin
.left
);
298 rc
.top
+= (BALLOON_TEXT_MARGIN
+ infoPtr
->rcMargin
.top
);
299 rc
.right
-= (BALLOON_TEXT_MARGIN
+ infoPtr
->rcMargin
.right
);
300 rc
.bottom
-= (BALLOON_TEXT_MARGIN
+ infoPtr
->rcMargin
.bottom
);
301 if(infoPtr
->bToolBelow
) rc
.top
+= BALLOON_STEMHEIGHT
;
303 if (infoPtr
->pszTitle
)
305 RECT rcTitle
= {rc
.left
, rc
.top
, rc
.right
, rc
.bottom
};
311 icon_present
= infoPtr
->hTitleIcon
&&
312 DrawIconEx(hdc
, rc
.left
, rc
.top
, infoPtr
->hTitleIcon
,
313 ICON_WIDTH
, ICON_HEIGHT
, 0, NULL
, DI_NORMAL
);
315 rcTitle
.left
+= ICON_WIDTH
+ BALLOON_ICON_TITLE_SPACING
;
317 rcTitle
.bottom
= rc
.top
+ ICON_HEIGHT
;
319 /* draw title text */
320 prevFont
= SelectObject (hdc
, infoPtr
->hTitleFont
);
321 height
= DrawTextW(hdc
, infoPtr
->pszTitle
, -1, &rcTitle
, DT_BOTTOM
| DT_SINGLELINE
| DT_NOPREFIX
);
322 SelectObject (hdc
, prevFont
);
323 rc
.top
+= height
+ BALLOON_TITLE_TEXT_SPACING
;
328 /* calculate text rectangle */
329 rc
.left
+= (NORMAL_TEXT_MARGIN
+ infoPtr
->rcMargin
.left
);
330 rc
.top
+= (NORMAL_TEXT_MARGIN
+ infoPtr
->rcMargin
.top
);
331 rc
.right
-= (NORMAL_TEXT_MARGIN
+ infoPtr
->rcMargin
.right
);
332 rc
.bottom
-= (NORMAL_TEXT_MARGIN
+ infoPtr
->rcMargin
.bottom
);
336 DrawTextW (hdc
, infoPtr
->szTipText
, -1, &rc
, uFlags
);
338 /* Custom draw - Call PostPaint after drawing */
339 if (cdmode
& CDRF_NOTIFYPOSTPAINT
) {
340 TOOLTIPS_notify_customdraw(CDDS_POSTPAINT
, &nmttcd
);
343 /* be polite and reset the things we changed in the dc */
344 SelectObject (hdc
, hOldFont
);
345 SetBkMode (hdc
, oldBkMode
);
347 if (dwStyle
& TTS_BALLOON
)
349 /* frame region because default window proc doesn't do it */
350 INT width
= GetSystemMetrics(SM_CXDLGFRAME
) - GetSystemMetrics(SM_CXEDGE
);
351 INT height
= GetSystemMetrics(SM_CYDLGFRAME
) - GetSystemMetrics(SM_CYEDGE
);
353 hBrush
= GetSysColorBrush(COLOR_WINDOWFRAME
);
354 FrameRgn(hdc
, hRgn
, hBrush
, width
, height
);
361 static void TOOLTIPS_GetDispInfoA(const TOOLTIPS_INFO
*infoPtr
, TTTOOL_INFO
*toolPtr
, WCHAR
*buffer
)
363 NMTTDISPINFOA ttnmdi
;
365 /* fill NMHDR struct */
366 ZeroMemory (&ttnmdi
, sizeof(NMTTDISPINFOA
));
367 ttnmdi
.hdr
.hwndFrom
= infoPtr
->hwndSelf
;
368 ttnmdi
.hdr
.idFrom
= toolPtr
->uId
;
369 ttnmdi
.hdr
.code
= TTN_GETDISPINFOA
; /* == TTN_NEEDTEXTA */
370 ttnmdi
.lpszText
= ttnmdi
.szText
;
371 ttnmdi
.uFlags
= toolPtr
->uFlags
;
372 ttnmdi
.lParam
= toolPtr
->lParam
;
374 TRACE("hdr.idFrom = %lx\n", ttnmdi
.hdr
.idFrom
);
375 SendMessageW(toolPtr
->hwnd
, WM_NOTIFY
, toolPtr
->uId
, (LPARAM
)&ttnmdi
);
377 if (IS_INTRESOURCE(ttnmdi
.lpszText
)) {
378 LoadStringW(ttnmdi
.hinst
, LOWORD(ttnmdi
.lpszText
),
379 buffer
, INFOTIPSIZE
);
380 if (ttnmdi
.uFlags
& TTF_DI_SETITEM
) {
381 toolPtr
->hinst
= ttnmdi
.hinst
;
382 toolPtr
->lpszText
= (LPWSTR
)ttnmdi
.lpszText
;
385 else if (ttnmdi
.lpszText
== 0) {
388 else if (ttnmdi
.lpszText
!= LPSTR_TEXTCALLBACKA
) {
389 Str_GetPtrAtoW(ttnmdi
.lpszText
, buffer
, INFOTIPSIZE
);
390 if (ttnmdi
.uFlags
& TTF_DI_SETITEM
) {
392 toolPtr
->lpszText
= NULL
;
393 Str_SetPtrW(&toolPtr
->lpszText
, buffer
);
397 ERR("recursive text callback\n");
401 /* no text available - try calling parent instead as per native */
402 /* FIXME: Unsure if SETITEM should save the value or not */
403 if (buffer
[0] == 0x00) {
405 SendMessageW(GetParent(toolPtr
->hwnd
), WM_NOTIFY
, toolPtr
->uId
, (LPARAM
)&ttnmdi
);
407 if (IS_INTRESOURCE(ttnmdi
.lpszText
)) {
408 LoadStringW(ttnmdi
.hinst
, LOWORD(ttnmdi
.lpszText
),
409 buffer
, INFOTIPSIZE
);
410 } else if (ttnmdi
.lpszText
&&
411 ttnmdi
.lpszText
!= LPSTR_TEXTCALLBACKA
) {
412 Str_GetPtrAtoW(ttnmdi
.lpszText
, buffer
, INFOTIPSIZE
);
417 static void TOOLTIPS_GetDispInfoW(const TOOLTIPS_INFO
*infoPtr
, TTTOOL_INFO
*toolPtr
, WCHAR
*buffer
)
419 NMTTDISPINFOW ttnmdi
;
421 /* fill NMHDR struct */
422 ZeroMemory (&ttnmdi
, sizeof(NMTTDISPINFOW
));
423 ttnmdi
.hdr
.hwndFrom
= infoPtr
->hwndSelf
;
424 ttnmdi
.hdr
.idFrom
= toolPtr
->uId
;
425 ttnmdi
.hdr
.code
= TTN_GETDISPINFOW
; /* == TTN_NEEDTEXTW */
426 ttnmdi
.lpszText
= ttnmdi
.szText
;
427 ttnmdi
.uFlags
= toolPtr
->uFlags
;
428 ttnmdi
.lParam
= toolPtr
->lParam
;
430 TRACE("hdr.idFrom = %lx\n", ttnmdi
.hdr
.idFrom
);
431 SendMessageW(toolPtr
->hwnd
, WM_NOTIFY
, toolPtr
->uId
, (LPARAM
)&ttnmdi
);
433 if (IS_INTRESOURCE(ttnmdi
.lpszText
)) {
434 LoadStringW(ttnmdi
.hinst
, LOWORD(ttnmdi
.lpszText
),
435 buffer
, INFOTIPSIZE
);
436 if (ttnmdi
.uFlags
& TTF_DI_SETITEM
) {
437 toolPtr
->hinst
= ttnmdi
.hinst
;
438 toolPtr
->lpszText
= ttnmdi
.lpszText
;
441 else if (ttnmdi
.lpszText
== 0) {
444 else if (ttnmdi
.lpszText
!= LPSTR_TEXTCALLBACKW
) {
445 Str_GetPtrW(ttnmdi
.lpszText
, buffer
, INFOTIPSIZE
);
446 if (ttnmdi
.uFlags
& TTF_DI_SETITEM
) {
448 toolPtr
->lpszText
= NULL
;
449 Str_SetPtrW(&toolPtr
->lpszText
, buffer
);
453 ERR("recursive text callback\n");
457 /* no text available - try calling parent instead as per native */
458 /* FIXME: Unsure if SETITEM should save the value or not */
459 if (buffer
[0] == 0x00) {
461 SendMessageW(GetParent(toolPtr
->hwnd
), WM_NOTIFY
, toolPtr
->uId
, (LPARAM
)&ttnmdi
);
463 if (IS_INTRESOURCE(ttnmdi
.lpszText
)) {
464 LoadStringW(ttnmdi
.hinst
, LOWORD(ttnmdi
.lpszText
),
465 buffer
, INFOTIPSIZE
);
466 } else if (ttnmdi
.lpszText
&&
467 ttnmdi
.lpszText
!= LPSTR_TEXTCALLBACKW
) {
468 Str_GetPtrW(ttnmdi
.lpszText
, buffer
, INFOTIPSIZE
);
475 TOOLTIPS_GetTipText (const TOOLTIPS_INFO
*infoPtr
, INT nTool
, WCHAR
*buffer
)
477 TTTOOL_INFO
*toolPtr
= &infoPtr
->tools
[nTool
];
479 if (IS_INTRESOURCE(toolPtr
->lpszText
)) {
480 /* load a resource */
481 TRACE("load res string %p %x\n",
482 toolPtr
->hinst
, LOWORD(toolPtr
->lpszText
));
483 if (!LoadStringW (toolPtr
->hinst
, LOWORD(toolPtr
->lpszText
), buffer
, INFOTIPSIZE
))
486 else if (toolPtr
->lpszText
) {
487 if (toolPtr
->lpszText
== LPSTR_TEXTCALLBACKW
) {
488 if (toolPtr
->bNotifyUnicode
)
489 TOOLTIPS_GetDispInfoW(infoPtr
, toolPtr
, buffer
);
491 TOOLTIPS_GetDispInfoA(infoPtr
, toolPtr
, buffer
);
494 /* the item is a usual (unicode) text */
495 lstrcpynW (buffer
, toolPtr
->lpszText
, INFOTIPSIZE
);
499 /* no text available */
503 if (!(GetWindowLongW(infoPtr
->hwndSelf
, GWL_STYLE
) & TTS_NOPREFIX
)) {
505 if ((ptrW
= strchrW(buffer
, '\t')))
509 TRACE("%s\n", debugstr_w(buffer
));
514 TOOLTIPS_CalcTipSize (const TOOLTIPS_INFO
*infoPtr
, LPSIZE lpSize
)
518 DWORD style
= GetWindowLongW(infoPtr
->hwndSelf
, GWL_STYLE
);
519 UINT uFlags
= DT_EXTERNALLEADING
| DT_CALCRECT
;
520 RECT rc
= {0, 0, 0, 0};
523 if (infoPtr
->nMaxTipWidth
> -1) {
524 rc
.right
= infoPtr
->nMaxTipWidth
;
525 uFlags
|= DT_WORDBREAK
;
527 if (style
& TTS_NOPREFIX
)
528 uFlags
|= DT_NOPREFIX
;
529 TRACE("%s\n", debugstr_w(infoPtr
->szTipText
));
531 hdc
= GetDC (infoPtr
->hwndSelf
);
532 if (infoPtr
->pszTitle
)
534 RECT rcTitle
= {0, 0, 0, 0};
535 TRACE("title %s\n", debugstr_w(infoPtr
->pszTitle
));
536 if (infoPtr
->hTitleIcon
)
538 title
.cx
= ICON_WIDTH
;
539 title
.cy
= ICON_HEIGHT
;
541 if (title
.cx
!= 0) title
.cx
+= BALLOON_ICON_TITLE_SPACING
;
542 hOldFont
= SelectObject (hdc
, infoPtr
->hTitleFont
);
543 DrawTextW(hdc
, infoPtr
->pszTitle
, -1, &rcTitle
, DT_SINGLELINE
| DT_NOPREFIX
| DT_CALCRECT
);
544 SelectObject (hdc
, hOldFont
);
545 title
.cy
= max(title
.cy
, rcTitle
.bottom
- rcTitle
.top
) + BALLOON_TITLE_TEXT_SPACING
;
546 title
.cx
+= (rcTitle
.right
- rcTitle
.left
);
548 hOldFont
= SelectObject (hdc
, infoPtr
->hFont
);
549 DrawTextW (hdc
, infoPtr
->szTipText
, -1, &rc
, uFlags
);
550 SelectObject (hdc
, hOldFont
);
551 ReleaseDC (infoPtr
->hwndSelf
, hdc
);
553 if ((style
& TTS_BALLOON
) || infoPtr
->pszTitle
)
555 lpSize
->cx
= max(rc
.right
- rc
.left
, title
.cx
) + 2*BALLOON_TEXT_MARGIN
+
556 infoPtr
->rcMargin
.left
+ infoPtr
->rcMargin
.right
;
557 lpSize
->cy
= title
.cy
+ rc
.bottom
- rc
.top
+ 2*BALLOON_TEXT_MARGIN
+
558 infoPtr
->rcMargin
.bottom
+ infoPtr
->rcMargin
.top
+
563 lpSize
->cx
= rc
.right
- rc
.left
+ 2*NORMAL_TEXT_MARGIN
+
564 infoPtr
->rcMargin
.left
+ infoPtr
->rcMargin
.right
;
565 lpSize
->cy
= rc
.bottom
- rc
.top
+ 2*NORMAL_TEXT_MARGIN
+
566 infoPtr
->rcMargin
.bottom
+ infoPtr
->rcMargin
.top
;
572 TOOLTIPS_Show (TOOLTIPS_INFO
*infoPtr
, BOOL track_activate
)
574 TTTOOL_INFO
*toolPtr
;
576 MONITORINFO mon_info
;
581 DWORD style
= GetWindowLongW(infoPtr
->hwndSelf
, GWL_STYLE
);
586 if (infoPtr
->nTrackTool
== -1)
588 TRACE("invalid tracking tool %d\n", infoPtr
->nTrackTool
);
591 nTool
= infoPtr
->nTrackTool
;
595 if (infoPtr
->nTool
== -1)
597 TRACE("invalid tool %d\n", infoPtr
->nTool
);
600 nTool
= infoPtr
->nTool
;
603 TRACE("Show tooltip pre %d, %p\n", nTool
, infoPtr
->hwndSelf
);
605 current
= infoPtr
->nCurrentTool
;
607 infoPtr
->nCurrentTool
= infoPtr
->nTool
;
609 TOOLTIPS_GetTipText (infoPtr
, nTool
, infoPtr
->szTipText
);
611 if (infoPtr
->szTipText
[0] == '\0')
613 infoPtr
->nCurrentTool
= current
;
617 toolPtr
= &infoPtr
->tools
[nTool
];
618 TOOLTIPS_CalcTipSize (infoPtr
, &size
);
620 TRACE("Show tooltip %d, %s, size %d x %d\n", nTool
, debugstr_w(infoPtr
->szTipText
),
623 if (track_activate
&& (toolPtr
->uFlags
& TTF_TRACK
))
625 rect
.left
= infoPtr
->xTrackPos
;
626 rect
.top
= infoPtr
->yTrackPos
;
629 if (toolPtr
->uFlags
& TTF_CENTERTIP
)
631 rect
.left
-= (size
.cx
/ 2);
632 if (!(style
& TTS_BALLOON
))
633 rect
.top
-= (size
.cy
/ 2);
635 if (!(infoPtr
->bToolBelow
= (infoPtr
->yTrackPos
+ size
.cy
<= GetSystemMetrics(SM_CYSCREEN
))))
638 if (!(toolPtr
->uFlags
& TTF_ABSOLUTE
))
640 if (style
& TTS_BALLOON
)
641 rect
.left
-= BALLOON_STEMINDENT
;
646 if (toolPtr
->uFlags
& TTF_IDISHWND
)
647 GetWindowRect ((HWND
)toolPtr
->uId
, &rcTool
);
650 rcTool
= toolPtr
->rect
;
651 MapWindowPoints (toolPtr
->hwnd
, NULL
, (LPPOINT
)&rcTool
, 2);
654 /* smart placement */
655 if ((rect
.left
+ size
.cx
> rcTool
.left
) && (rect
.left
< rcTool
.right
) &&
656 (rect
.top
+ size
.cy
> rcTool
.top
) && (rect
.top
< rcTool
.bottom
))
657 rect
.left
= rcTool
.right
;
663 if (toolPtr
->uFlags
& TTF_CENTERTIP
)
667 if (toolPtr
->uFlags
& TTF_IDISHWND
)
668 GetWindowRect ((HWND
)toolPtr
->uId
, &rc
);
671 MapWindowPoints (toolPtr
->hwnd
, NULL
, (LPPOINT
)&rc
, 2);
673 rect
.left
= (rc
.left
+ rc
.right
- size
.cx
) / 2;
674 if (style
& TTS_BALLOON
)
676 ptfx
= rc
.left
+ ((rc
.right
- rc
.left
) / 2);
678 /* CENTERTIP ballon tooltips default to below the field
679 * if they fit on the screen */
680 if (rc
.bottom
+ size
.cy
> GetSystemMetrics(SM_CYSCREEN
))
682 rect
.top
= rc
.top
- size
.cy
;
683 infoPtr
->bToolBelow
= FALSE
;
687 infoPtr
->bToolBelow
= TRUE
;
688 rect
.top
= rc
.bottom
;
690 rect
.left
= max(0, rect
.left
- BALLOON_STEMINDENT
);
694 rect
.top
= rc
.bottom
+ 2;
695 infoPtr
->bToolBelow
= TRUE
;
700 GetCursorPos ((LPPOINT
)&rect
);
701 if (style
& TTS_BALLOON
)
704 if(rect
.top
- size
.cy
>= 0)
707 infoPtr
->bToolBelow
= FALSE
;
711 infoPtr
->bToolBelow
= TRUE
;
714 rect
.left
= max(0, rect
.left
- BALLOON_STEMINDENT
);
719 infoPtr
->bToolBelow
= TRUE
;
724 TRACE("pos %d - %d\n", rect
.left
, rect
.top
);
726 rect
.right
= rect
.left
+ size
.cx
;
727 rect
.bottom
= rect
.top
+ size
.cy
;
731 monitor
= MonitorFromRect( &rect
, MONITOR_DEFAULTTOPRIMARY
);
732 mon_info
.cbSize
= sizeof(mon_info
);
733 GetMonitorInfoW( monitor
, &mon_info
);
735 if( rect
.right
> mon_info
.rcWork
.right
) {
736 rect
.left
-= rect
.right
- mon_info
.rcWork
.right
+ 2;
737 rect
.right
= mon_info
.rcWork
.right
- 2;
739 if (rect
.left
< mon_info
.rcWork
.left
) rect
.left
= mon_info
.rcWork
.left
;
741 if( rect
.bottom
> mon_info
.rcWork
.bottom
) {
744 if (toolPtr
->uFlags
& TTF_IDISHWND
)
745 GetWindowRect ((HWND
)toolPtr
->uId
, &rc
);
748 MapWindowPoints (toolPtr
->hwnd
, NULL
, (LPPOINT
)&rc
, 2);
750 rect
.bottom
= rc
.top
- 2;
751 rect
.top
= rect
.bottom
- size
.cy
;
754 AdjustWindowRectEx (&rect
, GetWindowLongW (infoPtr
->hwndSelf
, GWL_STYLE
),
755 FALSE
, GetWindowLongW (infoPtr
->hwndSelf
, GWL_EXSTYLE
));
757 if (style
& TTS_BALLOON
)
765 if(infoPtr
->bToolBelow
)
769 pts
[1].x
= max(BALLOON_STEMINDENT
, ptfx
- (BALLOON_STEMWIDTH
/ 2));
770 pts
[1].y
= BALLOON_STEMHEIGHT
;
771 pts
[2].x
= pts
[1].x
+ BALLOON_STEMWIDTH
;
773 if(pts
[2].x
> (rect
.right
- rect
.left
) - BALLOON_STEMINDENT
)
775 pts
[2].x
= (rect
.right
- rect
.left
) - BALLOON_STEMINDENT
;
776 pts
[1].x
= pts
[2].x
- BALLOON_STEMWIDTH
;
781 pts
[0].x
= max(BALLOON_STEMINDENT
, ptfx
- (BALLOON_STEMWIDTH
/ 2));
782 pts
[0].y
= (rect
.bottom
- rect
.top
) - BALLOON_STEMHEIGHT
;
783 pts
[1].x
= pts
[0].x
+ BALLOON_STEMWIDTH
;
786 pts
[2].y
= (rect
.bottom
- rect
.top
);
787 if(pts
[1].x
> (rect
.right
- rect
.left
) - BALLOON_STEMINDENT
)
789 pts
[1].x
= (rect
.right
- rect
.left
) - BALLOON_STEMINDENT
;
790 pts
[0].x
= pts
[1].x
- BALLOON_STEMWIDTH
;
794 hrStem
= CreatePolygonRgn(pts
, ARRAY_SIZE(pts
), ALTERNATE
);
796 hRgn
= CreateRoundRectRgn(0,
797 (infoPtr
->bToolBelow
? BALLOON_STEMHEIGHT
: 0),
798 rect
.right
- rect
.left
,
799 (infoPtr
->bToolBelow
? rect
.bottom
- rect
.top
: rect
.bottom
- rect
.top
- BALLOON_STEMHEIGHT
),
800 BALLOON_ROUNDEDNESS
, BALLOON_ROUNDEDNESS
);
802 CombineRgn(hRgn
, hRgn
, hrStem
, RGN_OR
);
803 DeleteObject(hrStem
);
805 SetWindowRgn(infoPtr
->hwndSelf
, hRgn
, FALSE
);
806 /* we don't free the region handle as the system deletes it when
807 * it is no longer needed */
810 SetWindowPos (infoPtr
->hwndSelf
, NULL
, rect
.left
, rect
.top
,
811 rect
.right
- rect
.left
, rect
.bottom
- rect
.top
, SWP_NOZORDER
| SWP_NOACTIVATE
);
813 hdr
.hwndFrom
= infoPtr
->hwndSelf
;
814 hdr
.idFrom
= toolPtr
->uId
;
816 SendMessageW (toolPtr
->hwnd
, WM_NOTIFY
, toolPtr
->uId
, (LPARAM
)&hdr
);
818 SetWindowPos (infoPtr
->hwndSelf
, HWND_TOPMOST
, 0, 0, 0, 0,
819 SWP_NOSIZE
| SWP_NOMOVE
| SWP_SHOWWINDOW
| SWP_NOACTIVATE
);
821 /* repaint the tooltip */
822 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
823 UpdateWindow(infoPtr
->hwndSelf
);
827 SetTimer (infoPtr
->hwndSelf
, ID_TIMERPOP
, infoPtr
->nAutoPopTime
, 0);
828 TRACE("timer 2 started\n");
829 SetTimer (infoPtr
->hwndSelf
, ID_TIMERLEAVE
, infoPtr
->nReshowTime
, 0);
830 TRACE("timer 3 started\n");
836 TOOLTIPS_Hide (TOOLTIPS_INFO
*infoPtr
)
838 TTTOOL_INFO
*toolPtr
;
841 TRACE("Hide tooltip %d, %p.\n", infoPtr
->nCurrentTool
, infoPtr
->hwndSelf
);
843 if (infoPtr
->nCurrentTool
== -1)
846 toolPtr
= &infoPtr
->tools
[infoPtr
->nCurrentTool
];
847 KillTimer (infoPtr
->hwndSelf
, ID_TIMERPOP
);
849 hdr
.hwndFrom
= infoPtr
->hwndSelf
;
850 hdr
.idFrom
= toolPtr
->uId
;
852 SendMessageW (toolPtr
->hwnd
, WM_NOTIFY
, toolPtr
->uId
, (LPARAM
)&hdr
);
854 infoPtr
->nCurrentTool
= -1;
856 SetWindowPos (infoPtr
->hwndSelf
, HWND_TOP
, 0, 0, 0, 0,
857 SWP_NOZORDER
| SWP_HIDEWINDOW
| SWP_NOACTIVATE
);
862 TOOLTIPS_TrackShow (TOOLTIPS_INFO
*infoPtr
)
864 TOOLTIPS_Show(infoPtr
, TRUE
);
869 TOOLTIPS_TrackHide (const TOOLTIPS_INFO
*infoPtr
)
871 TTTOOL_INFO
*toolPtr
;
874 TRACE("hide tracking tooltip %d\n", infoPtr
->nTrackTool
);
876 if (infoPtr
->nTrackTool
== -1)
879 toolPtr
= &infoPtr
->tools
[infoPtr
->nTrackTool
];
881 hdr
.hwndFrom
= infoPtr
->hwndSelf
;
882 hdr
.idFrom
= toolPtr
->uId
;
884 SendMessageW (toolPtr
->hwnd
, WM_NOTIFY
, toolPtr
->uId
, (LPARAM
)&hdr
);
886 SetWindowPos (infoPtr
->hwndSelf
, HWND_TOP
, 0, 0, 0, 0,
887 SWP_NOZORDER
| SWP_HIDEWINDOW
| SWP_NOACTIVATE
);
890 /* Structure layout is the same for TTTOOLINFOW and TTTOOLINFOA,
891 this helper is used in both cases. */
893 TOOLTIPS_GetToolFromInfoT (const TOOLTIPS_INFO
*infoPtr
, const TTTOOLINFOW
*lpToolInfo
)
895 TTTOOL_INFO
*toolPtr
;
898 for (nTool
= 0; nTool
< infoPtr
->uNumTools
; nTool
++) {
899 toolPtr
= &infoPtr
->tools
[nTool
];
901 if (!(toolPtr
->uFlags
& TTF_IDISHWND
) &&
902 (lpToolInfo
->hwnd
== toolPtr
->hwnd
) &&
903 (lpToolInfo
->uId
== toolPtr
->uId
))
907 for (nTool
= 0; nTool
< infoPtr
->uNumTools
; nTool
++) {
908 toolPtr
= &infoPtr
->tools
[nTool
];
910 if ((toolPtr
->uFlags
& TTF_IDISHWND
) &&
911 (lpToolInfo
->uId
== toolPtr
->uId
))
920 TOOLTIPS_GetToolFromPoint (const TOOLTIPS_INFO
*infoPtr
, HWND hwnd
, const POINT
*lpPt
)
922 TTTOOL_INFO
*toolPtr
;
925 for (nTool
= 0; nTool
< infoPtr
->uNumTools
; nTool
++) {
926 toolPtr
= &infoPtr
->tools
[nTool
];
928 if (!(toolPtr
->uFlags
& TTF_IDISHWND
)) {
929 if (hwnd
!= toolPtr
->hwnd
)
931 if (!PtInRect (&toolPtr
->rect
, *lpPt
))
937 for (nTool
= 0; nTool
< infoPtr
->uNumTools
; nTool
++) {
938 toolPtr
= &infoPtr
->tools
[nTool
];
940 if (toolPtr
->uFlags
& TTF_IDISHWND
) {
941 if ((HWND
)toolPtr
->uId
== hwnd
)
950 TOOLTIPS_CopyInfoT (const TOOLTIPS_INFO
*infoPtr
, INT index
, TTTOOLINFOW
*ti
, BOOL isW
)
952 const TTTOOL_INFO
*toolPtr
= &infoPtr
->tools
[index
];
954 ti
->uFlags
= toolPtr
->uFlags
;
955 ti
->hwnd
= toolPtr
->hwnd
;
956 ti
->uId
= toolPtr
->uId
;
957 ti
->rect
= toolPtr
->rect
;
958 ti
->hinst
= toolPtr
->hinst
;
961 if (toolPtr
->lpszText
== NULL
||
962 IS_INTRESOURCE(toolPtr
->lpszText
) ||
963 toolPtr
->lpszText
== LPSTR_TEXTCALLBACKW
)
964 ti
->lpszText
= toolPtr
->lpszText
;
966 strcpyW (ti
->lpszText
, toolPtr
->lpszText
);
968 /* ANSI version, the buffer is maximum 80 bytes without null. */
969 WideCharToMultiByte(CP_ACP
, 0, toolPtr
->lpszText
, -1,
970 (LPSTR
)ti
->lpszText
, MAX_TEXT_SIZE_A
, NULL
, NULL
);
973 if (ti
->cbSize
>= TTTOOLINFOW_V2_SIZE
)
974 ti
->lParam
= toolPtr
->lParam
;
976 /* lpReserved is intentionally not set. */
980 TOOLTIPS_IsWindowActive (HWND hwnd
)
982 HWND hwndActive
= GetActiveWindow ();
985 if (hwndActive
== hwnd
)
987 return IsChild (hwndActive
, hwnd
);
992 TOOLTIPS_CheckTool (const TOOLTIPS_INFO
*infoPtr
, BOOL bShowTest
)
999 hwndTool
= (HWND
)SendMessageW (infoPtr
->hwndSelf
, TTM_WINDOWFROMPOINT
, 0, (LPARAM
)&pt
);
1003 ScreenToClient (hwndTool
, &pt
);
1004 nTool
= TOOLTIPS_GetToolFromPoint (infoPtr
, hwndTool
, &pt
);
1008 if (!(GetWindowLongW (infoPtr
->hwndSelf
, GWL_STYLE
) & TTS_ALWAYSTIP
) && bShowTest
)
1010 TTTOOL_INFO
*ti
= &infoPtr
->tools
[nTool
];
1011 HWND hwnd
= (ti
->uFlags
& TTF_IDISHWND
) ? (HWND
)ti
->uId
: ti
->hwnd
;
1013 if (!TOOLTIPS_IsWindowActive(hwnd
))
1015 TRACE("not active: hwnd %p, parent %p, active %p\n",
1016 hwnd
, GetParent(hwnd
), GetActiveWindow());
1021 TRACE("tool %d\n", nTool
);
1028 TOOLTIPS_Activate (TOOLTIPS_INFO
*infoPtr
, BOOL activate
)
1030 infoPtr
->bActive
= activate
;
1032 TRACE("activate %d\n", activate
);
1034 if (!(infoPtr
->bActive
) && (infoPtr
->nCurrentTool
!= -1))
1035 TOOLTIPS_Hide (infoPtr
);
1042 TOOLTIPS_AddToolT (TOOLTIPS_INFO
*infoPtr
, const TTTOOLINFOW
*ti
, BOOL isW
)
1044 TTTOOL_INFO
*toolPtr
;
1047 if (!ti
) return FALSE
;
1049 TRACE("add tool (%p) %p %ld%s\n", infoPtr
->hwndSelf
, ti
->hwnd
, ti
->uId
,
1050 (ti
->uFlags
& TTF_IDISHWND
) ? " TTF_IDISHWND" : "");
1052 if (ti
->cbSize
> TTTOOLINFOW_V3_SIZE
&& isW
)
1055 if (infoPtr
->uNumTools
== 0) {
1056 infoPtr
->tools
= Alloc (sizeof(TTTOOL_INFO
));
1057 toolPtr
= infoPtr
->tools
;
1060 TTTOOL_INFO
*oldTools
= infoPtr
->tools
;
1062 Alloc (sizeof(TTTOOL_INFO
) * (infoPtr
->uNumTools
+ 1));
1063 memcpy (infoPtr
->tools
, oldTools
,
1064 infoPtr
->uNumTools
* sizeof(TTTOOL_INFO
));
1066 toolPtr
= &infoPtr
->tools
[infoPtr
->uNumTools
];
1069 infoPtr
->uNumTools
++;
1071 /* copy tool data */
1072 toolPtr
->uFlags
= ti
->uFlags
;
1073 toolPtr
->uInternalFlags
= (ti
->uFlags
& (TTF_SUBCLASS
| TTF_IDISHWND
));
1074 toolPtr
->hwnd
= ti
->hwnd
;
1075 toolPtr
->uId
= ti
->uId
;
1076 toolPtr
->rect
= ti
->rect
;
1077 toolPtr
->hinst
= ti
->hinst
;
1079 if (ti
->cbSize
>= TTTOOLINFOW_V1_SIZE
) {
1080 if (IS_INTRESOURCE(ti
->lpszText
)) {
1081 TRACE("add string id %x\n", LOWORD(ti
->lpszText
));
1082 toolPtr
->lpszText
= ti
->lpszText
;
1084 else if (ti
->lpszText
) {
1085 if (ti
->lpszText
== LPSTR_TEXTCALLBACKW
) {
1086 TRACE("add CALLBACK\n");
1087 toolPtr
->lpszText
= LPSTR_TEXTCALLBACKW
;
1090 INT len
= lstrlenW (ti
->lpszText
);
1091 TRACE("add text %s\n", debugstr_w(ti
->lpszText
));
1092 toolPtr
->lpszText
= Alloc ((len
+ 1)*sizeof(WCHAR
));
1093 strcpyW (toolPtr
->lpszText
, ti
->lpszText
);
1096 INT len
= MultiByteToWideChar(CP_ACP
, 0, (LPSTR
)ti
->lpszText
, -1, NULL
, 0);
1097 TRACE("add text \"%s\"\n", debugstr_a((char *)ti
->lpszText
));
1098 toolPtr
->lpszText
= Alloc (len
* sizeof(WCHAR
));
1099 MultiByteToWideChar(CP_ACP
, 0, (LPSTR
)ti
->lpszText
, -1, toolPtr
->lpszText
, len
);
1104 if (ti
->cbSize
>= TTTOOLINFOW_V2_SIZE
)
1105 toolPtr
->lParam
= ti
->lParam
;
1107 /* install subclassing hook */
1108 if (toolPtr
->uInternalFlags
& TTF_SUBCLASS
) {
1109 if (toolPtr
->uInternalFlags
& TTF_IDISHWND
) {
1110 SetWindowSubclass((HWND
)toolPtr
->uId
, TOOLTIPS_SubclassProc
, 1,
1111 (DWORD_PTR
)infoPtr
->hwndSelf
);
1114 SetWindowSubclass(toolPtr
->hwnd
, TOOLTIPS_SubclassProc
, 1,
1115 (DWORD_PTR
)infoPtr
->hwndSelf
);
1117 TRACE("subclassing installed\n");
1120 nResult
= SendMessageW (toolPtr
->hwnd
, WM_NOTIFYFORMAT
,
1121 (WPARAM
)infoPtr
->hwndSelf
, NF_QUERY
);
1122 if (nResult
== NFR_ANSI
) {
1123 toolPtr
->bNotifyUnicode
= FALSE
;
1124 TRACE(" -- WM_NOTIFYFORMAT returns: NFR_ANSI\n");
1125 } else if (nResult
== NFR_UNICODE
) {
1126 toolPtr
->bNotifyUnicode
= TRUE
;
1127 TRACE(" -- WM_NOTIFYFORMAT returns: NFR_UNICODE\n");
1129 TRACE (" -- WM_NOTIFYFORMAT returns: %d\n", nResult
);
1135 static void TOOLTIPS_ResetSubclass (const TTTOOL_INFO
*toolPtr
)
1137 /* Reset subclassing data. */
1138 if (toolPtr
->uInternalFlags
& TTF_SUBCLASS
)
1139 SetWindowSubclass(toolPtr
->uInternalFlags
& TTF_IDISHWND
? (HWND
)toolPtr
->uId
: toolPtr
->hwnd
,
1140 TOOLTIPS_SubclassProc
, 1, 0);
1144 TOOLTIPS_DelToolT (TOOLTIPS_INFO
*infoPtr
, const TTTOOLINFOW
*ti
, BOOL isW
)
1146 TTTOOL_INFO
*toolPtr
;
1150 if (isW
&& ti
->cbSize
> TTTOOLINFOW_V2_SIZE
&&
1151 ti
->cbSize
!= TTTOOLINFOW_V3_SIZE
)
1153 if (infoPtr
->uNumTools
== 0)
1156 nTool
= TOOLTIPS_GetToolFromInfoT (infoPtr
, ti
);
1158 TRACE("tool %d\n", nTool
);
1163 /* make sure the tooltip has disappeared before deleting it */
1164 TOOLTIPS_Hide(infoPtr
);
1166 /* delete text string */
1167 toolPtr
= &infoPtr
->tools
[nTool
];
1168 if (toolPtr
->lpszText
) {
1169 if ( (toolPtr
->lpszText
!= LPSTR_TEXTCALLBACKW
) &&
1170 !IS_INTRESOURCE(toolPtr
->lpszText
) )
1171 Free (toolPtr
->lpszText
);
1174 TOOLTIPS_ResetSubclass (toolPtr
);
1176 /* delete tool from tool list */
1177 if (infoPtr
->uNumTools
== 1) {
1178 Free (infoPtr
->tools
);
1179 infoPtr
->tools
= NULL
;
1182 TTTOOL_INFO
*oldTools
= infoPtr
->tools
;
1184 Alloc (sizeof(TTTOOL_INFO
) * (infoPtr
->uNumTools
- 1));
1187 memcpy (&infoPtr
->tools
[0], &oldTools
[0],
1188 nTool
* sizeof(TTTOOL_INFO
));
1190 if (nTool
< infoPtr
->uNumTools
- 1)
1191 memcpy (&infoPtr
->tools
[nTool
], &oldTools
[nTool
+ 1],
1192 (infoPtr
->uNumTools
- nTool
- 1) * sizeof(TTTOOL_INFO
));
1197 /* update any indices affected by delete */
1199 /* destroying tool that mouse was on on last relayed mouse move */
1200 if (infoPtr
->nTool
== nTool
)
1201 /* -1 means no current tool (0 means first tool) */
1202 infoPtr
->nTool
= -1;
1203 else if (infoPtr
->nTool
> nTool
)
1206 if (infoPtr
->nTrackTool
== nTool
)
1207 /* -1 means no current tool (0 means first tool) */
1208 infoPtr
->nTrackTool
= -1;
1209 else if (infoPtr
->nTrackTool
> nTool
)
1210 infoPtr
->nTrackTool
--;
1212 if (infoPtr
->nCurrentTool
== nTool
)
1213 /* -1 means no current tool (0 means first tool) */
1214 infoPtr
->nCurrentTool
= -1;
1215 else if (infoPtr
->nCurrentTool
> nTool
)
1216 infoPtr
->nCurrentTool
--;
1218 infoPtr
->uNumTools
--;
1224 TOOLTIPS_EnumToolsT (const TOOLTIPS_INFO
*infoPtr
, UINT uIndex
, TTTOOLINFOW
*ti
,
1227 if (!ti
|| ti
->cbSize
< TTTOOLINFOW_V1_SIZE
)
1229 if (uIndex
>= infoPtr
->uNumTools
)
1232 TRACE("index=%u\n", uIndex
);
1234 TOOLTIPS_CopyInfoT (infoPtr
, uIndex
, ti
, isW
);
1240 TOOLTIPS_GetBubbleSize (const TOOLTIPS_INFO
*infoPtr
, const TTTOOLINFOW
*lpToolInfo
)
1245 if (lpToolInfo
== NULL
)
1247 if (lpToolInfo
->cbSize
< TTTOOLINFOW_V1_SIZE
)
1250 nTool
= TOOLTIPS_GetToolFromInfoT (infoPtr
, lpToolInfo
);
1251 if (nTool
== -1) return 0;
1253 TRACE("tool %d\n", nTool
);
1255 TOOLTIPS_CalcTipSize (infoPtr
, &size
);
1256 TRACE("size %d x %d\n", size
.cx
, size
.cy
);
1258 return MAKELRESULT(size
.cx
, size
.cy
);
1262 TOOLTIPS_GetCurrentToolT (const TOOLTIPS_INFO
*infoPtr
, TTTOOLINFOW
*ti
, BOOL isW
)
1265 if (ti
->cbSize
< TTTOOLINFOW_V1_SIZE
)
1268 if (infoPtr
->nCurrentTool
!= -1)
1269 TOOLTIPS_CopyInfoT (infoPtr
, infoPtr
->nCurrentTool
, ti
, isW
);
1272 return infoPtr
->nCurrentTool
!= -1;
1277 TOOLTIPS_GetDelayTime (const TOOLTIPS_INFO
*infoPtr
, DWORD duration
)
1281 return infoPtr
->nReshowTime
;
1284 return infoPtr
->nAutoPopTime
;
1287 case TTDT_AUTOMATIC
: /* Apparently TTDT_AUTOMATIC returns TTDT_INITIAL */
1288 return infoPtr
->nInitialTime
;
1291 WARN("Invalid duration flag %x\n", duration
);
1300 TOOLTIPS_GetMargin (const TOOLTIPS_INFO
*infoPtr
, RECT
*rect
)
1303 *rect
= infoPtr
->rcMargin
;
1309 static inline LRESULT
1310 TOOLTIPS_GetMaxTipWidth (const TOOLTIPS_INFO
*infoPtr
)
1312 return infoPtr
->nMaxTipWidth
;
1317 TOOLTIPS_GetTextT (const TOOLTIPS_INFO
*infoPtr
, TTTOOLINFOW
*ti
, BOOL isW
)
1322 if (ti
->cbSize
< TTTOOLINFOW_V1_SIZE
)
1325 nTool
= TOOLTIPS_GetToolFromInfoT (infoPtr
, ti
);
1326 if (nTool
== -1) return 0;
1328 if (infoPtr
->tools
[nTool
].lpszText
== NULL
)
1332 ti
->lpszText
[0] = '\0';
1333 TOOLTIPS_GetTipText(infoPtr
, nTool
, ti
->lpszText
);
1336 WCHAR buffer
[INFOTIPSIZE
];
1338 /* NB this API is broken, there is no way for the app to determine
1339 what size buffer it requires nor a way to specify how long the
1340 one it supplies is. According to the test result, it's up to
1341 80 bytes by the ANSI version. */
1344 TOOLTIPS_GetTipText(infoPtr
, nTool
, buffer
);
1345 WideCharToMultiByte(CP_ACP
, 0, buffer
, -1, (LPSTR
)ti
->lpszText
,
1346 MAX_TEXT_SIZE_A
, NULL
, NULL
);
1353 static inline LRESULT
1354 TOOLTIPS_GetTipBkColor (const TOOLTIPS_INFO
*infoPtr
)
1356 return infoPtr
->clrBk
;
1360 static inline LRESULT
1361 TOOLTIPS_GetTipTextColor (const TOOLTIPS_INFO
*infoPtr
)
1363 return infoPtr
->clrText
;
1367 static inline LRESULT
1368 TOOLTIPS_GetToolCount (const TOOLTIPS_INFO
*infoPtr
)
1370 return infoPtr
->uNumTools
;
1375 TOOLTIPS_GetToolInfoT (const TOOLTIPS_INFO
*infoPtr
, TTTOOLINFOW
*ti
, BOOL isW
)
1380 if (!ti
) return FALSE
;
1381 if (ti
->cbSize
< TTTOOLINFOW_V1_SIZE
)
1383 if (infoPtr
->uNumTools
== 0)
1386 nTool
= TOOLTIPS_GetToolFromInfoT (infoPtr
, ti
);
1390 TRACE("tool %d\n", nTool
);
1393 TOOLTIPS_CopyInfoT (infoPtr
, nTool
, ti
, isW
);
1401 TOOLTIPS_HitTestT (const TOOLTIPS_INFO
*infoPtr
, LPTTHITTESTINFOW lptthit
,
1409 nTool
= TOOLTIPS_GetToolFromPoint (infoPtr
, lptthit
->hwnd
, &lptthit
->pt
);
1413 TRACE("tool %d\n", nTool
);
1415 /* copy tool data */
1416 if (lptthit
->ti
.cbSize
>= TTTOOLINFOW_V1_SIZE
)
1417 TOOLTIPS_CopyInfoT (infoPtr
, nTool
, &lptthit
->ti
, isW
);
1424 TOOLTIPS_NewToolRectT (TOOLTIPS_INFO
*infoPtr
, const TTTOOLINFOW
*ti
)
1429 if (ti
->cbSize
< TTTOOLINFOW_V1_SIZE
)
1432 nTool
= TOOLTIPS_GetToolFromInfoT (infoPtr
, ti
);
1434 TRACE("nTool = %d, rect = %s\n", nTool
, wine_dbgstr_rect(&ti
->rect
));
1436 if (nTool
== -1) return 0;
1438 infoPtr
->tools
[nTool
].rect
= ti
->rect
;
1444 static inline LRESULT
1445 TOOLTIPS_Pop (TOOLTIPS_INFO
*infoPtr
)
1447 TOOLTIPS_Hide (infoPtr
);
1454 TOOLTIPS_RelayEvent (TOOLTIPS_INFO
*infoPtr
, LPMSG lpMsg
)
1460 ERR("lpMsg == NULL\n");
1464 switch (lpMsg
->message
) {
1465 case WM_LBUTTONDOWN
:
1467 case WM_MBUTTONDOWN
:
1469 case WM_RBUTTONDOWN
:
1471 TOOLTIPS_Hide (infoPtr
);
1475 pt
.x
= (short)LOWORD(lpMsg
->lParam
);
1476 pt
.y
= (short)HIWORD(lpMsg
->lParam
);
1477 nOldTool
= infoPtr
->nTool
;
1478 infoPtr
->nTool
= TOOLTIPS_GetToolFromPoint(infoPtr
, lpMsg
->hwnd
,
1480 TRACE("tool (%p) %d %d %d\n", infoPtr
->hwndSelf
, nOldTool
,
1481 infoPtr
->nTool
, infoPtr
->nCurrentTool
);
1482 TRACE("WM_MOUSEMOVE (%p %s)\n", infoPtr
->hwndSelf
, wine_dbgstr_point(&pt
));
1484 if (infoPtr
->nTool
!= nOldTool
) {
1485 if(infoPtr
->nTool
== -1) { /* Moved out of all tools */
1486 TOOLTIPS_Hide(infoPtr
);
1487 KillTimer(infoPtr
->hwndSelf
, ID_TIMERLEAVE
);
1488 } else if (nOldTool
== -1) { /* Moved from outside */
1489 if(infoPtr
->bActive
) {
1490 SetTimer(infoPtr
->hwndSelf
, ID_TIMERSHOW
, infoPtr
->nInitialTime
, 0);
1491 TRACE("timer 1 started\n");
1493 } else { /* Moved from one to another */
1494 TOOLTIPS_Hide (infoPtr
);
1495 KillTimer(infoPtr
->hwndSelf
, ID_TIMERLEAVE
);
1496 if(infoPtr
->bActive
) {
1497 SetTimer (infoPtr
->hwndSelf
, ID_TIMERSHOW
, infoPtr
->nReshowTime
, 0);
1498 TRACE("timer 1 started\n");
1501 } else if(infoPtr
->nCurrentTool
!= -1) { /* restart autopop */
1502 KillTimer(infoPtr
->hwndSelf
, ID_TIMERPOP
);
1503 SetTimer(infoPtr
->hwndSelf
, ID_TIMERPOP
, infoPtr
->nAutoPopTime
, 0);
1504 TRACE("timer 2 restarted\n");
1505 } else if(infoPtr
->nTool
!= -1 && infoPtr
->bActive
) {
1506 /* previous show attempt didn't result in tooltip so try again */
1507 SetTimer(infoPtr
->hwndSelf
, ID_TIMERSHOW
, infoPtr
->nInitialTime
, 0);
1508 TRACE("timer 1 started\n");
1518 TOOLTIPS_SetDelayTime (TOOLTIPS_INFO
*infoPtr
, DWORD duration
, INT nTime
)
1521 case TTDT_AUTOMATIC
:
1523 nTime
= GetDoubleClickTime();
1524 infoPtr
->nReshowTime
= nTime
/ 5;
1525 infoPtr
->nAutoPopTime
= nTime
* 10;
1526 infoPtr
->nInitialTime
= nTime
;
1531 nTime
= GetDoubleClickTime() / 5;
1532 infoPtr
->nReshowTime
= nTime
;
1537 nTime
= GetDoubleClickTime() * 10;
1538 infoPtr
->nAutoPopTime
= nTime
;
1543 nTime
= GetDoubleClickTime();
1544 infoPtr
->nInitialTime
= nTime
;
1548 WARN("Invalid duration flag %x\n", duration
);
1557 TOOLTIPS_SetMargin (TOOLTIPS_INFO
*infoPtr
, const RECT
*rect
)
1560 infoPtr
->rcMargin
= *rect
;
1566 static inline LRESULT
1567 TOOLTIPS_SetMaxTipWidth (TOOLTIPS_INFO
*infoPtr
, INT MaxWidth
)
1569 INT nTemp
= infoPtr
->nMaxTipWidth
;
1571 infoPtr
->nMaxTipWidth
= MaxWidth
;
1577 static inline LRESULT
1578 TOOLTIPS_SetTipBkColor (TOOLTIPS_INFO
*infoPtr
, COLORREF clrBk
)
1580 infoPtr
->clrBk
= clrBk
;
1586 static inline LRESULT
1587 TOOLTIPS_SetTipTextColor (TOOLTIPS_INFO
*infoPtr
, COLORREF clrText
)
1589 infoPtr
->clrText
= clrText
;
1596 TOOLTIPS_SetTitleT (TOOLTIPS_INFO
*infoPtr
, UINT_PTR uTitleIcon
, LPCWSTR pszTitle
,
1601 TRACE("hwnd = %p, title = %s, icon = %p\n", infoPtr
->hwndSelf
, debugstr_w(pszTitle
),
1604 Free(infoPtr
->pszTitle
);
1610 size
= (strlenW(pszTitle
)+1)*sizeof(WCHAR
);
1611 infoPtr
->pszTitle
= Alloc(size
);
1612 if (!infoPtr
->pszTitle
)
1614 memcpy(infoPtr
->pszTitle
, pszTitle
, size
);
1618 size
= sizeof(WCHAR
)*MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)pszTitle
, -1, NULL
, 0);
1619 infoPtr
->pszTitle
= Alloc(size
);
1620 if (!infoPtr
->pszTitle
)
1622 MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)pszTitle
, -1, infoPtr
->pszTitle
, size
/sizeof(WCHAR
));
1626 infoPtr
->pszTitle
= NULL
;
1628 if (uTitleIcon
<= TTI_ERROR
)
1629 infoPtr
->hTitleIcon
= hTooltipIcons
[uTitleIcon
];
1631 infoPtr
->hTitleIcon
= CopyIcon((HICON
)uTitleIcon
);
1633 TRACE("icon = %p\n", infoPtr
->hTitleIcon
);
1640 TOOLTIPS_SetToolInfoT (TOOLTIPS_INFO
*infoPtr
, const TTTOOLINFOW
*ti
, BOOL isW
)
1642 TTTOOL_INFO
*toolPtr
;
1646 if (ti
->cbSize
< TTTOOLINFOW_V1_SIZE
)
1649 nTool
= TOOLTIPS_GetToolFromInfoT (infoPtr
, ti
);
1650 if (nTool
== -1) return 0;
1652 TRACE("tool %d\n", nTool
);
1654 toolPtr
= &infoPtr
->tools
[nTool
];
1656 /* copy tool data */
1657 toolPtr
->uFlags
= ti
->uFlags
;
1658 toolPtr
->hwnd
= ti
->hwnd
;
1659 toolPtr
->uId
= ti
->uId
;
1660 toolPtr
->rect
= ti
->rect
;
1661 toolPtr
->hinst
= ti
->hinst
;
1663 if (IS_INTRESOURCE(ti
->lpszText
)) {
1664 TRACE("set string id %x\n", LOWORD(ti
->lpszText
));
1665 toolPtr
->lpszText
= ti
->lpszText
;
1668 if (ti
->lpszText
== LPSTR_TEXTCALLBACKW
)
1669 toolPtr
->lpszText
= LPSTR_TEXTCALLBACKW
;
1671 if ( (toolPtr
->lpszText
) &&
1672 !IS_INTRESOURCE(toolPtr
->lpszText
) ) {
1673 if( toolPtr
->lpszText
!= LPSTR_TEXTCALLBACKW
)
1674 Free (toolPtr
->lpszText
);
1675 toolPtr
->lpszText
= NULL
;
1679 INT len
= lstrlenW (ti
->lpszText
);
1680 toolPtr
->lpszText
= Alloc ((len
+1)*sizeof(WCHAR
));
1681 strcpyW (toolPtr
->lpszText
, ti
->lpszText
);
1684 INT len
= MultiByteToWideChar(CP_ACP
, 0, (LPSTR
)ti
->lpszText
,
1686 toolPtr
->lpszText
= Alloc (len
* sizeof(WCHAR
));
1687 MultiByteToWideChar(CP_ACP
, 0, (LPSTR
)ti
->lpszText
, -1,
1688 toolPtr
->lpszText
, len
);
1694 if (ti
->cbSize
>= TTTOOLINFOW_V2_SIZE
)
1695 toolPtr
->lParam
= ti
->lParam
;
1697 if (infoPtr
->nCurrentTool
== nTool
)
1699 TOOLTIPS_GetTipText (infoPtr
, infoPtr
->nCurrentTool
, infoPtr
->szTipText
);
1701 if (infoPtr
->szTipText
[0] == 0)
1702 TOOLTIPS_Hide(infoPtr
);
1704 TOOLTIPS_Show (infoPtr
, FALSE
);
1712 TOOLTIPS_TrackActivate (TOOLTIPS_INFO
*infoPtr
, BOOL track_activate
, const TTTOOLINFOA
*ti
)
1714 if (track_activate
) {
1717 if (ti
->cbSize
< TTTOOLINFOA_V1_SIZE
)
1721 infoPtr
->nTrackTool
= TOOLTIPS_GetToolFromInfoT (infoPtr
, (const TTTOOLINFOW
*)ti
);
1722 if (infoPtr
->nTrackTool
!= -1) {
1723 TRACE("activated\n");
1724 infoPtr
->bTrackActive
= TRUE
;
1725 TOOLTIPS_TrackShow (infoPtr
);
1730 TOOLTIPS_TrackHide (infoPtr
);
1732 infoPtr
->bTrackActive
= FALSE
;
1733 infoPtr
->nTrackTool
= -1;
1735 TRACE("deactivated\n");
1743 TOOLTIPS_TrackPosition (TOOLTIPS_INFO
*infoPtr
, LPARAM coord
)
1745 infoPtr
->xTrackPos
= (INT
)LOWORD(coord
);
1746 infoPtr
->yTrackPos
= (INT
)HIWORD(coord
);
1748 if (infoPtr
->bTrackActive
) {
1750 infoPtr
->xTrackPos
, infoPtr
->yTrackPos
);
1752 TOOLTIPS_TrackShow (infoPtr
);
1760 TOOLTIPS_Update (TOOLTIPS_INFO
*infoPtr
)
1762 if (infoPtr
->nCurrentTool
!= -1)
1763 UpdateWindow (infoPtr
->hwndSelf
);
1770 TOOLTIPS_UpdateTipTextT (TOOLTIPS_INFO
*infoPtr
, const TTTOOLINFOW
*ti
, BOOL isW
)
1772 TTTOOL_INFO
*toolPtr
;
1776 if (ti
->cbSize
< TTTOOLINFOW_V1_SIZE
)
1779 nTool
= TOOLTIPS_GetToolFromInfoT (infoPtr
, ti
);
1783 TRACE("tool %d\n", nTool
);
1785 toolPtr
= &infoPtr
->tools
[nTool
];
1787 /* copy tool text */
1788 toolPtr
->hinst
= ti
->hinst
;
1790 if (IS_INTRESOURCE(ti
->lpszText
)){
1791 toolPtr
->lpszText
= ti
->lpszText
;
1793 else if (ti
->lpszText
) {
1794 if (ti
->lpszText
== LPSTR_TEXTCALLBACKW
)
1795 toolPtr
->lpszText
= LPSTR_TEXTCALLBACKW
;
1797 if ( (toolPtr
->lpszText
) &&
1798 !IS_INTRESOURCE(toolPtr
->lpszText
) ) {
1799 if( toolPtr
->lpszText
!= LPSTR_TEXTCALLBACKW
)
1800 Free (toolPtr
->lpszText
);
1801 toolPtr
->lpszText
= NULL
;
1805 INT len
= lstrlenW (ti
->lpszText
);
1806 toolPtr
->lpszText
= Alloc ((len
+1)*sizeof(WCHAR
));
1807 strcpyW (toolPtr
->lpszText
, ti
->lpszText
);
1810 INT len
= MultiByteToWideChar(CP_ACP
, 0, (LPSTR
)ti
->lpszText
,
1812 toolPtr
->lpszText
= Alloc (len
* sizeof(WCHAR
));
1813 MultiByteToWideChar(CP_ACP
, 0, (LPSTR
)ti
->lpszText
, -1,
1814 toolPtr
->lpszText
, len
);
1820 if(infoPtr
->nCurrentTool
== -1) return 0;
1822 if (infoPtr
->bActive
)
1823 TOOLTIPS_Show (infoPtr
, FALSE
);
1824 else if (infoPtr
->bTrackActive
)
1825 TOOLTIPS_Show (infoPtr
, TRUE
);
1832 TOOLTIPS_Create (HWND hwnd
)
1834 TOOLTIPS_INFO
*infoPtr
;
1836 /* allocate memory for info structure */
1837 infoPtr
= Alloc (sizeof(TOOLTIPS_INFO
));
1838 SetWindowLongPtrW (hwnd
, 0, (DWORD_PTR
)infoPtr
);
1840 /* initialize info structure */
1841 infoPtr
->bActive
= TRUE
;
1842 infoPtr
->bTrackActive
= FALSE
;
1844 infoPtr
->nMaxTipWidth
= -1;
1845 infoPtr
->nTool
= -1;
1846 infoPtr
->nCurrentTool
= -1;
1847 infoPtr
->nTrackTool
= -1;
1848 infoPtr
->hwndSelf
= hwnd
;
1850 /* initialize colours and fonts */
1851 TOOLTIPS_InitSystemSettings(infoPtr
);
1853 TOOLTIPS_SetDelayTime(infoPtr
, TTDT_AUTOMATIC
, 0);
1855 SetWindowPos (hwnd
, HWND_TOP
, 0, 0, 0, 0, SWP_NOZORDER
| SWP_HIDEWINDOW
| SWP_NOACTIVATE
);
1862 TOOLTIPS_Destroy (TOOLTIPS_INFO
*infoPtr
)
1864 TTTOOL_INFO
*toolPtr
;
1868 if (infoPtr
->tools
) {
1869 for (i
= 0; i
< infoPtr
->uNumTools
; i
++) {
1870 toolPtr
= &infoPtr
->tools
[i
];
1871 if (toolPtr
->lpszText
) {
1872 if ( (toolPtr
->lpszText
!= LPSTR_TEXTCALLBACKW
) &&
1873 !IS_INTRESOURCE(toolPtr
->lpszText
) )
1875 Free (toolPtr
->lpszText
);
1876 toolPtr
->lpszText
= NULL
;
1880 TOOLTIPS_ResetSubclass (toolPtr
);
1883 Free (infoPtr
->tools
);
1886 /* free title string */
1887 Free (infoPtr
->pszTitle
);
1888 /* free title icon if not a standard one */
1889 if (TOOLTIPS_GetTitleIconIndex(infoPtr
->hTitleIcon
) > TTI_ERROR
)
1890 DeleteObject(infoPtr
->hTitleIcon
);
1893 DeleteObject (infoPtr
->hFont
);
1894 DeleteObject (infoPtr
->hTitleFont
);
1896 /* free tool tips info data */
1897 SetWindowLongPtrW(infoPtr
->hwndSelf
, 0, 0);
1904 static inline LRESULT
1905 TOOLTIPS_GetFont (const TOOLTIPS_INFO
*infoPtr
)
1907 return (LRESULT
)infoPtr
->hFont
;
1912 TOOLTIPS_MouseMessage (TOOLTIPS_INFO
*infoPtr
)
1914 TOOLTIPS_Hide (infoPtr
);
1921 TOOLTIPS_NCCreate (HWND hwnd
)
1923 DWORD dwStyle
= GetWindowLongW (hwnd
, GWL_STYLE
);
1924 DWORD dwExStyle
= GetWindowLongW (hwnd
, GWL_EXSTYLE
);
1926 dwStyle
&= ~(WS_CHILD
| /*WS_MAXIMIZE |*/ WS_BORDER
| WS_DLGFRAME
);
1927 dwStyle
|= (WS_POPUP
| WS_BORDER
| WS_CLIPSIBLINGS
);
1929 /* WS_BORDER only draws a border round the window rect, not the
1930 * window region, therefore it is useless to us in balloon mode */
1931 if (dwStyle
& TTS_BALLOON
) dwStyle
&= ~WS_BORDER
;
1933 SetWindowLongW (hwnd
, GWL_STYLE
, dwStyle
);
1935 dwExStyle
|= WS_EX_TOOLWINDOW
;
1936 SetWindowLongW (hwnd
, GWL_EXSTYLE
, dwExStyle
);
1943 TOOLTIPS_NCHitTest (const TOOLTIPS_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
1945 INT nTool
= (infoPtr
->bTrackActive
) ? infoPtr
->nTrackTool
: infoPtr
->nTool
;
1947 TRACE(" nTool=%d\n", nTool
);
1949 if ((nTool
> -1) && (nTool
< infoPtr
->uNumTools
)) {
1950 if (infoPtr
->tools
[nTool
].uFlags
& TTF_TRANSPARENT
) {
1951 TRACE("-- in transparent mode\n");
1952 return HTTRANSPARENT
;
1956 return DefWindowProcW (infoPtr
->hwndSelf
, WM_NCHITTEST
, wParam
, lParam
);
1961 TOOLTIPS_NotifyFormat (TOOLTIPS_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
1963 FIXME ("hwnd=%p wParam=%lx lParam=%lx\n", infoPtr
->hwndSelf
, wParam
, lParam
);
1970 TOOLTIPS_Paint (const TOOLTIPS_INFO
*infoPtr
, HDC hDC
)
1975 hdc
= (hDC
== NULL
) ? BeginPaint (infoPtr
->hwndSelf
, &ps
) : hDC
;
1976 TOOLTIPS_Refresh (infoPtr
, hdc
);
1978 EndPaint (infoPtr
->hwndSelf
, &ps
);
1984 TOOLTIPS_SetFont (TOOLTIPS_INFO
*infoPtr
, HFONT hFont
, BOOL redraw
)
1988 if(!GetObjectW(hFont
, sizeof(lf
), &lf
))
1991 DeleteObject (infoPtr
->hFont
);
1992 infoPtr
->hFont
= CreateFontIndirectW(&lf
);
1994 DeleteObject (infoPtr
->hTitleFont
);
1995 lf
.lfWeight
= FW_BOLD
;
1996 infoPtr
->hTitleFont
= CreateFontIndirectW(&lf
);
1998 if (redraw
&& infoPtr
->nCurrentTool
!= -1)
1999 FIXME("full redraw needed\n");
2004 /******************************************************************
2005 * TOOLTIPS_GetTextLength
2007 * This function is called when the tooltip receive a
2008 * WM_GETTEXTLENGTH message.
2010 * returns the length, in characters, of the tip text
2012 static inline LRESULT
2013 TOOLTIPS_GetTextLength(const TOOLTIPS_INFO
*infoPtr
)
2015 return strlenW(infoPtr
->szTipText
);
2018 /******************************************************************
2019 * TOOLTIPS_OnWMGetText
2021 * This function is called when the tooltip receive a
2022 * WM_GETTEXT message.
2023 * wParam : specifies the maximum number of characters to be copied
2024 * lParam : is the pointer to the buffer that will receive
2027 * returns the number of characters copied
2030 TOOLTIPS_OnWMGetText (const TOOLTIPS_INFO
*infoPtr
, WPARAM size
, LPWSTR pszText
)
2037 res
= min(strlenW(infoPtr
->szTipText
)+1, size
);
2038 memcpy(pszText
, infoPtr
->szTipText
, res
*sizeof(WCHAR
));
2039 pszText
[res
-1] = '\0';
2044 TOOLTIPS_Timer (TOOLTIPS_INFO
*infoPtr
, INT iTimer
)
2048 TRACE("timer %d (%p) expired\n", iTimer
, infoPtr
->hwndSelf
);
2052 KillTimer (infoPtr
->hwndSelf
, ID_TIMERSHOW
);
2053 nOldTool
= infoPtr
->nTool
;
2054 if ((infoPtr
->nTool
= TOOLTIPS_CheckTool (infoPtr
, TRUE
)) == nOldTool
)
2055 TOOLTIPS_Show (infoPtr
, FALSE
);
2059 TOOLTIPS_Hide (infoPtr
);
2063 nOldTool
= infoPtr
->nTool
;
2064 infoPtr
->nTool
= TOOLTIPS_CheckTool (infoPtr
, FALSE
);
2065 TRACE("tool (%p) %d %d %d\n", infoPtr
->hwndSelf
, nOldTool
,
2066 infoPtr
->nTool
, infoPtr
->nCurrentTool
);
2067 if (infoPtr
->nTool
!= nOldTool
) {
2068 if(infoPtr
->nTool
== -1) { /* Moved out of all tools */
2069 TOOLTIPS_Hide(infoPtr
);
2070 KillTimer(infoPtr
->hwndSelf
, ID_TIMERLEAVE
);
2071 } else if (nOldTool
== -1) { /* Moved from outside */
2072 ERR("How did this happen?\n");
2073 } else { /* Moved from one to another */
2074 TOOLTIPS_Hide (infoPtr
);
2075 KillTimer(infoPtr
->hwndSelf
, ID_TIMERLEAVE
);
2076 if(infoPtr
->bActive
) {
2077 SetTimer (infoPtr
->hwndSelf
, ID_TIMERSHOW
, infoPtr
->nReshowTime
, 0);
2078 TRACE("timer 1 started!\n");
2085 ERR("Unknown timer id %d\n", iTimer
);
2093 TOOLTIPS_WinIniChange (TOOLTIPS_INFO
*infoPtr
)
2095 TOOLTIPS_InitSystemSettings (infoPtr
);
2101 static LRESULT CALLBACK
2102 TOOLTIPS_SubclassProc (HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
, UINT_PTR uID
, DWORD_PTR dwRef
)
2104 TOOLTIPS_INFO
*infoPtr
= TOOLTIPS_GetInfoPtr ((HWND
)dwRef
);
2110 case WM_LBUTTONDOWN
:
2112 case WM_MBUTTONDOWN
:
2114 case WM_RBUTTONDOWN
:
2119 msg
.message
= message
;
2120 msg
.wParam
= wParam
;
2121 msg
.lParam
= lParam
;
2122 TOOLTIPS_RelayEvent(infoPtr
, &msg
);
2126 RemoveWindowSubclass(hwnd
, TOOLTIPS_SubclassProc
, 1);
2132 return DefSubclassProc(hwnd
, message
, wParam
, lParam
);
2136 static LRESULT CALLBACK
2137 TOOLTIPS_WindowProc (HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
2139 TOOLTIPS_INFO
*infoPtr
= TOOLTIPS_GetInfoPtr (hwnd
);
2141 TRACE("hwnd=%p msg=%x wparam=%lx lParam=%lx\n", hwnd
, uMsg
, wParam
, lParam
);
2142 if (!infoPtr
&& (uMsg
!= WM_CREATE
) && (uMsg
!= WM_NCCREATE
))
2143 return DefWindowProcW (hwnd
, uMsg
, wParam
, lParam
);
2147 return TOOLTIPS_Activate (infoPtr
, (BOOL
)wParam
);
2151 return TOOLTIPS_AddToolT (infoPtr
, (LPTTTOOLINFOW
)lParam
, uMsg
== TTM_ADDTOOLW
);
2155 return TOOLTIPS_DelToolT (infoPtr
, (LPTOOLINFOW
)lParam
,
2156 uMsg
== TTM_DELTOOLW
);
2157 case TTM_ENUMTOOLSA
:
2158 case TTM_ENUMTOOLSW
:
2159 return TOOLTIPS_EnumToolsT (infoPtr
, (UINT
)wParam
, (LPTTTOOLINFOW
)lParam
,
2160 uMsg
== TTM_ENUMTOOLSW
);
2161 case TTM_GETBUBBLESIZE
:
2162 return TOOLTIPS_GetBubbleSize (infoPtr
, (LPTTTOOLINFOW
)lParam
);
2164 case TTM_GETCURRENTTOOLA
:
2165 case TTM_GETCURRENTTOOLW
:
2166 return TOOLTIPS_GetCurrentToolT (infoPtr
, (LPTTTOOLINFOW
)lParam
,
2167 uMsg
== TTM_GETCURRENTTOOLW
);
2169 case TTM_GETDELAYTIME
:
2170 return TOOLTIPS_GetDelayTime (infoPtr
, (DWORD
)wParam
);
2173 return TOOLTIPS_GetMargin (infoPtr
, (LPRECT
)lParam
);
2175 case TTM_GETMAXTIPWIDTH
:
2176 return TOOLTIPS_GetMaxTipWidth (infoPtr
);
2180 return TOOLTIPS_GetTextT (infoPtr
, (LPTTTOOLINFOW
)lParam
,
2181 uMsg
== TTM_GETTEXTW
);
2183 case TTM_GETTIPBKCOLOR
:
2184 return TOOLTIPS_GetTipBkColor (infoPtr
);
2186 case TTM_GETTIPTEXTCOLOR
:
2187 return TOOLTIPS_GetTipTextColor (infoPtr
);
2189 case TTM_GETTOOLCOUNT
:
2190 return TOOLTIPS_GetToolCount (infoPtr
);
2192 case TTM_GETTOOLINFOA
:
2193 case TTM_GETTOOLINFOW
:
2194 return TOOLTIPS_GetToolInfoT (infoPtr
, (LPTTTOOLINFOW
)lParam
,
2195 uMsg
== TTM_GETTOOLINFOW
);
2199 return TOOLTIPS_HitTestT (infoPtr
, (LPTTHITTESTINFOW
)lParam
,
2200 uMsg
== TTM_HITTESTW
);
2201 case TTM_NEWTOOLRECTA
:
2202 case TTM_NEWTOOLRECTW
:
2203 return TOOLTIPS_NewToolRectT (infoPtr
, (LPTTTOOLINFOW
)lParam
);
2206 return TOOLTIPS_Pop (infoPtr
);
2208 case TTM_RELAYEVENT
:
2209 return TOOLTIPS_RelayEvent (infoPtr
, (LPMSG
)lParam
);
2211 case TTM_SETDELAYTIME
:
2212 return TOOLTIPS_SetDelayTime (infoPtr
, (DWORD
)wParam
, (INT
)LOWORD(lParam
));
2215 return TOOLTIPS_SetMargin (infoPtr
, (LPRECT
)lParam
);
2217 case TTM_SETMAXTIPWIDTH
:
2218 return TOOLTIPS_SetMaxTipWidth (infoPtr
, (INT
)lParam
);
2220 case TTM_SETTIPBKCOLOR
:
2221 return TOOLTIPS_SetTipBkColor (infoPtr
, (COLORREF
)wParam
);
2223 case TTM_SETTIPTEXTCOLOR
:
2224 return TOOLTIPS_SetTipTextColor (infoPtr
, (COLORREF
)wParam
);
2228 return TOOLTIPS_SetTitleT (infoPtr
, (UINT_PTR
)wParam
, (LPCWSTR
)lParam
,
2229 uMsg
== TTM_SETTITLEW
);
2231 case TTM_SETTOOLINFOA
:
2232 case TTM_SETTOOLINFOW
:
2233 return TOOLTIPS_SetToolInfoT (infoPtr
, (LPTTTOOLINFOW
)lParam
,
2234 uMsg
== TTM_SETTOOLINFOW
);
2236 case TTM_TRACKACTIVATE
:
2237 return TOOLTIPS_TrackActivate (infoPtr
, (BOOL
)wParam
, (LPTTTOOLINFOA
)lParam
);
2239 case TTM_TRACKPOSITION
:
2240 return TOOLTIPS_TrackPosition (infoPtr
, lParam
);
2243 return TOOLTIPS_Update (infoPtr
);
2245 case TTM_UPDATETIPTEXTA
:
2246 case TTM_UPDATETIPTEXTW
:
2247 return TOOLTIPS_UpdateTipTextT (infoPtr
, (LPTTTOOLINFOW
)lParam
,
2248 uMsg
== TTM_UPDATETIPTEXTW
);
2250 case TTM_WINDOWFROMPOINT
:
2251 return (LRESULT
)WindowFromPoint (*((LPPOINT
)lParam
));
2254 return TOOLTIPS_Create (hwnd
);
2257 return TOOLTIPS_Destroy (infoPtr
);
2260 /* we draw the background in WM_PAINT */
2264 return TOOLTIPS_GetFont (infoPtr
);
2267 return TOOLTIPS_OnWMGetText (infoPtr
, wParam
, (LPWSTR
)lParam
);
2269 case WM_GETTEXTLENGTH
:
2270 return TOOLTIPS_GetTextLength (infoPtr
);
2272 case WM_LBUTTONDOWN
:
2274 case WM_MBUTTONDOWN
:
2276 case WM_RBUTTONDOWN
:
2279 return TOOLTIPS_MouseMessage (infoPtr
);
2282 return TOOLTIPS_NCCreate (hwnd
);
2285 return TOOLTIPS_NCHitTest (infoPtr
, wParam
, lParam
);
2287 case WM_NOTIFYFORMAT
:
2288 return TOOLTIPS_NotifyFormat (infoPtr
, wParam
, lParam
);
2290 case WM_PRINTCLIENT
:
2292 return TOOLTIPS_Paint (infoPtr
, (HDC
)wParam
);
2295 return TOOLTIPS_SetFont (infoPtr
, (HFONT
)wParam
, LOWORD(lParam
));
2297 case WM_SYSCOLORCHANGE
:
2298 COMCTL32_RefreshSysColors();
2302 return TOOLTIPS_Timer (infoPtr
, (INT
)wParam
);
2304 case WM_WININICHANGE
:
2305 return TOOLTIPS_WinIniChange (infoPtr
);
2308 if ((uMsg
>= WM_USER
) && (uMsg
< WM_APP
) && !COMCTL32_IsReflectedMessage(uMsg
))
2309 ERR("unknown msg %04x wp=%08lx lp=%08lx\n",
2310 uMsg
, wParam
, lParam
);
2311 return DefWindowProcW (hwnd
, uMsg
, wParam
, lParam
);
2317 TOOLTIPS_Register (void)
2321 ZeroMemory (&wndClass
, sizeof(WNDCLASSW
));
2322 wndClass
.style
= CS_GLOBALCLASS
| CS_DBLCLKS
| CS_SAVEBITS
;
2323 wndClass
.lpfnWndProc
= TOOLTIPS_WindowProc
;
2324 wndClass
.cbClsExtra
= 0;
2325 wndClass
.cbWndExtra
= sizeof(TOOLTIPS_INFO
*);
2326 wndClass
.hCursor
= LoadCursorW (0, (LPWSTR
)IDC_ARROW
);
2327 wndClass
.hbrBackground
= 0;
2328 wndClass
.lpszClassName
= TOOLTIPS_CLASSW
;
2330 RegisterClassW (&wndClass
);
2332 hTooltipIcons
[TTI_NONE
] = NULL
;
2333 hTooltipIcons
[TTI_INFO
] = LoadImageW(COMCTL32_hModule
,
2334 (LPCWSTR
)MAKEINTRESOURCE(IDI_TT_INFO_SM
), IMAGE_ICON
, 0, 0, 0);
2335 hTooltipIcons
[TTI_WARNING
] = LoadImageW(COMCTL32_hModule
,
2336 (LPCWSTR
)MAKEINTRESOURCE(IDI_TT_WARN_SM
), IMAGE_ICON
, 0, 0, 0);
2337 hTooltipIcons
[TTI_ERROR
] = LoadImageW(COMCTL32_hModule
,
2338 (LPCWSTR
)MAKEINTRESOURCE(IDI_TT_ERROR_SM
), IMAGE_ICON
, 0, 0, 0);
2343 TOOLTIPS_Unregister (void)
2346 for (i
= TTI_INFO
; i
<= TTI_ERROR
; i
++)
2347 DestroyIcon(hTooltipIcons
[i
]);
2348 UnregisterClassW (TOOLTIPS_CLASSW
, NULL
);