/** * @file XTPHyperLink.h * * @copyright * (c) 1998-2025 Codejock Software, All Rights Reserved. * * This source file is the property of Codejock Software and must not be * redistributed by any means without the explicit written permission of * Codejock Software. * * The use of this source code is governed by the terms and conditions specified * in the Toolkit Pro license agreement. Codejock Software grants you, as a * single software developer, the limited right to use this software on one * computer only. * * Contact Information: * support@codejock.com * http://www.codejock.com * */ /** @cond */ #if !defined(__XTPHYPERLINK_H__) # define __XTPHYPERLINK_H__ /** @endcond */ # if _MSC_VER > 1000 # pragma once # endif // _MSC_VER > 1000 # include "Common/Base/Diagnostic/XTPDisableNoisyWarnings.h" /** * @brief * CXTPHyperLink is a CStatic derived class. It is used to display a text * string that is used as a hyperlink control. The link's active, hover, * and selected color attributes are configurable. */ class _XTP_EXT_CLASS CXTPHyperLink : public CStatic { /** @cond */ DECLARE_DYNAMIC(CXTPHyperLink) /** @endcond */ public: /** * @brief * Constructs a CXTPHyperLink object. */ CXTPHyperLink(); /** * @brief * Destroys a CXTPHyperLink object, handles cleanup and deallocation. */ virtual ~CXTPHyperLink(); public: /** * @brief * Call this member function to enable/disable ShellExecute to be called * for the URL that is specified for the hyperlink control. If disabled, * you can add a BN_CLICKED message handler to perform your own task when * the link is clicked. * @param bEnable true to enable ShellExecute, false to disable. */ void EnableShellExecute(bool bEnable); /** * @brief * This member function sets the URL for the hyperlink control. * @param lpszLink A NULL-terminated character string that * represents the URL for the hyperlink. */ virtual void SetURL(LPCTSTR lpszLink); /** * @brief * This member function retrieves the URL for the hyperlink. * @return * A CString object that represents the URL for the hyperlink control. */ virtual CString GetURL() const; /** * @brief * This member function will set the RGB color values for the hyperlink text. * @param clrLink An RGB value representing the color for the hyperlink text color. * @param clrVisited An RGB value representing the color for the hyperlink text color * when the mouse is hovering. * @param clrHover An RGB value representing the color for the hyperlink text color * when the URL has been visited. */ virtual void SetColors(COLORREF clrLink, COLORREF clrVisited, COLORREF clrHover); /** * @brief * This member function retrieves the current hyperlink text color. * @return * An RGB color value that represents the current hyperlink text color. */ virtual COLORREF GetLinkColor() const; /** * @brief * This member function retrieves the current hyperlink text color * when the link has been activated. * @return * An RGB color value that represents the current hyperlink text color when * the link has been activated. */ virtual COLORREF GetVisitedColor() const; /** * @brief * This member function retrieves the current hyperlink text color * when the mouse hovers over the hyperlink. * @return * An RGB color value that represents the current hyperlink text color when * the mouse hovers over the hyperlink. */ virtual COLORREF GetHoverColor() const; /** * @brief * This member function will cause the control to display the hyperlink * text color as visited. * @param bVisited A boolean flag that, when set to true, causes the control to * display the hyperlink text color as visited. */ virtual void SetVisited(bool bVisited = true); /** * @brief * This member function checks to see if the user has visited the URL * associated with the hyperlink. * @return * true if the URL has been visited, otherwise false. */ virtual bool GetVisited() const; /** * @brief * This member function will set the cursor associated with the hyperlink * control. The associated cursor will be displayed when the mouse hovers * over the hyperlink control. * @param hCursor Handle of the cursor to be associated with the hyperlink control. */ virtual void SetLinkCursor(HCURSOR hCursor); /** * @brief * This member function will get a handle to the current cursor associated * with the hyperlink control. * @return * A handle to the current cursor for the hyperlink control. */ virtual HCURSOR GetLinkCursor() const; /** * @brief * This member function will cause the hyperlink to display the text * as underlined. * @param bUnderline A boolean flag that, when set to true, causes the control * to display the text as underlined. By default, this * parameter is 'true'. */ virtual void SetUnderline(bool bUnderline = true); /** * @brief * This member function checks to see if the hyperlink text is underlined. * @return * true if the hyperlink text is underlined, otherwise false. */ virtual bool GetUnderline() const; /** * @brief * This member function will set the background fill color for the * hyperlink control. By default, the hyperlink control uses the system * color for COLOR_3DFACE. * @param clrBack An RGB value representing the background fill color. */ virtual void SetBackColor(COLORREF clrBack); /** * @brief * This member function will retrieve the current background fill color for * the hyperlink control. * @return * A COLORREF value representing the background fill color for the hyperlink * control. */ virtual COLORREF GetBackColor() const; /** * @brief * This member function is called to execute the shell command associated * with the current URL. * @param lpszLink Pointer to a NULL-terminated string that represents the URL to * jump to. If NULL, then the default URL is activated. * @param nShowCmd Display state for the shell command associated with the URL. * The default is SW_SHOW. * @param lpszParams Pointer to a NULL-terminated string that represents additional * parameters that are to be passed to the ShellExecute command. * @param lpszDir Pointer to a NULL-terminated string that represents the default * directory. * @return * TRUE if successful, otherwise FALSE. */ virtual bool GotoURL(LPCTSTR lpszLink = NULL, int nShowCmd = SW_SHOW, LPCTSTR lpszParams = NULL, LPCTSTR lpszDir = NULL); /** * @brief * This member function checks to see if the hyperlink control is a * text control. * @return * true if the hyperlink control is a text control, otherwise false. */ virtual bool IsTextControl(); /** * @brief * Call this member function to enable/disable tooltips for the hyperlink * control. * @param bEnable true to enable tooltips, false to disable. */ void EnableToolTips(bool bEnable = true); /** * @brief * Call this member function to set the tooltip text for the tooltip * associated with the hyperlink control. * @param lpszTipText A NULL-terminated string that represents the new tooltip * text to display. */ void SetTipText(LPCTSTR lpszTipText); /** * @brief * Call this member to determine if the hyperlink is currently hot. * @details * The hyperlink is hot when the mouse pointer is positioned over it. * @return * true if the hyperlink is currently hot, otherwise false. */ virtual bool IsLinkHot(); /** * @brief * This member function is called by the CXTPHyperLink object to display * a message box whenever an error occurs. * @param iErrorNo See the ShellExecute API for a list of error codes. */ virtual void ReportError(int iErrorNo); protected: /** * @brief * This member function is called by the CXTPHyperLink class to perform * initialization when the window is created or sub-classed. * @return * true if the window was successfully initialized, otherwise false. */ virtual bool Init(); /** * @brief * This member function is called by the CXTPHyperLink class to * initialize the font to be used by the hyperlink control. * @return * true if the font was successfully initialized, otherwise false. */ virtual bool InitFont(); /** * @brief * This member function is called by the CXTPHyperLink class to * initialize a font to be used by the hyperlink control. * @param font Reference to the font to be created. * @param bUnderline TRUE to create underlined font. * @return * TRUE if the control was successfully initialized, otherwise FALSE. */ virtual BOOL CreateFont(CFont& font, BOOL bUnderline); /** @cond */ DECLARE_MESSAGE_MAP() //{{AFX_VIRTUAL(CXTPHyperLink) virtual BOOL PreTranslateMessage(MSG* pMsg); virtual void PreSubclassWindow(); protected: virtual BOOL PreCreateWindow(CREATESTRUCT& cs); //}}AFX_VIRTUAL //{{AFX_MSG(CXTPHyperLink) afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message); afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct); afx_msg HBRUSH CtlColor(CDC* pDC, UINT nCtlColor); afx_msg void OnMouseMove(UINT nFlags, CPoint point); afx_msg void OnTimer(UINT_PTR nIDEvent); afx_msg BOOL OnEraseBkgnd(CDC* pDC); afx_msg void OnPaint(); afx_msg void OnWindowPosChanged(WINDOWPOS FAR* lpwndpos); afx_msg void OnLButtonDown(UINT nFlags, CPoint point); afx_msg BOOL OnClicked(); afx_msg LRESULT OnNcHitTest(CPoint point); afx_msg void OnKillFocus(CWnd* pOldWnd); afx_msg void OnSetFocus(CWnd* pOldWnd); afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags); afx_msg UINT OnGetDlgCode(); //}}AFX_MSG /** @endcond */ protected: bool m_bShellExec; /**< true to cause the hyperlink to call ShellExecute for the specified URL. */ bool m_bPreSubclassInit; /**< true when initializing from PreSubclassWindow. */ bool m_bUnderline; /**< Set to true for underlined text. */ bool m_bMouseOver; /**< Set to true when the cursor is hovering over the control. */ bool m_bVisited; /**< Set to true when the hyperlink has been activated. */ bool m_bTipEnabled; /**< Set to false to disable tooltips. */ CXTPFont m_xtpFont; /**< Font used by the hyperlink control. */ XTP_SUBSTITUTE_GDI_MEMBER_WITH_CACHED(CFont, m_font, m_xtpFont, GetFontHandle); CString m_strLink; /**< String object that represents the URL for this control. */ CString m_strTipText; /**< String object that represents the tooltip text for this control. */ HCURSOR m_hcurHand; /**< Handle to the default cursor for this control. */ COLORREF m_clrLink; /**< An RGB value representing the color for the hyperlink text color. */ COLORREF m_clrHover; /**< An RGB value representing the color for the hyperlink text color when the mouse is hovering. */ COLORREF m_clrVisited; /**< An RGB value representing the color for the hyperlink text color when the URL has been visited. */ COLORREF m_clrBack; /**< An RGB value representing the background fill color for the hyperlink control. */ CToolTipCtrl m_toolTip; /**< Tooltip to be displayed for the control. */ }; ////////////////////////////////////////////////////////////////////// /** @cond */ AFX_INLINE CString CXTPHyperLink::GetURL() const { return m_strLink; } AFX_INLINE void CXTPHyperLink::SetColors(COLORREF clrLink, COLORREF clrVisited, COLORREF clrHover) { m_clrLink = clrLink; m_clrVisited = clrVisited; m_clrHover = clrHover; RedrawWindow(); } AFX_INLINE COLORREF CXTPHyperLink::GetLinkColor() const { return m_clrLink; } AFX_INLINE COLORREF CXTPHyperLink::GetVisitedColor() const { return m_clrVisited; } AFX_INLINE COLORREF CXTPHyperLink::GetHoverColor() const { return m_clrHover; } AFX_INLINE void CXTPHyperLink::SetVisited(bool bVisited) { m_bVisited = bVisited; RedrawWindow(); } AFX_INLINE bool CXTPHyperLink::GetVisited() const { return m_bVisited; } AFX_INLINE void CXTPHyperLink::SetLinkCursor(HCURSOR hCursor) { m_hcurHand = hCursor; } AFX_INLINE HCURSOR CXTPHyperLink::GetLinkCursor() const { return m_hcurHand; } AFX_INLINE void CXTPHyperLink::SetUnderline(bool bUnderline) { m_bUnderline = bUnderline; InitFont(); } AFX_INLINE bool CXTPHyperLink::GetUnderline() const { return m_bUnderline; } AFX_INLINE bool CXTPHyperLink::IsTextControl() { return ((GetStyle() & 0xFF) <= SS_RIGHT) ? true : false; } AFX_INLINE void CXTPHyperLink::EnableShellExecute(bool bEnable) { m_bShellExec = bEnable; } AFX_INLINE void CXTPHyperLink::SetBackColor(COLORREF clrBack) { m_clrBack = clrBack; RedrawWindow(); } AFX_INLINE COLORREF CXTPHyperLink::GetBackColor() const { return (m_clrBack == (COLORREF)-1) ? GetXtremeColor(COLOR_3DFACE) : m_clrBack; } /** @endcond */ # include "Common/Base/Diagnostic/XTPEnableNoisyWarnings.h" /** @cond */ #endif // #if !defined(__XTPHYPERLINK_H__) /** @endcond */