diff --git a/include/wx/generic/treectlg.h b/include/wx/generic/treectlg.h index e431299f88..e2913b0338 100644 --- a/include/wx/generic/treectlg.h +++ b/include/wx/generic/treectlg.h @@ -369,6 +369,13 @@ private: // operation. void ResetFindState(); + // Find the next item, either looking inside the collapsed items or not. + enum + { + Next_Any = 0, + Next_Visible = 1 + }; + wxTreeItemId DoGetNext(const wxTreeItemId& item, int flags = 0) const; // True if we're using custom colours/font, respectively, or false if we're // using the default colours and should update them whenever system colours diff --git a/src/generic/treectlg.cpp b/src/generic/treectlg.cpp index 4789e2314c..49c7e25e83 100644 --- a/src/generic/treectlg.cpp +++ b/src/generic/treectlg.cpp @@ -1491,29 +1491,36 @@ wxTreeItemId wxGenericTreeCtrl::GetPrevSibling(const wxTreeItemId& item) const // Only for internal use right now, but should probably be public wxTreeItemId wxGenericTreeCtrl::GetNext(const wxTreeItemId& item) const +{ + return DoGetNext(item, Next_Any); +} + +wxTreeItemId +wxGenericTreeCtrl::DoGetNext(const wxTreeItemId& item, int flags) const { wxCHECK_MSG( item.IsOk(), wxTreeItemId(), wxT("invalid tree item") ); wxGenericTreeItem *i = (wxGenericTreeItem*) item.m_pItem; // First see if there are any children. - wxArrayGenericTreeItems& children = i->GetChildren(); - if (children.GetCount() > 0) + if ( !(flags & Next_Visible) || i->IsExpanded() ) { - return children.Item(0); - } - else - { - // Try a sibling of this or ancestor instead - wxTreeItemId p = item; - wxTreeItemId toFind; - do - { - toFind = GetNextSibling(p); - p = GetItemParent(p); - } while (p.IsOk() && !toFind.IsOk()); - return toFind; + wxArrayGenericTreeItems& children = i->GetChildren(); + if (children.GetCount() > 0) + { + return children.Item(0); + } } + + // Try a sibling of this or ancestor instead + wxTreeItemId p = item; + wxTreeItemId toFind; + do + { + toFind = GetNextSibling(p); + p = GetItemParent(p); + } while (p.IsOk() && !toFind.IsOk()); + return toFind; } wxTreeItemId wxGenericTreeCtrl::GetFirstVisibleItem() const @@ -1537,16 +1544,7 @@ wxTreeItemId wxGenericTreeCtrl::GetNextVisible(const wxTreeItemId& item) const wxCHECK_MSG( item.IsOk(), wxTreeItemId(), wxT("invalid tree item") ); wxASSERT_MSG( IsVisible(item), wxT("this item itself should be visible") ); - wxTreeItemId id = item; - if (id.IsOk()) - { - while (id = GetNext(id), id.IsOk()) - { - if (IsVisible(id)) - return id; - } - } - return wxTreeItemId(); + return DoGetNext(item, Next_Visible); } wxTreeItemId wxGenericTreeCtrl::GetPrevVisible(const wxTreeItemId& item) const