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