~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Wine Cross Reference
wine/dlls/comctl32/tooltips.c

Version: ~ [ wine-1.1.33 ] ~ [ wine-1.1.32 ] ~ [ wine-1.1.31 ] ~ [ wine-1.1.30 ] ~ [ wine-1.1.29 ] ~ [ wine-1.1.28 ] ~ [ wine-1.1.27 ] ~ [ wine-1.1.26 ] ~ [ wine-1.1.25 ] ~ [ wine-1.1.24 ] ~ [ wine-1.1.23 ] ~ [ wine-1.1.22 ] ~ [ wine-1.1.21 ] ~ [ wine-1.1.20 ] ~ [ wine-1.1.19 ] ~ [ wine-1.1.18 ] ~ [ wine-1.1.17 ] ~ [ wine-1.1.16 ] ~ [ wine-1.1.15 ] ~ [ wine-1.1.14 ] ~ [ wine-1.1.13 ] ~ [ wine-1.1.12 ] ~ [ wine-1.1.11 ] ~ [ wine-1.1.10 ] ~ [ wine-1.1.9 ] ~ [ wine-1.1.8 ] ~ [ wine-1.1.7 ] ~ [ wine-1.0.1 ] ~ [ wine-1.1.6 ] ~ [ wine-1.1.5 ] ~ [ wine-1.1.4 ] ~ [ wine-1.1.3 ] ~ [ wine-1.1.2 ] ~ [ wine-1.1.1 ] ~ [ wine-1.1.0 ] ~ [ wine-1.0 ] ~

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

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.