comctl32/tooltips: Remove redundant code, let handlers deal with A<->W conversions.
[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(NMTTCUSTOMDRAW *lpnmttcd,
217                          const HWND hwnd,
218                          HDC hdc, const RECT *rcBounds, UINT uFlags)
219 {
220     TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr(hwnd);
221
222     ZeroMemory(lpnmttcd, sizeof(NMTTCUSTOMDRAW));
223     lpnmttcd->uDrawFlags = uFlags;
224     lpnmttcd->nmcd.hdr.hwndFrom = hwnd;
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 = CDRF_DODEFAULT;
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(&nmttcd, infoPtr->hwndSelf, 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) && toolPtr->hinst) {
489         /* load a resource */
490         TRACE("load res string %p %x\n",
491                toolPtr->hinst, LOWORD(toolPtr->lpszText));
492         LoadStringW (toolPtr->hinst, LOWORD(toolPtr->lpszText),
493                        buffer, INFOTIPSIZE);
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     TRACE("%s\n", debugstr_w(buffer));
513 }
514
515
516 static void
517 TOOLTIPS_CalcTipSize (const TOOLTIPS_INFO *infoPtr, LPSIZE lpSize)
518 {
519     HDC hdc;
520     HFONT hOldFont;
521     DWORD style = GetWindowLongW(infoPtr->hwndSelf, GWL_STYLE);
522     UINT uFlags = DT_EXTERNALLEADING | DT_CALCRECT;
523     RECT rc = {0, 0, 0, 0};
524     SIZE title = {0, 0};
525
526     if (infoPtr->nMaxTipWidth > -1) {
527         rc.right = infoPtr->nMaxTipWidth;
528         uFlags |= DT_WORDBREAK;
529     }
530     if (style & TTS_NOPREFIX)
531         uFlags |= DT_NOPREFIX;
532     TRACE("%s\n", debugstr_w(infoPtr->szTipText));
533
534     hdc = GetDC (infoPtr->hwndSelf);
535     if (infoPtr->pszTitle)
536     {
537         RECT rcTitle = {0, 0, 0, 0};
538         TRACE("title %s\n", debugstr_w(infoPtr->pszTitle));
539         if (infoPtr->hTitleIcon)
540         {
541             title.cx = ICON_WIDTH;
542             title.cy = ICON_HEIGHT;
543         }
544         if (title.cx != 0) title.cx += BALLOON_ICON_TITLE_SPACING;
545         hOldFont = SelectObject (hdc, infoPtr->hTitleFont);
546         DrawTextW(hdc, infoPtr->pszTitle, -1, &rcTitle, DT_SINGLELINE | DT_NOPREFIX | DT_CALCRECT);
547         SelectObject (hdc, hOldFont);
548         title.cy = max(title.cy, rcTitle.bottom - rcTitle.top) + BALLOON_TITLE_TEXT_SPACING;
549         title.cx += (rcTitle.right - rcTitle.left);
550     }
551     hOldFont = SelectObject (hdc, infoPtr->hFont);
552     DrawTextW (hdc, infoPtr->szTipText, -1, &rc, uFlags);
553     SelectObject (hdc, hOldFont);
554     ReleaseDC (infoPtr->hwndSelf, hdc);
555
556     if ((style & TTS_BALLOON) || infoPtr->pszTitle)
557     {
558         lpSize->cx = max(rc.right - rc.left, title.cx) + 2*BALLOON_TEXT_MARGIN +
559                        infoPtr->rcMargin.left + infoPtr->rcMargin.right;
560         lpSize->cy = title.cy + rc.bottom - rc.top + 2*BALLOON_TEXT_MARGIN +
561                        infoPtr->rcMargin.bottom + infoPtr->rcMargin.top +
562                        BALLOON_STEMHEIGHT;
563     }
564     else
565     {
566         lpSize->cx = rc.right - rc.left + 2*NORMAL_TEXT_MARGIN +
567                        infoPtr->rcMargin.left + infoPtr->rcMargin.right;
568         lpSize->cy = rc.bottom - rc.top + 2*NORMAL_TEXT_MARGIN +
569                        infoPtr->rcMargin.bottom + infoPtr->rcMargin.top;
570     }
571 }
572
573
574 static void
575 TOOLTIPS_Show (TOOLTIPS_INFO *infoPtr, BOOL track_activate)
576 {
577     TTTOOL_INFO *toolPtr;
578     HMONITOR monitor;
579     MONITORINFO mon_info;
580     RECT rect;
581     SIZE size;
582     NMHDR  hdr;
583     int ptfx = 0;
584     DWORD style = GetWindowLongW(infoPtr->hwndSelf, GWL_STYLE);
585     INT nTool;
586
587     if (track_activate)
588     {
589         if (infoPtr->nTrackTool == -1)
590         {
591             TRACE("invalid tracking tool (-1)!\n");
592             return;
593         }
594         nTool = infoPtr->nTrackTool;
595     }
596     else
597     {
598         if (infoPtr->nTool == -1)
599         {
600             TRACE("invalid tool (-1)!\n");
601                 return;
602         }
603         nTool = infoPtr->nTool;
604     }
605
606     TRACE("Show tooltip pre %d! (%p)\n", nTool, infoPtr->hwndSelf);
607
608     TOOLTIPS_GetTipText (infoPtr, nTool, infoPtr->szTipText);
609
610     if (infoPtr->szTipText[0] == '\0')
611         return;
612
613     toolPtr = &infoPtr->tools[nTool];
614
615     if (!track_activate)
616         infoPtr->nCurrentTool = infoPtr->nTool;
617
618     TRACE("Show tooltip %d!\n", nTool);
619
620     hdr.hwndFrom = infoPtr->hwndSelf;
621     hdr.idFrom = toolPtr->uId;
622     hdr.code = TTN_SHOW;
623     SendMessageW (toolPtr->hwnd, WM_NOTIFY, toolPtr->uId, (LPARAM)&hdr);
624
625     TRACE("%s\n", debugstr_w(infoPtr->szTipText));
626
627     TOOLTIPS_CalcTipSize (infoPtr, &size);
628     TRACE("size %d x %d\n", size.cx, size.cy);
629
630     if (track_activate)
631     {
632         rect.left = infoPtr->xTrackPos;
633         rect.top  = infoPtr->yTrackPos;
634         ptfx = rect.left;
635
636         if (toolPtr->uFlags & TTF_CENTERTIP)
637         {
638             rect.left -= (size.cx / 2);
639             if (!(style & TTS_BALLOON))
640                 rect.top  -= (size.cy / 2);
641         }
642         infoPtr->bToolBelow = TRUE;
643
644         if (!(toolPtr->uFlags & TTF_ABSOLUTE))
645         {
646             if (style & TTS_BALLOON)
647                 rect.left -= BALLOON_STEMINDENT;
648             else
649             {
650                 RECT rcTool;
651
652                 if (toolPtr->uFlags & TTF_IDISHWND)
653                     GetWindowRect ((HWND)toolPtr->uId, &rcTool);
654                 else
655                 {
656                     rcTool = toolPtr->rect;
657                     MapWindowPoints (toolPtr->hwnd, NULL, (LPPOINT)&rcTool, 2);
658                 }
659
660                 /* smart placement */
661                 if ((rect.left + size.cx > rcTool.left) && (rect.left < rcTool.right) &&
662                     (rect.top + size.cy > rcTool.top) && (rect.top < rcTool.bottom))
663                     rect.left = rcTool.right;
664             }
665         }
666     }
667     else
668     {
669         if (toolPtr->uFlags & TTF_CENTERTIP)
670         {
671                 RECT rc;
672
673             if (toolPtr->uFlags & TTF_IDISHWND)
674                 GetWindowRect ((HWND)toolPtr->uId, &rc);
675             else {
676                 rc = toolPtr->rect;
677                 MapWindowPoints (toolPtr->hwnd, NULL, (LPPOINT)&rc, 2);
678             }
679             rect.left = (rc.left + rc.right - size.cx) / 2;
680             if (style & TTS_BALLOON)
681             {
682                 ptfx = rc.left + ((rc.right - rc.left) / 2);
683
684                 /* CENTERTIP ballon tooltips default to below the field
685                  * if they fit on the screen */
686                 if (rc.bottom + size.cy > GetSystemMetrics(SM_CYSCREEN))
687                 {
688                     rect.top = rc.top - size.cy;
689                     infoPtr->bToolBelow = FALSE;
690                 }
691                 else
692                 {
693                     infoPtr->bToolBelow = TRUE;
694                     rect.top = rc.bottom;
695                 }
696                 rect.left = max(0, rect.left - BALLOON_STEMINDENT);
697             }
698             else
699             {
700                 rect.top  = rc.bottom + 2;
701                 infoPtr->bToolBelow = TRUE;
702             }
703         }
704         else
705         {
706             GetCursorPos ((LPPOINT)&rect);
707             if (style & TTS_BALLOON)
708             {
709                 ptfx = rect.left;
710                 if(rect.top - size.cy >= 0)
711                 {
712                     rect.top -= size.cy;
713                     infoPtr->bToolBelow = FALSE;
714                 }
715                 else
716                 {
717                     infoPtr->bToolBelow = TRUE;
718                     rect.top += 20;
719                 }
720                 rect.left = max(0, rect.left - BALLOON_STEMINDENT);
721             }
722             else
723             {
724                     rect.top += 20;
725                     infoPtr->bToolBelow = TRUE;
726             }
727         }
728     }
729
730     TRACE("pos %d - %d\n", rect.left, rect.top);
731
732     rect.right = rect.left + size.cx;
733     rect.bottom = rect.top + size.cy;
734
735     /* check position */
736
737     monitor = MonitorFromRect( &rect, MONITOR_DEFAULTTOPRIMARY );
738     mon_info.cbSize = sizeof(mon_info);
739     GetMonitorInfoW( monitor, &mon_info );
740
741     if( rect.right > mon_info.rcWork.right ) {
742         rect.left -= rect.right - mon_info.rcWork.right + 2;
743         rect.right = mon_info.rcWork.right - 2;
744     }
745     if (rect.left < mon_info.rcWork.left) rect.left = mon_info.rcWork.left;
746
747     if( rect.bottom > mon_info.rcWork.bottom ) {
748         RECT rc;
749
750         if (toolPtr->uFlags & TTF_IDISHWND)
751             GetWindowRect ((HWND)toolPtr->uId, &rc);
752         else {
753             rc = toolPtr->rect;
754             MapWindowPoints (toolPtr->hwnd, NULL, (LPPOINT)&rc, 2);
755         }
756         rect.bottom = rc.top - 2;
757         rect.top = rect.bottom - size.cy;
758     }
759
760     AdjustWindowRectEx (&rect, GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE),
761                         FALSE, GetWindowLongW (infoPtr->hwndSelf, GWL_EXSTYLE));
762
763     if (style & TTS_BALLOON)
764     {
765         HRGN hRgn;
766         HRGN hrStem;
767         POINT pts[3];
768
769         ptfx -= rect.left;
770
771         if(infoPtr->bToolBelow)
772         {
773           pts[0].x = ptfx;
774           pts[0].y = 0;
775           pts[1].x = max(BALLOON_STEMINDENT, ptfx - (BALLOON_STEMWIDTH / 2));
776           pts[1].y = BALLOON_STEMHEIGHT;
777           pts[2].x = pts[1].x + BALLOON_STEMWIDTH;
778           pts[2].y = pts[1].y;
779           if(pts[2].x > (rect.right - rect.left) - BALLOON_STEMINDENT)
780           {
781             pts[2].x = (rect.right - rect.left) - BALLOON_STEMINDENT;
782             pts[1].x = pts[2].x - BALLOON_STEMWIDTH;
783           }
784         }
785         else
786         {
787           pts[0].x = max(BALLOON_STEMINDENT, ptfx - (BALLOON_STEMWIDTH / 2));
788           pts[0].y = (rect.bottom - rect.top) - BALLOON_STEMHEIGHT;
789           pts[1].x = pts[0].x + BALLOON_STEMWIDTH;
790           pts[1].y = pts[0].y;
791           pts[2].x = ptfx;
792           pts[2].y = (rect.bottom - rect.top);
793           if(pts[1].x > (rect.right - rect.left) - BALLOON_STEMINDENT)
794           {
795             pts[1].x = (rect.right - rect.left) - BALLOON_STEMINDENT;
796             pts[0].x = pts[1].x - BALLOON_STEMWIDTH;
797           }
798         }
799
800         hrStem = CreatePolygonRgn(pts, sizeof(pts) / sizeof(pts[0]), ALTERNATE);
801         
802         hRgn = CreateRoundRectRgn(0,
803                                   (infoPtr->bToolBelow ? BALLOON_STEMHEIGHT : 0),
804                                   rect.right - rect.left,
805                                   (infoPtr->bToolBelow ? rect.bottom - rect.top : rect.bottom - rect.top - BALLOON_STEMHEIGHT),
806                                   BALLOON_ROUNDEDNESS, BALLOON_ROUNDEDNESS);
807
808         CombineRgn(hRgn, hRgn, hrStem, RGN_OR);
809         DeleteObject(hrStem);
810
811         SetWindowRgn(infoPtr->hwndSelf, hRgn, FALSE);
812         /* we don't free the region handle as the system deletes it when 
813          * it is no longer needed */
814     }
815
816     SetWindowPos (infoPtr->hwndSelf, HWND_TOPMOST, rect.left, rect.top,
817                     rect.right - rect.left, rect.bottom - rect.top,
818                     SWP_SHOWWINDOW | SWP_NOACTIVATE);
819
820     /* repaint the tooltip */
821     InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
822     UpdateWindow(infoPtr->hwndSelf);
823
824     if (!track_activate)
825     {
826         SetTimer (infoPtr->hwndSelf, ID_TIMERPOP, infoPtr->nAutoPopTime, 0);
827         TRACE("timer 2 started!\n");
828         SetTimer (infoPtr->hwndSelf, ID_TIMERLEAVE, infoPtr->nReshowTime, 0);
829         TRACE("timer 3 started!\n");
830     }
831 }
832
833
834 static void
835 TOOLTIPS_Hide (TOOLTIPS_INFO *infoPtr)
836 {
837     TTTOOL_INFO *toolPtr;
838     NMHDR hdr;
839
840     TRACE("Hide tooltip %d! (%p)\n", infoPtr->nCurrentTool, infoPtr->hwndSelf);
841
842     if (infoPtr->nCurrentTool == -1)
843         return;
844
845     toolPtr = &infoPtr->tools[infoPtr->nCurrentTool];
846     KillTimer (infoPtr->hwndSelf, ID_TIMERPOP);
847
848     hdr.hwndFrom = infoPtr->hwndSelf;
849     hdr.idFrom = toolPtr->uId;
850     hdr.code = TTN_POP;
851     SendMessageW (toolPtr->hwnd, WM_NOTIFY, toolPtr->uId, (LPARAM)&hdr);
852
853     infoPtr->nCurrentTool = -1;
854
855     SetWindowPos (infoPtr->hwndSelf, HWND_TOP, 0, 0, 0, 0,
856                     SWP_NOZORDER | SWP_HIDEWINDOW | SWP_NOACTIVATE);
857 }
858
859
860 static void
861 TOOLTIPS_TrackShow (TOOLTIPS_INFO *infoPtr)
862 {
863     TOOLTIPS_Show(infoPtr, TRUE);
864 }
865
866
867 static void
868 TOOLTIPS_TrackHide (const TOOLTIPS_INFO *infoPtr)
869 {
870     TTTOOL_INFO *toolPtr;
871     NMHDR hdr;
872
873     TRACE("hide tracking tooltip %d\n", infoPtr->nTrackTool);
874
875     if (infoPtr->nTrackTool == -1)
876         return;
877
878     toolPtr = &infoPtr->tools[infoPtr->nTrackTool];
879
880     hdr.hwndFrom = infoPtr->hwndSelf;
881     hdr.idFrom = toolPtr->uId;
882     hdr.code = TTN_POP;
883     SendMessageW (toolPtr->hwnd, WM_NOTIFY, toolPtr->uId, (LPARAM)&hdr);
884
885     SetWindowPos (infoPtr->hwndSelf, HWND_TOP, 0, 0, 0, 0,
886                     SWP_NOZORDER | SWP_HIDEWINDOW | SWP_NOACTIVATE);
887 }
888
889 /* Structure layout is the same for TTTOOLINFOW and TTTOOLINFOA,
890    this helper is used in both cases. */
891 static INT
892 TOOLTIPS_GetToolFromInfoT (const TOOLTIPS_INFO *infoPtr, const TTTOOLINFOW *lpToolInfo)
893 {
894     TTTOOL_INFO *toolPtr;
895     UINT nTool;
896
897     for (nTool = 0; nTool < infoPtr->uNumTools; nTool++) {
898         toolPtr = &infoPtr->tools[nTool];
899
900         if (!(toolPtr->uFlags & TTF_IDISHWND) &&
901             (lpToolInfo->hwnd == toolPtr->hwnd) &&
902             (lpToolInfo->uId == toolPtr->uId))
903             return nTool;
904     }
905
906     for (nTool = 0; nTool < infoPtr->uNumTools; nTool++) {
907         toolPtr = &infoPtr->tools[nTool];
908
909         if ((toolPtr->uFlags & TTF_IDISHWND) &&
910             (lpToolInfo->uId == toolPtr->uId))
911             return nTool;
912     }
913
914     return -1;
915 }
916
917
918 static INT
919 TOOLTIPS_GetToolFromPoint (const TOOLTIPS_INFO *infoPtr, HWND hwnd, const POINT *lpPt)
920 {
921     TTTOOL_INFO *toolPtr;
922     UINT nTool;
923
924     for (nTool = 0; nTool < infoPtr->uNumTools; nTool++) {
925         toolPtr = &infoPtr->tools[nTool];
926
927         if (!(toolPtr->uFlags & TTF_IDISHWND)) {
928             if (hwnd != toolPtr->hwnd)
929                 continue;
930             if (!PtInRect (&toolPtr->rect, *lpPt))
931                 continue;
932             return nTool;
933         }
934     }
935
936     for (nTool = 0; nTool < infoPtr->uNumTools; nTool++) {
937         toolPtr = &infoPtr->tools[nTool];
938
939         if (toolPtr->uFlags & TTF_IDISHWND) {
940             if ((HWND)toolPtr->uId == hwnd)
941                 return nTool;
942         }
943     }
944
945     return -1;
946 }
947
948
949 static BOOL
950 TOOLTIPS_IsWindowActive (HWND hwnd)
951 {
952     HWND hwndActive = GetActiveWindow ();
953     if (!hwndActive)
954         return FALSE;
955     if (hwndActive == hwnd)
956         return TRUE;
957     return IsChild (hwndActive, hwnd);
958 }
959
960
961 static INT
962 TOOLTIPS_CheckTool (const TOOLTIPS_INFO *infoPtr, BOOL bShowTest)
963 {
964     POINT pt;
965     HWND hwndTool;
966     INT nTool;
967
968     GetCursorPos (&pt);
969     hwndTool = (HWND)SendMessageW (infoPtr->hwndSelf, TTM_WINDOWFROMPOINT, 0, (LPARAM)&pt);
970     if (hwndTool == 0)
971         return -1;
972
973     ScreenToClient (hwndTool, &pt);
974     nTool = TOOLTIPS_GetToolFromPoint (infoPtr, hwndTool, &pt);
975     if (nTool == -1)
976         return -1;
977
978     if (!(GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE) & TTS_ALWAYSTIP) && bShowTest) {
979         if (!TOOLTIPS_IsWindowActive (GetWindow (infoPtr->hwndSelf, GW_OWNER)))
980             return -1;
981     }
982
983     TRACE("tool %d\n", nTool);
984
985     return nTool;
986 }
987
988
989 static LRESULT
990 TOOLTIPS_Activate (TOOLTIPS_INFO *infoPtr, BOOL activate)
991 {
992     infoPtr->bActive = activate;
993
994     if (infoPtr->bActive)
995         TRACE("activate!\n");
996
997     if (!(infoPtr->bActive) && (infoPtr->nCurrentTool != -1))
998         TOOLTIPS_Hide (infoPtr);
999
1000     return 0;
1001 }
1002
1003
1004 static LRESULT
1005 TOOLTIPS_AddToolT (TOOLTIPS_INFO *infoPtr, const TTTOOLINFOW *ti, BOOL isW)
1006 {
1007     TTTOOL_INFO *toolPtr;
1008     INT nResult;
1009
1010     if (!ti) return FALSE;
1011
1012     TRACE("add tool (%p) %p %ld%s!\n",
1013            infoPtr->hwndSelf, ti->hwnd, ti->uId,
1014            (ti->uFlags & TTF_IDISHWND) ? " TTF_IDISHWND" : "");
1015
1016     if (infoPtr->uNumTools == 0) {
1017         infoPtr->tools = Alloc (sizeof(TTTOOL_INFO));
1018         toolPtr = infoPtr->tools;
1019     }
1020     else {
1021         TTTOOL_INFO *oldTools = infoPtr->tools;
1022         infoPtr->tools =
1023             Alloc (sizeof(TTTOOL_INFO) * (infoPtr->uNumTools + 1));
1024         memcpy (infoPtr->tools, oldTools,
1025                 infoPtr->uNumTools * sizeof(TTTOOL_INFO));
1026         Free (oldTools);
1027         toolPtr = &infoPtr->tools[infoPtr->uNumTools];
1028     }
1029
1030     infoPtr->uNumTools++;
1031
1032     /* copy tool data */
1033     toolPtr->uFlags = ti->uFlags;
1034     toolPtr->hwnd   = ti->hwnd;
1035     toolPtr->uId    = ti->uId;
1036     toolPtr->rect   = ti->rect;
1037     toolPtr->hinst  = ti->hinst;
1038
1039     if (IS_INTRESOURCE(ti->lpszText)) {
1040         TRACE("add string id %x\n", LOWORD(ti->lpszText));
1041         toolPtr->lpszText = ti->lpszText;
1042     }
1043     else if (ti->lpszText) {
1044         if (TOOLTIPS_IsCallbackString(ti->lpszText, isW)) {
1045             TRACE("add CALLBACK!\n");
1046             toolPtr->lpszText = LPSTR_TEXTCALLBACKW;
1047         }
1048         else if (isW) {
1049             INT len = lstrlenW (ti->lpszText);
1050             TRACE("add text %s!\n", debugstr_w(ti->lpszText));
1051             toolPtr->lpszText = Alloc ((len + 1)*sizeof(WCHAR));
1052             strcpyW (toolPtr->lpszText, ti->lpszText);
1053         }
1054         else {
1055             INT len = MultiByteToWideChar(CP_ACP, 0, (LPSTR)ti->lpszText, -1, NULL, 0);
1056             TRACE("add text \"%s\"!\n", (LPSTR)ti->lpszText);
1057             toolPtr->lpszText = Alloc (len * sizeof(WCHAR));
1058             MultiByteToWideChar(CP_ACP, 0, (LPSTR)ti->lpszText, -1, toolPtr->lpszText, len);
1059         }
1060     }
1061
1062     if (ti->cbSize >= TTTOOLINFOW_V2_SIZE)
1063         toolPtr->lParam = ti->lParam;
1064
1065     /* install subclassing hook */
1066     if (toolPtr->uFlags & TTF_SUBCLASS) {
1067         if (toolPtr->uFlags & TTF_IDISHWND) {
1068             SetWindowSubclass((HWND)toolPtr->uId, TOOLTIPS_SubclassProc, 1,
1069                               (DWORD_PTR)infoPtr->hwndSelf);
1070         }
1071         else {
1072             SetWindowSubclass(toolPtr->hwnd, TOOLTIPS_SubclassProc, 1,
1073                               (DWORD_PTR)infoPtr->hwndSelf);
1074         }
1075         TRACE("subclassing installed!\n");
1076     }
1077
1078     nResult = (INT) SendMessageW (toolPtr->hwnd, WM_NOTIFYFORMAT,
1079                                   (WPARAM)infoPtr->hwndSelf, (LPARAM)NF_QUERY);
1080     if (nResult == NFR_ANSI) {
1081         toolPtr->bNotifyUnicode = FALSE;
1082         TRACE(" -- WM_NOTIFYFORMAT returns: NFR_ANSI\n");
1083     } else if (nResult == NFR_UNICODE) {
1084         toolPtr->bNotifyUnicode = TRUE;
1085         TRACE(" -- WM_NOTIFYFORMAT returns: NFR_UNICODE\n");
1086     } else {
1087         TRACE (" -- WM_NOTIFYFORMAT returns: error!\n");
1088     }
1089
1090     return TRUE;
1091 }
1092
1093
1094 static LRESULT
1095 TOOLTIPS_DelToolT (TOOLTIPS_INFO *infoPtr, const TTTOOLINFOW *ti, BOOL isW)
1096 {
1097     TTTOOL_INFO *toolPtr;
1098     INT nTool;
1099
1100     if (!ti) return 0;
1101     if (isW && ti->cbSize > TTTOOLINFOW_V2_SIZE &&
1102                ti->cbSize != TTTOOLINFOW_V3_SIZE)
1103         return 0;
1104     if (infoPtr->uNumTools == 0)
1105         return 0;
1106
1107     nTool = TOOLTIPS_GetToolFromInfoT (infoPtr, ti);
1108
1109     TRACE("tool %d\n", nTool);
1110
1111     if (nTool == -1)
1112         return 0;
1113
1114     /* make sure the tooltip has disappeared before deleting it */
1115     TOOLTIPS_Hide(infoPtr);
1116
1117     /* delete text string */
1118     toolPtr = &infoPtr->tools[nTool];
1119     if (toolPtr->lpszText) {
1120         if ( (toolPtr->lpszText != LPSTR_TEXTCALLBACKW) &&
1121              !IS_INTRESOURCE(toolPtr->lpszText) )
1122             Free (toolPtr->lpszText);
1123     }
1124
1125     /* remove subclassing */
1126     if (toolPtr->uFlags & TTF_SUBCLASS) {
1127         if (toolPtr->uFlags & TTF_IDISHWND) {
1128             RemoveWindowSubclass((HWND)toolPtr->uId, TOOLTIPS_SubclassProc, 1);
1129         }
1130         else {
1131             RemoveWindowSubclass(toolPtr->hwnd, TOOLTIPS_SubclassProc, 1);
1132         }
1133     }
1134
1135     /* delete tool from tool list */
1136     if (infoPtr->uNumTools == 1) {
1137         Free (infoPtr->tools);
1138         infoPtr->tools = NULL;
1139     }
1140     else {
1141         TTTOOL_INFO *oldTools = infoPtr->tools;
1142         infoPtr->tools =
1143             Alloc (sizeof(TTTOOL_INFO) * (infoPtr->uNumTools - 1));
1144
1145         if (nTool > 0)
1146             memcpy (&infoPtr->tools[0], &oldTools[0],
1147                     nTool * sizeof(TTTOOL_INFO));
1148
1149         if (nTool < infoPtr->uNumTools - 1)
1150             memcpy (&infoPtr->tools[nTool], &oldTools[nTool + 1],
1151                     (infoPtr->uNumTools - nTool - 1) * sizeof(TTTOOL_INFO));
1152
1153         Free (oldTools);
1154     }
1155
1156     /* update any indices affected by delete */
1157
1158     /* destroying tool that mouse was on on last relayed mouse move */
1159     if (infoPtr->nTool == nTool)
1160         /* -1 means no current tool (0 means first tool) */
1161         infoPtr->nTool = -1;
1162     else if (infoPtr->nTool > nTool)
1163         infoPtr->nTool--;
1164
1165     if (infoPtr->nTrackTool == nTool)
1166         /* -1 means no current tool (0 means first tool) */
1167         infoPtr->nTrackTool = -1;
1168     else if (infoPtr->nTrackTool > nTool)
1169         infoPtr->nTrackTool--;
1170
1171     if (infoPtr->nCurrentTool == nTool)
1172         /* -1 means no current tool (0 means first tool) */
1173         infoPtr->nCurrentTool = -1;
1174     else if (infoPtr->nCurrentTool > nTool)
1175         infoPtr->nCurrentTool--;
1176
1177     infoPtr->uNumTools--;
1178
1179     return 0;
1180 }
1181
1182 static LRESULT
1183 TOOLTIPS_EnumToolsT (const TOOLTIPS_INFO *infoPtr, UINT uIndex, TTTOOLINFOW *ti,
1184                      BOOL isW)
1185 {
1186     TTTOOL_INFO *toolPtr;
1187
1188     if (!ti) return FALSE;
1189     if (ti->cbSize < TTTOOLINFOW_V1_SIZE)
1190         return FALSE;
1191     if (uIndex >= infoPtr->uNumTools)
1192         return FALSE;
1193
1194     TRACE("index=%u\n", uIndex);
1195
1196     toolPtr = &infoPtr->tools[uIndex];
1197
1198     /* copy tool data */
1199     ti->uFlags   = toolPtr->uFlags;
1200     ti->hwnd     = toolPtr->hwnd;
1201     ti->uId      = toolPtr->uId;
1202     ti->rect     = toolPtr->rect;
1203     ti->hinst    = toolPtr->hinst;
1204 /*    ti->lpszText = toolPtr->lpszText; */
1205     ti->lpszText = NULL;  /* FIXME */
1206
1207     if (ti->cbSize >= TTTOOLINFOA_V2_SIZE)
1208         ti->lParam = toolPtr->lParam;
1209
1210     return TRUE;
1211 }
1212
1213 static LRESULT
1214 TOOLTIPS_GetBubbleSize (const TOOLTIPS_INFO *infoPtr, const TTTOOLINFOW *lpToolInfo)
1215 {
1216     INT nTool;
1217     SIZE size;
1218
1219     if (lpToolInfo == NULL)
1220         return FALSE;
1221     if (lpToolInfo->cbSize < TTTOOLINFOW_V1_SIZE)
1222         return FALSE;
1223
1224     nTool = TOOLTIPS_GetToolFromInfoT (infoPtr, lpToolInfo);
1225     if (nTool == -1) return 0;
1226
1227     TRACE("tool %d\n", nTool);
1228
1229     TOOLTIPS_CalcTipSize (infoPtr, &size);
1230     TRACE("size %d x %d\n", size.cx, size.cy);
1231
1232     return MAKELRESULT(size.cx, size.cy);
1233 }
1234
1235 static LRESULT
1236 TOOLTIPS_GetCurrentToolT (const TOOLTIPS_INFO *infoPtr, TTTOOLINFOW *ti, BOOL isW)
1237 {
1238     TTTOOL_INFO *toolPtr;
1239
1240     if (ti) {
1241         if (ti->cbSize < TTTOOLINFOW_V1_SIZE)
1242             return FALSE;
1243
1244         if (infoPtr->nCurrentTool > -1) {
1245             toolPtr = &infoPtr->tools[infoPtr->nCurrentTool];
1246
1247             /* copy tool data */
1248             ti->uFlags   = toolPtr->uFlags;
1249             ti->rect     = toolPtr->rect;
1250             ti->hinst    = toolPtr->hinst;
1251 /*          ti->lpszText = toolPtr->lpszText; */
1252             ti->lpszText = NULL;  /* FIXME */
1253
1254             if (ti->cbSize >= TTTOOLINFOW_V2_SIZE)
1255                 ti->lParam = toolPtr->lParam;
1256
1257             return TRUE;
1258         }
1259         else
1260             return FALSE;
1261     }
1262     else
1263         return (infoPtr->nCurrentTool != -1);
1264 }
1265
1266
1267 static LRESULT
1268 TOOLTIPS_GetDelayTime (const TOOLTIPS_INFO *infoPtr, DWORD duration)
1269 {
1270     switch (duration) {
1271     case TTDT_RESHOW:
1272         return infoPtr->nReshowTime;
1273
1274     case TTDT_AUTOPOP:
1275         return infoPtr->nAutoPopTime;
1276
1277     case TTDT_INITIAL:
1278     case TTDT_AUTOMATIC: /* Apparently TTDT_AUTOMATIC returns TTDT_INITIAL */
1279         return infoPtr->nInitialTime;
1280
1281     default:
1282         WARN("Invalid duration flag %x\n", duration);
1283         break;
1284     }
1285
1286     return -1;
1287 }
1288
1289
1290 static LRESULT
1291 TOOLTIPS_GetMargin (const TOOLTIPS_INFO *infoPtr, LPRECT lpRect)
1292 {
1293     lpRect->left   = infoPtr->rcMargin.left;
1294     lpRect->right  = infoPtr->rcMargin.right;
1295     lpRect->bottom = infoPtr->rcMargin.bottom;
1296     lpRect->top    = infoPtr->rcMargin.top;
1297
1298     return 0;
1299 }
1300
1301
1302 static inline LRESULT
1303 TOOLTIPS_GetMaxTipWidth (const TOOLTIPS_INFO *infoPtr)
1304 {
1305     return infoPtr->nMaxTipWidth;
1306 }
1307
1308
1309 static LRESULT
1310 TOOLTIPS_GetTextT (const TOOLTIPS_INFO *infoPtr, TTTOOLINFOW *ti, BOOL isW)
1311 {
1312     INT nTool;
1313
1314     if (!ti) return 0;
1315     if (ti->cbSize < TTTOOLINFOW_V1_SIZE)
1316         return 0;
1317
1318     nTool = TOOLTIPS_GetToolFromInfoT (infoPtr, ti);
1319     if (nTool == -1) return 0;
1320
1321     if (infoPtr->tools[nTool].lpszText == NULL)
1322         return 0;
1323
1324     if (isW) {
1325         ti->lpszText[0] = '\0';
1326         TOOLTIPS_GetTipText(infoPtr, nTool, ti->lpszText);
1327     }
1328     else {
1329         WCHAR buffer[INFOTIPSIZE];
1330
1331         /* NB this API is broken, there is no way for the app to determine
1332            what size buffer it requires nor a way to specify how long the
1333            one it supplies is.  We'll assume it's up to INFOTIPSIZE */
1334
1335         buffer[0] = '\0';
1336         TOOLTIPS_GetTipText(infoPtr, nTool, buffer);
1337         WideCharToMultiByte(CP_ACP, 0, buffer, -1, (LPSTR)ti->lpszText,
1338                                                    INFOTIPSIZE, NULL, NULL);
1339     }
1340
1341     return 0;
1342 }
1343
1344
1345 static inline LRESULT
1346 TOOLTIPS_GetTipBkColor (const TOOLTIPS_INFO *infoPtr)
1347 {
1348     return infoPtr->clrBk;
1349 }
1350
1351
1352 static inline LRESULT
1353 TOOLTIPS_GetTipTextColor (const TOOLTIPS_INFO *infoPtr)
1354 {
1355     return infoPtr->clrText;
1356 }
1357
1358
1359 static inline LRESULT
1360 TOOLTIPS_GetToolCount (const TOOLTIPS_INFO *infoPtr)
1361 {
1362     return infoPtr->uNumTools;
1363 }
1364
1365
1366 static LRESULT
1367 TOOLTIPS_GetToolInfoT (const TOOLTIPS_INFO *infoPtr, TTTOOLINFOW *ti, BOOL isW)
1368 {
1369     TTTOOL_INFO *toolPtr;
1370     INT nTool;
1371
1372     if (!ti) return FALSE;
1373     if (ti->cbSize < TTTOOLINFOW_V1_SIZE)
1374         return FALSE;
1375     if (infoPtr->uNumTools == 0)
1376         return FALSE;
1377
1378     nTool = TOOLTIPS_GetToolFromInfoT (infoPtr, ti);
1379     if (nTool == -1)
1380         return FALSE;
1381
1382     TRACE("tool %d\n", nTool);
1383
1384     toolPtr = &infoPtr->tools[nTool];
1385
1386     /* copy tool data */
1387     ti->uFlags   = toolPtr->uFlags;
1388     ti->rect     = toolPtr->rect;
1389     ti->hinst    = toolPtr->hinst;
1390 /*    lpToolInfo->lpszText = toolPtr->lpszText; */
1391     ti->lpszText = NULL;  /* FIXME */
1392
1393     if (ti->cbSize >= TTTOOLINFOW_V2_SIZE)
1394         ti->lParam = toolPtr->lParam;
1395
1396     return TRUE;
1397 }
1398
1399
1400 static LRESULT
1401 TOOLTIPS_HitTestT (const TOOLTIPS_INFO *infoPtr, LPTTHITTESTINFOW lptthit,
1402                    BOOL isW)
1403 {
1404     TTTOOL_INFO *toolPtr;
1405     INT nTool;
1406
1407     if (lptthit == 0)
1408         return FALSE;
1409
1410     nTool = TOOLTIPS_GetToolFromPoint (infoPtr, lptthit->hwnd, &lptthit->pt);
1411     if (nTool == -1)
1412         return FALSE;
1413
1414     TRACE("tool %d!\n", nTool);
1415
1416     /* copy tool data */
1417     if (lptthit->ti.cbSize >= TTTOOLINFOW_V1_SIZE) {
1418         toolPtr = &infoPtr->tools[nTool];
1419
1420         lptthit->ti.uFlags   = toolPtr->uFlags;
1421         lptthit->ti.hwnd     = toolPtr->hwnd;
1422         lptthit->ti.uId      = toolPtr->uId;
1423         lptthit->ti.rect     = toolPtr->rect;
1424         lptthit->ti.hinst    = toolPtr->hinst;
1425 /*      lptthit->ti.lpszText = toolPtr->lpszText; */
1426         lptthit->ti.lpszText = NULL;  /* FIXME */
1427         if (lptthit->ti.cbSize >= TTTOOLINFOW_V2_SIZE)
1428             lptthit->ti.lParam   = toolPtr->lParam;
1429     }
1430
1431     return TRUE;
1432 }
1433
1434
1435 static LRESULT
1436 TOOLTIPS_NewToolRectT (TOOLTIPS_INFO *infoPtr, const TTTOOLINFOW *ti, BOOL isW)
1437 {
1438     INT nTool;
1439
1440     if (!ti) return 0;
1441     if (ti->cbSize < TTTOOLINFOW_V1_SIZE)
1442         return FALSE;
1443
1444     nTool = TOOLTIPS_GetToolFromInfoT (infoPtr, ti);
1445
1446     TRACE("nTool = %d, rect = %s\n", nTool, wine_dbgstr_rect(&ti->rect));
1447
1448     if (nTool == -1) return 0;
1449
1450     infoPtr->tools[nTool].rect = ti->rect;
1451
1452     return 0;
1453 }
1454
1455
1456 static inline LRESULT
1457 TOOLTIPS_Pop (TOOLTIPS_INFO *infoPtr)
1458 {
1459     TOOLTIPS_Hide (infoPtr);
1460
1461     return 0;
1462 }
1463
1464
1465 static LRESULT
1466 TOOLTIPS_RelayEvent (TOOLTIPS_INFO *infoPtr, LPMSG lpMsg)
1467 {
1468     POINT pt;
1469     INT nOldTool;
1470
1471     if (!lpMsg) {
1472         ERR("lpMsg == NULL!\n");
1473         return 0;
1474     }
1475
1476     switch (lpMsg->message) {
1477         case WM_LBUTTONDOWN:
1478         case WM_LBUTTONUP:
1479         case WM_MBUTTONDOWN:
1480         case WM_MBUTTONUP:
1481         case WM_RBUTTONDOWN:
1482         case WM_RBUTTONUP:
1483             TOOLTIPS_Hide (infoPtr);
1484             break;
1485
1486         case WM_MOUSEMOVE:
1487             pt.x = (short)LOWORD(lpMsg->lParam);
1488             pt.y = (short)HIWORD(lpMsg->lParam);
1489             nOldTool = infoPtr->nTool;
1490             infoPtr->nTool = TOOLTIPS_GetToolFromPoint(infoPtr, lpMsg->hwnd,
1491                                                        &pt);
1492             TRACE("tool (%p) %d %d %d\n", infoPtr->hwndSelf, nOldTool,
1493                   infoPtr->nTool, infoPtr->nCurrentTool);
1494             TRACE("WM_MOUSEMOVE (%p %d %d)\n", infoPtr->hwndSelf, pt.x, pt.y);
1495
1496             if (infoPtr->nTool != nOldTool) {
1497                 if(infoPtr->nTool == -1) { /* Moved out of all tools */
1498                     TOOLTIPS_Hide(infoPtr);
1499                     KillTimer(infoPtr->hwndSelf, ID_TIMERLEAVE);
1500                 } else if (nOldTool == -1) { /* Moved from outside */
1501                     if(infoPtr->bActive) {
1502                         SetTimer(infoPtr->hwndSelf, ID_TIMERSHOW, infoPtr->nInitialTime, 0);
1503                         TRACE("timer 1 started!\n");
1504                     }
1505                 } else { /* Moved from one to another */
1506                     TOOLTIPS_Hide (infoPtr);
1507                     KillTimer(infoPtr->hwndSelf, ID_TIMERLEAVE);
1508                     if(infoPtr->bActive) {
1509                         SetTimer (infoPtr->hwndSelf, ID_TIMERSHOW, infoPtr->nReshowTime, 0);
1510                         TRACE("timer 1 started!\n");
1511                     }
1512                 }
1513             } else if(infoPtr->nCurrentTool != -1) { /* restart autopop */
1514                 KillTimer(infoPtr->hwndSelf, ID_TIMERPOP);
1515                 SetTimer(infoPtr->hwndSelf, ID_TIMERPOP, infoPtr->nAutoPopTime, 0);
1516                 TRACE("timer 2 restarted\n");
1517             } else if(infoPtr->nTool != -1 && infoPtr->bActive) {
1518                 /* previous show attempt didn't result in tooltip so try again */
1519                 SetTimer(infoPtr->hwndSelf, ID_TIMERSHOW, infoPtr->nInitialTime, 0);
1520                 TRACE("timer 1 started!\n");
1521             }
1522             break;
1523     }
1524
1525     return 0;
1526 }
1527
1528
1529 static LRESULT
1530 TOOLTIPS_SetDelayTime (TOOLTIPS_INFO *infoPtr, DWORD duration, INT nTime)
1531 {
1532     switch (duration) {
1533     case TTDT_AUTOMATIC:
1534         if (nTime <= 0)
1535             nTime = GetDoubleClickTime();
1536         infoPtr->nReshowTime    = nTime / 5;
1537         infoPtr->nAutoPopTime   = nTime * 10;
1538         infoPtr->nInitialTime   = nTime;
1539         break;
1540
1541     case TTDT_RESHOW:
1542         if(nTime < 0)
1543             nTime = GetDoubleClickTime() / 5;
1544         infoPtr->nReshowTime = nTime;
1545         break;
1546
1547     case TTDT_AUTOPOP:
1548         if(nTime < 0)
1549             nTime = GetDoubleClickTime() * 10;
1550         infoPtr->nAutoPopTime = nTime;
1551         break;
1552
1553     case TTDT_INITIAL:
1554         if(nTime < 0)
1555             nTime = GetDoubleClickTime();
1556         infoPtr->nInitialTime = nTime;
1557             break;
1558
1559     default:
1560         WARN("Invalid duration flag %x\n", duration);
1561         break;
1562     }
1563
1564     return 0;
1565 }
1566
1567
1568 static LRESULT
1569 TOOLTIPS_SetMargin (TOOLTIPS_INFO *infoPtr, const RECT *lpRect)
1570 {
1571     infoPtr->rcMargin.left   = lpRect->left;
1572     infoPtr->rcMargin.right  = lpRect->right;
1573     infoPtr->rcMargin.bottom = lpRect->bottom;
1574     infoPtr->rcMargin.top    = lpRect->top;
1575
1576     return 0;
1577 }
1578
1579
1580 static inline LRESULT
1581 TOOLTIPS_SetMaxTipWidth (TOOLTIPS_INFO *infoPtr, INT MaxWidth)
1582 {
1583     INT nTemp = infoPtr->nMaxTipWidth;
1584
1585     infoPtr->nMaxTipWidth = MaxWidth;
1586
1587     return nTemp;
1588 }
1589
1590
1591 static inline LRESULT
1592 TOOLTIPS_SetTipBkColor (TOOLTIPS_INFO *infoPtr, COLORREF clrBk)
1593 {
1594     infoPtr->clrBk = clrBk;
1595
1596     return 0;
1597 }
1598
1599
1600 static inline LRESULT
1601 TOOLTIPS_SetTipTextColor (TOOLTIPS_INFO *infoPtr, COLORREF clrText)
1602 {
1603     infoPtr->clrText = clrText;
1604
1605     return 0;
1606 }
1607
1608
1609 static LRESULT
1610 TOOLTIPS_SetTitleT (TOOLTIPS_INFO *infoPtr, UINT_PTR uTitleIcon, LPCWSTR pszTitle,
1611                     BOOL isW)
1612 {
1613     UINT size;
1614
1615     TRACE("hwnd = %p, title = %s, icon = %p\n", infoPtr->hwndSelf, debugstr_w(pszTitle),
1616         (void*)uTitleIcon);
1617
1618     Free(infoPtr->pszTitle);
1619
1620     if (pszTitle)
1621     {
1622         if (isW)
1623         {
1624             size = (strlenW(pszTitle)+1)*sizeof(WCHAR);
1625             infoPtr->pszTitle = Alloc(size);
1626             if (!infoPtr->pszTitle)
1627                 return FALSE;
1628             memcpy(infoPtr->pszTitle, pszTitle, size);
1629         }
1630         else
1631         {
1632             size = sizeof(WCHAR)*MultiByteToWideChar(CP_ACP, 0, (LPSTR)pszTitle, -1, NULL, 0);
1633             infoPtr->pszTitle = Alloc(size);
1634             if (!infoPtr->pszTitle)
1635                 return FALSE;
1636             MultiByteToWideChar(CP_ACP, 0, (LPSTR)pszTitle, -1, infoPtr->pszTitle, size/sizeof(WCHAR));
1637         }
1638     }
1639     else
1640         infoPtr->pszTitle = NULL;
1641
1642     if (uTitleIcon <= TTI_ERROR)
1643         infoPtr->hTitleIcon = hTooltipIcons[uTitleIcon];
1644     else
1645         infoPtr->hTitleIcon = CopyIcon((HICON)uTitleIcon);
1646
1647     TRACE("icon = %p\n", infoPtr->hTitleIcon);
1648
1649     return TRUE;
1650 }
1651
1652
1653 static LRESULT
1654 TOOLTIPS_SetToolInfoT (TOOLTIPS_INFO *infoPtr, const TTTOOLINFOW *ti, BOOL isW)
1655 {
1656     TTTOOL_INFO *toolPtr;
1657     INT nTool;
1658
1659     if (!ti) return 0;
1660     if (ti->cbSize < TTTOOLINFOW_V1_SIZE)
1661         return 0;
1662
1663     nTool = TOOLTIPS_GetToolFromInfoT (infoPtr, ti);
1664     if (nTool == -1) return 0;
1665
1666     TRACE("tool %d\n", nTool);
1667
1668     toolPtr = &infoPtr->tools[nTool];
1669
1670     /* copy tool data */
1671     toolPtr->uFlags = ti->uFlags;
1672     toolPtr->hwnd   = ti->hwnd;
1673     toolPtr->uId    = ti->uId;
1674     toolPtr->rect   = ti->rect;
1675     toolPtr->hinst  = ti->hinst;
1676
1677     if (IS_INTRESOURCE(ti->lpszText)) {
1678         TRACE("set string id %x!\n", LOWORD(ti->lpszText));
1679         toolPtr->lpszText = ti->lpszText;
1680     }
1681     else {
1682         if (TOOLTIPS_IsCallbackString(ti->lpszText, isW))
1683             toolPtr->lpszText = LPSTR_TEXTCALLBACKW;
1684         else {
1685             if ( (toolPtr->lpszText) &&
1686                  !IS_INTRESOURCE(toolPtr->lpszText) ) {
1687                 if( toolPtr->lpszText != LPSTR_TEXTCALLBACKW)
1688                     Free (toolPtr->lpszText);
1689                 toolPtr->lpszText = NULL;
1690             }
1691             if (ti->lpszText) {
1692                 if (isW) {
1693                     INT len = lstrlenW (ti->lpszText);
1694                     toolPtr->lpszText = Alloc ((len+1)*sizeof(WCHAR));
1695                     strcpyW (toolPtr->lpszText, ti->lpszText);
1696                 }
1697                 else {
1698                     INT len = MultiByteToWideChar(CP_ACP, 0, (LPSTR)ti->lpszText,
1699                                               -1, NULL, 0);
1700                     toolPtr->lpszText = Alloc (len * sizeof(WCHAR));
1701                     MultiByteToWideChar(CP_ACP, 0, (LPSTR)ti->lpszText, -1,
1702                                         toolPtr->lpszText, len);
1703                 }
1704             }
1705         }
1706     }
1707
1708     if (ti->cbSize >= TTTOOLINFOW_V2_SIZE)
1709         toolPtr->lParam = ti->lParam;
1710
1711     if (infoPtr->nCurrentTool == nTool)
1712     {
1713         TOOLTIPS_GetTipText (infoPtr, infoPtr->nCurrentTool, infoPtr->szTipText);
1714
1715         if (infoPtr->szTipText[0] == 0)
1716             TOOLTIPS_Hide(infoPtr);
1717         else
1718             TOOLTIPS_Show (infoPtr, FALSE);
1719     }
1720
1721     return 0;
1722 }
1723
1724
1725 static LRESULT
1726 TOOLTIPS_TrackActivate (TOOLTIPS_INFO *infoPtr, BOOL track_activate, const TTTOOLINFOA *ti)
1727 {
1728     if (track_activate) {
1729
1730         if (!ti) return 0;
1731         if (ti->cbSize < TTTOOLINFOA_V1_SIZE)
1732             return FALSE;
1733
1734         /* activate */
1735         infoPtr->nTrackTool = TOOLTIPS_GetToolFromInfoT (infoPtr, (TTTOOLINFOW*)ti);
1736         if (infoPtr->nTrackTool != -1) {
1737             TRACE("activated!\n");
1738             infoPtr->bTrackActive = TRUE;
1739             TOOLTIPS_TrackShow (infoPtr);
1740         }
1741     }
1742     else {
1743         /* deactivate */
1744         TOOLTIPS_TrackHide (infoPtr);
1745
1746         infoPtr->bTrackActive = FALSE;
1747         infoPtr->nTrackTool = -1;
1748
1749         TRACE("deactivated!\n");
1750     }
1751
1752     return 0;
1753 }
1754
1755
1756 static LRESULT
1757 TOOLTIPS_TrackPosition (TOOLTIPS_INFO *infoPtr, LPARAM coord)
1758 {
1759     infoPtr->xTrackPos = (INT)LOWORD(coord);
1760     infoPtr->yTrackPos = (INT)HIWORD(coord);
1761
1762     if (infoPtr->bTrackActive) {
1763         TRACE("[%d %d]\n",
1764                infoPtr->xTrackPos, infoPtr->yTrackPos);
1765
1766         TOOLTIPS_TrackShow (infoPtr);
1767     }
1768
1769     return 0;
1770 }
1771
1772
1773 static LRESULT
1774 TOOLTIPS_Update (TOOLTIPS_INFO *infoPtr)
1775 {
1776     if (infoPtr->nCurrentTool != -1)
1777         UpdateWindow (infoPtr->hwndSelf);
1778
1779     return 0;
1780 }
1781
1782
1783 static LRESULT
1784 TOOLTIPS_UpdateTipTextT (TOOLTIPS_INFO *infoPtr, const TTTOOLINFOW *ti, BOOL isW)
1785 {
1786     TTTOOL_INFO *toolPtr;
1787     INT nTool;
1788
1789     if (!ti) return 0;
1790     if (ti->cbSize < TTTOOLINFOW_V1_SIZE)
1791         return FALSE;
1792
1793     nTool = TOOLTIPS_GetToolFromInfoT (infoPtr, ti);
1794     if (nTool == -1)
1795         return 0;
1796
1797     TRACE("tool %d\n", nTool);
1798
1799     toolPtr = &infoPtr->tools[nTool];
1800
1801     /* copy tool text */
1802     toolPtr->hinst  = ti->hinst;
1803
1804     if (IS_INTRESOURCE(ti->lpszText)){
1805         toolPtr->lpszText = ti->lpszText;
1806     }
1807     else if (ti->lpszText) {
1808         if (TOOLTIPS_IsCallbackString(ti->lpszText, isW))
1809             toolPtr->lpszText = LPSTR_TEXTCALLBACKW;
1810         else {
1811             if ( (toolPtr->lpszText)  &&
1812                  !IS_INTRESOURCE(toolPtr->lpszText) ) {
1813                 if( toolPtr->lpszText != LPSTR_TEXTCALLBACKW)
1814                     Free (toolPtr->lpszText);
1815                 toolPtr->lpszText = NULL;
1816             }
1817             if (ti->lpszText) {
1818                 if (isW) {
1819                     INT len = lstrlenW (ti->lpszText);
1820                     toolPtr->lpszText = Alloc ((len+1)*sizeof(WCHAR));
1821                     strcpyW (toolPtr->lpszText, ti->lpszText);
1822                 }
1823                 else {
1824                     INT len = MultiByteToWideChar(CP_ACP, 0, (LPSTR)ti->lpszText,
1825                                                 -1, NULL, 0);
1826                     toolPtr->lpszText = Alloc (len * sizeof(WCHAR));
1827                     MultiByteToWideChar(CP_ACP, 0, (LPSTR)ti->lpszText, -1,
1828                                         toolPtr->lpszText, len);
1829                 }
1830             }
1831         }
1832     }
1833
1834     if(infoPtr->nCurrentTool == -1) return 0;
1835     /* force repaint */
1836     if (infoPtr->bActive)
1837         TOOLTIPS_Show (infoPtr, FALSE);
1838     else if (infoPtr->bTrackActive)
1839         TOOLTIPS_Show (infoPtr, TRUE);
1840
1841     return 0;
1842 }
1843
1844
1845 static LRESULT
1846 TOOLTIPS_WindowFromPoint (HWND hwnd, WPARAM wParam, LPARAM lParam)
1847 {
1848     return (LRESULT)WindowFromPoint (*((LPPOINT)lParam));
1849 }
1850
1851
1852
1853 static LRESULT
1854 TOOLTIPS_Create (HWND hwnd, const CREATESTRUCTW *lpcs)
1855 {
1856     TOOLTIPS_INFO *infoPtr;
1857
1858     /* allocate memory for info structure */
1859     infoPtr = Alloc (sizeof(TOOLTIPS_INFO));
1860     SetWindowLongPtrW (hwnd, 0, (DWORD_PTR)infoPtr);
1861
1862     /* initialize info structure */
1863     infoPtr->bActive = TRUE;
1864     infoPtr->bTrackActive = FALSE;
1865
1866     infoPtr->nMaxTipWidth = -1;
1867     infoPtr->nTool = -1;
1868     infoPtr->nCurrentTool = -1;
1869     infoPtr->nTrackTool = -1;
1870     infoPtr->hwndSelf = hwnd;
1871
1872     /* initialize colours and fonts */
1873     TOOLTIPS_InitSystemSettings(infoPtr);
1874
1875     TOOLTIPS_SetDelayTime(infoPtr, TTDT_AUTOMATIC, 0);
1876
1877     SetWindowPos (hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOZORDER | SWP_HIDEWINDOW | SWP_NOACTIVATE);
1878
1879     return 0;
1880 }
1881
1882
1883 static LRESULT
1884 TOOLTIPS_Destroy (TOOLTIPS_INFO *infoPtr)
1885 {
1886     TTTOOL_INFO *toolPtr;
1887     UINT i;
1888
1889     /* free tools */
1890     if (infoPtr->tools) {
1891         for (i = 0; i < infoPtr->uNumTools; i++) {
1892             toolPtr = &infoPtr->tools[i];
1893             if (toolPtr->lpszText) {
1894                 if ( (toolPtr->lpszText != LPSTR_TEXTCALLBACKW) &&
1895                      !IS_INTRESOURCE(toolPtr->lpszText) )
1896                 {
1897                     Free (toolPtr->lpszText);
1898                     toolPtr->lpszText = NULL;
1899                 }
1900             }
1901
1902             /* remove subclassing */
1903         if (toolPtr->uFlags & TTF_SUBCLASS) {
1904             if (toolPtr->uFlags & TTF_IDISHWND) {
1905                 RemoveWindowSubclass((HWND)toolPtr->uId, TOOLTIPS_SubclassProc, 1);
1906             }
1907             else {
1908                 RemoveWindowSubclass(toolPtr->hwnd, TOOLTIPS_SubclassProc, 1);
1909             }
1910         }
1911     }
1912         Free (infoPtr->tools);
1913     }
1914
1915     /* free title string */
1916     Free (infoPtr->pszTitle);
1917     /* free title icon if not a standard one */
1918     if (TOOLTIPS_GetTitleIconIndex(infoPtr->hTitleIcon) > TTI_ERROR)
1919         DeleteObject(infoPtr->hTitleIcon);
1920
1921     /* delete fonts */
1922     DeleteObject (infoPtr->hFont);
1923     DeleteObject (infoPtr->hTitleFont);
1924
1925     /* free tool tips info data */
1926     SetWindowLongPtrW(infoPtr->hwndSelf, 0, 0);
1927     Free (infoPtr);
1928
1929     return 0;
1930 }
1931
1932
1933 static inline LRESULT
1934 TOOLTIPS_GetFont (const TOOLTIPS_INFO *infoPtr)
1935 {
1936     return (LRESULT)infoPtr->hFont;
1937 }
1938
1939
1940 static LRESULT
1941 TOOLTIPS_MouseMessage (TOOLTIPS_INFO *infoPtr)
1942 {
1943     TOOLTIPS_Hide (infoPtr);
1944
1945     return 0;
1946 }
1947
1948
1949 static LRESULT
1950 TOOLTIPS_NCCreate (HWND hwnd, const CREATESTRUCTW *lpcs)
1951 {
1952     DWORD dwStyle = GetWindowLongW (hwnd, GWL_STYLE);
1953     DWORD dwExStyle = GetWindowLongW (hwnd, GWL_EXSTYLE);
1954
1955     dwStyle &= ~(WS_CHILD | /*WS_MAXIMIZE |*/ WS_BORDER | WS_DLGFRAME);
1956     dwStyle |= (WS_POPUP | WS_BORDER | WS_CLIPSIBLINGS);
1957
1958     /* WS_BORDER only draws a border round the window rect, not the
1959      * window region, therefore it is useless to us in balloon mode */
1960     if (dwStyle & TTS_BALLOON) dwStyle &= ~WS_BORDER;
1961
1962     SetWindowLongW (hwnd, GWL_STYLE, dwStyle);
1963
1964     dwExStyle |= WS_EX_TOOLWINDOW;
1965     SetWindowLongW (hwnd, GWL_EXSTYLE, dwExStyle);
1966
1967     return TRUE;
1968 }
1969
1970
1971 static LRESULT
1972 TOOLTIPS_NCHitTest (const TOOLTIPS_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
1973 {
1974     INT nTool = (infoPtr->bTrackActive) ? infoPtr->nTrackTool : infoPtr->nTool;
1975
1976     TRACE(" nTool=%d\n", nTool);
1977
1978     if ((nTool > -1) && (nTool < infoPtr->uNumTools)) {
1979         if (infoPtr->tools[nTool].uFlags & TTF_TRANSPARENT) {
1980             TRACE("-- in transparent mode!\n");
1981             return HTTRANSPARENT;
1982         }
1983     }
1984
1985     return DefWindowProcW (infoPtr->hwndSelf, WM_NCHITTEST, wParam, lParam);
1986 }
1987
1988
1989 static LRESULT
1990 TOOLTIPS_NotifyFormat (TOOLTIPS_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
1991 {
1992     FIXME ("hwnd=%p wParam=%lx lParam=%lx\n", infoPtr->hwndSelf, wParam, lParam);
1993
1994     return 0;
1995 }
1996
1997
1998 static LRESULT
1999 TOOLTIPS_Paint (const TOOLTIPS_INFO *infoPtr, HDC hDC)
2000 {
2001     HDC hdc;
2002     PAINTSTRUCT ps;
2003
2004     hdc = (hDC == NULL) ? BeginPaint (infoPtr->hwndSelf, &ps) : hDC;
2005     TOOLTIPS_Refresh (infoPtr, hdc);
2006     if (!hDC)
2007         EndPaint (infoPtr->hwndSelf, &ps);
2008     return 0;
2009 }
2010
2011
2012 static LRESULT
2013 TOOLTIPS_SetFont (TOOLTIPS_INFO *infoPtr, HFONT hFont, BOOL redraw)
2014 {
2015     LOGFONTW lf;
2016
2017     if(!GetObjectW(hFont, sizeof(lf), &lf))
2018         return 0;
2019
2020     DeleteObject (infoPtr->hFont);
2021     infoPtr->hFont = CreateFontIndirectW(&lf);
2022
2023     DeleteObject (infoPtr->hTitleFont);
2024     lf.lfWeight = FW_BOLD;
2025     infoPtr->hTitleFont = CreateFontIndirectW(&lf);
2026
2027     if (redraw & (infoPtr->nCurrentTool != -1)) {
2028         FIXME("full redraw needed!\n");
2029     }
2030
2031     return 0;
2032 }
2033
2034 /******************************************************************
2035  * TOOLTIPS_GetTextLength
2036  *
2037  * This function is called when the tooltip receive a
2038  * WM_GETTEXTLENGTH message.
2039  *
2040  * returns the length, in characters, of the tip text
2041  */
2042 static inline LRESULT
2043 TOOLTIPS_GetTextLength(const TOOLTIPS_INFO *infoPtr)
2044 {
2045     return strlenW(infoPtr->szTipText);
2046 }
2047
2048 /******************************************************************
2049  * TOOLTIPS_OnWMGetText
2050  *
2051  * This function is called when the tooltip receive a
2052  * WM_GETTEXT message.
2053  * wParam : specifies the maximum number of characters to be copied
2054  * lParam : is the pointer to the buffer that will receive
2055  *          the tip text
2056  *
2057  * returns the number of characters copied
2058  */
2059 static LRESULT
2060 TOOLTIPS_OnWMGetText (const TOOLTIPS_INFO *infoPtr, WPARAM size, LPWSTR pszText)
2061 {
2062     LRESULT res;
2063
2064     if(!infoPtr->szTipText || !size)
2065         return 0;
2066
2067     res = min(strlenW(infoPtr->szTipText)+1, size);
2068     memcpy(pszText, infoPtr->szTipText, res*sizeof(WCHAR));
2069     pszText[res-1] = '\0';
2070     return res-1;
2071 }
2072
2073 static LRESULT
2074 TOOLTIPS_Timer (TOOLTIPS_INFO *infoPtr, INT iTimer)
2075 {
2076     INT nOldTool;
2077
2078     TRACE("timer %d (%p) expired!\n", iTimer, infoPtr->hwndSelf);
2079
2080     switch (iTimer) {
2081     case ID_TIMERSHOW:
2082         KillTimer (infoPtr->hwndSelf, ID_TIMERSHOW);
2083         nOldTool = infoPtr->nTool;
2084         if ((infoPtr->nTool = TOOLTIPS_CheckTool (infoPtr, TRUE)) == nOldTool)
2085             TOOLTIPS_Show (infoPtr, FALSE);
2086         break;
2087
2088     case ID_TIMERPOP:
2089         TOOLTIPS_Hide (infoPtr);
2090         break;
2091
2092     case ID_TIMERLEAVE:
2093         nOldTool = infoPtr->nTool;
2094         infoPtr->nTool = TOOLTIPS_CheckTool (infoPtr, FALSE);
2095         TRACE("tool (%p) %d %d %d\n", infoPtr->hwndSelf, nOldTool,
2096               infoPtr->nTool, infoPtr->nCurrentTool);
2097         if (infoPtr->nTool != nOldTool) {
2098             if(infoPtr->nTool == -1) { /* Moved out of all tools */
2099                 TOOLTIPS_Hide(infoPtr);
2100                 KillTimer(infoPtr->hwndSelf, ID_TIMERLEAVE);
2101             } else if (nOldTool == -1) { /* Moved from outside */
2102                 ERR("How did this happen?\n");
2103             } else { /* Moved from one to another */
2104                 TOOLTIPS_Hide (infoPtr);
2105                 KillTimer(infoPtr->hwndSelf, ID_TIMERLEAVE);
2106                 if(infoPtr->bActive) {
2107                     SetTimer (infoPtr->hwndSelf, ID_TIMERSHOW, infoPtr->nReshowTime, 0);
2108                     TRACE("timer 1 started!\n");
2109                 }
2110             }
2111         }
2112         break;
2113
2114     default:
2115         ERR("Unknown timer id %d\n", iTimer);
2116         break;
2117     }
2118     return 0;
2119 }
2120
2121
2122 static LRESULT
2123 TOOLTIPS_WinIniChange (TOOLTIPS_INFO *infoPtr)
2124 {
2125     TOOLTIPS_InitSystemSettings (infoPtr);
2126
2127     return 0;
2128 }
2129
2130
2131 static LRESULT CALLBACK
2132 TOOLTIPS_SubclassProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uID, DWORD_PTR dwRef)
2133 {
2134     TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr ((HWND)dwRef);
2135     MSG msg;
2136
2137     switch(uMsg) {
2138     case WM_MOUSEMOVE:
2139     case WM_LBUTTONDOWN:
2140     case WM_LBUTTONUP:
2141     case WM_MBUTTONDOWN:
2142     case WM_MBUTTONUP:
2143     case WM_RBUTTONDOWN:
2144     case WM_RBUTTONUP:
2145         msg.hwnd = hwnd;
2146         msg.message = uMsg;
2147         msg.wParam = wParam;
2148         msg.lParam = lParam;
2149         TOOLTIPS_RelayEvent(infoPtr, &msg);
2150         break;
2151
2152     default:
2153         break;
2154     }
2155     return DefSubclassProc(hwnd, uMsg, wParam, lParam);
2156 }
2157
2158
2159 static LRESULT CALLBACK
2160 TOOLTIPS_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2161 {
2162     TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
2163
2164     TRACE("hwnd=%p msg=%x wparam=%lx lParam=%lx\n", hwnd, uMsg, wParam, lParam);
2165     if (!infoPtr && (uMsg != WM_CREATE) && (uMsg != WM_NCCREATE))
2166         return DefWindowProcW (hwnd, uMsg, wParam, lParam);
2167     switch (uMsg)
2168     {
2169         case TTM_ACTIVATE:
2170             return TOOLTIPS_Activate (infoPtr, (BOOL)wParam);
2171
2172         case TTM_ADDTOOLA:
2173         case TTM_ADDTOOLW:
2174             return TOOLTIPS_AddToolT (infoPtr, (LPTTTOOLINFOW)lParam, uMsg == TTM_ADDTOOLW);
2175
2176         case TTM_DELTOOLA:
2177         case TTM_DELTOOLW:
2178             return TOOLTIPS_DelToolT (infoPtr, (LPTOOLINFOW)lParam,
2179                                       uMsg == TTM_DELTOOLW);
2180         case TTM_ENUMTOOLSA:
2181         case TTM_ENUMTOOLSW:
2182             return TOOLTIPS_EnumToolsT (infoPtr, (UINT)wParam, (LPTTTOOLINFOW)lParam,
2183                                         uMsg == TTM_ENUMTOOLSW);
2184         case TTM_GETBUBBLESIZE:
2185             return TOOLTIPS_GetBubbleSize (infoPtr, (LPTTTOOLINFOW)lParam);
2186
2187         case TTM_GETCURRENTTOOLA:
2188         case TTM_GETCURRENTTOOLW:
2189             return TOOLTIPS_GetCurrentToolT (infoPtr, (LPTTTOOLINFOW)lParam,
2190                                              uMsg == TTM_GETCURRENTTOOLW);
2191
2192         case TTM_GETDELAYTIME:
2193             return TOOLTIPS_GetDelayTime (infoPtr, (DWORD)wParam);
2194
2195         case TTM_GETMARGIN:
2196             return TOOLTIPS_GetMargin (infoPtr, (LPRECT)lParam);
2197
2198         case TTM_GETMAXTIPWIDTH:
2199             return TOOLTIPS_GetMaxTipWidth (infoPtr);
2200
2201         case TTM_GETTEXTA:
2202         case TTM_GETTEXTW:
2203             return TOOLTIPS_GetTextT (infoPtr, (LPTTTOOLINFOW)lParam,
2204                                       uMsg == TTM_GETTEXTW);
2205
2206         case TTM_GETTIPBKCOLOR:
2207             return TOOLTIPS_GetTipBkColor (infoPtr);
2208
2209         case TTM_GETTIPTEXTCOLOR:
2210             return TOOLTIPS_GetTipTextColor (infoPtr);
2211
2212         case TTM_GETTOOLCOUNT:
2213             return TOOLTIPS_GetToolCount (infoPtr);
2214
2215         case TTM_GETTOOLINFOA:
2216         case TTM_GETTOOLINFOW:
2217             return TOOLTIPS_GetToolInfoT (infoPtr, (LPTTTOOLINFOW)lParam,
2218                                           uMsg == TTM_GETTOOLINFOW);
2219
2220         case TTM_HITTESTA:
2221         case TTM_HITTESTW:
2222             return TOOLTIPS_HitTestT (infoPtr, (LPTTHITTESTINFOW)lParam,
2223                                       uMsg == TTM_HITTESTW);
2224         case TTM_NEWTOOLRECTA:
2225         case TTM_NEWTOOLRECTW:
2226             return TOOLTIPS_NewToolRectT (infoPtr, (LPTTTOOLINFOW)lParam,
2227                                           uMsg == TTM_NEWTOOLRECTW);
2228         case TTM_POP:
2229             return TOOLTIPS_Pop (infoPtr);
2230
2231         case TTM_RELAYEVENT:
2232             return TOOLTIPS_RelayEvent (infoPtr, (LPMSG)lParam);
2233
2234         case TTM_SETDELAYTIME:
2235             return TOOLTIPS_SetDelayTime (infoPtr, (DWORD)wParam, (INT)LOWORD(lParam));
2236
2237         case TTM_SETMARGIN:
2238             return TOOLTIPS_SetMargin (infoPtr, (LPRECT)lParam);
2239
2240         case TTM_SETMAXTIPWIDTH:
2241             return TOOLTIPS_SetMaxTipWidth (infoPtr, (INT)lParam);
2242
2243         case TTM_SETTIPBKCOLOR:
2244             return TOOLTIPS_SetTipBkColor (infoPtr, (COLORREF)wParam);
2245
2246         case TTM_SETTIPTEXTCOLOR:
2247             return TOOLTIPS_SetTipTextColor (infoPtr, (COLORREF)wParam);
2248
2249         case TTM_SETTITLEA:
2250         case TTM_SETTITLEW:
2251             return TOOLTIPS_SetTitleT (infoPtr, (UINT_PTR)wParam, (LPCWSTR)lParam,
2252                                        uMsg == TTM_SETTITLEW);
2253
2254         case TTM_SETTOOLINFOA:
2255         case TTM_SETTOOLINFOW:
2256             return TOOLTIPS_SetToolInfoT (infoPtr, (LPTTTOOLINFOW)lParam,
2257                                           uMsg == TTM_SETTOOLINFOW);
2258
2259         case TTM_TRACKACTIVATE:
2260             return TOOLTIPS_TrackActivate (infoPtr, (BOOL)wParam, (LPTTTOOLINFOA)lParam);
2261
2262         case TTM_TRACKPOSITION:
2263             return TOOLTIPS_TrackPosition (infoPtr, lParam);
2264
2265         case TTM_UPDATE:
2266             return TOOLTIPS_Update (infoPtr);
2267
2268         case TTM_UPDATETIPTEXTA:
2269         case TTM_UPDATETIPTEXTW:
2270             return TOOLTIPS_UpdateTipTextT (infoPtr, (LPTTTOOLINFOW)lParam,
2271                                             uMsg == TTM_UPDATETIPTEXTW);
2272
2273         case TTM_WINDOWFROMPOINT:
2274             return TOOLTIPS_WindowFromPoint (hwnd, wParam, lParam);
2275
2276
2277         case WM_CREATE:
2278             return TOOLTIPS_Create (hwnd, (LPCREATESTRUCTW)lParam);
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, (LPCREATESTRUCTW)lParam);
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 }