]> git.saurik.com Git - wxWidgets.git/commitdiff
Add wxTreeCtrl::{Clear,Set}FocusedItem().
authorVadim Zeitlin <vadim@wxwidgets.org>
Sun, 2 May 2010 12:01:30 +0000 (12:01 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sun, 2 May 2010 12:01:30 +0000 (12:01 +0000)
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

docs/changes.txt
include/wx/generic/treectlg.h
include/wx/msw/treectrl.h
include/wx/treectrl.h
interface/wx/treectrl.h
samples/treectrl/treetest.cpp
samples/treectrl/treetest.h
src/generic/treectlg.cpp
src/msw/treectrl.cpp

index c7ba0b1c8da865fc5e11c4bdb412b809c2d3db2e..8aecf879ba70e09144195d6c23c1edf395742162 100644 (file)
@@ -515,6 +515,7 @@ All (GUI):
 - Added wxTransparentColour.
 - Added wxToolBar::GetToolByPos().
 - Added wxProgressDialog::Was{Cancelled,Skipped}() (Julien Weinzorn).
+- Added wxTreeCtrl::{Clear,Set}FocusedItem() (Nikolay Tiushkov).
 
 GTK:
 
index 6a1a838e18c82cbb84804a697687cd641176429e..7c068dd7f54e016c69827e609bde97f63e69b8a8 100644 (file)
@@ -122,6 +122,9 @@ public:
     virtual size_t GetSelections(wxArrayTreeItemIds&) const;
     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 GetFirstChild(const wxTreeItemId& item,
                                        wxTreeItemIdValue& cookie) const;
index 25461a87de14b03ee0f875c9b0cd03fd1d97eb81..b1e8e784929d2addbcc10ca545945987c99a116c 100644 (file)
@@ -129,6 +129,10 @@ public:
     virtual size_t GetSelections(wxArrayTreeItemIds& selections) const;
     virtual wxTreeItemId GetFocusedItem() const;
 
+    virtual void ClearFocusedItem();
+    virtual void SetFocusedItem(const wxTreeItemId& item);
+
+
     virtual wxTreeItemId GetItemParent(const wxTreeItemId& item) const;
     virtual wxTreeItemId GetFirstChild(const wxTreeItemId& item,
                                        wxTreeItemIdValue& cookie) const;
@@ -285,9 +289,6 @@ private:
     // and the tree has wxTR_HIDE_ROOT style)
     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)
     // indicate a position "on item": this is less trivial than just checking
index fe8b7f1fb62ed8bc3d2c8aa82650872023f7c544..7b2d71c6e2d639cde909e342b78f024fe19d2cbf 100644 (file)
@@ -214,6 +214,13 @@ public:
         // equivalent to GetSelection() if not wxTR_MULTIPLE
     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)
     virtual wxTreeItemId GetItemParent(const wxTreeItemId& item) const = 0;
 
index 9b9fb7c14150b40cf9d031d34df54c43ba6fcc05..f11959f743e7e9ec64fb1d038c68c93e5dad0214 100644 (file)
@@ -437,6 +437,24 @@ public:
     */
     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.
     */
index 0da06d9ea11f13d7a66b977a9d4e329ca30c3316..5ac4e9c5cbf2aa3f144df1cbaf3efee32b63e6d1 100644 (file)
@@ -129,6 +129,8 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame)
     MENU_LINK(ToggleIcon)
     MENU_LINK(ToggleState)
     MENU_LINK(SelectRoot)
+    MENU_LINK(SetFocusedRoot)
+    MENU_LINK(ClearFocused)
 
     MENU_LINK(ShowFirstVisible)
 #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_DeleteAll, wxT("Delete &all items"));
     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->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());
 }
 
+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))
 {
     m_treeCtrl->UnselectAll();
index 50db3d92e394e503a14fe18014ac5b4222d64420..645e0d0668ef506318dcd336e577fbee3f1b6e22 100644 (file)
@@ -212,6 +212,8 @@ public:
     void OnSelectChildren(wxCommandEvent& event);
 #endif // NO_MULTIPLE_SELECTION
     void OnSelectRoot(wxCommandEvent& event);
+    void OnSetFocusedRoot(wxCommandEvent& event);
+    void OnClearFocused(wxCommandEvent& event);
     void OnDelete(wxCommandEvent& event);
     void OnDeleteChildren(wxCommandEvent& event);
     void OnDeleteAll(wxCommandEvent& event);
@@ -355,6 +357,8 @@ enum
     TreeTest_Select,
     TreeTest_Unselect,
     TreeTest_SelectRoot,
+    TreeTest_ClearFocused,
+    TreeTest_SetFocusedRoot,
     TreeTest_SelectChildren,
     TreeTest_ShowFirstVisible,
     TreeTest_ShowLastVisible,
index a393dc0fbb3d0ae6375307713bcfb4fa6cb25f0e..b88ba3851ab790f11308206035328c9fe4f3ff8b 100644 (file)
@@ -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)
 {
     if (item->IsSelected())
index 9464bec90b3669822d36e04c1e34098d4910e195..9e8c7e31d1e158ad86ef1dd8c3e46768bae477cc 100644 (file)
@@ -2137,6 +2137,8 @@ void wxTreeCtrl::ClearFocusedItem()
 
 void wxTreeCtrl::SetFocusedItem(const wxTreeItemId& item)
 {
+    wxCHECK_RET( item.IsOk(), wxT("invalid tree item") );
+
     TempSetter set(m_changingSelection);
 
     ::SetFocus(GetHwnd(), HITEM(item));