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