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
94 WINE_DEFAULT_DEBUG_CHANNEL(tooltips
);
96 static HICON hTooltipIcons
[TTI_ERROR
+1];
114 WCHAR szTipText
[INFOTIPSIZE
];
125 INT nTool
; /* tool that mouse was on on last relayed mouse move */
139 #define ID_TIMERSHOW 1 /* show delay timer */
140 #define ID_TIMERPOP 2 /* auto pop timer */
141 #define ID_TIMERLEAVE 3 /* tool leave timer */
144 #define TOOLTIPS_GetInfoPtr(hWindow) ((TOOLTIPS_INFO *)GetWindowLongPtrW (hWindow, 0))
146 /* offsets from window edge to start of text */
147 #define NORMAL_TEXT_MARGIN 2
148 #define BALLOON_TEXT_MARGIN (NORMAL_TEXT_MARGIN+8)
149 /* value used for CreateRoundRectRgn that specifies how much
150 * each corner is curved */
151 #define BALLOON_ROUNDEDNESS 20
152 #define BALLOON_STEMHEIGHT 13
153 #define BALLOON_STEMWIDTH 10
154 #define BALLOON_STEMINDENT 20
156 #define BALLOON_ICON_TITLE_SPACING 8 /* horizontal spacing between icon and title */
157 #define BALLOON_TITLE_TEXT_SPACING 8 /* vertical spacing between icon/title and main text */
158 #define ICON_HEIGHT 16
159 #define ICON_WIDTH 16
161 #define MAX_TEXT_SIZE_A 80 /* maximum retrieving text size by ANSI message */
163 static LRESULT CALLBACK
164 TOOLTIPS_SubclassProc (HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
, UINT_PTR uId
, DWORD_PTR dwRef
);
167 static inline BOOL
TOOLTIPS_IsCallbackString(LPCWSTR str
, BOOL isW
)
170 return str
== LPSTR_TEXTCALLBACKW
;
172 return (LPCSTR
)str
== LPSTR_TEXTCALLBACKA
;
175 static inline UINT_PTR
176 TOOLTIPS_GetTitleIconIndex(HICON hIcon
)
179 for (i
= 0; i
<= TTI_ERROR
; i
++)
180 if (hTooltipIcons
[i
] == hIcon
)
182 return (UINT_PTR
)hIcon
;
186 TOOLTIPS_InitSystemSettings (TOOLTIPS_INFO
*infoPtr
)
188 NONCLIENTMETRICSW nclm
;
190 infoPtr
->clrBk
= comctl32_color
.clrInfoBk
;
191 infoPtr
->clrText
= comctl32_color
.clrInfoText
;
193 DeleteObject (infoPtr
->hFont
);
194 nclm
.cbSize
= sizeof(nclm
);
195 SystemParametersInfoW (SPI_GETNONCLIENTMETRICS
, sizeof(nclm
), &nclm
, 0);
196 infoPtr
->hFont
= CreateFontIndirectW (&nclm
.lfStatusFont
);
198 DeleteObject (infoPtr
->hTitleFont
);
199 nclm
.lfStatusFont
.lfWeight
= FW_BOLD
;
200 infoPtr
->hTitleFont
= CreateFontIndirectW (&nclm
.lfStatusFont
);
203 /* Custom draw routines */
205 TOOLTIPS_customdraw_fill(const TOOLTIPS_INFO
*infoPtr
, NMTTCUSTOMDRAW
*lpnmttcd
,
206 HDC hdc
, const RECT
*rcBounds
, UINT uFlags
)
208 ZeroMemory(lpnmttcd
, sizeof(NMTTCUSTOMDRAW
));
209 lpnmttcd
->uDrawFlags
= uFlags
;
210 lpnmttcd
->nmcd
.hdr
.hwndFrom
= infoPtr
->hwndSelf
;
211 lpnmttcd
->nmcd
.hdr
.code
= NM_CUSTOMDRAW
;
212 if (infoPtr
->nCurrentTool
!= -1) {
213 TTTOOL_INFO
*toolPtr
= &infoPtr
->tools
[infoPtr
->nCurrentTool
];
214 lpnmttcd
->nmcd
.hdr
.idFrom
= toolPtr
->uId
;
216 lpnmttcd
->nmcd
.hdc
= hdc
;
217 lpnmttcd
->nmcd
.rc
= *rcBounds
;
218 /* FIXME - dwItemSpec, uItemState, lItemlParam */
222 TOOLTIPS_notify_customdraw (DWORD dwDrawStage
, NMTTCUSTOMDRAW
*lpnmttcd
)
224 LRESULT result
= CDRF_DODEFAULT
;
225 lpnmttcd
->nmcd
.dwDrawStage
= dwDrawStage
;
227 TRACE("Notifying stage %d, flags %x, id %x\n", lpnmttcd
->nmcd
.dwDrawStage
,
228 lpnmttcd
->uDrawFlags
, lpnmttcd
->nmcd
.hdr
.code
);
230 result
= SendMessageW(GetParent(lpnmttcd
->nmcd
.hdr
.hwndFrom
), WM_NOTIFY
,
231 0, (LPARAM
)lpnmttcd
);
233 TRACE("Notify result %x\n", (unsigned int)result
);
239 TOOLTIPS_Refresh (const TOOLTIPS_INFO
*infoPtr
, HDC hdc
)
245 UINT uFlags
= DT_EXTERNALLEADING
;
247 DWORD dwStyle
= GetWindowLongW(infoPtr
->hwndSelf
, GWL_STYLE
);
248 NMTTCUSTOMDRAW nmttcd
;
251 if (infoPtr
->nMaxTipWidth
> -1)
252 uFlags
|= DT_WORDBREAK
;
253 if (GetWindowLongW (infoPtr
->hwndSelf
, GWL_STYLE
) & TTS_NOPREFIX
)
254 uFlags
|= DT_NOPREFIX
;
255 GetClientRect (infoPtr
->hwndSelf
, &rc
);
257 hBrush
= CreateSolidBrush(infoPtr
->clrBk
);
259 oldBkMode
= SetBkMode (hdc
, TRANSPARENT
);
260 SetTextColor (hdc
, infoPtr
->clrText
);
261 hOldFont
= SelectObject (hdc
, infoPtr
->hFont
);
263 /* Custom draw - Call PrePaint once initial properties set up */
264 /* Note: Contrary to MSDN, CDRF_SKIPDEFAULT still draws a tooltip */
265 TOOLTIPS_customdraw_fill(infoPtr
, &nmttcd
, hdc
, &rc
, uFlags
);
266 cdmode
= TOOLTIPS_notify_customdraw(CDDS_PREPAINT
, &nmttcd
);
267 uFlags
= nmttcd
.uDrawFlags
;
269 if (dwStyle
& TTS_BALLOON
)
271 /* create a region to store result into */
272 hRgn
= CreateRectRgn(0, 0, 0, 0);
274 GetWindowRgn(infoPtr
->hwndSelf
, hRgn
);
276 /* fill the background */
277 FillRgn(hdc
, hRgn
, hBrush
);
278 DeleteObject(hBrush
);
283 /* fill the background */
284 FillRect(hdc
, &rc
, hBrush
);
285 DeleteObject(hBrush
);
289 if ((dwStyle
& TTS_BALLOON
) || infoPtr
->pszTitle
)
291 /* calculate text rectangle */
292 rc
.left
+= (BALLOON_TEXT_MARGIN
+ infoPtr
->rcMargin
.left
);
293 rc
.top
+= (BALLOON_TEXT_MARGIN
+ infoPtr
->rcMargin
.top
);
294 rc
.right
-= (BALLOON_TEXT_MARGIN
+ infoPtr
->rcMargin
.right
);
295 rc
.bottom
-= (BALLOON_TEXT_MARGIN
+ infoPtr
->rcMargin
.bottom
);
296 if(infoPtr
->bToolBelow
) rc
.top
+= BALLOON_STEMHEIGHT
;
298 if (infoPtr
->pszTitle
)
300 RECT rcTitle
= {rc
.left
, rc
.top
, rc
.right
, rc
.bottom
};
306 icon_present
= infoPtr
->hTitleIcon
&&
307 DrawIconEx(hdc
, rc
.left
, rc
.top
, infoPtr
->hTitleIcon
,
308 ICON_WIDTH
, ICON_HEIGHT
, 0, NULL
, DI_NORMAL
);
310 rcTitle
.left
+= ICON_WIDTH
+ BALLOON_ICON_TITLE_SPACING
;
312 rcTitle
.bottom
= rc
.top
+ ICON_HEIGHT
;
314 /* draw title text */
315 prevFont
= SelectObject (hdc
, infoPtr
->hTitleFont
);
316 height
= DrawTextW(hdc
, infoPtr
->pszTitle
, -1, &rcTitle
, DT_BOTTOM
| DT_SINGLELINE
| DT_NOPREFIX
);
317 SelectObject (hdc
, prevFont
);
318 rc
.top
+= height
+ BALLOON_TITLE_TEXT_SPACING
;
323 /* calculate text rectangle */
324 rc
.left
+= (NORMAL_TEXT_MARGIN
+ infoPtr
->rcMargin
.left
);
325 rc
.top
+= (NORMAL_TEXT_MARGIN
+ infoPtr
->rcMargin
.top
);
326 rc
.right
-= (NORMAL_TEXT_MARGIN
+ infoPtr
->rcMargin
.right
);
327 rc
.bottom
-= (NORMAL_TEXT_MARGIN
+ infoPtr
->rcMargin
.bottom
);
331 DrawTextW (hdc
, infoPtr
->szTipText
, -1, &rc
, uFlags
);
333 /* Custom draw - Call PostPaint after drawing */
334 if (cdmode
& CDRF_NOTIFYPOSTPAINT
) {
335 TOOLTIPS_notify_customdraw(CDDS_POSTPAINT
, &nmttcd
);
338 /* be polite and reset the things we changed in the dc */
339 SelectObject (hdc
, hOldFont
);
340 SetBkMode (hdc
, oldBkMode
);
342 if (dwStyle
& TTS_BALLOON
)
344 /* frame region because default window proc doesn't do it */
345 INT width
= GetSystemMetrics(SM_CXDLGFRAME
) - GetSystemMetrics(SM_CXEDGE
);
346 INT height
= GetSystemMetrics(SM_CYDLGFRAME
) - GetSystemMetrics(SM_CYEDGE
);
348 hBrush
= GetSysColorBrush(COLOR_WINDOWFRAME
);
349 FrameRgn(hdc
, hRgn
, hBrush
, width
, height
);
356 static void TOOLTIPS_GetDispInfoA(const TOOLTIPS_INFO
*infoPtr
, TTTOOL_INFO
*toolPtr
, WCHAR
*buffer
)
358 NMTTDISPINFOA ttnmdi
;
360 /* fill NMHDR struct */
361 ZeroMemory (&ttnmdi
, sizeof(NMTTDISPINFOA
));
362 ttnmdi
.hdr
.hwndFrom
= infoPtr
->hwndSelf
;
363 ttnmdi
.hdr
.idFrom
= toolPtr
->uId
;
364 ttnmdi
.hdr
.code
= TTN_GETDISPINFOA
; /* == TTN_NEEDTEXTA */
365 ttnmdi
.lpszText
= ttnmdi
.szText
;
366 ttnmdi
.uFlags
= toolPtr
->uFlags
;
367 ttnmdi
.lParam
= toolPtr
->lParam
;
369 TRACE("hdr.idFrom = %lx\n", ttnmdi
.hdr
.idFrom
);
370 SendMessageW(toolPtr
->hwnd
, WM_NOTIFY
, toolPtr
->uId
, (LPARAM
)&ttnmdi
);
372 if (IS_INTRESOURCE(ttnmdi
.lpszText
)) {
373 LoadStringW(ttnmdi
.hinst
, LOWORD(ttnmdi
.lpszText
),
374 buffer
, INFOTIPSIZE
);
375 if (ttnmdi
.uFlags
& TTF_DI_SETITEM
) {
376 toolPtr
->hinst
= ttnmdi
.hinst
;
377 toolPtr
->lpszText
= (LPWSTR
)ttnmdi
.lpszText
;
380 else if (ttnmdi
.lpszText
== 0) {
383 else if (ttnmdi
.lpszText
!= LPSTR_TEXTCALLBACKA
) {
384 Str_GetPtrAtoW(ttnmdi
.lpszText
, buffer
, INFOTIPSIZE
);
385 if (ttnmdi
.uFlags
& TTF_DI_SETITEM
) {
387 toolPtr
->lpszText
= NULL
;
388 Str_SetPtrW(&toolPtr
->lpszText
, buffer
);
392 ERR("recursive text callback!\n");
396 /* no text available - try calling parent instead as per native */
397 /* FIXME: Unsure if SETITEM should save the value or not */
398 if (buffer
[0] == 0x00) {
400 SendMessageW(GetParent(toolPtr
->hwnd
), WM_NOTIFY
, toolPtr
->uId
, (LPARAM
)&ttnmdi
);
402 if (IS_INTRESOURCE(ttnmdi
.lpszText
)) {
403 LoadStringW(ttnmdi
.hinst
, LOWORD(ttnmdi
.lpszText
),
404 buffer
, INFOTIPSIZE
);
405 } else if (ttnmdi
.lpszText
&&
406 ttnmdi
.lpszText
!= LPSTR_TEXTCALLBACKA
) {
407 Str_GetPtrAtoW(ttnmdi
.lpszText
, buffer
, INFOTIPSIZE
);
412 static void TOOLTIPS_GetDispInfoW(const TOOLTIPS_INFO
*infoPtr
, TTTOOL_INFO
*toolPtr
, WCHAR
*buffer
)
414 NMTTDISPINFOW ttnmdi
;
416 /* fill NMHDR struct */
417 ZeroMemory (&ttnmdi
, sizeof(NMTTDISPINFOW
));
418 ttnmdi
.hdr
.hwndFrom
= infoPtr
->hwndSelf
;
419 ttnmdi
.hdr
.idFrom
= toolPtr
->uId
;
420 ttnmdi
.hdr
.code
= TTN_GETDISPINFOW
; /* == TTN_NEEDTEXTW */
421 ttnmdi
.lpszText
= ttnmdi
.szText
;
422 ttnmdi
.uFlags
= toolPtr
->uFlags
;
423 ttnmdi
.lParam
= toolPtr
->lParam
;
425 TRACE("hdr.idFrom = %lx\n", ttnmdi
.hdr
.idFrom
);
426 SendMessageW(toolPtr
->hwnd
, WM_NOTIFY
, toolPtr
->uId
, (LPARAM
)&ttnmdi
);
428 if (IS_INTRESOURCE(ttnmdi
.lpszText
)) {
429 LoadStringW(ttnmdi
.hinst
, LOWORD(ttnmdi
.lpszText
),
430 buffer
, INFOTIPSIZE
);
431 if (ttnmdi
.uFlags
& TTF_DI_SETITEM
) {
432 toolPtr
->hinst
= ttnmdi
.hinst
;
433 toolPtr
->lpszText
= ttnmdi
.lpszText
;
436 else if (ttnmdi
.lpszText
== 0) {
439 else if (ttnmdi
.lpszText
!= LPSTR_TEXTCALLBACKW
) {
440 Str_GetPtrW(ttnmdi
.lpszText
, buffer
, INFOTIPSIZE
);
441 if (ttnmdi
.uFlags
& TTF_DI_SETITEM
) {
443 toolPtr
->lpszText
= NULL
;
444 Str_SetPtrW(&toolPtr
->lpszText
, buffer
);
448 ERR("recursive text callback!\n");
452 /* no text available - try calling parent instead as per native */
453 /* FIXME: Unsure if SETITEM should save the value or not */
454 if (buffer
[0] == 0x00) {
456 SendMessageW(GetParent(toolPtr
->hwnd
), WM_NOTIFY
, toolPtr
->uId
, (LPARAM
)&ttnmdi
);
458 if (IS_INTRESOURCE(ttnmdi
.lpszText
)) {
459 LoadStringW(ttnmdi
.hinst
, LOWORD(ttnmdi
.lpszText
),
460 buffer
, INFOTIPSIZE
);
461 } else if (ttnmdi
.lpszText
&&
462 ttnmdi
.lpszText
!= LPSTR_TEXTCALLBACKW
) {
463 Str_GetPtrW(ttnmdi
.lpszText
, buffer
, INFOTIPSIZE
);
470 TOOLTIPS_GetTipText (const TOOLTIPS_INFO
*infoPtr
, INT nTool
, WCHAR
*buffer
)
472 TTTOOL_INFO
*toolPtr
= &infoPtr
->tools
[nTool
];
474 if (IS_INTRESOURCE(toolPtr
->lpszText
) && toolPtr
->hinst
) {
475 /* load a resource */
476 TRACE("load res string %p %x\n",
477 toolPtr
->hinst
, LOWORD(toolPtr
->lpszText
));
478 LoadStringW (toolPtr
->hinst
, LOWORD(toolPtr
->lpszText
),
479 buffer
, INFOTIPSIZE
);
481 else if (toolPtr
->lpszText
) {
482 if (toolPtr
->lpszText
== LPSTR_TEXTCALLBACKW
) {
483 if (toolPtr
->bNotifyUnicode
)
484 TOOLTIPS_GetDispInfoW(infoPtr
, toolPtr
, buffer
);
486 TOOLTIPS_GetDispInfoA(infoPtr
, toolPtr
, buffer
);
489 /* the item is a usual (unicode) text */
490 lstrcpynW (buffer
, toolPtr
->lpszText
, INFOTIPSIZE
);
494 /* no text available */
498 TRACE("%s\n", debugstr_w(buffer
));
503 TOOLTIPS_CalcTipSize (const TOOLTIPS_INFO
*infoPtr
, LPSIZE lpSize
)
507 DWORD style
= GetWindowLongW(infoPtr
->hwndSelf
, GWL_STYLE
);
508 UINT uFlags
= DT_EXTERNALLEADING
| DT_CALCRECT
;
509 RECT rc
= {0, 0, 0, 0};
512 if (infoPtr
->nMaxTipWidth
> -1) {
513 rc
.right
= infoPtr
->nMaxTipWidth
;
514 uFlags
|= DT_WORDBREAK
;
516 if (style
& TTS_NOPREFIX
)
517 uFlags
|= DT_NOPREFIX
;
518 TRACE("%s\n", debugstr_w(infoPtr
->szTipText
));
520 hdc
= GetDC (infoPtr
->hwndSelf
);
521 if (infoPtr
->pszTitle
)
523 RECT rcTitle
= {0, 0, 0, 0};
524 TRACE("title %s\n", debugstr_w(infoPtr
->pszTitle
));
525 if (infoPtr
->hTitleIcon
)
527 title
.cx
= ICON_WIDTH
;
528 title
.cy
= ICON_HEIGHT
;
530 if (title
.cx
!= 0) title
.cx
+= BALLOON_ICON_TITLE_SPACING
;
531 hOldFont
= SelectObject (hdc
, infoPtr
->hTitleFont
);
532 DrawTextW(hdc
, infoPtr
->pszTitle
, -1, &rcTitle
, DT_SINGLELINE
| DT_NOPREFIX
| DT_CALCRECT
);
533 SelectObject (hdc
, hOldFont
);
534 title
.cy
= max(title
.cy
, rcTitle
.bottom
- rcTitle
.top
) + BALLOON_TITLE_TEXT_SPACING
;
535 title
.cx
+= (rcTitle
.right
- rcTitle
.left
);
537 hOldFont
= SelectObject (hdc
, infoPtr
->hFont
);
538 DrawTextW (hdc
, infoPtr
->szTipText
, -1, &rc
, uFlags
);
539 SelectObject (hdc
, hOldFont
);
540 ReleaseDC (infoPtr
->hwndSelf
, hdc
);
542 if ((style
& TTS_BALLOON
) || infoPtr
->pszTitle
)
544 lpSize
->cx
= max(rc
.right
- rc
.left
, title
.cx
) + 2*BALLOON_TEXT_MARGIN
+
545 infoPtr
->rcMargin
.left
+ infoPtr
->rcMargin
.right
;
546 lpSize
->cy
= title
.cy
+ rc
.bottom
- rc
.top
+ 2*BALLOON_TEXT_MARGIN
+
547 infoPtr
->rcMargin
.bottom
+ infoPtr
->rcMargin
.top
+
552 lpSize
->cx
= rc
.right
- rc
.left
+ 2*NORMAL_TEXT_MARGIN
+
553 infoPtr
->rcMargin
.left
+ infoPtr
->rcMargin
.right
;
554 lpSize
->cy
= rc
.bottom
- rc
.top
+ 2*NORMAL_TEXT_MARGIN
+
555 infoPtr
->rcMargin
.bottom
+ infoPtr
->rcMargin
.top
;
561 TOOLTIPS_Show (TOOLTIPS_INFO
*infoPtr
, BOOL track_activate
)
563 TTTOOL_INFO
*toolPtr
;
565 MONITORINFO mon_info
;
570 DWORD style
= GetWindowLongW(infoPtr
->hwndSelf
, GWL_STYLE
);
575 if (infoPtr
->nTrackTool
== -1)
577 TRACE("invalid tracking tool (-1)!\n");
580 nTool
= infoPtr
->nTrackTool
;
584 if (infoPtr
->nTool
== -1)
586 TRACE("invalid tool (-1)!\n");
589 nTool
= infoPtr
->nTool
;
592 TRACE("Show tooltip pre %d! (%p)\n", nTool
, infoPtr
->hwndSelf
);
594 TOOLTIPS_GetTipText (infoPtr
, nTool
, infoPtr
->szTipText
);
596 if (infoPtr
->szTipText
[0] == '\0')
599 toolPtr
= &infoPtr
->tools
[nTool
];
602 infoPtr
->nCurrentTool
= infoPtr
->nTool
;
604 TRACE("Show tooltip %d!\n", nTool
);
606 hdr
.hwndFrom
= infoPtr
->hwndSelf
;
607 hdr
.idFrom
= toolPtr
->uId
;
609 SendMessageW (toolPtr
->hwnd
, WM_NOTIFY
, toolPtr
->uId
, (LPARAM
)&hdr
);
611 TRACE("%s\n", debugstr_w(infoPtr
->szTipText
));
613 TOOLTIPS_CalcTipSize (infoPtr
, &size
);
614 TRACE("size %d x %d\n", size
.cx
, size
.cy
);
618 rect
.left
= infoPtr
->xTrackPos
;
619 rect
.top
= infoPtr
->yTrackPos
;
622 if (toolPtr
->uFlags
& TTF_CENTERTIP
)
624 rect
.left
-= (size
.cx
/ 2);
625 if (!(style
& TTS_BALLOON
))
626 rect
.top
-= (size
.cy
/ 2);
628 if (!(infoPtr
->bToolBelow
= (infoPtr
->yTrackPos
+ size
.cy
<= GetSystemMetrics(SM_CYSCREEN
))))
631 if (!(toolPtr
->uFlags
& TTF_ABSOLUTE
))
633 if (style
& TTS_BALLOON
)
634 rect
.left
-= BALLOON_STEMINDENT
;
639 if (toolPtr
->uFlags
& TTF_IDISHWND
)
640 GetWindowRect ((HWND
)toolPtr
->uId
, &rcTool
);
643 rcTool
= toolPtr
->rect
;
644 MapWindowPoints (toolPtr
->hwnd
, NULL
, (LPPOINT
)&rcTool
, 2);
647 /* smart placement */
648 if ((rect
.left
+ size
.cx
> rcTool
.left
) && (rect
.left
< rcTool
.right
) &&
649 (rect
.top
+ size
.cy
> rcTool
.top
) && (rect
.top
< rcTool
.bottom
))
650 rect
.left
= rcTool
.right
;
656 if (toolPtr
->uFlags
& TTF_CENTERTIP
)
660 if (toolPtr
->uFlags
& TTF_IDISHWND
)
661 GetWindowRect ((HWND
)toolPtr
->uId
, &rc
);
664 MapWindowPoints (toolPtr
->hwnd
, NULL
, (LPPOINT
)&rc
, 2);
666 rect
.left
= (rc
.left
+ rc
.right
- size
.cx
) / 2;
667 if (style
& TTS_BALLOON
)
669 ptfx
= rc
.left
+ ((rc
.right
- rc
.left
) / 2);
671 /* CENTERTIP ballon tooltips default to below the field
672 * if they fit on the screen */
673 if (rc
.bottom
+ size
.cy
> GetSystemMetrics(SM_CYSCREEN
))
675 rect
.top
= rc
.top
- size
.cy
;
676 infoPtr
->bToolBelow
= FALSE
;
680 infoPtr
->bToolBelow
= TRUE
;
681 rect
.top
= rc
.bottom
;
683 rect
.left
= max(0, rect
.left
- BALLOON_STEMINDENT
);
687 rect
.top
= rc
.bottom
+ 2;
688 infoPtr
->bToolBelow
= TRUE
;
693 GetCursorPos ((LPPOINT
)&rect
);
694 if (style
& TTS_BALLOON
)
697 if(rect
.top
- size
.cy
>= 0)
700 infoPtr
->bToolBelow
= FALSE
;
704 infoPtr
->bToolBelow
= TRUE
;
707 rect
.left
= max(0, rect
.left
- BALLOON_STEMINDENT
);
712 infoPtr
->bToolBelow
= TRUE
;
717 TRACE("pos %d - %d\n", rect
.left
, rect
.top
);
719 rect
.right
= rect
.left
+ size
.cx
;
720 rect
.bottom
= rect
.top
+ size
.cy
;
724 monitor
= MonitorFromRect( &rect
, MONITOR_DEFAULTTOPRIMARY
);
725 mon_info
.cbSize
= sizeof(mon_info
);
726 GetMonitorInfoW( monitor
, &mon_info
);
728 if( rect
.right
> mon_info
.rcWork
.right
) {
729 rect
.left
-= rect
.right
- mon_info
.rcWork
.right
+ 2;
730 rect
.right
= mon_info
.rcWork
.right
- 2;
732 if (rect
.left
< mon_info
.rcWork
.left
) rect
.left
= mon_info
.rcWork
.left
;
734 if( rect
.bottom
> mon_info
.rcWork
.bottom
) {
737 if (toolPtr
->uFlags
& TTF_IDISHWND
)
738 GetWindowRect ((HWND
)toolPtr
->uId
, &rc
);
741 MapWindowPoints (toolPtr
->hwnd
, NULL
, (LPPOINT
)&rc
, 2);
743 rect
.bottom
= rc
.top
- 2;
744 rect
.top
= rect
.bottom
- size
.cy
;
747 AdjustWindowRectEx (&rect
, GetWindowLongW (infoPtr
->hwndSelf
, GWL_STYLE
),
748 FALSE
, GetWindowLongW (infoPtr
->hwndSelf
, GWL_EXSTYLE
));
750 if (style
& TTS_BALLOON
)
758 if(infoPtr
->bToolBelow
)
762 pts
[1].x
= max(BALLOON_STEMINDENT
, ptfx
- (BALLOON_STEMWIDTH
/ 2));
763 pts
[1].y
= BALLOON_STEMHEIGHT
;
764 pts
[2].x
= pts
[1].x
+ BALLOON_STEMWIDTH
;
766 if(pts
[2].x
> (rect
.right
- rect
.left
) - BALLOON_STEMINDENT
)
768 pts
[2].x
= (rect
.right
- rect
.left
) - BALLOON_STEMINDENT
;
769 pts
[1].x
= pts
[2].x
- BALLOON_STEMWIDTH
;
774 pts
[0].x
= max(BALLOON_STEMINDENT
, ptfx
- (BALLOON_STEMWIDTH
/ 2));
775 pts
[0].y
= (rect
.bottom
- rect
.top
) - BALLOON_STEMHEIGHT
;
776 pts
[1].x
= pts
[0].x
+ BALLOON_STEMWIDTH
;
779 pts
[2].y
= (rect
.bottom
- rect
.top
);
780 if(pts
[1].x
> (rect
.right
- rect
.left
) - BALLOON_STEMINDENT
)
782 pts
[1].x
= (rect
.right
- rect
.left
) - BALLOON_STEMINDENT
;
783 pts
[0].x
= pts
[1].x
- BALLOON_STEMWIDTH
;
787 hrStem
= CreatePolygonRgn(pts
, sizeof(pts
) / sizeof(pts
[0]), ALTERNATE
);
789 hRgn
= CreateRoundRectRgn(0,
790 (infoPtr
->bToolBelow
? BALLOON_STEMHEIGHT
: 0),
791 rect
.right
- rect
.left
,
792 (infoPtr
->bToolBelow
? rect
.bottom
- rect
.top
: rect
.bottom
- rect
.top
- BALLOON_STEMHEIGHT
),
793 BALLOON_ROUNDEDNESS
, BALLOON_ROUNDEDNESS
);
795 CombineRgn(hRgn
, hRgn
, hrStem
, RGN_OR
);
796 DeleteObject(hrStem
);
798 SetWindowRgn(infoPtr
->hwndSelf
, hRgn
, FALSE
);
799 /* we don't free the region handle as the system deletes it when
800 * it is no longer needed */
803 SetWindowPos (infoPtr
->hwndSelf
, HWND_TOPMOST
, rect
.left
, rect
.top
,
804 rect
.right
- rect
.left
, rect
.bottom
- rect
.top
,
805 SWP_SHOWWINDOW
| SWP_NOACTIVATE
);
807 /* repaint the tooltip */
808 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
809 UpdateWindow(infoPtr
->hwndSelf
);
813 SetTimer (infoPtr
->hwndSelf
, ID_TIMERPOP
, infoPtr
->nAutoPopTime
, 0);
814 TRACE("timer 2 started!\n");
815 SetTimer (infoPtr
->hwndSelf
, ID_TIMERLEAVE
, infoPtr
->nReshowTime
, 0);
816 TRACE("timer 3 started!\n");
822 TOOLTIPS_Hide (TOOLTIPS_INFO
*infoPtr
)
824 TTTOOL_INFO
*toolPtr
;
827 TRACE("Hide tooltip %d! (%p)\n", infoPtr
->nCurrentTool
, infoPtr
->hwndSelf
);
829 if (infoPtr
->nCurrentTool
== -1)
832 toolPtr
= &infoPtr
->tools
[infoPtr
->nCurrentTool
];
833 KillTimer (infoPtr
->hwndSelf
, ID_TIMERPOP
);
835 hdr
.hwndFrom
= infoPtr
->hwndSelf
;
836 hdr
.idFrom
= toolPtr
->uId
;
838 SendMessageW (toolPtr
->hwnd
, WM_NOTIFY
, toolPtr
->uId
, (LPARAM
)&hdr
);
840 infoPtr
->nCurrentTool
= -1;
842 SetWindowPos (infoPtr
->hwndSelf
, HWND_TOP
, 0, 0, 0, 0,
843 SWP_NOZORDER
| SWP_HIDEWINDOW
| SWP_NOACTIVATE
);
848 TOOLTIPS_TrackShow (TOOLTIPS_INFO
*infoPtr
)
850 TOOLTIPS_Show(infoPtr
, TRUE
);
855 TOOLTIPS_TrackHide (const TOOLTIPS_INFO
*infoPtr
)
857 TTTOOL_INFO
*toolPtr
;
860 TRACE("hide tracking tooltip %d\n", infoPtr
->nTrackTool
);
862 if (infoPtr
->nTrackTool
== -1)
865 toolPtr
= &infoPtr
->tools
[infoPtr
->nTrackTool
];
867 hdr
.hwndFrom
= infoPtr
->hwndSelf
;
868 hdr
.idFrom
= toolPtr
->uId
;
870 SendMessageW (toolPtr
->hwnd
, WM_NOTIFY
, toolPtr
->uId
, (LPARAM
)&hdr
);
872 SetWindowPos (infoPtr
->hwndSelf
, HWND_TOP
, 0, 0, 0, 0,
873 SWP_NOZORDER
| SWP_HIDEWINDOW
| SWP_NOACTIVATE
);
876 /* Structure layout is the same for TTTOOLINFOW and TTTOOLINFOA,
877 this helper is used in both cases. */
879 TOOLTIPS_GetToolFromInfoT (const TOOLTIPS_INFO
*infoPtr
, const TTTOOLINFOW
*lpToolInfo
)
881 TTTOOL_INFO
*toolPtr
;
884 for (nTool
= 0; nTool
< infoPtr
->uNumTools
; nTool
++) {
885 toolPtr
= &infoPtr
->tools
[nTool
];
887 if (!(toolPtr
->uFlags
& TTF_IDISHWND
) &&
888 (lpToolInfo
->hwnd
== toolPtr
->hwnd
) &&
889 (lpToolInfo
->uId
== toolPtr
->uId
))
893 for (nTool
= 0; nTool
< infoPtr
->uNumTools
; nTool
++) {
894 toolPtr
= &infoPtr
->tools
[nTool
];
896 if ((toolPtr
->uFlags
& TTF_IDISHWND
) &&
897 (lpToolInfo
->uId
== toolPtr
->uId
))
906 TOOLTIPS_GetToolFromPoint (const TOOLTIPS_INFO
*infoPtr
, HWND hwnd
, const POINT
*lpPt
)
908 TTTOOL_INFO
*toolPtr
;
911 for (nTool
= 0; nTool
< infoPtr
->uNumTools
; nTool
++) {
912 toolPtr
= &infoPtr
->tools
[nTool
];
914 if (!(toolPtr
->uFlags
& TTF_IDISHWND
)) {
915 if (hwnd
!= toolPtr
->hwnd
)
917 if (!PtInRect (&toolPtr
->rect
, *lpPt
))
923 for (nTool
= 0; nTool
< infoPtr
->uNumTools
; nTool
++) {
924 toolPtr
= &infoPtr
->tools
[nTool
];
926 if (toolPtr
->uFlags
& TTF_IDISHWND
) {
927 if ((HWND
)toolPtr
->uId
== hwnd
)
936 TOOLTIPS_CopyInfoT (const TTTOOL_INFO
*toolPtr
, TTTOOLINFOW
*ti
, BOOL isW
)
939 if (toolPtr
->lpszText
== NULL
||
940 IS_INTRESOURCE(toolPtr
->lpszText
) ||
941 toolPtr
->lpszText
== LPSTR_TEXTCALLBACKW
)
942 ti
->lpszText
= toolPtr
->lpszText
;
944 strcpyW (ti
->lpszText
, toolPtr
->lpszText
);
946 /* ANSI version, the buffer is maximum 80 bytes without null. */
947 WideCharToMultiByte(CP_ACP
, 0, toolPtr
->lpszText
, -1,
948 (LPSTR
)ti
->lpszText
, MAX_TEXT_SIZE_A
, NULL
, NULL
);
953 TOOLTIPS_IsWindowActive (HWND hwnd
)
955 HWND hwndActive
= GetActiveWindow ();
958 if (hwndActive
== hwnd
)
960 return IsChild (hwndActive
, hwnd
);
965 TOOLTIPS_CheckTool (const TOOLTIPS_INFO
*infoPtr
, BOOL bShowTest
)
972 hwndTool
= (HWND
)SendMessageW (infoPtr
->hwndSelf
, TTM_WINDOWFROMPOINT
, 0, (LPARAM
)&pt
);
976 ScreenToClient (hwndTool
, &pt
);
977 nTool
= TOOLTIPS_GetToolFromPoint (infoPtr
, hwndTool
, &pt
);
981 if (!(GetWindowLongW (infoPtr
->hwndSelf
, GWL_STYLE
) & TTS_ALWAYSTIP
) && bShowTest
)
983 TTTOOL_INFO
*ti
= &infoPtr
->tools
[nTool
];
984 HWND hwnd
= (ti
->uFlags
& TTF_IDISHWND
) ? (HWND
)ti
->uId
: ti
->hwnd
;
986 if (!TOOLTIPS_IsWindowActive(hwnd
))
988 TRACE("not active: hwnd %p, parent %p, active %p\n",
989 hwnd
, GetParent(hwnd
), GetActiveWindow());
994 TRACE("tool %d\n", nTool
);
1001 TOOLTIPS_Activate (TOOLTIPS_INFO
*infoPtr
, BOOL activate
)
1003 infoPtr
->bActive
= activate
;
1005 if (infoPtr
->bActive
)
1006 TRACE("activate!\n");
1008 if (!(infoPtr
->bActive
) && (infoPtr
->nCurrentTool
!= -1))
1009 TOOLTIPS_Hide (infoPtr
);
1016 TOOLTIPS_AddToolT (TOOLTIPS_INFO
*infoPtr
, const TTTOOLINFOW
*ti
, BOOL isW
)
1018 TTTOOL_INFO
*toolPtr
;
1021 if (!ti
) return FALSE
;
1023 TRACE("add tool (%p) %p %ld%s!\n",
1024 infoPtr
->hwndSelf
, ti
->hwnd
, ti
->uId
,
1025 (ti
->uFlags
& TTF_IDISHWND
) ? " TTF_IDISHWND" : "");
1027 if (infoPtr
->uNumTools
== 0) {
1028 infoPtr
->tools
= Alloc (sizeof(TTTOOL_INFO
));
1029 toolPtr
= infoPtr
->tools
;
1032 TTTOOL_INFO
*oldTools
= infoPtr
->tools
;
1034 Alloc (sizeof(TTTOOL_INFO
) * (infoPtr
->uNumTools
+ 1));
1035 memcpy (infoPtr
->tools
, oldTools
,
1036 infoPtr
->uNumTools
* sizeof(TTTOOL_INFO
));
1038 toolPtr
= &infoPtr
->tools
[infoPtr
->uNumTools
];
1041 infoPtr
->uNumTools
++;
1043 /* copy tool data */
1044 toolPtr
->uFlags
= ti
->uFlags
;
1045 toolPtr
->hwnd
= ti
->hwnd
;
1046 toolPtr
->uId
= ti
->uId
;
1047 toolPtr
->rect
= ti
->rect
;
1048 toolPtr
->hinst
= ti
->hinst
;
1050 if (IS_INTRESOURCE(ti
->lpszText
)) {
1051 TRACE("add string id %x\n", LOWORD(ti
->lpszText
));
1052 toolPtr
->lpszText
= ti
->lpszText
;
1054 else if (ti
->lpszText
) {
1055 if (TOOLTIPS_IsCallbackString(ti
->lpszText
, isW
)) {
1056 TRACE("add CALLBACK!\n");
1057 toolPtr
->lpszText
= LPSTR_TEXTCALLBACKW
;
1060 INT len
= lstrlenW (ti
->lpszText
);
1061 TRACE("add text %s!\n", debugstr_w(ti
->lpszText
));
1062 toolPtr
->lpszText
= Alloc ((len
+ 1)*sizeof(WCHAR
));
1063 strcpyW (toolPtr
->lpszText
, ti
->lpszText
);
1066 INT len
= MultiByteToWideChar(CP_ACP
, 0, (LPSTR
)ti
->lpszText
, -1, NULL
, 0);
1067 TRACE("add text \"%s\"!\n", (LPSTR
)ti
->lpszText
);
1068 toolPtr
->lpszText
= Alloc (len
* sizeof(WCHAR
));
1069 MultiByteToWideChar(CP_ACP
, 0, (LPSTR
)ti
->lpszText
, -1, toolPtr
->lpszText
, len
);
1073 if (ti
->cbSize
>= TTTOOLINFOW_V2_SIZE
)
1074 toolPtr
->lParam
= ti
->lParam
;
1076 /* install subclassing hook */
1077 if (toolPtr
->uFlags
& TTF_SUBCLASS
) {
1078 if (toolPtr
->uFlags
& TTF_IDISHWND
) {
1079 SetWindowSubclass((HWND
)toolPtr
->uId
, TOOLTIPS_SubclassProc
, 1,
1080 (DWORD_PTR
)infoPtr
->hwndSelf
);
1083 SetWindowSubclass(toolPtr
->hwnd
, TOOLTIPS_SubclassProc
, 1,
1084 (DWORD_PTR
)infoPtr
->hwndSelf
);
1086 TRACE("subclassing installed!\n");
1089 nResult
= SendMessageW (toolPtr
->hwnd
, WM_NOTIFYFORMAT
,
1090 (WPARAM
)infoPtr
->hwndSelf
, NF_QUERY
);
1091 if (nResult
== NFR_ANSI
) {
1092 toolPtr
->bNotifyUnicode
= FALSE
;
1093 TRACE(" -- WM_NOTIFYFORMAT returns: NFR_ANSI\n");
1094 } else if (nResult
== NFR_UNICODE
) {
1095 toolPtr
->bNotifyUnicode
= TRUE
;
1096 TRACE(" -- WM_NOTIFYFORMAT returns: NFR_UNICODE\n");
1098 TRACE (" -- WM_NOTIFYFORMAT returns: error!\n");
1106 TOOLTIPS_DelToolT (TOOLTIPS_INFO
*infoPtr
, const TTTOOLINFOW
*ti
, BOOL isW
)
1108 TTTOOL_INFO
*toolPtr
;
1112 if (isW
&& ti
->cbSize
> TTTOOLINFOW_V2_SIZE
&&
1113 ti
->cbSize
!= TTTOOLINFOW_V3_SIZE
)
1115 if (infoPtr
->uNumTools
== 0)
1118 nTool
= TOOLTIPS_GetToolFromInfoT (infoPtr
, ti
);
1120 TRACE("tool %d\n", nTool
);
1125 /* make sure the tooltip has disappeared before deleting it */
1126 TOOLTIPS_Hide(infoPtr
);
1128 /* delete text string */
1129 toolPtr
= &infoPtr
->tools
[nTool
];
1130 if (toolPtr
->lpszText
) {
1131 if ( (toolPtr
->lpszText
!= LPSTR_TEXTCALLBACKW
) &&
1132 !IS_INTRESOURCE(toolPtr
->lpszText
) )
1133 Free (toolPtr
->lpszText
);
1136 /* remove subclassing */
1137 if (toolPtr
->uFlags
& TTF_SUBCLASS
) {
1138 if (toolPtr
->uFlags
& TTF_IDISHWND
) {
1139 RemoveWindowSubclass((HWND
)toolPtr
->uId
, TOOLTIPS_SubclassProc
, 1);
1142 RemoveWindowSubclass(toolPtr
->hwnd
, TOOLTIPS_SubclassProc
, 1);
1146 /* delete tool from tool list */
1147 if (infoPtr
->uNumTools
== 1) {
1148 Free (infoPtr
->tools
);
1149 infoPtr
->tools
= NULL
;
1152 TTTOOL_INFO
*oldTools
= infoPtr
->tools
;
1154 Alloc (sizeof(TTTOOL_INFO
) * (infoPtr
->uNumTools
- 1));
1157 memcpy (&infoPtr
->tools
[0], &oldTools
[0],
1158 nTool
* sizeof(TTTOOL_INFO
));
1160 if (nTool
< infoPtr
->uNumTools
- 1)
1161 memcpy (&infoPtr
->tools
[nTool
], &oldTools
[nTool
+ 1],
1162 (infoPtr
->uNumTools
- nTool
- 1) * sizeof(TTTOOL_INFO
));
1167 /* update any indices affected by delete */
1169 /* destroying tool that mouse was on on last relayed mouse move */
1170 if (infoPtr
->nTool
== nTool
)
1171 /* -1 means no current tool (0 means first tool) */
1172 infoPtr
->nTool
= -1;
1173 else if (infoPtr
->nTool
> nTool
)
1176 if (infoPtr
->nTrackTool
== nTool
)
1177 /* -1 means no current tool (0 means first tool) */
1178 infoPtr
->nTrackTool
= -1;
1179 else if (infoPtr
->nTrackTool
> nTool
)
1180 infoPtr
->nTrackTool
--;
1182 if (infoPtr
->nCurrentTool
== nTool
)
1183 /* -1 means no current tool (0 means first tool) */
1184 infoPtr
->nCurrentTool
= -1;
1185 else if (infoPtr
->nCurrentTool
> nTool
)
1186 infoPtr
->nCurrentTool
--;
1188 infoPtr
->uNumTools
--;
1194 TOOLTIPS_EnumToolsT (const TOOLTIPS_INFO
*infoPtr
, UINT uIndex
, TTTOOLINFOW
*ti
,
1197 TTTOOL_INFO
*toolPtr
;
1199 if (!ti
) return FALSE
;
1200 if (ti
->cbSize
< TTTOOLINFOW_V1_SIZE
)
1202 if (uIndex
>= infoPtr
->uNumTools
)
1205 TRACE("index=%u\n", uIndex
);
1207 toolPtr
= &infoPtr
->tools
[uIndex
];
1209 /* copy tool data */
1210 ti
->uFlags
= toolPtr
->uFlags
;
1211 ti
->hwnd
= toolPtr
->hwnd
;
1212 ti
->uId
= toolPtr
->uId
;
1213 ti
->rect
= toolPtr
->rect
;
1214 ti
->hinst
= toolPtr
->hinst
;
1215 TOOLTIPS_CopyInfoT (toolPtr
, ti
, isW
);
1217 if (ti
->cbSize
>= TTTOOLINFOA_V2_SIZE
)
1218 ti
->lParam
= toolPtr
->lParam
;
1224 TOOLTIPS_GetBubbleSize (const TOOLTIPS_INFO
*infoPtr
, const TTTOOLINFOW
*lpToolInfo
)
1229 if (lpToolInfo
== NULL
)
1231 if (lpToolInfo
->cbSize
< TTTOOLINFOW_V1_SIZE
)
1234 nTool
= TOOLTIPS_GetToolFromInfoT (infoPtr
, lpToolInfo
);
1235 if (nTool
== -1) return 0;
1237 TRACE("tool %d\n", nTool
);
1239 TOOLTIPS_CalcTipSize (infoPtr
, &size
);
1240 TRACE("size %d x %d\n", size
.cx
, size
.cy
);
1242 return MAKELRESULT(size
.cx
, size
.cy
);
1246 TOOLTIPS_GetCurrentToolT (const TOOLTIPS_INFO
*infoPtr
, TTTOOLINFOW
*ti
, BOOL isW
)
1248 TTTOOL_INFO
*toolPtr
;
1251 if (ti
->cbSize
< TTTOOLINFOW_V1_SIZE
)
1254 if (infoPtr
->nCurrentTool
> -1) {
1255 toolPtr
= &infoPtr
->tools
[infoPtr
->nCurrentTool
];
1257 /* copy tool data */
1258 ti
->uFlags
= toolPtr
->uFlags
;
1259 ti
->rect
= toolPtr
->rect
;
1260 ti
->hinst
= toolPtr
->hinst
;
1261 TOOLTIPS_CopyInfoT (toolPtr
, ti
, isW
);
1263 if (ti
->cbSize
>= TTTOOLINFOW_V2_SIZE
)
1264 ti
->lParam
= toolPtr
->lParam
;
1272 return (infoPtr
->nCurrentTool
!= -1);
1277 TOOLTIPS_GetDelayTime (const TOOLTIPS_INFO
*infoPtr
, DWORD duration
)
1281 return infoPtr
->nReshowTime
;
1284 return infoPtr
->nAutoPopTime
;
1287 case TTDT_AUTOMATIC
: /* Apparently TTDT_AUTOMATIC returns TTDT_INITIAL */
1288 return infoPtr
->nInitialTime
;
1291 WARN("Invalid duration flag %x\n", duration
);
1300 TOOLTIPS_GetMargin (const TOOLTIPS_INFO
*infoPtr
, LPRECT lpRect
)
1302 lpRect
->left
= infoPtr
->rcMargin
.left
;
1303 lpRect
->right
= infoPtr
->rcMargin
.right
;
1304 lpRect
->bottom
= infoPtr
->rcMargin
.bottom
;
1305 lpRect
->top
= infoPtr
->rcMargin
.top
;
1311 static inline LRESULT
1312 TOOLTIPS_GetMaxTipWidth (const TOOLTIPS_INFO
*infoPtr
)
1314 return infoPtr
->nMaxTipWidth
;
1319 TOOLTIPS_GetTextT (const TOOLTIPS_INFO
*infoPtr
, TTTOOLINFOW
*ti
, BOOL isW
)
1324 if (ti
->cbSize
< TTTOOLINFOW_V1_SIZE
)
1327 nTool
= TOOLTIPS_GetToolFromInfoT (infoPtr
, ti
);
1328 if (nTool
== -1) return 0;
1330 if (infoPtr
->tools
[nTool
].lpszText
== NULL
)
1334 ti
->lpszText
[0] = '\0';
1335 TOOLTIPS_GetTipText(infoPtr
, nTool
, ti
->lpszText
);
1338 WCHAR buffer
[INFOTIPSIZE
];
1340 /* NB this API is broken, there is no way for the app to determine
1341 what size buffer it requires nor a way to specify how long the
1342 one it supplies is. According to the test result, it's up to
1343 80 bytes by the ANSI version. */
1346 TOOLTIPS_GetTipText(infoPtr
, nTool
, buffer
);
1347 WideCharToMultiByte(CP_ACP
, 0, buffer
, -1, (LPSTR
)ti
->lpszText
,
1348 MAX_TEXT_SIZE_A
, NULL
, NULL
);
1355 static inline LRESULT
1356 TOOLTIPS_GetTipBkColor (const TOOLTIPS_INFO
*infoPtr
)
1358 return infoPtr
->clrBk
;
1362 static inline LRESULT
1363 TOOLTIPS_GetTipTextColor (const TOOLTIPS_INFO
*infoPtr
)
1365 return infoPtr
->clrText
;
1369 static inline LRESULT
1370 TOOLTIPS_GetToolCount (const TOOLTIPS_INFO
*infoPtr
)
1372 return infoPtr
->uNumTools
;
1377 TOOLTIPS_GetToolInfoT (const TOOLTIPS_INFO
*infoPtr
, TTTOOLINFOW
*ti
, BOOL isW
)
1379 TTTOOL_INFO
*toolPtr
;
1382 if (!ti
) return FALSE
;
1383 if (ti
->cbSize
< TTTOOLINFOW_V1_SIZE
)
1385 if (infoPtr
->uNumTools
== 0)
1388 nTool
= TOOLTIPS_GetToolFromInfoT (infoPtr
, ti
);
1392 TRACE("tool %d\n", nTool
);
1394 toolPtr
= &infoPtr
->tools
[nTool
];
1396 /* copy tool data */
1397 ti
->uFlags
= toolPtr
->uFlags
;
1398 ti
->rect
= toolPtr
->rect
;
1399 ti
->hinst
= toolPtr
->hinst
;
1400 TOOLTIPS_CopyInfoT (toolPtr
, ti
, isW
);
1402 if (ti
->cbSize
>= TTTOOLINFOW_V2_SIZE
)
1403 ti
->lParam
= toolPtr
->lParam
;
1410 TOOLTIPS_HitTestT (const TOOLTIPS_INFO
*infoPtr
, LPTTHITTESTINFOW lptthit
,
1413 TTTOOL_INFO
*toolPtr
;
1419 nTool
= TOOLTIPS_GetToolFromPoint (infoPtr
, lptthit
->hwnd
, &lptthit
->pt
);
1423 TRACE("tool %d!\n", nTool
);
1425 /* copy tool data */
1426 if (lptthit
->ti
.cbSize
>= TTTOOLINFOW_V1_SIZE
) {
1427 toolPtr
= &infoPtr
->tools
[nTool
];
1429 lptthit
->ti
.uFlags
= toolPtr
->uFlags
;
1430 lptthit
->ti
.hwnd
= toolPtr
->hwnd
;
1431 lptthit
->ti
.uId
= toolPtr
->uId
;
1432 lptthit
->ti
.rect
= toolPtr
->rect
;
1433 lptthit
->ti
.hinst
= toolPtr
->hinst
;
1434 TOOLTIPS_CopyInfoT (toolPtr
, &lptthit
->ti
, isW
);
1435 if (lptthit
->ti
.cbSize
>= TTTOOLINFOW_V2_SIZE
)
1436 lptthit
->ti
.lParam
= toolPtr
->lParam
;
1444 TOOLTIPS_NewToolRectT (TOOLTIPS_INFO
*infoPtr
, const TTTOOLINFOW
*ti
)
1449 if (ti
->cbSize
< TTTOOLINFOW_V1_SIZE
)
1452 nTool
= TOOLTIPS_GetToolFromInfoT (infoPtr
, ti
);
1454 TRACE("nTool = %d, rect = %s\n", nTool
, wine_dbgstr_rect(&ti
->rect
));
1456 if (nTool
== -1) return 0;
1458 infoPtr
->tools
[nTool
].rect
= ti
->rect
;
1464 static inline LRESULT
1465 TOOLTIPS_Pop (TOOLTIPS_INFO
*infoPtr
)
1467 TOOLTIPS_Hide (infoPtr
);
1474 TOOLTIPS_RelayEvent (TOOLTIPS_INFO
*infoPtr
, LPMSG lpMsg
)
1480 ERR("lpMsg == NULL!\n");
1484 switch (lpMsg
->message
) {
1485 case WM_LBUTTONDOWN
:
1487 case WM_MBUTTONDOWN
:
1489 case WM_RBUTTONDOWN
:
1491 TOOLTIPS_Hide (infoPtr
);
1495 pt
.x
= (short)LOWORD(lpMsg
->lParam
);
1496 pt
.y
= (short)HIWORD(lpMsg
->lParam
);
1497 nOldTool
= infoPtr
->nTool
;
1498 infoPtr
->nTool
= TOOLTIPS_GetToolFromPoint(infoPtr
, lpMsg
->hwnd
,
1500 TRACE("tool (%p) %d %d %d\n", infoPtr
->hwndSelf
, nOldTool
,
1501 infoPtr
->nTool
, infoPtr
->nCurrentTool
);
1502 TRACE("WM_MOUSEMOVE (%p %d %d)\n", infoPtr
->hwndSelf
, pt
.x
, pt
.y
);
1504 if (infoPtr
->nTool
!= nOldTool
) {
1505 if(infoPtr
->nTool
== -1) { /* Moved out of all tools */
1506 TOOLTIPS_Hide(infoPtr
);
1507 KillTimer(infoPtr
->hwndSelf
, ID_TIMERLEAVE
);
1508 } else if (nOldTool
== -1) { /* Moved from outside */
1509 if(infoPtr
->bActive
) {
1510 SetTimer(infoPtr
->hwndSelf
, ID_TIMERSHOW
, infoPtr
->nInitialTime
, 0);
1511 TRACE("timer 1 started!\n");
1513 } else { /* Moved from one to another */
1514 TOOLTIPS_Hide (infoPtr
);
1515 KillTimer(infoPtr
->hwndSelf
, ID_TIMERLEAVE
);
1516 if(infoPtr
->bActive
) {
1517 SetTimer (infoPtr
->hwndSelf
, ID_TIMERSHOW
, infoPtr
->nReshowTime
, 0);
1518 TRACE("timer 1 started!\n");
1521 } else if(infoPtr
->nCurrentTool
!= -1) { /* restart autopop */
1522 KillTimer(infoPtr
->hwndSelf
, ID_TIMERPOP
);
1523 SetTimer(infoPtr
->hwndSelf
, ID_TIMERPOP
, infoPtr
->nAutoPopTime
, 0);
1524 TRACE("timer 2 restarted\n");
1525 } else if(infoPtr
->nTool
!= -1 && infoPtr
->bActive
) {
1526 /* previous show attempt didn't result in tooltip so try again */
1527 SetTimer(infoPtr
->hwndSelf
, ID_TIMERSHOW
, infoPtr
->nInitialTime
, 0);
1528 TRACE("timer 1 started!\n");
1538 TOOLTIPS_SetDelayTime (TOOLTIPS_INFO
*infoPtr
, DWORD duration
, INT nTime
)
1541 case TTDT_AUTOMATIC
:
1543 nTime
= GetDoubleClickTime();
1544 infoPtr
->nReshowTime
= nTime
/ 5;
1545 infoPtr
->nAutoPopTime
= nTime
* 10;
1546 infoPtr
->nInitialTime
= nTime
;
1551 nTime
= GetDoubleClickTime() / 5;
1552 infoPtr
->nReshowTime
= nTime
;
1557 nTime
= GetDoubleClickTime() * 10;
1558 infoPtr
->nAutoPopTime
= nTime
;
1563 nTime
= GetDoubleClickTime();
1564 infoPtr
->nInitialTime
= nTime
;
1568 WARN("Invalid duration flag %x\n", duration
);
1577 TOOLTIPS_SetMargin (TOOLTIPS_INFO
*infoPtr
, const RECT
*lpRect
)
1579 infoPtr
->rcMargin
.left
= lpRect
->left
;
1580 infoPtr
->rcMargin
.right
= lpRect
->right
;
1581 infoPtr
->rcMargin
.bottom
= lpRect
->bottom
;
1582 infoPtr
->rcMargin
.top
= lpRect
->top
;
1588 static inline LRESULT
1589 TOOLTIPS_SetMaxTipWidth (TOOLTIPS_INFO
*infoPtr
, INT MaxWidth
)
1591 INT nTemp
= infoPtr
->nMaxTipWidth
;
1593 infoPtr
->nMaxTipWidth
= MaxWidth
;
1599 static inline LRESULT
1600 TOOLTIPS_SetTipBkColor (TOOLTIPS_INFO
*infoPtr
, COLORREF clrBk
)
1602 infoPtr
->clrBk
= clrBk
;
1608 static inline LRESULT
1609 TOOLTIPS_SetTipTextColor (TOOLTIPS_INFO
*infoPtr
, COLORREF clrText
)
1611 infoPtr
->clrText
= clrText
;
1618 TOOLTIPS_SetTitleT (TOOLTIPS_INFO
*infoPtr
, UINT_PTR uTitleIcon
, LPCWSTR pszTitle
,
1623 TRACE("hwnd = %p, title = %s, icon = %p\n", infoPtr
->hwndSelf
, debugstr_w(pszTitle
),
1626 Free(infoPtr
->pszTitle
);
1632 size
= (strlenW(pszTitle
)+1)*sizeof(WCHAR
);
1633 infoPtr
->pszTitle
= Alloc(size
);
1634 if (!infoPtr
->pszTitle
)
1636 memcpy(infoPtr
->pszTitle
, pszTitle
, size
);
1640 size
= sizeof(WCHAR
)*MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)pszTitle
, -1, NULL
, 0);
1641 infoPtr
->pszTitle
= Alloc(size
);
1642 if (!infoPtr
->pszTitle
)
1644 MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)pszTitle
, -1, infoPtr
->pszTitle
, size
/sizeof(WCHAR
));
1648 infoPtr
->pszTitle
= NULL
;
1650 if (uTitleIcon
<= TTI_ERROR
)
1651 infoPtr
->hTitleIcon
= hTooltipIcons
[uTitleIcon
];
1653 infoPtr
->hTitleIcon
= CopyIcon((HICON
)uTitleIcon
);
1655 TRACE("icon = %p\n", infoPtr
->hTitleIcon
);
1662 TOOLTIPS_SetToolInfoT (TOOLTIPS_INFO
*infoPtr
, const TTTOOLINFOW
*ti
, BOOL isW
)
1664 TTTOOL_INFO
*toolPtr
;
1668 if (ti
->cbSize
< TTTOOLINFOW_V1_SIZE
)
1671 nTool
= TOOLTIPS_GetToolFromInfoT (infoPtr
, ti
);
1672 if (nTool
== -1) return 0;
1674 TRACE("tool %d\n", nTool
);
1676 toolPtr
= &infoPtr
->tools
[nTool
];
1678 /* copy tool data */
1679 toolPtr
->uFlags
= ti
->uFlags
;
1680 toolPtr
->hwnd
= ti
->hwnd
;
1681 toolPtr
->uId
= ti
->uId
;
1682 toolPtr
->rect
= ti
->rect
;
1683 toolPtr
->hinst
= ti
->hinst
;
1685 if (IS_INTRESOURCE(ti
->lpszText
)) {
1686 TRACE("set string id %x!\n", LOWORD(ti
->lpszText
));
1687 toolPtr
->lpszText
= ti
->lpszText
;
1690 if (TOOLTIPS_IsCallbackString(ti
->lpszText
, isW
))
1691 toolPtr
->lpszText
= LPSTR_TEXTCALLBACKW
;
1693 if ( (toolPtr
->lpszText
) &&
1694 !IS_INTRESOURCE(toolPtr
->lpszText
) ) {
1695 if( toolPtr
->lpszText
!= LPSTR_TEXTCALLBACKW
)
1696 Free (toolPtr
->lpszText
);
1697 toolPtr
->lpszText
= NULL
;
1701 INT len
= lstrlenW (ti
->lpszText
);
1702 toolPtr
->lpszText
= Alloc ((len
+1)*sizeof(WCHAR
));
1703 strcpyW (toolPtr
->lpszText
, ti
->lpszText
);
1706 INT len
= MultiByteToWideChar(CP_ACP
, 0, (LPSTR
)ti
->lpszText
,
1708 toolPtr
->lpszText
= Alloc (len
* sizeof(WCHAR
));
1709 MultiByteToWideChar(CP_ACP
, 0, (LPSTR
)ti
->lpszText
, -1,
1710 toolPtr
->lpszText
, len
);
1716 if (ti
->cbSize
>= TTTOOLINFOW_V2_SIZE
)
1717 toolPtr
->lParam
= ti
->lParam
;
1719 if (infoPtr
->nCurrentTool
== nTool
)
1721 TOOLTIPS_GetTipText (infoPtr
, infoPtr
->nCurrentTool
, infoPtr
->szTipText
);
1723 if (infoPtr
->szTipText
[0] == 0)
1724 TOOLTIPS_Hide(infoPtr
);
1726 TOOLTIPS_Show (infoPtr
, FALSE
);
1734 TOOLTIPS_TrackActivate (TOOLTIPS_INFO
*infoPtr
, BOOL track_activate
, const TTTOOLINFOA
*ti
)
1736 if (track_activate
) {
1739 if (ti
->cbSize
< TTTOOLINFOA_V1_SIZE
)
1743 infoPtr
->nTrackTool
= TOOLTIPS_GetToolFromInfoT (infoPtr
, (const TTTOOLINFOW
*)ti
);
1744 if (infoPtr
->nTrackTool
!= -1) {
1745 TRACE("activated!\n");
1746 infoPtr
->bTrackActive
= TRUE
;
1747 TOOLTIPS_TrackShow (infoPtr
);
1752 TOOLTIPS_TrackHide (infoPtr
);
1754 infoPtr
->bTrackActive
= FALSE
;
1755 infoPtr
->nTrackTool
= -1;
1757 TRACE("deactivated!\n");
1765 TOOLTIPS_TrackPosition (TOOLTIPS_INFO
*infoPtr
, LPARAM coord
)
1767 infoPtr
->xTrackPos
= (INT
)LOWORD(coord
);
1768 infoPtr
->yTrackPos
= (INT
)HIWORD(coord
);
1770 if (infoPtr
->bTrackActive
) {
1772 infoPtr
->xTrackPos
, infoPtr
->yTrackPos
);
1774 TOOLTIPS_TrackShow (infoPtr
);
1782 TOOLTIPS_Update (TOOLTIPS_INFO
*infoPtr
)
1784 if (infoPtr
->nCurrentTool
!= -1)
1785 UpdateWindow (infoPtr
->hwndSelf
);
1792 TOOLTIPS_UpdateTipTextT (TOOLTIPS_INFO
*infoPtr
, const TTTOOLINFOW
*ti
, BOOL isW
)
1794 TTTOOL_INFO
*toolPtr
;
1798 if (ti
->cbSize
< TTTOOLINFOW_V1_SIZE
)
1801 nTool
= TOOLTIPS_GetToolFromInfoT (infoPtr
, ti
);
1805 TRACE("tool %d\n", nTool
);
1807 toolPtr
= &infoPtr
->tools
[nTool
];
1809 /* copy tool text */
1810 toolPtr
->hinst
= ti
->hinst
;
1812 if (IS_INTRESOURCE(ti
->lpszText
)){
1813 toolPtr
->lpszText
= ti
->lpszText
;
1815 else if (ti
->lpszText
) {
1816 if (TOOLTIPS_IsCallbackString(ti
->lpszText
, isW
))
1817 toolPtr
->lpszText
= LPSTR_TEXTCALLBACKW
;
1819 if ( (toolPtr
->lpszText
) &&
1820 !IS_INTRESOURCE(toolPtr
->lpszText
) ) {
1821 if( toolPtr
->lpszText
!= LPSTR_TEXTCALLBACKW
)
1822 Free (toolPtr
->lpszText
);
1823 toolPtr
->lpszText
= NULL
;
1827 INT len
= lstrlenW (ti
->lpszText
);
1828 toolPtr
->lpszText
= Alloc ((len
+1)*sizeof(WCHAR
));
1829 strcpyW (toolPtr
->lpszText
, ti
->lpszText
);
1832 INT len
= MultiByteToWideChar(CP_ACP
, 0, (LPSTR
)ti
->lpszText
,
1834 toolPtr
->lpszText
= Alloc (len
* sizeof(WCHAR
));
1835 MultiByteToWideChar(CP_ACP
, 0, (LPSTR
)ti
->lpszText
, -1,
1836 toolPtr
->lpszText
, len
);
1842 if(infoPtr
->nCurrentTool
== -1) return 0;
1844 if (infoPtr
->bActive
)
1845 TOOLTIPS_Show (infoPtr
, FALSE
);
1846 else if (infoPtr
->bTrackActive
)
1847 TOOLTIPS_Show (infoPtr
, TRUE
);
1854 TOOLTIPS_Create (HWND hwnd
)
1856 TOOLTIPS_INFO
*infoPtr
;
1858 /* allocate memory for info structure */
1859 infoPtr
= Alloc (sizeof(TOOLTIPS_INFO
));
1860 SetWindowLongPtrW (hwnd
, 0, (DWORD_PTR
)infoPtr
);
1862 /* initialize info structure */
1863 infoPtr
->bActive
= TRUE
;
1864 infoPtr
->bTrackActive
= FALSE
;
1866 infoPtr
->nMaxTipWidth
= -1;
1867 infoPtr
->nTool
= -1;
1868 infoPtr
->nCurrentTool
= -1;
1869 infoPtr
->nTrackTool
= -1;
1870 infoPtr
->hwndSelf
= hwnd
;
1872 /* initialize colours and fonts */
1873 TOOLTIPS_InitSystemSettings(infoPtr
);
1875 TOOLTIPS_SetDelayTime(infoPtr
, TTDT_AUTOMATIC
, 0);
1877 SetWindowPos (hwnd
, HWND_TOP
, 0, 0, 0, 0, SWP_NOZORDER
| SWP_HIDEWINDOW
| SWP_NOACTIVATE
);
1884 TOOLTIPS_Destroy (TOOLTIPS_INFO
*infoPtr
)
1886 TTTOOL_INFO
*toolPtr
;
1890 if (infoPtr
->tools
) {
1891 for (i
= 0; i
< infoPtr
->uNumTools
; i
++) {
1892 toolPtr
= &infoPtr
->tools
[i
];
1893 if (toolPtr
->lpszText
) {
1894 if ( (toolPtr
->lpszText
!= LPSTR_TEXTCALLBACKW
) &&
1895 !IS_INTRESOURCE(toolPtr
->lpszText
) )
1897 Free (toolPtr
->lpszText
);
1898 toolPtr
->lpszText
= NULL
;
1902 /* remove subclassing */
1903 if (toolPtr
->uFlags
& TTF_SUBCLASS
) {
1904 if (toolPtr
->uFlags
& TTF_IDISHWND
) {
1905 RemoveWindowSubclass((HWND
)toolPtr
->uId
, TOOLTIPS_SubclassProc
, 1);
1908 RemoveWindowSubclass(toolPtr
->hwnd
, TOOLTIPS_SubclassProc
, 1);
1912 Free (infoPtr
->tools
);
1915 /* free title string */
1916 Free (infoPtr
->pszTitle
);
1917 /* free title icon if not a standard one */
1918 if (TOOLTIPS_GetTitleIconIndex(infoPtr
->hTitleIcon
) > TTI_ERROR
)
1919 DeleteObject(infoPtr
->hTitleIcon
);
1922 DeleteObject (infoPtr
->hFont
);
1923 DeleteObject (infoPtr
->hTitleFont
);
1925 /* free tool tips info data */
1926 SetWindowLongPtrW(infoPtr
->hwndSelf
, 0, 0);
1933 static inline LRESULT
1934 TOOLTIPS_GetFont (const TOOLTIPS_INFO
*infoPtr
)
1936 return (LRESULT
)infoPtr
->hFont
;
1941 TOOLTIPS_MouseMessage (TOOLTIPS_INFO
*infoPtr
)
1943 TOOLTIPS_Hide (infoPtr
);
1950 TOOLTIPS_NCCreate (HWND hwnd
)
1952 DWORD dwStyle
= GetWindowLongW (hwnd
, GWL_STYLE
);
1953 DWORD dwExStyle
= GetWindowLongW (hwnd
, GWL_EXSTYLE
);
1955 dwStyle
&= ~(WS_CHILD
| /*WS_MAXIMIZE |*/ WS_BORDER
| WS_DLGFRAME
);
1956 dwStyle
|= (WS_POPUP
| WS_BORDER
| WS_CLIPSIBLINGS
);
1958 /* WS_BORDER only draws a border round the window rect, not the
1959 * window region, therefore it is useless to us in balloon mode */
1960 if (dwStyle
& TTS_BALLOON
) dwStyle
&= ~WS_BORDER
;
1962 SetWindowLongW (hwnd
, GWL_STYLE
, dwStyle
);
1964 dwExStyle
|= WS_EX_TOOLWINDOW
;
1965 SetWindowLongW (hwnd
, GWL_EXSTYLE
, dwExStyle
);
1972 TOOLTIPS_NCHitTest (const TOOLTIPS_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
1974 INT nTool
= (infoPtr
->bTrackActive
) ? infoPtr
->nTrackTool
: infoPtr
->nTool
;
1976 TRACE(" nTool=%d\n", nTool
);
1978 if ((nTool
> -1) && (nTool
< infoPtr
->uNumTools
)) {
1979 if (infoPtr
->tools
[nTool
].uFlags
& TTF_TRANSPARENT
) {
1980 TRACE("-- in transparent mode!\n");
1981 return HTTRANSPARENT
;
1985 return DefWindowProcW (infoPtr
->hwndSelf
, WM_NCHITTEST
, wParam
, lParam
);
1990 TOOLTIPS_NotifyFormat (TOOLTIPS_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
1992 TTTOOL_INFO
*toolPtr
= infoPtr
->tools
;
1995 TRACE("infoPtr=%p wParam=%lx lParam=%p\n", infoPtr
, wParam
, (PVOID
)lParam
);
1997 if (lParam
== NF_QUERY
) {
1998 if (toolPtr
->bNotifyUnicode
) {
2004 else if (lParam
== NF_REQUERY
) {
2005 nResult
= SendMessageW (toolPtr
->hwnd
, WM_NOTIFYFORMAT
,
2006 (WPARAM
)infoPtr
->hwndSelf
, (LPARAM
)NF_QUERY
);
2007 if (nResult
== NFR_ANSI
) {
2008 toolPtr
->bNotifyUnicode
= FALSE
;
2009 TRACE(" -- WM_NOTIFYFORMAT returns: NFR_ANSI\n");
2010 } else if (nResult
== NFR_UNICODE
) {
2011 toolPtr
->bNotifyUnicode
= TRUE
;
2012 TRACE(" -- WM_NOTIFYFORMAT returns: NFR_UNICODE\n");
2014 TRACE (" -- WM_NOTIFYFORMAT returns: error!\n");
2024 TOOLTIPS_Paint (const TOOLTIPS_INFO
*infoPtr
, HDC hDC
)
2029 hdc
= (hDC
== NULL
) ? BeginPaint (infoPtr
->hwndSelf
, &ps
) : hDC
;
2030 TOOLTIPS_Refresh (infoPtr
, hdc
);
2032 EndPaint (infoPtr
->hwndSelf
, &ps
);
2038 TOOLTIPS_SetFont (TOOLTIPS_INFO
*infoPtr
, HFONT hFont
, BOOL redraw
)
2042 if(!GetObjectW(hFont
, sizeof(lf
), &lf
))
2045 DeleteObject (infoPtr
->hFont
);
2046 infoPtr
->hFont
= CreateFontIndirectW(&lf
);
2048 DeleteObject (infoPtr
->hTitleFont
);
2049 lf
.lfWeight
= FW_BOLD
;
2050 infoPtr
->hTitleFont
= CreateFontIndirectW(&lf
);
2052 if (redraw
&& infoPtr
->nCurrentTool
!= -1) {
2053 FIXME("full redraw needed!\n");
2059 /******************************************************************
2060 * TOOLTIPS_GetTextLength
2062 * This function is called when the tooltip receive a
2063 * WM_GETTEXTLENGTH message.
2065 * returns the length, in characters, of the tip text
2067 static inline LRESULT
2068 TOOLTIPS_GetTextLength(const TOOLTIPS_INFO
*infoPtr
)
2070 return strlenW(infoPtr
->szTipText
);
2073 /******************************************************************
2074 * TOOLTIPS_OnWMGetText
2076 * This function is called when the tooltip receive a
2077 * WM_GETTEXT message.
2078 * wParam : specifies the maximum number of characters to be copied
2079 * lParam : is the pointer to the buffer that will receive
2082 * returns the number of characters copied
2085 TOOLTIPS_OnWMGetText (const TOOLTIPS_INFO
*infoPtr
, WPARAM size
, LPWSTR pszText
)
2092 res
= min(strlenW(infoPtr
->szTipText
)+1, size
);
2093 memcpy(pszText
, infoPtr
->szTipText
, res
*sizeof(WCHAR
));
2094 pszText
[res
-1] = '\0';
2099 TOOLTIPS_Timer (TOOLTIPS_INFO
*infoPtr
, INT iTimer
)
2103 TRACE("timer %d (%p) expired!\n", iTimer
, infoPtr
->hwndSelf
);
2107 KillTimer (infoPtr
->hwndSelf
, ID_TIMERSHOW
);
2108 nOldTool
= infoPtr
->nTool
;
2109 if ((infoPtr
->nTool
= TOOLTIPS_CheckTool (infoPtr
, TRUE
)) == nOldTool
)
2110 TOOLTIPS_Show (infoPtr
, FALSE
);
2114 TOOLTIPS_Hide (infoPtr
);
2118 nOldTool
= infoPtr
->nTool
;
2119 infoPtr
->nTool
= TOOLTIPS_CheckTool (infoPtr
, FALSE
);
2120 TRACE("tool (%p) %d %d %d\n", infoPtr
->hwndSelf
, nOldTool
,
2121 infoPtr
->nTool
, infoPtr
->nCurrentTool
);
2122 if (infoPtr
->nTool
!= nOldTool
) {
2123 if(infoPtr
->nTool
== -1) { /* Moved out of all tools */
2124 TOOLTIPS_Hide(infoPtr
);
2125 KillTimer(infoPtr
->hwndSelf
, ID_TIMERLEAVE
);
2126 } else if (nOldTool
== -1) { /* Moved from outside */
2127 ERR("How did this happen?\n");
2128 } else { /* Moved from one to another */
2129 TOOLTIPS_Hide (infoPtr
);
2130 KillTimer(infoPtr
->hwndSelf
, ID_TIMERLEAVE
);
2131 if(infoPtr
->bActive
) {
2132 SetTimer (infoPtr
->hwndSelf
, ID_TIMERSHOW
, infoPtr
->nReshowTime
, 0);
2133 TRACE("timer 1 started!\n");
2140 ERR("Unknown timer id %d\n", iTimer
);
2148 TOOLTIPS_WinIniChange (TOOLTIPS_INFO
*infoPtr
)
2150 TOOLTIPS_InitSystemSettings (infoPtr
);
2156 static LRESULT CALLBACK
2157 TOOLTIPS_SubclassProc (HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
, UINT_PTR uID
, DWORD_PTR dwRef
)
2159 TOOLTIPS_INFO
*infoPtr
= TOOLTIPS_GetInfoPtr ((HWND
)dwRef
);
2164 case WM_LBUTTONDOWN
:
2166 case WM_MBUTTONDOWN
:
2168 case WM_RBUTTONDOWN
:
2172 msg
.wParam
= wParam
;
2173 msg
.lParam
= lParam
;
2174 TOOLTIPS_RelayEvent(infoPtr
, &msg
);
2180 return DefSubclassProc(hwnd
, uMsg
, wParam
, lParam
);
2184 static LRESULT CALLBACK
2185 TOOLTIPS_WindowProc (HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
2187 TOOLTIPS_INFO
*infoPtr
= TOOLTIPS_GetInfoPtr (hwnd
);
2189 TRACE("hwnd=%p msg=%x wparam=%lx lParam=%lx\n", hwnd
, uMsg
, wParam
, lParam
);
2190 if (!infoPtr
&& (uMsg
!= WM_CREATE
) && (uMsg
!= WM_NCCREATE
))
2191 return DefWindowProcW (hwnd
, uMsg
, wParam
, lParam
);
2195 return TOOLTIPS_Activate (infoPtr
, (BOOL
)wParam
);
2199 return TOOLTIPS_AddToolT (infoPtr
, (LPTTTOOLINFOW
)lParam
, uMsg
== TTM_ADDTOOLW
);
2203 return TOOLTIPS_DelToolT (infoPtr
, (LPTOOLINFOW
)lParam
,
2204 uMsg
== TTM_DELTOOLW
);
2205 case TTM_ENUMTOOLSA
:
2206 case TTM_ENUMTOOLSW
:
2207 return TOOLTIPS_EnumToolsT (infoPtr
, (UINT
)wParam
, (LPTTTOOLINFOW
)lParam
,
2208 uMsg
== TTM_ENUMTOOLSW
);
2209 case TTM_GETBUBBLESIZE
:
2210 return TOOLTIPS_GetBubbleSize (infoPtr
, (LPTTTOOLINFOW
)lParam
);
2212 case TTM_GETCURRENTTOOLA
:
2213 case TTM_GETCURRENTTOOLW
:
2214 return TOOLTIPS_GetCurrentToolT (infoPtr
, (LPTTTOOLINFOW
)lParam
,
2215 uMsg
== TTM_GETCURRENTTOOLW
);
2217 case TTM_GETDELAYTIME
:
2218 return TOOLTIPS_GetDelayTime (infoPtr
, (DWORD
)wParam
);
2221 return TOOLTIPS_GetMargin (infoPtr
, (LPRECT
)lParam
);
2223 case TTM_GETMAXTIPWIDTH
:
2224 return TOOLTIPS_GetMaxTipWidth (infoPtr
);
2228 return TOOLTIPS_GetTextT (infoPtr
, (LPTTTOOLINFOW
)lParam
,
2229 uMsg
== TTM_GETTEXTW
);
2231 case TTM_GETTIPBKCOLOR
:
2232 return TOOLTIPS_GetTipBkColor (infoPtr
);
2234 case TTM_GETTIPTEXTCOLOR
:
2235 return TOOLTIPS_GetTipTextColor (infoPtr
);
2237 case TTM_GETTOOLCOUNT
:
2238 return TOOLTIPS_GetToolCount (infoPtr
);
2240 case TTM_GETTOOLINFOA
:
2241 case TTM_GETTOOLINFOW
:
2242 return TOOLTIPS_GetToolInfoT (infoPtr
, (LPTTTOOLINFOW
)lParam
,
2243 uMsg
== TTM_GETTOOLINFOW
);
2247 return TOOLTIPS_HitTestT (infoPtr
, (LPTTHITTESTINFOW
)lParam
,
2248 uMsg
== TTM_HITTESTW
);
2249 case TTM_NEWTOOLRECTA
:
2250 case TTM_NEWTOOLRECTW
:
2251 return TOOLTIPS_NewToolRectT (infoPtr
, (LPTTTOOLINFOW
)lParam
);
2254 return TOOLTIPS_Pop (infoPtr
);
2256 case TTM_RELAYEVENT
:
2257 return TOOLTIPS_RelayEvent (infoPtr
, (LPMSG
)lParam
);
2259 case TTM_SETDELAYTIME
:
2260 return TOOLTIPS_SetDelayTime (infoPtr
, (DWORD
)wParam
, (INT
)LOWORD(lParam
));
2263 return TOOLTIPS_SetMargin (infoPtr
, (LPRECT
)lParam
);
2265 case TTM_SETMAXTIPWIDTH
:
2266 return TOOLTIPS_SetMaxTipWidth (infoPtr
, (INT
)lParam
);
2268 case TTM_SETTIPBKCOLOR
:
2269 return TOOLTIPS_SetTipBkColor (infoPtr
, (COLORREF
)wParam
);
2271 case TTM_SETTIPTEXTCOLOR
:
2272 return TOOLTIPS_SetTipTextColor (infoPtr
, (COLORREF
)wParam
);
2276 return TOOLTIPS_SetTitleT (infoPtr
, (UINT_PTR
)wParam
, (LPCWSTR
)lParam
,
2277 uMsg
== TTM_SETTITLEW
);
2279 case TTM_SETTOOLINFOA
:
2280 case TTM_SETTOOLINFOW
:
2281 return TOOLTIPS_SetToolInfoT (infoPtr
, (LPTTTOOLINFOW
)lParam
,
2282 uMsg
== TTM_SETTOOLINFOW
);
2284 case TTM_TRACKACTIVATE
:
2285 return TOOLTIPS_TrackActivate (infoPtr
, (BOOL
)wParam
, (LPTTTOOLINFOA
)lParam
);
2287 case TTM_TRACKPOSITION
:
2288 return TOOLTIPS_TrackPosition (infoPtr
, lParam
);
2291 return TOOLTIPS_Update (infoPtr
);
2293 case TTM_UPDATETIPTEXTA
:
2294 case TTM_UPDATETIPTEXTW
:
2295 return TOOLTIPS_UpdateTipTextT (infoPtr
, (LPTTTOOLINFOW
)lParam
,
2296 uMsg
== TTM_UPDATETIPTEXTW
);
2298 case TTM_WINDOWFROMPOINT
:
2299 return (LRESULT
)WindowFromPoint (*((LPPOINT
)lParam
));
2302 return TOOLTIPS_Create (hwnd
);
2305 return TOOLTIPS_Destroy (infoPtr
);
2308 /* we draw the background in WM_PAINT */
2312 return TOOLTIPS_GetFont (infoPtr
);
2315 return TOOLTIPS_OnWMGetText (infoPtr
, wParam
, (LPWSTR
)lParam
);
2317 case WM_GETTEXTLENGTH
:
2318 return TOOLTIPS_GetTextLength (infoPtr
);
2320 case WM_LBUTTONDOWN
:
2322 case WM_MBUTTONDOWN
:
2324 case WM_RBUTTONDOWN
:
2327 return TOOLTIPS_MouseMessage (infoPtr
);
2330 return TOOLTIPS_NCCreate (hwnd
);
2333 return TOOLTIPS_NCHitTest (infoPtr
, wParam
, lParam
);
2335 case WM_NOTIFYFORMAT
:
2336 return TOOLTIPS_NotifyFormat (infoPtr
, wParam
, lParam
);
2338 case WM_PRINTCLIENT
:
2340 return TOOLTIPS_Paint (infoPtr
, (HDC
)wParam
);
2343 return TOOLTIPS_SetFont (infoPtr
, (HFONT
)wParam
, LOWORD(lParam
));
2345 case WM_SYSCOLORCHANGE
:
2346 COMCTL32_RefreshSysColors();
2350 return TOOLTIPS_Timer (infoPtr
, (INT
)wParam
);
2352 case WM_WININICHANGE
:
2353 return TOOLTIPS_WinIniChange (infoPtr
);
2356 if ((uMsg
>= WM_USER
) && (uMsg
< WM_APP
) && !COMCTL32_IsReflectedMessage(uMsg
))
2357 ERR("unknown msg %04x wp=%08lx lp=%08lx\n",
2358 uMsg
, wParam
, lParam
);
2359 return DefWindowProcW (hwnd
, uMsg
, wParam
, lParam
);
2365 TOOLTIPS_Register (void)
2369 ZeroMemory (&wndClass
, sizeof(WNDCLASSW
));
2370 wndClass
.style
= CS_GLOBALCLASS
| CS_DBLCLKS
| CS_SAVEBITS
;
2371 wndClass
.lpfnWndProc
= TOOLTIPS_WindowProc
;
2372 wndClass
.cbClsExtra
= 0;
2373 wndClass
.cbWndExtra
= sizeof(TOOLTIPS_INFO
*);
2374 wndClass
.hCursor
= LoadCursorW (0, (LPWSTR
)IDC_ARROW
);
2375 wndClass
.hbrBackground
= 0;
2376 wndClass
.lpszClassName
= TOOLTIPS_CLASSW
;
2378 RegisterClassW (&wndClass
);
2380 hTooltipIcons
[TTI_NONE
] = NULL
;
2381 hTooltipIcons
[TTI_INFO
] = LoadImageW(COMCTL32_hModule
,
2382 (LPCWSTR
)MAKEINTRESOURCE(IDI_TT_INFO_SM
), IMAGE_ICON
, 0, 0, 0);
2383 hTooltipIcons
[TTI_WARNING
] = LoadImageW(COMCTL32_hModule
,
2384 (LPCWSTR
)MAKEINTRESOURCE(IDI_TT_WARN_SM
), IMAGE_ICON
, 0, 0, 0);
2385 hTooltipIcons
[TTI_ERROR
] = LoadImageW(COMCTL32_hModule
,
2386 (LPCWSTR
)MAKEINTRESOURCE(IDI_TT_ERROR_SM
), IMAGE_ICON
, 0, 0, 0);
2391 TOOLTIPS_Unregister (void)
2394 for (i
= TTI_INFO
; i
<= TTI_ERROR
; i
++)
2395 DestroyIcon(hTooltipIcons
[i
]);
2396 UnregisterClassW (TOOLTIPS_CLASSW
, NULL
);