]> git.saurik.com Git - wxWidgets.git/commitdiff
Allow using wxEVT_UPDATE_UI with wxRibbonButtonBar.
authorVadim Zeitlin <vadim@wxwidgets.org>
Thu, 29 Dec 2011 22:05:34 +0000 (22:05 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Thu, 29 Dec 2011 22:05:34 +0000 (22:05 +0000)
Generate wxUpdateUIEvent for the ribbon buttons to allow updating their state
using wxEVT_UPDATE_UI. Also update the same to show this.

Closes #12003.

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

docs/changes.txt
include/wx/ribbon/buttonbar.h
samples/ribbon/ribbondemo.cpp
src/ribbon/buttonbar.cpp

index 94f2001b70bdd8189e00e74296b74c2c4b0f15a4..9a8090e939e2a9a34092a632bc380fdc89758a73 100644 (file)
@@ -461,6 +461,7 @@ All (GUI):
 - Support font-family/style, text-decoration in wxHtmlWindow (Blake Oleander).
 - Show ribbon tools help strings in tooltips (John Roberts).
 - Improve row/column selection modes in wxGrid (joostn).
+- Allow using wxEVT_UPDATE_UI with wxRibbonButtonBar (Emilien Kia).
 
 GTK:
 
index 70985121eaa073eef7c7b332a7f38de11dc66cdb..b662997c4741a6cc4ecd89f05d75c37b6a889295 100644 (file)
@@ -120,6 +120,7 @@ protected:
     static wxBitmap MakeDisabledBitmap(const wxBitmap& original);
     void FetchButtonSizeInfo(wxRibbonButtonBarButtonBase* button,
         wxRibbonButtonBarButtonState size, wxDC& dc);
+    virtual void UpdateWindowUI(long flags);
 
     wxArrayRibbonButtonBarLayout m_layouts;
     wxArrayRibbonButtonBarButtonBase m_buttons;
index 95b7a9dd2b45d7e21b218906f6b37335c8241889..b158b4df1270aba606f36bdaa8c45bb172457dd2 100644 (file)
@@ -72,9 +72,26 @@ public:
         ID_POSITION_LEFT,
         ID_POSITION_LEFT_LABELS,
         ID_POSITION_LEFT_BOTH,
-        ID_TOGGLE_PANELS
+        ID_TOGGLE_PANELS,
+        ID_ENABLE,
+        ID_DISABLE,
+        ID_DISABLED,
+        ID_UI_ENABLE_UPDATED,
+        ID_CHECK,
+        ID_UI_CHECK_UPDATED,
+        ID_CHANGE_TEXT1,
+        ID_CHANGE_TEXT2,
+        ID_UI_CHANGE_TEXT_UPDATED
     };
 
+    void OnEnableUpdateUI(wxUpdateUIEvent& evt);
+    void OnCheckUpdateUI(wxUpdateUIEvent& evt);
+    void OnChangeTextUpdateUI(wxUpdateUIEvent& evt);
+    void OnCheck(wxRibbonButtonBarEvent& evt);
+    void OnEnable(wxRibbonButtonBarEvent& evt);
+    void OnDisable(wxRibbonButtonBarEvent& evt);
+    void OnChangeText1(wxRibbonButtonBarEvent& evt);
+    void OnChangeText2(wxRibbonButtonBarEvent& evt);
     void OnCircleButton(wxRibbonButtonBarEvent& evt);
     void OnCrossButton(wxRibbonButtonBarEvent& evt);
     void OnTriangleButton(wxRibbonButtonBarEvent& evt);
@@ -133,6 +150,9 @@ protected:
     wxColour m_default_secondary;
     wxColour m_default_tertiary;
     wxMemoryDC m_bitmap_creation_dc;
+    bool m_bEnabled;
+    bool m_bChecked;
+    wxString m_new_text;
 
     DECLARE_EVENT_TABLE()
 };
@@ -151,6 +171,14 @@ bool MyApp::OnInit()
 }
 
 BEGIN_EVENT_TABLE(MyFrame, wxFrame)
+EVT_RIBBONBUTTONBAR_CLICKED(ID_ENABLE, MyFrame::OnEnable)
+EVT_RIBBONBUTTONBAR_CLICKED(ID_DISABLE, MyFrame::OnDisable)
+EVT_UPDATE_UI(ID_UI_ENABLE_UPDATED, MyFrame::OnEnableUpdateUI)
+EVT_RIBBONBUTTONBAR_CLICKED(ID_CHECK, MyFrame::OnCheck)
+EVT_UPDATE_UI(ID_UI_CHECK_UPDATED, MyFrame::OnCheckUpdateUI)
+EVT_RIBBONBUTTONBAR_CLICKED(ID_CHANGE_TEXT1, MyFrame::OnChangeText1)
+EVT_RIBBONBUTTONBAR_CLICKED(ID_CHANGE_TEXT2, MyFrame::OnChangeText2)
+EVT_UPDATE_UI(ID_UI_CHANGE_TEXT_UPDATED, MyFrame::OnChangeTextUpdateUI)
 EVT_RIBBONBUTTONBAR_CLICKED(ID_DEFAULT_PROVIDER, MyFrame::OnDefaultProvider)
 EVT_RIBBONBUTTONBAR_CLICKED(ID_AUI_PROVIDER, MyFrame::OnAUIProvider)
 EVT_RIBBONBUTTONBAR_CLICKED(ID_MSW_PROVIDER, MyFrame::OnMSWProvider)
