]>
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 | } |
3c3ead1d PC |
404 | |
405 | m_ribbon->Realize(); | |
406 | ||
407 | m_logwindow = new wxTextCtrl(this, wxID_ANY, wxEmptyString, | |
408 | wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE | wxTE_READONLY | | |
409 | wxTE_LEFT | wxTE_BESTWRAP | wxBORDER_NONE); | |
410 | ||
3603e565 VZ |
411 | m_togglePanels = new wxToggleButton(this, ID_TOGGLE_PANELS, "&Toggle panels"); |
412 | m_togglePanels->SetValue(true); | |
413 | ||
3c3ead1d PC |
414 | wxSizer *s = new wxBoxSizer(wxVERTICAL); |
415 | ||
416 | s->Add(m_ribbon, 0, wxEXPAND); | |
417 | s->Add(m_logwindow, 1, wxEXPAND); | |
3603e565 | 418 | s->Add(m_togglePanels, wxSizerFlags().Border()); |
3c3ead1d PC |
419 | |
420 | SetSizer(s); | |
421 | } | |
422 | ||
423 | void MyFrame::SetBarStyle(long style) | |
424 | { | |
425 | m_ribbon->Freeze(); | |
426 | m_ribbon->SetWindowStyleFlag(style); | |
427 | wxBoxSizer *pTopSize = reinterpret_cast<wxBoxSizer*>(GetSizer()); | |
428 | wxRibbonToolBar *pToolbar = wxDynamicCast(FindWindow(ID_MAIN_TOOLBAR), wxRibbonToolBar); | |
429 | if(style & wxRIBBON_BAR_FLOW_VERTICAL) | |
430 | { | |
431 | m_ribbon->SetTabCtrlMargins(10, 10); | |
432 | pTopSize->SetOrientation(wxHORIZONTAL); | |
433 | if(pToolbar) | |
434 | pToolbar->SetRows(3, 5); | |
435 | } | |
436 | else | |
437 | { | |
438 | m_ribbon->SetTabCtrlMargins(50, 20); | |
439 | pTopSize->SetOrientation(wxVERTICAL); | |
440 | if(pToolbar) | |
441 | pToolbar->SetRows(2, 3); | |
442 | } | |
443 | m_ribbon->Realise(); | |
444 | Layout(); | |
445 | m_ribbon->Thaw(); | |
446 | } | |
447 | ||
448 | MyFrame::~MyFrame() | |
449 | { | |
450 | } | |
451 | ||
452 | class ColourClientData : public wxClientData | |
453 | { | |
454 | public: | |
455 | ColourClientData(const wxString& name, const wxColour& colour) | |
456 | : m_name(name), m_colour(colour) {} | |
457 | ||
458 | const wxString& GetName() const {return m_name;} | |
459 | const wxColour& GetColour() const {return m_colour;} | |
460 | ||
461 | private: | |
462 | wxString m_name; | |
463 | wxColour m_colour; | |
464 | }; | |
465 | ||
466 | wxRibbonGallery* MyFrame::PopulateColoursPanel(wxWindow* panel, | |
467 | wxColour def, int gallery_id) | |
468 | { | |
469 | wxRibbonGallery *gallery = wxDynamicCast(panel->FindWindow(gallery_id), wxRibbonGallery); | |
470 | if(gallery) | |
471 | gallery->Clear(); | |
472 | else | |
473 | gallery = new wxRibbonGallery(panel, gallery_id); | |
474 | wxMemoryDC& dc = m_bitmap_creation_dc; | |
ce00f59b | 475 | wxRibbonGalleryItem *def_item = |
3c3ead1d PC |
476 | AddColourToGallery(gallery, wxT("Default"), dc, &def); |
477 | gallery->SetSelection(def_item); | |
478 | AddColourToGallery(gallery, wxT("BLUE"), dc); | |
479 | AddColourToGallery(gallery, wxT("BLUE VIOLET"), dc); | |
480 | AddColourToGallery(gallery, wxT("BROWN"), dc); | |
481 | AddColourToGallery(gallery, wxT("CADET BLUE"), dc); | |
482 | AddColourToGallery(gallery, wxT("CORAL"), dc); | |
483 | AddColourToGallery(gallery, wxT("CYAN"), dc); | |
484 | AddColourToGallery(gallery, wxT("DARK GREEN"), dc); | |
485 | AddColourToGallery(gallery, wxT("DARK ORCHID"), dc); | |
486 | AddColourToGallery(gallery, wxT("FIREBRICK"), dc); | |
487 | AddColourToGallery(gallery, wxT("GOLD"), dc); | |
488 | AddColourToGallery(gallery, wxT("GOLDENROD"), dc); | |
489 | AddColourToGallery(gallery, wxT("GREEN"), dc); | |
490 | AddColourToGallery(gallery, wxT("INDIAN RED"), dc); | |
491 | AddColourToGallery(gallery, wxT("KHAKI"), dc); | |
492 | AddColourToGallery(gallery, wxT("LIGHT BLUE"), dc); | |
493 | AddColourToGallery(gallery, wxT("LIME GREEN"), dc); | |
494 | AddColourToGallery(gallery, wxT("MAGENTA"), dc); | |
495 | AddColourToGallery(gallery, wxT("MAROON"), dc); | |
496 | AddColourToGallery(gallery, wxT("NAVY"), dc); | |
497 | AddColourToGallery(gallery, wxT("ORANGE"), dc); | |
498 | AddColourToGallery(gallery, wxT("ORCHID"), dc); | |
499 | AddColourToGallery(gallery, wxT("PINK"), dc); | |
500 | AddColourToGallery(gallery, wxT("PLUM"), dc); | |
501 | AddColourToGallery(gallery, wxT("PURPLE"), dc); | |
502 | AddColourToGallery(gallery, wxT("RED"), dc); | |
503 | AddColourToGallery(gallery, wxT("SALMON"), dc); | |
504 | AddColourToGallery(gallery, wxT("SEA GREEN"), dc); | |
505 | AddColourToGallery(gallery, wxT("SIENNA"), dc); | |
506 | AddColourToGallery(gallery, wxT("SKY BLUE"), dc); | |
507 | AddColourToGallery(gallery, wxT("TAN"), dc); | |
508 | AddColourToGallery(gallery, wxT("THISTLE"), dc); | |
509 | AddColourToGallery(gallery, wxT("TURQUOISE"), dc); | |
510 | AddColourToGallery(gallery, wxT("VIOLET"), dc); | |
511 | AddColourToGallery(gallery, wxT("VIOLET RED"), dc); | |
512 | AddColourToGallery(gallery, wxT("WHEAT"), dc); | |
513 | AddColourToGallery(gallery, wxT("WHITE"), dc); | |
514 | AddColourToGallery(gallery, wxT("YELLOW"), dc); | |
515 | ||
516 | return gallery; | |
517 | } | |
518 | ||
519 | wxColour MyFrame::GetGalleryColour(wxRibbonGallery *gallery, | |
520 | wxRibbonGalleryItem* item, wxString* name) | |
521 | { | |
522 | ColourClientData *data = (ColourClientData*)gallery->GetItemClientObject(item); | |
523 | if(name != NULL) | |
524 | *name = data->GetName(); | |
525 | return data->GetColour(); | |
526 | } | |
527 | ||
528 | void MyFrame::OnHoveredColourChange(wxRibbonGalleryEvent& evt) | |
529 | { | |
530 | // Set the background of the gallery to the hovered colour, or back to the | |
531 | // default if there is no longer a hovered item. | |
532 | ||
533 | wxRibbonGallery *gallery = evt.GetGallery(); | |
534 | wxRibbonArtProvider *provider = gallery->GetArtProvider(); | |
535 | ||
536 | if(evt.GetGalleryItem() != NULL) | |
537 | { | |
538 | if(provider == m_ribbon->GetArtProvider()) | |
539 | { | |
540 | provider = provider->Clone(); | |
541 | gallery->SetArtProvider(provider); | |
542 | } | |
543 | provider->SetColour(wxRIBBON_ART_GALLERY_HOVER_BACKGROUND_COLOUR, | |
544 | GetGalleryColour(evt.GetGallery(), evt.GetGalleryItem(), NULL)); | |
545 | } | |
546 | else | |
547 | { | |
548 | if(provider != m_ribbon->GetArtProvider()) | |
549 | { | |
550 | gallery->SetArtProvider(m_ribbon->GetArtProvider()); | |
551 | delete provider; | |
552 | } | |
553 | } | |
554 | } | |
555 | ||
556 | void MyFrame::OnPrimaryColourSelect(wxRibbonGalleryEvent& evt) | |
557 | { | |
558 | wxString name; | |
559 | wxColour colour = GetGalleryColour(evt.GetGallery(), evt.GetGalleryItem(), &name); | |
560 | AddText(wxT("Colour \"") + name + wxT("\" selected as primary.")); | |
561 | wxColour secondary, tertiary; | |
562 | m_ribbon->GetArtProvider()->GetColourScheme(NULL, &secondary, &tertiary); | |
563 | m_ribbon->GetArtProvider()->SetColourScheme(colour, secondary, tertiary); | |
564 | ResetGalleryArtProviders(); | |
565 | m_ribbon->Refresh(); | |
566 | } | |
567 | ||
568 | void MyFrame::OnSecondaryColourSelect(wxRibbonGalleryEvent& evt) | |
569 | { | |
570 | wxString name; | |
571 | wxColour colour = GetGalleryColour(evt.GetGallery(), evt.GetGalleryItem(), &name); | |
572 | AddText(wxT("Colour \"") + name + wxT("\" selected as secondary.")); | |
573 | wxColour primary, tertiary; | |
574 | m_ribbon->GetArtProvider()->GetColourScheme(&primary, NULL, &tertiary); | |
575 | m_ribbon->GetArtProvider()->SetColourScheme(primary, colour, tertiary); | |
576 | ResetGalleryArtProviders(); | |
577 | m_ribbon->Refresh(); | |
578 | } | |
579 | ||
580 | void MyFrame::ResetGalleryArtProviders() | |
581 | { | |
582 | if(m_primary_gallery->GetArtProvider() != m_ribbon->GetArtProvider()) | |
583 | { | |
584 | delete m_primary_gallery->GetArtProvider(); | |
585 | m_primary_gallery->SetArtProvider(m_ribbon->GetArtProvider()); | |
586 | } | |
587 | if(m_secondary_gallery->GetArtProvider() != m_ribbon->GetArtProvider()) | |
588 | { | |
589 | delete m_secondary_gallery->GetArtProvider(); | |
590 | m_secondary_gallery->SetArtProvider(m_ribbon->GetArtProvider()); | |
591 | } | |
592 | } | |
593 | ||
f01e5624 VZ |
594 | void MyFrame::OnChangeText1(wxRibbonButtonBarEvent& WXUNUSED(evt)) |
595 | { | |
596 | m_new_text = wxT("One"); | |
597 | } | |
598 | ||
599 | void MyFrame::OnChangeText2(wxRibbonButtonBarEvent& WXUNUSED(evt)) | |
600 | { | |
601 | m_new_text = wxT("Two"); | |
602 | } | |
603 | ||
604 | void MyFrame::OnEnable(wxRibbonButtonBarEvent& WXUNUSED(evt)) | |
605 | { | |
606 | m_bEnabled = true; | |
607 | } | |
608 | ||
609 | void MyFrame::OnDisable(wxRibbonButtonBarEvent& WXUNUSED(evt)) | |
610 | { | |
611 | m_bEnabled = false; | |
612 | } | |
613 | ||
614 | void MyFrame::OnCheck(wxRibbonButtonBarEvent& WXUNUSED(evt)) | |
615 | { | |
616 | m_bChecked = !m_bChecked; | |
617 | } | |
618 | ||
619 | void MyFrame::OnEnableUpdateUI(wxUpdateUIEvent& evt) | |
620 | { | |
621 | evt.Enable(m_bEnabled); | |
622 | } | |
623 | ||
624 | void MyFrame::OnCheckUpdateUI(wxUpdateUIEvent& evt) | |
625 | { | |
626 | evt.Check(m_bChecked); | |
627 | } | |
628 | ||
629 | void MyFrame::OnChangeTextUpdateUI(wxUpdateUIEvent& evt) | |
630 | { | |
631 | if ( !m_new_text.IsEmpty() ) | |
632 | { | |
633 | evt.SetText(m_new_text); | |
634 | m_new_text = wxT(""); | |
635 | } | |
636 | } | |
637 | ||
3c3ead1d PC |
638 | void MyFrame::OnSelectionExpandHButton(wxRibbonButtonBarEvent& WXUNUSED(evt)) |
639 | { | |
640 | AddText(wxT("Expand selection horizontally button clicked.")); | |
641 | } | |
642 | ||
643 | void MyFrame::OnSelectionExpandVButton(wxRibbonButtonBarEvent& WXUNUSED(evt)) | |
644 | { | |
645 | AddText(wxT("Expand selection vertically button clicked.")); | |
646 | } | |
647 | ||
648 | void MyFrame::OnSelectionContractButton(wxRibbonButtonBarEvent& WXUNUSED(evt)) | |
649 | { | |
650 | AddText(wxT("Contract selection button clicked.")); | |
651 | } | |
652 | ||
653 | void MyFrame::OnCircleButton(wxRibbonButtonBarEvent& WXUNUSED(evt)) | |
654 | { | |
655 | AddText(wxT("Circle button clicked.")); | |
656 | } | |
657 | ||
658 | void MyFrame::OnCrossButton(wxRibbonButtonBarEvent& WXUNUSED(evt)) | |
659 | { | |
660 | AddText(wxT("Cross button clicked.")); | |
661 | } | |
662 | ||
663 | void MyFrame::OnTriangleButton(wxRibbonButtonBarEvent& WXUNUSED(evt)) | |
664 | { | |
665 | AddText(wxT("Triangle button clicked.")); | |
666 | } | |
667 | ||
668 | void MyFrame::OnTriangleDropdown(wxRibbonButtonBarEvent& evt) | |
669 | { | |
670 | wxMenu menu; | |
671 | menu.Append(wxID_ANY, wxT("Equilateral")); | |
672 | menu.Append(wxID_ANY, wxT("Isosceles")); | |
673 | menu.Append(wxID_ANY, wxT("Scalene")); | |
674 | ||
675 | evt.PopupMenu(&menu); | |
676 | } | |
677 | ||
678 | void MyFrame::OnSquareButton(wxRibbonButtonBarEvent& WXUNUSED(evt)) | |
679 | { | |
680 | AddText(wxT("Square button clicked.")); | |
681 | } | |
682 | ||
683 | void MyFrame::OnPolygonDropdown(wxRibbonButtonBarEvent& evt) | |
684 | { | |
685 | wxMenu menu; | |
686 | menu.Append(wxID_ANY, wxT("Pentagon (5 sided)")); | |
687 | menu.Append(wxID_ANY, wxT("Hexagon (6 sided)")); | |
688 | menu.Append(wxID_ANY, wxT("Heptagon (7 sided)")); | |
689 | menu.Append(wxID_ANY, wxT("Octogon (8 sided)")); | |
690 | menu.Append(wxID_ANY, wxT("Nonagon (9 sided)")); | |
691 | menu.Append(wxID_ANY, wxT("Decagon (10 sided)")); | |
692 | ||
693 | evt.PopupMenu(&menu); | |
694 | } | |
695 | ||
d1bf0be0 VZ |
696 | void MyFrame::OnJustify(wxRibbonToolBarEvent& evt) |
697 | { | |
698 | long style = m_logwindow->GetWindowStyle() & | |
699 | ~(wxTE_LEFT | wxTE_CENTER | wxTE_RIGHT); | |
700 | switch(evt.GetId()) | |
701 | { | |
702 | case wxID_JUSTIFY_LEFT: | |
703 | m_logwindow->SetWindowStyle(style | wxTE_LEFT); | |
704 | break; | |
705 | case wxID_JUSTIFY_CENTER: | |
706 | m_logwindow->SetWindowStyle(style | wxTE_CENTER); | |
707 | break; | |
708 | case wxID_JUSTIFY_RIGHT: | |
709 | m_logwindow->SetWindowStyle(style | wxTE_RIGHT); | |
710 | break; | |
711 | } | |
712 | } | |
713 | ||
714 | void MyFrame::OnJustifyUpdateUI(wxUpdateUIEvent& evt) | |
715 | { | |
716 | switch(evt.GetId()) | |
717 | { | |
718 | case wxID_JUSTIFY_LEFT: | |
719 | evt.Check(!m_logwindow->HasFlag(wxTE_CENTER | wxTE_RIGHT)); | |
720 | break; | |
721 | case wxID_JUSTIFY_CENTER: | |
722 | evt.Check(m_logwindow->HasFlag(wxTE_CENTER)); | |
723 | break; | |
724 | case wxID_JUSTIFY_RIGHT: | |
725 | evt.Check(m_logwindow->HasFlag(wxTE_RIGHT)); | |
726 | break; | |
727 | } | |
728 | } | |
729 | ||
3c3ead1d PC |
730 | void MyFrame::OnNew(wxRibbonToolBarEvent& WXUNUSED(evt)) |
731 | { | |
732 | AddText(wxT("New button clicked.")); | |
733 | } | |
734 | ||
735 | void MyFrame::OnNewDropdown(wxRibbonToolBarEvent& evt) | |
736 | { | |
737 | wxMenu menu; | |
738 | menu.Append(wxID_ANY, wxT("New Document")); | |
739 | menu.Append(wxID_ANY, wxT("New Template")); | |
740 | menu.Append(wxID_ANY, wxT("New Mail")); | |
741 | ||
742 | evt.PopupMenu(&menu); | |
743 | } | |
744 | ||
745 | void MyFrame::OnPrint(wxRibbonToolBarEvent& WXUNUSED(evt)) | |
746 | { | |
747 | AddText(wxT("Print button clicked.")); | |
748 | } | |
749 | ||
750 | void MyFrame::OnPrintDropdown(wxRibbonToolBarEvent& evt) | |
751 | { | |
752 | wxMenu menu; | |
753 | menu.Append(wxID_ANY, wxT("Print")); | |
754 | menu.Append(wxID_ANY, wxT("Preview")); | |
755 | menu.Append(wxID_ANY, wxT("Options")); | |
756 | ||
757 | evt.PopupMenu(&menu); | |
758 | } | |
759 | ||
760 | void MyFrame::OnRedoDropdown(wxRibbonToolBarEvent& evt) | |
761 | { | |
762 | wxMenu menu; | |
763 | menu.Append(wxID_ANY, wxT("Redo E")); | |
764 | menu.Append(wxID_ANY, wxT("Redo F")); | |
765 | menu.Append(wxID_ANY, wxT("Redo G")); | |
766 | ||
767 | evt.PopupMenu(&menu); | |
768 | } | |
769 | ||
770 | void MyFrame::OnUndoDropdown(wxRibbonToolBarEvent& evt) | |
771 | { | |
772 | wxMenu menu; | |
773 | menu.Append(wxID_ANY, wxT("Undo C")); | |
774 | menu.Append(wxID_ANY, wxT("Undo B")); | |
775 | menu.Append(wxID_ANY, wxT("Undo A")); | |
776 | ||
777 | evt.PopupMenu(&menu); | |
778 | } | |
779 | ||
780 | void MyFrame::OnPositionTopLabels(wxCommandEvent& WXUNUSED(evt)) | |
781 | { | |
782 | SetBarStyle(wxRIBBON_BAR_DEFAULT_STYLE); | |
783 | } | |
784 | ||
785 | void MyFrame::OnPositionTopIcons(wxCommandEvent& WXUNUSED(evt)) | |
786 | { | |
787 | SetBarStyle((wxRIBBON_BAR_DEFAULT_STYLE &~wxRIBBON_BAR_SHOW_PAGE_LABELS) | |
788 | | wxRIBBON_BAR_SHOW_PAGE_ICONS); | |
789 | } | |
790 | ||
791 | void MyFrame::OnPositionTopBoth(wxCommandEvent& WXUNUSED(evt)) | |
792 | { | |
793 | SetBarStyle(wxRIBBON_BAR_DEFAULT_STYLE | wxRIBBON_BAR_SHOW_PAGE_ICONS); | |
794 | } | |
795 | ||
796 | void MyFrame::OnPositionLeftLabels(wxCommandEvent& WXUNUSED(evt)) | |
797 | { | |
798 | SetBarStyle(wxRIBBON_BAR_DEFAULT_STYLE | wxRIBBON_BAR_FLOW_VERTICAL); | |
799 | } | |
800 | ||
801 | void MyFrame::OnPositionLeftIcons(wxCommandEvent& WXUNUSED(evt)) | |
802 | { | |
803 | SetBarStyle((wxRIBBON_BAR_DEFAULT_STYLE &~wxRIBBON_BAR_SHOW_PAGE_LABELS) | | |
804 | wxRIBBON_BAR_SHOW_PAGE_ICONS | wxRIBBON_BAR_FLOW_VERTICAL); | |
805 | } | |
806 | ||
807 | void MyFrame::OnPositionLeftBoth(wxCommandEvent& WXUNUSED(evt)) | |
808 | { | |
809 | SetBarStyle(wxRIBBON_BAR_DEFAULT_STYLE | wxRIBBON_BAR_SHOW_PAGE_ICONS | | |
810 | wxRIBBON_BAR_FLOW_VERTICAL); | |
811 | } | |
812 | ||
813 | void MyFrame::OnPositionTop(wxRibbonToolBarEvent& evt) | |
814 | { | |
815 | OnPositionTopLabels(evt); | |
816 | } | |
817 | ||
818 | void MyFrame::OnPositionTopDropdown(wxRibbonToolBarEvent& evt) | |
819 | { | |
820 | wxMenu menu; | |
821 | menu.Append(ID_POSITION_TOP, wxT("Top with Labels")); | |
822 | menu.Append(ID_POSITION_TOP_ICONS, wxT("Top with Icons")); | |
823 | menu.Append(ID_POSITION_TOP_BOTH, wxT("Top with Both")); | |
824 | evt.PopupMenu(&menu); | |
825 | } | |
826 | ||
827 | void MyFrame::OnPositionLeft(wxRibbonToolBarEvent& evt) | |
828 | { | |
829 | OnPositionLeftIcons(evt); | |
830 | } | |
831 | ||
832 | void MyFrame::OnPositionLeftDropdown(wxRibbonToolBarEvent& evt) | |
833 | { | |
834 | wxMenu menu; | |
835 | menu.Append(ID_POSITION_LEFT, wxT("Left with Icons")); | |
836 | menu.Append(ID_POSITION_LEFT_LABELS, wxT("Left with Labels")); | |
837 | menu.Append(ID_POSITION_LEFT_BOTH, wxT("Left with Both")); | |
838 | evt.PopupMenu(&menu); | |
839 | } | |
840 | ||
3603e565 VZ |
841 | void MyFrame::OnTogglePanels(wxCommandEvent& WXUNUSED(evt)) |
842 | { | |
843 | m_ribbon->ShowPanels(m_togglePanels->GetValue()); | |
844 | } | |
845 | ||
0a7ee6e0 VZ |
846 | void MyFrame::OnExtButton(wxRibbonPanelEvent& WXUNUSED(evt)) |
847 | { | |
848 | wxMessageBox("Extension button clicked"); | |
849 | } | |
850 | ||
3c3ead1d PC |
851 | void MyFrame::AddText(wxString msg) |
852 | { | |
853 | m_logwindow->AppendText(msg); | |
854 | m_logwindow->AppendText(wxT("\n")); | |
855 | m_ribbon->DismissExpandedPanel(); | |
856 | } | |
857 | ||
858 | wxRibbonGalleryItem* MyFrame::AddColourToGallery(wxRibbonGallery *gallery, | |
859 | wxString colour, wxMemoryDC& dc, | |
860 | wxColour* value) | |
861 | { | |
862 | wxRibbonGalleryItem* item = NULL; | |
8536ce5b PC |
863 | wxColour c; |
864 | if (colour != wxT("Default")) | |
865 | c = wxColour(colour); | |
866 | if (!c.IsOk()) | |
3c3ead1d PC |
867 | c = *value; |
868 | if(c.IsOk()) | |
869 | { | |
870 | const int iWidth = 64; | |
871 | const int iHeight = 40; | |
872 | ||
873 | wxBitmap bitmap(iWidth, iHeight); | |
874 | dc.SelectObject(bitmap); | |
875 | wxBrush b(c); | |
876 | dc.SetPen(*wxBLACK_PEN); | |
877 | dc.SetBrush(b); | |
878 | dc.DrawRectangle(0, 0, iWidth, iHeight); | |
879 | ||
880 | colour = colour.Mid(0, 1) + colour.Mid(1).Lower(); | |
881 | wxSize size = dc.GetTextExtent(colour); | |
882 | wxColour foreground = wxColour(~c.Red(), ~c.Green(), ~c.Blue()); | |
883 | if(abs(foreground.Red() - c.Red()) + abs(foreground.Blue() - c.Blue()) | |
884 | + abs(foreground.Green() - c.Green()) < 64) | |
885 | { | |
886 | // Foreground too similar to background - use a different | |
887 | // strategy to find a contrasting colour | |
888 | foreground = wxColour((c.Red() + 64) % 256, 255 - c.Green(), | |
889 | (c.Blue() + 192) % 256); | |
890 | } | |
891 | dc.SetTextForeground(foreground); | |
892 | dc.DrawText(colour, (iWidth - size.GetWidth() + 1) / 2, | |
893 | (iHeight - size.GetHeight()) / 2); | |
894 | dc.SelectObjectAsSource(wxNullBitmap); | |
895 | ||
896 | item = gallery->Append(bitmap, wxID_ANY); | |
897 | gallery->SetItemClientObject(item, new ColourClientData(colour, c)); | |
898 | } | |
899 | return item; | |
900 | } | |
901 | ||
902 | void MyFrame::OnColourGalleryButton(wxCommandEvent& evt) | |
903 | { | |
904 | wxRibbonGallery *gallery = wxDynamicCast(evt.GetEventObject(), wxRibbonGallery); | |
905 | if(gallery == NULL) | |
906 | return; | |
907 | ||
908 | m_ribbon->DismissExpandedPanel(); | |
909 | if(gallery->GetSelection()) | |
910 | m_colour_data.SetColour(GetGalleryColour(gallery, gallery->GetSelection(), NULL)); | |
911 | wxColourDialog dlg(this, &m_colour_data); | |
912 | if(dlg.ShowModal() == wxID_OK) | |
913 | { | |
914 | m_colour_data = dlg.GetColourData(); | |
915 | wxColour clr = m_colour_data.GetColour(); | |
916 | ||
917 | // Try to find colour in gallery | |
918 | wxRibbonGalleryItem *item = NULL; | |
919 | for(unsigned int i = 0; i < gallery->GetCount(); ++i) | |
920 | { | |
921 | item = gallery->GetItem(i); | |
922 | if(GetGalleryColour(gallery, item, NULL) == clr) | |
923 | break; | |
924 | else | |
925 | item = NULL; | |
926 | } | |
927 | ||
928 | // Colour not in gallery - add it | |
929 | if(item == NULL) | |
930 | { | |
931 | item = AddColourToGallery(gallery, | |
932 | clr.GetAsString(wxC2S_HTML_SYNTAX), m_bitmap_creation_dc, | |
933 | &clr); | |
934 | gallery->Realise(); | |
935 | } | |
936 | ||
937 | // Set selection | |
938 | gallery->EnsureVisible(item); | |
939 | gallery->SetSelection(item); | |
940 | ||
941 | // Send an event to respond to the selection change | |
942 | wxRibbonGalleryEvent dummy(wxEVT_COMMAND_RIBBONGALLERY_SELECTED, gallery->GetId()); | |
943 | dummy.SetEventObject(gallery); | |
944 | dummy.SetGallery(gallery); | |
945 | dummy.SetGalleryItem(item); | |
946 | ProcessWindowEvent(dummy); | |
947 | } | |
948 | } | |
949 | ||
950 | void MyFrame::OnDefaultProvider(wxRibbonButtonBarEvent& WXUNUSED(evt)) | |
951 | { | |
952 | m_ribbon->DismissExpandedPanel(); | |
953 | SetArtProvider(new wxRibbonDefaultArtProvider); | |
954 | } | |
955 | ||
956 | void MyFrame::OnAUIProvider(wxRibbonButtonBarEvent& WXUNUSED(evt)) | |
957 | { | |
958 | m_ribbon->DismissExpandedPanel(); | |
959 | SetArtProvider(new wxRibbonAUIArtProvider); | |
960 | } | |
961 | ||
962 | void MyFrame::OnMSWProvider(wxRibbonButtonBarEvent& WXUNUSED(evt)) | |
963 | { | |
964 | m_ribbon->DismissExpandedPanel(); | |
965 | SetArtProvider(new wxRibbonMSWArtProvider); | |
966 | } | |
967 | ||
968 | void MyFrame::SetArtProvider(wxRibbonArtProvider *prov) | |
969 | { | |
970 | m_ribbon->Freeze(); | |
971 | m_ribbon->SetArtProvider(prov); | |
972 | ||
973 | prov->GetColourScheme(&m_default_primary, &m_default_secondary, | |
974 | &m_default_tertiary); | |
975 | PopulateColoursPanel(m_primary_gallery->GetParent(), m_default_primary, | |
976 | ID_PRIMARY_COLOUR); | |
977 | PopulateColoursPanel(m_secondary_gallery->GetParent(), m_default_secondary, | |
978 | ID_SECONDARY_COLOUR); | |
979 | ||
980 | m_ribbon->Realize(); | |
981 | m_ribbon->Thaw(); | |
982 | GetSizer()->Layout(); | |
983 | } | |
c21b99e0 VZ |
984 | |
985 | void MyFrame::OnRemovePage(wxRibbonButtonBarEvent& WXUNUSED(evt)) | |
986 | { | |
987 | size_t n = m_ribbon->GetPageCount(); | |
988 | if(n > 0) | |
989 | { | |
990 | m_ribbon->DeletePage(n-1); | |
991 | m_ribbon->Realize(); | |
992 | } | |
993 | } | |
5c14ec26 VZ |
994 | |
995 | void MyFrame::OnHidePages(wxRibbonButtonBarEvent& WXUNUSED(evt)) | |
996 | { | |
997 | m_ribbon->HidePage(1); | |
998 | m_ribbon->HidePage(2); | |
999 | m_ribbon->HidePage(3); | |
1000 | m_ribbon->Realize(); | |
1001 | } | |
1002 | ||
1003 | void MyFrame::OnShowPages(wxRibbonButtonBarEvent& WXUNUSED(evt)) | |
1004 | { | |
1005 | m_ribbon->ShowPage(1); | |
1006 | m_ribbon->ShowPage(2); | |
1007 | m_ribbon->ShowPage(3); | |
1008 | m_ribbon->Realize(); | |
1009 | } | |
7c70331e VZ |
1010 | |
1011 | void MyFrame::OnRibbonBarToggled(wxRibbonBarEvent& WXUNUSED(evt)) | |
1012 | { | |
1013 | AddText(wxString::Format("Ribbon bar %s.", | |
1014 | m_ribbon->ArePanelsShown() | |
1015 | ? "expanded" | |
1016 | : "collapsed")); | |
1017 | } |