cabinet: Call FCI function pointers explicitly instead of hiding them inside macros.
[wine.git] / dlls / comctl32 / tooltips.c
bloba2e58e08ca3fe8367dc59e932d83fce95795a940
1 /*
2 * Tool tip control
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
21 * NOTES
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.
30 * TODO:
31 * - Custom draw support.
32 * - Animation.
33 * - Links.
34 * - Messages:
35 * o TTM_ADJUSTRECT
36 * o TTM_GETTITLEA
37 * o TTM_GETTTILEW
38 * o TTM_POPUP
39 * - Styles:
40 * o TTS_NOANIMATE
41 * o TTS_NOFADE
42 * o TTS_CLOSE
44 * Testing:
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.
50 * Timer logic.
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
59 * ID_TIMERLEAVE.
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
79 * tool.
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
88 * BOOL.
94 #include <stdarg.h>
95 #include <string.h>
97 #include "windef.h"
98 #include "winbase.h"
99 #include "wine/unicode.h"
100 #include "wingdi.h"
101 #include "winuser.h"
102 #include "winnls.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];
111 typedef struct
113 UINT uFlags;
114 HWND hwnd;
115 BOOL bNotifyUnicode;
116 UINT_PTR uId;
117 RECT rect;
118 HINSTANCE hinst;
119 LPWSTR lpszText;
120 LPARAM lParam;
121 } TTTOOL_INFO;
124 typedef struct
126 HWND hwndSelf;
127 WCHAR szTipText[INFOTIPSIZE];
128 BOOL bActive;
129 BOOL bTrackActive;
130 UINT uNumTools;
131 COLORREF clrBk;
132 COLORREF clrText;
133 HFONT hFont;
134 HFONT hTitleFont;
135 INT xTrackPos;
136 INT yTrackPos;
137 INT nMaxTipWidth;
138 INT nTool; /* tool that mouse was on on last relayed mouse move */
139 INT nCurrentTool;
140 INT nTrackTool;
141 INT nReshowTime;
142 INT nAutoPopTime;
143 INT nInitialTime;
144 RECT rcMargin;
145 BOOL bToolBelow;
146 LPWSTR pszTitle;
147 HICON hTitleIcon;
149 TTTOOL_INFO *tools;
150 } TOOLTIPS_INFO;
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 static LRESULT CALLBACK
175 TOOLTIPS_SubclassProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uId, DWORD_PTR dwRef);
178 static inline BOOL TOOLTIPS_IsCallbackString(LPCWSTR str, BOOL isW)
180 if (isW)
181 return str == LPSTR_TEXTCALLBACKW;
182 else
183 return (LPCSTR)str == LPSTR_TEXTCALLBACKA;
186 static inline UINT_PTR
187 TOOLTIPS_GetTitleIconIndex(HICON hIcon)
189 UINT i;
190 for (i = 0; i <= TTI_ERROR; i++)
191 if (hTooltipIcons[i] == hIcon)
192 return i;
193 return (UINT_PTR)hIcon;
196 static void
197 TOOLTIPS_InitSystemSettings (TOOLTIPS_INFO *infoPtr)
199 NONCLIENTMETRICSW nclm;
201 infoPtr->clrBk = comctl32_color.clrInfoBk;
202 infoPtr->clrText = comctl32_color.clrInfoText;
204 DeleteObject (infoPtr->hFont);
205 nclm.cbSize = sizeof(nclm);
206 SystemParametersInfoW (SPI_GETNONCLIENTMETRICS, sizeof(nclm), &nclm, 0);
207 infoPtr->hFont = CreateFontIndirectW (&nclm.lfStatusFont);
209 DeleteObject (infoPtr->hTitleFont);
210 nclm.lfStatusFont.lfWeight = FW_BOLD;
211 infoPtr->hTitleFont = CreateFontIndirectW (&nclm.lfStatusFont);
214 /* Custom draw routines */
215 static void
216 TOOLTIPS_customdraw_fill(const TOOLTIPS_INFO *infoPtr, NMTTCUSTOMDRAW *lpnmttcd,
217 HDC hdc, const RECT *rcBounds, UINT uFlags)
219 ZeroMemory(lpnmttcd, sizeof(NMTTCUSTOMDRAW));
220 lpnmttcd->uDrawFlags = uFlags;
221 lpnmttcd->nmcd.hdr.hwndFrom = infoPtr->hwndSelf;
222 lpnmttcd->nmcd.hdr.code = NM_CUSTOMDRAW;
223 if (infoPtr->nCurrentTool != -1) {
224 TTTOOL_INFO *toolPtr = &infoPtr->tools[infoPtr->nCurrentTool];
225 lpnmttcd->nmcd.hdr.idFrom = toolPtr->uId;
227 lpnmttcd->nmcd.hdc = hdc;
228 lpnmttcd->nmcd.rc = *rcBounds;
229 /* FIXME - dwItemSpec, uItemState, lItemlParam */
232 static inline DWORD
233 TOOLTIPS_notify_customdraw (DWORD dwDrawStage, NMTTCUSTOMDRAW *lpnmttcd)
235 LRESULT result = CDRF_DODEFAULT;
236 lpnmttcd->nmcd.dwDrawStage = dwDrawStage;
238 TRACE("Notifying stage %d, flags %x, id %x\n", lpnmttcd->nmcd.dwDrawStage,
239 lpnmttcd->uDrawFlags, lpnmttcd->nmcd.hdr.code);
241 result = SendMessageW(GetParent(lpnmttcd->nmcd.hdr.hwndFrom), WM_NOTIFY,
242 0, (LPARAM)lpnmttcd);
244 TRACE("Notify result %x\n", (unsigned int)result);
246 return result;
249 static void
250 TOOLTIPS_Refresh (const TOOLTIPS_INFO *infoPtr, HDC hdc)
252 RECT rc;
253 INT oldBkMode;
254 HFONT hOldFont;
255 HBRUSH hBrush;
256 UINT uFlags = DT_EXTERNALLEADING;
257 HRGN hRgn = NULL;
258 DWORD dwStyle = GetWindowLongW(infoPtr->hwndSelf, GWL_STYLE);
259 NMTTCUSTOMDRAW nmttcd;
260 DWORD cdmode;
262 if (infoPtr->nMaxTipWidth > -1)
263 uFlags |= DT_WORDBREAK;
264 if (GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE) & TTS_NOPREFIX)
265 uFlags |= DT_NOPREFIX;
266 GetClientRect (infoPtr->hwndSelf, &rc);
268 hBrush = CreateSolidBrush(infoPtr->clrBk);
270 oldBkMode = SetBkMode (hdc, TRANSPARENT);
271 SetTextColor (hdc, infoPtr->clrText);
272 hOldFont = SelectObject (hdc, infoPtr->hFont);
274 /* Custom draw - Call PrePaint once initial properties set up */
275 /* Note: Contrary to MSDN, CDRF_SKIPDEFAULT still draws a tooltip */
276 TOOLTIPS_customdraw_fill(infoPtr, &nmttcd, hdc, &rc, uFlags);
277 cdmode = TOOLTIPS_notify_customdraw(CDDS_PREPAINT, &nmttcd);
278 uFlags = nmttcd.uDrawFlags;
280 if (dwStyle & TTS_BALLOON)
282 /* create a region to store result into */
283 hRgn = CreateRectRgn(0, 0, 0, 0);
285 GetWindowRgn(infoPtr->hwndSelf, hRgn);
287 /* fill the background */
288 FillRgn(hdc, hRgn, hBrush);
289 DeleteObject(hBrush);
290 hBrush = NULL;
292 else
294 /* fill the background */
295 FillRect(hdc, &rc, hBrush);
296 DeleteObject(hBrush);
297 hBrush = NULL;
300 if ((dwStyle & TTS_BALLOON) || infoPtr->pszTitle)
302 /* calculate text rectangle */
303 rc.left += (BALLOON_TEXT_MARGIN + infoPtr->rcMargin.left);
304 rc.top += (BALLOON_TEXT_MARGIN + infoPtr->rcMargin.top);
305 rc.right -= (BALLOON_TEXT_MARGIN + infoPtr->rcMargin.right);
306 rc.bottom -= (BALLOON_TEXT_MARGIN + infoPtr->rcMargin.bottom);
307 if(infoPtr->bToolBelow) rc.top += BALLOON_STEMHEIGHT;
309 if (infoPtr->pszTitle)
311 RECT rcTitle = {rc.left, rc.top, rc.right, rc.bottom};
312 int height;
313 BOOL icon_present;
314 HFONT prevFont;
316 /* draw icon */
317 icon_present = infoPtr->hTitleIcon &&
318 DrawIconEx(hdc, rc.left, rc.top, infoPtr->hTitleIcon,
319 ICON_WIDTH, ICON_HEIGHT, 0, NULL, DI_NORMAL);
320 if (icon_present)
321 rcTitle.left += ICON_WIDTH + BALLOON_ICON_TITLE_SPACING;
323 rcTitle.bottom = rc.top + ICON_HEIGHT;
325 /* draw title text */
326 prevFont = SelectObject (hdc, infoPtr->hTitleFont);
327 height = DrawTextW(hdc, infoPtr->pszTitle, -1, &rcTitle, DT_BOTTOM | DT_SINGLELINE | DT_NOPREFIX);
328 SelectObject (hdc, prevFont);
329 rc.top += height + BALLOON_TITLE_TEXT_SPACING;
332 else
334 /* calculate text rectangle */
335 rc.left += (NORMAL_TEXT_MARGIN + infoPtr->rcMargin.left);
336 rc.top += (NORMAL_TEXT_MARGIN + infoPtr->rcMargin.top);
337 rc.right -= (NORMAL_TEXT_MARGIN + infoPtr->rcMargin.right);
338 rc.bottom -= (NORMAL_TEXT_MARGIN + infoPtr->rcMargin.bottom);
341 /* draw text */
342 DrawTextW (hdc, infoPtr->szTipText, -1, &rc, uFlags);
344 /* Custom draw - Call PostPaint after drawing */
345 if (cdmode & CDRF_NOTIFYPOSTPAINT) {
346 TOOLTIPS_notify_customdraw(CDDS_POSTPAINT, &nmttcd);
349 /* be polite and reset the things we changed in the dc */
350 SelectObject (hdc, hOldFont);
351 SetBkMode (hdc, oldBkMode);
353 if (dwStyle & TTS_BALLOON)
355 /* frame region because default window proc doesn't do it */
356 INT width = GetSystemMetrics(SM_CXDLGFRAME) - GetSystemMetrics(SM_CXEDGE);
357 INT height = GetSystemMetrics(SM_CYDLGFRAME) - GetSystemMetrics(SM_CYEDGE);
359 hBrush = GetSysColorBrush(COLOR_WINDOWFRAME);
360 FrameRgn(hdc, hRgn, hBrush, width, height);
363 if (hRgn)
364 DeleteObject(hRgn);
367 static void TOOLTIPS_GetDispInfoA(const TOOLTIPS_INFO *infoPtr, TTTOOL_INFO *toolPtr, WCHAR *buffer)
369 NMTTDISPINFOA ttnmdi;
371 /* fill NMHDR struct */
372 ZeroMemory (&ttnmdi, sizeof(NMTTDISPINFOA));
373 ttnmdi.hdr.hwndFrom = infoPtr->hwndSelf;
374 ttnmdi.hdr.idFrom = toolPtr->uId;
375 ttnmdi.hdr.code = TTN_GETDISPINFOA; /* == TTN_NEEDTEXTA */
376 ttnmdi.lpszText = ttnmdi.szText;
377 ttnmdi.uFlags = toolPtr->uFlags;
378 ttnmdi.lParam = toolPtr->lParam;
380 TRACE("hdr.idFrom = %lx\n", ttnmdi.hdr.idFrom);
381 SendMessageW(toolPtr->hwnd, WM_NOTIFY, toolPtr->uId, (LPARAM)&ttnmdi);
383 if (IS_INTRESOURCE(ttnmdi.lpszText)) {
384 LoadStringW(ttnmdi.hinst, LOWORD(ttnmdi.lpszText),
385 buffer, INFOTIPSIZE);
386 if (ttnmdi.uFlags & TTF_DI_SETITEM) {
387 toolPtr->hinst = ttnmdi.hinst;
388 toolPtr->lpszText = (LPWSTR)ttnmdi.lpszText;
391 else if (ttnmdi.lpszText == 0) {
392 buffer[0] = '\0';
394 else if (ttnmdi.lpszText != LPSTR_TEXTCALLBACKA) {
395 Str_GetPtrAtoW(ttnmdi.lpszText, buffer, INFOTIPSIZE);
396 if (ttnmdi.uFlags & TTF_DI_SETITEM) {
397 toolPtr->hinst = 0;
398 toolPtr->lpszText = NULL;
399 Str_SetPtrW(&toolPtr->lpszText, buffer);
402 else {
403 ERR("recursive text callback!\n");
404 buffer[0] = '\0';
407 /* no text available - try calling parent instead as per native */
408 /* FIXME: Unsure if SETITEM should save the value or not */
409 if (buffer[0] == 0x00) {
411 SendMessageW(GetParent(toolPtr->hwnd), WM_NOTIFY, toolPtr->uId, (LPARAM)&ttnmdi);
413 if (IS_INTRESOURCE(ttnmdi.lpszText)) {
414 LoadStringW(ttnmdi.hinst, LOWORD(ttnmdi.lpszText),
415 buffer, INFOTIPSIZE);
416 } else if (ttnmdi.lpszText &&
417 ttnmdi.lpszText != LPSTR_TEXTCALLBACKA) {
418 Str_GetPtrAtoW(ttnmdi.lpszText, buffer, INFOTIPSIZE);
423 static void TOOLTIPS_GetDispInfoW(const TOOLTIPS_INFO *infoPtr, TTTOOL_INFO *toolPtr, WCHAR *buffer)
425 NMTTDISPINFOW ttnmdi;
427 /* fill NMHDR struct */
428 ZeroMemory (&ttnmdi, sizeof(NMTTDISPINFOW));
429 ttnmdi.hdr.hwndFrom = infoPtr->hwndSelf;
430 ttnmdi.hdr.idFrom = toolPtr->uId;
431 ttnmdi.hdr.code = TTN_GETDISPINFOW; /* == TTN_NEEDTEXTW */
432 ttnmdi.lpszText = ttnmdi.szText;
433 ttnmdi.uFlags = toolPtr->uFlags;
434 ttnmdi.lParam = toolPtr->lParam;
436 TRACE("hdr.idFrom = %lx\n", ttnmdi.hdr.idFrom);
437 SendMessageW(toolPtr->hwnd, WM_NOTIFY, toolPtr->uId, (LPARAM)&ttnmdi);
439 if (IS_INTRESOURCE(ttnmdi.lpszText)) {
440 LoadStringW(ttnmdi.hinst, LOWORD(ttnmdi.lpszText),
441 buffer, INFOTIPSIZE);
442 if (ttnmdi.uFlags & TTF_DI_SETITEM) {
443 toolPtr->hinst = ttnmdi.hinst;
444 toolPtr->lpszText = ttnmdi.lpszText;
447 else if (ttnmdi.lpszText == 0) {
448 buffer[0] = '\0';
450 else if (ttnmdi.lpszText != LPSTR_TEXTCALLBACKW) {
451 Str_GetPtrW(ttnmdi.lpszText, buffer, INFOTIPSIZE);
452 if (ttnmdi.uFlags & TTF_DI_SETITEM) {
453 toolPtr->hinst = 0;
454 toolPtr->lpszText = NULL;
455 Str_SetPtrW(&toolPtr->lpszText, buffer);
458 else {
459 ERR("recursive text callback!\n");
460 buffer[0] = '\0';
463 /* no text available - try calling parent instead as per native */
464 /* FIXME: Unsure if SETITEM should save the value or not */
465 if (buffer[0] == 0x00) {
467 SendMessageW(GetParent(toolPtr->hwnd), WM_NOTIFY, toolPtr->uId, (LPARAM)&ttnmdi);
469 if (IS_INTRESOURCE(ttnmdi.lpszText)) {
470 LoadStringW(ttnmdi.hinst, LOWORD(ttnmdi.lpszText),
471 buffer, INFOTIPSIZE);
472 } else if (ttnmdi.lpszText &&
473 ttnmdi.lpszText != LPSTR_TEXTCALLBACKW) {
474 Str_GetPtrW(ttnmdi.lpszText, buffer, INFOTIPSIZE);
480 static void
481 TOOLTIPS_GetTipText (const TOOLTIPS_INFO *infoPtr, INT nTool, WCHAR *buffer)
483 TTTOOL_INFO *toolPtr = &infoPtr->tools[nTool];
485 if (IS_INTRESOURCE(toolPtr->lpszText) && toolPtr->hinst) {
486 /* load a resource */
487 TRACE("load res string %p %x\n",
488 toolPtr->hinst, LOWORD(toolPtr->lpszText));
489 LoadStringW (toolPtr->hinst, LOWORD(toolPtr->lpszText),
490 buffer, INFOTIPSIZE);
492 else if (toolPtr->lpszText) {
493 if (toolPtr->lpszText == LPSTR_TEXTCALLBACKW) {
494 if (toolPtr->bNotifyUnicode)
495 TOOLTIPS_GetDispInfoW(infoPtr, toolPtr, buffer);
496 else
497 TOOLTIPS_GetDispInfoA(infoPtr, toolPtr, buffer);
499 else {
500 /* the item is a usual (unicode) text */
501 lstrcpynW (buffer, toolPtr->lpszText, INFOTIPSIZE);
504 else {
505 /* no text available */
506 buffer[0] = '\0';
509 TRACE("%s\n", debugstr_w(buffer));
513 static void
514 TOOLTIPS_CalcTipSize (const TOOLTIPS_INFO *infoPtr, LPSIZE lpSize)
516 HDC hdc;
517 HFONT hOldFont;
518 DWORD style = GetWindowLongW(infoPtr->hwndSelf, GWL_STYLE);
519 UINT uFlags = DT_EXTERNALLEADING | DT_CALCRECT;
520 RECT rc = {0, 0, 0, 0};
521 SIZE title = {0, 0};
523 if (infoPtr->nMaxTipWidth > -1) {
524 rc.right = infoPtr->nMaxTipWidth;
525 uFlags |= DT_WORDBREAK;
527 if (style & TTS_NOPREFIX)
528 uFlags |= DT_NOPREFIX;
529 TRACE("%s\n", debugstr_w(infoPtr->szTipText));
531 hdc = GetDC (infoPtr->hwndSelf);
532 if (infoPtr->pszTitle)
534 RECT rcTitle = {0, 0, 0, 0};
535 TRACE("title %s\n", debugstr_w(infoPtr->pszTitle));
536 if (infoPtr->hTitleIcon)
538 title.cx = ICON_WIDTH;
539 title.cy = ICON_HEIGHT;
541 if (title.cx != 0) title.cx += BALLOON_ICON_TITLE_SPACING;
542 hOldFont = SelectObject (hdc, infoPtr->hTitleFont);
543 DrawTextW(hdc, infoPtr->pszTitle, -1, &rcTitle, DT_SINGLELINE | DT_NOPREFIX | DT_CALCRECT);
544 SelectObject (hdc, hOldFont);
545 title.cy = max(title.cy, rcTitle.bottom - rcTitle.top) + BALLOON_TITLE_TEXT_SPACING;
546 title.cx += (rcTitle.right - rcTitle.left);
548 hOldFont = SelectObject (hdc, infoPtr->hFont);
549 DrawTextW (hdc, infoPtr->szTipText, -1, &rc, uFlags);
550 SelectObject (hdc, hOldFont);
551 ReleaseDC (infoPtr->hwndSelf, hdc);
553 if ((style & TTS_BALLOON) || infoPtr->pszTitle)
555 lpSize->cx = max(rc.right - rc.left, title.cx) + 2*BALLOON_TEXT_MARGIN +
556 infoPtr->rcMargin.left + infoPtr->rcMargin.right;
557 lpSize->cy = title.cy + rc.bottom - rc.top + 2*BALLOON_TEXT_MARGIN +
558 infoPtr->rcMargin.bottom + infoPtr->rcMargin.top +
559 BALLOON_STEMHEIGHT;
561 else
563 lpSize->cx = rc.right - rc.left + 2*NORMAL_TEXT_MARGIN +
564 infoPtr->rcMargin.left + infoPtr->rcMargin.right;
565 lpSize->cy = rc.bottom - rc.top + 2*NORMAL_TEXT_MARGIN +
566 infoPtr->rcMargin.bottom + infoPtr->rcMargin.top;
571 static void
572 TOOLTIPS_Show (TOOLTIPS_INFO *infoPtr, BOOL track_activate)
574 TTTOOL_INFO *toolPtr;
575 HMONITOR monitor;
576 MONITORINFO mon_info;
577 RECT rect;
578 SIZE size;
579 NMHDR hdr;
580 int ptfx = 0;
581 DWORD style = GetWindowLongW(infoPtr->hwndSelf, GWL_STYLE);
582 INT nTool;
584 if (track_activate)
586 if (infoPtr->nTrackTool == -1)
588 TRACE("invalid tracking tool (-1)!\n");
589 return;
591 nTool = infoPtr->nTrackTool;
593 else
595 if (infoPtr->nTool == -1)
597 TRACE("invalid tool (-1)!\n");
598 return;
600 nTool = infoPtr->nTool;
603 TRACE("Show tooltip pre %d! (%p)\n", nTool, infoPtr->hwndSelf);
605 TOOLTIPS_GetTipText (infoPtr, nTool, infoPtr->szTipText);
607 if (infoPtr->szTipText[0] == '\0')
608 return;
610 toolPtr = &infoPtr->tools[nTool];
612 if (!track_activate)
613 infoPtr->nCurrentTool = infoPtr->nTool;
615 TRACE("Show tooltip %d!\n", nTool);
617 hdr.hwndFrom = infoPtr->hwndSelf;
618 hdr.idFrom = toolPtr->uId;
619 hdr.code = TTN_SHOW;
620 SendMessageW (toolPtr->hwnd, WM_NOTIFY, toolPtr->uId, (LPARAM)&hdr);
622 TRACE("%s\n", debugstr_w(infoPtr->szTipText));
624 TOOLTIPS_CalcTipSize (infoPtr, &size);
625 TRACE("size %d x %d\n", size.cx, size.cy);
627 if (track_activate)
629 rect.left = infoPtr->xTrackPos;
630 rect.top = infoPtr->yTrackPos;
631 ptfx = rect.left;
633 if (toolPtr->uFlags & TTF_CENTERTIP)
635 rect.left -= (size.cx / 2);
636 if (!(style & TTS_BALLOON))
637 rect.top -= (size.cy / 2);
639 if (!(infoPtr->bToolBelow = (infoPtr->yTrackPos + size.cy <= GetSystemMetrics(SM_CYSCREEN))))
640 rect.top -= size.cy;
642 if (!(toolPtr->uFlags & TTF_ABSOLUTE))
644 if (style & TTS_BALLOON)
645 rect.left -= BALLOON_STEMINDENT;
646 else
648 RECT rcTool;
650 if (toolPtr->uFlags & TTF_IDISHWND)
651 GetWindowRect ((HWND)toolPtr->uId, &rcTool);
652 else
654 rcTool = toolPtr->rect;
655 MapWindowPoints (toolPtr->hwnd, NULL, (LPPOINT)&rcTool, 2);
658 /* smart placement */
659 if ((rect.left + size.cx > rcTool.left) && (rect.left < rcTool.right) &&
660 (rect.top + size.cy > rcTool.top) && (rect.top < rcTool.bottom))
661 rect.left = rcTool.right;
665 else
667 if (toolPtr->uFlags & TTF_CENTERTIP)
669 RECT rc;
671 if (toolPtr->uFlags & TTF_IDISHWND)
672 GetWindowRect ((HWND)toolPtr->uId, &rc);
673 else {
674 rc = toolPtr->rect;
675 MapWindowPoints (toolPtr->hwnd, NULL, (LPPOINT)&rc, 2);
677 rect.left = (rc.left + rc.right - size.cx) / 2;
678 if (style & TTS_BALLOON)
680 ptfx = rc.left + ((rc.right - rc.left) / 2);
682 /* CENTERTIP ballon tooltips default to below the field
683 * if they fit on the screen */
684 if (rc.bottom + size.cy > GetSystemMetrics(SM_CYSCREEN))
686 rect.top = rc.top - size.cy;
687 infoPtr->bToolBelow = FALSE;
689 else
691 infoPtr->bToolBelow = TRUE;
692 rect.top = rc.bottom;
694 rect.left = max(0, rect.left - BALLOON_STEMINDENT);
696 else
698 rect.top = rc.bottom + 2;
699 infoPtr->bToolBelow = TRUE;
702 else
704 GetCursorPos ((LPPOINT)&rect);
705 if (style & TTS_BALLOON)
707 ptfx = rect.left;
708 if(rect.top - size.cy >= 0)
710 rect.top -= size.cy;
711 infoPtr->bToolBelow = FALSE;
713 else
715 infoPtr->bToolBelow = TRUE;
716 rect.top += 20;
718 rect.left = max(0, rect.left - BALLOON_STEMINDENT);
720 else
722 rect.top += 20;
723 infoPtr->bToolBelow = TRUE;
728 TRACE("pos %d - %d\n", rect.left, rect.top);
730 rect.right = rect.left + size.cx;
731 rect.bottom = rect.top + size.cy;
733 /* check position */
735 monitor = MonitorFromRect( &rect, MONITOR_DEFAULTTOPRIMARY );
736 mon_info.cbSize = sizeof(mon_info);
737 GetMonitorInfoW( monitor, &mon_info );
739 if( rect.right > mon_info.rcWork.right ) {
740 rect.left -= rect.right - mon_info.rcWork.right + 2;
741 rect.right = mon_info.rcWork.right - 2;
743 if (rect.left < mon_info.rcWork.left) rect.left = mon_info.rcWork.left;
745 if( rect.bottom > mon_info.rcWork.bottom ) {
746 RECT rc;
748 if (toolPtr->uFlags & TTF_IDISHWND)
749 GetWindowRect ((HWND)toolPtr->uId, &rc);
750 else {
751 rc = toolPtr->rect;
752 MapWindowPoints (toolPtr->hwnd, NULL, (LPPOINT)&rc, 2);
754 rect.bottom = rc.top - 2;
755 rect.top = rect.bottom - size.cy;
758 AdjustWindowRectEx (&rect, GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE),
759 FALSE, GetWindowLongW (infoPtr->hwndSelf, GWL_EXSTYLE));
761 if (style & TTS_BALLOON)
763 HRGN hRgn;
764 HRGN hrStem;
765 POINT pts[3];
767 ptfx -= rect.left;
769 if(infoPtr->bToolBelow)
771 pts[0].x = ptfx;
772 pts[0].y = 0;
773 pts[1].x = max(BALLOON_STEMINDENT, ptfx - (BALLOON_STEMWIDTH / 2));
774 pts[1].y = BALLOON_STEMHEIGHT;
775 pts[2].x = pts[1].x + BALLOON_STEMWIDTH;
776 pts[2].y = pts[1].y;
777 if(pts[2].x > (rect.right - rect.left) - BALLOON_STEMINDENT)
779 pts[2].x = (rect.right - rect.left) - BALLOON_STEMINDENT;
780 pts[1].x = pts[2].x - BALLOON_STEMWIDTH;
783 else
785 pts[0].x = max(BALLOON_STEMINDENT, ptfx - (BALLOON_STEMWIDTH / 2));
786 pts[0].y = (rect.bottom - rect.top) - BALLOON_STEMHEIGHT;
787 pts[1].x = pts[0].x + BALLOON_STEMWIDTH;
788 pts[1].y = pts[0].y;
789 pts[2].x = ptfx;
790 pts[2].y = (rect.bottom - rect.top);
791 if(pts[1].x > (rect.right - rect.left) - BALLOON_STEMINDENT)
793 pts[1].x = (rect.right - rect.left) - BALLOON_STEMINDENT;
794 pts[0].x = pts[1].x - BALLOON_STEMWIDTH;
798 hrStem = CreatePolygonRgn(pts, sizeof(pts) / sizeof(pts[0]), ALTERNATE);
800 hRgn = CreateRoundRectRgn(0,
801 (infoPtr->bToolBelow ? BALLOON_STEMHEIGHT : 0),
802 rect.right - rect.left,
803 (infoPtr->bToolBelow ? rect.bottom - rect.top : rect.bottom - rect.top - BALLOON_STEMHEIGHT),
804 BALLOON_ROUNDEDNESS, BALLOON_ROUNDEDNESS);
806 CombineRgn(hRgn, hRgn, hrStem, RGN_OR);
807 DeleteObject(hrStem);
809 SetWindowRgn(infoPtr->hwndSelf, hRgn, FALSE);
810 /* we don't free the region handle as the system deletes it when
811 * it is no longer needed */
814 SetWindowPos (infoPtr->hwndSelf, HWND_TOPMOST, rect.left, rect.top,
815 rect.right - rect.left, rect.bottom - rect.top,
816 SWP_SHOWWINDOW | SWP_NOACTIVATE);
818 /* repaint the tooltip */
819 InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
820 UpdateWindow(infoPtr->hwndSelf);
822 if (!track_activate)
824 SetTimer (infoPtr->hwndSelf, ID_TIMERPOP, infoPtr->nAutoPopTime, 0);
825 TRACE("timer 2 started!\n");
826 SetTimer (infoPtr->hwndSelf, ID_TIMERLEAVE, infoPtr->nReshowTime, 0);
827 TRACE("timer 3 started!\n");
832 static void
833 TOOLTIPS_Hide (TOOLTIPS_INFO *infoPtr)
835 TTTOOL_INFO *toolPtr;
836 NMHDR hdr;
838 TRACE("Hide tooltip %d! (%p)\n", infoPtr->nCurrentTool, infoPtr->hwndSelf);
840 if (infoPtr->nCurrentTool == -1)
841 return;
843 toolPtr = &infoPtr->tools[infoPtr->nCurrentTool];
844 KillTimer (infoPtr->hwndSelf, ID_TIMERPOP);
846 hdr.hwndFrom = infoPtr->hwndSelf;
847 hdr.idFrom = toolPtr->uId;
848 hdr.code = TTN_POP;
849 SendMessageW (toolPtr->hwnd, WM_NOTIFY, toolPtr->uId, (LPARAM)&hdr);
851 infoPtr->nCurrentTool = -1;
853 SetWindowPos (infoPtr->hwndSelf, HWND_TOP, 0, 0, 0, 0,
854 SWP_NOZORDER | SWP_HIDEWINDOW | SWP_NOACTIVATE);
858 static void
859 TOOLTIPS_TrackShow (TOOLTIPS_INFO *infoPtr)
861 TOOLTIPS_Show(infoPtr, TRUE);
865 static void
866 TOOLTIPS_TrackHide (const TOOLTIPS_INFO *infoPtr)
868 TTTOOL_INFO *toolPtr;
869 NMHDR hdr;
871 TRACE("hide tracking tooltip %d\n", infoPtr->nTrackTool);
873 if (infoPtr->nTrackTool == -1)
874 return;
876 toolPtr = &infoPtr->tools[infoPtr->nTrackTool];
878 hdr.hwndFrom = infoPtr->hwndSelf;
879 hdr.idFrom = toolPtr->uId;
880 hdr.code = TTN_POP;
881 SendMessageW (toolPtr->hwnd, WM_NOTIFY, toolPtr->uId, (LPARAM)&hdr);
883 SetWindowPos (infoPtr->hwndSelf, HWND_TOP, 0, 0, 0, 0,
884 SWP_NOZORDER | SWP_HIDEWINDOW | SWP_NOACTIVATE);
887 /* Structure layout is the same for TTTOOLINFOW and TTTOOLINFOA,
888 this helper is used in both cases. */
889 static INT
890 TOOLTIPS_GetToolFromInfoT (const TOOLTIPS_INFO *infoPtr, const TTTOOLINFOW *lpToolInfo)
892 TTTOOL_INFO *toolPtr;
893 UINT nTool;
895 for (nTool = 0; nTool < infoPtr->uNumTools; nTool++) {
896 toolPtr = &infoPtr->tools[nTool];
898 if (!(toolPtr->uFlags & TTF_IDISHWND) &&
899 (lpToolInfo->hwnd == toolPtr->hwnd) &&
900 (lpToolInfo->uId == toolPtr->uId))
901 return nTool;
904 for (nTool = 0; nTool < infoPtr->uNumTools; nTool++) {
905 toolPtr = &infoPtr->tools[nTool];
907 if ((toolPtr->uFlags & TTF_IDISHWND) &&
908 (lpToolInfo->uId == toolPtr->uId))
909 return nTool;
912 return -1;
916 static INT
917 TOOLTIPS_GetToolFromPoint (const TOOLTIPS_INFO *infoPtr, HWND hwnd, const POINT *lpPt)
919 TTTOOL_INFO *toolPtr;
920 UINT nTool;
922 for (nTool = 0; nTool < infoPtr->uNumTools; nTool++) {
923 toolPtr = &infoPtr->tools[nTool];
925 if (!(toolPtr->uFlags & TTF_IDISHWND)) {
926 if (hwnd != toolPtr->hwnd)
927 continue;
928 if (!PtInRect (&toolPtr->rect, *lpPt))
929 continue;
930 return nTool;
934 for (nTool = 0; nTool < infoPtr->uNumTools; nTool++) {
935 toolPtr = &infoPtr->tools[nTool];
937 if (toolPtr->uFlags & TTF_IDISHWND) {
938 if ((HWND)toolPtr->uId == hwnd)
939 return nTool;
943 return -1;
947 static BOOL
948 TOOLTIPS_IsWindowActive (HWND hwnd)
950 HWND hwndActive = GetActiveWindow ();
951 if (!hwndActive)
952 return FALSE;
953 if (hwndActive == hwnd)
954 return TRUE;
955 return IsChild (hwndActive, hwnd);
959 static INT
960 TOOLTIPS_CheckTool (const TOOLTIPS_INFO *infoPtr, BOOL bShowTest)
962 POINT pt;
963 HWND hwndTool;
964 INT nTool;
966 GetCursorPos (&pt);
967 hwndTool = (HWND)SendMessageW (infoPtr->hwndSelf, TTM_WINDOWFROMPOINT, 0, (LPARAM)&pt);
968 if (hwndTool == 0)
969 return -1;
971 ScreenToClient (hwndTool, &pt);
972 nTool = TOOLTIPS_GetToolFromPoint (infoPtr, hwndTool, &pt);
973 if (nTool == -1)
974 return -1;
976 if (!(GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE) & TTS_ALWAYSTIP) && bShowTest) {
977 if (!TOOLTIPS_IsWindowActive (GetWindow (infoPtr->hwndSelf, GW_OWNER)))
978 return -1;
981 TRACE("tool %d\n", nTool);
983 return nTool;
987 static LRESULT
988 TOOLTIPS_Activate (TOOLTIPS_INFO *infoPtr, BOOL activate)
990 infoPtr->bActive = activate;
992 if (infoPtr->bActive)
993 TRACE("activate!\n");
995 if (!(infoPtr->bActive) && (infoPtr->nCurrentTool != -1))
996 TOOLTIPS_Hide (infoPtr);
998 return 0;
1002 static LRESULT
1003 TOOLTIPS_AddToolT (TOOLTIPS_INFO *infoPtr, const TTTOOLINFOW *ti, BOOL isW)
1005 TTTOOL_INFO *toolPtr;
1006 INT nResult;
1008 if (!ti) return FALSE;
1010 TRACE("add tool (%p) %p %ld%s!\n",
1011 infoPtr->hwndSelf, ti->hwnd, ti->uId,
1012 (ti->uFlags & TTF_IDISHWND) ? " TTF_IDISHWND" : "");
1014 if (infoPtr->uNumTools == 0) {
1015 infoPtr->tools = Alloc (sizeof(TTTOOL_INFO));
1016 toolPtr = infoPtr->tools;
1018 else {
1019 TTTOOL_INFO *oldTools = infoPtr->tools;
1020 infoPtr->tools =
1021 Alloc (sizeof(TTTOOL_INFO) * (infoPtr->uNumTools + 1));
1022 memcpy (infoPtr->tools, oldTools,
1023 infoPtr->uNumTools * sizeof(TTTOOL_INFO));
1024 Free (oldTools);
1025 toolPtr = &infoPtr->tools[infoPtr->uNumTools];
1028 infoPtr->uNumTools++;
1030 /* copy tool data */
1031 toolPtr->uFlags = ti->uFlags;
1032 toolPtr->hwnd = ti->hwnd;
1033 toolPtr->uId = ti->uId;
1034 toolPtr->rect = ti->rect;
1035 toolPtr->hinst = ti->hinst;
1037 if (IS_INTRESOURCE(ti->lpszText)) {
1038 TRACE("add string id %x\n", LOWORD(ti->lpszText));
1039 toolPtr->lpszText = ti->lpszText;
1041 else if (ti->lpszText) {
1042 if (TOOLTIPS_IsCallbackString(ti->lpszText, isW)) {
1043 TRACE("add CALLBACK!\n");
1044 toolPtr->lpszText = LPSTR_TEXTCALLBACKW;
1046 else if (isW) {
1047 INT len = lstrlenW (ti->lpszText);
1048 TRACE("add text %s!\n", debugstr_w(ti->lpszText));
1049 toolPtr->lpszText = Alloc ((len + 1)*sizeof(WCHAR));
1050 strcpyW (toolPtr->lpszText, ti->lpszText);
1052 else {
1053 INT len = MultiByteToWideChar(CP_ACP, 0, (LPSTR)ti->lpszText, -1, NULL, 0);
1054 TRACE("add text \"%s\"!\n", (LPSTR)ti->lpszText);
1055 toolPtr->lpszText = Alloc (len * sizeof(WCHAR));
1056 MultiByteToWideChar(CP_ACP, 0, (LPSTR)ti->lpszText, -1, toolPtr->lpszText, len);
1060 if (ti->cbSize >= TTTOOLINFOW_V2_SIZE)
1061 toolPtr->lParam = ti->lParam;
1063 /* install subclassing hook */
1064 if (toolPtr->uFlags & TTF_SUBCLASS) {
1065 if (toolPtr->uFlags & TTF_IDISHWND) {
1066 SetWindowSubclass((HWND)toolPtr->uId, TOOLTIPS_SubclassProc, 1,
1067 (DWORD_PTR)infoPtr->hwndSelf);
1069 else {
1070 SetWindowSubclass(toolPtr->hwnd, TOOLTIPS_SubclassProc, 1,
1071 (DWORD_PTR)infoPtr->hwndSelf);
1073 TRACE("subclassing installed!\n");
1076 nResult = SendMessageW (toolPtr->hwnd, WM_NOTIFYFORMAT,
1077 (WPARAM)infoPtr->hwndSelf, NF_QUERY);
1078 if (nResult == NFR_ANSI) {
1079 toolPtr->bNotifyUnicode = FALSE;
1080 TRACE(" -- WM_NOTIFYFORMAT returns: NFR_ANSI\n");
1081 } else if (nResult == NFR_UNICODE) {
1082 toolPtr->bNotifyUnicode = TRUE;
1083 TRACE(" -- WM_NOTIFYFORMAT returns: NFR_UNICODE\n");
1084 } else {
1085 TRACE (" -- WM_NOTIFYFORMAT returns: error!\n");
1088 return TRUE;
1092 static LRESULT
1093 TOOLTIPS_DelToolT (TOOLTIPS_INFO *infoPtr, const TTTOOLINFOW *ti, BOOL isW)
1095 TTTOOL_INFO *toolPtr;
1096 INT nTool;
1098 if (!ti) return 0;
1099 if (isW && ti->cbSize > TTTOOLINFOW_V2_SIZE &&
1100 ti->cbSize != TTTOOLINFOW_V3_SIZE)
1101 return 0;
1102 if (infoPtr->uNumTools == 0)
1103 return 0;
1105 nTool = TOOLTIPS_GetToolFromInfoT (infoPtr, ti);
1107 TRACE("tool %d\n", nTool);
1109 if (nTool == -1)
1110 return 0;
1112 /* make sure the tooltip has disappeared before deleting it */
1113 TOOLTIPS_Hide(infoPtr);
1115 /* delete text string */
1116 toolPtr = &infoPtr->tools[nTool];
1117 if (toolPtr->lpszText) {
1118 if ( (toolPtr->lpszText != LPSTR_TEXTCALLBACKW) &&
1119 !IS_INTRESOURCE(toolPtr->lpszText) )
1120 Free (toolPtr->lpszText);
1123 /* remove subclassing */
1124 if (toolPtr->uFlags & TTF_SUBCLASS) {
1125 if (toolPtr->uFlags & TTF_IDISHWND) {
1126 RemoveWindowSubclass((HWND)toolPtr->uId, TOOLTIPS_SubclassProc, 1);
1128 else {
1129 RemoveWindowSubclass(toolPtr->hwnd, TOOLTIPS_SubclassProc, 1);
1133 /* delete tool from tool list */
1134 if (infoPtr->uNumTools == 1) {
1135 Free (infoPtr->tools);
1136 infoPtr->tools = NULL;
1138 else {
1139 TTTOOL_INFO *oldTools = infoPtr->tools;
1140 infoPtr->tools =
1141 Alloc (sizeof(TTTOOL_INFO) * (infoPtr->uNumTools - 1));
1143 if (nTool > 0)
1144 memcpy (&infoPtr->tools[0], &oldTools[0],
1145 nTool * sizeof(TTTOOL_INFO));
1147 if (nTool < infoPtr->uNumTools - 1)
1148 memcpy (&infoPtr->tools[nTool], &oldTools[nTool + 1],
1149 (infoPtr->uNumTools - nTool - 1) * sizeof(TTTOOL_INFO));
1151 Free (oldTools);
1154 /* update any indices affected by delete */
1156 /* destroying tool that mouse was on on last relayed mouse move */
1157 if (infoPtr->nTool == nTool)
1158 /* -1 means no current tool (0 means first tool) */
1159 infoPtr->nTool = -1;
1160 else if (infoPtr->nTool > nTool)
1161 infoPtr->nTool--;
1163 if (infoPtr->nTrackTool == nTool)
1164 /* -1 means no current tool (0 means first tool) */
1165 infoPtr->nTrackTool = -1;
1166 else if (infoPtr->nTrackTool > nTool)
1167 infoPtr->nTrackTool--;
1169 if (infoPtr->nCurrentTool == nTool)
1170 /* -1 means no current tool (0 means first tool) */
1171 infoPtr->nCurrentTool = -1;
1172 else if (infoPtr->nCurrentTool > nTool)
1173 infoPtr->nCurrentTool--;
1175 infoPtr->uNumTools--;
1177 return 0;
1180 static LRESULT
1181 TOOLTIPS_EnumToolsT (const TOOLTIPS_INFO *infoPtr, UINT uIndex, TTTOOLINFOW *ti,
1182 BOOL isW)
1184 TTTOOL_INFO *toolPtr;
1186 if (!ti) return FALSE;
1187 if (ti->cbSize < TTTOOLINFOW_V1_SIZE)
1188 return FALSE;
1189 if (uIndex >= infoPtr->uNumTools)
1190 return FALSE;
1192 TRACE("index=%u\n", uIndex);
1194 toolPtr = &infoPtr->tools[uIndex];
1196 /* copy tool data */
1197 ti->uFlags = toolPtr->uFlags;
1198 ti->hwnd = toolPtr->hwnd;
1199 ti->uId = toolPtr->uId;
1200 ti->rect = toolPtr->rect;
1201 ti->hinst = toolPtr->hinst;
1202 /* ti->lpszText = toolPtr->lpszText; */
1203 ti->lpszText = NULL; /* FIXME */
1205 if (ti->cbSize >= TTTOOLINFOA_V2_SIZE)
1206 ti->lParam = toolPtr->lParam;
1208 return TRUE;
1211 static LRESULT
1212 TOOLTIPS_GetBubbleSize (const TOOLTIPS_INFO *infoPtr, const TTTOOLINFOW *lpToolInfo)
1214 INT nTool;
1215 SIZE size;
1217 if (lpToolInfo == NULL)
1218 return FALSE;
1219 if (lpToolInfo->cbSize < TTTOOLINFOW_V1_SIZE)
1220 return FALSE;
1222 nTool = TOOLTIPS_GetToolFromInfoT (infoPtr, lpToolInfo);
1223 if (nTool == -1) return 0;
1225 TRACE("tool %d\n", nTool);
1227 TOOLTIPS_CalcTipSize (infoPtr, &size);
1228 TRACE("size %d x %d\n", size.cx, size.cy);
1230 return MAKELRESULT(size.cx, size.cy);
1233 static LRESULT
1234 TOOLTIPS_GetCurrentToolT (const TOOLTIPS_INFO *infoPtr, TTTOOLINFOW *ti, BOOL isW)
1236 TTTOOL_INFO *toolPtr;
1238 if (ti) {
1239 if (ti->cbSize < TTTOOLINFOW_V1_SIZE)
1240 return FALSE;
1242 if (infoPtr->nCurrentTool > -1) {
1243 toolPtr = &infoPtr->tools[infoPtr->nCurrentTool];
1245 /* copy tool data */
1246 ti->uFlags = toolPtr->uFlags;
1247 ti->rect = toolPtr->rect;
1248 ti->hinst = toolPtr->hinst;
1249 /* ti->lpszText = toolPtr->lpszText; */
1250 ti->lpszText = NULL; /* FIXME */
1252 if (ti->cbSize >= TTTOOLINFOW_V2_SIZE)
1253 ti->lParam = toolPtr->lParam;
1255 return TRUE;
1257 else
1258 return FALSE;
1260 else
1261 return (infoPtr->nCurrentTool != -1);
1265 static LRESULT
1266 TOOLTIPS_GetDelayTime (const TOOLTIPS_INFO *infoPtr, DWORD duration)
1268 switch (duration) {
1269 case TTDT_RESHOW:
1270 return infoPtr->nReshowTime;
1272 case TTDT_AUTOPOP:
1273 return infoPtr->nAutoPopTime;
1275 case TTDT_INITIAL:
1276 case TTDT_AUTOMATIC: /* Apparently TTDT_AUTOMATIC returns TTDT_INITIAL */
1277 return infoPtr->nInitialTime;
1279 default:
1280 WARN("Invalid duration flag %x\n", duration);
1281 break;
1284 return -1;
1288 static LRESULT
1289 TOOLTIPS_GetMargin (const TOOLTIPS_INFO *infoPtr, LPRECT lpRect)
1291 lpRect->left = infoPtr->rcMargin.left;
1292 lpRect->right = infoPtr->rcMargin.right;
1293 lpRect->bottom = infoPtr->rcMargin.bottom;
1294 lpRect->top = infoPtr->rcMargin.top;
1296 return 0;
1300 static inline LRESULT
1301 TOOLTIPS_GetMaxTipWidth (const TOOLTIPS_INFO *infoPtr)
1303 return infoPtr->nMaxTipWidth;
1307 static LRESULT
1308 TOOLTIPS_GetTextT (const TOOLTIPS_INFO *infoPtr, TTTOOLINFOW *ti, BOOL isW)
1310 INT nTool;
1312 if (!ti) return 0;
1313 if (ti->cbSize < TTTOOLINFOW_V1_SIZE)
1314 return 0;
1316 nTool = TOOLTIPS_GetToolFromInfoT (infoPtr, ti);
1317 if (nTool == -1) return 0;
1319 if (infoPtr->tools[nTool].lpszText == NULL)
1320 return 0;
1322 if (isW) {
1323 ti->lpszText[0] = '\0';
1324 TOOLTIPS_GetTipText(infoPtr, nTool, ti->lpszText);
1326 else {
1327 WCHAR buffer[INFOTIPSIZE];
1329 /* NB this API is broken, there is no way for the app to determine
1330 what size buffer it requires nor a way to specify how long the
1331 one it supplies is. We'll assume it's up to INFOTIPSIZE */
1333 buffer[0] = '\0';
1334 TOOLTIPS_GetTipText(infoPtr, nTool, buffer);
1335 WideCharToMultiByte(CP_ACP, 0, buffer, -1, (LPSTR)ti->lpszText,
1336 INFOTIPSIZE, NULL, NULL);
1339 return 0;
1343 static inline LRESULT
1344 TOOLTIPS_GetTipBkColor (const TOOLTIPS_INFO *infoPtr)
1346 return infoPtr->clrBk;
1350 static inline LRESULT
1351 TOOLTIPS_GetTipTextColor (const TOOLTIPS_INFO *infoPtr)
1353 return infoPtr->clrText;
1357 static inline LRESULT
1358 TOOLTIPS_GetToolCount (const TOOLTIPS_INFO *infoPtr)
1360 return infoPtr->uNumTools;
1364 static LRESULT
1365 TOOLTIPS_GetToolInfoT (const TOOLTIPS_INFO *infoPtr, TTTOOLINFOW *ti, BOOL isW)
1367 TTTOOL_INFO *toolPtr;
1368 INT nTool;
1370 if (!ti) return FALSE;
1371 if (ti->cbSize < TTTOOLINFOW_V1_SIZE)
1372 return FALSE;
1373 if (infoPtr->uNumTools == 0)
1374 return FALSE;
1376 nTool = TOOLTIPS_GetToolFromInfoT (infoPtr, ti);
1377 if (nTool == -1)
1378 return FALSE;
1380 TRACE("tool %d\n", nTool);
1382 toolPtr = &infoPtr->tools[nTool];
1384 /* copy tool data */
1385 ti->uFlags = toolPtr->uFlags;
1386 ti->rect = toolPtr->rect;
1387 ti->hinst = toolPtr->hinst;
1388 /* lpToolInfo->lpszText = toolPtr->lpszText; */
1389 ti->lpszText = NULL; /* FIXME */
1391 if (ti->cbSize >= TTTOOLINFOW_V2_SIZE)
1392 ti->lParam = toolPtr->lParam;
1394 return TRUE;
1398 static LRESULT
1399 TOOLTIPS_HitTestT (const TOOLTIPS_INFO *infoPtr, LPTTHITTESTINFOW lptthit,
1400 BOOL isW)
1402 TTTOOL_INFO *toolPtr;
1403 INT nTool;
1405 if (lptthit == 0)
1406 return FALSE;
1408 nTool = TOOLTIPS_GetToolFromPoint (infoPtr, lptthit->hwnd, &lptthit->pt);
1409 if (nTool == -1)
1410 return FALSE;
1412 TRACE("tool %d!\n", nTool);
1414 /* copy tool data */
1415 if (lptthit->ti.cbSize >= TTTOOLINFOW_V1_SIZE) {
1416 toolPtr = &infoPtr->tools[nTool];
1418 lptthit->ti.uFlags = toolPtr->uFlags;
1419 lptthit->ti.hwnd = toolPtr->hwnd;
1420 lptthit->ti.uId = toolPtr->uId;
1421 lptthit->ti.rect = toolPtr->rect;
1422 lptthit->ti.hinst = toolPtr->hinst;
1423 /* lptthit->ti.lpszText = toolPtr->lpszText; */
1424 lptthit->ti.lpszText = NULL; /* FIXME */
1425 if (lptthit->ti.cbSize >= TTTOOLINFOW_V2_SIZE)
1426 lptthit->ti.lParam = toolPtr->lParam;
1429 return TRUE;
1433 static LRESULT
1434 TOOLTIPS_NewToolRectT (TOOLTIPS_INFO *infoPtr, const TTTOOLINFOW *ti)
1436 INT nTool;
1438 if (!ti) return 0;
1439 if (ti->cbSize < TTTOOLINFOW_V1_SIZE)
1440 return FALSE;
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;
1450 return 0;
1454 static inline LRESULT
1455 TOOLTIPS_Pop (TOOLTIPS_INFO *infoPtr)
1457 TOOLTIPS_Hide (infoPtr);
1459 return 0;
1463 static LRESULT
1464 TOOLTIPS_RelayEvent (TOOLTIPS_INFO *infoPtr, LPMSG lpMsg)
1466 POINT pt;
1467 INT nOldTool;
1469 if (!lpMsg) {
1470 ERR("lpMsg == NULL!\n");
1471 return 0;
1474 switch (lpMsg->message) {
1475 case WM_LBUTTONDOWN:
1476 case WM_LBUTTONUP:
1477 case WM_MBUTTONDOWN:
1478 case WM_MBUTTONUP:
1479 case WM_RBUTTONDOWN:
1480 case WM_RBUTTONUP:
1481 TOOLTIPS_Hide (infoPtr);
1482 break;
1484 case WM_MOUSEMOVE:
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,
1489 &pt);
1490 TRACE("tool (%p) %d %d %d\n", infoPtr->hwndSelf, nOldTool,
1491 infoPtr->nTool, infoPtr->nCurrentTool);
1492 TRACE("WM_MOUSEMOVE (%p %d %d)\n", infoPtr->hwndSelf, pt.x, pt.y);
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");
1520 break;
1523 return 0;
1527 static LRESULT
1528 TOOLTIPS_SetDelayTime (TOOLTIPS_INFO *infoPtr, DWORD duration, INT nTime)
1530 switch (duration) {
1531 case TTDT_AUTOMATIC:
1532 if (nTime <= 0)
1533 nTime = GetDoubleClickTime();
1534 infoPtr->nReshowTime = nTime / 5;
1535 infoPtr->nAutoPopTime = nTime * 10;
1536 infoPtr->nInitialTime = nTime;
1537 break;
1539 case TTDT_RESHOW:
1540 if(nTime < 0)
1541 nTime = GetDoubleClickTime() / 5;
1542 infoPtr->nReshowTime = nTime;
1543 break;
1545 case TTDT_AUTOPOP:
1546 if(nTime < 0)
1547 nTime = GetDoubleClickTime() * 10;
1548 infoPtr->nAutoPopTime = nTime;
1549 break;
1551 case TTDT_INITIAL:
1552 if(nTime < 0)
1553 nTime = GetDoubleClickTime();
1554 infoPtr->nInitialTime = nTime;
1555 break;
1557 default:
1558 WARN("Invalid duration flag %x\n", duration);
1559 break;
1562 return 0;
1566 static LRESULT
1567 TOOLTIPS_SetMargin (TOOLTIPS_INFO *infoPtr, const RECT *lpRect)
1569 infoPtr->rcMargin.left = lpRect->left;
1570 infoPtr->rcMargin.right = lpRect->right;
1571 infoPtr->rcMargin.bottom = lpRect->bottom;
1572 infoPtr->rcMargin.top = lpRect->top;
1574 return 0;
1578 static inline LRESULT
1579 TOOLTIPS_SetMaxTipWidth (TOOLTIPS_INFO *infoPtr, INT MaxWidth)
1581 INT nTemp = infoPtr->nMaxTipWidth;
1583 infoPtr->nMaxTipWidth = MaxWidth;
1585 return nTemp;
1589 static inline LRESULT
1590 TOOLTIPS_SetTipBkColor (TOOLTIPS_INFO *infoPtr, COLORREF clrBk)
1592 infoPtr->clrBk = clrBk;
1594 return 0;
1598 static inline LRESULT
1599 TOOLTIPS_SetTipTextColor (TOOLTIPS_INFO *infoPtr, COLORREF clrText)
1601 infoPtr->clrText = clrText;
1603 return 0;
1607 static LRESULT
1608 TOOLTIPS_SetTitleT (TOOLTIPS_INFO *infoPtr, UINT_PTR uTitleIcon, LPCWSTR pszTitle,
1609 BOOL isW)
1611 UINT size;
1613 TRACE("hwnd = %p, title = %s, icon = %p\n", infoPtr->hwndSelf, debugstr_w(pszTitle),
1614 (void*)uTitleIcon);
1616 Free(infoPtr->pszTitle);
1618 if (pszTitle)
1620 if (isW)
1622 size = (strlenW(pszTitle)+1)*sizeof(WCHAR);
1623 infoPtr->pszTitle = Alloc(size);
1624 if (!infoPtr->pszTitle)
1625 return FALSE;
1626 memcpy(infoPtr->pszTitle, pszTitle, size);
1628 else
1630 size = sizeof(WCHAR)*MultiByteToWideChar(CP_ACP, 0, (LPCSTR)pszTitle, -1, NULL, 0);
1631 infoPtr->pszTitle = Alloc(size);
1632 if (!infoPtr->pszTitle)
1633 return FALSE;
1634 MultiByteToWideChar(CP_ACP, 0, (LPCSTR)pszTitle, -1, infoPtr->pszTitle, size/sizeof(WCHAR));
1637 else
1638 infoPtr->pszTitle = NULL;
1640 if (uTitleIcon <= TTI_ERROR)
1641 infoPtr->hTitleIcon = hTooltipIcons[uTitleIcon];
1642 else
1643 infoPtr->hTitleIcon = CopyIcon((HICON)uTitleIcon);
1645 TRACE("icon = %p\n", infoPtr->hTitleIcon);
1647 return TRUE;
1651 static LRESULT
1652 TOOLTIPS_SetToolInfoT (TOOLTIPS_INFO *infoPtr, const TTTOOLINFOW *ti, BOOL isW)
1654 TTTOOL_INFO *toolPtr;
1655 INT nTool;
1657 if (!ti) return 0;
1658 if (ti->cbSize < TTTOOLINFOW_V1_SIZE)
1659 return 0;
1661 nTool = TOOLTIPS_GetToolFromInfoT (infoPtr, ti);
1662 if (nTool == -1) return 0;
1664 TRACE("tool %d\n", nTool);
1666 toolPtr = &infoPtr->tools[nTool];
1668 /* copy tool data */
1669 toolPtr->uFlags = ti->uFlags;
1670 toolPtr->hwnd = ti->hwnd;
1671 toolPtr->uId = ti->uId;
1672 toolPtr->rect = ti->rect;
1673 toolPtr->hinst = ti->hinst;
1675 if (IS_INTRESOURCE(ti->lpszText)) {
1676 TRACE("set string id %x!\n", LOWORD(ti->lpszText));
1677 toolPtr->lpszText = ti->lpszText;
1679 else {
1680 if (TOOLTIPS_IsCallbackString(ti->lpszText, isW))
1681 toolPtr->lpszText = LPSTR_TEXTCALLBACKW;
1682 else {
1683 if ( (toolPtr->lpszText) &&
1684 !IS_INTRESOURCE(toolPtr->lpszText) ) {
1685 if( toolPtr->lpszText != LPSTR_TEXTCALLBACKW)
1686 Free (toolPtr->lpszText);
1687 toolPtr->lpszText = NULL;
1689 if (ti->lpszText) {
1690 if (isW) {
1691 INT len = lstrlenW (ti->lpszText);
1692 toolPtr->lpszText = Alloc ((len+1)*sizeof(WCHAR));
1693 strcpyW (toolPtr->lpszText, ti->lpszText);
1695 else {
1696 INT len = MultiByteToWideChar(CP_ACP, 0, (LPSTR)ti->lpszText,
1697 -1, NULL, 0);
1698 toolPtr->lpszText = Alloc (len * sizeof(WCHAR));
1699 MultiByteToWideChar(CP_ACP, 0, (LPSTR)ti->lpszText, -1,
1700 toolPtr->lpszText, len);
1706 if (ti->cbSize >= TTTOOLINFOW_V2_SIZE)
1707 toolPtr->lParam = ti->lParam;
1709 if (infoPtr->nCurrentTool == nTool)
1711 TOOLTIPS_GetTipText (infoPtr, infoPtr->nCurrentTool, infoPtr->szTipText);
1713 if (infoPtr->szTipText[0] == 0)
1714 TOOLTIPS_Hide(infoPtr);
1715 else
1716 TOOLTIPS_Show (infoPtr, FALSE);
1719 return 0;
1723 static LRESULT
1724 TOOLTIPS_TrackActivate (TOOLTIPS_INFO *infoPtr, BOOL track_activate, const TTTOOLINFOA *ti)
1726 if (track_activate) {
1728 if (!ti) return 0;
1729 if (ti->cbSize < TTTOOLINFOA_V1_SIZE)
1730 return FALSE;
1732 /* activate */
1733 infoPtr->nTrackTool = TOOLTIPS_GetToolFromInfoT (infoPtr, (const TTTOOLINFOW*)ti);
1734 if (infoPtr->nTrackTool != -1) {
1735 TRACE("activated!\n");
1736 infoPtr->bTrackActive = TRUE;
1737 TOOLTIPS_TrackShow (infoPtr);
1740 else {
1741 /* deactivate */
1742 TOOLTIPS_TrackHide (infoPtr);
1744 infoPtr->bTrackActive = FALSE;
1745 infoPtr->nTrackTool = -1;
1747 TRACE("deactivated!\n");
1750 return 0;
1754 static LRESULT
1755 TOOLTIPS_TrackPosition (TOOLTIPS_INFO *infoPtr, LPARAM coord)
1757 infoPtr->xTrackPos = (INT)LOWORD(coord);
1758 infoPtr->yTrackPos = (INT)HIWORD(coord);
1760 if (infoPtr->bTrackActive) {
1761 TRACE("[%d %d]\n",
1762 infoPtr->xTrackPos, infoPtr->yTrackPos);
1764 TOOLTIPS_TrackShow (infoPtr);
1767 return 0;
1771 static LRESULT
1772 TOOLTIPS_Update (TOOLTIPS_INFO *infoPtr)
1774 if (infoPtr->nCurrentTool != -1)
1775 UpdateWindow (infoPtr->hwndSelf);
1777 return 0;
1781 static LRESULT
1782 TOOLTIPS_UpdateTipTextT (TOOLTIPS_INFO *infoPtr, const TTTOOLINFOW *ti, BOOL isW)
1784 TTTOOL_INFO *toolPtr;
1785 INT nTool;
1787 if (!ti) return 0;
1788 if (ti->cbSize < TTTOOLINFOW_V1_SIZE)
1789 return FALSE;
1791 nTool = TOOLTIPS_GetToolFromInfoT (infoPtr, ti);
1792 if (nTool == -1)
1793 return 0;
1795 TRACE("tool %d\n", nTool);
1797 toolPtr = &infoPtr->tools[nTool];
1799 /* copy tool text */
1800 toolPtr->hinst = ti->hinst;
1802 if (IS_INTRESOURCE(ti->lpszText)){
1803 toolPtr->lpszText = ti->lpszText;
1805 else if (ti->lpszText) {
1806 if (TOOLTIPS_IsCallbackString(ti->lpszText, isW))
1807 toolPtr->lpszText = LPSTR_TEXTCALLBACKW;
1808 else {
1809 if ( (toolPtr->lpszText) &&
1810 !IS_INTRESOURCE(toolPtr->lpszText) ) {
1811 if( toolPtr->lpszText != LPSTR_TEXTCALLBACKW)
1812 Free (toolPtr->lpszText);
1813 toolPtr->lpszText = NULL;
1815 if (ti->lpszText) {
1816 if (isW) {
1817 INT len = lstrlenW (ti->lpszText);
1818 toolPtr->lpszText = Alloc ((len+1)*sizeof(WCHAR));
1819 strcpyW (toolPtr->lpszText, ti->lpszText);
1821 else {
1822 INT len = MultiByteToWideChar(CP_ACP, 0, (LPSTR)ti->lpszText,
1823 -1, NULL, 0);
1824 toolPtr->lpszText = Alloc (len * sizeof(WCHAR));
1825 MultiByteToWideChar(CP_ACP, 0, (LPSTR)ti->lpszText, -1,
1826 toolPtr->lpszText, len);
1832 if(infoPtr->nCurrentTool == -1) return 0;
1833 /* force repaint */
1834 if (infoPtr->bActive)
1835 TOOLTIPS_Show (infoPtr, FALSE);
1836 else if (infoPtr->bTrackActive)
1837 TOOLTIPS_Show (infoPtr, TRUE);
1839 return 0;
1843 static LRESULT
1844 TOOLTIPS_Create (HWND hwnd)
1846 TOOLTIPS_INFO *infoPtr;
1848 /* allocate memory for info structure */
1849 infoPtr = Alloc (sizeof(TOOLTIPS_INFO));
1850 SetWindowLongPtrW (hwnd, 0, (DWORD_PTR)infoPtr);
1852 /* initialize info structure */
1853 infoPtr->bActive = TRUE;
1854 infoPtr->bTrackActive = FALSE;
1856 infoPtr->nMaxTipWidth = -1;
1857 infoPtr->nTool = -1;
1858 infoPtr->nCurrentTool = -1;
1859 infoPtr->nTrackTool = -1;
1860 infoPtr->hwndSelf = hwnd;
1862 /* initialize colours and fonts */
1863 TOOLTIPS_InitSystemSettings(infoPtr);
1865 TOOLTIPS_SetDelayTime(infoPtr, TTDT_AUTOMATIC, 0);
1867 SetWindowPos (hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOZORDER | SWP_HIDEWINDOW | SWP_NOACTIVATE);
1869 return 0;
1873 static LRESULT
1874 TOOLTIPS_Destroy (TOOLTIPS_INFO *infoPtr)
1876 TTTOOL_INFO *toolPtr;
1877 UINT i;
1879 /* free tools */
1880 if (infoPtr->tools) {
1881 for (i = 0; i < infoPtr->uNumTools; i++) {
1882 toolPtr = &infoPtr->tools[i];
1883 if (toolPtr->lpszText) {
1884 if ( (toolPtr->lpszText != LPSTR_TEXTCALLBACKW) &&
1885 !IS_INTRESOURCE(toolPtr->lpszText) )
1887 Free (toolPtr->lpszText);
1888 toolPtr->lpszText = NULL;
1892 /* remove subclassing */
1893 if (toolPtr->uFlags & TTF_SUBCLASS) {
1894 if (toolPtr->uFlags & TTF_IDISHWND) {
1895 RemoveWindowSubclass((HWND)toolPtr->uId, TOOLTIPS_SubclassProc, 1);
1897 else {
1898 RemoveWindowSubclass(toolPtr->hwnd, TOOLTIPS_SubclassProc, 1);
1902 Free (infoPtr->tools);
1905 /* free title string */
1906 Free (infoPtr->pszTitle);
1907 /* free title icon if not a standard one */
1908 if (TOOLTIPS_GetTitleIconIndex(infoPtr->hTitleIcon) > TTI_ERROR)
1909 DeleteObject(infoPtr->hTitleIcon);
1911 /* delete fonts */
1912 DeleteObject (infoPtr->hFont);
1913 DeleteObject (infoPtr->hTitleFont);
1915 /* free tool tips info data */
1916 SetWindowLongPtrW(infoPtr->hwndSelf, 0, 0);
1917 Free (infoPtr);
1919 return 0;
1923 static inline LRESULT
1924 TOOLTIPS_GetFont (const TOOLTIPS_INFO *infoPtr)
1926 return (LRESULT)infoPtr->hFont;
1930 static LRESULT
1931 TOOLTIPS_MouseMessage (TOOLTIPS_INFO *infoPtr)
1933 TOOLTIPS_Hide (infoPtr);
1935 return 0;
1939 static LRESULT
1940 TOOLTIPS_NCCreate (HWND hwnd)
1942 DWORD dwStyle = GetWindowLongW (hwnd, GWL_STYLE);
1943 DWORD dwExStyle = GetWindowLongW (hwnd, GWL_EXSTYLE);
1945 dwStyle &= ~(WS_CHILD | /*WS_MAXIMIZE |*/ WS_BORDER | WS_DLGFRAME);
1946 dwStyle |= (WS_POPUP | WS_BORDER | WS_CLIPSIBLINGS);
1948 /* WS_BORDER only draws a border round the window rect, not the
1949 * window region, therefore it is useless to us in balloon mode */
1950 if (dwStyle & TTS_BALLOON) dwStyle &= ~WS_BORDER;
1952 SetWindowLongW (hwnd, GWL_STYLE, dwStyle);
1954 dwExStyle |= WS_EX_TOOLWINDOW;
1955 SetWindowLongW (hwnd, GWL_EXSTYLE, dwExStyle);
1957 return TRUE;
1961 static LRESULT
1962 TOOLTIPS_NCHitTest (const TOOLTIPS_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
1964 INT nTool = (infoPtr->bTrackActive) ? infoPtr->nTrackTool : infoPtr->nTool;
1966 TRACE(" nTool=%d\n", nTool);
1968 if ((nTool > -1) && (nTool < infoPtr->uNumTools)) {
1969 if (infoPtr->tools[nTool].uFlags & TTF_TRANSPARENT) {
1970 TRACE("-- in transparent mode!\n");
1971 return HTTRANSPARENT;
1975 return DefWindowProcW (infoPtr->hwndSelf, WM_NCHITTEST, wParam, lParam);
1979 static LRESULT
1980 TOOLTIPS_NotifyFormat (TOOLTIPS_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
1982 FIXME ("hwnd=%p wParam=%lx lParam=%lx\n", infoPtr->hwndSelf, wParam, lParam);
1984 return 0;
1988 static LRESULT
1989 TOOLTIPS_Paint (const TOOLTIPS_INFO *infoPtr, HDC hDC)
1991 HDC hdc;
1992 PAINTSTRUCT ps;
1994 hdc = (hDC == NULL) ? BeginPaint (infoPtr->hwndSelf, &ps) : hDC;
1995 TOOLTIPS_Refresh (infoPtr, hdc);
1996 if (!hDC)
1997 EndPaint (infoPtr->hwndSelf, &ps);
1998 return 0;
2002 static LRESULT
2003 TOOLTIPS_SetFont (TOOLTIPS_INFO *infoPtr, HFONT hFont, BOOL redraw)
2005 LOGFONTW lf;
2007 if(!GetObjectW(hFont, sizeof(lf), &lf))
2008 return 0;
2010 DeleteObject (infoPtr->hFont);
2011 infoPtr->hFont = CreateFontIndirectW(&lf);
2013 DeleteObject (infoPtr->hTitleFont);
2014 lf.lfWeight = FW_BOLD;
2015 infoPtr->hTitleFont = CreateFontIndirectW(&lf);
2017 if (redraw & (infoPtr->nCurrentTool != -1)) {
2018 FIXME("full redraw needed!\n");
2021 return 0;
2024 /******************************************************************
2025 * TOOLTIPS_GetTextLength
2027 * This function is called when the tooltip receive a
2028 * WM_GETTEXTLENGTH message.
2030 * returns the length, in characters, of the tip text
2032 static inline LRESULT
2033 TOOLTIPS_GetTextLength(const TOOLTIPS_INFO *infoPtr)
2035 return strlenW(infoPtr->szTipText);
2038 /******************************************************************
2039 * TOOLTIPS_OnWMGetText
2041 * This function is called when the tooltip receive a
2042 * WM_GETTEXT message.
2043 * wParam : specifies the maximum number of characters to be copied
2044 * lParam : is the pointer to the buffer that will receive
2045 * the tip text
2047 * returns the number of characters copied
2049 static LRESULT
2050 TOOLTIPS_OnWMGetText (const TOOLTIPS_INFO *infoPtr, WPARAM size, LPWSTR pszText)
2052 LRESULT res;
2054 if(!infoPtr->szTipText || !size)
2055 return 0;
2057 res = min(strlenW(infoPtr->szTipText)+1, size);
2058 memcpy(pszText, infoPtr->szTipText, res*sizeof(WCHAR));
2059 pszText[res-1] = '\0';
2060 return res-1;
2063 static LRESULT
2064 TOOLTIPS_Timer (TOOLTIPS_INFO *infoPtr, INT iTimer)
2066 INT nOldTool;
2068 TRACE("timer %d (%p) expired!\n", iTimer, infoPtr->hwndSelf);
2070 switch (iTimer) {
2071 case ID_TIMERSHOW:
2072 KillTimer (infoPtr->hwndSelf, ID_TIMERSHOW);
2073 nOldTool = infoPtr->nTool;
2074 if ((infoPtr->nTool = TOOLTIPS_CheckTool (infoPtr, TRUE)) == nOldTool)
2075 TOOLTIPS_Show (infoPtr, FALSE);
2076 break;
2078 case ID_TIMERPOP:
2079 TOOLTIPS_Hide (infoPtr);
2080 break;
2082 case ID_TIMERLEAVE:
2083 nOldTool = infoPtr->nTool;
2084 infoPtr->nTool = TOOLTIPS_CheckTool (infoPtr, FALSE);
2085 TRACE("tool (%p) %d %d %d\n", infoPtr->hwndSelf, nOldTool,
2086 infoPtr->nTool, infoPtr->nCurrentTool);
2087 if (infoPtr->nTool != nOldTool) {
2088 if(infoPtr->nTool == -1) { /* Moved out of all tools */
2089 TOOLTIPS_Hide(infoPtr);
2090 KillTimer(infoPtr->hwndSelf, ID_TIMERLEAVE);
2091 } else if (nOldTool == -1) { /* Moved from outside */
2092 ERR("How did this happen?\n");
2093 } else { /* Moved from one to another */
2094 TOOLTIPS_Hide (infoPtr);
2095 KillTimer(infoPtr->hwndSelf, ID_TIMERLEAVE);
2096 if(infoPtr->bActive) {
2097 SetTimer (infoPtr->hwndSelf, ID_TIMERSHOW, infoPtr->nReshowTime, 0);
2098 TRACE("timer 1 started!\n");
2102 break;
2104 default:
2105 ERR("Unknown timer id %d\n", iTimer);
2106 break;
2108 return 0;
2112 static LRESULT
2113 TOOLTIPS_WinIniChange (TOOLTIPS_INFO *infoPtr)
2115 TOOLTIPS_InitSystemSettings (infoPtr);
2117 return 0;
2121 static LRESULT CALLBACK
2122 TOOLTIPS_SubclassProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uID, DWORD_PTR dwRef)
2124 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr ((HWND)dwRef);
2125 MSG msg;
2127 switch(uMsg) {
2128 case WM_MOUSEMOVE:
2129 case WM_LBUTTONDOWN:
2130 case WM_LBUTTONUP:
2131 case WM_MBUTTONDOWN:
2132 case WM_MBUTTONUP:
2133 case WM_RBUTTONDOWN:
2134 case WM_RBUTTONUP:
2135 msg.hwnd = hwnd;
2136 msg.message = uMsg;
2137 msg.wParam = wParam;
2138 msg.lParam = lParam;
2139 TOOLTIPS_RelayEvent(infoPtr, &msg);
2140 break;
2142 default:
2143 break;
2145 return DefSubclassProc(hwnd, uMsg, wParam, lParam);
2149 static LRESULT CALLBACK
2150 TOOLTIPS_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2152 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
2154 TRACE("hwnd=%p msg=%x wparam=%lx lParam=%lx\n", hwnd, uMsg, wParam, lParam);
2155 if (!infoPtr && (uMsg != WM_CREATE) && (uMsg != WM_NCCREATE))
2156 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
2157 switch (uMsg)
2159 case TTM_ACTIVATE:
2160 return TOOLTIPS_Activate (infoPtr, (BOOL)wParam);
2162 case TTM_ADDTOOLA:
2163 case TTM_ADDTOOLW:
2164 return TOOLTIPS_AddToolT (infoPtr, (LPTTTOOLINFOW)lParam, uMsg == TTM_ADDTOOLW);
2166 case TTM_DELTOOLA:
2167 case TTM_DELTOOLW:
2168 return TOOLTIPS_DelToolT (infoPtr, (LPTOOLINFOW)lParam,
2169 uMsg == TTM_DELTOOLW);
2170 case TTM_ENUMTOOLSA:
2171 case TTM_ENUMTOOLSW:
2172 return TOOLTIPS_EnumToolsT (infoPtr, (UINT)wParam, (LPTTTOOLINFOW)lParam,
2173 uMsg == TTM_ENUMTOOLSW);
2174 case TTM_GETBUBBLESIZE:
2175 return TOOLTIPS_GetBubbleSize (infoPtr, (LPTTTOOLINFOW)lParam);
2177 case TTM_GETCURRENTTOOLA:
2178 case TTM_GETCURRENTTOOLW:
2179 return TOOLTIPS_GetCurrentToolT (infoPtr, (LPTTTOOLINFOW)lParam,
2180 uMsg == TTM_GETCURRENTTOOLW);
2182 case TTM_GETDELAYTIME:
2183 return TOOLTIPS_GetDelayTime (infoPtr, (DWORD)wParam);
2185 case TTM_GETMARGIN:
2186 return TOOLTIPS_GetMargin (infoPtr, (LPRECT)lParam);
2188 case TTM_GETMAXTIPWIDTH:
2189 return TOOLTIPS_GetMaxTipWidth (infoPtr);
2191 case TTM_GETTEXTA:
2192 case TTM_GETTEXTW:
2193 return TOOLTIPS_GetTextT (infoPtr, (LPTTTOOLINFOW)lParam,
2194 uMsg == TTM_GETTEXTW);
2196 case TTM_GETTIPBKCOLOR:
2197 return TOOLTIPS_GetTipBkColor (infoPtr);
2199 case TTM_GETTIPTEXTCOLOR:
2200 return TOOLTIPS_GetTipTextColor (infoPtr);
2202 case TTM_GETTOOLCOUNT:
2203 return TOOLTIPS_GetToolCount (infoPtr);
2205 case TTM_GETTOOLINFOA:
2206 case TTM_GETTOOLINFOW:
2207 return TOOLTIPS_GetToolInfoT (infoPtr, (LPTTTOOLINFOW)lParam,
2208 uMsg == TTM_GETTOOLINFOW);
2210 case TTM_HITTESTA:
2211 case TTM_HITTESTW:
2212 return TOOLTIPS_HitTestT (infoPtr, (LPTTHITTESTINFOW)lParam,
2213 uMsg == TTM_HITTESTW);
2214 case TTM_NEWTOOLRECTA:
2215 case TTM_NEWTOOLRECTW:
2216 return TOOLTIPS_NewToolRectT (infoPtr, (LPTTTOOLINFOW)lParam);
2218 case TTM_POP:
2219 return TOOLTIPS_Pop (infoPtr);
2221 case TTM_RELAYEVENT:
2222 return TOOLTIPS_RelayEvent (infoPtr, (LPMSG)lParam);
2224 case TTM_SETDELAYTIME:
2225 return TOOLTIPS_SetDelayTime (infoPtr, (DWORD)wParam, (INT)LOWORD(lParam));
2227 case TTM_SETMARGIN:
2228 return TOOLTIPS_SetMargin (infoPtr, (LPRECT)lParam);
2230 case TTM_SETMAXTIPWIDTH:
2231 return TOOLTIPS_SetMaxTipWidth (infoPtr, (INT)lParam);
2233 case TTM_SETTIPBKCOLOR:
2234 return TOOLTIPS_SetTipBkColor (infoPtr, (COLORREF)wParam);
2236 case TTM_SETTIPTEXTCOLOR:
2237 return TOOLTIPS_SetTipTextColor (infoPtr, (COLORREF)wParam);
2239 case TTM_SETTITLEA:
2240 case TTM_SETTITLEW:
2241 return TOOLTIPS_SetTitleT (infoPtr, (UINT_PTR)wParam, (LPCWSTR)lParam,
2242 uMsg == TTM_SETTITLEW);
2244 case TTM_SETTOOLINFOA:
2245 case TTM_SETTOOLINFOW:
2246 return TOOLTIPS_SetToolInfoT (infoPtr, (LPTTTOOLINFOW)lParam,
2247 uMsg == TTM_SETTOOLINFOW);
2249 case TTM_TRACKACTIVATE:
2250 return TOOLTIPS_TrackActivate (infoPtr, (BOOL)wParam, (LPTTTOOLINFOA)lParam);
2252 case TTM_TRACKPOSITION:
2253 return TOOLTIPS_TrackPosition (infoPtr, lParam);
2255 case TTM_UPDATE:
2256 return TOOLTIPS_Update (infoPtr);
2258 case TTM_UPDATETIPTEXTA:
2259 case TTM_UPDATETIPTEXTW:
2260 return TOOLTIPS_UpdateTipTextT (infoPtr, (LPTTTOOLINFOW)lParam,
2261 uMsg == TTM_UPDATETIPTEXTW);
2263 case TTM_WINDOWFROMPOINT:
2264 return (LRESULT)WindowFromPoint (*((LPPOINT)lParam));
2266 case WM_CREATE:
2267 return TOOLTIPS_Create (hwnd);
2269 case WM_DESTROY:
2270 return TOOLTIPS_Destroy (infoPtr);
2272 case WM_ERASEBKGND:
2273 /* we draw the background in WM_PAINT */
2274 return 0;
2276 case WM_GETFONT:
2277 return TOOLTIPS_GetFont (infoPtr);
2279 case WM_GETTEXT:
2280 return TOOLTIPS_OnWMGetText (infoPtr, wParam, (LPWSTR)lParam);
2282 case WM_GETTEXTLENGTH:
2283 return TOOLTIPS_GetTextLength (infoPtr);
2285 case WM_LBUTTONDOWN:
2286 case WM_LBUTTONUP:
2287 case WM_MBUTTONDOWN:
2288 case WM_MBUTTONUP:
2289 case WM_RBUTTONDOWN:
2290 case WM_RBUTTONUP:
2291 case WM_MOUSEMOVE:
2292 return TOOLTIPS_MouseMessage (infoPtr);
2294 case WM_NCCREATE:
2295 return TOOLTIPS_NCCreate (hwnd);
2297 case WM_NCHITTEST:
2298 return TOOLTIPS_NCHitTest (infoPtr, wParam, lParam);
2300 case WM_NOTIFYFORMAT:
2301 return TOOLTIPS_NotifyFormat (infoPtr, wParam, lParam);
2303 case WM_PRINTCLIENT:
2304 case WM_PAINT:
2305 return TOOLTIPS_Paint (infoPtr, (HDC)wParam);
2307 case WM_SETFONT:
2308 return TOOLTIPS_SetFont (infoPtr, (HFONT)wParam, LOWORD(lParam));
2310 case WM_SYSCOLORCHANGE:
2311 COMCTL32_RefreshSysColors();
2312 return 0;
2314 case WM_TIMER:
2315 return TOOLTIPS_Timer (infoPtr, (INT)wParam);
2317 case WM_WININICHANGE:
2318 return TOOLTIPS_WinIniChange (infoPtr);
2320 default:
2321 if ((uMsg >= WM_USER) && (uMsg < WM_APP) && !COMCTL32_IsReflectedMessage(uMsg))
2322 ERR("unknown msg %04x wp=%08lx lp=%08lx\n",
2323 uMsg, wParam, lParam);
2324 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
2329 VOID
2330 TOOLTIPS_Register (void)
2332 WNDCLASSW wndClass;
2334 ZeroMemory (&wndClass, sizeof(WNDCLASSW));
2335 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS | CS_SAVEBITS;
2336 wndClass.lpfnWndProc = TOOLTIPS_WindowProc;
2337 wndClass.cbClsExtra = 0;
2338 wndClass.cbWndExtra = sizeof(TOOLTIPS_INFO *);
2339 wndClass.hCursor = LoadCursorW (0, (LPWSTR)IDC_ARROW);
2340 wndClass.hbrBackground = 0;
2341 wndClass.lpszClassName = TOOLTIPS_CLASSW;
2343 RegisterClassW (&wndClass);
2345 hTooltipIcons[TTI_NONE] = NULL;
2346 hTooltipIcons[TTI_INFO] = LoadImageW(COMCTL32_hModule,
2347 (LPCWSTR)MAKEINTRESOURCE(IDI_TT_INFO_SM), IMAGE_ICON, 0, 0, 0);
2348 hTooltipIcons[TTI_WARNING] = LoadImageW(COMCTL32_hModule,
2349 (LPCWSTR)MAKEINTRESOURCE(IDI_TT_WARN_SM), IMAGE_ICON, 0, 0, 0);
2350 hTooltipIcons[TTI_ERROR] = LoadImageW(COMCTL32_hModule,
2351 (LPCWSTR)MAKEINTRESOURCE(IDI_TT_ERROR_SM), IMAGE_ICON, 0, 0, 0);
2355 VOID
2356 TOOLTIPS_Unregister (void)
2358 int i;
2359 for (i = TTI_INFO; i <= TTI_ERROR; i++)
2360 DestroyIcon(hTooltipIcons[i]);
2361 UnregisterClassW (TOOLTIPS_CLASSW, NULL);