]> git.saurik.com Git - wxWidgets.git/blob - samples/ribbon/ribbondemo.cpp
eliminate possibility of configure enabling gnomeprint with GTK3
[wxWidgets.git] / samples / ribbon / ribbondemo.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: ribbondemo.cpp
3 // Purpose: wxRibbon: Ribbon user interface - sample/test program
4 // Author: Peter Cawley
5 // Modified by:
6 // Created: 2009-05-25
7 // RCS-ID: $Id$
8 // Copyright: (C) Copyright 2009, Peter Cawley
9 // Licence: wxWindows Library Licence
10 ///////////////////////////////////////////////////////////////////////////////
11
12 #include "wx/wxprec.h"
13
14 #ifdef __BORLANDC__
15 #pragma hdrstop
16 #endif
17
18 #include "wx/app.h"
19 #include "wx/frame.h"
20 #include "wx/textctrl.h"
21 #include "wx/ribbon/bar.h"
22 #include "wx/ribbon/buttonbar.h"
23 #include "wx/ribbon/gallery.h"
24 #include "wx/ribbon/toolbar.h"
25 #include "wx/sizer.h"
26 #include "wx/menu.h"
27 #include "wx/msgdlg.h"
28 #include "wx/dcbuffer.h"
29 #include "wx/colordlg.h"
30 #include "wx/artprov.h"
31 #include "wx/combobox.h"
32 #include "wx/tglbtn.h"
33 #include "wx/wrapsizer.h"
34
35 // -- application --
36
37 class MyApp : public wxApp
38 {
39 public:
40 bool OnInit();
41 };
42
43 DECLARE_APP(MyApp)
44 IMPLEMENT_APP(MyApp)
45
46 // -- frame --
47
48 class MyFrame : public wxFrame
49 {
50 public:
51 MyFrame();
52 ~MyFrame();
53
54 enum
55 {
56 ID_CIRCLE = wxID_HIGHEST + 1,
57 ID_CROSS,
58 ID_TRIANGLE,
59 ID_SQUARE,
60 ID_POLYGON,
61 ID_SELECTION_EXPAND_H,
62 ID_SELECTION_EXPAND_V,
63 ID_SELECTION_CONTRACT,
64 ID_PRIMARY_COLOUR,
65 ID_SECONDARY_COLOUR,
66 ID_DEFAULT_PROVIDER,
67 ID_AUI_PROVIDER,
68 ID_MSW_PROVIDER,
69 ID_MAIN_TOOLBAR,
70 ID_POSITION_TOP,
71 ID_POSITION_TOP_ICONS,
72 ID_POSITION_TOP_BOTH,
73 ID_POSITION_LEFT,
74 ID_POSITION_LEFT_LABELS,
75 ID_POSITION_LEFT_BOTH,
76 ID_TOGGLE_PANELS,
77 ID_ENABLE,
78 ID_DISABLE,
79 ID_DISABLED,
80 ID_UI_ENABLE_UPDATED,
81 ID_CHECK,
82 ID_UI_CHECK_UPDATED,
83 ID_CHANGE_TEXT1,
84 ID_CHANGE_TEXT2,
85 ID_UI_CHANGE_TEXT_UPDATED,
86 ID_REMOVE_PAGE
87 };
88
89 void OnEnableUpdateUI(wxUpdateUIEvent& evt);
90 void OnCheckUpdateUI(wxUpdateUIEvent& evt);
91 void OnChangeTextUpdateUI(wxUpdateUIEvent& evt);
92 void OnCheck(wxRibbonButtonBarEvent& evt);
93 void OnEnable(wxRibbonButtonBarEvent& evt);
94 void OnDisable(wxRibbonButtonBarEvent& evt);
95 void OnChangeText1(wxRibbonButtonBarEvent& evt);
96 void OnChangeText2(wxRibbonButtonBarEvent& evt);
97 void OnCircleButton(wxRibbonButtonBarEvent& evt);
98 void OnCrossButton(wxRibbonButtonBarEvent& evt);
99 void OnTriangleButton(wxRibbonButtonBarEvent& evt);
100 void OnTriangleDropdown(wxRibbonButtonBarEvent& evt);
101 void OnSquareButton(wxRibbonButtonBarEvent& evt);
102 void OnPolygonDropdown(wxRibbonButtonBarEvent& evt);
103 void OnSelectionExpandVButton(wxRibbonButtonBarEvent& evt);
104 void OnSelectionExpandHButton(wxRibbonButtonBarEvent& evt);
105 void OnSelectionContractButton(wxRibbonButtonBarEvent& evt);
106 void OnHoveredColourChange(wxRibbonGalleryEvent& evt);
107 void OnPrimaryColourSelect(wxRibbonGalleryEvent& evt);
108 void OnSecondaryColourSelect(wxRibbonGalleryEvent& evt);
109 void OnColourGalleryButton(wxCommandEvent& evt);
110 void OnDefaultProvider(wxRibbonButtonBarEvent& evt);
111 void OnAUIProvider(wxRibbonButtonBarEvent& evt);
112 void OnMSWProvider(wxRibbonButtonBarEvent& evt);
113 void OnJustify(wxRibbonToolBarEvent& evt);
114 void OnJustifyUpdateUI(wxUpdateUIEvent& evt);
115 void OnNew(wxRibbonToolBarEvent& evt);
116 void OnNewDropdown(wxRibbonToolBarEvent& evt);
117 void OnPrint(wxRibbonToolBarEvent& evt);
118 void OnPrintDropdown(wxRibbonToolBarEvent& evt);
119 void OnRedoDropdown(wxRibbonToolBarEvent& evt);
120 void OnUndoDropdown(wxRibbonToolBarEvent& evt);
121 void OnPositionTop(wxRibbonToolBarEvent& evt);
122 void OnPositionTopLabels(wxCommandEvent& evt);
123 void OnPositionTopIcons(wxCommandEvent& evt);
124 void OnPositionTopBoth(wxCommandEvent& evt);
125 void OnPositionTopDropdown(wxRibbonToolBarEvent& evt);
126 void OnPositionLeft(wxRibbonToolBarEvent& evt);
127 void OnPositionLeftLabels(wxCommandEvent& evt);
128 void OnPositionLeftIcons(wxCommandEvent& evt);
129 void OnPositionLeftBoth(wxCommandEvent& evt);
130 void OnPositionLeftDropdown(wxRibbonToolBarEvent& evt);
131 void OnRemovePage(wxRibbonButtonBarEvent& evt);
132 void OnTogglePanels(wxCommandEvent& evt);
133
134 void OnExtButton(wxRibbonPanelEvent& evt);
135
136 protected:
137 wxRibbonGallery* PopulateColoursPanel(wxWindow* panel, wxColour def,
138 int gallery_id);
139 void AddText(wxString msg);
140 wxRibbonGalleryItem* AddColourToGallery(wxRibbonGallery *gallery,
141 wxString name, wxMemoryDC& dc, wxColour* value = NULL);
142 wxColour GetGalleryColour(wxRibbonGallery *gallery,
143 wxRibbonGalleryItem* item, wxString* name);
144 void ResetGalleryArtProviders();
145 void SetArtProvider(wxRibbonArtProvider* prov);
146 void SetBarStyle(long style);
147
148 wxRibbonBar* m_ribbon;
149 wxRibbonGallery* m_primary_gallery;
150 wxRibbonGallery* m_secondary_gallery;
151 wxTextCtrl* m_logwindow;
152 wxToggleButton* m_togglePanels;
153
154 wxColourData m_colour_data;
155 wxColour m_default_primary;
156 wxColour m_default_secondary;
157 wxColour m_default_tertiary;
158 wxMemoryDC m_bitmap_creation_dc;
159 bool m_bEnabled;
160 bool m_bChecked;
161 wxString m_new_text;
162
163 DECLARE_EVENT_TABLE()
164 };
165
166 // -- implementations --
167
168 bool MyApp::OnInit()
169 {
170 if(!wxApp::OnInit())
171 return false;
172
173 wxFrame* frame = new MyFrame;
174 frame->Show();
175
176 return true;
177 }
178
179 BEGIN_EVENT_TABLE(MyFrame, wxFrame)
180 EVT_RIBBONBUTTONBAR_CLICKED(ID_ENABLE, MyFrame::OnEnable)
181 EVT_RIBBONBUTTONBAR_CLICKED(ID_DISABLE, MyFrame::OnDisable)
182 EVT_UPDATE_UI(ID_UI_ENABLE_UPDATED, MyFrame::OnEnableUpdateUI)
183 EVT_RIBBONBUTTONBAR_CLICKED(ID_CHECK, MyFrame::OnCheck)
184 EVT_UPDATE_UI(ID_UI_CHECK_UPDATED, MyFrame::OnCheckUpdateUI)
185 EVT_RIBBONBUTTONBAR_CLICKED(ID_CHANGE_TEXT1, MyFrame::OnChangeText1)
186 EVT_RIBBONBUTTONBAR_CLICKED(ID_CHANGE_TEXT2, MyFrame::OnChangeText2)
187 EVT_UPDATE_UI(ID_UI_CHANGE_TEXT_UPDATED, MyFrame::OnChangeTextUpdateUI)
188 EVT_RIBBONBUTTONBAR_CLICKED(ID_DEFAULT_PROVIDER, MyFrame::OnDefaultProvider)
189 EVT_RIBBONBUTTONBAR_CLICKED(ID_AUI_PROVIDER, MyFrame::OnAUIProvider)
190 EVT_RIBBONBUTTONBAR_CLICKED(ID_MSW_PROVIDER, MyFrame::OnMSWProvider)
191 EVT_RIBBONBUTTONBAR_CLICKED(ID_SELECTION_EXPAND_H, MyFrame::OnSelectionExpandHButton)
192 EVT_RIBBONBUTTONBAR_CLICKED(ID_SELECTION_EXPAND_V, MyFrame::OnSelectionExpandVButton)
193 EVT_RIBBONBUTTONBAR_CLICKED(ID_SELECTION_CONTRACT, MyFrame::OnSelectionContractButton)
194 EVT_RIBBONBUTTONBAR_CLICKED(ID_CIRCLE, MyFrame::OnCircleButton)
195 EVT_RIBBONBUTTONBAR_CLICKED(ID_CROSS, MyFrame::OnCrossButton)
196 EVT_RIBBONBUTTONBAR_CLICKED(ID_TRIANGLE, MyFrame::OnTriangleButton)
197 EVT_RIBBONBUTTONBAR_CLICKED(ID_SQUARE, MyFrame::OnSquareButton)
198 EVT_RIBBONBUTTONBAR_DROPDOWN_CLICKED(ID_TRIANGLE, MyFrame::OnTriangleDropdown)
199 EVT_RIBBONBUTTONBAR_DROPDOWN_CLICKED(ID_POLYGON, MyFrame::OnPolygonDropdown)
200 EVT_RIBBONGALLERY_HOVER_CHANGED(ID_PRIMARY_COLOUR, MyFrame::OnHoveredColourChange)
201 EVT_RIBBONGALLERY_HOVER_CHANGED(ID_SECONDARY_COLOUR, MyFrame::OnHoveredColourChange)
202 EVT_RIBBONGALLERY_SELECTED(ID_PRIMARY_COLOUR, MyFrame::OnPrimaryColourSelect)
203 EVT_RIBBONGALLERY_SELECTED(ID_SECONDARY_COLOUR, MyFrame::OnSecondaryColourSelect)
204 EVT_RIBBONTOOLBAR_CLICKED(wxID_JUSTIFY_LEFT, MyFrame::OnJustify)
205 EVT_RIBBONTOOLBAR_CLICKED(wxID_JUSTIFY_CENTER, MyFrame::OnJustify)
206 EVT_RIBBONTOOLBAR_CLICKED(wxID_JUSTIFY_RIGHT, MyFrame::OnJustify)
207 EVT_UPDATE_UI(wxID_JUSTIFY_LEFT, MyFrame::OnJustifyUpdateUI)
208 EVT_UPDATE_UI(wxID_JUSTIFY_CENTER, MyFrame::OnJustifyUpdateUI)
209 EVT_UPDATE_UI(wxID_JUSTIFY_RIGHT, MyFrame::OnJustifyUpdateUI)
210 EVT_RIBBONTOOLBAR_CLICKED(wxID_NEW, MyFrame::OnNew)
211 EVT_RIBBONTOOLBAR_DROPDOWN_CLICKED(wxID_NEW, MyFrame::OnNewDropdown)
212 EVT_RIBBONTOOLBAR_CLICKED(wxID_PRINT, MyFrame::OnPrint)
213 EVT_RIBBONTOOLBAR_DROPDOWN_CLICKED(wxID_PRINT, MyFrame::OnPrintDropdown)
214 EVT_RIBBONTOOLBAR_DROPDOWN_CLICKED(wxID_REDO, MyFrame::OnRedoDropdown)
215 EVT_RIBBONTOOLBAR_DROPDOWN_CLICKED(wxID_UNDO, MyFrame::OnUndoDropdown)
216 EVT_RIBBONTOOLBAR_CLICKED(ID_POSITION_LEFT, MyFrame::OnPositionLeft)
217 EVT_RIBBONTOOLBAR_DROPDOWN_CLICKED(ID_POSITION_LEFT, MyFrame::OnPositionLeftDropdown)
218 EVT_RIBBONTOOLBAR_CLICKED(ID_POSITION_TOP, MyFrame::OnPositionTop)
219 EVT_RIBBONTOOLBAR_DROPDOWN_CLICKED(ID_POSITION_TOP, MyFrame::OnPositionTopDropdown)
220 EVT_BUTTON(ID_PRIMARY_COLOUR, MyFrame::OnColourGalleryButton)
221 EVT_BUTTON(ID_SECONDARY_COLOUR, MyFrame::OnColourGalleryButton)
222 EVT_MENU(ID_POSITION_LEFT, MyFrame::OnPositionLeftIcons)
223 EVT_MENU(ID_POSITION_LEFT_LABELS, MyFrame::OnPositionLeftLabels)
224 EVT_MENU(ID_POSITION_LEFT_BOTH, MyFrame::OnPositionLeftBoth)
225 EVT_MENU(ID_POSITION_TOP, MyFrame::OnPositionTopLabels)
226 EVT_MENU(ID_POSITION_TOP_ICONS, MyFrame::OnPositionTopIcons)
227 EVT_MENU(ID_POSITION_TOP_BOTH, MyFrame::OnPositionTopBoth)
228 EVT_TOGGLEBUTTON(ID_TOGGLE_PANELS, MyFrame::OnTogglePanels)
229 EVT_RIBBONPANEL_EXTBUTTON_ACTIVATED(wxID_ANY, MyFrame::OnExtButton)
230 EVT_RIBBONBUTTONBAR_CLICKED(ID_REMOVE_PAGE, MyFrame::OnRemovePage)
231 END_EVENT_TABLE()
232
233 #include "align_center.xpm"
234 #include "align_left.xpm"
235 #include "align_right.xpm"
236 #include "aui_style.xpm"
237 #include "auto_crop_selection.xpm"
238 #include "auto_crop_selection_small.xpm"
239 #include "circle.xpm"
240 #include "circle_small.xpm"
241 #include "colours.xpm"
242 #include "cross.xpm"
243 #include "empty.xpm"
244 #include "expand_selection_v.xpm"
245 #include "expand_selection_h.xpm"
246 #include "eye.xpm"
247 #include "hexagon.xpm"
248 #include "msw_style.xpm"
249 #include "position_left_small.xpm"
250 #include "position_top_small.xpm"
251 #include "ribbon.xpm"
252 #include "selection_panel.xpm"
253 #include "square.xpm"
254 #include "triangle.xpm"
255
256 MyFrame::MyFrame()
257 : wxFrame(NULL, wxID_ANY, wxT("wxRibbon Sample Application"), wxDefaultPosition, wxSize(800, 600), wxDEFAULT_FRAME_STYLE)
258 {
259 m_ribbon = new wxRibbonBar(this, wxID_ANY,
260 wxDefaultPosition, wxDefaultSize,
261 wxRIBBON_BAR_DEFAULT_STYLE |
262 wxRIBBON_BAR_SHOW_PANEL_EXT_BUTTONS);
263
264 {
265 wxRibbonPage* home = new wxRibbonPage(m_ribbon, wxID_ANY, wxT("Examples"), ribbon_xpm);
266 wxRibbonPanel *toolbar_panel = new wxRibbonPanel(home, wxID_ANY, wxT("Toolbar"),
267 wxNullBitmap, wxDefaultPosition, wxDefaultSize,
268 wxRIBBON_PANEL_NO_AUTO_MINIMISE |
269 wxRIBBON_PANEL_EXT_BUTTON);
270 wxRibbonToolBar *toolbar = new wxRibbonToolBar(toolbar_panel, ID_MAIN_TOOLBAR);
271 toolbar->AddToggleTool(wxID_JUSTIFY_LEFT, align_left_xpm);
272 toolbar->AddToggleTool(wxID_JUSTIFY_CENTER , align_center_xpm);
273 toolbar->AddToggleTool(wxID_JUSTIFY_RIGHT, align_right_xpm);
274 toolbar->AddSeparator();
275 toolbar->AddHybridTool(wxID_NEW, wxArtProvider::GetBitmap(wxART_NEW, wxART_OTHER, wxSize(16, 15)));
276 toolbar->AddTool(wxID_OPEN, wxArtProvider::GetBitmap(wxART_FILE_OPEN, wxART_OTHER, wxSize(16, 15)), "Open something");
277 toolbar->AddTool(wxID_SAVE, wxArtProvider::GetBitmap(wxART_FILE_SAVE, wxART_OTHER, wxSize(16, 15)), "Save something");
278 toolbar->AddTool(wxID_SAVEAS, wxArtProvider::GetBitmap(wxART_FILE_SAVE_AS, wxART_OTHER, wxSize(16, 15)), "Save something as ...");
279 toolbar->EnableTool(wxID_OPEN, false);
280 toolbar->EnableTool(wxID_SAVE, false);
281 toolbar->EnableTool(wxID_SAVEAS, false);
282 toolbar->AddSeparator();
283 toolbar->AddDropdownTool(wxID_UNDO, wxArtProvider::GetBitmap(wxART_UNDO, wxART_OTHER, wxSize(16, 15)));
284 toolbar->AddDropdownTool(wxID_REDO, wxArtProvider::GetBitmap(wxART_REDO, wxART_OTHER, wxSize(16, 15)));
285 toolbar->AddSeparator();
286 toolbar->AddTool(wxID_ANY, wxArtProvider::GetBitmap(wxART_REPORT_VIEW, wxART_OTHER, wxSize(16, 15)));
287 toolbar->AddTool(wxID_ANY, wxArtProvider::GetBitmap(wxART_LIST_VIEW, wxART_OTHER, wxSize(16, 15)));
288 toolbar->AddSeparator();
289 toolbar->AddHybridTool(ID_POSITION_LEFT, position_left_xpm,
290 "Align ribbonbar vertically\non the left\nfor demonstration purposes");
291 toolbar->AddHybridTool(ID_POSITION_TOP, position_top_xpm,
292 "Align the ribbonbar horizontally\nat the top\nfor demonstration purposes");
293 toolbar->AddSeparator();
294 toolbar->AddHybridTool(wxID_PRINT, wxArtProvider::GetBitmap(wxART_PRINT, wxART_OTHER, wxSize(16, 15)),
295 "This is the Print button tooltip\ndemonstrating a tooltip");
296 toolbar->SetRows(2, 3);
297
298 wxRibbonPanel *selection_panel = new wxRibbonPanel(home, wxID_ANY, wxT("Selection"), wxBitmap(selection_panel_xpm));
299 wxRibbonButtonBar *selection = new wxRibbonButtonBar(selection_panel);
300 selection->AddButton(ID_SELECTION_EXPAND_V, wxT("Expand Vertically"), wxBitmap(expand_selection_v_xpm),
301 "This is a tooltip for Expand Vertically\ndemonstrating a tooltip");
302 selection->AddButton(ID_SELECTION_EXPAND_H, wxT("Expand Horizontally"), wxBitmap(expand_selection_h_xpm), wxEmptyString);
303 selection->AddButton(ID_SELECTION_CONTRACT, wxT("Contract"), wxBitmap(auto_crop_selection_xpm), wxBitmap(auto_crop_selection_small_xpm));
304
305 wxRibbonPanel *shapes_panel = new wxRibbonPanel(home, wxID_ANY, wxT("Shapes"), wxBitmap(circle_small_xpm));
306 wxRibbonButtonBar *shapes = new wxRibbonButtonBar(shapes_panel);
307 shapes->AddButton(ID_CIRCLE, wxT("Circle"), wxBitmap(circle_xpm), wxBitmap(circle_small_xpm),
308 wxNullBitmap, wxNullBitmap, wxRIBBON_BUTTON_NORMAL,
309 "This is a tooltip for the circle button\ndemonstrating another tooltip");
310 shapes->AddButton(ID_CROSS, wxT("Cross"), wxBitmap(cross_xpm), wxEmptyString);
311 shapes->AddHybridButton(ID_TRIANGLE, wxT("Triangle"), wxBitmap(triangle_xpm));
312 shapes->AddButton(ID_SQUARE, wxT("Square"), wxBitmap(square_xpm), wxEmptyString);
313 shapes->AddDropdownButton(ID_POLYGON, wxT("Other Polygon"), wxBitmap(hexagon_xpm), wxEmptyString);
314
315 wxRibbonPanel *sizer_panel = new wxRibbonPanel(home, wxID_ANY, wxT("Panel with Sizer"),
316 wxNullBitmap, wxDefaultPosition, wxDefaultSize,
317 wxRIBBON_PANEL_DEFAULT_STYLE);
318
319 wxArrayString as;
320 as.Add("Item 1 using a box sizer now");
321 as.Add("Item 2 using a box sizer now");
322 wxComboBox* sizer_panelcombo = new wxComboBox(sizer_panel, wxID_ANY,
323 wxEmptyString,
324 wxDefaultPosition, wxDefaultSize,
325 as, wxCB_READONLY);
326
327 wxComboBox* sizer_panelcombo2 = new wxComboBox(sizer_panel, wxID_ANY,
328 wxEmptyString,
329 wxDefaultPosition, wxDefaultSize,
330 as, wxCB_READONLY);
331
332 sizer_panelcombo->Select(0);
333 sizer_panelcombo2->Select(1);
334 sizer_panelcombo->SetMinSize(wxSize(150, -1));
335 sizer_panelcombo2->SetMinSize(wxSize(150, -1));
336
337 //not using wxWrapSizer(wxHORIZONTAL) as it reports an incorrect min height
338 wxSizer* sizer_panelsizer = new wxBoxSizer(wxVERTICAL);
339 sizer_panelsizer->AddStretchSpacer(1);
340 sizer_panelsizer->Add(sizer_panelcombo, 0, wxALL|wxEXPAND, 2);
341 sizer_panelsizer->Add(sizer_panelcombo2, 0, wxALL|wxEXPAND, 2);
342 sizer_panelsizer->AddStretchSpacer(1);
343 sizer_panel->SetSizer(sizer_panelsizer);
344
345 wxFont label_font(8, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_LIGHT);
346 m_bitmap_creation_dc.SetFont(label_font);
347
348 wxRibbonPage* scheme = new wxRibbonPage(m_ribbon, wxID_ANY, wxT("Appearance"), eye_xpm);
349 m_ribbon->GetArtProvider()->GetColourScheme(&m_default_primary,
350 &m_default_secondary, &m_default_tertiary);
351 wxRibbonPanel *provider_panel = new wxRibbonPanel(scheme, wxID_ANY,
352 wxT("Art"), wxNullBitmap, wxDefaultPosition, wxDefaultSize, wxRIBBON_PANEL_NO_AUTO_MINIMISE);
353 wxRibbonButtonBar *provider_bar = new wxRibbonButtonBar(provider_panel, wxID_ANY);
354 provider_bar->AddButton(ID_DEFAULT_PROVIDER, wxT("Default Provider"),
355 wxArtProvider::GetBitmap(wxART_QUESTION, wxART_OTHER, wxSize(32, 32)));
356 provider_bar->AddButton(ID_AUI_PROVIDER, wxT("AUI Provider"), aui_style_xpm);
357 provider_bar->AddButton(ID_MSW_PROVIDER, wxT("MSW Provider"), msw_style_xpm);
358 wxRibbonPanel *primary_panel = new wxRibbonPanel(scheme, wxID_ANY,
359 wxT("Primary Colour"), colours_xpm);
360 m_primary_gallery = PopulateColoursPanel(primary_panel,
361 m_default_primary, ID_PRIMARY_COLOUR);
362 wxRibbonPanel *secondary_panel = new wxRibbonPanel(scheme, wxID_ANY,
363 wxT("Secondary Colour"), colours_xpm);
364 m_secondary_gallery = PopulateColoursPanel(secondary_panel,
365 m_default_secondary, ID_SECONDARY_COLOUR);
366 }
367 {
368 wxRibbonPage* page = new wxRibbonPage(m_ribbon, wxID_ANY, wxT("UI Updated"), ribbon_xpm);
369 wxRibbonPanel *panel = new wxRibbonPanel(page, wxID_ANY, wxT("Enable/Disable"), ribbon_xpm);
370 wxRibbonButtonBar *bar = new wxRibbonButtonBar(panel, wxID_ANY);
371 bar->AddButton(ID_DISABLED, wxT("Disabled"), ribbon_xpm);
372 bar->AddButton(ID_ENABLE, wxT("Enable"), ribbon_xpm);
373 bar->AddButton(ID_DISABLE, wxT("Disable"), ribbon_xpm);
374 bar->AddButton(ID_UI_ENABLE_UPDATED, wxT("Enable UI updated"), ribbon_xpm);
375 bar->EnableButton(ID_DISABLED, false);
376 m_bEnabled = true;
377
378 panel = new wxRibbonPanel(page, wxID_ANY, wxT("Toggle"), ribbon_xpm);
379 bar = new wxRibbonButtonBar(panel, wxID_ANY);
380 bar->AddButton(ID_CHECK, wxT("Toggle"), ribbon_xpm);
381 bar->AddToggleButton(ID_UI_CHECK_UPDATED, wxT("Toggled UI updated"), ribbon_xpm);
382 m_bChecked = true;
383
384 panel = new wxRibbonPanel(page, wxID_ANY, wxT("Change text"), ribbon_xpm);
385 bar = new wxRibbonButtonBar(panel, wxID_ANY);
386 bar->AddButton(ID_CHANGE_TEXT1, wxT("One"), ribbon_xpm);
387 bar->AddButton(ID_CHANGE_TEXT2, wxT("Two"), ribbon_xpm);
388 bar->AddButton(ID_UI_CHANGE_TEXT_UPDATED, wxT("Zero"), ribbon_xpm);
389 }
390 new wxRibbonPage(m_ribbon, wxID_ANY, wxT("Empty Page"), empty_xpm);
391 {
392 wxRibbonPage* page = new wxRibbonPage(m_ribbon, wxID_ANY, wxT("Another Page"), empty_xpm);
393 wxRibbonPanel *panel = new wxRibbonPanel(page, wxID_ANY, wxT("Page manipulation"), ribbon_xpm);
394 wxRibbonButtonBar *bar = new wxRibbonButtonBar(panel, wxID_ANY);
395 bar->AddButton(ID_REMOVE_PAGE, wxT("Remove"), wxArtProvider::GetBitmap(wxART_DELETE, wxART_OTHER, wxSize(24, 24)));
396 }
397
398 m_ribbon->Realize();
399
400 m_logwindow = new wxTextCtrl(this, wxID_ANY, wxEmptyString,
401 wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE | wxTE_READONLY |
402 wxTE_LEFT | wxTE_BESTWRAP | wxBORDER_NONE);
403
404 m_togglePanels = new wxToggleButton(this, ID_TOGGLE_PANELS, "&Toggle panels");
405 m_togglePanels->SetValue(true);
406
407 wxSizer *s = new wxBoxSizer(wxVERTICAL);
408
409 s->Add(m_ribbon, 0, wxEXPAND);
410 s->Add(m_logwindow, 1, wxEXPAND);
411 s->Add(m_togglePanels, wxSizerFlags().Border());
412
413 SetSizer(s);
414 }
415
416 void MyFrame::SetBarStyle(long style)
417 {
418 m_ribbon->Freeze();
419 m_ribbon->SetWindowStyleFlag(style);
420 wxBoxSizer *pTopSize = reinterpret_cast<wxBoxSizer*>(GetSizer());
421 wxRibbonToolBar *pToolbar = wxDynamicCast(FindWindow(ID_MAIN_TOOLBAR), wxRibbonToolBar);
422 if(style & wxRIBBON_BAR_FLOW_VERTICAL)
423 {
424 m_ribbon->SetTabCtrlMargins(10, 10);
425 pTopSize->SetOrientation(wxHORIZONTAL);
426 if(pToolbar)
427 pToolbar->SetRows(3, 5);
428 }
429 else
430 {
431 m_ribbon->SetTabCtrlMargins(50, 20);
432 pTopSize->SetOrientation(wxVERTICAL);
433 if(pToolbar)
434 pToolbar->SetRows(2, 3);
435 }
436 m_ribbon->Realise();
437 Layout();
438 m_ribbon->Thaw();
439 }
440
441 MyFrame::~MyFrame()
442 {
443 }
444
445 class ColourClientData : public wxClientData
446 {
447 public:
448 ColourClientData(const wxString& name, const wxColour& colour)
449 : m_name(name), m_colour(colour) {}
450
451 const wxString& GetName() const {return m_name;}
452 const wxColour& GetColour() const {return m_colour;}
453
454 private:
455 wxString m_name;
456 wxColour m_colour;
457 };
458
459 wxRibbonGallery* MyFrame::PopulateColoursPanel(wxWindow* panel,
460 wxColour def, int gallery_id)
461 {
462 wxRibbonGallery *gallery = wxDynamicCast(panel->FindWindow(gallery_id), wxRibbonGallery);
463 if(gallery)
464 gallery->Clear();
465 else
466 gallery = new wxRibbonGallery(panel, gallery_id);
467 wxMemoryDC& dc = m_bitmap_creation_dc;
468 wxRibbonGalleryItem *def_item =
469 AddColourToGallery(gallery, wxT("Default"), dc, &def);
470 gallery->SetSelection(def_item);
471 AddColourToGallery(gallery, wxT("BLUE"), dc);
472 AddColourToGallery(gallery, wxT("BLUE VIOLET"), dc);
473 AddColourToGallery(gallery, wxT("BROWN"), dc);
474 AddColourToGallery(gallery, wxT("CADET BLUE"), dc);
475 AddColourToGallery(gallery, wxT("CORAL"), dc);
476 AddColourToGallery(gallery, wxT("CYAN"), dc);
477 AddColourToGallery(gallery, wxT("DARK GREEN"), dc);
478 AddColourToGallery(gallery, wxT("DARK ORCHID"), dc);
479 AddColourToGallery(gallery, wxT("FIREBRICK"), dc);
480 AddColourToGallery(gallery, wxT("GOLD"), dc);
481 AddColourToGallery(gallery, wxT("GOLDENROD"), dc);
482 AddColourToGallery(gallery, wxT("GREEN"), dc);
483 AddColourToGallery(gallery, wxT("INDIAN RED"), dc);
484 AddColourToGallery(gallery, wxT("KHAKI"), dc);
485 AddColourToGallery(gallery, wxT("LIGHT BLUE"), dc);
486 AddColourToGallery(gallery, wxT("LIME GREEN"), dc);
487 AddColourToGallery(gallery, wxT("MAGENTA"), dc);
488 AddColourToGallery(gallery, wxT("MAROON"), dc);
489 AddColourToGallery(gallery, wxT("NAVY"), dc);
490 AddColourToGallery(gallery, wxT("ORANGE"), dc);
491 AddColourToGallery(gallery, wxT("ORCHID"), dc);
492 AddColourToGallery(gallery, wxT("PINK"), dc);
493 AddColourToGallery(gallery, wxT("PLUM"), dc);
494 AddColourToGallery(gallery, wxT("PURPLE"), dc);
495 AddColourToGallery(gallery, wxT("RED"), dc);
496 AddColourToGallery(gallery, wxT("SALMON"), dc);
497 AddColourToGallery(gallery, wxT("SEA GREEN"), dc);
498 AddColourToGallery(gallery, wxT("SIENNA"), dc);
499 AddColourToGallery(gallery, wxT("SKY BLUE"), dc);
500 AddColourToGallery(gallery, wxT("TAN"), dc);
501 AddColourToGallery(gallery, wxT("THISTLE"), dc);
502 AddColourToGallery(gallery, wxT("TURQUOISE"), dc);
503 AddColourToGallery(gallery, wxT("VIOLET"), dc);
504 AddColourToGallery(gallery, wxT("VIOLET RED"), dc);
505 AddColourToGallery(gallery, wxT("WHEAT"), dc);
506 AddColourToGallery(gallery, wxT("WHITE"), dc);
507 AddColourToGallery(gallery, wxT("YELLOW"), dc);
508
509 return gallery;
510 }
511
512 wxColour MyFrame::GetGalleryColour(wxRibbonGallery *gallery,
513 wxRibbonGalleryItem* item, wxString* name)
514 {
515 ColourClientData *data = (ColourClientData*)gallery->GetItemClientObject(item);
516 if(name != NULL)
517 *name = data->GetName();
518 return data->GetColour();
519 }
520
521 void MyFrame::OnHoveredColourChange(wxRibbonGalleryEvent& evt)
522 {
523 // Set the background of the gallery to the hovered colour, or back to the
524 // default if there is no longer a hovered item.
525
526 wxRibbonGallery *gallery = evt.GetGallery();
527 wxRibbonArtProvider *provider = gallery->GetArtProvider();
528
529 if(evt.GetGalleryItem() != NULL)
530 {
531 if(provider == m_ribbon->GetArtProvider())
532 {
533 provider = provider->Clone();
534 gallery->SetArtProvider(provider);
535 }
536 provider->SetColour(wxRIBBON_ART_GALLERY_HOVER_BACKGROUND_COLOUR,
537 GetGalleryColour(evt.GetGallery(), evt.GetGalleryItem(), NULL));
538 }
539 else
540 {
541 if(provider != m_ribbon->GetArtProvider())
542 {
543 gallery->SetArtProvider(m_ribbon->GetArtProvider());
544 delete provider;
545 }
546 }
547 }
548
549 void MyFrame::OnPrimaryColourSelect(wxRibbonGalleryEvent& evt)
550 {
551 wxString name;
552 wxColour colour = GetGalleryColour(evt.GetGallery(), evt.GetGalleryItem(), &name);
553 AddText(wxT("Colour \"") + name + wxT("\" selected as primary."));
554 wxColour secondary, tertiary;
555 m_ribbon->GetArtProvider()->GetColourScheme(NULL, &secondary, &tertiary);
556 m_ribbon->GetArtProvider()->SetColourScheme(colour, secondary, tertiary);
557 ResetGalleryArtProviders();
558 m_ribbon->Refresh();
559 }
560
561 void MyFrame::OnSecondaryColourSelect(wxRibbonGalleryEvent& evt)
562 {
563 wxString name;
564 wxColour colour = GetGalleryColour(evt.GetGallery(), evt.GetGalleryItem(), &name);
565 AddText(wxT("Colour \"") + name + wxT("\" selected as secondary."));
566 wxColour primary, tertiary;
567 m_ribbon->GetArtProvider()->GetColourScheme(&primary, NULL, &tertiary);
568 m_ribbon->GetArtProvider()->SetColourScheme(primary, colour, tertiary);
569 ResetGalleryArtProviders();
570 m_ribbon->Refresh();
571 }
572
573 void MyFrame::ResetGalleryArtProviders()
574 {
575 if(m_primary_gallery->GetArtProvider() != m_ribbon->GetArtProvider())
576 {
577 delete m_primary_gallery->GetArtProvider();
578 m_primary_gallery->SetArtProvider(m_ribbon->GetArtProvider());
579 }
580 if(m_secondary_gallery->GetArtProvider() != m_ribbon->GetArtProvider())
581 {
582 delete m_secondary_gallery->GetArtProvider();
583 m_secondary_gallery->SetArtProvider(m_ribbon->GetArtProvider());
584 }
585 }
586
587 void MyFrame::OnChangeText1(wxRibbonButtonBarEvent& WXUNUSED(evt))
588 {
589 m_new_text = wxT("One");
590 }
591
592 void MyFrame::OnChangeText2(wxRibbonButtonBarEvent& WXUNUSED(evt))
593 {
594 m_new_text = wxT("Two");
595 }
596
597 void MyFrame::OnEnable(wxRibbonButtonBarEvent& WXUNUSED(evt))
598 {
599 m_bEnabled = true;
600 }
601
602 void MyFrame::OnDisable(wxRibbonButtonBarEvent& WXUNUSED(evt))
603 {
604 m_bEnabled = false;
605 }
606
607 void MyFrame::OnCheck(wxRibbonButtonBarEvent& WXUNUSED(evt))
608 {
609 m_bChecked = !m_bChecked;
610 }
611
612 void MyFrame::OnEnableUpdateUI(wxUpdateUIEvent& evt)
613 {
614 evt.Enable(m_bEnabled);
615 }
616
617 void MyFrame::OnCheckUpdateUI(wxUpdateUIEvent& evt)
618 {
619 evt.Check(m_bChecked);
620 }
621
622 void MyFrame::OnChangeTextUpdateUI(wxUpdateUIEvent& evt)
623 {
624 if ( !m_new_text.IsEmpty() )
625 {
626 evt.SetText(m_new_text);
627 m_new_text = wxT("");
628 }
629 }
630
631 void MyFrame::OnSelectionExpandHButton(wxRibbonButtonBarEvent& WXUNUSED(evt))
632 {
633 AddText(wxT("Expand selection horizontally button clicked."));
634 }
635
636 void MyFrame::OnSelectionExpandVButton(wxRibbonButtonBarEvent& WXUNUSED(evt))
637 {
638 AddText(wxT("Expand selection vertically button clicked."));
639 }
640
641 void MyFrame::OnSelectionContractButton(wxRibbonButtonBarEvent& WXUNUSED(evt))
642 {
643 AddText(wxT("Contract selection button clicked."));
644 }
645
646 void MyFrame::OnCircleButton(wxRibbonButtonBarEvent& WXUNUSED(evt))
647 {
648 AddText(wxT("Circle button clicked."));
649 }
650
651 void MyFrame::OnCrossButton(wxRibbonButtonBarEvent& WXUNUSED(evt))
652 {
653 AddText(wxT("Cross button clicked."));
654 }
655
656 void MyFrame::OnTriangleButton(wxRibbonButtonBarEvent& WXUNUSED(evt))
657 {
658 AddText(wxT("Triangle button clicked."));
659 }
660
661 void MyFrame::OnTriangleDropdown(wxRibbonButtonBarEvent& evt)
662 {
663 wxMenu menu;
664 menu.Append(wxID_ANY, wxT("Equilateral"));
665 menu.Append(wxID_ANY, wxT("Isosceles"));
666 menu.Append(wxID_ANY, wxT("Scalene"));
667
668 evt.PopupMenu(&menu);
669 }
670
671 void MyFrame::OnSquareButton(wxRibbonButtonBarEvent& WXUNUSED(evt))
672 {
673 AddText(wxT("Square button clicked."));
674 }
675
676 void MyFrame::OnPolygonDropdown(wxRibbonButtonBarEvent& evt)
677 {
678 wxMenu menu;
679 menu.Append(wxID_ANY, wxT("Pentagon (5 sided)"));
680 menu.Append(wxID_ANY, wxT("Hexagon (6 sided)"));
681 menu.Append(wxID_ANY, wxT("Heptagon (7 sided)"));
682 menu.Append(wxID_ANY, wxT("Octogon (8 sided)"));
683 menu.Append(wxID_ANY, wxT("Nonagon (9 sided)"));
684 menu.Append(wxID_ANY, wxT("Decagon (10 sided)"));
685
686 evt.PopupMenu(&menu);
687 }
688
689 void MyFrame::OnJustify(wxRibbonToolBarEvent& evt)
690 {
691 long style = m_logwindow->GetWindowStyle() &
692 ~(wxTE_LEFT | wxTE_CENTER | wxTE_RIGHT);
693 switch(evt.GetId())
694 {
695 case wxID_JUSTIFY_LEFT:
696 m_logwindow->SetWindowStyle(style | wxTE_LEFT);
697 break;
698 case wxID_JUSTIFY_CENTER:
699 m_logwindow->SetWindowStyle(style | wxTE_CENTER);
700 break;
701 case wxID_JUSTIFY_RIGHT:
702 m_logwindow->SetWindowStyle(style | wxTE_RIGHT);
703 break;
704 }
705 }
706
707 void MyFrame::OnJustifyUpdateUI(wxUpdateUIEvent& evt)
708 {
709 switch(evt.GetId())
710 {
711 case wxID_JUSTIFY_LEFT:
712 evt.Check(!m_logwindow->HasFlag(wxTE_CENTER | wxTE_RIGHT));
713 break;
714 case wxID_JUSTIFY_CENTER:
715 evt.Check(m_logwindow->HasFlag(wxTE_CENTER));
716 break;
717 case wxID_JUSTIFY_RIGHT:
718 evt.Check(m_logwindow->HasFlag(wxTE_RIGHT));
719 break;
720 }
721 }
722
723 void MyFrame::OnNew(wxRibbonToolBarEvent& WXUNUSED(evt))
724 {
725 AddText(wxT("New button clicked."));
726 }
727
728 void MyFrame::OnNewDropdown(wxRibbonToolBarEvent& evt)
729 {
730 wxMenu menu;
731 menu.Append(wxID_ANY, wxT("New Document"));
732 menu.Append(wxID_ANY, wxT("New Template"));
733 menu.Append(wxID_ANY, wxT("New Mail"));
734
735 evt.PopupMenu(&menu);
736 }
737
738 void MyFrame::OnPrint(wxRibbonToolBarEvent& WXUNUSED(evt))
739 {
740 AddText(wxT("Print button clicked."));
741 }
742
743 void MyFrame::OnPrintDropdown(wxRibbonToolBarEvent& evt)
744 {
745 wxMenu menu;
746 menu.Append(wxID_ANY, wxT("Print"));
747 menu.Append(wxID_ANY, wxT("Preview"));
748 menu.Append(wxID_ANY, wxT("Options"));
749
750 evt.PopupMenu(&menu);
751 }
752
753 void MyFrame::OnRedoDropdown(wxRibbonToolBarEvent& evt)
754 {
755 wxMenu menu;
756 menu.Append(wxID_ANY, wxT("Redo E"));
757 menu.Append(wxID_ANY, wxT("Redo F"));
758 menu.Append(wxID_ANY, wxT("Redo G"));
759
760 evt.PopupMenu(&menu);
761 }
762
763 void MyFrame::OnUndoDropdown(wxRibbonToolBarEvent& evt)
764 {
765 wxMenu menu;
766 menu.Append(wxID_ANY, wxT("Undo C"));
767 menu.Append(wxID_ANY, wxT("Undo B"));
768 menu.Append(wxID_ANY, wxT("Undo A"));
769
770 evt.PopupMenu(&menu);
771 }
772
773 void MyFrame::OnPositionTopLabels(wxCommandEvent& WXUNUSED(evt))
774 {
775 SetBarStyle(wxRIBBON_BAR_DEFAULT_STYLE);
776 }
777
778 void MyFrame::OnPositionTopIcons(wxCommandEvent& WXUNUSED(evt))
779 {
780 SetBarStyle((wxRIBBON_BAR_DEFAULT_STYLE &~wxRIBBON_BAR_SHOW_PAGE_LABELS)
781 | wxRIBBON_BAR_SHOW_PAGE_ICONS);
782 }
783
784 void MyFrame::OnPositionTopBoth(wxCommandEvent& WXUNUSED(evt))
785 {
786 SetBarStyle(wxRIBBON_BAR_DEFAULT_STYLE | wxRIBBON_BAR_SHOW_PAGE_ICONS);
787 }
788
789 void MyFrame::OnPositionLeftLabels(wxCommandEvent& WXUNUSED(evt))
790 {
791 SetBarStyle(wxRIBBON_BAR_DEFAULT_STYLE | wxRIBBON_BAR_FLOW_VERTICAL);
792 }
793
794 void MyFrame::OnPositionLeftIcons(wxCommandEvent& WXUNUSED(evt))
795 {
796 SetBarStyle((wxRIBBON_BAR_DEFAULT_STYLE &~wxRIBBON_BAR_SHOW_PAGE_LABELS) |
797 wxRIBBON_BAR_SHOW_PAGE_ICONS | wxRIBBON_BAR_FLOW_VERTICAL);
798 }
799
800 void MyFrame::OnPositionLeftBoth(wxCommandEvent& WXUNUSED(evt))
801 {
802 SetBarStyle(wxRIBBON_BAR_DEFAULT_STYLE | wxRIBBON_BAR_SHOW_PAGE_ICONS |
803 wxRIBBON_BAR_FLOW_VERTICAL);
804 }
805
806 void MyFrame::OnPositionTop(wxRibbonToolBarEvent& evt)
807 {
808 OnPositionTopLabels(evt);
809 }
810
811 void MyFrame::OnPositionTopDropdown(wxRibbonToolBarEvent& evt)
812 {
813 wxMenu menu;
814 menu.Append(ID_POSITION_TOP, wxT("Top with Labels"));
815 menu.Append(ID_POSITION_TOP_ICONS, wxT("Top with Icons"));
816 menu.Append(ID_POSITION_TOP_BOTH, wxT("Top with Both"));
817 evt.PopupMenu(&menu);
818 }
819
820 void MyFrame::OnPositionLeft(wxRibbonToolBarEvent& evt)
821 {
822 OnPositionLeftIcons(evt);
823 }
824
825 void MyFrame::OnPositionLeftDropdown(wxRibbonToolBarEvent& evt)
826 {
827 wxMenu menu;
828 menu.Append(ID_POSITION_LEFT, wxT("Left with Icons"));
829 menu.Append(ID_POSITION_LEFT_LABELS, wxT("Left with Labels"));
830 menu.Append(ID_POSITION_LEFT_BOTH, wxT("Left with Both"));
831 evt.PopupMenu(&menu);
832 }
833
834 void MyFrame::OnTogglePanels(wxCommandEvent& WXUNUSED(evt))
835 {
836 m_ribbon->ShowPanels(m_togglePanels->GetValue());
837 }
838
839 void MyFrame::OnExtButton(wxRibbonPanelEvent& WXUNUSED(evt))
840 {
841 wxMessageBox("Extension button clicked");
842 }
843
844 void MyFrame::AddText(wxString msg)
845 {
846 m_logwindow->AppendText(msg);
847 m_logwindow->AppendText(wxT("\n"));
848 m_ribbon->DismissExpandedPanel();
849 }
850
851 wxRibbonGalleryItem* MyFrame::AddColourToGallery(wxRibbonGallery *gallery,
852 wxString colour, wxMemoryDC& dc,
853 wxColour* value)
854 {
855 wxRibbonGalleryItem* item = NULL;
856 wxColour c;
857 if (colour != wxT("Default"))
858 c = wxColour(colour);
859 if (!c.IsOk())
860 c = *value;
861 if(c.IsOk())
862 {
863 const int iWidth = 64;
864 const int iHeight = 40;
865
866 wxBitmap bitmap(iWidth, iHeight);
867 dc.SelectObject(bitmap);
868 wxBrush b(c);
869 dc.SetPen(*wxBLACK_PEN);
870 dc.SetBrush(b);
871 dc.DrawRectangle(0, 0, iWidth, iHeight);
872
873 colour = colour.Mid(0, 1) + colour.Mid(1).Lower();
874 wxSize size = dc.GetTextExtent(colour);
875 wxColour foreground = wxColour(~c.Red(), ~c.Green(), ~c.Blue());
876 if(abs(foreground.Red() - c.Red()) + abs(foreground.Blue() - c.Blue())
877 + abs(foreground.Green() - c.Green()) < 64)
878 {
879 // Foreground too similar to background - use a different
880 // strategy to find a contrasting colour
881 foreground = wxColour((c.Red() + 64) % 256, 255 - c.Green(),
882 (c.Blue() + 192) % 256);
883 }
884 dc.SetTextForeground(foreground);
885 dc.DrawText(colour, (iWidth - size.GetWidth() + 1) / 2,
886 (iHeight - size.GetHeight()) / 2);
887 dc.SelectObjectAsSource(wxNullBitmap);
888
889 item = gallery->Append(bitmap, wxID_ANY);
890 gallery->SetItemClientObject(item, new ColourClientData(colour, c));
891 }
892 return item;
893 }
894
895 void MyFrame::OnColourGalleryButton(wxCommandEvent& evt)
896 {
897 wxRibbonGallery *gallery = wxDynamicCast(evt.GetEventObject(), wxRibbonGallery);
898 if(gallery == NULL)
899 return;
900
901 m_ribbon->DismissExpandedPanel();
902 if(gallery->GetSelection())
903 m_colour_data.SetColour(GetGalleryColour(gallery, gallery->GetSelection(), NULL));
904 wxColourDialog dlg(this, &m_colour_data);
905 if(dlg.ShowModal() == wxID_OK)
906 {
907 m_colour_data = dlg.GetColourData();
908 wxColour clr = m_colour_data.GetColour();
909
910 // Try to find colour in gallery
911 wxRibbonGalleryItem *item = NULL;
912 for(unsigned int i = 0; i < gallery->GetCount(); ++i)
913 {
914 item = gallery->GetItem(i);
915 if(GetGalleryColour(gallery, item, NULL) == clr)
916 break;
917 else
918 item = NULL;
919 }
920
921 // Colour not in gallery - add it
922 if(item == NULL)
923 {
924 item = AddColourToGallery(gallery,
925 clr.GetAsString(wxC2S_HTML_SYNTAX), m_bitmap_creation_dc,
926 &clr);
927 gallery->Realise();
928 }
929
930 // Set selection
931 gallery->EnsureVisible(item);
932 gallery->SetSelection(item);
933
934 // Send an event to respond to the selection change
935 wxRibbonGalleryEvent dummy(wxEVT_COMMAND_RIBBONGALLERY_SELECTED, gallery->GetId());
936 dummy.SetEventObject(gallery);
937 dummy.SetGallery(gallery);
938 dummy.SetGalleryItem(item);
939 ProcessWindowEvent(dummy);
940 }
941 }
942
943 void MyFrame::OnDefaultProvider(wxRibbonButtonBarEvent& WXUNUSED(evt))
944 {
945 m_ribbon->DismissExpandedPanel();
946 SetArtProvider(new wxRibbonDefaultArtProvider);
947 }
948
949 void MyFrame::OnAUIProvider(wxRibbonButtonBarEvent& WXUNUSED(evt))
950 {
951 m_ribbon->DismissExpandedPanel();
952 SetArtProvider(new wxRibbonAUIArtProvider);
953 }
954
955 void MyFrame::OnMSWProvider(wxRibbonButtonBarEvent& WXUNUSED(evt))
956 {
957 m_ribbon->DismissExpandedPanel();
958 SetArtProvider(new wxRibbonMSWArtProvider);
959 }
960
961 void MyFrame::SetArtProvider(wxRibbonArtProvider *prov)
962 {
963 m_ribbon->Freeze();
964 m_ribbon->SetArtProvider(prov);
965
966 prov->GetColourScheme(&m_default_primary, &m_default_secondary,
967 &m_default_tertiary);
968 PopulateColoursPanel(m_primary_gallery->GetParent(), m_default_primary,
969 ID_PRIMARY_COLOUR);
970 PopulateColoursPanel(m_secondary_gallery->GetParent(), m_default_secondary,
971 ID_SECONDARY_COLOUR);
972
973 m_ribbon->Realize();
974 m_ribbon->Thaw();
975 GetSizer()->Layout();
976 }
977
978 void MyFrame::OnRemovePage(wxRibbonButtonBarEvent& WXUNUSED(evt))
979 {
980 size_t n = m_ribbon->GetPageCount();
981 if(n > 0)
982 {
983 m_ribbon->DeletePage(n-1);
984 m_ribbon->Realize();
985 }
986 }