/** * @file XTPTreeBase.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(__XTTREEBASE_H__) # define __XTTREEBASE_H__ /** @endcond */ # if _MSC_VER > 1000 # pragma once # endif // _MSC_VER > 1000 # include "Common/Base/Diagnostic/XTPDisableNoisyWarnings.h" class CXTPTreeTheme; class CXTPWinThemeWrapper; /** * @brief * CXTPTreeBase is a CTreeView derived class. It extends the CTreeView * class to add additional functionality, including tree traversal, * searching, color, and settings. */ class _XTP_EXT_CLASS CXTPTreeBase { protected: /** * @brief * CLRFONT structure is used to by the CXTPShellTreeCtrl and * CXTPShellTreeView classes to maintain font information for a * particular tree item. * @see * CXTPShellTreeCtrl, CXTPShellTreeView */ struct CLRFONT { /** * @brief * Constructs a CLRFONT struct and initializes member data. */ CLRFONT(); LOGFONT logfont; /**< A LOGFONT object that represents the tree item font. */ COLORREF color; /**< An RGB value that represents the text color for a tree item. */ COLORREF colorBack; /**< An RGB value that represents the background color for a tree item. */ }; /** * @brief * Map for maintaining HTREEITEM to CLRFONT structure relationships. * @details * CMap definition used by the CXTPTreeBase class to maintain * a list of HTREEITEM to CLRFONT structure relationships representing * a tree item that has user defined color information. * @see * CXTPTreeBase, CLRFONT */ typedef CMap CColorFontMap; protected: /** * @brief * Protected constructor used by dynamic creation. Constructs a * CXTPTreeBase object. */ CXTPTreeBase(); /** * @brief * Destroys a CXTPTreeBase object, handles cleanup and deallocation. */ virtual ~CXTPTreeBase(); public: /** * @brief * This member function will retrieve the tree view item that has the * specified relationship, indicated by the 'nCode' parameter, to 'hItem'. * @param hItem Handle of a tree item. * @return * The handle of the next item if successful, otherwise NULL. */ virtual HTREEITEM GetNextItem(HTREEITEM hItem) const; /** * @brief * This member function will retrieve the tree view item that has the * specified relationship, indicated by the 'nCode' parameter, to 'hItem'. * @param hItem Handle of a tree item. * @param nCode A flag indicating the type of relation to 'hItem'. This flag can be * one of the values listed in the Details section. * @details * nCode can be one of the following values: * TVGN_CARET: Retrieves the currently selected item. * TVGN_CHILD: Retrieves the first child item. The 'hItem' * parameter must be NULL. * TVGN_DROPHIGHLIGHT: Retrieves the item that is the target of a * drag-and-drop operation. * TVGN_FIRSTVISIBLE: Retrieves the first visible item. * TVGN_NEXT: Retrieves the next sibling item. * TVGN_NEXTVISIBLE: Retrieves the next visible item that follows * the specified item. * TVGN_PARENT: Retrieves the parent of the specified item. * TVGN_PREVIOUS: Retrieves the previous sibling item. * TVGN_PREVIOUSVISIBLE: Retrieves the first visible item that precedes * the specified item. * TVGN_ROOT: Retrieves the first child item of the root * item of which the specified item is a part. * The non-nCode version gets the next item as if the outline was completely * expanded. * @return * The handle of the next item if successful, otherwise NULL. */ virtual HTREEITEM GetNextItem(HTREEITEM hItem, UINT nCode) const; /** * @brief * This member function gets the previous item as if the outline was * completely expanded. * @param hItem Handle of the reference item. * @return * The handle of the item immediately above the reference item. */ virtual HTREEITEM GetPrevItem(HTREEITEM hItem) const; /** * @brief * This member function retrieves the last item in the branch. * @param hItem Node identifying the branch. NULL will return the last item * in the outline. * @return * The handle of the last item. */ virtual HTREEITEM GetLastItem(HTREEITEM hItem) const; /** * @brief * This member function searches the entire tree for an item label * that contains the search string. * @param lpszSearch String to search for. * @param bCaseSensitive TRUE if the search should be case sensitive. * @param bDownDir TRUE for down. * @param bWholeWord TRUE if the search should match whole words. * @param hItem Handle of the tree item to start searching from, * NULL to use the currently selected tree item. * @return * The handle to the item if successful, otherwise NULL. * @see * IsFindValid */ virtual HTREEITEM FindItem(LPCTSTR lpszSearch, BOOL bCaseSensitive = FALSE, BOOL bDownDir = TRUE, BOOL bWholeWord = FALSE, HTREEITEM hItem = NULL); /** * @brief * This member function searches the entire tree for an item label * that contains exactly the same text as search string. * @param lpszSearch String to search for. * @param bCaseSensitive TRUE if the search should be case sensitive. * @param bDownDir TRUE for down. * @param hItem Handle of the tree item to start searching from, * NULL to use the currently selected tree item. * @return * The handle to the item if successful, otherwise NULL. * @see * IsFindValid */ virtual HTREEITEM FindItemExact(LPCTSTR lpszSearch, BOOL bCaseSensitive = FALSE, BOOL bDownDir = TRUE, HTREEITEM hItem = NULL); /** * @brief * This member function searches the entire branch specified by 'htiItem' * for an item label that contains the search string. * @param lpszSearch String to search for. * @param bCaseSensitive TRUE if the search should be case sensitive. * @param bWholeWord TRUE if the search should match whole words. * @param htiItem Handle of the tree item to start searching from, * NULL to use the currently selected tree item. * @return * The handle to the item if successful, otherwise NULL. * @see * IsFindValid */ virtual HTREEITEM FindItemInBranch(LPCTSTR lpszSearch, BOOL bCaseSensitive /*= FALSE*/, BOOL bWholeWord /*= FALSE*/, HTREEITEM htiItem /*= NULL*/); /** * @brief * This member function sets the font for the reference tree item. * @param hItem Handle of the reference item. * @param logfont New font for the tree item. */ virtual void SetItemFont(HTREEITEM hItem, LOGFONT& logfont); /** * @brief * This member function retrieves the current LOGFONT font used by * the tree item. * @param hItem Handle of the reference item. * @param plogfont Pointer to receive LOGFONT information. * @return * TRUE if successful, otherwise FALSE. */ virtual BOOL GetItemFont(HTREEITEM hItem, LOGFONT* plogfont); /** * @brief * This member function sets the reference tree item font to bold. * @param hItem Handle of the reference item. * @param bBold TRUE for bold font. */ virtual void SetItemBold(HTREEITEM hItem, BOOL bBold = TRUE); /** * @brief * This member function checks whether or not a tree item has a bold font. * @param hItem Handle of the reference item. * @return * TRUE if the tree item has a bold font, otherwise FALSE. */ virtual BOOL GetItemBold(HTREEITEM hItem); /** * @brief * This member function sets the tree item text color. * @param hItem Handle of the reference item. * @param color An RGB value for the tree item's text. */ virtual void SetItemColor(HTREEITEM hItem, COLORREF color); /** * @brief * This member function sets the tree item background color. * @param hItem Handle of the reference item. * @param color An RGB value for the tree item's text. */ virtual void SetItemBackColor(HTREEITEM hItem, COLORREF color); /** * @brief * This member function returns the RGB value for the specified * tree item text color, or (COLORREF)-1 if the color was not set. * @param hItem Handle of the reference item. * @return * The RGB value for the specified tree item text color, * or (COLORREF)-1 if the color was not set. */ virtual COLORREF GetItemColor(HTREEITEM hItem); /** * @brief * This member function returns the RGB value for the specified * tree item background color, or (COLORREF)-1 if the color was not set. * @param hItem Handle of the reference item. * @return * The RGB value for the specified tree item background color, * or (COLORREF)-1 if the color was not set. */ virtual COLORREF GetItemBackColor(HTREEITEM hItem); /** * @brief * This member function enables/disables multi-selection for the * tree control. * @param bMultiSelect TRUE to enable multi-selection, FALSE to disable. * @return * TRUE if successful, otherwise FALSE. */ virtual BOOL EnableMultiSelect(BOOL bMultiSelect = TRUE); /** * @brief * This member function retrieves the previously selected tree item in * a multi-selection tree control. * @param hItem Handle of the reference item. * @return * A handle to the previously selected tree item. */ virtual HTREEITEM GetPrevSelectedItem(HTREEITEM hItem) const; /** * @brief * This member function retrieves the next selected item in * a multi-selection tree control. * @param hItem Handle of the reference item. * @return * A handle to the next selected tree item. */ virtual HTREEITEM GetNextSelectedItem(HTREEITEM hItem) const; /** * @brief * This member function retrieves the first selected item in * a multi-selection tree control. * @return * A handle to the first selected tree item. */ virtual HTREEITEM GetFirstSelectedItem() const; /** * @brief * This member function retrieves the number of tree items that are selected. * @return * A UINT value that represents the number of tree items selected. */ virtual UINT GetSelectedCount() const; /** * @brief * This member function is a replacement for the base class function * of the same name, to handle TVIS_FOCUSED in a multi-selection * tree control. It sets the state of the item specified by hItem. * @param hItem Handle of the item whose state is to be set. * @param nState Specifies the new states for the item. * @param nStateMask Specifies which states are to be changed. * @return * Nonzero if successful, otherwise zero. * @details * When set, the TVIS_FOCUSED state flag will draw a focus rectangle * around the tree item that currently has input focus. * Only one tree item can have focus at any given time. For a list of * possible item state flags, see Tree-View Control Item States in * the MSDN documentation. */ BOOL SetItemState(HTREEITEM hItem, UINT nState, UINT nStateMask); /** * @brief * This member function is a replacement for the base class function * of the same name, to handle TVIS_FOCUSED in a multi-selection * tree control. * @param hItem Handle of the item whose state is to be retrieved. * @param nStateMask Mask indicating which states are to be retrieved. For * more information on possible values for 'nStateMask', * see the discussion of the 'state' and 'stateMask' * members of the TVITEM structure in the Platform SDK. * @return * The state of the item specified by 'hItem'. */ UINT GetItemState(HTREEITEM hItem, UINT nStateMask) const; /** * @brief * This member function is a replacement for the base class function * of the same name, to handle TVIS_FOCUSED in a multi-select * tree control. Call this function to select the given tree view item. * If 'hItem' is NULL, then no items are selected. * @param hItem Handle of a tree item. * @return * Nonzero if successful, otherwise zero. */ BOOL SelectItem(HTREEITEM hItem); /** * @brief * This member function retrieves the handle to the tree item that * currently has focus. * @return * The handle of the item that has focus, otherwise NULL. */ HTREEITEM GetFocusedItem() const; /** * @brief * This member function will set the focus for the tree item specified * by 'hItem'. * @param hItem Handle of a tree item. * @return * TRUE if successful, otherwise FALSE. */ BOOL FocusItem(HTREEITEM hItem); /** * @brief * Call this member function to clear, or select, all of the visible items * in the tree control. This will not affect the focus of the tree items. * @param bSelect TRUE to select all the items, or FALSE to clear the selection. * @param htItem Tree item to start selection from. If NULL, then selection * will begin at the root. */ virtual void SelectAll(BOOL bSelect = TRUE, HTREEITEM htItem = NULL); /** * @brief * This member function selects items from 'hItemFrom' to 'hItemTo' in * a multi-selection tree control. It does not select a child item if * the parent is collapsed. It will remove the selection from all other * items if 'bOnly' is set to TRUE. * @param hItemFrom Handle of the item to start selecting from. * @param hItemTo Handle of the item to end selection at. * @param bOnly TRUE to only select the specified range, or FALSE to keep * existing selections. */ virtual void SelectItems(HTREEITEM hItemFrom, HTREEITEM hItemTo, BOOL bOnly = TRUE); /** * @brief * This member function checks whether or not the specified item is selected. * @param hItem Handle of a tree item. * @return * TRUE if the specified item is selected, otherwise FALSE. */ virtual BOOL IsSelected(HTREEITEM hItem) const; /** * @brief * This member function will cause all of the children of the specified * tree item to be selected or deselected. * @param hParent Handle of tree item to begin selection from. * @param bSelect TRUE to select only the child items, or FALSE to keep * existing selections. * @param bRecurse TRUE to recurse all siblings, or FALSE to select only * children of the parent item. * @return * TRUE if focus was on a child item, otherwise FALSE. */ BOOL SelectChildren(HTREEITEM hParent, BOOL bSelect = TRUE, BOOL bRecurse = TRUE); /** * @brief * This member function will retrieve a reference to the typed pointer * array that contains the items selected in the tree control. * @param list Reference to a CTypedPtrList object. */ void GetSelectedList(CTypedPtrList& list) const; /** * @brief * This member function checks to see if the tree control is a * multi-selection tree. * @return * TRUE if the tree control is a multi-selection tree, otherwise FALSE. */ BOOL IsMultiSelect() const; /** * @brief * This member function checks to see if the tree control has Explorer * theme applied. * @return * TRUE if the tree control has Explorer theme applied (Vista+). */ BOOL IsExplorerTheme() const; /** * @brief * This member function sets the Explorer theme applied (Vista+). * @param bSet TRUE to set Explorer theme */ void SetExplorerTheme(BOOL bSet); /** * @brief * This member function sets the banding mode for a multi-selection tree * control. If 'bLabel' is TRUE, then items are selected only when the * banding rect passes over the tree item label. If FALSE, then passing * over any part of the tree item will cause selection to be made when * the banding rect passes over it. * @param bLabel TRUE to select items only when the banding rect passes over * the text label, FALSE to select items when banding rect * passes over any part of the tree item. * @return * The previous banding state. */ BOOL SetBandingHit(BOOL bLabel); /** * @brief * This member function checks if the tree control uses default * (system specific) item drawing method. * @return * TRUE if the tree control uses default item drawing method, * FALSE if items are drawn by the framework. */ BOOL IsDefaultItemDrawingEnabled() const; /** * @brief * Enables/disables default item drawing method. By default, * items are drawn by the framework, which means default item * drawing is set to TRUE. * @param bEnable TRUE to enable default item drawing method. */ void EnableDefaultItemDrawing(BOOL bEnable = TRUE); /** * @brief * Sets the indent between the icon/text/expander. * @param iconIndent The indent to be set between the icon/text/expander. * @return * The previous indent between the icon/text/expander. */ int SetIconIndent(int iconIndent); /** * @brief * Gets the current indent between the icon/text/expander. * @return * The current indent between the icon/text/expander. */ int GetIconIndent() const; protected: /** * @brief * This member function is called by the CXTPTreeBase 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 * Sends a WM_NOTIFY message to the tree control owner window. * @param pNMHDR Pointer to an 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. * @details * Called by the tree control to package and send a WM_NOTIFY message * to the tree control's owner window. You can override this member * to provide additional functionality. * @return * The return value is ignored except for notification messages that * specify otherwise. */ virtual LRESULT SendNotify(LPNMHDR pNMHDR); /** * @brief * Toggles selection for all items in a multi-selection tree control. * @param bSelect TRUE to select, FALSE to remove selection. * @param hIgnore Handle to a tree item to skip while performing the operation. * @details * Called to toggle selection for all items in a multi-selection * tree control. You can override this member to provide additional * functionality. */ virtual void SelectAllIgnore(BOOL bSelect, HTREEITEM hIgnore); /** * @brief * Called when a mouse button click event occurs. * @param bLeft TRUE if the left mouse button is down. * @param nFlags Indicates whether various virtual keys are down. See Remarks * section for a list of values. * @param point XY cursor location. * @details * nFlags can be any combination of the following values:

