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
);
181 static inline BOOL
TOOLTIPS_IsCallbackString(LPCWSTR str
, BOOL isW
)
184 return str
== LPSTR_TEXTCALLBACKW
;
186 return (LPCSTR
)str
== LPSTR_TEXTCALLBACKA
;
189 static inline UINT_PTR
190 TOOLTIPS_GetTitleIconIndex(HICON hIcon
)
193 for (i
= 0; i
<= TTI_ERROR
; i
++)
194 if (hTooltipIcons
[i
] == hIcon
)
196 return (UINT_PTR
)hIcon
;
200 TOOLTIPS_InitSystemSettings (TOOLTIPS_INFO
*infoPtr
)
202 NONCLIENTMETRICSW nclm
;
204 infoPtr
->clrBk
= comctl32_color
.clrInfoBk
;
205 infoPtr
->clrText
= comctl32_color
.clrInfoText
;
207 DeleteObject (infoPtr
->hFont
);
208 nclm
.cbSize
= sizeof(nclm
);
209 SystemParametersInfoW (SPI_GETNONCLIENTMETRICS
, sizeof(nclm
), &nclm
, 0);
210 infoPtr
->hFont
= CreateFontIndirectW (&nclm
.lfStatusFont
);
212 DeleteObject (infoPtr
->hTitleFont
);
213 nclm
.lfStatusFont
.lfWeight
= FW_BOLD
;
214 infoPtr
->hTitleFont
= CreateFontIndirectW (&nclm
.lfStatusFont
);
217 /* Custom draw routines */
219 TOOLTIPS_customdraw_fill(const TOOLTIPS_INFO
*infoPtr
, NMTTCUSTOMDRAW
*lpnmttcd
,
220 HDC hdc
, const RECT
*rcBounds
, UINT uFlags
)
222 ZeroMemory(lpnmttcd
, sizeof(NMTTCUSTOMDRAW
));
223 lpnmttcd
->uDrawFlags
= uFlags
;
224 lpnmttcd
->nmcd
.hdr
.hwndFrom
= infoPtr
->hwndSelf
;
225 lpnmttcd
->nmcd
.hdr
.code
= NM_CUSTOMDRAW
;
226 if (infoPtr
->nCurrentTool
!= -1) {
227 TTTOOL_INFO
*toolPtr
= &infoPtr
->tools
[infoPtr
->nCurrentTool
];
228 lpnmttcd
->nmcd
.hdr
.idFrom
= toolPtr
->uId
;
230 lpnmttcd
->nmcd
.hdc
= hdc
;
231 lpnmttcd
->nmcd
.rc
= *rcBounds
;
232 /* FIXME - dwItemSpec, uItemState, lItemlParam */
236 TOOLTIPS_notify_customdraw (DWORD dwDrawStage
, NMTTCUSTOMDRAW
*lpnmttcd
)
239 lpnmttcd
->nmcd
.dwDrawStage
= dwDrawStage
;
241 TRACE("Notifying stage %d, flags %x, id %x\n", lpnmttcd
->nmcd
.dwDrawStage
,
242 lpnmttcd
->uDrawFlags
, lpnmttcd
->nmcd
.hdr
.code
);
244 result
= SendMessageW(GetParent(lpnmttcd
->nmcd
.hdr
.hwndFrom
), WM_NOTIFY
,
245 0, (LPARAM
)lpnmttcd
);
247 TRACE("Notify result %x\n", (unsigned int)result
);
253 TOOLTIPS_Refresh (const TOOLTIPS_INFO
*infoPtr
, HDC hdc
)
259 UINT uFlags
= DT_EXTERNALLEADING
;
261 DWORD dwStyle
= GetWindowLongW(infoPtr
->hwndSelf
, GWL_STYLE
);
262 NMTTCUSTOMDRAW nmttcd
;
265 if (infoPtr
->nMaxTipWidth
> -1)
266 uFlags
|= DT_WORDBREAK
;
267 if (GetWindowLongW (infoPtr
->hwndSelf
, GWL_STYLE
) & TTS_NOPREFIX
)
268 uFlags
|= DT_NOPREFIX
;
269 GetClientRect (infoPtr
->hwndSelf
, &rc
);
271 hBrush
= CreateSolidBrush(infoPtr
->clrBk
);
273 oldBkMode
= SetBkMode (hdc
, TRANSPARENT
);
274 SetTextColor (hdc
, infoPtr
->clrText
);
275 hOldFont
= SelectObject (hdc
, infoPtr
->hFont
);
277 /* Custom draw - Call PrePaint once initial properties set up */
278 /* Note: Contrary to MSDN, CDRF_SKIPDEFAULT still draws a tooltip */
279 TOOLTIPS_customdraw_fill(infoPtr
, &nmttcd
, hdc
, &rc
, uFlags
);
280 cdmode
= TOOLTIPS_notify_customdraw(CDDS_PREPAINT
, &nmttcd
);
281 uFlags
= nmttcd
.uDrawFlags
;
283 if (dwStyle
& TTS_BALLOON
)
285 /* create a region to store result into */
286 hRgn
= CreateRectRgn(0, 0, 0, 0);
288 GetWindowRgn(infoPtr
->hwndSelf
, hRgn
);
290 /* fill the background */
291 FillRgn(hdc
, hRgn
, hBrush
);
292 DeleteObject(hBrush
);
297 /* fill the background */
298 FillRect(hdc
, &rc
, hBrush
);
299 DeleteObject(hBrush
);
303 if ((dwStyle
& TTS_BALLOON
) || infoPtr
->pszTitle
)
305 /* calculate text rectangle */
306 rc
.left
+= (BALLOON_TEXT_MARGIN
+ infoPtr
->rcMargin
.left
);
307 rc
.top
+= (BALLOON_TEXT_MARGIN
+ infoPtr
->rcMargin
.top
);
308 rc
.right
-= (BALLOON_TEXT_MARGIN
+ infoPtr
->rcMargin
.right
);
309 rc
.bottom
-= (BALLOON_TEXT_MARGIN
+ infoPtr
->rcMargin
.bottom
);
310 if(infoPtr
->bToolBelow
) rc
.top
+= BALLOON_STEMHEIGHT
;
312 if (infoPtr
->pszTitle
)
314 RECT rcTitle
= {rc
.left
, rc
.top
, rc
.right
, rc
.bottom
};
320 icon_present
= infoPtr
->hTitleIcon
&&
321 DrawIconEx(hdc
, rc
.left
, rc
.top
, infoPtr
->hTitleIcon
,
322 ICON_WIDTH
, ICON_HEIGHT
, 0, NULL
, DI_NORMAL
);
324 rcTitle
.left
+= ICON_WIDTH
+ BALLOON_ICON_TITLE_SPACING
;
326 rcTitle
.bottom
= rc
.top
+ ICON_HEIGHT
;
328 /* draw title text */
329 prevFont
= SelectObject (hdc
, infoPtr
->hTitleFont
);
330 height
= DrawTextW(hdc
, infoPtr
->pszTitle
, -1, &rcTitle
, DT_BOTTOM
| DT_SINGLELINE
| DT_NOPREFIX
);
331 SelectObject (hdc
, prevFont
);
332 rc
.top
+= height
+ BALLOON_TITLE_TEXT_SPACING
;
337 /* calculate text rectangle */
338 rc
.left
+= (NORMAL_TEXT_MARGIN
+ infoPtr
->rcMargin
.left
);
339 rc
.top
+= (NORMAL_TEXT_MARGIN
+ infoPtr
->rcMargin
.top
);
340 rc
.right
-= (NORMAL_TEXT_MARGIN
+ infoPtr
->rcMargin
.right
);
341 rc
.bottom
-= (NORMAL_TEXT_MARGIN
+ infoPtr
->rcMargin
.bottom
);
345 DrawTextW (hdc
, infoPtr
->szTipText
, -1, &rc
, uFlags
);
347 /* Custom draw - Call PostPaint after drawing */
348 if (cdmode
& CDRF_NOTIFYPOSTPAINT
) {
349 TOOLTIPS_notify_customdraw(CDDS_POSTPAINT
, &nmttcd
);
352 /* be polite and reset the things we changed in the dc */
353 SelectObject (hdc
, hOldFont
);
354 SetBkMode (hdc
, oldBkMode
);
356 if (dwStyle
& TTS_BALLOON
)
358 /* frame region because default window proc doesn't do it */
359 INT width
= GetSystemMetrics(SM_CXDLGFRAME
) - GetSystemMetrics(SM_CXEDGE
);
360 INT height
= GetSystemMetrics(SM_CYDLGFRAME
) - GetSystemMetrics(SM_CYEDGE
);
362 hBrush
= GetSysColorBrush(COLOR_WINDOWFRAME
);
363 FrameRgn(hdc
, hRgn
, hBrush
, width
, height
);
370 static void TOOLTIPS_GetDispInfoA(const TOOLTIPS_INFO
*infoPtr
, TTTOOL_INFO
*toolPtr
, WCHAR
*buffer
)
372 NMTTDISPINFOA ttnmdi
;
374 /* fill NMHDR struct */
375 ZeroMemory (&ttnmdi
, sizeof(NMTTDISPINFOA
));
376 ttnmdi
.hdr
.hwndFrom
= infoPtr
->hwndSelf
;
377 ttnmdi
.hdr
.idFrom
= toolPtr
->uId
;
378 ttnmdi
.hdr
.code
= TTN_GETDISPINFOA
; /* == TTN_NEEDTEXTA */
379 ttnmdi
.lpszText
= ttnmdi
.szText
;
380 ttnmdi
.uFlags
= toolPtr
->uFlags
;
381 ttnmdi
.lParam
= toolPtr
->lParam
;
383 TRACE("hdr.idFrom = %lx\n", ttnmdi
.hdr
.idFrom
);
384 SendMessageW(toolPtr
->hwnd
, WM_NOTIFY
, toolPtr
->uId
, (LPARAM
)&ttnmdi
);
386 if (IS_INTRESOURCE(ttnmdi
.lpszText
)) {
387 LoadStringW(ttnmdi
.hinst
, LOWORD(ttnmdi
.lpszText
),
388 buffer
, INFOTIPSIZE
);
389 if (ttnmdi
.uFlags
& TTF_DI_SETITEM
) {
390 toolPtr
->hinst
= ttnmdi
.hinst
;
391 toolPtr
->lpszText
= (LPWSTR
)ttnmdi
.lpszText
;
394 else if (ttnmdi
.lpszText
== 0) {
397 else if (ttnmdi
.lpszText
!= LPSTR_TEXTCALLBACKA
) {
398 Str_GetPtrAtoW(ttnmdi
.lpszText
, buffer
, INFOTIPSIZE
);
399 if (ttnmdi
.uFlags
& TTF_DI_SETITEM
) {
401 toolPtr
->lpszText
= NULL
;
402 Str_SetPtrW(&toolPtr
->lpszText
, buffer
);
406 ERR("recursive text callback\n");
410 /* no text available - try calling parent instead as per native */
411 /* FIXME: Unsure if SETITEM should save the value or not */
412 if (buffer
[0] == 0x00) {
414 SendMessageW(GetParent(toolPtr
->hwnd
), WM_NOTIFY
, toolPtr
->uId
, (LPARAM
)&ttnmdi
);
416 if (IS_INTRESOURCE(ttnmdi
.lpszText
)) {
417 LoadStringW(ttnmdi
.hinst
, LOWORD(ttnmdi
.lpszText
),
418 buffer
, INFOTIPSIZE
);
419 } else if (ttnmdi
.lpszText
&&
420 ttnmdi
.lpszText
!= LPSTR_TEXTCALLBACKA
) {
421 Str_GetPtrAtoW(ttnmdi
.lpszText
, buffer
, INFOTIPSIZE
);
426 static void TOOLTIPS_GetDispInfoW(const TOOLTIPS_INFO
*infoPtr
, TTTOOL_INFO
*toolPtr
, WCHAR
*buffer
)
428 NMTTDISPINFOW ttnmdi
;
430 /* fill NMHDR struct */
431 ZeroMemory (&ttnmdi
, sizeof(NMTTDISPINFOW
));
432 ttnmdi
.hdr
.hwndFrom
= infoPtr
->hwndSelf
;
433 ttnmdi
.hdr
.idFrom
= toolPtr
->uId
;
434 ttnmdi
.hdr
.code
= TTN_GETDISPINFOW
; /* == TTN_NEEDTEXTW */
435 ttnmdi
.lpszText
= ttnmdi
.szText
;
436 ttnmdi
.uFlags
= toolPtr
->uFlags
;
437 ttnmdi
.lParam
= toolPtr
->lParam
;
439 TRACE("hdr.idFrom = %lx\n", ttnmdi
.hdr
.idFrom
);
440 SendMessageW(toolPtr
->hwnd
, WM_NOTIFY
, toolPtr
->uId
, (LPARAM
)&ttnmdi
);
442 if (IS_INTRESOURCE(ttnmdi
.lpszText
)) {
443 LoadStringW(ttnmdi
.hinst
, LOWORD(ttnmdi
.lpszText
),
444 buffer
, INFOTIPSIZE
);
445 if (ttnmdi
.uFlags
& TTF_DI_SETITEM
) {
446 toolPtr
->hinst
= ttnmdi
.hinst
;
447 toolPtr
->lpszText
= ttnmdi
.lpszText
;
450 else if (ttnmdi
.lpszText
== 0) {
453 else if (ttnmdi
.lpszText
!= LPSTR_TEXTCALLBACKW
) {
454 Str_GetPtrW(ttnmdi
.lpszText
, buffer
, INFOTIPSIZE
);
455 if (ttnmdi
.uFlags
& TTF_DI_SETITEM
) {
457 toolPtr
->lpszText
= NULL
;
458 Str_SetPtrW(&toolPtr
->lpszText
, buffer
);
462 ERR("recursive text callback\n");
466 /* no text available - try calling parent instead as per native */
467 /* FIXME: Unsure if SETITEM should save the value or not */
468 if (buffer
[0] == 0x00) {
470 SendMessageW(GetParent(toolPtr
->hwnd
), WM_NOTIFY
, toolPtr
->uId
, (LPARAM
)&ttnmdi
);
472 if (IS_INTRESOURCE(ttnmdi
.lpszText
)) {
473 LoadStringW(ttnmdi
.hinst
, LOWORD(ttnmdi
.lpszText
),
474 buffer
, INFOTIPSIZE
);
475 } else if (ttnmdi
.lpszText
&&
476 ttnmdi
.lpszText
!= LPSTR_TEXTCALLBACKW
) {
477 Str_GetPtrW(ttnmdi
.lpszText
, buffer
, INFOTIPSIZE
);
484 TOOLTIPS_GetTipText (const TOOLTIPS_INFO
*infoPtr
, INT nTool
, WCHAR
*buffer
)
486 TTTOOL_INFO
*toolPtr
= &infoPtr
->tools
[nTool
];
488 if (IS_INTRESOURCE(toolPtr
->lpszText
)) {
489 /* load a resource */
490 TRACE("load res string %p %x\n",
491 toolPtr
->hinst
, LOWORD(toolPtr
->lpszText
));
492 if (!LoadStringW (toolPtr
->hinst
, LOWORD(toolPtr
->lpszText
), buffer
, INFOTIPSIZE
))
495 else if (toolPtr
->lpszText
) {
496 if (toolPtr
->lpszText
== LPSTR_TEXTCALLBACKW
) {
497 if (toolPtr
->bNotifyUnicode
)
498 TOOLTIPS_GetDispInfoW(infoPtr
, toolPtr
, buffer
);
500 TOOLTIPS_GetDispInfoA(infoPtr
, toolPtr
, buffer
);
503 /* the item is a usual (unicode) text */
504 lstrcpynW (buffer
, toolPtr
->lpszText
, INFOTIPSIZE
);
508 /* no text available */
512 if (!(GetWindowLongW(infoPtr
->hwndSelf
, GWL_STYLE
) & TTS_NOPREFIX
)) {
514 if ((ptrW
= strchrW(buffer
, '\t')))
518 TRACE("%s\n", debugstr_w(buffer
));
523 TOOLTIPS_CalcTipSize (const TOOLTIPS_INFO
*infoPtr
, LPSIZE lpSize
)
527 DWORD style
= GetWindowLongW(infoPtr
->hwndSelf
, GWL_STYLE
);
528 UINT uFlags
= DT_EXTERNALLEADING
| DT_CALCRECT
;
529 RECT rc
= {0, 0, 0, 0};
532 if (infoPtr
->nMaxTipWidth
> -1) {
533 rc
.right
= infoPtr
->nMaxTipWidth
;
534 uFlags
|= DT_WORDBREAK
;
536 if (style
& TTS_NOPREFIX
)
537 uFlags
|= DT_NOPREFIX
;
538 TRACE("%s\n", debugstr_w(infoPtr
->szTipText
));
540 hdc
= GetDC (infoPtr
->hwndSelf
);
541 if (infoPtr
->pszTitle
)
543 RECT rcTitle
= {0, 0, 0, 0};
544 TRACE("title %s\n", debugstr_w(infoPtr
->pszTitle
));
545 if (infoPtr
->hTitleIcon
)
547 title
.cx
= ICON_WIDTH
;
548 title
.cy
= ICON_HEIGHT
;
550 if (title
.cx
!= 0) title
.cx
+= BALLOON_ICON_TITLE_SPACING
;
551 hOldFont
= SelectObject (hdc
, infoPtr
->hTitleFont
);
552 DrawTextW(hdc
, infoPtr
->pszTitle
, -1, &rcTitle
, DT_SINGLELINE
| DT_NOPREFIX
| DT_CALCRECT
);
553 SelectObject (hdc
, hOldFont
);
554 title
.cy
= max(title
.cy
, rcTitle
.bottom
- rcTitle
.top
) + BALLOON_TITLE_TEXT_SPACING
;
555 title
.cx
+= (rcTitle
.right
- rcTitle
.left
);
557 hOldFont
= SelectObject (hdc
, infoPtr
->hFont
);
558 DrawTextW (hdc
, infoPtr
->szTipText
, -1, &rc
, uFlags
);
559 SelectObject (hdc
, hOldFont
);
560 ReleaseDC (infoPtr
->hwndSelf
, hdc
);
562 if ((style
& TTS_BALLOON
) || infoPtr
->pszTitle
)
564 lpSize
->cx
= max(rc
.right
- rc
.left
, title
.cx
) + 2*BALLOON_TEXT_MARGIN
+
565 infoPtr
->rcMargin
.left
+ infoPtr
->rcMargin
.right
;
566 lpSize
->cy
= title
.cy
+ rc
.bottom
- rc
.top
+ 2*BALLOON_TEXT_MARGIN
+
567 infoPtr
->rcMargin
.bottom
+ infoPtr
->rcMargin
.top
+
572 lpSize
->cx
= rc
.right
- rc
.left
+ 2*NORMAL_TEXT_MARGIN
+
573 infoPtr
->rcMargin
.left
+ infoPtr
->rcMargin
.right
;
574 lpSize
->cy
= rc
.bottom
- rc
.top
+ 2*NORMAL_TEXT_MARGIN
+
575 infoPtr
->rcMargin
.bottom
+ infoPtr
->rcMargin
.top
;
581 TOOLTIPS_Show (TOOLTIPS_INFO
*infoPtr
, BOOL track_activate
)
583 TTTOOL_INFO
*toolPtr
;
585 MONITORINFO mon_info
;
590 DWORD style
= GetWindowLongW(infoPtr
->hwndSelf
, GWL_STYLE
);
595 if (infoPtr
->nTrackTool
== -1)
597 TRACE("invalid tracking tool %d\n", infoPtr
->nTrackTool
);
600 nTool
= infoPtr
->nTrackTool
;
604 if (infoPtr
->nTool
== -1)
606 TRACE("invalid tool %d\n", infoPtr
->nTool
);
609 nTool
= infoPtr
->nTool
;
612 TRACE("Show tooltip pre %d, %p\n", nTool
, infoPtr
->hwndSelf
);
614 current
= infoPtr
->nCurrentTool
;
616 infoPtr
->nCurrentTool
= infoPtr
->nTool
;
618 TOOLTIPS_GetTipText (infoPtr
, nTool
, infoPtr
->szTipText
);
620 if (infoPtr
->szTipText
[0] == '\0')
622 infoPtr
->nCurrentTool
= current
;
626 toolPtr
= &infoPtr
->tools
[nTool
];
627 TOOLTIPS_CalcTipSize (infoPtr
, &size
);
629 TRACE("Show tooltip %d, %s, size %d x %d\n", nTool
, debugstr_w(infoPtr
->szTipText
),
632 if (track_activate
&& (toolPtr
->uFlags
& TTF_TRACK
))
634 rect
.left
= infoPtr
->xTrackPos
;
635 rect
.top
= infoPtr
->yTrackPos
;
638 if (toolPtr
->uFlags
& TTF_CENTERTIP
)
640 rect
.left
-= (size
.cx
/ 2);
641 if (!(style
& TTS_BALLOON
))
642 rect
.top
-= (size
.cy
/ 2);
644 if (!(infoPtr
->bToolBelow
= (infoPtr
->yTrackPos
+ size
.cy
<= GetSystemMetrics(SM_CYSCREEN
))))
647 if (!(toolPtr
->uFlags
& TTF_ABSOLUTE
))
649 if (style
& TTS_BALLOON
)
650 rect
.left
-= BALLOON_STEMINDENT
;
655 if (toolPtr
->uFlags
& TTF_IDISHWND
)
656 GetWindowRect ((HWND
)toolPtr
->uId
, &rcTool
);
659 rcTool
= toolPtr
->rect
;
660 MapWindowPoints (toolPtr
->hwnd
, NULL
, (LPPOINT
)&rcTool
, 2);
663 /* smart placement */
664 if ((rect
.left
+ size
.cx
> rcTool
.left
) && (rect
.left
< rcTool
.right
) &&
665 (rect
.top
+ size
.cy
> rcTool
.top
) && (rect
.top
< rcTool
.bottom
))
666 rect
.left
= rcTool
.right
;
672 if (toolPtr
->uFlags
& TTF_CENTERTIP
)
676 if (toolPtr
->uFlags
& TTF_IDISHWND
)
677 GetWindowRect ((HWND
)toolPtr
->uId
, &rc
);
680 MapWindowPoints (toolPtr
->hwnd
, NULL
, (LPPOINT
)&rc
, 2);
682 rect
.left
= (rc
.left
+ rc
.right
- size
.cx
) / 2;
683 if (style
& TTS_BALLOON
)
685 ptfx
= rc
.left
+ ((rc
.right
- rc
.left
) / 2);
687 /* CENTERTIP ballon tooltips default to below the field
688 * if they fit on the screen */
689 if (rc
.bottom
+ size
.cy
> GetSystemMetrics(SM_CYSCREEN
))
691 rect
.top
= rc
.top
- size
.cy
;
692 infoPtr
->bToolBelow
= FALSE
;
696 infoPtr
->bToolBelow
= TRUE
;
697 rect
.top
= rc
.bottom
;
699 rect
.left
= max(0, rect
.left
- BALLOON_STEMINDENT
);
703 rect
.top
= rc
.bottom
+ 2;
704 infoPtr
->bToolBelow
= TRUE
;
709 GetCursorPos ((LPPOINT
)&rect
);
710 if (style
& TTS_BALLOON
)
713 if(rect
.top
- size
.cy
>= 0)
716 infoPtr
->bToolBelow
= FALSE
;
720 infoPtr
->bToolBelow
= TRUE
;
723 rect
.left
= max(0, rect
.left
- BALLOON_STEMINDENT
);
728 infoPtr
->bToolBelow
= TRUE
;
733 TRACE("pos %d - %d\n", rect
.left
, rect
.top
);
735 rect
.right
= rect
.left
+ size
.cx
;
736 rect
.bottom
= rect
.top
+ size
.cy
;
740 monitor
= MonitorFromRect( &rect
, MONITOR_DEFAULTTOPRIMARY
);
741 mon_info
.cbSize
= sizeof(mon_info
);
742 GetMonitorInfoW( monitor
, &mon_info
);
744 if( rect
.right
> mon_info
.rcWork
.right
) {
745 rect
.left
-= rect
.right
- mon_info
.rcWork
.right
+ 2;
746 rect
.right
= mon_info
.rcWork
.right
- 2;
748 if (rect
.left
< mon_info
.rcWork
.left
) rect
.left
= mon_info
.rcWork
.left
;
750 if( rect
.bottom
> mon_info
.rcWork
.bottom
) {
753 if (toolPtr
->uFlags
& TTF_IDISHWND
)
754 GetWindowRect ((HWND
)toolPtr
->uId
, &rc
);
757 MapWindowPoints (toolPtr
->hwnd
, NULL
, (LPPOINT
)&rc
, 2);
759 rect
.bottom
= rc
.top
- 2;
760 rect
.top
= rect
.bottom
- size
.cy
;
763 AdjustWindowRectEx (&rect
, GetWindowLongW (infoPtr
->hwndSelf
, GWL_STYLE
),
764 FALSE
, GetWindowLongW (infoPtr
->hwndSelf
, GWL_EXSTYLE
));
766 if (style
& TTS_BALLOON
)
774 if(infoPtr
->bToolBelow
)
778 pts
[1].x
= max(BALLOON_STEMINDENT
, ptfx
- (BALLOON_STEMWIDTH
/ 2));
779 pts
[1].y
= BALLOON_STEMHEIGHT
;
780 pts
[2].x
= pts
[1].x
+ BALLOON_STEMWIDTH
;
782 if(pts
[2].x
> (rect
.right
- rect
.left
) - BALLOON_STEMINDENT
)
784 pts
[2].x
= (rect
.right
- rect
.left
) - BALLOON_STEMINDENT
;
785 pts
[1].x
= pts
[2].x
- BALLOON_STEMWIDTH
;
790 pts
[0].x
= max(BALLOON_STEMINDENT
, ptfx
- (BALLOON_STEMWIDTH
/ 2));
791 pts
[0].y
= (rect
.bottom
- rect
.top
) - BALLOON_STEMHEIGHT
;
792 pts
[1].x
= pts
[0].x
+ BALLOON_STEMWIDTH
;
795 pts
[2].y
= (rect
.bottom
- rect
.top
);
796 if(pts
[1].x
> (rect
.right
- rect
.left
) - BALLOON_STEMINDENT
)
798 pts
[1].x
= (rect
.right
- rect
.left
) - BALLOON_STEMINDENT
;
799 pts
[0].x
= pts
[1].x
- BALLOON_STEMWIDTH
;
803 hrStem
= CreatePolygonRgn(pts
, ARRAY_SIZE(pts
), ALTERNATE
);
805 hRgn
= CreateRoundRectRgn(0,
806 (infoPtr
->bToolBelow
? BALLOON_STEMHEIGHT
: 0),
807 rect
.right
- rect
.left
,
808 (infoPtr
->bToolBelow
? rect
.bottom
- rect
.top
: rect
.bottom
- rect
.top
- BALLOON_STEMHEIGHT
),
809 BALLOON_ROUNDEDNESS
, BALLOON_ROUNDEDNESS
);
811 CombineRgn(hRgn
, hRgn
, hrStem
, RGN_OR
);
812 DeleteObject(hrStem
);
814 SetWindowRgn(infoPtr
->hwndSelf
, hRgn
, FALSE
);
815 /* we don't free the region handle as the system deletes it when
816 * it is no longer needed */
819 SetWindowPos (infoPtr
->hwndSelf
, NULL
, rect
.left
, rect
.top
,
820 rect
.right
- rect
.left
, rect
.bottom
- rect
.top
, SWP_NOZORDER
| SWP_NOACTIVATE
);
822 hdr
.hwndFrom
= infoPtr
->hwndSelf
;
823 hdr
.idFrom
= toolPtr
->uId
;
825 SendMessageW (toolPtr
->hwnd
, WM_NOTIFY
, toolPtr
->uId
, (LPARAM
)&hdr
);
827 SetWindowPos (infoPtr
->hwndSelf
, HWND_TOPMOST
, 0, 0, 0, 0,
828 SWP_NOSIZE
| SWP_NOMOVE
| SWP_SHOWWINDOW
| SWP_NOACTIVATE
);
830 /* repaint the tooltip */
831 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
832 UpdateWindow(infoPtr
->hwndSelf
);
836 SetTimer (infoPtr
->hwndSelf
, ID_TIMERPOP
, infoPtr
->nAutoPopTime
, 0);
837 TRACE("timer 2 started\n");
838 SetTimer (infoPtr
->hwndSelf
, ID_TIMERLEAVE
, infoPtr
->nReshowTime
, 0);
839 TRACE("timer 3 started\n");
845 TOOLTIPS_Hide (TOOLTIPS_INFO
*infoPtr
)
847 TTTOOL_INFO
*toolPtr
;
850 TRACE("Hide tooltip %d, %p.\n", infoPtr
->nCurrentTool
, infoPtr
->hwndSelf
);
852 if (infoPtr
->nCurrentTool
== -1)
855 toolPtr
= &infoPtr
->tools
[infoPtr
->nCurrentTool
];
856 KillTimer (infoPtr
->hwndSelf
, ID_TIMERPOP
);
858 hdr
.hwndFrom
= infoPtr
->hwndSelf
;
859 hdr
.idFrom
= toolPtr
->uId
;
861 SendMessageW (toolPtr
->hwnd
, WM_NOTIFY
, toolPtr
->uId
, (LPARAM
)&hdr
);
863 infoPtr
->nCurrentTool
= -1;
865 SetWindowPos (infoPtr
->hwndSelf
, HWND_TOP
, 0, 0, 0, 0,
866 SWP_NOZORDER
| SWP_HIDEWINDOW
| SWP_NOACTIVATE
);
871 TOOLTIPS_TrackShow (TOOLTIPS_INFO
*infoPtr
)
873 TOOLTIPS_Show(infoPtr
, TRUE
);
878 TOOLTIPS_TrackHide (const TOOLTIPS_INFO
*infoPtr
)
880 TTTOOL_INFO
*toolPtr
;
883 TRACE("hide tracking tooltip %d\n", infoPtr
->nTrackTool
);
885 if (infoPtr
->nTrackTool
== -1)
888 toolPtr
= &infoPtr
->tools
[infoPtr
->nTrackTool
];
890 hdr
.hwndFrom
= infoPtr
->hwndSelf
;
891 hdr
.idFrom
= toolPtr
->uId
;
893 SendMessageW (toolPtr
->hwnd
, WM_NOTIFY
, toolPtr
->uId
, (LPARAM
)&hdr
);
895 SetWindowPos (infoPtr
->hwndSelf
, HWND_TOP
, 0, 0, 0, 0,
896 SWP_NOZORDER
| SWP_HIDEWINDOW
| SWP_NOACTIVATE
);
899 /* Structure layout is the same for TTTOOLINFOW and TTTOOLINFOA,
900 this helper is used in both cases. */
902 TOOLTIPS_GetToolFromInfoT (const TOOLTIPS_INFO
*infoPtr
, const TTTOOLINFOW
*lpToolInfo
)
904 TTTOOL_INFO
*toolPtr
;
907 for (nTool
= 0; nTool
< infoPtr
->uNumTools
; nTool
++) {
908 toolPtr
= &infoPtr
->tools
[nTool
];
910 if (!(toolPtr
->uFlags
& TTF_IDISHWND
) &&
911 (lpToolInfo
->hwnd
== toolPtr
->hwnd
) &&
912 (lpToolInfo
->uId
== toolPtr
->uId
))
916 for (nTool
= 0; nTool
< infoPtr
->uNumTools
; nTool
++) {
917 toolPtr
= &infoPtr
->tools
[nTool
];
919 if ((toolPtr
->uFlags
& TTF_IDISHWND
) &&
920 (lpToolInfo
->uId
== toolPtr
->uId
))
929 TOOLTIPS_GetToolFromPoint (const TOOLTIPS_INFO
*infoPtr
, HWND hwnd
, const POINT
*lpPt
)
931 TTTOOL_INFO
*toolPtr
;
934 for (nTool
= 0; nTool
< infoPtr
->uNumTools
; nTool
++) {
935 toolPtr
= &infoPtr
->tools
[nTool
];
937 if (!(toolPtr
->uFlags
& TTF_IDISHWND
)) {
938 if (hwnd
!= toolPtr
->hwnd
)
940 if (!PtInRect (&toolPtr
->rect
, *lpPt
))
946 for (nTool
= 0; nTool
< infoPtr
->uNumTools
; nTool
++) {
947 toolPtr
= &infoPtr
->tools
[nTool
];
949 if (toolPtr
->uFlags
& TTF_IDISHWND
) {
950 if ((HWND
)toolPtr
->uId
== hwnd
)
959 TOOLTIPS_CopyInfoT (const TOOLTIPS_INFO
*infoPtr
, INT index
, TTTOOLINFOW
*ti
, BOOL isW
)
961 const TTTOOL_INFO
*toolPtr
= &infoPtr
->tools
[index
];
963 ti
->uFlags
= toolPtr
->uFlags
;
964 ti
->hwnd
= toolPtr
->hwnd
;
965 ti
->uId
= toolPtr
->uId
;
966 ti
->rect
= toolPtr
->rect
;
967 ti
->hinst
= toolPtr
->hinst
;
970 if (toolPtr
->lpszText
== NULL
||
971 IS_INTRESOURCE(toolPtr
->lpszText
) ||
972 toolPtr
->lpszText
== LPSTR_TEXTCALLBACKW
)
973 ti
->lpszText
= toolPtr
->lpszText
;
975 strcpyW (ti
->lpszText
, toolPtr
->lpszText
);
977 /* ANSI version, the buffer is maximum 80 bytes without null. */
978 WideCharToMultiByte(CP_ACP
, 0, toolPtr
->lpszText
, -1,
979 (LPSTR
)ti
->lpszText
, MAX_TEXT_SIZE_A
, NULL
, NULL
);
982 if (ti
->cbSize
>= TTTOOLINFOW_V2_SIZE
)
983 ti
->lParam
= toolPtr
->lParam
;
985 /* lpReserved is intentionally not set. */
989 TOOLTIPS_IsWindowActive (HWND hwnd
)
991 HWND hwndActive
= GetActiveWindow ();
994 if (hwndActive
== hwnd
)
996 return IsChild (hwndActive
, hwnd
);
1001 TOOLTIPS_CheckTool (const TOOLTIPS_INFO
*infoPtr
, BOOL bShowTest
)
1008 hwndTool
= (HWND
)SendMessageW (infoPtr
->hwndSelf
, TTM_WINDOWFROMPOINT
, 0, (LPARAM
)&pt
);
1012 ScreenToClient (hwndTool
, &pt
);
1013 nTool
= TOOLTIPS_GetToolFromPoint (infoPtr
, hwndTool
, &pt
);
1017 if (!(GetWindowLongW (infoPtr
->hwndSelf
, GWL_STYLE
) & TTS_ALWAYSTIP
) && bShowTest
)
1019 TTTOOL_INFO
*ti
= &infoPtr
->tools
[nTool
];
1020 HWND hwnd
= (ti
->uFlags
& TTF_IDISHWND
) ? (HWND
)ti
->uId
: ti
->hwnd
;
1022 if (!TOOLTIPS_IsWindowActive(hwnd
))
1024 TRACE("not active: hwnd %p, parent %p, active %p\n",
1025 hwnd
, GetParent(hwnd
), GetActiveWindow());
1030 TRACE("tool %d\n", nTool
);
1037 TOOLTIPS_Activate (TOOLTIPS_INFO
*infoPtr
, BOOL activate
)
1039 infoPtr
->bActive
= activate
;
1041 TRACE("activate %d\n", activate
);
1043 if (!(infoPtr
->bActive
) && (infoPtr
->nCurrentTool
!= -1))
1044 TOOLTIPS_Hide (infoPtr
);
1051 TOOLTIPS_AddToolT (TOOLTIPS_INFO
*infoPtr
, const TTTOOLINFOW
*ti
, BOOL isW
)
1053 TTTOOL_INFO
*toolPtr
;
1056 if (!ti
) return FALSE
;
1058 TRACE("add tool (%p) %p %ld%s\n", infoPtr
->hwndSelf
, ti
->hwnd
, ti
->uId
,
1059 (ti
->uFlags
& TTF_IDISHWND
) ? " TTF_IDISHWND" : "");
1061 if (ti
->cbSize
> TTTOOLINFOW_V3_SIZE
&& isW
)
1064 if (infoPtr
->uNumTools
== 0) {
1065 infoPtr
->tools
= Alloc (sizeof(TTTOOL_INFO
));
1066 toolPtr
= infoPtr
->tools
;
1069 TTTOOL_INFO
*oldTools
= infoPtr
->tools
;
1071 Alloc (sizeof(TTTOOL_INFO
) * (infoPtr
->uNumTools
+ 1));
1072 memcpy (infoPtr
->tools
, oldTools
,
1073 infoPtr
->uNumTools
* sizeof(TTTOOL_INFO
));
1075 toolPtr
= &infoPtr
->tools
[infoPtr
->uNumTools
];
1078 infoPtr
->uNumTools
++;
1080 /* copy tool data */
1081 toolPtr
->uFlags
= ti
->uFlags
;
1082 toolPtr
->uInternalFlags
= (ti
->uFlags
& (TTF_SUBCLASS
| TTF_IDISHWND
));
1083 toolPtr
->hwnd
= ti
->hwnd
;
1084 toolPtr
->uId
= ti
->uId
;
1085 toolPtr
->rect
= ti
->rect
;
1086 toolPtr
->hinst
= ti
->hinst
;
1088 if (ti
->cbSize
>= TTTOOLINFOW_V1_SIZE
) {
1089 if (IS_INTRESOURCE(ti
->lpszText
)) {
1090 TRACE("add string id %x\n", LOWORD(ti
->lpszText
));
1091 toolPtr
->lpszText
= ti
->lpszText
;
1093 else if (ti
->lpszText
) {
1094 if (TOOLTIPS_IsCallbackString(ti
->lpszText
, isW
)) {
1095 TRACE("add CALLBACK\n");
1096 toolPtr
->lpszText
= LPSTR_TEXTCALLBACKW
;
1099 INT len
= lstrlenW (ti
->lpszText
);
1100 TRACE("add text %s\n", debugstr_w(ti
->lpszText
));
1101 toolPtr
->lpszText
= Alloc ((len
+ 1)*sizeof(WCHAR
));
1102 strcpyW (toolPtr
->lpszText
, ti
->lpszText
);
1105 INT len
= MultiByteToWideChar(CP_ACP
, 0, (LPSTR
)ti
->lpszText
, -1, NULL
, 0);
1106 TRACE("add text \"%s\"\n", debugstr_a((char *)ti
->lpszText
));
1107 toolPtr
->lpszText
= Alloc (len
* sizeof(WCHAR
));
1108 MultiByteToWideChar(CP_ACP
, 0, (LPSTR
)ti
->lpszText
, -1, toolPtr
->lpszText
, len
);
1113 if (ti
->cbSize
>= TTTOOLINFOW_V2_SIZE
)
1114 toolPtr
->lParam
= ti
->lParam
;
1116 /* install subclassing hook */
1117 if (toolPtr
->uInternalFlags
& TTF_SUBCLASS
) {
1118 if (toolPtr
->uInternalFlags
& TTF_IDISHWND
) {
1119 SetWindowSubclass((HWND
)toolPtr
->uId
, TOOLTIPS_SubclassProc
, 1,
1120 (DWORD_PTR
)infoPtr
->hwndSelf
);
1123 SetWindowSubclass(toolPtr
->hwnd
, TOOLTIPS_SubclassProc
, 1,
1124 (DWORD_PTR
)infoPtr
->hwndSelf
);
1126 TRACE("subclassing installed\n");
1129 nResult
= SendMessageW (toolPtr
->hwnd
, WM_NOTIFYFORMAT
,
1130 (WPARAM
)infoPtr
->hwndSelf
, NF_QUERY
);
1131 if (nResult
== NFR_ANSI
) {
1132 toolPtr
->bNotifyUnicode
= FALSE
;
1133 TRACE(" -- WM_NOTIFYFORMAT returns: NFR_ANSI\n");
1134 } else if (nResult
== NFR_UNICODE
) {
1135 toolPtr
->bNotifyUnicode
= TRUE
;
1136 TRACE(" -- WM_NOTIFYFORMAT returns: NFR_UNICODE\n");
1138 TRACE (" -- WM_NOTIFYFORMAT returns: %d\n", nResult
);
1144 static void TOOLTIPS_ResetSubclass (const TTTOOL_INFO
*toolPtr
)
1146 /* Reset subclassing data. */
1147 if (toolPtr
->uInternalFlags
& TTF_SUBCLASS
)
1148 SetWindowSubclass(toolPtr
->uInternalFlags
& TTF_IDISHWND
? (HWND
)toolPtr
->uId
: toolPtr
->hwnd
,
1149 TOOLTIPS_SubclassProc
, 1, 0);
1153 TOOLTIPS_DelToolT (TOOLTIPS_INFO
*infoPtr
, const TTTOOLINFOW
*ti
, BOOL isW
)
1155 TTTOOL_INFO
*toolPtr
;
1159 if (isW
&& ti
->cbSize
> TTTOOLINFOW_V2_SIZE
&&
1160 ti
->cbSize
!= TTTOOLINFOW_V3_SIZE
)
1162 if (infoPtr
->uNumTools
== 0)
1165 nTool
= TOOLTIPS_GetToolFromInfoT (infoPtr
, ti
);
1167 TRACE("tool %d\n", nTool
);
1172 /* make sure the tooltip has disappeared before deleting it */
1173 TOOLTIPS_Hide(infoPtr
);
1175 /* delete text string */
1176 toolPtr
= &infoPtr
->tools
[nTool
];
1177 if (toolPtr
->lpszText
) {
1178 if ( (toolPtr
->lpszText
!= LPSTR_TEXTCALLBACKW
) &&
1179 !IS_INTRESOURCE(toolPtr
->lpszText
) )
1180 Free (toolPtr
->lpszText
);
1183 TOOLTIPS_ResetSubclass (toolPtr
);
1185 /* delete tool from tool list */
1186 if (infoPtr
->uNumTools
== 1) {
1187 Free (infoPtr
->tools
);
1188 infoPtr
->tools
= NULL
;
1191 TTTOOL_INFO
*oldTools
= infoPtr
->tools
;
1193 Alloc (sizeof(TTTOOL_INFO
) * (infoPtr
->uNumTools
- 1));
1196 memcpy (&infoPtr
->tools
[0], &oldTools
[0],
1197 nTool
* sizeof(TTTOOL_INFO
));
1199 if (nTool
< infoPtr
->uNumTools
- 1)
1200 memcpy (&infoPtr
->tools
[nTool
], &oldTools
[nTool
+ 1],
1201 (infoPtr
->uNumTools
- nTool
- 1) * sizeof(TTTOOL_INFO
));
1206 /* update any indices affected by delete */
1208 /* destroying tool that mouse was on on last relayed mouse move */
1209 if (infoPtr
->nTool
== nTool
)
1210 /* -1 means no current tool (0 means first tool) */
1211 infoPtr
->nTool
= -1;
1212 else if (infoPtr
->nTool
> nTool
)
1215 if (infoPtr
->nTrackTool
== nTool
)
1216 /* -1 means no current tool (0 means first tool) */
1217 infoPtr
->nTrackTool
= -1;
1218 else if (infoPtr
->nTrackTool
> nTool
)
1219 infoPtr
->nTrackTool
--;
1221 if (infoPtr
->nCurrentTool
== nTool
)
1222 /* -1 means no current tool (0 means first tool) */
1223 infoPtr
->nCurrentTool
= -1;
1224 else if (infoPtr
->nCurrentTool
> nTool
)
1225 infoPtr
->nCurrentTool
--;
1227 infoPtr
->uNumTools
--;
1233 TOOLTIPS_EnumToolsT (const TOOLTIPS_INFO
*infoPtr
, UINT uIndex
, TTTOOLINFOW
*ti
,
1236 if (!ti
|| ti
->cbSize
< TTTOOLINFOW_V1_SIZE
)
1238 if (uIndex
>= infoPtr
->uNumTools
)
1241 TRACE("index=%u\n", uIndex
);
1243 TOOLTIPS_CopyInfoT (infoPtr
, uIndex
, ti
, isW
);
1249 TOOLTIPS_GetBubbleSize (const TOOLTIPS_INFO
*infoPtr
, const TTTOOLINFOW
*lpToolInfo
)
1254 if (lpToolInfo
== NULL
)
1256 if (lpToolInfo
->cbSize
< TTTOOLINFOW_V1_SIZE
)
1259 nTool
= TOOLTIPS_GetToolFromInfoT (infoPtr
, lpToolInfo
);
1260 if (nTool
== -1) return 0;
1262 TRACE("tool %d\n", nTool
);
1264 TOOLTIPS_CalcTipSize (infoPtr
, &size
);
1265 TRACE("size %d x %d\n", size
.cx
, size
.cy
);
1267 return MAKELRESULT(size
.cx
, size
.cy
);
1271 TOOLTIPS_GetCurrentToolT (const TOOLTIPS_INFO
*infoPtr
, TTTOOLINFOW
*ti
, BOOL isW
)
1274 if (ti
->cbSize
< TTTOOLINFOW_V1_SIZE
)
1277 if (infoPtr
->nCurrentTool
!= -1)
1278 TOOLTIPS_CopyInfoT (infoPtr
, infoPtr
->nCurrentTool
, ti
, isW
);
1281 return infoPtr
->nCurrentTool
!= -1;
1286 TOOLTIPS_GetDelayTime (const TOOLTIPS_INFO
*infoPtr
, DWORD duration
)
1290 return infoPtr
->nReshowTime
;
1293 return infoPtr
->nAutoPopTime
;
1296 case TTDT_AUTOMATIC
: /* Apparently TTDT_AUTOMATIC returns TTDT_INITIAL */
1297 return infoPtr
->nInitialTime
;
1300 WARN("Invalid duration flag %x\n", duration
);
1309 TOOLTIPS_GetMargin (const TOOLTIPS_INFO
*infoPtr
, RECT
*rect
)
1312 *rect
= infoPtr
->rcMargin
;
1318 static inline LRESULT
1319 TOOLTIPS_GetMaxTipWidth (const TOOLTIPS_INFO
*infoPtr
)
1321 return infoPtr
->nMaxTipWidth
;
1326 TOOLTIPS_GetTextT (const TOOLTIPS_INFO
*infoPtr
, TTTOOLINFOW
*ti
, BOOL isW
)
1331 if (ti
->cbSize
< TTTOOLINFOW_V1_SIZE
)
1334 nTool
= TOOLTIPS_GetToolFromInfoT (infoPtr
, ti
);
1335 if (nTool
== -1) return 0;
1337 if (infoPtr
->tools
[nTool
].lpszText
== NULL
)
1341 ti
->lpszText
[0] = '\0';
1342 TOOLTIPS_GetTipText(infoPtr
, nTool
, ti
->lpszText
);
1345 WCHAR buffer
[INFOTIPSIZE
];
1347 /* NB this API is broken, there is no way for the app to determine
1348 what size buffer it requires nor a way to specify how long the
1349 one it supplies is. According to the test result, it's up to
1350 80 bytes by the ANSI version. */
1353 TOOLTIPS_GetTipText(infoPtr
, nTool
, buffer
);
1354 WideCharToMultiByte(CP_ACP
, 0, buffer
, -1, (LPSTR
)ti
->lpszText
,
1355 MAX_TEXT_SIZE_A
, NULL
, NULL
);
1362 static inline LRESULT
1363 TOOLTIPS_GetTipBkColor (const TOOLTIPS_INFO
*infoPtr
)
1365 return infoPtr
->clrBk
;
1369 static inline LRESULT
1370 TOOLTIPS_GetTipTextColor (const TOOLTIPS_INFO
*infoPtr
)
1372 return infoPtr
->clrText
;
1376 static inline LRESULT
1377 TOOLTIPS_GetToolCount (const TOOLTIPS_INFO
*infoPtr
)
1379 return infoPtr
->uNumTools
;
1384 TOOLTIPS_GetToolInfoT (const TOOLTIPS_INFO
*infoPtr
, TTTOOLINFOW
*ti
, BOOL isW
)
1389 if (!ti
) return FALSE
;
1390 if (ti
->cbSize
< TTTOOLINFOW_V1_SIZE
)
1392 if (infoPtr
->uNumTools
== 0)
1395 nTool
= TOOLTIPS_GetToolFromInfoT (infoPtr
, ti
);
1399 TRACE("tool %d\n", nTool
);
1402 TOOLTIPS_CopyInfoT (infoPtr
, nTool
, ti
, isW
);
1410 TOOLTIPS_HitTestT (const TOOLTIPS_INFO
*infoPtr
, LPTTHITTESTINFOW lptthit
,
1418 nTool
= TOOLTIPS_GetToolFromPoint (infoPtr
, lptthit
->hwnd
, &lptthit
->pt
);
1422 TRACE("tool %d\n", nTool
);
1424 /* copy tool data */
1425 if (lptthit
->ti
.cbSize
>= TTTOOLINFOW_V1_SIZE
)
1426 TOOLTIPS_CopyInfoT (infoPtr
, nTool
, &lptthit
->ti
, isW
);
1433 TOOLTIPS_NewToolRectT (TOOLTIPS_INFO
*infoPtr
, const TTTOOLINFOW
*ti
)
1438 if (ti
->cbSize
< TTTOOLINFOW_V1_SIZE
)
1441 nTool
= TOOLTIPS_GetToolFromInfoT (infoPtr
, ti
);
1443 TRACE("nTool = %d, rect = %s\n", nTool
, wine_dbgstr_rect(&ti
->rect
));
1445 if (nTool
== -1) return 0;
1447 infoPtr
->tools
[nTool
].rect
= ti
->rect
;
1453 static inline LRESULT
1454 TOOLTIPS_Pop (TOOLTIPS_INFO
*infoPtr
)
1456 TOOLTIPS_Hide (infoPtr
);
1463 TOOLTIPS_RelayEvent (TOOLTIPS_INFO
*infoPtr
, LPMSG lpMsg
)
1469 ERR("lpMsg == NULL\n");
1473 switch (lpMsg
->message
) {
1474 case WM_LBUTTONDOWN
:
1476 case WM_MBUTTONDOWN
:
1478 case WM_RBUTTONDOWN
:
1480 TOOLTIPS_Hide (infoPtr
);
1484 pt
.x
= (short)LOWORD(lpMsg
->lParam
);
1485 pt
.y
= (short)HIWORD(lpMsg
->lParam
);
1486 nOldTool
= infoPtr
->nTool
;
1487 infoPtr
->nTool
= TOOLTIPS_GetToolFromPoint(infoPtr
, lpMsg
->hwnd
,
1489 TRACE("tool (%p) %d %d %d\n", infoPtr
->hwndSelf
, nOldTool
,
1490 infoPtr
->nTool
, infoPtr
->nCurrentTool
);
1491 TRACE("WM_MOUSEMOVE (%p %s)\n", infoPtr
->hwndSelf
, wine_dbgstr_point(&pt
));
1493 if (infoPtr
->nTool
!= nOldTool
) {
1494 if(infoPtr
->nTool
== -1) { /* Moved out of all tools */
1495 TOOLTIPS_Hide(infoPtr
);
1496 KillTimer(infoPtr
->hwndSelf
, ID_TIMERLEAVE
);
1497 } else if (nOldTool
== -1) { /* Moved from outside */
1498 if(infoPtr
->bActive
) {
1499 SetTimer(infoPtr
->hwndSelf
, ID_TIMERSHOW
, infoPtr
->nInitialTime
, 0);
1500 TRACE("timer 1 started\n");
1502 } else { /* Moved from one to another */
1503 TOOLTIPS_Hide (infoPtr
);
1504 KillTimer(infoPtr
->hwndSelf
, ID_TIMERLEAVE
);
1505 if(infoPtr
->bActive
) {
1506 SetTimer (infoPtr
->hwndSelf
, ID_TIMERSHOW
, infoPtr
->nReshowTime
, 0);
1507 TRACE("timer 1 started\n");
1510 } else if(infoPtr
->nCurrentTool
!= -1) { /* restart autopop */
1511 KillTimer(infoPtr
->hwndSelf
, ID_TIMERPOP
);
1512 SetTimer(infoPtr
->hwndSelf
, ID_TIMERPOP
, infoPtr
->nAutoPopTime
, 0);
1513 TRACE("timer 2 restarted\n");
1514 } else if(infoPtr
->nTool
!= -1 && infoPtr
->bActive
) {
1515 /* previous show attempt didn't result in tooltip so try again */
1516 SetTimer(infoPtr
->hwndSelf
, ID_TIMERSHOW
, infoPtr
->nInitialTime
, 0);
1517 TRACE("timer 1 started\n");
1527 TOOLTIPS_SetDelayTime (TOOLTIPS_INFO
*infoPtr
, DWORD duration
, INT nTime
)
1530 case TTDT_AUTOMATIC
:
1532 nTime
= GetDoubleClickTime();
1533 infoPtr
->nReshowTime
= nTime
/ 5;
1534 infoPtr
->nAutoPopTime
= nTime
* 10;
1535 infoPtr
->nInitialTime
= nTime
;
1540 nTime
= GetDoubleClickTime() / 5;
1541 infoPtr
->nReshowTime
= nTime
;
1546 nTime
= GetDoubleClickTime() * 10;
1547 infoPtr
->nAutoPopTime
= nTime
;
1552 nTime
= GetDoubleClickTime();
1553 infoPtr
->nInitialTime
= nTime
;
1557 WARN("Invalid duration flag %x\n", duration
);
1566 TOOLTIPS_SetMargin (TOOLTIPS_INFO
*infoPtr
, const RECT
*rect
)
1569 infoPtr
->rcMargin
= *rect
;
1575 static inline LRESULT
1576 TOOLTIPS_SetMaxTipWidth (TOOLTIPS_INFO
*infoPtr
, INT MaxWidth
)
1578 INT nTemp
= infoPtr
->nMaxTipWidth
;
1580 infoPtr
->nMaxTipWidth
= MaxWidth
;
1586 static inline LRESULT
1587 TOOLTIPS_SetTipBkColor (TOOLTIPS_INFO
*infoPtr
, COLORREF clrBk
)
1589 infoPtr
->clrBk
= clrBk
;
1595 static inline LRESULT
1596 TOOLTIPS_SetTipTextColor (TOOLTIPS_INFO
*infoPtr
, COLORREF clrText
)
1598 infoPtr
->clrText
= clrText
;
1605 TOOLTIPS_SetTitleT (TOOLTIPS_INFO
*infoPtr
, UINT_PTR uTitleIcon
, LPCWSTR pszTitle
,
1610 TRACE("hwnd = %p, title = %s, icon = %p\n", infoPtr
->hwndSelf
, debugstr_w(pszTitle
),
1613 Free(infoPtr
->pszTitle
);
1619 size
= (strlenW(pszTitle
)+1)*sizeof(WCHAR
);
1620 infoPtr
->pszTitle
= Alloc(size
);
1621 if (!infoPtr
->pszTitle
)
1623 memcpy(infoPtr
->pszTitle
, pszTitle
, size
);
1627 size
= sizeof(WCHAR
)*MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)pszTitle
, -1, NULL
, 0);
1628 infoPtr
->pszTitle
= Alloc(size
);
1629 if (!infoPtr
->pszTitle
)
1631 MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)pszTitle
, -1, infoPtr
->pszTitle
, size
/sizeof(WCHAR
));
1635 infoPtr
->pszTitle
= NULL
;
1637 if (uTitleIcon
<= TTI_ERROR
)
1638 infoPtr
->hTitleIcon
= hTooltipIcons
[uTitleIcon
];
1640 infoPtr
->hTitleIcon
= CopyIcon((HICON
)uTitleIcon
);
1642 TRACE("icon = %p\n", infoPtr
->hTitleIcon
);
1649 TOOLTIPS_SetToolInfoT (TOOLTIPS_INFO
*infoPtr
, const TTTOOLINFOW
*ti
, BOOL isW
)
1651 TTTOOL_INFO
*toolPtr
;
1655 if (ti
->cbSize
< TTTOOLINFOW_V1_SIZE
)
1658 nTool
= TOOLTIPS_GetToolFromInfoT (infoPtr
, ti
);
1659 if (nTool
== -1) return 0;
1661 TRACE("tool %d\n", nTool
);
1663 toolPtr
= &infoPtr
->tools
[nTool
];
1665 /* copy tool data */
1666 toolPtr
->uFlags
= ti
->uFlags
;
1667 toolPtr
->hwnd
= ti
->hwnd
;
1668 toolPtr
->uId
= ti
->uId
;
1669 toolPtr
->rect
= ti
->rect
;
1670 toolPtr
->hinst
= ti
->hinst
;
1672 if (IS_INTRESOURCE(ti
->lpszText
)) {
1673 TRACE("set string id %x\n", LOWORD(ti
->lpszText
));
1674 toolPtr
->lpszText
= ti
->lpszText
;
1677 if (TOOLTIPS_IsCallbackString(ti
->lpszText
, isW
))
1678 toolPtr
->lpszText
= LPSTR_TEXTCALLBACKW
;
1680 if ( (toolPtr
->lpszText
) &&
1681 !IS_INTRESOURCE(toolPtr
->lpszText
) ) {
1682 if( toolPtr
->lpszText
!= LPSTR_TEXTCALLBACKW
)
1683 Free (toolPtr
->lpszText
);
1684 toolPtr
->lpszText
= NULL
;
1688 INT len
= lstrlenW (ti
->lpszText
);
1689 toolPtr
->lpszText
= Alloc ((len
+1)*sizeof(WCHAR
));
1690 strcpyW (toolPtr
->lpszText
, ti
->lpszText
);
1693 INT len
= MultiByteToWideChar(CP_ACP
, 0, (LPSTR
)ti
->lpszText
,
1695 toolPtr
->lpszText
= Alloc (len
* sizeof(WCHAR
));
1696 MultiByteToWideChar(CP_ACP
, 0, (LPSTR
)ti
->lpszText
, -1,
1697 toolPtr
->lpszText
, len
);
1703 if (ti
->cbSize
>= TTTOOLINFOW_V2_SIZE
)
1704 toolPtr
->lParam
= ti
->lParam
;
1706 if (infoPtr
->nCurrentTool
== nTool
)
1708 TOOLTIPS_GetTipText (infoPtr
, infoPtr
->nCurrentTool
, infoPtr
->szTipText
);
1710 if (infoPtr
->szTipText
[0] == 0)
1711 TOOLTIPS_Hide(infoPtr
);
1713 TOOLTIPS_Show (infoPtr
, FALSE
);
1721 TOOLTIPS_TrackActivate (TOOLTIPS_INFO
*infoPtr
, BOOL track_activate
, const TTTOOLINFOA
*ti
)
1723 if (track_activate
) {
1726 if (ti
->cbSize
< TTTOOLINFOA_V1_SIZE
)
1730 infoPtr
->nTrackTool
= TOOLTIPS_GetToolFromInfoT (infoPtr
, (const TTTOOLINFOW
*)ti
);
1731 if (infoPtr
->nTrackTool
!= -1) {
1732 TRACE("activated\n");
1733 infoPtr
->bTrackActive
= TRUE
;
1734 TOOLTIPS_TrackShow (infoPtr
);
1739 TOOLTIPS_TrackHide (infoPtr
);
1741 infoPtr
->bTrackActive
= FALSE
;
1742 infoPtr
->nTrackTool
= -1;
1744 TRACE("deactivated\n");
1752 TOOLTIPS_TrackPosition (TOOLTIPS_INFO
*infoPtr
, LPARAM coord
)
1754 infoPtr
->xTrackPos
= (INT
)LOWORD(coord
);
1755 infoPtr
->yTrackPos
= (INT
)HIWORD(coord
);
1757 if (infoPtr
->bTrackActive
) {
1759 infoPtr
->xTrackPos
, infoPtr
->yTrackPos
);
1761 TOOLTIPS_TrackShow (infoPtr
);
1769 TOOLTIPS_Update (TOOLTIPS_INFO
*infoPtr
)
1771 if (infoPtr
->nCurrentTool
!= -1)
1772 UpdateWindow (infoPtr
->hwndSelf
);
1779 TOOLTIPS_UpdateTipTextT (TOOLTIPS_INFO
*infoPtr
, const TTTOOLINFOW
*ti
, BOOL isW
)
1781 TTTOOL_INFO
*toolPtr
;
1785 if (ti
->cbSize
< TTTOOLINFOW_V1_SIZE
)
1788 nTool
= TOOLTIPS_GetToolFromInfoT (infoPtr
, ti
);
1792 TRACE("tool %d\n", nTool
);
1794 toolPtr
= &infoPtr
->tools
[nTool
];
1796 /* copy tool text */
1797 toolPtr
->hinst
= ti
->hinst
;
1799 if (IS_INTRESOURCE(ti
->lpszText
)){
1800 toolPtr
->lpszText
= ti
->lpszText
;
1802 else if (ti
->lpszText
) {
1803 if (TOOLTIPS_IsCallbackString(ti
->lpszText
, isW
))
1804 toolPtr
->lpszText
= LPSTR_TEXTCALLBACKW
;
1806 if ( (toolPtr
->lpszText
) &&
1807 !IS_INTRESOURCE(toolPtr
->lpszText
) ) {
1808 if( toolPtr
->lpszText
!= LPSTR_TEXTCALLBACKW
)
1809 Free (toolPtr
->lpszText
);
1810 toolPtr
->lpszText
= NULL
;
1814 INT len
= lstrlenW (ti
->lpszText
);
1815 toolPtr
->lpszText
= Alloc ((len
+1)*sizeof(WCHAR
));
1816 strcpyW (toolPtr
->lpszText
, ti
->lpszText
);
1819 INT len
= MultiByteToWideChar(CP_ACP
, 0, (LPSTR
)ti
->lpszText
,
1821 toolPtr
->lpszText
= Alloc (len
* sizeof(WCHAR
));
1822 MultiByteToWideChar(CP_ACP
, 0, (LPSTR
)ti
->lpszText
, -1,
1823 toolPtr
->lpszText
, len
);
1829 if(infoPtr
->nCurrentTool
== -1) return 0;
1831 if (infoPtr
->bActive
)
1832 TOOLTIPS_Show (infoPtr
, FALSE
);
1833 else if (infoPtr
->bTrackActive
)
1834 TOOLTIPS_Show (infoPtr
, TRUE
);
1841 TOOLTIPS_Create (HWND hwnd
)
1843 TOOLTIPS_INFO
*infoPtr
;
1845 /* allocate memory for info structure */
1846 infoPtr
= Alloc (sizeof(TOOLTIPS_INFO
));
1847 SetWindowLongPtrW (hwnd
, 0, (DWORD_PTR
)infoPtr
);
1849 /* initialize info structure */
1850 infoPtr
->bActive
= TRUE
;
1851 infoPtr
->bTrackActive
= FALSE
;
1853 infoPtr
->nMaxTipWidth
= -1;
1854 infoPtr
->nTool
= -1;
1855 infoPtr
->nCurrentTool
= -1;
1856 infoPtr
->nTrackTool
= -1;
1857 infoPtr
->hwndSelf
= hwnd
;
1859 /* initialize colours and fonts */
1860 TOOLTIPS_InitSystemSettings(infoPtr
);
1862 TOOLTIPS_SetDelayTime(infoPtr
, TTDT_AUTOMATIC
, 0);
1864 SetWindowPos (hwnd
, HWND_TOP
, 0, 0, 0, 0, SWP_NOZORDER
| SWP_HIDEWINDOW
| SWP_NOACTIVATE
);
1871 TOOLTIPS_Destroy (TOOLTIPS_INFO
*infoPtr
)
1873 TTTOOL_INFO
*toolPtr
;
1877 if (infoPtr
->tools
) {
1878 for (i
= 0; i
< infoPtr
->uNumTools
; i
++) {
1879 toolPtr
= &infoPtr
->tools
[i
];
1880 if (toolPtr
->lpszText
) {
1881 if ( (toolPtr
->lpszText
!= LPSTR_TEXTCALLBACKW
) &&
1882 !IS_INTRESOURCE(toolPtr
->lpszText
) )
1884 Free (toolPtr
->lpszText
);
1885 toolPtr
->lpszText
= NULL
;
1889 TOOLTIPS_ResetSubclass (toolPtr
);
1892 Free (infoPtr
->tools
);
1895 /* free title string */
1896 Free (infoPtr
->pszTitle
);
1897 /* free title icon if not a standard one */
1898 if (TOOLTIPS_GetTitleIconIndex(infoPtr
->hTitleIcon
) > TTI_ERROR
)
1899 DeleteObject(infoPtr
->hTitleIcon
);
1902 DeleteObject (infoPtr
->hFont
);
1903 DeleteObject (infoPtr
->hTitleFont
);
1905 /* free tool tips info data */
1906 SetWindowLongPtrW(infoPtr
->hwndSelf
, 0, 0);
1913 static inline LRESULT
1914 TOOLTIPS_GetFont (const TOOLTIPS_INFO
*infoPtr
)
1916 return (LRESULT
)infoPtr
->hFont
;
1921 TOOLTIPS_MouseMessage (TOOLTIPS_INFO
*infoPtr
)
1923 TOOLTIPS_Hide (infoPtr
);
1930 TOOLTIPS_NCCreate (HWND hwnd
)
1932 DWORD dwStyle
= GetWindowLongW (hwnd
, GWL_STYLE
);
1933 DWORD dwExStyle
= GetWindowLongW (hwnd
, GWL_EXSTYLE
);
1935 dwStyle
&= ~(WS_CHILD
| /*WS_MAXIMIZE |*/ WS_BORDER
| WS_DLGFRAME
);
1936 dwStyle
|= (WS_POPUP
| WS_BORDER
| WS_CLIPSIBLINGS
);
1938 /* WS_BORDER only draws a border round the window rect, not the
1939 * window region, therefore it is useless to us in balloon mode */
1940 if (dwStyle
& TTS_BALLOON
) dwStyle
&= ~WS_BORDER
;
1942 SetWindowLongW (hwnd
, GWL_STYLE
, dwStyle
);
1944 dwExStyle
|= WS_EX_TOOLWINDOW
;
1945 SetWindowLongW (hwnd
, GWL_EXSTYLE
, dwExStyle
);
1952 TOOLTIPS_NCHitTest (const TOOLTIPS_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
1954 INT nTool
= (infoPtr
->bTrackActive
) ? infoPtr
->nTrackTool
: infoPtr
->nTool
;
1956 TRACE(" nTool=%d\n", nTool
);
1958 if ((nTool
> -1) && (nTool
< infoPtr
->uNumTools
)) {
1959 if (infoPtr
->tools
[nTool
].uFlags
& TTF_TRANSPARENT
) {
1960 TRACE("-- in transparent mode\n");
1961 return HTTRANSPARENT
;
1965 return DefWindowProcW (infoPtr
->hwndSelf
, WM_NCHITTEST
, wParam
, lParam
);
1970 TOOLTIPS_NotifyFormat (TOOLTIPS_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
1972 FIXME ("hwnd=%p wParam=%lx lParam=%lx\n", infoPtr
->hwndSelf
, wParam
, lParam
);
1979 TOOLTIPS_Paint (const TOOLTIPS_INFO
*infoPtr
, HDC hDC
)
1984 hdc
= (hDC
== NULL
) ? BeginPaint (infoPtr
->hwndSelf
, &ps
) : hDC
;
1985 TOOLTIPS_Refresh (infoPtr
, hdc
);
1987 EndPaint (infoPtr
->hwndSelf
, &ps
);
1993 TOOLTIPS_SetFont (TOOLTIPS_INFO
*infoPtr
, HFONT hFont
, BOOL redraw
)
1997 if(!GetObjectW(hFont
, sizeof(lf
), &lf
))
2000 DeleteObject (infoPtr
->hFont
);
2001 infoPtr
->hFont
= CreateFontIndirectW(&lf
);
2003 DeleteObject (infoPtr
->hTitleFont
);
2004 lf
.lfWeight
= FW_BOLD
;
2005 infoPtr
->hTitleFont
= CreateFontIndirectW(&lf
);
2007 if (redraw
&& infoPtr
->nCurrentTool
!= -1)
2008 FIXME("full redraw needed\n");
2013 /******************************************************************
2014 * TOOLTIPS_GetTextLength
2016 * This function is called when the tooltip receive a
2017 * WM_GETTEXTLENGTH message.
2019 * returns the length, in characters, of the tip text
2021 static inline LRESULT
2022 TOOLTIPS_GetTextLength(const TOOLTIPS_INFO
*infoPtr
)
2024 return strlenW(infoPtr
->szTipText
);
2027 /******************************************************************
2028 * TOOLTIPS_OnWMGetText
2030 * This function is called when the tooltip receive a
2031 * WM_GETTEXT message.
2032 * wParam : specifies the maximum number of characters to be copied
2033 * lParam : is the pointer to the buffer that will receive
2036 * returns the number of characters copied
2039 TOOLTIPS_OnWMGetText (const TOOLTIPS_INFO
*infoPtr
, WPARAM size
, LPWSTR pszText
)
2046 res
= min(strlenW(infoPtr
->szTipText
)+1, size
);
2047 memcpy(pszText
, infoPtr
->szTipText
, res
*sizeof(WCHAR
));
2048 pszText
[res
-1] = '\0';
2053 TOOLTIPS_Timer (TOOLTIPS_INFO
*infoPtr
, INT iTimer
)
2057 TRACE("timer %d (%p) expired\n", iTimer
, infoPtr
->hwndSelf
);
2061 KillTimer (infoPtr
->hwndSelf
, ID_TIMERSHOW
);
2062 nOldTool
= infoPtr
->nTool
;
2063 if ((infoPtr
->nTool
= TOOLTIPS_CheckTool (infoPtr
, TRUE
)) == nOldTool
)
2064 TOOLTIPS_Show (infoPtr
, FALSE
);
2068 TOOLTIPS_Hide (infoPtr
);
2072 nOldTool
= infoPtr
->nTool
;
2073 infoPtr
->nTool
= TOOLTIPS_CheckTool (infoPtr
, FALSE
);
2074 TRACE("tool (%p) %d %d %d\n", infoPtr
->hwndSelf
, nOldTool
,
2075 infoPtr
->nTool
, infoPtr
->nCurrentTool
);
2076 if (infoPtr
->nTool
!= nOldTool
) {
2077 if(infoPtr
->nTool
== -1) { /* Moved out of all tools */
2078 TOOLTIPS_Hide(infoPtr
);
2079 KillTimer(infoPtr
->hwndSelf
, ID_TIMERLEAVE
);
2080 } else if (nOldTool
== -1) { /* Moved from outside */
2081 ERR("How did this happen?\n");
2082 } else { /* Moved from one to another */
2083 TOOLTIPS_Hide (infoPtr
);
2084 KillTimer(infoPtr
->hwndSelf
, ID_TIMERLEAVE
);
2085 if(infoPtr
->bActive
) {
2086 SetTimer (infoPtr
->hwndSelf
, ID_TIMERSHOW
, infoPtr
->nReshowTime
, 0);
2087 TRACE("timer 1 started!\n");
2094 ERR("Unknown timer id %d\n", iTimer
);
2102 TOOLTIPS_WinIniChange (TOOLTIPS_INFO
*infoPtr
)
2104 TOOLTIPS_InitSystemSettings (infoPtr
);
2110 static LRESULT CALLBACK
2111 TOOLTIPS_SubclassProc (HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
, UINT_PTR uID
, DWORD_PTR dwRef
)
2113 TOOLTIPS_INFO
*infoPtr
= TOOLTIPS_GetInfoPtr ((HWND
)dwRef
);
2119 case WM_LBUTTONDOWN
:
2121 case WM_MBUTTONDOWN
:
2123 case WM_RBUTTONDOWN
:
2128 msg
.message
= message
;
2129 msg
.wParam
= wParam
;
2130 msg
.lParam
= lParam
;
2131 TOOLTIPS_RelayEvent(infoPtr
, &msg
);
2135 RemoveWindowSubclass(hwnd
, TOOLTIPS_SubclassProc
, 1);
2141 return DefSubclassProc(hwnd
, message
, wParam
, lParam
);
2145 static LRESULT CALLBACK
2146 TOOLTIPS_WindowProc (HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
2148 TOOLTIPS_INFO
*infoPtr
= TOOLTIPS_GetInfoPtr (hwnd
);
2150 TRACE("hwnd=%p msg=%x wparam=%lx lParam=%lx\n", hwnd
, uMsg
, wParam
, lParam
);
2151 if (!infoPtr
&& (uMsg
!= WM_CREATE
) && (uMsg
!= WM_NCCREATE
))
2152 return DefWindowProcW (hwnd
, uMsg
, wParam
, lParam
);
2156 return TOOLTIPS_Activate (infoPtr
, (BOOL
)wParam
);
2160 return TOOLTIPS_AddToolT (infoPtr
, (LPTTTOOLINFOW
)lParam
, uMsg
== TTM_ADDTOOLW
);
2164 return TOOLTIPS_DelToolT (infoPtr
, (LPTOOLINFOW
)lParam
,
2165 uMsg
== TTM_DELTOOLW
);
2166 case TTM_ENUMTOOLSA
:
2167 case TTM_ENUMTOOLSW
:
2168 return TOOLTIPS_EnumToolsT (infoPtr
, (UINT
)wParam
, (LPTTTOOLINFOW
)lParam
,
2169 uMsg
== TTM_ENUMTOOLSW
);
2170 case TTM_GETBUBBLESIZE
:
2171 return TOOLTIPS_GetBubbleSize (infoPtr
, (LPTTTOOLINFOW
)lParam
);
2173 case TTM_GETCURRENTTOOLA
:
2174 case TTM_GETCURRENTTOOLW
:
2175 return TOOLTIPS_GetCurrentToolT (infoPtr
, (LPTTTOOLINFOW
)lParam
,
2176 uMsg
== TTM_GETCURRENTTOOLW
);
2178 case TTM_GETDELAYTIME
:
2179 return TOOLTIPS_GetDelayTime (infoPtr
, (DWORD
)wParam
);
2182 return TOOLTIPS_GetMargin (infoPtr
, (LPRECT
)lParam
);
2184 case TTM_GETMAXTIPWIDTH
:
2185 return TOOLTIPS_GetMaxTipWidth (infoPtr
);
2189 return TOOLTIPS_GetTextT (infoPtr
, (LPTTTOOLINFOW
)lParam
,
2190 uMsg
== TTM_GETTEXTW
);
2192 case TTM_GETTIPBKCOLOR
:
2193 return TOOLTIPS_GetTipBkColor (infoPtr
);
2195 case TTM_GETTIPTEXTCOLOR
:
2196 return TOOLTIPS_GetTipTextColor (infoPtr
);
2198 case TTM_GETTOOLCOUNT
:
2199 return TOOLTIPS_GetToolCount (infoPtr
);
2201 case TTM_GETTOOLINFOA
:
2202 case TTM_GETTOOLINFOW
:
2203 return TOOLTIPS_GetToolInfoT (infoPtr
, (LPTTTOOLINFOW
)lParam
,
2204 uMsg
== TTM_GETTOOLINFOW
);
2208 return TOOLTIPS_HitTestT (infoPtr
, (LPTTHITTESTINFOW
)lParam
,
2209 uMsg
== TTM_HITTESTW
);
2210 case TTM_NEWTOOLRECTA
:
2211 case TTM_NEWTOOLRECTW
:
2212 return TOOLTIPS_NewToolRectT (infoPtr
, (LPTTTOOLINFOW
)lParam
);
2215 return TOOLTIPS_Pop (infoPtr
);
2217 case TTM_RELAYEVENT
:
2218 return TOOLTIPS_RelayEvent (infoPtr
, (LPMSG
)lParam
);
2220 case TTM_SETDELAYTIME
:
2221 return TOOLTIPS_SetDelayTime (infoPtr
, (DWORD
)wParam
, (INT
)LOWORD(lParam
));
2224 return TOOLTIPS_SetMargin (infoPtr
, (LPRECT
)lParam
);
2226 case TTM_SETMAXTIPWIDTH
:
2227 return TOOLTIPS_SetMaxTipWidth (infoPtr
, (INT
)lParam
);
2229 case TTM_SETTIPBKCOLOR
:
2230 return TOOLTIPS_SetTipBkColor (infoPtr
, (COLORREF
)wParam
);
2232 case TTM_SETTIPTEXTCOLOR
:
2233 return TOOLTIPS_SetTipTextColor (infoPtr
, (COLORREF
)wParam
);
2237 return TOOLTIPS_SetTitleT (infoPtr
, (UINT_PTR
)wParam
, (LPCWSTR
)lParam
,
2238 uMsg
== TTM_SETTITLEW
);
2240 case TTM_SETTOOLINFOA
:
2241 case TTM_SETTOOLINFOW
:
2242 return TOOLTIPS_SetToolInfoT (infoPtr
, (LPTTTOOLINFOW
)lParam
,
2243 uMsg
== TTM_SETTOOLINFOW
);
2245 case TTM_TRACKACTIVATE
:
2246 return TOOLTIPS_TrackActivate (infoPtr
, (BOOL
)wParam
, (LPTTTOOLINFOA
)lParam
);
2248 case TTM_TRACKPOSITION
:
2249 return TOOLTIPS_TrackPosition (infoPtr
, lParam
);
2252 return TOOLTIPS_Update (infoPtr
);
2254 case TTM_UPDATETIPTEXTA
:
2255 case TTM_UPDATETIPTEXTW
:
2256 return TOOLTIPS_UpdateTipTextT (infoPtr
, (LPTTTOOLINFOW
)lParam
,
2257 uMsg
== TTM_UPDATETIPTEXTW
);
2259 case TTM_WINDOWFROMPOINT
:
2260 return (LRESULT
)WindowFromPoint (*((LPPOINT
)lParam
));
2263 return TOOLTIPS_Create (hwnd
);
2266 return TOOLTIPS_Destroy (infoPtr
);
2269 /* we draw the background in WM_PAINT */
2273 return TOOLTIPS_GetFont (infoPtr
);
2276 return TOOLTIPS_OnWMGetText (infoPtr
, wParam
, (LPWSTR
)lParam
);
2278 case WM_GETTEXTLENGTH
:
2279 return TOOLTIPS_GetTextLength (infoPtr
);
2281 case WM_LBUTTONDOWN
:
2283 case WM_MBUTTONDOWN
:
2285 case WM_RBUTTONDOWN
:
2288 return TOOLTIPS_MouseMessage (infoPtr
);
2291 return TOOLTIPS_NCCreate (hwnd
);
2294 return TOOLTIPS_NCHitTest (infoPtr
, wParam
, lParam
);
2296 case WM_NOTIFYFORMAT
:
2297 return TOOLTIPS_NotifyFormat (infoPtr
, wParam
, lParam
);
2299 case WM_PRINTCLIENT
:
2301 return TOOLTIPS_Paint (infoPtr
, (HDC
)wParam
);
2304 return TOOLTIPS_SetFont (infoPtr
, (HFONT
)wParam
, LOWORD(lParam
));
2306 case WM_SYSCOLORCHANGE
:
2307 COMCTL32_RefreshSysColors();
2311 return TOOLTIPS_Timer (infoPtr
, (INT
)wParam
);
2313 case WM_WININICHANGE
:
2314 return TOOLTIPS_WinIniChange (infoPtr
);
2317 if ((uMsg
>= WM_USER
) && (uMsg
< WM_APP
) && !COMCTL32_IsReflectedMessage(uMsg
))
2318 ERR("unknown msg %04x wp=%08lx lp=%08lx\n",
2319 uMsg
, wParam
, lParam
);
2320 return DefWindowProcW (hwnd
, uMsg
, wParam
, lParam
);
2326 TOOLTIPS_Register (void)
2330 ZeroMemory (&wndClass
, sizeof(WNDCLASSW
));
2331 wndClass
.style
= CS_GLOBALCLASS
| CS_DBLCLKS
| CS_SAVEBITS
;
2332 wndClass
.lpfnWndProc
= TOOLTIPS_WindowProc
;
2333 wndClass
.cbClsExtra
= 0;
2334 wndClass
.cbWndExtra
= sizeof(TOOLTIPS_INFO
*);
2335 wndClass
.hCursor
= LoadCursorW (0, (LPWSTR
)IDC_ARROW
);
2336 wndClass
.hbrBackground
= 0;
2337 wndClass
.lpszClassName
= TOOLTIPS_CLASSW
;
2339 RegisterClassW (&wndClass
);
2341 hTooltipIcons
[TTI_NONE
] = NULL
;
2342 hTooltipIcons
[TTI_INFO
] = LoadImageW(COMCTL32_hModule
,
2343 (LPCWSTR
)MAKEINTRESOURCE(IDI_TT_INFO_SM
), IMAGE_ICON
, 0, 0, 0);
2344 hTooltipIcons
[TTI_WARNING
] = LoadImageW(COMCTL32_hModule
,
2345 (LPCWSTR
)MAKEINTRESOURCE(IDI_TT_WARN_SM
), IMAGE_ICON
, 0, 0, 0);
2346 hTooltipIcons
[TTI_ERROR
] = LoadImageW(COMCTL32_hModule
,
2347 (LPCWSTR
)MAKEINTRESOURCE(IDI_TT_ERROR_SM
), IMAGE_ICON
, 0, 0, 0);
2352 TOOLTIPS_Unregister (void)
2355 for (i
= TTI_INFO
; i
<= TTI_ERROR
; i
++)
2356 DestroyIcon(hTooltipIcons
[i
]);
2357 UnregisterClassW (TOOLTIPS_CLASSW
, NULL
);