user32: Fix a typo.
[wine/multimedia.git] / dlls / comctl32 / tooltips.c
blob8740b63f8f5192cfa7edce688db6685dfbb18855
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 WCHAR szTipText[INFOTIPSIZE];
127 BOOL bActive;
128 BOOL bTrackActive;
129 UINT uNumTools;
130 COLORREF clrBk;
131 COLORREF clrText;
132 HFONT hFont;
133 HFONT hTitleFont;
134 INT xTrackPos;
135 INT yTrackPos;
136 INT nMaxTipWidth;
137 INT nTool; /* tool that mouse was on on last relayed mouse move */
138 INT nCurrentTool;
139 INT nTrackTool;
140 INT nReshowTime;
141 INT nAutoPopTime;
142 INT nInitialTime;
143 RECT rcMargin;
144 BOOL bToolBelow;
145 LPWSTR pszTitle;
146 HICON hTitleIcon;
148 TTTOOL_INFO *tools;
149 } TOOLTIPS_INFO;
151 #define ID_TIMERSHOW 1 /* show delay timer */
152 #define ID_TIMERPOP 2 /* auto pop timer */
153 #define ID_TIMERLEAVE 3 /* tool leave timer */
156 #define TOOLTIPS_GetInfoPtr(hWindow) ((TOOLTIPS_INFO *)GetWindowLongPtrW (hWindow, 0))
158 /* offsets from window edge to start of text */
159 #define NORMAL_TEXT_MARGIN 2
160 #define BALLOON_TEXT_MARGIN (NORMAL_TEXT_MARGIN+8)
161 /* value used for CreateRoundRectRgn that specifies how much
162 * each corner is curved */
163 #define BALLOON_ROUNDEDNESS 20
164 #define BALLOON_STEMHEIGHT 13
165 #define BALLOON_STEMWIDTH 10
166 #define BALLOON_STEMINDENT 20
168 #define BALLOON_ICON_TITLE_SPACING 8 /* horizontal spacing between icon and title */
169 #define BALLOON_TITLE_TEXT_SPACING 8 /* vertical spacing between icon/title and main text */
170 #define ICON_HEIGHT 16
171 #define ICON_WIDTH 16
173 static LRESULT CALLBACK
174 TOOLTIPS_SubclassProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uId, DWORD_PTR dwRef);
177 static inline UINT_PTR
178 TOOLTIPS_GetTitleIconIndex(HICON hIcon)
180 UINT i;
181 for (i = 0; i <= TTI_ERROR; i++)
182 if (hTooltipIcons[i] == hIcon)
183 return i;
184 return (UINT_PTR)hIcon;
187 static void
188 TOOLTIPS_InitSystemSettings (TOOLTIPS_INFO *infoPtr)
190 NONCLIENTMETRICSW nclm;
192 infoPtr->clrBk = GetSysColor (COLOR_INFOBK);
193 infoPtr->clrText = GetSysColor (COLOR_INFOTEXT);
195 DeleteObject (infoPtr->hFont);
196 nclm.cbSize = sizeof(nclm);
197 SystemParametersInfoW (SPI_GETNONCLIENTMETRICS, sizeof(nclm), &nclm, 0);
198 infoPtr->hFont = CreateFontIndirectW (&nclm.lfStatusFont);
200 DeleteObject (infoPtr->hTitleFont);
201 nclm.lfStatusFont.lfWeight = FW_BOLD;
202 infoPtr->hTitleFont = CreateFontIndirectW (&nclm.lfStatusFont);
205 static void
206 TOOLTIPS_Refresh (HWND hwnd, HDC hdc)
208 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr(hwnd);
209 RECT rc;
210 INT oldBkMode;
211 HFONT hOldFont;
212 HBRUSH hBrush;
213 UINT uFlags = DT_EXTERNALLEADING;
214 HRGN hRgn = NULL;
215 DWORD dwStyle = GetWindowLongW(hwnd, GWL_STYLE);
217 if (infoPtr->nMaxTipWidth > -1)
218 uFlags |= DT_WORDBREAK;
219 if (GetWindowLongW (hwnd, GWL_STYLE) & TTS_NOPREFIX)
220 uFlags |= DT_NOPREFIX;
221 GetClientRect (hwnd, &rc);
223 hBrush = CreateSolidBrush(infoPtr->clrBk);
225 oldBkMode = SetBkMode (hdc, TRANSPARENT);
226 SetTextColor (hdc, infoPtr->clrText);
228 if (dwStyle & TTS_BALLOON)
230 /* create a region to store result into */
231 hRgn = CreateRectRgn(0, 0, 0, 0);
233 GetWindowRgn(hwnd, hRgn);
235 /* fill the background */
236 FillRgn(hdc, hRgn, hBrush);
237 DeleteObject(hBrush);
238 hBrush = NULL;
240 else
242 /* fill the background */
243 FillRect(hdc, &rc, hBrush);
244 DeleteObject(hBrush);
245 hBrush = NULL;
248 if ((dwStyle & TTS_BALLOON) || infoPtr->pszTitle)
250 /* calculate text rectangle */
251 rc.left += (BALLOON_TEXT_MARGIN + infoPtr->rcMargin.left);
252 rc.top += (BALLOON_TEXT_MARGIN + infoPtr->rcMargin.top);
253 rc.right -= (BALLOON_TEXT_MARGIN + infoPtr->rcMargin.right);
254 rc.bottom -= (BALLOON_TEXT_MARGIN + infoPtr->rcMargin.bottom);
255 if(infoPtr->bToolBelow) rc.top += BALLOON_STEMHEIGHT;
257 if (infoPtr->pszTitle)
259 RECT rcTitle = {rc.left, rc.top, rc.right, rc.bottom};
260 int height;
261 BOOL icon_present;
263 /* draw icon */
264 icon_present = infoPtr->hTitleIcon &&
265 DrawIconEx(hdc, rc.left, rc.top, infoPtr->hTitleIcon,
266 ICON_WIDTH, ICON_HEIGHT, 0, NULL, DI_NORMAL);
267 if (icon_present)
268 rcTitle.left += ICON_WIDTH + BALLOON_ICON_TITLE_SPACING;
270 rcTitle.bottom = rc.top + ICON_HEIGHT;
272 /* draw title text */
273 hOldFont = SelectObject (hdc, infoPtr->hTitleFont);
274 height = DrawTextW(hdc, infoPtr->pszTitle, -1, &rcTitle, DT_BOTTOM | DT_SINGLELINE | DT_NOPREFIX);
275 SelectObject (hdc, hOldFont);
276 rc.top += height + BALLOON_TITLE_TEXT_SPACING;
279 else
281 /* calculate text rectangle */
282 rc.left += (NORMAL_TEXT_MARGIN + infoPtr->rcMargin.left);
283 rc.top += (NORMAL_TEXT_MARGIN + infoPtr->rcMargin.top);
284 rc.right -= (NORMAL_TEXT_MARGIN + infoPtr->rcMargin.right);
285 rc.bottom -= (NORMAL_TEXT_MARGIN + infoPtr->rcMargin.bottom);
288 /* draw text */
289 hOldFont = SelectObject (hdc, infoPtr->hFont);
290 DrawTextW (hdc, infoPtr->szTipText, -1, &rc, uFlags);
291 /* be polite and reset the things we changed in the dc */
292 SelectObject (hdc, hOldFont);
293 SetBkMode (hdc, oldBkMode);
295 if (dwStyle & TTS_BALLOON)
297 /* frame region because default window proc doesn't do it */
298 INT width = GetSystemMetrics(SM_CXDLGFRAME) - GetSystemMetrics(SM_CXEDGE);
299 INT height = GetSystemMetrics(SM_CYDLGFRAME) - GetSystemMetrics(SM_CYEDGE);
301 hBrush = GetSysColorBrush(COLOR_WINDOWFRAME);
302 FrameRgn(hdc, hRgn, hBrush, width, height);
305 if (hRgn)
306 DeleteObject(hRgn);
309 static void TOOLTIPS_GetDispInfoA(HWND hwnd, TOOLTIPS_INFO *infoPtr, TTTOOL_INFO *toolPtr)
311 NMTTDISPINFOA ttnmdi;
313 /* fill NMHDR struct */
314 ZeroMemory (&ttnmdi, sizeof(NMTTDISPINFOA));
315 ttnmdi.hdr.hwndFrom = hwnd;
316 ttnmdi.hdr.idFrom = toolPtr->uId;
317 ttnmdi.hdr.code = TTN_GETDISPINFOA; /* == TTN_NEEDTEXTA */
318 ttnmdi.lpszText = (LPSTR)&ttnmdi.szText;
319 ttnmdi.uFlags = toolPtr->uFlags;
320 ttnmdi.lParam = toolPtr->lParam;
322 TRACE("hdr.idFrom = %lx\n", ttnmdi.hdr.idFrom);
323 SendMessageW(toolPtr->hwnd, WM_NOTIFY,
324 (WPARAM)toolPtr->uId, (LPARAM)&ttnmdi);
326 if (IS_INTRESOURCE(ttnmdi.lpszText)) {
327 LoadStringW(ttnmdi.hinst, LOWORD(ttnmdi.lpszText),
328 infoPtr->szTipText, INFOTIPSIZE);
329 if (ttnmdi.uFlags & TTF_DI_SETITEM) {
330 toolPtr->hinst = ttnmdi.hinst;
331 toolPtr->lpszText = (LPWSTR)ttnmdi.lpszText;
334 else if (ttnmdi.lpszText == 0) {
335 infoPtr->szTipText[0] = '\0';
337 else if (ttnmdi.lpszText != LPSTR_TEXTCALLBACKA) {
338 Str_GetPtrAtoW(ttnmdi.lpszText, infoPtr->szTipText, INFOTIPSIZE);
339 if (ttnmdi.uFlags & TTF_DI_SETITEM) {
340 toolPtr->hinst = 0;
341 toolPtr->lpszText = NULL;
342 Str_SetPtrW(&toolPtr->lpszText, infoPtr->szTipText);
345 else {
346 ERR("recursive text callback!\n");
347 infoPtr->szTipText[0] = '\0';
350 /* no text available - try calling parent instead as per native */
351 /* FIXME: Unsure if SETITEM should save the value or not */
352 if (infoPtr->szTipText[0] == 0x00) {
354 SendMessageW(GetParent(toolPtr->hwnd), WM_NOTIFY,
355 (WPARAM)toolPtr->uId, (LPARAM)&ttnmdi);
357 if (IS_INTRESOURCE(ttnmdi.lpszText)) {
358 LoadStringW(ttnmdi.hinst, LOWORD(ttnmdi.lpszText),
359 infoPtr->szTipText, INFOTIPSIZE);
360 } else if (ttnmdi.lpszText &&
361 ttnmdi.lpszText != LPSTR_TEXTCALLBACKA) {
362 Str_GetPtrAtoW(ttnmdi.lpszText, infoPtr->szTipText, INFOTIPSIZE);
367 static void TOOLTIPS_GetDispInfoW(HWND hwnd, TOOLTIPS_INFO *infoPtr, TTTOOL_INFO *toolPtr)
369 NMTTDISPINFOW ttnmdi;
371 /* fill NMHDR struct */
372 ZeroMemory (&ttnmdi, sizeof(NMTTDISPINFOW));
373 ttnmdi.hdr.hwndFrom = hwnd;
374 ttnmdi.hdr.idFrom = toolPtr->uId;
375 ttnmdi.hdr.code = TTN_GETDISPINFOW; /* == TTN_NEEDTEXTW */
376 ttnmdi.lpszText = (LPWSTR)&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,
382 (WPARAM)toolPtr->uId, (LPARAM)&ttnmdi);
384 if (IS_INTRESOURCE(ttnmdi.lpszText)) {
385 LoadStringW(ttnmdi.hinst, LOWORD(ttnmdi.lpszText),
386 infoPtr->szTipText, INFOTIPSIZE);
387 if (ttnmdi.uFlags & TTF_DI_SETITEM) {
388 toolPtr->hinst = ttnmdi.hinst;
389 toolPtr->lpszText = ttnmdi.lpszText;
392 else if (ttnmdi.lpszText == 0) {
393 infoPtr->szTipText[0] = '\0';
395 else if (ttnmdi.lpszText != LPSTR_TEXTCALLBACKW) {
396 Str_GetPtrW(ttnmdi.lpszText, infoPtr->szTipText, INFOTIPSIZE);
397 if (ttnmdi.uFlags & TTF_DI_SETITEM) {
398 toolPtr->hinst = 0;
399 toolPtr->lpszText = NULL;
400 Str_SetPtrW(&toolPtr->lpszText, infoPtr->szTipText);
403 else {
404 ERR("recursive text callback!\n");
405 infoPtr->szTipText[0] = '\0';
408 /* no text available - try calling parent instead as per native */
409 /* FIXME: Unsure if SETITEM should save the value or not */
410 if (infoPtr->szTipText[0] == 0x00) {
412 SendMessageW(GetParent(toolPtr->hwnd), WM_NOTIFY,
413 (WPARAM)toolPtr->uId, (LPARAM)&ttnmdi);
415 if (IS_INTRESOURCE(ttnmdi.lpszText)) {
416 LoadStringW(ttnmdi.hinst, LOWORD(ttnmdi.lpszText),
417 infoPtr->szTipText, INFOTIPSIZE);
418 } else if (ttnmdi.lpszText &&
419 ttnmdi.lpszText != LPSTR_TEXTCALLBACKW) {
420 Str_GetPtrW(ttnmdi.lpszText, infoPtr->szTipText, INFOTIPSIZE);
426 static void
427 TOOLTIPS_GetTipText (HWND hwnd, TOOLTIPS_INFO *infoPtr, INT nTool)
429 TTTOOL_INFO *toolPtr = &infoPtr->tools[nTool];
431 if (IS_INTRESOURCE(toolPtr->lpszText) && toolPtr->hinst) {
432 /* load a resource */
433 TRACE("load res string %p %x\n",
434 toolPtr->hinst, LOWORD(toolPtr->lpszText));
435 LoadStringW (toolPtr->hinst, LOWORD(toolPtr->lpszText),
436 infoPtr->szTipText, INFOTIPSIZE);
438 else if (toolPtr->lpszText) {
439 if (toolPtr->lpszText == LPSTR_TEXTCALLBACKW) {
440 if (toolPtr->bNotifyUnicode)
441 TOOLTIPS_GetDispInfoW(hwnd, infoPtr, toolPtr);
442 else
443 TOOLTIPS_GetDispInfoA(hwnd, infoPtr, toolPtr);
445 else {
446 /* the item is a usual (unicode) text */
447 lstrcpynW (infoPtr->szTipText, toolPtr->lpszText, INFOTIPSIZE);
450 else {
451 /* no text available */
452 infoPtr->szTipText[0] = '\0';
455 TRACE("%s\n", debugstr_w(infoPtr->szTipText));
459 static void
460 TOOLTIPS_CalcTipSize (HWND hwnd, const TOOLTIPS_INFO *infoPtr, LPSIZE lpSize)
462 HDC hdc;
463 HFONT hOldFont;
464 DWORD style = GetWindowLongW(hwnd, GWL_STYLE);
465 UINT uFlags = DT_EXTERNALLEADING | DT_CALCRECT;
466 RECT rc = {0, 0, 0, 0};
467 SIZE title = {0, 0};
469 if (infoPtr->nMaxTipWidth > -1) {
470 rc.right = infoPtr->nMaxTipWidth;
471 uFlags |= DT_WORDBREAK;
473 if (style & TTS_NOPREFIX)
474 uFlags |= DT_NOPREFIX;
475 TRACE("%s\n", debugstr_w(infoPtr->szTipText));
477 hdc = GetDC (hwnd);
478 if (infoPtr->pszTitle)
480 RECT rcTitle = {0, 0, 0, 0};
481 TRACE("title %s\n", debugstr_w(infoPtr->pszTitle));
482 if (infoPtr->hTitleIcon)
484 title.cx = ICON_WIDTH;
485 title.cy = ICON_HEIGHT;
487 if (title.cx != 0) title.cx += BALLOON_ICON_TITLE_SPACING;
488 hOldFont = SelectObject (hdc, infoPtr->hTitleFont);
489 DrawTextW(hdc, infoPtr->pszTitle, -1, &rcTitle, DT_SINGLELINE | DT_NOPREFIX | DT_CALCRECT);
490 SelectObject (hdc, hOldFont);
491 title.cy = max(title.cy, rcTitle.bottom - rcTitle.top) + BALLOON_TITLE_TEXT_SPACING;
492 title.cx += (rcTitle.right - rcTitle.left);
494 hOldFont = SelectObject (hdc, infoPtr->hFont);
495 DrawTextW (hdc, infoPtr->szTipText, -1, &rc, uFlags);
496 SelectObject (hdc, hOldFont);
497 ReleaseDC (hwnd, hdc);
499 if ((style & TTS_BALLOON) || infoPtr->pszTitle)
501 lpSize->cx = max(rc.right - rc.left, title.cx) + 2*BALLOON_TEXT_MARGIN +
502 infoPtr->rcMargin.left + infoPtr->rcMargin.right;
503 lpSize->cy = title.cy + rc.bottom - rc.top + 2*BALLOON_TEXT_MARGIN +
504 infoPtr->rcMargin.bottom + infoPtr->rcMargin.top +
505 BALLOON_STEMHEIGHT;
507 else
509 lpSize->cx = rc.right - rc.left + 2*NORMAL_TEXT_MARGIN +
510 infoPtr->rcMargin.left + infoPtr->rcMargin.right;
511 lpSize->cy = rc.bottom - rc.top + 2*NORMAL_TEXT_MARGIN +
512 infoPtr->rcMargin.bottom + infoPtr->rcMargin.top;
517 static void
518 TOOLTIPS_Show (HWND hwnd, TOOLTIPS_INFO *infoPtr, BOOL track_activate)
520 TTTOOL_INFO *toolPtr;
521 HMONITOR monitor;
522 MONITORINFO mon_info;
523 RECT rect;
524 SIZE size;
525 NMHDR hdr;
526 int ptfx = 0;
527 DWORD style = GetWindowLongW(hwnd, GWL_STYLE);
528 INT nTool;
530 if (track_activate)
532 if (infoPtr->nTrackTool == -1)
534 TRACE("invalid tracking tool (-1)!\n");
535 return;
537 nTool = infoPtr->nTrackTool;
539 else
541 if (infoPtr->nTool == -1)
543 TRACE("invalid tool (-1)!\n");
544 return;
546 nTool = infoPtr->nTool;
549 TRACE("Show tooltip pre %d! (%p)\n", nTool, hwnd);
551 TOOLTIPS_GetTipText (hwnd, infoPtr, nTool);
553 if (infoPtr->szTipText[0] == '\0')
554 return;
556 toolPtr = &infoPtr->tools[nTool];
558 if (!track_activate)
559 infoPtr->nCurrentTool = infoPtr->nTool;
561 TRACE("Show tooltip %d!\n", nTool);
563 hdr.hwndFrom = hwnd;
564 hdr.idFrom = toolPtr->uId;
565 hdr.code = TTN_SHOW;
566 SendMessageW (toolPtr->hwnd, WM_NOTIFY,
567 (WPARAM)toolPtr->uId, (LPARAM)&hdr);
569 TRACE("%s\n", debugstr_w(infoPtr->szTipText));
571 TOOLTIPS_CalcTipSize (hwnd, infoPtr, &size);
572 TRACE("size %d x %d\n", size.cx, size.cy);
574 if (track_activate)
576 rect.left = infoPtr->xTrackPos;
577 rect.top = infoPtr->yTrackPos;
578 ptfx = rect.left;
580 if (toolPtr->uFlags & TTF_CENTERTIP)
582 rect.left -= (size.cx / 2);
583 if (!(style & TTS_BALLOON))
584 rect.top -= (size.cy / 2);
586 infoPtr->bToolBelow = TRUE;
588 if (!(toolPtr->uFlags & TTF_ABSOLUTE))
590 if (style & TTS_BALLOON)
591 rect.left -= BALLOON_STEMINDENT;
592 else
594 RECT rcTool;
596 if (toolPtr->uFlags & TTF_IDISHWND)
597 GetWindowRect ((HWND)toolPtr->uId, &rcTool);
598 else
600 rcTool = toolPtr->rect;
601 MapWindowPoints (toolPtr->hwnd, NULL, (LPPOINT)&rcTool, 2);
604 /* smart placement */
605 if ((rect.left + size.cx > rcTool.left) && (rect.left < rcTool.right) &&
606 (rect.top + size.cy > rcTool.top) && (rect.top < rcTool.bottom))
607 rect.left = rcTool.right;
611 else
613 if (toolPtr->uFlags & TTF_CENTERTIP)
615 RECT rc;
617 if (toolPtr->uFlags & TTF_IDISHWND)
618 GetWindowRect ((HWND)toolPtr->uId, &rc);
619 else {
620 rc = toolPtr->rect;
621 MapWindowPoints (toolPtr->hwnd, NULL, (LPPOINT)&rc, 2);
623 rect.left = (rc.left + rc.right - size.cx) / 2;
624 if (style & TTS_BALLOON)
626 ptfx = rc.left + ((rc.right - rc.left) / 2);
628 /* CENTERTIP ballon tooltips default to below the field
629 * if they fit on the screen */
630 if (rc.bottom + size.cy > GetSystemMetrics(SM_CYSCREEN))
632 rect.top = rc.top - size.cy;
633 infoPtr->bToolBelow = FALSE;
635 else
637 infoPtr->bToolBelow = TRUE;
638 rect.top = rc.bottom;
640 rect.left = max(0, rect.left - BALLOON_STEMINDENT);
642 else
644 rect.top = rc.bottom + 2;
645 infoPtr->bToolBelow = TRUE;
648 else
650 GetCursorPos ((LPPOINT)&rect);
651 if (style & TTS_BALLOON)
653 ptfx = rect.left;
654 if(rect.top - size.cy >= 0)
656 rect.top -= size.cy;
657 infoPtr->bToolBelow = FALSE;
659 else
661 infoPtr->bToolBelow = TRUE;
662 rect.top += 20;
664 rect.left = max(0, rect.left - BALLOON_STEMINDENT);
666 else
668 rect.top += 20;
669 infoPtr->bToolBelow = TRUE;
674 TRACE("pos %d - %d\n", rect.left, rect.top);
676 rect.right = rect.left + size.cx;
677 rect.bottom = rect.top + size.cy;
679 /* check position */
681 monitor = MonitorFromRect( &rect, MONITOR_DEFAULTTOPRIMARY );
682 mon_info.cbSize = sizeof(mon_info);
683 GetMonitorInfoW( monitor, &mon_info );
685 if( rect.right > mon_info.rcWork.right ) {
686 rect.left -= rect.right - mon_info.rcWork.right + 2;
687 rect.right = mon_info.rcWork.right - 2;
689 if (rect.left < mon_info.rcWork.left) rect.left = mon_info.rcWork.left;
691 if( rect.bottom > mon_info.rcWork.bottom ) {
692 RECT rc;
694 if (toolPtr->uFlags & TTF_IDISHWND)
695 GetWindowRect ((HWND)toolPtr->uId, &rc);
696 else {
697 rc = toolPtr->rect;
698 MapWindowPoints (toolPtr->hwnd, NULL, (LPPOINT)&rc, 2);
700 rect.bottom = rc.top - 2;
701 rect.top = rect.bottom - size.cy;
704 AdjustWindowRectEx (&rect, GetWindowLongW (hwnd, GWL_STYLE),
705 FALSE, GetWindowLongW (hwnd, GWL_EXSTYLE));
707 if (style & TTS_BALLOON)
709 HRGN hRgn;
710 HRGN hrStem;
711 POINT pts[3];
713 ptfx -= rect.left;
715 if(infoPtr->bToolBelow)
717 pts[0].x = ptfx;
718 pts[0].y = 0;
719 pts[1].x = max(BALLOON_STEMINDENT, ptfx - (BALLOON_STEMWIDTH / 2));
720 pts[1].y = BALLOON_STEMHEIGHT;
721 pts[2].x = pts[1].x + BALLOON_STEMWIDTH;
722 pts[2].y = pts[1].y;
723 if(pts[2].x > (rect.right - rect.left) - BALLOON_STEMINDENT)
725 pts[2].x = (rect.right - rect.left) - BALLOON_STEMINDENT;
726 pts[1].x = pts[2].x - BALLOON_STEMWIDTH;
729 else
731 pts[0].x = max(BALLOON_STEMINDENT, ptfx - (BALLOON_STEMWIDTH / 2));
732 pts[0].y = (rect.bottom - rect.top) - BALLOON_STEMHEIGHT;
733 pts[1].x = pts[0].x + BALLOON_STEMWIDTH;
734 pts[1].y = pts[0].y;
735 pts[2].x = ptfx;
736 pts[2].y = (rect.bottom - rect.top);
737 if(pts[1].x > (rect.right - rect.left) - BALLOON_STEMINDENT)
739 pts[1].x = (rect.right - rect.left) - BALLOON_STEMINDENT;
740 pts[0].x = pts[1].x - BALLOON_STEMWIDTH;
744 hrStem = CreatePolygonRgn(pts, sizeof(pts) / sizeof(pts[0]), ALTERNATE);
746 hRgn = CreateRoundRectRgn(0,
747 (infoPtr->bToolBelow ? BALLOON_STEMHEIGHT : 0),
748 rect.right - rect.left,
749 (infoPtr->bToolBelow ? rect.bottom - rect.top : rect.bottom - rect.top - BALLOON_STEMHEIGHT),
750 BALLOON_ROUNDEDNESS, BALLOON_ROUNDEDNESS);
752 CombineRgn(hRgn, hRgn, hrStem, RGN_OR);
753 DeleteObject(hrStem);
755 SetWindowRgn(hwnd, hRgn, FALSE);
756 /* we don't free the region handle as the system deletes it when
757 * it is no longer needed */
760 SetWindowPos (hwnd, HWND_TOP, rect.left, rect.top,
761 rect.right - rect.left, rect.bottom - rect.top,
762 SWP_SHOWWINDOW | SWP_NOACTIVATE);
764 /* repaint the tooltip */
765 InvalidateRect(hwnd, NULL, TRUE);
766 UpdateWindow(hwnd);
768 if (!track_activate)
770 SetTimer (hwnd, ID_TIMERPOP, infoPtr->nAutoPopTime, 0);
771 TRACE("timer 2 started!\n");
772 SetTimer (hwnd, ID_TIMERLEAVE, infoPtr->nReshowTime, 0);
773 TRACE("timer 3 started!\n");
778 static void
779 TOOLTIPS_Hide (HWND hwnd, TOOLTIPS_INFO *infoPtr)
781 TTTOOL_INFO *toolPtr;
782 NMHDR hdr;
784 TRACE("Hide tooltip %d! (%p)\n", infoPtr->nCurrentTool, hwnd);
786 if (infoPtr->nCurrentTool == -1)
787 return;
789 toolPtr = &infoPtr->tools[infoPtr->nCurrentTool];
790 KillTimer (hwnd, ID_TIMERPOP);
792 hdr.hwndFrom = hwnd;
793 hdr.idFrom = toolPtr->uId;
794 hdr.code = TTN_POP;
795 SendMessageW (toolPtr->hwnd, WM_NOTIFY,
796 (WPARAM)toolPtr->uId, (LPARAM)&hdr);
798 infoPtr->nCurrentTool = -1;
800 SetWindowPos (hwnd, HWND_TOP, 0, 0, 0, 0,
801 SWP_NOZORDER | SWP_HIDEWINDOW | SWP_NOACTIVATE);
805 static void
806 TOOLTIPS_TrackShow (HWND hwnd, TOOLTIPS_INFO *infoPtr)
808 TOOLTIPS_Show(hwnd, infoPtr, TRUE);
812 static void
813 TOOLTIPS_TrackHide (HWND hwnd, const TOOLTIPS_INFO *infoPtr)
815 TTTOOL_INFO *toolPtr;
816 NMHDR hdr;
818 TRACE("hide tracking tooltip %d\n", infoPtr->nTrackTool);
820 if (infoPtr->nTrackTool == -1)
821 return;
823 toolPtr = &infoPtr->tools[infoPtr->nTrackTool];
825 hdr.hwndFrom = hwnd;
826 hdr.idFrom = toolPtr->uId;
827 hdr.code = TTN_POP;
828 SendMessageW (toolPtr->hwnd, WM_NOTIFY,
829 (WPARAM)toolPtr->uId, (LPARAM)&hdr);
831 SetWindowPos (hwnd, HWND_TOP, 0, 0, 0, 0,
832 SWP_NOZORDER | SWP_HIDEWINDOW | SWP_NOACTIVATE);
836 static INT
837 TOOLTIPS_GetToolFromInfoA (const TOOLTIPS_INFO *infoPtr, const TTTOOLINFOA *lpToolInfo)
839 TTTOOL_INFO *toolPtr;
840 INT nTool;
842 for (nTool = 0; nTool < infoPtr->uNumTools; nTool++) {
843 toolPtr = &infoPtr->tools[nTool];
845 if (!(toolPtr->uFlags & TTF_IDISHWND) &&
846 (lpToolInfo->hwnd == toolPtr->hwnd) &&
847 (lpToolInfo->uId == toolPtr->uId))
848 return nTool;
851 for (nTool = 0; nTool < infoPtr->uNumTools; nTool++) {
852 toolPtr = &infoPtr->tools[nTool];
854 if ((toolPtr->uFlags & TTF_IDISHWND) &&
855 (lpToolInfo->uId == toolPtr->uId))
856 return nTool;
859 return -1;
863 static INT
864 TOOLTIPS_GetToolFromInfoW (const TOOLTIPS_INFO *infoPtr, const TTTOOLINFOW *lpToolInfo)
866 TTTOOL_INFO *toolPtr;
867 INT nTool;
869 for (nTool = 0; nTool < infoPtr->uNumTools; nTool++) {
870 toolPtr = &infoPtr->tools[nTool];
872 if (!(toolPtr->uFlags & TTF_IDISHWND) &&
873 (lpToolInfo->hwnd == toolPtr->hwnd) &&
874 (lpToolInfo->uId == toolPtr->uId))
875 return nTool;
878 for (nTool = 0; nTool < infoPtr->uNumTools; nTool++) {
879 toolPtr = &infoPtr->tools[nTool];
881 if ((toolPtr->uFlags & TTF_IDISHWND) &&
882 (lpToolInfo->uId == toolPtr->uId))
883 return nTool;
886 return -1;
890 static INT
891 TOOLTIPS_GetToolFromPoint (const TOOLTIPS_INFO *infoPtr, HWND hwnd, const POINT *lpPt)
893 TTTOOL_INFO *toolPtr;
894 INT nTool;
896 for (nTool = 0; nTool < infoPtr->uNumTools; nTool++) {
897 toolPtr = &infoPtr->tools[nTool];
899 if (!(toolPtr->uFlags & TTF_IDISHWND)) {
900 if (hwnd != toolPtr->hwnd)
901 continue;
902 if (!PtInRect (&toolPtr->rect, *lpPt))
903 continue;
904 return nTool;
908 for (nTool = 0; nTool < infoPtr->uNumTools; nTool++) {
909 toolPtr = &infoPtr->tools[nTool];
911 if (toolPtr->uFlags & TTF_IDISHWND) {
912 if ((HWND)toolPtr->uId == hwnd)
913 return nTool;
917 return -1;
921 static BOOL
922 TOOLTIPS_IsWindowActive (HWND hwnd)
924 HWND hwndActive = GetActiveWindow ();
925 if (!hwndActive)
926 return FALSE;
927 if (hwndActive == hwnd)
928 return TRUE;
929 return IsChild (hwndActive, hwnd);
933 static INT
934 TOOLTIPS_CheckTool (HWND hwnd, BOOL bShowTest)
936 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
937 POINT pt;
938 HWND hwndTool;
939 INT nTool;
941 GetCursorPos (&pt);
942 hwndTool = (HWND)SendMessageW (hwnd, TTM_WINDOWFROMPOINT, 0, (LPARAM)&pt);
943 if (hwndTool == 0)
944 return -1;
946 ScreenToClient (hwndTool, &pt);
947 nTool = TOOLTIPS_GetToolFromPoint (infoPtr, hwndTool, &pt);
948 if (nTool == -1)
949 return -1;
951 if (!(GetWindowLongW (hwnd, GWL_STYLE) & TTS_ALWAYSTIP) && bShowTest) {
952 if (!TOOLTIPS_IsWindowActive (GetWindow (hwnd, GW_OWNER)))
953 return -1;
956 TRACE("tool %d\n", nTool);
958 return nTool;
962 static LRESULT
963 TOOLTIPS_Activate (HWND hwnd, WPARAM wParam, LPARAM lParam)
965 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
967 infoPtr->bActive = (BOOL)wParam;
969 if (infoPtr->bActive)
970 TRACE("activate!\n");
972 if (!(infoPtr->bActive) && (infoPtr->nCurrentTool != -1))
973 TOOLTIPS_Hide (hwnd, infoPtr);
975 return 0;
979 static LRESULT
980 TOOLTIPS_AddToolA (HWND hwnd, WPARAM wParam, LPARAM lParam)
982 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
983 LPTTTOOLINFOA lpToolInfo = (LPTTTOOLINFOA)lParam;
984 TTTOOL_INFO *toolPtr;
985 INT nResult;
987 if (lpToolInfo == NULL)
988 return FALSE;
989 if (lpToolInfo->cbSize < TTTOOLINFOA_V1_SIZE)
990 return FALSE;
992 TRACE("add tool (%p) %p %ld%s!\n",
993 hwnd, lpToolInfo->hwnd, lpToolInfo->uId,
994 (lpToolInfo->uFlags & TTF_IDISHWND) ? " TTF_IDISHWND" : "");
996 if (infoPtr->uNumTools == 0) {
997 infoPtr->tools = Alloc (sizeof(TTTOOL_INFO));
998 toolPtr = infoPtr->tools;
1000 else {
1001 TTTOOL_INFO *oldTools = infoPtr->tools;
1002 infoPtr->tools =
1003 Alloc (sizeof(TTTOOL_INFO) * (infoPtr->uNumTools + 1));
1004 memcpy (infoPtr->tools, oldTools,
1005 infoPtr->uNumTools * sizeof(TTTOOL_INFO));
1006 Free (oldTools);
1007 toolPtr = &infoPtr->tools[infoPtr->uNumTools];
1010 infoPtr->uNumTools++;
1012 /* copy tool data */
1013 toolPtr->uFlags = lpToolInfo->uFlags;
1014 toolPtr->hwnd = lpToolInfo->hwnd;
1015 toolPtr->uId = lpToolInfo->uId;
1016 toolPtr->rect = lpToolInfo->rect;
1017 toolPtr->hinst = lpToolInfo->hinst;
1019 if (IS_INTRESOURCE(lpToolInfo->lpszText)) {
1020 TRACE("add string id %x!\n", LOWORD(lpToolInfo->lpszText));
1021 toolPtr->lpszText = (LPWSTR)lpToolInfo->lpszText;
1023 else if (lpToolInfo->lpszText) {
1024 if (lpToolInfo->lpszText == LPSTR_TEXTCALLBACKA) {
1025 TRACE("add CALLBACK!\n");
1026 toolPtr->lpszText = LPSTR_TEXTCALLBACKW;
1028 else {
1029 INT len = MultiByteToWideChar(CP_ACP, 0, lpToolInfo->lpszText, -1,
1030 NULL, 0);
1031 TRACE("add text \"%s\"!\n", lpToolInfo->lpszText);
1032 toolPtr->lpszText = Alloc (len * sizeof(WCHAR));
1033 MultiByteToWideChar(CP_ACP, 0, lpToolInfo->lpszText, -1,
1034 toolPtr->lpszText, len);
1038 if (lpToolInfo->cbSize >= sizeof(TTTOOLINFOA))
1039 toolPtr->lParam = lpToolInfo->lParam;
1041 /* install subclassing hook */
1042 if (toolPtr->uFlags & TTF_SUBCLASS) {
1043 if (toolPtr->uFlags & TTF_IDISHWND) {
1044 SetWindowSubclass((HWND)toolPtr->uId, TOOLTIPS_SubclassProc, 1,
1045 (DWORD_PTR)hwnd);
1047 else {
1048 SetWindowSubclass(toolPtr->hwnd, TOOLTIPS_SubclassProc, 1,
1049 (DWORD_PTR)hwnd);
1051 TRACE("subclassing installed!\n");
1054 nResult = (INT) SendMessageW (toolPtr->hwnd, WM_NOTIFYFORMAT,
1055 (WPARAM)hwnd, (LPARAM)NF_QUERY);
1056 if (nResult == NFR_ANSI) {
1057 toolPtr->bNotifyUnicode = FALSE;
1058 TRACE(" -- WM_NOTIFYFORMAT returns: NFR_ANSI\n");
1059 } else if (nResult == NFR_UNICODE) {
1060 toolPtr->bNotifyUnicode = TRUE;
1061 TRACE(" -- WM_NOTIFYFORMAT returns: NFR_UNICODE\n");
1062 } else {
1063 TRACE (" -- WM_NOTIFYFORMAT returns: error!\n");
1066 return TRUE;
1070 static LRESULT
1071 TOOLTIPS_AddToolW (HWND hwnd, WPARAM wParam, LPARAM lParam)
1073 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1074 LPTTTOOLINFOW lpToolInfo = (LPTTTOOLINFOW)lParam;
1075 TTTOOL_INFO *toolPtr;
1076 INT nResult;
1078 if (lpToolInfo == NULL)
1079 return FALSE;
1080 if (lpToolInfo->cbSize < TTTOOLINFOW_V1_SIZE)
1081 return FALSE;
1083 TRACE("add tool (%p) %p %ld%s!\n",
1084 hwnd, lpToolInfo->hwnd, lpToolInfo->uId,
1085 (lpToolInfo->uFlags & TTF_IDISHWND) ? " TTF_IDISHWND" : "");
1087 if (infoPtr->uNumTools == 0) {
1088 infoPtr->tools = Alloc (sizeof(TTTOOL_INFO));
1089 toolPtr = infoPtr->tools;
1091 else {
1092 TTTOOL_INFO *oldTools = infoPtr->tools;
1093 infoPtr->tools =
1094 Alloc (sizeof(TTTOOL_INFO) * (infoPtr->uNumTools + 1));
1095 memcpy (infoPtr->tools, oldTools,
1096 infoPtr->uNumTools * sizeof(TTTOOL_INFO));
1097 Free (oldTools);
1098 toolPtr = &infoPtr->tools[infoPtr->uNumTools];
1101 infoPtr->uNumTools++;
1103 /* copy tool data */
1104 toolPtr->uFlags = lpToolInfo->uFlags;
1105 toolPtr->hwnd = lpToolInfo->hwnd;
1106 toolPtr->uId = lpToolInfo->uId;
1107 toolPtr->rect = lpToolInfo->rect;
1108 toolPtr->hinst = lpToolInfo->hinst;
1110 if (IS_INTRESOURCE(lpToolInfo->lpszText)) {
1111 TRACE("add string id %x\n", LOWORD(lpToolInfo->lpszText));
1112 toolPtr->lpszText = (LPWSTR)lpToolInfo->lpszText;
1114 else if (lpToolInfo->lpszText) {
1115 if (lpToolInfo->lpszText == LPSTR_TEXTCALLBACKW) {
1116 TRACE("add CALLBACK!\n");
1117 toolPtr->lpszText = LPSTR_TEXTCALLBACKW;
1119 else {
1120 INT len = lstrlenW (lpToolInfo->lpszText);
1121 TRACE("add text %s!\n",
1122 debugstr_w(lpToolInfo->lpszText));
1123 toolPtr->lpszText = Alloc ((len + 1)*sizeof(WCHAR));
1124 strcpyW (toolPtr->lpszText, lpToolInfo->lpszText);
1128 if (lpToolInfo->cbSize >= sizeof(TTTOOLINFOW))
1129 toolPtr->lParam = lpToolInfo->lParam;
1131 /* install subclassing hook */
1132 if (toolPtr->uFlags & TTF_SUBCLASS) {
1133 if (toolPtr->uFlags & TTF_IDISHWND) {
1134 SetWindowSubclass((HWND)toolPtr->uId, TOOLTIPS_SubclassProc, 1,
1135 (DWORD_PTR)hwnd);
1137 else {
1138 SetWindowSubclass(toolPtr->hwnd, TOOLTIPS_SubclassProc, 1,
1139 (DWORD_PTR)hwnd);
1141 TRACE("subclassing installed!\n");
1144 nResult = (INT) SendMessageW (toolPtr->hwnd, WM_NOTIFYFORMAT,
1145 (WPARAM)hwnd, (LPARAM)NF_QUERY);
1146 if (nResult == NFR_ANSI) {
1147 toolPtr->bNotifyUnicode = FALSE;
1148 TRACE(" -- WM_NOTIFYFORMAT returns: NFR_ANSI\n");
1149 } else if (nResult == NFR_UNICODE) {
1150 toolPtr->bNotifyUnicode = TRUE;
1151 TRACE(" -- WM_NOTIFYFORMAT returns: NFR_UNICODE\n");
1152 } else {
1153 TRACE (" -- WM_NOTIFYFORMAT returns: error!\n");
1156 return TRUE;
1160 static void
1161 TOOLTIPS_DelToolCommon (HWND hwnd, TOOLTIPS_INFO *infoPtr, INT nTool)
1163 TTTOOL_INFO *toolPtr;
1165 TRACE("tool %d\n", nTool);
1167 if (nTool == -1)
1168 return;
1170 /* make sure the tooltip has disappeared before deleting it */
1171 TOOLTIPS_Hide(hwnd, infoPtr);
1173 /* delete text string */
1174 toolPtr = &infoPtr->tools[nTool];
1175 if (toolPtr->lpszText) {
1176 if ( (toolPtr->lpszText != LPSTR_TEXTCALLBACKW) &&
1177 !IS_INTRESOURCE(toolPtr->lpszText) )
1178 Free (toolPtr->lpszText);
1181 /* remove subclassing */
1182 if (toolPtr->uFlags & TTF_SUBCLASS) {
1183 if (toolPtr->uFlags & TTF_IDISHWND) {
1184 RemoveWindowSubclass((HWND)toolPtr->uId, TOOLTIPS_SubclassProc, 1);
1186 else {
1187 RemoveWindowSubclass(toolPtr->hwnd, TOOLTIPS_SubclassProc, 1);
1191 /* delete tool from tool list */
1192 if (infoPtr->uNumTools == 1) {
1193 Free (infoPtr->tools);
1194 infoPtr->tools = NULL;
1196 else {
1197 TTTOOL_INFO *oldTools = infoPtr->tools;
1198 infoPtr->tools =
1199 Alloc (sizeof(TTTOOL_INFO) * (infoPtr->uNumTools - 1));
1201 if (nTool > 0)
1202 memcpy (&infoPtr->tools[0], &oldTools[0],
1203 nTool * sizeof(TTTOOL_INFO));
1205 if (nTool < infoPtr->uNumTools - 1)
1206 memcpy (&infoPtr->tools[nTool], &oldTools[nTool + 1],
1207 (infoPtr->uNumTools - nTool - 1) * sizeof(TTTOOL_INFO));
1209 Free (oldTools);
1212 /* update any indices affected by delete */
1214 /* destroying tool that mouse was on on last relayed mouse move */
1215 if (infoPtr->nTool == nTool)
1216 /* -1 means no current tool (0 means first tool) */
1217 infoPtr->nTool = -1;
1218 else if (infoPtr->nTool > nTool)
1219 infoPtr->nTool--;
1221 if (infoPtr->nTrackTool == nTool)
1222 /* -1 means no current tool (0 means first tool) */
1223 infoPtr->nTrackTool = -1;
1224 else if (infoPtr->nTrackTool > nTool)
1225 infoPtr->nTrackTool--;
1227 if (infoPtr->nCurrentTool == nTool)
1228 /* -1 means no current tool (0 means first tool) */
1229 infoPtr->nCurrentTool = -1;
1230 else if (infoPtr->nCurrentTool > nTool)
1231 infoPtr->nCurrentTool--;
1233 infoPtr->uNumTools--;
1236 static LRESULT
1237 TOOLTIPS_DelToolA (HWND hwnd, WPARAM wParam, LPARAM lParam)
1239 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1240 LPTTTOOLINFOA lpToolInfo = (LPTTTOOLINFOA)lParam;
1241 INT nTool;
1243 if (lpToolInfo == NULL)
1244 return 0;
1245 if (lpToolInfo->cbSize < TTTOOLINFOA_V1_SIZE)
1246 return 0;
1247 if (infoPtr->uNumTools == 0)
1248 return 0;
1250 nTool = TOOLTIPS_GetToolFromInfoA (infoPtr, lpToolInfo);
1252 TOOLTIPS_DelToolCommon (hwnd, infoPtr, nTool);
1254 return 0;
1258 static LRESULT
1259 TOOLTIPS_DelToolW (HWND hwnd, WPARAM wParam, LPARAM lParam)
1261 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1262 LPTTTOOLINFOW lpToolInfo = (LPTTTOOLINFOW)lParam;
1263 INT nTool;
1265 if (lpToolInfo == NULL)
1266 return 0;
1267 if (lpToolInfo->cbSize < TTTOOLINFOW_V1_SIZE)
1268 return 0;
1269 if (infoPtr->uNumTools == 0)
1270 return 0;
1272 nTool = TOOLTIPS_GetToolFromInfoW (infoPtr, lpToolInfo);
1274 TOOLTIPS_DelToolCommon (hwnd, infoPtr, nTool);
1276 return 0;
1280 static LRESULT
1281 TOOLTIPS_EnumToolsA (HWND hwnd, WPARAM wParam, LPARAM lParam)
1283 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1284 UINT uIndex = (UINT)wParam;
1285 LPTTTOOLINFOA lpToolInfo = (LPTTTOOLINFOA)lParam;
1286 TTTOOL_INFO *toolPtr;
1288 if (lpToolInfo == NULL)
1289 return FALSE;
1290 if (lpToolInfo->cbSize < TTTOOLINFOA_V1_SIZE)
1291 return FALSE;
1292 if (uIndex >= infoPtr->uNumTools)
1293 return FALSE;
1295 TRACE("index=%u\n", uIndex);
1297 toolPtr = &infoPtr->tools[uIndex];
1299 /* copy tool data */
1300 lpToolInfo->uFlags = toolPtr->uFlags;
1301 lpToolInfo->hwnd = toolPtr->hwnd;
1302 lpToolInfo->uId = toolPtr->uId;
1303 lpToolInfo->rect = toolPtr->rect;
1304 lpToolInfo->hinst = toolPtr->hinst;
1305 /* lpToolInfo->lpszText = toolPtr->lpszText; */
1306 lpToolInfo->lpszText = NULL; /* FIXME */
1308 if (lpToolInfo->cbSize >= sizeof(TTTOOLINFOA))
1309 lpToolInfo->lParam = toolPtr->lParam;
1311 return TRUE;
1315 static LRESULT
1316 TOOLTIPS_EnumToolsW (HWND hwnd, WPARAM wParam, LPARAM lParam)
1318 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1319 UINT uIndex = (UINT)wParam;
1320 LPTTTOOLINFOW lpToolInfo = (LPTTTOOLINFOW)lParam;
1321 TTTOOL_INFO *toolPtr;
1323 if (lpToolInfo == NULL)
1324 return FALSE;
1325 if (lpToolInfo->cbSize < TTTOOLINFOW_V1_SIZE)
1326 return FALSE;
1327 if (uIndex >= infoPtr->uNumTools)
1328 return FALSE;
1330 TRACE("index=%u\n", uIndex);
1332 toolPtr = &infoPtr->tools[uIndex];
1334 /* copy tool data */
1335 lpToolInfo->uFlags = toolPtr->uFlags;
1336 lpToolInfo->hwnd = toolPtr->hwnd;
1337 lpToolInfo->uId = toolPtr->uId;
1338 lpToolInfo->rect = toolPtr->rect;
1339 lpToolInfo->hinst = toolPtr->hinst;
1340 /* lpToolInfo->lpszText = toolPtr->lpszText; */
1341 lpToolInfo->lpszText = NULL; /* FIXME */
1343 if (lpToolInfo->cbSize >= sizeof(TTTOOLINFOW))
1344 lpToolInfo->lParam = toolPtr->lParam;
1346 return TRUE;
1349 static LRESULT
1350 TOOLTIPS_GetBubbleSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
1352 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1353 LPTTTOOLINFOW lpToolInfo = (LPTTTOOLINFOW)lParam;
1354 INT nTool;
1355 SIZE size;
1357 if (lpToolInfo == NULL)
1358 return FALSE;
1359 if (lpToolInfo->cbSize < TTTOOLINFOW_V1_SIZE)
1360 return FALSE;
1362 nTool = TOOLTIPS_GetToolFromInfoW (infoPtr, lpToolInfo);
1363 if (nTool == -1) return 0;
1365 TRACE("tool %d\n", nTool);
1367 TOOLTIPS_CalcTipSize (hwnd, infoPtr, &size);
1368 TRACE("size %d x %d\n", size.cx, size.cy);
1370 return MAKELRESULT(size.cx, size.cy);
1373 static LRESULT
1374 TOOLTIPS_GetCurrentToolA (HWND hwnd, WPARAM wParam, LPARAM lParam)
1376 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1377 LPTTTOOLINFOA lpToolInfo = (LPTTTOOLINFOA)lParam;
1378 TTTOOL_INFO *toolPtr;
1380 if (lpToolInfo) {
1381 if (lpToolInfo->cbSize < TTTOOLINFOA_V1_SIZE)
1382 return FALSE;
1384 if (infoPtr->nCurrentTool > -1) {
1385 toolPtr = &infoPtr->tools[infoPtr->nCurrentTool];
1387 /* copy tool data */
1388 lpToolInfo->uFlags = toolPtr->uFlags;
1389 lpToolInfo->rect = toolPtr->rect;
1390 lpToolInfo->hinst = toolPtr->hinst;
1391 /* lpToolInfo->lpszText = toolPtr->lpszText; */
1392 lpToolInfo->lpszText = NULL; /* FIXME */
1394 if (lpToolInfo->cbSize >= sizeof(TTTOOLINFOA))
1395 lpToolInfo->lParam = toolPtr->lParam;
1397 return TRUE;
1399 else
1400 return FALSE;
1402 else
1403 return (infoPtr->nCurrentTool != -1);
1407 static LRESULT
1408 TOOLTIPS_GetCurrentToolW (HWND hwnd, WPARAM wParam, LPARAM lParam)
1410 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1411 LPTTTOOLINFOW lpToolInfo = (LPTTTOOLINFOW)lParam;
1412 TTTOOL_INFO *toolPtr;
1414 if (lpToolInfo) {
1415 if (lpToolInfo->cbSize < TTTOOLINFOW_V1_SIZE)
1416 return FALSE;
1418 if (infoPtr->nCurrentTool > -1) {
1419 toolPtr = &infoPtr->tools[infoPtr->nCurrentTool];
1421 /* copy tool data */
1422 lpToolInfo->uFlags = toolPtr->uFlags;
1423 lpToolInfo->rect = toolPtr->rect;
1424 lpToolInfo->hinst = toolPtr->hinst;
1425 /* lpToolInfo->lpszText = toolPtr->lpszText; */
1426 lpToolInfo->lpszText = NULL; /* FIXME */
1428 if (lpToolInfo->cbSize >= sizeof(TTTOOLINFOW))
1429 lpToolInfo->lParam = toolPtr->lParam;
1431 return TRUE;
1433 else
1434 return FALSE;
1436 else
1437 return (infoPtr->nCurrentTool != -1);
1441 static LRESULT
1442 TOOLTIPS_GetDelayTime (HWND hwnd, WPARAM wParam, LPARAM lParam)
1444 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1446 switch (wParam) {
1447 case TTDT_RESHOW:
1448 return infoPtr->nReshowTime;
1450 case TTDT_AUTOPOP:
1451 return infoPtr->nAutoPopTime;
1453 case TTDT_INITIAL:
1454 case TTDT_AUTOMATIC: /* Apparently TTDT_AUTOMATIC returns TTDT_INITIAL */
1455 return infoPtr->nInitialTime;
1457 default:
1458 WARN("Invalid wParam %lx\n", wParam);
1459 break;
1462 return -1;
1466 static LRESULT
1467 TOOLTIPS_GetMargin (HWND hwnd, WPARAM wParam, LPARAM lParam)
1469 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1470 LPRECT lpRect = (LPRECT)lParam;
1472 lpRect->left = infoPtr->rcMargin.left;
1473 lpRect->right = infoPtr->rcMargin.right;
1474 lpRect->bottom = infoPtr->rcMargin.bottom;
1475 lpRect->top = infoPtr->rcMargin.top;
1477 return 0;
1481 static inline LRESULT
1482 TOOLTIPS_GetMaxTipWidth (HWND hwnd, WPARAM wParam, LPARAM lParam)
1484 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1486 return infoPtr->nMaxTipWidth;
1490 static LRESULT
1491 TOOLTIPS_GetTextA (HWND hwnd, WPARAM wParam, LPARAM lParam)
1493 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1494 LPTTTOOLINFOA lpToolInfo = (LPTTTOOLINFOA)lParam;
1495 INT nTool;
1497 if (lpToolInfo == NULL)
1498 return 0;
1499 if (lpToolInfo->cbSize < TTTOOLINFOA_V1_SIZE)
1500 return 0;
1502 nTool = TOOLTIPS_GetToolFromInfoA (infoPtr, lpToolInfo);
1503 if (nTool == -1) return 0;
1505 /* NB this API is broken, there is no way for the app to determine
1506 what size buffer it requires nor a way to specify how long the
1507 one it supplies is. We'll assume it's up to INFOTIPSIZE */
1509 WideCharToMultiByte(CP_ACP, 0, infoPtr->tools[nTool].lpszText, -1,
1510 lpToolInfo->lpszText, INFOTIPSIZE, NULL, NULL);
1512 return 0;
1516 static LRESULT
1517 TOOLTIPS_GetTextW (HWND hwnd, WPARAM wParam, LPARAM lParam)
1519 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1520 LPTTTOOLINFOW lpToolInfo = (LPTTTOOLINFOW)lParam;
1521 INT nTool;
1523 if (lpToolInfo == NULL)
1524 return 0;
1525 if (lpToolInfo->cbSize < TTTOOLINFOW_V1_SIZE)
1526 return 0;
1528 nTool = TOOLTIPS_GetToolFromInfoW (infoPtr, lpToolInfo);
1529 if (nTool == -1) return 0;
1531 strcpyW (lpToolInfo->lpszText, infoPtr->tools[nTool].lpszText);
1533 return 0;
1537 static inline LRESULT
1538 TOOLTIPS_GetTipBkColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
1540 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1541 return infoPtr->clrBk;
1545 static inline LRESULT
1546 TOOLTIPS_GetTipTextColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
1548 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1549 return infoPtr->clrText;
1553 static inline LRESULT
1554 TOOLTIPS_GetToolCount (HWND hwnd, WPARAM wParam, LPARAM lParam)
1556 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1557 return infoPtr->uNumTools;
1561 static LRESULT
1562 TOOLTIPS_GetToolInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
1564 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1565 LPTTTOOLINFOA lpToolInfo = (LPTTTOOLINFOA)lParam;
1566 TTTOOL_INFO *toolPtr;
1567 INT nTool;
1569 if (lpToolInfo == NULL)
1570 return FALSE;
1571 if (lpToolInfo->cbSize < TTTOOLINFOA_V1_SIZE)
1572 return FALSE;
1573 if (infoPtr->uNumTools == 0)
1574 return FALSE;
1576 nTool = TOOLTIPS_GetToolFromInfoA (infoPtr, lpToolInfo);
1577 if (nTool == -1)
1578 return FALSE;
1580 TRACE("tool %d\n", nTool);
1582 toolPtr = &infoPtr->tools[nTool];
1584 /* copy tool data */
1585 lpToolInfo->uFlags = toolPtr->uFlags;
1586 lpToolInfo->rect = toolPtr->rect;
1587 lpToolInfo->hinst = toolPtr->hinst;
1588 /* lpToolInfo->lpszText = toolPtr->lpszText; */
1589 lpToolInfo->lpszText = NULL; /* FIXME */
1591 if (lpToolInfo->cbSize >= sizeof(TTTOOLINFOA))
1592 lpToolInfo->lParam = toolPtr->lParam;
1594 return TRUE;
1598 static LRESULT
1599 TOOLTIPS_GetToolInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
1601 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1602 LPTTTOOLINFOW lpToolInfo = (LPTTTOOLINFOW)lParam;
1603 TTTOOL_INFO *toolPtr;
1604 INT nTool;
1606 if (lpToolInfo == NULL)
1607 return FALSE;
1608 if (lpToolInfo->cbSize < TTTOOLINFOW_V1_SIZE)
1609 return FALSE;
1610 if (infoPtr->uNumTools == 0)
1611 return FALSE;
1613 nTool = TOOLTIPS_GetToolFromInfoW (infoPtr, lpToolInfo);
1614 if (nTool == -1)
1615 return FALSE;
1617 TRACE("tool %d\n", nTool);
1619 toolPtr = &infoPtr->tools[nTool];
1621 /* copy tool data */
1622 lpToolInfo->uFlags = toolPtr->uFlags;
1623 lpToolInfo->rect = toolPtr->rect;
1624 lpToolInfo->hinst = toolPtr->hinst;
1625 /* lpToolInfo->lpszText = toolPtr->lpszText; */
1626 lpToolInfo->lpszText = NULL; /* FIXME */
1628 if (lpToolInfo->cbSize >= sizeof(TTTOOLINFOW))
1629 lpToolInfo->lParam = toolPtr->lParam;
1631 return TRUE;
1635 static LRESULT
1636 TOOLTIPS_HitTestA (HWND hwnd, WPARAM wParam, LPARAM lParam)
1638 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1639 LPTTHITTESTINFOA lptthit = (LPTTHITTESTINFOA)lParam;
1640 TTTOOL_INFO *toolPtr;
1641 INT nTool;
1643 if (lptthit == 0)
1644 return FALSE;
1646 nTool = TOOLTIPS_GetToolFromPoint (infoPtr, lptthit->hwnd, &lptthit->pt);
1647 if (nTool == -1)
1648 return FALSE;
1650 TRACE("tool %d!\n", nTool);
1652 /* copy tool data */
1653 if (lptthit->ti.cbSize >= sizeof(TTTOOLINFOA)) {
1654 toolPtr = &infoPtr->tools[nTool];
1656 lptthit->ti.uFlags = toolPtr->uFlags;
1657 lptthit->ti.hwnd = toolPtr->hwnd;
1658 lptthit->ti.uId = toolPtr->uId;
1659 lptthit->ti.rect = toolPtr->rect;
1660 lptthit->ti.hinst = toolPtr->hinst;
1661 /* lptthit->ti.lpszText = toolPtr->lpszText; */
1662 lptthit->ti.lpszText = NULL; /* FIXME */
1663 lptthit->ti.lParam = toolPtr->lParam;
1666 return TRUE;
1670 static LRESULT
1671 TOOLTIPS_HitTestW (HWND hwnd, WPARAM wParam, LPARAM lParam)
1673 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1674 LPTTHITTESTINFOW lptthit = (LPTTHITTESTINFOW)lParam;
1675 TTTOOL_INFO *toolPtr;
1676 INT nTool;
1678 if (lptthit == 0)
1679 return FALSE;
1681 nTool = TOOLTIPS_GetToolFromPoint (infoPtr, lptthit->hwnd, &lptthit->pt);
1682 if (nTool == -1)
1683 return FALSE;
1685 TRACE("tool %d!\n", nTool);
1687 /* copy tool data */
1688 if (lptthit->ti.cbSize >= sizeof(TTTOOLINFOW)) {
1689 toolPtr = &infoPtr->tools[nTool];
1691 lptthit->ti.uFlags = toolPtr->uFlags;
1692 lptthit->ti.hwnd = toolPtr->hwnd;
1693 lptthit->ti.uId = toolPtr->uId;
1694 lptthit->ti.rect = toolPtr->rect;
1695 lptthit->ti.hinst = toolPtr->hinst;
1696 /* lptthit->ti.lpszText = toolPtr->lpszText; */
1697 lptthit->ti.lpszText = NULL; /* FIXME */
1698 lptthit->ti.lParam = toolPtr->lParam;
1701 return TRUE;
1705 static LRESULT
1706 TOOLTIPS_NewToolRectA (HWND hwnd, WPARAM wParam, LPARAM lParam)
1708 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1709 LPTTTOOLINFOA lpti = (LPTTTOOLINFOA)lParam;
1710 INT nTool;
1712 if (lpti == NULL)
1713 return 0;
1714 if (lpti->cbSize < TTTOOLINFOA_V1_SIZE)
1715 return FALSE;
1717 nTool = TOOLTIPS_GetToolFromInfoA (infoPtr, lpti);
1719 TRACE("nTool = %d, rect = %s\n", nTool, wine_dbgstr_rect(&lpti->rect));
1721 if (nTool == -1) return 0;
1723 infoPtr->tools[nTool].rect = lpti->rect;
1725 return 0;
1729 static LRESULT
1730 TOOLTIPS_NewToolRectW (HWND hwnd, WPARAM wParam, LPARAM lParam)
1732 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1733 LPTTTOOLINFOW lpti = (LPTTTOOLINFOW)lParam;
1734 INT nTool;
1736 if (lpti == NULL)
1737 return 0;
1738 if (lpti->cbSize < TTTOOLINFOW_V1_SIZE)
1739 return FALSE;
1741 nTool = TOOLTIPS_GetToolFromInfoW (infoPtr, lpti);
1743 TRACE("nTool = %d, rect = %s\n", nTool, wine_dbgstr_rect(&lpti->rect));
1745 if (nTool == -1) return 0;
1747 infoPtr->tools[nTool].rect = lpti->rect;
1749 return 0;
1753 static inline LRESULT
1754 TOOLTIPS_Pop (HWND hwnd, WPARAM wParam, LPARAM lParam)
1756 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1757 TOOLTIPS_Hide (hwnd, infoPtr);
1759 return 0;
1763 static LRESULT
1764 TOOLTIPS_RelayEvent (HWND hwnd, WPARAM wParam, LPARAM lParam)
1766 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1767 LPMSG lpMsg = (LPMSG)lParam;
1768 POINT pt;
1769 INT nOldTool;
1771 if (lParam == 0) {
1772 ERR("lpMsg == NULL!\n");
1773 return 0;
1776 switch (lpMsg->message) {
1777 case WM_LBUTTONDOWN:
1778 case WM_LBUTTONUP:
1779 case WM_MBUTTONDOWN:
1780 case WM_MBUTTONUP:
1781 case WM_RBUTTONDOWN:
1782 case WM_RBUTTONUP:
1783 TOOLTIPS_Hide (hwnd, infoPtr);
1784 break;
1786 case WM_MOUSEMOVE:
1787 pt.x = (short)LOWORD(lpMsg->lParam);
1788 pt.y = (short)HIWORD(lpMsg->lParam);
1789 nOldTool = infoPtr->nTool;
1790 infoPtr->nTool = TOOLTIPS_GetToolFromPoint(infoPtr, lpMsg->hwnd,
1791 &pt);
1792 TRACE("tool (%p) %d %d %d\n", hwnd, nOldTool,
1793 infoPtr->nTool, infoPtr->nCurrentTool);
1794 TRACE("WM_MOUSEMOVE (%p %d %d)\n", hwnd, pt.x, pt.y);
1796 if (infoPtr->nTool != nOldTool) {
1797 if(infoPtr->nTool == -1) { /* Moved out of all tools */
1798 TOOLTIPS_Hide(hwnd, infoPtr);
1799 KillTimer(hwnd, ID_TIMERLEAVE);
1800 } else if (nOldTool == -1) { /* Moved from outside */
1801 if(infoPtr->bActive) {
1802 SetTimer(hwnd, ID_TIMERSHOW, infoPtr->nInitialTime, 0);
1803 TRACE("timer 1 started!\n");
1805 } else { /* Moved from one to another */
1806 TOOLTIPS_Hide (hwnd, infoPtr);
1807 KillTimer(hwnd, ID_TIMERLEAVE);
1808 if(infoPtr->bActive) {
1809 SetTimer (hwnd, ID_TIMERSHOW, infoPtr->nReshowTime, 0);
1810 TRACE("timer 1 started!\n");
1813 } else if(infoPtr->nCurrentTool != -1) { /* restart autopop */
1814 KillTimer(hwnd, ID_TIMERPOP);
1815 SetTimer(hwnd, ID_TIMERPOP, infoPtr->nAutoPopTime, 0);
1816 TRACE("timer 2 restarted\n");
1817 } else if(infoPtr->nTool != -1 && infoPtr->bActive) {
1818 /* previous show attempt didn't result in tooltip so try again */
1819 SetTimer(hwnd, ID_TIMERSHOW, infoPtr->nInitialTime, 0);
1820 TRACE("timer 1 started!\n");
1822 break;
1825 return 0;
1829 static LRESULT
1830 TOOLTIPS_SetDelayTime (HWND hwnd, WPARAM wParam, LPARAM lParam)
1832 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1833 INT nTime = (INT)LOWORD(lParam);
1835 switch (wParam) {
1836 case TTDT_AUTOMATIC:
1837 if (nTime <= 0)
1838 nTime = GetDoubleClickTime();
1839 infoPtr->nReshowTime = nTime / 5;
1840 infoPtr->nAutoPopTime = nTime * 10;
1841 infoPtr->nInitialTime = nTime;
1842 break;
1844 case TTDT_RESHOW:
1845 if(nTime < 0)
1846 nTime = GetDoubleClickTime() / 5;
1847 infoPtr->nReshowTime = nTime;
1848 break;
1850 case TTDT_AUTOPOP:
1851 if(nTime < 0)
1852 nTime = GetDoubleClickTime() * 10;
1853 infoPtr->nAutoPopTime = nTime;
1854 break;
1856 case TTDT_INITIAL:
1857 if(nTime < 0)
1858 nTime = GetDoubleClickTime();
1859 infoPtr->nInitialTime = nTime;
1860 break;
1862 default:
1863 WARN("Invalid wParam %lx\n", wParam);
1864 break;
1867 return 0;
1871 static LRESULT
1872 TOOLTIPS_SetMargin (HWND hwnd, WPARAM wParam, LPARAM lParam)
1874 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1875 LPRECT lpRect = (LPRECT)lParam;
1877 infoPtr->rcMargin.left = lpRect->left;
1878 infoPtr->rcMargin.right = lpRect->right;
1879 infoPtr->rcMargin.bottom = lpRect->bottom;
1880 infoPtr->rcMargin.top = lpRect->top;
1882 return 0;
1886 static inline LRESULT
1887 TOOLTIPS_SetMaxTipWidth (HWND hwnd, WPARAM wParam, LPARAM lParam)
1889 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1890 INT nTemp = infoPtr->nMaxTipWidth;
1892 infoPtr->nMaxTipWidth = (INT)lParam;
1894 return nTemp;
1898 static inline LRESULT
1899 TOOLTIPS_SetTipBkColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
1901 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1903 infoPtr->clrBk = (COLORREF)wParam;
1905 return 0;
1909 static inline LRESULT
1910 TOOLTIPS_SetTipTextColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
1912 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1914 infoPtr->clrText = (COLORREF)wParam;
1916 return 0;
1920 static LRESULT
1921 TOOLTIPS_SetTitleA (HWND hwnd, WPARAM wParam, LPARAM lParam)
1923 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1924 LPCSTR pszTitle = (LPCSTR)lParam;
1925 UINT_PTR uTitleIcon = (UINT_PTR)wParam;
1926 UINT size;
1928 TRACE("hwnd = %p, title = %s, icon = %p\n", hwnd, debugstr_a(pszTitle),
1929 (void*)uTitleIcon);
1931 Free(infoPtr->pszTitle);
1933 if (pszTitle)
1935 size = sizeof(WCHAR)*MultiByteToWideChar(CP_ACP, 0, pszTitle, -1, NULL, 0);
1936 infoPtr->pszTitle = Alloc(size);
1937 if (!infoPtr->pszTitle)
1938 return FALSE;
1939 MultiByteToWideChar(CP_ACP, 0, pszTitle, -1, infoPtr->pszTitle, size/sizeof(WCHAR));
1941 else
1942 infoPtr->pszTitle = NULL;
1944 if (uTitleIcon <= TTI_ERROR)
1945 infoPtr->hTitleIcon = hTooltipIcons[uTitleIcon];
1946 else
1947 infoPtr->hTitleIcon = CopyIcon((HICON)wParam);
1949 return TRUE;
1953 static LRESULT
1954 TOOLTIPS_SetTitleW (HWND hwnd, WPARAM wParam, LPARAM lParam)
1956 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1957 LPCWSTR pszTitle = (LPCWSTR)lParam;
1958 UINT_PTR uTitleIcon = (UINT_PTR)wParam;
1959 UINT size;
1961 TRACE("hwnd = %p, title = %s, icon = %p\n", hwnd, debugstr_w(pszTitle),
1962 (void*)uTitleIcon);
1964 Free(infoPtr->pszTitle);
1966 if (pszTitle)
1968 size = (strlenW(pszTitle)+1)*sizeof(WCHAR);
1969 infoPtr->pszTitle = Alloc(size);
1970 if (!infoPtr->pszTitle)
1971 return FALSE;
1972 memcpy(infoPtr->pszTitle, pszTitle, size);
1974 else
1975 infoPtr->pszTitle = NULL;
1977 if (uTitleIcon <= TTI_ERROR)
1978 infoPtr->hTitleIcon = hTooltipIcons[uTitleIcon];
1979 else
1980 infoPtr->hTitleIcon = CopyIcon((HICON)wParam);
1982 TRACE("icon = %p\n", infoPtr->hTitleIcon);
1984 return TRUE;
1988 static LRESULT
1989 TOOLTIPS_SetToolInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
1991 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1992 LPTTTOOLINFOA lpToolInfo = (LPTTTOOLINFOA)lParam;
1993 TTTOOL_INFO *toolPtr;
1994 INT nTool;
1996 if (lpToolInfo == NULL)
1997 return 0;
1998 if (lpToolInfo->cbSize < TTTOOLINFOA_V1_SIZE)
1999 return 0;
2001 nTool = TOOLTIPS_GetToolFromInfoA (infoPtr, lpToolInfo);
2002 if (nTool == -1) return 0;
2004 TRACE("tool %d\n", nTool);
2006 toolPtr = &infoPtr->tools[nTool];
2008 /* copy tool data */
2009 toolPtr->uFlags = lpToolInfo->uFlags;
2010 toolPtr->hwnd = lpToolInfo->hwnd;
2011 toolPtr->uId = lpToolInfo->uId;
2012 toolPtr->rect = lpToolInfo->rect;
2013 toolPtr->hinst = lpToolInfo->hinst;
2015 if (IS_INTRESOURCE(lpToolInfo->lpszText)) {
2016 TRACE("set string id %x\n", LOWORD(lpToolInfo->lpszText));
2017 toolPtr->lpszText = (LPWSTR)lpToolInfo->lpszText;
2019 else if (lpToolInfo->lpszText) {
2020 if (lpToolInfo->lpszText == LPSTR_TEXTCALLBACKA)
2021 toolPtr->lpszText = LPSTR_TEXTCALLBACKW;
2022 else {
2023 if ( (toolPtr->lpszText) &&
2024 !IS_INTRESOURCE(toolPtr->lpszText) ) {
2025 if( toolPtr->lpszText != LPSTR_TEXTCALLBACKW)
2026 Free (toolPtr->lpszText);
2027 toolPtr->lpszText = NULL;
2029 if (lpToolInfo->lpszText) {
2030 INT len = MultiByteToWideChar(CP_ACP, 0, lpToolInfo->lpszText,
2031 -1, NULL, 0);
2032 toolPtr->lpszText = Alloc (len * sizeof(WCHAR));
2033 MultiByteToWideChar(CP_ACP, 0, lpToolInfo->lpszText, -1,
2034 toolPtr->lpszText, len);
2039 if (lpToolInfo->cbSize >= sizeof(TTTOOLINFOA))
2040 toolPtr->lParam = lpToolInfo->lParam;
2042 return 0;
2046 static LRESULT
2047 TOOLTIPS_SetToolInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
2049 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
2050 LPTTTOOLINFOW lpToolInfo = (LPTTTOOLINFOW)lParam;
2051 TTTOOL_INFO *toolPtr;
2052 INT nTool;
2054 if (lpToolInfo == NULL)
2055 return 0;
2056 if (lpToolInfo->cbSize < TTTOOLINFOW_V1_SIZE)
2057 return 0;
2059 nTool = TOOLTIPS_GetToolFromInfoW (infoPtr, lpToolInfo);
2060 if (nTool == -1) return 0;
2062 TRACE("tool %d\n", nTool);
2064 toolPtr = &infoPtr->tools[nTool];
2066 /* copy tool data */
2067 toolPtr->uFlags = lpToolInfo->uFlags;
2068 toolPtr->hwnd = lpToolInfo->hwnd;
2069 toolPtr->uId = lpToolInfo->uId;
2070 toolPtr->rect = lpToolInfo->rect;
2071 toolPtr->hinst = lpToolInfo->hinst;
2073 if (IS_INTRESOURCE(lpToolInfo->lpszText)) {
2074 TRACE("set string id %x!\n", LOWORD(lpToolInfo->lpszText));
2075 toolPtr->lpszText = lpToolInfo->lpszText;
2077 else {
2078 if (lpToolInfo->lpszText == LPSTR_TEXTCALLBACKW)
2079 toolPtr->lpszText = LPSTR_TEXTCALLBACKW;
2080 else {
2081 if ( (toolPtr->lpszText) &&
2082 !IS_INTRESOURCE(toolPtr->lpszText) ) {
2083 if( toolPtr->lpszText != LPSTR_TEXTCALLBACKW)
2084 Free (toolPtr->lpszText);
2085 toolPtr->lpszText = NULL;
2087 if (lpToolInfo->lpszText) {
2088 INT len = lstrlenW (lpToolInfo->lpszText);
2089 toolPtr->lpszText = Alloc ((len+1)*sizeof(WCHAR));
2090 strcpyW (toolPtr->lpszText, lpToolInfo->lpszText);
2095 if (lpToolInfo->cbSize >= sizeof(TTTOOLINFOW))
2096 toolPtr->lParam = lpToolInfo->lParam;
2098 if (infoPtr->nCurrentTool == nTool)
2100 TOOLTIPS_GetTipText (hwnd, infoPtr, infoPtr->nCurrentTool);
2102 if (infoPtr->szTipText[0] == 0)
2103 TOOLTIPS_Hide(hwnd, infoPtr);
2104 else
2105 TOOLTIPS_Show (hwnd, infoPtr, FALSE);
2108 return 0;
2112 static LRESULT
2113 TOOLTIPS_TrackActivate (HWND hwnd, WPARAM wParam, LPARAM lParam)
2115 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
2117 if ((BOOL)wParam) {
2118 LPTTTOOLINFOA lpToolInfo = (LPTTTOOLINFOA)lParam;
2120 if (lpToolInfo == NULL)
2121 return 0;
2122 if (lpToolInfo->cbSize < TTTOOLINFOA_V1_SIZE)
2123 return FALSE;
2125 /* activate */
2126 infoPtr->nTrackTool = TOOLTIPS_GetToolFromInfoA (infoPtr, lpToolInfo);
2127 if (infoPtr->nTrackTool != -1) {
2128 TRACE("activated!\n");
2129 infoPtr->bTrackActive = TRUE;
2130 TOOLTIPS_TrackShow (hwnd, infoPtr);
2133 else {
2134 /* deactivate */
2135 TOOLTIPS_TrackHide (hwnd, infoPtr);
2137 infoPtr->bTrackActive = FALSE;
2138 infoPtr->nTrackTool = -1;
2140 TRACE("deactivated!\n");
2143 return 0;
2147 static LRESULT
2148 TOOLTIPS_TrackPosition (HWND hwnd, WPARAM wParam, LPARAM lParam)
2150 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
2152 infoPtr->xTrackPos = (INT)LOWORD(lParam);
2153 infoPtr->yTrackPos = (INT)HIWORD(lParam);
2155 if (infoPtr->bTrackActive) {
2156 TRACE("[%d %d]\n",
2157 infoPtr->xTrackPos, infoPtr->yTrackPos);
2159 TOOLTIPS_TrackShow (hwnd, infoPtr);
2162 return 0;
2166 static LRESULT
2167 TOOLTIPS_Update (HWND hwnd, WPARAM wParam, LPARAM lParam)
2169 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
2171 if (infoPtr->nCurrentTool != -1)
2172 UpdateWindow (hwnd);
2174 return 0;
2178 static LRESULT
2179 TOOLTIPS_UpdateTipTextA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2181 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
2182 LPTTTOOLINFOA lpToolInfo = (LPTTTOOLINFOA)lParam;
2183 TTTOOL_INFO *toolPtr;
2184 INT nTool;
2186 if (lpToolInfo == NULL)
2187 return 0;
2188 if (lpToolInfo->cbSize < TTTOOLINFOA_V1_SIZE)
2189 return FALSE;
2191 nTool = TOOLTIPS_GetToolFromInfoA (infoPtr, lpToolInfo);
2192 if (nTool == -1) return 0;
2194 TRACE("tool %d\n", nTool);
2196 toolPtr = &infoPtr->tools[nTool];
2198 /* copy tool text */
2199 toolPtr->hinst = lpToolInfo->hinst;
2201 if (IS_INTRESOURCE(lpToolInfo->lpszText)){
2202 toolPtr->lpszText = (LPWSTR)lpToolInfo->lpszText;
2204 else if (lpToolInfo->lpszText) {
2205 if (lpToolInfo->lpszText == LPSTR_TEXTCALLBACKA)
2206 toolPtr->lpszText = LPSTR_TEXTCALLBACKW;
2207 else {
2208 if ( (toolPtr->lpszText) &&
2209 !IS_INTRESOURCE(toolPtr->lpszText) ) {
2210 if( toolPtr->lpszText != LPSTR_TEXTCALLBACKW)
2211 Free (toolPtr->lpszText);
2212 toolPtr->lpszText = NULL;
2214 if (lpToolInfo->lpszText) {
2215 INT len = MultiByteToWideChar(CP_ACP, 0, lpToolInfo->lpszText,
2216 -1, NULL, 0);
2217 toolPtr->lpszText = Alloc (len * sizeof(WCHAR));
2218 MultiByteToWideChar(CP_ACP, 0, lpToolInfo->lpszText, -1,
2219 toolPtr->lpszText, len);
2224 if(infoPtr->nCurrentTool == -1) return 0;
2225 /* force repaint */
2226 if (infoPtr->bActive)
2227 TOOLTIPS_Show (hwnd, infoPtr, FALSE);
2228 else if (infoPtr->bTrackActive)
2229 TOOLTIPS_TrackShow (hwnd, infoPtr);
2231 return 0;
2235 static LRESULT
2236 TOOLTIPS_UpdateTipTextW (HWND hwnd, WPARAM wParam, LPARAM lParam)
2238 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
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 (hwnd, infoPtr, FALSE);
2284 else if (infoPtr->bTrackActive)
2285 TOOLTIPS_Show (hwnd, 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 = (TOOLTIPS_INFO *)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;
2317 /* initialize colours and fonts */
2318 TOOLTIPS_InitSystemSettings(infoPtr);
2320 TOOLTIPS_SetDelayTime(hwnd, TTDT_AUTOMATIC, 0L);
2322 SetWindowPos (hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOZORDER | SWP_HIDEWINDOW | SWP_NOACTIVATE);
2324 return 0;
2328 static LRESULT
2329 TOOLTIPS_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
2331 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
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 Free (infoPtr);
2373 SetWindowLongPtrW(hwnd, 0, 0);
2374 return 0;
2378 static LRESULT
2379 TOOLTIPS_GetFont (HWND hwnd, WPARAM wParam, LPARAM lParam)
2381 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
2383 return (LRESULT)infoPtr->hFont;
2387 static LRESULT
2388 TOOLTIPS_MouseMessage (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2390 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
2392 TOOLTIPS_Hide (hwnd, infoPtr);
2394 return 0;
2398 static LRESULT
2399 TOOLTIPS_NCCreate (HWND hwnd, WPARAM wParam, LPARAM lParam)
2401 DWORD dwStyle = GetWindowLongW (hwnd, GWL_STYLE);
2402 DWORD dwExStyle = GetWindowLongW (hwnd, GWL_EXSTYLE);
2404 dwStyle &= ~(WS_CHILD | /*WS_MAXIMIZE |*/ WS_BORDER | WS_DLGFRAME);
2405 dwStyle |= (WS_POPUP | WS_BORDER | WS_CLIPSIBLINGS);
2407 /* WS_BORDER only draws a border round the window rect, not the
2408 * window region, therefore it is useless to us in balloon mode */
2409 if (dwStyle & TTS_BALLOON) dwStyle &= ~WS_BORDER;
2411 SetWindowLongW (hwnd, GWL_STYLE, dwStyle);
2413 dwExStyle |= WS_EX_TOOLWINDOW;
2414 SetWindowLongW (hwnd, GWL_EXSTYLE, dwExStyle);
2416 return TRUE;
2420 static LRESULT
2421 TOOLTIPS_NCHitTest (HWND hwnd, WPARAM wParam, LPARAM lParam)
2423 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
2424 INT nTool = (infoPtr->bTrackActive) ? infoPtr->nTrackTool : infoPtr->nTool;
2426 TRACE(" nTool=%d\n", nTool);
2428 if ((nTool > -1) && (nTool < infoPtr->uNumTools)) {
2429 if (infoPtr->tools[nTool].uFlags & TTF_TRANSPARENT) {
2430 TRACE("-- in transparent mode!\n");
2431 return HTTRANSPARENT;
2435 return DefWindowProcW (hwnd, WM_NCHITTEST, wParam, lParam);
2439 static LRESULT
2440 TOOLTIPS_NotifyFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
2442 FIXME ("hwnd=%p wParam=%lx lParam=%lx\n", hwnd, wParam, lParam);
2444 return 0;
2448 static LRESULT
2449 TOOLTIPS_Paint (HWND hwnd, WPARAM wParam, LPARAM lParam)
2451 HDC hdc;
2452 PAINTSTRUCT ps;
2454 hdc = (wParam == 0) ? BeginPaint (hwnd, &ps) : (HDC)wParam;
2455 TOOLTIPS_Refresh (hwnd, hdc);
2456 if (!wParam)
2457 EndPaint (hwnd, &ps);
2458 return 0;
2462 static LRESULT
2463 TOOLTIPS_SetFont (HWND hwnd, WPARAM wParam, LPARAM lParam)
2465 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
2466 LOGFONTW lf;
2468 if(!GetObjectW((HFONT)wParam, sizeof(lf), &lf))
2469 return 0;
2471 DeleteObject (infoPtr->hFont);
2472 infoPtr->hFont = CreateFontIndirectW(&lf);
2474 DeleteObject (infoPtr->hTitleFont);
2475 lf.lfWeight = FW_BOLD;
2476 infoPtr->hTitleFont = CreateFontIndirectW(&lf);
2478 if ((LOWORD(lParam)) & (infoPtr->nCurrentTool != -1)) {
2479 FIXME("full redraw needed!\n");
2482 return 0;
2485 /******************************************************************
2486 * TOOLTIPS_GetTextLength
2488 * This function is called when the tooltip receive a
2489 * WM_GETTEXTLENGTH message.
2490 * wParam : not used
2491 * lParam : not used
2493 * returns the length, in characters, of the tip text
2495 static LRESULT
2496 TOOLTIPS_GetTextLength(HWND hwnd, WPARAM wParam, LPARAM lParam)
2498 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
2499 return strlenW(infoPtr->szTipText);
2502 /******************************************************************
2503 * TOOLTIPS_OnWMGetText
2505 * This function is called when the tooltip receive a
2506 * WM_GETTEXT message.
2507 * wParam : specifies the maximum number of characters to be copied
2508 * lParam : is the pointer to the buffer that will receive
2509 * the tip text
2511 * returns the number of characters copied
2513 static LRESULT
2514 TOOLTIPS_OnWMGetText (HWND hwnd, WPARAM wParam, LPARAM lParam)
2516 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
2517 LRESULT res;
2518 LPWSTR pszText = (LPWSTR)lParam;
2520 if(!infoPtr->szTipText || !wParam)
2521 return 0;
2523 res = min(strlenW(infoPtr->szTipText)+1, wParam);
2524 memcpy(pszText, infoPtr->szTipText, res*sizeof(WCHAR));
2525 pszText[res-1] = '\0';
2526 return res-1;
2529 static LRESULT
2530 TOOLTIPS_Timer (HWND hwnd, WPARAM wParam, LPARAM lParam)
2532 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
2533 INT nOldTool;
2535 TRACE("timer %ld (%p) expired!\n", wParam, hwnd);
2537 switch (wParam) {
2538 case ID_TIMERSHOW:
2539 KillTimer (hwnd, ID_TIMERSHOW);
2540 nOldTool = infoPtr->nTool;
2541 if ((infoPtr->nTool = TOOLTIPS_CheckTool (hwnd, TRUE)) == nOldTool)
2542 TOOLTIPS_Show (hwnd, infoPtr, FALSE);
2543 break;
2545 case ID_TIMERPOP:
2546 TOOLTIPS_Hide (hwnd, infoPtr);
2547 break;
2549 case ID_TIMERLEAVE:
2550 nOldTool = infoPtr->nTool;
2551 infoPtr->nTool = TOOLTIPS_CheckTool (hwnd, FALSE);
2552 TRACE("tool (%p) %d %d %d\n", hwnd, nOldTool,
2553 infoPtr->nTool, infoPtr->nCurrentTool);
2554 if (infoPtr->nTool != nOldTool) {
2555 if(infoPtr->nTool == -1) { /* Moved out of all tools */
2556 TOOLTIPS_Hide(hwnd, infoPtr);
2557 KillTimer(hwnd, ID_TIMERLEAVE);
2558 } else if (nOldTool == -1) { /* Moved from outside */
2559 ERR("How did this happen?\n");
2560 } else { /* Moved from one to another */
2561 TOOLTIPS_Hide (hwnd, infoPtr);
2562 KillTimer(hwnd, ID_TIMERLEAVE);
2563 if(infoPtr->bActive) {
2564 SetTimer (hwnd, ID_TIMERSHOW, infoPtr->nReshowTime, 0);
2565 TRACE("timer 1 started!\n");
2569 break;
2571 default:
2572 ERR("Unknown timer id %ld\n", wParam);
2573 break;
2575 return 0;
2579 static LRESULT
2580 TOOLTIPS_WinIniChange (HWND hwnd, WPARAM wParam, LPARAM lParam)
2582 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
2584 TOOLTIPS_InitSystemSettings (infoPtr);
2586 return 0;
2590 static LRESULT CALLBACK
2591 TOOLTIPS_SubclassProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uID, DWORD_PTR dwRef)
2593 MSG msg;
2595 switch(uMsg) {
2596 case WM_MOUSEMOVE:
2597 case WM_LBUTTONDOWN:
2598 case WM_LBUTTONUP:
2599 case WM_MBUTTONDOWN:
2600 case WM_MBUTTONUP:
2601 case WM_RBUTTONDOWN:
2602 case WM_RBUTTONUP:
2603 msg.hwnd = hwnd;
2604 msg.message = uMsg;
2605 msg.wParam = wParam;
2606 msg.lParam = lParam;
2607 TOOLTIPS_RelayEvent((HWND)dwRef, 0, (LPARAM)&msg);
2608 break;
2610 default:
2611 break;
2613 return DefSubclassProc(hwnd, uMsg, wParam, lParam);
2617 static LRESULT CALLBACK
2618 TOOLTIPS_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2620 TRACE("hwnd=%p msg=%x wparam=%lx lParam=%lx\n", hwnd, uMsg, wParam, lParam);
2621 if (!TOOLTIPS_GetInfoPtr(hwnd) && (uMsg != WM_CREATE) && (uMsg != WM_NCCREATE))
2622 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
2623 switch (uMsg)
2625 case TTM_ACTIVATE:
2626 return TOOLTIPS_Activate (hwnd, wParam, lParam);
2628 case TTM_ADDTOOLA:
2629 return TOOLTIPS_AddToolA (hwnd, wParam, lParam);
2631 case TTM_ADDTOOLW:
2632 return TOOLTIPS_AddToolW (hwnd, wParam, lParam);
2634 case TTM_DELTOOLA:
2635 return TOOLTIPS_DelToolA (hwnd, wParam, lParam);
2637 case TTM_DELTOOLW:
2638 return TOOLTIPS_DelToolW (hwnd, wParam, lParam);
2640 case TTM_ENUMTOOLSA:
2641 return TOOLTIPS_EnumToolsA (hwnd, wParam, lParam);
2643 case TTM_ENUMTOOLSW:
2644 return TOOLTIPS_EnumToolsW (hwnd, wParam, lParam);
2646 case TTM_GETBUBBLESIZE:
2647 return TOOLTIPS_GetBubbleSize (hwnd, wParam, lParam);
2649 case TTM_GETCURRENTTOOLA:
2650 return TOOLTIPS_GetCurrentToolA (hwnd, wParam, lParam);
2652 case TTM_GETCURRENTTOOLW:
2653 return TOOLTIPS_GetCurrentToolW (hwnd, wParam, lParam);
2655 case TTM_GETDELAYTIME:
2656 return TOOLTIPS_GetDelayTime (hwnd, wParam, lParam);
2658 case TTM_GETMARGIN:
2659 return TOOLTIPS_GetMargin (hwnd, wParam, lParam);
2661 case TTM_GETMAXTIPWIDTH:
2662 return TOOLTIPS_GetMaxTipWidth (hwnd, wParam, lParam);
2664 case TTM_GETTEXTA:
2665 return TOOLTIPS_GetTextA (hwnd, wParam, lParam);
2667 case TTM_GETTEXTW:
2668 return TOOLTIPS_GetTextW (hwnd, wParam, lParam);
2670 case TTM_GETTIPBKCOLOR:
2671 return TOOLTIPS_GetTipBkColor (hwnd, wParam, lParam);
2673 case TTM_GETTIPTEXTCOLOR:
2674 return TOOLTIPS_GetTipTextColor (hwnd, wParam, lParam);
2676 case TTM_GETTOOLCOUNT:
2677 return TOOLTIPS_GetToolCount (hwnd, wParam, lParam);
2679 case TTM_GETTOOLINFOA:
2680 return TOOLTIPS_GetToolInfoA (hwnd, wParam, lParam);
2682 case TTM_GETTOOLINFOW:
2683 return TOOLTIPS_GetToolInfoW (hwnd, wParam, lParam);
2685 case TTM_HITTESTA:
2686 return TOOLTIPS_HitTestA (hwnd, wParam, lParam);
2688 case TTM_HITTESTW:
2689 return TOOLTIPS_HitTestW (hwnd, wParam, lParam);
2691 case TTM_NEWTOOLRECTA:
2692 return TOOLTIPS_NewToolRectA (hwnd, wParam, lParam);
2694 case TTM_NEWTOOLRECTW:
2695 return TOOLTIPS_NewToolRectW (hwnd, wParam, lParam);
2697 case TTM_POP:
2698 return TOOLTIPS_Pop (hwnd, wParam, lParam);
2700 case TTM_RELAYEVENT:
2701 return TOOLTIPS_RelayEvent (hwnd, wParam, lParam);
2703 case TTM_SETDELAYTIME:
2704 return TOOLTIPS_SetDelayTime (hwnd, wParam, lParam);
2706 case TTM_SETMARGIN:
2707 return TOOLTIPS_SetMargin (hwnd, wParam, lParam);
2709 case TTM_SETMAXTIPWIDTH:
2710 return TOOLTIPS_SetMaxTipWidth (hwnd, wParam, lParam);
2712 case TTM_SETTIPBKCOLOR:
2713 return TOOLTIPS_SetTipBkColor (hwnd, wParam, lParam);
2715 case TTM_SETTIPTEXTCOLOR:
2716 return TOOLTIPS_SetTipTextColor (hwnd, wParam, lParam);
2718 case TTM_SETTITLEA:
2719 return TOOLTIPS_SetTitleA (hwnd, wParam, lParam);
2721 case TTM_SETTITLEW:
2722 return TOOLTIPS_SetTitleW (hwnd, wParam, lParam);
2724 case TTM_SETTOOLINFOA:
2725 return TOOLTIPS_SetToolInfoA (hwnd, wParam, lParam);
2727 case TTM_SETTOOLINFOW:
2728 return TOOLTIPS_SetToolInfoW (hwnd, wParam, lParam);
2730 case TTM_TRACKACTIVATE:
2731 return TOOLTIPS_TrackActivate (hwnd, wParam, lParam);
2733 case TTM_TRACKPOSITION:
2734 return TOOLTIPS_TrackPosition (hwnd, wParam, lParam);
2736 case TTM_UPDATE:
2737 return TOOLTIPS_Update (hwnd, wParam, lParam);
2739 case TTM_UPDATETIPTEXTA:
2740 return TOOLTIPS_UpdateTipTextA (hwnd, wParam, lParam);
2742 case TTM_UPDATETIPTEXTW:
2743 return TOOLTIPS_UpdateTipTextW (hwnd, wParam, lParam);
2745 case TTM_WINDOWFROMPOINT:
2746 return TOOLTIPS_WindowFromPoint (hwnd, wParam, lParam);
2749 case WM_CREATE:
2750 return TOOLTIPS_Create (hwnd, (LPCREATESTRUCTW)lParam);
2752 case WM_DESTROY:
2753 return TOOLTIPS_Destroy (hwnd, wParam, lParam);
2755 case WM_ERASEBKGND:
2756 /* we draw the background in WM_PAINT */
2757 return 0;
2759 case WM_GETFONT:
2760 return TOOLTIPS_GetFont (hwnd, wParam, lParam);
2762 case WM_GETTEXT:
2763 return TOOLTIPS_OnWMGetText (hwnd, wParam, lParam);
2765 case WM_GETTEXTLENGTH:
2766 return TOOLTIPS_GetTextLength (hwnd, wParam, lParam);
2768 case WM_LBUTTONDOWN:
2769 case WM_LBUTTONUP:
2770 case WM_MBUTTONDOWN:
2771 case WM_MBUTTONUP:
2772 case WM_RBUTTONDOWN:
2773 case WM_RBUTTONUP:
2774 case WM_MOUSEMOVE:
2775 return TOOLTIPS_MouseMessage (hwnd, uMsg, wParam, lParam);
2777 case WM_NCCREATE:
2778 return TOOLTIPS_NCCreate (hwnd, wParam, lParam);
2780 case WM_NCHITTEST:
2781 return TOOLTIPS_NCHitTest (hwnd, wParam, lParam);
2783 case WM_NOTIFYFORMAT:
2784 return TOOLTIPS_NotifyFormat (hwnd, wParam, lParam);
2786 case WM_PRINTCLIENT:
2787 case WM_PAINT:
2788 return TOOLTIPS_Paint (hwnd, wParam, lParam);
2790 case WM_SETFONT:
2791 return TOOLTIPS_SetFont (hwnd, wParam, lParam);
2793 case WM_TIMER:
2794 return TOOLTIPS_Timer (hwnd, wParam, lParam);
2796 case WM_WININICHANGE:
2797 return TOOLTIPS_WinIniChange (hwnd, wParam, lParam);
2799 default:
2800 if ((uMsg >= WM_USER) && (uMsg < WM_APP))
2801 ERR("unknown msg %04x wp=%08lx lp=%08lx\n",
2802 uMsg, wParam, lParam);
2803 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
2808 VOID
2809 TOOLTIPS_Register (void)
2811 WNDCLASSW wndClass;
2813 ZeroMemory (&wndClass, sizeof(WNDCLASSW));
2814 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS | CS_SAVEBITS;
2815 wndClass.lpfnWndProc = TOOLTIPS_WindowProc;
2816 wndClass.cbClsExtra = 0;
2817 wndClass.cbWndExtra = sizeof(TOOLTIPS_INFO *);
2818 wndClass.hCursor = LoadCursorW (0, (LPWSTR)IDC_ARROW);
2819 wndClass.hbrBackground = 0;
2820 wndClass.lpszClassName = TOOLTIPS_CLASSW;
2822 RegisterClassW (&wndClass);
2824 hTooltipIcons[TTI_NONE] = NULL;
2825 hTooltipIcons[TTI_INFO] = LoadImageW(COMCTL32_hModule,
2826 (LPCWSTR)MAKEINTRESOURCE(IDI_TT_INFO_SM), IMAGE_ICON, 0, 0, 0);
2827 hTooltipIcons[TTI_WARNING] = LoadImageW(COMCTL32_hModule,
2828 (LPCWSTR)MAKEINTRESOURCE(IDI_TT_WARN_SM), IMAGE_ICON, 0, 0, 0);
2829 hTooltipIcons[TTI_ERROR] = LoadImageW(COMCTL32_hModule,
2830 (LPCWSTR)MAKEINTRESOURCE(IDI_TT_ERROR_SM), IMAGE_ICON, 0, 0, 0);
2834 VOID
2835 TOOLTIPS_Unregister (void)
2837 int i;
2838 for (i = TTI_INFO; i <= TTI_ERROR; i++)
2839 DestroyIcon(hTooltipIcons[i]);
2840 UnregisterClassW (TOOLTIPS_CLASSW, NULL);