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/wrapsizer.h"
35 class MyApp
: public wxApp
46 class MyFrame
: public wxFrame
54 ID_CIRCLE
= wxID_HIGHEST
+ 1,
59 ID_SELECTION_EXPAND_H
,
60 ID_SELECTION_EXPAND_V
,
61 ID_SELECTION_CONTRACT
,
69 ID_POSITION_TOP_ICONS
,
72 ID_POSITION_LEFT_LABELS
,
73 ID_POSITION_LEFT_BOTH
,
76 void OnCircleButton(wxRibbonButtonBarEvent
& evt
);
77 void OnCrossButton(wxRibbonButtonBarEvent
& evt
);
78 void OnTriangleButton(wxRibbonButtonBarEvent
& evt
);
79 void OnTriangleDropdown(wxRibbonButtonBarEvent
& evt
);
80 void OnSquareButton(wxRibbonButtonBarEvent
& evt
);
81 void OnPolygonDropdown(wxRibbonButtonBarEvent
& evt
);
82 void OnSelectionExpandVButton(wxRibbonButtonBarEvent
& evt
);
83 void OnSelectionExpandHButton(wxRibbonButtonBarEvent
& evt
);
84 void OnSelectionContractButton(wxRibbonButtonBarEvent
& evt
);
85 void OnHoveredColourChange(wxRibbonGalleryEvent
& evt
);
86 void OnPrimaryColourSelect(wxRibbonGalleryEvent
& evt
);
87 void OnSecondaryColourSelect(wxRibbonGalleryEvent
& evt
);
88 void OnColourGalleryButton(wxCommandEvent
& evt
);
89 void OnDefaultProvider(wxRibbonButtonBarEvent
& evt
);
90 void OnAUIProvider(wxRibbonButtonBarEvent
& evt
);
91 void OnMSWProvider(wxRibbonButtonBarEvent
& evt
);
92 void OnNew(wxRibbonToolBarEvent
& evt
);
93 void OnNewDropdown(wxRibbonToolBarEvent
& evt
);
94 void OnPrint(wxRibbonToolBarEvent
& evt
);
95 void OnPrintDropdown(wxRibbonToolBarEvent
& evt
);
96 void OnRedoDropdown(wxRibbonToolBarEvent
& evt
);
97 void OnUndoDropdown(wxRibbonToolBarEvent
& evt
);
98 void OnPositionTop(wxRibbonToolBarEvent
& evt
);
99 void OnPositionTopLabels(wxCommandEvent
& evt
);
100 void OnPositionTopIcons(wxCommandEvent
& evt
);
101 void OnPositionTopBoth(wxCommandEvent
& evt
);
102 void OnPositionTopDropdown(wxRibbonToolBarEvent
& evt
);
103 void OnPositionLeft(wxRibbonToolBarEvent
& evt
);
104 void OnPositionLeftLabels(wxCommandEvent
& evt
);
105 void OnPositionLeftIcons(wxCommandEvent
& evt
);
106 void OnPositionLeftBoth(wxCommandEvent
& evt
);
107 void OnPositionLeftDropdown(wxRibbonToolBarEvent
& evt
);
110 wxRibbonGallery
* PopulateColoursPanel(wxWindow
* panel
, wxColour def
,
112 void AddText(wxString msg
);
113 wxRibbonGalleryItem
* AddColourToGallery(wxRibbonGallery
*gallery
,
114 wxString name
, wxMemoryDC
& dc
, wxColour
* value
= NULL
);
115 wxColour
GetGalleryColour(wxRibbonGallery
*gallery
,
116 wxRibbonGalleryItem
* item
, wxString
* name
);
117 void ResetGalleryArtProviders();
118 void SetArtProvider(wxRibbonArtProvider
* prov
);
119 void SetBarStyle(long style
);
121 wxRibbonBar
* m_ribbon
;
122 wxRibbonGallery
* m_primary_gallery
;
123 wxRibbonGallery
* m_secondary_gallery
;
124 wxTextCtrl
* m_logwindow
;
125 wxColourData m_colour_data
;
126 wxColour m_default_primary
;
127 wxColour m_default_secondary
;
128 wxColour m_default_tertiary
;
129 wxMemoryDC m_bitmap_creation_dc
;
131 DECLARE_EVENT_TABLE()
134 // -- implementations --
141 wxFrame
* frame
= new MyFrame
;
148 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
149 EVT_RIBBONBUTTONBAR_CLICKED(ID_DEFAULT_PROVIDER
, MyFrame::OnDefaultProvider
)
150 EVT_RIBBONBUTTONBAR_CLICKED(ID_AUI_PROVIDER
, MyFrame::OnAUIProvider
)
151 EVT_RIBBONBUTTONBAR_CLICKED(ID_MSW_PROVIDER
, MyFrame::OnMSWProvider
)
152 EVT_RIBBONBUTTONBAR_CLICKED(ID_SELECTION_EXPAND_H
, MyFrame::OnSelectionExpandHButton
)
153 EVT_RIBBONBUTTONBAR_CLICKED(ID_SELECTION_EXPAND_V
, MyFrame::OnSelectionExpandVButton
)
154 EVT_RIBBONBUTTONBAR_CLICKED(ID_SELECTION_CONTRACT
, MyFrame::OnSelectionContractButton
)
155 EVT_RIBBONBUTTONBAR_CLICKED(ID_CIRCLE
, MyFrame::OnCircleButton
)
156 EVT_RIBBONBUTTONBAR_CLICKED(ID_CROSS
, MyFrame::OnCrossButton
)
157 EVT_RIBBONBUTTONBAR_CLICKED(ID_TRIANGLE
, MyFrame::OnTriangleButton
)
158 EVT_RIBBONBUTTONBAR_CLICKED(ID_SQUARE
, MyFrame::OnSquareButton
)
159 EVT_RIBBONBUTTONBAR_DROPDOWN_CLICKED(ID_TRIANGLE
, MyFrame::OnTriangleDropdown
)
160 EVT_RIBBONBUTTONBAR_DROPDOWN_CLICKED(ID_POLYGON
, MyFrame::OnPolygonDropdown
)
161 EVT_RIBBONGALLERY_HOVER_CHANGED(ID_PRIMARY_COLOUR
, MyFrame::OnHoveredColourChange
)
162 EVT_RIBBONGALLERY_HOVER_CHANGED(ID_SECONDARY_COLOUR
, MyFrame::OnHoveredColourChange
)
163 EVT_RIBBONGALLERY_SELECTED(ID_PRIMARY_COLOUR
, MyFrame::OnPrimaryColourSelect
)
164 EVT_RIBBONGALLERY_SELECTED(ID_SECONDARY_COLOUR
, MyFrame::OnSecondaryColourSelect
)
165 EVT_RIBBONTOOLBAR_CLICKED(wxID_NEW
, MyFrame::OnNew
)
166 EVT_RIBBONTOOLBAR_DROPDOWN_CLICKED(wxID_NEW
, MyFrame::OnNewDropdown
)
167 EVT_RIBBONTOOLBAR_CLICKED(wxID_PRINT
, MyFrame::OnPrint
)
168 EVT_RIBBONTOOLBAR_DROPDOWN_CLICKED(wxID_PRINT
, MyFrame::OnPrintDropdown
)
169 EVT_RIBBONTOOLBAR_DROPDOWN_CLICKED(wxID_REDO
, MyFrame::OnRedoDropdown
)
170 EVT_RIBBONTOOLBAR_DROPDOWN_CLICKED(wxID_UNDO
, MyFrame::OnUndoDropdown
)
171 EVT_RIBBONTOOLBAR_CLICKED(ID_POSITION_LEFT
, MyFrame::OnPositionLeft
)
172 EVT_RIBBONTOOLBAR_DROPDOWN_CLICKED(ID_POSITION_LEFT
, MyFrame::OnPositionLeftDropdown
)
173 EVT_RIBBONTOOLBAR_CLICKED(ID_POSITION_TOP
, MyFrame::OnPositionTop
)
174 EVT_RIBBONTOOLBAR_DROPDOWN_CLICKED(ID_POSITION_TOP
, MyFrame::OnPositionTopDropdown
)
175 EVT_BUTTON(ID_PRIMARY_COLOUR
, MyFrame::OnColourGalleryButton
)
176 EVT_BUTTON(ID_SECONDARY_COLOUR
, MyFrame::OnColourGalleryButton
)
177 EVT_MENU(ID_POSITION_LEFT
, MyFrame::OnPositionLeftIcons
)
178 EVT_MENU(ID_POSITION_LEFT_LABELS
, MyFrame::OnPositionLeftLabels
)
179 EVT_MENU(ID_POSITION_LEFT_BOTH
, MyFrame::OnPositionLeftBoth
)
180 EVT_MENU(ID_POSITION_TOP
, MyFrame::OnPositionTopLabels
)
181 EVT_MENU(ID_POSITION_TOP_ICONS
, MyFrame::OnPositionTopIcons
)
182 EVT_MENU(ID_POSITION_TOP_BOTH
, MyFrame::OnPositionTopBoth
)
185 #include "align_center.xpm"
186 #include "align_left.xpm"
187 #include "align_right.xpm"
188 #include "aui_style.xpm"
189 #include "auto_crop_selection.xpm"
190 #include "auto_crop_selection_small.xpm"
191 #include "circle.xpm"
192 #include "circle_small.xpm"
193 #include "colours.xpm"
196 #include "expand_selection_v.xpm"
197 #include "expand_selection_h.xpm"
199 #include "hexagon.xpm"
200 #include "msw_style.xpm"
201 #include "position_left_small.xpm"
202 #include "position_top_small.xpm"
203 #include "ribbon.xpm"
204 #include "selection_panel.xpm"
205 #include "square.xpm"
206 #include "triangle.xpm"
209 : wxFrame(NULL
, wxID_ANY
, wxT("wxRibbon Sample Application"), wxDefaultPosition
, wxSize(800, 600), wxDEFAULT_FRAME_STYLE
)
211 m_ribbon
= new wxRibbonBar(this, wxID_ANY
);
214 wxRibbonPage
* home
= new wxRibbonPage(m_ribbon
, wxID_ANY
, wxT("Examples"), ribbon_xpm
);
215 wxRibbonPanel
*toolbar_panel
= new wxRibbonPanel(home
, wxID_ANY
, wxT("Toolbar"),
216 wxNullBitmap
, wxDefaultPosition
, wxDefaultSize
,
217 wxRIBBON_PANEL_NO_AUTO_MINIMISE
);
218 wxRibbonToolBar
*toolbar
= new wxRibbonToolBar(toolbar_panel
, ID_MAIN_TOOLBAR
);
219 toolbar
->AddTool(wxID_ANY
, align_left_xpm
);
220 toolbar
->AddTool(wxID_ANY
, align_center_xpm
);
221 toolbar
->AddTool(wxID_ANY
, align_right_xpm
);
222 toolbar
->AddSeparator();
223 toolbar
->AddHybridTool(wxID_NEW
, wxArtProvider::GetBitmap(wxART_NEW
, wxART_OTHER
, wxSize(16, 15)));
224 toolbar
->AddTool(wxID_ANY
, wxArtProvider::GetBitmap(wxART_FILE_OPEN
, wxART_OTHER
, wxSize(16, 15)));
225 toolbar
->AddTool(wxID_ANY
, wxArtProvider::GetBitmap(wxART_FILE_SAVE
, wxART_OTHER
, wxSize(16, 15)));
226 toolbar
->AddTool(wxID_ANY
, wxArtProvider::GetBitmap(wxART_FILE_SAVE_AS
, wxART_OTHER
, wxSize(16, 15)));
227 toolbar
->AddSeparator();
228 toolbar
->AddDropdownTool(wxID_UNDO
, wxArtProvider::GetBitmap(wxART_UNDO
, wxART_OTHER
, wxSize(16, 15)));
229 toolbar
->AddDropdownTool(wxID_REDO
, wxArtProvider::GetBitmap(wxART_REDO
, wxART_OTHER
, wxSize(16, 15)));
230 toolbar
->AddSeparator();
231 toolbar
->AddTool(wxID_ANY
, wxArtProvider::GetBitmap(wxART_REPORT_VIEW
, wxART_OTHER
, wxSize(16, 15)));
232 toolbar
->AddTool(wxID_ANY
, wxArtProvider::GetBitmap(wxART_LIST_VIEW
, wxART_OTHER
, wxSize(16, 15)));
233 toolbar
->AddSeparator();
234 toolbar
->AddHybridTool(ID_POSITION_LEFT
, position_left_xpm
,
235 "Align ribbonbar vertically\non the left\nfor demonstration purposes");
236 toolbar
->AddHybridTool(ID_POSITION_TOP
, position_top_xpm
,
237 "Align the ribbonbar horizontally\nat the top\nfor demonstration purposes");
238 toolbar
->AddSeparator();
239 toolbar
->AddHybridTool(wxID_PRINT
, wxArtProvider::GetBitmap(wxART_PRINT
, wxART_OTHER
, wxSize(16, 15)),
240 "This is the Print button tooltip\ndemonstrating a tooltip");
241 toolbar
->SetRows(2, 3);
243 wxRibbonPanel
*selection_panel
= new wxRibbonPanel(home
, wxID_ANY
, wxT("Selection"), wxBitmap(selection_panel_xpm
));
244 wxRibbonButtonBar
*selection
= new wxRibbonButtonBar(selection_panel
);
245 selection
->AddButton(ID_SELECTION_EXPAND_V
, wxT("Expand Vertically"), wxBitmap(expand_selection_v_xpm
),
246 "This is a tooltip for Expand Vertically\ndemonstrating a tooltip");
247 selection
->AddButton(ID_SELECTION_EXPAND_H
, wxT("Expand Horizontally"), wxBitmap(expand_selection_h_xpm
), wxEmptyString
);
248 selection
->AddButton(ID_SELECTION_CONTRACT
, wxT("Contract"), wxBitmap(auto_crop_selection_xpm
), wxBitmap(auto_crop_selection_small_xpm
));
250 wxRibbonPanel
*shapes_panel
= new wxRibbonPanel(home
, wxID_ANY
, wxT("Shapes"), wxBitmap(circle_small_xpm
));
251 wxRibbonButtonBar
*shapes
= new wxRibbonButtonBar(shapes_panel
);
252 shapes
->AddButton(ID_CIRCLE
, wxT("Circle"), wxBitmap(circle_xpm
), wxBitmap(circle_small_xpm
),
253 wxNullBitmap
, wxNullBitmap
, wxRIBBON_BUTTON_NORMAL
,
254 "This is a tooltip for the circle button\ndemonstrating another tooltip");
255 shapes
->AddButton(ID_CROSS
, wxT("Cross"), wxBitmap(cross_xpm
), wxEmptyString
);
256 shapes
->AddHybridButton(ID_TRIANGLE
, wxT("Triangle"), wxBitmap(triangle_xpm
));
257 shapes
->AddButton(ID_SQUARE
, wxT("Square"), wxBitmap(square_xpm
), wxEmptyString
);
258 shapes
->AddDropdownButton(ID_POLYGON
, wxT("Other Polygon"), wxBitmap(hexagon_xpm
), wxEmptyString
);
260 wxRibbonPanel
*sizer_panel
= new wxRibbonPanel(home
, wxID_ANY
, wxT("Panel with Sizer"),
261 wxNullBitmap
, wxDefaultPosition
, wxDefaultSize
,
262 wxRIBBON_PANEL_DEFAULT_STYLE
);
265 as
.Add("Item 1 using a box sizer now");
266 as
.Add("Item 2 using a box sizer now");
267 wxComboBox
* sizer_panelcombo
= new wxComboBox(sizer_panel
, wxID_ANY
,
269 wxDefaultPosition
, wxDefaultSize
,
272 wxComboBox
* sizer_panelcombo2
= new wxComboBox(sizer_panel
, wxID_ANY
,
274 wxDefaultPosition
, wxDefaultSize
,
277 sizer_panelcombo
->Select(0);
278 sizer_panelcombo2
->Select(1);
279 sizer_panelcombo
->SetMinSize(wxSize(150, -1));
280 sizer_panelcombo2
->SetMinSize(wxSize(150, -1));
282 //not using wxWrapSizer(wxHORIZONTAL) as it reports an incorrect min height
283 wxSizer
* sizer_panelsizer
= new wxBoxSizer(wxVERTICAL
);
284 sizer_panelsizer
->AddStretchSpacer(1);
285 sizer_panelsizer
->Add(sizer_panelcombo
, 0, wxALL
|wxEXPAND
, 2);
286 sizer_panelsizer
->Add(sizer_panelcombo2
, 0, wxALL
|wxEXPAND
, 2);
287 sizer_panelsizer
->AddStretchSpacer(1);
288 sizer_panel
->SetSizer(sizer_panelsizer
);
290 wxFont
label_font(8, wxFONTFAMILY_DEFAULT
, wxFONTSTYLE_NORMAL
, wxFONTWEIGHT_LIGHT
);
291 m_bitmap_creation_dc
.SetFont(label_font
);
293 wxRibbonPage
* scheme
= new wxRibbonPage(m_ribbon
, wxID_ANY
, wxT("Appearance"), eye_xpm
);
294 m_ribbon
->GetArtProvider()->GetColourScheme(&m_default_primary
,
295 &m_default_secondary
, &m_default_tertiary
);
296 wxRibbonPanel
*provider_panel
= new wxRibbonPanel(scheme
, wxID_ANY
,
297 wxT("Art"), wxNullBitmap
, wxDefaultPosition
, wxDefaultSize
, wxRIBBON_PANEL_NO_AUTO_MINIMISE
);
298 wxRibbonButtonBar
*provider_bar
= new wxRibbonButtonBar(provider_panel
, wxID_ANY
);
299 provider_bar
->AddButton(ID_DEFAULT_PROVIDER
, wxT("Default Provider"),
300 wxArtProvider::GetBitmap(wxART_QUESTION
, wxART_OTHER
, wxSize(32, 32)));
301 provider_bar
->AddButton(ID_AUI_PROVIDER
, wxT("AUI Provider"), aui_style_xpm
);
302 provider_bar
->AddButton(ID_MSW_PROVIDER
, wxT("MSW Provider"), msw_style_xpm
);
303 wxRibbonPanel
*primary_panel
= new wxRibbonPanel(scheme
, wxID_ANY
,
304 wxT("Primary Colour"), colours_xpm
);
305 m_primary_gallery
= PopulateColoursPanel(primary_panel
,
306 m_default_primary
, ID_PRIMARY_COLOUR
);
307 wxRibbonPanel
*secondary_panel
= new wxRibbonPanel(scheme
, wxID_ANY
,
308 wxT("Secondary Colour"), colours_xpm
);
309 m_secondary_gallery
= PopulateColoursPanel(secondary_panel
,
310 m_default_secondary
, ID_SECONDARY_COLOUR
);
312 new wxRibbonPage(m_ribbon
, wxID_ANY
, wxT("Empty Page"), empty_xpm
);
313 new wxRibbonPage(m_ribbon
, wxID_ANY
, wxT("Another Page"), empty_xpm
);
317 m_logwindow
= new wxTextCtrl(this, wxID_ANY
, wxEmptyString
,
318 wxDefaultPosition
, wxDefaultSize
, wxTE_MULTILINE
| wxTE_READONLY
|
319 wxTE_LEFT
| wxTE_BESTWRAP
| wxBORDER_NONE
);
321 wxSizer
*s
= new wxBoxSizer(wxVERTICAL
);
323 s
->Add(m_ribbon
, 0, wxEXPAND
);
324 s
->Add(m_logwindow
, 1, wxEXPAND
);
329 void MyFrame::SetBarStyle(long style
)
332 m_ribbon
->SetWindowStyleFlag(style
);
333 wxBoxSizer
*pTopSize
= reinterpret_cast<wxBoxSizer
*>(GetSizer());
334 wxRibbonToolBar
*pToolbar
= wxDynamicCast(FindWindow(ID_MAIN_TOOLBAR
), wxRibbonToolBar
);
335 if(style
& wxRIBBON_BAR_FLOW_VERTICAL
)
337 m_ribbon
->SetTabCtrlMargins(10, 10);
338 pTopSize
->SetOrientation(wxHORIZONTAL
);
340 pToolbar
->SetRows(3, 5);
344 m_ribbon
->SetTabCtrlMargins(50, 20);
345 pTopSize
->SetOrientation(wxVERTICAL
);
347 pToolbar
->SetRows(2, 3);
358 class ColourClientData
: public wxClientData
361 ColourClientData(const wxString
& name
, const wxColour
& colour
)
362 : m_name(name
), m_colour(colour
) {}
364 const wxString
& GetName() const {return m_name
;}
365 const wxColour
& GetColour() const {return m_colour
;}
372 wxRibbonGallery
* MyFrame::PopulateColoursPanel(wxWindow
* panel
,
373 wxColour def
, int gallery_id
)
375 wxRibbonGallery
*gallery
= wxDynamicCast(panel
->FindWindow(gallery_id
), wxRibbonGallery
);
379 gallery
= new wxRibbonGallery(panel
, gallery_id
);
380 wxMemoryDC
& dc
= m_bitmap_creation_dc
;
381 wxRibbonGalleryItem
*def_item
=
382 AddColourToGallery(gallery
, wxT("Default"), dc
, &def
);
383 gallery
->SetSelection(def_item
);
384 AddColourToGallery(gallery
, wxT("BLUE"), dc
);
385 AddColourToGallery(gallery
, wxT("BLUE VIOLET"), dc
);
386 AddColourToGallery(gallery
, wxT("BROWN"), dc
);
387 AddColourToGallery(gallery
, wxT("CADET BLUE"), dc
);
388 AddColourToGallery(gallery
, wxT("CORAL"), dc
);
389 AddColourToGallery(gallery
, wxT("CYAN"), dc
);
390 AddColourToGallery(gallery
, wxT("DARK GREEN"), dc
);
391 AddColourToGallery(gallery
, wxT("DARK ORCHID"), dc
);
392 AddColourToGallery(gallery
, wxT("FIREBRICK"), dc
);
393 AddColourToGallery(gallery
, wxT("GOLD"), dc
);
394 AddColourToGallery(gallery
, wxT("GOLDENROD"), dc
);
395 AddColourToGallery(gallery
, wxT("GREEN"), dc
);
396 AddColourToGallery(gallery
, wxT("INDIAN RED"), dc
);
397 AddColourToGallery(gallery
, wxT("KHAKI"), dc
);
398 AddColourToGallery(gallery
, wxT("LIGHT BLUE"), dc
);
399 AddColourToGallery(gallery
, wxT("LIME GREEN"), dc
);
400 AddColourToGallery(gallery
, wxT("MAGENTA"), dc
);
401 AddColourToGallery(gallery
, wxT("MAROON"), dc
);
402 AddColourToGallery(gallery
, wxT("NAVY"), dc
);
403 AddColourToGallery(gallery
, wxT("ORANGE"), dc
);
404 AddColourToGallery(gallery
, wxT("ORCHID"), dc
);
405 AddColourToGallery(gallery
, wxT("PINK"), dc
);
406 AddColourToGallery(gallery
, wxT("PLUM"), dc
);
407 AddColourToGallery(gallery
, wxT("PURPLE"), dc
);
408 AddColourToGallery(gallery
, wxT("RED"), dc
);
409 AddColourToGallery(gallery
, wxT("SALMON"), dc
);
410 AddColourToGallery(gallery
, wxT("SEA GREEN"), dc
);
411 AddColourToGallery(gallery
, wxT("SIENNA"), dc
);
412 AddColourToGallery(gallery
, wxT("SKY BLUE"), dc
);
413 AddColourToGallery(gallery
, wxT("TAN"), dc
);
414 AddColourToGallery(gallery
, wxT("THISTLE"), dc
);
415 AddColourToGallery(gallery
, wxT("TURQUOISE"), dc
);
416 AddColourToGallery(gallery
, wxT("VIOLET"), dc
);
417 AddColourToGallery(gallery
, wxT("VIOLET RED"), dc
);
418 AddColourToGallery(gallery
, wxT("WHEAT"), dc
);
419 AddColourToGallery(gallery
, wxT("WHITE"), dc
);
420 AddColourToGallery(gallery
, wxT("YELLOW"), dc
);
425 wxColour
MyFrame::GetGalleryColour(wxRibbonGallery
*gallery
,
426 wxRibbonGalleryItem
* item
, wxString
* name
)
428 ColourClientData
*data
= (ColourClientData
*)gallery
->GetItemClientObject(item
);
430 *name
= data
->GetName();
431 return data
->GetColour();
434 void MyFrame::OnHoveredColourChange(wxRibbonGalleryEvent
& evt
)
436 // Set the background of the gallery to the hovered colour, or back to the
437 // default if there is no longer a hovered item.
439 wxRibbonGallery
*gallery
= evt
.GetGallery();
440 wxRibbonArtProvider
*provider
= gallery
->GetArtProvider();
442 if(evt
.GetGalleryItem() != NULL
)
444 if(provider
== m_ribbon
->GetArtProvider())
446 provider
= provider
->Clone();
447 gallery
->SetArtProvider(provider
);
449 provider
->SetColour(wxRIBBON_ART_GALLERY_HOVER_BACKGROUND_COLOUR
,
450 GetGalleryColour(evt
.GetGallery(), evt
.GetGalleryItem(), NULL
));
454 if(provider
!= m_ribbon
->GetArtProvider())
456 gallery
->SetArtProvider(m_ribbon
->GetArtProvider());
462 void MyFrame::OnPrimaryColourSelect(wxRibbonGalleryEvent
& evt
)
465 wxColour colour
= GetGalleryColour(evt
.GetGallery(), evt
.GetGalleryItem(), &name
);
466 AddText(wxT("Colour \"") + name
+ wxT("\" selected as primary."));
467 wxColour secondary
, tertiary
;
468 m_ribbon
->GetArtProvider()->GetColourScheme(NULL
, &secondary
, &tertiary
);
469 m_ribbon
->GetArtProvider()->SetColourScheme(colour
, secondary
, tertiary
);
470 ResetGalleryArtProviders();
474 void MyFrame::OnSecondaryColourSelect(wxRibbonGalleryEvent
& evt
)
477 wxColour colour
= GetGalleryColour(evt
.GetGallery(), evt
.GetGalleryItem(), &name
);
478 AddText(wxT("Colour \"") + name
+ wxT("\" selected as secondary."));
479 wxColour primary
, tertiary
;
480 m_ribbon
->GetArtProvider()->GetColourScheme(&primary
, NULL
, &tertiary
);
481 m_ribbon
->GetArtProvider()->SetColourScheme(primary
, colour
, tertiary
);
482 ResetGalleryArtProviders();
486 void MyFrame::ResetGalleryArtProviders()
488 if(m_primary_gallery
->GetArtProvider() != m_ribbon
->GetArtProvider())
490 delete m_primary_gallery
->GetArtProvider();
491 m_primary_gallery
->SetArtProvider(m_ribbon
->GetArtProvider());
493 if(m_secondary_gallery
->GetArtProvider() != m_ribbon
->GetArtProvider())
495 delete m_secondary_gallery
->GetArtProvider();
496 m_secondary_gallery
->SetArtProvider(m_ribbon
->GetArtProvider());
500 void MyFrame::OnSelectionExpandHButton(wxRibbonButtonBarEvent
& WXUNUSED(evt
))
502 AddText(wxT("Expand selection horizontally button clicked."));
505 void MyFrame::OnSelectionExpandVButton(wxRibbonButtonBarEvent
& WXUNUSED(evt
))
507 AddText(wxT("Expand selection vertically button clicked."));
510 void MyFrame::OnSelectionContractButton(wxRibbonButtonBarEvent
& WXUNUSED(evt
))
512 AddText(wxT("Contract selection button clicked."));
515 void MyFrame::OnCircleButton(wxRibbonButtonBarEvent
& WXUNUSED(evt
))
517 AddText(wxT("Circle button clicked."));
520 void MyFrame::OnCrossButton(wxRibbonButtonBarEvent
& WXUNUSED(evt
))
522 AddText(wxT("Cross button clicked."));
525 void MyFrame::OnTriangleButton(wxRibbonButtonBarEvent
& WXUNUSED(evt
))
527 AddText(wxT("Triangle button clicked."));
530 void MyFrame::OnTriangleDropdown(wxRibbonButtonBarEvent
& evt
)
533 menu
.Append(wxID_ANY
, wxT("Equilateral"));
534 menu
.Append(wxID_ANY
, wxT("Isosceles"));
535 menu
.Append(wxID_ANY
, wxT("Scalene"));
537 evt
.PopupMenu(&menu
);
540 void MyFrame::OnSquareButton(wxRibbonButtonBarEvent
& WXUNUSED(evt
))
542 AddText(wxT("Square button clicked."));
545 void MyFrame::OnPolygonDropdown(wxRibbonButtonBarEvent
& evt
)
548 menu
.Append(wxID_ANY
, wxT("Pentagon (5 sided)"));
549 menu
.Append(wxID_ANY
, wxT("Hexagon (6 sided)"));
550 menu
.Append(wxID_ANY
, wxT("Heptagon (7 sided)"));
551 menu
.Append(wxID_ANY
, wxT("Octogon (8 sided)"));
552 menu
.Append(wxID_ANY
, wxT("Nonagon (9 sided)"));
553 menu
.Append(wxID_ANY
, wxT("Decagon (10 sided)"));
555 evt
.PopupMenu(&menu
);
558 void MyFrame::OnNew(wxRibbonToolBarEvent
& WXUNUSED(evt
))
560 AddText(wxT("New button clicked."));
563 void MyFrame::OnNewDropdown(wxRibbonToolBarEvent
& evt
)
566 menu
.Append(wxID_ANY
, wxT("New Document"));
567 menu
.Append(wxID_ANY
, wxT("New Template"));
568 menu
.Append(wxID_ANY
, wxT("New Mail"));
570 evt
.PopupMenu(&menu
);
573 void MyFrame::OnPrint(wxRibbonToolBarEvent
& WXUNUSED(evt
))
575 AddText(wxT("Print button clicked."));
578 void MyFrame::OnPrintDropdown(wxRibbonToolBarEvent
& evt
)
581 menu
.Append(wxID_ANY
, wxT("Print"));
582 menu
.Append(wxID_ANY
, wxT("Preview"));
583 menu
.Append(wxID_ANY
, wxT("Options"));
585 evt
.PopupMenu(&menu
);
588 void MyFrame::OnRedoDropdown(wxRibbonToolBarEvent
& evt
)
591 menu
.Append(wxID_ANY
, wxT("Redo E"));
592 menu
.Append(wxID_ANY
, wxT("Redo F"));
593 menu
.Append(wxID_ANY
, wxT("Redo G"));
595 evt
.PopupMenu(&menu
);
598 void MyFrame::OnUndoDropdown(wxRibbonToolBarEvent
& evt
)
601 menu
.Append(wxID_ANY
, wxT("Undo C"));
602 menu
.Append(wxID_ANY
, wxT("Undo B"));
603 menu
.Append(wxID_ANY
, wxT("Undo A"));
605 evt
.PopupMenu(&menu
);
608 void MyFrame::OnPositionTopLabels(wxCommandEvent
& WXUNUSED(evt
))
610 SetBarStyle(wxRIBBON_BAR_DEFAULT_STYLE
);
613 void MyFrame::OnPositionTopIcons(wxCommandEvent
& WXUNUSED(evt
))
615 SetBarStyle((wxRIBBON_BAR_DEFAULT_STYLE
&~wxRIBBON_BAR_SHOW_PAGE_LABELS
)
616 | wxRIBBON_BAR_SHOW_PAGE_ICONS
);
619 void MyFrame::OnPositionTopBoth(wxCommandEvent
& WXUNUSED(evt
))
621 SetBarStyle(wxRIBBON_BAR_DEFAULT_STYLE
| wxRIBBON_BAR_SHOW_PAGE_ICONS
);
624 void MyFrame::OnPositionLeftLabels(wxCommandEvent
& WXUNUSED(evt
))
626 SetBarStyle(wxRIBBON_BAR_DEFAULT_STYLE
| wxRIBBON_BAR_FLOW_VERTICAL
);
629 void MyFrame::OnPositionLeftIcons(wxCommandEvent
& WXUNUSED(evt
))
631 SetBarStyle((wxRIBBON_BAR_DEFAULT_STYLE
&~wxRIBBON_BAR_SHOW_PAGE_LABELS
) |
632 wxRIBBON_BAR_SHOW_PAGE_ICONS
| wxRIBBON_BAR_FLOW_VERTICAL
);
635 void MyFrame::OnPositionLeftBoth(wxCommandEvent
& WXUNUSED(evt
))
637 SetBarStyle(wxRIBBON_BAR_DEFAULT_STYLE
| wxRIBBON_BAR_SHOW_PAGE_ICONS
|
638 wxRIBBON_BAR_FLOW_VERTICAL
);
641 void MyFrame::OnPositionTop(wxRibbonToolBarEvent
& evt
)
643 OnPositionTopLabels(evt
);
646 void MyFrame::OnPositionTopDropdown(wxRibbonToolBarEvent
& evt
)
649 menu
.Append(ID_POSITION_TOP
, wxT("Top with Labels"));
650 menu
.Append(ID_POSITION_TOP_ICONS
, wxT("Top with Icons"));
651 menu
.Append(ID_POSITION_TOP_BOTH
, wxT("Top with Both"));
652 evt
.PopupMenu(&menu
);
655 void MyFrame::OnPositionLeft(wxRibbonToolBarEvent
& evt
)
657 OnPositionLeftIcons(evt
);
660 void MyFrame::OnPositionLeftDropdown(wxRibbonToolBarEvent
& evt
)
663 menu
.Append(ID_POSITION_LEFT
, wxT("Left with Icons"));
664 menu
.Append(ID_POSITION_LEFT_LABELS
, wxT("Left with Labels"));
665 menu
.Append(ID_POSITION_LEFT_BOTH
, wxT("Left with Both"));
666 evt
.PopupMenu(&menu
);
669 void MyFrame::AddText(wxString msg
)
671 m_logwindow
->AppendText(msg
);
672 m_logwindow
->AppendText(wxT("\n"));
673 m_ribbon
->DismissExpandedPanel();
676 wxRibbonGalleryItem
* MyFrame::AddColourToGallery(wxRibbonGallery
*gallery
,
677 wxString colour
, wxMemoryDC
& dc
,
680 wxRibbonGalleryItem
* item
= NULL
;
682 if (colour
!= wxT("Default"))
683 c
= wxColour(colour
);
688 const int iWidth
= 64;
689 const int iHeight
= 40;
691 wxBitmap
bitmap(iWidth
, iHeight
);
692 dc
.SelectObject(bitmap
);
694 dc
.SetPen(*wxBLACK_PEN
);
696 dc
.DrawRectangle(0, 0, iWidth
, iHeight
);
698 colour
= colour
.Mid(0, 1) + colour
.Mid(1).Lower();
699 wxSize size
= dc
.GetTextExtent(colour
);
700 wxColour foreground
= wxColour(~c
.Red(), ~c
.Green(), ~c
.Blue());
701 if(abs(foreground
.Red() - c
.Red()) + abs(foreground
.Blue() - c
.Blue())
702 + abs(foreground
.Green() - c
.Green()) < 64)
704 // Foreground too similar to background - use a different
705 // strategy to find a contrasting colour
706 foreground
= wxColour((c
.Red() + 64) % 256, 255 - c
.Green(),
707 (c
.Blue() + 192) % 256);
709 dc
.SetTextForeground(foreground
);
710 dc
.DrawText(colour
, (iWidth
- size
.GetWidth() + 1) / 2,
711 (iHeight
- size
.GetHeight()) / 2);
712 dc
.SelectObjectAsSource(wxNullBitmap
);
714 item
= gallery
->Append(bitmap
, wxID_ANY
);
715 gallery
->SetItemClientObject(item
, new ColourClientData(colour
, c
));
720 void MyFrame::OnColourGalleryButton(wxCommandEvent
& evt
)
722 wxRibbonGallery
*gallery
= wxDynamicCast(evt
.GetEventObject(), wxRibbonGallery
);
726 m_ribbon
->DismissExpandedPanel();
727 if(gallery
->GetSelection())
728 m_colour_data
.SetColour(GetGalleryColour(gallery
, gallery
->GetSelection(), NULL
));
729 wxColourDialog
dlg(this, &m_colour_data
);
730 if(dlg
.ShowModal() == wxID_OK
)
732 m_colour_data
= dlg
.GetColourData();
733 wxColour clr
= m_colour_data
.GetColour();
735 // Try to find colour in gallery
736 wxRibbonGalleryItem
*item
= NULL
;
737 for(unsigned int i
= 0; i
< gallery
->GetCount(); ++i
)
739 item
= gallery
->GetItem(i
);
740 if(GetGalleryColour(gallery
, item
, NULL
) == clr
)
746 // Colour not in gallery - add it
749 item
= AddColourToGallery(gallery
,
750 clr
.GetAsString(wxC2S_HTML_SYNTAX
), m_bitmap_creation_dc
,
756 gallery
->EnsureVisible(item
);
757 gallery
->SetSelection(item
);
759 // Send an event to respond to the selection change
760 wxRibbonGalleryEvent
dummy(wxEVT_COMMAND_RIBBONGALLERY_SELECTED
, gallery
->GetId());
761 dummy
.SetEventObject(gallery
);
762 dummy
.SetGallery(gallery
);
763 dummy
.SetGalleryItem(item
);
764 ProcessWindowEvent(dummy
);
768 void MyFrame::OnDefaultProvider(wxRibbonButtonBarEvent
& WXUNUSED(evt
))
770 m_ribbon
->DismissExpandedPanel();
771 SetArtProvider(new wxRibbonDefaultArtProvider
);
774 void MyFrame::OnAUIProvider(wxRibbonButtonBarEvent
& WXUNUSED(evt
))
776 m_ribbon
->DismissExpandedPanel();
777 SetArtProvider(new wxRibbonAUIArtProvider
);
780 void MyFrame::OnMSWProvider(wxRibbonButtonBarEvent
& WXUNUSED(evt
))
782 m_ribbon
->DismissExpandedPanel();
783 SetArtProvider(new wxRibbonMSWArtProvider
);
786 void MyFrame::SetArtProvider(wxRibbonArtProvider
*prov
)
789 m_ribbon
->SetArtProvider(prov
);
791 prov
->GetColourScheme(&m_default_primary
, &m_default_secondary
,
792 &m_default_tertiary
);
793 PopulateColoursPanel(m_primary_gallery
->GetParent(), m_default_primary
,
795 PopulateColoursPanel(m_secondary_gallery
->GetParent(), m_default_secondary
,
796 ID_SECONDARY_COLOUR
);
800 GetSizer()->Layout();