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 (-1)!\n");
600 nTool
= infoPtr
->nTrackTool
;
604 if (infoPtr
->nTool
== -1)
606 TRACE("invalid tool (-1)!\n");
609 nTool
= infoPtr
->nTool
;
612 TRACE("Show tooltip pre %d! (%p)\n", nTool
, infoPtr
->hwndSelf
);
614 TOOLTIPS_GetTipText (infoPtr
, nTool
, infoPtr
->szTipText
);
616 if (infoPtr
->szTipText
[0] == '\0')
619 toolPtr
= &infoPtr
->tools
[nTool
];
622 infoPtr
->nCurrentTool
= infoPtr
->nTool
;
624 TRACE("Show tooltip %d!\n", nTool
);
626 hdr
.hwndFrom
= infoPtr
->hwndSelf
;
627 hdr
.idFrom
= toolPtr
->uId
;
629 SendMessageW (toolPtr
->hwnd
, WM_NOTIFY
, toolPtr
->uId
, (LPARAM
)&hdr
);
631 TRACE("%s\n", debugstr_w(infoPtr
->szTipText
));
633 TOOLTIPS_CalcTipSize (infoPtr
, &size
);
634 TRACE("size %d x %d\n", size
.cx
, size
.cy
);
636 if (track_activate
&& (toolPtr
->uFlags
& TTF_TRACK
))
638 rect
.left
= infoPtr
->xTrackPos
;
639 rect
.top
= infoPtr
->yTrackPos
;
642 if (toolPtr
->uFlags
& TTF_CENTERTIP
)
644 rect
.left
-= (size
.cx
/ 2);
645 if (!(style
& TTS_BALLOON
))
646 rect
.top
-= (size
.cy
/ 2);
648 if (!(infoPtr
->bToolBelow
= (infoPtr
->yTrackPos
+ size
.cy
<= GetSystemMetrics(SM_CYSCREEN
))))
651 if (!(toolPtr
->uFlags
& TTF_ABSOLUTE
))
653 if (style
& TTS_BALLOON
)
654 rect
.left
-= BALLOON_STEMINDENT
;
659 if (toolPtr
->uFlags
& TTF_IDISHWND
)
660 GetWindowRect ((HWND
)toolPtr
->uId
, &rcTool
);
663 rcTool
= toolPtr
->rect
;
664 MapWindowPoints (toolPtr
->hwnd
, NULL
, (LPPOINT
)&rcTool
, 2);
667 /* smart placement */
668 if ((rect
.left
+ size
.cx
> rcTool
.left
) && (rect
.left
< rcTool
.right
) &&
669 (rect
.top
+ size
.cy
> rcTool
.top
) && (rect
.top
< rcTool
.bottom
))
670 rect
.left
= rcTool
.right
;
676 if (toolPtr
->uFlags
& TTF_CENTERTIP
)
680 if (toolPtr
->uFlags
& TTF_IDISHWND
)
681 GetWindowRect ((HWND
)toolPtr
->uId
, &rc
);
684 MapWindowPoints (toolPtr
->hwnd
, NULL
, (LPPOINT
)&rc
, 2);
686 rect
.left
= (rc
.left
+ rc
.right
- size
.cx
) / 2;
687 if (style
& TTS_BALLOON
)
689 ptfx
= rc
.left
+ ((rc
.right
- rc
.left
) / 2);
691 /* CENTERTIP ballon tooltips default to below the field
692 * if they fit on the screen */
693 if (rc
.bottom
+ size
.cy
> GetSystemMetrics(SM_CYSCREEN
))
695 rect
.top
= rc
.top
- size
.cy
;
696 infoPtr
->bToolBelow
= FALSE
;
700 infoPtr
->bToolBelow
= TRUE
;
701 rect
.top
= rc
.bottom
;
703 rect
.left
= max(0, rect
.left
- BALLOON_STEMINDENT
);
707 rect
.top
= rc
.bottom
+ 2;
708 infoPtr
->bToolBelow
= TRUE
;
713 GetCursorPos ((LPPOINT
)&rect
);
714 if (style
& TTS_BALLOON
)
717 if(rect
.top
- size
.cy
>= 0)
720 infoPtr
->bToolBelow
= FALSE
;
724 infoPtr
->bToolBelow
= TRUE
;
727 rect
.left
= max(0, rect
.left
- BALLOON_STEMINDENT
);
732 infoPtr
->bToolBelow
= TRUE
;
737 TRACE("pos %d - %d\n", rect
.left
, rect
.top
);
739 rect
.right
= rect
.left
+ size
.cx
;
740 rect
.bottom
= rect
.top
+ size
.cy
;
744 monitor
= MonitorFromRect( &rect
, MONITOR_DEFAULTTOPRIMARY
);
745 mon_info
.cbSize
= sizeof(mon_info
);
746 GetMonitorInfoW( monitor
, &mon_info
);
748 if( rect
.right
> mon_info
.rcWork
.right
) {
749 rect
.left
-= rect
.right
- mon_info
.rcWork
.right
+ 2;
750 rect
.right
= mon_info
.rcWork
.right
- 2;
752 if (rect
.left
< mon_info
.rcWork
.left
) rect
.left
= mon_info
.rcWork
.left
;
754 if( rect
.bottom
> mon_info
.rcWork
.bottom
) {
757 if (toolPtr
->uFlags
& TTF_IDISHWND
)
758 GetWindowRect ((HWND
)toolPtr
->uId
, &rc
);
761 MapWindowPoints (toolPtr
->hwnd
, NULL
, (LPPOINT
)&rc
, 2);
763 rect
.bottom
= rc
.top
- 2;
764 rect
.top
= rect
.bottom
- size
.cy
;
767 AdjustWindowRectEx (&rect
, GetWindowLongW (infoPtr
->hwndSelf
, GWL_STYLE
),
768 FALSE
, GetWindowLongW (infoPtr
->hwndSelf
, GWL_EXSTYLE
));
770 if (style
& TTS_BALLOON
)
778 if(infoPtr
->bToolBelow
)
782 pts
[1].x
= max(BALLOON_STEMINDENT
, ptfx
- (BALLOON_STEMWIDTH
/ 2));
783 pts
[1].y
= BALLOON_STEMHEIGHT
;
784 pts
[2].x
= pts
[1].x
+ BALLOON_STEMWIDTH
;
786 if(pts
[2].x
> (rect
.right
- rect
.left
) - BALLOON_STEMINDENT
)
788 pts
[2].x
= (rect
.right
- rect
.left
) - BALLOON_STEMINDENT
;
789 pts
[1].x
= pts
[2].x
- BALLOON_STEMWIDTH
;
794 pts
[0].x
= max(BALLOON_STEMINDENT
, ptfx
- (BALLOON_STEMWIDTH
/ 2));
795 pts
[0].y
= (rect
.bottom
- rect
.top
) - BALLOON_STEMHEIGHT
;
796 pts
[1].x
= pts
[0].x
+ BALLOON_STEMWIDTH
;
799 pts
[2].y
= (rect
.bottom
- rect
.top
);
800 if(pts
[1].x
> (rect
.right
- rect
.left
) - BALLOON_STEMINDENT
)
802 pts
[1].x
= (rect
.right
- rect
.left
) - BALLOON_STEMINDENT
;
803 pts
[0].x
= pts
[1].x
- BALLOON_STEMWIDTH
;
807 hrStem
= CreatePolygonRgn(pts
, sizeof(pts
) / sizeof(pts
[0]), ALTERNATE
);
809 hRgn
= CreateRoundRectRgn(0,
810 (infoPtr
->bToolBelow
? BALLOON_STEMHEIGHT
: 0),
811 rect
.right
- rect
.left
,
812 (infoPtr
->bToolBelow
? rect
.bottom
- rect
.top
: rect
.bottom
- rect
.top
- BALLOON_STEMHEIGHT
),
813 BALLOON_ROUNDEDNESS
, BALLOON_ROUNDEDNESS
);
815 CombineRgn(hRgn
, hRgn
, hrStem
, RGN_OR
);
816 DeleteObject(hrStem
);
818 SetWindowRgn(infoPtr
->hwndSelf
, hRgn
, FALSE
);
819 /* we don't free the region handle as the system deletes it when
820 * it is no longer needed */
823 SetWindowPos (infoPtr
->hwndSelf
, HWND_TOPMOST
, rect
.left
, rect
.top
,
824 rect
.right
- rect
.left
, rect
.bottom
- rect
.top
,
825 SWP_SHOWWINDOW
| SWP_NOACTIVATE
);
827 /* repaint the tooltip */
828 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
829 UpdateWindow(infoPtr
->hwndSelf
);
833 SetTimer (infoPtr
->hwndSelf
, ID_TIMERPOP
, infoPtr
->nAutoPopTime
, 0);
834 TRACE("timer 2 started!\n");
835 SetTimer (infoPtr
->hwndSelf
, ID_TIMERLEAVE
, infoPtr
->nReshowTime
, 0);
836 TRACE("timer 3 started!\n");
842 TOOLTIPS_Hide (TOOLTIPS_INFO
*infoPtr
)
844 TTTOOL_INFO
*toolPtr
;
847 TRACE("Hide tooltip %d! (%p)\n", infoPtr
->nCurrentTool
, infoPtr
->hwndSelf
);
849 if (infoPtr
->nCurrentTool
== -1)
852 toolPtr
= &infoPtr
->tools
[infoPtr
->nCurrentTool
];
853 KillTimer (infoPtr
->hwndSelf
, ID_TIMERPOP
);
855 hdr
.hwndFrom
= infoPtr
->hwndSelf
;
856 hdr
.idFrom
= toolPtr
->uId
;
858 SendMessageW (toolPtr
->hwnd
, WM_NOTIFY
, toolPtr
->uId
, (LPARAM
)&hdr
);
860 infoPtr
->nCurrentTool
= -1;
862 SetWindowPos (infoPtr
->hwndSelf
, HWND_TOP
, 0, 0, 0, 0,
863 SWP_NOZORDER
| SWP_HIDEWINDOW
| SWP_NOACTIVATE
);
868 TOOLTIPS_TrackShow (TOOLTIPS_INFO
*infoPtr
)
870 TOOLTIPS_Show(infoPtr
, TRUE
);
875 TOOLTIPS_TrackHide (const TOOLTIPS_INFO
*infoPtr
)
877 TTTOOL_INFO
*toolPtr
;
880 TRACE("hide tracking tooltip %d\n", infoPtr
->nTrackTool
);
882 if (infoPtr
->nTrackTool
== -1)
885 toolPtr
= &infoPtr
->tools
[infoPtr
->nTrackTool
];
887 hdr
.hwndFrom
= infoPtr
->hwndSelf
;
888 hdr
.idFrom
= toolPtr
->uId
;
890 SendMessageW (toolPtr
->hwnd
, WM_NOTIFY
, toolPtr
->uId
, (LPARAM
)&hdr
);
892 SetWindowPos (infoPtr
->hwndSelf
, HWND_TOP
, 0, 0, 0, 0,
893 SWP_NOZORDER
| SWP_HIDEWINDOW
| SWP_NOACTIVATE
);
896 /* Structure layout is the same for TTTOOLINFOW and TTTOOLINFOA,
897 this helper is used in both cases. */
899 TOOLTIPS_GetToolFromInfoT (const TOOLTIPS_INFO
*infoPtr
, const TTTOOLINFOW
*lpToolInfo
)
901 TTTOOL_INFO
*toolPtr
;
904 for (nTool
= 0; nTool
< infoPtr
->uNumTools
; nTool
++) {
905 toolPtr
= &infoPtr
->tools
[nTool
];
907 if (!(toolPtr
->uFlags
& TTF_IDISHWND
) &&
908 (lpToolInfo
->hwnd
== toolPtr
->hwnd
) &&
909 (lpToolInfo
->uId
== toolPtr
->uId
))
913 for (nTool
= 0; nTool
< infoPtr
->uNumTools
; nTool
++) {
914 toolPtr
= &infoPtr
->tools
[nTool
];
916 if ((toolPtr
->uFlags
& TTF_IDISHWND
) &&
917 (lpToolInfo
->uId
== toolPtr
->uId
))
926 TOOLTIPS_GetToolFromPoint (const TOOLTIPS_INFO
*infoPtr
, HWND hwnd
, const POINT
*lpPt
)
928 TTTOOL_INFO
*toolPtr
;
931 for (nTool
= 0; nTool
< infoPtr
->uNumTools
; nTool
++) {
932 toolPtr
= &infoPtr
->tools
[nTool
];
934 if (!(toolPtr
->uFlags
& TTF_IDISHWND
)) {
935 if (hwnd
!= toolPtr
->hwnd
)
937 if (!PtInRect (&toolPtr
->rect
, *lpPt
))
943 for (nTool
= 0; nTool
< infoPtr
->uNumTools
; nTool
++) {
944 toolPtr
= &infoPtr
->tools
[nTool
];
946 if (toolPtr
->uFlags
& TTF_IDISHWND
) {
947 if ((HWND
)toolPtr
->uId
== hwnd
)
956 TOOLTIPS_CopyInfoT (const TTTOOL_INFO
*toolPtr
, TTTOOLINFOW
*ti
, BOOL isW
)
959 if (toolPtr
->lpszText
== NULL
||
960 IS_INTRESOURCE(toolPtr
->lpszText
) ||
961 toolPtr
->lpszText
== LPSTR_TEXTCALLBACKW
)
962 ti
->lpszText
= toolPtr
->lpszText
;
964 strcpyW (ti
->lpszText
, toolPtr
->lpszText
);
966 /* ANSI version, the buffer is maximum 80 bytes without null. */
967 WideCharToMultiByte(CP_ACP
, 0, toolPtr
->lpszText
, -1,
968 (LPSTR
)ti
->lpszText
, MAX_TEXT_SIZE_A
, NULL
, NULL
);
973 TOOLTIPS_IsWindowActive (HWND hwnd
)
975 HWND hwndActive
= GetActiveWindow ();
978 if (hwndActive
== hwnd
)
980 return IsChild (hwndActive
, hwnd
);
985 TOOLTIPS_CheckTool (const TOOLTIPS_INFO
*infoPtr
, BOOL bShowTest
)
992 hwndTool
= (HWND
)SendMessageW (infoPtr
->hwndSelf
, TTM_WINDOWFROMPOINT
, 0, (LPARAM
)&pt
);
996 ScreenToClient (hwndTool
, &pt
);
997 nTool
= TOOLTIPS_GetToolFromPoint (infoPtr
, hwndTool
, &pt
);
1001 if (!(GetWindowLongW (infoPtr
->hwndSelf
, GWL_STYLE
) & TTS_ALWAYSTIP
) && bShowTest
)
1003 TTTOOL_INFO
*ti
= &infoPtr
->tools
[nTool
];
1004 HWND hwnd
= (ti
->uFlags
& TTF_IDISHWND
) ? (HWND
)ti
->uId
: ti
->hwnd
;
1006 if (!TOOLTIPS_IsWindowActive(hwnd
))
1008 TRACE("not active: hwnd %p, parent %p, active %p\n",
1009 hwnd
, GetParent(hwnd
), GetActiveWindow());
1014 TRACE("tool %d\n", nTool
);
1021 TOOLTIPS_Activate (TOOLTIPS_INFO
*infoPtr
, BOOL activate
)
1023 infoPtr
->bActive
= activate
;
1025 if (infoPtr
->bActive
)
1026 TRACE("activate!\n");
1028 if (!(infoPtr
->bActive
) && (infoPtr
->nCurrentTool
!= -1))
1029 TOOLTIPS_Hide (infoPtr
);
1036 TOOLTIPS_AddToolT (TOOLTIPS_INFO
*infoPtr
, const TTTOOLINFOW
*ti
, BOOL isW
)
1038 TTTOOL_INFO
*toolPtr
;
1041 if (!ti
) return FALSE
;
1043 TRACE("add tool (%p) %p %ld%s!\n",
1044 infoPtr
->hwndSelf
, ti
->hwnd
, ti
->uId
,
1045 (ti
->uFlags
& TTF_IDISHWND
) ? " TTF_IDISHWND" : "");
1047 if (ti
->cbSize
>= TTTOOLINFOW_V2_SIZE
&& !ti
->lpszText
&& isW
)
1050 if (infoPtr
->uNumTools
== 0) {
1051 infoPtr
->tools
= Alloc (sizeof(TTTOOL_INFO
));
1052 toolPtr
= infoPtr
->tools
;
1055 TTTOOL_INFO
*oldTools
= infoPtr
->tools
;
1057 Alloc (sizeof(TTTOOL_INFO
) * (infoPtr
->uNumTools
+ 1));
1058 memcpy (infoPtr
->tools
, oldTools
,
1059 infoPtr
->uNumTools
* sizeof(TTTOOL_INFO
));
1061 toolPtr
= &infoPtr
->tools
[infoPtr
->uNumTools
];
1064 infoPtr
->uNumTools
++;
1066 /* copy tool data */
1067 toolPtr
->uFlags
= ti
->uFlags
;
1068 toolPtr
->uInternalFlags
= (ti
->uFlags
& (TTF_SUBCLASS
| TTF_IDISHWND
));
1069 toolPtr
->hwnd
= ti
->hwnd
;
1070 toolPtr
->uId
= ti
->uId
;
1071 toolPtr
->rect
= ti
->rect
;
1072 toolPtr
->hinst
= ti
->hinst
;
1074 if (ti
->cbSize
>= TTTOOLINFOW_V1_SIZE
) {
1075 if (IS_INTRESOURCE(ti
->lpszText
)) {
1076 TRACE("add string id %x\n", LOWORD(ti
->lpszText
));
1077 toolPtr
->lpszText
= ti
->lpszText
;
1079 else if (ti
->lpszText
) {
1080 if (TOOLTIPS_IsCallbackString(ti
->lpszText
, isW
)) {
1081 TRACE("add CALLBACK!\n");
1082 toolPtr
->lpszText
= LPSTR_TEXTCALLBACKW
;
1085 INT len
= lstrlenW (ti
->lpszText
);
1086 TRACE("add text %s!\n", debugstr_w(ti
->lpszText
));
1087 toolPtr
->lpszText
= Alloc ((len
+ 1)*sizeof(WCHAR
));
1088 strcpyW (toolPtr
->lpszText
, ti
->lpszText
);
1091 INT len
= MultiByteToWideChar(CP_ACP
, 0, (LPSTR
)ti
->lpszText
, -1, NULL
, 0);
1092 TRACE("add text \"%s\"!\n", (LPSTR
)ti
->lpszText
);
1093 toolPtr
->lpszText
= Alloc (len
* sizeof(WCHAR
));
1094 MultiByteToWideChar(CP_ACP
, 0, (LPSTR
)ti
->lpszText
, -1, toolPtr
->lpszText
, len
);
1099 if (ti
->cbSize
>= TTTOOLINFOW_V2_SIZE
)
1100 toolPtr
->lParam
= ti
->lParam
;
1102 /* install subclassing hook */
1103 if (toolPtr
->uInternalFlags
& TTF_SUBCLASS
) {
1104 if (toolPtr
->uInternalFlags
& TTF_IDISHWND
) {
1105 SetWindowSubclass((HWND
)toolPtr
->uId
, TOOLTIPS_SubclassProc
, 1,
1106 (DWORD_PTR
)infoPtr
->hwndSelf
);
1109 SetWindowSubclass(toolPtr
->hwnd
, TOOLTIPS_SubclassProc
, 1,
1110 (DWORD_PTR
)infoPtr
->hwndSelf
);
1112 TRACE("subclassing installed!\n");
1115 nResult
= SendMessageW (toolPtr
->hwnd
, WM_NOTIFYFORMAT
,
1116 (WPARAM
)infoPtr
->hwndSelf
, NF_QUERY
);
1117 if (nResult
== NFR_ANSI
) {
1118 toolPtr
->bNotifyUnicode
= FALSE
;
1119 TRACE(" -- WM_NOTIFYFORMAT returns: NFR_ANSI\n");
1120 } else if (nResult
== NFR_UNICODE
) {
1121 toolPtr
->bNotifyUnicode
= TRUE
;
1122 TRACE(" -- WM_NOTIFYFORMAT returns: NFR_UNICODE\n");
1124 TRACE (" -- WM_NOTIFYFORMAT returns: error!\n");
1132 TOOLTIPS_DelToolT (TOOLTIPS_INFO
*infoPtr
, const TTTOOLINFOW
*ti
, BOOL isW
)
1134 TTTOOL_INFO
*toolPtr
;
1138 if (isW
&& ti
->cbSize
> TTTOOLINFOW_V2_SIZE
&&
1139 ti
->cbSize
!= TTTOOLINFOW_V3_SIZE
)
1141 if (infoPtr
->uNumTools
== 0)
1144 nTool
= TOOLTIPS_GetToolFromInfoT (infoPtr
, ti
);
1146 TRACE("tool %d\n", nTool
);
1151 /* make sure the tooltip has disappeared before deleting it */
1152 TOOLTIPS_Hide(infoPtr
);
1154 /* delete text string */
1155 toolPtr
= &infoPtr
->tools
[nTool
];
1156 if (toolPtr
->lpszText
) {
1157 if ( (toolPtr
->lpszText
!= LPSTR_TEXTCALLBACKW
) &&
1158 !IS_INTRESOURCE(toolPtr
->lpszText
) )
1159 Free (toolPtr
->lpszText
);
1162 /* remove subclassing */
1163 if (toolPtr
->uInternalFlags
& TTF_SUBCLASS
) {
1164 if (toolPtr
->uInternalFlags
& TTF_IDISHWND
) {
1165 RemoveWindowSubclass((HWND
)toolPtr
->uId
, TOOLTIPS_SubclassProc
, 1);
1168 RemoveWindowSubclass(toolPtr
->hwnd
, TOOLTIPS_SubclassProc
, 1);
1172 /* delete tool from tool list */
1173 if (infoPtr
->uNumTools
== 1) {
1174 Free (infoPtr
->tools
);
1175 infoPtr
->tools
= NULL
;
1178 TTTOOL_INFO
*oldTools
= infoPtr
->tools
;
1180 Alloc (sizeof(TTTOOL_INFO
) * (infoPtr
->uNumTools
- 1));
1183 memcpy (&infoPtr
->tools
[0], &oldTools
[0],
1184 nTool
* sizeof(TTTOOL_INFO
));
1186 if (nTool
< infoPtr
->uNumTools
- 1)
1187 memcpy (&infoPtr
->tools
[nTool
], &oldTools
[nTool
+ 1],
1188 (infoPtr
->uNumTools
- nTool
- 1) * sizeof(TTTOOL_INFO
));
1193 /* update any indices affected by delete */
1195 /* destroying tool that mouse was on on last relayed mouse move */
1196 if (infoPtr
->nTool
== nTool
)
1197 /* -1 means no current tool (0 means first tool) */
1198 infoPtr
->nTool
= -1;
1199 else if (infoPtr
->nTool
> nTool
)
1202 if (infoPtr
->nTrackTool
== nTool
)
1203 /* -1 means no current tool (0 means first tool) */
1204 infoPtr
->nTrackTool
= -1;
1205 else if (infoPtr
->nTrackTool
> nTool
)
1206 infoPtr
->nTrackTool
--;
1208 if (infoPtr
->nCurrentTool
== nTool
)
1209 /* -1 means no current tool (0 means first tool) */
1210 infoPtr
->nCurrentTool
= -1;
1211 else if (infoPtr
->nCurrentTool
> nTool
)
1212 infoPtr
->nCurrentTool
--;
1214 infoPtr
->uNumTools
--;
1220 TOOLTIPS_EnumToolsT (const TOOLTIPS_INFO
*infoPtr
, UINT uIndex
, TTTOOLINFOW
*ti
,
1223 TTTOOL_INFO
*toolPtr
;
1225 if (!ti
) return FALSE
;
1226 if (ti
->cbSize
< TTTOOLINFOW_V1_SIZE
)
1228 if (uIndex
>= infoPtr
->uNumTools
)
1231 TRACE("index=%u\n", uIndex
);
1233 toolPtr
= &infoPtr
->tools
[uIndex
];
1235 /* copy tool data */
1236 ti
->uFlags
= toolPtr
->uFlags
;
1237 ti
->hwnd
= toolPtr
->hwnd
;
1238 ti
->uId
= toolPtr
->uId
;
1239 ti
->rect
= toolPtr
->rect
;
1240 ti
->hinst
= toolPtr
->hinst
;
1241 TOOLTIPS_CopyInfoT (toolPtr
, ti
, isW
);
1243 if (ti
->cbSize
>= TTTOOLINFOA_V2_SIZE
)
1244 ti
->lParam
= toolPtr
->lParam
;
1250 TOOLTIPS_GetBubbleSize (const TOOLTIPS_INFO
*infoPtr
, const TTTOOLINFOW
*lpToolInfo
)
1255 if (lpToolInfo
== NULL
)
1257 if (lpToolInfo
->cbSize
< TTTOOLINFOW_V1_SIZE
)
1260 nTool
= TOOLTIPS_GetToolFromInfoT (infoPtr
, lpToolInfo
);
1261 if (nTool
== -1) return 0;
1263 TRACE("tool %d\n", nTool
);
1265 TOOLTIPS_CalcTipSize (infoPtr
, &size
);
1266 TRACE("size %d x %d\n", size
.cx
, size
.cy
);
1268 return MAKELRESULT(size
.cx
, size
.cy
);
1272 TOOLTIPS_GetCurrentToolT (const TOOLTIPS_INFO
*infoPtr
, TTTOOLINFOW
*ti
, BOOL isW
)
1274 TTTOOL_INFO
*toolPtr
;
1277 if (ti
->cbSize
< TTTOOLINFOW_V1_SIZE
)
1280 if (infoPtr
->nCurrentTool
> -1) {
1281 toolPtr
= &infoPtr
->tools
[infoPtr
->nCurrentTool
];
1283 /* copy tool data */
1284 ti
->uFlags
= toolPtr
->uFlags
;
1285 ti
->rect
= toolPtr
->rect
;
1286 ti
->hinst
= toolPtr
->hinst
;
1287 TOOLTIPS_CopyInfoT (toolPtr
, ti
, isW
);
1289 if (ti
->cbSize
>= TTTOOLINFOW_V2_SIZE
)
1290 ti
->lParam
= toolPtr
->lParam
;
1298 return (infoPtr
->nCurrentTool
!= -1);
1303 TOOLTIPS_GetDelayTime (const TOOLTIPS_INFO
*infoPtr
, DWORD duration
)
1307 return infoPtr
->nReshowTime
;
1310 return infoPtr
->nAutoPopTime
;
1313 case TTDT_AUTOMATIC
: /* Apparently TTDT_AUTOMATIC returns TTDT_INITIAL */
1314 return infoPtr
->nInitialTime
;
1317 WARN("Invalid duration flag %x\n", duration
);
1326 TOOLTIPS_GetMargin (const TOOLTIPS_INFO
*infoPtr
, LPRECT lpRect
)
1328 lpRect
->left
= infoPtr
->rcMargin
.left
;
1329 lpRect
->right
= infoPtr
->rcMargin
.right
;
1330 lpRect
->bottom
= infoPtr
->rcMargin
.bottom
;
1331 lpRect
->top
= infoPtr
->rcMargin
.top
;
1337 static inline LRESULT
1338 TOOLTIPS_GetMaxTipWidth (const TOOLTIPS_INFO
*infoPtr
)
1340 return infoPtr
->nMaxTipWidth
;
1345 TOOLTIPS_GetTextT (const TOOLTIPS_INFO
*infoPtr
, TTTOOLINFOW
*ti
, BOOL isW
)
1350 if (ti
->cbSize
< TTTOOLINFOW_V1_SIZE
)
1353 nTool
= TOOLTIPS_GetToolFromInfoT (infoPtr
, ti
);
1354 if (nTool
== -1) return 0;
1356 if (infoPtr
->tools
[nTool
].lpszText
== NULL
)
1360 ti
->lpszText
[0] = '\0';
1361 TOOLTIPS_GetTipText(infoPtr
, nTool
, ti
->lpszText
);
1364 WCHAR buffer
[INFOTIPSIZE
];
1366 /* NB this API is broken, there is no way for the app to determine
1367 what size buffer it requires nor a way to specify how long the
1368 one it supplies is. According to the test result, it's up to
1369 80 bytes by the ANSI version. */
1372 TOOLTIPS_GetTipText(infoPtr
, nTool
, buffer
);
1373 WideCharToMultiByte(CP_ACP
, 0, buffer
, -1, (LPSTR
)ti
->lpszText
,
1374 MAX_TEXT_SIZE_A
, NULL
, NULL
);
1381 static inline LRESULT
1382 TOOLTIPS_GetTipBkColor (const TOOLTIPS_INFO
*infoPtr
)
1384 return infoPtr
->clrBk
;
1388 static inline LRESULT
1389 TOOLTIPS_GetTipTextColor (const TOOLTIPS_INFO
*infoPtr
)
1391 return infoPtr
->clrText
;
1395 static inline LRESULT
1396 TOOLTIPS_GetToolCount (const TOOLTIPS_INFO
*infoPtr
)
1398 return infoPtr
->uNumTools
;
1403 TOOLTIPS_GetToolInfoT (const TOOLTIPS_INFO
*infoPtr
, TTTOOLINFOW
*ti
, BOOL isW
)
1405 TTTOOL_INFO
*toolPtr
;
1408 if (!ti
) return FALSE
;
1409 if (ti
->cbSize
< TTTOOLINFOW_V1_SIZE
)
1411 if (infoPtr
->uNumTools
== 0)
1414 nTool
= TOOLTIPS_GetToolFromInfoT (infoPtr
, ti
);
1418 TRACE("tool %d\n", nTool
);
1420 toolPtr
= &infoPtr
->tools
[nTool
];
1422 /* copy tool data */
1423 ti
->uFlags
= toolPtr
->uFlags
;
1424 ti
->rect
= toolPtr
->rect
;
1425 ti
->hinst
= toolPtr
->hinst
;
1426 TOOLTIPS_CopyInfoT (toolPtr
, ti
, isW
);
1428 if (ti
->cbSize
>= TTTOOLINFOW_V2_SIZE
)
1429 ti
->lParam
= toolPtr
->lParam
;
1436 TOOLTIPS_HitTestT (const TOOLTIPS_INFO
*infoPtr
, LPTTHITTESTINFOW lptthit
,
1439 TTTOOL_INFO
*toolPtr
;
1445 nTool
= TOOLTIPS_GetToolFromPoint (infoPtr
, lptthit
->hwnd
, &lptthit
->pt
);
1449 TRACE("tool %d!\n", nTool
);
1451 /* copy tool data */
1452 if (lptthit
->ti
.cbSize
>= TTTOOLINFOW_V1_SIZE
) {
1453 toolPtr
= &infoPtr
->tools
[nTool
];
1455 lptthit
->ti
.uFlags
= toolPtr
->uFlags
;
1456 lptthit
->ti
.hwnd
= toolPtr
->hwnd
;
1457 lptthit
->ti
.uId
= toolPtr
->uId
;
1458 lptthit
->ti
.rect
= toolPtr
->rect
;
1459 lptthit
->ti
.hinst
= toolPtr
->hinst
;
1460 TOOLTIPS_CopyInfoT (toolPtr
, &lptthit
->ti
, isW
);
1461 if (lptthit
->ti
.cbSize
>= TTTOOLINFOW_V2_SIZE
)
1462 lptthit
->ti
.lParam
= toolPtr
->lParam
;
1470 TOOLTIPS_NewToolRectT (TOOLTIPS_INFO
*infoPtr
, const TTTOOLINFOW
*ti
)
1475 if (ti
->cbSize
< TTTOOLINFOW_V1_SIZE
)
1478 nTool
= TOOLTIPS_GetToolFromInfoT (infoPtr
, ti
);
1480 TRACE("nTool = %d, rect = %s\n", nTool
, wine_dbgstr_rect(&ti
->rect
));
1482 if (nTool
== -1) return 0;
1484 infoPtr
->tools
[nTool
].rect
= ti
->rect
;
1490 static inline LRESULT
1491 TOOLTIPS_Pop (TOOLTIPS_INFO
*infoPtr
)
1493 TOOLTIPS_Hide (infoPtr
);
1500 TOOLTIPS_RelayEvent (TOOLTIPS_INFO
*infoPtr
, LPMSG lpMsg
)
1506 ERR("lpMsg == NULL!\n");
1510 switch (lpMsg
->message
) {
1511 case WM_LBUTTONDOWN
:
1513 case WM_MBUTTONDOWN
:
1515 case WM_RBUTTONDOWN
:
1517 TOOLTIPS_Hide (infoPtr
);
1521 pt
.x
= (short)LOWORD(lpMsg
->lParam
);
1522 pt
.y
= (short)HIWORD(lpMsg
->lParam
);
1523 nOldTool
= infoPtr
->nTool
;
1524 infoPtr
->nTool
= TOOLTIPS_GetToolFromPoint(infoPtr
, lpMsg
->hwnd
,
1526 TRACE("tool (%p) %d %d %d\n", infoPtr
->hwndSelf
, nOldTool
,
1527 infoPtr
->nTool
, infoPtr
->nCurrentTool
);
1528 TRACE("WM_MOUSEMOVE (%p %d %d)\n", infoPtr
->hwndSelf
, pt
.x
, pt
.y
);
1530 if (infoPtr
->nTool
!= nOldTool
) {
1531 if(infoPtr
->nTool
== -1) { /* Moved out of all tools */
1532 TOOLTIPS_Hide(infoPtr
);
1533 KillTimer(infoPtr
->hwndSelf
, ID_TIMERLEAVE
);
1534 } else if (nOldTool
== -1) { /* Moved from outside */
1535 if(infoPtr
->bActive
) {
1536 SetTimer(infoPtr
->hwndSelf
, ID_TIMERSHOW
, infoPtr
->nInitialTime
, 0);
1537 TRACE("timer 1 started!\n");
1539 } else { /* Moved from one to another */
1540 TOOLTIPS_Hide (infoPtr
);
1541 KillTimer(infoPtr
->hwndSelf
, ID_TIMERLEAVE
);
1542 if(infoPtr
->bActive
) {
1543 SetTimer (infoPtr
->hwndSelf
, ID_TIMERSHOW
, infoPtr
->nReshowTime
, 0);
1544 TRACE("timer 1 started!\n");
1547 } else if(infoPtr
->nCurrentTool
!= -1) { /* restart autopop */
1548 KillTimer(infoPtr
->hwndSelf
, ID_TIMERPOP
);
1549 SetTimer(infoPtr
->hwndSelf
, ID_TIMERPOP
, infoPtr
->nAutoPopTime
, 0);
1550 TRACE("timer 2 restarted\n");
1551 } else if(infoPtr
->nTool
!= -1 && infoPtr
->bActive
) {
1552 /* previous show attempt didn't result in tooltip so try again */
1553 SetTimer(infoPtr
->hwndSelf
, ID_TIMERSHOW
, infoPtr
->nInitialTime
, 0);
1554 TRACE("timer 1 started!\n");
1564 TOOLTIPS_SetDelayTime (TOOLTIPS_INFO
*infoPtr
, DWORD duration
, INT nTime
)
1567 case TTDT_AUTOMATIC
:
1569 nTime
= GetDoubleClickTime();
1570 infoPtr
->nReshowTime
= nTime
/ 5;
1571 infoPtr
->nAutoPopTime
= nTime
* 10;
1572 infoPtr
->nInitialTime
= nTime
;
1577 nTime
= GetDoubleClickTime() / 5;
1578 infoPtr
->nReshowTime
= nTime
;
1583 nTime
= GetDoubleClickTime() * 10;
1584 infoPtr
->nAutoPopTime
= nTime
;
1589 nTime
= GetDoubleClickTime();
1590 infoPtr
->nInitialTime
= nTime
;
1594 WARN("Invalid duration flag %x\n", duration
);
1603 TOOLTIPS_SetMargin (TOOLTIPS_INFO
*infoPtr
, const RECT
*lpRect
)
1605 infoPtr
->rcMargin
.left
= lpRect
->left
;
1606 infoPtr
->rcMargin
.right
= lpRect
->right
;
1607 infoPtr
->rcMargin
.bottom
= lpRect
->bottom
;
1608 infoPtr
->rcMargin
.top
= lpRect
->top
;
1614 static inline LRESULT
1615 TOOLTIPS_SetMaxTipWidth (TOOLTIPS_INFO
*infoPtr
, INT MaxWidth
)
1617 INT nTemp
= infoPtr
->nMaxTipWidth
;
1619 infoPtr
->nMaxTipWidth
= MaxWidth
;
1625 static inline LRESULT
1626 TOOLTIPS_SetTipBkColor (TOOLTIPS_INFO
*infoPtr
, COLORREF clrBk
)
1628 infoPtr
->clrBk
= clrBk
;
1634 static inline LRESULT
1635 TOOLTIPS_SetTipTextColor (TOOLTIPS_INFO
*infoPtr
, COLORREF clrText
)
1637 infoPtr
->clrText
= clrText
;
1644 TOOLTIPS_SetTitleT (TOOLTIPS_INFO
*infoPtr
, UINT_PTR uTitleIcon
, LPCWSTR pszTitle
,
1649 TRACE("hwnd = %p, title = %s, icon = %p\n", infoPtr
->hwndSelf
, debugstr_w(pszTitle
),
1652 Free(infoPtr
->pszTitle
);
1658 size
= (strlenW(pszTitle
)+1)*sizeof(WCHAR
);
1659 infoPtr
->pszTitle
= Alloc(size
);
1660 if (!infoPtr
->pszTitle
)
1662 memcpy(infoPtr
->pszTitle
, pszTitle
, size
);
1666 size
= sizeof(WCHAR
)*MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)pszTitle
, -1, NULL
, 0);
1667 infoPtr
->pszTitle
= Alloc(size
);
1668 if (!infoPtr
->pszTitle
)
1670 MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)pszTitle
, -1, infoPtr
->pszTitle
, size
/sizeof(WCHAR
));
1674 infoPtr
->pszTitle
= NULL
;
1676 if (uTitleIcon
<= TTI_ERROR
)
1677 infoPtr
->hTitleIcon
= hTooltipIcons
[uTitleIcon
];
1679 infoPtr
->hTitleIcon
= CopyIcon((HICON
)uTitleIcon
);
1681 TRACE("icon = %p\n", infoPtr
->hTitleIcon
);
1688 TOOLTIPS_SetToolInfoT (TOOLTIPS_INFO
*infoPtr
, const TTTOOLINFOW
*ti
, BOOL isW
)
1690 TTTOOL_INFO
*toolPtr
;
1694 if (ti
->cbSize
< TTTOOLINFOW_V1_SIZE
)
1697 nTool
= TOOLTIPS_GetToolFromInfoT (infoPtr
, ti
);
1698 if (nTool
== -1) return 0;
1700 TRACE("tool %d\n", nTool
);
1702 toolPtr
= &infoPtr
->tools
[nTool
];
1704 /* copy tool data */
1705 toolPtr
->uFlags
= ti
->uFlags
;
1706 toolPtr
->hwnd
= ti
->hwnd
;
1707 toolPtr
->uId
= ti
->uId
;
1708 toolPtr
->rect
= ti
->rect
;
1709 toolPtr
->hinst
= ti
->hinst
;
1711 if (IS_INTRESOURCE(ti
->lpszText
)) {
1712 TRACE("set string id %x!\n", LOWORD(ti
->lpszText
));
1713 toolPtr
->lpszText
= ti
->lpszText
;
1716 if (TOOLTIPS_IsCallbackString(ti
->lpszText
, isW
))
1717 toolPtr
->lpszText
= LPSTR_TEXTCALLBACKW
;
1719 if ( (toolPtr
->lpszText
) &&
1720 !IS_INTRESOURCE(toolPtr
->lpszText
) ) {
1721 if( toolPtr
->lpszText
!= LPSTR_TEXTCALLBACKW
)
1722 Free (toolPtr
->lpszText
);
1723 toolPtr
->lpszText
= NULL
;
1727 INT len
= lstrlenW (ti
->lpszText
);
1728 toolPtr
->lpszText
= Alloc ((len
+1)*sizeof(WCHAR
));
1729 strcpyW (toolPtr
->lpszText
, ti
->lpszText
);
1732 INT len
= MultiByteToWideChar(CP_ACP
, 0, (LPSTR
)ti
->lpszText
,
1734 toolPtr
->lpszText
= Alloc (len
* sizeof(WCHAR
));
1735 MultiByteToWideChar(CP_ACP
, 0, (LPSTR
)ti
->lpszText
, -1,
1736 toolPtr
->lpszText
, len
);
1742 if (ti
->cbSize
>= TTTOOLINFOW_V2_SIZE
)
1743 toolPtr
->lParam
= ti
->lParam
;
1745 if (infoPtr
->nCurrentTool
== nTool
)
1747 TOOLTIPS_GetTipText (infoPtr
, infoPtr
->nCurrentTool
, infoPtr
->szTipText
);
1749 if (infoPtr
->szTipText
[0] == 0)
1750 TOOLTIPS_Hide(infoPtr
);
1752 TOOLTIPS_Show (infoPtr
, FALSE
);
1760 TOOLTIPS_TrackActivate (TOOLTIPS_INFO
*infoPtr
, BOOL track_activate
, const TTTOOLINFOA
*ti
)
1762 if (track_activate
) {
1765 if (ti
->cbSize
< TTTOOLINFOA_V1_SIZE
)
1769 infoPtr
->nTrackTool
= TOOLTIPS_GetToolFromInfoT (infoPtr
, (const TTTOOLINFOW
*)ti
);
1770 if (infoPtr
->nTrackTool
!= -1) {
1771 TRACE("activated!\n");
1772 infoPtr
->bTrackActive
= TRUE
;
1773 TOOLTIPS_TrackShow (infoPtr
);
1778 TOOLTIPS_TrackHide (infoPtr
);
1780 infoPtr
->bTrackActive
= FALSE
;
1781 infoPtr
->nTrackTool
= -1;
1783 TRACE("deactivated!\n");
1791 TOOLTIPS_TrackPosition (TOOLTIPS_INFO
*infoPtr
, LPARAM coord
)
1793 infoPtr
->xTrackPos
= (INT
)LOWORD(coord
);
1794 infoPtr
->yTrackPos
= (INT
)HIWORD(coord
);
1796 if (infoPtr
->bTrackActive
) {
1798 infoPtr
->xTrackPos
, infoPtr
->yTrackPos
);
1800 TOOLTIPS_TrackShow (infoPtr
);
1808 TOOLTIPS_Update (TOOLTIPS_INFO
*infoPtr
)
1810 if (infoPtr
->nCurrentTool
!= -1)
1811 UpdateWindow (infoPtr
->hwndSelf
);
1818 TOOLTIPS_UpdateTipTextT (TOOLTIPS_INFO
*infoPtr
, const TTTOOLINFOW
*ti
, BOOL isW
)
1820 TTTOOL_INFO
*toolPtr
;
1824 if (ti
->cbSize
< TTTOOLINFOW_V1_SIZE
)
1827 nTool
= TOOLTIPS_GetToolFromInfoT (infoPtr
, ti
);
1831 TRACE("tool %d\n", nTool
);
1833 toolPtr
= &infoPtr
->tools
[nTool
];
1835 /* copy tool text */
1836 toolPtr
->hinst
= ti
->hinst
;
1838 if (IS_INTRESOURCE(ti
->lpszText
)){
1839 toolPtr
->lpszText
= ti
->lpszText
;
1841 else if (ti
->lpszText
) {
1842 if (TOOLTIPS_IsCallbackString(ti
->lpszText
, isW
))
1843 toolPtr
->lpszText
= LPSTR_TEXTCALLBACKW
;
1845 if ( (toolPtr
->lpszText
) &&
1846 !IS_INTRESOURCE(toolPtr
->lpszText
) ) {
1847 if( toolPtr
->lpszText
!= LPSTR_TEXTCALLBACKW
)
1848 Free (toolPtr
->lpszText
);
1849 toolPtr
->lpszText
= NULL
;
1853 INT len
= lstrlenW (ti
->lpszText
);
1854 toolPtr
->lpszText
= Alloc ((len
+1)*sizeof(WCHAR
));
1855 strcpyW (toolPtr
->lpszText
, ti
->lpszText
);
1858 INT len
= MultiByteToWideChar(CP_ACP
, 0, (LPSTR
)ti
->lpszText
,
1860 toolPtr
->lpszText
= Alloc (len
* sizeof(WCHAR
));
1861 MultiByteToWideChar(CP_ACP
, 0, (LPSTR
)ti
->lpszText
, -1,
1862 toolPtr
->lpszText
, len
);
1868 if(infoPtr
->nCurrentTool
== -1) return 0;
1870 if (infoPtr
->bActive
)
1871 TOOLTIPS_Show (infoPtr
, FALSE
);
1872 else if (infoPtr
->bTrackActive
)
1873 TOOLTIPS_Show (infoPtr
, TRUE
);
1880 TOOLTIPS_Create (HWND hwnd
)
1882 TOOLTIPS_INFO
*infoPtr
;
1884 /* allocate memory for info structure */
1885 infoPtr
= Alloc (sizeof(TOOLTIPS_INFO
));
1886 SetWindowLongPtrW (hwnd
, 0, (DWORD_PTR
)infoPtr
);
1888 /* initialize info structure */
1889 infoPtr
->bActive
= TRUE
;
1890 infoPtr
->bTrackActive
= FALSE
;
1892 infoPtr
->nMaxTipWidth
= -1;
1893 infoPtr
->nTool
= -1;
1894 infoPtr
->nCurrentTool
= -1;
1895 infoPtr
->nTrackTool
= -1;
1896 infoPtr
->hwndSelf
= hwnd
;
1898 /* initialize colours and fonts */
1899 TOOLTIPS_InitSystemSettings(infoPtr
);
1901 TOOLTIPS_SetDelayTime(infoPtr
, TTDT_AUTOMATIC
, 0);
1903 SetWindowPos (hwnd
, HWND_TOP
, 0, 0, 0, 0, SWP_NOZORDER
| SWP_HIDEWINDOW
| SWP_NOACTIVATE
);
1910 TOOLTIPS_Destroy (TOOLTIPS_INFO
*infoPtr
)
1912 TTTOOL_INFO
*toolPtr
;
1916 if (infoPtr
->tools
) {
1917 for (i
= 0; i
< infoPtr
->uNumTools
; i
++) {
1918 toolPtr
= &infoPtr
->tools
[i
];
1919 if (toolPtr
->lpszText
) {
1920 if ( (toolPtr
->lpszText
!= LPSTR_TEXTCALLBACKW
) &&
1921 !IS_INTRESOURCE(toolPtr
->lpszText
) )
1923 Free (toolPtr
->lpszText
);
1924 toolPtr
->lpszText
= NULL
;
1928 /* remove subclassing */
1929 if (toolPtr
->uInternalFlags
& TTF_SUBCLASS
) {
1930 if (toolPtr
->uInternalFlags
& TTF_IDISHWND
) {
1931 RemoveWindowSubclass((HWND
)toolPtr
->uId
, TOOLTIPS_SubclassProc
, 1);
1934 RemoveWindowSubclass(toolPtr
->hwnd
, TOOLTIPS_SubclassProc
, 1);
1938 Free (infoPtr
->tools
);
1941 /* free title string */
1942 Free (infoPtr
->pszTitle
);
1943 /* free title icon if not a standard one */
1944 if (TOOLTIPS_GetTitleIconIndex(infoPtr
->hTitleIcon
) > TTI_ERROR
)
1945 DeleteObject(infoPtr
->hTitleIcon
);
1948 DeleteObject (infoPtr
->hFont
);
1949 DeleteObject (infoPtr
->hTitleFont
);
1951 /* free tool tips info data */
1952 SetWindowLongPtrW(infoPtr
->hwndSelf
, 0, 0);
1959 static inline LRESULT
1960 TOOLTIPS_GetFont (const TOOLTIPS_INFO
*infoPtr
)
1962 return (LRESULT
)infoPtr
->hFont
;
1967 TOOLTIPS_MouseMessage (TOOLTIPS_INFO
*infoPtr
)
1969 TOOLTIPS_Hide (infoPtr
);
1976 TOOLTIPS_NCCreate (HWND hwnd
)
1978 DWORD dwStyle
= GetWindowLongW (hwnd
, GWL_STYLE
);
1979 DWORD dwExStyle
= GetWindowLongW (hwnd
, GWL_EXSTYLE
);
1981 dwStyle
&= ~(WS_CHILD
| /*WS_MAXIMIZE |*/ WS_BORDER
| WS_DLGFRAME
);
1982 dwStyle
|= (WS_POPUP
| WS_BORDER
| WS_CLIPSIBLINGS
);
1984 /* WS_BORDER only draws a border round the window rect, not the
1985 * window region, therefore it is useless to us in balloon mode */
1986 if (dwStyle
& TTS_BALLOON
) dwStyle
&= ~WS_BORDER
;
1988 SetWindowLongW (hwnd
, GWL_STYLE
, dwStyle
);
1990 dwExStyle
|= WS_EX_TOOLWINDOW
;
1991 SetWindowLongW (hwnd
, GWL_EXSTYLE
, dwExStyle
);
1998 TOOLTIPS_NCHitTest (const TOOLTIPS_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
2000 INT nTool
= (infoPtr
->bTrackActive
) ? infoPtr
->nTrackTool
: infoPtr
->nTool
;
2002 TRACE(" nTool=%d\n", nTool
);
2004 if ((nTool
> -1) && (nTool
< infoPtr
->uNumTools
)) {
2005 if (infoPtr
->tools
[nTool
].uFlags
& TTF_TRANSPARENT
) {
2006 TRACE("-- in transparent mode!\n");
2007 return HTTRANSPARENT
;
2011 return DefWindowProcW (infoPtr
->hwndSelf
, WM_NCHITTEST
, wParam
, lParam
);
2016 TOOLTIPS_NotifyFormat (TOOLTIPS_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
2018 FIXME ("hwnd=%p wParam=%lx lParam=%lx\n", infoPtr
->hwndSelf
, wParam
, lParam
);
2025 TOOLTIPS_Paint (const TOOLTIPS_INFO
*infoPtr
, HDC hDC
)
2030 hdc
= (hDC
== NULL
) ? BeginPaint (infoPtr
->hwndSelf
, &ps
) : hDC
;
2031 TOOLTIPS_Refresh (infoPtr
, hdc
);
2033 EndPaint (infoPtr
->hwndSelf
, &ps
);
2039 TOOLTIPS_SetFont (TOOLTIPS_INFO
*infoPtr
, HFONT hFont
, BOOL redraw
)
2043 if(!GetObjectW(hFont
, sizeof(lf
), &lf
))
2046 DeleteObject (infoPtr
->hFont
);
2047 infoPtr
->hFont
= CreateFontIndirectW(&lf
);
2049 DeleteObject (infoPtr
->hTitleFont
);
2050 lf
.lfWeight
= FW_BOLD
;
2051 infoPtr
->hTitleFont
= CreateFontIndirectW(&lf
);
2053 if (redraw
&& infoPtr
->nCurrentTool
!= -1) {
2054 FIXME("full redraw needed!\n");
2060 /******************************************************************
2061 * TOOLTIPS_GetTextLength
2063 * This function is called when the tooltip receive a
2064 * WM_GETTEXTLENGTH message.
2066 * returns the length, in characters, of the tip text
2068 static inline LRESULT
2069 TOOLTIPS_GetTextLength(const TOOLTIPS_INFO
*infoPtr
)
2071 return strlenW(infoPtr
->szTipText
);
2074 /******************************************************************
2075 * TOOLTIPS_OnWMGetText
2077 * This function is called when the tooltip receive a
2078 * WM_GETTEXT message.
2079 * wParam : specifies the maximum number of characters to be copied
2080 * lParam : is the pointer to the buffer that will receive
2083 * returns the number of characters copied
2086 TOOLTIPS_OnWMGetText (const TOOLTIPS_INFO
*infoPtr
, WPARAM size
, LPWSTR pszText
)
2093 res
= min(strlenW(infoPtr
->szTipText
)+1, size
);
2094 memcpy(pszText
, infoPtr
->szTipText
, res
*sizeof(WCHAR
));
2095 pszText
[res
-1] = '\0';
2100 TOOLTIPS_Timer (TOOLTIPS_INFO
*infoPtr
, INT iTimer
)
2104 TRACE("timer %d (%p) expired!\n", iTimer
, infoPtr
->hwndSelf
);
2108 KillTimer (infoPtr
->hwndSelf
, ID_TIMERSHOW
);
2109 nOldTool
= infoPtr
->nTool
;
2110 if ((infoPtr
->nTool
= TOOLTIPS_CheckTool (infoPtr
, TRUE
)) == nOldTool
)
2111 TOOLTIPS_Show (infoPtr
, FALSE
);
2115 TOOLTIPS_Hide (infoPtr
);
2119 nOldTool
= infoPtr
->nTool
;
2120 infoPtr
->nTool
= TOOLTIPS_CheckTool (infoPtr
, FALSE
);
2121 TRACE("tool (%p) %d %d %d\n", infoPtr
->hwndSelf
, nOldTool
,
2122 infoPtr
->nTool
, infoPtr
->nCurrentTool
);
2123 if (infoPtr
->nTool
!= nOldTool
) {
2124 if(infoPtr
->nTool
== -1) { /* Moved out of all tools */
2125 TOOLTIPS_Hide(infoPtr
);
2126 KillTimer(infoPtr
->hwndSelf
, ID_TIMERLEAVE
);
2127 } else if (nOldTool
== -1) { /* Moved from outside */
2128 ERR("How did this happen?\n");
2129 } else { /* Moved from one to another */
2130 TOOLTIPS_Hide (infoPtr
);
2131 KillTimer(infoPtr
->hwndSelf
, ID_TIMERLEAVE
);
2132 if(infoPtr
->bActive
) {
2133 SetTimer (infoPtr
->hwndSelf
, ID_TIMERSHOW
, infoPtr
->nReshowTime
, 0);
2134 TRACE("timer 1 started!\n");
2141 ERR("Unknown timer id %d\n", iTimer
);
2149 TOOLTIPS_WinIniChange (TOOLTIPS_INFO
*infoPtr
)
2151 TOOLTIPS_InitSystemSettings (infoPtr
);
2157 static LRESULT CALLBACK
2158 TOOLTIPS_SubclassProc (HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
, UINT_PTR uID
, DWORD_PTR dwRef
)
2160 TOOLTIPS_INFO
*infoPtr
= TOOLTIPS_GetInfoPtr ((HWND
)dwRef
);
2165 case WM_LBUTTONDOWN
:
2167 case WM_MBUTTONDOWN
:
2169 case WM_RBUTTONDOWN
:
2173 msg
.wParam
= wParam
;
2174 msg
.lParam
= lParam
;
2175 TOOLTIPS_RelayEvent(infoPtr
, &msg
);
2181 return DefSubclassProc(hwnd
, uMsg
, wParam
, lParam
);
2185 static LRESULT CALLBACK
2186 TOOLTIPS_WindowProc (HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
2188 TOOLTIPS_INFO
*infoPtr
= TOOLTIPS_GetInfoPtr (hwnd
);
2190 TRACE("hwnd=%p msg=%x wparam=%lx lParam=%lx\n", hwnd
, uMsg
, wParam
, lParam
);
2191 if (!infoPtr
&& (uMsg
!= WM_CREATE
) && (uMsg
!= WM_NCCREATE
))
2192 return DefWindowProcW (hwnd
, uMsg
, wParam
, lParam
);
2196 return TOOLTIPS_Activate (infoPtr
, (BOOL
)wParam
);
2200 return TOOLTIPS_AddToolT (infoPtr
, (LPTTTOOLINFOW
)lParam
, uMsg
== TTM_ADDTOOLW
);
2204 return TOOLTIPS_DelToolT (infoPtr
, (LPTOOLINFOW
)lParam
,
2205 uMsg
== TTM_DELTOOLW
);
2206 case TTM_ENUMTOOLSA
:
2207 case TTM_ENUMTOOLSW
:
2208 return TOOLTIPS_EnumToolsT (infoPtr
, (UINT
)wParam
, (LPTTTOOLINFOW
)lParam
,
2209 uMsg
== TTM_ENUMTOOLSW
);
2210 case TTM_GETBUBBLESIZE
:
2211 return TOOLTIPS_GetBubbleSize (infoPtr
, (LPTTTOOLINFOW
)lParam
);
2213 case TTM_GETCURRENTTOOLA
:
2214 case TTM_GETCURRENTTOOLW
:
2215 return TOOLTIPS_GetCurrentToolT (infoPtr
, (LPTTTOOLINFOW
)lParam
,
2216 uMsg
== TTM_GETCURRENTTOOLW
);
2218 case TTM_GETDELAYTIME
:
2219 return TOOLTIPS_GetDelayTime (infoPtr
, (DWORD
)wParam
);
2222 return TOOLTIPS_GetMargin (infoPtr
, (LPRECT
)lParam
);
2224 case TTM_GETMAXTIPWIDTH
:
2225 return TOOLTIPS_GetMaxTipWidth (infoPtr
);
2229 return TOOLTIPS_GetTextT (infoPtr
, (LPTTTOOLINFOW
)lParam
,
2230 uMsg
== TTM_GETTEXTW
);
2232 case TTM_GETTIPBKCOLOR
:
2233 return TOOLTIPS_GetTipBkColor (infoPtr
);
2235 case TTM_GETTIPTEXTCOLOR
:
2236 return TOOLTIPS_GetTipTextColor (infoPtr
);
2238 case TTM_GETTOOLCOUNT
:
2239 return TOOLTIPS_GetToolCount (infoPtr
);
2241 case TTM_GETTOOLINFOA
:
2242 case TTM_GETTOOLINFOW
:
2243 return TOOLTIPS_GetToolInfoT (infoPtr
, (LPTTTOOLINFOW
)lParam
,
2244 uMsg
== TTM_GETTOOLINFOW
);
2248 return TOOLTIPS_HitTestT (infoPtr
, (LPTTHITTESTINFOW
)lParam
,
2249 uMsg
== TTM_HITTESTW
);
2250 case TTM_NEWTOOLRECTA
:
2251 case TTM_NEWTOOLRECTW
:
2252 return TOOLTIPS_NewToolRectT (infoPtr
, (LPTTTOOLINFOW
)lParam
);
2255 return TOOLTIPS_Pop (infoPtr
);
2257 case TTM_RELAYEVENT
:
2258 return TOOLTIPS_RelayEvent (infoPtr
, (LPMSG
)lParam
);
2260 case TTM_SETDELAYTIME
:
2261 return TOOLTIPS_SetDelayTime (infoPtr
, (DWORD
)wParam
, (INT
)LOWORD(lParam
));
2264 return TOOLTIPS_SetMargin (infoPtr
, (LPRECT
)lParam
);
2266 case TTM_SETMAXTIPWIDTH
:
2267 return TOOLTIPS_SetMaxTipWidth (infoPtr
, (INT
)lParam
);
2269 case TTM_SETTIPBKCOLOR
:
2270 return TOOLTIPS_SetTipBkColor (infoPtr
, (COLORREF
)wParam
);
2272 case TTM_SETTIPTEXTCOLOR
:
2273 return TOOLTIPS_SetTipTextColor (infoPtr
, (COLORREF
)wParam
);
2277 return TOOLTIPS_SetTitleT (infoPtr
, (UINT_PTR
)wParam
, (LPCWSTR
)lParam
,
2278 uMsg
== TTM_SETTITLEW
);
2280 case TTM_SETTOOLINFOA
:
2281 case TTM_SETTOOLINFOW
:
2282 return TOOLTIPS_SetToolInfoT (infoPtr
, (LPTTTOOLINFOW
)lParam
,
2283 uMsg
== TTM_SETTOOLINFOW
);
2285 case TTM_TRACKACTIVATE
:
2286 return TOOLTIPS_TrackActivate (infoPtr
, (BOOL
)wParam
, (LPTTTOOLINFOA
)lParam
);
2288 case TTM_TRACKPOSITION
:
2289 return TOOLTIPS_TrackPosition (infoPtr
, lParam
);
2292 return TOOLTIPS_Update (infoPtr
);
2294 case TTM_UPDATETIPTEXTA
:
2295 case TTM_UPDATETIPTEXTW
:
2296 return TOOLTIPS_UpdateTipTextT (infoPtr
, (LPTTTOOLINFOW
)lParam
,
2297 uMsg
== TTM_UPDATETIPTEXTW
);
2299 case TTM_WINDOWFROMPOINT
:
2300 return (LRESULT
)WindowFromPoint (*((LPPOINT
)lParam
));
2303 return TOOLTIPS_Create (hwnd
);
2306 return TOOLTIPS_Destroy (infoPtr
);
2309 /* we draw the background in WM_PAINT */
2313 return TOOLTIPS_GetFont (infoPtr
);
2316 return TOOLTIPS_OnWMGetText (infoPtr
, wParam
, (LPWSTR
)lParam
);
2318 case WM_GETTEXTLENGTH
:
2319 return TOOLTIPS_GetTextLength (infoPtr
);
2321 case WM_LBUTTONDOWN
:
2323 case WM_MBUTTONDOWN
:
2325 case WM_RBUTTONDOWN
:
2328 return TOOLTIPS_MouseMessage (infoPtr
);
2331 return TOOLTIPS_NCCreate (hwnd
);
2334 return TOOLTIPS_NCHitTest (infoPtr
, wParam
, lParam
);
2336 case WM_NOTIFYFORMAT
:
2337 return TOOLTIPS_NotifyFormat (infoPtr
, wParam
, lParam
);
2339 case WM_PRINTCLIENT
:
2341 return TOOLTIPS_Paint (infoPtr
, (HDC
)wParam
);
2344 return TOOLTIPS_SetFont (infoPtr
, (HFONT
)wParam
, LOWORD(lParam
));
2346 case WM_SYSCOLORCHANGE
:
2347 COMCTL32_RefreshSysColors();
2351 return TOOLTIPS_Timer (infoPtr
, (INT
)wParam
);
2353 case WM_WININICHANGE
:
2354 return TOOLTIPS_WinIniChange (infoPtr
);
2357 if ((uMsg
>= WM_USER
) && (uMsg
< WM_APP
) && !COMCTL32_IsReflectedMessage(uMsg
))
2358 ERR("unknown msg %04x wp=%08lx lp=%08lx\n",
2359 uMsg
, wParam
, lParam
);
2360 return DefWindowProcW (hwnd
, uMsg
, wParam
, lParam
);
2366 TOOLTIPS_Register (void)
2370 ZeroMemory (&wndClass
, sizeof(WNDCLASSW
));
2371 wndClass
.style
= CS_GLOBALCLASS
| CS_DBLCLKS
| CS_SAVEBITS
;
2372 wndClass
.lpfnWndProc
= TOOLTIPS_WindowProc
;
2373 wndClass
.cbClsExtra
= 0;
2374 wndClass
.cbWndExtra
= sizeof(TOOLTIPS_INFO
*);
2375 wndClass
.hCursor
= LoadCursorW (0, (LPWSTR
)IDC_ARROW
);
2376 wndClass
.hbrBackground
= 0;
2377 wndClass
.lpszClassName
= TOOLTIPS_CLASSW
;
2379 RegisterClassW (&wndClass
);
2381 hTooltipIcons
[TTI_NONE
] = NULL
;
2382 hTooltipIcons
[TTI_INFO
] = LoadImageW(COMCTL32_hModule
,
2383 (LPCWSTR
)MAKEINTRESOURCE(IDI_TT_INFO_SM
), IMAGE_ICON
, 0, 0, 0);
2384 hTooltipIcons
[TTI_WARNING
] = LoadImageW(COMCTL32_hModule
,
2385 (LPCWSTR
)MAKEINTRESOURCE(IDI_TT_WARN_SM
), IMAGE_ICON
, 0, 0, 0);
2386 hTooltipIcons
[TTI_ERROR
] = LoadImageW(COMCTL32_hModule
,
2387 (LPCWSTR
)MAKEINTRESOURCE(IDI_TT_ERROR_SM
), IMAGE_ICON
, 0, 0, 0);
2392 TOOLTIPS_Unregister (void)
2395 for (i
= TTI_INFO
; i
<= TTI_ERROR
; i
++)
2396 DestroyIcon(hTooltipIcons
[i
]);
2397 UnregisterClassW (TOOLTIPS_CLASSW
, NULL
);