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
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.
31 * - Custom draw support.
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.
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
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
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
99 #include "wine/unicode.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];
127 WCHAR szTipText[INFOTIPSIZE];
138 INT nTool; /* tool that mouse was on on last relayed mouse move */
152 #define ID_TIMERSHOW 1 /* show delay timer */
153 #define ID_TIMERPOP 2 /* auto pop timer */
154 #define ID_TIMERLEAVE 3 /* tool leave timer */
157 #define TOOLTIPS_GetInfoPtr(hWindow) ((TOOLTIPS_INFO *)GetWindowLongPtrW (hWindow, 0))
159 /* offsets from window edge to start of text */
160 #define NORMAL_TEXT_MARGIN 2
161 #define BALLOON_TEXT_MARGIN (NORMAL_TEXT_MARGIN+8)
162 /* value used for CreateRoundRectRgn that specifies how much
163 * each corner is curved */
164 #define BALLOON_ROUNDEDNESS 20
165 #define BALLOON_STEMHEIGHT 13
166 #define BALLOON_STEMWIDTH 10
167 #define BALLOON_STEMINDENT 20
169 #define BALLOON_ICON_TITLE_SPACING 8 /* horizontal spacing between icon and title */
170 #define BALLOON_TITLE_TEXT_SPACING 8 /* vertical spacing between icon/title and main text */
171 #define ICON_HEIGHT 16
172 #define ICON_WIDTH 16
174 static LRESULT CALLBACK
175 TOOLTIPS_SubclassProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uId, DWORD_PTR dwRef);
178 static inline BOOL TOOLTIPS_IsCallbackString(LPCWSTR str, BOOL isW)
181 return str == LPSTR_TEXTCALLBACKW;
183 return (LPCSTR)str == LPSTR_TEXTCALLBACKA;
186 static inline UINT_PTR
187 TOOLTIPS_GetTitleIconIndex(HICON hIcon)
190 for (i = 0; i <= TTI_ERROR; i++)
191 if (hTooltipIcons[i] == hIcon)
193 return (UINT_PTR)hIcon;
197 TOOLTIPS_InitSystemSettings (TOOLTIPS_INFO *infoPtr)
199 NONCLIENTMETRICSW nclm;
201 infoPtr->clrBk = comctl32_color.clrInfoBk;
202 infoPtr->clrText = comctl32_color.clrInfoText;
204 DeleteObject (infoPtr->hFont);
205 nclm.cbSize = sizeof(nclm);
206 SystemParametersInfoW (SPI_GETNONCLIENTMETRICS, sizeof(nclm), &nclm, 0);
207 infoPtr->hFont = CreateFontIndirectW (&nclm.lfStatusFont);
209 DeleteObject (infoPtr->hTitleFont);
210 nclm.lfStatusFont.lfWeight = FW_BOLD;
211 infoPtr->hTitleFont = CreateFontIndirectW (&nclm.lfStatusFont);
214 /* Custom draw routines */
216 TOOLTIPS_customdraw_fill(NMTTCUSTOMDRAW *lpnmttcd,
218 HDC hdc, const RECT *rcBounds, UINT uFlags)
220 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr(hwnd);
222 ZeroMemory(lpnmttcd, sizeof(NMTTCUSTOMDRAW));
223 lpnmttcd->uDrawFlags = uFlags;
224 lpnmttcd->nmcd.hdr.hwndFrom = hwnd;
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 */
236 TOOLTIPS_notify_customdraw (DWORD dwDrawStage, NMTTCUSTOMDRAW *lpnmttcd)
238 LRESULT result = CDRF_DODEFAULT;
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);
253 TOOLTIPS_Refresh (const TOOLTIPS_INFO *infoPtr, HDC hdc)
259 UINT uFlags = DT_EXTERNALLEADING;
261 DWORD dwStyle = GetWindowLongW(infoPtr->hwndSelf, GWL_STYLE);
262 NMTTCUSTOMDRAW nmttcd;
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(&nmttcd, infoPtr->hwndSelf, 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);
297 /* fill the background */
298 FillRect(hdc, &rc, hBrush);
299 DeleteObject(hBrush);
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};
320 icon_present = infoPtr->hTitleIcon &&
321 DrawIconEx(hdc, rc.left, rc.top, infoPtr->hTitleIcon,
322 ICON_WIDTH, ICON_HEIGHT, 0, NULL, DI_NORMAL);
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;
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);
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);
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) {
397 else if (ttnmdi.lpszText != LPSTR_TEXTCALLBACKA) {
398 Str_GetPtrAtoW(ttnmdi.lpszText, buffer, INFOTIPSIZE);
399 if (ttnmdi.uFlags & TTF_DI_SETITEM) {
401 toolPtr->lpszText = NULL;
402 Str_SetPtrW(&toolPtr->lpszText, buffer);
406 ERR("recursive text callback!\n");
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) {
453 else if (ttnmdi.lpszText != LPSTR_TEXTCALLBACKW) {
454 Str_GetPtrW(ttnmdi.lpszText, buffer, INFOTIPSIZE);
455 if (ttnmdi.uFlags & TTF_DI_SETITEM) {
457 toolPtr->lpszText = NULL;
458 Str_SetPtrW(&toolPtr->lpszText, buffer);
462 ERR("recursive text callback!\n");
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);
484 TOOLTIPS_GetTipText (const TOOLTIPS_INFO *infoPtr, INT nTool, WCHAR *buffer)
486 TTTOOL_INFO *toolPtr = &infoPtr->tools[nTool];
488 if (IS_INTRESOURCE(toolPtr->lpszText) && toolPtr->hinst) {
489 /* load a resource */
490 TRACE("load res string %p %x\n",
491 toolPtr->hinst, LOWORD(toolPtr->lpszText));
492 LoadStringW (toolPtr->hinst, LOWORD(toolPtr->lpszText),
493 buffer, INFOTIPSIZE);
495 else if (toolPtr->lpszText) {
496 if (toolPtr->lpszText == LPSTR_TEXTCALLBACKW) {
497 if (toolPtr->bNotifyUnicode)
498 TOOLTIPS_GetDispInfoW(infoPtr, toolPtr, buffer);
500 TOOLTIPS_GetDispInfoA(infoPtr, toolPtr, buffer);
503 /* the item is a usual (unicode) text */
504 lstrcpynW (buffer, toolPtr->lpszText, INFOTIPSIZE);
508 /* no text available */
512 TRACE("%s\n", debugstr_w(buffer));
517 TOOLTIPS_CalcTipSize (const TOOLTIPS_INFO *infoPtr, LPSIZE lpSize)
521 DWORD style = GetWindowLongW(infoPtr->hwndSelf, GWL_STYLE);
522 UINT uFlags = DT_EXTERNALLEADING | DT_CALCRECT;
523 RECT rc = {0, 0, 0, 0};
526 if (infoPtr->nMaxTipWidth > -1) {
527 rc.right = infoPtr->nMaxTipWidth;
528 uFlags |= DT_WORDBREAK;
530 if (style & TTS_NOPREFIX)
531 uFlags |= DT_NOPREFIX;
532 TRACE("%s\n", debugstr_w(infoPtr->szTipText));
534 hdc = GetDC (infoPtr->hwndSelf);
535 if (infoPtr->pszTitle)
537 RECT rcTitle = {0, 0, 0, 0};
538 TRACE("title %s\n", debugstr_w(infoPtr->pszTitle));
539 if (infoPtr->hTitleIcon)
541 title.cx = ICON_WIDTH;
542 title.cy = ICON_HEIGHT;
544 if (title.cx != 0) title.cx += BALLOON_ICON_TITLE_SPACING;
545 hOldFont = SelectObject (hdc, infoPtr->hTitleFont);
546 DrawTextW(hdc, infoPtr->pszTitle, -1, &rcTitle, DT_SINGLELINE | DT_NOPREFIX | DT_CALCRECT);
547 SelectObject (hdc, hOldFont);
548 title.cy = max(title.cy, rcTitle.bottom - rcTitle.top) + BALLOON_TITLE_TEXT_SPACING;
549 title.cx += (rcTitle.right - rcTitle.left);
551 hOldFont = SelectObject (hdc, infoPtr->hFont);
552 DrawTextW (hdc, infoPtr->szTipText, -1, &rc, uFlags);
553 SelectObject (hdc, hOldFont);
554 ReleaseDC (infoPtr->hwndSelf, hdc);
556 if ((style & TTS_BALLOON) || infoPtr->pszTitle)
558 lpSize->cx = max(rc.right - rc.left, title.cx) + 2*BALLOON_TEXT_MARGIN +
559 infoPtr->rcMargin.left + infoPtr->rcMargin.right;
560 lpSize->cy = title.cy + rc.bottom - rc.top + 2*BALLOON_TEXT_MARGIN +
561 infoPtr->rcMargin.bottom + infoPtr->rcMargin.top +
566 lpSize->cx = rc.right - rc.left + 2*NORMAL_TEXT_MARGIN +
567 infoPtr->rcMargin.left + infoPtr->rcMargin.right;
568 lpSize->cy = rc.bottom - rc.top + 2*NORMAL_TEXT_MARGIN +
569 infoPtr->rcMargin.bottom + infoPtr->rcMargin.top;
575 TOOLTIPS_Show (TOOLTIPS_INFO *infoPtr, BOOL track_activate)
577 TTTOOL_INFO *toolPtr;
579 MONITORINFO mon_info;
584 DWORD style = GetWindowLongW(infoPtr->hwndSelf, GWL_STYLE);
589 if (infoPtr->nTrackTool == -1)
591 TRACE("invalid tracking tool (-1)!\n");
594 nTool = infoPtr->nTrackTool;
598 if (infoPtr->nTool == -1)
600 TRACE("invalid tool (-1)!\n");
603 nTool = infoPtr->nTool;
606 TRACE("Show tooltip pre %d! (%p)\n", nTool, infoPtr->hwndSelf);
608 TOOLTIPS_GetTipText (infoPtr, nTool, infoPtr->szTipText);
610 if (infoPtr->szTipText[0] == '\0')
613 toolPtr = &infoPtr->tools[nTool];
616 infoPtr->nCurrentTool = infoPtr->nTool;
618 TRACE("Show tooltip %d!\n", nTool);
620 hdr.hwndFrom = infoPtr->hwndSelf;
621 hdr.idFrom = toolPtr->uId;
623 SendMessageW (toolPtr->hwnd, WM_NOTIFY, toolPtr->uId, (LPARAM)&hdr);
625 TRACE("%s\n", debugstr_w(infoPtr->szTipText));
627 TOOLTIPS_CalcTipSize (infoPtr, &size);
628 TRACE("size %d x %d\n", size.cx, size.cy);
632 rect.left = infoPtr->xTrackPos;
633 rect.top = infoPtr->yTrackPos;
636 if (toolPtr->uFlags & TTF_CENTERTIP)
638 rect.left -= (size.cx / 2);
639 if (!(style & TTS_BALLOON))
640 rect.top -= (size.cy / 2);
642 infoPtr->bToolBelow = TRUE;
644 if (!(toolPtr->uFlags & TTF_ABSOLUTE))
646 if (style & TTS_BALLOON)
647 rect.left -= BALLOON_STEMINDENT;
652 if (toolPtr->uFlags & TTF_IDISHWND)
653 GetWindowRect ((HWND)toolPtr->uId, &rcTool);
656 rcTool = toolPtr->rect;
657 MapWindowPoints (toolPtr->hwnd, NULL, (LPPOINT)&rcTool, 2);
660 /* smart placement */
661 if ((rect.left + size.cx > rcTool.left) && (rect.left < rcTool.right) &&
662 (rect.top + size.cy > rcTool.top) && (rect.top < rcTool.bottom))
663 rect.left = rcTool.right;
669 if (toolPtr->uFlags & TTF_CENTERTIP)
673 if (toolPtr->uFlags & TTF_IDISHWND)
674 GetWindowRect ((HWND)toolPtr->uId, &rc);
677 MapWindowPoints (toolPtr->hwnd, NULL, (LPPOINT)&rc, 2);
679 rect.left = (rc.left + rc.right - size.cx) / 2;
680 if (style & TTS_BALLOON)
682 ptfx = rc.left + ((rc.right - rc.left) / 2);
684 /* CENTERTIP ballon tooltips default to below the field
685 * if they fit on the screen */
686 if (rc.bottom + size.cy > GetSystemMetrics(SM_CYSCREEN))
688 rect.top = rc.top - size.cy;
689 infoPtr->bToolBelow = FALSE;
693 infoPtr->bToolBelow = TRUE;
694 rect.top = rc.bottom;
696 rect.left = max(0, rect.left - BALLOON_STEMINDENT);
700 rect.top = rc.bottom + 2;
701 infoPtr->bToolBelow = TRUE;
706 GetCursorPos ((LPPOINT)&rect);
707 if (style & TTS_BALLOON)
710 if(rect.top - size.cy >= 0)
713 infoPtr->bToolBelow = FALSE;
717 infoPtr->bToolBelow = TRUE;
720 rect.left = max(0, rect.left - BALLOON_STEMINDENT);
725 infoPtr->bToolBelow = TRUE;
730 TRACE("pos %d - %d\n", rect.left, rect.top);
732 rect.right = rect.left + size.cx;
733 rect.bottom = rect.top + size.cy;
737 monitor = MonitorFromRect( &rect, MONITOR_DEFAULTTOPRIMARY );
738 mon_info.cbSize = sizeof(mon_info);
739 GetMonitorInfoW( monitor, &mon_info );
741 if( rect.right > mon_info.rcWork.right ) {
742 rect.left -= rect.right - mon_info.rcWork.right + 2;
743 rect.right = mon_info.rcWork.right - 2;
745 if (rect.left < mon_info.rcWork.left) rect.left = mon_info.rcWork.left;
747 if( rect.bottom > mon_info.rcWork.bottom ) {
750 if (toolPtr->uFlags & TTF_IDISHWND)
751 GetWindowRect ((HWND)toolPtr->uId, &rc);
754 MapWindowPoints (toolPtr->hwnd, NULL, (LPPOINT)&rc, 2);
756 rect.bottom = rc.top - 2;
757 rect.top = rect.bottom - size.cy;
760 AdjustWindowRectEx (&rect, GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE),
761 FALSE, GetWindowLongW (infoPtr->hwndSelf, GWL_EXSTYLE));
763 if (style & TTS_BALLOON)
771 if(infoPtr->bToolBelow)
775 pts[1].x = max(BALLOON_STEMINDENT, ptfx - (BALLOON_STEMWIDTH / 2));
776 pts[1].y = BALLOON_STEMHEIGHT;
777 pts[2].x = pts[1].x + BALLOON_STEMWIDTH;
779 if(pts[2].x > (rect.right - rect.left) - BALLOON_STEMINDENT)
781 pts[2].x = (rect.right - rect.left) - BALLOON_STEMINDENT;
782 pts[1].x = pts[2].x - BALLOON_STEMWIDTH;
787 pts[0].x = max(BALLOON_STEMINDENT, ptfx - (BALLOON_STEMWIDTH / 2));
788 pts[0].y = (rect.bottom - rect.top) - BALLOON_STEMHEIGHT;
789 pts[1].x = pts[0].x + BALLOON_STEMWIDTH;
792 pts[2].y = (rect.bottom - rect.top);
793 if(pts[1].x > (rect.right - rect.left) - BALLOON_STEMINDENT)
795 pts[1].x = (rect.right - rect.left) - BALLOON_STEMINDENT;
796 pts[0].x = pts[1].x - BALLOON_STEMWIDTH;
800 hrStem = CreatePolygonRgn(pts, sizeof(pts) / sizeof(pts[0]), ALTERNATE);
802 hRgn = CreateRoundRectRgn(0,
803 (infoPtr->bToolBelow ? BALLOON_STEMHEIGHT : 0),
804 rect.right - rect.left,
805 (infoPtr->bToolBelow ? rect.bottom - rect.top : rect.bottom - rect.top - BALLOON_STEMHEIGHT),
806 BALLOON_ROUNDEDNESS, BALLOON_ROUNDEDNESS);
808 CombineRgn(hRgn, hRgn, hrStem, RGN_OR);
809 DeleteObject(hrStem);
811 SetWindowRgn(infoPtr->hwndSelf, hRgn, FALSE);
812 /* we don't free the region handle as the system deletes it when
813 * it is no longer needed */
816 SetWindowPos (infoPtr->hwndSelf, HWND_TOPMOST, rect.left, rect.top,
817 rect.right - rect.left, rect.bottom - rect.top,
818 SWP_SHOWWINDOW | SWP_NOACTIVATE);
820 /* repaint the tooltip */
821 InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
822 UpdateWindow(infoPtr->hwndSelf);
826 SetTimer (infoPtr->hwndSelf, ID_TIMERPOP, infoPtr->nAutoPopTime, 0);
827 TRACE("timer 2 started!\n");
828 SetTimer (infoPtr->hwndSelf, ID_TIMERLEAVE, infoPtr->nReshowTime, 0);
829 TRACE("timer 3 started!\n");
835 TOOLTIPS_Hide (TOOLTIPS_INFO *infoPtr)
837 TTTOOL_INFO *toolPtr;
840 TRACE("Hide tooltip %d! (%p)\n", infoPtr->nCurrentTool, infoPtr->hwndSelf);
842 if (infoPtr->nCurrentTool == -1)
845 toolPtr = &infoPtr->tools[infoPtr->nCurrentTool];
846 KillTimer (infoPtr->hwndSelf, ID_TIMERPOP);
848 hdr.hwndFrom = infoPtr->hwndSelf;
849 hdr.idFrom = toolPtr->uId;
851 SendMessageW (toolPtr->hwnd, WM_NOTIFY, toolPtr->uId, (LPARAM)&hdr);
853 infoPtr->nCurrentTool = -1;
855 SetWindowPos (infoPtr->hwndSelf, HWND_TOP, 0, 0, 0, 0,
856 SWP_NOZORDER | SWP_HIDEWINDOW | SWP_NOACTIVATE);
861 TOOLTIPS_TrackShow (TOOLTIPS_INFO *infoPtr)
863 TOOLTIPS_Show(infoPtr, TRUE);
868 TOOLTIPS_TrackHide (const TOOLTIPS_INFO *infoPtr)
870 TTTOOL_INFO *toolPtr;
873 TRACE("hide tracking tooltip %d\n", infoPtr->nTrackTool);
875 if (infoPtr->nTrackTool == -1)
878 toolPtr = &infoPtr->tools[infoPtr->nTrackTool];
880 hdr.hwndFrom = infoPtr->hwndSelf;
881 hdr.idFrom = toolPtr->uId;
883 SendMessageW (toolPtr->hwnd, WM_NOTIFY, toolPtr->uId, (LPARAM)&hdr);
885 SetWindowPos (infoPtr->hwndSelf, HWND_TOP, 0, 0, 0, 0,
886 SWP_NOZORDER | SWP_HIDEWINDOW | SWP_NOACTIVATE);
889 /* Structure layout is the same for TTTOOLINFOW and TTTOOLINFOA,
890 this helper is used in both cases. */
892 TOOLTIPS_GetToolFromInfoT (const TOOLTIPS_INFO *infoPtr, const TTTOOLINFOW *lpToolInfo)
894 TTTOOL_INFO *toolPtr;
897 for (nTool = 0; nTool < infoPtr->uNumTools; nTool++) {
898 toolPtr = &infoPtr->tools[nTool];
900 if (!(toolPtr->uFlags & TTF_IDISHWND) &&
901 (lpToolInfo->hwnd == toolPtr->hwnd) &&
902 (lpToolInfo->uId == toolPtr->uId))
906 for (nTool = 0; nTool < infoPtr->uNumTools; nTool++) {
907 toolPtr = &infoPtr->tools[nTool];
909 if ((toolPtr->uFlags & TTF_IDISHWND) &&
910 (lpToolInfo->uId == toolPtr->uId))
919 TOOLTIPS_GetToolFromPoint (const TOOLTIPS_INFO *infoPtr, HWND hwnd, const POINT *lpPt)
921 TTTOOL_INFO *toolPtr;
924 for (nTool = 0; nTool < infoPtr->uNumTools; nTool++) {
925 toolPtr = &infoPtr->tools[nTool];
927 if (!(toolPtr->uFlags & TTF_IDISHWND)) {
928 if (hwnd != toolPtr->hwnd)
930 if (!PtInRect (&toolPtr->rect, *lpPt))
936 for (nTool = 0; nTool < infoPtr->uNumTools; nTool++) {
937 toolPtr = &infoPtr->tools[nTool];
939 if (toolPtr->uFlags & TTF_IDISHWND) {
940 if ((HWND)toolPtr->uId == hwnd)
950 TOOLTIPS_IsWindowActive (HWND hwnd)
952 HWND hwndActive = GetActiveWindow ();
955 if (hwndActive == hwnd)
957 return IsChild (hwndActive, hwnd);
962 TOOLTIPS_CheckTool (const TOOLTIPS_INFO *infoPtr, BOOL bShowTest)
969 hwndTool = (HWND)SendMessageW (infoPtr->hwndSelf, TTM_WINDOWFROMPOINT, 0, (LPARAM)&pt);
973 ScreenToClient (hwndTool, &pt);
974 nTool = TOOLTIPS_GetToolFromPoint (infoPtr, hwndTool, &pt);
978 if (!(GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE) & TTS_ALWAYSTIP) && bShowTest) {
979 if (!TOOLTIPS_IsWindowActive (GetWindow (infoPtr->hwndSelf, GW_OWNER)))
983 TRACE("tool %d\n", nTool);
990 TOOLTIPS_Activate (TOOLTIPS_INFO *infoPtr, BOOL activate)
992 infoPtr->bActive = activate;
994 if (infoPtr->bActive)
995 TRACE("activate!\n");
997 if (!(infoPtr->bActive) && (infoPtr->nCurrentTool != -1))
998 TOOLTIPS_Hide (infoPtr);
1005 TOOLTIPS_AddToolT (TOOLTIPS_INFO *infoPtr, const TTTOOLINFOW *ti, BOOL isW)
1007 TTTOOL_INFO *toolPtr;
1010 if (!ti) return FALSE;
1012 TRACE("add tool (%p) %p %ld%s!\n",
1013 infoPtr->hwndSelf, ti->hwnd, ti->uId,
1014 (ti->uFlags & TTF_IDISHWND) ? " TTF_IDISHWND" : "");
1016 if (infoPtr->uNumTools == 0) {
1017 infoPtr->tools = Alloc (sizeof(TTTOOL_INFO));
1018 toolPtr = infoPtr->tools;
1021 TTTOOL_INFO *oldTools = infoPtr->tools;
1023 Alloc (sizeof(TTTOOL_INFO) * (infoPtr->uNumTools + 1));
1024 memcpy (infoPtr->tools, oldTools,
1025 infoPtr->uNumTools * sizeof(TTTOOL_INFO));
1027 toolPtr = &infoPtr->tools[infoPtr->uNumTools];
1030 infoPtr->uNumTools++;
1032 /* copy tool data */
1033 toolPtr->uFlags = ti->uFlags;
1034 toolPtr->hwnd = ti->hwnd;
1035 toolPtr->uId = ti->uId;
1036 toolPtr->rect = ti->rect;
1037 toolPtr->hinst = ti->hinst;
1039 if (IS_INTRESOURCE(ti->lpszText)) {
1040 TRACE("add string id %x\n", LOWORD(ti->lpszText));
1041 toolPtr->lpszText = ti->lpszText;
1043 else if (ti->lpszText) {
1044 if (TOOLTIPS_IsCallbackString(ti->lpszText, isW)) {
1045 TRACE("add CALLBACK!\n");
1046 toolPtr->lpszText = LPSTR_TEXTCALLBACKW;
1049 INT len = lstrlenW (ti->lpszText);
1050 TRACE("add text %s!\n", debugstr_w(ti->lpszText));
1051 toolPtr->lpszText = Alloc ((len + 1)*sizeof(WCHAR));
1052 strcpyW (toolPtr->lpszText, ti->lpszText);
1055 INT len = MultiByteToWideChar(CP_ACP, 0, (LPSTR)ti->lpszText, -1, NULL, 0);
1056 TRACE("add text \"%s\"!\n", (LPSTR)ti->lpszText);
1057 toolPtr->lpszText = Alloc (len * sizeof(WCHAR));
1058 MultiByteToWideChar(CP_ACP, 0, (LPSTR)ti->lpszText, -1, toolPtr->lpszText, len);
1062 if (ti->cbSize >= TTTOOLINFOW_V2_SIZE)
1063 toolPtr->lParam = ti->lParam;
1065 /* install subclassing hook */
1066 if (toolPtr->uFlags & TTF_SUBCLASS) {
1067 if (toolPtr->uFlags & TTF_IDISHWND) {
1068 SetWindowSubclass((HWND)toolPtr->uId, TOOLTIPS_SubclassProc, 1,
1069 (DWORD_PTR)infoPtr->hwndSelf);
1072 SetWindowSubclass(toolPtr->hwnd, TOOLTIPS_SubclassProc, 1,
1073 (DWORD_PTR)infoPtr->hwndSelf);
1075 TRACE("subclassing installed!\n");
1078 nResult = (INT) SendMessageW (toolPtr->hwnd, WM_NOTIFYFORMAT,
1079 (WPARAM)infoPtr->hwndSelf, (LPARAM)NF_QUERY);
1080 if (nResult == NFR_ANSI) {
1081 toolPtr->bNotifyUnicode = FALSE;
1082 TRACE(" -- WM_NOTIFYFORMAT returns: NFR_ANSI\n");
1083 } else if (nResult == NFR_UNICODE) {
1084 toolPtr->bNotifyUnicode = TRUE;
1085 TRACE(" -- WM_NOTIFYFORMAT returns: NFR_UNICODE\n");
1087 TRACE (" -- WM_NOTIFYFORMAT returns: error!\n");
1095 TOOLTIPS_DelToolT (TOOLTIPS_INFO *infoPtr, const TTTOOLINFOW *ti, BOOL isW)
1097 TTTOOL_INFO *toolPtr;
1101 if (isW && ti->cbSize > TTTOOLINFOW_V2_SIZE &&
1102 ti->cbSize != TTTOOLINFOW_V3_SIZE)
1104 if (infoPtr->uNumTools == 0)
1107 nTool = TOOLTIPS_GetToolFromInfoT (infoPtr, ti);
1109 TRACE("tool %d\n", nTool);
1114 /* make sure the tooltip has disappeared before deleting it */
1115 TOOLTIPS_Hide(infoPtr);
1117 /* delete text string */
1118 toolPtr = &infoPtr->tools[nTool];
1119 if (toolPtr->lpszText) {
1120 if ( (toolPtr->lpszText != LPSTR_TEXTCALLBACKW) &&
1121 !IS_INTRESOURCE(toolPtr->lpszText) )
1122 Free (toolPtr->lpszText);
1125 /* remove subclassing */
1126 if (toolPtr->uFlags & TTF_SUBCLASS) {
1127 if (toolPtr->uFlags & TTF_IDISHWND) {
1128 RemoveWindowSubclass((HWND)toolPtr->uId, TOOLTIPS_SubclassProc, 1);
1131 RemoveWindowSubclass(toolPtr->hwnd, TOOLTIPS_SubclassProc, 1);
1135 /* delete tool from tool list */
1136 if (infoPtr->uNumTools == 1) {
1137 Free (infoPtr->tools);
1138 infoPtr->tools = NULL;
1141 TTTOOL_INFO *oldTools = infoPtr->tools;
1143 Alloc (sizeof(TTTOOL_INFO) * (infoPtr->uNumTools - 1));
1146 memcpy (&infoPtr->tools[0], &oldTools[0],
1147 nTool * sizeof(TTTOOL_INFO));
1149 if (nTool < infoPtr->uNumTools - 1)
1150 memcpy (&infoPtr->tools[nTool], &oldTools[nTool + 1],
1151 (infoPtr->uNumTools - nTool - 1) * sizeof(TTTOOL_INFO));
1156 /* update any indices affected by delete */
1158 /* destroying tool that mouse was on on last relayed mouse move */
1159 if (infoPtr->nTool == nTool)
1160 /* -1 means no current tool (0 means first tool) */
1161 infoPtr->nTool = -1;
1162 else if (infoPtr->nTool > nTool)
1165 if (infoPtr->nTrackTool == nTool)
1166 /* -1 means no current tool (0 means first tool) */
1167 infoPtr->nTrackTool = -1;
1168 else if (infoPtr->nTrackTool > nTool)
1169 infoPtr->nTrackTool--;
1171 if (infoPtr->nCurrentTool == nTool)
1172 /* -1 means no current tool (0 means first tool) */
1173 infoPtr->nCurrentTool = -1;
1174 else if (infoPtr->nCurrentTool > nTool)
1175 infoPtr->nCurrentTool--;
1177 infoPtr->uNumTools--;
1183 TOOLTIPS_EnumToolsT (const TOOLTIPS_INFO *infoPtr, UINT uIndex, TTTOOLINFOW *ti,
1186 TTTOOL_INFO *toolPtr;
1188 if (!ti) return FALSE;
1189 if (ti->cbSize < TTTOOLINFOW_V1_SIZE)
1191 if (uIndex >= infoPtr->uNumTools)
1194 TRACE("index=%u\n", uIndex);
1196 toolPtr = &infoPtr->tools[uIndex];
1198 /* copy tool data */
1199 ti->uFlags = toolPtr->uFlags;
1200 ti->hwnd = toolPtr->hwnd;
1201 ti->uId = toolPtr->uId;
1202 ti->rect = toolPtr->rect;
1203 ti->hinst = toolPtr->hinst;
1204 /* ti->lpszText = toolPtr->lpszText; */
1205 ti->lpszText = NULL; /* FIXME */
1207 if (ti->cbSize >= TTTOOLINFOA_V2_SIZE)
1208 ti->lParam = toolPtr->lParam;
1214 TOOLTIPS_GetBubbleSize (const TOOLTIPS_INFO *infoPtr, const TTTOOLINFOW *lpToolInfo)
1219 if (lpToolInfo == NULL)
1221 if (lpToolInfo->cbSize < TTTOOLINFOW_V1_SIZE)
1224 nTool = TOOLTIPS_GetToolFromInfoT (infoPtr, lpToolInfo);
1225 if (nTool == -1) return 0;
1227 TRACE("tool %d\n", nTool);
1229 TOOLTIPS_CalcTipSize (infoPtr, &size);
1230 TRACE("size %d x %d\n", size.cx, size.cy);
1232 return MAKELRESULT(size.cx, size.cy);
1236 TOOLTIPS_GetCurrentToolT (const TOOLTIPS_INFO *infoPtr, TTTOOLINFOW *ti, BOOL isW)
1238 TTTOOL_INFO *toolPtr;
1241 if (ti->cbSize < TTTOOLINFOW_V1_SIZE)
1244 if (infoPtr->nCurrentTool > -1) {
1245 toolPtr = &infoPtr->tools[infoPtr->nCurrentTool];
1247 /* copy tool data */
1248 ti->uFlags = toolPtr->uFlags;
1249 ti->rect = toolPtr->rect;
1250 ti->hinst = toolPtr->hinst;
1251 /* ti->lpszText = toolPtr->lpszText; */
1252 ti->lpszText = NULL; /* FIXME */
1254 if (ti->cbSize >= TTTOOLINFOW_V2_SIZE)
1255 ti->lParam = toolPtr->lParam;
1263 return (infoPtr->nCurrentTool != -1);
1268 TOOLTIPS_GetDelayTime (const TOOLTIPS_INFO *infoPtr, DWORD duration)
1272 return infoPtr->nReshowTime;
1275 return infoPtr->nAutoPopTime;
1278 case TTDT_AUTOMATIC: /* Apparently TTDT_AUTOMATIC returns TTDT_INITIAL */
1279 return infoPtr->nInitialTime;
1282 WARN("Invalid duration flag %x\n", duration);
1291 TOOLTIPS_GetMargin (const TOOLTIPS_INFO *infoPtr, LPRECT lpRect)
1293 lpRect->left = infoPtr->rcMargin.left;
1294 lpRect->right = infoPtr->rcMargin.right;
1295 lpRect->bottom = infoPtr->rcMargin.bottom;
1296 lpRect->top = infoPtr->rcMargin.top;
1302 static inline LRESULT
1303 TOOLTIPS_GetMaxTipWidth (const TOOLTIPS_INFO *infoPtr)
1305 return infoPtr->nMaxTipWidth;
1310 TOOLTIPS_GetTextT (const TOOLTIPS_INFO *infoPtr, TTTOOLINFOW *ti, BOOL isW)
1315 if (ti->cbSize < TTTOOLINFOW_V1_SIZE)
1318 nTool = TOOLTIPS_GetToolFromInfoT (infoPtr, ti);
1319 if (nTool == -1) return 0;
1321 if (infoPtr->tools[nTool].lpszText == NULL)
1325 ti->lpszText[0] = '\0';
1326 TOOLTIPS_GetTipText(infoPtr, nTool, ti->lpszText);
1329 WCHAR buffer[INFOTIPSIZE];
1331 /* NB this API is broken, there is no way for the app to determine
1332 what size buffer it requires nor a way to specify how long the
1333 one it supplies is. We'll assume it's up to INFOTIPSIZE */
1336 TOOLTIPS_GetTipText(infoPtr, nTool, buffer);
1337 WideCharToMultiByte(CP_ACP, 0, buffer, -1, (LPSTR)ti->lpszText,
1338 INFOTIPSIZE, NULL, NULL);
1345 static inline LRESULT
1346 TOOLTIPS_GetTipBkColor (const TOOLTIPS_INFO *infoPtr)
1348 return infoPtr->clrBk;
1352 static inline LRESULT
1353 TOOLTIPS_GetTipTextColor (const TOOLTIPS_INFO *infoPtr)
1355 return infoPtr->clrText;
1359 static inline LRESULT
1360 TOOLTIPS_GetToolCount (const TOOLTIPS_INFO *infoPtr)
1362 return infoPtr->uNumTools;
1367 TOOLTIPS_GetToolInfoT (const TOOLTIPS_INFO *infoPtr, TTTOOLINFOW *ti, BOOL isW)
1369 TTTOOL_INFO *toolPtr;
1372 if (!ti) return FALSE;
1373 if (ti->cbSize < TTTOOLINFOW_V1_SIZE)
1375 if (infoPtr->uNumTools == 0)
1378 nTool = TOOLTIPS_GetToolFromInfoT (infoPtr, ti);
1382 TRACE("tool %d\n", nTool);
1384 toolPtr = &infoPtr->tools[nTool];
1386 /* copy tool data */
1387 ti->uFlags = toolPtr->uFlags;
1388 ti->rect = toolPtr->rect;
1389 ti->hinst = toolPtr->hinst;
1390 /* lpToolInfo->lpszText = toolPtr->lpszText; */
1391 ti->lpszText = NULL; /* FIXME */
1393 if (ti->cbSize >= TTTOOLINFOW_V2_SIZE)
1394 ti->lParam = toolPtr->lParam;
1401 TOOLTIPS_HitTestT (const TOOLTIPS_INFO *infoPtr, LPTTHITTESTINFOW lptthit,
1404 TTTOOL_INFO *toolPtr;
1410 nTool = TOOLTIPS_GetToolFromPoint (infoPtr, lptthit->hwnd, &lptthit->pt);
1414 TRACE("tool %d!\n", nTool);
1416 /* copy tool data */
1417 if (lptthit->ti.cbSize >= TTTOOLINFOW_V1_SIZE) {
1418 toolPtr = &infoPtr->tools[nTool];
1420 lptthit->ti.uFlags = toolPtr->uFlags;
1421 lptthit->ti.hwnd = toolPtr->hwnd;
1422 lptthit->ti.uId = toolPtr->uId;
1423 lptthit->ti.rect = toolPtr->rect;
1424 lptthit->ti.hinst = toolPtr->hinst;
1425 /* lptthit->ti.lpszText = toolPtr->lpszText; */
1426 lptthit->ti.lpszText = NULL; /* FIXME */
1427 if (lptthit->ti.cbSize >= TTTOOLINFOW_V2_SIZE)
1428 lptthit->ti.lParam = toolPtr->lParam;
1436 TOOLTIPS_NewToolRectT (TOOLTIPS_INFO *infoPtr, const TTTOOLINFOW *ti, BOOL isW)
1441 if (ti->cbSize < TTTOOLINFOW_V1_SIZE)
1444 nTool = TOOLTIPS_GetToolFromInfoT (infoPtr, ti);
1446 TRACE("nTool = %d, rect = %s\n", nTool, wine_dbgstr_rect(&ti->rect));
1448 if (nTool == -1) return 0;
1450 infoPtr->tools[nTool].rect = ti->rect;
1456 static inline LRESULT
1457 TOOLTIPS_Pop (TOOLTIPS_INFO *infoPtr)
1459 TOOLTIPS_Hide (infoPtr);
1466 TOOLTIPS_RelayEvent (TOOLTIPS_INFO *infoPtr, LPMSG lpMsg)
1472 ERR("lpMsg == NULL!\n");
1476 switch (lpMsg->message) {
1477 case WM_LBUTTONDOWN:
1479 case WM_MBUTTONDOWN:
1481 case WM_RBUTTONDOWN:
1483 TOOLTIPS_Hide (infoPtr);
1487 pt.x = (short)LOWORD(lpMsg->lParam);
1488 pt.y = (short)HIWORD(lpMsg->lParam);
1489 nOldTool = infoPtr->nTool;
1490 infoPtr->nTool = TOOLTIPS_GetToolFromPoint(infoPtr, lpMsg->hwnd,
1492 TRACE("tool (%p) %d %d %d\n", infoPtr->hwndSelf, nOldTool,
1493 infoPtr->nTool, infoPtr->nCurrentTool);
1494 TRACE("WM_MOUSEMOVE (%p %d %d)\n", infoPtr->hwndSelf, pt.x, pt.y);
1496 if (infoPtr->nTool != nOldTool) {
1497 if(infoPtr->nTool == -1) { /* Moved out of all tools */
1498 TOOLTIPS_Hide(infoPtr);
1499 KillTimer(infoPtr->hwndSelf, ID_TIMERLEAVE);
1500 } else if (nOldTool == -1) { /* Moved from outside */
1501 if(infoPtr->bActive) {
1502 SetTimer(infoPtr->hwndSelf, ID_TIMERSHOW, infoPtr->nInitialTime, 0);
1503 TRACE("timer 1 started!\n");
1505 } else { /* Moved from one to another */
1506 TOOLTIPS_Hide (infoPtr);
1507 KillTimer(infoPtr->hwndSelf, ID_TIMERLEAVE);
1508 if(infoPtr->bActive) {
1509 SetTimer (infoPtr->hwndSelf, ID_TIMERSHOW, infoPtr->nReshowTime, 0);
1510 TRACE("timer 1 started!\n");
1513 } else if(infoPtr->nCurrentTool != -1) { /* restart autopop */
1514 KillTimer(infoPtr->hwndSelf, ID_TIMERPOP);
1515 SetTimer(infoPtr->hwndSelf, ID_TIMERPOP, infoPtr->nAutoPopTime, 0);
1516 TRACE("timer 2 restarted\n");
1517 } else if(infoPtr->nTool != -1 && infoPtr->bActive) {
1518 /* previous show attempt didn't result in tooltip so try again */
1519 SetTimer(infoPtr->hwndSelf, ID_TIMERSHOW, infoPtr->nInitialTime, 0);
1520 TRACE("timer 1 started!\n");
1530 TOOLTIPS_SetDelayTime (TOOLTIPS_INFO *infoPtr, DWORD duration, INT nTime)
1533 case TTDT_AUTOMATIC:
1535 nTime = GetDoubleClickTime();
1536 infoPtr->nReshowTime = nTime / 5;
1537 infoPtr->nAutoPopTime = nTime * 10;
1538 infoPtr->nInitialTime = nTime;
1543 nTime = GetDoubleClickTime() / 5;
1544 infoPtr->nReshowTime = nTime;
1549 nTime = GetDoubleClickTime() * 10;
1550 infoPtr->nAutoPopTime = nTime;
1555 nTime = GetDoubleClickTime();
1556 infoPtr->nInitialTime = nTime;
1560 WARN("Invalid duration flag %x\n", duration);
1569 TOOLTIPS_SetMargin (TOOLTIPS_INFO *infoPtr, const RECT *lpRect)
1571 infoPtr->rcMargin.left = lpRect->left;
1572 infoPtr->rcMargin.right = lpRect->right;
1573 infoPtr->rcMargin.bottom = lpRect->bottom;
1574 infoPtr->rcMargin.top = lpRect->top;
1580 static inline LRESULT
1581 TOOLTIPS_SetMaxTipWidth (TOOLTIPS_INFO *infoPtr, INT MaxWidth)
1583 INT nTemp = infoPtr->nMaxTipWidth;
1585 infoPtr->nMaxTipWidth = MaxWidth;
1591 static inline LRESULT
1592 TOOLTIPS_SetTipBkColor (TOOLTIPS_INFO *infoPtr, COLORREF clrBk)
1594 infoPtr->clrBk = clrBk;
1600 static inline LRESULT
1601 TOOLTIPS_SetTipTextColor (TOOLTIPS_INFO *infoPtr, COLORREF clrText)
1603 infoPtr->clrText = clrText;
1610 TOOLTIPS_SetTitleT (TOOLTIPS_INFO *infoPtr, UINT_PTR uTitleIcon, LPCWSTR pszTitle,
1615 TRACE("hwnd = %p, title = %s, icon = %p\n", infoPtr->hwndSelf, debugstr_w(pszTitle),
1618 Free(infoPtr->pszTitle);
1624 size = (strlenW(pszTitle)+1)*sizeof(WCHAR);
1625 infoPtr->pszTitle = Alloc(size);
1626 if (!infoPtr->pszTitle)
1628 memcpy(infoPtr->pszTitle, pszTitle, size);
1632 size = sizeof(WCHAR)*MultiByteToWideChar(CP_ACP, 0, (LPSTR)pszTitle, -1, NULL, 0);
1633 infoPtr->pszTitle = Alloc(size);
1634 if (!infoPtr->pszTitle)
1636 MultiByteToWideChar(CP_ACP, 0, (LPSTR)pszTitle, -1, infoPtr->pszTitle, size/sizeof(WCHAR));
1640 infoPtr->pszTitle = NULL;
1642 if (uTitleIcon <= TTI_ERROR)
1643 infoPtr->hTitleIcon = hTooltipIcons[uTitleIcon];
1645 infoPtr->hTitleIcon = CopyIcon((HICON)uTitleIcon);
1647 TRACE("icon = %p\n", infoPtr->hTitleIcon);
1654 TOOLTIPS_SetToolInfoT (TOOLTIPS_INFO *infoPtr, const TTTOOLINFOW *ti, BOOL isW)
1656 TTTOOL_INFO *toolPtr;
1660 if (ti->cbSize < TTTOOLINFOW_V1_SIZE)
1663 nTool = TOOLTIPS_GetToolFromInfoT (infoPtr, ti);
1664 if (nTool == -1) return 0;
1666 TRACE("tool %d\n", nTool);
1668 toolPtr = &infoPtr->tools[nTool];
1670 /* copy tool data */
1671 toolPtr->uFlags = ti->uFlags;
1672 toolPtr->hwnd = ti->hwnd;
1673 toolPtr->uId = ti->uId;
1674 toolPtr->rect = ti->rect;
1675 toolPtr->hinst = ti->hinst;
1677 if (IS_INTRESOURCE(ti->lpszText)) {
1678 TRACE("set string id %x!\n", LOWORD(ti->lpszText));
1679 toolPtr->lpszText = ti->lpszText;
1682 if (TOOLTIPS_IsCallbackString(ti->lpszText, isW))
1683 toolPtr->lpszText = LPSTR_TEXTCALLBACKW;
1685 if ( (toolPtr->lpszText) &&
1686 !IS_INTRESOURCE(toolPtr->lpszText) ) {
1687 if( toolPtr->lpszText != LPSTR_TEXTCALLBACKW)
1688 Free (toolPtr->lpszText);
1689 toolPtr->lpszText = NULL;
1693 INT len = lstrlenW (ti->lpszText);
1694 toolPtr->lpszText = Alloc ((len+1)*sizeof(WCHAR));
1695 strcpyW (toolPtr->lpszText, ti->lpszText);
1698 INT len = MultiByteToWideChar(CP_ACP, 0, (LPSTR)ti->lpszText,
1700 toolPtr->lpszText = Alloc (len * sizeof(WCHAR));
1701 MultiByteToWideChar(CP_ACP, 0, (LPSTR)ti->lpszText, -1,
1702 toolPtr->lpszText, len);
1708 if (ti->cbSize >= TTTOOLINFOW_V2_SIZE)
1709 toolPtr->lParam = ti->lParam;
1711 if (infoPtr->nCurrentTool == nTool)
1713 TOOLTIPS_GetTipText (infoPtr, infoPtr->nCurrentTool, infoPtr->szTipText);
1715 if (infoPtr->szTipText[0] == 0)
1716 TOOLTIPS_Hide(infoPtr);
1718 TOOLTIPS_Show (infoPtr, FALSE);
1726 TOOLTIPS_TrackActivate (TOOLTIPS_INFO *infoPtr, BOOL track_activate, const TTTOOLINFOA *ti)
1728 if (track_activate) {
1731 if (ti->cbSize < TTTOOLINFOA_V1_SIZE)
1735 infoPtr->nTrackTool = TOOLTIPS_GetToolFromInfoT (infoPtr, (TTTOOLINFOW*)ti);
1736 if (infoPtr->nTrackTool != -1) {
1737 TRACE("activated!\n");
1738 infoPtr->bTrackActive = TRUE;
1739 TOOLTIPS_TrackShow (infoPtr);
1744 TOOLTIPS_TrackHide (infoPtr);
1746 infoPtr->bTrackActive = FALSE;
1747 infoPtr->nTrackTool = -1;
1749 TRACE("deactivated!\n");
1757 TOOLTIPS_TrackPosition (TOOLTIPS_INFO *infoPtr, LPARAM coord)
1759 infoPtr->xTrackPos = (INT)LOWORD(coord);
1760 infoPtr->yTrackPos = (INT)HIWORD(coord);
1762 if (infoPtr->bTrackActive) {
1764 infoPtr->xTrackPos, infoPtr->yTrackPos);
1766 TOOLTIPS_TrackShow (infoPtr);
1774 TOOLTIPS_Update (TOOLTIPS_INFO *infoPtr)
1776 if (infoPtr->nCurrentTool != -1)
1777 UpdateWindow (infoPtr->hwndSelf);
1784 TOOLTIPS_UpdateTipTextT (TOOLTIPS_INFO *infoPtr, const TTTOOLINFOW *ti, BOOL isW)
1786 TTTOOL_INFO *toolPtr;
1790 if (ti->cbSize < TTTOOLINFOW_V1_SIZE)
1793 nTool = TOOLTIPS_GetToolFromInfoT (infoPtr, ti);
1797 TRACE("tool %d\n", nTool);
1799 toolPtr = &infoPtr->tools[nTool];
1801 /* copy tool text */
1802 toolPtr->hinst = ti->hinst;
1804 if (IS_INTRESOURCE(ti->lpszText)){
1805 toolPtr->lpszText = ti->lpszText;
1807 else if (ti->lpszText) {
1808 if (TOOLTIPS_IsCallbackString(ti->lpszText, isW))
1809 toolPtr->lpszText = LPSTR_TEXTCALLBACKW;
1811 if ( (toolPtr->lpszText) &&
1812 !IS_INTRESOURCE(toolPtr->lpszText) ) {
1813 if( toolPtr->lpszText != LPSTR_TEXTCALLBACKW)
1814 Free (toolPtr->lpszText);
1815 toolPtr->lpszText = NULL;
1819 INT len = lstrlenW (ti->lpszText);
1820 toolPtr->lpszText = Alloc ((len+1)*sizeof(WCHAR));
1821 strcpyW (toolPtr->lpszText, ti->lpszText);
1824 INT len = MultiByteToWideChar(CP_ACP, 0, (LPSTR)ti->lpszText,
1826 toolPtr->lpszText = Alloc (len * sizeof(WCHAR));
1827 MultiByteToWideChar(CP_ACP, 0, (LPSTR)ti->lpszText, -1,
1828 toolPtr->lpszText, len);
1834 if(infoPtr->nCurrentTool == -1) return 0;
1836 if (infoPtr->bActive)
1837 TOOLTIPS_Show (infoPtr, FALSE);
1838 else if (infoPtr->bTrackActive)
1839 TOOLTIPS_Show (infoPtr, TRUE);
1846 TOOLTIPS_WindowFromPoint (HWND hwnd, WPARAM wParam, LPARAM lParam)
1848 return (LRESULT)WindowFromPoint (*((LPPOINT)lParam));
1854 TOOLTIPS_Create (HWND hwnd, const CREATESTRUCTW *lpcs)
1856 TOOLTIPS_INFO *infoPtr;
1858 /* allocate memory for info structure */
1859 infoPtr = Alloc (sizeof(TOOLTIPS_INFO));
1860 SetWindowLongPtrW (hwnd, 0, (DWORD_PTR)infoPtr);
1862 /* initialize info structure */
1863 infoPtr->bActive = TRUE;
1864 infoPtr->bTrackActive = FALSE;
1866 infoPtr->nMaxTipWidth = -1;
1867 infoPtr->nTool = -1;
1868 infoPtr->nCurrentTool = -1;
1869 infoPtr->nTrackTool = -1;
1870 infoPtr->hwndSelf = hwnd;
1872 /* initialize colours and fonts */
1873 TOOLTIPS_InitSystemSettings(infoPtr);
1875 TOOLTIPS_SetDelayTime(infoPtr, TTDT_AUTOMATIC, 0);
1877 SetWindowPos (hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOZORDER | SWP_HIDEWINDOW | SWP_NOACTIVATE);
1884 TOOLTIPS_Destroy (TOOLTIPS_INFO *infoPtr)
1886 TTTOOL_INFO *toolPtr;
1890 if (infoPtr->tools) {
1891 for (i = 0; i < infoPtr->uNumTools; i++) {
1892 toolPtr = &infoPtr->tools[i];
1893 if (toolPtr->lpszText) {
1894 if ( (toolPtr->lpszText != LPSTR_TEXTCALLBACKW) &&
1895 !IS_INTRESOURCE(toolPtr->lpszText) )
1897 Free (toolPtr->lpszText);
1898 toolPtr->lpszText = NULL;
1902 /* remove subclassing */
1903 if (toolPtr->uFlags & TTF_SUBCLASS) {
1904 if (toolPtr->uFlags & TTF_IDISHWND) {
1905 RemoveWindowSubclass((HWND)toolPtr->uId, TOOLTIPS_SubclassProc, 1);
1908 RemoveWindowSubclass(toolPtr->hwnd, TOOLTIPS_SubclassProc, 1);
1912 Free (infoPtr->tools);
1915 /* free title string */
1916 Free (infoPtr->pszTitle);
1917 /* free title icon if not a standard one */
1918 if (TOOLTIPS_GetTitleIconIndex(infoPtr->hTitleIcon) > TTI_ERROR)
1919 DeleteObject(infoPtr->hTitleIcon);
1922 DeleteObject (infoPtr->hFont);
1923 DeleteObject (infoPtr->hTitleFont);
1925 /* free tool tips info data */
1926 SetWindowLongPtrW(infoPtr->hwndSelf, 0, 0);
1933 static inline LRESULT
1934 TOOLTIPS_GetFont (const TOOLTIPS_INFO *infoPtr)
1936 return (LRESULT)infoPtr->hFont;
1941 TOOLTIPS_MouseMessage (TOOLTIPS_INFO *infoPtr)
1943 TOOLTIPS_Hide (infoPtr);
1950 TOOLTIPS_NCCreate (HWND hwnd, const CREATESTRUCTW *lpcs)
1952 DWORD dwStyle = GetWindowLongW (hwnd, GWL_STYLE);
1953 DWORD dwExStyle = GetWindowLongW (hwnd, GWL_EXSTYLE);
1955 dwStyle &= ~(WS_CHILD | /*WS_MAXIMIZE |*/ WS_BORDER | WS_DLGFRAME);
1956 dwStyle |= (WS_POPUP | WS_BORDER | WS_CLIPSIBLINGS);
1958 /* WS_BORDER only draws a border round the window rect, not the
1959 * window region, therefore it is useless to us in balloon mode */
1960 if (dwStyle & TTS_BALLOON) dwStyle &= ~WS_BORDER;
1962 SetWindowLongW (hwnd, GWL_STYLE, dwStyle);
1964 dwExStyle |= WS_EX_TOOLWINDOW;
1965 SetWindowLongW (hwnd, GWL_EXSTYLE, dwExStyle);
1972 TOOLTIPS_NCHitTest (const TOOLTIPS_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
1974 INT nTool = (infoPtr->bTrackActive) ? infoPtr->nTrackTool : infoPtr->nTool;
1976 TRACE(" nTool=%d\n", nTool);
1978 if ((nTool > -1) && (nTool < infoPtr->uNumTools)) {
1979 if (infoPtr->tools[nTool].uFlags & TTF_TRANSPARENT) {
1980 TRACE("-- in transparent mode!\n");
1981 return HTTRANSPARENT;
1985 return DefWindowProcW (infoPtr->hwndSelf, WM_NCHITTEST, wParam, lParam);
1990 TOOLTIPS_NotifyFormat (TOOLTIPS_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
1992 FIXME ("hwnd=%p wParam=%lx lParam=%lx\n", infoPtr->hwndSelf, wParam, lParam);
1999 TOOLTIPS_Paint (const TOOLTIPS_INFO *infoPtr, HDC hDC)
2004 hdc = (hDC == NULL) ? BeginPaint (infoPtr->hwndSelf, &ps) : hDC;
2005 TOOLTIPS_Refresh (infoPtr, hdc);
2007 EndPaint (infoPtr->hwndSelf, &ps);
2013 TOOLTIPS_SetFont (TOOLTIPS_INFO *infoPtr, HFONT hFont, BOOL redraw)
2017 if(!GetObjectW(hFont, sizeof(lf), &lf))
2020 DeleteObject (infoPtr->hFont);
2021 infoPtr->hFont = CreateFontIndirectW(&lf);
2023 DeleteObject (infoPtr->hTitleFont);
2024 lf.lfWeight = FW_BOLD;
2025 infoPtr->hTitleFont = CreateFontIndirectW(&lf);
2027 if (redraw & (infoPtr->nCurrentTool != -1)) {
2028 FIXME("full redraw needed!\n");
2034 /******************************************************************
2035 * TOOLTIPS_GetTextLength
2037 * This function is called when the tooltip receive a
2038 * WM_GETTEXTLENGTH message.
2040 * returns the length, in characters, of the tip text
2042 static inline LRESULT
2043 TOOLTIPS_GetTextLength(const TOOLTIPS_INFO *infoPtr)
2045 return strlenW(infoPtr->szTipText);
2048 /******************************************************************
2049 * TOOLTIPS_OnWMGetText
2051 * This function is called when the tooltip receive a
2052 * WM_GETTEXT message.
2053 * wParam : specifies the maximum number of characters to be copied
2054 * lParam : is the pointer to the buffer that will receive
2057 * returns the number of characters copied
2060 TOOLTIPS_OnWMGetText (const TOOLTIPS_INFO *infoPtr, WPARAM size, LPWSTR pszText)
2064 if(!infoPtr->szTipText || !size)
2067 res = min(strlenW(infoPtr->szTipText)+1, size);
2068 memcpy(pszText, infoPtr->szTipText, res*sizeof(WCHAR));
2069 pszText[res-1] = '\0';
2074 TOOLTIPS_Timer (TOOLTIPS_INFO *infoPtr, INT iTimer)
2078 TRACE("timer %d (%p) expired!\n", iTimer, infoPtr->hwndSelf);
2082 KillTimer (infoPtr->hwndSelf, ID_TIMERSHOW);
2083 nOldTool = infoPtr->nTool;
2084 if ((infoPtr->nTool = TOOLTIPS_CheckTool (infoPtr, TRUE)) == nOldTool)
2085 TOOLTIPS_Show (infoPtr, FALSE);
2089 TOOLTIPS_Hide (infoPtr);
2093 nOldTool = infoPtr->nTool;
2094 infoPtr->nTool = TOOLTIPS_CheckTool (infoPtr, FALSE);
2095 TRACE("tool (%p) %d %d %d\n", infoPtr->hwndSelf, nOldTool,
2096 infoPtr->nTool, infoPtr->nCurrentTool);
2097 if (infoPtr->nTool != nOldTool) {
2098 if(infoPtr->nTool == -1) { /* Moved out of all tools */
2099 TOOLTIPS_Hide(infoPtr);
2100 KillTimer(infoPtr->hwndSelf, ID_TIMERLEAVE);
2101 } else if (nOldTool == -1) { /* Moved from outside */
2102 ERR("How did this happen?\n");
2103 } else { /* Moved from one to another */
2104 TOOLTIPS_Hide (infoPtr);
2105 KillTimer(infoPtr->hwndSelf, ID_TIMERLEAVE);
2106 if(infoPtr->bActive) {
2107 SetTimer (infoPtr->hwndSelf, ID_TIMERSHOW, infoPtr->nReshowTime, 0);
2108 TRACE("timer 1 started!\n");
2115 ERR("Unknown timer id %d\n", iTimer);
2123 TOOLTIPS_WinIniChange (TOOLTIPS_INFO *infoPtr)
2125 TOOLTIPS_InitSystemSettings (infoPtr);
2131 static LRESULT CALLBACK
2132 TOOLTIPS_SubclassProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uID, DWORD_PTR dwRef)
2134 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr ((HWND)dwRef);
2139 case WM_LBUTTONDOWN:
2141 case WM_MBUTTONDOWN:
2143 case WM_RBUTTONDOWN:
2147 msg.wParam = wParam;
2148 msg.lParam = lParam;
2149 TOOLTIPS_RelayEvent(infoPtr, &msg);
2155 return DefSubclassProc(hwnd, uMsg, wParam, lParam);
2159 static LRESULT CALLBACK
2160 TOOLTIPS_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2162 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
2164 TRACE("hwnd=%p msg=%x wparam=%lx lParam=%lx\n", hwnd, uMsg, wParam, lParam);
2165 if (!infoPtr && (uMsg != WM_CREATE) && (uMsg != WM_NCCREATE))
2166 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
2170 return TOOLTIPS_Activate (infoPtr, (BOOL)wParam);
2174 return TOOLTIPS_AddToolT (infoPtr, (LPTTTOOLINFOW)lParam, uMsg == TTM_ADDTOOLW);
2178 return TOOLTIPS_DelToolT (infoPtr, (LPTOOLINFOW)lParam,
2179 uMsg == TTM_DELTOOLW);
2180 case TTM_ENUMTOOLSA:
2181 case TTM_ENUMTOOLSW:
2182 return TOOLTIPS_EnumToolsT (infoPtr, (UINT)wParam, (LPTTTOOLINFOW)lParam,
2183 uMsg == TTM_ENUMTOOLSW);
2184 case TTM_GETBUBBLESIZE:
2185 return TOOLTIPS_GetBubbleSize (infoPtr, (LPTTTOOLINFOW)lParam);
2187 case TTM_GETCURRENTTOOLA:
2188 case TTM_GETCURRENTTOOLW:
2189 return TOOLTIPS_GetCurrentToolT (infoPtr, (LPTTTOOLINFOW)lParam,
2190 uMsg == TTM_GETCURRENTTOOLW);
2192 case TTM_GETDELAYTIME:
2193 return TOOLTIPS_GetDelayTime (infoPtr, (DWORD)wParam);
2196 return TOOLTIPS_GetMargin (infoPtr, (LPRECT)lParam);
2198 case TTM_GETMAXTIPWIDTH:
2199 return TOOLTIPS_GetMaxTipWidth (infoPtr);
2203 return TOOLTIPS_GetTextT (infoPtr, (LPTTTOOLINFOW)lParam,
2204 uMsg == TTM_GETTEXTW);
2206 case TTM_GETTIPBKCOLOR:
2207 return TOOLTIPS_GetTipBkColor (infoPtr);
2209 case TTM_GETTIPTEXTCOLOR:
2210 return TOOLTIPS_GetTipTextColor (infoPtr);
2212 case TTM_GETTOOLCOUNT:
2213 return TOOLTIPS_GetToolCount (infoPtr);
2215 case TTM_GETTOOLINFOA:
2216 case TTM_GETTOOLINFOW:
2217 return TOOLTIPS_GetToolInfoT (infoPtr, (LPTTTOOLINFOW)lParam,
2218 uMsg == TTM_GETTOOLINFOW);
2222 return TOOLTIPS_HitTestT (infoPtr, (LPTTHITTESTINFOW)lParam,
2223 uMsg == TTM_HITTESTW);
2224 case TTM_NEWTOOLRECTA:
2225 case TTM_NEWTOOLRECTW:
2226 return TOOLTIPS_NewToolRectT (infoPtr, (LPTTTOOLINFOW)lParam,
2227 uMsg == TTM_NEWTOOLRECTW);
2229 return TOOLTIPS_Pop (infoPtr);
2231 case TTM_RELAYEVENT:
2232 return TOOLTIPS_RelayEvent (infoPtr, (LPMSG)lParam);
2234 case TTM_SETDELAYTIME:
2235 return TOOLTIPS_SetDelayTime (infoPtr, (DWORD)wParam, (INT)LOWORD(lParam));
2238 return TOOLTIPS_SetMargin (infoPtr, (LPRECT)lParam);
2240 case TTM_SETMAXTIPWIDTH:
2241 return TOOLTIPS_SetMaxTipWidth (infoPtr, (INT)lParam);
2243 case TTM_SETTIPBKCOLOR:
2244 return TOOLTIPS_SetTipBkColor (infoPtr, (COLORREF)wParam);
2246 case TTM_SETTIPTEXTCOLOR:
2247 return TOOLTIPS_SetTipTextColor (infoPtr, (COLORREF)wParam);
2251 return TOOLTIPS_SetTitleT (infoPtr, (UINT_PTR)wParam, (LPCWSTR)lParam,
2252 uMsg == TTM_SETTITLEW);
2254 case TTM_SETTOOLINFOA:
2255 case TTM_SETTOOLINFOW:
2256 return TOOLTIPS_SetToolInfoT (infoPtr, (LPTTTOOLINFOW)lParam,
2257 uMsg == TTM_SETTOOLINFOW);
2259 case TTM_TRACKACTIVATE:
2260 return TOOLTIPS_TrackActivate (infoPtr, (BOOL)wParam, (LPTTTOOLINFOA)lParam);
2262 case TTM_TRACKPOSITION:
2263 return TOOLTIPS_TrackPosition (infoPtr, lParam);
2266 return TOOLTIPS_Update (infoPtr);
2268 case TTM_UPDATETIPTEXTA:
2269 case TTM_UPDATETIPTEXTW:
2270 return TOOLTIPS_UpdateTipTextT (infoPtr, (LPTTTOOLINFOW)lParam,
2271 uMsg == TTM_UPDATETIPTEXTW);
2273 case TTM_WINDOWFROMPOINT:
2274 return TOOLTIPS_WindowFromPoint (hwnd, wParam, lParam);
2278 return TOOLTIPS_Create (hwnd, (LPCREATESTRUCTW)lParam);
2281 return TOOLTIPS_Destroy (infoPtr);
2284 /* we draw the background in WM_PAINT */
2288 return TOOLTIPS_GetFont (infoPtr);
2291 return TOOLTIPS_OnWMGetText (infoPtr, wParam, (LPWSTR)lParam);
2293 case WM_GETTEXTLENGTH:
2294 return TOOLTIPS_GetTextLength (infoPtr);
2296 case WM_LBUTTONDOWN:
2298 case WM_MBUTTONDOWN:
2300 case WM_RBUTTONDOWN:
2303 return TOOLTIPS_MouseMessage (infoPtr);
2306 return TOOLTIPS_NCCreate (hwnd, (LPCREATESTRUCTW)lParam);
2309 return TOOLTIPS_NCHitTest (infoPtr, wParam, lParam);
2311 case WM_NOTIFYFORMAT:
2312 return TOOLTIPS_NotifyFormat (infoPtr, wParam, lParam);
2314 case WM_PRINTCLIENT:
2316 return TOOLTIPS_Paint (infoPtr, (HDC)wParam);
2319 return TOOLTIPS_SetFont (infoPtr, (HFONT)wParam, LOWORD(lParam));
2321 case WM_SYSCOLORCHANGE:
2322 COMCTL32_RefreshSysColors();
2326 return TOOLTIPS_Timer (infoPtr, (INT)wParam);
2328 case WM_WININICHANGE:
2329 return TOOLTIPS_WinIniChange (infoPtr);
2332 if ((uMsg >= WM_USER) && (uMsg < WM_APP) && !COMCTL32_IsReflectedMessage(uMsg))
2333 ERR("unknown msg %04x wp=%08lx lp=%08lx\n",
2334 uMsg, wParam, lParam);
2335 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
2341 TOOLTIPS_Register (void)
2345 ZeroMemory (&wndClass, sizeof(WNDCLASSW));
2346 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS | CS_SAVEBITS;
2347 wndClass.lpfnWndProc = TOOLTIPS_WindowProc;
2348 wndClass.cbClsExtra = 0;
2349 wndClass.cbWndExtra = sizeof(TOOLTIPS_INFO *);
2350 wndClass.hCursor = LoadCursorW (0, (LPWSTR)IDC_ARROW);
2351 wndClass.hbrBackground = 0;
2352 wndClass.lpszClassName = TOOLTIPS_CLASSW;
2354 RegisterClassW (&wndClass);
2356 hTooltipIcons[TTI_NONE] = NULL;
2357 hTooltipIcons[TTI_INFO] = LoadImageW(COMCTL32_hModule,
2358 (LPCWSTR)MAKEINTRESOURCE(IDI_TT_INFO_SM), IMAGE_ICON, 0, 0, 0);
2359 hTooltipIcons[TTI_WARNING] = LoadImageW(COMCTL32_hModule,
2360 (LPCWSTR)MAKEINTRESOURCE(IDI_TT_WARN_SM), IMAGE_ICON, 0, 0, 0);
2361 hTooltipIcons[TTI_ERROR] = LoadImageW(COMCTL32_hModule,
2362 (LPCWSTR)MAKEINTRESOURCE(IDI_TT_ERROR_SM), IMAGE_ICON, 0, 0, 0);
2367 TOOLTIPS_Unregister (void)
2370 for (i = TTI_INFO; i <= TTI_ERROR; i++)
2371 DestroyIcon(hTooltipIcons[i]);
2372 UnregisterClassW (TOOLTIPS_CLASSW, NULL);