]> git.saurik.com Git - wxWidgets.git/blobdiff - samples/ribbon/ribbondemo.cpp
Enable wxComboBox::SetString() test in the widgets sample.
[wxWidgets.git] / samples / ribbon / ribbondemo.cpp
index 126c75b51378a35037dd6db713331d7a271189fd..546838ebf07d7b6fc2f0f678ae9eca9e44182f35 100644 (file)
@@ -28,6 +28,7 @@
 #include "wx/colordlg.h"
 #include "wx/artprov.h"
 #include "wx/combobox.h"
+#include "wx/tglbtn.h"
 #include "wx/wrapsizer.h"
 
 // -- application --
@@ -71,8 +72,26 @@ public:
         ID_POSITION_LEFT,
         ID_POSITION_LEFT_LABELS,
         ID_POSITION_LEFT_BOTH,
+        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);
@@ -89,6 +108,8 @@ public:
     void OnDefaultProvider(wxRibbonButtonBarEvent& evt);
     void OnAUIProvider(wxRibbonButtonBarEvent& evt);
     void OnMSWProvider(wxRibbonButtonBarEvent& evt);
+    void OnJustify(wxRibbonToolBarEvent& evt);
+    void OnJustifyUpdateUI(wxUpdateUIEvent& evt);
     void OnNew(wxRibbonToolBarEvent& evt);
     void OnNewDropdown(wxRibbonToolBarEvent& evt);
     void OnPrint(wxRibbonToolBarEvent& evt);
@@ -106,6 +127,8 @@ public:
     void OnPositionLeftBoth(wxCommandEvent& evt);
     void OnPositionLeftDropdown(wxRibbonToolBarEvent& evt);
 
+    void OnTogglePanels(wxCommandEvent& evt);
+
 protected:
     wxRibbonGallery* PopulateColoursPanel(wxWindow* panel, wxColour def,
         int gallery_id);
@@ -122,11 +145,16 @@ protected:
     wxRibbonGallery* m_primary_gallery;
     wxRibbonGallery* m_secondary_gallery;
     wxTextCtrl* m_logwindow;
+    wxToggleButton* m_togglePanels;
+
     wxColourData m_colour_data;
     wxColour m_default_primary;
     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()
 };
@@ -139,13 +167,20 @@ bool MyApp::OnInit()
         return false;
 
     wxFrame* frame = new MyFrame;
-    SetTopWindow(frame);
     frame->Show();
 
     return true;
 }
 
 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)
