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