]> git.saurik.com Git - wxWidgets.git/blame - samples/ribbon/ribbondemo.cpp
Added 'HasAlpha' attribute for wxColourProperty. Setting it to true allows user to...
[wxWidgets.git] / samples / ribbon / ribbondemo.cpp
CommitLineData
3c3ead1d
PC
1///////////////////////////////////////////////////////////////////////////////
2// Name: ribbondemo.cpp
3// Purpose: wxRibbon: Ribbon user interface - sample/test program
4// Author: Peter Cawley
5// Modified by:
6// Created: 2009-05-25
7// RCS-ID: $Id$
8// Copyright: (C) Copyright 2009, Peter Cawley
9// Licence: wxWindows Library Licence
10///////////////////////////////////////////////////////////////////////////////
11
12#include "wx/wxprec.h"
13
14#ifdef __BORLANDC__
15 #pragma hdrstop
16#endif
17
18#include "wx/app.h"
19#include "wx/frame.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"
25#include "wx/sizer.h"
26#include "wx/menu.h"
27#include "wx/dcbuffer.h"
28#include "wx/colordlg.h"
29#include "wx/artprov.h"
66ddc77b
RR
30#include "wx/combobox.h"
31#include "wx/wrapsizer.h"
3c3ead1d
PC
32
33// -- application --
34
35class MyApp : public wxApp
36{
37public:
38 bool OnInit();
39};
40
41DECLARE_APP(MyApp)
42IMPLEMENT_APP(MyApp)
43
44// -- frame --
45
46class MyFrame : public wxFrame
47{
48public:
49 MyFrame();
50 ~MyFrame();
51
52 enum
53 {
54 ID_CIRCLE = wxID_HIGHEST + 1,
55 ID_CROSS,
56 ID_TRIANGLE,
57 ID_SQUARE,
58 ID_POLYGON,
59 ID_SELECTION_EXPAND_H,
60 ID_SELECTION_EXPAND_V,
61 ID_SELECTION_CONTRACT,
62 ID_PRIMARY_COLOUR,
63 ID_SECONDARY_COLOUR,
64 ID_DEFAULT_PROVIDER,
65 ID_AUI_PROVIDER,
66 ID_MSW_PROVIDER,
67 ID_MAIN_TOOLBAR,
68 ID_POSITION_TOP,
69 ID_POSITION_TOP_ICONS,
70 ID_POSITION_TOP_BOTH,
71 ID_POSITION_LEFT,
72 ID_POSITION_LEFT_LABELS,
73 ID_POSITION_LEFT_BOTH,
74 };
75
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);
108
109protected:
110 wxRibbonGallery* PopulateColoursPanel(wxWindow* panel, wxColour def,
111 int gallery_id);
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);
120
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;
130
131 DECLARE_EVENT_TABLE()
132};
133
134// -- implementations --
135
136bool MyApp::OnInit()
137{
138 if(!wxApp::OnInit())
139 return false;
140
141 wxFrame* frame = new MyFrame;
142 SetTopWindow(frame);
143 frame->Show();
144
145 return true;
146}
147
148BEGIN_EVENT_TABLE(MyFrame, wxFrame)
149EVT_RIBBONBUTTONBAR_CLICKED(ID_DEFAULT_PROVIDER, MyFrame::OnDefaultProvider)
150EVT_RIBBONBUTTONBAR_CLICKED(ID_AUI_PROVIDER, MyFrame::OnAUIProvider)
151EVT_RIBBONBUTTONBAR_CLICKED(ID_MSW_PROVIDER, MyFrame::OnMSWProvider)
152EVT_RIBBONBUTTONBAR_CLICKED(ID_SELECTION_EXPAND_H, MyFrame::OnSelectionExpandHButton)
153EVT_RIBBONBUTTONBAR_CLICKED(ID_SELECTION_EXPAND_V, MyFrame::OnSelectionExpandVButton)
154EVT_RIBBONBUTTONBAR_CLICKED(ID_SELECTION_CONTRACT, MyFrame::OnSelectionContractButton)
155EVT_RIBBONBUTTONBAR_CLICKED(ID_CIRCLE, MyFrame::OnCircleButton)
156EVT_RIBBONBUTTONBAR_CLICKED(ID_CROSS, MyFrame::OnCrossButton)
157EVT_RIBBONBUTTONBAR_CLICKED(ID_TRIANGLE, MyFrame::OnTriangleButton)
158EVT_RIBBONBUTTONBAR_CLICKED(ID_SQUARE, MyFrame::OnSquareButton)
159EVT_RIBBONBUTTONBAR_DROPDOWN_CLICKED(ID_TRIANGLE, MyFrame::OnTriangleDropdown)
160EVT_RIBBONBUTTONBAR_DROPDOWN_CLICKED(ID_POLYGON, MyFrame::OnPolygonDropdown)
161EVT_RIBBONGALLERY_HOVER_CHANGED(ID_PRIMARY_COLOUR, MyFrame::OnHoveredColourChange)
162EVT_RIBBONGALLERY_HOVER_CHANGED(ID_SECONDARY_COLOUR, MyFrame::OnHoveredColourChange)
163EVT_RIBBONGALLERY_SELECTED(ID_PRIMARY_COLOUR, MyFrame::OnPrimaryColourSelect)
164EVT_RIBBONGALLERY_SELECTED(ID_SECONDARY_COLOUR, MyFrame::OnSecondaryColourSelect)
165EVT_RIBBONTOOLBAR_CLICKED(wxID_NEW, MyFrame::OnNew)
166EVT_RIBBONTOOLBAR_DROPDOWN_CLICKED(wxID_NEW, MyFrame::OnNewDropdown)
167EVT_RIBBONTOOLBAR_CLICKED(wxID_PRINT, MyFrame::OnPrint)
168EVT_RIBBONTOOLBAR_DROPDOWN_CLICKED(wxID_PRINT, MyFrame::OnPrintDropdown)
169EVT_RIBBONTOOLBAR_DROPDOWN_CLICKED(wxID_REDO, MyFrame::OnRedoDropdown)
170EVT_RIBBONTOOLBAR_DROPDOWN_CLICKED(wxID_UNDO, MyFrame::OnUndoDropdown)
171EVT_RIBBONTOOLBAR_CLICKED(ID_POSITION_LEFT, MyFrame::OnPositionLeft)
172EVT_RIBBONTOOLBAR_DROPDOWN_CLICKED(ID_POSITION_LEFT, MyFrame::OnPositionLeftDropdown)
173EVT_RIBBONTOOLBAR_CLICKED(ID_POSITION_TOP, MyFrame::OnPositionTop)
174EVT_RIBBONTOOLBAR_DROPDOWN_CLICKED(ID_POSITION_TOP, MyFrame::OnPositionTopDropdown)
175EVT_BUTTON(ID_PRIMARY_COLOUR, MyFrame::OnColourGalleryButton)
176EVT_BUTTON(ID_SECONDARY_COLOUR, MyFrame::OnColourGalleryButton)
177EVT_MENU(ID_POSITION_LEFT, MyFrame::OnPositionLeftIcons)
178EVT_MENU(ID_POSITION_LEFT_LABELS, MyFrame::OnPositionLeftLabels)
179EVT_MENU(ID_POSITION_LEFT_BOTH, MyFrame::OnPositionLeftBoth)
180EVT_MENU(ID_POSITION_TOP, MyFrame::OnPositionTopLabels)
181EVT_MENU(ID_POSITION_TOP_ICONS, MyFrame::OnPositionTopIcons)
182EVT_MENU(ID_POSITION_TOP_BOTH, MyFrame::OnPositionTopBoth)
183END_EVENT_TABLE()
184
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"
194#include "cross.xpm"
195#include "empty.xpm"
196#include "expand_selection_v.xpm"
197#include "expand_selection_h.xpm"
198#include "eye.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"
207
208MyFrame::MyFrame()
209 : wxFrame(NULL, wxID_ANY, wxT("wxRibbon Sample Application"), wxDefaultPosition, wxSize(800, 600), wxDEFAULT_FRAME_STYLE)
210{
211 m_ribbon = new wxRibbonBar(this, wxID_ANY);
212
213 {
214 wxRibbonPage* home = new wxRibbonPage(m_ribbon, wxID_ANY, wxT("Examples"), ribbon_xpm);
140091e5
PC
215 wxRibbonPanel *toolbar_panel = new wxRibbonPanel(home, wxID_ANY, wxT("Toolbar"),
216 wxNullBitmap, wxDefaultPosition, wxDefaultSize,
217 wxRIBBON_PANEL_NO_AUTO_MINIMISE);
3c3ead1d
PC
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();
140091e5
PC
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");
3c3ead1d 238 toolbar->AddSeparator();
140091e5
PC
239 toolbar->AddHybridTool(wxID_PRINT, wxArtProvider::GetBitmap(wxART_PRINT, wxART_OTHER, wxSize(16, 15)),
240 "This is the Print button tooltip\ndemonstrating a tooltip");
3c3ead1d
PC
241 toolbar->SetRows(2, 3);
242
243 wxRibbonPanel *selection_panel = new wxRibbonPanel(home, wxID_ANY, wxT("Selection"), wxBitmap(selection_panel_xpm));
244 wxRibbonButtonBar *selection = new wxRibbonButtonBar(selection_panel);
140091e5
PC
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");
3c3ead1d
PC
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));
249
250 wxRibbonPanel *shapes_panel = new wxRibbonPanel(home, wxID_ANY, wxT("Shapes"), wxBitmap(circle_small_xpm));
251 wxRibbonButtonBar *shapes = new wxRibbonButtonBar(shapes_panel);
140091e5
PC
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");
3c3ead1d
PC
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);
259
140091e5
PC
260 wxRibbonPanel *sizer_panel = new wxRibbonPanel(home, wxID_ANY, wxT("Panel with Sizer"),
261 wxNullBitmap, wxDefaultPosition, wxDefaultSize,
262 wxRIBBON_PANEL_DEFAULT_STYLE);
66ddc77b
RR
263
264 wxArrayString as;
140091e5
PC
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,
268 wxEmptyString,
269 wxDefaultPosition, wxDefaultSize,
270 as, wxCB_READONLY);
ce00f59b 271
140091e5
PC
272 wxComboBox* sizer_panelcombo2 = new wxComboBox(sizer_panel, wxID_ANY,
273 wxEmptyString,
274 wxDefaultPosition, wxDefaultSize,
275 as, wxCB_READONLY);
276
277 sizer_panelcombo->Select(0);
278 sizer_panelcombo2->Select(1);
66ddc77b
RR
279 sizer_panelcombo->SetMinSize(wxSize(150, -1));
280 sizer_panelcombo2->SetMinSize(wxSize(150, -1));
281
140091e5
PC
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);
66ddc77b
RR
288 sizer_panel->SetSizer(sizer_panelsizer);
289
3c3ead1d
PC
290 wxFont label_font(8, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_LIGHT);
291 m_bitmap_creation_dc.SetFont(label_font);
292
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);
311 }
312 new wxRibbonPage(m_ribbon, wxID_ANY, wxT("Empty Page"), empty_xpm);
313 new wxRibbonPage(m_ribbon, wxID_ANY, wxT("Another Page"), empty_xpm);
314
315 m_ribbon->Realize();
316
317 m_logwindow = new wxTextCtrl(this, wxID_ANY, wxEmptyString,
318 wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE | wxTE_READONLY |
319 wxTE_LEFT | wxTE_BESTWRAP | wxBORDER_NONE);
320
321 wxSizer *s = new wxBoxSizer(wxVERTICAL);
322
323 s->Add(m_ribbon, 0, wxEXPAND);
324 s->Add(m_logwindow, 1, wxEXPAND);
325
326 SetSizer(s);
327}
328
329void MyFrame::SetBarStyle(long style)
330{
331 m_ribbon->Freeze();
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)
336 {
337 m_ribbon->SetTabCtrlMargins(10, 10);
338 pTopSize->SetOrientation(wxHORIZONTAL);
339 if(pToolbar)
340 pToolbar->SetRows(3, 5);
341 }
342 else
343 {
344 m_ribbon->SetTabCtrlMargins(50, 20);
345 pTopSize->SetOrientation(wxVERTICAL);
346 if(pToolbar)
347 pToolbar->SetRows(2, 3);
348 }
349 m_ribbon->Realise();
350 Layout();
351 m_ribbon->Thaw();
352}
353
354MyFrame::~MyFrame()
355{
356}
357
358class ColourClientData : public wxClientData
359{
360public:
361 ColourClientData(const wxString& name, const wxColour& colour)
362 : m_name(name), m_colour(colour) {}
363
364 const wxString& GetName() const {return m_name;}
365 const wxColour& GetColour() const {return m_colour;}
366
367private:
368 wxString m_name;
369 wxColour m_colour;
370};
371
372wxRibbonGallery* MyFrame::PopulateColoursPanel(wxWindow* panel,
373 wxColour def, int gallery_id)
374{
375 wxRibbonGallery *gallery = wxDynamicCast(panel->FindWindow(gallery_id), wxRibbonGallery);
376 if(gallery)
377 gallery->Clear();
378 else
379 gallery = new wxRibbonGallery(panel, gallery_id);
380 wxMemoryDC& dc = m_bitmap_creation_dc;
ce00f59b 381 wxRibbonGalleryItem *def_item =
3c3ead1d
PC
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);
421
422 return gallery;
423}
424
425wxColour MyFrame::GetGalleryColour(wxRibbonGallery *gallery,
426 wxRibbonGalleryItem* item, wxString* name)
427{
428 ColourClientData *data = (ColourClientData*)gallery->GetItemClientObject(item);
429 if(name != NULL)
430 *name = data->GetName();
431 return data->GetColour();
432}
433
434void MyFrame::OnHoveredColourChange(wxRibbonGalleryEvent& evt)
435{
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.
438
439 wxRibbonGallery *gallery = evt.GetGallery();
440 wxRibbonArtProvider *provider = gallery->GetArtProvider();
441
442 if(evt.GetGalleryItem() != NULL)
443 {
444 if(provider == m_ribbon->GetArtProvider())
445 {
446 provider = provider->Clone();
447 gallery->SetArtProvider(provider);
448 }
449 provider->SetColour(wxRIBBON_ART_GALLERY_HOVER_BACKGROUND_COLOUR,
450 GetGalleryColour(evt.GetGallery(), evt.GetGalleryItem(), NULL));
451 }
452 else
453 {
454 if(provider != m_ribbon->GetArtProvider())
455 {
456 gallery->SetArtProvider(m_ribbon->GetArtProvider());
457 delete provider;
458 }
459 }
460}
461
462void MyFrame::OnPrimaryColourSelect(wxRibbonGalleryEvent& evt)
463{
464 wxString name;
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();
471 m_ribbon->Refresh();
472}
473
474void MyFrame::OnSecondaryColourSelect(wxRibbonGalleryEvent& evt)
475{
476 wxString name;
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();
483 m_ribbon->Refresh();
484}
485
486void MyFrame::ResetGalleryArtProviders()
487{
488 if(m_primary_gallery->GetArtProvider() != m_ribbon->GetArtProvider())
489 {
490 delete m_primary_gallery->GetArtProvider();
491 m_primary_gallery->SetArtProvider(m_ribbon->GetArtProvider());
492 }
493 if(m_secondary_gallery->GetArtProvider() != m_ribbon->GetArtProvider())
494 {
495 delete m_secondary_gallery->GetArtProvider();
496 m_secondary_gallery->SetArtProvider(m_ribbon->GetArtProvider());
497 }
498}
499
500void MyFrame::OnSelectionExpandHButton(wxRibbonButtonBarEvent& WXUNUSED(evt))
501{
502 AddText(wxT("Expand selection horizontally button clicked."));
503}
504
505void MyFrame::OnSelectionExpandVButton(wxRibbonButtonBarEvent& WXUNUSED(evt))
506{
507 AddText(wxT("Expand selection vertically button clicked."));
508}
509
510void MyFrame::OnSelectionContractButton(wxRibbonButtonBarEvent& WXUNUSED(evt))
511{
512 AddText(wxT("Contract selection button clicked."));
513}
514
515void MyFrame::OnCircleButton(wxRibbonButtonBarEvent& WXUNUSED(evt))
516{
517 AddText(wxT("Circle button clicked."));
518}
519
520void MyFrame::OnCrossButton(wxRibbonButtonBarEvent& WXUNUSED(evt))
521{
522 AddText(wxT("Cross button clicked."));
523}
524
525void MyFrame::OnTriangleButton(wxRibbonButtonBarEvent& WXUNUSED(evt))
526{
527 AddText(wxT("Triangle button clicked."));
528}
529
530void MyFrame::OnTriangleDropdown(wxRibbonButtonBarEvent& evt)
531{
532 wxMenu menu;
533 menu.Append(wxID_ANY, wxT("Equilateral"));
534 menu.Append(wxID_ANY, wxT("Isosceles"));
535 menu.Append(wxID_ANY, wxT("Scalene"));
536
537 evt.PopupMenu(&menu);
538}
539
540void MyFrame::OnSquareButton(wxRibbonButtonBarEvent& WXUNUSED(evt))
541{
542 AddText(wxT("Square button clicked."));
543}
544
545void MyFrame::OnPolygonDropdown(wxRibbonButtonBarEvent& evt)
546{
547 wxMenu menu;
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)"));
554
555 evt.PopupMenu(&menu);
556}
557
558void MyFrame::OnNew(wxRibbonToolBarEvent& WXUNUSED(evt))
559{
560 AddText(wxT("New button clicked."));
561}
562
563void MyFrame::OnNewDropdown(wxRibbonToolBarEvent& evt)
564{
565 wxMenu menu;
566 menu.Append(wxID_ANY, wxT("New Document"));
567 menu.Append(wxID_ANY, wxT("New Template"));
568 menu.Append(wxID_ANY, wxT("New Mail"));
569
570 evt.PopupMenu(&menu);
571}
572
573void MyFrame::OnPrint(wxRibbonToolBarEvent& WXUNUSED(evt))
574{
575 AddText(wxT("Print button clicked."));
576}
577
578void MyFrame::OnPrintDropdown(wxRibbonToolBarEvent& evt)
579{
580 wxMenu menu;
581 menu.Append(wxID_ANY, wxT("Print"));
582 menu.Append(wxID_ANY, wxT("Preview"));
583 menu.Append(wxID_ANY, wxT("Options"));
584
585 evt.PopupMenu(&menu);
586}
587
588void MyFrame::OnRedoDropdown(wxRibbonToolBarEvent& evt)
589{
590 wxMenu menu;
591 menu.Append(wxID_ANY, wxT("Redo E"));
592 menu.Append(wxID_ANY, wxT("Redo F"));
593 menu.Append(wxID_ANY, wxT("Redo G"));
594
595 evt.PopupMenu(&menu);
596}
597
598void MyFrame::OnUndoDropdown(wxRibbonToolBarEvent& evt)
599{
600 wxMenu menu;
601 menu.Append(wxID_ANY, wxT("Undo C"));
602 menu.Append(wxID_ANY, wxT("Undo B"));
603 menu.Append(wxID_ANY, wxT("Undo A"));
604
605 evt.PopupMenu(&menu);
606}
607
608void MyFrame::OnPositionTopLabels(wxCommandEvent& WXUNUSED(evt))
609{
610 SetBarStyle(wxRIBBON_BAR_DEFAULT_STYLE);
611}
612
613void MyFrame::OnPositionTopIcons(wxCommandEvent& WXUNUSED(evt))
614{
615 SetBarStyle((wxRIBBON_BAR_DEFAULT_STYLE &~wxRIBBON_BAR_SHOW_PAGE_LABELS)
616 | wxRIBBON_BAR_SHOW_PAGE_ICONS);
617}
618
619void MyFrame::OnPositionTopBoth(wxCommandEvent& WXUNUSED(evt))
620{
621 SetBarStyle(wxRIBBON_BAR_DEFAULT_STYLE | wxRIBBON_BAR_SHOW_PAGE_ICONS);
622}
623
624void MyFrame::OnPositionLeftLabels(wxCommandEvent& WXUNUSED(evt))
625{
626 SetBarStyle(wxRIBBON_BAR_DEFAULT_STYLE | wxRIBBON_BAR_FLOW_VERTICAL);
627}
628
629void MyFrame::OnPositionLeftIcons(wxCommandEvent& WXUNUSED(evt))
630{
631 SetBarStyle((wxRIBBON_BAR_DEFAULT_STYLE &~wxRIBBON_BAR_SHOW_PAGE_LABELS) |
632 wxRIBBON_BAR_SHOW_PAGE_ICONS | wxRIBBON_BAR_FLOW_VERTICAL);
633}
634
635void MyFrame::OnPositionLeftBoth(wxCommandEvent& WXUNUSED(evt))
636{
637 SetBarStyle(wxRIBBON_BAR_DEFAULT_STYLE | wxRIBBON_BAR_SHOW_PAGE_ICONS |
638 wxRIBBON_BAR_FLOW_VERTICAL);
639}
640
641void MyFrame::OnPositionTop(wxRibbonToolBarEvent& evt)
642{
643 OnPositionTopLabels(evt);
644}
645
646void MyFrame::OnPositionTopDropdown(wxRibbonToolBarEvent& evt)
647{
648 wxMenu menu;
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);
653}
654
655void MyFrame::OnPositionLeft(wxRibbonToolBarEvent& evt)
656{
657 OnPositionLeftIcons(evt);
658}
659
660void MyFrame::OnPositionLeftDropdown(wxRibbonToolBarEvent& evt)
661{
662 wxMenu menu;
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);
667}
668
669void MyFrame::AddText(wxString msg)
670{
671 m_logwindow->AppendText(msg);
672 m_logwindow->AppendText(wxT("\n"));
673 m_ribbon->DismissExpandedPanel();
674}
675
676wxRibbonGalleryItem* MyFrame::AddColourToGallery(wxRibbonGallery *gallery,
677 wxString colour, wxMemoryDC& dc,
678 wxColour* value)
679{
680 wxRibbonGalleryItem* item = NULL;
8536ce5b
PC
681 wxColour c;
682 if (colour != wxT("Default"))
683 c = wxColour(colour);
684 if (!c.IsOk())
3c3ead1d
PC
685 c = *value;
686 if(c.IsOk())
687 {
688 const int iWidth = 64;
689 const int iHeight = 40;
690
691 wxBitmap bitmap(iWidth, iHeight);
692 dc.SelectObject(bitmap);
693 wxBrush b(c);
694 dc.SetPen(*wxBLACK_PEN);
695 dc.SetBrush(b);
696 dc.DrawRectangle(0, 0, iWidth, iHeight);
697
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)
703 {
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);
708 }
709 dc.SetTextForeground(foreground);
710 dc.DrawText(colour, (iWidth - size.GetWidth() + 1) / 2,
711 (iHeight - size.GetHeight()) / 2);
712 dc.SelectObjectAsSource(wxNullBitmap);
713
714 item = gallery->Append(bitmap, wxID_ANY);
715 gallery->SetItemClientObject(item, new ColourClientData(colour, c));
716 }
717 return item;
718}
719
720void MyFrame::OnColourGalleryButton(wxCommandEvent& evt)
721{
722 wxRibbonGallery *gallery = wxDynamicCast(evt.GetEventObject(), wxRibbonGallery);
723 if(gallery == NULL)
724 return;
725
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)
731 {
732 m_colour_data = dlg.GetColourData();
733 wxColour clr = m_colour_data.GetColour();
734
735 // Try to find colour in gallery
736 wxRibbonGalleryItem *item = NULL;
737 for(unsigned int i = 0; i < gallery->GetCount(); ++i)
738 {
739 item = gallery->GetItem(i);
740 if(GetGalleryColour(gallery, item, NULL) == clr)
741 break;
742 else
743 item = NULL;
744 }
745
746 // Colour not in gallery - add it
747 if(item == NULL)
748 {
749 item = AddColourToGallery(gallery,
750 clr.GetAsString(wxC2S_HTML_SYNTAX), m_bitmap_creation_dc,
751 &clr);
752 gallery->Realise();
753 }
754
755 // Set selection
756 gallery->EnsureVisible(item);
757 gallery->SetSelection(item);
758
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);
765 }
766}
767
768void MyFrame::OnDefaultProvider(wxRibbonButtonBarEvent& WXUNUSED(evt))
769{
770 m_ribbon->DismissExpandedPanel();
771 SetArtProvider(new wxRibbonDefaultArtProvider);
772}
773
774void MyFrame::OnAUIProvider(wxRibbonButtonBarEvent& WXUNUSED(evt))
775{
776 m_ribbon->DismissExpandedPanel();
777 SetArtProvider(new wxRibbonAUIArtProvider);
778}
779
780void MyFrame::OnMSWProvider(wxRibbonButtonBarEvent& WXUNUSED(evt))
781{
782 m_ribbon->DismissExpandedPanel();
783 SetArtProvider(new wxRibbonMSWArtProvider);
784}
785
786void MyFrame::SetArtProvider(wxRibbonArtProvider *prov)
787{
788 m_ribbon->Freeze();
789 m_ribbon->SetArtProvider(prov);
790
791 prov->GetColourScheme(&m_default_primary, &m_default_secondary,
792 &m_default_tertiary);
793 PopulateColoursPanel(m_primary_gallery->GetParent(), m_default_primary,
794 ID_PRIMARY_COLOUR);
795 PopulateColoursPanel(m_secondary_gallery->GetParent(), m_default_secondary,
796 ID_SECONDARY_COLOUR);
797
798 m_ribbon->Realize();
799 m_ribbon->Thaw();
800 GetSizer()->Layout();
801}