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