@@ -162,6 +197,12 @@ EVT_RIBBONGALLERY_HOVER_CHANGED(ID_PRIMARY_COLOUR, MyFrame::OnHoveredColourChang
 EVT_RIBBONGALLERY_HOVER_CHANGED(ID_SECONDARY_COLOUR, MyFrame::OnHoveredColourChange)
 EVT_RIBBONGALLERY_SELECTED(ID_PRIMARY_COLOUR, MyFrame::OnPrimaryColourSelect)
 EVT_RIBBONGALLERY_SELECTED(ID_SECONDARY_COLOUR, MyFrame::OnSecondaryColourSelect)
+EVT_RIBBONTOOLBAR_CLICKED(wxID_JUSTIFY_LEFT, MyFrame::OnJustify)
+EVT_RIBBONTOOLBAR_CLICKED(wxID_JUSTIFY_CENTER, MyFrame::OnJustify)
+EVT_RIBBONTOOLBAR_CLICKED(wxID_JUSTIFY_RIGHT, MyFrame::OnJustify)
+EVT_UPDATE_UI(wxID_JUSTIFY_LEFT, MyFrame::OnJustifyUpdateUI)
+EVT_UPDATE_UI(wxID_JUSTIFY_CENTER, MyFrame::OnJustifyUpdateUI)
+EVT_UPDATE_UI(wxID_JUSTIFY_RIGHT, MyFrame::OnJustifyUpdateUI)
 EVT_RIBBONTOOLBAR_CLICKED(wxID_NEW, MyFrame::OnNew)
 EVT_RIBBONTOOLBAR_DROPDOWN_CLICKED(wxID_NEW, MyFrame::OnNewDropdown)
 EVT_RIBBONTOOLBAR_CLICKED(wxID_PRINT, MyFrame::OnPrint)
@@ -180,6 +221,7 @@ EVT_MENU(ID_POSITION_LEFT_BOTH, MyFrame::OnPositionLeftBoth)
 EVT_MENU(ID_POSITION_TOP, MyFrame::OnPositionTopLabels)
 EVT_MENU(ID_POSITION_TOP_ICONS, MyFrame::OnPositionTopIcons)
 EVT_MENU(ID_POSITION_TOP_BOTH, MyFrame::OnPositionTopBoth)
+EVT_TOGGLEBUTTON(ID_TOGGLE_PANELS, MyFrame::OnTogglePanels)
 END_EVENT_TABLE()
 
 #include "align_center.xpm"
@@ -212,16 +254,21 @@ MyFrame::MyFrame()
 
     {
         wxRibbonPage* home = new wxRibbonPage(m_ribbon, wxID_ANY, wxT("Examples"), ribbon_xpm);
-        wxRibbonPanel *toolbar_panel = new wxRibbonPanel(home, wxID_ANY, wxT("Toolbar"), wxNullBitmap, wxDefaultPosition, wxDefaultSize, wxRIBBON_PANEL_NO_AUTO_MINIMISE);
+        wxRibbonPanel *toolbar_panel = new wxRibbonPanel(home, wxID_ANY, wxT("Toolbar"), 
+                                            wxNullBitmap, wxDefaultPosition, wxDefaultSize, 
+                                            wxRIBBON_PANEL_NO_AUTO_MINIMISE);
         wxRibbonToolBar *toolbar = new wxRibbonToolBar(toolbar_panel, ID_MAIN_TOOLBAR);
-        toolbar->AddTool(wxID_ANY, align_left_xpm);
-        toolbar->AddTool(wxID_ANY, align_center_xpm);
-        toolbar->AddTool(wxID_ANY, align_right_xpm);
+        toolbar->AddToggleTool(wxID_JUSTIFY_LEFT, align_left_xpm);
+        toolbar->AddToggleTool(wxID_JUSTIFY_CENTER , align_center_xpm);
+        toolbar->AddToggleTool(wxID_JUSTIFY_RIGHT, align_right_xpm);
         toolbar->AddSeparator();
         toolbar->AddHybridTool(wxID_NEW, wxArtProvider::GetBitmap(wxART_NEW, wxART_OTHER, wxSize(16, 15)));
-        toolbar->AddTool(wxID_ANY, wxArtProvider::GetBitmap(wxART_FILE_OPEN, wxART_OTHER, wxSize(16, 15)));
-        toolbar->AddTool(wxID_ANY, wxArtProvider::GetBitmap(wxART_FILE_SAVE, wxART_OTHER, wxSize(16, 15)));
-        toolbar->AddTool(wxID_ANY, wxArtProvider::GetBitmap(wxART_FILE_SAVE_AS, wxART_OTHER, wxSize(16, 15)));
+        toolbar->AddTool(wxID_OPEN, wxArtProvider::GetBitmap(wxART_FILE_OPEN, wxART_OTHER, wxSize(16, 15)), "Open something");
+        toolbar->AddTool(wxID_SAVE, wxArtProvider::GetBitmap(wxART_FILE_SAVE, wxART_OTHER, wxSize(16, 15)), "Save something");
+        toolbar->AddTool(wxID_SAVEAS, wxArtProvider::GetBitmap(wxART_FILE_SAVE_AS, wxART_OTHER, wxSize(16, 15)), "Save something as ...");
+        toolbar->EnableTool(wxID_OPEN, false);
+        toolbar->EnableTool(wxID_SAVE, false);
+        toolbar->EnableTool(wxID_SAVEAS, false);
         toolbar->AddSeparator();
         toolbar->AddDropdownTool(wxID_UNDO, wxArtProvider::GetBitmap(wxART_UNDO, wxART_OTHER, wxSize(16, 15)));
         toolbar->AddDropdownTool(wxID_REDO, wxArtProvider::GetBitmap(wxART_REDO, wxART_OTHER, wxSize(16, 15)));
@@ -229,44 +276,60 @@ MyFrame::MyFrame()
         toolbar->AddTool(wxID_ANY, wxArtProvider::GetBitmap(wxART_REPORT_VIEW, wxART_OTHER, wxSize(16, 15)));
         toolbar->AddTool(wxID_ANY, wxArtProvider::GetBitmap(wxART_LIST_VIEW, wxART_OTHER, wxSize(16, 15)));
         toolbar->AddSeparator();
-        toolbar->AddHybridTool(ID_POSITION_LEFT, position_left_xpm);
-        toolbar->AddHybridTool(ID_POSITION_TOP, position_top_xpm);
+        toolbar->AddHybridTool(ID_POSITION_LEFT, position_left_xpm, 
+                                "Align ribbonbar vertically\non the left\nfor demonstration purposes");
+        toolbar->AddHybridTool(ID_POSITION_TOP, position_top_xpm, 
+                                "Align the ribbonbar horizontally\nat the top\nfor demonstration purposes");
         toolbar->AddSeparator();
-        toolbar->AddHybridTool(wxID_PRINT, wxArtProvider::GetBitmap(wxART_PRINT, wxART_OTHER, wxSize(16, 15)));
+        toolbar->AddHybridTool(wxID_PRINT, wxArtProvider::GetBitmap(wxART_PRINT, wxART_OTHER, wxSize(16, 15)),
+                                "This is the Print button tooltip\ndemonstrating a tooltip");
         toolbar->SetRows(2, 3);
 
         wxRibbonPanel *selection_panel = new wxRibbonPanel(home, wxID_ANY, wxT("Selection"), wxBitmap(selection_panel_xpm));
         wxRibbonButtonBar *selection = new wxRibbonButtonBar(selection_panel);
-        selection->AddButton(ID_SELECTION_EXPAND_V, wxT("Expand Vertically"), wxBitmap(expand_selection_v_xpm), wxEmptyString);
+        selection->AddButton(ID_SELECTION_EXPAND_V, wxT("Expand Vertically"), wxBitmap(expand_selection_v_xpm),
+                                "This is a tooltip for Expand Vertically\ndemonstrating a tooltip");
         selection->AddButton(ID_SELECTION_EXPAND_H, wxT("Expand Horizontally"), wxBitmap(expand_selection_h_xpm), wxEmptyString);
         selection->AddButton(ID_SELECTION_CONTRACT, wxT("Contract"), wxBitmap(auto_crop_selection_xpm), wxBitmap(auto_crop_selection_small_xpm));
 
         wxRibbonPanel *shapes_panel = new wxRibbonPanel(home, wxID_ANY, wxT("Shapes"), wxBitmap(circle_small_xpm));
         wxRibbonButtonBar *shapes = new wxRibbonButtonBar(shapes_panel);
-        shapes->AddButton(ID_CIRCLE, wxT("Circle"), wxBitmap(circle_xpm), wxBitmap(circle_small_xpm));
+        shapes->AddButton(ID_CIRCLE, wxT("Circle"), wxBitmap(circle_xpm), wxBitmap(circle_small_xpm), 
+                            wxNullBitmap, wxNullBitmap, wxRIBBON_BUTTON_NORMAL,
+                            "This is a tooltip for the circle button\ndemonstrating another tooltip");
         shapes->AddButton(ID_CROSS, wxT("Cross"), wxBitmap(cross_xpm), wxEmptyString);
         shapes->AddHybridButton(ID_TRIANGLE, wxT("Triangle"), wxBitmap(triangle_xpm));
         shapes->AddButton(ID_SQUARE, wxT("Square"), wxBitmap(square_xpm), wxEmptyString);
         shapes->AddDropdownButton(ID_POLYGON, wxT("Other Polygon"), wxBitmap(hexagon_xpm), wxEmptyString);
 
         wxRibbonPanel *sizer_panel = new wxRibbonPanel(home, wxID_ANY, wxT("Panel with Sizer"), 
-                                        wxNullBitmap, wxDefaultPosition, wxDefaultSize, 
-                                        wxRIBBON_PANEL_EXT_BUTTON);
+                                                    wxNullBitmap, wxDefaultPosition, wxDefaultSize, 
+                                                    wxRIBBON_PANEL_DEFAULT_STYLE);
 
         wxArrayString as;
-        as.Add("Item 1");
-        as.Add("Item 2");
-        wxComboBox* sizer_panelcombo = new wxComboBox(sizer_panel, wxID_ANY, wxEmptyString, 
-                             wxDefaultPosition, wxDefaultSize, as, wxCB_READONLY);
-        wxComboBox* sizer_panelcombo2 = new wxComboBox(sizer_panel, wxID_ANY, wxEmptyString, 
-                             wxDefaultPosition, wxDefaultSize, as, wxCB_READONLY);
-    
+        as.Add("Item 1 using a box sizer now");
+        as.Add("Item 2 using a box sizer now");
+        wxComboBox* sizer_panelcombo = new wxComboBox(sizer_panel, wxID_ANY, 
+                                                    wxEmptyString, 
+                                                    wxDefaultPosition, wxDefaultSize, 
+                                                    as, wxCB_READONLY);
+
+        wxComboBox* sizer_panelcombo2 = new wxComboBox(sizer_panel, wxID_ANY, 
+                                                    wxEmptyString, 
+                                                    wxDefaultPosition, wxDefaultSize, 
+                                                    as, wxCB_READONLY);
+
+        sizer_panelcombo->Select(0);
+        sizer_panelcombo2->Select(1);
         sizer_panelcombo->SetMinSize(wxSize(150, -1));
         sizer_panelcombo2->SetMinSize(wxSize(150, -1));
 
-        wxSizer* sizer_panelsizer = new wxWrapSizer(wxHORIZONTAL);
-        sizer_panelsizer->Add(sizer_panelcombo, 2, wxALL|wxEXPAND, 2);
-        sizer_panelsizer->Add(sizer_panelcombo2, 2, wxALL|wxEXPAND, 2);
+        //not using wxWrapSizer(wxHORIZONTAL) as it reports an incorrect min height
+        wxSizer* sizer_panelsizer = new wxBoxSizer(wxVERTICAL);
+        sizer_panelsizer->AddStretchSpacer(1);
+        sizer_panelsizer->Add(sizer_panelcombo, 0, wxALL|wxEXPAND, 2);
+        sizer_panelsizer->Add(sizer_panelcombo2, 0, wxALL|wxEXPAND, 2);
+        sizer_panelsizer->AddStretchSpacer(1);
         sizer_panel->SetSizer(sizer_panelsizer);
 
         wxFont label_font(8, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_LIGHT);
@@ -291,6 +354,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);
 
