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
,
78 void OnCircleButton(wxRibbonButtonBarEvent
& evt
);
79 void OnCrossButton(wxRibbonButtonBarEvent
& evt
);
80 void OnTriangleButton(wxRibbonButtonBarEvent
& evt
);
81 void OnTriangleDropdown(wxRibbonButtonBarEvent
& evt
);
82 void OnSquareButton(wxRibbonButtonBarEvent
& evt
);
83 void OnPolygonDropdown(wxRibbonButtonBarEvent
& evt
);
84 void OnSelectionExpandVButton(wxRibbonButtonBarEvent
& evt
);
85 void OnSelectionExpandHButton(wxRibbonButtonBarEvent
& evt
);
86 void OnSelectionContractButton(wxRibbonButtonBarEvent
& evt
);
87 void OnHoveredColourChange(wxRibbonGalleryEvent
& evt
);
88 void OnPrimaryColourSelect(wxRibbonGalleryEvent
& evt
);
89 void OnSecondaryColourSelect(wxRibbonGalleryEvent
& evt
);
90 void OnColourGalleryButton(wxCommandEvent
& evt
);
91 void OnDefaultProvider(wxRibbonButtonBarEvent
& evt
);
92 void OnAUIProvider(wxRibbonButtonBarEvent
& evt
);
93 void OnMSWProvider(wxRibbonButtonBarEvent
& evt
);
94 void OnNew(wxRibbonToolBarEvent
& evt
);
95 void OnNewDropdown(wxRibbonToolBarEvent
& evt
);
96 void OnPrint(wxRibbonToolBarEvent
& evt
);
97 void OnPrintDropdown(wxRibbonToolBarEvent
& evt
);
98 void OnRedoDropdown(wxRibbonToolBarEvent
& evt
);
99 void OnUndoDropdown(wxRibbonToolBarEvent
& evt
);
100 void OnPositionTop(wxRibbonToolBarEvent
& evt
);
101 void OnPositionTopLabels(wxCommandEvent
& evt
);
102 void OnPositionTopIcons(wxCommandEvent
& evt
);
103 void OnPositionTopBoth(wxCommandEvent
& evt
);
104 void OnPositionTopDropdown(wxRibbonToolBarEvent
& evt
);
105 void OnPositionLeft(wxRibbonToolBarEvent
& evt
);
106 void OnPositionLeftLabels(wxCommandEvent
& evt
);
107 void OnPositionLeftIcons(wxCommandEvent
& evt
);
108 void OnPositionLeftBoth(wxCommandEvent
& evt
);
109 void OnPositionLeftDropdown(wxRibbonToolBarEvent
& evt
);
111 void OnTogglePanels(wxCommandEvent
& evt
);
114 wxRibbonGallery
* PopulateColoursPanel(wxWindow
* panel
, wxColour def
,
116 void AddText(wxString msg
);
117 wxRibbonGalleryItem
* AddColourToGallery(wxRibbonGallery
*gallery
,
118 wxString name
, wxMemoryDC
& dc
, wxColour
* value
= NULL
);
119 wxColour
GetGalleryColour(wxRibbonGallery
*gallery
,
120 wxRibbonGalleryItem
* item
, wxString
* name
);
121 void ResetGalleryArtProviders();
122 void SetArtProvider(wxRibbonArtProvider
* prov
);
123 void SetBarStyle(long style
);
125 wxRibbonBar
* m_ribbon
;
126 wxRibbonGallery
* m_primary_gallery
;
127 wxRibbonGallery
* m_secondary_gallery
;
128 wxTextCtrl
* m_logwindow
;
129 wxToggleButton
* m_togglePanels
;
131 wxColourData m_colour_data
;
132 wxColour m_default_primary
;
133 wxColour m_default_secondary
;
134 wxColour m_default_tertiary
;
135 wxMemoryDC m_bitmap_creation_dc
;
137 DECLARE_EVENT_TABLE()
140 // -- implementations --
147 wxFrame
* frame
= new MyFrame
;
153 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
154 EVT_RIBBONBUTTONBAR_CLICKED(ID_DEFAULT_PROVIDER
, MyFrame::OnDefaultProvider
)
155 EVT_RIBBONBUTTONBAR_CLICKED(ID_AUI_PROVIDER
, MyFrame::OnAUIProvider
)
156 EVT_RIBBONBUTTONBAR_CLICKED(ID_MSW_PROVIDER
, MyFrame::OnMSWProvider
)
157 EVT_RIBBONBUTTONBAR_CLICKED(ID_SELECTION_EXPAND_H
, MyFrame::OnSelectionExpandHButton
)
158 EVT_RIBBONBUTTONBAR_CLICKED(ID_SELECTION_EXPAND_V
, MyFrame::OnSelectionExpandVButton
)
159 EVT_RIBBONBUTTONBAR_CLICKED(ID_SELECTION_CONTRACT
, MyFrame::OnSelectionContractButton
)
160 EVT_RIBBONBUTTONBAR_CLICKED(ID_CIRCLE
, MyFrame::OnCircleButton
)
161 EVT_RIBBONBUTTONBAR_CLICKED(ID_CROSS
, MyFrame::OnCrossButton
)
162 EVT_RIBBONBUTTONBAR_CLICKED(ID_TRIANGLE
, MyFrame::OnTriangleButton
)
163 EVT_RIBBONBUTTONBAR_CLICKED(ID_SQUARE
, MyFrame::OnSquareButton
)
164 EVT_RIBBONBUTTONBAR_DROPDOWN_CLICKED(ID_TRIANGLE
, MyFrame::OnTriangleDropdown
)
165 EVT_RIBBONBUTTONBAR_DROPDOWN_CLICKED(ID_POLYGON
, MyFrame::OnPolygonDropdown
)
166 EVT_RIBBONGALLERY_HOVER_CHANGED(ID_PRIMARY_COLOUR
, MyFrame::OnHoveredColourChange
)
167 EVT_RIBBONGALLERY_HOVER_CHANGED(ID_SECONDARY_COLOUR
, MyFrame::OnHoveredColourChange
)
168 EVT_RIBBONGALLERY_SELECTED(ID_PRIMARY_COLOUR
, MyFrame::OnPrimaryColourSelect
)
169 EVT_RIBBONGALLERY_SELECTED(ID_SECONDARY_COLOUR
, MyFrame::OnSecondaryColourSelect
)
170 EVT_RIBBONTOOLBAR_CLICKED(wxID_NEW
, MyFrame::OnNew
)
171 EVT_RIBBONTOOLBAR_DROPDOWN_CLICKED(wxID_NEW
, MyFrame::OnNewDropdown
)
172 EVT_RIBBONTOOLBAR_CLICKED(wxID_PRINT
, MyFrame::OnPrint
)
173 EVT_RIBBONTOOLBAR_DROPDOWN_CLICKED(wxID_PRINT
, MyFrame::OnPrintDropdown
)
174 EVT_RIBBONTOOLBAR_DROPDOWN_CLICKED(wxID_REDO
, MyFrame::OnRedoDropdown
)
175 EVT_RIBBONTOOLBAR_DROPDOWN_CLICKED(wxID_UNDO
, MyFrame::OnUndoDropdown
)
176 EVT_RIBBONTOOLBAR_CLICKED(ID_POSITION_LEFT
, MyFrame::OnPositionLeft
)
177 EVT_RIBBONTOOLBAR_DROPDOWN_CLICKED(ID_POSITION_LEFT
, MyFrame::OnPositionLeftDropdown
)
178 EVT_RIBBONTOOLBAR_CLICKED(ID_POSITION_TOP
, MyFrame::OnPositionTop
)
179 EVT_RIBBONTOOLBAR_DROPDOWN_CLICKED(ID_POSITION_TOP
, MyFrame::OnPositionTopDropdown
)
180 EVT_BUTTON(ID_PRIMARY_COLOUR
, MyFrame::OnColourGalleryButton
)
181 EVT_BUTTON(ID_SECONDARY_COLOUR
, MyFrame::OnColourGalleryButton
)
182 EVT_MENU(ID_POSITION_LEFT
, MyFrame::OnPositionLeftIcons
)
183 EVT_MENU(ID_POSITION_LEFT_LABELS
, MyFrame::OnPositionLeftLabels
)
184 EVT_MENU(ID_POSITION_LEFT_BOTH
, MyFrame::OnPositionLeftBoth
)
185 EVT_MENU(ID_POSITION_TOP
, MyFrame::OnPositionTopLabels
)
186 EVT_MENU(ID_POSITION_TOP_ICONS
, MyFrame::OnPositionTopIcons
)
187 EVT_MENU(ID_POSITION_TOP_BOTH
, MyFrame::OnPositionTopBoth
)
188 EVT_TOGGLEBUTTON(ID_TOGGLE_PANELS
, MyFrame::OnTogglePanels
)
191 #include "align_center.xpm"
192 #include "align_left.xpm"
193 #include "align_right.xpm"
194 #include "aui_style.xpm"
195 #include "auto_crop_selection.xpm"
196 #include "auto_crop_selection_small.xpm"
197 #include "circle.xpm"
198 #include "circle_small.xpm"
199 #include "colours.xpm"
202 #include "expand_selection_v.xpm"
203 #include "expand_selection_h.xpm"
205 #include "hexagon.xpm"
206 #include "msw_style.xpm"
207 #include "position_left_small.xpm"
208 #include "position_top_small.xpm"
209 #include "ribbon.xpm"
210 #include "selection_panel.xpm"
211 #include "square.xpm"
212 #include "triangle.xpm"
215 : wxFrame(NULL
, wxID_ANY
, wxT("wxRibbon Sample Application"), wxDefaultPosition
, wxSize(800, 600), wxDEFAULT_FRAME_STYLE
)
217 m_ribbon
= new wxRibbonBar(this, wxID_ANY
);
220 wxRibbonPage
* home
= new wxRibbonPage(m_ribbon
, wxID_ANY
, wxT("Examples"), ribbon_xpm
);
221 wxRibbonPanel
*toolbar_panel
= new wxRibbonPanel(home
, wxID_ANY
, wxT("Toolbar"),
222 wxNullBitmap
, wxDefaultPosition
, wxDefaultSize
,
223 wxRIBBON_PANEL_NO_AUTO_MINIMISE
);
224 wxRibbonToolBar
*toolbar
= new wxRibbonToolBar(toolbar_panel
, ID_MAIN_TOOLBAR
);
225 toolbar
->AddTool(wxID_ANY
, align_left_xpm
);
226 toolbar
->AddTool(wxID_ANY
, align_center_xpm
);
227 toolbar
->AddTool(wxID_ANY
, align_right_xpm
);
228 toolbar
->AddSeparator();
229 toolbar
->AddHybridTool(wxID_NEW
, wxArtProvider::GetBitmap(wxART_NEW
, wxART_OTHER
, wxSize(16, 15)));
230 toolbar
->AddTool(wxID_ANY
, wxArtProvider::GetBitmap(wxART_FILE_OPEN
, wxART_OTHER
, wxSize(16, 15)));
231 toolbar
->AddTool(wxID_ANY
, wxArtProvider::GetBitmap(wxART_FILE_SAVE
, wxART_OTHER
, wxSize(16, 15)));
232 toolbar
->AddTool(wxID_ANY
, wxArtProvider::GetBitmap(wxART_FILE_SAVE_AS
, wxART_OTHER
, wxSize(16, 15)));
233 toolbar
->AddSeparator();
234 toolbar
->AddDropdownTool(wxID_UNDO
, wxArtProvider::GetBitmap(wxART_UNDO
, wxART_OTHER
, wxSize(16, 15)));
235 toolbar
->AddDropdownTool(wxID_REDO
, wxArtProvider::GetBitmap(wxART_REDO
, wxART_OTHER
, wxSize(16, 15)));
236 toolbar
->AddSeparator();
237 toolbar
->AddTool(wxID_ANY
, wxArtProvider::GetBitmap(wxART_REPORT_VIEW
, wxART_OTHER
, wxSize(16, 15)));
238 toolbar
->AddTool(wxID_ANY
, wxArtProvider::GetBitmap(wxART_LIST_VIEW
, wxART_OTHER
, wxSize(16, 15)));
239 toolbar
->AddSeparator();
240 toolbar
->AddHybridTool(ID_POSITION_LEFT
, position_left_xpm
,
241 "Align ribbonbar vertically\non the left\nfor demonstration purposes");
242 toolbar
->AddHybridTool(ID_POSITION_TOP
, position_top_xpm
,
243 "Align the ribbonbar horizontally\nat the top\nfor demonstration purposes");
244 toolbar
->AddSeparator();
245 toolbar
->AddHybridTool(wxID_PRINT
, wxArtProvider::GetBitmap(wxART_PRINT
, wxART_OTHER
, wxSize(16, 15)),
246 "This is the Print button tooltip\ndemonstrating a tooltip");
247 toolbar
->SetRows(2, 3);
249 wxRibbonPanel
*selection_panel
= new wxRibbonPanel(home
, wxID_ANY
, wxT("Selection"), wxBitmap(selection_panel_xpm
));
250 wxRibbonButtonBar
*selection
= new wxRibbonButtonBar(selection_panel
);
251 selection
->AddButton(ID_SELECTION_EXPAND_V
, wxT("Expand Vertically"), wxBitmap(expand_selection_v_xpm
),
252 "This is a tooltip for Expand Vertically\ndemonstrating a tooltip");
253 selection
->AddButton(ID_SELECTION_EXPAND_H
, wxT("Expand Horizontally"), wxBitmap(expand_selection_h_xpm
), wxEmptyString
);
254 selection
->AddButton(ID_SELECTION_CONTRACT
, wxT("Contract"), wxBitmap(auto_crop_selection_xpm
), wxBitmap(auto_crop_selection_small_xpm
));
256 wxRibbonPanel
*shapes_panel
= new wxRibbonPanel(home
, wxID_ANY
, wxT("Shapes"), wxBitmap(circle_small_xpm
));
257 wxRibbonButtonBar
*shapes
= new wxRibbonButtonBar(shapes_panel
);
258 shapes
->AddButton(ID_CIRCLE
, wxT("Circle"), wxBitmap(circle_xpm
), wxBitmap(circle_small_xpm
),
259 wxNullBitmap
, wxNullBitmap
, wxRIBBON_BUTTON_NORMAL
,
260 "This is a tooltip for the circle button\ndemonstrating another tooltip");
261 shapes
->AddButton(ID_CROSS
, wxT("Cross"), wxBitmap(cross_xpm
), wxEmptyString
);
262 shapes
->AddHybridButton(ID_TRIANGLE
, wxT("Triangle"), wxBitmap(triangle_xpm
));
263 shapes
->AddButton(ID_SQUARE
, wxT("Square"), wxBitmap(square_xpm
), wxEmptyString
);
264 shapes
->AddDropdownButton(ID_POLYGON
, wxT("Other Polygon"), wxBitmap(hexagon_xpm
), wxEmptyString
);
266 wxRibbonPanel
*sizer_panel
= new wxRibbonPanel(home
, wxID_ANY
, wxT("Panel with Sizer"),
267 wxNullBitmap
, wxDefaultPosition
, wxDefaultSize
,
268 wxRIBBON_PANEL_DEFAULT_STYLE
);
271 as
.Add("Item 1 using a box sizer now");
272 as
.Add("Item 2 using a box sizer now");
273 wxComboBox
* sizer_panelcombo
= new wxComboBox(sizer_panel
, wxID_ANY
,
275 wxDefaultPosition
, wxDefaultSize
,
278 wxComboBox
* sizer_panelcombo2
= new wxComboBox(sizer_panel
, wxID_ANY
,
280 wxDefaultPosition
, wxDefaultSize
,
283 sizer_panelcombo
->Select(0);
284 sizer_panelcombo2
->Select(1);
285 sizer_panelcombo
->SetMinSize(wxSize(150, -1));
286 sizer_panelcombo2
->SetMinSize(wxSize(150, -1));
288 //not using wxWrapSizer(wxHORIZONTAL) as it reports an incorrect min height
289 wxSizer
* sizer_panelsizer
= new wxBoxSizer(wxVERTICAL
);
290 sizer_panelsizer
->AddStretchSpacer(1);
291 sizer_panelsizer
->Add(sizer_panelcombo
, 0, wxALL
|wxEXPAND
, 2);
292 sizer_panelsizer
->Add(sizer_panelcombo2
, 0, wxALL
|wxEXPAND
, 2);
293 sizer_panelsizer
->AddStretchSpacer(1);
294 sizer_panel
->SetSizer(sizer_panelsizer
);
296 wxFont
label_font(8, wxFONTFAMILY_DEFAULT
, wxFONTSTYLE_NORMAL
, wxFONTWEIGHT_LIGHT
);
297 m_bitmap_creation_dc
.SetFont(label_font
);
299 wxRibbonPage
* scheme
= new wxRibbonPage(m_ribbon
, wxID_ANY
, wxT("Appearance"), eye_xpm
);
300 m_ribbon
->GetArtProvider()->GetColourScheme(&m_default_primary
,
301 &m_default_secondary
, &m_default_tertiary
);
302 wxRibbonPanel
*provider_panel
= new wxRibbonPanel(scheme
, wxID_ANY
,
303 wxT("Art"), wxNullBitmap
, wxDefaultPosition
, wxDefaultSize
, wxRIBBON_PANEL_NO_AUTO_MINIMISE
);
304 wxRibbonButtonBar
*provider_bar
= new wxRibbonButtonBar(provider_panel
, wxID_ANY
);
305 provider_bar
->AddButton(ID_DEFAULT_PROVIDER
, wxT("Default Provider"),
306 wxArtProvider::GetBitmap(wxART_QUESTION
, wxART_OTHER
, wxSize(32, 32)));
307 provider_bar
->AddButton(ID_AUI_PROVIDER
, wxT("AUI Provider"), aui_style_xpm
);
308 provider_bar
->AddButton(ID_MSW_PROVIDER
, wxT("MSW Provider"), msw_style_xpm
);
309 wxRibbonPanel
*primary_panel
= new wxRibbonPanel(scheme
, wxID_ANY
,
310 wxT("Primary Colour"), colours_xpm
);
311 m_primary_gallery
= PopulateColoursPanel(primary_panel
,
312 m_default_primary
, ID_PRIMARY_COLOUR
);
313 wxRibbonPanel
*secondary_panel
= new wxRibbonPanel(scheme
, wxID_ANY
,
314 wxT("Secondary Colour"), colours_xpm
);
315 m_secondary_gallery
= PopulateColoursPanel(secondary_panel
,
316 m_default_secondary
, ID_SECONDARY_COLOUR
);
318 new wxRibbonPage(m_ribbon
, wxID_ANY
, wxT("Empty Page"), empty_xpm
);
319 new wxRibbonPage(m_ribbon
, wxID_ANY
, wxT("Another Page"), empty_xpm
);
323 m_logwindow
= new wxTextCtrl(this, wxID_ANY
, wxEmptyString
,
324 wxDefaultPosition
, wxDefaultSize
, wxTE_MULTILINE
| wxTE_READONLY
|
325 wxTE_LEFT
| wxTE_BESTWRAP
| wxBORDER_NONE
);
327 m_togglePanels
= new wxToggleButton(this, ID_TOGGLE_PANELS
, "&Toggle panels");
328 m_togglePanels
->SetValue(true);
330 wxSizer
*s
= new wxBoxSizer(wxVERTICAL
);
332 s
->Add(m_ribbon
, 0, wxEXPAND
);
333 s
->Add(m_logwindow
, 1, wxEXPAND
);
334 s
->Add(m_togglePanels
, wxSizerFlags().Border());
339 void MyFrame::SetBarStyle(long style
)
342 m_ribbon
->SetWindowStyleFlag(style
);
343 wxBoxSizer
*pTopSize
= reinterpret_cast<wxBoxSizer
*>(GetSizer());
344 wxRibbonToolBar
*pToolbar
= wxDynamicCast(FindWindow(ID_MAIN_TOOLBAR
), wxRibbonToolBar
);
345 if(style
& wxRIBBON_BAR_FLOW_VERTICAL
)
347 m_ribbon
->SetTabCtrlMargins(10, 10);
348 pTopSize
->SetOrientation(wxHORIZONTAL
);
350 pToolbar
->SetRows(3, 5);
354 m_ribbon
->SetTabCtrlMargins(50, 20);
355 pTopSize
->SetOrientation(wxVERTICAL
);
357 pToolbar
->SetRows(2, 3);
368 class ColourClientData
: public wxClientData
371 ColourClientData(const wxString
& name
, const wxColour
& colour
)
372 : m_name(name
), m_colour(colour
) {}
374 const wxString
& GetName() const {return m_name
;}
375 const wxColour
& GetColour() const {return m_colour
;}
382 wxRibbonGallery
* MyFrame::PopulateColoursPanel(wxWindow
* panel
,
383 wxColour def
, int gallery_id
)
385 wxRibbonGallery
*gallery
= wxDynamicCast(panel
->FindWindow(gallery_id
), wxRibbonGallery
);
389 gallery
= new wxRibbonGallery(panel
, gallery_id
);
390 wxMemoryDC
& dc
= m_bitmap_creation_dc
;
391 wxRibbonGalleryItem
*def_item
=
392 AddColourToGallery(gallery
, wxT("Default"), dc
, &def
);
393 gallery
->SetSelection(def_item
);
394 AddColourToGallery(gallery
, wxT("BLUE"), dc
);
395 AddColourToGallery(gallery
, wxT("BLUE VIOLET"), dc
);
396 AddColourToGallery(gallery
, wxT("BROWN"), dc
);
397 AddColourToGallery(gallery
, wxT("CADET BLUE"), dc
);
398 AddColourToGallery(gallery
, wxT("CORAL"), dc
);
399 AddColourToGallery(gallery
, wxT("CYAN"), dc
);
400 AddColourToGallery(gallery
, wxT("DARK GREEN"), dc
);
401 AddColourToGallery(gallery
, wxT("DARK ORCHID"), dc
);
402 AddColourToGallery(gallery
, wxT("FIREBRICK"), dc
);
403 AddColourToGallery(gallery
, wxT("GOLD"), dc
);
404 AddColourToGallery(gallery
, wxT("GOLDENROD"), dc
);
405 AddColourToGallery(gallery
, wxT("GREEN"), dc
);
406 AddColourToGallery(gallery
, wxT("INDIAN RED"), dc
);
407 AddColourToGallery(gallery
, wxT("KHAKI"), dc
);
408 AddColourToGallery(gallery
, wxT("LIGHT BLUE"), dc
);
409 AddColourToGallery(gallery
, wxT("LIME GREEN"), dc
);
410 AddColourToGallery(gallery
, wxT("MAGENTA"), dc
);
411 AddColourToGallery(gallery
, wxT("MAROON"), dc
);
412 AddColourToGallery(gallery
, wxT("NAVY"), dc
);
413 AddColourToGallery(gallery
, wxT("ORANGE"), dc
);
414 AddColourToGallery(gallery
, wxT("ORCHID"), dc
);
415 AddColourToGallery(gallery
, wxT("PINK"), dc
);
416 AddColourToGallery(gallery
, wxT("PLUM"), dc
);
417 AddColourToGallery(gallery
, wxT("PURPLE"), dc
);
418 AddColourToGallery(gallery
, wxT("RED"), dc
);
419 AddColourToGallery(gallery
, wxT("SALMON"), dc
);
420 AddColourToGallery(gallery
, wxT("SEA GREEN"), dc
);
421 AddColourToGallery(gallery
, wxT("SIENNA"), dc
);
422 AddColourToGallery(gallery
, wxT("SKY BLUE"), dc
);
423 AddColourToGallery(gallery
, wxT("TAN"), dc
);
424 AddColourToGallery(gallery
, wxT("THISTLE"), dc
);
425 AddColourToGallery(gallery
, wxT("TURQUOISE"), dc
);
426 AddColourToGallery(gallery
, wxT("VIOLET"), dc
);
427 AddColourToGallery(gallery
, wxT("VIOLET RED"), dc
);
428 AddColourToGallery(gallery
, wxT("WHEAT"), dc
);
429 AddColourToGallery(gallery
, wxT("WHITE"), dc
);
430 AddColourToGallery(gallery
, wxT("YELLOW"), dc
);
435 wxColour
MyFrame::GetGalleryColour(wxRibbonGallery
*gallery
,
436 wxRibbonGalleryItem
* item
, wxString
* name
)
438 ColourClientData
*data
= (ColourClientData
*)gallery
->GetItemClientObject(item
);
440 *name
= data
->GetName();
441 return data
->GetColour();
444 void MyFrame::OnHoveredColourChange(wxRibbonGalleryEvent
& evt
)
446 // Set the background of the gallery to the hovered colour, or back to the
447 // default if there is no longer a hovered item.
449 wxRibbonGallery
*gallery
= evt
.GetGallery();
450 wxRibbonArtProvider
*provider
= gallery
->GetArtProvider();
452 if(evt
.GetGalleryItem() != NULL
)
454 if(provider
== m_ribbon
->GetArtProvider())
456 provider
= provider
->Clone();
457 gallery
->SetArtProvider(provider
);
459 provider
->SetColour(wxRIBBON_ART_GALLERY_HOVER_BACKGROUND_COLOUR
,
460 GetGalleryColour(evt
.GetGallery(), evt
.GetGalleryItem(), NULL
));
464 if(provider
!= m_ribbon
->GetArtProvider())
466 gallery
->SetArtProvider(m_ribbon
->GetArtProvider());
472 void MyFrame::OnPrimaryColourSelect(wxRibbonGalleryEvent
& evt
)
475 wxColour colour
= GetGalleryColour(evt
.GetGallery(), evt
.GetGalleryItem(), &name
);
476 AddText(wxT("Colour \"") + name
+ wxT("\" selected as primary."));
477 wxColour secondary
, tertiary
;
478 m_ribbon
->GetArtProvider()->GetColourScheme(NULL
, &secondary
, &tertiary
);
479 m_ribbon
->GetArtProvider()->SetColourScheme(colour
, secondary
, tertiary
);
480 ResetGalleryArtProviders();
484 void MyFrame::OnSecondaryColourSelect(wxRibbonGalleryEvent
& evt
)
487 wxColour colour
= GetGalleryColour(evt
.GetGallery(), evt
.GetGalleryItem(), &name
);
488 AddText(wxT("Colour \"") + name
+ wxT("\" selected as secondary."));
489 wxColour primary
, tertiary
;
490 m_ribbon
->GetArtProvider()->GetColourScheme(&primary
, NULL
, &tertiary
);
491 m_ribbon
->GetArtProvider()->SetColourScheme(primary
, colour
, tertiary
);
492 ResetGalleryArtProviders();
496 void MyFrame::ResetGalleryArtProviders()
498 if(m_primary_gallery
->GetArtProvider() != m_ribbon
->GetArtProvider())
500 delete m_primary_gallery
->GetArtProvider();
501 m_primary_gallery
->SetArtProvider(m_ribbon
->GetArtProvider());
503 if(m_secondary_gallery
->GetArtProvider() != m_ribbon
->GetArtProvider())
505 delete m_secondary_gallery
->GetArtProvider();
506 m_secondary_gallery
->SetArtProvider(m_ribbon
->GetArtProvider());
510 void MyFrame::OnSelectionExpandHButton(wxRibbonButtonBarEvent
& WXUNUSED(evt
))
512 AddText(wxT("Expand selection horizontally button clicked."));
515 void MyFrame::OnSelectionExpandVButton(wxRibbonButtonBarEvent
& WXUNUSED(evt
))
517 AddText(wxT("Expand selection vertically button clicked."));
520 void MyFrame::OnSelectionContractButton(wxRibbonButtonBarEvent
& WXUNUSED(evt
))
522 AddText(wxT("Contract selection button clicked."));
525 void MyFrame::OnCircleButton(wxRibbonButtonBarEvent
& WXUNUSED(evt
))
527 AddText(wxT("Circle button clicked."));
530 void MyFrame::OnCrossButton(wxRibbonButtonBarEvent
& WXUNUSED(evt
))
532 AddText(wxT("Cross button clicked."));
535 void MyFrame::OnTriangleButton(wxRibbonButtonBarEvent
& WXUNUSED(evt
))
537 AddText(wxT("Triangle button clicked."));
540 void MyFrame::OnTriangleDropdown(wxRibbonButtonBarEvent
& evt
)
543 menu
.Append(wxID_ANY
, wxT("Equilateral"));
544 menu
.Append(wxID_ANY
, wxT("Isosceles"));
545 menu
.Append(wxID_ANY
, wxT("Scalene"));
547 evt
.PopupMenu(&menu
);
550 void MyFrame::OnSquareButton(wxRibbonButtonBarEvent
& WXUNUSED(evt
))
552 AddText(wxT("Square button clicked."));
555 void MyFrame::OnPolygonDropdown(wxRibbonButtonBarEvent
& evt
)
558 menu
.Append(wxID_ANY
, wxT("Pentagon (5 sided)"));
559 menu
.Append(wxID_ANY
, wxT("Hexagon (6 sided)"));
560 menu
.Append(wxID_ANY
, wxT("Heptagon (7 sided)"));
561 menu
.Append(wxID_ANY
, wxT("Octogon (8 sided)"));
562 menu
.Append(wxID_ANY
, wxT("Nonagon (9 sided)"));
563 menu
.Append(wxID_ANY
, wxT("Decagon (10 sided)"));
565 evt
.PopupMenu(&menu
);
568 void MyFrame::OnNew(wxRibbonToolBarEvent
& WXUNUSED(evt
))
570 AddText(wxT("New button clicked."));
573 void MyFrame::OnNewDropdown(wxRibbonToolBarEvent
& evt
)
576 menu
.Append(wxID_ANY
, wxT("New Document"));
577 menu
.Append(wxID_ANY
, wxT("New Template"));
578 menu
.Append(wxID_ANY
, wxT("New Mail"));
580 evt
.PopupMenu(&menu
);
583 void MyFrame::OnPrint(wxRibbonToolBarEvent
& WXUNUSED(evt
))
585 AddText(wxT("Print button clicked."));
588 void MyFrame::OnPrintDropdown(wxRibbonToolBarEvent
& evt
)
591 menu
.Append(wxID_ANY
, wxT("Print"));
592 menu
.Append(wxID_ANY
, wxT("Preview"));
593 menu
.Append(wxID_ANY
, wxT("Options"));
595 evt
.PopupMenu(&menu
);
598 void MyFrame::OnRedoDropdown(wxRibbonToolBarEvent
& evt
)
601 menu
.Append(wxID_ANY
, wxT("Redo E"));
602 menu
.Append(wxID_ANY
, wxT("Redo F"));
603 menu
.Append(wxID_ANY
, wxT("Redo G"));
605 evt
.PopupMenu(&menu
);
608 void MyFrame::OnUndoDropdown(wxRibbonToolBarEvent
& evt
)
611 menu
.Append(wxID_ANY
, wxT("Undo C"));
612 menu
.Append(wxID_ANY
, wxT("Undo B"));
613 menu
.Append(wxID_ANY
, wxT("Undo A"));
615 evt
.PopupMenu(&menu
);
618 void MyFrame::OnPositionTopLabels(wxCommandEvent
& WXUNUSED(evt
))
620 SetBarStyle(wxRIBBON_BAR_DEFAULT_STYLE
);
623 void MyFrame::OnPositionTopIcons(wxCommandEvent
& WXUNUSED(evt
))
625 SetBarStyle((wxRIBBON_BAR_DEFAULT_STYLE
&~wxRIBBON_BAR_SHOW_PAGE_LABELS
)
626 | wxRIBBON_BAR_SHOW_PAGE_ICONS
);
629 void MyFrame::OnPositionTopBoth(wxCommandEvent
& WXUNUSED(evt
))
631 SetBarStyle(wxRIBBON_BAR_DEFAULT_STYLE
| wxRIBBON_BAR_SHOW_PAGE_ICONS
);
634 void MyFrame::OnPositionLeftLabels(wxCommandEvent
& WXUNUSED(evt
))
636 SetBarStyle(wxRIBBON_BAR_DEFAULT_STYLE
| wxRIBBON_BAR_FLOW_VERTICAL
);
639 void MyFrame::OnPositionLeftIcons(wxCommandEvent
& WXUNUSED(evt
))
641 SetBarStyle((wxRIBBON_BAR_DEFAULT_STYLE
&~wxRIBBON_BAR_SHOW_PAGE_LABELS
) |
642 wxRIBBON_BAR_SHOW_PAGE_ICONS
| wxRIBBON_BAR_FLOW_VERTICAL
);
645 void MyFrame::OnPositionLeftBoth(wxCommandEvent
& WXUNUSED(evt
))
647 SetBarStyle(wxRIBBON_BAR_DEFAULT_STYLE
| wxRIBBON_BAR_SHOW_PAGE_ICONS
|
648 wxRIBBON_BAR_FLOW_VERTICAL
);
651 void MyFrame::OnPositionTop(wxRibbonToolBarEvent
& evt
)
653 OnPositionTopLabels(evt
);
656 void MyFrame::OnPositionTopDropdown(wxRibbonToolBarEvent
& evt
)
659 menu
.Append(ID_POSITION_TOP
, wxT("Top with Labels"));
660 menu
.Append(ID_POSITION_TOP_ICONS
, wxT("Top with Icons"));
661 menu
.Append(ID_POSITION_TOP_BOTH
, wxT("Top with Both"));
662 evt
.PopupMenu(&menu
);
665 void MyFrame::OnPositionLeft(wxRibbonToolBarEvent
& evt
)
667 OnPositionLeftIcons(evt
);
670 void MyFrame::OnPositionLeftDropdown(wxRibbonToolBarEvent
& evt
)
673 menu
.Append(ID_POSITION_LEFT
, wxT("Left with Icons"));
674 menu
.Append(ID_POSITION_LEFT_LABELS
, wxT("Left with Labels"));
675 menu
.Append(ID_POSITION_LEFT_BOTH
, wxT("Left with Both"));
676 evt
.PopupMenu(&menu
);
679 void MyFrame::OnTogglePanels(wxCommandEvent
& WXUNUSED(evt
))
681 m_ribbon
->ShowPanels(m_togglePanels
->GetValue());
684 void MyFrame::AddText(wxString msg
)
686 m_logwindow
->AppendText(msg
);
687 m_logwindow
->AppendText(wxT("\n"));
688 m_ribbon
->DismissExpandedPanel();
691 wxRibbonGalleryItem
* MyFrame::AddColourToGallery(wxRibbonGallery
*gallery
,
692 wxString colour
, wxMemoryDC
& dc
,
695 wxRibbonGalleryItem
* item
= NULL
;
697 if (colour
!= wxT("Default"))
698 c
= wxColour(colour
);
703 const int iWidth
= 64;
704 const int iHeight
= 40;
706 wxBitmap
bitmap(iWidth
, iHeight
);
707 dc
.SelectObject(bitmap
);
709 dc
.SetPen(*wxBLACK_PEN
);
711 dc
.DrawRectangle(0, 0, iWidth
, iHeight
);
713 colour
= colour
.Mid(0, 1) + colour
.Mid(1).Lower();
714 wxSize size
= dc
.GetTextExtent(colour
);
715 wxColour foreground
= wxColour(~c
.Red(), ~c
.Green(), ~c
.Blue());
716 if(abs(foreground
.Red() - c
.Red()) + abs(foreground
.Blue() - c
.Blue())
717 + abs(foreground
.Green() - c
.Green()) < 64)
719 // Foreground too similar to background - use a different
720 // strategy to find a contrasting colour
721 foreground
= wxColour((c
.Red() + 64) % 256, 255 - c
.Green(),
722 (c
.Blue() + 192) % 256);
724 dc
.SetTextForeground(foreground
);
725 dc
.DrawText(colour
, (iWidth
- size
.GetWidth() + 1) / 2,
726 (iHeight
- size
.GetHeight()) / 2);
727 dc
.SelectObjectAsSource(wxNullBitmap
);
729 item
= gallery
->Append(bitmap
, wxID_ANY
);
730 gallery
->SetItemClientObject(item
, new ColourClientData(colour
, c
));
735 void MyFrame::OnColourGalleryButton(wxCommandEvent
& evt
)
737 wxRibbonGallery
*gallery
= wxDynamicCast(evt
.GetEventObject(), wxRibbonGallery
);
741 m_ribbon
->DismissExpandedPanel();
742 if(gallery
->GetSelection())
743 m_colour_data
.SetColour(GetGalleryColour(gallery
, gallery
->GetSelection(), NULL
));
744 wxColourDialog
dlg(this, &m_colour_data
);
745 if(dlg
.ShowModal() == wxID_OK
)
747 m_colour_data
= dlg
.GetColourData();
748 wxColour clr
= m_colour_data
.GetColour();
750 // Try to find colour in gallery
751 wxRibbonGalleryItem
*item
= NULL
;
752 for(unsigned int i
= 0; i
< gallery
->GetCount(); ++i
)
754 item
= gallery
->GetItem(i
);
755 if(GetGalleryColour(gallery
, item
, NULL
) == clr
)
761 // Colour not in gallery - add it
764 item
= AddColourToGallery(gallery
,
765 clr
.GetAsString(wxC2S_HTML_SYNTAX
), m_bitmap_creation_dc
,
771 gallery
->EnsureVisible(item
);
772 gallery
->SetSelection(item
);
774 // Send an event to respond to the selection change
775 wxRibbonGalleryEvent
dummy(wxEVT_COMMAND_RIBBONGALLERY_SELECTED
, gallery
->GetId());
776 dummy
.SetEventObject(gallery
);
777 dummy
.SetGallery(gallery
);
778 dummy
.SetGalleryItem(item
);
779 ProcessWindowEvent(dummy
);
783 void MyFrame::OnDefaultProvider(wxRibbonButtonBarEvent
& WXUNUSED(evt
))
785 m_ribbon
->DismissExpandedPanel();
786 SetArtProvider(new wxRibbonDefaultArtProvider
);
789 void MyFrame::OnAUIProvider(wxRibbonButtonBarEvent
& WXUNUSED(evt
))
791 m_ribbon
->DismissExpandedPanel();
792 SetArtProvider(new wxRibbonAUIArtProvider
);
795 void MyFrame::OnMSWProvider(wxRibbonButtonBarEvent
& WXUNUSED(evt
))
797 m_ribbon
->DismissExpandedPanel();
798 SetArtProvider(new wxRibbonMSWArtProvider
);
801 void MyFrame::SetArtProvider(wxRibbonArtProvider
*prov
)
804 m_ribbon
->SetArtProvider(prov
);
806 prov
->GetColourScheme(&m_default_primary
, &m_default_secondary
,
807 &m_default_tertiary
);
808 PopulateColoursPanel(m_primary_gallery
->GetParent(), m_default_primary
,
810 PopulateColoursPanel(m_secondary_gallery
->GetParent(), m_default_secondary
,
811 ID_SECONDARY_COLOUR
);
815 GetSizer()->Layout();