include/roapi.h: Add further typedefs.
[wine.git] / dlls / comctl32 / tooltips.c
blob54601017d6153b80a2bdecefbeaef1bbb736bb4d
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 UINT uInternalFlags;
115 HWND hwnd;
116 BOOL bNotifyUnicode;
117 UINT_PTR uId;
118 RECT rect;
119 HINSTANCE hinst;
120 LPWSTR lpszText;
121 LPARAM lParam;
122 } TTTOOL_INFO;
125 typedef struct
127 HWND hwndSelf;
128 WCHAR szTipText[INFOTIPSIZE];
129 BOOL bActive;
130 BOOL bTrackActive;
131 UINT uNumTools;
132 COLORREF clrBk;
133 COLORREF clrText;
134 HFONT hFont;
135 HFONT hTitleFont;
136 INT xTrackPos;
137 INT yTrackPos;
138 INT nMaxTipWidth;
139 INT nTool; /* tool that mouse was on on last relayed mouse move */
140 INT nCurrentTool;
141 INT nTrackTool;
142 INT nReshowTime;
143 INT nAutoPopTime;
144 INT nInitialTime;
145 RECT rcMargin;
146 BOOL bToolBelow;
147 LPWSTR pszTitle;
148 HICON hTitleIcon;
150 TTTOOL_INFO *tools;
151 } TOOLTIPS_INFO;
153 #define ID_TIMERSHOW 1 /* show delay timer */
154 #define ID_TIMERPOP 2 /* auto pop timer */
155 #define ID_TIMERLEAVE 3 /* tool leave timer */
158 #define TOOLTIPS_GetInfoPtr(hWindow) ((TOOLTIPS_INFO *)GetWindowLongPtrW (hWindow, 0))
160 /* offsets from window edge to start of text */
161 #define NORMAL_TEXT_MARGIN 2
162 #define BALLOON_TEXT_MARGIN (NORMAL_TEXT_MARGIN+8)
163 /* value used for CreateRoundRectRgn that specifies how much
164 * each corner is curved */
165 #define BALLOON_ROUNDEDNESS 20
166 #define BALLOON_STEMHEIGHT 13
167 #define BALLOON_STEMWIDTH 10
168 #define BALLOON_STEMINDENT 20
170 #define BALLOON_ICON_TITLE_SPACING 8 /* horizontal spacing between icon and title */
171 #define BALLOON_TITLE_TEXT_SPACING 8 /* vertical spacing between icon/title and main text */
172 #define ICON_HEIGHT 16
173 #define ICON_WIDTH 16
175 #define MAX_TEXT_SIZE_A 80 /* maximum retrieving text size by ANSI message */
177 static LRESULT CALLBACK
178 TOOLTIPS_SubclassProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uId, DWORD_PTR dwRef);
181 static inline BOOL TOOLTIPS_IsCallbackString(LPCWSTR str, BOOL isW)
183 if (isW)
184 return str == LPSTR_TEXTCALLBACKW;
185 else
186 return (LPCSTR)str == LPSTR_TEXTCALLBACKA;
189 static inline UINT_PTR
190 TOOLTIPS_GetTitleIconIndex(HICON hIcon)
192 UINT i;
193 for (i = 0; i <= TTI_ERROR; i++)
194 if (hTooltipIcons[i] == hIcon)
195 return i;
196 return (UINT_PTR)hIcon;
199 static void
200 TOOLTIPS_InitSystemSettings (TOOLTIPS_INFO *infoPtr)
202 NONCLIENTMETRICSW nclm;
204 infoPtr->clrBk = comctl32_color.clrInfoBk;
205 infoPtr->clrText = comctl32_color.clrInfoText;
207 DeleteObject (infoPtr->hFont);
208 nclm.cbSize = sizeof(nclm);
209 SystemParametersInfoW (SPI_GETNONCLIENTMETRICS, sizeof(nclm), &nclm, 0);
210 infoPtr->hFont = CreateFontIndirectW (&nclm.lfStatusFont);
212 DeleteObject (infoPtr->hTitleFont);
213 nclm.lfStatusFont.lfWeight = FW_BOLD;
214 infoPtr->hTitleFont = CreateFontIndirectW (&nclm.lfStatusFont);
217 /* Custom draw routines */
218 static void
219 TOOLTIPS_customdraw_fill(const TOOLTIPS_INFO *infoPtr, NMTTCUSTOMDRAW *lpnmttcd,
220 HDC hdc, const RECT *rcBounds, UINT uFlags)
222 ZeroMemory(lpnmttcd, sizeof(NMTTCUSTOMDRAW));
223 lpnmttcd->uDrawFlags = uFlags;
224 lpnmttcd->nmcd.hdr.hwndFrom = infoPtr->hwndSelf;
225 lpnmttcd->nmcd.hdr.code = NM_CUSTOMDRAW;
226 if (infoPtr->nCurrentTool != -1) {
227 TTTOOL_INFO *toolPtr = &infoPtr->tools[infoPtr->nCurrentTool];
228 lpnmttcd->nmcd.hdr.idFrom = toolPtr->uId;
230 lpnmttcd->nmcd.hdc = hdc;
231 lpnmttcd->nmcd.rc = *rcBounds;
232 /* FIXME - dwItemSpec, uItemState, lItemlParam */
235 static inline DWORD
236 TOOLTIPS_notify_customdraw (DWORD dwDrawStage, NMTTCUSTOMDRAW *lpnmttcd)
238 LRESULT result;
239 lpnmttcd->nmcd.dwDrawStage = dwDrawStage;
241 TRACE("Notifying stage %d, flags %x, id %x\n", lpnmttcd->nmcd.dwDrawStage,
242 lpnmttcd->uDrawFlags, lpnmttcd->nmcd.hdr.code);
244 result = SendMessageW(GetParent(lpnmttcd->nmcd.hdr.hwndFrom), WM_NOTIFY,
245 0, (LPARAM)lpnmttcd);
247 TRACE("Notify result %x\n", (unsigned int)result);
249 return result;
252 static void
253 TOOLTIPS_Refresh (const TOOLTIPS_INFO *infoPtr, HDC hdc)
255 RECT rc;
256 INT oldBkMode;
257 HFONT hOldFont;
258 HBRUSH hBrush;
259 UINT uFlags = DT_EXTERNALLEADING;
260 HRGN hRgn = NULL;
261 DWORD dwStyle = GetWindowLongW(infoPtr->hwndSelf, GWL_STYLE);
262 NMTTCUSTOMDRAW nmttcd;
263 DWORD cdmode;
265 if (infoPtr->nMaxTipWidth > -1)
266 uFlags |= DT_WORDBREAK;
267 if (GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE) & TTS_NOPREFIX)
268 uFlags |= DT_NOPREFIX;
269 GetClientRect (infoPtr->hwndSelf, &rc);
271 hBrush = CreateSolidBrush(infoPtr->clrBk);
273 oldBkMode = SetBkMode (hdc, TRANSPARENT);
274 SetTextColor (hdc, infoPtr->clrText);
275 hOldFont = SelectObject (hdc, infoPtr->hFont);
277 /* Custom draw - Call PrePaint once initial properties set up */
278 /* Note: Contrary to MSDN, CDRF_SKIPDEFAULT still draws a tooltip */
279 TOOLTIPS_customdraw_fill(infoPtr, &nmttcd, hdc, &rc, uFlags);
280 cdmode = TOOLTIPS_notify_customdraw(CDDS_PREPAINT, &nmttcd);
281 uFlags = nmttcd.uDrawFlags;
283 if (dwStyle & TTS_BALLOON)
285 /* create a region to store result into */
286 hRgn = CreateRectRgn(0, 0, 0, 0);
288 GetWindowRgn(infoPtr->hwndSelf, hRgn);
290 /* fill the background */
291 FillRgn(hdc, hRgn, hBrush);
292 DeleteObject(hBrush);
293 hBrush = NULL;
295 else
297 /* fill the background */
298 FillRect(hdc, &rc, hBrush);
299 DeleteObject(hBrush);
300 hBrush = NULL;
303 if ((dwStyle & TTS_BALLOON) || infoPtr->pszTitle)
305 /* calculate text rectangle */
306 rc.left += (BALLOON_TEXT_MARGIN + infoPtr->rcMargin.left);
307 rc.top += (BALLOON_TEXT_MARGIN + infoPtr->rcMargin.top);
308 rc.right -= (BALLOON_TEXT_MARGIN + infoPtr->rcMargin.right);
309 rc.bottom -= (BALLOON_TEXT_MARGIN + infoPtr->rcMargin.bottom);
310 if(infoPtr->bToolBelow) rc.top += BALLOON_STEMHEIGHT;
312 if (infoPtr->pszTitle)
314 RECT rcTitle = {rc.left, rc.top, rc.right, rc.bottom};
315 int height;
316 BOOL icon_present;
317 HFONT prevFont;
319 /* draw icon */
320 icon_present = infoPtr->hTitleIcon &&
321 DrawIconEx(hdc, rc.left, rc.top, infoPtr->hTitleIcon,
322 ICON_WIDTH, ICON_HEIGHT, 0, NULL, DI_NORMAL);
323 if (icon_present)
324 rcTitle.left += ICON_WIDTH + BALLOON_ICON_TITLE_SPACING;
326 rcTitle.bottom = rc.top + ICON_HEIGHT;
328 /* draw title text */
329 prevFont = SelectObject (hdc, infoPtr->hTitleFont);
330 height = DrawTextW(hdc, infoPtr->pszTitle, -1, &rcTitle, DT_BOTTOM | DT_SINGLELINE | DT_NOPREFIX);
331 SelectObject (hdc, prevFont);
332 rc.top += height + BALLOON_TITLE_TEXT_SPACING;
335 else
337 /* calculate text rectangle */
338 rc.left += (NORMAL_TEXT_MARGIN + infoPtr->rcMargin.left);
339 rc.top += (NORMAL_TEXT_MARGIN + infoPtr->rcMargin.top);
340 rc.right -= (NORMAL_TEXT_MARGIN + infoPtr->rcMargin.right);
341 rc.bottom -= (NORMAL_TEXT_MARGIN + infoPtr->rcMargin.bottom);
344 /* draw text */
345 DrawTextW (hdc, infoPtr->szTipText, -1, &rc, uFlags);
347 /* Custom draw - Call PostPaint after drawing */
348 if (cdmode & CDRF_NOTIFYPOSTPAINT) {
349 TOOLTIPS_notify_customdraw(CDDS_POSTPAINT, &nmttcd);
352 /* be polite and reset the things we changed in the dc */
353 SelectObject (hdc, hOldFont);
354 SetBkMode (hdc, oldBkMode);
356 if (dwStyle & TTS_BALLOON)
358 /* frame region because default window proc doesn't do it */
359 INT width = GetSystemMetrics(SM_CXDLGFRAME) - GetSystemMetrics(SM_CXEDGE);
360 INT height = GetSystemMetrics(SM_CYDLGFRAME) - GetSystemMetrics(SM_CYEDGE);
362 hBrush = GetSysColorBrush(COLOR_WINDOWFRAME);
363 FrameRgn(hdc, hRgn, hBrush, width, height);
366 if (hRgn)
367 DeleteObject(hRgn);
370 static void TOOLTIPS_GetDispInfoA(const TOOLTIPS_INFO *infoPtr, TTTOOL_INFO *toolPtr, WCHAR *buffer)
372 NMTTDISPINFOA ttnmdi;
374 /* fill NMHDR struct */
375 ZeroMemory (&ttnmdi, sizeof(NMTTDISPINFOA));
376 ttnmdi.hdr.hwndFrom = infoPtr->hwndSelf;
377 ttnmdi.hdr.idFrom = toolPtr->uId;
378 ttnmdi.hdr.code = TTN_GETDISPINFOA; /* == TTN_NEEDTEXTA */
379 ttnmdi.lpszText = ttnmdi.szText;
380 ttnmdi.uFlags = toolPtr->uFlags;
381 ttnmdi.lParam = toolPtr->lParam;
383 TRACE("hdr.idFrom = %lx\n", ttnmdi.hdr.idFrom);
384 SendMessageW(toolPtr->hwnd, WM_NOTIFY, toolPtr->uId, (LPARAM)&ttnmdi);
386 if (IS_INTRESOURCE(ttnmdi.lpszText)) {
387 LoadStringW(ttnmdi.hinst, LOWORD(ttnmdi.lpszText),
388 buffer, INFOTIPSIZE);
389 if (ttnmdi.uFlags & TTF_DI_SETITEM) {
390 toolPtr->hinst = ttnmdi.hinst;
391 toolPtr->lpszText = (LPWSTR)ttnmdi.lpszText;
394 else if (ttnmdi.lpszText == 0) {
395 buffer[0] = '\0';
397 else if (ttnmdi.lpszText != LPSTR_TEXTCALLBACKA) {
398 Str_GetPtrAtoW(ttnmdi.lpszText, buffer, INFOTIPSIZE);
399 if (ttnmdi.uFlags & TTF_DI_SETITEM) {
400 toolPtr->hinst = 0;
401 toolPtr->lpszText = NULL;
402 Str_SetPtrW(&toolPtr->lpszText, buffer);
405 else {
406 ERR("recursive text callback\n");
407 buffer[0] = '\0';
410 /* no text available - try calling parent instead as per native */
411 /* FIXME: Unsure if SETITEM should save the value or not */
412 if (buffer[0] == 0x00) {
414 SendMessageW(GetParent(toolPtr->hwnd), WM_NOTIFY, toolPtr->uId, (LPARAM)&ttnmdi);
416 if (IS_INTRESOURCE(ttnmdi.lpszText)) {
417 LoadStringW(ttnmdi.hinst, LOWORD(ttnmdi.lpszText),
418 buffer, INFOTIPSIZE);
419 } else if (ttnmdi.lpszText &&
420 ttnmdi.lpszText != LPSTR_TEXTCALLBACKA) {
421 Str_GetPtrAtoW(ttnmdi.lpszText, buffer, INFOTIPSIZE);
426 static void TOOLTIPS_GetDispInfoW(const TOOLTIPS_INFO *infoPtr, TTTOOL_INFO *toolPtr, WCHAR *buffer)
428 NMTTDISPINFOW ttnmdi;
430 /* fill NMHDR struct */
431 ZeroMemory (&ttnmdi, sizeof(NMTTDISPINFOW));
432 ttnmdi.hdr.hwndFrom = infoPtr->hwndSelf;
433 ttnmdi.hdr.idFrom = toolPtr->uId;
434 ttnmdi.hdr.code = TTN_GETDISPINFOW; /* == TTN_NEEDTEXTW */
435 ttnmdi.lpszText = ttnmdi.szText;
436 ttnmdi.uFlags = toolPtr->uFlags;
437 ttnmdi.lParam = toolPtr->lParam;
439 TRACE("hdr.idFrom = %lx\n", ttnmdi.hdr.idFrom);
440 SendMessageW(toolPtr->hwnd, WM_NOTIFY, toolPtr->uId, (LPARAM)&ttnmdi);
442 if (IS_INTRESOURCE(ttnmdi.lpszText)) {
443 LoadStringW(ttnmdi.hinst, LOWORD(ttnmdi.lpszText),
444 buffer, INFOTIPSIZE);
445 if (ttnmdi.uFlags & TTF_DI_SETITEM) {
446 toolPtr->hinst = ttnmdi.hinst;
447 toolPtr->lpszText = ttnmdi.lpszText;
450 else if (ttnmdi.lpszText == 0) {
451 buffer[0] = '\0';
453 else if (ttnmdi.lpszText != LPSTR_TEXTCALLBACKW) {
454 Str_GetPtrW(ttnmdi.lpszText, buffer, INFOTIPSIZE);
455 if (ttnmdi.uFlags & TTF_DI_SETITEM) {
456 toolPtr->hinst = 0;
457 toolPtr->lpszText = NULL;
458 Str_SetPtrW(&toolPtr->lpszText, buffer);
461 else {
462 ERR("recursive text callback\n");
463 buffer[0] = '\0';
466 /* no text available - try calling parent instead as per native */
467 /* FIXME: Unsure if SETITEM should save the value or not */
468 if (buffer[0] == 0x00) {
470 SendMessageW(GetParent(toolPtr->hwnd), WM_NOTIFY, toolPtr->uId, (LPARAM)&ttnmdi);
472 if (IS_INTRESOURCE(ttnmdi.lpszText)) {
473 LoadStringW(ttnmdi.hinst, LOWORD(ttnmdi.lpszText),
474 buffer, INFOTIPSIZE);
475 } else if (ttnmdi.lpszText &&
476 ttnmdi.lpszText != LPSTR_TEXTCALLBACKW) {
477 Str_GetPtrW(ttnmdi.lpszText, buffer, INFOTIPSIZE);
483 static void
484 TOOLTIPS_GetTipText (const TOOLTIPS_INFO *infoPtr, INT nTool, WCHAR *buffer)
486 TTTOOL_INFO *toolPtr = &infoPtr->tools[nTool];
488 if (IS_INTRESOURCE(toolPtr->lpszText)) {
489 /* load a resource */
490 TRACE("load res string %p %x\n",
491 toolPtr->hinst, LOWORD(toolPtr->lpszText));
492 if (!LoadStringW (toolPtr->hinst, LOWORD(toolPtr->lpszText), buffer, INFOTIPSIZE))
493 buffer[0] = '\0';
495 else if (toolPtr->lpszText) {
496 if (toolPtr->lpszText == LPSTR_TEXTCALLBACKW) {
497 if (toolPtr->bNotifyUnicode)
498 TOOLTIPS_GetDispInfoW(infoPtr, toolPtr, buffer);
499 else
500 TOOLTIPS_GetDispInfoA(infoPtr, toolPtr, buffer);
502 else {
503 /* the item is a usual (unicode) text */
504 lstrcpynW (buffer, toolPtr->lpszText, INFOTIPSIZE);
507 else {
508 /* no text available */
509 buffer[0] = '\0';
512 if (!(GetWindowLongW(infoPtr->hwndSelf, GWL_STYLE) & TTS_NOPREFIX)) {
513 WCHAR *ptrW;
514 if ((ptrW = strchrW(buffer, '\t')))
515 *ptrW = 0;
518 TRACE("%s\n", debugstr_w(buffer));
522 static void
523 TOOLTIPS_CalcTipSize (const TOOLTIPS_INFO *infoPtr, LPSIZE lpSize)
525 HDC hdc;
526 HFONT hOldFont;
527 DWORD style = GetWindowLongW(infoPtr->hwndSelf, GWL_STYLE);
528 UINT uFlags = DT_EXTERNALLEADING | DT_CALCRECT;
529 RECT rc = {0, 0, 0, 0};
530 SIZE title = {0, 0};
532 if (infoPtr->nMaxTipWidth > -1) {
533 rc.right = infoPtr->nMaxTipWidth;
534 uFlags |= DT_WORDBREAK;
536 if (style & TTS_NOPREFIX)
537 uFlags |= DT_NOPREFIX;
538 TRACE("%s\n", debugstr_w(infoPtr->szTipText));
540 hdc = GetDC (infoPtr->hwndSelf);
541 if (infoPtr->pszTitle)
543 RECT rcTitle = {0, 0, 0, 0};
544 TRACE("title %s\n", debugstr_w(infoPtr->pszTitle));
545 if (infoPtr->hTitleIcon)
547 title.cx = ICON_WIDTH;
548 title.cy = ICON_HEIGHT;
550 if (title.cx != 0) title.cx += BALLOON_ICON_TITLE_SPACING;
551 hOldFont = SelectObject (hdc, infoPtr->hTitleFont);
552 DrawTextW(hdc, infoPtr->pszTitle, -1, &rcTitle, DT_SINGLELINE | DT_NOPREFIX | DT_CALCRECT);
553 SelectObject (hdc, hOldFont);
554 title.cy = max(title.cy, rcTitle.bottom - rcTitle.top) + BALLOON_TITLE_TEXT_SPACING;
555 title.cx += (rcTitle.right - rcTitle.left);
557 hOldFont = SelectObject (hdc, infoPtr->hFont);
558 DrawTextW (hdc, infoPtr->szTipText, -1, &rc, uFlags);
559 SelectObject (hdc, hOldFont);
560 ReleaseDC (infoPtr->hwndSelf, hdc);
562 if ((style & TTS_BALLOON) || infoPtr->pszTitle)
564 lpSize->cx = max(rc.right - rc.left, title.cx) + 2*BALLOON_TEXT_MARGIN +
565 infoPtr->rcMargin.left + infoPtr->rcMargin.right;
566 lpSize->cy = title.cy + rc.bottom - rc.top + 2*BALLOON_TEXT_MARGIN +
567 infoPtr->rcMargin.bottom + infoPtr->rcMargin.top +
568 BALLOON_STEMHEIGHT;
570 else
572 lpSize->cx = rc.right - rc.left + 2*NORMAL_TEXT_MARGIN +
573 infoPtr->rcMargin.left + infoPtr->rcMargin.right;
574 lpSize->cy = rc.bottom - rc.top + 2*NORMAL_TEXT_MARGIN +
575 infoPtr->rcMargin.bottom + infoPtr->rcMargin.top;
580 static void
581 TOOLTIPS_Show (TOOLTIPS_INFO *infoPtr, BOOL track_activate)
583 TTTOOL_INFO *toolPtr;
584 HMONITOR monitor;
585 MONITORINFO mon_info;
586 RECT rect;
587 SIZE size;
588 NMHDR hdr;
589 int ptfx = 0;
590 DWORD style = GetWindowLongW(infoPtr->hwndSelf, GWL_STYLE);
591 INT nTool, current;
593 if (track_activate)
595 if (infoPtr->nTrackTool == -1)
597 TRACE("invalid tracking tool %d\n", infoPtr->nTrackTool);
598 return;
600 nTool = infoPtr->nTrackTool;
602 else
604 if (infoPtr->nTool == -1)
606 TRACE("invalid tool %d\n", infoPtr->nTool);
607 return;
609 nTool = infoPtr->nTool;
612 TRACE("Show tooltip pre %d, %p\n", nTool, infoPtr->hwndSelf);
614 current = infoPtr->nCurrentTool;
615 if (!track_activate)
616 infoPtr->nCurrentTool = infoPtr->nTool;
618 TOOLTIPS_GetTipText (infoPtr, nTool, infoPtr->szTipText);
620 if (infoPtr->szTipText[0] == '\0')
622 infoPtr->nCurrentTool = current;
623 return;
626 toolPtr = &infoPtr->tools[nTool];
627 TOOLTIPS_CalcTipSize (infoPtr, &size);
629 TRACE("Show tooltip %d, %s, size %d x %d\n", nTool, debugstr_w(infoPtr->szTipText),
630 size.cx, size.cy);
632 if (track_activate && (toolPtr->uFlags & TTF_TRACK))
634 rect.left = infoPtr->xTrackPos;
635 rect.top = infoPtr->yTrackPos;
636 ptfx = rect.left;
638 if (toolPtr->uFlags & TTF_CENTERTIP)
640 rect.left -= (size.cx / 2);
641 if (!(style & TTS_BALLOON))
642 rect.top -= (size.cy / 2);
644 if (!(infoPtr->bToolBelow = (infoPtr->yTrackPos + size.cy <= GetSystemMetrics(SM_CYSCREEN))))
645 rect.top -= size.cy;
647 if (!(toolPtr->uFlags & TTF_ABSOLUTE))
649 if (style & TTS_BALLOON)
650 rect.left -= BALLOON_STEMINDENT;
651 else
653 RECT rcTool;
655 if (toolPtr->uFlags & TTF_IDISHWND)
656 GetWindowRect ((HWND)toolPtr->uId, &rcTool);
657 else
659 rcTool = toolPtr->rect;
660 MapWindowPoints (toolPtr->hwnd, NULL, (LPPOINT)&rcTool, 2);
663 /* smart placement */
664 if ((rect.left + size.cx > rcTool.left) && (rect.left < rcTool.right) &&
665 (rect.top + size.cy > rcTool.top) && (rect.top < rcTool.bottom))
666 rect.left = rcTool.right;
670 else
672 if (toolPtr->uFlags & TTF_CENTERTIP)
674 RECT rc;
676 if (toolPtr->uFlags & TTF_IDISHWND)
677 GetWindowRect ((HWND)toolPtr->uId, &rc);
678 else {
679 rc = toolPtr->rect;
680 MapWindowPoints (toolPtr->hwnd, NULL, (LPPOINT)&rc, 2);
682 rect.left = (rc.left + rc.right - size.cx) / 2;
683 if (style & TTS_BALLOON)
685 ptfx = rc.left + ((rc.right - rc.left) / 2);
687 /* CENTERTIP ballon tooltips default to below the field
688 * if they fit on the screen */
689 if (rc.bottom + size.cy > GetSystemMetrics(SM_CYSCREEN))
691 rect.top = rc.top - size.cy;
692 infoPtr->bToolBelow = FALSE;
694 else
696 infoPtr->bToolBelow = TRUE;
697 rect.top = rc.bottom;
699 rect.left = max(0, rect.left - BALLOON_STEMINDENT);
701 else
703 rect.top = rc.bottom + 2;
704 infoPtr->bToolBelow = TRUE;
707 else
709 GetCursorPos ((LPPOINT)&rect);
710 if (style & TTS_BALLOON)
712 ptfx = rect.left;
713 if(rect.top - size.cy >= 0)
715 rect.top -= size.cy;
716 infoPtr->bToolBelow = FALSE;
718 else
720 infoPtr->bToolBelow = TRUE;
721 rect.top += 20;
723 rect.left = max(0, rect.left - BALLOON_STEMINDENT);
725 else
727 rect.top += 20;
728 infoPtr->bToolBelow = TRUE;
733 TRACE("pos %d - %d\n", rect.left, rect.top);
735 rect.right = rect.left + size.cx;
736 rect.bottom = rect.top + size.cy;
738 /* check position */
740 monitor = MonitorFromRect( &rect, MONITOR_DEFAULTTOPRIMARY );
741 mon_info.cbSize = sizeof(mon_info);
742 GetMonitorInfoW( monitor, &mon_info );
744 if( rect.right > mon_info.rcWork.right ) {
745 rect.left -= rect.right - mon_info.rcWork.right + 2;
746 rect.right = mon_info.rcWork.right - 2;
748 if (rect.left < mon_info.rcWork.left) rect.left = mon_info.rcWork.left;
750 if( rect.bottom > mon_info.rcWork.bottom ) {
751 RECT rc;
753 if (toolPtr->uFlags & TTF_IDISHWND)
754 GetWindowRect ((HWND)toolPtr->uId, &rc);
755 else {
756 rc = toolPtr->rect;
757 MapWindowPoints (toolPtr->hwnd, NULL, (LPPOINT)&rc, 2);
759 rect.bottom = rc.top - 2;
760 rect.top = rect.bottom - size.cy;
763 AdjustWindowRectEx (&rect, GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE),
764 FALSE, GetWindowLongW (infoPtr->hwndSelf, GWL_EXSTYLE));
766 if (style & TTS_BALLOON)
768 HRGN hRgn;
769 HRGN hrStem;
770 POINT pts[3];
772 ptfx -= rect.left;
774 if(infoPtr->bToolBelow)
776 pts[0].x = ptfx;
777 pts[0].y = 0;
778 pts[1].x = max(BALLOON_STEMINDENT, ptfx - (BALLOON_STEMWIDTH / 2));
779 pts[1].y = BALLOON_STEMHEIGHT;
780 pts[2].x = pts[1].x + BALLOON_STEMWIDTH;
781 pts[2].y = pts[1].y;
782 if(pts[2].x > (rect.right - rect.left) - BALLOON_STEMINDENT)
784 pts[2].x = (rect.right - rect.left) - BALLOON_STEMINDENT;
785 pts[1].x = pts[2].x - BALLOON_STEMWIDTH;
788 else
790 pts[0].x = max(BALLOON_STEMINDENT, ptfx - (BALLOON_STEMWIDTH / 2));
791 pts[0].y = (rect.bottom - rect.top) - BALLOON_STEMHEIGHT;
792 pts[1].x = pts[0].x + BALLOON_STEMWIDTH;
793 pts[1].y = pts[0].y;
794 pts[2].x = ptfx;
795 pts[2].y = (rect.bottom - rect.top);
796 if(pts[1].x > (rect.right - rect.left) - BALLOON_STEMINDENT)
798 pts[1].x = (rect.right - rect.left) - BALLOON_STEMINDENT;
799 pts[0].x = pts[1].x - BALLOON_STEMWIDTH;
803 hrStem = CreatePolygonRgn(pts, ARRAY_SIZE(pts), ALTERNATE);
805 hRgn = CreateRoundRectRgn(0,
806 (infoPtr->bToolBelow ? BALLOON_STEMHEIGHT : 0),
807 rect.right - rect.left,
808 (infoPtr->bToolBelow ? rect.bottom - rect.top : rect.bottom - rect.top - BALLOON_STEMHEIGHT),
809 BALLOON_ROUNDEDNESS, BALLOON_ROUNDEDNESS);
811 CombineRgn(hRgn, hRgn, hrStem, RGN_OR);
812 DeleteObject(hrStem);
814 SetWindowRgn(infoPtr->hwndSelf, hRgn, FALSE);
815 /* we don't free the region handle as the system deletes it when
816 * it is no longer needed */
819 SetWindowPos (infoPtr->hwndSelf, NULL, rect.left, rect.top,
820 rect.right - rect.left, rect.bottom - rect.top, SWP_NOZORDER | SWP_NOACTIVATE);
822 hdr.hwndFrom = infoPtr->hwndSelf;
823 hdr.idFrom = toolPtr->uId;
824 hdr.code = TTN_SHOW;
825 SendMessageW (toolPtr->hwnd, WM_NOTIFY, toolPtr->uId, (LPARAM)&hdr);
827 SetWindowPos (infoPtr->hwndSelf, HWND_TOPMOST, 0, 0, 0, 0,
828 SWP_NOSIZE | SWP_NOMOVE | SWP_SHOWWINDOW | SWP_NOACTIVATE);
830 /* repaint the tooltip */
831 InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
832 UpdateWindow(infoPtr->hwndSelf);
834 if (!track_activate)
836 SetTimer (infoPtr->hwndSelf, ID_TIMERPOP, infoPtr->nAutoPopTime, 0);
837 TRACE("timer 2 started\n");
838 SetTimer (infoPtr->hwndSelf, ID_TIMERLEAVE, infoPtr->nReshowTime, 0);
839 TRACE("timer 3 started\n");
844 static void
845 TOOLTIPS_Hide (TOOLTIPS_INFO *infoPtr)
847 TTTOOL_INFO *toolPtr;
848 NMHDR hdr;
850 TRACE("Hide tooltip %d, %p.\n", infoPtr->nCurrentTool, infoPtr->hwndSelf);
852 if (infoPtr->nCurrentTool == -1)
853 return;
855 toolPtr = &infoPtr->tools[infoPtr->nCurrentTool];
856 KillTimer (infoPtr->hwndSelf, ID_TIMERPOP);
858 hdr.hwndFrom = infoPtr->hwndSelf;
859 hdr.idFrom = toolPtr->uId;
860 hdr.code = TTN_POP;
861 SendMessageW (toolPtr->hwnd, WM_NOTIFY, toolPtr->uId, (LPARAM)&hdr);
863 infoPtr->nCurrentTool = -1;
865 SetWindowPos (infoPtr->hwndSelf, HWND_TOP, 0, 0, 0, 0,
866 SWP_NOZORDER | SWP_HIDEWINDOW | SWP_NOACTIVATE);
870 static void
871 TOOLTIPS_TrackShow (TOOLTIPS_INFO *infoPtr)
873 TOOLTIPS_Show(infoPtr, TRUE);
877 static void
878 TOOLTIPS_TrackHide (const TOOLTIPS_INFO *infoPtr)
880 TTTOOL_INFO *toolPtr;
881 NMHDR hdr;
883 TRACE("hide tracking tooltip %d\n", infoPtr->nTrackTool);
885 if (infoPtr->nTrackTool == -1)
886 return;
888 toolPtr = &infoPtr->tools[infoPtr->nTrackTool];
890 hdr.hwndFrom = infoPtr->hwndSelf;
891 hdr.idFrom = toolPtr->uId;
892 hdr.code = TTN_POP;
893 SendMessageW (toolPtr->hwnd, WM_NOTIFY, toolPtr->uId, (LPARAM)&hdr);
895 SetWindowPos (infoPtr->hwndSelf, HWND_TOP, 0, 0, 0, 0,
896 SWP_NOZORDER | SWP_HIDEWINDOW | SWP_NOACTIVATE);
899 /* Structure layout is the same for TTTOOLINFOW and TTTOOLINFOA,
900 this helper is used in both cases. */
901 static INT
902 TOOLTIPS_GetToolFromInfoT (const TOOLTIPS_INFO *infoPtr, const TTTOOLINFOW *lpToolInfo)
904 TTTOOL_INFO *toolPtr;
905 UINT nTool;
907 for (nTool = 0; nTool < infoPtr->uNumTools; nTool++) {
908 toolPtr = &infoPtr->tools[nTool];
910 if (!(toolPtr->uFlags & TTF_IDISHWND) &&
911 (lpToolInfo->hwnd == toolPtr->hwnd) &&
912 (lpToolInfo->uId == toolPtr->uId))
913 return nTool;
916 for (nTool = 0; nTool < infoPtr->uNumTools; nTool++) {
917 toolPtr = &infoPtr->tools[nTool];
919 if ((toolPtr->uFlags & TTF_IDISHWND) &&
920 (lpToolInfo->uId == toolPtr->uId))
921 return nTool;
924 return -1;
928 static INT
929 TOOLTIPS_GetToolFromPoint (const TOOLTIPS_INFO *infoPtr, HWND hwnd, const POINT *lpPt)
931 TTTOOL_INFO *toolPtr;
932 UINT nTool;
934 for (nTool = 0; nTool < infoPtr->uNumTools; nTool++) {
935 toolPtr = &infoPtr->tools[nTool];
937 if (!(toolPtr->uFlags & TTF_IDISHWND)) {
938 if (hwnd != toolPtr->hwnd)
939 continue;
940 if (!PtInRect (&toolPtr->rect, *lpPt))
941 continue;
942 return nTool;
946 for (nTool = 0; nTool < infoPtr->uNumTools; nTool++) {
947 toolPtr = &infoPtr->tools[nTool];
949 if (toolPtr->uFlags & TTF_IDISHWND) {
950 if ((HWND)toolPtr->uId == hwnd)
951 return nTool;
955 return -1;
958 static inline void
959 TOOLTIPS_CopyInfoT (const TOOLTIPS_INFO *infoPtr, INT index, TTTOOLINFOW *ti, BOOL isW)
961 const TTTOOL_INFO *toolPtr = &infoPtr->tools[index];
963 ti->uFlags = toolPtr->uFlags;
964 ti->hwnd = toolPtr->hwnd;
965 ti->uId = toolPtr->uId;
966 ti->rect = toolPtr->rect;
967 ti->hinst = toolPtr->hinst;
969 if (ti->lpszText) {
970 if (toolPtr->lpszText == NULL ||
971 IS_INTRESOURCE(toolPtr->lpszText) ||
972 toolPtr->lpszText == LPSTR_TEXTCALLBACKW)
973 ti->lpszText = toolPtr->lpszText;
974 else if (isW)
975 strcpyW (ti->lpszText, toolPtr->lpszText);
976 else
977 /* ANSI version, the buffer is maximum 80 bytes without null. */
978 WideCharToMultiByte(CP_ACP, 0, toolPtr->lpszText, -1,
979 (LPSTR)ti->lpszText, MAX_TEXT_SIZE_A, NULL, NULL);
982 if (ti->cbSize >= TTTOOLINFOW_V2_SIZE)
983 ti->lParam = toolPtr->lParam;
985 /* lpReserved is intentionally not set. */
988 static BOOL
989 TOOLTIPS_IsWindowActive (HWND hwnd)
991 HWND hwndActive = GetActiveWindow ();
992 if (!hwndActive)
993 return FALSE;
994 if (hwndActive == hwnd)
995 return TRUE;
996 return IsChild (hwndActive, hwnd);
1000 static INT
1001 TOOLTIPS_CheckTool (const TOOLTIPS_INFO *infoPtr, BOOL bShowTest)
1003 POINT pt;
1004 HWND hwndTool;
1005 INT nTool;
1007 GetCursorPos (&pt);
1008 hwndTool = (HWND)SendMessageW (infoPtr->hwndSelf, TTM_WINDOWFROMPOINT, 0, (LPARAM)&pt);
1009 if (hwndTool == 0)
1010 return -1;
1012 ScreenToClient (hwndTool, &pt);
1013 nTool = TOOLTIPS_GetToolFromPoint (infoPtr, hwndTool, &pt);
1014 if (nTool == -1)
1015 return -1;
1017 if (!(GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE) & TTS_ALWAYSTIP) && bShowTest)
1019 TTTOOL_INFO *ti = &infoPtr->tools[nTool];
1020 HWND hwnd = (ti->uFlags & TTF_IDISHWND) ? (HWND)ti->uId : ti->hwnd;
1022 if (!TOOLTIPS_IsWindowActive(hwnd))
1024 TRACE("not active: hwnd %p, parent %p, active %p\n",
1025 hwnd, GetParent(hwnd), GetActiveWindow());
1026 return -1;
1030 TRACE("tool %d\n", nTool);
1032 return nTool;
1036 static LRESULT
1037 TOOLTIPS_Activate (TOOLTIPS_INFO *infoPtr, BOOL activate)
1039 infoPtr->bActive = activate;
1041 TRACE("activate %d\n", activate);
1043 if (!(infoPtr->bActive) && (infoPtr->nCurrentTool != -1))
1044 TOOLTIPS_Hide (infoPtr);
1046 return 0;
1050 static LRESULT
1051 TOOLTIPS_AddToolT (TOOLTIPS_INFO *infoPtr, const TTTOOLINFOW *ti, BOOL isW)
1053 TTTOOL_INFO *toolPtr;
1054 INT nResult;
1056 if (!ti) return FALSE;
1058 TRACE("add tool (%p) %p %ld%s\n", infoPtr->hwndSelf, ti->hwnd, ti->uId,
1059 (ti->uFlags & TTF_IDISHWND) ? " TTF_IDISHWND" : "");
1061 if (ti->cbSize > TTTOOLINFOW_V3_SIZE && isW)
1062 return FALSE;
1064 if (infoPtr->uNumTools == 0) {
1065 infoPtr->tools = Alloc (sizeof(TTTOOL_INFO));
1066 toolPtr = infoPtr->tools;
1068 else {
1069 TTTOOL_INFO *oldTools = infoPtr->tools;
1070 infoPtr->tools =
1071 Alloc (sizeof(TTTOOL_INFO) * (infoPtr->uNumTools + 1));
1072 memcpy (infoPtr->tools, oldTools,
1073 infoPtr->uNumTools * sizeof(TTTOOL_INFO));
1074 Free (oldTools);
1075 toolPtr = &infoPtr->tools[infoPtr->uNumTools];
1078 infoPtr->uNumTools++;
1080 /* copy tool data */
1081 toolPtr->uFlags = ti->uFlags;
1082 toolPtr->uInternalFlags = (ti->uFlags & (TTF_SUBCLASS | TTF_IDISHWND));
1083 toolPtr->hwnd = ti->hwnd;
1084 toolPtr->uId = ti->uId;
1085 toolPtr->rect = ti->rect;
1086 toolPtr->hinst = ti->hinst;
1088 if (ti->cbSize >= TTTOOLINFOW_V1_SIZE) {
1089 if (IS_INTRESOURCE(ti->lpszText)) {
1090 TRACE("add string id %x\n", LOWORD(ti->lpszText));
1091 toolPtr->lpszText = ti->lpszText;
1093 else if (ti->lpszText) {
1094 if (TOOLTIPS_IsCallbackString(ti->lpszText, isW)) {
1095 TRACE("add CALLBACK\n");
1096 toolPtr->lpszText = LPSTR_TEXTCALLBACKW;
1098 else if (isW) {
1099 INT len = lstrlenW (ti->lpszText);
1100 TRACE("add text %s\n", debugstr_w(ti->lpszText));
1101 toolPtr->lpszText = Alloc ((len + 1)*sizeof(WCHAR));
1102 strcpyW (toolPtr->lpszText, ti->lpszText);
1104 else {
1105 INT len = MultiByteToWideChar(CP_ACP, 0, (LPSTR)ti->lpszText, -1, NULL, 0);
1106 TRACE("add text \"%s\"\n", debugstr_a((char *)ti->lpszText));
1107 toolPtr->lpszText = Alloc (len * sizeof(WCHAR));
1108 MultiByteToWideChar(CP_ACP, 0, (LPSTR)ti->lpszText, -1, toolPtr->lpszText, len);
1113 if (ti->cbSize >= TTTOOLINFOW_V2_SIZE)
1114 toolPtr->lParam = ti->lParam;
1116 /* install subclassing hook */
1117 if (toolPtr->uInternalFlags & TTF_SUBCLASS) {
1118 if (toolPtr->uInternalFlags & TTF_IDISHWND) {
1119 SetWindowSubclass((HWND)toolPtr->uId, TOOLTIPS_SubclassProc, 1,
1120 (DWORD_PTR)infoPtr->hwndSelf);
1122 else {
1123 SetWindowSubclass(toolPtr->hwnd, TOOLTIPS_SubclassProc, 1,
1124 (DWORD_PTR)infoPtr->hwndSelf);
1126 TRACE("subclassing installed\n");
1129 nResult = SendMessageW (toolPtr->hwnd, WM_NOTIFYFORMAT,
1130 (WPARAM)infoPtr->hwndSelf, NF_QUERY);
1131 if (nResult == NFR_ANSI) {
1132 toolPtr->bNotifyUnicode = FALSE;
1133 TRACE(" -- WM_NOTIFYFORMAT returns: NFR_ANSI\n");
1134 } else if (nResult == NFR_UNICODE) {
1135 toolPtr->bNotifyUnicode = TRUE;
1136 TRACE(" -- WM_NOTIFYFORMAT returns: NFR_UNICODE\n");
1137 } else {
1138 TRACE (" -- WM_NOTIFYFORMAT returns: %d\n", nResult);
1141 return TRUE;
1144 static void TOOLTIPS_ResetSubclass (const TTTOOL_INFO *toolPtr)
1146 /* Reset subclassing data. */
1147 if (toolPtr->uInternalFlags & TTF_SUBCLASS)
1148 SetWindowSubclass(toolPtr->uInternalFlags & TTF_IDISHWND ? (HWND)toolPtr->uId : toolPtr->hwnd,
1149 TOOLTIPS_SubclassProc, 1, 0);
1152 static LRESULT
1153 TOOLTIPS_DelToolT (TOOLTIPS_INFO *infoPtr, const TTTOOLINFOW *ti, BOOL isW)
1155 TTTOOL_INFO *toolPtr;
1156 INT nTool;
1158 if (!ti) return 0;
1159 if (isW && ti->cbSize > TTTOOLINFOW_V2_SIZE &&
1160 ti->cbSize != TTTOOLINFOW_V3_SIZE)
1161 return 0;
1162 if (infoPtr->uNumTools == 0)
1163 return 0;
1165 nTool = TOOLTIPS_GetToolFromInfoT (infoPtr, ti);
1167 TRACE("tool %d\n", nTool);
1169 if (nTool == -1)
1170 return 0;
1172 /* make sure the tooltip has disappeared before deleting it */
1173 TOOLTIPS_Hide(infoPtr);
1175 /* delete text string */
1176 toolPtr = &infoPtr->tools[nTool];
1177 if (toolPtr->lpszText) {
1178 if ( (toolPtr->lpszText != LPSTR_TEXTCALLBACKW) &&
1179 !IS_INTRESOURCE(toolPtr->lpszText) )
1180 Free (toolPtr->lpszText);
1183 TOOLTIPS_ResetSubclass (toolPtr);
1185 /* delete tool from tool list */
1186 if (infoPtr->uNumTools == 1) {
1187 Free (infoPtr->tools);
1188 infoPtr->tools = NULL;
1190 else {
1191 TTTOOL_INFO *oldTools = infoPtr->tools;
1192 infoPtr->tools =
1193 Alloc (sizeof(TTTOOL_INFO) * (infoPtr->uNumTools - 1));
1195 if (nTool > 0)
1196 memcpy (&infoPtr->tools[0], &oldTools[0],
1197 nTool * sizeof(TTTOOL_INFO));
1199 if (nTool < infoPtr->uNumTools - 1)
1200 memcpy (&infoPtr->tools[nTool], &oldTools[nTool + 1],
1201 (infoPtr->uNumTools - nTool - 1) * sizeof(TTTOOL_INFO));
1203 Free (oldTools);
1206 /* update any indices affected by delete */
1208 /* destroying tool that mouse was on on last relayed mouse move */
1209 if (infoPtr->nTool == nTool)
1210 /* -1 means no current tool (0 means first tool) */
1211 infoPtr->nTool = -1;
1212 else if (infoPtr->nTool > nTool)
1213 infoPtr->nTool--;
1215 if (infoPtr->nTrackTool == nTool)
1216 /* -1 means no current tool (0 means first tool) */
1217 infoPtr->nTrackTool = -1;
1218 else if (infoPtr->nTrackTool > nTool)
1219 infoPtr->nTrackTool--;
1221 if (infoPtr->nCurrentTool == nTool)
1222 /* -1 means no current tool (0 means first tool) */
1223 infoPtr->nCurrentTool = -1;
1224 else if (infoPtr->nCurrentTool > nTool)
1225 infoPtr->nCurrentTool--;
1227 infoPtr->uNumTools--;
1229 return 0;
1232 static LRESULT
1233 TOOLTIPS_EnumToolsT (const TOOLTIPS_INFO *infoPtr, UINT uIndex, TTTOOLINFOW *ti,
1234 BOOL isW)
1236 if (!ti || ti->cbSize < TTTOOLINFOW_V1_SIZE)
1237 return FALSE;
1238 if (uIndex >= infoPtr->uNumTools)
1239 return FALSE;
1241 TRACE("index=%u\n", uIndex);
1243 TOOLTIPS_CopyInfoT (infoPtr, uIndex, ti, isW);
1245 return TRUE;
1248 static LRESULT
1249 TOOLTIPS_GetBubbleSize (const TOOLTIPS_INFO *infoPtr, const TTTOOLINFOW *lpToolInfo)
1251 INT nTool;
1252 SIZE size;
1254 if (lpToolInfo == NULL)
1255 return FALSE;
1256 if (lpToolInfo->cbSize < TTTOOLINFOW_V1_SIZE)
1257 return FALSE;
1259 nTool = TOOLTIPS_GetToolFromInfoT (infoPtr, lpToolInfo);
1260 if (nTool == -1) return 0;
1262 TRACE("tool %d\n", nTool);
1264 TOOLTIPS_CalcTipSize (infoPtr, &size);
1265 TRACE("size %d x %d\n", size.cx, size.cy);
1267 return MAKELRESULT(size.cx, size.cy);
1270 static LRESULT
1271 TOOLTIPS_GetCurrentToolT (const TOOLTIPS_INFO *infoPtr, TTTOOLINFOW *ti, BOOL isW)
1273 if (ti) {
1274 if (ti->cbSize < TTTOOLINFOW_V1_SIZE)
1275 return FALSE;
1277 if (infoPtr->nCurrentTool != -1)
1278 TOOLTIPS_CopyInfoT (infoPtr, infoPtr->nCurrentTool, ti, isW);
1281 return infoPtr->nCurrentTool != -1;
1285 static LRESULT
1286 TOOLTIPS_GetDelayTime (const TOOLTIPS_INFO *infoPtr, DWORD duration)
1288 switch (duration) {
1289 case TTDT_RESHOW:
1290 return infoPtr->nReshowTime;
1292 case TTDT_AUTOPOP:
1293 return infoPtr->nAutoPopTime;
1295 case TTDT_INITIAL:
1296 case TTDT_AUTOMATIC: /* Apparently TTDT_AUTOMATIC returns TTDT_INITIAL */
1297 return infoPtr->nInitialTime;
1299 default:
1300 WARN("Invalid duration flag %x\n", duration);
1301 break;
1304 return -1;
1308 static LRESULT
1309 TOOLTIPS_GetMargin (const TOOLTIPS_INFO *infoPtr, RECT *rect)
1311 if (rect)
1312 *rect = infoPtr->rcMargin;
1314 return 0;
1318 static inline LRESULT
1319 TOOLTIPS_GetMaxTipWidth (const TOOLTIPS_INFO *infoPtr)
1321 return infoPtr->nMaxTipWidth;
1325 static LRESULT
1326 TOOLTIPS_GetTextT (const TOOLTIPS_INFO *infoPtr, TTTOOLINFOW *ti, BOOL isW)
1328 INT nTool;
1330 if (!ti) return 0;
1331 if (ti->cbSize < TTTOOLINFOW_V1_SIZE)
1332 return 0;
1334 nTool = TOOLTIPS_GetToolFromInfoT (infoPtr, ti);
1335 if (nTool == -1) return 0;
1337 if (infoPtr->tools[nTool].lpszText == NULL)
1338 return 0;
1340 if (isW) {
1341 ti->lpszText[0] = '\0';
1342 TOOLTIPS_GetTipText(infoPtr, nTool, ti->lpszText);
1344 else {
1345 WCHAR buffer[INFOTIPSIZE];
1347 /* NB this API is broken, there is no way for the app to determine
1348 what size buffer it requires nor a way to specify how long the
1349 one it supplies is. According to the test result, it's up to
1350 80 bytes by the ANSI version. */
1352 buffer[0] = '\0';
1353 TOOLTIPS_GetTipText(infoPtr, nTool, buffer);
1354 WideCharToMultiByte(CP_ACP, 0, buffer, -1, (LPSTR)ti->lpszText,
1355 MAX_TEXT_SIZE_A, NULL, NULL);
1358 return 0;
1362 static inline LRESULT
1363 TOOLTIPS_GetTipBkColor (const TOOLTIPS_INFO *infoPtr)
1365 return infoPtr->clrBk;
1369 static inline LRESULT
1370 TOOLTIPS_GetTipTextColor (const TOOLTIPS_INFO *infoPtr)
1372 return infoPtr->clrText;
1376 static inline LRESULT
1377 TOOLTIPS_GetToolCount (const TOOLTIPS_INFO *infoPtr)
1379 return infoPtr->uNumTools;
1383 static LRESULT
1384 TOOLTIPS_GetToolInfoT (const TOOLTIPS_INFO *infoPtr, TTTOOLINFOW *ti, BOOL isW)
1386 INT nTool;
1387 HWND hwnd;
1389 if (!ti) return FALSE;
1390 if (ti->cbSize < TTTOOLINFOW_V1_SIZE)
1391 return FALSE;
1392 if (infoPtr->uNumTools == 0)
1393 return FALSE;
1395 nTool = TOOLTIPS_GetToolFromInfoT (infoPtr, ti);
1396 if (nTool == -1)
1397 return FALSE;
1399 TRACE("tool %d\n", nTool);
1401 hwnd = ti->hwnd;
1402 TOOLTIPS_CopyInfoT (infoPtr, nTool, ti, isW);
1403 ti->hwnd = hwnd;
1405 return TRUE;
1409 static LRESULT
1410 TOOLTIPS_HitTestT (const TOOLTIPS_INFO *infoPtr, LPTTHITTESTINFOW lptthit,
1411 BOOL isW)
1413 INT nTool;
1415 if (lptthit == 0)
1416 return FALSE;
1418 nTool = TOOLTIPS_GetToolFromPoint (infoPtr, lptthit->hwnd, &lptthit->pt);
1419 if (nTool == -1)
1420 return FALSE;
1422 TRACE("tool %d\n", nTool);
1424 /* copy tool data */
1425 if (lptthit->ti.cbSize >= TTTOOLINFOW_V1_SIZE)
1426 TOOLTIPS_CopyInfoT (infoPtr, nTool, &lptthit->ti, isW);
1428 return TRUE;
1432 static LRESULT
1433 TOOLTIPS_NewToolRectT (TOOLTIPS_INFO *infoPtr, const TTTOOLINFOW *ti)
1435 INT nTool;
1437 if (!ti) return 0;
1438 if (ti->cbSize < TTTOOLINFOW_V1_SIZE)
1439 return FALSE;
1441 nTool = TOOLTIPS_GetToolFromInfoT (infoPtr, ti);
1443 TRACE("nTool = %d, rect = %s\n", nTool, wine_dbgstr_rect(&ti->rect));
1445 if (nTool == -1) return 0;
1447 infoPtr->tools[nTool].rect = ti->rect;
1449 return 0;
1453 static inline LRESULT
1454 TOOLTIPS_Pop (TOOLTIPS_INFO *infoPtr)
1456 TOOLTIPS_Hide (infoPtr);
1458 return 0;
1462 static LRESULT
1463 TOOLTIPS_RelayEvent (TOOLTIPS_INFO *infoPtr, LPMSG lpMsg)
1465 POINT pt;
1466 INT nOldTool;
1468 if (!lpMsg) {
1469 ERR("lpMsg == NULL\n");
1470 return 0;
1473 switch (lpMsg->message) {
1474 case WM_LBUTTONDOWN:
1475 case WM_LBUTTONUP:
1476 case WM_MBUTTONDOWN:
1477 case WM_MBUTTONUP:
1478 case WM_RBUTTONDOWN:
1479 case WM_RBUTTONUP:
1480 TOOLTIPS_Hide (infoPtr);
1481 break;
1483 case WM_MOUSEMOVE:
1484 pt.x = (short)LOWORD(lpMsg->lParam);
1485 pt.y = (short)HIWORD(lpMsg->lParam);
1486 nOldTool = infoPtr->nTool;
1487 infoPtr->nTool = TOOLTIPS_GetToolFromPoint(infoPtr, lpMsg->hwnd,
1488 &pt);
1489 TRACE("tool (%p) %d %d %d\n", infoPtr->hwndSelf, nOldTool,
1490 infoPtr->nTool, infoPtr->nCurrentTool);
1491 TRACE("WM_MOUSEMOVE (%p %s)\n", infoPtr->hwndSelf, wine_dbgstr_point(&pt));
1493 if (infoPtr->nTool != nOldTool) {
1494 if(infoPtr->nTool == -1) { /* Moved out of all tools */
1495 TOOLTIPS_Hide(infoPtr);
1496 KillTimer(infoPtr->hwndSelf, ID_TIMERLEAVE);
1497 } else if (nOldTool == -1) { /* Moved from outside */
1498 if(infoPtr->bActive) {
1499 SetTimer(infoPtr->hwndSelf, ID_TIMERSHOW, infoPtr->nInitialTime, 0);
1500 TRACE("timer 1 started\n");
1502 } else { /* Moved from one to another */
1503 TOOLTIPS_Hide (infoPtr);
1504 KillTimer(infoPtr->hwndSelf, ID_TIMERLEAVE);
1505 if(infoPtr->bActive) {
1506 SetTimer (infoPtr->hwndSelf, ID_TIMERSHOW, infoPtr->nReshowTime, 0);
1507 TRACE("timer 1 started\n");
1510 } else if(infoPtr->nCurrentTool != -1) { /* restart autopop */
1511 KillTimer(infoPtr->hwndSelf, ID_TIMERPOP);
1512 SetTimer(infoPtr->hwndSelf, ID_TIMERPOP, infoPtr->nAutoPopTime, 0);
1513 TRACE("timer 2 restarted\n");
1514 } else if(infoPtr->nTool != -1 && infoPtr->bActive) {
1515 /* previous show attempt didn't result in tooltip so try again */
1516 SetTimer(infoPtr->hwndSelf, ID_TIMERSHOW, infoPtr->nInitialTime, 0);
1517 TRACE("timer 1 started\n");
1519 break;
1522 return 0;
1526 static LRESULT
1527 TOOLTIPS_SetDelayTime (TOOLTIPS_INFO *infoPtr, DWORD duration, INT nTime)
1529 switch (duration) {
1530 case TTDT_AUTOMATIC:
1531 if (nTime <= 0)
1532 nTime = GetDoubleClickTime();
1533 infoPtr->nReshowTime = nTime / 5;
1534 infoPtr->nAutoPopTime = nTime * 10;
1535 infoPtr->nInitialTime = nTime;
1536 break;
1538 case TTDT_RESHOW:
1539 if(nTime < 0)
1540 nTime = GetDoubleClickTime() / 5;
1541 infoPtr->nReshowTime = nTime;
1542 break;
1544 case TTDT_AUTOPOP:
1545 if(nTime < 0)
1546 nTime = GetDoubleClickTime() * 10;
1547 infoPtr->nAutoPopTime = nTime;
1548 break;
1550 case TTDT_INITIAL:
1551 if(nTime < 0)
1552 nTime = GetDoubleClickTime();
1553 infoPtr->nInitialTime = nTime;
1554 break;
1556 default:
1557 WARN("Invalid duration flag %x\n", duration);
1558 break;
1561 return 0;
1565 static LRESULT
1566 TOOLTIPS_SetMargin (TOOLTIPS_INFO *infoPtr, const RECT *rect)
1568 if (rect)
1569 infoPtr->rcMargin = *rect;
1571 return 0;
1575 static inline LRESULT
1576 TOOLTIPS_SetMaxTipWidth (TOOLTIPS_INFO *infoPtr, INT MaxWidth)
1578 INT nTemp = infoPtr->nMaxTipWidth;
1580 infoPtr->nMaxTipWidth = MaxWidth;
1582 return nTemp;
1586 static inline LRESULT
1587 TOOLTIPS_SetTipBkColor (TOOLTIPS_INFO *infoPtr, COLORREF clrBk)
1589 infoPtr->clrBk = clrBk;
1591 return 0;
1595 static inline LRESULT
1596 TOOLTIPS_SetTipTextColor (TOOLTIPS_INFO *infoPtr, COLORREF clrText)
1598 infoPtr->clrText = clrText;
1600 return 0;
1604 static LRESULT
1605 TOOLTIPS_SetTitleT (TOOLTIPS_INFO *infoPtr, UINT_PTR uTitleIcon, LPCWSTR pszTitle,
1606 BOOL isW)
1608 UINT size;
1610 TRACE("hwnd = %p, title = %s, icon = %p\n", infoPtr->hwndSelf, debugstr_w(pszTitle),
1611 (void*)uTitleIcon);
1613 Free(infoPtr->pszTitle);
1615 if (pszTitle)
1617 if (isW)
1619 size = (strlenW(pszTitle)+1)*sizeof(WCHAR);
1620 infoPtr->pszTitle = Alloc(size);
1621 if (!infoPtr->pszTitle)
1622 return FALSE;
1623 memcpy(infoPtr->pszTitle, pszTitle, size);
1625 else
1627 size = sizeof(WCHAR)*MultiByteToWideChar(CP_ACP, 0, (LPCSTR)pszTitle, -1, NULL, 0);
1628 infoPtr->pszTitle = Alloc(size);
1629 if (!infoPtr->pszTitle)
1630 return FALSE;
1631 MultiByteToWideChar(CP_ACP, 0, (LPCSTR)pszTitle, -1, infoPtr->pszTitle, size/sizeof(WCHAR));
1634 else
1635 infoPtr->pszTitle = NULL;
1637 if (uTitleIcon <= TTI_ERROR)
1638 infoPtr->hTitleIcon = hTooltipIcons[uTitleIcon];
1639 else
1640 infoPtr->hTitleIcon = CopyIcon((HICON)uTitleIcon);
1642 TRACE("icon = %p\n", infoPtr->hTitleIcon);
1644 return TRUE;
1648 static LRESULT
1649 TOOLTIPS_SetToolInfoT (TOOLTIPS_INFO *infoPtr, const TTTOOLINFOW *ti, BOOL isW)
1651 TTTOOL_INFO *toolPtr;
1652 INT nTool;
1654 if (!ti) return 0;
1655 if (ti->cbSize < TTTOOLINFOW_V1_SIZE)
1656 return 0;
1658 nTool = TOOLTIPS_GetToolFromInfoT (infoPtr, ti);
1659 if (nTool == -1) return 0;
1661 TRACE("tool %d\n", nTool);
1663 toolPtr = &infoPtr->tools[nTool];
1665 /* copy tool data */
1666 toolPtr->uFlags = ti->uFlags;
1667 toolPtr->hwnd = ti->hwnd;
1668 toolPtr->uId = ti->uId;
1669 toolPtr->rect = ti->rect;
1670 toolPtr->hinst = ti->hinst;
1672 if (IS_INTRESOURCE(ti->lpszText)) {
1673 TRACE("set string id %x\n", LOWORD(ti->lpszText));
1674 toolPtr->lpszText = ti->lpszText;
1676 else {
1677 if (TOOLTIPS_IsCallbackString(ti->lpszText, isW))
1678 toolPtr->lpszText = LPSTR_TEXTCALLBACKW;
1679 else {
1680 if ( (toolPtr->lpszText) &&
1681 !IS_INTRESOURCE(toolPtr->lpszText) ) {
1682 if( toolPtr->lpszText != LPSTR_TEXTCALLBACKW)
1683 Free (toolPtr->lpszText);
1684 toolPtr->lpszText = NULL;
1686 if (ti->lpszText) {
1687 if (isW) {
1688 INT len = lstrlenW (ti->lpszText);
1689 toolPtr->lpszText = Alloc ((len+1)*sizeof(WCHAR));
1690 strcpyW (toolPtr->lpszText, ti->lpszText);
1692 else {
1693 INT len = MultiByteToWideChar(CP_ACP, 0, (LPSTR)ti->lpszText,
1694 -1, NULL, 0);
1695 toolPtr->lpszText = Alloc (len * sizeof(WCHAR));
1696 MultiByteToWideChar(CP_ACP, 0, (LPSTR)ti->lpszText, -1,
1697 toolPtr->lpszText, len);
1703 if (ti->cbSize >= TTTOOLINFOW_V2_SIZE)
1704 toolPtr->lParam = ti->lParam;
1706 if (infoPtr->nCurrentTool == nTool)
1708 TOOLTIPS_GetTipText (infoPtr, infoPtr->nCurrentTool, infoPtr->szTipText);
1710 if (infoPtr->szTipText[0] == 0)
1711 TOOLTIPS_Hide(infoPtr);
1712 else
1713 TOOLTIPS_Show (infoPtr, FALSE);
1716 return 0;
1720 static LRESULT
1721 TOOLTIPS_TrackActivate (TOOLTIPS_INFO *infoPtr, BOOL track_activate, const TTTOOLINFOA *ti)
1723 if (track_activate) {
1725 if (!ti) return 0;
1726 if (ti->cbSize < TTTOOLINFOA_V1_SIZE)
1727 return FALSE;
1729 /* activate */
1730 infoPtr->nTrackTool = TOOLTIPS_GetToolFromInfoT (infoPtr, (const TTTOOLINFOW*)ti);
1731 if (infoPtr->nTrackTool != -1) {
1732 TRACE("activated\n");
1733 infoPtr->bTrackActive = TRUE;
1734 TOOLTIPS_TrackShow (infoPtr);
1737 else {
1738 /* deactivate */
1739 TOOLTIPS_TrackHide (infoPtr);
1741 infoPtr->bTrackActive = FALSE;
1742 infoPtr->nTrackTool = -1;
1744 TRACE("deactivated\n");
1747 return 0;
1751 static LRESULT
1752 TOOLTIPS_TrackPosition (TOOLTIPS_INFO *infoPtr, LPARAM coord)
1754 infoPtr->xTrackPos = (INT)LOWORD(coord);
1755 infoPtr->yTrackPos = (INT)HIWORD(coord);
1757 if (infoPtr->bTrackActive) {
1758 TRACE("[%d %d]\n",
1759 infoPtr->xTrackPos, infoPtr->yTrackPos);
1761 TOOLTIPS_TrackShow (infoPtr);
1764 return 0;
1768 static LRESULT
1769 TOOLTIPS_Update (TOOLTIPS_INFO *infoPtr)
1771 if (infoPtr->nCurrentTool != -1)
1772 UpdateWindow (infoPtr->hwndSelf);
1774 return 0;
1778 static LRESULT
1779 TOOLTIPS_UpdateTipTextT (TOOLTIPS_INFO *infoPtr, const TTTOOLINFOW *ti, BOOL isW)
1781 TTTOOL_INFO *toolPtr;
1782 INT nTool;
1784 if (!ti) return 0;
1785 if (ti->cbSize < TTTOOLINFOW_V1_SIZE)
1786 return FALSE;
1788 nTool = TOOLTIPS_GetToolFromInfoT (infoPtr, ti);
1789 if (nTool == -1)
1790 return 0;
1792 TRACE("tool %d\n", nTool);
1794 toolPtr = &infoPtr->tools[nTool];
1796 /* copy tool text */
1797 toolPtr->hinst = ti->hinst;
1799 if (IS_INTRESOURCE(ti->lpszText)){
1800 toolPtr->lpszText = ti->lpszText;
1802 else if (ti->lpszText) {
1803 if (TOOLTIPS_IsCallbackString(ti->lpszText, isW))
1804 toolPtr->lpszText = LPSTR_TEXTCALLBACKW;
1805 else {
1806 if ( (toolPtr->lpszText) &&
1807 !IS_INTRESOURCE(toolPtr->lpszText) ) {
1808 if( toolPtr->lpszText != LPSTR_TEXTCALLBACKW)
1809 Free (toolPtr->lpszText);
1810 toolPtr->lpszText = NULL;
1812 if (ti->lpszText) {
1813 if (isW) {
1814 INT len = lstrlenW (ti->lpszText);
1815 toolPtr->lpszText = Alloc ((len+1)*sizeof(WCHAR));
1816 strcpyW (toolPtr->lpszText, ti->lpszText);
1818 else {
1819 INT len = MultiByteToWideChar(CP_ACP, 0, (LPSTR)ti->lpszText,
1820 -1, NULL, 0);
1821 toolPtr->lpszText = Alloc (len * sizeof(WCHAR));
1822 MultiByteToWideChar(CP_ACP, 0, (LPSTR)ti->lpszText, -1,
1823 toolPtr->lpszText, len);
1829 if(infoPtr->nCurrentTool == -1) return 0;
1830 /* force repaint */
1831 if (infoPtr->bActive)
1832 TOOLTIPS_Show (infoPtr, FALSE);
1833 else if (infoPtr->bTrackActive)
1834 TOOLTIPS_Show (infoPtr, TRUE);
1836 return 0;
1840 static LRESULT
1841 TOOLTIPS_Create (HWND hwnd)
1843 TOOLTIPS_INFO *infoPtr;
1845 /* allocate memory for info structure */
1846 infoPtr = Alloc (sizeof(TOOLTIPS_INFO));
1847 SetWindowLongPtrW (hwnd, 0, (DWORD_PTR)infoPtr);
1849 /* initialize info structure */
1850 infoPtr->bActive = TRUE;
1851 infoPtr->bTrackActive = FALSE;
1853 infoPtr->nMaxTipWidth = -1;
1854 infoPtr->nTool = -1;
1855 infoPtr->nCurrentTool = -1;
1856 infoPtr->nTrackTool = -1;
1857 infoPtr->hwndSelf = hwnd;
1859 /* initialize colours and fonts */
1860 TOOLTIPS_InitSystemSettings(infoPtr);
1862 TOOLTIPS_SetDelayTime(infoPtr, TTDT_AUTOMATIC, 0);
1864 SetWindowPos (hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOZORDER | SWP_HIDEWINDOW | SWP_NOACTIVATE);
1866 return 0;
1870 static LRESULT
1871 TOOLTIPS_Destroy (TOOLTIPS_INFO *infoPtr)
1873 TTTOOL_INFO *toolPtr;
1874 UINT i;
1876 /* free tools */
1877 if (infoPtr->tools) {
1878 for (i = 0; i < infoPtr->uNumTools; i++) {
1879 toolPtr = &infoPtr->tools[i];
1880 if (toolPtr->lpszText) {
1881 if ( (toolPtr->lpszText != LPSTR_TEXTCALLBACKW) &&
1882 !IS_INTRESOURCE(toolPtr->lpszText) )
1884 Free (toolPtr->lpszText);
1885 toolPtr->lpszText = NULL;
1889 TOOLTIPS_ResetSubclass (toolPtr);
1892 Free (infoPtr->tools);
1895 /* free title string */
1896 Free (infoPtr->pszTitle);
1897 /* free title icon if not a standard one */
1898 if (TOOLTIPS_GetTitleIconIndex(infoPtr->hTitleIcon) > TTI_ERROR)
1899 DeleteObject(infoPtr->hTitleIcon);
1901 /* delete fonts */
1902 DeleteObject (infoPtr->hFont);
1903 DeleteObject (infoPtr->hTitleFont);
1905 /* free tool tips info data */
1906 SetWindowLongPtrW(infoPtr->hwndSelf, 0, 0);
1907 Free (infoPtr);
1909 return 0;
1913 static inline LRESULT
1914 TOOLTIPS_GetFont (const TOOLTIPS_INFO *infoPtr)
1916 return (LRESULT)infoPtr->hFont;
1920 static LRESULT
1921 TOOLTIPS_MouseMessage (TOOLTIPS_INFO *infoPtr)
1923 TOOLTIPS_Hide (infoPtr);
1925 return 0;
1929 static LRESULT
1930 TOOLTIPS_NCCreate (HWND hwnd)
1932 DWORD dwStyle = GetWindowLongW (hwnd, GWL_STYLE);
1933 DWORD dwExStyle = GetWindowLongW (hwnd, GWL_EXSTYLE);
1935 dwStyle &= ~(WS_CHILD | /*WS_MAXIMIZE |*/ WS_BORDER | WS_DLGFRAME);
1936 dwStyle |= (WS_POPUP | WS_BORDER | WS_CLIPSIBLINGS);
1938 /* WS_BORDER only draws a border round the window rect, not the
1939 * window region, therefore it is useless to us in balloon mode */
1940 if (dwStyle & TTS_BALLOON) dwStyle &= ~WS_BORDER;
1942 SetWindowLongW (hwnd, GWL_STYLE, dwStyle);
1944 dwExStyle |= WS_EX_TOOLWINDOW;
1945 SetWindowLongW (hwnd, GWL_EXSTYLE, dwExStyle);
1947 return TRUE;
1951 static LRESULT
1952 TOOLTIPS_NCHitTest (const TOOLTIPS_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
1954 INT nTool = (infoPtr->bTrackActive) ? infoPtr->nTrackTool : infoPtr->nTool;
1956 TRACE(" nTool=%d\n", nTool);
1958 if ((nTool > -1) && (nTool < infoPtr->uNumTools)) {
1959 if (infoPtr->tools[nTool].uFlags & TTF_TRANSPARENT) {
1960 TRACE("-- in transparent mode\n");
1961 return HTTRANSPARENT;
1965 return DefWindowProcW (infoPtr->hwndSelf, WM_NCHITTEST, wParam, lParam);
1969 static LRESULT
1970 TOOLTIPS_NotifyFormat (TOOLTIPS_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
1972 FIXME ("hwnd=%p wParam=%lx lParam=%lx\n", infoPtr->hwndSelf, wParam, lParam);
1974 return 0;
1978 static LRESULT
1979 TOOLTIPS_Paint (const TOOLTIPS_INFO *infoPtr, HDC hDC)
1981 HDC hdc;
1982 PAINTSTRUCT ps;
1984 hdc = (hDC == NULL) ? BeginPaint (infoPtr->hwndSelf, &ps) : hDC;
1985 TOOLTIPS_Refresh (infoPtr, hdc);
1986 if (!hDC)
1987 EndPaint (infoPtr->hwndSelf, &ps);
1988 return 0;
1992 static LRESULT
1993 TOOLTIPS_SetFont (TOOLTIPS_INFO *infoPtr, HFONT hFont, BOOL redraw)
1995 LOGFONTW lf;
1997 if(!GetObjectW(hFont, sizeof(lf), &lf))
1998 return 0;
2000 DeleteObject (infoPtr->hFont);
2001 infoPtr->hFont = CreateFontIndirectW(&lf);
2003 DeleteObject (infoPtr->hTitleFont);
2004 lf.lfWeight = FW_BOLD;
2005 infoPtr->hTitleFont = CreateFontIndirectW(&lf);
2007 if (redraw && infoPtr->nCurrentTool != -1)
2008 FIXME("full redraw needed\n");
2010 return 0;
2013 /******************************************************************
2014 * TOOLTIPS_GetTextLength
2016 * This function is called when the tooltip receive a
2017 * WM_GETTEXTLENGTH message.
2019 * returns the length, in characters, of the tip text
2021 static inline LRESULT
2022 TOOLTIPS_GetTextLength(const TOOLTIPS_INFO *infoPtr)
2024 return strlenW(infoPtr->szTipText);
2027 /******************************************************************
2028 * TOOLTIPS_OnWMGetText
2030 * This function is called when the tooltip receive a
2031 * WM_GETTEXT message.
2032 * wParam : specifies the maximum number of characters to be copied
2033 * lParam : is the pointer to the buffer that will receive
2034 * the tip text
2036 * returns the number of characters copied
2038 static LRESULT
2039 TOOLTIPS_OnWMGetText (const TOOLTIPS_INFO *infoPtr, WPARAM size, LPWSTR pszText)
2041 LRESULT res;
2043 if(!size)
2044 return 0;
2046 res = min(strlenW(infoPtr->szTipText)+1, size);
2047 memcpy(pszText, infoPtr->szTipText, res*sizeof(WCHAR));
2048 pszText[res-1] = '\0';
2049 return res-1;
2052 static LRESULT
2053 TOOLTIPS_Timer (TOOLTIPS_INFO *infoPtr, INT iTimer)
2055 INT nOldTool;
2057 TRACE("timer %d (%p) expired\n", iTimer, infoPtr->hwndSelf);
2059 switch (iTimer) {
2060 case ID_TIMERSHOW:
2061 KillTimer (infoPtr->hwndSelf, ID_TIMERSHOW);
2062 nOldTool = infoPtr->nTool;
2063 if ((infoPtr->nTool = TOOLTIPS_CheckTool (infoPtr, TRUE)) == nOldTool)
2064 TOOLTIPS_Show (infoPtr, FALSE);
2065 break;
2067 case ID_TIMERPOP:
2068 TOOLTIPS_Hide (infoPtr);
2069 break;
2071 case ID_TIMERLEAVE:
2072 nOldTool = infoPtr->nTool;
2073 infoPtr->nTool = TOOLTIPS_CheckTool (infoPtr, FALSE);
2074 TRACE("tool (%p) %d %d %d\n", infoPtr->hwndSelf, nOldTool,
2075 infoPtr->nTool, infoPtr->nCurrentTool);
2076 if (infoPtr->nTool != nOldTool) {
2077 if(infoPtr->nTool == -1) { /* Moved out of all tools */
2078 TOOLTIPS_Hide(infoPtr);
2079 KillTimer(infoPtr->hwndSelf, ID_TIMERLEAVE);
2080 } else if (nOldTool == -1) { /* Moved from outside */
2081 ERR("How did this happen?\n");
2082 } else { /* Moved from one to another */
2083 TOOLTIPS_Hide (infoPtr);
2084 KillTimer(infoPtr->hwndSelf, ID_TIMERLEAVE);
2085 if(infoPtr->bActive) {
2086 SetTimer (infoPtr->hwndSelf, ID_TIMERSHOW, infoPtr->nReshowTime, 0);
2087 TRACE("timer 1 started!\n");
2091 break;
2093 default:
2094 ERR("Unknown timer id %d\n", iTimer);
2095 break;
2097 return 0;
2101 static LRESULT
2102 TOOLTIPS_WinIniChange (TOOLTIPS_INFO *infoPtr)
2104 TOOLTIPS_InitSystemSettings (infoPtr);
2106 return 0;
2110 static LRESULT CALLBACK
2111 TOOLTIPS_SubclassProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam, UINT_PTR uID, DWORD_PTR dwRef)
2113 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr ((HWND)dwRef);
2114 MSG msg;
2116 switch (message)
2118 case WM_MOUSEMOVE:
2119 case WM_LBUTTONDOWN:
2120 case WM_LBUTTONUP:
2121 case WM_MBUTTONDOWN:
2122 case WM_MBUTTONUP:
2123 case WM_RBUTTONDOWN:
2124 case WM_RBUTTONUP:
2125 if (infoPtr)
2127 msg.hwnd = hwnd;
2128 msg.message = message;
2129 msg.wParam = wParam;
2130 msg.lParam = lParam;
2131 TOOLTIPS_RelayEvent(infoPtr, &msg);
2133 break;
2134 case WM_NCDESTROY:
2135 RemoveWindowSubclass(hwnd, TOOLTIPS_SubclassProc, 1);
2136 break;
2137 default:
2138 break;
2141 return DefSubclassProc(hwnd, message, wParam, lParam);
2145 static LRESULT CALLBACK
2146 TOOLTIPS_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2148 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
2150 TRACE("hwnd=%p msg=%x wparam=%lx lParam=%lx\n", hwnd, uMsg, wParam, lParam);
2151 if (!infoPtr && (uMsg != WM_CREATE) && (uMsg != WM_NCCREATE))
2152 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
2153 switch (uMsg)
2155 case TTM_ACTIVATE:
2156 return TOOLTIPS_Activate (infoPtr, (BOOL)wParam);
2158 case TTM_ADDTOOLA:
2159 case TTM_ADDTOOLW:
2160 return TOOLTIPS_AddToolT (infoPtr, (LPTTTOOLINFOW)lParam, uMsg == TTM_ADDTOOLW);
2162 case TTM_DELTOOLA:
2163 case TTM_DELTOOLW:
2164 return TOOLTIPS_DelToolT (infoPtr, (LPTOOLINFOW)lParam,
2165 uMsg == TTM_DELTOOLW);
2166 case TTM_ENUMTOOLSA:
2167 case TTM_ENUMTOOLSW:
2168 return TOOLTIPS_EnumToolsT (infoPtr, (UINT)wParam, (LPTTTOOLINFOW)lParam,
2169 uMsg == TTM_ENUMTOOLSW);
2170 case TTM_GETBUBBLESIZE:
2171 return TOOLTIPS_GetBubbleSize (infoPtr, (LPTTTOOLINFOW)lParam);
2173 case TTM_GETCURRENTTOOLA:
2174 case TTM_GETCURRENTTOOLW:
2175 return TOOLTIPS_GetCurrentToolT (infoPtr, (LPTTTOOLINFOW)lParam,
2176 uMsg == TTM_GETCURRENTTOOLW);
2178 case TTM_GETDELAYTIME:
2179 return TOOLTIPS_GetDelayTime (infoPtr, (DWORD)wParam);
2181 case TTM_GETMARGIN:
2182 return TOOLTIPS_GetMargin (infoPtr, (LPRECT)lParam);
2184 case TTM_GETMAXTIPWIDTH:
2185 return TOOLTIPS_GetMaxTipWidth (infoPtr);
2187 case TTM_GETTEXTA:
2188 case TTM_GETTEXTW:
2189 return TOOLTIPS_GetTextT (infoPtr, (LPTTTOOLINFOW)lParam,
2190 uMsg == TTM_GETTEXTW);
2192 case TTM_GETTIPBKCOLOR:
2193 return TOOLTIPS_GetTipBkColor (infoPtr);
2195 case TTM_GETTIPTEXTCOLOR:
2196 return TOOLTIPS_GetTipTextColor (infoPtr);
2198 case TTM_GETTOOLCOUNT:
2199 return TOOLTIPS_GetToolCount (infoPtr);
2201 case TTM_GETTOOLINFOA:
2202 case TTM_GETTOOLINFOW:
2203 return TOOLTIPS_GetToolInfoT (infoPtr, (LPTTTOOLINFOW)lParam,
2204 uMsg == TTM_GETTOOLINFOW);
2206 case TTM_HITTESTA:
2207 case TTM_HITTESTW:
2208 return TOOLTIPS_HitTestT (infoPtr, (LPTTHITTESTINFOW)lParam,
2209 uMsg == TTM_HITTESTW);
2210 case TTM_NEWTOOLRECTA:
2211 case TTM_NEWTOOLRECTW:
2212 return TOOLTIPS_NewToolRectT (infoPtr, (LPTTTOOLINFOW)lParam);
2214 case TTM_POP:
2215 return TOOLTIPS_Pop (infoPtr);
2217 case TTM_RELAYEVENT:
2218 return TOOLTIPS_RelayEvent (infoPtr, (LPMSG)lParam);
2220 case TTM_SETDELAYTIME:
2221 return TOOLTIPS_SetDelayTime (infoPtr, (DWORD)wParam, (INT)LOWORD(lParam));
2223 case TTM_SETMARGIN:
2224 return TOOLTIPS_SetMargin (infoPtr, (LPRECT)lParam);
2226 case TTM_SETMAXTIPWIDTH:
2227 return TOOLTIPS_SetMaxTipWidth (infoPtr, (INT)lParam);
2229 case TTM_SETTIPBKCOLOR:
2230 return TOOLTIPS_SetTipBkColor (infoPtr, (COLORREF)wParam);
2232 case TTM_SETTIPTEXTCOLOR:
2233 return TOOLTIPS_SetTipTextColor (infoPtr, (COLORREF)wParam);
2235 case TTM_SETTITLEA:
2236 case TTM_SETTITLEW:
2237 return TOOLTIPS_SetTitleT (infoPtr, (UINT_PTR)wParam, (LPCWSTR)lParam,
2238 uMsg == TTM_SETTITLEW);
2240 case TTM_SETTOOLINFOA:
2241 case TTM_SETTOOLINFOW:
2242 return TOOLTIPS_SetToolInfoT (infoPtr, (LPTTTOOLINFOW)lParam,
2243 uMsg == TTM_SETTOOLINFOW);
2245 case TTM_TRACKACTIVATE:
2246 return TOOLTIPS_TrackActivate (infoPtr, (BOOL)wParam, (LPTTTOOLINFOA)lParam);
2248 case TTM_TRACKPOSITION:
2249 return TOOLTIPS_TrackPosition (infoPtr, lParam);
2251 case TTM_UPDATE:
2252 return TOOLTIPS_Update (infoPtr);
2254 case TTM_UPDATETIPTEXTA:
2255 case TTM_UPDATETIPTEXTW:
2256 return TOOLTIPS_UpdateTipTextT (infoPtr, (LPTTTOOLINFOW)lParam,
2257 uMsg == TTM_UPDATETIPTEXTW);
2259 case TTM_WINDOWFROMPOINT:
2260 return (LRESULT)WindowFromPoint (*((LPPOINT)lParam));
2262 case WM_CREATE:
2263 return TOOLTIPS_Create (hwnd);
2265 case WM_DESTROY:
2266 return TOOLTIPS_Destroy (infoPtr);
2268 case WM_ERASEBKGND:
2269 /* we draw the background in WM_PAINT */
2270 return 0;
2272 case WM_GETFONT:
2273 return TOOLTIPS_GetFont (infoPtr);
2275 case WM_GETTEXT:
2276 return TOOLTIPS_OnWMGetText (infoPtr, wParam, (LPWSTR)lParam);
2278 case WM_GETTEXTLENGTH:
2279 return TOOLTIPS_GetTextLength (infoPtr);
2281 case WM_LBUTTONDOWN:
2282 case WM_LBUTTONUP:
2283 case WM_MBUTTONDOWN:
2284 case WM_MBUTTONUP:
2285 case WM_RBUTTONDOWN:
2286 case WM_RBUTTONUP:
2287 case WM_MOUSEMOVE:
2288 return TOOLTIPS_MouseMessage (infoPtr);
2290 case WM_NCCREATE:
2291 return TOOLTIPS_NCCreate (hwnd);
2293 case WM_NCHITTEST:
2294 return TOOLTIPS_NCHitTest (infoPtr, wParam, lParam);
2296 case WM_NOTIFYFORMAT:
2297 return TOOLTIPS_NotifyFormat (infoPtr, wParam, lParam);
2299 case WM_PRINTCLIENT:
2300 case WM_PAINT:
2301 return TOOLTIPS_Paint (infoPtr, (HDC)wParam);
2303 case WM_SETFONT:
2304 return TOOLTIPS_SetFont (infoPtr, (HFONT)wParam, LOWORD(lParam));
2306 case WM_SYSCOLORCHANGE:
2307 COMCTL32_RefreshSysColors();
2308 return 0;
2310 case WM_TIMER:
2311 return TOOLTIPS_Timer (infoPtr, (INT)wParam);
2313 case WM_WININICHANGE:
2314 return TOOLTIPS_WinIniChange (infoPtr);
2316 default:
2317 if ((uMsg >= WM_USER) && (uMsg < WM_APP) && !COMCTL32_IsReflectedMessage(uMsg))
2318 ERR("unknown msg %04x wp=%08lx lp=%08lx\n",
2319 uMsg, wParam, lParam);
2320 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
2325 VOID
2326 TOOLTIPS_Register (void)
2328 WNDCLASSW wndClass;
2330 ZeroMemory (&wndClass, sizeof(WNDCLASSW));
2331 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS | CS_SAVEBITS;
2332 wndClass.lpfnWndProc = TOOLTIPS_WindowProc;
2333 wndClass.cbClsExtra = 0;
2334 wndClass.cbWndExtra = sizeof(TOOLTIPS_INFO *);
2335 wndClass.hCursor = LoadCursorW (0, (LPWSTR)IDC_ARROW);
2336 wndClass.hbrBackground = 0;
2337 wndClass.lpszClassName = TOOLTIPS_CLASSW;
2339 RegisterClassW (&wndClass);
2341 hTooltipIcons[TTI_NONE] = NULL;
2342 hTooltipIcons[TTI_INFO] = LoadImageW(COMCTL32_hModule,
2343 (LPCWSTR)MAKEINTRESOURCE(IDI_TT_INFO_SM), IMAGE_ICON, 0, 0, 0);
2344 hTooltipIcons[TTI_WARNING] = LoadImageW(COMCTL32_hModule,
2345 (LPCWSTR)MAKEINTRESOURCE(IDI_TT_WARN_SM), IMAGE_ICON, 0, 0, 0);
2346 hTooltipIcons[TTI_ERROR] = LoadImageW(COMCTL32_hModule,
2347 (LPCWSTR)MAKEINTRESOURCE(IDI_TT_ERROR_SM), IMAGE_ICON, 0, 0, 0);
2351 VOID
2352 TOOLTIPS_Unregister (void)
2354 int i;
2355 for (i = TTI_INFO; i <= TTI_ERROR; i++)
2356 DestroyIcon(hTooltipIcons[i]);
2357 UnregisterClassW (TOOLTIPS_CLASSW, NULL);