Something went wrong. Try again.
Reactos
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408/* * Tool tip control * * Copyright 1998, 1999 Eric Kohl * Copyright 2004 Robert Shearman * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA * * NOTES * * This code was audited for completeness against the documented features * of Comctl32.dll version 6.0 on Sep. 08, 2004, by Robert Shearman. * * Unless otherwise noted, we believe this code to be complete, as per * the specification mentioned above. * If you discover missing features or bugs please note them below. * * TODO: * - Custom draw support. * - Animation. * - Links. * - Messages: * o TTM_ADJUSTRECT * o TTM_GETTITLEA * o TTM_GETTTILEW * o TTM_POPUP * - Styles: * o TTS_NOANIMATE * o TTS_NOFADE * o TTS_CLOSE * * Testing: * - Run tests using Waite Group Windows95 API Bible Volume 2. * The second cdrom (chapter 3) contains executables activate.exe, * curtool.exe, deltool.exe, enumtools.exe, getinfo.exe, getiptxt.exe, * hittest.exe, needtext.exe, newrect.exe, updtext.exe and winfrpt.exe. * * Timer logic. * * One important point to remember is that tools don't necessarily get * a WM_MOUSEMOVE once the cursor leaves the tool, an example is when * a tool sets TTF_IDISHWND (i.e. an entire window is a tool) because * here WM_MOUSEMOVEs only get sent when the cursor is inside the * client area. Therefore the only reliable way to know that the * cursor has left a tool is to keep a timer running and check the * position every time it expires. This is the role of timer * ID_TIMERLEAVE. * * * On entering a tool (detected in a relayed WM_MOUSEMOVE) we start * ID_TIMERSHOW, if this times out and we're still in the tool we show * the tip. On showing a tip we start both ID_TIMERPOP and * ID_TIMERLEAVE. On hiding a tooltip we kill ID_TIMERPOP. * ID_TIMERPOP is restarted on every relayed WM_MOUSEMOVE. If * ID_TIMERPOP expires the tool is hidden and ID_TIMERPOP is killed. * ID_TIMERLEAVE remains running - this is important as we need to * determine when the cursor leaves the tool. * * When ID_TIMERLEAVE expires or on a relayed WM_MOUSEMOVE if we're * still in the tool do nothing (apart from restart ID_TIMERPOP if * this is a WM_MOUSEMOVE) (ID_TIMERLEAVE remains running). If we've * left the tool and entered another one then hide the tip and start * ID_TIMERSHOW with time ReshowTime and kill ID_TIMERLEAVE. If we're * outside all tools hide the tip and kill ID_TIMERLEAVE. On Relayed * mouse button messages hide the tip but leave ID_TIMERLEAVE running, * this again will let us keep track of when the cursor leaves the * tool. * * * infoPtr->nTool is the tool the mouse was on on the last relayed MM * or timer expiry or -1 if the mouse was not on a tool. * * infoPtr->nCurrentTool is the tool for which the tip is currently * displaying text for or -1 if the tip is not shown. Actually this * will only ever be infoPtr-nTool or -1, so it could be changed to a * BOOL. * */
#include <stdarg.h>#include <string.h>#include <stdlib.h>
#include "windef.h"#include "winbase.h"#include "wingdi.h"#include "winuser.h"#include "winnls.h"#include "commctrl.h"#include "comctl32.h"#include "wine/debug.h"
WINE_DEFAULT_DEBUG_CHANNEL(tooltips);
static HICON hTooltipIcons[TTI_ERROR+1];
typedef struct{ UINT uFlags; UINT uInternalFlags; HWND hwnd; BOOL bNotifyUnicode; UINT_PTR uId; RECT rect; HINSTANCE hinst; LPWSTR lpszText; LPARAM lParam;} TTTOOL_INFO;
typedef struct{ HWND hwndSelf; WCHAR szTipText[INFOTIPSIZE]; BOOL bActive; BOOL bTrackActive; UINT uNumTools; COLORREF clrBk; COLORREF clrText; HFONT hFont; HFONT hTitleFont; INT xTrackPos; INT yTrackPos; INT nMaxTipWidth; INT nTool; /* tool that mouse was on on last relayed mouse move */ INT nCurrentTool; INT nTrackTool; INT nReshowTime; INT nAutoPopTime; INT nInitialTime; RECT rcMargin; BOOL bToolBelow; LPWSTR pszTitle; HICON hTitleIcon;
TTTOOL_INFO *tools;} TOOLTIPS_INFO;
#define ID_TIMERSHOW 1 /* show delay timer */#define ID_TIMERPOP 2 /* auto pop timer */#define ID_TIMERLEAVE 3 /* tool leave timer */
#define TOOLTIPS_GetInfoPtr(hWindow) ((TOOLTIPS_INFO *)GetWindowLongPtrW (hWindow, 0))
/* offsets from window edge to start of text */#define NORMAL_TEXT_MARGIN 2#define BALLOON_TEXT_MARGIN (NORMAL_TEXT_MARGIN+8)/* value used for CreateRoundRectRgn that specifies how much * each corner is curved */#ifdef __REACTOS__#define BALLOON_ROUNDEDNESS 16#define BALLOON_STEMHEIGHT 18#define BALLOON_STEMWIDTH 18#define BALLOON_STEMINDENT 16#else#define BALLOON_ROUNDEDNESS 20#define BALLOON_STEMHEIGHT 13#define BALLOON_STEMWIDTH 10#define BALLOON_STEMINDENT 20#endif // __REACTOS__
#define BALLOON_ICON_TITLE_SPACING 8 /* horizontal spacing between icon and title */#define BALLOON_TITLE_TEXT_SPACING 8 /* vertical spacing between icon/title and main text */#define ICON_HEIGHT 16#define ICON_WIDTH 16
#define MAX_TEXT_SIZE_A 80 /* maximum retrieving text size by ANSI message */
static LRESULT CALLBACKTOOLTIPS_SubclassProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uId, DWORD_PTR dwRef);
static inline UINT_PTRTOOLTIPS_GetTitleIconIndex(HICON hIcon){ UINT i; for (i = 0; i <= TTI_ERROR; i++) if (hTooltipIcons[i] == hIcon) return i; return (UINT_PTR)hIcon;}
static voidTOOLTIPS_InitSystemSettings (TOOLTIPS_INFO *infoPtr){ NONCLIENTMETRICSW nclm;
infoPtr->clrBk = comctl32_color.clrInfoBk; infoPtr->clrText = comctl32_color.clrInfoText;
DeleteObject (infoPtr->hFont); nclm.cbSize = sizeof(nclm); SystemParametersInfoW (SPI_GETNONCLIENTMETRICS, sizeof(nclm), &nclm, 0); infoPtr->hFont = CreateFontIndirectW (&nclm.lfStatusFont);
DeleteObject (infoPtr->hTitleFont); nclm.lfStatusFont.lfWeight = FW_BOLD; infoPtr->hTitleFont = CreateFontIndirectW (&nclm.lfStatusFont);}
/* Custom draw routines */static voidTOOLTIPS_customdraw_fill(const TOOLTIPS_INFO *infoPtr, NMTTCUSTOMDRAW *lpnmttcd, HDC hdc, const RECT *rcBounds, UINT uFlags){ ZeroMemory(lpnmttcd, sizeof(NMTTCUSTOMDRAW)); lpnmttcd->uDrawFlags = uFlags; lpnmttcd->nmcd.hdr.hwndFrom = infoPtr->hwndSelf; lpnmttcd->nmcd.hdr.code = NM_CUSTOMDRAW; if (infoPtr->nCurrentTool != -1) { TTTOOL_INFO *toolPtr = &infoPtr->tools[infoPtr->nCurrentTool]; lpnmttcd->nmcd.hdr.idFrom = toolPtr->uId; } lpnmttcd->nmcd.hdc = hdc; lpnmttcd->nmcd.rc = *rcBounds; /* FIXME - dwItemSpec, uItemState, lItemlParam */}
static inline DWORDTOOLTIPS_notify_customdraw (DWORD dwDrawStage, NMTTCUSTOMDRAW *lpnmttcd){ LRESULT result; lpnmttcd->nmcd.dwDrawStage = dwDrawStage;
TRACE("Notifying stage %d, flags %x, id %x\n", lpnmttcd->nmcd.dwDrawStage, lpnmttcd->uDrawFlags, lpnmttcd->nmcd.hdr.code);
result = SendMessageW(GetParent(lpnmttcd->nmcd.hdr.hwndFrom), WM_NOTIFY, 0, (LPARAM)lpnmttcd);
TRACE("Notify result %x\n", (unsigned int)result);
return result;}
static voidTOOLTIPS_Refresh (const TOOLTIPS_INFO *infoPtr, HDC hdc){ RECT rc; INT oldBkMode; HFONT hOldFont; HBRUSH hBrush; UINT uFlags = DT_EXTERNALLEADING; HRGN hRgn = NULL; DWORD dwStyle = GetWindowLongW(infoPtr->hwndSelf, GWL_STYLE); NMTTCUSTOMDRAW nmttcd; DWORD cdmode;
if (infoPtr->nMaxTipWidth > -1) uFlags |= DT_WORDBREAK; if (GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE) & TTS_NOPREFIX) uFlags |= DT_NOPREFIX; GetClientRect (infoPtr->hwndSelf, &rc);
hBrush = CreateSolidBrush(infoPtr->clrBk);
oldBkMode = SetBkMode (hdc, TRANSPARENT); SetTextColor (hdc, infoPtr->clrText); hOldFont = SelectObject (hdc, infoPtr->hFont);
/* Custom draw - Call PrePaint once initial properties set up */ /* Note: Contrary to MSDN, CDRF_SKIPDEFAULT still draws a tooltip */ TOOLTIPS_customdraw_fill(infoPtr, &nmttcd, hdc, &rc, uFlags); cdmode = TOOLTIPS_notify_customdraw(CDDS_PREPAINT, &nmttcd); uFlags = nmttcd.uDrawFlags;
if (dwStyle & TTS_BALLOON) { /* create a region to store result into */ hRgn = CreateRectRgn(0, 0, 0, 0);
GetWindowRgn(infoPtr->hwndSelf, hRgn);
/* fill the background */ FillRgn(hdc, hRgn, hBrush); DeleteObject(hBrush); hBrush = NULL; } else { /* fill the background */ FillRect(hdc, &rc, hBrush); DeleteObject(hBrush); hBrush = NULL; }
if ((dwStyle & TTS_BALLOON) || infoPtr->pszTitle) { /* calculate text rectangle */ rc.left += (BALLOON_TEXT_MARGIN + infoPtr->rcMargin.left); rc.top += (BALLOON_TEXT_MARGIN + infoPtr->rcMargin.top); rc.right -= (BALLOON_TEXT_MARGIN + infoPtr->rcMargin.right); rc.bottom -= (BALLOON_TEXT_MARGIN + infoPtr->rcMargin.bottom); if(infoPtr->bToolBelow) rc.top += BALLOON_STEMHEIGHT;
if (infoPtr->pszTitle) { RECT rcTitle = {rc.left, rc.top, rc.right, rc.bottom}; int height; BOOL icon_present; HFONT prevFont;
/* draw icon */ icon_present = infoPtr->hTitleIcon && DrawIconEx(hdc, rc.left, rc.top, infoPtr->hTitleIcon, ICON_WIDTH, ICON_HEIGHT, 0, NULL, DI_NORMAL); if (icon_present) rcTitle.left += ICON_WIDTH + BALLOON_ICON_TITLE_SPACING;
rcTitle.bottom = rc.top + ICON_HEIGHT;
/* draw title text */ prevFont = SelectObject (hdc, infoPtr->hTitleFont); height = DrawTextW(hdc, infoPtr->pszTitle, -1, &rcTitle, DT_BOTTOM | DT_SINGLELINE | DT_NOPREFIX); SelectObject (hdc, prevFont); rc.top += height + BALLOON_TITLE_TEXT_SPACING; } } else { /* calculate text rectangle */ rc.left += (NORMAL_TEXT_MARGIN + infoPtr->rcMargin.left); rc.top += (NORMAL_TEXT_MARGIN + infoPtr->rcMargin.top); rc.right -= (NORMAL_TEXT_MARGIN + infoPtr->rcMargin.right); rc.bottom -= (NORMAL_TEXT_MARGIN + infoPtr->rcMargin.bottom); }
/* draw text */#ifdef __REACTOS__ uFlags |= DT_EXPANDTABS;#endif DrawTextW (hdc, infoPtr->szTipText, -1, &rc, uFlags);
/* Custom draw - Call PostPaint after drawing */ if (cdmode & CDRF_NOTIFYPOSTPAINT) { TOOLTIPS_notify_customdraw(CDDS_POSTPAINT, &nmttcd); }
/* be polite and reset the things we changed in the dc */ SelectObject (hdc, hOldFont); SetBkMode (hdc, oldBkMode);
if (dwStyle & TTS_BALLOON) { /* frame region because default window proc doesn't do it */ INT width = GetSystemMetrics(SM_CXDLGFRAME) - GetSystemMetrics(SM_CXEDGE); INT height = GetSystemMetrics(SM_CYDLGFRAME) - GetSystemMetrics(SM_CYEDGE);
hBrush = GetSysColorBrush(COLOR_WINDOWFRAME); FrameRgn(hdc, hRgn, hBrush, width, height); }
if (hRgn) DeleteObject(hRgn);}
static void TOOLTIPS_GetDispInfoA(const TOOLTIPS_INFO *infoPtr, TTTOOL_INFO *toolPtr, WCHAR *buffer){ NMTTDISPINFOA ttnmdi;
/* fill NMHDR struct */ ZeroMemory (&ttnmdi, sizeof(NMTTDISPINFOA)); ttnmdi.hdr.hwndFrom = infoPtr->hwndSelf; ttnmdi.hdr.idFrom = toolPtr->uId; ttnmdi.hdr.code = TTN_GETDISPINFOA; /* == TTN_NEEDTEXTA */ ttnmdi.lpszText = ttnmdi.szText; ttnmdi.uFlags = toolPtr->uFlags; ttnmdi.lParam = toolPtr->lParam;
TRACE("hdr.idFrom = %lx\n", ttnmdi.hdr.idFrom); SendMessageW(toolPtr->hwnd, WM_NOTIFY, toolPtr->uId, (LPARAM)&ttnmdi);
if (IS_INTRESOURCE(ttnmdi.lpszText)) { LoadStringW(ttnmdi.hinst, LOWORD(ttnmdi.lpszText), buffer, INFOTIPSIZE); if (ttnmdi.uFlags & TTF_DI_SETITEM) { toolPtr->hinst = ttnmdi.hinst; toolPtr->lpszText = (LPWSTR)ttnmdi.lpszText; } } else if (ttnmdi.lpszText == 0) { buffer[0] = '\0'; } else if (ttnmdi.lpszText != LPSTR_TEXTCALLBACKA) { Str_GetPtrAtoW(ttnmdi.lpszText, buffer, INFOTIPSIZE); if (ttnmdi.uFlags & TTF_DI_SETITEM) { toolPtr->hinst = 0; toolPtr->lpszText = NULL; Str_SetPtrW(&toolPtr->lpszText, buffer); } } else { ERR("recursive text callback\n"); buffer[0] = '\0'; }
#ifndef __REACTOS_ /* no text available - try calling parent instead as per native */ /* FIXME: Unsure if SETITEM should save the value or not */ if (buffer[0] == 0x00) {
SendMessageW(GetParent(toolPtr->hwnd), WM_NOTIFY, toolPtr->uId, (LPARAM)&ttnmdi);
if (IS_INTRESOURCE(ttnmdi.lpszText)) { LoadStringW(ttnmdi.hinst, LOWORD(ttnmdi.lpszText), buffer, INFOTIPSIZE); } else if (ttnmdi.lpszText && ttnmdi.lpszText != LPSTR_TEXTCALLBACKA) { Str_GetPtrAtoW(ttnmdi.lpszText, buffer, INFOTIPSIZE); } }#endif}
static void TOOLTIPS_GetDispInfoW(const TOOLTIPS_INFO *infoPtr, TTTOOL_INFO *toolPtr, WCHAR *buffer){ NMTTDISPINFOW ttnmdi;
/* fill NMHDR struct */ ZeroMemory (&ttnmdi, sizeof(NMTTDISPINFOW)); ttnmdi.hdr.hwndFrom = infoPtr->hwndSelf; ttnmdi.hdr.idFrom = toolPtr->uId; ttnmdi.hdr.code = TTN_GETDISPINFOW; /* == TTN_NEEDTEXTW */ ttnmdi.lpszText = ttnmdi.szText; ttnmdi.uFlags = toolPtr->uFlags; ttnmdi.lParam = toolPtr->lParam;
TRACE("hdr.idFrom = %lx\n", ttnmdi.hdr.idFrom); SendMessageW(toolPtr->hwnd, WM_NOTIFY, toolPtr->uId, (LPARAM)&ttnmdi);
if (IS_INTRESOURCE(ttnmdi.lpszText)) { LoadStringW(ttnmdi.hinst, LOWORD(ttnmdi.lpszText), buffer, INFOTIPSIZE); if (ttnmdi.uFlags & TTF_DI_SETITEM) { toolPtr->hinst = ttnmdi.hinst; toolPtr->lpszText = ttnmdi.lpszText; } } else if (ttnmdi.lpszText == 0) { buffer[0] = '\0'; } else if (ttnmdi.lpszText != LPSTR_TEXTCALLBACKW) { Str_GetPtrW(ttnmdi.lpszText, buffer, INFOTIPSIZE); if (ttnmdi.uFlags & TTF_DI_SETITEM) { toolPtr->hinst = 0; toolPtr->lpszText = NULL; Str_SetPtrW(&toolPtr->lpszText, buffer); } } else { ERR("recursive text callback\n"); buffer[0] = '\0'; }
#ifndef __REACTOS__ /* no text available - try calling parent instead as per native */ /* FIXME: Unsure if SETITEM should save the value or not */ if (buffer[0] == 0x00) {
SendMessageW(GetParent(toolPtr->hwnd), WM_NOTIFY, toolPtr->uId, (LPARAM)&ttnmdi);
if (IS_INTRESOURCE(ttnmdi.lpszText)) { LoadStringW(ttnmdi.hinst, LOWORD(ttnmdi.lpszText), buffer, INFOTIPSIZE); } else if (ttnmdi.lpszText && ttnmdi.lpszText != LPSTR_TEXTCALLBACKW) { Str_GetPtrW(ttnmdi.lpszText, buffer, INFOTIPSIZE); } }#endif
}
static voidTOOLTIPS_GetTipText (const TOOLTIPS_INFO *infoPtr, INT nTool, WCHAR *buffer){ TTTOOL_INFO *toolPtr = &infoPtr->tools[nTool];
if (IS_INTRESOURCE(toolPtr->lpszText)) { /* load a resource */ TRACE("load res string %p %x\n", toolPtr->hinst, LOWORD(toolPtr->lpszText)); if (!LoadStringW (toolPtr->hinst, LOWORD(toolPtr->lpszText), buffer, INFOTIPSIZE)) buffer[0] = '\0'; } else if (toolPtr->lpszText) { if (toolPtr->lpszText == LPSTR_TEXTCALLBACKW) { if (toolPtr->bNotifyUnicode) TOOLTIPS_GetDispInfoW(infoPtr, toolPtr, buffer); else TOOLTIPS_GetDispInfoA(infoPtr, toolPtr, buffer); } else { /* the item is a usual (unicode) text */ lstrcpynW (buffer, toolPtr->lpszText, INFOTIPSIZE); } } else { /* no text available */ buffer[0] = '\0'; }
if (!(GetWindowLongW(infoPtr->hwndSelf, GWL_STYLE) & TTS_NOPREFIX)) { WCHAR *ptrW; if ((ptrW = wcschr(buffer, '\t'))) *ptrW = 0; }
TRACE("%s\n", debugstr_w(buffer));}
static voidTOOLTIPS_CalcTipSize (const TOOLTIPS_INFO *infoPtr, LPSIZE lpSize){ HDC hdc; HFONT hOldFont; DWORD style = GetWindowLongW(infoPtr->hwndSelf, GWL_STYLE); UINT uFlags = DT_EXTERNALLEADING | DT_CALCRECT; RECT rc = {0, 0, 0, 0}; SIZE title = {0, 0};
if (infoPtr->nMaxTipWidth > -1) { rc.right = infoPtr->nMaxTipWidth; uFlags |= DT_WORDBREAK; } if (style & TTS_NOPREFIX) uFlags |= DT_NOPREFIX; TRACE("%s\n", debugstr_w(infoPtr->szTipText));
hdc = GetDC (infoPtr->hwndSelf); if (infoPtr->pszTitle) { RECT rcTitle = {0, 0, 0, 0}; TRACE("title %s\n", debugstr_w(infoPtr->pszTitle)); if (infoPtr->hTitleIcon) { title.cx = ICON_WIDTH; title.cy = ICON_HEIGHT; } if (title.cx != 0) title.cx += BALLOON_ICON_TITLE_SPACING; hOldFont = SelectObject (hdc, infoPtr->hTitleFont); DrawTextW(hdc, infoPtr->pszTitle, -1, &rcTitle, DT_SINGLELINE | DT_NOPREFIX | DT_CALCRECT); SelectObject (hdc, hOldFont); title.cy = max(title.cy, rcTitle.bottom - rcTitle.top) + BALLOON_TITLE_TEXT_SPACING; title.cx += (rcTitle.right - rcTitle.left); } hOldFont = SelectObject (hdc, infoPtr->hFont);#ifdef __REACTOS__ uFlags |= DT_EXPANDTABS;#endif DrawTextW (hdc, infoPtr->szTipText, -1, &rc, uFlags); SelectObject (hdc, hOldFont); ReleaseDC (infoPtr->hwndSelf, hdc);
if ((style & TTS_BALLOON) || infoPtr->pszTitle) { lpSize->cx = max(rc.right - rc.left, title.cx) + 2*BALLOON_TEXT_MARGIN + infoPtr->rcMargin.left + infoPtr->rcMargin.right; lpSize->cy = title.cy + rc.bottom - rc.top + 2*BALLOON_TEXT_MARGIN + infoPtr->rcMargin.bottom + infoPtr->rcMargin.top + BALLOON_STEMHEIGHT; } else { lpSize->cx = rc.right - rc.left + 2*NORMAL_TEXT_MARGIN + infoPtr->rcMargin.left + infoPtr->rcMargin.right; lpSize->cy = rc.bottom - rc.top + 2*NORMAL_TEXT_MARGIN + infoPtr->rcMargin.bottom + infoPtr->rcMargin.top; }}
static voidTOOLTIPS_Show (TOOLTIPS_INFO *infoPtr, BOOL track_activate){ TTTOOL_INFO *toolPtr; HMONITOR monitor; MONITORINFO mon_info; RECT rect; SIZE size; NMHDR hdr; int ptfx = 0; DWORD style = GetWindowLongW(infoPtr->hwndSelf, GWL_STYLE); INT nTool, current;
if (track_activate) { if (infoPtr->nTrackTool == -1) { TRACE("invalid tracking tool %d\n", infoPtr->nTrackTool); return; } nTool = infoPtr->nTrackTool; } else { if (infoPtr->nTool == -1) { TRACE("invalid tool %d\n", infoPtr->nTool); return; } nTool = infoPtr->nTool; }
TRACE("Show tooltip pre %d, %p\n", nTool, infoPtr->hwndSelf);
current = infoPtr->nCurrentTool; if (!track_activate) infoPtr->nCurrentTool = infoPtr->nTool;
TOOLTIPS_GetTipText (infoPtr, nTool, infoPtr->szTipText);
if (infoPtr->szTipText[0] == '\0') { infoPtr->nCurrentTool = current; return; }
toolPtr = &infoPtr->tools[nTool]; TOOLTIPS_CalcTipSize (infoPtr, &size);
TRACE("Show tooltip %d, %s, size %d x %d\n", nTool, debugstr_w(infoPtr->szTipText), size.cx, size.cy);
if (track_activate && (toolPtr->uFlags & TTF_TRACK)) { rect.left = infoPtr->xTrackPos; rect.top = infoPtr->yTrackPos; ptfx = rect.left;
if (toolPtr->uFlags & TTF_CENTERTIP) { rect.left -= (size.cx / 2); if (!(style & TTS_BALLOON)) rect.top -= (size.cy / 2); } if (!(infoPtr->bToolBelow = (infoPtr->yTrackPos + size.cy <= GetSystemMetrics(SM_CYSCREEN)))) rect.top -= size.cy;
if (!(toolPtr->uFlags & TTF_ABSOLUTE)) { if (style & TTS_BALLOON) rect.left -= BALLOON_STEMINDENT; else { RECT rcTool;
if (toolPtr->uFlags & TTF_IDISHWND) GetWindowRect ((HWND)toolPtr->uId, &rcTool); else { rcTool = toolPtr->rect; MapWindowPoints (toolPtr->hwnd, NULL, (LPPOINT)&rcTool, 2); }
/* smart placement */ if ((rect.left + size.cx > rcTool.left) && (rect.left < rcTool.right) && (rect.top + size.cy > rcTool.top) && (rect.top < rcTool.bottom)) rect.left = rcTool.right; } } } else { if (toolPtr->uFlags & TTF_CENTERTIP) { RECT rc;
if (toolPtr->uFlags & TTF_IDISHWND) GetWindowRect ((HWND)toolPtr->uId, &rc); else { rc = toolPtr->rect; MapWindowPoints (toolPtr->hwnd, NULL, (LPPOINT)&rc, 2); } rect.left = (rc.left + rc.right - size.cx) / 2; if (style & TTS_BALLOON) { ptfx = rc.left + ((rc.right - rc.left) / 2);
/* CENTERTIP ballon tooltips default to below the field * if they fit on the screen */ if (rc.bottom + size.cy > GetSystemMetrics(SM_CYSCREEN)) { rect.top = rc.top - size.cy; infoPtr->bToolBelow = FALSE; } else { infoPtr->bToolBelow = TRUE; rect.top = rc.bottom; } rect.left = max(0, rect.left - BALLOON_STEMINDENT); } else { rect.top = rc.bottom + 2; infoPtr->bToolBelow = TRUE; } } else { GetCursorPos ((LPPOINT)&rect); if (style & TTS_BALLOON) { ptfx = rect.left; if(rect.top - size.cy >= 0) { rect.top -= size.cy; infoPtr->bToolBelow = FALSE; } else { infoPtr->bToolBelow = TRUE; rect.top += 20; } rect.left = max(0, rect.left - BALLOON_STEMINDENT); } else { rect.top += 20; infoPtr->bToolBelow = TRUE; } } }
TRACE("pos %d - %d\n", rect.left, rect.top);
rect.right = rect.left + size.cx; rect.bottom = rect.top + size.cy;
/* check position */
monitor = MonitorFromRect( &rect, MONITOR_DEFAULTTOPRIMARY ); mon_info.cbSize = sizeof(mon_info); GetMonitorInfoW( monitor, &mon_info );
#ifdef __REACTOS__ if (rect.right > mon_info.rcMonitor.right) { rect.left -= size.cx - (BALLOON_STEMINDENT + BALLOON_STEMWIDTH); rect.right -= size.cx - (BALLOON_STEMINDENT + BALLOON_STEMWIDTH); if (rect.right > mon_info.rcMonitor.right) { rect.left -= (rect.right - mon_info.rcMonitor.right); rect.right = mon_info.rcMonitor.right; } }
if (rect.left < mon_info.rcMonitor.left) { rect.right += abs(rect.left); rect.left = 0; }
if (rect.bottom > mon_info.rcMonitor.bottom) { RECT rc; if (toolPtr->uFlags & TTF_IDISHWND) { GetWindowRect((HWND)toolPtr->uId, &rc); } else { rc = toolPtr->rect; MapWindowPoints(toolPtr->hwnd, NULL, (LPPOINT)&rc, 2); } rect.bottom = rc.top - 2; rect.top = rect.bottom - size.cy; }#else if( rect.right > mon_info.rcWork.right ) { rect.left -= rect.right - mon_info.rcWork.right + 2; rect.right = mon_info.rcWork.right - 2; } if (rect.left < mon_info.rcWork.left) rect.left = mon_info.rcWork.left;
if( rect.bottom > mon_info.rcWork.bottom ) { RECT rc;
if (toolPtr->uFlags & TTF_IDISHWND) GetWindowRect ((HWND)toolPtr->uId, &rc); else { rc = toolPtr->rect; MapWindowPoints (toolPtr->hwnd, NULL, (LPPOINT)&rc, 2); } rect.bottom = rc.top - 2; rect.top = rect.bottom - size.cy; }#endif // __REACTOS__
AdjustWindowRectEx (&rect, GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE), FALSE, GetWindowLongW (infoPtr->hwndSelf, GWL_EXSTYLE));
if (style & TTS_BALLOON) { HRGN hRgn; HRGN hrStem; POINT pts[3];
ptfx -= rect.left;
if(infoPtr->bToolBelow) { pts[0].x = ptfx; pts[0].y = 0;#ifdef __REACTOS__ pts[1].x = max(BALLOON_STEMINDENT, ptfx - BALLOON_STEMWIDTH);#else pts[1].x = max(BALLOON_STEMINDENT, ptfx - (BALLOON_STEMWIDTH / 2));#endif pts[1].y = BALLOON_STEMHEIGHT; pts[2].x = pts[1].x + BALLOON_STEMWIDTH; pts[2].y = pts[1].y; if(pts[2].x > (rect.right - rect.left) - BALLOON_STEMINDENT) { pts[2].x = (rect.right - rect.left) - BALLOON_STEMINDENT; pts[1].x = pts[2].x - BALLOON_STEMWIDTH; } } else {#ifdef __REACTOS__ pts[0].x = max(BALLOON_STEMINDENT, ptfx - BALLOON_STEMWIDTH);#else pts[0].x = max(BALLOON_STEMINDENT, ptfx - (BALLOON_STEMWIDTH / 2));#endif pts[0].y = (rect.bottom - rect.top) - BALLOON_STEMHEIGHT; pts[1].x = pts[0].x + BALLOON_STEMWIDTH; pts[1].y = pts[0].y; pts[2].x = ptfx; pts[2].y = (rect.bottom - rect.top); if(pts[1].x > (rect.right - rect.left) - BALLOON_STEMINDENT) { pts[1].x = (rect.right - rect.left) - BALLOON_STEMINDENT; pts[0].x = pts[1].x - BALLOON_STEMWIDTH; } }
hrStem = CreatePolygonRgn(pts, ARRAY_SIZE(pts), ALTERNATE); hRgn = CreateRoundRectRgn(0, (infoPtr->bToolBelow ? BALLOON_STEMHEIGHT : 0), rect.right - rect.left,#ifdef __REACTOS__ (infoPtr->bToolBelow ? rect.bottom - rect.top : rect.bottom - rect.top - BALLOON_STEMHEIGHT + 1),#else (infoPtr->bToolBelow ? rect.bottom - rect.top : rect.bottom - rect.top - BALLOON_STEMHEIGHT),#endif BALLOON_ROUNDEDNESS, BALLOON_ROUNDEDNESS);
CombineRgn(hRgn, hRgn, hrStem, RGN_OR); DeleteObject(hrStem);
SetWindowRgn(infoPtr->hwndSelf, hRgn, FALSE); /* we don't free the region handle as the system deletes it when * it is no longer needed */ }
SetWindowPos (infoPtr->hwndSelf, NULL, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, SWP_NOZORDER | SWP_NOACTIVATE);
hdr.hwndFrom = infoPtr->hwndSelf; hdr.idFrom = toolPtr->uId; hdr.code = TTN_SHOW; SendMessageW (toolPtr->hwnd, WM_NOTIFY, toolPtr->uId, (LPARAM)&hdr);
SetWindowPos (infoPtr->hwndSelf, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_SHOWWINDOW | SWP_NOACTIVATE);
/* repaint the tooltip */ InvalidateRect(infoPtr->hwndSelf, NULL, TRUE); UpdateWindow(infoPtr->hwndSelf);
if (!track_activate) { SetTimer (infoPtr->hwndSelf, ID_TIMERPOP, infoPtr->nAutoPopTime, 0); TRACE("timer 2 started\n"); SetTimer (infoPtr->hwndSelf, ID_TIMERLEAVE, infoPtr->nReshowTime, 0); TRACE("timer 3 started\n"); }}
static voidTOOLTIPS_Hide (TOOLTIPS_INFO *infoPtr){ TTTOOL_INFO *toolPtr; NMHDR hdr;
TRACE("Hide tooltip %d, %p.\n", infoPtr->nCurrentTool, infoPtr->hwndSelf);
if (infoPtr->nCurrentTool == -1) return;
toolPtr = &infoPtr->tools[infoPtr->nCurrentTool]; KillTimer (infoPtr->hwndSelf, ID_TIMERPOP);
hdr.hwndFrom = infoPtr->hwndSelf; hdr.idFrom = toolPtr->uId; hdr.code = TTN_POP; SendMessageW (toolPtr->hwnd, WM_NOTIFY, toolPtr->uId, (LPARAM)&hdr);
infoPtr->nCurrentTool = -1;
SetWindowPos (infoPtr->hwndSelf, HWND_TOP, 0, 0, 0, 0, SWP_NOZORDER | SWP_HIDEWINDOW | SWP_NOACTIVATE);}
static voidTOOLTIPS_TrackShow (TOOLTIPS_INFO *infoPtr){ TOOLTIPS_Show(infoPtr, TRUE);}
static voidTOOLTIPS_TrackHide (const TOOLTIPS_INFO *infoPtr){ TTTOOL_INFO *toolPtr; NMHDR hdr;
TRACE("hide tracking tooltip %d\n", infoPtr->nTrackTool);
if (infoPtr->nTrackTool == -1) return;
toolPtr = &infoPtr->tools[infoPtr->nTrackTool];
hdr.hwndFrom = infoPtr->hwndSelf; hdr.idFrom = toolPtr->uId; hdr.code = TTN_POP; SendMessageW (toolPtr->hwnd, WM_NOTIFY, toolPtr->uId, (LPARAM)&hdr);
SetWindowPos (infoPtr->hwndSelf, HWND_TOP, 0, 0, 0, 0, SWP_NOZORDER | SWP_HIDEWINDOW | SWP_NOACTIVATE);}
/* Structure layout is the same for TTTOOLINFOW and TTTOOLINFOA, this helper is used in both cases. */static INTTOOLTIPS_GetToolFromInfoT (const TOOLTIPS_INFO *infoPtr, const TTTOOLINFOW *lpToolInfo){ TTTOOL_INFO *toolPtr; UINT nTool;
for (nTool = 0; nTool < infoPtr->uNumTools; nTool++) { toolPtr = &infoPtr->tools[nTool];
if (!(toolPtr->uFlags & TTF_IDISHWND) && (lpToolInfo->hwnd == toolPtr->hwnd) && (lpToolInfo->uId == toolPtr->uId)) return nTool; }
for (nTool = 0; nTool < infoPtr->uNumTools; nTool++) { toolPtr = &infoPtr->tools[nTool];
if ((toolPtr->uFlags & TTF_IDISHWND) && (lpToolInfo->uId == toolPtr->uId)) return nTool; }
return -1;}
static INTTOOLTIPS_GetToolFromPoint (const TOOLTIPS_INFO *infoPtr, HWND hwnd, const POINT *lpPt){ TTTOOL_INFO *toolPtr; UINT nTool;
for (nTool = 0; nTool < infoPtr->uNumTools; nTool++) { toolPtr = &infoPtr->tools[nTool];
if (!(toolPtr->uFlags & TTF_IDISHWND)) { if (hwnd != toolPtr->hwnd) continue; if (!PtInRect (&toolPtr->rect, *lpPt)) continue; return nTool; } }
for (nTool = 0; nTool < infoPtr->uNumTools; nTool++) { toolPtr = &infoPtr->tools[nTool];
if (toolPtr->uFlags & TTF_IDISHWND) { if ((HWND)toolPtr->uId == hwnd) return nTool; } }
return -1;}
static inline voidTOOLTIPS_CopyInfoT (const TOOLTIPS_INFO *infoPtr, INT index, TTTOOLINFOW *ti, BOOL isW){ const TTTOOL_INFO *toolPtr = &infoPtr->tools[index];
ti->uFlags = toolPtr->uFlags; ti->hwnd = toolPtr->hwnd; ti->uId = toolPtr->uId; ti->rect = toolPtr->rect; ti->hinst = toolPtr->hinst;
if (ti->lpszText) { if (toolPtr->lpszText == NULL || IS_INTRESOURCE(toolPtr->lpszText) || toolPtr->lpszText == LPSTR_TEXTCALLBACKW) ti->lpszText = toolPtr->lpszText; else if (isW) lstrcpyW (ti->lpszText, toolPtr->lpszText); else /* ANSI version, the buffer is maximum 80 bytes without null. */ WideCharToMultiByte(CP_ACP, 0, toolPtr->lpszText, -1, (LPSTR)ti->lpszText, MAX_TEXT_SIZE_A, NULL, NULL); }
if (ti->cbSize >= TTTOOLINFOW_V2_SIZE) ti->lParam = toolPtr->lParam;
/* lpReserved is intentionally not set. */}
static BOOLTOOLTIPS_IsWindowActive (HWND hwnd){ HWND hwndActive = GetActiveWindow (); if (!hwndActive) return FALSE; if (hwndActive == hwnd) return TRUE; return IsChild (hwndActive, hwnd);}
static INTTOOLTIPS_CheckTool (const TOOLTIPS_INFO *infoPtr, BOOL bShowTest){ POINT pt; HWND hwndTool; INT nTool;
GetCursorPos (&pt); hwndTool = (HWND)SendMessageW (infoPtr->hwndSelf, TTM_WINDOWFROMPOINT, 0, (LPARAM)&pt); if (hwndTool == 0) return -1;
ScreenToClient (hwndTool, &pt); nTool = TOOLTIPS_GetToolFromPoint (infoPtr, hwndTool, &pt); if (nTool == -1) return -1;
if (!(GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE) & TTS_ALWAYSTIP) && bShowTest) { TTTOOL_INFO *ti = &infoPtr->tools[nTool]; HWND hwnd = (ti->uFlags & TTF_IDISHWND) ? (HWND)ti->uId : ti->hwnd;
if (!TOOLTIPS_IsWindowActive(hwnd)) { TRACE("not active: hwnd %p, parent %p, active %p\n", hwnd, GetParent(hwnd), GetActiveWindow()); return -1; } }
TRACE("tool %d\n", nTool);
return nTool;}
static LRESULTTOOLTIPS_Activate (TOOLTIPS_INFO *infoPtr, BOOL activate){ infoPtr->bActive = activate;
TRACE("activate %d\n", activate);
if (!(infoPtr->bActive) && (infoPtr->nCurrentTool != -1)) TOOLTIPS_Hide (infoPtr);
return 0;}
static LRESULTTOOLTIPS_AddToolT (TOOLTIPS_INFO *infoPtr, const TTTOOLINFOW *ti, BOOL isW){ TTTOOL_INFO *toolPtr; INT nResult;
if (!ti) return FALSE;
TRACE("add tool (%p) %p %ld%s\n", infoPtr->hwndSelf, ti->hwnd, ti->uId, (ti->uFlags & TTF_IDISHWND) ? " TTF_IDISHWND" : "");
if (ti->cbSize > TTTOOLINFOW_V3_SIZE && isW) return FALSE;
if (infoPtr->uNumTools == 0) { infoPtr->tools = Alloc (sizeof(TTTOOL_INFO)); toolPtr = infoPtr->tools; } else { TTTOOL_INFO *oldTools = infoPtr->tools; infoPtr->tools = Alloc (sizeof(TTTOOL_INFO) * (infoPtr->uNumTools + 1)); memcpy (infoPtr->tools, oldTools, infoPtr->uNumTools * sizeof(TTTOOL_INFO)); Free (oldTools); toolPtr = &infoPtr->tools[infoPtr->uNumTools]; }
infoPtr->uNumTools++;
/* copy tool data */ toolPtr->uFlags = ti->uFlags; toolPtr->uInternalFlags = (ti->uFlags & (TTF_SUBCLASS | TTF_IDISHWND)); toolPtr->hwnd = ti->hwnd; toolPtr->uId = ti->uId; toolPtr->rect = ti->rect; toolPtr->hinst = ti->hinst;
if (ti->cbSize >= TTTOOLINFOW_V1_SIZE) { if (IS_INTRESOURCE(ti->lpszText)) { TRACE("add string id %x\n", LOWORD(ti->lpszText)); toolPtr->lpszText = ti->lpszText; } else if (ti->lpszText) { if (ti->lpszText == LPSTR_TEXTCALLBACKW) { TRACE("add CALLBACK\n"); toolPtr->lpszText = LPSTR_TEXTCALLBACKW; } else if (isW) { INT len = lstrlenW (ti->lpszText); TRACE("add text %s\n", debugstr_w(ti->lpszText)); toolPtr->lpszText = Alloc ((len + 1)*sizeof(WCHAR)); lstrcpyW (toolPtr->lpszText, ti->lpszText); } else { INT len = MultiByteToWideChar(CP_ACP, 0, (LPSTR)ti->lpszText, -1, NULL, 0); TRACE("add text \"%s\"\n", debugstr_a((char *)ti->lpszText)); toolPtr->lpszText = Alloc (len * sizeof(WCHAR)); MultiByteToWideChar(CP_ACP, 0, (LPSTR)ti->lpszText, -1, toolPtr->lpszText, len); } } }
if (ti->cbSize >= TTTOOLINFOW_V2_SIZE) toolPtr->lParam = ti->lParam;
/* install subclassing hook */ if (toolPtr->uInternalFlags & TTF_SUBCLASS) { if (toolPtr->uInternalFlags & TTF_IDISHWND) { SetWindowSubclass((HWND)toolPtr->uId, TOOLTIPS_SubclassProc, 1, (DWORD_PTR)infoPtr->hwndSelf); } else { SetWindowSubclass(toolPtr->hwnd, TOOLTIPS_SubclassProc, 1, (DWORD_PTR)infoPtr->hwndSelf); } TRACE("subclassing installed\n"); }
nResult = SendMessageW (toolPtr->hwnd, WM_NOTIFYFORMAT, (WPARAM)infoPtr->hwndSelf, NF_QUERY); if (nResult == NFR_ANSI) { toolPtr->bNotifyUnicode = FALSE; TRACE(" -- WM_NOTIFYFORMAT returns: NFR_ANSI\n"); } else if (nResult == NFR_UNICODE) { toolPtr->bNotifyUnicode = TRUE; TRACE(" -- WM_NOTIFYFORMAT returns: NFR_UNICODE\n"); } else { TRACE (" -- WM_NOTIFYFORMAT returns: %d\n", nResult); }
return TRUE;}
static void TOOLTIPS_ResetSubclass (const TTTOOL_INFO *toolPtr){ /* Reset subclassing data. */ if (toolPtr->uInternalFlags & TTF_SUBCLASS) SetWindowSubclass(toolPtr->uInternalFlags & TTF_IDISHWND ? (HWND)toolPtr->uId : toolPtr->hwnd, TOOLTIPS_SubclassProc, 1, 0);}
static void TOOLTIPS_FreeToolText(TTTOOL_INFO *toolPtr){ if (toolPtr->lpszText) { if (!IS_INTRESOURCE(toolPtr->lpszText) && toolPtr->lpszText != LPSTR_TEXTCALLBACKW) Free(toolPtr->lpszText); toolPtr->lpszText = NULL; }}
static void TOOLTIPS_SetToolText(TTTOOL_INFO *toolPtr, WCHAR *text, BOOL is_unicode){ int len;
TOOLTIPS_FreeToolText (toolPtr);
if (IS_INTRESOURCE(text)) toolPtr->lpszText = text; else if (text == LPSTR_TEXTCALLBACKW) toolPtr->lpszText = LPSTR_TEXTCALLBACKW; else if (text) { if (is_unicode) { len = lstrlenW(text); toolPtr->lpszText = Alloc ((len + 1) * sizeof(WCHAR)); if (toolPtr->lpszText) lstrcpyW (toolPtr->lpszText, text); } else { len = MultiByteToWideChar(CP_ACP, 0, (char *)text, -1, NULL, 0); toolPtr->lpszText = Alloc (len * sizeof(WCHAR)); if (toolPtr->lpszText) MultiByteToWideChar(CP_ACP, 0, (char *)text, -1, toolPtr->lpszText, len); } }}
static LRESULTTOOLTIPS_DelToolT (TOOLTIPS_INFO *infoPtr, const TTTOOLINFOW *ti, BOOL isW){ TTTOOL_INFO *toolPtr; INT nTool;
if (!ti) return 0; if (isW && ti->cbSize > TTTOOLINFOW_V2_SIZE && ti->cbSize != TTTOOLINFOW_V3_SIZE) return 0; if (infoPtr->uNumTools == 0) return 0;
nTool = TOOLTIPS_GetToolFromInfoT (infoPtr, ti);
TRACE("tool %d\n", nTool);
if (nTool == -1) return 0;
/* make sure the tooltip has disappeared before deleting it */ TOOLTIPS_Hide(infoPtr);
toolPtr = &infoPtr->tools[nTool]; TOOLTIPS_FreeToolText (toolPtr); TOOLTIPS_ResetSubclass (toolPtr);
/* delete tool from tool list */ if (infoPtr->uNumTools == 1) { Free (infoPtr->tools); infoPtr->tools = NULL; } else { TTTOOL_INFO *oldTools = infoPtr->tools; infoPtr->tools = Alloc (sizeof(TTTOOL_INFO) * (infoPtr->uNumTools - 1));
if (nTool > 0) memcpy (&infoPtr->tools[0], &oldTools[0], nTool * sizeof(TTTOOL_INFO));
if (nTool < infoPtr->uNumTools - 1) memcpy (&infoPtr->tools[nTool], &oldTools[nTool + 1], (infoPtr->uNumTools - nTool - 1) * sizeof(TTTOOL_INFO));
Free (oldTools); }
/* update any indices affected by delete */
/* destroying tool that mouse was on on last relayed mouse move */ if (infoPtr->nTool == nTool) /* -1 means no current tool (0 means first tool) */ infoPtr->nTool = -1; else if (infoPtr->nTool > nTool) infoPtr->nTool--;
if (infoPtr->nTrackTool == nTool) /* -1 means no current tool (0 means first tool) */ infoPtr->nTrackTool = -1; else if (infoPtr->nTrackTool > nTool) infoPtr->nTrackTool--;
if (infoPtr->nCurrentTool == nTool) /* -1 means no current tool (0 means first tool) */ infoPtr->nCurrentTool = -1; else if (infoPtr->nCurrentTool > nTool) infoPtr->nCurrentTool--;
infoPtr->uNumTools--;
return 0;}
static LRESULTTOOLTIPS_EnumToolsT (const TOOLTIPS_INFO *infoPtr, UINT uIndex, TTTOOLINFOW *ti, BOOL isW){ if (!ti || ti->cbSize < TTTOOLINFOW_V1_SIZE) return FALSE; if (uIndex >= infoPtr->uNumTools) return FALSE;
TRACE("index=%u\n", uIndex);
TOOLTIPS_CopyInfoT (infoPtr, uIndex, ti, isW);
return TRUE;}
static LRESULTTOOLTIPS_GetBubbleSize (const TOOLTIPS_INFO *infoPtr, const TTTOOLINFOW *lpToolInfo){ INT nTool; SIZE size;
if (lpToolInfo == NULL) return FALSE; if (lpToolInfo->cbSize < TTTOOLINFOW_V1_SIZE) return FALSE;
nTool = TOOLTIPS_GetToolFromInfoT (infoPtr, lpToolInfo); if (nTool == -1) return 0;
TRACE("tool %d\n", nTool);
TOOLTIPS_CalcTipSize (infoPtr, &size); TRACE("size %d x %d\n", size.cx, size.cy);
return MAKELRESULT(size.cx, size.cy);}
static LRESULTTOOLTIPS_GetCurrentToolT (const TOOLTIPS_INFO *infoPtr, TTTOOLINFOW *ti, BOOL isW){ if (ti) { if (ti->cbSize < TTTOOLINFOW_V1_SIZE) return FALSE;
if (infoPtr->nCurrentTool != -1) TOOLTIPS_CopyInfoT (infoPtr, infoPtr->nCurrentTool, ti, isW); }
return infoPtr->nCurrentTool != -1;}
static LRESULTTOOLTIPS_GetDelayTime (const TOOLTIPS_INFO *infoPtr, DWORD duration){ switch (duration) { case TTDT_RESHOW: return infoPtr->nReshowTime;
case TTDT_AUTOPOP: return infoPtr->nAutoPopTime;
case TTDT_INITIAL: case TTDT_AUTOMATIC: /* Apparently TTDT_AUTOMATIC returns TTDT_INITIAL */ return infoPtr->nInitialTime;
default: WARN("Invalid duration flag %x\n", duration); break; }
return -1;}
static LRESULTTOOLTIPS_GetMargin (const TOOLTIPS_INFO *infoPtr, RECT *rect){ if (rect) *rect = infoPtr->rcMargin;
return 0;}
static inline LRESULTTOOLTIPS_GetMaxTipWidth (const TOOLTIPS_INFO *infoPtr){ return infoPtr->nMaxTipWidth;}
static LRESULTTOOLTIPS_GetTextT (const TOOLTIPS_INFO *infoPtr, TTTOOLINFOW *ti, BOOL isW){ INT nTool;
if (!ti) return 0; if (ti->cbSize < TTTOOLINFOW_V1_SIZE) return 0;
nTool = TOOLTIPS_GetToolFromInfoT (infoPtr, ti); if (nTool == -1) return 0;
if (infoPtr->tools[nTool].lpszText == NULL) return 0;
if (isW) { ti->lpszText[0] = '\0'; TOOLTIPS_GetTipText(infoPtr, nTool, ti->lpszText); } else { WCHAR buffer[INFOTIPSIZE];
/* NB this API is broken, there is no way for the app to determine what size buffer it requires nor a way to specify how long the one it supplies is. According to the test result, it's up to 80 bytes by the ANSI version. */
buffer[0] = '\0'; TOOLTIPS_GetTipText(infoPtr, nTool, buffer); WideCharToMultiByte(CP_ACP, 0, buffer, -1, (LPSTR)ti->lpszText, MAX_TEXT_SIZE_A, NULL, NULL); }
return 0;}
static inline LRESULTTOOLTIPS_GetTipBkColor (const TOOLTIPS_INFO *infoPtr){ return infoPtr->clrBk;}
static inline LRESULTTOOLTIPS_GetTipTextColor (const TOOLTIPS_INFO *infoPtr){ return infoPtr->clrText;}
static inline LRESULTTOOLTIPS_GetToolCount (const TOOLTIPS_INFO *infoPtr){ return infoPtr->uNumTools;}
static LRESULTTOOLTIPS_GetToolInfoT (const TOOLTIPS_INFO *infoPtr, TTTOOLINFOW *ti, BOOL isW){ INT nTool; HWND hwnd;
if (!ti) return FALSE; if (ti->cbSize < TTTOOLINFOW_V1_SIZE) return FALSE; if (infoPtr->uNumTools == 0) return FALSE;
nTool = TOOLTIPS_GetToolFromInfoT (infoPtr, ti); if (nTool == -1) return FALSE;
TRACE("tool %d\n", nTool);
hwnd = ti->hwnd; TOOLTIPS_CopyInfoT (infoPtr, nTool, ti, isW); ti->hwnd = hwnd;
return TRUE;}
static LRESULTTOOLTIPS_HitTestT (const TOOLTIPS_INFO *infoPtr, LPTTHITTESTINFOW lptthit, BOOL isW){ INT nTool;
if (lptthit == 0) return FALSE;
nTool = TOOLTIPS_GetToolFromPoint (infoPtr, lptthit->hwnd, &lptthit->pt); if (nTool == -1) return FALSE;
TRACE("tool %d\n", nTool);
/* copy tool data */ if (lptthit->ti.cbSize >= TTTOOLINFOW_V1_SIZE) TOOLTIPS_CopyInfoT (infoPtr, nTool, &lptthit->ti, isW);
return TRUE;}
static LRESULTTOOLTIPS_NewToolRectT (TOOLTIPS_INFO *infoPtr, const TTTOOLINFOW *ti){ INT nTool;
if (!ti) return 0; if (ti->cbSize < TTTOOLINFOW_V1_SIZE) return FALSE;
nTool = TOOLTIPS_GetToolFromInfoT (infoPtr, ti);
TRACE("nTool = %d, rect = %s\n", nTool, wine_dbgstr_rect(&ti->rect));
if (nTool == -1) return 0;
infoPtr->tools[nTool].rect = ti->rect;
return 0;}
static inline LRESULTTOOLTIPS_Pop (TOOLTIPS_INFO *infoPtr){ TOOLTIPS_Hide (infoPtr);
return 0;}
static LRESULTTOOLTIPS_RelayEvent (TOOLTIPS_INFO *infoPtr, LPMSG lpMsg){ POINT pt; INT nOldTool;
if (!lpMsg) { ERR("lpMsg == NULL\n"); return 0; }
switch (lpMsg->message) { case WM_LBUTTONDOWN: case WM_LBUTTONUP: case WM_MBUTTONDOWN: case WM_MBUTTONUP: case WM_RBUTTONDOWN: case WM_RBUTTONUP: TOOLTIPS_Hide (infoPtr); break;
case WM_MOUSEMOVE: pt.x = (short)LOWORD(lpMsg->lParam); pt.y = (short)HIWORD(lpMsg->lParam); nOldTool = infoPtr->nTool; infoPtr->nTool = TOOLTIPS_GetToolFromPoint(infoPtr, lpMsg->hwnd, &pt); TRACE("tool (%p) %d %d %d\n", infoPtr->hwndSelf, nOldTool, infoPtr->nTool, infoPtr->nCurrentTool); TRACE("WM_MOUSEMOVE (%p %s)\n", infoPtr->hwndSelf, wine_dbgstr_point(&pt));
if (infoPtr->nTool != nOldTool) { if(infoPtr->nTool == -1) { /* Moved out of all tools */ TOOLTIPS_Hide(infoPtr); KillTimer(infoPtr->hwndSelf, ID_TIMERLEAVE); } else if (nOldTool == -1) { /* Moved from outside */ if(infoPtr->bActive) { SetTimer(infoPtr->hwndSelf, ID_TIMERSHOW, infoPtr->nInitialTime, 0); TRACE("timer 1 started\n"); } } else { /* Moved from one to another */ TOOLTIPS_Hide (infoPtr); KillTimer(infoPtr->hwndSelf, ID_TIMERLEAVE); if(infoPtr->bActive) { SetTimer (infoPtr->hwndSelf, ID_TIMERSHOW, infoPtr->nReshowTime, 0); TRACE("timer 1 started\n"); } } } else if(infoPtr->nCurrentTool != -1) { /* restart autopop */ KillTimer(infoPtr->hwndSelf, ID_TIMERPOP); SetTimer(infoPtr->hwndSelf, ID_TIMERPOP, infoPtr->nAutoPopTime, 0); TRACE("timer 2 restarted\n"); } else if(infoPtr->nTool != -1 && infoPtr->bActive) { /* previous show attempt didn't result in tooltip so try again */ SetTimer(infoPtr->hwndSelf, ID_TIMERSHOW, infoPtr->nInitialTime, 0); TRACE("timer 1 started\n"); } break; }
return 0;}
static LRESULTTOOLTIPS_SetDelayTime (TOOLTIPS_INFO *infoPtr, DWORD duration, INT nTime){ switch (duration) { case TTDT_AUTOMATIC: if (nTime <= 0) nTime = GetDoubleClickTime(); infoPtr->nReshowTime = nTime / 5; infoPtr->nAutoPopTime = nTime * 10; infoPtr->nInitialTime = nTime; break;
case TTDT_RESHOW: if(nTime < 0) nTime = GetDoubleClickTime() / 5; infoPtr->nReshowTime = nTime; break;
case TTDT_AUTOPOP: if(nTime < 0) nTime = GetDoubleClickTime() * 10; infoPtr->nAutoPopTime = nTime; break;
case TTDT_INITIAL: if(nTime < 0) nTime = GetDoubleClickTime(); infoPtr->nInitialTime = nTime; break;
default: WARN("Invalid duration flag %x\n", duration); break; }
return 0;}
static LRESULTTOOLTIPS_SetMargin (TOOLTIPS_INFO *infoPtr, const RECT *rect){ if (rect) infoPtr->rcMargin = *rect;
return 0;}
static inline LRESULTTOOLTIPS_SetMaxTipWidth (TOOLTIPS_INFO *infoPtr, INT MaxWidth){ INT nTemp = infoPtr->nMaxTipWidth;
infoPtr->nMaxTipWidth = MaxWidth;
return nTemp;}
static inline LRESULTTOOLTIPS_SetTipBkColor (TOOLTIPS_INFO *infoPtr, COLORREF clrBk){ infoPtr->clrBk = clrBk;
return 0;}
static inline LRESULTTOOLTIPS_SetTipTextColor (TOOLTIPS_INFO *infoPtr, COLORREF clrText){ infoPtr->clrText = clrText;
return 0;}
static LRESULTTOOLTIPS_SetTitleT (TOOLTIPS_INFO *infoPtr, UINT_PTR uTitleIcon, LPCWSTR pszTitle, BOOL isW){ UINT size;
TRACE("hwnd = %p, title = %s, icon = %p\n", infoPtr->hwndSelf, debugstr_w(pszTitle), (void*)uTitleIcon);
Free(infoPtr->pszTitle);
if (pszTitle) { if (isW) { size = (lstrlenW(pszTitle)+1)*sizeof(WCHAR); infoPtr->pszTitle = Alloc(size); if (!infoPtr->pszTitle) return FALSE; memcpy(infoPtr->pszTitle, pszTitle, size); } else { size = sizeof(WCHAR)*MultiByteToWideChar(CP_ACP, 0, (LPCSTR)pszTitle, -1, NULL, 0); infoPtr->pszTitle = Alloc(size); if (!infoPtr->pszTitle) return FALSE; MultiByteToWideChar(CP_ACP, 0, (LPCSTR)pszTitle, -1, infoPtr->pszTitle, size/sizeof(WCHAR)); } } else infoPtr->pszTitle = NULL;
if (uTitleIcon <= TTI_ERROR) infoPtr->hTitleIcon = hTooltipIcons[uTitleIcon]; else infoPtr->hTitleIcon = CopyIcon((HICON)uTitleIcon);
TRACE("icon = %p\n", infoPtr->hTitleIcon);
return TRUE;}
static LRESULTTOOLTIPS_SetToolInfoT (TOOLTIPS_INFO *infoPtr, const TTTOOLINFOW *ti, BOOL isW){ TTTOOL_INFO *toolPtr; INT nTool;
if (!ti) return 0; if (ti->cbSize < TTTOOLINFOW_V1_SIZE) return 0;
nTool = TOOLTIPS_GetToolFromInfoT (infoPtr, ti); if (nTool == -1) return 0;
TRACE("tool %d\n", nTool);
toolPtr = &infoPtr->tools[nTool];
/* copy tool data */ toolPtr->uFlags = ti->uFlags; toolPtr->hwnd = ti->hwnd; toolPtr->uId = ti->uId; toolPtr->rect = ti->rect; toolPtr->hinst = ti->hinst;
TOOLTIPS_SetToolText (toolPtr, ti->lpszText, isW);
if (ti->cbSize >= TTTOOLINFOW_V2_SIZE) toolPtr->lParam = ti->lParam;
if (infoPtr->nCurrentTool == nTool) { TOOLTIPS_GetTipText (infoPtr, infoPtr->nCurrentTool, infoPtr->szTipText);
if (infoPtr->szTipText[0] == 0) TOOLTIPS_Hide(infoPtr); else TOOLTIPS_Show (infoPtr, FALSE); }
return 0;}
static LRESULTTOOLTIPS_TrackActivate (TOOLTIPS_INFO *infoPtr, BOOL track_activate, const TTTOOLINFOA *ti){ if (track_activate) {
if (!ti) return 0; if (ti->cbSize < TTTOOLINFOA_V1_SIZE) return FALSE;
/* activate */ infoPtr->nTrackTool = TOOLTIPS_GetToolFromInfoT (infoPtr, (const TTTOOLINFOW*)ti); if (infoPtr->nTrackTool != -1) { TRACE("activated\n"); infoPtr->bTrackActive = TRUE; TOOLTIPS_TrackShow (infoPtr); } } else { /* deactivate */ TOOLTIPS_TrackHide (infoPtr);
infoPtr->bTrackActive = FALSE; infoPtr->nTrackTool = -1;
TRACE("deactivated\n"); }
return 0;}
static LRESULTTOOLTIPS_TrackPosition (TOOLTIPS_INFO *infoPtr, LPARAM coord){ infoPtr->xTrackPos = (INT)LOWORD(coord); infoPtr->yTrackPos = (INT)HIWORD(coord);
if (infoPtr->bTrackActive) { TRACE("[%d %d]\n", infoPtr->xTrackPos, infoPtr->yTrackPos);
TOOLTIPS_TrackShow (infoPtr); }
return 0;}
static LRESULTTOOLTIPS_Update (TOOLTIPS_INFO *infoPtr){ if (infoPtr->nCurrentTool != -1) UpdateWindow (infoPtr->hwndSelf);
return 0;}
static LRESULTTOOLTIPS_UpdateTipTextT (TOOLTIPS_INFO *infoPtr, const TTTOOLINFOW *ti, BOOL isW){ TTTOOL_INFO *toolPtr; INT nTool;
if (!ti) return 0; if (ti->cbSize < TTTOOLINFOW_V1_SIZE) return FALSE;
nTool = TOOLTIPS_GetToolFromInfoT (infoPtr, ti); if (nTool == -1) return 0;
TRACE("tool %d\n", nTool);
toolPtr = &infoPtr->tools[nTool];
toolPtr->hinst = ti->hinst;
TOOLTIPS_SetToolText(toolPtr, ti->lpszText, isW);
if(infoPtr->nCurrentTool == -1) return 0; /* force repaint */ if (infoPtr->bActive) TOOLTIPS_Show (infoPtr, FALSE); else if (infoPtr->bTrackActive) TOOLTIPS_Show (infoPtr, TRUE);
return 0;}
static LRESULTTOOLTIPS_Create (HWND hwnd){ TOOLTIPS_INFO *infoPtr;
/* allocate memory for info structure */ infoPtr = Alloc (sizeof(TOOLTIPS_INFO)); SetWindowLongPtrW (hwnd, 0, (DWORD_PTR)infoPtr);
/* initialize info structure */ infoPtr->bActive = TRUE; infoPtr->bTrackActive = FALSE;
infoPtr->nMaxTipWidth = -1; infoPtr->nTool = -1; infoPtr->nCurrentTool = -1; infoPtr->nTrackTool = -1; infoPtr->hwndSelf = hwnd;
/* initialize colours and fonts */ TOOLTIPS_InitSystemSettings(infoPtr);
TOOLTIPS_SetDelayTime(infoPtr, TTDT_AUTOMATIC, 0);
SetWindowPos (hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOZORDER | SWP_HIDEWINDOW | SWP_NOACTIVATE);
return 0;}
static LRESULTTOOLTIPS_Destroy (TOOLTIPS_INFO *infoPtr){ TTTOOL_INFO *toolPtr; UINT i;
for (i = 0; i < infoPtr->uNumTools; i++) { toolPtr = &infoPtr->tools[i];
TOOLTIPS_FreeToolText (toolPtr); TOOLTIPS_ResetSubclass (toolPtr); }
Free (infoPtr->tools);
/* free title string */ Free (infoPtr->pszTitle); /* free title icon if not a standard one */ if (TOOLTIPS_GetTitleIconIndex(infoPtr->hTitleIcon) > TTI_ERROR) DeleteObject(infoPtr->hTitleIcon);
/* delete fonts */ DeleteObject (infoPtr->hFont); DeleteObject (infoPtr->hTitleFont);
/* free tool tips info data */ SetWindowLongPtrW(infoPtr->hwndSelf, 0, 0); Free (infoPtr);
return 0;}
static inline LRESULTTOOLTIPS_GetFont (const TOOLTIPS_INFO *infoPtr){ return (LRESULT)infoPtr->hFont;}
static LRESULTTOOLTIPS_MouseMessage (TOOLTIPS_INFO *infoPtr){ TOOLTIPS_Hide (infoPtr);
return 0;}
static LRESULTTOOLTIPS_NCCreate (HWND hwnd){ DWORD dwStyle = GetWindowLongW (hwnd, GWL_STYLE); DWORD dwExStyle = GetWindowLongW (hwnd, GWL_EXSTYLE);
dwStyle &= ~(WS_CHILD | /*WS_MAXIMIZE |*/ WS_BORDER | WS_DLGFRAME); dwStyle |= (WS_POPUP | WS_BORDER | WS_CLIPSIBLINGS);
/* WS_BORDER only draws a border round the window rect, not the * window region, therefore it is useless to us in balloon mode */ if (dwStyle & TTS_BALLOON) dwStyle &= ~WS_BORDER;
SetWindowLongW (hwnd, GWL_STYLE, dwStyle);
dwExStyle |= WS_EX_TOOLWINDOW; SetWindowLongW (hwnd, GWL_EXSTYLE, dwExStyle);
return TRUE;}
static LRESULTTOOLTIPS_NCHitTest (const TOOLTIPS_INFO *infoPtr, WPARAM wParam, LPARAM lParam){ INT nTool = (infoPtr->bTrackActive) ? infoPtr->nTrackTool : infoPtr->nTool;
TRACE(" nTool=%d\n", nTool);
if ((nTool > -1) && (nTool < infoPtr->uNumTools)) { if (infoPtr->tools[nTool].uFlags & TTF_TRANSPARENT) { TRACE("-- in transparent mode\n"); return HTTRANSPARENT; } }
return DefWindowProcW (infoPtr->hwndSelf, WM_NCHITTEST, wParam, lParam);}
static LRESULTTOOLTIPS_NotifyFormat (TOOLTIPS_INFO *infoPtr, WPARAM wParam, LPARAM lParam){#ifdef __REACTOS__ TTTOOL_INFO *toolPtr = infoPtr->tools; LRESULT nResult;
TRACE("infoPtr=%p wParam=%lx lParam=%p\n", infoPtr, wParam, (PVOID)lParam);
if (lParam == NF_QUERY) { if (toolPtr->bNotifyUnicode) { return NFR_UNICODE; } else { return NFR_ANSI; } } else if (lParam == NF_REQUERY) { nResult = SendMessageW (toolPtr->hwnd, WM_NOTIFYFORMAT, (WPARAM)infoPtr->hwndSelf, (LPARAM)NF_QUERY); if (nResult == NFR_ANSI) { toolPtr->bNotifyUnicode = FALSE; TRACE(" -- WM_NOTIFYFORMAT returns: NFR_ANSI\n"); } else if (nResult == NFR_UNICODE) { toolPtr->bNotifyUnicode = TRUE; TRACE(" -- WM_NOTIFYFORMAT returns: NFR_UNICODE\n"); } else { TRACE (" -- WM_NOTIFYFORMAT returns: error!\n"); } return nResult; }#else FIXME ("hwnd=%p wParam=%lx lParam=%lx\n", infoPtr->hwndSelf, wParam, lParam);#endif
return 0;}
static LRESULTTOOLTIPS_Paint (const TOOLTIPS_INFO *infoPtr, HDC hDC){ HDC hdc; PAINTSTRUCT ps;
hdc = (hDC == NULL) ? BeginPaint (infoPtr->hwndSelf, &ps) : hDC; TOOLTIPS_Refresh (infoPtr, hdc); if (!hDC) EndPaint (infoPtr->hwndSelf, &ps); return 0;}
static LRESULTTOOLTIPS_SetFont (TOOLTIPS_INFO *infoPtr, HFONT hFont, BOOL redraw){ LOGFONTW lf;
if(!GetObjectW(hFont, sizeof(lf), &lf)) return 0;
DeleteObject (infoPtr->hFont); infoPtr->hFont = CreateFontIndirectW(&lf);
DeleteObject (infoPtr->hTitleFont); lf.lfWeight = FW_BOLD; infoPtr->hTitleFont = CreateFontIndirectW(&lf);
if (redraw && infoPtr->nCurrentTool != -1) FIXME("full redraw needed\n");
return 0;}
/****************************************************************** * TOOLTIPS_GetTextLength * * This function is called when the tooltip receive a * WM_GETTEXTLENGTH message. * * returns the length, in characters, of the tip text */static inline LRESULTTOOLTIPS_GetTextLength(const TOOLTIPS_INFO *infoPtr){ return lstrlenW(infoPtr->szTipText);}
/****************************************************************** * TOOLTIPS_OnWMGetText * * This function is called when the tooltip receive a * WM_GETTEXT message. * wParam : specifies the maximum number of characters to be copied * lParam : is the pointer to the buffer that will receive * the tip text * * returns the number of characters copied */static LRESULTTOOLTIPS_OnWMGetText (const TOOLTIPS_INFO *infoPtr, WPARAM size, LPWSTR pszText){ LRESULT res;
if(!size) return 0;
res = min(lstrlenW(infoPtr->szTipText)+1, size); memcpy(pszText, infoPtr->szTipText, res*sizeof(WCHAR)); pszText[res-1] = '\0'; return res-1;}
static LRESULTTOOLTIPS_Timer (TOOLTIPS_INFO *infoPtr, INT iTimer){ INT nOldTool;
TRACE("timer %d (%p) expired\n", iTimer, infoPtr->hwndSelf);
switch (iTimer) { case ID_TIMERSHOW: KillTimer (infoPtr->hwndSelf, ID_TIMERSHOW); nOldTool = infoPtr->nTool; if ((infoPtr->nTool = TOOLTIPS_CheckTool (infoPtr, TRUE)) == nOldTool) TOOLTIPS_Show (infoPtr, FALSE); break;
case ID_TIMERPOP: TOOLTIPS_Hide (infoPtr); break;
case ID_TIMERLEAVE: nOldTool = infoPtr->nTool; infoPtr->nTool = TOOLTIPS_CheckTool (infoPtr, FALSE); TRACE("tool (%p) %d %d %d\n", infoPtr->hwndSelf, nOldTool, infoPtr->nTool, infoPtr->nCurrentTool); if (infoPtr->nTool != nOldTool) { if(infoPtr->nTool == -1) { /* Moved out of all tools */ TOOLTIPS_Hide(infoPtr); KillTimer(infoPtr->hwndSelf, ID_TIMERLEAVE); } else if (nOldTool == -1) { /* Moved from outside */ ERR("How did this happen?\n"); } else { /* Moved from one to another */ TOOLTIPS_Hide (infoPtr); KillTimer(infoPtr->hwndSelf, ID_TIMERLEAVE); if(infoPtr->bActive) { SetTimer (infoPtr->hwndSelf, ID_TIMERSHOW, infoPtr->nReshowTime, 0); TRACE("timer 1 started!\n"); } } } break;
default: ERR("Unknown timer id %d\n", iTimer); break; } return 0;}
static LRESULTTOOLTIPS_WinIniChange (TOOLTIPS_INFO *infoPtr){ TOOLTIPS_InitSystemSettings (infoPtr);
return 0;}
static LRESULT CALLBACKTOOLTIPS_SubclassProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam, UINT_PTR uID, DWORD_PTR dwRef){ TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr ((HWND)dwRef); MSG msg;
switch (message) { case WM_MOUSEMOVE: case WM_LBUTTONDOWN: case WM_LBUTTONUP: case WM_MBUTTONDOWN: case WM_MBUTTONUP: case WM_RBUTTONDOWN: case WM_RBUTTONUP: if (infoPtr) { msg.hwnd = hwnd; msg.message = message; msg.wParam = wParam; msg.lParam = lParam; TOOLTIPS_RelayEvent(infoPtr, &msg); } break; case WM_NCDESTROY: RemoveWindowSubclass(hwnd, TOOLTIPS_SubclassProc, 1); break; default: break; }
return DefSubclassProc(hwnd, message, wParam, lParam);}
static LRESULT CALLBACKTOOLTIPS_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam){ TOOLTIPS_INFO *infoPtr = TOOLTIPS_GetInfoPtr (hwnd);
TRACE("hwnd=%p msg=%x wparam=%lx lParam=%lx\n", hwnd, uMsg, wParam, lParam); if (!infoPtr && (uMsg != WM_CREATE) && (uMsg != WM_NCCREATE)) return DefWindowProcW (hwnd, uMsg, wParam, lParam); switch (uMsg) { case TTM_ACTIVATE: return TOOLTIPS_Activate (infoPtr, (BOOL)wParam);
case TTM_ADDTOOLA: case TTM_ADDTOOLW: return TOOLTIPS_AddToolT (infoPtr, (LPTTTOOLINFOW)lParam, uMsg == TTM_ADDTOOLW);
case TTM_DELTOOLA: case TTM_DELTOOLW: return TOOLTIPS_DelToolT (infoPtr, (LPTOOLINFOW)lParam, uMsg == TTM_DELTOOLW); case TTM_ENUMTOOLSA: case TTM_ENUMTOOLSW: return TOOLTIPS_EnumToolsT (infoPtr, (UINT)wParam, (LPTTTOOLINFOW)lParam, uMsg == TTM_ENUMTOOLSW); case TTM_GETBUBBLESIZE: return TOOLTIPS_GetBubbleSize (infoPtr, (LPTTTOOLINFOW)lParam);
case TTM_GETCURRENTTOOLA: case TTM_GETCURRENTTOOLW: return TOOLTIPS_GetCurrentToolT (infoPtr, (LPTTTOOLINFOW)lParam, uMsg == TTM_GETCURRENTTOOLW);
case TTM_GETDELAYTIME: return TOOLTIPS_GetDelayTime (infoPtr, (DWORD)wParam);
case TTM_GETMARGIN: return TOOLTIPS_GetMargin (infoPtr, (LPRECT)lParam);
case TTM_GETMAXTIPWIDTH: return TOOLTIPS_GetMaxTipWidth (infoPtr);
case TTM_GETTEXTA: case TTM_GETTEXTW: return TOOLTIPS_GetTextT (infoPtr, (LPTTTOOLINFOW)lParam, uMsg == TTM_GETTEXTW);
case TTM_GETTIPBKCOLOR: return TOOLTIPS_GetTipBkColor (infoPtr);
case TTM_GETTIPTEXTCOLOR: return TOOLTIPS_GetTipTextColor (infoPtr);
case TTM_GETTOOLCOUNT: return TOOLTIPS_GetToolCount (infoPtr);
case TTM_GETTOOLINFOA: case TTM_GETTOOLINFOW: return TOOLTIPS_GetToolInfoT (infoPtr, (LPTTTOOLINFOW)lParam, uMsg == TTM_GETTOOLINFOW);
case TTM_HITTESTA: case TTM_HITTESTW: return TOOLTIPS_HitTestT (infoPtr, (LPTTHITTESTINFOW)lParam, uMsg == TTM_HITTESTW); case TTM_NEWTOOLRECTA: case TTM_NEWTOOLRECTW: return TOOLTIPS_NewToolRectT (infoPtr, (LPTTTOOLINFOW)lParam);
case TTM_POP: return TOOLTIPS_Pop (infoPtr);
case TTM_RELAYEVENT: return TOOLTIPS_RelayEvent (infoPtr, (LPMSG)lParam);
case TTM_SETDELAYTIME: return TOOLTIPS_SetDelayTime (infoPtr, (DWORD)wParam, (INT)LOWORD(lParam));
case TTM_SETMARGIN: return TOOLTIPS_SetMargin (infoPtr, (LPRECT)lParam);
case TTM_SETMAXTIPWIDTH: return TOOLTIPS_SetMaxTipWidth (infoPtr, (INT)lParam);
case TTM_SETTIPBKCOLOR: return TOOLTIPS_SetTipBkColor (infoPtr, (COLORREF)wParam);
case TTM_SETTIPTEXTCOLOR: return TOOLTIPS_SetTipTextColor (infoPtr, (COLORREF)wParam);
case TTM_SETTITLEA: case TTM_SETTITLEW: return TOOLTIPS_SetTitleT (infoPtr, (UINT_PTR)wParam, (LPCWSTR)lParam, uMsg == TTM_SETTITLEW);
case TTM_SETTOOLINFOA: case TTM_SETTOOLINFOW: return TOOLTIPS_SetToolInfoT (infoPtr, (LPTTTOOLINFOW)lParam, uMsg == TTM_SETTOOLINFOW);
case TTM_TRACKACTIVATE: return TOOLTIPS_TrackActivate (infoPtr, (BOOL)wParam, (LPTTTOOLINFOA)lParam);
case TTM_TRACKPOSITION: return TOOLTIPS_TrackPosition (infoPtr, lParam);
case TTM_UPDATE: return TOOLTIPS_Update (infoPtr);
case TTM_UPDATETIPTEXTA: case TTM_UPDATETIPTEXTW: return TOOLTIPS_UpdateTipTextT (infoPtr, (LPTTTOOLINFOW)lParam, uMsg == TTM_UPDATETIPTEXTW);
case TTM_WINDOWFROMPOINT: return (LRESULT)WindowFromPoint (*((LPPOINT)lParam));
case WM_CREATE: return TOOLTIPS_Create (hwnd);
case WM_DESTROY: return TOOLTIPS_Destroy (infoPtr);
case WM_ERASEBKGND: /* we draw the background in WM_PAINT */ return 0;
case WM_GETFONT: return TOOLTIPS_GetFont (infoPtr);
case WM_GETTEXT: return TOOLTIPS_OnWMGetText (infoPtr, wParam, (LPWSTR)lParam);
case WM_GETTEXTLENGTH: return TOOLTIPS_GetTextLength (infoPtr);
case WM_LBUTTONDOWN: case WM_LBUTTONUP: case WM_MBUTTONDOWN: case WM_MBUTTONUP: case WM_RBUTTONDOWN: case WM_RBUTTONUP: case WM_MOUSEMOVE: return TOOLTIPS_MouseMessage (infoPtr);
case WM_NCCREATE: return TOOLTIPS_NCCreate (hwnd);
case WM_NCHITTEST: return TOOLTIPS_NCHitTest (infoPtr, wParam, lParam);
case WM_NOTIFYFORMAT: return TOOLTIPS_NotifyFormat (infoPtr, wParam, lParam);
case WM_PRINTCLIENT: case WM_PAINT: return TOOLTIPS_Paint (infoPtr, (HDC)wParam);
case WM_SETFONT: return TOOLTIPS_SetFont (infoPtr, (HFONT)wParam, LOWORD(lParam));
case WM_SYSCOLORCHANGE: COMCTL32_RefreshSysColors(); return 0;
case WM_TIMER: return TOOLTIPS_Timer (infoPtr, (INT)wParam);
case WM_WININICHANGE: return TOOLTIPS_WinIniChange (infoPtr);
default: if ((uMsg >= WM_USER) && (uMsg < WM_APP) && !COMCTL32_IsReflectedMessage(uMsg)) ERR("unknown msg %04x wp=%08lx lp=%08lx\n", uMsg, wParam, lParam); return DefWindowProcW (hwnd, uMsg, wParam, lParam); }}
VOIDTOOLTIPS_Register (void){ WNDCLASSW wndClass;
ZeroMemory (&wndClass, sizeof(WNDCLASSW)); wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS | CS_SAVEBITS; wndClass.lpfnWndProc = TOOLTIPS_WindowProc; wndClass.cbClsExtra = 0; wndClass.cbWndExtra = sizeof(TOOLTIPS_INFO *); wndClass.hCursor = LoadCursorW (0, (LPWSTR)IDC_ARROW); wndClass.hbrBackground = 0; wndClass.lpszClassName = TOOLTIPS_CLASSW;
RegisterClassW (&wndClass);
hTooltipIcons[TTI_NONE] = NULL; hTooltipIcons[TTI_INFO] = LoadImageW(COMCTL32_hModule, (LPCWSTR)MAKEINTRESOURCE(IDI_TT_INFO_SM), IMAGE_ICON, 0, 0, 0); hTooltipIcons[TTI_WARNING] = LoadImageW(COMCTL32_hModule, (LPCWSTR)MAKEINTRESOURCE(IDI_TT_WARN_SM), IMAGE_ICON, 0, 0, 0); hTooltipIcons[TTI_ERROR] = LoadImageW(COMCTL32_hModule, (LPCWSTR)MAKEINTRESOURCE(IDI_TT_ERROR_SM), IMAGE_ICON, 0, 0, 0);}
VOIDTOOLTIPS_Unregister (void){ int i; for (i = TTI_INFO; i <= TTI_ERROR; i++) DestroyIcon(hTooltipIcons[i]); UnregisterClassW (TOOLTIPS_CLASSW, NULL);}