wined3d: Alpha states -> misc pipeline states.
[wine/gsoc_dplay.git] / dlls / comctl32 / tooltips.c
blob5368835c476cce8890020f9c44e4f5f17aca5ca5
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 /* Custom draw routines */
206 static void
207 TOOLTIPS_customdraw_fill(NMTTCUSTOMDRAW *lpnmttcd,
208 const HWND hwnd,
209 HDC hdc, const RECT *rcBounds, UINT uFlags)
211 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr(hwnd);
213 ZeroMemory(lpnmttcd, sizeof(NMTTCUSTOMDRAW));
214 lpnmttcd->uDrawFlags = uFlags;
215 lpnmttcd->nmcd.hdr.hwndFrom = hwnd;
216 lpnmttcd->nmcd.hdr.code = NM_CUSTOMDRAW;
217 if (infoPtr->nCurrentTool != -1) {
218 TTTOOL_INFO *toolPtr = &infoPtr->tools[infoPtr->nCurrentTool];
219 lpnmttcd->nmcd.hdr.idFrom = toolPtr->uId;
221 lpnmttcd->nmcd.hdc = hdc;
222 lpnmttcd->nmcd.rc = *rcBounds;
223 /* FIXME - dwItemSpec, uItemState, lItemlParam */
226 static inline DWORD
227 TOOLTIPS_notify_customdraw (DWORD dwDrawStage, NMTTCUSTOMDRAW *lpnmttcd)
229 LRESULT result = CDRF_DODEFAULT;
230 lpnmttcd->nmcd.dwDrawStage = dwDrawStage;
232 TRACE("Notifying stage %d, flags %x, id %x\n", lpnmttcd->nmcd.dwDrawStage,
233 lpnmttcd->uDrawFlags, lpnmttcd->nmcd.hdr.code);
235 result = SendMessageW(GetParent(lpnmttcd->nmcd.hdr.hwndFrom), WM_NOTIFY,
236 0, (LPARAM)lpnmttcd);
238 TRACE("Notify result %x\n", (unsigned int)result);
240 return result;
243 static void
244 TOOLTIPS_Refresh (HWND hwnd, HDC hdc)
246 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr(hwnd);
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(hwnd, GWL_STYLE);
254 NMTTCUSTOMDRAW nmttcd;
255 DWORD cdmode;
257 if (infoPtr->nMaxTipWidth > -1)
258 uFlags |= DT_WORDBREAK;
259 if (GetWindowLongW (hwnd, GWL_STYLE) & TTS_NOPREFIX)
260 uFlags |= DT_NOPREFIX;
261 GetClientRect (hwnd, &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, hwnd, 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(hwnd, 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(HWND hwnd, TOOLTIPS_INFO *infoPtr, TTTOOL_INFO *toolPtr)
364 NMTTDISPINFOA ttnmdi;
366 /* fill NMHDR struct */
367 ZeroMemory (&ttnmdi, sizeof(NMTTDISPINFOA));
368 ttnmdi.hdr.hwndFrom = hwnd;
369 ttnmdi.hdr.idFrom = toolPtr->uId;
370 ttnmdi.hdr.code = TTN_GETDISPINFOA; /* == TTN_NEEDTEXTA */
371 ttnmdi.lpszText = (LPSTR)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(HWND hwnd, TOOLTIPS_INFO *infoPtr, TTTOOL_INFO *toolPtr)
420 NMTTDISPINFOW ttnmdi;
422 /* fill NMHDR struct */
423 ZeroMemory (&ttnmdi, sizeof(NMTTDISPINFOW));
424 ttnmdi.hdr.hwndFrom = hwnd;
425 ttnmdi.hdr.idFrom = toolPtr->uId;
426 ttnmdi.hdr.code = TTN_GETDISPINFOW; /* == TTN_NEEDTEXTW */
427 ttnmdi.lpszText = (LPWSTR)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 (HWND hwnd, 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(hwnd, infoPtr, toolPtr);
491 else
492 TOOLTIPS_GetDispInfoA(hwnd, 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 (HWND hwnd, const TOOLTIPS_INFO *infoPtr, LPSIZE lpSize)
511 HDC hdc;
512 HFONT hOldFont;
513 DWORD style = GetWindowLongW(hwnd, 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 (hwnd);
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 (hwnd, 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 (HWND hwnd, 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(hwnd, 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, hwnd);
600 TOOLTIPS_GetTipText (hwnd, 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 = hwnd;
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 (hwnd, 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 (hwnd, GWL_STYLE),
753 FALSE, GetWindowLongW (hwnd, 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(hwnd, hRgn, FALSE);
804 /* we don't free the region handle as the system deletes it when
805 * it is no longer needed */
808 SetWindowPos (hwnd, 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(hwnd, NULL, TRUE);
814 UpdateWindow(hwnd);
816 if (!track_activate)
818 SetTimer (hwnd, ID_TIMERPOP, infoPtr->nAutoPopTime, 0);
819 TRACE("timer 2 started!\n");
820 SetTimer (hwnd, ID_TIMERLEAVE, infoPtr->nReshowTime, 0);
821 TRACE("timer 3 started!\n");
826 static void
827 TOOLTIPS_Hide (HWND hwnd, TOOLTIPS_INFO *infoPtr)
829 TTTOOL_INFO *toolPtr;
830 NMHDR hdr;
832 TRACE("Hide tooltip %d! (%p)\n", infoPtr->nCurrentTool, hwnd);
834 if (infoPtr->nCurrentTool == -1)
835 return;
837 toolPtr = &infoPtr->tools[infoPtr->nCurrentTool];
838 KillTimer (hwnd, ID_TIMERPOP);
840 hdr.hwndFrom = hwnd;
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 (hwnd, HWND_TOP, 0, 0, 0, 0,
848 SWP_NOZORDER | SWP_HIDEWINDOW | SWP_NOACTIVATE);
852 static void
853 TOOLTIPS_TrackShow (HWND hwnd, TOOLTIPS_INFO *infoPtr)
855 TOOLTIPS_Show(hwnd, infoPtr, TRUE);
859 static void
860 TOOLTIPS_TrackHide (HWND hwnd, 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 = hwnd;
873 hdr.idFrom = toolPtr->uId;
874 hdr.code = TTN_POP;
875 SendMessageW (toolPtr->hwnd, WM_NOTIFY, toolPtr->uId, (LPARAM)&hdr);
877 SetWindowPos (hwnd, 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 (HWND hwnd, BOOL bShowTest)
982 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
983 POINT pt;
984 HWND hwndTool;
985 INT nTool;
987 GetCursorPos (&pt);
988 hwndTool = (HWND)SendMessageW (hwnd, TTM_WINDOWFROMPOINT, 0, (LPARAM)&pt);
989 if (hwndTool == 0)
990 return -1;
992 ScreenToClient (hwndTool, &pt);
993 nTool = TOOLTIPS_GetToolFromPoint (infoPtr, hwndTool, &pt);
994 if (nTool == -1)
995 return -1;
997 if (!(GetWindowLongW (hwnd, GWL_STYLE) & TTS_ALWAYSTIP) && bShowTest) {
998 if (!TOOLTIPS_IsWindowActive (GetWindow (hwnd, GW_OWNER)))
999 return -1;
1002 TRACE("tool %d\n", nTool);
1004 return nTool;
1008 static LRESULT
1009 TOOLTIPS_Activate (HWND hwnd, WPARAM wParam, LPARAM lParam)
1011 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1013 infoPtr->bActive = (BOOL)wParam;
1015 if (infoPtr->bActive)
1016 TRACE("activate!\n");
1018 if (!(infoPtr->bActive) && (infoPtr->nCurrentTool != -1))
1019 TOOLTIPS_Hide (hwnd, infoPtr);
1021 return 0;
1025 static LRESULT
1026 TOOLTIPS_AddToolA (HWND hwnd, WPARAM wParam, LPARAM lParam)
1028 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1029 LPTTTOOLINFOA lpToolInfo = (LPTTTOOLINFOA)lParam;
1030 TTTOOL_INFO *toolPtr;
1031 INT nResult;
1033 if (lpToolInfo == NULL)
1034 return FALSE;
1035 if (lpToolInfo->cbSize < TTTOOLINFOA_V1_SIZE)
1036 return FALSE;
1038 TRACE("add tool (%p) %p %ld%s!\n",
1039 hwnd, lpToolInfo->hwnd, lpToolInfo->uId,
1040 (lpToolInfo->uFlags & TTF_IDISHWND) ? " TTF_IDISHWND" : "");
1042 if (infoPtr->uNumTools == 0) {
1043 infoPtr->tools = Alloc (sizeof(TTTOOL_INFO));
1044 toolPtr = infoPtr->tools;
1046 else {
1047 TTTOOL_INFO *oldTools = infoPtr->tools;
1048 infoPtr->tools =
1049 Alloc (sizeof(TTTOOL_INFO) * (infoPtr->uNumTools + 1));
1050 memcpy (infoPtr->tools, oldTools,
1051 infoPtr->uNumTools * sizeof(TTTOOL_INFO));
1052 Free (oldTools);
1053 toolPtr = &infoPtr->tools[infoPtr->uNumTools];
1056 infoPtr->uNumTools++;
1058 /* copy tool data */
1059 toolPtr->uFlags = lpToolInfo->uFlags;
1060 toolPtr->hwnd = lpToolInfo->hwnd;
1061 toolPtr->uId = lpToolInfo->uId;
1062 toolPtr->rect = lpToolInfo->rect;
1063 toolPtr->hinst = lpToolInfo->hinst;
1065 if (IS_INTRESOURCE(lpToolInfo->lpszText)) {
1066 TRACE("add string id %x!\n", LOWORD(lpToolInfo->lpszText));
1067 toolPtr->lpszText = (LPWSTR)lpToolInfo->lpszText;
1069 else if (lpToolInfo->lpszText) {
1070 if (lpToolInfo->lpszText == LPSTR_TEXTCALLBACKA) {
1071 TRACE("add CALLBACK!\n");
1072 toolPtr->lpszText = LPSTR_TEXTCALLBACKW;
1074 else {
1075 INT len = MultiByteToWideChar(CP_ACP, 0, lpToolInfo->lpszText, -1,
1076 NULL, 0);
1077 TRACE("add text \"%s\"!\n", lpToolInfo->lpszText);
1078 toolPtr->lpszText = Alloc (len * sizeof(WCHAR));
1079 MultiByteToWideChar(CP_ACP, 0, lpToolInfo->lpszText, -1,
1080 toolPtr->lpszText, len);
1084 if (lpToolInfo->cbSize >= sizeof(TTTOOLINFOA))
1085 toolPtr->lParam = lpToolInfo->lParam;
1087 /* install subclassing hook */
1088 if (toolPtr->uFlags & TTF_SUBCLASS) {
1089 if (toolPtr->uFlags & TTF_IDISHWND) {
1090 SetWindowSubclass((HWND)toolPtr->uId, TOOLTIPS_SubclassProc, 1,
1091 (DWORD_PTR)hwnd);
1093 else {
1094 SetWindowSubclass(toolPtr->hwnd, TOOLTIPS_SubclassProc, 1,
1095 (DWORD_PTR)hwnd);
1097 TRACE("subclassing installed!\n");
1100 nResult = (INT) SendMessageW (toolPtr->hwnd, WM_NOTIFYFORMAT,
1101 (WPARAM)hwnd, (LPARAM)NF_QUERY);
1102 if (nResult == NFR_ANSI) {
1103 toolPtr->bNotifyUnicode = FALSE;
1104 TRACE(" -- WM_NOTIFYFORMAT returns: NFR_ANSI\n");
1105 } else if (nResult == NFR_UNICODE) {
1106 toolPtr->bNotifyUnicode = TRUE;
1107 TRACE(" -- WM_NOTIFYFORMAT returns: NFR_UNICODE\n");
1108 } else {
1109 TRACE (" -- WM_NOTIFYFORMAT returns: error!\n");
1112 return TRUE;
1116 static LRESULT
1117 TOOLTIPS_AddToolW (HWND hwnd, WPARAM wParam, LPARAM lParam)
1119 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1120 LPTTTOOLINFOW lpToolInfo = (LPTTTOOLINFOW)lParam;
1121 TTTOOL_INFO *toolPtr;
1122 INT nResult;
1124 if (lpToolInfo == NULL)
1125 return FALSE;
1126 if (lpToolInfo->cbSize < TTTOOLINFOW_V1_SIZE)
1127 return FALSE;
1129 TRACE("add tool (%p) %p %ld%s!\n",
1130 hwnd, lpToolInfo->hwnd, lpToolInfo->uId,
1131 (lpToolInfo->uFlags & TTF_IDISHWND) ? " TTF_IDISHWND" : "");
1133 if (infoPtr->uNumTools == 0) {
1134 infoPtr->tools = Alloc (sizeof(TTTOOL_INFO));
1135 toolPtr = infoPtr->tools;
1137 else {
1138 TTTOOL_INFO *oldTools = infoPtr->tools;
1139 infoPtr->tools =
1140 Alloc (sizeof(TTTOOL_INFO) * (infoPtr->uNumTools + 1));
1141 memcpy (infoPtr->tools, oldTools,
1142 infoPtr->uNumTools * sizeof(TTTOOL_INFO));
1143 Free (oldTools);
1144 toolPtr = &infoPtr->tools[infoPtr->uNumTools];
1147 infoPtr->uNumTools++;
1149 /* copy tool data */
1150 toolPtr->uFlags = lpToolInfo->uFlags;
1151 toolPtr->hwnd = lpToolInfo->hwnd;
1152 toolPtr->uId = lpToolInfo->uId;
1153 toolPtr->rect = lpToolInfo->rect;
1154 toolPtr->hinst = lpToolInfo->hinst;
1156 if (IS_INTRESOURCE(lpToolInfo->lpszText)) {
1157 TRACE("add string id %x\n", LOWORD(lpToolInfo->lpszText));
1158 toolPtr->lpszText = lpToolInfo->lpszText;
1160 else if (lpToolInfo->lpszText) {
1161 if (lpToolInfo->lpszText == LPSTR_TEXTCALLBACKW) {
1162 TRACE("add CALLBACK!\n");
1163 toolPtr->lpszText = LPSTR_TEXTCALLBACKW;
1165 else {
1166 INT len = lstrlenW (lpToolInfo->lpszText);
1167 TRACE("add text %s!\n",
1168 debugstr_w(lpToolInfo->lpszText));
1169 toolPtr->lpszText = Alloc ((len + 1)*sizeof(WCHAR));
1170 strcpyW (toolPtr->lpszText, lpToolInfo->lpszText);
1174 if (lpToolInfo->cbSize >= sizeof(TTTOOLINFOW))
1175 toolPtr->lParam = lpToolInfo->lParam;
1177 /* install subclassing hook */
1178 if (toolPtr->uFlags & TTF_SUBCLASS) {
1179 if (toolPtr->uFlags & TTF_IDISHWND) {
1180 SetWindowSubclass((HWND)toolPtr->uId, TOOLTIPS_SubclassProc, 1,
1181 (DWORD_PTR)hwnd);
1183 else {
1184 SetWindowSubclass(toolPtr->hwnd, TOOLTIPS_SubclassProc, 1,
1185 (DWORD_PTR)hwnd);
1187 TRACE("subclassing installed!\n");
1190 nResult = (INT) SendMessageW (toolPtr->hwnd, WM_NOTIFYFORMAT,
1191 (WPARAM)hwnd, (LPARAM)NF_QUERY);
1192 if (nResult == NFR_ANSI) {
1193 toolPtr->bNotifyUnicode = FALSE;
1194 TRACE(" -- WM_NOTIFYFORMAT returns: NFR_ANSI\n");
1195 } else if (nResult == NFR_UNICODE) {
1196 toolPtr->bNotifyUnicode = TRUE;
1197 TRACE(" -- WM_NOTIFYFORMAT returns: NFR_UNICODE\n");
1198 } else {
1199 TRACE (" -- WM_NOTIFYFORMAT returns: error!\n");
1202 return TRUE;
1206 static void
1207 TOOLTIPS_DelToolCommon (HWND hwnd, TOOLTIPS_INFO *infoPtr, INT nTool)
1209 TTTOOL_INFO *toolPtr;
1211 TRACE("tool %d\n", nTool);
1213 if (nTool == -1)
1214 return;
1216 /* make sure the tooltip has disappeared before deleting it */
1217 TOOLTIPS_Hide(hwnd, infoPtr);
1219 /* delete text string */
1220 toolPtr = &infoPtr->tools[nTool];
1221 if (toolPtr->lpszText) {
1222 if ( (toolPtr->lpszText != LPSTR_TEXTCALLBACKW) &&
1223 !IS_INTRESOURCE(toolPtr->lpszText) )
1224 Free (toolPtr->lpszText);
1227 /* remove subclassing */
1228 if (toolPtr->uFlags & TTF_SUBCLASS) {
1229 if (toolPtr->uFlags & TTF_IDISHWND) {
1230 RemoveWindowSubclass((HWND)toolPtr->uId, TOOLTIPS_SubclassProc, 1);
1232 else {
1233 RemoveWindowSubclass(toolPtr->hwnd, TOOLTIPS_SubclassProc, 1);
1237 /* delete tool from tool list */
1238 if (infoPtr->uNumTools == 1) {
1239 Free (infoPtr->tools);
1240 infoPtr->tools = NULL;
1242 else {
1243 TTTOOL_INFO *oldTools = infoPtr->tools;
1244 infoPtr->tools =
1245 Alloc (sizeof(TTTOOL_INFO) * (infoPtr->uNumTools - 1));
1247 if (nTool > 0)
1248 memcpy (&infoPtr->tools[0], &oldTools[0],
1249 nTool * sizeof(TTTOOL_INFO));
1251 if (nTool < infoPtr->uNumTools - 1)
1252 memcpy (&infoPtr->tools[nTool], &oldTools[nTool + 1],
1253 (infoPtr->uNumTools - nTool - 1) * sizeof(TTTOOL_INFO));
1255 Free (oldTools);
1258 /* update any indices affected by delete */
1260 /* destroying tool that mouse was on on last relayed mouse move */
1261 if (infoPtr->nTool == nTool)
1262 /* -1 means no current tool (0 means first tool) */
1263 infoPtr->nTool = -1;
1264 else if (infoPtr->nTool > nTool)
1265 infoPtr->nTool--;
1267 if (infoPtr->nTrackTool == nTool)
1268 /* -1 means no current tool (0 means first tool) */
1269 infoPtr->nTrackTool = -1;
1270 else if (infoPtr->nTrackTool > nTool)
1271 infoPtr->nTrackTool--;
1273 if (infoPtr->nCurrentTool == nTool)
1274 /* -1 means no current tool (0 means first tool) */
1275 infoPtr->nCurrentTool = -1;
1276 else if (infoPtr->nCurrentTool > nTool)
1277 infoPtr->nCurrentTool--;
1279 infoPtr->uNumTools--;
1282 static LRESULT
1283 TOOLTIPS_DelToolA (HWND hwnd, WPARAM wParam, LPARAM lParam)
1285 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1286 LPTTTOOLINFOA lpToolInfo = (LPTTTOOLINFOA)lParam;
1287 INT nTool;
1289 if (lpToolInfo == NULL)
1290 return 0;
1291 if (lpToolInfo->cbSize < TTTOOLINFOA_V1_SIZE)
1292 return 0;
1293 if (infoPtr->uNumTools == 0)
1294 return 0;
1296 nTool = TOOLTIPS_GetToolFromInfoA (infoPtr, lpToolInfo);
1298 TOOLTIPS_DelToolCommon (hwnd, infoPtr, nTool);
1300 return 0;
1304 static LRESULT
1305 TOOLTIPS_DelToolW (HWND hwnd, WPARAM wParam, LPARAM lParam)
1307 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1308 LPTTTOOLINFOW lpToolInfo = (LPTTTOOLINFOW)lParam;
1309 INT nTool;
1311 if (lpToolInfo == NULL)
1312 return 0;
1313 if (lpToolInfo->cbSize < TTTOOLINFOW_V1_SIZE)
1314 return 0;
1315 if (infoPtr->uNumTools == 0)
1316 return 0;
1318 nTool = TOOLTIPS_GetToolFromInfoW (infoPtr, lpToolInfo);
1320 TOOLTIPS_DelToolCommon (hwnd, infoPtr, nTool);
1322 return 0;
1326 static LRESULT
1327 TOOLTIPS_EnumToolsA (HWND hwnd, WPARAM wParam, LPARAM lParam)
1329 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1330 UINT uIndex = (UINT)wParam;
1331 LPTTTOOLINFOA lpToolInfo = (LPTTTOOLINFOA)lParam;
1332 TTTOOL_INFO *toolPtr;
1334 if (lpToolInfo == NULL)
1335 return FALSE;
1336 if (lpToolInfo->cbSize < TTTOOLINFOA_V1_SIZE)
1337 return FALSE;
1338 if (uIndex >= infoPtr->uNumTools)
1339 return FALSE;
1341 TRACE("index=%u\n", uIndex);
1343 toolPtr = &infoPtr->tools[uIndex];
1345 /* copy tool data */
1346 lpToolInfo->uFlags = toolPtr->uFlags;
1347 lpToolInfo->hwnd = toolPtr->hwnd;
1348 lpToolInfo->uId = toolPtr->uId;
1349 lpToolInfo->rect = toolPtr->rect;
1350 lpToolInfo->hinst = toolPtr->hinst;
1351 /* lpToolInfo->lpszText = toolPtr->lpszText; */
1352 lpToolInfo->lpszText = NULL; /* FIXME */
1354 if (lpToolInfo->cbSize >= sizeof(TTTOOLINFOA))
1355 lpToolInfo->lParam = toolPtr->lParam;
1357 return TRUE;
1361 static LRESULT
1362 TOOLTIPS_EnumToolsW (HWND hwnd, WPARAM wParam, LPARAM lParam)
1364 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1365 UINT uIndex = (UINT)wParam;
1366 LPTTTOOLINFOW lpToolInfo = (LPTTTOOLINFOW)lParam;
1367 TTTOOL_INFO *toolPtr;
1369 if (lpToolInfo == NULL)
1370 return FALSE;
1371 if (lpToolInfo->cbSize < TTTOOLINFOW_V1_SIZE)
1372 return FALSE;
1373 if (uIndex >= infoPtr->uNumTools)
1374 return FALSE;
1376 TRACE("index=%u\n", uIndex);
1378 toolPtr = &infoPtr->tools[uIndex];
1380 /* copy tool data */
1381 lpToolInfo->uFlags = toolPtr->uFlags;
1382 lpToolInfo->hwnd = toolPtr->hwnd;
1383 lpToolInfo->uId = toolPtr->uId;
1384 lpToolInfo->rect = toolPtr->rect;
1385 lpToolInfo->hinst = toolPtr->hinst;
1386 /* lpToolInfo->lpszText = toolPtr->lpszText; */
1387 lpToolInfo->lpszText = NULL; /* FIXME */
1389 if (lpToolInfo->cbSize >= sizeof(TTTOOLINFOW))
1390 lpToolInfo->lParam = toolPtr->lParam;
1392 return TRUE;
1395 static LRESULT
1396 TOOLTIPS_GetBubbleSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
1398 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1399 LPTTTOOLINFOW lpToolInfo = (LPTTTOOLINFOW)lParam;
1400 INT nTool;
1401 SIZE size;
1403 if (lpToolInfo == NULL)
1404 return FALSE;
1405 if (lpToolInfo->cbSize < TTTOOLINFOW_V1_SIZE)
1406 return FALSE;
1408 nTool = TOOLTIPS_GetToolFromInfoW (infoPtr, lpToolInfo);
1409 if (nTool == -1) return 0;
1411 TRACE("tool %d\n", nTool);
1413 TOOLTIPS_CalcTipSize (hwnd, infoPtr, &size);
1414 TRACE("size %d x %d\n", size.cx, size.cy);
1416 return MAKELRESULT(size.cx, size.cy);
1419 static LRESULT
1420 TOOLTIPS_GetCurrentToolA (HWND hwnd, WPARAM wParam, LPARAM lParam)
1422 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1423 LPTTTOOLINFOA lpToolInfo = (LPTTTOOLINFOA)lParam;
1424 TTTOOL_INFO *toolPtr;
1426 if (lpToolInfo) {
1427 if (lpToolInfo->cbSize < TTTOOLINFOA_V1_SIZE)
1428 return FALSE;
1430 if (infoPtr->nCurrentTool > -1) {
1431 toolPtr = &infoPtr->tools[infoPtr->nCurrentTool];
1433 /* copy tool data */
1434 lpToolInfo->uFlags = toolPtr->uFlags;
1435 lpToolInfo->rect = toolPtr->rect;
1436 lpToolInfo->hinst = toolPtr->hinst;
1437 /* lpToolInfo->lpszText = toolPtr->lpszText; */
1438 lpToolInfo->lpszText = NULL; /* FIXME */
1440 if (lpToolInfo->cbSize >= sizeof(TTTOOLINFOA))
1441 lpToolInfo->lParam = toolPtr->lParam;
1443 return TRUE;
1445 else
1446 return FALSE;
1448 else
1449 return (infoPtr->nCurrentTool != -1);
1453 static LRESULT
1454 TOOLTIPS_GetCurrentToolW (HWND hwnd, WPARAM wParam, LPARAM lParam)
1456 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1457 LPTTTOOLINFOW lpToolInfo = (LPTTTOOLINFOW)lParam;
1458 TTTOOL_INFO *toolPtr;
1460 if (lpToolInfo) {
1461 if (lpToolInfo->cbSize < TTTOOLINFOW_V1_SIZE)
1462 return FALSE;
1464 if (infoPtr->nCurrentTool > -1) {
1465 toolPtr = &infoPtr->tools[infoPtr->nCurrentTool];
1467 /* copy tool data */
1468 lpToolInfo->uFlags = toolPtr->uFlags;
1469 lpToolInfo->rect = toolPtr->rect;
1470 lpToolInfo->hinst = toolPtr->hinst;
1471 /* lpToolInfo->lpszText = toolPtr->lpszText; */
1472 lpToolInfo->lpszText = NULL; /* FIXME */
1474 if (lpToolInfo->cbSize >= sizeof(TTTOOLINFOW))
1475 lpToolInfo->lParam = toolPtr->lParam;
1477 return TRUE;
1479 else
1480 return FALSE;
1482 else
1483 return (infoPtr->nCurrentTool != -1);
1487 static LRESULT
1488 TOOLTIPS_GetDelayTime (HWND hwnd, WPARAM wParam, LPARAM lParam)
1490 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1492 switch (wParam) {
1493 case TTDT_RESHOW:
1494 return infoPtr->nReshowTime;
1496 case TTDT_AUTOPOP:
1497 return infoPtr->nAutoPopTime;
1499 case TTDT_INITIAL:
1500 case TTDT_AUTOMATIC: /* Apparently TTDT_AUTOMATIC returns TTDT_INITIAL */
1501 return infoPtr->nInitialTime;
1503 default:
1504 WARN("Invalid wParam %lx\n", wParam);
1505 break;
1508 return -1;
1512 static LRESULT
1513 TOOLTIPS_GetMargin (HWND hwnd, WPARAM wParam, LPARAM lParam)
1515 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1516 LPRECT lpRect = (LPRECT)lParam;
1518 lpRect->left = infoPtr->rcMargin.left;
1519 lpRect->right = infoPtr->rcMargin.right;
1520 lpRect->bottom = infoPtr->rcMargin.bottom;
1521 lpRect->top = infoPtr->rcMargin.top;
1523 return 0;
1527 static inline LRESULT
1528 TOOLTIPS_GetMaxTipWidth (HWND hwnd, WPARAM wParam, LPARAM lParam)
1530 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1532 return infoPtr->nMaxTipWidth;
1536 static LRESULT
1537 TOOLTIPS_GetTextA (HWND hwnd, WPARAM wParam, LPARAM lParam)
1539 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1540 LPTTTOOLINFOA lpToolInfo = (LPTTTOOLINFOA)lParam;
1541 INT nTool;
1543 if (lpToolInfo == NULL)
1544 return 0;
1545 if (lpToolInfo->cbSize < TTTOOLINFOA_V1_SIZE)
1546 return 0;
1548 nTool = TOOLTIPS_GetToolFromInfoA (infoPtr, lpToolInfo);
1549 if (nTool == -1) return 0;
1551 /* NB this API is broken, there is no way for the app to determine
1552 what size buffer it requires nor a way to specify how long the
1553 one it supplies is. We'll assume it's up to INFOTIPSIZE */
1555 WideCharToMultiByte(CP_ACP, 0, infoPtr->tools[nTool].lpszText, -1,
1556 lpToolInfo->lpszText, INFOTIPSIZE, NULL, NULL);
1558 return 0;
1562 static LRESULT
1563 TOOLTIPS_GetTextW (HWND hwnd, WPARAM wParam, LPARAM lParam)
1565 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1566 LPTTTOOLINFOW lpToolInfo = (LPTTTOOLINFOW)lParam;
1567 INT nTool;
1569 if (lpToolInfo == NULL)
1570 return 0;
1571 if (lpToolInfo->cbSize < TTTOOLINFOW_V1_SIZE)
1572 return 0;
1574 nTool = TOOLTIPS_GetToolFromInfoW (infoPtr, lpToolInfo);
1575 if (nTool == -1) return 0;
1577 strcpyW (lpToolInfo->lpszText, infoPtr->tools[nTool].lpszText);
1579 return 0;
1583 static inline LRESULT
1584 TOOLTIPS_GetTipBkColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
1586 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1587 return infoPtr->clrBk;
1591 static inline LRESULT
1592 TOOLTIPS_GetTipTextColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
1594 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1595 return infoPtr->clrText;
1599 static inline LRESULT
1600 TOOLTIPS_GetToolCount (HWND hwnd, WPARAM wParam, LPARAM lParam)
1602 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1603 return infoPtr->uNumTools;
1607 static LRESULT
1608 TOOLTIPS_GetToolInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
1610 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1611 LPTTTOOLINFOA lpToolInfo = (LPTTTOOLINFOA)lParam;
1612 TTTOOL_INFO *toolPtr;
1613 INT nTool;
1615 if (lpToolInfo == NULL)
1616 return FALSE;
1617 if (lpToolInfo->cbSize < TTTOOLINFOA_V1_SIZE)
1618 return FALSE;
1619 if (infoPtr->uNumTools == 0)
1620 return FALSE;
1622 nTool = TOOLTIPS_GetToolFromInfoA (infoPtr, lpToolInfo);
1623 if (nTool == -1)
1624 return FALSE;
1626 TRACE("tool %d\n", nTool);
1628 toolPtr = &infoPtr->tools[nTool];
1630 /* copy tool data */
1631 lpToolInfo->uFlags = toolPtr->uFlags;
1632 lpToolInfo->rect = toolPtr->rect;
1633 lpToolInfo->hinst = toolPtr->hinst;
1634 /* lpToolInfo->lpszText = toolPtr->lpszText; */
1635 lpToolInfo->lpszText = NULL; /* FIXME */
1637 if (lpToolInfo->cbSize >= sizeof(TTTOOLINFOA))
1638 lpToolInfo->lParam = toolPtr->lParam;
1640 return TRUE;
1644 static LRESULT
1645 TOOLTIPS_GetToolInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
1647 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1648 LPTTTOOLINFOW lpToolInfo = (LPTTTOOLINFOW)lParam;
1649 TTTOOL_INFO *toolPtr;
1650 INT nTool;
1652 if (lpToolInfo == NULL)
1653 return FALSE;
1654 if (lpToolInfo->cbSize < TTTOOLINFOW_V1_SIZE)
1655 return FALSE;
1656 if (infoPtr->uNumTools == 0)
1657 return FALSE;
1659 nTool = TOOLTIPS_GetToolFromInfoW (infoPtr, lpToolInfo);
1660 if (nTool == -1)
1661 return FALSE;
1663 TRACE("tool %d\n", nTool);
1665 toolPtr = &infoPtr->tools[nTool];
1667 /* copy tool data */
1668 lpToolInfo->uFlags = toolPtr->uFlags;
1669 lpToolInfo->rect = toolPtr->rect;
1670 lpToolInfo->hinst = toolPtr->hinst;
1671 /* lpToolInfo->lpszText = toolPtr->lpszText; */
1672 lpToolInfo->lpszText = NULL; /* FIXME */
1674 if (lpToolInfo->cbSize >= sizeof(TTTOOLINFOW))
1675 lpToolInfo->lParam = toolPtr->lParam;
1677 return TRUE;
1681 static LRESULT
1682 TOOLTIPS_HitTestA (HWND hwnd, WPARAM wParam, LPARAM lParam)
1684 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1685 LPTTHITTESTINFOA lptthit = (LPTTHITTESTINFOA)lParam;
1686 TTTOOL_INFO *toolPtr;
1687 INT nTool;
1689 if (lptthit == 0)
1690 return FALSE;
1692 nTool = TOOLTIPS_GetToolFromPoint (infoPtr, lptthit->hwnd, &lptthit->pt);
1693 if (nTool == -1)
1694 return FALSE;
1696 TRACE("tool %d!\n", nTool);
1698 /* copy tool data */
1699 if (lptthit->ti.cbSize >= sizeof(TTTOOLINFOA)) {
1700 toolPtr = &infoPtr->tools[nTool];
1702 lptthit->ti.uFlags = toolPtr->uFlags;
1703 lptthit->ti.hwnd = toolPtr->hwnd;
1704 lptthit->ti.uId = toolPtr->uId;
1705 lptthit->ti.rect = toolPtr->rect;
1706 lptthit->ti.hinst = toolPtr->hinst;
1707 /* lptthit->ti.lpszText = toolPtr->lpszText; */
1708 lptthit->ti.lpszText = NULL; /* FIXME */
1709 lptthit->ti.lParam = toolPtr->lParam;
1712 return TRUE;
1716 static LRESULT
1717 TOOLTIPS_HitTestW (HWND hwnd, WPARAM wParam, LPARAM lParam)
1719 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1720 LPTTHITTESTINFOW lptthit = (LPTTHITTESTINFOW)lParam;
1721 TTTOOL_INFO *toolPtr;
1722 INT nTool;
1724 if (lptthit == 0)
1725 return FALSE;
1727 nTool = TOOLTIPS_GetToolFromPoint (infoPtr, lptthit->hwnd, &lptthit->pt);
1728 if (nTool == -1)
1729 return FALSE;
1731 TRACE("tool %d!\n", nTool);
1733 /* copy tool data */
1734 if (lptthit->ti.cbSize >= sizeof(TTTOOLINFOW)) {
1735 toolPtr = &infoPtr->tools[nTool];
1737 lptthit->ti.uFlags = toolPtr->uFlags;
1738 lptthit->ti.hwnd = toolPtr->hwnd;
1739 lptthit->ti.uId = toolPtr->uId;
1740 lptthit->ti.rect = toolPtr->rect;
1741 lptthit->ti.hinst = toolPtr->hinst;
1742 /* lptthit->ti.lpszText = toolPtr->lpszText; */
1743 lptthit->ti.lpszText = NULL; /* FIXME */
1744 lptthit->ti.lParam = toolPtr->lParam;
1747 return TRUE;
1751 static LRESULT
1752 TOOLTIPS_NewToolRectA (HWND hwnd, WPARAM wParam, LPARAM lParam)
1754 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1755 LPTTTOOLINFOA lpti = (LPTTTOOLINFOA)lParam;
1756 INT nTool;
1758 if (lpti == NULL)
1759 return 0;
1760 if (lpti->cbSize < TTTOOLINFOA_V1_SIZE)
1761 return FALSE;
1763 nTool = TOOLTIPS_GetToolFromInfoA (infoPtr, lpti);
1765 TRACE("nTool = %d, rect = %s\n", nTool, wine_dbgstr_rect(&lpti->rect));
1767 if (nTool == -1) return 0;
1769 infoPtr->tools[nTool].rect = lpti->rect;
1771 return 0;
1775 static LRESULT
1776 TOOLTIPS_NewToolRectW (HWND hwnd, WPARAM wParam, LPARAM lParam)
1778 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1779 LPTTTOOLINFOW lpti = (LPTTTOOLINFOW)lParam;
1780 INT nTool;
1782 if (lpti == NULL)
1783 return 0;
1784 if (lpti->cbSize < TTTOOLINFOW_V1_SIZE)
1785 return FALSE;
1787 nTool = TOOLTIPS_GetToolFromInfoW (infoPtr, lpti);
1789 TRACE("nTool = %d, rect = %s\n", nTool, wine_dbgstr_rect(&lpti->rect));
1791 if (nTool == -1) return 0;
1793 infoPtr->tools[nTool].rect = lpti->rect;
1795 return 0;
1799 static inline LRESULT
1800 TOOLTIPS_Pop (HWND hwnd, WPARAM wParam, LPARAM lParam)
1802 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1803 TOOLTIPS_Hide (hwnd, infoPtr);
1805 return 0;
1809 static LRESULT
1810 TOOLTIPS_RelayEvent (HWND hwnd, WPARAM wParam, LPARAM lParam)
1812 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1813 LPMSG lpMsg = (LPMSG)lParam;
1814 POINT pt;
1815 INT nOldTool;
1817 if (lParam == 0) {
1818 ERR("lpMsg == NULL!\n");
1819 return 0;
1822 switch (lpMsg->message) {
1823 case WM_LBUTTONDOWN:
1824 case WM_LBUTTONUP:
1825 case WM_MBUTTONDOWN:
1826 case WM_MBUTTONUP:
1827 case WM_RBUTTONDOWN:
1828 case WM_RBUTTONUP:
1829 TOOLTIPS_Hide (hwnd, infoPtr);
1830 break;
1832 case WM_MOUSEMOVE:
1833 pt.x = (short)LOWORD(lpMsg->lParam);
1834 pt.y = (short)HIWORD(lpMsg->lParam);
1835 nOldTool = infoPtr->nTool;
1836 infoPtr->nTool = TOOLTIPS_GetToolFromPoint(infoPtr, lpMsg->hwnd,
1837 &pt);
1838 TRACE("tool (%p) %d %d %d\n", hwnd, nOldTool,
1839 infoPtr->nTool, infoPtr->nCurrentTool);
1840 TRACE("WM_MOUSEMOVE (%p %d %d)\n", hwnd, pt.x, pt.y);
1842 if (infoPtr->nTool != nOldTool) {
1843 if(infoPtr->nTool == -1) { /* Moved out of all tools */
1844 TOOLTIPS_Hide(hwnd, infoPtr);
1845 KillTimer(hwnd, ID_TIMERLEAVE);
1846 } else if (nOldTool == -1) { /* Moved from outside */
1847 if(infoPtr->bActive) {
1848 SetTimer(hwnd, ID_TIMERSHOW, infoPtr->nInitialTime, 0);
1849 TRACE("timer 1 started!\n");
1851 } else { /* Moved from one to another */
1852 TOOLTIPS_Hide (hwnd, infoPtr);
1853 KillTimer(hwnd, ID_TIMERLEAVE);
1854 if(infoPtr->bActive) {
1855 SetTimer (hwnd, ID_TIMERSHOW, infoPtr->nReshowTime, 0);
1856 TRACE("timer 1 started!\n");
1859 } else if(infoPtr->nCurrentTool != -1) { /* restart autopop */
1860 KillTimer(hwnd, ID_TIMERPOP);
1861 SetTimer(hwnd, ID_TIMERPOP, infoPtr->nAutoPopTime, 0);
1862 TRACE("timer 2 restarted\n");
1863 } else if(infoPtr->nTool != -1 && infoPtr->bActive) {
1864 /* previous show attempt didn't result in tooltip so try again */
1865 SetTimer(hwnd, ID_TIMERSHOW, infoPtr->nInitialTime, 0);
1866 TRACE("timer 1 started!\n");
1868 break;
1871 return 0;
1875 static LRESULT
1876 TOOLTIPS_SetDelayTime (HWND hwnd, WPARAM wParam, LPARAM lParam)
1878 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1879 INT nTime = (INT)LOWORD(lParam);
1881 switch (wParam) {
1882 case TTDT_AUTOMATIC:
1883 if (nTime <= 0)
1884 nTime = GetDoubleClickTime();
1885 infoPtr->nReshowTime = nTime / 5;
1886 infoPtr->nAutoPopTime = nTime * 10;
1887 infoPtr->nInitialTime = nTime;
1888 break;
1890 case TTDT_RESHOW:
1891 if(nTime < 0)
1892 nTime = GetDoubleClickTime() / 5;
1893 infoPtr->nReshowTime = nTime;
1894 break;
1896 case TTDT_AUTOPOP:
1897 if(nTime < 0)
1898 nTime = GetDoubleClickTime() * 10;
1899 infoPtr->nAutoPopTime = nTime;
1900 break;
1902 case TTDT_INITIAL:
1903 if(nTime < 0)
1904 nTime = GetDoubleClickTime();
1905 infoPtr->nInitialTime = nTime;
1906 break;
1908 default:
1909 WARN("Invalid wParam %lx\n", wParam);
1910 break;
1913 return 0;
1917 static LRESULT
1918 TOOLTIPS_SetMargin (HWND hwnd, WPARAM wParam, LPARAM lParam)
1920 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1921 LPRECT lpRect = (LPRECT)lParam;
1923 infoPtr->rcMargin.left = lpRect->left;
1924 infoPtr->rcMargin.right = lpRect->right;
1925 infoPtr->rcMargin.bottom = lpRect->bottom;
1926 infoPtr->rcMargin.top = lpRect->top;
1928 return 0;
1932 static inline LRESULT
1933 TOOLTIPS_SetMaxTipWidth (HWND hwnd, WPARAM wParam, LPARAM lParam)
1935 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1936 INT nTemp = infoPtr->nMaxTipWidth;
1938 infoPtr->nMaxTipWidth = (INT)lParam;
1940 return nTemp;
1944 static inline LRESULT
1945 TOOLTIPS_SetTipBkColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
1947 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1949 infoPtr->clrBk = (COLORREF)wParam;
1951 return 0;
1955 static inline LRESULT
1956 TOOLTIPS_SetTipTextColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
1958 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1960 infoPtr->clrText = (COLORREF)wParam;
1962 return 0;
1966 static LRESULT
1967 TOOLTIPS_SetTitleA (HWND hwnd, WPARAM wParam, LPARAM lParam)
1969 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1970 LPCSTR pszTitle = (LPCSTR)lParam;
1971 UINT_PTR uTitleIcon = wParam;
1972 UINT size;
1974 TRACE("hwnd = %p, title = %s, icon = %p\n", hwnd, debugstr_a(pszTitle),
1975 (void*)uTitleIcon);
1977 Free(infoPtr->pszTitle);
1979 if (pszTitle)
1981 size = sizeof(WCHAR)*MultiByteToWideChar(CP_ACP, 0, pszTitle, -1, NULL, 0);
1982 infoPtr->pszTitle = Alloc(size);
1983 if (!infoPtr->pszTitle)
1984 return FALSE;
1985 MultiByteToWideChar(CP_ACP, 0, pszTitle, -1, infoPtr->pszTitle, size/sizeof(WCHAR));
1987 else
1988 infoPtr->pszTitle = NULL;
1990 if (uTitleIcon <= TTI_ERROR)
1991 infoPtr->hTitleIcon = hTooltipIcons[uTitleIcon];
1992 else
1993 infoPtr->hTitleIcon = CopyIcon((HICON)wParam);
1995 return TRUE;
1999 static LRESULT
2000 TOOLTIPS_SetTitleW (HWND hwnd, WPARAM wParam, LPARAM lParam)
2002 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
2003 LPCWSTR pszTitle = (LPCWSTR)lParam;
2004 UINT_PTR uTitleIcon = wParam;
2005 UINT size;
2007 TRACE("hwnd = %p, title = %s, icon = %p\n", hwnd, debugstr_w(pszTitle),
2008 (void*)uTitleIcon);
2010 Free(infoPtr->pszTitle);
2012 if (pszTitle)
2014 size = (strlenW(pszTitle)+1)*sizeof(WCHAR);
2015 infoPtr->pszTitle = Alloc(size);
2016 if (!infoPtr->pszTitle)
2017 return FALSE;
2018 memcpy(infoPtr->pszTitle, pszTitle, size);
2020 else
2021 infoPtr->pszTitle = NULL;
2023 if (uTitleIcon <= TTI_ERROR)
2024 infoPtr->hTitleIcon = hTooltipIcons[uTitleIcon];
2025 else
2026 infoPtr->hTitleIcon = CopyIcon((HICON)wParam);
2028 TRACE("icon = %p\n", infoPtr->hTitleIcon);
2030 return TRUE;
2034 static LRESULT
2035 TOOLTIPS_SetToolInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2037 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
2038 LPTTTOOLINFOA lpToolInfo = (LPTTTOOLINFOA)lParam;
2039 TTTOOL_INFO *toolPtr;
2040 INT nTool;
2042 if (lpToolInfo == NULL)
2043 return 0;
2044 if (lpToolInfo->cbSize < TTTOOLINFOA_V1_SIZE)
2045 return 0;
2047 nTool = TOOLTIPS_GetToolFromInfoA (infoPtr, lpToolInfo);
2048 if (nTool == -1) return 0;
2050 TRACE("tool %d\n", nTool);
2052 toolPtr = &infoPtr->tools[nTool];
2054 /* copy tool data */
2055 toolPtr->uFlags = lpToolInfo->uFlags;
2056 toolPtr->hwnd = lpToolInfo->hwnd;
2057 toolPtr->uId = lpToolInfo->uId;
2058 toolPtr->rect = lpToolInfo->rect;
2059 toolPtr->hinst = lpToolInfo->hinst;
2061 if (IS_INTRESOURCE(lpToolInfo->lpszText)) {
2062 TRACE("set string id %x\n", LOWORD(lpToolInfo->lpszText));
2063 toolPtr->lpszText = (LPWSTR)lpToolInfo->lpszText;
2065 else if (lpToolInfo->lpszText) {
2066 if (lpToolInfo->lpszText == LPSTR_TEXTCALLBACKA)
2067 toolPtr->lpszText = LPSTR_TEXTCALLBACKW;
2068 else {
2069 if ( (toolPtr->lpszText) &&
2070 !IS_INTRESOURCE(toolPtr->lpszText) ) {
2071 if( toolPtr->lpszText != LPSTR_TEXTCALLBACKW)
2072 Free (toolPtr->lpszText);
2073 toolPtr->lpszText = NULL;
2075 if (lpToolInfo->lpszText) {
2076 INT len = MultiByteToWideChar(CP_ACP, 0, lpToolInfo->lpszText,
2077 -1, NULL, 0);
2078 toolPtr->lpszText = Alloc (len * sizeof(WCHAR));
2079 MultiByteToWideChar(CP_ACP, 0, lpToolInfo->lpszText, -1,
2080 toolPtr->lpszText, len);
2085 if (lpToolInfo->cbSize >= sizeof(TTTOOLINFOA))
2086 toolPtr->lParam = lpToolInfo->lParam;
2088 return 0;
2092 static LRESULT
2093 TOOLTIPS_SetToolInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
2095 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
2096 LPTTTOOLINFOW lpToolInfo = (LPTTTOOLINFOW)lParam;
2097 TTTOOL_INFO *toolPtr;
2098 INT nTool;
2100 if (lpToolInfo == NULL)
2101 return 0;
2102 if (lpToolInfo->cbSize < TTTOOLINFOW_V1_SIZE)
2103 return 0;
2105 nTool = TOOLTIPS_GetToolFromInfoW (infoPtr, lpToolInfo);
2106 if (nTool == -1) return 0;
2108 TRACE("tool %d\n", nTool);
2110 toolPtr = &infoPtr->tools[nTool];
2112 /* copy tool data */
2113 toolPtr->uFlags = lpToolInfo->uFlags;
2114 toolPtr->hwnd = lpToolInfo->hwnd;
2115 toolPtr->uId = lpToolInfo->uId;
2116 toolPtr->rect = lpToolInfo->rect;
2117 toolPtr->hinst = lpToolInfo->hinst;
2119 if (IS_INTRESOURCE(lpToolInfo->lpszText)) {
2120 TRACE("set string id %x!\n", LOWORD(lpToolInfo->lpszText));
2121 toolPtr->lpszText = lpToolInfo->lpszText;
2123 else {
2124 if (lpToolInfo->lpszText == LPSTR_TEXTCALLBACKW)
2125 toolPtr->lpszText = LPSTR_TEXTCALLBACKW;
2126 else {
2127 if ( (toolPtr->lpszText) &&
2128 !IS_INTRESOURCE(toolPtr->lpszText) ) {
2129 if( toolPtr->lpszText != LPSTR_TEXTCALLBACKW)
2130 Free (toolPtr->lpszText);
2131 toolPtr->lpszText = NULL;
2133 if (lpToolInfo->lpszText) {
2134 INT len = lstrlenW (lpToolInfo->lpszText);
2135 toolPtr->lpszText = Alloc ((len+1)*sizeof(WCHAR));
2136 strcpyW (toolPtr->lpszText, lpToolInfo->lpszText);
2141 if (lpToolInfo->cbSize >= sizeof(TTTOOLINFOW))
2142 toolPtr->lParam = lpToolInfo->lParam;
2144 if (infoPtr->nCurrentTool == nTool)
2146 TOOLTIPS_GetTipText (hwnd, infoPtr, infoPtr->nCurrentTool);
2148 if (infoPtr->szTipText[0] == 0)
2149 TOOLTIPS_Hide(hwnd, infoPtr);
2150 else
2151 TOOLTIPS_Show (hwnd, infoPtr, FALSE);
2154 return 0;
2158 static LRESULT
2159 TOOLTIPS_TrackActivate (HWND hwnd, WPARAM wParam, LPARAM lParam)
2161 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
2163 if ((BOOL)wParam) {
2164 LPTTTOOLINFOA lpToolInfo = (LPTTTOOLINFOA)lParam;
2166 if (lpToolInfo == NULL)
2167 return 0;
2168 if (lpToolInfo->cbSize < TTTOOLINFOA_V1_SIZE)
2169 return FALSE;
2171 /* activate */
2172 infoPtr->nTrackTool = TOOLTIPS_GetToolFromInfoA (infoPtr, lpToolInfo);
2173 if (infoPtr->nTrackTool != -1) {
2174 TRACE("activated!\n");
2175 infoPtr->bTrackActive = TRUE;
2176 TOOLTIPS_TrackShow (hwnd, infoPtr);
2179 else {
2180 /* deactivate */
2181 TOOLTIPS_TrackHide (hwnd, infoPtr);
2183 infoPtr->bTrackActive = FALSE;
2184 infoPtr->nTrackTool = -1;
2186 TRACE("deactivated!\n");
2189 return 0;
2193 static LRESULT
2194 TOOLTIPS_TrackPosition (HWND hwnd, WPARAM wParam, LPARAM lParam)
2196 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
2198 infoPtr->xTrackPos = (INT)LOWORD(lParam);
2199 infoPtr->yTrackPos = (INT)HIWORD(lParam);
2201 if (infoPtr->bTrackActive) {
2202 TRACE("[%d %d]\n",
2203 infoPtr->xTrackPos, infoPtr->yTrackPos);
2205 TOOLTIPS_TrackShow (hwnd, infoPtr);
2208 return 0;
2212 static LRESULT
2213 TOOLTIPS_Update (HWND hwnd, WPARAM wParam, LPARAM lParam)
2215 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
2217 if (infoPtr->nCurrentTool != -1)
2218 UpdateWindow (hwnd);
2220 return 0;
2224 static LRESULT
2225 TOOLTIPS_UpdateTipTextA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2227 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
2228 LPTTTOOLINFOA lpToolInfo = (LPTTTOOLINFOA)lParam;
2229 TTTOOL_INFO *toolPtr;
2230 INT nTool;
2232 if (lpToolInfo == NULL)
2233 return 0;
2234 if (lpToolInfo->cbSize < TTTOOLINFOA_V1_SIZE)
2235 return FALSE;
2237 nTool = TOOLTIPS_GetToolFromInfoA (infoPtr, lpToolInfo);
2238 if (nTool == -1) return 0;
2240 TRACE("tool %d\n", nTool);
2242 toolPtr = &infoPtr->tools[nTool];
2244 /* copy tool text */
2245 toolPtr->hinst = lpToolInfo->hinst;
2247 if (IS_INTRESOURCE(lpToolInfo->lpszText)){
2248 toolPtr->lpszText = (LPWSTR)lpToolInfo->lpszText;
2250 else if (lpToolInfo->lpszText) {
2251 if (lpToolInfo->lpszText == LPSTR_TEXTCALLBACKA)
2252 toolPtr->lpszText = LPSTR_TEXTCALLBACKW;
2253 else {
2254 if ( (toolPtr->lpszText) &&
2255 !IS_INTRESOURCE(toolPtr->lpszText) ) {
2256 if( toolPtr->lpszText != LPSTR_TEXTCALLBACKW)
2257 Free (toolPtr->lpszText);
2258 toolPtr->lpszText = NULL;
2260 if (lpToolInfo->lpszText) {
2261 INT len = MultiByteToWideChar(CP_ACP, 0, lpToolInfo->lpszText,
2262 -1, NULL, 0);
2263 toolPtr->lpszText = Alloc (len * sizeof(WCHAR));
2264 MultiByteToWideChar(CP_ACP, 0, lpToolInfo->lpszText, -1,
2265 toolPtr->lpszText, len);
2270 if(infoPtr->nCurrentTool == -1) return 0;
2271 /* force repaint */
2272 if (infoPtr->bActive)
2273 TOOLTIPS_Show (hwnd, infoPtr, FALSE);
2274 else if (infoPtr->bTrackActive)
2275 TOOLTIPS_TrackShow (hwnd, infoPtr);
2277 return 0;
2281 static LRESULT
2282 TOOLTIPS_UpdateTipTextW (HWND hwnd, WPARAM wParam, LPARAM lParam)
2284 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
2285 LPTTTOOLINFOW lpToolInfo = (LPTTTOOLINFOW)lParam;
2286 TTTOOL_INFO *toolPtr;
2287 INT nTool;
2289 if (lpToolInfo == NULL)
2290 return 0;
2291 if (lpToolInfo->cbSize < TTTOOLINFOW_V1_SIZE)
2292 return FALSE;
2294 nTool = TOOLTIPS_GetToolFromInfoW (infoPtr, lpToolInfo);
2295 if (nTool == -1)
2296 return 0;
2298 TRACE("tool %d\n", nTool);
2300 toolPtr = &infoPtr->tools[nTool];
2302 /* copy tool text */
2303 toolPtr->hinst = lpToolInfo->hinst;
2305 if (IS_INTRESOURCE(lpToolInfo->lpszText)){
2306 toolPtr->lpszText = lpToolInfo->lpszText;
2308 else if (lpToolInfo->lpszText) {
2309 if (lpToolInfo->lpszText == LPSTR_TEXTCALLBACKW)
2310 toolPtr->lpszText = LPSTR_TEXTCALLBACKW;
2311 else {
2312 if ( (toolPtr->lpszText) &&
2313 !IS_INTRESOURCE(toolPtr->lpszText) ) {
2314 if( toolPtr->lpszText != LPSTR_TEXTCALLBACKW)
2315 Free (toolPtr->lpszText);
2316 toolPtr->lpszText = NULL;
2318 if (lpToolInfo->lpszText) {
2319 INT len = lstrlenW (lpToolInfo->lpszText);
2320 toolPtr->lpszText = Alloc ((len+1)*sizeof(WCHAR));
2321 strcpyW (toolPtr->lpszText, lpToolInfo->lpszText);
2326 if(infoPtr->nCurrentTool == -1) return 0;
2327 /* force repaint */
2328 if (infoPtr->bActive)
2329 TOOLTIPS_Show (hwnd, infoPtr, FALSE);
2330 else if (infoPtr->bTrackActive)
2331 TOOLTIPS_Show (hwnd, infoPtr, TRUE);
2333 return 0;
2337 static LRESULT
2338 TOOLTIPS_WindowFromPoint (HWND hwnd, WPARAM wParam, LPARAM lParam)
2340 return (LRESULT)WindowFromPoint (*((LPPOINT)lParam));
2345 static LRESULT
2346 TOOLTIPS_Create (HWND hwnd, const CREATESTRUCTW *lpcs)
2348 TOOLTIPS_INFO *infoPtr;
2350 /* allocate memory for info structure */
2351 infoPtr = (TOOLTIPS_INFO *)Alloc (sizeof(TOOLTIPS_INFO));
2352 SetWindowLongPtrW (hwnd, 0, (DWORD_PTR)infoPtr);
2354 /* initialize info structure */
2355 infoPtr->bActive = TRUE;
2356 infoPtr->bTrackActive = FALSE;
2358 infoPtr->nMaxTipWidth = -1;
2359 infoPtr->nTool = -1;
2360 infoPtr->nCurrentTool = -1;
2361 infoPtr->nTrackTool = -1;
2363 /* initialize colours and fonts */
2364 TOOLTIPS_InitSystemSettings(infoPtr);
2366 TOOLTIPS_SetDelayTime(hwnd, TTDT_AUTOMATIC, 0L);
2368 SetWindowPos (hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOZORDER | SWP_HIDEWINDOW | SWP_NOACTIVATE);
2370 return 0;
2374 static LRESULT
2375 TOOLTIPS_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
2377 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
2378 TTTOOL_INFO *toolPtr;
2379 UINT i;
2381 /* free tools */
2382 if (infoPtr->tools) {
2383 for (i = 0; i < infoPtr->uNumTools; i++) {
2384 toolPtr = &infoPtr->tools[i];
2385 if (toolPtr->lpszText) {
2386 if ( (toolPtr->lpszText != LPSTR_TEXTCALLBACKW) &&
2387 !IS_INTRESOURCE(toolPtr->lpszText) )
2389 Free (toolPtr->lpszText);
2390 toolPtr->lpszText = NULL;
2394 /* remove subclassing */
2395 if (toolPtr->uFlags & TTF_SUBCLASS) {
2396 if (toolPtr->uFlags & TTF_IDISHWND) {
2397 RemoveWindowSubclass((HWND)toolPtr->uId, TOOLTIPS_SubclassProc, 1);
2399 else {
2400 RemoveWindowSubclass(toolPtr->hwnd, TOOLTIPS_SubclassProc, 1);
2404 Free (infoPtr->tools);
2407 /* free title string */
2408 Free (infoPtr->pszTitle);
2409 /* free title icon if not a standard one */
2410 if (TOOLTIPS_GetTitleIconIndex(infoPtr->hTitleIcon) > TTI_ERROR)
2411 DeleteObject(infoPtr->hTitleIcon);
2413 /* delete fonts */
2414 DeleteObject (infoPtr->hFont);
2415 DeleteObject (infoPtr->hTitleFont);
2417 /* free tool tips info data */
2418 Free (infoPtr);
2419 SetWindowLongPtrW(hwnd, 0, 0);
2420 return 0;
2424 static LRESULT
2425 TOOLTIPS_GetFont (HWND hwnd, WPARAM wParam, LPARAM lParam)
2427 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
2429 return (LRESULT)infoPtr->hFont;
2433 static LRESULT
2434 TOOLTIPS_MouseMessage (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2436 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
2438 TOOLTIPS_Hide (hwnd, infoPtr);
2440 return 0;
2444 static LRESULT
2445 TOOLTIPS_NCCreate (HWND hwnd, WPARAM wParam, LPARAM lParam)
2447 DWORD dwStyle = GetWindowLongW (hwnd, GWL_STYLE);
2448 DWORD dwExStyle = GetWindowLongW (hwnd, GWL_EXSTYLE);
2450 dwStyle &= ~(WS_CHILD | /*WS_MAXIMIZE |*/ WS_BORDER | WS_DLGFRAME);
2451 dwStyle |= (WS_POPUP | WS_BORDER | WS_CLIPSIBLINGS);
2453 /* WS_BORDER only draws a border round the window rect, not the
2454 * window region, therefore it is useless to us in balloon mode */
2455 if (dwStyle & TTS_BALLOON) dwStyle &= ~WS_BORDER;
2457 SetWindowLongW (hwnd, GWL_STYLE, dwStyle);
2459 dwExStyle |= WS_EX_TOOLWINDOW;
2460 SetWindowLongW (hwnd, GWL_EXSTYLE, dwExStyle);
2462 return TRUE;
2466 static LRESULT
2467 TOOLTIPS_NCHitTest (HWND hwnd, WPARAM wParam, LPARAM lParam)
2469 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
2470 INT nTool = (infoPtr->bTrackActive) ? infoPtr->nTrackTool : infoPtr->nTool;
2472 TRACE(" nTool=%d\n", nTool);
2474 if ((nTool > -1) && (nTool < infoPtr->uNumTools)) {
2475 if (infoPtr->tools[nTool].uFlags & TTF_TRANSPARENT) {
2476 TRACE("-- in transparent mode!\n");
2477 return HTTRANSPARENT;
2481 return DefWindowProcW (hwnd, WM_NCHITTEST, wParam, lParam);
2485 static LRESULT
2486 TOOLTIPS_NotifyFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
2488 FIXME ("hwnd=%p wParam=%lx lParam=%lx\n", hwnd, wParam, lParam);
2490 return 0;
2494 static LRESULT
2495 TOOLTIPS_Paint (HWND hwnd, WPARAM wParam, LPARAM lParam)
2497 HDC hdc;
2498 PAINTSTRUCT ps;
2500 hdc = (wParam == 0) ? BeginPaint (hwnd, &ps) : (HDC)wParam;
2501 TOOLTIPS_Refresh (hwnd, hdc);
2502 if (!wParam)
2503 EndPaint (hwnd, &ps);
2504 return 0;
2508 static LRESULT
2509 TOOLTIPS_SetFont (HWND hwnd, WPARAM wParam, LPARAM lParam)
2511 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
2512 LOGFONTW lf;
2514 if(!GetObjectW((HFONT)wParam, sizeof(lf), &lf))
2515 return 0;
2517 DeleteObject (infoPtr->hFont);
2518 infoPtr->hFont = CreateFontIndirectW(&lf);
2520 DeleteObject (infoPtr->hTitleFont);
2521 lf.lfWeight = FW_BOLD;
2522 infoPtr->hTitleFont = CreateFontIndirectW(&lf);
2524 if ((LOWORD(lParam)) & (infoPtr->nCurrentTool != -1)) {
2525 FIXME("full redraw needed!\n");
2528 return 0;
2531 /******************************************************************
2532 * TOOLTIPS_GetTextLength
2534 * This function is called when the tooltip receive a
2535 * WM_GETTEXTLENGTH message.
2536 * wParam : not used
2537 * lParam : not used
2539 * returns the length, in characters, of the tip text
2541 static LRESULT
2542 TOOLTIPS_GetTextLength(HWND hwnd, WPARAM wParam, LPARAM lParam)
2544 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
2545 return strlenW(infoPtr->szTipText);
2548 /******************************************************************
2549 * TOOLTIPS_OnWMGetText
2551 * This function is called when the tooltip receive a
2552 * WM_GETTEXT message.
2553 * wParam : specifies the maximum number of characters to be copied
2554 * lParam : is the pointer to the buffer that will receive
2555 * the tip text
2557 * returns the number of characters copied
2559 static LRESULT
2560 TOOLTIPS_OnWMGetText (HWND hwnd, WPARAM wParam, LPARAM lParam)
2562 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
2563 LRESULT res;
2564 LPWSTR pszText = (LPWSTR)lParam;
2566 if(!infoPtr->szTipText || !wParam)
2567 return 0;
2569 res = min(strlenW(infoPtr->szTipText)+1, wParam);
2570 memcpy(pszText, infoPtr->szTipText, res*sizeof(WCHAR));
2571 pszText[res-1] = '\0';
2572 return res-1;
2575 static LRESULT
2576 TOOLTIPS_Timer (HWND hwnd, WPARAM wParam, LPARAM lParam)
2578 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
2579 INT nOldTool;
2581 TRACE("timer %ld (%p) expired!\n", wParam, hwnd);
2583 switch (wParam) {
2584 case ID_TIMERSHOW:
2585 KillTimer (hwnd, ID_TIMERSHOW);
2586 nOldTool = infoPtr->nTool;
2587 if ((infoPtr->nTool = TOOLTIPS_CheckTool (hwnd, TRUE)) == nOldTool)
2588 TOOLTIPS_Show (hwnd, infoPtr, FALSE);
2589 break;
2591 case ID_TIMERPOP:
2592 TOOLTIPS_Hide (hwnd, infoPtr);
2593 break;
2595 case ID_TIMERLEAVE:
2596 nOldTool = infoPtr->nTool;
2597 infoPtr->nTool = TOOLTIPS_CheckTool (hwnd, FALSE);
2598 TRACE("tool (%p) %d %d %d\n", hwnd, nOldTool,
2599 infoPtr->nTool, infoPtr->nCurrentTool);
2600 if (infoPtr->nTool != nOldTool) {
2601 if(infoPtr->nTool == -1) { /* Moved out of all tools */
2602 TOOLTIPS_Hide(hwnd, infoPtr);
2603 KillTimer(hwnd, ID_TIMERLEAVE);
2604 } else if (nOldTool == -1) { /* Moved from outside */
2605 ERR("How did this happen?\n");
2606 } else { /* Moved from one to another */
2607 TOOLTIPS_Hide (hwnd, infoPtr);
2608 KillTimer(hwnd, ID_TIMERLEAVE);
2609 if(infoPtr->bActive) {
2610 SetTimer (hwnd, ID_TIMERSHOW, infoPtr->nReshowTime, 0);
2611 TRACE("timer 1 started!\n");
2615 break;
2617 default:
2618 ERR("Unknown timer id %ld\n", wParam);
2619 break;
2621 return 0;
2625 static LRESULT
2626 TOOLTIPS_WinIniChange (HWND hwnd, WPARAM wParam, LPARAM lParam)
2628 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
2630 TOOLTIPS_InitSystemSettings (infoPtr);
2632 return 0;
2636 static LRESULT CALLBACK
2637 TOOLTIPS_SubclassProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uID, DWORD_PTR dwRef)
2639 MSG msg;
2641 switch(uMsg) {
2642 case WM_MOUSEMOVE:
2643 case WM_LBUTTONDOWN:
2644 case WM_LBUTTONUP:
2645 case WM_MBUTTONDOWN:
2646 case WM_MBUTTONUP:
2647 case WM_RBUTTONDOWN:
2648 case WM_RBUTTONUP:
2649 msg.hwnd = hwnd;
2650 msg.message = uMsg;
2651 msg.wParam = wParam;
2652 msg.lParam = lParam;
2653 TOOLTIPS_RelayEvent((HWND)dwRef, 0, (LPARAM)&msg);
2654 break;
2656 default:
2657 break;
2659 return DefSubclassProc(hwnd, uMsg, wParam, lParam);
2663 static LRESULT CALLBACK
2664 TOOLTIPS_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2666 TRACE("hwnd=%p msg=%x wparam=%lx lParam=%lx\n", hwnd, uMsg, wParam, lParam);
2667 if (!TOOLTIPS_GetInfoPtr(hwnd) && (uMsg != WM_CREATE) && (uMsg != WM_NCCREATE))
2668 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
2669 switch (uMsg)
2671 case TTM_ACTIVATE:
2672 return TOOLTIPS_Activate (hwnd, wParam, lParam);
2674 case TTM_ADDTOOLA:
2675 return TOOLTIPS_AddToolA (hwnd, wParam, lParam);
2677 case TTM_ADDTOOLW:
2678 return TOOLTIPS_AddToolW (hwnd, wParam, lParam);
2680 case TTM_DELTOOLA:
2681 return TOOLTIPS_DelToolA (hwnd, wParam, lParam);
2683 case TTM_DELTOOLW:
2684 return TOOLTIPS_DelToolW (hwnd, wParam, lParam);
2686 case TTM_ENUMTOOLSA:
2687 return TOOLTIPS_EnumToolsA (hwnd, wParam, lParam);
2689 case TTM_ENUMTOOLSW:
2690 return TOOLTIPS_EnumToolsW (hwnd, wParam, lParam);
2692 case TTM_GETBUBBLESIZE:
2693 return TOOLTIPS_GetBubbleSize (hwnd, wParam, lParam);
2695 case TTM_GETCURRENTTOOLA:
2696 return TOOLTIPS_GetCurrentToolA (hwnd, wParam, lParam);
2698 case TTM_GETCURRENTTOOLW:
2699 return TOOLTIPS_GetCurrentToolW (hwnd, wParam, lParam);
2701 case TTM_GETDELAYTIME:
2702 return TOOLTIPS_GetDelayTime (hwnd, wParam, lParam);
2704 case TTM_GETMARGIN:
2705 return TOOLTIPS_GetMargin (hwnd, wParam, lParam);
2707 case TTM_GETMAXTIPWIDTH:
2708 return TOOLTIPS_GetMaxTipWidth (hwnd, wParam, lParam);
2710 case TTM_GETTEXTA:
2711 return TOOLTIPS_GetTextA (hwnd, wParam, lParam);
2713 case TTM_GETTEXTW:
2714 return TOOLTIPS_GetTextW (hwnd, wParam, lParam);
2716 case TTM_GETTIPBKCOLOR:
2717 return TOOLTIPS_GetTipBkColor (hwnd, wParam, lParam);
2719 case TTM_GETTIPTEXTCOLOR:
2720 return TOOLTIPS_GetTipTextColor (hwnd, wParam, lParam);
2722 case TTM_GETTOOLCOUNT:
2723 return TOOLTIPS_GetToolCount (hwnd, wParam, lParam);
2725 case TTM_GETTOOLINFOA:
2726 return TOOLTIPS_GetToolInfoA (hwnd, wParam, lParam);
2728 case TTM_GETTOOLINFOW:
2729 return TOOLTIPS_GetToolInfoW (hwnd, wParam, lParam);
2731 case TTM_HITTESTA:
2732 return TOOLTIPS_HitTestA (hwnd, wParam, lParam);
2734 case TTM_HITTESTW:
2735 return TOOLTIPS_HitTestW (hwnd, wParam, lParam);
2737 case TTM_NEWTOOLRECTA:
2738 return TOOLTIPS_NewToolRectA (hwnd, wParam, lParam);
2740 case TTM_NEWTOOLRECTW:
2741 return TOOLTIPS_NewToolRectW (hwnd, wParam, lParam);
2743 case TTM_POP:
2744 return TOOLTIPS_Pop (hwnd, wParam, lParam);
2746 case TTM_RELAYEVENT:
2747 return TOOLTIPS_RelayEvent (hwnd, wParam, lParam);
2749 case TTM_SETDELAYTIME:
2750 return TOOLTIPS_SetDelayTime (hwnd, wParam, lParam);
2752 case TTM_SETMARGIN:
2753 return TOOLTIPS_SetMargin (hwnd, wParam, lParam);
2755 case TTM_SETMAXTIPWIDTH:
2756 return TOOLTIPS_SetMaxTipWidth (hwnd, wParam, lParam);
2758 case TTM_SETTIPBKCOLOR:
2759 return TOOLTIPS_SetTipBkColor (hwnd, wParam, lParam);
2761 case TTM_SETTIPTEXTCOLOR:
2762 return TOOLTIPS_SetTipTextColor (hwnd, wParam, lParam);
2764 case TTM_SETTITLEA:
2765 return TOOLTIPS_SetTitleA (hwnd, wParam, lParam);
2767 case TTM_SETTITLEW:
2768 return TOOLTIPS_SetTitleW (hwnd, wParam, lParam);
2770 case TTM_SETTOOLINFOA:
2771 return TOOLTIPS_SetToolInfoA (hwnd, wParam, lParam);
2773 case TTM_SETTOOLINFOW:
2774 return TOOLTIPS_SetToolInfoW (hwnd, wParam, lParam);
2776 case TTM_TRACKACTIVATE:
2777 return TOOLTIPS_TrackActivate (hwnd, wParam, lParam);
2779 case TTM_TRACKPOSITION:
2780 return TOOLTIPS_TrackPosition (hwnd, wParam, lParam);
2782 case TTM_UPDATE:
2783 return TOOLTIPS_Update (hwnd, wParam, lParam);
2785 case TTM_UPDATETIPTEXTA:
2786 return TOOLTIPS_UpdateTipTextA (hwnd, wParam, lParam);
2788 case TTM_UPDATETIPTEXTW:
2789 return TOOLTIPS_UpdateTipTextW (hwnd, wParam, lParam);
2791 case TTM_WINDOWFROMPOINT:
2792 return TOOLTIPS_WindowFromPoint (hwnd, wParam, lParam);
2795 case WM_CREATE:
2796 return TOOLTIPS_Create (hwnd, (LPCREATESTRUCTW)lParam);
2798 case WM_DESTROY:
2799 return TOOLTIPS_Destroy (hwnd, wParam, lParam);
2801 case WM_ERASEBKGND:
2802 /* we draw the background in WM_PAINT */
2803 return 0;
2805 case WM_GETFONT:
2806 return TOOLTIPS_GetFont (hwnd, wParam, lParam);
2808 case WM_GETTEXT:
2809 return TOOLTIPS_OnWMGetText (hwnd, wParam, lParam);
2811 case WM_GETTEXTLENGTH:
2812 return TOOLTIPS_GetTextLength (hwnd, wParam, lParam);
2814 case WM_LBUTTONDOWN:
2815 case WM_LBUTTONUP:
2816 case WM_MBUTTONDOWN:
2817 case WM_MBUTTONUP:
2818 case WM_RBUTTONDOWN:
2819 case WM_RBUTTONUP:
2820 case WM_MOUSEMOVE:
2821 return TOOLTIPS_MouseMessage (hwnd, uMsg, wParam, lParam);
2823 case WM_NCCREATE:
2824 return TOOLTIPS_NCCreate (hwnd, wParam, lParam);
2826 case WM_NCHITTEST:
2827 return TOOLTIPS_NCHitTest (hwnd, wParam, lParam);
2829 case WM_NOTIFYFORMAT:
2830 return TOOLTIPS_NotifyFormat (hwnd, wParam, lParam);
2832 case WM_PRINTCLIENT:
2833 case WM_PAINT:
2834 return TOOLTIPS_Paint (hwnd, wParam, lParam);
2836 case WM_SETFONT:
2837 return TOOLTIPS_SetFont (hwnd, wParam, lParam);
2839 case WM_TIMER:
2840 return TOOLTIPS_Timer (hwnd, wParam, lParam);
2842 case WM_WININICHANGE:
2843 return TOOLTIPS_WinIniChange (hwnd, wParam, lParam);
2845 default:
2846 if ((uMsg >= WM_USER) && (uMsg < WM_APP))
2847 ERR("unknown msg %04x wp=%08lx lp=%08lx\n",
2848 uMsg, wParam, lParam);
2849 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
2854 VOID
2855 TOOLTIPS_Register (void)
2857 WNDCLASSW wndClass;
2859 ZeroMemory (&wndClass, sizeof(WNDCLASSW));
2860 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS | CS_SAVEBITS;
2861 wndClass.lpfnWndProc = TOOLTIPS_WindowProc;
2862 wndClass.cbClsExtra = 0;
2863 wndClass.cbWndExtra = sizeof(TOOLTIPS_INFO *);
2864 wndClass.hCursor = LoadCursorW (0, (LPWSTR)IDC_ARROW);
2865 wndClass.hbrBackground = 0;
2866 wndClass.lpszClassName = TOOLTIPS_CLASSW;
2868 RegisterClassW (&wndClass);
2870 hTooltipIcons[TTI_NONE] = NULL;
2871 hTooltipIcons[TTI_INFO] = LoadImageW(COMCTL32_hModule,
2872 (LPCWSTR)MAKEINTRESOURCE(IDI_TT_INFO_SM), IMAGE_ICON, 0, 0, 0);
2873 hTooltipIcons[TTI_WARNING] = LoadImageW(COMCTL32_hModule,
2874 (LPCWSTR)MAKEINTRESOURCE(IDI_TT_WARN_SM), IMAGE_ICON, 0, 0, 0);
2875 hTooltipIcons[TTI_ERROR] = LoadImageW(COMCTL32_hModule,
2876 (LPCWSTR)MAKEINTRESOURCE(IDI_TT_ERROR_SM), IMAGE_ICON, 0, 0, 0);
2880 VOID
2881 TOOLTIPS_Unregister (void)
2883 int i;
2884 for (i = TTI_INFO; i <= TTI_ERROR; i++)
2885 DestroyIcon(hTooltipIcons[i]);
2886 UnregisterClassW (TOOLTIPS_CLASSW, NULL);