]> git.saurik.com Git - wxWidgets.git/commitdiff
Take into account the initial buttons state when creating wxGTK toolbar.
authorVadim Zeitlin <vadim@wxwidgets.org>
Sat, 26 Dec 2009 16:36:39 +0000 (16:36 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sat, 26 Dec 2009 16:36:39 +0000 (16:36 +0000)
With wxMSW it is possible to call e.g. wxToolBarTool::Enable(false) on a tool
before calling wxToolBar::Realize() to create the tool in an initially
disabled state but this wasn't done in wxGTK version.

Override Realize() now under wxGTK to bring the native toolbar buttons state
in sync with the internal state of the corresponding wxToolBarTools.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@62994 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/gtk/toolbar.h
src/gtk/toolbar.cpp

index ffefa73a5802a3def5b607586d1e7631536fa213..c752a8dd45f1855eb31ee41990b3f3cdb25a40f1 100644 (file)
@@ -51,6 +51,8 @@ public:
     virtual void SetToolNormalBitmap(int id, const wxBitmap& bitmap);
     virtual void SetToolDisabledBitmap(int id, const wxBitmap& bitmap);
 
+    virtual bool Realize();
+
     static wxVisualAttributes
     GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
 
index 274feaa587a31c2464900e3c7a8d3e74a7406d2f..df4530d636c1d8134dc1f126a30e0b0164824f16 100644 (file)
@@ -445,6 +445,32 @@ void wxToolBar::SetWindowStyleFlag( long style )
         GtkSetStyle();
 }
 
+bool wxToolBar::Realize()
+{
+    if ( !wxToolBarBase::Realize() )
+        return false;
+
+    // bring the initial state of all the toolbar items in line with the
+    // internal state if the latter was changed by calling wxToolBarTool::
+    // Enable(): this works under MSW, where the toolbar items are only created
+    // in Realize() which uses the internal state to determine the initial
+    // button state, so make it work under GTK too
+    for ( wxToolBarToolsList::const_iterator i = m_tools.begin();
+          i != m_tools.end();
+          ++i )
+    {
+        // by default the toolbar items are enabled and not toggled, so we only
+        // have to do something if their internal state doesn't correspond to
+        // this
+        if ( !(*i)->IsEnabled() )
+            DoEnableTool(*i, false);
+        if ( (*i)->IsToggled() )
+            DoToggleTool(*i, true);
+    }
+
+    return true;
+}
+
 bool wxToolBar::DoInsertTool(size_t pos, wxToolBarToolBase *toolBase)
 {
     wxToolBarTool* tool = static_cast<wxToolBarTool*>(toolBase);