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 */
126 #define ID_TIMERSHOW 1 /* show delay timer */
127 #define ID_TIMERPOP 2 /* auto pop timer */
128 #define ID_TIMERLEAVE 3 /* tool leave timer */
131 #define TOOLTIPS_GetInfoPtr(hWindow) ((TOOLTIPS_INFO *)GetWindowLongA (hWindow, 0))
133 /* offsets from window edge to start of text */
134 #define NORMAL_TEXT_MARGIN 2
135 #define BALLOON_TEXT_MARGIN (NORMAL_TEXT_MARGIN+10)
136 /* value used for CreateRoundRectRgn that specifies how much
137 * each corner is curved */
138 #define BALLOON_ROUNDEDNESS 20
141 TOOLTIPS_SubclassProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uId, DWORD_PTR dwRef);
145 TOOLTIPS_Refresh (HWND hwnd, HDC hdc)
147 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr(hwnd);
152 UINT uFlags = DT_EXTERNALLEADING;
154 DWORD dwStyle = GetWindowLongW(hwnd, GWL_STYLE);
156 if (infoPtr->nMaxTipWidth > -1)
157 uFlags |= DT_WORDBREAK;
158 if (GetWindowLongA (hwnd, GWL_STYLE) & TTS_NOPREFIX)
159 uFlags |= DT_NOPREFIX;
160 GetClientRect (hwnd, &rc);
162 hBrush = CreateSolidBrush(infoPtr->clrBk);
164 if (dwStyle & TTS_BALLOON)
166 /* create a region to store result into */
167 hRgn = CreateRectRgn(0, 0, 0, 0);
169 GetWindowRgn(hwnd, hRgn);
171 /* fill the background */
172 FillRgn(hdc, hRgn, hBrush);
173 DeleteObject(hBrush);
176 /* calculate text rectangle */
177 rc.left += (BALLOON_TEXT_MARGIN + infoPtr->rcMargin.left);
178 rc.top += (BALLOON_TEXT_MARGIN + infoPtr->rcMargin.top);
179 rc.right -= (BALLOON_TEXT_MARGIN + infoPtr->rcMargin.right);
180 rc.bottom -= (BALLOON_TEXT_MARGIN + infoPtr->rcMargin.bottom);
184 /* fill the background */
185 FillRect(hdc, &rc, hBrush);
186 DeleteObject(hBrush);
189 /* calculate text rectangle */
190 rc.left += (NORMAL_TEXT_MARGIN + infoPtr->rcMargin.left);
191 rc.top += (NORMAL_TEXT_MARGIN + infoPtr->rcMargin.top);
192 rc.right -= (NORMAL_TEXT_MARGIN + infoPtr->rcMargin.right);
193 rc.bottom -= (NORMAL_TEXT_MARGIN + infoPtr->rcMargin.bottom);
196 /* already drawn the background; don't need to draw it again
197 * when drawing text */
198 oldBkMode = SetBkMode (hdc, TRANSPARENT);
199 SetTextColor (hdc, infoPtr->clrText);
200 hOldFont = SelectObject (hdc, infoPtr->hFont);
202 DrawTextW (hdc, infoPtr->szTipText, -1, &rc, uFlags);
203 /* be polite and reset the things we changed in the dc */
204 SelectObject (hdc, hOldFont);
205 SetBkMode (hdc, oldBkMode);
207 if (dwStyle & TTS_BALLOON)
209 /* frame region because default window proc doesn't do it */
210 INT width = GetSystemMetrics(SM_CXDLGFRAME) - GetSystemMetrics(SM_CXEDGE);
211 INT height = GetSystemMetrics(SM_CYDLGFRAME) - GetSystemMetrics(SM_CYEDGE);
213 hBrush = GetSysColorBrush(COLOR_WINDOWFRAME);
214 FrameRgn(hdc, hRgn, hBrush, width, height);
221 static void TOOLTIPS_GetDispInfoA(HWND hwnd, TOOLTIPS_INFO *infoPtr, TTTOOL_INFO *toolPtr)
223 NMTTDISPINFOA ttnmdi;
225 /* fill NMHDR struct */
226 ZeroMemory (&ttnmdi, sizeof(NMTTDISPINFOA));
227 ttnmdi.hdr.hwndFrom = hwnd;
228 ttnmdi.hdr.idFrom = toolPtr->uId;
229 ttnmdi.hdr.code = TTN_GETDISPINFOA;
230 ttnmdi.lpszText = (LPSTR)&ttnmdi.szText;
231 ttnmdi.uFlags = toolPtr->uFlags;
232 ttnmdi.lParam = toolPtr->lParam;
234 TRACE("hdr.idFrom = %x\n", ttnmdi.hdr.idFrom);
235 SendMessageA(toolPtr->hwnd, WM_NOTIFY,
236 (WPARAM)toolPtr->uId, (LPARAM)&ttnmdi);
238 if (HIWORD((UINT)ttnmdi.lpszText) == 0) {
239 LoadStringW(ttnmdi.hinst, (UINT)ttnmdi.lpszText,
240 infoPtr->szTipText, INFOTIPSIZE);
241 if (ttnmdi.uFlags & TTF_DI_SETITEM) {
242 toolPtr->hinst = ttnmdi.hinst;
243 toolPtr->lpszText = (LPWSTR)ttnmdi.lpszText;
246 else if (ttnmdi.lpszText == 0) {
247 /* no text available */
248 infoPtr->szTipText[0] = '\0';
250 else if (ttnmdi.lpszText != LPSTR_TEXTCALLBACKA) {
251 INT max_len = (ttnmdi.lpszText == &ttnmdi.szText[0]) ?
252 sizeof(ttnmdi.szText)/sizeof(ttnmdi.szText[0]) : -1;
253 MultiByteToWideChar(CP_ACP, 0, ttnmdi.lpszText, max_len,
254 infoPtr->szTipText, INFOTIPSIZE);
255 if (ttnmdi.uFlags & TTF_DI_SETITEM) {
256 INT len = MultiByteToWideChar(CP_ACP, 0, ttnmdi.lpszText,
259 toolPtr->lpszText = Alloc (len * sizeof(WCHAR));
260 MultiByteToWideChar(CP_ACP, 0, ttnmdi.lpszText, -1,
261 toolPtr->lpszText, len);
265 ERR("recursive text callback!\n");
266 infoPtr->szTipText[0] = '\0';
270 static void TOOLTIPS_GetDispInfoW(HWND hwnd, TOOLTIPS_INFO *infoPtr, TTTOOL_INFO *toolPtr)
272 NMTTDISPINFOW ttnmdi;
274 /* fill NMHDR struct */
275 ZeroMemory (&ttnmdi, sizeof(NMTTDISPINFOW));
276 ttnmdi.hdr.hwndFrom = hwnd;
277 ttnmdi.hdr.idFrom = toolPtr->uId;
278 ttnmdi.hdr.code = TTN_GETDISPINFOW;
279 ttnmdi.lpszText = (LPWSTR)&ttnmdi.szText;
280 ttnmdi.uFlags = toolPtr->uFlags;
281 ttnmdi.lParam = toolPtr->lParam;
283 TRACE("hdr.idFrom = %x\n", ttnmdi.hdr.idFrom);
284 SendMessageW(toolPtr->hwnd, WM_NOTIFY,
285 (WPARAM)toolPtr->uId, (LPARAM)&ttnmdi);
287 if (HIWORD((UINT)ttnmdi.lpszText) == 0) {
288 LoadStringW(ttnmdi.hinst, (UINT)ttnmdi.lpszText,
289 infoPtr->szTipText, INFOTIPSIZE);
290 if (ttnmdi.uFlags & TTF_DI_SETITEM) {
291 toolPtr->hinst = ttnmdi.hinst;
292 toolPtr->lpszText = ttnmdi.lpszText;
295 else if (ttnmdi.lpszText == 0) {
296 /* no text available */
297 infoPtr->szTipText[0] = '\0';
299 else if (ttnmdi.lpszText != LPSTR_TEXTCALLBACKW) {
300 INT max_len = (ttnmdi.lpszText == &ttnmdi.szText[0]) ?
301 sizeof(ttnmdi.szText)/sizeof(ttnmdi.szText[0]) : INFOTIPSIZE-1;
302 strncpyW(infoPtr->szTipText, ttnmdi.lpszText, max_len);
303 if (ttnmdi.uFlags & TTF_DI_SETITEM) {
304 INT len = max(strlenW(ttnmdi.lpszText), max_len);
306 toolPtr->lpszText = Alloc ((len+1) * sizeof(WCHAR));
307 memcpy(toolPtr->lpszText, ttnmdi.lpszText, (len+1) * sizeof(WCHAR));
311 ERR("recursive text callback!\n");
312 infoPtr->szTipText[0] = '\0';
317 TOOLTIPS_GetTipText (HWND hwnd, TOOLTIPS_INFO *infoPtr, INT nTool)
319 TTTOOL_INFO *toolPtr = &infoPtr->tools[nTool];
321 if (HIWORD((UINT)toolPtr->lpszText) == 0) {
322 /* load a resource */
323 TRACE("load res string %p %x\n",
324 toolPtr->hinst, (int)toolPtr->lpszText);
325 LoadStringW (toolPtr->hinst, (UINT)toolPtr->lpszText,
326 infoPtr->szTipText, INFOTIPSIZE);
328 else if (toolPtr->lpszText) {
329 if (toolPtr->lpszText == LPSTR_TEXTCALLBACKW) {
330 if (toolPtr->bNotifyUnicode)
331 TOOLTIPS_GetDispInfoW(hwnd, infoPtr, toolPtr);
333 TOOLTIPS_GetDispInfoA(hwnd, infoPtr, toolPtr);
336 /* the item is a usual (unicode) text */
337 lstrcpynW (infoPtr->szTipText, toolPtr->lpszText, INFOTIPSIZE);
341 /* no text available */
342 infoPtr->szTipText[0] = L'\0';
345 TRACE("%s\n", debugstr_w(infoPtr->szTipText));
350 TOOLTIPS_CalcTipSize (HWND hwnd, TOOLTIPS_INFO *infoPtr, LPSIZE lpSize)
354 UINT uFlags = DT_EXTERNALLEADING | DT_CALCRECT;
355 RECT rc = {0, 0, 0, 0};
357 if (infoPtr->nMaxTipWidth > -1) {
358 rc.right = infoPtr->nMaxTipWidth;
359 uFlags |= DT_WORDBREAK;
361 if (GetWindowLongA (hwnd, GWL_STYLE) & TTS_NOPREFIX)
362 uFlags |= DT_NOPREFIX;
363 TRACE("%s\n", debugstr_w(infoPtr->szTipText));
366 hOldFont = SelectObject (hdc, infoPtr->hFont);
367 DrawTextW (hdc, infoPtr->szTipText, -1, &rc, uFlags);
368 SelectObject (hdc, hOldFont);
369 ReleaseDC (hwnd, hdc);
371 if (GetWindowLongW(hwnd, GWL_STYLE) & TTS_BALLOON)
373 lpSize->cx = rc.right - rc.left + 2*BALLOON_TEXT_MARGIN +
374 infoPtr->rcMargin.left + infoPtr->rcMargin.right;
375 lpSize->cy = rc.bottom - rc.top + 2*BALLOON_TEXT_MARGIN +
376 infoPtr->rcMargin.bottom + infoPtr->rcMargin.top;
380 lpSize->cx = rc.right - rc.left + 2*NORMAL_TEXT_MARGIN +
381 infoPtr->rcMargin.left + infoPtr->rcMargin.right;
382 lpSize->cy = rc.bottom - rc.top + 2*NORMAL_TEXT_MARGIN +
383 infoPtr->rcMargin.bottom + infoPtr->rcMargin.top;
389 TOOLTIPS_Show (HWND hwnd, TOOLTIPS_INFO *infoPtr)
391 TTTOOL_INFO *toolPtr;
396 if (infoPtr->nTool == -1) {
397 TRACE("invalid tool (-1)!\n");
401 infoPtr->nCurrentTool = infoPtr->nTool;
403 TRACE("Show tooltip pre %d! (%p)\n", infoPtr->nTool, hwnd);
405 TOOLTIPS_GetTipText (hwnd, infoPtr, infoPtr->nCurrentTool);
407 if (infoPtr->szTipText[0] == L'\0') {
408 infoPtr->nCurrentTool = -1;
412 TRACE("Show tooltip %d!\n", infoPtr->nCurrentTool);
413 toolPtr = &infoPtr->tools[infoPtr->nCurrentTool];
416 hdr.idFrom = toolPtr->uId;
418 SendMessageA (toolPtr->hwnd, WM_NOTIFY,
419 (WPARAM)toolPtr->uId, (LPARAM)&hdr);
421 TRACE("%s\n", debugstr_w(infoPtr->szTipText));
423 TOOLTIPS_CalcTipSize (hwnd, infoPtr, &size);
424 TRACE("size %ld x %ld\n", size.cx, size.cy);
426 if (toolPtr->uFlags & TTF_CENTERTIP) {
429 if (toolPtr->uFlags & TTF_IDISHWND)
430 GetWindowRect ((HWND)toolPtr->uId, &rc);
433 MapWindowPoints (toolPtr->hwnd, NULL, (LPPOINT)&rc, 2);
435 rect.left = (rc.left + rc.right - size.cx) / 2;
436 rect.top = rc.bottom + 2;
439 GetCursorPos ((LPPOINT)&rect);
443 TRACE("pos %ld - %ld\n", rect.left, rect.top);
445 rect.right = rect.left + size.cx;
446 rect.bottom = rect.top + size.cy;
449 wndrect.right = GetSystemMetrics( SM_CXSCREEN );
450 if( rect.right > wndrect.right ) {
451 rect.left -= rect.right - wndrect.right + 2;
452 rect.right = wndrect.right - 2;
454 wndrect.bottom = GetSystemMetrics( SM_CYSCREEN );
455 if( rect.bottom > wndrect.bottom ) {
458 if (toolPtr->uFlags & TTF_IDISHWND)
459 GetWindowRect ((HWND)toolPtr->uId, &rc);
462 MapWindowPoints (toolPtr->hwnd, NULL, (LPPOINT)&rc, 2);
464 rect.bottom = rc.top - 2;
465 rect.top = rect.bottom - size.cy;
468 AdjustWindowRectEx (&rect, GetWindowLongA (hwnd, GWL_STYLE),
469 FALSE, GetWindowLongA (hwnd, GWL_EXSTYLE));
471 if (GetWindowLongW(hwnd, GWL_STYLE) & TTS_BALLOON)
475 /* FIXME: need to add pointy bit using CreatePolyRgn & CombinRgn */
476 hRgn = CreateRoundRectRgn(0, 0, rect.right - rect.left, rect.bottom - rect.top, BALLOON_ROUNDEDNESS, BALLOON_ROUNDEDNESS);
478 SetWindowRgn(hwnd, hRgn, FALSE);
479 /* we don't free the region handle as the system deletes it when
480 * it is no longer needed */
483 SetWindowPos (hwnd, HWND_TOP, rect.left, rect.top,
484 rect.right - rect.left, rect.bottom - rect.top,
485 SWP_SHOWWINDOW | SWP_NOACTIVATE);
487 /* repaint the tooltip */
488 InvalidateRect(hwnd, NULL, TRUE);
491 SetTimer (hwnd, ID_TIMERPOP, infoPtr->nAutoPopTime, 0);
492 TRACE("timer 2 started!\n");
493 SetTimer (hwnd, ID_TIMERLEAVE, infoPtr->nReshowTime, 0);
494 TRACE("timer 3 started!\n");
499 TOOLTIPS_Hide (HWND hwnd, TOOLTIPS_INFO *infoPtr)
501 TTTOOL_INFO *toolPtr;
504 TRACE("Hide tooltip %d! (%p)\n", infoPtr->nCurrentTool, hwnd);
506 if (infoPtr->nCurrentTool == -1)
509 toolPtr = &infoPtr->tools[infoPtr->nCurrentTool];
510 KillTimer (hwnd, ID_TIMERPOP);
513 hdr.idFrom = toolPtr->uId;
515 SendMessageA (toolPtr->hwnd, WM_NOTIFY,
516 (WPARAM)toolPtr->uId, (LPARAM)&hdr);
518 infoPtr->nCurrentTool = -1;
520 SetWindowPos (hwnd, HWND_TOP, 0, 0, 0, 0,
521 SWP_NOZORDER | SWP_HIDEWINDOW | SWP_NOACTIVATE);
526 TOOLTIPS_TrackShow (HWND hwnd, TOOLTIPS_INFO *infoPtr)
528 TTTOOL_INFO *toolPtr;
533 if (infoPtr->nTrackTool == -1) {
534 TRACE("invalid tracking tool (-1)!\n");
538 TRACE("show tracking tooltip pre %d!\n", infoPtr->nTrackTool);
540 TOOLTIPS_GetTipText (hwnd, infoPtr, infoPtr->nTrackTool);
542 if (infoPtr->szTipText[0] == L'\0') {
543 infoPtr->nTrackTool = -1;
547 TRACE("show tracking tooltip %d!\n", infoPtr->nTrackTool);
548 toolPtr = &infoPtr->tools[infoPtr->nTrackTool];
551 hdr.idFrom = toolPtr->uId;
553 SendMessageA (toolPtr->hwnd, WM_NOTIFY,
554 (WPARAM)toolPtr->uId, (LPARAM)&hdr);
556 TRACE("%s\n", debugstr_w(infoPtr->szTipText));
558 TOOLTIPS_CalcTipSize (hwnd, infoPtr, &size);
559 TRACE("size %ld x %ld\n", size.cx, size.cy);
561 if (toolPtr->uFlags & TTF_ABSOLUTE) {
562 rect.left = infoPtr->xTrackPos;
563 rect.top = infoPtr->yTrackPos;
565 if (toolPtr->uFlags & TTF_CENTERTIP) {
566 rect.left -= (size.cx / 2);
567 rect.top -= (size.cy / 2);
573 if (toolPtr->uFlags & TTF_IDISHWND)
574 GetWindowRect ((HWND)toolPtr->uId, &rcTool);
576 rcTool = toolPtr->rect;
577 MapWindowPoints (toolPtr->hwnd, NULL, (LPPOINT)&rcTool, 2);
580 GetCursorPos ((LPPOINT)&rect);
583 if (toolPtr->uFlags & TTF_CENTERTIP) {
584 rect.left -= (size.cx / 2);
585 rect.top -= (size.cy / 2);
588 /* smart placement */
589 if ((rect.left + size.cx > rcTool.left) && (rect.left < rcTool.right) &&
590 (rect.top + size.cy > rcTool.top) && (rect.top < rcTool.bottom))
591 rect.left = rcTool.right;
594 TRACE("pos %ld - %ld\n", rect.left, rect.top);
596 rect.right = rect.left + size.cx;
597 rect.bottom = rect.top + size.cy;
599 AdjustWindowRectEx (&rect, GetWindowLongA (hwnd, GWL_STYLE),
600 FALSE, GetWindowLongA (hwnd, GWL_EXSTYLE));
602 if (GetWindowLongW(hwnd, GWL_STYLE) & TTS_BALLOON)
606 /* FIXME: need to add pointy bit using CreatePolyRgn & CombinRgn */
607 hRgn = CreateRoundRectRgn(0, 0, rect.right - rect.left, rect.bottom - rect.top, BALLOON_ROUNDEDNESS, BALLOON_ROUNDEDNESS);
609 SetWindowRgn(hwnd, hRgn, FALSE);
610 /* we don't free the region handle as the system deletes it when
611 * it is no longer needed */
614 SetWindowPos (hwnd, HWND_TOP, rect.left, rect.top,
615 rect.right - rect.left, rect.bottom - rect.top,
616 SWP_SHOWWINDOW | SWP_NOACTIVATE );
618 InvalidateRect(hwnd, NULL, TRUE);
624 TOOLTIPS_TrackHide (HWND hwnd, TOOLTIPS_INFO *infoPtr)
626 TTTOOL_INFO *toolPtr;
629 TRACE("hide tracking tooltip %d\n", infoPtr->nTrackTool);
631 if (infoPtr->nTrackTool == -1)
634 toolPtr = &infoPtr->tools[infoPtr->nTrackTool];
637 hdr.idFrom = toolPtr->uId;
639 SendMessageA (toolPtr->hwnd, WM_NOTIFY,
640 (WPARAM)toolPtr->uId, (LPARAM)&hdr);
642 SetWindowPos (hwnd, HWND_TOP, 0, 0, 0, 0,
643 SWP_NOZORDER | SWP_HIDEWINDOW | SWP_NOACTIVATE);
648 TOOLTIPS_GetToolFromInfoA (TOOLTIPS_INFO *infoPtr, LPTTTOOLINFOA lpToolInfo)
650 TTTOOL_INFO *toolPtr;
653 for (nTool = 0; nTool < infoPtr->uNumTools; nTool++) {
654 toolPtr = &infoPtr->tools[nTool];
656 if (!(toolPtr->uFlags & TTF_IDISHWND) &&
657 (lpToolInfo->hwnd == toolPtr->hwnd) &&
658 (lpToolInfo->uId == toolPtr->uId))
662 for (nTool = 0; nTool < infoPtr->uNumTools; nTool++) {
663 toolPtr = &infoPtr->tools[nTool];
665 if ((toolPtr->uFlags & TTF_IDISHWND) &&
666 (lpToolInfo->uId == toolPtr->uId))
675 TOOLTIPS_GetToolFromInfoW (TOOLTIPS_INFO *infoPtr, LPTTTOOLINFOW lpToolInfo)
677 TTTOOL_INFO *toolPtr;
680 for (nTool = 0; nTool < infoPtr->uNumTools; nTool++) {
681 toolPtr = &infoPtr->tools[nTool];
683 if (!(toolPtr->uFlags & TTF_IDISHWND) &&
684 (lpToolInfo->hwnd == toolPtr->hwnd) &&
685 (lpToolInfo->uId == toolPtr->uId))
689 for (nTool = 0; nTool < infoPtr->uNumTools; nTool++) {
690 toolPtr = &infoPtr->tools[nTool];
692 if ((toolPtr->uFlags & TTF_IDISHWND) &&
693 (lpToolInfo->uId == toolPtr->uId))
702 TOOLTIPS_GetToolFromPoint (TOOLTIPS_INFO *infoPtr, HWND hwnd, LPPOINT lpPt)
704 TTTOOL_INFO *toolPtr;
707 for (nTool = 0; nTool < infoPtr->uNumTools; nTool++) {
708 toolPtr = &infoPtr->tools[nTool];
710 if (!(toolPtr->uFlags & TTF_IDISHWND)) {
711 if (hwnd != toolPtr->hwnd)
713 if (!PtInRect (&toolPtr->rect, *lpPt))
719 for (nTool = 0; nTool < infoPtr->uNumTools; nTool++) {
720 toolPtr = &infoPtr->tools[nTool];
722 if (toolPtr->uFlags & TTF_IDISHWND) {
723 if ((HWND)toolPtr->uId == hwnd)
733 TOOLTIPS_IsWindowActive (HWND hwnd)
735 HWND hwndActive = GetActiveWindow ();
738 if (hwndActive == hwnd)
740 return IsChild (hwndActive, hwnd);
745 TOOLTIPS_CheckTool (HWND hwnd, BOOL bShowTest)
747 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
753 hwndTool = (HWND)SendMessageA (hwnd, TTM_WINDOWFROMPOINT, 0, (LPARAM)&pt);
757 ScreenToClient (hwndTool, &pt);
758 nTool = TOOLTIPS_GetToolFromPoint (infoPtr, hwndTool, &pt);
762 if (!(GetWindowLongA (hwnd, GWL_STYLE) & TTS_ALWAYSTIP) && bShowTest) {
763 if (!TOOLTIPS_IsWindowActive (GetWindow (hwnd, GW_OWNER)))
767 TRACE("tool %d\n", nTool);
774 TOOLTIPS_Activate (HWND hwnd, WPARAM wParam, LPARAM lParam)
776 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
778 infoPtr->bActive = (BOOL)wParam;
780 if (infoPtr->bActive)
781 TRACE("activate!\n");
783 if (!(infoPtr->bActive) && (infoPtr->nCurrentTool != -1))
784 TOOLTIPS_Hide (hwnd, infoPtr);
791 TOOLTIPS_AddToolA (HWND hwnd, WPARAM wParam, LPARAM lParam)
793 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
794 LPTTTOOLINFOA lpToolInfo = (LPTTTOOLINFOA)lParam;
795 TTTOOL_INFO *toolPtr;
798 if (lpToolInfo == NULL)
800 if (lpToolInfo->cbSize < TTTOOLINFOA_V1_SIZE)
803 TRACE("add tool (%p) %p %d%s!\n",
804 hwnd, lpToolInfo->hwnd, lpToolInfo->uId,
805 (lpToolInfo->uFlags & TTF_IDISHWND) ? " TTF_IDISHWND" : "");
807 if (infoPtr->uNumTools == 0) {
808 infoPtr->tools = Alloc (sizeof(TTTOOL_INFO));
809 toolPtr = infoPtr->tools;
812 TTTOOL_INFO *oldTools = infoPtr->tools;
814 Alloc (sizeof(TTTOOL_INFO) * (infoPtr->uNumTools + 1));
815 memcpy (infoPtr->tools, oldTools,
816 infoPtr->uNumTools * sizeof(TTTOOL_INFO));
818 toolPtr = &infoPtr->tools[infoPtr->uNumTools];
821 infoPtr->uNumTools++;
824 toolPtr->uFlags = lpToolInfo->uFlags;
825 toolPtr->hwnd = lpToolInfo->hwnd;
826 toolPtr->uId = lpToolInfo->uId;
827 toolPtr->rect = lpToolInfo->rect;
828 toolPtr->hinst = lpToolInfo->hinst;
830 if (HIWORD(lpToolInfo->lpszText) == 0) {
831 TRACE("add string id %x!\n", (int)lpToolInfo->lpszText);
832 toolPtr->lpszText = (LPWSTR)lpToolInfo->lpszText;
834 else if (lpToolInfo->lpszText) {
835 if (lpToolInfo->lpszText == LPSTR_TEXTCALLBACKA) {
836 TRACE("add CALLBACK!\n");
837 toolPtr->lpszText = LPSTR_TEXTCALLBACKW;
840 INT len = MultiByteToWideChar(CP_ACP, 0, lpToolInfo->lpszText, -1,
842 TRACE("add text \"%s\"!\n", lpToolInfo->lpszText);
843 toolPtr->lpszText = Alloc (len * sizeof(WCHAR));
844 MultiByteToWideChar(CP_ACP, 0, lpToolInfo->lpszText, -1,
845 toolPtr->lpszText, len);
849 if (lpToolInfo->cbSize >= sizeof(TTTOOLINFOA))
850 toolPtr->lParam = lpToolInfo->lParam;
852 /* install subclassing hook */
853 if (toolPtr->uFlags & TTF_SUBCLASS) {
854 if (toolPtr->uFlags & TTF_IDISHWND) {
855 SetWindowSubclass((HWND)toolPtr->uId, TOOLTIPS_SubclassProc, 1,
859 SetWindowSubclass(toolPtr->hwnd, TOOLTIPS_SubclassProc, 1,
862 TRACE("subclassing installed!\n");
865 nResult = (INT) SendMessageA (toolPtr->hwnd, WM_NOTIFYFORMAT,
866 (WPARAM)hwnd, (LPARAM)NF_QUERY);
867 if (nResult == NFR_ANSI) {
868 toolPtr->bNotifyUnicode = FALSE;
869 TRACE(" -- WM_NOTIFYFORMAT returns: NFR_ANSI\n");
870 } else if (nResult == NFR_UNICODE) {
871 toolPtr->bNotifyUnicode = TRUE;
872 TRACE(" -- WM_NOTIFYFORMAT returns: NFR_UNICODE\n");
874 TRACE (" -- WM_NOTIFYFORMAT returns: error!\n");
882 TOOLTIPS_AddToolW (HWND hwnd, WPARAM wParam, LPARAM lParam)
884 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
885 LPTTTOOLINFOW lpToolInfo = (LPTTTOOLINFOW)lParam;
886 TTTOOL_INFO *toolPtr;
889 if (lpToolInfo == NULL)
891 if (lpToolInfo->cbSize < TTTOOLINFOW_V1_SIZE)
894 TRACE("add tool (%p) %p %d%s!\n",
895 hwnd, lpToolInfo->hwnd, lpToolInfo->uId,
896 (lpToolInfo->uFlags & TTF_IDISHWND) ? " TTF_IDISHWND" : "");
898 if (infoPtr->uNumTools == 0) {
899 infoPtr->tools = Alloc (sizeof(TTTOOL_INFO));
900 toolPtr = infoPtr->tools;
903 TTTOOL_INFO *oldTools = infoPtr->tools;
905 Alloc (sizeof(TTTOOL_INFO) * (infoPtr->uNumTools + 1));
906 memcpy (infoPtr->tools, oldTools,
907 infoPtr->uNumTools * sizeof(TTTOOL_INFO));
909 toolPtr = &infoPtr->tools[infoPtr->uNumTools];
912 infoPtr->uNumTools++;
915 toolPtr->uFlags = lpToolInfo->uFlags;
916 toolPtr->hwnd = lpToolInfo->hwnd;
917 toolPtr->uId = lpToolInfo->uId;
918 toolPtr->rect = lpToolInfo->rect;
919 toolPtr->hinst = lpToolInfo->hinst;
921 if (HIWORD(lpToolInfo->lpszText) == 0) {
922 TRACE("add string id %x!\n", (int)lpToolInfo->lpszText);
923 toolPtr->lpszText = (LPWSTR)lpToolInfo->lpszText;
925 else if (lpToolInfo->lpszText) {
926 if (lpToolInfo->lpszText == LPSTR_TEXTCALLBACKW) {
927 TRACE("add CALLBACK!\n");
928 toolPtr->lpszText = LPSTR_TEXTCALLBACKW;
931 INT len = lstrlenW (lpToolInfo->lpszText);
932 TRACE("add text %s!\n",
933 debugstr_w(lpToolInfo->lpszText));
934 toolPtr->lpszText = Alloc ((len + 1)*sizeof(WCHAR));
935 strcpyW (toolPtr->lpszText, lpToolInfo->lpszText);
939 if (lpToolInfo->cbSize >= sizeof(TTTOOLINFOW))
940 toolPtr->lParam = lpToolInfo->lParam;
942 /* install subclassing hook */
943 if (toolPtr->uFlags & TTF_SUBCLASS) {
944 if (toolPtr->uFlags & TTF_IDISHWND) {
945 SetWindowSubclass((HWND)toolPtr->uId, TOOLTIPS_SubclassProc, 1,
949 SetWindowSubclass(toolPtr->hwnd, TOOLTIPS_SubclassProc, 1,
952 TRACE("subclassing installed!\n");
955 nResult = (INT) SendMessageA (toolPtr->hwnd, WM_NOTIFYFORMAT,
956 (WPARAM)hwnd, (LPARAM)NF_QUERY);
957 if (nResult == NFR_ANSI) {
958 toolPtr->bNotifyUnicode = FALSE;
959 TRACE(" -- WM_NOTIFYFORMAT returns: NFR_ANSI\n");
960 } else if (nResult == NFR_UNICODE) {
961 toolPtr->bNotifyUnicode = TRUE;
962 TRACE(" -- WM_NOTIFYFORMAT returns: NFR_UNICODE\n");
964 TRACE (" -- WM_NOTIFYFORMAT returns: error!\n");
971 static void TOOLTIPS_DelToolCommon (HWND hwnd, TOOLTIPS_INFO *infoPtr, INT nTool)
973 TTTOOL_INFO *toolPtr;
975 TRACE("tool %d\n", nTool);
980 /* make sure the tooltip has disappeared before deleting it */
981 TOOLTIPS_Hide(hwnd, infoPtr);
983 /* delete text string */
984 toolPtr = &infoPtr->tools[nTool];
985 if (toolPtr->lpszText) {
986 if ( (toolPtr->lpszText != LPSTR_TEXTCALLBACKW) &&
987 (HIWORD((INT)toolPtr->lpszText) != 0) )
988 Free (toolPtr->lpszText);
991 /* remove subclassing */
992 if (toolPtr->uFlags & TTF_SUBCLASS) {
993 if (toolPtr->uFlags & TTF_IDISHWND) {
994 RemoveWindowSubclass((HWND)toolPtr->uId, TOOLTIPS_SubclassProc, 1);
997 RemoveWindowSubclass(toolPtr->hwnd, TOOLTIPS_SubclassProc, 1);
1001 /* delete tool from tool list */
1002 if (infoPtr->uNumTools == 1) {
1003 Free (infoPtr->tools);
1004 infoPtr->tools = NULL;
1007 TTTOOL_INFO *oldTools = infoPtr->tools;
1009 Alloc (sizeof(TTTOOL_INFO) * (infoPtr->uNumTools - 1));
1012 memcpy (&infoPtr->tools[0], &oldTools[0],
1013 nTool * sizeof(TTTOOL_INFO));
1015 if (nTool < infoPtr->uNumTools - 1)
1016 memcpy (&infoPtr->tools[nTool], &oldTools[nTool + 1],
1017 (infoPtr->uNumTools - nTool - 1) * sizeof(TTTOOL_INFO));
1022 /* update any indices affected by delete */
1024 /* destroying tool that mouse was on on last relayed mouse move */
1025 if (infoPtr->nTool == nTool)
1026 /* -1 means no current tool (0 means first tool) */
1027 infoPtr->nTool = -1;
1028 else if (infoPtr->nTool > nTool)
1031 if (infoPtr->nTrackTool == nTool)
1032 /* -1 means no current tool (0 means first tool) */
1033 infoPtr->nTrackTool = -1;
1034 else if (infoPtr->nTrackTool > nTool)
1035 infoPtr->nTrackTool--;
1037 if (infoPtr->nCurrentTool == nTool)
1038 /* -1 means no current tool (0 means first tool) */
1039 infoPtr->nCurrentTool = -1;
1040 else if (infoPtr->nCurrentTool > nTool)
1041 infoPtr->nCurrentTool--;
1043 infoPtr->uNumTools--;
1047 TOOLTIPS_DelToolA (HWND hwnd, WPARAM wParam, LPARAM lParam)
1049 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1050 LPTTTOOLINFOA lpToolInfo = (LPTTTOOLINFOA)lParam;
1053 if (lpToolInfo == NULL)
1055 if (lpToolInfo->cbSize < TTTOOLINFOA_V1_SIZE)
1057 if (infoPtr->uNumTools == 0)
1060 nTool = TOOLTIPS_GetToolFromInfoA (infoPtr, lpToolInfo);
1062 TOOLTIPS_DelToolCommon (hwnd, infoPtr, nTool);
1069 TOOLTIPS_DelToolW (HWND hwnd, WPARAM wParam, LPARAM lParam)
1071 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1072 LPTTTOOLINFOW lpToolInfo = (LPTTTOOLINFOW)lParam;
1075 if (lpToolInfo == NULL)
1077 if (lpToolInfo->cbSize < TTTOOLINFOW_V1_SIZE)
1079 if (infoPtr->uNumTools == 0)
1082 nTool = TOOLTIPS_GetToolFromInfoW (infoPtr, lpToolInfo);
1084 TOOLTIPS_DelToolCommon (hwnd, infoPtr, nTool);
1091 TOOLTIPS_EnumToolsA (HWND hwnd, WPARAM wParam, LPARAM lParam)
1093 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1094 UINT uIndex = (UINT)wParam;
1095 LPTTTOOLINFOA lpToolInfo = (LPTTTOOLINFOA)lParam;
1096 TTTOOL_INFO *toolPtr;
1098 if (lpToolInfo == NULL)
1100 if (lpToolInfo->cbSize < TTTOOLINFOA_V1_SIZE)
1102 if (uIndex >= infoPtr->uNumTools)
1105 TRACE("index=%u\n", uIndex);
1107 toolPtr = &infoPtr->tools[uIndex];
1109 /* copy tool data */
1110 lpToolInfo->uFlags = toolPtr->uFlags;
1111 lpToolInfo->hwnd = toolPtr->hwnd;
1112 lpToolInfo->uId = toolPtr->uId;
1113 lpToolInfo->rect = toolPtr->rect;
1114 lpToolInfo->hinst = toolPtr->hinst;
1115 /* lpToolInfo->lpszText = toolPtr->lpszText; */
1116 lpToolInfo->lpszText = NULL; /* FIXME */
1118 if (lpToolInfo->cbSize >= sizeof(TTTOOLINFOA))
1119 lpToolInfo->lParam = toolPtr->lParam;
1126 TOOLTIPS_EnumToolsW (HWND hwnd, WPARAM wParam, LPARAM lParam)
1128 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1129 UINT uIndex = (UINT)wParam;
1130 LPTTTOOLINFOW lpToolInfo = (LPTTTOOLINFOW)lParam;
1131 TTTOOL_INFO *toolPtr;
1133 if (lpToolInfo == NULL)
1135 if (lpToolInfo->cbSize < TTTOOLINFOW_V1_SIZE)
1137 if (uIndex >= infoPtr->uNumTools)
1140 TRACE("index=%u\n", uIndex);
1142 toolPtr = &infoPtr->tools[uIndex];
1144 /* copy tool data */
1145 lpToolInfo->uFlags = toolPtr->uFlags;
1146 lpToolInfo->hwnd = toolPtr->hwnd;
1147 lpToolInfo->uId = toolPtr->uId;
1148 lpToolInfo->rect = toolPtr->rect;
1149 lpToolInfo->hinst = toolPtr->hinst;
1150 /* lpToolInfo->lpszText = toolPtr->lpszText; */
1151 lpToolInfo->lpszText = NULL; /* FIXME */
1153 if (lpToolInfo->cbSize >= sizeof(TTTOOLINFOW))
1154 lpToolInfo->lParam = toolPtr->lParam;
1160 TOOLTIPS_GetBubbleSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
1162 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1163 LPTTTOOLINFOW lpToolInfo = (LPTTTOOLINFOW)lParam;
1167 if (lpToolInfo == NULL)
1169 if (lpToolInfo->cbSize < TTTOOLINFOW_V1_SIZE)
1172 nTool = TOOLTIPS_GetToolFromInfoW (infoPtr, lpToolInfo);
1173 if (nTool == -1) return 0;
1175 TRACE("tool %d\n", nTool);
1177 TOOLTIPS_CalcTipSize (hwnd, infoPtr, &size);
1178 TRACE("size %ld x %ld\n", size.cx, size.cy);
1180 return MAKELRESULT(size.cx, size.cy);
1184 TOOLTIPS_GetCurrentToolA (HWND hwnd, WPARAM wParam, LPARAM lParam)
1186 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1187 LPTTTOOLINFOA lpToolInfo = (LPTTTOOLINFOA)lParam;
1188 TTTOOL_INFO *toolPtr;
1190 if (lpToolInfo == NULL)
1192 if (lpToolInfo->cbSize < TTTOOLINFOA_V1_SIZE)
1196 if (infoPtr->nCurrentTool > -1) {
1197 toolPtr = &infoPtr->tools[infoPtr->nCurrentTool];
1199 /* copy tool data */
1200 lpToolInfo->uFlags = toolPtr->uFlags;
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;
1215 return (infoPtr->nCurrentTool != -1);
1222 TOOLTIPS_GetCurrentToolW (HWND hwnd, WPARAM wParam, LPARAM lParam)
1224 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1225 LPTTTOOLINFOW lpToolInfo = (LPTTTOOLINFOW)lParam;
1226 TTTOOL_INFO *toolPtr;
1228 if (lpToolInfo == NULL)
1230 if (lpToolInfo->cbSize < TTTOOLINFOW_V1_SIZE)
1234 if (infoPtr->nCurrentTool > -1) {
1235 toolPtr = &infoPtr->tools[infoPtr->nCurrentTool];
1237 /* copy tool data */
1238 lpToolInfo->uFlags = toolPtr->uFlags;
1239 lpToolInfo->rect = toolPtr->rect;
1240 lpToolInfo->hinst = toolPtr->hinst;
1241 /* lpToolInfo->lpszText = toolPtr->lpszText; */
1242 lpToolInfo->lpszText = NULL; /* FIXME */
1244 if (lpToolInfo->cbSize >= sizeof(TTTOOLINFOW))
1245 lpToolInfo->lParam = toolPtr->lParam;
1253 return (infoPtr->nCurrentTool != -1);
1260 TOOLTIPS_GetDelayTime (HWND hwnd, WPARAM wParam, LPARAM lParam)
1262 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1266 return infoPtr->nReshowTime;
1269 return infoPtr->nAutoPopTime;
1272 case TTDT_AUTOMATIC: /* Apparently TTDT_AUTOMATIC returns TTDT_INITIAL */
1273 return infoPtr->nInitialTime;
1276 WARN("Invalid wParam %x\n", wParam);
1285 TOOLTIPS_GetMargin (HWND hwnd, WPARAM wParam, LPARAM lParam)
1287 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1288 LPRECT lpRect = (LPRECT)lParam;
1290 lpRect->left = infoPtr->rcMargin.left;
1291 lpRect->right = infoPtr->rcMargin.right;
1292 lpRect->bottom = infoPtr->rcMargin.bottom;
1293 lpRect->top = infoPtr->rcMargin.top;
1299 inline static LRESULT
1300 TOOLTIPS_GetMaxTipWidth (HWND hwnd, WPARAM wParam, LPARAM lParam)
1302 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1304 return infoPtr->nMaxTipWidth;
1309 TOOLTIPS_GetTextA (HWND hwnd, WPARAM wParam, LPARAM lParam)
1311 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1312 LPTTTOOLINFOA lpToolInfo = (LPTTTOOLINFOA)lParam;
1315 if (lpToolInfo == NULL)
1317 if (lpToolInfo->cbSize < TTTOOLINFOA_V1_SIZE)
1320 nTool = TOOLTIPS_GetToolFromInfoA (infoPtr, lpToolInfo);
1321 if (nTool == -1) return 0;
1323 /* NB this API is broken, there is no way for the app to determine
1324 what size buffer it requires nor a way to specify how long the
1325 one it supplies is. We'll assume it's upto INFOTIPSIZE */
1327 WideCharToMultiByte(CP_ACP, 0, infoPtr->tools[nTool].lpszText, -1,
1328 lpToolInfo->lpszText, INFOTIPSIZE, NULL, NULL);
1335 TOOLTIPS_GetTextW (HWND hwnd, WPARAM wParam, LPARAM lParam)
1337 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1338 LPTTTOOLINFOW lpToolInfo = (LPTTTOOLINFOW)lParam;
1341 if (lpToolInfo == NULL)
1343 if (lpToolInfo->cbSize < TTTOOLINFOW_V1_SIZE)
1346 nTool = TOOLTIPS_GetToolFromInfoW (infoPtr, lpToolInfo);
1347 if (nTool == -1) return 0;
1349 strcpyW (lpToolInfo->lpszText, infoPtr->tools[nTool].lpszText);
1355 inline static LRESULT
1356 TOOLTIPS_GetTipBkColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
1358 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1359 return infoPtr->clrBk;
1363 inline static LRESULT
1364 TOOLTIPS_GetTipTextColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
1366 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1367 return infoPtr->clrText;
1371 inline static LRESULT
1372 TOOLTIPS_GetToolCount (HWND hwnd, WPARAM wParam, LPARAM lParam)
1374 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1375 return infoPtr->uNumTools;
1380 TOOLTIPS_GetToolInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
1382 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1383 LPTTTOOLINFOA lpToolInfo = (LPTTTOOLINFOA)lParam;
1384 TTTOOL_INFO *toolPtr;
1387 if (lpToolInfo == NULL)
1389 if (lpToolInfo->cbSize < TTTOOLINFOA_V1_SIZE)
1391 if (infoPtr->uNumTools == 0)
1394 nTool = TOOLTIPS_GetToolFromInfoA (infoPtr, lpToolInfo);
1398 TRACE("tool %d\n", nTool);
1400 toolPtr = &infoPtr->tools[nTool];
1402 /* copy tool data */
1403 lpToolInfo->uFlags = toolPtr->uFlags;
1404 lpToolInfo->rect = toolPtr->rect;
1405 lpToolInfo->hinst = toolPtr->hinst;
1406 /* lpToolInfo->lpszText = toolPtr->lpszText; */
1407 lpToolInfo->lpszText = NULL; /* FIXME */
1409 if (lpToolInfo->cbSize >= sizeof(TTTOOLINFOA))
1410 lpToolInfo->lParam = toolPtr->lParam;
1417 TOOLTIPS_GetToolInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
1419 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1420 LPTTTOOLINFOW lpToolInfo = (LPTTTOOLINFOW)lParam;
1421 TTTOOL_INFO *toolPtr;
1424 if (lpToolInfo == NULL)
1426 if (lpToolInfo->cbSize < TTTOOLINFOW_V1_SIZE)
1428 if (infoPtr->uNumTools == 0)
1431 nTool = TOOLTIPS_GetToolFromInfoW (infoPtr, lpToolInfo);
1435 TRACE("tool %d\n", nTool);
1437 toolPtr = &infoPtr->tools[nTool];
1439 /* copy tool data */
1440 lpToolInfo->uFlags = toolPtr->uFlags;
1441 lpToolInfo->rect = toolPtr->rect;
1442 lpToolInfo->hinst = toolPtr->hinst;
1443 /* lpToolInfo->lpszText = toolPtr->lpszText; */
1444 lpToolInfo->lpszText = NULL; /* FIXME */
1446 if (lpToolInfo->cbSize >= sizeof(TTTOOLINFOW))
1447 lpToolInfo->lParam = toolPtr->lParam;
1454 TOOLTIPS_HitTestA (HWND hwnd, WPARAM wParam, LPARAM lParam)
1456 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1457 LPTTHITTESTINFOA lptthit = (LPTTHITTESTINFOA)lParam;
1458 TTTOOL_INFO *toolPtr;
1464 nTool = TOOLTIPS_GetToolFromPoint (infoPtr, lptthit->hwnd, &lptthit->pt);
1468 TRACE("tool %d!\n", nTool);
1470 /* copy tool data */
1471 if (lptthit->ti.cbSize >= sizeof(TTTOOLINFOA)) {
1472 toolPtr = &infoPtr->tools[nTool];
1474 lptthit->ti.uFlags = toolPtr->uFlags;
1475 lptthit->ti.hwnd = toolPtr->hwnd;
1476 lptthit->ti.uId = toolPtr->uId;
1477 lptthit->ti.rect = toolPtr->rect;
1478 lptthit->ti.hinst = toolPtr->hinst;
1479 /* lptthit->ti.lpszText = toolPtr->lpszText; */
1480 lptthit->ti.lpszText = NULL; /* FIXME */
1481 lptthit->ti.lParam = toolPtr->lParam;
1489 TOOLTIPS_HitTestW (HWND hwnd, WPARAM wParam, LPARAM lParam)
1491 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1492 LPTTHITTESTINFOW lptthit = (LPTTHITTESTINFOW)lParam;
1493 TTTOOL_INFO *toolPtr;
1499 nTool = TOOLTIPS_GetToolFromPoint (infoPtr, lptthit->hwnd, &lptthit->pt);
1503 TRACE("tool %d!\n", nTool);
1505 /* copy tool data */
1506 if (lptthit->ti.cbSize >= sizeof(TTTOOLINFOW)) {
1507 toolPtr = &infoPtr->tools[nTool];
1509 lptthit->ti.uFlags = toolPtr->uFlags;
1510 lptthit->ti.hwnd = toolPtr->hwnd;
1511 lptthit->ti.uId = toolPtr->uId;
1512 lptthit->ti.rect = toolPtr->rect;
1513 lptthit->ti.hinst = toolPtr->hinst;
1514 /* lptthit->ti.lpszText = toolPtr->lpszText; */
1515 lptthit->ti.lpszText = NULL; /* FIXME */
1516 lptthit->ti.lParam = toolPtr->lParam;
1524 TOOLTIPS_NewToolRectA (HWND hwnd, WPARAM wParam, LPARAM lParam)
1526 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1527 LPTTTOOLINFOA lpti = (LPTTTOOLINFOA)lParam;
1532 if (lpti->cbSize < TTTOOLINFOA_V1_SIZE)
1535 nTool = TOOLTIPS_GetToolFromInfoA (infoPtr, lpti);
1537 TRACE("nTool = %d, rect = %s\n", nTool, wine_dbgstr_rect(&lpti->rect));
1539 if (nTool == -1) return 0;
1541 infoPtr->tools[nTool].rect = lpti->rect;
1548 TOOLTIPS_NewToolRectW (HWND hwnd, WPARAM wParam, LPARAM lParam)
1550 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1551 LPTTTOOLINFOW lpti = (LPTTTOOLINFOW)lParam;
1556 if (lpti->cbSize < TTTOOLINFOW_V1_SIZE)
1559 nTool = TOOLTIPS_GetToolFromInfoW (infoPtr, lpti);
1561 TRACE("nTool = %d, rect = %s\n", nTool, wine_dbgstr_rect(&lpti->rect));
1563 if (nTool == -1) return 0;
1565 infoPtr->tools[nTool].rect = lpti->rect;
1571 inline static LRESULT
1572 TOOLTIPS_Pop (HWND hwnd, WPARAM wParam, LPARAM lParam)
1574 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1575 TOOLTIPS_Hide (hwnd, infoPtr);
1582 TOOLTIPS_RelayEvent (HWND hwnd, WPARAM wParam, LPARAM lParam)
1584 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1585 LPMSG lpMsg = (LPMSG)lParam;
1590 ERR("lpMsg == NULL!\n");
1594 switch (lpMsg->message) {
1595 case WM_LBUTTONDOWN:
1597 case WM_MBUTTONDOWN:
1599 case WM_RBUTTONDOWN:
1601 TOOLTIPS_Hide (hwnd, infoPtr);
1605 pt.x = LOWORD(lpMsg->lParam);
1606 pt.y = HIWORD(lpMsg->lParam);
1607 nOldTool = infoPtr->nTool;
1608 infoPtr->nTool = TOOLTIPS_GetToolFromPoint(infoPtr, lpMsg->hwnd,
1610 TRACE("tool (%p) %d %d %d\n", hwnd, nOldTool,
1611 infoPtr->nTool, infoPtr->nCurrentTool);
1612 TRACE("WM_MOUSEMOVE (%p %ld %ld)\n", hwnd, pt.x, pt.y);
1614 if (infoPtr->nTool != nOldTool) {
1615 if(infoPtr->nTool == -1) { /* Moved out of all tools */
1616 TOOLTIPS_Hide(hwnd, infoPtr);
1617 KillTimer(hwnd, ID_TIMERLEAVE);
1618 } else if (nOldTool == -1) { /* Moved from outside */
1619 if(infoPtr->bActive) {
1620 SetTimer(hwnd, ID_TIMERSHOW, infoPtr->nInitialTime, 0);
1621 TRACE("timer 1 started!\n");
1623 } else { /* Moved from one to another */
1624 TOOLTIPS_Hide (hwnd, infoPtr);
1625 KillTimer(hwnd, ID_TIMERLEAVE);
1626 if(infoPtr->bActive) {
1627 SetTimer (hwnd, ID_TIMERSHOW, infoPtr->nReshowTime, 0);
1628 TRACE("timer 1 started!\n");
1631 } else if(infoPtr->nCurrentTool != -1) { /* restart autopop */
1632 KillTimer(hwnd, ID_TIMERPOP);
1633 SetTimer(hwnd, ID_TIMERPOP, infoPtr->nAutoPopTime, 0);
1634 TRACE("timer 2 restarted\n");
1644 TOOLTIPS_SetDelayTime (HWND hwnd, WPARAM wParam, LPARAM lParam)
1646 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1647 INT nTime = (INT)LOWORD(lParam);
1650 case TTDT_AUTOMATIC:
1652 nTime = GetDoubleClickTime();
1653 infoPtr->nReshowTime = nTime / 5;
1654 infoPtr->nAutoPopTime = nTime * 10;
1655 infoPtr->nInitialTime = nTime;
1660 nTime = GetDoubleClickTime() / 5;
1661 infoPtr->nReshowTime = nTime;
1666 nTime = GetDoubleClickTime() * 10;
1667 infoPtr->nAutoPopTime = nTime;
1672 nTime = GetDoubleClickTime();
1673 infoPtr->nInitialTime = nTime;
1677 WARN("Invalid wParam %x\n", wParam);
1686 TOOLTIPS_SetMargin (HWND hwnd, WPARAM wParam, LPARAM lParam)
1688 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1689 LPRECT lpRect = (LPRECT)lParam;
1691 infoPtr->rcMargin.left = lpRect->left;
1692 infoPtr->rcMargin.right = lpRect->right;
1693 infoPtr->rcMargin.bottom = lpRect->bottom;
1694 infoPtr->rcMargin.top = lpRect->top;
1700 inline static LRESULT
1701 TOOLTIPS_SetMaxTipWidth (HWND hwnd, WPARAM wParam, LPARAM lParam)
1703 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1704 INT nTemp = infoPtr->nMaxTipWidth;
1706 infoPtr->nMaxTipWidth = (INT)lParam;
1712 inline static LRESULT
1713 TOOLTIPS_SetTipBkColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
1715 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1717 infoPtr->clrBk = (COLORREF)wParam;
1723 inline static LRESULT
1724 TOOLTIPS_SetTipTextColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
1726 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1728 infoPtr->clrText = (COLORREF)wParam;
1735 TOOLTIPS_SetToolInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
1737 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1738 LPTTTOOLINFOA lpToolInfo = (LPTTTOOLINFOA)lParam;
1739 TTTOOL_INFO *toolPtr;
1742 if (lpToolInfo == NULL)
1744 if (lpToolInfo->cbSize < TTTOOLINFOA_V1_SIZE)
1747 nTool = TOOLTIPS_GetToolFromInfoA (infoPtr, lpToolInfo);
1748 if (nTool == -1) return 0;
1750 TRACE("tool %d\n", nTool);
1752 toolPtr = &infoPtr->tools[nTool];
1754 /* copy tool data */
1755 toolPtr->uFlags = lpToolInfo->uFlags;
1756 toolPtr->hwnd = lpToolInfo->hwnd;
1757 toolPtr->uId = lpToolInfo->uId;
1758 toolPtr->rect = lpToolInfo->rect;
1759 toolPtr->hinst = lpToolInfo->hinst;
1761 if (HIWORD(lpToolInfo->lpszText) == 0) {
1762 TRACE("set string id %x!\n", (INT)lpToolInfo->lpszText);
1763 toolPtr->lpszText = (LPWSTR)lpToolInfo->lpszText;
1765 else if (lpToolInfo->lpszText) {
1766 if (lpToolInfo->lpszText == LPSTR_TEXTCALLBACKA)
1767 toolPtr->lpszText = LPSTR_TEXTCALLBACKW;
1769 if ( (toolPtr->lpszText) &&
1770 (HIWORD((INT)toolPtr->lpszText) != 0) ) {
1771 Free (toolPtr->lpszText);
1772 toolPtr->lpszText = NULL;
1774 if (lpToolInfo->lpszText) {
1775 INT len = MultiByteToWideChar(CP_ACP, 0, lpToolInfo->lpszText,
1777 toolPtr->lpszText = Alloc (len * sizeof(WCHAR));
1778 MultiByteToWideChar(CP_ACP, 0, lpToolInfo->lpszText, -1,
1779 toolPtr->lpszText, len);
1784 if (lpToolInfo->cbSize >= sizeof(TTTOOLINFOA))
1785 toolPtr->lParam = lpToolInfo->lParam;
1792 TOOLTIPS_SetToolInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
1794 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1795 LPTTTOOLINFOW lpToolInfo = (LPTTTOOLINFOW)lParam;
1796 TTTOOL_INFO *toolPtr;
1799 if (lpToolInfo == NULL)
1801 if (lpToolInfo->cbSize < TTTOOLINFOW_V1_SIZE)
1804 nTool = TOOLTIPS_GetToolFromInfoW (infoPtr, lpToolInfo);
1805 if (nTool == -1) return 0;
1807 TRACE("tool %d\n", nTool);
1809 toolPtr = &infoPtr->tools[nTool];
1811 /* copy tool data */
1812 toolPtr->uFlags = lpToolInfo->uFlags;
1813 toolPtr->hwnd = lpToolInfo->hwnd;
1814 toolPtr->uId = lpToolInfo->uId;
1815 toolPtr->rect = lpToolInfo->rect;
1816 toolPtr->hinst = lpToolInfo->hinst;
1818 if (HIWORD(lpToolInfo->lpszText) == 0) {
1819 TRACE("set string id %x!\n", (INT)lpToolInfo->lpszText);
1820 toolPtr->lpszText = lpToolInfo->lpszText;
1822 else if (lpToolInfo->lpszText) {
1823 if (lpToolInfo->lpszText == LPSTR_TEXTCALLBACKW)
1824 toolPtr->lpszText = LPSTR_TEXTCALLBACKW;
1826 if ( (toolPtr->lpszText) &&
1827 (HIWORD((INT)toolPtr->lpszText) != 0) ) {
1828 Free (toolPtr->lpszText);
1829 toolPtr->lpszText = NULL;
1831 if (lpToolInfo->lpszText) {
1832 INT len = lstrlenW (lpToolInfo->lpszText);
1833 toolPtr->lpszText = Alloc ((len+1)*sizeof(WCHAR));
1834 strcpyW (toolPtr->lpszText, lpToolInfo->lpszText);
1839 if (lpToolInfo->cbSize >= sizeof(TTTOOLINFOW))
1840 toolPtr->lParam = lpToolInfo->lParam;
1847 TOOLTIPS_TrackActivate (HWND hwnd, WPARAM wParam, LPARAM lParam)
1849 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1852 LPTTTOOLINFOA lpToolInfo = (LPTTTOOLINFOA)lParam;
1854 if (lpToolInfo == NULL)
1856 if (lpToolInfo->cbSize < TTTOOLINFOA_V1_SIZE)
1860 infoPtr->nTrackTool = TOOLTIPS_GetToolFromInfoA (infoPtr, lpToolInfo);
1861 if (infoPtr->nTrackTool != -1) {
1862 TRACE("activated!\n");
1863 infoPtr->bTrackActive = TRUE;
1864 TOOLTIPS_TrackShow (hwnd, infoPtr);
1869 TOOLTIPS_TrackHide (hwnd, infoPtr);
1871 infoPtr->bTrackActive = FALSE;
1872 infoPtr->nTrackTool = -1;
1874 TRACE("deactivated!\n");
1882 TOOLTIPS_TrackPosition (HWND hwnd, WPARAM wParam, LPARAM lParam)
1884 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1886 infoPtr->xTrackPos = (INT)LOWORD(lParam);
1887 infoPtr->yTrackPos = (INT)HIWORD(lParam);
1889 if (infoPtr->bTrackActive) {
1891 infoPtr->xTrackPos, infoPtr->yTrackPos);
1893 TOOLTIPS_TrackShow (hwnd, infoPtr);
1901 TOOLTIPS_Update (HWND hwnd, WPARAM wParam, LPARAM lParam)
1903 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1905 if (infoPtr->nCurrentTool != -1)
1906 UpdateWindow (hwnd);
1913 TOOLTIPS_UpdateTipTextA (HWND hwnd, WPARAM wParam, LPARAM lParam)
1915 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1916 LPTTTOOLINFOA lpToolInfo = (LPTTTOOLINFOA)lParam;
1917 TTTOOL_INFO *toolPtr;
1920 if (lpToolInfo == NULL)
1922 if (lpToolInfo->cbSize < TTTOOLINFOA_V1_SIZE)
1925 nTool = TOOLTIPS_GetToolFromInfoA (infoPtr, lpToolInfo);
1926 if (nTool == -1) return 0;
1928 TRACE("tool %d\n", nTool);
1930 toolPtr = &infoPtr->tools[nTool];
1932 /* copy tool text */
1933 toolPtr->hinst = lpToolInfo->hinst;
1935 if (HIWORD(lpToolInfo->lpszText) == 0){
1936 toolPtr->lpszText = (LPWSTR)lpToolInfo->lpszText;
1938 else if (lpToolInfo->lpszText) {
1939 if (lpToolInfo->lpszText == LPSTR_TEXTCALLBACKA)
1940 toolPtr->lpszText = LPSTR_TEXTCALLBACKW;
1942 if ( (toolPtr->lpszText) &&
1943 (HIWORD((INT)toolPtr->lpszText) != 0) ) {
1944 Free (toolPtr->lpszText);
1945 toolPtr->lpszText = NULL;
1947 if (lpToolInfo->lpszText) {
1948 INT len = MultiByteToWideChar(CP_ACP, 0, lpToolInfo->lpszText,
1950 toolPtr->lpszText = Alloc (len * sizeof(WCHAR));
1951 MultiByteToWideChar(CP_ACP, 0, lpToolInfo->lpszText, -1,
1952 toolPtr->lpszText, len);
1957 if(infoPtr->nCurrentTool == -1) return 0;
1959 if (infoPtr->bActive)
1960 TOOLTIPS_Show (hwnd, infoPtr);
1961 else if (infoPtr->bTrackActive)
1962 TOOLTIPS_TrackShow (hwnd, infoPtr);
1969 TOOLTIPS_UpdateTipTextW (HWND hwnd, WPARAM wParam, LPARAM lParam)
1971 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1972 LPTTTOOLINFOW lpToolInfo = (LPTTTOOLINFOW)lParam;
1973 TTTOOL_INFO *toolPtr;
1976 if (lpToolInfo == NULL)
1978 if (lpToolInfo->cbSize < TTTOOLINFOW_V1_SIZE)
1981 nTool = TOOLTIPS_GetToolFromInfoW (infoPtr, lpToolInfo);
1985 TRACE("tool %d\n", nTool);
1987 toolPtr = &infoPtr->tools[nTool];
1989 /* copy tool text */
1990 toolPtr->hinst = lpToolInfo->hinst;
1992 if (HIWORD(lpToolInfo->lpszText) == 0){
1993 toolPtr->lpszText = lpToolInfo->lpszText;
1995 else if (lpToolInfo->lpszText) {
1996 if (lpToolInfo->lpszText == LPSTR_TEXTCALLBACKW)
1997 toolPtr->lpszText = LPSTR_TEXTCALLBACKW;
1999 if ( (toolPtr->lpszText) &&
2000 (HIWORD((INT)toolPtr->lpszText) != 0) ) {
2001 Free (toolPtr->lpszText);
2002 toolPtr->lpszText = NULL;
2004 if (lpToolInfo->lpszText) {
2005 INT len = lstrlenW (lpToolInfo->lpszText);
2006 toolPtr->lpszText = Alloc ((len+1)*sizeof(WCHAR));
2007 strcpyW (toolPtr->lpszText, lpToolInfo->lpszText);
2012 if(infoPtr->nCurrentTool == -1) return 0;
2014 if (infoPtr->bActive)
2015 TOOLTIPS_Show (hwnd, infoPtr);
2016 else if (infoPtr->bTrackActive)
2017 TOOLTIPS_TrackShow (hwnd, infoPtr);
2024 TOOLTIPS_WindowFromPoint (HWND hwnd, WPARAM wParam, LPARAM lParam)
2026 return (LRESULT)WindowFromPoint (*((LPPOINT)lParam));
2032 TOOLTIPS_Create (HWND hwnd, const CREATESTRUCTW *lpcs)
2034 TOOLTIPS_INFO *infoPtr;
2035 NONCLIENTMETRICSA nclm;
2037 /* allocate memory for info structure */
2038 infoPtr = (TOOLTIPS_INFO *)Alloc (sizeof(TOOLTIPS_INFO));
2039 SetWindowLongA (hwnd, 0, (DWORD)infoPtr);
2041 /* initialize info structure */
2042 infoPtr->bActive = TRUE;
2043 infoPtr->bTrackActive = FALSE;
2044 infoPtr->clrBk = GetSysColor (COLOR_INFOBK);
2045 infoPtr->clrText = GetSysColor (COLOR_INFOTEXT);
2047 nclm.cbSize = sizeof(NONCLIENTMETRICSA);
2048 SystemParametersInfoA (SPI_GETNONCLIENTMETRICS, 0, &nclm, 0);
2049 infoPtr->hFont = CreateFontIndirectA (&nclm.lfStatusFont);
2051 infoPtr->nMaxTipWidth = -1;
2052 infoPtr->nTool = -1;
2053 infoPtr->nCurrentTool = -1;
2054 infoPtr->nTrackTool = -1;
2056 TOOLTIPS_SetDelayTime(hwnd, TTDT_AUTOMATIC, 0L);
2058 SetWindowPos (hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOZORDER | SWP_HIDEWINDOW | SWP_NOACTIVATE);
2065 TOOLTIPS_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
2067 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
2068 TTTOOL_INFO *toolPtr;
2072 if (infoPtr->tools) {
2073 for (i = 0; i < infoPtr->uNumTools; i++) {
2074 toolPtr = &infoPtr->tools[i];
2075 if (toolPtr->lpszText) {
2076 if ( (toolPtr->lpszText != LPSTR_TEXTCALLBACKW) &&
2077 (HIWORD((INT)toolPtr->lpszText) != 0) )
2079 Free (toolPtr->lpszText);
2080 toolPtr->lpszText = NULL;
2084 /* remove subclassing */
2085 if (toolPtr->uFlags & TTF_SUBCLASS) {
2086 if (toolPtr->uFlags & TTF_IDISHWND) {
2087 RemoveWindowSubclass((HWND)toolPtr->uId, TOOLTIPS_SubclassProc, 1);
2090 RemoveWindowSubclass(toolPtr->hwnd, TOOLTIPS_SubclassProc, 1);
2094 Free (infoPtr->tools);
2098 DeleteObject (infoPtr->hFont);
2100 /* free tool tips info data */
2102 SetWindowLongA(hwnd, 0, 0);
2108 TOOLTIPS_GetFont (HWND hwnd, WPARAM wParam, LPARAM lParam)
2110 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
2112 return (LRESULT)infoPtr->hFont;
2117 TOOLTIPS_MouseMessage (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2119 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
2121 TOOLTIPS_Hide (hwnd, infoPtr);
2128 TOOLTIPS_NCCreate (HWND hwnd, WPARAM wParam, LPARAM lParam)
2130 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
2131 DWORD dwExStyle = GetWindowLongA (hwnd, GWL_EXSTYLE);
2133 dwStyle &= 0x0000FFFF;
2134 dwStyle |= (WS_POPUP | WS_BORDER | WS_CLIPSIBLINGS);
2136 /* WS_BORDER only draws a border round the window rect, not the
2137 * window region, therefore it is useless to us in balloon mode */
2138 if (dwStyle & TTS_BALLOON) dwStyle &= ~WS_BORDER;
2140 SetWindowLongA (hwnd, GWL_STYLE, dwStyle);
2142 dwExStyle |= WS_EX_TOOLWINDOW;
2143 SetWindowLongA (hwnd, GWL_EXSTYLE, dwExStyle);
2150 TOOLTIPS_NCHitTest (HWND hwnd, WPARAM wParam, LPARAM lParam)
2152 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
2153 INT nTool = (infoPtr->bTrackActive) ? infoPtr->nTrackTool : infoPtr->nTool;
2155 TRACE(" nTool=%d\n", nTool);
2157 if ((nTool > -1) && (nTool < infoPtr->uNumTools)) {
2158 if (infoPtr->tools[nTool].uFlags & TTF_TRANSPARENT) {
2159 TRACE("-- in transparent mode!\n");
2160 return HTTRANSPARENT;
2164 return DefWindowProcA (hwnd, WM_NCHITTEST, wParam, lParam);
2169 TOOLTIPS_NotifyFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
2171 FIXME ("hwnd=%p wParam=%x lParam=%lx\n", hwnd, wParam, lParam);
2178 TOOLTIPS_Paint (HWND hwnd, WPARAM wParam, LPARAM lParam)
2183 hdc = (wParam == 0) ? BeginPaint (hwnd, &ps) : (HDC)wParam;
2184 TOOLTIPS_Refresh (hwnd, hdc);
2186 EndPaint (hwnd, &ps);
2192 TOOLTIPS_SetFont (HWND hwnd, WPARAM wParam, LPARAM lParam)
2194 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
2197 if(!GetObjectW((HFONT)wParam, sizeof(lf), &lf))
2200 if(infoPtr->hFont) DeleteObject (infoPtr->hFont);
2201 infoPtr->hFont = CreateFontIndirectW(&lf);
2203 if ((LOWORD(lParam)) & (infoPtr->nCurrentTool != -1)) {
2204 FIXME("full redraw needed!\n");
2209 /******************************************************************
2210 * TOOLTIPS_OnWMGetTextLength
2212 * This function is called when the tooltip receive a
2213 * WM_GETTEXTLENGTH message.
2217 * returns the length, in characters, of the tip text
2218 ******************************************************************/
2220 TOOLTIPS_OnWMGetTextLength(HWND hwnd, WPARAM wParam, LPARAM lParam)
2222 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
2223 return lstrlenW(infoPtr->szTipText);
2226 /******************************************************************
2227 * TOOLTIPS_OnWMGetText
2229 * This function is called when the tooltip receive a
2230 * WM_GETTEXT message.
2231 * wParam : specifies the maximum number of characters to be copied
2232 * lParam : is the pointer to the buffer that will receive
2235 * returns the number of characters copied
2236 ******************************************************************/
2238 TOOLTIPS_OnWMGetText (HWND hwnd, WPARAM wParam, LPARAM lParam)
2240 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
2242 if(!infoPtr || !(infoPtr->szTipText))
2245 return WideCharToMultiByte(CP_ACP, 0, infoPtr->szTipText, -1,
2246 (LPSTR)lParam, wParam, NULL, NULL);
2250 TOOLTIPS_Timer (HWND hwnd, WPARAM wParam, LPARAM lParam)
2252 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
2255 TRACE("timer %d (%p) expired!\n", wParam, hwnd);
2259 KillTimer (hwnd, ID_TIMERSHOW);
2260 nOldTool = infoPtr->nTool;
2261 if ((infoPtr->nTool = TOOLTIPS_CheckTool (hwnd, TRUE)) == nOldTool)
2262 TOOLTIPS_Show (hwnd, infoPtr);
2266 TOOLTIPS_Hide (hwnd, infoPtr);
2270 nOldTool = infoPtr->nTool;
2271 infoPtr->nTool = TOOLTIPS_CheckTool (hwnd, FALSE);
2272 TRACE("tool (%p) %d %d %d\n", hwnd, nOldTool,
2273 infoPtr->nTool, infoPtr->nCurrentTool);
2274 if (infoPtr->nTool != nOldTool) {
2275 if(infoPtr->nTool == -1) { /* Moved out of all tools */
2276 TOOLTIPS_Hide(hwnd, infoPtr);
2277 KillTimer(hwnd, ID_TIMERLEAVE);
2278 } else if (nOldTool == -1) { /* Moved from outside */
2279 ERR("How did this happen?\n");
2280 } else { /* Moved from one to another */
2281 TOOLTIPS_Hide (hwnd, infoPtr);
2282 KillTimer(hwnd, ID_TIMERLEAVE);
2283 if(infoPtr->bActive) {
2284 SetTimer (hwnd, ID_TIMERSHOW, infoPtr->nReshowTime, 0);
2285 TRACE("timer 1 started!\n");
2292 ERR("Unknown timer id %d\n", wParam);
2300 TOOLTIPS_WinIniChange (HWND hwnd, WPARAM wParam, LPARAM lParam)
2302 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
2303 NONCLIENTMETRICSA nclm;
2305 infoPtr->clrBk = GetSysColor (COLOR_INFOBK);
2306 infoPtr->clrText = GetSysColor (COLOR_INFOTEXT);
2308 DeleteObject (infoPtr->hFont);
2309 nclm.cbSize = sizeof(NONCLIENTMETRICSA);
2310 SystemParametersInfoA (SPI_GETNONCLIENTMETRICS, 0, &nclm, 0);
2311 infoPtr->hFont = CreateFontIndirectA (&nclm.lfStatusFont);
2318 TOOLTIPS_SubclassProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uID, DWORD_PTR dwRef)
2324 case WM_LBUTTONDOWN:
2326 case WM_MBUTTONDOWN:
2328 case WM_RBUTTONDOWN:
2332 msg.wParam = wParam;
2333 msg.lParam = lParam;
2334 TOOLTIPS_RelayEvent((HWND)dwRef, 0, (LPARAM)&msg);
2340 return DefSubclassProc(hwnd, uMsg, wParam, lParam);
2344 static LRESULT CALLBACK
2345 TOOLTIPS_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2347 TRACE("hwnd=%p msg=%x wparam=%x lParam=%lx\n", hwnd, uMsg, wParam, lParam);
2348 if (!TOOLTIPS_GetInfoPtr(hwnd) && (uMsg != WM_CREATE) && (uMsg != WM_NCCREATE))
2349 return DefWindowProcA (hwnd, uMsg, wParam, lParam);
2353 return TOOLTIPS_Activate (hwnd, wParam, lParam);
2356 return TOOLTIPS_AddToolA (hwnd, wParam, lParam);
2359 return TOOLTIPS_AddToolW (hwnd, wParam, lParam);
2362 return TOOLTIPS_DelToolA (hwnd, wParam, lParam);
2365 return TOOLTIPS_DelToolW (hwnd, wParam, lParam);
2367 case TTM_ENUMTOOLSA:
2368 return TOOLTIPS_EnumToolsA (hwnd, wParam, lParam);
2370 case TTM_ENUMTOOLSW:
2371 return TOOLTIPS_EnumToolsW (hwnd, wParam, lParam);
2373 case TTM_GETBUBBLESIZE:
2374 return TOOLTIPS_GetBubbleSize (hwnd, wParam, lParam);
2376 case TTM_GETCURRENTTOOLA:
2377 return TOOLTIPS_GetCurrentToolA (hwnd, wParam, lParam);
2379 case TTM_GETCURRENTTOOLW:
2380 return TOOLTIPS_GetCurrentToolW (hwnd, wParam, lParam);
2382 case TTM_GETDELAYTIME:
2383 return TOOLTIPS_GetDelayTime (hwnd, wParam, lParam);
2386 return TOOLTIPS_GetMargin (hwnd, wParam, lParam);
2388 case TTM_GETMAXTIPWIDTH:
2389 return TOOLTIPS_GetMaxTipWidth (hwnd, wParam, lParam);
2392 return TOOLTIPS_GetTextA (hwnd, wParam, lParam);
2395 return TOOLTIPS_GetTextW (hwnd, wParam, lParam);
2397 case TTM_GETTIPBKCOLOR:
2398 return TOOLTIPS_GetTipBkColor (hwnd, wParam, lParam);
2400 case TTM_GETTIPTEXTCOLOR:
2401 return TOOLTIPS_GetTipTextColor (hwnd, wParam, lParam);
2403 case TTM_GETTOOLCOUNT:
2404 return TOOLTIPS_GetToolCount (hwnd, wParam, lParam);
2406 case TTM_GETTOOLINFOA:
2407 return TOOLTIPS_GetToolInfoA (hwnd, wParam, lParam);
2409 case TTM_GETTOOLINFOW:
2410 return TOOLTIPS_GetToolInfoW (hwnd, wParam, lParam);
2413 return TOOLTIPS_HitTestA (hwnd, wParam, lParam);
2416 return TOOLTIPS_HitTestW (hwnd, wParam, lParam);
2418 case TTM_NEWTOOLRECTA:
2419 return TOOLTIPS_NewToolRectA (hwnd, wParam, lParam);
2421 case TTM_NEWTOOLRECTW:
2422 return TOOLTIPS_NewToolRectW (hwnd, wParam, lParam);
2425 return TOOLTIPS_Pop (hwnd, wParam, lParam);
2427 case TTM_RELAYEVENT:
2428 return TOOLTIPS_RelayEvent (hwnd, wParam, lParam);
2430 case TTM_SETDELAYTIME:
2431 return TOOLTIPS_SetDelayTime (hwnd, wParam, lParam);
2434 return TOOLTIPS_SetMargin (hwnd, wParam, lParam);
2436 case TTM_SETMAXTIPWIDTH:
2437 return TOOLTIPS_SetMaxTipWidth (hwnd, wParam, lParam);
2439 case TTM_SETTIPBKCOLOR:
2440 return TOOLTIPS_SetTipBkColor (hwnd, wParam, lParam);
2442 case TTM_SETTIPTEXTCOLOR:
2443 return TOOLTIPS_SetTipTextColor (hwnd, wParam, lParam);
2445 case TTM_SETTOOLINFOA:
2446 return TOOLTIPS_SetToolInfoA (hwnd, wParam, lParam);
2448 case TTM_SETTOOLINFOW:
2449 return TOOLTIPS_SetToolInfoW (hwnd, wParam, lParam);
2451 case TTM_TRACKACTIVATE:
2452 return TOOLTIPS_TrackActivate (hwnd, wParam, lParam);
2454 case TTM_TRACKPOSITION:
2455 return TOOLTIPS_TrackPosition (hwnd, wParam, lParam);
2458 return TOOLTIPS_Update (hwnd, wParam, lParam);
2460 case TTM_UPDATETIPTEXTA:
2461 return TOOLTIPS_UpdateTipTextA (hwnd, wParam, lParam);
2463 case TTM_UPDATETIPTEXTW:
2464 return TOOLTIPS_UpdateTipTextW (hwnd, wParam, lParam);
2466 case TTM_WINDOWFROMPOINT:
2467 return TOOLTIPS_WindowFromPoint (hwnd, wParam, lParam);
2471 return TOOLTIPS_Create (hwnd, (LPCREATESTRUCTW)lParam);
2474 return TOOLTIPS_Destroy (hwnd, wParam, lParam);
2477 /* we draw the background in WM_PAINT */
2481 return TOOLTIPS_GetFont (hwnd, wParam, lParam);
2484 return TOOLTIPS_OnWMGetText (hwnd, wParam, lParam);
2486 case WM_GETTEXTLENGTH:
2487 return TOOLTIPS_OnWMGetTextLength (hwnd, wParam, lParam);
2490 case WM_LBUTTONDOWN:
2492 case WM_MBUTTONDOWN:
2494 case WM_RBUTTONDOWN:
2497 return TOOLTIPS_MouseMessage (hwnd, uMsg, wParam, lParam);
2500 return TOOLTIPS_NCCreate (hwnd, wParam, lParam);
2503 return TOOLTIPS_NCHitTest (hwnd, wParam, lParam);
2505 case WM_NOTIFYFORMAT:
2506 return TOOLTIPS_NotifyFormat (hwnd, wParam, lParam);
2509 return TOOLTIPS_Paint (hwnd, wParam, lParam);
2512 return TOOLTIPS_SetFont (hwnd, wParam, lParam);
2515 return TOOLTIPS_Timer (hwnd, wParam, lParam);
2517 case WM_WININICHANGE:
2518 return TOOLTIPS_WinIniChange (hwnd, wParam, lParam);
2521 if ((uMsg >= WM_USER) && (uMsg < WM_APP))
2522 ERR("unknown msg %04x wp=%08x lp=%08lx\n",
2523 uMsg, wParam, lParam);
2524 return DefWindowProcA (hwnd, uMsg, wParam, lParam);
2531 TOOLTIPS_Register (void)
2535 ZeroMemory (&wndClass, sizeof(WNDCLASSA));
2536 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS | CS_SAVEBITS;
2537 wndClass.lpfnWndProc = (WNDPROC)TOOLTIPS_WindowProc;
2538 wndClass.cbClsExtra = 0;
2539 wndClass.cbWndExtra = sizeof(TOOLTIPS_INFO *);
2540 wndClass.hCursor = LoadCursorA (0, (LPSTR)IDC_ARROW);
2541 wndClass.hbrBackground = 0;
2542 wndClass.lpszClassName = TOOLTIPS_CLASSA;
2544 RegisterClassA (&wndClass);
2549 TOOLTIPS_Unregister (void)
2551 UnregisterClassA (TOOLTIPS_CLASSA, NULL);