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