From: Vadim Zeitlin Date: Fri, 19 Jun 2009 23:34:51 +0000 (+0000) Subject: added wxTreeCtrl::GetFocusedItem() (closes #10859) X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/febebac1a01ce5d7fc11cf2c645e0c93261ad0f0 added wxTreeCtrl::GetFocusedItem() (closes #10859) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@61134 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/docs/changes.txt b/docs/changes.txt index 405fff83fe..48baa8bd11 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -128,6 +128,10 @@ Changes in behaviour not resulting in compilation errors, please read this! changed. See the updated wxWindow::SetBackgroundStyle() description in the manual for more details. +- wxTreeCtrl::GetSelection now asserts if the tree has the wxTR_MULTIPLE style. + Instead use GetSelections() for multiple items; or if you want only the + single item last touched, the new wxTreeCtrl::GetFocusedItem. + Changes in behaviour which may result in compilation errors ----------------------------------------------------------- diff --git a/include/wx/generic/treectlg.h b/include/wx/generic/treectlg.h index 71dea9fc13..98bc85666a 100644 --- a/include/wx/generic/treectlg.h +++ b/include/wx/generic/treectlg.h @@ -120,6 +120,7 @@ public: return m_current; } virtual size_t GetSelections(wxArrayTreeItemIds&) const; + virtual wxTreeItemId GetFocusedItem() const { return m_current; } virtual wxTreeItemId GetItemParent(const wxTreeItemId& item) const; virtual wxTreeItemId GetFirstChild(const wxTreeItemId& item, diff --git a/include/wx/treectrl.h b/include/wx/treectrl.h index 81e24a8e8c..ee13f4f4a4 100644 --- a/include/wx/treectrl.h +++ b/include/wx/treectrl.h @@ -210,6 +210,10 @@ public: // control with a lot of items (~ O(number of items)). virtual size_t GetSelections(wxArrayTreeItemIds& selections) const = 0; + // get the last item to be clicked when the control has wxTR_MULTIPLE + // equivalent to GetSelection() if not wxTR_MULTIPLE + virtual wxTreeItemId GetFocusedItem() const = 0; + // get the parent of this item (may return NULL if root) virtual wxTreeItemId GetItemParent(const wxTreeItemId& item) const = 0; diff --git a/interface/wx/treectrl.h b/interface/wx/treectrl.h index dff4440b32..6897303738 100644 --- a/interface/wx/treectrl.h +++ b/interface/wx/treectrl.h @@ -418,6 +418,15 @@ public: */ virtual wxTreeItemId GetFirstVisibleItem() const; + /** + Returns the item last clicked or otherwise selected. + Unlike GetSelection(), it can be used whether or not + the control has the @c wxTR_MULTIPLE style. + + @since 2.9.1 + */ + virtual wxTreeItemId GetFocusedItem() const; + /** Returns the normal image list. */ @@ -566,7 +575,8 @@ public: /** Returns the selection, or an invalid item if there is no selection. This function only works with the controls without @c wxTR_MULTIPLE style, - use GetSelections() for the controls which do have this style. + use GetSelections() for the controls which do have this style + or, if a single item is wanted, use GetFocusedItem(). */ virtual wxTreeItemId GetSelection() const; diff --git a/samples/treectrl/treetest.cpp b/samples/treectrl/treetest.cpp index e422f27a55..edc685a307 100644 --- a/samples/treectrl/treetest.cpp +++ b/samples/treectrl/treetest.cpp @@ -479,7 +479,7 @@ void MyFrame::OnClearLog(wxCommandEvent& WXUNUSED(event)) void MyFrame::OnRename(wxCommandEvent& WXUNUSED(event)) { - wxTreeItemId item = m_treeCtrl->GetSelection(); + wxTreeItemId item = m_treeCtrl->GetFocusedItem(); CHECK_ITEM( item ); @@ -500,7 +500,7 @@ void MyFrame::OnRename(wxCommandEvent& WXUNUSED(event)) void MyFrame::OnCount(wxCommandEvent& WXUNUSED(event)) { - wxTreeItemId item = m_treeCtrl->GetSelection(); + wxTreeItemId item = m_treeCtrl->GetFocusedItem(); CHECK_ITEM( item ); @@ -511,7 +511,7 @@ void MyFrame::OnCount(wxCommandEvent& WXUNUSED(event)) void MyFrame::OnCountRec(wxCommandEvent& WXUNUSED(event)) { - wxTreeItemId item = m_treeCtrl->GetSelection(); + wxTreeItemId item = m_treeCtrl->GetFocusedItem(); CHECK_ITEM( item ); @@ -522,7 +522,7 @@ void MyFrame::OnCountRec(wxCommandEvent& WXUNUSED(event)) void MyFrame::DoSort(bool reverse) { - wxTreeItemId item = m_treeCtrl->GetSelection(); + wxTreeItemId item = m_treeCtrl->GetFocusedItem(); CHECK_ITEM( item ); @@ -531,7 +531,7 @@ void MyFrame::DoSort(bool reverse) void MyFrame::OnHighlight(wxCommandEvent& WXUNUSED(event)) { - wxTreeItemId id = m_treeCtrl->GetSelection(); + wxTreeItemId id = m_treeCtrl->GetFocusedItem(); CHECK_ITEM( id ); @@ -551,7 +551,7 @@ void MyFrame::OnHighlight(wxCommandEvent& WXUNUSED(event)) void MyFrame::OnDump(wxCommandEvent& WXUNUSED(event)) { - wxTreeItemId root = m_treeCtrl->GetSelection(); + wxTreeItemId root = m_treeCtrl->GetFocusedItem(); CHECK_ITEM( root ); @@ -580,7 +580,7 @@ void MyFrame::OnDumpSelected(wxCommandEvent& WXUNUSED(event)) void MyFrame::OnSelect(wxCommandEvent& WXUNUSED(event)) { - m_treeCtrl->SelectItem(m_treeCtrl->GetSelection()); + m_treeCtrl->SelectItem(m_treeCtrl->GetFocusedItem()); } void MyFrame::OnSelectRoot(wxCommandEvent& WXUNUSED(event)) @@ -598,7 +598,7 @@ void MyFrame::OnUnselect(wxCommandEvent& WXUNUSED(event)) void MyFrame::DoSetBold(bool bold) { - wxTreeItemId item = m_treeCtrl->GetSelection(); + wxTreeItemId item = m_treeCtrl->GetFocusedItem(); CHECK_ITEM( item ); @@ -607,7 +607,7 @@ void MyFrame::DoSetBold(bool bold) void MyFrame::OnDelete(wxCommandEvent& WXUNUSED(event)) { - wxTreeItemId item = m_treeCtrl->GetSelection(); + wxTreeItemId item = m_treeCtrl->GetFocusedItem(); CHECK_ITEM( item ); @@ -616,7 +616,7 @@ void MyFrame::OnDelete(wxCommandEvent& WXUNUSED(event)) void MyFrame::OnDeleteChildren(wxCommandEvent& WXUNUSED(event)) { - wxTreeItemId item = m_treeCtrl->GetSelection(); + wxTreeItemId item = m_treeCtrl->GetFocusedItem(); CHECK_ITEM( item ); @@ -763,19 +763,25 @@ void MyFrame::OnIncSpacing(wxCommandEvent& WXUNUSED(event)) { unsigned int indent = m_treeCtrl->GetSpacing(); if (indent < 100) + { m_treeCtrl->SetSpacing( indent+5 ); + m_treeCtrl->Refresh(); + } } void MyFrame::OnDecSpacing(wxCommandEvent& WXUNUSED(event)) { unsigned int indent = m_treeCtrl->GetSpacing(); if (indent > 10) + { m_treeCtrl->SetSpacing( indent-5 ); + m_treeCtrl->Refresh(); + } } void MyFrame::OnToggleIcon(wxCommandEvent& WXUNUSED(event)) { - wxTreeItemId item = m_treeCtrl->GetSelection(); + wxTreeItemId item = m_treeCtrl->GetFocusedItem(); CHECK_ITEM( item ); @@ -784,7 +790,7 @@ void MyFrame::OnToggleIcon(wxCommandEvent& WXUNUSED(event)) void MyFrame::OnToggleState(wxCommandEvent& WXUNUSED(event)) { - wxTreeItemId item = m_treeCtrl->GetSelection(); + wxTreeItemId item = m_treeCtrl->GetFocusedItem(); CHECK_ITEM( item ); @@ -804,7 +810,7 @@ void MyFrame::DoShowFirstOrLast(TreeFunc0_t pfn, const wxString& label) void MyFrame::DoShowRelativeItem(TreeFunc1_t pfn, const wxString& label) { - wxTreeItemId item = m_treeCtrl->GetSelection(); + wxTreeItemId item = m_treeCtrl->GetFocusedItem(); CHECK_ITEM( item );