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