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/dcbuffer.h"
28 #include "wx/colordlg.h"
29 #include "wx/artprov.h"
30 #include "wx/combobox.h"
31 #include "wx/tglbtn.h"
32 #include "wx/wrapsizer.h"
36 class MyApp
: public wxApp
47 class MyFrame
: public wxFrame
55 ID_CIRCLE
= wxID_HIGHEST
+ 1,
60 ID_SELECTION_EXPAND_H
,
61 ID_SELECTION_EXPAND_V
,
62 ID_SELECTION_CONTRACT
,
70 ID_POSITION_TOP_ICONS
,
73 ID_POSITION_LEFT_LABELS
,
74 ID_POSITION_LEFT_BOTH
,
84 ID_UI_CHANGE_TEXT_UPDATED
87 void OnEnableUpdateUI(wxUpdateUIEvent
& evt
);
88 void OnCheckUpdateUI(wxUpdateUIEvent
& evt
);
89 void OnChangeTextUpdateUI(wxUpdateUIEvent
& evt
);
90 void OnCheck(wxRibbonButtonBarEvent
& evt
);
91 void OnEnable(wxRibbonButtonBarEvent
& evt
);
92 void OnDisable(wxRibbonButtonBarEvent
& evt
);
93 void OnChangeText1(wxRibbonButtonBarEvent
& evt
);
94 void OnChangeText2(wxRibbonButtonBarEvent
& evt
);
95 void OnCircleButton(wxRibbonButtonBarEvent
& evt
);
96 void OnCrossButton(wxRibbonButtonBarEvent
& evt
);
97 void OnTriangleButton(wxRibbonButtonBarEvent
& evt
);
98 void OnTriangleDropdown(wxRibbonButtonBarEvent
& evt
);
99 void OnSquareButton(wxRibbonButtonBarEvent
& evt
);
100 void OnPolygonDropdown(wxRibbonButtonBarEvent
& evt
);
101 void OnSelectionExpandVButton(wxRibbonButtonBarEvent
& evt
);
102 void OnSelectionExpandHButton(wxRibbonButtonBarEvent
& evt
);
103 void OnSelectionContractButton(wxRibbonButtonBarEvent
& evt
);
104 void OnHoveredColourChange(wxRibbonGalleryEvent
& evt
);
105 void OnPrimaryColourSelect(wxRibbonGalleryEvent
& evt
);
106 void OnSecondaryColourSelect(wxRibbonGalleryEvent
& evt
);
107 void OnColourGalleryButton(wxCommandEvent
& evt
);
108 void OnDefaultProvider(wxRibbonButtonBarEvent
& evt
);
109 void OnAUIProvider(wxRibbonButtonBarEvent
& evt
);
110 void OnMSWProvider(wxRibbonButtonBarEvent
& evt
);
111 void OnJustify(wxRibbonToolBarEvent
& evt
);
112 void OnJustifyUpdateUI(wxUpdateUIEvent
& evt
);
113 void OnNew(wxRibbonToolBarEvent
& evt
);
114 void OnNewDropdown(wxRibbonToolBarEvent
& evt
);
115 void OnPrint(wxRibbonToolBarEvent
& evt
);
116 void OnPrintDropdown(wxRibbonToolBarEvent
& evt
);
117 void OnRedoDropdown(wxRibbonToolBarEvent
& evt
);
118 void OnUndoDropdown(wxRibbonToolBarEvent
& evt
);
119 void OnPositionTop(wxRibbonToolBarEvent
& evt
);
120 void OnPositionTopLabels(wxCommandEvent
& evt
);
121 void OnPositionTopIcons(wxCommandEvent
& evt
);
122 void OnPositionTopBoth(wxCommandEvent
& evt
);
123 void OnPositionTopDropdown(wxRibbonToolBarEvent
& evt
);
124 void OnPositionLeft(wxRibbonToolBarEvent
& evt
);
125 void OnPositionLeftLabels(wxCommandEvent
& evt
);
126 void OnPositionLeftIcons(wxCommandEvent
& evt
);
127 void OnPositionLeftBoth(wxCommandEvent
& evt
);
128 void OnPositionLeftDropdown(wxRibbonToolBarEvent
& evt
);
130 void OnTogglePanels(wxCommandEvent
& evt
);
133 wxRibbonGallery
* PopulateColoursPanel(wxWindow
* panel
, wxColour def
,
135 void AddText(wxString msg
);
136 wxRibbonGalleryItem
* AddColourToGallery(wxRibbonGallery
*gallery
,
137 wxString name
, wxMemoryDC
& dc
, wxColour
* value
= NULL
);
138 wxColour
GetGalleryColour(wxRibbonGallery
*gallery
,
139 wxRibbonGalleryItem
* item
, wxString
* name
);
140 void ResetGalleryArtProviders();
141 void SetArtProvider(wxRibbonArtProvider
* prov
);
142 void SetBarStyle(long style
);
144 wxRibbonBar
* m_ribbon
;
145 wxRibbonGallery
* m_primary_gallery
;
146 wxRibbonGallery
* m_secondary_gallery
;
147 wxTextCtrl
* m_logwindow
;
148 wxToggleButton
* m_togglePanels
;
150 wxColourData m_colour_data
;
151 wxColour m_default_primary
;
152 wxColour m_default_secondary
;
153 wxColour m_default_tertiary
;
154 wxMemoryDC m_bitmap_creation_dc
;
159 DECLARE_EVENT_TABLE()
162 // -- implementations --
169 wxFrame
* frame
= new MyFrame
;
175 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
176 EVT_RIBBONBUTTONBAR_CLICKED(ID_ENABLE
, MyFrame::OnEnable
)
177 EVT_RIBBONBUTTONBAR_CLICKED(ID_DISABLE
, MyFrame::OnDisable
)
178 EVT_UPDATE_UI(ID_UI_ENABLE_UPDATED
, MyFrame::OnEnableUpdateUI
)
179 EVT_RIBBONBUTTONBAR_CLICKED(ID_CHECK
, MyFrame::OnCheck
)
180 EVT_UPDATE_UI(ID_UI_CHECK_UPDATED
, MyFrame::OnCheckUpdateUI
)
181 EVT_RIBBONBUTTONBAR_CLICKED(ID_CHANGE_TEXT1
, MyFrame::OnChangeText1
)
182 EVT_RIBBONBUTTONBAR_CLICKED(ID_CHANGE_TEXT2
, MyFrame::OnChangeText2
)
183 EVT_UPDATE_UI(ID_UI_CHANGE_TEXT_UPDATED
, MyFrame::OnChangeTextUpdateUI
)
184 EVT_RIBBONBUTTONBAR_CLICKED(ID_DEFAULT_PROVIDER
, MyFrame::OnDefaultProvider
)
185 EVT_RIBBONBUTTONBAR_CLICKED(ID_AUI_PROVIDER
, MyFrame::OnAUIProvider
)
186 EVT_RIBBONBUTTONBAR_CLICKED(ID_MSW_PROVIDER
, MyFrame::OnMSWProvider
)
187 EVT_RIBBONBUTTONBAR_CLICKED(ID_SELECTION_EXPAND_H
, MyFrame::OnSelectionExpandHButton
)
188 EVT_RIBBONBUTTONBAR_CLICKED(ID_SELECTION_EXPAND_V
, MyFrame::OnSelectionExpandVButton
)
189 EVT_RIBBONBUTTONBAR_CLICKED(ID_SELECTION_CONTRACT
, MyFrame::OnSelectionContractButton
)
190 EVT_RIBBONBUTTONBAR_CLICKED(ID_CIRCLE
, MyFrame::OnCircleButton
)
191 EVT_RIBBONBUTTONBAR_CLICKED(ID_CROSS
, MyFrame::OnCrossButton
)
192 EVT_RIBBONBUTTONBAR_CLICKED(ID_TRIANGLE
, MyFrame::OnTriangleButton
)
193 EVT_RIBBONBUTTONBAR_CLICKED(ID_SQUARE
, MyFrame::OnSquareButton
)
194 EVT_RIBBONBUTTONBAR_DROPDOWN_CLICKED(ID_TRIANGLE
, MyFrame::OnTriangleDropdown
)
195 EVT_RIBBONBUTTONBAR_DROPDOWN_CLICKED(ID_POLYGON
, MyFrame::OnPolygonDropdown
)
196 EVT_RIBBONGALLERY_HOVER_CHANGED(ID_PRIMARY_COLOUR
, MyFrame::OnHoveredColourChange
)
197 EVT_RIBBONGALLERY_HOVER_CHANGED(ID_SECONDARY_COLOUR
, MyFrame::OnHoveredColourChange
)
198 EVT_RIBBONGALLERY_SELECTED(ID_PRIMARY_COLOUR
, MyFrame::OnPrimaryColourSelect
)
199 EVT_RIBBONGALLERY_SELECTED(ID_SECONDARY_COLOUR
, MyFrame::OnSecondaryColourSelect
)
200 EVT_RIBBONTOOLBAR_CLICKED(wxID_JUSTIFY_LEFT
, MyFrame::OnJustify
)
201 EVT_RIBBONTOOLBAR_CLICKED(wxID_JUSTIFY_CENTER
, MyFrame::OnJustify
)
202 EVT_RIBBONTOOLBAR_CLICKED(wxID_JUSTIFY_RIGHT
, MyFrame::OnJustify
)
203 EVT_UPDATE_UI(wxID_JUSTIFY_LEFT
, MyFrame::OnJustifyUpdateUI
)
204 EVT_UPDATE_UI(wxID_JUSTIFY_CENTER
, MyFrame::OnJustifyUpdateUI
)
205 EVT_UPDATE_UI(wxID_JUSTIFY_RIGHT
, MyFrame::OnJustifyUpdateUI
)
206 EVT_RIBBONTOOLBAR_CLICKED(wxID_NEW
, MyFrame::OnNew
)
207 EVT_RIBBONTOOLBAR_DROPDOWN_CLICKED(wxID_NEW
, MyFrame::OnNewDropdown
)
208 EVT_RIBBONTOOLBAR_CLICKED(wxID_PRINT
, MyFrame::OnPrint
)
209 EVT_RIBBONTOOLBAR_DROPDOWN_CLICKED(wxID_PRINT
, MyFrame::OnPrintDropdown
)
210 EVT_RIBBONTOOLBAR_DROPDOWN_CLICKED(wxID_REDO
, MyFrame::OnRedoDropdown
)
211 EVT_RIBBONTOOLBAR_DROPDOWN_CLICKED(wxID_UNDO
, MyFrame::OnUndoDropdown
)
212 EVT_RIBBONTOOLBAR_CLICKED(ID_POSITION_LEFT
, MyFrame::OnPositionLeft
)
213 EVT_RIBBONTOOLBAR_DROPDOWN_CLICKED(ID_POSITION_LEFT
, MyFrame::OnPositionLeftDropdown
)
214 EVT_RIBBONTOOLBAR_CLICKED(ID_POSITION_TOP
, MyFrame::OnPositionTop
)
215 EVT_RIBBONTOOLBAR_DROPDOWN_CLICKED(ID_POSITION_TOP
, MyFrame::OnPositionTopDropdown
)
216 EVT_BUTTON(ID_PRIMARY_COLOUR
, MyFrame::OnColourGalleryButton
)
217 EVT_BUTTON(ID_SECONDARY_COLOUR
, MyFrame::OnColourGalleryButton
)
218 EVT_MENU(ID_POSITION_LEFT
, MyFrame::OnPositionLeftIcons
)
219 EVT_MENU(ID_POSITION_LEFT_LABELS
, MyFrame::OnPositionLeftLabels
)
220 EVT_MENU(ID_POSITION_LEFT_BOTH
, MyFrame::OnPositionLeftBoth
)
221 EVT_MENU(ID_POSITION_TOP
, MyFrame::OnPositionTopLabels
)
222 EVT_MENU(ID_POSITION_TOP_ICONS
, MyFrame::OnPositionTopIcons
)
223 EVT_MENU(ID_POSITION_TOP_BOTH
, MyFrame::OnPositionTopBoth
)
224 EVT_TOGGLEBUTTON(ID_TOGGLE_PANELS
, MyFrame::OnTogglePanels
)
227 #include "align_center.xpm"
228 #include "align_left.xpm"
229 #include "align_right.xpm"
230 #include "aui_style.xpm"
231 #include "auto_crop_selection.xpm"
232 #include "auto_crop_selection_small.xpm"
233 #include "circle.xpm"
234 #include "circle_small.xpm"
235 #include "colours.xpm"
238 #include "expand_selection_v.xpm"
239 #include "expand_selection_h.xpm"
241 #include "hexagon.xpm"
242 #include "msw_style.xpm"
243 #include "position_left_small.xpm"
244 #include "position_top_small.xpm"
245 #include "ribbon.xpm"
246 #include "selection_panel.xpm"
247 #include "square.xpm"
248 #include "triangle.xpm"
251 : wxFrame(NULL
, wxID_ANY
, wxT("wxRibbon Sample Application"), wxDefaultPosition
, wxSize(800, 600), wxDEFAULT_FRAME_STYLE
)
253 m_ribbon
= new wxRibbonBar(this, wxID_ANY
);
256 wxRibbonPage
* home
= new wxRibbonPage(m_ribbon
, wxID_ANY
, wxT("Examples"), ribbon_xpm
);
257 wxRibbonPanel
*toolbar_panel
= new wxRibbonPanel(home
, wxID_ANY
, wxT("Toolbar"),
258 wxNullBitmap
, wxDefaultPosition
, wxDefaultSize
,
259 wxRIBBON_PANEL_NO_AUTO_MINIMISE
);
260 wxRibbonToolBar
*toolbar
= new wxRibbonToolBar(toolbar_panel
, ID_MAIN_TOOLBAR
);
261 toolbar
->AddToggleTool(wxID_JUSTIFY_LEFT
, align_left_xpm
);
262 toolbar
->AddToggleTool(wxID_JUSTIFY_CENTER
, align_center_xpm
);
263 toolbar
->AddToggleTool(wxID_JUSTIFY_RIGHT
, align_right_xpm
);
264 toolbar
->AddSeparator();
265 toolbar
->AddHybridTool(wxID_NEW
, wxArtProvider::GetBitmap(wxART_NEW
, wxART_OTHER
, wxSize(16, 15)));
266 toolbar
->AddTool(wxID_OPEN
, wxArtProvider::GetBitmap(wxART_FILE_OPEN
, wxART_OTHER
, wxSize(16, 15)), "Open something");
267 toolbar
->AddTool(wxID_SAVE
, wxArtProvider::GetBitmap(wxART_FILE_SAVE
, wxART_OTHER
, wxSize(16, 15)), "Save something");
268 toolbar
->AddTool(wxID_SAVEAS
, wxArtProvider::GetBitmap(wxART_FILE_SAVE_AS
, wxART_OTHER
, wxSize(16, 15)), "Save something as ...");
269 toolbar
->EnableTool(wxID_OPEN
, false);
270 toolbar
->EnableTool(wxID_SAVE
, false);
271 toolbar
->EnableTool(wxID_SAVEAS
, false);
272 toolbar
->AddSeparator();
273 toolbar
->AddDropdownTool(wxID_UNDO
, wxArtProvider::GetBitmap(wxART_UNDO
, wxART_OTHER
, wxSize(16, 15)));
274 toolbar
->AddDropdownTool(wxID_REDO
, wxArtProvider::GetBitmap(wxART_REDO
, wxART_OTHER
, wxSize(16, 15)));
275 toolbar
->AddSeparator();
276 toolbar
->AddTool(wxID_ANY
, wxArtProvider::GetBitmap(wxART_REPORT_VIEW
, wxART_OTHER
, wxSize(16, 15)));
277 toolbar
->AddTool(wxID_ANY
, wxArtProvider::GetBitmap(wxART_LIST_VIEW
, wxART_OTHER
, wxSize(16, 15)));
278 toolbar
->AddSeparator();
279 toolbar
->AddHybridTool(ID_POSITION_LEFT
, position_left_xpm
,
280 "Align ribbonbar vertically\non the left\nfor demonstration purposes");
281 toolbar
->AddHybridTool(ID_POSITION_TOP
, position_top_xpm
,
282 "Align the ribbonbar horizontally\nat the top\nfor demonstration purposes");
283 toolbar
->AddSeparator();
284 toolbar
->AddHybridTool(wxID_PRINT
, wxArtProvider::GetBitmap(wxART_PRINT
, wxART_OTHER
, wxSize(16, 15)),
285 "This is the Print button tooltip\ndemonstrating a tooltip");
286 toolbar
->SetRows(2, 3);
288 wxRibbonPanel
*selection_panel
= new wxRibbonPanel(home
, wxID_ANY
, wxT("Selection"), wxBitmap(selection_panel_xpm
));
289 wxRibbonButtonBar
*selection
= new wxRibbonButtonBar(selection_panel
);
290 selection
->AddButton(ID_SELECTION_EXPAND_V
, wxT("Expand Vertically"), wxBitmap(expand_selection_v_xpm
),
291 "This is a tooltip for Expand Vertically\ndemonstrating a tooltip");
292 selection
->AddButton(ID_SELECTION_EXPAND_H
, wxT("Expand Horizontally"), wxBitmap(expand_selection_h_xpm
), wxEmptyString
);
293 selection
->AddButton(ID_SELECTION_CONTRACT
, wxT("Contract"), wxBitmap(auto_crop_selection_xpm
), wxBitmap(auto_crop_selection_small_xpm
));
295 wxRibbonPanel
*shapes_panel
= new wxRibbonPanel(home
, wxID_ANY
, wxT("Shapes"), wxBitmap(circle_small_xpm
));
296 wxRibbonButtonBar
*shapes
= new wxRibbonButtonBar(shapes_panel
);
297 shapes
->AddButton(ID_CIRCLE
, wxT("Circle"), wxBitmap(circle_xpm
), wxBitmap(circle_small_xpm
),
298 wxNullBitmap
, wxNullBitmap
, wxRIBBON_BUTTON_NORMAL
,
299 "This is a tooltip for the circle button\ndemonstrating another tooltip");
300 shapes
->AddButton(ID_CROSS
, wxT("Cross"), wxBitmap(cross_xpm
), wxEmptyString
);
301 shapes
->AddHybridButton(ID_TRIANGLE
, wxT("Triangle"), wxBitmap(triangle_xpm
));
302 shapes
->AddButton(ID_SQUARE
, wxT("Square"), wxBitmap(square_xpm
), wxEmptyString
);
303 shapes
->AddDropdownButton(ID_POLYGON
, wxT("Other Polygon"), wxBitmap(hexagon_xpm
), wxEmptyString
);
305 wxRibbonPanel
*sizer_panel
= new wxRibbonPanel(home
, wxID_ANY
, wxT("Panel with Sizer"),
306 wxNullBitmap
, wxDefaultPosition
, wxDefaultSize
,
307 wxRIBBON_PANEL_DEFAULT_STYLE
);
310 as
.Add("Item 1 using a box sizer now");
311 as
.Add("Item 2 using a box sizer now");
312 wxComboBox
* sizer_panelcombo
= new wxComboBox(sizer_panel
, wxID_ANY
,
314 wxDefaultPosition
, wxDefaultSize
,
317 wxComboBox
* sizer_panelcombo2
= new wxComboBox(sizer_panel
, wxID_ANY
,
319 wxDefaultPosition
, wxDefaultSize
,
322 sizer_panelcombo
->Select(0);
323 sizer_panelcombo2
->Select(1);
324 sizer_panelcombo
->SetMinSize(wxSize(150, -1));
325 sizer_panelcombo2
->SetMinSize(wxSize(150, -1));
327 //not using wxWrapSizer(wxHORIZONTAL) as it reports an incorrect min height
328 wxSizer
* sizer_panelsizer
= new wxBoxSizer(wxVERTICAL
);
329 sizer_panelsizer
->AddStretchSpacer(1);
330 sizer_panelsizer
->Add(sizer_panelcombo
, 0, wxALL
|wxEXPAND
, 2);
331 sizer_panelsizer
->Add(sizer_panelcombo2
, 0, wxALL
|wxEXPAND
, 2);
332 sizer_panelsizer
->AddStretchSpacer(1);
333 sizer_panel
->SetSizer(sizer_panelsizer
);
335 wxFont
label_font(8, wxFONTFAMILY_DEFAULT
, wxFONTSTYLE_NORMAL
, wxFONTWEIGHT_LIGHT
);
336 m_bitmap_creation_dc
.SetFont(label_font
);
338 wxRibbonPage
* scheme
= new wxRibbonPage(m_ribbon
, wxID_ANY
, wxT("Appearance"), eye_xpm
);
339 m_ribbon
->GetArtProvider()->GetColourScheme(&m_default_primary
,
340 &m_default_secondary
, &m_default_tertiary
);
341 wxRibbonPanel
*provider_panel
= new wxRibbonPanel(scheme
, wxID_ANY
,
342 wxT("Art"), wxNullBitmap
, wxDefaultPosition
, wxDefaultSize
, wxRIBBON_PANEL_NO_AUTO_MINIMISE
);
343 wxRibbonButtonBar
*provider_bar
= new wxRibbonButtonBar(provider_panel
, wxID_ANY
);
344 provider_bar
->AddButton(ID_DEFAULT_PROVIDER
, wxT("Default Provider"),
345 wxArtProvider::GetBitmap(wxART_QUESTION
, wxART_OTHER
, wxSize(32, 32)));
346 provider_bar
->AddButton(ID_AUI_PROVIDER
, wxT("AUI Provider"), aui_style_xpm
);
347 provider_bar
->AddButton(ID_MSW_PROVIDER
, wxT("MSW Provider"), msw_style_xpm
);
348 wxRibbonPanel
*primary_panel
= new wxRibbonPanel(scheme
, wxID_ANY
,
349 wxT("Primary Colour"), colours_xpm
);
350 m_primary_gallery
= PopulateColoursPanel(primary_panel
,
351 m_default_primary
, ID_PRIMARY_COLOUR
);
352 wxRibbonPanel
*secondary_panel
= new wxRibbonPanel(scheme
, wxID_ANY
,
353 wxT("Secondary Colour"), colours_xpm
);
354 m_secondary_gallery
= PopulateColoursPanel(secondary_panel
,
355 m_default_secondary
, ID_SECONDARY_COLOUR
);
358 wxRibbonPage
* page
= new wxRibbonPage(m_ribbon
, wxID_ANY
, wxT("UI Updated"), ribbon_xpm
);
359 wxRibbonPanel
*panel
= new wxRibbonPanel(page
, wxID_ANY
, wxT("Enable/Disable"), ribbon_xpm
);
360 wxRibbonButtonBar
*bar
= new wxRibbonButtonBar(panel
, wxID_ANY
);
361 bar
->AddButton(ID_DISABLED
, wxT("Disabled"), ribbon_xpm
);
362 bar
->AddButton(ID_ENABLE
, wxT("Enable"), ribbon_xpm
);
363 bar
->AddButton(ID_DISABLE
, wxT("Disable"), ribbon_xpm
);
364 bar
->AddButton(ID_UI_ENABLE_UPDATED
, wxT("Enable UI updated"), ribbon_xpm
);
365 bar
->EnableButton(ID_DISABLED
, false);
368 panel
= new wxRibbonPanel(page
, wxID_ANY
, wxT("Toggle"), ribbon_xpm
);
369 bar
= new wxRibbonButtonBar(panel
, wxID_ANY
);
370 bar
->AddButton(ID_CHECK
, wxT("Toggle"), ribbon_xpm
);
371 bar
->AddToggleButton(ID_UI_CHECK_UPDATED
, wxT("Toggled UI updated"), ribbon_xpm
);
374 panel
= new wxRibbonPanel(page
, wxID_ANY
, wxT("Change text"), ribbon_xpm
);
375 bar
= new wxRibbonButtonBar(panel
, wxID_ANY
);
376 bar
->AddButton(ID_CHANGE_TEXT1
, wxT("One"), ribbon_xpm
);
377 bar
->AddButton(ID_CHANGE_TEXT2
, wxT("Two"), ribbon_xpm
);
378 bar
->AddButton(ID_UI_CHANGE_TEXT_UPDATED
, wxT("Zero"), ribbon_xpm
);
380 new wxRibbonPage(m_ribbon
, wxID_ANY
, wxT("Empty Page"), empty_xpm
);
381 new wxRibbonPage(m_ribbon
, wxID_ANY
, wxT("Another Page"), empty_xpm
);
385 m_logwindow
= new wxTextCtrl(this, wxID_ANY
, wxEmptyString
,
386 wxDefaultPosition
, wxDefaultSize
, wxTE_MULTILINE
| wxTE_READONLY
|
387 wxTE_LEFT
| wxTE_BESTWRAP
| wxBORDER_NONE
);
389 m_togglePanels
= new wxToggleButton(this, ID_TOGGLE_PANELS
, "&Toggle panels");
390 m_togglePanels
->SetValue(true);
392 wxSizer
*s
= new wxBoxSizer(wxVERTICAL
);
394 s
->Add(m_ribbon
, 0, wxEXPAND
);
395 s
->Add(m_logwindow
, 1, wxEXPAND
);
396 s
->Add(m_togglePanels
, wxSizerFlags().Border());
401 void MyFrame::SetBarStyle(long style
)
404 m_ribbon
->SetWindowStyleFlag(style
);
405 wxBoxSizer
*pTopSize
= reinterpret_cast<wxBoxSizer
*>(GetSizer());
406 wxRibbonToolBar
*pToolbar
= wxDynamicCast(FindWindow(ID_MAIN_TOOLBAR
), wxRibbonToolBar
);
407 if(style
& wxRIBBON_BAR_FLOW_VERTICAL
)
409 m_ribbon
->SetTabCtrlMargins(10, 10);
410 pTopSize
->SetOrientation(wxHORIZONTAL
);
412 pToolbar
->SetRows(3, 5);
416 m_ribbon
->SetTabCtrlMargins(50, 20);
417 pTopSize
->SetOrientation(wxVERTICAL
);
419 pToolbar
->SetRows(2, 3);
430 class ColourClientData
: public wxClientData
433 ColourClientData(const wxString
& name
, const wxColour
& colour
)
434 : m_name(name
), m_colour(colour
) {}
436 const wxString
& GetName() const {return m_name
;}
437 const wxColour
& GetColour() const {return m_colour
;}
444 wxRibbonGallery
* MyFrame::PopulateColoursPanel(wxWindow
* panel
,
445 wxColour def
, int gallery_id
)
447 wxRibbonGallery
*gallery
= wxDynamicCast(panel
->FindWindow(gallery_id
), wxRibbonGallery
);
451 gallery
= new wxRibbonGallery(panel
, gallery_id
);
452 wxMemoryDC
& dc
= m_bitmap_creation_dc
;
453 wxRibbonGalleryItem
*def_item
=
454 AddColourToGallery(gallery
, wxT("Default"), dc
, &def
);
455 gallery
->SetSelection(def_item
);
456 AddColourToGallery(gallery
, wxT("BLUE"), dc
);
457 AddColourToGallery(gallery
, wxT("BLUE VIOLET"), dc
);
458 AddColourToGallery(gallery
, wxT("BROWN"), dc
);
459 AddColourToGallery(gallery
, wxT("CADET BLUE"), dc
);
460 AddColourToGallery(gallery
, wxT("CORAL"), dc
);
461 AddColourToGallery(gallery
, wxT("CYAN"), dc
);
462 AddColourToGallery(gallery
, wxT("DARK GREEN"), dc
);
463 AddColourToGallery(gallery
, wxT("DARK ORCHID"), dc
);
464 AddColourToGallery(gallery
, wxT("FIREBRICK"), dc
);
465 AddColourToGallery(gallery
, wxT("GOLD"), dc
);
466 AddColourToGallery(gallery
, wxT("GOLDENROD"), dc
);
467 AddColourToGallery(gallery
, wxT("GREEN"), dc
);
468 AddColourToGallery(gallery
, wxT("INDIAN RED"), dc
);
469 AddColourToGallery(gallery
, wxT("KHAKI"), dc
);
470 AddColourToGallery(gallery
, wxT("LIGHT BLUE"), dc
);
471 AddColourToGallery(gallery
, wxT("LIME GREEN"), dc
);
472 AddColourToGallery(gallery
, wxT("MAGENTA"), dc
);
473 AddColourToGallery(gallery
, wxT("MAROON"), dc
);
474 AddColourToGallery(gallery
, wxT("NAVY"), dc
);
475 AddColourToGallery(gallery
, wxT("ORANGE"), dc
);
476 AddColourToGallery(gallery
, wxT("ORCHID"), dc
);
477 AddColourToGallery(gallery
, wxT("PINK"), dc
);
478 AddColourToGallery(gallery
, wxT("PLUM"), dc
);
479 AddColourToGallery(gallery
, wxT("PURPLE"), dc
);
480 AddColourToGallery(gallery
, wxT("RED"), dc
);
481 AddColourToGallery(gallery
, wxT("SALMON"), dc
);
482 AddColourToGallery(gallery
, wxT("SEA GREEN"), dc
);
483 AddColourToGallery(gallery
, wxT("SIENNA"), dc
);
484 AddColourToGallery(gallery
, wxT("SKY BLUE"), dc
);
485 AddColourToGallery(gallery
, wxT("TAN"), dc
);
486 AddColourToGallery(gallery
, wxT("THISTLE"), dc
);
487 AddColourToGallery(gallery
, wxT("TURQUOISE"), dc
);
488 AddColourToGallery(gallery
, wxT("VIOLET"), dc
);
489 AddColourToGallery(gallery
, wxT("VIOLET RED"), dc
);
490 AddColourToGallery(gallery
, wxT("WHEAT"), dc
);
491 AddColourToGallery(gallery
, wxT("WHITE"), dc
);
492 AddColourToGallery(gallery
, wxT("YELLOW"), dc
);
497 wxColour
MyFrame::GetGalleryColour(wxRibbonGallery
*gallery
,
498 wxRibbonGalleryItem
* item
, wxString
* name
)
500 ColourClientData
*data
= (ColourClientData
*)gallery
->GetItemClientObject(item
);
502 *name
= data
->GetName();
503 return data
->GetColour();
506 void MyFrame::OnHoveredColourChange(wxRibbonGalleryEvent
& evt
)
508 // Set the background of the gallery to the hovered colour, or back to the
509 // default if there is no longer a hovered item.
511 wxRibbonGallery
*gallery
= evt
.GetGallery();
512 wxRibbonArtProvider
*provider
= gallery
->GetArtProvider();
514 if(evt
.GetGalleryItem() != NULL
)
516 if(provider
== m_ribbon
->GetArtProvider())
518 provider
= provider
->Clone();
519 gallery
->SetArtProvider(provider
);
521 provider
->SetColour(wxRIBBON_ART_GALLERY_HOVER_BACKGROUND_COLOUR
,
522 GetGalleryColour(evt
.GetGallery(), evt
.GetGalleryItem(), NULL
));
526 if(provider
!= m_ribbon
->GetArtProvider())
528 gallery
->SetArtProvider(m_ribbon
->GetArtProvider());
534 void MyFrame::OnPrimaryColourSelect(wxRibbonGalleryEvent
& evt
)
537 wxColour colour
= GetGalleryColour(evt
.GetGallery(), evt
.GetGalleryItem(), &name
);
538 AddText(wxT("Colour \"") + name
+ wxT("\" selected as primary."));
539 wxColour secondary
, tertiary
;
540 m_ribbon
->GetArtProvider()->GetColourScheme(NULL
, &secondary
, &tertiary
);
541 m_ribbon
->GetArtProvider()->SetColourScheme(colour
, secondary
, tertiary
);
542 ResetGalleryArtProviders();
546 void MyFrame::OnSecondaryColourSelect(wxRibbonGalleryEvent
& evt
)
549 wxColour colour
= GetGalleryColour(evt
.GetGallery(), evt
.GetGalleryItem(), &name
);
550 AddText(wxT("Colour \"") + name
+ wxT("\" selected as secondary."));
551 wxColour primary
, tertiary
;
552 m_ribbon
->GetArtProvider()->GetColourScheme(&primary
, NULL
, &tertiary
);
553 m_ribbon
->GetArtProvider()->SetColourScheme(primary
, colour
, tertiary
);
554 ResetGalleryArtProviders();
558 void MyFrame::ResetGalleryArtProviders()
560 if(m_primary_gallery
->GetArtProvider() != m_ribbon
->GetArtProvider())
562 delete m_primary_gallery
->GetArtProvider();
563 m_primary_gallery
->SetArtProvider(m_ribbon
->GetArtProvider());
565 if(m_secondary_gallery
->GetArtProvider() != m_ribbon
->GetArtProvider())
567 delete m_secondary_gallery
->GetArtProvider();
568 m_secondary_gallery
->SetArtProvider(m_ribbon
->GetArtProvider());
572 void MyFrame::OnChangeText1(wxRibbonButtonBarEvent
& WXUNUSED(evt
))
574 m_new_text
= wxT("One");
577 void MyFrame::OnChangeText2(wxRibbonButtonBarEvent
& WXUNUSED(evt
))
579 m_new_text
= wxT("Two");
582 void MyFrame::OnEnable(wxRibbonButtonBarEvent
& WXUNUSED(evt
))
587 void MyFrame::OnDisable(wxRibbonButtonBarEvent
& WXUNUSED(evt
))
592 void MyFrame::OnCheck(wxRibbonButtonBarEvent
& WXUNUSED(evt
))
594 m_bChecked
= !m_bChecked
;
597 void MyFrame::OnEnableUpdateUI(wxUpdateUIEvent
& evt
)
599 evt
.Enable(m_bEnabled
);
602 void MyFrame::OnCheckUpdateUI(wxUpdateUIEvent
& evt
)
604 evt
.Check(m_bChecked
);
607 void MyFrame::OnChangeTextUpdateUI(wxUpdateUIEvent
& evt
)
609 if ( !m_new_text
.IsEmpty() )
611 evt
.SetText(m_new_text
);
612 m_new_text
= wxT("");
616 void MyFrame::OnSelectionExpandHButton(wxRibbonButtonBarEvent
& WXUNUSED(evt
))
618 AddText(wxT("Expand selection horizontally button clicked."));
621 void MyFrame::OnSelectionExpandVButton(wxRibbonButtonBarEvent
& WXUNUSED(evt
))
623 AddText(wxT("Expand selection vertically button clicked."));
626 void MyFrame::OnSelectionContractButton(wxRibbonButtonBarEvent
& WXUNUSED(evt
))
628 AddText(wxT("Contract selection button clicked."));
631 void MyFrame::OnCircleButton(wxRibbonButtonBarEvent
& WXUNUSED(evt
))
633 AddText(wxT("Circle button clicked."));
636 void MyFrame::OnCrossButton(wxRibbonButtonBarEvent
& WXUNUSED(evt
))
638 AddText(wxT("Cross button clicked."));
641 void MyFrame::OnTriangleButton(wxRibbonButtonBarEvent
& WXUNUSED(evt
))
643 AddText(wxT("Triangle button clicked."));
646 void MyFrame::OnTriangleDropdown(wxRibbonButtonBarEvent
& evt
)
649 menu
.Append(wxID_ANY
, wxT("Equilateral"));
650 menu
.Append(wxID_ANY
, wxT("Isosceles"));
651 menu
.Append(wxID_ANY
, wxT("Scalene"));
653 evt
.PopupMenu(&menu
);
656 void MyFrame::OnSquareButton(wxRibbonButtonBarEvent
& WXUNUSED(evt
))
658 AddText(wxT("Square button clicked."));
661 void MyFrame::OnPolygonDropdown(wxRibbonButtonBarEvent
& evt
)
664 menu
.Append(wxID_ANY
, wxT("Pentagon (5 sided)"));
665 menu
.Append(wxID_ANY
, wxT("Hexagon (6 sided)"));
666 menu
.Append(wxID_ANY
, wxT("Heptagon (7 sided)"));
667 menu
.Append(wxID_ANY
, wxT("Octogon (8 sided)"));
668 menu
.Append(wxID_ANY
, wxT("Nonagon (9 sided)"));
669 menu
.Append(wxID_ANY
, wxT("Decagon (10 sided)"));
671 evt
.PopupMenu(&menu
);
674 void MyFrame::OnJustify(wxRibbonToolBarEvent
& evt
)
676 long style
= m_logwindow
->GetWindowStyle() &
677 ~(wxTE_LEFT
| wxTE_CENTER
| wxTE_RIGHT
);
680 case wxID_JUSTIFY_LEFT
:
681 m_logwindow
->SetWindowStyle(style
| wxTE_LEFT
);
683 case wxID_JUSTIFY_CENTER
:
684 m_logwindow
->SetWindowStyle(style
| wxTE_CENTER
);
686 case wxID_JUSTIFY_RIGHT
:
687 m_logwindow
->SetWindowStyle(style
| wxTE_RIGHT
);
692 void MyFrame::OnJustifyUpdateUI(wxUpdateUIEvent
& evt
)
696 case wxID_JUSTIFY_LEFT
:
697 evt
.Check(!m_logwindow
->HasFlag(wxTE_CENTER
| wxTE_RIGHT
));
699 case wxID_JUSTIFY_CENTER
:
700 evt
.Check(m_logwindow
->HasFlag(wxTE_CENTER
));
702 case wxID_JUSTIFY_RIGHT
:
703 evt
.Check(m_logwindow
->HasFlag(wxTE_RIGHT
));
708 void MyFrame::OnNew(wxRibbonToolBarEvent
& WXUNUSED(evt
))
710 AddText(wxT("New button clicked."));
713 void MyFrame::OnNewDropdown(wxRibbonToolBarEvent
& evt
)
716 menu
.Append(wxID_ANY
, wxT("New Document"));
717 menu
.Append(wxID_ANY
, wxT("New Template"));
718 menu
.Append(wxID_ANY
, wxT("New Mail"));
720 evt
.PopupMenu(&menu
);
723 void MyFrame::OnPrint(wxRibbonToolBarEvent
& WXUNUSED(evt
))
725 AddText(wxT("Print button clicked."));
728 void MyFrame::OnPrintDropdown(wxRibbonToolBarEvent
& evt
)
731 menu
.Append(wxID_ANY
, wxT("Print"));
732 menu
.Append(wxID_ANY
, wxT("Preview"));
733 menu
.Append(wxID_ANY
, wxT("Options"));
735 evt
.PopupMenu(&menu
);
738 void MyFrame::OnRedoDropdown(wxRibbonToolBarEvent
& evt
)
741 menu
.Append(wxID_ANY
, wxT("Redo E"));
742 menu
.Append(wxID_ANY
, wxT("Redo F"));
743 menu
.Append(wxID_ANY
, wxT("Redo G"));
745 evt
.PopupMenu(&menu
);
748 void MyFrame::OnUndoDropdown(wxRibbonToolBarEvent
& evt
)
751 menu
.Append(wxID_ANY
, wxT("Undo C"));
752 menu
.Append(wxID_ANY
, wxT("Undo B"));
753 menu
.Append(wxID_ANY
, wxT("Undo A"));
755 evt
.PopupMenu(&menu
);
758 void MyFrame::OnPositionTopLabels(wxCommandEvent
& WXUNUSED(evt
))
760 SetBarStyle(wxRIBBON_BAR_DEFAULT_STYLE
);
763 void MyFrame::OnPositionTopIcons(wxCommandEvent
& WXUNUSED(evt
))
765 SetBarStyle((wxRIBBON_BAR_DEFAULT_STYLE
&~wxRIBBON_BAR_SHOW_PAGE_LABELS
)
766 | wxRIBBON_BAR_SHOW_PAGE_ICONS
);
769 void MyFrame::OnPositionTopBoth(wxCommandEvent
& WXUNUSED(evt
))
771 SetBarStyle(wxRIBBON_BAR_DEFAULT_STYLE
| wxRIBBON_BAR_SHOW_PAGE_ICONS
);
774 void MyFrame::OnPositionLeftLabels(wxCommandEvent
& WXUNUSED(evt
))
776 SetBarStyle(wxRIBBON_BAR_DEFAULT_STYLE
| wxRIBBON_BAR_FLOW_VERTICAL
);
779 void MyFrame::OnPositionLeftIcons(wxCommandEvent
& WXUNUSED(evt
))
781 SetBarStyle((wxRIBBON_BAR_DEFAULT_STYLE
&~wxRIBBON_BAR_SHOW_PAGE_LABELS
) |
782 wxRIBBON_BAR_SHOW_PAGE_ICONS
| wxRIBBON_BAR_FLOW_VERTICAL
);
785 void MyFrame::OnPositionLeftBoth(wxCommandEvent
& WXUNUSED(evt
))
787 SetBarStyle(wxRIBBON_BAR_DEFAULT_STYLE
| wxRIBBON_BAR_SHOW_PAGE_ICONS
|
788 wxRIBBON_BAR_FLOW_VERTICAL
);
791 void MyFrame::OnPositionTop(wxRibbonToolBarEvent
& evt
)
793 OnPositionTopLabels(evt
);
796 void MyFrame::OnPositionTopDropdown(wxRibbonToolBarEvent
& evt
)
799 menu
.Append(ID_POSITION_TOP
, wxT("Top with Labels"));
800 menu
.Append(ID_POSITION_TOP_ICONS
, wxT("Top with Icons"));
801 menu
.Append(ID_POSITION_TOP_BOTH
, wxT("Top with Both"));
802 evt
.PopupMenu(&menu
);
805 void MyFrame::OnPositionLeft(wxRibbonToolBarEvent
& evt
)
807 OnPositionLeftIcons(evt
);
810 void MyFrame::OnPositionLeftDropdown(wxRibbonToolBarEvent
& evt
)
813 menu
.Append(ID_POSITION_LEFT
, wxT("Left with Icons"));
814 menu
.Append(ID_POSITION_LEFT_LABELS
, wxT("Left with Labels"));
815 menu
.Append(ID_POSITION_LEFT_BOTH
, wxT("Left with Both"));
816 evt
.PopupMenu(&menu
);
819 void MyFrame::OnTogglePanels(wxCommandEvent
& WXUNUSED(evt
))
821 m_ribbon
->ShowPanels(m_togglePanels
->GetValue());
824 void MyFrame::AddText(wxString msg
)
826 m_logwindow
->AppendText(msg
);
827 m_logwindow
->AppendText(wxT("\n"));
828 m_ribbon
->DismissExpandedPanel();
831 wxRibbonGalleryItem
* MyFrame::AddColourToGallery(wxRibbonGallery
*gallery
,
832 wxString colour
, wxMemoryDC
& dc
,
835 wxRibbonGalleryItem
* item
= NULL
;
837 if (colour
!= wxT("Default"))
838 c
= wxColour(colour
);
843 const int iWidth
= 64;
844 const int iHeight
= 40;
846 wxBitmap
bitmap(iWidth
, iHeight
);
847 dc
.SelectObject(bitmap
);
849 dc
.SetPen(*wxBLACK_PEN
);
851 dc
.DrawRectangle(0, 0, iWidth
, iHeight
);
853 colour
= colour
.Mid(0, 1) + colour
.Mid(1).Lower();
854 wxSize size
= dc
.GetTextExtent(colour
);
855 wxColour foreground
= wxColour(~c
.Red(), ~c
.Green(), ~c
.Blue());
856 if(abs(foreground
.Red() - c
.Red()) + abs(foreground
.Blue() - c
.Blue())
857 + abs(foreground
.Green() - c
.Green()) < 64)
859 // Foreground too similar to background - use a different
860 // strategy to find a contrasting colour
861 foreground
= wxColour((c
.Red() + 64) % 256, 255 - c
.Green(),
862 (c
.Blue() + 192) % 256);
864 dc
.SetTextForeground(foreground
);
865 dc
.DrawText(colour
, (iWidth
- size
.GetWidth() + 1) / 2,
866 (iHeight
- size
.GetHeight()) / 2);
867 dc
.SelectObjectAsSource(wxNullBitmap
);
869 item
= gallery
->Append(bitmap
, wxID_ANY
);
870 gallery
->SetItemClientObject(item
, new ColourClientData(colour
, c
));
875 void MyFrame::OnColourGalleryButton(wxCommandEvent
& evt
)
877 wxRibbonGallery
*gallery
= wxDynamicCast(evt
.GetEventObject(), wxRibbonGallery
);
881 m_ribbon
->DismissExpandedPanel();
882 if(gallery
->GetSelection())
883 m_colour_data
.SetColour(GetGalleryColour(gallery
, gallery
->GetSelection(), NULL
));
884 wxColourDialog
dlg(this, &m_colour_data
);
885 if(dlg
.ShowModal() == wxID_OK
)
887 m_colour_data
= dlg
.GetColourData();
888 wxColour clr
= m_colour_data
.GetColour();
890 // Try to find colour in gallery
891 wxRibbonGalleryItem
*item
= NULL
;
892 for(unsigned int i
= 0; i
< gallery
->GetCount(); ++i
)
894 item
= gallery
->GetItem(i
);
895 if(GetGalleryColour(gallery
, item
, NULL
) == clr
)
901 // Colour not in gallery - add it
904 item
= AddColourToGallery(gallery
,
905 clr
.GetAsString(wxC2S_HTML_SYNTAX
), m_bitmap_creation_dc
,
911 gallery
->EnsureVisible(item
);
912 gallery
->SetSelection(item
);
914 // Send an event to respond to the selection change
915 wxRibbonGalleryEvent
dummy(wxEVT_COMMAND_RIBBONGALLERY_SELECTED
, gallery
->GetId());
916 dummy
.SetEventObject(gallery
);
917 dummy
.SetGallery(gallery
);
918 dummy
.SetGalleryItem(item
);
919 ProcessWindowEvent(dummy
);
923 void MyFrame::OnDefaultProvider(wxRibbonButtonBarEvent
& WXUNUSED(evt
))
925 m_ribbon
->DismissExpandedPanel();
926 SetArtProvider(new wxRibbonDefaultArtProvider
);
929 void MyFrame::OnAUIProvider(wxRibbonButtonBarEvent
& WXUNUSED(evt
))
931 m_ribbon
->DismissExpandedPanel();
932 SetArtProvider(new wxRibbonAUIArtProvider
);
935 void MyFrame::OnMSWProvider(wxRibbonButtonBarEvent
& WXUNUSED(evt
))
937 m_ribbon
->DismissExpandedPanel();
938 SetArtProvider(new wxRibbonMSWArtProvider
);
941 void MyFrame::SetArtProvider(wxRibbonArtProvider
*prov
)
944 m_ribbon
->SetArtProvider(prov
);
946 prov
->GetColourScheme(&m_default_primary
, &m_default_secondary
,
947 &m_default_tertiary
);
948 PopulateColoursPanel(m_primary_gallery
->GetParent(), m_default_primary
,
950 PopulateColoursPanel(m_secondary_gallery
->GetParent(), m_default_secondary
,
951 ID_SECONDARY_COLOUR
);
955 GetSizer()->Layout();