@@ -315,6 +343,29 @@ MyFrame::MyFrame()
         m_secondary_gallery = PopulateColoursPanel(secondary_panel,
             m_default_secondary, ID_SECONDARY_COLOUR);
     }
+    {
+        wxRibbonPage* page = new wxRibbonPage(m_ribbon, wxID_ANY, wxT("UI Updated"), ribbon_xpm);
+        wxRibbonPanel *panel = new wxRibbonPanel(page, wxID_ANY, wxT("Enable/Disable"), ribbon_xpm);
+        wxRibbonButtonBar *bar = new wxRibbonButtonBar(panel, wxID_ANY);
+        bar->AddButton(ID_DISABLED, wxT("Disabled"), ribbon_xpm);
+        bar->AddButton(ID_ENABLE,   wxT("Enable"), ribbon_xpm);
+        bar->AddButton(ID_DISABLE,  wxT("Disable"), ribbon_xpm);
+        bar->AddButton(ID_UI_ENABLE_UPDATED, wxT("Enable UI updated"), ribbon_xpm);
+        bar->EnableButton(ID_DISABLED, false);
+        m_bEnabled = true;
+
+        panel = new wxRibbonPanel(page, wxID_ANY, wxT("Toggle"), ribbon_xpm);
+        bar = new wxRibbonButtonBar(panel, wxID_ANY);
+        bar->AddButton(ID_CHECK, wxT("Toggle"), ribbon_xpm);
+        bar->AddToggleButton(ID_UI_CHECK_UPDATED, wxT("Toggled UI updated"), ribbon_xpm);
+        m_bChecked = true;
+
+        panel = new wxRibbonPanel(page, wxID_ANY, wxT("Change text"), ribbon_xpm);
+        bar = new wxRibbonButtonBar(panel, wxID_ANY);
+        bar->AddButton(ID_CHANGE_TEXT1, wxT("One"), ribbon_xpm);
+        bar->AddButton(ID_CHANGE_TEXT2, wxT("Two"), ribbon_xpm);
+        bar->AddButton(ID_UI_CHANGE_TEXT_UPDATED, wxT("Zero"), ribbon_xpm);
+    }
     new wxRibbonPage(m_ribbon, wxID_ANY, wxT("Empty Page"), empty_xpm);
     new wxRibbonPage(m_ribbon, wxID_ANY, wxT("Another Page"), empty_xpm);
 
@@ -507,6 +558,50 @@ void MyFrame::ResetGalleryArtProviders()
     }
 }
 
+void MyFrame::OnChangeText1(wxRibbonButtonBarEvent& WXUNUSED(evt))
+{
+    m_new_text = wxT("One");
+}
+
+void MyFrame::OnChangeText2(wxRibbonButtonBarEvent& WXUNUSED(evt))
+{
+    m_new_text = wxT("Two");
+}
+
+void MyFrame::OnEnable(wxRibbonButtonBarEvent& WXUNUSED(evt))
+{
+    m_bEnabled = true;
+}
+
+void MyFrame::OnDisable(wxRibbonButtonBarEvent& WXUNUSED(evt))
+{
+    m_bEnabled = false;
+}
+
+void MyFrame::OnCheck(wxRibbonButtonBarEvent& WXUNUSED(evt))
+{
+    m_bChecked = !m_bChecked;
+}
+
+void MyFrame::OnEnableUpdateUI(wxUpdateUIEvent& evt)
+{
+    evt.Enable(m_bEnabled);
+}
+
+void MyFrame::OnCheckUpdateUI(wxUpdateUIEvent& evt)
+{
+    evt.Check(m_bChecked);
+}
+
+void MyFrame::OnChangeTextUpdateUI(wxUpdateUIEvent& evt)
+{
+    if ( !m_new_text.IsEmpty() )
+    {
+        evt.SetText(m_new_text);
+        m_new_text = wxT("");
+    }
+}
+
 void MyFrame::OnSelectionExpandHButton(wxRibbonButtonBarEvent& WXUNUSED(evt))
 {
     AddText(wxT("Expand selection horizontally button clicked."));
index 10680a0c31d7f27ff64b3166cba08c98d639ad17..a9f733e950ae96826b77715b993aa00de44406c3 100644 (file)
@@ -598,6 +598,42 @@ wxSize wxRibbonButtonBar::DoGetNextLargerSize(wxOrientation direction,
     return result;
 }
 
+void wxRibbonButtonBar::UpdateWindowUI(long flags)
+{
+    wxWindowBase::UpdateWindowUI(flags);
+
+    // don't waste time updating state of tools in a hidden toolbar
+    if ( !IsShown() )
+        return;
+
+    size_t btn_count = m_buttons.size();
+    bool rerealize = false;
+    for ( size_t btn_i = 0; btn_i < btn_count; ++btn_i )
+    {
+        wxRibbonButtonBarButtonBase& btn = *m_buttons.Item(btn_i);
+        int id = btn.id;
+
+        wxUpdateUIEvent event(id);
+        event.SetEventObject(this);
+
+        if ( ProcessWindowEvent(event) )
+        {
+            if ( event.GetSetEnabled() )
+                EnableButton(id, event.GetEnabled());
+            if ( event.GetSetChecked() )
+                ToggleButton(id, event.GetChecked());
+            if ( event.GetSetText() )
+            {
+                btn.label = event.GetText();
+                rerealize = true;
+            }
+        }
+    }
+
+    if ( rerealize )
+        Realize();
+}
+
 void wxRibbonButtonBar::OnEraseBackground(wxEraseEvent& WXUNUSED(evt))
 {
     // All painting done in main paint handler to minimise flicker