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))
135 TOOLTIPS_SubclassProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uId, DWORD_PTR dwRef);
139 TOOLTIPS_Refresh (HWND hwnd, HDC hdc)
141 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr(hwnd);
146 UINT uFlags = DT_EXTERNALLEADING;
148 if (infoPtr->nMaxTipWidth > -1)
149 uFlags |= DT_WORDBREAK;
150 if (GetWindowLongA (hwnd, GWL_STYLE) & TTS_NOPREFIX)
151 uFlags |= DT_NOPREFIX;
152 GetClientRect (hwnd, &rc);
154 /* fill the background */
155 hBrush = CreateSolidBrush (infoPtr->clrBk);
156 FillRect (hdc, &rc, hBrush);
157 DeleteObject (hBrush);
159 /* calculate text rectangle */
160 rc.left += (2 + infoPtr->rcMargin.left);
161 rc.top += (2 + infoPtr->rcMargin.top);
162 rc.right -= (2 + infoPtr->rcMargin.right);
163 rc.bottom -= (2 + infoPtr->rcMargin.bottom);
166 oldBkMode = SetBkMode (hdc, TRANSPARENT);
167 SetTextColor (hdc, infoPtr->clrText);
168 hOldFont = SelectObject (hdc, infoPtr->hFont);
169 DrawTextW (hdc, infoPtr->szTipText, -1, &rc, uFlags);
170 SelectObject (hdc, hOldFont);
171 if (oldBkMode != TRANSPARENT)
172 SetBkMode (hdc, oldBkMode);
175 static void TOOLTIPS_GetDispInfoA(HWND hwnd, TOOLTIPS_INFO *infoPtr, TTTOOL_INFO *toolPtr)
177 NMTTDISPINFOA ttnmdi;
179 /* fill NMHDR struct */
180 ZeroMemory (&ttnmdi, sizeof(NMTTDISPINFOA));
181 ttnmdi.hdr.hwndFrom = hwnd;
182 ttnmdi.hdr.idFrom = toolPtr->uId;
183 ttnmdi.hdr.code = TTN_GETDISPINFOA;
184 ttnmdi.lpszText = (LPSTR)&ttnmdi.szText;
185 ttnmdi.uFlags = toolPtr->uFlags;
186 ttnmdi.lParam = toolPtr->lParam;
188 TRACE("hdr.idFrom = %x\n", ttnmdi.hdr.idFrom);
189 SendMessageA(toolPtr->hwnd, WM_NOTIFY,
190 (WPARAM)toolPtr->uId, (LPARAM)&ttnmdi);
192 if (HIWORD((UINT)ttnmdi.lpszText) == 0) {
193 LoadStringW(ttnmdi.hinst, (UINT)ttnmdi.lpszText,
194 infoPtr->szTipText, INFOTIPSIZE);
195 if (ttnmdi.uFlags & TTF_DI_SETITEM) {
196 toolPtr->hinst = ttnmdi.hinst;
197 toolPtr->lpszText = (LPWSTR)ttnmdi.lpszText;
200 else if (ttnmdi.lpszText == 0) {
201 /* no text available */
202 infoPtr->szTipText[0] = '\0';
204 else if (ttnmdi.lpszText != LPSTR_TEXTCALLBACKA) {
205 INT max_len = (ttnmdi.lpszText == &ttnmdi.szText[0]) ?
206 sizeof(ttnmdi.szText)/sizeof(ttnmdi.szText[0]) : -1;
207 MultiByteToWideChar(CP_ACP, 0, ttnmdi.lpszText, max_len,
208 infoPtr->szTipText, INFOTIPSIZE);
209 if (ttnmdi.uFlags & TTF_DI_SETITEM) {
210 INT len = MultiByteToWideChar(CP_ACP, 0, ttnmdi.lpszText,
213 toolPtr->lpszText = Alloc (len * sizeof(WCHAR));
214 MultiByteToWideChar(CP_ACP, 0, ttnmdi.lpszText, -1,
215 toolPtr->lpszText, len);
219 ERR("recursive text callback!\n");
220 infoPtr->szTipText[0] = '\0';
224 static void TOOLTIPS_GetDispInfoW(HWND hwnd, TOOLTIPS_INFO *infoPtr, TTTOOL_INFO *toolPtr)
226 NMTTDISPINFOW ttnmdi;
228 /* fill NMHDR struct */
229 ZeroMemory (&ttnmdi, sizeof(NMTTDISPINFOW));
230 ttnmdi.hdr.hwndFrom = hwnd;
231 ttnmdi.hdr.idFrom = toolPtr->uId;
232 ttnmdi.hdr.code = TTN_GETDISPINFOW;
233 ttnmdi.lpszText = (LPWSTR)&ttnmdi.szText;
234 ttnmdi.uFlags = toolPtr->uFlags;
235 ttnmdi.lParam = toolPtr->lParam;
237 TRACE("hdr.idFrom = %x\n", ttnmdi.hdr.idFrom);
238 SendMessageW(toolPtr->hwnd, WM_NOTIFY,
239 (WPARAM)toolPtr->uId, (LPARAM)&ttnmdi);
241 if (HIWORD((UINT)ttnmdi.lpszText) == 0) {
242 LoadStringW(ttnmdi.hinst, (UINT)ttnmdi.lpszText,
243 infoPtr->szTipText, INFOTIPSIZE);
244 if (ttnmdi.uFlags & TTF_DI_SETITEM) {
245 toolPtr->hinst = ttnmdi.hinst;
246 toolPtr->lpszText = ttnmdi.lpszText;
249 else if (ttnmdi.lpszText == 0) {
250 /* no text available */
251 infoPtr->szTipText[0] = '\0';
253 else if (ttnmdi.lpszText != LPSTR_TEXTCALLBACKW) {
254 INT max_len = (ttnmdi.lpszText == &ttnmdi.szText[0]) ?
255 sizeof(ttnmdi.szText)/sizeof(ttnmdi.szText[0]) : INFOTIPSIZE-1;
256 strncpyW(infoPtr->szTipText, ttnmdi.lpszText, max_len);
257 if (ttnmdi.uFlags & TTF_DI_SETITEM) {
258 INT len = max(strlenW(ttnmdi.lpszText), max_len);
260 toolPtr->lpszText = Alloc ((len+1) * sizeof(WCHAR));
261 memcpy(toolPtr->lpszText, ttnmdi.lpszText, (len+1) * sizeof(WCHAR));
265 ERR("recursive text callback!\n");
266 infoPtr->szTipText[0] = '\0';
271 TOOLTIPS_GetTipText (HWND hwnd, TOOLTIPS_INFO *infoPtr, INT nTool)
273 TTTOOL_INFO *toolPtr = &infoPtr->tools[nTool];
275 if (HIWORD((UINT)toolPtr->lpszText) == 0) {
276 /* load a resource */
277 TRACE("load res string %p %x\n",
278 toolPtr->hinst, (int)toolPtr->lpszText);
279 LoadStringW (toolPtr->hinst, (UINT)toolPtr->lpszText,
280 infoPtr->szTipText, INFOTIPSIZE);
282 else if (toolPtr->lpszText) {
283 if (toolPtr->lpszText == LPSTR_TEXTCALLBACKW) {
284 if (toolPtr->bNotifyUnicode)
285 TOOLTIPS_GetDispInfoW(hwnd, infoPtr, toolPtr);
287 TOOLTIPS_GetDispInfoA(hwnd, infoPtr, toolPtr);
290 /* the item is a usual (unicode) text */
291 lstrcpynW (infoPtr->szTipText, toolPtr->lpszText, INFOTIPSIZE);
295 /* no text available */
296 infoPtr->szTipText[0] = L'\0';
299 TRACE("%s\n", debugstr_w(infoPtr->szTipText));
304 TOOLTIPS_CalcTipSize (HWND hwnd, TOOLTIPS_INFO *infoPtr, LPSIZE lpSize)
308 UINT uFlags = DT_EXTERNALLEADING | DT_CALCRECT;
309 RECT rc = {0, 0, 0, 0};
311 if (infoPtr->nMaxTipWidth > -1) {
312 rc.right = infoPtr->nMaxTipWidth;
313 uFlags |= DT_WORDBREAK;
315 if (GetWindowLongA (hwnd, GWL_STYLE) & TTS_NOPREFIX)
316 uFlags |= DT_NOPREFIX;
317 TRACE("%s\n", debugstr_w(infoPtr->szTipText));
320 hOldFont = SelectObject (hdc, infoPtr->hFont);
321 DrawTextW (hdc, infoPtr->szTipText, -1, &rc, uFlags);
322 SelectObject (hdc, hOldFont);
323 ReleaseDC (hwnd, hdc);
325 lpSize->cx = rc.right - rc.left + 4 +
326 infoPtr->rcMargin.left + infoPtr->rcMargin.right;
327 lpSize->cy = rc.bottom - rc.top + 4 +
328 infoPtr->rcMargin.bottom + infoPtr->rcMargin.top;
333 TOOLTIPS_Show (HWND hwnd, TOOLTIPS_INFO *infoPtr)
335 TTTOOL_INFO *toolPtr;
340 if (infoPtr->nTool == -1) {
341 TRACE("invalid tool (-1)!\n");
345 infoPtr->nCurrentTool = infoPtr->nTool;
347 TRACE("Show tooltip pre %d! (%p)\n", infoPtr->nTool, hwnd);
349 TOOLTIPS_GetTipText (hwnd, infoPtr, infoPtr->nCurrentTool);
351 if (infoPtr->szTipText[0] == L'\0') {
352 infoPtr->nCurrentTool = -1;
356 TRACE("Show tooltip %d!\n", infoPtr->nCurrentTool);
357 toolPtr = &infoPtr->tools[infoPtr->nCurrentTool];
360 hdr.idFrom = toolPtr->uId;
362 SendMessageA (toolPtr->hwnd, WM_NOTIFY,
363 (WPARAM)toolPtr->uId, (LPARAM)&hdr);
365 TRACE("%s\n", debugstr_w(infoPtr->szTipText));
367 TOOLTIPS_CalcTipSize (hwnd, infoPtr, &size);
368 TRACE("size %ld x %ld\n", size.cx, size.cy);
370 if (toolPtr->uFlags & TTF_CENTERTIP) {
373 if (toolPtr->uFlags & TTF_IDISHWND)
374 GetWindowRect ((HWND)toolPtr->uId, &rc);
377 MapWindowPoints (toolPtr->hwnd, NULL, (LPPOINT)&rc, 2);
379 rect.left = (rc.left + rc.right - size.cx) / 2;
380 rect.top = rc.bottom + 2;
383 GetCursorPos ((LPPOINT)&rect);
387 TRACE("pos %ld - %ld\n", rect.left, rect.top);
389 rect.right = rect.left + size.cx;
390 rect.bottom = rect.top + size.cy;
393 wndrect.right = GetSystemMetrics( SM_CXSCREEN );
394 if( rect.right > wndrect.right ) {
395 rect.left -= rect.right - wndrect.right + 2;
396 rect.right = wndrect.right - 2;
398 wndrect.bottom = GetSystemMetrics( SM_CYSCREEN );
399 if( rect.bottom > wndrect.bottom ) {
402 if (toolPtr->uFlags & TTF_IDISHWND)
403 GetWindowRect ((HWND)toolPtr->uId, &rc);
406 MapWindowPoints (toolPtr->hwnd, NULL, (LPPOINT)&rc, 2);
408 rect.bottom = rc.top - 2;
409 rect.top = rect.bottom - size.cy;
412 AdjustWindowRectEx (&rect, GetWindowLongA (hwnd, GWL_STYLE),
413 FALSE, GetWindowLongA (hwnd, GWL_EXSTYLE));
415 SetWindowPos (hwnd, HWND_TOP, rect.left, rect.top,
416 rect.right - rect.left, rect.bottom - rect.top,
417 SWP_SHOWWINDOW | SWP_NOACTIVATE);
419 /* repaint the tooltip */
420 InvalidateRect(hwnd, NULL, TRUE);
423 SetTimer (hwnd, ID_TIMERPOP, infoPtr->nAutoPopTime, 0);
424 TRACE("timer 2 started!\n");
425 SetTimer (hwnd, ID_TIMERLEAVE, infoPtr->nReshowTime, 0);
426 TRACE("timer 3 started!\n");
431 TOOLTIPS_Hide (HWND hwnd, TOOLTIPS_INFO *infoPtr)
433 TTTOOL_INFO *toolPtr;
436 TRACE("Hide tooltip %d! (%p)\n", infoPtr->nCurrentTool, hwnd);
438 if (infoPtr->nCurrentTool == -1)
441 toolPtr = &infoPtr->tools[infoPtr->nCurrentTool];
442 KillTimer (hwnd, ID_TIMERPOP);
445 hdr.idFrom = toolPtr->uId;
447 SendMessageA (toolPtr->hwnd, WM_NOTIFY,
448 (WPARAM)toolPtr->uId, (LPARAM)&hdr);
450 infoPtr->nCurrentTool = -1;
452 SetWindowPos (hwnd, HWND_TOP, 0, 0, 0, 0,
453 SWP_NOZORDER | SWP_HIDEWINDOW | SWP_NOACTIVATE);
458 TOOLTIPS_TrackShow (HWND hwnd, TOOLTIPS_INFO *infoPtr)
460 TTTOOL_INFO *toolPtr;
465 if (infoPtr->nTrackTool == -1) {
466 TRACE("invalid tracking tool (-1)!\n");
470 TRACE("show tracking tooltip pre %d!\n", infoPtr->nTrackTool);
472 TOOLTIPS_GetTipText (hwnd, infoPtr, infoPtr->nTrackTool);
474 if (infoPtr->szTipText[0] == L'\0') {
475 infoPtr->nTrackTool = -1;
479 TRACE("show tracking tooltip %d!\n", infoPtr->nTrackTool);
480 toolPtr = &infoPtr->tools[infoPtr->nTrackTool];
483 hdr.idFrom = toolPtr->uId;
485 SendMessageA (toolPtr->hwnd, WM_NOTIFY,
486 (WPARAM)toolPtr->uId, (LPARAM)&hdr);
488 TRACE("%s\n", debugstr_w(infoPtr->szTipText));
490 TOOLTIPS_CalcTipSize (hwnd, infoPtr, &size);
491 TRACE("size %ld x %ld\n", size.cx, size.cy);
493 if (toolPtr->uFlags & TTF_ABSOLUTE) {
494 rect.left = infoPtr->xTrackPos;
495 rect.top = infoPtr->yTrackPos;
497 if (toolPtr->uFlags & TTF_CENTERTIP) {
498 rect.left -= (size.cx / 2);
499 rect.top -= (size.cy / 2);
505 if (toolPtr->uFlags & TTF_IDISHWND)
506 GetWindowRect ((HWND)toolPtr->uId, &rcTool);
508 rcTool = toolPtr->rect;
509 MapWindowPoints (toolPtr->hwnd, NULL, (LPPOINT)&rcTool, 2);
512 GetCursorPos ((LPPOINT)&rect);
515 if (toolPtr->uFlags & TTF_CENTERTIP) {
516 rect.left -= (size.cx / 2);
517 rect.top -= (size.cy / 2);
520 /* smart placement */
521 if ((rect.left + size.cx > rcTool.left) && (rect.left < rcTool.right) &&
522 (rect.top + size.cy > rcTool.top) && (rect.top < rcTool.bottom))
523 rect.left = rcTool.right;
526 TRACE("pos %ld - %ld\n", rect.left, rect.top);
528 rect.right = rect.left + size.cx;
529 rect.bottom = rect.top + size.cy;
531 AdjustWindowRectEx (&rect, GetWindowLongA (hwnd, GWL_STYLE),
532 FALSE, GetWindowLongA (hwnd, GWL_EXSTYLE));
534 SetWindowPos (hwnd, HWND_TOP, rect.left, rect.top,
535 rect.right - rect.left, rect.bottom - rect.top,
536 SWP_SHOWWINDOW | SWP_NOACTIVATE );
538 InvalidateRect(hwnd, NULL, TRUE);
544 TOOLTIPS_TrackHide (HWND hwnd, TOOLTIPS_INFO *infoPtr)
546 TTTOOL_INFO *toolPtr;
549 TRACE("hide tracking tooltip %d\n", infoPtr->nTrackTool);
551 if (infoPtr->nTrackTool == -1)
554 toolPtr = &infoPtr->tools[infoPtr->nTrackTool];
557 hdr.idFrom = toolPtr->uId;
559 SendMessageA (toolPtr->hwnd, WM_NOTIFY,
560 (WPARAM)toolPtr->uId, (LPARAM)&hdr);
562 SetWindowPos (hwnd, HWND_TOP, 0, 0, 0, 0,
563 SWP_NOZORDER | SWP_HIDEWINDOW | SWP_NOACTIVATE);
568 TOOLTIPS_GetToolFromInfoA (TOOLTIPS_INFO *infoPtr, LPTTTOOLINFOA lpToolInfo)
570 TTTOOL_INFO *toolPtr;
573 for (nTool = 0; nTool < infoPtr->uNumTools; nTool++) {
574 toolPtr = &infoPtr->tools[nTool];
576 if (!(toolPtr->uFlags & TTF_IDISHWND) &&
577 (lpToolInfo->hwnd == toolPtr->hwnd) &&
578 (lpToolInfo->uId == toolPtr->uId))
582 for (nTool = 0; nTool < infoPtr->uNumTools; nTool++) {
583 toolPtr = &infoPtr->tools[nTool];
585 if ((toolPtr->uFlags & TTF_IDISHWND) &&
586 (lpToolInfo->uId == toolPtr->uId))
595 TOOLTIPS_GetToolFromInfoW (TOOLTIPS_INFO *infoPtr, LPTTTOOLINFOW lpToolInfo)
597 TTTOOL_INFO *toolPtr;
600 for (nTool = 0; nTool < infoPtr->uNumTools; nTool++) {
601 toolPtr = &infoPtr->tools[nTool];
603 if (!(toolPtr->uFlags & TTF_IDISHWND) &&
604 (lpToolInfo->hwnd == toolPtr->hwnd) &&
605 (lpToolInfo->uId == toolPtr->uId))
609 for (nTool = 0; nTool < infoPtr->uNumTools; nTool++) {
610 toolPtr = &infoPtr->tools[nTool];
612 if ((toolPtr->uFlags & TTF_IDISHWND) &&
613 (lpToolInfo->uId == toolPtr->uId))
622 TOOLTIPS_GetToolFromPoint (TOOLTIPS_INFO *infoPtr, HWND hwnd, LPPOINT lpPt)
624 TTTOOL_INFO *toolPtr;
627 for (nTool = 0; nTool < infoPtr->uNumTools; nTool++) {
628 toolPtr = &infoPtr->tools[nTool];
630 if (!(toolPtr->uFlags & TTF_IDISHWND)) {
631 if (hwnd != toolPtr->hwnd)
633 if (!PtInRect (&toolPtr->rect, *lpPt))
639 for (nTool = 0; nTool < infoPtr->uNumTools; nTool++) {
640 toolPtr = &infoPtr->tools[nTool];
642 if (toolPtr->uFlags & TTF_IDISHWND) {
643 if ((HWND)toolPtr->uId == hwnd)
653 TOOLTIPS_IsWindowActive (HWND hwnd)
655 HWND hwndActive = GetActiveWindow ();
658 if (hwndActive == hwnd)
660 return IsChild (hwndActive, hwnd);
665 TOOLTIPS_CheckTool (HWND hwnd, BOOL bShowTest)
667 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
673 hwndTool = (HWND)SendMessageA (hwnd, TTM_WINDOWFROMPOINT, 0, (LPARAM)&pt);
677 ScreenToClient (hwndTool, &pt);
678 nTool = TOOLTIPS_GetToolFromPoint (infoPtr, hwndTool, &pt);
682 if (!(GetWindowLongA (hwnd, GWL_STYLE) & TTS_ALWAYSTIP) && bShowTest) {
683 if (!TOOLTIPS_IsWindowActive (GetWindow (hwnd, GW_OWNER)))
687 TRACE("tool %d\n", nTool);
694 TOOLTIPS_Activate (HWND hwnd, WPARAM wParam, LPARAM lParam)
696 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
698 infoPtr->bActive = (BOOL)wParam;
700 if (infoPtr->bActive)
701 TRACE("activate!\n");
703 if (!(infoPtr->bActive) && (infoPtr->nCurrentTool != -1))
704 TOOLTIPS_Hide (hwnd, infoPtr);
711 TOOLTIPS_AddToolA (HWND hwnd, WPARAM wParam, LPARAM lParam)
713 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
714 LPTTTOOLINFOA lpToolInfo = (LPTTTOOLINFOA)lParam;
715 TTTOOL_INFO *toolPtr;
718 if (lpToolInfo == NULL)
720 if (lpToolInfo->cbSize < TTTOOLINFOA_V1_SIZE)
723 TRACE("add tool (%p) %p %d%s!\n",
724 hwnd, lpToolInfo->hwnd, lpToolInfo->uId,
725 (lpToolInfo->uFlags & TTF_IDISHWND) ? " TTF_IDISHWND" : "");
727 if (infoPtr->uNumTools == 0) {
728 infoPtr->tools = Alloc (sizeof(TTTOOL_INFO));
729 toolPtr = infoPtr->tools;
732 TTTOOL_INFO *oldTools = infoPtr->tools;
734 Alloc (sizeof(TTTOOL_INFO) * (infoPtr->uNumTools + 1));
735 memcpy (infoPtr->tools, oldTools,
736 infoPtr->uNumTools * sizeof(TTTOOL_INFO));
738 toolPtr = &infoPtr->tools[infoPtr->uNumTools];
741 infoPtr->uNumTools++;
744 toolPtr->uFlags = lpToolInfo->uFlags;
745 toolPtr->hwnd = lpToolInfo->hwnd;
746 toolPtr->uId = lpToolInfo->uId;
747 toolPtr->rect = lpToolInfo->rect;
748 toolPtr->hinst = lpToolInfo->hinst;
750 if (HIWORD(lpToolInfo->lpszText) == 0) {
751 TRACE("add string id %x!\n", (int)lpToolInfo->lpszText);
752 toolPtr->lpszText = (LPWSTR)lpToolInfo->lpszText;
754 else if (lpToolInfo->lpszText) {
755 if (lpToolInfo->lpszText == LPSTR_TEXTCALLBACKA) {
756 TRACE("add CALLBACK!\n");
757 toolPtr->lpszText = LPSTR_TEXTCALLBACKW;
760 INT len = MultiByteToWideChar(CP_ACP, 0, lpToolInfo->lpszText, -1,
762 TRACE("add text \"%s\"!\n", lpToolInfo->lpszText);
763 toolPtr->lpszText = Alloc (len * sizeof(WCHAR));
764 MultiByteToWideChar(CP_ACP, 0, lpToolInfo->lpszText, -1,
765 toolPtr->lpszText, len);
769 if (lpToolInfo->cbSize >= sizeof(TTTOOLINFOA))
770 toolPtr->lParam = lpToolInfo->lParam;
772 /* install subclassing hook */
773 if (toolPtr->uFlags & TTF_SUBCLASS) {
774 if (toolPtr->uFlags & TTF_IDISHWND) {
775 SetWindowSubclass((HWND)toolPtr->uId, TOOLTIPS_SubclassProc, 1,
779 SetWindowSubclass(toolPtr->hwnd, TOOLTIPS_SubclassProc, 1,
782 TRACE("subclassing installed!\n");
785 nResult = (INT) SendMessageA (toolPtr->hwnd, WM_NOTIFYFORMAT,
786 (WPARAM)hwnd, (LPARAM)NF_QUERY);
787 if (nResult == NFR_ANSI) {
788 toolPtr->bNotifyUnicode = FALSE;
789 TRACE(" -- WM_NOTIFYFORMAT returns: NFR_ANSI\n");
790 } else if (nResult == NFR_UNICODE) {
791 toolPtr->bNotifyUnicode = TRUE;
792 TRACE(" -- WM_NOTIFYFORMAT returns: NFR_UNICODE\n");
794 TRACE (" -- WM_NOTIFYFORMAT returns: error!\n");
802 TOOLTIPS_AddToolW (HWND hwnd, WPARAM wParam, LPARAM lParam)
804 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
805 LPTTTOOLINFOW lpToolInfo = (LPTTTOOLINFOW)lParam;
806 TTTOOL_INFO *toolPtr;
809 if (lpToolInfo == NULL)
811 if (lpToolInfo->cbSize < TTTOOLINFOW_V1_SIZE)
814 TRACE("add tool (%p) %p %d%s!\n",
815 hwnd, lpToolInfo->hwnd, lpToolInfo->uId,
816 (lpToolInfo->uFlags & TTF_IDISHWND) ? " TTF_IDISHWND" : "");
818 if (infoPtr->uNumTools == 0) {
819 infoPtr->tools = Alloc (sizeof(TTTOOL_INFO));
820 toolPtr = infoPtr->tools;
823 TTTOOL_INFO *oldTools = infoPtr->tools;
825 Alloc (sizeof(TTTOOL_INFO) * (infoPtr->uNumTools + 1));
826 memcpy (infoPtr->tools, oldTools,
827 infoPtr->uNumTools * sizeof(TTTOOL_INFO));
829 toolPtr = &infoPtr->tools[infoPtr->uNumTools];
832 infoPtr->uNumTools++;
835 toolPtr->uFlags = lpToolInfo->uFlags;
836 toolPtr->hwnd = lpToolInfo->hwnd;
837 toolPtr->uId = lpToolInfo->uId;
838 toolPtr->rect = lpToolInfo->rect;
839 toolPtr->hinst = lpToolInfo->hinst;
841 if (HIWORD(lpToolInfo->lpszText) == 0) {
842 TRACE("add string id %x!\n", (int)lpToolInfo->lpszText);
843 toolPtr->lpszText = (LPWSTR)lpToolInfo->lpszText;
845 else if (lpToolInfo->lpszText) {
846 if (lpToolInfo->lpszText == LPSTR_TEXTCALLBACKW) {
847 TRACE("add CALLBACK!\n");
848 toolPtr->lpszText = LPSTR_TEXTCALLBACKW;
851 INT len = lstrlenW (lpToolInfo->lpszText);
852 TRACE("add text %s!\n",
853 debugstr_w(lpToolInfo->lpszText));
854 toolPtr->lpszText = Alloc ((len + 1)*sizeof(WCHAR));
855 strcpyW (toolPtr->lpszText, lpToolInfo->lpszText);
859 if (lpToolInfo->cbSize >= sizeof(TTTOOLINFOW))
860 toolPtr->lParam = lpToolInfo->lParam;
862 /* install subclassing hook */
863 if (toolPtr->uFlags & TTF_SUBCLASS) {
864 if (toolPtr->uFlags & TTF_IDISHWND) {
865 SetWindowSubclass((HWND)toolPtr->uId, TOOLTIPS_SubclassProc, 1,
869 SetWindowSubclass(toolPtr->hwnd, TOOLTIPS_SubclassProc, 1,
872 TRACE("subclassing installed!\n");
875 nResult = (INT) SendMessageA (toolPtr->hwnd, WM_NOTIFYFORMAT,
876 (WPARAM)hwnd, (LPARAM)NF_QUERY);
877 if (nResult == NFR_ANSI) {
878 toolPtr->bNotifyUnicode = FALSE;
879 TRACE(" -- WM_NOTIFYFORMAT returns: NFR_ANSI\n");
880 } else if (nResult == NFR_UNICODE) {
881 toolPtr->bNotifyUnicode = TRUE;
882 TRACE(" -- WM_NOTIFYFORMAT returns: NFR_UNICODE\n");
884 TRACE (" -- WM_NOTIFYFORMAT returns: error!\n");
891 static void TOOLTIPS_DelToolCommon (HWND hwnd, TOOLTIPS_INFO *infoPtr, INT nTool)
893 TTTOOL_INFO *toolPtr;
895 TRACE("tool %d\n", nTool);
900 /* make sure the tooltip has disappeared before deleting it */
901 TOOLTIPS_Hide(hwnd, infoPtr);
903 /* delete text string */
904 toolPtr = &infoPtr->tools[nTool];
905 if (toolPtr->lpszText) {
906 if ( (toolPtr->lpszText != LPSTR_TEXTCALLBACKW) &&
907 (HIWORD((INT)toolPtr->lpszText) != 0) )
908 Free (toolPtr->lpszText);
911 /* remove subclassing */
912 if (toolPtr->uFlags & TTF_SUBCLASS) {
913 if (toolPtr->uFlags & TTF_IDISHWND) {
914 RemoveWindowSubclass((HWND)toolPtr->uId, TOOLTIPS_SubclassProc, 1);
917 RemoveWindowSubclass(toolPtr->hwnd, TOOLTIPS_SubclassProc, 1);
921 /* delete tool from tool list */
922 if (infoPtr->uNumTools == 1) {
923 Free (infoPtr->tools);
924 infoPtr->tools = NULL;
927 TTTOOL_INFO *oldTools = infoPtr->tools;
929 Alloc (sizeof(TTTOOL_INFO) * (infoPtr->uNumTools - 1));
932 memcpy (&infoPtr->tools[0], &oldTools[0],
933 nTool * sizeof(TTTOOL_INFO));
935 if (nTool < infoPtr->uNumTools - 1)
936 memcpy (&infoPtr->tools[nTool], &oldTools[nTool + 1],
937 (infoPtr->uNumTools - nTool - 1) * sizeof(TTTOOL_INFO));
942 /* update any indices affected by delete */
944 /* destroying tool that mouse was on on last relayed mouse move */
945 if (infoPtr->nTool == nTool)
946 /* -1 means no current tool (0 means first tool) */
948 else if (infoPtr->nTool > nTool)
951 if (infoPtr->nTrackTool == nTool)
952 /* -1 means no current tool (0 means first tool) */
953 infoPtr->nTrackTool = -1;
954 else if (infoPtr->nTrackTool > nTool)
955 infoPtr->nTrackTool--;
957 if (infoPtr->nCurrentTool == nTool)
958 /* -1 means no current tool (0 means first tool) */
959 infoPtr->nCurrentTool = -1;
960 else if (infoPtr->nCurrentTool > nTool)
961 infoPtr->nCurrentTool--;
963 infoPtr->uNumTools--;
967 TOOLTIPS_DelToolA (HWND hwnd, WPARAM wParam, LPARAM lParam)
969 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
970 LPTTTOOLINFOA lpToolInfo = (LPTTTOOLINFOA)lParam;
973 if (lpToolInfo == NULL)
975 if (lpToolInfo->cbSize < TTTOOLINFOA_V1_SIZE)
977 if (infoPtr->uNumTools == 0)
980 nTool = TOOLTIPS_GetToolFromInfoA (infoPtr, lpToolInfo);
982 TOOLTIPS_DelToolCommon (hwnd, infoPtr, nTool);
989 TOOLTIPS_DelToolW (HWND hwnd, WPARAM wParam, LPARAM lParam)
991 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
992 LPTTTOOLINFOW lpToolInfo = (LPTTTOOLINFOW)lParam;
995 if (lpToolInfo == NULL)
997 if (lpToolInfo->cbSize < TTTOOLINFOW_V1_SIZE)
999 if (infoPtr->uNumTools == 0)
1002 nTool = TOOLTIPS_GetToolFromInfoW (infoPtr, lpToolInfo);
1004 TOOLTIPS_DelToolCommon (hwnd, infoPtr, nTool);
1011 TOOLTIPS_EnumToolsA (HWND hwnd, WPARAM wParam, LPARAM lParam)
1013 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1014 UINT uIndex = (UINT)wParam;
1015 LPTTTOOLINFOA lpToolInfo = (LPTTTOOLINFOA)lParam;
1016 TTTOOL_INFO *toolPtr;
1018 if (lpToolInfo == NULL)
1020 if (lpToolInfo->cbSize < TTTOOLINFOA_V1_SIZE)
1022 if (uIndex >= infoPtr->uNumTools)
1025 TRACE("index=%u\n", uIndex);
1027 toolPtr = &infoPtr->tools[uIndex];
1029 /* copy tool data */
1030 lpToolInfo->uFlags = toolPtr->uFlags;
1031 lpToolInfo->hwnd = toolPtr->hwnd;
1032 lpToolInfo->uId = toolPtr->uId;
1033 lpToolInfo->rect = toolPtr->rect;
1034 lpToolInfo->hinst = toolPtr->hinst;
1035 /* lpToolInfo->lpszText = toolPtr->lpszText; */
1036 lpToolInfo->lpszText = NULL; /* FIXME */
1038 if (lpToolInfo->cbSize >= sizeof(TTTOOLINFOA))
1039 lpToolInfo->lParam = toolPtr->lParam;
1046 TOOLTIPS_EnumToolsW (HWND hwnd, WPARAM wParam, LPARAM lParam)
1048 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1049 UINT uIndex = (UINT)wParam;
1050 LPTTTOOLINFOW lpToolInfo = (LPTTTOOLINFOW)lParam;
1051 TTTOOL_INFO *toolPtr;
1053 if (lpToolInfo == NULL)
1055 if (lpToolInfo->cbSize < TTTOOLINFOW_V1_SIZE)
1057 if (uIndex >= infoPtr->uNumTools)
1060 TRACE("index=%u\n", uIndex);
1062 toolPtr = &infoPtr->tools[uIndex];
1064 /* copy tool data */
1065 lpToolInfo->uFlags = toolPtr->uFlags;
1066 lpToolInfo->hwnd = toolPtr->hwnd;
1067 lpToolInfo->uId = toolPtr->uId;
1068 lpToolInfo->rect = toolPtr->rect;
1069 lpToolInfo->hinst = toolPtr->hinst;
1070 /* lpToolInfo->lpszText = toolPtr->lpszText; */
1071 lpToolInfo->lpszText = NULL; /* FIXME */
1073 if (lpToolInfo->cbSize >= sizeof(TTTOOLINFOW))
1074 lpToolInfo->lParam = toolPtr->lParam;
1080 TOOLTIPS_GetBubbleSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
1082 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1083 LPTTTOOLINFOW lpToolInfo = (LPTTTOOLINFOW)lParam;
1087 if (lpToolInfo == NULL)
1089 if (lpToolInfo->cbSize < TTTOOLINFOW_V1_SIZE)
1092 nTool = TOOLTIPS_GetToolFromInfoW (infoPtr, lpToolInfo);
1093 if (nTool == -1) return 0;
1095 TRACE("tool %d\n", nTool);
1097 TOOLTIPS_CalcTipSize (hwnd, infoPtr, &size);
1098 TRACE("size %ld x %ld\n", size.cx, size.cy);
1100 return MAKELRESULT(size.cx, size.cy);
1104 TOOLTIPS_GetCurrentToolA (HWND hwnd, WPARAM wParam, LPARAM lParam)
1106 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1107 LPTTTOOLINFOA lpToolInfo = (LPTTTOOLINFOA)lParam;
1108 TTTOOL_INFO *toolPtr;
1110 if (lpToolInfo == NULL)
1112 if (lpToolInfo->cbSize < TTTOOLINFOA_V1_SIZE)
1116 if (infoPtr->nCurrentTool > -1) {
1117 toolPtr = &infoPtr->tools[infoPtr->nCurrentTool];
1119 /* copy tool data */
1120 lpToolInfo->uFlags = toolPtr->uFlags;
1121 lpToolInfo->rect = toolPtr->rect;
1122 lpToolInfo->hinst = toolPtr->hinst;
1123 /* lpToolInfo->lpszText = toolPtr->lpszText; */
1124 lpToolInfo->lpszText = NULL; /* FIXME */
1126 if (lpToolInfo->cbSize >= sizeof(TTTOOLINFOA))
1127 lpToolInfo->lParam = toolPtr->lParam;
1135 return (infoPtr->nCurrentTool != -1);
1142 TOOLTIPS_GetCurrentToolW (HWND hwnd, WPARAM wParam, LPARAM lParam)
1144 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1145 LPTTTOOLINFOW lpToolInfo = (LPTTTOOLINFOW)lParam;
1146 TTTOOL_INFO *toolPtr;
1148 if (lpToolInfo == NULL)
1150 if (lpToolInfo->cbSize < TTTOOLINFOW_V1_SIZE)
1154 if (infoPtr->nCurrentTool > -1) {
1155 toolPtr = &infoPtr->tools[infoPtr->nCurrentTool];
1157 /* copy tool data */
1158 lpToolInfo->uFlags = toolPtr->uFlags;
1159 lpToolInfo->rect = toolPtr->rect;
1160 lpToolInfo->hinst = toolPtr->hinst;
1161 /* lpToolInfo->lpszText = toolPtr->lpszText; */
1162 lpToolInfo->lpszText = NULL; /* FIXME */
1164 if (lpToolInfo->cbSize >= sizeof(TTTOOLINFOW))
1165 lpToolInfo->lParam = toolPtr->lParam;
1173 return (infoPtr->nCurrentTool != -1);
1180 TOOLTIPS_GetDelayTime (HWND hwnd, WPARAM wParam, LPARAM lParam)
1182 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1186 return infoPtr->nReshowTime;
1189 return infoPtr->nAutoPopTime;
1192 case TTDT_AUTOMATIC: /* Apparently TTDT_AUTOMATIC returns TTDT_INITIAL */
1193 return infoPtr->nInitialTime;
1196 WARN("Invalid wParam %x\n", wParam);
1205 TOOLTIPS_GetMargin (HWND hwnd, WPARAM wParam, LPARAM lParam)
1207 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1208 LPRECT lpRect = (LPRECT)lParam;
1210 lpRect->left = infoPtr->rcMargin.left;
1211 lpRect->right = infoPtr->rcMargin.right;
1212 lpRect->bottom = infoPtr->rcMargin.bottom;
1213 lpRect->top = infoPtr->rcMargin.top;
1219 inline static LRESULT
1220 TOOLTIPS_GetMaxTipWidth (HWND hwnd, WPARAM wParam, LPARAM lParam)
1222 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1224 return infoPtr->nMaxTipWidth;
1229 TOOLTIPS_GetTextA (HWND hwnd, WPARAM wParam, LPARAM lParam)
1231 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1232 LPTTTOOLINFOA lpToolInfo = (LPTTTOOLINFOA)lParam;
1235 if (lpToolInfo == NULL)
1237 if (lpToolInfo->cbSize < TTTOOLINFOA_V1_SIZE)
1240 nTool = TOOLTIPS_GetToolFromInfoA (infoPtr, lpToolInfo);
1241 if (nTool == -1) return 0;
1243 /* NB this API is broken, there is no way for the app to determine
1244 what size buffer it requires nor a way to specify how long the
1245 one it supplies is. We'll assume it's upto INFOTIPSIZE */
1247 WideCharToMultiByte(CP_ACP, 0, infoPtr->tools[nTool].lpszText, -1,
1248 lpToolInfo->lpszText, INFOTIPSIZE, NULL, NULL);
1255 TOOLTIPS_GetTextW (HWND hwnd, WPARAM wParam, LPARAM lParam)
1257 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1258 LPTTTOOLINFOW lpToolInfo = (LPTTTOOLINFOW)lParam;
1261 if (lpToolInfo == NULL)
1263 if (lpToolInfo->cbSize < TTTOOLINFOW_V1_SIZE)
1266 nTool = TOOLTIPS_GetToolFromInfoW (infoPtr, lpToolInfo);
1267 if (nTool == -1) return 0;
1269 strcpyW (lpToolInfo->lpszText, infoPtr->tools[nTool].lpszText);
1275 inline static LRESULT
1276 TOOLTIPS_GetTipBkColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
1278 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1279 return infoPtr->clrBk;
1283 inline static LRESULT
1284 TOOLTIPS_GetTipTextColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
1286 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1287 return infoPtr->clrText;
1291 inline static LRESULT
1292 TOOLTIPS_GetToolCount (HWND hwnd, WPARAM wParam, LPARAM lParam)
1294 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1295 return infoPtr->uNumTools;
1300 TOOLTIPS_GetToolInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
1302 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1303 LPTTTOOLINFOA lpToolInfo = (LPTTTOOLINFOA)lParam;
1304 TTTOOL_INFO *toolPtr;
1307 if (lpToolInfo == NULL)
1309 if (lpToolInfo->cbSize < TTTOOLINFOA_V1_SIZE)
1311 if (infoPtr->uNumTools == 0)
1314 nTool = TOOLTIPS_GetToolFromInfoA (infoPtr, lpToolInfo);
1318 TRACE("tool %d\n", nTool);
1320 toolPtr = &infoPtr->tools[nTool];
1322 /* copy tool data */
1323 lpToolInfo->uFlags = toolPtr->uFlags;
1324 lpToolInfo->rect = toolPtr->rect;
1325 lpToolInfo->hinst = toolPtr->hinst;
1326 /* lpToolInfo->lpszText = toolPtr->lpszText; */
1327 lpToolInfo->lpszText = NULL; /* FIXME */
1329 if (lpToolInfo->cbSize >= sizeof(TTTOOLINFOA))
1330 lpToolInfo->lParam = toolPtr->lParam;
1337 TOOLTIPS_GetToolInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
1339 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1340 LPTTTOOLINFOW lpToolInfo = (LPTTTOOLINFOW)lParam;
1341 TTTOOL_INFO *toolPtr;
1344 if (lpToolInfo == NULL)
1346 if (lpToolInfo->cbSize < TTTOOLINFOW_V1_SIZE)
1348 if (infoPtr->uNumTools == 0)
1351 nTool = TOOLTIPS_GetToolFromInfoW (infoPtr, lpToolInfo);
1355 TRACE("tool %d\n", nTool);
1357 toolPtr = &infoPtr->tools[nTool];
1359 /* copy tool data */
1360 lpToolInfo->uFlags = toolPtr->uFlags;
1361 lpToolInfo->rect = toolPtr->rect;
1362 lpToolInfo->hinst = toolPtr->hinst;
1363 /* lpToolInfo->lpszText = toolPtr->lpszText; */
1364 lpToolInfo->lpszText = NULL; /* FIXME */
1366 if (lpToolInfo->cbSize >= sizeof(TTTOOLINFOW))
1367 lpToolInfo->lParam = toolPtr->lParam;
1374 TOOLTIPS_HitTestA (HWND hwnd, WPARAM wParam, LPARAM lParam)
1376 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1377 LPTTHITTESTINFOA lptthit = (LPTTHITTESTINFOA)lParam;
1378 TTTOOL_INFO *toolPtr;
1384 nTool = TOOLTIPS_GetToolFromPoint (infoPtr, lptthit->hwnd, &lptthit->pt);
1388 TRACE("tool %d!\n", nTool);
1390 /* copy tool data */
1391 if (lptthit->ti.cbSize >= sizeof(TTTOOLINFOA)) {
1392 toolPtr = &infoPtr->tools[nTool];
1394 lptthit->ti.uFlags = toolPtr->uFlags;
1395 lptthit->ti.hwnd = toolPtr->hwnd;
1396 lptthit->ti.uId = toolPtr->uId;
1397 lptthit->ti.rect = toolPtr->rect;
1398 lptthit->ti.hinst = toolPtr->hinst;
1399 /* lptthit->ti.lpszText = toolPtr->lpszText; */
1400 lptthit->ti.lpszText = NULL; /* FIXME */
1401 lptthit->ti.lParam = toolPtr->lParam;
1409 TOOLTIPS_HitTestW (HWND hwnd, WPARAM wParam, LPARAM lParam)
1411 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1412 LPTTHITTESTINFOW lptthit = (LPTTHITTESTINFOW)lParam;
1413 TTTOOL_INFO *toolPtr;
1419 nTool = TOOLTIPS_GetToolFromPoint (infoPtr, lptthit->hwnd, &lptthit->pt);
1423 TRACE("tool %d!\n", nTool);
1425 /* copy tool data */
1426 if (lptthit->ti.cbSize >= sizeof(TTTOOLINFOW)) {
1427 toolPtr = &infoPtr->tools[nTool];
1429 lptthit->ti.uFlags = toolPtr->uFlags;
1430 lptthit->ti.hwnd = toolPtr->hwnd;
1431 lptthit->ti.uId = toolPtr->uId;
1432 lptthit->ti.rect = toolPtr->rect;
1433 lptthit->ti.hinst = toolPtr->hinst;
1434 /* lptthit->ti.lpszText = toolPtr->lpszText; */
1435 lptthit->ti.lpszText = NULL; /* FIXME */
1436 lptthit->ti.lParam = toolPtr->lParam;
1444 TOOLTIPS_NewToolRectA (HWND hwnd, WPARAM wParam, LPARAM lParam)
1446 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1447 LPTTTOOLINFOA lpti = (LPTTTOOLINFOA)lParam;
1452 if (lpti->cbSize < TTTOOLINFOA_V1_SIZE)
1455 nTool = TOOLTIPS_GetToolFromInfoA (infoPtr, lpti);
1457 TRACE("nTool = %d, rect = %s\n", nTool, wine_dbgstr_rect(&lpti->rect));
1459 if (nTool == -1) return 0;
1461 infoPtr->tools[nTool].rect = lpti->rect;
1468 TOOLTIPS_NewToolRectW (HWND hwnd, WPARAM wParam, LPARAM lParam)
1470 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1471 LPTTTOOLINFOW lpti = (LPTTTOOLINFOW)lParam;
1476 if (lpti->cbSize < TTTOOLINFOW_V1_SIZE)
1479 nTool = TOOLTIPS_GetToolFromInfoW (infoPtr, lpti);
1481 TRACE("nTool = %d, rect = %s\n", nTool, wine_dbgstr_rect(&lpti->rect));
1483 if (nTool == -1) return 0;
1485 infoPtr->tools[nTool].rect = lpti->rect;
1491 inline static LRESULT
1492 TOOLTIPS_Pop (HWND hwnd, WPARAM wParam, LPARAM lParam)
1494 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1495 TOOLTIPS_Hide (hwnd, infoPtr);
1502 TOOLTIPS_RelayEvent (HWND hwnd, WPARAM wParam, LPARAM lParam)
1504 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1505 LPMSG lpMsg = (LPMSG)lParam;
1510 ERR("lpMsg == NULL!\n");
1514 switch (lpMsg->message) {
1515 case WM_LBUTTONDOWN:
1517 case WM_MBUTTONDOWN:
1519 case WM_RBUTTONDOWN:
1521 TOOLTIPS_Hide (hwnd, infoPtr);
1525 pt.x = LOWORD(lpMsg->lParam);
1526 pt.y = HIWORD(lpMsg->lParam);
1527 nOldTool = infoPtr->nTool;
1528 infoPtr->nTool = TOOLTIPS_GetToolFromPoint(infoPtr, lpMsg->hwnd,
1530 TRACE("tool (%p) %d %d %d\n", hwnd, nOldTool,
1531 infoPtr->nTool, infoPtr->nCurrentTool);
1532 TRACE("WM_MOUSEMOVE (%p %ld %ld)\n", hwnd, pt.x, pt.y);
1534 if (infoPtr->nTool != nOldTool) {
1535 if(infoPtr->nTool == -1) { /* Moved out of all tools */
1536 TOOLTIPS_Hide(hwnd, infoPtr);
1537 KillTimer(hwnd, ID_TIMERLEAVE);
1538 } else if (nOldTool == -1) { /* Moved from outside */
1539 if(infoPtr->bActive) {
1540 SetTimer(hwnd, ID_TIMERSHOW, infoPtr->nInitialTime, 0);
1541 TRACE("timer 1 started!\n");
1543 } else { /* Moved from one to another */
1544 TOOLTIPS_Hide (hwnd, infoPtr);
1545 KillTimer(hwnd, ID_TIMERLEAVE);
1546 if(infoPtr->bActive) {
1547 SetTimer (hwnd, ID_TIMERSHOW, infoPtr->nReshowTime, 0);
1548 TRACE("timer 1 started!\n");
1551 } else if(infoPtr->nCurrentTool != -1) { /* restart autopop */
1552 KillTimer(hwnd, ID_TIMERPOP);
1553 SetTimer(hwnd, ID_TIMERPOP, infoPtr->nAutoPopTime, 0);
1554 TRACE("timer 2 restarted\n");
1564 TOOLTIPS_SetDelayTime (HWND hwnd, WPARAM wParam, LPARAM lParam)
1566 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1567 INT nTime = (INT)LOWORD(lParam);
1570 case TTDT_AUTOMATIC:
1572 nTime = GetDoubleClickTime();
1573 infoPtr->nReshowTime = nTime / 5;
1574 infoPtr->nAutoPopTime = nTime * 10;
1575 infoPtr->nInitialTime = nTime;
1580 nTime = GetDoubleClickTime() / 5;
1581 infoPtr->nReshowTime = nTime;
1586 nTime = GetDoubleClickTime() * 10;
1587 infoPtr->nAutoPopTime = nTime;
1592 nTime = GetDoubleClickTime();
1593 infoPtr->nInitialTime = nTime;
1597 WARN("Invalid wParam %x\n", wParam);
1606 TOOLTIPS_SetMargin (HWND hwnd, WPARAM wParam, LPARAM lParam)
1608 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1609 LPRECT lpRect = (LPRECT)lParam;
1611 infoPtr->rcMargin.left = lpRect->left;
1612 infoPtr->rcMargin.right = lpRect->right;
1613 infoPtr->rcMargin.bottom = lpRect->bottom;
1614 infoPtr->rcMargin.top = lpRect->top;
1620 inline static LRESULT
1621 TOOLTIPS_SetMaxTipWidth (HWND hwnd, WPARAM wParam, LPARAM lParam)
1623 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1624 INT nTemp = infoPtr->nMaxTipWidth;
1626 infoPtr->nMaxTipWidth = (INT)lParam;
1632 inline static LRESULT
1633 TOOLTIPS_SetTipBkColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
1635 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1637 infoPtr->clrBk = (COLORREF)wParam;
1643 inline static LRESULT
1644 TOOLTIPS_SetTipTextColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
1646 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1648 infoPtr->clrText = (COLORREF)wParam;
1655 TOOLTIPS_SetToolInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
1657 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1658 LPTTTOOLINFOA lpToolInfo = (LPTTTOOLINFOA)lParam;
1659 TTTOOL_INFO *toolPtr;
1662 if (lpToolInfo == NULL)
1664 if (lpToolInfo->cbSize < TTTOOLINFOA_V1_SIZE)
1667 nTool = TOOLTIPS_GetToolFromInfoA (infoPtr, lpToolInfo);
1668 if (nTool == -1) return 0;
1670 TRACE("tool %d\n", nTool);
1672 toolPtr = &infoPtr->tools[nTool];
1674 /* copy tool data */
1675 toolPtr->uFlags = lpToolInfo->uFlags;
1676 toolPtr->hwnd = lpToolInfo->hwnd;
1677 toolPtr->uId = lpToolInfo->uId;
1678 toolPtr->rect = lpToolInfo->rect;
1679 toolPtr->hinst = lpToolInfo->hinst;
1681 if (HIWORD(lpToolInfo->lpszText) == 0) {
1682 TRACE("set string id %x!\n", (INT)lpToolInfo->lpszText);
1683 toolPtr->lpszText = (LPWSTR)lpToolInfo->lpszText;
1685 else if (lpToolInfo->lpszText) {
1686 if (lpToolInfo->lpszText == LPSTR_TEXTCALLBACKA)
1687 toolPtr->lpszText = LPSTR_TEXTCALLBACKW;
1689 if ( (toolPtr->lpszText) &&
1690 (HIWORD((INT)toolPtr->lpszText) != 0) ) {
1691 Free (toolPtr->lpszText);
1692 toolPtr->lpszText = NULL;
1694 if (lpToolInfo->lpszText) {
1695 INT len = MultiByteToWideChar(CP_ACP, 0, lpToolInfo->lpszText,
1697 toolPtr->lpszText = Alloc (len * sizeof(WCHAR));
1698 MultiByteToWideChar(CP_ACP, 0, lpToolInfo->lpszText, -1,
1699 toolPtr->lpszText, len);
1704 if (lpToolInfo->cbSize >= sizeof(TTTOOLINFOA))
1705 toolPtr->lParam = lpToolInfo->lParam;
1712 TOOLTIPS_SetToolInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
1714 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1715 LPTTTOOLINFOW lpToolInfo = (LPTTTOOLINFOW)lParam;
1716 TTTOOL_INFO *toolPtr;
1719 if (lpToolInfo == NULL)
1721 if (lpToolInfo->cbSize < TTTOOLINFOW_V1_SIZE)
1724 nTool = TOOLTIPS_GetToolFromInfoW (infoPtr, lpToolInfo);
1725 if (nTool == -1) return 0;
1727 TRACE("tool %d\n", nTool);
1729 toolPtr = &infoPtr->tools[nTool];
1731 /* copy tool data */
1732 toolPtr->uFlags = lpToolInfo->uFlags;
1733 toolPtr->hwnd = lpToolInfo->hwnd;
1734 toolPtr->uId = lpToolInfo->uId;
1735 toolPtr->rect = lpToolInfo->rect;
1736 toolPtr->hinst = lpToolInfo->hinst;
1738 if (HIWORD(lpToolInfo->lpszText) == 0) {
1739 TRACE("set string id %x!\n", (INT)lpToolInfo->lpszText);
1740 toolPtr->lpszText = lpToolInfo->lpszText;
1742 else if (lpToolInfo->lpszText) {
1743 if (lpToolInfo->lpszText == LPSTR_TEXTCALLBACKW)
1744 toolPtr->lpszText = LPSTR_TEXTCALLBACKW;
1746 if ( (toolPtr->lpszText) &&
1747 (HIWORD((INT)toolPtr->lpszText) != 0) ) {
1748 Free (toolPtr->lpszText);
1749 toolPtr->lpszText = NULL;
1751 if (lpToolInfo->lpszText) {
1752 INT len = lstrlenW (lpToolInfo->lpszText);
1753 toolPtr->lpszText = Alloc ((len+1)*sizeof(WCHAR));
1754 strcpyW (toolPtr->lpszText, lpToolInfo->lpszText);
1759 if (lpToolInfo->cbSize >= sizeof(TTTOOLINFOW))
1760 toolPtr->lParam = lpToolInfo->lParam;
1767 TOOLTIPS_TrackActivate (HWND hwnd, WPARAM wParam, LPARAM lParam)
1769 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1772 LPTTTOOLINFOA lpToolInfo = (LPTTTOOLINFOA)lParam;
1774 if (lpToolInfo == NULL)
1776 if (lpToolInfo->cbSize < TTTOOLINFOA_V1_SIZE)
1780 infoPtr->nTrackTool = TOOLTIPS_GetToolFromInfoA (infoPtr, lpToolInfo);
1781 if (infoPtr->nTrackTool != -1) {
1782 TRACE("activated!\n");
1783 infoPtr->bTrackActive = TRUE;
1784 TOOLTIPS_TrackShow (hwnd, infoPtr);
1789 TOOLTIPS_TrackHide (hwnd, infoPtr);
1791 infoPtr->bTrackActive = FALSE;
1792 infoPtr->nTrackTool = -1;
1794 TRACE("deactivated!\n");
1802 TOOLTIPS_TrackPosition (HWND hwnd, WPARAM wParam, LPARAM lParam)
1804 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1806 infoPtr->xTrackPos = (INT)LOWORD(lParam);
1807 infoPtr->yTrackPos = (INT)HIWORD(lParam);
1809 if (infoPtr->bTrackActive) {
1811 infoPtr->xTrackPos, infoPtr->yTrackPos);
1813 TOOLTIPS_TrackShow (hwnd, infoPtr);
1821 TOOLTIPS_Update (HWND hwnd, WPARAM wParam, LPARAM lParam)
1823 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1825 if (infoPtr->nCurrentTool != -1)
1826 UpdateWindow (hwnd);
1833 TOOLTIPS_UpdateTipTextA (HWND hwnd, WPARAM wParam, LPARAM lParam)
1835 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1836 LPTTTOOLINFOA lpToolInfo = (LPTTTOOLINFOA)lParam;
1837 TTTOOL_INFO *toolPtr;
1840 if (lpToolInfo == NULL)
1842 if (lpToolInfo->cbSize < TTTOOLINFOA_V1_SIZE)
1845 nTool = TOOLTIPS_GetToolFromInfoA (infoPtr, lpToolInfo);
1846 if (nTool == -1) return 0;
1848 TRACE("tool %d\n", nTool);
1850 toolPtr = &infoPtr->tools[nTool];
1852 /* copy tool text */
1853 toolPtr->hinst = lpToolInfo->hinst;
1855 if (HIWORD(lpToolInfo->lpszText) == 0){
1856 toolPtr->lpszText = (LPWSTR)lpToolInfo->lpszText;
1858 else if (lpToolInfo->lpszText) {
1859 if (lpToolInfo->lpszText == LPSTR_TEXTCALLBACKA)
1860 toolPtr->lpszText = LPSTR_TEXTCALLBACKW;
1862 if ( (toolPtr->lpszText) &&
1863 (HIWORD((INT)toolPtr->lpszText) != 0) ) {
1864 Free (toolPtr->lpszText);
1865 toolPtr->lpszText = NULL;
1867 if (lpToolInfo->lpszText) {
1868 INT len = MultiByteToWideChar(CP_ACP, 0, lpToolInfo->lpszText,
1870 toolPtr->lpszText = Alloc (len * sizeof(WCHAR));
1871 MultiByteToWideChar(CP_ACP, 0, lpToolInfo->lpszText, -1,
1872 toolPtr->lpszText, len);
1877 if(infoPtr->nCurrentTool == -1) return 0;
1879 if (infoPtr->bActive)
1880 TOOLTIPS_Show (hwnd, infoPtr);
1881 else if (infoPtr->bTrackActive)
1882 TOOLTIPS_TrackShow (hwnd, infoPtr);
1889 TOOLTIPS_UpdateTipTextW (HWND hwnd, WPARAM wParam, LPARAM lParam)
1891 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1892 LPTTTOOLINFOW lpToolInfo = (LPTTTOOLINFOW)lParam;
1893 TTTOOL_INFO *toolPtr;
1896 if (lpToolInfo == NULL)
1898 if (lpToolInfo->cbSize < TTTOOLINFOW_V1_SIZE)
1901 nTool = TOOLTIPS_GetToolFromInfoW (infoPtr, lpToolInfo);
1905 TRACE("tool %d\n", nTool);
1907 toolPtr = &infoPtr->tools[nTool];
1909 /* copy tool text */
1910 toolPtr->hinst = lpToolInfo->hinst;
1912 if (HIWORD(lpToolInfo->lpszText) == 0){
1913 toolPtr->lpszText = lpToolInfo->lpszText;
1915 else if (lpToolInfo->lpszText) {
1916 if (lpToolInfo->lpszText == LPSTR_TEXTCALLBACKW)
1917 toolPtr->lpszText = LPSTR_TEXTCALLBACKW;
1919 if ( (toolPtr->lpszText) &&
1920 (HIWORD((INT)toolPtr->lpszText) != 0) ) {
1921 Free (toolPtr->lpszText);
1922 toolPtr->lpszText = NULL;
1924 if (lpToolInfo->lpszText) {
1925 INT len = lstrlenW (lpToolInfo->lpszText);
1926 toolPtr->lpszText = Alloc ((len+1)*sizeof(WCHAR));
1927 strcpyW (toolPtr->lpszText, lpToolInfo->lpszText);
1932 if(infoPtr->nCurrentTool == -1) return 0;
1934 if (infoPtr->bActive)
1935 TOOLTIPS_Show (hwnd, infoPtr);
1936 else if (infoPtr->bTrackActive)
1937 TOOLTIPS_TrackShow (hwnd, infoPtr);
1944 TOOLTIPS_WindowFromPoint (HWND hwnd, WPARAM wParam, LPARAM lParam)
1946 return (LRESULT)WindowFromPoint (*((LPPOINT)lParam));
1952 TOOLTIPS_Create (HWND hwnd, const CREATESTRUCTW *lpcs)
1954 TOOLTIPS_INFO *infoPtr;
1955 NONCLIENTMETRICSA nclm;
1957 /* allocate memory for info structure */
1958 infoPtr = (TOOLTIPS_INFO *)Alloc (sizeof(TOOLTIPS_INFO));
1959 SetWindowLongA (hwnd, 0, (DWORD)infoPtr);
1961 /* initialize info structure */
1962 infoPtr->bActive = TRUE;
1963 infoPtr->bTrackActive = FALSE;
1964 infoPtr->clrBk = GetSysColor (COLOR_INFOBK);
1965 infoPtr->clrText = GetSysColor (COLOR_INFOTEXT);
1967 nclm.cbSize = sizeof(NONCLIENTMETRICSA);
1968 SystemParametersInfoA (SPI_GETNONCLIENTMETRICS, 0, &nclm, 0);
1969 infoPtr->hFont = CreateFontIndirectA (&nclm.lfStatusFont);
1971 infoPtr->nMaxTipWidth = -1;
1972 infoPtr->nTool = -1;
1973 infoPtr->nCurrentTool = -1;
1974 infoPtr->nTrackTool = -1;
1976 TOOLTIPS_SetDelayTime(hwnd, TTDT_AUTOMATIC, 0L);
1978 SetWindowPos (hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOZORDER | SWP_HIDEWINDOW | SWP_NOACTIVATE);
1985 TOOLTIPS_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
1987 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
1988 TTTOOL_INFO *toolPtr;
1992 if (infoPtr->tools) {
1993 for (i = 0; i < infoPtr->uNumTools; i++) {
1994 toolPtr = &infoPtr->tools[i];
1995 if (toolPtr->lpszText) {
1996 if ( (toolPtr->lpszText != LPSTR_TEXTCALLBACKW) &&
1997 (HIWORD((INT)toolPtr->lpszText) != 0) )
1999 Free (toolPtr->lpszText);
2000 toolPtr->lpszText = NULL;
2004 /* remove subclassing */
2005 if (toolPtr->uFlags & TTF_SUBCLASS) {
2006 if (toolPtr->uFlags & TTF_IDISHWND) {
2007 RemoveWindowSubclass((HWND)toolPtr->uId, TOOLTIPS_SubclassProc, 1);
2010 RemoveWindowSubclass(toolPtr->hwnd, TOOLTIPS_SubclassProc, 1);
2014 Free (infoPtr->tools);
2018 DeleteObject (infoPtr->hFont);
2020 /* free tool tips info data */
2022 SetWindowLongA(hwnd, 0, 0);
2028 TOOLTIPS_EraseBackground (HWND hwnd, WPARAM wParam, LPARAM lParam)
2030 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
2034 hBrush = CreateSolidBrush (infoPtr->clrBk);
2035 GetClientRect (hwnd, &rect);
2036 FillRect ((HDC)wParam, &rect, hBrush);
2037 DeleteObject (hBrush);
2044 TOOLTIPS_GetFont (HWND hwnd, WPARAM wParam, LPARAM lParam)
2046 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
2048 return (LRESULT)infoPtr->hFont;
2053 TOOLTIPS_MouseMessage (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2055 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
2057 TOOLTIPS_Hide (hwnd, infoPtr);
2064 TOOLTIPS_NCCreate (HWND hwnd, WPARAM wParam, LPARAM lParam)
2066 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
2067 DWORD dwExStyle = GetWindowLongA (hwnd, GWL_EXSTYLE);
2069 dwStyle &= 0x0000FFFF;
2070 dwStyle |= (WS_POPUP | WS_BORDER | WS_CLIPSIBLINGS);
2071 SetWindowLongA (hwnd, GWL_STYLE, dwStyle);
2073 dwExStyle |= WS_EX_TOOLWINDOW;
2074 SetWindowLongA (hwnd, GWL_EXSTYLE, dwExStyle);
2081 TOOLTIPS_NCHitTest (HWND hwnd, WPARAM wParam, LPARAM lParam)
2083 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
2084 INT nTool = (infoPtr->bTrackActive) ? infoPtr->nTrackTool : infoPtr->nTool;
2086 TRACE(" nTool=%d\n", nTool);
2088 if ((nTool > -1) && (nTool < infoPtr->uNumTools)) {
2089 if (infoPtr->tools[nTool].uFlags & TTF_TRANSPARENT) {
2090 TRACE("-- in transparent mode!\n");
2091 return HTTRANSPARENT;
2095 return DefWindowProcA (hwnd, WM_NCHITTEST, wParam, lParam);
2100 TOOLTIPS_NotifyFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
2102 FIXME ("hwnd=%p wParam=%x lParam=%lx\n", hwnd, wParam, lParam);
2109 TOOLTIPS_Paint (HWND hwnd, WPARAM wParam, LPARAM lParam)
2114 hdc = (wParam == 0) ? BeginPaint (hwnd, &ps) : (HDC)wParam;
2115 TOOLTIPS_Refresh (hwnd, hdc);
2117 EndPaint (hwnd, &ps);
2123 TOOLTIPS_SetFont (HWND hwnd, WPARAM wParam, LPARAM lParam)
2125 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
2128 if(!GetObjectW((HFONT)wParam, sizeof(lf), &lf))
2131 if(infoPtr->hFont) DeleteObject (infoPtr->hFont);
2132 infoPtr->hFont = CreateFontIndirectW(&lf);
2134 if ((LOWORD(lParam)) & (infoPtr->nCurrentTool != -1)) {
2135 FIXME("full redraw needed!\n");
2140 /******************************************************************
2141 * TOOLTIPS_OnWMGetTextLength
2143 * This function is called when the tooltip receive a
2144 * WM_GETTEXTLENGTH message.
2148 * returns the length, in characters, of the tip text
2149 ******************************************************************/
2151 TOOLTIPS_OnWMGetTextLength(HWND hwnd, WPARAM wParam, LPARAM lParam)
2153 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
2154 return lstrlenW(infoPtr->szTipText);
2157 /******************************************************************
2158 * TOOLTIPS_OnWMGetText
2160 * This function is called when the tooltip receive a
2161 * WM_GETTEXT message.
2162 * wParam : specifies the maximum number of characters to be copied
2163 * lParam : is the pointer to the buffer that will receive
2166 * returns the number of characters copied
2167 ******************************************************************/
2169 TOOLTIPS_OnWMGetText (HWND hwnd, WPARAM wParam, LPARAM lParam)
2171 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
2173 if(!infoPtr || !(infoPtr->szTipText))
2176 return WideCharToMultiByte(CP_ACP, 0, infoPtr->szTipText, -1,
2177 (LPSTR)lParam, wParam, NULL, NULL);
2181 TOOLTIPS_Timer (HWND hwnd, WPARAM wParam, LPARAM lParam)
2183 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
2186 TRACE("timer %d (%p) expired!\n", wParam, hwnd);
2190 KillTimer (hwnd, ID_TIMERSHOW);
2191 nOldTool = infoPtr->nTool;
2192 if ((infoPtr->nTool = TOOLTIPS_CheckTool (hwnd, TRUE)) == nOldTool)
2193 TOOLTIPS_Show (hwnd, infoPtr);
2197 TOOLTIPS_Hide (hwnd, infoPtr);
2201 nOldTool = infoPtr->nTool;
2202 infoPtr->nTool = TOOLTIPS_CheckTool (hwnd, FALSE);
2203 TRACE("tool (%p) %d %d %d\n", hwnd, nOldTool,
2204 infoPtr->nTool, infoPtr->nCurrentTool);
2205 if (infoPtr->nTool != nOldTool) {
2206 if(infoPtr->nTool == -1) { /* Moved out of all tools */
2207 TOOLTIPS_Hide(hwnd, infoPtr);
2208 KillTimer(hwnd, ID_TIMERLEAVE);
2209 } else if (nOldTool == -1) { /* Moved from outside */
2210 ERR("How did this happen?\n");
2211 } else { /* Moved from one to another */
2212 TOOLTIPS_Hide (hwnd, infoPtr);
2213 KillTimer(hwnd, ID_TIMERLEAVE);
2214 if(infoPtr->bActive) {
2215 SetTimer (hwnd, ID_TIMERSHOW, infoPtr->nReshowTime, 0);
2216 TRACE("timer 1 started!\n");
2223 ERR("Unknown timer id %d\n", wParam);
2231 TOOLTIPS_WinIniChange (HWND hwnd, WPARAM wParam, LPARAM lParam)
2233 TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
2234 NONCLIENTMETRICSA nclm;
2236 infoPtr->clrBk = GetSysColor (COLOR_INFOBK);
2237 infoPtr->clrText = GetSysColor (COLOR_INFOTEXT);
2239 DeleteObject (infoPtr->hFont);
2240 nclm.cbSize = sizeof(NONCLIENTMETRICSA);
2241 SystemParametersInfoA (SPI_GETNONCLIENTMETRICS, 0, &nclm, 0);
2242 infoPtr->hFont = CreateFontIndirectA (&nclm.lfStatusFont);
2249 TOOLTIPS_SubclassProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uID, DWORD_PTR dwRef)
2255 case WM_LBUTTONDOWN:
2257 case WM_MBUTTONDOWN:
2259 case WM_RBUTTONDOWN:
2263 msg.wParam = wParam;
2264 msg.lParam = lParam;
2265 TOOLTIPS_RelayEvent((HWND)dwRef, 0, (LPARAM)&msg);
2271 return DefSubclassProc(hwnd, uMsg, wParam, lParam);
2275 static LRESULT CALLBACK
2276 TOOLTIPS_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2278 TRACE("hwnd=%p msg=%x wparam=%x lParam=%lx\n", hwnd, uMsg, wParam, lParam);
2279 if (!TOOLTIPS_GetInfoPtr(hwnd) && (uMsg != WM_CREATE) && (uMsg != WM_NCCREATE))
2280 return DefWindowProcA (hwnd, uMsg, wParam, lParam);
2284 return TOOLTIPS_Activate (hwnd, wParam, lParam);
2287 return TOOLTIPS_AddToolA (hwnd, wParam, lParam);
2290 return TOOLTIPS_AddToolW (hwnd, wParam, lParam);
2293 return TOOLTIPS_DelToolA (hwnd, wParam, lParam);
2296 return TOOLTIPS_DelToolW (hwnd, wParam, lParam);
2298 case TTM_ENUMTOOLSA:
2299 return TOOLTIPS_EnumToolsA (hwnd, wParam, lParam);
2301 case TTM_ENUMTOOLSW:
2302 return TOOLTIPS_EnumToolsW (hwnd, wParam, lParam);
2304 case TTM_GETBUBBLESIZE:
2305 return TOOLTIPS_GetBubbleSize (hwnd, wParam, lParam);
2307 case TTM_GETCURRENTTOOLA:
2308 return TOOLTIPS_GetCurrentToolA (hwnd, wParam, lParam);
2310 case TTM_GETCURRENTTOOLW:
2311 return TOOLTIPS_GetCurrentToolW (hwnd, wParam, lParam);
2313 case TTM_GETDELAYTIME:
2314 return TOOLTIPS_GetDelayTime (hwnd, wParam, lParam);
2317 return TOOLTIPS_GetMargin (hwnd, wParam, lParam);
2319 case TTM_GETMAXTIPWIDTH:
2320 return TOOLTIPS_GetMaxTipWidth (hwnd, wParam, lParam);
2323 return TOOLTIPS_GetTextA (hwnd, wParam, lParam);
2326 return TOOLTIPS_GetTextW (hwnd, wParam, lParam);
2328 case TTM_GETTIPBKCOLOR:
2329 return TOOLTIPS_GetTipBkColor (hwnd, wParam, lParam);
2331 case TTM_GETTIPTEXTCOLOR:
2332 return TOOLTIPS_GetTipTextColor (hwnd, wParam, lParam);
2334 case TTM_GETTOOLCOUNT:
2335 return TOOLTIPS_GetToolCount (hwnd, wParam, lParam);
2337 case TTM_GETTOOLINFOA:
2338 return TOOLTIPS_GetToolInfoA (hwnd, wParam, lParam);
2340 case TTM_GETTOOLINFOW:
2341 return TOOLTIPS_GetToolInfoW (hwnd, wParam, lParam);
2344 return TOOLTIPS_HitTestA (hwnd, wParam, lParam);
2347 return TOOLTIPS_HitTestW (hwnd, wParam, lParam);
2349 case TTM_NEWTOOLRECTA:
2350 return TOOLTIPS_NewToolRectA (hwnd, wParam, lParam);
2352 case TTM_NEWTOOLRECTW:
2353 return TOOLTIPS_NewToolRectW (hwnd, wParam, lParam);
2356 return TOOLTIPS_Pop (hwnd, wParam, lParam);
2358 case TTM_RELAYEVENT:
2359 return TOOLTIPS_RelayEvent (hwnd, wParam, lParam);
2361 case TTM_SETDELAYTIME:
2362 return TOOLTIPS_SetDelayTime (hwnd, wParam, lParam);
2365 return TOOLTIPS_SetMargin (hwnd, wParam, lParam);
2367 case TTM_SETMAXTIPWIDTH:
2368 return TOOLTIPS_SetMaxTipWidth (hwnd, wParam, lParam);
2370 case TTM_SETTIPBKCOLOR:
2371 return TOOLTIPS_SetTipBkColor (hwnd, wParam, lParam);
2373 case TTM_SETTIPTEXTCOLOR:
2374 return TOOLTIPS_SetTipTextColor (hwnd, wParam, lParam);
2376 case TTM_SETTOOLINFOA:
2377 return TOOLTIPS_SetToolInfoA (hwnd, wParam, lParam);
2379 case TTM_SETTOOLINFOW:
2380 return TOOLTIPS_SetToolInfoW (hwnd, wParam, lParam);
2382 case TTM_TRACKACTIVATE:
2383 return TOOLTIPS_TrackActivate (hwnd, wParam, lParam);
2385 case TTM_TRACKPOSITION:
2386 return TOOLTIPS_TrackPosition (hwnd, wParam, lParam);
2389 return TOOLTIPS_Update (hwnd, wParam, lParam);
2391 case TTM_UPDATETIPTEXTA:
2392 return TOOLTIPS_UpdateTipTextA (hwnd, wParam, lParam);
2394 case TTM_UPDATETIPTEXTW:
2395 return TOOLTIPS_UpdateTipTextW (hwnd, wParam, lParam);
2397 case TTM_WINDOWFROMPOINT:
2398 return TOOLTIPS_WindowFromPoint (hwnd, wParam, lParam);
2402 return TOOLTIPS_Create (hwnd, (LPCREATESTRUCTW)lParam);
2405 return TOOLTIPS_Destroy (hwnd, wParam, lParam);
2408 return TOOLTIPS_EraseBackground (hwnd, wParam, lParam);
2411 return TOOLTIPS_GetFont (hwnd, wParam, lParam);
2414 return TOOLTIPS_OnWMGetText (hwnd, wParam, lParam);
2416 case WM_GETTEXTLENGTH:
2417 return TOOLTIPS_OnWMGetTextLength (hwnd, wParam, lParam);
2420 case WM_LBUTTONDOWN:
2422 case WM_MBUTTONDOWN:
2424 case WM_RBUTTONDOWN:
2427 return TOOLTIPS_MouseMessage (hwnd, uMsg, wParam, lParam);
2430 return TOOLTIPS_NCCreate (hwnd, wParam, lParam);
2433 return TOOLTIPS_NCHitTest (hwnd, wParam, lParam);
2435 case WM_NOTIFYFORMAT:
2436 return TOOLTIPS_NotifyFormat (hwnd, wParam, lParam);
2439 return TOOLTIPS_Paint (hwnd, wParam, lParam);
2442 return TOOLTIPS_SetFont (hwnd, wParam, lParam);
2445 return TOOLTIPS_Timer (hwnd, wParam, lParam);
2447 case WM_WININICHANGE:
2448 return TOOLTIPS_WinIniChange (hwnd, wParam, lParam);
2451 if ((uMsg >= WM_USER) && (uMsg < WM_APP))
2452 ERR("unknown msg %04x wp=%08x lp=%08lx\n",
2453 uMsg, wParam, lParam);
2454 return DefWindowProcA (hwnd, uMsg, wParam, lParam);
2461 TOOLTIPS_Register (void)
2465 ZeroMemory (&wndClass, sizeof(WNDCLASSA));
2466 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS | CS_SAVEBITS;
2467 wndClass.lpfnWndProc = (WNDPROC)TOOLTIPS_WindowProc;
2468 wndClass.cbClsExtra = 0;
2469 wndClass.cbWndExtra = sizeof(TOOLTIPS_INFO *);
2470 wndClass.hCursor = LoadCursorA (0, (LPSTR)IDC_ARROW);
2471 wndClass.hbrBackground = 0;
2472 wndClass.lpszClassName = TOOLTIPS_CLASSA;
2474 RegisterClassA (&wndClass);
2479 TOOLTIPS_Unregister (void)
2481 UnregisterClassA (TOOLTIPS_CLASSA, NULL);