Add wxTreeCtrl::{Clear,Set}FocusedItem().
Allow changing just the currently focused (not selected) item and also removing the focus completely. Closes #11599. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@64196 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -515,6 +515,7 @@ All (GUI):
|
|||||||
- Added wxTransparentColour.
|
- Added wxTransparentColour.
|
||||||
- Added wxToolBar::GetToolByPos().
|
- Added wxToolBar::GetToolByPos().
|
||||||
- Added wxProgressDialog::Was{Cancelled,Skipped}() (Julien Weinzorn).
|
- Added wxProgressDialog::Was{Cancelled,Skipped}() (Julien Weinzorn).
|
||||||
|
- Added wxTreeCtrl::{Clear,Set}FocusedItem() (Nikolay Tiushkov).
|
||||||
|
|
||||||
GTK:
|
GTK:
|
||||||
|
|
||||||
|
@@ -122,6 +122,9 @@ public:
|
|||||||
virtual size_t GetSelections(wxArrayTreeItemIds&) const;
|
virtual size_t GetSelections(wxArrayTreeItemIds&) const;
|
||||||
virtual wxTreeItemId GetFocusedItem() const { return m_current; }
|
virtual wxTreeItemId GetFocusedItem() const { return m_current; }
|
||||||
|
|
||||||
|
virtual void ClearFocusedItem();
|
||||||
|
virtual void SetFocusedItem(const wxTreeItemId& item);
|
||||||
|
|
||||||
virtual wxTreeItemId GetItemParent(const wxTreeItemId& item) const;
|
virtual wxTreeItemId GetItemParent(const wxTreeItemId& item) const;
|
||||||
virtual wxTreeItemId GetFirstChild(const wxTreeItemId& item,
|
virtual wxTreeItemId GetFirstChild(const wxTreeItemId& item,
|
||||||
wxTreeItemIdValue& cookie) const;
|
wxTreeItemIdValue& cookie) const;
|
||||||
|
@@ -129,6 +129,10 @@ public:
|
|||||||
virtual size_t GetSelections(wxArrayTreeItemIds& selections) const;
|
virtual size_t GetSelections(wxArrayTreeItemIds& selections) const;
|
||||||
virtual wxTreeItemId GetFocusedItem() const;
|
virtual wxTreeItemId GetFocusedItem() const;
|
||||||
|
|
||||||
|
virtual void ClearFocusedItem();
|
||||||
|
virtual void SetFocusedItem(const wxTreeItemId& item);
|
||||||
|
|
||||||
|
|
||||||
virtual wxTreeItemId GetItemParent(const wxTreeItemId& item) const;
|
virtual wxTreeItemId GetItemParent(const wxTreeItemId& item) const;
|
||||||
virtual wxTreeItemId GetFirstChild(const wxTreeItemId& item,
|
virtual wxTreeItemId GetFirstChild(const wxTreeItemId& item,
|
||||||
wxTreeItemIdValue& cookie) const;
|
wxTreeItemIdValue& cookie) const;
|
||||||
@@ -285,9 +289,6 @@ private:
|
|||||||
// and the tree has wxTR_HIDE_ROOT style)
|
// and the tree has wxTR_HIDE_ROOT style)
|
||||||
bool IsHiddenRoot(const wxTreeItemId& item) const;
|
bool IsHiddenRoot(const wxTreeItemId& item) const;
|
||||||
|
|
||||||
// clears/sets the currently focused item
|
|
||||||
void ClearFocusedItem();
|
|
||||||
void SetFocusedItem(const wxTreeItemId& item);
|
|
||||||
|
|
||||||
// check if the given flags (taken from TV_HITTESTINFO structure)
|
// check if the given flags (taken from TV_HITTESTINFO structure)
|
||||||
// indicate a position "on item": this is less trivial than just checking
|
// indicate a position "on item": this is less trivial than just checking
|
||||||
|
@@ -214,6 +214,13 @@ public:
|
|||||||
// equivalent to GetSelection() if not wxTR_MULTIPLE
|
// equivalent to GetSelection() if not wxTR_MULTIPLE
|
||||||
virtual wxTreeItemId GetFocusedItem() const = 0;
|
virtual wxTreeItemId GetFocusedItem() const = 0;
|
||||||
|
|
||||||
|
|
||||||
|
// Clears the currently focused item
|
||||||
|
virtual void ClearFocusedItem() = 0;
|
||||||
|
// Sets the currently focused item. Item should be valid
|
||||||
|
virtual void SetFocusedItem(const wxTreeItemId& item) = 0;
|
||||||
|
|
||||||
|
|
||||||
// get the parent of this item (may return NULL if root)
|
// get the parent of this item (may return NULL if root)
|
||||||
virtual wxTreeItemId GetItemParent(const wxTreeItemId& item) const = 0;
|
virtual wxTreeItemId GetItemParent(const wxTreeItemId& item) const = 0;
|
||||||
|
|
||||||
|
@@ -437,6 +437,24 @@ public:
|
|||||||
*/
|
*/
|
||||||
virtual wxTreeItemId GetFocusedItem() const;
|
virtual wxTreeItemId GetFocusedItem() const;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Clears the currently focused item
|
||||||
|
|
||||||
|
@since 2.9.1
|
||||||
|
*/
|
||||||
|
virtual void ClearFocusedItem();
|
||||||
|
|
||||||
|
/**
|
||||||
|
Sets the currently focused item.
|
||||||
|
|
||||||
|
@param item
|
||||||
|
The item to make the current one. It must be valid.
|
||||||
|
@since 2.9.1
|
||||||
|
*/
|
||||||
|
virtual void SetFocusedItem(const wxTreeItemId& item);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Returns the normal image list.
|
Returns the normal image list.
|
||||||
*/
|
*/
|
||||||
|
@@ -129,6 +129,8 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame)
|
|||||||
MENU_LINK(ToggleIcon)
|
MENU_LINK(ToggleIcon)
|
||||||
MENU_LINK(ToggleState)
|
MENU_LINK(ToggleState)
|
||||||
MENU_LINK(SelectRoot)
|
MENU_LINK(SelectRoot)
|
||||||
|
MENU_LINK(SetFocusedRoot)
|
||||||
|
MENU_LINK(ClearFocused)
|
||||||
|
|
||||||
MENU_LINK(ShowFirstVisible)
|
MENU_LINK(ShowFirstVisible)
|
||||||
#ifdef wxHAS_LAST_VISIBLE
|
#ifdef wxHAS_LAST_VISIBLE
|
||||||
@@ -263,6 +265,9 @@ MyFrame::MyFrame(const wxString& title, int x, int y, int w, int h)
|
|||||||
tree_menu->Append(TreeTest_DeleteChildren, wxT("Delete &children"));
|
tree_menu->Append(TreeTest_DeleteChildren, wxT("Delete &children"));
|
||||||
tree_menu->Append(TreeTest_DeleteAll, wxT("Delete &all items"));
|
tree_menu->Append(TreeTest_DeleteAll, wxT("Delete &all items"));
|
||||||
tree_menu->Append(TreeTest_SelectRoot, wxT("Select root item"));
|
tree_menu->Append(TreeTest_SelectRoot, wxT("Select root item"));
|
||||||
|
tree_menu->AppendSeparator();
|
||||||
|
tree_menu->Append(TreeTest_SetFocusedRoot, wxT("Set focus to root item"));
|
||||||
|
tree_menu->Append(TreeTest_ClearFocused, wxT("Reset focus"));
|
||||||
|
|
||||||
tree_menu->AppendSeparator();
|
tree_menu->AppendSeparator();
|
||||||
tree_menu->Append(TreeTest_Count, wxT("Count children of current item"));
|
tree_menu->Append(TreeTest_Count, wxT("Count children of current item"));
|
||||||
@@ -592,6 +597,17 @@ void MyFrame::OnSelectRoot(wxCommandEvent& WXUNUSED(event))
|
|||||||
m_treeCtrl->SelectItem(m_treeCtrl->GetRootItem());
|
m_treeCtrl->SelectItem(m_treeCtrl->GetRootItem());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MyFrame::OnSetFocusedRoot(wxCommandEvent& WXUNUSED(event))
|
||||||
|
{
|
||||||
|
if ( !m_treeCtrl->HasFlag(wxTR_HIDE_ROOT) )
|
||||||
|
m_treeCtrl->SetFocusedItem(m_treeCtrl->GetRootItem());
|
||||||
|
}
|
||||||
|
|
||||||
|
void MyFrame::OnClearFocused(wxCommandEvent& WXUNUSED(event))
|
||||||
|
{
|
||||||
|
m_treeCtrl->ClearFocusedItem();
|
||||||
|
}
|
||||||
|
|
||||||
void MyFrame::OnUnselect(wxCommandEvent& WXUNUSED(event))
|
void MyFrame::OnUnselect(wxCommandEvent& WXUNUSED(event))
|
||||||
{
|
{
|
||||||
m_treeCtrl->UnselectAll();
|
m_treeCtrl->UnselectAll();
|
||||||
|
@@ -212,6 +212,8 @@ public:
|
|||||||
void OnSelectChildren(wxCommandEvent& event);
|
void OnSelectChildren(wxCommandEvent& event);
|
||||||
#endif // NO_MULTIPLE_SELECTION
|
#endif // NO_MULTIPLE_SELECTION
|
||||||
void OnSelectRoot(wxCommandEvent& event);
|
void OnSelectRoot(wxCommandEvent& event);
|
||||||
|
void OnSetFocusedRoot(wxCommandEvent& event);
|
||||||
|
void OnClearFocused(wxCommandEvent& event);
|
||||||
void OnDelete(wxCommandEvent& event);
|
void OnDelete(wxCommandEvent& event);
|
||||||
void OnDeleteChildren(wxCommandEvent& event);
|
void OnDeleteChildren(wxCommandEvent& event);
|
||||||
void OnDeleteAll(wxCommandEvent& event);
|
void OnDeleteAll(wxCommandEvent& event);
|
||||||
@@ -355,6 +357,8 @@ enum
|
|||||||
TreeTest_Select,
|
TreeTest_Select,
|
||||||
TreeTest_Unselect,
|
TreeTest_Unselect,
|
||||||
TreeTest_SelectRoot,
|
TreeTest_SelectRoot,
|
||||||
|
TreeTest_ClearFocused,
|
||||||
|
TreeTest_SetFocusedRoot,
|
||||||
TreeTest_SelectChildren,
|
TreeTest_SelectChildren,
|
||||||
TreeTest_ShowFirstVisible,
|
TreeTest_ShowFirstVisible,
|
||||||
TreeTest_ShowLastVisible,
|
TreeTest_ShowLastVisible,
|
||||||
|
@@ -1953,6 +1953,20 @@ void wxGenericTreeCtrl::Unselect()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void wxGenericTreeCtrl::ClearFocusedItem()
|
||||||
|
{
|
||||||
|
wxTreeItemId item = GetFocusedItem();
|
||||||
|
if ( item.IsOk() )
|
||||||
|
SelectItem(item, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxGenericTreeCtrl::SetFocusedItem(const wxTreeItemId& item)
|
||||||
|
{
|
||||||
|
wxCHECK_RET( item.IsOk(), wxT("invalid tree item") );
|
||||||
|
|
||||||
|
SelectItem(item, true);
|
||||||
|
}
|
||||||
|
|
||||||
void wxGenericTreeCtrl::UnselectAllChildren(wxGenericTreeItem *item)
|
void wxGenericTreeCtrl::UnselectAllChildren(wxGenericTreeItem *item)
|
||||||
{
|
{
|
||||||
if (item->IsSelected())
|
if (item->IsSelected())
|
||||||
|
@@ -2137,6 +2137,8 @@ void wxTreeCtrl::ClearFocusedItem()
|
|||||||
|
|
||||||
void wxTreeCtrl::SetFocusedItem(const wxTreeItemId& item)
|
void wxTreeCtrl::SetFocusedItem(const wxTreeItemId& item)
|
||||||
{
|
{
|
||||||
|
wxCHECK_RET( item.IsOk(), wxT("invalid tree item") );
|
||||||
|
|
||||||
TempSetter set(m_changingSelection);
|
TempSetter set(m_changingSelection);
|
||||||
|
|
||||||
::SetFocus(GetHwnd(), HITEM(item));
|
::SetFocus(GetHwnd(), HITEM(item));
|
||||||
|
Reference in New Issue
Block a user