comctl32/tooltips: Test the way structure size field is validated.
[wine/multimedia.git] / dlls / comctl32 / tooltips.c
blob99656d7f058340b0bd74833400269a98346338ee
1 /*
2 * Tool tip control
4 * Copyright 1998, 1999 Eric Kohl
5 * Copyright 2004 Robert Shearman
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 * NOTES
23 * This code was audited for completeness against the documented features
24 * of Comctl32.dll version 6.0 on Sep. 08, 2004, by Robert Shearman.
26 * Unless otherwise noted, we believe this code to be complete, as per
27 * the specification mentioned above.
28 * If you discover missing features or bugs please note them below.
30 * TODO:
31 * - Custom draw support.
32 * - Animation.
33 * - Links.
34 * - Messages:
35 * o TTM_ADJUSTRECT
36 * o TTM_GETTITLEA
37 * o TTM_GETTTILEW
38 * o TTM_POPUP
39 * - Styles:
40 * o TTS_NOANIMATE
41 * o TTS_NOFADE
42 * o TTS_CLOSE
44 * Testing:
45 * - Run tests using Waite Group Windows95 API Bible Volume 2.
46 * The second cdrom (chapter 3) contains executables activate.exe,
47 * curtool.exe, deltool.exe, enumtools.exe, getinfo.exe, getiptxt.exe,
48 * hittest.exe, needtext.exe, newrect.exe, updtext.exe and winfrpt.exe.
50 * Timer logic.
52 * One important point to remember is that tools don't necessarily get
53 * a WM_MOUSEMOVE once the cursor leaves the tool, an example is when
54 * a tool sets TTF_IDISHWND (i.e. an entire window is a tool) because
55 * here WM_MOUSEMOVEs only get sent when the cursor is inside the
56 * client area. Therefore the only reliable way to know that the
57 * cursor has left a tool is to keep a timer running and check the
58 * position every time it expires. This is the role of timer
59 * ID_TIMERLEAVE.
62 * On entering a tool (detected in a relayed WM_MOUSEMOVE) we start
63 * ID_TIMERSHOW, if this times out and we're still in the tool we show
64 * the tip. On showing a tip we start both ID_TIMERPOP and
65 * ID_TIMERLEAVE. On hiding a tooltip we kill ID_TIMERPOP.
66 * ID_TIMERPOP is restarted on every relayed WM_MOUSEMOVE. If
67 * ID_TIMERPOP expires the tool is hidden and ID_TIMERPOP is killed.
68 * ID_TIMERLEAVE remains running - this is important as we need to
69 * determine when the cursor leaves the tool.
71 * When ID_TIMERLEAVE expires or on a relayed WM_MOUSEMOVE if we're
72 * still in the tool do nothing (apart from restart ID_TIMERPOP if
73 * this is a WM_MOUSEMOVE) (ID_TIMERLEAVE remains running). If we've
74 * left the tool and entered another one then hide the tip and start
75 * ID_TIMERSHOW with time ReshowTime and kill ID_TIMERLEAVE. If we're
76 * outside all tools hide the tip and kill ID_TIMERLEAVE. On Relayed
77 * mouse button messages hide the tip but leave ID_TIMERLEAVE running,
78 * this again will let us keep track of when the cursor leaves the
79 * tool.
82 * infoPtr->nTool is the tool the mouse was on on the last relayed MM
83 * or timer expiry or -1 if the mouse was not on a tool.
85 * infoPtr->nCurrentTool is the tool for which the tip is currently
86 * displaying text for or -1 if the tip is not shown. Actually this
87 * will only ever be infoPtr-nTool or -1, so it could be changed to a
88 * BOOL.
94 #include <stdarg.h>
95 #include <string.h>
97 #include "windef.h"
98 #include "winbase.h"
99 #include "wine/unicode.h"
100 #include "wingdi.h"
101 #include "winuser.h"
102 #include "winnls.h"
103 #include "commctrl.h"
104 #include "comctl32.h"
105 #include "wine/debug.h"
107 WINE_DEFAULT_DEBUG_CHANNEL(tooltips);
109 static HICON hTooltipIcons[TTI_ERROR+1];
111 typedef struct
113 UINT uFlags;
114 HWND hwnd;
115 BOOL bNotifyUnicode;
116 UINT_PTR uId;
117 RECT rect;
118 HINSTANCE hinst;
119 LPWSTR lpszText;
120 LPARAM lParam;
121 } TTTOOL_INFO;
124 typedef struct
126 HWND hwndSelf;
127 WCHAR szTipText[INFOTIPSIZE];
128 BOOL bActive;
129 BOOL bTrackActive;
130 UINT uNumTools;
131 COLORREF clrBk;
132 COLORREF clrText;
133 HFONT hFont;
134 HFONT hTitleFont;
135 INT xTrackPos;
136 INT yTrackPos;
137 INT nMaxTipWidth;
138 INT nTool; /* tool that mouse was on on last relayed mouse move */
139 INT nCurrentTool;
140 INT nTrackTool;
141 INT nReshowTime;
142 INT nAutoPopTime;
143 INT nInitialTime;
144 RECT rcMargin;
145 BOOL bToolBelow;
146 LPWSTR pszTitle;
147 HICON hTitleIcon;
149 TTTOOL_INFO *tools;
150 } TOOLTIPS_INFO;
152 #define ID_TIMERSHOW 1 /* show delay timer */
153 #define ID_TIMERPOP 2 /* auto pop timer */
154 #define ID_TIMERLEAVE 3 /* tool leave timer */
157 #define TOOLTIPS_GetInfoPtr(hWindow) ((TOOLTIPS_INFO *)GetWindowLongPtrW (hWindow, 0))
159 /* offsets from window edge to start of text */
160 #define NORMAL_TEXT_MARGIN 2
161 #define BALLOON_TEXT_MARGIN (NORMAL_TEXT_MARGIN+8)
162 /* value used for CreateRoundRectRgn that specifies how much
163 * each corner is curved */
164 #define BALLOON_ROUNDEDNESS 20
165 #define BALLOON_STEMHEIGHT 13
166 #define BALLOON_STEMWIDTH 10
167 #define BALLOON_STEMINDENT 20
169 #define BALLOON_ICON_TITLE_SPACING 8 /* horizontal spacing between icon and title */
170 #define BALLOON_TITLE_TEXT_SPACING 8 /* vertical spacing between icon/title and main text */
171 #define ICON_HEIGHT 16
172 #define ICON_WIDTH 16
174 static LRESULT CALLBACK
175 TOOLTIPS_SubclassProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uId, DWORD_PTR dwRef);
178 static inline UINT_PTR
179 TOOLTIPS_GetTitleIconIndex(HICON hIcon)
181 UINT i;
182 for (i = 0; i <= TTI_ERROR; i++)
183 if (hTooltipIcons[i] == hIcon)
184 return i;
185 return (UINT_PTR)hIcon;
188 static void
189 TOOLTIPS_InitSystemSettings (TOOLTIPS_INFO *infoPtr)
191 NONCLIENTMETRICSW nclm;
193 infoPtr->clrBk = comctl32_color.clrInfoBk;
194 infoPtr->clrText = comctl32_color.clrInfoText;
196 DeleteObject (infoPtr->hFont);
197 nclm.cbSize = sizeof(nclm);
198 SystemParametersInfoW (SPI_GETNONCLIENTMETRICS, sizeof(nclm), &nclm, 0);
199 infoPtr->hFont = CreateFontIndirectW (&nclm.lfStatusFont);
201 DeleteObject (infoPtr->hTitleFont);
202 nclm.lfStatusFont.lfWeight = FW_BOLD;
203 infoPtr->hTitleFont = CreateFontIndirectW (&nclm.lfStatusFont);
206 /* Custom draw routines */
207 static void
208 TOOLTIPS_customdraw_fill(NMTTCUSTOMDRAW *lpnmttcd,
209 const HWND hwnd,
210 HDC hdc, const RECT *rcBounds, UINT uFlags)
212 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr(hwnd);
214 ZeroMemory(lpnmttcd, sizeof(NMTTCUSTOMDRAW));
215 lpnmttcd->uDrawFlags = uFlags;
216 lpnmttcd->nmcd.hdr.hwndFrom = hwnd;
217 lpnmttcd->nmcd.hdr.code = NM_CUSTOMDRAW;
218 if (infoPtr->nCurrentTool != -1) {
219 TTTOOL_INFO *toolPtr = &infoPtr->tools[infoPtr->nCurrentTool];
220 lpnmttcd->nmcd.hdr.idFrom = toolPtr->uId;
222 lpnmttcd->nmcd.hdc = hdc;
223 lpnmttcd->nmcd.rc = *rcBounds;
224 /* FIXME - dwItemSpec, uItemState, lItemlParam */
227 static inline DWORD
228 TOOLTIPS_notify_customdraw (DWORD dwDrawStage, NMTTCUSTOMDRAW *lpnmttcd)
230 LRESULT result = CDRF_DODEFAULT;
231 lpnmttcd->nmcd.dwDrawStage = dwDrawStage;
233 TRACE("Notifying stage %d, flags %x, id %x\n", lpnmttcd->nmcd.dwDrawStage,
234 lpnmttcd->uDrawFlags, lpnmttcd->nmcd.hdr.code);
236 result = SendMessageW(GetParent(lpnmttcd->nmcd.hdr.hwndFrom), WM_NOTIFY,
237 0, (LPARAM)lpnmttcd);
239 TRACE("Notify result %x\n", (unsigned int)result);
241 return result;
244 static void
245 TOOLTIPS_Refresh (const TOOLTIPS_INFO *infoPtr, HDC hdc)
247 RECT rc;
248 INT oldBkMode;
249 HFONT hOldFont;
250 HBRUSH hBrush;
251 UINT uFlags = DT_EXTERNALLEADING;
252 HRGN hRgn = NULL;
253 DWORD dwStyle = GetWindowLongW(infoPtr->hwndSelf, GWL_STYLE);
254 NMTTCUSTOMDRAW nmttcd;
255 DWORD cdmode;
257 if (infoPtr->nMaxTipWidth > -1)
258 uFlags |= DT_WORDBREAK;
259 if (GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE) & TTS_NOPREFIX)
260 uFlags |= DT_NOPREFIX;
261 GetClientRect (infoPtr->hwndSelf, &rc);
263 hBrush = CreateSolidBrush(infoPtr->clrBk);
265 oldBkMode = SetBkMode (hdc, TRANSPARENT);
266 SetTextColor (hdc, infoPtr->clrText);
267 hOldFont = SelectObject (hdc, infoPtr->hFont);
269 /* Custom draw - Call PrePaint once initial properties set up */
270 /* Note: Contrary to MSDN, CDRF_SKIPDEFAULT still draws a tooltip */
271 TOOLTIPS_customdraw_fill(&nmttcd, infoPtr->hwndSelf, hdc, &rc, uFlags);
272 cdmode = TOOLTIPS_notify_customdraw(CDDS_PREPAINT, &nmttcd);
273 uFlags = nmttcd.uDrawFlags;
275 if (dwStyle & TTS_BALLOON)
277 /* create a region to store result into */
278 hRgn = CreateRectRgn(0, 0, 0, 0);
280 GetWindowRgn(infoPtr->hwndSelf, hRgn);
282 /* fill the background */
283 FillRgn(hdc, hRgn, hBrush);
284 DeleteObject(hBrush);
285 hBrush = NULL;
287 else
289 /* fill the background */
290 FillRect(hdc, &rc, hBrush);
291 DeleteObject(hBrush);
292 hBrush = NULL;
295 if ((dwStyle & TTS_BALLOON) || infoPtr->pszTitle)
297 /* calculate text rectangle */
298 rc.left += (BALLOON_TEXT_MARGIN + infoPtr->rcMargin.left);
299 rc.top += (BALLOON_TEXT_MARGIN + infoPtr->rcMargin.top);
300 rc.right -= (BALLOON_TEXT_MARGIN + infoPtr->rcMargin.right);
301 rc.bottom -= (BALLOON_TEXT_MARGIN + infoPtr->rcMargin.bottom);
302 if(infoPtr->bToolBelow) rc.top += BALLOON_STEMHEIGHT;
304 if (infoPtr->pszTitle)
306 RECT rcTitle = {rc.left, rc.top, rc.right, rc.bottom};
307 int height;
308 BOOL icon_present;
309 HFONT prevFont;
311 /* draw icon */
312 icon_present = infoPtr->hTitleIcon &&
313 DrawIconEx(hdc, rc.left, rc.top, infoPtr->hTitleIcon,
314 ICON_WIDTH, ICON_HEIGHT, 0, NULL, DI_NORMAL);
315 if (icon_present)
316 rcTitle.left += ICON_WIDTH + BALLOON_ICON_TITLE_SPACING;
318 rcTitle.bottom = rc.top + ICON_HEIGHT;
320 /* draw title text */
321 prevFont = SelectObject (hdc, infoPtr->hTitleFont);
322 height = DrawTextW(hdc, infoPtr->pszTitle, -1, &rcTitle, DT_BOTTOM | DT_SINGLELINE | DT_NOPREFIX);
323 SelectObject (hdc, prevFont);
324 rc.top += height + BALLOON_TITLE_TEXT_SPACING;
327 else
329 /* calculate text rectangle */
330 rc.left += (NORMAL_TEXT_MARGIN + infoPtr->rcMargin.left);
331 rc.top += (NORMAL_TEXT_MARGIN + infoPtr->rcMargin.top);
332 rc.right -= (NORMAL_TEXT_MARGIN + infoPtr->rcMargin.right);
333 rc.bottom -= (NORMAL_TEXT_MARGIN + infoPtr->rcMargin.bottom);
336 /* draw text */
337 DrawTextW (hdc, infoPtr->szTipText, -1, &rc, uFlags);
339 /* Custom draw - Call PostPaint after drawing */
340 if (cdmode & CDRF_NOTIFYPOSTPAINT) {
341 TOOLTIPS_notify_customdraw(CDDS_POSTPAINT, &nmttcd);
344 /* be polite and reset the things we changed in the dc */
345 SelectObject (hdc, hOldFont);
346 SetBkMode (hdc, oldBkMode);
348 if (dwStyle & TTS_BALLOON)
350 /* frame region because default window proc doesn't do it */
351 INT width = GetSystemMetrics(SM_CXDLGFRAME) - GetSystemMetrics(SM_CXEDGE);
352 INT height = GetSystemMetrics(SM_CYDLGFRAME) - GetSystemMetrics(SM_CYEDGE);
354 hBrush = GetSysColorBrush(COLOR_WINDOWFRAME);
355 FrameRgn(hdc, hRgn, hBrush, width, height);
358 if (hRgn)
359 DeleteObject(hRgn);
362 static void TOOLTIPS_GetDispInfoA(const TOOLTIPS_INFO *infoPtr, TTTOOL_INFO *toolPtr, WCHAR *buffer)
364 NMTTDISPINFOA ttnmdi;
366 /* fill NMHDR struct */
367 ZeroMemory (&ttnmdi, sizeof(NMTTDISPINFOA));
368 ttnmdi.hdr.hwndFrom = infoPtr->hwndSelf;
369 ttnmdi.hdr.idFrom = toolPtr->uId;
370 ttnmdi.hdr.code = TTN_GETDISPINFOA; /* == TTN_NEEDTEXTA */
371 ttnmdi.lpszText = ttnmdi.szText;
372 ttnmdi.uFlags = toolPtr->uFlags;
373 ttnmdi.lParam = toolPtr->lParam;
375 TRACE("hdr.idFrom = %lx\n", ttnmdi.hdr.idFrom);
376 SendMessageW(toolPtr->hwnd, WM_NOTIFY, toolPtr->uId, (LPARAM)&ttnmdi);
378 if (IS_INTRESOURCE(ttnmdi.lpszText)) {
379 LoadStringW(ttnmdi.hinst, LOWORD(ttnmdi.lpszText),
380 buffer, 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 buffer[0] = '\0';
389 else if (ttnmdi.lpszText != LPSTR_TEXTCALLBACKA) {
390 Str_GetPtrAtoW(ttnmdi.lpszText, buffer, INFOTIPSIZE);
391 if (ttnmdi.uFlags & TTF_DI_SETITEM) {
392 toolPtr->hinst = 0;
393 toolPtr->lpszText = NULL;
394 Str_SetPtrW(&toolPtr->lpszText, buffer);
397 else {
398 ERR("recursive text callback!\n");
399 buffer[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 (buffer[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 buffer, INFOTIPSIZE);
411 } else if (ttnmdi.lpszText &&
412 ttnmdi.lpszText != LPSTR_TEXTCALLBACKA) {
413 Str_GetPtrAtoW(ttnmdi.lpszText, buffer, INFOTIPSIZE);
418 static void TOOLTIPS_GetDispInfoW(const TOOLTIPS_INFO *infoPtr, TTTOOL_INFO *toolPtr, WCHAR *buffer)
420 NMTTDISPINFOW ttnmdi;
422 /* fill NMHDR struct */
423 ZeroMemory (&ttnmdi, sizeof(NMTTDISPINFOW));
424 ttnmdi.hdr.hwndFrom = infoPtr->hwndSelf;
425 ttnmdi.hdr.idFrom = toolPtr->uId;
426 ttnmdi.hdr.code = TTN_GETDISPINFOW; /* == TTN_NEEDTEXTW */
427 ttnmdi.lpszText = ttnmdi.szText;
428 ttnmdi.uFlags = toolPtr->uFlags;
429 ttnmdi.lParam = toolPtr->lParam;
431 TRACE("hdr.idFrom = %lx\n", ttnmdi.hdr.idFrom);
432 SendMessageW(toolPtr->hwnd, WM_NOTIFY, toolPtr->uId, (LPARAM)&ttnmdi);
434 if (IS_INTRESOURCE(ttnmdi.lpszText)) {
435 LoadStringW(ttnmdi.hinst, LOWORD(ttnmdi.lpszText),
436 buffer, 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 buffer[0] = '\0';
445 else if (ttnmdi.lpszText != LPSTR_TEXTCALLBACKW) {
446 Str_GetPtrW(ttnmdi.lpszText, buffer, INFOTIPSIZE);
447 if (ttnmdi.uFlags & TTF_DI_SETITEM) {
448 toolPtr->hinst = 0;
449 toolPtr->lpszText = NULL;
450 Str_SetPtrW(&toolPtr->lpszText, buffer);
453 else {
454 ERR("recursive text callback!\n");
455 buffer[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 (buffer[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 buffer, INFOTIPSIZE);
467 } else if (ttnmdi.lpszText &&
468 ttnmdi.lpszText != LPSTR_TEXTCALLBACKW) {
469 Str_GetPtrW(ttnmdi.lpszText, buffer, INFOTIPSIZE);
475 static void
476 TOOLTIPS_GetTipText (const TOOLTIPS_INFO *infoPtr, INT nTool, WCHAR *buffer)
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 buffer, INFOTIPSIZE);
487 else if (toolPtr->lpszText) {
488 if (toolPtr->lpszText == LPSTR_TEXTCALLBACKW) {
489 if (toolPtr->bNotifyUnicode)
490 TOOLTIPS_GetDispInfoW(infoPtr, toolPtr, buffer);
491 else
492 TOOLTIPS_GetDispInfoA(infoPtr, toolPtr, buffer);
494 else {
495 /* the item is a usual (unicode) text */
496 lstrcpynW (buffer, toolPtr->lpszText, INFOTIPSIZE);
499 else {
500 /* no text available */
501 buffer[0] = '\0';
504 TRACE("%s\n", debugstr_w(buffer));
508 static void
509 TOOLTIPS_CalcTipSize (const TOOLTIPS_INFO *infoPtr, LPSIZE lpSize)
511 HDC hdc;
512 HFONT hOldFont;
513 DWORD style = GetWindowLongW(infoPtr->hwndSelf, GWL_STYLE);
514 UINT uFlags = DT_EXTERNALLEADING | DT_CALCRECT;
515 RECT rc = {0, 0, 0, 0};
516 SIZE title = {0, 0};
518 if (infoPtr->nMaxTipWidth > -1) {
519 rc.right = infoPtr->nMaxTipWidth;
520 uFlags |= DT_WORDBREAK;
522 if (style & TTS_NOPREFIX)
523 uFlags |= DT_NOPREFIX;
524 TRACE("%s\n", debugstr_w(infoPtr->szTipText));
526 hdc = GetDC (infoPtr->hwndSelf);
527 if (infoPtr->pszTitle)
529 RECT rcTitle = {0, 0, 0, 0};
530 TRACE("title %s\n", debugstr_w(infoPtr->pszTitle));
531 if (infoPtr->hTitleIcon)
533 title.cx = ICON_WIDTH;
534 title.cy = ICON_HEIGHT;
536 if (title.cx != 0) title.cx += BALLOON_ICON_TITLE_SPACING;
537 hOldFont = SelectObject (hdc, infoPtr->hTitleFont);
538 DrawTextW(hdc, infoPtr->pszTitle, -1, &rcTitle, DT_SINGLELINE | DT_NOPREFIX | DT_CALCRECT);
539 SelectObject (hdc, hOldFont);
540 title.cy = max(title.cy, rcTitle.bottom - rcTitle.top) + BALLOON_TITLE_TEXT_SPACING;
541 title.cx += (rcTitle.right - rcTitle.left);
543 hOldFont = SelectObject (hdc, infoPtr->hFont);
544 DrawTextW (hdc, infoPtr->szTipText, -1, &rc, uFlags);
545 SelectObject (hdc, hOldFont);
546 ReleaseDC (infoPtr->hwndSelf, hdc);
548 if ((style & TTS_BALLOON) || infoPtr->pszTitle)
550 lpSize->cx = max(rc.right - rc.left, title.cx) + 2*BALLOON_TEXT_MARGIN +
551 infoPtr->rcMargin.left + infoPtr->rcMargin.right;
552 lpSize->cy = title.cy + rc.bottom - rc.top + 2*BALLOON_TEXT_MARGIN +
553 infoPtr->rcMargin.bottom + infoPtr->rcMargin.top +
554 BALLOON_STEMHEIGHT;
556 else
558 lpSize->cx = rc.right - rc.left + 2*NORMAL_TEXT_MARGIN +
559 infoPtr->rcMargin.left + infoPtr->rcMargin.right;
560 lpSize->cy = rc.bottom - rc.top + 2*NORMAL_TEXT_MARGIN +
561 infoPtr->rcMargin.bottom + infoPtr->rcMargin.top;
566 static void
567 TOOLTIPS_Show (TOOLTIPS_INFO *infoPtr, BOOL track_activate)
569 TTTOOL_INFO *toolPtr;
570 HMONITOR monitor;
571 MONITORINFO mon_info;
572 RECT rect;
573 SIZE size;
574 NMHDR hdr;
575 int ptfx = 0;
576 DWORD style = GetWindowLongW(infoPtr->hwndSelf, GWL_STYLE);
577 INT nTool;
579 if (track_activate)
581 if (infoPtr->nTrackTool == -1)
583 TRACE("invalid tracking tool (-1)!\n");
584 return;
586 nTool = infoPtr->nTrackTool;
588 else
590 if (infoPtr->nTool == -1)
592 TRACE("invalid tool (-1)!\n");
593 return;
595 nTool = infoPtr->nTool;
598 TRACE("Show tooltip pre %d! (%p)\n", nTool, infoPtr->hwndSelf);
600 TOOLTIPS_GetTipText (infoPtr, nTool, infoPtr->szTipText);
602 if (infoPtr->szTipText[0] == '\0')
603 return;
605 toolPtr = &infoPtr->tools[nTool];
607 if (!track_activate)
608 infoPtr->nCurrentTool = infoPtr->nTool;
610 TRACE("Show tooltip %d!\n", nTool);
612 hdr.hwndFrom = infoPtr->hwndSelf;
613 hdr.idFrom = toolPtr->uId;
614 hdr.code = TTN_SHOW;
615 SendMessageW (toolPtr->hwnd, WM_NOTIFY, toolPtr->uId, (LPARAM)&hdr);
617 TRACE("%s\n", debugstr_w(infoPtr->szTipText));
619 TOOLTIPS_CalcTipSize (infoPtr, &size);
620 TRACE("size %d x %d\n", size.cx, size.cy);
622 if (track_activate)
624 rect.left = infoPtr->xTrackPos;
625 rect.top = infoPtr->yTrackPos;
626 ptfx = rect.left;
628 if (toolPtr->uFlags & TTF_CENTERTIP)
630 rect.left -= (size.cx / 2);
631 if (!(style & TTS_BALLOON))
632 rect.top -= (size.cy / 2);
634 infoPtr->bToolBelow = TRUE;
636 if (!(toolPtr->uFlags & TTF_ABSOLUTE))
638 if (style & TTS_BALLOON)
639 rect.left -= BALLOON_STEMINDENT;
640 else
642 RECT rcTool;
644 if (toolPtr->uFlags & TTF_IDISHWND)
645 GetWindowRect ((HWND)toolPtr->uId, &rcTool);
646 else
648 rcTool = toolPtr->rect;
649 MapWindowPoints (toolPtr->hwnd, NULL, (LPPOINT)&rcTool, 2);
652 /* smart placement */
653 if ((rect.left + size.cx > rcTool.left) && (rect.left < rcTool.right) &&
654 (rect.top + size.cy > rcTool.top) && (rect.top < rcTool.bottom))
655 rect.left = rcTool.right;
659 else
661 if (toolPtr->uFlags & TTF_CENTERTIP)
663 RECT rc;
665 if (toolPtr->uFlags & TTF_IDISHWND)
666 GetWindowRect ((HWND)toolPtr->uId, &rc);
667 else {
668 rc = toolPtr->rect;
669 MapWindowPoints (toolPtr->hwnd, NULL, (LPPOINT)&rc, 2);
671 rect.left = (rc.left + rc.right - size.cx) / 2;
672 if (style & TTS_BALLOON)
674 ptfx = rc.left + ((rc.right - rc.left) / 2);
676 /* CENTERTIP ballon tooltips default to below the field
677 * if they fit on the screen */
678 if (rc.bottom + size.cy > GetSystemMetrics(SM_CYSCREEN))
680 rect.top = rc.top - size.cy;
681 infoPtr->bToolBelow = FALSE;
683 else
685 infoPtr->bToolBelow = TRUE;
686 rect.top = rc.bottom;
688 rect.left = max(0, rect.left - BALLOON_STEMINDENT);
690 else
692 rect.top = rc.bottom + 2;
693 infoPtr->bToolBelow = TRUE;
696 else
698 GetCursorPos ((LPPOINT)&rect);
699 if (style & TTS_BALLOON)
701 ptfx = rect.left;
702 if(rect.top - size.cy >= 0)
704 rect.top -= size.cy;
705 infoPtr->bToolBelow = FALSE;
707 else
709 infoPtr->bToolBelow = TRUE;
710 rect.top += 20;
712 rect.left = max(0, rect.left - BALLOON_STEMINDENT);
714 else
716 rect.top += 20;
717 infoPtr->bToolBelow = TRUE;
722 TRACE("pos %d - %d\n", rect.left, rect.top);
724 rect.right = rect.left + size.cx;
725 rect.bottom = rect.top + size.cy;
727 /* check position */
729 monitor = MonitorFromRect( &rect, MONITOR_DEFAULTTOPRIMARY );
730 mon_info.cbSize = sizeof(mon_info);
731 GetMonitorInfoW( monitor, &mon_info );
733 if( rect.right > mon_info.rcWork.right ) {
734 rect.left -= rect.right - mon_info.rcWork.right + 2;
735 rect.right = mon_info.rcWork.right - 2;
737 if (rect.left < mon_info.rcWork.left) rect.left = mon_info.rcWork.left;
739 if( rect.bottom > mon_info.rcWork.bottom ) {
740 RECT rc;
742 if (toolPtr->uFlags & TTF_IDISHWND)
743 GetWindowRect ((HWND)toolPtr->uId, &rc);
744 else {
745 rc = toolPtr->rect;
746 MapWindowPoints (toolPtr->hwnd, NULL, (LPPOINT)&rc, 2);
748 rect.bottom = rc.top - 2;
749 rect.top = rect.bottom - size.cy;
752 AdjustWindowRectEx (&rect, GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE),
753 FALSE, GetWindowLongW (infoPtr->hwndSelf, GWL_EXSTYLE));
755 if (style & TTS_BALLOON)
757 HRGN hRgn;
758 HRGN hrStem;
759 POINT pts[3];
761 ptfx -= rect.left;
763 if(infoPtr->bToolBelow)
765 pts[0].x = ptfx;
766 pts[0].y = 0;
767 pts[1].x = max(BALLOON_STEMINDENT, ptfx - (BALLOON_STEMWIDTH / 2));
768 pts[1].y = BALLOON_STEMHEIGHT;
769 pts[2].x = pts[1].x + BALLOON_STEMWIDTH;
770 pts[2].y = pts[1].y;
771 if(pts[2].x > (rect.right - rect.left) - BALLOON_STEMINDENT)
773 pts[2].x = (rect.right - rect.left) - BALLOON_STEMINDENT;
774 pts[1].x = pts[2].x - BALLOON_STEMWIDTH;
777 else
779 pts[0].x = max(BALLOON_STEMINDENT, ptfx - (BALLOON_STEMWIDTH / 2));
780 pts[0].y = (rect.bottom - rect.top) - BALLOON_STEMHEIGHT;
781 pts[1].x = pts[0].x + BALLOON_STEMWIDTH;
782 pts[1].y = pts[0].y;
783 pts[2].x = ptfx;
784 pts[2].y = (rect.bottom - rect.top);
785 if(pts[1].x > (rect.right - rect.left) - BALLOON_STEMINDENT)
787 pts[1].x = (rect.right - rect.left) - BALLOON_STEMINDENT;
788 pts[0].x = pts[1].x - BALLOON_STEMWIDTH;
792 hrStem = CreatePolygonRgn(pts, sizeof(pts) / sizeof(pts[0]), ALTERNATE);
794 hRgn = CreateRoundRectRgn(0,
795 (infoPtr->bToolBelow ? BALLOON_STEMHEIGHT : 0),
796 rect.right - rect.left,
797 (infoPtr->bToolBelow ? rect.bottom - rect.top : rect.bottom - rect.top - BALLOON_STEMHEIGHT),
798 BALLOON_ROUNDEDNESS, BALLOON_ROUNDEDNESS);
800 CombineRgn(hRgn, hRgn, hrStem, RGN_OR);
801 DeleteObject(hrStem);
803 SetWindowRgn(infoPtr->hwndSelf, hRgn, FALSE);
804 /* we don't free the region handle as the system deletes it when
805 * it is no longer needed */
808 SetWindowPos (infoPtr->hwndSelf, HWND_TOPMOST, rect.left, rect.top,
809 rect.right - rect.left, rect.bottom - rect.top,
810 SWP_SHOWWINDOW | SWP_NOACTIVATE);
812 /* repaint the tooltip */
813 InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
814 UpdateWindow(infoPtr->hwndSelf);
816 if (!track_activate)
818 SetTimer (infoPtr->hwndSelf, ID_TIMERPOP, infoPtr->nAutoPopTime, 0);
819 TRACE("timer 2 started!\n");
820 SetTimer (infoPtr->hwndSelf, ID_TIMERLEAVE, infoPtr->nReshowTime, 0);
821 TRACE("timer 3 started!\n");
826 static void
827 TOOLTIPS_Hide (TOOLTIPS_INFO *infoPtr)
829 TTTOOL_INFO *toolPtr;
830 NMHDR hdr;
832 TRACE("Hide tooltip %d! (%p)\n", infoPtr->nCurrentTool, infoPtr->hwndSelf);
834 if (infoPtr->nCurrentTool == -1)
835 return;
837 toolPtr = &infoPtr->tools[infoPtr->nCurrentTool];
838 KillTimer (infoPtr->hwndSelf, ID_TIMERPOP);
840 hdr.hwndFrom = infoPtr->hwndSelf;
841 hdr.idFrom = toolPtr->uId;
842 hdr.code = TTN_POP;
843 SendMessageW (toolPtr->hwnd, WM_NOTIFY, toolPtr->uId, (LPARAM)&hdr);
845 infoPtr->nCurrentTool = -1;
847 SetWindowPos (infoPtr->hwndSelf, HWND_TOP, 0, 0, 0, 0,
848 SWP_NOZORDER | SWP_HIDEWINDOW | SWP_NOACTIVATE);
852 static void
853 TOOLTIPS_TrackShow (TOOLTIPS_INFO *infoPtr)
855 TOOLTIPS_Show(infoPtr, TRUE);
859 static void
860 TOOLTIPS_TrackHide (const TOOLTIPS_INFO *infoPtr)
862 TTTOOL_INFO *toolPtr;
863 NMHDR hdr;
865 TRACE("hide tracking tooltip %d\n", infoPtr->nTrackTool);
867 if (infoPtr->nTrackTool == -1)
868 return;
870 toolPtr = &infoPtr->tools[infoPtr->nTrackTool];
872 hdr.hwndFrom = infoPtr->hwndSelf;
873 hdr.idFrom = toolPtr->uId;
874 hdr.code = TTN_POP;
875 SendMessageW (toolPtr->hwnd, WM_NOTIFY, toolPtr->uId, (LPARAM)&hdr);
877 SetWindowPos (infoPtr->hwndSelf, HWND_TOP, 0, 0, 0, 0,
878 SWP_NOZORDER | SWP_HIDEWINDOW | SWP_NOACTIVATE);
882 static INT
883 TOOLTIPS_GetToolFromInfoA (const TOOLTIPS_INFO *infoPtr, const TTTOOLINFOA *lpToolInfo)
885 TTTOOL_INFO *toolPtr;
886 UINT nTool;
888 for (nTool = 0; nTool < infoPtr->uNumTools; nTool++) {
889 toolPtr = &infoPtr->tools[nTool];
891 if (!(toolPtr->uFlags & TTF_IDISHWND) &&
892 (lpToolInfo->hwnd == toolPtr->hwnd) &&
893 (lpToolInfo->uId == toolPtr->uId))
894 return nTool;
897 for (nTool = 0; nTool < infoPtr->uNumTools; nTool++) {
898 toolPtr = &infoPtr->tools[nTool];
900 if ((toolPtr->uFlags & TTF_IDISHWND) &&
901 (lpToolInfo->uId == toolPtr->uId))
902 return nTool;
905 return -1;
909 static INT
910 TOOLTIPS_GetToolFromInfoW (const TOOLTIPS_INFO *infoPtr, const TTTOOLINFOW *lpToolInfo)
912 TTTOOL_INFO *toolPtr;
913 UINT nTool;
915 for (nTool = 0; nTool < infoPtr->uNumTools; nTool++) {
916 toolPtr = &infoPtr->tools[nTool];
918 if (!(toolPtr->uFlags & TTF_IDISHWND) &&
919 (lpToolInfo->hwnd == toolPtr->hwnd) &&
920 (lpToolInfo->uId == toolPtr->uId))
921 return nTool;
924 for (nTool = 0; nTool < infoPtr->uNumTools; nTool++) {
925 toolPtr = &infoPtr->tools[nTool];
927 if ((toolPtr->uFlags & TTF_IDISHWND) &&
928 (lpToolInfo->uId == toolPtr->uId))
929 return nTool;
932 return -1;
936 static INT
937 TOOLTIPS_GetToolFromPoint (const TOOLTIPS_INFO *infoPtr, HWND hwnd, const POINT *lpPt)
939 TTTOOL_INFO *toolPtr;
940 UINT nTool;
942 for (nTool = 0; nTool < infoPtr->uNumTools; nTool++) {
943 toolPtr = &infoPtr->tools[nTool];
945 if (!(toolPtr->uFlags & TTF_IDISHWND)) {
946 if (hwnd != toolPtr->hwnd)
947 continue;
948 if (!PtInRect (&toolPtr->rect, *lpPt))
949 continue;
950 return nTool;
954 for (nTool = 0; nTool < infoPtr->uNumTools; nTool++) {
955 toolPtr = &infoPtr->tools[nTool];
957 if (toolPtr->uFlags & TTF_IDISHWND) {
958 if ((HWND)toolPtr->uId == hwnd)
959 return nTool;
963 return -1;
967 static BOOL
968 TOOLTIPS_IsWindowActive (HWND hwnd)
970 HWND hwndActive = GetActiveWindow ();
971 if (!hwndActive)
972 return FALSE;
973 if (hwndActive == hwnd)
974 return TRUE;
975 return IsChild (hwndActive, hwnd);
979 static INT
980 TOOLTIPS_CheckTool (const TOOLTIPS_INFO *infoPtr, BOOL bShowTest)
982 POINT pt;
983 HWND hwndTool;
984 INT nTool;
986 GetCursorPos (&pt);
987 hwndTool = (HWND)SendMessageW (infoPtr->hwndSelf, TTM_WINDOWFROMPOINT, 0, (LPARAM)&pt);
988 if (hwndTool == 0)
989 return -1;
991 ScreenToClient (hwndTool, &pt);
992 nTool = TOOLTIPS_GetToolFromPoint (infoPtr, hwndTool, &pt);
993 if (nTool == -1)
994 return -1;
996 if (!(GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE) & TTS_ALWAYSTIP) && bShowTest) {
997 if (!TOOLTIPS_IsWindowActive (GetWindow (infoPtr->hwndSelf, GW_OWNER)))
998 return -1;
1001 TRACE("tool %d\n", nTool);
1003 return nTool;
1007 static LRESULT
1008 TOOLTIPS_Activate (TOOLTIPS_INFO *infoPtr, BOOL activate)
1010 infoPtr->bActive = activate;
1012 if (infoPtr->bActive)
1013 TRACE("activate!\n");
1015 if (!(infoPtr->bActive) && (infoPtr->nCurrentTool != -1))
1016 TOOLTIPS_Hide (infoPtr);
1018 return 0;
1022 static LRESULT
1023 TOOLTIPS_AddToolA (TOOLTIPS_INFO *infoPtr, const TTTOOLINFOA *lpToolInfo)
1025 TTTOOL_INFO *toolPtr;
1026 INT nResult;
1028 if (lpToolInfo == NULL)
1029 return FALSE;
1031 TRACE("add tool (%p) %p %ld%s!\n",
1032 infoPtr->hwndSelf, lpToolInfo->hwnd, lpToolInfo->uId,
1033 (lpToolInfo->uFlags & TTF_IDISHWND) ? " TTF_IDISHWND" : "");
1035 if (infoPtr->uNumTools == 0) {
1036 infoPtr->tools = Alloc (sizeof(TTTOOL_INFO));
1037 toolPtr = infoPtr->tools;
1039 else {
1040 TTTOOL_INFO *oldTools = infoPtr->tools;
1041 infoPtr->tools =
1042 Alloc (sizeof(TTTOOL_INFO) * (infoPtr->uNumTools + 1));
1043 memcpy (infoPtr->tools, oldTools,
1044 infoPtr->uNumTools * sizeof(TTTOOL_INFO));
1045 Free (oldTools);
1046 toolPtr = &infoPtr->tools[infoPtr->uNumTools];
1049 infoPtr->uNumTools++;
1051 /* copy tool data */
1052 toolPtr->uFlags = lpToolInfo->uFlags;
1053 toolPtr->hwnd = lpToolInfo->hwnd;
1054 toolPtr->uId = lpToolInfo->uId;
1055 toolPtr->rect = lpToolInfo->rect;
1056 toolPtr->hinst = lpToolInfo->hinst;
1058 if (IS_INTRESOURCE(lpToolInfo->lpszText)) {
1059 TRACE("add string id %x!\n", LOWORD(lpToolInfo->lpszText));
1060 toolPtr->lpszText = (LPWSTR)lpToolInfo->lpszText;
1062 else if (lpToolInfo->lpszText) {
1063 if (lpToolInfo->lpszText == LPSTR_TEXTCALLBACKA) {
1064 TRACE("add CALLBACK!\n");
1065 toolPtr->lpszText = LPSTR_TEXTCALLBACKW;
1067 else {
1068 INT len = MultiByteToWideChar(CP_ACP, 0, lpToolInfo->lpszText, -1,
1069 NULL, 0);
1070 TRACE("add text \"%s\"!\n", lpToolInfo->lpszText);
1071 toolPtr->lpszText = Alloc (len * sizeof(WCHAR));
1072 MultiByteToWideChar(CP_ACP, 0, lpToolInfo->lpszText, -1,
1073 toolPtr->lpszText, len);
1077 if (lpToolInfo->cbSize >= TTTOOLINFOA_V2_SIZE)
1078 toolPtr->lParam = lpToolInfo->lParam;
1080 /* install subclassing hook */
1081 if (toolPtr->uFlags & TTF_SUBCLASS) {
1082 if (toolPtr->uFlags & TTF_IDISHWND) {
1083 SetWindowSubclass((HWND)toolPtr->uId, TOOLTIPS_SubclassProc, 1,
1084 (DWORD_PTR)infoPtr->hwndSelf);
1086 else {
1087 SetWindowSubclass(toolPtr->hwnd, TOOLTIPS_SubclassProc, 1,
1088 (DWORD_PTR)infoPtr->hwndSelf);
1090 TRACE("subclassing installed!\n");
1093 nResult = (INT) SendMessageW (toolPtr->hwnd, WM_NOTIFYFORMAT,
1094 (WPARAM)infoPtr->hwndSelf, (LPARAM)NF_QUERY);
1095 if (nResult == NFR_ANSI) {
1096 toolPtr->bNotifyUnicode = FALSE;
1097 TRACE(" -- WM_NOTIFYFORMAT returns: NFR_ANSI\n");
1098 } else if (nResult == NFR_UNICODE) {
1099 toolPtr->bNotifyUnicode = TRUE;
1100 TRACE(" -- WM_NOTIFYFORMAT returns: NFR_UNICODE\n");
1101 } else {
1102 TRACE (" -- WM_NOTIFYFORMAT returns: error!\n");
1105 return TRUE;
1109 static LRESULT
1110 TOOLTIPS_AddToolW (TOOLTIPS_INFO *infoPtr, const TTTOOLINFOW *lpToolInfo)
1112 TTTOOL_INFO *toolPtr;
1113 INT nResult;
1115 if (lpToolInfo == NULL)
1116 return FALSE;
1118 TRACE("add tool (%p) %p %ld%s!\n",
1119 infoPtr->hwndSelf, lpToolInfo->hwnd, lpToolInfo->uId,
1120 (lpToolInfo->uFlags & TTF_IDISHWND) ? " TTF_IDISHWND" : "");
1122 if (infoPtr->uNumTools == 0) {
1123 infoPtr->tools = Alloc (sizeof(TTTOOL_INFO));
1124 toolPtr = infoPtr->tools;
1126 else {
1127 TTTOOL_INFO *oldTools = infoPtr->tools;
1128 infoPtr->tools =
1129 Alloc (sizeof(TTTOOL_INFO) * (infoPtr->uNumTools + 1));
1130 memcpy (infoPtr->tools, oldTools,
1131 infoPtr->uNumTools * sizeof(TTTOOL_INFO));
1132 Free (oldTools);
1133 toolPtr = &infoPtr->tools[infoPtr->uNumTools];
1136 infoPtr->uNumTools++;
1138 /* copy tool data */
1139 toolPtr->uFlags = lpToolInfo->uFlags;
1140 toolPtr->hwnd = lpToolInfo->hwnd;
1141 toolPtr->uId = lpToolInfo->uId;
1142 toolPtr->rect = lpToolInfo->rect;
1143 toolPtr->hinst = lpToolInfo->hinst;
1145 if (IS_INTRESOURCE(lpToolInfo->lpszText)) {
1146 TRACE("add string id %x\n", LOWORD(lpToolInfo->lpszText));
1147 toolPtr->lpszText = lpToolInfo->lpszText;
1149 else if (lpToolInfo->lpszText) {
1150 if (lpToolInfo->lpszText == LPSTR_TEXTCALLBACKW) {
1151 TRACE("add CALLBACK!\n");
1152 toolPtr->lpszText = LPSTR_TEXTCALLBACKW;
1154 else {
1155 INT len = lstrlenW (lpToolInfo->lpszText);
1156 TRACE("add text %s!\n",
1157 debugstr_w(lpToolInfo->lpszText));
1158 toolPtr->lpszText = Alloc ((len + 1)*sizeof(WCHAR));
1159 strcpyW (toolPtr->lpszText, lpToolInfo->lpszText);
1163 if (lpToolInfo->cbSize >= TTTOOLINFOW_V2_SIZE)
1164 toolPtr->lParam = lpToolInfo->lParam;
1166 /* install subclassing hook */
1167 if (toolPtr->uFlags & TTF_SUBCLASS) {
1168 if (toolPtr->uFlags & TTF_IDISHWND) {
1169 SetWindowSubclass((HWND)toolPtr->uId, TOOLTIPS_SubclassProc, 1,
1170 (DWORD_PTR)infoPtr->hwndSelf);
1172 else {
1173 SetWindowSubclass(toolPtr->hwnd, TOOLTIPS_SubclassProc, 1,
1174 (DWORD_PTR)infoPtr->hwndSelf);
1176 TRACE("subclassing installed!\n");
1179 nResult = (INT) SendMessageW (toolPtr->hwnd, WM_NOTIFYFORMAT,
1180 (WPARAM)infoPtr->hwndSelf, (LPARAM)NF_QUERY);
1181 if (nResult == NFR_ANSI) {
1182 toolPtr->bNotifyUnicode = FALSE;
1183 TRACE(" -- WM_NOTIFYFORMAT returns: NFR_ANSI\n");
1184 } else if (nResult == NFR_UNICODE) {
1185 toolPtr->bNotifyUnicode = TRUE;
1186 TRACE(" -- WM_NOTIFYFORMAT returns: NFR_UNICODE\n");
1187 } else {
1188 TRACE (" -- WM_NOTIFYFORMAT returns: error!\n");
1191 return TRUE;
1195 static void
1196 TOOLTIPS_DelToolCommon (TOOLTIPS_INFO *infoPtr, INT nTool)
1198 TTTOOL_INFO *toolPtr;
1200 TRACE("tool %d\n", nTool);
1202 if (nTool == -1)
1203 return;
1205 /* make sure the tooltip has disappeared before deleting it */
1206 TOOLTIPS_Hide(infoPtr);
1208 /* delete text string */
1209 toolPtr = &infoPtr->tools[nTool];
1210 if (toolPtr->lpszText) {
1211 if ( (toolPtr->lpszText != LPSTR_TEXTCALLBACKW) &&
1212 !IS_INTRESOURCE(toolPtr->lpszText) )
1213 Free (toolPtr->lpszText);
1216 /* remove subclassing */
1217 if (toolPtr->uFlags & TTF_SUBCLASS) {
1218 if (toolPtr->uFlags & TTF_IDISHWND) {
1219 RemoveWindowSubclass((HWND)toolPtr->uId, TOOLTIPS_SubclassProc, 1);
1221 else {
1222 RemoveWindowSubclass(toolPtr->hwnd, TOOLTIPS_SubclassProc, 1);
1226 /* delete tool from tool list */
1227 if (infoPtr->uNumTools == 1) {
1228 Free (infoPtr->tools);
1229 infoPtr->tools = NULL;
1231 else {
1232 TTTOOL_INFO *oldTools = infoPtr->tools;
1233 infoPtr->tools =
1234 Alloc (sizeof(TTTOOL_INFO) * (infoPtr->uNumTools - 1));
1236 if (nTool > 0)
1237 memcpy (&infoPtr->tools[0], &oldTools[0],
1238 nTool * sizeof(TTTOOL_INFO));
1240 if (nTool < infoPtr->uNumTools - 1)
1241 memcpy (&infoPtr->tools[nTool], &oldTools[nTool + 1],
1242 (infoPtr->uNumTools - nTool - 1) * sizeof(TTTOOL_INFO));
1244 Free (oldTools);
1247 /* update any indices affected by delete */
1249 /* destroying tool that mouse was on on last relayed mouse move */
1250 if (infoPtr->nTool == nTool)
1251 /* -1 means no current tool (0 means first tool) */
1252 infoPtr->nTool = -1;
1253 else if (infoPtr->nTool > nTool)
1254 infoPtr->nTool--;
1256 if (infoPtr->nTrackTool == nTool)
1257 /* -1 means no current tool (0 means first tool) */
1258 infoPtr->nTrackTool = -1;
1259 else if (infoPtr->nTrackTool > nTool)
1260 infoPtr->nTrackTool--;
1262 if (infoPtr->nCurrentTool == nTool)
1263 /* -1 means no current tool (0 means first tool) */
1264 infoPtr->nCurrentTool = -1;
1265 else if (infoPtr->nCurrentTool > nTool)
1266 infoPtr->nCurrentTool--;
1268 infoPtr->uNumTools--;
1271 static LRESULT
1272 TOOLTIPS_DelToolA (TOOLTIPS_INFO *infoPtr, LPTTTOOLINFOA lpToolInfo)
1274 INT nTool;
1276 if (lpToolInfo == NULL)
1277 return 0;
1278 if (infoPtr->uNumTools == 0)
1279 return 0;
1281 nTool = TOOLTIPS_GetToolFromInfoA (infoPtr, lpToolInfo);
1283 TOOLTIPS_DelToolCommon (infoPtr, nTool);
1285 return 0;
1289 static LRESULT
1290 TOOLTIPS_DelToolW (TOOLTIPS_INFO *infoPtr, LPTTTOOLINFOW lpToolInfo)
1292 INT nTool;
1294 if (lpToolInfo == NULL)
1295 return 0;
1296 if (lpToolInfo->cbSize > TTTOOLINFOW_V2_SIZE &&
1297 lpToolInfo->cbSize != TTTOOLINFOW_V3_SIZE)
1298 return 0;
1299 if (infoPtr->uNumTools == 0)
1300 return 0;
1302 nTool = TOOLTIPS_GetToolFromInfoW (infoPtr, lpToolInfo);
1304 TOOLTIPS_DelToolCommon (infoPtr, nTool);
1306 return 0;
1310 static LRESULT
1311 TOOLTIPS_EnumToolsA (const TOOLTIPS_INFO *infoPtr, UINT uIndex, LPTTTOOLINFOA lpToolInfo)
1313 TTTOOL_INFO *toolPtr;
1315 if (lpToolInfo == NULL)
1316 return FALSE;
1317 if (lpToolInfo->cbSize < TTTOOLINFOA_V1_SIZE)
1318 return FALSE;
1319 if (uIndex >= infoPtr->uNumTools)
1320 return FALSE;
1322 TRACE("index=%u\n", uIndex);
1324 toolPtr = &infoPtr->tools[uIndex];
1326 /* copy tool data */
1327 lpToolInfo->uFlags = toolPtr->uFlags;
1328 lpToolInfo->hwnd = toolPtr->hwnd;
1329 lpToolInfo->uId = toolPtr->uId;
1330 lpToolInfo->rect = toolPtr->rect;
1331 lpToolInfo->hinst = toolPtr->hinst;
1332 /* lpToolInfo->lpszText = toolPtr->lpszText; */
1333 lpToolInfo->lpszText = NULL; /* FIXME */
1335 if (lpToolInfo->cbSize >= TTTOOLINFOA_V2_SIZE)
1336 lpToolInfo->lParam = toolPtr->lParam;
1338 return TRUE;
1342 static LRESULT
1343 TOOLTIPS_EnumToolsW (const TOOLTIPS_INFO *infoPtr, UINT uIndex, LPTTTOOLINFOW lpToolInfo)
1345 TTTOOL_INFO *toolPtr;
1347 if (lpToolInfo == NULL)
1348 return FALSE;
1349 if (lpToolInfo->cbSize < TTTOOLINFOW_V1_SIZE)
1350 return FALSE;
1351 if (uIndex >= infoPtr->uNumTools)
1352 return FALSE;
1354 TRACE("index=%u\n", uIndex);
1356 toolPtr = &infoPtr->tools[uIndex];
1358 /* copy tool data */
1359 lpToolInfo->uFlags = toolPtr->uFlags;
1360 lpToolInfo->hwnd = toolPtr->hwnd;
1361 lpToolInfo->uId = toolPtr->uId;
1362 lpToolInfo->rect = toolPtr->rect;
1363 lpToolInfo->hinst = toolPtr->hinst;
1364 /* lpToolInfo->lpszText = toolPtr->lpszText; */
1365 lpToolInfo->lpszText = NULL; /* FIXME */
1367 if (lpToolInfo->cbSize >= TTTOOLINFOW_V2_SIZE)
1368 lpToolInfo->lParam = toolPtr->lParam;
1370 return TRUE;
1373 static LRESULT
1374 TOOLTIPS_GetBubbleSize (const TOOLTIPS_INFO *infoPtr, const TTTOOLINFOW *lpToolInfo)
1376 INT nTool;
1377 SIZE size;
1379 if (lpToolInfo == NULL)
1380 return FALSE;
1381 if (lpToolInfo->cbSize < TTTOOLINFOW_V1_SIZE)
1382 return FALSE;
1384 nTool = TOOLTIPS_GetToolFromInfoW (infoPtr, lpToolInfo);
1385 if (nTool == -1) return 0;
1387 TRACE("tool %d\n", nTool);
1389 TOOLTIPS_CalcTipSize (infoPtr, &size);
1390 TRACE("size %d x %d\n", size.cx, size.cy);
1392 return MAKELRESULT(size.cx, size.cy);
1395 static LRESULT
1396 TOOLTIPS_GetCurrentToolA (const TOOLTIPS_INFO *infoPtr, LPTTTOOLINFOA lpToolInfo)
1398 TTTOOL_INFO *toolPtr;
1400 if (lpToolInfo) {
1401 if (lpToolInfo->cbSize < TTTOOLINFOA_V1_SIZE)
1402 return FALSE;
1404 if (infoPtr->nCurrentTool > -1) {
1405 toolPtr = &infoPtr->tools[infoPtr->nCurrentTool];
1407 /* copy tool data */
1408 lpToolInfo->uFlags = toolPtr->uFlags;
1409 lpToolInfo->rect = toolPtr->rect;
1410 lpToolInfo->hinst = toolPtr->hinst;
1411 /* lpToolInfo->lpszText = toolPtr->lpszText; */
1412 lpToolInfo->lpszText = NULL; /* FIXME */
1414 if (lpToolInfo->cbSize >= TTTOOLINFOA_V2_SIZE)
1415 lpToolInfo->lParam = toolPtr->lParam;
1417 return TRUE;
1419 else
1420 return FALSE;
1422 else
1423 return (infoPtr->nCurrentTool != -1);
1427 static LRESULT
1428 TOOLTIPS_GetCurrentToolW (const TOOLTIPS_INFO *infoPtr, LPTTTOOLINFOW lpToolInfo)
1430 TTTOOL_INFO *toolPtr;
1432 if (lpToolInfo) {
1433 if (lpToolInfo->cbSize < TTTOOLINFOW_V1_SIZE)
1434 return FALSE;
1436 if (infoPtr->nCurrentTool > -1) {
1437 toolPtr = &infoPtr->tools[infoPtr->nCurrentTool];
1439 /* copy tool data */
1440 lpToolInfo->uFlags = toolPtr->uFlags;
1441 lpToolInfo->rect = toolPtr->rect;
1442 lpToolInfo->hinst = toolPtr->hinst;
1443 /* lpToolInfo->lpszText = toolPtr->lpszText; */
1444 lpToolInfo->lpszText = NULL; /* FIXME */
1446 if (lpToolInfo->cbSize >= TTTOOLINFOW_V2_SIZE)
1447 lpToolInfo->lParam = toolPtr->lParam;
1449 return TRUE;
1451 else
1452 return FALSE;
1454 else
1455 return (infoPtr->nCurrentTool != -1);
1459 static LRESULT
1460 TOOLTIPS_GetDelayTime (const TOOLTIPS_INFO *infoPtr, DWORD duration)
1462 switch (duration) {
1463 case TTDT_RESHOW:
1464 return infoPtr->nReshowTime;
1466 case TTDT_AUTOPOP:
1467 return infoPtr->nAutoPopTime;
1469 case TTDT_INITIAL:
1470 case TTDT_AUTOMATIC: /* Apparently TTDT_AUTOMATIC returns TTDT_INITIAL */
1471 return infoPtr->nInitialTime;
1473 default:
1474 WARN("Invalid duration flag %x\n", duration);
1475 break;
1478 return -1;
1482 static LRESULT
1483 TOOLTIPS_GetMargin (const TOOLTIPS_INFO *infoPtr, LPRECT lpRect)
1485 lpRect->left = infoPtr->rcMargin.left;
1486 lpRect->right = infoPtr->rcMargin.right;
1487 lpRect->bottom = infoPtr->rcMargin.bottom;
1488 lpRect->top = infoPtr->rcMargin.top;
1490 return 0;
1494 static inline LRESULT
1495 TOOLTIPS_GetMaxTipWidth (const TOOLTIPS_INFO *infoPtr)
1497 return infoPtr->nMaxTipWidth;
1501 static LRESULT
1502 TOOLTIPS_GetTextA (const TOOLTIPS_INFO *infoPtr, LPTTTOOLINFOA lpToolInfo)
1504 WCHAR buffer[INFOTIPSIZE];
1505 INT nTool;
1507 if (lpToolInfo == NULL)
1508 return 0;
1509 if (lpToolInfo->cbSize < TTTOOLINFOA_V1_SIZE)
1510 return 0;
1512 nTool = TOOLTIPS_GetToolFromInfoA (infoPtr, lpToolInfo);
1513 if (nTool == -1) return 0;
1515 /* NB this API is broken, there is no way for the app to determine
1516 what size buffer it requires nor a way to specify how long the
1517 one it supplies is. We'll assume it's up to INFOTIPSIZE */
1519 buffer[0] = '\0';
1520 TOOLTIPS_GetTipText(infoPtr, nTool, buffer);
1521 WideCharToMultiByte(CP_ACP, 0, buffer, -1, lpToolInfo->lpszText,
1522 INFOTIPSIZE, NULL, NULL);
1524 return 0;
1528 static LRESULT
1529 TOOLTIPS_GetTextW (const TOOLTIPS_INFO *infoPtr, LPTTTOOLINFOW lpToolInfo)
1531 INT nTool;
1533 if (lpToolInfo == NULL)
1534 return 0;
1535 if (lpToolInfo->cbSize < TTTOOLINFOW_V1_SIZE)
1536 return 0;
1538 nTool = TOOLTIPS_GetToolFromInfoW (infoPtr, lpToolInfo);
1539 if (nTool == -1) return 0;
1541 if (infoPtr->tools[nTool].lpszText == NULL)
1542 return 0;
1544 lpToolInfo->lpszText[0] = '\0';
1545 TOOLTIPS_GetTipText(infoPtr, nTool, lpToolInfo->lpszText);
1547 return 0;
1551 static inline LRESULT
1552 TOOLTIPS_GetTipBkColor (const TOOLTIPS_INFO *infoPtr)
1554 return infoPtr->clrBk;
1558 static inline LRESULT
1559 TOOLTIPS_GetTipTextColor (const TOOLTIPS_INFO *infoPtr)
1561 return infoPtr->clrText;
1565 static inline LRESULT
1566 TOOLTIPS_GetToolCount (const TOOLTIPS_INFO *infoPtr)
1568 return infoPtr->uNumTools;
1572 static LRESULT
1573 TOOLTIPS_GetToolInfoA (const TOOLTIPS_INFO *infoPtr, LPTTTOOLINFOA lpToolInfo)
1575 TTTOOL_INFO *toolPtr;
1576 INT nTool;
1578 if (lpToolInfo == NULL)
1579 return FALSE;
1580 if (lpToolInfo->cbSize < TTTOOLINFOA_V1_SIZE)
1581 return FALSE;
1582 if (infoPtr->uNumTools == 0)
1583 return FALSE;
1585 nTool = TOOLTIPS_GetToolFromInfoA (infoPtr, lpToolInfo);
1586 if (nTool == -1)
1587 return FALSE;
1589 TRACE("tool %d\n", nTool);
1591 toolPtr = &infoPtr->tools[nTool];
1593 /* copy tool data */
1594 lpToolInfo->uFlags = toolPtr->uFlags;
1595 lpToolInfo->rect = toolPtr->rect;
1596 lpToolInfo->hinst = toolPtr->hinst;
1597 /* lpToolInfo->lpszText = toolPtr->lpszText; */
1598 lpToolInfo->lpszText = NULL; /* FIXME */
1600 if (lpToolInfo->cbSize >= TTTOOLINFOA_V2_SIZE)
1601 lpToolInfo->lParam = toolPtr->lParam;
1603 return TRUE;
1607 static LRESULT
1608 TOOLTIPS_GetToolInfoW (const TOOLTIPS_INFO *infoPtr, LPTTTOOLINFOW lpToolInfo)
1610 TTTOOL_INFO *toolPtr;
1611 INT nTool;
1613 if (lpToolInfo == NULL)
1614 return FALSE;
1615 if (lpToolInfo->cbSize < TTTOOLINFOW_V1_SIZE)
1616 return FALSE;
1617 if (infoPtr->uNumTools == 0)
1618 return FALSE;
1620 nTool = TOOLTIPS_GetToolFromInfoW (infoPtr, lpToolInfo);
1621 if (nTool == -1)
1622 return FALSE;
1624 TRACE("tool %d\n", nTool);
1626 toolPtr = &infoPtr->tools[nTool];
1628 /* copy tool data */
1629 lpToolInfo->uFlags = toolPtr->uFlags;
1630 lpToolInfo->rect = toolPtr->rect;
1631 lpToolInfo->hinst = toolPtr->hinst;
1632 /* lpToolInfo->lpszText = toolPtr->lpszText; */
1633 lpToolInfo->lpszText = NULL; /* FIXME */
1635 if (lpToolInfo->cbSize >= TTTOOLINFOW_V2_SIZE)
1636 lpToolInfo->lParam = toolPtr->lParam;
1638 return TRUE;
1642 static LRESULT
1643 TOOLTIPS_HitTestA (const TOOLTIPS_INFO *infoPtr, LPTTHITTESTINFOA lptthit)
1645 TTTOOL_INFO *toolPtr;
1646 INT nTool;
1648 if (lptthit == 0)
1649 return FALSE;
1651 nTool = TOOLTIPS_GetToolFromPoint (infoPtr, lptthit->hwnd, &lptthit->pt);
1652 if (nTool == -1)
1653 return FALSE;
1655 TRACE("tool %d!\n", nTool);
1657 /* copy tool data */
1658 if (lptthit->ti.cbSize >= TTTOOLINFOA_V1_SIZE) {
1659 toolPtr = &infoPtr->tools[nTool];
1661 lptthit->ti.uFlags = toolPtr->uFlags;
1662 lptthit->ti.hwnd = toolPtr->hwnd;
1663 lptthit->ti.uId = toolPtr->uId;
1664 lptthit->ti.rect = toolPtr->rect;
1665 lptthit->ti.hinst = toolPtr->hinst;
1666 /* lptthit->ti.lpszText = toolPtr->lpszText; */
1667 lptthit->ti.lpszText = NULL; /* FIXME */
1668 if (lptthit->ti.cbSize >= TTTOOLINFOA_V2_SIZE)
1669 lptthit->ti.lParam = toolPtr->lParam;
1672 return TRUE;
1676 static LRESULT
1677 TOOLTIPS_HitTestW (const TOOLTIPS_INFO *infoPtr, LPTTHITTESTINFOW lptthit)
1679 TTTOOL_INFO *toolPtr;
1680 INT nTool;
1682 if (lptthit == 0)
1683 return FALSE;
1685 nTool = TOOLTIPS_GetToolFromPoint (infoPtr, lptthit->hwnd, &lptthit->pt);
1686 if (nTool == -1)
1687 return FALSE;
1689 TRACE("tool %d!\n", nTool);
1691 /* copy tool data */
1692 if (lptthit->ti.cbSize >= TTTOOLINFOW_V1_SIZE) {
1693 toolPtr = &infoPtr->tools[nTool];
1695 lptthit->ti.uFlags = toolPtr->uFlags;
1696 lptthit->ti.hwnd = toolPtr->hwnd;
1697 lptthit->ti.uId = toolPtr->uId;
1698 lptthit->ti.rect = toolPtr->rect;
1699 lptthit->ti.hinst = toolPtr->hinst;
1700 /* lptthit->ti.lpszText = toolPtr->lpszText; */
1701 lptthit->ti.lpszText = NULL; /* FIXME */
1702 if (lptthit->ti.cbSize >= TTTOOLINFOW_V2_SIZE)
1703 lptthit->ti.lParam = toolPtr->lParam;
1706 return TRUE;
1710 static LRESULT
1711 TOOLTIPS_NewToolRectA (TOOLTIPS_INFO *infoPtr, const TTTOOLINFOA *lpti)
1713 INT nTool;
1715 if (lpti == NULL)
1716 return 0;
1717 if (lpti->cbSize < TTTOOLINFOA_V1_SIZE)
1718 return FALSE;
1720 nTool = TOOLTIPS_GetToolFromInfoA (infoPtr, lpti);
1722 TRACE("nTool = %d, rect = %s\n", nTool, wine_dbgstr_rect(&lpti->rect));
1724 if (nTool == -1) return 0;
1726 infoPtr->tools[nTool].rect = lpti->rect;
1728 return 0;
1732 static LRESULT
1733 TOOLTIPS_NewToolRectW (TOOLTIPS_INFO *infoPtr, const TTTOOLINFOW *lpti)
1735 INT nTool;
1737 if (lpti == NULL)
1738 return 0;
1739 if (lpti->cbSize < TTTOOLINFOW_V1_SIZE)
1740 return FALSE;
1742 nTool = TOOLTIPS_GetToolFromInfoW (infoPtr, lpti);
1744 TRACE("nTool = %d, rect = %s\n", nTool, wine_dbgstr_rect(&lpti->rect));
1746 if (nTool == -1) return 0;
1748 infoPtr->tools[nTool].rect = lpti->rect;
1750 return 0;
1754 static inline LRESULT
1755 TOOLTIPS_Pop (TOOLTIPS_INFO *infoPtr)
1757 TOOLTIPS_Hide (infoPtr);
1759 return 0;
1763 static LRESULT
1764 TOOLTIPS_RelayEvent (TOOLTIPS_INFO *infoPtr, LPMSG lpMsg)
1766 POINT pt;
1767 INT nOldTool;
1769 if (!lpMsg) {
1770 ERR("lpMsg == NULL!\n");
1771 return 0;
1774 switch (lpMsg->message) {
1775 case WM_LBUTTONDOWN:
1776 case WM_LBUTTONUP:
1777 case WM_MBUTTONDOWN:
1778 case WM_MBUTTONUP:
1779 case WM_RBUTTONDOWN:
1780 case WM_RBUTTONUP:
1781 TOOLTIPS_Hide (infoPtr);
1782 break;
1784 case WM_MOUSEMOVE:
1785 pt.x = (short)LOWORD(lpMsg->lParam);
1786 pt.y = (short)HIWORD(lpMsg->lParam);
1787 nOldTool = infoPtr->nTool;
1788 infoPtr->nTool = TOOLTIPS_GetToolFromPoint(infoPtr, lpMsg->hwnd,
1789 &pt);
1790 TRACE("tool (%p) %d %d %d\n", infoPtr->hwndSelf, nOldTool,
1791 infoPtr->nTool, infoPtr->nCurrentTool);
1792 TRACE("WM_MOUSEMOVE (%p %d %d)\n", infoPtr->hwndSelf, pt.x, pt.y);
1794 if (infoPtr->nTool != nOldTool) {
1795 if(infoPtr->nTool == -1) { /* Moved out of all tools */
1796 TOOLTIPS_Hide(infoPtr);
1797 KillTimer(infoPtr->hwndSelf, ID_TIMERLEAVE);
1798 } else if (nOldTool == -1) { /* Moved from outside */
1799 if(infoPtr->bActive) {
1800 SetTimer(infoPtr->hwndSelf, ID_TIMERSHOW, infoPtr->nInitialTime, 0);
1801 TRACE("timer 1 started!\n");
1803 } else { /* Moved from one to another */
1804 TOOLTIPS_Hide (infoPtr);
1805 KillTimer(infoPtr->hwndSelf, ID_TIMERLEAVE);
1806 if(infoPtr->bActive) {
1807 SetTimer (infoPtr->hwndSelf, ID_TIMERSHOW, infoPtr->nReshowTime, 0);
1808 TRACE("timer 1 started!\n");
1811 } else if(infoPtr->nCurrentTool != -1) { /* restart autopop */
1812 KillTimer(infoPtr->hwndSelf, ID_TIMERPOP);
1813 SetTimer(infoPtr->hwndSelf, ID_TIMERPOP, infoPtr->nAutoPopTime, 0);
1814 TRACE("timer 2 restarted\n");
1815 } else if(infoPtr->nTool != -1 && infoPtr->bActive) {
1816 /* previous show attempt didn't result in tooltip so try again */
1817 SetTimer(infoPtr->hwndSelf, ID_TIMERSHOW, infoPtr->nInitialTime, 0);
1818 TRACE("timer 1 started!\n");
1820 break;
1823 return 0;
1827 static LRESULT
1828 TOOLTIPS_SetDelayTime (TOOLTIPS_INFO *infoPtr, DWORD duration, INT nTime)
1830 switch (duration) {
1831 case TTDT_AUTOMATIC:
1832 if (nTime <= 0)
1833 nTime = GetDoubleClickTime();
1834 infoPtr->nReshowTime = nTime / 5;
1835 infoPtr->nAutoPopTime = nTime * 10;
1836 infoPtr->nInitialTime = nTime;
1837 break;
1839 case TTDT_RESHOW:
1840 if(nTime < 0)
1841 nTime = GetDoubleClickTime() / 5;
1842 infoPtr->nReshowTime = nTime;
1843 break;
1845 case TTDT_AUTOPOP:
1846 if(nTime < 0)
1847 nTime = GetDoubleClickTime() * 10;
1848 infoPtr->nAutoPopTime = nTime;
1849 break;
1851 case TTDT_INITIAL:
1852 if(nTime < 0)
1853 nTime = GetDoubleClickTime();
1854 infoPtr->nInitialTime = nTime;
1855 break;
1857 default:
1858 WARN("Invalid duration flag %x\n", duration);
1859 break;
1862 return 0;
1866 static LRESULT
1867 TOOLTIPS_SetMargin (TOOLTIPS_INFO *infoPtr, const RECT *lpRect)
1869 infoPtr->rcMargin.left = lpRect->left;
1870 infoPtr->rcMargin.right = lpRect->right;
1871 infoPtr->rcMargin.bottom = lpRect->bottom;
1872 infoPtr->rcMargin.top = lpRect->top;
1874 return 0;
1878 static inline LRESULT
1879 TOOLTIPS_SetMaxTipWidth (TOOLTIPS_INFO *infoPtr, INT MaxWidth)
1881 INT nTemp = infoPtr->nMaxTipWidth;
1883 infoPtr->nMaxTipWidth = MaxWidth;
1885 return nTemp;
1889 static inline LRESULT
1890 TOOLTIPS_SetTipBkColor (TOOLTIPS_INFO *infoPtr, COLORREF clrBk)
1892 infoPtr->clrBk = clrBk;
1894 return 0;
1898 static inline LRESULT
1899 TOOLTIPS_SetTipTextColor (TOOLTIPS_INFO *infoPtr, COLORREF clrText)
1901 infoPtr->clrText = clrText;
1903 return 0;
1907 static LRESULT
1908 TOOLTIPS_SetTitleA (TOOLTIPS_INFO *infoPtr, UINT_PTR uTitleIcon, LPCSTR pszTitle)
1910 UINT size;
1912 TRACE("hwnd = %p, title = %s, icon = %p\n", infoPtr->hwndSelf, debugstr_a(pszTitle),
1913 (void*)uTitleIcon);
1915 Free(infoPtr->pszTitle);
1917 if (pszTitle)
1919 size = sizeof(WCHAR)*MultiByteToWideChar(CP_ACP, 0, pszTitle, -1, NULL, 0);
1920 infoPtr->pszTitle = Alloc(size);
1921 if (!infoPtr->pszTitle)
1922 return FALSE;
1923 MultiByteToWideChar(CP_ACP, 0, pszTitle, -1, infoPtr->pszTitle, size/sizeof(WCHAR));
1925 else
1926 infoPtr->pszTitle = NULL;
1928 if (uTitleIcon <= TTI_ERROR)
1929 infoPtr->hTitleIcon = hTooltipIcons[uTitleIcon];
1930 else
1931 infoPtr->hTitleIcon = CopyIcon((HICON)uTitleIcon);
1933 return TRUE;
1937 static LRESULT
1938 TOOLTIPS_SetTitleW (TOOLTIPS_INFO *infoPtr, UINT_PTR uTitleIcon, LPCWSTR pszTitle)
1940 UINT size;
1942 TRACE("hwnd = %p, title = %s, icon = %p\n", infoPtr->hwndSelf, debugstr_w(pszTitle),
1943 (void*)uTitleIcon);
1945 Free(infoPtr->pszTitle);
1947 if (pszTitle)
1949 size = (strlenW(pszTitle)+1)*sizeof(WCHAR);
1950 infoPtr->pszTitle = Alloc(size);
1951 if (!infoPtr->pszTitle)
1952 return FALSE;
1953 memcpy(infoPtr->pszTitle, pszTitle, size);
1955 else
1956 infoPtr->pszTitle = NULL;
1958 if (uTitleIcon <= TTI_ERROR)
1959 infoPtr->hTitleIcon = hTooltipIcons[uTitleIcon];
1960 else
1961 infoPtr->hTitleIcon = CopyIcon((HICON)uTitleIcon);
1963 TRACE("icon = %p\n", infoPtr->hTitleIcon);
1965 return TRUE;
1969 static LRESULT
1970 TOOLTIPS_SetToolInfoA (TOOLTIPS_INFO *infoPtr, const TTTOOLINFOA *lpToolInfo)
1972 TTTOOL_INFO *toolPtr;
1973 INT nTool;
1975 if (lpToolInfo == NULL)
1976 return 0;
1977 if (lpToolInfo->cbSize < TTTOOLINFOA_V1_SIZE)
1978 return 0;
1980 nTool = TOOLTIPS_GetToolFromInfoA (infoPtr, lpToolInfo);
1981 if (nTool == -1) return 0;
1983 TRACE("tool %d\n", nTool);
1985 toolPtr = &infoPtr->tools[nTool];
1987 /* copy tool data */
1988 toolPtr->uFlags = lpToolInfo->uFlags;
1989 toolPtr->hwnd = lpToolInfo->hwnd;
1990 toolPtr->uId = lpToolInfo->uId;
1991 toolPtr->rect = lpToolInfo->rect;
1992 toolPtr->hinst = lpToolInfo->hinst;
1994 if (IS_INTRESOURCE(lpToolInfo->lpszText)) {
1995 TRACE("set string id %x\n", LOWORD(lpToolInfo->lpszText));
1996 toolPtr->lpszText = (LPWSTR)lpToolInfo->lpszText;
1998 else if (lpToolInfo->lpszText) {
1999 if (lpToolInfo->lpszText == LPSTR_TEXTCALLBACKA)
2000 toolPtr->lpszText = LPSTR_TEXTCALLBACKW;
2001 else {
2002 if ( (toolPtr->lpszText) &&
2003 !IS_INTRESOURCE(toolPtr->lpszText) ) {
2004 if( toolPtr->lpszText != LPSTR_TEXTCALLBACKW)
2005 Free (toolPtr->lpszText);
2006 toolPtr->lpszText = NULL;
2008 if (lpToolInfo->lpszText) {
2009 INT len = MultiByteToWideChar(CP_ACP, 0, lpToolInfo->lpszText,
2010 -1, NULL, 0);
2011 toolPtr->lpszText = Alloc (len * sizeof(WCHAR));
2012 MultiByteToWideChar(CP_ACP, 0, lpToolInfo->lpszText, -1,
2013 toolPtr->lpszText, len);
2018 if (lpToolInfo->cbSize >= TTTOOLINFOA_V2_SIZE)
2019 toolPtr->lParam = lpToolInfo->lParam;
2021 return 0;
2025 static LRESULT
2026 TOOLTIPS_SetToolInfoW (TOOLTIPS_INFO *infoPtr, const TTTOOLINFOW *lpToolInfo)
2028 TTTOOL_INFO *toolPtr;
2029 INT nTool;
2031 if (lpToolInfo == NULL)
2032 return 0;
2033 if (lpToolInfo->cbSize < TTTOOLINFOW_V1_SIZE)
2034 return 0;
2036 nTool = TOOLTIPS_GetToolFromInfoW (infoPtr, lpToolInfo);
2037 if (nTool == -1) return 0;
2039 TRACE("tool %d\n", nTool);
2041 toolPtr = &infoPtr->tools[nTool];
2043 /* copy tool data */
2044 toolPtr->uFlags = lpToolInfo->uFlags;
2045 toolPtr->hwnd = lpToolInfo->hwnd;
2046 toolPtr->uId = lpToolInfo->uId;
2047 toolPtr->rect = lpToolInfo->rect;
2048 toolPtr->hinst = lpToolInfo->hinst;
2050 if (IS_INTRESOURCE(lpToolInfo->lpszText)) {
2051 TRACE("set string id %x!\n", LOWORD(lpToolInfo->lpszText));
2052 toolPtr->lpszText = lpToolInfo->lpszText;
2054 else {
2055 if (lpToolInfo->lpszText == LPSTR_TEXTCALLBACKW)
2056 toolPtr->lpszText = LPSTR_TEXTCALLBACKW;
2057 else {
2058 if ( (toolPtr->lpszText) &&
2059 !IS_INTRESOURCE(toolPtr->lpszText) ) {
2060 if( toolPtr->lpszText != LPSTR_TEXTCALLBACKW)
2061 Free (toolPtr->lpszText);
2062 toolPtr->lpszText = NULL;
2064 if (lpToolInfo->lpszText) {
2065 INT len = lstrlenW (lpToolInfo->lpszText);
2066 toolPtr->lpszText = Alloc ((len+1)*sizeof(WCHAR));
2067 strcpyW (toolPtr->lpszText, lpToolInfo->lpszText);
2072 if (lpToolInfo->cbSize >= TTTOOLINFOW_V2_SIZE)
2073 toolPtr->lParam = lpToolInfo->lParam;
2075 if (infoPtr->nCurrentTool == nTool)
2077 TOOLTIPS_GetTipText (infoPtr, infoPtr->nCurrentTool, infoPtr->szTipText);
2079 if (infoPtr->szTipText[0] == 0)
2080 TOOLTIPS_Hide(infoPtr);
2081 else
2082 TOOLTIPS_Show (infoPtr, FALSE);
2085 return 0;
2089 static LRESULT
2090 TOOLTIPS_TrackActivate (TOOLTIPS_INFO *infoPtr, BOOL track_activate, const TTTOOLINFOA *lpToolInfo)
2092 if (track_activate) {
2094 if (lpToolInfo == NULL)
2095 return 0;
2096 if (lpToolInfo->cbSize < TTTOOLINFOA_V1_SIZE)
2097 return FALSE;
2099 /* activate */
2100 infoPtr->nTrackTool = TOOLTIPS_GetToolFromInfoA (infoPtr, lpToolInfo);
2101 if (infoPtr->nTrackTool != -1) {
2102 TRACE("activated!\n");
2103 infoPtr->bTrackActive = TRUE;
2104 TOOLTIPS_TrackShow (infoPtr);
2107 else {
2108 /* deactivate */
2109 TOOLTIPS_TrackHide (infoPtr);
2111 infoPtr->bTrackActive = FALSE;
2112 infoPtr->nTrackTool = -1;
2114 TRACE("deactivated!\n");
2117 return 0;
2121 static LRESULT
2122 TOOLTIPS_TrackPosition (TOOLTIPS_INFO *infoPtr, LPARAM coord)
2124 infoPtr->xTrackPos = (INT)LOWORD(coord);
2125 infoPtr->yTrackPos = (INT)HIWORD(coord);
2127 if (infoPtr->bTrackActive) {
2128 TRACE("[%d %d]\n",
2129 infoPtr->xTrackPos, infoPtr->yTrackPos);
2131 TOOLTIPS_TrackShow (infoPtr);
2134 return 0;
2138 static LRESULT
2139 TOOLTIPS_Update (TOOLTIPS_INFO *infoPtr)
2141 if (infoPtr->nCurrentTool != -1)
2142 UpdateWindow (infoPtr->hwndSelf);
2144 return 0;
2148 static LRESULT
2149 TOOLTIPS_UpdateTipTextA (TOOLTIPS_INFO *infoPtr, const TTTOOLINFOA *lpToolInfo)
2151 TTTOOL_INFO *toolPtr;
2152 INT nTool;
2154 if (lpToolInfo == NULL)
2155 return 0;
2156 if (lpToolInfo->cbSize < TTTOOLINFOA_V1_SIZE)
2157 return FALSE;
2159 nTool = TOOLTIPS_GetToolFromInfoA (infoPtr, lpToolInfo);
2160 if (nTool == -1) return 0;
2162 TRACE("tool %d\n", nTool);
2164 toolPtr = &infoPtr->tools[nTool];
2166 /* copy tool text */
2167 toolPtr->hinst = lpToolInfo->hinst;
2169 if (IS_INTRESOURCE(lpToolInfo->lpszText)){
2170 toolPtr->lpszText = (LPWSTR)lpToolInfo->lpszText;
2172 else if (lpToolInfo->lpszText) {
2173 if (lpToolInfo->lpszText == LPSTR_TEXTCALLBACKA)
2174 toolPtr->lpszText = LPSTR_TEXTCALLBACKW;
2175 else {
2176 if ( (toolPtr->lpszText) &&
2177 !IS_INTRESOURCE(toolPtr->lpszText) ) {
2178 if( toolPtr->lpszText != LPSTR_TEXTCALLBACKW)
2179 Free (toolPtr->lpszText);
2180 toolPtr->lpszText = NULL;
2182 if (lpToolInfo->lpszText) {
2183 INT len = MultiByteToWideChar(CP_ACP, 0, lpToolInfo->lpszText,
2184 -1, NULL, 0);
2185 toolPtr->lpszText = Alloc (len * sizeof(WCHAR));
2186 MultiByteToWideChar(CP_ACP, 0, lpToolInfo->lpszText, -1,
2187 toolPtr->lpszText, len);
2192 if(infoPtr->nCurrentTool == -1) return 0;
2193 /* force repaint */
2194 if (infoPtr->bActive)
2195 TOOLTIPS_Show (infoPtr, FALSE);
2196 else if (infoPtr->bTrackActive)
2197 TOOLTIPS_TrackShow (infoPtr);
2199 return 0;
2203 static LRESULT
2204 TOOLTIPS_UpdateTipTextW (TOOLTIPS_INFO *infoPtr, const TTTOOLINFOW *lpToolInfo)
2206 TTTOOL_INFO *toolPtr;
2207 INT nTool;
2209 if (lpToolInfo == NULL)
2210 return 0;
2211 if (lpToolInfo->cbSize < TTTOOLINFOW_V1_SIZE)
2212 return FALSE;
2214 nTool = TOOLTIPS_GetToolFromInfoW (infoPtr, lpToolInfo);
2215 if (nTool == -1)
2216 return 0;
2218 TRACE("tool %d\n", nTool);
2220 toolPtr = &infoPtr->tools[nTool];
2222 /* copy tool text */
2223 toolPtr->hinst = lpToolInfo->hinst;
2225 if (IS_INTRESOURCE(lpToolInfo->lpszText)){
2226 toolPtr->lpszText = lpToolInfo->lpszText;
2228 else if (lpToolInfo->lpszText) {
2229 if (lpToolInfo->lpszText == LPSTR_TEXTCALLBACKW)
2230 toolPtr->lpszText = LPSTR_TEXTCALLBACKW;
2231 else {
2232 if ( (toolPtr->lpszText) &&
2233 !IS_INTRESOURCE(toolPtr->lpszText) ) {
2234 if( toolPtr->lpszText != LPSTR_TEXTCALLBACKW)
2235 Free (toolPtr->lpszText);
2236 toolPtr->lpszText = NULL;
2238 if (lpToolInfo->lpszText) {
2239 INT len = lstrlenW (lpToolInfo->lpszText);
2240 toolPtr->lpszText = Alloc ((len+1)*sizeof(WCHAR));
2241 strcpyW (toolPtr->lpszText, lpToolInfo->lpszText);
2246 if(infoPtr->nCurrentTool == -1) return 0;
2247 /* force repaint */
2248 if (infoPtr->bActive)
2249 TOOLTIPS_Show (infoPtr, FALSE);
2250 else if (infoPtr->bTrackActive)
2251 TOOLTIPS_Show (infoPtr, TRUE);
2253 return 0;
2257 static LRESULT
2258 TOOLTIPS_WindowFromPoint (HWND hwnd, WPARAM wParam, LPARAM lParam)
2260 return (LRESULT)WindowFromPoint (*((LPPOINT)lParam));
2265 static LRESULT
2266 TOOLTIPS_Create (HWND hwnd, const CREATESTRUCTW *lpcs)
2268 TOOLTIPS_INFO *infoPtr;
2270 /* allocate memory for info structure */
2271 infoPtr = Alloc (sizeof(TOOLTIPS_INFO));
2272 SetWindowLongPtrW (hwnd, 0, (DWORD_PTR)infoPtr);
2274 /* initialize info structure */
2275 infoPtr->bActive = TRUE;
2276 infoPtr->bTrackActive = FALSE;
2278 infoPtr->nMaxTipWidth = -1;
2279 infoPtr->nTool = -1;
2280 infoPtr->nCurrentTool = -1;
2281 infoPtr->nTrackTool = -1;
2282 infoPtr->hwndSelf = hwnd;
2284 /* initialize colours and fonts */
2285 TOOLTIPS_InitSystemSettings(infoPtr);
2287 TOOLTIPS_SetDelayTime(infoPtr, TTDT_AUTOMATIC, 0);
2289 SetWindowPos (hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOZORDER | SWP_HIDEWINDOW | SWP_NOACTIVATE);
2291 return 0;
2295 static LRESULT
2296 TOOLTIPS_Destroy (TOOLTIPS_INFO *infoPtr)
2298 TTTOOL_INFO *toolPtr;
2299 UINT i;
2301 /* free tools */
2302 if (infoPtr->tools) {
2303 for (i = 0; i < infoPtr->uNumTools; i++) {
2304 toolPtr = &infoPtr->tools[i];
2305 if (toolPtr->lpszText) {
2306 if ( (toolPtr->lpszText != LPSTR_TEXTCALLBACKW) &&
2307 !IS_INTRESOURCE(toolPtr->lpszText) )
2309 Free (toolPtr->lpszText);
2310 toolPtr->lpszText = NULL;
2314 /* remove subclassing */
2315 if (toolPtr->uFlags & TTF_SUBCLASS) {
2316 if (toolPtr->uFlags & TTF_IDISHWND) {
2317 RemoveWindowSubclass((HWND)toolPtr->uId, TOOLTIPS_SubclassProc, 1);
2319 else {
2320 RemoveWindowSubclass(toolPtr->hwnd, TOOLTIPS_SubclassProc, 1);
2324 Free (infoPtr->tools);
2327 /* free title string */
2328 Free (infoPtr->pszTitle);
2329 /* free title icon if not a standard one */
2330 if (TOOLTIPS_GetTitleIconIndex(infoPtr->hTitleIcon) > TTI_ERROR)
2331 DeleteObject(infoPtr->hTitleIcon);
2333 /* delete fonts */
2334 DeleteObject (infoPtr->hFont);
2335 DeleteObject (infoPtr->hTitleFont);
2337 /* free tool tips info data */
2338 SetWindowLongPtrW(infoPtr->hwndSelf, 0, 0);
2339 Free (infoPtr);
2341 return 0;
2345 static inline LRESULT
2346 TOOLTIPS_GetFont (const TOOLTIPS_INFO *infoPtr)
2348 return (LRESULT)infoPtr->hFont;
2352 static LRESULT
2353 TOOLTIPS_MouseMessage (TOOLTIPS_INFO *infoPtr)
2355 TOOLTIPS_Hide (infoPtr);
2357 return 0;
2361 static LRESULT
2362 TOOLTIPS_NCCreate (HWND hwnd, const CREATESTRUCTW *lpcs)
2364 DWORD dwStyle = GetWindowLongW (hwnd, GWL_STYLE);
2365 DWORD dwExStyle = GetWindowLongW (hwnd, GWL_EXSTYLE);
2367 dwStyle &= ~(WS_CHILD | /*WS_MAXIMIZE |*/ WS_BORDER | WS_DLGFRAME);
2368 dwStyle |= (WS_POPUP | WS_BORDER | WS_CLIPSIBLINGS);
2370 /* WS_BORDER only draws a border round the window rect, not the
2371 * window region, therefore it is useless to us in balloon mode */
2372 if (dwStyle & TTS_BALLOON) dwStyle &= ~WS_BORDER;
2374 SetWindowLongW (hwnd, GWL_STYLE, dwStyle);
2376 dwExStyle |= WS_EX_TOOLWINDOW;
2377 SetWindowLongW (hwnd, GWL_EXSTYLE, dwExStyle);
2379 return TRUE;
2383 static LRESULT
2384 TOOLTIPS_NCHitTest (const TOOLTIPS_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
2386 INT nTool = (infoPtr->bTrackActive) ? infoPtr->nTrackTool : infoPtr->nTool;
2388 TRACE(" nTool=%d\n", nTool);
2390 if ((nTool > -1) && (nTool < infoPtr->uNumTools)) {
2391 if (infoPtr->tools[nTool].uFlags & TTF_TRANSPARENT) {
2392 TRACE("-- in transparent mode!\n");
2393 return HTTRANSPARENT;
2397 return DefWindowProcW (infoPtr->hwndSelf, WM_NCHITTEST, wParam, lParam);
2401 static LRESULT
2402 TOOLTIPS_NotifyFormat (TOOLTIPS_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
2404 FIXME ("hwnd=%p wParam=%lx lParam=%lx\n", infoPtr->hwndSelf, wParam, lParam);
2406 return 0;
2410 static LRESULT
2411 TOOLTIPS_Paint (const TOOLTIPS_INFO *infoPtr, HDC hDC)
2413 HDC hdc;
2414 PAINTSTRUCT ps;
2416 hdc = (hDC == NULL) ? BeginPaint (infoPtr->hwndSelf, &ps) : hDC;
2417 TOOLTIPS_Refresh (infoPtr, hdc);
2418 if (!hDC)
2419 EndPaint (infoPtr->hwndSelf, &ps);
2420 return 0;
2424 static LRESULT
2425 TOOLTIPS_SetFont (TOOLTIPS_INFO *infoPtr, HFONT hFont, BOOL redraw)
2427 LOGFONTW lf;
2429 if(!GetObjectW(hFont, sizeof(lf), &lf))
2430 return 0;
2432 DeleteObject (infoPtr->hFont);
2433 infoPtr->hFont = CreateFontIndirectW(&lf);
2435 DeleteObject (infoPtr->hTitleFont);
2436 lf.lfWeight = FW_BOLD;
2437 infoPtr->hTitleFont = CreateFontIndirectW(&lf);
2439 if (redraw & (infoPtr->nCurrentTool != -1)) {
2440 FIXME("full redraw needed!\n");
2443 return 0;
2446 /******************************************************************
2447 * TOOLTIPS_GetTextLength
2449 * This function is called when the tooltip receive a
2450 * WM_GETTEXTLENGTH message.
2452 * returns the length, in characters, of the tip text
2454 static inline LRESULT
2455 TOOLTIPS_GetTextLength(const TOOLTIPS_INFO *infoPtr)
2457 return strlenW(infoPtr->szTipText);
2460 /******************************************************************
2461 * TOOLTIPS_OnWMGetText
2463 * This function is called when the tooltip receive a
2464 * WM_GETTEXT message.
2465 * wParam : specifies the maximum number of characters to be copied
2466 * lParam : is the pointer to the buffer that will receive
2467 * the tip text
2469 * returns the number of characters copied
2471 static LRESULT
2472 TOOLTIPS_OnWMGetText (const TOOLTIPS_INFO *infoPtr, WPARAM size, LPWSTR pszText)
2474 LRESULT res;
2476 if(!infoPtr->szTipText || !size)
2477 return 0;
2479 res = min(strlenW(infoPtr->szTipText)+1, size);
2480 memcpy(pszText, infoPtr->szTipText, res*sizeof(WCHAR));
2481 pszText[res-1] = '\0';
2482 return res-1;
2485 static LRESULT
2486 TOOLTIPS_Timer (TOOLTIPS_INFO *infoPtr, INT iTimer)
2488 INT nOldTool;
2490 TRACE("timer %d (%p) expired!\n", iTimer, infoPtr->hwndSelf);
2492 switch (iTimer) {
2493 case ID_TIMERSHOW:
2494 KillTimer (infoPtr->hwndSelf, ID_TIMERSHOW);
2495 nOldTool = infoPtr->nTool;
2496 if ((infoPtr->nTool = TOOLTIPS_CheckTool (infoPtr, TRUE)) == nOldTool)
2497 TOOLTIPS_Show (infoPtr, FALSE);
2498 break;
2500 case ID_TIMERPOP:
2501 TOOLTIPS_Hide (infoPtr);
2502 break;
2504 case ID_TIMERLEAVE:
2505 nOldTool = infoPtr->nTool;
2506 infoPtr->nTool = TOOLTIPS_CheckTool (infoPtr, FALSE);
2507 TRACE("tool (%p) %d %d %d\n", infoPtr->hwndSelf, nOldTool,
2508 infoPtr->nTool, infoPtr->nCurrentTool);
2509 if (infoPtr->nTool != nOldTool) {
2510 if(infoPtr->nTool == -1) { /* Moved out of all tools */
2511 TOOLTIPS_Hide(infoPtr);
2512 KillTimer(infoPtr->hwndSelf, ID_TIMERLEAVE);
2513 } else if (nOldTool == -1) { /* Moved from outside */
2514 ERR("How did this happen?\n");
2515 } else { /* Moved from one to another */
2516 TOOLTIPS_Hide (infoPtr);
2517 KillTimer(infoPtr->hwndSelf, ID_TIMERLEAVE);
2518 if(infoPtr->bActive) {
2519 SetTimer (infoPtr->hwndSelf, ID_TIMERSHOW, infoPtr->nReshowTime, 0);
2520 TRACE("timer 1 started!\n");
2524 break;
2526 default:
2527 ERR("Unknown timer id %d\n", iTimer);
2528 break;
2530 return 0;
2534 static LRESULT
2535 TOOLTIPS_WinIniChange (TOOLTIPS_INFO *infoPtr)
2537 TOOLTIPS_InitSystemSettings (infoPtr);
2539 return 0;
2543 static LRESULT CALLBACK
2544 TOOLTIPS_SubclassProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uID, DWORD_PTR dwRef)
2546 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr ((HWND)dwRef);
2547 MSG msg;
2549 switch(uMsg) {
2550 case WM_MOUSEMOVE:
2551 case WM_LBUTTONDOWN:
2552 case WM_LBUTTONUP:
2553 case WM_MBUTTONDOWN:
2554 case WM_MBUTTONUP:
2555 case WM_RBUTTONDOWN:
2556 case WM_RBUTTONUP:
2557 msg.hwnd = hwnd;
2558 msg.message = uMsg;
2559 msg.wParam = wParam;
2560 msg.lParam = lParam;
2561 TOOLTIPS_RelayEvent(infoPtr, &msg);
2562 break;
2564 default:
2565 break;
2567 return DefSubclassProc(hwnd, uMsg, wParam, lParam);
2571 static LRESULT CALLBACK
2572 TOOLTIPS_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2574 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
2576 TRACE("hwnd=%p msg=%x wparam=%lx lParam=%lx\n", hwnd, uMsg, wParam, lParam);
2577 if (!infoPtr && (uMsg != WM_CREATE) && (uMsg != WM_NCCREATE))
2578 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
2579 switch (uMsg)
2581 case TTM_ACTIVATE:
2582 return TOOLTIPS_Activate (infoPtr, (BOOL)wParam);
2584 case TTM_ADDTOOLA:
2585 return TOOLTIPS_AddToolA (infoPtr, (LPTTTOOLINFOA)lParam);
2587 case TTM_ADDTOOLW:
2588 return TOOLTIPS_AddToolW (infoPtr, (LPTTTOOLINFOW)lParam);
2590 case TTM_DELTOOLA:
2591 return TOOLTIPS_DelToolA (infoPtr, (LPTOOLINFOA)lParam);
2593 case TTM_DELTOOLW:
2594 return TOOLTIPS_DelToolW (infoPtr, (LPTOOLINFOW)lParam);
2596 case TTM_ENUMTOOLSA:
2597 return TOOLTIPS_EnumToolsA (infoPtr, (UINT)wParam, (LPTTTOOLINFOA)lParam);
2599 case TTM_ENUMTOOLSW:
2600 return TOOLTIPS_EnumToolsW (infoPtr, (UINT)wParam, (LPTTTOOLINFOW)lParam);
2602 case TTM_GETBUBBLESIZE:
2603 return TOOLTIPS_GetBubbleSize (infoPtr, (LPTTTOOLINFOW)lParam);
2605 case TTM_GETCURRENTTOOLA:
2606 return TOOLTIPS_GetCurrentToolA (infoPtr, (LPTTTOOLINFOA)lParam);
2608 case TTM_GETCURRENTTOOLW:
2609 return TOOLTIPS_GetCurrentToolW (infoPtr, (LPTTTOOLINFOW)lParam);
2611 case TTM_GETDELAYTIME:
2612 return TOOLTIPS_GetDelayTime (infoPtr, (DWORD)wParam);
2614 case TTM_GETMARGIN:
2615 return TOOLTIPS_GetMargin (infoPtr, (LPRECT)lParam);
2617 case TTM_GETMAXTIPWIDTH:
2618 return TOOLTIPS_GetMaxTipWidth (infoPtr);
2620 case TTM_GETTEXTA:
2621 return TOOLTIPS_GetTextA (infoPtr, (LPTTTOOLINFOA)lParam);
2623 case TTM_GETTEXTW:
2624 return TOOLTIPS_GetTextW (infoPtr, (LPTTTOOLINFOW)lParam);
2626 case TTM_GETTIPBKCOLOR:
2627 return TOOLTIPS_GetTipBkColor (infoPtr);
2629 case TTM_GETTIPTEXTCOLOR:
2630 return TOOLTIPS_GetTipTextColor (infoPtr);
2632 case TTM_GETTOOLCOUNT:
2633 return TOOLTIPS_GetToolCount (infoPtr);
2635 case TTM_GETTOOLINFOA:
2636 return TOOLTIPS_GetToolInfoA (infoPtr, (LPTTTOOLINFOA)lParam);
2638 case TTM_GETTOOLINFOW:
2639 return TOOLTIPS_GetToolInfoW (infoPtr, (LPTTTOOLINFOW)lParam);
2641 case TTM_HITTESTA:
2642 return TOOLTIPS_HitTestA (infoPtr, (LPTTHITTESTINFOA)lParam);
2644 case TTM_HITTESTW:
2645 return TOOLTIPS_HitTestW (infoPtr, (LPTTHITTESTINFOW)lParam);
2647 case TTM_NEWTOOLRECTA:
2648 return TOOLTIPS_NewToolRectA (infoPtr, (LPTTTOOLINFOA)lParam);
2650 case TTM_NEWTOOLRECTW:
2651 return TOOLTIPS_NewToolRectW (infoPtr, (LPTTTOOLINFOW)lParam);
2653 case TTM_POP:
2654 return TOOLTIPS_Pop (infoPtr);
2656 case TTM_RELAYEVENT:
2657 return TOOLTIPS_RelayEvent (infoPtr, (LPMSG)lParam);
2659 case TTM_SETDELAYTIME:
2660 return TOOLTIPS_SetDelayTime (infoPtr, (DWORD)wParam, (INT)LOWORD(lParam));
2662 case TTM_SETMARGIN:
2663 return TOOLTIPS_SetMargin (infoPtr, (LPRECT)lParam);
2665 case TTM_SETMAXTIPWIDTH:
2666 return TOOLTIPS_SetMaxTipWidth (infoPtr, (INT)lParam);
2668 case TTM_SETTIPBKCOLOR:
2669 return TOOLTIPS_SetTipBkColor (infoPtr, (COLORREF)wParam);
2671 case TTM_SETTIPTEXTCOLOR:
2672 return TOOLTIPS_SetTipTextColor (infoPtr, (COLORREF)wParam);
2674 case TTM_SETTITLEA:
2675 return TOOLTIPS_SetTitleA (infoPtr, (UINT_PTR)wParam, (LPCSTR)lParam);
2677 case TTM_SETTITLEW:
2678 return TOOLTIPS_SetTitleW (infoPtr, (UINT_PTR)wParam, (LPCWSTR)lParam);
2680 case TTM_SETTOOLINFOA:
2681 return TOOLTIPS_SetToolInfoA (infoPtr, (LPTTTOOLINFOA)lParam);
2683 case TTM_SETTOOLINFOW:
2684 return TOOLTIPS_SetToolInfoW (infoPtr, (LPTTTOOLINFOW)lParam);
2686 case TTM_TRACKACTIVATE:
2687 return TOOLTIPS_TrackActivate (infoPtr, (BOOL)wParam, (LPTTTOOLINFOA)lParam);
2689 case TTM_TRACKPOSITION:
2690 return TOOLTIPS_TrackPosition (infoPtr, lParam);
2692 case TTM_UPDATE:
2693 return TOOLTIPS_Update (infoPtr);
2695 case TTM_UPDATETIPTEXTA:
2696 return TOOLTIPS_UpdateTipTextA (infoPtr, (LPTTTOOLINFOA)lParam);
2698 case TTM_UPDATETIPTEXTW:
2699 return TOOLTIPS_UpdateTipTextW (infoPtr, (LPTTTOOLINFOW)lParam);
2701 case TTM_WINDOWFROMPOINT:
2702 return TOOLTIPS_WindowFromPoint (hwnd, wParam, lParam);
2705 case WM_CREATE:
2706 return TOOLTIPS_Create (hwnd, (LPCREATESTRUCTW)lParam);
2708 case WM_DESTROY:
2709 return TOOLTIPS_Destroy (infoPtr);
2711 case WM_ERASEBKGND:
2712 /* we draw the background in WM_PAINT */
2713 return 0;
2715 case WM_GETFONT:
2716 return TOOLTIPS_GetFont (infoPtr);
2718 case WM_GETTEXT:
2719 return TOOLTIPS_OnWMGetText (infoPtr, wParam, (LPWSTR)lParam);
2721 case WM_GETTEXTLENGTH:
2722 return TOOLTIPS_GetTextLength (infoPtr);
2724 case WM_LBUTTONDOWN:
2725 case WM_LBUTTONUP:
2726 case WM_MBUTTONDOWN:
2727 case WM_MBUTTONUP:
2728 case WM_RBUTTONDOWN:
2729 case WM_RBUTTONUP:
2730 case WM_MOUSEMOVE:
2731 return TOOLTIPS_MouseMessage (infoPtr);
2733 case WM_NCCREATE:
2734 return TOOLTIPS_NCCreate (hwnd, (LPCREATESTRUCTW)lParam);
2736 case WM_NCHITTEST:
2737 return TOOLTIPS_NCHitTest (infoPtr, wParam, lParam);
2739 case WM_NOTIFYFORMAT:
2740 return TOOLTIPS_NotifyFormat (infoPtr, wParam, lParam);
2742 case WM_PRINTCLIENT:
2743 case WM_PAINT:
2744 return TOOLTIPS_Paint (infoPtr, (HDC)wParam);
2746 case WM_SETFONT:
2747 return TOOLTIPS_SetFont (infoPtr, (HFONT)wParam, LOWORD(lParam));
2749 case WM_SYSCOLORCHANGE:
2750 COMCTL32_RefreshSysColors();
2751 return 0;
2753 case WM_TIMER:
2754 return TOOLTIPS_Timer (infoPtr, (INT)wParam);
2756 case WM_WININICHANGE:
2757 return TOOLTIPS_WinIniChange (infoPtr);
2759 default:
2760 if ((uMsg >= WM_USER) && (uMsg < WM_APP) && !COMCTL32_IsReflectedMessage(uMsg))
2761 ERR("unknown msg %04x wp=%08lx lp=%08lx\n",
2762 uMsg, wParam, lParam);
2763 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
2768 VOID
2769 TOOLTIPS_Register (void)
2771 WNDCLASSW wndClass;
2773 ZeroMemory (&wndClass, sizeof(WNDCLASSW));
2774 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS | CS_SAVEBITS;
2775 wndClass.lpfnWndProc = TOOLTIPS_WindowProc;
2776 wndClass.cbClsExtra = 0;
2777 wndClass.cbWndExtra = sizeof(TOOLTIPS_INFO *);
2778 wndClass.hCursor = LoadCursorW (0, (LPWSTR)IDC_ARROW);
2779 wndClass.hbrBackground = 0;
2780 wndClass.lpszClassName = TOOLTIPS_CLASSW;
2782 RegisterClassW (&wndClass);
2784 hTooltipIcons[TTI_NONE] = NULL;
2785 hTooltipIcons[TTI_INFO] = LoadImageW(COMCTL32_hModule,
2786 (LPCWSTR)MAKEINTRESOURCE(IDI_TT_INFO_SM), IMAGE_ICON, 0, 0, 0);
2787 hTooltipIcons[TTI_WARNING] = LoadImageW(COMCTL32_hModule,
2788 (LPCWSTR)MAKEINTRESOURCE(IDI_TT_WARN_SM), IMAGE_ICON, 0, 0, 0);
2789 hTooltipIcons[TTI_ERROR] = LoadImageW(COMCTL32_hModule,
2790 (LPCWSTR)MAKEINTRESOURCE(IDI_TT_ERROR_SM), IMAGE_ICON, 0, 0, 0);
2794 VOID
2795 TOOLTIPS_Unregister (void)
2797 int i;
2798 for (i = TTI_INFO; i <= TTI_ERROR; i++)
2799 DestroyIcon(hTooltipIcons[i]);
2800 UnregisterClassW (TOOLTIPS_CLASSW, NULL);