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