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