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