@@ -300,10 +386,14 @@ MyFrame::MyFrame()
         wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE | wxTE_READONLY |
         wxTE_LEFT | wxTE_BESTWRAP | wxBORDER_NONE);
 
+    m_togglePanels = new wxToggleButton(this, ID_TOGGLE_PANELS, "&Toggle panels");
+    m_togglePanels->SetValue(true);
+
     wxSizer *s = new wxBoxSizer(wxVERTICAL);
 
     s->Add(m_ribbon, 0, wxEXPAND);
     s->Add(m_logwindow, 1, wxEXPAND);
+    s->Add(m_togglePanels, wxSizerFlags().Border());
 
     SetSizer(s);
 }
@@ -360,7 +450,7 @@ wxRibbonGallery* MyFrame::PopulateColoursPanel(wxWindow* panel,
     else
         gallery = new wxRibbonGallery(panel, gallery_id);
     wxMemoryDC& dc = m_bitmap_creation_dc;
-    wxRibbonGalleryItem *def_item = 
+    wxRibbonGalleryItem *def_item =
         AddColourToGallery(gallery, wxT("Default"), dc, &def);
     gallery->SetSelection(def_item);
     AddColourToGallery(gallery, wxT("BLUE"), dc);
@@ -479,6 +569,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."));
@@ -537,6 +671,40 @@ void MyFrame::OnPolygonDropdown(wxRibbonButtonBarEvent& evt)
     evt.PopupMenu(&menu);
 }
 
