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 TRACE("%s\n", debugstr_w(buffer
));
517 TOOLTIPS_CalcTipSize (const TOOLTIPS_INFO
*infoPtr
, LPSIZE lpSize
)
521 DWORD style
= GetWindowLongW(infoPtr
->hwndSelf
, GWL_STYLE
);
522 UINT uFlags
= DT_EXTERNALLEADING
| DT_CALCRECT
;
523 RECT rc
= {0, 0, 0, 0};
526 if (infoPtr
->nMaxTipWidth
> -1) {
527 rc
.right
= infoPtr
->nMaxTipWidth
;
528 uFlags
|= DT_WORDBREAK
;
530 if (style
& TTS_NOPREFIX
)
531 uFlags
|= DT_NOPREFIX
;
532 TRACE("%s\n", debugstr_w(infoPtr
->szTipText
));
534 hdc
= GetDC (infoPtr
->hwndSelf
);
535 if (infoPtr
->pszTitle
)
537 RECT rcTitle
= {0, 0, 0, 0};
538 TRACE("title %s\n", debugstr_w(infoPtr
->pszTitle
));
539 if (infoPtr
->hTitleIcon
)
541 title
.cx
= ICON_WIDTH
;
542 title
.cy
= ICON_HEIGHT
;
544 if (title
.cx
!= 0) title
.cx
+= BALLOON_ICON_TITLE_SPACING
;
545 hOldFont
= SelectObject (hdc
, infoPtr
->hTitleFont
);
546 DrawTextW(hdc
, infoPtr
->pszTitle
, -1, &rcTitle
, DT_SINGLELINE
| DT_NOPREFIX
| DT_CALCRECT
);
547 SelectObject (hdc
, hOldFont
);
548 title
.cy
= max(title
.cy
, rcTitle
.bottom
- rcTitle
.top
) + BALLOON_TITLE_TEXT_SPACING
;
549 title
.cx
+= (rcTitle
.right
- rcTitle
.left
);
551 hOldFont
= SelectObject (hdc
, infoPtr
->hFont
);
552 DrawTextW (hdc
, infoPtr
->szTipText
, -1, &rc
, uFlags
);
553 SelectObject (hdc
, hOldFont
);
554 ReleaseDC (infoPtr
->hwndSelf
, hdc
);
556 if ((style
& TTS_BALLOON
) || infoPtr
->pszTitle
)
558 lpSize
->cx
= max(rc
.right
- rc
.left
, title
.cx
) + 2*BALLOON_TEXT_MARGIN
+
559 infoPtr
->rcMargin
.left
+ infoPtr
->rcMargin
.right
;
560 lpSize
->cy
= title
.cy
+ rc
.bottom
- rc
.top
+ 2*BALLOON_TEXT_MARGIN
+
561 infoPtr
->rcMargin
.bottom
+ infoPtr
->rcMargin
.top
+
566 lpSize
->cx
= rc
.right
- rc
.left
+ 2*NORMAL_TEXT_MARGIN
+
567 infoPtr
->rcMargin
.left
+ infoPtr
->rcMargin
.right
;
568 lpSize
->cy
= rc
.bottom
- rc
.top
+ 2*NORMAL_TEXT_MARGIN
+
569 infoPtr
->rcMargin
.bottom
+ infoPtr
->rcMargin
.top
;
575 TOOLTIPS_Show (TOOLTIPS_INFO
*infoPtr
, BOOL track_activate
)
577 TTTOOL_INFO
*toolPtr
;
579 MONITORINFO mon_info
;
584 DWORD style
= GetWindowLongW(infoPtr
->hwndSelf
, GWL_STYLE
);
589 if (infoPtr
->nTrackTool
== -1)
591 TRACE("invalid tracking tool (-1)!\n");
594 nTool
= infoPtr
->nTrackTool
;
598 if (infoPtr
->nTool
== -1)
600 TRACE("invalid tool (-1)!\n");
603 nTool
= infoPtr
->nTool
;
606 TRACE("Show tooltip pre %d! (%p)\n", nTool
, infoPtr
->hwndSelf
);
608 TOOLTIPS_GetTipText (infoPtr
, nTool
, infoPtr
->szTipText
);
610 if (infoPtr
->szTipText
[0] == '\0')
613 toolPtr
= &infoPtr
->tools
[nTool
];
616 infoPtr
->nCurrentTool
= infoPtr
->nTool
;
618 TRACE("Show tooltip %d!\n", nTool
);
620 hdr
.hwndFrom
= infoPtr
->hwndSelf
;
621 hdr
.idFrom
= toolPtr
->uId
;
623 SendMessageW (toolPtr
->hwnd
, WM_NOTIFY
, toolPtr
->uId
, (LPARAM
)&hdr
);
625 TRACE("%s\n", debugstr_w(infoPtr
->szTipText
));
627 TOOLTIPS_CalcTipSize (infoPtr
, &size
);
628 TRACE("size %d x %d\n", size
.cx
, size
.cy
);
630 if (track_activate
&& (toolPtr
->uFlags
& TTF_TRACK
))
632 rect
.left
= infoPtr
->xTrackPos
;
633 rect
.top
= infoPtr
->yTrackPos
;
636 if (toolPtr
->uFlags
& TTF_CENTERTIP
)
638 rect
.left
-= (size
.cx
/ 2);
639 if (!(style
& TTS_BALLOON
))
640 rect
.top
-= (size
.cy
/ 2);
642 if (!(infoPtr
->bToolBelow
= (infoPtr
->yTrackPos
+ size
.cy
<= GetSystemMetrics(SM_CYSCREEN
))))
645 if (!(toolPtr
->uFlags
& TTF_ABSOLUTE
))
647 if (style
& TTS_BALLOON
)
648 rect
.left
-= BALLOON_STEMINDENT
;
653 if (toolPtr
->uFlags
& TTF_IDISHWND
)
654 GetWindowRect ((HWND
)toolPtr
->uId
, &rcTool
);
657 rcTool
= toolPtr
->rect
;
658 MapWindowPoints (toolPtr
->hwnd
, NULL
, (LPPOINT
)&rcTool
, 2);
661 /* smart placement */
662 if ((rect
.left
+ size
.cx
> rcTool
.left
) && (rect
.left
< rcTool
.right
) &&
663 (rect
.top
+ size
.cy
> rcTool
.top
) && (rect
.top
< rcTool
.bottom
))
664 rect
.left
= rcTool
.right
;
670 if (toolPtr
->uFlags
& TTF_CENTERTIP
)
674 if (toolPtr
->uFlags
& TTF_IDISHWND
)
675 GetWindowRect ((HWND
)toolPtr
->uId
, &rc
);
678 MapWindowPoints (toolPtr
->hwnd
, NULL
, (LPPOINT
)&rc
, 2);
680 rect
.left
= (rc
.left
+ rc
.right
- size
.cx
) / 2;
681 if (style
& TTS_BALLOON
)
683 ptfx
= rc
.left
+ ((rc
.right
- rc
.left
) / 2);
685 /* CENTERTIP ballon tooltips default to below the field
686 * if they fit on the screen */
687 if (rc
.bottom
+ size
.cy
> GetSystemMetrics(SM_CYSCREEN
))
689 rect
.top
= rc
.top
- size
.cy
;
690 infoPtr
->bToolBelow
= FALSE
;
694 infoPtr
->bToolBelow
= TRUE
;
695 rect
.top
= rc
.bottom
;
697 rect
.left
= max(0, rect
.left
- BALLOON_STEMINDENT
);
701 rect
.top
= rc
.bottom
+ 2;
702 infoPtr
->bToolBelow
= TRUE
;
707 GetCursorPos ((LPPOINT
)&rect
);
708 if (style
& TTS_BALLOON
)
711 if(rect
.top
- size
.cy
>= 0)
714 infoPtr
->bToolBelow
= FALSE
;
718 infoPtr
->bToolBelow
= TRUE
;
721 rect
.left
= max(0, rect
.left
- BALLOON_STEMINDENT
);
726 infoPtr
->bToolBelow
= TRUE
;
731 TRACE("pos %d - %d\n", rect
.left
, rect
.top
);
733 rect
.right
= rect
.left
+ size
.cx
;
734 rect
.bottom
= rect
.top
+ size
.cy
;
738 monitor
= MonitorFromRect( &rect
, MONITOR_DEFAULTTOPRIMARY
);
739 mon_info
.cbSize
= sizeof(mon_info
);
740 GetMonitorInfoW( monitor
, &mon_info
);
742 if( rect
.right
> mon_info
.rcWork
.right
) {
743 rect
.left
-= rect
.right
- mon_info
.rcWork
.right
+ 2;
744 rect
.right
= mon_info
.rcWork
.right
- 2;
746 if (rect
.left
< mon_info
.rcWork
.left
) rect
.left
= mon_info
.rcWork
.left
;
748 if( rect
.bottom
> mon_info
.rcWork
.bottom
) {
751 if (toolPtr
->uFlags
& TTF_IDISHWND
)
752 GetWindowRect ((HWND
)toolPtr
->uId
, &rc
);
755 MapWindowPoints (toolPtr
->hwnd
, NULL
, (LPPOINT
)&rc
, 2);
757 rect
.bottom
= rc
.top
- 2;
758 rect
.top
= rect
.bottom
- size
.cy
;
761 AdjustWindowRectEx (&rect
, GetWindowLongW (infoPtr
->hwndSelf
, GWL_STYLE
),
762 FALSE
, GetWindowLongW (infoPtr
->hwndSelf
, GWL_EXSTYLE
));
764 if (style
& TTS_BALLOON
)
772 if(infoPtr
->bToolBelow
)
776 pts
[1].x
= max(BALLOON_STEMINDENT
, ptfx
- (BALLOON_STEMWIDTH
/ 2));
777 pts
[1].y
= BALLOON_STEMHEIGHT
;
778 pts
[2].x
= pts
[1].x
+ BALLOON_STEMWIDTH
;
780 if(pts
[2].x
> (rect
.right
- rect
.left
) - BALLOON_STEMINDENT
)
782 pts
[2].x
= (rect
.right
- rect
.left
) - BALLOON_STEMINDENT
;
783 pts
[1].x
= pts
[2].x
- BALLOON_STEMWIDTH
;
788 pts
[0].x
= max(BALLOON_STEMINDENT
, ptfx
- (BALLOON_STEMWIDTH
/ 2));
789 pts
[0].y
= (rect
.bottom
- rect
.top
) - BALLOON_STEMHEIGHT
;
790 pts
[1].x
= pts
[0].x
+ BALLOON_STEMWIDTH
;
793 pts
[2].y
= (rect
.bottom
- rect
.top
);
794 if(pts
[1].x
> (rect
.right
- rect
.left
) - BALLOON_STEMINDENT
)
796 pts
[1].x
= (rect
.right
- rect
.left
) - BALLOON_STEMINDENT
;
797 pts
[0].x
= pts
[1].x
- BALLOON_STEMWIDTH
;
801 hrStem
= CreatePolygonRgn(pts
, sizeof(pts
) / sizeof(pts
[0]), ALTERNATE
);
803 hRgn
= CreateRoundRectRgn(0,
804 (infoPtr
->bToolBelow
? BALLOON_STEMHEIGHT
: 0),
805 rect
.right
- rect
.left
,
806 (infoPtr
->bToolBelow
? rect
.bottom
- rect
.top
: rect
.bottom
- rect
.top
- BALLOON_STEMHEIGHT
),
807 BALLOON_ROUNDEDNESS
, BALLOON_ROUNDEDNESS
);
809 CombineRgn(hRgn
, hRgn
, hrStem
, RGN_OR
);
810 DeleteObject(hrStem
);
812 SetWindowRgn(infoPtr
->hwndSelf
, hRgn
, FALSE
);
813 /* we don't free the region handle as the system deletes it when
814 * it is no longer needed */
817 SetWindowPos (infoPtr
->hwndSelf
, HWND_TOPMOST
, rect
.left
, rect
.top
,
818 rect
.right
- rect
.left
, rect
.bottom
- rect
.top
,
819 SWP_SHOWWINDOW
| SWP_NOACTIVATE
);
821 /* repaint the tooltip */
822 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
823 UpdateWindow(infoPtr
->hwndSelf
);
827 SetTimer (infoPtr
->hwndSelf
, ID_TIMERPOP
, infoPtr
->nAutoPopTime
, 0);
828 TRACE("timer 2 started!\n");
829 SetTimer (infoPtr
->hwndSelf
, ID_TIMERLEAVE
, infoPtr
->nReshowTime
, 0);
830 TRACE("timer 3 started!\n");
836 TOOLTIPS_Hide (TOOLTIPS_INFO
*infoPtr
)
838 TTTOOL_INFO
*toolPtr
;
841 TRACE("Hide tooltip %d! (%p)\n", infoPtr
->nCurrentTool
, infoPtr
->hwndSelf
);
843 if (infoPtr
->nCurrentTool
== -1)
846 toolPtr
= &infoPtr
->tools
[infoPtr
->nCurrentTool
];
847 KillTimer (infoPtr
->hwndSelf
, ID_TIMERPOP
);
849 hdr
.hwndFrom
= infoPtr
->hwndSelf
;
850 hdr
.idFrom
= toolPtr
->uId
;
852 SendMessageW (toolPtr
->hwnd
, WM_NOTIFY
, toolPtr
->uId
, (LPARAM
)&hdr
);
854 infoPtr
->nCurrentTool
= -1;
856 SetWindowPos (infoPtr
->hwndSelf
, HWND_TOP
, 0, 0, 0, 0,
857 SWP_NOZORDER
| SWP_HIDEWINDOW
| SWP_NOACTIVATE
);
862 TOOLTIPS_TrackShow (TOOLTIPS_INFO
*infoPtr
)
864 TOOLTIPS_Show(infoPtr
, TRUE
);
869 TOOLTIPS_TrackHide (const TOOLTIPS_INFO
*infoPtr
)
871 TTTOOL_INFO
*toolPtr
;
874 TRACE("hide tracking tooltip %d\n", infoPtr
->nTrackTool
);
876 if (infoPtr
->nTrackTool
== -1)
879 toolPtr
= &infoPtr
->tools
[infoPtr
->nTrackTool
];
881 hdr
.hwndFrom
= infoPtr
->hwndSelf
;
882 hdr
.idFrom
= toolPtr
->uId
;
884 SendMessageW (toolPtr
->hwnd
, WM_NOTIFY
, toolPtr
->uId
, (LPARAM
)&hdr
);
886 SetWindowPos (infoPtr
->hwndSelf
, HWND_TOP
, 0, 0, 0, 0,
887 SWP_NOZORDER
| SWP_HIDEWINDOW
| SWP_NOACTIVATE
);
890 /* Structure layout is the same for TTTOOLINFOW and TTTOOLINFOA,
891 this helper is used in both cases. */
893 TOOLTIPS_GetToolFromInfoT (const TOOLTIPS_INFO
*infoPtr
, const TTTOOLINFOW
*lpToolInfo
)
895 TTTOOL_INFO
*toolPtr
;
898 for (nTool
= 0; nTool
< infoPtr
->uNumTools
; nTool
++) {
899 toolPtr
= &infoPtr
->tools
[nTool
];
901 if (!(toolPtr
->uFlags
& TTF_IDISHWND
) &&
902 (lpToolInfo
->hwnd
== toolPtr
->hwnd
) &&
903 (lpToolInfo
->uId
== toolPtr
->uId
))
907 for (nTool
= 0; nTool
< infoPtr
->uNumTools
; nTool
++) {
908 toolPtr
= &infoPtr
->tools
[nTool
];
910 if ((toolPtr
->uFlags
& TTF_IDISHWND
) &&
911 (lpToolInfo
->uId
== toolPtr
->uId
))
920 TOOLTIPS_GetToolFromPoint (const TOOLTIPS_INFO
*infoPtr
, HWND hwnd
, const POINT
*lpPt
)
922 TTTOOL_INFO
*toolPtr
;
925 for (nTool
= 0; nTool
< infoPtr
->uNumTools
; nTool
++) {
926 toolPtr
= &infoPtr
->tools
[nTool
];
928 if (!(toolPtr
->uFlags
& TTF_IDISHWND
)) {
929 if (hwnd
!= toolPtr
->hwnd
)
931 if (!PtInRect (&toolPtr
->rect
, *lpPt
))
937 for (nTool
= 0; nTool
< infoPtr
->uNumTools
; nTool
++) {
938 toolPtr
= &infoPtr
->tools
[nTool
];
940 if (toolPtr
->uFlags
& TTF_IDISHWND
) {
941 if ((HWND
)toolPtr
->uId
== hwnd
)
950 TOOLTIPS_CopyInfoT (const TTTOOL_INFO
*toolPtr
, TTTOOLINFOW
*ti
, BOOL isW
)
953 if (toolPtr
->lpszText
== NULL
||
954 IS_INTRESOURCE(toolPtr
->lpszText
) ||
955 toolPtr
->lpszText
== LPSTR_TEXTCALLBACKW
)
956 ti
->lpszText
= toolPtr
->lpszText
;
958 strcpyW (ti
->lpszText
, toolPtr
->lpszText
);
960 /* ANSI version, the buffer is maximum 80 bytes without null. */
961 WideCharToMultiByte(CP_ACP
, 0, toolPtr
->lpszText
, -1,
962 (LPSTR
)ti
->lpszText
, MAX_TEXT_SIZE_A
, NULL
, NULL
);
967 TOOLTIPS_IsWindowActive (HWND hwnd
)
969 HWND hwndActive
= GetActiveWindow ();
972 if (hwndActive
== hwnd
)
974 return IsChild (hwndActive
, hwnd
);
979 TOOLTIPS_CheckTool (const TOOLTIPS_INFO
*infoPtr
, BOOL bShowTest
)
986 hwndTool
= (HWND
)SendMessageW (infoPtr
->hwndSelf
, TTM_WINDOWFROMPOINT
, 0, (LPARAM
)&pt
);
990 ScreenToClient (hwndTool
, &pt
);
991 nTool
= TOOLTIPS_GetToolFromPoint (infoPtr
, hwndTool
, &pt
);
995 if (!(GetWindowLongW (infoPtr
->hwndSelf
, GWL_STYLE
) & TTS_ALWAYSTIP
) && bShowTest
)
997 TTTOOL_INFO
*ti
= &infoPtr
->tools
[nTool
];
998 HWND hwnd
= (ti
->uFlags
& TTF_IDISHWND
) ? (HWND
)ti
->uId
: ti
->hwnd
;
1000 if (!TOOLTIPS_IsWindowActive(hwnd
))
1002 TRACE("not active: hwnd %p, parent %p, active %p\n",
1003 hwnd
, GetParent(hwnd
), GetActiveWindow());
1008 TRACE("tool %d\n", nTool
);
1015 TOOLTIPS_Activate (TOOLTIPS_INFO
*infoPtr
, BOOL activate
)
1017 infoPtr
->bActive
= activate
;
1019 if (infoPtr
->bActive
)
1020 TRACE("activate!\n");
1022 if (!(infoPtr
->bActive
) && (infoPtr
->nCurrentTool
!= -1))
1023 TOOLTIPS_Hide (infoPtr
);
1030 TOOLTIPS_AddToolT (TOOLTIPS_INFO
*infoPtr
, const TTTOOLINFOW
*ti
, BOOL isW
)
1032 TTTOOL_INFO
*toolPtr
;
1035 if (!ti
) return FALSE
;
1037 TRACE("add tool (%p) %p %ld%s!\n",
1038 infoPtr
->hwndSelf
, ti
->hwnd
, ti
->uId
,
1039 (ti
->uFlags
& TTF_IDISHWND
) ? " TTF_IDISHWND" : "");
1041 if (ti
->cbSize
>= TTTOOLINFOW_V2_SIZE
&& !ti
->lpszText
&& isW
)
1044 if (infoPtr
->uNumTools
== 0) {
1045 infoPtr
->tools
= Alloc (sizeof(TTTOOL_INFO
));
1046 toolPtr
= infoPtr
->tools
;
1049 TTTOOL_INFO
*oldTools
= infoPtr
->tools
;
1051 Alloc (sizeof(TTTOOL_INFO
) * (infoPtr
->uNumTools
+ 1));
1052 memcpy (infoPtr
->tools
, oldTools
,
1053 infoPtr
->uNumTools
* sizeof(TTTOOL_INFO
));
1055 toolPtr
= &infoPtr
->tools
[infoPtr
->uNumTools
];
1058 infoPtr
->uNumTools
++;
1060 /* copy tool data */
1061 toolPtr
->uFlags
= ti
->uFlags
;
1062 toolPtr
->uInternalFlags
= (ti
->uFlags
& (TTF_SUBCLASS
| TTF_IDISHWND
));
1063 toolPtr
->hwnd
= ti
->hwnd
;
1064 toolPtr
->uId
= ti
->uId
;
1065 toolPtr
->rect
= ti
->rect
;
1066 toolPtr
->hinst
= ti
->hinst
;
1068 if (ti
->cbSize
>= TTTOOLINFOW_V1_SIZE
) {
1069 if (IS_INTRESOURCE(ti
->lpszText
)) {
1070 TRACE("add string id %x\n", LOWORD(ti
->lpszText
));
1071 toolPtr
->lpszText
= ti
->lpszText
;
1073 else if (ti
->lpszText
) {
1074 if (TOOLTIPS_IsCallbackString(ti
->lpszText
, isW
)) {
1075 TRACE("add CALLBACK!\n");
1076 toolPtr
->lpszText
= LPSTR_TEXTCALLBACKW
;
1079 INT len
= lstrlenW (ti
->lpszText
);
1080 TRACE("add text %s!\n", debugstr_w(ti
->lpszText
));
1081 toolPtr
->lpszText
= Alloc ((len
+ 1)*sizeof(WCHAR
));
1082 strcpyW (toolPtr
->lpszText
, ti
->lpszText
);
1085 INT len
= MultiByteToWideChar(CP_ACP
, 0, (LPSTR
)ti
->lpszText
, -1, NULL
, 0);
1086 TRACE("add text \"%s\"!\n", (LPSTR
)ti
->lpszText
);
1087 toolPtr
->lpszText
= Alloc (len
* sizeof(WCHAR
));
1088 MultiByteToWideChar(CP_ACP
, 0, (LPSTR
)ti
->lpszText
, -1, toolPtr
->lpszText
, len
);
1093 if (ti
->cbSize
>= TTTOOLINFOW_V2_SIZE
)
1094 toolPtr
->lParam
= ti
->lParam
;
1096 /* install subclassing hook */
1097 if (toolPtr
->uInternalFlags
& TTF_SUBCLASS
) {
1098 if (toolPtr
->uInternalFlags
& TTF_IDISHWND
) {
1099 SetWindowSubclass((HWND
)toolPtr
->uId
, TOOLTIPS_SubclassProc
, 1,
1100 (DWORD_PTR
)infoPtr
->hwndSelf
);
1103 SetWindowSubclass(toolPtr
->hwnd
, TOOLTIPS_SubclassProc
, 1,
1104 (DWORD_PTR
)infoPtr
->hwndSelf
);
1106 TRACE("subclassing installed!\n");
1109 nResult
= SendMessageW (toolPtr
->hwnd
, WM_NOTIFYFORMAT
,
1110 (WPARAM
)infoPtr
->hwndSelf
, NF_QUERY
);
1111 if (nResult
== NFR_ANSI
) {
1112 toolPtr
->bNotifyUnicode
= FALSE
;
1113 TRACE(" -- WM_NOTIFYFORMAT returns: NFR_ANSI\n");
1114 } else if (nResult
== NFR_UNICODE
) {
1115 toolPtr
->bNotifyUnicode
= TRUE
;
1116 TRACE(" -- WM_NOTIFYFORMAT returns: NFR_UNICODE\n");
1118 TRACE (" -- WM_NOTIFYFORMAT returns: error!\n");
1126 TOOLTIPS_DelToolT (TOOLTIPS_INFO
*infoPtr
, const TTTOOLINFOW
*ti
, BOOL isW
)
1128 TTTOOL_INFO
*toolPtr
;
1132 if (isW
&& ti
->cbSize
> TTTOOLINFOW_V2_SIZE
&&
1133 ti
->cbSize
!= TTTOOLINFOW_V3_SIZE
)
1135 if (infoPtr
->uNumTools
== 0)
1138 nTool
= TOOLTIPS_GetToolFromInfoT (infoPtr
, ti
);
1140 TRACE("tool %d\n", nTool
);
1145 /* make sure the tooltip has disappeared before deleting it */
1146 TOOLTIPS_Hide(infoPtr
);
1148 /* delete text string */
1149 toolPtr
= &infoPtr
->tools
[nTool
];
1150 if (toolPtr
->lpszText
) {
1151 if ( (toolPtr
->lpszText
!= LPSTR_TEXTCALLBACKW
) &&
1152 !IS_INTRESOURCE(toolPtr
->lpszText
) )
1153 Free (toolPtr
->lpszText
);
1156 /* remove subclassing */
1157 if (toolPtr
->uInternalFlags
& TTF_SUBCLASS
) {
1158 if (toolPtr
->uInternalFlags
& TTF_IDISHWND
) {
1159 RemoveWindowSubclass((HWND
)toolPtr
->uId
, TOOLTIPS_SubclassProc
, 1);
1162 RemoveWindowSubclass(toolPtr
->hwnd
, TOOLTIPS_SubclassProc
, 1);
1166 /* delete tool from tool list */
1167 if (infoPtr
->uNumTools
== 1) {
1168 Free (infoPtr
->tools
);
1169 infoPtr
->tools
= NULL
;
1172 TTTOOL_INFO
*oldTools
= infoPtr
->tools
;
1174 Alloc (sizeof(TTTOOL_INFO
) * (infoPtr
->uNumTools
- 1));
1177 memcpy (&infoPtr
->tools
[0], &oldTools
[0],
1178 nTool
* sizeof(TTTOOL_INFO
));
1180 if (nTool
< infoPtr
->uNumTools
- 1)
1181 memcpy (&infoPtr
->tools
[nTool
], &oldTools
[nTool
+ 1],
1182 (infoPtr
->uNumTools
- nTool
- 1) * sizeof(TTTOOL_INFO
));
1187 /* update any indices affected by delete */
1189 /* destroying tool that mouse was on on last relayed mouse move */
1190 if (infoPtr
->nTool
== nTool
)
1191 /* -1 means no current tool (0 means first tool) */
1192 infoPtr
->nTool
= -1;
1193 else if (infoPtr
->nTool
> nTool
)
1196 if (infoPtr
->nTrackTool
== nTool
)
1197 /* -1 means no current tool (0 means first tool) */
1198 infoPtr
->nTrackTool
= -1;
1199 else if (infoPtr
->nTrackTool
> nTool
)
1200 infoPtr
->nTrackTool
--;
1202 if (infoPtr
->nCurrentTool
== nTool
)
1203 /* -1 means no current tool (0 means first tool) */
1204 infoPtr
->nCurrentTool
= -1;
1205 else if (infoPtr
->nCurrentTool
> nTool
)
1206 infoPtr
->nCurrentTool
--;
1208 infoPtr
->uNumTools
--;
1214 TOOLTIPS_EnumToolsT (const TOOLTIPS_INFO
*infoPtr
, UINT uIndex
, TTTOOLINFOW
*ti
,
1217 TTTOOL_INFO
*toolPtr
;
1219 if (!ti
) return FALSE
;
1220 if (ti
->cbSize
< TTTOOLINFOW_V1_SIZE
)
1222 if (uIndex
>= infoPtr
->uNumTools
)
1225 TRACE("index=%u\n", uIndex
);
1227 toolPtr
= &infoPtr
->tools
[uIndex
];
1229 /* copy tool data */
1230 ti
->uFlags
= toolPtr
->uFlags
;
1231 ti
->hwnd
= toolPtr
->hwnd
;
1232 ti
->uId
= toolPtr
->uId
;
1233 ti
->rect
= toolPtr
->rect
;
1234 ti
->hinst
= toolPtr
->hinst
;
1235 TOOLTIPS_CopyInfoT (toolPtr
, ti
, isW
);
1237 if (ti
->cbSize
>= TTTOOLINFOA_V2_SIZE
)
1238 ti
->lParam
= toolPtr
->lParam
;
1244 TOOLTIPS_GetBubbleSize (const TOOLTIPS_INFO
*infoPtr
, const TTTOOLINFOW
*lpToolInfo
)
1249 if (lpToolInfo
== NULL
)
1251 if (lpToolInfo
->cbSize
< TTTOOLINFOW_V1_SIZE
)
1254 nTool
= TOOLTIPS_GetToolFromInfoT (infoPtr
, lpToolInfo
);
1255 if (nTool
== -1) return 0;
1257 TRACE("tool %d\n", nTool
);
1259 TOOLTIPS_CalcTipSize (infoPtr
, &size
);
1260 TRACE("size %d x %d\n", size
.cx
, size
.cy
);
1262 return MAKELRESULT(size
.cx
, size
.cy
);
1266 TOOLTIPS_GetCurrentToolT (const TOOLTIPS_INFO
*infoPtr
, TTTOOLINFOW
*ti
, BOOL isW
)
1268 TTTOOL_INFO
*toolPtr
;
1271 if (ti
->cbSize
< TTTOOLINFOW_V1_SIZE
)
1274 if (infoPtr
->nCurrentTool
> -1) {
1275 toolPtr
= &infoPtr
->tools
[infoPtr
->nCurrentTool
];
1277 /* copy tool data */
1278 ti
->uFlags
= toolPtr
->uFlags
;
1279 ti
->rect
= toolPtr
->rect
;
1280 ti
->hinst
= toolPtr
->hinst
;
1281 TOOLTIPS_CopyInfoT (toolPtr
, ti
, isW
);
1283 if (ti
->cbSize
>= TTTOOLINFOW_V2_SIZE
)
1284 ti
->lParam
= toolPtr
->lParam
;
1292 return (infoPtr
->nCurrentTool
!= -1);
1297 TOOLTIPS_GetDelayTime (const TOOLTIPS_INFO
*infoPtr
, DWORD duration
)
1301 return infoPtr
->nReshowTime
;
1304 return infoPtr
->nAutoPopTime
;
1307 case TTDT_AUTOMATIC
: /* Apparently TTDT_AUTOMATIC returns TTDT_INITIAL */
1308 return infoPtr
->nInitialTime
;
1311 WARN("Invalid duration flag %x\n", duration
);
1320 TOOLTIPS_GetMargin (const TOOLTIPS_INFO
*infoPtr
, LPRECT lpRect
)
1322 lpRect
->left
= infoPtr
->rcMargin
.left
;
1323 lpRect
->right
= infoPtr
->rcMargin
.right
;
1324 lpRect
->bottom
= infoPtr
->rcMargin
.bottom
;
1325 lpRect
->top
= infoPtr
->rcMargin
.top
;
1331 static inline LRESULT
1332 TOOLTIPS_GetMaxTipWidth (const TOOLTIPS_INFO
*infoPtr
)
1334 return infoPtr
->nMaxTipWidth
;
1339 TOOLTIPS_GetTextT (const TOOLTIPS_INFO
*infoPtr
, TTTOOLINFOW
*ti
, BOOL isW
)
1344 if (ti
->cbSize
< TTTOOLINFOW_V1_SIZE
)
1347 nTool
= TOOLTIPS_GetToolFromInfoT (infoPtr
, ti
);
1348 if (nTool
== -1) return 0;
1350 if (infoPtr
->tools
[nTool
].lpszText
== NULL
)
1354 ti
->lpszText
[0] = '\0';
1355 TOOLTIPS_GetTipText(infoPtr
, nTool
, ti
->lpszText
);
1358 WCHAR buffer
[INFOTIPSIZE
];
1360 /* NB this API is broken, there is no way for the app to determine
1361 what size buffer it requires nor a way to specify how long the
1362 one it supplies is. According to the test result, it's up to
1363 80 bytes by the ANSI version. */
1366 TOOLTIPS_GetTipText(infoPtr
, nTool
, buffer
);
1367 WideCharToMultiByte(CP_ACP
, 0, buffer
, -1, (LPSTR
)ti
->lpszText
,
1368 MAX_TEXT_SIZE_A
, NULL
, NULL
);
1375 static inline LRESULT
1376 TOOLTIPS_GetTipBkColor (const TOOLTIPS_INFO
*infoPtr
)
1378 return infoPtr
->clrBk
;
1382 static inline LRESULT
1383 TOOLTIPS_GetTipTextColor (const TOOLTIPS_INFO
*infoPtr
)
1385 return infoPtr
->clrText
;
1389 static inline LRESULT
1390 TOOLTIPS_GetToolCount (const TOOLTIPS_INFO
*infoPtr
)
1392 return infoPtr
->uNumTools
;
1397 TOOLTIPS_GetToolInfoT (const TOOLTIPS_INFO
*infoPtr
, TTTOOLINFOW
*ti
, BOOL isW
)
1399 TTTOOL_INFO
*toolPtr
;
1402 if (!ti
) return FALSE
;
1403 if (ti
->cbSize
< TTTOOLINFOW_V1_SIZE
)
1405 if (infoPtr
->uNumTools
== 0)
1408 nTool
= TOOLTIPS_GetToolFromInfoT (infoPtr
, ti
);
1412 TRACE("tool %d\n", nTool
);
1414 toolPtr
= &infoPtr
->tools
[nTool
];
1416 /* copy tool data */
1417 ti
->uFlags
= toolPtr
->uFlags
;
1418 ti
->rect
= toolPtr
->rect
;
1419 ti
->hinst
= toolPtr
->hinst
;
1420 TOOLTIPS_CopyInfoT (toolPtr
, ti
, isW
);
1422 if (ti
->cbSize
>= TTTOOLINFOW_V2_SIZE
)
1423 ti
->lParam
= toolPtr
->lParam
;
1430 TOOLTIPS_HitTestT (const TOOLTIPS_INFO
*infoPtr
, LPTTHITTESTINFOW lptthit
,
1433 TTTOOL_INFO
*toolPtr
;
1439 nTool
= TOOLTIPS_GetToolFromPoint (infoPtr
, lptthit
->hwnd
, &lptthit
->pt
);
1443 TRACE("tool %d!\n", nTool
);
1445 /* copy tool data */
1446 if (lptthit
->ti
.cbSize
>= TTTOOLINFOW_V1_SIZE
) {
1447 toolPtr
= &infoPtr
->tools
[nTool
];
1449 lptthit
->ti
.uFlags
= toolPtr
->uFlags
;
1450 lptthit
->ti
.hwnd
= toolPtr
->hwnd
;
1451 lptthit
->ti
.uId
= toolPtr
->uId
;
1452 lptthit
->ti
.rect
= toolPtr
->rect
;
1453 lptthit
->ti
.hinst
= toolPtr
->hinst
;
1454 TOOLTIPS_CopyInfoT (toolPtr
, &lptthit
->ti
, isW
);
1455 if (lptthit
->ti
.cbSize
>= TTTOOLINFOW_V2_SIZE
)
1456 lptthit
->ti
.lParam
= toolPtr
->lParam
;
1464 TOOLTIPS_NewToolRectT (TOOLTIPS_INFO
*infoPtr
, const TTTOOLINFOW
*ti
)
1469 if (ti
->cbSize
< TTTOOLINFOW_V1_SIZE
)
1472 nTool
= TOOLTIPS_GetToolFromInfoT (infoPtr
, ti
);
1474 TRACE("nTool = %d, rect = %s\n", nTool
, wine_dbgstr_rect(&ti
->rect
));
1476 if (nTool
== -1) return 0;
1478 infoPtr
->tools
[nTool
].rect
= ti
->rect
;
1484 static inline LRESULT
1485 TOOLTIPS_Pop (TOOLTIPS_INFO
*infoPtr
)
1487 TOOLTIPS_Hide (infoPtr
);
1494 TOOLTIPS_RelayEvent (TOOLTIPS_INFO
*infoPtr
, LPMSG lpMsg
)
1500 ERR("lpMsg == NULL!\n");
1504 switch (lpMsg
->message
) {
1505 case WM_LBUTTONDOWN
:
1507 case WM_MBUTTONDOWN
:
1509 case WM_RBUTTONDOWN
:
1511 TOOLTIPS_Hide (infoPtr
);
1515 pt
.x
= (short)LOWORD(lpMsg
->lParam
);
1516 pt
.y
= (short)HIWORD(lpMsg
->lParam
);
1517 nOldTool
= infoPtr
->nTool
;
1518 infoPtr
->nTool
= TOOLTIPS_GetToolFromPoint(infoPtr
, lpMsg
->hwnd
,
1520 TRACE("tool (%p) %d %d %d\n", infoPtr
->hwndSelf
, nOldTool
,
1521 infoPtr
->nTool
, infoPtr
->nCurrentTool
);
1522 TRACE("WM_MOUSEMOVE (%p %d %d)\n", infoPtr
->hwndSelf
, pt
.x
, pt
.y
);
1524 if (infoPtr
->nTool
!= nOldTool
) {
1525 if(infoPtr
->nTool
== -1) { /* Moved out of all tools */
1526 TOOLTIPS_Hide(infoPtr
);
1527 KillTimer(infoPtr
->hwndSelf
, ID_TIMERLEAVE
);
1528 } else if (nOldTool
== -1) { /* Moved from outside */
1529 if(infoPtr
->bActive
) {
1530 SetTimer(infoPtr
->hwndSelf
, ID_TIMERSHOW
, infoPtr
->nInitialTime
, 0);
1531 TRACE("timer 1 started!\n");
1533 } else { /* Moved from one to another */
1534 TOOLTIPS_Hide (infoPtr
);
1535 KillTimer(infoPtr
->hwndSelf
, ID_TIMERLEAVE
);
1536 if(infoPtr
->bActive
) {
1537 SetTimer (infoPtr
->hwndSelf
, ID_TIMERSHOW
, infoPtr
->nReshowTime
, 0);
1538 TRACE("timer 1 started!\n");
1541 } else if(infoPtr
->nCurrentTool
!= -1) { /* restart autopop */
1542 KillTimer(infoPtr
->hwndSelf
, ID_TIMERPOP
);
1543 SetTimer(infoPtr
->hwndSelf
, ID_TIMERPOP
, infoPtr
->nAutoPopTime
, 0);
1544 TRACE("timer 2 restarted\n");
1545 } else if(infoPtr
->nTool
!= -1 && infoPtr
->bActive
) {
1546 /* previous show attempt didn't result in tooltip so try again */
1547 SetTimer(infoPtr
->hwndSelf
, ID_TIMERSHOW
, infoPtr
->nInitialTime
, 0);
1548 TRACE("timer 1 started!\n");
1558 TOOLTIPS_SetDelayTime (TOOLTIPS_INFO
*infoPtr
, DWORD duration
, INT nTime
)
1561 case TTDT_AUTOMATIC
:
1563 nTime
= GetDoubleClickTime();
1564 infoPtr
->nReshowTime
= nTime
/ 5;
1565 infoPtr
->nAutoPopTime
= nTime
* 10;
1566 infoPtr
->nInitialTime
= nTime
;
1571 nTime
= GetDoubleClickTime() / 5;
1572 infoPtr
->nReshowTime
= nTime
;
1577 nTime
= GetDoubleClickTime() * 10;
1578 infoPtr
->nAutoPopTime
= nTime
;
1583 nTime
= GetDoubleClickTime();
1584 infoPtr
->nInitialTime
= nTime
;
1588 WARN("Invalid duration flag %x\n", duration
);
1597 TOOLTIPS_SetMargin (TOOLTIPS_INFO
*infoPtr
, const RECT
*lpRect
)
1599 infoPtr
->rcMargin
.left
= lpRect
->left
;
1600 infoPtr
->rcMargin
.right
= lpRect
->right
;
1601 infoPtr
->rcMargin
.bottom
= lpRect
->bottom
;
1602 infoPtr
->rcMargin
.top
= lpRect
->top
;
1608 static inline LRESULT
1609 TOOLTIPS_SetMaxTipWidth (TOOLTIPS_INFO
*infoPtr
, INT MaxWidth
)
1611 INT nTemp
= infoPtr
->nMaxTipWidth
;
1613 infoPtr
->nMaxTipWidth
= MaxWidth
;
1619 static inline LRESULT
1620 TOOLTIPS_SetTipBkColor (TOOLTIPS_INFO
*infoPtr
, COLORREF clrBk
)
1622 infoPtr
->clrBk
= clrBk
;
1628 static inline LRESULT
1629 TOOLTIPS_SetTipTextColor (TOOLTIPS_INFO
*infoPtr
, COLORREF clrText
)
1631 infoPtr
->clrText
= clrText
;
1638 TOOLTIPS_SetTitleT (TOOLTIPS_INFO
*infoPtr
, UINT_PTR uTitleIcon
, LPCWSTR pszTitle
,
1643 TRACE("hwnd = %p, title = %s, icon = %p\n", infoPtr
->hwndSelf
, debugstr_w(pszTitle
),
1646 Free(infoPtr
->pszTitle
);
1652 size
= (strlenW(pszTitle
)+1)*sizeof(WCHAR
);
1653 infoPtr
->pszTitle
= Alloc(size
);
1654 if (!infoPtr
->pszTitle
)
1656 memcpy(infoPtr
->pszTitle
, pszTitle
, size
);
1660 size
= sizeof(WCHAR
)*MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)pszTitle
, -1, NULL
, 0);
1661 infoPtr
->pszTitle
= Alloc(size
);
1662 if (!infoPtr
->pszTitle
)
1664 MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)pszTitle
, -1, infoPtr
->pszTitle
, size
/sizeof(WCHAR
));
1668 infoPtr
->pszTitle
= NULL
;
1670 if (uTitleIcon
<= TTI_ERROR
)
1671 infoPtr
->hTitleIcon
= hTooltipIcons
[uTitleIcon
];
1673 infoPtr
->hTitleIcon
= CopyIcon((HICON
)uTitleIcon
);
1675 TRACE("icon = %p\n", infoPtr
->hTitleIcon
);
1682 TOOLTIPS_SetToolInfoT (TOOLTIPS_INFO
*infoPtr
, const TTTOOLINFOW
*ti
, BOOL isW
)
1684 TTTOOL_INFO
*toolPtr
;
1688 if (ti
->cbSize
< TTTOOLINFOW_V1_SIZE
)
1691 nTool
= TOOLTIPS_GetToolFromInfoT (infoPtr
, ti
);
1692 if (nTool
== -1) return 0;
1694 TRACE("tool %d\n", nTool
);
1696 toolPtr
= &infoPtr
->tools
[nTool
];
1698 /* copy tool data */
1699 toolPtr
->uFlags
= ti
->uFlags
;
1700 toolPtr
->hwnd
= ti
->hwnd
;
1701 toolPtr
->uId
= ti
->uId
;
1702 toolPtr
->rect
= ti
->rect
;
1703 toolPtr
->hinst
= ti
->hinst
;
1705 if (IS_INTRESOURCE(ti
->lpszText
)) {
1706 TRACE("set string id %x!\n", LOWORD(ti
->lpszText
));
1707 toolPtr
->lpszText
= ti
->lpszText
;
1710 if (TOOLTIPS_IsCallbackString(ti
->lpszText
, isW
))
1711 toolPtr
->lpszText
= LPSTR_TEXTCALLBACKW
;
1713 if ( (toolPtr
->lpszText
) &&
1714 !IS_INTRESOURCE(toolPtr
->lpszText
) ) {
1715 if( toolPtr
->lpszText
!= LPSTR_TEXTCALLBACKW
)
1716 Free (toolPtr
->lpszText
);
1717 toolPtr
->lpszText
= NULL
;
1721 INT len
= lstrlenW (ti
->lpszText
);
1722 toolPtr
->lpszText
= Alloc ((len
+1)*sizeof(WCHAR
));
1723 strcpyW (toolPtr
->lpszText
, ti
->lpszText
);
1726 INT len
= MultiByteToWideChar(CP_ACP
, 0, (LPSTR
)ti
->lpszText
,
1728 toolPtr
->lpszText
= Alloc (len
* sizeof(WCHAR
));
1729 MultiByteToWideChar(CP_ACP
, 0, (LPSTR
)ti
->lpszText
, -1,
1730 toolPtr
->lpszText
, len
);
1736 if (ti
->cbSize
>= TTTOOLINFOW_V2_SIZE
)
1737 toolPtr
->lParam
= ti
->lParam
;
1739 if (infoPtr
->nCurrentTool
== nTool
)
1741 TOOLTIPS_GetTipText (infoPtr
, infoPtr
->nCurrentTool
, infoPtr
->szTipText
);
1743 if (infoPtr
->szTipText
[0] == 0)
1744 TOOLTIPS_Hide(infoPtr
);
1746 TOOLTIPS_Show (infoPtr
, FALSE
);
1754 TOOLTIPS_TrackActivate (TOOLTIPS_INFO
*infoPtr
, BOOL track_activate
, const TTTOOLINFOA
*ti
)
1756 if (track_activate
) {
1759 if (ti
->cbSize
< TTTOOLINFOA_V1_SIZE
)
1763 infoPtr
->nTrackTool
= TOOLTIPS_GetToolFromInfoT (infoPtr
, (const TTTOOLINFOW
*)ti
);
1764 if (infoPtr
->nTrackTool
!= -1) {
1765 TRACE("activated!\n");
1766 infoPtr
->bTrackActive
= TRUE
;
1767 TOOLTIPS_TrackShow (infoPtr
);
1772 TOOLTIPS_TrackHide (infoPtr
);
1774 infoPtr
->bTrackActive
= FALSE
;
1775 infoPtr
->nTrackTool
= -1;
1777 TRACE("deactivated!\n");
1785 TOOLTIPS_TrackPosition (TOOLTIPS_INFO
*infoPtr
, LPARAM coord
)
1787 infoPtr
->xTrackPos
= (INT
)LOWORD(coord
);
1788 infoPtr
->yTrackPos
= (INT
)HIWORD(coord
);
1790 if (infoPtr
->bTrackActive
) {
1792 infoPtr
->xTrackPos
, infoPtr
->yTrackPos
);
1794 TOOLTIPS_TrackShow (infoPtr
);
1802 TOOLTIPS_Update (TOOLTIPS_INFO
*infoPtr
)
1804 if (infoPtr
->nCurrentTool
!= -1)
1805 UpdateWindow (infoPtr
->hwndSelf
);
1812 TOOLTIPS_UpdateTipTextT (TOOLTIPS_INFO
*infoPtr
, const TTTOOLINFOW
*ti
, BOOL isW
)
1814 TTTOOL_INFO
*toolPtr
;
1818 if (ti
->cbSize
< TTTOOLINFOW_V1_SIZE
)
1821 nTool
= TOOLTIPS_GetToolFromInfoT (infoPtr
, ti
);
1825 TRACE("tool %d\n", nTool
);
1827 toolPtr
= &infoPtr
->tools
[nTool
];
1829 /* copy tool text */
1830 toolPtr
->hinst
= ti
->hinst
;
1832 if (IS_INTRESOURCE(ti
->lpszText
)){
1833 toolPtr
->lpszText
= ti
->lpszText
;
1835 else if (ti
->lpszText
) {
1836 if (TOOLTIPS_IsCallbackString(ti
->lpszText
, isW
))
1837 toolPtr
->lpszText
= LPSTR_TEXTCALLBACKW
;
1839 if ( (toolPtr
->lpszText
) &&
1840 !IS_INTRESOURCE(toolPtr
->lpszText
) ) {
1841 if( toolPtr
->lpszText
!= LPSTR_TEXTCALLBACKW
)
1842 Free (toolPtr
->lpszText
);
1843 toolPtr
->lpszText
= NULL
;
1847 INT len
= lstrlenW (ti
->lpszText
);
1848 toolPtr
->lpszText
= Alloc ((len
+1)*sizeof(WCHAR
));
1849 strcpyW (toolPtr
->lpszText
, ti
->lpszText
);
1852 INT len
= MultiByteToWideChar(CP_ACP
, 0, (LPSTR
)ti
->lpszText
,
1854 toolPtr
->lpszText
= Alloc (len
* sizeof(WCHAR
));
1855 MultiByteToWideChar(CP_ACP
, 0, (LPSTR
)ti
->lpszText
, -1,
1856 toolPtr
->lpszText
, len
);
1862 if(infoPtr
->nCurrentTool
== -1) return 0;
1864 if (infoPtr
->bActive
)
1865 TOOLTIPS_Show (infoPtr
, FALSE
);
1866 else if (infoPtr
->bTrackActive
)
1867 TOOLTIPS_Show (infoPtr
, TRUE
);
1874 TOOLTIPS_Create (HWND hwnd
)
1876 TOOLTIPS_INFO
*infoPtr
;
1878 /* allocate memory for info structure */
1879 infoPtr
= Alloc (sizeof(TOOLTIPS_INFO
));
1880 SetWindowLongPtrW (hwnd
, 0, (DWORD_PTR
)infoPtr
);
1882 /* initialize info structure */
1883 infoPtr
->bActive
= TRUE
;
1884 infoPtr
->bTrackActive
= FALSE
;
1886 infoPtr
->nMaxTipWidth
= -1;
1887 infoPtr
->nTool
= -1;
1888 infoPtr
->nCurrentTool
= -1;
1889 infoPtr
->nTrackTool
= -1;
1890 infoPtr
->hwndSelf
= hwnd
;
1892 /* initialize colours and fonts */
1893 TOOLTIPS_InitSystemSettings(infoPtr
);
1895 TOOLTIPS_SetDelayTime(infoPtr
, TTDT_AUTOMATIC
, 0);
1897 SetWindowPos (hwnd
, HWND_TOP
, 0, 0, 0, 0, SWP_NOZORDER
| SWP_HIDEWINDOW
| SWP_NOACTIVATE
);
1904 TOOLTIPS_Destroy (TOOLTIPS_INFO
*infoPtr
)
1906 TTTOOL_INFO
*toolPtr
;
1910 if (infoPtr
->tools
) {
1911 for (i
= 0; i
< infoPtr
->uNumTools
; i
++) {
1912 toolPtr
= &infoPtr
->tools
[i
];
1913 if (toolPtr
->lpszText
) {
1914 if ( (toolPtr
->lpszText
!= LPSTR_TEXTCALLBACKW
) &&
1915 !IS_INTRESOURCE(toolPtr
->lpszText
) )
1917 Free (toolPtr
->lpszText
);
1918 toolPtr
->lpszText
= NULL
;
1922 /* remove subclassing */
1923 if (toolPtr
->uInternalFlags
& TTF_SUBCLASS
) {
1924 if (toolPtr
->uInternalFlags
& TTF_IDISHWND
) {
1925 RemoveWindowSubclass((HWND
)toolPtr
->uId
, TOOLTIPS_SubclassProc
, 1);
1928 RemoveWindowSubclass(toolPtr
->hwnd
, TOOLTIPS_SubclassProc
, 1);
1932 Free (infoPtr
->tools
);
1935 /* free title string */
1936 Free (infoPtr
->pszTitle
);
1937 /* free title icon if not a standard one */
1938 if (TOOLTIPS_GetTitleIconIndex(infoPtr
->hTitleIcon
) > TTI_ERROR
)
1939 DeleteObject(infoPtr
->hTitleIcon
);
1942 DeleteObject (infoPtr
->hFont
);
1943 DeleteObject (infoPtr
->hTitleFont
);
1945 /* free tool tips info data */
1946 SetWindowLongPtrW(infoPtr
->hwndSelf
, 0, 0);
1953 static inline LRESULT
1954 TOOLTIPS_GetFont (const TOOLTIPS_INFO
*infoPtr
)
1956 return (LRESULT
)infoPtr
->hFont
;
1961 TOOLTIPS_MouseMessage (TOOLTIPS_INFO
*infoPtr
)
1963 TOOLTIPS_Hide (infoPtr
);
1970 TOOLTIPS_NCCreate (HWND hwnd
)
1972 DWORD dwStyle
= GetWindowLongW (hwnd
, GWL_STYLE
);
1973 DWORD dwExStyle
= GetWindowLongW (hwnd
, GWL_EXSTYLE
);
1975 dwStyle
&= ~(WS_CHILD
| /*WS_MAXIMIZE |*/ WS_BORDER
| WS_DLGFRAME
);
1976 dwStyle
|= (WS_POPUP
| WS_BORDER
| WS_CLIPSIBLINGS
);
1978 /* WS_BORDER only draws a border round the window rect, not the
1979 * window region, therefore it is useless to us in balloon mode */
1980 if (dwStyle
& TTS_BALLOON
) dwStyle
&= ~WS_BORDER
;
1982 SetWindowLongW (hwnd
, GWL_STYLE
, dwStyle
);
1984 dwExStyle
|= WS_EX_TOOLWINDOW
;
1985 SetWindowLongW (hwnd
, GWL_EXSTYLE
, dwExStyle
);
1992 TOOLTIPS_NCHitTest (const TOOLTIPS_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
1994 INT nTool
= (infoPtr
->bTrackActive
) ? infoPtr
->nTrackTool
: infoPtr
->nTool
;
1996 TRACE(" nTool=%d\n", nTool
);
1998 if ((nTool
> -1) && (nTool
< infoPtr
->uNumTools
)) {
1999 if (infoPtr
->tools
[nTool
].uFlags
& TTF_TRANSPARENT
) {
2000 TRACE("-- in transparent mode!\n");
2001 return HTTRANSPARENT
;
2005 return DefWindowProcW (infoPtr
->hwndSelf
, WM_NCHITTEST
, wParam
, lParam
);
2010 TOOLTIPS_NotifyFormat (TOOLTIPS_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
2012 FIXME ("hwnd=%p wParam=%lx lParam=%lx\n", infoPtr
->hwndSelf
, wParam
, lParam
);
2019 TOOLTIPS_Paint (const TOOLTIPS_INFO
*infoPtr
, HDC hDC
)
2024 hdc
= (hDC
== NULL
) ? BeginPaint (infoPtr
->hwndSelf
, &ps
) : hDC
;
2025 TOOLTIPS_Refresh (infoPtr
, hdc
);
2027 EndPaint (infoPtr
->hwndSelf
, &ps
);
2033 TOOLTIPS_SetFont (TOOLTIPS_INFO
*infoPtr
, HFONT hFont
, BOOL redraw
)
2037 if(!GetObjectW(hFont
, sizeof(lf
), &lf
))
2040 DeleteObject (infoPtr
->hFont
);
2041 infoPtr
->hFont
= CreateFontIndirectW(&lf
);
2043 DeleteObject (infoPtr
->hTitleFont
);
2044 lf
.lfWeight
= FW_BOLD
;
2045 infoPtr
->hTitleFont
= CreateFontIndirectW(&lf
);
2047 if (redraw
&& infoPtr
->nCurrentTool
!= -1) {
2048 FIXME("full redraw needed!\n");
2054 /******************************************************************
2055 * TOOLTIPS_GetTextLength
2057 * This function is called when the tooltip receive a
2058 * WM_GETTEXTLENGTH message.
2060 * returns the length, in characters, of the tip text
2062 static inline LRESULT
2063 TOOLTIPS_GetTextLength(const TOOLTIPS_INFO
*infoPtr
)
2065 return strlenW(infoPtr
->szTipText
);
2068 /******************************************************************
2069 * TOOLTIPS_OnWMGetText
2071 * This function is called when the tooltip receive a
2072 * WM_GETTEXT message.
2073 * wParam : specifies the maximum number of characters to be copied
2074 * lParam : is the pointer to the buffer that will receive
2077 * returns the number of characters copied
2080 TOOLTIPS_OnWMGetText (const TOOLTIPS_INFO
*infoPtr
, WPARAM size
, LPWSTR pszText
)
2087 res
= min(strlenW(infoPtr
->szTipText
)+1, size
);
2088 memcpy(pszText
, infoPtr
->szTipText
, res
*sizeof(WCHAR
));
2089 pszText
[res
-1] = '\0';
2094 TOOLTIPS_Timer (TOOLTIPS_INFO
*infoPtr
, INT iTimer
)
2098 TRACE("timer %d (%p) expired!\n", iTimer
, infoPtr
->hwndSelf
);
2102 KillTimer (infoPtr
->hwndSelf
, ID_TIMERSHOW
);
2103 nOldTool
= infoPtr
->nTool
;
2104 if ((infoPtr
->nTool
= TOOLTIPS_CheckTool (infoPtr
, TRUE
)) == nOldTool
)
2105 TOOLTIPS_Show (infoPtr
, FALSE
);
2109 TOOLTIPS_Hide (infoPtr
);
2113 nOldTool
= infoPtr
->nTool
;
2114 infoPtr
->nTool
= TOOLTIPS_CheckTool (infoPtr
, FALSE
);
2115 TRACE("tool (%p) %d %d %d\n", infoPtr
->hwndSelf
, nOldTool
,
2116 infoPtr
->nTool
, infoPtr
->nCurrentTool
);
2117 if (infoPtr
->nTool
!= nOldTool
) {
2118 if(infoPtr
->nTool
== -1) { /* Moved out of all tools */
2119 TOOLTIPS_Hide(infoPtr
);
2120 KillTimer(infoPtr
->hwndSelf
, ID_TIMERLEAVE
);
2121 } else if (nOldTool
== -1) { /* Moved from outside */
2122 ERR("How did this happen?\n");
2123 } else { /* Moved from one to another */
2124 TOOLTIPS_Hide (infoPtr
);
2125 KillTimer(infoPtr
->hwndSelf
, ID_TIMERLEAVE
);
2126 if(infoPtr
->bActive
) {
2127 SetTimer (infoPtr
->hwndSelf
, ID_TIMERSHOW
, infoPtr
->nReshowTime
, 0);
2128 TRACE("timer 1 started!\n");
2135 ERR("Unknown timer id %d\n", iTimer
);
2143 TOOLTIPS_WinIniChange (TOOLTIPS_INFO
*infoPtr
)
2145 TOOLTIPS_InitSystemSettings (infoPtr
);
2151 static LRESULT CALLBACK
2152 TOOLTIPS_SubclassProc (HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
, UINT_PTR uID
, DWORD_PTR dwRef
)
2154 TOOLTIPS_INFO
*infoPtr
= TOOLTIPS_GetInfoPtr ((HWND
)dwRef
);
2159 case WM_LBUTTONDOWN
:
2161 case WM_MBUTTONDOWN
:
2163 case WM_RBUTTONDOWN
:
2167 msg
.wParam
= wParam
;
2168 msg
.lParam
= lParam
;
2169 TOOLTIPS_RelayEvent(infoPtr
, &msg
);
2175 return DefSubclassProc(hwnd
, uMsg
, wParam
, lParam
);
2179 static LRESULT CALLBACK
2180 TOOLTIPS_WindowProc (HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
2182 TOOLTIPS_INFO
*infoPtr
= TOOLTIPS_GetInfoPtr (hwnd
);
2184 TRACE("hwnd=%p msg=%x wparam=%lx lParam=%lx\n", hwnd
, uMsg
, wParam
, lParam
);
2185 if (!infoPtr
&& (uMsg
!= WM_CREATE
) && (uMsg
!= WM_NCCREATE
))
2186 return DefWindowProcW (hwnd
, uMsg
, wParam
, lParam
);
2190 return TOOLTIPS_Activate (infoPtr
, (BOOL
)wParam
);
2194 return TOOLTIPS_AddToolT (infoPtr
, (LPTTTOOLINFOW
)lParam
, uMsg
== TTM_ADDTOOLW
);
2198 return TOOLTIPS_DelToolT (infoPtr
, (LPTOOLINFOW
)lParam
,
2199 uMsg
== TTM_DELTOOLW
);
2200 case TTM_ENUMTOOLSA
:
2201 case TTM_ENUMTOOLSW
:
2202 return TOOLTIPS_EnumToolsT (infoPtr
, (UINT
)wParam
, (LPTTTOOLINFOW
)lParam
,
2203 uMsg
== TTM_ENUMTOOLSW
);
2204 case TTM_GETBUBBLESIZE
:
2205 return TOOLTIPS_GetBubbleSize (infoPtr
, (LPTTTOOLINFOW
)lParam
);
2207 case TTM_GETCURRENTTOOLA
:
2208 case TTM_GETCURRENTTOOLW
:
2209 return TOOLTIPS_GetCurrentToolT (infoPtr
, (LPTTTOOLINFOW
)lParam
,
2210 uMsg
== TTM_GETCURRENTTOOLW
);
2212 case TTM_GETDELAYTIME
:
2213 return TOOLTIPS_GetDelayTime (infoPtr
, (DWORD
)wParam
);
2216 return TOOLTIPS_GetMargin (infoPtr
, (LPRECT
)lParam
);
2218 case TTM_GETMAXTIPWIDTH
:
2219 return TOOLTIPS_GetMaxTipWidth (infoPtr
);
2223 return TOOLTIPS_GetTextT (infoPtr
, (LPTTTOOLINFOW
)lParam
,
2224 uMsg
== TTM_GETTEXTW
);
2226 case TTM_GETTIPBKCOLOR
:
2227 return TOOLTIPS_GetTipBkColor (infoPtr
);
2229 case TTM_GETTIPTEXTCOLOR
:
2230 return TOOLTIPS_GetTipTextColor (infoPtr
);
2232 case TTM_GETTOOLCOUNT
:
2233 return TOOLTIPS_GetToolCount (infoPtr
);
2235 case TTM_GETTOOLINFOA
:
2236 case TTM_GETTOOLINFOW
:
2237 return TOOLTIPS_GetToolInfoT (infoPtr
, (LPTTTOOLINFOW
)lParam
,
2238 uMsg
== TTM_GETTOOLINFOW
);
2242 return TOOLTIPS_HitTestT (infoPtr
, (LPTTHITTESTINFOW
)lParam
,
2243 uMsg
== TTM_HITTESTW
);
2244 case TTM_NEWTOOLRECTA
:
2245 case TTM_NEWTOOLRECTW
:
2246 return TOOLTIPS_NewToolRectT (infoPtr
, (LPTTTOOLINFOW
)lParam
);
2249 return TOOLTIPS_Pop (infoPtr
);
2251 case TTM_RELAYEVENT
:
2252 return TOOLTIPS_RelayEvent (infoPtr
, (LPMSG
)lParam
);
2254 case TTM_SETDELAYTIME
:
2255 return TOOLTIPS_SetDelayTime (infoPtr
, (DWORD
)wParam
, (INT
)LOWORD(lParam
));
2258 return TOOLTIPS_SetMargin (infoPtr
, (LPRECT
)lParam
);
2260 case TTM_SETMAXTIPWIDTH
:
2261 return TOOLTIPS_SetMaxTipWidth (infoPtr
, (INT
)lParam
);
2263 case TTM_SETTIPBKCOLOR
:
2264 return TOOLTIPS_SetTipBkColor (infoPtr
, (COLORREF
)wParam
);
2266 case TTM_SETTIPTEXTCOLOR
:
2267 return TOOLTIPS_SetTipTextColor (infoPtr
, (COLORREF
)wParam
);
2271 return TOOLTIPS_SetTitleT (infoPtr
, (UINT_PTR
)wParam
, (LPCWSTR
)lParam
,
2272 uMsg
== TTM_SETTITLEW
);
2274 case TTM_SETTOOLINFOA
:
2275 case TTM_SETTOOLINFOW
:
2276 return TOOLTIPS_SetToolInfoT (infoPtr
, (LPTTTOOLINFOW
)lParam
,
2277 uMsg
== TTM_SETTOOLINFOW
);
2279 case TTM_TRACKACTIVATE
:
2280 return TOOLTIPS_TrackActivate (infoPtr
, (BOOL
)wParam
, (LPTTTOOLINFOA
)lParam
);
2282 case TTM_TRACKPOSITION
:
2283 return TOOLTIPS_TrackPosition (infoPtr
, lParam
);
2286 return TOOLTIPS_Update (infoPtr
);
2288 case TTM_UPDATETIPTEXTA
:
2289 case TTM_UPDATETIPTEXTW
:
2290 return TOOLTIPS_UpdateTipTextT (infoPtr
, (LPTTTOOLINFOW
)lParam
,
2291 uMsg
== TTM_UPDATETIPTEXTW
);
2293 case TTM_WINDOWFROMPOINT
:
2294 return (LRESULT
)WindowFromPoint (*((LPPOINT
)lParam
));
2297 return TOOLTIPS_Create (hwnd
);
2300 return TOOLTIPS_Destroy (infoPtr
);
2303 /* we draw the background in WM_PAINT */
2307 return TOOLTIPS_GetFont (infoPtr
);
2310 return TOOLTIPS_OnWMGetText (infoPtr
, wParam
, (LPWSTR
)lParam
);
2312 case WM_GETTEXTLENGTH
:
2313 return TOOLTIPS_GetTextLength (infoPtr
);
2315 case WM_LBUTTONDOWN
:
2317 case WM_MBUTTONDOWN
:
2319 case WM_RBUTTONDOWN
:
2322 return TOOLTIPS_MouseMessage (infoPtr
);
2325 return TOOLTIPS_NCCreate (hwnd
);
2328 return TOOLTIPS_NCHitTest (infoPtr
, wParam
, lParam
);
2330 case WM_NOTIFYFORMAT
:
2331 return TOOLTIPS_NotifyFormat (infoPtr
, wParam
, lParam
);
2333 case WM_PRINTCLIENT
:
2335 return TOOLTIPS_Paint (infoPtr
, (HDC
)wParam
);
2338 return TOOLTIPS_SetFont (infoPtr
, (HFONT
)wParam
, LOWORD(lParam
));
2340 case WM_SYSCOLORCHANGE
:
2341 COMCTL32_RefreshSysColors();
2345 return TOOLTIPS_Timer (infoPtr
, (INT
)wParam
);
2347 case WM_WININICHANGE
:
2348 return TOOLTIPS_WinIniChange (infoPtr
);
2351 if ((uMsg
>= WM_USER
) && (uMsg
< WM_APP
) && !COMCTL32_IsReflectedMessage(uMsg
))
2352 ERR("unknown msg %04x wp=%08lx lp=%08lx\n",
2353 uMsg
, wParam
, lParam
);
2354 return DefWindowProcW (hwnd
, uMsg
, wParam
, lParam
);
2360 TOOLTIPS_Register (void)
2364 ZeroMemory (&wndClass
, sizeof(WNDCLASSW
));
2365 wndClass
.style
= CS_GLOBALCLASS
| CS_DBLCLKS
| CS_SAVEBITS
;
2366 wndClass
.lpfnWndProc
= TOOLTIPS_WindowProc
;
2367 wndClass
.cbClsExtra
= 0;
2368 wndClass
.cbWndExtra
= sizeof(TOOLTIPS_INFO
*);
2369 wndClass
.hCursor
= LoadCursorW (0, (LPWSTR
)IDC_ARROW
);
2370 wndClass
.hbrBackground
= 0;
2371 wndClass
.lpszClassName
= TOOLTIPS_CLASSW
;
2373 RegisterClassW (&wndClass
);
2375 hTooltipIcons
[TTI_NONE
] = NULL
;
2376 hTooltipIcons
[TTI_INFO
] = LoadImageW(COMCTL32_hModule
,
2377 (LPCWSTR
)MAKEINTRESOURCE(IDI_TT_INFO_SM
), IMAGE_ICON
, 0, 0, 0);
2378 hTooltipIcons
[TTI_WARNING
] = LoadImageW(COMCTL32_hModule
,
2379 (LPCWSTR
)MAKEINTRESOURCE(IDI_TT_WARN_SM
), IMAGE_ICON
, 0, 0, 0);
2380 hTooltipIcons
[TTI_ERROR
] = LoadImageW(COMCTL32_hModule
,
2381 (LPCWSTR
)MAKEINTRESOURCE(IDI_TT_ERROR_SM
), IMAGE_ICON
, 0, 0, 0);
2386 TOOLTIPS_Unregister (void)
2389 for (i
= TTI_INFO
; i
<= TTI_ERROR
; i
++)
2390 DestroyIcon(hTooltipIcons
[i
]);
2391 UnregisterClassW (TOOLTIPS_CLASSW
, NULL
);