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 OnNew(wxRibbonToolBarEvent
& evt
);
112 void OnNewDropdown(wxRibbonToolBarEvent
& evt
);
113 void OnPrint(wxRibbonToolBarEvent
& evt
);
114 void OnPrintDropdown(wxRibbonToolBarEvent
& evt
);
115 void OnRedoDropdown(wxRibbonToolBarEvent
& evt
);
116 void OnUndoDropdown(wxRibbonToolBarEvent
& evt
);
117 void OnPositionTop(wxRibbonToolBarEvent
& evt
);
118 void OnPositionTopLabels(wxCommandEvent
& evt
);
119 void OnPositionTopIcons(wxCommandEvent
& evt
);
120 void OnPositionTopBoth(wxCommandEvent
& evt
);
121 void OnPositionTopDropdown(wxRibbonToolBarEvent
& evt
);
122 void OnPositionLeft(wxRibbonToolBarEvent
& evt
);
123 void OnPositionLeftLabels(wxCommandEvent
& evt
);
124 void OnPositionLeftIcons(wxCommandEvent
& evt
);
125 void OnPositionLeftBoth(wxCommandEvent
& evt
);
126 void OnPositionLeftDropdown(wxRibbonToolBarEvent
& evt
);
128 void OnTogglePanels(wxCommandEvent
& evt
);
131 wxRibbonGallery
* PopulateColoursPanel(wxWindow
* panel
, wxColour def
,
133 void AddText(wxString msg
);
134 wxRibbonGalleryItem
* AddColourToGallery(wxRibbonGallery
*gallery
,
135 wxString name
, wxMemoryDC
& dc
, wxColour
* value
= NULL
);
136 wxColour
GetGalleryColour(wxRibbonGallery
*gallery
,
137 wxRibbonGalleryItem
* item
, wxString
* name
);
138 void ResetGalleryArtProviders();
139 void SetArtProvider(wxRibbonArtProvider
* prov
);
140 void SetBarStyle(long style
);
142 wxRibbonBar
* m_ribbon
;
143 wxRibbonGallery
* m_primary_gallery
;
144 wxRibbonGallery
* m_secondary_gallery
;
145 wxTextCtrl
* m_logwindow
;
146 wxToggleButton
* m_togglePanels
;
148 wxColourData m_colour_data
;
149 wxColour m_default_primary
;
150 wxColour m_default_secondary
;
151 wxColour m_default_tertiary
;
152 wxMemoryDC m_bitmap_creation_dc
;
157 DECLARE_EVENT_TABLE()
160 // -- implementations --
167 wxFrame
* frame
= new MyFrame
;
173 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
174 EVT_RIBBONBUTTONBAR_CLICKED(ID_ENABLE
, MyFrame::OnEnable
)
175 EVT_RIBBONBUTTONBAR_CLICKED(ID_DISABLE
, MyFrame::OnDisable
)
176 EVT_UPDATE_UI(ID_UI_ENABLE_UPDATED
, MyFrame::OnEnableUpdateUI
)
177 EVT_RIBBONBUTTONBAR_CLICKED(ID_CHECK
, MyFrame::OnCheck
)
178 EVT_UPDATE_UI(ID_UI_CHECK_UPDATED
, MyFrame::OnCheckUpdateUI
)
179 EVT_RIBBONBUTTONBAR_CLICKED(ID_CHANGE_TEXT1
, MyFrame::OnChangeText1
)
180 EVT_RIBBONBUTTONBAR_CLICKED(ID_CHANGE_TEXT2
, MyFrame::OnChangeText2
)
181 EVT_UPDATE_UI(ID_UI_CHANGE_TEXT_UPDATED
, MyFrame::OnChangeTextUpdateUI
)
182 EVT_RIBBONBUTTONBAR_CLICKED(ID_DEFAULT_PROVIDER
, MyFrame::OnDefaultProvider
)
183 EVT_RIBBONBUTTONBAR_CLICKED(ID_AUI_PROVIDER
, MyFrame::OnAUIProvider
)
184 EVT_RIBBONBUTTONBAR_CLICKED(ID_MSW_PROVIDER
, MyFrame::OnMSWProvider
)
185 EVT_RIBBONBUTTONBAR_CLICKED(ID_SELECTION_EXPAND_H
, MyFrame::OnSelectionExpandHButton
)
186 EVT_RIBBONBUTTONBAR_CLICKED(ID_SELECTION_EXPAND_V
, MyFrame::OnSelectionExpandVButton
)
187 EVT_RIBBONBUTTONBAR_CLICKED(ID_SELECTION_CONTRACT
, MyFrame::OnSelectionContractButton
)
188 EVT_RIBBONBUTTONBAR_CLICKED(ID_CIRCLE
, MyFrame::OnCircleButton
)
189 EVT_RIBBONBUTTONBAR_CLICKED(ID_CROSS
, MyFrame::OnCrossButton
)
190 EVT_RIBBONBUTTONBAR_CLICKED(ID_TRIANGLE
, MyFrame::OnTriangleButton
)
191 EVT_RIBBONBUTTONBAR_CLICKED(ID_SQUARE
, MyFrame::OnSquareButton
)
192 EVT_RIBBONBUTTONBAR_DROPDOWN_CLICKED(ID_TRIANGLE
, MyFrame::OnTriangleDropdown
)
193 EVT_RIBBONBUTTONBAR_DROPDOWN_CLICKED(ID_POLYGON
, MyFrame::OnPolygonDropdown
)
194 EVT_RIBBONGALLERY_HOVER_CHANGED(ID_PRIMARY_COLOUR
, MyFrame::OnHoveredColourChange
)
195 EVT_RIBBONGALLERY_HOVER_CHANGED(ID_SECONDARY_COLOUR
, MyFrame::OnHoveredColourChange
)
196 EVT_RIBBONGALLERY_SELECTED(ID_PRIMARY_COLOUR
, MyFrame::OnPrimaryColourSelect
)
197 EVT_RIBBONGALLERY_SELECTED(ID_SECONDARY_COLOUR
, MyFrame::OnSecondaryColourSelect
)
198 EVT_RIBBONTOOLBAR_CLICKED(wxID_NEW
, MyFrame::OnNew
)
199 EVT_RIBBONTOOLBAR_DROPDOWN_CLICKED(wxID_NEW
, MyFrame::OnNewDropdown
)
200 EVT_RIBBONTOOLBAR_CLICKED(wxID_PRINT
, MyFrame::OnPrint
)
201 EVT_RIBBONTOOLBAR_DROPDOWN_CLICKED(wxID_PRINT
, MyFrame::OnPrintDropdown
)
202 EVT_RIBBONTOOLBAR_DROPDOWN_CLICKED(wxID_REDO
, MyFrame::OnRedoDropdown
)
203 EVT_RIBBONTOOLBAR_DROPDOWN_CLICKED(wxID_UNDO
, MyFrame::OnUndoDropdown
)
204 EVT_RIBBONTOOLBAR_CLICKED(ID_POSITION_LEFT
, MyFrame::OnPositionLeft
)
205 EVT_RIBBONTOOLBAR_DROPDOWN_CLICKED(ID_POSITION_LEFT
, MyFrame::OnPositionLeftDropdown
)
206 EVT_RIBBONTOOLBAR_CLICKED(ID_POSITION_TOP
, MyFrame::OnPositionTop
)
207 EVT_RIBBONTOOLBAR_DROPDOWN_CLICKED(ID_POSITION_TOP
, MyFrame::OnPositionTopDropdown
)
208 EVT_BUTTON(ID_PRIMARY_COLOUR
, MyFrame::OnColourGalleryButton
)
209 EVT_BUTTON(ID_SECONDARY_COLOUR
, MyFrame::OnColourGalleryButton
)
210 EVT_MENU(ID_POSITION_LEFT
, MyFrame::OnPositionLeftIcons
)
211 EVT_MENU(ID_POSITION_LEFT_LABELS
, MyFrame::OnPositionLeftLabels
)
212 EVT_MENU(ID_POSITION_LEFT_BOTH
, MyFrame::OnPositionLeftBoth
)
213 EVT_MENU(ID_POSITION_TOP
, MyFrame::OnPositionTopLabels
)
214 EVT_MENU(ID_POSITION_TOP_ICONS
, MyFrame::OnPositionTopIcons
)
215 EVT_MENU(ID_POSITION_TOP_BOTH
, MyFrame::OnPositionTopBoth
)
216 EVT_TOGGLEBUTTON(ID_TOGGLE_PANELS
, MyFrame::OnTogglePanels
)
219 #include "align_center.xpm"
220 #include "align_left.xpm"
221 #include "align_right.xpm"
222 #include "aui_style.xpm"
223 #include "auto_crop_selection.xpm"
224 #include "auto_crop_selection_small.xpm"
225 #include "circle.xpm"
226 #include "circle_small.xpm"
227 #include "colours.xpm"
230 #include "expand_selection_v.xpm"
231 #include "expand_selection_h.xpm"
233 #include "hexagon.xpm"
234 #include "msw_style.xpm"
235 #include "position_left_small.xpm"
236 #include "position_top_small.xpm"
237 #include "ribbon.xpm"
238 #include "selection_panel.xpm"
239 #include "square.xpm"
240 #include "triangle.xpm"
243 : wxFrame(NULL
, wxID_ANY
, wxT("wxRibbon Sample Application"), wxDefaultPosition
, wxSize(800, 600), wxDEFAULT_FRAME_STYLE
)
245 m_ribbon
= new wxRibbonBar(this, wxID_ANY
);
248 wxRibbonPage
* home
= new wxRibbonPage(m_ribbon
, wxID_ANY
, wxT("Examples"), ribbon_xpm
);
249 wxRibbonPanel
*toolbar_panel
= new wxRibbonPanel(home
, wxID_ANY
, wxT("Toolbar"),
250 wxNullBitmap
, wxDefaultPosition
, wxDefaultSize
,
251 wxRIBBON_PANEL_NO_AUTO_MINIMISE
);
252 wxRibbonToolBar
*toolbar
= new wxRibbonToolBar(toolbar_panel
, ID_MAIN_TOOLBAR
);
253 toolbar
->AddTool(wxID_ANY
, align_left_xpm
);
254 toolbar
->AddTool(wxID_ANY
, align_center_xpm
);
255 toolbar
->AddTool(wxID_ANY
, align_right_xpm
);
256 toolbar
->AddSeparator();
257 toolbar
->AddHybridTool(wxID_NEW
, wxArtProvider::GetBitmap(wxART_NEW
, wxART_OTHER
, wxSize(16, 15)));
258 toolbar
->AddTool(wxID_ANY
, wxArtProvider::GetBitmap(wxART_FILE_OPEN
, wxART_OTHER
, wxSize(16, 15)));
259 toolbar
->AddTool(wxID_ANY
, wxArtProvider::GetBitmap(wxART_FILE_SAVE
, wxART_OTHER
, wxSize(16, 15)));
260 toolbar
->AddTool(wxID_ANY
, wxArtProvider::GetBitmap(wxART_FILE_SAVE_AS
, wxART_OTHER
, wxSize(16, 15)));
261 toolbar
->AddSeparator();
262 toolbar
->AddDropdownTool(wxID_UNDO
, wxArtProvider::GetBitmap(wxART_UNDO
, wxART_OTHER
, wxSize(16, 15)));
263 toolbar
->AddDropdownTool(wxID_REDO
, wxArtProvider::GetBitmap(wxART_REDO
, wxART_OTHER
, wxSize(16, 15)));
264 toolbar
->AddSeparator();
265 toolbar
->AddTool(wxID_ANY
, wxArtProvider::GetBitmap(wxART_REPORT_VIEW
, wxART_OTHER
, wxSize(16, 15)));
266 toolbar
->AddTool(wxID_ANY
, wxArtProvider::GetBitmap(wxART_LIST_VIEW
, wxART_OTHER
, wxSize(16, 15)));
267 toolbar
->AddSeparator();
268 toolbar
->AddHybridTool(ID_POSITION_LEFT
, position_left_xpm
,
269 "Align ribbonbar vertically\non the left\nfor demonstration purposes");
270 toolbar
->AddHybridTool(ID_POSITION_TOP
, position_top_xpm
,
271 "Align the ribbonbar horizontally\nat the top\nfor demonstration purposes");
272 toolbar
->AddSeparator();
273 toolbar
->AddHybridTool(wxID_PRINT
, wxArtProvider::GetBitmap(wxART_PRINT
, wxART_OTHER
, wxSize(16, 15)),
274 "This is the Print button tooltip\ndemonstrating a tooltip");
275 toolbar
->SetRows(2, 3);
277 wxRibbonPanel
*selection_panel
= new wxRibbonPanel(home
, wxID_ANY
, wxT("Selection"), wxBitmap(selection_panel_xpm
));
278 wxRibbonButtonBar
*selection
= new wxRibbonButtonBar(selection_panel
);
279 selection
->AddButton(ID_SELECTION_EXPAND_V
, wxT("Expand Vertically"), wxBitmap(expand_selection_v_xpm
),
280 "This is a tooltip for Expand Vertically\ndemonstrating a tooltip");
281 selection
->AddButton(ID_SELECTION_EXPAND_H
, wxT("Expand Horizontally"), wxBitmap(expand_selection_h_xpm
), wxEmptyString
);
282 selection
->AddButton(ID_SELECTION_CONTRACT
, wxT("Contract"), wxBitmap(auto_crop_selection_xpm
), wxBitmap(auto_crop_selection_small_xpm
));
284 wxRibbonPanel
*shapes_panel
= new wxRibbonPanel(home
, wxID_ANY
, wxT("Shapes"), wxBitmap(circle_small_xpm
));
285 wxRibbonButtonBar
*shapes
= new wxRibbonButtonBar(shapes_panel
);
286 shapes
->AddButton(ID_CIRCLE
, wxT("Circle"), wxBitmap(circle_xpm
), wxBitmap(circle_small_xpm
),
287 wxNullBitmap
, wxNullBitmap
, wxRIBBON_BUTTON_NORMAL
,
288 "This is a tooltip for the circle button\ndemonstrating another tooltip");
289 shapes
->AddButton(ID_CROSS
, wxT("Cross"), wxBitmap(cross_xpm
), wxEmptyString
);
290 shapes
->AddHybridButton(ID_TRIANGLE
, wxT("Triangle"), wxBitmap(triangle_xpm
));
291 shapes
->AddButton(ID_SQUARE
, wxT("Square"), wxBitmap(square_xpm
), wxEmptyString
);
292 shapes
->AddDropdownButton(ID_POLYGON
, wxT("Other Polygon"), wxBitmap(hexagon_xpm
), wxEmptyString
);
294 wxRibbonPanel
*sizer_panel
= new wxRibbonPanel(home
, wxID_ANY
, wxT("Panel with Sizer"),
295 wxNullBitmap
, wxDefaultPosition
, wxDefaultSize
,
296 wxRIBBON_PANEL_DEFAULT_STYLE
);
299 as
.Add("Item 1 using a box sizer now");
300 as
.Add("Item 2 using a box sizer now");
301 wxComboBox
* sizer_panelcombo
= new wxComboBox(sizer_panel
, wxID_ANY
,
303 wxDefaultPosition
, wxDefaultSize
,
306 wxComboBox
* sizer_panelcombo2
= new wxComboBox(sizer_panel
, wxID_ANY
,
308 wxDefaultPosition
, wxDefaultSize
,
311 sizer_panelcombo
->Select(0);
312 sizer_panelcombo2
->Select(1);
313 sizer_panelcombo
->SetMinSize(wxSize(150, -1));
314 sizer_panelcombo2
->SetMinSize(wxSize(150, -1));
316 //not using wxWrapSizer(wxHORIZONTAL) as it reports an incorrect min height
317 wxSizer
* sizer_panelsizer
= new wxBoxSizer(wxVERTICAL
);
318 sizer_panelsizer
->AddStretchSpacer(1);
319 sizer_panelsizer
->Add(sizer_panelcombo
, 0, wxALL
|wxEXPAND
, 2);
320 sizer_panelsizer
->Add(sizer_panelcombo2
, 0, wxALL
|wxEXPAND
, 2);
321 sizer_panelsizer
->AddStretchSpacer(1);
322 sizer_panel
->SetSizer(sizer_panelsizer
);
324 wxFont
label_font(8, wxFONTFAMILY_DEFAULT
, wxFONTSTYLE_NORMAL
, wxFONTWEIGHT_LIGHT
);
325 m_bitmap_creation_dc
.SetFont(label_font
);
327 wxRibbonPage
* scheme
= new wxRibbonPage(m_ribbon
, wxID_ANY
, wxT("Appearance"), eye_xpm
);
328 m_ribbon
->GetArtProvider()->GetColourScheme(&m_default_primary
,
329 &m_default_secondary
, &m_default_tertiary
);
330 wxRibbonPanel
*provider_panel
= new wxRibbonPanel(scheme
, wxID_ANY
,
331 wxT("Art"), wxNullBitmap
, wxDefaultPosition
, wxDefaultSize
, wxRIBBON_PANEL_NO_AUTO_MINIMISE
);
332 wxRibbonButtonBar
*provider_bar
= new wxRibbonButtonBar(provider_panel
, wxID_ANY
);
333 provider_bar
->AddButton(ID_DEFAULT_PROVIDER
, wxT("Default Provider"),
334 wxArtProvider::GetBitmap(wxART_QUESTION
, wxART_OTHER
, wxSize(32, 32)));
335 provider_bar
->AddButton(ID_AUI_PROVIDER
, wxT("AUI Provider"), aui_style_xpm
);
336 provider_bar
->AddButton(ID_MSW_PROVIDER
, wxT("MSW Provider"), msw_style_xpm
);
337 wxRibbonPanel
*primary_panel
= new wxRibbonPanel(scheme
, wxID_ANY
,
338 wxT("Primary Colour"), colours_xpm
);
339 m_primary_gallery
= PopulateColoursPanel(primary_panel
,
340 m_default_primary
, ID_PRIMARY_COLOUR
);
341 wxRibbonPanel
*secondary_panel
= new wxRibbonPanel(scheme
, wxID_ANY
,
342 wxT("Secondary Colour"), colours_xpm
);
343 m_secondary_gallery
= PopulateColoursPanel(secondary_panel
,
344 m_default_secondary
, ID_SECONDARY_COLOUR
);
347 wxRibbonPage
* page
= new wxRibbonPage(m_ribbon
, wxID_ANY
, wxT("UI Updated"), ribbon_xpm
);
348 wxRibbonPanel
*panel
= new wxRibbonPanel(page
, wxID_ANY
, wxT("Enable/Disable"), ribbon_xpm
);
349 wxRibbonButtonBar
*bar
= new wxRibbonButtonBar(panel
, wxID_ANY
);
350 bar
->AddButton(ID_DISABLED
, wxT("Disabled"), ribbon_xpm
);
351 bar
->AddButton(ID_ENABLE
, wxT("Enable"), ribbon_xpm
);
352 bar
->AddButton(ID_DISABLE
, wxT("Disable"), ribbon_xpm
);
353 bar
->AddButton(ID_UI_ENABLE_UPDATED
, wxT("Enable UI updated"), ribbon_xpm
);
354 bar
->EnableButton(ID_DISABLED
, false);
357 panel
= new wxRibbonPanel(page
, wxID_ANY
, wxT("Toggle"), ribbon_xpm
);
358 bar
= new wxRibbonButtonBar(panel
, wxID_ANY
);
359 bar
->AddButton(ID_CHECK
, wxT("Toggle"), ribbon_xpm
);
360 bar
->AddToggleButton(ID_UI_CHECK_UPDATED
, wxT("Toggled UI updated"), ribbon_xpm
);
363 panel
= new wxRibbonPanel(page
, wxID_ANY
, wxT("Change text"), ribbon_xpm
);
364 bar
= new wxRibbonButtonBar(panel
, wxID_ANY
);
365 bar
->AddButton(ID_CHANGE_TEXT1
, wxT("One"), ribbon_xpm
);
366 bar
->AddButton(ID_CHANGE_TEXT2
, wxT("Two"), ribbon_xpm
);
367 bar
->AddButton(ID_UI_CHANGE_TEXT_UPDATED
, wxT("Zero"), ribbon_xpm
);
369 new wxRibbonPage(m_ribbon
, wxID_ANY
, wxT("Empty Page"), empty_xpm
);
370 new wxRibbonPage(m_ribbon
, wxID_ANY
, wxT("Another Page"), empty_xpm
);
374 m_logwindow
= new wxTextCtrl(this, wxID_ANY
, wxEmptyString
,
375 wxDefaultPosition
, wxDefaultSize
, wxTE_MULTILINE
| wxTE_READONLY
|
376 wxTE_LEFT
| wxTE_BESTWRAP
| wxBORDER_NONE
);
378 m_togglePanels
= new wxToggleButton(this, ID_TOGGLE_PANELS
, "&Toggle panels");
379 m_togglePanels
->SetValue(true);
381 wxSizer
*s
= new wxBoxSizer(wxVERTICAL
);
383 s
->Add(m_ribbon
, 0, wxEXPAND
);
384 s
->Add(m_logwindow
, 1, wxEXPAND
);
385 s
->Add(m_togglePanels
, wxSizerFlags().Border());
390 void MyFrame::SetBarStyle(long style
)
393 m_ribbon
->SetWindowStyleFlag(style
);
394 wxBoxSizer
*pTopSize
= reinterpret_cast<wxBoxSizer
*>(GetSizer());
395 wxRibbonToolBar
*pToolbar
= wxDynamicCast(FindWindow(ID_MAIN_TOOLBAR
), wxRibbonToolBar
);
396 if(style
& wxRIBBON_BAR_FLOW_VERTICAL
)
398 m_ribbon
->SetTabCtrlMargins(10, 10);
399 pTopSize
->SetOrientation(wxHORIZONTAL
);
401 pToolbar
->SetRows(3, 5);
405 m_ribbon
->SetTabCtrlMargins(50, 20);
406 pTopSize
->SetOrientation(wxVERTICAL
);
408 pToolbar
->SetRows(2, 3);
419 class ColourClientData
: public wxClientData
422 ColourClientData(const wxString
& name
, const wxColour
& colour
)
423 : m_name(name
), m_colour(colour
) {}
425 const wxString
& GetName() const {return m_name
;}
426 const wxColour
& GetColour() const {return m_colour
;}
433 wxRibbonGallery
* MyFrame::PopulateColoursPanel(wxWindow
* panel
,
434 wxColour def
, int gallery_id
)
436 wxRibbonGallery
*gallery
= wxDynamicCast(panel
->FindWindow(gallery_id
), wxRibbonGallery
);
440 gallery
= new wxRibbonGallery(panel
, gallery_id
);
441 wxMemoryDC
& dc
= m_bitmap_creation_dc
;
442 wxRibbonGalleryItem
*def_item
=
443 AddColourToGallery(gallery
, wxT("Default"), dc
, &def
);
444 gallery
->SetSelection(def_item
);
445 AddColourToGallery(gallery
, wxT("BLUE"), dc
);
446 AddColourToGallery(gallery
, wxT("BLUE VIOLET"), dc
);
447 AddColourToGallery(gallery
, wxT("BROWN"), dc
);
448 AddColourToGallery(gallery
, wxT("CADET BLUE"), dc
);
449 AddColourToGallery(gallery
, wxT("CORAL"), dc
);
450 AddColourToGallery(gallery
, wxT("CYAN"), dc
);
451 AddColourToGallery(gallery
, wxT("DARK GREEN"), dc
);
452 AddColourToGallery(gallery
, wxT("DARK ORCHID"), dc
);
453 AddColourToGallery(gallery
, wxT("FIREBRICK"), dc
);
454 AddColourToGallery(gallery
, wxT("GOLD"), dc
);
455 AddColourToGallery(gallery
, wxT("GOLDENROD"), dc
);
456 AddColourToGallery(gallery
, wxT("GREEN"), dc
);
457 AddColourToGallery(gallery
, wxT("INDIAN RED"), dc
);
458 AddColourToGallery(gallery
, wxT("KHAKI"), dc
);
459 AddColourToGallery(gallery
, wxT("LIGHT BLUE"), dc
);
460 AddColourToGallery(gallery
, wxT("LIME GREEN"), dc
);
461 AddColourToGallery(gallery
, wxT("MAGENTA"), dc
);
462 AddColourToGallery(gallery
, wxT("MAROON"), dc
);
463 AddColourToGallery(gallery
, wxT("NAVY"), dc
);
464 AddColourToGallery(gallery
, wxT("ORANGE"), dc
);
465 AddColourToGallery(gallery
, wxT("ORCHID"), dc
);
466 AddColourToGallery(gallery
, wxT("PINK"), dc
);
467 AddColourToGallery(gallery
, wxT("PLUM"), dc
);
468 AddColourToGallery(gallery
, wxT("PURPLE"), dc
);
469 AddColourToGallery(gallery
, wxT("RED"), dc
);
470 AddColourToGallery(gallery
, wxT("SALMON"), dc
);
471 AddColourToGallery(gallery
, wxT("SEA GREEN"), dc
);
472 AddColourToGallery(gallery
, wxT("SIENNA"), dc
);
473 AddColourToGallery(gallery
, wxT("SKY BLUE"), dc
);
474 AddColourToGallery(gallery
, wxT("TAN"), dc
);
475 AddColourToGallery(gallery
, wxT("THISTLE"), dc
);
476 AddColourToGallery(gallery
, wxT("TURQUOISE"), dc
);
477 AddColourToGallery(gallery
, wxT("VIOLET"), dc
);
478 AddColourToGallery(gallery
, wxT("VIOLET RED"), dc
);
479 AddColourToGallery(gallery
, wxT("WHEAT"), dc
);
480 AddColourToGallery(gallery
, wxT("WHITE"), dc
);
481 AddColourToGallery(gallery
, wxT("YELLOW"), dc
);
486 wxColour
MyFrame::GetGalleryColour(wxRibbonGallery
*gallery
,
487 wxRibbonGalleryItem
* item
, wxString
* name
)
489 ColourClientData
*data
= (ColourClientData
*)gallery
->GetItemClientObject(item
);
491 *name
= data
->GetName();
492 return data
->GetColour();
495 void MyFrame::OnHoveredColourChange(wxRibbonGalleryEvent
& evt
)
497 // Set the background of the gallery to the hovered colour, or back to the
498 // default if there is no longer a hovered item.
500 wxRibbonGallery
*gallery
= evt
.GetGallery();
501 wxRibbonArtProvider
*provider
= gallery
->GetArtProvider();
503 if(evt
.GetGalleryItem() != NULL
)
505 if(provider
== m_ribbon
->GetArtProvider())
507 provider
= provider
->Clone();
508 gallery
->SetArtProvider(provider
);
510 provider
->SetColour(wxRIBBON_ART_GALLERY_HOVER_BACKGROUND_COLOUR
,
511 GetGalleryColour(evt
.GetGallery(), evt
.GetGalleryItem(), NULL
));
515 if(provider
!= m_ribbon
->GetArtProvider())
517 gallery
->SetArtProvider(m_ribbon
->GetArtProvider());
523 void MyFrame::OnPrimaryColourSelect(wxRibbonGalleryEvent
& evt
)
526 wxColour colour
= GetGalleryColour(evt
.GetGallery(), evt
.GetGalleryItem(), &name
);
527 AddText(wxT("Colour \"") + name
+ wxT("\" selected as primary."));
528 wxColour secondary
, tertiary
;
529 m_ribbon
->GetArtProvider()->GetColourScheme(NULL
, &secondary
, &tertiary
);
530 m_ribbon
->GetArtProvider()->SetColourScheme(colour
, secondary
, tertiary
);
531 ResetGalleryArtProviders();
535 void MyFrame::OnSecondaryColourSelect(wxRibbonGalleryEvent
& evt
)
538 wxColour colour
= GetGalleryColour(evt
.GetGallery(), evt
.GetGalleryItem(), &name
);
539 AddText(wxT("Colour \"") + name
+ wxT("\" selected as secondary."));
540 wxColour primary
, tertiary
;
541 m_ribbon
->GetArtProvider()->GetColourScheme(&primary
, NULL
, &tertiary
);
542 m_ribbon
->GetArtProvider()->SetColourScheme(primary
, colour
, tertiary
);
543 ResetGalleryArtProviders();
547 void MyFrame::ResetGalleryArtProviders()
549 if(m_primary_gallery
->GetArtProvider() != m_ribbon
->GetArtProvider())
551 delete m_primary_gallery
->GetArtProvider();
552 m_primary_gallery
->SetArtProvider(m_ribbon
->GetArtProvider());
554 if(m_secondary_gallery
->GetArtProvider() != m_ribbon
->GetArtProvider())
556 delete m_secondary_gallery
->GetArtProvider();
557 m_secondary_gallery
->SetArtProvider(m_ribbon
->GetArtProvider());
561 void MyFrame::OnChangeText1(wxRibbonButtonBarEvent
& WXUNUSED(evt
))
563 m_new_text
= wxT("One");
566 void MyFrame::OnChangeText2(wxRibbonButtonBarEvent
& WXUNUSED(evt
))
568 m_new_text
= wxT("Two");
571 void MyFrame::OnEnable(wxRibbonButtonBarEvent
& WXUNUSED(evt
))
576 void MyFrame::OnDisable(wxRibbonButtonBarEvent
& WXUNUSED(evt
))
581 void MyFrame::OnCheck(wxRibbonButtonBarEvent
& WXUNUSED(evt
))
583 m_bChecked
= !m_bChecked
;
586 void MyFrame::OnEnableUpdateUI(wxUpdateUIEvent
& evt
)
588 evt
.Enable(m_bEnabled
);
591 void MyFrame::OnCheckUpdateUI(wxUpdateUIEvent
& evt
)
593 evt
.Check(m_bChecked
);
596 void MyFrame::OnChangeTextUpdateUI(wxUpdateUIEvent
& evt
)
598 if ( !m_new_text
.IsEmpty() )
600 evt
.SetText(m_new_text
);
601 m_new_text
= wxT("");
605 void MyFrame::OnSelectionExpandHButton(wxRibbonButtonBarEvent
& WXUNUSED(evt
))
607 AddText(wxT("Expand selection horizontally button clicked."));
610 void MyFrame::OnSelectionExpandVButton(wxRibbonButtonBarEvent
& WXUNUSED(evt
))
612 AddText(wxT("Expand selection vertically button clicked."));
615 void MyFrame::OnSelectionContractButton(wxRibbonButtonBarEvent
& WXUNUSED(evt
))
617 AddText(wxT("Contract selection button clicked."));
620 void MyFrame::OnCircleButton(wxRibbonButtonBarEvent
& WXUNUSED(evt
))
622 AddText(wxT("Circle button clicked."));
625 void MyFrame::OnCrossButton(wxRibbonButtonBarEvent
& WXUNUSED(evt
))
627 AddText(wxT("Cross button clicked."));
630 void MyFrame::OnTriangleButton(wxRibbonButtonBarEvent
& WXUNUSED(evt
))
632 AddText(wxT("Triangle button clicked."));
635 void MyFrame::OnTriangleDropdown(wxRibbonButtonBarEvent
& evt
)
638 menu
.Append(wxID_ANY
, wxT("Equilateral"));
639 menu
.Append(wxID_ANY
, wxT("Isosceles"));
640 menu
.Append(wxID_ANY
, wxT("Scalene"));
642 evt
.PopupMenu(&menu
);
645 void MyFrame::OnSquareButton(wxRibbonButtonBarEvent
& WXUNUSED(evt
))
647 AddText(wxT("Square button clicked."));
650 void MyFrame::OnPolygonDropdown(wxRibbonButtonBarEvent
& evt
)
653 menu
.Append(wxID_ANY
, wxT("Pentagon (5 sided)"));
654 menu
.Append(wxID_ANY
, wxT("Hexagon (6 sided)"));
655 menu
.Append(wxID_ANY
, wxT("Heptagon (7 sided)"));
656 menu
.Append(wxID_ANY
, wxT("Octogon (8 sided)"));
657 menu
.Append(wxID_ANY
, wxT("Nonagon (9 sided)"));
658 menu
.Append(wxID_ANY
, wxT("Decagon (10 sided)"));
660 evt
.PopupMenu(&menu
);
663 void MyFrame::OnNew(wxRibbonToolBarEvent
& WXUNUSED(evt
))
665 AddText(wxT("New button clicked."));
668 void MyFrame::OnNewDropdown(wxRibbonToolBarEvent
& evt
)
671 menu
.Append(wxID_ANY
, wxT("New Document"));
672 menu
.Append(wxID_ANY
, wxT("New Template"));
673 menu
.Append(wxID_ANY
, wxT("New Mail"));
675 evt
.PopupMenu(&menu
);
678 void MyFrame::OnPrint(wxRibbonToolBarEvent
& WXUNUSED(evt
))
680 AddText(wxT("Print button clicked."));
683 void MyFrame::OnPrintDropdown(wxRibbonToolBarEvent
& evt
)
686 menu
.Append(wxID_ANY
, wxT("Print"));
687 menu
.Append(wxID_ANY
, wxT("Preview"));
688 menu
.Append(wxID_ANY
, wxT("Options"));
690 evt
.PopupMenu(&menu
);
693 void MyFrame::OnRedoDropdown(wxRibbonToolBarEvent
& evt
)
696 menu
.Append(wxID_ANY
, wxT("Redo E"));
697 menu
.Append(wxID_ANY
, wxT("Redo F"));
698 menu
.Append(wxID_ANY
, wxT("Redo G"));
700 evt
.PopupMenu(&menu
);
703 void MyFrame::OnUndoDropdown(wxRibbonToolBarEvent
& evt
)
706 menu
.Append(wxID_ANY
, wxT("Undo C"));
707 menu
.Append(wxID_ANY
, wxT("Undo B"));
708 menu
.Append(wxID_ANY
, wxT("Undo A"));
710 evt
.PopupMenu(&menu
);
713 void MyFrame::OnPositionTopLabels(wxCommandEvent
& WXUNUSED(evt
))
715 SetBarStyle(wxRIBBON_BAR_DEFAULT_STYLE
);
718 void MyFrame::OnPositionTopIcons(wxCommandEvent
& WXUNUSED(evt
))
720 SetBarStyle((wxRIBBON_BAR_DEFAULT_STYLE
&~wxRIBBON_BAR_SHOW_PAGE_LABELS
)
721 | wxRIBBON_BAR_SHOW_PAGE_ICONS
);
724 void MyFrame::OnPositionTopBoth(wxCommandEvent
& WXUNUSED(evt
))
726 SetBarStyle(wxRIBBON_BAR_DEFAULT_STYLE
| wxRIBBON_BAR_SHOW_PAGE_ICONS
);
729 void MyFrame::OnPositionLeftLabels(wxCommandEvent
& WXUNUSED(evt
))
731 SetBarStyle(wxRIBBON_BAR_DEFAULT_STYLE
| wxRIBBON_BAR_FLOW_VERTICAL
);
734 void MyFrame::OnPositionLeftIcons(wxCommandEvent
& WXUNUSED(evt
))
736 SetBarStyle((wxRIBBON_BAR_DEFAULT_STYLE
&~wxRIBBON_BAR_SHOW_PAGE_LABELS
) |
737 wxRIBBON_BAR_SHOW_PAGE_ICONS
| wxRIBBON_BAR_FLOW_VERTICAL
);
740 void MyFrame::OnPositionLeftBoth(wxCommandEvent
& WXUNUSED(evt
))
742 SetBarStyle(wxRIBBON_BAR_DEFAULT_STYLE
| wxRIBBON_BAR_SHOW_PAGE_ICONS
|
743 wxRIBBON_BAR_FLOW_VERTICAL
);
746 void MyFrame::OnPositionTop(wxRibbonToolBarEvent
& evt
)
748 OnPositionTopLabels(evt
);
751 void MyFrame::OnPositionTopDropdown(wxRibbonToolBarEvent
& evt
)
754 menu
.Append(ID_POSITION_TOP
, wxT("Top with Labels"));
755 menu
.Append(ID_POSITION_TOP_ICONS
, wxT("Top with Icons"));
756 menu
.Append(ID_POSITION_TOP_BOTH
, wxT("Top with Both"));
757 evt
.PopupMenu(&menu
);
760 void MyFrame::OnPositionLeft(wxRibbonToolBarEvent
& evt
)
762 OnPositionLeftIcons(evt
);
765 void MyFrame::OnPositionLeftDropdown(wxRibbonToolBarEvent
& evt
)
768 menu
.Append(ID_POSITION_LEFT
, wxT("Left with Icons"));
769 menu
.Append(ID_POSITION_LEFT_LABELS
, wxT("Left with Labels"));
770 menu
.Append(ID_POSITION_LEFT_BOTH
, wxT("Left with Both"));
771 evt
.PopupMenu(&menu
);
774 void MyFrame::OnTogglePanels(wxCommandEvent
& WXUNUSED(evt
))
776 m_ribbon
->ShowPanels(m_togglePanels
->GetValue());
779 void MyFrame::AddText(wxString msg
)
781 m_logwindow
->AppendText(msg
);
782 m_logwindow
->AppendText(wxT("\n"));
783 m_ribbon
->DismissExpandedPanel();
786 wxRibbonGalleryItem
* MyFrame::AddColourToGallery(wxRibbonGallery
*gallery
,
787 wxString colour
, wxMemoryDC
& dc
,
790 wxRibbonGalleryItem
* item
= NULL
;
792 if (colour
!= wxT("Default"))
793 c
= wxColour(colour
);
798 const int iWidth
= 64;
799 const int iHeight
= 40;
801 wxBitmap
bitmap(iWidth
, iHeight
);
802 dc
.SelectObject(bitmap
);
804 dc
.SetPen(*wxBLACK_PEN
);
806 dc
.DrawRectangle(0, 0, iWidth
, iHeight
);
808 colour
= colour
.Mid(0, 1) + colour
.Mid(1).Lower();
809 wxSize size
= dc
.GetTextExtent(colour
);
810 wxColour foreground
= wxColour(~c
.Red(), ~c
.Green(), ~c
.Blue());
811 if(abs(foreground
.Red() - c
.Red()) + abs(foreground
.Blue() - c
.Blue())
812 + abs(foreground
.Green() - c
.Green()) < 64)
814 // Foreground too similar to background - use a different
815 // strategy to find a contrasting colour
816 foreground
= wxColour((c
.Red() + 64) % 256, 255 - c
.Green(),
817 (c
.Blue() + 192) % 256);
819 dc
.SetTextForeground(foreground
);
820 dc
.DrawText(colour
, (iWidth
- size
.GetWidth() + 1) / 2,
821 (iHeight
- size
.GetHeight()) / 2);
822 dc
.SelectObjectAsSource(wxNullBitmap
);
824 item
= gallery
->Append(bitmap
, wxID_ANY
);
825 gallery
->SetItemClientObject(item
, new ColourClientData(colour
, c
));
830 void MyFrame::OnColourGalleryButton(wxCommandEvent
& evt
)
832 wxRibbonGallery
*gallery
= wxDynamicCast(evt
.GetEventObject(), wxRibbonGallery
);
836 m_ribbon
->DismissExpandedPanel();
837 if(gallery
->GetSelection())
838 m_colour_data
.SetColour(GetGalleryColour(gallery
, gallery
->GetSelection(), NULL
));
839 wxColourDialog
dlg(this, &m_colour_data
);
840 if(dlg
.ShowModal() == wxID_OK
)
842 m_colour_data
= dlg
.GetColourData();
843 wxColour clr
= m_colour_data
.GetColour();
845 // Try to find colour in gallery
846 wxRibbonGalleryItem
*item
= NULL
;
847 for(unsigned int i
= 0; i
< gallery
->GetCount(); ++i
)
849 item
= gallery
->GetItem(i
);
850 if(GetGalleryColour(gallery
, item
, NULL
) == clr
)
856 // Colour not in gallery - add it
859 item
= AddColourToGallery(gallery
,
860 clr
.GetAsString(wxC2S_HTML_SYNTAX
), m_bitmap_creation_dc
,
866 gallery
->EnsureVisible(item
);
867 gallery
->SetSelection(item
);
869 // Send an event to respond to the selection change
870 wxRibbonGalleryEvent
dummy(wxEVT_COMMAND_RIBBONGALLERY_SELECTED
, gallery
->GetId());
871 dummy
.SetEventObject(gallery
);
872 dummy
.SetGallery(gallery
);
873 dummy
.SetGalleryItem(item
);
874 ProcessWindowEvent(dummy
);
878 void MyFrame::OnDefaultProvider(wxRibbonButtonBarEvent
& WXUNUSED(evt
))
880 m_ribbon
->DismissExpandedPanel();
881 SetArtProvider(new wxRibbonDefaultArtProvider
);
884 void MyFrame::OnAUIProvider(wxRibbonButtonBarEvent
& WXUNUSED(evt
))
886 m_ribbon
->DismissExpandedPanel();
887 SetArtProvider(new wxRibbonAUIArtProvider
);
890 void MyFrame::OnMSWProvider(wxRibbonButtonBarEvent
& WXUNUSED(evt
))
892 m_ribbon
->DismissExpandedPanel();
893 SetArtProvider(new wxRibbonMSWArtProvider
);
896 void MyFrame::SetArtProvider(wxRibbonArtProvider
*prov
)
899 m_ribbon
->SetArtProvider(prov
);
901 prov
->GetColourScheme(&m_default_primary
, &m_default_secondary
,
902 &m_default_tertiary
);
903 PopulateColoursPanel(m_primary_gallery
->GetParent(), m_default_primary
,
905 PopulateColoursPanel(m_secondary_gallery
->GetParent(), m_default_secondary
,
906 ID_SECONDARY_COLOUR
);
910 GetSizer()->Layout();