4 * Copyright 1998, 1999 Eric Kohl
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 * - Custom draw support.
26 * - Run tests using Waite Group Windows95 API Bible Volume 2.
27 * The second cdrom (chapter 3) contains executables activate.exe,
28 * curtool.exe, deltool.exe, enumtools.exe, getinfo.exe, getiptxt.exe,
29 * hittest.exe, needtext.exe, newrect.exe, updtext.exe and winfrpt.exe.
33 * One important point to remember is that tools don't necessarily get
34 * a WM_MOUSEMOVE once the cursor leaves the tool, an example is when
35 * a tool sets TTF_IDISHWND (i.e. an entire window is a tool) because
36 * here WM_MOUSEMOVEs only get sent when the cursor is inside the
37 * client area. Therefore the only reliable way to know that the
38 * cursor has left a tool is to keep a timer running and check the
39 * position every time it expires. This is the role of timer
43 * On entering a tool (detected in a relayed WM_MOUSEMOVE) we start
44 * ID_TIMERSHOW, if this times out and we're still in the tool we show
45 * the tip. On showing a tip we start both ID_TIMERPOP and
46 * ID_TIMERLEAVE. On hiding a tooltip we kill ID_TIMERPOP.
47 * ID_TIMERPOP is restarted on every relayed WM_MOUSEMOVE. If
48 * ID_TIMERPOP expires the tool is hidden and ID_TIMERPOP is killed.
49 * ID_TIMERLEAVE remains running - this is important as we need to
50 * determine when the cursor leaves the tool.
52 * When ID_TIMERLEAVE expires or on a relayed WM_MOUSEMOVE if we're
53 * still in the tool do nothing (apart from restart ID_TIMERPOP if
54 * this is a WM_MOUSEMOVE) (ID_TIMERLEAVE remains running). If we've
55 * left the tool and entered another one then hide the tip and start
56 * ID_TIMERSHOW with time ReshowTime and kill ID_TIMERLEAVE. If we're
57 * outside all tools hide the tip and kill ID_TIMERLEAVE. On Relayed
58 * mouse button messages hide the tip but leave ID_TIMERLEAVE running,
59 * this again will let us keep track of when the cursor leaves the
63 * infoPtr->nTool is the tool the mouse was on on the last relayed MM
64 * or timer expiry or -1 if the mouse was not on a tool.
66 * infoPtr->nCurrentTool is the tool for which the tip is currently
67 * displaying text for or -1 if the tip is not shown. Actually this
68 * will only ever be infoPtr-nTool or -1, so it could be changed to a
80 #include "wine/unicode.h"
86 #include "wine/debug.h"
88 WINE_DEFAULT_DEBUG_CHANNEL(tooltips);
105 WCHAR szTipText[INFOTIPSIZE];
115 INT nTool; /* tool that mouse was on on last relayed mouse move */
127 #define ID_TIMERSHOW 1 /* show delay timer */
128 #define ID_TIMERPOP 2 /* auto pop timer */
129 #define ID_TIMERLEAVE 3 /* tool leave timer */
132 #define TOOLTIPS_GetInfoPtr(hWindow) ((TOOLTIPS_INFO *)GetWindowLongA (hWindow, 0))
134 /* offsets from window edge to start of text */
135 #define NORMAL_TEXT_MARGIN 2
136 #define BALLOON_TEXT_MARGIN (NORMAL_TEXT_MARGIN+8)
137 /* value used for CreateRoundRectRgn that specifies how much
138 * each corner is curved */
139 #define BALLOON_ROUNDEDNESS 20
140 #define BALLOON_STEMHEIGHT 13
141 #define BALLOON_STEMWIDTH 10
142 #define BALLOON_STEMINDENT 20
145 TOOLTIPS_SubclassProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uId, DWORD_PTR dwRef);
149 TOOLTIPS_Refresh (HWND hwnd, HDC hdc)
151 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr(hwnd);
156 UINT uFlags = DT_EXTERNALLEADING;
158 DWORD dwStyle = GetWindowLongW(hwnd, GWL_STYLE);
160 if (infoPtr->nMaxTipWidth > -1)
161 uFlags |= DT_WORDBREAK;
162 if (GetWindowLongA (hwnd, GWL_STYLE) & TTS_NOPREFIX)
163 uFlags |= DT_NOPREFIX;
164 GetClientRect (hwnd, &rc);
166 hBrush = CreateSolidBrush(infoPtr->clrBk);
168 if (dwStyle & TTS_BALLOON)
170 /* create a region to store result into */
171 hRgn = CreateRectRgn(0, 0, 0, 0);
173 GetWindowRgn(hwnd, hRgn);
175 /* fill the background */
176 FillRgn(hdc, hRgn, hBrush);
177 DeleteObject(hBrush);
180 /* calculate text rectangle */
181 rc.left += (BALLOON_TEXT_MARGIN + infoPtr->rcMargin.left);
182 rc.top += (BALLOON_TEXT_MARGIN + infoPtr->rcMargin.top);
183 rc.right -= (BALLOON_TEXT_MARGIN + infoPtr->rcMargin.right);
184 rc.bottom -= (BALLOON_TEXT_MARGIN + infoPtr->rcMargin.bottom);
185 if(infoPtr->bToolBelow) rc.top += BALLOON_STEMHEIGHT;
189 /* fill the background */
190 FillRect(hdc, &rc, hBrush);
191 DeleteObject(hBrush);
194 /* calculate text rectangle */
195 rc.left += (NORMAL_TEXT_MARGIN + infoPtr->rcMargin.left);
196 rc.top += (NORMAL_TEXT_MARGIN + infoPtr->rcMargin.top);
197 rc.right -= (NORMAL_TEXT_MARGIN + infoPtr->rcMargin.right);
198 rc.bottom -= (NORMAL_TEXT_MARGIN + infoPtr->rcMargin.bottom);
201 /* already drawn the background; don't need to draw it again
202 * when drawing text */
203 oldBkMode = SetBkMode (hdc, TRANSPARENT);
204 SetTextColor (hdc, infoPtr->clrText);
205 hOldFont = SelectObject (hdc, infoPtr->hFont);
207 DrawTextW (hdc, infoPtr->szTipText, -1, &rc, uFlags);
208 /* be polite and reset the things we changed in the dc */
209 SelectObject (hdc, hOldFont);
210 SetBkMode (hdc, oldBkMode);
212 if (dwStyle & TTS_BALLOON)
214 /* frame region because default window proc doesn't do it */
215 INT width = GetSystemMetrics(SM_CXDLGFRAME) - GetSystemMetrics(SM_CXEDGE);
216 INT height = GetSystemMetrics(SM_CYDLGFRAME) - GetSystemMetrics(SM_CYEDGE);
218 hBrush = GetSysColorBrush(COLOR_WINDOWFRAME);
219 FrameRgn(hdc, hRgn, hBrush, width, height);
226 static void TOOLTIPS_GetDispInfoA(HWND hwnd, TOOLTIPS_INFO *infoPtr, TTTOOL_INFO *toolPtr)
228 NMTTDISPINFOA ttnmdi;
230 /* fill NMHDR struct */
231 ZeroMemory (&ttnmdi, sizeof(NMTTDISPINFOA));
232 ttnmdi.hdr.hwndFrom = hwnd;
233 ttnmdi.hdr.idFrom = toolPtr->uId;
234 ttnmdi.hdr.code = TTN_GETDISPINFOA;
235 ttnmdi.lpszText = (LPSTR)&ttnmdi.szText;
236 ttnmdi.uFlags = toolPtr->uFlags;
237 ttnmdi.lParam = toolPtr->lParam;
239 TRACE("hdr.idFrom = %x\n", ttnmdi.hdr.idFrom);
240 SendMessageA(toolPtr->hwnd, WM_NOTIFY,
241 (WPARAM)toolPtr->uId, (LPARAM)&ttnmdi);
243 if (HIWORD((UINT)ttnmdi.lpszText) == 0) {
244 LoadStringW(ttnmdi.hinst, (UINT)ttnmdi.lpszText,
245 infoPtr->szTipText, INFOTIPSIZE);
246 if (ttnmdi.uFlags & TTF_DI_SETITEM) {
247 toolPtr->hinst = ttnmdi.hinst;
248 toolPtr->lpszText = (LPWSTR)ttnmdi.lpszText;
251 else if (ttnmdi.lpszText == 0) {
252 /* no text available */
253 infoPtr->szTipText[0] = '\0';
255 else if (ttnmdi.lpszText != LPSTR_TEXTCALLBACKA) {
256 INT max_len = (ttnmdi.lpszText == &ttnmdi.szText[0]) ?
257 sizeof(ttnmdi.szText)/sizeof(ttnmdi.szText[0]) : -1;
258 MultiByteToWideChar(CP_ACP, 0, ttnmdi.lpszText, max_len,
259 infoPtr->szTipText, INFOTIPSIZE);
260 if (ttnmdi.uFlags & TTF_DI_SETITEM) {
261 INT len = MultiByteToWideChar(CP_ACP, 0, ttnmdi.lpszText,
264 toolPtr->lpszText = Alloc (len * sizeof(WCHAR));
265 MultiByteToWideChar(CP_ACP, 0, ttnmdi.lpszText, -1,
266 toolPtr->lpszText, len);
270 ERR("recursive text callback!\n");
271 infoPtr->szTipText[0] = '\0';
275 static void TOOLTIPS_GetDispInfoW(HWND hwnd, TOOLTIPS_INFO *infoPtr, TTTOOL_INFO *toolPtr)
277 NMTTDISPINFOW ttnmdi;
279 /* fill NMHDR struct */
280 ZeroMemory (&ttnmdi, sizeof(NMTTDISPINFOW));
281 ttnmdi.hdr.hwndFrom = hwnd;
282 ttnmdi.hdr.idFrom = toolPtr->uId;
283 ttnmdi.hdr.code = TTN_GETDISPINFOW;
284 ttnmdi.lpszText = (LPWSTR)&ttnmdi.szText;
285 ttnmdi.uFlags = toolPtr->uFlags;
286 ttnmdi.lParam = toolPtr->lParam;
288 TRACE("hdr.idFrom = %x\n", ttnmdi.hdr.idFrom);
289 SendMessageW(toolPtr->hwnd, WM_NOTIFY,
290 (WPARAM)toolPtr->uId, (LPARAM)&ttnmdi);
292 if (HIWORD((UINT)ttnmdi.lpszText) == 0) {
293 LoadStringW(ttnmdi.hinst, (UINT)ttnmdi.lpszText,
294 infoPtr->szTipText, INFOTIPSIZE);
295 if (ttnmdi.uFlags & TTF_DI_SETITEM) {
296 toolPtr->hinst = ttnmdi.hinst;
297 toolPtr->lpszText = ttnmdi.lpszText;
300 else if (ttnmdi.lpszText == 0) {
301 /* no text available */
302 infoPtr->szTipText[0] = '\0';
304 else if (ttnmdi.lpszText != LPSTR_TEXTCALLBACKW) {
305 INT max_len = (ttnmdi.lpszText == &ttnmdi.szText[0]) ?
306 sizeof(ttnmdi.szText)/sizeof(ttnmdi.szText[0]) : INFOTIPSIZE-1;
307 strncpyW(infoPtr->szTipText, ttnmdi.lpszText, max_len);
308 if (ttnmdi.uFlags & TTF_DI_SETITEM) {
309 INT len = max(strlenW(ttnmdi.lpszText), max_len);
311 toolPtr->lpszText = Alloc ((len+1) * sizeof(WCHAR));
312 memcpy(toolPtr->lpszText, ttnmdi.lpszText, (len+1) * sizeof(WCHAR));
316 ERR("recursive text callback!\n");
317 infoPtr->szTipText[0] = '\0';
322 TOOLTIPS_GetTipText (HWND hwnd, TOOLTIPS_INFO *infoPtr, INT nTool)
324 TTTOOL_INFO *toolPtr = &infoPtr->tools[nTool];
326 if (HIWORD((UINT)toolPtr->lpszText) == 0) {
327 /* load a resource */
328 TRACE("load res string %p %x\n",
329 toolPtr->hinst, (int)toolPtr->lpszText);
330 LoadStringW (toolPtr->hinst, (UINT)toolPtr->lpszText,
331 infoPtr->szTipText, INFOTIPSIZE);
333 else if (toolPtr->lpszText) {
334 if (toolPtr->lpszText == LPSTR_TEXTCALLBACKW) {
335 if (toolPtr->bNotifyUnicode)
336 TOOLTIPS_GetDispInfoW(hwnd, infoPtr, toolPtr);
338 TOOLTIPS_GetDispInfoA(hwnd, infoPtr, toolPtr);
341 /* the item is a usual (unicode) text */
342 lstrcpynW (infoPtr->szTipText, toolPtr->lpszText, INFOTIPSIZE);
346 /* no text available */
347 infoPtr->szTipText[0] = L'\0';
350 TRACE("%s\n", debugstr_w(infoPtr->szTipText));
355 TOOLTIPS_CalcTipSize (HWND hwnd, TOOLTIPS_INFO *infoPtr, LPSIZE lpSize)
359 DWORD style = GetWindowLongW(hwnd, GWL_STYLE);
360 UINT uFlags = DT_EXTERNALLEADING | DT_CALCRECT;
361 RECT rc = {0, 0, 0, 0};
363 if (infoPtr->nMaxTipWidth > -1) {
364 rc.right = infoPtr->nMaxTipWidth;
365 uFlags |= DT_WORDBREAK;
367 if (style & TTS_NOPREFIX)
368 uFlags |= DT_NOPREFIX;
369 TRACE("%s\n", debugstr_w(infoPtr->szTipText));
372 hOldFont = SelectObject (hdc, infoPtr->hFont);
373 DrawTextW (hdc, infoPtr->szTipText, -1, &rc, uFlags);
374 SelectObject (hdc, hOldFont);
375 ReleaseDC (hwnd, hdc);
377 if (style & TTS_BALLOON)
379 lpSize->cx = rc.right - rc.left + 2*BALLOON_TEXT_MARGIN +
380 infoPtr->rcMargin.left + infoPtr->rcMargin.right;
381 lpSize->cy = rc.bottom - rc.top + 2*BALLOON_TEXT_MARGIN +
382 infoPtr->rcMargin.bottom + infoPtr->rcMargin.top +
387 lpSize->cx = rc.right - rc.left + 2*NORMAL_TEXT_MARGIN +
388 infoPtr->rcMargin.left + infoPtr->rcMargin.right;
389 lpSize->cy = rc.bottom - rc.top + 2*NORMAL_TEXT_MARGIN +
390 infoPtr->rcMargin.bottom + infoPtr->rcMargin.top;
396 TOOLTIPS_Show (HWND hwnd, TOOLTIPS_INFO *infoPtr)
398 TTTOOL_INFO *toolPtr;
403 DWORD style = GetWindowLongW(hwnd, GWL_STYLE);
405 if (infoPtr->nTool == -1) {
406 TRACE("invalid tool (-1)!\n");
410 infoPtr->nCurrentTool = infoPtr->nTool;
412 TRACE("Show tooltip pre %d! (%p)\n", infoPtr->nTool, hwnd);
414 TOOLTIPS_GetTipText (hwnd, infoPtr, infoPtr->nCurrentTool);
416 if (infoPtr->szTipText[0] == L'\0') {
417 infoPtr->nCurrentTool = -1;
421 TRACE("Show tooltip %d!\n", infoPtr->nCurrentTool);
422 toolPtr = &infoPtr->tools[infoPtr->nCurrentTool];
425 hdr.idFrom = toolPtr->uId;
427 SendMessageA (toolPtr->hwnd, WM_NOTIFY,
428 (WPARAM)toolPtr->uId, (LPARAM)&hdr);
430 TRACE("%s\n", debugstr_w(infoPtr->szTipText));
432 TOOLTIPS_CalcTipSize (hwnd, infoPtr, &size);
433 TRACE("size %ld x %ld\n", size.cx, size.cy);
435 if (toolPtr->uFlags & TTF_CENTERTIP) {
438 if (toolPtr->uFlags & TTF_IDISHWND)
439 GetWindowRect ((HWND)toolPtr->uId, &rc);
442 MapWindowPoints (toolPtr->hwnd, NULL, (LPPOINT)&rc, 2);
444 rect.left = (rc.left + rc.right - size.cx) / 2;
445 if (style & TTS_BALLOON)
447 ptfx = rc.left + ((rc.right - rc.left) / 2);
448 if(rect.top - size.cy >= 0)
451 infoPtr->bToolBelow = FALSE;
455 infoPtr->bToolBelow = TRUE;
458 rect.left = max(0, rect.left - BALLOON_STEMINDENT);
462 rect.top = rc.bottom + 2;
463 infoPtr->bToolBelow = TRUE;
467 GetCursorPos ((LPPOINT)&rect);
468 if (style & TTS_BALLOON)
471 if(rect.top - size.cy >= 0)
474 infoPtr->bToolBelow = FALSE;
478 infoPtr->bToolBelow = TRUE;
481 rect.left = max(0, rect.left - BALLOON_STEMINDENT);
486 infoPtr->bToolBelow = TRUE;
490 TRACE("pos %ld - %ld\n", rect.left, rect.top);
492 rect.right = rect.left + size.cx;
493 rect.bottom = rect.top + size.cy;
496 wndrect.right = GetSystemMetrics( SM_CXSCREEN );
497 if( rect.right > wndrect.right ) {
498 rect.left -= rect.right - wndrect.right + 2;
499 rect.right = wndrect.right - 2;
501 wndrect.bottom = GetSystemMetrics( SM_CYSCREEN );
502 if( rect.bottom > wndrect.bottom ) {
505 if (toolPtr->uFlags & TTF_IDISHWND)
506 GetWindowRect ((HWND)toolPtr->uId, &rc);
509 MapWindowPoints (toolPtr->hwnd, NULL, (LPPOINT)&rc, 2);
511 rect.bottom = rc.top - 2;
512 rect.top = rect.bottom - size.cy;
515 AdjustWindowRectEx (&rect, GetWindowLongA (hwnd, GWL_STYLE),
516 FALSE, GetWindowLongA (hwnd, GWL_EXSTYLE));
518 if (style & TTS_BALLOON)
526 if(infoPtr->bToolBelow)
530 pts[1].x = max(BALLOON_STEMINDENT, ptfx - (BALLOON_STEMWIDTH / 2));
531 pts[1].y = BALLOON_STEMHEIGHT;
532 pts[2].x = pts[1].x + BALLOON_STEMWIDTH;
534 if(pts[2].x > (rect.right - rect.left) - BALLOON_STEMINDENT)
536 pts[2].x = (rect.right - rect.left) - BALLOON_STEMINDENT;
537 pts[1].x = pts[2].x - BALLOON_STEMWIDTH;
542 pts[0].x = max(BALLOON_STEMINDENT, ptfx - (BALLOON_STEMWIDTH / 2));
543 pts[0].y = (rect.bottom - rect.top) - BALLOON_STEMHEIGHT;
544 pts[1].x = pts[0].x + BALLOON_STEMWIDTH;
547 pts[2].y = (rect.bottom - rect.top);
548 if(pts[1].x > (rect.right - rect.left) - BALLOON_STEMINDENT)
550 pts[1].x = (rect.right - rect.left) - BALLOON_STEMINDENT;
551 pts[0].x = pts[1].x - BALLOON_STEMWIDTH;
555 hrStem = CreatePolygonRgn(pts, sizeof(pts) / sizeof(pts[0]), ALTERNATE);
557 hRgn = CreateRoundRectRgn(0,
558 (infoPtr->bToolBelow ? BALLOON_STEMHEIGHT : 0),
559 rect.right - rect.left,
560 (infoPtr->bToolBelow ? rect.bottom - rect.top : rect.bottom - rect.top - BALLOON_STEMHEIGHT),
561 BALLOON_ROUNDEDNESS, BALLOON_ROUNDEDNESS);
563 CombineRgn(hRgn, hRgn, hrStem, RGN_OR);
564 DeleteObject(hrStem);
566 SetWindowRgn(hwnd, hRgn, FALSE);
567 /* we don't free the region handle as the system deletes it when
568 * it is no longer needed */
571 SetWindowPos (hwnd, HWND_TOP, rect.left, rect.top,
572 rect.right - rect.left, rect.bottom - rect.top,
573 SWP_SHOWWINDOW | SWP_NOACTIVATE);
575 /* repaint the tooltip */
576 InvalidateRect(hwnd, NULL, TRUE);
579 SetTimer (hwnd, ID_TIMERPOP, infoPtr->nAutoPopTime, 0);
580 TRACE("timer 2 started!\n");
581 SetTimer (hwnd, ID_TIMERLEAVE, infoPtr->nReshowTime, 0);
582 TRACE("timer 3 started!\n");
587 TOOLTIPS_Hide (HWND hwnd, TOOLTIPS_INFO *infoPtr)
589 TTTOOL_INFO *toolPtr;
592 TRACE("Hide tooltip %d! (%p)\n", infoPtr->nCurrentTool, hwnd);
594 if (infoPtr->nCurrentTool == -1)
597 toolPtr = &infoPtr->tools[infoPtr->nCurrentTool];
598 KillTimer (hwnd, ID_TIMERPOP);
601 hdr.idFrom = toolPtr->uId;
603 SendMessageA (toolPtr->hwnd, WM_NOTIFY,
604 (WPARAM)toolPtr->uId, (LPARAM)&hdr);
606 infoPtr->nCurrentTool = -1;
608 SetWindowPos (hwnd, HWND_TOP, 0, 0, 0, 0,
609 SWP_NOZORDER | SWP_HIDEWINDOW | SWP_NOACTIVATE);
614 TOOLTIPS_TrackShow (HWND hwnd, TOOLTIPS_INFO *infoPtr)
616 TTTOOL_INFO *toolPtr;
621 if (infoPtr->nTrackTool == -1) {
622 TRACE("invalid tracking tool (-1)!\n");
626 TRACE("show tracking tooltip pre %d!\n", infoPtr->nTrackTool);
628 TOOLTIPS_GetTipText (hwnd, infoPtr, infoPtr->nTrackTool);
630 if (infoPtr->szTipText[0] == L'\0') {
631 infoPtr->nTrackTool = -1;
635 TRACE("show tracking tooltip %d!\n", infoPtr->nTrackTool);
636 toolPtr = &infoPtr->tools[infoPtr->nTrackTool];
639 hdr.idFrom = toolPtr->uId;
641 SendMessageA (toolPtr->hwnd, WM_NOTIFY,
642 (WPARAM)toolPtr->uId, (LPARAM)&hdr);
644 TRACE("%s\n", debugstr_w(infoPtr->szTipText));
646 TOOLTIPS_CalcTipSize (hwnd, infoPtr, &size);
647 TRACE("size %ld x %ld\n", size.cx, size.cy);
649 if (toolPtr->uFlags & TTF_ABSOLUTE) {
650 rect.left = infoPtr->xTrackPos;
651 rect.top = infoPtr->yTrackPos;
653 if (toolPtr->uFlags & TTF_CENTERTIP) {
654 rect.left -= (size.cx / 2);
655 rect.top -= (size.cy / 2);
661 if (toolPtr->uFlags & TTF_IDISHWND)
662 GetWindowRect ((HWND)toolPtr->uId, &rcTool);
664 rcTool = toolPtr->rect;
665 MapWindowPoints (toolPtr->hwnd, NULL, (LPPOINT)&rcTool, 2);
668 GetCursorPos ((LPPOINT)&rect);
671 if (toolPtr->uFlags & TTF_CENTERTIP) {
672 rect.left -= (size.cx / 2);
673 rect.top -= (size.cy / 2);
676 /* smart placement */
677 if ((rect.left + size.cx > rcTool.left) && (rect.left < rcTool.right) &&
678 (rect.top + size.cy > rcTool.top) && (rect.top < rcTool.bottom))
679 rect.left = rcTool.right;
682 TRACE("pos %ld - %ld\n", rect.left, rect.top);
684 rect.right = rect.left + size.cx;
685 rect.bottom = rect.top + size.cy;
687 AdjustWindowRectEx (&rect, GetWindowLongA (hwnd, GWL_STYLE),
688 FALSE, GetWindowLongA (hwnd, GWL_EXSTYLE));
690 if (GetWindowLongW(hwnd, GWL_STYLE) & TTS_BALLOON)
694 /* FIXME: need to add pointy bit using CreatePolyRgn & CombinRgn */
695 hRgn = CreateRoundRectRgn(0, 0, rect.right - rect.left, rect.bottom - rect.top, BALLOON_ROUNDEDNESS, BALLOON_ROUNDEDNESS);
697 SetWindowRgn(hwnd, hRgn, FALSE);
698 /* we don't free the region handle as the system deletes it when
699 * it is no longer needed */
702 SetWindowPos (hwnd, HWND_TOP, rect.left, rect.top,
703 rect.right - rect.left, rect.bottom - rect.top,
704 SWP_SHOWWINDOW | SWP_NOACTIVATE );
706 InvalidateRect(hwnd, NULL, TRUE);
712 TOOLTIPS_TrackHide (HWND hwnd, TOOLTIPS_INFO *infoPtr)
714 TTTOOL_INFO *toolPtr;
717 TRACE("hide tracking tooltip %d\n", infoPtr->nTrackTool);
719 if (infoPtr->nTrackTool == -1)
722 toolPtr = &infoPtr->tools[infoPtr->nTrackTool];
725 hdr.idFrom = toolPtr->uId;
727 SendMessageA (toolPtr->hwnd, WM_NOTIFY,
728 (WPARAM)toolPtr->uId, (LPARAM)&hdr);
730 SetWindowPos (hwnd, HWND_TOP, 0, 0, 0, 0,
731 SWP_NOZORDER | SWP_HIDEWINDOW | SWP_NOACTIVATE);
736 TOOLTIPS_GetToolFromInfoA (TOOLTIPS_INFO *infoPtr, LPTTTOOLINFOA lpToolInfo)
738 TTTOOL_INFO *toolPtr;
741 for (nTool = 0; nTool < infoPtr->uNumTools; nTool++) {
742 toolPtr = &infoPtr->tools[nTool];
744 if (!(toolPtr->uFlags & TTF_IDISHWND) &&
745 (lpToolInfo->hwnd == toolPtr->hwnd) &&
746 (lpToolInfo->uId == toolPtr->uId))
750 for (nTool = 0; nTool < infoPtr->uNumTools; nTool++) {
751 toolPtr = &infoPtr->tools[nTool];
753 if ((toolPtr->uFlags & TTF_IDISHWND) &&
754 (lpToolInfo->uId == toolPtr->uId))
763 TOOLTIPS_GetToolFromInfoW (TOOLTIPS_INFO *infoPtr, LPTTTOOLINFOW lpToolInfo)
765 TTTOOL_INFO *toolPtr;
768 for (nTool = 0; nTool < infoPtr->uNumTools; nTool++) {
769 toolPtr = &infoPtr->tools[nTool];
771 if (!(toolPtr->uFlags & TTF_IDISHWND) &&
772 (lpToolInfo->hwnd == toolPtr->hwnd) &&
773 (lpToolInfo->uId == toolPtr->uId))
777 for (nTool = 0; nTool < infoPtr->uNumTools; nTool++) {
778 toolPtr = &infoPtr->tools[nTool];
780 if ((toolPtr->uFlags & TTF_IDISHWND) &&
781 (lpToolInfo->uId == toolPtr->uId))
790 TOOLTIPS_GetToolFromPoint (TOOLTIPS_INFO *infoPtr, HWND hwnd, LPPOINT lpPt)
792 TTTOOL_INFO *toolPtr;
795 for (nTool = 0; nTool < infoPtr->uNumTools; nTool++) {
796 toolPtr = &infoPtr->tools[nTool];
798 if (!(toolPtr->uFlags & TTF_IDISHWND)) {
799 if (hwnd != toolPtr->hwnd)
801 if (!PtInRect (&toolPtr->rect, *lpPt))
807 for (nTool = 0; nTool < infoPtr->uNumTools; nTool++) {
808 toolPtr = &infoPtr->tools[nTool];
810 if (toolPtr->uFlags & TTF_IDISHWND) {
811 if ((HWND)toolPtr->uId == hwnd)
821 TOOLTIPS_IsWindowActive (HWND hwnd)
823 HWND hwndActive = GetActiveWindow ();
826 if (hwndActive == hwnd)
828 return IsChild (hwndActive, hwnd);
833 TOOLTIPS_CheckTool (HWND hwnd, BOOL bShowTest)
835 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
841 hwndTool = (HWND)SendMessageA (hwnd, TTM_WINDOWFROMPOINT, 0, (LPARAM)&pt);
845 ScreenToClient (hwndTool, &pt);
846 nTool = TOOLTIPS_GetToolFromPoint (infoPtr, hwndTool, &pt);
850 if (!(GetWindowLongA (hwnd, GWL_STYLE) & TTS_ALWAYSTIP) && bShowTest) {
851 if (!TOOLTIPS_IsWindowActive (GetWindow (hwnd, GW_OWNER)))
855 TRACE("tool %d\n", nTool);
862 TOOLTIPS_Activate (HWND hwnd, WPARAM wParam, LPARAM lParam)
864 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
866 infoPtr->bActive = (BOOL)wParam;
868 if (infoPtr->bActive)
869 TRACE("activate!\n");
871 if (!(infoPtr->bActive) && (infoPtr->nCurrentTool != -1))
872 TOOLTIPS_Hide (hwnd, infoPtr);
879 TOOLTIPS_AddToolA (HWND hwnd, WPARAM wParam, LPARAM lParam)
881 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
882 LPTTTOOLINFOA lpToolInfo = (LPTTTOOLINFOA)lParam;
883 TTTOOL_INFO *toolPtr;
886 if (lpToolInfo == NULL)
888 if (lpToolInfo->cbSize < TTTOOLINFOA_V1_SIZE)
891 TRACE("add tool (%p) %p %d%s!\n",
892 hwnd, lpToolInfo->hwnd, lpToolInfo->uId,
893 (lpToolInfo->uFlags & TTF_IDISHWND) ? " TTF_IDISHWND" : "");
895 if (infoPtr->uNumTools == 0) {
896 infoPtr->tools = Alloc (sizeof(TTTOOL_INFO));
897 toolPtr = infoPtr->tools;
900 TTTOOL_INFO *oldTools = infoPtr->tools;
902 Alloc (sizeof(TTTOOL_INFO) * (infoPtr->uNumTools + 1));
903 memcpy (infoPtr->tools, oldTools,
904 infoPtr->uNumTools * sizeof(TTTOOL_INFO));
906 toolPtr = &infoPtr->tools[infoPtr->uNumTools];
909 infoPtr->uNumTools++;
912 toolPtr->uFlags = lpToolInfo->uFlags;
913 toolPtr->hwnd = lpToolInfo->hwnd;
914 toolPtr->uId = lpToolInfo->uId;
915 toolPtr->rect = lpToolInfo->rect;
916 toolPtr->hinst = lpToolInfo->hinst;
918 if (HIWORD(lpToolInfo->lpszText) == 0) {
919 TRACE("add string id %x!\n", (int)lpToolInfo->lpszText);
920 toolPtr->lpszText = (LPWSTR)lpToolInfo->lpszText;
922 else if (lpToolInfo->lpszText) {
923 if (lpToolInfo->lpszText == LPSTR_TEXTCALLBACKA) {
924 TRACE("add CALLBACK!\n");
925 toolPtr->lpszText = LPSTR_TEXTCALLBACKW;
928 INT len = MultiByteToWideChar(CP_ACP, 0, lpToolInfo->lpszText, -1,
930 TRACE("add text \"%s\"!\n", lpToolInfo->lpszText);
931 toolPtr->lpszText = Alloc (len * sizeof(WCHAR));
932 MultiByteToWideChar(CP_ACP, 0, lpToolInfo->lpszText, -1,
933 toolPtr->lpszText, len);
937 if (lpToolInfo->cbSize >= sizeof(TTTOOLINFOA))
938 toolPtr->lParam = lpToolInfo->lParam;
940 /* install subclassing hook */
941 if (toolPtr->uFlags & TTF_SUBCLASS) {
942 if (toolPtr->uFlags & TTF_IDISHWND) {
943 SetWindowSubclass((HWND)toolPtr->uId, TOOLTIPS_SubclassProc, 1,
947 SetWindowSubclass(toolPtr->hwnd, TOOLTIPS_SubclassProc, 1,
950 TRACE("subclassing installed!\n");
953 nResult = (INT) SendMessageA (toolPtr->hwnd, WM_NOTIFYFORMAT,
954 (WPARAM)hwnd, (LPARAM)NF_QUERY);
955 if (nResult == NFR_ANSI) {
956 toolPtr->bNotifyUnicode = FALSE;
957 TRACE(" -- WM_NOTIFYFORMAT returns: NFR_ANSI\n");
958 } else if (nResult == NFR_UNICODE) {
959 toolPtr->bNotifyUnicode = TRUE;
960 TRACE(" -- WM_NOTIFYFORMAT returns: NFR_UNICODE\n");
962 TRACE (" -- WM_NOTIFYFORMAT returns: error!\n");
970 TOOLTIPS_AddToolW (HWND hwnd, WPARAM wParam, LPARAM lParam)
972 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
973 LPTTTOOLINFOW lpToolInfo = (LPTTTOOLINFOW)lParam;
974 TTTOOL_INFO *toolPtr;
977 if (lpToolInfo == NULL)
979 if (lpToolInfo->cbSize < TTTOOLINFOW_V1_SIZE)
982 TRACE("add tool (%p) %p %d%s!\n",
983 hwnd, lpToolInfo->hwnd, lpToolInfo->uId,
984 (lpToolInfo->uFlags & TTF_IDISHWND) ? " TTF_IDISHWND" : "");
986 if (infoPtr->uNumTools == 0) {
987 infoPtr->tools = Alloc (sizeof(TTTOOL_INFO));
988 toolPtr = infoPtr->tools;
991 TTTOOL_INFO *oldTools = infoPtr->tools;
993 Alloc (sizeof(TTTOOL_INFO) * (infoPtr->uNumTools + 1));
994 memcpy (infoPtr->tools, oldTools,
995 infoPtr->uNumTools * sizeof(TTTOOL_INFO));
997 toolPtr = &infoPtr->tools[infoPtr->uNumTools];
1000 infoPtr->uNumTools++;
1002 /* copy tool data */
1003 toolPtr->uFlags = lpToolInfo->uFlags;
1004 toolPtr->hwnd = lpToolInfo->hwnd;
1005 toolPtr->uId = lpToolInfo->uId;
1006 toolPtr->rect = lpToolInfo->rect;
1007 toolPtr->hinst = lpToolInfo->hinst;
1009 if (HIWORD(lpToolInfo->lpszText) == 0) {
1010 TRACE("add string id %x!\n", (int)lpToolInfo->lpszText);
1011 toolPtr->lpszText = (LPWSTR)lpToolInfo->lpszText;
1013 else if (lpToolInfo->lpszText) {
1014 if (lpToolInfo->lpszText == LPSTR_TEXTCALLBACKW) {
1015 TRACE("add CALLBACK!\n");
1016 toolPtr->lpszText = LPSTR_TEXTCALLBACKW;
1019 INT len = lstrlenW (lpToolInfo->lpszText);
1020 TRACE("add text %s!\n",
1021 debugstr_w(lpToolInfo->lpszText));
1022 toolPtr->lpszText = Alloc ((len + 1)*sizeof(WCHAR));
1023 strcpyW (toolPtr->lpszText, lpToolInfo->lpszText);
1027 if (lpToolInfo->cbSize >= sizeof(TTTOOLINFOW))
1028 toolPtr->lParam = lpToolInfo->lParam;
1030 /* install subclassing hook */
1031 if (toolPtr->uFlags & TTF_SUBCLASS) {
1032 if (toolPtr->uFlags & TTF_IDISHWND) {
1033 SetWindowSubclass((HWND)toolPtr->uId, TOOLTIPS_SubclassProc, 1,
1037 SetWindowSubclass(toolPtr->hwnd, TOOLTIPS_SubclassProc, 1,
1040 TRACE("subclassing installed!\n");
1043 nResult = (INT) SendMessageA (toolPtr->hwnd, WM_NOTIFYFORMAT,
1044 (WPARAM)hwnd, (LPARAM)NF_QUERY);
1045 if (nResult == NFR_ANSI) {
1046 toolPtr->bNotifyUnicode = FALSE;
1047 TRACE(" -- WM_NOTIFYFORMAT returns: NFR_ANSI\n");
1048 } else if (nResult == NFR_UNICODE) {
1049 toolPtr->bNotifyUnicode = TRUE;
1050 TRACE(" -- WM_NOTIFYFORMAT returns: NFR_UNICODE\n");
1052 TRACE (" -- WM_NOTIFYFORMAT returns: error!\n");
1059 static void TOOLTIPS_DelToolCommon (HWND hwnd, TOOLTIPS_INFO *infoPtr, INT nTool)
1061 TTTOOL_INFO *toolPtr;
1063 TRACE("tool %d\n", nTool);
1068 /* make sure the tooltip has disappeared before deleting it */
1069 TOOLTIPS_Hide(hwnd, infoPtr);
1071 /* delete text string */
1072 toolPtr = &infoPtr->tools[nTool];
1073 if (toolPtr->lpszText) {
1074 if ( (toolPtr->lpszText != LPSTR_TEXTCALLBACKW) &&
1075 (HIWORD((INT)toolPtr->lpszText) != 0) )
1076 Free (toolPtr->lpszText);
1079 /* remove subclassing */
1080 if (toolPtr->uFlags & TTF_SUBCLASS) {
1081 if (toolPtr->uFlags & TTF_IDISHWND) {
1082 RemoveWindowSubclass((HWND)toolPtr->uId, TOOLTIPS_SubclassProc, 1);
1085 RemoveWindowSubclass(toolPtr->hwnd, TOOLTIPS_SubclassProc, 1);
1089 /* delete tool from tool list */
1090 if (infoPtr->uNumTools == 1) {
1091 Free (infoPtr->tools);
1092 infoPtr->tools = NULL;
1095 TTTOOL_INFO *oldTools = infoPtr->tools;
1097 Alloc (sizeof(TTTOOL_INFO) * (infoPtr->uNumTools - 1));
1100 memcpy (&infoPtr->tools[0], &oldTools[0],
1101 nTool * sizeof(TTTOOL_INFO));
1103 if (nTool < infoPtr->uNumTools - 1)
1104 memcpy (&infoPtr->tools[nTool], &oldTools[nTool + 1],
1105 (infoPtr->uNumTools - nTool - 1) * sizeof(TTTOOL_INFO));
1110 /* update any indices affected by delete */
1112 /* destroying tool that mouse was on on last relayed mouse move */
1113 if (infoPtr->nTool == nTool)
1114 /* -1 means no current tool (0 means first tool) */
1115 infoPtr->nTool = -1;
1116 else if (infoPtr->nTool > nTool)
1119 if (infoPtr->nTrackTool == nTool)
1120 /* -1 means no current tool (0 means first tool) */
1121 infoPtr->nTrackTool = -1;
1122 else if (infoPtr->nTrackTool > nTool)
1123 infoPtr->nTrackTool--;
1125 if (infoPtr->nCurrentTool == nTool)
1126 /* -1 means no current tool (0 means first tool) */
1127 infoPtr->nCurrentTool = -1;
1128 else if (infoPtr->nCurrentTool > nTool)
1129 infoPtr->nCurrentTool--;
1131 infoPtr->uNumTools--;
1135 TOOLTIPS_DelToolA (HWND hwnd, WPARAM wParam, LPARAM lParam)
1137 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1138 LPTTTOOLINFOA lpToolInfo = (LPTTTOOLINFOA)lParam;
1141 if (lpToolInfo == NULL)
1143 if (lpToolInfo->cbSize < TTTOOLINFOA_V1_SIZE)
1145 if (infoPtr->uNumTools == 0)
1148 nTool = TOOLTIPS_GetToolFromInfoA (infoPtr, lpToolInfo);
1150 TOOLTIPS_DelToolCommon (hwnd, infoPtr, nTool);
1157 TOOLTIPS_DelToolW (HWND hwnd, WPARAM wParam, LPARAM lParam)
1159 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1160 LPTTTOOLINFOW lpToolInfo = (LPTTTOOLINFOW)lParam;
1163 if (lpToolInfo == NULL)
1165 if (lpToolInfo->cbSize < TTTOOLINFOW_V1_SIZE)
1167 if (infoPtr->uNumTools == 0)
1170 nTool = TOOLTIPS_GetToolFromInfoW (infoPtr, lpToolInfo);
1172 TOOLTIPS_DelToolCommon (hwnd, infoPtr, nTool);
1179 TOOLTIPS_EnumToolsA (HWND hwnd, WPARAM wParam, LPARAM lParam)
1181 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1182 UINT uIndex = (UINT)wParam;
1183 LPTTTOOLINFOA lpToolInfo = (LPTTTOOLINFOA)lParam;
1184 TTTOOL_INFO *toolPtr;
1186 if (lpToolInfo == NULL)
1188 if (lpToolInfo->cbSize < TTTOOLINFOA_V1_SIZE)
1190 if (uIndex >= infoPtr->uNumTools)
1193 TRACE("index=%u\n", uIndex);
1195 toolPtr = &infoPtr->tools[uIndex];
1197 /* copy tool data */
1198 lpToolInfo->uFlags = toolPtr->uFlags;
1199 lpToolInfo->hwnd = toolPtr->hwnd;
1200 lpToolInfo->uId = toolPtr->uId;
1201 lpToolInfo->rect = toolPtr->rect;
1202 lpToolInfo->hinst = toolPtr->hinst;
1203 /* lpToolInfo->lpszText = toolPtr->lpszText; */
1204 lpToolInfo->lpszText = NULL; /* FIXME */
1206 if (lpToolInfo->cbSize >= sizeof(TTTOOLINFOA))
1207 lpToolInfo->lParam = toolPtr->lParam;
1214 TOOLTIPS_EnumToolsW (HWND hwnd, WPARAM wParam, LPARAM lParam)
1216 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1217 UINT uIndex = (UINT)wParam;
1218 LPTTTOOLINFOW lpToolInfo = (LPTTTOOLINFOW)lParam;
1219 TTTOOL_INFO *toolPtr;
1221 if (lpToolInfo == NULL)
1223 if (lpToolInfo->cbSize < TTTOOLINFOW_V1_SIZE)
1225 if (uIndex >= infoPtr->uNumTools)
1228 TRACE("index=%u\n", uIndex);
1230 toolPtr = &infoPtr->tools[uIndex];
1232 /* copy tool data */
1233 lpToolInfo->uFlags = toolPtr->uFlags;
1234 lpToolInfo->hwnd = toolPtr->hwnd;
1235 lpToolInfo->uId = toolPtr->uId;
1236 lpToolInfo->rect = toolPtr->rect;
1237 lpToolInfo->hinst = toolPtr->hinst;
1238 /* lpToolInfo->lpszText = toolPtr->lpszText; */
1239 lpToolInfo->lpszText = NULL; /* FIXME */
1241 if (lpToolInfo->cbSize >= sizeof(TTTOOLINFOW))
1242 lpToolInfo->lParam = toolPtr->lParam;
1248 TOOLTIPS_GetBubbleSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
1250 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1251 LPTTTOOLINFOW lpToolInfo = (LPTTTOOLINFOW)lParam;
1255 if (lpToolInfo == NULL)
1257 if (lpToolInfo->cbSize < TTTOOLINFOW_V1_SIZE)
1260 nTool = TOOLTIPS_GetToolFromInfoW (infoPtr, lpToolInfo);
1261 if (nTool == -1) return 0;
1263 TRACE("tool %d\n", nTool);
1265 TOOLTIPS_CalcTipSize (hwnd, infoPtr, &size);
1266 TRACE("size %ld x %ld\n", size.cx, size.cy);
1268 return MAKELRESULT(size.cx, size.cy);
1272 TOOLTIPS_GetCurrentToolA (HWND hwnd, WPARAM wParam, LPARAM lParam)
1274 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1275 LPTTTOOLINFOA lpToolInfo = (LPTTTOOLINFOA)lParam;
1276 TTTOOL_INFO *toolPtr;
1278 if (lpToolInfo == NULL)
1280 if (lpToolInfo->cbSize < TTTOOLINFOA_V1_SIZE)
1284 if (infoPtr->nCurrentTool > -1) {
1285 toolPtr = &infoPtr->tools[infoPtr->nCurrentTool];
1287 /* copy tool data */
1288 lpToolInfo->uFlags = toolPtr->uFlags;
1289 lpToolInfo->rect = toolPtr->rect;
1290 lpToolInfo->hinst = toolPtr->hinst;
1291 /* lpToolInfo->lpszText = toolPtr->lpszText; */
1292 lpToolInfo->lpszText = NULL; /* FIXME */
1294 if (lpToolInfo->cbSize >= sizeof(TTTOOLINFOA))
1295 lpToolInfo->lParam = toolPtr->lParam;
1303 return (infoPtr->nCurrentTool != -1);
1310 TOOLTIPS_GetCurrentToolW (HWND hwnd, WPARAM wParam, LPARAM lParam)
1312 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1313 LPTTTOOLINFOW lpToolInfo = (LPTTTOOLINFOW)lParam;
1314 TTTOOL_INFO *toolPtr;
1316 if (lpToolInfo == NULL)
1318 if (lpToolInfo->cbSize < TTTOOLINFOW_V1_SIZE)
1322 if (infoPtr->nCurrentTool > -1) {
1323 toolPtr = &infoPtr->tools[infoPtr->nCurrentTool];
1325 /* copy tool data */
1326 lpToolInfo->uFlags = toolPtr->uFlags;
1327 lpToolInfo->rect = toolPtr->rect;
1328 lpToolInfo->hinst = toolPtr->hinst;
1329 /* lpToolInfo->lpszText = toolPtr->lpszText; */
1330 lpToolInfo->lpszText = NULL; /* FIXME */
1332 if (lpToolInfo->cbSize >= sizeof(TTTOOLINFOW))
1333 lpToolInfo->lParam = toolPtr->lParam;
1341 return (infoPtr->nCurrentTool != -1);
1348 TOOLTIPS_GetDelayTime (HWND hwnd, WPARAM wParam, LPARAM lParam)
1350 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1354 return infoPtr->nReshowTime;
1357 return infoPtr->nAutoPopTime;
1360 case TTDT_AUTOMATIC: /* Apparently TTDT_AUTOMATIC returns TTDT_INITIAL */
1361 return infoPtr->nInitialTime;
1364 WARN("Invalid wParam %x\n", wParam);
1373 TOOLTIPS_GetMargin (HWND hwnd, WPARAM wParam, LPARAM lParam)
1375 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1376 LPRECT lpRect = (LPRECT)lParam;
1378 lpRect->left = infoPtr->rcMargin.left;
1379 lpRect->right = infoPtr->rcMargin.right;
1380 lpRect->bottom = infoPtr->rcMargin.bottom;
1381 lpRect->top = infoPtr->rcMargin.top;
1387 inline static LRESULT
1388 TOOLTIPS_GetMaxTipWidth (HWND hwnd, WPARAM wParam, LPARAM lParam)
1390 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1392 return infoPtr->nMaxTipWidth;
1397 TOOLTIPS_GetTextA (HWND hwnd, WPARAM wParam, LPARAM lParam)
1399 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1400 LPTTTOOLINFOA lpToolInfo = (LPTTTOOLINFOA)lParam;
1403 if (lpToolInfo == NULL)
1405 if (lpToolInfo->cbSize < TTTOOLINFOA_V1_SIZE)
1408 nTool = TOOLTIPS_GetToolFromInfoA (infoPtr, lpToolInfo);
1409 if (nTool == -1) return 0;
1411 /* NB this API is broken, there is no way for the app to determine
1412 what size buffer it requires nor a way to specify how long the
1413 one it supplies is. We'll assume it's upto INFOTIPSIZE */
1415 WideCharToMultiByte(CP_ACP, 0, infoPtr->tools[nTool].lpszText, -1,
1416 lpToolInfo->lpszText, INFOTIPSIZE, NULL, NULL);
1423 TOOLTIPS_GetTextW (HWND hwnd, WPARAM wParam, LPARAM lParam)
1425 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1426 LPTTTOOLINFOW lpToolInfo = (LPTTTOOLINFOW)lParam;
1429 if (lpToolInfo == NULL)
1431 if (lpToolInfo->cbSize < TTTOOLINFOW_V1_SIZE)
1434 nTool = TOOLTIPS_GetToolFromInfoW (infoPtr, lpToolInfo);
1435 if (nTool == -1) return 0;
1437 strcpyW (lpToolInfo->lpszText, infoPtr->tools[nTool].lpszText);
1443 inline static LRESULT
1444 TOOLTIPS_GetTipBkColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
1446 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1447 return infoPtr->clrBk;
1451 inline static LRESULT
1452 TOOLTIPS_GetTipTextColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
1454 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1455 return infoPtr->clrText;
1459 inline static LRESULT
1460 TOOLTIPS_GetToolCount (HWND hwnd, WPARAM wParam, LPARAM lParam)
1462 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1463 return infoPtr->uNumTools;
1468 TOOLTIPS_GetToolInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
1470 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1471 LPTTTOOLINFOA lpToolInfo = (LPTTTOOLINFOA)lParam;
1472 TTTOOL_INFO *toolPtr;
1475 if (lpToolInfo == NULL)
1477 if (lpToolInfo->cbSize < TTTOOLINFOA_V1_SIZE)
1479 if (infoPtr->uNumTools == 0)
1482 nTool = TOOLTIPS_GetToolFromInfoA (infoPtr, lpToolInfo);
1486 TRACE("tool %d\n", nTool);
1488 toolPtr = &infoPtr->tools[nTool];
1490 /* copy tool data */
1491 lpToolInfo->uFlags = toolPtr->uFlags;
1492 lpToolInfo->rect = toolPtr->rect;
1493 lpToolInfo->hinst = toolPtr->hinst;
1494 /* lpToolInfo->lpszText = toolPtr->lpszText; */
1495 lpToolInfo->lpszText = NULL; /* FIXME */
1497 if (lpToolInfo->cbSize >= sizeof(TTTOOLINFOA))
1498 lpToolInfo->lParam = toolPtr->lParam;
1505 TOOLTIPS_GetToolInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
1507 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1508 LPTTTOOLINFOW lpToolInfo = (LPTTTOOLINFOW)lParam;
1509 TTTOOL_INFO *toolPtr;
1512 if (lpToolInfo == NULL)
1514 if (lpToolInfo->cbSize < TTTOOLINFOW_V1_SIZE)
1516 if (infoPtr->uNumTools == 0)
1519 nTool = TOOLTIPS_GetToolFromInfoW (infoPtr, lpToolInfo);
1523 TRACE("tool %d\n", nTool);
1525 toolPtr = &infoPtr->tools[nTool];
1527 /* copy tool data */
1528 lpToolInfo->uFlags = toolPtr->uFlags;
1529 lpToolInfo->rect = toolPtr->rect;
1530 lpToolInfo->hinst = toolPtr->hinst;
1531 /* lpToolInfo->lpszText = toolPtr->lpszText; */
1532 lpToolInfo->lpszText = NULL; /* FIXME */
1534 if (lpToolInfo->cbSize >= sizeof(TTTOOLINFOW))
1535 lpToolInfo->lParam = toolPtr->lParam;
1542 TOOLTIPS_HitTestA (HWND hwnd, WPARAM wParam, LPARAM lParam)
1544 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1545 LPTTHITTESTINFOA lptthit = (LPTTHITTESTINFOA)lParam;
1546 TTTOOL_INFO *toolPtr;
1552 nTool = TOOLTIPS_GetToolFromPoint (infoPtr, lptthit->hwnd, &lptthit->pt);
1556 TRACE("tool %d!\n", nTool);
1558 /* copy tool data */
1559 if (lptthit->ti.cbSize >= sizeof(TTTOOLINFOA)) {
1560 toolPtr = &infoPtr->tools[nTool];
1562 lptthit->ti.uFlags = toolPtr->uFlags;
1563 lptthit->ti.hwnd = toolPtr->hwnd;
1564 lptthit->ti.uId = toolPtr->uId;
1565 lptthit->ti.rect = toolPtr->rect;
1566 lptthit->ti.hinst = toolPtr->hinst;
1567 /* lptthit->ti.lpszText = toolPtr->lpszText; */
1568 lptthit->ti.lpszText = NULL; /* FIXME */
1569 lptthit->ti.lParam = toolPtr->lParam;
1577 TOOLTIPS_HitTestW (HWND hwnd, WPARAM wParam, LPARAM lParam)
1579 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1580 LPTTHITTESTINFOW lptthit = (LPTTHITTESTINFOW)lParam;
1581 TTTOOL_INFO *toolPtr;
1587 nTool = TOOLTIPS_GetToolFromPoint (infoPtr, lptthit->hwnd, &lptthit->pt);
1591 TRACE("tool %d!\n", nTool);
1593 /* copy tool data */
1594 if (lptthit->ti.cbSize >= sizeof(TTTOOLINFOW)) {
1595 toolPtr = &infoPtr->tools[nTool];
1597 lptthit->ti.uFlags = toolPtr->uFlags;
1598 lptthit->ti.hwnd = toolPtr->hwnd;
1599 lptthit->ti.uId = toolPtr->uId;
1600 lptthit->ti.rect = toolPtr->rect;
1601 lptthit->ti.hinst = toolPtr->hinst;
1602 /* lptthit->ti.lpszText = toolPtr->lpszText; */
1603 lptthit->ti.lpszText = NULL; /* FIXME */
1604 lptthit->ti.lParam = toolPtr->lParam;
1612 TOOLTIPS_NewToolRectA (HWND hwnd, WPARAM wParam, LPARAM lParam)
1614 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1615 LPTTTOOLINFOA lpti = (LPTTTOOLINFOA)lParam;
1620 if (lpti->cbSize < TTTOOLINFOA_V1_SIZE)
1623 nTool = TOOLTIPS_GetToolFromInfoA (infoPtr, lpti);
1625 TRACE("nTool = %d, rect = %s\n", nTool, wine_dbgstr_rect(&lpti->rect));
1627 if (nTool == -1) return 0;
1629 infoPtr->tools[nTool].rect = lpti->rect;
1636 TOOLTIPS_NewToolRectW (HWND hwnd, WPARAM wParam, LPARAM lParam)
1638 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1639 LPTTTOOLINFOW lpti = (LPTTTOOLINFOW)lParam;
1644 if (lpti->cbSize < TTTOOLINFOW_V1_SIZE)
1647 nTool = TOOLTIPS_GetToolFromInfoW (infoPtr, lpti);
1649 TRACE("nTool = %d, rect = %s\n", nTool, wine_dbgstr_rect(&lpti->rect));
1651 if (nTool == -1) return 0;
1653 infoPtr->tools[nTool].rect = lpti->rect;
1659 inline static LRESULT
1660 TOOLTIPS_Pop (HWND hwnd, WPARAM wParam, LPARAM lParam)
1662 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1663 TOOLTIPS_Hide (hwnd, infoPtr);
1670 TOOLTIPS_RelayEvent (HWND hwnd, WPARAM wParam, LPARAM lParam)
1672 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1673 LPMSG lpMsg = (LPMSG)lParam;
1678 ERR("lpMsg == NULL!\n");
1682 switch (lpMsg->message) {
1683 case WM_LBUTTONDOWN:
1685 case WM_MBUTTONDOWN:
1687 case WM_RBUTTONDOWN:
1689 TOOLTIPS_Hide (hwnd, infoPtr);
1693 pt.x = LOWORD(lpMsg->lParam);
1694 pt.y = HIWORD(lpMsg->lParam);
1695 nOldTool = infoPtr->nTool;
1696 infoPtr->nTool = TOOLTIPS_GetToolFromPoint(infoPtr, lpMsg->hwnd,
1698 TRACE("tool (%p) %d %d %d\n", hwnd, nOldTool,
1699 infoPtr->nTool, infoPtr->nCurrentTool);
1700 TRACE("WM_MOUSEMOVE (%p %ld %ld)\n", hwnd, pt.x, pt.y);
1702 if (infoPtr->nTool != nOldTool) {
1703 if(infoPtr->nTool == -1) { /* Moved out of all tools */
1704 TOOLTIPS_Hide(hwnd, infoPtr);
1705 KillTimer(hwnd, ID_TIMERLEAVE);
1706 } else if (nOldTool == -1) { /* Moved from outside */
1707 if(infoPtr->bActive) {
1708 SetTimer(hwnd, ID_TIMERSHOW, infoPtr->nInitialTime, 0);
1709 TRACE("timer 1 started!\n");
1711 } else { /* Moved from one to another */
1712 TOOLTIPS_Hide (hwnd, infoPtr);
1713 KillTimer(hwnd, ID_TIMERLEAVE);
1714 if(infoPtr->bActive) {
1715 SetTimer (hwnd, ID_TIMERSHOW, infoPtr->nReshowTime, 0);
1716 TRACE("timer 1 started!\n");
1719 } else if(infoPtr->nCurrentTool != -1) { /* restart autopop */
1720 KillTimer(hwnd, ID_TIMERPOP);
1721 SetTimer(hwnd, ID_TIMERPOP, infoPtr->nAutoPopTime, 0);
1722 TRACE("timer 2 restarted\n");
1732 TOOLTIPS_SetDelayTime (HWND hwnd, WPARAM wParam, LPARAM lParam)
1734 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1735 INT nTime = (INT)LOWORD(lParam);
1738 case TTDT_AUTOMATIC:
1740 nTime = GetDoubleClickTime();
1741 infoPtr->nReshowTime = nTime / 5;
1742 infoPtr->nAutoPopTime = nTime * 10;
1743 infoPtr->nInitialTime = nTime;
1748 nTime = GetDoubleClickTime() / 5;
1749 infoPtr->nReshowTime = nTime;
1754 nTime = GetDoubleClickTime() * 10;
1755 infoPtr->nAutoPopTime = nTime;
1760 nTime = GetDoubleClickTime();
1761 infoPtr->nInitialTime = nTime;
1765 WARN("Invalid wParam %x\n", wParam);
1774 TOOLTIPS_SetMargin (HWND hwnd, WPARAM wParam, LPARAM lParam)
1776 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1777 LPRECT lpRect = (LPRECT)lParam;
1779 infoPtr->rcMargin.left = lpRect->left;
1780 infoPtr->rcMargin.right = lpRect->right;
1781 infoPtr->rcMargin.bottom = lpRect->bottom;
1782 infoPtr->rcMargin.top = lpRect->top;
1788 inline static LRESULT
1789 TOOLTIPS_SetMaxTipWidth (HWND hwnd, WPARAM wParam, LPARAM lParam)
1791 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1792 INT nTemp = infoPtr->nMaxTipWidth;
1794 infoPtr->nMaxTipWidth = (INT)lParam;
1800 inline static LRESULT
1801 TOOLTIPS_SetTipBkColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
1803 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1805 infoPtr->clrBk = (COLORREF)wParam;
1811 inline static LRESULT
1812 TOOLTIPS_SetTipTextColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
1814 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1816 infoPtr->clrText = (COLORREF)wParam;
1823 TOOLTIPS_SetToolInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
1825 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1826 LPTTTOOLINFOA lpToolInfo = (LPTTTOOLINFOA)lParam;
1827 TTTOOL_INFO *toolPtr;
1830 if (lpToolInfo == NULL)
1832 if (lpToolInfo->cbSize < TTTOOLINFOA_V1_SIZE)
1835 nTool = TOOLTIPS_GetToolFromInfoA (infoPtr, lpToolInfo);
1836 if (nTool == -1) return 0;
1838 TRACE("tool %d\n", nTool);
1840 toolPtr = &infoPtr->tools[nTool];
1842 /* copy tool data */
1843 toolPtr->uFlags = lpToolInfo->uFlags;
1844 toolPtr->hwnd = lpToolInfo->hwnd;
1845 toolPtr->uId = lpToolInfo->uId;
1846 toolPtr->rect = lpToolInfo->rect;
1847 toolPtr->hinst = lpToolInfo->hinst;
1849 if (HIWORD(lpToolInfo->lpszText) == 0) {
1850 TRACE("set string id %x!\n", (INT)lpToolInfo->lpszText);
1851 toolPtr->lpszText = (LPWSTR)lpToolInfo->lpszText;
1853 else if (lpToolInfo->lpszText) {
1854 if (lpToolInfo->lpszText == LPSTR_TEXTCALLBACKA)
1855 toolPtr->lpszText = LPSTR_TEXTCALLBACKW;
1857 if ( (toolPtr->lpszText) &&
1858 (HIWORD((INT)toolPtr->lpszText) != 0) ) {
1859 Free (toolPtr->lpszText);
1860 toolPtr->lpszText = NULL;
1862 if (lpToolInfo->lpszText) {
1863 INT len = MultiByteToWideChar(CP_ACP, 0, lpToolInfo->lpszText,
1865 toolPtr->lpszText = Alloc (len * sizeof(WCHAR));
1866 MultiByteToWideChar(CP_ACP, 0, lpToolInfo->lpszText, -1,
1867 toolPtr->lpszText, len);
1872 if (lpToolInfo->cbSize >= sizeof(TTTOOLINFOA))
1873 toolPtr->lParam = lpToolInfo->lParam;
1880 TOOLTIPS_SetToolInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
1882 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1883 LPTTTOOLINFOW lpToolInfo = (LPTTTOOLINFOW)lParam;
1884 TTTOOL_INFO *toolPtr;
1887 if (lpToolInfo == NULL)
1889 if (lpToolInfo->cbSize < TTTOOLINFOW_V1_SIZE)
1892 nTool = TOOLTIPS_GetToolFromInfoW (infoPtr, lpToolInfo);
1893 if (nTool == -1) return 0;
1895 TRACE("tool %d\n", nTool);
1897 toolPtr = &infoPtr->tools[nTool];
1899 /* copy tool data */
1900 toolPtr->uFlags = lpToolInfo->uFlags;
1901 toolPtr->hwnd = lpToolInfo->hwnd;
1902 toolPtr->uId = lpToolInfo->uId;
1903 toolPtr->rect = lpToolInfo->rect;
1904 toolPtr->hinst = lpToolInfo->hinst;
1906 if (HIWORD(lpToolInfo->lpszText) == 0) {
1907 TRACE("set string id %x!\n", (INT)lpToolInfo->lpszText);
1908 toolPtr->lpszText = lpToolInfo->lpszText;
1910 else if (lpToolInfo->lpszText) {
1911 if (lpToolInfo->lpszText == LPSTR_TEXTCALLBACKW)
1912 toolPtr->lpszText = LPSTR_TEXTCALLBACKW;
1914 if ( (toolPtr->lpszText) &&
1915 (HIWORD((INT)toolPtr->lpszText) != 0) ) {
1916 Free (toolPtr->lpszText);
1917 toolPtr->lpszText = NULL;
1919 if (lpToolInfo->lpszText) {
1920 INT len = lstrlenW (lpToolInfo->lpszText);
1921 toolPtr->lpszText = Alloc ((len+1)*sizeof(WCHAR));
1922 strcpyW (toolPtr->lpszText, lpToolInfo->lpszText);
1927 if (lpToolInfo->cbSize >= sizeof(TTTOOLINFOW))
1928 toolPtr->lParam = lpToolInfo->lParam;
1935 TOOLTIPS_TrackActivate (HWND hwnd, WPARAM wParam, LPARAM lParam)
1937 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1940 LPTTTOOLINFOA lpToolInfo = (LPTTTOOLINFOA)lParam;
1942 if (lpToolInfo == NULL)
1944 if (lpToolInfo->cbSize < TTTOOLINFOA_V1_SIZE)
1948 infoPtr->nTrackTool = TOOLTIPS_GetToolFromInfoA (infoPtr, lpToolInfo);
1949 if (infoPtr->nTrackTool != -1) {
1950 TRACE("activated!\n");
1951 infoPtr->bTrackActive = TRUE;
1952 TOOLTIPS_TrackShow (hwnd, infoPtr);
1957 TOOLTIPS_TrackHide (hwnd, infoPtr);
1959 infoPtr->bTrackActive = FALSE;
1960 infoPtr->nTrackTool = -1;
1962 TRACE("deactivated!\n");
1970 TOOLTIPS_TrackPosition (HWND hwnd, WPARAM wParam, LPARAM lParam)
1972 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1974 infoPtr->xTrackPos = (INT)LOWORD(lParam);
1975 infoPtr->yTrackPos = (INT)HIWORD(lParam);
1977 if (infoPtr->bTrackActive) {
1979 infoPtr->xTrackPos, infoPtr->yTrackPos);
1981 TOOLTIPS_TrackShow (hwnd, infoPtr);
1989 TOOLTIPS_Update (HWND hwnd, WPARAM wParam, LPARAM lParam)
1991 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1993 if (infoPtr->nCurrentTool != -1)
1994 UpdateWindow (hwnd);
2001 TOOLTIPS_UpdateTipTextA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2003 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
2004 LPTTTOOLINFOA lpToolInfo = (LPTTTOOLINFOA)lParam;
2005 TTTOOL_INFO *toolPtr;
2008 if (lpToolInfo == NULL)
2010 if (lpToolInfo->cbSize < TTTOOLINFOA_V1_SIZE)
2013 nTool = TOOLTIPS_GetToolFromInfoA (infoPtr, lpToolInfo);
2014 if (nTool == -1) return 0;
2016 TRACE("tool %d\n", nTool);
2018 toolPtr = &infoPtr->tools[nTool];
2020 /* copy tool text */
2021 toolPtr->hinst = lpToolInfo->hinst;
2023 if (HIWORD(lpToolInfo->lpszText) == 0){
2024 toolPtr->lpszText = (LPWSTR)lpToolInfo->lpszText;
2026 else if (lpToolInfo->lpszText) {
2027 if (lpToolInfo->lpszText == LPSTR_TEXTCALLBACKA)
2028 toolPtr->lpszText = LPSTR_TEXTCALLBACKW;
2030 if ( (toolPtr->lpszText) &&
2031 (HIWORD((INT)toolPtr->lpszText) != 0) ) {
2032 Free (toolPtr->lpszText);
2033 toolPtr->lpszText = NULL;
2035 if (lpToolInfo->lpszText) {
2036 INT len = MultiByteToWideChar(CP_ACP, 0, lpToolInfo->lpszText,
2038 toolPtr->lpszText = Alloc (len * sizeof(WCHAR));
2039 MultiByteToWideChar(CP_ACP, 0, lpToolInfo->lpszText, -1,
2040 toolPtr->lpszText, len);
2045 if(infoPtr->nCurrentTool == -1) return 0;
2047 if (infoPtr->bActive)
2048 TOOLTIPS_Show (hwnd, infoPtr);
2049 else if (infoPtr->bTrackActive)
2050 TOOLTIPS_TrackShow (hwnd, infoPtr);
2057 TOOLTIPS_UpdateTipTextW (HWND hwnd, WPARAM wParam, LPARAM lParam)
2059 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
2060 LPTTTOOLINFOW lpToolInfo = (LPTTTOOLINFOW)lParam;
2061 TTTOOL_INFO *toolPtr;
2064 if (lpToolInfo == NULL)
2066 if (lpToolInfo->cbSize < TTTOOLINFOW_V1_SIZE)
2069 nTool = TOOLTIPS_GetToolFromInfoW (infoPtr, lpToolInfo);
2073 TRACE("tool %d\n", nTool);
2075 toolPtr = &infoPtr->tools[nTool];
2077 /* copy tool text */
2078 toolPtr->hinst = lpToolInfo->hinst;
2080 if (HIWORD(lpToolInfo->lpszText) == 0){
2081 toolPtr->lpszText = lpToolInfo->lpszText;
2083 else if (lpToolInfo->lpszText) {
2084 if (lpToolInfo->lpszText == LPSTR_TEXTCALLBACKW)
2085 toolPtr->lpszText = LPSTR_TEXTCALLBACKW;
2087 if ( (toolPtr->lpszText) &&
2088 (HIWORD((INT)toolPtr->lpszText) != 0) ) {
2089 Free (toolPtr->lpszText);
2090 toolPtr->lpszText = NULL;
2092 if (lpToolInfo->lpszText) {
2093 INT len = lstrlenW (lpToolInfo->lpszText);
2094 toolPtr->lpszText = Alloc ((len+1)*sizeof(WCHAR));
2095 strcpyW (toolPtr->lpszText, lpToolInfo->lpszText);
2100 if(infoPtr->nCurrentTool == -1) return 0;
2102 if (infoPtr->bActive)
2103 TOOLTIPS_Show (hwnd, infoPtr);
2104 else if (infoPtr->bTrackActive)
2105 TOOLTIPS_TrackShow (hwnd, infoPtr);
2112 TOOLTIPS_WindowFromPoint (HWND hwnd, WPARAM wParam, LPARAM lParam)
2114 return (LRESULT)WindowFromPoint (*((LPPOINT)lParam));
2120 TOOLTIPS_Create (HWND hwnd, const CREATESTRUCTW *lpcs)
2122 TOOLTIPS_INFO *infoPtr;
2123 NONCLIENTMETRICSA nclm;
2125 /* allocate memory for info structure */
2126 infoPtr = (TOOLTIPS_INFO *)Alloc (sizeof(TOOLTIPS_INFO));
2127 SetWindowLongA (hwnd, 0, (DWORD)infoPtr);
2129 /* initialize info structure */
2130 infoPtr->bActive = TRUE;
2131 infoPtr->bTrackActive = FALSE;
2132 infoPtr->clrBk = GetSysColor (COLOR_INFOBK);
2133 infoPtr->clrText = GetSysColor (COLOR_INFOTEXT);
2135 nclm.cbSize = sizeof(NONCLIENTMETRICSA);
2136 SystemParametersInfoA (SPI_GETNONCLIENTMETRICS, 0, &nclm, 0);
2137 infoPtr->hFont = CreateFontIndirectA (&nclm.lfStatusFont);
2139 infoPtr->nMaxTipWidth = -1;
2140 infoPtr->nTool = -1;
2141 infoPtr->nCurrentTool = -1;
2142 infoPtr->nTrackTool = -1;
2144 TOOLTIPS_SetDelayTime(hwnd, TTDT_AUTOMATIC, 0L);
2146 SetWindowPos (hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOZORDER | SWP_HIDEWINDOW | SWP_NOACTIVATE);
2153 TOOLTIPS_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
2155 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
2156 TTTOOL_INFO *toolPtr;
2160 if (infoPtr->tools) {
2161 for (i = 0; i < infoPtr->uNumTools; i++) {
2162 toolPtr = &infoPtr->tools[i];
2163 if (toolPtr->lpszText) {
2164 if ( (toolPtr->lpszText != LPSTR_TEXTCALLBACKW) &&
2165 (HIWORD((INT)toolPtr->lpszText) != 0) )
2167 Free (toolPtr->lpszText);
2168 toolPtr->lpszText = NULL;
2172 /* remove subclassing */
2173 if (toolPtr->uFlags & TTF_SUBCLASS) {
2174 if (toolPtr->uFlags & TTF_IDISHWND) {
2175 RemoveWindowSubclass((HWND)toolPtr->uId, TOOLTIPS_SubclassProc, 1);
2178 RemoveWindowSubclass(toolPtr->hwnd, TOOLTIPS_SubclassProc, 1);
2182 Free (infoPtr->tools);
2186 DeleteObject (infoPtr->hFont);
2188 /* free tool tips info data */
2190 SetWindowLongA(hwnd, 0, 0);
2196 TOOLTIPS_GetFont (HWND hwnd, WPARAM wParam, LPARAM lParam)
2198 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
2200 return (LRESULT)infoPtr->hFont;
2205 TOOLTIPS_MouseMessage (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2207 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
2209 TOOLTIPS_Hide (hwnd, infoPtr);
2216 TOOLTIPS_NCCreate (HWND hwnd, WPARAM wParam, LPARAM lParam)
2218 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
2219 DWORD dwExStyle = GetWindowLongA (hwnd, GWL_EXSTYLE);
2221 dwStyle &= 0x0000FFFF;
2222 dwStyle |= (WS_POPUP | WS_BORDER | WS_CLIPSIBLINGS);
2224 /* WS_BORDER only draws a border round the window rect, not the
2225 * window region, therefore it is useless to us in balloon mode */
2226 if (dwStyle & TTS_BALLOON) dwStyle &= ~WS_BORDER;
2228 SetWindowLongA (hwnd, GWL_STYLE, dwStyle);
2230 dwExStyle |= WS_EX_TOOLWINDOW;
2231 SetWindowLongA (hwnd, GWL_EXSTYLE, dwExStyle);
2238 TOOLTIPS_NCHitTest (HWND hwnd, WPARAM wParam, LPARAM lParam)
2240 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
2241 INT nTool = (infoPtr->bTrackActive) ? infoPtr->nTrackTool : infoPtr->nTool;
2243 TRACE(" nTool=%d\n", nTool);
2245 if ((nTool > -1) && (nTool < infoPtr->uNumTools)) {
2246 if (infoPtr->tools[nTool].uFlags & TTF_TRANSPARENT) {
2247 TRACE("-- in transparent mode!\n");
2248 return HTTRANSPARENT;
2252 return DefWindowProcA (hwnd, WM_NCHITTEST, wParam, lParam);
2257 TOOLTIPS_NotifyFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
2259 FIXME ("hwnd=%p wParam=%x lParam=%lx\n", hwnd, wParam, lParam);
2266 TOOLTIPS_Paint (HWND hwnd, WPARAM wParam, LPARAM lParam)
2271 hdc = (wParam == 0) ? BeginPaint (hwnd, &ps) : (HDC)wParam;
2272 TOOLTIPS_Refresh (hwnd, hdc);
2274 EndPaint (hwnd, &ps);
2280 TOOLTIPS_SetFont (HWND hwnd, WPARAM wParam, LPARAM lParam)
2282 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
2285 if(!GetObjectW((HFONT)wParam, sizeof(lf), &lf))
2288 if(infoPtr->hFont) DeleteObject (infoPtr->hFont);
2289 infoPtr->hFont = CreateFontIndirectW(&lf);
2291 if ((LOWORD(lParam)) & (infoPtr->nCurrentTool != -1)) {
2292 FIXME("full redraw needed!\n");
2297 /******************************************************************
2298 * TOOLTIPS_OnWMGetTextLength
2300 * This function is called when the tooltip receive a
2301 * WM_GETTEXTLENGTH message.
2305 * returns the length, in characters, of the tip text
2306 ******************************************************************/
2308 TOOLTIPS_OnWMGetTextLength(HWND hwnd, WPARAM wParam, LPARAM lParam)
2310 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
2311 return lstrlenW(infoPtr->szTipText);
2314 /******************************************************************
2315 * TOOLTIPS_OnWMGetText
2317 * This function is called when the tooltip receive a
2318 * WM_GETTEXT message.
2319 * wParam : specifies the maximum number of characters to be copied
2320 * lParam : is the pointer to the buffer that will receive
2323 * returns the number of characters copied
2324 ******************************************************************/
2326 TOOLTIPS_OnWMGetText (HWND hwnd, WPARAM wParam, LPARAM lParam)
2328 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
2330 if(!infoPtr || !(infoPtr->szTipText))
2333 return WideCharToMultiByte(CP_ACP, 0, infoPtr->szTipText, -1,
2334 (LPSTR)lParam, wParam, NULL, NULL);
2338 TOOLTIPS_Timer (HWND hwnd, WPARAM wParam, LPARAM lParam)
2340 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
2343 TRACE("timer %d (%p) expired!\n", wParam, hwnd);
2347 KillTimer (hwnd, ID_TIMERSHOW);
2348 nOldTool = infoPtr->nTool;
2349 if ((infoPtr->nTool = TOOLTIPS_CheckTool (hwnd, TRUE)) == nOldTool)
2350 TOOLTIPS_Show (hwnd, infoPtr);
2354 TOOLTIPS_Hide (hwnd, infoPtr);
2358 nOldTool = infoPtr->nTool;
2359 infoPtr->nTool = TOOLTIPS_CheckTool (hwnd, FALSE);
2360 TRACE("tool (%p) %d %d %d\n", hwnd, nOldTool,
2361 infoPtr->nTool, infoPtr->nCurrentTool);
2362 if (infoPtr->nTool != nOldTool) {
2363 if(infoPtr->nTool == -1) { /* Moved out of all tools */
2364 TOOLTIPS_Hide(hwnd, infoPtr);
2365 KillTimer(hwnd, ID_TIMERLEAVE);
2366 } else if (nOldTool == -1) { /* Moved from outside */
2367 ERR("How did this happen?\n");
2368 } else { /* Moved from one to another */
2369 TOOLTIPS_Hide (hwnd, infoPtr);
2370 KillTimer(hwnd, ID_TIMERLEAVE);
2371 if(infoPtr->bActive) {
2372 SetTimer (hwnd, ID_TIMERSHOW, infoPtr->nReshowTime, 0);
2373 TRACE("timer 1 started!\n");
2380 ERR("Unknown timer id %d\n", wParam);
2388 TOOLTIPS_WinIniChange (HWND hwnd, WPARAM wParam, LPARAM lParam)
2390 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
2391 NONCLIENTMETRICSA nclm;
2393 infoPtr->clrBk = GetSysColor (COLOR_INFOBK);
2394 infoPtr->clrText = GetSysColor (COLOR_INFOTEXT);
2396 DeleteObject (infoPtr->hFont);
2397 nclm.cbSize = sizeof(NONCLIENTMETRICSA);
2398 SystemParametersInfoA (SPI_GETNONCLIENTMETRICS, 0, &nclm, 0);
2399 infoPtr->hFont = CreateFontIndirectA (&nclm.lfStatusFont);
2406 TOOLTIPS_SubclassProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uID, DWORD_PTR dwRef)
2412 case WM_LBUTTONDOWN:
2414 case WM_MBUTTONDOWN:
2416 case WM_RBUTTONDOWN:
2420 msg.wParam = wParam;
2421 msg.lParam = lParam;
2422 TOOLTIPS_RelayEvent((HWND)dwRef, 0, (LPARAM)&msg);
2428 return DefSubclassProc(hwnd, uMsg, wParam, lParam);
2432 static LRESULT CALLBACK
2433 TOOLTIPS_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2435 TRACE("hwnd=%p msg=%x wparam=%x lParam=%lx\n", hwnd, uMsg, wParam, lParam);
2436 if (!TOOLTIPS_GetInfoPtr(hwnd) && (uMsg != WM_CREATE) && (uMsg != WM_NCCREATE))
2437 return DefWindowProcA (hwnd, uMsg, wParam, lParam);
2441 return TOOLTIPS_Activate (hwnd, wParam, lParam);
2444 return TOOLTIPS_AddToolA (hwnd, wParam, lParam);
2447 return TOOLTIPS_AddToolW (hwnd, wParam, lParam);
2450 return TOOLTIPS_DelToolA (hwnd, wParam, lParam);
2453 return TOOLTIPS_DelToolW (hwnd, wParam, lParam);
2455 case TTM_ENUMTOOLSA:
2456 return TOOLTIPS_EnumToolsA (hwnd, wParam, lParam);
2458 case TTM_ENUMTOOLSW:
2459 return TOOLTIPS_EnumToolsW (hwnd, wParam, lParam);
2461 case TTM_GETBUBBLESIZE:
2462 return TOOLTIPS_GetBubbleSize (hwnd, wParam, lParam);
2464 case TTM_GETCURRENTTOOLA:
2465 return TOOLTIPS_GetCurrentToolA (hwnd, wParam, lParam);
2467 case TTM_GETCURRENTTOOLW:
2468 return TOOLTIPS_GetCurrentToolW (hwnd, wParam, lParam);
2470 case TTM_GETDELAYTIME:
2471 return TOOLTIPS_GetDelayTime (hwnd, wParam, lParam);
2474 return TOOLTIPS_GetMargin (hwnd, wParam, lParam);
2476 case TTM_GETMAXTIPWIDTH:
2477 return TOOLTIPS_GetMaxTipWidth (hwnd, wParam, lParam);
2480 return TOOLTIPS_GetTextA (hwnd, wParam, lParam);
2483 return TOOLTIPS_GetTextW (hwnd, wParam, lParam);
2485 case TTM_GETTIPBKCOLOR:
2486 return TOOLTIPS_GetTipBkColor (hwnd, wParam, lParam);
2488 case TTM_GETTIPTEXTCOLOR:
2489 return TOOLTIPS_GetTipTextColor (hwnd, wParam, lParam);
2491 case TTM_GETTOOLCOUNT:
2492 return TOOLTIPS_GetToolCount (hwnd, wParam, lParam);
2494 case TTM_GETTOOLINFOA:
2495 return TOOLTIPS_GetToolInfoA (hwnd, wParam, lParam);
2497 case TTM_GETTOOLINFOW:
2498 return TOOLTIPS_GetToolInfoW (hwnd, wParam, lParam);
2501 return TOOLTIPS_HitTestA (hwnd, wParam, lParam);
2504 return TOOLTIPS_HitTestW (hwnd, wParam, lParam);
2506 case TTM_NEWTOOLRECTA:
2507 return TOOLTIPS_NewToolRectA (hwnd, wParam, lParam);
2509 case TTM_NEWTOOLRECTW:
2510 return TOOLTIPS_NewToolRectW (hwnd, wParam, lParam);
2513 return TOOLTIPS_Pop (hwnd, wParam, lParam);
2515 case TTM_RELAYEVENT:
2516 return TOOLTIPS_RelayEvent (hwnd, wParam, lParam);
2518 case TTM_SETDELAYTIME:
2519 return TOOLTIPS_SetDelayTime (hwnd, wParam, lParam);
2522 return TOOLTIPS_SetMargin (hwnd, wParam, lParam);
2524 case TTM_SETMAXTIPWIDTH:
2525 return TOOLTIPS_SetMaxTipWidth (hwnd, wParam, lParam);
2527 case TTM_SETTIPBKCOLOR:
2528 return TOOLTIPS_SetTipBkColor (hwnd, wParam, lParam);
2530 case TTM_SETTIPTEXTCOLOR:
2531 return TOOLTIPS_SetTipTextColor (hwnd, wParam, lParam);
2533 case TTM_SETTOOLINFOA:
2534 return TOOLTIPS_SetToolInfoA (hwnd, wParam, lParam);
2536 case TTM_SETTOOLINFOW:
2537 return TOOLTIPS_SetToolInfoW (hwnd, wParam, lParam);
2539 case TTM_TRACKACTIVATE:
2540 return TOOLTIPS_TrackActivate (hwnd, wParam, lParam);
2542 case TTM_TRACKPOSITION:
2543 return TOOLTIPS_TrackPosition (hwnd, wParam, lParam);
2546 return TOOLTIPS_Update (hwnd, wParam, lParam);
2548 case TTM_UPDATETIPTEXTA:
2549 return TOOLTIPS_UpdateTipTextA (hwnd, wParam, lParam);
2551 case TTM_UPDATETIPTEXTW:
2552 return TOOLTIPS_UpdateTipTextW (hwnd, wParam, lParam);
2554 case TTM_WINDOWFROMPOINT:
2555 return TOOLTIPS_WindowFromPoint (hwnd, wParam, lParam);
2559 return TOOLTIPS_Create (hwnd, (LPCREATESTRUCTW)lParam);
2562 return TOOLTIPS_Destroy (hwnd, wParam, lParam);
2565 /* we draw the background in WM_PAINT */
2569 return TOOLTIPS_GetFont (hwnd, wParam, lParam);
2572 return TOOLTIPS_OnWMGetText (hwnd, wParam, lParam);
2574 case WM_GETTEXTLENGTH:
2575 return TOOLTIPS_OnWMGetTextLength (hwnd, wParam, lParam);
2578 case WM_LBUTTONDOWN:
2580 case WM_MBUTTONDOWN:
2582 case WM_RBUTTONDOWN:
2585 return TOOLTIPS_MouseMessage (hwnd, uMsg, wParam, lParam);
2588 return TOOLTIPS_NCCreate (hwnd, wParam, lParam);
2591 return TOOLTIPS_NCHitTest (hwnd, wParam, lParam);
2593 case WM_NOTIFYFORMAT:
2594 return TOOLTIPS_NotifyFormat (hwnd, wParam, lParam);
2597 return TOOLTIPS_Paint (hwnd, wParam, lParam);
2600 return TOOLTIPS_SetFont (hwnd, wParam, lParam);
2603 return TOOLTIPS_Timer (hwnd, wParam, lParam);
2605 case WM_WININICHANGE:
2606 return TOOLTIPS_WinIniChange (hwnd, wParam, lParam);
2609 if ((uMsg >= WM_USER) && (uMsg < WM_APP))
2610 ERR("unknown msg %04x wp=%08x lp=%08lx\n",
2611 uMsg, wParam, lParam);
2612 return DefWindowProcA (hwnd, uMsg, wParam, lParam);
2619 TOOLTIPS_Register (void)
2623 ZeroMemory (&wndClass, sizeof(WNDCLASSA));
2624 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS | CS_SAVEBITS;
2625 wndClass.lpfnWndProc = (WNDPROC)TOOLTIPS_WindowProc;
2626 wndClass.cbClsExtra = 0;
2627 wndClass.cbWndExtra = sizeof(TOOLTIPS_INFO *);
2628 wndClass.hCursor = LoadCursorA (0, (LPSTR)IDC_ARROW);
2629 wndClass.hbrBackground = 0;
2630 wndClass.lpszClassName = TOOLTIPS_CLASSA;
2632 RegisterClassA (&wndClass);
2637 TOOLTIPS_Unregister (void)
2639 UnregisterClassA (TOOLTIPS_CLASSA, NULL);