/** * @file XTPGridSection.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(__XTPGRIDSECTION_H__) # define __XTPGRIDSECTION_H__ /** @endcond */ # if _MSC_VER > 1000 # pragma once # endif // _MSC_VER > 1000 # include "Common/Base/Diagnostic/XTPDisableNoisyWarnings.h" class CXTPGridControl; class CXTPGridRecords; class CXTPGridRecord; class CXTPGridRows; class CXTPGridRow; class CXTPGridSelectedRows; class CXTPGridBorder; /** * @brief * Section height algorithm. */ enum XTPGridSectionHeightMode { xtpGridSectionHeightModeFixed, /**< Equal to 'px' in HTML.*/ xtpGridSectionHeightModeRelative, /**< Equal to '%' in HTML.*/ xtpGridSectionHeightModeAuto, /**< Equal to 'auto' in HTML.*/ xtpGridSectionHeightModeExpand, /**< Equal to '*' in HTML.*/ xtpGridSectionHeightModeAutoExpand, /**< Minimum auto size.*/ xtpGridSectionHeightModeAutoShrink, /**< Maximum auto size.*/ }; /** * @brief * Represents a grid section. */ class _XTP_EXT_CLASS CXTPGridSection : public CXTPCmdTarget { public: /** * @brief * Constructs a grid section. * @param pControl Pointer to the grid control. * @param rowType Row type identifier. */ CXTPGridSection(CXTPGridControl* pControl, XTPGridRowType rowType); /** * @brief * Destructs a grid section. */ virtual ~CXTPGridSection(); public: /** * @brief * Gets the border of this grid section. * @return * The border of this grid section. */ CXTPGridBorder* GetBorder() const; /** * @brief * Specifies if the user is allowed to move the selection to rows. * @param bAllowAccess TRUE to allow the user to move the selection to rows, * FALSE otherwise. * @see * IsAllowAccess */ void AllowAccess(BOOL bAllowAccess); /** * @brief * Determines if the user is allowed to move the selection to rows. * @return * TRUE if the user is allowed to move the selection to rows, * otherwise FALSE. * @see * AllowAccess. */ BOOL IsAllowAccess() const; /** * @brief * Specifies if the text in all CXTPGridRecordItem(s) can be edited. * @param bAllowEdit TRUE to allow the text in CXTPGridRecordItem(s) * to be edited, FALSE otherwise. * @details * If bAllowEdit is set to TRUE, then an edit box will be added that * allows for CXTPGridRecordItem(s) to be editable. * If bAllowEdit is set to FALSE, then the edit box that allows for * CXTPGridRecordItem(s) to be editable will be removed. * @see * IsAllowEdit, EditOnClick, IsEditOnClick */ void AllowEdit(BOOL bAllowEdit); /** * @brief * Determines if the text in all CXTPGridRecordItem(s) can be edited. * @return * TRUE if the text in all CXTPGridRecordItem(s) can be edited, * otherwise FALSE. * @see * AllowEdit, EditOnClick, IsEditOnClick */ BOOL IsAllowEdit() const; /** * @brief * Enables/disables row grouping. * @param bAllowGroup TRUE to enable row grouping, * FALSE to disable row grouping. * @see * IsAllowGroup */ void AllowGroup(BOOL bAllowGroup); /** * @brief * Determines if row grouping is enabled/disabled. * @return * TRUE if row grouping is enabled, otherwise FALSE. * @see * AllowGroup */ BOOL IsAllowGroup() const; /** * @brief * Enables/disables row sorting. * @param bAllowSort TRUE to enable row sorting, * FALSE to disable row sorting. * @see * IsAllowSort */ void AllowSort(BOOL bAllowSort); /** * @brief * Determines if row sorting is enabled/disabled. * @return * TRUE if row sorting is enabled, otherwise FALSE. * @see * AllowSort */ BOOL IsAllowSort() const; /** * @brief * Enables/disables row filtering. * @param bAllowFilter TRUE to enable row filtering, * FALSE to disable row filtering. * @see * IsAllowFilter */ void AllowFilter(BOOL bAllowFilter); /** * @brief * Determines if row filtering is enabled/disabled. * @return * TRUE if row filtering is enabled, otherwise FALSE. * @see * AllowFilter */ BOOL IsAllowFilter() const; /** * @brief * Enables/disables rows selection. * @param bEnable TRUE to enable rows selection, * FALSE to disable rows selection. * @see * IsSelectionEnabled */ void SelectionEnable(BOOL bEnable); /** * @brief * Determines if rows selection is enabled/disabled. * @return * TRUE if rows selection is enabled, otherwise FALSE. * @see * SelectionEnable */ BOOL IsSelectionEnabled() const; /** * @brief * Sets the visible state of the section. * @param bVisible A BOOL value to define visible state. * @see * IsVisible */ void SetVisible(BOOL bVisible = TRUE); /** * @brief * Gets the visible state of the section. * @return * TRUE if the section is visible, otherwise FALSE. * @see * SetVisible */ BOOL IsVisible() const; /** * @brief * Gets the current height mode. * @return * The current height mode; one of the values defined * by the XTPGridSectionHeightMode enumeration. * @see * SetHeightMode */ XTPGridSectionHeightMode GetHeightMode() const; /** * @brief * Sets the current height mode. * @param heightMode New height mode; must be one of the values defined * by the XTPGridSectionHeightMode enumeration. * @see * GetHeightMode */ void SetHeightMode(XTPGridSectionHeightMode heightMode); /** * @brief * Gets the suggested height. * @return * The suggested height. * @see * SetHeightMode */ int GetHeight() const; /** * @brief * Sets the suggested height. * @param nHeight New suggested height. * @see * GetHeight */ void SetHeight(int nHeight); /** * @brief * Gets the divider position for this section. * @return * The divider position for this section; one of the values defined * by the XTPGridSectionDividerPosition enumeration. * @see * SetDividerPosition */ XTPGridSectionDividerPosition GetDividerPosition() const; /** * @brief * Sets the divider position for this section. * @param dividerPosition New divider position; must be one of the values defined * by the XTPGridSectionDividerPosition enumeration. * @see * GetDividerPosition */ void SetDividerPosition(XTPGridSectionDividerPosition dividerPosition); /** * @brief * Gets the divider style for this section. * @return * The divider style for this section; one of the values defined * by the XTPGridSectionDividerStyle enumeration. * @see * SetDividerStyle */ XTPGridSectionDividerStyle GetDividerStyle() const; /** * @brief * Sets the divider style for this section. * @param dividerStyle New divider style; must be one of the values defined * by the XTPGridSectionDividerStyle enumeration. * @see * GetDividerStyle */ void SetDividerStyle(XTPGridSectionDividerStyle dividerStyle); /** * @brief * Gets the divider color for this section. * @return * The divider color for this section. * @see * SetDividerColor */ CXTPPaintManagerColor GetDividerColor() const; /** * @brief * Sets the divider color for this section. * @param clrDivider New divider color. * @see * GetDividerColor */ void SetDividerColor(CXTPPaintManagerColor clrDivider); /** * @brief * Gets the rectangle of this section. * @return * The rectangle of this section. */ CRect GetRect() const; /** * @brief * Gets the divider rectangle of this section. * @return * The divider rectangle of this section. */ CRect GetDividerRect() const; /** * @brief * Gets the collection of data records. * @return * A pointer to the collection of data records. * @details * Use this member function to retrieve access to the collection * of grid data records. You may then perform standard operations * on the collection (e.g. adding, removing, etc.). * @see * CXTPGridRecords overview, AddRecord */ CXTPGridRecords* GetRecords() const; /** * @brief * Gets the collection of grid rows. * @details * Use this member function to retrieve access to the collection * of grid rows, representing the current control view. * Note that the rows collection could be rebuilt automatically * by executing the Populate method. * @return * A pointer to the collection of grid rows. * * Example: * See example for the CXTPGridControl::BeginUpdate method. * @see * CXTPGridRows overview, Populate */ CXTPGridRows* GetRows() const; /** * @brief * Gets the type of the selected rows (i.e. body, header, or footer). * @return * The type of the selected rows (i.e. body, header, or footer); * one of the values defined by the XTPGridRowType enumeration. */ XTPGridRowType GetRowType() const; /** * @brief * Adds a record to the records collection. * @param pRecord Pointer to a record to be added. * @details * Call this member function if you want to add a record to the * Grid control's internal storage. * * Example: *
* // this function adds 2 empty records to a Grid control
* void Add2Empties(CXTPGridControl* pGridCtrl)
* {
* pGridCtrl->AddRecord(new CXTPGridRecord());
* pGridCtrl->AddRecord(new CXTPGridRecord());
* }
*
* @return
* Pointer to the recently added record object.
* @see
* CXTPGridRecord overview, GetRecords
*/
virtual CXTPGridRecord* AddRecord(CXTPGridRecord* pRecord);
virtual void AddRecordEx(CXTPGridRecord* pRecord, CXTPGridRecord* pParentRecord = NULL,
int nRowChildIndex = -1, int nRecordChildIndex = -1);
virtual void UpdateRecord(CXTPGridRecord* pRecord, BOOL bUpdateChildren);
virtual BOOL RemoveRecordEx(CXTPGridRecord* pRecord, BOOL bAdjustLayout = TRUE,
BOOL bRemoveFromParent = TRUE);
virtual BOOL RemoveRowEx(CXTPGridRow* pRow, BOOL bAdjustLayout);
/**
* @brief
* Deletes all rows and records from the section.
*/
virtual void ResetContent();
/**
* @brief
* Populates the section with rows.
* @param bUpdate TRUE to update the parent Grid control.
*/
virtual void Populate(BOOL bUpdate);
/**
* @brief
* Re-sorts the rows for this section.
*/
virtual void ReSortRows();
/**
* @brief
* Recalculates the indexes for all rows.
*/
virtual void RefreshIndexes();
/**
* @brief
* Recalculates the indexes for all rows.
* @param nIndexStart Specifies the zero-based index of the item before the first item
*/
virtual void RefreshIndexes(int nIndexStart);
/**
* @brief
* Expands all children of a specified row.
* @param nIndex Index to insert the expanded children at; used in recursion.
* @param pRow Pointer to a row to expand.
* @param bUpdateSelection TRUE to update the rows selection. This is used to prevent
* multiple invocation of CXTPGridSelectedRows::_OnExpanded
* in recursion through InsertRow.
* @return
* The number of expanded children.
*/
virtual int _DoExpand(int nIndex, CXTPGridRow* pRow, BOOL bUpdateSelection);
/**
* @brief
* Expands all children of a specified row.
* @param nIndex Index to insert the expanded children at; used in recursion.
* @param pRow Pointer to a row to expand.
* @return
* The number of expanded children.
*/
virtual int _DoExpand(int nIndex, CXTPGridRow* pRow);
/**
* @brief
* Collapses all children of the specified row.
* @param pRow Pointer to a row to collapse.
* @return The number of the collapsed rows.
*/
virtual int _DoCollapse(CXTPGridRow* pRow);
/**
* @brief
* Draws this section on a specified device context.
* @param pDC Pointer to a device context to draw this section on.
*/
virtual void Draw(CDC* pDC);
/**
* @brief
* Determines if virtual mode is enabled/disabled for this section.
* @return
* TRUE if virtual mode is enabled for this section,
* FALSE if virtual mode is disabled for this section.
*/
virtual BOOL IsVirtualMode() const;
virtual int InsertRow(int nIndex, CXTPGridRow* pRow);
virtual int GetPageRowCount(CDC* pDC) const;
virtual int GetTotalHeight(CDC* pDC) const;
virtual int GetRowsHeight(CDC* pDC) const;
virtual BOOL GetRowAt(CDC* pDC, int nWidth, int nOffset, int& nIndex, int& nTop);
virtual int GetRowOffset(CDC* pDC, int nWidth, int nIndex);
virtual BOOL EnsureVisible(CDC* pDC, CXTPGridRow* pRow);
/**
* @brief
* Sets the markup context.
* @param pMarkupContext Pointer to the markup context to be set.
*/
void SetMarkupContext(CXTPMarkupContext* pMarkupContext);
/**
* @brief
* Gets the number of records after using m_strFilterText.
* @return
* The number of records after using m_strFilterText.
*/
int GetPopulatedRecordsCount() const;
/**
* @brief
* Gets the index of this section.
* @return
* The index of this section.
*/
int GetIndex() const;
protected:
BOOL EnsureVisibleSmooth(CDC* pDC, CXTPGridRow* pRow);
int EnsureVisibleCalc(CDC* pDC, CXTPGridRow* pRow);
BOOL EnsureVisibleBlock(CDC* pDC, CXTPGridRow* pRow);
BOOL EnsureVisibleIcon(CDC* pDC, CXTPGridRow* pRow);
/**
* @brief
* Builds a rows tree based on the provided data record.
* @param pTree Pointer to the rows tree to add items into.
* @param pParentRow Pointer to the parent tree row.
* @param pRecords Pointer to the records collection to transfer to rows.
* @details
* This method recursively calls itself when building nested branches of rows.
*/
void BuildTree(CXTPGridRows* pTree, CXTPGridRow* pParentRow, CXTPGridRecords* pRecords);
/**
* @brief
* Sorts a rows tree collection according to the sort order for columns.
* @param pTree Rows tree collection to sort.
*/
virtual void SortTree(CXTPGridRows* pTree);
/**
* @brief
* Sorts a rows collection according to the sort order for columns.
* @param pRows Rows collection to sort.
*/
virtual void SortRows(CXTPGridRows* pRows);
/**
* @brief
* Gets the collection of selected rows.
* @details
* Use this member function to retrieve access to the collection
* of currently selected grid rows.
* @return
* A pointer to the collection of selected rows.
* @see
* CXTPGridSelectedRows overview.
*/
CXTPGridSelectedRows* GetSelectedRows() const;
/**
* @brief
* Gets the currently focused row in the Grid control's view.
* @return
* A pointer to the currently focused row if successful, otherwise NULL.
*/
CXTPGridRow* GetFocusedRow() const;
/**
* @brief
* Gets the current topmost row.
* @return
* The index of the current topmost row.
*/
virtual int GetScrollIndexV();
/**
* @brief
* Sets the current topmost row.
* @param nIndex Index of the row to be set as the current topmost row.
*/
virtual void SetScrollIndexV(int nIndex);
/**
* @brief
* Gets the vertical scroll offset.
* @return
* The vertical scroll offset.
*/
virtual int GetScrollOffsetV() const;
/**
* @brief
* Sets the vertical scroll offset.
* @param nScrollOffsetV Vertical scroll offset to be set.
*/
virtual void SetScrollOffsetV(int nScrollOffsetV);
XTPGridScrollMode GetScrollModeV() const;
XTPGridScrollMode GetScrollModeH() const;
/**
* @brief
* Collapses all rows.
* @details
* The CollapseAll method collapses all CXTPGridRow objects,
* including child rows, that are in the Grid control.
* @see
* ExpandAll, CXTPGridRow::SetExpanded
*/
void CollapseAll();
/**
* @brief
* Expands all rows.
* @param bRecursive TRUE to recursively expand all levels of child rows,
* FALSE to only expand one level of child rows.
* @details
* The ExpandAll method expands all CXTPGridRow objects,
* including child rows, that are in the Grid control.
* @see
* CollapseAll, CXTPGridRow::SetExpanded
*/
void ExpandAll(BOOL bRecursive);
protected:
void OnDeletedRefreshIndexes();
protected:
CXTPMarkupContext* m_pMarkupContext; /**< Markup context. */
CXTPGridBorder* m_pBorder; /**< Border. */
CXTPGridControl* m_pControl; /**< Parent control. */
CXTPGridRecords* m_pRecords; /**< Records container. */
CXTPGridRows* m_pRows; /**< Rows container. */
CXTPGridRows* m_pTree; /**< Tree rows container. */
int m_nPopulatedRecordsCount; /**< Number of records after using m_strFilterText. */
//////////////////////////////////////////////////////////////////////////
// Divider
//////////////////////////////////////////////////////////////////////////
CRect m_rcSection; /**< The area occupied by the section. */
CRect m_rcDivider; /**< Divider rectangle. */
CXTPPaintManagerColor m_clrDivider; /**< Divider color. */
XTPGridSectionDividerPosition m_dividerPosition; /**< Divider position. */
XTPGridSectionDividerStyle m_dividerStyle; /**< Divider style. */
XTPGridSectionHeightMode m_heightMode; /**< Height mode algorithm. */
int m_nHeight; /**< Suggested height (Fixed/Relative). */
BOOL m_bAllowAccess; /**< TRUE if rows can be selected. */
BOOL m_bAllowEdit; /**< TRUE if rows can be edited. */
BOOL m_bAllowGroup; /**< TRUE if rows can be grouped. */
BOOL m_bAllowSort; /**< TRUE if rows can be sorted. */
BOOL m_bAllowFilter; /**< TRUE if rows can be filtered. */
BOOL m_bSelectionEnable; /**< TRUE if selection enabled. */
BOOL m_bVisible; /**< TRUE if section is visible. */
//////////////////////////////////////////////////////////////////////////
// Scrolling
//////////////////////////////////////////////////////////////////////////
int m_nScrollIndexV; /**< Current top row in the visible area.
IMPORTANT: With smooth scrolling this member may
be -1 when the scrolling offset is changed and
the new top row index is not yet recalculated.
GetTopRowIndex() always returns the correct value. */
int m_nScrollOffsetV; /**< Vertical scroll offset. */
XTPGridRowType m_rowType;
CUIntArray m_UaSorted; /**< Sorted array. */
private:
# ifdef _XTP_ACTIVEX
DECLARE_OLETYPELIB_EX(CXTPGridSection);
DECLARE_DISPATCH_MAP()
DECLARE_INTERFACE_MAP()
# endif // _XTP_ACTIVEX
/** @cond */
friend class CXTPGridControl;
friend class CXTPGridSections;
friend class CXTPGridGroupRow;
/** @endcond */
};
AFX_INLINE void CXTPGridSection::AllowAccess(BOOL bAllowAccess)
{
m_bAllowAccess = bAllowAccess;
}
AFX_INLINE BOOL CXTPGridSection::IsAllowAccess() const
{
return m_bAllowAccess;
}
AFX_INLINE void CXTPGridSection::AllowEdit(BOOL bAllowEdit)
{
m_bAllowEdit = bAllowEdit;
}
AFX_INLINE BOOL CXTPGridSection::IsAllowEdit() const
{
return m_bAllowEdit;
}
AFX_INLINE void CXTPGridSection::AllowGroup(BOOL bAllowGroup)
{
m_bAllowGroup = bAllowGroup;
}
AFX_INLINE BOOL CXTPGridSection::IsAllowGroup() const
{
return m_bAllowGroup;
}
AFX_INLINE void CXTPGridSection::AllowSort(BOOL bAllowSort)
{
m_bAllowSort = bAllowSort;
}
AFX_INLINE BOOL CXTPGridSection::IsAllowSort() const
{
return m_bAllowSort;
}
AFX_INLINE void CXTPGridSection::AllowFilter(BOOL bAllowFilter)
{
m_bAllowFilter = bAllowFilter;
}
AFX_INLINE BOOL CXTPGridSection::IsAllowFilter() const
{
return m_bAllowFilter;
}
AFX_INLINE void CXTPGridSection::SelectionEnable(BOOL bEnable)
{
m_bSelectionEnable = bEnable;
}
AFX_INLINE BOOL CXTPGridSection::IsSelectionEnabled() const
{
return m_bSelectionEnable;
}
AFX_INLINE void CXTPGridSection::SetVisible(BOOL bVisible)
{
m_bVisible = bVisible;
}
AFX_INLINE BOOL CXTPGridSection::IsVisible() const
{
return m_bVisible;
}
AFX_INLINE CXTPGridRecords* CXTPGridSection::GetRecords() const
{
return m_pRecords;
}
AFX_INLINE CXTPGridRows* CXTPGridSection::GetRows() const
{
return m_pRows;
}
AFX_INLINE XTPGridSectionHeightMode CXTPGridSection::GetHeightMode() const
{
return m_heightMode;
}
AFX_INLINE void CXTPGridSection::SetHeightMode(XTPGridSectionHeightMode heightMode)
{
m_heightMode = heightMode;
}
AFX_INLINE int CXTPGridSection::GetHeight() const
{
return m_nHeight;
}
AFX_INLINE void CXTPGridSection::SetHeight(int nHeight)
{
m_nHeight = nHeight;
}
AFX_INLINE XTPGridSectionDividerPosition CXTPGridSection::GetDividerPosition() const
{
return m_dividerPosition;
}
AFX_INLINE void CXTPGridSection::SetDividerPosition(XTPGridSectionDividerPosition dividerPosition)
{
m_dividerPosition = dividerPosition;
}
AFX_INLINE XTPGridSectionDividerStyle CXTPGridSection::GetDividerStyle() const
{
return m_dividerStyle;
}
AFX_INLINE void CXTPGridSection::SetDividerStyle(XTPGridSectionDividerStyle dividerStyle)
{
m_dividerStyle = dividerStyle;
}
AFX_INLINE CXTPPaintManagerColor CXTPGridSection::GetDividerColor() const
{
return m_clrDivider;
}
AFX_INLINE void CXTPGridSection::SetDividerColor(CXTPPaintManagerColor clrDivider)
{
m_clrDivider = clrDivider;
}
AFX_INLINE CRect CXTPGridSection::GetRect() const
{
return m_rcSection;
}
AFX_INLINE CRect CXTPGridSection::GetDividerRect() const
{
return m_rcDivider;
}
AFX_INLINE int CXTPGridSection::GetPopulatedRecordsCount() const
{
return m_nPopulatedRecordsCount;
}
AFX_INLINE XTPGridScrollMode CXTPGridSection::GetScrollModeH() const
{
XTPGridScrollMode scrollMode = xtpGridScrollModeNone;
if (NULL != m_pControl)
{
scrollMode = m_pControl->GetScrollMode(xtpGridOrientationHorizontal);
}
return scrollMode;
}
AFX_INLINE XTPGridScrollMode CXTPGridSection::GetScrollModeV() const
{
XTPGridScrollMode scrollMode = xtpGridScrollModeNone;
if (NULL != m_pControl)
{
scrollMode = m_pControl->GetScrollMode(xtpGridOrientationVertical);
}
return scrollMode;
}
/** @cond */
# include "Common/Base/Diagnostic/XTPEnableNoisyWarnings.h"
#endif //#if !defined(__XTPGRIDSECTION_H__)
/** @endcond */