/* * Create a tooltip for the control passed as first parameter * duration sets the duration in ms. Use -1 for default * message is an UTF-8 string */ BOOL CreateTooltip(HWND hControl, const char* message, int duration) { TOOLINFOW toolInfo = {0}; int i; if ( (hControl == NULL) || (message == NULL) ) { return FALSE; } // Destroy existing tooltip if any DestroyTooltip(hControl); // Find an empty slot for (i=0; i<MAX_TOOLTIPS; i++) { if (ttlist[i].hTip == NULL) break; } if (i >= MAX_TOOLTIPS) { uprintf("Maximum number of tooltips reached (%d)\n", MAX_TOOLTIPS); return FALSE; } // Create the tooltip window ttlist[i].hTip = CreateWindowExW(0, TOOLTIPS_CLASSW, NULL, WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, hMainDialog, NULL, hMainInstance, NULL); if (ttlist[i].hTip == NULL) { return FALSE; } ttlist[i].hCtrl = hControl; // Subclass the tooltip to handle multiline ttlist[i].original_proc = (WNDPROC)SetWindowLongPtr(ttlist[i].hTip, GWLP_WNDPROC, (LONG_PTR)TooltipCallback); // Set the string to display (can be multiline) ttlist[i].wstring = utf8_to_wchar(message); // Set tooltip duration (ms) PostMessage(ttlist[i].hTip, TTM_SETDELAYTIME, (WPARAM)TTDT_AUTOPOP, (LPARAM)duration); // Associate the tooltip to the control toolInfo.cbSize = sizeof(toolInfo); toolInfo.hwnd = ttlist[i].hTip; // Set to the tooltip itself to ease up subclassing toolInfo.uFlags = TTF_IDISHWND | TTF_SUBCLASS | ((right_to_left_mode)?TTF_RTLREADING:0); toolInfo.uId = (UINT_PTR)hControl; toolInfo.lpszText = LPSTR_TEXTCALLBACKW; SendMessageW(ttlist[i].hTip, TTM_ADDTOOLW, 0, (LPARAM)&toolInfo); return TRUE; }
nsresult nsXULTooltipListener::HideTooltip() { mCachedMouseEvent = nsnull; #ifdef MOZ_XUL nsCOMPtr<nsIContent> currentTooltip = do_QueryReferent(mCurrentTooltip); if (currentTooltip) { nsXULPopupManager* pm = nsXULPopupManager::GetInstance(); if (pm) pm->HidePopup(currentTooltip, PR_FALSE, PR_FALSE, PR_FALSE); } #endif DestroyTooltip(); return NS_OK; }
NS_IMETHODIMP nsXULTooltipListener::PopupHiding(nsIDOMEvent* aEvent) { DestroyTooltip(); return NS_OK; }