From 9248adc8da5476a48d6e0263f4683b87f7b899d4 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 7 Jan 2007 15:02:57 +0000 Subject: [PATCH] added wxTreeCtrl::CollapseAll[Children]() and IsEmpty() methods; documented wxTreeItemId (patch 1622125) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@44116 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/changes.txt | 1 + docs/latex/wx/treectrl.tex | 89 +++++++++++++++++++++++++++++++++++++- include/wx/treectrl.h | 7 +++ src/common/treebase.cpp | 31 +++++++++++++ 4 files changed, 126 insertions(+), 2 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index 3820e02e63..db0a190df6 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -95,6 +95,7 @@ All: - Fix compilation with wxUSE_STL=1 - wxGrid::GetBestSize() returns same size the grid would have after AutoSize() +- Added wxTreeCtrl::CollapseAll[Children]() and IsEmpty() (Francesco Montorsi) wxMSW: diff --git a/docs/latex/wx/treectrl.tex b/docs/latex/wx/treectrl.tex index 96859ec829..727181f7b3 100644 --- a/docs/latex/wx/treectrl.tex +++ b/docs/latex/wx/treectrl.tex @@ -13,7 +13,7 @@ A tree control presents information as a hierarchy, with items that may be expanded to show further items. Items in a tree control are referenced by wxTreeItemId handles, -which may be tested for validity by calling wxTreeItemId::IsOk. +which may be tested for validity by calling \helpref{wxTreeItemId::IsOk}{wxtreeitemidisok}. To intercept events from a tree control, use the event table macros described in \helpref{wxTreeEvent}{wxtreeevent}. @@ -238,6 +238,28 @@ See also \helpref{SetStateImageList}{wxtreectrlsetstateimagelist}. Collapses the given item. +\membersection{wxTreeCtrl::CollapseAll}\label{wxtreectrlcollapseall} + +\func{void}{CollapseAll}{\void} + +Collapses the root item. + +\wxheading{See also} + +\helpref{ExpandAll}{wxtreectrlexpandall} + + +\membersection{wxTreeCtrl::CollapseAllChildren}\label{wxtreectrlcollapseallchildren} + +\func{void}{CollapseAllChildren}{\param{const wxTreeItemId\&}{ item}} + +Collapses this item and all of its children, recursively. + +\wxheading{See also} + +\helpref{ExpandAllChildren}{wxtreectrlexpandallchildren} + + \membersection{wxTreeCtrl::CollapseAndReset}\label{wxtreectrlcollapseandreset} \func{void}{CollapseAndReset}{\param{const wxTreeItemId\&}{ item}} @@ -333,7 +355,7 @@ Expands the given item. \membersection{wxTreeCtrl::ExpandAll}\label{wxtreectrlexpandall} -\func{void}{Expand}{\void} +\func{void}{ExpandAll}{\void} Expands all items in the tree. @@ -728,6 +750,13 @@ Returns {\tt true} if the given item is in bold state. See also: \helpref{SetItemBold}{wxtreectrlsetitembold} +\membersection{wxTreeCtrl::IsEmpty}\label{wxtreectrlisempty} + +\constfunc{bool}{IsEmpty}{} + +Returns \true if the control is empty (i.e. has no items, even no root one). + + \membersection{wxTreeCtrl::IsExpanded}\label{wxtreectrlisexpanded} \constfunc{bool}{IsExpanded}{\param{const wxTreeItemId\&}{ item}} @@ -1023,3 +1052,59 @@ all items if it does have this style. Unselects the given item. This works in multiselection controls only. + + + + +%% the wxTreeItemId opaque class + + +\section{\class{wxTreeItemId}}\label{wxtreeitemid} + +An opaque reference to a tree item. + + +\wxheading{Derived from} + +None + +\wxheading{Include files} + + + +\wxheading{See also} + +\helpref{wxTreeItemCtrl}{wxtreeitemctrl}, \helpref{wxTreeItemData}{wxtreeitemdata},\\ +\helpref{wxTreeCtrl overview}{wxtreectrloverview} + + +\latexignore{\rtfignore{\wxheading{Members}}} + +\membersection{wxTreeItemId::wxTreeItemId}\label{wxtreeitemidconstr} + +\func{}{wxTreeItemId}{\void} + +Default constructor. wxTreemItemIds are not meant to be constructed explicitly by +the user; they are returned by the \helpref{wxTreeItemCtrl}{wxtreeitemctrl} functions instead. + + +\membersection{wxTreeItemId::IsOk}\label{wxtreeitemidisok} + +\constfunc{bool}{IsOk}{} + +Returns \true if this instance is referencing a valid tree item. + + +\membersection{Operators}\label{wxtreeitemidoperators} + +\constfunc{void}{operator $!$}{} + +Synonim for \helpref{IsOk}{wxtreeitemidisok} + + +\constfunc{bool}{operator $==$}{\param{const wxTreeItemId\& }{item}} + +\constfunc{bool}{operator $!=$}{\param{const wxTreeItemId\& }{item}} + +Operators for comparison between \helpref{wxTreeItemId}{wxtreeitemid} objects. + diff --git a/include/wx/treectrl.h b/include/wx/treectrl.h index e964012a4f..923d1b945a 100644 --- a/include/wx/treectrl.h +++ b/include/wx/treectrl.h @@ -172,6 +172,9 @@ public: virtual bool IsSelected(const wxTreeItemId& item) const = 0; // is item text in bold font? virtual bool IsBold(const wxTreeItemId& item) const = 0; + // is the control empty? + bool IsEmpty() const; + // number of children // ------------------ @@ -293,6 +296,10 @@ public: void ExpandAll(); // collapse the item without removing its children virtual void Collapse(const wxTreeItemId& item) = 0; + // collapse the item and all its childs and thats childs + void CollapseAllChildren(const wxTreeItemId& item); + // collapse all items + void CollapseAll(); // collapse the item and remove all children virtual void CollapseAndReset(const wxTreeItemId& item) = 0; // toggles the current state diff --git a/src/common/treebase.cpp b/src/common/treebase.cpp index 08220fa503..f10e2af927 100644 --- a/src/common/treebase.cpp +++ b/src/common/treebase.cpp @@ -183,6 +183,9 @@ wxSize wxTreeCtrlBase::DoGetBestSize() const void wxTreeCtrlBase::ExpandAll() { + if ( IsEmpty() ) + return; + ExpandAllChildren(GetRootItem()); } @@ -202,5 +205,33 @@ void wxTreeCtrlBase::ExpandAllChildren(const wxTreeItemId& item) } } +void wxTreeCtrlBase::CollapseAll() +{ + if ( IsEmpty() ) + return; + + CollapseAllChildren(GetRootItem()); +} + +void wxTreeCtrlBase::CollapseAllChildren(const wxTreeItemId& item) +{ + // first (recursively) collapse all the children + wxTreeItemIdValue cookie; + for ( wxTreeItemId idCurr = GetFirstChild(item, cookie); + idCurr.IsOk(); + idCurr = GetNextChild(item, cookie) ) + { + CollapseAllChildren(idCurr); + } + + // then collapse this element too + Collapse(item); +} + +bool wxTreeCtrlBase::IsEmpty() const +{ + return !GetRootItem().IsOk(); +} + #endif // wxUSE_TREECTRL -- 2.47.2