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
];
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
->hStatusFont
);
199 nclm
.cbSize
= sizeof(nclm
);
200 SystemParametersInfoW (SPI_GETNONCLIENTMETRICS
, sizeof(nclm
), &nclm
, 0);
201 infoPtr
->hStatusFont
= CreateFontIndirectW (&nclm
.lfStatusFont
);
203 DeleteObject (infoPtr
->hTitleFont
);
204 nclm
.lfStatusFont
.lfWeight
= FW_BOLD
;
205 infoPtr
->hTitleFont
= CreateFontIndirectW (&nclm
.lfStatusFont
);
207 infoPtr
->hFont
= infoPtr
->hStatusFont
;
210 /* Custom draw routines */
212 TOOLTIPS_customdraw_fill(const TOOLTIPS_INFO
*infoPtr
, NMTTCUSTOMDRAW
*lpnmttcd
,
213 HDC hdc
, const RECT
*rcBounds
, UINT uFlags
)
215 ZeroMemory(lpnmttcd
, sizeof(NMTTCUSTOMDRAW
));
216 lpnmttcd
->uDrawFlags
= uFlags
;
217 lpnmttcd
->nmcd
.hdr
.hwndFrom
= infoPtr
->hwndSelf
;
218 lpnmttcd
->nmcd
.hdr
.code
= NM_CUSTOMDRAW
;
219 if (infoPtr
->nCurrentTool
!= -1) {
220 TTTOOL_INFO
*toolPtr
= &infoPtr
->tools
[infoPtr
->nCurrentTool
];
221 lpnmttcd
->nmcd
.hdr
.idFrom
= toolPtr
->uId
;
223 lpnmttcd
->nmcd
.hdc
= hdc
;
224 lpnmttcd
->nmcd
.rc
= *rcBounds
;
225 /* FIXME - dwItemSpec, uItemState, lItemlParam */
229 TOOLTIPS_notify_customdraw (DWORD dwDrawStage
, NMTTCUSTOMDRAW
*lpnmttcd
)
232 lpnmttcd
->nmcd
.dwDrawStage
= dwDrawStage
;
234 TRACE("Notifying stage %ld, flags %x, id %x\n", lpnmttcd
->nmcd
.dwDrawStage
,
235 lpnmttcd
->uDrawFlags
, lpnmttcd
->nmcd
.hdr
.code
);
237 result
= SendMessageW(GetParent(lpnmttcd
->nmcd
.hdr
.hwndFrom
), WM_NOTIFY
,
238 0, (LPARAM
)lpnmttcd
);
240 TRACE("Notify result %x\n", (unsigned int)result
);
246 TOOLTIPS_Refresh (const TOOLTIPS_INFO
*infoPtr
, HDC hdc
)
252 UINT uFlags
= DT_EXTERNALLEADING
;
254 DWORD dwStyle
= GetWindowLongW(infoPtr
->hwndSelf
, GWL_STYLE
);
255 NMTTCUSTOMDRAW nmttcd
;
258 if (infoPtr
->nMaxTipWidth
> -1)
259 uFlags
|= DT_WORDBREAK
;
260 if (GetWindowLongW (infoPtr
->hwndSelf
, GWL_STYLE
) & TTS_NOPREFIX
)
261 uFlags
|= DT_NOPREFIX
;
262 GetClientRect (infoPtr
->hwndSelf
, &rc
);
264 hBrush
= CreateSolidBrush(infoPtr
->clrBk
);
266 oldBkMode
= SetBkMode (hdc
, TRANSPARENT
);
267 SetTextColor (hdc
, infoPtr
->clrText
);
268 hOldFont
= SelectObject (hdc
, infoPtr
->hFont
);
270 /* Custom draw - Call PrePaint once initial properties set up */
271 /* Note: Contrary to MSDN, CDRF_SKIPDEFAULT still draws a tooltip */
272 TOOLTIPS_customdraw_fill(infoPtr
, &nmttcd
, hdc
, &rc
, uFlags
);
273 cdmode
= TOOLTIPS_notify_customdraw(CDDS_PREPAINT
, &nmttcd
);
274 uFlags
= nmttcd
.uDrawFlags
;
276 if (dwStyle
& TTS_BALLOON
)
278 /* create a region to store result into */
279 hRgn
= CreateRectRgn(0, 0, 0, 0);
281 GetWindowRgn(infoPtr
->hwndSelf
, hRgn
);
283 /* fill the background */
284 FillRgn(hdc
, hRgn
, hBrush
);
285 DeleteObject(hBrush
);
290 /* fill the background */
291 FillRect(hdc
, &rc
, hBrush
);
292 DeleteObject(hBrush
);
296 if ((dwStyle
& TTS_BALLOON
) || infoPtr
->pszTitle
)
298 /* calculate text rectangle */
299 rc
.left
+= (BALLOON_TEXT_MARGIN
+ infoPtr
->rcMargin
.left
);
300 rc
.top
+= (BALLOON_TEXT_MARGIN
+ infoPtr
->rcMargin
.top
);
301 rc
.right
-= (BALLOON_TEXT_MARGIN
+ infoPtr
->rcMargin
.right
);
302 rc
.bottom
-= (BALLOON_TEXT_MARGIN
+ infoPtr
->rcMargin
.bottom
);
303 if(infoPtr
->bToolBelow
) rc
.top
+= BALLOON_STEMHEIGHT
;
305 if (infoPtr
->pszTitle
)
307 RECT rcTitle
= {rc
.left
, rc
.top
, rc
.right
, rc
.bottom
};
313 icon_present
= infoPtr
->hTitleIcon
&&
314 DrawIconEx(hdc
, rc
.left
, rc
.top
, infoPtr
->hTitleIcon
,
315 ICON_WIDTH
, ICON_HEIGHT
, 0, NULL
, DI_NORMAL
);
317 rcTitle
.left
+= ICON_WIDTH
+ BALLOON_ICON_TITLE_SPACING
;
319 rcTitle
.bottom
= rc
.top
+ ICON_HEIGHT
;
321 /* draw title text */
322 prevFont
= SelectObject (hdc
, infoPtr
->hTitleFont
);
323 height
= DrawTextW(hdc
, infoPtr
->pszTitle
, -1, &rcTitle
, DT_BOTTOM
| DT_SINGLELINE
| DT_NOPREFIX
);
324 SelectObject (hdc
, prevFont
);
325 rc
.top
+= height
+ BALLOON_TITLE_TEXT_SPACING
;
330 /* calculate text rectangle */
331 rc
.left
+= (NORMAL_TEXT_MARGIN
+ infoPtr
->rcMargin
.left
);
332 rc
.top
+= (NORMAL_TEXT_MARGIN
+ infoPtr
->rcMargin
.top
);
333 rc
.right
-= (NORMAL_TEXT_MARGIN
+ infoPtr
->rcMargin
.right
);
334 rc
.bottom
-= (NORMAL_TEXT_MARGIN
+ infoPtr
->rcMargin
.bottom
);
338 DrawTextW (hdc
, infoPtr
->szTipText
, -1, &rc
, uFlags
);
340 /* Custom draw - Call PostPaint after drawing */
341 if (cdmode
& CDRF_NOTIFYPOSTPAINT
) {
342 TOOLTIPS_notify_customdraw(CDDS_POSTPAINT
, &nmttcd
);
345 /* be polite and reset the things we changed in the dc */
346 SelectObject (hdc
, hOldFont
);
347 SetBkMode (hdc
, oldBkMode
);
349 if (dwStyle
& TTS_BALLOON
)
351 /* frame region because default window proc doesn't do it */
352 INT width
= GetSystemMetrics(SM_CXDLGFRAME
) - GetSystemMetrics(SM_CXEDGE
);
353 INT height
= GetSystemMetrics(SM_CYDLGFRAME
) - GetSystemMetrics(SM_CYEDGE
);
355 hBrush
= GetSysColorBrush(COLOR_WINDOWFRAME
);
356 FrameRgn(hdc
, hRgn
, hBrush
, width
, height
);
363 static void TOOLTIPS_GetDispInfoA(const TOOLTIPS_INFO
*infoPtr
, TTTOOL_INFO
*toolPtr
, WCHAR
*buffer
)
365 NMTTDISPINFOA ttnmdi
;
367 /* fill NMHDR struct */
368 ZeroMemory (&ttnmdi
, sizeof(NMTTDISPINFOA
));
369 ttnmdi
.hdr
.hwndFrom
= infoPtr
->hwndSelf
;
370 ttnmdi
.hdr
.idFrom
= toolPtr
->uId
;
371 ttnmdi
.hdr
.code
= TTN_GETDISPINFOA
; /* == TTN_NEEDTEXTA */
372 ttnmdi
.lpszText
= ttnmdi
.szText
;
373 ttnmdi
.uFlags
= toolPtr
->uFlags
;
374 ttnmdi
.lParam
= toolPtr
->lParam
;
376 TRACE("hdr.idFrom = %Ix\n", ttnmdi
.hdr
.idFrom
);
377 SendMessageW(toolPtr
->hwnd
, WM_NOTIFY
, toolPtr
->uId
, (LPARAM
)&ttnmdi
);
379 if (IS_INTRESOURCE(ttnmdi
.lpszText
)) {
380 LoadStringW(ttnmdi
.hinst
, LOWORD(ttnmdi
.lpszText
),
381 buffer
, INFOTIPSIZE
);
382 if (ttnmdi
.uFlags
& TTF_DI_SETITEM
) {
383 toolPtr
->hinst
= ttnmdi
.hinst
;
384 toolPtr
->lpszText
= (LPWSTR
)ttnmdi
.lpszText
;
387 else if (ttnmdi
.lpszText
== 0) {
390 else if (ttnmdi
.lpszText
!= LPSTR_TEXTCALLBACKA
) {
391 Str_GetPtrAtoW(ttnmdi
.lpszText
, buffer
, INFOTIPSIZE
);
392 if (ttnmdi
.uFlags
& TTF_DI_SETITEM
) {
394 toolPtr
->lpszText
= NULL
;
395 Str_SetPtrW(&toolPtr
->lpszText
, buffer
);
399 ERR("recursive text callback\n");
403 /* no text available - try calling parent instead as per native */
404 /* FIXME: Unsure if SETITEM should save the value or not */
405 if (buffer
[0] == 0x00) {
407 SendMessageW(GetParent(toolPtr
->hwnd
), WM_NOTIFY
, toolPtr
->uId
, (LPARAM
)&ttnmdi
);
409 if (IS_INTRESOURCE(ttnmdi
.lpszText
)) {
410 LoadStringW(ttnmdi
.hinst
, LOWORD(ttnmdi
.lpszText
),
411 buffer
, INFOTIPSIZE
);
412 } else if (ttnmdi
.lpszText
&&
413 ttnmdi
.lpszText
!= LPSTR_TEXTCALLBACKA
) {
414 Str_GetPtrAtoW(ttnmdi
.lpszText
, buffer
, INFOTIPSIZE
);
419 static void TOOLTIPS_GetDispInfoW(const TOOLTIPS_INFO
*infoPtr
, TTTOOL_INFO
*toolPtr
, WCHAR
*buffer
)
421 NMTTDISPINFOW ttnmdi
;
423 /* fill NMHDR struct */
424 ZeroMemory (&ttnmdi
, sizeof(NMTTDISPINFOW
));
425 ttnmdi
.hdr
.hwndFrom
= infoPtr
->hwndSelf
;
426 ttnmdi
.hdr
.idFrom
= toolPtr
->uId
;
427 ttnmdi
.hdr
.code
= TTN_GETDISPINFOW
; /* == TTN_NEEDTEXTW */
428 ttnmdi
.lpszText
= ttnmdi
.szText
;
429 ttnmdi
.uFlags
= toolPtr
->uFlags
;
430 ttnmdi
.lParam
= toolPtr
->lParam
;
432 TRACE("hdr.idFrom = %Ix\n", ttnmdi
.hdr
.idFrom
);
433 SendMessageW(toolPtr
->hwnd
, WM_NOTIFY
, toolPtr
->uId
, (LPARAM
)&ttnmdi
);
435 if (IS_INTRESOURCE(ttnmdi
.lpszText
)) {
436 LoadStringW(ttnmdi
.hinst
, LOWORD(ttnmdi
.lpszText
),
437 buffer
, INFOTIPSIZE
);
438 if (ttnmdi
.uFlags
& TTF_DI_SETITEM
) {
439 toolPtr
->hinst
= ttnmdi
.hinst
;
440 toolPtr
->lpszText
= ttnmdi
.lpszText
;
443 else if (ttnmdi
.lpszText
== 0) {
446 else if (ttnmdi
.lpszText
!= LPSTR_TEXTCALLBACKW
) {
447 Str_GetPtrW(ttnmdi
.lpszText
, buffer
, INFOTIPSIZE
);
448 if (ttnmdi
.uFlags
& TTF_DI_SETITEM
) {
450 toolPtr
->lpszText
= NULL
;
451 Str_SetPtrW(&toolPtr
->lpszText
, buffer
);
455 ERR("recursive text callback\n");
459 /* no text available - try calling parent instead as per native */
460 /* FIXME: Unsure if SETITEM should save the value or not */
461 if (buffer
[0] == 0x00) {
463 SendMessageW(GetParent(toolPtr
->hwnd
), WM_NOTIFY
, toolPtr
->uId
, (LPARAM
)&ttnmdi
);
465 if (IS_INTRESOURCE(ttnmdi
.lpszText
)) {
466 LoadStringW(ttnmdi
.hinst
, LOWORD(ttnmdi
.lpszText
),
467 buffer
, INFOTIPSIZE
);
468 } else if (ttnmdi
.lpszText
&&
469 ttnmdi
.lpszText
!= LPSTR_TEXTCALLBACKW
) {
470 Str_GetPtrW(ttnmdi
.lpszText
, buffer
, INFOTIPSIZE
);
477 TOOLTIPS_GetTipText (const TOOLTIPS_INFO
*infoPtr
, INT nTool
, WCHAR
*buffer
)
479 TTTOOL_INFO
*toolPtr
= &infoPtr
->tools
[nTool
];
481 if (IS_INTRESOURCE(toolPtr
->lpszText
)) {
482 /* load a resource */
483 TRACE("load res string %p %x\n",
484 toolPtr
->hinst
, LOWORD(toolPtr
->lpszText
));
485 if (!LoadStringW (toolPtr
->hinst
, LOWORD(toolPtr
->lpszText
), buffer
, INFOTIPSIZE
))
488 else if (toolPtr
->lpszText
) {
489 if (toolPtr
->lpszText
== LPSTR_TEXTCALLBACKW
) {
490 if (toolPtr
->bNotifyUnicode
)
491 TOOLTIPS_GetDispInfoW(infoPtr
, toolPtr
, buffer
);
493 TOOLTIPS_GetDispInfoA(infoPtr
, toolPtr
, buffer
);
496 /* the item is a usual (unicode) text */
497 lstrcpynW (buffer
, toolPtr
->lpszText
, INFOTIPSIZE
);
501 /* no text available */
505 if (!(GetWindowLongW(infoPtr
->hwndSelf
, GWL_STYLE
) & TTS_NOPREFIX
)) {
507 if ((ptrW
= wcschr(buffer
, '\t')))
511 TRACE("%s\n", debugstr_w(buffer
));
516 TOOLTIPS_CalcTipSize (const TOOLTIPS_INFO
*infoPtr
, LPSIZE lpSize
)
520 DWORD style
= GetWindowLongW(infoPtr
->hwndSelf
, GWL_STYLE
);
521 UINT uFlags
= DT_EXTERNALLEADING
| DT_CALCRECT
;
522 RECT rc
= {0, 0, 0, 0};
525 if (infoPtr
->nMaxTipWidth
> -1) {
526 rc
.right
= infoPtr
->nMaxTipWidth
;
527 uFlags
|= DT_WORDBREAK
;
529 if (style
& TTS_NOPREFIX
)
530 uFlags
|= DT_NOPREFIX
;
531 TRACE("%s\n", debugstr_w(infoPtr
->szTipText
));
533 hdc
= GetDC (infoPtr
->hwndSelf
);
534 if (infoPtr
->pszTitle
)
536 RECT rcTitle
= {0, 0, 0, 0};
537 TRACE("title %s\n", debugstr_w(infoPtr
->pszTitle
));
538 if (infoPtr
->hTitleIcon
)
540 title
.cx
= ICON_WIDTH
;
541 title
.cy
= ICON_HEIGHT
;
543 if (title
.cx
!= 0) title
.cx
+= BALLOON_ICON_TITLE_SPACING
;
544 hOldFont
= SelectObject (hdc
, infoPtr
->hTitleFont
);
545 DrawTextW(hdc
, infoPtr
->pszTitle
, -1, &rcTitle
, DT_SINGLELINE
| DT_NOPREFIX
| DT_CALCRECT
);
546 SelectObject (hdc
, hOldFont
);
547 title
.cy
= max(title
.cy
, rcTitle
.bottom
- rcTitle
.top
) + BALLOON_TITLE_TEXT_SPACING
;
548 title
.cx
+= (rcTitle
.right
- rcTitle
.left
);
550 hOldFont
= SelectObject (hdc
, infoPtr
->hFont
);
551 DrawTextW (hdc
, infoPtr
->szTipText
, -1, &rc
, uFlags
);
552 SelectObject (hdc
, hOldFont
);
553 ReleaseDC (infoPtr
->hwndSelf
, hdc
);
555 if ((style
& TTS_BALLOON
) || infoPtr
->pszTitle
)
557 lpSize
->cx
= max(rc
.right
- rc
.left
, title
.cx
) + 2*BALLOON_TEXT_MARGIN
+
558 infoPtr
->rcMargin
.left
+ infoPtr
->rcMargin
.right
;
559 lpSize
->cy
= title
.cy
+ rc
.bottom
- rc
.top
+ 2*BALLOON_TEXT_MARGIN
+
560 infoPtr
->rcMargin
.bottom
+ infoPtr
->rcMargin
.top
+
565 lpSize
->cx
= rc
.right
- rc
.left
+ 2*NORMAL_TEXT_MARGIN
+
566 infoPtr
->rcMargin
.left
+ infoPtr
->rcMargin
.right
;
567 lpSize
->cy
= rc
.bottom
- rc
.top
+ 2*NORMAL_TEXT_MARGIN
+
568 infoPtr
->rcMargin
.bottom
+ infoPtr
->rcMargin
.top
;
574 TOOLTIPS_Show (TOOLTIPS_INFO
*infoPtr
, BOOL track_activate
)
576 TTTOOL_INFO
*toolPtr
;
578 MONITORINFO mon_info
;
583 DWORD style
= GetWindowLongW(infoPtr
->hwndSelf
, GWL_STYLE
);
588 if (infoPtr
->nTrackTool
== -1)
590 TRACE("invalid tracking tool %d\n", infoPtr
->nTrackTool
);
593 nTool
= infoPtr
->nTrackTool
;
597 if (infoPtr
->nTool
== -1)
599 TRACE("invalid tool %d\n", infoPtr
->nTool
);
602 nTool
= infoPtr
->nTool
;
605 TRACE("Show tooltip pre %d, %p\n", nTool
, infoPtr
->hwndSelf
);
607 current
= infoPtr
->nCurrentTool
;
609 infoPtr
->nCurrentTool
= infoPtr
->nTool
;
611 TOOLTIPS_GetTipText (infoPtr
, nTool
, infoPtr
->szTipText
);
613 if (infoPtr
->szTipText
[0] == '\0')
615 infoPtr
->nCurrentTool
= current
;
619 toolPtr
= &infoPtr
->tools
[nTool
];
620 TOOLTIPS_CalcTipSize (infoPtr
, &size
);
622 TRACE("Show tooltip %d, %s, size %ld x %ld\n", nTool
, debugstr_w(infoPtr
->szTipText
),
625 if (track_activate
&& (toolPtr
->uFlags
& TTF_TRACK
))
627 rect
.left
= infoPtr
->xTrackPos
;
628 rect
.top
= infoPtr
->yTrackPos
;
631 if (toolPtr
->uFlags
& TTF_CENTERTIP
)
633 rect
.left
-= (size
.cx
/ 2);
634 if (!(style
& TTS_BALLOON
))
635 rect
.top
-= (size
.cy
/ 2);
637 if (!(infoPtr
->bToolBelow
= (infoPtr
->yTrackPos
+ size
.cy
<= GetSystemMetrics(SM_CYSCREEN
))))
640 if (!(toolPtr
->uFlags
& TTF_ABSOLUTE
))
642 if (style
& TTS_BALLOON
)
643 rect
.left
-= BALLOON_STEMINDENT
;
648 if (toolPtr
->uFlags
& TTF_IDISHWND
)
649 GetWindowRect ((HWND
)toolPtr
->uId
, &rcTool
);
652 rcTool
= toolPtr
->rect
;
653 MapWindowPoints (toolPtr
->hwnd
, NULL
, (LPPOINT
)&rcTool
, 2);
656 /* smart placement */
657 if ((rect
.left
+ size
.cx
> rcTool
.left
) && (rect
.left
< rcTool
.right
) &&
658 (rect
.top
+ size
.cy
> rcTool
.top
) && (rect
.top
< rcTool
.bottom
))
659 rect
.left
= rcTool
.right
;
665 if (toolPtr
->uFlags
& TTF_CENTERTIP
)
669 if (toolPtr
->uFlags
& TTF_IDISHWND
)
670 GetWindowRect ((HWND
)toolPtr
->uId
, &rc
);
673 MapWindowPoints (toolPtr
->hwnd
, NULL
, (LPPOINT
)&rc
, 2);
675 rect
.left
= (rc
.left
+ rc
.right
- size
.cx
) / 2;
676 if (style
& TTS_BALLOON
)
678 ptfx
= rc
.left
+ ((rc
.right
- rc
.left
) / 2);
680 /* CENTERTIP ballon tooltips default to below the field
681 * if they fit on the screen */
682 if (rc
.bottom
+ size
.cy
> GetSystemMetrics(SM_CYSCREEN
))
684 rect
.top
= rc
.top
- size
.cy
;
685 infoPtr
->bToolBelow
= FALSE
;
689 infoPtr
->bToolBelow
= TRUE
;
690 rect
.top
= rc
.bottom
;
692 rect
.left
= max(0, rect
.left
- BALLOON_STEMINDENT
);
696 rect
.top
= rc
.bottom
+ 2;
697 infoPtr
->bToolBelow
= TRUE
;
702 GetCursorPos ((LPPOINT
)&rect
);
703 if (style
& TTS_BALLOON
)
706 if(rect
.top
- size
.cy
>= 0)
709 infoPtr
->bToolBelow
= FALSE
;
713 infoPtr
->bToolBelow
= TRUE
;
716 rect
.left
= max(0, rect
.left
- BALLOON_STEMINDENT
);
721 infoPtr
->bToolBelow
= TRUE
;
726 TRACE("pos %ld - %ld\n", rect
.left
, rect
.top
);
728 rect
.right
= rect
.left
+ size
.cx
;
729 rect
.bottom
= rect
.top
+ size
.cy
;
733 monitor
= MonitorFromRect( &rect
, MONITOR_DEFAULTTOPRIMARY
);
734 mon_info
.cbSize
= sizeof(mon_info
);
735 GetMonitorInfoW( monitor
, &mon_info
);
737 if( rect
.right
> mon_info
.rcWork
.right
) {
738 rect
.left
-= rect
.right
- mon_info
.rcWork
.right
+ 2;
739 rect
.right
= mon_info
.rcWork
.right
- 2;
741 if (rect
.left
< mon_info
.rcWork
.left
) rect
.left
= mon_info
.rcWork
.left
;
743 if( rect
.bottom
> mon_info
.rcWork
.bottom
) {
746 if (toolPtr
->uFlags
& TTF_IDISHWND
)
747 GetWindowRect ((HWND
)toolPtr
->uId
, &rc
);
750 MapWindowPoints (toolPtr
->hwnd
, NULL
, (LPPOINT
)&rc
, 2);
752 rect
.bottom
= rc
.top
- 2;
753 rect
.top
= rect
.bottom
- size
.cy
;
756 AdjustWindowRectEx (&rect
, GetWindowLongW (infoPtr
->hwndSelf
, GWL_STYLE
),
757 FALSE
, GetWindowLongW (infoPtr
->hwndSelf
, GWL_EXSTYLE
));
759 if (style
& TTS_BALLOON
)
767 if(infoPtr
->bToolBelow
)
771 pts
[1].x
= max(BALLOON_STEMINDENT
, ptfx
- (BALLOON_STEMWIDTH
/ 2));
772 pts
[1].y
= BALLOON_STEMHEIGHT
;
773 pts
[2].x
= pts
[1].x
+ BALLOON_STEMWIDTH
;
775 if(pts
[2].x
> (rect
.right
- rect
.left
) - BALLOON_STEMINDENT
)
777 pts
[2].x
= (rect
.right
- rect
.left
) - BALLOON_STEMINDENT
;
778 pts
[1].x
= pts
[2].x
- BALLOON_STEMWIDTH
;
783 pts
[0].x
= max(BALLOON_STEMINDENT
, ptfx
- (BALLOON_STEMWIDTH
/ 2));
784 pts
[0].y
= (rect
.bottom
- rect
.top
) - BALLOON_STEMHEIGHT
;
785 pts
[1].x
= pts
[0].x
+ BALLOON_STEMWIDTH
;
788 pts
[2].y
= (rect
.bottom
- rect
.top
);
789 if(pts
[1].x
> (rect
.right
- rect
.left
) - BALLOON_STEMINDENT
)
791 pts
[1].x
= (rect
.right
- rect
.left
) - BALLOON_STEMINDENT
;
792 pts
[0].x
= pts
[1].x
- BALLOON_STEMWIDTH
;
796 hrStem
= CreatePolygonRgn(pts
, ARRAY_SIZE(pts
), ALTERNATE
);
798 hRgn
= CreateRoundRectRgn(0,
799 (infoPtr
->bToolBelow
? BALLOON_STEMHEIGHT
: 0),
800 rect
.right
- rect
.left
,
801 (infoPtr
->bToolBelow
? rect
.bottom
- rect
.top
: rect
.bottom
- rect
.top
- BALLOON_STEMHEIGHT
),
802 BALLOON_ROUNDEDNESS
, BALLOON_ROUNDEDNESS
);
804 CombineRgn(hRgn
, hRgn
, hrStem
, RGN_OR
);
805 DeleteObject(hrStem
);
807 SetWindowRgn(infoPtr
->hwndSelf
, hRgn
, FALSE
);
808 /* we don't free the region handle as the system deletes it when
809 * it is no longer needed */
812 SetWindowPos (infoPtr
->hwndSelf
, NULL
, rect
.left
, rect
.top
,
813 rect
.right
- rect
.left
, rect
.bottom
- rect
.top
, SWP_NOZORDER
| SWP_NOACTIVATE
);
815 hdr
.hwndFrom
= infoPtr
->hwndSelf
;
816 hdr
.idFrom
= toolPtr
->uId
;
818 SendMessageW (toolPtr
->hwnd
, WM_NOTIFY
, toolPtr
->uId
, (LPARAM
)&hdr
);
820 SetWindowPos (infoPtr
->hwndSelf
, HWND_TOPMOST
, 0, 0, 0, 0,
821 SWP_NOSIZE
| SWP_NOMOVE
| SWP_SHOWWINDOW
| SWP_NOACTIVATE
);
823 /* repaint the tooltip */
824 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
825 UpdateWindow(infoPtr
->hwndSelf
);
829 SetTimer (infoPtr
->hwndSelf
, ID_TIMERPOP
, infoPtr
->nAutoPopTime
, 0);
830 TRACE("timer 2 started\n");
831 SetTimer (infoPtr
->hwndSelf
, ID_TIMERLEAVE
, infoPtr
->nReshowTime
, 0);
832 TRACE("timer 3 started\n");
838 TOOLTIPS_Hide (TOOLTIPS_INFO
*infoPtr
)
840 TTTOOL_INFO
*toolPtr
;
843 TRACE("Hide tooltip %d, %p.\n", infoPtr
->nCurrentTool
, infoPtr
->hwndSelf
);
845 if (infoPtr
->nCurrentTool
== -1)
848 toolPtr
= &infoPtr
->tools
[infoPtr
->nCurrentTool
];
849 KillTimer (infoPtr
->hwndSelf
, ID_TIMERPOP
);
851 hdr
.hwndFrom
= infoPtr
->hwndSelf
;
852 hdr
.idFrom
= toolPtr
->uId
;
854 SendMessageW (toolPtr
->hwnd
, WM_NOTIFY
, toolPtr
->uId
, (LPARAM
)&hdr
);
856 infoPtr
->nCurrentTool
= -1;
858 SetWindowPos (infoPtr
->hwndSelf
, HWND_TOP
, 0, 0, 0, 0,
859 SWP_NOZORDER
| SWP_HIDEWINDOW
| SWP_NOACTIVATE
);
864 TOOLTIPS_TrackShow (TOOLTIPS_INFO
*infoPtr
)
866 TOOLTIPS_Show(infoPtr
, TRUE
);
871 TOOLTIPS_TrackHide (const TOOLTIPS_INFO
*infoPtr
)
873 TTTOOL_INFO
*toolPtr
;
876 TRACE("hide tracking tooltip %d\n", infoPtr
->nTrackTool
);
878 if (infoPtr
->nTrackTool
== -1)
881 toolPtr
= &infoPtr
->tools
[infoPtr
->nTrackTool
];
883 hdr
.hwndFrom
= infoPtr
->hwndSelf
;
884 hdr
.idFrom
= toolPtr
->uId
;
886 SendMessageW (toolPtr
->hwnd
, WM_NOTIFY
, toolPtr
->uId
, (LPARAM
)&hdr
);
888 SetWindowPos (infoPtr
->hwndSelf
, HWND_TOP
, 0, 0, 0, 0,
889 SWP_NOZORDER
| SWP_HIDEWINDOW
| SWP_NOACTIVATE
);
892 /* Structure layout is the same for TTTOOLINFOW and TTTOOLINFOA,
893 this helper is used in both cases. */
895 TOOLTIPS_GetToolFromInfoT (const TOOLTIPS_INFO
*infoPtr
, const TTTOOLINFOW
*lpToolInfo
)
897 TTTOOL_INFO
*toolPtr
;
900 for (nTool
= 0; nTool
< infoPtr
->uNumTools
; nTool
++) {
901 toolPtr
= &infoPtr
->tools
[nTool
];
903 if (!(toolPtr
->uFlags
& TTF_IDISHWND
) &&
904 (lpToolInfo
->hwnd
== toolPtr
->hwnd
) &&
905 (lpToolInfo
->uId
== toolPtr
->uId
))
909 for (nTool
= 0; nTool
< infoPtr
->uNumTools
; nTool
++) {
910 toolPtr
= &infoPtr
->tools
[nTool
];
912 if ((toolPtr
->uFlags
& TTF_IDISHWND
) &&
913 (lpToolInfo
->uId
== toolPtr
->uId
))
922 TOOLTIPS_GetToolFromPoint (const TOOLTIPS_INFO
*infoPtr
, HWND hwnd
, const POINT
*lpPt
)
924 TTTOOL_INFO
*toolPtr
;
927 for (nTool
= 0; nTool
< infoPtr
->uNumTools
; nTool
++) {
928 toolPtr
= &infoPtr
->tools
[nTool
];
930 if (!(toolPtr
->uFlags
& TTF_IDISHWND
)) {
931 if (hwnd
!= toolPtr
->hwnd
)
933 if (!PtInRect (&toolPtr
->rect
, *lpPt
))
939 for (nTool
= 0; nTool
< infoPtr
->uNumTools
; nTool
++) {
940 toolPtr
= &infoPtr
->tools
[nTool
];
942 if (toolPtr
->uFlags
& TTF_IDISHWND
) {
943 if ((HWND
)toolPtr
->uId
== hwnd
)
952 TOOLTIPS_CopyInfoT (const TOOLTIPS_INFO
*infoPtr
, INT index
, TTTOOLINFOW
*ti
, BOOL isW
)
954 const TTTOOL_INFO
*toolPtr
= &infoPtr
->tools
[index
];
956 ti
->uFlags
= toolPtr
->uFlags
;
957 ti
->hwnd
= toolPtr
->hwnd
;
958 ti
->uId
= toolPtr
->uId
;
959 ti
->rect
= toolPtr
->rect
;
960 ti
->hinst
= toolPtr
->hinst
;
963 if (toolPtr
->lpszText
== NULL
||
964 IS_INTRESOURCE(toolPtr
->lpszText
) ||
965 toolPtr
->lpszText
== LPSTR_TEXTCALLBACKW
)
966 ti
->lpszText
= toolPtr
->lpszText
;
968 lstrcpyW (ti
->lpszText
, toolPtr
->lpszText
);
970 /* ANSI version, the buffer is maximum 80 bytes without null. */
971 WideCharToMultiByte(CP_ACP
, 0, toolPtr
->lpszText
, -1,
972 (LPSTR
)ti
->lpszText
, MAX_TEXT_SIZE_A
, NULL
, NULL
);
975 if (ti
->cbSize
>= TTTOOLINFOW_V2_SIZE
)
976 ti
->lParam
= toolPtr
->lParam
;
978 /* lpReserved is intentionally not set. */
982 TOOLTIPS_IsWindowActive (HWND hwnd
)
984 HWND hwndActive
= GetActiveWindow ();
987 if (hwndActive
== hwnd
)
989 return IsChild (hwndActive
, hwnd
);
994 TOOLTIPS_CheckTool (const TOOLTIPS_INFO
*infoPtr
, BOOL bShowTest
)
1001 hwndTool
= (HWND
)SendMessageW (infoPtr
->hwndSelf
, TTM_WINDOWFROMPOINT
, 0, (LPARAM
)&pt
);
1005 ScreenToClient (hwndTool
, &pt
);
1006 nTool
= TOOLTIPS_GetToolFromPoint (infoPtr
, hwndTool
, &pt
);
1010 if (!(GetWindowLongW (infoPtr
->hwndSelf
, GWL_STYLE
) & TTS_ALWAYSTIP
) && bShowTest
)
1012 TTTOOL_INFO
*ti
= &infoPtr
->tools
[nTool
];
1013 HWND hwnd
= (ti
->uFlags
& TTF_IDISHWND
) ? (HWND
)ti
->uId
: ti
->hwnd
;
1015 if (!TOOLTIPS_IsWindowActive(hwnd
))
1017 TRACE("not active: hwnd %p, parent %p, active %p\n",
1018 hwnd
, GetParent(hwnd
), GetActiveWindow());
1023 TRACE("tool %d\n", nTool
);
1030 TOOLTIPS_Activate (TOOLTIPS_INFO
*infoPtr
, BOOL activate
)
1032 infoPtr
->bActive
= activate
;
1034 TRACE("activate %d\n", activate
);
1036 if (!(infoPtr
->bActive
) && (infoPtr
->nCurrentTool
!= -1))
1037 TOOLTIPS_Hide (infoPtr
);
1044 TOOLTIPS_AddToolT (TOOLTIPS_INFO
*infoPtr
, const TTTOOLINFOW
*ti
, BOOL isW
)
1046 TTTOOL_INFO
*toolPtr
;
1049 if (!ti
) return FALSE
;
1051 TRACE("add tool (%p) %p %Id%s\n", infoPtr
->hwndSelf
, ti
->hwnd
, ti
->uId
,
1052 (ti
->uFlags
& TTF_IDISHWND
) ? " TTF_IDISHWND" : "");
1054 if (ti
->cbSize
> TTTOOLINFOW_V3_SIZE
&& isW
)
1057 if (infoPtr
->uNumTools
== 0) {
1058 infoPtr
->tools
= Alloc (sizeof(TTTOOL_INFO
));
1059 toolPtr
= infoPtr
->tools
;
1062 TTTOOL_INFO
*oldTools
= infoPtr
->tools
;
1064 Alloc (sizeof(TTTOOL_INFO
) * (infoPtr
->uNumTools
+ 1));
1065 memcpy (infoPtr
->tools
, oldTools
,
1066 infoPtr
->uNumTools
* sizeof(TTTOOL_INFO
));
1068 toolPtr
= &infoPtr
->tools
[infoPtr
->uNumTools
];
1071 infoPtr
->uNumTools
++;
1073 /* copy tool data */
1074 toolPtr
->uFlags
= ti
->uFlags
;
1075 toolPtr
->uInternalFlags
= (ti
->uFlags
& (TTF_SUBCLASS
| TTF_IDISHWND
));
1076 toolPtr
->hwnd
= ti
->hwnd
;
1077 toolPtr
->uId
= ti
->uId
;
1078 toolPtr
->rect
= ti
->rect
;
1079 toolPtr
->hinst
= ti
->hinst
;
1081 if (ti
->cbSize
>= TTTOOLINFOW_V1_SIZE
) {
1082 if (IS_INTRESOURCE(ti
->lpszText
)) {
1083 TRACE("add string id %x\n", LOWORD(ti
->lpszText
));
1084 toolPtr
->lpszText
= ti
->lpszText
;
1086 else if (ti
->lpszText
) {
1087 if (ti
->lpszText
== LPSTR_TEXTCALLBACKW
) {
1088 TRACE("add CALLBACK\n");
1089 toolPtr
->lpszText
= LPSTR_TEXTCALLBACKW
;
1092 INT len
= lstrlenW (ti
->lpszText
);
1093 TRACE("add text %s\n", debugstr_w(ti
->lpszText
));
1094 toolPtr
->lpszText
= Alloc ((len
+ 1)*sizeof(WCHAR
));
1095 lstrcpyW (toolPtr
->lpszText
, ti
->lpszText
);
1098 INT len
= MultiByteToWideChar(CP_ACP
, 0, (LPSTR
)ti
->lpszText
, -1, NULL
, 0);
1099 TRACE("add text \"%s\"\n", debugstr_a((char *)ti
->lpszText
));
1100 toolPtr
->lpszText
= Alloc (len
* sizeof(WCHAR
));
1101 MultiByteToWideChar(CP_ACP
, 0, (LPSTR
)ti
->lpszText
, -1, toolPtr
->lpszText
, len
);
1106 if (ti
->cbSize
>= TTTOOLINFOW_V2_SIZE
)
1107 toolPtr
->lParam
= ti
->lParam
;
1109 /* install subclassing hook */
1110 if (toolPtr
->uInternalFlags
& TTF_SUBCLASS
) {
1111 if (toolPtr
->uInternalFlags
& TTF_IDISHWND
) {
1112 SetWindowSubclass((HWND
)toolPtr
->uId
, TOOLTIPS_SubclassProc
, 1,
1113 (DWORD_PTR
)infoPtr
->hwndSelf
);
1116 SetWindowSubclass(toolPtr
->hwnd
, TOOLTIPS_SubclassProc
, 1,
1117 (DWORD_PTR
)infoPtr
->hwndSelf
);
1119 TRACE("subclassing installed\n");
1122 nResult
= SendMessageW (toolPtr
->hwnd
, WM_NOTIFYFORMAT
,
1123 (WPARAM
)infoPtr
->hwndSelf
, NF_QUERY
);
1124 if (nResult
== NFR_ANSI
) {
1125 toolPtr
->bNotifyUnicode
= FALSE
;
1126 TRACE(" -- WM_NOTIFYFORMAT returns: NFR_ANSI\n");
1127 } else if (nResult
== NFR_UNICODE
) {
1128 toolPtr
->bNotifyUnicode
= TRUE
;
1129 TRACE(" -- WM_NOTIFYFORMAT returns: NFR_UNICODE\n");
1131 TRACE (" -- WM_NOTIFYFORMAT returns: %d\n", nResult
);
1137 static void TOOLTIPS_ResetSubclass (const TTTOOL_INFO
*toolPtr
)
1139 /* Reset subclassing data. */
1140 if (toolPtr
->uInternalFlags
& TTF_SUBCLASS
)
1141 SetWindowSubclass(toolPtr
->uInternalFlags
& TTF_IDISHWND
? (HWND
)toolPtr
->uId
: toolPtr
->hwnd
,
1142 TOOLTIPS_SubclassProc
, 1, 0);
1145 static void TOOLTIPS_FreeToolText(TTTOOL_INFO
*toolPtr
)
1147 if (toolPtr
->lpszText
)
1149 if (!IS_INTRESOURCE(toolPtr
->lpszText
) && toolPtr
->lpszText
!= LPSTR_TEXTCALLBACKW
)
1150 Free(toolPtr
->lpszText
);
1151 toolPtr
->lpszText
= NULL
;
1155 static void TOOLTIPS_SetToolText(TTTOOL_INFO
*toolPtr
, WCHAR
*text
, BOOL is_unicode
)
1159 TOOLTIPS_FreeToolText (toolPtr
);
1161 if (IS_INTRESOURCE(text
))
1162 toolPtr
->lpszText
= text
;
1163 else if (text
== LPSTR_TEXTCALLBACKW
)
1164 toolPtr
->lpszText
= LPSTR_TEXTCALLBACKW
;
1169 len
= lstrlenW(text
);
1170 toolPtr
->lpszText
= Alloc ((len
+ 1) * sizeof(WCHAR
));
1171 if (toolPtr
->lpszText
)
1172 lstrcpyW (toolPtr
->lpszText
, text
);
1176 len
= MultiByteToWideChar(CP_ACP
, 0, (char *)text
, -1, NULL
, 0);
1177 toolPtr
->lpszText
= Alloc (len
* sizeof(WCHAR
));
1178 if (toolPtr
->lpszText
)
1179 MultiByteToWideChar(CP_ACP
, 0, (char *)text
, -1, toolPtr
->lpszText
, len
);
1185 TOOLTIPS_DelToolT (TOOLTIPS_INFO
*infoPtr
, const TTTOOLINFOW
*ti
, BOOL isW
)
1187 TTTOOL_INFO
*toolPtr
;
1191 if (isW
&& ti
->cbSize
> TTTOOLINFOW_V2_SIZE
&&
1192 ti
->cbSize
!= TTTOOLINFOW_V3_SIZE
)
1194 if (infoPtr
->uNumTools
== 0)
1197 nTool
= TOOLTIPS_GetToolFromInfoT (infoPtr
, ti
);
1199 TRACE("tool %d\n", nTool
);
1204 /* make sure the tooltip has disappeared before deleting it */
1205 TOOLTIPS_Hide(infoPtr
);
1207 toolPtr
= &infoPtr
->tools
[nTool
];
1208 TOOLTIPS_FreeToolText (toolPtr
);
1209 TOOLTIPS_ResetSubclass (toolPtr
);
1211 /* delete tool from tool list */
1212 if (infoPtr
->uNumTools
== 1) {
1213 Free (infoPtr
->tools
);
1214 infoPtr
->tools
= NULL
;
1217 TTTOOL_INFO
*oldTools
= infoPtr
->tools
;
1219 Alloc (sizeof(TTTOOL_INFO
) * (infoPtr
->uNumTools
- 1));
1222 memcpy (&infoPtr
->tools
[0], &oldTools
[0],
1223 nTool
* sizeof(TTTOOL_INFO
));
1225 if (nTool
< infoPtr
->uNumTools
- 1)
1226 memcpy (&infoPtr
->tools
[nTool
], &oldTools
[nTool
+ 1],
1227 (infoPtr
->uNumTools
- nTool
- 1) * sizeof(TTTOOL_INFO
));
1232 /* update any indices affected by delete */
1234 /* destroying tool that mouse was on on last relayed mouse move */
1235 if (infoPtr
->nTool
== nTool
)
1236 /* -1 means no current tool (0 means first tool) */
1237 infoPtr
->nTool
= -1;
1238 else if (infoPtr
->nTool
> nTool
)
1241 if (infoPtr
->nTrackTool
== nTool
)
1242 /* -1 means no current tool (0 means first tool) */
1243 infoPtr
->nTrackTool
= -1;
1244 else if (infoPtr
->nTrackTool
> nTool
)
1245 infoPtr
->nTrackTool
--;
1247 if (infoPtr
->nCurrentTool
== nTool
)
1248 /* -1 means no current tool (0 means first tool) */
1249 infoPtr
->nCurrentTool
= -1;
1250 else if (infoPtr
->nCurrentTool
> nTool
)
1251 infoPtr
->nCurrentTool
--;
1253 infoPtr
->uNumTools
--;
1259 TOOLTIPS_EnumToolsT (const TOOLTIPS_INFO
*infoPtr
, UINT uIndex
, TTTOOLINFOW
*ti
,
1262 if (!ti
|| ti
->cbSize
< TTTOOLINFOW_V1_SIZE
)
1264 if (uIndex
>= infoPtr
->uNumTools
)
1267 TRACE("index=%u\n", uIndex
);
1269 TOOLTIPS_CopyInfoT (infoPtr
, uIndex
, ti
, isW
);
1275 TOOLTIPS_GetBubbleSize (const TOOLTIPS_INFO
*infoPtr
, const TTTOOLINFOW
*lpToolInfo
)
1280 if (lpToolInfo
== NULL
)
1282 if (lpToolInfo
->cbSize
< TTTOOLINFOW_V1_SIZE
)
1285 nTool
= TOOLTIPS_GetToolFromInfoT (infoPtr
, lpToolInfo
);
1286 if (nTool
== -1) return 0;
1288 TRACE("tool %d\n", nTool
);
1290 TOOLTIPS_CalcTipSize (infoPtr
, &size
);
1291 TRACE("size %ld x %ld\n", size
.cx
, size
.cy
);
1293 return MAKELRESULT(size
.cx
, size
.cy
);
1297 TOOLTIPS_GetCurrentToolT (const TOOLTIPS_INFO
*infoPtr
, TTTOOLINFOW
*ti
, BOOL isW
)
1300 if (ti
->cbSize
< TTTOOLINFOW_V1_SIZE
)
1303 if (infoPtr
->nCurrentTool
!= -1)
1304 TOOLTIPS_CopyInfoT (infoPtr
, infoPtr
->nCurrentTool
, ti
, isW
);
1307 return infoPtr
->nCurrentTool
!= -1;
1312 TOOLTIPS_GetDelayTime (const TOOLTIPS_INFO
*infoPtr
, DWORD duration
)
1316 return infoPtr
->nReshowTime
;
1319 return infoPtr
->nAutoPopTime
;
1322 case TTDT_AUTOMATIC
: /* Apparently TTDT_AUTOMATIC returns TTDT_INITIAL */
1323 return infoPtr
->nInitialTime
;
1326 WARN("Invalid duration flag %lx\n", duration
);
1335 TOOLTIPS_GetMargin (const TOOLTIPS_INFO
*infoPtr
, RECT
*rect
)
1338 *rect
= infoPtr
->rcMargin
;
1344 static inline LRESULT
1345 TOOLTIPS_GetMaxTipWidth (const TOOLTIPS_INFO
*infoPtr
)
1347 return infoPtr
->nMaxTipWidth
;
1352 TOOLTIPS_GetTextT (const TOOLTIPS_INFO
*infoPtr
, TTTOOLINFOW
*ti
, BOOL isW
)
1357 if (ti
->cbSize
< TTTOOLINFOW_V1_SIZE
)
1360 nTool
= TOOLTIPS_GetToolFromInfoT (infoPtr
, ti
);
1361 if (nTool
== -1) return 0;
1363 if (infoPtr
->tools
[nTool
].lpszText
== NULL
)
1367 ti
->lpszText
[0] = '\0';
1368 TOOLTIPS_GetTipText(infoPtr
, nTool
, ti
->lpszText
);
1371 WCHAR buffer
[INFOTIPSIZE
];
1373 /* NB this API is broken, there is no way for the app to determine
1374 what size buffer it requires nor a way to specify how long the
1375 one it supplies is. According to the test result, it's up to
1376 80 bytes by the ANSI version. */
1379 TOOLTIPS_GetTipText(infoPtr
, nTool
, buffer
);
1380 WideCharToMultiByte(CP_ACP
, 0, buffer
, -1, (LPSTR
)ti
->lpszText
,
1381 MAX_TEXT_SIZE_A
, NULL
, NULL
);
1388 static inline LRESULT
1389 TOOLTIPS_GetTipBkColor (const TOOLTIPS_INFO
*infoPtr
)
1391 return infoPtr
->clrBk
;
1395 static inline LRESULT
1396 TOOLTIPS_GetTipTextColor (const TOOLTIPS_INFO
*infoPtr
)
1398 return infoPtr
->clrText
;
1402 static inline LRESULT
1403 TOOLTIPS_GetToolCount (const TOOLTIPS_INFO
*infoPtr
)
1405 return infoPtr
->uNumTools
;
1410 TOOLTIPS_GetToolInfoT (const TOOLTIPS_INFO
*infoPtr
, TTTOOLINFOW
*ti
, BOOL isW
)
1415 if (!ti
) return FALSE
;
1416 if (ti
->cbSize
< TTTOOLINFOW_V1_SIZE
)
1418 if (infoPtr
->uNumTools
== 0)
1421 nTool
= TOOLTIPS_GetToolFromInfoT (infoPtr
, ti
);
1425 TRACE("tool %d\n", nTool
);
1428 TOOLTIPS_CopyInfoT (infoPtr
, nTool
, ti
, isW
);
1436 TOOLTIPS_HitTestT (const TOOLTIPS_INFO
*infoPtr
, LPTTHITTESTINFOW lptthit
,
1444 nTool
= TOOLTIPS_GetToolFromPoint (infoPtr
, lptthit
->hwnd
, &lptthit
->pt
);
1448 TRACE("tool %d\n", nTool
);
1450 /* copy tool data */
1451 if (lptthit
->ti
.cbSize
>= TTTOOLINFOW_V1_SIZE
)
1452 TOOLTIPS_CopyInfoT (infoPtr
, nTool
, &lptthit
->ti
, isW
);
1459 TOOLTIPS_NewToolRectT (TOOLTIPS_INFO
*infoPtr
, const TTTOOLINFOW
*ti
)
1464 if (ti
->cbSize
< TTTOOLINFOW_V1_SIZE
)
1467 nTool
= TOOLTIPS_GetToolFromInfoT (infoPtr
, ti
);
1469 TRACE("nTool = %d, rect = %s\n", nTool
, wine_dbgstr_rect(&ti
->rect
));
1471 if (nTool
== -1) return 0;
1473 infoPtr
->tools
[nTool
].rect
= ti
->rect
;
1479 static inline LRESULT
1480 TOOLTIPS_Pop (TOOLTIPS_INFO
*infoPtr
)
1482 TOOLTIPS_Hide (infoPtr
);
1489 TOOLTIPS_RelayEvent (TOOLTIPS_INFO
*infoPtr
, LPMSG lpMsg
)
1495 ERR("lpMsg == NULL\n");
1499 switch (lpMsg
->message
) {
1500 case WM_LBUTTONDOWN
:
1502 case WM_MBUTTONDOWN
:
1504 case WM_RBUTTONDOWN
:
1506 TOOLTIPS_Hide (infoPtr
);
1510 pt
.x
= (short)LOWORD(lpMsg
->lParam
);
1511 pt
.y
= (short)HIWORD(lpMsg
->lParam
);
1512 nOldTool
= infoPtr
->nTool
;
1513 infoPtr
->nTool
= TOOLTIPS_GetToolFromPoint(infoPtr
, lpMsg
->hwnd
,
1515 TRACE("tool (%p) %d %d %d\n", infoPtr
->hwndSelf
, nOldTool
,
1516 infoPtr
->nTool
, infoPtr
->nCurrentTool
);
1517 TRACE("WM_MOUSEMOVE (%p %s)\n", infoPtr
->hwndSelf
, wine_dbgstr_point(&pt
));
1519 if (infoPtr
->nTool
!= nOldTool
) {
1520 if(infoPtr
->nTool
== -1) { /* Moved out of all tools */
1521 TOOLTIPS_Hide(infoPtr
);
1522 KillTimer(infoPtr
->hwndSelf
, ID_TIMERLEAVE
);
1523 } else if (nOldTool
== -1) { /* Moved from outside */
1524 if(infoPtr
->bActive
) {
1525 SetTimer(infoPtr
->hwndSelf
, ID_TIMERSHOW
, infoPtr
->nInitialTime
, 0);
1526 TRACE("timer 1 started\n");
1528 } else { /* Moved from one to another */
1529 TOOLTIPS_Hide (infoPtr
);
1530 KillTimer(infoPtr
->hwndSelf
, ID_TIMERLEAVE
);
1531 if(infoPtr
->bActive
) {
1532 SetTimer (infoPtr
->hwndSelf
, ID_TIMERSHOW
, infoPtr
->nReshowTime
, 0);
1533 TRACE("timer 1 started\n");
1536 } else if(infoPtr
->nCurrentTool
!= -1) { /* restart autopop */
1537 KillTimer(infoPtr
->hwndSelf
, ID_TIMERPOP
);
1538 SetTimer(infoPtr
->hwndSelf
, ID_TIMERPOP
, infoPtr
->nAutoPopTime
, 0);
1539 TRACE("timer 2 restarted\n");
1540 } else if(infoPtr
->nTool
!= -1 && infoPtr
->bActive
) {
1541 /* previous show attempt didn't result in tooltip so try again */
1542 SetTimer(infoPtr
->hwndSelf
, ID_TIMERSHOW
, infoPtr
->nInitialTime
, 0);
1543 TRACE("timer 1 started\n");
1553 TOOLTIPS_SetDelayTime (TOOLTIPS_INFO
*infoPtr
, DWORD duration
, INT nTime
)
1556 case TTDT_AUTOMATIC
:
1558 nTime
= GetDoubleClickTime();
1559 infoPtr
->nReshowTime
= nTime
/ 5;
1560 infoPtr
->nAutoPopTime
= nTime
* 10;
1561 infoPtr
->nInitialTime
= nTime
;
1566 nTime
= GetDoubleClickTime() / 5;
1567 infoPtr
->nReshowTime
= nTime
;
1572 nTime
= GetDoubleClickTime() * 10;
1573 infoPtr
->nAutoPopTime
= nTime
;
1578 nTime
= GetDoubleClickTime();
1579 infoPtr
->nInitialTime
= nTime
;
1583 WARN("Invalid duration flag %lx\n", duration
);
1592 TOOLTIPS_SetMargin (TOOLTIPS_INFO
*infoPtr
, const RECT
*rect
)
1595 infoPtr
->rcMargin
= *rect
;
1601 static inline LRESULT
1602 TOOLTIPS_SetMaxTipWidth (TOOLTIPS_INFO
*infoPtr
, INT MaxWidth
)
1604 INT nTemp
= infoPtr
->nMaxTipWidth
;
1606 infoPtr
->nMaxTipWidth
= MaxWidth
;
1612 static inline LRESULT
1613 TOOLTIPS_SetTipBkColor (TOOLTIPS_INFO
*infoPtr
, COLORREF clrBk
)
1615 infoPtr
->clrBk
= clrBk
;
1621 static inline LRESULT
1622 TOOLTIPS_SetTipTextColor (TOOLTIPS_INFO
*infoPtr
, COLORREF clrText
)
1624 infoPtr
->clrText
= clrText
;
1631 TOOLTIPS_SetTitleT (TOOLTIPS_INFO
*infoPtr
, UINT_PTR uTitleIcon
, LPCWSTR pszTitle
,
1636 TRACE("hwnd = %p, title = %s, icon = %p\n", infoPtr
->hwndSelf
, debugstr_w(pszTitle
),
1639 Free(infoPtr
->pszTitle
);
1645 size
= (lstrlenW(pszTitle
)+1)*sizeof(WCHAR
);
1646 infoPtr
->pszTitle
= Alloc(size
);
1647 if (!infoPtr
->pszTitle
)
1649 memcpy(infoPtr
->pszTitle
, pszTitle
, size
);
1653 size
= sizeof(WCHAR
)*MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)pszTitle
, -1, NULL
, 0);
1654 infoPtr
->pszTitle
= Alloc(size
);
1655 if (!infoPtr
->pszTitle
)
1657 MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)pszTitle
, -1, infoPtr
->pszTitle
, size
/sizeof(WCHAR
));
1661 infoPtr
->pszTitle
= NULL
;
1663 if (uTitleIcon
<= TTI_ERROR
)
1664 infoPtr
->hTitleIcon
= hTooltipIcons
[uTitleIcon
];
1666 infoPtr
->hTitleIcon
= CopyIcon((HICON
)uTitleIcon
);
1668 TRACE("icon = %p\n", infoPtr
->hTitleIcon
);
1674 TOOLTIPS_SetToolInfoT (TOOLTIPS_INFO
*infoPtr
, const TTTOOLINFOW
*ti
, BOOL isW
)
1676 TTTOOL_INFO
*toolPtr
;
1680 if (ti
->cbSize
< TTTOOLINFOW_V1_SIZE
)
1683 nTool
= TOOLTIPS_GetToolFromInfoT (infoPtr
, ti
);
1684 if (nTool
== -1) return 0;
1686 TRACE("tool %d\n", nTool
);
1688 toolPtr
= &infoPtr
->tools
[nTool
];
1690 /* copy tool data */
1691 toolPtr
->uFlags
= ti
->uFlags
;
1692 toolPtr
->hwnd
= ti
->hwnd
;
1693 toolPtr
->uId
= ti
->uId
;
1694 toolPtr
->rect
= ti
->rect
;
1695 toolPtr
->hinst
= ti
->hinst
;
1697 TOOLTIPS_SetToolText (toolPtr
, ti
->lpszText
, isW
);
1699 if (ti
->cbSize
>= TTTOOLINFOW_V2_SIZE
)
1700 toolPtr
->lParam
= ti
->lParam
;
1702 if (infoPtr
->nCurrentTool
== nTool
)
1704 TOOLTIPS_GetTipText (infoPtr
, infoPtr
->nCurrentTool
, infoPtr
->szTipText
);
1706 if (infoPtr
->szTipText
[0] == 0)
1707 TOOLTIPS_Hide(infoPtr
);
1709 TOOLTIPS_Show (infoPtr
, FALSE
);
1717 TOOLTIPS_TrackActivate (TOOLTIPS_INFO
*infoPtr
, BOOL track_activate
, const TTTOOLINFOA
*ti
)
1719 if (track_activate
) {
1722 if (ti
->cbSize
< TTTOOLINFOA_V1_SIZE
)
1726 infoPtr
->nTrackTool
= TOOLTIPS_GetToolFromInfoT (infoPtr
, (const TTTOOLINFOW
*)ti
);
1727 if (infoPtr
->nTrackTool
!= -1) {
1728 TRACE("activated\n");
1729 infoPtr
->bTrackActive
= TRUE
;
1730 TOOLTIPS_TrackShow (infoPtr
);
1735 TOOLTIPS_TrackHide (infoPtr
);
1737 infoPtr
->bTrackActive
= FALSE
;
1738 infoPtr
->nTrackTool
= -1;
1740 TRACE("deactivated\n");
1748 TOOLTIPS_TrackPosition (TOOLTIPS_INFO
*infoPtr
, LPARAM coord
)
1750 infoPtr
->xTrackPos
= (INT
)LOWORD(coord
);
1751 infoPtr
->yTrackPos
= (INT
)HIWORD(coord
);
1753 if (infoPtr
->bTrackActive
) {
1755 infoPtr
->xTrackPos
, infoPtr
->yTrackPos
);
1757 TOOLTIPS_TrackShow (infoPtr
);
1765 TOOLTIPS_Update (TOOLTIPS_INFO
*infoPtr
)
1767 if (infoPtr
->nCurrentTool
!= -1)
1768 UpdateWindow (infoPtr
->hwndSelf
);
1775 TOOLTIPS_UpdateTipTextT (TOOLTIPS_INFO
*infoPtr
, const TTTOOLINFOW
*ti
, BOOL isW
)
1777 TTTOOL_INFO
*toolPtr
;
1781 if (ti
->cbSize
< TTTOOLINFOW_V1_SIZE
)
1784 nTool
= TOOLTIPS_GetToolFromInfoT (infoPtr
, ti
);
1788 TRACE("tool %d\n", nTool
);
1790 toolPtr
= &infoPtr
->tools
[nTool
];
1792 toolPtr
->hinst
= ti
->hinst
;
1794 TOOLTIPS_SetToolText(toolPtr
, ti
->lpszText
, isW
);
1796 if(infoPtr
->nCurrentTool
== -1) return 0;
1798 if (infoPtr
->bActive
)
1799 TOOLTIPS_Show (infoPtr
, FALSE
);
1800 else if (infoPtr
->bTrackActive
)
1801 TOOLTIPS_Show (infoPtr
, TRUE
);
1808 TOOLTIPS_Create (HWND hwnd
)
1810 TOOLTIPS_INFO
*infoPtr
;
1812 /* allocate memory for info structure */
1813 infoPtr
= Alloc (sizeof(TOOLTIPS_INFO
));
1814 SetWindowLongPtrW (hwnd
, 0, (DWORD_PTR
)infoPtr
);
1816 /* initialize info structure */
1817 infoPtr
->bActive
= TRUE
;
1818 infoPtr
->bTrackActive
= FALSE
;
1820 infoPtr
->nMaxTipWidth
= -1;
1821 infoPtr
->nTool
= -1;
1822 infoPtr
->nCurrentTool
= -1;
1823 infoPtr
->nTrackTool
= -1;
1824 infoPtr
->hwndSelf
= hwnd
;
1826 /* initialize colours and fonts */
1827 TOOLTIPS_InitSystemSettings(infoPtr
);
1829 TOOLTIPS_SetDelayTime(infoPtr
, TTDT_AUTOMATIC
, 0);
1831 SetWindowPos (hwnd
, HWND_TOP
, 0, 0, 0, 0, SWP_NOZORDER
| SWP_HIDEWINDOW
| SWP_NOACTIVATE
);
1838 TOOLTIPS_Destroy (TOOLTIPS_INFO
*infoPtr
)
1840 TTTOOL_INFO
*toolPtr
;
1843 for (i
= 0; i
< infoPtr
->uNumTools
; i
++)
1845 toolPtr
= &infoPtr
->tools
[i
];
1847 TOOLTIPS_FreeToolText (toolPtr
);
1848 TOOLTIPS_ResetSubclass (toolPtr
);
1851 Free (infoPtr
->tools
);
1853 /* free title string */
1854 Free (infoPtr
->pszTitle
);
1855 /* free title icon if not a standard one */
1856 if (TOOLTIPS_GetTitleIconIndex(infoPtr
->hTitleIcon
) > TTI_ERROR
)
1857 DeleteObject(infoPtr
->hTitleIcon
);
1860 DeleteObject (infoPtr
->hStatusFont
);
1861 DeleteObject (infoPtr
->hTitleFont
);
1863 /* free tool tips info data */
1864 SetWindowLongPtrW(infoPtr
->hwndSelf
, 0, 0);
1871 static inline LRESULT
1872 TOOLTIPS_GetFont (const TOOLTIPS_INFO
*infoPtr
)
1874 return (LRESULT
)infoPtr
->hFont
;
1879 TOOLTIPS_MouseMessage (TOOLTIPS_INFO
*infoPtr
)
1881 TOOLTIPS_Hide (infoPtr
);
1888 TOOLTIPS_NCCreate (HWND hwnd
)
1890 DWORD dwStyle
= GetWindowLongW (hwnd
, GWL_STYLE
);
1891 DWORD dwExStyle
= GetWindowLongW (hwnd
, GWL_EXSTYLE
);
1893 dwStyle
&= ~(WS_CHILD
| /*WS_MAXIMIZE |*/ WS_BORDER
| WS_DLGFRAME
);
1894 dwStyle
|= (WS_POPUP
| WS_BORDER
| WS_CLIPSIBLINGS
);
1896 /* WS_BORDER only draws a border round the window rect, not the
1897 * window region, therefore it is useless to us in balloon mode */
1898 if (dwStyle
& TTS_BALLOON
) dwStyle
&= ~WS_BORDER
;
1900 SetWindowLongW (hwnd
, GWL_STYLE
, dwStyle
);
1902 dwExStyle
|= WS_EX_TOOLWINDOW
;
1903 SetWindowLongW (hwnd
, GWL_EXSTYLE
, dwExStyle
);
1910 TOOLTIPS_NCHitTest (const TOOLTIPS_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
1912 INT nTool
= (infoPtr
->bTrackActive
) ? infoPtr
->nTrackTool
: infoPtr
->nTool
;
1914 TRACE(" nTool=%d\n", nTool
);
1916 if ((nTool
> -1) && (nTool
< infoPtr
->uNumTools
)) {
1917 if (infoPtr
->tools
[nTool
].uFlags
& TTF_TRANSPARENT
) {
1918 TRACE("-- in transparent mode\n");
1919 return HTTRANSPARENT
;
1923 return DefWindowProcW (infoPtr
->hwndSelf
, WM_NCHITTEST
, wParam
, lParam
);
1928 TOOLTIPS_NotifyFormat (TOOLTIPS_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
1930 FIXME("hwnd %p, wParam %Ix, lParam %Ix\n", infoPtr
->hwndSelf
, wParam
, lParam
);
1937 TOOLTIPS_Paint (const TOOLTIPS_INFO
*infoPtr
, HDC hDC
)
1942 hdc
= (hDC
== NULL
) ? BeginPaint (infoPtr
->hwndSelf
, &ps
) : hDC
;
1943 TOOLTIPS_Refresh (infoPtr
, hdc
);
1945 EndPaint (infoPtr
->hwndSelf
, &ps
);
1951 TOOLTIPS_SetFont (TOOLTIPS_INFO
*infoPtr
, HFONT hFont
, BOOL redraw
)
1955 if(!GetObjectW(hFont
, sizeof(lf
), &lf
))
1958 infoPtr
->hFont
= hFont
;
1960 DeleteObject (infoPtr
->hTitleFont
);
1961 lf
.lfWeight
= FW_BOLD
;
1962 infoPtr
->hTitleFont
= CreateFontIndirectW(&lf
);
1964 if (redraw
&& infoPtr
->nCurrentTool
!= -1)
1965 FIXME("full redraw needed\n");
1970 /******************************************************************
1971 * TOOLTIPS_GetTextLength
1973 * This function is called when the tooltip receive a
1974 * WM_GETTEXTLENGTH message.
1976 * returns the length, in characters, of the tip text
1978 static inline LRESULT
1979 TOOLTIPS_GetTextLength(const TOOLTIPS_INFO
*infoPtr
)
1981 return lstrlenW(infoPtr
->szTipText
);
1984 /******************************************************************
1985 * TOOLTIPS_OnWMGetText
1987 * This function is called when the tooltip receive a
1988 * WM_GETTEXT message.
1989 * wParam : specifies the maximum number of characters to be copied
1990 * lParam : is the pointer to the buffer that will receive
1993 * returns the number of characters copied
1996 TOOLTIPS_OnWMGetText (const TOOLTIPS_INFO
*infoPtr
, WPARAM size
, LPWSTR pszText
)
2003 res
= min(lstrlenW(infoPtr
->szTipText
)+1, size
);
2004 memcpy(pszText
, infoPtr
->szTipText
, res
*sizeof(WCHAR
));
2005 pszText
[res
-1] = '\0';
2010 TOOLTIPS_Timer (TOOLTIPS_INFO
*infoPtr
, INT iTimer
)
2014 TRACE("timer %d (%p) expired\n", iTimer
, infoPtr
->hwndSelf
);
2018 KillTimer (infoPtr
->hwndSelf
, ID_TIMERSHOW
);
2019 nOldTool
= infoPtr
->nTool
;
2020 if ((infoPtr
->nTool
= TOOLTIPS_CheckTool (infoPtr
, TRUE
)) == nOldTool
)
2021 TOOLTIPS_Show (infoPtr
, FALSE
);
2025 TOOLTIPS_Hide (infoPtr
);
2029 nOldTool
= infoPtr
->nTool
;
2030 infoPtr
->nTool
= TOOLTIPS_CheckTool (infoPtr
, FALSE
);
2031 TRACE("tool (%p) %d %d %d\n", infoPtr
->hwndSelf
, nOldTool
,
2032 infoPtr
->nTool
, infoPtr
->nCurrentTool
);
2033 if (infoPtr
->nTool
!= nOldTool
) {
2034 if(infoPtr
->nTool
== -1) { /* Moved out of all tools */
2035 TOOLTIPS_Hide(infoPtr
);
2036 KillTimer(infoPtr
->hwndSelf
, ID_TIMERLEAVE
);
2037 } else if (nOldTool
== -1) { /* Moved from outside */
2038 ERR("How did this happen?\n");
2039 } else { /* Moved from one to another */
2040 TOOLTIPS_Hide (infoPtr
);
2041 KillTimer(infoPtr
->hwndSelf
, ID_TIMERLEAVE
);
2042 if(infoPtr
->bActive
) {
2043 SetTimer (infoPtr
->hwndSelf
, ID_TIMERSHOW
, infoPtr
->nReshowTime
, 0);
2044 TRACE("timer 1 started!\n");
2051 ERR("Unknown timer id %d\n", iTimer
);
2059 TOOLTIPS_WinIniChange (TOOLTIPS_INFO
*infoPtr
)
2061 TOOLTIPS_InitSystemSettings (infoPtr
);
2067 static LRESULT CALLBACK
2068 TOOLTIPS_SubclassProc (HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
, UINT_PTR uID
, DWORD_PTR dwRef
)
2070 TOOLTIPS_INFO
*infoPtr
= TOOLTIPS_GetInfoPtr ((HWND
)dwRef
);
2076 case WM_LBUTTONDOWN
:
2078 case WM_MBUTTONDOWN
:
2080 case WM_RBUTTONDOWN
:
2085 msg
.message
= message
;
2086 msg
.wParam
= wParam
;
2087 msg
.lParam
= lParam
;
2088 TOOLTIPS_RelayEvent(infoPtr
, &msg
);
2092 RemoveWindowSubclass(hwnd
, TOOLTIPS_SubclassProc
, 1);
2098 return DefSubclassProc(hwnd
, message
, wParam
, lParam
);
2102 static LRESULT CALLBACK
2103 TOOLTIPS_WindowProc (HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
2105 TOOLTIPS_INFO
*infoPtr
= TOOLTIPS_GetInfoPtr (hwnd
);
2107 TRACE("hwnd %p, msg %x, wparam %Ix, lParam %Ix\n", hwnd
, uMsg
, wParam
, lParam
);
2109 if (!infoPtr
&& (uMsg
!= WM_CREATE
) && (uMsg
!= WM_NCCREATE
))
2110 return DefWindowProcW (hwnd
, uMsg
, wParam
, lParam
);
2114 return TOOLTIPS_Activate (infoPtr
, (BOOL
)wParam
);
2118 return TOOLTIPS_AddToolT (infoPtr
, (LPTTTOOLINFOW
)lParam
, uMsg
== TTM_ADDTOOLW
);
2122 return TOOLTIPS_DelToolT (infoPtr
, (LPTOOLINFOW
)lParam
,
2123 uMsg
== TTM_DELTOOLW
);
2124 case TTM_ENUMTOOLSA
:
2125 case TTM_ENUMTOOLSW
:
2126 return TOOLTIPS_EnumToolsT (infoPtr
, (UINT
)wParam
, (LPTTTOOLINFOW
)lParam
,
2127 uMsg
== TTM_ENUMTOOLSW
);
2128 case TTM_GETBUBBLESIZE
:
2129 return TOOLTIPS_GetBubbleSize (infoPtr
, (LPTTTOOLINFOW
)lParam
);
2131 case TTM_GETCURRENTTOOLA
:
2132 case TTM_GETCURRENTTOOLW
:
2133 return TOOLTIPS_GetCurrentToolT (infoPtr
, (LPTTTOOLINFOW
)lParam
,
2134 uMsg
== TTM_GETCURRENTTOOLW
);
2136 case TTM_GETDELAYTIME
:
2137 return TOOLTIPS_GetDelayTime (infoPtr
, (DWORD
)wParam
);
2140 return TOOLTIPS_GetMargin (infoPtr
, (LPRECT
)lParam
);
2142 case TTM_GETMAXTIPWIDTH
:
2143 return TOOLTIPS_GetMaxTipWidth (infoPtr
);
2147 return TOOLTIPS_GetTextT (infoPtr
, (LPTTTOOLINFOW
)lParam
,
2148 uMsg
== TTM_GETTEXTW
);
2150 case TTM_GETTIPBKCOLOR
:
2151 return TOOLTIPS_GetTipBkColor (infoPtr
);
2153 case TTM_GETTIPTEXTCOLOR
:
2154 return TOOLTIPS_GetTipTextColor (infoPtr
);
2156 case TTM_GETTOOLCOUNT
:
2157 return TOOLTIPS_GetToolCount (infoPtr
);
2159 case TTM_GETTOOLINFOA
:
2160 case TTM_GETTOOLINFOW
:
2161 return TOOLTIPS_GetToolInfoT (infoPtr
, (LPTTTOOLINFOW
)lParam
,
2162 uMsg
== TTM_GETTOOLINFOW
);
2166 return TOOLTIPS_HitTestT (infoPtr
, (LPTTHITTESTINFOW
)lParam
,
2167 uMsg
== TTM_HITTESTW
);
2168 case TTM_NEWTOOLRECTA
:
2169 case TTM_NEWTOOLRECTW
:
2170 return TOOLTIPS_NewToolRectT (infoPtr
, (LPTTTOOLINFOW
)lParam
);
2173 return TOOLTIPS_Pop (infoPtr
);
2175 case TTM_RELAYEVENT
:
2176 return TOOLTIPS_RelayEvent (infoPtr
, (LPMSG
)lParam
);
2178 case TTM_SETDELAYTIME
:
2179 return TOOLTIPS_SetDelayTime (infoPtr
, (DWORD
)wParam
, (INT
)LOWORD(lParam
));
2182 return TOOLTIPS_SetMargin (infoPtr
, (LPRECT
)lParam
);
2184 case TTM_SETMAXTIPWIDTH
:
2185 return TOOLTIPS_SetMaxTipWidth (infoPtr
, (INT
)lParam
);
2187 case TTM_SETTIPBKCOLOR
:
2188 return TOOLTIPS_SetTipBkColor (infoPtr
, (COLORREF
)wParam
);
2190 case TTM_SETTIPTEXTCOLOR
:
2191 return TOOLTIPS_SetTipTextColor (infoPtr
, (COLORREF
)wParam
);
2195 return TOOLTIPS_SetTitleT (infoPtr
, (UINT_PTR
)wParam
, (LPCWSTR
)lParam
,
2196 uMsg
== TTM_SETTITLEW
);
2198 case TTM_SETTOOLINFOA
:
2199 case TTM_SETTOOLINFOW
:
2200 return TOOLTIPS_SetToolInfoT (infoPtr
, (LPTTTOOLINFOW
)lParam
,
2201 uMsg
== TTM_SETTOOLINFOW
);
2203 case TTM_TRACKACTIVATE
:
2204 return TOOLTIPS_TrackActivate (infoPtr
, (BOOL
)wParam
, (LPTTTOOLINFOA
)lParam
);
2206 case TTM_TRACKPOSITION
:
2207 return TOOLTIPS_TrackPosition (infoPtr
, lParam
);
2210 return TOOLTIPS_Update (infoPtr
);
2212 case TTM_UPDATETIPTEXTA
:
2213 case TTM_UPDATETIPTEXTW
:
2214 return TOOLTIPS_UpdateTipTextT (infoPtr
, (LPTTTOOLINFOW
)lParam
,
2215 uMsg
== TTM_UPDATETIPTEXTW
);
2217 case TTM_WINDOWFROMPOINT
:
2218 return (LRESULT
)WindowFromPoint (*((LPPOINT
)lParam
));
2221 return TOOLTIPS_Create (hwnd
);
2224 return TOOLTIPS_Destroy (infoPtr
);
2227 /* we draw the background in WM_PAINT */
2231 return TOOLTIPS_GetFont (infoPtr
);
2234 return TOOLTIPS_OnWMGetText (infoPtr
, wParam
, (LPWSTR
)lParam
);
2236 case WM_GETTEXTLENGTH
:
2237 return TOOLTIPS_GetTextLength (infoPtr
);
2239 case WM_LBUTTONDOWN
:
2241 case WM_MBUTTONDOWN
:
2243 case WM_RBUTTONDOWN
:
2246 return TOOLTIPS_MouseMessage (infoPtr
);
2249 return TOOLTIPS_NCCreate (hwnd
);
2252 return TOOLTIPS_NCHitTest (infoPtr
, wParam
, lParam
);
2254 case WM_NOTIFYFORMAT
:
2255 return TOOLTIPS_NotifyFormat (infoPtr
, wParam
, lParam
);
2257 case WM_PRINTCLIENT
:
2259 return TOOLTIPS_Paint (infoPtr
, (HDC
)wParam
);
2262 return TOOLTIPS_SetFont (infoPtr
, (HFONT
)wParam
, LOWORD(lParam
));
2264 case WM_SYSCOLORCHANGE
:
2265 COMCTL32_RefreshSysColors();
2269 return TOOLTIPS_Timer (infoPtr
, (INT
)wParam
);
2271 case WM_WININICHANGE
:
2272 return TOOLTIPS_WinIniChange (infoPtr
);
2275 if ((uMsg
>= WM_USER
) && (uMsg
< WM_APP
) && !COMCTL32_IsReflectedMessage(uMsg
))
2276 ERR("unknown msg %04x, wp %Ix, lp %Ix\n", uMsg
, wParam
, lParam
);
2277 return DefWindowProcW (hwnd
, uMsg
, wParam
, lParam
);
2283 TOOLTIPS_Register (void)
2287 ZeroMemory (&wndClass
, sizeof(WNDCLASSW
));
2288 wndClass
.style
= CS_GLOBALCLASS
| CS_DBLCLKS
| CS_SAVEBITS
;
2289 wndClass
.lpfnWndProc
= TOOLTIPS_WindowProc
;
2290 wndClass
.cbClsExtra
= 0;
2291 wndClass
.cbWndExtra
= sizeof(TOOLTIPS_INFO
*);
2292 wndClass
.hCursor
= LoadCursorW (0, (LPWSTR
)IDC_ARROW
);
2293 wndClass
.hbrBackground
= 0;
2294 wndClass
.lpszClassName
= TOOLTIPS_CLASSW
;
2296 RegisterClassW (&wndClass
);
2298 hTooltipIcons
[TTI_NONE
] = NULL
;
2299 hTooltipIcons
[TTI_INFO
] = LoadImageW(COMCTL32_hModule
,
2300 (LPCWSTR
)MAKEINTRESOURCE(IDI_TT_INFO_SM
), IMAGE_ICON
, 0, 0, 0);
2301 hTooltipIcons
[TTI_WARNING
] = LoadImageW(COMCTL32_hModule
,
2302 (LPCWSTR
)MAKEINTRESOURCE(IDI_TT_WARN_SM
), IMAGE_ICON
, 0, 0, 0);
2303 hTooltipIcons
[TTI_ERROR
] = LoadImageW(COMCTL32_hModule
,
2304 (LPCWSTR
)MAKEINTRESOURCE(IDI_TT_ERROR_SM
), IMAGE_ICON
, 0, 0, 0);
2309 TOOLTIPS_Unregister (void)
2312 for (i
= TTI_INFO
; i
<= TTI_ERROR
; i
++)
2313 DestroyIcon(hTooltipIcons
[i
]);
2314 UnregisterClassW (TOOLTIPS_CLASSW
, NULL
);