]>
Commit | Line | Data |
---|---|---|
14d1ccd8 | 1 | ///////////////////////////////////////////////////////////////////////////// |
fc6bbc6d | 2 | // Name: toolbar.cpp |
14d1ccd8 JS |
3 | // Purpose: wxToolBar sample |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 04/01/98 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Julian Smart | |
ad9bb75f | 9 | // Licence: wxWindows licence |
14d1ccd8 JS |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
ad9bb75f VZ |
12 | // ============================================================================ |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
19 | ||
14d1ccd8 | 20 | // For compilers that support precompilation, includes "wx/wx.h". |
92a19c2e | 21 | #include "wx/wxprec.h" |
14d1ccd8 JS |
22 | |
23 | #ifdef __BORLANDC__ | |
ad9bb75f | 24 | #pragma hdrstop |
14d1ccd8 JS |
25 | #endif |
26 | ||
27 | #ifndef WX_PRECOMP | |
ad9bb75f | 28 | #include <wx/wx.h> |
14d1ccd8 JS |
29 | #endif |
30 | ||
ad9bb75f | 31 | #include <wx/toolbar.h> |
8bbe427f | 32 | #include <wx/log.h> |
40515a21 | 33 | #include <wx/image.h> |
8bbe427f | 34 | |
ad4ae6ed | 35 | // define this to 1 to use wxToolBarSimple instead of the native one |
9fb35cf1 | 36 | #define USE_GENERIC_TBAR 0 |
ad4ae6ed | 37 | |
f6bcfd97 | 38 | // define this to use XPMs everywhere (by default, BMPs are used under Win) |
0ed1d09c | 39 | // BMPs use less space, but aren't compiled into the executable on other platforms |
f6bcfd97 BP |
40 | #ifdef __WXMSW__ |
41 | #define USE_XPM_BITMAPS 0 | |
42 | #else | |
43 | #define USE_XPM_BITMAPS 1 | |
44 | #endif | |
45 | ||
ad4ae6ed VZ |
46 | #if USE_GENERIC_TBAR |
47 | #if !wxUSE_TOOLBAR_SIMPLE | |
9fb35cf1 VZ |
48 | #error wxToolBarSimple is not compiled in, set wxUSE_TOOLBAR_SIMPLE \ |
49 | to 1 in setup.h and recompile the library. | |
ad4ae6ed VZ |
50 | #else |
51 | #include <wx/tbarsmpl.h> | |
52 | #endif | |
53 | #endif // USE_GENERIC_TBAR | |
54 | ||
f6bcfd97 BP |
55 | #if USE_XPM_BITMAPS && defined(__WXMSW__) && !wxUSE_XPM_IN_MSW |
56 | #error You need to enable XPM support to use XPM bitmaps with toolbar! | |
57 | #endif // USE_XPM_BITMAPS | |
58 | ||
ad9bb75f VZ |
59 | // ---------------------------------------------------------------------------- |
60 | // resources | |
61 | // ---------------------------------------------------------------------------- | |
14d1ccd8 | 62 | |
f6bcfd97 | 63 | #if USE_XPM_BITMAPS |
ad9bb75f VZ |
64 | #include "mondrian.xpm" |
65 | #include "bitmaps/new.xpm" | |
66 | #include "bitmaps/open.xpm" | |
67 | #include "bitmaps/save.xpm" | |
68 | #include "bitmaps/copy.xpm" | |
69 | #include "bitmaps/cut.xpm" | |
5ef2e633 | 70 | #include "bitmaps/preview.xpm" // paste XPM |
ad9bb75f | 71 | #include "bitmaps/print.xpm" |
ad9bb75f | 72 | #include "bitmaps/help.xpm" |
f6bcfd97 | 73 | #endif // USE_XPM_BITMAPS |
ad9bb75f VZ |
74 | |
75 | // ---------------------------------------------------------------------------- | |
76 | // classes | |
77 | // ---------------------------------------------------------------------------- | |
78 | ||
79 | // Define a new application | |
5ef2e633 | 80 | class MyApp : public wxApp |
ad9bb75f VZ |
81 | { |
82 | public: | |
83 | bool OnInit(); | |
ad9bb75f | 84 | }; |
47908e25 | 85 | |
ad9bb75f VZ |
86 | // Define a new frame |
87 | class MyFrame: public wxFrame | |
88 | { | |
89 | public: | |
90 | MyFrame(wxFrame *parent, | |
91 | wxWindowID id = -1, | |
ab1ca7b3 | 92 | const wxString& title = _T("wxToolBar Sample"), |
ad9bb75f VZ |
93 | const wxPoint& pos = wxDefaultPosition, |
94 | const wxSize& size = wxDefaultSize, | |
229de929 | 95 | long style = wxDEFAULT_FRAME_STYLE|wxCLIP_CHILDREN|wxNO_FULL_REPAINT_ON_RESIZE); |
14d1ccd8 | 96 | |
5ef2e633 VZ |
97 | void RecreateToolbar(); |
98 | ||
ad9bb75f VZ |
99 | void OnQuit(wxCommandEvent& event); |
100 | void OnAbout(wxCommandEvent& event); | |
101 | ||
f6bcfd97 BP |
102 | void OnSize(wxSizeEvent& event); |
103 | ||
ba0abe3c | 104 | void OnToggleToolbar(wxCommandEvent& event); |
f6bcfd97 | 105 | void OnToggleAnotherToolbar(wxCommandEvent& event); |
96dc4236 | 106 | void OnToggleHorizontalText(wxCommandEvent& WXUNUSED(event)); |
f6bcfd97 | 107 | |
5ef2e633 VZ |
108 | void OnToggleToolbarSize(wxCommandEvent& event); |
109 | void OnToggleToolbarOrient(wxCommandEvent& event); | |
98066234 | 110 | void OnToggleToolbarRows(wxCommandEvent& event); |
5ef2e633 | 111 | |
ad4ae6ed VZ |
112 | void OnEnablePrint(wxCommandEvent& WXUNUSED(event)) { DoEnablePrint(); } |
113 | void OnDeletePrint(wxCommandEvent& WXUNUSED(event)) { DoDeletePrint(); } | |
bdc72a22 | 114 | void OnInsertPrint(wxCommandEvent& event); |
a1f79c1e | 115 | void OnChangeToolTip(wxCommandEvent& event); |
ad4ae6ed | 116 | void OnToggleHelp(wxCommandEvent& WXUNUSED(event)) { DoToggleHelp(); } |
3bf4189d | 117 | void OnToggleRadioBtn(wxCommandEvent& event); |
ad9bb75f | 118 | |
ec483b11 VZ |
119 | void OnToolbarStyle(wxCommandEvent& event); |
120 | ||
ad9bb75f VZ |
121 | void OnToolLeftClick(wxCommandEvent& event); |
122 | void OnToolEnter(wxCommandEvent& event); | |
123 | ||
1c383dba VZ |
124 | void OnCombo(wxCommandEvent& event); |
125 | ||
5ef2e633 | 126 | void OnUpdateCopyAndCut(wxUpdateUIEvent& event); |
96dc4236 | 127 | void OnUpdateToggleHorzText(wxUpdateUIEvent& event); |
3bf4189d VZ |
128 | void OnUpdateToggleRadioBtn(wxUpdateUIEvent& event) |
129 | { event.Enable( m_tbar != NULL ); } | |
5ef2e633 | 130 | |
ad4ae6ed VZ |
131 | #if USE_GENERIC_TBAR |
132 | virtual wxToolBar *OnCreateToolBar(long style, | |
133 | wxWindowID id, | |
134 | const wxString& name ); | |
135 | #endif // USE_GENERIC_TBAR | |
136 | ||
ad9bb75f VZ |
137 | private: |
138 | void DoEnablePrint(); | |
97d7bfb8 | 139 | void DoDeletePrint(); |
ad9bb75f VZ |
140 | void DoToggleHelp(); |
141 | ||
f6bcfd97 BP |
142 | void LayoutChildren(); |
143 | ||
5ef2e633 | 144 | bool m_smallToolbar, |
96dc4236 VZ |
145 | m_horzToolbar, |
146 | m_horzText; | |
98066234 VZ |
147 | size_t m_rows; // 1 or 2 only |
148 | ||
2b5f62a0 VZ |
149 | // the number of print buttons we have (they're added/removed dynamically) |
150 | size_t m_nPrint; | |
151 | ||
f6bcfd97 BP |
152 | wxTextCtrl *m_textWindow; |
153 | ||
154 | wxToolBar *m_tbar; | |
ad9bb75f | 155 | |
ad9bb75f VZ |
156 | DECLARE_EVENT_TABLE() |
157 | }; | |
158 | ||
159 | // ---------------------------------------------------------------------------- | |
160 | // constants | |
161 | // ---------------------------------------------------------------------------- | |
162 | ||
163 | const int ID_TOOLBAR = 500; | |
164 | ||
dd46ee66 | 165 | static const long TOOLBAR_STYLE = wxTB_FLAT | wxTB_DOCKABLE | wxTB_TEXT; |
86f65864 | 166 | |
ad9bb75f | 167 | enum |
14d1ccd8 | 168 | { |
5ef2e633 VZ |
169 | IDM_TOOLBAR_TOGGLETOOLBARSIZE = 200, |
170 | IDM_TOOLBAR_TOGGLETOOLBARORIENT, | |
98066234 | 171 | IDM_TOOLBAR_TOGGLETOOLBARROWS, |
ad9bb75f | 172 | IDM_TOOLBAR_ENABLEPRINT, |
97d7bfb8 | 173 | IDM_TOOLBAR_DELETEPRINT, |
bdc72a22 | 174 | IDM_TOOLBAR_INSERTPRINT, |
1c383dba | 175 | IDM_TOOLBAR_TOGGLEHELP, |
3bf4189d VZ |
176 | IDM_TOOLBAR_TOGGLERADIOBTN1, |
177 | IDM_TOOLBAR_TOGGLERADIOBTN2, | |
178 | IDM_TOOLBAR_TOGGLERADIOBTN3, | |
ba0abe3c | 179 | IDM_TOOLBAR_TOGGLE_TOOLBAR, |
96dc4236 | 180 | IDM_TOOLBAR_TOGGLE_HORIZONTAL_TEXT, |
f6bcfd97 | 181 | IDM_TOOLBAR_TOGGLE_ANOTHER_TOOLBAR, |
a1f79c1e | 182 | IDM_TOOLBAR_CHANGE_TOOLTIP, |
ec483b11 VZ |
183 | IDM_TOOLBAR_SHOW_TEXT, |
184 | IDM_TOOLBAR_SHOW_ICONS, | |
185 | IDM_TOOLBAR_SHOW_BOTH, | |
1c383dba | 186 | |
3bf4189d VZ |
187 | IDM_TOOLBAR_OTHER_1, |
188 | IDM_TOOLBAR_OTHER_2, | |
189 | IDM_TOOLBAR_OTHER_3, | |
190 | ||
1c383dba | 191 | ID_COMBO = 1000 |
ad9bb75f | 192 | }; |
14d1ccd8 | 193 | |
ad9bb75f VZ |
194 | // ---------------------------------------------------------------------------- |
195 | // event tables | |
196 | // ---------------------------------------------------------------------------- | |
14d1ccd8 | 197 | |
ad9bb75f VZ |
198 | // Notice that wxID_HELP will be processed for the 'About' menu and the toolbar |
199 | // help button. | |
14d1ccd8 | 200 | |
ad9bb75f | 201 | BEGIN_EVENT_TABLE(MyFrame, wxFrame) |
f6bcfd97 BP |
202 | EVT_SIZE(MyFrame::OnSize) |
203 | ||
ad9bb75f VZ |
204 | EVT_MENU(wxID_EXIT, MyFrame::OnQuit) |
205 | EVT_MENU(wxID_HELP, MyFrame::OnAbout) | |
14d1ccd8 | 206 | |
ba0abe3c | 207 | EVT_MENU(IDM_TOOLBAR_TOGGLE_TOOLBAR, MyFrame::OnToggleToolbar) |
f6bcfd97 | 208 | EVT_MENU(IDM_TOOLBAR_TOGGLE_ANOTHER_TOOLBAR, MyFrame::OnToggleAnotherToolbar) |
96dc4236 | 209 | EVT_MENU(IDM_TOOLBAR_TOGGLE_HORIZONTAL_TEXT, MyFrame::OnToggleHorizontalText) |
f6bcfd97 | 210 | |
5ef2e633 VZ |
211 | EVT_MENU(IDM_TOOLBAR_TOGGLETOOLBARSIZE, MyFrame::OnToggleToolbarSize) |
212 | EVT_MENU(IDM_TOOLBAR_TOGGLETOOLBARORIENT, MyFrame::OnToggleToolbarOrient) | |
98066234 | 213 | EVT_MENU(IDM_TOOLBAR_TOGGLETOOLBARROWS, MyFrame::OnToggleToolbarRows) |
5ef2e633 | 214 | |
ad9bb75f | 215 | EVT_MENU(IDM_TOOLBAR_ENABLEPRINT, MyFrame::OnEnablePrint) |
97d7bfb8 | 216 | EVT_MENU(IDM_TOOLBAR_DELETEPRINT, MyFrame::OnDeletePrint) |
bdc72a22 | 217 | EVT_MENU(IDM_TOOLBAR_INSERTPRINT, MyFrame::OnInsertPrint) |
ad9bb75f | 218 | EVT_MENU(IDM_TOOLBAR_TOGGLEHELP, MyFrame::OnToggleHelp) |
3bf4189d VZ |
219 | EVT_MENU_RANGE(IDM_TOOLBAR_TOGGLERADIOBTN1, IDM_TOOLBAR_TOGGLERADIOBTN3, |
220 | MyFrame::OnToggleRadioBtn) | |
a1f79c1e | 221 | EVT_MENU(IDM_TOOLBAR_CHANGE_TOOLTIP, MyFrame::OnChangeToolTip) |
14d1ccd8 | 222 | |
ec483b11 VZ |
223 | EVT_MENU_RANGE(IDM_TOOLBAR_SHOW_TEXT, IDM_TOOLBAR_SHOW_BOTH, |
224 | MyFrame::OnToolbarStyle) | |
225 | ||
ad9bb75f | 226 | EVT_MENU(-1, MyFrame::OnToolLeftClick) |
14d1ccd8 | 227 | |
1c383dba VZ |
228 | EVT_COMBOBOX(ID_COMBO, MyFrame::OnCombo) |
229 | ||
ad9bb75f | 230 | EVT_TOOL_ENTER(ID_TOOLBAR, MyFrame::OnToolEnter) |
5ef2e633 VZ |
231 | |
232 | EVT_UPDATE_UI(wxID_COPY, MyFrame::OnUpdateCopyAndCut) | |
233 | EVT_UPDATE_UI(wxID_CUT, MyFrame::OnUpdateCopyAndCut) | |
96dc4236 | 234 | |
3bf4189d VZ |
235 | EVT_UPDATE_UI_RANGE(IDM_TOOLBAR_TOGGLERADIOBTN1, |
236 | IDM_TOOLBAR_TOGGLERADIOBTN3, | |
237 | MyFrame::OnUpdateToggleRadioBtn) | |
96dc4236 VZ |
238 | EVT_UPDATE_UI(IDM_TOOLBAR_TOGGLE_HORIZONTAL_TEXT, |
239 | MyFrame::OnUpdateToggleHorzText) | |
ad9bb75f | 240 | END_EVENT_TABLE() |
14d1ccd8 | 241 | |
ad9bb75f VZ |
242 | // ============================================================================ |
243 | // implementation | |
244 | // ============================================================================ | |
14d1ccd8 | 245 | |
ad9bb75f VZ |
246 | // ---------------------------------------------------------------------------- |
247 | // MyApp | |
248 | // ---------------------------------------------------------------------------- | |
14d1ccd8 | 249 | |
ad9bb75f | 250 | IMPLEMENT_APP(MyApp) |
14d1ccd8 | 251 | |
ad9bb75f VZ |
252 | // The `main program' equivalent, creating the windows and returning the |
253 | // main frame | |
254 | bool MyApp::OnInit() | |
255 | { | |
256 | // Create the main frame window | |
257 | MyFrame* frame = new MyFrame((wxFrame *) NULL, -1, | |
ab1ca7b3 | 258 | _T("wxToolBar Sample"), |
bf95a04f | 259 | #ifdef __WXWINCE__ |
0cfc2a92 | 260 | wxDefaultPosition, wxDefaultSize |
bf95a04f JS |
261 | #else |
262 | wxPoint(100, 100), wxSize(550, 300) | |
263 | #endif | |
264 | ); | |
14d1ccd8 | 265 | |
7fb23305 VZ |
266 | frame->Show(TRUE); |
267 | ||
0cfc2a92 | 268 | #ifndef __SMARTPHONE__ |
be5a51fb | 269 | frame->SetStatusText(_T("Hello, wxWidgets")); |
0cfc2a92 | 270 | #endif |
7fb23305 VZ |
271 | |
272 | SetTopWindow(frame); | |
273 | ||
274 | return TRUE; | |
14d1ccd8 JS |
275 | } |
276 | ||
5ef2e633 | 277 | void MyFrame::RecreateToolbar() |
14d1ccd8 | 278 | { |
bf95a04f JS |
279 | #ifdef __WXWINCE__ |
280 | // On Windows CE, we should not delete the | |
281 | // previous toolbar in case it contains the menubar. | |
282 | // We'll try to accomodate this usage in due course. | |
283 | wxToolBar* toolBar = CreateToolBar(); | |
284 | #else | |
5ef2e633 | 285 | // delete and recreate the toolbar |
ad4ae6ed | 286 | wxToolBarBase *toolBar = GetToolBar(); |
ec483b11 VZ |
287 | long style = toolBar ? toolBar->GetWindowStyle() : TOOLBAR_STYLE; |
288 | ||
5ef2e633 | 289 | delete toolBar; |
14d1ccd8 | 290 | |
5ef2e633 VZ |
291 | SetToolBar(NULL); |
292 | ||
96dc4236 | 293 | style &= ~(wxTB_HORIZONTAL | wxTB_VERTICAL | wxTB_HORZ_LAYOUT); |
5ef2e633 | 294 | style |= m_horzToolbar ? wxTB_HORIZONTAL : wxTB_VERTICAL; |
96dc4236 VZ |
295 | |
296 | if ( style & wxTB_TEXT && !(style & wxTB_NOICONS) && m_horzText ) | |
297 | style |= wxTB_HORZ_LAYOUT; | |
5ef2e633 VZ |
298 | |
299 | toolBar = CreateToolBar(style, ID_TOOLBAR); | |
bf95a04f | 300 | #endif |
5ef2e633 VZ |
301 | |
302 | // Set up toolbar | |
303 | wxBitmap toolBarBitmaps[8]; | |
304 | ||
f6bcfd97 BP |
305 | #if USE_XPM_BITMAPS |
306 | toolBarBitmaps[0] = wxBitmap(new_xpm); | |
307 | toolBarBitmaps[1] = wxBitmap(open_xpm); | |
308 | toolBarBitmaps[2] = wxBitmap(save_xpm); | |
309 | toolBarBitmaps[3] = wxBitmap(copy_xpm); | |
310 | toolBarBitmaps[4] = wxBitmap(cut_xpm); | |
311 | toolBarBitmaps[5] = wxBitmap(paste_xpm); | |
312 | toolBarBitmaps[6] = wxBitmap(print_xpm); | |
313 | toolBarBitmaps[7] = wxBitmap(help_xpm); | |
314 | #else // !USE_XPM_BITMAPS | |
5ef2e633 VZ |
315 | toolBarBitmaps[0] = wxBITMAP(new); |
316 | toolBarBitmaps[1] = wxBITMAP(open); | |
40515a21 VZ |
317 | toolBarBitmaps[2] = wxBITMAP(save); |
318 | toolBarBitmaps[3] = wxBITMAP(copy); | |
319 | toolBarBitmaps[4] = wxBITMAP(cut); | |
320 | toolBarBitmaps[5] = wxBITMAP(paste); | |
321 | toolBarBitmaps[6] = wxBITMAP(print); | |
322 | toolBarBitmaps[7] = wxBITMAP(help); | |
f6bcfd97 | 323 | #endif // USE_XPM_BITMAPS/!USE_XPM_BITMAPS |
40515a21 | 324 | |
5ef2e633 VZ |
325 | if ( !m_smallToolbar ) |
326 | { | |
40515a21 VZ |
327 | int w = 2*toolBarBitmaps[0].GetWidth(), |
328 | h = 2*toolBarBitmaps[0].GetHeight(); | |
329 | for ( size_t n = 0; n < WXSIZEOF(toolBarBitmaps); n++ ) | |
330 | { | |
331 | toolBarBitmaps[n] = | |
368d59f0 | 332 | wxBitmap(toolBarBitmaps[n].ConvertToImage().Scale(w, h)); |
40515a21 VZ |
333 | } |
334 | ||
335 | toolBar->SetToolBitmapSize(wxSize(w, h)); | |
5ef2e633 | 336 | } |
14d1ccd8 | 337 | |
ec483b11 VZ |
338 | toolBar->AddTool(wxID_NEW, _T("New"), toolBarBitmaps[0], _T("New file")); |
339 | toolBar->AddTool(wxID_OPEN, _T("Open"), toolBarBitmaps[1], _T("Open file")); | |
14d1ccd8 | 340 | |
aae91497 MB |
341 | // the generic toolbar doesn't really support this |
342 | #if (wxUSE_TOOLBAR_NATIVE && !USE_GENERIC_TBAR) && !defined(__WXX11__) || defined(__WXUNIVERSAL__) | |
5ef2e633 VZ |
343 | // adding a combo to a vertical toolbar is not very smart |
344 | if ( m_horzToolbar ) | |
345 | { | |
ab1ca7b3 | 346 | wxComboBox *combo = new wxComboBox(toolBar, ID_COMBO, _T(""), wxDefaultPosition, wxSize(200,-1) ); |
2b5f62a0 VZ |
347 | combo->Append(_T("This")); |
348 | combo->Append(_T("is a")); | |
349 | combo->Append(_T("combobox")); | |
350 | combo->Append(_T("in a")); | |
351 | combo->Append(_T("toolbar")); | |
5ef2e633 VZ |
352 | toolBar->AddControl(combo); |
353 | } | |
ad4ae6ed | 354 | #endif // toolbars which don't support controls |
14d1ccd8 | 355 | |
ec483b11 VZ |
356 | toolBar->AddTool(wxID_SAVE, _T("Save"), toolBarBitmaps[2], _T("Toggle button 1"), wxITEM_CHECK); |
357 | toolBar->AddTool(wxID_COPY, _T("Copy"), toolBarBitmaps[3], _T("Toggle button 2"), wxITEM_CHECK); | |
358 | toolBar->AddTool(wxID_CUT, _T("Cut"), toolBarBitmaps[4], _T("Toggle/Untoggle help button")); | |
359 | toolBar->AddTool(wxID_PASTE, _T("Paste"), toolBarBitmaps[5], _T("Paste")); | |
256b8649 | 360 | toolBar->AddTool(wxID_PRINT, _T("Print"), toolBarBitmaps[6], _T("Delete this tool. This is a very long tooltip to test whether it does the right thing when the tooltip is more than Windows can cope with.")); |
40515a21 | 361 | toolBar->AddSeparator(); |
ec483b11 | 362 | toolBar->AddTool(wxID_HELP, _T("Help"), toolBarBitmaps[7], _T("Help button"), wxITEM_CHECK); |
13437238 | 363 | |
5ef2e633 VZ |
364 | // after adding the buttons to the toolbar, must call Realize() to reflect |
365 | // the changes | |
366 | toolBar->Realize(); | |
98066234 VZ |
367 | |
368 | toolBar->SetRows(m_horzToolbar ? m_rows : 10 / m_rows); | |
14d1ccd8 JS |
369 | } |
370 | ||
ad9bb75f VZ |
371 | // ---------------------------------------------------------------------------- |
372 | // MyFrame | |
373 | // ---------------------------------------------------------------------------- | |
13437238 JS |
374 | |
375 | // Define my frame constructor | |
7fb23305 VZ |
376 | MyFrame::MyFrame(wxFrame* parent, |
377 | wxWindowID id, | |
378 | const wxString& title, | |
379 | const wxPoint& pos, | |
380 | const wxSize& size, | |
381 | long style) | |
382 | : wxFrame(parent, id, title, pos, size, style) | |
14d1ccd8 | 383 | { |
f6bcfd97 | 384 | m_tbar = NULL; |
98066234 | 385 | |
40515a21 | 386 | m_smallToolbar = TRUE; |
98066234 | 387 | m_horzToolbar = TRUE; |
96dc4236 | 388 | m_horzText = FALSE; |
98066234 | 389 | m_rows = 1; |
2b5f62a0 | 390 | m_nPrint = 1; |
ad9bb75f | 391 | |
0cfc2a92 | 392 | #ifndef __SMARTPHONE__ |
ad9bb75f VZ |
393 | // Give it a status line |
394 | CreateStatusBar(); | |
0cfc2a92 | 395 | #endif |
ad9bb75f VZ |
396 | |
397 | // Give it an icon | |
398 | SetIcon(wxICON(mondrian)); | |
399 | ||
400 | // Make a menubar | |
401 | wxMenu *tbarMenu = new wxMenu; | |
ba0abe3c | 402 | tbarMenu->AppendCheckItem(IDM_TOOLBAR_TOGGLE_TOOLBAR, |
2b5f62a0 VZ |
403 | _T("Toggle &toolbar\tCtrl-Z"), |
404 | _T("Show or hide the toolbar")); | |
ba0abe3c VZ |
405 | |
406 | tbarMenu->AppendCheckItem(IDM_TOOLBAR_TOGGLE_ANOTHER_TOOLBAR, | |
2b5f62a0 VZ |
407 | _T("Toggle &another toolbar\tCtrl-A"), |
408 | _T("Show/hide another test toolbar")); | |
ba0abe3c | 409 | |
96dc4236 VZ |
410 | tbarMenu->AppendCheckItem(IDM_TOOLBAR_TOGGLE_HORIZONTAL_TEXT, |
411 | _T("Toggle hori&zontal text\tCtrl-H"), | |
412 | _T("Show text under/alongside the icon")); | |
413 | ||
ba0abe3c | 414 | tbarMenu->AppendCheckItem(IDM_TOOLBAR_TOGGLETOOLBARSIZE, |
2b5f62a0 VZ |
415 | _T("&Toggle toolbar size\tCtrl-S"), |
416 | _T("Toggle between big/small toolbar")); | |
ba0abe3c VZ |
417 | |
418 | tbarMenu->AppendCheckItem(IDM_TOOLBAR_TOGGLETOOLBARORIENT, | |
2b5f62a0 VZ |
419 | _T("Toggle toolbar &orientation\tCtrl-O"), |
420 | _T("Toggle toolbar orientation")); | |
ba0abe3c VZ |
421 | |
422 | tbarMenu->AppendCheckItem(IDM_TOOLBAR_TOGGLETOOLBARROWS, | |
2b5f62a0 VZ |
423 | _T("Toggle number of &rows\tCtrl-R"), |
424 | _T("Toggle number of toolbar rows between 1 and 2")); | |
5ef2e633 VZ |
425 | |
426 | tbarMenu->AppendSeparator(); | |
427 | ||
2b5f62a0 VZ |
428 | tbarMenu->Append(IDM_TOOLBAR_ENABLEPRINT, _T("&Enable print button\tCtrl-E"), _T("")); |
429 | tbarMenu->Append(IDM_TOOLBAR_DELETEPRINT, _T("&Delete print button\tCtrl-D"), _T("")); | |
430 | tbarMenu->Append(IDM_TOOLBAR_INSERTPRINT, _T("&Insert print button\tCtrl-I"), _T("")); | |
431 | tbarMenu->Append(IDM_TOOLBAR_TOGGLEHELP, _T("Toggle &help button\tCtrl-T"), _T("")); | |
a1f79c1e | 432 | tbarMenu->AppendSeparator(); |
3bf4189d VZ |
433 | tbarMenu->Append(IDM_TOOLBAR_TOGGLERADIOBTN1, _T("Toggle &1st radio button\tCtrl-1"), _T("")); |
434 | tbarMenu->Append(IDM_TOOLBAR_TOGGLERADIOBTN2, _T("Toggle &2nd radio button\tCtrl-2"), _T("")); | |
435 | tbarMenu->Append(IDM_TOOLBAR_TOGGLERADIOBTN3, _T("Toggle &3rd radio button\tCtrl-3"), _T("")); | |
436 | tbarMenu->AppendSeparator(); | |
2b5f62a0 | 437 | tbarMenu->Append(IDM_TOOLBAR_CHANGE_TOOLTIP, _T("Change tool tip"), _T("")); |
ec483b11 | 438 | tbarMenu->AppendSeparator(); |
2b5f62a0 VZ |
439 | tbarMenu->AppendRadioItem(IDM_TOOLBAR_SHOW_TEXT, _T("Show &text\tAlt-T")); |
440 | tbarMenu->AppendRadioItem(IDM_TOOLBAR_SHOW_ICONS, _T("Show &icons\tAlt-I")); | |
441 | tbarMenu->AppendRadioItem(IDM_TOOLBAR_SHOW_BOTH, _T("Show &both\tAlt-B")); | |
b487a08f | 442 | |
ad9bb75f | 443 | wxMenu *fileMenu = new wxMenu; |
2b5f62a0 | 444 | fileMenu->Append(wxID_EXIT, _T("E&xit\tAlt-X"), _T("Quit toolbar sample") ); |
ad9bb75f | 445 | |
ad9bb75f | 446 | wxMenu *helpMenu = new wxMenu; |
2b5f62a0 | 447 | helpMenu->Append(wxID_HELP, _T("&About"), _T("About toolbar sample")); |
ad9bb75f VZ |
448 | |
449 | wxMenuBar* menuBar = new wxMenuBar( wxMB_DOCKABLE ); | |
450 | ||
2b5f62a0 VZ |
451 | menuBar->Append(fileMenu, _T("&File")); |
452 | menuBar->Append(tbarMenu, _T("&Toolbar")); | |
453 | menuBar->Append(helpMenu, _T("&Help")); | |
ad9bb75f VZ |
454 | |
455 | // Associate the menu bar with the frame | |
456 | SetMenuBar(menuBar); | |
457 | ||
c631abda VZ |
458 | menuBar->Check(IDM_TOOLBAR_SHOW_BOTH, TRUE); |
459 | ||
ad9bb75f | 460 | // Create the toolbar |
5ef2e633 | 461 | RecreateToolbar(); |
949b8e62 VZ |
462 | |
463 | m_textWindow = new wxTextCtrl(this, -1, _T(""), wxPoint(0, 0), wxSize(-1, -1), wxTE_MULTILINE); | |
5ef2e633 | 464 | } |
ad9bb75f | 465 | |
ad4ae6ed VZ |
466 | #if USE_GENERIC_TBAR |
467 | ||
468 | wxToolBar* MyFrame::OnCreateToolBar(long style, | |
469 | wxWindowID id, | |
470 | const wxString& name) | |
471 | { | |
472 | return (wxToolBar *)new wxToolBarSimple(this, id, | |
473 | wxDefaultPosition, wxDefaultSize, | |
474 | style, name); | |
475 | } | |
476 | ||
477 | #endif // USE_GENERIC_TBAR | |
478 | ||
f6bcfd97 BP |
479 | void MyFrame::LayoutChildren() |
480 | { | |
481 | wxSize size = GetClientSize(); | |
482 | ||
483 | int offset; | |
484 | if ( m_tbar ) | |
485 | { | |
486 | m_tbar->SetSize(-1, size.y); | |
487 | m_tbar->Move(0, 0); | |
488 | ||
489 | offset = m_tbar->GetSize().x; | |
490 | } | |
491 | else | |
492 | { | |
493 | offset = 0; | |
494 | } | |
495 | ||
496 | m_textWindow->SetSize(offset, 0, size.x - offset, size.y); | |
497 | } | |
498 | ||
499 | void MyFrame::OnSize(wxSizeEvent& event) | |
500 | { | |
501 | if ( m_tbar ) | |
502 | { | |
503 | LayoutChildren(); | |
504 | } | |
505 | else | |
506 | { | |
507 | event.Skip(); | |
508 | } | |
509 | } | |
510 | ||
ba0abe3c VZ |
511 | void MyFrame::OnToggleToolbar(wxCommandEvent& WXUNUSED(event)) |
512 | { | |
513 | wxToolBar *tbar = GetToolBar(); | |
514 | ||
515 | if ( !tbar ) | |
516 | { | |
517 | RecreateToolbar(); | |
518 | } | |
519 | else | |
520 | { | |
521 | delete tbar; | |
522 | ||
523 | SetToolBar(NULL); | |
524 | } | |
525 | } | |
526 | ||
96dc4236 VZ |
527 | void MyFrame::OnToggleHorizontalText(wxCommandEvent& WXUNUSED(event)) |
528 | { | |
529 | m_horzText = !m_horzText; | |
530 | ||
531 | RecreateToolbar(); | |
532 | } | |
533 | ||
f6bcfd97 BP |
534 | void MyFrame::OnToggleAnotherToolbar(wxCommandEvent& WXUNUSED(event)) |
535 | { | |
536 | if ( m_tbar ) | |
537 | { | |
538 | delete m_tbar; | |
539 | m_tbar = NULL; | |
540 | } | |
541 | else | |
542 | { | |
ec483b11 VZ |
543 | long style = GetToolBar()->GetWindowStyle(); |
544 | style &= ~wxTB_HORIZONTAL; | |
545 | style |= wxTB_VERTICAL; | |
546 | ||
f6bcfd97 BP |
547 | m_tbar = new wxToolBar(this, -1, |
548 | wxDefaultPosition, wxDefaultSize, | |
ec483b11 VZ |
549 | style); |
550 | ||
69c14ebe VZ |
551 | m_tbar->SetMargins(4, 4); |
552 | ||
3bf4189d VZ |
553 | m_tbar->AddRadioTool(IDM_TOOLBAR_OTHER_1, _T("First"), wxBITMAP(new)); |
554 | m_tbar->AddRadioTool(IDM_TOOLBAR_OTHER_2, _T("Second"), wxBITMAP(open)); | |
555 | m_tbar->AddRadioTool(IDM_TOOLBAR_OTHER_3, _T("Third"), wxBITMAP(save)); | |
ec483b11 VZ |
556 | m_tbar->AddSeparator(); |
557 | m_tbar->AddTool(wxID_HELP, _T("Help"), wxBITMAP(help)); | |
558 | ||
f6bcfd97 BP |
559 | m_tbar->Realize(); |
560 | } | |
561 | ||
562 | LayoutChildren(); | |
563 | } | |
564 | ||
5ef2e633 VZ |
565 | void MyFrame::OnToggleToolbarSize(wxCommandEvent& WXUNUSED(event)) |
566 | { | |
567 | m_smallToolbar = !m_smallToolbar; | |
ad9bb75f | 568 | |
5ef2e633 | 569 | RecreateToolbar(); |
7fb23305 VZ |
570 | } |
571 | ||
98066234 VZ |
572 | void MyFrame::OnToggleToolbarRows(wxCommandEvent& WXUNUSED(event)) |
573 | { | |
574 | // m_rows may be only 1 or 2 | |
575 | m_rows = 3 - m_rows; | |
576 | ||
577 | GetToolBar()->SetRows(m_horzToolbar ? m_rows : 10 / m_rows); | |
578 | ||
9fb35cf1 | 579 | //RecreateToolbar(); -- this is unneeded |
98066234 VZ |
580 | } |
581 | ||
5ef2e633 | 582 | void MyFrame::OnToggleToolbarOrient(wxCommandEvent& WXUNUSED(event)) |
7fb23305 | 583 | { |
5ef2e633 | 584 | m_horzToolbar = !m_horzToolbar; |
7fb23305 | 585 | |
5ef2e633 | 586 | RecreateToolbar(); |
14d1ccd8 JS |
587 | } |
588 | ||
47908e25 | 589 | void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event)) |
14d1ccd8 | 590 | { |
13437238 | 591 | Close(TRUE); |
14d1ccd8 JS |
592 | } |
593 | ||
e08bbf37 | 594 | void MyFrame::OnAbout(wxCommandEvent& event) |
14d1ccd8 | 595 | { |
e08bbf37 VZ |
596 | if ( event.IsChecked() ) |
597 | m_textWindow->WriteText( _T("Help button down now.\n") ); | |
598 | else | |
599 | m_textWindow->WriteText( _T("Help button up now.\n") ); | |
600 | ||
be5a51fb | 601 | (void)wxMessageBox(_T("wxWidgets toolbar sample"), _T("About wxToolBar")); |
13437238 | 602 | } |
14d1ccd8 | 603 | |
13437238 JS |
604 | void MyFrame::OnToolLeftClick(wxCommandEvent& event) |
605 | { | |
e179bd65 RR |
606 | wxString str; |
607 | str.Printf( _T("Clicked on tool %d\n"), event.GetId()); | |
608 | m_textWindow->WriteText( str ); | |
ad9bb75f | 609 | |
e179bd65 RR |
610 | if (event.GetId() == wxID_COPY) |
611 | { | |
7fb23305 | 612 | DoEnablePrint(); |
e179bd65 | 613 | } |
ad9bb75f | 614 | |
e179bd65 RR |
615 | if (event.GetId() == wxID_CUT) |
616 | { | |
7fb23305 | 617 | DoToggleHelp(); |
e179bd65 | 618 | } |
1c4f8f8d | 619 | |
97d7bfb8 RR |
620 | if (event.GetId() == wxID_PRINT) |
621 | { | |
622 | DoDeletePrint(); | |
623 | } | |
14d1ccd8 JS |
624 | } |
625 | ||
1c383dba VZ |
626 | void MyFrame::OnCombo(wxCommandEvent& event) |
627 | { | |
628 | wxLogStatus(_T("Combobox string '%s' selected"), event.GetString().c_str()); | |
629 | } | |
630 | ||
7fb23305 VZ |
631 | void MyFrame::DoEnablePrint() |
632 | { | |
2b5f62a0 VZ |
633 | if ( !m_nPrint ) |
634 | return; | |
635 | ||
ad4ae6ed | 636 | wxToolBarBase *tb = GetToolBar(); |
2b5f62a0 | 637 | tb->EnableTool(wxID_PRINT, !tb->GetToolEnabled(wxID_PRINT)); |
7fb23305 VZ |
638 | } |
639 | ||
97d7bfb8 RR |
640 | void MyFrame::DoDeletePrint() |
641 | { | |
2b5f62a0 VZ |
642 | if ( !m_nPrint ) |
643 | return; | |
1c4f8f8d | 644 | |
2b5f62a0 | 645 | wxToolBarBase *tb = GetToolBar(); |
97d7bfb8 | 646 | tb->DeleteTool( wxID_PRINT ); |
2b5f62a0 VZ |
647 | |
648 | m_nPrint--; | |
97d7bfb8 RR |
649 | } |
650 | ||
7fb23305 VZ |
651 | void MyFrame::DoToggleHelp() |
652 | { | |
ad4ae6ed | 653 | wxToolBarBase *tb = GetToolBar(); |
7fb23305 VZ |
654 | tb->ToggleTool( wxID_HELP, !tb->GetToolState( wxID_HELP ) ); |
655 | } | |
656 | ||
5ef2e633 VZ |
657 | void MyFrame::OnUpdateCopyAndCut(wxUpdateUIEvent& event) |
658 | { | |
96dc4236 VZ |
659 | event.Enable( m_textWindow->CanCopy() ); |
660 | } | |
661 | ||
662 | void MyFrame::OnUpdateToggleHorzText(wxUpdateUIEvent& event) | |
663 | { | |
664 | wxToolBar *tbar = GetToolBar(); | |
665 | event.Enable( tbar && | |
666 | tbar->HasFlag(wxTB_TEXT) && | |
667 | !tbar->HasFlag(wxTB_NOICONS) ); | |
5ef2e633 VZ |
668 | } |
669 | ||
a1f79c1e VZ |
670 | void MyFrame::OnChangeToolTip(wxCommandEvent& WXUNUSED(event)) |
671 | { | |
672 | GetToolBar()->SetToolShortHelp(wxID_NEW, _T("New toolbar button")); | |
673 | } | |
674 | ||
ec483b11 VZ |
675 | void MyFrame::OnToolbarStyle(wxCommandEvent& event) |
676 | { | |
677 | long style = GetToolBar()->GetWindowStyle(); | |
678 | style &= ~(wxTB_NOICONS | wxTB_TEXT); | |
679 | ||
680 | switch ( event.GetId() ) | |
681 | { | |
682 | case IDM_TOOLBAR_SHOW_TEXT: | |
683 | style |= wxTB_NOICONS | wxTB_TEXT; | |
684 | break; | |
685 | ||
686 | case IDM_TOOLBAR_SHOW_ICONS: | |
687 | // nothing to do | |
688 | break; | |
689 | ||
690 | case IDM_TOOLBAR_SHOW_BOTH: | |
691 | style |= wxTB_TEXT; | |
692 | } | |
693 | ||
694 | GetToolBar()->SetWindowStyle(style); | |
695 | } | |
696 | ||
bdc72a22 VZ |
697 | void MyFrame::OnInsertPrint(wxCommandEvent& WXUNUSED(event)) |
698 | { | |
2b5f62a0 | 699 | m_nPrint++; |
bdc72a22 | 700 | |
2b5f62a0 VZ |
701 | wxToolBarBase *tb = GetToolBar(); |
702 | tb->InsertTool(0, wxID_PRINT, _T("New print"), | |
703 | wxBITMAP(print), wxNullBitmap, | |
704 | wxITEM_NORMAL, | |
705 | _T("Delete this tool"), | |
706 | _T("This button was inserted into the toolbar")); | |
707 | ||
708 | // must call Realize() after adding a new button | |
709 | tb->Realize(); | |
bdc72a22 VZ |
710 | } |
711 | ||
13437238 JS |
712 | void MyFrame::OnToolEnter(wxCommandEvent& event) |
713 | { | |
0cfc2a92 | 714 | #ifndef __SMARTPHONE__ |
ad4ae6ed VZ |
715 | if (event.GetSelection() > -1) |
716 | { | |
717 | wxString str; | |
718 | str.Printf(_T("This is tool number %d"), event.GetSelection()); | |
719 | SetStatusText(str); | |
720 | } | |
721 | else | |
2b5f62a0 | 722 | SetStatusText(_T("")); |
0cfc2a92 | 723 | #endif |
13437238 | 724 | } |
14d1ccd8 | 725 | |
3bf4189d VZ |
726 | void MyFrame::OnToggleRadioBtn(wxCommandEvent& event) |
727 | { | |
728 | if ( m_tbar ) | |
729 | { | |
730 | m_tbar->ToggleTool(IDM_TOOLBAR_OTHER_1 + | |
731 | event.GetId() - IDM_TOOLBAR_TOGGLERADIOBTN1, true); | |
732 | } | |
733 | } | |
734 |