/** * @file XTPListBase.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(__XTPLISTBASE_H__) # define __XTPLISTBASE_H__ /** @endcond */ # if _MSC_VER > 1000 # pragma once # endif // _MSC_VER > 1000 # include "Common/Base/Diagnostic/XTPDisableNoisyWarnings.h" /** * @brief * CXTPListBase is a non-inherited class. It implements the extended * list control services provided by the Xtreme Toolkit list control classes. */ class _XTP_EXT_CLASS CXTPListBase { public: /** * @brief * ROWCOLOR structure is used by the CXTPListBase class to * store user-defined background and text color settings for a * particular row in a list control. * @see * CRowColorList, SetRowColor, RemoveRowColors, Lookup */ struct ROWCOLOR { int iRow; /**< List control row index. */ COLORREF crBack; /**< RGB value for text background color. */ COLORREF crText; /**< RGB value for text foreground color. */ LPARAM lParam; /**< User-defined data. */ }; /** * @brief * List for maintaining ROWCOLOR structures. * @details * CList definition used by the CXTPListBase class to maintain * a list of ROWCOLOR structures representing each row that has * a user-defined color setting for the list control. * @see * CXTPListBase, CXTPListBase::SetRowColor, RemoveRowColors, Lookup, ROWCOLOR */ typedef CList CRowColorList; public: /** * @brief * Constructs a CXTPListBase object. */ CXTPListBase(); /** * @brief * Destroys a CXTPListBase object, handles cleanup and deallocation. */ virtual ~CXTPListBase(); public: /** * @brief * Call this member function to get a pointer to the flat header control. * @return * A pointer to a CXTPHeaderCtrl object if subclassed, otherwise NULL. */ CXTPHeaderCtrl* XTPGetHeaderCtrl() const; /** * @brief * This member function will set the sort image for the specified column. * @param nCol Zero-based index of the column to set the sort image for. * @param bAsc TRUE if ascending, otherwise FALSE. * @return * The zero-based index of the previously sorted column. */ virtual int SetSortImage(int nCol, BOOL bAsc); /** * @brief * This member function will return the column width stored in the * registry. * @param nCol Zero-based index of the column. * @return * The column width stored in the registry. */ virtual int GetStoredWidth(int nCol); /** * @brief * This member function will set the column width from the registry * settings. * @param nCol Zero-based index of the column. */ virtual void SetStoredWidth(int nCol); /** * @brief * This member function loads the column widths from the registry. */ virtual void LoadColumnWidths(); /** * @brief * This member function saves the column widths to the registry. */ virtual void SaveColumnWidths(); /** * @brief * Automatically sizes a specified column. * @param nCol Zero-based index of the column, or -1 to indicate all columns. */ virtual void AutoSizeColumn(int nCol = -1); /** * @brief * Automatically sizes a specified column. * @param nCol Zero-based index of the column, or -1 to indicate all columns. * @param bUseHeader Automatically sizes the column to fit the header text. * If you use this value with the last column, its width * is set to fill the remaining width of the list-view control. */ virtual void AutoSizeColumn(int nCol, BOOL bUseHeader); /** * @brief * Initializes the auto save feature. * @param lpszSection Registry section name. If NULL, then the * default is "Settings". * @param lpszEntry Registry entry name. If NULL, then the * default is "Column Info". * @param lpszDefault Registry default value. If NULL, then the * default ID. * @details * This member function will initialize the auto save feature. If * called, column widths will be saved to the system registry when * the list control window is destroyed. */ virtual void AutoSaveColumns(LPCTSTR lpszSection = NULL, LPCTSTR lpszEntry = NULL, LPCTSTR lpszDefault = NULL); /** * @brief * Call this member function to subclass the flat header control. * @param bBoldFont true to use a bold font in the header control. * @return TRUE if successful, FALSE otherwise. */ virtual bool SubclassHeader(bool bBoldFont = false); /** * @brief * Override this member function in your derived class to perform custom * sort routines. * @param nCol Passed in from the control. Index of the column clicked. * @param bAscending Passed in from the control. true if sort order should * be ascending. * @return TRUE if successful, FALSE otherwise. */ virtual bool SortList(int nCol, bool bAscending); /** * @brief * This member function is called to set extended styles for the list * control, ie: LVS_EX_FULLROWSELECT, LVS_EX_GRIDLINES, etc. See MSDN * documentation for a complete list of available styles. * @param dwExStyle DWORD value that specifies the extended list-view control * style. This parameter can be a combination of Extended * List-View Styles. */ virtual void SetExtendedStyle(DWORD dwExStyle); /** * @brief * This member function is called to retrieve the list control extended * style. * @return * A DWORD value that represents the extended style of the list control. */ virtual DWORD GetExtendedStyle(); /** * @brief * Call this member function to disable/enable column sizing. * @param bDisable true to disable column sizing, false to enable. */ virtual void DisableColumnSizing(bool bDisable); /** * @brief * Call this member function to set a minimum column size. * @param nSize Size in pixels of the column's minimum size. */ void SetMinimumColSize(int nSize); /** * @brief * Call this member function to get the minimum column size for the list * control. * @return * An integer value that represents the minimum column size for the list control. */ int GetMinimumColSize(); /** * @brief * Call this member function to get the maximum column size for the list control. * @return * An integer value that represents the maximum column size for the list control. */ int GetMaximumColSize(); /** * @brief * Call this member function to determine the row index and column * index for a 'point'. * @param point Point to be tested. * @param col Address of the column index. * @return * The row index, or -1 if 'point' is not over a row. */ virtual int HitTestEx(CPoint& point, int* col) const; /** * @brief * Call this member function to add a column after the right most column. * @param lpszColHeading The column's heading. * @param nWidth Width of the column in pixels. If this parameter is -1, * then the column width is the same as the previous column. * @param nFormat The alignment of the column. It can be LVCFMT_LEFT, * LVCFMT_RIGHT, or LVCFMT_CENTER. * @return * The index of the new column if successful, or -1 if unsuccessful. */ virtual int AddColumn(LPCTSTR lpszColHeading, int nWidth = -1, int nFormat = LVCFMT_LEFT); /** * @brief * This member function will build the columns for the list control. * @param nCols [in] Number of columns contained in the list control. * @param nWidth [in] 'int' array containing the column widths. * @param nColString [in] 'int' array containing the string resource ID for each * column. * @details * Call this member function to automatically generate the columns * for the list control. This is done by passing in an array of * column indexes specified by nCols, an array of column * widths specified by nWidth, and an array of column labels * specified by nColString or strColString. * Example: * The following example demonstrates the use of BuildColumns: *
	 * static int arColWidths[] = {
	 *    24,
	 *    21,
	 *    100,
	 *    180,
	 *    120
	 * };
	 *
	 * static CString arColLabels[] = {
	 *    _T(" "),
	 *    _T(" "),
	 *    _T("From"),
	 *    _T("Subject"),
	 *    _T("Received")
	 * };
	 *
	 * // Insert the columns.
	 * BuildColumns(_countof(arColWidths), arColWidths, arColLabels);
	 * 
