/** * @file XTPTagCloudCtrl.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(__XTPTAGCLOUDCTRL_H__) # define __XTPTAGCLOUDCTRL_H__ /** @endcond */ # if _MSC_VER > 1000 # pragma once # endif // _MSC_VER > 1000 # include "Common/Base/Diagnostic/XTPDisableNoisyWarnings.h" /** * @brief * CXTPTagCloudStyle is a helper class used by CXTPTagCloudStyleManager * to manage styles for the CXTPTagCloudCtrl class. */ class _XTP_EXT_CLASS CXTPTagCloudStyle { public: /** * @brief * Default constructor. */ CXTPTagCloudStyle(); /** * @brief * Default constructor. * @param style Reference to a CXTPTagCloudStyle object. */ CXTPTagCloudStyle(const CXTPTagCloudStyle& style); /** * @brief * Default constructor. * @param nScore Unique ID for the style. * @param clrText An RGB value representing the style text color. * @param clrTextHover An RGB value representing the style text hover color. * @param clrBorder An RGB value representing the style border color. * Setting to COLORREF_NULL (-1) indicates no border. * @param lf Reference to a LOGFONT struct used to create * the font used by the style. */ CXTPTagCloudStyle(int nScore, COLORREF clrText, COLORREF clrTextHover, COLORREF clrBorder, LOGFONT& lf); /** * @brief * Sets the font for the style using the LOGFONT struct specified by lf. * @param lf Reference to a LOGFONT struct used to create the font used * by the style. */ void SetFont(LOGFONT& lf); /** * @brief * Overloaded operator initializes a CXTPTagCloudStyle class using * the object specified by style. * @param style Reference to a CXTPTagCloudStyle object used to initialize * this class. * @return * A reference to the CXTPTagCloudStyle object. */ CXTPTagCloudStyle& operator=(const CXTPTagCloudStyle& style); /** * @brief * Copies the contents from one CXTPTagCloudStyle object to another. * @param pSource Pointer to the source CXTPTagCloudStyle object. * @param pDest Pointer to the destination CXTPTagCloudStyle object. * @return */ static void AFX_CDECL Copy(const CXTPTagCloudStyle* pSource, CXTPTagCloudStyle* pDest); int m_nScore; /**< Unique identifier used to specify the score or weight of the style. */ CXTPFont m_xtpFont; /**< Font used by the style. */ XTP_SUBSTITUTE_GDI_MEMBER_WITH_CACHED(CFont, m_font, m_xtpFont, GetFontHandle); COLORREF m_clrText; /**< An RGB value representing the style text color. */ COLORREF m_clrTextHover; /**< An RGB value representing the style text hover color. */ COLORREF m_clrBorder; /**< An RGB value representing the style border color. */ }; /** * @brief * CArray based object used for storing CXTPTagCloudStyle structs. */ typedef CArray CXTPTagCloudStyleArray; /** * @brief * CXTPTagCloudStyleManager is a singleton class used to manage * CXTPTagCloudStyle structs that identify each tag style used by * CXTPTagCloudCtrl. */ class _XTP_EXT_CLASS CXTPTagCloudStyleManager : public CXTPCmdTarget { CXTPTagCloudStyleManager(); public: /** * @brief * Destructor used to handle cleanup and deallocation. */ ~CXTPTagCloudStyleManager(); /** * @brief * Called by the CXTPTagCloudCtrl to initialize a default array * of CXTPTagCloudStyle structs representing unique tag styles. */ void InitDefaultStyles(); /** * @brief * Call this member function to add a new style to the style array. * @param nScore Unique ID for the style. * @param clrText An RGB value representing the style text color. * @param clrTextHover An RGB value representing the style text hover color. * @param clrBorder An RGB value representing the style border color. * Setting to COLORREF_NULL (-1) indicates no border. * @param lf Reference to a LOGFONT struct used to create * the font used by the style. * @return * The index of the added element. */ INT_PTR AddStyle(int nScore, COLORREF clrText, COLORREF clrTextHover, COLORREF clrBorder, LOGFONT& lf); /** * @brief * Call this member function to add a new style to the style array. * @param pStyle Pointer to a valid CXTPTagCloudStyle object. * @return * The index of the added element. */ INT_PTR AddStyle(CXTPTagCloudStyle* pStyle); /** * @brief * Call this member function to remove an existing style from the * style array. * @param nScore Identifier of the style to remove. * @return * TRUE if successful, otherwise FALSE. */ BOOL RemoveStyle(int nScore); /** * @brief * Call this member function to remove all tag styles from the * style array and free any allocated memory. */ void RemoveAll(); /** * @brief * Call this member function to retrieve the style associated * with the identifier specified by nScore. * @param nScore Unique identifier for the style to find. * @return * A pointer to a CXTPTagCloudStyle object if successful, otherwise NULL. */ CXTPTagCloudStyle* GetStyle(int nScore); /** * @brief * Sets the color values for the style specified by nScore. * @param nScore ID of the style to update. * @param clrText An RGB value representing the style text color. * If COLORREF_NULL, then this value is ignored. * @param clrTextHover An RGB value representing the style text highlight color * If COLORREF_NULL, then this value is ignored. * @param clrBorder An RGB value representing the style border color. * If COLORREF_NULL, then no border will be drawn. * @return * TRUE if the style was found and updated, otherwise FALSE. */ BOOL SetColors(int nScore, COLORREF clrText, COLORREF clrTextHover, COLORREF clrBorder = COLORREF_NULL); /** * @brief * Sets the font for the style specified by nScore. * @param nScore ID of the style to update. * @param lf Reference to a LOGFONT struct used to create * the font used by the style. * @return * TRUE if the style was found and updated, otherwise FALSE. */ BOOL SetFont(int nScore, LOGFONT& lf); /** * @brief * Call this member function to retrieve a reference to the * CXTPTagCloudStyleArray managed by CXTPTagCloudStyleManager. * @return * A reference to a CXTPTagCloudStyleArray object. */ CXTPTagCloudStyleArray& GetCloudStyleArray(); /** * @brief * Call this member function to determine if the score * specified by nScore already exists in the array. * @param nScore Score index to check. * @return * TRUE if the score already exists, otherwise FALSE. */ BOOL ScoreExists(int nScore); protected: CXTPTagCloudStyleArray m_arrStyles; /**< Array of CXTPTagCloudStyle structs managed by CXTPTagCloudStyleManager. */ private: friend class CXTPSingleton; friend _XTP_EXT_CLASS CXTPTagCloudStyleManager* AFX_CDECL XTPTabCloudStyleManager(); # ifdef _XTP_ACTIVEX /** @cond */ DECLARE_DISPATCH_MAP() DECLARE_INTERFACE_MAP() DECLARE_OLETYPELIB_EX(CXTPTagCloudStyleManager); void OleInitDefaultStyles(); void OleAdd(LPDISPATCH pStyle); void OleRemove(long Score); void OleRemoveAll(); LPDISPATCH OleGet(long Score); void OleSetStyle(LPDISPATCH pStyle); BOOL OleScoreExists(long Score); LPDISPATCH OleCreateStyle(); virtual void OnFinalRelease(); afx_msg long OleGetItemCount(); afx_msg LPDISPATCH OleGetItem(long Index); DECLARE_ENUM_VARIANT(CXTPTagCloudStyleManager); /** @endcond */ # endif }; /** @cond */ AFX_INLINE CXTPTagCloudStyleArray& CXTPTagCloudStyleManager::GetCloudStyleArray() { return m_arrStyles; } /** @endcond */ /** * @brief * Use the XTPTabCloudStyleManager() function for access to the * singleton class CXTPTagCloudStyleManager. * @return A global tab cloud style manager object pointer. */ _XTP_EXT_CLASS CXTPTagCloudStyleManager* AFX_CDECL XTPTabCloudStyleManager(); /** * @brief * Manages the attributes for each tag element such as weight, font, * background and foreground color. */ struct XTP_TAGCLOUDTAG { /** * @brief * Default constructor initializes members. * @param lpszItem Name of the tag cloud item. * @param nScore Score of the tag cloud item. */ XTP_TAGCLOUDTAG(LPCTSTR lpszItem, int nScore) : nScore(nScore) , strItem(lpszItem) { } int nScore; /**< Style for this tag. */ CString strItem; /**< String value representing the tag text. */ CXTPEmptyRect rcItem; /**< Size and location of the tag. */ }; /** * @brief * XTPTagCloudSort is an enumeration used by the CXTPTagCloudTagArray * class to perform sorting operations. */ enum XTPTagCloudSort { xtpTagCloudNone, /**< No sorting. */ xtpTagCloudAlpha, /**< Sort by tag name. */ xtpTagCloudNumeric, /**< Sort by tag score. */ }; /** * @brief * CXTPTagCloudTagArray is a CArray derived class used to manage * XTP_TAGCLOUDTAG objects for the CXTPTagCloudCtrl class. */ class _XTP_EXT_CLASS CXTPTagCloudTagArray : public CArray { public: /** * @brief * Call this member function to sort the tag item array by the * style specified by nSort. * @param nSort Specifies the sorting style; can be one of the * following values: xtpTagCloudNone, xtpTagCloudAlpha, * or xtpTagCloudNumeric. * @param bAsc TRUE to sort ascending, FALSE to sort descending. */ void Sort(XTPTagCloudSort nSort, BOOL bAsc); private: //----------------------------------------------------------------------- // Private use: CXTPTagCloudCtrl::RemoveAll() instead. //----------------------------------------------------------------------- void RemoveAll(); //----------------------------------------------------------------------- // Private use: CXTPTagCloudCtrl::RemoveTag(XTP_TAGCLOUDTAG* pTag) instead. //----------------------------------------------------------------------- void RemoveAt(INT_PTR nIndex, INT_PTR nCount = 1); static int AFX_CDECL CompareName(XTP_TAGCLOUDTAG* pTagA, XTP_TAGCLOUDTAG* pTagB, BOOL bAsc); static int AFX_CDECL CompareScore(XTP_TAGCLOUDTAG* pTagA, XTP_TAGCLOUDTAG* pTagB, BOOL bAsc); static int AFX_CDECL CompareNameAsc(LPCVOID a, LPCVOID b); static int AFX_CDECL CompareNameDesc(LPCVOID a, LPCVOID b); static int AFX_CDECL CompareScoreAsc(LPCVOID a, LPCVOID b); static int AFX_CDECL CompareScoreDesc(LPCVOID a, LPCVOID b); friend class CXTPTagCloudCtrl; }; /** @cond */ AFX_INLINE int AFX_CDECL CXTPTagCloudTagArray::CompareNameAsc(LPCVOID a, LPCVOID b) { return CompareName(*(XTP_TAGCLOUDTAG**)a, *(XTP_TAGCLOUDTAG**)b, TRUE); } AFX_INLINE int AFX_CDECL CXTPTagCloudTagArray::CompareNameDesc(LPCVOID a, LPCVOID b) { return CompareName(*(XTP_TAGCLOUDTAG**)a, *(XTP_TAGCLOUDTAG**)b, FALSE); } AFX_INLINE int AFX_CDECL CXTPTagCloudTagArray::CompareScoreAsc(LPCVOID a, LPCVOID b) { return CompareScore(*(XTP_TAGCLOUDTAG**)a, *(XTP_TAGCLOUDTAG**)b, TRUE); } AFX_INLINE int AFX_CDECL CXTPTagCloudTagArray::CompareScoreDesc(LPCVOID a, LPCVOID b) { return CompareScore(*(XTP_TAGCLOUDTAG**)a, *(XTP_TAGCLOUDTAG**)b, FALSE); } /** @endcond */ /** * @brief * The CXTPTagCloudCtrl class is used to create a tag cloud control * representing a visual depiction of generated tags identified by * color and font size to represent the prominence or frequency of * the tags depicted. */ class _XTP_EXT_CLASS CXTPTagCloudCtrl : public CWnd { public: /** * @brief * Default constructor. */ CXTPTagCloudCtrl(); /** * @brief * Destructor used to handle cleanup and deallocation. */ virtual ~CXTPTagCloudCtrl(); /** * @brief * Call this member function to create the CXTPTagCloudCtrl window. * @param dwStyle Specifies the window style. * @param rect Size of the tag cloud control. * @param pParentWnd Parent window. * @param nID Identifier for the tag cloud control. * @return * TRUE if successful, otherwise FALSE. */ virtual BOOL Create(DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID); using CWnd::Create; /** * @brief * Adds a new tag to the tag cloud control. * @param pTag A pointer to a valid XTP_TAGCLOUDTAG object to add. */ void AddTag(XTP_TAGCLOUDTAG* pTag); /** * @brief * Removes a tag from the tag cloud control. * @param pTag A pointer to a valid XTP_TAGCLOUDTAG object to remove. */ void RemoveTag(XTP_TAGCLOUDTAG* pTag); /** * @brief * Removes all tags from the XTP_TAGCLOUDTAG window. */ void RemoveAll(); /** * @brief * Retrieves the tag from the cursor position specified by point. * @param point Cursor position in client coordinates. * @return * A pointer to an XTP_TAGCLOUDTAG if successful, otherwise NULL. */ XTP_TAGCLOUDTAG* HitTest(const CPoint& point); /** * @brief * Recalculates the size and position for all tags associated * with the tag cloud control. */ virtual void RecalcLayout(); /** * @brief * Sets the margin for the client area of the tag cloud control. * @param nMargin Size, in pixels, of the margin to set. */ void SetMargin(int nMargin); /** * @brief * Retrieves the client area margin for the tag cloud control. * @return * An integer representing the client area margin in pixels. */ int GetMargin() const; /** * @brief * Sets the padding for each tag associated with the tag cloud control. * @param nPadding Size, in pixels, of the padding to set. */ void SetPadding(int nPadding); /** * @brief * Retrieves the padding for each tag associated with the tag cloud control. * @return * An integer representing the padding for each tag in pixels. */ int GetPadding() const; /** * @brief * Enables/disables tooltips for the tag cloud control. * @param bTipEnabled TRUE to enable tooltips, FALSE to disable. */ void EnableTooltip(BOOL bTipEnabled); /** * @brief * Called to determine if tooltips are enabled for the tab cloud control. * @return * TRUE if tooltips are enabled for the tag cloud control. */ BOOL IsTipEnabled() const; /** * @brief * Enables/disables tag item focus rectangle display. * @param bFocusRect TRUE to enable tag item focus display. */ void EnableFocusRect(BOOL bFocusRect); /** * @brief * Called to determine if tag item focus display is enabled for * the tag cloud control. * @return * TRUE if tag item focus has been enabled, otherwise FALSE. */ BOOL IsFocusEnabled() const; /** * @brief * Sets the sort order for all tags associated with the tag * cloud control. * @param nSortOrder Specifies the sort order for the tag items; * can be one of the following values: xtpTagCloudNone, * xtpTagCloudAlpha, or xtpTagCloudNumeric. * @param bAsc TRUE to sort ascending, FALSE to sort descending. */ void SetSortOrder(XTPTagCloudSort nSortOrder, BOOL bAsc); /** * @brief * Called to determine the sort order for the tag cloud control; * can be one of the following values: xtpTagCloudNone, * xtpTagCloudAlpha or xtpTagCloudNumeric. * @return * A XTPTagCloudSort enumeration value representing the tag cloud * control sort order. */ XTPTagCloudSort GetSortOrder() const; /** * @brief * Retrieves a pointer to the currently selected tag if any. * @return * A pointer to the currently selected XTP_TAGCLOUDTAG object * if a tag has been selected, otherwise NULL. */ XTP_TAGCLOUDTAG* GetCurSel(); /** * @brief * Sets the current selection for the tag cloud control * and sends an event notification to the owner window. * @param pCurSel A pointer to a valid XTP_TAGCLOUDTAG tag. */ void SetCurSel(XTP_TAGCLOUDTAG* pCurSel); /** * @brief * Sets the background color for the tag cloud control. * @param clrBack A CXTPPaintManagerColorGradient representing the * background color for the tag cloud control. If * dark and light colors are specified, then the background * will be drawn gradient, otherwise drawn solid. * @param bHorz TRUE if the gradient should be drawn horizontal, * FALSE to draw vertical. */ void SetBackColor(CXTPPaintManagerColorGradient clrBack, BOOL bHorz = FALSE); /** * @brief * Retrieves the background color for the tag cloud control. * @return * A CXTPPaintManagerColorGradient representing the background * color for the tag cloud control. */ CXTPPaintManagerColorGradient GetBackColor() const; /** * @brief * Sets the border color for the tag cloud control. * @param clrBorder Specifies the new border color. */ void SetBorderColor(CXTPPaintManagerColor clrBorder); /** * @brief * Retrieves the border color for the tag cloud control. * @return * A CXTPPaintManagerColor object representing the border color * for the tag cloud control. */ CXTPPaintManagerColor GetBorderColor() const; /** * @brief * Determines if the background gradient fill style is horizontal * or vertical. * @return * TRUE if the fill style is horizontal, FALSE if vertical. */ BOOL IsFillHorz() const; /** * @brief * Called to restore all default values for the tag cloud control. */ void RestoreDefaults(); //{{AFX_VIRTUAL(CXTPTagCloudCtrl) public: virtual BOOL PreTranslateMessage(MSG* pMsg); //}}AFX_VIRTUAL protected: /** * @brief * Retrieves a reference to the CXTPTagCloudTagArray that contains * all of the tags associated with the tag cloud control. * @return * A reference to a CXTPTagCloudTagArray object. */ virtual CXTPTagCloudTagArray& GetTagArray(); /** * @brief * Called by the tag cloud control to register the window * class used to create the control. * @param hInstance Handle to the instance that contains the window * procedure for the class. * @return * TRUE if successful, otherwise FALSE. */ virtual BOOL RegisterWindowClass(HINSTANCE hInstance = NULL); /** * @brief * Called by the tag cloud control to draw the client area of * the control. * @param pDC Pointer to a valid device context. * @param rcClient Size of the client area to draw. */ virtual void OnDraw(CDC* pDC, const CRect& rcClient); /** * @brief * Called by the OnDraw function to calculate the size and * position for a tag in the row specified by arrRow. * @param rcClient Specifies the client area of the tag cloud * excluding margins. * @param arrRow Array of tags representing a single row in the * tag cloud control. * @return * A CSize object representing the max width and height for * each tag in the row specified by arrRow. */ virtual CSize CalcRowLayout(const CRect& rcClient, const CXTPTagCloudTagArray& arrRow); /** * @brief * Retrieves the cursor position in window coordinates and * determines if the cursor is hovering over the tag cloud window. * @return * TRUE if the cursor is hovering over the tag cloud control, * otherwise FALSE. */ virtual BOOL PointInRect(); /** * @brief * Called during mouse move events to set the active/inactive * state for the tag cloud control. * @param bActive TRUE if the tag cloud control is active, * FALSE if inactive. */ virtual void SetActive(BOOL bActive); /** * @brief * Called by tag cloud control to send notification messages * to the owner window when an event specified by nEventCode * occurs. * @param pTag Pointer to an XTP_TAGCLOUDTAG struct. * @param nEventCode Event code identifier. * @return * TRUE if notification was sent to the owner window, * otherwise FALSE. */ virtual BOOL OnNotify(XTP_TAGCLOUDTAG* pTag, UINT nEventCode); using CWnd::OnNotify; /** * @brief * Removes all tags from the XTP_TAGCLOUDTAG window. */ void RemoveAllInternal(); int m_nPadding; /**< Size, in pixels, of the padding around each tag item. */ int m_nMargin; /**< Size, in pixels, of the margin for the client area. */ BOOL m_bActive; /**< TRUE if the tag cloud control is active. */ BOOL m_bTipEnabled; /**< Set to FALSE to disable tooltips. */ BOOL m_bFocusRect; /**< Set to FALSE to disable focus rect. */ BOOL m_bHorz; /**< TRUE if the background gradient colors should be drawn horizontal, FALSE if vertical. */ BOOL m_bAsc; /**< TRUE if sorting ascending, FALSE if sorting descending. */ HCURSOR m_hCursor; /**< Handle to the mouse hover cursor. */ CToolTipCtrl m_wndToolTip; /**< Tooltip to be displayed for the control. */ XTPTagCloudSort m_nSortOrder; /**< Specifies the sort order for the tag cloud control. */ XTP_TAGCLOUDTAG* m_pHover; /**< Pointer to the tag item that the mouse cursor is currently hovering over. */ XTP_TAGCLOUDTAG* m_pCurSel; /**< Pointer to the tag item that is currently selected. */ CXTPTagCloudTagArray m_arrTags; /**< Array of all tags associated with the tag cloud control. */ CXTPTagCloudTagArray m_arrTagsSorted; /**< Array of sorted tags associated with the tag cloud control. */ CXTPPaintManagerColor m_clrBorder; /**< Tag cloud control border color. */ CXTPPaintManagerColorGradient m_clrBack; /**< Tag cloud control background colors. */ CXTPWinThemeWrapper m_themeWrapper; /**< Determines if tag cloud control should use Windows themes. */ //{{AFX_MSG(CXTPTagCloudCtrl) afx_msg void OnPaint(); afx_msg void OnLButtonDown(UINT nFlags, CPoint point); afx_msg void OnSize(UINT nType, int cx, int cy); afx_msg void OnMouseMove(UINT nFlags, CPoint point); afx_msg BOOL OnEraseBkgnd(CDC* pDC); afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message); afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point); afx_msg void OnRButtonDown(UINT nFlags, CPoint point); afx_msg void OnNcPaint(); afx_msg void OnNcCalcSize(BOOL bCalcValidRects, NCCALCSIZE_PARAMS* lpncsp); //}}AFX_MSG /** @cond */ afx_msg void OnMouseLeave(); DECLARE_MESSAGE_MAP() /** @endcond */ }; /** @cond */ AFX_INLINE void CXTPTagCloudCtrl::SetMargin(int nMargin) { m_nMargin = nMargin; } AFX_INLINE int CXTPTagCloudCtrl::GetMargin() const { return m_nMargin; } AFX_INLINE void CXTPTagCloudCtrl::SetPadding(int nPadding) { m_nPadding = nPadding; } AFX_INLINE int CXTPTagCloudCtrl::GetPadding() const { return m_nPadding; } AFX_INLINE BOOL CXTPTagCloudCtrl::IsTipEnabled() const { return m_bTipEnabled; } AFX_INLINE void CXTPTagCloudCtrl::EnableFocusRect(BOOL bFocusRect) { m_bFocusRect = bFocusRect; if (GetSafeHwnd()) RedrawWindow(); } AFX_INLINE BOOL CXTPTagCloudCtrl::IsFocusEnabled() const { return m_bFocusRect; } AFX_INLINE XTPTagCloudSort CXTPTagCloudCtrl::GetSortOrder() const { return m_nSortOrder; } AFX_INLINE XTP_TAGCLOUDTAG* CXTPTagCloudCtrl::GetCurSel() { return m_pCurSel; } AFX_INLINE void CXTPTagCloudCtrl::SetBackColor(CXTPPaintManagerColorGradient clrBack, BOOL bHorz) { m_clrBack = clrBack; m_bHorz = bHorz; } AFX_INLINE CXTPPaintManagerColorGradient CXTPTagCloudCtrl::GetBackColor() const { return m_clrBack; } AFX_INLINE void CXTPTagCloudCtrl::SetBorderColor(CXTPPaintManagerColor clrBorder) { m_clrBorder = clrBorder; } AFX_INLINE CXTPPaintManagerColor CXTPTagCloudCtrl::GetBorderColor() const { return m_clrBorder; } AFX_INLINE BOOL CXTPTagCloudCtrl::IsFillHorz() const { return m_bHorz; } /** @endcond */ ///////////////////////////////////////////////////////////////////////////// //{{AFX_INSERT_LOCATION}} // Microsoft Visual C++ will insert additional declarations immediately before the previous line. # include "Common/Base/Diagnostic/XTPEnableNoisyWarnings.h" /** @cond */ #endif // !defined(__XTPTAGCLOUDCTRL_H__) /** @endcond */