cmd: Fix German translation.
[wine/hramrach.git] / dlls / comctl32 / tooltips.c
blob54600e81c8774265b4818c6f97cd4c482a08c802
1 /*
2 * Tool tip control
4 * Copyright 1998, 1999 Eric Kohl
5 * Copyright 2004 Robert Shearman
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.
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.
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
21 * NOTES
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.
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.
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
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.
50 * Timer logic.
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.
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.
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.
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.
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.
94 #include <stdarg.h>
95 #include <string.h>
97 #include "windef.h"
98 #include "winbase.h"
99 #include "wine/unicode.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"
107 WINE_DEFAULT_DEBUG_CHANNEL(tooltips);
109 static HICON hTooltipIcons[TTI_ERROR+1];
111 typedef struct
113 UINT uFlags;
114 HWND hwnd;
115 BOOL bNotifyUnicode;
116 UINT_PTR uId;
117 RECT rect;
118 HINSTANCE hinst;
119 LPWSTR lpszText;
120 LPARAM lParam;
121 } TTTOOL_INFO;
124 typedef struct
126 HWND hwndSelf;
127 WCHAR szTipText[INFOTIPSIZE];
128 BOOL bActive;
129 BOOL bTrackActive;
130 UINT uNumTools;
131 COLORREF clrBk;
132 COLORREF clrText;
133 HFONT hFont;
134 HFONT hTitleFont;
135 INT xTrackPos;
136 INT yTrackPos;
137 INT nMaxTipWidth;
138 INT nTool; /* tool that mouse was on on last relayed mouse move */
139 INT nCurrentTool;
140 INT nTrackTool;
141 INT nReshowTime;
142 INT nAutoPopTime;
143 INT nInitialTime;
144 RECT rcMargin;
145 BOOL bToolBelow;
146 LPWSTR pszTitle;
147 HICON hTitleIcon;
149 TTTOOL_INFO *tools;
150 } TOOLTIPS_INFO;
152 #define ID_TIMERSHOW 1 /* show delay timer */
153 #define ID_TIMERPOP 2 /* auto pop timer */
154 #define ID_TIMERLEAVE 3 /* tool leave timer */
157 #define TOOLTIPS_GetInfoPtr(hWindow) ((TOOLTIPS_INFO *)GetWindowLongPtrW (hWindow, 0))
159 /* offsets from window edge to start of text */
160 #define NORMAL_TEXT_MARGIN 2
161 #define BALLOON_TEXT_MARGIN (NORMAL_TEXT_MARGIN+8)
162 /* value used for CreateRoundRectRgn that specifies how much
163 * each corner is curved */
164 #define BALLOON_ROUNDEDNESS 20
165 #define BALLOON_STEMHEIGHT 13
166 #define BALLOON_STEMWIDTH 10
167 #define BALLOON_STEMINDENT 20
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
174 static LRESULT CALLBACK
175 TOOLTIPS_SubclassProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uId, DWORD_PTR dwRef);
178 static inline UINT_PTR
179 TOOLTIPS_GetTitleIconIndex(HICON hIcon)
181 UINT i;
182 for (i = 0; i <= TTI_ERROR; i++)
183 if (hTooltipIcons[i] == hIcon)
184 return i;
185 return (UINT_PTR)hIcon;
188 static void
189 TOOLTIPS_InitSystemSettings (TOOLTIPS_INFO *infoPtr)
191 NONCLIENTMETRICSW nclm;
193 infoPtr->clrBk = comctl32_color.clrInfoBk;
194 infoPtr->clrText = comctl32_color.clrInfoText;
196 DeleteObject (infoPtr->hFont);
197 nclm.cbSize = sizeof(nclm);
198 SystemParametersInfoW (SPI_GETNONCLIENTMETRICS, sizeof(nclm), &nclm, 0);
199 infoPtr->hFont = CreateFontIndirectW (&nclm.lfStatusFont);
201 DeleteObject (infoPtr->hTitleFont);
202 nclm.lfStatusFont.lfWeight = FW_BOLD;
203 infoPtr->hTitleFont = CreateFontIndirectW (&nclm.lfStatusFont);
206 /* Custom draw routines */
207 static void
208 TOOLTIPS_customdraw_fill(NMTTCUSTOMDRAW *lpnmttcd,
209 const HWND hwnd,
210 HDC hdc, const RECT *rcBounds, UINT uFlags)
212 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr(hwnd);
214 ZeroMemory(lpnmttcd, sizeof(NMTTCUSTOMDRAW));
215 lpnmttcd->uDrawFlags = uFlags;
216 lpnmttcd->nmcd.hdr.hwndFrom = hwnd;
217 lpnmttcd->nmcd.hdr.code = NM_CUSTOMDRAW;
218 if (infoPtr->nCurrentTool != -1) {
219 TTTOOL_INFO *toolPtr = &infoPtr->tools[infoPtr->nCurrentTool];
220 lpnmttcd->nmcd.hdr.idFrom = toolPtr->uId;
222 lpnmttcd->nmcd.hdc = hdc;
223 lpnmttcd->nmcd.rc = *rcBounds;
224 /* FIXME - dwItemSpec, uItemState, lItemlParam */
227 static inline DWORD
228 TOOLTIPS_notify_customdraw (DWORD dwDrawStage, NMTTCUSTOMDRAW *lpnmttcd)
230 LRESULT result = CDRF_DODEFAULT;
231 lpnmttcd->nmcd.dwDrawStage = dwDrawStage;
233 TRACE("Notifying stage %d, flags %x, id %x\n", lpnmttcd->nmcd.dwDrawStage,
234 lpnmttcd->uDrawFlags, lpnmttcd->nmcd.hdr.code);
236 result = SendMessageW(GetParent(lpnmttcd->nmcd.hdr.hwndFrom), WM_NOTIFY,
237 0, (LPARAM)lpnmttcd);
239 TRACE("Notify result %x\n", (unsigned int)result);
241 return result;
244 static void
245 TOOLTIPS_Refresh (const TOOLTIPS_INFO *infoPtr, HDC hdc)
247 RECT rc;
248 INT oldBkMode;
249 HFONT hOldFont;
250 HBRUSH hBrush;
251 UINT uFlags = DT_EXTERNALLEADING;
252 HRGN hRgn = NULL;
253 DWORD dwStyle = GetWindowLongW(infoPtr->hwndSelf, GWL_STYLE);
254 NMTTCUSTOMDRAW nmttcd;
255 DWORD cdmode;
257 if (infoPtr->nMaxTipWidth > -1)
258 uFlags |= DT_WORDBREAK;
259 if (GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE) & TTS_NOPREFIX)
260 uFlags |= DT_NOPREFIX;
261 GetClientRect (infoPtr->hwndSelf, &rc);
263 hBrush = CreateSolidBrush(infoPtr->clrBk);
265 oldBkMode = SetBkMode (hdc, TRANSPARENT);
266 SetTextColor (hdc, infoPtr->clrText);
267 hOldFont = SelectObject (hdc, infoPtr->hFont);
269 /* Custom draw - Call PrePaint once initial properties set up */
270 /* Note: Contrary to MSDN, CDRF_SKIPDEFAULT still draws a tooltip */
271 TOOLTIPS_customdraw_fill(&nmttcd, infoPtr->hwndSelf, hdc, &rc, uFlags);
272 cdmode = TOOLTIPS_notify_customdraw(CDDS_PREPAINT, &nmttcd);
273 uFlags = nmttcd.uDrawFlags;
275 if (dwStyle & TTS_BALLOON)
277 /* create a region to store result into */
278 hRgn = CreateRectRgn(0, 0, 0, 0);
280 GetWindowRgn(infoPtr->hwndSelf, hRgn);
282 /* fill the background */
283 FillRgn(hdc, hRgn, hBrush);
284 DeleteObject(hBrush);
285 hBrush = NULL;
287 else
289 /* fill the background */
290 FillRect(hdc, &rc, hBrush);
291 DeleteObject(hBrush);
292 hBrush = NULL;
295 if ((dwStyle & TTS_BALLOON) || infoPtr->pszTitle)
297 /* calculate text rectangle */
298 rc.left += (BALLOON_TEXT_MARGIN + infoPtr->rcMargin.left);
299 rc.top += (BALLOON_TEXT_MARGIN + infoPtr->rcMargin.top);
300 rc.right -= (BALLOON_TEXT_MARGIN + infoPtr->rcMargin.right);
301 rc.bottom -= (BALLOON_TEXT_MARGIN + infoPtr->rcMargin.bottom);
302 if(infoPtr->bToolBelow) rc.top += BALLOON_STEMHEIGHT;
304 if (infoPtr->pszTitle)
306 RECT rcTitle = {rc.left, rc.top, rc.right, rc.bottom};
307 int height;
308 BOOL icon_present;
309 HFONT prevFont;
311 /* draw icon */
312 icon_present = infoPtr->hTitleIcon &&
313 DrawIconEx(hdc, rc.left, rc.top, infoPtr->hTitleIcon,
314 ICON_WIDTH, ICON_HEIGHT, 0, NULL, DI_NORMAL);
315 if (icon_present)
316 rcTitle.left += ICON_WIDTH + BALLOON_ICON_TITLE_SPACING;
318 rcTitle.bottom = rc.top + ICON_HEIGHT;
320 /* draw title text */
321 prevFont = SelectObject (hdc, infoPtr->hTitleFont);
322 height = DrawTextW(hdc, infoPtr->pszTitle, -1, &rcTitle, DT_BOTTOM | DT_SINGLELINE | DT_NOPREFIX);
323 SelectObject (hdc, prevFont);
324 rc.top += height + BALLOON_TITLE_TEXT_SPACING;
327 else
329 /* calculate text rectangle */
330 rc.left += (NORMAL_TEXT_MARGIN + infoPtr->rcMargin.left);
331 rc.top += (NORMAL_TEXT_MARGIN + infoPtr->rcMargin.top);
332 rc.right -= (NORMAL_TEXT_MARGIN + infoPtr->rcMargin.right);
333 rc.bottom -= (NORMAL_TEXT_MARGIN + infoPtr->rcMargin.bottom);
336 /* draw text */
337 DrawTextW (hdc, infoPtr->szTipText, -1, &rc, uFlags);
339 /* Custom draw - Call PostPaint after drawing */
340 if (cdmode & CDRF_NOTIFYPOSTPAINT) {
341 TOOLTIPS_notify_customdraw(CDDS_POSTPAINT, &nmttcd);
344 /* be polite and reset the things we changed in the dc */
345 SelectObject (hdc, hOldFont);
346 SetBkMode (hdc, oldBkMode);
348 if (dwStyle & TTS_BALLOON)
350 /* frame region because default window proc doesn't do it */
351 INT width = GetSystemMetrics(SM_CXDLGFRAME) - GetSystemMetrics(SM_CXEDGE);
352 INT height = GetSystemMetrics(SM_CYDLGFRAME) - GetSystemMetrics(SM_CYEDGE);
354 hBrush = GetSysColorBrush(COLOR_WINDOWFRAME);
355 FrameRgn(hdc, hRgn, hBrush, width, height);
358 if (hRgn)
359 DeleteObject(hRgn);
362 static void TOOLTIPS_GetDispInfoA(const TOOLTIPS_INFO *infoPtr, TTTOOL_INFO *toolPtr, WCHAR *buffer)
364 NMTTDISPINFOA ttnmdi;
366 /* fill NMHDR struct */
367 ZeroMemory (&ttnmdi, sizeof(NMTTDISPINFOA));
368 ttnmdi.hdr.hwndFrom = infoPtr->hwndSelf;
369 ttnmdi.hdr.idFrom = toolPtr->uId;
370 ttnmdi.hdr.code = TTN_GETDISPINFOA; /* == TTN_NEEDTEXTA */
371 ttnmdi.lpszText = ttnmdi.szText;
372 ttnmdi.uFlags = toolPtr->uFlags;
373 ttnmdi.lParam = toolPtr->lParam;
375 TRACE("hdr.idFrom = %lx\n", ttnmdi.hdr.idFrom);
376 SendMessageW(toolPtr->hwnd, WM_NOTIFY, toolPtr->uId, (LPARAM)&ttnmdi);
378 if (IS_INTRESOURCE(ttnmdi.lpszText)) {
379 LoadStringW(ttnmdi.hinst, LOWORD(ttnmdi.lpszText),
380 buffer, INFOTIPSIZE);
381 if (ttnmdi.uFlags & TTF_DI_SETITEM) {
382 toolPtr->hinst = ttnmdi.hinst;
383 toolPtr->lpszText = (LPWSTR)ttnmdi.lpszText;
386 else if (ttnmdi.lpszText == 0) {
387 buffer[0] = '\0';
389 else if (ttnmdi.lpszText != LPSTR_TEXTCALLBACKA) {
390 Str_GetPtrAtoW(ttnmdi.lpszText, buffer, INFOTIPSIZE);
391 if (ttnmdi.uFlags & TTF_DI_SETITEM) {
392 toolPtr->hinst = 0;
393 toolPtr->lpszText = NULL;
394 Str_SetPtrW(&toolPtr->lpszText, buffer);
397 else {
398 ERR("recursive text callback!\n");
399 buffer[0] = '\0';
402 /* no text available - try calling parent instead as per native */
403 /* FIXME: Unsure if SETITEM should save the value or not */
404 if (buffer[0] == 0x00) {
406 SendMessageW(GetParent(toolPtr->hwnd), WM_NOTIFY, toolPtr->uId, (LPARAM)&ttnmdi);
408 if (IS_INTRESOURCE(ttnmdi.lpszText)) {
409 LoadStringW(ttnmdi.hinst, LOWORD(ttnmdi.lpszText),
410 buffer, INFOTIPSIZE);
411 } else if (ttnmdi.lpszText &&
412 ttnmdi.lpszText != LPSTR_TEXTCALLBACKA) {
413 Str_GetPtrAtoW(ttnmdi.lpszText, buffer, INFOTIPSIZE);
418 static void TOOLTIPS_GetDispInfoW(const TOOLTIPS_INFO *infoPtr, TTTOOL_INFO *toolPtr, WCHAR *buffer)
420 NMTTDISPINFOW ttnmdi;
422 /* fill NMHDR struct */
423 ZeroMemory (&ttnmdi, sizeof(NMTTDISPINFOW));
424 ttnmdi.hdr.hwndFrom = infoPtr->hwndSelf;
425 ttnmdi.hdr.idFrom = toolPtr->uId;
426 ttnmdi.hdr.code = TTN_GETDISPINFOW; /* == TTN_NEEDTEXTW */
427 ttnmdi.lpszText = ttnmdi.szText;
428 ttnmdi.uFlags = toolPtr->uFlags;
429 ttnmdi.lParam = toolPtr->lParam;
431 TRACE("hdr.idFrom = %lx\n", ttnmdi.hdr.idFrom);
432 SendMessageW(toolPtr->hwnd, WM_NOTIFY, toolPtr->uId, (LPARAM)&ttnmdi);
434 if (IS_INTRESOURCE(ttnmdi.lpszText)) {
435 LoadStringW(ttnmdi.hinst, LOWORD(ttnmdi.lpszText),
436 buffer, INFOTIPSIZE);
437 if (ttnmdi.uFlags & TTF_DI_SETITEM) {
438 toolPtr->hinst = ttnmdi.hinst;
439 toolPtr->lpszText = ttnmdi.lpszText;
442 else if (ttnmdi.lpszText == 0) {
443 buffer[0] = '\0';
445 else if (ttnmdi.lpszText != LPSTR_TEXTCALLBACKW) {
446 Str_GetPtrW(ttnmdi.lpszText, buffer, INFOTIPSIZE);
447 if (ttnmdi.uFlags & TTF_DI_SETITEM) {
448 toolPtr->hinst = 0;
449 toolPtr->lpszText = NULL;
450 Str_SetPtrW(&toolPtr->lpszText, buffer);
453 else {
454 ERR("recursive text callback!\n");
455 buffer[0] = '\0';
458 /* no text available - try calling parent instead as per native */
459 /* FIXME: Unsure if SETITEM should save the value or not */
460 if (buffer[0] == 0x00) {
462 SendMessageW(GetParent(toolPtr->hwnd), WM_NOTIFY, toolPtr->uId, (LPARAM)&ttnmdi);
464 if (IS_INTRESOURCE(ttnmdi.lpszText)) {
465 LoadStringW(ttnmdi.hinst, LOWORD(ttnmdi.lpszText),
466 buffer, INFOTIPSIZE);
467 } else if (ttnmdi.lpszText &&
468 ttnmdi.lpszText != LPSTR_TEXTCALLBACKW) {
469 Str_GetPtrW(ttnmdi.lpszText, buffer, INFOTIPSIZE);
475 static void
476 TOOLTIPS_GetTipText (const TOOLTIPS_INFO *infoPtr, INT nTool, WCHAR *buffer)
478 TTTOOL_INFO *toolPtr = &infoPtr->tools[nTool];
480 if (IS_INTRESOURCE(toolPtr->lpszText) && toolPtr->hinst) {
481 /* load a resource */
482 TRACE("load res string %p %x\n",
483 toolPtr->hinst, LOWORD(toolPtr->lpszText));
484 LoadStringW (toolPtr->hinst, LOWORD(toolPtr->lpszText),
485 buffer, INFOTIPSIZE);
487 else if (toolPtr->lpszText) {
488 if (toolPtr->lpszText == LPSTR_TEXTCALLBACKW) {
489 if (toolPtr->bNotifyUnicode)
490 TOOLTIPS_GetDispInfoW(infoPtr, toolPtr, buffer);
491 else
492 TOOLTIPS_GetDispInfoA(infoPtr, toolPtr, buffer);
494 else {
495 /* the item is a usual (unicode) text */
496 lstrcpynW (buffer, toolPtr->lpszText, INFOTIPSIZE);
499 else {
500 /* no text available */
501 buffer[0] = '\0';
504 TRACE("%s\n", debugstr_w(buffer));
508 static void
509 TOOLTIPS_CalcTipSize (const TOOLTIPS_INFO *infoPtr, LPSIZE lpSize)
511 HDC hdc;
512 HFONT hOldFont;
513 DWORD style = GetWindowLongW(infoPtr->hwndSelf, GWL_STYLE);
514 UINT uFlags = DT_EXTERNALLEADING | DT_CALCRECT;
515 RECT rc = {0, 0, 0, 0};
516 SIZE title = {0, 0};
518 if (infoPtr->nMaxTipWidth > -1) {
519 rc.right = infoPtr->nMaxTipWidth;
520 uFlags |= DT_WORDBREAK;
522 if (style & TTS_NOPREFIX)
523 uFlags |= DT_NOPREFIX;
524 TRACE("%s\n", debugstr_w(infoPtr->szTipText));
526 hdc = GetDC (infoPtr->hwndSelf);
527 if (infoPtr->pszTitle)
529 RECT rcTitle = {0, 0, 0, 0};
530 TRACE("title %s\n", debugstr_w(infoPtr->pszTitle));
531 if (infoPtr->hTitleIcon)
533 title.cx = ICON_WIDTH;
534 title.cy = ICON_HEIGHT;
536 if (title.cx != 0) title.cx += BALLOON_ICON_TITLE_SPACING;
537 hOldFont = SelectObject (hdc, infoPtr->hTitleFont);
538 DrawTextW(hdc, infoPtr->pszTitle, -1, &rcTitle, DT_SINGLELINE | DT_NOPREFIX | DT_CALCRECT);
539 SelectObject (hdc, hOldFont);
540 title.cy = max(title.cy, rcTitle.bottom - rcTitle.top) + BALLOON_TITLE_TEXT_SPACING;
541 title.cx += (rcTitle.right - rcTitle.left);
543 hOldFont = SelectObject (hdc, infoPtr->hFont);
544 DrawTextW (hdc, infoPtr->szTipText, -1, &rc, uFlags);
545 SelectObject (hdc, hOldFont);
546 ReleaseDC (infoPtr->hwndSelf, hdc);
548 if ((style & TTS_BALLOON) || infoPtr->pszTitle)
550 lpSize->cx = max(rc.right - rc.left, title.cx) + 2*BALLOON_TEXT_MARGIN +
551 infoPtr->rcMargin.left + infoPtr->rcMargin.right;
552 lpSize->cy = title.cy + rc.bottom - rc.top + 2*BALLOON_TEXT_MARGIN +
553 infoPtr->rcMargin.bottom + infoPtr->rcMargin.top +
554 BALLOON_STEMHEIGHT;
556 else
558 lpSize->cx = rc.right - rc.left + 2*NORMAL_TEXT_MARGIN +
559 infoPtr->rcMargin.left + infoPtr->rcMargin.right;
560 lpSize->cy = rc.bottom - rc.top + 2*NORMAL_TEXT_MARGIN +
561 infoPtr->rcMargin.bottom + infoPtr->rcMargin.top;
566 static void
567 TOOLTIPS_Show (TOOLTIPS_INFO *infoPtr, BOOL track_activate)
569 TTTOOL_INFO *toolPtr;
570 HMONITOR monitor;
571 MONITORINFO mon_info;
572 RECT rect;
573 SIZE size;
574 NMHDR hdr;
575 int ptfx = 0;
576 DWORD style = GetWindowLongW(infoPtr->hwndSelf, GWL_STYLE);
577 INT nTool;
579 if (track_activate)
581 if (infoPtr->nTrackTool == -1)
583 TRACE("invalid tracking tool (-1)!\n");
584 return;
586 nTool = infoPtr->nTrackTool;
588 else
590 if (infoPtr->nTool == -1)
592 TRACE("invalid tool (-1)!\n");
593 return;
595 nTool = infoPtr->nTool;
598 TRACE("Show tooltip pre %d! (%p)\n", nTool, infoPtr->hwndSelf);
600 TOOLTIPS_GetTipText (infoPtr, nTool, infoPtr->szTipText);
602 if (infoPtr->szTipText[0] == '\0')
603 return;
605 toolPtr = &infoPtr->tools[nTool];
607 if (!track_activate)
608 infoPtr->nCurrentTool = infoPtr->nTool;
610 TRACE("Show tooltip %d!\n", nTool);
612 hdr.hwndFrom = infoPtr->hwndSelf;
613 hdr.idFrom = toolPtr->uId;
614 hdr.code = TTN_SHOW;
615 SendMessageW (toolPtr->hwnd, WM_NOTIFY, toolPtr->uId, (LPARAM)&hdr);
617 TRACE("%s\n", debugstr_w(infoPtr->szTipText));
619 TOOLTIPS_CalcTipSize (infoPtr, &size);
620 TRACE("size %d x %d\n", size.cx, size.cy);
622 if (track_activate)
624 rect.left = infoPtr->xTrackPos;
625 rect.top = infoPtr->yTrackPos;
626 ptfx = rect.left;
628 if (toolPtr->uFlags & TTF_CENTERTIP)
630 rect.left -= (size.cx / 2);
631 if (!(style & TTS_BALLOON))
632 rect.top -= (size.cy / 2);
634 infoPtr->bToolBelow = TRUE;
636 if (!(toolPtr->uFlags & TTF_ABSOLUTE))
638 if (style & TTS_BALLOON)
639 rect.left -= BALLOON_STEMINDENT;
640 else
642 RECT rcTool;
644 if (toolPtr->uFlags & TTF_IDISHWND)
645 GetWindowRect ((HWND)toolPtr->uId, &rcTool);
646 else
648 rcTool = toolPtr->rect;
649 MapWindowPoints (toolPtr->hwnd, NULL, (LPPOINT)&rcTool, 2);
652 /* smart placement */
653 if ((rect.left + size.cx > rcTool.left) && (rect.left < rcTool.right) &&
654 (rect.top + size.cy > rcTool.top) && (rect.top < rcTool.bottom))
655 rect.left = rcTool.right;
659 else
661 if (toolPtr->uFlags & TTF_CENTERTIP)
663 RECT rc;
665 if (toolPtr->uFlags & TTF_IDISHWND)
666 GetWindowRect ((HWND)toolPtr->uId, &rc);
667 else {
668 rc = toolPtr->rect;
669 MapWindowPoints (toolPtr->hwnd, NULL, (LPPOINT)&rc, 2);
671 rect.left = (rc.left + rc.right - size.cx) / 2;
672 if (style & TTS_BALLOON)
674 ptfx = rc.left + ((rc.right - rc.left) / 2);
676 /* CENTERTIP ballon tooltips default to below the field
677 * if they fit on the screen */
678 if (rc.bottom + size.cy > GetSystemMetrics(SM_CYSCREEN))
680 rect.top = rc.top - size.cy;
681 infoPtr->bToolBelow = FALSE;
683 else
685 infoPtr->bToolBelow = TRUE;
686 rect.top = rc.bottom;
688 rect.left = max(0, rect.left - BALLOON_STEMINDENT);
690 else
692 rect.top = rc.bottom + 2;
693 infoPtr->bToolBelow = TRUE;
696 else
698 GetCursorPos ((LPPOINT)&rect);
699 if (style & TTS_BALLOON)
701 ptfx = rect.left;
702 if(rect.top - size.cy >= 0)
704 rect.top -= size.cy;
705 infoPtr->bToolBelow = FALSE;
707 else
709 infoPtr->bToolBelow = TRUE;
710 rect.top += 20;
712 rect.left = max(0, rect.left - BALLOON_STEMINDENT);
714 else
716 rect.top += 20;
717 infoPtr->bToolBelow = TRUE;
722 TRACE("pos %d - %d\n", rect.left, rect.top);
724 rect.right = rect.left + size.cx;
725 rect.bottom = rect.top + size.cy;
727 /* check position */
729 monitor = MonitorFromRect( &rect, MONITOR_DEFAULTTOPRIMARY );
730 mon_info.cbSize = sizeof(mon_info);
731 GetMonitorInfoW( monitor, &mon_info );
733 if( rect.right > mon_info.rcWork.right ) {
734 rect.left -= rect.right - mon_info.rcWork.right + 2;
735 rect.right = mon_info.rcWork.right - 2;
737 if (rect.left < mon_info.rcWork.left) rect.left = mon_info.rcWork.left;
739 if( rect.bottom > mon_info.rcWork.bottom ) {
740 RECT rc;
742 if (toolPtr->uFlags & TTF_IDISHWND)
743 GetWindowRect ((HWND)toolPtr->uId, &rc);
744 else {
745 rc = toolPtr->rect;
746 MapWindowPoints (toolPtr->hwnd, NULL, (LPPOINT)&rc, 2);
748 rect.bottom = rc.top - 2;
749 rect.top = rect.bottom - size.cy;
752 AdjustWindowRectEx (&rect, GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE),
753 FALSE, GetWindowLongW (infoPtr->hwndSelf, GWL_EXSTYLE));
755 if (style & TTS_BALLOON)
757 HRGN hRgn;
758 HRGN hrStem;
759 POINT pts[3];
761 ptfx -= rect.left;
763 if(infoPtr->bToolBelow)
765 pts[0].x = ptfx;
766 pts[0].y = 0;
767 pts[1].x = max(BALLOON_STEMINDENT, ptfx - (BALLOON_STEMWIDTH / 2));
768 pts[1].y = BALLOON_STEMHEIGHT;
769 pts[2].x = pts[1].x + BALLOON_STEMWIDTH;
770 pts[2].y = pts[1].y;
771 if(pts[2].x > (rect.right - rect.left) - BALLOON_STEMINDENT)
773 pts[2].x = (rect.right - rect.left) - BALLOON_STEMINDENT;
774 pts[1].x = pts[2].x - BALLOON_STEMWIDTH;
777 else
779 pts[0].x = max(BALLOON_STEMINDENT, ptfx - (BALLOON_STEMWIDTH / 2));
780 pts[0].y = (rect.bottom - rect.top) - BALLOON_STEMHEIGHT;
781 pts[1].x = pts[0].x + BALLOON_STEMWIDTH;
782 pts[1].y = pts[0].y;
783 pts[2].x = ptfx;
784 pts[2].y = (rect.bottom - rect.top);
785 if(pts[1].x > (rect.right - rect.left) - BALLOON_STEMINDENT)
787 pts[1].x = (rect.right - rect.left) - BALLOON_STEMINDENT;
788 pts[0].x = pts[1].x - BALLOON_STEMWIDTH;
792 hrStem = CreatePolygonRgn(pts, sizeof(pts) / sizeof(pts[0]), ALTERNATE);
794 hRgn = CreateRoundRectRgn(0,
795 (infoPtr->bToolBelow ? BALLOON_STEMHEIGHT : 0),
796 rect.right - rect.left,
797 (infoPtr->bToolBelow ? rect.bottom - rect.top : rect.bottom - rect.top - BALLOON_STEMHEIGHT),
798 BALLOON_ROUNDEDNESS, BALLOON_ROUNDEDNESS);
800 CombineRgn(hRgn, hRgn, hrStem, RGN_OR);
801 DeleteObject(hrStem);
803 SetWindowRgn(infoPtr->hwndSelf, hRgn, FALSE);
804 /* we don't free the region handle as the system deletes it when
805 * it is no longer needed */
808 SetWindowPos (infoPtr->hwndSelf, HWND_TOPMOST, rect.left, rect.top,
809 rect.right - rect.left, rect.bottom - rect.top,
810 SWP_SHOWWINDOW | SWP_NOACTIVATE);
812 /* repaint the tooltip */
813 InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
814 UpdateWindow(infoPtr->hwndSelf);
816 if (!track_activate)
818 SetTimer (infoPtr->hwndSelf, ID_TIMERPOP, infoPtr->nAutoPopTime, 0);
819 TRACE("timer 2 started!\n");
820 SetTimer (infoPtr->hwndSelf, ID_TIMERLEAVE, infoPtr->nReshowTime, 0);
821 TRACE("timer 3 started!\n");
826 static void
827 TOOLTIPS_Hide (TOOLTIPS_INFO *infoPtr)
829 TTTOOL_INFO *toolPtr;
830 NMHDR hdr;
832 TRACE("Hide tooltip %d! (%p)\n", infoPtr->nCurrentTool, infoPtr->hwndSelf);
834 if (infoPtr->nCurrentTool == -1)
835 return;
837 toolPtr = &infoPtr->tools[infoPtr->nCurrentTool];
838 KillTimer (infoPtr->hwndSelf, ID_TIMERPOP);
840 hdr.hwndFrom = infoPtr->hwndSelf;
841 hdr.idFrom = toolPtr->uId;
842 hdr.code = TTN_POP;
843 SendMessageW (toolPtr->hwnd, WM_NOTIFY, toolPtr->uId, (LPARAM)&hdr);
845 infoPtr->nCurrentTool = -1;
847 SetWindowPos (infoPtr->hwndSelf, HWND_TOP, 0, 0, 0, 0,
848 SWP_NOZORDER | SWP_HIDEWINDOW | SWP_NOACTIVATE);
852 static void
853 TOOLTIPS_TrackShow (TOOLTIPS_INFO *infoPtr)
855 TOOLTIPS_Show(infoPtr, TRUE);
859 static void
860 TOOLTIPS_TrackHide (const TOOLTIPS_INFO *infoPtr)
862 TTTOOL_INFO *toolPtr;
863 NMHDR hdr;
865 TRACE("hide tracking tooltip %d\n", infoPtr->nTrackTool);
867 if (infoPtr->nTrackTool == -1)
868 return;
870 toolPtr = &infoPtr->tools[infoPtr->nTrackTool];
872 hdr.hwndFrom = infoPtr->hwndSelf;
873 hdr.idFrom = toolPtr->uId;
874 hdr.code = TTN_POP;
875 SendMessageW (toolPtr->hwnd, WM_NOTIFY, toolPtr->uId, (LPARAM)&hdr);
877 SetWindowPos (infoPtr->hwndSelf, HWND_TOP, 0, 0, 0, 0,
878 SWP_NOZORDER | SWP_HIDEWINDOW | SWP_NOACTIVATE);
882 static INT
883 TOOLTIPS_GetToolFromInfoA (const TOOLTIPS_INFO *infoPtr, const TTTOOLINFOA *lpToolInfo)
885 TTTOOL_INFO *toolPtr;
886 UINT nTool;
888 for (nTool = 0; nTool < infoPtr->uNumTools; nTool++) {
889 toolPtr = &infoPtr->tools[nTool];
891 if (!(toolPtr->uFlags & TTF_IDISHWND) &&
892 (lpToolInfo->hwnd == toolPtr->hwnd) &&
893 (lpToolInfo->uId == toolPtr->uId))
894 return nTool;
897 for (nTool = 0; nTool < infoPtr->uNumTools; nTool++) {
898 toolPtr = &infoPtr->tools[nTool];
900 if ((toolPtr->uFlags & TTF_IDISHWND) &&
901 (lpToolInfo->uId == toolPtr->uId))
902 return nTool;
905 return -1;
909 static INT
910 TOOLTIPS_GetToolFromInfoW (const TOOLTIPS_INFO *infoPtr, const TTTOOLINFOW *lpToolInfo)
912 TTTOOL_INFO *toolPtr;
913 UINT nTool;
915 for (nTool = 0; nTool < infoPtr->uNumTools; nTool++) {
916 toolPtr = &infoPtr->tools[nTool];
918 if (!(toolPtr->uFlags & TTF_IDISHWND) &&
919 (lpToolInfo->hwnd == toolPtr->hwnd) &&
920 (lpToolInfo->uId == toolPtr->uId))
921 return nTool;
924 for (nTool = 0; nTool < infoPtr->uNumTools; nTool++) {
925 toolPtr = &infoPtr->tools[nTool];
927 if ((toolPtr->uFlags & TTF_IDISHWND) &&
928 (lpToolInfo->uId == toolPtr->uId))
929 return nTool;
932 return -1;
936 static INT
937 TOOLTIPS_GetToolFromPoint (const TOOLTIPS_INFO *infoPtr, HWND hwnd, const POINT *lpPt)
939 TTTOOL_INFO *toolPtr;
940 UINT nTool;
942 for (nTool = 0; nTool < infoPtr->uNumTools; nTool++) {
943 toolPtr = &infoPtr->tools[nTool];
945 if (!(toolPtr->uFlags & TTF_IDISHWND)) {
946 if (hwnd != toolPtr->hwnd)
947 continue;
948 if (!PtInRect (&toolPtr->rect, *lpPt))
949 continue;
950 return nTool;
954 for (nTool = 0; nTool < infoPtr->uNumTools; nTool++) {
955 toolPtr = &infoPtr->tools[nTool];
957 if (toolPtr->uFlags & TTF_IDISHWND) {
958 if ((HWND)toolPtr->uId == hwnd)
959 return nTool;
963 return -1;
967 static BOOL
968 TOOLTIPS_IsWindowActive (HWND hwnd)
970 HWND hwndActive = GetActiveWindow ();
971 if (!hwndActive)
972 return FALSE;
973 if (hwndActive == hwnd)
974 return TRUE;
975 return IsChild (hwndActive, hwnd);
979 static INT
980 TOOLTIPS_CheckTool (const TOOLTIPS_INFO *infoPtr, BOOL bShowTest)
982 POINT pt;
983 HWND hwndTool;
984 INT nTool;
986 GetCursorPos (&pt);
987 hwndTool = (HWND)SendMessageW (infoPtr->hwndSelf, TTM_WINDOWFROMPOINT, 0, (LPARAM)&pt);
988 if (hwndTool == 0)
989 return -1;
991 ScreenToClient (hwndTool, &pt);
992 nTool = TOOLTIPS_GetToolFromPoint (infoPtr, hwndTool, &pt);
993 if (nTool == -1)
994 return -1;
996 if (!(GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE) & TTS_ALWAYSTIP) && bShowTest) {
997 if (!TOOLTIPS_IsWindowActive (GetWindow (infoPtr->hwndSelf, GW_OWNER)))
998 return -1;
1001 TRACE("tool %d\n", nTool);
1003 return nTool;
1007 static LRESULT
1008 TOOLTIPS_Activate (TOOLTIPS_INFO *infoPtr, BOOL activate)
1010 infoPtr->bActive = activate;
1012 if (infoPtr->bActive)
1013 TRACE("activate!\n");
1015 if (!(infoPtr->bActive) && (infoPtr->nCurrentTool != -1))
1016 TOOLTIPS_Hide (infoPtr);
1018 return 0;
1022 static LRESULT
1023 TOOLTIPS_AddToolA (TOOLTIPS_INFO *infoPtr, const TTTOOLINFOA *lpToolInfo)
1025 TTTOOL_INFO *toolPtr;
1026 INT nResult;
1028 if (lpToolInfo == NULL)
1029 return FALSE;
1030 if (lpToolInfo->cbSize < TTTOOLINFOA_V1_SIZE)
1031 return FALSE;
1033 TRACE("add tool (%p) %p %ld%s!\n",
1034 infoPtr->hwndSelf, lpToolInfo->hwnd, lpToolInfo->uId,
1035 (lpToolInfo->uFlags & TTF_IDISHWND) ? " TTF_IDISHWND" : "");
1037 if (infoPtr->uNumTools == 0) {
1038 infoPtr->tools = Alloc (sizeof(TTTOOL_INFO));
1039 toolPtr = infoPtr->tools;
1041 else {
1042 TTTOOL_INFO *oldTools = infoPtr->tools;
1043 infoPtr->tools =
1044 Alloc (sizeof(TTTOOL_INFO) * (infoPtr->uNumTools + 1));
1045 memcpy (infoPtr->tools, oldTools,
1046 infoPtr->uNumTools * sizeof(TTTOOL_INFO));
1047 Free (oldTools);
1048 toolPtr = &infoPtr->tools[infoPtr->uNumTools];
1051 infoPtr->uNumTools++;
1053 /* copy tool data */
1054 toolPtr->uFlags = lpToolInfo->uFlags;
1055 toolPtr->hwnd = lpToolInfo->hwnd;
1056 toolPtr->uId = lpToolInfo->uId;
1057 toolPtr->rect = lpToolInfo->rect;
1058 toolPtr->hinst = lpToolInfo->hinst;
1060 if (IS_INTRESOURCE(lpToolInfo->lpszText)) {
1061 TRACE("add string id %x!\n", LOWORD(lpToolInfo->lpszText));
1062 toolPtr->lpszText = (LPWSTR)lpToolInfo->lpszText;
1064 else if (lpToolInfo->lpszText) {
1065 if (lpToolInfo->lpszText == LPSTR_TEXTCALLBACKA) {
1066 TRACE("add CALLBACK!\n");
1067 toolPtr->lpszText = LPSTR_TEXTCALLBACKW;
1069 else {
1070 INT len = MultiByteToWideChar(CP_ACP, 0, lpToolInfo->lpszText, -1,
1071 NULL, 0);
1072 TRACE("add text \"%s\"!\n", lpToolInfo->lpszText);
1073 toolPtr->lpszText = Alloc (len * sizeof(WCHAR));
1074 MultiByteToWideChar(CP_ACP, 0, lpToolInfo->lpszText, -1,
1075 toolPtr->lpszText, len);
1079 if (lpToolInfo->cbSize >= sizeof(TTTOOLINFOA))
1080 toolPtr->lParam = lpToolInfo->lParam;
1082 /* install subclassing hook */
1083 if (toolPtr->uFlags & TTF_SUBCLASS) {
1084 if (toolPtr->uFlags & TTF_IDISHWND) {
1085 SetWindowSubclass((HWND)toolPtr->uId, TOOLTIPS_SubclassProc, 1,
1086 (DWORD_PTR)infoPtr->hwndSelf);
1088 else {
1089 SetWindowSubclass(toolPtr->hwnd, TOOLTIPS_SubclassProc, 1,
1090 (DWORD_PTR)infoPtr->hwndSelf);
1092 TRACE("subclassing installed!\n");
1095 nResult = (INT) SendMessageW (toolPtr->hwnd, WM_NOTIFYFORMAT,
1096 (WPARAM)infoPtr->hwndSelf, (LPARAM)NF_QUERY);
1097 if (nResult == NFR_ANSI) {
1098 toolPtr->bNotifyUnicode = FALSE;
1099 TRACE(" -- WM_NOTIFYFORMAT returns: NFR_ANSI\n");
1100 } else if (nResult == NFR_UNICODE) {
1101 toolPtr->bNotifyUnicode = TRUE;
1102 TRACE(" -- WM_NOTIFYFORMAT returns: NFR_UNICODE\n");
1103 } else {
1104 TRACE (" -- WM_NOTIFYFORMAT returns: error!\n");
1107 return TRUE;
1111 static LRESULT
1112 TOOLTIPS_AddToolW (TOOLTIPS_INFO *infoPtr, const TTTOOLINFOW *lpToolInfo)
1114 TTTOOL_INFO *toolPtr;
1115 INT nResult;
1117 if (lpToolInfo == NULL)
1118 return FALSE;
1119 if (lpToolInfo->cbSize < TTTOOLINFOW_V1_SIZE)
1120 return FALSE;
1122 TRACE("add tool (%p) %p %ld%s!\n",
1123 infoPtr->hwndSelf, lpToolInfo->hwnd, lpToolInfo->uId,
1124 (lpToolInfo->uFlags & TTF_IDISHWND) ? " TTF_IDISHWND" : "");
1126 if (infoPtr->uNumTools == 0) {
1127 infoPtr->tools = Alloc (sizeof(TTTOOL_INFO));
1128 toolPtr = infoPtr->tools;
1130 else {
1131 TTTOOL_INFO *oldTools = infoPtr->tools;
1132 infoPtr->tools =
1133 Alloc (sizeof(TTTOOL_INFO) * (infoPtr->uNumTools + 1));
1134 memcpy (infoPtr->tools, oldTools,
1135 infoPtr->uNumTools * sizeof(TTTOOL_INFO));
1136 Free (oldTools);
1137 toolPtr = &infoPtr->tools[infoPtr->uNumTools];
1140 infoPtr->uNumTools++;
1142 /* copy tool data */
1143 toolPtr->uFlags = lpToolInfo->uFlags;
1144 toolPtr->hwnd = lpToolInfo->hwnd;
1145 toolPtr->uId = lpToolInfo->uId;
1146 toolPtr->rect = lpToolInfo->rect;
1147 toolPtr->hinst = lpToolInfo->hinst;
1149 if (IS_INTRESOURCE(lpToolInfo->lpszText)) {
1150 TRACE("add string id %x\n", LOWORD(lpToolInfo->lpszText));
1151 toolPtr->lpszText = lpToolInfo->lpszText;
1153 else if (lpToolInfo->lpszText) {
1154 if (lpToolInfo->lpszText == LPSTR_TEXTCALLBACKW) {
1155 TRACE("add CALLBACK!\n");
1156 toolPtr->lpszText = LPSTR_TEXTCALLBACKW;
1158 else {
1159 INT len = lstrlenW (lpToolInfo->lpszText);
1160 TRACE("add text %s!\n",
1161 debugstr_w(lpToolInfo->lpszText));
1162 toolPtr->lpszText = Alloc ((len + 1)*sizeof(WCHAR));
1163 strcpyW (toolPtr->lpszText, lpToolInfo->lpszText);
1167 if (lpToolInfo->cbSize >= sizeof(TTTOOLINFOW))
1168 toolPtr->lParam = lpToolInfo->lParam;
1170 /* install subclassing hook */
1171 if (toolPtr->uFlags & TTF_SUBCLASS) {
1172 if (toolPtr->uFlags & TTF_IDISHWND) {
1173 SetWindowSubclass((HWND)toolPtr->uId, TOOLTIPS_SubclassProc, 1,
1174 (DWORD_PTR)infoPtr->hwndSelf);
1176 else {
1177 SetWindowSubclass(toolPtr->hwnd, TOOLTIPS_SubclassProc, 1,
1178 (DWORD_PTR)infoPtr->hwndSelf);
1180 TRACE("subclassing installed!\n");
1183 nResult = (INT) SendMessageW (toolPtr->hwnd, WM_NOTIFYFORMAT,
1184 (WPARAM)infoPtr->hwndSelf, (LPARAM)NF_QUERY);
1185 if (nResult == NFR_ANSI) {
1186 toolPtr->bNotifyUnicode = FALSE;
1187 TRACE(" -- WM_NOTIFYFORMAT returns: NFR_ANSI\n");
1188 } else if (nResult == NFR_UNICODE) {
1189 toolPtr->bNotifyUnicode = TRUE;
1190 TRACE(" -- WM_NOTIFYFORMAT returns: NFR_UNICODE\n");
1191 } else {
1192 TRACE (" -- WM_NOTIFYFORMAT returns: error!\n");
1195 return TRUE;
1199 static void
1200 TOOLTIPS_DelToolCommon (TOOLTIPS_INFO *infoPtr, INT nTool)
1202 TTTOOL_INFO *toolPtr;
1204 TRACE("tool %d\n", nTool);
1206 if (nTool == -1)
1207 return;
1209 /* make sure the tooltip has disappeared before deleting it */
1210 TOOLTIPS_Hide(infoPtr);
1212 /* delete text string */
1213 toolPtr = &infoPtr->tools[nTool];
1214 if (toolPtr->lpszText) {
1215 if ( (toolPtr->lpszText != LPSTR_TEXTCALLBACKW) &&
1216 !IS_INTRESOURCE(toolPtr->lpszText) )
1217 Free (toolPtr->lpszText);
1220 /* remove subclassing */
1221 if (toolPtr->uFlags & TTF_SUBCLASS) {
1222 if (toolPtr->uFlags & TTF_IDISHWND) {
1223 RemoveWindowSubclass((HWND)toolPtr->uId, TOOLTIPS_SubclassProc, 1);
1225 else {
1226 RemoveWindowSubclass(toolPtr->hwnd, TOOLTIPS_SubclassProc, 1);
1230 /* delete tool from tool list */
1231 if (infoPtr->uNumTools == 1) {
1232 Free (infoPtr->tools);
1233 infoPtr->tools = NULL;
1235 else {
1236 TTTOOL_INFO *oldTools = infoPtr->tools;
1237 infoPtr->tools =
1238 Alloc (sizeof(TTTOOL_INFO) * (infoPtr->uNumTools - 1));
1240 if (nTool > 0)
1241 memcpy (&infoPtr->tools[0], &oldTools[0],
1242 nTool * sizeof(TTTOOL_INFO));
1244 if (nTool < infoPtr->uNumTools - 1)
1245 memcpy (&infoPtr->tools[nTool], &oldTools[nTool + 1],
1246 (infoPtr->uNumTools - nTool - 1) * sizeof(TTTOOL_INFO));
1248 Free (oldTools);
1251 /* update any indices affected by delete */
1253 /* destroying tool that mouse was on on last relayed mouse move */
1254 if (infoPtr->nTool == nTool)
1255 /* -1 means no current tool (0 means first tool) */
1256 infoPtr->nTool = -1;
1257 else if (infoPtr->nTool > nTool)
1258 infoPtr->nTool--;
1260 if (infoPtr->nTrackTool == nTool)
1261 /* -1 means no current tool (0 means first tool) */
1262 infoPtr->nTrackTool = -1;
1263 else if (infoPtr->nTrackTool > nTool)
1264 infoPtr->nTrackTool--;
1266 if (infoPtr->nCurrentTool == nTool)
1267 /* -1 means no current tool (0 means first tool) */
1268 infoPtr->nCurrentTool = -1;
1269 else if (infoPtr->nCurrentTool > nTool)
1270 infoPtr->nCurrentTool--;
1272 infoPtr->uNumTools--;
1275 static LRESULT
1276 TOOLTIPS_DelToolA (TOOLTIPS_INFO *infoPtr, LPTTTOOLINFOA lpToolInfo)
1278 INT nTool;
1280 if (lpToolInfo == NULL)
1281 return 0;
1282 if (lpToolInfo->cbSize < TTTOOLINFOA_V1_SIZE)
1283 return 0;
1284 if (infoPtr->uNumTools == 0)
1285 return 0;
1287 nTool = TOOLTIPS_GetToolFromInfoA (infoPtr, lpToolInfo);
1289 TOOLTIPS_DelToolCommon (infoPtr, nTool);
1291 return 0;
1295 static LRESULT
1296 TOOLTIPS_DelToolW (TOOLTIPS_INFO *infoPtr, LPTTTOOLINFOW lpToolInfo)
1298 INT nTool;
1300 if (lpToolInfo == NULL)
1301 return 0;
1302 if (lpToolInfo->cbSize < TTTOOLINFOW_V1_SIZE)
1303 return 0;
1304 if (infoPtr->uNumTools == 0)
1305 return 0;
1307 nTool = TOOLTIPS_GetToolFromInfoW (infoPtr, lpToolInfo);
1309 TOOLTIPS_DelToolCommon (infoPtr, nTool);
1311 return 0;
1315 static LRESULT
1316 TOOLTIPS_EnumToolsA (const TOOLTIPS_INFO *infoPtr, UINT uIndex, LPTTTOOLINFOA lpToolInfo)
1318 TTTOOL_INFO *toolPtr;
1320 if (lpToolInfo == NULL)
1321 return FALSE;
1322 if (lpToolInfo->cbSize < TTTOOLINFOA_V1_SIZE)
1323 return FALSE;
1324 if (uIndex >= infoPtr->uNumTools)
1325 return FALSE;
1327 TRACE("index=%u\n", uIndex);
1329 toolPtr = &infoPtr->tools[uIndex];
1331 /* copy tool data */
1332 lpToolInfo->uFlags = toolPtr->uFlags;
1333 lpToolInfo->hwnd = toolPtr->hwnd;
1334 lpToolInfo->uId = toolPtr->uId;
1335 lpToolInfo->rect = toolPtr->rect;
1336 lpToolInfo->hinst = toolPtr->hinst;
1337 /* lpToolInfo->lpszText = toolPtr->lpszText; */
1338 lpToolInfo->lpszText = NULL; /* FIXME */
1340 if (lpToolInfo->cbSize >= sizeof(TTTOOLINFOA))
1341 lpToolInfo->lParam = toolPtr->lParam;
1343 return TRUE;
1347 static LRESULT
1348 TOOLTIPS_EnumToolsW (const TOOLTIPS_INFO *infoPtr, UINT uIndex, LPTTTOOLINFOW lpToolInfo)
1350 TTTOOL_INFO *toolPtr;
1352 if (lpToolInfo == NULL)
1353 return FALSE;
1354 if (lpToolInfo->cbSize < TTTOOLINFOW_V1_SIZE)
1355 return FALSE;
1356 if (uIndex >= infoPtr->uNumTools)
1357 return FALSE;
1359 TRACE("index=%u\n", uIndex);
1361 toolPtr = &infoPtr->tools[uIndex];
1363 /* copy tool data */
1364 lpToolInfo->uFlags = toolPtr->uFlags;
1365 lpToolInfo->hwnd = toolPtr->hwnd;
1366 lpToolInfo->uId = toolPtr->uId;
1367 lpToolInfo->rect = toolPtr->rect;
1368 lpToolInfo->hinst = toolPtr->hinst;
1369 /* lpToolInfo->lpszText = toolPtr->lpszText; */
1370 lpToolInfo->lpszText = NULL; /* FIXME */
1372 if (lpToolInfo->cbSize >= sizeof(TTTOOLINFOW))
1373 lpToolInfo->lParam = toolPtr->lParam;
1375 return TRUE;
1378 static LRESULT
1379 TOOLTIPS_GetBubbleSize (const TOOLTIPS_INFO *infoPtr, const TTTOOLINFOW *lpToolInfo)
1381 INT nTool;
1382 SIZE size;
1384 if (lpToolInfo == NULL)
1385 return FALSE;
1386 if (lpToolInfo->cbSize < TTTOOLINFOW_V1_SIZE)
1387 return FALSE;
1389 nTool = TOOLTIPS_GetToolFromInfoW (infoPtr, lpToolInfo);
1390 if (nTool == -1) return 0;
1392 TRACE("tool %d\n", nTool);
1394 TOOLTIPS_CalcTipSize (infoPtr, &size);
1395 TRACE("size %d x %d\n", size.cx, size.cy);
1397 return MAKELRESULT(size.cx, size.cy);
1400 static LRESULT
1401 TOOLTIPS_GetCurrentToolA (const TOOLTIPS_INFO *infoPtr, LPTTTOOLINFOA lpToolInfo)
1403 TTTOOL_INFO *toolPtr;
1405 if (lpToolInfo) {
1406 if (lpToolInfo->cbSize < TTTOOLINFOA_V1_SIZE)
1407 return FALSE;
1409 if (infoPtr->nCurrentTool > -1) {
1410 toolPtr = &infoPtr->tools[infoPtr->nCurrentTool];
1412 /* copy tool data */
1413 lpToolInfo->uFlags = toolPtr->uFlags;
1414 lpToolInfo->rect = toolPtr->rect;
1415 lpToolInfo->hinst = toolPtr->hinst;
1416 /* lpToolInfo->lpszText = toolPtr->lpszText; */
1417 lpToolInfo->lpszText = NULL; /* FIXME */
1419 if (lpToolInfo->cbSize >= sizeof(TTTOOLINFOA))
1420 lpToolInfo->lParam = toolPtr->lParam;
1422 return TRUE;
1424 else
1425 return FALSE;
1427 else
1428 return (infoPtr->nCurrentTool != -1);
1432 static LRESULT
1433 TOOLTIPS_GetCurrentToolW (const TOOLTIPS_INFO *infoPtr, LPTTTOOLINFOW lpToolInfo)
1435 TTTOOL_INFO *toolPtr;
1437 if (lpToolInfo) {
1438 if (lpToolInfo->cbSize < TTTOOLINFOW_V1_SIZE)
1439 return FALSE;
1441 if (infoPtr->nCurrentTool > -1) {
1442 toolPtr = &infoPtr->tools[infoPtr->nCurrentTool];
1444 /* copy tool data */
1445 lpToolInfo->uFlags = toolPtr->uFlags;
1446 lpToolInfo->rect = toolPtr->rect;
1447 lpToolInfo->hinst = toolPtr->hinst;
1448 /* lpToolInfo->lpszText = toolPtr->lpszText; */
1449 lpToolInfo->lpszText = NULL; /* FIXME */
1451 if (lpToolInfo->cbSize >= sizeof(TTTOOLINFOW))
1452 lpToolInfo->lParam = toolPtr->lParam;
1454 return TRUE;
1456 else
1457 return FALSE;
1459 else
1460 return (infoPtr->nCurrentTool != -1);
1464 static LRESULT
1465 TOOLTIPS_GetDelayTime (const TOOLTIPS_INFO *infoPtr, DWORD duration)
1467 switch (duration) {
1468 case TTDT_RESHOW:
1469 return infoPtr->nReshowTime;
1471 case TTDT_AUTOPOP:
1472 return infoPtr->nAutoPopTime;
1474 case TTDT_INITIAL:
1475 case TTDT_AUTOMATIC: /* Apparently TTDT_AUTOMATIC returns TTDT_INITIAL */
1476 return infoPtr->nInitialTime;
1478 default:
1479 WARN("Invalid duration flag %x\n", duration);
1480 break;
1483 return -1;
1487 static LRESULT
1488 TOOLTIPS_GetMargin (const TOOLTIPS_INFO *infoPtr, LPRECT lpRect)
1490 lpRect->left = infoPtr->rcMargin.left;
1491 lpRect->right = infoPtr->rcMargin.right;
1492 lpRect->bottom = infoPtr->rcMargin.bottom;
1493 lpRect->top = infoPtr->rcMargin.top;
1495 return 0;
1499 static inline LRESULT
1500 TOOLTIPS_GetMaxTipWidth (const TOOLTIPS_INFO *infoPtr)
1502 return infoPtr->nMaxTipWidth;
1506 static LRESULT
1507 TOOLTIPS_GetTextA (const TOOLTIPS_INFO *infoPtr, LPTTTOOLINFOA lpToolInfo)
1509 WCHAR buffer[INFOTIPSIZE];
1510 INT nTool;
1512 if (lpToolInfo == NULL)
1513 return 0;
1514 if (lpToolInfo->cbSize < TTTOOLINFOA_V1_SIZE)
1515 return 0;
1517 nTool = TOOLTIPS_GetToolFromInfoA (infoPtr, lpToolInfo);
1518 if (nTool == -1) return 0;
1520 /* NB this API is broken, there is no way for the app to determine
1521 what size buffer it requires nor a way to specify how long the
1522 one it supplies is. We'll assume it's up to INFOTIPSIZE */
1524 buffer[0] = '\0';
1525 TOOLTIPS_GetTipText(infoPtr, nTool, buffer);
1526 WideCharToMultiByte(CP_ACP, 0, buffer, -1, lpToolInfo->lpszText,
1527 INFOTIPSIZE, NULL, NULL);
1529 return 0;
1533 static LRESULT
1534 TOOLTIPS_GetTextW (const TOOLTIPS_INFO *infoPtr, LPTTTOOLINFOW lpToolInfo)
1536 INT nTool;
1538 if (lpToolInfo == NULL)
1539 return 0;
1540 if (lpToolInfo->cbSize < TTTOOLINFOW_V1_SIZE)
1541 return 0;
1543 nTool = TOOLTIPS_GetToolFromInfoW (infoPtr, lpToolInfo);
1544 if (nTool == -1) return 0;
1546 if (infoPtr->tools[nTool].lpszText == NULL)
1547 return 0;
1549 lpToolInfo->lpszText[0] = '\0';
1550 TOOLTIPS_GetTipText(infoPtr, nTool, lpToolInfo->lpszText);
1552 return 0;
1556 static inline LRESULT
1557 TOOLTIPS_GetTipBkColor (const TOOLTIPS_INFO *infoPtr)
1559 return infoPtr->clrBk;
1563 static inline LRESULT
1564 TOOLTIPS_GetTipTextColor (const TOOLTIPS_INFO *infoPtr)
1566 return infoPtr->clrText;
1570 static inline LRESULT
1571 TOOLTIPS_GetToolCount (const TOOLTIPS_INFO *infoPtr)
1573 return infoPtr->uNumTools;
1577 static LRESULT
1578 TOOLTIPS_GetToolInfoA (const TOOLTIPS_INFO *infoPtr, LPTTTOOLINFOA lpToolInfo)
1580 TTTOOL_INFO *toolPtr;
1581 INT nTool;
1583 if (lpToolInfo == NULL)
1584 return FALSE;
1585 if (lpToolInfo->cbSize < TTTOOLINFOA_V1_SIZE)
1586 return FALSE;
1587 if (infoPtr->uNumTools == 0)
1588 return FALSE;
1590 nTool = TOOLTIPS_GetToolFromInfoA (infoPtr, lpToolInfo);
1591 if (nTool == -1)
1592 return FALSE;
1594 TRACE("tool %d\n", nTool);
1596 toolPtr = &infoPtr->tools[nTool];
1598 /* copy tool data */
1599 lpToolInfo->uFlags = toolPtr->uFlags;
1600 lpToolInfo->rect = toolPtr->rect;
1601 lpToolInfo->hinst = toolPtr->hinst;
1602 /* lpToolInfo->lpszText = toolPtr->lpszText; */
1603 lpToolInfo->lpszText = NULL; /* FIXME */
1605 if (lpToolInfo->cbSize >= sizeof(TTTOOLINFOA))
1606 lpToolInfo->lParam = toolPtr->lParam;
1608 return TRUE;
1612 static LRESULT
1613 TOOLTIPS_GetToolInfoW (const TOOLTIPS_INFO *infoPtr, LPTTTOOLINFOW lpToolInfo)
1615 TTTOOL_INFO *toolPtr;
1616 INT nTool;
1618 if (lpToolInfo == NULL)
1619 return FALSE;
1620 if (lpToolInfo->cbSize < TTTOOLINFOW_V1_SIZE)
1621 return FALSE;
1622 if (infoPtr->uNumTools == 0)
1623 return FALSE;
1625 nTool = TOOLTIPS_GetToolFromInfoW (infoPtr, lpToolInfo);
1626 if (nTool == -1)
1627 return FALSE;
1629 TRACE("tool %d\n", nTool);
1631 toolPtr = &infoPtr->tools[nTool];
1633 /* copy tool data */
1634 lpToolInfo->uFlags = toolPtr->uFlags;
1635 lpToolInfo->rect = toolPtr->rect;
1636 lpToolInfo->hinst = toolPtr->hinst;
1637 /* lpToolInfo->lpszText = toolPtr->lpszText; */
1638 lpToolInfo->lpszText = NULL; /* FIXME */
1640 if (lpToolInfo->cbSize >= sizeof(TTTOOLINFOW))
1641 lpToolInfo->lParam = toolPtr->lParam;
1643 return TRUE;
1647 static LRESULT
1648 TOOLTIPS_HitTestA (const TOOLTIPS_INFO *infoPtr, LPTTHITTESTINFOA lptthit)
1650 TTTOOL_INFO *toolPtr;
1651 INT nTool;
1653 if (lptthit == 0)
1654 return FALSE;
1656 nTool = TOOLTIPS_GetToolFromPoint (infoPtr, lptthit->hwnd, &lptthit->pt);
1657 if (nTool == -1)
1658 return FALSE;
1660 TRACE("tool %d!\n", nTool);
1662 /* copy tool data */
1663 if (lptthit->ti.cbSize >= sizeof(TTTOOLINFOA)) {
1664 toolPtr = &infoPtr->tools[nTool];
1666 lptthit->ti.uFlags = toolPtr->uFlags;
1667 lptthit->ti.hwnd = toolPtr->hwnd;
1668 lptthit->ti.uId = toolPtr->uId;
1669 lptthit->ti.rect = toolPtr->rect;
1670 lptthit->ti.hinst = toolPtr->hinst;
1671 /* lptthit->ti.lpszText = toolPtr->lpszText; */
1672 lptthit->ti.lpszText = NULL; /* FIXME */
1673 lptthit->ti.lParam = toolPtr->lParam;
1676 return TRUE;
1680 static LRESULT
1681 TOOLTIPS_HitTestW (const TOOLTIPS_INFO *infoPtr, LPTTHITTESTINFOW lptthit)
1683 TTTOOL_INFO *toolPtr;
1684 INT nTool;
1686 if (lptthit == 0)
1687 return FALSE;
1689 nTool = TOOLTIPS_GetToolFromPoint (infoPtr, lptthit->hwnd, &lptthit->pt);
1690 if (nTool == -1)
1691 return FALSE;
1693 TRACE("tool %d!\n", nTool);
1695 /* copy tool data */
1696 if (lptthit->ti.cbSize >= sizeof(TTTOOLINFOW)) {
1697 toolPtr = &infoPtr->tools[nTool];
1699 lptthit->ti.uFlags = toolPtr->uFlags;
1700 lptthit->ti.hwnd = toolPtr->hwnd;
1701 lptthit->ti.uId = toolPtr->uId;
1702 lptthit->ti.rect = toolPtr->rect;
1703 lptthit->ti.hinst = toolPtr->hinst;
1704 /* lptthit->ti.lpszText = toolPtr->lpszText; */
1705 lptthit->ti.lpszText = NULL; /* FIXME */
1706 lptthit->ti.lParam = toolPtr->lParam;
1709 return TRUE;
1713 static LRESULT
1714 TOOLTIPS_NewToolRectA (TOOLTIPS_INFO *infoPtr, const TTTOOLINFOA *lpti)
1716 INT nTool;
1718 if (lpti == NULL)
1719 return 0;
1720 if (lpti->cbSize < TTTOOLINFOA_V1_SIZE)
1721 return FALSE;
1723 nTool = TOOLTIPS_GetToolFromInfoA (infoPtr, lpti);
1725 TRACE("nTool = %d, rect = %s\n", nTool, wine_dbgstr_rect(&lpti->rect));
1727 if (nTool == -1) return 0;
1729 infoPtr->tools[nTool].rect = lpti->rect;
1731 return 0;
1735 static LRESULT
1736 TOOLTIPS_NewToolRectW (TOOLTIPS_INFO *infoPtr, const TTTOOLINFOW *lpti)
1738 INT nTool;
1740 if (lpti == NULL)
1741 return 0;
1742 if (lpti->cbSize < TTTOOLINFOW_V1_SIZE)
1743 return FALSE;
1745 nTool = TOOLTIPS_GetToolFromInfoW (infoPtr, lpti);
1747 TRACE("nTool = %d, rect = %s\n", nTool, wine_dbgstr_rect(&lpti->rect));
1749 if (nTool == -1) return 0;
1751 infoPtr->tools[nTool].rect = lpti->rect;
1753 return 0;
1757 static inline LRESULT
1758 TOOLTIPS_Pop (TOOLTIPS_INFO *infoPtr)
1760 TOOLTIPS_Hide (infoPtr);
1762 return 0;
1766 static LRESULT
1767 TOOLTIPS_RelayEvent (TOOLTIPS_INFO *infoPtr, LPMSG lpMsg)
1769 POINT pt;
1770 INT nOldTool;
1772 if (!lpMsg) {
1773 ERR("lpMsg == NULL!\n");
1774 return 0;
1777 switch (lpMsg->message) {
1778 case WM_LBUTTONDOWN:
1779 case WM_LBUTTONUP:
1780 case WM_MBUTTONDOWN:
1781 case WM_MBUTTONUP:
1782 case WM_RBUTTONDOWN:
1783 case WM_RBUTTONUP:
1784 TOOLTIPS_Hide (infoPtr);
1785 break;
1787 case WM_MOUSEMOVE:
1788 pt.x = (short)LOWORD(lpMsg->lParam);
1789 pt.y = (short)HIWORD(lpMsg->lParam);
1790 nOldTool = infoPtr->nTool;
1791 infoPtr->nTool = TOOLTIPS_GetToolFromPoint(infoPtr, lpMsg->hwnd,
1792 &pt);
1793 TRACE("tool (%p) %d %d %d\n", infoPtr->hwndSelf, nOldTool,
1794 infoPtr->nTool, infoPtr->nCurrentTool);
1795 TRACE("WM_MOUSEMOVE (%p %d %d)\n", infoPtr->hwndSelf, pt.x, pt.y);
1797 if (infoPtr->nTool != nOldTool) {
1798 if(infoPtr->nTool == -1) { /* Moved out of all tools */
1799 TOOLTIPS_Hide(infoPtr);
1800 KillTimer(infoPtr->hwndSelf, ID_TIMERLEAVE);
1801 } else if (nOldTool == -1) { /* Moved from outside */
1802 if(infoPtr->bActive) {
1803 SetTimer(infoPtr->hwndSelf, ID_TIMERSHOW, infoPtr->nInitialTime, 0);
1804 TRACE("timer 1 started!\n");
1806 } else { /* Moved from one to another */
1807 TOOLTIPS_Hide (infoPtr);
1808 KillTimer(infoPtr->hwndSelf, ID_TIMERLEAVE);
1809 if(infoPtr->bActive) {
1810 SetTimer (infoPtr->hwndSelf, ID_TIMERSHOW, infoPtr->nReshowTime, 0);
1811 TRACE("timer 1 started!\n");
1814 } else if(infoPtr->nCurrentTool != -1) { /* restart autopop */
1815 KillTimer(infoPtr->hwndSelf, ID_TIMERPOP);
1816 SetTimer(infoPtr->hwndSelf, ID_TIMERPOP, infoPtr->nAutoPopTime, 0);
1817 TRACE("timer 2 restarted\n");
1818 } else if(infoPtr->nTool != -1 && infoPtr->bActive) {
1819 /* previous show attempt didn't result in tooltip so try again */
1820 SetTimer(infoPtr->hwndSelf, ID_TIMERSHOW, infoPtr->nInitialTime, 0);
1821 TRACE("timer 1 started!\n");
1823 break;
1826 return 0;
1830 static LRESULT
1831 TOOLTIPS_SetDelayTime (TOOLTIPS_INFO *infoPtr, DWORD duration, INT nTime)
1833 switch (duration) {
1834 case TTDT_AUTOMATIC:
1835 if (nTime <= 0)
1836 nTime = GetDoubleClickTime();
1837 infoPtr->nReshowTime = nTime / 5;
1838 infoPtr->nAutoPopTime = nTime * 10;
1839 infoPtr->nInitialTime = nTime;
1840 break;
1842 case TTDT_RESHOW:
1843 if(nTime < 0)
1844 nTime = GetDoubleClickTime() / 5;
1845 infoPtr->nReshowTime = nTime;
1846 break;
1848 case TTDT_AUTOPOP:
1849 if(nTime < 0)
1850 nTime = GetDoubleClickTime() * 10;
1851 infoPtr->nAutoPopTime = nTime;
1852 break;
1854 case TTDT_INITIAL:
1855 if(nTime < 0)
1856 nTime = GetDoubleClickTime();
1857 infoPtr->nInitialTime = nTime;
1858 break;
1860 default:
1861 WARN("Invalid duration flag %x\n", duration);
1862 break;
1865 return 0;
1869 static LRESULT
1870 TOOLTIPS_SetMargin (TOOLTIPS_INFO *infoPtr, const RECT *lpRect)
1872 infoPtr->rcMargin.left = lpRect->left;
1873 infoPtr->rcMargin.right = lpRect->right;
1874 infoPtr->rcMargin.bottom = lpRect->bottom;
1875 infoPtr->rcMargin.top = lpRect->top;
1877 return 0;
1881 static inline LRESULT
1882 TOOLTIPS_SetMaxTipWidth (TOOLTIPS_INFO *infoPtr, INT MaxWidth)
1884 INT nTemp = infoPtr->nMaxTipWidth;
1886 infoPtr->nMaxTipWidth = MaxWidth;
1888 return nTemp;
1892 static inline LRESULT
1893 TOOLTIPS_SetTipBkColor (TOOLTIPS_INFO *infoPtr, COLORREF clrBk)
1895 infoPtr->clrBk = clrBk;
1897 return 0;
1901 static inline LRESULT
1902 TOOLTIPS_SetTipTextColor (TOOLTIPS_INFO *infoPtr, COLORREF clrText)
1904 infoPtr->clrText = clrText;
1906 return 0;
1910 static LRESULT
1911 TOOLTIPS_SetTitleA (TOOLTIPS_INFO *infoPtr, UINT_PTR uTitleIcon, LPCSTR pszTitle)
1913 UINT size;
1915 TRACE("hwnd = %p, title = %s, icon = %p\n", infoPtr->hwndSelf, debugstr_a(pszTitle),
1916 (void*)uTitleIcon);
1918 Free(infoPtr->pszTitle);
1920 if (pszTitle)
1922 size = sizeof(WCHAR)*MultiByteToWideChar(CP_ACP, 0, pszTitle, -1, NULL, 0);
1923 infoPtr->pszTitle = Alloc(size);
1924 if (!infoPtr->pszTitle)
1925 return FALSE;
1926 MultiByteToWideChar(CP_ACP, 0, pszTitle, -1, infoPtr->pszTitle, size/sizeof(WCHAR));
1928 else
1929 infoPtr->pszTitle = NULL;
1931 if (uTitleIcon <= TTI_ERROR)
1932 infoPtr->hTitleIcon = hTooltipIcons[uTitleIcon];
1933 else
1934 infoPtr->hTitleIcon = CopyIcon((HICON)uTitleIcon);
1936 return TRUE;
1940 static LRESULT
1941 TOOLTIPS_SetTitleW (TOOLTIPS_INFO *infoPtr, UINT_PTR uTitleIcon, LPCWSTR pszTitle)
1943 UINT size;
1945 TRACE("hwnd = %p, title = %s, icon = %p\n", infoPtr->hwndSelf, debugstr_w(pszTitle),
1946 (void*)uTitleIcon);
1948 Free(infoPtr->pszTitle);
1950 if (pszTitle)
1952 size = (strlenW(pszTitle)+1)*sizeof(WCHAR);
1953 infoPtr->pszTitle = Alloc(size);
1954 if (!infoPtr->pszTitle)
1955 return FALSE;
1956 memcpy(infoPtr->pszTitle, pszTitle, size);
1958 else
1959 infoPtr->pszTitle = NULL;
1961 if (uTitleIcon <= TTI_ERROR)
1962 infoPtr->hTitleIcon = hTooltipIcons[uTitleIcon];
1963 else
1964 infoPtr->hTitleIcon = CopyIcon((HICON)uTitleIcon);
1966 TRACE("icon = %p\n", infoPtr->hTitleIcon);
1968 return TRUE;
1972 static LRESULT
1973 TOOLTIPS_SetToolInfoA (TOOLTIPS_INFO *infoPtr, const TTTOOLINFOA *lpToolInfo)
1975 TTTOOL_INFO *toolPtr;
1976 INT nTool;
1978 if (lpToolInfo == NULL)
1979 return 0;
1980 if (lpToolInfo->cbSize < TTTOOLINFOA_V1_SIZE)
1981 return 0;
1983 nTool = TOOLTIPS_GetToolFromInfoA (infoPtr, lpToolInfo);
1984 if (nTool == -1) return 0;
1986 TRACE("tool %d\n", nTool);
1988 toolPtr = &infoPtr->tools[nTool];
1990 /* copy tool data */
1991 toolPtr->uFlags = lpToolInfo->uFlags;
1992 toolPtr->hwnd = lpToolInfo->hwnd;
1993 toolPtr->uId = lpToolInfo->uId;
1994 toolPtr->rect = lpToolInfo->rect;
1995 toolPtr->hinst = lpToolInfo->hinst;
1997 if (IS_INTRESOURCE(lpToolInfo->lpszText)) {
1998 TRACE("set string id %x\n", LOWORD(lpToolInfo->lpszText));
1999 toolPtr->lpszText = (LPWSTR)lpToolInfo->lpszText;
2001 else if (lpToolInfo->lpszText) {
2002 if (lpToolInfo->lpszText == LPSTR_TEXTCALLBACKA)
2003 toolPtr->lpszText = LPSTR_TEXTCALLBACKW;
2004 else {
2005 if ( (toolPtr->lpszText) &&
2006 !IS_INTRESOURCE(toolPtr->lpszText) ) {
2007 if( toolPtr->lpszText != LPSTR_TEXTCALLBACKW)
2008 Free (toolPtr->lpszText);
2009 toolPtr->lpszText = NULL;
2011 if (lpToolInfo->lpszText) {
2012 INT len = MultiByteToWideChar(CP_ACP, 0, lpToolInfo->lpszText,
2013 -1, NULL, 0);
2014 toolPtr->lpszText = Alloc (len * sizeof(WCHAR));
2015 MultiByteToWideChar(CP_ACP, 0, lpToolInfo->lpszText, -1,
2016 toolPtr->lpszText, len);
2021 if (lpToolInfo->cbSize >= sizeof(TTTOOLINFOA))
2022 toolPtr->lParam = lpToolInfo->lParam;
2024 return 0;
2028 static LRESULT
2029 TOOLTIPS_SetToolInfoW (TOOLTIPS_INFO *infoPtr, const TTTOOLINFOW *lpToolInfo)
2031 TTTOOL_INFO *toolPtr;
2032 INT nTool;
2034 if (lpToolInfo == NULL)
2035 return 0;
2036 if (lpToolInfo->cbSize < TTTOOLINFOW_V1_SIZE)
2037 return 0;
2039 nTool = TOOLTIPS_GetToolFromInfoW (infoPtr, lpToolInfo);
2040 if (nTool == -1) return 0;
2042 TRACE("tool %d\n", nTool);
2044 toolPtr = &infoPtr->tools[nTool];
2046 /* copy tool data */
2047 toolPtr->uFlags = lpToolInfo->uFlags;
2048 toolPtr->hwnd = lpToolInfo->hwnd;
2049 toolPtr->uId = lpToolInfo->uId;
2050 toolPtr->rect = lpToolInfo->rect;
2051 toolPtr->hinst = lpToolInfo->hinst;
2053 if (IS_INTRESOURCE(lpToolInfo->lpszText)) {
2054 TRACE("set string id %x!\n", LOWORD(lpToolInfo->lpszText));
2055 toolPtr->lpszText = lpToolInfo->lpszText;
2057 else {
2058 if (lpToolInfo->lpszText == LPSTR_TEXTCALLBACKW)
2059 toolPtr->lpszText = LPSTR_TEXTCALLBACKW;
2060 else {
2061 if ( (toolPtr->lpszText) &&
2062 !IS_INTRESOURCE(toolPtr->lpszText) ) {
2063 if( toolPtr->lpszText != LPSTR_TEXTCALLBACKW)
2064 Free (toolPtr->lpszText);
2065 toolPtr->lpszText = NULL;
2067 if (lpToolInfo->lpszText) {
2068 INT len = lstrlenW (lpToolInfo->lpszText);
2069 toolPtr->lpszText = Alloc ((len+1)*sizeof(WCHAR));
2070 strcpyW (toolPtr->lpszText, lpToolInfo->lpszText);
2075 if (lpToolInfo->cbSize >= sizeof(TTTOOLINFOW))
2076 toolPtr->lParam = lpToolInfo->lParam;
2078 if (infoPtr->nCurrentTool == nTool)
2080 TOOLTIPS_GetTipText (infoPtr, infoPtr->nCurrentTool, infoPtr->szTipText);
2082 if (infoPtr->szTipText[0] == 0)
2083 TOOLTIPS_Hide(infoPtr);
2084 else
2085 TOOLTIPS_Show (infoPtr, FALSE);
2088 return 0;
2092 static LRESULT
2093 TOOLTIPS_TrackActivate (TOOLTIPS_INFO *infoPtr, BOOL track_activate, const TTTOOLINFOA *lpToolInfo)
2095 if (track_activate) {
2097 if (lpToolInfo == NULL)
2098 return 0;
2099 if (lpToolInfo->cbSize < TTTOOLINFOA_V1_SIZE)
2100 return FALSE;
2102 /* activate */
2103 infoPtr->nTrackTool = TOOLTIPS_GetToolFromInfoA (infoPtr, lpToolInfo);
2104 if (infoPtr->nTrackTool != -1) {
2105 TRACE("activated!\n");
2106 infoPtr->bTrackActive = TRUE;
2107 TOOLTIPS_TrackShow (infoPtr);
2110 else {
2111 /* deactivate */
2112 TOOLTIPS_TrackHide (infoPtr);
2114 infoPtr->bTrackActive = FALSE;
2115 infoPtr->nTrackTool = -1;
2117 TRACE("deactivated!\n");
2120 return 0;
2124 static LRESULT
2125 TOOLTIPS_TrackPosition (TOOLTIPS_INFO *infoPtr, LPARAM coord)
2127 infoPtr->xTrackPos = (INT)LOWORD(coord);
2128 infoPtr->yTrackPos = (INT)HIWORD(coord);
2130 if (infoPtr->bTrackActive) {
2131 TRACE("[%d %d]\n",
2132 infoPtr->xTrackPos, infoPtr->yTrackPos);
2134 TOOLTIPS_TrackShow (infoPtr);
2137 return 0;
2141 static LRESULT
2142 TOOLTIPS_Update (TOOLTIPS_INFO *infoPtr)
2144 if (infoPtr->nCurrentTool != -1)
2145 UpdateWindow (infoPtr->hwndSelf);
2147 return 0;
2151 static LRESULT
2152 TOOLTIPS_UpdateTipTextA (TOOLTIPS_INFO *infoPtr, const TTTOOLINFOA *lpToolInfo)
2154 TTTOOL_INFO *toolPtr;
2155 INT nTool;
2157 if (lpToolInfo == NULL)
2158 return 0;
2159 if (lpToolInfo->cbSize < TTTOOLINFOA_V1_SIZE)
2160 return FALSE;
2162 nTool = TOOLTIPS_GetToolFromInfoA (infoPtr, lpToolInfo);
2163 if (nTool == -1) return 0;
2165 TRACE("tool %d\n", nTool);
2167 toolPtr = &infoPtr->tools[nTool];
2169 /* copy tool text */
2170 toolPtr->hinst = lpToolInfo->hinst;
2172 if (IS_INTRESOURCE(lpToolInfo->lpszText)){
2173 toolPtr->lpszText = (LPWSTR)lpToolInfo->lpszText;
2175 else if (lpToolInfo->lpszText) {
2176 if (lpToolInfo->lpszText == LPSTR_TEXTCALLBACKA)
2177 toolPtr->lpszText = LPSTR_TEXTCALLBACKW;
2178 else {
2179 if ( (toolPtr->lpszText) &&
2180 !IS_INTRESOURCE(toolPtr->lpszText) ) {
2181 if( toolPtr->lpszText != LPSTR_TEXTCALLBACKW)
2182 Free (toolPtr->lpszText);
2183 toolPtr->lpszText = NULL;
2185 if (lpToolInfo->lpszText) {
2186 INT len = MultiByteToWideChar(CP_ACP, 0, lpToolInfo->lpszText,
2187 -1, NULL, 0);
2188 toolPtr->lpszText = Alloc (len * sizeof(WCHAR));
2189 MultiByteToWideChar(CP_ACP, 0, lpToolInfo->lpszText, -1,
2190 toolPtr->lpszText, len);
2195 if(infoPtr->nCurrentTool == -1) return 0;
2196 /* force repaint */
2197 if (infoPtr->bActive)
2198 TOOLTIPS_Show (infoPtr, FALSE);
2199 else if (infoPtr->bTrackActive)
2200 TOOLTIPS_TrackShow (infoPtr);
2202 return 0;
2206 static LRESULT
2207 TOOLTIPS_UpdateTipTextW (TOOLTIPS_INFO *infoPtr, const TTTOOLINFOW *lpToolInfo)
2209 TTTOOL_INFO *toolPtr;
2210 INT nTool;
2212 if (lpToolInfo == NULL)
2213 return 0;
2214 if (lpToolInfo->cbSize < TTTOOLINFOW_V1_SIZE)
2215 return FALSE;
2217 nTool = TOOLTIPS_GetToolFromInfoW (infoPtr, lpToolInfo);
2218 if (nTool == -1)
2219 return 0;
2221 TRACE("tool %d\n", nTool);
2223 toolPtr = &infoPtr->tools[nTool];
2225 /* copy tool text */
2226 toolPtr->hinst = lpToolInfo->hinst;
2228 if (IS_INTRESOURCE(lpToolInfo->lpszText)){
2229 toolPtr->lpszText = lpToolInfo->lpszText;
2231 else if (lpToolInfo->lpszText) {
2232 if (lpToolInfo->lpszText == LPSTR_TEXTCALLBACKW)
2233 toolPtr->lpszText = LPSTR_TEXTCALLBACKW;
2234 else {
2235 if ( (toolPtr->lpszText) &&
2236 !IS_INTRESOURCE(toolPtr->lpszText) ) {
2237 if( toolPtr->lpszText != LPSTR_TEXTCALLBACKW)
2238 Free (toolPtr->lpszText);
2239 toolPtr->lpszText = NULL;
2241 if (lpToolInfo->lpszText) {
2242 INT len = lstrlenW (lpToolInfo->lpszText);
2243 toolPtr->lpszText = Alloc ((len+1)*sizeof(WCHAR));
2244 strcpyW (toolPtr->lpszText, lpToolInfo->lpszText);
2249 if(infoPtr->nCurrentTool == -1) return 0;
2250 /* force repaint */
2251 if (infoPtr->bActive)
2252 TOOLTIPS_Show (infoPtr, FALSE);
2253 else if (infoPtr->bTrackActive)
2254 TOOLTIPS_Show (infoPtr, TRUE);
2256 return 0;
2260 static LRESULT
2261 TOOLTIPS_WindowFromPoint (HWND hwnd, WPARAM wParam, LPARAM lParam)
2263 return (LRESULT)WindowFromPoint (*((LPPOINT)lParam));
2268 static LRESULT
2269 TOOLTIPS_Create (HWND hwnd, const CREATESTRUCTW *lpcs)
2271 TOOLTIPS_INFO *infoPtr;
2273 /* allocate memory for info structure */
2274 infoPtr = Alloc (sizeof(TOOLTIPS_INFO));
2275 SetWindowLongPtrW (hwnd, 0, (DWORD_PTR)infoPtr);
2277 /* initialize info structure */
2278 infoPtr->bActive = TRUE;
2279 infoPtr->bTrackActive = FALSE;
2281 infoPtr->nMaxTipWidth = -1;
2282 infoPtr->nTool = -1;
2283 infoPtr->nCurrentTool = -1;
2284 infoPtr->nTrackTool = -1;
2285 infoPtr->hwndSelf = hwnd;
2287 /* initialize colours and fonts */
2288 TOOLTIPS_InitSystemSettings(infoPtr);
2290 TOOLTIPS_SetDelayTime(infoPtr, TTDT_AUTOMATIC, 0);
2292 SetWindowPos (hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOZORDER | SWP_HIDEWINDOW | SWP_NOACTIVATE);
2294 return 0;
2298 static LRESULT
2299 TOOLTIPS_Destroy (TOOLTIPS_INFO *infoPtr)
2301 TTTOOL_INFO *toolPtr;
2302 UINT i;
2304 /* free tools */
2305 if (infoPtr->tools) {
2306 for (i = 0; i < infoPtr->uNumTools; i++) {
2307 toolPtr = &infoPtr->tools[i];
2308 if (toolPtr->lpszText) {
2309 if ( (toolPtr->lpszText != LPSTR_TEXTCALLBACKW) &&
2310 !IS_INTRESOURCE(toolPtr->lpszText) )
2312 Free (toolPtr->lpszText);
2313 toolPtr->lpszText = NULL;
2317 /* remove subclassing */
2318 if (toolPtr->uFlags & TTF_SUBCLASS) {
2319 if (toolPtr->uFlags & TTF_IDISHWND) {
2320 RemoveWindowSubclass((HWND)toolPtr->uId, TOOLTIPS_SubclassProc, 1);
2322 else {
2323 RemoveWindowSubclass(toolPtr->hwnd, TOOLTIPS_SubclassProc, 1);
2327 Free (infoPtr->tools);
2330 /* free title string */
2331 Free (infoPtr->pszTitle);
2332 /* free title icon if not a standard one */
2333 if (TOOLTIPS_GetTitleIconIndex(infoPtr->hTitleIcon) > TTI_ERROR)
2334 DeleteObject(infoPtr->hTitleIcon);
2336 /* delete fonts */
2337 DeleteObject (infoPtr->hFont);
2338 DeleteObject (infoPtr->hTitleFont);
2340 /* free tool tips info data */
2341 SetWindowLongPtrW(infoPtr->hwndSelf, 0, 0);
2342 Free (infoPtr);
2344 return 0;
2348 static inline LRESULT
2349 TOOLTIPS_GetFont (const TOOLTIPS_INFO *infoPtr)
2351 return (LRESULT)infoPtr->hFont;
2355 static LRESULT
2356 TOOLTIPS_MouseMessage (TOOLTIPS_INFO *infoPtr)
2358 TOOLTIPS_Hide (infoPtr);
2360 return 0;
2364 static LRESULT
2365 TOOLTIPS_NCCreate (HWND hwnd, const CREATESTRUCTW *lpcs)
2367 DWORD dwStyle = GetWindowLongW (hwnd, GWL_STYLE);
2368 DWORD dwExStyle = GetWindowLongW (hwnd, GWL_EXSTYLE);
2370 dwStyle &= ~(WS_CHILD | /*WS_MAXIMIZE |*/ WS_BORDER | WS_DLGFRAME);
2371 dwStyle |= (WS_POPUP | WS_BORDER | WS_CLIPSIBLINGS);
2373 /* WS_BORDER only draws a border round the window rect, not the
2374 * window region, therefore it is useless to us in balloon mode */
2375 if (dwStyle & TTS_BALLOON) dwStyle &= ~WS_BORDER;
2377 SetWindowLongW (hwnd, GWL_STYLE, dwStyle);
2379 dwExStyle |= WS_EX_TOOLWINDOW;
2380 SetWindowLongW (hwnd, GWL_EXSTYLE, dwExStyle);
2382 return TRUE;
2386 static LRESULT
2387 TOOLTIPS_NCHitTest (const TOOLTIPS_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
2389 INT nTool = (infoPtr->bTrackActive) ? infoPtr->nTrackTool : infoPtr->nTool;
2391 TRACE(" nTool=%d\n", nTool);
2393 if ((nTool > -1) && (nTool < infoPtr->uNumTools)) {
2394 if (infoPtr->tools[nTool].uFlags & TTF_TRANSPARENT) {
2395 TRACE("-- in transparent mode!\n");
2396 return HTTRANSPARENT;
2400 return DefWindowProcW (infoPtr->hwndSelf, WM_NCHITTEST, wParam, lParam);
2404 static LRESULT
2405 TOOLTIPS_NotifyFormat (TOOLTIPS_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
2407 FIXME ("hwnd=%p wParam=%lx lParam=%lx\n", infoPtr->hwndSelf, wParam, lParam);
2409 return 0;
2413 static LRESULT
2414 TOOLTIPS_Paint (const TOOLTIPS_INFO *infoPtr, HDC hDC)
2416 HDC hdc;
2417 PAINTSTRUCT ps;
2419 hdc = (hDC == NULL) ? BeginPaint (infoPtr->hwndSelf, &ps) : hDC;
2420 TOOLTIPS_Refresh (infoPtr, hdc);
2421 if (!hDC)
2422 EndPaint (infoPtr->hwndSelf, &ps);
2423 return 0;
2427 static LRESULT
2428 TOOLTIPS_SetFont (TOOLTIPS_INFO *infoPtr, HFONT hFont, BOOL redraw)
2430 LOGFONTW lf;
2432 if(!GetObjectW(hFont, sizeof(lf), &lf))
2433 return 0;
2435 DeleteObject (infoPtr->hFont);
2436 infoPtr->hFont = CreateFontIndirectW(&lf);
2438 DeleteObject (infoPtr->hTitleFont);
2439 lf.lfWeight = FW_BOLD;
2440 infoPtr->hTitleFont = CreateFontIndirectW(&lf);
2442 if (redraw & (infoPtr->nCurrentTool != -1)) {
2443 FIXME("full redraw needed!\n");
2446 return 0;
2449 /******************************************************************
2450 * TOOLTIPS_GetTextLength
2452 * This function is called when the tooltip receive a
2453 * WM_GETTEXTLENGTH message.
2455 * returns the length, in characters, of the tip text
2457 static inline LRESULT
2458 TOOLTIPS_GetTextLength(const TOOLTIPS_INFO *infoPtr)
2460 return strlenW(infoPtr->szTipText);
2463 /******************************************************************
2464 * TOOLTIPS_OnWMGetText
2466 * This function is called when the tooltip receive a
2467 * WM_GETTEXT message.
2468 * wParam : specifies the maximum number of characters to be copied
2469 * lParam : is the pointer to the buffer that will receive
2470 * the tip text
2472 * returns the number of characters copied
2474 static LRESULT
2475 TOOLTIPS_OnWMGetText (const TOOLTIPS_INFO *infoPtr, WPARAM size, LPWSTR pszText)
2477 LRESULT res;
2479 if(!infoPtr->szTipText || !size)
2480 return 0;
2482 res = min(strlenW(infoPtr->szTipText)+1, size);
2483 memcpy(pszText, infoPtr->szTipText, res*sizeof(WCHAR));
2484 pszText[res-1] = '\0';
2485 return res-1;
2488 static LRESULT
2489 TOOLTIPS_Timer (TOOLTIPS_INFO *infoPtr, INT iTimer)
2491 INT nOldTool;
2493 TRACE("timer %d (%p) expired!\n", iTimer, infoPtr->hwndSelf);
2495 switch (iTimer) {
2496 case ID_TIMERSHOW:
2497 KillTimer (infoPtr->hwndSelf, ID_TIMERSHOW);
2498 nOldTool = infoPtr->nTool;
2499 if ((infoPtr->nTool = TOOLTIPS_CheckTool (infoPtr, TRUE)) == nOldTool)
2500 TOOLTIPS_Show (infoPtr, FALSE);
2501 break;
2503 case ID_TIMERPOP:
2504 TOOLTIPS_Hide (infoPtr);
2505 break;
2507 case ID_TIMERLEAVE:
2508 nOldTool = infoPtr->nTool;
2509 infoPtr->nTool = TOOLTIPS_CheckTool (infoPtr, FALSE);
2510 TRACE("tool (%p) %d %d %d\n", infoPtr->hwndSelf, nOldTool,
2511 infoPtr->nTool, infoPtr->nCurrentTool);
2512 if (infoPtr->nTool != nOldTool) {
2513 if(infoPtr->nTool == -1) { /* Moved out of all tools */
2514 TOOLTIPS_Hide(infoPtr);
2515 KillTimer(infoPtr->hwndSelf, ID_TIMERLEAVE);
2516 } else if (nOldTool == -1) { /* Moved from outside */
2517 ERR("How did this happen?\n");
2518 } else { /* Moved from one to another */
2519 TOOLTIPS_Hide (infoPtr);
2520 KillTimer(infoPtr->hwndSelf, ID_TIMERLEAVE);
2521 if(infoPtr->bActive) {
2522 SetTimer (infoPtr->hwndSelf, ID_TIMERSHOW, infoPtr->nReshowTime, 0);
2523 TRACE("timer 1 started!\n");
2527 break;
2529 default:
2530 ERR("Unknown timer id %d\n", iTimer);
2531 break;
2533 return 0;
2537 static LRESULT
2538 TOOLTIPS_WinIniChange (TOOLTIPS_INFO *infoPtr)
2540 TOOLTIPS_InitSystemSettings (infoPtr);
2542 return 0;
2546 static LRESULT CALLBACK
2547 TOOLTIPS_SubclassProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uID, DWORD_PTR dwRef)
2549 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr ((HWND)dwRef);
2550 MSG msg;
2552 switch(uMsg) {
2553 case WM_MOUSEMOVE:
2554 case WM_LBUTTONDOWN:
2555 case WM_LBUTTONUP:
2556 case WM_MBUTTONDOWN:
2557 case WM_MBUTTONUP:
2558 case WM_RBUTTONDOWN:
2559 case WM_RBUTTONUP:
2560 msg.hwnd = hwnd;
2561 msg.message = uMsg;
2562 msg.wParam = wParam;
2563 msg.lParam = lParam;
2564 TOOLTIPS_RelayEvent(infoPtr, &msg);
2565 break;
2567 default:
2568 break;
2570 return DefSubclassProc(hwnd, uMsg, wParam, lParam);
2574 static LRESULT CALLBACK
2575 TOOLTIPS_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2577 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
2579 TRACE("hwnd=%p msg=%x wparam=%lx lParam=%lx\n", hwnd, uMsg, wParam, lParam);
2580 if (!infoPtr && (uMsg != WM_CREATE) && (uMsg != WM_NCCREATE))
2581 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
2582 switch (uMsg)
2584 case TTM_ACTIVATE:
2585 return TOOLTIPS_Activate (infoPtr, (BOOL)wParam);
2587 case TTM_ADDTOOLA:
2588 return TOOLTIPS_AddToolA (infoPtr, (LPTTTOOLINFOA)lParam);
2590 case TTM_ADDTOOLW:
2591 return TOOLTIPS_AddToolW (infoPtr, (LPTTTOOLINFOW)lParam);
2593 case TTM_DELTOOLA:
2594 return TOOLTIPS_DelToolA (infoPtr, (LPTOOLINFOA)lParam);
2596 case TTM_DELTOOLW:
2597 return TOOLTIPS_DelToolW (infoPtr, (LPTOOLINFOW)lParam);
2599 case TTM_ENUMTOOLSA:
2600 return TOOLTIPS_EnumToolsA (infoPtr, (UINT)wParam, (LPTTTOOLINFOA)lParam);
2602 case TTM_ENUMTOOLSW:
2603 return TOOLTIPS_EnumToolsW (infoPtr, (UINT)wParam, (LPTTTOOLINFOW)lParam);
2605 case TTM_GETBUBBLESIZE:
2606 return TOOLTIPS_GetBubbleSize (infoPtr, (LPTTTOOLINFOW)lParam);
2608 case TTM_GETCURRENTTOOLA:
2609 return TOOLTIPS_GetCurrentToolA (infoPtr, (LPTTTOOLINFOA)lParam);
2611 case TTM_GETCURRENTTOOLW:
2612 return TOOLTIPS_GetCurrentToolW (infoPtr, (LPTTTOOLINFOW)lParam);
2614 case TTM_GETDELAYTIME:
2615 return TOOLTIPS_GetDelayTime (infoPtr, (DWORD)wParam);
2617 case TTM_GETMARGIN:
2618 return TOOLTIPS_GetMargin (infoPtr, (LPRECT)lParam);
2620 case TTM_GETMAXTIPWIDTH:
2621 return TOOLTIPS_GetMaxTipWidth (infoPtr);
2623 case TTM_GETTEXTA:
2624 return TOOLTIPS_GetTextA (infoPtr, (LPTTTOOLINFOA)lParam);
2626 case TTM_GETTEXTW:
2627 return TOOLTIPS_GetTextW (infoPtr, (LPTTTOOLINFOW)lParam);
2629 case TTM_GETTIPBKCOLOR:
2630 return TOOLTIPS_GetTipBkColor (infoPtr);
2632 case TTM_GETTIPTEXTCOLOR:
2633 return TOOLTIPS_GetTipTextColor (infoPtr);
2635 case TTM_GETTOOLCOUNT:
2636 return TOOLTIPS_GetToolCount (infoPtr);
2638 case TTM_GETTOOLINFOA:
2639 return TOOLTIPS_GetToolInfoA (infoPtr, (LPTTTOOLINFOA)lParam);
2641 case TTM_GETTOOLINFOW:
2642 return TOOLTIPS_GetToolInfoW (infoPtr, (LPTTTOOLINFOW)lParam);
2644 case TTM_HITTESTA:
2645 return TOOLTIPS_HitTestA (infoPtr, (LPTTHITTESTINFOA)lParam);
2647 case TTM_HITTESTW:
2648 return TOOLTIPS_HitTestW (infoPtr, (LPTTHITTESTINFOW)lParam);
2650 case TTM_NEWTOOLRECTA:
2651 return TOOLTIPS_NewToolRectA (infoPtr, (LPTTTOOLINFOA)lParam);
2653 case TTM_NEWTOOLRECTW:
2654 return TOOLTIPS_NewToolRectW (infoPtr, (LPTTTOOLINFOW)lParam);
2656 case TTM_POP:
2657 return TOOLTIPS_Pop (infoPtr);
2659 case TTM_RELAYEVENT:
2660 return TOOLTIPS_RelayEvent (infoPtr, (LPMSG)lParam);
2662 case TTM_SETDELAYTIME:
2663 return TOOLTIPS_SetDelayTime (infoPtr, (DWORD)wParam, (INT)LOWORD(lParam));
2665 case TTM_SETMARGIN:
2666 return TOOLTIPS_SetMargin (infoPtr, (LPRECT)lParam);
2668 case TTM_SETMAXTIPWIDTH:
2669 return TOOLTIPS_SetMaxTipWidth (infoPtr, (INT)lParam);
2671 case TTM_SETTIPBKCOLOR:
2672 return TOOLTIPS_SetTipBkColor (infoPtr, (COLORREF)wParam);
2674 case TTM_SETTIPTEXTCOLOR:
2675 return TOOLTIPS_SetTipTextColor (infoPtr, (COLORREF)wParam);
2677 case TTM_SETTITLEA:
2678 return TOOLTIPS_SetTitleA (infoPtr, (UINT_PTR)wParam, (LPCSTR)lParam);
2680 case TTM_SETTITLEW:
2681 return TOOLTIPS_SetTitleW (infoPtr, (UINT_PTR)wParam, (LPCWSTR)lParam);
2683 case TTM_SETTOOLINFOA:
2684 return TOOLTIPS_SetToolInfoA (infoPtr, (LPTTTOOLINFOA)lParam);
2686 case TTM_SETTOOLINFOW:
2687 return TOOLTIPS_SetToolInfoW (infoPtr, (LPTTTOOLINFOW)lParam);
2689 case TTM_TRACKACTIVATE:
2690 return TOOLTIPS_TrackActivate (infoPtr, (BOOL)wParam, (LPTTTOOLINFOA)lParam);
2692 case TTM_TRACKPOSITION:
2693 return TOOLTIPS_TrackPosition (infoPtr, lParam);
2695 case TTM_UPDATE:
2696 return TOOLTIPS_Update (infoPtr);
2698 case TTM_UPDATETIPTEXTA:
2699 return TOOLTIPS_UpdateTipTextA (infoPtr, (LPTTTOOLINFOA)lParam);
2701 case TTM_UPDATETIPTEXTW:
2702 return TOOLTIPS_UpdateTipTextW (infoPtr, (LPTTTOOLINFOW)lParam);
2704 case TTM_WINDOWFROMPOINT:
2705 return TOOLTIPS_WindowFromPoint (hwnd, wParam, lParam);
2708 case WM_CREATE:
2709 return TOOLTIPS_Create (hwnd, (LPCREATESTRUCTW)lParam);
2711 case WM_DESTROY:
2712 return TOOLTIPS_Destroy (infoPtr);
2714 case WM_ERASEBKGND:
2715 /* we draw the background in WM_PAINT */
2716 return 0;
2718 case WM_GETFONT:
2719 return TOOLTIPS_GetFont (infoPtr);
2721 case WM_GETTEXT:
2722 return TOOLTIPS_OnWMGetText (infoPtr, wParam, (LPWSTR)lParam);
2724 case WM_GETTEXTLENGTH:
2725 return TOOLTIPS_GetTextLength (infoPtr);
2727 case WM_LBUTTONDOWN:
2728 case WM_LBUTTONUP:
2729 case WM_MBUTTONDOWN:
2730 case WM_MBUTTONUP:
2731 case WM_RBUTTONDOWN:
2732 case WM_RBUTTONUP:
2733 case WM_MOUSEMOVE:
2734 return TOOLTIPS_MouseMessage (infoPtr);
2736 case WM_NCCREATE:
2737 return TOOLTIPS_NCCreate (hwnd, (LPCREATESTRUCTW)lParam);
2739 case WM_NCHITTEST:
2740 return TOOLTIPS_NCHitTest (infoPtr, wParam, lParam);
2742 case WM_NOTIFYFORMAT:
2743 return TOOLTIPS_NotifyFormat (infoPtr, wParam, lParam);
2745 case WM_PRINTCLIENT:
2746 case WM_PAINT:
2747 return TOOLTIPS_Paint (infoPtr, (HDC)wParam);
2749 case WM_SETFONT:
2750 return TOOLTIPS_SetFont (infoPtr, (HFONT)wParam, LOWORD(lParam));
2752 case WM_SYSCOLORCHANGE:
2753 COMCTL32_RefreshSysColors();
2754 return 0;
2756 case WM_TIMER:
2757 return TOOLTIPS_Timer (infoPtr, (INT)wParam);
2759 case WM_WININICHANGE:
2760 return TOOLTIPS_WinIniChange (infoPtr);
2762 default:
2763 if ((uMsg >= WM_USER) && (uMsg < WM_APP) && !COMCTL32_IsReflectedMessage(uMsg))
2764 ERR("unknown msg %04x wp=%08lx lp=%08lx\n",
2765 uMsg, wParam, lParam);
2766 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
2771 VOID
2772 TOOLTIPS_Register (void)
2774 WNDCLASSW wndClass;
2776 ZeroMemory (&wndClass, sizeof(WNDCLASSW));
2777 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS | CS_SAVEBITS;
2778 wndClass.lpfnWndProc = TOOLTIPS_WindowProc;
2779 wndClass.cbClsExtra = 0;
2780 wndClass.cbWndExtra = sizeof(TOOLTIPS_INFO *);
2781 wndClass.hCursor = LoadCursorW (0, (LPWSTR)IDC_ARROW);
2782 wndClass.hbrBackground = 0;
2783 wndClass.lpszClassName = TOOLTIPS_CLASSW;
2785 RegisterClassW (&wndClass);
2787 hTooltipIcons[TTI_NONE] = NULL;
2788 hTooltipIcons[TTI_INFO] = LoadImageW(COMCTL32_hModule,
2789 (LPCWSTR)MAKEINTRESOURCE(IDI_TT_INFO_SM), IMAGE_ICON, 0, 0, 0);
2790 hTooltipIcons[TTI_WARNING] = LoadImageW(COMCTL32_hModule,
2791 (LPCWSTR)MAKEINTRESOURCE(IDI_TT_WARN_SM), IMAGE_ICON, 0, 0, 0);
2792 hTooltipIcons[TTI_ERROR] = LoadImageW(COMCTL32_hModule,
2793 (LPCWSTR)MAKEINTRESOURCE(IDI_TT_ERROR_SM), IMAGE_ICON, 0, 0, 0);
2797 VOID
2798 TOOLTIPS_Unregister (void)
2800 int i;
2801 for (i = TTI_INFO; i <= TTI_ERROR; i++)
2802 DestroyIcon(hTooltipIcons[i]);
2803 UnregisterClassW (TOOLTIPS_CLASSW, NULL);