+void MyFrame::OnJustify(wxRibbonToolBarEvent& evt)
+{
+    long style = m_logwindow->GetWindowStyle() &
+        ~(wxTE_LEFT | wxTE_CENTER | wxTE_RIGHT);
+    switch(evt.GetId())
+    {
+        case wxID_JUSTIFY_LEFT:
+            m_logwindow->SetWindowStyle(style | wxTE_LEFT);
+            break;
+        case wxID_JUSTIFY_CENTER:
+            m_logwindow->SetWindowStyle(style | wxTE_CENTER);
+            break;
+        case wxID_JUSTIFY_RIGHT:
+            m_logwindow->SetWindowStyle(style | wxTE_RIGHT);
+            break;
+    }
+}
+
+void MyFrame::OnJustifyUpdateUI(wxUpdateUIEvent& evt)
+{
+    switch(evt.GetId())
+    {
+        case wxID_JUSTIFY_LEFT:
+            evt.Check(!m_logwindow->HasFlag(wxTE_CENTER | wxTE_RIGHT));
+            break;
+        case wxID_JUSTIFY_CENTER:
+            evt.Check(m_logwindow->HasFlag(wxTE_CENTER));
+            break;
+        case wxID_JUSTIFY_RIGHT:
+            evt.Check(m_logwindow->HasFlag(wxTE_RIGHT));
+            break;
+    }
+}
+
 void MyFrame::OnNew(wxRibbonToolBarEvent& WXUNUSED(evt))
 {
     AddText(wxT("New button clicked."));
@@ -648,6 +816,11 @@ void MyFrame::OnPositionLeftDropdown(wxRibbonToolBarEvent& evt)
     evt.PopupMenu(&menu);
 }
 
+void MyFrame::OnTogglePanels(wxCommandEvent& WXUNUSED(evt))
+{
+    m_ribbon->ShowPanels(m_togglePanels->GetValue());
+}
+
 void MyFrame::AddText(wxString msg)
 {
     m_logwindow->AppendText(msg);