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
,
89 void OnEnableUpdateUI(wxUpdateUIEvent
& evt
);
90 void OnCheckUpdateUI(wxUpdateUIEvent
& evt
);
91 void OnChangeTextUpdateUI(wxUpdateUIEvent
& evt
);
92 void OnCheck(wxRibbonButtonBarEvent
& evt
);
93 void OnEnable(wxRibbonButtonBarEvent
& evt
);
94 void OnDisable(wxRibbonButtonBarEvent
& evt
);
95 void OnChangeText1(wxRibbonButtonBarEvent
& evt
);
96 void OnChangeText2(wxRibbonButtonBarEvent
& evt
);
97 void OnCircleButton(wxRibbonButtonBarEvent
& evt
);
98 void OnCrossButton(wxRibbonButtonBarEvent
& evt
);
99 void OnTriangleButton(wxRibbonButtonBarEvent
& evt
);
100 void OnTriangleDropdown(wxRibbonButtonBarEvent
& evt
);
101 void OnSquareButton(wxRibbonButtonBarEvent
& evt
);
102 void OnPolygonDropdown(wxRibbonButtonBarEvent
& evt
);
103 void OnSelectionExpandVButton(wxRibbonButtonBarEvent
& evt
);
104 void OnSelectionExpandHButton(wxRibbonButtonBarEvent
& evt
);
105 void OnSelectionContractButton(wxRibbonButtonBarEvent
& evt
);
106 void OnHoveredColourChange(wxRibbonGalleryEvent
& evt
);
107 void OnPrimaryColourSelect(wxRibbonGalleryEvent
& evt
);
108 void OnSecondaryColourSelect(wxRibbonGalleryEvent
& evt
);
109 void OnColourGalleryButton(wxCommandEvent
& evt
);
110 void OnDefaultProvider(wxRibbonButtonBarEvent
& evt
);
111 void OnAUIProvider(wxRibbonButtonBarEvent
& evt
);
112 void OnMSWProvider(wxRibbonButtonBarEvent
& evt
);
113 void OnJustify(wxRibbonToolBarEvent
& evt
);
114 void OnJustifyUpdateUI(wxUpdateUIEvent
& evt
);
115 void OnNew(wxRibbonToolBarEvent
& evt
);
116 void OnNewDropdown(wxRibbonToolBarEvent
& evt
);
117 void OnPrint(wxRibbonToolBarEvent
& evt
);
118 void OnPrintDropdown(wxRibbonToolBarEvent
& evt
);
119 void OnRedoDropdown(wxRibbonToolBarEvent
& evt
);
120 void OnUndoDropdown(wxRibbonToolBarEvent
& evt
);
121 void OnPositionTop(wxRibbonToolBarEvent
& evt
);
122 void OnPositionTopLabels(wxCommandEvent
& evt
);
123 void OnPositionTopIcons(wxCommandEvent
& evt
);
124 void OnPositionTopBoth(wxCommandEvent
& evt
);
125 void OnPositionTopDropdown(wxRibbonToolBarEvent
& evt
);
126 void OnPositionLeft(wxRibbonToolBarEvent
& evt
);
127 void OnPositionLeftLabels(wxCommandEvent
& evt
);
128 void OnPositionLeftIcons(wxCommandEvent
& evt
);
129 void OnPositionLeftBoth(wxCommandEvent
& evt
);
130 void OnPositionLeftDropdown(wxRibbonToolBarEvent
& evt
);
131 void OnRemovePage(wxRibbonButtonBarEvent
& evt
);
132 void OnTogglePanels(wxCommandEvent
& evt
);
134 void OnExtButton(wxRibbonPanelEvent
& evt
);
137 wxRibbonGallery
* PopulateColoursPanel(wxWindow
* panel
, wxColour def
,
139 void AddText(wxString msg
);
140 wxRibbonGalleryItem
* AddColourToGallery(wxRibbonGallery
*gallery
,
141 wxString name
, wxMemoryDC
& dc
, wxColour
* value
= NULL
);
142 wxColour
GetGalleryColour(wxRibbonGallery
*gallery
,
143 wxRibbonGalleryItem
* item
, wxString
* name
);
144 void ResetGalleryArtProviders();
145 void SetArtProvider(wxRibbonArtProvider
* prov
);
146 void SetBarStyle(long style
);
148 wxRibbonBar
* m_ribbon
;
149 wxRibbonGallery
* m_primary_gallery
;
150 wxRibbonGallery
* m_secondary_gallery
;
151 wxTextCtrl
* m_logwindow
;
152 wxToggleButton
* m_togglePanels
;
154 wxColourData m_colour_data
;
155 wxColour m_default_primary
;
156 wxColour m_default_secondary
;
157 wxColour m_default_tertiary
;
158 wxMemoryDC m_bitmap_creation_dc
;
163 DECLARE_EVENT_TABLE()
166 // -- implementations --
173 wxFrame
* frame
= new MyFrame
;
179 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
180 EVT_RIBBONBUTTONBAR_CLICKED(ID_ENABLE
, MyFrame::OnEnable
)
181 EVT_RIBBONBUTTONBAR_CLICKED(ID_DISABLE
, MyFrame::OnDisable
)
182 EVT_UPDATE_UI(ID_UI_ENABLE_UPDATED
, MyFrame::OnEnableUpdateUI
)
183 EVT_RIBBONBUTTONBAR_CLICKED(ID_CHECK
, MyFrame::OnCheck
)
184 EVT_UPDATE_UI(ID_UI_CHECK_UPDATED
, MyFrame::OnCheckUpdateUI
)
185 EVT_RIBBONBUTTONBAR_CLICKED(ID_CHANGE_TEXT1
, MyFrame::OnChangeText1
)
186 EVT_RIBBONBUTTONBAR_CLICKED(ID_CHANGE_TEXT2
, MyFrame::OnChangeText2
)
187 EVT_UPDATE_UI(ID_UI_CHANGE_TEXT_UPDATED
, MyFrame::OnChangeTextUpdateUI
)
188 EVT_RIBBONBUTTONBAR_CLICKED(ID_DEFAULT_PROVIDER
, MyFrame::OnDefaultProvider
)
189 EVT_RIBBONBUTTONBAR_CLICKED(ID_AUI_PROVIDER
, MyFrame::OnAUIProvider
)
190 EVT_RIBBONBUTTONBAR_CLICKED(ID_MSW_PROVIDER
, MyFrame::OnMSWProvider
)
191 EVT_RIBBONBUTTONBAR_CLICKED(ID_SELECTION_EXPAND_H
, MyFrame::OnSelectionExpandHButton
)
192 EVT_RIBBONBUTTONBAR_CLICKED(ID_SELECTION_EXPAND_V
, MyFrame::OnSelectionExpandVButton
)
193 EVT_RIBBONBUTTONBAR_CLICKED(ID_SELECTION_CONTRACT
, MyFrame::OnSelectionContractButton
)
194 EVT_RIBBONBUTTONBAR_CLICKED(ID_CIRCLE
, MyFrame::OnCircleButton
)
195 EVT_RIBBONBUTTONBAR_CLICKED(ID_CROSS
, MyFrame::OnCrossButton
)
196 EVT_RIBBONBUTTONBAR_CLICKED(ID_TRIANGLE
, MyFrame::OnTriangleButton
)
197 EVT_RIBBONBUTTONBAR_CLICKED(ID_SQUARE
, MyFrame::OnSquareButton
)
198 EVT_RIBBONBUTTONBAR_DROPDOWN_CLICKED(ID_TRIANGLE
, MyFrame::OnTriangleDropdown
)
199 EVT_RIBBONBUTTONBAR_DROPDOWN_CLICKED(ID_POLYGON
, MyFrame::OnPolygonDropdown
)
200 EVT_RIBBONGALLERY_HOVER_CHANGED(ID_PRIMARY_COLOUR
, MyFrame::OnHoveredColourChange
)
201 EVT_RIBBONGALLERY_HOVER_CHANGED(ID_SECONDARY_COLOUR
, MyFrame::OnHoveredColourChange
)
202 EVT_RIBBONGALLERY_SELECTED(ID_PRIMARY_COLOUR
, MyFrame::OnPrimaryColourSelect
)
203 EVT_RIBBONGALLERY_SELECTED(ID_SECONDARY_COLOUR
, MyFrame::OnSecondaryColourSelect
)
204 EVT_RIBBONTOOLBAR_CLICKED(wxID_JUSTIFY_LEFT
, MyFrame::OnJustify
)
205 EVT_RIBBONTOOLBAR_CLICKED(wxID_JUSTIFY_CENTER
, MyFrame::OnJustify
)
206 EVT_RIBBONTOOLBAR_CLICKED(wxID_JUSTIFY_RIGHT
, MyFrame::OnJustify
)
207 EVT_UPDATE_UI(wxID_JUSTIFY_LEFT
, MyFrame::OnJustifyUpdateUI
)
208 EVT_UPDATE_UI(wxID_JUSTIFY_CENTER
, MyFrame::OnJustifyUpdateUI
)
209 EVT_UPDATE_UI(wxID_JUSTIFY_RIGHT
, MyFrame::OnJustifyUpdateUI
)
210 EVT_RIBBONTOOLBAR_CLICKED(wxID_NEW
, MyFrame::OnNew
)
211 EVT_RIBBONTOOLBAR_DROPDOWN_CLICKED(wxID_NEW
, MyFrame::OnNewDropdown
)
212 EVT_RIBBONTOOLBAR_CLICKED(wxID_PRINT
, MyFrame::OnPrint
)
213 EVT_RIBBONTOOLBAR_DROPDOWN_CLICKED(wxID_PRINT
, MyFrame::OnPrintDropdown
)
214 EVT_RIBBONTOOLBAR_DROPDOWN_CLICKED(wxID_REDO
, MyFrame::OnRedoDropdown
)
215 EVT_RIBBONTOOLBAR_DROPDOWN_CLICKED(wxID_UNDO
, MyFrame::OnUndoDropdown
)
216 EVT_RIBBONTOOLBAR_CLICKED(ID_POSITION_LEFT
, MyFrame::OnPositionLeft
)
217 EVT_RIBBONTOOLBAR_DROPDOWN_CLICKED(ID_POSITION_LEFT
, MyFrame::OnPositionLeftDropdown
)
218 EVT_RIBBONTOOLBAR_CLICKED(ID_POSITION_TOP
, MyFrame::OnPositionTop
)
219 EVT_RIBBONTOOLBAR_DROPDOWN_CLICKED(ID_POSITION_TOP
, MyFrame::OnPositionTopDropdown
)
220 EVT_BUTTON(ID_PRIMARY_COLOUR
, MyFrame::OnColourGalleryButton
)
221 EVT_BUTTON(ID_SECONDARY_COLOUR
, MyFrame::OnColourGalleryButton
)
222 EVT_MENU(ID_POSITION_LEFT
, MyFrame::OnPositionLeftIcons
)
223 EVT_MENU(ID_POSITION_LEFT_LABELS
, MyFrame::OnPositionLeftLabels
)
224 EVT_MENU(ID_POSITION_LEFT_BOTH
, MyFrame::OnPositionLeftBoth
)
225 EVT_MENU(ID_POSITION_TOP
, MyFrame::OnPositionTopLabels
)
226 EVT_MENU(ID_POSITION_TOP_ICONS
, MyFrame::OnPositionTopIcons
)
227 EVT_MENU(ID_POSITION_TOP_BOTH
, MyFrame::OnPositionTopBoth
)
228 EVT_TOGGLEBUTTON(ID_TOGGLE_PANELS
, MyFrame::OnTogglePanels
)
229 EVT_RIBBONPANEL_EXTBUTTON_ACTIVATED(wxID_ANY
, MyFrame::OnExtButton
)
230 EVT_RIBBONBUTTONBAR_CLICKED(ID_REMOVE_PAGE
, MyFrame::OnRemovePage
)
233 #include "align_center.xpm"
234 #include "align_left.xpm"
235 #include "align_right.xpm"
236 #include "aui_style.xpm"
237 #include "auto_crop_selection.xpm"
238 #include "auto_crop_selection_small.xpm"
239 #include "circle.xpm"
240 #include "circle_small.xpm"
241 #include "colours.xpm"
244 #include "expand_selection_v.xpm"
245 #include "expand_selection_h.xpm"
247 #include "hexagon.xpm"
248 #include "msw_style.xpm"
249 #include "position_left_small.xpm"
250 #include "position_top_small.xpm"
251 #include "ribbon.xpm"
252 #include "selection_panel.xpm"
253 #include "square.xpm"
254 #include "triangle.xpm"
257 : wxFrame(NULL
, wxID_ANY
, wxT("wxRibbon Sample Application"), wxDefaultPosition
, wxSize(800, 600), wxDEFAULT_FRAME_STYLE
)
259 m_ribbon
= new wxRibbonBar(this, wxID_ANY
,
260 wxDefaultPosition
, wxDefaultSize
,
261 wxRIBBON_BAR_DEFAULT_STYLE
|
262 wxRIBBON_BAR_SHOW_PANEL_EXT_BUTTONS
);
265 wxRibbonPage
* home
= new wxRibbonPage(m_ribbon
, wxID_ANY
, wxT("Examples"), ribbon_xpm
);
266 wxRibbonPanel
*toolbar_panel
= new wxRibbonPanel(home
, wxID_ANY
, wxT("Toolbar"),
267 wxNullBitmap
, wxDefaultPosition
, wxDefaultSize
,
268 wxRIBBON_PANEL_NO_AUTO_MINIMISE
|
269 wxRIBBON_PANEL_EXT_BUTTON
);
270 wxRibbonToolBar
*toolbar
= new wxRibbonToolBar(toolbar_panel
, ID_MAIN_TOOLBAR
);
271 toolbar
->AddToggleTool(wxID_JUSTIFY_LEFT
, align_left_xpm
);
272 toolbar
->AddToggleTool(wxID_JUSTIFY_CENTER
, align_center_xpm
);
273 toolbar
->AddToggleTool(wxID_JUSTIFY_RIGHT
, align_right_xpm
);
274 toolbar
->AddSeparator();
275 toolbar
->AddHybridTool(wxID_NEW
, wxArtProvider::GetBitmap(wxART_NEW
, wxART_OTHER
, wxSize(16, 15)));
276 toolbar
->AddTool(wxID_OPEN
, wxArtProvider::GetBitmap(wxART_FILE_OPEN
, wxART_OTHER
, wxSize(16, 15)), "Open something");
277 toolbar
->AddTool(wxID_SAVE
, wxArtProvider::GetBitmap(wxART_FILE_SAVE
, wxART_OTHER
, wxSize(16, 15)), "Save something");
278 toolbar
->AddTool(wxID_SAVEAS
, wxArtProvider::GetBitmap(wxART_FILE_SAVE_AS
, wxART_OTHER
, wxSize(16, 15)), "Save something as ...");
279 toolbar
->EnableTool(wxID_OPEN
, false);
280 toolbar
->EnableTool(wxID_SAVE
, false);
281 toolbar
->EnableTool(wxID_SAVEAS
, false);
282 toolbar
->AddSeparator();
283 toolbar
->AddDropdownTool(wxID_UNDO
, wxArtProvider::GetBitmap(wxART_UNDO
, wxART_OTHER
, wxSize(16, 15)));
284 toolbar
->AddDropdownTool(wxID_REDO
, wxArtProvider::GetBitmap(wxART_REDO
, wxART_OTHER
, wxSize(16, 15)));
285 toolbar
->AddSeparator();
286 toolbar
->AddTool(wxID_ANY
, wxArtProvider::GetBitmap(wxART_REPORT_VIEW
, wxART_OTHER
, wxSize(16, 15)));
287 toolbar
->AddTool(wxID_ANY
, wxArtProvider::GetBitmap(wxART_LIST_VIEW
, wxART_OTHER
, wxSize(16, 15)));
288 toolbar
->AddSeparator();
289 toolbar
->AddHybridTool(ID_POSITION_LEFT
, position_left_xpm
,
290 "Align ribbonbar vertically\non the left\nfor demonstration purposes");
291 toolbar
->AddHybridTool(ID_POSITION_TOP
, position_top_xpm
,
292 "Align the ribbonbar horizontally\nat the top\nfor demonstration purposes");
293 toolbar
->AddSeparator();
294 toolbar
->AddHybridTool(wxID_PRINT
, wxArtProvider::GetBitmap(wxART_PRINT
, wxART_OTHER
, wxSize(16, 15)),
295 "This is the Print button tooltip\ndemonstrating a tooltip");
296 toolbar
->SetRows(2, 3);
298 wxRibbonPanel
*selection_panel
= new wxRibbonPanel(home
, wxID_ANY
, wxT("Selection"), wxBitmap(selection_panel_xpm
));
299 wxRibbonButtonBar
*selection
= new wxRibbonButtonBar(selection_panel
);
300 selection
->AddButton(ID_SELECTION_EXPAND_V
, wxT("Expand Vertically"), wxBitmap(expand_selection_v_xpm
),
301 "This is a tooltip for Expand Vertically\ndemonstrating a tooltip");
302 selection
->AddButton(ID_SELECTION_EXPAND_H
, wxT("Expand Horizontally"), wxBitmap(expand_selection_h_xpm
), wxEmptyString
);
303 selection
->AddButton(ID_SELECTION_CONTRACT
, wxT("Contract"), wxBitmap(auto_crop_selection_xpm
), wxBitmap(auto_crop_selection_small_xpm
));
305 wxRibbonPanel
*shapes_panel
= new wxRibbonPanel(home
, wxID_ANY
, wxT("Shapes"), wxBitmap(circle_small_xpm
));
306 wxRibbonButtonBar
*shapes
= new wxRibbonButtonBar(shapes_panel
);
307 shapes
->AddButton(ID_CIRCLE
, wxT("Circle"), wxBitmap(circle_xpm
), wxBitmap(circle_small_xpm
),
308 wxNullBitmap
, wxNullBitmap
, wxRIBBON_BUTTON_NORMAL
,
309 "This is a tooltip for the circle button\ndemonstrating another tooltip");
310 shapes
->AddButton(ID_CROSS
, wxT("Cross"), wxBitmap(cross_xpm
), wxEmptyString
);
311 shapes
->AddHybridButton(ID_TRIANGLE
, wxT("Triangle"), wxBitmap(triangle_xpm
));
312 shapes
->AddButton(ID_SQUARE
, wxT("Square"), wxBitmap(square_xpm
), wxEmptyString
);
313 shapes
->AddDropdownButton(ID_POLYGON
, wxT("Other Polygon"), wxBitmap(hexagon_xpm
), wxEmptyString
);
315 wxRibbonPanel
*sizer_panel
= new wxRibbonPanel(home
, wxID_ANY
, wxT("Panel with Sizer"),
316 wxNullBitmap
, wxDefaultPosition
, wxDefaultSize
,
317 wxRIBBON_PANEL_DEFAULT_STYLE
);
320 as
.Add("Item 1 using a box sizer now");
321 as
.Add("Item 2 using a box sizer now");
322 wxComboBox
* sizer_panelcombo
= new wxComboBox(sizer_panel
, wxID_ANY
,
324 wxDefaultPosition
, wxDefaultSize
,
327 wxComboBox
* sizer_panelcombo2
= new wxComboBox(sizer_panel
, wxID_ANY
,
329 wxDefaultPosition
, wxDefaultSize
,
332 sizer_panelcombo
->Select(0);
333 sizer_panelcombo2
->Select(1);
334 sizer_panelcombo
->SetMinSize(wxSize(150, -1));
335 sizer_panelcombo2
->SetMinSize(wxSize(150, -1));
337 //not using wxWrapSizer(wxHORIZONTAL) as it reports an incorrect min height
338 wxSizer
* sizer_panelsizer
= new wxBoxSizer(wxVERTICAL
);
339 sizer_panelsizer
->AddStretchSpacer(1);
340 sizer_panelsizer
->Add(sizer_panelcombo
, 0, wxALL
|wxEXPAND
, 2);
341 sizer_panelsizer
->Add(sizer_panelcombo2
, 0, wxALL
|wxEXPAND
, 2);
342 sizer_panelsizer
->AddStretchSpacer(1);
343 sizer_panel
->SetSizer(sizer_panelsizer
);
345 wxFont
label_font(8, wxFONTFAMILY_DEFAULT
, wxFONTSTYLE_NORMAL
, wxFONTWEIGHT_LIGHT
);
346 m_bitmap_creation_dc
.SetFont(label_font
);
348 wxRibbonPage
* scheme
= new wxRibbonPage(m_ribbon
, wxID_ANY
, wxT("Appearance"), eye_xpm
);
349 m_ribbon
->GetArtProvider()->GetColourScheme(&m_default_primary
,
350 &m_default_secondary
, &m_default_tertiary
);
351 wxRibbonPanel
*provider_panel
= new wxRibbonPanel(scheme
, wxID_ANY
,
352 wxT("Art"), wxNullBitmap
, wxDefaultPosition
, wxDefaultSize
, wxRIBBON_PANEL_NO_AUTO_MINIMISE
);
353 wxRibbonButtonBar
*provider_bar
= new wxRibbonButtonBar(provider_panel
, wxID_ANY
);
354 provider_bar
->AddButton(ID_DEFAULT_PROVIDER
, wxT("Default Provider"),
355 wxArtProvider::GetBitmap(wxART_QUESTION
, wxART_OTHER
, wxSize(32, 32)));
356 provider_bar
->AddButton(ID_AUI_PROVIDER
, wxT("AUI Provider"), aui_style_xpm
);
357 provider_bar
->AddButton(ID_MSW_PROVIDER
, wxT("MSW Provider"), msw_style_xpm
);
358 wxRibbonPanel
*primary_panel
= new wxRibbonPanel(scheme
, wxID_ANY
,
359 wxT("Primary Colour"), colours_xpm
);
360 m_primary_gallery
= PopulateColoursPanel(primary_panel
,
361 m_default_primary
, ID_PRIMARY_COLOUR
);
362 wxRibbonPanel
*secondary_panel
= new wxRibbonPanel(scheme
, wxID_ANY
,
363 wxT("Secondary Colour"), colours_xpm
);
364 m_secondary_gallery
= PopulateColoursPanel(secondary_panel
,
365 m_default_secondary
, ID_SECONDARY_COLOUR
);
368 wxRibbonPage
* page
= new wxRibbonPage(m_ribbon
, wxID_ANY
, wxT("UI Updated"), ribbon_xpm
);
369 wxRibbonPanel
*panel
= new wxRibbonPanel(page
, wxID_ANY
, wxT("Enable/Disable"), ribbon_xpm
);
370 wxRibbonButtonBar
*bar
= new wxRibbonButtonBar(panel
, wxID_ANY
);
371 bar
->AddButton(ID_DISABLED
, wxT("Disabled"), ribbon_xpm
);
372 bar
->AddButton(ID_ENABLE
, wxT("Enable"), ribbon_xpm
);
373 bar
->AddButton(ID_DISABLE
, wxT("Disable"), ribbon_xpm
);
374 bar
->AddButton(ID_UI_ENABLE_UPDATED
, wxT("Enable UI updated"), ribbon_xpm
);
375 bar
->EnableButton(ID_DISABLED
, false);
378 panel
= new wxRibbonPanel(page
, wxID_ANY
, wxT("Toggle"), ribbon_xpm
);
379 bar
= new wxRibbonButtonBar(panel
, wxID_ANY
);
380 bar
->AddButton(ID_CHECK
, wxT("Toggle"), ribbon_xpm
);
381 bar
->AddToggleButton(ID_UI_CHECK_UPDATED
, wxT("Toggled UI updated"), ribbon_xpm
);
384 panel
= new wxRibbonPanel(page
, wxID_ANY
, wxT("Change text"), ribbon_xpm
);
385 bar
= new wxRibbonButtonBar(panel
, wxID_ANY
);
386 bar
->AddButton(ID_CHANGE_TEXT1
, wxT("One"), ribbon_xpm
);
387 bar
->AddButton(ID_CHANGE_TEXT2
, wxT("Two"), ribbon_xpm
);
388 bar
->AddButton(ID_UI_CHANGE_TEXT_UPDATED
, wxT("Zero"), ribbon_xpm
);
390 new wxRibbonPage(m_ribbon
, wxID_ANY
, wxT("Empty Page"), empty_xpm
);
392 wxRibbonPage
* page
= new wxRibbonPage(m_ribbon
, wxID_ANY
, wxT("Another Page"), empty_xpm
);
393 wxRibbonPanel
*panel
= new wxRibbonPanel(page
, wxID_ANY
, wxT("Page manipulation"), ribbon_xpm
);
394 wxRibbonButtonBar
*bar
= new wxRibbonButtonBar(panel
, wxID_ANY
);
395 bar
->AddButton(ID_REMOVE_PAGE
, wxT("Remove"), wxArtProvider::GetBitmap(wxART_DELETE
, wxART_OTHER
, wxSize(24, 24)));
400 m_logwindow
= new wxTextCtrl(this, wxID_ANY
, wxEmptyString
,
401 wxDefaultPosition
, wxDefaultSize
, wxTE_MULTILINE
| wxTE_READONLY
|
402 wxTE_LEFT
| wxTE_BESTWRAP
| wxBORDER_NONE
);
404 m_togglePanels
= new wxToggleButton(this, ID_TOGGLE_PANELS
, "&Toggle panels");
405 m_togglePanels
->SetValue(true);
407 wxSizer
*s
= new wxBoxSizer(wxVERTICAL
);
409 s
->Add(m_ribbon
, 0, wxEXPAND
);
410 s
->Add(m_logwindow
, 1, wxEXPAND
);
411 s
->Add(m_togglePanels
, wxSizerFlags().Border());
416 void MyFrame::SetBarStyle(long style
)
419 m_ribbon
->SetWindowStyleFlag(style
);
420 wxBoxSizer
*pTopSize
= reinterpret_cast<wxBoxSizer
*>(GetSizer());
421 wxRibbonToolBar
*pToolbar
= wxDynamicCast(FindWindow(ID_MAIN_TOOLBAR
), wxRibbonToolBar
);
422 if(style
& wxRIBBON_BAR_FLOW_VERTICAL
)
424 m_ribbon
->SetTabCtrlMargins(10, 10);
425 pTopSize
->SetOrientation(wxHORIZONTAL
);
427 pToolbar
->SetRows(3, 5);
431 m_ribbon
->SetTabCtrlMargins(50, 20);
432 pTopSize
->SetOrientation(wxVERTICAL
);
434 pToolbar
->SetRows(2, 3);
445 class ColourClientData
: public wxClientData
448 ColourClientData(const wxString
& name
, const wxColour
& colour
)
449 : m_name(name
), m_colour(colour
) {}
451 const wxString
& GetName() const {return m_name
;}
452 const wxColour
& GetColour() const {return m_colour
;}
459 wxRibbonGallery
* MyFrame::PopulateColoursPanel(wxWindow
* panel
,
460 wxColour def
, int gallery_id
)
462 wxRibbonGallery
*gallery
= wxDynamicCast(panel
->FindWindow(gallery_id
), wxRibbonGallery
);
466 gallery
= new wxRibbonGallery(panel
, gallery_id
);
467 wxMemoryDC
& dc
= m_bitmap_creation_dc
;
468 wxRibbonGalleryItem
*def_item
=
469 AddColourToGallery(gallery
, wxT("Default"), dc
, &def
);
470 gallery
->SetSelection(def_item
);
471 AddColourToGallery(gallery
, wxT("BLUE"), dc
);
472 AddColourToGallery(gallery
, wxT("BLUE VIOLET"), dc
);
473 AddColourToGallery(gallery
, wxT("BROWN"), dc
);
474 AddColourToGallery(gallery
, wxT("CADET BLUE"), dc
);
475 AddColourToGallery(gallery
, wxT("CORAL"), dc
);
476 AddColourToGallery(gallery
, wxT("CYAN"), dc
);
477 AddColourToGallery(gallery
, wxT("DARK GREEN"), dc
);
478 AddColourToGallery(gallery
, wxT("DARK ORCHID"), dc
);
479 AddColourToGallery(gallery
, wxT("FIREBRICK"), dc
);
480 AddColourToGallery(gallery
, wxT("GOLD"), dc
);
481 AddColourToGallery(gallery
, wxT("GOLDENROD"), dc
);
482 AddColourToGallery(gallery
, wxT("GREEN"), dc
);
483 AddColourToGallery(gallery
, wxT("INDIAN RED"), dc
);
484 AddColourToGallery(gallery
, wxT("KHAKI"), dc
);
485 AddColourToGallery(gallery
, wxT("LIGHT BLUE"), dc
);
486 AddColourToGallery(gallery
, wxT("LIME GREEN"), dc
);
487 AddColourToGallery(gallery
, wxT("MAGENTA"), dc
);
488 AddColourToGallery(gallery
, wxT("MAROON"), dc
);
489 AddColourToGallery(gallery
, wxT("NAVY"), dc
);
490 AddColourToGallery(gallery
, wxT("ORANGE"), dc
);
491 AddColourToGallery(gallery
, wxT("ORCHID"), dc
);
492 AddColourToGallery(gallery
, wxT("PINK"), dc
);
493 AddColourToGallery(gallery
, wxT("PLUM"), dc
);
494 AddColourToGallery(gallery
, wxT("PURPLE"), dc
);
495 AddColourToGallery(gallery
, wxT("RED"), dc
);
496 AddColourToGallery(gallery
, wxT("SALMON"), dc
);
497 AddColourToGallery(gallery
, wxT("SEA GREEN"), dc
);
498 AddColourToGallery(gallery
, wxT("SIENNA"), dc
);
499 AddColourToGallery(gallery
, wxT("SKY BLUE"), dc
);
500 AddColourToGallery(gallery
, wxT("TAN"), dc
);
501 AddColourToGallery(gallery
, wxT("THISTLE"), dc
);
502 AddColourToGallery(gallery
, wxT("TURQUOISE"), dc
);
503 AddColourToGallery(gallery
, wxT("VIOLET"), dc
);
504 AddColourToGallery(gallery
, wxT("VIOLET RED"), dc
);
505 AddColourToGallery(gallery
, wxT("WHEAT"), dc
);
506 AddColourToGallery(gallery
, wxT("WHITE"), dc
);
507 AddColourToGallery(gallery
, wxT("YELLOW"), dc
);
512 wxColour
MyFrame::GetGalleryColour(wxRibbonGallery
*gallery
,
513 wxRibbonGalleryItem
* item
, wxString
* name
)
515 ColourClientData
*data
= (ColourClientData
*)gallery
->GetItemClientObject(item
);
517 *name
= data
->GetName();
518 return data
->GetColour();
521 void MyFrame::OnHoveredColourChange(wxRibbonGalleryEvent
& evt
)
523 // Set the background of the gallery to the hovered colour, or back to the
524 // default if there is no longer a hovered item.
526 wxRibbonGallery
*gallery
= evt
.GetGallery();
527 wxRibbonArtProvider
*provider
= gallery
->GetArtProvider();
529 if(evt
.GetGalleryItem() != NULL
)
531 if(provider
== m_ribbon
->GetArtProvider())
533 provider
= provider
->Clone();
534 gallery
->SetArtProvider(provider
);
536 provider
->SetColour(wxRIBBON_ART_GALLERY_HOVER_BACKGROUND_COLOUR
,
537 GetGalleryColour(evt
.GetGallery(), evt
.GetGalleryItem(), NULL
));
541 if(provider
!= m_ribbon
->GetArtProvider())
543 gallery
->SetArtProvider(m_ribbon
->GetArtProvider());
549 void MyFrame::OnPrimaryColourSelect(wxRibbonGalleryEvent
& evt
)
552 wxColour colour
= GetGalleryColour(evt
.GetGallery(), evt
.GetGalleryItem(), &name
);
553 AddText(wxT("Colour \"") + name
+ wxT("\" selected as primary."));
554 wxColour secondary
, tertiary
;
555 m_ribbon
->GetArtProvider()->GetColourScheme(NULL
, &secondary
, &tertiary
);
556 m_ribbon
->GetArtProvider()->SetColourScheme(colour
, secondary
, tertiary
);
557 ResetGalleryArtProviders();
561 void MyFrame::OnSecondaryColourSelect(wxRibbonGalleryEvent
& evt
)
564 wxColour colour
= GetGalleryColour(evt
.GetGallery(), evt
.GetGalleryItem(), &name
);
565 AddText(wxT("Colour \"") + name
+ wxT("\" selected as secondary."));
566 wxColour primary
, tertiary
;
567 m_ribbon
->GetArtProvider()->GetColourScheme(&primary
, NULL
, &tertiary
);
568 m_ribbon
->GetArtProvider()->SetColourScheme(primary
, colour
, tertiary
);
569 ResetGalleryArtProviders();
573 void MyFrame::ResetGalleryArtProviders()
575 if(m_primary_gallery
->GetArtProvider() != m_ribbon
->GetArtProvider())
577 delete m_primary_gallery
->GetArtProvider();
578 m_primary_gallery
->SetArtProvider(m_ribbon
->GetArtProvider());
580 if(m_secondary_gallery
->GetArtProvider() != m_ribbon
->GetArtProvider())
582 delete m_secondary_gallery
->GetArtProvider();
583 m_secondary_gallery
->SetArtProvider(m_ribbon
->GetArtProvider());
587 void MyFrame::OnChangeText1(wxRibbonButtonBarEvent
& WXUNUSED(evt
))
589 m_new_text
= wxT("One");
592 void MyFrame::OnChangeText2(wxRibbonButtonBarEvent
& WXUNUSED(evt
))
594 m_new_text
= wxT("Two");
597 void MyFrame::OnEnable(wxRibbonButtonBarEvent
& WXUNUSED(evt
))
602 void MyFrame::OnDisable(wxRibbonButtonBarEvent
& WXUNUSED(evt
))
607 void MyFrame::OnCheck(wxRibbonButtonBarEvent
& WXUNUSED(evt
))
609 m_bChecked
= !m_bChecked
;
612 void MyFrame::OnEnableUpdateUI(wxUpdateUIEvent
& evt
)
614 evt
.Enable(m_bEnabled
);
617 void MyFrame::OnCheckUpdateUI(wxUpdateUIEvent
& evt
)
619 evt
.Check(m_bChecked
);
622 void MyFrame::OnChangeTextUpdateUI(wxUpdateUIEvent
& evt
)
624 if ( !m_new_text
.IsEmpty() )
626 evt
.SetText(m_new_text
);
627 m_new_text
= wxT("");
631 void MyFrame::OnSelectionExpandHButton(wxRibbonButtonBarEvent
& WXUNUSED(evt
))
633 AddText(wxT("Expand selection horizontally button clicked."));
636 void MyFrame::OnSelectionExpandVButton(wxRibbonButtonBarEvent
& WXUNUSED(evt
))
638 AddText(wxT("Expand selection vertically button clicked."));
641 void MyFrame::OnSelectionContractButton(wxRibbonButtonBarEvent
& WXUNUSED(evt
))
643 AddText(wxT("Contract selection button clicked."));
646 void MyFrame::OnCircleButton(wxRibbonButtonBarEvent
& WXUNUSED(evt
))
648 AddText(wxT("Circle button clicked."));
651 void MyFrame::OnCrossButton(wxRibbonButtonBarEvent
& WXUNUSED(evt
))
653 AddText(wxT("Cross button clicked."));
656 void MyFrame::OnTriangleButton(wxRibbonButtonBarEvent
& WXUNUSED(evt
))
658 AddText(wxT("Triangle button clicked."));
661 void MyFrame::OnTriangleDropdown(wxRibbonButtonBarEvent
& evt
)
664 menu
.Append(wxID_ANY
, wxT("Equilateral"));
665 menu
.Append(wxID_ANY
, wxT("Isosceles"));
666 menu
.Append(wxID_ANY
, wxT("Scalene"));
668 evt
.PopupMenu(&menu
);
671 void MyFrame::OnSquareButton(wxRibbonButtonBarEvent
& WXUNUSED(evt
))
673 AddText(wxT("Square button clicked."));
676 void MyFrame::OnPolygonDropdown(wxRibbonButtonBarEvent
& evt
)
679 menu
.Append(wxID_ANY
, wxT("Pentagon (5 sided)"));
680 menu
.Append(wxID_ANY
, wxT("Hexagon (6 sided)"));
681 menu
.Append(wxID_ANY
, wxT("Heptagon (7 sided)"));
682 menu
.Append(wxID_ANY
, wxT("Octogon (8 sided)"));
683 menu
.Append(wxID_ANY
, wxT("Nonagon (9 sided)"));
684 menu
.Append(wxID_ANY
, wxT("Decagon (10 sided)"));
686 evt
.PopupMenu(&menu
);
689 void MyFrame::OnJustify(wxRibbonToolBarEvent
& evt
)
691 long style
= m_logwindow
->GetWindowStyle() &
692 ~(wxTE_LEFT
| wxTE_CENTER
| wxTE_RIGHT
);
695 case wxID_JUSTIFY_LEFT
:
696 m_logwindow
->SetWindowStyle(style
| wxTE_LEFT
);
698 case wxID_JUSTIFY_CENTER
:
699 m_logwindow
->SetWindowStyle(style
| wxTE_CENTER
);
701 case wxID_JUSTIFY_RIGHT
:
702 m_logwindow
->SetWindowStyle(style
| wxTE_RIGHT
);
707 void MyFrame::OnJustifyUpdateUI(wxUpdateUIEvent
& evt
)
711 case wxID_JUSTIFY_LEFT
:
712 evt
.Check(!m_logwindow
->HasFlag(wxTE_CENTER
| wxTE_RIGHT
));
714 case wxID_JUSTIFY_CENTER
:
715 evt
.Check(m_logwindow
->HasFlag(wxTE_CENTER
));
717 case wxID_JUSTIFY_RIGHT
:
718 evt
.Check(m_logwindow
->HasFlag(wxTE_RIGHT
));
723 void MyFrame::OnNew(wxRibbonToolBarEvent
& WXUNUSED(evt
))
725 AddText(wxT("New button clicked."));
728 void MyFrame::OnNewDropdown(wxRibbonToolBarEvent
& evt
)
731 menu
.Append(wxID_ANY
, wxT("New Document"));
732 menu
.Append(wxID_ANY
, wxT("New Template"));
733 menu
.Append(wxID_ANY
, wxT("New Mail"));
735 evt
.PopupMenu(&menu
);
738 void MyFrame::OnPrint(wxRibbonToolBarEvent
& WXUNUSED(evt
))
740 AddText(wxT("Print button clicked."));
743 void MyFrame::OnPrintDropdown(wxRibbonToolBarEvent
& evt
)
746 menu
.Append(wxID_ANY
, wxT("Print"));
747 menu
.Append(wxID_ANY
, wxT("Preview"));
748 menu
.Append(wxID_ANY
, wxT("Options"));
750 evt
.PopupMenu(&menu
);
753 void MyFrame::OnRedoDropdown(wxRibbonToolBarEvent
& evt
)
756 menu
.Append(wxID_ANY
, wxT("Redo E"));
757 menu
.Append(wxID_ANY
, wxT("Redo F"));
758 menu
.Append(wxID_ANY
, wxT("Redo G"));
760 evt
.PopupMenu(&menu
);
763 void MyFrame::OnUndoDropdown(wxRibbonToolBarEvent
& evt
)
766 menu
.Append(wxID_ANY
, wxT("Undo C"));
767 menu
.Append(wxID_ANY
, wxT("Undo B"));
768 menu
.Append(wxID_ANY
, wxT("Undo A"));
770 evt
.PopupMenu(&menu
);
773 void MyFrame::OnPositionTopLabels(wxCommandEvent
& WXUNUSED(evt
))
775 SetBarStyle(wxRIBBON_BAR_DEFAULT_STYLE
);
778 void MyFrame::OnPositionTopIcons(wxCommandEvent
& WXUNUSED(evt
))
780 SetBarStyle((wxRIBBON_BAR_DEFAULT_STYLE
&~wxRIBBON_BAR_SHOW_PAGE_LABELS
)
781 | wxRIBBON_BAR_SHOW_PAGE_ICONS
);
784 void MyFrame::OnPositionTopBoth(wxCommandEvent
& WXUNUSED(evt
))
786 SetBarStyle(wxRIBBON_BAR_DEFAULT_STYLE
| wxRIBBON_BAR_SHOW_PAGE_ICONS
);
789 void MyFrame::OnPositionLeftLabels(wxCommandEvent
& WXUNUSED(evt
))
791 SetBarStyle(wxRIBBON_BAR_DEFAULT_STYLE
| wxRIBBON_BAR_FLOW_VERTICAL
);
794 void MyFrame::OnPositionLeftIcons(wxCommandEvent
& WXUNUSED(evt
))
796 SetBarStyle((wxRIBBON_BAR_DEFAULT_STYLE
&~wxRIBBON_BAR_SHOW_PAGE_LABELS
) |
797 wxRIBBON_BAR_SHOW_PAGE_ICONS
| wxRIBBON_BAR_FLOW_VERTICAL
);
800 void MyFrame::OnPositionLeftBoth(wxCommandEvent
& WXUNUSED(evt
))
802 SetBarStyle(wxRIBBON_BAR_DEFAULT_STYLE
| wxRIBBON_BAR_SHOW_PAGE_ICONS
|
803 wxRIBBON_BAR_FLOW_VERTICAL
);
806 void MyFrame::OnPositionTop(wxRibbonToolBarEvent
& evt
)
808 OnPositionTopLabels(evt
);
811 void MyFrame::OnPositionTopDropdown(wxRibbonToolBarEvent
& evt
)
814 menu
.Append(ID_POSITION_TOP
, wxT("Top with Labels"));
815 menu
.Append(ID_POSITION_TOP_ICONS
, wxT("Top with Icons"));
816 menu
.Append(ID_POSITION_TOP_BOTH
, wxT("Top with Both"));
817 evt
.PopupMenu(&menu
);
820 void MyFrame::OnPositionLeft(wxRibbonToolBarEvent
& evt
)
822 OnPositionLeftIcons(evt
);
825 void MyFrame::OnPositionLeftDropdown(wxRibbonToolBarEvent
& evt
)
828 menu
.Append(ID_POSITION_LEFT
, wxT("Left with Icons"));
829 menu
.Append(ID_POSITION_LEFT_LABELS
, wxT("Left with Labels"));
830 menu
.Append(ID_POSITION_LEFT_BOTH
, wxT("Left with Both"));
831 evt
.PopupMenu(&menu
);
834 void MyFrame::OnTogglePanels(wxCommandEvent
& WXUNUSED(evt
))
836 m_ribbon
->ShowPanels(m_togglePanels
->GetValue());
839 void MyFrame::OnExtButton(wxRibbonPanelEvent
& WXUNUSED(evt
))
841 wxMessageBox("Extension button clicked");
844 void MyFrame::AddText(wxString msg
)
846 m_logwindow
->AppendText(msg
);
847 m_logwindow
->AppendText(wxT("\n"));
848 m_ribbon
->DismissExpandedPanel();
851 wxRibbonGalleryItem
* MyFrame::AddColourToGallery(wxRibbonGallery
*gallery
,
852 wxString colour
, wxMemoryDC
& dc
,
855 wxRibbonGalleryItem
* item
= NULL
;
857 if (colour
!= wxT("Default"))
858 c
= wxColour(colour
);
863 const int iWidth
= 64;
864 const int iHeight
= 40;
866 wxBitmap
bitmap(iWidth
, iHeight
);
867 dc
.SelectObject(bitmap
);
869 dc
.SetPen(*wxBLACK_PEN
);
871 dc
.DrawRectangle(0, 0, iWidth
, iHeight
);
873 colour
= colour
.Mid(0, 1) + colour
.Mid(1).Lower();
874 wxSize size
= dc
.GetTextExtent(colour
);
875 wxColour foreground
= wxColour(~c
.Red(), ~c
.Green(), ~c
.Blue());
876 if(abs(foreground
.Red() - c
.Red()) + abs(foreground
.Blue() - c
.Blue())
877 + abs(foreground
.Green() - c
.Green()) < 64)
879 // Foreground too similar to background - use a different
880 // strategy to find a contrasting colour
881 foreground
= wxColour((c
.Red() + 64) % 256, 255 - c
.Green(),
882 (c
.Blue() + 192) % 256);
884 dc
.SetTextForeground(foreground
);
885 dc
.DrawText(colour
, (iWidth
- size
.GetWidth() + 1) / 2,
886 (iHeight
- size
.GetHeight()) / 2);
887 dc
.SelectObjectAsSource(wxNullBitmap
);
889 item
= gallery
->Append(bitmap
, wxID_ANY
);
890 gallery
->SetItemClientObject(item
, new ColourClientData(colour
, c
));
895 void MyFrame::OnColourGalleryButton(wxCommandEvent
& evt
)
897 wxRibbonGallery
*gallery
= wxDynamicCast(evt
.GetEventObject(), wxRibbonGallery
);
901 m_ribbon
->DismissExpandedPanel();
902 if(gallery
->GetSelection())
903 m_colour_data
.SetColour(GetGalleryColour(gallery
, gallery
->GetSelection(), NULL
));
904 wxColourDialog
dlg(this, &m_colour_data
);
905 if(dlg
.ShowModal() == wxID_OK
)
907 m_colour_data
= dlg
.GetColourData();
908 wxColour clr
= m_colour_data
.GetColour();
910 // Try to find colour in gallery
911 wxRibbonGalleryItem
*item
= NULL
;
912 for(unsigned int i
= 0; i
< gallery
->GetCount(); ++i
)
914 item
= gallery
->GetItem(i
);
915 if(GetGalleryColour(gallery
, item
, NULL
) == clr
)
921 // Colour not in gallery - add it
924 item
= AddColourToGallery(gallery
,
925 clr
.GetAsString(wxC2S_HTML_SYNTAX
), m_bitmap_creation_dc
,
931 gallery
->EnsureVisible(item
);
932 gallery
->SetSelection(item
);
934 // Send an event to respond to the selection change
935 wxRibbonGalleryEvent
dummy(wxEVT_COMMAND_RIBBONGALLERY_SELECTED
, gallery
->GetId());
936 dummy
.SetEventObject(gallery
);
937 dummy
.SetGallery(gallery
);
938 dummy
.SetGalleryItem(item
);
939 ProcessWindowEvent(dummy
);
943 void MyFrame::OnDefaultProvider(wxRibbonButtonBarEvent
& WXUNUSED(evt
))
945 m_ribbon
->DismissExpandedPanel();
946 SetArtProvider(new wxRibbonDefaultArtProvider
);
949 void MyFrame::OnAUIProvider(wxRibbonButtonBarEvent
& WXUNUSED(evt
))
951 m_ribbon
->DismissExpandedPanel();
952 SetArtProvider(new wxRibbonAUIArtProvider
);
955 void MyFrame::OnMSWProvider(wxRibbonButtonBarEvent
& WXUNUSED(evt
))
957 m_ribbon
->DismissExpandedPanel();
958 SetArtProvider(new wxRibbonMSWArtProvider
);
961 void MyFrame::SetArtProvider(wxRibbonArtProvider
*prov
)
964 m_ribbon
->SetArtProvider(prov
);
966 prov
->GetColourScheme(&m_default_primary
, &m_default_secondary
,
967 &m_default_tertiary
);
968 PopulateColoursPanel(m_primary_gallery
->GetParent(), m_default_primary
,
970 PopulateColoursPanel(m_secondary_gallery
->GetParent(), m_default_secondary
,
971 ID_SECONDARY_COLOUR
);
975 GetSizer()->Layout();
978 void MyFrame::OnRemovePage(wxRibbonButtonBarEvent
& WXUNUSED(evt
))
980 size_t n
= m_ribbon
->GetPageCount();
983 m_ribbon
->DeletePage(n
-1);