]>
Commit | Line | Data |
---|---|---|
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" | |
30 | #include "wx/combobox.h" | |
31 | #include "wx/tglbtn.h" | |
32 | #include "wx/wrapsizer.h" | |
33 | ||
34 | // -- application -- | |
35 | ||
36 | class MyApp : public wxApp | |
37 | { | |
38 | public: | |
39 | bool OnInit(); | |
40 | }; | |
41 | ||
42 | DECLARE_APP(MyApp) | |
43 | IMPLEMENT_APP(MyApp) | |
44 | ||
45 | // -- frame -- | |
46 | ||
47 | class MyFrame : public wxFrame | |
48 | { | |
49 | public: | |
50 | MyFrame(); | |
51 | ~MyFrame(); | |
52 | ||
53 | enum | |
54 | { | |
55 | ID_CIRCLE = wxID_HIGHEST + 1, | |
56 | ID_CROSS, | |
57 | ID_TRIANGLE, | |
58 | ID_SQUARE, | |
59 | ID_POLYGON, | |
60 | ID_SELECTION_EXPAND_H, | |
61 | ID_SELECTION_EXPAND_V, | |
62 | ID_SELECTION_CONTRACT, | |
63 | ID_PRIMARY_COLOUR, | |
64 | ID_SECONDARY_COLOUR, | |
65 | ID_DEFAULT_PROVIDER, | |
66 | ID_AUI_PROVIDER, | |
67 | ID_MSW_PROVIDER, | |
68 | ID_MAIN_TOOLBAR, | |
69 | ID_POSITION_TOP, | |
70 | ID_POSITION_TOP_ICONS, | |
71 | ID_POSITION_TOP_BOTH, | |
72 | ID_POSITION_LEFT, | |
73 | ID_POSITION_LEFT_LABELS, | |
74 | ID_POSITION_LEFT_BOTH, | |
75 | ID_TOGGLE_PANELS | |
76 | }; | |
77 | ||
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); | |
110 | ||
111 | void OnTogglePanels(wxCommandEvent& evt); | |
112 | ||
113 | protected: | |
114 | wxRibbonGallery* PopulateColoursPanel(wxWindow* panel, wxColour def, | |
115 | int gallery_id); | |
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); | |
124 | ||
125 | wxRibbonBar* m_ribbon; | |
126 | wxRibbonGallery* m_primary_gallery; | |
127 | wxRibbonGallery* m_secondary_gallery; | |
128 | wxTextCtrl* m_logwindow; | |
129 | wxToggleButton* m_togglePanels; | |
130 | ||
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; | |
136 | ||
137 | DECLARE_EVENT_TABLE() | |
138 | }; | |
139 | ||
140 | // -- implementations -- | |
141 | ||
142 | bool MyApp::OnInit() | |
143 | { | |
144 | if(!wxApp::OnInit()) | |
145 | return false; | |
146 | ||
147 | wxFrame* frame = new MyFrame; | |
148 | frame->Show(); | |
149 | ||
150 | return true; | |
151 | } | |
152 | ||
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) | |
189 | END_EVENT_TABLE() | |
190 | ||
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" | |
200 | #include "cross.xpm" | |
201 | #include "empty.xpm" | |
202 | #include "expand_selection_v.xpm" | |
203 | #include "expand_selection_h.xpm" | |
204 | #include "eye.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" | |
213 | ||
214 | MyFrame::MyFrame() | |
215 | : wxFrame(NULL, wxID_ANY, wxT("wxRibbon Sample Application"), wxDefaultPosition, wxSize(800, 600), wxDEFAULT_FRAME_STYLE) | |
216 | { | |
217 | m_ribbon = new wxRibbonBar(this, wxID_ANY); | |
218 | ||
219 | { | |
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); | |
248 | ||
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)); | |
255 | ||
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); | |
265 | ||
266 | wxRibbonPanel *sizer_panel = new wxRibbonPanel(home, wxID_ANY, wxT("Panel with Sizer"), | |
267 | wxNullBitmap, wxDefaultPosition, wxDefaultSize, | |
268 | wxRIBBON_PANEL_DEFAULT_STYLE); | |
269 | ||
270 | wxArrayString as; | |
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, | |
274 | wxEmptyString, | |
275 | wxDefaultPosition, wxDefaultSize, | |
276 | as, wxCB_READONLY); | |
277 | ||
278 | wxComboBox* sizer_panelcombo2 = new wxComboBox(sizer_panel, wxID_ANY, | |
279 | wxEmptyString, | |
280 | wxDefaultPosition, wxDefaultSize, | |
281 | as, wxCB_READONLY); | |
282 | ||
283 | sizer_panelcombo->Select(0); | |
284 | sizer_panelcombo2->Select(1); | |
285 | sizer_panelcombo->SetMinSize(wxSize(150, -1)); | |
286 | sizer_panelcombo2->SetMinSize(wxSize(150, -1)); | |
287 | ||
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); | |
295 | ||
296 | wxFont label_font(8, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_LIGHT); | |
297 | m_bitmap_creation_dc.SetFont(label_font); | |
298 | ||
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); | |
317 | } | |
318 | new wxRibbonPage(m_ribbon, wxID_ANY, wxT("Empty Page"), empty_xpm); | |
319 | new wxRibbonPage(m_ribbon, wxID_ANY, wxT("Another Page"), empty_xpm); | |
320 | ||
321 | m_ribbon->Realize(); | |
322 | ||
323 | m_logwindow = new wxTextCtrl(this, wxID_ANY, wxEmptyString, | |
324 | wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE | wxTE_READONLY | | |
325 | wxTE_LEFT | wxTE_BESTWRAP | wxBORDER_NONE); | |
326 | ||
327 | m_togglePanels = new wxToggleButton(this, ID_TOGGLE_PANELS, "&Toggle panels"); | |
328 | m_togglePanels->SetValue(true); | |
329 | ||
330 | wxSizer *s = new wxBoxSizer(wxVERTICAL); | |
331 | ||
332 | s->Add(m_ribbon, 0, wxEXPAND); | |
333 | s->Add(m_logwindow, 1, wxEXPAND); | |
334 | s->Add(m_togglePanels, wxSizerFlags().Border()); | |
335 | ||
336 | SetSizer(s); | |
337 | } | |
338 | ||
339 | void MyFrame::SetBarStyle(long style) | |
340 | { | |
341 | m_ribbon->Freeze(); | |
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) | |
346 | { | |
347 | m_ribbon->SetTabCtrlMargins(10, 10); | |
348 | pTopSize->SetOrientation(wxHORIZONTAL); | |
349 | if(pToolbar) | |
350 | pToolbar->SetRows(3, 5); | |
351 | } | |
352 | else | |
353 | { | |
354 | m_ribbon->SetTabCtrlMargins(50, 20); | |
355 | pTopSize->SetOrientation(wxVERTICAL); | |
356 | if(pToolbar) | |
357 | pToolbar->SetRows(2, 3); | |
358 | } | |
359 | m_ribbon->Realise(); | |
360 | Layout(); | |
361 | m_ribbon->Thaw(); | |
362 | } | |
363 | ||
364 | MyFrame::~MyFrame() | |
365 | { | |
366 | } | |
367 | ||
368 | class ColourClientData : public wxClientData | |
369 | { | |
370 | public: | |
371 | ColourClientData(const wxString& name, const wxColour& colour) | |
372 | : m_name(name), m_colour(colour) {} | |
373 | ||
374 | const wxString& GetName() const {return m_name;} | |
375 | const wxColour& GetColour() const {return m_colour;} | |
376 | ||
377 | private: | |
378 | wxString m_name; | |
379 | wxColour m_colour; | |
380 | }; | |
381 | ||
382 | wxRibbonGallery* MyFrame::PopulateColoursPanel(wxWindow* panel, | |
383 | wxColour def, int gallery_id) | |
384 | { | |
385 | wxRibbonGallery *gallery = wxDynamicCast(panel->FindWindow(gallery_id), wxRibbonGallery); | |
386 | if(gallery) | |
387 | gallery->Clear(); | |
388 | else | |
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); | |
431 | ||
432 | return gallery; | |
433 | } | |
434 | ||
435 | wxColour MyFrame::GetGalleryColour(wxRibbonGallery *gallery, | |
436 | wxRibbonGalleryItem* item, wxString* name) | |
437 | { | |
438 | ColourClientData *data = (ColourClientData*)gallery->GetItemClientObject(item); | |
439 | if(name != NULL) | |
440 | *name = data->GetName(); | |
441 | return data->GetColour(); | |
442 | } | |
443 | ||
444 | void MyFrame::OnHoveredColourChange(wxRibbonGalleryEvent& evt) | |
445 | { | |
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. | |
448 | ||
449 | wxRibbonGallery *gallery = evt.GetGallery(); | |
450 | wxRibbonArtProvider *provider = gallery->GetArtProvider(); | |
451 | ||
452 | if(evt.GetGalleryItem() != NULL) | |
453 | { | |
454 | if(provider == m_ribbon->GetArtProvider()) | |
455 | { | |
456 | provider = provider->Clone(); | |
457 | gallery->SetArtProvider(provider); | |
458 | } | |
459 | provider->SetColour(wxRIBBON_ART_GALLERY_HOVER_BACKGROUND_COLOUR, | |
460 | GetGalleryColour(evt.GetGallery(), evt.GetGalleryItem(), NULL)); | |
461 | } | |
462 | else | |
463 | { | |
464 | if(provider != m_ribbon->GetArtProvider()) | |
465 | { | |
466 | gallery->SetArtProvider(m_ribbon->GetArtProvider()); | |
467 | delete provider; | |
468 | } | |
469 | } | |
470 | } | |
471 | ||
472 | void MyFrame::OnPrimaryColourSelect(wxRibbonGalleryEvent& evt) | |
473 | { | |
474 | wxString name; | |
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(); | |
481 | m_ribbon->Refresh(); | |
482 | } | |
483 | ||
484 | void MyFrame::OnSecondaryColourSelect(wxRibbonGalleryEvent& evt) | |
485 | { | |
486 | wxString name; | |
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(); | |
493 | m_ribbon->Refresh(); | |
494 | } | |
495 | ||
496 | void MyFrame::ResetGalleryArtProviders() | |
497 | { | |
498 | if(m_primary_gallery->GetArtProvider() != m_ribbon->GetArtProvider()) | |
499 | { | |
500 | delete m_primary_gallery->GetArtProvider(); | |
501 | m_primary_gallery->SetArtProvider(m_ribbon->GetArtProvider()); | |
502 | } | |
503 | if(m_secondary_gallery->GetArtProvider() != m_ribbon->GetArtProvider()) | |
504 | { | |
505 | delete m_secondary_gallery->GetArtProvider(); | |
506 | m_secondary_gallery->SetArtProvider(m_ribbon->GetArtProvider()); | |
507 | } | |
508 | } | |
509 | ||
510 | void MyFrame::OnSelectionExpandHButton(wxRibbonButtonBarEvent& WXUNUSED(evt)) | |
511 | { | |
512 | AddText(wxT("Expand selection horizontally button clicked.")); | |
513 | } | |
514 | ||
515 | void MyFrame::OnSelectionExpandVButton(wxRibbonButtonBarEvent& WXUNUSED(evt)) | |
516 | { | |
517 | AddText(wxT("Expand selection vertically button clicked.")); | |
518 | } | |
519 | ||
520 | void MyFrame::OnSelectionContractButton(wxRibbonButtonBarEvent& WXUNUSED(evt)) | |
521 | { | |
522 | AddText(wxT("Contract selection button clicked.")); | |
523 | } | |
524 | ||
525 | void MyFrame::OnCircleButton(wxRibbonButtonBarEvent& WXUNUSED(evt)) | |
526 | { | |
527 | AddText(wxT("Circle button clicked.")); | |
528 | } | |
529 | ||
530 | void MyFrame::OnCrossButton(wxRibbonButtonBarEvent& WXUNUSED(evt)) | |
531 | { | |
532 | AddText(wxT("Cross button clicked.")); | |
533 | } | |
534 | ||
535 | void MyFrame::OnTriangleButton(wxRibbonButtonBarEvent& WXUNUSED(evt)) | |
536 | { | |
537 | AddText(wxT("Triangle button clicked.")); | |
538 | } | |
539 | ||
540 | void MyFrame::OnTriangleDropdown(wxRibbonButtonBarEvent& evt) | |
541 | { | |
542 | wxMenu menu; | |
543 | menu.Append(wxID_ANY, wxT("Equilateral")); | |
544 | menu.Append(wxID_ANY, wxT("Isosceles")); | |
545 | menu.Append(wxID_ANY, wxT("Scalene")); | |
546 | ||
547 | evt.PopupMenu(&menu); | |
548 | } | |
549 | ||
550 | void MyFrame::OnSquareButton(wxRibbonButtonBarEvent& WXUNUSED(evt)) | |
551 | { | |
552 | AddText(wxT("Square button clicked.")); | |
553 | } | |
554 | ||
555 | void MyFrame::OnPolygonDropdown(wxRibbonButtonBarEvent& evt) | |
556 | { | |
557 | wxMenu menu; | |
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)")); | |
564 | ||
565 | evt.PopupMenu(&menu); | |
566 | } | |
567 | ||
568 | void MyFrame::OnNew(wxRibbonToolBarEvent& WXUNUSED(evt)) | |
569 | { | |
570 | AddText(wxT("New button clicked.")); | |
571 | } | |
572 | ||
573 | void MyFrame::OnNewDropdown(wxRibbonToolBarEvent& evt) | |
574 | { | |
575 | wxMenu menu; | |
576 | menu.Append(wxID_ANY, wxT("New Document")); | |
577 | menu.Append(wxID_ANY, wxT("New Template")); | |
578 | menu.Append(wxID_ANY, wxT("New Mail")); | |
579 | ||
580 | evt.PopupMenu(&menu); | |
581 | } | |
582 | ||
583 | void MyFrame::OnPrint(wxRibbonToolBarEvent& WXUNUSED(evt)) | |
584 | { | |
585 | AddText(wxT("Print button clicked.")); | |
586 | } | |
587 | ||
588 | void MyFrame::OnPrintDropdown(wxRibbonToolBarEvent& evt) | |
589 | { | |
590 | wxMenu menu; | |
591 | menu.Append(wxID_ANY, wxT("Print")); | |
592 | menu.Append(wxID_ANY, wxT("Preview")); | |
593 | menu.Append(wxID_ANY, wxT("Options")); | |
594 | ||
595 | evt.PopupMenu(&menu); | |
596 | } | |
597 | ||
598 | void MyFrame::OnRedoDropdown(wxRibbonToolBarEvent& evt) | |
599 | { | |
600 | wxMenu menu; | |
601 | menu.Append(wxID_ANY, wxT("Redo E")); | |
602 | menu.Append(wxID_ANY, wxT("Redo F")); | |
603 | menu.Append(wxID_ANY, wxT("Redo G")); | |
604 | ||
605 | evt.PopupMenu(&menu); | |
606 | } | |
607 | ||
608 | void MyFrame::OnUndoDropdown(wxRibbonToolBarEvent& evt) | |
609 | { | |
610 | wxMenu menu; | |
611 | menu.Append(wxID_ANY, wxT("Undo C")); | |
612 | menu.Append(wxID_ANY, wxT("Undo B")); | |
613 | menu.Append(wxID_ANY, wxT("Undo A")); | |
614 | ||
615 | evt.PopupMenu(&menu); | |
616 | } | |
617 | ||
618 | void MyFrame::OnPositionTopLabels(wxCommandEvent& WXUNUSED(evt)) | |
619 | { | |
620 | SetBarStyle(wxRIBBON_BAR_DEFAULT_STYLE); | |
621 | } | |
622 | ||
623 | void MyFrame::OnPositionTopIcons(wxCommandEvent& WXUNUSED(evt)) | |
624 | { | |
625 | SetBarStyle((wxRIBBON_BAR_DEFAULT_STYLE &~wxRIBBON_BAR_SHOW_PAGE_LABELS) | |
626 | | wxRIBBON_BAR_SHOW_PAGE_ICONS); | |
627 | } | |
628 | ||
629 | void MyFrame::OnPositionTopBoth(wxCommandEvent& WXUNUSED(evt)) | |
630 | { | |
631 | SetBarStyle(wxRIBBON_BAR_DEFAULT_STYLE | wxRIBBON_BAR_SHOW_PAGE_ICONS); | |
632 | } | |
633 | ||
634 | void MyFrame::OnPositionLeftLabels(wxCommandEvent& WXUNUSED(evt)) | |
635 | { | |
636 | SetBarStyle(wxRIBBON_BAR_DEFAULT_STYLE | wxRIBBON_BAR_FLOW_VERTICAL); | |
637 | } | |
638 | ||
639 | void MyFrame::OnPositionLeftIcons(wxCommandEvent& WXUNUSED(evt)) | |
640 | { | |
641 | SetBarStyle((wxRIBBON_BAR_DEFAULT_STYLE &~wxRIBBON_BAR_SHOW_PAGE_LABELS) | | |
642 | wxRIBBON_BAR_SHOW_PAGE_ICONS | wxRIBBON_BAR_FLOW_VERTICAL); | |
643 | } | |
644 | ||
645 | void MyFrame::OnPositionLeftBoth(wxCommandEvent& WXUNUSED(evt)) | |
646 | { | |
647 | SetBarStyle(wxRIBBON_BAR_DEFAULT_STYLE | wxRIBBON_BAR_SHOW_PAGE_ICONS | | |
648 | wxRIBBON_BAR_FLOW_VERTICAL); | |
649 | } | |
650 | ||
651 | void MyFrame::OnPositionTop(wxRibbonToolBarEvent& evt) | |
652 | { | |
653 | OnPositionTopLabels(evt); | |
654 | } | |
655 | ||
656 | void MyFrame::OnPositionTopDropdown(wxRibbonToolBarEvent& evt) | |
657 | { | |
658 | wxMenu menu; | |
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); | |
663 | } | |
664 | ||
665 | void MyFrame::OnPositionLeft(wxRibbonToolBarEvent& evt) | |
666 | { | |
667 | OnPositionLeftIcons(evt); | |
668 | } | |
669 | ||
670 | void MyFrame::OnPositionLeftDropdown(wxRibbonToolBarEvent& evt) | |
671 | { | |
672 | wxMenu menu; | |
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); | |
677 | } | |
678 | ||
679 | void MyFrame::OnTogglePanels(wxCommandEvent& WXUNUSED(evt)) | |
680 | { | |
681 | m_ribbon->ShowPanels(m_togglePanels->GetValue()); | |
682 | } | |
683 | ||
684 | void MyFrame::AddText(wxString msg) | |
685 | { | |
686 | m_logwindow->AppendText(msg); | |
687 | m_logwindow->AppendText(wxT("\n")); | |
688 | m_ribbon->DismissExpandedPanel(); | |
689 | } | |
690 | ||
691 | wxRibbonGalleryItem* MyFrame::AddColourToGallery(wxRibbonGallery *gallery, | |
692 | wxString colour, wxMemoryDC& dc, | |
693 | wxColour* value) | |
694 | { | |
695 | wxRibbonGalleryItem* item = NULL; | |
696 | wxColour c; | |
697 | if (colour != wxT("Default")) | |
698 | c = wxColour(colour); | |
699 | if (!c.IsOk()) | |
700 | c = *value; | |
701 | if(c.IsOk()) | |
702 | { | |
703 | const int iWidth = 64; | |
704 | const int iHeight = 40; | |
705 | ||
706 | wxBitmap bitmap(iWidth, iHeight); | |
707 | dc.SelectObject(bitmap); | |
708 | wxBrush b(c); | |
709 | dc.SetPen(*wxBLACK_PEN); | |
710 | dc.SetBrush(b); | |
711 | dc.DrawRectangle(0, 0, iWidth, iHeight); | |
712 | ||
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) | |
718 | { | |
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); | |
723 | } | |
724 | dc.SetTextForeground(foreground); | |
725 | dc.DrawText(colour, (iWidth - size.GetWidth() + 1) / 2, | |
726 | (iHeight - size.GetHeight()) / 2); | |
727 | dc.SelectObjectAsSource(wxNullBitmap); | |
728 | ||
729 | item = gallery->Append(bitmap, wxID_ANY); | |
730 | gallery->SetItemClientObject(item, new ColourClientData(colour, c)); | |
731 | } | |
732 | return item; | |
733 | } | |
734 | ||
735 | void MyFrame::OnColourGalleryButton(wxCommandEvent& evt) | |
736 | { | |
737 | wxRibbonGallery *gallery = wxDynamicCast(evt.GetEventObject(), wxRibbonGallery); | |
738 | if(gallery == NULL) | |
739 | return; | |
740 | ||
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) | |
746 | { | |
747 | m_colour_data = dlg.GetColourData(); | |
748 | wxColour clr = m_colour_data.GetColour(); | |
749 | ||
750 | // Try to find colour in gallery | |
751 | wxRibbonGalleryItem *item = NULL; | |
752 | for(unsigned int i = 0; i < gallery->GetCount(); ++i) | |
753 | { | |
754 | item = gallery->GetItem(i); | |
755 | if(GetGalleryColour(gallery, item, NULL) == clr) | |
756 | break; | |
757 | else | |
758 | item = NULL; | |
759 | } | |
760 | ||
761 | // Colour not in gallery - add it | |
762 | if(item == NULL) | |
763 | { | |
764 | item = AddColourToGallery(gallery, | |
765 | clr.GetAsString(wxC2S_HTML_SYNTAX), m_bitmap_creation_dc, | |
766 | &clr); | |
767 | gallery->Realise(); | |
768 | } | |
769 | ||
770 | // Set selection | |
771 | gallery->EnsureVisible(item); | |
772 | gallery->SetSelection(item); | |
773 | ||
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); | |
780 | } | |
781 | } | |
782 | ||
783 | void MyFrame::OnDefaultProvider(wxRibbonButtonBarEvent& WXUNUSED(evt)) | |
784 | { | |
785 | m_ribbon->DismissExpandedPanel(); | |
786 | SetArtProvider(new wxRibbonDefaultArtProvider); | |
787 | } | |
788 | ||
789 | void MyFrame::OnAUIProvider(wxRibbonButtonBarEvent& WXUNUSED(evt)) | |
790 | { | |
791 | m_ribbon->DismissExpandedPanel(); | |
792 | SetArtProvider(new wxRibbonAUIArtProvider); | |
793 | } | |
794 | ||
795 | void MyFrame::OnMSWProvider(wxRibbonButtonBarEvent& WXUNUSED(evt)) | |
796 | { | |
797 | m_ribbon->DismissExpandedPanel(); | |
798 | SetArtProvider(new wxRibbonMSWArtProvider); | |
799 | } | |
800 | ||
801 | void MyFrame::SetArtProvider(wxRibbonArtProvider *prov) | |
802 | { | |
803 | m_ribbon->Freeze(); | |
804 | m_ribbon->SetArtProvider(prov); | |
805 | ||
806 | prov->GetColourScheme(&m_default_primary, &m_default_secondary, | |
807 | &m_default_tertiary); | |
808 | PopulateColoursPanel(m_primary_gallery->GetParent(), m_default_primary, | |
809 | ID_PRIMARY_COLOUR); | |
810 | PopulateColoursPanel(m_secondary_gallery->GetParent(), m_default_secondary, | |
811 | ID_SECONDARY_COLOUR); | |
812 | ||
813 | m_ribbon->Realize(); | |
814 | m_ribbon->Thaw(); | |
815 | GetSizer()->Layout(); | |
816 | } |