]> git.saurik.com Git - wxWidgets.git/blobdiff - samples/ribbon/ribbondemo.cpp
eliminate possibility of configure enabling gnomeprint with GTK3
[wxWidgets.git] / samples / ribbon / ribbondemo.cpp
index b158b4df1270aba606f36bdaa8c45bb172457dd2..30bbdd7da2cfb76b2ca6fcfc885add1c67eff90e 100644 (file)
@@ -24,6 +24,7 @@
 #include "wx/ribbon/toolbar.h"
 #include "wx/sizer.h"
 #include "wx/menu.h"
+#include "wx/msgdlg.h"
 #include "wx/dcbuffer.h"
 #include "wx/colordlg.h"
 #include "wx/artprov.h"
@@ -81,7 +82,8 @@ public:
         ID_UI_CHECK_UPDATED,
         ID_CHANGE_TEXT1,
         ID_CHANGE_TEXT2,
-        ID_UI_CHANGE_TEXT_UPDATED
+        ID_UI_CHANGE_TEXT_UPDATED,
+        ID_REMOVE_PAGE
     };
 
     void OnEnableUpdateUI(wxUpdateUIEvent& evt);
@@ -108,6 +110,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);
@@ -124,9 +128,11 @@ public:
     void OnPositionLeftIcons(wxCommandEvent& evt);
     void OnPositionLeftBoth(wxCommandEvent& evt);
     void OnPositionLeftDropdown(wxRibbonToolBarEvent& evt);
-
+    void OnRemovePage(wxRibbonButtonBarEvent& evt);
     void OnTogglePanels(wxCommandEvent& evt);
 
+    void OnExtButton(wxRibbonPanelEvent& evt);
+
 protected:
     wxRibbonGallery* PopulateColoursPanel(wxWindow* panel, wxColour def,
         int gallery_id);
@@ -195,6 +201,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)
@@ -214,6 +226,8 @@ 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)
+EVT_RIBBONPANEL_EXTBUTTON_ACTIVATED(wxID_ANY, MyFrame::OnExtButton)
+EVT_RIBBONBUTTONBAR_CLICKED(ID_REMOVE_PAGE, MyFrame::OnRemovePage)
 END_EVENT_TABLE()
 
 #include "align_center.xpm"
@@ -242,22 +256,29 @@ END_EVENT_TABLE()
 MyFrame::MyFrame()
     : wxFrame(NULL, wxID_ANY, wxT("wxRibbon Sample Application"), wxDefaultPosition, wxSize(800, 600), wxDEFAULT_FRAME_STYLE)
 {
-    m_ribbon = new wxRibbonBar(this, wxID_ANY);
+    m_ribbon = new wxRibbonBar(this, wxID_ANY,
+                               wxDefaultPosition, wxDefaultSize,
+                               wxRIBBON_BAR_DEFAULT_STYLE |
+                               wxRIBBON_BAR_SHOW_PANEL_EXT_BUTTONS);
 
     {
         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);
+                                            wxRIBBON_PANEL_NO_AUTO_MINIMISE |
+                                            wxRIBBON_PANEL_EXT_BUTTON);
         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)));
@@ -367,7 +388,12 @@ MyFrame::MyFrame()
         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);
+    {
+        wxRibbonPage* page = new wxRibbonPage(m_ribbon, wxID_ANY, wxT("Another Page"), empty_xpm);
+        wxRibbonPanel *panel = new wxRibbonPanel(page, wxID_ANY, wxT("Page manipulation"), ribbon_xpm);
+        wxRibbonButtonBar *bar = new wxRibbonButtonBar(panel, wxID_ANY);
+        bar->AddButton(ID_REMOVE_PAGE, wxT("Remove"), wxArtProvider::GetBitmap(wxART_DELETE, wxART_OTHER, wxSize(24, 24)));
+    }
 
     m_ribbon->Realize();
 
@@ -660,6 +686,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."));
@@ -776,6 +836,11 @@ void MyFrame::OnTogglePanels(wxCommandEvent& WXUNUSED(evt))
     m_ribbon->ShowPanels(m_togglePanels->GetValue());
 }
 
+void MyFrame::OnExtButton(wxRibbonPanelEvent& WXUNUSED(evt))
+{
+    wxMessageBox("Extension button clicked");
+}
+
 void MyFrame::AddText(wxString msg)
 {
     m_logwindow->AppendText(msg);
@@ -909,3 +974,13 @@ void MyFrame::SetArtProvider(wxRibbonArtProvider *prov)
     m_ribbon->Thaw();
     GetSizer()->Layout();
 }
+
+void MyFrame::OnRemovePage(wxRibbonButtonBarEvent& WXUNUSED(evt))
+{
+    size_t n = m_ribbon->GetPageCount();
+    if(n > 0)
+    {
+        m_ribbon->DeletePage(n-1);
+        m_ribbon->Realize();
+    }
+}