]> git.saurik.com Git - wxWidgets.git/commitdiff
fix state images after changing their style (see #9591)
authorVadim Zeitlin <vadim@wxwidgets.org>
Sun, 25 Jan 2009 18:34:45 +0000 (18:34 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sun, 25 Jan 2009 18:34:45 +0000 (18:34 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@58409 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

samples/treectrl/treetest.cpp
samples/treectrl/treetest.h

index 15069adaca8cba78d05f8f64a917465df8dd675c..1daf44607534838c7e3b4683a5abb0a17ec0445d 100644 (file)
@@ -680,6 +680,11 @@ void MyFrame::OnToggleAlternateStates(wxCommandEvent& WXUNUSED(event))
 
     m_treeCtrl->SetAlternateStates(!alternateStates);
     m_treeCtrl->CreateStateImageList();
+
+    // normal states < alternate states
+    // so we must reset broken states
+    if ( alternateStates )
+        m_treeCtrl->ResetBrokenStateImages();
 }
 
 void MyFrame::OnToggleButtons(wxCommandEvent& WXUNUSED(event))
@@ -1152,6 +1157,29 @@ void MyTreeCtrl::DoToggleState(const wxTreeItemId& item)
     }
 }
 
+void MyTreeCtrl::DoResetBrokenStateImages(const wxTreeItemId& idParent,
+                                          wxTreeItemIdValue cookie, int state)
+{
+    wxTreeItemId id;
+
+    if ( !cookie )
+        id = GetFirstChild(idParent, cookie);
+    else
+        id = GetNextChild(idParent, cookie);
+
+    if ( !id.IsOk() )
+        return;
+
+    int curState = GetItemState(id);
+    if ( curState != wxTREE_ITEMSTATE_NONE && curState > state )
+        SetItemState(id, state);
+
+    if (ItemHasChildren(id))
+        DoResetBrokenStateImages(id, 0, state);
+
+    DoResetBrokenStateImages(idParent, cookie, state);
+}
+
 void MyTreeCtrl::LogEvent(const wxChar *name, const wxTreeEvent& event)
 {
     wxTreeItemId item = event.GetItem();
index 5b93a8113290e4ce11591c1aabe579e4eae9214c..8fd17755c37049b06827487b312e441e23c1bc2d 100644 (file)
@@ -123,6 +123,13 @@ public:
     void SetAlternateStates(bool show) { m_alternateStates = show; }
     bool AlternateStates() const { return m_alternateStates; }
 
+    void ResetBrokenStateImages()
+    {
+        const size_t count = GetStateImageList()->GetImageCount();
+        int state = count > 0 ? count - 1 : wxTREE_ITEMSTATE_NONE;
+        DoResetBrokenStateImages(GetRootItem(), 0, state);
+    }
+
 protected:
     virtual int OnCompareItems(const wxTreeItemId& i1, const wxTreeItemId& i2);
 
@@ -139,6 +146,9 @@ private:
                              size_t depth,
                              size_t folder);
 
+    void DoResetBrokenStateImages(const wxTreeItemId& idParent,
+                                  wxTreeItemIdValue cookie, int state);
+
     void LogEvent(const wxChar *name, const wxTreeEvent& event);
 
     int          m_imageSize;               // current size of images