mlang/tests: Make the tests more silent.
[wine/hacks.git] / dlls / comctl32 / tooltips.c
blobcf952c7595af7c7475a35555d425cc9c08091eb7
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 UINT_PTR
179 TOOLTIPS_GetTitleIconIndex(HICON hIcon)
181 UINT i;
182 for (i = 0; i <= TTI_ERROR; i++)
183 if (hTooltipIcons[i] == hIcon)
184 return i;
185 return (UINT_PTR)hIcon;
188 static void
189 TOOLTIPS_InitSystemSettings (TOOLTIPS_INFO *infoPtr)
191 NONCLIENTMETRICSW nclm;
193 infoPtr->clrBk = comctl32_color.clrInfoBk;
194 infoPtr->clrText = comctl32_color.clrInfoText;
196 DeleteObject (infoPtr->hFont);
197 nclm.cbSize = sizeof(nclm);
198 SystemParametersInfoW (SPI_GETNONCLIENTMETRICS, sizeof(nclm), &nclm, 0);
199 infoPtr->hFont = CreateFontIndirectW (&nclm.lfStatusFont);
201 DeleteObject (infoPtr->hTitleFont);
202 nclm.lfStatusFont.lfWeight = FW_BOLD;
203 infoPtr->hTitleFont = CreateFontIndirectW (&nclm.lfStatusFont);
206 /* Custom draw routines */
207 static void
208 TOOLTIPS_customdraw_fill(NMTTCUSTOMDRAW *lpnmttcd,
209 const HWND hwnd,
210 HDC hdc, const RECT *rcBounds, UINT uFlags)
212 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr(hwnd);
214 ZeroMemory(lpnmttcd, sizeof(NMTTCUSTOMDRAW));
215 lpnmttcd->uDrawFlags = uFlags;
216 lpnmttcd->nmcd.hdr.hwndFrom = hwnd;
217 lpnmttcd->nmcd.hdr.code = NM_CUSTOMDRAW;
218 if (infoPtr->nCurrentTool != -1) {
219 TTTOOL_INFO *toolPtr = &infoPtr->tools[infoPtr->nCurrentTool];
220 lpnmttcd->nmcd.hdr.idFrom = toolPtr->uId;
222 lpnmttcd->nmcd.hdc = hdc;
223 lpnmttcd->nmcd.rc = *rcBounds;
224 /* FIXME - dwItemSpec, uItemState, lItemlParam */
227 static inline DWORD
228 TOOLTIPS_notify_customdraw (DWORD dwDrawStage, NMTTCUSTOMDRAW *lpnmttcd)
230 LRESULT result = CDRF_DODEFAULT;
231 lpnmttcd->nmcd.dwDrawStage = dwDrawStage;
233 TRACE("Notifying stage %d, flags %x, id %x\n", lpnmttcd->nmcd.dwDrawStage,
234 lpnmttcd->uDrawFlags, lpnmttcd->nmcd.hdr.code);
236 result = SendMessageW(GetParent(lpnmttcd->nmcd.hdr.hwndFrom), WM_NOTIFY,
237 0, (LPARAM)lpnmttcd);
239 TRACE("Notify result %x\n", (unsigned int)result);
241 return result;
244 static void
245 TOOLTIPS_Refresh (const TOOLTIPS_INFO *infoPtr, HDC hdc)
247 RECT rc;
248 INT oldBkMode;
249 HFONT hOldFont;
250 HBRUSH hBrush;
251 UINT uFlags = DT_EXTERNALLEADING;
252 HRGN hRgn = NULL;
253 DWORD dwStyle = GetWindowLongW(infoPtr->hwndSelf, GWL_STYLE);
254 NMTTCUSTOMDRAW nmttcd;
255 DWORD cdmode;
257 if (infoPtr->nMaxTipWidth > -1)
258 uFlags |= DT_WORDBREAK;
259 if (GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE) & TTS_NOPREFIX)
260 uFlags |= DT_NOPREFIX;
261 GetClientRect (infoPtr->hwndSelf, &rc);
263 hBrush = CreateSolidBrush(infoPtr->clrBk);
265 oldBkMode = SetBkMode (hdc, TRANSPARENT);
266 SetTextColor (hdc, infoPtr->clrText);
267 hOldFont = SelectObject (hdc, infoPtr->hFont);
269 /* Custom draw - Call PrePaint once initial properties set up */
270 /* Note: Contrary to MSDN, CDRF_SKIPDEFAULT still draws a tooltip */
271 TOOLTIPS_customdraw_fill(&nmttcd, infoPtr->hwndSelf, hdc, &rc, uFlags);
272 cdmode = TOOLTIPS_notify_customdraw(CDDS_PREPAINT, &nmttcd);
273 uFlags = nmttcd.uDrawFlags;
275 if (dwStyle & TTS_BALLOON)
277 /* create a region to store result into */
278 hRgn = CreateRectRgn(0, 0, 0, 0);
280 GetWindowRgn(infoPtr->hwndSelf, hRgn);
282 /* fill the background */
283 FillRgn(hdc, hRgn, hBrush);
284 DeleteObject(hBrush);
285 hBrush = NULL;
287 else
289 /* fill the background */
290 FillRect(hdc, &rc, hBrush);
291 DeleteObject(hBrush);
292 hBrush = NULL;
295 if ((dwStyle & TTS_BALLOON) || infoPtr->pszTitle)
297 /* calculate text rectangle */
298 rc.left += (BALLOON_TEXT_MARGIN + infoPtr->rcMargin.left);
299 rc.top += (BALLOON_TEXT_MARGIN + infoPtr->rcMargin.top);
300 rc.right -= (BALLOON_TEXT_MARGIN + infoPtr->rcMargin.right);
301 rc.bottom -= (BALLOON_TEXT_MARGIN + infoPtr->rcMargin.bottom);
302 if(infoPtr->bToolBelow) rc.top += BALLOON_STEMHEIGHT;
304 if (infoPtr->pszTitle)
306 RECT rcTitle = {rc.left, rc.top, rc.right, rc.bottom};
307 int height;
308 BOOL icon_present;
309 HFONT prevFont;
311 /* draw icon */
312 icon_present = infoPtr->hTitleIcon &&
313 DrawIconEx(hdc, rc.left, rc.top, infoPtr->hTitleIcon,
314 ICON_WIDTH, ICON_HEIGHT, 0, NULL, DI_NORMAL);
315 if (icon_present)
316 rcTitle.left += ICON_WIDTH + BALLOON_ICON_TITLE_SPACING;
318 rcTitle.bottom = rc.top + ICON_HEIGHT;
320 /* draw title text */
321 prevFont = SelectObject (hdc, infoPtr->hTitleFont);
322 height = DrawTextW(hdc, infoPtr->pszTitle, -1, &rcTitle, DT_BOTTOM | DT_SINGLELINE | DT_NOPREFIX);
323 SelectObject (hdc, prevFont);
324 rc.top += height + BALLOON_TITLE_TEXT_SPACING;
327 else
329 /* calculate text rectangle */
330 rc.left += (NORMAL_TEXT_MARGIN + infoPtr->rcMargin.left);
331 rc.top += (NORMAL_TEXT_MARGIN + infoPtr->rcMargin.top);
332 rc.right -= (NORMAL_TEXT_MARGIN + infoPtr->rcMargin.right);
333 rc.bottom -= (NORMAL_TEXT_MARGIN + infoPtr->rcMargin.bottom);
336 /* draw text */
337 DrawTextW (hdc, infoPtr->szTipText, -1, &rc, uFlags);
339 /* Custom draw - Call PostPaint after drawing */
340 if (cdmode & CDRF_NOTIFYPOSTPAINT) {
341 TOOLTIPS_notify_customdraw(CDDS_POSTPAINT, &nmttcd);
344 /* be polite and reset the things we changed in the dc */
345 SelectObject (hdc, hOldFont);
346 SetBkMode (hdc, oldBkMode);
348 if (dwStyle & TTS_BALLOON)
350 /* frame region because default window proc doesn't do it */
351 INT width = GetSystemMetrics(SM_CXDLGFRAME) - GetSystemMetrics(SM_CXEDGE);
352 INT height = GetSystemMetrics(SM_CYDLGFRAME) - GetSystemMetrics(SM_CYEDGE);
354 hBrush = GetSysColorBrush(COLOR_WINDOWFRAME);
355 FrameRgn(hdc, hRgn, hBrush, width, height);
358 if (hRgn)
359 DeleteObject(hRgn);
362 static void TOOLTIPS_GetDispInfoA(TOOLTIPS_INFO *infoPtr, TTTOOL_INFO *toolPtr)
364 NMTTDISPINFOA ttnmdi;
366 /* fill NMHDR struct */
367 ZeroMemory (&ttnmdi, sizeof(NMTTDISPINFOA));
368 ttnmdi.hdr.hwndFrom = infoPtr->hwndSelf;
369 ttnmdi.hdr.idFrom = toolPtr->uId;
370 ttnmdi.hdr.code = TTN_GETDISPINFOA; /* == TTN_NEEDTEXTA */
371 ttnmdi.lpszText = ttnmdi.szText;
372 ttnmdi.uFlags = toolPtr->uFlags;
373 ttnmdi.lParam = toolPtr->lParam;
375 TRACE("hdr.idFrom = %lx\n", ttnmdi.hdr.idFrom);
376 SendMessageW(toolPtr->hwnd, WM_NOTIFY, toolPtr->uId, (LPARAM)&ttnmdi);
378 if (IS_INTRESOURCE(ttnmdi.lpszText)) {
379 LoadStringW(ttnmdi.hinst, LOWORD(ttnmdi.lpszText),
380 infoPtr->szTipText, INFOTIPSIZE);
381 if (ttnmdi.uFlags & TTF_DI_SETITEM) {
382 toolPtr->hinst = ttnmdi.hinst;
383 toolPtr->lpszText = (LPWSTR)ttnmdi.lpszText;
386 else if (ttnmdi.lpszText == 0) {
387 infoPtr->szTipText[0] = '\0';
389 else if (ttnmdi.lpszText != LPSTR_TEXTCALLBACKA) {
390 Str_GetPtrAtoW(ttnmdi.lpszText, infoPtr->szTipText, INFOTIPSIZE);
391 if (ttnmdi.uFlags & TTF_DI_SETITEM) {
392 toolPtr->hinst = 0;
393 toolPtr->lpszText = NULL;
394 Str_SetPtrW(&toolPtr->lpszText, infoPtr->szTipText);
397 else {
398 ERR("recursive text callback!\n");
399 infoPtr->szTipText[0] = '\0';
402 /* no text available - try calling parent instead as per native */
403 /* FIXME: Unsure if SETITEM should save the value or not */
404 if (infoPtr->szTipText[0] == 0x00) {
406 SendMessageW(GetParent(toolPtr->hwnd), WM_NOTIFY, toolPtr->uId, (LPARAM)&ttnmdi);
408 if (IS_INTRESOURCE(ttnmdi.lpszText)) {
409 LoadStringW(ttnmdi.hinst, LOWORD(ttnmdi.lpszText),
410 infoPtr->szTipText, INFOTIPSIZE);
411 } else if (ttnmdi.lpszText &&
412 ttnmdi.lpszText != LPSTR_TEXTCALLBACKA) {
413 Str_GetPtrAtoW(ttnmdi.lpszText, infoPtr->szTipText, INFOTIPSIZE);
418 static void TOOLTIPS_GetDispInfoW(TOOLTIPS_INFO *infoPtr, TTTOOL_INFO *toolPtr)
420 NMTTDISPINFOW ttnmdi;
422 /* fill NMHDR struct */
423 ZeroMemory (&ttnmdi, sizeof(NMTTDISPINFOW));
424 ttnmdi.hdr.hwndFrom = infoPtr->hwndSelf;
425 ttnmdi.hdr.idFrom = toolPtr->uId;
426 ttnmdi.hdr.code = TTN_GETDISPINFOW; /* == TTN_NEEDTEXTW */
427 ttnmdi.lpszText = ttnmdi.szText;
428 ttnmdi.uFlags = toolPtr->uFlags;
429 ttnmdi.lParam = toolPtr->lParam;
431 TRACE("hdr.idFrom = %lx\n", ttnmdi.hdr.idFrom);
432 SendMessageW(toolPtr->hwnd, WM_NOTIFY, toolPtr->uId, (LPARAM)&ttnmdi);
434 if (IS_INTRESOURCE(ttnmdi.lpszText)) {
435 LoadStringW(ttnmdi.hinst, LOWORD(ttnmdi.lpszText),
436 infoPtr->szTipText, INFOTIPSIZE);
437 if (ttnmdi.uFlags & TTF_DI_SETITEM) {
438 toolPtr->hinst = ttnmdi.hinst;
439 toolPtr->lpszText = ttnmdi.lpszText;
442 else if (ttnmdi.lpszText == 0) {
443 infoPtr->szTipText[0] = '\0';
445 else if (ttnmdi.lpszText != LPSTR_TEXTCALLBACKW) {
446 Str_GetPtrW(ttnmdi.lpszText, infoPtr->szTipText, INFOTIPSIZE);
447 if (ttnmdi.uFlags & TTF_DI_SETITEM) {
448 toolPtr->hinst = 0;
449 toolPtr->lpszText = NULL;
450 Str_SetPtrW(&toolPtr->lpszText, infoPtr->szTipText);
453 else {
454 ERR("recursive text callback!\n");
455 infoPtr->szTipText[0] = '\0';
458 /* no text available - try calling parent instead as per native */
459 /* FIXME: Unsure if SETITEM should save the value or not */
460 if (infoPtr->szTipText[0] == 0x00) {
462 SendMessageW(GetParent(toolPtr->hwnd), WM_NOTIFY, toolPtr->uId, (LPARAM)&ttnmdi);
464 if (IS_INTRESOURCE(ttnmdi.lpszText)) {
465 LoadStringW(ttnmdi.hinst, LOWORD(ttnmdi.lpszText),
466 infoPtr->szTipText, INFOTIPSIZE);
467 } else if (ttnmdi.lpszText &&
468 ttnmdi.lpszText != LPSTR_TEXTCALLBACKW) {
469 Str_GetPtrW(ttnmdi.lpszText, infoPtr->szTipText, INFOTIPSIZE);
475 static void
476 TOOLTIPS_GetTipText (TOOLTIPS_INFO *infoPtr, INT nTool)
478 TTTOOL_INFO *toolPtr = &infoPtr->tools[nTool];
480 if (IS_INTRESOURCE(toolPtr->lpszText) && toolPtr->hinst) {
481 /* load a resource */
482 TRACE("load res string %p %x\n",
483 toolPtr->hinst, LOWORD(toolPtr->lpszText));
484 LoadStringW (toolPtr->hinst, LOWORD(toolPtr->lpszText),
485 infoPtr->szTipText, INFOTIPSIZE);
487 else if (toolPtr->lpszText) {
488 if (toolPtr->lpszText == LPSTR_TEXTCALLBACKW) {
489 if (toolPtr->bNotifyUnicode)
490 TOOLTIPS_GetDispInfoW(infoPtr, toolPtr);
491 else
492 TOOLTIPS_GetDispInfoA(infoPtr, toolPtr);
494 else {
495 /* the item is a usual (unicode) text */
496 lstrcpynW (infoPtr->szTipText, toolPtr->lpszText, INFOTIPSIZE);
499 else {
500 /* no text available */
501 infoPtr->szTipText[0] = '\0';
504 TRACE("%s\n", debugstr_w(infoPtr->szTipText));
508 static void
509 TOOLTIPS_CalcTipSize (const TOOLTIPS_INFO *infoPtr, LPSIZE lpSize)
511 HDC hdc;
512 HFONT hOldFont;
513 DWORD style = GetWindowLongW(infoPtr->hwndSelf, GWL_STYLE);
514 UINT uFlags = DT_EXTERNALLEADING | DT_CALCRECT;
515 RECT rc = {0, 0, 0, 0};
516 SIZE title = {0, 0};
518 if (infoPtr->nMaxTipWidth > -1) {
519 rc.right = infoPtr->nMaxTipWidth;
520 uFlags |= DT_WORDBREAK;
522 if (style & TTS_NOPREFIX)
523 uFlags |= DT_NOPREFIX;
524 TRACE("%s\n", debugstr_w(infoPtr->szTipText));
526 hdc = GetDC (infoPtr->hwndSelf);
527 if (infoPtr->pszTitle)
529 RECT rcTitle = {0, 0, 0, 0};
530 TRACE("title %s\n", debugstr_w(infoPtr->pszTitle));
531 if (infoPtr->hTitleIcon)
533 title.cx = ICON_WIDTH;
534 title.cy = ICON_HEIGHT;
536 if (title.cx != 0) title.cx += BALLOON_ICON_TITLE_SPACING;
537 hOldFont = SelectObject (hdc, infoPtr->hTitleFont);
538 DrawTextW(hdc, infoPtr->pszTitle, -1, &rcTitle, DT_SINGLELINE | DT_NOPREFIX | DT_CALCRECT);
539 SelectObject (hdc, hOldFont);
540 title.cy = max(title.cy, rcTitle.bottom - rcTitle.top) + BALLOON_TITLE_TEXT_SPACING;
541 title.cx += (rcTitle.right - rcTitle.left);
543 hOldFont = SelectObject (hdc, infoPtr->hFont);
544 DrawTextW (hdc, infoPtr->szTipText, -1, &rc, uFlags);
545 SelectObject (hdc, hOldFont);
546 ReleaseDC (infoPtr->hwndSelf, hdc);
548 if ((style & TTS_BALLOON) || infoPtr->pszTitle)
550 lpSize->cx = max(rc.right - rc.left, title.cx) + 2*BALLOON_TEXT_MARGIN +
551 infoPtr->rcMargin.left + infoPtr->rcMargin.right;
552 lpSize->cy = title.cy + rc.bottom - rc.top + 2*BALLOON_TEXT_MARGIN +
553 infoPtr->rcMargin.bottom + infoPtr->rcMargin.top +
554 BALLOON_STEMHEIGHT;
556 else
558 lpSize->cx = rc.right - rc.left + 2*NORMAL_TEXT_MARGIN +
559 infoPtr->rcMargin.left + infoPtr->rcMargin.right;
560 lpSize->cy = rc.bottom - rc.top + 2*NORMAL_TEXT_MARGIN +
561 infoPtr->rcMargin.bottom + infoPtr->rcMargin.top;
566 static void
567 TOOLTIPS_Show (TOOLTIPS_INFO *infoPtr, BOOL track_activate)
569 TTTOOL_INFO *toolPtr;
570 HMONITOR monitor;
571 MONITORINFO mon_info;
572 RECT rect;
573 SIZE size;
574 NMHDR hdr;
575 int ptfx = 0;
576 DWORD style = GetWindowLongW(infoPtr->hwndSelf, GWL_STYLE);
577 INT nTool;
579 if (track_activate)
581 if (infoPtr->nTrackTool == -1)
583 TRACE("invalid tracking tool (-1)!\n");
584 return;
586 nTool = infoPtr->nTrackTool;
588 else
590 if (infoPtr->nTool == -1)
592 TRACE("invalid tool (-1)!\n");
593 return;
595 nTool = infoPtr->nTool;
598 TRACE("Show tooltip pre %d! (%p)\n", nTool, infoPtr->hwndSelf);
600 TOOLTIPS_GetTipText (infoPtr, nTool);
602 if (infoPtr->szTipText[0] == '\0')
603 return;
605 toolPtr = &infoPtr->tools[nTool];
607 if (!track_activate)
608 infoPtr->nCurrentTool = infoPtr->nTool;
610 TRACE("Show tooltip %d!\n", nTool);
612 hdr.hwndFrom = infoPtr->hwndSelf;
613 hdr.idFrom = toolPtr->uId;
614 hdr.code = TTN_SHOW;
615 SendMessageW (toolPtr->hwnd, WM_NOTIFY, toolPtr->uId, (LPARAM)&hdr);
617 TRACE("%s\n", debugstr_w(infoPtr->szTipText));
619 TOOLTIPS_CalcTipSize (infoPtr, &size);
620 TRACE("size %d x %d\n", size.cx, size.cy);
622 if (track_activate)
624 rect.left = infoPtr->xTrackPos;
625 rect.top = infoPtr->yTrackPos;
626 ptfx = rect.left;
628 if (toolPtr->uFlags & TTF_CENTERTIP)
630 rect.left -= (size.cx / 2);
631 if (!(style & TTS_BALLOON))
632 rect.top -= (size.cy / 2);
634 infoPtr->bToolBelow = TRUE;
636 if (!(toolPtr->uFlags & TTF_ABSOLUTE))
638 if (style & TTS_BALLOON)
639 rect.left -= BALLOON_STEMINDENT;
640 else
642 RECT rcTool;
644 if (toolPtr->uFlags & TTF_IDISHWND)
645 GetWindowRect ((HWND)toolPtr->uId, &rcTool);
646 else
648 rcTool = toolPtr->rect;
649 MapWindowPoints (toolPtr->hwnd, NULL, (LPPOINT)&rcTool, 2);
652 /* smart placement */
653 if ((rect.left + size.cx > rcTool.left) && (rect.left < rcTool.right) &&
654 (rect.top + size.cy > rcTool.top) && (rect.top < rcTool.bottom))
655 rect.left = rcTool.right;
659 else
661 if (toolPtr->uFlags & TTF_CENTERTIP)
663 RECT rc;
665 if (toolPtr->uFlags & TTF_IDISHWND)
666 GetWindowRect ((HWND)toolPtr->uId, &rc);
667 else {
668 rc = toolPtr->rect;
669 MapWindowPoints (toolPtr->hwnd, NULL, (LPPOINT)&rc, 2);
671 rect.left = (rc.left + rc.right - size.cx) / 2;
672 if (style & TTS_BALLOON)
674 ptfx = rc.left + ((rc.right - rc.left) / 2);
676 /* CENTERTIP ballon tooltips default to below the field
677 * if they fit on the screen */
678 if (rc.bottom + size.cy > GetSystemMetrics(SM_CYSCREEN))
680 rect.top = rc.top - size.cy;
681 infoPtr->bToolBelow = FALSE;
683 else
685 infoPtr->bToolBelow = TRUE;
686 rect.top = rc.bottom;
688 rect.left = max(0, rect.left - BALLOON_STEMINDENT);
690 else
692 rect.top = rc.bottom + 2;
693 infoPtr->bToolBelow = TRUE;
696 else
698 GetCursorPos ((LPPOINT)&rect);
699 if (style & TTS_BALLOON)
701 ptfx = rect.left;
702 if(rect.top - size.cy >= 0)
704 rect.top -= size.cy;
705 infoPtr->bToolBelow = FALSE;
707 else
709 infoPtr->bToolBelow = TRUE;
710 rect.top += 20;
712 rect.left = max(0, rect.left - BALLOON_STEMINDENT);
714 else
716 rect.top += 20;
717 infoPtr->bToolBelow = TRUE;
722 TRACE("pos %d - %d\n", rect.left, rect.top);
724 rect.right = rect.left + size.cx;
725 rect.bottom = rect.top + size.cy;
727 /* check position */
729 monitor = MonitorFromRect( &rect, MONITOR_DEFAULTTOPRIMARY );
730 mon_info.cbSize = sizeof(mon_info);
731 GetMonitorInfoW( monitor, &mon_info );
733 if( rect.right > mon_info.rcWork.right ) {
734 rect.left -= rect.right - mon_info.rcWork.right + 2;
735 rect.right = mon_info.rcWork.right - 2;
737 if (rect.left < mon_info.rcWork.left) rect.left = mon_info.rcWork.left;
739 if( rect.bottom > mon_info.rcWork.bottom ) {
740 RECT rc;
742 if (toolPtr->uFlags & TTF_IDISHWND)
743 GetWindowRect ((HWND)toolPtr->uId, &rc);
744 else {
745 rc = toolPtr->rect;
746 MapWindowPoints (toolPtr->hwnd, NULL, (LPPOINT)&rc, 2);
748 rect.bottom = rc.top - 2;
749 rect.top = rect.bottom - size.cy;
752 AdjustWindowRectEx (&rect, GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE),
753 FALSE, GetWindowLongW (infoPtr->hwndSelf, GWL_EXSTYLE));
755 if (style & TTS_BALLOON)
757 HRGN hRgn;
758 HRGN hrStem;
759 POINT pts[3];
761 ptfx -= rect.left;
763 if(infoPtr->bToolBelow)
765 pts[0].x = ptfx;
766 pts[0].y = 0;
767 pts[1].x = max(BALLOON_STEMINDENT, ptfx - (BALLOON_STEMWIDTH / 2));
768 pts[1].y = BALLOON_STEMHEIGHT;
769 pts[2].x = pts[1].x + BALLOON_STEMWIDTH;
770 pts[2].y = pts[1].y;
771 if(pts[2].x > (rect.right - rect.left) - BALLOON_STEMINDENT)
773 pts[2].x = (rect.right - rect.left) - BALLOON_STEMINDENT;
774 pts[1].x = pts[2].x - BALLOON_STEMWIDTH;
777 else
779 pts[0].x = max(BALLOON_STEMINDENT, ptfx - (BALLOON_STEMWIDTH / 2));
780 pts[0].y = (rect.bottom - rect.top) - BALLOON_STEMHEIGHT;
781 pts[1].x = pts[0].x + BALLOON_STEMWIDTH;
782 pts[1].y = pts[0].y;
783 pts[2].x = ptfx;
784 pts[2].y = (rect.bottom - rect.top);
785 if(pts[1].x > (rect.right - rect.left) - BALLOON_STEMINDENT)
787 pts[1].x = (rect.right - rect.left) - BALLOON_STEMINDENT;
788 pts[0].x = pts[1].x - BALLOON_STEMWIDTH;
792 hrStem = CreatePolygonRgn(pts, sizeof(pts) / sizeof(pts[0]), ALTERNATE);
794 hRgn = CreateRoundRectRgn(0,
795 (infoPtr->bToolBelow ? BALLOON_STEMHEIGHT : 0),
796 rect.right - rect.left,
797 (infoPtr->bToolBelow ? rect.bottom - rect.top : rect.bottom - rect.top - BALLOON_STEMHEIGHT),
798 BALLOON_ROUNDEDNESS, BALLOON_ROUNDEDNESS);
800 CombineRgn(hRgn, hRgn, hrStem, RGN_OR);
801 DeleteObject(hrStem);
803 SetWindowRgn(infoPtr->hwndSelf, hRgn, FALSE);
804 /* we don't free the region handle as the system deletes it when
805 * it is no longer needed */
808 SetWindowPos (infoPtr->hwndSelf, HWND_TOPMOST, rect.left, rect.top,
809 rect.right - rect.left, rect.bottom - rect.top,
810 SWP_SHOWWINDOW | SWP_NOACTIVATE);
812 /* repaint the tooltip */
813 InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
814 UpdateWindow(infoPtr->hwndSelf);
816 if (!track_activate)
818 SetTimer (infoPtr->hwndSelf, ID_TIMERPOP, infoPtr->nAutoPopTime, 0);
819 TRACE("timer 2 started!\n");
820 SetTimer (infoPtr->hwndSelf, ID_TIMERLEAVE, infoPtr->nReshowTime, 0);
821 TRACE("timer 3 started!\n");
826 static void
827 TOOLTIPS_Hide (TOOLTIPS_INFO *infoPtr)
829 TTTOOL_INFO *toolPtr;
830 NMHDR hdr;
832 TRACE("Hide tooltip %d! (%p)\n", infoPtr->nCurrentTool, infoPtr->hwndSelf);
834 if (infoPtr->nCurrentTool == -1)
835 return;
837 toolPtr = &infoPtr->tools[infoPtr->nCurrentTool];
838 KillTimer (infoPtr->hwndSelf, ID_TIMERPOP);
840 hdr.hwndFrom = infoPtr->hwndSelf;
841 hdr.idFrom = toolPtr->uId;
842 hdr.code = TTN_POP;
843 SendMessageW (toolPtr->hwnd, WM_NOTIFY, toolPtr->uId, (LPARAM)&hdr);
845 infoPtr->nCurrentTool = -1;
847 SetWindowPos (infoPtr->hwndSelf, HWND_TOP, 0, 0, 0, 0,
848 SWP_NOZORDER | SWP_HIDEWINDOW | SWP_NOACTIVATE);
852 static void
853 TOOLTIPS_TrackShow (TOOLTIPS_INFO *infoPtr)
855 TOOLTIPS_Show(infoPtr, TRUE);
859 static void
860 TOOLTIPS_TrackHide (const TOOLTIPS_INFO *infoPtr)
862 TTTOOL_INFO *toolPtr;
863 NMHDR hdr;
865 TRACE("hide tracking tooltip %d\n", infoPtr->nTrackTool);
867 if (infoPtr->nTrackTool == -1)
868 return;
870 toolPtr = &infoPtr->tools[infoPtr->nTrackTool];
872 hdr.hwndFrom = infoPtr->hwndSelf;
873 hdr.idFrom = toolPtr->uId;
874 hdr.code = TTN_POP;
875 SendMessageW (toolPtr->hwnd, WM_NOTIFY, toolPtr->uId, (LPARAM)&hdr);
877 SetWindowPos (infoPtr->hwndSelf, HWND_TOP, 0, 0, 0, 0,
878 SWP_NOZORDER | SWP_HIDEWINDOW | SWP_NOACTIVATE);
882 static INT
883 TOOLTIPS_GetToolFromInfoA (const TOOLTIPS_INFO *infoPtr, const TTTOOLINFOA *lpToolInfo)
885 TTTOOL_INFO *toolPtr;
886 UINT nTool;
888 for (nTool = 0; nTool < infoPtr->uNumTools; nTool++) {
889 toolPtr = &infoPtr->tools[nTool];
891 if (!(toolPtr->uFlags & TTF_IDISHWND) &&
892 (lpToolInfo->hwnd == toolPtr->hwnd) &&
893 (lpToolInfo->uId == toolPtr->uId))
894 return nTool;
897 for (nTool = 0; nTool < infoPtr->uNumTools; nTool++) {
898 toolPtr = &infoPtr->tools[nTool];
900 if ((toolPtr->uFlags & TTF_IDISHWND) &&
901 (lpToolInfo->uId == toolPtr->uId))
902 return nTool;
905 return -1;
909 static INT
910 TOOLTIPS_GetToolFromInfoW (const TOOLTIPS_INFO *infoPtr, const TTTOOLINFOW *lpToolInfo)
912 TTTOOL_INFO *toolPtr;
913 UINT nTool;
915 for (nTool = 0; nTool < infoPtr->uNumTools; nTool++) {
916 toolPtr = &infoPtr->tools[nTool];
918 if (!(toolPtr->uFlags & TTF_IDISHWND) &&
919 (lpToolInfo->hwnd == toolPtr->hwnd) &&
920 (lpToolInfo->uId == toolPtr->uId))
921 return nTool;
924 for (nTool = 0; nTool < infoPtr->uNumTools; nTool++) {
925 toolPtr = &infoPtr->tools[nTool];
927 if ((toolPtr->uFlags & TTF_IDISHWND) &&
928 (lpToolInfo->uId == toolPtr->uId))
929 return nTool;
932 return -1;
936 static INT
937 TOOLTIPS_GetToolFromPoint (const TOOLTIPS_INFO *infoPtr, HWND hwnd, const POINT *lpPt)
939 TTTOOL_INFO *toolPtr;
940 UINT nTool;
942 for (nTool = 0; nTool < infoPtr->uNumTools; nTool++) {
943 toolPtr = &infoPtr->tools[nTool];
945 if (!(toolPtr->uFlags & TTF_IDISHWND)) {
946 if (hwnd != toolPtr->hwnd)
947 continue;
948 if (!PtInRect (&toolPtr->rect, *lpPt))
949 continue;
950 return nTool;
954 for (nTool = 0; nTool < infoPtr->uNumTools; nTool++) {
955 toolPtr = &infoPtr->tools[nTool];
957 if (toolPtr->uFlags & TTF_IDISHWND) {
958 if ((HWND)toolPtr->uId == hwnd)
959 return nTool;
963 return -1;
967 static BOOL
968 TOOLTIPS_IsWindowActive (HWND hwnd)
970 HWND hwndActive = GetActiveWindow ();
971 if (!hwndActive)
972 return FALSE;
973 if (hwndActive == hwnd)
974 return TRUE;
975 return IsChild (hwndActive, hwnd);
979 static INT
980 TOOLTIPS_CheckTool (const TOOLTIPS_INFO *infoPtr, BOOL bShowTest)
982 POINT pt;
983 HWND hwndTool;
984 INT nTool;
986 GetCursorPos (&pt);
987 hwndTool = (HWND)SendMessageW (infoPtr->hwndSelf, TTM_WINDOWFROMPOINT, 0, (LPARAM)&pt);
988 if (hwndTool == 0)
989 return -1;
991 ScreenToClient (hwndTool, &pt);
992 nTool = TOOLTIPS_GetToolFromPoint (infoPtr, hwndTool, &pt);
993 if (nTool == -1)
994 return -1;
996 if (!(GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE) & TTS_ALWAYSTIP) && bShowTest) {
997 if (!TOOLTIPS_IsWindowActive (GetWindow (infoPtr->hwndSelf, GW_OWNER)))
998 return -1;
1001 TRACE("tool %d\n", nTool);
1003 return nTool;
1007 static LRESULT
1008 TOOLTIPS_Activate (TOOLTIPS_INFO *infoPtr, WPARAM wParam)
1010 infoPtr->bActive = (BOOL)wParam;
1012 if (infoPtr->bActive)
1013 TRACE("activate!\n");
1015 if (!(infoPtr->bActive) && (infoPtr->nCurrentTool != -1))
1016 TOOLTIPS_Hide (infoPtr);
1018 return 0;
1022 static LRESULT
1023 TOOLTIPS_AddToolA (TOOLTIPS_INFO *infoPtr, LPARAM lParam)
1025 LPTTTOOLINFOA lpToolInfo = (LPTTTOOLINFOA)lParam;
1026 TTTOOL_INFO *toolPtr;
1027 INT nResult;
1029 if (lpToolInfo == NULL)
1030 return FALSE;
1031 if (lpToolInfo->cbSize < TTTOOLINFOA_V1_SIZE)
1032 return FALSE;
1034 TRACE("add tool (%p) %p %ld%s!\n",
1035 infoPtr->hwndSelf, lpToolInfo->hwnd, lpToolInfo->uId,
1036 (lpToolInfo->uFlags & TTF_IDISHWND) ? " TTF_IDISHWND" : "");
1038 if (infoPtr->uNumTools == 0) {
1039 infoPtr->tools = Alloc (sizeof(TTTOOL_INFO));
1040 toolPtr = infoPtr->tools;
1042 else {
1043 TTTOOL_INFO *oldTools = infoPtr->tools;
1044 infoPtr->tools =
1045 Alloc (sizeof(TTTOOL_INFO) * (infoPtr->uNumTools + 1));
1046 memcpy (infoPtr->tools, oldTools,
1047 infoPtr->uNumTools * sizeof(TTTOOL_INFO));
1048 Free (oldTools);
1049 toolPtr = &infoPtr->tools[infoPtr->uNumTools];
1052 infoPtr->uNumTools++;
1054 /* copy tool data */
1055 toolPtr->uFlags = lpToolInfo->uFlags;
1056 toolPtr->hwnd = lpToolInfo->hwnd;
1057 toolPtr->uId = lpToolInfo->uId;
1058 toolPtr->rect = lpToolInfo->rect;
1059 toolPtr->hinst = lpToolInfo->hinst;
1061 if (IS_INTRESOURCE(lpToolInfo->lpszText)) {
1062 TRACE("add string id %x!\n", LOWORD(lpToolInfo->lpszText));
1063 toolPtr->lpszText = (LPWSTR)lpToolInfo->lpszText;
1065 else if (lpToolInfo->lpszText) {
1066 if (lpToolInfo->lpszText == LPSTR_TEXTCALLBACKA) {
1067 TRACE("add CALLBACK!\n");
1068 toolPtr->lpszText = LPSTR_TEXTCALLBACKW;
1070 else {
1071 INT len = MultiByteToWideChar(CP_ACP, 0, lpToolInfo->lpszText, -1,
1072 NULL, 0);
1073 TRACE("add text \"%s\"!\n", lpToolInfo->lpszText);
1074 toolPtr->lpszText = Alloc (len * sizeof(WCHAR));
1075 MultiByteToWideChar(CP_ACP, 0, lpToolInfo->lpszText, -1,
1076 toolPtr->lpszText, len);
1080 if (lpToolInfo->cbSize >= sizeof(TTTOOLINFOA))
1081 toolPtr->lParam = lpToolInfo->lParam;
1083 /* install subclassing hook */
1084 if (toolPtr->uFlags & TTF_SUBCLASS) {
1085 if (toolPtr->uFlags & TTF_IDISHWND) {
1086 SetWindowSubclass((HWND)toolPtr->uId, TOOLTIPS_SubclassProc, 1,
1087 (DWORD_PTR)infoPtr->hwndSelf);
1089 else {
1090 SetWindowSubclass(toolPtr->hwnd, TOOLTIPS_SubclassProc, 1,
1091 (DWORD_PTR)infoPtr->hwndSelf);
1093 TRACE("subclassing installed!\n");
1096 nResult = (INT) SendMessageW (toolPtr->hwnd, WM_NOTIFYFORMAT,
1097 (WPARAM)infoPtr->hwndSelf, (LPARAM)NF_QUERY);
1098 if (nResult == NFR_ANSI) {
1099 toolPtr->bNotifyUnicode = FALSE;
1100 TRACE(" -- WM_NOTIFYFORMAT returns: NFR_ANSI\n");
1101 } else if (nResult == NFR_UNICODE) {
1102 toolPtr->bNotifyUnicode = TRUE;
1103 TRACE(" -- WM_NOTIFYFORMAT returns: NFR_UNICODE\n");
1104 } else {
1105 TRACE (" -- WM_NOTIFYFORMAT returns: error!\n");
1108 return TRUE;
1112 static LRESULT
1113 TOOLTIPS_AddToolW (TOOLTIPS_INFO *infoPtr, LPARAM lParam)
1115 LPTTTOOLINFOW lpToolInfo = (LPTTTOOLINFOW)lParam;
1116 TTTOOL_INFO *toolPtr;
1117 INT nResult;
1119 if (lpToolInfo == NULL)
1120 return FALSE;
1121 if (lpToolInfo->cbSize < TTTOOLINFOW_V1_SIZE)
1122 return FALSE;
1124 TRACE("add tool (%p) %p %ld%s!\n",
1125 infoPtr->hwndSelf, lpToolInfo->hwnd, lpToolInfo->uId,
1126 (lpToolInfo->uFlags & TTF_IDISHWND) ? " TTF_IDISHWND" : "");
1128 if (infoPtr->uNumTools == 0) {
1129 infoPtr->tools = Alloc (sizeof(TTTOOL_INFO));
1130 toolPtr = infoPtr->tools;
1132 else {
1133 TTTOOL_INFO *oldTools = infoPtr->tools;
1134 infoPtr->tools =
1135 Alloc (sizeof(TTTOOL_INFO) * (infoPtr->uNumTools + 1));
1136 memcpy (infoPtr->tools, oldTools,
1137 infoPtr->uNumTools * sizeof(TTTOOL_INFO));
1138 Free (oldTools);
1139 toolPtr = &infoPtr->tools[infoPtr->uNumTools];
1142 infoPtr->uNumTools++;
1144 /* copy tool data */
1145 toolPtr->uFlags = lpToolInfo->uFlags;
1146 toolPtr->hwnd = lpToolInfo->hwnd;
1147 toolPtr->uId = lpToolInfo->uId;
1148 toolPtr->rect = lpToolInfo->rect;
1149 toolPtr->hinst = lpToolInfo->hinst;
1151 if (IS_INTRESOURCE(lpToolInfo->lpszText)) {
1152 TRACE("add string id %x\n", LOWORD(lpToolInfo->lpszText));
1153 toolPtr->lpszText = lpToolInfo->lpszText;
1155 else if (lpToolInfo->lpszText) {
1156 if (lpToolInfo->lpszText == LPSTR_TEXTCALLBACKW) {
1157 TRACE("add CALLBACK!\n");
1158 toolPtr->lpszText = LPSTR_TEXTCALLBACKW;
1160 else {
1161 INT len = lstrlenW (lpToolInfo->lpszText);
1162 TRACE("add text %s!\n",
1163 debugstr_w(lpToolInfo->lpszText));
1164 toolPtr->lpszText = Alloc ((len + 1)*sizeof(WCHAR));
1165 strcpyW (toolPtr->lpszText, lpToolInfo->lpszText);
1169 if (lpToolInfo->cbSize >= sizeof(TTTOOLINFOW))
1170 toolPtr->lParam = lpToolInfo->lParam;
1172 /* install subclassing hook */
1173 if (toolPtr->uFlags & TTF_SUBCLASS) {
1174 if (toolPtr->uFlags & TTF_IDISHWND) {
1175 SetWindowSubclass((HWND)toolPtr->uId, TOOLTIPS_SubclassProc, 1,
1176 (DWORD_PTR)infoPtr->hwndSelf);
1178 else {
1179 SetWindowSubclass(toolPtr->hwnd, TOOLTIPS_SubclassProc, 1,
1180 (DWORD_PTR)infoPtr->hwndSelf);
1182 TRACE("subclassing installed!\n");
1185 nResult = (INT) SendMessageW (toolPtr->hwnd, WM_NOTIFYFORMAT,
1186 (WPARAM)infoPtr->hwndSelf, (LPARAM)NF_QUERY);
1187 if (nResult == NFR_ANSI) {
1188 toolPtr->bNotifyUnicode = FALSE;
1189 TRACE(" -- WM_NOTIFYFORMAT returns: NFR_ANSI\n");
1190 } else if (nResult == NFR_UNICODE) {
1191 toolPtr->bNotifyUnicode = TRUE;
1192 TRACE(" -- WM_NOTIFYFORMAT returns: NFR_UNICODE\n");
1193 } else {
1194 TRACE (" -- WM_NOTIFYFORMAT returns: error!\n");
1197 return TRUE;
1201 static void
1202 TOOLTIPS_DelToolCommon (TOOLTIPS_INFO *infoPtr, INT nTool)
1204 TTTOOL_INFO *toolPtr;
1206 TRACE("tool %d\n", nTool);
1208 if (nTool == -1)
1209 return;
1211 /* make sure the tooltip has disappeared before deleting it */
1212 TOOLTIPS_Hide(infoPtr);
1214 /* delete text string */
1215 toolPtr = &infoPtr->tools[nTool];
1216 if (toolPtr->lpszText) {
1217 if ( (toolPtr->lpszText != LPSTR_TEXTCALLBACKW) &&
1218 !IS_INTRESOURCE(toolPtr->lpszText) )
1219 Free (toolPtr->lpszText);
1222 /* remove subclassing */
1223 if (toolPtr->uFlags & TTF_SUBCLASS) {
1224 if (toolPtr->uFlags & TTF_IDISHWND) {
1225 RemoveWindowSubclass((HWND)toolPtr->uId, TOOLTIPS_SubclassProc, 1);
1227 else {
1228 RemoveWindowSubclass(toolPtr->hwnd, TOOLTIPS_SubclassProc, 1);
1232 /* delete tool from tool list */
1233 if (infoPtr->uNumTools == 1) {
1234 Free (infoPtr->tools);
1235 infoPtr->tools = NULL;
1237 else {
1238 TTTOOL_INFO *oldTools = infoPtr->tools;
1239 infoPtr->tools =
1240 Alloc (sizeof(TTTOOL_INFO) * (infoPtr->uNumTools - 1));
1242 if (nTool > 0)
1243 memcpy (&infoPtr->tools[0], &oldTools[0],
1244 nTool * sizeof(TTTOOL_INFO));
1246 if (nTool < infoPtr->uNumTools - 1)
1247 memcpy (&infoPtr->tools[nTool], &oldTools[nTool + 1],
1248 (infoPtr->uNumTools - nTool - 1) * sizeof(TTTOOL_INFO));
1250 Free (oldTools);
1253 /* update any indices affected by delete */
1255 /* destroying tool that mouse was on on last relayed mouse move */
1256 if (infoPtr->nTool == nTool)
1257 /* -1 means no current tool (0 means first tool) */
1258 infoPtr->nTool = -1;
1259 else if (infoPtr->nTool > nTool)
1260 infoPtr->nTool--;
1262 if (infoPtr->nTrackTool == nTool)
1263 /* -1 means no current tool (0 means first tool) */
1264 infoPtr->nTrackTool = -1;
1265 else if (infoPtr->nTrackTool > nTool)
1266 infoPtr->nTrackTool--;
1268 if (infoPtr->nCurrentTool == nTool)
1269 /* -1 means no current tool (0 means first tool) */
1270 infoPtr->nCurrentTool = -1;
1271 else if (infoPtr->nCurrentTool > nTool)
1272 infoPtr->nCurrentTool--;
1274 infoPtr->uNumTools--;
1277 static LRESULT
1278 TOOLTIPS_DelToolA (TOOLTIPS_INFO *infoPtr, LPARAM lParam)
1280 LPTTTOOLINFOA lpToolInfo = (LPTTTOOLINFOA)lParam;
1281 INT nTool;
1283 if (lpToolInfo == NULL)
1284 return 0;
1285 if (lpToolInfo->cbSize < TTTOOLINFOA_V1_SIZE)
1286 return 0;
1287 if (infoPtr->uNumTools == 0)
1288 return 0;
1290 nTool = TOOLTIPS_GetToolFromInfoA (infoPtr, lpToolInfo);
1292 TOOLTIPS_DelToolCommon (infoPtr, nTool);
1294 return 0;
1298 static LRESULT
1299 TOOLTIPS_DelToolW (TOOLTIPS_INFO *infoPtr, LPARAM lParam)
1301 LPTTTOOLINFOW lpToolInfo = (LPTTTOOLINFOW)lParam;
1302 INT nTool;
1304 if (lpToolInfo == NULL)
1305 return 0;
1306 if (lpToolInfo->cbSize < TTTOOLINFOW_V1_SIZE)
1307 return 0;
1308 if (infoPtr->uNumTools == 0)
1309 return 0;
1311 nTool = TOOLTIPS_GetToolFromInfoW (infoPtr, lpToolInfo);
1313 TOOLTIPS_DelToolCommon (infoPtr, nTool);
1315 return 0;
1319 static LRESULT
1320 TOOLTIPS_EnumToolsA (const TOOLTIPS_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
1322 UINT uIndex = (UINT)wParam;
1323 LPTTTOOLINFOA lpToolInfo = (LPTTTOOLINFOA)lParam;
1324 TTTOOL_INFO *toolPtr;
1326 if (lpToolInfo == NULL)
1327 return FALSE;
1328 if (lpToolInfo->cbSize < TTTOOLINFOA_V1_SIZE)
1329 return FALSE;
1330 if (uIndex >= infoPtr->uNumTools)
1331 return FALSE;
1333 TRACE("index=%u\n", uIndex);
1335 toolPtr = &infoPtr->tools[uIndex];
1337 /* copy tool data */
1338 lpToolInfo->uFlags = toolPtr->uFlags;
1339 lpToolInfo->hwnd = toolPtr->hwnd;
1340 lpToolInfo->uId = toolPtr->uId;
1341 lpToolInfo->rect = toolPtr->rect;
1342 lpToolInfo->hinst = toolPtr->hinst;
1343 /* lpToolInfo->lpszText = toolPtr->lpszText; */
1344 lpToolInfo->lpszText = NULL; /* FIXME */
1346 if (lpToolInfo->cbSize >= sizeof(TTTOOLINFOA))
1347 lpToolInfo->lParam = toolPtr->lParam;
1349 return TRUE;
1353 static LRESULT
1354 TOOLTIPS_EnumToolsW (const TOOLTIPS_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
1356 UINT uIndex = (UINT)wParam;
1357 LPTTTOOLINFOW lpToolInfo = (LPTTTOOLINFOW)lParam;
1358 TTTOOL_INFO *toolPtr;
1360 if (lpToolInfo == NULL)
1361 return FALSE;
1362 if (lpToolInfo->cbSize < TTTOOLINFOW_V1_SIZE)
1363 return FALSE;
1364 if (uIndex >= infoPtr->uNumTools)
1365 return FALSE;
1367 TRACE("index=%u\n", uIndex);
1369 toolPtr = &infoPtr->tools[uIndex];
1371 /* copy tool data */
1372 lpToolInfo->uFlags = toolPtr->uFlags;
1373 lpToolInfo->hwnd = toolPtr->hwnd;
1374 lpToolInfo->uId = toolPtr->uId;
1375 lpToolInfo->rect = toolPtr->rect;
1376 lpToolInfo->hinst = toolPtr->hinst;
1377 /* lpToolInfo->lpszText = toolPtr->lpszText; */
1378 lpToolInfo->lpszText = NULL; /* FIXME */
1380 if (lpToolInfo->cbSize >= sizeof(TTTOOLINFOW))
1381 lpToolInfo->lParam = toolPtr->lParam;
1383 return TRUE;
1386 static LRESULT
1387 TOOLTIPS_GetBubbleSize (const TOOLTIPS_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
1389 LPTTTOOLINFOW lpToolInfo = (LPTTTOOLINFOW)lParam;
1390 INT nTool;
1391 SIZE size;
1393 if (lpToolInfo == NULL)
1394 return FALSE;
1395 if (lpToolInfo->cbSize < TTTOOLINFOW_V1_SIZE)
1396 return FALSE;
1398 nTool = TOOLTIPS_GetToolFromInfoW (infoPtr, lpToolInfo);
1399 if (nTool == -1) return 0;
1401 TRACE("tool %d\n", nTool);
1403 TOOLTIPS_CalcTipSize (infoPtr, &size);
1404 TRACE("size %d x %d\n", size.cx, size.cy);
1406 return MAKELRESULT(size.cx, size.cy);
1409 static LRESULT
1410 TOOLTIPS_GetCurrentToolA (const TOOLTIPS_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
1412 LPTTTOOLINFOA lpToolInfo = (LPTTTOOLINFOA)lParam;
1413 TTTOOL_INFO *toolPtr;
1415 if (lpToolInfo) {
1416 if (lpToolInfo->cbSize < TTTOOLINFOA_V1_SIZE)
1417 return FALSE;
1419 if (infoPtr->nCurrentTool > -1) {
1420 toolPtr = &infoPtr->tools[infoPtr->nCurrentTool];
1422 /* copy tool data */
1423 lpToolInfo->uFlags = toolPtr->uFlags;
1424 lpToolInfo->rect = toolPtr->rect;
1425 lpToolInfo->hinst = toolPtr->hinst;
1426 /* lpToolInfo->lpszText = toolPtr->lpszText; */
1427 lpToolInfo->lpszText = NULL; /* FIXME */
1429 if (lpToolInfo->cbSize >= sizeof(TTTOOLINFOA))
1430 lpToolInfo->lParam = toolPtr->lParam;
1432 return TRUE;
1434 else
1435 return FALSE;
1437 else
1438 return (infoPtr->nCurrentTool != -1);
1442 static LRESULT
1443 TOOLTIPS_GetCurrentToolW (const TOOLTIPS_INFO *infoPtr, LPARAM lParam)
1445 LPTTTOOLINFOW lpToolInfo = (LPTTTOOLINFOW)lParam;
1446 TTTOOL_INFO *toolPtr;
1448 if (lpToolInfo) {
1449 if (lpToolInfo->cbSize < TTTOOLINFOW_V1_SIZE)
1450 return FALSE;
1452 if (infoPtr->nCurrentTool > -1) {
1453 toolPtr = &infoPtr->tools[infoPtr->nCurrentTool];
1455 /* copy tool data */
1456 lpToolInfo->uFlags = toolPtr->uFlags;
1457 lpToolInfo->rect = toolPtr->rect;
1458 lpToolInfo->hinst = toolPtr->hinst;
1459 /* lpToolInfo->lpszText = toolPtr->lpszText; */
1460 lpToolInfo->lpszText = NULL; /* FIXME */
1462 if (lpToolInfo->cbSize >= sizeof(TTTOOLINFOW))
1463 lpToolInfo->lParam = toolPtr->lParam;
1465 return TRUE;
1467 else
1468 return FALSE;
1470 else
1471 return (infoPtr->nCurrentTool != -1);
1475 static LRESULT
1476 TOOLTIPS_GetDelayTime (const TOOLTIPS_INFO *infoPtr, WPARAM wParam)
1478 switch (wParam) {
1479 case TTDT_RESHOW:
1480 return infoPtr->nReshowTime;
1482 case TTDT_AUTOPOP:
1483 return infoPtr->nAutoPopTime;
1485 case TTDT_INITIAL:
1486 case TTDT_AUTOMATIC: /* Apparently TTDT_AUTOMATIC returns TTDT_INITIAL */
1487 return infoPtr->nInitialTime;
1489 default:
1490 WARN("Invalid wParam %lx\n", wParam);
1491 break;
1494 return -1;
1498 static LRESULT
1499 TOOLTIPS_GetMargin (const TOOLTIPS_INFO *infoPtr, LPARAM lParam)
1501 LPRECT lpRect = (LPRECT)lParam;
1503 lpRect->left = infoPtr->rcMargin.left;
1504 lpRect->right = infoPtr->rcMargin.right;
1505 lpRect->bottom = infoPtr->rcMargin.bottom;
1506 lpRect->top = infoPtr->rcMargin.top;
1508 return 0;
1512 static inline LRESULT
1513 TOOLTIPS_GetMaxTipWidth (const TOOLTIPS_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
1515 return infoPtr->nMaxTipWidth;
1519 static LRESULT
1520 TOOLTIPS_GetTextA (const TOOLTIPS_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
1522 LPTTTOOLINFOA lpToolInfo = (LPTTTOOLINFOA)lParam;
1523 INT nTool;
1525 if (lpToolInfo == NULL)
1526 return 0;
1527 if (lpToolInfo->cbSize < TTTOOLINFOA_V1_SIZE)
1528 return 0;
1530 nTool = TOOLTIPS_GetToolFromInfoA (infoPtr, lpToolInfo);
1531 if (nTool == -1) return 0;
1533 /* NB this API is broken, there is no way for the app to determine
1534 what size buffer it requires nor a way to specify how long the
1535 one it supplies is. We'll assume it's up to INFOTIPSIZE */
1537 WideCharToMultiByte(CP_ACP, 0, infoPtr->tools[nTool].lpszText, -1,
1538 lpToolInfo->lpszText, INFOTIPSIZE, NULL, NULL);
1540 return 0;
1544 static LRESULT
1545 TOOLTIPS_GetTextW (const TOOLTIPS_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
1547 LPTTTOOLINFOW lpToolInfo = (LPTTTOOLINFOW)lParam;
1548 INT nTool;
1550 if (lpToolInfo == NULL)
1551 return 0;
1552 if (lpToolInfo->cbSize < TTTOOLINFOW_V1_SIZE)
1553 return 0;
1555 nTool = TOOLTIPS_GetToolFromInfoW (infoPtr, lpToolInfo);
1556 if (nTool == -1) return 0;
1558 if (infoPtr->tools[nTool].lpszText == NULL)
1559 return 0;
1561 strcpyW (lpToolInfo->lpszText, infoPtr->tools[nTool].lpszText);
1563 return 0;
1567 static inline LRESULT
1568 TOOLTIPS_GetTipBkColor (const TOOLTIPS_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
1570 return infoPtr->clrBk;
1574 static inline LRESULT
1575 TOOLTIPS_GetTipTextColor (const TOOLTIPS_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
1577 return infoPtr->clrText;
1581 static inline LRESULT
1582 TOOLTIPS_GetToolCount (const TOOLTIPS_INFO *infoPtr)
1584 return infoPtr->uNumTools;
1588 static LRESULT
1589 TOOLTIPS_GetToolInfoA (const TOOLTIPS_INFO *infoPtr, LPARAM lParam)
1591 LPTTTOOLINFOA lpToolInfo = (LPTTTOOLINFOA)lParam;
1592 TTTOOL_INFO *toolPtr;
1593 INT nTool;
1595 if (lpToolInfo == NULL)
1596 return FALSE;
1597 if (lpToolInfo->cbSize < TTTOOLINFOA_V1_SIZE)
1598 return FALSE;
1599 if (infoPtr->uNumTools == 0)
1600 return FALSE;
1602 nTool = TOOLTIPS_GetToolFromInfoA (infoPtr, lpToolInfo);
1603 if (nTool == -1)
1604 return FALSE;
1606 TRACE("tool %d\n", nTool);
1608 toolPtr = &infoPtr->tools[nTool];
1610 /* copy tool data */
1611 lpToolInfo->uFlags = toolPtr->uFlags;
1612 lpToolInfo->rect = toolPtr->rect;
1613 lpToolInfo->hinst = toolPtr->hinst;
1614 /* lpToolInfo->lpszText = toolPtr->lpszText; */
1615 lpToolInfo->lpszText = NULL; /* FIXME */
1617 if (lpToolInfo->cbSize >= sizeof(TTTOOLINFOA))
1618 lpToolInfo->lParam = toolPtr->lParam;
1620 return TRUE;
1624 static LRESULT
1625 TOOLTIPS_GetToolInfoW (const TOOLTIPS_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
1627 LPTTTOOLINFOW lpToolInfo = (LPTTTOOLINFOW)lParam;
1628 TTTOOL_INFO *toolPtr;
1629 INT nTool;
1631 if (lpToolInfo == NULL)
1632 return FALSE;
1633 if (lpToolInfo->cbSize < TTTOOLINFOW_V1_SIZE)
1634 return FALSE;
1635 if (infoPtr->uNumTools == 0)
1636 return FALSE;
1638 nTool = TOOLTIPS_GetToolFromInfoW (infoPtr, lpToolInfo);
1639 if (nTool == -1)
1640 return FALSE;
1642 TRACE("tool %d\n", nTool);
1644 toolPtr = &infoPtr->tools[nTool];
1646 /* copy tool data */
1647 lpToolInfo->uFlags = toolPtr->uFlags;
1648 lpToolInfo->rect = toolPtr->rect;
1649 lpToolInfo->hinst = toolPtr->hinst;
1650 /* lpToolInfo->lpszText = toolPtr->lpszText; */
1651 lpToolInfo->lpszText = NULL; /* FIXME */
1653 if (lpToolInfo->cbSize >= sizeof(TTTOOLINFOW))
1654 lpToolInfo->lParam = toolPtr->lParam;
1656 return TRUE;
1660 static LRESULT
1661 TOOLTIPS_HitTestA (const TOOLTIPS_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
1663 LPTTHITTESTINFOA lptthit = (LPTTHITTESTINFOA)lParam;
1664 TTTOOL_INFO *toolPtr;
1665 INT nTool;
1667 if (lptthit == 0)
1668 return FALSE;
1670 nTool = TOOLTIPS_GetToolFromPoint (infoPtr, lptthit->hwnd, &lptthit->pt);
1671 if (nTool == -1)
1672 return FALSE;
1674 TRACE("tool %d!\n", nTool);
1676 /* copy tool data */
1677 if (lptthit->ti.cbSize >= sizeof(TTTOOLINFOA)) {
1678 toolPtr = &infoPtr->tools[nTool];
1680 lptthit->ti.uFlags = toolPtr->uFlags;
1681 lptthit->ti.hwnd = toolPtr->hwnd;
1682 lptthit->ti.uId = toolPtr->uId;
1683 lptthit->ti.rect = toolPtr->rect;
1684 lptthit->ti.hinst = toolPtr->hinst;
1685 /* lptthit->ti.lpszText = toolPtr->lpszText; */
1686 lptthit->ti.lpszText = NULL; /* FIXME */
1687 lptthit->ti.lParam = toolPtr->lParam;
1690 return TRUE;
1694 static LRESULT
1695 TOOLTIPS_HitTestW (const TOOLTIPS_INFO *infoPtr, LPARAM lParam)
1697 LPTTHITTESTINFOW lptthit = (LPTTHITTESTINFOW)lParam;
1698 TTTOOL_INFO *toolPtr;
1699 INT nTool;
1701 if (lptthit == 0)
1702 return FALSE;
1704 nTool = TOOLTIPS_GetToolFromPoint (infoPtr, lptthit->hwnd, &lptthit->pt);
1705 if (nTool == -1)
1706 return FALSE;
1708 TRACE("tool %d!\n", nTool);
1710 /* copy tool data */
1711 if (lptthit->ti.cbSize >= sizeof(TTTOOLINFOW)) {
1712 toolPtr = &infoPtr->tools[nTool];
1714 lptthit->ti.uFlags = toolPtr->uFlags;
1715 lptthit->ti.hwnd = toolPtr->hwnd;
1716 lptthit->ti.uId = toolPtr->uId;
1717 lptthit->ti.rect = toolPtr->rect;
1718 lptthit->ti.hinst = toolPtr->hinst;
1719 /* lptthit->ti.lpszText = toolPtr->lpszText; */
1720 lptthit->ti.lpszText = NULL; /* FIXME */
1721 lptthit->ti.lParam = toolPtr->lParam;
1724 return TRUE;
1728 static LRESULT
1729 TOOLTIPS_NewToolRectA (TOOLTIPS_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
1731 LPTTTOOLINFOA lpti = (LPTTTOOLINFOA)lParam;
1732 INT nTool;
1734 if (lpti == NULL)
1735 return 0;
1736 if (lpti->cbSize < TTTOOLINFOA_V1_SIZE)
1737 return FALSE;
1739 nTool = TOOLTIPS_GetToolFromInfoA (infoPtr, lpti);
1741 TRACE("nTool = %d, rect = %s\n", nTool, wine_dbgstr_rect(&lpti->rect));
1743 if (nTool == -1) return 0;
1745 infoPtr->tools[nTool].rect = lpti->rect;
1747 return 0;
1751 static LRESULT
1752 TOOLTIPS_NewToolRectW (TOOLTIPS_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
1754 LPTTTOOLINFOW lpti = (LPTTTOOLINFOW)lParam;
1755 INT nTool;
1757 if (lpti == NULL)
1758 return 0;
1759 if (lpti->cbSize < TTTOOLINFOW_V1_SIZE)
1760 return FALSE;
1762 nTool = TOOLTIPS_GetToolFromInfoW (infoPtr, lpti);
1764 TRACE("nTool = %d, rect = %s\n", nTool, wine_dbgstr_rect(&lpti->rect));
1766 if (nTool == -1) return 0;
1768 infoPtr->tools[nTool].rect = lpti->rect;
1770 return 0;
1774 static inline LRESULT
1775 TOOLTIPS_Pop (TOOLTIPS_INFO *infoPtr)
1777 TOOLTIPS_Hide (infoPtr);
1779 return 0;
1783 static LRESULT
1784 TOOLTIPS_RelayEvent (TOOLTIPS_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
1786 LPMSG lpMsg = (LPMSG)lParam;
1787 POINT pt;
1788 INT nOldTool;
1790 if (lParam == 0) {
1791 ERR("lpMsg == NULL!\n");
1792 return 0;
1795 switch (lpMsg->message) {
1796 case WM_LBUTTONDOWN:
1797 case WM_LBUTTONUP:
1798 case WM_MBUTTONDOWN:
1799 case WM_MBUTTONUP:
1800 case WM_RBUTTONDOWN:
1801 case WM_RBUTTONUP:
1802 TOOLTIPS_Hide (infoPtr);
1803 break;
1805 case WM_MOUSEMOVE:
1806 pt.x = (short)LOWORD(lpMsg->lParam);
1807 pt.y = (short)HIWORD(lpMsg->lParam);
1808 nOldTool = infoPtr->nTool;
1809 infoPtr->nTool = TOOLTIPS_GetToolFromPoint(infoPtr, lpMsg->hwnd,
1810 &pt);
1811 TRACE("tool (%p) %d %d %d\n", infoPtr->hwndSelf, nOldTool,
1812 infoPtr->nTool, infoPtr->nCurrentTool);
1813 TRACE("WM_MOUSEMOVE (%p %d %d)\n", infoPtr->hwndSelf, pt.x, pt.y);
1815 if (infoPtr->nTool != nOldTool) {
1816 if(infoPtr->nTool == -1) { /* Moved out of all tools */
1817 TOOLTIPS_Hide(infoPtr);
1818 KillTimer(infoPtr->hwndSelf, ID_TIMERLEAVE);
1819 } else if (nOldTool == -1) { /* Moved from outside */
1820 if(infoPtr->bActive) {
1821 SetTimer(infoPtr->hwndSelf, ID_TIMERSHOW, infoPtr->nInitialTime, 0);
1822 TRACE("timer 1 started!\n");
1824 } else { /* Moved from one to another */
1825 TOOLTIPS_Hide (infoPtr);
1826 KillTimer(infoPtr->hwndSelf, ID_TIMERLEAVE);
1827 if(infoPtr->bActive) {
1828 SetTimer (infoPtr->hwndSelf, ID_TIMERSHOW, infoPtr->nReshowTime, 0);
1829 TRACE("timer 1 started!\n");
1832 } else if(infoPtr->nCurrentTool != -1) { /* restart autopop */
1833 KillTimer(infoPtr->hwndSelf, ID_TIMERPOP);
1834 SetTimer(infoPtr->hwndSelf, ID_TIMERPOP, infoPtr->nAutoPopTime, 0);
1835 TRACE("timer 2 restarted\n");
1836 } else if(infoPtr->nTool != -1 && infoPtr->bActive) {
1837 /* previous show attempt didn't result in tooltip so try again */
1838 SetTimer(infoPtr->hwndSelf, ID_TIMERSHOW, infoPtr->nInitialTime, 0);
1839 TRACE("timer 1 started!\n");
1841 break;
1844 return 0;
1848 static LRESULT
1849 TOOLTIPS_SetDelayTime (TOOLTIPS_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
1851 INT nTime = (INT)LOWORD(lParam);
1853 switch (wParam) {
1854 case TTDT_AUTOMATIC:
1855 if (nTime <= 0)
1856 nTime = GetDoubleClickTime();
1857 infoPtr->nReshowTime = nTime / 5;
1858 infoPtr->nAutoPopTime = nTime * 10;
1859 infoPtr->nInitialTime = nTime;
1860 break;
1862 case TTDT_RESHOW:
1863 if(nTime < 0)
1864 nTime = GetDoubleClickTime() / 5;
1865 infoPtr->nReshowTime = nTime;
1866 break;
1868 case TTDT_AUTOPOP:
1869 if(nTime < 0)
1870 nTime = GetDoubleClickTime() * 10;
1871 infoPtr->nAutoPopTime = nTime;
1872 break;
1874 case TTDT_INITIAL:
1875 if(nTime < 0)
1876 nTime = GetDoubleClickTime();
1877 infoPtr->nInitialTime = nTime;
1878 break;
1880 default:
1881 WARN("Invalid wParam %lx\n", wParam);
1882 break;
1885 return 0;
1889 static LRESULT
1890 TOOLTIPS_SetMargin (TOOLTIPS_INFO *infoPtr, LPARAM lParam)
1892 LPRECT lpRect = (LPRECT)lParam;
1894 infoPtr->rcMargin.left = lpRect->left;
1895 infoPtr->rcMargin.right = lpRect->right;
1896 infoPtr->rcMargin.bottom = lpRect->bottom;
1897 infoPtr->rcMargin.top = lpRect->top;
1899 return 0;
1903 static inline LRESULT
1904 TOOLTIPS_SetMaxTipWidth (TOOLTIPS_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
1906 INT nTemp = infoPtr->nMaxTipWidth;
1908 infoPtr->nMaxTipWidth = (INT)lParam;
1910 return nTemp;
1914 static inline LRESULT
1915 TOOLTIPS_SetTipBkColor (TOOLTIPS_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
1917 infoPtr->clrBk = (COLORREF)wParam;
1919 return 0;
1923 static inline LRESULT
1924 TOOLTIPS_SetTipTextColor (TOOLTIPS_INFO *infoPtr, WPARAM wParam)
1926 infoPtr->clrText = (COLORREF)wParam;
1928 return 0;
1932 static LRESULT
1933 TOOLTIPS_SetTitleA (TOOLTIPS_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
1935 LPCSTR pszTitle = (LPCSTR)lParam;
1936 UINT_PTR uTitleIcon = wParam;
1937 UINT size;
1939 TRACE("hwnd = %p, title = %s, icon = %p\n", infoPtr->hwndSelf, debugstr_a(pszTitle),
1940 (void*)uTitleIcon);
1942 Free(infoPtr->pszTitle);
1944 if (pszTitle)
1946 size = sizeof(WCHAR)*MultiByteToWideChar(CP_ACP, 0, pszTitle, -1, NULL, 0);
1947 infoPtr->pszTitle = Alloc(size);
1948 if (!infoPtr->pszTitle)
1949 return FALSE;
1950 MultiByteToWideChar(CP_ACP, 0, pszTitle, -1, infoPtr->pszTitle, size/sizeof(WCHAR));
1952 else
1953 infoPtr->pszTitle = NULL;
1955 if (uTitleIcon <= TTI_ERROR)
1956 infoPtr->hTitleIcon = hTooltipIcons[uTitleIcon];
1957 else
1958 infoPtr->hTitleIcon = CopyIcon((HICON)wParam);
1960 return TRUE;
1964 static LRESULT
1965 TOOLTIPS_SetTitleW (TOOLTIPS_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
1967 LPCWSTR pszTitle = (LPCWSTR)lParam;
1968 UINT_PTR uTitleIcon = wParam;
1969 UINT size;
1971 TRACE("hwnd = %p, title = %s, icon = %p\n", infoPtr->hwndSelf, debugstr_w(pszTitle),
1972 (void*)uTitleIcon);
1974 Free(infoPtr->pszTitle);
1976 if (pszTitle)
1978 size = (strlenW(pszTitle)+1)*sizeof(WCHAR);
1979 infoPtr->pszTitle = Alloc(size);
1980 if (!infoPtr->pszTitle)
1981 return FALSE;
1982 memcpy(infoPtr->pszTitle, pszTitle, size);
1984 else
1985 infoPtr->pszTitle = NULL;
1987 if (uTitleIcon <= TTI_ERROR)
1988 infoPtr->hTitleIcon = hTooltipIcons[uTitleIcon];
1989 else
1990 infoPtr->hTitleIcon = CopyIcon((HICON)wParam);
1992 TRACE("icon = %p\n", infoPtr->hTitleIcon);
1994 return TRUE;
1998 static LRESULT
1999 TOOLTIPS_SetToolInfoA (TOOLTIPS_INFO *infoPtr, LPARAM lParam)
2001 LPTTTOOLINFOA lpToolInfo = (LPTTTOOLINFOA)lParam;
2002 TTTOOL_INFO *toolPtr;
2003 INT nTool;
2005 if (lpToolInfo == NULL)
2006 return 0;
2007 if (lpToolInfo->cbSize < TTTOOLINFOA_V1_SIZE)
2008 return 0;
2010 nTool = TOOLTIPS_GetToolFromInfoA (infoPtr, lpToolInfo);
2011 if (nTool == -1) return 0;
2013 TRACE("tool %d\n", nTool);
2015 toolPtr = &infoPtr->tools[nTool];
2017 /* copy tool data */
2018 toolPtr->uFlags = lpToolInfo->uFlags;
2019 toolPtr->hwnd = lpToolInfo->hwnd;
2020 toolPtr->uId = lpToolInfo->uId;
2021 toolPtr->rect = lpToolInfo->rect;
2022 toolPtr->hinst = lpToolInfo->hinst;
2024 if (IS_INTRESOURCE(lpToolInfo->lpszText)) {
2025 TRACE("set string id %x\n", LOWORD(lpToolInfo->lpszText));
2026 toolPtr->lpszText = (LPWSTR)lpToolInfo->lpszText;
2028 else if (lpToolInfo->lpszText) {
2029 if (lpToolInfo->lpszText == LPSTR_TEXTCALLBACKA)
2030 toolPtr->lpszText = LPSTR_TEXTCALLBACKW;
2031 else {
2032 if ( (toolPtr->lpszText) &&
2033 !IS_INTRESOURCE(toolPtr->lpszText) ) {
2034 if( toolPtr->lpszText != LPSTR_TEXTCALLBACKW)
2035 Free (toolPtr->lpszText);
2036 toolPtr->lpszText = NULL;
2038 if (lpToolInfo->lpszText) {
2039 INT len = MultiByteToWideChar(CP_ACP, 0, lpToolInfo->lpszText,
2040 -1, NULL, 0);
2041 toolPtr->lpszText = Alloc (len * sizeof(WCHAR));
2042 MultiByteToWideChar(CP_ACP, 0, lpToolInfo->lpszText, -1,
2043 toolPtr->lpszText, len);
2048 if (lpToolInfo->cbSize >= sizeof(TTTOOLINFOA))
2049 toolPtr->lParam = lpToolInfo->lParam;
2051 return 0;
2055 static LRESULT
2056 TOOLTIPS_SetToolInfoW (TOOLTIPS_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
2058 LPTTTOOLINFOW lpToolInfo = (LPTTTOOLINFOW)lParam;
2059 TTTOOL_INFO *toolPtr;
2060 INT nTool;
2062 if (lpToolInfo == NULL)
2063 return 0;
2064 if (lpToolInfo->cbSize < TTTOOLINFOW_V1_SIZE)
2065 return 0;
2067 nTool = TOOLTIPS_GetToolFromInfoW (infoPtr, lpToolInfo);
2068 if (nTool == -1) return 0;
2070 TRACE("tool %d\n", nTool);
2072 toolPtr = &infoPtr->tools[nTool];
2074 /* copy tool data */
2075 toolPtr->uFlags = lpToolInfo->uFlags;
2076 toolPtr->hwnd = lpToolInfo->hwnd;
2077 toolPtr->uId = lpToolInfo->uId;
2078 toolPtr->rect = lpToolInfo->rect;
2079 toolPtr->hinst = lpToolInfo->hinst;
2081 if (IS_INTRESOURCE(lpToolInfo->lpszText)) {
2082 TRACE("set string id %x!\n", LOWORD(lpToolInfo->lpszText));
2083 toolPtr->lpszText = lpToolInfo->lpszText;
2085 else {
2086 if (lpToolInfo->lpszText == LPSTR_TEXTCALLBACKW)
2087 toolPtr->lpszText = LPSTR_TEXTCALLBACKW;
2088 else {
2089 if ( (toolPtr->lpszText) &&
2090 !IS_INTRESOURCE(toolPtr->lpszText) ) {
2091 if( toolPtr->lpszText != LPSTR_TEXTCALLBACKW)
2092 Free (toolPtr->lpszText);
2093 toolPtr->lpszText = NULL;
2095 if (lpToolInfo->lpszText) {
2096 INT len = lstrlenW (lpToolInfo->lpszText);
2097 toolPtr->lpszText = Alloc ((len+1)*sizeof(WCHAR));
2098 strcpyW (toolPtr->lpszText, lpToolInfo->lpszText);
2103 if (lpToolInfo->cbSize >= sizeof(TTTOOLINFOW))
2104 toolPtr->lParam = lpToolInfo->lParam;
2106 if (infoPtr->nCurrentTool == nTool)
2108 TOOLTIPS_GetTipText (infoPtr, infoPtr->nCurrentTool);
2110 if (infoPtr->szTipText[0] == 0)
2111 TOOLTIPS_Hide(infoPtr);
2112 else
2113 TOOLTIPS_Show (infoPtr, FALSE);
2116 return 0;
2120 static LRESULT
2121 TOOLTIPS_TrackActivate (TOOLTIPS_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
2123 if ((BOOL)wParam) {
2124 LPTTTOOLINFOA lpToolInfo = (LPTTTOOLINFOA)lParam;
2126 if (lpToolInfo == NULL)
2127 return 0;
2128 if (lpToolInfo->cbSize < TTTOOLINFOA_V1_SIZE)
2129 return FALSE;
2131 /* activate */
2132 infoPtr->nTrackTool = TOOLTIPS_GetToolFromInfoA (infoPtr, lpToolInfo);
2133 if (infoPtr->nTrackTool != -1) {
2134 TRACE("activated!\n");
2135 infoPtr->bTrackActive = TRUE;
2136 TOOLTIPS_TrackShow (infoPtr);
2139 else {
2140 /* deactivate */
2141 TOOLTIPS_TrackHide (infoPtr);
2143 infoPtr->bTrackActive = FALSE;
2144 infoPtr->nTrackTool = -1;
2146 TRACE("deactivated!\n");
2149 return 0;
2153 static LRESULT
2154 TOOLTIPS_TrackPosition (TOOLTIPS_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
2156 infoPtr->xTrackPos = (INT)LOWORD(lParam);
2157 infoPtr->yTrackPos = (INT)HIWORD(lParam);
2159 if (infoPtr->bTrackActive) {
2160 TRACE("[%d %d]\n",
2161 infoPtr->xTrackPos, infoPtr->yTrackPos);
2163 TOOLTIPS_TrackShow (infoPtr);
2166 return 0;
2170 static LRESULT
2171 TOOLTIPS_Update (TOOLTIPS_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
2173 if (infoPtr->nCurrentTool != -1)
2174 UpdateWindow (infoPtr->hwndSelf);
2176 return 0;
2180 static LRESULT
2181 TOOLTIPS_UpdateTipTextA (TOOLTIPS_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
2183 LPTTTOOLINFOA lpToolInfo = (LPTTTOOLINFOA)lParam;
2184 TTTOOL_INFO *toolPtr;
2185 INT nTool;
2187 if (lpToolInfo == NULL)
2188 return 0;
2189 if (lpToolInfo->cbSize < TTTOOLINFOA_V1_SIZE)
2190 return FALSE;
2192 nTool = TOOLTIPS_GetToolFromInfoA (infoPtr, lpToolInfo);
2193 if (nTool == -1) return 0;
2195 TRACE("tool %d\n", nTool);
2197 toolPtr = &infoPtr->tools[nTool];
2199 /* copy tool text */
2200 toolPtr->hinst = lpToolInfo->hinst;
2202 if (IS_INTRESOURCE(lpToolInfo->lpszText)){
2203 toolPtr->lpszText = (LPWSTR)lpToolInfo->lpszText;
2205 else if (lpToolInfo->lpszText) {
2206 if (lpToolInfo->lpszText == LPSTR_TEXTCALLBACKA)
2207 toolPtr->lpszText = LPSTR_TEXTCALLBACKW;
2208 else {
2209 if ( (toolPtr->lpszText) &&
2210 !IS_INTRESOURCE(toolPtr->lpszText) ) {
2211 if( toolPtr->lpszText != LPSTR_TEXTCALLBACKW)
2212 Free (toolPtr->lpszText);
2213 toolPtr->lpszText = NULL;
2215 if (lpToolInfo->lpszText) {
2216 INT len = MultiByteToWideChar(CP_ACP, 0, lpToolInfo->lpszText,
2217 -1, NULL, 0);
2218 toolPtr->lpszText = Alloc (len * sizeof(WCHAR));
2219 MultiByteToWideChar(CP_ACP, 0, lpToolInfo->lpszText, -1,
2220 toolPtr->lpszText, len);
2225 if(infoPtr->nCurrentTool == -1) return 0;
2226 /* force repaint */
2227 if (infoPtr->bActive)
2228 TOOLTIPS_Show (infoPtr, FALSE);
2229 else if (infoPtr->bTrackActive)
2230 TOOLTIPS_TrackShow (infoPtr);
2232 return 0;
2236 static LRESULT
2237 TOOLTIPS_UpdateTipTextW (TOOLTIPS_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
2239 LPTTTOOLINFOW lpToolInfo = (LPTTTOOLINFOW)lParam;
2240 TTTOOL_INFO *toolPtr;
2241 INT nTool;
2243 if (lpToolInfo == NULL)
2244 return 0;
2245 if (lpToolInfo->cbSize < TTTOOLINFOW_V1_SIZE)
2246 return FALSE;
2248 nTool = TOOLTIPS_GetToolFromInfoW (infoPtr, lpToolInfo);
2249 if (nTool == -1)
2250 return 0;
2252 TRACE("tool %d\n", nTool);
2254 toolPtr = &infoPtr->tools[nTool];
2256 /* copy tool text */
2257 toolPtr->hinst = lpToolInfo->hinst;
2259 if (IS_INTRESOURCE(lpToolInfo->lpszText)){
2260 toolPtr->lpszText = lpToolInfo->lpszText;
2262 else if (lpToolInfo->lpszText) {
2263 if (lpToolInfo->lpszText == LPSTR_TEXTCALLBACKW)
2264 toolPtr->lpszText = LPSTR_TEXTCALLBACKW;
2265 else {
2266 if ( (toolPtr->lpszText) &&
2267 !IS_INTRESOURCE(toolPtr->lpszText) ) {
2268 if( toolPtr->lpszText != LPSTR_TEXTCALLBACKW)
2269 Free (toolPtr->lpszText);
2270 toolPtr->lpszText = NULL;
2272 if (lpToolInfo->lpszText) {
2273 INT len = lstrlenW (lpToolInfo->lpszText);
2274 toolPtr->lpszText = Alloc ((len+1)*sizeof(WCHAR));
2275 strcpyW (toolPtr->lpszText, lpToolInfo->lpszText);
2280 if(infoPtr->nCurrentTool == -1) return 0;
2281 /* force repaint */
2282 if (infoPtr->bActive)
2283 TOOLTIPS_Show (infoPtr, FALSE);
2284 else if (infoPtr->bTrackActive)
2285 TOOLTIPS_Show (infoPtr, TRUE);
2287 return 0;
2291 static LRESULT
2292 TOOLTIPS_WindowFromPoint (HWND hwnd, WPARAM wParam, LPARAM lParam)
2294 return (LRESULT)WindowFromPoint (*((LPPOINT)lParam));
2299 static LRESULT
2300 TOOLTIPS_Create (HWND hwnd, const CREATESTRUCTW *lpcs)
2302 TOOLTIPS_INFO *infoPtr;
2304 /* allocate memory for info structure */
2305 infoPtr = Alloc (sizeof(TOOLTIPS_INFO));
2306 SetWindowLongPtrW (hwnd, 0, (DWORD_PTR)infoPtr);
2308 /* initialize info structure */
2309 infoPtr->bActive = TRUE;
2310 infoPtr->bTrackActive = FALSE;
2312 infoPtr->nMaxTipWidth = -1;
2313 infoPtr->nTool = -1;
2314 infoPtr->nCurrentTool = -1;
2315 infoPtr->nTrackTool = -1;
2316 infoPtr->hwndSelf = hwnd;
2318 /* initialize colours and fonts */
2319 TOOLTIPS_InitSystemSettings(infoPtr);
2321 TOOLTIPS_SetDelayTime(infoPtr, TTDT_AUTOMATIC, 0L);
2323 SetWindowPos (hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOZORDER | SWP_HIDEWINDOW | SWP_NOACTIVATE);
2325 return 0;
2329 static LRESULT
2330 TOOLTIPS_Destroy (TOOLTIPS_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
2332 TTTOOL_INFO *toolPtr;
2333 UINT i;
2335 /* free tools */
2336 if (infoPtr->tools) {
2337 for (i = 0; i < infoPtr->uNumTools; i++) {
2338 toolPtr = &infoPtr->tools[i];
2339 if (toolPtr->lpszText) {
2340 if ( (toolPtr->lpszText != LPSTR_TEXTCALLBACKW) &&
2341 !IS_INTRESOURCE(toolPtr->lpszText) )
2343 Free (toolPtr->lpszText);
2344 toolPtr->lpszText = NULL;
2348 /* remove subclassing */
2349 if (toolPtr->uFlags & TTF_SUBCLASS) {
2350 if (toolPtr->uFlags & TTF_IDISHWND) {
2351 RemoveWindowSubclass((HWND)toolPtr->uId, TOOLTIPS_SubclassProc, 1);
2353 else {
2354 RemoveWindowSubclass(toolPtr->hwnd, TOOLTIPS_SubclassProc, 1);
2358 Free (infoPtr->tools);
2361 /* free title string */
2362 Free (infoPtr->pszTitle);
2363 /* free title icon if not a standard one */
2364 if (TOOLTIPS_GetTitleIconIndex(infoPtr->hTitleIcon) > TTI_ERROR)
2365 DeleteObject(infoPtr->hTitleIcon);
2367 /* delete fonts */
2368 DeleteObject (infoPtr->hFont);
2369 DeleteObject (infoPtr->hTitleFont);
2371 /* free tool tips info data */
2372 SetWindowLongPtrW(infoPtr->hwndSelf, 0, 0);
2373 Free (infoPtr);
2375 return 0;
2379 static LRESULT
2380 TOOLTIPS_GetFont (const TOOLTIPS_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
2382 return (LRESULT)infoPtr->hFont;
2386 static LRESULT
2387 TOOLTIPS_MouseMessage (TOOLTIPS_INFO *infoPtr, UINT uMsg, WPARAM wParam, LPARAM lParam)
2389 TOOLTIPS_Hide (infoPtr);
2391 return 0;
2395 static LRESULT
2396 TOOLTIPS_NCCreate (HWND hwnd, WPARAM wParam, LPARAM lParam)
2398 DWORD dwStyle = GetWindowLongW (hwnd, GWL_STYLE);
2399 DWORD dwExStyle = GetWindowLongW (hwnd, GWL_EXSTYLE);
2401 dwStyle &= ~(WS_CHILD | /*WS_MAXIMIZE |*/ WS_BORDER | WS_DLGFRAME);
2402 dwStyle |= (WS_POPUP | WS_BORDER | WS_CLIPSIBLINGS);
2404 /* WS_BORDER only draws a border round the window rect, not the
2405 * window region, therefore it is useless to us in balloon mode */
2406 if (dwStyle & TTS_BALLOON) dwStyle &= ~WS_BORDER;
2408 SetWindowLongW (hwnd, GWL_STYLE, dwStyle);
2410 dwExStyle |= WS_EX_TOOLWINDOW;
2411 SetWindowLongW (hwnd, GWL_EXSTYLE, dwExStyle);
2413 return TRUE;
2417 static LRESULT
2418 TOOLTIPS_NCHitTest (const TOOLTIPS_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
2420 INT nTool = (infoPtr->bTrackActive) ? infoPtr->nTrackTool : infoPtr->nTool;
2422 TRACE(" nTool=%d\n", nTool);
2424 if ((nTool > -1) && (nTool < infoPtr->uNumTools)) {
2425 if (infoPtr->tools[nTool].uFlags & TTF_TRANSPARENT) {
2426 TRACE("-- in transparent mode!\n");
2427 return HTTRANSPARENT;
2431 return DefWindowProcW (infoPtr->hwndSelf, WM_NCHITTEST, wParam, lParam);
2435 static LRESULT
2436 TOOLTIPS_NotifyFormat (TOOLTIPS_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
2438 FIXME ("hwnd=%p wParam=%lx lParam=%lx\n", infoPtr->hwndSelf, wParam, lParam);
2440 return 0;
2444 static LRESULT
2445 TOOLTIPS_Paint (const TOOLTIPS_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
2447 HDC hdc;
2448 PAINTSTRUCT ps;
2450 hdc = (wParam == 0) ? BeginPaint (infoPtr->hwndSelf, &ps) : (HDC)wParam;
2451 TOOLTIPS_Refresh (infoPtr, hdc);
2452 if (!wParam)
2453 EndPaint (infoPtr->hwndSelf, &ps);
2454 return 0;
2458 static LRESULT
2459 TOOLTIPS_SetFont (TOOLTIPS_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
2461 LOGFONTW lf;
2463 if(!GetObjectW((HFONT)wParam, sizeof(lf), &lf))
2464 return 0;
2466 DeleteObject (infoPtr->hFont);
2467 infoPtr->hFont = CreateFontIndirectW(&lf);
2469 DeleteObject (infoPtr->hTitleFont);
2470 lf.lfWeight = FW_BOLD;
2471 infoPtr->hTitleFont = CreateFontIndirectW(&lf);
2473 if ((LOWORD(lParam)) & (infoPtr->nCurrentTool != -1)) {
2474 FIXME("full redraw needed!\n");
2477 return 0;
2480 /******************************************************************
2481 * TOOLTIPS_GetTextLength
2483 * This function is called when the tooltip receive a
2484 * WM_GETTEXTLENGTH message.
2485 * wParam : not used
2486 * lParam : not used
2488 * returns the length, in characters, of the tip text
2490 static LRESULT
2491 TOOLTIPS_GetTextLength(const TOOLTIPS_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
2493 return strlenW(infoPtr->szTipText);
2496 /******************************************************************
2497 * TOOLTIPS_OnWMGetText
2499 * This function is called when the tooltip receive a
2500 * WM_GETTEXT message.
2501 * wParam : specifies the maximum number of characters to be copied
2502 * lParam : is the pointer to the buffer that will receive
2503 * the tip text
2505 * returns the number of characters copied
2507 static LRESULT
2508 TOOLTIPS_OnWMGetText (const TOOLTIPS_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
2510 LRESULT res;
2511 LPWSTR pszText = (LPWSTR)lParam;
2513 if(!infoPtr->szTipText || !wParam)
2514 return 0;
2516 res = min(strlenW(infoPtr->szTipText)+1, wParam);
2517 memcpy(pszText, infoPtr->szTipText, res*sizeof(WCHAR));
2518 pszText[res-1] = '\0';
2519 return res-1;
2522 static LRESULT
2523 TOOLTIPS_Timer (TOOLTIPS_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
2525 INT nOldTool;
2527 TRACE("timer %ld (%p) expired!\n", wParam, infoPtr->hwndSelf);
2529 switch (wParam) {
2530 case ID_TIMERSHOW:
2531 KillTimer (infoPtr->hwndSelf, ID_TIMERSHOW);
2532 nOldTool = infoPtr->nTool;
2533 if ((infoPtr->nTool = TOOLTIPS_CheckTool (infoPtr, TRUE)) == nOldTool)
2534 TOOLTIPS_Show (infoPtr, FALSE);
2535 break;
2537 case ID_TIMERPOP:
2538 TOOLTIPS_Hide (infoPtr);
2539 break;
2541 case ID_TIMERLEAVE:
2542 nOldTool = infoPtr->nTool;
2543 infoPtr->nTool = TOOLTIPS_CheckTool (infoPtr, FALSE);
2544 TRACE("tool (%p) %d %d %d\n", infoPtr->hwndSelf, nOldTool,
2545 infoPtr->nTool, infoPtr->nCurrentTool);
2546 if (infoPtr->nTool != nOldTool) {
2547 if(infoPtr->nTool == -1) { /* Moved out of all tools */
2548 TOOLTIPS_Hide(infoPtr);
2549 KillTimer(infoPtr->hwndSelf, ID_TIMERLEAVE);
2550 } else if (nOldTool == -1) { /* Moved from outside */
2551 ERR("How did this happen?\n");
2552 } else { /* Moved from one to another */
2553 TOOLTIPS_Hide (infoPtr);
2554 KillTimer(infoPtr->hwndSelf, ID_TIMERLEAVE);
2555 if(infoPtr->bActive) {
2556 SetTimer (infoPtr->hwndSelf, ID_TIMERSHOW, infoPtr->nReshowTime, 0);
2557 TRACE("timer 1 started!\n");
2561 break;
2563 default:
2564 ERR("Unknown timer id %ld\n", wParam);
2565 break;
2567 return 0;
2571 static LRESULT
2572 TOOLTIPS_WinIniChange (TOOLTIPS_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
2574 TOOLTIPS_InitSystemSettings (infoPtr);
2576 return 0;
2580 static LRESULT CALLBACK
2581 TOOLTIPS_SubclassProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uID, DWORD_PTR dwRef)
2583 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr ((HWND)dwRef);
2584 MSG msg;
2586 switch(uMsg) {
2587 case WM_MOUSEMOVE:
2588 case WM_LBUTTONDOWN:
2589 case WM_LBUTTONUP:
2590 case WM_MBUTTONDOWN:
2591 case WM_MBUTTONUP:
2592 case WM_RBUTTONDOWN:
2593 case WM_RBUTTONUP:
2594 msg.hwnd = hwnd;
2595 msg.message = uMsg;
2596 msg.wParam = wParam;
2597 msg.lParam = lParam;
2598 TOOLTIPS_RelayEvent(infoPtr, 0, (LPARAM)&msg);
2599 break;
2601 default:
2602 break;
2604 return DefSubclassProc(hwnd, uMsg, wParam, lParam);
2608 static LRESULT CALLBACK
2609 TOOLTIPS_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2611 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
2613 TRACE("hwnd=%p msg=%x wparam=%lx lParam=%lx\n", hwnd, uMsg, wParam, lParam);
2614 if (!infoPtr && (uMsg != WM_CREATE) && (uMsg != WM_NCCREATE))
2615 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
2616 switch (uMsg)
2618 case TTM_ACTIVATE:
2619 return TOOLTIPS_Activate (infoPtr, wParam);
2621 case TTM_ADDTOOLA:
2622 return TOOLTIPS_AddToolA (infoPtr, lParam);
2624 case TTM_ADDTOOLW:
2625 return TOOLTIPS_AddToolW (infoPtr, lParam);
2627 case TTM_DELTOOLA:
2628 return TOOLTIPS_DelToolA (infoPtr, lParam);
2630 case TTM_DELTOOLW:
2631 return TOOLTIPS_DelToolW (infoPtr, lParam);
2633 case TTM_ENUMTOOLSA:
2634 return TOOLTIPS_EnumToolsA (infoPtr, wParam, lParam);
2636 case TTM_ENUMTOOLSW:
2637 return TOOLTIPS_EnumToolsW (infoPtr, wParam, lParam);
2639 case TTM_GETBUBBLESIZE:
2640 return TOOLTIPS_GetBubbleSize (infoPtr, wParam, lParam);
2642 case TTM_GETCURRENTTOOLA:
2643 return TOOLTIPS_GetCurrentToolA (infoPtr, wParam, lParam);
2645 case TTM_GETCURRENTTOOLW:
2646 return TOOLTIPS_GetCurrentToolW (infoPtr, lParam);
2648 case TTM_GETDELAYTIME:
2649 return TOOLTIPS_GetDelayTime (infoPtr, wParam);
2651 case TTM_GETMARGIN:
2652 return TOOLTIPS_GetMargin (infoPtr, lParam);
2654 case TTM_GETMAXTIPWIDTH:
2655 return TOOLTIPS_GetMaxTipWidth (infoPtr, wParam, lParam);
2657 case TTM_GETTEXTA:
2658 return TOOLTIPS_GetTextA (infoPtr, wParam, lParam);
2660 case TTM_GETTEXTW:
2661 return TOOLTIPS_GetTextW (infoPtr, wParam, lParam);
2663 case TTM_GETTIPBKCOLOR:
2664 return TOOLTIPS_GetTipBkColor (infoPtr, wParam, lParam);
2666 case TTM_GETTIPTEXTCOLOR:
2667 return TOOLTIPS_GetTipTextColor (infoPtr, wParam, lParam);
2669 case TTM_GETTOOLCOUNT:
2670 return TOOLTIPS_GetToolCount (infoPtr);
2672 case TTM_GETTOOLINFOA:
2673 return TOOLTIPS_GetToolInfoA (infoPtr, lParam);
2675 case TTM_GETTOOLINFOW:
2676 return TOOLTIPS_GetToolInfoW (infoPtr, wParam, lParam);
2678 case TTM_HITTESTA:
2679 return TOOLTIPS_HitTestA (infoPtr, wParam, lParam);
2681 case TTM_HITTESTW:
2682 return TOOLTIPS_HitTestW (infoPtr, lParam);
2684 case TTM_NEWTOOLRECTA:
2685 return TOOLTIPS_NewToolRectA (infoPtr, wParam, lParam);
2687 case TTM_NEWTOOLRECTW:
2688 return TOOLTIPS_NewToolRectW (infoPtr, wParam, lParam);
2690 case TTM_POP:
2691 return TOOLTIPS_Pop (infoPtr);
2693 case TTM_RELAYEVENT:
2694 return TOOLTIPS_RelayEvent (infoPtr, wParam, lParam);
2696 case TTM_SETDELAYTIME:
2697 return TOOLTIPS_SetDelayTime (infoPtr, wParam, lParam);
2699 case TTM_SETMARGIN:
2700 return TOOLTIPS_SetMargin (infoPtr, lParam);
2702 case TTM_SETMAXTIPWIDTH:
2703 return TOOLTIPS_SetMaxTipWidth (infoPtr, wParam, lParam);
2705 case TTM_SETTIPBKCOLOR:
2706 return TOOLTIPS_SetTipBkColor (infoPtr, wParam, lParam);
2708 case TTM_SETTIPTEXTCOLOR:
2709 return TOOLTIPS_SetTipTextColor (infoPtr, wParam);
2711 case TTM_SETTITLEA:
2712 return TOOLTIPS_SetTitleA (infoPtr, wParam, lParam);
2714 case TTM_SETTITLEW:
2715 return TOOLTIPS_SetTitleW (infoPtr, wParam, lParam);
2717 case TTM_SETTOOLINFOA:
2718 return TOOLTIPS_SetToolInfoA (infoPtr, lParam);
2720 case TTM_SETTOOLINFOW:
2721 return TOOLTIPS_SetToolInfoW (infoPtr, wParam, lParam);
2723 case TTM_TRACKACTIVATE:
2724 return TOOLTIPS_TrackActivate (infoPtr, wParam, lParam);
2726 case TTM_TRACKPOSITION:
2727 return TOOLTIPS_TrackPosition (infoPtr, wParam, lParam);
2729 case TTM_UPDATE:
2730 return TOOLTIPS_Update (infoPtr, wParam, lParam);
2732 case TTM_UPDATETIPTEXTA:
2733 return TOOLTIPS_UpdateTipTextA (infoPtr, wParam, lParam);
2735 case TTM_UPDATETIPTEXTW:
2736 return TOOLTIPS_UpdateTipTextW (infoPtr, wParam, lParam);
2738 case TTM_WINDOWFROMPOINT:
2739 return TOOLTIPS_WindowFromPoint (hwnd, wParam, lParam);
2742 case WM_CREATE:
2743 return TOOLTIPS_Create (hwnd, (LPCREATESTRUCTW)lParam);
2745 case WM_DESTROY:
2746 return TOOLTIPS_Destroy (infoPtr, wParam, lParam);
2748 case WM_ERASEBKGND:
2749 /* we draw the background in WM_PAINT */
2750 return 0;
2752 case WM_GETFONT:
2753 return TOOLTIPS_GetFont (infoPtr, wParam, lParam);
2755 case WM_GETTEXT:
2756 return TOOLTIPS_OnWMGetText (infoPtr, wParam, lParam);
2758 case WM_GETTEXTLENGTH:
2759 return TOOLTIPS_GetTextLength (infoPtr, wParam, lParam);
2761 case WM_LBUTTONDOWN:
2762 case WM_LBUTTONUP:
2763 case WM_MBUTTONDOWN:
2764 case WM_MBUTTONUP:
2765 case WM_RBUTTONDOWN:
2766 case WM_RBUTTONUP:
2767 case WM_MOUSEMOVE:
2768 return TOOLTIPS_MouseMessage (infoPtr, uMsg, wParam, lParam);
2770 case WM_NCCREATE:
2771 return TOOLTIPS_NCCreate (hwnd, wParam, lParam);
2773 case WM_NCHITTEST:
2774 return TOOLTIPS_NCHitTest (infoPtr, wParam, lParam);
2776 case WM_NOTIFYFORMAT:
2777 return TOOLTIPS_NotifyFormat (infoPtr, wParam, lParam);
2779 case WM_PRINTCLIENT:
2780 case WM_PAINT:
2781 return TOOLTIPS_Paint (infoPtr, wParam, lParam);
2783 case WM_SETFONT:
2784 return TOOLTIPS_SetFont (infoPtr, wParam, lParam);
2786 case WM_SYSCOLORCHANGE:
2787 COMCTL32_RefreshSysColors();
2788 return 0;
2790 case WM_TIMER:
2791 return TOOLTIPS_Timer (infoPtr, wParam, lParam);
2793 case WM_WININICHANGE:
2794 return TOOLTIPS_WinIniChange (infoPtr, wParam, lParam);
2796 default:
2797 if ((uMsg >= WM_USER) && (uMsg < WM_APP) && !COMCTL32_IsReflectedMessage(uMsg))
2798 ERR("unknown msg %04x wp=%08lx lp=%08lx\n",
2799 uMsg, wParam, lParam);
2800 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
2805 VOID
2806 TOOLTIPS_Register (void)
2808 WNDCLASSW wndClass;
2810 ZeroMemory (&wndClass, sizeof(WNDCLASSW));
2811 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS | CS_SAVEBITS;
2812 wndClass.lpfnWndProc = TOOLTIPS_WindowProc;
2813 wndClass.cbClsExtra = 0;
2814 wndClass.cbWndExtra = sizeof(TOOLTIPS_INFO *);
2815 wndClass.hCursor = LoadCursorW (0, (LPWSTR)IDC_ARROW);
2816 wndClass.hbrBackground = 0;
2817 wndClass.lpszClassName = TOOLTIPS_CLASSW;
2819 RegisterClassW (&wndClass);
2821 hTooltipIcons[TTI_NONE] = NULL;
2822 hTooltipIcons[TTI_INFO] = LoadImageW(COMCTL32_hModule,
2823 (LPCWSTR)MAKEINTRESOURCE(IDI_TT_INFO_SM), IMAGE_ICON, 0, 0, 0);
2824 hTooltipIcons[TTI_WARNING] = LoadImageW(COMCTL32_hModule,
2825 (LPCWSTR)MAKEINTRESOURCE(IDI_TT_WARN_SM), IMAGE_ICON, 0, 0, 0);
2826 hTooltipIcons[TTI_ERROR] = LoadImageW(COMCTL32_hModule,
2827 (LPCWSTR)MAKEINTRESOURCE(IDI_TT_ERROR_SM), IMAGE_ICON, 0, 0, 0);
2831 VOID
2832 TOOLTIPS_Unregister (void)
2834 int i;
2835 for (i = TTI_INFO; i <= TTI_ERROR; i++)
2836 DestroyIcon(hTooltipIcons[i]);
2837 UnregisterClassW (TOOLTIPS_CLASSW, NULL);