]>
Commit | Line | Data |
---|---|---|
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" | |
a15f0e42 | 27 | #include "wx/msgdlg.h" |
3c3ead1d PC |
28 | #include "wx/dcbuffer.h" |
29 | #include "wx/colordlg.h" | |
30 | #include "wx/artprov.h" | |
66ddc77b | 31 | #include "wx/combobox.h" |
3603e565 | 32 | #include "wx/tglbtn.h" |
66ddc77b | 33 | #include "wx/wrapsizer.h" |
3c3ead1d PC |
34 | |
35 | // -- application -- | |
36 | ||
37 | class MyApp : public wxApp | |
38 | { | |
39 | public: | |
40 | bool OnInit(); | |
41 | }; | |
42 | ||
43 | DECLARE_APP(MyApp) | |
44 | IMPLEMENT_APP(MyApp) | |
45 | ||
46 | // -- frame -- | |
47 | ||
48 | class MyFrame : public wxFrame | |
49 | { | |
50 | public: | |
51 | MyFrame(); | |
52 | ~MyFrame(); | |
53 | ||
54 | enum | |
55 | { | |
56 | ID_CIRCLE = wxID_HIGHEST + 1, | |
57 | ID_CROSS, | |
58 | ID_TRIANGLE, | |
59 | ID_SQUARE, | |
60 | ID_POLYGON, | |
61 | ID_SELECTION_EXPAND_H, | |
62 | ID_SELECTION_EXPAND_V, | |
63 | ID_SELECTION_CONTRACT, | |
64 | ID_PRIMARY_COLOUR, | |
65 | ID_SECONDARY_COLOUR, | |
66 | ID_DEFAULT_PROVIDER, | |
67 | ID_AUI_PROVIDER, | |
68 | ID_MSW_PROVIDER, | |
69 | ID_MAIN_TOOLBAR, | |
70 | ID_POSITION_TOP, | |
71 | ID_POSITION_TOP_ICONS, | |
72 | ID_POSITION_TOP_BOTH, | |
73 | ID_POSITION_LEFT, | |
74 | ID_POSITION_LEFT_LABELS, | |
75 | ID_POSITION_LEFT_BOTH, | |
f01e5624 VZ |
76 | ID_TOGGLE_PANELS, |
77 | ID_ENABLE, | |
78 | ID_DISABLE, | |
79 | ID_DISABLED, | |
80 | ID_UI_ENABLE_UPDATED, | |
81 | ID_CHECK, | |
82 | ID_UI_CHECK_UPDATED, | |
83 | ID_CHANGE_TEXT1, | |
84 | ID_CHANGE_TEXT2, | |
c21b99e0 | 85 | ID_UI_CHANGE_TEXT_UPDATED, |
5c14ec26 VZ |
86 | ID_REMOVE_PAGE, |
87 | ID_HIDE_PAGES, | |
88 | ID_SHOW_PAGES | |
3c3ead1d PC |
89 | }; |
90 | ||
f01e5624 VZ |
91 | void OnEnableUpdateUI(wxUpdateUIEvent& evt); |
92 | void OnCheckUpdateUI(wxUpdateUIEvent& evt); | |
93 | void OnChangeTextUpdateUI(wxUpdateUIEvent& evt); | |
94 | void OnCheck(wxRibbonButtonBarEvent& evt); | |
95 | void OnEnable(wxRibbonButtonBarEvent& evt); | |
96 | void OnDisable(wxRibbonButtonBarEvent& evt); | |
97 | void OnChangeText1(wxRibbonButtonBarEvent& evt); | |
98 | void OnChangeText2(wxRibbonButtonBarEvent& evt); | |
3c3ead1d PC |
99 | void OnCircleButton(wxRibbonButtonBarEvent& evt); |
100 | void OnCrossButton(wxRibbonButtonBarEvent& evt); | |
101 | void OnTriangleButton(wxRibbonButtonBarEvent& evt); | |
102 | void OnTriangleDropdown(wxRibbonButtonBarEvent& evt); | |
103 | void OnSquareButton(wxRibbonButtonBarEvent& evt); | |
104 | void OnPolygonDropdown(wxRibbonButtonBarEvent& evt); | |
105 | void OnSelectionExpandVButton(wxRibbonButtonBarEvent& evt); | |
106 | void OnSelectionExpandHButton(wxRibbonButtonBarEvent& evt); | |
107 | void OnSelectionContractButton(wxRibbonButtonBarEvent& evt); | |
108 | void OnHoveredColourChange(wxRibbonGalleryEvent& evt); | |
109 | void OnPrimaryColourSelect(wxRibbonGalleryEvent& evt); | |
110 | void OnSecondaryColourSelect(wxRibbonGalleryEvent& evt); | |
111 | void OnColourGalleryButton(wxCommandEvent& evt); | |
112 | void OnDefaultProvider(wxRibbonButtonBarEvent& evt); | |
113 | void OnAUIProvider(wxRibbonButtonBarEvent& evt); | |
114 | void OnMSWProvider(wxRibbonButtonBarEvent& evt); | |
d1bf0be0 VZ |
115 | void OnJustify(wxRibbonToolBarEvent& evt); |
116 | void OnJustifyUpdateUI(wxUpdateUIEvent& evt); | |
3c3ead1d PC |
117 | void OnNew(wxRibbonToolBarEvent& evt); |
118 | void OnNewDropdown(wxRibbonToolBarEvent& evt); | |
119 | void OnPrint(wxRibbonToolBarEvent& evt); | |
120 | void OnPrintDropdown(wxRibbonToolBarEvent& evt); | |
121 | void OnRedoDropdown(wxRibbonToolBarEvent& evt); | |
122 | void OnUndoDropdown(wxRibbonToolBarEvent& evt); | |
123 | void OnPositionTop(wxRibbonToolBarEvent& evt); | |
124 | void OnPositionTopLabels(wxCommandEvent& evt); | |
125 | void OnPositionTopIcons(wxCommandEvent& evt); | |
126 | void OnPositionTopBoth(wxCommandEvent& evt); | |
127 | void OnPositionTopDropdown(wxRibbonToolBarEvent& evt); | |
128 | void OnPositionLeft(wxRibbonToolBarEvent& evt); | |
129 | void OnPositionLeftLabels(wxCommandEvent& evt); | |
130 | void OnPositionLeftIcons(wxCommandEvent& evt); | |
131 | void OnPositionLeftBoth(wxCommandEvent& evt); | |
132 | void OnPositionLeftDropdown(wxRibbonToolBarEvent& evt); | |
c21b99e0 | 133 | void OnRemovePage(wxRibbonButtonBarEvent& evt); |
5c14ec26 VZ |
134 | void OnHidePages(wxRibbonButtonBarEvent& evt); |
135 | void OnShowPages(wxRibbonButtonBarEvent& evt); | |
3603e565 | 136 | void OnTogglePanels(wxCommandEvent& evt); |
7c70331e | 137 | void OnRibbonBarToggled(wxRibbonBarEvent& evt); |
3603e565 | 138 | |
0a7ee6e0 VZ |
139 | void OnExtButton(wxRibbonPanelEvent& evt); |
140 | ||
3c3ead1d PC |
141 | protected: |
142 | wxRibbonGallery* PopulateColoursPanel(wxWindow* panel, wxColour def, | |
143 | int gallery_id); | |
144 | void AddText(wxString msg); | |
145 | wxRibbonGalleryItem* AddColourToGallery(wxRibbonGallery *gallery, | |
146 | wxString name, wxMemoryDC& dc, wxColour* value = NULL); | |
147 | wxColour GetGalleryColour(wxRibbonGallery *gallery, | |
148 | wxRibbonGalleryItem* item, wxString* name); | |
149 | void ResetGalleryArtProviders(); | |
150 | void SetArtProvider(wxRibbonArtProvider* prov); | |
151 | void SetBarStyle(long style); | |
152 | ||
153 | wxRibbonBar* m_ribbon; | |
154 | wxRibbonGallery* m_primary_gallery; | |
155 | wxRibbonGallery* m_secondary_gallery; | |
156 | wxTextCtrl* m_logwindow; | |
3603e565 VZ |
157 | wxToggleButton* m_togglePanels; |
158 | ||
3c3ead1d PC |
159 | wxColourData m_colour_data; |
160 | wxColour m_default_primary; | |
161 | wxColour m_default_secondary; | |
162 | wxColour m_default_tertiary; | |
163 | wxMemoryDC m_bitmap_creation_dc; | |
f01e5624 VZ |
164 | bool m_bEnabled; |
165 | bool m_bChecked; | |
166 | wxString m_new_text; | |
3c3ead1d PC |
167 | |
168 | DECLARE_EVENT_TABLE() | |
169 | }; | |
170 | ||
171 | // -- implementations -- | |
172 | ||
173 | bool MyApp::OnInit() | |
174 | { | |
175 | if(!wxApp::OnInit()) | |
176 | return false; | |
177 | ||
178 | wxFrame* frame = new MyFrame; | |
3c3ead1d PC |
179 | frame->Show(); |
180 | ||
181 | return true; | |
182 | } | |
183 | ||
184 | BEGIN_EVENT_TABLE(MyFrame, wxFrame) | |
f01e5624 VZ |
185 | EVT_RIBBONBUTTONBAR_CLICKED(ID_ENABLE, MyFrame::OnEnable) |
186 | EVT_RIBBONBUTTONBAR_CLICKED(ID_DISABLE, MyFrame::OnDisable) | |
187 | EVT_UPDATE_UI(ID_UI_ENABLE_UPDATED, MyFrame::OnEnableUpdateUI) | |
188 | EVT_RIBBONBUTTONBAR_CLICKED(ID_CHECK, MyFrame::OnCheck) | |
189 | EVT_UPDATE_UI(ID_UI_CHECK_UPDATED, MyFrame::OnCheckUpdateUI) | |
190 | EVT_RIBBONBUTTONBAR_CLICKED(ID_CHANGE_TEXT1, MyFrame::OnChangeText1) | |
191 | EVT_RIBBONBUTTONBAR_CLICKED(ID_CHANGE_TEXT2, MyFrame::OnChangeText2) | |
192 | EVT_UPDATE_UI(ID_UI_CHANGE_TEXT_UPDATED, MyFrame::OnChangeTextUpdateUI) | |
3c3ead1d PC |
193 | EVT_RIBBONBUTTONBAR_CLICKED(ID_DEFAULT_PROVIDER, MyFrame::OnDefaultProvider) |
194 | EVT_RIBBONBUTTONBAR_CLICKED(ID_AUI_PROVIDER, MyFrame::OnAUIProvider) | |
195 | EVT_RIBBONBUTTONBAR_CLICKED(ID_MSW_PROVIDER, MyFrame::OnMSWProvider) | |
196 | EVT_RIBBONBUTTONBAR_CLICKED(ID_SELECTION_EXPAND_H, MyFrame::OnSelectionExpandHButton) | |
197 | EVT_RIBBONBUTTONBAR_CLICKED(ID_SELECTION_EXPAND_V, MyFrame::OnSelectionExpandVButton) | |
198 | EVT_RIBBONBUTTONBAR_CLICKED(ID_SELECTION_CONTRACT, MyFrame::OnSelectionContractButton) | |
199 | EVT_RIBBONBUTTONBAR_CLICKED(ID_CIRCLE, MyFrame::OnCircleButton) | |
200 | EVT_RIBBONBUTTONBAR_CLICKED(ID_CROSS, MyFrame::OnCrossButton) | |
201 | EVT_RIBBONBUTTONBAR_CLICKED(ID_TRIANGLE, MyFrame::OnTriangleButton) | |
202 | EVT_RIBBONBUTTONBAR_CLICKED(ID_SQUARE, MyFrame::OnSquareButton) | |
203 | EVT_RIBBONBUTTONBAR_DROPDOWN_CLICKED(ID_TRIANGLE, MyFrame::OnTriangleDropdown) | |
204 | EVT_RIBBONBUTTONBAR_DROPDOWN_CLICKED(ID_POLYGON, MyFrame::OnPolygonDropdown) | |
205 | EVT_RIBBONGALLERY_HOVER_CHANGED(ID_PRIMARY_COLOUR, MyFrame::OnHoveredColourChange) | |
206 | EVT_RIBBONGALLERY_HOVER_CHANGED(ID_SECONDARY_COLOUR, MyFrame::OnHoveredColourChange) | |
207 | EVT_RIBBONGALLERY_SELECTED(ID_PRIMARY_COLOUR, MyFrame::OnPrimaryColourSelect) | |
208 | EVT_RIBBONGALLERY_SELECTED(ID_SECONDARY_COLOUR, MyFrame::OnSecondaryColourSelect) | |
d1bf0be0 VZ |
209 | EVT_RIBBONTOOLBAR_CLICKED(wxID_JUSTIFY_LEFT, MyFrame::OnJustify) |
210 | EVT_RIBBONTOOLBAR_CLICKED(wxID_JUSTIFY_CENTER, MyFrame::OnJustify) | |
211 | EVT_RIBBONTOOLBAR_CLICKED(wxID_JUSTIFY_RIGHT, MyFrame::OnJustify) | |
212 | EVT_UPDATE_UI(wxID_JUSTIFY_LEFT, MyFrame::OnJustifyUpdateUI) | |
213 | EVT_UPDATE_UI(wxID_JUSTIFY_CENTER, MyFrame::OnJustifyUpdateUI) | |
214 | EVT_UPDATE_UI(wxID_JUSTIFY_RIGHT, MyFrame::OnJustifyUpdateUI) | |
3c3ead1d PC |
215 | EVT_RIBBONTOOLBAR_CLICKED(wxID_NEW, MyFrame::OnNew) |
216 | EVT_RIBBONTOOLBAR_DROPDOWN_CLICKED(wxID_NEW, MyFrame::OnNewDropdown) | |
217 | EVT_RIBBONTOOLBAR_CLICKED(wxID_PRINT, MyFrame::OnPrint) | |
218 | EVT_RIBBONTOOLBAR_DROPDOWN_CLICKED(wxID_PRINT, MyFrame::OnPrintDropdown) | |
219 | EVT_RIBBONTOOLBAR_DROPDOWN_CLICKED(wxID_REDO, MyFrame::OnRedoDropdown) | |
220 | EVT_RIBBONTOOLBAR_DROPDOWN_CLICKED(wxID_UNDO, MyFrame::OnUndoDropdown) | |
221 | EVT_RIBBONTOOLBAR_CLICKED(ID_POSITION_LEFT, MyFrame::OnPositionLeft) | |
222 | EVT_RIBBONTOOLBAR_DROPDOWN_CLICKED(ID_POSITION_LEFT, MyFrame::OnPositionLeftDropdown) | |
223 | EVT_RIBBONTOOLBAR_CLICKED(ID_POSITION_TOP, MyFrame::OnPositionTop) | |
224 | EVT_RIBBONTOOLBAR_DROPDOWN_CLICKED(ID_POSITION_TOP, MyFrame::OnPositionTopDropdown) | |
225 | EVT_BUTTON(ID_PRIMARY_COLOUR, MyFrame::OnColourGalleryButton) | |
226 | EVT_BUTTON(ID_SECONDARY_COLOUR, MyFrame::OnColourGalleryButton) | |
227 | EVT_MENU(ID_POSITION_LEFT, MyFrame::OnPositionLeftIcons) | |
228 | EVT_MENU(ID_POSITION_LEFT_LABELS, MyFrame::OnPositionLeftLabels) | |
229 | EVT_MENU(ID_POSITION_LEFT_BOTH, MyFrame::OnPositionLeftBoth) | |
230 | EVT_MENU(ID_POSITION_TOP, MyFrame::OnPositionTopLabels) | |
231 | EVT_MENU(ID_POSITION_TOP_ICONS, MyFrame::OnPositionTopIcons) | |
232 | EVT_MENU(ID_POSITION_TOP_BOTH, MyFrame::OnPositionTopBoth) | |
3603e565 | 233 | EVT_TOGGLEBUTTON(ID_TOGGLE_PANELS, MyFrame::OnTogglePanels) |
0a7ee6e0 | 234 | EVT_RIBBONPANEL_EXTBUTTON_ACTIVATED(wxID_ANY, MyFrame::OnExtButton) |
c21b99e0 | 235 | EVT_RIBBONBUTTONBAR_CLICKED(ID_REMOVE_PAGE, MyFrame::OnRemovePage) |
5c14ec26 VZ |
236 | EVT_RIBBONBUTTONBAR_CLICKED(ID_HIDE_PAGES, MyFrame::OnHidePages) |
237 | EVT_RIBBONBUTTONBAR_CLICKED(ID_SHOW_PAGES, MyFrame::OnShowPages) | |
7c70331e | 238 | EVT_RIBBONBAR_TOGGLED(wxID_ANY, MyFrame::OnRibbonBarToggled) |
3c3ead1d PC |
239 | END_EVENT_TABLE() |
240 | ||
241 | #include "align_center.xpm" | |
242 | #include "align_left.xpm" | |
243 | #include "align_right.xpm" | |
244 | #include "aui_style.xpm" | |
245 | #include "auto_crop_selection.xpm" | |
246 | #include "auto_crop_selection_small.xpm" | |
247 | #include "circle.xpm" | |
248 | #include "circle_small.xpm" | |
249 | #include "colours.xpm" | |
250 | #include "cross.xpm" | |
251 | #include "empty.xpm" | |
252 | #include "expand_selection_v.xpm" | |
253 | #include "expand_selection_h.xpm" | |
254 | #include "eye.xpm" | |
255 | #include "hexagon.xpm" | |
256 | #include "msw_style.xpm" | |
257 | #include "position_left_small.xpm" | |
258 | #include "position_top_small.xpm" | |
259 | #include "ribbon.xpm" | |
260 | #include "selection_panel.xpm" | |
261 | #include "square.xpm" | |
262 | #include "triangle.xpm" | |
263 | ||
264 | MyFrame::MyFrame() | |
265 | : wxFrame(NULL, wxID_ANY, wxT("wxRibbon Sample Application"), wxDefaultPosition, wxSize(800, 600), wxDEFAULT_FRAME_STYLE) | |
266 | { | |
7c70331e | 267 | m_ribbon = new wxRibbonBar(this); |
3c3ead1d PC |
268 | |
269 | { | |
270 | wxRibbonPage* home = new wxRibbonPage(m_ribbon, wxID_ANY, wxT("Examples"), ribbon_xpm); | |
140091e5 PC |
271 | wxRibbonPanel *toolbar_panel = new wxRibbonPanel(home, wxID_ANY, wxT("Toolbar"), |
272 | wxNullBitmap, wxDefaultPosition, wxDefaultSize, | |
0a7ee6e0 VZ |
273 | wxRIBBON_PANEL_NO_AUTO_MINIMISE | |
274 | wxRIBBON_PANEL_EXT_BUTTON); | |
3c3ead1d | 275 | wxRibbonToolBar *toolbar = new wxRibbonToolBar(toolbar_panel, ID_MAIN_TOOLBAR); |
d1bf0be0 VZ |
276 | toolbar->AddToggleTool(wxID_JUSTIFY_LEFT, align_left_xpm); |
277 | toolbar->AddToggleTool(wxID_JUSTIFY_CENTER , align_center_xpm); | |
278 | toolbar->AddToggleTool(wxID_JUSTIFY_RIGHT, align_right_xpm); | |
3c3ead1d PC |
279 | toolbar->AddSeparator(); |
280 | toolbar->AddHybridTool(wxID_NEW, wxArtProvider::GetBitmap(wxART_NEW, wxART_OTHER, wxSize(16, 15))); | |
d1bf0be0 VZ |
281 | toolbar->AddTool(wxID_OPEN, wxArtProvider::GetBitmap(wxART_FILE_OPEN, wxART_OTHER, wxSize(16, 15)), "Open something"); |
282 | toolbar->AddTool(wxID_SAVE, wxArtProvider::GetBitmap(wxART_FILE_SAVE, wxART_OTHER, wxSize(16, 15)), "Save something"); | |
283 | toolbar->AddTool(wxID_SAVEAS, wxArtProvider::GetBitmap(wxART_FILE_SAVE_AS, wxART_OTHER, wxSize(16, 15)), "Save something as ..."); | |
284 | toolbar->EnableTool(wxID_OPEN, false); | |
285 | toolbar->EnableTool(wxID_SAVE, false); | |
286 | toolbar->EnableTool(wxID_SAVEAS, false); | |
3c3ead1d PC |
287 | toolbar->AddSeparator(); |
288 | toolbar->AddDropdownTool(wxID_UNDO, wxArtProvider::GetBitmap(wxART_UNDO, wxART_OTHER, wxSize(16, 15))); | |
289 | toolbar->AddDropdownTool(wxID_REDO, wxArtProvider::GetBitmap(wxART_REDO, wxART_OTHER, wxSize(16, 15))); | |
290 | toolbar->AddSeparator(); | |
291 | toolbar->AddTool(wxID_ANY, wxArtProvider::GetBitmap(wxART_REPORT_VIEW, wxART_OTHER, wxSize(16, 15))); | |
292 | toolbar->AddTool(wxID_ANY, wxArtProvider::GetBitmap(wxART_LIST_VIEW, wxART_OTHER, wxSize(16, 15))); | |
293 | toolbar->AddSeparator(); | |
140091e5 PC |
294 | toolbar->AddHybridTool(ID_POSITION_LEFT, position_left_xpm, |
295 | "Align ribbonbar vertically\non the left\nfor demonstration purposes"); | |
296 | toolbar->AddHybridTool(ID_POSITION_TOP, position_top_xpm, | |
297 | "Align the ribbonbar horizontally\nat the top\nfor demonstration purposes"); | |
3c3ead1d | 298 | toolbar->AddSeparator(); |
140091e5 PC |
299 | toolbar->AddHybridTool(wxID_PRINT, wxArtProvider::GetBitmap(wxART_PRINT, wxART_OTHER, wxSize(16, 15)), |
300 | "This is the Print button tooltip\ndemonstrating a tooltip"); | |
3c3ead1d PC |
301 | toolbar->SetRows(2, 3); |
302 | ||
303 | wxRibbonPanel *selection_panel = new wxRibbonPanel(home, wxID_ANY, wxT("Selection"), wxBitmap(selection_panel_xpm)); | |
304 | wxRibbonButtonBar *selection = new wxRibbonButtonBar(selection_panel); | |
140091e5 PC |
305 | selection->AddButton(ID_SELECTION_EXPAND_V, wxT("Expand Vertically"), wxBitmap(expand_selection_v_xpm), |
306 | "This is a tooltip for Expand Vertically\ndemonstrating a tooltip"); | |
3c3ead1d PC |
307 | selection->AddButton(ID_SELECTION_EXPAND_H, wxT("Expand Horizontally"), wxBitmap(expand_selection_h_xpm), wxEmptyString); |
308 | selection->AddButton(ID_SELECTION_CONTRACT, wxT("Contract"), wxBitmap(auto_crop_selection_xpm), wxBitmap(auto_crop_selection_small_xpm)); | |
309 | ||
310 | wxRibbonPanel *shapes_panel = new wxRibbonPanel(home, wxID_ANY, wxT("Shapes"), wxBitmap(circle_small_xpm)); | |
311 | wxRibbonButtonBar *shapes = new wxRibbonButtonBar(shapes_panel); | |
140091e5 PC |
312 | shapes->AddButton(ID_CIRCLE, wxT("Circle"), wxBitmap(circle_xpm), wxBitmap(circle_small_xpm), |
313 | wxNullBitmap, wxNullBitmap, wxRIBBON_BUTTON_NORMAL, | |
314 | "This is a tooltip for the circle button\ndemonstrating another tooltip"); | |
3c3ead1d PC |
315 | shapes->AddButton(ID_CROSS, wxT("Cross"), wxBitmap(cross_xpm), wxEmptyString); |
316 | shapes->AddHybridButton(ID_TRIANGLE, wxT("Triangle"), wxBitmap(triangle_xpm)); | |
317 | shapes->AddButton(ID_SQUARE, wxT("Square"), wxBitmap(square_xpm), wxEmptyString); | |
318 | shapes->AddDropdownButton(ID_POLYGON, wxT("Other Polygon"), wxBitmap(hexagon_xpm), wxEmptyString); | |
319 | ||
140091e5 PC |
320 | wxRibbonPanel *sizer_panel = new wxRibbonPanel(home, wxID_ANY, wxT("Panel with Sizer"), |
321 | wxNullBitmap, wxDefaultPosition, wxDefaultSize, | |
322 | wxRIBBON_PANEL_DEFAULT_STYLE); | |
66ddc77b RR |
323 | |
324 | wxArrayString as; | |
140091e5 PC |
325 | as.Add("Item 1 using a box sizer now"); |
326 | as.Add("Item 2 using a box sizer now"); | |
327 | wxComboBox* sizer_panelcombo = new wxComboBox(sizer_panel, wxID_ANY, | |
328 | wxEmptyString, | |
329 | wxDefaultPosition, wxDefaultSize, | |
330 | as, wxCB_READONLY); | |
ce00f59b | 331 | |
140091e5 PC |
332 | wxComboBox* sizer_panelcombo2 = new wxComboBox(sizer_panel, wxID_ANY, |
333 | wxEmptyString, | |
334 | wxDefaultPosition, wxDefaultSize, | |
335 | as, wxCB_READONLY); | |
336 | ||
337 | sizer_panelcombo->Select(0); | |
338 | sizer_panelcombo2->Select(1); | |
66ddc77b RR |
339 | sizer_panelcombo->SetMinSize(wxSize(150, -1)); |
340 | sizer_panelcombo2->SetMinSize(wxSize(150, -1)); | |
341 | ||
140091e5 PC |
342 | //not using wxWrapSizer(wxHORIZONTAL) as it reports an incorrect min height |
343 | wxSizer* sizer_panelsizer = new wxBoxSizer(wxVERTICAL); | |
344 | sizer_panelsizer->AddStretchSpacer(1); | |
345 | sizer_panelsizer->Add(sizer_panelcombo, 0, wxALL|wxEXPAND, 2); | |
346 | sizer_panelsizer->Add(sizer_panelcombo2, 0, wxALL|wxEXPAND, 2); | |
347 | sizer_panelsizer->AddStretchSpacer(1); | |
66ddc77b RR |
348 | sizer_panel->SetSizer(sizer_panelsizer); |
349 | ||
3c3ead1d PC |
350 | wxFont label_font(8, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_LIGHT); |
351 | m_bitmap_creation_dc.SetFont(label_font); | |
352 | ||
353 | wxRibbonPage* scheme = new wxRibbonPage(m_ribbon, wxID_ANY, wxT("Appearance"), eye_xpm); | |
354 | m_ribbon->GetArtProvider()->GetColourScheme(&m_default_primary, | |
355 | &m_default_secondary, &m_default_tertiary); | |
356 | wxRibbonPanel *provider_panel = new wxRibbonPanel(scheme, wxID_ANY, | |
357 | wxT("Art"), wxNullBitmap, wxDefaultPosition, wxDefaultSize, wxRIBBON_PANEL_NO_AUTO_MINIMISE); | |
358 | wxRibbonButtonBar *provider_bar = new wxRibbonButtonBar(provider_panel, wxID_ANY); | |
359 | provider_bar->AddButton(ID_DEFAULT_PROVIDER, wxT("Default Provider"), | |
360 | wxArtProvider::GetBitmap(wxART_QUESTION, wxART_OTHER, wxSize(32, 32))); | |
361 | provider_bar->AddButton(ID_AUI_PROVIDER, wxT("AUI Provider"), aui_style_xpm); | |
362 | provider_bar->AddButton(ID_MSW_PROVIDER, wxT("MSW Provider"), msw_style_xpm); | |
363 | wxRibbonPanel *primary_panel = new wxRibbonPanel(scheme, wxID_ANY, | |
364 | wxT("Primary Colour"), colours_xpm); | |
365 | m_primary_gallery = PopulateColoursPanel(primary_panel, | |
366 | m_default_primary, ID_PRIMARY_COLOUR); | |
367 | wxRibbonPanel *secondary_panel = new wxRibbonPanel(scheme, wxID_ANY, | |
368 | wxT("Secondary Colour"), colours_xpm); | |
369 | m_secondary_gallery = PopulateColoursPanel(secondary_panel, | |
370 | m_default_secondary, ID_SECONDARY_COLOUR); | |
371 | } | |
f01e5624 VZ |
372 | { |
373 | wxRibbonPage* page = new wxRibbonPage(m_ribbon, wxID_ANY, wxT("UI Updated"), ribbon_xpm); | |
374 | wxRibbonPanel *panel = new wxRibbonPanel(page, wxID_ANY, wxT("Enable/Disable"), ribbon_xpm); | |
375 | wxRibbonButtonBar *bar = new wxRibbonButtonBar(panel, wxID_ANY); | |
376 | bar->AddButton(ID_DISABLED, wxT("Disabled"), ribbon_xpm); | |
377 | bar->AddButton(ID_ENABLE, wxT("Enable"), ribbon_xpm); | |
378 | bar->AddButton(ID_DISABLE, wxT("Disable"), ribbon_xpm); | |
379 | bar->AddButton(ID_UI_ENABLE_UPDATED, wxT("Enable UI updated"), ribbon_xpm); | |
380 | bar->EnableButton(ID_DISABLED, false); | |
381 | m_bEnabled = true; | |
382 | ||
383 | panel = new wxRibbonPanel(page, wxID_ANY, wxT("Toggle"), ribbon_xpm); | |
384 | bar = new wxRibbonButtonBar(panel, wxID_ANY); | |
385 | bar->AddButton(ID_CHECK, wxT("Toggle"), ribbon_xpm); | |
386 | bar->AddToggleButton(ID_UI_CHECK_UPDATED, wxT("Toggled UI updated"), ribbon_xpm); | |
387 | m_bChecked = true; | |
388 | ||
389 | panel = new wxRibbonPanel(page, wxID_ANY, wxT("Change text"), ribbon_xpm); | |
390 | bar = new wxRibbonButtonBar(panel, wxID_ANY); | |
391 | bar->AddButton(ID_CHANGE_TEXT1, wxT("One"), ribbon_xpm); | |
392 | bar->AddButton(ID_CHANGE_TEXT2, wxT("Two"), ribbon_xpm); | |
393 | bar->AddButton(ID_UI_CHANGE_TEXT_UPDATED, wxT("Zero"), ribbon_xpm); | |
394 | } | |
3c3ead1d | 395 | new wxRibbonPage(m_ribbon, wxID_ANY, wxT("Empty Page"), empty_xpm); |
c21b99e0 VZ |
396 | { |
397 | wxRibbonPage* page = new wxRibbonPage(m_ribbon, wxID_ANY, wxT("Another Page"), empty_xpm); | |
398 | wxRibbonPanel *panel = new wxRibbonPanel(page, wxID_ANY, wxT("Page manipulation"), ribbon_xpm); | |
399 | wxRibbonButtonBar *bar = new wxRibbonButtonBar(panel, wxID_ANY); | |
400 | bar->AddButton(ID_REMOVE_PAGE, wxT("Remove"), wxArtProvider::GetBitmap(wxART_DELETE, wxART_OTHER, wxSize(24, 24))); | |
5c14ec26 VZ |
401 | bar->AddButton(ID_HIDE_PAGES, wxT("Hide Pages"), ribbon_xpm); |
402 | bar->AddButton(ID_SHOW_PAGES, wxT("Show Pages"), ribbon_xpm); | |
c21b99e0 | 403 | } |
70f86ded VZ |
404 | new wxRibbonPage(m_ribbon, wxID_ANY, wxT("Highlight Page"), empty_xpm); |
405 | m_ribbon->AddPageHighlight(m_ribbon->GetPageCount()-1); | |
3c3ead1d PC |
406 | |
407 | m_ribbon->Realize(); | |
408 | ||
409 | m_logwindow = new wxTextCtrl(this, wxID_ANY, wxEmptyString, | |
410 | wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE | wxTE_READONLY | | |
411 | wxTE_LEFT | wxTE_BESTWRAP | wxBORDER_NONE); | |
412 | ||
3603e565 VZ |
413 | m_togglePanels = new wxToggleButton(this, ID_TOGGLE_PANELS, "&Toggle panels"); |
414 | m_togglePanels->SetValue(true); | |
415 | ||
3c3ead1d PC |
416 | wxSizer *s = new wxBoxSizer(wxVERTICAL); |
417 | ||
418 | s->Add(m_ribbon, 0, wxEXPAND); | |
419 | s->Add(m_logwindow, 1, wxEXPAND); | |
3603e565 | 420 | s->Add(m_togglePanels, wxSizerFlags().Border()); |
3c3ead1d PC |
421 | |
422 | SetSizer(s); | |
423 | } | |
424 | ||
425 | void MyFrame::SetBarStyle(long style) | |
426 | { | |
427 | m_ribbon->Freeze(); | |
428 | m_ribbon->SetWindowStyleFlag(style); | |
429 | wxBoxSizer *pTopSize = reinterpret_cast<wxBoxSizer*>(GetSizer()); | |
430 | wxRibbonToolBar *pToolbar = wxDynamicCast(FindWindow(ID_MAIN_TOOLBAR), wxRibbonToolBar); | |
431 | if(style & wxRIBBON_BAR_FLOW_VERTICAL) | |
432 | { | |
433 | m_ribbon->SetTabCtrlMargins(10, 10); | |
434 | pTopSize->SetOrientation(wxHORIZONTAL); | |
435 | if(pToolbar) | |
436 | pToolbar->SetRows(3, 5); | |
437 | } | |
438 | else | |
439 | { | |
440 | m_ribbon->SetTabCtrlMargins(50, 20); | |
441 | pTopSize->SetOrientation(wxVERTICAL); | |
442 | if(pToolbar) | |
443 | pToolbar->SetRows(2, 3); | |
444 | } | |
445 | m_ribbon->Realise(); | |
446 | Layout(); | |
447 | m_ribbon->Thaw(); | |
448 | } | |
449 | ||
450 | MyFrame::~MyFrame() | |
451 | { | |
452 | } | |
453 | ||
454 | class ColourClientData : public wxClientData | |
455 | { | |
456 | public: | |
457 | ColourClientData(const wxString& name, const wxColour& colour) | |
458 | : m_name(name), m_colour(colour) {} | |
459 | ||
460 | const wxString& GetName() const {return m_name;} | |
461 | const wxColour& GetColour() const {return m_colour;} | |
462 | ||
463 | private: | |
464 | wxString m_name; | |
465 | wxColour m_colour; | |
466 | }; | |
467 | ||
468 | wxRibbonGallery* MyFrame::PopulateColoursPanel(wxWindow* panel, | |
469 | wxColour def, int gallery_id) | |
470 | { | |
471 | wxRibbonGallery *gallery = wxDynamicCast(panel->FindWindow(gallery_id), wxRibbonGallery); | |
472 | if(gallery) | |
473 | gallery->Clear(); | |
474 | else | |
475 | gallery = new wxRibbonGallery(panel, gallery_id); | |
476 | wxMemoryDC& dc = m_bitmap_creation_dc; | |
ce00f59b | 477 | wxRibbonGalleryItem *def_item = |
3c3ead1d PC |
478 | AddColourToGallery(gallery, wxT("Default"), dc, &def); |
479 | gallery->SetSelection(def_item); | |
480 | AddColourToGallery(gallery, wxT("BLUE"), dc); | |
481 | AddColourToGallery(gallery, wxT("BLUE VIOLET"), dc); | |
482 | AddColourToGallery(gallery, wxT("BROWN"), dc); | |
483 | AddColourToGallery(gallery, wxT("CADET BLUE"), dc); | |
484 | AddColourToGallery(gallery, wxT("CORAL"), dc); | |
485 | AddColourToGallery(gallery, wxT("CYAN"), dc); | |
486 | AddColourToGallery(gallery, wxT("DARK GREEN"), dc); | |
487 | AddColourToGallery(gallery, wxT("DARK ORCHID"), dc); | |
488 | AddColourToGallery(gallery, wxT("FIREBRICK"), dc); | |
489 | AddColourToGallery(gallery, wxT("GOLD"), dc); | |
490 | AddColourToGallery(gallery, wxT("GOLDENROD"), dc); | |
491 | AddColourToGallery(gallery, wxT("GREEN"), dc); | |
492 | AddColourToGallery(gallery, wxT("INDIAN RED"), dc); | |
493 | AddColourToGallery(gallery, wxT("KHAKI"), dc); | |
494 | AddColourToGallery(gallery, wxT("LIGHT BLUE"), dc); | |
495 | AddColourToGallery(gallery, wxT("LIME GREEN"), dc); | |
496 | AddColourToGallery(gallery, wxT("MAGENTA"), dc); | |
497 | AddColourToGallery(gallery, wxT("MAROON"), dc); | |
498 | AddColourToGallery(gallery, wxT("NAVY"), dc); | |
499 | AddColourToGallery(gallery, wxT("ORANGE"), dc); | |
500 | AddColourToGallery(gallery, wxT("ORCHID"), dc); | |
501 | AddColourToGallery(gallery, wxT("PINK"), dc); | |
502 | AddColourToGallery(gallery, wxT("PLUM"), dc); | |
503 | AddColourToGallery(gallery, wxT("PURPLE"), dc); | |
504 | AddColourToGallery(gallery, wxT("RED"), dc); | |
505 | AddColourToGallery(gallery, wxT("SALMON"), dc); | |
506 | AddColourToGallery(gallery, wxT("SEA GREEN"), dc); | |
507 | AddColourToGallery(gallery, wxT("SIENNA"), dc); | |
508 | AddColourToGallery(gallery, wxT("SKY BLUE"), dc); | |
509 | AddColourToGallery(gallery, wxT("TAN"), dc); | |
510 | AddColourToGallery(gallery, wxT("THISTLE"), dc); | |
511 | AddColourToGallery(gallery, wxT("TURQUOISE"), dc); | |
512 | AddColourToGallery(gallery, wxT("VIOLET"), dc); | |
513 | AddColourToGallery(gallery, wxT("VIOLET RED"), dc); | |
514 | AddColourToGallery(gallery, wxT("WHEAT"), dc); | |
515 | AddColourToGallery(gallery, wxT("WHITE"), dc); | |
516 | AddColourToGallery(gallery, wxT("YELLOW"), dc); | |
517 | ||
518 | return gallery; | |
519 | } | |
520 | ||
521 | wxColour MyFrame::GetGalleryColour(wxRibbonGallery *gallery, | |
522 | wxRibbonGalleryItem* item, wxString* name) | |
523 | { | |
524 | ColourClientData *data = (ColourClientData*)gallery->GetItemClientObject(item); | |
525 | if(name != NULL) | |
526 | *name = data->GetName(); | |
527 | return data->GetColour(); | |
528 | } | |
529 | ||
530 | void MyFrame::OnHoveredColourChange(wxRibbonGalleryEvent& evt) | |
531 | { | |
532 | // Set the background of the gallery to the hovered colour, or back to the | |
533 | // default if there is no longer a hovered item. | |
534 | ||
535 | wxRibbonGallery *gallery = evt.GetGallery(); | |
536 | wxRibbonArtProvider *provider = gallery->GetArtProvider(); | |
537 | ||
538 | if(evt.GetGalleryItem() != NULL) | |
539 | { | |
540 | if(provider == m_ribbon->GetArtProvider()) | |
541 | { | |
542 | provider = provider->Clone(); | |
543 | gallery->SetArtProvider(provider); | |
544 | } | |
545 | provider->SetColour(wxRIBBON_ART_GALLERY_HOVER_BACKGROUND_COLOUR, | |
546 | GetGalleryColour(evt.GetGallery(), evt.GetGalleryItem(), NULL)); | |
547 | } | |
548 | else | |
549 | { | |
550 | if(provider != m_ribbon->GetArtProvider()) | |
551 | { | |
552 | gallery->SetArtProvider(m_ribbon->GetArtProvider()); | |
553 | delete provider; | |
554 | } | |
555 | } | |
556 | } | |
557 | ||
558 | void MyFrame::OnPrimaryColourSelect(wxRibbonGalleryEvent& evt) | |
559 | { | |
560 | wxString name; | |
561 | wxColour colour = GetGalleryColour(evt.GetGallery(), evt.GetGalleryItem(), &name); | |
562 | AddText(wxT("Colour \"") + name + wxT("\" selected as primary.")); | |
563 | wxColour secondary, tertiary; | |
564 | m_ribbon->GetArtProvider()->GetColourScheme(NULL, &secondary, &tertiary); | |
565 | m_ribbon->GetArtProvider()->SetColourScheme(colour, secondary, tertiary); | |
566 | ResetGalleryArtProviders(); | |
567 | m_ribbon->Refresh(); | |
568 | } | |
569 | ||
570 | void MyFrame::OnSecondaryColourSelect(wxRibbonGalleryEvent& evt) | |
571 | { | |
572 | wxString name; | |
573 | wxColour colour = GetGalleryColour(evt.GetGallery(), evt.GetGalleryItem(), &name); | |
574 | AddText(wxT("Colour \"") + name + wxT("\" selected as secondary.")); | |
575 | wxColour primary, tertiary; | |
576 | m_ribbon->GetArtProvider()->GetColourScheme(&primary, NULL, &tertiary); | |
577 | m_ribbon->GetArtProvider()->SetColourScheme(primary, colour, tertiary); | |
578 | ResetGalleryArtProviders(); | |
579 | m_ribbon->Refresh(); | |
580 | } | |
581 | ||
582 | void MyFrame::ResetGalleryArtProviders() | |
583 | { | |
584 | if(m_primary_gallery->GetArtProvider() != m_ribbon->GetArtProvider()) | |
585 | { | |
586 | delete m_primary_gallery->GetArtProvider(); | |
587 | m_primary_gallery->SetArtProvider(m_ribbon->GetArtProvider()); | |
588 | } | |
589 | if(m_secondary_gallery->GetArtProvider() != m_ribbon->GetArtProvider()) | |
590 | { | |
591 | delete m_secondary_gallery->GetArtProvider(); | |
592 | m_secondary_gallery->SetArtProvider(m_ribbon->GetArtProvider()); | |
593 | } | |
594 | } | |
595 | ||
f01e5624 VZ |
596 | void MyFrame::OnChangeText1(wxRibbonButtonBarEvent& WXUNUSED(evt)) |
597 | { | |
598 | m_new_text = wxT("One"); | |
599 | } | |
600 | ||
601 | void MyFrame::OnChangeText2(wxRibbonButtonBarEvent& WXUNUSED(evt)) | |
602 | { | |
603 | m_new_text = wxT("Two"); | |
604 | } | |
605 | ||
606 | void MyFrame::OnEnable(wxRibbonButtonBarEvent& WXUNUSED(evt)) | |
607 | { | |
608 | m_bEnabled = true; | |
609 | } | |
610 | ||
611 | void MyFrame::OnDisable(wxRibbonButtonBarEvent& WXUNUSED(evt)) | |
612 | { | |
613 | m_bEnabled = false; | |
614 | } | |
615 | ||
616 | void MyFrame::OnCheck(wxRibbonButtonBarEvent& WXUNUSED(evt)) | |
617 | { | |
618 | m_bChecked = !m_bChecked; | |
619 | } | |
620 | ||
621 | void MyFrame::OnEnableUpdateUI(wxUpdateUIEvent& evt) | |
622 | { | |
623 | evt.Enable(m_bEnabled); | |
624 | } | |
625 | ||
626 | void MyFrame::OnCheckUpdateUI(wxUpdateUIEvent& evt) | |
627 | { | |
628 | evt.Check(m_bChecked); | |
629 | } | |
630 | ||
631 | void MyFrame::OnChangeTextUpdateUI(wxUpdateUIEvent& evt) | |
632 | { | |
633 | if ( !m_new_text.IsEmpty() ) | |
634 | { | |
635 | evt.SetText(m_new_text); | |
636 | m_new_text = wxT(""); | |
637 | } | |
638 | } | |
639 | ||
3c3ead1d PC |
640 | void MyFrame::OnSelectionExpandHButton(wxRibbonButtonBarEvent& WXUNUSED(evt)) |
641 | { | |
642 | AddText(wxT("Expand selection horizontally button clicked.")); | |
643 | } | |
644 | ||
645 | void MyFrame::OnSelectionExpandVButton(wxRibbonButtonBarEvent& WXUNUSED(evt)) | |
646 | { | |
647 | AddText(wxT("Expand selection vertically button clicked.")); | |
648 | } | |
649 | ||
650 | void MyFrame::OnSelectionContractButton(wxRibbonButtonBarEvent& WXUNUSED(evt)) | |
651 | { | |
652 | AddText(wxT("Contract selection button clicked.")); | |
653 | } | |
654 | ||
655 | void MyFrame::OnCircleButton(wxRibbonButtonBarEvent& WXUNUSED(evt)) | |
656 | { | |
657 | AddText(wxT("Circle button clicked.")); | |
658 | } | |
659 | ||
660 | void MyFrame::OnCrossButton(wxRibbonButtonBarEvent& WXUNUSED(evt)) | |
661 | { | |
662 | AddText(wxT("Cross button clicked.")); | |
663 | } | |
664 | ||
665 | void MyFrame::OnTriangleButton(wxRibbonButtonBarEvent& WXUNUSED(evt)) | |
666 | { | |
667 | AddText(wxT("Triangle button clicked.")); | |
668 | } | |
669 | ||
670 | void MyFrame::OnTriangleDropdown(wxRibbonButtonBarEvent& evt) | |
671 | { | |
672 | wxMenu menu; | |
673 | menu.Append(wxID_ANY, wxT("Equilateral")); | |
674 | menu.Append(wxID_ANY, wxT("Isosceles")); | |
675 | menu.Append(wxID_ANY, wxT("Scalene")); | |
676 | ||
677 | evt.PopupMenu(&menu); | |
678 | } | |
679 | ||
680 | void MyFrame::OnSquareButton(wxRibbonButtonBarEvent& WXUNUSED(evt)) | |
681 | { | |
682 | AddText(wxT("Square button clicked.")); | |
683 | } | |
684 | ||
685 | void MyFrame::OnPolygonDropdown(wxRibbonButtonBarEvent& evt) | |
686 | { | |
687 | wxMenu menu; | |
688 | menu.Append(wxID_ANY, wxT("Pentagon (5 sided)")); | |
689 | menu.Append(wxID_ANY, wxT("Hexagon (6 sided)")); | |
690 | menu.Append(wxID_ANY, wxT("Heptagon (7 sided)")); | |
691 | menu.Append(wxID_ANY, wxT("Octogon (8 sided)")); | |
692 | menu.Append(wxID_ANY, wxT("Nonagon (9 sided)")); | |
693 | menu.Append(wxID_ANY, wxT("Decagon (10 sided)")); | |
694 | ||
695 | evt.PopupMenu(&menu); | |
696 | } | |
697 | ||
d1bf0be0 VZ |
698 | void MyFrame::OnJustify(wxRibbonToolBarEvent& evt) |
699 | { | |
700 | long style = m_logwindow->GetWindowStyle() & | |
701 | ~(wxTE_LEFT | wxTE_CENTER | wxTE_RIGHT); | |
702 | switch(evt.GetId()) | |
703 | { | |
704 | case wxID_JUSTIFY_LEFT: | |
705 | m_logwindow->SetWindowStyle(style | wxTE_LEFT); | |
706 | break; | |
707 | case wxID_JUSTIFY_CENTER: | |
708 | m_logwindow->SetWindowStyle(style | wxTE_CENTER); | |
709 | break; | |
710 | case wxID_JUSTIFY_RIGHT: | |
711 | m_logwindow->SetWindowStyle(style | wxTE_RIGHT); | |
712 | break; | |
713 | } | |
714 | } | |
715 | ||
716 | void MyFrame::OnJustifyUpdateUI(wxUpdateUIEvent& evt) | |
717 | { | |
718 | switch(evt.GetId()) | |
719 | { | |
720 | case wxID_JUSTIFY_LEFT: | |
721 | evt.Check(!m_logwindow->HasFlag(wxTE_CENTER | wxTE_RIGHT)); | |
722 | break; | |
723 | case wxID_JUSTIFY_CENTER: | |
724 | evt.Check(m_logwindow->HasFlag(wxTE_CENTER)); | |
725 | break; | |
726 | case wxID_JUSTIFY_RIGHT: | |
727 | evt.Check(m_logwindow->HasFlag(wxTE_RIGHT)); | |
728 | break; | |
729 | } | |
730 | } | |
731 | ||
3c3ead1d PC |
732 | void MyFrame::OnNew(wxRibbonToolBarEvent& WXUNUSED(evt)) |
733 | { | |
734 | AddText(wxT("New button clicked.")); | |
735 | } | |
736 | ||
737 | void MyFrame::OnNewDropdown(wxRibbonToolBarEvent& evt) | |
738 | { | |
739 | wxMenu menu; | |
740 | menu.Append(wxID_ANY, wxT("New Document")); | |
741 | menu.Append(wxID_ANY, wxT("New Template")); | |
742 | menu.Append(wxID_ANY, wxT("New Mail")); | |
743 | ||
744 | evt.PopupMenu(&menu); | |
745 | } | |
746 | ||
747 | void MyFrame::OnPrint(wxRibbonToolBarEvent& WXUNUSED(evt)) | |
748 | { | |
749 | AddText(wxT("Print button clicked.")); | |
750 | } | |
751 | ||
752 | void MyFrame::OnPrintDropdown(wxRibbonToolBarEvent& evt) | |
753 | { | |
754 | wxMenu menu; | |
755 | menu.Append(wxID_ANY, wxT("Print")); | |
756 | menu.Append(wxID_ANY, wxT("Preview")); | |
757 | menu.Append(wxID_ANY, wxT("Options")); | |
758 | ||
759 | evt.PopupMenu(&menu); | |
760 | } | |
761 | ||
762 | void MyFrame::OnRedoDropdown(wxRibbonToolBarEvent& evt) | |
763 | { | |
764 | wxMenu menu; | |
765 | menu.Append(wxID_ANY, wxT("Redo E")); | |
766 | menu.Append(wxID_ANY, wxT("Redo F")); | |
767 | menu.Append(wxID_ANY, wxT("Redo G")); | |
768 | ||
769 | evt.PopupMenu(&menu); | |
770 | } | |
771 | ||
772 | void MyFrame::OnUndoDropdown(wxRibbonToolBarEvent& evt) | |
773 | { | |
774 | wxMenu menu; | |
775 | menu.Append(wxID_ANY, wxT("Undo C")); | |
776 | menu.Append(wxID_ANY, wxT("Undo B")); | |
777 | menu.Append(wxID_ANY, wxT("Undo A")); | |
778 | ||
779 | evt.PopupMenu(&menu); | |
780 | } | |
781 | ||
782 | void MyFrame::OnPositionTopLabels(wxCommandEvent& WXUNUSED(evt)) | |
783 | { | |
784 | SetBarStyle(wxRIBBON_BAR_DEFAULT_STYLE); | |
785 | } | |
786 | ||
787 | void MyFrame::OnPositionTopIcons(wxCommandEvent& WXUNUSED(evt)) | |
788 | { | |
789 | SetBarStyle((wxRIBBON_BAR_DEFAULT_STYLE &~wxRIBBON_BAR_SHOW_PAGE_LABELS) | |
790 | | wxRIBBON_BAR_SHOW_PAGE_ICONS); | |
791 | } | |
792 | ||
793 | void MyFrame::OnPositionTopBoth(wxCommandEvent& WXUNUSED(evt)) | |
794 | { | |
795 | SetBarStyle(wxRIBBON_BAR_DEFAULT_STYLE | wxRIBBON_BAR_SHOW_PAGE_ICONS); | |
796 | } | |
797 | ||
798 | void MyFrame::OnPositionLeftLabels(wxCommandEvent& WXUNUSED(evt)) | |
799 | { | |
800 | SetBarStyle(wxRIBBON_BAR_DEFAULT_STYLE | wxRIBBON_BAR_FLOW_VERTICAL); | |
801 | } | |
802 | ||
803 | void MyFrame::OnPositionLeftIcons(wxCommandEvent& WXUNUSED(evt)) | |
804 | { | |
805 | SetBarStyle((wxRIBBON_BAR_DEFAULT_STYLE &~wxRIBBON_BAR_SHOW_PAGE_LABELS) | | |
806 | wxRIBBON_BAR_SHOW_PAGE_ICONS | wxRIBBON_BAR_FLOW_VERTICAL); | |
807 | } | |
808 | ||
809 | void MyFrame::OnPositionLeftBoth(wxCommandEvent& WXUNUSED(evt)) | |
810 | { | |
811 | SetBarStyle(wxRIBBON_BAR_DEFAULT_STYLE | wxRIBBON_BAR_SHOW_PAGE_ICONS | | |
812 | wxRIBBON_BAR_FLOW_VERTICAL); | |
813 | } | |
814 | ||
815 | void MyFrame::OnPositionTop(wxRibbonToolBarEvent& evt) | |
816 | { | |
817 | OnPositionTopLabels(evt); | |
818 | } | |
819 | ||
820 | void MyFrame::OnPositionTopDropdown(wxRibbonToolBarEvent& evt) | |
821 | { | |
822 | wxMenu menu; | |
823 | menu.Append(ID_POSITION_TOP, wxT("Top with Labels")); | |
824 | menu.Append(ID_POSITION_TOP_ICONS, wxT("Top with Icons")); | |
825 | menu.Append(ID_POSITION_TOP_BOTH, wxT("Top with Both")); | |
826 | evt.PopupMenu(&menu); | |
827 | } | |
828 | ||
829 | void MyFrame::OnPositionLeft(wxRibbonToolBarEvent& evt) | |
830 | { | |
831 | OnPositionLeftIcons(evt); | |
832 | } | |
833 | ||
834 | void MyFrame::OnPositionLeftDropdown(wxRibbonToolBarEvent& evt) | |
835 | { | |
836 | wxMenu menu; | |
837 | menu.Append(ID_POSITION_LEFT, wxT("Left with Icons")); | |
838 | menu.Append(ID_POSITION_LEFT_LABELS, wxT("Left with Labels")); | |
839 | menu.Append(ID_POSITION_LEFT_BOTH, wxT("Left with Both")); | |
840 | evt.PopupMenu(&menu); | |
841 | } | |
842 | ||
3603e565 VZ |
843 | void MyFrame::OnTogglePanels(wxCommandEvent& WXUNUSED(evt)) |
844 | { | |
845 | m_ribbon->ShowPanels(m_togglePanels->GetValue()); | |
846 | } | |
847 | ||
0a7ee6e0 VZ |
848 | void MyFrame::OnExtButton(wxRibbonPanelEvent& WXUNUSED(evt)) |
849 | { | |
850 | wxMessageBox("Extension button clicked"); | |
851 | } | |
852 | ||
3c3ead1d PC |
853 | void MyFrame::AddText(wxString msg) |
854 | { | |
855 | m_logwindow->AppendText(msg); | |
856 | m_logwindow->AppendText(wxT("\n")); | |
857 | m_ribbon->DismissExpandedPanel(); | |
858 | } | |
859 | ||
860 | wxRibbonGalleryItem* MyFrame::AddColourToGallery(wxRibbonGallery *gallery, | |
861 | wxString colour, wxMemoryDC& dc, | |
862 | wxColour* value) | |
863 | { | |
864 | wxRibbonGalleryItem* item = NULL; | |
8536ce5b PC |
865 | wxColour c; |
866 | if (colour != wxT("Default")) | |
867 | c = wxColour(colour); | |
868 | if (!c.IsOk()) | |
3c3ead1d PC |
869 | c = *value; |
870 | if(c.IsOk()) | |
871 | { | |
872 | const int iWidth = 64; | |
873 | const int iHeight = 40; | |
874 | ||
875 | wxBitmap bitmap(iWidth, iHeight); | |
876 | dc.SelectObject(bitmap); | |
877 | wxBrush b(c); | |
878 | dc.SetPen(*wxBLACK_PEN); | |
879 | dc.SetBrush(b); | |
880 | dc.DrawRectangle(0, 0, iWidth, iHeight); | |
881 | ||
882 | colour = colour.Mid(0, 1) + colour.Mid(1).Lower(); | |
883 | wxSize size = dc.GetTextExtent(colour); | |
884 | wxColour foreground = wxColour(~c.Red(), ~c.Green(), ~c.Blue()); | |
885 | if(abs(foreground.Red() - c.Red()) + abs(foreground.Blue() - c.Blue()) | |
886 | + abs(foreground.Green() - c.Green()) < 64) | |
887 | { | |
888 | // Foreground too similar to background - use a different | |
889 | // strategy to find a contrasting colour | |
890 | foreground = wxColour((c.Red() + 64) % 256, 255 - c.Green(), | |
891 | (c.Blue() + 192) % 256); | |
892 | } | |
893 | dc.SetTextForeground(foreground); | |
894 | dc.DrawText(colour, (iWidth - size.GetWidth() + 1) / 2, | |
895 | (iHeight - size.GetHeight()) / 2); | |
896 | dc.SelectObjectAsSource(wxNullBitmap); | |
897 | ||
898 | item = gallery->Append(bitmap, wxID_ANY); | |
899 | gallery->SetItemClientObject(item, new ColourClientData(colour, c)); | |
900 | } | |
901 | return item; | |
902 | } | |
903 | ||
904 | void MyFrame::OnColourGalleryButton(wxCommandEvent& evt) | |
905 | { | |
906 | wxRibbonGallery *gallery = wxDynamicCast(evt.GetEventObject(), wxRibbonGallery); | |
907 | if(gallery == NULL) | |
908 | return; | |
909 | ||
910 | m_ribbon->DismissExpandedPanel(); | |
911 | if(gallery->GetSelection()) | |
912 | m_colour_data.SetColour(GetGalleryColour(gallery, gallery->GetSelection(), NULL)); | |
913 | wxColourDialog dlg(this, &m_colour_data); | |
914 | if(dlg.ShowModal() == wxID_OK) | |
915 | { | |
916 | m_colour_data = dlg.GetColourData(); | |
917 | wxColour clr = m_colour_data.GetColour(); | |
918 | ||
919 | // Try to find colour in gallery | |
920 | wxRibbonGalleryItem *item = NULL; | |
921 | for(unsigned int i = 0; i < gallery->GetCount(); ++i) | |
922 | { | |
923 | item = gallery->GetItem(i); | |
924 | if(GetGalleryColour(gallery, item, NULL) == clr) | |
925 | break; | |
926 | else | |
927 | item = NULL; | |
928 | } | |
929 | ||
930 | // Colour not in gallery - add it | |
931 | if(item == NULL) | |
932 | { | |
933 | item = AddColourToGallery(gallery, | |
934 | clr.GetAsString(wxC2S_HTML_SYNTAX), m_bitmap_creation_dc, | |
935 | &clr); | |
936 | gallery->Realise(); | |
937 | } | |
938 | ||
939 | // Set selection | |
940 | gallery->EnsureVisible(item); | |
941 | gallery->SetSelection(item); | |
942 | ||
943 | // Send an event to respond to the selection change | |
944 | wxRibbonGalleryEvent dummy(wxEVT_COMMAND_RIBBONGALLERY_SELECTED, gallery->GetId()); | |
945 | dummy.SetEventObject(gallery); | |
946 | dummy.SetGallery(gallery); | |
947 | dummy.SetGalleryItem(item); | |
948 | ProcessWindowEvent(dummy); | |
949 | } | |
950 | } | |
951 | ||
952 | void MyFrame::OnDefaultProvider(wxRibbonButtonBarEvent& WXUNUSED(evt)) | |
953 | { | |
954 | m_ribbon->DismissExpandedPanel(); | |
955 | SetArtProvider(new wxRibbonDefaultArtProvider); | |
956 | } | |
957 | ||
958 | void MyFrame::OnAUIProvider(wxRibbonButtonBarEvent& WXUNUSED(evt)) | |
959 | { | |
960 | m_ribbon->DismissExpandedPanel(); | |
961 | SetArtProvider(new wxRibbonAUIArtProvider); | |
962 | } | |
963 | ||
964 | void MyFrame::OnMSWProvider(wxRibbonButtonBarEvent& WXUNUSED(evt)) | |
965 | { | |
966 | m_ribbon->DismissExpandedPanel(); | |
967 | SetArtProvider(new wxRibbonMSWArtProvider); | |
968 | } | |
969 | ||
970 | void MyFrame::SetArtProvider(wxRibbonArtProvider *prov) | |
971 | { | |
972 | m_ribbon->Freeze(); | |
973 | m_ribbon->SetArtProvider(prov); | |
974 | ||
975 | prov->GetColourScheme(&m_default_primary, &m_default_secondary, | |
976 | &m_default_tertiary); | |
977 | PopulateColoursPanel(m_primary_gallery->GetParent(), m_default_primary, | |
978 | ID_PRIMARY_COLOUR); | |
979 | PopulateColoursPanel(m_secondary_gallery->GetParent(), m_default_secondary, | |
980 | ID_SECONDARY_COLOUR); | |
981 | ||
982 | m_ribbon->Realize(); | |
983 | m_ribbon->Thaw(); | |
984 | GetSizer()->Layout(); | |
985 | } | |
c21b99e0 VZ |
986 | |
987 | void MyFrame::OnRemovePage(wxRibbonButtonBarEvent& WXUNUSED(evt)) | |
988 | { | |
989 | size_t n = m_ribbon->GetPageCount(); | |
990 | if(n > 0) | |
991 | { | |
992 | m_ribbon->DeletePage(n-1); | |
993 | m_ribbon->Realize(); | |
994 | } | |
995 | } | |
5c14ec26 VZ |
996 | |
997 | void MyFrame::OnHidePages(wxRibbonButtonBarEvent& WXUNUSED(evt)) | |
998 | { | |
999 | m_ribbon->HidePage(1); | |
1000 | m_ribbon->HidePage(2); | |
1001 | m_ribbon->HidePage(3); | |
1002 | m_ribbon->Realize(); | |
1003 | } | |
1004 | ||
1005 | void MyFrame::OnShowPages(wxRibbonButtonBarEvent& WXUNUSED(evt)) | |
1006 | { | |
1007 | m_ribbon->ShowPage(1); | |
1008 | m_ribbon->ShowPage(2); | |
1009 | m_ribbon->ShowPage(3); | |
1010 | m_ribbon->Realize(); | |
1011 | } | |
7c70331e VZ |
1012 | |
1013 | void MyFrame::OnRibbonBarToggled(wxRibbonBarEvent& WXUNUSED(evt)) | |
1014 | { | |
1015 | AddText(wxString::Format("Ribbon bar %s.", | |
1016 | m_ribbon->ArePanelsShown() | |
1017 | ? "expanded" | |
1018 | : "collapsed")); | |
1019 | } |