4 * Copyright 1998, 1999 Eric Kohl
5 * Copyright 2004 Robert Shearman
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 * This code was audited for completeness against the documented features
24 * of Comctl32.dll version 6.0 on Sep. 08, 2004, by Robert Shearman.
26 * Unless otherwise noted, we believe this code to be complete, as per
27 * the specification mentioned above.
28 * If you discover missing features or bugs please note them below.
31 * - Custom draw support.
45 * - Run tests using Waite Group Windows95 API Bible Volume 2.
46 * The second cdrom (chapter 3) contains executables activate.exe,
47 * curtool.exe, deltool.exe, enumtools.exe, getinfo.exe, getiptxt.exe,
48 * hittest.exe, needtext.exe, newrect.exe, updtext.exe and winfrpt.exe.
52 * One important point to remember is that tools don't necessarily get
53 * a WM_MOUSEMOVE once the cursor leaves the tool, an example is when
54 * a tool sets TTF_IDISHWND (i.e. an entire window is a tool) because
55 * here WM_MOUSEMOVEs only get sent when the cursor is inside the
56 * client area. Therefore the only reliable way to know that the
57 * cursor has left a tool is to keep a timer running and check the
58 * position every time it expires. This is the role of timer
62 * On entering a tool (detected in a relayed WM_MOUSEMOVE) we start
63 * ID_TIMERSHOW, if this times out and we're still in the tool we show
64 * the tip. On showing a tip we start both ID_TIMERPOP and
65 * ID_TIMERLEAVE. On hiding a tooltip we kill ID_TIMERPOP.
66 * ID_TIMERPOP is restarted on every relayed WM_MOUSEMOVE. If
67 * ID_TIMERPOP expires the tool is hidden and ID_TIMERPOP is killed.
68 * ID_TIMERLEAVE remains running - this is important as we need to
69 * determine when the cursor leaves the tool.
71 * When ID_TIMERLEAVE expires or on a relayed WM_MOUSEMOVE if we're
72 * still in the tool do nothing (apart from restart ID_TIMERPOP if
73 * this is a WM_MOUSEMOVE) (ID_TIMERLEAVE remains running). If we've
74 * left the tool and entered another one then hide the tip and start
75 * ID_TIMERSHOW with time ReshowTime and kill ID_TIMERLEAVE. If we're
76 * outside all tools hide the tip and kill ID_TIMERLEAVE. On Relayed
77 * mouse button messages hide the tip but leave ID_TIMERLEAVE running,
78 * this again will let us keep track of when the cursor leaves the
82 * infoPtr->nTool is the tool the mouse was on on the last relayed MM
83 * or timer expiry or -1 if the mouse was not on a tool.
85 * infoPtr->nCurrentTool is the tool for which the tip is currently
86 * displaying text for or -1 if the tip is not shown. Actually this
87 * will only ever be infoPtr-nTool or -1, so it could be changed to a
99 #include "wine/unicode.h"
103 #include "commctrl.h"
104 #include "comctl32.h"
105 #include "wine/debug.h"
107 WINE_DEFAULT_DEBUG_CHANNEL(tooltips
);
109 static HICON hTooltipIcons
[TTI_ERROR
+1];
128 WCHAR szTipText
[INFOTIPSIZE
];
139 INT nTool
; /* tool that mouse was on on last relayed mouse move */
153 #define ID_TIMERSHOW 1 /* show delay timer */
154 #define ID_TIMERPOP 2 /* auto pop timer */
155 #define ID_TIMERLEAVE 3 /* tool leave timer */
158 #define TOOLTIPS_GetInfoPtr(hWindow) ((TOOLTIPS_INFO *)GetWindowLongPtrW (hWindow, 0))
160 /* offsets from window edge to start of text */
161 #define NORMAL_TEXT_MARGIN 2
162 #define BALLOON_TEXT_MARGIN (NORMAL_TEXT_MARGIN+8)
163 /* value used for CreateRoundRectRgn that specifies how much
164 * each corner is curved */
165 #define BALLOON_ROUNDEDNESS 20
166 #define BALLOON_STEMHEIGHT 13
167 #define BALLOON_STEMWIDTH 10
168 #define BALLOON_STEMINDENT 20
170 #define BALLOON_ICON_TITLE_SPACING 8 /* horizontal spacing between icon and title */
171 #define BALLOON_TITLE_TEXT_SPACING 8 /* vertical spacing between icon/title and main text */
172 #define ICON_HEIGHT 16
173 #define ICON_WIDTH 16
175 #define MAX_TEXT_SIZE_A 80 /* maximum retrieving text size by ANSI message */
177 static LRESULT CALLBACK
178 TOOLTIPS_SubclassProc (HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
, UINT_PTR uId
, DWORD_PTR dwRef
);
181 static inline BOOL
TOOLTIPS_IsCallbackString(LPCWSTR str
, BOOL isW
)
184 return str
== LPSTR_TEXTCALLBACKW
;
186 return (LPCSTR
)str
== LPSTR_TEXTCALLBACKA
;
189 static inline UINT_PTR
190 TOOLTIPS_GetTitleIconIndex(HICON hIcon
)
193 for (i
= 0; i
<= TTI_ERROR
; i
++)
194 if (hTooltipIcons
[i
] == hIcon
)
196 return (UINT_PTR
)hIcon
;
200 TOOLTIPS_InitSystemSettings (TOOLTIPS_INFO
*infoPtr
)
202 NONCLIENTMETRICSW nclm
;
204 infoPtr
->clrBk
= comctl32_color
.clrInfoBk
;
205 infoPtr
->clrText
= comctl32_color
.clrInfoText
;
207 DeleteObject (infoPtr
->hFont
);
208 nclm
.cbSize
= sizeof(nclm
);
209 SystemParametersInfoW (SPI_GETNONCLIENTMETRICS
, sizeof(nclm
), &nclm
, 0);
210 infoPtr
->hFont
= CreateFontIndirectW (&nclm
.lfStatusFont
);
212 DeleteObject (infoPtr
->hTitleFont
);
213 nclm
.lfStatusFont
.lfWeight
= FW_BOLD
;
214 infoPtr
->hTitleFont
= CreateFontIndirectW (&nclm
.lfStatusFont
);
217 /* Custom draw routines */
219 TOOLTIPS_customdraw_fill(const TOOLTIPS_INFO
*infoPtr
, NMTTCUSTOMDRAW
*lpnmttcd
,
220 HDC hdc
, const RECT
*rcBounds
, UINT uFlags
)
222 ZeroMemory(lpnmttcd
, sizeof(NMTTCUSTOMDRAW
));
223 lpnmttcd
->uDrawFlags
= uFlags
;
224 lpnmttcd
->nmcd
.hdr
.hwndFrom
= infoPtr
->hwndSelf
;
225 lpnmttcd
->nmcd
.hdr
.code
= NM_CUSTOMDRAW
;
226 if (infoPtr
->nCurrentTool
!= -1) {
227 TTTOOL_INFO
*toolPtr
= &infoPtr
->tools
[infoPtr
->nCurrentTool
];
228 lpnmttcd
->nmcd
.hdr
.idFrom
= toolPtr
->uId
;
230 lpnmttcd
->nmcd
.hdc
= hdc
;
231 lpnmttcd
->nmcd
.rc
= *rcBounds
;
232 /* FIXME - dwItemSpec, uItemState, lItemlParam */
236 TOOLTIPS_notify_customdraw (DWORD dwDrawStage
, NMTTCUSTOMDRAW
*lpnmttcd
)
239 lpnmttcd
->nmcd
.dwDrawStage
= dwDrawStage
;
241 TRACE("Notifying stage %d, flags %x, id %x\n", lpnmttcd
->nmcd
.dwDrawStage
,
242 lpnmttcd
->uDrawFlags
, lpnmttcd
->nmcd
.hdr
.code
);
244 result
= SendMessageW(GetParent(lpnmttcd
->nmcd
.hdr
.hwndFrom
), WM_NOTIFY
,
245 0, (LPARAM
)lpnmttcd
);
247 TRACE("Notify result %x\n", (unsigned int)result
);
253 TOOLTIPS_Refresh (const TOOLTIPS_INFO
*infoPtr
, HDC hdc
)
259 UINT uFlags
= DT_EXTERNALLEADING
;
261 DWORD dwStyle
= GetWindowLongW(infoPtr
->hwndSelf
, GWL_STYLE
);
262 NMTTCUSTOMDRAW nmttcd
;
265 if (infoPtr
->nMaxTipWidth
> -1)
266 uFlags
|= DT_WORDBREAK
;
267 if (GetWindowLongW (infoPtr
->hwndSelf
, GWL_STYLE
) & TTS_NOPREFIX
)
268 uFlags
|= DT_NOPREFIX
;
269 GetClientRect (infoPtr
->hwndSelf
, &rc
);
271 hBrush
= CreateSolidBrush(infoPtr
->clrBk
);
273 oldBkMode
= SetBkMode (hdc
, TRANSPARENT
);
274 SetTextColor (hdc
, infoPtr
->clrText
);
275 hOldFont
= SelectObject (hdc
, infoPtr
->hFont
);
277 /* Custom draw - Call PrePaint once initial properties set up */
278 /* Note: Contrary to MSDN, CDRF_SKIPDEFAULT still draws a tooltip */
279 TOOLTIPS_customdraw_fill(infoPtr
, &nmttcd
, hdc
, &rc
, uFlags
);
280 cdmode
= TOOLTIPS_notify_customdraw(CDDS_PREPAINT
, &nmttcd
);
281 uFlags
= nmttcd
.uDrawFlags
;
283 if (dwStyle
& TTS_BALLOON
)
285 /* create a region to store result into */
286 hRgn
= CreateRectRgn(0, 0, 0, 0);
288 GetWindowRgn(infoPtr
->hwndSelf
, hRgn
);
290 /* fill the background */
291 FillRgn(hdc
, hRgn
, hBrush
);
292 DeleteObject(hBrush
);
297 /* fill the background */
298 FillRect(hdc
, &rc
, hBrush
);
299 DeleteObject(hBrush
);
303 if ((dwStyle
& TTS_BALLOON
) || infoPtr
->pszTitle
)
305 /* calculate text rectangle */
306 rc
.left
+= (BALLOON_TEXT_MARGIN
+ infoPtr
->rcMargin
.left
);
307 rc
.top
+= (BALLOON_TEXT_MARGIN
+ infoPtr
->rcMargin
.top
);
308 rc
.right
-= (BALLOON_TEXT_MARGIN
+ infoPtr
->rcMargin
.right
);
309 rc
.bottom
-= (BALLOON_TEXT_MARGIN
+ infoPtr
->rcMargin
.bottom
);
310 if(infoPtr
->bToolBelow
) rc
.top
+= BALLOON_STEMHEIGHT
;
312 if (infoPtr
->pszTitle
)
314 RECT rcTitle
= {rc
.left
, rc
.top
, rc
.right
, rc
.bottom
};
320 icon_present
= infoPtr
->hTitleIcon
&&
321 DrawIconEx(hdc
, rc
.left
, rc
.top
, infoPtr
->hTitleIcon
,
322 ICON_WIDTH
, ICON_HEIGHT
, 0, NULL
, DI_NORMAL
);
324 rcTitle
.left
+= ICON_WIDTH
+ BALLOON_ICON_TITLE_SPACING
;
326 rcTitle
.bottom
= rc
.top
+ ICON_HEIGHT
;
328 /* draw title text */
329 prevFont
= SelectObject (hdc
, infoPtr
->hTitleFont
);
330 height
= DrawTextW(hdc
, infoPtr
->pszTitle
, -1, &rcTitle
, DT_BOTTOM
| DT_SINGLELINE
| DT_NOPREFIX
);
331 SelectObject (hdc
, prevFont
);
332 rc
.top
+= height
+ BALLOON_TITLE_TEXT_SPACING
;
337 /* calculate text rectangle */
338 rc
.left
+= (NORMAL_TEXT_MARGIN
+ infoPtr
->rcMargin
.left
);
339 rc
.top
+= (NORMAL_TEXT_MARGIN
+ infoPtr
->rcMargin
.top
);
340 rc
.right
-= (NORMAL_TEXT_MARGIN
+ infoPtr
->rcMargin
.right
);
341 rc
.bottom
-= (NORMAL_TEXT_MARGIN
+ infoPtr
->rcMargin
.bottom
);
345 DrawTextW (hdc
, infoPtr
->szTipText
, -1, &rc
, uFlags
);
347 /* Custom draw - Call PostPaint after drawing */
348 if (cdmode
& CDRF_NOTIFYPOSTPAINT
) {
349 TOOLTIPS_notify_customdraw(CDDS_POSTPAINT
, &nmttcd
);
352 /* be polite and reset the things we changed in the dc */
353 SelectObject (hdc
, hOldFont
);
354 SetBkMode (hdc
, oldBkMode
);
356 if (dwStyle
& TTS_BALLOON
)
358 /* frame region because default window proc doesn't do it */
359 INT width
= GetSystemMetrics(SM_CXDLGFRAME
) - GetSystemMetrics(SM_CXEDGE
);
360 INT height
= GetSystemMetrics(SM_CYDLGFRAME
) - GetSystemMetrics(SM_CYEDGE
);
362 hBrush
= GetSysColorBrush(COLOR_WINDOWFRAME
);
363 FrameRgn(hdc
, hRgn
, hBrush
, width
, height
);
370 static void TOOLTIPS_GetDispInfoA(const TOOLTIPS_INFO
*infoPtr
, TTTOOL_INFO
*toolPtr
, WCHAR
*buffer
)
372 NMTTDISPINFOA ttnmdi
;
374 /* fill NMHDR struct */
375 ZeroMemory (&ttnmdi
, sizeof(NMTTDISPINFOA
));
376 ttnmdi
.hdr
.hwndFrom
= infoPtr
->hwndSelf
;
377 ttnmdi
.hdr
.idFrom
= toolPtr
->uId
;
378 ttnmdi
.hdr
.code
= TTN_GETDISPINFOA
; /* == TTN_NEEDTEXTA */
379 ttnmdi
.lpszText
= ttnmdi
.szText
;
380 ttnmdi
.uFlags
= toolPtr
->uFlags
;
381 ttnmdi
.lParam
= toolPtr
->lParam
;
383 TRACE("hdr.idFrom = %lx\n", ttnmdi
.hdr
.idFrom
);
384 SendMessageW(toolPtr
->hwnd
, WM_NOTIFY
, toolPtr
->uId
, (LPARAM
)&ttnmdi
);
386 if (IS_INTRESOURCE(ttnmdi
.lpszText
)) {
387 LoadStringW(ttnmdi
.hinst
, LOWORD(ttnmdi
.lpszText
),
388 buffer
, INFOTIPSIZE
);
389 if (ttnmdi
.uFlags
& TTF_DI_SETITEM
) {
390 toolPtr
->hinst
= ttnmdi
.hinst
;
391 toolPtr
->lpszText
= (LPWSTR
)ttnmdi
.lpszText
;
394 else if (ttnmdi
.lpszText
== 0) {
397 else if (ttnmdi
.lpszText
!= LPSTR_TEXTCALLBACKA
) {
398 Str_GetPtrAtoW(ttnmdi
.lpszText
, buffer
, INFOTIPSIZE
);
399 if (ttnmdi
.uFlags
& TTF_DI_SETITEM
) {
401 toolPtr
->lpszText
= NULL
;
402 Str_SetPtrW(&toolPtr
->lpszText
, buffer
);
406 ERR("recursive text callback\n");
410 /* no text available - try calling parent instead as per native */
411 /* FIXME: Unsure if SETITEM should save the value or not */
412 if (buffer
[0] == 0x00) {
414 SendMessageW(GetParent(toolPtr
->hwnd
), WM_NOTIFY
, toolPtr
->uId
, (LPARAM
)&ttnmdi
);
416 if (IS_INTRESOURCE(ttnmdi
.lpszText
)) {
417 LoadStringW(ttnmdi
.hinst
, LOWORD(ttnmdi
.lpszText
),
418 buffer
, INFOTIPSIZE
);
419 } else if (ttnmdi
.lpszText
&&
420 ttnmdi
.lpszText
!= LPSTR_TEXTCALLBACKA
) {
421 Str_GetPtrAtoW(ttnmdi
.lpszText
, buffer
, INFOTIPSIZE
);
426 static void TOOLTIPS_GetDispInfoW(const TOOLTIPS_INFO
*infoPtr
, TTTOOL_INFO
*toolPtr
, WCHAR
*buffer
)
428 NMTTDISPINFOW ttnmdi
;
430 /* fill NMHDR struct */
431 ZeroMemory (&ttnmdi
, sizeof(NMTTDISPINFOW
));
432 ttnmdi
.hdr
.hwndFrom
= infoPtr
->hwndSelf
;
433 ttnmdi
.hdr
.idFrom
= toolPtr
->uId
;
434 ttnmdi
.hdr
.code
= TTN_GETDISPINFOW
; /* == TTN_NEEDTEXTW */
435 ttnmdi
.lpszText
= ttnmdi
.szText
;
436 ttnmdi
.uFlags
= toolPtr
->uFlags
;
437 ttnmdi
.lParam
= toolPtr
->lParam
;
439 TRACE("hdr.idFrom = %lx\n", ttnmdi
.hdr
.idFrom
);
440 SendMessageW(toolPtr
->hwnd
, WM_NOTIFY
, toolPtr
->uId
, (LPARAM
)&ttnmdi
);
442 if (IS_INTRESOURCE(ttnmdi
.lpszText
)) {
443 LoadStringW(ttnmdi
.hinst
, LOWORD(ttnmdi
.lpszText
),
444 buffer
, INFOTIPSIZE
);
445 if (ttnmdi
.uFlags
& TTF_DI_SETITEM
) {
446 toolPtr
->hinst
= ttnmdi
.hinst
;
447 toolPtr
->lpszText
= ttnmdi
.lpszText
;
450 else if (ttnmdi
.lpszText
== 0) {
453 else if (ttnmdi
.lpszText
!= LPSTR_TEXTCALLBACKW
) {
454 Str_GetPtrW(ttnmdi
.lpszText
, buffer
, INFOTIPSIZE
);
455 if (ttnmdi
.uFlags
& TTF_DI_SETITEM
) {
457 toolPtr
->lpszText
= NULL
;
458 Str_SetPtrW(&toolPtr
->lpszText
, buffer
);
462 ERR("recursive text callback\n");
466 /* no text available - try calling parent instead as per native */
467 /* FIXME: Unsure if SETITEM should save the value or not */
468 if (buffer
[0] == 0x00) {
470 SendMessageW(GetParent(toolPtr
->hwnd
), WM_NOTIFY
, toolPtr
->uId
, (LPARAM
)&ttnmdi
);
472 if (IS_INTRESOURCE(ttnmdi
.lpszText
)) {
473 LoadStringW(ttnmdi
.hinst
, LOWORD(ttnmdi
.lpszText
),
474 buffer
, INFOTIPSIZE
);
475 } else if (ttnmdi
.lpszText
&&
476 ttnmdi
.lpszText
!= LPSTR_TEXTCALLBACKW
) {
477 Str_GetPtrW(ttnmdi
.lpszText
, buffer
, INFOTIPSIZE
);
484 TOOLTIPS_GetTipText (const TOOLTIPS_INFO
*infoPtr
, INT nTool
, WCHAR
*buffer
)
486 TTTOOL_INFO
*toolPtr
= &infoPtr
->tools
[nTool
];
488 if (IS_INTRESOURCE(toolPtr
->lpszText
)) {
489 /* load a resource */
490 TRACE("load res string %p %x\n",
491 toolPtr
->hinst
, LOWORD(toolPtr
->lpszText
));
492 if (!LoadStringW (toolPtr
->hinst
, LOWORD(toolPtr
->lpszText
), buffer
, INFOTIPSIZE
))
495 else if (toolPtr
->lpszText
) {
496 if (toolPtr
->lpszText
== LPSTR_TEXTCALLBACKW
) {
497 if (toolPtr
->bNotifyUnicode
)
498 TOOLTIPS_GetDispInfoW(infoPtr
, toolPtr
, buffer
);
500 TOOLTIPS_GetDispInfoA(infoPtr
, toolPtr
, buffer
);
503 /* the item is a usual (unicode) text */
504 lstrcpynW (buffer
, toolPtr
->lpszText
, INFOTIPSIZE
);
508 /* no text available */
512 if (!(GetWindowLongW(infoPtr
->hwndSelf
, GWL_STYLE
) & TTS_NOPREFIX
)) {
514 if ((ptrW
= strchrW(buffer
, '\t')))
518 TRACE("%s\n", debugstr_w(buffer
));
523 TOOLTIPS_CalcTipSize (const TOOLTIPS_INFO
*infoPtr
, LPSIZE lpSize
)
527 DWORD style
= GetWindowLongW(infoPtr
->hwndSelf
, GWL_STYLE
);
528 UINT uFlags
= DT_EXTERNALLEADING
| DT_CALCRECT
;
529 RECT rc
= {0, 0, 0, 0};
532 if (infoPtr
->nMaxTipWidth
> -1) {
533 rc
.right
= infoPtr
->nMaxTipWidth
;
534 uFlags
|= DT_WORDBREAK
;
536 if (style
& TTS_NOPREFIX
)
537 uFlags
|= DT_NOPREFIX
;
538 TRACE("%s\n", debugstr_w(infoPtr
->szTipText
));
540 hdc
= GetDC (infoPtr
->hwndSelf
);
541 if (infoPtr
->pszTitle
)
543 RECT rcTitle
= {0, 0, 0, 0};
544 TRACE("title %s\n", debugstr_w(infoPtr
->pszTitle
));
545 if (infoPtr
->hTitleIcon
)
547 title
.cx
= ICON_WIDTH
;
548 title
.cy
= ICON_HEIGHT
;
550 if (title
.cx
!= 0) title
.cx
+= BALLOON_ICON_TITLE_SPACING
;
551 hOldFont
= SelectObject (hdc
, infoPtr
->hTitleFont
);
552 DrawTextW(hdc
, infoPtr
->pszTitle
, -1, &rcTitle
, DT_SINGLELINE
| DT_NOPREFIX
| DT_CALCRECT
);
553 SelectObject (hdc
, hOldFont
);
554 title
.cy
= max(title
.cy
, rcTitle
.bottom
- rcTitle
.top
) + BALLOON_TITLE_TEXT_SPACING
;
555 title
.cx
+= (rcTitle
.right
- rcTitle
.left
);
557 hOldFont
= SelectObject (hdc
, infoPtr
->hFont
);
558 DrawTextW (hdc
, infoPtr
->szTipText
, -1, &rc
, uFlags
);
559 SelectObject (hdc
, hOldFont
);
560 ReleaseDC (infoPtr
->hwndSelf
, hdc
);
562 if ((style
& TTS_BALLOON
) || infoPtr
->pszTitle
)
564 lpSize
->cx
= max(rc
.right
- rc
.left
, title
.cx
) + 2*BALLOON_TEXT_MARGIN
+
565 infoPtr
->rcMargin
.left
+ infoPtr
->rcMargin
.right
;
566 lpSize
->cy
= title
.cy
+ rc
.bottom
- rc
.top
+ 2*BALLOON_TEXT_MARGIN
+
567 infoPtr
->rcMargin
.bottom
+ infoPtr
->rcMargin
.top
+
572 lpSize
->cx
= rc
.right
- rc
.left
+ 2*NORMAL_TEXT_MARGIN
+
573 infoPtr
->rcMargin
.left
+ infoPtr
->rcMargin
.right
;
574 lpSize
->cy
= rc
.bottom
- rc
.top
+ 2*NORMAL_TEXT_MARGIN
+
575 infoPtr
->rcMargin
.bottom
+ infoPtr
->rcMargin
.top
;
581 TOOLTIPS_Show (TOOLTIPS_INFO
*infoPtr
, BOOL track_activate
)
583 TTTOOL_INFO
*toolPtr
;
585 MONITORINFO mon_info
;
590 DWORD style
= GetWindowLongW(infoPtr
->hwndSelf
, GWL_STYLE
);
595 if (infoPtr
->nTrackTool
== -1)
597 TRACE("invalid tracking tool %d\n", infoPtr
->nTrackTool
);
600 nTool
= infoPtr
->nTrackTool
;
604 if (infoPtr
->nTool
== -1)
606 TRACE("invalid tool %d\n", infoPtr
->nTool
);
609 nTool
= infoPtr
->nTool
;
612 TRACE("Show tooltip pre %d, %p\n", nTool
, infoPtr
->hwndSelf
);
614 current
= infoPtr
->nCurrentTool
;
616 infoPtr
->nCurrentTool
= infoPtr
->nTool
;
618 TOOLTIPS_GetTipText (infoPtr
, nTool
, infoPtr
->szTipText
);
620 if (infoPtr
->szTipText
[0] == '\0')
622 infoPtr
->nCurrentTool
= current
;
626 toolPtr
= &infoPtr
->tools
[nTool
];
628 TRACE("Show tooltip %d\n", nTool
);
630 hdr
.hwndFrom
= infoPtr
->hwndSelf
;
631 hdr
.idFrom
= toolPtr
->uId
;
633 SendMessageW (toolPtr
->hwnd
, WM_NOTIFY
, toolPtr
->uId
, (LPARAM
)&hdr
);
635 TRACE("%s\n", debugstr_w(infoPtr
->szTipText
));
637 TOOLTIPS_CalcTipSize (infoPtr
, &size
);
638 TRACE("size %d x %d\n", size
.cx
, size
.cy
);
640 if (track_activate
&& (toolPtr
->uFlags
& TTF_TRACK
))
642 rect
.left
= infoPtr
->xTrackPos
;
643 rect
.top
= infoPtr
->yTrackPos
;
646 if (toolPtr
->uFlags
& TTF_CENTERTIP
)
648 rect
.left
-= (size
.cx
/ 2);
649 if (!(style
& TTS_BALLOON
))
650 rect
.top
-= (size
.cy
/ 2);
652 if (!(infoPtr
->bToolBelow
= (infoPtr
->yTrackPos
+ size
.cy
<= GetSystemMetrics(SM_CYSCREEN
))))
655 if (!(toolPtr
->uFlags
& TTF_ABSOLUTE
))
657 if (style
& TTS_BALLOON
)
658 rect
.left
-= BALLOON_STEMINDENT
;
663 if (toolPtr
->uFlags
& TTF_IDISHWND
)
664 GetWindowRect ((HWND
)toolPtr
->uId
, &rcTool
);
667 rcTool
= toolPtr
->rect
;
668 MapWindowPoints (toolPtr
->hwnd
, NULL
, (LPPOINT
)&rcTool
, 2);
671 /* smart placement */
672 if ((rect
.left
+ size
.cx
> rcTool
.left
) && (rect
.left
< rcTool
.right
) &&
673 (rect
.top
+ size
.cy
> rcTool
.top
) && (rect
.top
< rcTool
.bottom
))
674 rect
.left
= rcTool
.right
;
680 if (toolPtr
->uFlags
& TTF_CENTERTIP
)
684 if (toolPtr
->uFlags
& TTF_IDISHWND
)
685 GetWindowRect ((HWND
)toolPtr
->uId
, &rc
);
688 MapWindowPoints (toolPtr
->hwnd
, NULL
, (LPPOINT
)&rc
, 2);
690 rect
.left
= (rc
.left
+ rc
.right
- size
.cx
) / 2;
691 if (style
& TTS_BALLOON
)
693 ptfx
= rc
.left
+ ((rc
.right
- rc
.left
) / 2);
695 /* CENTERTIP ballon tooltips default to below the field
696 * if they fit on the screen */
697 if (rc
.bottom
+ size
.cy
> GetSystemMetrics(SM_CYSCREEN
))
699 rect
.top
= rc
.top
- size
.cy
;
700 infoPtr
->bToolBelow
= FALSE
;
704 infoPtr
->bToolBelow
= TRUE
;
705 rect
.top
= rc
.bottom
;
707 rect
.left
= max(0, rect
.left
- BALLOON_STEMINDENT
);
711 rect
.top
= rc
.bottom
+ 2;
712 infoPtr
->bToolBelow
= TRUE
;
717 GetCursorPos ((LPPOINT
)&rect
);
718 if (style
& TTS_BALLOON
)
721 if(rect
.top
- size
.cy
>= 0)
724 infoPtr
->bToolBelow
= FALSE
;
728 infoPtr
->bToolBelow
= TRUE
;
731 rect
.left
= max(0, rect
.left
- BALLOON_STEMINDENT
);
736 infoPtr
->bToolBelow
= TRUE
;
741 TRACE("pos %d - %d\n", rect
.left
, rect
.top
);
743 rect
.right
= rect
.left
+ size
.cx
;
744 rect
.bottom
= rect
.top
+ size
.cy
;
748 monitor
= MonitorFromRect( &rect
, MONITOR_DEFAULTTOPRIMARY
);
749 mon_info
.cbSize
= sizeof(mon_info
);
750 GetMonitorInfoW( monitor
, &mon_info
);
752 if( rect
.right
> mon_info
.rcWork
.right
) {
753 rect
.left
-= rect
.right
- mon_info
.rcWork
.right
+ 2;
754 rect
.right
= mon_info
.rcWork
.right
- 2;
756 if (rect
.left
< mon_info
.rcWork
.left
) rect
.left
= mon_info
.rcWork
.left
;
758 if( rect
.bottom
> mon_info
.rcWork
.bottom
) {
761 if (toolPtr
->uFlags
& TTF_IDISHWND
)
762 GetWindowRect ((HWND
)toolPtr
->uId
, &rc
);
765 MapWindowPoints (toolPtr
->hwnd
, NULL
, (LPPOINT
)&rc
, 2);
767 rect
.bottom
= rc
.top
- 2;
768 rect
.top
= rect
.bottom
- size
.cy
;
771 AdjustWindowRectEx (&rect
, GetWindowLongW (infoPtr
->hwndSelf
, GWL_STYLE
),
772 FALSE
, GetWindowLongW (infoPtr
->hwndSelf
, GWL_EXSTYLE
));
774 if (style
& TTS_BALLOON
)
782 if(infoPtr
->bToolBelow
)
786 pts
[1].x
= max(BALLOON_STEMINDENT
, ptfx
- (BALLOON_STEMWIDTH
/ 2));
787 pts
[1].y
= BALLOON_STEMHEIGHT
;
788 pts
[2].x
= pts
[1].x
+ BALLOON_STEMWIDTH
;
790 if(pts
[2].x
> (rect
.right
- rect
.left
) - BALLOON_STEMINDENT
)
792 pts
[2].x
= (rect
.right
- rect
.left
) - BALLOON_STEMINDENT
;
793 pts
[1].x
= pts
[2].x
- BALLOON_STEMWIDTH
;
798 pts
[0].x
= max(BALLOON_STEMINDENT
, ptfx
- (BALLOON_STEMWIDTH
/ 2));
799 pts
[0].y
= (rect
.bottom
- rect
.top
) - BALLOON_STEMHEIGHT
;
800 pts
[1].x
= pts
[0].x
+ BALLOON_STEMWIDTH
;
803 pts
[2].y
= (rect
.bottom
- rect
.top
);
804 if(pts
[1].x
> (rect
.right
- rect
.left
) - BALLOON_STEMINDENT
)
806 pts
[1].x
= (rect
.right
- rect
.left
) - BALLOON_STEMINDENT
;
807 pts
[0].x
= pts
[1].x
- BALLOON_STEMWIDTH
;
811 hrStem
= CreatePolygonRgn(pts
, sizeof(pts
) / sizeof(pts
[0]), ALTERNATE
);
813 hRgn
= CreateRoundRectRgn(0,
814 (infoPtr
->bToolBelow
? BALLOON_STEMHEIGHT
: 0),
815 rect
.right
- rect
.left
,
816 (infoPtr
->bToolBelow
? rect
.bottom
- rect
.top
: rect
.bottom
- rect
.top
- BALLOON_STEMHEIGHT
),
817 BALLOON_ROUNDEDNESS
, BALLOON_ROUNDEDNESS
);
819 CombineRgn(hRgn
, hRgn
, hrStem
, RGN_OR
);
820 DeleteObject(hrStem
);
822 SetWindowRgn(infoPtr
->hwndSelf
, hRgn
, FALSE
);
823 /* we don't free the region handle as the system deletes it when
824 * it is no longer needed */
827 SetWindowPos (infoPtr
->hwndSelf
, HWND_TOPMOST
, rect
.left
, rect
.top
,
828 rect
.right
- rect
.left
, rect
.bottom
- rect
.top
,
829 SWP_SHOWWINDOW
| SWP_NOACTIVATE
);
831 /* repaint the tooltip */
832 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
833 UpdateWindow(infoPtr
->hwndSelf
);
837 SetTimer (infoPtr
->hwndSelf
, ID_TIMERPOP
, infoPtr
->nAutoPopTime
, 0);
838 TRACE("timer 2 started\n");
839 SetTimer (infoPtr
->hwndSelf
, ID_TIMERLEAVE
, infoPtr
->nReshowTime
, 0);
840 TRACE("timer 3 started\n");
846 TOOLTIPS_Hide (TOOLTIPS_INFO
*infoPtr
)
848 TTTOOL_INFO
*toolPtr
;
851 TRACE("Hide tooltip %d, %p.\n", infoPtr
->nCurrentTool
, infoPtr
->hwndSelf
);
853 if (infoPtr
->nCurrentTool
== -1)
856 toolPtr
= &infoPtr
->tools
[infoPtr
->nCurrentTool
];
857 KillTimer (infoPtr
->hwndSelf
, ID_TIMERPOP
);
859 hdr
.hwndFrom
= infoPtr
->hwndSelf
;
860 hdr
.idFrom
= toolPtr
->uId
;
862 SendMessageW (toolPtr
->hwnd
, WM_NOTIFY
, toolPtr
->uId
, (LPARAM
)&hdr
);
864 infoPtr
->nCurrentTool
= -1;
866 SetWindowPos (infoPtr
->hwndSelf
, HWND_TOP
, 0, 0, 0, 0,
867 SWP_NOZORDER
| SWP_HIDEWINDOW
| SWP_NOACTIVATE
);
872 TOOLTIPS_TrackShow (TOOLTIPS_INFO
*infoPtr
)
874 TOOLTIPS_Show(infoPtr
, TRUE
);
879 TOOLTIPS_TrackHide (const TOOLTIPS_INFO
*infoPtr
)
881 TTTOOL_INFO
*toolPtr
;
884 TRACE("hide tracking tooltip %d\n", infoPtr
->nTrackTool
);
886 if (infoPtr
->nTrackTool
== -1)
889 toolPtr
= &infoPtr
->tools
[infoPtr
->nTrackTool
];
891 hdr
.hwndFrom
= infoPtr
->hwndSelf
;
892 hdr
.idFrom
= toolPtr
->uId
;
894 SendMessageW (toolPtr
->hwnd
, WM_NOTIFY
, toolPtr
->uId
, (LPARAM
)&hdr
);
896 SetWindowPos (infoPtr
->hwndSelf
, HWND_TOP
, 0, 0, 0, 0,
897 SWP_NOZORDER
| SWP_HIDEWINDOW
| SWP_NOACTIVATE
);
900 /* Structure layout is the same for TTTOOLINFOW and TTTOOLINFOA,
901 this helper is used in both cases. */
903 TOOLTIPS_GetToolFromInfoT (const TOOLTIPS_INFO
*infoPtr
, const TTTOOLINFOW
*lpToolInfo
)
905 TTTOOL_INFO
*toolPtr
;
908 for (nTool
= 0; nTool
< infoPtr
->uNumTools
; nTool
++) {
909 toolPtr
= &infoPtr
->tools
[nTool
];
911 if (!(toolPtr
->uFlags
& TTF_IDISHWND
) &&
912 (lpToolInfo
->hwnd
== toolPtr
->hwnd
) &&
913 (lpToolInfo
->uId
== toolPtr
->uId
))
917 for (nTool
= 0; nTool
< infoPtr
->uNumTools
; nTool
++) {
918 toolPtr
= &infoPtr
->tools
[nTool
];
920 if ((toolPtr
->uFlags
& TTF_IDISHWND
) &&
921 (lpToolInfo
->uId
== toolPtr
->uId
))
930 TOOLTIPS_GetToolFromPoint (const TOOLTIPS_INFO
*infoPtr
, HWND hwnd
, const POINT
*lpPt
)
932 TTTOOL_INFO
*toolPtr
;
935 for (nTool
= 0; nTool
< infoPtr
->uNumTools
; nTool
++) {
936 toolPtr
= &infoPtr
->tools
[nTool
];
938 if (!(toolPtr
->uFlags
& TTF_IDISHWND
)) {
939 if (hwnd
!= toolPtr
->hwnd
)
941 if (!PtInRect (&toolPtr
->rect
, *lpPt
))
947 for (nTool
= 0; nTool
< infoPtr
->uNumTools
; nTool
++) {
948 toolPtr
= &infoPtr
->tools
[nTool
];
950 if (toolPtr
->uFlags
& TTF_IDISHWND
) {
951 if ((HWND
)toolPtr
->uId
== hwnd
)
960 TOOLTIPS_CopyInfoT (const TOOLTIPS_INFO
*infoPtr
, INT index
, TTTOOLINFOW
*ti
, BOOL isW
)
962 const TTTOOL_INFO
*toolPtr
= &infoPtr
->tools
[index
];
964 ti
->uFlags
= toolPtr
->uFlags
;
965 ti
->hwnd
= toolPtr
->hwnd
;
966 ti
->uId
= toolPtr
->uId
;
967 ti
->rect
= toolPtr
->rect
;
968 ti
->hinst
= toolPtr
->hinst
;
971 if (toolPtr
->lpszText
== NULL
||
972 IS_INTRESOURCE(toolPtr
->lpszText
) ||
973 toolPtr
->lpszText
== LPSTR_TEXTCALLBACKW
)
974 ti
->lpszText
= toolPtr
->lpszText
;
976 strcpyW (ti
->lpszText
, toolPtr
->lpszText
);
978 /* ANSI version, the buffer is maximum 80 bytes without null. */
979 WideCharToMultiByte(CP_ACP
, 0, toolPtr
->lpszText
, -1,
980 (LPSTR
)ti
->lpszText
, MAX_TEXT_SIZE_A
, NULL
, NULL
);
983 if (ti
->cbSize
>= TTTOOLINFOW_V2_SIZE
)
984 ti
->lParam
= toolPtr
->lParam
;
986 /* lpReserved is intentionally not set. */
990 TOOLTIPS_IsWindowActive (HWND hwnd
)
992 HWND hwndActive
= GetActiveWindow ();
995 if (hwndActive
== hwnd
)
997 return IsChild (hwndActive
, hwnd
);
1002 TOOLTIPS_CheckTool (const TOOLTIPS_INFO
*infoPtr
, BOOL bShowTest
)
1009 hwndTool
= (HWND
)SendMessageW (infoPtr
->hwndSelf
, TTM_WINDOWFROMPOINT
, 0, (LPARAM
)&pt
);
1013 ScreenToClient (hwndTool
, &pt
);
1014 nTool
= TOOLTIPS_GetToolFromPoint (infoPtr
, hwndTool
, &pt
);
1018 if (!(GetWindowLongW (infoPtr
->hwndSelf
, GWL_STYLE
) & TTS_ALWAYSTIP
) && bShowTest
)
1020 TTTOOL_INFO
*ti
= &infoPtr
->tools
[nTool
];
1021 HWND hwnd
= (ti
->uFlags
& TTF_IDISHWND
) ? (HWND
)ti
->uId
: ti
->hwnd
;
1023 if (!TOOLTIPS_IsWindowActive(hwnd
))
1025 TRACE("not active: hwnd %p, parent %p, active %p\n",
1026 hwnd
, GetParent(hwnd
), GetActiveWindow());
1031 TRACE("tool %d\n", nTool
);
1038 TOOLTIPS_Activate (TOOLTIPS_INFO
*infoPtr
, BOOL activate
)
1040 infoPtr
->bActive
= activate
;
1042 TRACE("activate %d\n", activate
);
1044 if (!(infoPtr
->bActive
) && (infoPtr
->nCurrentTool
!= -1))
1045 TOOLTIPS_Hide (infoPtr
);
1052 TOOLTIPS_AddToolT (TOOLTIPS_INFO
*infoPtr
, const TTTOOLINFOW
*ti
, BOOL isW
)
1054 TTTOOL_INFO
*toolPtr
;
1057 if (!ti
) return FALSE
;
1059 TRACE("add tool (%p) %p %ld%s\n", infoPtr
->hwndSelf
, ti
->hwnd
, ti
->uId
,
1060 (ti
->uFlags
& TTF_IDISHWND
) ? " TTF_IDISHWND" : "");
1062 if (ti
->cbSize
>= TTTOOLINFOW_V2_SIZE
&& !ti
->lpszText
&& isW
)
1065 if (infoPtr
->uNumTools
== 0) {
1066 infoPtr
->tools
= Alloc (sizeof(TTTOOL_INFO
));
1067 toolPtr
= infoPtr
->tools
;
1070 TTTOOL_INFO
*oldTools
= infoPtr
->tools
;
1072 Alloc (sizeof(TTTOOL_INFO
) * (infoPtr
->uNumTools
+ 1));
1073 memcpy (infoPtr
->tools
, oldTools
,
1074 infoPtr
->uNumTools
* sizeof(TTTOOL_INFO
));
1076 toolPtr
= &infoPtr
->tools
[infoPtr
->uNumTools
];
1079 infoPtr
->uNumTools
++;
1081 /* copy tool data */
1082 toolPtr
->uFlags
= ti
->uFlags
;
1083 toolPtr
->uInternalFlags
= (ti
->uFlags
& (TTF_SUBCLASS
| TTF_IDISHWND
));
1084 toolPtr
->hwnd
= ti
->hwnd
;
1085 toolPtr
->uId
= ti
->uId
;
1086 toolPtr
->rect
= ti
->rect
;
1087 toolPtr
->hinst
= ti
->hinst
;
1089 if (ti
->cbSize
>= TTTOOLINFOW_V1_SIZE
) {
1090 if (IS_INTRESOURCE(ti
->lpszText
)) {
1091 TRACE("add string id %x\n", LOWORD(ti
->lpszText
));
1092 toolPtr
->lpszText
= ti
->lpszText
;
1094 else if (ti
->lpszText
) {
1095 if (TOOLTIPS_IsCallbackString(ti
->lpszText
, isW
)) {
1096 TRACE("add CALLBACK\n");
1097 toolPtr
->lpszText
= LPSTR_TEXTCALLBACKW
;
1100 INT len
= lstrlenW (ti
->lpszText
);
1101 TRACE("add text %s\n", debugstr_w(ti
->lpszText
));
1102 toolPtr
->lpszText
= Alloc ((len
+ 1)*sizeof(WCHAR
));
1103 strcpyW (toolPtr
->lpszText
, ti
->lpszText
);
1106 INT len
= MultiByteToWideChar(CP_ACP
, 0, (LPSTR
)ti
->lpszText
, -1, NULL
, 0);
1107 TRACE("add text \"%s\"\n", debugstr_a((char *)ti
->lpszText
));
1108 toolPtr
->lpszText
= Alloc (len
* sizeof(WCHAR
));
1109 MultiByteToWideChar(CP_ACP
, 0, (LPSTR
)ti
->lpszText
, -1, toolPtr
->lpszText
, len
);
1114 if (ti
->cbSize
>= TTTOOLINFOW_V2_SIZE
)
1115 toolPtr
->lParam
= ti
->lParam
;
1117 /* install subclassing hook */
1118 if (toolPtr
->uInternalFlags
& TTF_SUBCLASS
) {
1119 if (toolPtr
->uInternalFlags
& TTF_IDISHWND
) {
1120 SetWindowSubclass((HWND
)toolPtr
->uId
, TOOLTIPS_SubclassProc
, 1,
1121 (DWORD_PTR
)infoPtr
->hwndSelf
);
1124 SetWindowSubclass(toolPtr
->hwnd
, TOOLTIPS_SubclassProc
, 1,
1125 (DWORD_PTR
)infoPtr
->hwndSelf
);
1127 TRACE("subclassing installed\n");
1130 nResult
= SendMessageW (toolPtr
->hwnd
, WM_NOTIFYFORMAT
,
1131 (WPARAM
)infoPtr
->hwndSelf
, NF_QUERY
);
1132 if (nResult
== NFR_ANSI
) {
1133 toolPtr
->bNotifyUnicode
= FALSE
;
1134 TRACE(" -- WM_NOTIFYFORMAT returns: NFR_ANSI\n");
1135 } else if (nResult
== NFR_UNICODE
) {
1136 toolPtr
->bNotifyUnicode
= TRUE
;
1137 TRACE(" -- WM_NOTIFYFORMAT returns: NFR_UNICODE\n");
1139 TRACE (" -- WM_NOTIFYFORMAT returns: %d\n", nResult
);
1145 static void TOOLTIPS_ResetSubclass (const TTTOOL_INFO
*toolPtr
)
1147 /* Reset subclassing data. */
1148 if (toolPtr
->uInternalFlags
& TTF_SUBCLASS
)
1149 SetWindowSubclass(toolPtr
->uInternalFlags
& TTF_IDISHWND
? (HWND
)toolPtr
->uId
: toolPtr
->hwnd
,
1150 TOOLTIPS_SubclassProc
, 1, 0);
1154 TOOLTIPS_DelToolT (TOOLTIPS_INFO
*infoPtr
, const TTTOOLINFOW
*ti
, BOOL isW
)
1156 TTTOOL_INFO
*toolPtr
;
1160 if (isW
&& ti
->cbSize
> TTTOOLINFOW_V2_SIZE
&&
1161 ti
->cbSize
!= TTTOOLINFOW_V3_SIZE
)
1163 if (infoPtr
->uNumTools
== 0)
1166 nTool
= TOOLTIPS_GetToolFromInfoT (infoPtr
, ti
);
1168 TRACE("tool %d\n", nTool
);
1173 /* make sure the tooltip has disappeared before deleting it */
1174 TOOLTIPS_Hide(infoPtr
);
1176 /* delete text string */
1177 toolPtr
= &infoPtr
->tools
[nTool
];
1178 if (toolPtr
->lpszText
) {
1179 if ( (toolPtr
->lpszText
!= LPSTR_TEXTCALLBACKW
) &&
1180 !IS_INTRESOURCE(toolPtr
->lpszText
) )
1181 Free (toolPtr
->lpszText
);
1184 TOOLTIPS_ResetSubclass (toolPtr
);
1186 /* delete tool from tool list */
1187 if (infoPtr
->uNumTools
== 1) {
1188 Free (infoPtr
->tools
);
1189 infoPtr
->tools
= NULL
;
1192 TTTOOL_INFO
*oldTools
= infoPtr
->tools
;
1194 Alloc (sizeof(TTTOOL_INFO
) * (infoPtr
->uNumTools
- 1));
1197 memcpy (&infoPtr
->tools
[0], &oldTools
[0],
1198 nTool
* sizeof(TTTOOL_INFO
));
1200 if (nTool
< infoPtr
->uNumTools
- 1)
1201 memcpy (&infoPtr
->tools
[nTool
], &oldTools
[nTool
+ 1],
1202 (infoPtr
->uNumTools
- nTool
- 1) * sizeof(TTTOOL_INFO
));
1207 /* update any indices affected by delete */
1209 /* destroying tool that mouse was on on last relayed mouse move */
1210 if (infoPtr
->nTool
== nTool
)
1211 /* -1 means no current tool (0 means first tool) */
1212 infoPtr
->nTool
= -1;
1213 else if (infoPtr
->nTool
> nTool
)
1216 if (infoPtr
->nTrackTool
== nTool
)
1217 /* -1 means no current tool (0 means first tool) */
1218 infoPtr
->nTrackTool
= -1;
1219 else if (infoPtr
->nTrackTool
> nTool
)
1220 infoPtr
->nTrackTool
--;
1222 if (infoPtr
->nCurrentTool
== nTool
)
1223 /* -1 means no current tool (0 means first tool) */
1224 infoPtr
->nCurrentTool
= -1;
1225 else if (infoPtr
->nCurrentTool
> nTool
)
1226 infoPtr
->nCurrentTool
--;
1228 infoPtr
->uNumTools
--;
1234 TOOLTIPS_EnumToolsT (const TOOLTIPS_INFO
*infoPtr
, UINT uIndex
, TTTOOLINFOW
*ti
,
1237 if (!ti
|| ti
->cbSize
< TTTOOLINFOW_V1_SIZE
)
1239 if (uIndex
>= infoPtr
->uNumTools
)
1242 TRACE("index=%u\n", uIndex
);
1244 TOOLTIPS_CopyInfoT (infoPtr
, uIndex
, ti
, isW
);
1250 TOOLTIPS_GetBubbleSize (const TOOLTIPS_INFO
*infoPtr
, const TTTOOLINFOW
*lpToolInfo
)
1255 if (lpToolInfo
== NULL
)
1257 if (lpToolInfo
->cbSize
< TTTOOLINFOW_V1_SIZE
)
1260 nTool
= TOOLTIPS_GetToolFromInfoT (infoPtr
, lpToolInfo
);
1261 if (nTool
== -1) return 0;
1263 TRACE("tool %d\n", nTool
);
1265 TOOLTIPS_CalcTipSize (infoPtr
, &size
);
1266 TRACE("size %d x %d\n", size
.cx
, size
.cy
);
1268 return MAKELRESULT(size
.cx
, size
.cy
);
1272 TOOLTIPS_GetCurrentToolT (const TOOLTIPS_INFO
*infoPtr
, TTTOOLINFOW
*ti
, BOOL isW
)
1275 if (ti
->cbSize
< TTTOOLINFOW_V1_SIZE
)
1278 if (infoPtr
->nCurrentTool
!= -1)
1279 TOOLTIPS_CopyInfoT (infoPtr
, infoPtr
->nCurrentTool
, ti
, isW
);
1282 return infoPtr
->nCurrentTool
!= -1;
1287 TOOLTIPS_GetDelayTime (const TOOLTIPS_INFO
*infoPtr
, DWORD duration
)
1291 return infoPtr
->nReshowTime
;
1294 return infoPtr
->nAutoPopTime
;
1297 case TTDT_AUTOMATIC
: /* Apparently TTDT_AUTOMATIC returns TTDT_INITIAL */
1298 return infoPtr
->nInitialTime
;
1301 WARN("Invalid duration flag %x\n", duration
);
1310 TOOLTIPS_GetMargin (const TOOLTIPS_INFO
*infoPtr
, RECT
*rect
)
1313 *rect
= infoPtr
->rcMargin
;
1319 static inline LRESULT
1320 TOOLTIPS_GetMaxTipWidth (const TOOLTIPS_INFO
*infoPtr
)
1322 return infoPtr
->nMaxTipWidth
;
1327 TOOLTIPS_GetTextT (const TOOLTIPS_INFO
*infoPtr
, TTTOOLINFOW
*ti
, BOOL isW
)
1332 if (ti
->cbSize
< TTTOOLINFOW_V1_SIZE
)
1335 nTool
= TOOLTIPS_GetToolFromInfoT (infoPtr
, ti
);
1336 if (nTool
== -1) return 0;
1338 if (infoPtr
->tools
[nTool
].lpszText
== NULL
)
1342 ti
->lpszText
[0] = '\0';
1343 TOOLTIPS_GetTipText(infoPtr
, nTool
, ti
->lpszText
);
1346 WCHAR buffer
[INFOTIPSIZE
];
1348 /* NB this API is broken, there is no way for the app to determine
1349 what size buffer it requires nor a way to specify how long the
1350 one it supplies is. According to the test result, it's up to
1351 80 bytes by the ANSI version. */
1354 TOOLTIPS_GetTipText(infoPtr
, nTool
, buffer
);
1355 WideCharToMultiByte(CP_ACP
, 0, buffer
, -1, (LPSTR
)ti
->lpszText
,
1356 MAX_TEXT_SIZE_A
, NULL
, NULL
);
1363 static inline LRESULT
1364 TOOLTIPS_GetTipBkColor (const TOOLTIPS_INFO
*infoPtr
)
1366 return infoPtr
->clrBk
;
1370 static inline LRESULT
1371 TOOLTIPS_GetTipTextColor (const TOOLTIPS_INFO
*infoPtr
)
1373 return infoPtr
->clrText
;
1377 static inline LRESULT
1378 TOOLTIPS_GetToolCount (const TOOLTIPS_INFO
*infoPtr
)
1380 return infoPtr
->uNumTools
;
1385 TOOLTIPS_GetToolInfoT (const TOOLTIPS_INFO
*infoPtr
, TTTOOLINFOW
*ti
, BOOL isW
)
1390 if (!ti
) return FALSE
;
1391 if (ti
->cbSize
< TTTOOLINFOW_V1_SIZE
)
1393 if (infoPtr
->uNumTools
== 0)
1396 nTool
= TOOLTIPS_GetToolFromInfoT (infoPtr
, ti
);
1400 TRACE("tool %d\n", nTool
);
1403 TOOLTIPS_CopyInfoT (infoPtr
, nTool
, ti
, isW
);
1411 TOOLTIPS_HitTestT (const TOOLTIPS_INFO
*infoPtr
, LPTTHITTESTINFOW lptthit
,
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 TOOLTIPS_CopyInfoT (infoPtr
, nTool
, &lptthit
->ti
, isW
);
1434 TOOLTIPS_NewToolRectT (TOOLTIPS_INFO
*infoPtr
, const TTTOOLINFOW
*ti
)
1439 if (ti
->cbSize
< TTTOOLINFOW_V1_SIZE
)
1442 nTool
= TOOLTIPS_GetToolFromInfoT (infoPtr
, ti
);
1444 TRACE("nTool = %d, rect = %s\n", nTool
, wine_dbgstr_rect(&ti
->rect
));
1446 if (nTool
== -1) return 0;
1448 infoPtr
->tools
[nTool
].rect
= ti
->rect
;
1454 static inline LRESULT
1455 TOOLTIPS_Pop (TOOLTIPS_INFO
*infoPtr
)
1457 TOOLTIPS_Hide (infoPtr
);
1464 TOOLTIPS_RelayEvent (TOOLTIPS_INFO
*infoPtr
, LPMSG lpMsg
)
1470 ERR("lpMsg == NULL\n");
1474 switch (lpMsg
->message
) {
1475 case WM_LBUTTONDOWN
:
1477 case WM_MBUTTONDOWN
:
1479 case WM_RBUTTONDOWN
:
1481 TOOLTIPS_Hide (infoPtr
);
1485 pt
.x
= (short)LOWORD(lpMsg
->lParam
);
1486 pt
.y
= (short)HIWORD(lpMsg
->lParam
);
1487 nOldTool
= infoPtr
->nTool
;
1488 infoPtr
->nTool
= TOOLTIPS_GetToolFromPoint(infoPtr
, lpMsg
->hwnd
,
1490 TRACE("tool (%p) %d %d %d\n", infoPtr
->hwndSelf
, nOldTool
,
1491 infoPtr
->nTool
, infoPtr
->nCurrentTool
);
1492 TRACE("WM_MOUSEMOVE (%p %s)\n", infoPtr
->hwndSelf
, wine_dbgstr_point(&pt
));
1494 if (infoPtr
->nTool
!= nOldTool
) {
1495 if(infoPtr
->nTool
== -1) { /* Moved out of all tools */
1496 TOOLTIPS_Hide(infoPtr
);
1497 KillTimer(infoPtr
->hwndSelf
, ID_TIMERLEAVE
);
1498 } else if (nOldTool
== -1) { /* Moved from outside */
1499 if(infoPtr
->bActive
) {
1500 SetTimer(infoPtr
->hwndSelf
, ID_TIMERSHOW
, infoPtr
->nInitialTime
, 0);
1501 TRACE("timer 1 started\n");
1503 } else { /* Moved from one to another */
1504 TOOLTIPS_Hide (infoPtr
);
1505 KillTimer(infoPtr
->hwndSelf
, ID_TIMERLEAVE
);
1506 if(infoPtr
->bActive
) {
1507 SetTimer (infoPtr
->hwndSelf
, ID_TIMERSHOW
, infoPtr
->nReshowTime
, 0);
1508 TRACE("timer 1 started\n");
1511 } else if(infoPtr
->nCurrentTool
!= -1) { /* restart autopop */
1512 KillTimer(infoPtr
->hwndSelf
, ID_TIMERPOP
);
1513 SetTimer(infoPtr
->hwndSelf
, ID_TIMERPOP
, infoPtr
->nAutoPopTime
, 0);
1514 TRACE("timer 2 restarted\n");
1515 } else if(infoPtr
->nTool
!= -1 && infoPtr
->bActive
) {
1516 /* previous show attempt didn't result in tooltip so try again */
1517 SetTimer(infoPtr
->hwndSelf
, ID_TIMERSHOW
, infoPtr
->nInitialTime
, 0);
1518 TRACE("timer 1 started\n");
1528 TOOLTIPS_SetDelayTime (TOOLTIPS_INFO
*infoPtr
, DWORD duration
, INT nTime
)
1531 case TTDT_AUTOMATIC
:
1533 nTime
= GetDoubleClickTime();
1534 infoPtr
->nReshowTime
= nTime
/ 5;
1535 infoPtr
->nAutoPopTime
= nTime
* 10;
1536 infoPtr
->nInitialTime
= nTime
;
1541 nTime
= GetDoubleClickTime() / 5;
1542 infoPtr
->nReshowTime
= nTime
;
1547 nTime
= GetDoubleClickTime() * 10;
1548 infoPtr
->nAutoPopTime
= nTime
;
1553 nTime
= GetDoubleClickTime();
1554 infoPtr
->nInitialTime
= nTime
;
1558 WARN("Invalid duration flag %x\n", duration
);
1567 TOOLTIPS_SetMargin (TOOLTIPS_INFO
*infoPtr
, const RECT
*rect
)
1570 infoPtr
->rcMargin
= *rect
;
1576 static inline LRESULT
1577 TOOLTIPS_SetMaxTipWidth (TOOLTIPS_INFO
*infoPtr
, INT MaxWidth
)
1579 INT nTemp
= infoPtr
->nMaxTipWidth
;
1581 infoPtr
->nMaxTipWidth
= MaxWidth
;
1587 static inline LRESULT
1588 TOOLTIPS_SetTipBkColor (TOOLTIPS_INFO
*infoPtr
, COLORREF clrBk
)
1590 infoPtr
->clrBk
= clrBk
;
1596 static inline LRESULT
1597 TOOLTIPS_SetTipTextColor (TOOLTIPS_INFO
*infoPtr
, COLORREF clrText
)
1599 infoPtr
->clrText
= clrText
;
1606 TOOLTIPS_SetTitleT (TOOLTIPS_INFO
*infoPtr
, UINT_PTR uTitleIcon
, LPCWSTR pszTitle
,
1611 TRACE("hwnd = %p, title = %s, icon = %p\n", infoPtr
->hwndSelf
, debugstr_w(pszTitle
),
1614 Free(infoPtr
->pszTitle
);
1620 size
= (strlenW(pszTitle
)+1)*sizeof(WCHAR
);
1621 infoPtr
->pszTitle
= Alloc(size
);
1622 if (!infoPtr
->pszTitle
)
1624 memcpy(infoPtr
->pszTitle
, pszTitle
, size
);
1628 size
= sizeof(WCHAR
)*MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)pszTitle
, -1, NULL
, 0);
1629 infoPtr
->pszTitle
= Alloc(size
);
1630 if (!infoPtr
->pszTitle
)
1632 MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)pszTitle
, -1, infoPtr
->pszTitle
, size
/sizeof(WCHAR
));
1636 infoPtr
->pszTitle
= NULL
;
1638 if (uTitleIcon
<= TTI_ERROR
)
1639 infoPtr
->hTitleIcon
= hTooltipIcons
[uTitleIcon
];
1641 infoPtr
->hTitleIcon
= CopyIcon((HICON
)uTitleIcon
);
1643 TRACE("icon = %p\n", infoPtr
->hTitleIcon
);
1650 TOOLTIPS_SetToolInfoT (TOOLTIPS_INFO
*infoPtr
, const TTTOOLINFOW
*ti
, BOOL isW
)
1652 TTTOOL_INFO
*toolPtr
;
1656 if (ti
->cbSize
< TTTOOLINFOW_V1_SIZE
)
1659 nTool
= TOOLTIPS_GetToolFromInfoT (infoPtr
, ti
);
1660 if (nTool
== -1) return 0;
1662 TRACE("tool %d\n", nTool
);
1664 toolPtr
= &infoPtr
->tools
[nTool
];
1666 /* copy tool data */
1667 toolPtr
->uFlags
= ti
->uFlags
;
1668 toolPtr
->hwnd
= ti
->hwnd
;
1669 toolPtr
->uId
= ti
->uId
;
1670 toolPtr
->rect
= ti
->rect
;
1671 toolPtr
->hinst
= ti
->hinst
;
1673 if (IS_INTRESOURCE(ti
->lpszText
)) {
1674 TRACE("set string id %x\n", LOWORD(ti
->lpszText
));
1675 toolPtr
->lpszText
= ti
->lpszText
;
1678 if (TOOLTIPS_IsCallbackString(ti
->lpszText
, isW
))
1679 toolPtr
->lpszText
= LPSTR_TEXTCALLBACKW
;
1681 if ( (toolPtr
->lpszText
) &&
1682 !IS_INTRESOURCE(toolPtr
->lpszText
) ) {
1683 if( toolPtr
->lpszText
!= LPSTR_TEXTCALLBACKW
)
1684 Free (toolPtr
->lpszText
);
1685 toolPtr
->lpszText
= NULL
;
1689 INT len
= lstrlenW (ti
->lpszText
);
1690 toolPtr
->lpszText
= Alloc ((len
+1)*sizeof(WCHAR
));
1691 strcpyW (toolPtr
->lpszText
, ti
->lpszText
);
1694 INT len
= MultiByteToWideChar(CP_ACP
, 0, (LPSTR
)ti
->lpszText
,
1696 toolPtr
->lpszText
= Alloc (len
* sizeof(WCHAR
));
1697 MultiByteToWideChar(CP_ACP
, 0, (LPSTR
)ti
->lpszText
, -1,
1698 toolPtr
->lpszText
, len
);
1704 if (ti
->cbSize
>= TTTOOLINFOW_V2_SIZE
)
1705 toolPtr
->lParam
= ti
->lParam
;
1707 if (infoPtr
->nCurrentTool
== nTool
)
1709 TOOLTIPS_GetTipText (infoPtr
, infoPtr
->nCurrentTool
, infoPtr
->szTipText
);
1711 if (infoPtr
->szTipText
[0] == 0)
1712 TOOLTIPS_Hide(infoPtr
);
1714 TOOLTIPS_Show (infoPtr
, FALSE
);
1722 TOOLTIPS_TrackActivate (TOOLTIPS_INFO
*infoPtr
, BOOL track_activate
, const TTTOOLINFOA
*ti
)
1724 if (track_activate
) {
1727 if (ti
->cbSize
< TTTOOLINFOA_V1_SIZE
)
1731 infoPtr
->nTrackTool
= TOOLTIPS_GetToolFromInfoT (infoPtr
, (const TTTOOLINFOW
*)ti
);
1732 if (infoPtr
->nTrackTool
!= -1) {
1733 TRACE("activated\n");
1734 infoPtr
->bTrackActive
= TRUE
;
1735 TOOLTIPS_TrackShow (infoPtr
);
1740 TOOLTIPS_TrackHide (infoPtr
);
1742 infoPtr
->bTrackActive
= FALSE
;
1743 infoPtr
->nTrackTool
= -1;
1745 TRACE("deactivated\n");
1753 TOOLTIPS_TrackPosition (TOOLTIPS_INFO
*infoPtr
, LPARAM coord
)
1755 infoPtr
->xTrackPos
= (INT
)LOWORD(coord
);
1756 infoPtr
->yTrackPos
= (INT
)HIWORD(coord
);
1758 if (infoPtr
->bTrackActive
) {
1760 infoPtr
->xTrackPos
, infoPtr
->yTrackPos
);
1762 TOOLTIPS_TrackShow (infoPtr
);
1770 TOOLTIPS_Update (TOOLTIPS_INFO
*infoPtr
)
1772 if (infoPtr
->nCurrentTool
!= -1)
1773 UpdateWindow (infoPtr
->hwndSelf
);
1780 TOOLTIPS_UpdateTipTextT (TOOLTIPS_INFO
*infoPtr
, const TTTOOLINFOW
*ti
, BOOL isW
)
1782 TTTOOL_INFO
*toolPtr
;
1786 if (ti
->cbSize
< TTTOOLINFOW_V1_SIZE
)
1789 nTool
= TOOLTIPS_GetToolFromInfoT (infoPtr
, ti
);
1793 TRACE("tool %d\n", nTool
);
1795 toolPtr
= &infoPtr
->tools
[nTool
];
1797 /* copy tool text */
1798 toolPtr
->hinst
= ti
->hinst
;
1800 if (IS_INTRESOURCE(ti
->lpszText
)){
1801 toolPtr
->lpszText
= ti
->lpszText
;
1803 else if (ti
->lpszText
) {
1804 if (TOOLTIPS_IsCallbackString(ti
->lpszText
, isW
))
1805 toolPtr
->lpszText
= LPSTR_TEXTCALLBACKW
;
1807 if ( (toolPtr
->lpszText
) &&
1808 !IS_INTRESOURCE(toolPtr
->lpszText
) ) {
1809 if( toolPtr
->lpszText
!= LPSTR_TEXTCALLBACKW
)
1810 Free (toolPtr
->lpszText
);
1811 toolPtr
->lpszText
= NULL
;
1815 INT len
= lstrlenW (ti
->lpszText
);
1816 toolPtr
->lpszText
= Alloc ((len
+1)*sizeof(WCHAR
));
1817 strcpyW (toolPtr
->lpszText
, ti
->lpszText
);
1820 INT len
= MultiByteToWideChar(CP_ACP
, 0, (LPSTR
)ti
->lpszText
,
1822 toolPtr
->lpszText
= Alloc (len
* sizeof(WCHAR
));
1823 MultiByteToWideChar(CP_ACP
, 0, (LPSTR
)ti
->lpszText
, -1,
1824 toolPtr
->lpszText
, len
);
1830 if(infoPtr
->nCurrentTool
== -1) return 0;
1832 if (infoPtr
->bActive
)
1833 TOOLTIPS_Show (infoPtr
, FALSE
);
1834 else if (infoPtr
->bTrackActive
)
1835 TOOLTIPS_Show (infoPtr
, TRUE
);
1842 TOOLTIPS_Create (HWND hwnd
)
1844 TOOLTIPS_INFO
*infoPtr
;
1846 /* allocate memory for info structure */
1847 infoPtr
= Alloc (sizeof(TOOLTIPS_INFO
));
1848 SetWindowLongPtrW (hwnd
, 0, (DWORD_PTR
)infoPtr
);
1850 /* initialize info structure */
1851 infoPtr
->bActive
= TRUE
;
1852 infoPtr
->bTrackActive
= FALSE
;
1854 infoPtr
->nMaxTipWidth
= -1;
1855 infoPtr
->nTool
= -1;
1856 infoPtr
->nCurrentTool
= -1;
1857 infoPtr
->nTrackTool
= -1;
1858 infoPtr
->hwndSelf
= hwnd
;
1860 /* initialize colours and fonts */
1861 TOOLTIPS_InitSystemSettings(infoPtr
);
1863 TOOLTIPS_SetDelayTime(infoPtr
, TTDT_AUTOMATIC
, 0);
1865 SetWindowPos (hwnd
, HWND_TOP
, 0, 0, 0, 0, SWP_NOZORDER
| SWP_HIDEWINDOW
| SWP_NOACTIVATE
);
1872 TOOLTIPS_Destroy (TOOLTIPS_INFO
*infoPtr
)
1874 TTTOOL_INFO
*toolPtr
;
1878 if (infoPtr
->tools
) {
1879 for (i
= 0; i
< infoPtr
->uNumTools
; i
++) {
1880 toolPtr
= &infoPtr
->tools
[i
];
1881 if (toolPtr
->lpszText
) {
1882 if ( (toolPtr
->lpszText
!= LPSTR_TEXTCALLBACKW
) &&
1883 !IS_INTRESOURCE(toolPtr
->lpszText
) )
1885 Free (toolPtr
->lpszText
);
1886 toolPtr
->lpszText
= NULL
;
1890 TOOLTIPS_ResetSubclass (toolPtr
);
1893 Free (infoPtr
->tools
);
1896 /* free title string */
1897 Free (infoPtr
->pszTitle
);
1898 /* free title icon if not a standard one */
1899 if (TOOLTIPS_GetTitleIconIndex(infoPtr
->hTitleIcon
) > TTI_ERROR
)
1900 DeleteObject(infoPtr
->hTitleIcon
);
1903 DeleteObject (infoPtr
->hFont
);
1904 DeleteObject (infoPtr
->hTitleFont
);
1906 /* free tool tips info data */
1907 SetWindowLongPtrW(infoPtr
->hwndSelf
, 0, 0);
1914 static inline LRESULT
1915 TOOLTIPS_GetFont (const TOOLTIPS_INFO
*infoPtr
)
1917 return (LRESULT
)infoPtr
->hFont
;
1922 TOOLTIPS_MouseMessage (TOOLTIPS_INFO
*infoPtr
)
1924 TOOLTIPS_Hide (infoPtr
);
1931 TOOLTIPS_NCCreate (HWND hwnd
)
1933 DWORD dwStyle
= GetWindowLongW (hwnd
, GWL_STYLE
);
1934 DWORD dwExStyle
= GetWindowLongW (hwnd
, GWL_EXSTYLE
);
1936 dwStyle
&= ~(WS_CHILD
| /*WS_MAXIMIZE |*/ WS_BORDER
| WS_DLGFRAME
);
1937 dwStyle
|= (WS_POPUP
| WS_BORDER
| WS_CLIPSIBLINGS
);
1939 /* WS_BORDER only draws a border round the window rect, not the
1940 * window region, therefore it is useless to us in balloon mode */
1941 if (dwStyle
& TTS_BALLOON
) dwStyle
&= ~WS_BORDER
;
1943 SetWindowLongW (hwnd
, GWL_STYLE
, dwStyle
);
1945 dwExStyle
|= WS_EX_TOOLWINDOW
;
1946 SetWindowLongW (hwnd
, GWL_EXSTYLE
, dwExStyle
);
1953 TOOLTIPS_NCHitTest (const TOOLTIPS_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
1955 INT nTool
= (infoPtr
->bTrackActive
) ? infoPtr
->nTrackTool
: infoPtr
->nTool
;
1957 TRACE(" nTool=%d\n", nTool
);
1959 if ((nTool
> -1) && (nTool
< infoPtr
->uNumTools
)) {
1960 if (infoPtr
->tools
[nTool
].uFlags
& TTF_TRANSPARENT
) {
1961 TRACE("-- in transparent mode\n");
1962 return HTTRANSPARENT
;
1966 return DefWindowProcW (infoPtr
->hwndSelf
, WM_NCHITTEST
, wParam
, lParam
);
1971 TOOLTIPS_NotifyFormat (TOOLTIPS_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
1973 FIXME ("hwnd=%p wParam=%lx lParam=%lx\n", infoPtr
->hwndSelf
, wParam
, lParam
);
1980 TOOLTIPS_Paint (const TOOLTIPS_INFO
*infoPtr
, HDC hDC
)
1985 hdc
= (hDC
== NULL
) ? BeginPaint (infoPtr
->hwndSelf
, &ps
) : hDC
;
1986 TOOLTIPS_Refresh (infoPtr
, hdc
);
1988 EndPaint (infoPtr
->hwndSelf
, &ps
);
1994 TOOLTIPS_SetFont (TOOLTIPS_INFO
*infoPtr
, HFONT hFont
, BOOL redraw
)
1998 if(!GetObjectW(hFont
, sizeof(lf
), &lf
))
2001 DeleteObject (infoPtr
->hFont
);
2002 infoPtr
->hFont
= CreateFontIndirectW(&lf
);
2004 DeleteObject (infoPtr
->hTitleFont
);
2005 lf
.lfWeight
= FW_BOLD
;
2006 infoPtr
->hTitleFont
= CreateFontIndirectW(&lf
);
2008 if (redraw
&& infoPtr
->nCurrentTool
!= -1)
2009 FIXME("full redraw needed\n");
2014 /******************************************************************
2015 * TOOLTIPS_GetTextLength
2017 * This function is called when the tooltip receive a
2018 * WM_GETTEXTLENGTH message.
2020 * returns the length, in characters, of the tip text
2022 static inline LRESULT
2023 TOOLTIPS_GetTextLength(const TOOLTIPS_INFO
*infoPtr
)
2025 return strlenW(infoPtr
->szTipText
);
2028 /******************************************************************
2029 * TOOLTIPS_OnWMGetText
2031 * This function is called when the tooltip receive a
2032 * WM_GETTEXT message.
2033 * wParam : specifies the maximum number of characters to be copied
2034 * lParam : is the pointer to the buffer that will receive
2037 * returns the number of characters copied
2040 TOOLTIPS_OnWMGetText (const TOOLTIPS_INFO
*infoPtr
, WPARAM size
, LPWSTR pszText
)
2047 res
= min(strlenW(infoPtr
->szTipText
)+1, size
);
2048 memcpy(pszText
, infoPtr
->szTipText
, res
*sizeof(WCHAR
));
2049 pszText
[res
-1] = '\0';
2054 TOOLTIPS_Timer (TOOLTIPS_INFO
*infoPtr
, INT iTimer
)
2058 TRACE("timer %d (%p) expired\n", iTimer
, infoPtr
->hwndSelf
);
2062 KillTimer (infoPtr
->hwndSelf
, ID_TIMERSHOW
);
2063 nOldTool
= infoPtr
->nTool
;
2064 if ((infoPtr
->nTool
= TOOLTIPS_CheckTool (infoPtr
, TRUE
)) == nOldTool
)
2065 TOOLTIPS_Show (infoPtr
, FALSE
);
2069 TOOLTIPS_Hide (infoPtr
);
2073 nOldTool
= infoPtr
->nTool
;
2074 infoPtr
->nTool
= TOOLTIPS_CheckTool (infoPtr
, FALSE
);
2075 TRACE("tool (%p) %d %d %d\n", infoPtr
->hwndSelf
, nOldTool
,
2076 infoPtr
->nTool
, infoPtr
->nCurrentTool
);
2077 if (infoPtr
->nTool
!= nOldTool
) {
2078 if(infoPtr
->nTool
== -1) { /* Moved out of all tools */
2079 TOOLTIPS_Hide(infoPtr
);
2080 KillTimer(infoPtr
->hwndSelf
, ID_TIMERLEAVE
);
2081 } else if (nOldTool
== -1) { /* Moved from outside */
2082 ERR("How did this happen?\n");
2083 } else { /* Moved from one to another */
2084 TOOLTIPS_Hide (infoPtr
);
2085 KillTimer(infoPtr
->hwndSelf
, ID_TIMERLEAVE
);
2086 if(infoPtr
->bActive
) {
2087 SetTimer (infoPtr
->hwndSelf
, ID_TIMERSHOW
, infoPtr
->nReshowTime
, 0);
2088 TRACE("timer 1 started!\n");
2095 ERR("Unknown timer id %d\n", iTimer
);
2103 TOOLTIPS_WinIniChange (TOOLTIPS_INFO
*infoPtr
)
2105 TOOLTIPS_InitSystemSettings (infoPtr
);
2111 static LRESULT CALLBACK
2112 TOOLTIPS_SubclassProc (HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
, UINT_PTR uID
, DWORD_PTR dwRef
)
2114 TOOLTIPS_INFO
*infoPtr
= TOOLTIPS_GetInfoPtr ((HWND
)dwRef
);
2120 case WM_LBUTTONDOWN
:
2122 case WM_MBUTTONDOWN
:
2124 case WM_RBUTTONDOWN
:
2129 msg
.message
= message
;
2130 msg
.wParam
= wParam
;
2131 msg
.lParam
= lParam
;
2132 TOOLTIPS_RelayEvent(infoPtr
, &msg
);
2136 RemoveWindowSubclass(hwnd
, TOOLTIPS_SubclassProc
, 1);
2142 return DefSubclassProc(hwnd
, message
, wParam
, lParam
);
2146 static LRESULT CALLBACK
2147 TOOLTIPS_WindowProc (HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
2149 TOOLTIPS_INFO
*infoPtr
= TOOLTIPS_GetInfoPtr (hwnd
);
2151 TRACE("hwnd=%p msg=%x wparam=%lx lParam=%lx\n", hwnd
, uMsg
, wParam
, lParam
);
2152 if (!infoPtr
&& (uMsg
!= WM_CREATE
) && (uMsg
!= WM_NCCREATE
))
2153 return DefWindowProcW (hwnd
, uMsg
, wParam
, lParam
);
2157 return TOOLTIPS_Activate (infoPtr
, (BOOL
)wParam
);
2161 return TOOLTIPS_AddToolT (infoPtr
, (LPTTTOOLINFOW
)lParam
, uMsg
== TTM_ADDTOOLW
);
2165 return TOOLTIPS_DelToolT (infoPtr
, (LPTOOLINFOW
)lParam
,
2166 uMsg
== TTM_DELTOOLW
);
2167 case TTM_ENUMTOOLSA
:
2168 case TTM_ENUMTOOLSW
:
2169 return TOOLTIPS_EnumToolsT (infoPtr
, (UINT
)wParam
, (LPTTTOOLINFOW
)lParam
,
2170 uMsg
== TTM_ENUMTOOLSW
);
2171 case TTM_GETBUBBLESIZE
:
2172 return TOOLTIPS_GetBubbleSize (infoPtr
, (LPTTTOOLINFOW
)lParam
);
2174 case TTM_GETCURRENTTOOLA
:
2175 case TTM_GETCURRENTTOOLW
:
2176 return TOOLTIPS_GetCurrentToolT (infoPtr
, (LPTTTOOLINFOW
)lParam
,
2177 uMsg
== TTM_GETCURRENTTOOLW
);
2179 case TTM_GETDELAYTIME
:
2180 return TOOLTIPS_GetDelayTime (infoPtr
, (DWORD
)wParam
);
2183 return TOOLTIPS_GetMargin (infoPtr
, (LPRECT
)lParam
);
2185 case TTM_GETMAXTIPWIDTH
:
2186 return TOOLTIPS_GetMaxTipWidth (infoPtr
);
2190 return TOOLTIPS_GetTextT (infoPtr
, (LPTTTOOLINFOW
)lParam
,
2191 uMsg
== TTM_GETTEXTW
);
2193 case TTM_GETTIPBKCOLOR
:
2194 return TOOLTIPS_GetTipBkColor (infoPtr
);
2196 case TTM_GETTIPTEXTCOLOR
:
2197 return TOOLTIPS_GetTipTextColor (infoPtr
);
2199 case TTM_GETTOOLCOUNT
:
2200 return TOOLTIPS_GetToolCount (infoPtr
);
2202 case TTM_GETTOOLINFOA
:
2203 case TTM_GETTOOLINFOW
:
2204 return TOOLTIPS_GetToolInfoT (infoPtr
, (LPTTTOOLINFOW
)lParam
,
2205 uMsg
== TTM_GETTOOLINFOW
);
2209 return TOOLTIPS_HitTestT (infoPtr
, (LPTTHITTESTINFOW
)lParam
,
2210 uMsg
== TTM_HITTESTW
);
2211 case TTM_NEWTOOLRECTA
:
2212 case TTM_NEWTOOLRECTW
:
2213 return TOOLTIPS_NewToolRectT (infoPtr
, (LPTTTOOLINFOW
)lParam
);
2216 return TOOLTIPS_Pop (infoPtr
);
2218 case TTM_RELAYEVENT
:
2219 return TOOLTIPS_RelayEvent (infoPtr
, (LPMSG
)lParam
);
2221 case TTM_SETDELAYTIME
:
2222 return TOOLTIPS_SetDelayTime (infoPtr
, (DWORD
)wParam
, (INT
)LOWORD(lParam
));
2225 return TOOLTIPS_SetMargin (infoPtr
, (LPRECT
)lParam
);
2227 case TTM_SETMAXTIPWIDTH
:
2228 return TOOLTIPS_SetMaxTipWidth (infoPtr
, (INT
)lParam
);
2230 case TTM_SETTIPBKCOLOR
:
2231 return TOOLTIPS_SetTipBkColor (infoPtr
, (COLORREF
)wParam
);
2233 case TTM_SETTIPTEXTCOLOR
:
2234 return TOOLTIPS_SetTipTextColor (infoPtr
, (COLORREF
)wParam
);
2238 return TOOLTIPS_SetTitleT (infoPtr
, (UINT_PTR
)wParam
, (LPCWSTR
)lParam
,
2239 uMsg
== TTM_SETTITLEW
);
2241 case TTM_SETTOOLINFOA
:
2242 case TTM_SETTOOLINFOW
:
2243 return TOOLTIPS_SetToolInfoT (infoPtr
, (LPTTTOOLINFOW
)lParam
,
2244 uMsg
== TTM_SETTOOLINFOW
);
2246 case TTM_TRACKACTIVATE
:
2247 return TOOLTIPS_TrackActivate (infoPtr
, (BOOL
)wParam
, (LPTTTOOLINFOA
)lParam
);
2249 case TTM_TRACKPOSITION
:
2250 return TOOLTIPS_TrackPosition (infoPtr
, lParam
);
2253 return TOOLTIPS_Update (infoPtr
);
2255 case TTM_UPDATETIPTEXTA
:
2256 case TTM_UPDATETIPTEXTW
:
2257 return TOOLTIPS_UpdateTipTextT (infoPtr
, (LPTTTOOLINFOW
)lParam
,
2258 uMsg
== TTM_UPDATETIPTEXTW
);
2260 case TTM_WINDOWFROMPOINT
:
2261 return (LRESULT
)WindowFromPoint (*((LPPOINT
)lParam
));
2264 return TOOLTIPS_Create (hwnd
);
2267 return TOOLTIPS_Destroy (infoPtr
);
2270 /* we draw the background in WM_PAINT */
2274 return TOOLTIPS_GetFont (infoPtr
);
2277 return TOOLTIPS_OnWMGetText (infoPtr
, wParam
, (LPWSTR
)lParam
);
2279 case WM_GETTEXTLENGTH
:
2280 return TOOLTIPS_GetTextLength (infoPtr
);
2282 case WM_LBUTTONDOWN
:
2284 case WM_MBUTTONDOWN
:
2286 case WM_RBUTTONDOWN
:
2289 return TOOLTIPS_MouseMessage (infoPtr
);
2292 return TOOLTIPS_NCCreate (hwnd
);
2295 return TOOLTIPS_NCHitTest (infoPtr
, wParam
, lParam
);
2297 case WM_NOTIFYFORMAT
:
2298 return TOOLTIPS_NotifyFormat (infoPtr
, wParam
, lParam
);
2300 case WM_PRINTCLIENT
:
2302 return TOOLTIPS_Paint (infoPtr
, (HDC
)wParam
);
2305 return TOOLTIPS_SetFont (infoPtr
, (HFONT
)wParam
, LOWORD(lParam
));
2307 case WM_SYSCOLORCHANGE
:
2308 COMCTL32_RefreshSysColors();
2312 return TOOLTIPS_Timer (infoPtr
, (INT
)wParam
);
2314 case WM_WININICHANGE
:
2315 return TOOLTIPS_WinIniChange (infoPtr
);
2318 if ((uMsg
>= WM_USER
) && (uMsg
< WM_APP
) && !COMCTL32_IsReflectedMessage(uMsg
))
2319 ERR("unknown msg %04x wp=%08lx lp=%08lx\n",
2320 uMsg
, wParam
, lParam
);
2321 return DefWindowProcW (hwnd
, uMsg
, wParam
, lParam
);
2327 TOOLTIPS_Register (void)
2331 ZeroMemory (&wndClass
, sizeof(WNDCLASSW
));
2332 wndClass
.style
= CS_GLOBALCLASS
| CS_DBLCLKS
| CS_SAVEBITS
;
2333 wndClass
.lpfnWndProc
= TOOLTIPS_WindowProc
;
2334 wndClass
.cbClsExtra
= 0;
2335 wndClass
.cbWndExtra
= sizeof(TOOLTIPS_INFO
*);
2336 wndClass
.hCursor
= LoadCursorW (0, (LPWSTR
)IDC_ARROW
);
2337 wndClass
.hbrBackground
= 0;
2338 wndClass
.lpszClassName
= TOOLTIPS_CLASSW
;
2340 RegisterClassW (&wndClass
);
2342 hTooltipIcons
[TTI_NONE
] = NULL
;
2343 hTooltipIcons
[TTI_INFO
] = LoadImageW(COMCTL32_hModule
,
2344 (LPCWSTR
)MAKEINTRESOURCE(IDI_TT_INFO_SM
), IMAGE_ICON
, 0, 0, 0);
2345 hTooltipIcons
[TTI_WARNING
] = LoadImageW(COMCTL32_hModule
,
2346 (LPCWSTR
)MAKEINTRESOURCE(IDI_TT_WARN_SM
), IMAGE_ICON
, 0, 0, 0);
2347 hTooltipIcons
[TTI_ERROR
] = LoadImageW(COMCTL32_hModule
,
2348 (LPCWSTR
)MAKEINTRESOURCE(IDI_TT_ERROR_SM
), IMAGE_ICON
, 0, 0, 0);
2353 TOOLTIPS_Unregister (void)
2356 for (i
= TTI_INFO
; i
<= TTI_ERROR
; i
++)
2357 DestroyIcon(hTooltipIcons
[i
]);
2358 UnregisterClassW (TOOLTIPS_CLASSW
, NULL
);