xref: /reactos/dll/win32/comctl32/tooltips.c (revision 1734f297)
1 /*
2  * Tool tip control
3  *
4  * Copyright 1998, 1999 Eric Kohl
5  * Copyright 2004 Robert Shearman
6  *
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.
11  *
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.
16  *
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
20  *
21  * NOTES
22  *
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.
25  *
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.
29  *
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
43  *
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.
49  *
50  *   Timer logic.
51  *
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.
60  *
61  *
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.
70  *
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.
80  *
81  *
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.
84  *
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.
89  *
90  */
91 
92 
93 
94 #include <stdarg.h>
95 #include <string.h>
96 
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"
106 
107 WINE_DEFAULT_DEBUG_CHANNEL(tooltips);
108 
109 static HICON hTooltipIcons[TTI_ERROR+1];
110 
111 typedef struct
112 {
113     UINT      uFlags;
114     UINT      uInternalFlags;
115     HWND      hwnd;
116     BOOL      bNotifyUnicode;
117     UINT_PTR  uId;
118     RECT      rect;
119     HINSTANCE hinst;
120     LPWSTR      lpszText;
121     LPARAM      lParam;
122 } TTTOOL_INFO;
123 
124 
125 typedef struct
126 {
127     HWND     hwndSelf;
128     WCHAR      szTipText[INFOTIPSIZE];
129     BOOL     bActive;
130     BOOL     bTrackActive;
131     UINT     uNumTools;
132     COLORREF   clrBk;
133     COLORREF   clrText;
134     HFONT    hFont;
135     HFONT    hTitleFont;
136     INT      xTrackPos;
137     INT      yTrackPos;
138     INT      nMaxTipWidth;
139     INT      nTool; /* tool that mouse was on on last relayed mouse move */
140     INT      nCurrentTool;
141     INT      nTrackTool;
142     INT      nReshowTime;
143     INT      nAutoPopTime;
144     INT      nInitialTime;
145     RECT     rcMargin;
146     BOOL     bToolBelow;
147     LPWSTR   pszTitle;
148     HICON    hTitleIcon;
149 
150     TTTOOL_INFO *tools;
151 } TOOLTIPS_INFO;
152 
153 #define ID_TIMERSHOW   1    /* show delay timer */
154 #define ID_TIMERPOP    2    /* auto pop timer */
155 #define ID_TIMERLEAVE  3    /* tool leave timer */
156 
157 
158 #define TOOLTIPS_GetInfoPtr(hWindow) ((TOOLTIPS_INFO *)GetWindowLongPtrW (hWindow, 0))
159 
160 /* offsets from window edge to start of text */
161 #define NORMAL_TEXT_MARGIN 2
162 #define BALLOON_TEXT_MARGIN (NORMAL_TEXT_MARGIN+8)
163 /* value used for CreateRoundRectRgn that specifies how much
164  * each corner is curved */
165 #define BALLOON_ROUNDEDNESS 20
166 #define BALLOON_STEMHEIGHT 13
167 #define BALLOON_STEMWIDTH 10
168 #define BALLOON_STEMINDENT 20
169 
170 #define BALLOON_ICON_TITLE_SPACING 8 /* horizontal spacing between icon and title */
171 #define BALLOON_TITLE_TEXT_SPACING 8 /* vertical spacing between icon/title and main text */
172 #define ICON_HEIGHT 16
173 #define ICON_WIDTH  16
174 
175 #define MAX_TEXT_SIZE_A 80 /* maximum retrieving text size by ANSI message */
176 
177 static LRESULT CALLBACK
178 TOOLTIPS_SubclassProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uId, DWORD_PTR dwRef);
179 
180 
181 static inline BOOL TOOLTIPS_IsCallbackString(LPCWSTR str, BOOL isW)
182 {
183     if (isW)
184       return str == LPSTR_TEXTCALLBACKW;
185     else
186       return (LPCSTR)str == LPSTR_TEXTCALLBACKA;
187 }
188 
189 static inline UINT_PTR
190 TOOLTIPS_GetTitleIconIndex(HICON hIcon)
191 {
192     UINT i;
193     for (i = 0; i <= TTI_ERROR; i++)
194         if (hTooltipIcons[i] == hIcon)
195             return i;
196     return (UINT_PTR)hIcon;
197 }
198 
199 static void
200 TOOLTIPS_InitSystemSettings (TOOLTIPS_INFO *infoPtr)
201 {
202     NONCLIENTMETRICSW nclm;
203 
204     infoPtr->clrBk   = comctl32_color.clrInfoBk;
205     infoPtr->clrText = comctl32_color.clrInfoText;
206 
207     DeleteObject (infoPtr->hFont);
208     nclm.cbSize = sizeof(nclm);
209     SystemParametersInfoW (SPI_GETNONCLIENTMETRICS, sizeof(nclm), &nclm, 0);
210     infoPtr->hFont = CreateFontIndirectW (&nclm.lfStatusFont);
211 
212     DeleteObject (infoPtr->hTitleFont);
213     nclm.lfStatusFont.lfWeight = FW_BOLD;
214     infoPtr->hTitleFont = CreateFontIndirectW (&nclm.lfStatusFont);
215 }
216 
217 /* Custom draw routines */
218 static void
219 TOOLTIPS_customdraw_fill(const TOOLTIPS_INFO *infoPtr, NMTTCUSTOMDRAW *lpnmttcd,
220                          HDC hdc, const RECT *rcBounds, UINT uFlags)
221 {
222     ZeroMemory(lpnmttcd, sizeof(NMTTCUSTOMDRAW));
223     lpnmttcd->uDrawFlags = uFlags;
224     lpnmttcd->nmcd.hdr.hwndFrom = infoPtr->hwndSelf;
225     lpnmttcd->nmcd.hdr.code     = NM_CUSTOMDRAW;
226     if (infoPtr->nCurrentTool != -1) {
227         TTTOOL_INFO *toolPtr = &infoPtr->tools[infoPtr->nCurrentTool];
228         lpnmttcd->nmcd.hdr.idFrom = toolPtr->uId;
229     }
230     lpnmttcd->nmcd.hdc = hdc;
231     lpnmttcd->nmcd.rc = *rcBounds;
232     /* FIXME - dwItemSpec, uItemState, lItemlParam */
233 }
234 
235 static inline DWORD
236 TOOLTIPS_notify_customdraw (DWORD dwDrawStage, NMTTCUSTOMDRAW *lpnmttcd)
237 {
238     LRESULT result;
239     lpnmttcd->nmcd.dwDrawStage = dwDrawStage;
240 
241     TRACE("Notifying stage %d, flags %x, id %x\n", lpnmttcd->nmcd.dwDrawStage,
242           lpnmttcd->uDrawFlags, lpnmttcd->nmcd.hdr.code);
243 
244     result = SendMessageW(GetParent(lpnmttcd->nmcd.hdr.hwndFrom), WM_NOTIFY,
245                           0, (LPARAM)lpnmttcd);
246 
247     TRACE("Notify result %x\n", (unsigned int)result);
248 
249     return result;
250 }
251 
252 static void
253 TOOLTIPS_Refresh (const TOOLTIPS_INFO *infoPtr, HDC hdc)
254 {
255     RECT rc;
256     INT oldBkMode;
257     HFONT hOldFont;
258     HBRUSH hBrush;
259     UINT uFlags = DT_EXTERNALLEADING;
260     HRGN hRgn = NULL;
261     DWORD dwStyle = GetWindowLongW(infoPtr->hwndSelf, GWL_STYLE);
262     NMTTCUSTOMDRAW nmttcd;
263     DWORD cdmode;
264 
265     if (infoPtr->nMaxTipWidth > -1)
266 	uFlags |= DT_WORDBREAK;
267     if (GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE) & TTS_NOPREFIX)
268 	uFlags |= DT_NOPREFIX;
269     GetClientRect (infoPtr->hwndSelf, &rc);
270 
271     hBrush = CreateSolidBrush(infoPtr->clrBk);
272 
273     oldBkMode = SetBkMode (hdc, TRANSPARENT);
274     SetTextColor (hdc, infoPtr->clrText);
275     hOldFont = SelectObject (hdc, infoPtr->hFont);
276 
277     /* Custom draw - Call PrePaint once initial properties set up     */
278     /* Note: Contrary to MSDN, CDRF_SKIPDEFAULT still draws a tooltip */
279     TOOLTIPS_customdraw_fill(infoPtr, &nmttcd, hdc, &rc, uFlags);
280     cdmode = TOOLTIPS_notify_customdraw(CDDS_PREPAINT, &nmttcd);
281     uFlags = nmttcd.uDrawFlags;
282 
283     if (dwStyle & TTS_BALLOON)
284     {
285         /* create a region to store result into */
286         hRgn = CreateRectRgn(0, 0, 0, 0);
287 
288         GetWindowRgn(infoPtr->hwndSelf, hRgn);
289 
290         /* fill the background */
291         FillRgn(hdc, hRgn, hBrush);
292         DeleteObject(hBrush);
293         hBrush = NULL;
294     }
295     else
296     {
297         /* fill the background */
298         FillRect(hdc, &rc, hBrush);
299         DeleteObject(hBrush);
300         hBrush = NULL;
301     }
302 
303     if ((dwStyle & TTS_BALLOON) || infoPtr->pszTitle)
304     {
305         /* calculate text rectangle */
306         rc.left   += (BALLOON_TEXT_MARGIN + infoPtr->rcMargin.left);
307         rc.top    += (BALLOON_TEXT_MARGIN + infoPtr->rcMargin.top);
308         rc.right  -= (BALLOON_TEXT_MARGIN + infoPtr->rcMargin.right);
309         rc.bottom -= (BALLOON_TEXT_MARGIN + infoPtr->rcMargin.bottom);
310         if(infoPtr->bToolBelow) rc.top += BALLOON_STEMHEIGHT;
311 
312         if (infoPtr->pszTitle)
313         {
314             RECT rcTitle = {rc.left, rc.top, rc.right, rc.bottom};
315             int height;
316             BOOL icon_present;
317             HFONT prevFont;
318 
319             /* draw icon */
320             icon_present = infoPtr->hTitleIcon &&
321                 DrawIconEx(hdc, rc.left, rc.top, infoPtr->hTitleIcon,
322                            ICON_WIDTH, ICON_HEIGHT, 0, NULL, DI_NORMAL);
323             if (icon_present)
324                 rcTitle.left += ICON_WIDTH + BALLOON_ICON_TITLE_SPACING;
325 
326             rcTitle.bottom = rc.top + ICON_HEIGHT;
327 
328             /* draw title text */
329             prevFont = SelectObject (hdc, infoPtr->hTitleFont);
330             height = DrawTextW(hdc, infoPtr->pszTitle, -1, &rcTitle, DT_BOTTOM | DT_SINGLELINE | DT_NOPREFIX);
331             SelectObject (hdc, prevFont);
332             rc.top += height + BALLOON_TITLE_TEXT_SPACING;
333         }
334     }
335     else
336     {
337         /* calculate text rectangle */
338         rc.left   += (NORMAL_TEXT_MARGIN + infoPtr->rcMargin.left);
339         rc.top    += (NORMAL_TEXT_MARGIN + infoPtr->rcMargin.top);
340         rc.right  -= (NORMAL_TEXT_MARGIN + infoPtr->rcMargin.right);
341         rc.bottom -= (NORMAL_TEXT_MARGIN + infoPtr->rcMargin.bottom);
342     }
343 
344     /* draw text */
345     DrawTextW (hdc, infoPtr->szTipText, -1, &rc, uFlags);
346 
347     /* Custom draw - Call PostPaint after drawing */
348     if (cdmode & CDRF_NOTIFYPOSTPAINT) {
349         TOOLTIPS_notify_customdraw(CDDS_POSTPAINT, &nmttcd);
350     }
351 
352     /* be polite and reset the things we changed in the dc */
353     SelectObject (hdc, hOldFont);
354     SetBkMode (hdc, oldBkMode);
355 
356     if (dwStyle & TTS_BALLOON)
357     {
358         /* frame region because default window proc doesn't do it */
359         INT width = GetSystemMetrics(SM_CXDLGFRAME) - GetSystemMetrics(SM_CXEDGE);
360         INT height = GetSystemMetrics(SM_CYDLGFRAME) - GetSystemMetrics(SM_CYEDGE);
361 
362         hBrush = GetSysColorBrush(COLOR_WINDOWFRAME);
363         FrameRgn(hdc, hRgn, hBrush, width, height);
364     }
365 
366     if (hRgn)
367         DeleteObject(hRgn);
368 }
369 
370 static void TOOLTIPS_GetDispInfoA(const TOOLTIPS_INFO *infoPtr, TTTOOL_INFO *toolPtr, WCHAR *buffer)
371 {
372     NMTTDISPINFOA ttnmdi;
373 
374     /* fill NMHDR struct */
375     ZeroMemory (&ttnmdi, sizeof(NMTTDISPINFOA));
376     ttnmdi.hdr.hwndFrom = infoPtr->hwndSelf;
377     ttnmdi.hdr.idFrom = toolPtr->uId;
378     ttnmdi.hdr.code = TTN_GETDISPINFOA; /* == TTN_NEEDTEXTA */
379     ttnmdi.lpszText = ttnmdi.szText;
380     ttnmdi.uFlags = toolPtr->uFlags;
381     ttnmdi.lParam = toolPtr->lParam;
382 
383     TRACE("hdr.idFrom = %lx\n", ttnmdi.hdr.idFrom);
384     SendMessageW(toolPtr->hwnd, WM_NOTIFY, toolPtr->uId, (LPARAM)&ttnmdi);
385 
386     if (IS_INTRESOURCE(ttnmdi.lpszText)) {
387         LoadStringW(ttnmdi.hinst, LOWORD(ttnmdi.lpszText),
388                buffer, INFOTIPSIZE);
389         if (ttnmdi.uFlags & TTF_DI_SETITEM) {
390             toolPtr->hinst = ttnmdi.hinst;
391             toolPtr->lpszText = (LPWSTR)ttnmdi.lpszText;
392         }
393     }
394     else if (ttnmdi.lpszText == 0) {
395         buffer[0] = '\0';
396     }
397     else if (ttnmdi.lpszText != LPSTR_TEXTCALLBACKA) {
398         Str_GetPtrAtoW(ttnmdi.lpszText, buffer, INFOTIPSIZE);
399         if (ttnmdi.uFlags & TTF_DI_SETITEM) {
400             toolPtr->hinst = 0;
401             toolPtr->lpszText = NULL;
402             Str_SetPtrW(&toolPtr->lpszText, buffer);
403         }
404     }
405     else {
406         ERR("recursive text callback\n");
407         buffer[0] = '\0';
408     }
409 
410     /* no text available - try calling parent instead as per native */
411     /* FIXME: Unsure if SETITEM should save the value or not        */
412     if (buffer[0] == 0x00) {
413 
414         SendMessageW(GetParent(toolPtr->hwnd), WM_NOTIFY, toolPtr->uId, (LPARAM)&ttnmdi);
415 
416         if (IS_INTRESOURCE(ttnmdi.lpszText)) {
417             LoadStringW(ttnmdi.hinst, LOWORD(ttnmdi.lpszText),
418                    buffer, INFOTIPSIZE);
419         } else if (ttnmdi.lpszText &&
420                    ttnmdi.lpszText != LPSTR_TEXTCALLBACKA) {
421             Str_GetPtrAtoW(ttnmdi.lpszText, buffer, INFOTIPSIZE);
422         }
423     }
424 }
425 
426 static void TOOLTIPS_GetDispInfoW(const TOOLTIPS_INFO *infoPtr, TTTOOL_INFO *toolPtr, WCHAR *buffer)
427 {
428     NMTTDISPINFOW ttnmdi;
429 
430     /* fill NMHDR struct */
431     ZeroMemory (&ttnmdi, sizeof(NMTTDISPINFOW));
432     ttnmdi.hdr.hwndFrom = infoPtr->hwndSelf;
433     ttnmdi.hdr.idFrom = toolPtr->uId;
434     ttnmdi.hdr.code = TTN_GETDISPINFOW; /* == TTN_NEEDTEXTW */
435     ttnmdi.lpszText = ttnmdi.szText;
436     ttnmdi.uFlags = toolPtr->uFlags;
437     ttnmdi.lParam = toolPtr->lParam;
438 
439     TRACE("hdr.idFrom = %lx\n", ttnmdi.hdr.idFrom);
440     SendMessageW(toolPtr->hwnd, WM_NOTIFY, toolPtr->uId, (LPARAM)&ttnmdi);
441 
442     if (IS_INTRESOURCE(ttnmdi.lpszText)) {
443         LoadStringW(ttnmdi.hinst, LOWORD(ttnmdi.lpszText),
444                buffer, INFOTIPSIZE);
445         if (ttnmdi.uFlags & TTF_DI_SETITEM) {
446             toolPtr->hinst = ttnmdi.hinst;
447             toolPtr->lpszText = ttnmdi.lpszText;
448         }
449     }
450     else if (ttnmdi.lpszText == 0) {
451         buffer[0] = '\0';
452     }
453     else if (ttnmdi.lpszText != LPSTR_TEXTCALLBACKW) {
454         Str_GetPtrW(ttnmdi.lpszText, buffer, INFOTIPSIZE);
455         if (ttnmdi.uFlags & TTF_DI_SETITEM) {
456             toolPtr->hinst = 0;
457             toolPtr->lpszText = NULL;
458             Str_SetPtrW(&toolPtr->lpszText, buffer);
459         }
460     }
461     else {
462         ERR("recursive text callback\n");
463         buffer[0] = '\0';
464     }
465 
466     /* no text available - try calling parent instead as per native */
467     /* FIXME: Unsure if SETITEM should save the value or not        */
468     if (buffer[0] == 0x00) {
469 
470         SendMessageW(GetParent(toolPtr->hwnd), WM_NOTIFY, toolPtr->uId, (LPARAM)&ttnmdi);
471 
472         if (IS_INTRESOURCE(ttnmdi.lpszText)) {
473             LoadStringW(ttnmdi.hinst, LOWORD(ttnmdi.lpszText),
474                    buffer, INFOTIPSIZE);
475         } else if (ttnmdi.lpszText &&
476                    ttnmdi.lpszText != LPSTR_TEXTCALLBACKW) {
477             Str_GetPtrW(ttnmdi.lpszText, buffer, INFOTIPSIZE);
478         }
479     }
480 
481 }
482 
483 static void
484 TOOLTIPS_GetTipText (const TOOLTIPS_INFO *infoPtr, INT nTool, WCHAR *buffer)
485 {
486     TTTOOL_INFO *toolPtr = &infoPtr->tools[nTool];
487 
488     if (IS_INTRESOURCE(toolPtr->lpszText)) {
489 	/* load a resource */
490 	TRACE("load res string %p %x\n",
491 	       toolPtr->hinst, LOWORD(toolPtr->lpszText));
492 	if (!LoadStringW (toolPtr->hinst, LOWORD(toolPtr->lpszText), buffer, INFOTIPSIZE))
493 	    buffer[0] = '\0';
494     }
495     else if (toolPtr->lpszText) {
496 	if (toolPtr->lpszText == LPSTR_TEXTCALLBACKW) {
497 	    if (toolPtr->bNotifyUnicode)
498 		TOOLTIPS_GetDispInfoW(infoPtr, toolPtr, buffer);
499 	    else
500 		TOOLTIPS_GetDispInfoA(infoPtr, toolPtr, buffer);
501 	}
502 	else {
503 	    /* the item is a usual (unicode) text */
504 	    lstrcpynW (buffer, toolPtr->lpszText, INFOTIPSIZE);
505 	}
506     }
507     else {
508 	/* no text available */
509         buffer[0] = '\0';
510     }
511 
512     if (!(GetWindowLongW(infoPtr->hwndSelf, GWL_STYLE) & TTS_NOPREFIX)) {
513         WCHAR *ptrW;
514         if ((ptrW = strchrW(buffer, '\t')))
515             *ptrW = 0;
516     }
517 
518     TRACE("%s\n", debugstr_w(buffer));
519 }
520 
521 
522 static void
523 TOOLTIPS_CalcTipSize (const TOOLTIPS_INFO *infoPtr, LPSIZE lpSize)
524 {
525     HDC hdc;
526     HFONT hOldFont;
527     DWORD style = GetWindowLongW(infoPtr->hwndSelf, GWL_STYLE);
528     UINT uFlags = DT_EXTERNALLEADING | DT_CALCRECT;
529     RECT rc = {0, 0, 0, 0};
530     SIZE title = {0, 0};
531 
532     if (infoPtr->nMaxTipWidth > -1) {
533 	rc.right = infoPtr->nMaxTipWidth;
534 	uFlags |= DT_WORDBREAK;
535     }
536     if (style & TTS_NOPREFIX)
537 	uFlags |= DT_NOPREFIX;
538     TRACE("%s\n", debugstr_w(infoPtr->szTipText));
539 
540     hdc = GetDC (infoPtr->hwndSelf);
541     if (infoPtr->pszTitle)
542     {
543         RECT rcTitle = {0, 0, 0, 0};
544         TRACE("title %s\n", debugstr_w(infoPtr->pszTitle));
545         if (infoPtr->hTitleIcon)
546         {
547             title.cx = ICON_WIDTH;
548             title.cy = ICON_HEIGHT;
549         }
550         if (title.cx != 0) title.cx += BALLOON_ICON_TITLE_SPACING;
551         hOldFont = SelectObject (hdc, infoPtr->hTitleFont);
552         DrawTextW(hdc, infoPtr->pszTitle, -1, &rcTitle, DT_SINGLELINE | DT_NOPREFIX | DT_CALCRECT);
553         SelectObject (hdc, hOldFont);
554         title.cy = max(title.cy, rcTitle.bottom - rcTitle.top) + BALLOON_TITLE_TEXT_SPACING;
555         title.cx += (rcTitle.right - rcTitle.left);
556     }
557     hOldFont = SelectObject (hdc, infoPtr->hFont);
558     DrawTextW (hdc, infoPtr->szTipText, -1, &rc, uFlags);
559     SelectObject (hdc, hOldFont);
560     ReleaseDC (infoPtr->hwndSelf, hdc);
561 
562     if ((style & TTS_BALLOON) || infoPtr->pszTitle)
563     {
564         lpSize->cx = max(rc.right - rc.left, title.cx) + 2*BALLOON_TEXT_MARGIN +
565                        infoPtr->rcMargin.left + infoPtr->rcMargin.right;
566         lpSize->cy = title.cy + rc.bottom - rc.top + 2*BALLOON_TEXT_MARGIN +
567                        infoPtr->rcMargin.bottom + infoPtr->rcMargin.top +
568                        BALLOON_STEMHEIGHT;
569     }
570     else
571     {
572         lpSize->cx = rc.right - rc.left + 2*NORMAL_TEXT_MARGIN +
573                        infoPtr->rcMargin.left + infoPtr->rcMargin.right;
574         lpSize->cy = rc.bottom - rc.top + 2*NORMAL_TEXT_MARGIN +
575                        infoPtr->rcMargin.bottom + infoPtr->rcMargin.top;
576     }
577 }
578 
579 
580 static void
581 TOOLTIPS_Show (TOOLTIPS_INFO *infoPtr, BOOL track_activate)
582 {
583     TTTOOL_INFO *toolPtr;
584     HMONITOR monitor;
585     MONITORINFO mon_info;
586     RECT rect;
587     SIZE size;
588     NMHDR  hdr;
589     int ptfx = 0;
590     DWORD style = GetWindowLongW(infoPtr->hwndSelf, GWL_STYLE);
591     INT nTool, current;
592 
593     if (track_activate)
594     {
595         if (infoPtr->nTrackTool == -1)
596         {
597             TRACE("invalid tracking tool %d\n", infoPtr->nTrackTool);
598             return;
599         }
600         nTool = infoPtr->nTrackTool;
601     }
602     else
603     {
604         if (infoPtr->nTool == -1)
605         {
606             TRACE("invalid tool %d\n", infoPtr->nTool);
607             return;
608         }
609         nTool = infoPtr->nTool;
610     }
611 
612     TRACE("Show tooltip pre %d, %p\n", nTool, infoPtr->hwndSelf);
613 
614     current = infoPtr->nCurrentTool;
615     if (!track_activate)
616         infoPtr->nCurrentTool = infoPtr->nTool;
617 
618     TOOLTIPS_GetTipText (infoPtr, nTool, infoPtr->szTipText);
619 
620     if (infoPtr->szTipText[0] == '\0')
621     {
622         infoPtr->nCurrentTool = current;
623         return;
624     }
625 
626     toolPtr = &infoPtr->tools[nTool];
627     TOOLTIPS_CalcTipSize (infoPtr, &size);
628 
629     TRACE("Show tooltip %d, %s, size %d x %d\n", nTool, debugstr_w(infoPtr->szTipText),
630         size.cx, size.cy);
631 
632     if (track_activate && (toolPtr->uFlags & TTF_TRACK))
633     {
634         rect.left = infoPtr->xTrackPos;
635         rect.top  = infoPtr->yTrackPos;
636         ptfx = rect.left;
637 
638         if (toolPtr->uFlags & TTF_CENTERTIP)
639         {
640             rect.left -= (size.cx / 2);
641             if (!(style & TTS_BALLOON))
642                 rect.top  -= (size.cy / 2);
643         }
644         if (!(infoPtr->bToolBelow = (infoPtr->yTrackPos + size.cy <= GetSystemMetrics(SM_CYSCREEN))))
645             rect.top -= size.cy;
646 
647         if (!(toolPtr->uFlags & TTF_ABSOLUTE))
648         {
649             if (style & TTS_BALLOON)
650                 rect.left -= BALLOON_STEMINDENT;
651             else
652             {
653                 RECT rcTool;
654 
655                 if (toolPtr->uFlags & TTF_IDISHWND)
656                     GetWindowRect ((HWND)toolPtr->uId, &rcTool);
657                 else
658                 {
659                     rcTool = toolPtr->rect;
660                     MapWindowPoints (toolPtr->hwnd, NULL, (LPPOINT)&rcTool, 2);
661                 }
662 
663                 /* smart placement */
664                 if ((rect.left + size.cx > rcTool.left) && (rect.left < rcTool.right) &&
665                     (rect.top + size.cy > rcTool.top) && (rect.top < rcTool.bottom))
666                     rect.left = rcTool.right;
667             }
668         }
669     }
670     else
671     {
672         if (toolPtr->uFlags & TTF_CENTERTIP)
673         {
674 		RECT rc;
675 
676             if (toolPtr->uFlags & TTF_IDISHWND)
677                 GetWindowRect ((HWND)toolPtr->uId, &rc);
678             else {
679                 rc = toolPtr->rect;
680                 MapWindowPoints (toolPtr->hwnd, NULL, (LPPOINT)&rc, 2);
681             }
682             rect.left = (rc.left + rc.right - size.cx) / 2;
683             if (style & TTS_BALLOON)
684             {
685                 ptfx = rc.left + ((rc.right - rc.left) / 2);
686 
687                 /* CENTERTIP ballon tooltips default to below the field
688                  * if they fit on the screen */
689                 if (rc.bottom + size.cy > GetSystemMetrics(SM_CYSCREEN))
690                 {
691                     rect.top = rc.top - size.cy;
692                     infoPtr->bToolBelow = FALSE;
693                 }
694                 else
695                 {
696                     infoPtr->bToolBelow = TRUE;
697                     rect.top = rc.bottom;
698                 }
699                 rect.left = max(0, rect.left - BALLOON_STEMINDENT);
700             }
701             else
702             {
703                 rect.top  = rc.bottom + 2;
704                 infoPtr->bToolBelow = TRUE;
705             }
706         }
707         else
708         {
709             GetCursorPos ((LPPOINT)&rect);
710             if (style & TTS_BALLOON)
711             {
712                 ptfx = rect.left;
713                 if(rect.top - size.cy >= 0)
714                 {
715                     rect.top -= size.cy;
716                     infoPtr->bToolBelow = FALSE;
717                 }
718                 else
719                 {
720                     infoPtr->bToolBelow = TRUE;
721                     rect.top += 20;
722                 }
723                 rect.left = max(0, rect.left - BALLOON_STEMINDENT);
724             }
725             else
726             {
727 		    rect.top += 20;
728 		    infoPtr->bToolBelow = TRUE;
729             }
730         }
731     }
732 
733     TRACE("pos %d - %d\n", rect.left, rect.top);
734 
735     rect.right = rect.left + size.cx;
736     rect.bottom = rect.top + size.cy;
737 
738     /* check position */
739 
740     monitor = MonitorFromRect( &rect, MONITOR_DEFAULTTOPRIMARY );
741     mon_info.cbSize = sizeof(mon_info);
742     GetMonitorInfoW( monitor, &mon_info );
743 
744     if( rect.right > mon_info.rcWork.right ) {
745         rect.left -= rect.right - mon_info.rcWork.right + 2;
746         rect.right = mon_info.rcWork.right - 2;
747     }
748     if (rect.left < mon_info.rcWork.left) rect.left = mon_info.rcWork.left;
749 
750     if( rect.bottom > mon_info.rcWork.bottom ) {
751         RECT rc;
752 
753 	if (toolPtr->uFlags & TTF_IDISHWND)
754 	    GetWindowRect ((HWND)toolPtr->uId, &rc);
755 	else {
756 	    rc = toolPtr->rect;
757 	    MapWindowPoints (toolPtr->hwnd, NULL, (LPPOINT)&rc, 2);
758 	}
759 	rect.bottom = rc.top - 2;
760     	rect.top = rect.bottom - size.cy;
761     }
762 
763     AdjustWindowRectEx (&rect, GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE),
764 			FALSE, GetWindowLongW (infoPtr->hwndSelf, GWL_EXSTYLE));
765 
766     if (style & TTS_BALLOON)
767     {
768         HRGN hRgn;
769         HRGN hrStem;
770         POINT pts[3];
771 
772         ptfx -= rect.left;
773 
774         if(infoPtr->bToolBelow)
775         {
776           pts[0].x = ptfx;
777           pts[0].y = 0;
778           pts[1].x = max(BALLOON_STEMINDENT, ptfx - (BALLOON_STEMWIDTH / 2));
779           pts[1].y = BALLOON_STEMHEIGHT;
780           pts[2].x = pts[1].x + BALLOON_STEMWIDTH;
781           pts[2].y = pts[1].y;
782           if(pts[2].x > (rect.right - rect.left) - BALLOON_STEMINDENT)
783           {
784             pts[2].x = (rect.right - rect.left) - BALLOON_STEMINDENT;
785             pts[1].x = pts[2].x - BALLOON_STEMWIDTH;
786           }
787         }
788         else
789         {
790           pts[0].x = max(BALLOON_STEMINDENT, ptfx - (BALLOON_STEMWIDTH / 2));
791           pts[0].y = (rect.bottom - rect.top) - BALLOON_STEMHEIGHT;
792           pts[1].x = pts[0].x + BALLOON_STEMWIDTH;
793           pts[1].y = pts[0].y;
794           pts[2].x = ptfx;
795           pts[2].y = (rect.bottom - rect.top);
796           if(pts[1].x > (rect.right - rect.left) - BALLOON_STEMINDENT)
797           {
798             pts[1].x = (rect.right - rect.left) - BALLOON_STEMINDENT;
799             pts[0].x = pts[1].x - BALLOON_STEMWIDTH;
800           }
801         }
802 
803         hrStem = CreatePolygonRgn(pts, ARRAY_SIZE(pts), ALTERNATE);
804 
805         hRgn = CreateRoundRectRgn(0,
806                                   (infoPtr->bToolBelow ? BALLOON_STEMHEIGHT : 0),
807                                   rect.right - rect.left,
808                                   (infoPtr->bToolBelow ? rect.bottom - rect.top : rect.bottom - rect.top - BALLOON_STEMHEIGHT),
809                                   BALLOON_ROUNDEDNESS, BALLOON_ROUNDEDNESS);
810 
811         CombineRgn(hRgn, hRgn, hrStem, RGN_OR);
812         DeleteObject(hrStem);
813 
814         SetWindowRgn(infoPtr->hwndSelf, hRgn, FALSE);
815         /* we don't free the region handle as the system deletes it when
816          * it is no longer needed */
817     }
818 
819     SetWindowPos (infoPtr->hwndSelf, NULL, rect.left, rect.top,
820         rect.right - rect.left, rect.bottom - rect.top, SWP_NOZORDER | SWP_NOACTIVATE);
821 
822     hdr.hwndFrom = infoPtr->hwndSelf;
823     hdr.idFrom = toolPtr->uId;
824     hdr.code = TTN_SHOW;
825     SendMessageW (toolPtr->hwnd, WM_NOTIFY, toolPtr->uId, (LPARAM)&hdr);
826 
827     SetWindowPos (infoPtr->hwndSelf, HWND_TOPMOST, 0, 0, 0, 0,
828         SWP_NOSIZE | SWP_NOMOVE | SWP_SHOWWINDOW | SWP_NOACTIVATE);
829 
830     /* repaint the tooltip */
831     InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
832     UpdateWindow(infoPtr->hwndSelf);
833 
834     if (!track_activate)
835     {
836         SetTimer (infoPtr->hwndSelf, ID_TIMERPOP, infoPtr->nAutoPopTime, 0);
837         TRACE("timer 2 started\n");
838         SetTimer (infoPtr->hwndSelf, ID_TIMERLEAVE, infoPtr->nReshowTime, 0);
839         TRACE("timer 3 started\n");
840     }
841 }
842 
843 
844 static void
845 TOOLTIPS_Hide (TOOLTIPS_INFO *infoPtr)
846 {
847     TTTOOL_INFO *toolPtr;
848     NMHDR hdr;
849 
850     TRACE("Hide tooltip %d, %p.\n", infoPtr->nCurrentTool, infoPtr->hwndSelf);
851 
852     if (infoPtr->nCurrentTool == -1)
853 	return;
854 
855     toolPtr = &infoPtr->tools[infoPtr->nCurrentTool];
856     KillTimer (infoPtr->hwndSelf, ID_TIMERPOP);
857 
858     hdr.hwndFrom = infoPtr->hwndSelf;
859     hdr.idFrom = toolPtr->uId;
860     hdr.code = TTN_POP;
861     SendMessageW (toolPtr->hwnd, WM_NOTIFY, toolPtr->uId, (LPARAM)&hdr);
862 
863     infoPtr->nCurrentTool = -1;
864 
865     SetWindowPos (infoPtr->hwndSelf, HWND_TOP, 0, 0, 0, 0,
866 		    SWP_NOZORDER | SWP_HIDEWINDOW | SWP_NOACTIVATE);
867 }
868 
869 
870 static void
871 TOOLTIPS_TrackShow (TOOLTIPS_INFO *infoPtr)
872 {
873     TOOLTIPS_Show(infoPtr, TRUE);
874 }
875 
876 
877 static void
878 TOOLTIPS_TrackHide (const TOOLTIPS_INFO *infoPtr)
879 {
880     TTTOOL_INFO *toolPtr;
881     NMHDR hdr;
882 
883     TRACE("hide tracking tooltip %d\n", infoPtr->nTrackTool);
884 
885     if (infoPtr->nTrackTool == -1)
886 	return;
887 
888     toolPtr = &infoPtr->tools[infoPtr->nTrackTool];
889 
890     hdr.hwndFrom = infoPtr->hwndSelf;
891     hdr.idFrom = toolPtr->uId;
892     hdr.code = TTN_POP;
893     SendMessageW (toolPtr->hwnd, WM_NOTIFY, toolPtr->uId, (LPARAM)&hdr);
894 
895     SetWindowPos (infoPtr->hwndSelf, HWND_TOP, 0, 0, 0, 0,
896 		    SWP_NOZORDER | SWP_HIDEWINDOW | SWP_NOACTIVATE);
897 }
898 
899 /* Structure layout is the same for TTTOOLINFOW and TTTOOLINFOA,
900    this helper is used in both cases. */
901 static INT
902 TOOLTIPS_GetToolFromInfoT (const TOOLTIPS_INFO *infoPtr, const TTTOOLINFOW *lpToolInfo)
903 {
904     TTTOOL_INFO *toolPtr;
905     UINT nTool;
906 
907     for (nTool = 0; nTool < infoPtr->uNumTools; nTool++) {
908 	toolPtr = &infoPtr->tools[nTool];
909 
910 	if (!(toolPtr->uFlags & TTF_IDISHWND) &&
911 	    (lpToolInfo->hwnd == toolPtr->hwnd) &&
912 	    (lpToolInfo->uId == toolPtr->uId))
913 	    return nTool;
914     }
915 
916     for (nTool = 0; nTool < infoPtr->uNumTools; nTool++) {
917 	toolPtr = &infoPtr->tools[nTool];
918 
919 	if ((toolPtr->uFlags & TTF_IDISHWND) &&
920 	    (lpToolInfo->uId == toolPtr->uId))
921 	    return nTool;
922     }
923 
924     return -1;
925 }
926 
927 
928 static INT
929 TOOLTIPS_GetToolFromPoint (const TOOLTIPS_INFO *infoPtr, HWND hwnd, const POINT *lpPt)
930 {
931     TTTOOL_INFO *toolPtr;
932     UINT nTool;
933 
934     for (nTool = 0; nTool < infoPtr->uNumTools; nTool++) {
935 	toolPtr = &infoPtr->tools[nTool];
936 
937 	if (!(toolPtr->uFlags & TTF_IDISHWND)) {
938 	    if (hwnd != toolPtr->hwnd)
939 		continue;
940 	    if (!PtInRect (&toolPtr->rect, *lpPt))
941 		continue;
942 	    return nTool;
943 	}
944     }
945 
946     for (nTool = 0; nTool < infoPtr->uNumTools; nTool++) {
947 	toolPtr = &infoPtr->tools[nTool];
948 
949 	if (toolPtr->uFlags & TTF_IDISHWND) {
950 	    if ((HWND)toolPtr->uId == hwnd)
951 		return nTool;
952 	}
953     }
954 
955     return -1;
956 }
957 
958 static inline void
959 TOOLTIPS_CopyInfoT (const TOOLTIPS_INFO *infoPtr, INT index, TTTOOLINFOW *ti, BOOL isW)
960 {
961     const TTTOOL_INFO *toolPtr = &infoPtr->tools[index];
962 
963     ti->uFlags = toolPtr->uFlags;
964     ti->hwnd   = toolPtr->hwnd;
965     ti->uId    = toolPtr->uId;
966     ti->rect   = toolPtr->rect;
967     ti->hinst  = toolPtr->hinst;
968 
969     if (ti->lpszText) {
970         if (toolPtr->lpszText == NULL ||
971             IS_INTRESOURCE(toolPtr->lpszText) ||
972             toolPtr->lpszText == LPSTR_TEXTCALLBACKW)
973             ti->lpszText = toolPtr->lpszText;
974         else if (isW)
975             strcpyW (ti->lpszText, toolPtr->lpszText);
976         else
977             /* ANSI version, the buffer is maximum 80 bytes without null. */
978             WideCharToMultiByte(CP_ACP, 0, toolPtr->lpszText, -1,
979                                 (LPSTR)ti->lpszText, MAX_TEXT_SIZE_A, NULL, NULL);
980     }
981 
982     if (ti->cbSize >= TTTOOLINFOW_V2_SIZE)
983         ti->lParam = toolPtr->lParam;
984 
985     /* lpReserved is intentionally not set. */
986 }
987 
988 static BOOL
989 TOOLTIPS_IsWindowActive (HWND hwnd)
990 {
991     HWND hwndActive = GetActiveWindow ();
992     if (!hwndActive)
993 	return FALSE;
994     if (hwndActive == hwnd)
995 	return TRUE;
996     return IsChild (hwndActive, hwnd);
997 }
998 
999 
1000 static INT
1001 TOOLTIPS_CheckTool (const TOOLTIPS_INFO *infoPtr, BOOL bShowTest)
1002 {
1003     POINT pt;
1004     HWND hwndTool;
1005     INT nTool;
1006 
1007     GetCursorPos (&pt);
1008     hwndTool = (HWND)SendMessageW (infoPtr->hwndSelf, TTM_WINDOWFROMPOINT, 0, (LPARAM)&pt);
1009     if (hwndTool == 0)
1010 	return -1;
1011 
1012     ScreenToClient (hwndTool, &pt);
1013     nTool = TOOLTIPS_GetToolFromPoint (infoPtr, hwndTool, &pt);
1014     if (nTool == -1)
1015 	return -1;
1016 
1017     if (!(GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE) & TTS_ALWAYSTIP) && bShowTest)
1018     {
1019         TTTOOL_INFO *ti = &infoPtr->tools[nTool];
1020         HWND hwnd = (ti->uFlags & TTF_IDISHWND) ? (HWND)ti->uId : ti->hwnd;
1021 
1022         if (!TOOLTIPS_IsWindowActive(hwnd))
1023         {
1024             TRACE("not active: hwnd %p, parent %p, active %p\n",
1025                   hwnd, GetParent(hwnd), GetActiveWindow());
1026             return -1;
1027         }
1028     }
1029 
1030     TRACE("tool %d\n", nTool);
1031 
1032     return nTool;
1033 }
1034 
1035 
1036 static LRESULT
1037 TOOLTIPS_Activate (TOOLTIPS_INFO *infoPtr, BOOL activate)
1038 {
1039     infoPtr->bActive = activate;
1040 
1041     TRACE("activate %d\n", activate);
1042 
1043     if (!(infoPtr->bActive) && (infoPtr->nCurrentTool != -1))
1044 	TOOLTIPS_Hide (infoPtr);
1045 
1046     return 0;
1047 }
1048 
1049 
1050 static LRESULT
1051 TOOLTIPS_AddToolT (TOOLTIPS_INFO *infoPtr, const TTTOOLINFOW *ti, BOOL isW)
1052 {
1053     TTTOOL_INFO *toolPtr;
1054     INT nResult;
1055 
1056     if (!ti) return FALSE;
1057 
1058     TRACE("add tool (%p) %p %ld%s\n", infoPtr->hwndSelf, ti->hwnd, ti->uId,
1059         (ti->uFlags & TTF_IDISHWND) ? " TTF_IDISHWND" : "");
1060 
1061     if (ti->cbSize > TTTOOLINFOW_V3_SIZE && isW)
1062         return FALSE;
1063 
1064     if (infoPtr->uNumTools == 0) {
1065 	infoPtr->tools = Alloc (sizeof(TTTOOL_INFO));
1066 	toolPtr = infoPtr->tools;
1067     }
1068     else {
1069 	TTTOOL_INFO *oldTools = infoPtr->tools;
1070 	infoPtr->tools =
1071 	    Alloc (sizeof(TTTOOL_INFO) * (infoPtr->uNumTools + 1));
1072 	memcpy (infoPtr->tools, oldTools,
1073 		infoPtr->uNumTools * sizeof(TTTOOL_INFO));
1074 	Free (oldTools);
1075 	toolPtr = &infoPtr->tools[infoPtr->uNumTools];
1076     }
1077 
1078     infoPtr->uNumTools++;
1079 
1080     /* copy tool data */
1081     toolPtr->uFlags         = ti->uFlags;
1082     toolPtr->uInternalFlags = (ti->uFlags & (TTF_SUBCLASS | TTF_IDISHWND));
1083     toolPtr->hwnd           = ti->hwnd;
1084     toolPtr->uId            = ti->uId;
1085     toolPtr->rect           = ti->rect;
1086     toolPtr->hinst          = ti->hinst;
1087 
1088     if (ti->cbSize >= TTTOOLINFOW_V1_SIZE) {
1089         if (IS_INTRESOURCE(ti->lpszText)) {
1090             TRACE("add string id %x\n", LOWORD(ti->lpszText));
1091             toolPtr->lpszText = ti->lpszText;
1092         }
1093         else if (ti->lpszText) {
1094             if (TOOLTIPS_IsCallbackString(ti->lpszText, isW)) {
1095                 TRACE("add CALLBACK\n");
1096                 toolPtr->lpszText = LPSTR_TEXTCALLBACKW;
1097             }
1098             else if (isW) {
1099                 INT len = lstrlenW (ti->lpszText);
1100                 TRACE("add text %s\n", debugstr_w(ti->lpszText));
1101                 toolPtr->lpszText =	Alloc ((len + 1)*sizeof(WCHAR));
1102                 strcpyW (toolPtr->lpszText, ti->lpszText);
1103             }
1104             else {
1105                 INT len = MultiByteToWideChar(CP_ACP, 0, (LPSTR)ti->lpszText, -1, NULL, 0);
1106                 TRACE("add text \"%s\"\n", debugstr_a((char *)ti->lpszText));
1107                 toolPtr->lpszText =	Alloc (len * sizeof(WCHAR));
1108                 MultiByteToWideChar(CP_ACP, 0, (LPSTR)ti->lpszText, -1, toolPtr->lpszText, len);
1109             }
1110         }
1111     }
1112 
1113     if (ti->cbSize >= TTTOOLINFOW_V2_SIZE)
1114 	toolPtr->lParam = ti->lParam;
1115 
1116     /* install subclassing hook */
1117     if (toolPtr->uInternalFlags & TTF_SUBCLASS) {
1118 	if (toolPtr->uInternalFlags & TTF_IDISHWND) {
1119 	    SetWindowSubclass((HWND)toolPtr->uId, TOOLTIPS_SubclassProc, 1,
1120 			      (DWORD_PTR)infoPtr->hwndSelf);
1121 	}
1122 	else {
1123 	    SetWindowSubclass(toolPtr->hwnd, TOOLTIPS_SubclassProc, 1,
1124 			      (DWORD_PTR)infoPtr->hwndSelf);
1125 	}
1126 	TRACE("subclassing installed\n");
1127     }
1128 
1129     nResult = SendMessageW (toolPtr->hwnd, WM_NOTIFYFORMAT,
1130                             (WPARAM)infoPtr->hwndSelf, NF_QUERY);
1131     if (nResult == NFR_ANSI) {
1132         toolPtr->bNotifyUnicode = FALSE;
1133 	TRACE(" -- WM_NOTIFYFORMAT returns: NFR_ANSI\n");
1134     } else if (nResult == NFR_UNICODE) {
1135         toolPtr->bNotifyUnicode = TRUE;
1136 	TRACE(" -- WM_NOTIFYFORMAT returns: NFR_UNICODE\n");
1137     } else {
1138         TRACE (" -- WM_NOTIFYFORMAT returns: %d\n", nResult);
1139     }
1140 
1141     return TRUE;
1142 }
1143 
1144 static void TOOLTIPS_ResetSubclass (const TTTOOL_INFO *toolPtr)
1145 {
1146     /* Reset subclassing data. */
1147     if (toolPtr->uInternalFlags & TTF_SUBCLASS)
1148         SetWindowSubclass(toolPtr->uInternalFlags & TTF_IDISHWND ? (HWND)toolPtr->uId : toolPtr->hwnd,
1149             TOOLTIPS_SubclassProc, 1, 0);
1150 }
1151 
1152 static LRESULT
1153 TOOLTIPS_DelToolT (TOOLTIPS_INFO *infoPtr, const TTTOOLINFOW *ti, BOOL isW)
1154 {
1155     TTTOOL_INFO *toolPtr;
1156     INT nTool;
1157 
1158     if (!ti) return 0;
1159     if (isW && ti->cbSize > TTTOOLINFOW_V2_SIZE &&
1160                ti->cbSize != TTTOOLINFOW_V3_SIZE)
1161 	return 0;
1162     if (infoPtr->uNumTools == 0)
1163 	return 0;
1164 
1165     nTool = TOOLTIPS_GetToolFromInfoT (infoPtr, ti);
1166 
1167     TRACE("tool %d\n", nTool);
1168 
1169     if (nTool == -1)
1170         return 0;
1171 
1172     /* make sure the tooltip has disappeared before deleting it */
1173     TOOLTIPS_Hide(infoPtr);
1174 
1175     /* delete text string */
1176     toolPtr = &infoPtr->tools[nTool];
1177     if (toolPtr->lpszText) {
1178 	if ( (toolPtr->lpszText != LPSTR_TEXTCALLBACKW) &&
1179 	     !IS_INTRESOURCE(toolPtr->lpszText) )
1180 	    Free (toolPtr->lpszText);
1181     }
1182 
1183     TOOLTIPS_ResetSubclass (toolPtr);
1184 
1185     /* delete tool from tool list */
1186     if (infoPtr->uNumTools == 1) {
1187 	Free (infoPtr->tools);
1188 	infoPtr->tools = NULL;
1189     }
1190     else {
1191 	TTTOOL_INFO *oldTools = infoPtr->tools;
1192 	infoPtr->tools =
1193 	    Alloc (sizeof(TTTOOL_INFO) * (infoPtr->uNumTools - 1));
1194 
1195 	if (nTool > 0)
1196 	    memcpy (&infoPtr->tools[0], &oldTools[0],
1197 		    nTool * sizeof(TTTOOL_INFO));
1198 
1199 	if (nTool < infoPtr->uNumTools - 1)
1200 	    memcpy (&infoPtr->tools[nTool], &oldTools[nTool + 1],
1201 		    (infoPtr->uNumTools - nTool - 1) * sizeof(TTTOOL_INFO));
1202 
1203 	Free (oldTools);
1204     }
1205 
1206     /* update any indices affected by delete */
1207 
1208     /* destroying tool that mouse was on on last relayed mouse move */
1209     if (infoPtr->nTool == nTool)
1210         /* -1 means no current tool (0 means first tool) */
1211         infoPtr->nTool = -1;
1212     else if (infoPtr->nTool > nTool)
1213         infoPtr->nTool--;
1214 
1215     if (infoPtr->nTrackTool == nTool)
1216         /* -1 means no current tool (0 means first tool) */
1217         infoPtr->nTrackTool = -1;
1218     else if (infoPtr->nTrackTool > nTool)
1219         infoPtr->nTrackTool--;
1220 
1221     if (infoPtr->nCurrentTool == nTool)
1222         /* -1 means no current tool (0 means first tool) */
1223         infoPtr->nCurrentTool = -1;
1224     else if (infoPtr->nCurrentTool > nTool)
1225         infoPtr->nCurrentTool--;
1226 
1227     infoPtr->uNumTools--;
1228 
1229     return 0;
1230 }
1231 
1232 static LRESULT
1233 TOOLTIPS_EnumToolsT (const TOOLTIPS_INFO *infoPtr, UINT uIndex, TTTOOLINFOW *ti,
1234                      BOOL isW)
1235 {
1236     if (!ti || ti->cbSize < TTTOOLINFOW_V1_SIZE)
1237 	return FALSE;
1238     if (uIndex >= infoPtr->uNumTools)
1239 	return FALSE;
1240 
1241     TRACE("index=%u\n", uIndex);
1242 
1243     TOOLTIPS_CopyInfoT (infoPtr, uIndex, ti, isW);
1244 
1245     return TRUE;
1246 }
1247 
1248 static LRESULT
1249 TOOLTIPS_GetBubbleSize (const TOOLTIPS_INFO *infoPtr, const TTTOOLINFOW *lpToolInfo)
1250 {
1251     INT nTool;
1252     SIZE size;
1253 
1254     if (lpToolInfo == NULL)
1255 	return FALSE;
1256     if (lpToolInfo->cbSize < TTTOOLINFOW_V1_SIZE)
1257 	return FALSE;
1258 
1259     nTool = TOOLTIPS_GetToolFromInfoT (infoPtr, lpToolInfo);
1260     if (nTool == -1) return 0;
1261 
1262     TRACE("tool %d\n", nTool);
1263 
1264     TOOLTIPS_CalcTipSize (infoPtr, &size);
1265     TRACE("size %d x %d\n", size.cx, size.cy);
1266 
1267     return MAKELRESULT(size.cx, size.cy);
1268 }
1269 
1270 static LRESULT
1271 TOOLTIPS_GetCurrentToolT (const TOOLTIPS_INFO *infoPtr, TTTOOLINFOW *ti, BOOL isW)
1272 {
1273     if (ti) {
1274         if (ti->cbSize < TTTOOLINFOW_V1_SIZE)
1275             return FALSE;
1276 
1277         if (infoPtr->nCurrentTool != -1)
1278             TOOLTIPS_CopyInfoT (infoPtr, infoPtr->nCurrentTool, ti, isW);
1279     }
1280 
1281     return infoPtr->nCurrentTool != -1;
1282 }
1283 
1284 
1285 static LRESULT
1286 TOOLTIPS_GetDelayTime (const TOOLTIPS_INFO *infoPtr, DWORD duration)
1287 {
1288     switch (duration) {
1289     case TTDT_RESHOW:
1290         return infoPtr->nReshowTime;
1291 
1292     case TTDT_AUTOPOP:
1293         return infoPtr->nAutoPopTime;
1294 
1295     case TTDT_INITIAL:
1296     case TTDT_AUTOMATIC: /* Apparently TTDT_AUTOMATIC returns TTDT_INITIAL */
1297         return infoPtr->nInitialTime;
1298 
1299     default:
1300         WARN("Invalid duration flag %x\n", duration);
1301 	break;
1302     }
1303 
1304     return -1;
1305 }
1306 
1307 
1308 static LRESULT
1309 TOOLTIPS_GetMargin (const TOOLTIPS_INFO *infoPtr, RECT *rect)
1310 {
1311     if (rect)
1312         *rect = infoPtr->rcMargin;
1313 
1314     return 0;
1315 }
1316 
1317 
1318 static inline LRESULT
1319 TOOLTIPS_GetMaxTipWidth (const TOOLTIPS_INFO *infoPtr)
1320 {
1321     return infoPtr->nMaxTipWidth;
1322 }
1323 
1324 
1325 static LRESULT
1326 TOOLTIPS_GetTextT (const TOOLTIPS_INFO *infoPtr, TTTOOLINFOW *ti, BOOL isW)
1327 {
1328     INT nTool;
1329 
1330     if (!ti) return 0;
1331     if (ti->cbSize < TTTOOLINFOW_V1_SIZE)
1332 	return 0;
1333 
1334     nTool = TOOLTIPS_GetToolFromInfoT (infoPtr, ti);
1335     if (nTool == -1) return 0;
1336 
1337     if (infoPtr->tools[nTool].lpszText == NULL)
1338 	return 0;
1339 
1340     if (isW) {
1341         ti->lpszText[0] = '\0';
1342         TOOLTIPS_GetTipText(infoPtr, nTool, ti->lpszText);
1343     }
1344     else {
1345         WCHAR buffer[INFOTIPSIZE];
1346 
1347         /* NB this API is broken, there is no way for the app to determine
1348            what size buffer it requires nor a way to specify how long the
1349            one it supplies is.  According to the test result, it's up to
1350            80 bytes by the ANSI version. */
1351 
1352         buffer[0] = '\0';
1353         TOOLTIPS_GetTipText(infoPtr, nTool, buffer);
1354         WideCharToMultiByte(CP_ACP, 0, buffer, -1, (LPSTR)ti->lpszText,
1355                                                    MAX_TEXT_SIZE_A, NULL, NULL);
1356     }
1357 
1358     return 0;
1359 }
1360 
1361 
1362 static inline LRESULT
1363 TOOLTIPS_GetTipBkColor (const TOOLTIPS_INFO *infoPtr)
1364 {
1365     return infoPtr->clrBk;
1366 }
1367 
1368 
1369 static inline LRESULT
1370 TOOLTIPS_GetTipTextColor (const TOOLTIPS_INFO *infoPtr)
1371 {
1372     return infoPtr->clrText;
1373 }
1374 
1375 
1376 static inline LRESULT
1377 TOOLTIPS_GetToolCount (const TOOLTIPS_INFO *infoPtr)
1378 {
1379     return infoPtr->uNumTools;
1380 }
1381 
1382 
1383 static LRESULT
1384 TOOLTIPS_GetToolInfoT (const TOOLTIPS_INFO *infoPtr, TTTOOLINFOW *ti, BOOL isW)
1385 {
1386     INT nTool;
1387     HWND hwnd;
1388 
1389     if (!ti) return FALSE;
1390     if (ti->cbSize < TTTOOLINFOW_V1_SIZE)
1391 	return FALSE;
1392     if (infoPtr->uNumTools == 0)
1393 	return FALSE;
1394 
1395     nTool = TOOLTIPS_GetToolFromInfoT (infoPtr, ti);
1396     if (nTool == -1)
1397 	return FALSE;
1398 
1399     TRACE("tool %d\n", nTool);
1400 
1401     hwnd = ti->hwnd;
1402     TOOLTIPS_CopyInfoT (infoPtr, nTool, ti, isW);
1403     ti->hwnd = hwnd;
1404 
1405     return TRUE;
1406 }
1407 
1408 
1409 static LRESULT
1410 TOOLTIPS_HitTestT (const TOOLTIPS_INFO *infoPtr, LPTTHITTESTINFOW lptthit,
1411                    BOOL isW)
1412 {
1413     INT nTool;
1414 
1415     if (lptthit == 0)
1416 	return FALSE;
1417 
1418     nTool = TOOLTIPS_GetToolFromPoint (infoPtr, lptthit->hwnd, &lptthit->pt);
1419     if (nTool == -1)
1420 	return FALSE;
1421 
1422     TRACE("tool %d\n", nTool);
1423 
1424     /* copy tool data */
1425     if (lptthit->ti.cbSize >= TTTOOLINFOW_V1_SIZE)
1426         TOOLTIPS_CopyInfoT (infoPtr, nTool, &lptthit->ti, isW);
1427 
1428     return TRUE;
1429 }
1430 
1431 
1432 static LRESULT
1433 TOOLTIPS_NewToolRectT (TOOLTIPS_INFO *infoPtr, const TTTOOLINFOW *ti)
1434 {
1435     INT nTool;
1436 
1437     if (!ti) return 0;
1438     if (ti->cbSize < TTTOOLINFOW_V1_SIZE)
1439 	return FALSE;
1440 
1441     nTool = TOOLTIPS_GetToolFromInfoT (infoPtr, ti);
1442 
1443     TRACE("nTool = %d, rect = %s\n", nTool, wine_dbgstr_rect(&ti->rect));
1444 
1445     if (nTool == -1) return 0;
1446 
1447     infoPtr->tools[nTool].rect = ti->rect;
1448 
1449     return 0;
1450 }
1451 
1452 
1453 static inline LRESULT
1454 TOOLTIPS_Pop (TOOLTIPS_INFO *infoPtr)
1455 {
1456     TOOLTIPS_Hide (infoPtr);
1457 
1458     return 0;
1459 }
1460 
1461 
1462 static LRESULT
1463 TOOLTIPS_RelayEvent (TOOLTIPS_INFO *infoPtr, LPMSG lpMsg)
1464 {
1465     POINT pt;
1466     INT nOldTool;
1467 
1468     if (!lpMsg) {
1469 	ERR("lpMsg == NULL\n");
1470 	return 0;
1471     }
1472 
1473     switch (lpMsg->message) {
1474 	case WM_LBUTTONDOWN:
1475 	case WM_LBUTTONUP:
1476 	case WM_MBUTTONDOWN:
1477 	case WM_MBUTTONUP:
1478 	case WM_RBUTTONDOWN:
1479 	case WM_RBUTTONUP:
1480 	    TOOLTIPS_Hide (infoPtr);
1481 	    break;
1482 
1483 	case WM_MOUSEMOVE:
1484 	    pt.x = (short)LOWORD(lpMsg->lParam);
1485 	    pt.y = (short)HIWORD(lpMsg->lParam);
1486 	    nOldTool = infoPtr->nTool;
1487 	    infoPtr->nTool = TOOLTIPS_GetToolFromPoint(infoPtr, lpMsg->hwnd,
1488 						       &pt);
1489 	    TRACE("tool (%p) %d %d %d\n", infoPtr->hwndSelf, nOldTool,
1490 		  infoPtr->nTool, infoPtr->nCurrentTool);
1491             TRACE("WM_MOUSEMOVE (%p %s)\n", infoPtr->hwndSelf, wine_dbgstr_point(&pt));
1492 
1493 	    if (infoPtr->nTool != nOldTool) {
1494 	        if(infoPtr->nTool == -1) { /* Moved out of all tools */
1495 		    TOOLTIPS_Hide(infoPtr);
1496 		    KillTimer(infoPtr->hwndSelf, ID_TIMERLEAVE);
1497 		} else if (nOldTool == -1) { /* Moved from outside */
1498 		    if(infoPtr->bActive) {
1499 		        SetTimer(infoPtr->hwndSelf, ID_TIMERSHOW, infoPtr->nInitialTime, 0);
1500                         TRACE("timer 1 started\n");
1501 		    }
1502 		} else { /* Moved from one to another */
1503 		    TOOLTIPS_Hide (infoPtr);
1504 		    KillTimer(infoPtr->hwndSelf, ID_TIMERLEAVE);
1505 		    if(infoPtr->bActive) {
1506 		        SetTimer (infoPtr->hwndSelf, ID_TIMERSHOW, infoPtr->nReshowTime, 0);
1507                         TRACE("timer 1 started\n");
1508 		    }
1509 		}
1510 	    } else if(infoPtr->nCurrentTool != -1) { /* restart autopop */
1511 	        KillTimer(infoPtr->hwndSelf, ID_TIMERPOP);
1512 		SetTimer(infoPtr->hwndSelf, ID_TIMERPOP, infoPtr->nAutoPopTime, 0);
1513 		TRACE("timer 2 restarted\n");
1514 	    } else if(infoPtr->nTool != -1 && infoPtr->bActive) {
1515                 /* previous show attempt didn't result in tooltip so try again */
1516 		SetTimer(infoPtr->hwndSelf, ID_TIMERSHOW, infoPtr->nInitialTime, 0);
1517                 TRACE("timer 1 started\n");
1518 	    }
1519 	    break;
1520     }
1521 
1522     return 0;
1523 }
1524 
1525 
1526 static LRESULT
1527 TOOLTIPS_SetDelayTime (TOOLTIPS_INFO *infoPtr, DWORD duration, INT nTime)
1528 {
1529     switch (duration) {
1530     case TTDT_AUTOMATIC:
1531         if (nTime <= 0)
1532 	    nTime = GetDoubleClickTime();
1533 	infoPtr->nReshowTime    = nTime / 5;
1534 	infoPtr->nAutoPopTime   = nTime * 10;
1535 	infoPtr->nInitialTime   = nTime;
1536 	break;
1537 
1538     case TTDT_RESHOW:
1539         if(nTime < 0)
1540 	    nTime = GetDoubleClickTime() / 5;
1541 	infoPtr->nReshowTime = nTime;
1542 	break;
1543 
1544     case TTDT_AUTOPOP:
1545         if(nTime < 0)
1546 	    nTime = GetDoubleClickTime() * 10;
1547 	infoPtr->nAutoPopTime = nTime;
1548 	break;
1549 
1550     case TTDT_INITIAL:
1551         if(nTime < 0)
1552 	    nTime = GetDoubleClickTime();
1553 	infoPtr->nInitialTime = nTime;
1554 	    break;
1555 
1556     default:
1557         WARN("Invalid duration flag %x\n", duration);
1558 	break;
1559     }
1560 
1561     return 0;
1562 }
1563 
1564 
1565 static LRESULT
1566 TOOLTIPS_SetMargin (TOOLTIPS_INFO *infoPtr, const RECT *rect)
1567 {
1568     if (rect)
1569         infoPtr->rcMargin = *rect;
1570 
1571     return 0;
1572 }
1573 
1574 
1575 static inline LRESULT
1576 TOOLTIPS_SetMaxTipWidth (TOOLTIPS_INFO *infoPtr, INT MaxWidth)
1577 {
1578     INT nTemp = infoPtr->nMaxTipWidth;
1579 
1580     infoPtr->nMaxTipWidth = MaxWidth;
1581 
1582     return nTemp;
1583 }
1584 
1585 
1586 static inline LRESULT
1587 TOOLTIPS_SetTipBkColor (TOOLTIPS_INFO *infoPtr, COLORREF clrBk)
1588 {
1589     infoPtr->clrBk = clrBk;
1590 
1591     return 0;
1592 }
1593 
1594 
1595 static inline LRESULT
1596 TOOLTIPS_SetTipTextColor (TOOLTIPS_INFO *infoPtr, COLORREF clrText)
1597 {
1598     infoPtr->clrText = clrText;
1599 
1600     return 0;
1601 }
1602 
1603 
1604 static LRESULT
1605 TOOLTIPS_SetTitleT (TOOLTIPS_INFO *infoPtr, UINT_PTR uTitleIcon, LPCWSTR pszTitle,
1606                     BOOL isW)
1607 {
1608     UINT size;
1609 
1610     TRACE("hwnd = %p, title = %s, icon = %p\n", infoPtr->hwndSelf, debugstr_w(pszTitle),
1611         (void*)uTitleIcon);
1612 
1613     Free(infoPtr->pszTitle);
1614 
1615     if (pszTitle)
1616     {
1617         if (isW)
1618         {
1619             size = (strlenW(pszTitle)+1)*sizeof(WCHAR);
1620             infoPtr->pszTitle = Alloc(size);
1621             if (!infoPtr->pszTitle)
1622                 return FALSE;
1623             memcpy(infoPtr->pszTitle, pszTitle, size);
1624         }
1625         else
1626         {
1627             size = sizeof(WCHAR)*MultiByteToWideChar(CP_ACP, 0, (LPCSTR)pszTitle, -1, NULL, 0);
1628             infoPtr->pszTitle = Alloc(size);
1629             if (!infoPtr->pszTitle)
1630                 return FALSE;
1631             MultiByteToWideChar(CP_ACP, 0, (LPCSTR)pszTitle, -1, infoPtr->pszTitle, size/sizeof(WCHAR));
1632         }
1633     }
1634     else
1635         infoPtr->pszTitle = NULL;
1636 
1637     if (uTitleIcon <= TTI_ERROR)
1638         infoPtr->hTitleIcon = hTooltipIcons[uTitleIcon];
1639     else
1640         infoPtr->hTitleIcon = CopyIcon((HICON)uTitleIcon);
1641 
1642     TRACE("icon = %p\n", infoPtr->hTitleIcon);
1643 
1644     return TRUE;
1645 }
1646 
1647 
1648 static LRESULT
1649 TOOLTIPS_SetToolInfoT (TOOLTIPS_INFO *infoPtr, const TTTOOLINFOW *ti, BOOL isW)
1650 {
1651     TTTOOL_INFO *toolPtr;
1652     INT nTool;
1653 
1654     if (!ti) return 0;
1655     if (ti->cbSize < TTTOOLINFOW_V1_SIZE)
1656 	return 0;
1657 
1658     nTool = TOOLTIPS_GetToolFromInfoT (infoPtr, ti);
1659     if (nTool == -1) return 0;
1660 
1661     TRACE("tool %d\n", nTool);
1662 
1663     toolPtr = &infoPtr->tools[nTool];
1664 
1665     /* copy tool data */
1666     toolPtr->uFlags = ti->uFlags;
1667     toolPtr->hwnd   = ti->hwnd;
1668     toolPtr->uId    = ti->uId;
1669     toolPtr->rect   = ti->rect;
1670     toolPtr->hinst  = ti->hinst;
1671 
1672     if (IS_INTRESOURCE(ti->lpszText)) {
1673 	TRACE("set string id %x\n", LOWORD(ti->lpszText));
1674 	toolPtr->lpszText = ti->lpszText;
1675     }
1676     else {
1677 	if (TOOLTIPS_IsCallbackString(ti->lpszText, isW))
1678 	    toolPtr->lpszText = LPSTR_TEXTCALLBACKW;
1679 	else {
1680 	    if ( (toolPtr->lpszText) &&
1681 		 !IS_INTRESOURCE(toolPtr->lpszText) ) {
1682 		if( toolPtr->lpszText != LPSTR_TEXTCALLBACKW)
1683                     Free (toolPtr->lpszText);
1684 		toolPtr->lpszText = NULL;
1685 	    }
1686 	    if (ti->lpszText) {
1687 		if (isW) {
1688 		    INT len = lstrlenW (ti->lpszText);
1689 		    toolPtr->lpszText = Alloc ((len+1)*sizeof(WCHAR));
1690 		    strcpyW (toolPtr->lpszText, ti->lpszText);
1691 		}
1692 		else {
1693 		    INT len = MultiByteToWideChar(CP_ACP, 0, (LPSTR)ti->lpszText,
1694 					      -1, NULL, 0);
1695 		    toolPtr->lpszText = Alloc (len * sizeof(WCHAR));
1696 		    MultiByteToWideChar(CP_ACP, 0, (LPSTR)ti->lpszText, -1,
1697 					toolPtr->lpszText, len);
1698 		}
1699 	    }
1700 	}
1701     }
1702 
1703     if (ti->cbSize >= TTTOOLINFOW_V2_SIZE)
1704 	toolPtr->lParam = ti->lParam;
1705 
1706     if (infoPtr->nCurrentTool == nTool)
1707     {
1708         TOOLTIPS_GetTipText (infoPtr, infoPtr->nCurrentTool, infoPtr->szTipText);
1709 
1710         if (infoPtr->szTipText[0] == 0)
1711             TOOLTIPS_Hide(infoPtr);
1712         else
1713             TOOLTIPS_Show (infoPtr, FALSE);
1714     }
1715 
1716     return 0;
1717 }
1718 
1719 
1720 static LRESULT
1721 TOOLTIPS_TrackActivate (TOOLTIPS_INFO *infoPtr, BOOL track_activate, const TTTOOLINFOA *ti)
1722 {
1723     if (track_activate) {
1724 
1725 	if (!ti) return 0;
1726 	if (ti->cbSize < TTTOOLINFOA_V1_SIZE)
1727 	    return FALSE;
1728 
1729 	/* activate */
1730 	infoPtr->nTrackTool = TOOLTIPS_GetToolFromInfoT (infoPtr, (const TTTOOLINFOW*)ti);
1731 	if (infoPtr->nTrackTool != -1) {
1732 	    TRACE("activated\n");
1733 	    infoPtr->bTrackActive = TRUE;
1734 	    TOOLTIPS_TrackShow (infoPtr);
1735 	}
1736     }
1737     else {
1738 	/* deactivate */
1739 	TOOLTIPS_TrackHide (infoPtr);
1740 
1741 	infoPtr->bTrackActive = FALSE;
1742 	infoPtr->nTrackTool = -1;
1743 
1744         TRACE("deactivated\n");
1745     }
1746 
1747     return 0;
1748 }
1749 
1750 
1751 static LRESULT
1752 TOOLTIPS_TrackPosition (TOOLTIPS_INFO *infoPtr, LPARAM coord)
1753 {
1754     infoPtr->xTrackPos = (INT)LOWORD(coord);
1755     infoPtr->yTrackPos = (INT)HIWORD(coord);
1756 
1757     if (infoPtr->bTrackActive) {
1758 	TRACE("[%d %d]\n",
1759 	       infoPtr->xTrackPos, infoPtr->yTrackPos);
1760 
1761 	TOOLTIPS_TrackShow (infoPtr);
1762     }
1763 
1764     return 0;
1765 }
1766 
1767 
1768 static LRESULT
1769 TOOLTIPS_Update (TOOLTIPS_INFO *infoPtr)
1770 {
1771     if (infoPtr->nCurrentTool != -1)
1772 	UpdateWindow (infoPtr->hwndSelf);
1773 
1774     return 0;
1775 }
1776 
1777 
1778 static LRESULT
1779 TOOLTIPS_UpdateTipTextT (TOOLTIPS_INFO *infoPtr, const TTTOOLINFOW *ti, BOOL isW)
1780 {
1781     TTTOOL_INFO *toolPtr;
1782     INT nTool;
1783 
1784     if (!ti) return 0;
1785     if (ti->cbSize < TTTOOLINFOW_V1_SIZE)
1786 	return FALSE;
1787 
1788     nTool = TOOLTIPS_GetToolFromInfoT (infoPtr, ti);
1789     if (nTool == -1)
1790 	return 0;
1791 
1792     TRACE("tool %d\n", nTool);
1793 
1794     toolPtr = &infoPtr->tools[nTool];
1795 
1796     /* copy tool text */
1797     toolPtr->hinst  = ti->hinst;
1798 
1799     if (IS_INTRESOURCE(ti->lpszText)){
1800 	toolPtr->lpszText = ti->lpszText;
1801     }
1802     else if (ti->lpszText) {
1803 	if (TOOLTIPS_IsCallbackString(ti->lpszText, isW))
1804 	    toolPtr->lpszText = LPSTR_TEXTCALLBACKW;
1805 	else {
1806 	    if ( (toolPtr->lpszText)  &&
1807 		 !IS_INTRESOURCE(toolPtr->lpszText) ) {
1808 		if( toolPtr->lpszText != LPSTR_TEXTCALLBACKW)
1809                     Free (toolPtr->lpszText);
1810 		toolPtr->lpszText = NULL;
1811 	    }
1812 	    if (ti->lpszText) {
1813 		if (isW) {
1814 		    INT len = lstrlenW (ti->lpszText);
1815 		    toolPtr->lpszText = Alloc ((len+1)*sizeof(WCHAR));
1816 		    strcpyW (toolPtr->lpszText, ti->lpszText);
1817 		}
1818 		else {
1819 		    INT len = MultiByteToWideChar(CP_ACP, 0, (LPSTR)ti->lpszText,
1820 						-1, NULL, 0);
1821 		    toolPtr->lpszText = Alloc (len * sizeof(WCHAR));
1822 		    MultiByteToWideChar(CP_ACP, 0, (LPSTR)ti->lpszText, -1,
1823 					toolPtr->lpszText, len);
1824 	        }
1825 	    }
1826 	}
1827     }
1828 
1829     if(infoPtr->nCurrentTool == -1) return 0;
1830     /* force repaint */
1831     if (infoPtr->bActive)
1832 	TOOLTIPS_Show (infoPtr, FALSE);
1833     else if (infoPtr->bTrackActive)
1834 	TOOLTIPS_Show (infoPtr, TRUE);
1835 
1836     return 0;
1837 }
1838 
1839 
1840 static LRESULT
1841 TOOLTIPS_Create (HWND hwnd)
1842 {
1843     TOOLTIPS_INFO *infoPtr;
1844 
1845     /* allocate memory for info structure */
1846     infoPtr = Alloc (sizeof(TOOLTIPS_INFO));
1847     SetWindowLongPtrW (hwnd, 0, (DWORD_PTR)infoPtr);
1848 
1849     /* initialize info structure */
1850     infoPtr->bActive = TRUE;
1851     infoPtr->bTrackActive = FALSE;
1852 
1853     infoPtr->nMaxTipWidth = -1;
1854     infoPtr->nTool = -1;
1855     infoPtr->nCurrentTool = -1;
1856     infoPtr->nTrackTool = -1;
1857     infoPtr->hwndSelf = hwnd;
1858 
1859     /* initialize colours and fonts */
1860     TOOLTIPS_InitSystemSettings(infoPtr);
1861 
1862     TOOLTIPS_SetDelayTime(infoPtr, TTDT_AUTOMATIC, 0);
1863 
1864     SetWindowPos (hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOZORDER | SWP_HIDEWINDOW | SWP_NOACTIVATE);
1865 
1866     return 0;
1867 }
1868 
1869 
1870 static LRESULT
1871 TOOLTIPS_Destroy (TOOLTIPS_INFO *infoPtr)
1872 {
1873     TTTOOL_INFO *toolPtr;
1874     UINT i;
1875 
1876     /* free tools */
1877     if (infoPtr->tools) {
1878 	for (i = 0; i < infoPtr->uNumTools; i++) {
1879 	    toolPtr = &infoPtr->tools[i];
1880 	    if (toolPtr->lpszText) {
1881 		if ( (toolPtr->lpszText != LPSTR_TEXTCALLBACKW) &&
1882 		     !IS_INTRESOURCE(toolPtr->lpszText) )
1883 		{
1884 		    Free (toolPtr->lpszText);
1885 		    toolPtr->lpszText = NULL;
1886 		}
1887 	    }
1888 
1889             TOOLTIPS_ResetSubclass (toolPtr);
1890         }
1891 
1892 	Free (infoPtr->tools);
1893     }
1894 
1895     /* free title string */
1896     Free (infoPtr->pszTitle);
1897     /* free title icon if not a standard one */
1898     if (TOOLTIPS_GetTitleIconIndex(infoPtr->hTitleIcon) > TTI_ERROR)
1899         DeleteObject(infoPtr->hTitleIcon);
1900 
1901     /* delete fonts */
1902     DeleteObject (infoPtr->hFont);
1903     DeleteObject (infoPtr->hTitleFont);
1904 
1905     /* free tool tips info data */
1906     SetWindowLongPtrW(infoPtr->hwndSelf, 0, 0);
1907     Free (infoPtr);
1908 
1909     return 0;
1910 }
1911 
1912 
1913 static inline LRESULT
1914 TOOLTIPS_GetFont (const TOOLTIPS_INFO *infoPtr)
1915 {
1916     return (LRESULT)infoPtr->hFont;
1917 }
1918 
1919 
1920 static LRESULT
1921 TOOLTIPS_MouseMessage (TOOLTIPS_INFO *infoPtr)
1922 {
1923     TOOLTIPS_Hide (infoPtr);
1924 
1925     return 0;
1926 }
1927 
1928 
1929 static LRESULT
1930 TOOLTIPS_NCCreate (HWND hwnd)
1931 {
1932     DWORD dwStyle = GetWindowLongW (hwnd, GWL_STYLE);
1933     DWORD dwExStyle = GetWindowLongW (hwnd, GWL_EXSTYLE);
1934 
1935     dwStyle &= ~(WS_CHILD | /*WS_MAXIMIZE |*/ WS_BORDER | WS_DLGFRAME);
1936     dwStyle |= (WS_POPUP | WS_BORDER | WS_CLIPSIBLINGS);
1937 
1938     /* WS_BORDER only draws a border round the window rect, not the
1939      * window region, therefore it is useless to us in balloon mode */
1940     if (dwStyle & TTS_BALLOON) dwStyle &= ~WS_BORDER;
1941 
1942     SetWindowLongW (hwnd, GWL_STYLE, dwStyle);
1943 
1944     dwExStyle |= WS_EX_TOOLWINDOW;
1945     SetWindowLongW (hwnd, GWL_EXSTYLE, dwExStyle);
1946 
1947     return TRUE;
1948 }
1949 
1950 
1951 static LRESULT
1952 TOOLTIPS_NCHitTest (const TOOLTIPS_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
1953 {
1954     INT nTool = (infoPtr->bTrackActive) ? infoPtr->nTrackTool : infoPtr->nTool;
1955 
1956     TRACE(" nTool=%d\n", nTool);
1957 
1958     if ((nTool > -1) && (nTool < infoPtr->uNumTools)) {
1959 	if (infoPtr->tools[nTool].uFlags & TTF_TRANSPARENT) {
1960 	    TRACE("-- in transparent mode\n");
1961 	    return HTTRANSPARENT;
1962 	}
1963     }
1964 
1965     return DefWindowProcW (infoPtr->hwndSelf, WM_NCHITTEST, wParam, lParam);
1966 }
1967 
1968 
1969 static LRESULT
1970 TOOLTIPS_NotifyFormat (TOOLTIPS_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
1971 {
1972 #ifdef __REACTOS__
1973     TTTOOL_INFO *toolPtr = infoPtr->tools;
1974     LRESULT nResult;
1975 
1976     TRACE("infoPtr=%p wParam=%lx lParam=%p\n", infoPtr, wParam, (PVOID)lParam);
1977 
1978     if (lParam == NF_QUERY) {
1979         if (toolPtr->bNotifyUnicode) {
1980             return NFR_UNICODE;
1981         } else {
1982             return NFR_ANSI;
1983         }
1984     }
1985     else if (lParam == NF_REQUERY) {
1986         nResult = SendMessageW (toolPtr->hwnd, WM_NOTIFYFORMAT,
1987                     (WPARAM)infoPtr->hwndSelf, (LPARAM)NF_QUERY);
1988         if (nResult == NFR_ANSI) {
1989             toolPtr->bNotifyUnicode = FALSE;
1990             TRACE(" -- WM_NOTIFYFORMAT returns: NFR_ANSI\n");
1991         } else if (nResult == NFR_UNICODE) {
1992             toolPtr->bNotifyUnicode = TRUE;
1993             TRACE(" -- WM_NOTIFYFORMAT returns: NFR_UNICODE\n");
1994         } else {
1995             TRACE (" -- WM_NOTIFYFORMAT returns: error!\n");
1996         }
1997         return nResult;
1998     }
1999 #else
2000     FIXME ("hwnd=%p wParam=%lx lParam=%lx\n", infoPtr->hwndSelf, wParam, lParam);
2001 #endif
2002 
2003     return 0;
2004 }
2005 
2006 
2007 static LRESULT
2008 TOOLTIPS_Paint (const TOOLTIPS_INFO *infoPtr, HDC hDC)
2009 {
2010     HDC hdc;
2011     PAINTSTRUCT ps;
2012 
2013     hdc = (hDC == NULL) ? BeginPaint (infoPtr->hwndSelf, &ps) : hDC;
2014     TOOLTIPS_Refresh (infoPtr, hdc);
2015     if (!hDC)
2016 	EndPaint (infoPtr->hwndSelf, &ps);
2017     return 0;
2018 }
2019 
2020 
2021 static LRESULT
2022 TOOLTIPS_SetFont (TOOLTIPS_INFO *infoPtr, HFONT hFont, BOOL redraw)
2023 {
2024     LOGFONTW lf;
2025 
2026     if(!GetObjectW(hFont, sizeof(lf), &lf))
2027         return 0;
2028 
2029     DeleteObject (infoPtr->hFont);
2030     infoPtr->hFont = CreateFontIndirectW(&lf);
2031 
2032     DeleteObject (infoPtr->hTitleFont);
2033     lf.lfWeight = FW_BOLD;
2034     infoPtr->hTitleFont = CreateFontIndirectW(&lf);
2035 
2036     if (redraw && infoPtr->nCurrentTool != -1)
2037         FIXME("full redraw needed\n");
2038 
2039     return 0;
2040 }
2041 
2042 /******************************************************************
2043  * TOOLTIPS_GetTextLength
2044  *
2045  * This function is called when the tooltip receive a
2046  * WM_GETTEXTLENGTH message.
2047  *
2048  * returns the length, in characters, of the tip text
2049  */
2050 static inline LRESULT
2051 TOOLTIPS_GetTextLength(const TOOLTIPS_INFO *infoPtr)
2052 {
2053     return strlenW(infoPtr->szTipText);
2054 }
2055 
2056 /******************************************************************
2057  * TOOLTIPS_OnWMGetText
2058  *
2059  * This function is called when the tooltip receive a
2060  * WM_GETTEXT message.
2061  * wParam : specifies the maximum number of characters to be copied
2062  * lParam : is the pointer to the buffer that will receive
2063  *          the tip text
2064  *
2065  * returns the number of characters copied
2066  */
2067 static LRESULT
2068 TOOLTIPS_OnWMGetText (const TOOLTIPS_INFO *infoPtr, WPARAM size, LPWSTR pszText)
2069 {
2070     LRESULT res;
2071 
2072     if(!size)
2073         return 0;
2074 
2075     res = min(strlenW(infoPtr->szTipText)+1, size);
2076     memcpy(pszText, infoPtr->szTipText, res*sizeof(WCHAR));
2077     pszText[res-1] = '\0';
2078     return res-1;
2079 }
2080 
2081 static LRESULT
2082 TOOLTIPS_Timer (TOOLTIPS_INFO *infoPtr, INT iTimer)
2083 {
2084     INT nOldTool;
2085 
2086     TRACE("timer %d (%p) expired\n", iTimer, infoPtr->hwndSelf);
2087 
2088     switch (iTimer) {
2089     case ID_TIMERSHOW:
2090         KillTimer (infoPtr->hwndSelf, ID_TIMERSHOW);
2091 	nOldTool = infoPtr->nTool;
2092 	if ((infoPtr->nTool = TOOLTIPS_CheckTool (infoPtr, TRUE)) == nOldTool)
2093 	    TOOLTIPS_Show (infoPtr, FALSE);
2094 	break;
2095 
2096     case ID_TIMERPOP:
2097         TOOLTIPS_Hide (infoPtr);
2098 	break;
2099 
2100     case ID_TIMERLEAVE:
2101         nOldTool = infoPtr->nTool;
2102 	infoPtr->nTool = TOOLTIPS_CheckTool (infoPtr, FALSE);
2103 	TRACE("tool (%p) %d %d %d\n", infoPtr->hwndSelf, nOldTool,
2104 	      infoPtr->nTool, infoPtr->nCurrentTool);
2105 	if (infoPtr->nTool != nOldTool) {
2106 	    if(infoPtr->nTool == -1) { /* Moved out of all tools */
2107 	        TOOLTIPS_Hide(infoPtr);
2108 		KillTimer(infoPtr->hwndSelf, ID_TIMERLEAVE);
2109 	    } else if (nOldTool == -1) { /* Moved from outside */
2110 	        ERR("How did this happen?\n");
2111 	    } else { /* Moved from one to another */
2112 	        TOOLTIPS_Hide (infoPtr);
2113 		KillTimer(infoPtr->hwndSelf, ID_TIMERLEAVE);
2114 		if(infoPtr->bActive) {
2115 		    SetTimer (infoPtr->hwndSelf, ID_TIMERSHOW, infoPtr->nReshowTime, 0);
2116 		    TRACE("timer 1 started!\n");
2117 		}
2118 	    }
2119 	}
2120 	break;
2121 
2122     default:
2123         ERR("Unknown timer id %d\n", iTimer);
2124 	break;
2125     }
2126     return 0;
2127 }
2128 
2129 
2130 static LRESULT
2131 TOOLTIPS_WinIniChange (TOOLTIPS_INFO *infoPtr)
2132 {
2133     TOOLTIPS_InitSystemSettings (infoPtr);
2134 
2135     return 0;
2136 }
2137 
2138 
2139 static LRESULT CALLBACK
2140 TOOLTIPS_SubclassProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam, UINT_PTR uID, DWORD_PTR dwRef)
2141 {
2142     TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr ((HWND)dwRef);
2143     MSG msg;
2144 
2145     switch (message)
2146     {
2147     case WM_MOUSEMOVE:
2148     case WM_LBUTTONDOWN:
2149     case WM_LBUTTONUP:
2150     case WM_MBUTTONDOWN:
2151     case WM_MBUTTONUP:
2152     case WM_RBUTTONDOWN:
2153     case WM_RBUTTONUP:
2154         if (infoPtr)
2155         {
2156             msg.hwnd = hwnd;
2157             msg.message = message;
2158             msg.wParam = wParam;
2159             msg.lParam = lParam;
2160             TOOLTIPS_RelayEvent(infoPtr, &msg);
2161         }
2162         break;
2163     case WM_NCDESTROY:
2164         RemoveWindowSubclass(hwnd, TOOLTIPS_SubclassProc, 1);
2165         break;
2166     default:
2167         break;
2168     }
2169 
2170     return DefSubclassProc(hwnd, message, wParam, lParam);
2171 }
2172 
2173 
2174 static LRESULT CALLBACK
2175 TOOLTIPS_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2176 {
2177     TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
2178 
2179     TRACE("hwnd=%p msg=%x wparam=%lx lParam=%lx\n", hwnd, uMsg, wParam, lParam);
2180     if (!infoPtr && (uMsg != WM_CREATE) && (uMsg != WM_NCCREATE))
2181         return DefWindowProcW (hwnd, uMsg, wParam, lParam);
2182     switch (uMsg)
2183     {
2184 	case TTM_ACTIVATE:
2185 	    return TOOLTIPS_Activate (infoPtr, (BOOL)wParam);
2186 
2187 	case TTM_ADDTOOLA:
2188 	case TTM_ADDTOOLW:
2189 	    return TOOLTIPS_AddToolT (infoPtr, (LPTTTOOLINFOW)lParam, uMsg == TTM_ADDTOOLW);
2190 
2191 	case TTM_DELTOOLA:
2192 	case TTM_DELTOOLW:
2193 	    return TOOLTIPS_DelToolT (infoPtr, (LPTOOLINFOW)lParam,
2194                                       uMsg == TTM_DELTOOLW);
2195 	case TTM_ENUMTOOLSA:
2196 	case TTM_ENUMTOOLSW:
2197 	    return TOOLTIPS_EnumToolsT (infoPtr, (UINT)wParam, (LPTTTOOLINFOW)lParam,
2198                                         uMsg == TTM_ENUMTOOLSW);
2199 	case TTM_GETBUBBLESIZE:
2200 	    return TOOLTIPS_GetBubbleSize (infoPtr, (LPTTTOOLINFOW)lParam);
2201 
2202 	case TTM_GETCURRENTTOOLA:
2203 	case TTM_GETCURRENTTOOLW:
2204 	    return TOOLTIPS_GetCurrentToolT (infoPtr, (LPTTTOOLINFOW)lParam,
2205                                              uMsg == TTM_GETCURRENTTOOLW);
2206 
2207 	case TTM_GETDELAYTIME:
2208 	    return TOOLTIPS_GetDelayTime (infoPtr, (DWORD)wParam);
2209 
2210 	case TTM_GETMARGIN:
2211 	    return TOOLTIPS_GetMargin (infoPtr, (LPRECT)lParam);
2212 
2213 	case TTM_GETMAXTIPWIDTH:
2214 	    return TOOLTIPS_GetMaxTipWidth (infoPtr);
2215 
2216 	case TTM_GETTEXTA:
2217 	case TTM_GETTEXTW:
2218 	    return TOOLTIPS_GetTextT (infoPtr, (LPTTTOOLINFOW)lParam,
2219                                       uMsg == TTM_GETTEXTW);
2220 
2221 	case TTM_GETTIPBKCOLOR:
2222 	    return TOOLTIPS_GetTipBkColor (infoPtr);
2223 
2224 	case TTM_GETTIPTEXTCOLOR:
2225 	    return TOOLTIPS_GetTipTextColor (infoPtr);
2226 
2227 	case TTM_GETTOOLCOUNT:
2228 	    return TOOLTIPS_GetToolCount (infoPtr);
2229 
2230 	case TTM_GETTOOLINFOA:
2231 	case TTM_GETTOOLINFOW:
2232 	    return TOOLTIPS_GetToolInfoT (infoPtr, (LPTTTOOLINFOW)lParam,
2233                                           uMsg == TTM_GETTOOLINFOW);
2234 
2235 	case TTM_HITTESTA:
2236 	case TTM_HITTESTW:
2237 	    return TOOLTIPS_HitTestT (infoPtr, (LPTTHITTESTINFOW)lParam,
2238                                       uMsg == TTM_HITTESTW);
2239 	case TTM_NEWTOOLRECTA:
2240 	case TTM_NEWTOOLRECTW:
2241 	    return TOOLTIPS_NewToolRectT (infoPtr, (LPTTTOOLINFOW)lParam);
2242 
2243 	case TTM_POP:
2244 	    return TOOLTIPS_Pop (infoPtr);
2245 
2246 	case TTM_RELAYEVENT:
2247 	    return TOOLTIPS_RelayEvent (infoPtr, (LPMSG)lParam);
2248 
2249 	case TTM_SETDELAYTIME:
2250 	    return TOOLTIPS_SetDelayTime (infoPtr, (DWORD)wParam, (INT)LOWORD(lParam));
2251 
2252 	case TTM_SETMARGIN:
2253 	    return TOOLTIPS_SetMargin (infoPtr, (LPRECT)lParam);
2254 
2255 	case TTM_SETMAXTIPWIDTH:
2256 	    return TOOLTIPS_SetMaxTipWidth (infoPtr, (INT)lParam);
2257 
2258 	case TTM_SETTIPBKCOLOR:
2259 	    return TOOLTIPS_SetTipBkColor (infoPtr, (COLORREF)wParam);
2260 
2261 	case TTM_SETTIPTEXTCOLOR:
2262 	    return TOOLTIPS_SetTipTextColor (infoPtr, (COLORREF)wParam);
2263 
2264 	case TTM_SETTITLEA:
2265 	case TTM_SETTITLEW:
2266 	    return TOOLTIPS_SetTitleT (infoPtr, (UINT_PTR)wParam, (LPCWSTR)lParam,
2267                                        uMsg == TTM_SETTITLEW);
2268 
2269 	case TTM_SETTOOLINFOA:
2270 	case TTM_SETTOOLINFOW:
2271 	    return TOOLTIPS_SetToolInfoT (infoPtr, (LPTTTOOLINFOW)lParam,
2272                                           uMsg == TTM_SETTOOLINFOW);
2273 
2274 	case TTM_TRACKACTIVATE:
2275 	    return TOOLTIPS_TrackActivate (infoPtr, (BOOL)wParam, (LPTTTOOLINFOA)lParam);
2276 
2277 	case TTM_TRACKPOSITION:
2278 	    return TOOLTIPS_TrackPosition (infoPtr, lParam);
2279 
2280 	case TTM_UPDATE:
2281 	    return TOOLTIPS_Update (infoPtr);
2282 
2283 	case TTM_UPDATETIPTEXTA:
2284 	case TTM_UPDATETIPTEXTW:
2285 	    return TOOLTIPS_UpdateTipTextT (infoPtr, (LPTTTOOLINFOW)lParam,
2286                                             uMsg == TTM_UPDATETIPTEXTW);
2287 
2288 	case TTM_WINDOWFROMPOINT:
2289 	    return (LRESULT)WindowFromPoint (*((LPPOINT)lParam));
2290 
2291 	case WM_CREATE:
2292 	    return TOOLTIPS_Create (hwnd);
2293 
2294 	case WM_DESTROY:
2295 	    return TOOLTIPS_Destroy (infoPtr);
2296 
2297 	case WM_ERASEBKGND:
2298 	    /* we draw the background in WM_PAINT */
2299 	    return 0;
2300 
2301 	case WM_GETFONT:
2302 	    return TOOLTIPS_GetFont (infoPtr);
2303 
2304 	case WM_GETTEXT:
2305 	    return TOOLTIPS_OnWMGetText (infoPtr, wParam, (LPWSTR)lParam);
2306 
2307 	case WM_GETTEXTLENGTH:
2308 	    return TOOLTIPS_GetTextLength (infoPtr);
2309 
2310 	case WM_LBUTTONDOWN:
2311 	case WM_LBUTTONUP:
2312 	case WM_MBUTTONDOWN:
2313 	case WM_MBUTTONUP:
2314 	case WM_RBUTTONDOWN:
2315 	case WM_RBUTTONUP:
2316 	case WM_MOUSEMOVE:
2317 	    return TOOLTIPS_MouseMessage (infoPtr);
2318 
2319 	case WM_NCCREATE:
2320 	    return TOOLTIPS_NCCreate (hwnd);
2321 
2322 	case WM_NCHITTEST:
2323 	    return TOOLTIPS_NCHitTest (infoPtr, wParam, lParam);
2324 
2325 	case WM_NOTIFYFORMAT:
2326 	    return TOOLTIPS_NotifyFormat (infoPtr, wParam, lParam);
2327 
2328 	case WM_PRINTCLIENT:
2329 	case WM_PAINT:
2330 	    return TOOLTIPS_Paint (infoPtr, (HDC)wParam);
2331 
2332 	case WM_SETFONT:
2333 	    return TOOLTIPS_SetFont (infoPtr, (HFONT)wParam, LOWORD(lParam));
2334 
2335 	case WM_SYSCOLORCHANGE:
2336 	    COMCTL32_RefreshSysColors();
2337 	    return 0;
2338 
2339 	case WM_TIMER:
2340 	    return TOOLTIPS_Timer (infoPtr, (INT)wParam);
2341 
2342 	case WM_WININICHANGE:
2343 	    return TOOLTIPS_WinIniChange (infoPtr);
2344 
2345 	default:
2346 	    if ((uMsg >= WM_USER) && (uMsg < WM_APP) && !COMCTL32_IsReflectedMessage(uMsg))
2347 		ERR("unknown msg %04x wp=%08lx lp=%08lx\n",
2348 		     uMsg, wParam, lParam);
2349 	    return DefWindowProcW (hwnd, uMsg, wParam, lParam);
2350     }
2351 }
2352 
2353 
2354 VOID
2355 TOOLTIPS_Register (void)
2356 {
2357     WNDCLASSW wndClass;
2358 
2359     ZeroMemory (&wndClass, sizeof(WNDCLASSW));
2360     wndClass.style         = CS_GLOBALCLASS | CS_DBLCLKS | CS_SAVEBITS;
2361     wndClass.lpfnWndProc   = TOOLTIPS_WindowProc;
2362     wndClass.cbClsExtra    = 0;
2363     wndClass.cbWndExtra    = sizeof(TOOLTIPS_INFO *);
2364     wndClass.hCursor       = LoadCursorW (0, (LPWSTR)IDC_ARROW);
2365     wndClass.hbrBackground = 0;
2366     wndClass.lpszClassName = TOOLTIPS_CLASSW;
2367 
2368     RegisterClassW (&wndClass);
2369 
2370     hTooltipIcons[TTI_NONE] = NULL;
2371     hTooltipIcons[TTI_INFO] = LoadImageW(COMCTL32_hModule,
2372         (LPCWSTR)MAKEINTRESOURCE(IDI_TT_INFO_SM), IMAGE_ICON, 0, 0, 0);
2373     hTooltipIcons[TTI_WARNING] = LoadImageW(COMCTL32_hModule,
2374         (LPCWSTR)MAKEINTRESOURCE(IDI_TT_WARN_SM), IMAGE_ICON, 0, 0, 0);
2375     hTooltipIcons[TTI_ERROR] = LoadImageW(COMCTL32_hModule,
2376         (LPCWSTR)MAKEINTRESOURCE(IDI_TT_ERROR_SM), IMAGE_ICON, 0, 0, 0);
2377 }
2378 
2379 
2380 VOID
2381 TOOLTIPS_Unregister (void)
2382 {
2383     int i;
2384     for (i = TTI_INFO; i <= TTI_ERROR; i++)
2385         DestroyIcon(hTooltipIcons[i]);
2386     UnregisterClassW (TOOLTIPS_CLASSW, NULL);
2387 }
2388