* @return * true if successful, or false if an error occurred. */ virtual bool BuildColumns(int nCols, int* nWidth, int* nColString); /** * @brief * This member function will build the columns for the list control. * @param nCols [in] Number of columns contained in the list control. * @param nWidth [in] 'int' array containing the column widths. * @param strColString [in] CString array containing the string for each * column. * @details * Call this member function to automatically generate the columns * for the list control. This is done by passing in an array of * column indexes specified by nCols, an array of column * widths specified by nWidth, and an array of column labels * specified by nColString or strColString. * Example: * The following example demonstrates the use of BuildColumns: *
	 * static int arColWidths[] = {
	 *    24,
	 *    21,
	 *    100,
	 *    180,
	 *    120
	 * };
	 *
	 * static CString arColLabels[] = {
	 *    _T(" "),
	 *    _T(" "),
	 *    _T("From"),
	 *    _T("Subject"),
	 *    _T("Received")
	 * };
	 *
	 * // Insert the columns.
	 * BuildColumns(_countof(arColWidths), arColWidths, arColLabels);
	 * 
* @return * true if successful, or false if an error occurred. */ virtual bool BuildColumns(int nCols, int* nWidth, CString* strColString); /** * @brief * This member function gets the number of columns in the list. * @return * An integer value that represents the number of columns in the list. */ virtual int GetColumnCount(); /** * @brief * This member function copies a row to a new location. * @param nFrom Index of the source row. * @param nTo Index of the destination row. * @return * The index of the source row specified by 'nFrom'. */ virtual int CopyRow(int nFrom, int nTo); /** * @brief * This member function moves a row to a new location. * @param nFrom Index of the source row. * @param nTo Index of the destination row. * @return * true if successful, or false if an error occurred. */ virtual bool MoveRow(int nFrom, int nTo); /** * @brief * This member function is a utility function to retrieve the associated * header control. * @return * A CHeaderCtrl pointer to the associated header control. */ CHeaderCtrl* _xtGetHeaderCtrl() const; /** * @brief * This member function sets the row, text, and background colors for * the list control. * @param clrText An RGB value representing the row text color. * @param clrTextBk An RGB value representing the row background color. * @details * The iIndex version sets the text and background colors for * the specified row in the list control. */ void SetRowColors(COLORREF clrText, COLORREF clrTextBk); /** * @brief * This member function sets the text and background colors for * the specified row in the list control. * @param lpRowColor Pointer to a ROWCOLOR that contains the RGB row * color information. * @param bRedraw TRUE to invalidate the control. */ void SetRowColor(ROWCOLOR* lpRowColor, BOOL bRedraw = TRUE); /** * @brief * This member function sets the text and background colors for the * specified row in the list control. * @param bRedraw TRUE to invalidate control. * @param iRow Index of the row to set the colors for. * @param crText An RGB value representing the row text color. * @param crBack An RGB value representing the row background color. */ void SetRowColor(int iRow, COLORREF crText, COLORREF crBack, BOOL bRedraw = TRUE); /** * @brief * Call this member function to remove all user-defined row colors * from the list control. */ void RemoveRowColors(); /** * @brief * Call this member function to determine if the specified row * contains user-defined color attributes. * @param iRow Index of the row to check. * @return * A pointer to a ROWCOLOR structure if successful, otherwise NULL. */ virtual ROWCOLOR* Lookup(int iRow); /** * @brief * Call this member function to modify the extended style for the * list control. * @param dwRemove Specifies window styles to be removed during style * modification. * @param dwAdd Specifies window styles to be added during style * modification. * @return * TRUE if successful, otherwise FALSE. */ virtual BOOL ModifyExtendedStyle(DWORD dwRemove, DWORD dwAdd); /** * @brief * Call this member function to retrieve the RGB color value used * for the column background color. * @return * Returns an RGB value representing the column background color. */ COLORREF GetListBackColor() const; /** * @brief * Call this member function to set the RGB color value used for the * list background color. * @param crListBack An RGB value representing the list background color. */ void SetListBackColor(COLORREF crListBack); /** * @brief * Call this member function to retrieve the RGB color value used * for the column text color. * @return * Returns an RGB value representing the column text color. */ COLORREF GetListTextColor() const; /** * @brief * Call this member function to set the RGB color value used for the * list text color. * @param crListText An RGB value representing the list text color. */ void SetListTextColor(COLORREF crListText); /** * @brief * Call this member function to retrieve the RGB color value used * for the sorted column background color. * @return * Returns an RGB value representing the sorted column background color. */ COLORREF GetSortBackColor() const; /** * @brief * Call this member function to set the RGB color value used * for the sorted column background color. * @param crSortBack An RGB value representing the sorted column background color. */ void SetSortBackColor(COLORREF crSortBack); /** * @brief * Call this member function to retrieve the RGB color value used * for the sorted column text color. * @return * Returns an RGB value representing the sorted column text color. */ COLORREF GetSortTextColor() const; /** * @brief * Call this member function to set the RGB color value used * for the sorted column text color. * @param crSortText An RGB value representing the sorted column text color. */ void SetSortTextColor(COLORREF crSortText); /** * @brief * Call this member function to enable/disable sorted column colors. * @param bEnable true to enable sorted column colors, false to disable. */ void EnableUserSortColor(bool bEnable); /** * @brief * Call this member function to determine if sorted column colors * are enabled. * @return * true if sorted column colors are enabled, otherwise false. */ bool IsUserSortColor() const; /** * @brief * Call this member function to enable/disable user-defined colors. * @param bEnable true to enable user-defined colors, false to disable. */ void EnableUserListColor(bool bEnable); /** * @brief * Call this member function to determine if user-defined colors * are enabled. * @return * true if user-defined colors are enabled, otherwise false. */ bool IsUserListColor() const; /** * @brief * Call this member function to enable/disable user-defined row colors. * @param bEnable true to enable user-defined row colors, false to disable. */ void EnableUserRowColor(bool bEnable); /** * @brief * Call this member function to determine if user-defined row colors * are enabled. * @return * true if user-defined row colors are enabled, otherwise false. */ bool IsUserRowColor() const; /** * @brief * Call this member function to automatically set the font for * the list control when the control is initialized to use the * toolkit default font. This will also reset the font for the * header control as well. * @param bAutoFont true to enable auto font, otherwise false. */ void SetAutoFont(bool bAutoFont); protected: /** * @brief * This member function is called by the CXTPListBase 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 * Sets the list control pointer. * @param pListCtrl Pointer to the CListCtrl object to attach. * @details * This member function is called by the derived class to * set the list control pointer for this implementation. */ void ImplAttach(CListCtrl* pListCtrl); /** * @brief * Called from the derived class OnNotify method. * @param wParam Identifies the control that sends the message if the * message is from a control. Otherwise, wParam is 0. * @param lParam Pointer to a notification message (NMHDR) structure * that contains the notification code and additional * information. For some notification messages, this * parameter points to a larger structure that has the * NMHDR structure as its first member. * @param pResult Pointer to an LRESULT variable in which to store the * result code if the message is handled. * @details * The derived class calls this member function to process the message * map for a control notification. The derived class should call * this member function from the CWnd::OnNotify override. * @return * An application returns nonzero if it processes this message, otherwise 0. */ virtual BOOL OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult); /** * @brief * Updates colors and size values. * @details * This member function is called whenever there is a need to * refresh the colors and size values that are set using system * values. Usually called when the operating system color or * settings change. */ void RefreshMetrics(); protected: /** @cond */ //{{AFX_MSG afx_msg void OnCustomDraw(NMHDR* pNMHDR, LRESULT* pResult); afx_msg void OnDestroy(); afx_msg BOOL OnEraseBkgnd(CDC* pDC); afx_msg void OnPaint(); afx_msg LRESULT OnPrintClient(WPARAM wParam, LPARAM lParam); afx_msg void OnSettingChange(UINT uFlags, LPCTSTR lpszSection); //}}AFX_MSG /** @endcond */ protected: /** @cond */ // Needed in order to access protected functions. class CListCtrl_Friendly : public CListCtrl { friend class CXTPListBase; }; /** @endcond */ int m_nMinColWidth; /**< Minimum width for columns. */ int m_nMaxColWidth; /**< Maximum width for columns. */ int m_nSortedCol; /**< Index of the currently selected column. */ bool m_bAutoFont; /**< If true, then the font will automatically be set for the control. */ bool m_bAutoSave; /**< true if saving the column widths. */ bool m_bListColor; /**< true if user-defined colors are used for background and text. */ bool m_bRowColor; /**< true if rows are drawn with user-defined colors. */ bool m_bSortColor; /**< true if the sorted column is drawn in color. */ bool m_bAscending; /**< Flag to determine the sorting order. */ bool m_bNoColSizing; /**< If true, then column sizing is disabled. */ CString m_strSection; /**< Registry section name. */ CString m_strEntry; /**< Registry entry name. */ CString m_strDefault; /**< Registry default value. */ COLORREF m_crListText; /**< RGB value representing the row text color. */ COLORREF m_crListBack; /**< RGB value representing the row text background color. */ COLORREF m_crSortText; /**< RGB value for sort column text color. */ COLORREF m_crSortBack; /**< RGB value for sort column background color. */ CRowColorList m_arRowColor; /**< List of user-defined text and background row colors. */ CXTPHeaderCtrl m_wndHeader; /**< Subclassed flat header control. */ CListCtrl_Friendly* m_pListCtrl; /**< List control instance. */ }; /** @cond */ AFX_INLINE int CXTPListBase::GetMinimumColSize() { return m_nMinColWidth; } AFX_INLINE int CXTPListBase::GetMaximumColSize() { return m_nMaxColWidth; } AFX_INLINE void CXTPListBase::DisableColumnSizing(bool bDisable) { m_bNoColSizing = bDisable; } AFX_INLINE void CXTPListBase::SetListBackColor(COLORREF crListBack) { m_crListBack = crListBack; } AFX_INLINE void CXTPListBase::SetListTextColor(COLORREF crListText) { m_crListText = crListText; } AFX_INLINE void CXTPListBase::EnableUserListColor(bool bEnable) { m_bListColor = bEnable; } AFX_INLINE void CXTPListBase::SetSortBackColor(COLORREF crSortBack) { m_crSortBack = crSortBack; } AFX_INLINE void CXTPListBase::SetSortTextColor(COLORREF crSortText) { m_crSortText = crSortText; } AFX_INLINE void CXTPListBase::EnableUserSortColor(bool bEnable) { m_bSortColor = bEnable; } AFX_INLINE bool CXTPListBase::IsUserSortColor() const { return m_bSortColor; } AFX_INLINE bool CXTPListBase::IsUserListColor() const { return m_bListColor; } AFX_INLINE void CXTPListBase::EnableUserRowColor(bool bEnable) { m_bRowColor = bEnable; } AFX_INLINE bool CXTPListBase::IsUserRowColor() const { return m_bRowColor; } AFX_INLINE void CXTPListBase::SetAutoFont(bool bAutoFont) { m_bAutoFont = bAutoFont; } # define DECLARE_LIST_BASE(ClassName, List, Base) \ class _XTP_EXT_CLASS ClassName \ : public List \ , public Base \ { \ public: \ ClassName() \ { \ m_bPreSubclassInit = true; \ } \ virtual DWORD GetExtendedStyle() \ { \ return Base::GetExtendedStyle(); \ } \ virtual void SetExtendedStyle(DWORD dwExStyle) \ { \ Base::SetExtendedStyle(dwExStyle); \ } \ \ protected: \ virtual BOOL OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult) \ { \ return Base::OnNotify(wParam, lParam, pResult); \ } \ virtual bool Init() \ { \ return Base::Init(); \ } \ virtual void PreSubclassWindow() \ { \ List::PreSubclassWindow(); \ if (m_bPreSubclassInit) \ Init(); \ } \ virtual BOOL PreCreateWindow(CREATESTRUCT& cs) \ { \ if (!List::PreCreateWindow(cs)) \ return FALSE; \ m_bPreSubclassInit = false; \ return TRUE; \ } \ bool m_bPreSubclassInit; \ afx_msg void OnCustomDraw(NMHDR* pNMHDR, LRESULT* pResult) \ { \ Base::OnCustomDraw(pNMHDR, pResult); \ } \ afx_msg void OnSettingChange(UINT uFlags, LPCTSTR lpszSection) \ { \ List::OnSettingChange(uFlags, lpszSection); \ Base::OnSettingChange(uFlags, lpszSection); \ } \ afx_msg void OnDestroy() \ { \ Base::OnDestroy(); \ List::OnDestroy(); \ } \ afx_msg BOOL OnEraseBkgnd(CDC* pDC) \ { \ return Base::OnEraseBkgnd(pDC); \ } \ afx_msg void OnPaint() \ { \ Base::OnPaint(); \ } \ afx_msg LRESULT OnPrintClient(WPARAM wParam, LPARAM lParam) \ { \ return Base::OnPrintClient(wParam, lParam); \ } \ afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct) \ { \ if (List::OnCreate(lpCreateStruct) == -1) \ return -1; \ Init(); \ return 0; \ } \ }; # define ON_LISTCTRL_REFLECT \ ON_NOTIFY_REFLECT(NM_CUSTOMDRAW, OnCustomDraw) \ ON_WM_DESTROY() \ ON_WM_ERASEBKGND() \ ON_WM_PAINT() \ ON_MESSAGE(WM_PRINTCLIENT, OnPrintClient) \ ON_WM_CREATE() \ ON_WM_SETTINGCHANGE /** @endcond */ # include "Common/Base/Diagnostic/XTPEnableNoisyWarnings.h" /** @cond */ #endif // #if !defined(__XTPLISTBASE_H__) /** @endcond */