00001 /** 00002 * \file mgui/oxttctrl.h 00003 * \brief Tool Tip control for MFC 00004 * 00005 * This should be moved to mi32p or contrib, but mi32/mdisp.h includes it, 00006 * so we have to distribute it. 00007 * 00008 * \if NODOC 00009 * $Log: oxttctrl.h_v $ 00010 * Revision 1.5 2003/10/03 19:58:19 linux32build!build 00011 * Doxygen 00012 * 00013 * Revision 1.4 2003/09/15 16:11:18 dwilliss 00014 * Fixed mismatched ifdefs from doxygen 00015 * 00016 * Revision 1.3 2003/09/15 13:49:32 fileserver!dwilliss 00017 * Doxygen 00018 * 00019 * Revision 1.2 2003/04/09 20:52:09 dwilliss 00020 * Don't use _T in templates. Mac's ctype.h defines a global _T 00021 * 00022 * Revision 1.1 2002/12/11 15:22:17 mju 00023 * Initial revision 00024 * 00025 * 00026 * 3 2/01/01 2:44p Mju 00027 * Add IsCreated() 00028 * 00029 * 2 2/01/01 2:02p Mju 00030 * Keep track of whether to use full client rect. 00031 * Retain bounding rectangle in client coordinates. 00032 * \endif 00033 */ 00034 00035 #ifndef INC_MGUI_OXTTCTRL_H 00036 #define INC_MGUI_OXTTCTRL_H 00037 00038 #ifndef GENERATING_DOXYGEN_OUTPUT 00039 //! ========================================================================== 00040 //! Class Specification : COXToolTipCtrl 00041 //! ========================================================================== 00042 //! ////////////////////////////////////////////////////////////////////////// 00043 //! Header file : OXToolTipCtrl.h 00044 00045 //! Copyright © Dundas Software Ltd. 1997 - 1999, All Rights Reserved 00046 00047 //! ////////////////////////////////////////////////////////////////////////// 00048 00049 00050 //! Properties: 00051 //! NO Abstract class (does not have any objects) 00052 //! YES Derived from CWnd 00053 00054 //! YES Is a Cwnd. 00055 //! YES Two stage creation (constructor & Create()) 00056 //! YES Has a message map 00057 //! NO Needs a resource (template) 00058 00059 //! NO Persistent objects (saveable on disk) 00060 //! NO Uses exceptions 00061 00062 //! ////////////////////////////////////////////////////////////////////////// 00063 00064 00065 /* 00066 DESCRIPTION 00067 00068 COXToolTipCtrl is an extended tooltip control that allows multiline tooltips, 00069 plus extended tooltip text. Extended tooltip text is extra text that is 00070 displayed if the user clicks on the tooltip window. If the tooltip contains 00071 extended text (as well as a standard tooltip string) then the info window 00072 will contain a small arrow that prompts the user to click on the window. Once 00073 the window is clicked, the extended text is shown. If the window is clicked 00074 again then the window reduces to showing just the standard text. 00075 00076 The maximum width of the tooltips can be specified, and if the info text is 00077 too big to fit within these bounds then the text will be wrapped over multiple 00078 lines. The control also allows you to specify a different text and background 00079 colors for the tooltips, and the display font can also be changed. 00080 00081 Using ToolTipCtrlEx : 00082 00083 This class is a direct replacement for the CToolTipCtrl class. It incorporates 00084 the entire API of the standard CToolTipCtrl, and introduces new features not 00085 found in the standard tooltip. 00086 00087 The control is used just like any other tooltip control. To use the tool simply 00088 call Create(...) and specify the parent window of the tool, then add tools to 00089 the control using the AddTool(...) member function. 00090 00091 eg. (In a formview or dialog) 00092 00093 tooltip.Create(this) 00094 tooltip.AddTool(GetDlgItem(IDC_CONTROL), 00095 _CT("Tooltip text\rThis is the extended\ntooltip text")); 00096 00097 where ID_CONTROL is the ID of a control. 00098 00099 To specify extended text for a tooltip, simply append a '\r' after your tooltip 00100 text, and then append the extended tooltip info. 00101 00102 As with the standard tooltip control you can specify the actual text for the tool 00103 at creation time (as shown above), or you can specify the LPSTR_TEXTCALLBACK value 00104 and provide a TTN_NEEDTEXT handler to return the text dynamically at runtime. 00105 00106 To handle the TTN_NEEDTEXT message, you will need to add a message handler in the 00107 parent window, and an entry in the message map; 00108 00109 eg. In you view or form 00110 00111 BEGIN_MESSAGE_MAP(CMyDlg, CDialog) 00112 ... 00113 ON_NOTIFY_EX( TTN_NEEDTEXT, 0, OnToolTipNotify) 00114 END_MESSAGE_MAP() 00115 00116 BOOL CMyDlg::OnInitDialog() 00117 { 00118 CDialog::OnInitDialog(); 00119 00120 tooltip.Create(this) 00121 tooltip.AddTool(GetDlgItem(IDC_CONTROL), LPSTR_TEXTCALLBACK); 00122 ... 00123 } 00124 00125 BOOL CMyDlg::OnToolTipNotify(UINT id, NMHDR* pNMHDR, LRESULT* pResult) 00126 { 00127 TOOLTIPTEXT *pTTT = (TOOLTIPTEXT *)pNMHDR; 00128 UINT nID = pNMHDR->idFrom; 00129 00130 if (nID == IDC_CONTROL) Fill in the text buffer 00131 { 00132 _tcscpy(pTTT->szText, _CT("Tooltip text\rExtended tooltip text")); 00133 return TRUE; 00134 } 00135 00136 return FALSE; 00137 } 00138 00139 You can also supply text two alternate ways, either by supplying a string 00140 resource 00141 00142 pTTT->lpszText = MAKEINTRESOURCE(nID); 00143 pTTT->hinst = AfxGetResourceHandle(); 00144 return TRUE; 00145 00146 or by supplying a pointer to the text: 00147 00148 pTTT->lpszText = _CT("Tooltip text\rExtended tooltip text"); 00149 return TRUE; 00150 00151 Newline characters ('\n') can be embedded anywhere within the text or extended 00152 text to produce a multiline tooltip. If the width of the tooltip window is 00153 specified using SetMaxTipWidth() then the tooltip text will be wrapped to this 00154 length, and if necessary displayed on more than one line. 00155 00156 To change the font of the tooltips simply use the SetFont member function. 00157 00158 The GetToolInfo/SetToolInfo functions, and the HitTest functions are very 00159 similar to the CToolTipCtrl versions except that they use a OXTOOLINFO 00160 structure instead of a TOOLINFO structure. This structure is defined as 00161 00162 struct OXTOOLINFO : public TOOLINFO 00163 { 00164 #if (_WIN32_IE < 0x0300) 00165 LPARAM lParam; Application defined value that is associated with the tool 00166 #endif 00167 int nWidth; Width of box, or 0 for default 00168 COLORREF clrTextColor; text color 00169 COLORREF clrBackColor; background color 00170 } 00171 00172 and so is very similar to the standard TOOLINFO, and is used in the same way, 00173 with the exception that the uFlags member is not (yet) used. 00174 00175 To change the color of an individual tip, use the GetToolInfo/SetToolInfo 00176 functions 00177 00178 OXTOOLINFO ToolInfo; 00179 if (m_toolTip.GetToolInfo(ToolInfo, GetDlgItem(IDC_CONTROL))) 00180 { 00181 ToolInfo.clrBackColor = RGB(255, 255, 255); 00182 ToolInfo.clrTextColor = RGB( 0, 0, 255); 00183 m_toolTip.SetToolInfo(&ToolInfo); 00184 } 00185 00186 00187 00188 The ToolTipEx sample that demonstrate the functionality of the COXToolTipCtrl class 00189 can be found in the .\Samples\gui\ToolTipEx subdirectory of your Ultimate Toolbox 00190 directory. 00191 00192 00193 00194 Dependencies: 00195 00196 #include "OXToolTipCtrl.h" 00197 00198 00199 Source code files: 00200 00201 "OXToolTipCtrl.cpp" - COXToolTipCtrl implementation 00202 00203 00204 */ 00205 //! 00206 //! 00207 //////////////////////////////////////////////////////////////////////////! 00208 00209 00210 #if !defined(_OXTOOLTIPCTRL_H__) && defined(WIN32_MFC) 00211 #define _OXTOOLTIPCTRL_H__ 00212 00213 #if _MSC_VER > 1000 00214 #pragma once 00215 #endif //!< _MSC_VER > 1000 00216 00217 #include <mgui/OXDllExt.h> 00218 00219 class COXToolTipInfo; 00220 00221 struct OXTOOLINFO : public TOOLINFO 00222 { 00223 #if (_WIN32_IE < 0x0300) 00224 //! Application defined value that is associated with the tool 00225 LPARAM lParam; 00226 #endif 00227 //! Width of box, or 0 for default 00228 int nWidth; 00229 //! Set to use full client rectangle 00230 bool bUseFullRect; 00231 //! text color 00232 COLORREF clrTextColor; 00233 //! background color 00234 COLORREF clrBackColor; 00235 00236 00237 OXTOOLINFO::OXTOOLINFO() 00238 { 00239 cbSize = sizeof(OXTOOLINFO); 00240 } 00241 00242 void operator=(COXToolTipInfo& RHS); 00243 }; 00244 00245 //! this structure holds all the tooltip information internall 00246 class OX_CLASS_DECL COXToolTipInfo : public CObject 00247 { 00248 public: 00249 UINT uFlags; //!< Not used 00250 HWND hWnd; //!< Window handle of the control 00251 UINT nIDTool; //!< ID of tool 00252 CRect rectBounds; //!< Bounding rect for toolinfo to be displayed relative to upper left corner of hWnd 00253 LPCTSTR szText; //!< Either LPSTR_TEXTCALLBACK or NULL 00254 CString strText; //!< Tooltip text if szText is NULL, or empty. 00255 int nWidth; //!< Width of box, or 0 for default 00256 bool bUseFullRect; //!< Use full client rectangle, ignoring 'rectBounds' 00257 COLORREF clrTextColor; //!< text color 00258 COLORREF clrBackColor; //!< background color 00259 LPARAM lParam; //!< Application defined value that is associated 00260 //! with the tool 00261 00262 00263 void operator=(OXTOOLINFO& RHS) 00264 { 00265 uFlags = RHS.uFlags; 00266 hWnd = RHS.hwnd; 00267 nIDTool = RHS.uId; 00268 rectBounds = RHS.rect; 00269 if (RHS.lpszText == LPSTR_TEXTCALLBACK) 00270 { 00271 szText = RHS.lpszText; 00272 strText.Empty(); 00273 } 00274 else 00275 { 00276 szText = NULL; 00277 strText = RHS.lpszText; 00278 } 00279 nWidth = RHS.nWidth; 00280 bUseFullRect = RHS.bUseFullRect; 00281 clrTextColor = RHS.clrTextColor; 00282 clrBackColor = RHS.clrBackColor; 00283 lParam = RHS.lParam; 00284 } 00285 00286 void operator=(COXToolTipInfo& RHS) 00287 { 00288 uFlags = RHS.uFlags; 00289 hWnd = RHS.hWnd; 00290 nIDTool = RHS.nIDTool; 00291 rectBounds = RHS.rectBounds; 00292 strText = RHS.strText; 00293 nWidth = RHS.nWidth; 00294 bUseFullRect = RHS.bUseFullRect; 00295 clrTextColor = RHS.clrTextColor; 00296 clrBackColor = RHS.clrBackColor; 00297 lParam = RHS.lParam; 00298 } 00299 }; 00300 00301 inline void OXTOOLINFO::operator=(COXToolTipInfo& RHS) 00302 { 00303 cbSize = sizeof(OXTOOLINFO); 00304 uFlags = RHS.uFlags; 00305 hwnd = RHS.hWnd; 00306 uId = RHS.nIDTool; 00307 rect = RHS.rectBounds; 00308 hinst = AfxGetResourceHandle(); 00309 if (RHS.szText == LPSTR_TEXTCALLBACK) 00310 lpszText = LPSTR_TEXTCALLBACK; 00311 else 00312 lpszText = (LPTSTR)(LPCTSTR) RHS.strText; 00313 lParam = RHS.lParam; 00314 nWidth = RHS.nWidth; 00315 bUseFullRect = RHS.bUseFullRect; 00316 clrTextColor = RHS.clrTextColor; 00317 clrBackColor = RHS.clrBackColor; 00318 } 00319 00320 00321 /////////////////////////////////////////////////////////////////////////////! 00322 //! COXToolTipCtrl window 00323 00324 class OX_CLASS_DECL COXToolTipCtrl : public CWnd 00325 { 00326 //! Construction 00327 public: 00328 //! --- In : 00329 //! --- Out : 00330 //! --- Returns: 00331 //! --- Effect : The constructor - all relevant variables initialized 00332 COXToolTipCtrl(); 00333 00334 //! Attributes 00335 public: 00336 //! --- In: ToolInfo - Reference to a TOOLINFO object that receives the 00337 //! tool’s text. 00338 //! pWnd - Pointer to the window that contains the tool. 00339 //! nIDTool - ID of the tool. 00340 //! --- Out : 00341 //! --- Returns: TRUE on success, FALSE otherwise 00342 //! --- Effect : Call this function to retrieve the information that a tool tip 00343 //! control maintains about a tool. If the control has information 00344 //! on the tool identified by the window and ID, then the 00345 //! COXToolTipInfo structure is filled with that information. 00346 BOOL GetToolInfo(OXTOOLINFO& ToolInfo, CWnd* pWnd, UINT nIDTool = 0); 00347 00348 //! --- In: pToolInfo - A pointer to a OXTOOLINFO structure that 00349 //! specifies the information to set. 00350 //! --- Out : 00351 //! --- Returns: 00352 //! --- Effect: Sets the information that a tool tip maintains for a tool 00353 void SetToolInfo(OXTOOLINFO* pToolInfo); 00354 00355 00356 //! --- In: 00357 //! --- Out: lprc - Address of a RECT structure that will receive the 00358 //! margin information 00359 //! --- Returns: 00360 //! --- Effect: Retrieves the margins used for drawing the text in the tooltip. 00361 //! The rectangle does not specify a bounding rect, but rather the 00362 //! top, bottom, left and right distances (in pixels) between the 00363 //! text and the the edge of the toltip window. 00364 void GetMargin(LPRECT lprc) const; 00365 00366 00367 //! --- In: pWnd - Pointer to the window that contains the tool. 00368 //! nIDTool - ID of the tool. 00369 //! --- Out: str - Reference to a CString object that receives the 00370 //! tool’s text 00371 //! --- Returns : 00372 //! --- Effect : Retrieves the text that a tool tip control maintains for a tool. 00373 //! If pWnd and nIDTool specify a valid tool that has been previously 00374 //! registered, then str is filled with the tooltip's text. 00375 void GetText(CString& str, CWnd* pWnd, UINT nIDTool = 0); 00376 00377 00378 //! --- In: nTime - Specifies the new delay time, in milliseconds 00379 //! dwDuration - Flag that specifies which duration value will 00380 //! be set. This is either: 00381 //! 00382 //! TTDT_AUTOPOP - The length of time the tool tip window 00383 //! remains visible if the pointer is 00384 //! stationary within a tool's bounding 00385 //! rectangle. 00386 //! TTDT_INITIAL - The length of time the pointer must 00387 //! remain stationary within a tool's 00388 //! bounding rectangle before the tool tip 00389 //! window appears. 00390 //! nDelay - Specifies the new delay time, in milliseconds 00391 //! --- Out : 00392 //! --- Returns: 00393 //! --- Effect: Sets the delay times for the tooltip in milliseconds 00394 void SetDelayTime(DWORD dwDuration, int nTime); 00395 inline void SetDelayTime(UINT nDelay) { m_nDisplayDelay = nDelay; } 00396 00397 //! --- In: dwDuration - Flag that specifies which duration value will 00398 //! be retrieved. This is either: 00399 //! 00400 //! TTDT_AUTOPOP - The length of time the tool tip window 00401 //! remains visible if the pointer is 00402 //! stationary within a tool's bounding 00403 //! rectangle. 00404 //! TTDT_INITIAL - The length of time the pointer must 00405 //! remain stationary within a tool's 00406 //! bounding rectangle before the tool tip 00407 //! window appears. 00408 //! --- Out : 00409 //! --- Returns: The delay times for the tooltip in milliseconds 00410 //! --- Effect: Retrieves the initial, pop-up, and reshow durations currently 00411 //! set for a tooltip control 00412 int GetDelayTime(DWORD dwDuration) const; 00413 00414 00415 //! --- In : 00416 //! --- Out : 00417 //! --- Returns: The maximum width for a tool tip window, or 0 if this width is 00418 //! calculated automatically 00419 //! --- Effect: Retrieves the maximum width of the tool tip window 00420 int GetMaxTipWidth() const; 00421 00422 //! --- In: nWidth - The maximum width for a tool tip window, or 0 if this 00423 //! width is calculated automatically. The maximum 00424 //! tooltip width value does not indicate a tooltip 00425 //! window's actual width. Rather, if a tooltip string 00426 //! exceeds the maximum width, the control breaks the 00427 //! text into multiple lines, using spaces to determine 00428 //! line breaks. If the text cannot be segmented into 00429 //! multiple lines, it will be displayed on a single line. 00430 //! The length of this line may exceed the maximum 00431 //! tooltip width. 00432 //! --- Out : 00433 //! --- Returns: The previous maximum tool tip window width. 00434 //! --- Effect: Sets the maximum tool tip window width 00435 int SetMaxTipWidth(int nWidth); 00436 00437 //! --- In : 00438 //! --- Out : 00439 //! --- Returns: A COLORREF value that represents the background color of the 00440 //! tool tip window 00441 //! --- Effect: Retrieves the background color 00442 COLORREF GetTipBkColor() const; 00443 00444 //! --- In: clr - The new background color 00445 //! --- Out : 00446 //! --- Returns: 00447 //! --- Effect: Sets the background colour for all tools maintained by this 00448 //! control. If the value is CLR_DEFAULT then the default system 00449 //! colour is used 00450 void SetTipBkColor(COLORREF clr); 00451 00452 00453 //! --- In : 00454 //! --- Out : 00455 //! --- Returns: A COLORREF value that represents the text color 00456 //! --- Effect: Retrieves the text color 00457 COLORREF GetTipTextColor() const; 00458 00459 //! --- In: clr - The new text color 00460 //! --- Out : 00461 //! --- Returns: 00462 //! --- Effect: Sets the text colour for all tools maintained by this control. 00463 //! If the value is CLR_DEFAULT then the default system colour is 00464 //! used 00465 void SetTipTextColor(COLORREF clr); 00466 00467 //! Attributes - inline 00468 public: 00469 00470 //! --- In: bActivate - Specifies whether the tool tip control is to be 00471 //! activated or deactivated. 00472 //! --- Out : 00473 //! --- Returns: 00474 //! --- Effect: Call this function to activate or deactivate a tool tip control. 00475 //! If bActivate is TRUE, the control is activated; if FALSE, it is 00476 //! deactivated. When a tool tip control is active, the tool tip 00477 //! information appears when the cursor is on a tool that is 00478 //! registered with the control; when it is inactive, the tool tip 00479 //! information does not appear, even when the cursor is on a tool. 00480 inline void Activate(BOOL bActivate) { m_bActivated = bActivate; } 00481 00482 00483 //! --- In : 00484 //! --- Out : 00485 //! --- Returns: A count of tools registered with the tool tip control 00486 //! --- Effect: Retrieves a count of the tools registered with the 00487 //! tool tip control 00488 inline int GetToolCount() const { return m_arrTools.GetSize(); } 00489 00490 //! Determine if Create() has been performed. 00491 inline bool IsCreated () const { return (m_pParentWnd != 0); } 00492 00493 00494 //! --- In : lprc - Address of a RECT structure that contains the margin 00495 //! information to be set. The members of the RECT 00496 //! structure do not define a bounding rectangle, 00497 //! but rather the top, bottom, left and right distances 00498 //! (in pixels) between the text and the the edge of the 00499 //! toltip window. 00500 //! --- Out : 00501 //! --- Returns: 00502 //! --- Effect: Sets the top, left, bottom, and right margins for a tooltip 00503 //! window. A margin is the distance, in pixels, between the tooltip 00504 //! window border and the text contained within the tooltip window. 00505 inline void SetMargin(LPRECT lprc) { m_rectMargin = lprc; } 00506 00507 00508 //! Operations 00509 public: 00510 00511 //! --- In: pParentWnd - A pointer to the tool tip control parent 00512 //! --- Out : 00513 //! --- Returns: TRUE on success, FALSE otherwise 00514 //! --- Effect: Creates the tooltip window, initially invisible 00515 BOOL Create(CWnd* pParentWnd); 00516 00517 00518 //! --- In : pWnd - Pointer to the window that contains the tool. 00519 //! nIDText - ID of the string resource that contains the text 00520 //! for the tool. If the text contains a '\r' 00521 //! character, then all text before the \r is the 00522 //! standard tooltip text, and all text after the \r 00523 //! will be displayed as extended test if the use 00524 //! clicks on the tooltip 00525 //! lpszText - Pointer to the text for the tool. If the text 00526 //! contains a '\r' character, then all text before 00527 //! the \r is the standard tooltip text, and all text 00528 //! after the \r will be displayed as extended test if 00529 //! the use clicks on the tooltip. If the text is 00530 //! LPSTR_TEXTCALLBACK then the control will send the 00531 //! TTN_NEEDTEXT notification message to the parent 00532 //! window to retrieve the text. 00533 //! lpRectTool - Pointer to a RECT structure containing coordinates 00534 //! of the tool's bounding rectangle, using client 00535 //! coordinates relative to the window identified 00536 //! by pWnd. 00537 //! nIDTool - ID of the tool. 00538 //! --- Out : 00539 //! --- Returns: TRUE on success, FALSE otherwise 00540 //! --- Effect : Registers a tool with the tool tip control, so that the 00541 //! information stored in the tool tip is displayed when the cursor 00542 //! is on the tool. 00543 BOOL AddTool(CWnd* pWnd, UINT nIDText, 00544 LPCRECT lpRectTool = NULL, UINT nIDTool = 0); 00545 BOOL AddTool(CWnd* pWnd, LPCTSTR lpszText, 00546 LPCRECT lpRectTool = NULL, UINT nIDTool = 0); 00547 00548 //! --- In: pWnd - Pointer to the window that contains the tool 00549 //! nIDTool - ID of the tool 00550 //! --- Out : 00551 //! --- Returns: 00552 //! --- Effect: Removes the tool specified by pWnd and nIDTool from the 00553 //! collection of tools supported by a tool tip control. 00554 void DelTool(CWnd* pWnd, UINT nIDTool = 0); 00555 00556 00557 //! --- In: pMsg - Pointer to a MSG structure that contains the 00558 //! message to relay 00559 //! --- Out : 00560 //! --- Returns: 00561 //! --- Effect: Call this function to pass a mouse message to a tool tip 00562 //! control for processing. 00563 void RelayEvent(MSG* pMsg); 00564 00565 00566 //! --- In: pWnd - Pointer to the window that contains the tool. 00567 //! pt - Pointer to a CPoint object containing the 00568 //! coordinates of the point to be tested. 00569 //! lpToolInfo - Pointer to a OXTOOLINFO structure that contains 00570 //! information about the tool. 00571 //! --- Out : 00572 //! --- Returns: TRUE if the point specified by the hit-test information is 00573 //! within the tool’s bounding rectangle; otherwise FALSE. 00574 //! --- Effect: Returns TRUE if the given pt is in the windows toolinfo bounding 00575 //! rectangle (pt is in client coords relative to the parent window). 00576 //! If this function returns a TRUE, the structure pointed to by 00577 //! pToolInfo is filled with information on the corresponding tool. 00578 BOOL HitTest(CWnd* pWnd, POINT pt, OXTOOLINFO* pToolInfo) const; 00579 00580 00581 //! --- In : 00582 //! --- Out : 00583 //! --- Returns: 00584 //! --- Effect: Hides the tooltip. 00585 void Pop(); 00586 00587 //! Overrides 00588 //! ClassWizard generated virtual function overrides 00589 //!{{AFX_VIRTUAL(COXToolTipCtrl) 00590 //!}}AFX_VIRTUAL 00591 00592 protected: 00593 00594 //! --- In: pt - the topleft corner of the region 00595 //! pToolTip - information on the tooltip 00596 //! rectTextBounds - the minimum rectangle needed to contain the 00597 //! text 00598 //! --- Out : 00599 //! --- Returns: A rectangle containing the bounds of the tooltip 00600 //! --- Effect: Given the bounding rect of some text, this returns the rectangle 00601 //! (in screen coords) that is best suited to displaying the tooltip 00602 //! info (uses current mouse position) 00603 virtual CRect CalculateInfoBoxRect(const CPoint& pt, COXToolTipInfo* pToolTip, 00604 CRect& rectTextBounds) const; 00605 00606 //! --- In: strText - the text to be displayed (may be multiline) 00607 //! nWidth - the desired width. If this is 0, then the width 00608 //! will be calculated 00609 //! --- Out : 00610 //! --- Returns: The bounding rect for the text (with topleft at 0,0) 00611 //! --- Effect : Returns the smallest possible rectangle that will contain 00612 //! the text (inc. margins) 00613 virtual CRect GetBoundsRect(CString strText, int nWidth) const; 00614 00615 //! Implementation 00616 public: 00617 //! --- In : 00618 //! --- Out : 00619 //! --- Returns: 00620 //! --- Effect: The destructor - cleanup and memory release 00621 virtual ~COXToolTipCtrl(); 00622 00623 protected: 00624 inline BOOL IsVisible() const { return ((GetStyle() & WS_VISIBLE) == WS_VISIBLE); } 00625 00626 //! --- In: pToolTip - A pointer to a COXToolTipInfo structure 00627 //! describing the tooltip 00628 //! --- Out : 00629 //! --- Returns: A CString containing the tooltip text 00630 //! --- Effect: Returns the tooltip text for the tool. If the tooltip is 00631 //! currently displaying extended text, then the extended 00632 //! text, if available, will be returned. Otherwise the standard 00633 //! tooltip text will be returned. 00634 CString GetTooltipText(COXToolTipInfo *pToolTip); 00635 00636 00637 //! --- In: pWnd - a window containing a tool 00638 //! nIDTool - the ID of the tool 00639 //! --- Out : 00640 //! --- Returns: A pointer to the internal storage of the tooltip for the given 00641 //! window and ID 00642 //! --- Effect: Retrieves the internal info about a tool 00643 COXToolTipInfo* GetToolInfoPtr(CWnd* pWnd, UINT nIDTool /*=0*/); 00644 00645 00646 //! --- In: point - a point (in parent window client coords) to test. 00647 //! --- Out : 00648 //! --- Returns: The child window (of the parent window) from the supplied point. 00649 //! --- Effect : Retrieves to a child window of the tool tip control parent 00650 //! window that contains the specified point 00651 CWnd* GetChildWindowFromPoint(const POINT& point) const; 00652 00653 00654 //! --- In: pToolInfo - a tooltip 00655 //! --- Out: 00656 //! --- Returns: 00657 //! --- Effect: Initiates the display of a tooltip. The tip will not actually 00658 //! be displayed until the preset delay (m_nDisplayDelay) is up. 00659 void StartNewTool(COXToolTipInfo* pToolInfo); 00660 00661 //! --- In: pt - the topleft corner where the tooltip should be 00662 //! displayed 00663 //! bExtended - if TRUE, then the extended text is displayed. 00664 //! --- Out : 00665 //! --- Returns : 00666 //! --- Effect : Displays the current tooltip, either as a normal tooltip or as an 00667 //! extended tooltip 00668 void DisplayToolTip(const CPoint& pt, BOOL bExtended = FALSE); 00669 00670 00671 //! --- In: pt - a point (in parent window client coords) to test 00672 //! --- Out : 00673 //! --- Returns: Eeither a pointer to the COXToolTipInfo, or NULL if failed 00674 //! --- Effect : Searches through the list of tools looking for the first tool 00675 //! whose bounding rect contains pt. 00676 COXToolTipInfo* FindToolFromPoint(const POINT& pt); 00677 00678 00679 //! --- In: pToolInfo - a tool tip info 00680 //! --- Out : 00681 //! --- Returns: Returns TRUE if the cursor is in the tool given by pToolInfo 00682 //! --- Effect: Retrieves the flag that specifies if cursor is over the 00683 //! specified tool 00684 BOOL IsCursorInTool(COXToolTipInfo* pToolInfo) const; 00685 00686 //! --- In : 00687 //! --- Out : 00688 //! --- Returns: Returns TRUE if the cursor is in the current tooltip window 00689 //! --- Effect: Retrieves the flag that specifies if cursor is over the 00690 //! current tooltip window 00691 BOOL IsCursorInToolTip() const; 00692 00693 00694 //! --- In: ref - the string to parse 00695 //! nIndex - the field number to return (0 based) 00696 //! ch - the separator character 00697 //! --- Out : 00698 //! --- Returns: The substring of ref delimted by ch 00699 //! --- Effect: This routine breaks a supplied string into substrings, 00700 //! each delimited by 'ch', and returns the substring number given 00701 //! by nIndex 00702 CString GetFieldFromString(CString ref, int nIndex, TCHAR ch) const; 00703 00704 00705 //! --- In: lpLogFont - A pointer to a LOGFONT structure (the new font) 00706 //! bRedraw - If TRUE then the tooltip should be immediately 00707 //! redrawn 00708 //! --- Out : 00709 //! --- Returns: TRUE on success, FALSE otherwise 00710 //! --- Effect: Sets the font to be used in the tooltip 00711 BOOL SetLogFont(LPLOGFONT lpLogFont, BOOL bRedraw = TRUE); 00712 00713 //! --- In : 00714 //! --- Out : 00715 //! --- Returns: A pointer to a LOGFONT structure that contains default font 00716 //! used in tool tips 00717 //! --- Effect : Returns the system tool tip font 00718 LPLOGFONT GetSystemToolTipFont() const; 00719 00720 protected: 00721 CWnd* m_pParentWnd; //!< Parent window of all the tools 00722 CRect m_rectMargin; //!< Margin between text and tooltip window edge 00723 int m_nMaxWidth; //!< Max tooltip width 00724 CPoint m_ptOffset; //!< offset from the cursor to the topleft of 00725 CFont m_Font; 00726 LOGFONT m_LogFont; //!< Current font in use 00727 DWORD m_dwTextStyle; //!< The style in which to draw the text 00728 BOOL m_bUsingSystemFont; //!< Use system tooltip font? 00729 COXToolTipInfo *m_pCurrentToolTip; //!< Current tooltip information 00730 UINT m_nCheckInterval; //!< Time in ms between check of the tip 00731 UINT m_nDisplayTime; //!< Time in ms to display the tip 00732 UINT m_nElapsedTime; //!< Elapsed display time of the tip 00733 UINT m_nDisplayDelay; //!< Delay in ms before the tip is displayed 00734 BOOL m_bActivated; //!< Are tips activated? 00735 BOOL m_bTipCancelled; //!< Has the current tooltip been cancelled? 00736 BOOL m_bHasExtendedText; //!< TRUE if the tooltip contains extended text 00737 BOOL m_bExtended; //!< Is the tip displaying extended info? 00738 00739 COLORREF m_crBackColor; //!< Default background color of tips 00740 COLORREF m_crTextColor; //!< Default foreground color of tips 00741 00742 HWND m_hOldFocusWnd; //!< window that had focus before the tooltip 00743 //! was clicked on 00744 00745 static LPCTSTR m_szArrowSpace; //!< Spaces (' ') added to allow room for arrow in text 00746 00747 protected: 00748 enum { eIDDisplayToolEvent = 1, eIDCheckToolEvent = 2}; 00749 00750 private: 00751 #ifndef GENERATING_DOXYGEN_OUTPUT 00752 CObArray m_arrTools; //!< Collection of all tools 00753 00754 //! Generated message map functions 00755 protected: 00756 //!{{AFX_MSG(COXToolTipCtrl) 00757 afx_msg void OnPaint(); 00758 afx_msg void OnTimer(UINT nIDEvent); 00759 afx_msg void OnLButtonDown(UINT nFlags, CPoint point); 00760 afx_msg void OnSetFocus(CWnd* pOldWnd); 00761 afx_msg void OnDestroy(); 00762 afx_msg void OnSettingChange(UINT uFlags, LPCTSTR lpszSection); 00763 afx_msg int OnMouseActivate(CWnd* pDesktopWnd, UINT nHitTest, UINT message); 00764 //!}}AFX_MSG 00765 afx_msg LRESULT OnSetFont(WPARAM hFont, LPARAM lParam); 00766 afx_msg LRESULT OnGetFont(WPARAM hFont, LPARAM lParam); 00767 DECLARE_MESSAGE_MAP() 00768 #endif // GENERATING_DOXYGEN_OUTPUT 00769 }; 00770 00771 /////////////////////////////////////////////////////////////////////////////! 00772 00773 //!{{AFX_INSERT_LOCATION}} 00774 //! Microsoft Visual C++ will insert additional declarations immediately before the previous line. 00775 00776 #endif //!< !defined(_OXTOOLTIPCTRL_H__) 00777 00778 #endif // GENERATING_DOXYGEN_OUTPUT 00779 #endif // INC_MGUI_OXTTCTRL_H
1.3.4-20031026