/** * @file XTPHeaderCtrl.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(__XTHEADERCTRL_H__) # define __XTHEADERCTRL_H__ /** @endcond */ # if _MSC_VER >= 1000 # pragma once # endif // _MSC_VER >= 1000 # include "Common/Base/Diagnostic/XTPDisableNoisyWarnings.h" class CXTPImageManager; class CXTPHeaderCtrlTheme; /** * @brief * CXTPHeaderCtrl is a CHeaderCtrl derived class. It is used to create * a CXTPHeaderCtrl window similar to CHeaderCtrl, but with additional functionality. * @details * A "header control" is a window that is usually positioned above columns of text * or numbers. It contains a title for each column, and it can be divided * into parts. The user can drag the dividers that separate the parts to * set the width of each column. * * Use a header control, represented by class CXTPHeaderCtrl, to display * column headers for a columnar list. For example, a header control would * be useful for implementing column controls in a spreadsheet. * * The header control is usually divided into parts, called "header items", * each bearing a title for the associated column of text or numbers. Depending * on the styles you set, you can provide a number of direct ways for users * to manipulate the header items. */ class _XTP_EXT_CLASS CXTPHeaderCtrl : public CHeaderCtrl { /** @cond */ DECLARE_DYNAMIC(CXTPHeaderCtrl) /** @endcond */ public: /** * @brief * Constructs a CXTPHeaderCtrl object. */ CXTPHeaderCtrl(); /** * @brief * Destroys a CXTPHeaderCtrl object, handles cleanup and deallocation. */ virtual ~CXTPHeaderCtrl(); public: /** * @brief * Call this member function to enable auto-sizing for the header control. * This will cause the columns in the list control to be sized to fit * in the available space when the list control is resized. * @param bEnable true to enable an auto-sizing header control. */ void EnableAutoSize(bool bEnable = true); /** * @brief * Call this member function to freeze a column in the header control. * Freezing a column will disable sizing for the column. * @param iCol Index of the column to freeze. */ void FreezeColumn(int iCol); /** * @brief * Call this member function to thaw a column in the header control. * Thawing a column will enable sizing for the column if it was previously * frozen. * @param iCol Index of the column to thaw. */ void ThawColumn(int iCol); /** * @brief * Call this member function to thaw all columns in the header control. * This will will enable sizing for any column that was previously * frozen. */ void ThawAllColumns(); /** * @brief * Call this member function to determine if a specified column is * frozen. * @param iCol Index of the column to check. * @return * true if the column is frozen, otherwise false. */ bool IsColFrozen(int iCol); /** * @brief * Call this member to set the minimum size for auto-sizing columns. * The minimum size represents the smallest size that all columns can * be sized to. * @param iMinSize Minimum column size. */ void SetMinSize(int iMinSize); /** * @brief * This member function will set the sort image for the specified column. * @param iSortCol Zero-based index of the column to set the sort image for. * @param bSortAsc TRUE if ascending, otherwise FALSE. * @return * A zero-based index of the previously sorted column. */ int SetSortImage(int iSortCol, BOOL bSortAsc); /** * @brief * Call this member function to return the index to the currently sorted * column. * @param pbSortAsc Set to TRUE if ascending, otherwise FALSE. * @return * The index of the currently sorted column. */ int GetSortedCol(BOOL* pbSortAsc = NULL); /** * @brief * Call this member function to set the bitmap image for the specified * header item. * @param iCol Zero-based index of the column to set the sort image for. * @param uBitmapID Resource ID of the bitmap to use. * @param dwRemove Indicates the header format style to remove, see HD_ITEM structure. * Example: * The following example demonstrates the use of SetBitmap. *
* // add bitmap images. * m_header.SetBitmap(0, IDB_COLUMN_0, FALSE, RGB(0, 255, 0)); * m_header.SetBitmap(1, IDB_COLUMN_1, FALSE, RGB(0, 255, 0)); * m_header.SetBitmap(2, IDB_COLUMN_2, FALSE, RGB(0, 255, 0)); **/ void SetBitmap(int iCol, UINT uBitmapID, DWORD dwRemove = NULL); /** * @brief * Call this member function to set the bitmap image for the specified * header item. * @param iCol Zero-based index of the column to set the sort image for. * @param uBitmapID Resource ID of the bitmap to use. * @param bRemove TRUE to remove a bitmap, FALSE if adding a bitmap. * @param crMask Color used to generate the mask. Each pixel of * this color in the given bitmap is changed to black * and the corresponding bit in the mask is set to one. * Example: * The following example demonstrates the use of SetBitmap. *
* // add bitmap images. * m_header.SetBitmap(0, IDB_COLUMN_0, FALSE, RGB(0, 255, 0)); * m_header.SetBitmap(1, IDB_COLUMN_1, FALSE, RGB(0, 255, 0)); * m_header.SetBitmap(2, IDB_COLUMN_2, FALSE, RGB(0, 255, 0)); **/ void SetBitmap(int iCol, UINT uBitmapID, BOOL bRemove, COLORREF crMask); /** * @brief * Call this member function to determine if the specified header * item is pressed (selected). * @param iItem Index of the header item to check. * @return * TRUE if the specified header item is pressed (selected). */ virtual BOOL ItemPressed(int iItem); /** * @brief * This member function is called whenever the theme has changed. * @details * Override this member function to add additional functionality * whenever the control theme changes. */ virtual void OnThemeChanged(); /** * @brief * This member function is called to check if the header control * is using a theme. * @return * TRUE if a theme is used, otherwise FALSE. */ BOOL IsThemeValid() const; /** * @brief * Tests a point to determine which header item, if any, is at the * specified point. * @param pt POINT structure that contains the point to be hit test, * in client coordinates. * @param pFlags Variable that receives information about the results of a hit * test. This member can be one or more of the values listed in * the Remarks section. * @details * pFlags can be one or more of the following values: * HHT_ABOVE: The point is above the header control's * bounding rectangle. * HHT_BELOW: The point is below the header control's * bounding rectangle. * HHT_NOWHERE: The point is inside the header control's * bounding rectangle but is not over a header item. * HHT_ONDIVIDER: The point is on the divider between two * header items. * HHT_ONDIVOPEN: The point is on the divider of an item that has a * width of zero. Dragging the divider reveals the item * instead of resizing the item to the left of the divider. * HHT_ONHEADER: The point is inside the header control's * bounding rectangle. * HHT_ONFILTER: Version 5.80 The point is over the * filter area. * HHT_ONFILTERBUTTON: Version 5.80 The point is on the * filter button. * HHT_TOLEFT: The point is to the left of the header * control's bounding rectangle. * HHT_TORIGHT: The point is to the right of the header * control's bounding rectangle. * @return * If the hit test is successful, returns the index of the item at * the hit test point, if any. Otherwise, returns a value of -1. */ int HitTest(CPoint pt, UINT* pFlags = NULL) const; /** * @brief * Called by the header control to recalculate the size and layout * for the header control and header items. * @return * TRUE if successful, otherwise FALSE. */ BOOL RecalcLayout(); /** * @brief * This member function must be called after creation to initialize * the font that the header will use. * @param bBoldFont TRUE if the header's font should be bold. */ virtual void InitializeHeader(BOOL bBoldFont); /** * @brief * This member function is called to associate a menu and toolbar * resource with the context menu. * @param popupMenuID Resource ID for the pop-up menu used with the header. * @param nPos Position of the submenu to be displayed. */ virtual void SetMenuID(UINT popupMenuID, int nPos = 0); /** * @brief * This member function can be used to toggle the font from bold to normal. * @param bBoldFont TRUE if the header's font should be bold. */ virtual void SetFontBold(BOOL bBoldFont = TRUE); /** * @brief * Call this member function to enable/disable the column sort arrow. * @param bSortArrow TRUE to draw the column sort arrow. */ virtual void ShowSortArrow(BOOL bSortArrow); /** * @brief * Call this member function to set the text justification for the * header control. * @param nFlag Text alignment; either LVCFMT_CENTER, LVCFMT_LEFT, or LVCFMT_RIGHT. * @return * TRUE if successful, otherwise FALSE. */ virtual BOOL SetAlingment(int nFlag); /** * @brief * Call this member function to determine if the current sorting order * is ascending. * @return * TRUE if the sorting order is ascending, otherwise FALSE. */ BOOL GetAscending() const; /** * @brief * Call this member function to enable/disable the pop-up menu display whenever * a user right clicks on the header control. * @param bEnableMenus TRUE to enable pop-up menus, FALSE to disable. */ void EnablePopupMenus(BOOL bEnableMenus); /** * @brief * Call this member function to determine if the header control displays * a sort arrow. * @return * TRUE if the header control displays a sort arrow, otherwise FALSE. */ BOOL HasSortArrow(); /** * @brief * Call this member function to resize all header columns equally * to fit the available client area. */ void ResizeColumnsToFit(); /** * @brief * Retrieves the image manager associated with the header. * @return * Pointer to the image manager object that stores images in * the header. */ CXTPImageManager* GetImageManager() const; /** * @brief * Call this method to assign a new image manager. * @param pImageManager Pointer to the new image manager object that will * store images in the header. */ void SetImageManager(CXTPImageManager* pImageManager); /** * @brief * Call this member to change the visual theme of the control. * @param eTheme New window theme. Can be any of the values listed in * the Remarks section. * @details * eTheme can be one of the following values: * xtpControlThemeDefault: Use default theme. * xtpControlThemeNativeWinXP: Use Windows Explorer theme. * xtpControlThemeOfficeXP: Use Office XP theme. * xtpControlThemeOffice2003: Use Office 2003 theme. * @return TRUE if successful; otherwise FALSE. */ BOOL SetTheme(XTPControlTheme eTheme); /** * @brief * Call this member to change the visual theme of the control. * @param pTheme New window theme pointer. * @return TRUE if successful; otherwise FALSE. */ BOOL SetTheme(CXTPHeaderCtrlTheme* pTheme); /** * @brief * Call this member function to get a pointer to the currently selected theme. * @return * A pointer to a CXTPHeaderCtrlTheme object representing the currently * selected theme. */ CXTPHeaderCtrlTheme* GetTheme(); /** * @brief * Gets DPI bitmap scaling flag. If set, all raster icons and bitmaps * used in the control will be stretched automatically if DPI scaling * factor for control's window isn't equal to 100%. The default value is * derived from CXTPDpi::IsDpiBitmapScalingEnabled. Once changed the new value * will be used. * @return * The current value of the DPI bitmap scaling flag for the control. */ BOOL IsDpiBitmapScalingEnabled() const; /** * @brief * Sets DPI bitmap scaling flag. If set, all raster icons and bitmaps * used in the control will be stretched automatically if DPI scaling * factor for control's window isn't equal to 100%. The default value is * derived from CXTPDpi::IsDpiBitmapScalingEnabled. Once changed the new value * will be used. * @param bEnable TRUE to enable bitmaps scaling, FALSE to disable. */ void EnableDpiBitmapScaling(BOOL bEnable = TRUE); protected: /** * @brief * This member function is used by the header control to determine * the text alignment for the system locale. * @return * true if the text alignment is right-to-left (RTL), or * false if the text alignment is left-to-right (LTR). */ virtual bool DetermineRTL(); /** * @brief * This member function is used by the header control to auto-size the * columns for the list control. * @param iNewWidth New width to resize all columns to. */ virtual void ApplyFieldWidths(int iNewWidth); /** * @brief * This member function is used by the header control to determine the * new width for auto-sized columns and to resize the columns accordingly. * @param iNewWidth New width to resize all columns to. If iNewWidth * is '0', then columns are equally sized to fit the * available client area. */ virtual void FitFieldWidths(int iNewWidth); /** * @brief * This member function is used by the header control to determine * the total width of all frozen columns in the header control. * @return * The combined size, in pixels, of all frozen columns. */ virtual int GetFrozenColWidth(); /** * @brief * Called to send WM_NOTIFY to tell the parent's owner that a column needs * to be sorted. * @param iIndex Index of the column to be sorted. */ void SendNotify(int iIndex); /** * @brief * Call this member function to refresh theme colors and redraw the control. */ virtual void RefreshMetrics(); /** @cond */ //{{AFX_VIRTUAL(CXTPHeaderCtrl) virtual BOOL OnWndMsg(UINT message, WPARAM wParam, LPARAM lParam, LRESULT* pResult); //}}AFX_VIRTUAL /** @endcond */ protected: /** @cond */ DECLARE_MESSAGE_MAP() //{{AFX_MSG(CXTPHeaderCtrl) afx_msg void OnWindowPosChanging(WINDOWPOS FAR* lpwndpos); afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message); afx_msg void OnPaint(); afx_msg LRESULT OnPrintClient(WPARAM wParam, LPARAM /*lParam*/); afx_msg BOOL OnEraseBkgnd(CDC* pDC); afx_msg void OnLButtonDown(UINT nFlags, CPoint point); afx_msg void OnLButtonUp(UINT nFlags, CPoint point); afx_msg void OnMouseMove(UINT nFlags, CPoint point); afx_msg void OnTimer(UINT_PTR nIDEvent); afx_msg LRESULT OnLayout(WPARAM wparam, LPARAM lparam); afx_msg void OnDestroy(); afx_msg BOOL OnItemchanging(NMHDR* pNMHDR, LRESULT* pResult); afx_msg void OnRButtonDown(UINT nFlags, CPoint point); afx_msg void OnSortAsc(); afx_msg void OnSortDsc(); afx_msg void OnAlignLeft(); afx_msg void OnAlignCenter(); afx_msg void OnAlignRight(); //}}AFX_MSG afx_msg LRESULT OnSetTheme(WPARAM wParam, LPARAM lParam); /** @endcond */ protected: int m_iMinSize; /**< Minimum column size for an auto-size header control. */ int m_nPos; /**< Index of the pop-up menu contained in the menu. */ int m_iOverIndex; /**< Column that the mouse is currently hovering over. */ int m_nSortedCol; /**< Last column pressed during sort. */ bool m_bRTL; /**< Used internally to determine if text is right-to-left or left-to-right (depends on system locale). */ bool m_bAutoSize; /**< true if the header control columns are auto-sizing. */ BOOL m_bEnableMenus; /**< TRUE to disable the pop-up menu display. */ BOOL m_bAscending; /**< Used, when column is pressed, to draw a sort arrow. */ BOOL m_bLBtnDown; /**< TRUE if the left mouse button is pressed. */ BOOL m_bPainted; /**< Used during paint operations. */ UINT m_popupMenuID; /**< Pop-up menu resource ID. */ CPoint m_pt; /**< Point where right click took place. */ CList