wine.inf: We should not override existing associations.
[wine/hacks.git] / dlls / comctl32 / tooltips.c
blob83064f26795eb359ed31796fc2a6d045c4a1d9ed
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 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 (IS_INTRESOURCE(ttnmdi.lpszText)) {
327 LoadStringW(ttnmdi.hinst, LOWORD(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 (IS_INTRESOURCE(ttnmdi.lpszText)) {
376 LoadStringW(ttnmdi.hinst, LOWORD(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 (IS_INTRESOURCE(toolPtr->lpszText) && toolPtr->hinst) {
410 /* load a resource */
411 TRACE("load res string %p %x\n",
412 toolPtr->hinst, LOWORD(toolPtr->lpszText));
413 LoadStringW (toolPtr->hinst, LOWORD(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 (IS_INTRESOURCE(lpToolInfo->lpszText)) {
1019 TRACE("add string id %x!\n", LOWORD(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 (IS_INTRESOURCE(lpToolInfo->lpszText)) {
1110 TRACE("add string id %x\n", LOWORD(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 !IS_INTRESOURCE(toolPtr->lpszText) )
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 up to 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 (IS_INTRESOURCE(lpToolInfo->lpszText)) {
2019 TRACE("set string id %x\n", LOWORD(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 !IS_INTRESOURCE(toolPtr->lpszText) ) {
2028 if( toolPtr->lpszText != LPSTR_TEXTCALLBACKW)
2029 Free (toolPtr->lpszText);
2030 toolPtr->lpszText = NULL;
2032 if (lpToolInfo->lpszText) {
2033 INT len = MultiByteToWideChar(CP_ACP, 0, lpToolInfo->lpszText,
2034 -1, NULL, 0);
2035 toolPtr->lpszText = Alloc (len * sizeof(WCHAR));
2036 MultiByteToWideChar(CP_ACP, 0, lpToolInfo->lpszText, -1,
2037 toolPtr->lpszText, len);
2042 if (lpToolInfo->cbSize >= sizeof(TTTOOLINFOA))
2043 toolPtr->lParam = lpToolInfo->lParam;
2045 return 0;
2049 static LRESULT
2050 TOOLTIPS_SetToolInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
2052 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
2053 LPTTTOOLINFOW lpToolInfo = (LPTTTOOLINFOW)lParam;
2054 TTTOOL_INFO *toolPtr;
2055 INT nTool;
2057 if (lpToolInfo == NULL)
2058 return 0;
2059 if (lpToolInfo->cbSize < TTTOOLINFOW_V1_SIZE)
2060 return 0;
2062 nTool = TOOLTIPS_GetToolFromInfoW (infoPtr, lpToolInfo);
2063 if (nTool == -1) return 0;
2065 TRACE("tool %d\n", nTool);
2067 toolPtr = &infoPtr->tools[nTool];
2069 /* copy tool data */
2070 toolPtr->uFlags = lpToolInfo->uFlags;
2071 toolPtr->hwnd = lpToolInfo->hwnd;
2072 toolPtr->uId = lpToolInfo->uId;
2073 toolPtr->rect = lpToolInfo->rect;
2074 toolPtr->hinst = lpToolInfo->hinst;
2076 if (IS_INTRESOURCE(lpToolInfo->lpszText)) {
2077 TRACE("set string id %x!\n", LOWORD(lpToolInfo->lpszText));
2078 toolPtr->lpszText = lpToolInfo->lpszText;
2080 else {
2081 if (lpToolInfo->lpszText == LPSTR_TEXTCALLBACKW)
2082 toolPtr->lpszText = LPSTR_TEXTCALLBACKW;
2083 else {
2084 if ( (toolPtr->lpszText) &&
2085 !IS_INTRESOURCE(toolPtr->lpszText) ) {
2086 if( toolPtr->lpszText != LPSTR_TEXTCALLBACKW)
2087 Free (toolPtr->lpszText);
2088 toolPtr->lpszText = NULL;
2090 if (lpToolInfo->lpszText) {
2091 INT len = lstrlenW (lpToolInfo->lpszText);
2092 toolPtr->lpszText = Alloc ((len+1)*sizeof(WCHAR));
2093 strcpyW (toolPtr->lpszText, lpToolInfo->lpszText);
2098 if (lpToolInfo->cbSize >= sizeof(TTTOOLINFOW))
2099 toolPtr->lParam = lpToolInfo->lParam;
2101 if (infoPtr->nCurrentTool == nTool)
2103 TOOLTIPS_GetTipText (hwnd, infoPtr, infoPtr->nCurrentTool);
2105 if (infoPtr->szTipText[0] == 0)
2106 TOOLTIPS_Hide(hwnd, infoPtr);
2107 else
2108 TOOLTIPS_Show (hwnd, infoPtr);
2111 return 0;
2115 static LRESULT
2116 TOOLTIPS_TrackActivate (HWND hwnd, WPARAM wParam, LPARAM lParam)
2118 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
2120 if ((BOOL)wParam) {
2121 LPTTTOOLINFOA lpToolInfo = (LPTTTOOLINFOA)lParam;
2123 if (lpToolInfo == NULL)
2124 return 0;
2125 if (lpToolInfo->cbSize < TTTOOLINFOA_V1_SIZE)
2126 return FALSE;
2128 /* activate */
2129 infoPtr->nTrackTool = TOOLTIPS_GetToolFromInfoA (infoPtr, lpToolInfo);
2130 if (infoPtr->nTrackTool != -1) {
2131 TRACE("activated!\n");
2132 infoPtr->bTrackActive = TRUE;
2133 TOOLTIPS_TrackShow (hwnd, infoPtr);
2136 else {
2137 /* deactivate */
2138 TOOLTIPS_TrackHide (hwnd, infoPtr);
2140 infoPtr->bTrackActive = FALSE;
2141 infoPtr->nTrackTool = -1;
2143 TRACE("deactivated!\n");
2146 return 0;
2150 static LRESULT
2151 TOOLTIPS_TrackPosition (HWND hwnd, WPARAM wParam, LPARAM lParam)
2153 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
2155 infoPtr->xTrackPos = (INT)LOWORD(lParam);
2156 infoPtr->yTrackPos = (INT)HIWORD(lParam);
2158 if (infoPtr->bTrackActive) {
2159 TRACE("[%d %d]\n",
2160 infoPtr->xTrackPos, infoPtr->yTrackPos);
2162 TOOLTIPS_TrackShow (hwnd, infoPtr);
2165 return 0;
2169 static LRESULT
2170 TOOLTIPS_Update (HWND hwnd, WPARAM wParam, LPARAM lParam)
2172 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
2174 if (infoPtr->nCurrentTool != -1)
2175 UpdateWindow (hwnd);
2177 return 0;
2181 static LRESULT
2182 TOOLTIPS_UpdateTipTextA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2184 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
2185 LPTTTOOLINFOA lpToolInfo = (LPTTTOOLINFOA)lParam;
2186 TTTOOL_INFO *toolPtr;
2187 INT nTool;
2189 if (lpToolInfo == NULL)
2190 return 0;
2191 if (lpToolInfo->cbSize < TTTOOLINFOA_V1_SIZE)
2192 return FALSE;
2194 nTool = TOOLTIPS_GetToolFromInfoA (infoPtr, lpToolInfo);
2195 if (nTool == -1) return 0;
2197 TRACE("tool %d\n", nTool);
2199 toolPtr = &infoPtr->tools[nTool];
2201 /* copy tool text */
2202 toolPtr->hinst = lpToolInfo->hinst;
2204 if (IS_INTRESOURCE(lpToolInfo->lpszText)){
2205 toolPtr->lpszText = (LPWSTR)lpToolInfo->lpszText;
2207 else if (lpToolInfo->lpszText) {
2208 if (lpToolInfo->lpszText == LPSTR_TEXTCALLBACKA)
2209 toolPtr->lpszText = LPSTR_TEXTCALLBACKW;
2210 else {
2211 if ( (toolPtr->lpszText) &&
2212 !IS_INTRESOURCE(toolPtr->lpszText) ) {
2213 if( toolPtr->lpszText != LPSTR_TEXTCALLBACKW)
2214 Free (toolPtr->lpszText);
2215 toolPtr->lpszText = NULL;
2217 if (lpToolInfo->lpszText) {
2218 INT len = MultiByteToWideChar(CP_ACP, 0, lpToolInfo->lpszText,
2219 -1, NULL, 0);
2220 toolPtr->lpszText = Alloc (len * sizeof(WCHAR));
2221 MultiByteToWideChar(CP_ACP, 0, lpToolInfo->lpszText, -1,
2222 toolPtr->lpszText, len);
2227 if(infoPtr->nCurrentTool == -1) return 0;
2228 /* force repaint */
2229 if (infoPtr->bActive)
2230 TOOLTIPS_Show (hwnd, infoPtr);
2231 else if (infoPtr->bTrackActive)
2232 TOOLTIPS_TrackShow (hwnd, infoPtr);
2234 return 0;
2238 static LRESULT
2239 TOOLTIPS_UpdateTipTextW (HWND hwnd, WPARAM wParam, LPARAM lParam)
2241 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
2242 LPTTTOOLINFOW lpToolInfo = (LPTTTOOLINFOW)lParam;
2243 TTTOOL_INFO *toolPtr;
2244 INT nTool;
2246 if (lpToolInfo == NULL)
2247 return 0;
2248 if (lpToolInfo->cbSize < TTTOOLINFOW_V1_SIZE)
2249 return FALSE;
2251 nTool = TOOLTIPS_GetToolFromInfoW (infoPtr, lpToolInfo);
2252 if (nTool == -1)
2253 return 0;
2255 TRACE("tool %d\n", nTool);
2257 toolPtr = &infoPtr->tools[nTool];
2259 /* copy tool text */
2260 toolPtr->hinst = lpToolInfo->hinst;
2262 if (IS_INTRESOURCE(lpToolInfo->lpszText)){
2263 toolPtr->lpszText = lpToolInfo->lpszText;
2265 else if (lpToolInfo->lpszText) {
2266 if (lpToolInfo->lpszText == LPSTR_TEXTCALLBACKW)
2267 toolPtr->lpszText = LPSTR_TEXTCALLBACKW;
2268 else {
2269 if ( (toolPtr->lpszText) &&
2270 !IS_INTRESOURCE(toolPtr->lpszText) ) {
2271 if( toolPtr->lpszText != LPSTR_TEXTCALLBACKW)
2272 Free (toolPtr->lpszText);
2273 toolPtr->lpszText = NULL;
2275 if (lpToolInfo->lpszText) {
2276 INT len = lstrlenW (lpToolInfo->lpszText);
2277 toolPtr->lpszText = Alloc ((len+1)*sizeof(WCHAR));
2278 strcpyW (toolPtr->lpszText, lpToolInfo->lpszText);
2283 if(infoPtr->nCurrentTool == -1) return 0;
2284 /* force repaint */
2285 if (infoPtr->bActive)
2286 TOOLTIPS_Show (hwnd, infoPtr);
2287 else if (infoPtr->bTrackActive)
2288 TOOLTIPS_TrackShow (hwnd, infoPtr);
2290 return 0;
2294 static LRESULT
2295 TOOLTIPS_WindowFromPoint (HWND hwnd, WPARAM wParam, LPARAM lParam)
2297 return (LRESULT)WindowFromPoint (*((LPPOINT)lParam));
2302 static LRESULT
2303 TOOLTIPS_Create (HWND hwnd, const CREATESTRUCTW *lpcs)
2305 TOOLTIPS_INFO *infoPtr;
2307 /* allocate memory for info structure */
2308 infoPtr = (TOOLTIPS_INFO *)Alloc (sizeof(TOOLTIPS_INFO));
2309 SetWindowLongPtrW (hwnd, 0, (DWORD_PTR)infoPtr);
2311 /* initialize info structure */
2312 infoPtr->bActive = TRUE;
2313 infoPtr->bTrackActive = FALSE;
2315 infoPtr->nMaxTipWidth = -1;
2316 infoPtr->nTool = -1;
2317 infoPtr->nCurrentTool = -1;
2318 infoPtr->nTrackTool = -1;
2320 /* initialize colours and fonts */
2321 TOOLTIPS_InitSystemSettings(infoPtr);
2323 TOOLTIPS_SetDelayTime(hwnd, TTDT_AUTOMATIC, 0L);
2325 SetWindowPos (hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOZORDER | SWP_HIDEWINDOW | SWP_NOACTIVATE);
2327 return 0;
2331 static LRESULT
2332 TOOLTIPS_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
2334 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
2335 TTTOOL_INFO *toolPtr;
2336 UINT i;
2338 /* free tools */
2339 if (infoPtr->tools) {
2340 for (i = 0; i < infoPtr->uNumTools; i++) {
2341 toolPtr = &infoPtr->tools[i];
2342 if (toolPtr->lpszText) {
2343 if ( (toolPtr->lpszText != LPSTR_TEXTCALLBACKW) &&
2344 !IS_INTRESOURCE(toolPtr->lpszText) )
2346 Free (toolPtr->lpszText);
2347 toolPtr->lpszText = NULL;
2351 /* remove subclassing */
2352 if (toolPtr->uFlags & TTF_SUBCLASS) {
2353 if (toolPtr->uFlags & TTF_IDISHWND) {
2354 RemoveWindowSubclass((HWND)toolPtr->uId, TOOLTIPS_SubclassProc, 1);
2356 else {
2357 RemoveWindowSubclass(toolPtr->hwnd, TOOLTIPS_SubclassProc, 1);
2361 Free (infoPtr->tools);
2364 /* free title string */
2365 Free (infoPtr->pszTitle);
2366 /* free title icon if not a standard one */
2367 if (TOOLTIPS_GetTitleIconIndex(infoPtr->hTitleIcon) > TTI_ERROR)
2368 DeleteObject(infoPtr->hTitleIcon);
2370 /* delete fonts */
2371 DeleteObject (infoPtr->hFont);
2372 DeleteObject (infoPtr->hTitleFont);
2374 /* free tool tips info data */
2375 Free (infoPtr);
2376 SetWindowLongPtrW(hwnd, 0, 0);
2377 return 0;
2381 static LRESULT
2382 TOOLTIPS_GetFont (HWND hwnd, WPARAM wParam, LPARAM lParam)
2384 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
2386 return (LRESULT)infoPtr->hFont;
2390 static LRESULT
2391 TOOLTIPS_MouseMessage (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2393 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
2395 TOOLTIPS_Hide (hwnd, infoPtr);
2397 return 0;
2401 static LRESULT
2402 TOOLTIPS_NCCreate (HWND hwnd, WPARAM wParam, LPARAM lParam)
2404 DWORD dwStyle = GetWindowLongW (hwnd, GWL_STYLE);
2405 DWORD dwExStyle = GetWindowLongW (hwnd, GWL_EXSTYLE);
2407 dwStyle &= ~(WS_CHILD | /*WS_MAXIMIZE |*/ WS_BORDER | WS_DLGFRAME);
2408 dwStyle |= (WS_POPUP | WS_BORDER | WS_CLIPSIBLINGS);
2410 /* WS_BORDER only draws a border round the window rect, not the
2411 * window region, therefore it is useless to us in balloon mode */
2412 if (dwStyle & TTS_BALLOON) dwStyle &= ~WS_BORDER;
2414 SetWindowLongW (hwnd, GWL_STYLE, dwStyle);
2416 dwExStyle |= WS_EX_TOOLWINDOW;
2417 SetWindowLongW (hwnd, GWL_EXSTYLE, dwExStyle);
2419 return TRUE;
2423 static LRESULT
2424 TOOLTIPS_NCHitTest (HWND hwnd, WPARAM wParam, LPARAM lParam)
2426 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
2427 INT nTool = (infoPtr->bTrackActive) ? infoPtr->nTrackTool : infoPtr->nTool;
2429 TRACE(" nTool=%d\n", nTool);
2431 if ((nTool > -1) && (nTool < infoPtr->uNumTools)) {
2432 if (infoPtr->tools[nTool].uFlags & TTF_TRANSPARENT) {
2433 TRACE("-- in transparent mode!\n");
2434 return HTTRANSPARENT;
2438 return DefWindowProcW (hwnd, WM_NCHITTEST, wParam, lParam);
2442 static LRESULT
2443 TOOLTIPS_NotifyFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
2445 FIXME ("hwnd=%p wParam=%x lParam=%lx\n", hwnd, wParam, lParam);
2447 return 0;
2451 static LRESULT
2452 TOOLTIPS_Paint (HWND hwnd, WPARAM wParam, LPARAM lParam)
2454 HDC hdc;
2455 PAINTSTRUCT ps;
2457 hdc = (wParam == 0) ? BeginPaint (hwnd, &ps) : (HDC)wParam;
2458 TOOLTIPS_Refresh (hwnd, hdc);
2459 if (!wParam)
2460 EndPaint (hwnd, &ps);
2461 return 0;
2465 static LRESULT
2466 TOOLTIPS_SetFont (HWND hwnd, WPARAM wParam, LPARAM lParam)
2468 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
2469 LOGFONTW lf;
2471 if(!GetObjectW((HFONT)wParam, sizeof(lf), &lf))
2472 return 0;
2474 DeleteObject (infoPtr->hFont);
2475 infoPtr->hFont = CreateFontIndirectW(&lf);
2477 DeleteObject (infoPtr->hTitleFont);
2478 lf.lfWeight = FW_BOLD;
2479 infoPtr->hTitleFont = CreateFontIndirectW(&lf);
2481 if ((LOWORD(lParam)) & (infoPtr->nCurrentTool != -1)) {
2482 FIXME("full redraw needed!\n");
2485 return 0;
2488 /******************************************************************
2489 * TOOLTIPS_GetTextLength
2491 * This function is called when the tooltip receive a
2492 * WM_GETTEXTLENGTH message.
2493 * wParam : not used
2494 * lParam : not used
2496 * returns the length, in characters, of the tip text
2498 static LRESULT
2499 TOOLTIPS_GetTextLength(HWND hwnd, WPARAM wParam, LPARAM lParam)
2501 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
2502 return strlenW(infoPtr->szTipText);
2505 /******************************************************************
2506 * TOOLTIPS_OnWMGetText
2508 * This function is called when the tooltip receive a
2509 * WM_GETTEXT message.
2510 * wParam : specifies the maximum number of characters to be copied
2511 * lParam : is the pointer to the buffer that will receive
2512 * the tip text
2514 * returns the number of characters copied
2516 static LRESULT
2517 TOOLTIPS_OnWMGetText (HWND hwnd, WPARAM wParam, LPARAM lParam)
2519 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
2520 LRESULT res;
2521 LPWSTR pszText = (LPWSTR)lParam;
2523 if(!infoPtr->szTipText || !wParam)
2524 return 0;
2526 res = min(strlenW(infoPtr->szTipText)+1, wParam);
2527 memcpy(pszText, infoPtr->szTipText, res*sizeof(WCHAR));
2528 pszText[res-1] = '\0';
2529 return res-1;
2532 static LRESULT
2533 TOOLTIPS_Timer (HWND hwnd, WPARAM wParam, LPARAM lParam)
2535 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
2536 INT nOldTool;
2538 TRACE("timer %d (%p) expired!\n", wParam, hwnd);
2540 switch (wParam) {
2541 case ID_TIMERSHOW:
2542 KillTimer (hwnd, ID_TIMERSHOW);
2543 nOldTool = infoPtr->nTool;
2544 if ((infoPtr->nTool = TOOLTIPS_CheckTool (hwnd, TRUE)) == nOldTool)
2545 TOOLTIPS_Show (hwnd, infoPtr);
2546 break;
2548 case ID_TIMERPOP:
2549 TOOLTIPS_Hide (hwnd, infoPtr);
2550 break;
2552 case ID_TIMERLEAVE:
2553 nOldTool = infoPtr->nTool;
2554 infoPtr->nTool = TOOLTIPS_CheckTool (hwnd, FALSE);
2555 TRACE("tool (%p) %d %d %d\n", hwnd, nOldTool,
2556 infoPtr->nTool, infoPtr->nCurrentTool);
2557 if (infoPtr->nTool != nOldTool) {
2558 if(infoPtr->nTool == -1) { /* Moved out of all tools */
2559 TOOLTIPS_Hide(hwnd, infoPtr);
2560 KillTimer(hwnd, ID_TIMERLEAVE);
2561 } else if (nOldTool == -1) { /* Moved from outside */
2562 ERR("How did this happen?\n");
2563 } else { /* Moved from one to another */
2564 TOOLTIPS_Hide (hwnd, infoPtr);
2565 KillTimer(hwnd, ID_TIMERLEAVE);
2566 if(infoPtr->bActive) {
2567 SetTimer (hwnd, ID_TIMERSHOW, infoPtr->nReshowTime, 0);
2568 TRACE("timer 1 started!\n");
2572 break;
2574 default:
2575 ERR("Unknown timer id %d\n", wParam);
2576 break;
2578 return 0;
2582 static LRESULT
2583 TOOLTIPS_WinIniChange (HWND hwnd, WPARAM wParam, LPARAM lParam)
2585 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
2587 TOOLTIPS_InitSystemSettings (infoPtr);
2589 return 0;
2593 static LRESULT CALLBACK
2594 TOOLTIPS_SubclassProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uID, DWORD_PTR dwRef)
2596 MSG msg;
2598 switch(uMsg) {
2599 case WM_MOUSEMOVE:
2600 case WM_LBUTTONDOWN:
2601 case WM_LBUTTONUP:
2602 case WM_MBUTTONDOWN:
2603 case WM_MBUTTONUP:
2604 case WM_RBUTTONDOWN:
2605 case WM_RBUTTONUP:
2606 msg.hwnd = hwnd;
2607 msg.message = uMsg;
2608 msg.wParam = wParam;
2609 msg.lParam = lParam;
2610 TOOLTIPS_RelayEvent((HWND)dwRef, 0, (LPARAM)&msg);
2611 break;
2613 default:
2614 break;
2616 return DefSubclassProc(hwnd, uMsg, wParam, lParam);
2620 static LRESULT CALLBACK
2621 TOOLTIPS_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2623 TRACE("hwnd=%p msg=%x wparam=%x lParam=%lx\n", hwnd, uMsg, wParam, lParam);
2624 if (!TOOLTIPS_GetInfoPtr(hwnd) && (uMsg != WM_CREATE) && (uMsg != WM_NCCREATE))
2625 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
2626 switch (uMsg)
2628 case TTM_ACTIVATE:
2629 return TOOLTIPS_Activate (hwnd, wParam, lParam);
2631 case TTM_ADDTOOLA:
2632 return TOOLTIPS_AddToolA (hwnd, wParam, lParam);
2634 case TTM_ADDTOOLW:
2635 return TOOLTIPS_AddToolW (hwnd, wParam, lParam);
2637 case TTM_DELTOOLA:
2638 return TOOLTIPS_DelToolA (hwnd, wParam, lParam);
2640 case TTM_DELTOOLW:
2641 return TOOLTIPS_DelToolW (hwnd, wParam, lParam);
2643 case TTM_ENUMTOOLSA:
2644 return TOOLTIPS_EnumToolsA (hwnd, wParam, lParam);
2646 case TTM_ENUMTOOLSW:
2647 return TOOLTIPS_EnumToolsW (hwnd, wParam, lParam);
2649 case TTM_GETBUBBLESIZE:
2650 return TOOLTIPS_GetBubbleSize (hwnd, wParam, lParam);
2652 case TTM_GETCURRENTTOOLA:
2653 return TOOLTIPS_GetCurrentToolA (hwnd, wParam, lParam);
2655 case TTM_GETCURRENTTOOLW:
2656 return TOOLTIPS_GetCurrentToolW (hwnd, wParam, lParam);
2658 case TTM_GETDELAYTIME:
2659 return TOOLTIPS_GetDelayTime (hwnd, wParam, lParam);
2661 case TTM_GETMARGIN:
2662 return TOOLTIPS_GetMargin (hwnd, wParam, lParam);
2664 case TTM_GETMAXTIPWIDTH:
2665 return TOOLTIPS_GetMaxTipWidth (hwnd, wParam, lParam);
2667 case TTM_GETTEXTA:
2668 return TOOLTIPS_GetTextA (hwnd, wParam, lParam);
2670 case TTM_GETTEXTW:
2671 return TOOLTIPS_GetTextW (hwnd, wParam, lParam);
2673 case TTM_GETTIPBKCOLOR:
2674 return TOOLTIPS_GetTipBkColor (hwnd, wParam, lParam);
2676 case TTM_GETTIPTEXTCOLOR:
2677 return TOOLTIPS_GetTipTextColor (hwnd, wParam, lParam);
2679 case TTM_GETTOOLCOUNT:
2680 return TOOLTIPS_GetToolCount (hwnd, wParam, lParam);
2682 case TTM_GETTOOLINFOA:
2683 return TOOLTIPS_GetToolInfoA (hwnd, wParam, lParam);
2685 case TTM_GETTOOLINFOW:
2686 return TOOLTIPS_GetToolInfoW (hwnd, wParam, lParam);
2688 case TTM_HITTESTA:
2689 return TOOLTIPS_HitTestA (hwnd, wParam, lParam);
2691 case TTM_HITTESTW:
2692 return TOOLTIPS_HitTestW (hwnd, wParam, lParam);
2694 case TTM_NEWTOOLRECTA:
2695 return TOOLTIPS_NewToolRectA (hwnd, wParam, lParam);
2697 case TTM_NEWTOOLRECTW:
2698 return TOOLTIPS_NewToolRectW (hwnd, wParam, lParam);
2700 case TTM_POP:
2701 return TOOLTIPS_Pop (hwnd, wParam, lParam);
2703 case TTM_RELAYEVENT:
2704 return TOOLTIPS_RelayEvent (hwnd, wParam, lParam);
2706 case TTM_SETDELAYTIME:
2707 return TOOLTIPS_SetDelayTime (hwnd, wParam, lParam);
2709 case TTM_SETMARGIN:
2710 return TOOLTIPS_SetMargin (hwnd, wParam, lParam);
2712 case TTM_SETMAXTIPWIDTH:
2713 return TOOLTIPS_SetMaxTipWidth (hwnd, wParam, lParam);
2715 case TTM_SETTIPBKCOLOR:
2716 return TOOLTIPS_SetTipBkColor (hwnd, wParam, lParam);
2718 case TTM_SETTIPTEXTCOLOR:
2719 return TOOLTIPS_SetTipTextColor (hwnd, wParam, lParam);
2721 case TTM_SETTITLEA:
2722 return TOOLTIPS_SetTitleA (hwnd, wParam, lParam);
2724 case TTM_SETTITLEW:
2725 return TOOLTIPS_SetTitleW (hwnd, wParam, lParam);
2727 case TTM_SETTOOLINFOA:
2728 return TOOLTIPS_SetToolInfoA (hwnd, wParam, lParam);
2730 case TTM_SETTOOLINFOW:
2731 return TOOLTIPS_SetToolInfoW (hwnd, wParam, lParam);
2733 case TTM_TRACKACTIVATE:
2734 return TOOLTIPS_TrackActivate (hwnd, wParam, lParam);
2736 case TTM_TRACKPOSITION:
2737 return TOOLTIPS_TrackPosition (hwnd, wParam, lParam);
2739 case TTM_UPDATE:
2740 return TOOLTIPS_Update (hwnd, wParam, lParam);
2742 case TTM_UPDATETIPTEXTA:
2743 return TOOLTIPS_UpdateTipTextA (hwnd, wParam, lParam);
2745 case TTM_UPDATETIPTEXTW:
2746 return TOOLTIPS_UpdateTipTextW (hwnd, wParam, lParam);
2748 case TTM_WINDOWFROMPOINT:
2749 return TOOLTIPS_WindowFromPoint (hwnd, wParam, lParam);
2752 case WM_CREATE:
2753 return TOOLTIPS_Create (hwnd, (LPCREATESTRUCTW)lParam);
2755 case WM_DESTROY:
2756 return TOOLTIPS_Destroy (hwnd, wParam, lParam);
2758 case WM_ERASEBKGND:
2759 /* we draw the background in WM_PAINT */
2760 return 0;
2762 case WM_GETFONT:
2763 return TOOLTIPS_GetFont (hwnd, wParam, lParam);
2765 case WM_GETTEXT:
2766 return TOOLTIPS_OnWMGetText (hwnd, wParam, lParam);
2768 case WM_GETTEXTLENGTH:
2769 return TOOLTIPS_GetTextLength (hwnd, wParam, lParam);
2771 case WM_LBUTTONDOWN:
2772 case WM_LBUTTONUP:
2773 case WM_MBUTTONDOWN:
2774 case WM_MBUTTONUP:
2775 case WM_RBUTTONDOWN:
2776 case WM_RBUTTONUP:
2777 case WM_MOUSEMOVE:
2778 return TOOLTIPS_MouseMessage (hwnd, uMsg, wParam, lParam);
2780 case WM_NCCREATE:
2781 return TOOLTIPS_NCCreate (hwnd, wParam, lParam);
2783 case WM_NCHITTEST:
2784 return TOOLTIPS_NCHitTest (hwnd, wParam, lParam);
2786 case WM_NOTIFYFORMAT:
2787 return TOOLTIPS_NotifyFormat (hwnd, wParam, lParam);
2789 case WM_PRINTCLIENT:
2790 case WM_PAINT:
2791 return TOOLTIPS_Paint (hwnd, wParam, lParam);
2793 case WM_SETFONT:
2794 return TOOLTIPS_SetFont (hwnd, wParam, lParam);
2796 case WM_TIMER:
2797 return TOOLTIPS_Timer (hwnd, wParam, lParam);
2799 case WM_WININICHANGE:
2800 return TOOLTIPS_WinIniChange (hwnd, wParam, lParam);
2802 default:
2803 if ((uMsg >= WM_USER) && (uMsg < WM_APP))
2804 ERR("unknown msg %04x wp=%08x lp=%08lx\n",
2805 uMsg, wParam, lParam);
2806 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
2811 VOID
2812 TOOLTIPS_Register (void)
2814 WNDCLASSW wndClass;
2816 ZeroMemory (&wndClass, sizeof(WNDCLASSW));
2817 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS | CS_SAVEBITS;
2818 wndClass.lpfnWndProc = TOOLTIPS_WindowProc;
2819 wndClass.cbClsExtra = 0;
2820 wndClass.cbWndExtra = sizeof(TOOLTIPS_INFO *);
2821 wndClass.hCursor = LoadCursorW (0, (LPWSTR)IDC_ARROW);
2822 wndClass.hbrBackground = 0;
2823 wndClass.lpszClassName = TOOLTIPS_CLASSW;
2825 RegisterClassW (&wndClass);
2827 hTooltipIcons[TTI_NONE] = NULL;
2828 hTooltipIcons[TTI_INFO] = LoadImageW(COMCTL32_hModule,
2829 (LPCWSTR)MAKEINTRESOURCE(IDI_TT_INFO_SM), IMAGE_ICON, 0, 0, 0);
2830 hTooltipIcons[TTI_WARNING] = LoadImageW(COMCTL32_hModule,
2831 (LPCWSTR)MAKEINTRESOURCE(IDI_TT_WARN_SM), IMAGE_ICON, 0, 0, 0);
2832 hTooltipIcons[TTI_ERROR] = LoadImageW(COMCTL32_hModule,
2833 (LPCWSTR)MAKEINTRESOURCE(IDI_TT_ERROR_SM), IMAGE_ICON, 0, 0, 0);
2837 VOID
2838 TOOLTIPS_Unregister (void)
2840 int i;
2841 for (i = TTI_INFO; i <= TTI_ERROR; i++)
2842 DestroyIcon(hTooltipIcons[i]);
2843 UnregisterClassW (TOOLTIPS_CLASSW, NULL);