Added YUV routines needed for v4l driver, and in the future possibly
[wine/gsoc-2012-control.git] / dlls / comctl32 / tooltips.c
blob80073d47935f25fe6088fd71f73f1fc547b3e964
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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 uId;
117 RECT rect;
118 HINSTANCE hinst;
119 LPWSTR lpszText;
120 LPARAM lParam;
121 } TTTOOL_INFO;
124 typedef struct
126 WCHAR szTipText[INFOTIPSIZE];
127 BOOL bActive;
128 BOOL bTrackActive;
129 UINT uNumTools;
130 COLORREF clrBk;
131 COLORREF clrText;
132 HFONT hFont;
133 HFONT hTitleFont;
134 INT xTrackPos;
135 INT yTrackPos;
136 INT nMaxTipWidth;
137 INT nTool; /* tool that mouse was on on last relayed mouse move */
138 INT nCurrentTool;
139 INT nTrackTool;
140 INT nReshowTime;
141 INT nAutoPopTime;
142 INT nInitialTime;
143 RECT rcMargin;
144 BOOL bToolBelow;
145 LPWSTR pszTitle;
146 HICON hTitleIcon;
148 TTTOOL_INFO *tools;
149 } TOOLTIPS_INFO;
151 #define ID_TIMERSHOW 1 /* show delay timer */
152 #define ID_TIMERPOP 2 /* auto pop timer */
153 #define ID_TIMERLEAVE 3 /* tool leave timer */
156 #define TOOLTIPS_GetInfoPtr(hWindow) ((TOOLTIPS_INFO *)GetWindowLongPtrW (hWindow, 0))
158 /* offsets from window edge to start of text */
159 #define NORMAL_TEXT_MARGIN 2
160 #define BALLOON_TEXT_MARGIN (NORMAL_TEXT_MARGIN+8)
161 /* value used for CreateRoundRectRgn that specifies how much
162 * each corner is curved */
163 #define BALLOON_ROUNDEDNESS 20
164 #define BALLOON_STEMHEIGHT 13
165 #define BALLOON_STEMWIDTH 10
166 #define BALLOON_STEMINDENT 20
168 #define BALLOON_ICON_TITLE_SPACING 8 /* horizontal spacing between icon and title */
169 #define BALLOON_TITLE_TEXT_SPACING 8 /* vertical spacing between icon/title and main text */
170 #define ICON_HEIGHT 16
171 #define ICON_WIDTH 16
173 static LRESULT CALLBACK
174 TOOLTIPS_SubclassProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uId, DWORD_PTR dwRef);
177 inline static UINT_PTR
178 TOOLTIPS_GetTitleIconIndex(HICON hIcon)
180 UINT i;
181 for (i = 0; i <= TTI_ERROR; i++)
182 if (hTooltipIcons[i] == hIcon)
183 return i;
184 return (UINT_PTR)hIcon;
187 static void
188 TOOLTIPS_InitSystemSettings (TOOLTIPS_INFO *infoPtr)
190 NONCLIENTMETRICSW nclm;
192 infoPtr->clrBk = GetSysColor (COLOR_INFOBK);
193 infoPtr->clrText = GetSysColor (COLOR_INFOTEXT);
195 DeleteObject (infoPtr->hFont);
196 nclm.cbSize = sizeof(nclm);
197 SystemParametersInfoW (SPI_GETNONCLIENTMETRICS, sizeof(nclm), &nclm, 0);
198 infoPtr->hFont = CreateFontIndirectW (&nclm.lfStatusFont);
200 DeleteObject (infoPtr->hTitleFont);
201 nclm.lfStatusFont.lfWeight = FW_BOLD;
202 infoPtr->hTitleFont = CreateFontIndirectW (&nclm.lfStatusFont);
205 static void
206 TOOLTIPS_Refresh (HWND hwnd, HDC hdc)
208 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr(hwnd);
209 RECT rc;
210 INT oldBkMode;
211 HFONT hOldFont;
212 HBRUSH hBrush;
213 UINT uFlags = DT_EXTERNALLEADING;
214 HRGN hRgn = NULL;
215 DWORD dwStyle = GetWindowLongW(hwnd, GWL_STYLE);
217 if (infoPtr->nMaxTipWidth > -1)
218 uFlags |= DT_WORDBREAK;
219 if (GetWindowLongW (hwnd, GWL_STYLE) & TTS_NOPREFIX)
220 uFlags |= DT_NOPREFIX;
221 GetClientRect (hwnd, &rc);
223 hBrush = CreateSolidBrush(infoPtr->clrBk);
225 oldBkMode = SetBkMode (hdc, TRANSPARENT);
226 SetTextColor (hdc, infoPtr->clrText);
228 if (dwStyle & TTS_BALLOON)
230 /* create a region to store result into */
231 hRgn = CreateRectRgn(0, 0, 0, 0);
233 GetWindowRgn(hwnd, hRgn);
235 /* fill the background */
236 FillRgn(hdc, hRgn, hBrush);
237 DeleteObject(hBrush);
238 hBrush = NULL;
240 else
242 /* fill the background */
243 FillRect(hdc, &rc, hBrush);
244 DeleteObject(hBrush);
245 hBrush = NULL;
248 if ((dwStyle & TTS_BALLOON) || infoPtr->pszTitle)
250 /* calculate text rectangle */
251 rc.left += (BALLOON_TEXT_MARGIN + infoPtr->rcMargin.left);
252 rc.top += (BALLOON_TEXT_MARGIN + infoPtr->rcMargin.top);
253 rc.right -= (BALLOON_TEXT_MARGIN + infoPtr->rcMargin.right);
254 rc.bottom -= (BALLOON_TEXT_MARGIN + infoPtr->rcMargin.bottom);
255 if(infoPtr->bToolBelow) rc.top += BALLOON_STEMHEIGHT;
257 if (infoPtr->pszTitle)
259 RECT rcTitle = {rc.left, rc.top, rc.right, rc.bottom};
260 int height;
261 BOOL icon_present;
263 /* draw icon */
264 icon_present = infoPtr->hTitleIcon &&
265 DrawIconEx(hdc, rc.left, rc.top, infoPtr->hTitleIcon,
266 ICON_WIDTH, ICON_HEIGHT, 0, NULL, DI_NORMAL);
267 if (icon_present)
268 rcTitle.left += ICON_WIDTH + BALLOON_ICON_TITLE_SPACING;
270 rcTitle.bottom = rc.top + ICON_HEIGHT;
272 /* draw title text */
273 hOldFont = SelectObject (hdc, infoPtr->hTitleFont);
274 height = DrawTextW(hdc, infoPtr->pszTitle, -1, &rcTitle, DT_BOTTOM | DT_SINGLELINE | DT_NOPREFIX);
275 SelectObject (hdc, hOldFont);
276 rc.top += height + BALLOON_TITLE_TEXT_SPACING;
279 else
281 /* calculate text rectangle */
282 rc.left += (NORMAL_TEXT_MARGIN + infoPtr->rcMargin.left);
283 rc.top += (NORMAL_TEXT_MARGIN + infoPtr->rcMargin.top);
284 rc.right -= (NORMAL_TEXT_MARGIN + infoPtr->rcMargin.right);
285 rc.bottom -= (NORMAL_TEXT_MARGIN + infoPtr->rcMargin.bottom);
288 /* draw text */
289 hOldFont = SelectObject (hdc, infoPtr->hFont);
290 DrawTextW (hdc, infoPtr->szTipText, -1, &rc, uFlags);
291 /* be polite and reset the things we changed in the dc */
292 SelectObject (hdc, hOldFont);
293 SetBkMode (hdc, oldBkMode);
295 if (dwStyle & TTS_BALLOON)
297 /* frame region because default window proc doesn't do it */
298 INT width = GetSystemMetrics(SM_CXDLGFRAME) - GetSystemMetrics(SM_CXEDGE);
299 INT height = GetSystemMetrics(SM_CYDLGFRAME) - GetSystemMetrics(SM_CYEDGE);
301 hBrush = GetSysColorBrush(COLOR_WINDOWFRAME);
302 FrameRgn(hdc, hRgn, hBrush, width, height);
305 if (hRgn)
306 DeleteObject(hRgn);
309 static void TOOLTIPS_GetDispInfoA(HWND hwnd, TOOLTIPS_INFO *infoPtr, TTTOOL_INFO *toolPtr)
311 NMTTDISPINFOA ttnmdi;
313 /* fill NMHDR struct */
314 ZeroMemory (&ttnmdi, sizeof(NMTTDISPINFOA));
315 ttnmdi.hdr.hwndFrom = hwnd;
316 ttnmdi.hdr.idFrom = toolPtr->uId;
317 ttnmdi.hdr.code = TTN_GETDISPINFOA;
318 ttnmdi.lpszText = (LPSTR)&ttnmdi.szText;
319 ttnmdi.uFlags = toolPtr->uFlags;
320 ttnmdi.lParam = toolPtr->lParam;
322 TRACE("hdr.idFrom = %x\n", ttnmdi.hdr.idFrom);
323 SendMessageW(toolPtr->hwnd, WM_NOTIFY,
324 (WPARAM)toolPtr->uId, (LPARAM)&ttnmdi);
326 if (HIWORD((UINT)ttnmdi.lpszText) == 0) {
327 LoadStringW(ttnmdi.hinst, (UINT)ttnmdi.lpszText,
328 infoPtr->szTipText, INFOTIPSIZE);
329 if (ttnmdi.uFlags & TTF_DI_SETITEM) {
330 toolPtr->hinst = ttnmdi.hinst;
331 toolPtr->lpszText = (LPWSTR)ttnmdi.lpszText;
334 else if (ttnmdi.lpszText == 0) {
335 /* no text available */
336 infoPtr->szTipText[0] = '\0';
338 else if (ttnmdi.lpszText != LPSTR_TEXTCALLBACKA) {
339 INT max_len = (ttnmdi.lpszText == &ttnmdi.szText[0]) ?
340 sizeof(ttnmdi.szText)/sizeof(ttnmdi.szText[0]) : -1;
341 MultiByteToWideChar(CP_ACP, 0, ttnmdi.lpszText, max_len,
342 infoPtr->szTipText, INFOTIPSIZE);
343 if (ttnmdi.uFlags & TTF_DI_SETITEM) {
344 INT len = MultiByteToWideChar(CP_ACP, 0, ttnmdi.lpszText,
345 max_len, NULL, 0);
346 toolPtr->hinst = 0;
347 toolPtr->lpszText = Alloc (len * sizeof(WCHAR));
348 MultiByteToWideChar(CP_ACP, 0, ttnmdi.lpszText, -1,
349 toolPtr->lpszText, len);
352 else {
353 ERR("recursive text callback!\n");
354 infoPtr->szTipText[0] = '\0';
358 static void TOOLTIPS_GetDispInfoW(HWND hwnd, TOOLTIPS_INFO *infoPtr, TTTOOL_INFO *toolPtr)
360 NMTTDISPINFOW ttnmdi;
362 /* fill NMHDR struct */
363 ZeroMemory (&ttnmdi, sizeof(NMTTDISPINFOW));
364 ttnmdi.hdr.hwndFrom = hwnd;
365 ttnmdi.hdr.idFrom = toolPtr->uId;
366 ttnmdi.hdr.code = TTN_GETDISPINFOW;
367 ttnmdi.lpszText = (LPWSTR)&ttnmdi.szText;
368 ttnmdi.uFlags = toolPtr->uFlags;
369 ttnmdi.lParam = toolPtr->lParam;
371 TRACE("hdr.idFrom = %x\n", ttnmdi.hdr.idFrom);
372 SendMessageW(toolPtr->hwnd, WM_NOTIFY,
373 (WPARAM)toolPtr->uId, (LPARAM)&ttnmdi);
375 if (HIWORD((UINT)ttnmdi.lpszText) == 0) {
376 LoadStringW(ttnmdi.hinst, (UINT)ttnmdi.lpszText,
377 infoPtr->szTipText, INFOTIPSIZE);
378 if (ttnmdi.uFlags & TTF_DI_SETITEM) {
379 toolPtr->hinst = ttnmdi.hinst;
380 toolPtr->lpszText = ttnmdi.lpszText;
383 else if (ttnmdi.lpszText == 0) {
384 /* no text available */
385 infoPtr->szTipText[0] = '\0';
387 else if (ttnmdi.lpszText != LPSTR_TEXTCALLBACKW) {
388 INT max_len = (ttnmdi.lpszText == &ttnmdi.szText[0]) ?
389 sizeof(ttnmdi.szText)/sizeof(ttnmdi.szText[0]) : INFOTIPSIZE-1;
390 lstrcpynW(infoPtr->szTipText, ttnmdi.lpszText, max_len);
391 if (ttnmdi.uFlags & TTF_DI_SETITEM) {
392 INT len = max(strlenW(ttnmdi.lpszText), max_len);
393 toolPtr->hinst = 0;
394 toolPtr->lpszText = Alloc ((len+1) * sizeof(WCHAR));
395 memcpy(toolPtr->lpszText, ttnmdi.lpszText, (len+1) * sizeof(WCHAR));
398 else {
399 ERR("recursive text callback!\n");
400 infoPtr->szTipText[0] = '\0';
404 static void
405 TOOLTIPS_GetTipText (HWND hwnd, TOOLTIPS_INFO *infoPtr, INT nTool)
407 TTTOOL_INFO *toolPtr = &infoPtr->tools[nTool];
409 if (HIWORD((UINT)toolPtr->lpszText) == 0 && toolPtr->hinst) {
410 /* load a resource */
411 TRACE("load res string %p %x\n",
412 toolPtr->hinst, (int)toolPtr->lpszText);
413 LoadStringW (toolPtr->hinst, (UINT)toolPtr->lpszText,
414 infoPtr->szTipText, INFOTIPSIZE);
416 else if (toolPtr->lpszText) {
417 if (toolPtr->lpszText == LPSTR_TEXTCALLBACKW) {
418 if (toolPtr->bNotifyUnicode)
419 TOOLTIPS_GetDispInfoW(hwnd, infoPtr, toolPtr);
420 else
421 TOOLTIPS_GetDispInfoA(hwnd, infoPtr, toolPtr);
423 else {
424 /* the item is a usual (unicode) text */
425 lstrcpynW (infoPtr->szTipText, toolPtr->lpszText, INFOTIPSIZE);
428 else {
429 /* no text available */
430 infoPtr->szTipText[0] = L'\0';
433 TRACE("%s\n", debugstr_w(infoPtr->szTipText));
437 static void
438 TOOLTIPS_CalcTipSize (HWND hwnd, TOOLTIPS_INFO *infoPtr, LPSIZE lpSize)
440 HDC hdc;
441 HFONT hOldFont;
442 DWORD style = GetWindowLongW(hwnd, GWL_STYLE);
443 UINT uFlags = DT_EXTERNALLEADING | DT_CALCRECT;
444 RECT rc = {0, 0, 0, 0};
445 SIZE title = {0, 0};
447 if (infoPtr->nMaxTipWidth > -1) {
448 rc.right = infoPtr->nMaxTipWidth;
449 uFlags |= DT_WORDBREAK;
451 if (style & TTS_NOPREFIX)
452 uFlags |= DT_NOPREFIX;
453 TRACE("%s\n", debugstr_w(infoPtr->szTipText));
455 hdc = GetDC (hwnd);
456 if (infoPtr->pszTitle)
458 RECT rcTitle = {0, 0, 0, 0};
459 TRACE("title %s\n", debugstr_w(infoPtr->pszTitle));
460 if (infoPtr->hTitleIcon)
462 title.cx = ICON_WIDTH;
463 title.cy = ICON_HEIGHT;
465 if (title.cx != 0) title.cx += BALLOON_ICON_TITLE_SPACING;
466 hOldFont = SelectObject (hdc, infoPtr->hTitleFont);
467 DrawTextW(hdc, infoPtr->pszTitle, -1, &rcTitle, DT_SINGLELINE | DT_NOPREFIX | DT_CALCRECT);
468 SelectObject (hdc, hOldFont);
469 title.cy = max(title.cy, rcTitle.bottom - rcTitle.top) + BALLOON_TITLE_TEXT_SPACING;
470 title.cx += (rcTitle.right - rcTitle.left);
472 hOldFont = SelectObject (hdc, infoPtr->hFont);
473 DrawTextW (hdc, infoPtr->szTipText, -1, &rc, uFlags);
474 SelectObject (hdc, hOldFont);
475 ReleaseDC (hwnd, hdc);
477 if ((style & TTS_BALLOON) || infoPtr->pszTitle)
479 lpSize->cx = max(rc.right - rc.left, title.cx) + 2*BALLOON_TEXT_MARGIN +
480 infoPtr->rcMargin.left + infoPtr->rcMargin.right;
481 lpSize->cy = title.cy + rc.bottom - rc.top + 2*BALLOON_TEXT_MARGIN +
482 infoPtr->rcMargin.bottom + infoPtr->rcMargin.top +
483 BALLOON_STEMHEIGHT;
485 else
487 lpSize->cx = rc.right - rc.left + 2*NORMAL_TEXT_MARGIN +
488 infoPtr->rcMargin.left + infoPtr->rcMargin.right;
489 lpSize->cy = rc.bottom - rc.top + 2*NORMAL_TEXT_MARGIN +
490 infoPtr->rcMargin.bottom + infoPtr->rcMargin.top;
495 static void
496 TOOLTIPS_Show (HWND hwnd, TOOLTIPS_INFO *infoPtr)
498 TTTOOL_INFO *toolPtr;
499 RECT rect, wndrect;
500 SIZE size;
501 NMHDR hdr;
502 int ptfx = 0;
503 DWORD style = GetWindowLongW(hwnd, GWL_STYLE);
505 if (infoPtr->nTool == -1) {
506 TRACE("invalid tool (-1)!\n");
507 return;
510 infoPtr->nCurrentTool = infoPtr->nTool;
512 TRACE("Show tooltip pre %d! (%p)\n", infoPtr->nTool, hwnd);
514 TOOLTIPS_GetTipText (hwnd, infoPtr, infoPtr->nCurrentTool);
516 if (infoPtr->szTipText[0] == L'\0') {
517 infoPtr->nCurrentTool = -1;
518 return;
521 TRACE("Show tooltip %d!\n", infoPtr->nCurrentTool);
522 toolPtr = &infoPtr->tools[infoPtr->nCurrentTool];
524 hdr.hwndFrom = hwnd;
525 hdr.idFrom = toolPtr->uId;
526 hdr.code = TTN_SHOW;
527 SendMessageW (toolPtr->hwnd, WM_NOTIFY,
528 (WPARAM)toolPtr->uId, (LPARAM)&hdr);
530 TRACE("%s\n", debugstr_w(infoPtr->szTipText));
532 TOOLTIPS_CalcTipSize (hwnd, infoPtr, &size);
533 TRACE("size %ld x %ld\n", size.cx, size.cy);
535 if (toolPtr->uFlags & TTF_CENTERTIP) {
536 RECT rc;
538 if (toolPtr->uFlags & TTF_IDISHWND)
539 GetWindowRect ((HWND)toolPtr->uId, &rc);
540 else {
541 rc = toolPtr->rect;
542 MapWindowPoints (toolPtr->hwnd, NULL, (LPPOINT)&rc, 2);
544 rect.left = (rc.left + rc.right - size.cx) / 2;
545 if (style & TTS_BALLOON)
547 ptfx = rc.left + ((rc.right - rc.left) / 2);
548 if(rect.top - size.cy >= 0)
550 rect.top -= size.cy;
551 infoPtr->bToolBelow = FALSE;
553 else
555 infoPtr->bToolBelow = TRUE;
556 rect.top += 20;
558 rect.left = max(0, rect.left - BALLOON_STEMINDENT);
560 else
562 rect.top = rc.bottom + 2;
563 infoPtr->bToolBelow = TRUE;
566 else {
567 GetCursorPos ((LPPOINT)&rect);
568 if (style & TTS_BALLOON)
570 ptfx = rect.left;
571 if(rect.top - size.cy >= 0)
573 rect.top -= size.cy;
574 infoPtr->bToolBelow = FALSE;
576 else
578 infoPtr->bToolBelow = TRUE;
579 rect.top += 20;
581 rect.left = max(0, rect.left - BALLOON_STEMINDENT);
583 else
585 rect.top += 20;
586 infoPtr->bToolBelow = TRUE;
590 TRACE("pos %ld - %ld\n", rect.left, rect.top);
592 rect.right = rect.left + size.cx;
593 rect.bottom = rect.top + size.cy;
595 /* check position */
596 wndrect.right = GetSystemMetrics( SM_CXSCREEN );
597 if( rect.right > wndrect.right ) {
598 rect.left -= rect.right - wndrect.right + 2;
599 rect.right = wndrect.right - 2;
601 wndrect.bottom = GetSystemMetrics( SM_CYSCREEN );
602 if( rect.bottom > wndrect.bottom ) {
603 RECT rc;
605 if (toolPtr->uFlags & TTF_IDISHWND)
606 GetWindowRect ((HWND)toolPtr->uId, &rc);
607 else {
608 rc = toolPtr->rect;
609 MapWindowPoints (toolPtr->hwnd, NULL, (LPPOINT)&rc, 2);
611 rect.bottom = rc.top - 2;
612 rect.top = rect.bottom - size.cy;
615 AdjustWindowRectEx (&rect, GetWindowLongW (hwnd, GWL_STYLE),
616 FALSE, GetWindowLongW (hwnd, GWL_EXSTYLE));
618 if (style & TTS_BALLOON)
620 HRGN hRgn;
621 HRGN hrStem;
622 POINT pts[3];
624 ptfx -= rect.left;
626 if(infoPtr->bToolBelow)
628 pts[0].x = ptfx;
629 pts[0].y = 0;
630 pts[1].x = max(BALLOON_STEMINDENT, ptfx - (BALLOON_STEMWIDTH / 2));
631 pts[1].y = BALLOON_STEMHEIGHT;
632 pts[2].x = pts[1].x + BALLOON_STEMWIDTH;
633 pts[2].y = pts[1].y;
634 if(pts[2].x > (rect.right - rect.left) - BALLOON_STEMINDENT)
636 pts[2].x = (rect.right - rect.left) - BALLOON_STEMINDENT;
637 pts[1].x = pts[2].x - BALLOON_STEMWIDTH;
640 else
642 pts[0].x = max(BALLOON_STEMINDENT, ptfx - (BALLOON_STEMWIDTH / 2));
643 pts[0].y = (rect.bottom - rect.top) - BALLOON_STEMHEIGHT;
644 pts[1].x = pts[0].x + BALLOON_STEMWIDTH;
645 pts[1].y = pts[0].y;
646 pts[2].x = ptfx;
647 pts[2].y = (rect.bottom - rect.top);
648 if(pts[1].x > (rect.right - rect.left) - BALLOON_STEMINDENT)
650 pts[1].x = (rect.right - rect.left) - BALLOON_STEMINDENT;
651 pts[0].x = pts[1].x - BALLOON_STEMWIDTH;
655 hrStem = CreatePolygonRgn(pts, sizeof(pts) / sizeof(pts[0]), ALTERNATE);
657 hRgn = CreateRoundRectRgn(0,
658 (infoPtr->bToolBelow ? BALLOON_STEMHEIGHT : 0),
659 rect.right - rect.left,
660 (infoPtr->bToolBelow ? rect.bottom - rect.top : rect.bottom - rect.top - BALLOON_STEMHEIGHT),
661 BALLOON_ROUNDEDNESS, BALLOON_ROUNDEDNESS);
663 CombineRgn(hRgn, hRgn, hrStem, RGN_OR);
664 DeleteObject(hrStem);
666 SetWindowRgn(hwnd, hRgn, FALSE);
667 /* we don't free the region handle as the system deletes it when
668 * it is no longer needed */
671 SetWindowPos (hwnd, HWND_TOP, rect.left, rect.top,
672 rect.right - rect.left, rect.bottom - rect.top,
673 SWP_SHOWWINDOW | SWP_NOACTIVATE);
675 /* repaint the tooltip */
676 InvalidateRect(hwnd, NULL, TRUE);
677 UpdateWindow(hwnd);
679 SetTimer (hwnd, ID_TIMERPOP, infoPtr->nAutoPopTime, 0);
680 TRACE("timer 2 started!\n");
681 SetTimer (hwnd, ID_TIMERLEAVE, infoPtr->nReshowTime, 0);
682 TRACE("timer 3 started!\n");
686 static void
687 TOOLTIPS_Hide (HWND hwnd, TOOLTIPS_INFO *infoPtr)
689 TTTOOL_INFO *toolPtr;
690 NMHDR hdr;
692 TRACE("Hide tooltip %d! (%p)\n", infoPtr->nCurrentTool, hwnd);
694 if (infoPtr->nCurrentTool == -1)
695 return;
697 toolPtr = &infoPtr->tools[infoPtr->nCurrentTool];
698 KillTimer (hwnd, ID_TIMERPOP);
700 hdr.hwndFrom = hwnd;
701 hdr.idFrom = toolPtr->uId;
702 hdr.code = TTN_POP;
703 SendMessageW (toolPtr->hwnd, WM_NOTIFY,
704 (WPARAM)toolPtr->uId, (LPARAM)&hdr);
706 infoPtr->nCurrentTool = -1;
708 SetWindowPos (hwnd, HWND_TOP, 0, 0, 0, 0,
709 SWP_NOZORDER | SWP_HIDEWINDOW | SWP_NOACTIVATE);
713 static void
714 TOOLTIPS_TrackShow (HWND hwnd, TOOLTIPS_INFO *infoPtr)
716 TTTOOL_INFO *toolPtr;
717 RECT rect;
718 SIZE size;
719 NMHDR hdr;
721 if (infoPtr->nTrackTool == -1) {
722 TRACE("invalid tracking tool (-1)!\n");
723 return;
726 TRACE("show tracking tooltip pre %d!\n", infoPtr->nTrackTool);
728 TOOLTIPS_GetTipText (hwnd, infoPtr, infoPtr->nTrackTool);
730 if (infoPtr->szTipText[0] == L'\0') {
731 infoPtr->nTrackTool = -1;
732 return;
735 TRACE("show tracking tooltip %d!\n", infoPtr->nTrackTool);
736 toolPtr = &infoPtr->tools[infoPtr->nTrackTool];
738 hdr.hwndFrom = hwnd;
739 hdr.idFrom = toolPtr->uId;
740 hdr.code = TTN_SHOW;
741 SendMessageW (toolPtr->hwnd, WM_NOTIFY,
742 (WPARAM)toolPtr->uId, (LPARAM)&hdr);
744 TRACE("%s\n", debugstr_w(infoPtr->szTipText));
746 TOOLTIPS_CalcTipSize (hwnd, infoPtr, &size);
747 TRACE("size %ld x %ld\n", size.cx, size.cy);
749 if (toolPtr->uFlags & TTF_ABSOLUTE) {
750 rect.left = infoPtr->xTrackPos;
751 rect.top = infoPtr->yTrackPos;
753 if (toolPtr->uFlags & TTF_CENTERTIP) {
754 rect.left -= (size.cx / 2);
755 rect.top -= (size.cy / 2);
758 else {
759 RECT rcTool;
761 if (toolPtr->uFlags & TTF_IDISHWND)
762 GetWindowRect ((HWND)toolPtr->uId, &rcTool);
763 else {
764 rcTool = toolPtr->rect;
765 MapWindowPoints (toolPtr->hwnd, NULL, (LPPOINT)&rcTool, 2);
768 GetCursorPos ((LPPOINT)&rect);
769 rect.top += 20;
771 if (toolPtr->uFlags & TTF_CENTERTIP) {
772 rect.left -= (size.cx / 2);
773 rect.top -= (size.cy / 2);
776 /* smart placement */
777 if ((rect.left + size.cx > rcTool.left) && (rect.left < rcTool.right) &&
778 (rect.top + size.cy > rcTool.top) && (rect.top < rcTool.bottom))
779 rect.left = rcTool.right;
782 TRACE("pos %ld - %ld\n", rect.left, rect.top);
784 rect.right = rect.left + size.cx;
785 rect.bottom = rect.top + size.cy;
787 AdjustWindowRectEx (&rect, GetWindowLongW (hwnd, GWL_STYLE),
788 FALSE, GetWindowLongW (hwnd, GWL_EXSTYLE));
790 if (GetWindowLongW(hwnd, GWL_STYLE) & TTS_BALLOON)
792 HRGN hRgn;
794 /* FIXME: need to add pointy bit using CreatePolyRgn & CombinRgn */
795 hRgn = CreateRoundRectRgn(0, 0, rect.right - rect.left, rect.bottom - rect.top, BALLOON_ROUNDEDNESS, BALLOON_ROUNDEDNESS);
797 SetWindowRgn(hwnd, hRgn, FALSE);
798 /* we don't free the region handle as the system deletes it when
799 * it is no longer needed */
802 SetWindowPos (hwnd, HWND_TOP, rect.left, rect.top,
803 rect.right - rect.left, rect.bottom - rect.top,
804 SWP_SHOWWINDOW | SWP_NOACTIVATE );
806 InvalidateRect(hwnd, NULL, TRUE);
807 UpdateWindow(hwnd);
811 static void
812 TOOLTIPS_TrackHide (HWND hwnd, TOOLTIPS_INFO *infoPtr)
814 TTTOOL_INFO *toolPtr;
815 NMHDR hdr;
817 TRACE("hide tracking tooltip %d\n", infoPtr->nTrackTool);
819 if (infoPtr->nTrackTool == -1)
820 return;
822 toolPtr = &infoPtr->tools[infoPtr->nTrackTool];
824 hdr.hwndFrom = hwnd;
825 hdr.idFrom = toolPtr->uId;
826 hdr.code = TTN_POP;
827 SendMessageW (toolPtr->hwnd, WM_NOTIFY,
828 (WPARAM)toolPtr->uId, (LPARAM)&hdr);
830 SetWindowPos (hwnd, HWND_TOP, 0, 0, 0, 0,
831 SWP_NOZORDER | SWP_HIDEWINDOW | SWP_NOACTIVATE);
835 static INT
836 TOOLTIPS_GetToolFromInfoA (TOOLTIPS_INFO *infoPtr, LPTTTOOLINFOA lpToolInfo)
838 TTTOOL_INFO *toolPtr;
839 INT nTool;
841 for (nTool = 0; nTool < infoPtr->uNumTools; nTool++) {
842 toolPtr = &infoPtr->tools[nTool];
844 if (!(toolPtr->uFlags & TTF_IDISHWND) &&
845 (lpToolInfo->hwnd == toolPtr->hwnd) &&
846 (lpToolInfo->uId == toolPtr->uId))
847 return nTool;
850 for (nTool = 0; nTool < infoPtr->uNumTools; nTool++) {
851 toolPtr = &infoPtr->tools[nTool];
853 if ((toolPtr->uFlags & TTF_IDISHWND) &&
854 (lpToolInfo->uId == toolPtr->uId))
855 return nTool;
858 return -1;
862 static INT
863 TOOLTIPS_GetToolFromInfoW (TOOLTIPS_INFO *infoPtr, LPTTTOOLINFOW lpToolInfo)
865 TTTOOL_INFO *toolPtr;
866 INT nTool;
868 for (nTool = 0; nTool < infoPtr->uNumTools; nTool++) {
869 toolPtr = &infoPtr->tools[nTool];
871 if (!(toolPtr->uFlags & TTF_IDISHWND) &&
872 (lpToolInfo->hwnd == toolPtr->hwnd) &&
873 (lpToolInfo->uId == toolPtr->uId))
874 return nTool;
877 for (nTool = 0; nTool < infoPtr->uNumTools; nTool++) {
878 toolPtr = &infoPtr->tools[nTool];
880 if ((toolPtr->uFlags & TTF_IDISHWND) &&
881 (lpToolInfo->uId == toolPtr->uId))
882 return nTool;
885 return -1;
889 static INT
890 TOOLTIPS_GetToolFromPoint (TOOLTIPS_INFO *infoPtr, HWND hwnd, LPPOINT lpPt)
892 TTTOOL_INFO *toolPtr;
893 INT nTool;
895 for (nTool = 0; nTool < infoPtr->uNumTools; nTool++) {
896 toolPtr = &infoPtr->tools[nTool];
898 if (!(toolPtr->uFlags & TTF_IDISHWND)) {
899 if (hwnd != toolPtr->hwnd)
900 continue;
901 if (!PtInRect (&toolPtr->rect, *lpPt))
902 continue;
903 return nTool;
907 for (nTool = 0; nTool < infoPtr->uNumTools; nTool++) {
908 toolPtr = &infoPtr->tools[nTool];
910 if (toolPtr->uFlags & TTF_IDISHWND) {
911 if ((HWND)toolPtr->uId == hwnd)
912 return nTool;
916 return -1;
920 static BOOL
921 TOOLTIPS_IsWindowActive (HWND hwnd)
923 HWND hwndActive = GetActiveWindow ();
924 if (!hwndActive)
925 return FALSE;
926 if (hwndActive == hwnd)
927 return TRUE;
928 return IsChild (hwndActive, hwnd);
932 static INT
933 TOOLTIPS_CheckTool (HWND hwnd, BOOL bShowTest)
935 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
936 POINT pt;
937 HWND hwndTool;
938 INT nTool;
940 GetCursorPos (&pt);
941 hwndTool = (HWND)SendMessageW (hwnd, TTM_WINDOWFROMPOINT, 0, (LPARAM)&pt);
942 if (hwndTool == 0)
943 return -1;
945 ScreenToClient (hwndTool, &pt);
946 nTool = TOOLTIPS_GetToolFromPoint (infoPtr, hwndTool, &pt);
947 if (nTool == -1)
948 return -1;
950 if (!(GetWindowLongW (hwnd, GWL_STYLE) & TTS_ALWAYSTIP) && bShowTest) {
951 if (!TOOLTIPS_IsWindowActive (GetWindow (hwnd, GW_OWNER)))
952 return -1;
955 TRACE("tool %d\n", nTool);
957 return nTool;
961 static LRESULT
962 TOOLTIPS_Activate (HWND hwnd, WPARAM wParam, LPARAM lParam)
964 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
966 infoPtr->bActive = (BOOL)wParam;
968 if (infoPtr->bActive)
969 TRACE("activate!\n");
971 if (!(infoPtr->bActive) && (infoPtr->nCurrentTool != -1))
972 TOOLTIPS_Hide (hwnd, infoPtr);
974 return 0;
978 static LRESULT
979 TOOLTIPS_AddToolA (HWND hwnd, WPARAM wParam, LPARAM lParam)
981 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
982 LPTTTOOLINFOA lpToolInfo = (LPTTTOOLINFOA)lParam;
983 TTTOOL_INFO *toolPtr;
984 INT nResult;
986 if (lpToolInfo == NULL)
987 return FALSE;
988 if (lpToolInfo->cbSize < TTTOOLINFOA_V1_SIZE)
989 return FALSE;
991 TRACE("add tool (%p) %p %d%s!\n",
992 hwnd, lpToolInfo->hwnd, lpToolInfo->uId,
993 (lpToolInfo->uFlags & TTF_IDISHWND) ? " TTF_IDISHWND" : "");
995 if (infoPtr->uNumTools == 0) {
996 infoPtr->tools = Alloc (sizeof(TTTOOL_INFO));
997 toolPtr = infoPtr->tools;
999 else {
1000 TTTOOL_INFO *oldTools = infoPtr->tools;
1001 infoPtr->tools =
1002 Alloc (sizeof(TTTOOL_INFO) * (infoPtr->uNumTools + 1));
1003 memcpy (infoPtr->tools, oldTools,
1004 infoPtr->uNumTools * sizeof(TTTOOL_INFO));
1005 Free (oldTools);
1006 toolPtr = &infoPtr->tools[infoPtr->uNumTools];
1009 infoPtr->uNumTools++;
1011 /* copy tool data */
1012 toolPtr->uFlags = lpToolInfo->uFlags;
1013 toolPtr->hwnd = lpToolInfo->hwnd;
1014 toolPtr->uId = lpToolInfo->uId;
1015 toolPtr->rect = lpToolInfo->rect;
1016 toolPtr->hinst = lpToolInfo->hinst;
1018 if (HIWORD(lpToolInfo->lpszText) == 0) {
1019 TRACE("add string id %x!\n", (int)lpToolInfo->lpszText);
1020 toolPtr->lpszText = (LPWSTR)lpToolInfo->lpszText;
1022 else if (lpToolInfo->lpszText) {
1023 if (lpToolInfo->lpszText == LPSTR_TEXTCALLBACKA) {
1024 TRACE("add CALLBACK!\n");
1025 toolPtr->lpszText = LPSTR_TEXTCALLBACKW;
1027 else {
1028 INT len = MultiByteToWideChar(CP_ACP, 0, lpToolInfo->lpszText, -1,
1029 NULL, 0);
1030 TRACE("add text \"%s\"!\n", lpToolInfo->lpszText);
1031 toolPtr->lpszText = Alloc (len * sizeof(WCHAR));
1032 MultiByteToWideChar(CP_ACP, 0, lpToolInfo->lpszText, -1,
1033 toolPtr->lpszText, len);
1037 if (lpToolInfo->cbSize >= sizeof(TTTOOLINFOA))
1038 toolPtr->lParam = lpToolInfo->lParam;
1040 /* install subclassing hook */
1041 if (toolPtr->uFlags & TTF_SUBCLASS) {
1042 if (toolPtr->uFlags & TTF_IDISHWND) {
1043 SetWindowSubclass((HWND)toolPtr->uId, TOOLTIPS_SubclassProc, 1,
1044 (DWORD_PTR)hwnd);
1046 else {
1047 SetWindowSubclass(toolPtr->hwnd, TOOLTIPS_SubclassProc, 1,
1048 (DWORD_PTR)hwnd);
1050 TRACE("subclassing installed!\n");
1053 nResult = (INT) SendMessageW (toolPtr->hwnd, WM_NOTIFYFORMAT,
1054 (WPARAM)hwnd, (LPARAM)NF_QUERY);
1055 if (nResult == NFR_ANSI) {
1056 toolPtr->bNotifyUnicode = FALSE;
1057 TRACE(" -- WM_NOTIFYFORMAT returns: NFR_ANSI\n");
1058 } else if (nResult == NFR_UNICODE) {
1059 toolPtr->bNotifyUnicode = TRUE;
1060 TRACE(" -- WM_NOTIFYFORMAT returns: NFR_UNICODE\n");
1061 } else {
1062 TRACE (" -- WM_NOTIFYFORMAT returns: error!\n");
1065 return TRUE;
1069 static LRESULT
1070 TOOLTIPS_AddToolW (HWND hwnd, WPARAM wParam, LPARAM lParam)
1072 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1073 LPTTTOOLINFOW lpToolInfo = (LPTTTOOLINFOW)lParam;
1074 TTTOOL_INFO *toolPtr;
1075 INT nResult;
1077 if (lpToolInfo == NULL)
1078 return FALSE;
1079 if (lpToolInfo->cbSize < TTTOOLINFOW_V1_SIZE)
1080 return FALSE;
1082 TRACE("add tool (%p) %p %d%s!\n",
1083 hwnd, lpToolInfo->hwnd, lpToolInfo->uId,
1084 (lpToolInfo->uFlags & TTF_IDISHWND) ? " TTF_IDISHWND" : "");
1086 if (infoPtr->uNumTools == 0) {
1087 infoPtr->tools = Alloc (sizeof(TTTOOL_INFO));
1088 toolPtr = infoPtr->tools;
1090 else {
1091 TTTOOL_INFO *oldTools = infoPtr->tools;
1092 infoPtr->tools =
1093 Alloc (sizeof(TTTOOL_INFO) * (infoPtr->uNumTools + 1));
1094 memcpy (infoPtr->tools, oldTools,
1095 infoPtr->uNumTools * sizeof(TTTOOL_INFO));
1096 Free (oldTools);
1097 toolPtr = &infoPtr->tools[infoPtr->uNumTools];
1100 infoPtr->uNumTools++;
1102 /* copy tool data */
1103 toolPtr->uFlags = lpToolInfo->uFlags;
1104 toolPtr->hwnd = lpToolInfo->hwnd;
1105 toolPtr->uId = lpToolInfo->uId;
1106 toolPtr->rect = lpToolInfo->rect;
1107 toolPtr->hinst = lpToolInfo->hinst;
1109 if (HIWORD(lpToolInfo->lpszText) == 0) {
1110 TRACE("add string id %x!\n", (int)lpToolInfo->lpszText);
1111 toolPtr->lpszText = (LPWSTR)lpToolInfo->lpszText;
1113 else if (lpToolInfo->lpszText) {
1114 if (lpToolInfo->lpszText == LPSTR_TEXTCALLBACKW) {
1115 TRACE("add CALLBACK!\n");
1116 toolPtr->lpszText = LPSTR_TEXTCALLBACKW;
1118 else {
1119 INT len = lstrlenW (lpToolInfo->lpszText);
1120 TRACE("add text %s!\n",
1121 debugstr_w(lpToolInfo->lpszText));
1122 toolPtr->lpszText = Alloc ((len + 1)*sizeof(WCHAR));
1123 strcpyW (toolPtr->lpszText, lpToolInfo->lpszText);
1127 if (lpToolInfo->cbSize >= sizeof(TTTOOLINFOW))
1128 toolPtr->lParam = lpToolInfo->lParam;
1130 /* install subclassing hook */
1131 if (toolPtr->uFlags & TTF_SUBCLASS) {
1132 if (toolPtr->uFlags & TTF_IDISHWND) {
1133 SetWindowSubclass((HWND)toolPtr->uId, TOOLTIPS_SubclassProc, 1,
1134 (DWORD_PTR)hwnd);
1136 else {
1137 SetWindowSubclass(toolPtr->hwnd, TOOLTIPS_SubclassProc, 1,
1138 (DWORD_PTR)hwnd);
1140 TRACE("subclassing installed!\n");
1143 nResult = (INT) SendMessageW (toolPtr->hwnd, WM_NOTIFYFORMAT,
1144 (WPARAM)hwnd, (LPARAM)NF_QUERY);
1145 if (nResult == NFR_ANSI) {
1146 toolPtr->bNotifyUnicode = FALSE;
1147 TRACE(" -- WM_NOTIFYFORMAT returns: NFR_ANSI\n");
1148 } else if (nResult == NFR_UNICODE) {
1149 toolPtr->bNotifyUnicode = TRUE;
1150 TRACE(" -- WM_NOTIFYFORMAT returns: NFR_UNICODE\n");
1151 } else {
1152 TRACE (" -- WM_NOTIFYFORMAT returns: error!\n");
1155 return TRUE;
1159 static void
1160 TOOLTIPS_DelToolCommon (HWND hwnd, TOOLTIPS_INFO *infoPtr, INT nTool)
1162 TTTOOL_INFO *toolPtr;
1164 TRACE("tool %d\n", nTool);
1166 if (nTool == -1)
1167 return;
1169 /* make sure the tooltip has disappeared before deleting it */
1170 TOOLTIPS_Hide(hwnd, infoPtr);
1172 /* delete text string */
1173 toolPtr = &infoPtr->tools[nTool];
1174 if (toolPtr->lpszText) {
1175 if ( (toolPtr->lpszText != LPSTR_TEXTCALLBACKW) &&
1176 (HIWORD((INT)toolPtr->lpszText) != 0) )
1177 Free (toolPtr->lpszText);
1180 /* remove subclassing */
1181 if (toolPtr->uFlags & TTF_SUBCLASS) {
1182 if (toolPtr->uFlags & TTF_IDISHWND) {
1183 RemoveWindowSubclass((HWND)toolPtr->uId, TOOLTIPS_SubclassProc, 1);
1185 else {
1186 RemoveWindowSubclass(toolPtr->hwnd, TOOLTIPS_SubclassProc, 1);
1190 /* delete tool from tool list */
1191 if (infoPtr->uNumTools == 1) {
1192 Free (infoPtr->tools);
1193 infoPtr->tools = NULL;
1195 else {
1196 TTTOOL_INFO *oldTools = infoPtr->tools;
1197 infoPtr->tools =
1198 Alloc (sizeof(TTTOOL_INFO) * (infoPtr->uNumTools - 1));
1200 if (nTool > 0)
1201 memcpy (&infoPtr->tools[0], &oldTools[0],
1202 nTool * sizeof(TTTOOL_INFO));
1204 if (nTool < infoPtr->uNumTools - 1)
1205 memcpy (&infoPtr->tools[nTool], &oldTools[nTool + 1],
1206 (infoPtr->uNumTools - nTool - 1) * sizeof(TTTOOL_INFO));
1208 Free (oldTools);
1211 /* update any indices affected by delete */
1213 /* destroying tool that mouse was on on last relayed mouse move */
1214 if (infoPtr->nTool == nTool)
1215 /* -1 means no current tool (0 means first tool) */
1216 infoPtr->nTool = -1;
1217 else if (infoPtr->nTool > nTool)
1218 infoPtr->nTool--;
1220 if (infoPtr->nTrackTool == nTool)
1221 /* -1 means no current tool (0 means first tool) */
1222 infoPtr->nTrackTool = -1;
1223 else if (infoPtr->nTrackTool > nTool)
1224 infoPtr->nTrackTool--;
1226 if (infoPtr->nCurrentTool == nTool)
1227 /* -1 means no current tool (0 means first tool) */
1228 infoPtr->nCurrentTool = -1;
1229 else if (infoPtr->nCurrentTool > nTool)
1230 infoPtr->nCurrentTool--;
1232 infoPtr->uNumTools--;
1235 static LRESULT
1236 TOOLTIPS_DelToolA (HWND hwnd, WPARAM wParam, LPARAM lParam)
1238 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1239 LPTTTOOLINFOA lpToolInfo = (LPTTTOOLINFOA)lParam;
1240 INT nTool;
1242 if (lpToolInfo == NULL)
1243 return 0;
1244 if (lpToolInfo->cbSize < TTTOOLINFOA_V1_SIZE)
1245 return 0;
1246 if (infoPtr->uNumTools == 0)
1247 return 0;
1249 nTool = TOOLTIPS_GetToolFromInfoA (infoPtr, lpToolInfo);
1251 TOOLTIPS_DelToolCommon (hwnd, infoPtr, nTool);
1253 return 0;
1257 static LRESULT
1258 TOOLTIPS_DelToolW (HWND hwnd, WPARAM wParam, LPARAM lParam)
1260 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1261 LPTTTOOLINFOW lpToolInfo = (LPTTTOOLINFOW)lParam;
1262 INT nTool;
1264 if (lpToolInfo == NULL)
1265 return 0;
1266 if (lpToolInfo->cbSize < TTTOOLINFOW_V1_SIZE)
1267 return 0;
1268 if (infoPtr->uNumTools == 0)
1269 return 0;
1271 nTool = TOOLTIPS_GetToolFromInfoW (infoPtr, lpToolInfo);
1273 TOOLTIPS_DelToolCommon (hwnd, infoPtr, nTool);
1275 return 0;
1279 static LRESULT
1280 TOOLTIPS_EnumToolsA (HWND hwnd, WPARAM wParam, LPARAM lParam)
1282 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1283 UINT uIndex = (UINT)wParam;
1284 LPTTTOOLINFOA lpToolInfo = (LPTTTOOLINFOA)lParam;
1285 TTTOOL_INFO *toolPtr;
1287 if (lpToolInfo == NULL)
1288 return FALSE;
1289 if (lpToolInfo->cbSize < TTTOOLINFOA_V1_SIZE)
1290 return FALSE;
1291 if (uIndex >= infoPtr->uNumTools)
1292 return FALSE;
1294 TRACE("index=%u\n", uIndex);
1296 toolPtr = &infoPtr->tools[uIndex];
1298 /* copy tool data */
1299 lpToolInfo->uFlags = toolPtr->uFlags;
1300 lpToolInfo->hwnd = toolPtr->hwnd;
1301 lpToolInfo->uId = toolPtr->uId;
1302 lpToolInfo->rect = toolPtr->rect;
1303 lpToolInfo->hinst = toolPtr->hinst;
1304 /* lpToolInfo->lpszText = toolPtr->lpszText; */
1305 lpToolInfo->lpszText = NULL; /* FIXME */
1307 if (lpToolInfo->cbSize >= sizeof(TTTOOLINFOA))
1308 lpToolInfo->lParam = toolPtr->lParam;
1310 return TRUE;
1314 static LRESULT
1315 TOOLTIPS_EnumToolsW (HWND hwnd, WPARAM wParam, LPARAM lParam)
1317 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1318 UINT uIndex = (UINT)wParam;
1319 LPTTTOOLINFOW lpToolInfo = (LPTTTOOLINFOW)lParam;
1320 TTTOOL_INFO *toolPtr;
1322 if (lpToolInfo == NULL)
1323 return FALSE;
1324 if (lpToolInfo->cbSize < TTTOOLINFOW_V1_SIZE)
1325 return FALSE;
1326 if (uIndex >= infoPtr->uNumTools)
1327 return FALSE;
1329 TRACE("index=%u\n", uIndex);
1331 toolPtr = &infoPtr->tools[uIndex];
1333 /* copy tool data */
1334 lpToolInfo->uFlags = toolPtr->uFlags;
1335 lpToolInfo->hwnd = toolPtr->hwnd;
1336 lpToolInfo->uId = toolPtr->uId;
1337 lpToolInfo->rect = toolPtr->rect;
1338 lpToolInfo->hinst = toolPtr->hinst;
1339 /* lpToolInfo->lpszText = toolPtr->lpszText; */
1340 lpToolInfo->lpszText = NULL; /* FIXME */
1342 if (lpToolInfo->cbSize >= sizeof(TTTOOLINFOW))
1343 lpToolInfo->lParam = toolPtr->lParam;
1345 return TRUE;
1348 static LRESULT
1349 TOOLTIPS_GetBubbleSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
1351 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1352 LPTTTOOLINFOW lpToolInfo = (LPTTTOOLINFOW)lParam;
1353 INT nTool;
1354 SIZE size;
1356 if (lpToolInfo == NULL)
1357 return FALSE;
1358 if (lpToolInfo->cbSize < TTTOOLINFOW_V1_SIZE)
1359 return FALSE;
1361 nTool = TOOLTIPS_GetToolFromInfoW (infoPtr, lpToolInfo);
1362 if (nTool == -1) return 0;
1364 TRACE("tool %d\n", nTool);
1366 TOOLTIPS_CalcTipSize (hwnd, infoPtr, &size);
1367 TRACE("size %ld x %ld\n", size.cx, size.cy);
1369 return MAKELRESULT(size.cx, size.cy);
1372 static LRESULT
1373 TOOLTIPS_GetCurrentToolA (HWND hwnd, WPARAM wParam, LPARAM lParam)
1375 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1376 LPTTTOOLINFOA lpToolInfo = (LPTTTOOLINFOA)lParam;
1377 TTTOOL_INFO *toolPtr;
1379 if (lpToolInfo == NULL)
1380 return FALSE;
1381 if (lpToolInfo->cbSize < TTTOOLINFOA_V1_SIZE)
1382 return FALSE;
1384 if (lpToolInfo) {
1385 if (infoPtr->nCurrentTool > -1) {
1386 toolPtr = &infoPtr->tools[infoPtr->nCurrentTool];
1388 /* copy tool data */
1389 lpToolInfo->uFlags = toolPtr->uFlags;
1390 lpToolInfo->rect = toolPtr->rect;
1391 lpToolInfo->hinst = toolPtr->hinst;
1392 /* lpToolInfo->lpszText = toolPtr->lpszText; */
1393 lpToolInfo->lpszText = NULL; /* FIXME */
1395 if (lpToolInfo->cbSize >= sizeof(TTTOOLINFOA))
1396 lpToolInfo->lParam = toolPtr->lParam;
1398 return TRUE;
1400 else
1401 return FALSE;
1403 else
1404 return (infoPtr->nCurrentTool != -1);
1408 static LRESULT
1409 TOOLTIPS_GetCurrentToolW (HWND hwnd, WPARAM wParam, LPARAM lParam)
1411 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1412 LPTTTOOLINFOW lpToolInfo = (LPTTTOOLINFOW)lParam;
1413 TTTOOL_INFO *toolPtr;
1415 if (lpToolInfo == NULL)
1416 return FALSE;
1417 if (lpToolInfo->cbSize < TTTOOLINFOW_V1_SIZE)
1418 return FALSE;
1420 if (lpToolInfo) {
1421 if (infoPtr->nCurrentTool > -1) {
1422 toolPtr = &infoPtr->tools[infoPtr->nCurrentTool];
1424 /* copy tool data */
1425 lpToolInfo->uFlags = toolPtr->uFlags;
1426 lpToolInfo->rect = toolPtr->rect;
1427 lpToolInfo->hinst = toolPtr->hinst;
1428 /* lpToolInfo->lpszText = toolPtr->lpszText; */
1429 lpToolInfo->lpszText = NULL; /* FIXME */
1431 if (lpToolInfo->cbSize >= sizeof(TTTOOLINFOW))
1432 lpToolInfo->lParam = toolPtr->lParam;
1434 return TRUE;
1436 else
1437 return FALSE;
1439 else
1440 return (infoPtr->nCurrentTool != -1);
1444 static LRESULT
1445 TOOLTIPS_GetDelayTime (HWND hwnd, WPARAM wParam, LPARAM lParam)
1447 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1449 switch (wParam) {
1450 case TTDT_RESHOW:
1451 return infoPtr->nReshowTime;
1453 case TTDT_AUTOPOP:
1454 return infoPtr->nAutoPopTime;
1456 case TTDT_INITIAL:
1457 case TTDT_AUTOMATIC: /* Apparently TTDT_AUTOMATIC returns TTDT_INITIAL */
1458 return infoPtr->nInitialTime;
1460 default:
1461 WARN("Invalid wParam %x\n", wParam);
1462 break;
1465 return -1;
1469 static LRESULT
1470 TOOLTIPS_GetMargin (HWND hwnd, WPARAM wParam, LPARAM lParam)
1472 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1473 LPRECT lpRect = (LPRECT)lParam;
1475 lpRect->left = infoPtr->rcMargin.left;
1476 lpRect->right = infoPtr->rcMargin.right;
1477 lpRect->bottom = infoPtr->rcMargin.bottom;
1478 lpRect->top = infoPtr->rcMargin.top;
1480 return 0;
1484 inline static LRESULT
1485 TOOLTIPS_GetMaxTipWidth (HWND hwnd, WPARAM wParam, LPARAM lParam)
1487 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1489 return infoPtr->nMaxTipWidth;
1493 static LRESULT
1494 TOOLTIPS_GetTextA (HWND hwnd, WPARAM wParam, LPARAM lParam)
1496 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1497 LPTTTOOLINFOA lpToolInfo = (LPTTTOOLINFOA)lParam;
1498 INT nTool;
1500 if (lpToolInfo == NULL)
1501 return 0;
1502 if (lpToolInfo->cbSize < TTTOOLINFOA_V1_SIZE)
1503 return 0;
1505 nTool = TOOLTIPS_GetToolFromInfoA (infoPtr, lpToolInfo);
1506 if (nTool == -1) return 0;
1508 /* NB this API is broken, there is no way for the app to determine
1509 what size buffer it requires nor a way to specify how long the
1510 one it supplies is. We'll assume it's upto INFOTIPSIZE */
1512 WideCharToMultiByte(CP_ACP, 0, infoPtr->tools[nTool].lpszText, -1,
1513 lpToolInfo->lpszText, INFOTIPSIZE, NULL, NULL);
1515 return 0;
1519 static LRESULT
1520 TOOLTIPS_GetTextW (HWND hwnd, WPARAM wParam, LPARAM lParam)
1522 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1523 LPTTTOOLINFOW lpToolInfo = (LPTTTOOLINFOW)lParam;
1524 INT nTool;
1526 if (lpToolInfo == NULL)
1527 return 0;
1528 if (lpToolInfo->cbSize < TTTOOLINFOW_V1_SIZE)
1529 return 0;
1531 nTool = TOOLTIPS_GetToolFromInfoW (infoPtr, lpToolInfo);
1532 if (nTool == -1) return 0;
1534 strcpyW (lpToolInfo->lpszText, infoPtr->tools[nTool].lpszText);
1536 return 0;
1540 inline static LRESULT
1541 TOOLTIPS_GetTipBkColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
1543 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1544 return infoPtr->clrBk;
1548 inline static LRESULT
1549 TOOLTIPS_GetTipTextColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
1551 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1552 return infoPtr->clrText;
1556 inline static LRESULT
1557 TOOLTIPS_GetToolCount (HWND hwnd, WPARAM wParam, LPARAM lParam)
1559 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1560 return infoPtr->uNumTools;
1564 static LRESULT
1565 TOOLTIPS_GetToolInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
1567 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1568 LPTTTOOLINFOA lpToolInfo = (LPTTTOOLINFOA)lParam;
1569 TTTOOL_INFO *toolPtr;
1570 INT nTool;
1572 if (lpToolInfo == NULL)
1573 return FALSE;
1574 if (lpToolInfo->cbSize < TTTOOLINFOA_V1_SIZE)
1575 return FALSE;
1576 if (infoPtr->uNumTools == 0)
1577 return FALSE;
1579 nTool = TOOLTIPS_GetToolFromInfoA (infoPtr, lpToolInfo);
1580 if (nTool == -1)
1581 return FALSE;
1583 TRACE("tool %d\n", nTool);
1585 toolPtr = &infoPtr->tools[nTool];
1587 /* copy tool data */
1588 lpToolInfo->uFlags = toolPtr->uFlags;
1589 lpToolInfo->rect = toolPtr->rect;
1590 lpToolInfo->hinst = toolPtr->hinst;
1591 /* lpToolInfo->lpszText = toolPtr->lpszText; */
1592 lpToolInfo->lpszText = NULL; /* FIXME */
1594 if (lpToolInfo->cbSize >= sizeof(TTTOOLINFOA))
1595 lpToolInfo->lParam = toolPtr->lParam;
1597 return TRUE;
1601 static LRESULT
1602 TOOLTIPS_GetToolInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
1604 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1605 LPTTTOOLINFOW lpToolInfo = (LPTTTOOLINFOW)lParam;
1606 TTTOOL_INFO *toolPtr;
1607 INT nTool;
1609 if (lpToolInfo == NULL)
1610 return FALSE;
1611 if (lpToolInfo->cbSize < TTTOOLINFOW_V1_SIZE)
1612 return FALSE;
1613 if (infoPtr->uNumTools == 0)
1614 return FALSE;
1616 nTool = TOOLTIPS_GetToolFromInfoW (infoPtr, lpToolInfo);
1617 if (nTool == -1)
1618 return FALSE;
1620 TRACE("tool %d\n", nTool);
1622 toolPtr = &infoPtr->tools[nTool];
1624 /* copy tool data */
1625 lpToolInfo->uFlags = toolPtr->uFlags;
1626 lpToolInfo->rect = toolPtr->rect;
1627 lpToolInfo->hinst = toolPtr->hinst;
1628 /* lpToolInfo->lpszText = toolPtr->lpszText; */
1629 lpToolInfo->lpszText = NULL; /* FIXME */
1631 if (lpToolInfo->cbSize >= sizeof(TTTOOLINFOW))
1632 lpToolInfo->lParam = toolPtr->lParam;
1634 return TRUE;
1638 static LRESULT
1639 TOOLTIPS_HitTestA (HWND hwnd, WPARAM wParam, LPARAM lParam)
1641 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1642 LPTTHITTESTINFOA lptthit = (LPTTHITTESTINFOA)lParam;
1643 TTTOOL_INFO *toolPtr;
1644 INT nTool;
1646 if (lptthit == 0)
1647 return FALSE;
1649 nTool = TOOLTIPS_GetToolFromPoint (infoPtr, lptthit->hwnd, &lptthit->pt);
1650 if (nTool == -1)
1651 return FALSE;
1653 TRACE("tool %d!\n", nTool);
1655 /* copy tool data */
1656 if (lptthit->ti.cbSize >= sizeof(TTTOOLINFOA)) {
1657 toolPtr = &infoPtr->tools[nTool];
1659 lptthit->ti.uFlags = toolPtr->uFlags;
1660 lptthit->ti.hwnd = toolPtr->hwnd;
1661 lptthit->ti.uId = toolPtr->uId;
1662 lptthit->ti.rect = toolPtr->rect;
1663 lptthit->ti.hinst = toolPtr->hinst;
1664 /* lptthit->ti.lpszText = toolPtr->lpszText; */
1665 lptthit->ti.lpszText = NULL; /* FIXME */
1666 lptthit->ti.lParam = toolPtr->lParam;
1669 return TRUE;
1673 static LRESULT
1674 TOOLTIPS_HitTestW (HWND hwnd, WPARAM wParam, LPARAM lParam)
1676 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1677 LPTTHITTESTINFOW lptthit = (LPTTHITTESTINFOW)lParam;
1678 TTTOOL_INFO *toolPtr;
1679 INT nTool;
1681 if (lptthit == 0)
1682 return FALSE;
1684 nTool = TOOLTIPS_GetToolFromPoint (infoPtr, lptthit->hwnd, &lptthit->pt);
1685 if (nTool == -1)
1686 return FALSE;
1688 TRACE("tool %d!\n", nTool);
1690 /* copy tool data */
1691 if (lptthit->ti.cbSize >= sizeof(TTTOOLINFOW)) {
1692 toolPtr = &infoPtr->tools[nTool];
1694 lptthit->ti.uFlags = toolPtr->uFlags;
1695 lptthit->ti.hwnd = toolPtr->hwnd;
1696 lptthit->ti.uId = toolPtr->uId;
1697 lptthit->ti.rect = toolPtr->rect;
1698 lptthit->ti.hinst = toolPtr->hinst;
1699 /* lptthit->ti.lpszText = toolPtr->lpszText; */
1700 lptthit->ti.lpszText = NULL; /* FIXME */
1701 lptthit->ti.lParam = toolPtr->lParam;
1704 return TRUE;
1708 static LRESULT
1709 TOOLTIPS_NewToolRectA (HWND hwnd, WPARAM wParam, LPARAM lParam)
1711 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1712 LPTTTOOLINFOA lpti = (LPTTTOOLINFOA)lParam;
1713 INT nTool;
1715 if (lpti == NULL)
1716 return 0;
1717 if (lpti->cbSize < TTTOOLINFOA_V1_SIZE)
1718 return FALSE;
1720 nTool = TOOLTIPS_GetToolFromInfoA (infoPtr, lpti);
1722 TRACE("nTool = %d, rect = %s\n", nTool, wine_dbgstr_rect(&lpti->rect));
1724 if (nTool == -1) return 0;
1726 infoPtr->tools[nTool].rect = lpti->rect;
1728 return 0;
1732 static LRESULT
1733 TOOLTIPS_NewToolRectW (HWND hwnd, WPARAM wParam, LPARAM lParam)
1735 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1736 LPTTTOOLINFOW lpti = (LPTTTOOLINFOW)lParam;
1737 INT nTool;
1739 if (lpti == NULL)
1740 return 0;
1741 if (lpti->cbSize < TTTOOLINFOW_V1_SIZE)
1742 return FALSE;
1744 nTool = TOOLTIPS_GetToolFromInfoW (infoPtr, lpti);
1746 TRACE("nTool = %d, rect = %s\n", nTool, wine_dbgstr_rect(&lpti->rect));
1748 if (nTool == -1) return 0;
1750 infoPtr->tools[nTool].rect = lpti->rect;
1752 return 0;
1756 inline static LRESULT
1757 TOOLTIPS_Pop (HWND hwnd, WPARAM wParam, LPARAM lParam)
1759 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1760 TOOLTIPS_Hide (hwnd, infoPtr);
1762 return 0;
1766 static LRESULT
1767 TOOLTIPS_RelayEvent (HWND hwnd, WPARAM wParam, LPARAM lParam)
1769 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1770 LPMSG lpMsg = (LPMSG)lParam;
1771 POINT pt;
1772 INT nOldTool;
1774 if (lParam == 0) {
1775 ERR("lpMsg == NULL!\n");
1776 return 0;
1779 switch (lpMsg->message) {
1780 case WM_LBUTTONDOWN:
1781 case WM_LBUTTONUP:
1782 case WM_MBUTTONDOWN:
1783 case WM_MBUTTONUP:
1784 case WM_RBUTTONDOWN:
1785 case WM_RBUTTONUP:
1786 TOOLTIPS_Hide (hwnd, infoPtr);
1787 break;
1789 case WM_MOUSEMOVE:
1790 pt.x = LOWORD(lpMsg->lParam);
1791 pt.y = HIWORD(lpMsg->lParam);
1792 nOldTool = infoPtr->nTool;
1793 infoPtr->nTool = TOOLTIPS_GetToolFromPoint(infoPtr, lpMsg->hwnd,
1794 &pt);
1795 TRACE("tool (%p) %d %d %d\n", hwnd, nOldTool,
1796 infoPtr->nTool, infoPtr->nCurrentTool);
1797 TRACE("WM_MOUSEMOVE (%p %ld %ld)\n", hwnd, pt.x, pt.y);
1799 if (infoPtr->nTool != nOldTool) {
1800 if(infoPtr->nTool == -1) { /* Moved out of all tools */
1801 TOOLTIPS_Hide(hwnd, infoPtr);
1802 KillTimer(hwnd, ID_TIMERLEAVE);
1803 } else if (nOldTool == -1) { /* Moved from outside */
1804 if(infoPtr->bActive) {
1805 SetTimer(hwnd, ID_TIMERSHOW, infoPtr->nInitialTime, 0);
1806 TRACE("timer 1 started!\n");
1808 } else { /* Moved from one to another */
1809 TOOLTIPS_Hide (hwnd, infoPtr);
1810 KillTimer(hwnd, ID_TIMERLEAVE);
1811 if(infoPtr->bActive) {
1812 SetTimer (hwnd, ID_TIMERSHOW, infoPtr->nReshowTime, 0);
1813 TRACE("timer 1 started!\n");
1816 } else if(infoPtr->nCurrentTool != -1) { /* restart autopop */
1817 KillTimer(hwnd, ID_TIMERPOP);
1818 SetTimer(hwnd, ID_TIMERPOP, infoPtr->nAutoPopTime, 0);
1819 TRACE("timer 2 restarted\n");
1820 } else if(infoPtr->nTool != -1 && infoPtr->bActive) {
1821 /* previous show attempt didn't result in tooltip so try again */
1822 SetTimer(hwnd, ID_TIMERSHOW, infoPtr->nInitialTime, 0);
1823 TRACE("timer 1 started!\n");
1825 break;
1828 return 0;
1832 static LRESULT
1833 TOOLTIPS_SetDelayTime (HWND hwnd, WPARAM wParam, LPARAM lParam)
1835 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1836 INT nTime = (INT)LOWORD(lParam);
1838 switch (wParam) {
1839 case TTDT_AUTOMATIC:
1840 if (nTime <= 0)
1841 nTime = GetDoubleClickTime();
1842 infoPtr->nReshowTime = nTime / 5;
1843 infoPtr->nAutoPopTime = nTime * 10;
1844 infoPtr->nInitialTime = nTime;
1845 break;
1847 case TTDT_RESHOW:
1848 if(nTime < 0)
1849 nTime = GetDoubleClickTime() / 5;
1850 infoPtr->nReshowTime = nTime;
1851 break;
1853 case TTDT_AUTOPOP:
1854 if(nTime < 0)
1855 nTime = GetDoubleClickTime() * 10;
1856 infoPtr->nAutoPopTime = nTime;
1857 break;
1859 case TTDT_INITIAL:
1860 if(nTime < 0)
1861 nTime = GetDoubleClickTime();
1862 infoPtr->nInitialTime = nTime;
1863 break;
1865 default:
1866 WARN("Invalid wParam %x\n", wParam);
1867 break;
1870 return 0;
1874 static LRESULT
1875 TOOLTIPS_SetMargin (HWND hwnd, WPARAM wParam, LPARAM lParam)
1877 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1878 LPRECT lpRect = (LPRECT)lParam;
1880 infoPtr->rcMargin.left = lpRect->left;
1881 infoPtr->rcMargin.right = lpRect->right;
1882 infoPtr->rcMargin.bottom = lpRect->bottom;
1883 infoPtr->rcMargin.top = lpRect->top;
1885 return 0;
1889 inline static LRESULT
1890 TOOLTIPS_SetMaxTipWidth (HWND hwnd, WPARAM wParam, LPARAM lParam)
1892 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1893 INT nTemp = infoPtr->nMaxTipWidth;
1895 infoPtr->nMaxTipWidth = (INT)lParam;
1897 return nTemp;
1901 inline static LRESULT
1902 TOOLTIPS_SetTipBkColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
1904 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1906 infoPtr->clrBk = (COLORREF)wParam;
1908 return 0;
1912 inline static LRESULT
1913 TOOLTIPS_SetTipTextColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
1915 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1917 infoPtr->clrText = (COLORREF)wParam;
1919 return 0;
1923 static LRESULT
1924 TOOLTIPS_SetTitleA (HWND hwnd, WPARAM wParam, LPARAM lParam)
1926 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1927 LPCSTR pszTitle = (LPCSTR)lParam;
1928 UINT_PTR uTitleIcon = (UINT_PTR)wParam;
1929 UINT size;
1931 TRACE("hwnd = %p, title = %s, icon = %p\n", hwnd, debugstr_a(pszTitle),
1932 (void*)uTitleIcon);
1934 Free(infoPtr->pszTitle);
1936 if (pszTitle)
1938 size = sizeof(WCHAR)*MultiByteToWideChar(CP_ACP, 0, pszTitle, -1, NULL, 0);
1939 infoPtr->pszTitle = Alloc(size);
1940 if (!infoPtr->pszTitle)
1941 return FALSE;
1942 MultiByteToWideChar(CP_ACP, 0, pszTitle, -1, infoPtr->pszTitle, size/sizeof(WCHAR));
1944 else
1945 infoPtr->pszTitle = NULL;
1947 if (uTitleIcon <= TTI_ERROR)
1948 infoPtr->hTitleIcon = hTooltipIcons[uTitleIcon];
1949 else
1950 infoPtr->hTitleIcon = CopyIcon((HICON)wParam);
1952 return TRUE;
1956 static LRESULT
1957 TOOLTIPS_SetTitleW (HWND hwnd, WPARAM wParam, LPARAM lParam)
1959 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1960 LPCWSTR pszTitle = (LPCWSTR)lParam;
1961 UINT_PTR uTitleIcon = (UINT_PTR)wParam;
1962 UINT size;
1964 TRACE("hwnd = %p, title = %s, icon = %p\n", hwnd, debugstr_w(pszTitle),
1965 (void*)uTitleIcon);
1967 Free(infoPtr->pszTitle);
1969 if (pszTitle)
1971 size = (strlenW(pszTitle)+1)*sizeof(WCHAR);
1972 infoPtr->pszTitle = Alloc(size);
1973 if (!infoPtr->pszTitle)
1974 return FALSE;
1975 memcpy(infoPtr->pszTitle, pszTitle, size);
1977 else
1978 infoPtr->pszTitle = NULL;
1980 if (uTitleIcon <= TTI_ERROR)
1981 infoPtr->hTitleIcon = hTooltipIcons[uTitleIcon];
1982 else
1983 infoPtr->hTitleIcon = CopyIcon((HICON)wParam);
1985 TRACE("icon = %p\n", infoPtr->hTitleIcon);
1987 return TRUE;
1991 static LRESULT
1992 TOOLTIPS_SetToolInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
1994 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1995 LPTTTOOLINFOA lpToolInfo = (LPTTTOOLINFOA)lParam;
1996 TTTOOL_INFO *toolPtr;
1997 INT nTool;
1999 if (lpToolInfo == NULL)
2000 return 0;
2001 if (lpToolInfo->cbSize < TTTOOLINFOA_V1_SIZE)
2002 return 0;
2004 nTool = TOOLTIPS_GetToolFromInfoA (infoPtr, lpToolInfo);
2005 if (nTool == -1) return 0;
2007 TRACE("tool %d\n", nTool);
2009 toolPtr = &infoPtr->tools[nTool];
2011 /* copy tool data */
2012 toolPtr->uFlags = lpToolInfo->uFlags;
2013 toolPtr->hwnd = lpToolInfo->hwnd;
2014 toolPtr->uId = lpToolInfo->uId;
2015 toolPtr->rect = lpToolInfo->rect;
2016 toolPtr->hinst = lpToolInfo->hinst;
2018 if (HIWORD(lpToolInfo->lpszText) == 0) {
2019 TRACE("set string id %x!\n", (INT)lpToolInfo->lpszText);
2020 toolPtr->lpszText = (LPWSTR)lpToolInfo->lpszText;
2022 else if (lpToolInfo->lpszText) {
2023 if (lpToolInfo->lpszText == LPSTR_TEXTCALLBACKA)
2024 toolPtr->lpszText = LPSTR_TEXTCALLBACKW;
2025 else {
2026 if ( (toolPtr->lpszText) &&
2027 (HIWORD((INT)toolPtr->lpszText) != 0) ) {
2028 Free (toolPtr->lpszText);
2029 toolPtr->lpszText = NULL;
2031 if (lpToolInfo->lpszText) {
2032 INT len = MultiByteToWideChar(CP_ACP, 0, lpToolInfo->lpszText,
2033 -1, NULL, 0);
2034 toolPtr->lpszText = Alloc (len * sizeof(WCHAR));
2035 MultiByteToWideChar(CP_ACP, 0, lpToolInfo->lpszText, -1,
2036 toolPtr->lpszText, len);
2041 if (lpToolInfo->cbSize >= sizeof(TTTOOLINFOA))
2042 toolPtr->lParam = lpToolInfo->lParam;
2044 return 0;
2048 static LRESULT
2049 TOOLTIPS_SetToolInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
2051 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
2052 LPTTTOOLINFOW lpToolInfo = (LPTTTOOLINFOW)lParam;
2053 TTTOOL_INFO *toolPtr;
2054 INT nTool;
2056 if (lpToolInfo == NULL)
2057 return 0;
2058 if (lpToolInfo->cbSize < TTTOOLINFOW_V1_SIZE)
2059 return 0;
2061 nTool = TOOLTIPS_GetToolFromInfoW (infoPtr, lpToolInfo);
2062 if (nTool == -1) return 0;
2064 TRACE("tool %d\n", nTool);
2066 toolPtr = &infoPtr->tools[nTool];
2068 /* copy tool data */
2069 toolPtr->uFlags = lpToolInfo->uFlags;
2070 toolPtr->hwnd = lpToolInfo->hwnd;
2071 toolPtr->uId = lpToolInfo->uId;
2072 toolPtr->rect = lpToolInfo->rect;
2073 toolPtr->hinst = lpToolInfo->hinst;
2075 if (HIWORD(lpToolInfo->lpszText) == 0) {
2076 TRACE("set string id %x!\n", (INT)lpToolInfo->lpszText);
2077 toolPtr->lpszText = lpToolInfo->lpszText;
2079 else {
2080 if (lpToolInfo->lpszText == LPSTR_TEXTCALLBACKW)
2081 toolPtr->lpszText = LPSTR_TEXTCALLBACKW;
2082 else {
2083 if ( (toolPtr->lpszText) &&
2084 (HIWORD((INT)toolPtr->lpszText) != 0) ) {
2085 Free (toolPtr->lpszText);
2086 toolPtr->lpszText = NULL;
2088 if (lpToolInfo->lpszText) {
2089 INT len = lstrlenW (lpToolInfo->lpszText);
2090 toolPtr->lpszText = Alloc ((len+1)*sizeof(WCHAR));
2091 strcpyW (toolPtr->lpszText, lpToolInfo->lpszText);
2096 if (lpToolInfo->cbSize >= sizeof(TTTOOLINFOW))
2097 toolPtr->lParam = lpToolInfo->lParam;
2099 if (infoPtr->nCurrentTool == nTool)
2101 TOOLTIPS_GetTipText (hwnd, infoPtr, infoPtr->nCurrentTool);
2103 if (infoPtr->szTipText[0] == 0)
2104 TOOLTIPS_Hide(hwnd, infoPtr);
2105 else
2106 TOOLTIPS_Show (hwnd, infoPtr);
2109 return 0;
2113 static LRESULT
2114 TOOLTIPS_TrackActivate (HWND hwnd, WPARAM wParam, LPARAM lParam)
2116 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
2118 if ((BOOL)wParam) {
2119 LPTTTOOLINFOA lpToolInfo = (LPTTTOOLINFOA)lParam;
2121 if (lpToolInfo == NULL)
2122 return 0;
2123 if (lpToolInfo->cbSize < TTTOOLINFOA_V1_SIZE)
2124 return FALSE;
2126 /* activate */
2127 infoPtr->nTrackTool = TOOLTIPS_GetToolFromInfoA (infoPtr, lpToolInfo);
2128 if (infoPtr->nTrackTool != -1) {
2129 TRACE("activated!\n");
2130 infoPtr->bTrackActive = TRUE;
2131 TOOLTIPS_TrackShow (hwnd, infoPtr);
2134 else {
2135 /* deactivate */
2136 TOOLTIPS_TrackHide (hwnd, infoPtr);
2138 infoPtr->bTrackActive = FALSE;
2139 infoPtr->nTrackTool = -1;
2141 TRACE("deactivated!\n");
2144 return 0;
2148 static LRESULT
2149 TOOLTIPS_TrackPosition (HWND hwnd, WPARAM wParam, LPARAM lParam)
2151 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
2153 infoPtr->xTrackPos = (INT)LOWORD(lParam);
2154 infoPtr->yTrackPos = (INT)HIWORD(lParam);
2156 if (infoPtr->bTrackActive) {
2157 TRACE("[%d %d]\n",
2158 infoPtr->xTrackPos, infoPtr->yTrackPos);
2160 TOOLTIPS_TrackShow (hwnd, infoPtr);
2163 return 0;
2167 static LRESULT
2168 TOOLTIPS_Update (HWND hwnd, WPARAM wParam, LPARAM lParam)
2170 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
2172 if (infoPtr->nCurrentTool != -1)
2173 UpdateWindow (hwnd);
2175 return 0;
2179 static LRESULT
2180 TOOLTIPS_UpdateTipTextA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2182 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
2183 LPTTTOOLINFOA lpToolInfo = (LPTTTOOLINFOA)lParam;
2184 TTTOOL_INFO *toolPtr;
2185 INT nTool;
2187 if (lpToolInfo == NULL)
2188 return 0;
2189 if (lpToolInfo->cbSize < TTTOOLINFOA_V1_SIZE)
2190 return FALSE;
2192 nTool = TOOLTIPS_GetToolFromInfoA (infoPtr, lpToolInfo);
2193 if (nTool == -1) return 0;
2195 TRACE("tool %d\n", nTool);
2197 toolPtr = &infoPtr->tools[nTool];
2199 /* copy tool text */
2200 toolPtr->hinst = lpToolInfo->hinst;
2202 if (HIWORD(lpToolInfo->lpszText) == 0){
2203 toolPtr->lpszText = (LPWSTR)lpToolInfo->lpszText;
2205 else if (lpToolInfo->lpszText) {
2206 if (lpToolInfo->lpszText == LPSTR_TEXTCALLBACKA)
2207 toolPtr->lpszText = LPSTR_TEXTCALLBACKW;
2208 else {
2209 if ( (toolPtr->lpszText) &&
2210 (HIWORD((INT)toolPtr->lpszText) != 0) ) {
2211 Free (toolPtr->lpszText);
2212 toolPtr->lpszText = NULL;
2214 if (lpToolInfo->lpszText) {
2215 INT len = MultiByteToWideChar(CP_ACP, 0, lpToolInfo->lpszText,
2216 -1, NULL, 0);
2217 toolPtr->lpszText = Alloc (len * sizeof(WCHAR));
2218 MultiByteToWideChar(CP_ACP, 0, lpToolInfo->lpszText, -1,
2219 toolPtr->lpszText, len);
2224 if(infoPtr->nCurrentTool == -1) return 0;
2225 /* force repaint */
2226 if (infoPtr->bActive)
2227 TOOLTIPS_Show (hwnd, infoPtr);
2228 else if (infoPtr->bTrackActive)
2229 TOOLTIPS_TrackShow (hwnd, infoPtr);
2231 return 0;
2235 static LRESULT
2236 TOOLTIPS_UpdateTipTextW (HWND hwnd, WPARAM wParam, LPARAM lParam)
2238 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
2239 LPTTTOOLINFOW lpToolInfo = (LPTTTOOLINFOW)lParam;
2240 TTTOOL_INFO *toolPtr;
2241 INT nTool;
2243 if (lpToolInfo == NULL)
2244 return 0;
2245 if (lpToolInfo->cbSize < TTTOOLINFOW_V1_SIZE)
2246 return FALSE;
2248 nTool = TOOLTIPS_GetToolFromInfoW (infoPtr, lpToolInfo);
2249 if (nTool == -1)
2250 return 0;
2252 TRACE("tool %d\n", nTool);
2254 toolPtr = &infoPtr->tools[nTool];
2256 /* copy tool text */
2257 toolPtr->hinst = lpToolInfo->hinst;
2259 if (HIWORD(lpToolInfo->lpszText) == 0){
2260 toolPtr->lpszText = lpToolInfo->lpszText;
2262 else if (lpToolInfo->lpszText) {
2263 if (lpToolInfo->lpszText == LPSTR_TEXTCALLBACKW)
2264 toolPtr->lpszText = LPSTR_TEXTCALLBACKW;
2265 else {
2266 if ( (toolPtr->lpszText) &&
2267 (HIWORD((INT)toolPtr->lpszText) != 0) ) {
2268 Free (toolPtr->lpszText);
2269 toolPtr->lpszText = NULL;
2271 if (lpToolInfo->lpszText) {
2272 INT len = lstrlenW (lpToolInfo->lpszText);
2273 toolPtr->lpszText = Alloc ((len+1)*sizeof(WCHAR));
2274 strcpyW (toolPtr->lpszText, lpToolInfo->lpszText);
2279 if(infoPtr->nCurrentTool == -1) return 0;
2280 /* force repaint */
2281 if (infoPtr->bActive)
2282 TOOLTIPS_Show (hwnd, infoPtr);
2283 else if (infoPtr->bTrackActive)
2284 TOOLTIPS_TrackShow (hwnd, infoPtr);
2286 return 0;
2290 static LRESULT
2291 TOOLTIPS_WindowFromPoint (HWND hwnd, WPARAM wParam, LPARAM lParam)
2293 return (LRESULT)WindowFromPoint (*((LPPOINT)lParam));
2298 static LRESULT
2299 TOOLTIPS_Create (HWND hwnd, const CREATESTRUCTW *lpcs)
2301 TOOLTIPS_INFO *infoPtr;
2303 /* allocate memory for info structure */
2304 infoPtr = (TOOLTIPS_INFO *)Alloc (sizeof(TOOLTIPS_INFO));
2305 SetWindowLongPtrW (hwnd, 0, (DWORD_PTR)infoPtr);
2307 /* initialize info structure */
2308 infoPtr->bActive = TRUE;
2309 infoPtr->bTrackActive = FALSE;
2311 infoPtr->nMaxTipWidth = -1;
2312 infoPtr->nTool = -1;
2313 infoPtr->nCurrentTool = -1;
2314 infoPtr->nTrackTool = -1;
2316 /* initialize colours and fonts */
2317 TOOLTIPS_InitSystemSettings(infoPtr);
2319 TOOLTIPS_SetDelayTime(hwnd, TTDT_AUTOMATIC, 0L);
2321 SetWindowPos (hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOZORDER | SWP_HIDEWINDOW | SWP_NOACTIVATE);
2323 return 0;
2327 static LRESULT
2328 TOOLTIPS_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
2330 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
2331 TTTOOL_INFO *toolPtr;
2332 UINT i;
2334 /* free tools */
2335 if (infoPtr->tools) {
2336 for (i = 0; i < infoPtr->uNumTools; i++) {
2337 toolPtr = &infoPtr->tools[i];
2338 if (toolPtr->lpszText) {
2339 if ( (toolPtr->lpszText != LPSTR_TEXTCALLBACKW) &&
2340 (HIWORD((INT)toolPtr->lpszText) != 0) )
2342 Free (toolPtr->lpszText);
2343 toolPtr->lpszText = NULL;
2347 /* remove subclassing */
2348 if (toolPtr->uFlags & TTF_SUBCLASS) {
2349 if (toolPtr->uFlags & TTF_IDISHWND) {
2350 RemoveWindowSubclass((HWND)toolPtr->uId, TOOLTIPS_SubclassProc, 1);
2352 else {
2353 RemoveWindowSubclass(toolPtr->hwnd, TOOLTIPS_SubclassProc, 1);
2357 Free (infoPtr->tools);
2360 /* free title string */
2361 Free (infoPtr->pszTitle);
2362 /* free title icon if not a standard one */
2363 if (TOOLTIPS_GetTitleIconIndex(infoPtr->hTitleIcon) > TTI_ERROR)
2364 DeleteObject(infoPtr->hTitleIcon);
2366 /* delete fonts */
2367 DeleteObject (infoPtr->hFont);
2368 DeleteObject (infoPtr->hTitleFont);
2370 /* free tool tips info data */
2371 Free (infoPtr);
2372 SetWindowLongPtrW(hwnd, 0, 0);
2373 return 0;
2377 static LRESULT
2378 TOOLTIPS_GetFont (HWND hwnd, WPARAM wParam, LPARAM lParam)
2380 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
2382 return (LRESULT)infoPtr->hFont;
2386 static LRESULT
2387 TOOLTIPS_MouseMessage (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2389 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
2391 TOOLTIPS_Hide (hwnd, infoPtr);
2393 return 0;
2397 static LRESULT
2398 TOOLTIPS_NCCreate (HWND hwnd, WPARAM wParam, LPARAM lParam)
2400 DWORD dwStyle = GetWindowLongW (hwnd, GWL_STYLE);
2401 DWORD dwExStyle = GetWindowLongW (hwnd, GWL_EXSTYLE);
2403 dwStyle &= 0x0000FFFF;
2404 dwStyle |= (WS_POPUP | WS_BORDER | WS_CLIPSIBLINGS);
2406 /* WS_BORDER only draws a border round the window rect, not the
2407 * window region, therefore it is useless to us in balloon mode */
2408 if (dwStyle & TTS_BALLOON) dwStyle &= ~WS_BORDER;
2410 SetWindowLongW (hwnd, GWL_STYLE, dwStyle);
2412 dwExStyle |= WS_EX_TOOLWINDOW;
2413 SetWindowLongW (hwnd, GWL_EXSTYLE, dwExStyle);
2415 return TRUE;
2419 static LRESULT
2420 TOOLTIPS_NCHitTest (HWND hwnd, WPARAM wParam, LPARAM lParam)
2422 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
2423 INT nTool = (infoPtr->bTrackActive) ? infoPtr->nTrackTool : infoPtr->nTool;
2425 TRACE(" nTool=%d\n", nTool);
2427 if ((nTool > -1) && (nTool < infoPtr->uNumTools)) {
2428 if (infoPtr->tools[nTool].uFlags & TTF_TRANSPARENT) {
2429 TRACE("-- in transparent mode!\n");
2430 return HTTRANSPARENT;
2434 return DefWindowProcW (hwnd, WM_NCHITTEST, wParam, lParam);
2438 static LRESULT
2439 TOOLTIPS_NotifyFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
2441 FIXME ("hwnd=%p wParam=%x lParam=%lx\n", hwnd, wParam, lParam);
2443 return 0;
2447 static LRESULT
2448 TOOLTIPS_Paint (HWND hwnd, WPARAM wParam, LPARAM lParam)
2450 HDC hdc;
2451 PAINTSTRUCT ps;
2453 hdc = (wParam == 0) ? BeginPaint (hwnd, &ps) : (HDC)wParam;
2454 TOOLTIPS_Refresh (hwnd, hdc);
2455 if (!wParam)
2456 EndPaint (hwnd, &ps);
2457 return 0;
2461 static LRESULT
2462 TOOLTIPS_SetFont (HWND hwnd, WPARAM wParam, LPARAM lParam)
2464 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
2465 LOGFONTW lf;
2467 if(!GetObjectW((HFONT)wParam, sizeof(lf), &lf))
2468 return 0;
2470 DeleteObject (infoPtr->hFont);
2471 infoPtr->hFont = CreateFontIndirectW(&lf);
2473 DeleteObject (infoPtr->hTitleFont);
2474 lf.lfWeight = FW_BOLD;
2475 infoPtr->hTitleFont = CreateFontIndirectW(&lf);
2477 if ((LOWORD(lParam)) & (infoPtr->nCurrentTool != -1)) {
2478 FIXME("full redraw needed!\n");
2481 return 0;
2484 /******************************************************************
2485 * TOOLTIPS_GetTextLength
2487 * This function is called when the tooltip receive a
2488 * WM_GETTEXTLENGTH message.
2489 * wParam : not used
2490 * lParam : not used
2492 * returns the length, in characters, of the tip text
2494 static LRESULT
2495 TOOLTIPS_GetTextLength(HWND hwnd, WPARAM wParam, LPARAM lParam)
2497 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
2498 return strlenW(infoPtr->szTipText);
2501 /******************************************************************
2502 * TOOLTIPS_OnWMGetText
2504 * This function is called when the tooltip receive a
2505 * WM_GETTEXT message.
2506 * wParam : specifies the maximum number of characters to be copied
2507 * lParam : is the pointer to the buffer that will receive
2508 * the tip text
2510 * returns the number of characters copied
2512 static LRESULT
2513 TOOLTIPS_OnWMGetText (HWND hwnd, WPARAM wParam, LPARAM lParam)
2515 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
2516 LRESULT res;
2517 LPWSTR pszText = (LPWSTR)lParam;
2519 if(!infoPtr->szTipText || !wParam)
2520 return 0;
2522 res = min(strlenW(infoPtr->szTipText)+1, wParam);
2523 memcpy(pszText, infoPtr->szTipText, res*sizeof(WCHAR));
2524 pszText[res-1] = '\0';
2525 return res-1;
2528 static LRESULT
2529 TOOLTIPS_Timer (HWND hwnd, WPARAM wParam, LPARAM lParam)
2531 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
2532 INT nOldTool;
2534 TRACE("timer %d (%p) expired!\n", wParam, hwnd);
2536 switch (wParam) {
2537 case ID_TIMERSHOW:
2538 KillTimer (hwnd, ID_TIMERSHOW);
2539 nOldTool = infoPtr->nTool;
2540 if ((infoPtr->nTool = TOOLTIPS_CheckTool (hwnd, TRUE)) == nOldTool)
2541 TOOLTIPS_Show (hwnd, infoPtr);
2542 break;
2544 case ID_TIMERPOP:
2545 TOOLTIPS_Hide (hwnd, infoPtr);
2546 break;
2548 case ID_TIMERLEAVE:
2549 nOldTool = infoPtr->nTool;
2550 infoPtr->nTool = TOOLTIPS_CheckTool (hwnd, FALSE);
2551 TRACE("tool (%p) %d %d %d\n", hwnd, nOldTool,
2552 infoPtr->nTool, infoPtr->nCurrentTool);
2553 if (infoPtr->nTool != nOldTool) {
2554 if(infoPtr->nTool == -1) { /* Moved out of all tools */
2555 TOOLTIPS_Hide(hwnd, infoPtr);
2556 KillTimer(hwnd, ID_TIMERLEAVE);
2557 } else if (nOldTool == -1) { /* Moved from outside */
2558 ERR("How did this happen?\n");
2559 } else { /* Moved from one to another */
2560 TOOLTIPS_Hide (hwnd, infoPtr);
2561 KillTimer(hwnd, ID_TIMERLEAVE);
2562 if(infoPtr->bActive) {
2563 SetTimer (hwnd, ID_TIMERSHOW, infoPtr->nReshowTime, 0);
2564 TRACE("timer 1 started!\n");
2568 break;
2570 default:
2571 ERR("Unknown timer id %d\n", wParam);
2572 break;
2574 return 0;
2578 static LRESULT
2579 TOOLTIPS_WinIniChange (HWND hwnd, WPARAM wParam, LPARAM lParam)
2581 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
2583 TOOLTIPS_InitSystemSettings (infoPtr);
2585 return 0;
2589 static LRESULT CALLBACK
2590 TOOLTIPS_SubclassProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uID, DWORD_PTR dwRef)
2592 MSG msg;
2594 switch(uMsg) {
2595 case WM_MOUSEMOVE:
2596 case WM_LBUTTONDOWN:
2597 case WM_LBUTTONUP:
2598 case WM_MBUTTONDOWN:
2599 case WM_MBUTTONUP:
2600 case WM_RBUTTONDOWN:
2601 case WM_RBUTTONUP:
2602 msg.hwnd = hwnd;
2603 msg.message = uMsg;
2604 msg.wParam = wParam;
2605 msg.lParam = lParam;
2606 TOOLTIPS_RelayEvent((HWND)dwRef, 0, (LPARAM)&msg);
2607 break;
2609 default:
2610 break;
2612 return DefSubclassProc(hwnd, uMsg, wParam, lParam);
2616 static LRESULT CALLBACK
2617 TOOLTIPS_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2619 TRACE("hwnd=%p msg=%x wparam=%x lParam=%lx\n", hwnd, uMsg, wParam, lParam);
2620 if (!TOOLTIPS_GetInfoPtr(hwnd) && (uMsg != WM_CREATE) && (uMsg != WM_NCCREATE))
2621 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
2622 switch (uMsg)
2624 case TTM_ACTIVATE:
2625 return TOOLTIPS_Activate (hwnd, wParam, lParam);
2627 case TTM_ADDTOOLA:
2628 return TOOLTIPS_AddToolA (hwnd, wParam, lParam);
2630 case TTM_ADDTOOLW:
2631 return TOOLTIPS_AddToolW (hwnd, wParam, lParam);
2633 case TTM_DELTOOLA:
2634 return TOOLTIPS_DelToolA (hwnd, wParam, lParam);
2636 case TTM_DELTOOLW:
2637 return TOOLTIPS_DelToolW (hwnd, wParam, lParam);
2639 case TTM_ENUMTOOLSA:
2640 return TOOLTIPS_EnumToolsA (hwnd, wParam, lParam);
2642 case TTM_ENUMTOOLSW:
2643 return TOOLTIPS_EnumToolsW (hwnd, wParam, lParam);
2645 case TTM_GETBUBBLESIZE:
2646 return TOOLTIPS_GetBubbleSize (hwnd, wParam, lParam);
2648 case TTM_GETCURRENTTOOLA:
2649 return TOOLTIPS_GetCurrentToolA (hwnd, wParam, lParam);
2651 case TTM_GETCURRENTTOOLW:
2652 return TOOLTIPS_GetCurrentToolW (hwnd, wParam, lParam);
2654 case TTM_GETDELAYTIME:
2655 return TOOLTIPS_GetDelayTime (hwnd, wParam, lParam);
2657 case TTM_GETMARGIN:
2658 return TOOLTIPS_GetMargin (hwnd, wParam, lParam);
2660 case TTM_GETMAXTIPWIDTH:
2661 return TOOLTIPS_GetMaxTipWidth (hwnd, wParam, lParam);
2663 case TTM_GETTEXTA:
2664 return TOOLTIPS_GetTextA (hwnd, wParam, lParam);
2666 case TTM_GETTEXTW:
2667 return TOOLTIPS_GetTextW (hwnd, wParam, lParam);
2669 case TTM_GETTIPBKCOLOR:
2670 return TOOLTIPS_GetTipBkColor (hwnd, wParam, lParam);
2672 case TTM_GETTIPTEXTCOLOR:
2673 return TOOLTIPS_GetTipTextColor (hwnd, wParam, lParam);
2675 case TTM_GETTOOLCOUNT:
2676 return TOOLTIPS_GetToolCount (hwnd, wParam, lParam);
2678 case TTM_GETTOOLINFOA:
2679 return TOOLTIPS_GetToolInfoA (hwnd, wParam, lParam);
2681 case TTM_GETTOOLINFOW:
2682 return TOOLTIPS_GetToolInfoW (hwnd, wParam, lParam);
2684 case TTM_HITTESTA:
2685 return TOOLTIPS_HitTestA (hwnd, wParam, lParam);
2687 case TTM_HITTESTW:
2688 return TOOLTIPS_HitTestW (hwnd, wParam, lParam);
2690 case TTM_NEWTOOLRECTA:
2691 return TOOLTIPS_NewToolRectA (hwnd, wParam, lParam);
2693 case TTM_NEWTOOLRECTW:
2694 return TOOLTIPS_NewToolRectW (hwnd, wParam, lParam);
2696 case TTM_POP:
2697 return TOOLTIPS_Pop (hwnd, wParam, lParam);
2699 case TTM_RELAYEVENT:
2700 return TOOLTIPS_RelayEvent (hwnd, wParam, lParam);
2702 case TTM_SETDELAYTIME:
2703 return TOOLTIPS_SetDelayTime (hwnd, wParam, lParam);
2705 case TTM_SETMARGIN:
2706 return TOOLTIPS_SetMargin (hwnd, wParam, lParam);
2708 case TTM_SETMAXTIPWIDTH:
2709 return TOOLTIPS_SetMaxTipWidth (hwnd, wParam, lParam);
2711 case TTM_SETTIPBKCOLOR:
2712 return TOOLTIPS_SetTipBkColor (hwnd, wParam, lParam);
2714 case TTM_SETTIPTEXTCOLOR:
2715 return TOOLTIPS_SetTipTextColor (hwnd, wParam, lParam);
2717 case TTM_SETTITLEA:
2718 return TOOLTIPS_SetTitleA (hwnd, wParam, lParam);
2720 case TTM_SETTITLEW:
2721 return TOOLTIPS_SetTitleW (hwnd, wParam, lParam);
2723 case TTM_SETTOOLINFOA:
2724 return TOOLTIPS_SetToolInfoA (hwnd, wParam, lParam);
2726 case TTM_SETTOOLINFOW:
2727 return TOOLTIPS_SetToolInfoW (hwnd, wParam, lParam);
2729 case TTM_TRACKACTIVATE:
2730 return TOOLTIPS_TrackActivate (hwnd, wParam, lParam);
2732 case TTM_TRACKPOSITION:
2733 return TOOLTIPS_TrackPosition (hwnd, wParam, lParam);
2735 case TTM_UPDATE:
2736 return TOOLTIPS_Update (hwnd, wParam, lParam);
2738 case TTM_UPDATETIPTEXTA:
2739 return TOOLTIPS_UpdateTipTextA (hwnd, wParam, lParam);
2741 case TTM_UPDATETIPTEXTW:
2742 return TOOLTIPS_UpdateTipTextW (hwnd, wParam, lParam);
2744 case TTM_WINDOWFROMPOINT:
2745 return TOOLTIPS_WindowFromPoint (hwnd, wParam, lParam);
2748 case WM_CREATE:
2749 return TOOLTIPS_Create (hwnd, (LPCREATESTRUCTW)lParam);
2751 case WM_DESTROY:
2752 return TOOLTIPS_Destroy (hwnd, wParam, lParam);
2754 case WM_ERASEBKGND:
2755 /* we draw the background in WM_PAINT */
2756 return 0;
2758 case WM_GETFONT:
2759 return TOOLTIPS_GetFont (hwnd, wParam, lParam);
2761 case WM_GETTEXT:
2762 return TOOLTIPS_OnWMGetText (hwnd, wParam, lParam);
2764 case WM_GETTEXTLENGTH:
2765 return TOOLTIPS_GetTextLength (hwnd, wParam, lParam);
2767 case WM_LBUTTONDOWN:
2768 case WM_LBUTTONUP:
2769 case WM_MBUTTONDOWN:
2770 case WM_MBUTTONUP:
2771 case WM_RBUTTONDOWN:
2772 case WM_RBUTTONUP:
2773 case WM_MOUSEMOVE:
2774 return TOOLTIPS_MouseMessage (hwnd, uMsg, wParam, lParam);
2776 case WM_NCCREATE:
2777 return TOOLTIPS_NCCreate (hwnd, wParam, lParam);
2779 case WM_NCHITTEST:
2780 return TOOLTIPS_NCHitTest (hwnd, wParam, lParam);
2782 case WM_NOTIFYFORMAT:
2783 return TOOLTIPS_NotifyFormat (hwnd, wParam, lParam);
2785 case WM_PAINT:
2786 return TOOLTIPS_Paint (hwnd, wParam, lParam);
2788 case WM_SETFONT:
2789 return TOOLTIPS_SetFont (hwnd, wParam, lParam);
2791 case WM_TIMER:
2792 return TOOLTIPS_Timer (hwnd, wParam, lParam);
2794 case WM_WININICHANGE:
2795 return TOOLTIPS_WinIniChange (hwnd, wParam, lParam);
2797 default:
2798 if ((uMsg >= WM_USER) && (uMsg < WM_APP))
2799 ERR("unknown msg %04x wp=%08x lp=%08lx\n",
2800 uMsg, wParam, lParam);
2801 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
2806 VOID
2807 TOOLTIPS_Register (void)
2809 WNDCLASSW wndClass;
2811 ZeroMemory (&wndClass, sizeof(WNDCLASSW));
2812 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS | CS_SAVEBITS;
2813 wndClass.lpfnWndProc = TOOLTIPS_WindowProc;
2814 wndClass.cbClsExtra = 0;
2815 wndClass.cbWndExtra = sizeof(TOOLTIPS_INFO *);
2816 wndClass.hCursor = LoadCursorW (0, (LPWSTR)IDC_ARROW);
2817 wndClass.hbrBackground = 0;
2818 wndClass.lpszClassName = TOOLTIPS_CLASSW;
2820 RegisterClassW (&wndClass);
2822 hTooltipIcons[TTI_NONE] = NULL;
2823 hTooltipIcons[TTI_INFO] = LoadImageW(COMCTL32_hModule,
2824 (LPCWSTR)MAKEINTRESOURCE(IDI_TT_INFO_SM), IMAGE_ICON, 0, 0, 0);
2825 hTooltipIcons[TTI_WARNING] = LoadImageW(COMCTL32_hModule,
2826 (LPCWSTR)MAKEINTRESOURCE(IDI_TT_WARN_SM), IMAGE_ICON, 0, 0, 0);
2827 hTooltipIcons[TTI_ERROR] = LoadImageW(COMCTL32_hModule,
2828 (LPCWSTR)MAKEINTRESOURCE(IDI_TT_ERROR_SM), IMAGE_ICON, 0, 0, 0);
2832 VOID
2833 TOOLTIPS_Unregister (void)
2835 int i;
2836 for (i = TTI_INFO; i <= TTI_ERROR; i++)
2837 DestroyIcon(hTooltipIcons[i]);
2838 UnregisterClassW (TOOLTIPS_CLASSW, NULL);