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"
33 class MyApp
: public wxApp
44 class MyFrame
: public wxFrame
52 ID_CIRCLE
= wxID_HIGHEST
+ 1,
57 ID_SELECTION_EXPAND_H
,
58 ID_SELECTION_EXPAND_V
,
59 ID_SELECTION_CONTRACT
,
67 ID_POSITION_TOP_ICONS
,
70 ID_POSITION_LEFT_LABELS
,
71 ID_POSITION_LEFT_BOTH
,
74 void OnCircleButton(wxRibbonButtonBarEvent
& evt
);
75 void OnCrossButton(wxRibbonButtonBarEvent
& evt
);
76 void OnTriangleButton(wxRibbonButtonBarEvent
& evt
);
77 void OnTriangleDropdown(wxRibbonButtonBarEvent
& evt
);
78 void OnSquareButton(wxRibbonButtonBarEvent
& evt
);
79 void OnPolygonDropdown(wxRibbonButtonBarEvent
& evt
);
80 void OnSelectionExpandVButton(wxRibbonButtonBarEvent
& evt
);
81 void OnSelectionExpandHButton(wxRibbonButtonBarEvent
& evt
);
82 void OnSelectionContractButton(wxRibbonButtonBarEvent
& evt
);
83 void OnHoveredColourChange(wxRibbonGalleryEvent
& evt
);
84 void OnPrimaryColourSelect(wxRibbonGalleryEvent
& evt
);
85 void OnSecondaryColourSelect(wxRibbonGalleryEvent
& evt
);
86 void OnColourGalleryButton(wxCommandEvent
& evt
);
87 void OnDefaultProvider(wxRibbonButtonBarEvent
& evt
);
88 void OnAUIProvider(wxRibbonButtonBarEvent
& evt
);
89 void OnMSWProvider(wxRibbonButtonBarEvent
& evt
);
90 void OnNew(wxRibbonToolBarEvent
& evt
);
91 void OnNewDropdown(wxRibbonToolBarEvent
& evt
);
92 void OnPrint(wxRibbonToolBarEvent
& evt
);
93 void OnPrintDropdown(wxRibbonToolBarEvent
& evt
);
94 void OnRedoDropdown(wxRibbonToolBarEvent
& evt
);
95 void OnUndoDropdown(wxRibbonToolBarEvent
& evt
);
96 void OnPositionTop(wxRibbonToolBarEvent
& evt
);
97 void OnPositionTopLabels(wxCommandEvent
& evt
);
98 void OnPositionTopIcons(wxCommandEvent
& evt
);
99 void OnPositionTopBoth(wxCommandEvent
& evt
);
100 void OnPositionTopDropdown(wxRibbonToolBarEvent
& evt
);
101 void OnPositionLeft(wxRibbonToolBarEvent
& evt
);
102 void OnPositionLeftLabels(wxCommandEvent
& evt
);
103 void OnPositionLeftIcons(wxCommandEvent
& evt
);
104 void OnPositionLeftBoth(wxCommandEvent
& evt
);
105 void OnPositionLeftDropdown(wxRibbonToolBarEvent
& evt
);
108 wxRibbonGallery
* PopulateColoursPanel(wxWindow
* panel
, wxColour def
,
110 void AddText(wxString msg
);
111 wxRibbonGalleryItem
* AddColourToGallery(wxRibbonGallery
*gallery
,
112 wxString name
, wxMemoryDC
& dc
, wxColour
* value
= NULL
);
113 wxColour
GetGalleryColour(wxRibbonGallery
*gallery
,
114 wxRibbonGalleryItem
* item
, wxString
* name
);
115 void ResetGalleryArtProviders();
116 void SetArtProvider(wxRibbonArtProvider
* prov
);
117 void SetBarStyle(long style
);
119 wxRibbonBar
* m_ribbon
;
120 wxRibbonGallery
* m_primary_gallery
;
121 wxRibbonGallery
* m_secondary_gallery
;
122 wxTextCtrl
* m_logwindow
;
123 wxColourData m_colour_data
;
124 wxColour m_default_primary
;
125 wxColour m_default_secondary
;
126 wxColour m_default_tertiary
;
127 wxMemoryDC m_bitmap_creation_dc
;
129 DECLARE_EVENT_TABLE()
132 // -- implementations --
139 wxFrame
* frame
= new MyFrame
;
146 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
147 EVT_RIBBONBUTTONBAR_CLICKED(ID_DEFAULT_PROVIDER
, MyFrame::OnDefaultProvider
)
148 EVT_RIBBONBUTTONBAR_CLICKED(ID_AUI_PROVIDER
, MyFrame::OnAUIProvider
)
149 EVT_RIBBONBUTTONBAR_CLICKED(ID_MSW_PROVIDER
, MyFrame::OnMSWProvider
)
150 EVT_RIBBONBUTTONBAR_CLICKED(ID_SELECTION_EXPAND_H
, MyFrame::OnSelectionExpandHButton
)
151 EVT_RIBBONBUTTONBAR_CLICKED(ID_SELECTION_EXPAND_V
, MyFrame::OnSelectionExpandVButton
)
152 EVT_RIBBONBUTTONBAR_CLICKED(ID_SELECTION_CONTRACT
, MyFrame::OnSelectionContractButton
)
153 EVT_RIBBONBUTTONBAR_CLICKED(ID_CIRCLE
, MyFrame::OnCircleButton
)
154 EVT_RIBBONBUTTONBAR_CLICKED(ID_CROSS
, MyFrame::OnCrossButton
)
155 EVT_RIBBONBUTTONBAR_CLICKED(ID_TRIANGLE
, MyFrame::OnTriangleButton
)
156 EVT_RIBBONBUTTONBAR_CLICKED(ID_SQUARE
, MyFrame::OnSquareButton
)
157 EVT_RIBBONBUTTONBAR_DROPDOWN_CLICKED(ID_TRIANGLE
, MyFrame::OnTriangleDropdown
)
158 EVT_RIBBONBUTTONBAR_DROPDOWN_CLICKED(ID_POLYGON
, MyFrame::OnPolygonDropdown
)
159 EVT_RIBBONGALLERY_HOVER_CHANGED(ID_PRIMARY_COLOUR
, MyFrame::OnHoveredColourChange
)
160 EVT_RIBBONGALLERY_HOVER_CHANGED(ID_SECONDARY_COLOUR
, MyFrame::OnHoveredColourChange
)
161 EVT_RIBBONGALLERY_SELECTED(ID_PRIMARY_COLOUR
, MyFrame::OnPrimaryColourSelect
)
162 EVT_RIBBONGALLERY_SELECTED(ID_SECONDARY_COLOUR
, MyFrame::OnSecondaryColourSelect
)
163 EVT_RIBBONTOOLBAR_CLICKED(wxID_NEW
, MyFrame::OnNew
)
164 EVT_RIBBONTOOLBAR_DROPDOWN_CLICKED(wxID_NEW
, MyFrame::OnNewDropdown
)
165 EVT_RIBBONTOOLBAR_CLICKED(wxID_PRINT
, MyFrame::OnPrint
)
166 EVT_RIBBONTOOLBAR_DROPDOWN_CLICKED(wxID_PRINT
, MyFrame::OnPrintDropdown
)
167 EVT_RIBBONTOOLBAR_DROPDOWN_CLICKED(wxID_REDO
, MyFrame::OnRedoDropdown
)
168 EVT_RIBBONTOOLBAR_DROPDOWN_CLICKED(wxID_UNDO
, MyFrame::OnUndoDropdown
)
169 EVT_RIBBONTOOLBAR_CLICKED(ID_POSITION_LEFT
, MyFrame::OnPositionLeft
)
170 EVT_RIBBONTOOLBAR_DROPDOWN_CLICKED(ID_POSITION_LEFT
, MyFrame::OnPositionLeftDropdown
)
171 EVT_RIBBONTOOLBAR_CLICKED(ID_POSITION_TOP
, MyFrame::OnPositionTop
)
172 EVT_RIBBONTOOLBAR_DROPDOWN_CLICKED(ID_POSITION_TOP
, MyFrame::OnPositionTopDropdown
)
173 EVT_BUTTON(ID_PRIMARY_COLOUR
, MyFrame::OnColourGalleryButton
)
174 EVT_BUTTON(ID_SECONDARY_COLOUR
, MyFrame::OnColourGalleryButton
)
175 EVT_MENU(ID_POSITION_LEFT
, MyFrame::OnPositionLeftIcons
)
176 EVT_MENU(ID_POSITION_LEFT_LABELS
, MyFrame::OnPositionLeftLabels
)
177 EVT_MENU(ID_POSITION_LEFT_BOTH
, MyFrame::OnPositionLeftBoth
)
178 EVT_MENU(ID_POSITION_TOP
, MyFrame::OnPositionTopLabels
)
179 EVT_MENU(ID_POSITION_TOP_ICONS
, MyFrame::OnPositionTopIcons
)
180 EVT_MENU(ID_POSITION_TOP_BOTH
, MyFrame::OnPositionTopBoth
)
183 #include "align_center.xpm"
184 #include "align_left.xpm"
185 #include "align_right.xpm"
186 #include "aui_style.xpm"
187 #include "auto_crop_selection.xpm"
188 #include "auto_crop_selection_small.xpm"
189 #include "circle.xpm"
190 #include "circle_small.xpm"
191 #include "colours.xpm"
194 #include "expand_selection_v.xpm"
195 #include "expand_selection_h.xpm"
197 #include "hexagon.xpm"
198 #include "msw_style.xpm"
199 #include "position_left_small.xpm"
200 #include "position_top_small.xpm"
201 #include "ribbon.xpm"
202 #include "selection_panel.xpm"
203 #include "square.xpm"
204 #include "triangle.xpm"
207 : wxFrame(NULL
, wxID_ANY
, wxT("wxRibbon Sample Application"), wxDefaultPosition
, wxSize(800, 600), wxDEFAULT_FRAME_STYLE
)
209 m_ribbon
= new wxRibbonBar(this, wxID_ANY
);
212 wxRibbonPage
* home
= new wxRibbonPage(m_ribbon
, wxID_ANY
, wxT("Examples"), ribbon_xpm
);
213 wxRibbonPanel
*toolbar_panel
= new wxRibbonPanel(home
, wxID_ANY
, wxT("Toolbar"), wxNullBitmap
, wxDefaultPosition
, wxDefaultSize
, wxRIBBON_PANEL_NO_AUTO_MINIMISE
);
214 wxRibbonToolBar
*toolbar
= new wxRibbonToolBar(toolbar_panel
, ID_MAIN_TOOLBAR
);
215 toolbar
->AddTool(wxID_ANY
, align_left_xpm
);
216 toolbar
->AddTool(wxID_ANY
, align_center_xpm
);
217 toolbar
->AddTool(wxID_ANY
, align_right_xpm
);
218 toolbar
->AddSeparator();
219 toolbar
->AddHybridTool(wxID_NEW
, wxArtProvider::GetBitmap(wxART_NEW
, wxART_OTHER
, wxSize(16, 15)));
220 toolbar
->AddTool(wxID_ANY
, wxArtProvider::GetBitmap(wxART_FILE_OPEN
, wxART_OTHER
, wxSize(16, 15)));
221 toolbar
->AddTool(wxID_ANY
, wxArtProvider::GetBitmap(wxART_FILE_SAVE
, wxART_OTHER
, wxSize(16, 15)));
222 toolbar
->AddTool(wxID_ANY
, wxArtProvider::GetBitmap(wxART_FILE_SAVE_AS
, wxART_OTHER
, wxSize(16, 15)));
223 toolbar
->AddSeparator();
224 toolbar
->AddDropdownTool(wxID_UNDO
, wxArtProvider::GetBitmap(wxART_UNDO
, wxART_OTHER
, wxSize(16, 15)));
225 toolbar
->AddDropdownTool(wxID_REDO
, wxArtProvider::GetBitmap(wxART_REDO
, wxART_OTHER
, wxSize(16, 15)));
226 toolbar
->AddSeparator();
227 toolbar
->AddTool(wxID_ANY
, wxArtProvider::GetBitmap(wxART_REPORT_VIEW
, wxART_OTHER
, wxSize(16, 15)));
228 toolbar
->AddTool(wxID_ANY
, wxArtProvider::GetBitmap(wxART_LIST_VIEW
, wxART_OTHER
, wxSize(16, 15)));
229 toolbar
->AddSeparator();
230 toolbar
->AddHybridTool(ID_POSITION_LEFT
, position_left_xpm
);
231 toolbar
->AddHybridTool(ID_POSITION_TOP
, position_top_xpm
);
232 toolbar
->AddSeparator();
233 toolbar
->AddHybridTool(wxID_PRINT
, wxArtProvider::GetBitmap(wxART_PRINT
, wxART_OTHER
, wxSize(16, 15)));
234 toolbar
->SetRows(2, 3);
236 wxRibbonPanel
*selection_panel
= new wxRibbonPanel(home
, wxID_ANY
, wxT("Selection"), wxBitmap(selection_panel_xpm
));
237 wxRibbonButtonBar
*selection
= new wxRibbonButtonBar(selection_panel
);
238 selection
->AddButton(ID_SELECTION_EXPAND_V
, wxT("Expand Vertically"), wxBitmap(expand_selection_v_xpm
), wxEmptyString
);
239 selection
->AddButton(ID_SELECTION_EXPAND_H
, wxT("Expand Horizontally"), wxBitmap(expand_selection_h_xpm
), wxEmptyString
);
240 selection
->AddButton(ID_SELECTION_CONTRACT
, wxT("Contract"), wxBitmap(auto_crop_selection_xpm
), wxBitmap(auto_crop_selection_small_xpm
));
242 wxRibbonPanel
*shapes_panel
= new wxRibbonPanel(home
, wxID_ANY
, wxT("Shapes"), wxBitmap(circle_small_xpm
));
243 wxRibbonButtonBar
*shapes
= new wxRibbonButtonBar(shapes_panel
);
244 shapes
->AddButton(ID_CIRCLE
, wxT("Circle"), wxBitmap(circle_xpm
), wxBitmap(circle_small_xpm
));
245 shapes
->AddButton(ID_CROSS
, wxT("Cross"), wxBitmap(cross_xpm
), wxEmptyString
);
246 shapes
->AddHybridButton(ID_TRIANGLE
, wxT("Triangle"), wxBitmap(triangle_xpm
));
247 shapes
->AddButton(ID_SQUARE
, wxT("Square"), wxBitmap(square_xpm
), wxEmptyString
);
248 shapes
->AddDropdownButton(ID_POLYGON
, wxT("Other Polygon"), wxBitmap(hexagon_xpm
), wxEmptyString
);
250 new wxRibbonPanel(home
, wxID_ANY
, wxT("Another Panel"), wxNullBitmap
, wxDefaultPosition
, wxDefaultSize
, wxRIBBON_PANEL_EXT_BUTTON
);
253 wxFont
label_font(8, wxFONTFAMILY_DEFAULT
, wxFONTSTYLE_NORMAL
, wxFONTWEIGHT_LIGHT
);
254 m_bitmap_creation_dc
.SetFont(label_font
);
256 wxRibbonPage
* scheme
= new wxRibbonPage(m_ribbon
, wxID_ANY
, wxT("Appearance"), eye_xpm
);
257 m_ribbon
->GetArtProvider()->GetColourScheme(&m_default_primary
,
258 &m_default_secondary
, &m_default_tertiary
);
259 wxRibbonPanel
*provider_panel
= new wxRibbonPanel(scheme
, wxID_ANY
,
260 wxT("Art"), wxNullBitmap
, wxDefaultPosition
, wxDefaultSize
, wxRIBBON_PANEL_NO_AUTO_MINIMISE
);
261 wxRibbonButtonBar
*provider_bar
= new wxRibbonButtonBar(provider_panel
, wxID_ANY
);
262 provider_bar
->AddButton(ID_DEFAULT_PROVIDER
, wxT("Default Provider"),
263 wxArtProvider::GetBitmap(wxART_QUESTION
, wxART_OTHER
, wxSize(32, 32)));
264 provider_bar
->AddButton(ID_AUI_PROVIDER
, wxT("AUI Provider"), aui_style_xpm
);
265 provider_bar
->AddButton(ID_MSW_PROVIDER
, wxT("MSW Provider"), msw_style_xpm
);
266 wxRibbonPanel
*primary_panel
= new wxRibbonPanel(scheme
, wxID_ANY
,
267 wxT("Primary Colour"), colours_xpm
);
268 m_primary_gallery
= PopulateColoursPanel(primary_panel
,
269 m_default_primary
, ID_PRIMARY_COLOUR
);
270 wxRibbonPanel
*secondary_panel
= new wxRibbonPanel(scheme
, wxID_ANY
,
271 wxT("Secondary Colour"), colours_xpm
);
272 m_secondary_gallery
= PopulateColoursPanel(secondary_panel
,
273 m_default_secondary
, ID_SECONDARY_COLOUR
);
275 new wxRibbonPage(m_ribbon
, wxID_ANY
, wxT("Empty Page"), empty_xpm
);
276 new wxRibbonPage(m_ribbon
, wxID_ANY
, wxT("Another Page"), empty_xpm
);
280 m_logwindow
= new wxTextCtrl(this, wxID_ANY
, wxEmptyString
,
281 wxDefaultPosition
, wxDefaultSize
, wxTE_MULTILINE
| wxTE_READONLY
|
282 wxTE_LEFT
| wxTE_BESTWRAP
| wxBORDER_NONE
);
284 wxSizer
*s
= new wxBoxSizer(wxVERTICAL
);
286 s
->Add(m_ribbon
, 0, wxEXPAND
);
287 s
->Add(m_logwindow
, 1, wxEXPAND
);
292 void MyFrame::SetBarStyle(long style
)
295 m_ribbon
->SetWindowStyleFlag(style
);
296 wxBoxSizer
*pTopSize
= reinterpret_cast<wxBoxSizer
*>(GetSizer());
297 wxRibbonToolBar
*pToolbar
= wxDynamicCast(FindWindow(ID_MAIN_TOOLBAR
), wxRibbonToolBar
);
298 if(style
& wxRIBBON_BAR_FLOW_VERTICAL
)
300 m_ribbon
->SetTabCtrlMargins(10, 10);
301 pTopSize
->SetOrientation(wxHORIZONTAL
);
303 pToolbar
->SetRows(3, 5);
307 m_ribbon
->SetTabCtrlMargins(50, 20);
308 pTopSize
->SetOrientation(wxVERTICAL
);
310 pToolbar
->SetRows(2, 3);
321 class ColourClientData
: public wxClientData
324 ColourClientData(const wxString
& name
, const wxColour
& colour
)
325 : m_name(name
), m_colour(colour
) {}
327 const wxString
& GetName() const {return m_name
;}
328 const wxColour
& GetColour() const {return m_colour
;}
335 wxRibbonGallery
* MyFrame::PopulateColoursPanel(wxWindow
* panel
,
336 wxColour def
, int gallery_id
)
338 wxRibbonGallery
*gallery
= wxDynamicCast(panel
->FindWindow(gallery_id
), wxRibbonGallery
);
342 gallery
= new wxRibbonGallery(panel
, gallery_id
);
343 wxMemoryDC
& dc
= m_bitmap_creation_dc
;
344 wxRibbonGalleryItem
*def_item
=
345 AddColourToGallery(gallery
, wxT("Default"), dc
, &def
);
346 gallery
->SetSelection(def_item
);
347 AddColourToGallery(gallery
, wxT("BLUE"), dc
);
348 AddColourToGallery(gallery
, wxT("BLUE VIOLET"), dc
);
349 AddColourToGallery(gallery
, wxT("BROWN"), dc
);
350 AddColourToGallery(gallery
, wxT("CADET BLUE"), dc
);
351 AddColourToGallery(gallery
, wxT("CORAL"), dc
);
352 AddColourToGallery(gallery
, wxT("CYAN"), dc
);
353 AddColourToGallery(gallery
, wxT("DARK GREEN"), dc
);
354 AddColourToGallery(gallery
, wxT("DARK ORCHID"), dc
);
355 AddColourToGallery(gallery
, wxT("FIREBRICK"), dc
);
356 AddColourToGallery(gallery
, wxT("GOLD"), dc
);
357 AddColourToGallery(gallery
, wxT("GOLDENROD"), dc
);
358 AddColourToGallery(gallery
, wxT("GREEN"), dc
);
359 AddColourToGallery(gallery
, wxT("INDIAN RED"), dc
);
360 AddColourToGallery(gallery
, wxT("KHAKI"), dc
);
361 AddColourToGallery(gallery
, wxT("LIGHT BLUE"), dc
);
362 AddColourToGallery(gallery
, wxT("LIME GREEN"), dc
);
363 AddColourToGallery(gallery
, wxT("MAGENTA"), dc
);
364 AddColourToGallery(gallery
, wxT("MAROON"), dc
);
365 AddColourToGallery(gallery
, wxT("NAVY"), dc
);
366 AddColourToGallery(gallery
, wxT("ORANGE"), dc
);
367 AddColourToGallery(gallery
, wxT("ORCHID"), dc
);
368 AddColourToGallery(gallery
, wxT("PINK"), dc
);
369 AddColourToGallery(gallery
, wxT("PLUM"), dc
);
370 AddColourToGallery(gallery
, wxT("PURPLE"), dc
);
371 AddColourToGallery(gallery
, wxT("RED"), dc
);
372 AddColourToGallery(gallery
, wxT("SALMON"), dc
);
373 AddColourToGallery(gallery
, wxT("SEA GREEN"), dc
);
374 AddColourToGallery(gallery
, wxT("SIENNA"), dc
);
375 AddColourToGallery(gallery
, wxT("SKY BLUE"), dc
);
376 AddColourToGallery(gallery
, wxT("TAN"), dc
);
377 AddColourToGallery(gallery
, wxT("THISTLE"), dc
);
378 AddColourToGallery(gallery
, wxT("TURQUOISE"), dc
);
379 AddColourToGallery(gallery
, wxT("VIOLET"), dc
);
380 AddColourToGallery(gallery
, wxT("VIOLET RED"), dc
);
381 AddColourToGallery(gallery
, wxT("WHEAT"), dc
);
382 AddColourToGallery(gallery
, wxT("WHITE"), dc
);
383 AddColourToGallery(gallery
, wxT("YELLOW"), dc
);
388 wxColour
MyFrame::GetGalleryColour(wxRibbonGallery
*gallery
,
389 wxRibbonGalleryItem
* item
, wxString
* name
)
391 ColourClientData
*data
= (ColourClientData
*)gallery
->GetItemClientObject(item
);
393 *name
= data
->GetName();
394 return data
->GetColour();
397 void MyFrame::OnHoveredColourChange(wxRibbonGalleryEvent
& evt
)
399 // Set the background of the gallery to the hovered colour, or back to the
400 // default if there is no longer a hovered item.
402 wxRibbonGallery
*gallery
= evt
.GetGallery();
403 wxRibbonArtProvider
*provider
= gallery
->GetArtProvider();
405 if(evt
.GetGalleryItem() != NULL
)
407 if(provider
== m_ribbon
->GetArtProvider())
409 provider
= provider
->Clone();
410 gallery
->SetArtProvider(provider
);
412 provider
->SetColour(wxRIBBON_ART_GALLERY_HOVER_BACKGROUND_COLOUR
,
413 GetGalleryColour(evt
.GetGallery(), evt
.GetGalleryItem(), NULL
));
417 if(provider
!= m_ribbon
->GetArtProvider())
419 gallery
->SetArtProvider(m_ribbon
->GetArtProvider());
425 void MyFrame::OnPrimaryColourSelect(wxRibbonGalleryEvent
& evt
)
428 wxColour colour
= GetGalleryColour(evt
.GetGallery(), evt
.GetGalleryItem(), &name
);
429 AddText(wxT("Colour \"") + name
+ wxT("\" selected as primary."));
430 wxColour secondary
, tertiary
;
431 m_ribbon
->GetArtProvider()->GetColourScheme(NULL
, &secondary
, &tertiary
);
432 m_ribbon
->GetArtProvider()->SetColourScheme(colour
, secondary
, tertiary
);
433 ResetGalleryArtProviders();
437 void MyFrame::OnSecondaryColourSelect(wxRibbonGalleryEvent
& evt
)
440 wxColour colour
= GetGalleryColour(evt
.GetGallery(), evt
.GetGalleryItem(), &name
);
441 AddText(wxT("Colour \"") + name
+ wxT("\" selected as secondary."));
442 wxColour primary
, tertiary
;
443 m_ribbon
->GetArtProvider()->GetColourScheme(&primary
, NULL
, &tertiary
);
444 m_ribbon
->GetArtProvider()->SetColourScheme(primary
, colour
, tertiary
);
445 ResetGalleryArtProviders();
449 void MyFrame::ResetGalleryArtProviders()
451 if(m_primary_gallery
->GetArtProvider() != m_ribbon
->GetArtProvider())
453 delete m_primary_gallery
->GetArtProvider();
454 m_primary_gallery
->SetArtProvider(m_ribbon
->GetArtProvider());
456 if(m_secondary_gallery
->GetArtProvider() != m_ribbon
->GetArtProvider())
458 delete m_secondary_gallery
->GetArtProvider();
459 m_secondary_gallery
->SetArtProvider(m_ribbon
->GetArtProvider());
463 void MyFrame::OnSelectionExpandHButton(wxRibbonButtonBarEvent
& WXUNUSED(evt
))
465 AddText(wxT("Expand selection horizontally button clicked."));
468 void MyFrame::OnSelectionExpandVButton(wxRibbonButtonBarEvent
& WXUNUSED(evt
))
470 AddText(wxT("Expand selection vertically button clicked."));
473 void MyFrame::OnSelectionContractButton(wxRibbonButtonBarEvent
& WXUNUSED(evt
))
475 AddText(wxT("Contract selection button clicked."));
478 void MyFrame::OnCircleButton(wxRibbonButtonBarEvent
& WXUNUSED(evt
))
480 AddText(wxT("Circle button clicked."));
483 void MyFrame::OnCrossButton(wxRibbonButtonBarEvent
& WXUNUSED(evt
))
485 AddText(wxT("Cross button clicked."));
488 void MyFrame::OnTriangleButton(wxRibbonButtonBarEvent
& WXUNUSED(evt
))
490 AddText(wxT("Triangle button clicked."));
493 void MyFrame::OnTriangleDropdown(wxRibbonButtonBarEvent
& evt
)
496 menu
.Append(wxID_ANY
, wxT("Equilateral"));
497 menu
.Append(wxID_ANY
, wxT("Isosceles"));
498 menu
.Append(wxID_ANY
, wxT("Scalene"));
500 evt
.PopupMenu(&menu
);
503 void MyFrame::OnSquareButton(wxRibbonButtonBarEvent
& WXUNUSED(evt
))
505 AddText(wxT("Square button clicked."));
508 void MyFrame::OnPolygonDropdown(wxRibbonButtonBarEvent
& evt
)
511 menu
.Append(wxID_ANY
, wxT("Pentagon (5 sided)"));
512 menu
.Append(wxID_ANY
, wxT("Hexagon (6 sided)"));
513 menu
.Append(wxID_ANY
, wxT("Heptagon (7 sided)"));
514 menu
.Append(wxID_ANY
, wxT("Octogon (8 sided)"));
515 menu
.Append(wxID_ANY
, wxT("Nonagon (9 sided)"));
516 menu
.Append(wxID_ANY
, wxT("Decagon (10 sided)"));
518 evt
.PopupMenu(&menu
);
521 void MyFrame::OnNew(wxRibbonToolBarEvent
& WXUNUSED(evt
))
523 AddText(wxT("New button clicked."));
526 void MyFrame::OnNewDropdown(wxRibbonToolBarEvent
& evt
)
529 menu
.Append(wxID_ANY
, wxT("New Document"));
530 menu
.Append(wxID_ANY
, wxT("New Template"));
531 menu
.Append(wxID_ANY
, wxT("New Mail"));
533 evt
.PopupMenu(&menu
);
536 void MyFrame::OnPrint(wxRibbonToolBarEvent
& WXUNUSED(evt
))
538 AddText(wxT("Print button clicked."));
541 void MyFrame::OnPrintDropdown(wxRibbonToolBarEvent
& evt
)
544 menu
.Append(wxID_ANY
, wxT("Print"));
545 menu
.Append(wxID_ANY
, wxT("Preview"));
546 menu
.Append(wxID_ANY
, wxT("Options"));
548 evt
.PopupMenu(&menu
);
551 void MyFrame::OnRedoDropdown(wxRibbonToolBarEvent
& evt
)
554 menu
.Append(wxID_ANY
, wxT("Redo E"));
555 menu
.Append(wxID_ANY
, wxT("Redo F"));
556 menu
.Append(wxID_ANY
, wxT("Redo G"));
558 evt
.PopupMenu(&menu
);
561 void MyFrame::OnUndoDropdown(wxRibbonToolBarEvent
& evt
)
564 menu
.Append(wxID_ANY
, wxT("Undo C"));
565 menu
.Append(wxID_ANY
, wxT("Undo B"));
566 menu
.Append(wxID_ANY
, wxT("Undo A"));
568 evt
.PopupMenu(&menu
);
571 void MyFrame::OnPositionTopLabels(wxCommandEvent
& WXUNUSED(evt
))
573 SetBarStyle(wxRIBBON_BAR_DEFAULT_STYLE
);
576 void MyFrame::OnPositionTopIcons(wxCommandEvent
& WXUNUSED(evt
))
578 SetBarStyle((wxRIBBON_BAR_DEFAULT_STYLE
&~wxRIBBON_BAR_SHOW_PAGE_LABELS
)
579 | wxRIBBON_BAR_SHOW_PAGE_ICONS
);
582 void MyFrame::OnPositionTopBoth(wxCommandEvent
& WXUNUSED(evt
))
584 SetBarStyle(wxRIBBON_BAR_DEFAULT_STYLE
| wxRIBBON_BAR_SHOW_PAGE_ICONS
);
587 void MyFrame::OnPositionLeftLabels(wxCommandEvent
& WXUNUSED(evt
))
589 SetBarStyle(wxRIBBON_BAR_DEFAULT_STYLE
| wxRIBBON_BAR_FLOW_VERTICAL
);
592 void MyFrame::OnPositionLeftIcons(wxCommandEvent
& WXUNUSED(evt
))
594 SetBarStyle((wxRIBBON_BAR_DEFAULT_STYLE
&~wxRIBBON_BAR_SHOW_PAGE_LABELS
) |
595 wxRIBBON_BAR_SHOW_PAGE_ICONS
| wxRIBBON_BAR_FLOW_VERTICAL
);
598 void MyFrame::OnPositionLeftBoth(wxCommandEvent
& WXUNUSED(evt
))
600 SetBarStyle(wxRIBBON_BAR_DEFAULT_STYLE
| wxRIBBON_BAR_SHOW_PAGE_ICONS
|
601 wxRIBBON_BAR_FLOW_VERTICAL
);
604 void MyFrame::OnPositionTop(wxRibbonToolBarEvent
& evt
)
606 OnPositionTopLabels(evt
);
609 void MyFrame::OnPositionTopDropdown(wxRibbonToolBarEvent
& evt
)
612 menu
.Append(ID_POSITION_TOP
, wxT("Top with Labels"));
613 menu
.Append(ID_POSITION_TOP_ICONS
, wxT("Top with Icons"));
614 menu
.Append(ID_POSITION_TOP_BOTH
, wxT("Top with Both"));
615 evt
.PopupMenu(&menu
);
618 void MyFrame::OnPositionLeft(wxRibbonToolBarEvent
& evt
)
620 OnPositionLeftIcons(evt
);
623 void MyFrame::OnPositionLeftDropdown(wxRibbonToolBarEvent
& evt
)
626 menu
.Append(ID_POSITION_LEFT
, wxT("Left with Icons"));
627 menu
.Append(ID_POSITION_LEFT_LABELS
, wxT("Left with Labels"));
628 menu
.Append(ID_POSITION_LEFT_BOTH
, wxT("Left with Both"));
629 evt
.PopupMenu(&menu
);
632 void MyFrame::AddText(wxString msg
)
634 m_logwindow
->AppendText(msg
);
635 m_logwindow
->AppendText(wxT("\n"));
636 m_ribbon
->DismissExpandedPanel();
639 wxRibbonGalleryItem
* MyFrame::AddColourToGallery(wxRibbonGallery
*gallery
,
640 wxString colour
, wxMemoryDC
& dc
,
643 wxRibbonGalleryItem
* item
= NULL
;
649 const int iWidth
= 64;
650 const int iHeight
= 40;
652 wxBitmap
bitmap(iWidth
, iHeight
);
653 dc
.SelectObject(bitmap
);
655 dc
.SetPen(*wxBLACK_PEN
);
657 dc
.DrawRectangle(0, 0, iWidth
, iHeight
);
659 colour
= colour
.Mid(0, 1) + colour
.Mid(1).Lower();
660 wxSize size
= dc
.GetTextExtent(colour
);
661 wxColour foreground
= wxColour(~c
.Red(), ~c
.Green(), ~c
.Blue());
662 if(abs(foreground
.Red() - c
.Red()) + abs(foreground
.Blue() - c
.Blue())
663 + abs(foreground
.Green() - c
.Green()) < 64)
665 // Foreground too similar to background - use a different
666 // strategy to find a contrasting colour
667 foreground
= wxColour((c
.Red() + 64) % 256, 255 - c
.Green(),
668 (c
.Blue() + 192) % 256);
670 dc
.SetTextForeground(foreground
);
671 dc
.DrawText(colour
, (iWidth
- size
.GetWidth() + 1) / 2,
672 (iHeight
- size
.GetHeight()) / 2);
673 dc
.SelectObjectAsSource(wxNullBitmap
);
675 item
= gallery
->Append(bitmap
, wxID_ANY
);
676 gallery
->SetItemClientObject(item
, new ColourClientData(colour
, c
));
681 void MyFrame::OnColourGalleryButton(wxCommandEvent
& evt
)
683 wxRibbonGallery
*gallery
= wxDynamicCast(evt
.GetEventObject(), wxRibbonGallery
);
687 m_ribbon
->DismissExpandedPanel();
688 if(gallery
->GetSelection())
689 m_colour_data
.SetColour(GetGalleryColour(gallery
, gallery
->GetSelection(), NULL
));
690 wxColourDialog
dlg(this, &m_colour_data
);
691 if(dlg
.ShowModal() == wxID_OK
)
693 m_colour_data
= dlg
.GetColourData();
694 wxColour clr
= m_colour_data
.GetColour();
696 // Try to find colour in gallery
697 wxRibbonGalleryItem
*item
= NULL
;
698 for(unsigned int i
= 0; i
< gallery
->GetCount(); ++i
)
700 item
= gallery
->GetItem(i
);
701 if(GetGalleryColour(gallery
, item
, NULL
) == clr
)
707 // Colour not in gallery - add it
710 item
= AddColourToGallery(gallery
,
711 clr
.GetAsString(wxC2S_HTML_SYNTAX
), m_bitmap_creation_dc
,
717 gallery
->EnsureVisible(item
);
718 gallery
->SetSelection(item
);
720 // Send an event to respond to the selection change
721 wxRibbonGalleryEvent
dummy(wxEVT_COMMAND_RIBBONGALLERY_SELECTED
, gallery
->GetId());
722 dummy
.SetEventObject(gallery
);
723 dummy
.SetGallery(gallery
);
724 dummy
.SetGalleryItem(item
);
725 ProcessWindowEvent(dummy
);
729 void MyFrame::OnDefaultProvider(wxRibbonButtonBarEvent
& WXUNUSED(evt
))
731 m_ribbon
->DismissExpandedPanel();
732 SetArtProvider(new wxRibbonDefaultArtProvider
);
735 void MyFrame::OnAUIProvider(wxRibbonButtonBarEvent
& WXUNUSED(evt
))
737 m_ribbon
->DismissExpandedPanel();
738 SetArtProvider(new wxRibbonAUIArtProvider
);
741 void MyFrame::OnMSWProvider(wxRibbonButtonBarEvent
& WXUNUSED(evt
))
743 m_ribbon
->DismissExpandedPanel();
744 SetArtProvider(new wxRibbonMSWArtProvider
);
747 void MyFrame::SetArtProvider(wxRibbonArtProvider
*prov
)
750 m_ribbon
->SetArtProvider(prov
);
752 prov
->GetColourScheme(&m_default_primary
, &m_default_secondary
,
753 &m_default_tertiary
);
754 PopulateColoursPanel(m_primary_gallery
->GetParent(), m_default_primary
,
756 PopulateColoursPanel(m_secondary_gallery
->GetParent(), m_default_secondary
,
757 ID_SECONDARY_COLOUR
);
761 GetSizer()->Layout();