[REACTOS]
[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 && (toolPtr->uFlags & TTF_TRACK))
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 (ti->cbSize >= TTTOOLINFOW_V2_SIZE && !ti->lpszText && isW)
1028 return FALSE;
1029
1030 if (infoPtr->uNumTools == 0) {
1031 infoPtr->tools = Alloc (sizeof(TTTOOL_INFO));
1032 toolPtr = infoPtr->tools;
1033 }
1034 else {
1035 TTTOOL_INFO *oldTools = infoPtr->tools;
1036 infoPtr->tools =
1037 Alloc (sizeof(TTTOOL_INFO) * (infoPtr->uNumTools + 1));
1038 memcpy (infoPtr->tools, oldTools,
1039 infoPtr->uNumTools * sizeof(TTTOOL_INFO));
1040 Free (oldTools);
1041 toolPtr = &infoPtr->tools[infoPtr->uNumTools];
1042 }
1043
1044 infoPtr->uNumTools++;
1045
1046 /* copy tool data */
1047 toolPtr->uFlags = ti->uFlags;
1048 toolPtr->hwnd = ti->hwnd;
1049 toolPtr->uId = ti->uId;
1050 toolPtr->rect = ti->rect;
1051 toolPtr->hinst = ti->hinst;
1052
1053 if (ti->cbSize >= TTTOOLINFOW_V1_SIZE) {
1054 if (IS_INTRESOURCE(ti->lpszText)) {
1055 TRACE("add string id %x\n", LOWORD(ti->lpszText));
1056 toolPtr->lpszText = ti->lpszText;
1057 }
1058 else if (ti->lpszText) {
1059 if (TOOLTIPS_IsCallbackString(ti->lpszText, isW)) {
1060 TRACE("add CALLBACK!\n");
1061 toolPtr->lpszText = LPSTR_TEXTCALLBACKW;
1062 }
1063 else if (isW) {
1064 INT len = lstrlenW (ti->lpszText);
1065 TRACE("add text %s!\n", debugstr_w(ti->lpszText));
1066 toolPtr->lpszText = Alloc ((len + 1)*sizeof(WCHAR));
1067 strcpyW (toolPtr->lpszText, ti->lpszText);
1068 }
1069 else {
1070 INT len = MultiByteToWideChar(CP_ACP, 0, (LPSTR)ti->lpszText, -1, NULL, 0);
1071 TRACE("add text \"%s\"!\n", (LPSTR)ti->lpszText);
1072 toolPtr->lpszText = Alloc (len * sizeof(WCHAR));
1073 MultiByteToWideChar(CP_ACP, 0, (LPSTR)ti->lpszText, -1, toolPtr->lpszText, len);
1074 }
1075 }
1076 }
1077
1078 if (ti->cbSize >= TTTOOLINFOW_V2_SIZE)
1079 toolPtr->lParam = ti->lParam;
1080
1081 /* install subclassing hook */
1082 if (toolPtr->uFlags & TTF_SUBCLASS) {
1083 if (toolPtr->uFlags & TTF_IDISHWND) {
1084 SetWindowSubclass((HWND)toolPtr->uId, TOOLTIPS_SubclassProc, 1,
1085 (DWORD_PTR)infoPtr->hwndSelf);
1086 }
1087 else {
1088 SetWindowSubclass(toolPtr->hwnd, TOOLTIPS_SubclassProc, 1,
1089 (DWORD_PTR)infoPtr->hwndSelf);
1090 }
1091 TRACE("subclassing installed!\n");
1092 }
1093
1094 nResult = SendMessageW (toolPtr->hwnd, WM_NOTIFYFORMAT,
1095 (WPARAM)infoPtr->hwndSelf, NF_QUERY);
1096 if (nResult == NFR_ANSI) {
1097 toolPtr->bNotifyUnicode = FALSE;
1098 TRACE(" -- WM_NOTIFYFORMAT returns: NFR_ANSI\n");
1099 } else if (nResult == NFR_UNICODE) {
1100 toolPtr->bNotifyUnicode = TRUE;
1101 TRACE(" -- WM_NOTIFYFORMAT returns: NFR_UNICODE\n");
1102 } else {
1103 TRACE (" -- WM_NOTIFYFORMAT returns: error!\n");
1104 }
1105
1106 return TRUE;
1107 }
1108
1109
1110 static LRESULT
1111 TOOLTIPS_DelToolT (TOOLTIPS_INFO *infoPtr, const TTTOOLINFOW *ti, BOOL isW)
1112 {
1113 TTTOOL_INFO *toolPtr;
1114 INT nTool;
1115
1116 if (!ti) return 0;
1117 if (isW && ti->cbSize > TTTOOLINFOW_V2_SIZE &&
1118 ti->cbSize != TTTOOLINFOW_V3_SIZE)
1119 return 0;
1120 if (infoPtr->uNumTools == 0)
1121 return 0;
1122
1123 nTool = TOOLTIPS_GetToolFromInfoT (infoPtr, ti);
1124
1125 TRACE("tool %d\n", nTool);
1126
1127 if (nTool == -1)
1128 return 0;
1129
1130 /* make sure the tooltip has disappeared before deleting it */
1131 TOOLTIPS_Hide(infoPtr);
1132
1133 /* delete text string */
1134 toolPtr = &infoPtr->tools[nTool];
1135 if (toolPtr->lpszText) {
1136 if ( (toolPtr->lpszText != LPSTR_TEXTCALLBACKW) &&
1137 !IS_INTRESOURCE(toolPtr->lpszText) )
1138 Free (toolPtr->lpszText);
1139 }
1140
1141 /* remove subclassing */
1142 if (toolPtr->uFlags & TTF_SUBCLASS) {
1143 if (toolPtr->uFlags & TTF_IDISHWND) {
1144 RemoveWindowSubclass((HWND)toolPtr->uId, TOOLTIPS_SubclassProc, 1);
1145 }
1146 else {
1147 RemoveWindowSubclass(toolPtr->hwnd, TOOLTIPS_SubclassProc, 1);
1148 }
1149 }
1150
1151 /* delete tool from tool list */
1152 if (infoPtr->uNumTools == 1) {
1153 Free (infoPtr->tools);
1154 infoPtr->tools = NULL;
1155 }
1156 else {
1157 TTTOOL_INFO *oldTools = infoPtr->tools;
1158 infoPtr->tools =
1159 Alloc (sizeof(TTTOOL_INFO) * (infoPtr->uNumTools - 1));
1160
1161 if (nTool > 0)
1162 memcpy (&infoPtr->tools[0], &oldTools[0],
1163 nTool * sizeof(TTTOOL_INFO));
1164
1165 if (nTool < infoPtr->uNumTools - 1)
1166 memcpy (&infoPtr->tools[nTool], &oldTools[nTool + 1],
1167 (infoPtr->uNumTools - nTool - 1) * sizeof(TTTOOL_INFO));
1168
1169 Free (oldTools);
1170 }
1171
1172 /* update any indices affected by delete */
1173
1174 /* destroying tool that mouse was on on last relayed mouse move */
1175 if (infoPtr->nTool == nTool)
1176 /* -1 means no current tool (0 means first tool) */
1177 infoPtr->nTool = -1;
1178 else if (infoPtr->nTool > nTool)
1179 infoPtr->nTool--;
1180
1181 if (infoPtr->nTrackTool == nTool)
1182 /* -1 means no current tool (0 means first tool) */
1183 infoPtr->nTrackTool = -1;
1184 else if (infoPtr->nTrackTool > nTool)
1185 infoPtr->nTrackTool--;
1186
1187 if (infoPtr->nCurrentTool == nTool)
1188 /* -1 means no current tool (0 means first tool) */
1189 infoPtr->nCurrentTool = -1;
1190 else if (infoPtr->nCurrentTool > nTool)
1191 infoPtr->nCurrentTool--;
1192
1193 infoPtr->uNumTools--;
1194
1195 return 0;
1196 }
1197
1198 static LRESULT
1199 TOOLTIPS_EnumToolsT (const TOOLTIPS_INFO *infoPtr, UINT uIndex, TTTOOLINFOW *ti,
1200 BOOL isW)
1201 {
1202 TTTOOL_INFO *toolPtr;
1203
1204 if (!ti) return FALSE;
1205 if (ti->cbSize < TTTOOLINFOW_V1_SIZE)
1206 return FALSE;
1207 if (uIndex >= infoPtr->uNumTools)
1208 return FALSE;
1209
1210 TRACE("index=%u\n", uIndex);
1211
1212 toolPtr = &infoPtr->tools[uIndex];
1213
1214 /* copy tool data */
1215 ti->uFlags = toolPtr->uFlags;
1216 ti->hwnd = toolPtr->hwnd;
1217 ti->uId = toolPtr->uId;
1218 ti->rect = toolPtr->rect;
1219 ti->hinst = toolPtr->hinst;
1220 TOOLTIPS_CopyInfoT (toolPtr, ti, isW);
1221
1222 if (ti->cbSize >= TTTOOLINFOA_V2_SIZE)
1223 ti->lParam = toolPtr->lParam;
1224
1225 return TRUE;
1226 }
1227
1228 static LRESULT
1229 TOOLTIPS_GetBubbleSize (const TOOLTIPS_INFO *infoPtr, const TTTOOLINFOW *lpToolInfo)
1230 {
1231 INT nTool;
1232 SIZE size;
1233
1234 if (lpToolInfo == NULL)
1235 return FALSE;
1236 if (lpToolInfo->cbSize < TTTOOLINFOW_V1_SIZE)
1237 return FALSE;
1238
1239 nTool = TOOLTIPS_GetToolFromInfoT (infoPtr, lpToolInfo);
1240 if (nTool == -1) return 0;
1241
1242 TRACE("tool %d\n", nTool);
1243
1244 TOOLTIPS_CalcTipSize (infoPtr, &size);
1245 TRACE("size %d x %d\n", size.cx, size.cy);
1246
1247 return MAKELRESULT(size.cx, size.cy);
1248 }
1249
1250 static LRESULT
1251 TOOLTIPS_GetCurrentToolT (const TOOLTIPS_INFO *infoPtr, TTTOOLINFOW *ti, BOOL isW)
1252 {
1253 TTTOOL_INFO *toolPtr;
1254
1255 if (ti) {
1256 if (ti->cbSize < TTTOOLINFOW_V1_SIZE)
1257 return FALSE;
1258
1259 if (infoPtr->nCurrentTool > -1) {
1260 toolPtr = &infoPtr->tools[infoPtr->nCurrentTool];
1261
1262 /* copy tool data */
1263 ti->uFlags = toolPtr->uFlags;
1264 ti->rect = toolPtr->rect;
1265 ti->hinst = toolPtr->hinst;
1266 TOOLTIPS_CopyInfoT (toolPtr, ti, isW);
1267
1268 if (ti->cbSize >= TTTOOLINFOW_V2_SIZE)
1269 ti->lParam = toolPtr->lParam;
1270
1271 return TRUE;
1272 }
1273 else
1274 return FALSE;
1275 }
1276 else
1277 return (infoPtr->nCurrentTool != -1);
1278 }
1279
1280
1281 static LRESULT
1282 TOOLTIPS_GetDelayTime (const TOOLTIPS_INFO *infoPtr, DWORD duration)
1283 {
1284 switch (duration) {
1285 case TTDT_RESHOW:
1286 return infoPtr->nReshowTime;
1287
1288 case TTDT_AUTOPOP:
1289 return infoPtr->nAutoPopTime;
1290
1291 case TTDT_INITIAL:
1292 case TTDT_AUTOMATIC: /* Apparently TTDT_AUTOMATIC returns TTDT_INITIAL */
1293 return infoPtr->nInitialTime;
1294
1295 default:
1296 WARN("Invalid duration flag %x\n", duration);
1297 break;
1298 }
1299
1300 return -1;
1301 }
1302
1303
1304 static LRESULT
1305 TOOLTIPS_GetMargin (const TOOLTIPS_INFO *infoPtr, LPRECT lpRect)
1306 {
1307 lpRect->left = infoPtr->rcMargin.left;
1308 lpRect->right = infoPtr->rcMargin.right;
1309 lpRect->bottom = infoPtr->rcMargin.bottom;
1310 lpRect->top = infoPtr->rcMargin.top;
1311
1312 return 0;
1313 }
1314
1315
1316 static inline LRESULT
1317 TOOLTIPS_GetMaxTipWidth (const TOOLTIPS_INFO *infoPtr)
1318 {
1319 return infoPtr->nMaxTipWidth;
1320 }
1321
1322
1323 static LRESULT
1324 TOOLTIPS_GetTextT (const TOOLTIPS_INFO *infoPtr, TTTOOLINFOW *ti, BOOL isW)
1325 {
1326 INT nTool;
1327
1328 if (!ti) return 0;
1329 if (ti->cbSize < TTTOOLINFOW_V1_SIZE)
1330 return 0;
1331
1332 nTool = TOOLTIPS_GetToolFromInfoT (infoPtr, ti);
1333 if (nTool == -1) return 0;
1334
1335 if (infoPtr->tools[nTool].lpszText == NULL)
1336 return 0;
1337
1338 if (isW) {
1339 ti->lpszText[0] = '\0';
1340 TOOLTIPS_GetTipText(infoPtr, nTool, ti->lpszText);
1341 }
1342 else {
1343 WCHAR buffer[INFOTIPSIZE];
1344
1345 /* NB this API is broken, there is no way for the app to determine
1346 what size buffer it requires nor a way to specify how long the
1347 one it supplies is. According to the test result, it's up to
1348 80 bytes by the ANSI version. */
1349
1350 buffer[0] = '\0';
1351 TOOLTIPS_GetTipText(infoPtr, nTool, buffer);
1352 WideCharToMultiByte(CP_ACP, 0, buffer, -1, (LPSTR)ti->lpszText,
1353 MAX_TEXT_SIZE_A, NULL, NULL);
1354 }
1355
1356 return 0;
1357 }
1358
1359
1360 static inline LRESULT
1361 TOOLTIPS_GetTipBkColor (const TOOLTIPS_INFO *infoPtr)
1362 {
1363 return infoPtr->clrBk;
1364 }
1365
1366
1367 static inline LRESULT
1368 TOOLTIPS_GetTipTextColor (const TOOLTIPS_INFO *infoPtr)
1369 {
1370 return infoPtr->clrText;
1371 }
1372
1373
1374 static inline LRESULT
1375 TOOLTIPS_GetToolCount (const TOOLTIPS_INFO *infoPtr)
1376 {
1377 return infoPtr->uNumTools;
1378 }
1379
1380
1381 static LRESULT
1382 TOOLTIPS_GetToolInfoT (const TOOLTIPS_INFO *infoPtr, TTTOOLINFOW *ti, BOOL isW)
1383 {
1384 TTTOOL_INFO *toolPtr;
1385 INT nTool;
1386
1387 if (!ti) return FALSE;
1388 if (ti->cbSize < TTTOOLINFOW_V1_SIZE)
1389 return FALSE;
1390 if (infoPtr->uNumTools == 0)
1391 return FALSE;
1392
1393 nTool = TOOLTIPS_GetToolFromInfoT (infoPtr, ti);
1394 if (nTool == -1)
1395 return FALSE;
1396
1397 TRACE("tool %d\n", nTool);
1398
1399 toolPtr = &infoPtr->tools[nTool];
1400
1401 /* copy tool data */
1402 ti->uFlags = toolPtr->uFlags;
1403 ti->rect = toolPtr->rect;
1404 ti->hinst = toolPtr->hinst;
1405 TOOLTIPS_CopyInfoT (toolPtr, ti, isW);
1406
1407 if (ti->cbSize >= TTTOOLINFOW_V2_SIZE)
1408 ti->lParam = toolPtr->lParam;
1409
1410 return TRUE;
1411 }
1412
1413
1414 static LRESULT
1415 TOOLTIPS_HitTestT (const TOOLTIPS_INFO *infoPtr, LPTTHITTESTINFOW lptthit,
1416 BOOL isW)
1417 {
1418 TTTOOL_INFO *toolPtr;
1419 INT nTool;
1420
1421 if (lptthit == 0)
1422 return FALSE;
1423
1424 nTool = TOOLTIPS_GetToolFromPoint (infoPtr, lptthit->hwnd, &lptthit->pt);
1425 if (nTool == -1)
1426 return FALSE;
1427
1428 TRACE("tool %d!\n", nTool);
1429
1430 /* copy tool data */
1431 if (lptthit->ti.cbSize >= TTTOOLINFOW_V1_SIZE) {
1432 toolPtr = &infoPtr->tools[nTool];
1433
1434 lptthit->ti.uFlags = toolPtr->uFlags;
1435 lptthit->ti.hwnd = toolPtr->hwnd;
1436 lptthit->ti.uId = toolPtr->uId;
1437 lptthit->ti.rect = toolPtr->rect;
1438 lptthit->ti.hinst = toolPtr->hinst;
1439 TOOLTIPS_CopyInfoT (toolPtr, &lptthit->ti, isW);
1440 if (lptthit->ti.cbSize >= TTTOOLINFOW_V2_SIZE)
1441 lptthit->ti.lParam = toolPtr->lParam;
1442 }
1443
1444 return TRUE;
1445 }
1446
1447
1448 static LRESULT
1449 TOOLTIPS_NewToolRectT (TOOLTIPS_INFO *infoPtr, const TTTOOLINFOW *ti)
1450 {
1451 INT nTool;
1452
1453 if (!ti) return 0;
1454 if (ti->cbSize < TTTOOLINFOW_V1_SIZE)
1455 return FALSE;
1456
1457 nTool = TOOLTIPS_GetToolFromInfoT (infoPtr, ti);
1458
1459 TRACE("nTool = %d, rect = %s\n", nTool, wine_dbgstr_rect(&ti->rect));
1460
1461 if (nTool == -1) return 0;
1462
1463 infoPtr->tools[nTool].rect = ti->rect;
1464
1465 return 0;
1466 }
1467
1468
1469 static inline LRESULT
1470 TOOLTIPS_Pop (TOOLTIPS_INFO *infoPtr)
1471 {
1472 TOOLTIPS_Hide (infoPtr);
1473
1474 return 0;
1475 }
1476
1477
1478 static LRESULT
1479 TOOLTIPS_RelayEvent (TOOLTIPS_INFO *infoPtr, LPMSG lpMsg)
1480 {
1481 POINT pt;
1482 INT nOldTool;
1483
1484 if (!lpMsg) {
1485 ERR("lpMsg == NULL!\n");
1486 return 0;
1487 }
1488
1489 switch (lpMsg->message) {
1490 case WM_LBUTTONDOWN:
1491 case WM_LBUTTONUP:
1492 case WM_MBUTTONDOWN:
1493 case WM_MBUTTONUP:
1494 case WM_RBUTTONDOWN:
1495 case WM_RBUTTONUP:
1496 TOOLTIPS_Hide (infoPtr);
1497 break;
1498
1499 case WM_MOUSEMOVE:
1500 pt.x = (short)LOWORD(lpMsg->lParam);
1501 pt.y = (short)HIWORD(lpMsg->lParam);
1502 nOldTool = infoPtr->nTool;
1503 infoPtr->nTool = TOOLTIPS_GetToolFromPoint(infoPtr, lpMsg->hwnd,
1504 &pt);
1505 TRACE("tool (%p) %d %d %d\n", infoPtr->hwndSelf, nOldTool,
1506 infoPtr->nTool, infoPtr->nCurrentTool);
1507 TRACE("WM_MOUSEMOVE (%p %d %d)\n", infoPtr->hwndSelf, pt.x, pt.y);
1508
1509 if (infoPtr->nTool != nOldTool) {
1510 if(infoPtr->nTool == -1) { /* Moved out of all tools */
1511 TOOLTIPS_Hide(infoPtr);
1512 KillTimer(infoPtr->hwndSelf, ID_TIMERLEAVE);
1513 } else if (nOldTool == -1) { /* Moved from outside */
1514 if(infoPtr->bActive) {
1515 SetTimer(infoPtr->hwndSelf, ID_TIMERSHOW, infoPtr->nInitialTime, 0);
1516 TRACE("timer 1 started!\n");
1517 }
1518 } else { /* Moved from one to another */
1519 TOOLTIPS_Hide (infoPtr);
1520 KillTimer(infoPtr->hwndSelf, ID_TIMERLEAVE);
1521 if(infoPtr->bActive) {
1522 SetTimer (infoPtr->hwndSelf, ID_TIMERSHOW, infoPtr->nReshowTime, 0);
1523 TRACE("timer 1 started!\n");
1524 }
1525 }
1526 } else if(infoPtr->nCurrentTool != -1) { /* restart autopop */
1527 KillTimer(infoPtr->hwndSelf, ID_TIMERPOP);
1528 SetTimer(infoPtr->hwndSelf, ID_TIMERPOP, infoPtr->nAutoPopTime, 0);
1529 TRACE("timer 2 restarted\n");
1530 } else if(infoPtr->nTool != -1 && infoPtr->bActive) {
1531 /* previous show attempt didn't result in tooltip so try again */
1532 SetTimer(infoPtr->hwndSelf, ID_TIMERSHOW, infoPtr->nInitialTime, 0);
1533 TRACE("timer 1 started!\n");
1534 }
1535 break;
1536 }
1537
1538 return 0;
1539 }
1540
1541
1542 static LRESULT
1543 TOOLTIPS_SetDelayTime (TOOLTIPS_INFO *infoPtr, DWORD duration, INT nTime)
1544 {
1545 switch (duration) {
1546 case TTDT_AUTOMATIC:
1547 if (nTime <= 0)
1548 nTime = GetDoubleClickTime();
1549 infoPtr->nReshowTime = nTime / 5;
1550 infoPtr->nAutoPopTime = nTime * 10;
1551 infoPtr->nInitialTime = nTime;
1552 break;
1553
1554 case TTDT_RESHOW:
1555 if(nTime < 0)
1556 nTime = GetDoubleClickTime() / 5;
1557 infoPtr->nReshowTime = nTime;
1558 break;
1559
1560 case TTDT_AUTOPOP:
1561 if(nTime < 0)
1562 nTime = GetDoubleClickTime() * 10;
1563 infoPtr->nAutoPopTime = nTime;
1564 break;
1565
1566 case TTDT_INITIAL:
1567 if(nTime < 0)
1568 nTime = GetDoubleClickTime();
1569 infoPtr->nInitialTime = nTime;
1570 break;
1571
1572 default:
1573 WARN("Invalid duration flag %x\n", duration);
1574 break;
1575 }
1576
1577 return 0;
1578 }
1579
1580
1581 static LRESULT
1582 TOOLTIPS_SetMargin (TOOLTIPS_INFO *infoPtr, const RECT *lpRect)
1583 {
1584 infoPtr->rcMargin.left = lpRect->left;
1585 infoPtr->rcMargin.right = lpRect->right;
1586 infoPtr->rcMargin.bottom = lpRect->bottom;
1587 infoPtr->rcMargin.top = lpRect->top;
1588
1589 return 0;
1590 }
1591
1592
1593 static inline LRESULT
1594 TOOLTIPS_SetMaxTipWidth (TOOLTIPS_INFO *infoPtr, INT MaxWidth)
1595 {
1596 INT nTemp = infoPtr->nMaxTipWidth;
1597
1598 infoPtr->nMaxTipWidth = MaxWidth;
1599
1600 return nTemp;
1601 }
1602
1603
1604 static inline LRESULT
1605 TOOLTIPS_SetTipBkColor (TOOLTIPS_INFO *infoPtr, COLORREF clrBk)
1606 {
1607 infoPtr->clrBk = clrBk;
1608
1609 return 0;
1610 }
1611
1612
1613 static inline LRESULT
1614 TOOLTIPS_SetTipTextColor (TOOLTIPS_INFO *infoPtr, COLORREF clrText)
1615 {
1616 infoPtr->clrText = clrText;
1617
1618 return 0;
1619 }
1620
1621
1622 static LRESULT
1623 TOOLTIPS_SetTitleT (TOOLTIPS_INFO *infoPtr, UINT_PTR uTitleIcon, LPCWSTR pszTitle,
1624 BOOL isW)
1625 {
1626 UINT size;
1627
1628 TRACE("hwnd = %p, title = %s, icon = %p\n", infoPtr->hwndSelf, debugstr_w(pszTitle),
1629 (void*)uTitleIcon);
1630
1631 Free(infoPtr->pszTitle);
1632
1633 if (pszTitle)
1634 {
1635 if (isW)
1636 {
1637 size = (strlenW(pszTitle)+1)*sizeof(WCHAR);
1638 infoPtr->pszTitle = Alloc(size);
1639 if (!infoPtr->pszTitle)
1640 return FALSE;
1641 memcpy(infoPtr->pszTitle, pszTitle, size);
1642 }
1643 else
1644 {
1645 size = sizeof(WCHAR)*MultiByteToWideChar(CP_ACP, 0, (LPCSTR)pszTitle, -1, NULL, 0);
1646 infoPtr->pszTitle = Alloc(size);
1647 if (!infoPtr->pszTitle)
1648 return FALSE;
1649 MultiByteToWideChar(CP_ACP, 0, (LPCSTR)pszTitle, -1, infoPtr->pszTitle, size/sizeof(WCHAR));
1650 }
1651 }
1652 else
1653 infoPtr->pszTitle = NULL;
1654
1655 if (uTitleIcon <= TTI_ERROR)
1656 infoPtr->hTitleIcon = hTooltipIcons[uTitleIcon];
1657 else
1658 infoPtr->hTitleIcon = CopyIcon((HICON)uTitleIcon);
1659
1660 TRACE("icon = %p\n", infoPtr->hTitleIcon);
1661
1662 return TRUE;
1663 }
1664
1665
1666 static LRESULT
1667 TOOLTIPS_SetToolInfoT (TOOLTIPS_INFO *infoPtr, const TTTOOLINFOW *ti, BOOL isW)
1668 {
1669 TTTOOL_INFO *toolPtr;
1670 INT nTool;
1671
1672 if (!ti) return 0;
1673 if (ti->cbSize < TTTOOLINFOW_V1_SIZE)
1674 return 0;
1675
1676 nTool = TOOLTIPS_GetToolFromInfoT (infoPtr, ti);
1677 if (nTool == -1) return 0;
1678
1679 TRACE("tool %d\n", nTool);
1680
1681 toolPtr = &infoPtr->tools[nTool];
1682
1683 /* copy tool data */
1684 toolPtr->uFlags = ti->uFlags;
1685 toolPtr->hwnd = ti->hwnd;
1686 toolPtr->uId = ti->uId;
1687 toolPtr->rect = ti->rect;
1688 toolPtr->hinst = ti->hinst;
1689
1690 if (IS_INTRESOURCE(ti->lpszText)) {
1691 TRACE("set string id %x!\n", LOWORD(ti->lpszText));
1692 toolPtr->lpszText = ti->lpszText;
1693 }
1694 else {
1695 if (TOOLTIPS_IsCallbackString(ti->lpszText, isW))
1696 toolPtr->lpszText = LPSTR_TEXTCALLBACKW;
1697 else {
1698 if ( (toolPtr->lpszText) &&
1699 !IS_INTRESOURCE(toolPtr->lpszText) ) {
1700 if( toolPtr->lpszText != LPSTR_TEXTCALLBACKW)
1701 Free (toolPtr->lpszText);
1702 toolPtr->lpszText = NULL;
1703 }
1704 if (ti->lpszText) {
1705 if (isW) {
1706 INT len = lstrlenW (ti->lpszText);
1707 toolPtr->lpszText = Alloc ((len+1)*sizeof(WCHAR));
1708 strcpyW (toolPtr->lpszText, ti->lpszText);
1709 }
1710 else {
1711 INT len = MultiByteToWideChar(CP_ACP, 0, (LPSTR)ti->lpszText,
1712 -1, NULL, 0);
1713 toolPtr->lpszText = Alloc (len * sizeof(WCHAR));
1714 MultiByteToWideChar(CP_ACP, 0, (LPSTR)ti->lpszText, -1,
1715 toolPtr->lpszText, len);
1716 }
1717 }
1718 }
1719 }
1720
1721 if (ti->cbSize >= TTTOOLINFOW_V2_SIZE)
1722 toolPtr->lParam = ti->lParam;
1723
1724 if (infoPtr->nCurrentTool == nTool)
1725 {
1726 TOOLTIPS_GetTipText (infoPtr, infoPtr->nCurrentTool, infoPtr->szTipText);
1727
1728 if (infoPtr->szTipText[0] == 0)
1729 TOOLTIPS_Hide(infoPtr);
1730 else
1731 TOOLTIPS_Show (infoPtr, FALSE);
1732 }
1733
1734 return 0;
1735 }
1736
1737
1738 static LRESULT
1739 TOOLTIPS_TrackActivate (TOOLTIPS_INFO *infoPtr, BOOL track_activate, const TTTOOLINFOA *ti)
1740 {
1741 if (track_activate) {
1742
1743 if (!ti) return 0;
1744 if (ti->cbSize < TTTOOLINFOA_V1_SIZE)
1745 return FALSE;
1746
1747 /* activate */
1748 infoPtr->nTrackTool = TOOLTIPS_GetToolFromInfoT (infoPtr, (const TTTOOLINFOW*)ti);
1749 if (infoPtr->nTrackTool != -1) {
1750 TRACE("activated!\n");
1751 infoPtr->bTrackActive = TRUE;
1752 TOOLTIPS_TrackShow (infoPtr);
1753 }
1754 }
1755 else {
1756 /* deactivate */
1757 TOOLTIPS_TrackHide (infoPtr);
1758
1759 infoPtr->bTrackActive = FALSE;
1760 infoPtr->nTrackTool = -1;
1761
1762 TRACE("deactivated!\n");
1763 }
1764
1765 return 0;
1766 }
1767
1768
1769 static LRESULT
1770 TOOLTIPS_TrackPosition (TOOLTIPS_INFO *infoPtr, LPARAM coord)
1771 {
1772 infoPtr->xTrackPos = (INT)LOWORD(coord);
1773 infoPtr->yTrackPos = (INT)HIWORD(coord);
1774
1775 if (infoPtr->bTrackActive) {
1776 TRACE("[%d %d]\n",
1777 infoPtr->xTrackPos, infoPtr->yTrackPos);
1778
1779 TOOLTIPS_TrackShow (infoPtr);
1780 }
1781
1782 return 0;
1783 }
1784
1785
1786 static LRESULT
1787 TOOLTIPS_Update (TOOLTIPS_INFO *infoPtr)
1788 {
1789 if (infoPtr->nCurrentTool != -1)
1790 UpdateWindow (infoPtr->hwndSelf);
1791
1792 return 0;
1793 }
1794
1795
1796 static LRESULT
1797 TOOLTIPS_UpdateTipTextT (TOOLTIPS_INFO *infoPtr, const TTTOOLINFOW *ti, BOOL isW)
1798 {
1799 TTTOOL_INFO *toolPtr;
1800 INT nTool;
1801
1802 if (!ti) return 0;
1803 if (ti->cbSize < TTTOOLINFOW_V1_SIZE)
1804 return FALSE;
1805
1806 nTool = TOOLTIPS_GetToolFromInfoT (infoPtr, ti);
1807 if (nTool == -1)
1808 return 0;
1809
1810 TRACE("tool %d\n", nTool);
1811
1812 toolPtr = &infoPtr->tools[nTool];
1813
1814 /* copy tool text */
1815 toolPtr->hinst = ti->hinst;
1816
1817 if (IS_INTRESOURCE(ti->lpszText)){
1818 toolPtr->lpszText = ti->lpszText;
1819 }
1820 else if (ti->lpszText) {
1821 if (TOOLTIPS_IsCallbackString(ti->lpszText, isW))
1822 toolPtr->lpszText = LPSTR_TEXTCALLBACKW;
1823 else {
1824 if ( (toolPtr->lpszText) &&
1825 !IS_INTRESOURCE(toolPtr->lpszText) ) {
1826 if( toolPtr->lpszText != LPSTR_TEXTCALLBACKW)
1827 Free (toolPtr->lpszText);
1828 toolPtr->lpszText = NULL;
1829 }
1830 if (ti->lpszText) {
1831 if (isW) {
1832 INT len = lstrlenW (ti->lpszText);
1833 toolPtr->lpszText = Alloc ((len+1)*sizeof(WCHAR));
1834 strcpyW (toolPtr->lpszText, ti->lpszText);
1835 }
1836 else {
1837 INT len = MultiByteToWideChar(CP_ACP, 0, (LPSTR)ti->lpszText,
1838 -1, NULL, 0);
1839 toolPtr->lpszText = Alloc (len * sizeof(WCHAR));
1840 MultiByteToWideChar(CP_ACP, 0, (LPSTR)ti->lpszText, -1,
1841 toolPtr->lpszText, len);
1842 }
1843 }
1844 }
1845 }
1846
1847 if(infoPtr->nCurrentTool == -1) return 0;
1848 /* force repaint */
1849 if (infoPtr->bActive)
1850 TOOLTIPS_Show (infoPtr, FALSE);
1851 else if (infoPtr->bTrackActive)
1852 TOOLTIPS_Show (infoPtr, TRUE);
1853
1854 return 0;
1855 }
1856
1857
1858 static LRESULT
1859 TOOLTIPS_Create (HWND hwnd)
1860 {
1861 TOOLTIPS_INFO *infoPtr;
1862
1863 /* allocate memory for info structure */
1864 infoPtr = Alloc (sizeof(TOOLTIPS_INFO));
1865 SetWindowLongPtrW (hwnd, 0, (DWORD_PTR)infoPtr);
1866
1867 /* initialize info structure */
1868 infoPtr->bActive = TRUE;
1869 infoPtr->bTrackActive = FALSE;
1870
1871 infoPtr->nMaxTipWidth = -1;
1872 infoPtr->nTool = -1;
1873 infoPtr->nCurrentTool = -1;
1874 infoPtr->nTrackTool = -1;
1875 infoPtr->hwndSelf = hwnd;
1876
1877 /* initialize colours and fonts */
1878 TOOLTIPS_InitSystemSettings(infoPtr);
1879
1880 TOOLTIPS_SetDelayTime(infoPtr, TTDT_AUTOMATIC, 0);
1881
1882 SetWindowPos (hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOZORDER | SWP_HIDEWINDOW | SWP_NOACTIVATE);
1883
1884 return 0;
1885 }
1886
1887
1888 static LRESULT
1889 TOOLTIPS_Destroy (TOOLTIPS_INFO *infoPtr)
1890 {
1891 TTTOOL_INFO *toolPtr;
1892 UINT i;
1893
1894 /* free tools */
1895 if (infoPtr->tools) {
1896 for (i = 0; i < infoPtr->uNumTools; i++) {
1897 toolPtr = &infoPtr->tools[i];
1898 if (toolPtr->lpszText) {
1899 if ( (toolPtr->lpszText != LPSTR_TEXTCALLBACKW) &&
1900 !IS_INTRESOURCE(toolPtr->lpszText) )
1901 {
1902 Free (toolPtr->lpszText);
1903 toolPtr->lpszText = NULL;
1904 }
1905 }
1906
1907 /* remove subclassing */
1908 if (toolPtr->uFlags & TTF_SUBCLASS) {
1909 if (toolPtr->uFlags & TTF_IDISHWND) {
1910 RemoveWindowSubclass((HWND)toolPtr->uId, TOOLTIPS_SubclassProc, 1);
1911 }
1912 else {
1913 RemoveWindowSubclass(toolPtr->hwnd, TOOLTIPS_SubclassProc, 1);
1914 }
1915 }
1916 }
1917 Free (infoPtr->tools);
1918 }
1919
1920 /* free title string */
1921 Free (infoPtr->pszTitle);
1922 /* free title icon if not a standard one */
1923 if (TOOLTIPS_GetTitleIconIndex(infoPtr->hTitleIcon) > TTI_ERROR)
1924 DeleteObject(infoPtr->hTitleIcon);
1925
1926 /* delete fonts */
1927 DeleteObject (infoPtr->hFont);
1928 DeleteObject (infoPtr->hTitleFont);
1929
1930 /* free tool tips info data */
1931 SetWindowLongPtrW(infoPtr->hwndSelf, 0, 0);
1932 Free (infoPtr);
1933
1934 return 0;
1935 }
1936
1937
1938 static inline LRESULT
1939 TOOLTIPS_GetFont (const TOOLTIPS_INFO *infoPtr)
1940 {
1941 return (LRESULT)infoPtr->hFont;
1942 }
1943
1944
1945 static LRESULT
1946 TOOLTIPS_MouseMessage (TOOLTIPS_INFO *infoPtr)
1947 {
1948 TOOLTIPS_Hide (infoPtr);
1949
1950 return 0;
1951 }
1952
1953
1954 static LRESULT
1955 TOOLTIPS_NCCreate (HWND hwnd)
1956 {
1957 DWORD dwStyle = GetWindowLongW (hwnd, GWL_STYLE);
1958 DWORD dwExStyle = GetWindowLongW (hwnd, GWL_EXSTYLE);
1959
1960 dwStyle &= ~(WS_CHILD | /*WS_MAXIMIZE |*/ WS_BORDER | WS_DLGFRAME);
1961 dwStyle |= (WS_POPUP | WS_BORDER | WS_CLIPSIBLINGS);
1962
1963 /* WS_BORDER only draws a border round the window rect, not the
1964 * window region, therefore it is useless to us in balloon mode */
1965 if (dwStyle & TTS_BALLOON) dwStyle &= ~WS_BORDER;
1966
1967 SetWindowLongW (hwnd, GWL_STYLE, dwStyle);
1968
1969 dwExStyle |= WS_EX_TOOLWINDOW;
1970 SetWindowLongW (hwnd, GWL_EXSTYLE, dwExStyle);
1971
1972 return TRUE;
1973 }
1974
1975
1976 static LRESULT
1977 TOOLTIPS_NCHitTest (const TOOLTIPS_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
1978 {
1979 INT nTool = (infoPtr->bTrackActive) ? infoPtr->nTrackTool : infoPtr->nTool;
1980
1981 TRACE(" nTool=%d\n", nTool);
1982
1983 if ((nTool > -1) && (nTool < infoPtr->uNumTools)) {
1984 if (infoPtr->tools[nTool].uFlags & TTF_TRANSPARENT) {
1985 TRACE("-- in transparent mode!\n");
1986 return HTTRANSPARENT;
1987 }
1988 }
1989
1990 return DefWindowProcW (infoPtr->hwndSelf, WM_NCHITTEST, wParam, lParam);
1991 }
1992
1993
1994 static LRESULT
1995 TOOLTIPS_NotifyFormat (TOOLTIPS_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
1996 {
1997 TTTOOL_INFO *toolPtr = infoPtr->tools;
1998 LRESULT nResult;
1999
2000 TRACE("infoPtr=%p wParam=%lx lParam=%p\n", infoPtr, wParam, (PVOID)lParam);
2001
2002 if (lParam == NF_QUERY) {
2003 if (toolPtr->bNotifyUnicode) {
2004 return NFR_UNICODE;
2005 } else {
2006 return NFR_ANSI;
2007 }
2008 }
2009 else if (lParam == NF_REQUERY) {
2010 nResult = SendMessageW (toolPtr->hwnd, WM_NOTIFYFORMAT,
2011 (WPARAM)infoPtr->hwndSelf, (LPARAM)NF_QUERY);
2012 if (nResult == NFR_ANSI) {
2013 toolPtr->bNotifyUnicode = FALSE;
2014 TRACE(" -- WM_NOTIFYFORMAT returns: NFR_ANSI\n");
2015 } else if (nResult == NFR_UNICODE) {
2016 toolPtr->bNotifyUnicode = TRUE;
2017 TRACE(" -- WM_NOTIFYFORMAT returns: NFR_UNICODE\n");
2018 } else {
2019 TRACE (" -- WM_NOTIFYFORMAT returns: error!\n");
2020 }
2021 return nResult;
2022 }
2023
2024 return 0;
2025 }
2026
2027
2028 static LRESULT
2029 TOOLTIPS_Paint (const TOOLTIPS_INFO *infoPtr, HDC hDC)
2030 {
2031 HDC hdc;
2032 PAINTSTRUCT ps;
2033
2034 hdc = (hDC == NULL) ? BeginPaint (infoPtr->hwndSelf, &ps) : hDC;
2035 TOOLTIPS_Refresh (infoPtr, hdc);
2036 if (!hDC)
2037 EndPaint (infoPtr->hwndSelf, &ps);
2038 return 0;
2039 }
2040
2041
2042 static LRESULT
2043 TOOLTIPS_SetFont (TOOLTIPS_INFO *infoPtr, HFONT hFont, BOOL redraw)
2044 {
2045 LOGFONTW lf;
2046
2047 if(!GetObjectW(hFont, sizeof(lf), &lf))
2048 return 0;
2049
2050 DeleteObject (infoPtr->hFont);
2051 infoPtr->hFont = CreateFontIndirectW(&lf);
2052
2053 DeleteObject (infoPtr->hTitleFont);
2054 lf.lfWeight = FW_BOLD;
2055 infoPtr->hTitleFont = CreateFontIndirectW(&lf);
2056
2057 if (redraw && infoPtr->nCurrentTool != -1) {
2058 FIXME("full redraw needed!\n");
2059 }
2060
2061 return 0;
2062 }
2063
2064 /******************************************************************
2065 * TOOLTIPS_GetTextLength
2066 *
2067 * This function is called when the tooltip receive a
2068 * WM_GETTEXTLENGTH message.
2069 *
2070 * returns the length, in characters, of the tip text
2071 */
2072 static inline LRESULT
2073 TOOLTIPS_GetTextLength(const TOOLTIPS_INFO *infoPtr)
2074 {
2075 return strlenW(infoPtr->szTipText);
2076 }
2077
2078 /******************************************************************
2079 * TOOLTIPS_OnWMGetText
2080 *
2081 * This function is called when the tooltip receive a
2082 * WM_GETTEXT message.
2083 * wParam : specifies the maximum number of characters to be copied
2084 * lParam : is the pointer to the buffer that will receive
2085 * the tip text
2086 *
2087 * returns the number of characters copied
2088 */
2089 static LRESULT
2090 TOOLTIPS_OnWMGetText (const TOOLTIPS_INFO *infoPtr, WPARAM size, LPWSTR pszText)
2091 {
2092 LRESULT res;
2093
2094 if(!size)
2095 return 0;
2096
2097 res = min(strlenW(infoPtr->szTipText)+1, size);
2098 memcpy(pszText, infoPtr->szTipText, res*sizeof(WCHAR));
2099 pszText[res-1] = '\0';
2100 return res-1;
2101 }
2102
2103 static LRESULT
2104 TOOLTIPS_Timer (TOOLTIPS_INFO *infoPtr, INT iTimer)
2105 {
2106 INT nOldTool;
2107
2108 TRACE("timer %d (%p) expired!\n", iTimer, infoPtr->hwndSelf);
2109
2110 switch (iTimer) {
2111 case ID_TIMERSHOW:
2112 KillTimer (infoPtr->hwndSelf, ID_TIMERSHOW);
2113 nOldTool = infoPtr->nTool;
2114 if ((infoPtr->nTool = TOOLTIPS_CheckTool (infoPtr, TRUE)) == nOldTool)
2115 TOOLTIPS_Show (infoPtr, FALSE);
2116 break;
2117
2118 case ID_TIMERPOP:
2119 TOOLTIPS_Hide (infoPtr);
2120 break;
2121
2122 case ID_TIMERLEAVE:
2123 nOldTool = infoPtr->nTool;
2124 infoPtr->nTool = TOOLTIPS_CheckTool (infoPtr, FALSE);
2125 TRACE("tool (%p) %d %d %d\n", infoPtr->hwndSelf, nOldTool,
2126 infoPtr->nTool, infoPtr->nCurrentTool);
2127 if (infoPtr->nTool != nOldTool) {
2128 if(infoPtr->nTool == -1) { /* Moved out of all tools */
2129 TOOLTIPS_Hide(infoPtr);
2130 KillTimer(infoPtr->hwndSelf, ID_TIMERLEAVE);
2131 } else if (nOldTool == -1) { /* Moved from outside */
2132 ERR("How did this happen?\n");
2133 } else { /* Moved from one to another */
2134 TOOLTIPS_Hide (infoPtr);
2135 KillTimer(infoPtr->hwndSelf, ID_TIMERLEAVE);
2136 if(infoPtr->bActive) {
2137 SetTimer (infoPtr->hwndSelf, ID_TIMERSHOW, infoPtr->nReshowTime, 0);
2138 TRACE("timer 1 started!\n");
2139 }
2140 }
2141 }
2142 break;
2143
2144 default:
2145 ERR("Unknown timer id %d\n", iTimer);
2146 break;
2147 }
2148 return 0;
2149 }
2150
2151
2152 static LRESULT
2153 TOOLTIPS_WinIniChange (TOOLTIPS_INFO *infoPtr)
2154 {
2155 TOOLTIPS_InitSystemSettings (infoPtr);
2156
2157 return 0;
2158 }
2159
2160
2161 static LRESULT CALLBACK
2162 TOOLTIPS_SubclassProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uID, DWORD_PTR dwRef)
2163 {
2164 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr ((HWND)dwRef);
2165 MSG msg;
2166
2167 switch(uMsg) {
2168 case WM_MOUSEMOVE:
2169 case WM_LBUTTONDOWN:
2170 case WM_LBUTTONUP:
2171 case WM_MBUTTONDOWN:
2172 case WM_MBUTTONUP:
2173 case WM_RBUTTONDOWN:
2174 case WM_RBUTTONUP:
2175 msg.hwnd = hwnd;
2176 msg.message = uMsg;
2177 msg.wParam = wParam;
2178 msg.lParam = lParam;
2179 TOOLTIPS_RelayEvent(infoPtr, &msg);
2180 break;
2181
2182 default:
2183 break;
2184 }
2185 return DefSubclassProc(hwnd, uMsg, wParam, lParam);
2186 }
2187
2188
2189 static LRESULT CALLBACK
2190 TOOLTIPS_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2191 {
2192 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
2193
2194 TRACE("hwnd=%p msg=%x wparam=%lx lParam=%lx\n", hwnd, uMsg, wParam, lParam);
2195 if (!infoPtr && (uMsg != WM_CREATE) && (uMsg != WM_NCCREATE))
2196 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
2197 switch (uMsg)
2198 {
2199 case TTM_ACTIVATE:
2200 return TOOLTIPS_Activate (infoPtr, (BOOL)wParam);
2201
2202 case TTM_ADDTOOLA:
2203 case TTM_ADDTOOLW:
2204 return TOOLTIPS_AddToolT (infoPtr, (LPTTTOOLINFOW)lParam, uMsg == TTM_ADDTOOLW);
2205
2206 case TTM_DELTOOLA:
2207 case TTM_DELTOOLW:
2208 return TOOLTIPS_DelToolT (infoPtr, (LPTOOLINFOW)lParam,
2209 uMsg == TTM_DELTOOLW);
2210 case TTM_ENUMTOOLSA:
2211 case TTM_ENUMTOOLSW:
2212 return TOOLTIPS_EnumToolsT (infoPtr, (UINT)wParam, (LPTTTOOLINFOW)lParam,
2213 uMsg == TTM_ENUMTOOLSW);
2214 case TTM_GETBUBBLESIZE:
2215 return TOOLTIPS_GetBubbleSize (infoPtr, (LPTTTOOLINFOW)lParam);
2216
2217 case TTM_GETCURRENTTOOLA:
2218 case TTM_GETCURRENTTOOLW:
2219 return TOOLTIPS_GetCurrentToolT (infoPtr, (LPTTTOOLINFOW)lParam,
2220 uMsg == TTM_GETCURRENTTOOLW);
2221
2222 case TTM_GETDELAYTIME:
2223 return TOOLTIPS_GetDelayTime (infoPtr, (DWORD)wParam);
2224
2225 case TTM_GETMARGIN:
2226 return TOOLTIPS_GetMargin (infoPtr, (LPRECT)lParam);
2227
2228 case TTM_GETMAXTIPWIDTH:
2229 return TOOLTIPS_GetMaxTipWidth (infoPtr);
2230
2231 case TTM_GETTEXTA:
2232 case TTM_GETTEXTW:
2233 return TOOLTIPS_GetTextT (infoPtr, (LPTTTOOLINFOW)lParam,
2234 uMsg == TTM_GETTEXTW);
2235
2236 case TTM_GETTIPBKCOLOR:
2237 return TOOLTIPS_GetTipBkColor (infoPtr);
2238
2239 case TTM_GETTIPTEXTCOLOR:
2240 return TOOLTIPS_GetTipTextColor (infoPtr);
2241
2242 case TTM_GETTOOLCOUNT:
2243 return TOOLTIPS_GetToolCount (infoPtr);
2244
2245 case TTM_GETTOOLINFOA:
2246 case TTM_GETTOOLINFOW:
2247 return TOOLTIPS_GetToolInfoT (infoPtr, (LPTTTOOLINFOW)lParam,
2248 uMsg == TTM_GETTOOLINFOW);
2249
2250 case TTM_HITTESTA:
2251 case TTM_HITTESTW:
2252 return TOOLTIPS_HitTestT (infoPtr, (LPTTHITTESTINFOW)lParam,
2253 uMsg == TTM_HITTESTW);
2254 case TTM_NEWTOOLRECTA:
2255 case TTM_NEWTOOLRECTW:
2256 return TOOLTIPS_NewToolRectT (infoPtr, (LPTTTOOLINFOW)lParam);
2257
2258 case TTM_POP:
2259 return TOOLTIPS_Pop (infoPtr);
2260
2261 case TTM_RELAYEVENT:
2262 return TOOLTIPS_RelayEvent (infoPtr, (LPMSG)lParam);
2263
2264 case TTM_SETDELAYTIME:
2265 return TOOLTIPS_SetDelayTime (infoPtr, (DWORD)wParam, (INT)LOWORD(lParam));
2266
2267 case TTM_SETMARGIN:
2268 return TOOLTIPS_SetMargin (infoPtr, (LPRECT)lParam);
2269
2270 case TTM_SETMAXTIPWIDTH:
2271 return TOOLTIPS_SetMaxTipWidth (infoPtr, (INT)lParam);
2272
2273 case TTM_SETTIPBKCOLOR:
2274 return TOOLTIPS_SetTipBkColor (infoPtr, (COLORREF)wParam);
2275
2276 case TTM_SETTIPTEXTCOLOR:
2277 return TOOLTIPS_SetTipTextColor (infoPtr, (COLORREF)wParam);
2278
2279 case TTM_SETTITLEA:
2280 case TTM_SETTITLEW:
2281 return TOOLTIPS_SetTitleT (infoPtr, (UINT_PTR)wParam, (LPCWSTR)lParam,
2282 uMsg == TTM_SETTITLEW);
2283
2284 case TTM_SETTOOLINFOA:
2285 case TTM_SETTOOLINFOW:
2286 return TOOLTIPS_SetToolInfoT (infoPtr, (LPTTTOOLINFOW)lParam,
2287 uMsg == TTM_SETTOOLINFOW);
2288
2289 case TTM_TRACKACTIVATE:
2290 return TOOLTIPS_TrackActivate (infoPtr, (BOOL)wParam, (LPTTTOOLINFOA)lParam);
2291
2292 case TTM_TRACKPOSITION:
2293 return TOOLTIPS_TrackPosition (infoPtr, lParam);
2294
2295 case TTM_UPDATE:
2296 return TOOLTIPS_Update (infoPtr);
2297
2298 case TTM_UPDATETIPTEXTA:
2299 case TTM_UPDATETIPTEXTW:
2300 return TOOLTIPS_UpdateTipTextT (infoPtr, (LPTTTOOLINFOW)lParam,
2301 uMsg == TTM_UPDATETIPTEXTW);
2302
2303 case TTM_WINDOWFROMPOINT:
2304 return (LRESULT)WindowFromPoint (*((LPPOINT)lParam));
2305
2306 case WM_CREATE:
2307 return TOOLTIPS_Create (hwnd);
2308
2309 case WM_DESTROY:
2310 return TOOLTIPS_Destroy (infoPtr);
2311
2312 case WM_ERASEBKGND:
2313 /* we draw the background in WM_PAINT */
2314 return 0;
2315
2316 case WM_GETFONT:
2317 return TOOLTIPS_GetFont (infoPtr);
2318
2319 case WM_GETTEXT:
2320 return TOOLTIPS_OnWMGetText (infoPtr, wParam, (LPWSTR)lParam);
2321
2322 case WM_GETTEXTLENGTH:
2323 return TOOLTIPS_GetTextLength (infoPtr);
2324
2325 case WM_LBUTTONDOWN:
2326 case WM_LBUTTONUP:
2327 case WM_MBUTTONDOWN:
2328 case WM_MBUTTONUP:
2329 case WM_RBUTTONDOWN:
2330 case WM_RBUTTONUP:
2331 case WM_MOUSEMOVE:
2332 return TOOLTIPS_MouseMessage (infoPtr);
2333
2334 case WM_NCCREATE:
2335 return TOOLTIPS_NCCreate (hwnd);
2336
2337 case WM_NCHITTEST:
2338 return TOOLTIPS_NCHitTest (infoPtr, wParam, lParam);
2339
2340 case WM_NOTIFYFORMAT:
2341 return TOOLTIPS_NotifyFormat (infoPtr, wParam, lParam);
2342
2343 case WM_PRINTCLIENT:
2344 case WM_PAINT:
2345 return TOOLTIPS_Paint (infoPtr, (HDC)wParam);
2346
2347 case WM_SETFONT:
2348 return TOOLTIPS_SetFont (infoPtr, (HFONT)wParam, LOWORD(lParam));
2349
2350 case WM_SYSCOLORCHANGE:
2351 COMCTL32_RefreshSysColors();
2352 return 0;
2353
2354 case WM_TIMER:
2355 return TOOLTIPS_Timer (infoPtr, (INT)wParam);
2356
2357 case WM_WININICHANGE:
2358 return TOOLTIPS_WinIniChange (infoPtr);
2359
2360 default:
2361 if ((uMsg >= WM_USER) && (uMsg < WM_APP) && !COMCTL32_IsReflectedMessage(uMsg))
2362 ERR("unknown msg %04x wp=%08lx lp=%08lx\n",
2363 uMsg, wParam, lParam);
2364 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
2365 }
2366 }
2367
2368
2369 VOID
2370 TOOLTIPS_Register (void)
2371 {
2372 WNDCLASSW wndClass;
2373
2374 ZeroMemory (&wndClass, sizeof(WNDCLASSW));
2375 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS | CS_SAVEBITS;
2376 wndClass.lpfnWndProc = TOOLTIPS_WindowProc;
2377 wndClass.cbClsExtra = 0;
2378 wndClass.cbWndExtra = sizeof(TOOLTIPS_INFO *);
2379 wndClass.hCursor = LoadCursorW (0, (LPWSTR)IDC_ARROW);
2380 wndClass.hbrBackground = 0;
2381 wndClass.lpszClassName = TOOLTIPS_CLASSW;
2382
2383 RegisterClassW (&wndClass);
2384
2385 hTooltipIcons[TTI_NONE] = NULL;
2386 hTooltipIcons[TTI_INFO] = LoadImageW(COMCTL32_hModule,
2387 (LPCWSTR)MAKEINTRESOURCE(IDI_TT_INFO_SM), IMAGE_ICON, 0, 0, 0);
2388 hTooltipIcons[TTI_WARNING] = LoadImageW(COMCTL32_hModule,
2389 (LPCWSTR)MAKEINTRESOURCE(IDI_TT_WARN_SM), IMAGE_ICON, 0, 0, 0);
2390 hTooltipIcons[TTI_ERROR] = LoadImageW(COMCTL32_hModule,
2391 (LPCWSTR)MAKEINTRESOURCE(IDI_TT_ERROR_SM), IMAGE_ICON, 0, 0, 0);
2392 }
2393
2394
2395 VOID
2396 TOOLTIPS_Unregister (void)
2397 {
2398 int i;
2399 for (i = TTI_INFO; i <= TTI_ERROR; i++)
2400 DestroyIcon(hTooltipIcons[i]);
2401 UnregisterClassW (TOOLTIPS_CLASSW, NULL);
2402 }