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