added wxTreeCtrl::GetFocusedItem() (closes #10859)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@61134 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin 2009-06-19 23:34:51 +00:00
parent 61dabbffe3
commit febebac1a0
5 changed files with 39 additions and 14 deletions

View File

@ -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
-----------------------------------------------------------

View File

@ -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,

View File

@ -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;

View File

@ -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;

View File

@ -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 );