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