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];
127 WCHAR szTipText
[INFOTIPSIZE
];
138 INT nTool
; /* tool that mouse was on on last relayed mouse move */
152 #define ID_TIMERSHOW 1 /* show delay timer */
153 #define ID_TIMERPOP 2 /* auto pop timer */
154 #define ID_TIMERLEAVE 3 /* tool leave timer */
157 #define TOOLTIPS_GetInfoPtr(hWindow) ((TOOLTIPS_INFO *)GetWindowLongPtrW (hWindow, 0))
159 /* offsets from window edge to start of text */
160 #define NORMAL_TEXT_MARGIN 2
161 #define BALLOON_TEXT_MARGIN (NORMAL_TEXT_MARGIN+8)
162 /* value used for CreateRoundRectRgn that specifies how much
163 * each corner is curved */
164 #define BALLOON_ROUNDEDNESS 20
165 #define BALLOON_STEMHEIGHT 13
166 #define BALLOON_STEMWIDTH 10
167 #define BALLOON_STEMINDENT 20
169 #define BALLOON_ICON_TITLE_SPACING 8 /* horizontal spacing between icon and title */
170 #define BALLOON_TITLE_TEXT_SPACING 8 /* vertical spacing between icon/title and main text */
171 #define ICON_HEIGHT 16
172 #define ICON_WIDTH 16
174 #define MAX_TEXT_SIZE_A 80 /* maximum retrieving text size by ANSI message */
176 static LRESULT CALLBACK
177 TOOLTIPS_SubclassProc (HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
, UINT_PTR uId
, DWORD_PTR dwRef
);
180 static inline BOOL
TOOLTIPS_IsCallbackString(LPCWSTR str
, BOOL isW
)
183 return str
== LPSTR_TEXTCALLBACKW
;
185 return (LPCSTR
)str
== LPSTR_TEXTCALLBACKA
;
188 static inline UINT_PTR
189 TOOLTIPS_GetTitleIconIndex(HICON hIcon
)
192 for (i
= 0; i
<= TTI_ERROR
; i
++)
193 if (hTooltipIcons
[i
] == hIcon
)
195 return (UINT_PTR
)hIcon
;
199 TOOLTIPS_InitSystemSettings (TOOLTIPS_INFO
*infoPtr
)
201 NONCLIENTMETRICSW nclm
;
203 infoPtr
->clrBk
= comctl32_color
.clrInfoBk
;
204 infoPtr
->clrText
= comctl32_color
.clrInfoText
;
206 DeleteObject (infoPtr
->hFont
);
207 nclm
.cbSize
= sizeof(nclm
);
208 SystemParametersInfoW (SPI_GETNONCLIENTMETRICS
, sizeof(nclm
), &nclm
, 0);
209 infoPtr
->hFont
= CreateFontIndirectW (&nclm
.lfStatusFont
);
211 DeleteObject (infoPtr
->hTitleFont
);
212 nclm
.lfStatusFont
.lfWeight
= FW_BOLD
;
213 infoPtr
->hTitleFont
= CreateFontIndirectW (&nclm
.lfStatusFont
);
216 /* Custom draw routines */
218 TOOLTIPS_customdraw_fill(const TOOLTIPS_INFO
*infoPtr
, NMTTCUSTOMDRAW
*lpnmttcd
,
219 HDC hdc
, const RECT
*rcBounds
, UINT uFlags
)
221 ZeroMemory(lpnmttcd
, sizeof(NMTTCUSTOMDRAW
));
222 lpnmttcd
->uDrawFlags
= uFlags
;
223 lpnmttcd
->nmcd
.hdr
.hwndFrom
= infoPtr
->hwndSelf
;
224 lpnmttcd
->nmcd
.hdr
.code
= NM_CUSTOMDRAW
;
225 if (infoPtr
->nCurrentTool
!= -1) {
226 TTTOOL_INFO
*toolPtr
= &infoPtr
->tools
[infoPtr
->nCurrentTool
];
227 lpnmttcd
->nmcd
.hdr
.idFrom
= toolPtr
->uId
;
229 lpnmttcd
->nmcd
.hdc
= hdc
;
230 lpnmttcd
->nmcd
.rc
= *rcBounds
;
231 /* FIXME - dwItemSpec, uItemState, lItemlParam */
235 TOOLTIPS_notify_customdraw (DWORD dwDrawStage
, NMTTCUSTOMDRAW
*lpnmttcd
)
237 LRESULT result
= CDRF_DODEFAULT
;
238 lpnmttcd
->nmcd
.dwDrawStage
= dwDrawStage
;
240 TRACE("Notifying stage %d, flags %x, id %x\n", lpnmttcd
->nmcd
.dwDrawStage
,
241 lpnmttcd
->uDrawFlags
, lpnmttcd
->nmcd
.hdr
.code
);
243 result
= SendMessageW(GetParent(lpnmttcd
->nmcd
.hdr
.hwndFrom
), WM_NOTIFY
,
244 0, (LPARAM
)lpnmttcd
);
246 TRACE("Notify result %x\n", (unsigned int)result
);
252 TOOLTIPS_Refresh (const TOOLTIPS_INFO
*infoPtr
, HDC hdc
)
258 UINT uFlags
= DT_EXTERNALLEADING
;
260 DWORD dwStyle
= GetWindowLongW(infoPtr
->hwndSelf
, GWL_STYLE
);
261 NMTTCUSTOMDRAW nmttcd
;
264 if (infoPtr
->nMaxTipWidth
> -1)
265 uFlags
|= DT_WORDBREAK
;
266 if (GetWindowLongW (infoPtr
->hwndSelf
, GWL_STYLE
) & TTS_NOPREFIX
)
267 uFlags
|= DT_NOPREFIX
;
268 GetClientRect (infoPtr
->hwndSelf
, &rc
);
270 hBrush
= CreateSolidBrush(infoPtr
->clrBk
);
272 oldBkMode
= SetBkMode (hdc
, TRANSPARENT
);
273 SetTextColor (hdc
, infoPtr
->clrText
);
274 hOldFont
= SelectObject (hdc
, infoPtr
->hFont
);
276 /* Custom draw - Call PrePaint once initial properties set up */
277 /* Note: Contrary to MSDN, CDRF_SKIPDEFAULT still draws a tooltip */
278 TOOLTIPS_customdraw_fill(infoPtr
, &nmttcd
, hdc
, &rc
, uFlags
);
279 cdmode
= TOOLTIPS_notify_customdraw(CDDS_PREPAINT
, &nmttcd
);
280 uFlags
= nmttcd
.uDrawFlags
;
282 if (dwStyle
& TTS_BALLOON
)
284 /* create a region to store result into */
285 hRgn
= CreateRectRgn(0, 0, 0, 0);
287 GetWindowRgn(infoPtr
->hwndSelf
, hRgn
);
289 /* fill the background */
290 FillRgn(hdc
, hRgn
, hBrush
);
291 DeleteObject(hBrush
);
296 /* fill the background */
297 FillRect(hdc
, &rc
, hBrush
);
298 DeleteObject(hBrush
);
302 if ((dwStyle
& TTS_BALLOON
) || infoPtr
->pszTitle
)
304 /* calculate text rectangle */
305 rc
.left
+= (BALLOON_TEXT_MARGIN
+ infoPtr
->rcMargin
.left
);
306 rc
.top
+= (BALLOON_TEXT_MARGIN
+ infoPtr
->rcMargin
.top
);
307 rc
.right
-= (BALLOON_TEXT_MARGIN
+ infoPtr
->rcMargin
.right
);
308 rc
.bottom
-= (BALLOON_TEXT_MARGIN
+ infoPtr
->rcMargin
.bottom
);
309 if(infoPtr
->bToolBelow
) rc
.top
+= BALLOON_STEMHEIGHT
;
311 if (infoPtr
->pszTitle
)
313 RECT rcTitle
= {rc
.left
, rc
.top
, rc
.right
, rc
.bottom
};
319 icon_present
= infoPtr
->hTitleIcon
&&
320 DrawIconEx(hdc
, rc
.left
, rc
.top
, infoPtr
->hTitleIcon
,
321 ICON_WIDTH
, ICON_HEIGHT
, 0, NULL
, DI_NORMAL
);
323 rcTitle
.left
+= ICON_WIDTH
+ BALLOON_ICON_TITLE_SPACING
;
325 rcTitle
.bottom
= rc
.top
+ ICON_HEIGHT
;
327 /* draw title text */
328 prevFont
= SelectObject (hdc
, infoPtr
->hTitleFont
);
329 height
= DrawTextW(hdc
, infoPtr
->pszTitle
, -1, &rcTitle
, DT_BOTTOM
| DT_SINGLELINE
| DT_NOPREFIX
);
330 SelectObject (hdc
, prevFont
);
331 rc
.top
+= height
+ BALLOON_TITLE_TEXT_SPACING
;
336 /* calculate text rectangle */
337 rc
.left
+= (NORMAL_TEXT_MARGIN
+ infoPtr
->rcMargin
.left
);
338 rc
.top
+= (NORMAL_TEXT_MARGIN
+ infoPtr
->rcMargin
.top
);
339 rc
.right
-= (NORMAL_TEXT_MARGIN
+ infoPtr
->rcMargin
.right
);
340 rc
.bottom
-= (NORMAL_TEXT_MARGIN
+ infoPtr
->rcMargin
.bottom
);
344 DrawTextW (hdc
, infoPtr
->szTipText
, -1, &rc
, uFlags
);
346 /* Custom draw - Call PostPaint after drawing */
347 if (cdmode
& CDRF_NOTIFYPOSTPAINT
) {
348 TOOLTIPS_notify_customdraw(CDDS_POSTPAINT
, &nmttcd
);
351 /* be polite and reset the things we changed in the dc */
352 SelectObject (hdc
, hOldFont
);
353 SetBkMode (hdc
, oldBkMode
);
355 if (dwStyle
& TTS_BALLOON
)
357 /* frame region because default window proc doesn't do it */
358 INT width
= GetSystemMetrics(SM_CXDLGFRAME
) - GetSystemMetrics(SM_CXEDGE
);
359 INT height
= GetSystemMetrics(SM_CYDLGFRAME
) - GetSystemMetrics(SM_CYEDGE
);
361 hBrush
= GetSysColorBrush(COLOR_WINDOWFRAME
);
362 FrameRgn(hdc
, hRgn
, hBrush
, width
, height
);
369 static void TOOLTIPS_GetDispInfoA(const TOOLTIPS_INFO
*infoPtr
, TTTOOL_INFO
*toolPtr
, WCHAR
*buffer
)
371 NMTTDISPINFOA ttnmdi
;
373 /* fill NMHDR struct */
374 ZeroMemory (&ttnmdi
, sizeof(NMTTDISPINFOA
));
375 ttnmdi
.hdr
.hwndFrom
= infoPtr
->hwndSelf
;
376 ttnmdi
.hdr
.idFrom
= toolPtr
->uId
;
377 ttnmdi
.hdr
.code
= TTN_GETDISPINFOA
; /* == TTN_NEEDTEXTA */
378 ttnmdi
.lpszText
= ttnmdi
.szText
;
379 ttnmdi
.uFlags
= toolPtr
->uFlags
;
380 ttnmdi
.lParam
= toolPtr
->lParam
;
382 TRACE("hdr.idFrom = %lx\n", ttnmdi
.hdr
.idFrom
);
383 SendMessageW(toolPtr
->hwnd
, WM_NOTIFY
, toolPtr
->uId
, (LPARAM
)&ttnmdi
);
385 if (IS_INTRESOURCE(ttnmdi
.lpszText
)) {
386 LoadStringW(ttnmdi
.hinst
, LOWORD(ttnmdi
.lpszText
),
387 buffer
, INFOTIPSIZE
);
388 if (ttnmdi
.uFlags
& TTF_DI_SETITEM
) {
389 toolPtr
->hinst
= ttnmdi
.hinst
;
390 toolPtr
->lpszText
= (LPWSTR
)ttnmdi
.lpszText
;
393 else if (ttnmdi
.lpszText
== 0) {
396 else if (ttnmdi
.lpszText
!= LPSTR_TEXTCALLBACKA
) {
397 Str_GetPtrAtoW(ttnmdi
.lpszText
, buffer
, INFOTIPSIZE
);
398 if (ttnmdi
.uFlags
& TTF_DI_SETITEM
) {
400 toolPtr
->lpszText
= NULL
;
401 Str_SetPtrW(&toolPtr
->lpszText
, buffer
);
405 ERR("recursive text callback!\n");
409 /* no text available - try calling parent instead as per native */
410 /* FIXME: Unsure if SETITEM should save the value or not */
411 if (buffer
[0] == 0x00) {
413 SendMessageW(GetParent(toolPtr
->hwnd
), WM_NOTIFY
, toolPtr
->uId
, (LPARAM
)&ttnmdi
);
415 if (IS_INTRESOURCE(ttnmdi
.lpszText
)) {
416 LoadStringW(ttnmdi
.hinst
, LOWORD(ttnmdi
.lpszText
),
417 buffer
, INFOTIPSIZE
);
418 } else if (ttnmdi
.lpszText
&&
419 ttnmdi
.lpszText
!= LPSTR_TEXTCALLBACKA
) {
420 Str_GetPtrAtoW(ttnmdi
.lpszText
, buffer
, INFOTIPSIZE
);
425 static void TOOLTIPS_GetDispInfoW(const TOOLTIPS_INFO
*infoPtr
, TTTOOL_INFO
*toolPtr
, WCHAR
*buffer
)
427 NMTTDISPINFOW ttnmdi
;
429 /* fill NMHDR struct */
430 ZeroMemory (&ttnmdi
, sizeof(NMTTDISPINFOW
));
431 ttnmdi
.hdr
.hwndFrom
= infoPtr
->hwndSelf
;
432 ttnmdi
.hdr
.idFrom
= toolPtr
->uId
;
433 ttnmdi
.hdr
.code
= TTN_GETDISPINFOW
; /* == TTN_NEEDTEXTW */
434 ttnmdi
.lpszText
= ttnmdi
.szText
;
435 ttnmdi
.uFlags
= toolPtr
->uFlags
;
436 ttnmdi
.lParam
= toolPtr
->lParam
;
438 TRACE("hdr.idFrom = %lx\n", ttnmdi
.hdr
.idFrom
);
439 SendMessageW(toolPtr
->hwnd
, WM_NOTIFY
, toolPtr
->uId
, (LPARAM
)&ttnmdi
);
441 if (IS_INTRESOURCE(ttnmdi
.lpszText
)) {
442 LoadStringW(ttnmdi
.hinst
, LOWORD(ttnmdi
.lpszText
),
443 buffer
, INFOTIPSIZE
);
444 if (ttnmdi
.uFlags
& TTF_DI_SETITEM
) {
445 toolPtr
->hinst
= ttnmdi
.hinst
;
446 toolPtr
->lpszText
= ttnmdi
.lpszText
;
449 else if (ttnmdi
.lpszText
== 0) {
452 else if (ttnmdi
.lpszText
!= LPSTR_TEXTCALLBACKW
) {
453 Str_GetPtrW(ttnmdi
.lpszText
, buffer
, INFOTIPSIZE
);
454 if (ttnmdi
.uFlags
& TTF_DI_SETITEM
) {
456 toolPtr
->lpszText
= NULL
;
457 Str_SetPtrW(&toolPtr
->lpszText
, buffer
);
461 ERR("recursive text callback!\n");
465 /* no text available - try calling parent instead as per native */
466 /* FIXME: Unsure if SETITEM should save the value or not */
467 if (buffer
[0] == 0x00) {
469 SendMessageW(GetParent(toolPtr
->hwnd
), WM_NOTIFY
, toolPtr
->uId
, (LPARAM
)&ttnmdi
);
471 if (IS_INTRESOURCE(ttnmdi
.lpszText
)) {
472 LoadStringW(ttnmdi
.hinst
, LOWORD(ttnmdi
.lpszText
),
473 buffer
, INFOTIPSIZE
);
474 } else if (ttnmdi
.lpszText
&&
475 ttnmdi
.lpszText
!= LPSTR_TEXTCALLBACKW
) {
476 Str_GetPtrW(ttnmdi
.lpszText
, buffer
, INFOTIPSIZE
);
483 TOOLTIPS_GetTipText (const TOOLTIPS_INFO
*infoPtr
, INT nTool
, WCHAR
*buffer
)
485 TTTOOL_INFO
*toolPtr
= &infoPtr
->tools
[nTool
];
487 if (IS_INTRESOURCE(toolPtr
->lpszText
) && toolPtr
->hinst
) {
488 /* load a resource */
489 TRACE("load res string %p %x\n",
490 toolPtr
->hinst
, LOWORD(toolPtr
->lpszText
));
491 LoadStringW (toolPtr
->hinst
, LOWORD(toolPtr
->lpszText
),
492 buffer
, INFOTIPSIZE
);
494 else if (toolPtr
->lpszText
) {
495 if (toolPtr
->lpszText
== LPSTR_TEXTCALLBACKW
) {
496 if (toolPtr
->bNotifyUnicode
)
497 TOOLTIPS_GetDispInfoW(infoPtr
, toolPtr
, buffer
);
499 TOOLTIPS_GetDispInfoA(infoPtr
, toolPtr
, buffer
);
502 /* the item is a usual (unicode) text */
503 lstrcpynW (buffer
, toolPtr
->lpszText
, INFOTIPSIZE
);
507 /* no text available */
511 TRACE("%s\n", debugstr_w(buffer
));
516 TOOLTIPS_CalcTipSize (const TOOLTIPS_INFO
*infoPtr
, LPSIZE lpSize
)
520 DWORD style
= GetWindowLongW(infoPtr
->hwndSelf
, GWL_STYLE
);
521 UINT uFlags
= DT_EXTERNALLEADING
| DT_CALCRECT
;
522 RECT rc
= {0, 0, 0, 0};
525 if (infoPtr
->nMaxTipWidth
> -1) {
526 rc
.right
= infoPtr
->nMaxTipWidth
;
527 uFlags
|= DT_WORDBREAK
;
529 if (style
& TTS_NOPREFIX
)
530 uFlags
|= DT_NOPREFIX
;
531 TRACE("%s\n", debugstr_w(infoPtr
->szTipText
));
533 hdc
= GetDC (infoPtr
->hwndSelf
);
534 if (infoPtr
->pszTitle
)
536 RECT rcTitle
= {0, 0, 0, 0};
537 TRACE("title %s\n", debugstr_w(infoPtr
->pszTitle
));
538 if (infoPtr
->hTitleIcon
)
540 title
.cx
= ICON_WIDTH
;
541 title
.cy
= ICON_HEIGHT
;
543 if (title
.cx
!= 0) title
.cx
+= BALLOON_ICON_TITLE_SPACING
;
544 hOldFont
= SelectObject (hdc
, infoPtr
->hTitleFont
);
545 DrawTextW(hdc
, infoPtr
->pszTitle
, -1, &rcTitle
, DT_SINGLELINE
| DT_NOPREFIX
| DT_CALCRECT
);
546 SelectObject (hdc
, hOldFont
);
547 title
.cy
= max(title
.cy
, rcTitle
.bottom
- rcTitle
.top
) + BALLOON_TITLE_TEXT_SPACING
;
548 title
.cx
+= (rcTitle
.right
- rcTitle
.left
);
550 hOldFont
= SelectObject (hdc
, infoPtr
->hFont
);
551 DrawTextW (hdc
, infoPtr
->szTipText
, -1, &rc
, uFlags
);
552 SelectObject (hdc
, hOldFont
);
553 ReleaseDC (infoPtr
->hwndSelf
, hdc
);
555 if ((style
& TTS_BALLOON
) || infoPtr
->pszTitle
)
557 lpSize
->cx
= max(rc
.right
- rc
.left
, title
.cx
) + 2*BALLOON_TEXT_MARGIN
+
558 infoPtr
->rcMargin
.left
+ infoPtr
->rcMargin
.right
;
559 lpSize
->cy
= title
.cy
+ rc
.bottom
- rc
.top
+ 2*BALLOON_TEXT_MARGIN
+
560 infoPtr
->rcMargin
.bottom
+ infoPtr
->rcMargin
.top
+
565 lpSize
->cx
= rc
.right
- rc
.left
+ 2*NORMAL_TEXT_MARGIN
+
566 infoPtr
->rcMargin
.left
+ infoPtr
->rcMargin
.right
;
567 lpSize
->cy
= rc
.bottom
- rc
.top
+ 2*NORMAL_TEXT_MARGIN
+
568 infoPtr
->rcMargin
.bottom
+ infoPtr
->rcMargin
.top
;
574 TOOLTIPS_Show (TOOLTIPS_INFO
*infoPtr
, BOOL track_activate
)
576 TTTOOL_INFO
*toolPtr
;
578 MONITORINFO mon_info
;
583 DWORD style
= GetWindowLongW(infoPtr
->hwndSelf
, GWL_STYLE
);
588 if (infoPtr
->nTrackTool
== -1)
590 TRACE("invalid tracking tool (-1)!\n");
593 nTool
= infoPtr
->nTrackTool
;
597 if (infoPtr
->nTool
== -1)
599 TRACE("invalid tool (-1)!\n");
602 nTool
= infoPtr
->nTool
;
605 TRACE("Show tooltip pre %d! (%p)\n", nTool
, infoPtr
->hwndSelf
);
607 TOOLTIPS_GetTipText (infoPtr
, nTool
, infoPtr
->szTipText
);
609 if (infoPtr
->szTipText
[0] == '\0')
612 toolPtr
= &infoPtr
->tools
[nTool
];
615 infoPtr
->nCurrentTool
= infoPtr
->nTool
;
617 TRACE("Show tooltip %d!\n", nTool
);
619 hdr
.hwndFrom
= infoPtr
->hwndSelf
;
620 hdr
.idFrom
= toolPtr
->uId
;
622 SendMessageW (toolPtr
->hwnd
, WM_NOTIFY
, toolPtr
->uId
, (LPARAM
)&hdr
);
624 TRACE("%s\n", debugstr_w(infoPtr
->szTipText
));
626 TOOLTIPS_CalcTipSize (infoPtr
, &size
);
627 TRACE("size %d x %d\n", size
.cx
, size
.cy
);
631 rect
.left
= infoPtr
->xTrackPos
;
632 rect
.top
= infoPtr
->yTrackPos
;
635 if (toolPtr
->uFlags
& TTF_CENTERTIP
)
637 rect
.left
-= (size
.cx
/ 2);
638 if (!(style
& TTS_BALLOON
))
639 rect
.top
-= (size
.cy
/ 2);
641 if (!(infoPtr
->bToolBelow
= (infoPtr
->yTrackPos
+ size
.cy
<= GetSystemMetrics(SM_CYSCREEN
))))
644 if (!(toolPtr
->uFlags
& TTF_ABSOLUTE
))
646 if (style
& TTS_BALLOON
)
647 rect
.left
-= BALLOON_STEMINDENT
;
652 if (toolPtr
->uFlags
& TTF_IDISHWND
)
653 GetWindowRect ((HWND
)toolPtr
->uId
, &rcTool
);
656 rcTool
= toolPtr
->rect
;
657 MapWindowPoints (toolPtr
->hwnd
, NULL
, (LPPOINT
)&rcTool
, 2);
660 /* smart placement */
661 if ((rect
.left
+ size
.cx
> rcTool
.left
) && (rect
.left
< rcTool
.right
) &&
662 (rect
.top
+ size
.cy
> rcTool
.top
) && (rect
.top
< rcTool
.bottom
))
663 rect
.left
= rcTool
.right
;
669 if (toolPtr
->uFlags
& TTF_CENTERTIP
)
673 if (toolPtr
->uFlags
& TTF_IDISHWND
)
674 GetWindowRect ((HWND
)toolPtr
->uId
, &rc
);
677 MapWindowPoints (toolPtr
->hwnd
, NULL
, (LPPOINT
)&rc
, 2);
679 rect
.left
= (rc
.left
+ rc
.right
- size
.cx
) / 2;
680 if (style
& TTS_BALLOON
)
682 ptfx
= rc
.left
+ ((rc
.right
- rc
.left
) / 2);
684 /* CENTERTIP ballon tooltips default to below the field
685 * if they fit on the screen */
686 if (rc
.bottom
+ size
.cy
> GetSystemMetrics(SM_CYSCREEN
))
688 rect
.top
= rc
.top
- size
.cy
;
689 infoPtr
->bToolBelow
= FALSE
;
693 infoPtr
->bToolBelow
= TRUE
;
694 rect
.top
= rc
.bottom
;
696 rect
.left
= max(0, rect
.left
- BALLOON_STEMINDENT
);
700 rect
.top
= rc
.bottom
+ 2;
701 infoPtr
->bToolBelow
= TRUE
;
706 GetCursorPos ((LPPOINT
)&rect
);
707 if (style
& TTS_BALLOON
)
710 if(rect
.top
- size
.cy
>= 0)
713 infoPtr
->bToolBelow
= FALSE
;
717 infoPtr
->bToolBelow
= TRUE
;
720 rect
.left
= max(0, rect
.left
- BALLOON_STEMINDENT
);
725 infoPtr
->bToolBelow
= TRUE
;
730 TRACE("pos %d - %d\n", rect
.left
, rect
.top
);
732 rect
.right
= rect
.left
+ size
.cx
;
733 rect
.bottom
= rect
.top
+ size
.cy
;
737 monitor
= MonitorFromRect( &rect
, MONITOR_DEFAULTTOPRIMARY
);
738 mon_info
.cbSize
= sizeof(mon_info
);
739 GetMonitorInfoW( monitor
, &mon_info
);
741 if( rect
.right
> mon_info
.rcWork
.right
) {
742 rect
.left
-= rect
.right
- mon_info
.rcWork
.right
+ 2;
743 rect
.right
= mon_info
.rcWork
.right
- 2;
745 if (rect
.left
< mon_info
.rcWork
.left
) rect
.left
= mon_info
.rcWork
.left
;
747 if( rect
.bottom
> mon_info
.rcWork
.bottom
) {
750 if (toolPtr
->uFlags
& TTF_IDISHWND
)
751 GetWindowRect ((HWND
)toolPtr
->uId
, &rc
);
754 MapWindowPoints (toolPtr
->hwnd
, NULL
, (LPPOINT
)&rc
, 2);
756 rect
.bottom
= rc
.top
- 2;
757 rect
.top
= rect
.bottom
- size
.cy
;
760 AdjustWindowRectEx (&rect
, GetWindowLongW (infoPtr
->hwndSelf
, GWL_STYLE
),
761 FALSE
, GetWindowLongW (infoPtr
->hwndSelf
, GWL_EXSTYLE
));
763 if (style
& TTS_BALLOON
)
771 if(infoPtr
->bToolBelow
)
775 pts
[1].x
= max(BALLOON_STEMINDENT
, ptfx
- (BALLOON_STEMWIDTH
/ 2));
776 pts
[1].y
= BALLOON_STEMHEIGHT
;
777 pts
[2].x
= pts
[1].x
+ BALLOON_STEMWIDTH
;
779 if(pts
[2].x
> (rect
.right
- rect
.left
) - BALLOON_STEMINDENT
)
781 pts
[2].x
= (rect
.right
- rect
.left
) - BALLOON_STEMINDENT
;
782 pts
[1].x
= pts
[2].x
- BALLOON_STEMWIDTH
;
787 pts
[0].x
= max(BALLOON_STEMINDENT
, ptfx
- (BALLOON_STEMWIDTH
/ 2));
788 pts
[0].y
= (rect
.bottom
- rect
.top
) - BALLOON_STEMHEIGHT
;
789 pts
[1].x
= pts
[0].x
+ BALLOON_STEMWIDTH
;
792 pts
[2].y
= (rect
.bottom
- rect
.top
);
793 if(pts
[1].x
> (rect
.right
- rect
.left
) - BALLOON_STEMINDENT
)
795 pts
[1].x
= (rect
.right
- rect
.left
) - BALLOON_STEMINDENT
;
796 pts
[0].x
= pts
[1].x
- BALLOON_STEMWIDTH
;
800 hrStem
= CreatePolygonRgn(pts
, sizeof(pts
) / sizeof(pts
[0]), ALTERNATE
);
802 hRgn
= CreateRoundRectRgn(0,
803 (infoPtr
->bToolBelow
? BALLOON_STEMHEIGHT
: 0),
804 rect
.right
- rect
.left
,
805 (infoPtr
->bToolBelow
? rect
.bottom
- rect
.top
: rect
.bottom
- rect
.top
- BALLOON_STEMHEIGHT
),
806 BALLOON_ROUNDEDNESS
, BALLOON_ROUNDEDNESS
);
808 CombineRgn(hRgn
, hRgn
, hrStem
, RGN_OR
);
809 DeleteObject(hrStem
);
811 SetWindowRgn(infoPtr
->hwndSelf
, hRgn
, FALSE
);
812 /* we don't free the region handle as the system deletes it when
813 * it is no longer needed */
816 SetWindowPos (infoPtr
->hwndSelf
, HWND_TOPMOST
, rect
.left
, rect
.top
,
817 rect
.right
- rect
.left
, rect
.bottom
- rect
.top
,
818 SWP_SHOWWINDOW
| SWP_NOACTIVATE
);
820 /* repaint the tooltip */
821 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
822 UpdateWindow(infoPtr
->hwndSelf
);
826 SetTimer (infoPtr
->hwndSelf
, ID_TIMERPOP
, infoPtr
->nAutoPopTime
, 0);
827 TRACE("timer 2 started!\n");
828 SetTimer (infoPtr
->hwndSelf
, ID_TIMERLEAVE
, infoPtr
->nReshowTime
, 0);
829 TRACE("timer 3 started!\n");
835 TOOLTIPS_Hide (TOOLTIPS_INFO
*infoPtr
)
837 TTTOOL_INFO
*toolPtr
;
840 TRACE("Hide tooltip %d! (%p)\n", infoPtr
->nCurrentTool
, infoPtr
->hwndSelf
);
842 if (infoPtr
->nCurrentTool
== -1)
845 toolPtr
= &infoPtr
->tools
[infoPtr
->nCurrentTool
];
846 KillTimer (infoPtr
->hwndSelf
, ID_TIMERPOP
);
848 hdr
.hwndFrom
= infoPtr
->hwndSelf
;
849 hdr
.idFrom
= toolPtr
->uId
;
851 SendMessageW (toolPtr
->hwnd
, WM_NOTIFY
, toolPtr
->uId
, (LPARAM
)&hdr
);
853 infoPtr
->nCurrentTool
= -1;
855 SetWindowPos (infoPtr
->hwndSelf
, HWND_TOP
, 0, 0, 0, 0,
856 SWP_NOZORDER
| SWP_HIDEWINDOW
| SWP_NOACTIVATE
);
861 TOOLTIPS_TrackShow (TOOLTIPS_INFO
*infoPtr
)
863 TOOLTIPS_Show(infoPtr
, TRUE
);
868 TOOLTIPS_TrackHide (const TOOLTIPS_INFO
*infoPtr
)
870 TTTOOL_INFO
*toolPtr
;
873 TRACE("hide tracking tooltip %d\n", infoPtr
->nTrackTool
);
875 if (infoPtr
->nTrackTool
== -1)
878 toolPtr
= &infoPtr
->tools
[infoPtr
->nTrackTool
];
880 hdr
.hwndFrom
= infoPtr
->hwndSelf
;
881 hdr
.idFrom
= toolPtr
->uId
;
883 SendMessageW (toolPtr
->hwnd
, WM_NOTIFY
, toolPtr
->uId
, (LPARAM
)&hdr
);
885 SetWindowPos (infoPtr
->hwndSelf
, HWND_TOP
, 0, 0, 0, 0,
886 SWP_NOZORDER
| SWP_HIDEWINDOW
| SWP_NOACTIVATE
);
889 /* Structure layout is the same for TTTOOLINFOW and TTTOOLINFOA,
890 this helper is used in both cases. */
892 TOOLTIPS_GetToolFromInfoT (const TOOLTIPS_INFO
*infoPtr
, const TTTOOLINFOW
*lpToolInfo
)
894 TTTOOL_INFO
*toolPtr
;
897 for (nTool
= 0; nTool
< infoPtr
->uNumTools
; nTool
++) {
898 toolPtr
= &infoPtr
->tools
[nTool
];
900 if (!(toolPtr
->uFlags
& TTF_IDISHWND
) &&
901 (lpToolInfo
->hwnd
== toolPtr
->hwnd
) &&
902 (lpToolInfo
->uId
== toolPtr
->uId
))
906 for (nTool
= 0; nTool
< infoPtr
->uNumTools
; nTool
++) {
907 toolPtr
= &infoPtr
->tools
[nTool
];
909 if ((toolPtr
->uFlags
& TTF_IDISHWND
) &&
910 (lpToolInfo
->uId
== toolPtr
->uId
))
919 TOOLTIPS_GetToolFromPoint (const TOOLTIPS_INFO
*infoPtr
, HWND hwnd
, const POINT
*lpPt
)
921 TTTOOL_INFO
*toolPtr
;
924 for (nTool
= 0; nTool
< infoPtr
->uNumTools
; nTool
++) {
925 toolPtr
= &infoPtr
->tools
[nTool
];
927 if (!(toolPtr
->uFlags
& TTF_IDISHWND
)) {
928 if (hwnd
!= toolPtr
->hwnd
)
930 if (!PtInRect (&toolPtr
->rect
, *lpPt
))
936 for (nTool
= 0; nTool
< infoPtr
->uNumTools
; nTool
++) {
937 toolPtr
= &infoPtr
->tools
[nTool
];
939 if (toolPtr
->uFlags
& TTF_IDISHWND
) {
940 if ((HWND
)toolPtr
->uId
== hwnd
)
949 TOOLTIPS_CopyInfoT (const TTTOOL_INFO
*toolPtr
, TTTOOLINFOW
*ti
, BOOL isW
)
952 if (toolPtr
->lpszText
== NULL
||
953 IS_INTRESOURCE(toolPtr
->lpszText
) ||
954 toolPtr
->lpszText
== LPSTR_TEXTCALLBACKW
)
955 ti
->lpszText
= toolPtr
->lpszText
;
957 strcpyW (ti
->lpszText
, toolPtr
->lpszText
);
959 /* ANSI version, the buffer is maximum 80 bytes without null. */
960 WideCharToMultiByte(CP_ACP
, 0, toolPtr
->lpszText
, -1,
961 (LPSTR
)ti
->lpszText
, MAX_TEXT_SIZE_A
, NULL
, NULL
);
966 TOOLTIPS_IsWindowActive (HWND hwnd
)
968 HWND hwndActive
= GetActiveWindow ();
971 if (hwndActive
== hwnd
)
973 return IsChild (hwndActive
, hwnd
);
978 TOOLTIPS_CheckTool (const TOOLTIPS_INFO
*infoPtr
, BOOL bShowTest
)
985 hwndTool
= (HWND
)SendMessageW (infoPtr
->hwndSelf
, TTM_WINDOWFROMPOINT
, 0, (LPARAM
)&pt
);
989 ScreenToClient (hwndTool
, &pt
);
990 nTool
= TOOLTIPS_GetToolFromPoint (infoPtr
, hwndTool
, &pt
);
994 if (!(GetWindowLongW (infoPtr
->hwndSelf
, GWL_STYLE
) & TTS_ALWAYSTIP
) && bShowTest
) {
995 if (!TOOLTIPS_IsWindowActive (GetWindow (infoPtr
->hwndSelf
, GW_OWNER
)))
999 TRACE("tool %d\n", nTool
);
1006 TOOLTIPS_Activate (TOOLTIPS_INFO
*infoPtr
, BOOL activate
)
1008 infoPtr
->bActive
= activate
;
1010 if (infoPtr
->bActive
)
1011 TRACE("activate!\n");
1013 if (!(infoPtr
->bActive
) && (infoPtr
->nCurrentTool
!= -1))
1014 TOOLTIPS_Hide (infoPtr
);
1021 TOOLTIPS_AddToolT (TOOLTIPS_INFO
*infoPtr
, const TTTOOLINFOW
*ti
, BOOL isW
)
1023 TTTOOL_INFO
*toolPtr
;
1026 if (!ti
) return FALSE
;
1028 TRACE("add tool (%p) %p %ld%s!\n",
1029 infoPtr
->hwndSelf
, ti
->hwnd
, ti
->uId
,
1030 (ti
->uFlags
& TTF_IDISHWND
) ? " TTF_IDISHWND" : "");
1032 if (infoPtr
->uNumTools
== 0) {
1033 infoPtr
->tools
= Alloc (sizeof(TTTOOL_INFO
));
1034 toolPtr
= infoPtr
->tools
;
1037 TTTOOL_INFO
*oldTools
= infoPtr
->tools
;
1039 Alloc (sizeof(TTTOOL_INFO
) * (infoPtr
->uNumTools
+ 1));
1040 memcpy (infoPtr
->tools
, oldTools
,
1041 infoPtr
->uNumTools
* sizeof(TTTOOL_INFO
));
1043 toolPtr
= &infoPtr
->tools
[infoPtr
->uNumTools
];
1046 infoPtr
->uNumTools
++;
1048 /* copy tool data */
1049 toolPtr
->uFlags
= ti
->uFlags
;
1050 toolPtr
->hwnd
= ti
->hwnd
;
1051 toolPtr
->uId
= ti
->uId
;
1052 toolPtr
->rect
= ti
->rect
;
1053 toolPtr
->hinst
= ti
->hinst
;
1055 if (IS_INTRESOURCE(ti
->lpszText
)) {
1056 TRACE("add string id %x\n", LOWORD(ti
->lpszText
));
1057 toolPtr
->lpszText
= ti
->lpszText
;
1059 else if (ti
->lpszText
) {
1060 if (TOOLTIPS_IsCallbackString(ti
->lpszText
, isW
)) {
1061 TRACE("add CALLBACK!\n");
1062 toolPtr
->lpszText
= LPSTR_TEXTCALLBACKW
;
1065 INT len
= lstrlenW (ti
->lpszText
);
1066 TRACE("add text %s!\n", debugstr_w(ti
->lpszText
));
1067 toolPtr
->lpszText
= Alloc ((len
+ 1)*sizeof(WCHAR
));
1068 strcpyW (toolPtr
->lpszText
, ti
->lpszText
);
1071 INT len
= MultiByteToWideChar(CP_ACP
, 0, (LPSTR
)ti
->lpszText
, -1, NULL
, 0);
1072 TRACE("add text \"%s\"!\n", (LPSTR
)ti
->lpszText
);
1073 toolPtr
->lpszText
= Alloc (len
* sizeof(WCHAR
));
1074 MultiByteToWideChar(CP_ACP
, 0, (LPSTR
)ti
->lpszText
, -1, toolPtr
->lpszText
, len
);
1078 if (ti
->cbSize
>= TTTOOLINFOW_V2_SIZE
)
1079 toolPtr
->lParam
= ti
->lParam
;
1081 /* install subclassing hook */
1082 if (toolPtr
->uFlags
& TTF_SUBCLASS
) {
1083 if (toolPtr
->uFlags
& TTF_IDISHWND
) {
1084 SetWindowSubclass((HWND
)toolPtr
->uId
, TOOLTIPS_SubclassProc
, 1,
1085 (DWORD_PTR
)infoPtr
->hwndSelf
);
1088 SetWindowSubclass(toolPtr
->hwnd
, TOOLTIPS_SubclassProc
, 1,
1089 (DWORD_PTR
)infoPtr
->hwndSelf
);
1091 TRACE("subclassing installed!\n");
1094 nResult
= SendMessageW (toolPtr
->hwnd
, WM_NOTIFYFORMAT
,
1095 (WPARAM
)infoPtr
->hwndSelf
, NF_QUERY
);
1096 if (nResult
== NFR_ANSI
) {
1097 toolPtr
->bNotifyUnicode
= FALSE
;
1098 TRACE(" -- WM_NOTIFYFORMAT returns: NFR_ANSI\n");
1099 } else if (nResult
== NFR_UNICODE
) {
1100 toolPtr
->bNotifyUnicode
= TRUE
;
1101 TRACE(" -- WM_NOTIFYFORMAT returns: NFR_UNICODE\n");
1103 TRACE (" -- WM_NOTIFYFORMAT returns: error!\n");
1111 TOOLTIPS_DelToolT (TOOLTIPS_INFO
*infoPtr
, const TTTOOLINFOW
*ti
, BOOL isW
)
1113 TTTOOL_INFO
*toolPtr
;
1117 if (isW
&& ti
->cbSize
> TTTOOLINFOW_V2_SIZE
&&
1118 ti
->cbSize
!= TTTOOLINFOW_V3_SIZE
)
1120 if (infoPtr
->uNumTools
== 0)
1123 nTool
= TOOLTIPS_GetToolFromInfoT (infoPtr
, ti
);
1125 TRACE("tool %d\n", nTool
);
1130 /* make sure the tooltip has disappeared before deleting it */
1131 TOOLTIPS_Hide(infoPtr
);
1133 /* delete text string */
1134 toolPtr
= &infoPtr
->tools
[nTool
];
1135 if (toolPtr
->lpszText
) {
1136 if ( (toolPtr
->lpszText
!= LPSTR_TEXTCALLBACKW
) &&
1137 !IS_INTRESOURCE(toolPtr
->lpszText
) )
1138 Free (toolPtr
->lpszText
);
1141 /* remove subclassing */
1142 if (toolPtr
->uFlags
& TTF_SUBCLASS
) {
1143 if (toolPtr
->uFlags
& TTF_IDISHWND
) {
1144 RemoveWindowSubclass((HWND
)toolPtr
->uId
, TOOLTIPS_SubclassProc
, 1);
1147 RemoveWindowSubclass(toolPtr
->hwnd
, TOOLTIPS_SubclassProc
, 1);
1151 /* delete tool from tool list */
1152 if (infoPtr
->uNumTools
== 1) {
1153 Free (infoPtr
->tools
);
1154 infoPtr
->tools
= NULL
;
1157 TTTOOL_INFO
*oldTools
= infoPtr
->tools
;
1159 Alloc (sizeof(TTTOOL_INFO
) * (infoPtr
->uNumTools
- 1));
1162 memcpy (&infoPtr
->tools
[0], &oldTools
[0],
1163 nTool
* sizeof(TTTOOL_INFO
));
1165 if (nTool
< infoPtr
->uNumTools
- 1)
1166 memcpy (&infoPtr
->tools
[nTool
], &oldTools
[nTool
+ 1],
1167 (infoPtr
->uNumTools
- nTool
- 1) * sizeof(TTTOOL_INFO
));
1172 /* update any indices affected by delete */
1174 /* destroying tool that mouse was on on last relayed mouse move */
1175 if (infoPtr
->nTool
== nTool
)
1176 /* -1 means no current tool (0 means first tool) */
1177 infoPtr
->nTool
= -1;
1178 else if (infoPtr
->nTool
> nTool
)
1181 if (infoPtr
->nTrackTool
== nTool
)
1182 /* -1 means no current tool (0 means first tool) */
1183 infoPtr
->nTrackTool
= -1;
1184 else if (infoPtr
->nTrackTool
> nTool
)
1185 infoPtr
->nTrackTool
--;
1187 if (infoPtr
->nCurrentTool
== nTool
)
1188 /* -1 means no current tool (0 means first tool) */
1189 infoPtr
->nCurrentTool
= -1;
1190 else if (infoPtr
->nCurrentTool
> nTool
)
1191 infoPtr
->nCurrentTool
--;
1193 infoPtr
->uNumTools
--;
1199 TOOLTIPS_EnumToolsT (const TOOLTIPS_INFO
*infoPtr
, UINT uIndex
, TTTOOLINFOW
*ti
,
1202 TTTOOL_INFO
*toolPtr
;
1204 if (!ti
) return FALSE
;
1205 if (ti
->cbSize
< TTTOOLINFOW_V1_SIZE
)
1207 if (uIndex
>= infoPtr
->uNumTools
)
1210 TRACE("index=%u\n", uIndex
);
1212 toolPtr
= &infoPtr
->tools
[uIndex
];
1214 /* copy tool data */
1215 ti
->uFlags
= toolPtr
->uFlags
;
1216 ti
->hwnd
= toolPtr
->hwnd
;
1217 ti
->uId
= toolPtr
->uId
;
1218 ti
->rect
= toolPtr
->rect
;
1219 ti
->hinst
= toolPtr
->hinst
;
1220 TOOLTIPS_CopyInfoT (toolPtr
, ti
, isW
);
1222 if (ti
->cbSize
>= TTTOOLINFOA_V2_SIZE
)
1223 ti
->lParam
= toolPtr
->lParam
;
1229 TOOLTIPS_GetBubbleSize (const TOOLTIPS_INFO
*infoPtr
, const TTTOOLINFOW
*lpToolInfo
)
1234 if (lpToolInfo
== NULL
)
1236 if (lpToolInfo
->cbSize
< TTTOOLINFOW_V1_SIZE
)
1239 nTool
= TOOLTIPS_GetToolFromInfoT (infoPtr
, lpToolInfo
);
1240 if (nTool
== -1) return 0;
1242 TRACE("tool %d\n", nTool
);
1244 TOOLTIPS_CalcTipSize (infoPtr
, &size
);
1245 TRACE("size %d x %d\n", size
.cx
, size
.cy
);
1247 return MAKELRESULT(size
.cx
, size
.cy
);
1251 TOOLTIPS_GetCurrentToolT (const TOOLTIPS_INFO
*infoPtr
, TTTOOLINFOW
*ti
, BOOL isW
)
1253 TTTOOL_INFO
*toolPtr
;
1256 if (ti
->cbSize
< TTTOOLINFOW_V1_SIZE
)
1259 if (infoPtr
->nCurrentTool
> -1) {
1260 toolPtr
= &infoPtr
->tools
[infoPtr
->nCurrentTool
];
1262 /* copy tool data */
1263 ti
->uFlags
= toolPtr
->uFlags
;
1264 ti
->rect
= toolPtr
->rect
;
1265 ti
->hinst
= toolPtr
->hinst
;
1266 TOOLTIPS_CopyInfoT (toolPtr
, ti
, isW
);
1268 if (ti
->cbSize
>= TTTOOLINFOW_V2_SIZE
)
1269 ti
->lParam
= toolPtr
->lParam
;
1277 return (infoPtr
->nCurrentTool
!= -1);
1282 TOOLTIPS_GetDelayTime (const TOOLTIPS_INFO
*infoPtr
, DWORD duration
)
1286 return infoPtr
->nReshowTime
;
1289 return infoPtr
->nAutoPopTime
;
1292 case TTDT_AUTOMATIC
: /* Apparently TTDT_AUTOMATIC returns TTDT_INITIAL */
1293 return infoPtr
->nInitialTime
;
1296 WARN("Invalid duration flag %x\n", duration
);
1305 TOOLTIPS_GetMargin (const TOOLTIPS_INFO
*infoPtr
, LPRECT lpRect
)
1307 lpRect
->left
= infoPtr
->rcMargin
.left
;
1308 lpRect
->right
= infoPtr
->rcMargin
.right
;
1309 lpRect
->bottom
= infoPtr
->rcMargin
.bottom
;
1310 lpRect
->top
= infoPtr
->rcMargin
.top
;
1316 static inline LRESULT
1317 TOOLTIPS_GetMaxTipWidth (const TOOLTIPS_INFO
*infoPtr
)
1319 return infoPtr
->nMaxTipWidth
;
1324 TOOLTIPS_GetTextT (const TOOLTIPS_INFO
*infoPtr
, TTTOOLINFOW
*ti
, BOOL isW
)
1329 if (ti
->cbSize
< TTTOOLINFOW_V1_SIZE
)
1332 nTool
= TOOLTIPS_GetToolFromInfoT (infoPtr
, ti
);
1333 if (nTool
== -1) return 0;
1335 if (infoPtr
->tools
[nTool
].lpszText
== NULL
)
1339 ti
->lpszText
[0] = '\0';
1340 TOOLTIPS_GetTipText(infoPtr
, nTool
, ti
->lpszText
);
1343 WCHAR buffer
[INFOTIPSIZE
];
1345 /* NB this API is broken, there is no way for the app to determine
1346 what size buffer it requires nor a way to specify how long the
1347 one it supplies is. According to the test result, it's up to
1348 80 bytes by the ANSI version. */
1351 TOOLTIPS_GetTipText(infoPtr
, nTool
, buffer
);
1352 WideCharToMultiByte(CP_ACP
, 0, buffer
, -1, (LPSTR
)ti
->lpszText
,
1353 MAX_TEXT_SIZE_A
, NULL
, NULL
);
1360 static inline LRESULT
1361 TOOLTIPS_GetTipBkColor (const TOOLTIPS_INFO
*infoPtr
)
1363 return infoPtr
->clrBk
;
1367 static inline LRESULT
1368 TOOLTIPS_GetTipTextColor (const TOOLTIPS_INFO
*infoPtr
)
1370 return infoPtr
->clrText
;
1374 static inline LRESULT
1375 TOOLTIPS_GetToolCount (const TOOLTIPS_INFO
*infoPtr
)
1377 return infoPtr
->uNumTools
;
1382 TOOLTIPS_GetToolInfoT (const TOOLTIPS_INFO
*infoPtr
, TTTOOLINFOW
*ti
, BOOL isW
)
1384 TTTOOL_INFO
*toolPtr
;
1387 if (!ti
) return FALSE
;
1388 if (ti
->cbSize
< TTTOOLINFOW_V1_SIZE
)
1390 if (infoPtr
->uNumTools
== 0)
1393 nTool
= TOOLTIPS_GetToolFromInfoT (infoPtr
, ti
);
1397 TRACE("tool %d\n", nTool
);
1399 toolPtr
= &infoPtr
->tools
[nTool
];
1401 /* copy tool data */
1402 ti
->uFlags
= toolPtr
->uFlags
;
1403 ti
->rect
= toolPtr
->rect
;
1404 ti
->hinst
= toolPtr
->hinst
;
1405 TOOLTIPS_CopyInfoT (toolPtr
, ti
, isW
);
1407 if (ti
->cbSize
>= TTTOOLINFOW_V2_SIZE
)
1408 ti
->lParam
= toolPtr
->lParam
;
1415 TOOLTIPS_HitTestT (const TOOLTIPS_INFO
*infoPtr
, LPTTHITTESTINFOW lptthit
,
1418 TTTOOL_INFO
*toolPtr
;
1424 nTool
= TOOLTIPS_GetToolFromPoint (infoPtr
, lptthit
->hwnd
, &lptthit
->pt
);
1428 TRACE("tool %d!\n", nTool
);
1430 /* copy tool data */
1431 if (lptthit
->ti
.cbSize
>= TTTOOLINFOW_V1_SIZE
) {
1432 toolPtr
= &infoPtr
->tools
[nTool
];
1434 lptthit
->ti
.uFlags
= toolPtr
->uFlags
;
1435 lptthit
->ti
.hwnd
= toolPtr
->hwnd
;
1436 lptthit
->ti
.uId
= toolPtr
->uId
;
1437 lptthit
->ti
.rect
= toolPtr
->rect
;
1438 lptthit
->ti
.hinst
= toolPtr
->hinst
;
1439 TOOLTIPS_CopyInfoT (toolPtr
, &lptthit
->ti
, isW
);
1440 if (lptthit
->ti
.cbSize
>= TTTOOLINFOW_V2_SIZE
)
1441 lptthit
->ti
.lParam
= toolPtr
->lParam
;
1449 TOOLTIPS_NewToolRectT (TOOLTIPS_INFO
*infoPtr
, const TTTOOLINFOW
*ti
)
1454 if (ti
->cbSize
< TTTOOLINFOW_V1_SIZE
)
1457 nTool
= TOOLTIPS_GetToolFromInfoT (infoPtr
, ti
);
1459 TRACE("nTool = %d, rect = %s\n", nTool
, wine_dbgstr_rect(&ti
->rect
));
1461 if (nTool
== -1) return 0;
1463 infoPtr
->tools
[nTool
].rect
= ti
->rect
;
1469 static inline LRESULT
1470 TOOLTIPS_Pop (TOOLTIPS_INFO
*infoPtr
)
1472 TOOLTIPS_Hide (infoPtr
);
1479 TOOLTIPS_RelayEvent (TOOLTIPS_INFO
*infoPtr
, LPMSG lpMsg
)
1485 ERR("lpMsg == NULL!\n");
1489 switch (lpMsg
->message
) {
1490 case WM_LBUTTONDOWN
:
1492 case WM_MBUTTONDOWN
:
1494 case WM_RBUTTONDOWN
:
1496 TOOLTIPS_Hide (infoPtr
);
1500 pt
.x
= (short)LOWORD(lpMsg
->lParam
);
1501 pt
.y
= (short)HIWORD(lpMsg
->lParam
);
1502 nOldTool
= infoPtr
->nTool
;
1503 infoPtr
->nTool
= TOOLTIPS_GetToolFromPoint(infoPtr
, lpMsg
->hwnd
,
1505 TRACE("tool (%p) %d %d %d\n", infoPtr
->hwndSelf
, nOldTool
,
1506 infoPtr
->nTool
, infoPtr
->nCurrentTool
);
1507 TRACE("WM_MOUSEMOVE (%p %d %d)\n", infoPtr
->hwndSelf
, pt
.x
, pt
.y
);
1509 if (infoPtr
->nTool
!= nOldTool
) {
1510 if(infoPtr
->nTool
== -1) { /* Moved out of all tools */
1511 TOOLTIPS_Hide(infoPtr
);
1512 KillTimer(infoPtr
->hwndSelf
, ID_TIMERLEAVE
);
1513 } else if (nOldTool
== -1) { /* Moved from outside */
1514 if(infoPtr
->bActive
) {
1515 SetTimer(infoPtr
->hwndSelf
, ID_TIMERSHOW
, infoPtr
->nInitialTime
, 0);
1516 TRACE("timer 1 started!\n");
1518 } else { /* Moved from one to another */
1519 TOOLTIPS_Hide (infoPtr
);
1520 KillTimer(infoPtr
->hwndSelf
, ID_TIMERLEAVE
);
1521 if(infoPtr
->bActive
) {
1522 SetTimer (infoPtr
->hwndSelf
, ID_TIMERSHOW
, infoPtr
->nReshowTime
, 0);
1523 TRACE("timer 1 started!\n");
1526 } else if(infoPtr
->nCurrentTool
!= -1) { /* restart autopop */
1527 KillTimer(infoPtr
->hwndSelf
, ID_TIMERPOP
);
1528 SetTimer(infoPtr
->hwndSelf
, ID_TIMERPOP
, infoPtr
->nAutoPopTime
, 0);
1529 TRACE("timer 2 restarted\n");
1530 } else if(infoPtr
->nTool
!= -1 && infoPtr
->bActive
) {
1531 /* previous show attempt didn't result in tooltip so try again */
1532 SetTimer(infoPtr
->hwndSelf
, ID_TIMERSHOW
, infoPtr
->nInitialTime
, 0);
1533 TRACE("timer 1 started!\n");
1543 TOOLTIPS_SetDelayTime (TOOLTIPS_INFO
*infoPtr
, DWORD duration
, INT nTime
)
1546 case TTDT_AUTOMATIC
:
1548 nTime
= GetDoubleClickTime();
1549 infoPtr
->nReshowTime
= nTime
/ 5;
1550 infoPtr
->nAutoPopTime
= nTime
* 10;
1551 infoPtr
->nInitialTime
= nTime
;
1556 nTime
= GetDoubleClickTime() / 5;
1557 infoPtr
->nReshowTime
= nTime
;
1562 nTime
= GetDoubleClickTime() * 10;
1563 infoPtr
->nAutoPopTime
= nTime
;
1568 nTime
= GetDoubleClickTime();
1569 infoPtr
->nInitialTime
= nTime
;
1573 WARN("Invalid duration flag %x\n", duration
);
1582 TOOLTIPS_SetMargin (TOOLTIPS_INFO
*infoPtr
, const RECT
*lpRect
)
1584 infoPtr
->rcMargin
.left
= lpRect
->left
;
1585 infoPtr
->rcMargin
.right
= lpRect
->right
;
1586 infoPtr
->rcMargin
.bottom
= lpRect
->bottom
;
1587 infoPtr
->rcMargin
.top
= lpRect
->top
;
1593 static inline LRESULT
1594 TOOLTIPS_SetMaxTipWidth (TOOLTIPS_INFO
*infoPtr
, INT MaxWidth
)
1596 INT nTemp
= infoPtr
->nMaxTipWidth
;
1598 infoPtr
->nMaxTipWidth
= MaxWidth
;
1604 static inline LRESULT
1605 TOOLTIPS_SetTipBkColor (TOOLTIPS_INFO
*infoPtr
, COLORREF clrBk
)
1607 infoPtr
->clrBk
= clrBk
;
1613 static inline LRESULT
1614 TOOLTIPS_SetTipTextColor (TOOLTIPS_INFO
*infoPtr
, COLORREF clrText
)
1616 infoPtr
->clrText
= clrText
;
1623 TOOLTIPS_SetTitleT (TOOLTIPS_INFO
*infoPtr
, UINT_PTR uTitleIcon
, LPCWSTR pszTitle
,
1628 TRACE("hwnd = %p, title = %s, icon = %p\n", infoPtr
->hwndSelf
, debugstr_w(pszTitle
),
1631 Free(infoPtr
->pszTitle
);
1637 size
= (strlenW(pszTitle
)+1)*sizeof(WCHAR
);
1638 infoPtr
->pszTitle
= Alloc(size
);
1639 if (!infoPtr
->pszTitle
)
1641 memcpy(infoPtr
->pszTitle
, pszTitle
, size
);
1645 size
= sizeof(WCHAR
)*MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)pszTitle
, -1, NULL
, 0);
1646 infoPtr
->pszTitle
= Alloc(size
);
1647 if (!infoPtr
->pszTitle
)
1649 MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)pszTitle
, -1, infoPtr
->pszTitle
, size
/sizeof(WCHAR
));
1653 infoPtr
->pszTitle
= NULL
;
1655 if (uTitleIcon
<= TTI_ERROR
)
1656 infoPtr
->hTitleIcon
= hTooltipIcons
[uTitleIcon
];
1658 infoPtr
->hTitleIcon
= CopyIcon((HICON
)uTitleIcon
);
1660 TRACE("icon = %p\n", infoPtr
->hTitleIcon
);
1667 TOOLTIPS_SetToolInfoT (TOOLTIPS_INFO
*infoPtr
, const TTTOOLINFOW
*ti
, BOOL isW
)
1669 TTTOOL_INFO
*toolPtr
;
1673 if (ti
->cbSize
< TTTOOLINFOW_V1_SIZE
)
1676 nTool
= TOOLTIPS_GetToolFromInfoT (infoPtr
, ti
);
1677 if (nTool
== -1) return 0;
1679 TRACE("tool %d\n", nTool
);
1681 toolPtr
= &infoPtr
->tools
[nTool
];
1683 /* copy tool data */
1684 toolPtr
->uFlags
= ti
->uFlags
;
1685 toolPtr
->hwnd
= ti
->hwnd
;
1686 toolPtr
->uId
= ti
->uId
;
1687 toolPtr
->rect
= ti
->rect
;
1688 toolPtr
->hinst
= ti
->hinst
;
1690 if (IS_INTRESOURCE(ti
->lpszText
)) {
1691 TRACE("set string id %x!\n", LOWORD(ti
->lpszText
));
1692 toolPtr
->lpszText
= ti
->lpszText
;
1695 if (TOOLTIPS_IsCallbackString(ti
->lpszText
, isW
))
1696 toolPtr
->lpszText
= LPSTR_TEXTCALLBACKW
;
1698 if ( (toolPtr
->lpszText
) &&
1699 !IS_INTRESOURCE(toolPtr
->lpszText
) ) {
1700 if( toolPtr
->lpszText
!= LPSTR_TEXTCALLBACKW
)
1701 Free (toolPtr
->lpszText
);
1702 toolPtr
->lpszText
= NULL
;
1706 INT len
= lstrlenW (ti
->lpszText
);
1707 toolPtr
->lpszText
= Alloc ((len
+1)*sizeof(WCHAR
));
1708 strcpyW (toolPtr
->lpszText
, ti
->lpszText
);
1711 INT len
= MultiByteToWideChar(CP_ACP
, 0, (LPSTR
)ti
->lpszText
,
1713 toolPtr
->lpszText
= Alloc (len
* sizeof(WCHAR
));
1714 MultiByteToWideChar(CP_ACP
, 0, (LPSTR
)ti
->lpszText
, -1,
1715 toolPtr
->lpszText
, len
);
1721 if (ti
->cbSize
>= TTTOOLINFOW_V2_SIZE
)
1722 toolPtr
->lParam
= ti
->lParam
;
1724 if (infoPtr
->nCurrentTool
== nTool
)
1726 TOOLTIPS_GetTipText (infoPtr
, infoPtr
->nCurrentTool
, infoPtr
->szTipText
);
1728 if (infoPtr
->szTipText
[0] == 0)
1729 TOOLTIPS_Hide(infoPtr
);
1731 TOOLTIPS_Show (infoPtr
, FALSE
);
1739 TOOLTIPS_TrackActivate (TOOLTIPS_INFO
*infoPtr
, BOOL track_activate
, const TTTOOLINFOA
*ti
)
1741 if (track_activate
) {
1744 if (ti
->cbSize
< TTTOOLINFOA_V1_SIZE
)
1748 infoPtr
->nTrackTool
= TOOLTIPS_GetToolFromInfoT (infoPtr
, (const TTTOOLINFOW
*)ti
);
1749 if (infoPtr
->nTrackTool
!= -1) {
1750 TRACE("activated!\n");
1751 infoPtr
->bTrackActive
= TRUE
;
1752 TOOLTIPS_TrackShow (infoPtr
);
1757 TOOLTIPS_TrackHide (infoPtr
);
1759 infoPtr
->bTrackActive
= FALSE
;
1760 infoPtr
->nTrackTool
= -1;
1762 TRACE("deactivated!\n");
1770 TOOLTIPS_TrackPosition (TOOLTIPS_INFO
*infoPtr
, LPARAM coord
)
1772 infoPtr
->xTrackPos
= (INT
)LOWORD(coord
);
1773 infoPtr
->yTrackPos
= (INT
)HIWORD(coord
);
1775 if (infoPtr
->bTrackActive
) {
1777 infoPtr
->xTrackPos
, infoPtr
->yTrackPos
);
1779 TOOLTIPS_TrackShow (infoPtr
);
1787 TOOLTIPS_Update (TOOLTIPS_INFO
*infoPtr
)
1789 if (infoPtr
->nCurrentTool
!= -1)
1790 UpdateWindow (infoPtr
->hwndSelf
);
1797 TOOLTIPS_UpdateTipTextT (TOOLTIPS_INFO
*infoPtr
, const TTTOOLINFOW
*ti
, BOOL isW
)
1799 TTTOOL_INFO
*toolPtr
;
1803 if (ti
->cbSize
< TTTOOLINFOW_V1_SIZE
)
1806 nTool
= TOOLTIPS_GetToolFromInfoT (infoPtr
, ti
);
1810 TRACE("tool %d\n", nTool
);
1812 toolPtr
= &infoPtr
->tools
[nTool
];
1814 /* copy tool text */
1815 toolPtr
->hinst
= ti
->hinst
;
1817 if (IS_INTRESOURCE(ti
->lpszText
)){
1818 toolPtr
->lpszText
= ti
->lpszText
;
1820 else if (ti
->lpszText
) {
1821 if (TOOLTIPS_IsCallbackString(ti
->lpszText
, isW
))
1822 toolPtr
->lpszText
= LPSTR_TEXTCALLBACKW
;
1824 if ( (toolPtr
->lpszText
) &&
1825 !IS_INTRESOURCE(toolPtr
->lpszText
) ) {
1826 if( toolPtr
->lpszText
!= LPSTR_TEXTCALLBACKW
)
1827 Free (toolPtr
->lpszText
);
1828 toolPtr
->lpszText
= NULL
;
1832 INT len
= lstrlenW (ti
->lpszText
);
1833 toolPtr
->lpszText
= Alloc ((len
+1)*sizeof(WCHAR
));
1834 strcpyW (toolPtr
->lpszText
, ti
->lpszText
);
1837 INT len
= MultiByteToWideChar(CP_ACP
, 0, (LPSTR
)ti
->lpszText
,
1839 toolPtr
->lpszText
= Alloc (len
* sizeof(WCHAR
));
1840 MultiByteToWideChar(CP_ACP
, 0, (LPSTR
)ti
->lpszText
, -1,
1841 toolPtr
->lpszText
, len
);
1847 if(infoPtr
->nCurrentTool
== -1) return 0;
1849 if (infoPtr
->bActive
)
1850 TOOLTIPS_Show (infoPtr
, FALSE
);
1851 else if (infoPtr
->bTrackActive
)
1852 TOOLTIPS_Show (infoPtr
, TRUE
);
1859 TOOLTIPS_Create (HWND hwnd
)
1861 TOOLTIPS_INFO
*infoPtr
;
1863 /* allocate memory for info structure */
1864 infoPtr
= Alloc (sizeof(TOOLTIPS_INFO
));
1865 SetWindowLongPtrW (hwnd
, 0, (DWORD_PTR
)infoPtr
);
1867 /* initialize info structure */
1868 infoPtr
->bActive
= TRUE
;
1869 infoPtr
->bTrackActive
= FALSE
;
1871 infoPtr
->nMaxTipWidth
= -1;
1872 infoPtr
->nTool
= -1;
1873 infoPtr
->nCurrentTool
= -1;
1874 infoPtr
->nTrackTool
= -1;
1875 infoPtr
->hwndSelf
= hwnd
;
1877 /* initialize colours and fonts */
1878 TOOLTIPS_InitSystemSettings(infoPtr
);
1880 TOOLTIPS_SetDelayTime(infoPtr
, TTDT_AUTOMATIC
, 0);
1882 SetWindowPos (hwnd
, HWND_TOP
, 0, 0, 0, 0, SWP_NOZORDER
| SWP_HIDEWINDOW
| SWP_NOACTIVATE
);
1889 TOOLTIPS_Destroy (TOOLTIPS_INFO
*infoPtr
)
1891 TTTOOL_INFO
*toolPtr
;
1895 if (infoPtr
->tools
) {
1896 for (i
= 0; i
< infoPtr
->uNumTools
; i
++) {
1897 toolPtr
= &infoPtr
->tools
[i
];
1898 if (toolPtr
->lpszText
) {
1899 if ( (toolPtr
->lpszText
!= LPSTR_TEXTCALLBACKW
) &&
1900 !IS_INTRESOURCE(toolPtr
->lpszText
) )
1902 Free (toolPtr
->lpszText
);
1903 toolPtr
->lpszText
= NULL
;
1907 /* remove subclassing */
1908 if (toolPtr
->uFlags
& TTF_SUBCLASS
) {
1909 if (toolPtr
->uFlags
& TTF_IDISHWND
) {
1910 RemoveWindowSubclass((HWND
)toolPtr
->uId
, TOOLTIPS_SubclassProc
, 1);
1913 RemoveWindowSubclass(toolPtr
->hwnd
, TOOLTIPS_SubclassProc
, 1);
1917 Free (infoPtr
->tools
);
1920 /* free title string */
1921 Free (infoPtr
->pszTitle
);
1922 /* free title icon if not a standard one */
1923 if (TOOLTIPS_GetTitleIconIndex(infoPtr
->hTitleIcon
) > TTI_ERROR
)
1924 DeleteObject(infoPtr
->hTitleIcon
);
1927 DeleteObject (infoPtr
->hFont
);
1928 DeleteObject (infoPtr
->hTitleFont
);
1930 /* free tool tips info data */
1931 SetWindowLongPtrW(infoPtr
->hwndSelf
, 0, 0);
1938 static inline LRESULT
1939 TOOLTIPS_GetFont (const TOOLTIPS_INFO
*infoPtr
)
1941 return (LRESULT
)infoPtr
->hFont
;
1946 TOOLTIPS_MouseMessage (TOOLTIPS_INFO
*infoPtr
)
1948 TOOLTIPS_Hide (infoPtr
);
1955 TOOLTIPS_NCCreate (HWND hwnd
)
1957 DWORD dwStyle
= GetWindowLongW (hwnd
, GWL_STYLE
);
1958 DWORD dwExStyle
= GetWindowLongW (hwnd
, GWL_EXSTYLE
);
1960 dwStyle
&= ~(WS_CHILD
| /*WS_MAXIMIZE |*/ WS_BORDER
| WS_DLGFRAME
);
1961 dwStyle
|= (WS_POPUP
| WS_BORDER
| WS_CLIPSIBLINGS
);
1963 /* WS_BORDER only draws a border round the window rect, not the
1964 * window region, therefore it is useless to us in balloon mode */
1965 if (dwStyle
& TTS_BALLOON
) dwStyle
&= ~WS_BORDER
;
1967 SetWindowLongW (hwnd
, GWL_STYLE
, dwStyle
);
1969 dwExStyle
|= WS_EX_TOOLWINDOW
;
1970 SetWindowLongW (hwnd
, GWL_EXSTYLE
, dwExStyle
);
1977 TOOLTIPS_NCHitTest (const TOOLTIPS_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
1979 INT nTool
= (infoPtr
->bTrackActive
) ? infoPtr
->nTrackTool
: infoPtr
->nTool
;
1981 TRACE(" nTool=%d\n", nTool
);
1983 if ((nTool
> -1) && (nTool
< infoPtr
->uNumTools
)) {
1984 if (infoPtr
->tools
[nTool
].uFlags
& TTF_TRANSPARENT
) {
1985 TRACE("-- in transparent mode!\n");
1986 return HTTRANSPARENT
;
1990 return DefWindowProcW (infoPtr
->hwndSelf
, WM_NCHITTEST
, wParam
, lParam
);
1995 TOOLTIPS_NotifyFormat (TOOLTIPS_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
1997 FIXME ("hwnd=%p wParam=%lx lParam=%lx\n", infoPtr
->hwndSelf
, wParam
, lParam
);
2004 TOOLTIPS_Paint (const TOOLTIPS_INFO
*infoPtr
, HDC hDC
)
2009 hdc
= (hDC
== NULL
) ? BeginPaint (infoPtr
->hwndSelf
, &ps
) : hDC
;
2010 TOOLTIPS_Refresh (infoPtr
, hdc
);
2012 EndPaint (infoPtr
->hwndSelf
, &ps
);
2018 TOOLTIPS_SetFont (TOOLTIPS_INFO
*infoPtr
, HFONT hFont
, BOOL redraw
)
2022 if(!GetObjectW(hFont
, sizeof(lf
), &lf
))
2025 DeleteObject (infoPtr
->hFont
);
2026 infoPtr
->hFont
= CreateFontIndirectW(&lf
);
2028 DeleteObject (infoPtr
->hTitleFont
);
2029 lf
.lfWeight
= FW_BOLD
;
2030 infoPtr
->hTitleFont
= CreateFontIndirectW(&lf
);
2032 if (redraw
&& infoPtr
->nCurrentTool
!= -1) {
2033 FIXME("full redraw needed!\n");
2039 /******************************************************************
2040 * TOOLTIPS_GetTextLength
2042 * This function is called when the tooltip receive a
2043 * WM_GETTEXTLENGTH message.
2045 * returns the length, in characters, of the tip text
2047 static inline LRESULT
2048 TOOLTIPS_GetTextLength(const TOOLTIPS_INFO
*infoPtr
)
2050 return strlenW(infoPtr
->szTipText
);
2053 /******************************************************************
2054 * TOOLTIPS_OnWMGetText
2056 * This function is called when the tooltip receive a
2057 * WM_GETTEXT message.
2058 * wParam : specifies the maximum number of characters to be copied
2059 * lParam : is the pointer to the buffer that will receive
2062 * returns the number of characters copied
2065 TOOLTIPS_OnWMGetText (const TOOLTIPS_INFO
*infoPtr
, WPARAM size
, LPWSTR pszText
)
2072 res
= min(strlenW(infoPtr
->szTipText
)+1, size
);
2073 memcpy(pszText
, infoPtr
->szTipText
, res
*sizeof(WCHAR
));
2074 pszText
[res
-1] = '\0';
2079 TOOLTIPS_Timer (TOOLTIPS_INFO
*infoPtr
, INT iTimer
)
2083 TRACE("timer %d (%p) expired!\n", iTimer
, infoPtr
->hwndSelf
);
2087 KillTimer (infoPtr
->hwndSelf
, ID_TIMERSHOW
);
2088 nOldTool
= infoPtr
->nTool
;
2089 if ((infoPtr
->nTool
= TOOLTIPS_CheckTool (infoPtr
, TRUE
)) == nOldTool
)
2090 TOOLTIPS_Show (infoPtr
, FALSE
);
2094 TOOLTIPS_Hide (infoPtr
);
2098 nOldTool
= infoPtr
->nTool
;
2099 infoPtr
->nTool
= TOOLTIPS_CheckTool (infoPtr
, FALSE
);
2100 TRACE("tool (%p) %d %d %d\n", infoPtr
->hwndSelf
, nOldTool
,
2101 infoPtr
->nTool
, infoPtr
->nCurrentTool
);
2102 if (infoPtr
->nTool
!= nOldTool
) {
2103 if(infoPtr
->nTool
== -1) { /* Moved out of all tools */
2104 TOOLTIPS_Hide(infoPtr
);
2105 KillTimer(infoPtr
->hwndSelf
, ID_TIMERLEAVE
);
2106 } else if (nOldTool
== -1) { /* Moved from outside */
2107 ERR("How did this happen?\n");
2108 } else { /* Moved from one to another */
2109 TOOLTIPS_Hide (infoPtr
);
2110 KillTimer(infoPtr
->hwndSelf
, ID_TIMERLEAVE
);
2111 if(infoPtr
->bActive
) {
2112 SetTimer (infoPtr
->hwndSelf
, ID_TIMERSHOW
, infoPtr
->nReshowTime
, 0);
2113 TRACE("timer 1 started!\n");
2120 ERR("Unknown timer id %d\n", iTimer
);
2128 TOOLTIPS_WinIniChange (TOOLTIPS_INFO
*infoPtr
)
2130 TOOLTIPS_InitSystemSettings (infoPtr
);
2136 static LRESULT CALLBACK
2137 TOOLTIPS_SubclassProc (HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
, UINT_PTR uID
, DWORD_PTR dwRef
)
2139 TOOLTIPS_INFO
*infoPtr
= TOOLTIPS_GetInfoPtr ((HWND
)dwRef
);
2144 case WM_LBUTTONDOWN
:
2146 case WM_MBUTTONDOWN
:
2148 case WM_RBUTTONDOWN
:
2152 msg
.wParam
= wParam
;
2153 msg
.lParam
= lParam
;
2154 TOOLTIPS_RelayEvent(infoPtr
, &msg
);
2160 return DefSubclassProc(hwnd
, uMsg
, wParam
, lParam
);
2164 static LRESULT CALLBACK
2165 TOOLTIPS_WindowProc (HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
2167 TOOLTIPS_INFO
*infoPtr
= TOOLTIPS_GetInfoPtr (hwnd
);
2169 TRACE("hwnd=%p msg=%x wparam=%lx lParam=%lx\n", hwnd
, uMsg
, wParam
, lParam
);
2170 if (!infoPtr
&& (uMsg
!= WM_CREATE
) && (uMsg
!= WM_NCCREATE
))
2171 return DefWindowProcW (hwnd
, uMsg
, wParam
, lParam
);
2175 return TOOLTIPS_Activate (infoPtr
, (BOOL
)wParam
);
2179 return TOOLTIPS_AddToolT (infoPtr
, (LPTTTOOLINFOW
)lParam
, uMsg
== TTM_ADDTOOLW
);
2183 return TOOLTIPS_DelToolT (infoPtr
, (LPTOOLINFOW
)lParam
,
2184 uMsg
== TTM_DELTOOLW
);
2185 case TTM_ENUMTOOLSA
:
2186 case TTM_ENUMTOOLSW
:
2187 return TOOLTIPS_EnumToolsT (infoPtr
, (UINT
)wParam
, (LPTTTOOLINFOW
)lParam
,
2188 uMsg
== TTM_ENUMTOOLSW
);
2189 case TTM_GETBUBBLESIZE
:
2190 return TOOLTIPS_GetBubbleSize (infoPtr
, (LPTTTOOLINFOW
)lParam
);
2192 case TTM_GETCURRENTTOOLA
:
2193 case TTM_GETCURRENTTOOLW
:
2194 return TOOLTIPS_GetCurrentToolT (infoPtr
, (LPTTTOOLINFOW
)lParam
,
2195 uMsg
== TTM_GETCURRENTTOOLW
);
2197 case TTM_GETDELAYTIME
:
2198 return TOOLTIPS_GetDelayTime (infoPtr
, (DWORD
)wParam
);
2201 return TOOLTIPS_GetMargin (infoPtr
, (LPRECT
)lParam
);
2203 case TTM_GETMAXTIPWIDTH
:
2204 return TOOLTIPS_GetMaxTipWidth (infoPtr
);
2208 return TOOLTIPS_GetTextT (infoPtr
, (LPTTTOOLINFOW
)lParam
,
2209 uMsg
== TTM_GETTEXTW
);
2211 case TTM_GETTIPBKCOLOR
:
2212 return TOOLTIPS_GetTipBkColor (infoPtr
);
2214 case TTM_GETTIPTEXTCOLOR
:
2215 return TOOLTIPS_GetTipTextColor (infoPtr
);
2217 case TTM_GETTOOLCOUNT
:
2218 return TOOLTIPS_GetToolCount (infoPtr
);
2220 case TTM_GETTOOLINFOA
:
2221 case TTM_GETTOOLINFOW
:
2222 return TOOLTIPS_GetToolInfoT (infoPtr
, (LPTTTOOLINFOW
)lParam
,
2223 uMsg
== TTM_GETTOOLINFOW
);
2227 return TOOLTIPS_HitTestT (infoPtr
, (LPTTHITTESTINFOW
)lParam
,
2228 uMsg
== TTM_HITTESTW
);
2229 case TTM_NEWTOOLRECTA
:
2230 case TTM_NEWTOOLRECTW
:
2231 return TOOLTIPS_NewToolRectT (infoPtr
, (LPTTTOOLINFOW
)lParam
);
2234 return TOOLTIPS_Pop (infoPtr
);
2236 case TTM_RELAYEVENT
:
2237 return TOOLTIPS_RelayEvent (infoPtr
, (LPMSG
)lParam
);
2239 case TTM_SETDELAYTIME
:
2240 return TOOLTIPS_SetDelayTime (infoPtr
, (DWORD
)wParam
, (INT
)LOWORD(lParam
));
2243 return TOOLTIPS_SetMargin (infoPtr
, (LPRECT
)lParam
);
2245 case TTM_SETMAXTIPWIDTH
:
2246 return TOOLTIPS_SetMaxTipWidth (infoPtr
, (INT
)lParam
);
2248 case TTM_SETTIPBKCOLOR
:
2249 return TOOLTIPS_SetTipBkColor (infoPtr
, (COLORREF
)wParam
);
2251 case TTM_SETTIPTEXTCOLOR
:
2252 return TOOLTIPS_SetTipTextColor (infoPtr
, (COLORREF
)wParam
);
2256 return TOOLTIPS_SetTitleT (infoPtr
, (UINT_PTR
)wParam
, (LPCWSTR
)lParam
,
2257 uMsg
== TTM_SETTITLEW
);
2259 case TTM_SETTOOLINFOA
:
2260 case TTM_SETTOOLINFOW
:
2261 return TOOLTIPS_SetToolInfoT (infoPtr
, (LPTTTOOLINFOW
)lParam
,
2262 uMsg
== TTM_SETTOOLINFOW
);
2264 case TTM_TRACKACTIVATE
:
2265 return TOOLTIPS_TrackActivate (infoPtr
, (BOOL
)wParam
, (LPTTTOOLINFOA
)lParam
);
2267 case TTM_TRACKPOSITION
:
2268 return TOOLTIPS_TrackPosition (infoPtr
, lParam
);
2271 return TOOLTIPS_Update (infoPtr
);
2273 case TTM_UPDATETIPTEXTA
:
2274 case TTM_UPDATETIPTEXTW
:
2275 return TOOLTIPS_UpdateTipTextT (infoPtr
, (LPTTTOOLINFOW
)lParam
,
2276 uMsg
== TTM_UPDATETIPTEXTW
);
2278 case TTM_WINDOWFROMPOINT
:
2279 return (LRESULT
)WindowFromPoint (*((LPPOINT
)lParam
));
2282 return TOOLTIPS_Create (hwnd
);
2285 return TOOLTIPS_Destroy (infoPtr
);
2288 /* we draw the background in WM_PAINT */
2292 return TOOLTIPS_GetFont (infoPtr
);
2295 return TOOLTIPS_OnWMGetText (infoPtr
, wParam
, (LPWSTR
)lParam
);
2297 case WM_GETTEXTLENGTH
:
2298 return TOOLTIPS_GetTextLength (infoPtr
);
2300 case WM_LBUTTONDOWN
:
2302 case WM_MBUTTONDOWN
:
2304 case WM_RBUTTONDOWN
:
2307 return TOOLTIPS_MouseMessage (infoPtr
);
2310 return TOOLTIPS_NCCreate (hwnd
);
2313 return TOOLTIPS_NCHitTest (infoPtr
, wParam
, lParam
);
2315 case WM_NOTIFYFORMAT
:
2316 return TOOLTIPS_NotifyFormat (infoPtr
, wParam
, lParam
);
2318 case WM_PRINTCLIENT
:
2320 return TOOLTIPS_Paint (infoPtr
, (HDC
)wParam
);
2323 return TOOLTIPS_SetFont (infoPtr
, (HFONT
)wParam
, LOWORD(lParam
));
2325 case WM_SYSCOLORCHANGE
:
2326 COMCTL32_RefreshSysColors();
2330 return TOOLTIPS_Timer (infoPtr
, (INT
)wParam
);
2332 case WM_WININICHANGE
:
2333 return TOOLTIPS_WinIniChange (infoPtr
);
2336 if ((uMsg
>= WM_USER
) && (uMsg
< WM_APP
) && !COMCTL32_IsReflectedMessage(uMsg
))
2337 ERR("unknown msg %04x wp=%08lx lp=%08lx\n",
2338 uMsg
, wParam
, lParam
);
2339 return DefWindowProcW (hwnd
, uMsg
, wParam
, lParam
);
2345 TOOLTIPS_Register (void)
2349 ZeroMemory (&wndClass
, sizeof(WNDCLASSW
));
2350 wndClass
.style
= CS_GLOBALCLASS
| CS_DBLCLKS
| CS_SAVEBITS
;
2351 wndClass
.lpfnWndProc
= TOOLTIPS_WindowProc
;
2352 wndClass
.cbClsExtra
= 0;
2353 wndClass
.cbWndExtra
= sizeof(TOOLTIPS_INFO
*);
2354 wndClass
.hCursor
= LoadCursorW (0, (LPWSTR
)IDC_ARROW
);
2355 wndClass
.hbrBackground
= 0;
2356 wndClass
.lpszClassName
= TOOLTIPS_CLASSW
;
2358 RegisterClassW (&wndClass
);
2360 hTooltipIcons
[TTI_NONE
] = NULL
;
2361 hTooltipIcons
[TTI_INFO
] = LoadImageW(COMCTL32_hModule
,
2362 (LPCWSTR
)MAKEINTRESOURCE(IDI_TT_INFO_SM
), IMAGE_ICON
, 0, 0, 0);
2363 hTooltipIcons
[TTI_WARNING
] = LoadImageW(COMCTL32_hModule
,
2364 (LPCWSTR
)MAKEINTRESOURCE(IDI_TT_WARN_SM
), IMAGE_ICON
, 0, 0, 0);
2365 hTooltipIcons
[TTI_ERROR
] = LoadImageW(COMCTL32_hModule
,
2366 (LPCWSTR
)MAKEINTRESOURCE(IDI_TT_ERROR_SM
), IMAGE_ICON
, 0, 0, 0);
2371 TOOLTIPS_Unregister (void)
2374 for (i
= TTI_INFO
; i
<= TTI_ERROR
; i
++)
2375 DestroyIcon(hTooltipIcons
[i
]);
2376 UnregisterClassW (TOOLTIPS_CLASSW
, NULL
);