* MK_CONTROL: Set if the CTRL key is down. * MK_LBUTTON: Set if the left mouse button is down. * MK_MBUTTON: Set if the middle mouse button is down. * MK_RBUTTON: Set if the right mouse button is down. * MK_SHIFT: Set if the SHIFT key is down. * @return * TRUE if successful, otherwise FALSE. */ virtual BOOL OnButtonDown(BOOL bLeft, UINT nFlags, CPoint point); /** * @brief * Called during item selection in a multi-selection tree control. * @param hItem Handle to the last item clicked that will receive focus. * @param bLeft TRUE if the left mouse button is down. * @param nFlags Indicates whether various virtual keys are down. See Remarks * section for a list of values. * @details * nFlags can be any combination of the following values:

* MK_CONTROL: Set if the CTRL key is down. * MK_LBUTTON: Set if the left mouse button is down. * MK_MBUTTON: Set if the middle mouse button is down. * MK_RBUTTON: Set if the right mouse button is down. * MK_SHIFT: Set if the SHIFT key is down. */ virtual void DoPreSelection(HTREEITEM hItem, BOOL bLeft, UINT nFlags); /** * @brief * Called during item selection in a multi-selection tree control. * @param hItem Handle to the last item clicked that will receive focus. * @param bLeft TRUE if the left mouse button is down. * @param nFlags Indicates whether various virtual keys are down. See Remarks * section for a list of values. * @param point Mouse cursor position. * @details * nFlags can be any combination of the following values:

* MK_CONTROL: Set if the CTRL key is down. * MK_LBUTTON: Set if the left mouse button is down. * MK_MBUTTON: Set if the middle mouse button is down. * MK_RBUTTON: Set if the right mouse button is down. * MK_SHIFT: Set if the SHIFT key is down. */ virtual void DoAction(HTREEITEM hItem, BOOL bLeft, UINT nFlags, CPoint point); /** * @brief * Draws a selection rectangle during item selection. * @param point XY location of the mouse cursor. * @param nFlags Indicates whether various virtual keys are down. See Remarks * section for a list of values. * @details * nFlags can be any combination of the following values:

* MK_CONTROL: Set if the CTRL key is down. * MK_LBUTTON: Set if the left mouse button is down. * MK_MBUTTON: Set if the middle mouse button is down. * MK_RBUTTON: Set if the right mouse button is down. * MK_SHIFT: Set if the SHIFT key is down. */ virtual void DoBanding(UINT nFlags, CPoint point); /** * @brief * Updates tree item selection. * @param pRect Cursor drag rectangle representing tree items to select. * @param nFlags Indicates whether various virtual keys are down. See Remarks * section for a list of values. * @param list An array of tree items that are currently selected. * @details * Called by the tree control to select tree items based upon the area * specified by pRect. * nFlags can be any combination of the following values:

* MK_CONTROL: Set if the CTRL key is down. * MK_LBUTTON: Set if the left mouse button is down. * MK_MBUTTON: Set if the middle mouse button is down. * MK_RBUTTON: Set if the right mouse button is down. * MK_SHIFT: Set if the SHIFT key is down. */ virtual void UpdateSelectionForRect(LPCRECT pRect, UINT nFlags, CTypedPtrList& list); /** * @brief * Member override to determine if a tree item is valid. * @param hti Handle to the tree item that was found when FindItem or * FindItemInBranch has been called. * @details * Override this member function to determine if the tree item * specified by hti is valid. If IsFindValid returns * FALSE, then the calling functions FindItem and FindItemInBranch * will return NULL. * @return * TRUE in the base class. Derived classes must return TRUE to * indicate success or FALSE to indicate failure. */ virtual BOOL IsFindValid(HTREEITEM hti); /** * @brief * Called to render the tree control. * @param dc Reference to the tree control device context. * @param bInternal FALSE to skip extended rendering tasks and to * use the tree control's default rendering. * @details * This member is called to render the tree control using user defined * fonts and colors. You can override this member to provide additional * functionality. */ virtual void DoPaint(CDC& dc, BOOL bInternal = TRUE); /** * @brief * Retrieves the tree control's background color. * @return * An RGB value representing the tree control's background color. * @see * CTreeCtrl::SetBkColor, CTreeCtrl::GetBkColor, GetTreeTextColor, * GetItemBackColor, GetItemTextColor */ virtual COLORREF GetTreeBackColor() const; /** * @brief * Retrieves the tree control's text color. * @return * An RGB value representing the tree control's text color. * @see * CTreeCtrl::SetTextColor, CTreeCtrl::GetTextColor, GetTreeBackColor, * GetItemBackColor, GetItemTextColor */ virtual COLORREF GetTreeTextColor() const; /** * @brief * Computes an item icon rectangle. * @param hItem Item handle for which an icon rectangle must be computed. * @return * Item icon rectangle, or an empty rectangle if the item provided * has no icon. */ virtual CRect GetItemIconRect(HTREEITEM hItem) const; /** * @brief * Computes an item state icon rectangle. * @param hItem Item handle for which the state icon rectangle must be computed. * @param rcIcon Reference to a CRect object representing the size of the icon. * @return * Item state icon rectangle, or an empty rectangle if the item provided * has no state icon. */ virtual CRect GetItemStateIconRect(HTREEITEM hItem, const CRect& rcIcon) const; /** * @brief * Computes an item expander rectangle. * @param hItem Item handle for which an expander rectangle must be computed. * @param pDC Points to a valid device context. * @param rcIcon Reference to a CRect object representing the size of the icon. * @param rcStateIcon Reference to a CRect object representing the size of the state icon. * @return * Item expander rectangle, or an empty rectangle if the item provided * has no expander. */ virtual CRect GetItemExpanderRect(HTREEITEM hItem, CDC* pDC, const CRect& rcIcon, const CRect& rcStateIcon) const; /** * @brief * Custom drawing of an item along with its icon and lines if necessary. * @param pDC Points to a valid device context. * @param hItem Item handle for which an expander rectangle must be computed. * @param crBack An RGB value representing the background color. */ void DrawItem(CDC* pDC, HTREEITEM hItem, const COLORREF crBack); /** @cond */ _XTP_DEPRECATED_IN_FAVOR_("DrawItem(CDC *pDC, HTREEITEM hItem, const COLORREF crBack)") void DrawItem(CDC* pDC, HTREEITEM hItem); /** @endcond */ /** * @brief * Draws expander with explorer style when using a dark theme. * @param pDC Pointer to the current device context. * @param crBack Item back color. * @param rcItem Item rectangle. * @param rcExpander Expander rectangle. * @param nPart Part number to draw. * @param nState State number (of the part) to draw. */ void DrawDarkThemeExpander(CDC* pDC, COLORREF crBack, CRect rcItem, CRect rcExpander, int nPart, int nState) const; /** * @brief * Retrieves a tree item's background color. * @param uState Mask indicating which states are to be retrieved. For * more information on possible values for nStateMask, see * the discussion of the state and stateMask members of * the TVITEM structure in the Platform SDK. * @param bTreeHasFocus true if the tree item has input focus. * @param dwStyle Set of flags specifying the tree item's state. * @param crBack Default color to be returned; usually the tree control's * background color. * @details * This member function is called to retrieve a tree item's background * color. The value retrieved will depend on the tree item's state and * TVS_ style. * @return * An RGB value representing the specified item's background color. * @see * GetTreeBackColor, GetTreeTextColor, GetItemTextColor */ virtual COLORREF GetItemBackColor(UINT uState, bool bTreeHasFocus, DWORD dwStyle, COLORREF crBack) const; /** * @brief * Retrieves a tree item's text color. * @param uState Mask indicating which states are to be retrieved. For * more information on possible values for nStateMask, see * the discussion of the state and stateMask members of * the TVITEM structure in the Platform SDK. * @param bTreeHasFocus true if the tree item has input focus. * @param dwStyle Set of flags specifying the tree item's state. * @param crText Default color to be returned; usually the tree control's * text color. * @details * This member function is called to retrieve a tree item's text * color. The value retrieved will depend on the tree item's state and * TVS_ style. * @return * An RGB value representing the specified item's text color. * @see * GetTreeBackColor, GetTreeTextColor, GetItemBackColor */ virtual COLORREF GetItemTextColor(UINT uState, bool bTreeHasFocus, DWORD dwStyle, COLORREF crText) const; /** * @brief * Determines if the tree control has edit labels. * @return * true if the TVS_EDITLABELS style is set for the tree control, otherwise false. */ bool HasEditLabels() const; /** * @brief * This member function searches the entire tree for an item label * that contains the search string. * @param lpszSearch String to search for. * @param bCaseSensitive TRUE if the search should be case sensitive. * @param bDownDir TRUE for down. * @param bWholeWord TRUE if the search should match whole words. * @param hItem Handle of the tree item to start searching from, * NULL to use the currently selected tree item. * @param bExactlySameStr TRUE if the item label and input search string should * have exactly the same text. If this parameter is TRUE, * then the value of bWholeWord is not taken into account. * @return * The handle to the item if successful, otherwise NULL. * @see * IsFindValid */ virtual HTREEITEM FindItemImpl(LPCTSTR lpszSearch, BOOL bCaseSensitive = FALSE, BOOL bDownDir = TRUE, BOOL bWholeWord = FALSE, HTREEITEM hItem = NULL, BOOL bExactlySameStr = FALSE); /** * @brief * Checks if full row selection is enabled. * @return * TRUE if full row selection is enabled. */ virtual BOOL IsFullRowSelectionEnabled(); /** * @brief * Sets the insertion mark in a tree view control. * @param hItem specifies at which item the insertion mark will be placed. If this argument is * NULL, the insertion mark is removed. * @param fAfter specifies if the insertion mark is placed before or after the specified item. * @return * TRUE value that specifies if the insertion mark is placed before or after the specified * item. */ BOOL SetInsertMark(HTREEITEM hItem, BOOL fAfter); /** * @brief * Retrieves the color used to draw the insertion mark for the tree view. * @return * Value that contains the current insertion mark color. */ COLORREF GetInsertMarkColor() const; /** * @brief * Sets the color used to draw the insertion mark for the tree view. * @param clrNew value that contains the new insertion mark color. * @return * Value that contains the current insertion mark color. */ COLORREF SetInsertMarkColor(COLORREF clrNew); public: void SetTheme(int nTheme); /* XTPControlTheme */ void RefreshMetrics(); CTreeCtrl* GetSelfTreeCtrl() const; int GetTheme() const; protected: /** @cond */ //{{AFX_VIRTUAL(CXTPTreeBase) virtual BOOL PreTranslateMessage(MSG* pMsg); virtual BOOL OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult); //}}AFX_VIRTUAL //{{AFX_MSG(CXTPTreeBase) afx_msg void OnLButtonDown(UINT nFlags, CPoint point); afx_msg void OnSetFocus(CWnd* pOldWnd); afx_msg void OnKillFocus(CWnd* pNewWnd); afx_msg void OnRButtonDown(UINT nFlags, CPoint point); afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags); afx_msg void OnSize(UINT nType, int cx, int cy); afx_msg BOOL OnDeleteItem(NMHDR* pNMHDR, LRESULT* pResult); afx_msg BOOL OnItemExpanding(NMHDR* pNMHDR, LRESULT* pResult); afx_msg BOOL OnBeginLabelEdit(NMHDR* pNMHDR, LRESULT* pResult); afx_msg BOOL OnEndLabelEdit(NMHDR* pNMHDR, LRESULT* pResult); afx_msg void OnMouseMove(UINT nFlags, CPoint point); afx_msg void OnTimer(UINT_PTR nIDEvent); afx_msg void OnNcMouseMove(UINT nHitTest, CPoint point); afx_msg LRESULT OnSetTheme(WPARAM wParam, LPARAM lParam); //}}AFX_MSG private: void DrawDottedLine(CDC* pDC, const CPoint& ptStart, const CPoint& ptEnd); /** * @brief * Retrieves the first visible item which has the first symbol. * @param nChar Specifies the virtual key code of the given key. * @param nFlags Specifies the scan code. * @details * This member function is called to retrieve the first visible item which * has the first symbol (such as nChar code). * @return * HTREEITEM value or NULL if not found. * @see * CWnd::OnKeyDown */ HTREEITEM FindVisibleItem(UINT nChar, UINT nFlags); /** @endcond */ protected: /** @cond */ // Needed in order to access protected functions. class CTreeCtrl_Friendly : public CTreeCtrl { friend class CXTPTreeBase; }; /** @endcond */ protected: BOOL m_bMultiSelect; /**< TRUE for a multi-selection tree control. */ BOOL m_bBandLabel; /**< TRUE to include the label when selecting tree items. */ BOOL m_bExplorerTheme; /**< TRUE if Explorer theme is On for tree control (Windows Vista+) */ HTREEITEM m_hSelect; /**< For shift selection. */ HTREEITEM m_htiEdit; /**< Tree item that is currently edited. */ HTREEITEM m_htiLast; /**< Tree item that last had the mouse over. */ CColorFontMap m_mapColorFont; /**< Maps HTREEITEM handles with CLRFONT structures that contains the color and logfont information for the tree item. */ CTreeCtrl_Friendly* m_pTreeCtrl; /** Self tree pointer. */ int m_nTheme; /**< This variable will be removed with themes support. */ CXTPTreeTheme* m_pTheme; CXTPWinThemeWrapper* m_pWindowsTreeTheme; BOOL m_bDoDefaultItemDrawing; /**< FALSE by default, which means an item will be drawn by the framework. If TRUE, then items will be drawn in a standard way. */ int m_iconIndent; /**< Indent between icon/text/expander. */ HTREEITEM m_hInsertMark; /**< Tree item the insertion mark will be placed. */ BOOL m_InsertMarkAfter; /**< Insertion mark is placed before or after */ COLORREF m_InsertMarkColor; /**< Insertion mark color */ private: CPen m_penLines; bool m_bActionDone; bool m_bOkToEdit; }; ////////////////////////////////////////////////////////////////////// /** @cond */ AFX_INLINE HTREEITEM CXTPTreeBase::GetNextItem(HTREEITEM hItem, UINT nCode) const { _ASSERTE(::IsWindow(m_pTreeCtrl->m_hWnd)); return m_pTreeCtrl->GetNextItem(hItem, nCode); } AFX_INLINE HTREEITEM CXTPTreeBase::GetFocusedItem() const { _ASSERTE(m_bMultiSelect); return m_pTreeCtrl->GetSelectedItem(); } AFX_INLINE BOOL CXTPTreeBase::IsSelected(HTREEITEM hItem) const { return !!(TVIS_SELECTED & m_pTreeCtrl->GetItemState(hItem, TVIS_SELECTED)); } AFX_INLINE BOOL CXTPTreeBase::IsMultiSelect() const { return m_bMultiSelect; } AFX_INLINE BOOL CXTPTreeBase::IsExplorerTheme() const { return m_bExplorerTheme; } AFX_INLINE BOOL CXTPTreeBase::SetBandingHit(BOOL bLabel) { BOOL bReturn = m_bBandLabel; m_bBandLabel = bLabel; return bReturn; } AFX_INLINE CXTPTreeBase::CLRFONT::CLRFONT() : color((COLORREF)-1) , colorBack((COLORREF)-1) { ::ZeroMemory(&logfont, sizeof(LOGFONT)); } AFX_INLINE CTreeCtrl* CXTPTreeBase::GetSelfTreeCtrl() const { return m_pTreeCtrl; } AFX_INLINE int CXTPTreeBase::GetTheme() const { return m_nTheme; } AFX_INLINE BOOL CXTPTreeBase::IsDefaultItemDrawingEnabled() const { return m_bDoDefaultItemDrawing; } AFX_INLINE void CXTPTreeBase::EnableDefaultItemDrawing(BOOL bEnable /*= TRUE*/) { m_bDoDefaultItemDrawing = bEnable; } /** @endcond */ /** @cond */ # define DECLARE_TREE_BASE(ClassName, Tree, Base) \ class _XTP_EXT_CLASS ClassName \ : public Tree \ , public Base \ { \ public: \ ClassName() \ { \ m_bPreSubclassInit = true; \ } \ virtual UINT GetItemState(HTREEITEM hItem, UINT nStateMask) const \ { \ return Base::GetItemState(hItem, nStateMask); \ } \ virtual BOOL SelectItem(HTREEITEM hItem) \ { \ return Base::SelectItem(hItem); \ } \ virtual BOOL SetItemState(HTREEITEM hItem, UINT nState, UINT nStateMask) \ { \ return Base::SetItemState(hItem, nState, nStateMask); \ } \ virtual HTREEITEM GetNextItem(HTREEITEM hItem, UINT nCode) const \ { \ return Base::GetNextItem(hItem, nCode); \ } \ virtual HTREEITEM GetNextItem(HTREEITEM hItem) const \ { \ return Base::GetNextItem(hItem); \ } \ UINT GetSelectedCount() const \ { \ return Base::GetSelectedCount(); \ } \ BOOL SetInsertMark(HTREEITEM hItem, BOOL fAfter = TRUE) \ { \ return Base::SetInsertMark(hItem, fAfter); \ } \ COLORREF GetInsertMarkColor() const \ { \ return Base::GetInsertMarkColor(); \ } \ COLORREF SetInsertMarkColor(COLORREF clrNew) \ { \ return Base::SetInsertMarkColor(clrNew); \ } \ \ protected: \ virtual BOOL OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult) \ { \ return Base::OnNotify(wParam, lParam, pResult); \ } \ virtual BOOL PreTranslateMessage(MSG* pMsg) \ { \ return Base::PreTranslateMessage(pMsg); \ } \ virtual bool Init() \ { \ return Base::Init(); \ } \ virtual void PreSubclassWindow() \ { \ Tree::PreSubclassWindow(); \ if (m_bPreSubclassInit) \ Init(); \ } \ virtual BOOL PreCreateWindow(CREATESTRUCT& cs) \ { \ if (!Tree::PreCreateWindow(cs)) \ return FALSE; \ m_bPreSubclassInit = false; \ return TRUE; \ } \ bool m_bPreSubclassInit; \ afx_msg void OnLButtonDown(UINT nFlags, CPoint point) \ { \ Base::OnLButtonDown(nFlags, point); \ } \ afx_msg void OnRButtonDown(UINT nFlags, CPoint point) \ { \ Base::OnRButtonDown(nFlags, point); \ } \ afx_msg void OnSetFocus(CWnd* pOldWnd) \ { \ Base::OnSetFocus(pOldWnd); \ } \ afx_msg void OnKillFocus(CWnd* pNewWnd) \ { \ Base::OnKillFocus(pNewWnd); \ } \ afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) \ { \ Base::OnKeyDown(nChar, nRepCnt, nFlags); \ } \ afx_msg BOOL OnBeginLabelEdit(NMHDR* pNMHDR, LRESULT* pResult) \ { \ return Base::OnBeginLabelEdit(pNMHDR, pResult); \ } \ afx_msg BOOL OnEndLabelEdit(NMHDR* pNMHDR, LRESULT* pResult) \ { \ return Base::OnEndLabelEdit(pNMHDR, pResult); \ } \ afx_msg BOOL OnItemExpanding(NMHDR* pNMHDR, LRESULT* pResult) \ { \ return Base::OnItemExpanding(pNMHDR, pResult); \ } \ afx_msg BOOL OnDeleteItem(NMHDR* pNMHDR, LRESULT* pResult) \ { \ return Base::OnDeleteItem(pNMHDR, pResult); \ } \ afx_msg void OnSize(UINT nType, int cx, int cy) \ { \ Base::OnSize(nType, cx, cy); \ } \ afx_msg void OnMouseMove(UINT nFlags, CPoint point) \ { \ Base::OnMouseMove(nFlags, point); \ } \ afx_msg void OnTimer(UINT_PTR nIDEvent) \ { \ Base::OnTimer(nIDEvent); \ } \ afx_msg void OnNcMouseMove(UINT nHitTest, CPoint point) \ { \ Base::OnNcMouseMove(nHitTest, point); \ } \ afx_msg BOOL OnEraseBkgnd(CDC*) \ { \ return TRUE; \ } \ afx_msg void OnPaint() \ { \ CPaintDC dc(this); \ DoPaint(dc); \ } \ afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct) \ { \ if (Tree::OnCreate(lpCreateStruct) == -1) \ return -1; \ Init(); \ return 0; \ } \ afx_msg LRESULT OnSetTheme(WPARAM wParam, LPARAM lParam) \ { \ return Base::OnSetTheme(wParam, lParam); \ } \ }; # define ON_TREECTRL_REFLECT \ ON_MESSAGE(WM_XTP_SETCONTROLTHEME, OnSetTheme) \ ON_WM_LBUTTONDOWN() \ ON_WM_SETFOCUS() \ ON_WM_KILLFOCUS() \ ON_WM_RBUTTONDOWN() \ ON_WM_KEYDOWN() \ ON_WM_ERASEBKGND() \ ON_WM_PAINT() \ ON_WM_SIZE() \ ON_NOTIFY_REFLECT_EX(TVN_DELETEITEM, OnDeleteItem) \ ON_NOTIFY_REFLECT_EX(TVN_ITEMEXPANDING, OnItemExpanding) \ ON_NOTIFY_REFLECT_EX(TVN_BEGINLABELEDIT, OnBeginLabelEdit) \ ON_NOTIFY_REFLECT_EX(TVN_ENDLABELEDIT, OnEndLabelEdit) \ ON_WM_MOUSEMOVE() \ ON_WM_TIMER() \ ON_WM_NCMOUSEMOVE() \ ON_WM_CREATE /** @endcond */ const DWORD TVIS_FOCUSED = 0x0001; /**< @see CXTPTreeBase::SetItemState */ # include "Common/Base/Diagnostic/XTPEnableNoisyWarnings.h" /** @cond */ #endif // !defined(__XTTREEBASE_H__) /** @endcond */