1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: ribbondemo.cpp
3 // Purpose: wxRibbon: Ribbon user interface - sample/test program
4 // Author: Peter Cawley
8 // Copyright: (C) Copyright 2009, Peter Cawley
9 // Licence: wxWindows Library Licence
10 ///////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.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"
27 #include "wx/msgdlg.h"
28 #include "wx/dcbuffer.h"
29 #include "wx/colordlg.h"
30 #include "wx/artprov.h"
31 #include "wx/combobox.h"
32 #include "wx/tglbtn.h"
33 #include "wx/wrapsizer.h"
37 class MyApp
: public wxApp
48 class MyFrame
: public wxFrame
56 ID_CIRCLE
= wxID_HIGHEST
+ 1,
61 ID_SELECTION_EXPAND_H
,
62 ID_SELECTION_EXPAND_V
,
63 ID_SELECTION_CONTRACT
,
71 ID_POSITION_TOP_ICONS
,
74 ID_POSITION_LEFT_LABELS
,
75 ID_POSITION_LEFT_BOTH
,
85 ID_UI_CHANGE_TEXT_UPDATED
88 void OnEnableUpdateUI(wxUpdateUIEvent
& evt
);
89 void OnCheckUpdateUI(wxUpdateUIEvent
& evt
);
90 void OnChangeTextUpdateUI(wxUpdateUIEvent
& evt
);
91 void OnCheck(wxRibbonButtonBarEvent
& evt
);
92 void OnEnable(wxRibbonButtonBarEvent
& evt
);
93 void OnDisable(wxRibbonButtonBarEvent
& evt
);
94 void OnChangeText1(wxRibbonButtonBarEvent
& evt
);
95 void OnChangeText2(wxRibbonButtonBarEvent
& evt
);
96 void OnCircleButton(wxRibbonButtonBarEvent
& evt
);
97 void OnCrossButton(wxRibbonButtonBarEvent
& evt
);
98 void OnTriangleButton(wxRibbonButtonBarEvent
& evt
);
99 void OnTriangleDropdown(wxRibbonButtonBarEvent
& evt
);
100 void OnSquareButton(wxRibbonButtonBarEvent
& evt
);
101 void OnPolygonDropdown(wxRibbonButtonBarEvent
& evt
);
102 void OnSelectionExpandVButton(wxRibbonButtonBarEvent
& evt
);
103 void OnSelectionExpandHButton(wxRibbonButtonBarEvent
& evt
);
104 void OnSelectionContractButton(wxRibbonButtonBarEvent
& evt
);
105 void OnHoveredColourChange(wxRibbonGalleryEvent
& evt
);
106 void OnPrimaryColourSelect(wxRibbonGalleryEvent
& evt
);
107 void OnSecondaryColourSelect(wxRibbonGalleryEvent
& evt
);
108 void OnColourGalleryButton(wxCommandEvent
& evt
);
109 void OnDefaultProvider(wxRibbonButtonBarEvent
& evt
);
110 void OnAUIProvider(wxRibbonButtonBarEvent
& evt
);
111 void OnMSWProvider(wxRibbonButtonBarEvent
& evt
);
112 void OnJustify(wxRibbonToolBarEvent
& evt
);
113 void OnJustifyUpdateUI(wxUpdateUIEvent
& evt
);
114 void OnNew(wxRibbonToolBarEvent
& evt
);
115 void OnNewDropdown(wxRibbonToolBarEvent
& evt
);
116 void OnPrint(wxRibbonToolBarEvent
& evt
);
117 void OnPrintDropdown(wxRibbonToolBarEvent
& evt
);
118 void OnRedoDropdown(wxRibbonToolBarEvent
& evt
);
119 void OnUndoDropdown(wxRibbonToolBarEvent
& evt
);
120 void OnPositionTop(wxRibbonToolBarEvent
& evt
);
121 void OnPositionTopLabels(wxCommandEvent
& evt
);
122 void OnPositionTopIcons(wxCommandEvent
& evt
);
123 void OnPositionTopBoth(wxCommandEvent
& evt
);
124 void OnPositionTopDropdown(wxRibbonToolBarEvent
& evt
);
125 void OnPositionLeft(wxRibbonToolBarEvent
& evt
);
126 void OnPositionLeftLabels(wxCommandEvent
& evt
);
127 void OnPositionLeftIcons(wxCommandEvent
& evt
);
128 void OnPositionLeftBoth(wxCommandEvent
& evt
);
129 void OnPositionLeftDropdown(wxRibbonToolBarEvent
& evt
);
131 void OnTogglePanels(wxCommandEvent
& evt
);
133 void OnExtButton(wxRibbonPanelEvent
& evt
);
136 wxRibbonGallery
* PopulateColoursPanel(wxWindow
* panel
, wxColour def
,
138 void AddText(wxString msg
);
139 wxRibbonGalleryItem
* AddColourToGallery(wxRibbonGallery
*gallery
,
140 wxString name
, wxMemoryDC
& dc
, wxColour
* value
= NULL
);
141 wxColour
GetGalleryColour(wxRibbonGallery
*gallery
,
142 wxRibbonGalleryItem
* item
, wxString
* name
);
143 void ResetGalleryArtProviders();
144 void SetArtProvider(wxRibbonArtProvider
* prov
);
145 void SetBarStyle(long style
);
147 wxRibbonBar
* m_ribbon
;
148 wxRibbonGallery
* m_primary_gallery
;
149 wxRibbonGallery
* m_secondary_gallery
;
150 wxTextCtrl
* m_logwindow
;
151 wxToggleButton
* m_togglePanels
;
153 wxColourData m_colour_data
;
154 wxColour m_default_primary
;
155 wxColour m_default_secondary
;
156 wxColour m_default_tertiary
;
157 wxMemoryDC m_bitmap_creation_dc
;
162 DECLARE_EVENT_TABLE()
165 // -- implementations --
172 wxFrame
* frame
= new MyFrame
;
178 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
179 EVT_RIBBONBUTTONBAR_CLICKED(ID_ENABLE
, MyFrame::OnEnable
)
180 EVT_RIBBONBUTTONBAR_CLICKED(ID_DISABLE
, MyFrame::OnDisable
)
181 EVT_UPDATE_UI(ID_UI_ENABLE_UPDATED
, MyFrame::OnEnableUpdateUI
)
182 EVT_RIBBONBUTTONBAR_CLICKED(ID_CHECK
, MyFrame::OnCheck
)
183 EVT_UPDATE_UI(ID_UI_CHECK_UPDATED
, MyFrame::OnCheckUpdateUI
)
184 EVT_RIBBONBUTTONBAR_CLICKED(ID_CHANGE_TEXT1
, MyFrame::OnChangeText1
)
185 EVT_RIBBONBUTTONBAR_CLICKED(ID_CHANGE_TEXT2
, MyFrame::OnChangeText2
)
186 EVT_UPDATE_UI(ID_UI_CHANGE_TEXT_UPDATED
, MyFrame::OnChangeTextUpdateUI
)
187 EVT_RIBBONBUTTONBAR_CLICKED(ID_DEFAULT_PROVIDER
, MyFrame::OnDefaultProvider
)
188 EVT_RIBBONBUTTONBAR_CLICKED(ID_AUI_PROVIDER
, MyFrame::OnAUIProvider
)
189 EVT_RIBBONBUTTONBAR_CLICKED(ID_MSW_PROVIDER
, MyFrame::OnMSWProvider
)
190 EVT_RIBBONBUTTONBAR_CLICKED(ID_SELECTION_EXPAND_H
, MyFrame::OnSelectionExpandHButton
)
191 EVT_RIBBONBUTTONBAR_CLICKED(ID_SELECTION_EXPAND_V
, MyFrame::OnSelectionExpandVButton
)
192 EVT_RIBBONBUTTONBAR_CLICKED(ID_SELECTION_CONTRACT
, MyFrame::OnSelectionContractButton
)
193 EVT_RIBBONBUTTONBAR_CLICKED(ID_CIRCLE
, MyFrame::OnCircleButton
)
194 EVT_RIBBONBUTTONBAR_CLICKED(ID_CROSS
, MyFrame::OnCrossButton
)
195 EVT_RIBBONBUTTONBAR_CLICKED(ID_TRIANGLE
, MyFrame::OnTriangleButton
)
196 EVT_RIBBONBUTTONBAR_CLICKED(ID_SQUARE
, MyFrame::OnSquareButton
)
197 EVT_RIBBONBUTTONBAR_DROPDOWN_CLICKED(ID_TRIANGLE
, MyFrame::OnTriangleDropdown
)
198 EVT_RIBBONBUTTONBAR_DROPDOWN_CLICKED(ID_POLYGON
, MyFrame::OnPolygonDropdown
)
199 EVT_RIBBONGALLERY_HOVER_CHANGED(ID_PRIMARY_COLOUR
, MyFrame::OnHoveredColourChange
)
200 EVT_RIBBONGALLERY_HOVER_CHANGED(ID_SECONDARY_COLOUR
, MyFrame::OnHoveredColourChange
)
201 EVT_RIBBONGALLERY_SELECTED(ID_PRIMARY_COLOUR
, MyFrame::OnPrimaryColourSelect
)
202 EVT_RIBBONGALLERY_SELECTED(ID_SECONDARY_COLOUR
, MyFrame::OnSecondaryColourSelect
)
203 EVT_RIBBONTOOLBAR_CLICKED(wxID_JUSTIFY_LEFT
, MyFrame::OnJustify
)
204 EVT_RIBBONTOOLBAR_CLICKED(wxID_JUSTIFY_CENTER
, MyFrame::OnJustify
)
205 EVT_RIBBONTOOLBAR_CLICKED(wxID_JUSTIFY_RIGHT
, MyFrame::OnJustify
)
206 EVT_UPDATE_UI(wxID_JUSTIFY_LEFT
, MyFrame::OnJustifyUpdateUI
)
207 EVT_UPDATE_UI(wxID_JUSTIFY_CENTER
, MyFrame::OnJustifyUpdateUI
)
208 EVT_UPDATE_UI(wxID_JUSTIFY_RIGHT
, MyFrame::OnJustifyUpdateUI
)
209 EVT_RIBBONTOOLBAR_CLICKED(wxID_NEW
, MyFrame::OnNew
)
210 EVT_RIBBONTOOLBAR_DROPDOWN_CLICKED(wxID_NEW
, MyFrame::OnNewDropdown
)
211 EVT_RIBBONTOOLBAR_CLICKED(wxID_PRINT
, MyFrame::OnPrint
)
212 EVT_RIBBONTOOLBAR_DROPDOWN_CLICKED(wxID_PRINT
, MyFrame::OnPrintDropdown
)
213 EVT_RIBBONTOOLBAR_DROPDOWN_CLICKED(wxID_REDO
, MyFrame::OnRedoDropdown
)
214 EVT_RIBBONTOOLBAR_DROPDOWN_CLICKED(wxID_UNDO
, MyFrame::OnUndoDropdown
)
215 EVT_RIBBONTOOLBAR_CLICKED(ID_POSITION_LEFT
, MyFrame::OnPositionLeft
)
216 EVT_RIBBONTOOLBAR_DROPDOWN_CLICKED(ID_POSITION_LEFT
, MyFrame::OnPositionLeftDropdown
)
217 EVT_RIBBONTOOLBAR_CLICKED(ID_POSITION_TOP
, MyFrame::OnPositionTop
)
218 EVT_RIBBONTOOLBAR_DROPDOWN_CLICKED(ID_POSITION_TOP
, MyFrame::OnPositionTopDropdown
)
219 EVT_BUTTON(ID_PRIMARY_COLOUR
, MyFrame::OnColourGalleryButton
)
220 EVT_BUTTON(ID_SECONDARY_COLOUR
, MyFrame::OnColourGalleryButton
)
221 EVT_MENU(ID_POSITION_LEFT
, MyFrame::OnPositionLeftIcons
)
222 EVT_MENU(ID_POSITION_LEFT_LABELS
, MyFrame::OnPositionLeftLabels
)
223 EVT_MENU(ID_POSITION_LEFT_BOTH
, MyFrame::OnPositionLeftBoth
)
224 EVT_MENU(ID_POSITION_TOP
, MyFrame::OnPositionTopLabels
)
225 EVT_MENU(ID_POSITION_TOP_ICONS
, MyFrame::OnPositionTopIcons
)
226 EVT_MENU(ID_POSITION_TOP_BOTH
, MyFrame::OnPositionTopBoth
)
227 EVT_TOGGLEBUTTON(ID_TOGGLE_PANELS
, MyFrame::OnTogglePanels
)
228 EVT_RIBBONPANEL_EXTBUTTON_ACTIVATED(wxID_ANY
, MyFrame::OnExtButton
)
231 #include "align_center.xpm"
232 #include "align_left.xpm"
233 #include "align_right.xpm"
234 #include "aui_style.xpm"
235 #include "auto_crop_selection.xpm"
236 #include "auto_crop_selection_small.xpm"
237 #include "circle.xpm"
238 #include "circle_small.xpm"
239 #include "colours.xpm"
242 #include "expand_selection_v.xpm"
243 #include "expand_selection_h.xpm"
245 #include "hexagon.xpm"
246 #include "msw_style.xpm"
247 #include "position_left_small.xpm"
248 #include "position_top_small.xpm"
249 #include "ribbon.xpm"
250 #include "selection_panel.xpm"
251 #include "square.xpm"
252 #include "triangle.xpm"
255 : wxFrame(NULL
, wxID_ANY
, wxT("wxRibbon Sample Application"), wxDefaultPosition
, wxSize(800, 600), wxDEFAULT_FRAME_STYLE
)
257 m_ribbon
= new wxRibbonBar(this, wxID_ANY
,
258 wxDefaultPosition
, wxDefaultSize
,
259 wxRIBBON_BAR_DEFAULT_STYLE
|
260 wxRIBBON_BAR_SHOW_PANEL_EXT_BUTTONS
);
263 wxRibbonPage
* home
= new wxRibbonPage(m_ribbon
, wxID_ANY
, wxT("Examples"), ribbon_xpm
);
264 wxRibbonPanel
*toolbar_panel
= new wxRibbonPanel(home
, wxID_ANY
, wxT("Toolbar"),
265 wxNullBitmap
, wxDefaultPosition
, wxDefaultSize
,
266 wxRIBBON_PANEL_NO_AUTO_MINIMISE
|
267 wxRIBBON_PANEL_EXT_BUTTON
);
268 wxRibbonToolBar
*toolbar
= new wxRibbonToolBar(toolbar_panel
, ID_MAIN_TOOLBAR
);
269 toolbar
->AddToggleTool(wxID_JUSTIFY_LEFT
, align_left_xpm
);
270 toolbar
->AddToggleTool(wxID_JUSTIFY_CENTER
, align_center_xpm
);
271 toolbar
->AddToggleTool(wxID_JUSTIFY_RIGHT
, align_right_xpm
);
272 toolbar
->AddSeparator();
273 toolbar
->AddHybridTool(wxID_NEW
, wxArtProvider::GetBitmap(wxART_NEW
, wxART_OTHER
, wxSize(16, 15)));
274 toolbar
->AddTool(wxID_OPEN
, wxArtProvider::GetBitmap(wxART_FILE_OPEN
, wxART_OTHER
, wxSize(16, 15)), "Open something");
275 toolbar
->AddTool(wxID_SAVE
, wxArtProvider::GetBitmap(wxART_FILE_SAVE
, wxART_OTHER
, wxSize(16, 15)), "Save something");
276 toolbar
->AddTool(wxID_SAVEAS
, wxArtProvider::GetBitmap(wxART_FILE_SAVE_AS
, wxART_OTHER
, wxSize(16, 15)), "Save something as ...");
277 toolbar
->EnableTool(wxID_OPEN
, false);
278 toolbar
->EnableTool(wxID_SAVE
, false);
279 toolbar
->EnableTool(wxID_SAVEAS
, false);
280 toolbar
->AddSeparator();
281 toolbar
->AddDropdownTool(wxID_UNDO
, wxArtProvider::GetBitmap(wxART_UNDO
, wxART_OTHER
, wxSize(16, 15)));
282 toolbar
->AddDropdownTool(wxID_REDO
, wxArtProvider::GetBitmap(wxART_REDO
, wxART_OTHER
, wxSize(16, 15)));
283 toolbar
->AddSeparator();
284 toolbar
->AddTool(wxID_ANY
, wxArtProvider::GetBitmap(wxART_REPORT_VIEW
, wxART_OTHER
, wxSize(16, 15)));
285 toolbar
->AddTool(wxID_ANY
, wxArtProvider::GetBitmap(wxART_LIST_VIEW
, wxART_OTHER
, wxSize(16, 15)));
286 toolbar
->AddSeparator();
287 toolbar
->AddHybridTool(ID_POSITION_LEFT
, position_left_xpm
,
288 "Align ribbonbar vertically\non the left\nfor demonstration purposes");
289 toolbar
->AddHybridTool(ID_POSITION_TOP
, position_top_xpm
,
290 "Align the ribbonbar horizontally\nat the top\nfor demonstration purposes");
291 toolbar
->AddSeparator();
292 toolbar
->AddHybridTool(wxID_PRINT
, wxArtProvider::GetBitmap(wxART_PRINT
, wxART_OTHER
, wxSize(16, 15)),
293 "This is the Print button tooltip\ndemonstrating a tooltip");
294 toolbar
->SetRows(2, 3);
296 wxRibbonPanel
*selection_panel
= new wxRibbonPanel(home
, wxID_ANY
, wxT("Selection"), wxBitmap(selection_panel_xpm
));
297 wxRibbonButtonBar
*selection
= new wxRibbonButtonBar(selection_panel
);
298 selection
->AddButton(ID_SELECTION_EXPAND_V
, wxT("Expand Vertically"), wxBitmap(expand_selection_v_xpm
),
299 "This is a tooltip for Expand Vertically\ndemonstrating a tooltip");
300 selection
->AddButton(ID_SELECTION_EXPAND_H
, wxT("Expand Horizontally"), wxBitmap(expand_selection_h_xpm
), wxEmptyString
);
301 selection
->AddButton(ID_SELECTION_CONTRACT
, wxT("Contract"), wxBitmap(auto_crop_selection_xpm
), wxBitmap(auto_crop_selection_small_xpm
));
303 wxRibbonPanel
*shapes_panel
= new wxRibbonPanel(home
, wxID_ANY
, wxT("Shapes"), wxBitmap(circle_small_xpm
));
304 wxRibbonButtonBar
*shapes
= new wxRibbonButtonBar(shapes_panel
);
305 shapes
->AddButton(ID_CIRCLE
, wxT("Circle"), wxBitmap(circle_xpm
), wxBitmap(circle_small_xpm
),
306 wxNullBitmap
, wxNullBitmap
, wxRIBBON_BUTTON_NORMAL
,
307 "This is a tooltip for the circle button\ndemonstrating another tooltip");
308 shapes
->AddButton(ID_CROSS
, wxT("Cross"), wxBitmap(cross_xpm
), wxEmptyString
);
309 shapes
->AddHybridButton(ID_TRIANGLE
, wxT("Triangle"), wxBitmap(triangle_xpm
));
310 shapes
->AddButton(ID_SQUARE
, wxT("Square"), wxBitmap(square_xpm
), wxEmptyString
);
311 shapes
->AddDropdownButton(ID_POLYGON
, wxT("Other Polygon"), wxBitmap(hexagon_xpm
), wxEmptyString
);
313 wxRibbonPanel
*sizer_panel
= new wxRibbonPanel(home
, wxID_ANY
, wxT("Panel with Sizer"),
314 wxNullBitmap
, wxDefaultPosition
, wxDefaultSize
,
315 wxRIBBON_PANEL_DEFAULT_STYLE
);
318 as
.Add("Item 1 using a box sizer now");
319 as
.Add("Item 2 using a box sizer now");
320 wxComboBox
* sizer_panelcombo
= new wxComboBox(sizer_panel
, wxID_ANY
,
322 wxDefaultPosition
, wxDefaultSize
,
325 wxComboBox
* sizer_panelcombo2
= new wxComboBox(sizer_panel
, wxID_ANY
,
327 wxDefaultPosition
, wxDefaultSize
,
330 sizer_panelcombo
->Select(0);
331 sizer_panelcombo2
->Select(1);
332 sizer_panelcombo
->SetMinSize(wxSize(150, -1));
333 sizer_panelcombo2
->SetMinSize(wxSize(150, -1));
335 //not using wxWrapSizer(wxHORIZONTAL) as it reports an incorrect min height
336 wxSizer
* sizer_panelsizer
= new wxBoxSizer(wxVERTICAL
);
337 sizer_panelsizer
->AddStretchSpacer(1);
338 sizer_panelsizer
->Add(sizer_panelcombo
, 0, wxALL
|wxEXPAND
, 2);
339 sizer_panelsizer
->Add(sizer_panelcombo2
, 0, wxALL
|wxEXPAND
, 2);
340 sizer_panelsizer
->AddStretchSpacer(1);
341 sizer_panel
->SetSizer(sizer_panelsizer
);
343 wxFont
label_font(8, wxFONTFAMILY_DEFAULT
, wxFONTSTYLE_NORMAL
, wxFONTWEIGHT_LIGHT
);
344 m_bitmap_creation_dc
.SetFont(label_font
);
346 wxRibbonPage
* scheme
= new wxRibbonPage(m_ribbon
, wxID_ANY
, wxT("Appearance"), eye_xpm
);
347 m_ribbon
->GetArtProvider()->GetColourScheme(&m_default_primary
,
348 &m_default_secondary
, &m_default_tertiary
);
349 wxRibbonPanel
*provider_panel
= new wxRibbonPanel(scheme
, wxID_ANY
,
350 wxT("Art"), wxNullBitmap
, wxDefaultPosition
, wxDefaultSize
, wxRIBBON_PANEL_NO_AUTO_MINIMISE
);
351 wxRibbonButtonBar
*provider_bar
= new wxRibbonButtonBar(provider_panel
, wxID_ANY
);
352 provider_bar
->AddButton(ID_DEFAULT_PROVIDER
, wxT("Default Provider"),
353 wxArtProvider::GetBitmap(wxART_QUESTION
, wxART_OTHER
, wxSize(32, 32)));
354 provider_bar
->AddButton(ID_AUI_PROVIDER
, wxT("AUI Provider"), aui_style_xpm
);
355 provider_bar
->AddButton(ID_MSW_PROVIDER
, wxT("MSW Provider"), msw_style_xpm
);
356 wxRibbonPanel
*primary_panel
= new wxRibbonPanel(scheme
, wxID_ANY
,
357 wxT("Primary Colour"), colours_xpm
);
358 m_primary_gallery
= PopulateColoursPanel(primary_panel
,
359 m_default_primary
, ID_PRIMARY_COLOUR
);
360 wxRibbonPanel
*secondary_panel
= new wxRibbonPanel(scheme
, wxID_ANY
,
361 wxT("Secondary Colour"), colours_xpm
);
362 m_secondary_gallery
= PopulateColoursPanel(secondary_panel
,
363 m_default_secondary
, ID_SECONDARY_COLOUR
);
366 wxRibbonPage
* page
= new wxRibbonPage(m_ribbon
, wxID_ANY
, wxT("UI Updated"), ribbon_xpm
);
367 wxRibbonPanel
*panel
= new wxRibbonPanel(page
, wxID_ANY
, wxT("Enable/Disable"), ribbon_xpm
);
368 wxRibbonButtonBar
*bar
= new wxRibbonButtonBar(panel
, wxID_ANY
);
369 bar
->AddButton(ID_DISABLED
, wxT("Disabled"), ribbon_xpm
);
370 bar
->AddButton(ID_ENABLE
, wxT("Enable"), ribbon_xpm
);
371 bar
->AddButton(ID_DISABLE
, wxT("Disable"), ribbon_xpm
);
372 bar
->AddButton(ID_UI_ENABLE_UPDATED
, wxT("Enable UI updated"), ribbon_xpm
);
373 bar
->EnableButton(ID_DISABLED
, false);
376 panel
= new wxRibbonPanel(page
, wxID_ANY
, wxT("Toggle"), ribbon_xpm
);
377 bar
= new wxRibbonButtonBar(panel
, wxID_ANY
);
378 bar
->AddButton(ID_CHECK
, wxT("Toggle"), ribbon_xpm
);
379 bar
->AddToggleButton(ID_UI_CHECK_UPDATED
, wxT("Toggled UI updated"), ribbon_xpm
);
382 panel
= new wxRibbonPanel(page
, wxID_ANY
, wxT("Change text"), ribbon_xpm
);
383 bar
= new wxRibbonButtonBar(panel
, wxID_ANY
);
384 bar
->AddButton(ID_CHANGE_TEXT1
, wxT("One"), ribbon_xpm
);
385 bar
->AddButton(ID_CHANGE_TEXT2
, wxT("Two"), ribbon_xpm
);
386 bar
->AddButton(ID_UI_CHANGE_TEXT_UPDATED
, wxT("Zero"), ribbon_xpm
);
388 new wxRibbonPage(m_ribbon
, wxID_ANY
, wxT("Empty Page"), empty_xpm
);
389 new wxRibbonPage(m_ribbon
, wxID_ANY
, wxT("Another Page"), empty_xpm
);
393 m_logwindow
= new wxTextCtrl(this, wxID_ANY
, wxEmptyString
,
394 wxDefaultPosition
, wxDefaultSize
, wxTE_MULTILINE
| wxTE_READONLY
|
395 wxTE_LEFT
| wxTE_BESTWRAP
| wxBORDER_NONE
);
397 m_togglePanels
= new wxToggleButton(this, ID_TOGGLE_PANELS
, "&Toggle panels");
398 m_togglePanels
->SetValue(true);
400 wxSizer
*s
= new wxBoxSizer(wxVERTICAL
);
402 s
->Add(m_ribbon
, 0, wxEXPAND
);
403 s
->Add(m_logwindow
, 1, wxEXPAND
);
404 s
->Add(m_togglePanels
, wxSizerFlags().Border());
409 void MyFrame::SetBarStyle(long style
)
412 m_ribbon
->SetWindowStyleFlag(style
);
413 wxBoxSizer
*pTopSize
= reinterpret_cast<wxBoxSizer
*>(GetSizer());
414 wxRibbonToolBar
*pToolbar
= wxDynamicCast(FindWindow(ID_MAIN_TOOLBAR
), wxRibbonToolBar
);
415 if(style
& wxRIBBON_BAR_FLOW_VERTICAL
)
417 m_ribbon
->SetTabCtrlMargins(10, 10);
418 pTopSize
->SetOrientation(wxHORIZONTAL
);
420 pToolbar
->SetRows(3, 5);
424 m_ribbon
->SetTabCtrlMargins(50, 20);
425 pTopSize
->SetOrientation(wxVERTICAL
);
427 pToolbar
->SetRows(2, 3);
438 class ColourClientData
: public wxClientData
441 ColourClientData(const wxString
& name
, const wxColour
& colour
)
442 : m_name(name
), m_colour(colour
) {}
444 const wxString
& GetName() const {return m_name
;}
445 const wxColour
& GetColour() const {return m_colour
;}
452 wxRibbonGallery
* MyFrame::PopulateColoursPanel(wxWindow
* panel
,
453 wxColour def
, int gallery_id
)
455 wxRibbonGallery
*gallery
= wxDynamicCast(panel
->FindWindow(gallery_id
), wxRibbonGallery
);
459 gallery
= new wxRibbonGallery(panel
, gallery_id
);
460 wxMemoryDC
& dc
= m_bitmap_creation_dc
;
461 wxRibbonGalleryItem
*def_item
=
462 AddColourToGallery(gallery
, wxT("Default"), dc
, &def
);
463 gallery
->SetSelection(def_item
);
464 AddColourToGallery(gallery
, wxT("BLUE"), dc
);
465 AddColourToGallery(gallery
, wxT("BLUE VIOLET"), dc
);
466 AddColourToGallery(gallery
, wxT("BROWN"), dc
);
467 AddColourToGallery(gallery
, wxT("CADET BLUE"), dc
);
468 AddColourToGallery(gallery
, wxT("CORAL"), dc
);
469 AddColourToGallery(gallery
, wxT("CYAN"), dc
);
470 AddColourToGallery(gallery
, wxT("DARK GREEN"), dc
);
471 AddColourToGallery(gallery
, wxT("DARK ORCHID"), dc
);
472 AddColourToGallery(gallery
, wxT("FIREBRICK"), dc
);
473 AddColourToGallery(gallery
, wxT("GOLD"), dc
);
474 AddColourToGallery(gallery
, wxT("GOLDENROD"), dc
);
475 AddColourToGallery(gallery
, wxT("GREEN"), dc
);
476 AddColourToGallery(gallery
, wxT("INDIAN RED"), dc
);
477 AddColourToGallery(gallery
, wxT("KHAKI"), dc
);
478 AddColourToGallery(gallery
, wxT("LIGHT BLUE"), dc
);
479 AddColourToGallery(gallery
, wxT("LIME GREEN"), dc
);
480 AddColourToGallery(gallery
, wxT("MAGENTA"), dc
);
481 AddColourToGallery(gallery
, wxT("MAROON"), dc
);
482 AddColourToGallery(gallery
, wxT("NAVY"), dc
);
483 AddColourToGallery(gallery
, wxT("ORANGE"), dc
);
484 AddColourToGallery(gallery
, wxT("ORCHID"), dc
);
485 AddColourToGallery(gallery
, wxT("PINK"), dc
);
486 AddColourToGallery(gallery
, wxT("PLUM"), dc
);
487 AddColourToGallery(gallery
, wxT("PURPLE"), dc
);
488 AddColourToGallery(gallery
, wxT("RED"), dc
);
489 AddColourToGallery(gallery
, wxT("SALMON"), dc
);
490 AddColourToGallery(gallery
, wxT("SEA GREEN"), dc
);
491 AddColourToGallery(gallery
, wxT("SIENNA"), dc
);
492 AddColourToGallery(gallery
, wxT("SKY BLUE"), dc
);
493 AddColourToGallery(gallery
, wxT("TAN"), dc
);
494 AddColourToGallery(gallery
, wxT("THISTLE"), dc
);
495 AddColourToGallery(gallery
, wxT("TURQUOISE"), dc
);
496 AddColourToGallery(gallery
, wxT("VIOLET"), dc
);
497 AddColourToGallery(gallery
, wxT("VIOLET RED"), dc
);
498 AddColourToGallery(gallery
, wxT("WHEAT"), dc
);
499 AddColourToGallery(gallery
, wxT("WHITE"), dc
);
500 AddColourToGallery(gallery
, wxT("YELLOW"), dc
);
505 wxColour
MyFrame::GetGalleryColour(wxRibbonGallery
*gallery
,
506 wxRibbonGalleryItem
* item
, wxString
* name
)
508 ColourClientData
*data
= (ColourClientData
*)gallery
->GetItemClientObject(item
);
510 *name
= data
->GetName();
511 return data
->GetColour();
514 void MyFrame::OnHoveredColourChange(wxRibbonGalleryEvent
& evt
)
516 // Set the background of the gallery to the hovered colour, or back to the
517 // default if there is no longer a hovered item.
519 wxRibbonGallery
*gallery
= evt
.GetGallery();
520 wxRibbonArtProvider
*provider
= gallery
->GetArtProvider();
522 if(evt
.GetGalleryItem() != NULL
)
524 if(provider
== m_ribbon
->GetArtProvider())
526 provider
= provider
->Clone();
527 gallery
->SetArtProvider(provider
);
529 provider
->SetColour(wxRIBBON_ART_GALLERY_HOVER_BACKGROUND_COLOUR
,
530 GetGalleryColour(evt
.GetGallery(), evt
.GetGalleryItem(), NULL
));
534 if(provider
!= m_ribbon
->GetArtProvider())
536 gallery
->SetArtProvider(m_ribbon
->GetArtProvider());
542 void MyFrame::OnPrimaryColourSelect(wxRibbonGalleryEvent
& evt
)
545 wxColour colour
= GetGalleryColour(evt
.GetGallery(), evt
.GetGalleryItem(), &name
);
546 AddText(wxT("Colour \"") + name
+ wxT("\" selected as primary."));
547 wxColour secondary
, tertiary
;
548 m_ribbon
->GetArtProvider()->GetColourScheme(NULL
, &secondary
, &tertiary
);
549 m_ribbon
->GetArtProvider()->SetColourScheme(colour
, secondary
, tertiary
);
550 ResetGalleryArtProviders();
554 void MyFrame::OnSecondaryColourSelect(wxRibbonGalleryEvent
& evt
)
557 wxColour colour
= GetGalleryColour(evt
.GetGallery(), evt
.GetGalleryItem(), &name
);
558 AddText(wxT("Colour \"") + name
+ wxT("\" selected as secondary."));
559 wxColour primary
, tertiary
;
560 m_ribbon
->GetArtProvider()->GetColourScheme(&primary
, NULL
, &tertiary
);
561 m_ribbon
->GetArtProvider()->SetColourScheme(primary
, colour
, tertiary
);
562 ResetGalleryArtProviders();
566 void MyFrame::ResetGalleryArtProviders()
568 if(m_primary_gallery
->GetArtProvider() != m_ribbon
->GetArtProvider())
570 delete m_primary_gallery
->GetArtProvider();
571 m_primary_gallery
->SetArtProvider(m_ribbon
->GetArtProvider());
573 if(m_secondary_gallery
->GetArtProvider() != m_ribbon
->GetArtProvider())
575 delete m_secondary_gallery
->GetArtProvider();
576 m_secondary_gallery
->SetArtProvider(m_ribbon
->GetArtProvider());
580 void MyFrame::OnChangeText1(wxRibbonButtonBarEvent
& WXUNUSED(evt
))
582 m_new_text
= wxT("One");
585 void MyFrame::OnChangeText2(wxRibbonButtonBarEvent
& WXUNUSED(evt
))
587 m_new_text
= wxT("Two");
590 void MyFrame::OnEnable(wxRibbonButtonBarEvent
& WXUNUSED(evt
))
595 void MyFrame::OnDisable(wxRibbonButtonBarEvent
& WXUNUSED(evt
))
600 void MyFrame::OnCheck(wxRibbonButtonBarEvent
& WXUNUSED(evt
))
602 m_bChecked
= !m_bChecked
;
605 void MyFrame::OnEnableUpdateUI(wxUpdateUIEvent
& evt
)
607 evt
.Enable(m_bEnabled
);
610 void MyFrame::OnCheckUpdateUI(wxUpdateUIEvent
& evt
)
612 evt
.Check(m_bChecked
);
615 void MyFrame::OnChangeTextUpdateUI(wxUpdateUIEvent
& evt
)
617 if ( !m_new_text
.IsEmpty() )
619 evt
.SetText(m_new_text
);
620 m_new_text
= wxT("");
624 void MyFrame::OnSelectionExpandHButton(wxRibbonButtonBarEvent
& WXUNUSED(evt
))
626 AddText(wxT("Expand selection horizontally button clicked."));
629 void MyFrame::OnSelectionExpandVButton(wxRibbonButtonBarEvent
& WXUNUSED(evt
))
631 AddText(wxT("Expand selection vertically button clicked."));
634 void MyFrame::OnSelectionContractButton(wxRibbonButtonBarEvent
& WXUNUSED(evt
))
636 AddText(wxT("Contract selection button clicked."));
639 void MyFrame::OnCircleButton(wxRibbonButtonBarEvent
& WXUNUSED(evt
))
641 AddText(wxT("Circle button clicked."));
644 void MyFrame::OnCrossButton(wxRibbonButtonBarEvent
& WXUNUSED(evt
))
646 AddText(wxT("Cross button clicked."));
649 void MyFrame::OnTriangleButton(wxRibbonButtonBarEvent
& WXUNUSED(evt
))
651 AddText(wxT("Triangle button clicked."));
654 void MyFrame::OnTriangleDropdown(wxRibbonButtonBarEvent
& evt
)
657 menu
.Append(wxID_ANY
, wxT("Equilateral"));
658 menu
.Append(wxID_ANY
, wxT("Isosceles"));
659 menu
.Append(wxID_ANY
, wxT("Scalene"));
661 evt
.PopupMenu(&menu
);
664 void MyFrame::OnSquareButton(wxRibbonButtonBarEvent
& WXUNUSED(evt
))
666 AddText(wxT("Square button clicked."));
669 void MyFrame::OnPolygonDropdown(wxRibbonButtonBarEvent
& evt
)
672 menu
.Append(wxID_ANY
, wxT("Pentagon (5 sided)"));
673 menu
.Append(wxID_ANY
, wxT("Hexagon (6 sided)"));
674 menu
.Append(wxID_ANY
, wxT("Heptagon (7 sided)"));
675 menu
.Append(wxID_ANY
, wxT("Octogon (8 sided)"));
676 menu
.Append(wxID_ANY
, wxT("Nonagon (9 sided)"));
677 menu
.Append(wxID_ANY
, wxT("Decagon (10 sided)"));
679 evt
.PopupMenu(&menu
);
682 void MyFrame::OnJustify(wxRibbonToolBarEvent
& evt
)
684 long style
= m_logwindow
->GetWindowStyle() &
685 ~(wxTE_LEFT
| wxTE_CENTER
| wxTE_RIGHT
);
688 case wxID_JUSTIFY_LEFT
:
689 m_logwindow
->SetWindowStyle(style
| wxTE_LEFT
);
691 case wxID_JUSTIFY_CENTER
:
692 m_logwindow
->SetWindowStyle(style
| wxTE_CENTER
);
694 case wxID_JUSTIFY_RIGHT
:
695 m_logwindow
->SetWindowStyle(style
| wxTE_RIGHT
);
700 void MyFrame::OnJustifyUpdateUI(wxUpdateUIEvent
& evt
)
704 case wxID_JUSTIFY_LEFT
:
705 evt
.Check(!m_logwindow
->HasFlag(wxTE_CENTER
| wxTE_RIGHT
));
707 case wxID_JUSTIFY_CENTER
:
708 evt
.Check(m_logwindow
->HasFlag(wxTE_CENTER
));
710 case wxID_JUSTIFY_RIGHT
:
711 evt
.Check(m_logwindow
->HasFlag(wxTE_RIGHT
));
716 void MyFrame::OnNew(wxRibbonToolBarEvent
& WXUNUSED(evt
))
718 AddText(wxT("New button clicked."));
721 void MyFrame::OnNewDropdown(wxRibbonToolBarEvent
& evt
)
724 menu
.Append(wxID_ANY
, wxT("New Document"));
725 menu
.Append(wxID_ANY
, wxT("New Template"));
726 menu
.Append(wxID_ANY
, wxT("New Mail"));
728 evt
.PopupMenu(&menu
);
731 void MyFrame::OnPrint(wxRibbonToolBarEvent
& WXUNUSED(evt
))
733 AddText(wxT("Print button clicked."));
736 void MyFrame::OnPrintDropdown(wxRibbonToolBarEvent
& evt
)
739 menu
.Append(wxID_ANY
, wxT("Print"));
740 menu
.Append(wxID_ANY
, wxT("Preview"));
741 menu
.Append(wxID_ANY
, wxT("Options"));
743 evt
.PopupMenu(&menu
);
746 void MyFrame::OnRedoDropdown(wxRibbonToolBarEvent
& evt
)
749 menu
.Append(wxID_ANY
, wxT("Redo E"));
750 menu
.Append(wxID_ANY
, wxT("Redo F"));
751 menu
.Append(wxID_ANY
, wxT("Redo G"));
753 evt
.PopupMenu(&menu
);
756 void MyFrame::OnUndoDropdown(wxRibbonToolBarEvent
& evt
)
759 menu
.Append(wxID_ANY
, wxT("Undo C"));
760 menu
.Append(wxID_ANY
, wxT("Undo B"));
761 menu
.Append(wxID_ANY
, wxT("Undo A"));
763 evt
.PopupMenu(&menu
);
766 void MyFrame::OnPositionTopLabels(wxCommandEvent
& WXUNUSED(evt
))
768 SetBarStyle(wxRIBBON_BAR_DEFAULT_STYLE
);
771 void MyFrame::OnPositionTopIcons(wxCommandEvent
& WXUNUSED(evt
))
773 SetBarStyle((wxRIBBON_BAR_DEFAULT_STYLE
&~wxRIBBON_BAR_SHOW_PAGE_LABELS
)
774 | wxRIBBON_BAR_SHOW_PAGE_ICONS
);
777 void MyFrame::OnPositionTopBoth(wxCommandEvent
& WXUNUSED(evt
))
779 SetBarStyle(wxRIBBON_BAR_DEFAULT_STYLE
| wxRIBBON_BAR_SHOW_PAGE_ICONS
);
782 void MyFrame::OnPositionLeftLabels(wxCommandEvent
& WXUNUSED(evt
))
784 SetBarStyle(wxRIBBON_BAR_DEFAULT_STYLE
| wxRIBBON_BAR_FLOW_VERTICAL
);
787 void MyFrame::OnPositionLeftIcons(wxCommandEvent
& WXUNUSED(evt
))
789 SetBarStyle((wxRIBBON_BAR_DEFAULT_STYLE
&~wxRIBBON_BAR_SHOW_PAGE_LABELS
) |
790 wxRIBBON_BAR_SHOW_PAGE_ICONS
| wxRIBBON_BAR_FLOW_VERTICAL
);
793 void MyFrame::OnPositionLeftBoth(wxCommandEvent
& WXUNUSED(evt
))
795 SetBarStyle(wxRIBBON_BAR_DEFAULT_STYLE
| wxRIBBON_BAR_SHOW_PAGE_ICONS
|
796 wxRIBBON_BAR_FLOW_VERTICAL
);
799 void MyFrame::OnPositionTop(wxRibbonToolBarEvent
& evt
)
801 OnPositionTopLabels(evt
);
804 void MyFrame::OnPositionTopDropdown(wxRibbonToolBarEvent
& evt
)
807 menu
.Append(ID_POSITION_TOP
, wxT("Top with Labels"));
808 menu
.Append(ID_POSITION_TOP_ICONS
, wxT("Top with Icons"));
809 menu
.Append(ID_POSITION_TOP_BOTH
, wxT("Top with Both"));
810 evt
.PopupMenu(&menu
);
813 void MyFrame::OnPositionLeft(wxRibbonToolBarEvent
& evt
)
815 OnPositionLeftIcons(evt
);
818 void MyFrame::OnPositionLeftDropdown(wxRibbonToolBarEvent
& evt
)
821 menu
.Append(ID_POSITION_LEFT
, wxT("Left with Icons"));
822 menu
.Append(ID_POSITION_LEFT_LABELS
, wxT("Left with Labels"));
823 menu
.Append(ID_POSITION_LEFT_BOTH
, wxT("Left with Both"));
824 evt
.PopupMenu(&menu
);
827 void MyFrame::OnTogglePanels(wxCommandEvent
& WXUNUSED(evt
))
829 m_ribbon
->ShowPanels(m_togglePanels
->GetValue());
832 void MyFrame::OnExtButton(wxRibbonPanelEvent
& WXUNUSED(evt
))
834 wxMessageBox("Extension button clicked");
837 void MyFrame::AddText(wxString msg
)
839 m_logwindow
->AppendText(msg
);
840 m_logwindow
->AppendText(wxT("\n"));
841 m_ribbon
->DismissExpandedPanel();
844 wxRibbonGalleryItem
* MyFrame::AddColourToGallery(wxRibbonGallery
*gallery
,
845 wxString colour
, wxMemoryDC
& dc
,
848 wxRibbonGalleryItem
* item
= NULL
;
850 if (colour
!= wxT("Default"))
851 c
= wxColour(colour
);
856 const int iWidth
= 64;
857 const int iHeight
= 40;
859 wxBitmap
bitmap(iWidth
, iHeight
);
860 dc
.SelectObject(bitmap
);
862 dc
.SetPen(*wxBLACK_PEN
);
864 dc
.DrawRectangle(0, 0, iWidth
, iHeight
);
866 colour
= colour
.Mid(0, 1) + colour
.Mid(1).Lower();
867 wxSize size
= dc
.GetTextExtent(colour
);
868 wxColour foreground
= wxColour(~c
.Red(), ~c
.Green(), ~c
.Blue());
869 if(abs(foreground
.Red() - c
.Red()) + abs(foreground
.Blue() - c
.Blue())
870 + abs(foreground
.Green() - c
.Green()) < 64)
872 // Foreground too similar to background - use a different
873 // strategy to find a contrasting colour
874 foreground
= wxColour((c
.Red() + 64) % 256, 255 - c
.Green(),
875 (c
.Blue() + 192) % 256);
877 dc
.SetTextForeground(foreground
);
878 dc
.DrawText(colour
, (iWidth
- size
.GetWidth() + 1) / 2,
879 (iHeight
- size
.GetHeight()) / 2);
880 dc
.SelectObjectAsSource(wxNullBitmap
);
882 item
= gallery
->Append(bitmap
, wxID_ANY
);
883 gallery
->SetItemClientObject(item
, new ColourClientData(colour
, c
));
888 void MyFrame::OnColourGalleryButton(wxCommandEvent
& evt
)
890 wxRibbonGallery
*gallery
= wxDynamicCast(evt
.GetEventObject(), wxRibbonGallery
);
894 m_ribbon
->DismissExpandedPanel();
895 if(gallery
->GetSelection())
896 m_colour_data
.SetColour(GetGalleryColour(gallery
, gallery
->GetSelection(), NULL
));
897 wxColourDialog
dlg(this, &m_colour_data
);
898 if(dlg
.ShowModal() == wxID_OK
)
900 m_colour_data
= dlg
.GetColourData();
901 wxColour clr
= m_colour_data
.GetColour();
903 // Try to find colour in gallery
904 wxRibbonGalleryItem
*item
= NULL
;
905 for(unsigned int i
= 0; i
< gallery
->GetCount(); ++i
)
907 item
= gallery
->GetItem(i
);
908 if(GetGalleryColour(gallery
, item
, NULL
) == clr
)
914 // Colour not in gallery - add it
917 item
= AddColourToGallery(gallery
,
918 clr
.GetAsString(wxC2S_HTML_SYNTAX
), m_bitmap_creation_dc
,
924 gallery
->EnsureVisible(item
);
925 gallery
->SetSelection(item
);
927 // Send an event to respond to the selection change
928 wxRibbonGalleryEvent
dummy(wxEVT_COMMAND_RIBBONGALLERY_SELECTED
, gallery
->GetId());
929 dummy
.SetEventObject(gallery
);
930 dummy
.SetGallery(gallery
);
931 dummy
.SetGalleryItem(item
);
932 ProcessWindowEvent(dummy
);
936 void MyFrame::OnDefaultProvider(wxRibbonButtonBarEvent
& WXUNUSED(evt
))
938 m_ribbon
->DismissExpandedPanel();
939 SetArtProvider(new wxRibbonDefaultArtProvider
);
942 void MyFrame::OnAUIProvider(wxRibbonButtonBarEvent
& WXUNUSED(evt
))
944 m_ribbon
->DismissExpandedPanel();
945 SetArtProvider(new wxRibbonAUIArtProvider
);
948 void MyFrame::OnMSWProvider(wxRibbonButtonBarEvent
& WXUNUSED(evt
))
950 m_ribbon
->DismissExpandedPanel();
951 SetArtProvider(new wxRibbonMSWArtProvider
);
954 void MyFrame::SetArtProvider(wxRibbonArtProvider
*prov
)
957 m_ribbon
->SetArtProvider(prov
);
959 prov
->GetColourScheme(&m_default_primary
, &m_default_secondary
,
960 &m_default_tertiary
);
961 PopulateColoursPanel(m_primary_gallery
->GetParent(), m_default_primary
,
963 PopulateColoursPanel(m_secondary_gallery
->GetParent(), m_default_secondary
,
964 ID_SECONDARY_COLOUR
);
968 GetSizer()->Layout();