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