]> git.saurik.com Git - wxWidgets.git/blob - samples/ribbon/ribbondemo.cpp
Add --disable-gui and --disable-all-features builds to the ravnsgaard buildbot.
[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/dcbuffer.h"
28 #include "wx/colordlg.h"
29 #include "wx/artprov.h"
30
31 // -- application --
32
33 class MyApp : public wxApp
34 {
35 public:
36 bool OnInit();
37 };
38
39 DECLARE_APP(MyApp)
40 IMPLEMENT_APP(MyApp)
41
42 // -- frame --
43
44 class MyFrame : public wxFrame
45 {
46 public:
47 MyFrame();
48 ~MyFrame();
49
50 enum
51 {
52 ID_CIRCLE = wxID_HIGHEST + 1,
53 ID_CROSS,
54 ID_TRIANGLE,
55 ID_SQUARE,
56 ID_POLYGON,
57 ID_SELECTION_EXPAND_H,
58 ID_SELECTION_EXPAND_V,
59 ID_SELECTION_CONTRACT,
60 ID_PRIMARY_COLOUR,
61 ID_SECONDARY_COLOUR,
62 ID_DEFAULT_PROVIDER,
63 ID_AUI_PROVIDER,
64 ID_MSW_PROVIDER,
65 ID_MAIN_TOOLBAR,
66 ID_POSITION_TOP,
67 ID_POSITION_TOP_ICONS,
68 ID_POSITION_TOP_BOTH,
69 ID_POSITION_LEFT,
70 ID_POSITION_LEFT_LABELS,
71 ID_POSITION_LEFT_BOTH,
72 };
73
74 void OnCircleButton(wxRibbonButtonBarEvent& evt);
75 void OnCrossButton(wxRibbonButtonBarEvent& evt);
76 void OnTriangleButton(wxRibbonButtonBarEvent& evt);
77 void OnTriangleDropdown(wxRibbonButtonBarEvent& evt);
78 void OnSquareButton(wxRibbonButtonBarEvent& evt);
79 void OnPolygonDropdown(wxRibbonButtonBarEvent& evt);
80 void OnSelectionExpandVButton(wxRibbonButtonBarEvent& evt);
81 void OnSelectionExpandHButton(wxRibbonButtonBarEvent& evt);
82 void OnSelectionContractButton(wxRibbonButtonBarEvent& evt);
83 void OnHoveredColourChange(wxRibbonGalleryEvent& evt);
84 void OnPrimaryColourSelect(wxRibbonGalleryEvent& evt);
85 void OnSecondaryColourSelect(wxRibbonGalleryEvent& evt);
86 void OnColourGalleryButton(wxCommandEvent& evt);
87 void OnDefaultProvider(wxRibbonButtonBarEvent& evt);
88 void OnAUIProvider(wxRibbonButtonBarEvent& evt);
89 void OnMSWProvider(wxRibbonButtonBarEvent& evt);
90 void OnNew(wxRibbonToolBarEvent& evt);
91 void OnNewDropdown(wxRibbonToolBarEvent& evt);
92 void OnPrint(wxRibbonToolBarEvent& evt);
93 void OnPrintDropdown(wxRibbonToolBarEvent& evt);
94 void OnRedoDropdown(wxRibbonToolBarEvent& evt);
95 void OnUndoDropdown(wxRibbonToolBarEvent& evt);
96 void OnPositionTop(wxRibbonToolBarEvent& evt);
97 void OnPositionTopLabels(wxCommandEvent& evt);
98 void OnPositionTopIcons(wxCommandEvent& evt);
99 void OnPositionTopBoth(wxCommandEvent& evt);
100 void OnPositionTopDropdown(wxRibbonToolBarEvent& evt);
101 void OnPositionLeft(wxRibbonToolBarEvent& evt);
102 void OnPositionLeftLabels(wxCommandEvent& evt);
103 void OnPositionLeftIcons(wxCommandEvent& evt);
104 void OnPositionLeftBoth(wxCommandEvent& evt);
105 void OnPositionLeftDropdown(wxRibbonToolBarEvent& evt);
106
107 protected:
108 wxRibbonGallery* PopulateColoursPanel(wxWindow* panel, wxColour def,
109 int gallery_id);
110 void AddText(wxString msg);
111 wxRibbonGalleryItem* AddColourToGallery(wxRibbonGallery *gallery,
112 wxString name, wxMemoryDC& dc, wxColour* value = NULL);
113 wxColour GetGalleryColour(wxRibbonGallery *gallery,
114 wxRibbonGalleryItem* item, wxString* name);
115 void ResetGalleryArtProviders();
116 void SetArtProvider(wxRibbonArtProvider* prov);
117 void SetBarStyle(long style);
118
119 wxRibbonBar* m_ribbon;
120 wxRibbonGallery* m_primary_gallery;
121 wxRibbonGallery* m_secondary_gallery;
122 wxTextCtrl* m_logwindow;
123 wxColourData m_colour_data;
124 wxColour m_default_primary;
125 wxColour m_default_secondary;
126 wxColour m_default_tertiary;
127 wxMemoryDC m_bitmap_creation_dc;
128
129 DECLARE_EVENT_TABLE()
130 };
131
132 // -- implementations --
133
134 bool MyApp::OnInit()
135 {
136 if(!wxApp::OnInit())
137 return false;
138
139 wxFrame* frame = new MyFrame;
140 SetTopWindow(frame);
141 frame->Show();
142
143 return true;
144 }
145
146 BEGIN_EVENT_TABLE(MyFrame, wxFrame)
147 EVT_RIBBONBUTTONBAR_CLICKED(ID_DEFAULT_PROVIDER, MyFrame::OnDefaultProvider)
148 EVT_RIBBONBUTTONBAR_CLICKED(ID_AUI_PROVIDER, MyFrame::OnAUIProvider)
149 EVT_RIBBONBUTTONBAR_CLICKED(ID_MSW_PROVIDER, MyFrame::OnMSWProvider)
150 EVT_RIBBONBUTTONBAR_CLICKED(ID_SELECTION_EXPAND_H, MyFrame::OnSelectionExpandHButton)
151 EVT_RIBBONBUTTONBAR_CLICKED(ID_SELECTION_EXPAND_V, MyFrame::OnSelectionExpandVButton)
152 EVT_RIBBONBUTTONBAR_CLICKED(ID_SELECTION_CONTRACT, MyFrame::OnSelectionContractButton)
153 EVT_RIBBONBUTTONBAR_CLICKED(ID_CIRCLE, MyFrame::OnCircleButton)
154 EVT_RIBBONBUTTONBAR_CLICKED(ID_CROSS, MyFrame::OnCrossButton)
155 EVT_RIBBONBUTTONBAR_CLICKED(ID_TRIANGLE, MyFrame::OnTriangleButton)
156 EVT_RIBBONBUTTONBAR_CLICKED(ID_SQUARE, MyFrame::OnSquareButton)
157 EVT_RIBBONBUTTONBAR_DROPDOWN_CLICKED(ID_TRIANGLE, MyFrame::OnTriangleDropdown)
158 EVT_RIBBONBUTTONBAR_DROPDOWN_CLICKED(ID_POLYGON, MyFrame::OnPolygonDropdown)
159 EVT_RIBBONGALLERY_HOVER_CHANGED(ID_PRIMARY_COLOUR, MyFrame::OnHoveredColourChange)
160 EVT_RIBBONGALLERY_HOVER_CHANGED(ID_SECONDARY_COLOUR, MyFrame::OnHoveredColourChange)
161 EVT_RIBBONGALLERY_SELECTED(ID_PRIMARY_COLOUR, MyFrame::OnPrimaryColourSelect)
162 EVT_RIBBONGALLERY_SELECTED(ID_SECONDARY_COLOUR, MyFrame::OnSecondaryColourSelect)
163 EVT_RIBBONTOOLBAR_CLICKED(wxID_NEW, MyFrame::OnNew)
164 EVT_RIBBONTOOLBAR_DROPDOWN_CLICKED(wxID_NEW, MyFrame::OnNewDropdown)
165 EVT_RIBBONTOOLBAR_CLICKED(wxID_PRINT, MyFrame::OnPrint)
166 EVT_RIBBONTOOLBAR_DROPDOWN_CLICKED(wxID_PRINT, MyFrame::OnPrintDropdown)
167 EVT_RIBBONTOOLBAR_DROPDOWN_CLICKED(wxID_REDO, MyFrame::OnRedoDropdown)
168 EVT_RIBBONTOOLBAR_DROPDOWN_CLICKED(wxID_UNDO, MyFrame::OnUndoDropdown)
169 EVT_RIBBONTOOLBAR_CLICKED(ID_POSITION_LEFT, MyFrame::OnPositionLeft)
170 EVT_RIBBONTOOLBAR_DROPDOWN_CLICKED(ID_POSITION_LEFT, MyFrame::OnPositionLeftDropdown)
171 EVT_RIBBONTOOLBAR_CLICKED(ID_POSITION_TOP, MyFrame::OnPositionTop)
172 EVT_RIBBONTOOLBAR_DROPDOWN_CLICKED(ID_POSITION_TOP, MyFrame::OnPositionTopDropdown)
173 EVT_BUTTON(ID_PRIMARY_COLOUR, MyFrame::OnColourGalleryButton)
174 EVT_BUTTON(ID_SECONDARY_COLOUR, MyFrame::OnColourGalleryButton)
175 EVT_MENU(ID_POSITION_LEFT, MyFrame::OnPositionLeftIcons)
176 EVT_MENU(ID_POSITION_LEFT_LABELS, MyFrame::OnPositionLeftLabels)
177 EVT_MENU(ID_POSITION_LEFT_BOTH, MyFrame::OnPositionLeftBoth)
178 EVT_MENU(ID_POSITION_TOP, MyFrame::OnPositionTopLabels)
179 EVT_MENU(ID_POSITION_TOP_ICONS, MyFrame::OnPositionTopIcons)
180 EVT_MENU(ID_POSITION_TOP_BOTH, MyFrame::OnPositionTopBoth)
181 END_EVENT_TABLE()
182
183 #include "align_center.xpm"
184 #include "align_left.xpm"
185 #include "align_right.xpm"
186 #include "aui_style.xpm"
187 #include "auto_crop_selection.xpm"
188 #include "auto_crop_selection_small.xpm"
189 #include "circle.xpm"
190 #include "circle_small.xpm"
191 #include "colours.xpm"
192 #include "cross.xpm"
193 #include "empty.xpm"
194 #include "expand_selection_v.xpm"
195 #include "expand_selection_h.xpm"
196 #include "eye.xpm"
197 #include "hexagon.xpm"
198 #include "msw_style.xpm"
199 #include "position_left_small.xpm"
200 #include "position_top_small.xpm"
201 #include "ribbon.xpm"
202 #include "selection_panel.xpm"
203 #include "square.xpm"
204 #include "triangle.xpm"
205
206 MyFrame::MyFrame()
207 : wxFrame(NULL, wxID_ANY, wxT("wxRibbon Sample Application"), wxDefaultPosition, wxSize(800, 600), wxDEFAULT_FRAME_STYLE)
208 {
209 m_ribbon = new wxRibbonBar(this, wxID_ANY);
210
211 {
212 wxRibbonPage* home = new wxRibbonPage(m_ribbon, wxID_ANY, wxT("Examples"), ribbon_xpm);
213 wxRibbonPanel *toolbar_panel = new wxRibbonPanel(home, wxID_ANY, wxT("Toolbar"), wxNullBitmap, wxDefaultPosition, wxDefaultSize, wxRIBBON_PANEL_NO_AUTO_MINIMISE);
214 wxRibbonToolBar *toolbar = new wxRibbonToolBar(toolbar_panel, ID_MAIN_TOOLBAR);
215 toolbar->AddTool(wxID_ANY, align_left_xpm);
216 toolbar->AddTool(wxID_ANY, align_center_xpm);
217 toolbar->AddTool(wxID_ANY, align_right_xpm);
218 toolbar->AddSeparator();
219 toolbar->AddHybridTool(wxID_NEW, wxArtProvider::GetBitmap(wxART_NEW, wxART_OTHER, wxSize(16, 15)));
220 toolbar->AddTool(wxID_ANY, wxArtProvider::GetBitmap(wxART_FILE_OPEN, wxART_OTHER, wxSize(16, 15)));
221 toolbar->AddTool(wxID_ANY, wxArtProvider::GetBitmap(wxART_FILE_SAVE, wxART_OTHER, wxSize(16, 15)));
222 toolbar->AddTool(wxID_ANY, wxArtProvider::GetBitmap(wxART_FILE_SAVE_AS, wxART_OTHER, wxSize(16, 15)));
223 toolbar->AddSeparator();
224 toolbar->AddDropdownTool(wxID_UNDO, wxArtProvider::GetBitmap(wxART_UNDO, wxART_OTHER, wxSize(16, 15)));
225 toolbar->AddDropdownTool(wxID_REDO, wxArtProvider::GetBitmap(wxART_REDO, wxART_OTHER, wxSize(16, 15)));
226 toolbar->AddSeparator();
227 toolbar->AddTool(wxID_ANY, wxArtProvider::GetBitmap(wxART_REPORT_VIEW, wxART_OTHER, wxSize(16, 15)));
228 toolbar->AddTool(wxID_ANY, wxArtProvider::GetBitmap(wxART_LIST_VIEW, wxART_OTHER, wxSize(16, 15)));
229 toolbar->AddSeparator();
230 toolbar->AddHybridTool(ID_POSITION_LEFT, position_left_xpm);
231 toolbar->AddHybridTool(ID_POSITION_TOP, position_top_xpm);
232 toolbar->AddSeparator();
233 toolbar->AddHybridTool(wxID_PRINT, wxArtProvider::GetBitmap(wxART_PRINT, wxART_OTHER, wxSize(16, 15)));
234 toolbar->SetRows(2, 3);
235
236 wxRibbonPanel *selection_panel = new wxRibbonPanel(home, wxID_ANY, wxT("Selection"), wxBitmap(selection_panel_xpm));
237 wxRibbonButtonBar *selection = new wxRibbonButtonBar(selection_panel);
238 selection->AddButton(ID_SELECTION_EXPAND_V, wxT("Expand Vertically"), wxBitmap(expand_selection_v_xpm), wxEmptyString);
239 selection->AddButton(ID_SELECTION_EXPAND_H, wxT("Expand Horizontally"), wxBitmap(expand_selection_h_xpm), wxEmptyString);
240 selection->AddButton(ID_SELECTION_CONTRACT, wxT("Contract"), wxBitmap(auto_crop_selection_xpm), wxBitmap(auto_crop_selection_small_xpm));
241
242 wxRibbonPanel *shapes_panel = new wxRibbonPanel(home, wxID_ANY, wxT("Shapes"), wxBitmap(circle_small_xpm));
243 wxRibbonButtonBar *shapes = new wxRibbonButtonBar(shapes_panel);
244 shapes->AddButton(ID_CIRCLE, wxT("Circle"), wxBitmap(circle_xpm), wxBitmap(circle_small_xpm));
245 shapes->AddButton(ID_CROSS, wxT("Cross"), wxBitmap(cross_xpm), wxEmptyString);
246 shapes->AddHybridButton(ID_TRIANGLE, wxT("Triangle"), wxBitmap(triangle_xpm));
247 shapes->AddButton(ID_SQUARE, wxT("Square"), wxBitmap(square_xpm), wxEmptyString);
248 shapes->AddDropdownButton(ID_POLYGON, wxT("Other Polygon"), wxBitmap(hexagon_xpm), wxEmptyString);
249
250 new wxRibbonPanel(home, wxID_ANY, wxT("Another Panel"), wxNullBitmap, wxDefaultPosition, wxDefaultSize, wxRIBBON_PANEL_EXT_BUTTON);
251 }
252 {
253 wxFont label_font(8, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_LIGHT);
254 m_bitmap_creation_dc.SetFont(label_font);
255
256 wxRibbonPage* scheme = new wxRibbonPage(m_ribbon, wxID_ANY, wxT("Appearance"), eye_xpm);
257 m_ribbon->GetArtProvider()->GetColourScheme(&m_default_primary,
258 &m_default_secondary, &m_default_tertiary);
259 wxRibbonPanel *provider_panel = new wxRibbonPanel(scheme, wxID_ANY,
260 wxT("Art"), wxNullBitmap, wxDefaultPosition, wxDefaultSize, wxRIBBON_PANEL_NO_AUTO_MINIMISE);
261 wxRibbonButtonBar *provider_bar = new wxRibbonButtonBar(provider_panel, wxID_ANY);
262 provider_bar->AddButton(ID_DEFAULT_PROVIDER, wxT("Default Provider"),
263 wxArtProvider::GetBitmap(wxART_QUESTION, wxART_OTHER, wxSize(32, 32)));
264 provider_bar->AddButton(ID_AUI_PROVIDER, wxT("AUI Provider"), aui_style_xpm);
265 provider_bar->AddButton(ID_MSW_PROVIDER, wxT("MSW Provider"), msw_style_xpm);
266 wxRibbonPanel *primary_panel = new wxRibbonPanel(scheme, wxID_ANY,
267 wxT("Primary Colour"), colours_xpm);
268 m_primary_gallery = PopulateColoursPanel(primary_panel,
269 m_default_primary, ID_PRIMARY_COLOUR);
270 wxRibbonPanel *secondary_panel = new wxRibbonPanel(scheme, wxID_ANY,
271 wxT("Secondary Colour"), colours_xpm);
272 m_secondary_gallery = PopulateColoursPanel(secondary_panel,
273 m_default_secondary, ID_SECONDARY_COLOUR);
274 }
275 new wxRibbonPage(m_ribbon, wxID_ANY, wxT("Empty Page"), empty_xpm);
276 new wxRibbonPage(m_ribbon, wxID_ANY, wxT("Another Page"), empty_xpm);
277
278 m_ribbon->Realize();
279
280 m_logwindow = new wxTextCtrl(this, wxID_ANY, wxEmptyString,
281 wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE | wxTE_READONLY |
282 wxTE_LEFT | wxTE_BESTWRAP | wxBORDER_NONE);
283
284 wxSizer *s = new wxBoxSizer(wxVERTICAL);
285
286 s->Add(m_ribbon, 0, wxEXPAND);
287 s->Add(m_logwindow, 1, wxEXPAND);
288
289 SetSizer(s);
290 }
291
292 void MyFrame::SetBarStyle(long style)
293 {
294 m_ribbon->Freeze();
295 m_ribbon->SetWindowStyleFlag(style);
296 wxBoxSizer *pTopSize = reinterpret_cast<wxBoxSizer*>(GetSizer());
297 wxRibbonToolBar *pToolbar = wxDynamicCast(FindWindow(ID_MAIN_TOOLBAR), wxRibbonToolBar);
298 if(style & wxRIBBON_BAR_FLOW_VERTICAL)
299 {
300 m_ribbon->SetTabCtrlMargins(10, 10);
301 pTopSize->SetOrientation(wxHORIZONTAL);
302 if(pToolbar)
303 pToolbar->SetRows(3, 5);
304 }
305 else
306 {
307 m_ribbon->SetTabCtrlMargins(50, 20);
308 pTopSize->SetOrientation(wxVERTICAL);
309 if(pToolbar)
310 pToolbar->SetRows(2, 3);
311 }
312 m_ribbon->Realise();
313 Layout();
314 m_ribbon->Thaw();
315 }
316
317 MyFrame::~MyFrame()
318 {
319 }
320
321 class ColourClientData : public wxClientData
322 {
323 public:
324 ColourClientData(const wxString& name, const wxColour& colour)
325 : m_name(name), m_colour(colour) {}
326
327 const wxString& GetName() const {return m_name;}
328 const wxColour& GetColour() const {return m_colour;}
329
330 private:
331 wxString m_name;
332 wxColour m_colour;
333 };
334
335 wxRibbonGallery* MyFrame::PopulateColoursPanel(wxWindow* panel,
336 wxColour def, int gallery_id)
337 {
338 wxRibbonGallery *gallery = wxDynamicCast(panel->FindWindow(gallery_id), wxRibbonGallery);
339 if(gallery)
340 gallery->Clear();
341 else
342 gallery = new wxRibbonGallery(panel, gallery_id);
343 wxMemoryDC& dc = m_bitmap_creation_dc;
344 wxRibbonGalleryItem *def_item =
345 AddColourToGallery(gallery, wxT("Default"), dc, &def);
346 gallery->SetSelection(def_item);
347 AddColourToGallery(gallery, wxT("BLUE"), dc);
348 AddColourToGallery(gallery, wxT("BLUE VIOLET"), dc);
349 AddColourToGallery(gallery, wxT("BROWN"), dc);
350 AddColourToGallery(gallery, wxT("CADET BLUE"), dc);
351 AddColourToGallery(gallery, wxT("CORAL"), dc);
352 AddColourToGallery(gallery, wxT("CYAN"), dc);
353 AddColourToGallery(gallery, wxT("DARK GREEN"), dc);
354 AddColourToGallery(gallery, wxT("DARK ORCHID"), dc);
355 AddColourToGallery(gallery, wxT("FIREBRICK"), dc);
356 AddColourToGallery(gallery, wxT("GOLD"), dc);
357 AddColourToGallery(gallery, wxT("GOLDENROD"), dc);
358 AddColourToGallery(gallery, wxT("GREEN"), dc);
359 AddColourToGallery(gallery, wxT("INDIAN RED"), dc);
360 AddColourToGallery(gallery, wxT("KHAKI"), dc);
361 AddColourToGallery(gallery, wxT("LIGHT BLUE"), dc);
362 AddColourToGallery(gallery, wxT("LIME GREEN"), dc);
363 AddColourToGallery(gallery, wxT("MAGENTA"), dc);
364 AddColourToGallery(gallery, wxT("MAROON"), dc);
365 AddColourToGallery(gallery, wxT("NAVY"), dc);
366 AddColourToGallery(gallery, wxT("ORANGE"), dc);
367 AddColourToGallery(gallery, wxT("ORCHID"), dc);
368 AddColourToGallery(gallery, wxT("PINK"), dc);
369 AddColourToGallery(gallery, wxT("PLUM"), dc);
370 AddColourToGallery(gallery, wxT("PURPLE"), dc);
371 AddColourToGallery(gallery, wxT("RED"), dc);
372 AddColourToGallery(gallery, wxT("SALMON"), dc);
373 AddColourToGallery(gallery, wxT("SEA GREEN"), dc);
374 AddColourToGallery(gallery, wxT("SIENNA"), dc);
375 AddColourToGallery(gallery, wxT("SKY BLUE"), dc);
376 AddColourToGallery(gallery, wxT("TAN"), dc);
377 AddColourToGallery(gallery, wxT("THISTLE"), dc);
378 AddColourToGallery(gallery, wxT("TURQUOISE"), dc);
379 AddColourToGallery(gallery, wxT("VIOLET"), dc);
380 AddColourToGallery(gallery, wxT("VIOLET RED"), dc);
381 AddColourToGallery(gallery, wxT("WHEAT"), dc);
382 AddColourToGallery(gallery, wxT("WHITE"), dc);
383 AddColourToGallery(gallery, wxT("YELLOW"), dc);
384
385 return gallery;
386 }
387
388 wxColour MyFrame::GetGalleryColour(wxRibbonGallery *gallery,
389 wxRibbonGalleryItem* item, wxString* name)
390 {
391 ColourClientData *data = (ColourClientData*)gallery->GetItemClientObject(item);
392 if(name != NULL)
393 *name = data->GetName();
394 return data->GetColour();
395 }
396
397 void MyFrame::OnHoveredColourChange(wxRibbonGalleryEvent& evt)
398 {
399 // Set the background of the gallery to the hovered colour, or back to the
400 // default if there is no longer a hovered item.
401
402 wxRibbonGallery *gallery = evt.GetGallery();
403 wxRibbonArtProvider *provider = gallery->GetArtProvider();
404
405 if(evt.GetGalleryItem() != NULL)
406 {
407 if(provider == m_ribbon->GetArtProvider())
408 {
409 provider = provider->Clone();
410 gallery->SetArtProvider(provider);
411 }
412 provider->SetColour(wxRIBBON_ART_GALLERY_HOVER_BACKGROUND_COLOUR,
413 GetGalleryColour(evt.GetGallery(), evt.GetGalleryItem(), NULL));
414 }
415 else
416 {
417 if(provider != m_ribbon->GetArtProvider())
418 {
419 gallery->SetArtProvider(m_ribbon->GetArtProvider());
420 delete provider;
421 }
422 }
423 }
424
425 void MyFrame::OnPrimaryColourSelect(wxRibbonGalleryEvent& evt)
426 {
427 wxString name;
428 wxColour colour = GetGalleryColour(evt.GetGallery(), evt.GetGalleryItem(), &name);
429 AddText(wxT("Colour \"") + name + wxT("\" selected as primary."));
430 wxColour secondary, tertiary;
431 m_ribbon->GetArtProvider()->GetColourScheme(NULL, &secondary, &tertiary);
432 m_ribbon->GetArtProvider()->SetColourScheme(colour, secondary, tertiary);
433 ResetGalleryArtProviders();
434 m_ribbon->Refresh();
435 }
436
437 void MyFrame::OnSecondaryColourSelect(wxRibbonGalleryEvent& evt)
438 {
439 wxString name;
440 wxColour colour = GetGalleryColour(evt.GetGallery(), evt.GetGalleryItem(), &name);
441 AddText(wxT("Colour \"") + name + wxT("\" selected as secondary."));
442 wxColour primary, tertiary;
443 m_ribbon->GetArtProvider()->GetColourScheme(&primary, NULL, &tertiary);
444 m_ribbon->GetArtProvider()->SetColourScheme(primary, colour, tertiary);
445 ResetGalleryArtProviders();
446 m_ribbon->Refresh();
447 }
448
449 void MyFrame::ResetGalleryArtProviders()
450 {
451 if(m_primary_gallery->GetArtProvider() != m_ribbon->GetArtProvider())
452 {
453 delete m_primary_gallery->GetArtProvider();
454 m_primary_gallery->SetArtProvider(m_ribbon->GetArtProvider());
455 }
456 if(m_secondary_gallery->GetArtProvider() != m_ribbon->GetArtProvider())
457 {
458 delete m_secondary_gallery->GetArtProvider();
459 m_secondary_gallery->SetArtProvider(m_ribbon->GetArtProvider());
460 }
461 }
462
463 void MyFrame::OnSelectionExpandHButton(wxRibbonButtonBarEvent& WXUNUSED(evt))
464 {
465 AddText(wxT("Expand selection horizontally button clicked."));
466 }
467
468 void MyFrame::OnSelectionExpandVButton(wxRibbonButtonBarEvent& WXUNUSED(evt))
469 {
470 AddText(wxT("Expand selection vertically button clicked."));
471 }
472
473 void MyFrame::OnSelectionContractButton(wxRibbonButtonBarEvent& WXUNUSED(evt))
474 {
475 AddText(wxT("Contract selection button clicked."));
476 }
477
478 void MyFrame::OnCircleButton(wxRibbonButtonBarEvent& WXUNUSED(evt))
479 {
480 AddText(wxT("Circle button clicked."));
481 }
482
483 void MyFrame::OnCrossButton(wxRibbonButtonBarEvent& WXUNUSED(evt))
484 {
485 AddText(wxT("Cross button clicked."));
486 }
487
488 void MyFrame::OnTriangleButton(wxRibbonButtonBarEvent& WXUNUSED(evt))
489 {
490 AddText(wxT("Triangle button clicked."));
491 }
492
493 void MyFrame::OnTriangleDropdown(wxRibbonButtonBarEvent& evt)
494 {
495 wxMenu menu;
496 menu.Append(wxID_ANY, wxT("Equilateral"));
497 menu.Append(wxID_ANY, wxT("Isosceles"));
498 menu.Append(wxID_ANY, wxT("Scalene"));
499
500 evt.PopupMenu(&menu);
501 }
502
503 void MyFrame::OnSquareButton(wxRibbonButtonBarEvent& WXUNUSED(evt))
504 {
505 AddText(wxT("Square button clicked."));
506 }
507
508 void MyFrame::OnPolygonDropdown(wxRibbonButtonBarEvent& evt)
509 {
510 wxMenu menu;
511 menu.Append(wxID_ANY, wxT("Pentagon (5 sided)"));
512 menu.Append(wxID_ANY, wxT("Hexagon (6 sided)"));
513 menu.Append(wxID_ANY, wxT("Heptagon (7 sided)"));
514 menu.Append(wxID_ANY, wxT("Octogon (8 sided)"));
515 menu.Append(wxID_ANY, wxT("Nonagon (9 sided)"));
516 menu.Append(wxID_ANY, wxT("Decagon (10 sided)"));
517
518 evt.PopupMenu(&menu);
519 }
520
521 void MyFrame::OnNew(wxRibbonToolBarEvent& WXUNUSED(evt))
522 {
523 AddText(wxT("New button clicked."));
524 }
525
526 void MyFrame::OnNewDropdown(wxRibbonToolBarEvent& evt)
527 {
528 wxMenu menu;
529 menu.Append(wxID_ANY, wxT("New Document"));
530 menu.Append(wxID_ANY, wxT("New Template"));
531 menu.Append(wxID_ANY, wxT("New Mail"));
532
533 evt.PopupMenu(&menu);
534 }
535
536 void MyFrame::OnPrint(wxRibbonToolBarEvent& WXUNUSED(evt))
537 {
538 AddText(wxT("Print button clicked."));
539 }
540
541 void MyFrame::OnPrintDropdown(wxRibbonToolBarEvent& evt)
542 {
543 wxMenu menu;
544 menu.Append(wxID_ANY, wxT("Print"));
545 menu.Append(wxID_ANY, wxT("Preview"));
546 menu.Append(wxID_ANY, wxT("Options"));
547
548 evt.PopupMenu(&menu);
549 }
550
551 void MyFrame::OnRedoDropdown(wxRibbonToolBarEvent& evt)
552 {
553 wxMenu menu;
554 menu.Append(wxID_ANY, wxT("Redo E"));
555 menu.Append(wxID_ANY, wxT("Redo F"));
556 menu.Append(wxID_ANY, wxT("Redo G"));
557
558 evt.PopupMenu(&menu);
559 }
560
561 void MyFrame::OnUndoDropdown(wxRibbonToolBarEvent& evt)
562 {
563 wxMenu menu;
564 menu.Append(wxID_ANY, wxT("Undo C"));
565 menu.Append(wxID_ANY, wxT("Undo B"));
566 menu.Append(wxID_ANY, wxT("Undo A"));
567
568 evt.PopupMenu(&menu);
569 }
570
571 void MyFrame::OnPositionTopLabels(wxCommandEvent& WXUNUSED(evt))
572 {
573 SetBarStyle(wxRIBBON_BAR_DEFAULT_STYLE);
574 }
575
576 void MyFrame::OnPositionTopIcons(wxCommandEvent& WXUNUSED(evt))
577 {
578 SetBarStyle((wxRIBBON_BAR_DEFAULT_STYLE &~wxRIBBON_BAR_SHOW_PAGE_LABELS)
579 | wxRIBBON_BAR_SHOW_PAGE_ICONS);
580 }
581
582 void MyFrame::OnPositionTopBoth(wxCommandEvent& WXUNUSED(evt))
583 {
584 SetBarStyle(wxRIBBON_BAR_DEFAULT_STYLE | wxRIBBON_BAR_SHOW_PAGE_ICONS);
585 }
586
587 void MyFrame::OnPositionLeftLabels(wxCommandEvent& WXUNUSED(evt))
588 {
589 SetBarStyle(wxRIBBON_BAR_DEFAULT_STYLE | wxRIBBON_BAR_FLOW_VERTICAL);
590 }
591
592 void MyFrame::OnPositionLeftIcons(wxCommandEvent& WXUNUSED(evt))
593 {
594 SetBarStyle((wxRIBBON_BAR_DEFAULT_STYLE &~wxRIBBON_BAR_SHOW_PAGE_LABELS) |
595 wxRIBBON_BAR_SHOW_PAGE_ICONS | wxRIBBON_BAR_FLOW_VERTICAL);
596 }
597
598 void MyFrame::OnPositionLeftBoth(wxCommandEvent& WXUNUSED(evt))
599 {
600 SetBarStyle(wxRIBBON_BAR_DEFAULT_STYLE | wxRIBBON_BAR_SHOW_PAGE_ICONS |
601 wxRIBBON_BAR_FLOW_VERTICAL);
602 }
603
604 void MyFrame::OnPositionTop(wxRibbonToolBarEvent& evt)
605 {
606 OnPositionTopLabels(evt);
607 }
608
609 void MyFrame::OnPositionTopDropdown(wxRibbonToolBarEvent& evt)
610 {
611 wxMenu menu;
612 menu.Append(ID_POSITION_TOP, wxT("Top with Labels"));
613 menu.Append(ID_POSITION_TOP_ICONS, wxT("Top with Icons"));
614 menu.Append(ID_POSITION_TOP_BOTH, wxT("Top with Both"));
615 evt.PopupMenu(&menu);
616 }
617
618 void MyFrame::OnPositionLeft(wxRibbonToolBarEvent& evt)
619 {
620 OnPositionLeftIcons(evt);
621 }
622
623 void MyFrame::OnPositionLeftDropdown(wxRibbonToolBarEvent& evt)
624 {
625 wxMenu menu;
626 menu.Append(ID_POSITION_LEFT, wxT("Left with Icons"));
627 menu.Append(ID_POSITION_LEFT_LABELS, wxT("Left with Labels"));
628 menu.Append(ID_POSITION_LEFT_BOTH, wxT("Left with Both"));
629 evt.PopupMenu(&menu);
630 }
631
632 void MyFrame::AddText(wxString msg)
633 {
634 m_logwindow->AppendText(msg);
635 m_logwindow->AppendText(wxT("\n"));
636 m_ribbon->DismissExpandedPanel();
637 }
638
639 wxRibbonGalleryItem* MyFrame::AddColourToGallery(wxRibbonGallery *gallery,
640 wxString colour, wxMemoryDC& dc,
641 wxColour* value)
642 {
643 wxRibbonGalleryItem* item = NULL;
644 wxColour c;
645 if (colour != wxT("Default"))
646 c = wxColour(colour);
647 if (!c.IsOk())
648 c = *value;
649 if(c.IsOk())
650 {
651 const int iWidth = 64;
652 const int iHeight = 40;
653
654 wxBitmap bitmap(iWidth, iHeight);
655 dc.SelectObject(bitmap);
656 wxBrush b(c);
657 dc.SetPen(*wxBLACK_PEN);
658 dc.SetBrush(b);
659 dc.DrawRectangle(0, 0, iWidth, iHeight);
660
661 colour = colour.Mid(0, 1) + colour.Mid(1).Lower();
662 wxSize size = dc.GetTextExtent(colour);
663 wxColour foreground = wxColour(~c.Red(), ~c.Green(), ~c.Blue());
664 if(abs(foreground.Red() - c.Red()) + abs(foreground.Blue() - c.Blue())
665 + abs(foreground.Green() - c.Green()) < 64)
666 {
667 // Foreground too similar to background - use a different
668 // strategy to find a contrasting colour
669 foreground = wxColour((c.Red() + 64) % 256, 255 - c.Green(),
670 (c.Blue() + 192) % 256);
671 }
672 dc.SetTextForeground(foreground);
673 dc.DrawText(colour, (iWidth - size.GetWidth() + 1) / 2,
674 (iHeight - size.GetHeight()) / 2);
675 dc.SelectObjectAsSource(wxNullBitmap);
676
677 item = gallery->Append(bitmap, wxID_ANY);
678 gallery->SetItemClientObject(item, new ColourClientData(colour, c));
679 }
680 return item;
681 }
682
683 void MyFrame::OnColourGalleryButton(wxCommandEvent& evt)
684 {
685 wxRibbonGallery *gallery = wxDynamicCast(evt.GetEventObject(), wxRibbonGallery);
686 if(gallery == NULL)
687 return;
688
689 m_ribbon->DismissExpandedPanel();
690 if(gallery->GetSelection())
691 m_colour_data.SetColour(GetGalleryColour(gallery, gallery->GetSelection(), NULL));
692 wxColourDialog dlg(this, &m_colour_data);
693 if(dlg.ShowModal() == wxID_OK)
694 {
695 m_colour_data = dlg.GetColourData();
696 wxColour clr = m_colour_data.GetColour();
697
698 // Try to find colour in gallery
699 wxRibbonGalleryItem *item = NULL;
700 for(unsigned int i = 0; i < gallery->GetCount(); ++i)
701 {
702 item = gallery->GetItem(i);
703 if(GetGalleryColour(gallery, item, NULL) == clr)
704 break;
705 else
706 item = NULL;
707 }
708
709 // Colour not in gallery - add it
710 if(item == NULL)
711 {
712 item = AddColourToGallery(gallery,
713 clr.GetAsString(wxC2S_HTML_SYNTAX), m_bitmap_creation_dc,
714 &clr);
715 gallery->Realise();
716 }
717
718 // Set selection
719 gallery->EnsureVisible(item);
720 gallery->SetSelection(item);
721
722 // Send an event to respond to the selection change
723 wxRibbonGalleryEvent dummy(wxEVT_COMMAND_RIBBONGALLERY_SELECTED, gallery->GetId());
724 dummy.SetEventObject(gallery);
725 dummy.SetGallery(gallery);
726 dummy.SetGalleryItem(item);
727 ProcessWindowEvent(dummy);
728 }
729 }
730
731 void MyFrame::OnDefaultProvider(wxRibbonButtonBarEvent& WXUNUSED(evt))
732 {
733 m_ribbon->DismissExpandedPanel();
734 SetArtProvider(new wxRibbonDefaultArtProvider);
735 }
736
737 void MyFrame::OnAUIProvider(wxRibbonButtonBarEvent& WXUNUSED(evt))
738 {
739 m_ribbon->DismissExpandedPanel();
740 SetArtProvider(new wxRibbonAUIArtProvider);
741 }
742
743 void MyFrame::OnMSWProvider(wxRibbonButtonBarEvent& WXUNUSED(evt))
744 {
745 m_ribbon->DismissExpandedPanel();
746 SetArtProvider(new wxRibbonMSWArtProvider);
747 }
748
749 void MyFrame::SetArtProvider(wxRibbonArtProvider *prov)
750 {
751 m_ribbon->Freeze();
752 m_ribbon->SetArtProvider(prov);
753
754 prov->GetColourScheme(&m_default_primary, &m_default_secondary,
755 &m_default_tertiary);
756 PopulateColoursPanel(m_primary_gallery->GetParent(), m_default_primary,
757 ID_PRIMARY_COLOUR);
758 PopulateColoursPanel(m_secondary_gallery->GetParent(), m_default_secondary,
759 ID_SECONDARY_COLOUR);
760
761 m_ribbon->Realize();
762 m_ribbon->Thaw();
763 GetSizer()->Layout();
764 }