]>
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 BP |
105 | void OnToggleAnotherToolbar(wxCommandEvent& event); |
106 | ||
5ef2e633 VZ |
107 | void OnToggleToolbarSize(wxCommandEvent& event); |
108 | void OnToggleToolbarOrient(wxCommandEvent& event); | |
98066234 | 109 | void OnToggleToolbarRows(wxCommandEvent& event); |
5ef2e633 | 110 | |
ad4ae6ed VZ |
111 | void OnEnablePrint(wxCommandEvent& WXUNUSED(event)) { DoEnablePrint(); } |
112 | void OnDeletePrint(wxCommandEvent& WXUNUSED(event)) { DoDeletePrint(); } | |
bdc72a22 | 113 | void OnInsertPrint(wxCommandEvent& event); |
a1f79c1e | 114 | void OnChangeToolTip(wxCommandEvent& event); |
ad4ae6ed | 115 | void OnToggleHelp(wxCommandEvent& WXUNUSED(event)) { DoToggleHelp(); } |
ad9bb75f | 116 | |
ec483b11 VZ |
117 | void OnToolbarStyle(wxCommandEvent& event); |
118 | ||
ad9bb75f VZ |
119 | void OnToolLeftClick(wxCommandEvent& event); |
120 | void OnToolEnter(wxCommandEvent& event); | |
121 | ||
1c383dba VZ |
122 | void OnCombo(wxCommandEvent& event); |
123 | ||
5ef2e633 VZ |
124 | void OnUpdateCopyAndCut(wxUpdateUIEvent& event); |
125 | ||
ad4ae6ed VZ |
126 | #if USE_GENERIC_TBAR |
127 | virtual wxToolBar *OnCreateToolBar(long style, | |
128 | wxWindowID id, | |
129 | const wxString& name ); | |
130 | #endif // USE_GENERIC_TBAR | |
131 | ||
ad9bb75f VZ |
132 | private: |
133 | void DoEnablePrint(); | |
97d7bfb8 | 134 | void DoDeletePrint(); |
ad9bb75f VZ |
135 | void DoToggleHelp(); |
136 | ||
f6bcfd97 BP |
137 | void LayoutChildren(); |
138 | ||
5ef2e633 VZ |
139 | bool m_smallToolbar, |
140 | m_horzToolbar; | |
98066234 VZ |
141 | size_t m_rows; // 1 or 2 only |
142 | ||
2b5f62a0 VZ |
143 | // the number of print buttons we have (they're added/removed dynamically) |
144 | size_t m_nPrint; | |
145 | ||
f6bcfd97 BP |
146 | wxTextCtrl *m_textWindow; |
147 | ||
148 | wxToolBar *m_tbar; | |
ad9bb75f | 149 | |
ad9bb75f VZ |
150 | DECLARE_EVENT_TABLE() |
151 | }; | |
152 | ||
153 | // ---------------------------------------------------------------------------- | |
154 | // constants | |
155 | // ---------------------------------------------------------------------------- | |
156 | ||
157 | const int ID_TOOLBAR = 500; | |
158 | ||
dd46ee66 | 159 | static const long TOOLBAR_STYLE = wxTB_FLAT | wxTB_DOCKABLE | wxTB_TEXT; |
86f65864 | 160 | |
ad9bb75f | 161 | enum |
14d1ccd8 | 162 | { |
5ef2e633 VZ |
163 | IDM_TOOLBAR_TOGGLETOOLBARSIZE = 200, |
164 | IDM_TOOLBAR_TOGGLETOOLBARORIENT, | |
98066234 | 165 | IDM_TOOLBAR_TOGGLETOOLBARROWS, |
ad9bb75f | 166 | IDM_TOOLBAR_ENABLEPRINT, |
97d7bfb8 | 167 | IDM_TOOLBAR_DELETEPRINT, |
bdc72a22 | 168 | IDM_TOOLBAR_INSERTPRINT, |
1c383dba | 169 | IDM_TOOLBAR_TOGGLEHELP, |
ba0abe3c | 170 | IDM_TOOLBAR_TOGGLE_TOOLBAR, |
f6bcfd97 | 171 | IDM_TOOLBAR_TOGGLE_ANOTHER_TOOLBAR, |
a1f79c1e | 172 | IDM_TOOLBAR_CHANGE_TOOLTIP, |
ec483b11 VZ |
173 | IDM_TOOLBAR_SHOW_TEXT, |
174 | IDM_TOOLBAR_SHOW_ICONS, | |
175 | IDM_TOOLBAR_SHOW_BOTH, | |
1c383dba VZ |
176 | |
177 | ID_COMBO = 1000 | |
ad9bb75f | 178 | }; |
14d1ccd8 | 179 | |
ad9bb75f VZ |
180 | // ---------------------------------------------------------------------------- |
181 | // event tables | |
182 | // ---------------------------------------------------------------------------- | |
14d1ccd8 | 183 | |
ad9bb75f VZ |
184 | // Notice that wxID_HELP will be processed for the 'About' menu and the toolbar |
185 | // help button. | |
14d1ccd8 | 186 | |
ad9bb75f | 187 | BEGIN_EVENT_TABLE(MyFrame, wxFrame) |
f6bcfd97 BP |
188 | EVT_SIZE(MyFrame::OnSize) |
189 | ||
ad9bb75f VZ |
190 | EVT_MENU(wxID_EXIT, MyFrame::OnQuit) |
191 | EVT_MENU(wxID_HELP, MyFrame::OnAbout) | |
14d1ccd8 | 192 | |
ba0abe3c | 193 | EVT_MENU(IDM_TOOLBAR_TOGGLE_TOOLBAR, MyFrame::OnToggleToolbar) |
f6bcfd97 BP |
194 | EVT_MENU(IDM_TOOLBAR_TOGGLE_ANOTHER_TOOLBAR, MyFrame::OnToggleAnotherToolbar) |
195 | ||
5ef2e633 VZ |
196 | EVT_MENU(IDM_TOOLBAR_TOGGLETOOLBARSIZE, MyFrame::OnToggleToolbarSize) |
197 | EVT_MENU(IDM_TOOLBAR_TOGGLETOOLBARORIENT, MyFrame::OnToggleToolbarOrient) | |
98066234 | 198 | EVT_MENU(IDM_TOOLBAR_TOGGLETOOLBARROWS, MyFrame::OnToggleToolbarRows) |
5ef2e633 | 199 | |
ad9bb75f | 200 | EVT_MENU(IDM_TOOLBAR_ENABLEPRINT, MyFrame::OnEnablePrint) |
97d7bfb8 | 201 | EVT_MENU(IDM_TOOLBAR_DELETEPRINT, MyFrame::OnDeletePrint) |
bdc72a22 | 202 | EVT_MENU(IDM_TOOLBAR_INSERTPRINT, MyFrame::OnInsertPrint) |
ad9bb75f | 203 | EVT_MENU(IDM_TOOLBAR_TOGGLEHELP, MyFrame::OnToggleHelp) |
a1f79c1e | 204 | EVT_MENU(IDM_TOOLBAR_CHANGE_TOOLTIP, MyFrame::OnChangeToolTip) |
14d1ccd8 | 205 | |
ec483b11 VZ |
206 | EVT_MENU_RANGE(IDM_TOOLBAR_SHOW_TEXT, IDM_TOOLBAR_SHOW_BOTH, |
207 | MyFrame::OnToolbarStyle) | |
208 | ||
ad9bb75f | 209 | EVT_MENU(-1, MyFrame::OnToolLeftClick) |
14d1ccd8 | 210 | |
1c383dba VZ |
211 | EVT_COMBOBOX(ID_COMBO, MyFrame::OnCombo) |
212 | ||
ad9bb75f | 213 | EVT_TOOL_ENTER(ID_TOOLBAR, MyFrame::OnToolEnter) |
5ef2e633 VZ |
214 | |
215 | EVT_UPDATE_UI(wxID_COPY, MyFrame::OnUpdateCopyAndCut) | |
216 | EVT_UPDATE_UI(wxID_CUT, MyFrame::OnUpdateCopyAndCut) | |
ad9bb75f | 217 | END_EVENT_TABLE() |
14d1ccd8 | 218 | |
ad9bb75f VZ |
219 | // ============================================================================ |
220 | // implementation | |
221 | // ============================================================================ | |
14d1ccd8 | 222 | |
ad9bb75f VZ |
223 | // ---------------------------------------------------------------------------- |
224 | // MyApp | |
225 | // ---------------------------------------------------------------------------- | |
14d1ccd8 | 226 | |
ad9bb75f | 227 | IMPLEMENT_APP(MyApp) |
14d1ccd8 | 228 | |
ad9bb75f VZ |
229 | // The `main program' equivalent, creating the windows and returning the |
230 | // main frame | |
231 | bool MyApp::OnInit() | |
232 | { | |
233 | // Create the main frame window | |
234 | MyFrame* frame = new MyFrame((wxFrame *) NULL, -1, | |
ab1ca7b3 | 235 | _T("wxToolBar Sample"), |
bf95a04f JS |
236 | #ifdef __WXWINCE__ |
237 | wxPoint(0, 0), wxDefaultSize, wxNO_BORDER | |
238 | #else | |
239 | wxPoint(100, 100), wxSize(550, 300) | |
240 | #endif | |
241 | ); | |
14d1ccd8 | 242 | |
7fb23305 VZ |
243 | frame->Show(TRUE); |
244 | ||
ab1ca7b3 | 245 | frame->SetStatusText(_T("Hello, wxWindows")); |
7fb23305 VZ |
246 | |
247 | SetTopWindow(frame); | |
248 | ||
249 | return TRUE; | |
14d1ccd8 JS |
250 | } |
251 | ||
5ef2e633 | 252 | void MyFrame::RecreateToolbar() |
14d1ccd8 | 253 | { |
bf95a04f JS |
254 | #ifdef __WXWINCE__ |
255 | // On Windows CE, we should not delete the | |
256 | // previous toolbar in case it contains the menubar. | |
257 | // We'll try to accomodate this usage in due course. | |
258 | wxToolBar* toolBar = CreateToolBar(); | |
259 | #else | |
5ef2e633 | 260 | // delete and recreate the toolbar |
ad4ae6ed | 261 | wxToolBarBase *toolBar = GetToolBar(); |
ec483b11 VZ |
262 | long style = toolBar ? toolBar->GetWindowStyle() : TOOLBAR_STYLE; |
263 | ||
5ef2e633 | 264 | delete toolBar; |
14d1ccd8 | 265 | |
5ef2e633 VZ |
266 | SetToolBar(NULL); |
267 | ||
ec483b11 | 268 | style &= ~(wxTB_HORIZONTAL | wxTB_VERTICAL); |
5ef2e633 | 269 | style |= m_horzToolbar ? wxTB_HORIZONTAL : wxTB_VERTICAL; |
229de929 | 270 | style |= wxNO_FULL_REPAINT_ON_RESIZE ; |
5ef2e633 VZ |
271 | |
272 | toolBar = CreateToolBar(style, ID_TOOLBAR); | |
bf95a04f | 273 | #endif |
5ef2e633 VZ |
274 | |
275 | // Set up toolbar | |
276 | wxBitmap toolBarBitmaps[8]; | |
277 | ||
f6bcfd97 BP |
278 | #if USE_XPM_BITMAPS |
279 | toolBarBitmaps[0] = wxBitmap(new_xpm); | |
280 | toolBarBitmaps[1] = wxBitmap(open_xpm); | |
281 | toolBarBitmaps[2] = wxBitmap(save_xpm); | |
282 | toolBarBitmaps[3] = wxBitmap(copy_xpm); | |
283 | toolBarBitmaps[4] = wxBitmap(cut_xpm); | |
284 | toolBarBitmaps[5] = wxBitmap(paste_xpm); | |
285 | toolBarBitmaps[6] = wxBitmap(print_xpm); | |
286 | toolBarBitmaps[7] = wxBitmap(help_xpm); | |
287 | #else // !USE_XPM_BITMAPS | |
5ef2e633 VZ |
288 | toolBarBitmaps[0] = wxBITMAP(new); |
289 | toolBarBitmaps[1] = wxBITMAP(open); | |
40515a21 VZ |
290 | toolBarBitmaps[2] = wxBITMAP(save); |
291 | toolBarBitmaps[3] = wxBITMAP(copy); | |
292 | toolBarBitmaps[4] = wxBITMAP(cut); | |
293 | toolBarBitmaps[5] = wxBITMAP(paste); | |
294 | toolBarBitmaps[6] = wxBITMAP(print); | |
295 | toolBarBitmaps[7] = wxBITMAP(help); | |
f6bcfd97 | 296 | #endif // USE_XPM_BITMAPS/!USE_XPM_BITMAPS |
40515a21 | 297 | |
5ef2e633 VZ |
298 | if ( !m_smallToolbar ) |
299 | { | |
40515a21 VZ |
300 | int w = 2*toolBarBitmaps[0].GetWidth(), |
301 | h = 2*toolBarBitmaps[0].GetHeight(); | |
302 | for ( size_t n = 0; n < WXSIZEOF(toolBarBitmaps); n++ ) | |
303 | { | |
304 | toolBarBitmaps[n] = | |
368d59f0 | 305 | wxBitmap(toolBarBitmaps[n].ConvertToImage().Scale(w, h)); |
40515a21 VZ |
306 | } |
307 | ||
308 | toolBar->SetToolBitmapSize(wxSize(w, h)); | |
5ef2e633 | 309 | } |
14d1ccd8 | 310 | |
ec483b11 VZ |
311 | toolBar->AddTool(wxID_NEW, _T("New"), toolBarBitmaps[0], _T("New file")); |
312 | toolBar->AddTool(wxID_OPEN, _T("Open"), toolBarBitmaps[1], _T("Open file")); | |
14d1ccd8 | 313 | |
aae91497 MB |
314 | // the generic toolbar doesn't really support this |
315 | #if (wxUSE_TOOLBAR_NATIVE && !USE_GENERIC_TBAR) && !defined(__WXX11__) || defined(__WXUNIVERSAL__) | |
5ef2e633 VZ |
316 | // adding a combo to a vertical toolbar is not very smart |
317 | if ( m_horzToolbar ) | |
318 | { | |
ab1ca7b3 | 319 | wxComboBox *combo = new wxComboBox(toolBar, ID_COMBO, _T(""), wxDefaultPosition, wxSize(200,-1) ); |
2b5f62a0 VZ |
320 | combo->Append(_T("This")); |
321 | combo->Append(_T("is a")); | |
322 | combo->Append(_T("combobox")); | |
323 | combo->Append(_T("in a")); | |
324 | combo->Append(_T("toolbar")); | |
5ef2e633 VZ |
325 | toolBar->AddControl(combo); |
326 | } | |
ad4ae6ed | 327 | #endif // toolbars which don't support controls |
14d1ccd8 | 328 | |
ec483b11 VZ |
329 | toolBar->AddTool(wxID_SAVE, _T("Save"), toolBarBitmaps[2], _T("Toggle button 1"), wxITEM_CHECK); |
330 | toolBar->AddTool(wxID_COPY, _T("Copy"), toolBarBitmaps[3], _T("Toggle button 2"), wxITEM_CHECK); | |
331 | toolBar->AddTool(wxID_CUT, _T("Cut"), toolBarBitmaps[4], _T("Toggle/Untoggle help button")); | |
332 | toolBar->AddTool(wxID_PASTE, _T("Paste"), toolBarBitmaps[5], _T("Paste")); | |
333 | toolBar->AddTool(wxID_PRINT, _T("Print"), toolBarBitmaps[6], _T("Delete this tool")); | |
40515a21 | 334 | toolBar->AddSeparator(); |
ec483b11 | 335 | toolBar->AddTool(wxID_HELP, _T("Help"), toolBarBitmaps[7], _T("Help button"), wxITEM_CHECK); |
13437238 | 336 | |
5ef2e633 VZ |
337 | // after adding the buttons to the toolbar, must call Realize() to reflect |
338 | // the changes | |
339 | toolBar->Realize(); | |
98066234 VZ |
340 | |
341 | toolBar->SetRows(m_horzToolbar ? m_rows : 10 / m_rows); | |
14d1ccd8 JS |
342 | } |
343 | ||
ad9bb75f VZ |
344 | // ---------------------------------------------------------------------------- |
345 | // MyFrame | |
346 | // ---------------------------------------------------------------------------- | |
13437238 JS |
347 | |
348 | // Define my frame constructor | |
7fb23305 VZ |
349 | MyFrame::MyFrame(wxFrame* parent, |
350 | wxWindowID id, | |
351 | const wxString& title, | |
352 | const wxPoint& pos, | |
353 | const wxSize& size, | |
354 | long style) | |
355 | : wxFrame(parent, id, title, pos, size, style) | |
14d1ccd8 | 356 | { |
f6bcfd97 | 357 | m_tbar = NULL; |
2b5f62a0 | 358 | m_textWindow = new wxTextCtrl(this, -1, _T(""), wxPoint(0, 0), wxSize(-1, -1), wxTE_MULTILINE); |
98066234 | 359 | |
40515a21 | 360 | m_smallToolbar = TRUE; |
98066234 VZ |
361 | m_horzToolbar = TRUE; |
362 | m_rows = 1; | |
2b5f62a0 | 363 | m_nPrint = 1; |
ad9bb75f | 364 | |
bf95a04f | 365 | #ifndef __WXWINCE__ |
ad9bb75f VZ |
366 | // Give it a status line |
367 | CreateStatusBar(); | |
bf95a04f | 368 | #endif |
ad9bb75f VZ |
369 | |
370 | // Give it an icon | |
371 | SetIcon(wxICON(mondrian)); | |
372 | ||
373 | // Make a menubar | |
374 | wxMenu *tbarMenu = new wxMenu; | |
ba0abe3c | 375 | tbarMenu->AppendCheckItem(IDM_TOOLBAR_TOGGLE_TOOLBAR, |
2b5f62a0 VZ |
376 | _T("Toggle &toolbar\tCtrl-Z"), |
377 | _T("Show or hide the toolbar")); | |
ba0abe3c VZ |
378 | |
379 | tbarMenu->AppendCheckItem(IDM_TOOLBAR_TOGGLE_ANOTHER_TOOLBAR, | |
2b5f62a0 VZ |
380 | _T("Toggle &another toolbar\tCtrl-A"), |
381 | _T("Show/hide another test toolbar")); | |
ba0abe3c VZ |
382 | |
383 | tbarMenu->AppendCheckItem(IDM_TOOLBAR_TOGGLETOOLBARSIZE, | |
2b5f62a0 VZ |
384 | _T("&Toggle toolbar size\tCtrl-S"), |
385 | _T("Toggle between big/small toolbar")); | |
ba0abe3c VZ |
386 | |
387 | tbarMenu->AppendCheckItem(IDM_TOOLBAR_TOGGLETOOLBARORIENT, | |
2b5f62a0 VZ |
388 | _T("Toggle toolbar &orientation\tCtrl-O"), |
389 | _T("Toggle toolbar orientation")); | |
ba0abe3c VZ |
390 | |
391 | tbarMenu->AppendCheckItem(IDM_TOOLBAR_TOGGLETOOLBARROWS, | |
2b5f62a0 VZ |
392 | _T("Toggle number of &rows\tCtrl-R"), |
393 | _T("Toggle number of toolbar rows between 1 and 2")); | |
5ef2e633 VZ |
394 | |
395 | tbarMenu->AppendSeparator(); | |
396 | ||
2b5f62a0 VZ |
397 | tbarMenu->Append(IDM_TOOLBAR_ENABLEPRINT, _T("&Enable print button\tCtrl-E"), _T("")); |
398 | tbarMenu->Append(IDM_TOOLBAR_DELETEPRINT, _T("&Delete print button\tCtrl-D"), _T("")); | |
399 | tbarMenu->Append(IDM_TOOLBAR_INSERTPRINT, _T("&Insert print button\tCtrl-I"), _T("")); | |
400 | tbarMenu->Append(IDM_TOOLBAR_TOGGLEHELP, _T("Toggle &help button\tCtrl-T"), _T("")); | |
a1f79c1e | 401 | tbarMenu->AppendSeparator(); |
2b5f62a0 | 402 | tbarMenu->Append(IDM_TOOLBAR_CHANGE_TOOLTIP, _T("Change tool tip"), _T("")); |
ec483b11 | 403 | tbarMenu->AppendSeparator(); |
2b5f62a0 VZ |
404 | tbarMenu->AppendRadioItem(IDM_TOOLBAR_SHOW_TEXT, _T("Show &text\tAlt-T")); |
405 | tbarMenu->AppendRadioItem(IDM_TOOLBAR_SHOW_ICONS, _T("Show &icons\tAlt-I")); | |
406 | tbarMenu->AppendRadioItem(IDM_TOOLBAR_SHOW_BOTH, _T("Show &both\tAlt-B")); | |
b487a08f | 407 | |
ad9bb75f | 408 | wxMenu *fileMenu = new wxMenu; |
2b5f62a0 | 409 | fileMenu->Append(wxID_EXIT, _T("E&xit\tAlt-X"), _T("Quit toolbar sample") ); |
ad9bb75f | 410 | |
ad9bb75f | 411 | wxMenu *helpMenu = new wxMenu; |
2b5f62a0 | 412 | helpMenu->Append(wxID_HELP, _T("&About"), _T("About toolbar sample")); |
ad9bb75f VZ |
413 | |
414 | wxMenuBar* menuBar = new wxMenuBar( wxMB_DOCKABLE ); | |
415 | ||
2b5f62a0 VZ |
416 | menuBar->Append(fileMenu, _T("&File")); |
417 | menuBar->Append(tbarMenu, _T("&Toolbar")); | |
418 | menuBar->Append(helpMenu, _T("&Help")); | |
ad9bb75f VZ |
419 | |
420 | // Associate the menu bar with the frame | |
421 | SetMenuBar(menuBar); | |
422 | ||
c631abda VZ |
423 | menuBar->Check(IDM_TOOLBAR_SHOW_BOTH, TRUE); |
424 | ||
ad9bb75f | 425 | // Create the toolbar |
5ef2e633 VZ |
426 | RecreateToolbar(); |
427 | } | |
ad9bb75f | 428 | |
ad4ae6ed VZ |
429 | #if USE_GENERIC_TBAR |
430 | ||
431 | wxToolBar* MyFrame::OnCreateToolBar(long style, | |
432 | wxWindowID id, | |
433 | const wxString& name) | |
434 | { | |
435 | return (wxToolBar *)new wxToolBarSimple(this, id, | |
436 | wxDefaultPosition, wxDefaultSize, | |
437 | style, name); | |
438 | } | |
439 | ||
440 | #endif // USE_GENERIC_TBAR | |
441 | ||
f6bcfd97 BP |
442 | void MyFrame::LayoutChildren() |
443 | { | |
444 | wxSize size = GetClientSize(); | |
445 | ||
446 | int offset; | |
447 | if ( m_tbar ) | |
448 | { | |
449 | m_tbar->SetSize(-1, size.y); | |
450 | m_tbar->Move(0, 0); | |
451 | ||
452 | offset = m_tbar->GetSize().x; | |
453 | } | |
454 | else | |
455 | { | |
456 | offset = 0; | |
457 | } | |
458 | ||
459 | m_textWindow->SetSize(offset, 0, size.x - offset, size.y); | |
460 | } | |
461 | ||
462 | void MyFrame::OnSize(wxSizeEvent& event) | |
463 | { | |
464 | if ( m_tbar ) | |
465 | { | |
466 | LayoutChildren(); | |
467 | } | |
468 | else | |
469 | { | |
470 | event.Skip(); | |
471 | } | |
472 | } | |
473 | ||
ba0abe3c VZ |
474 | void MyFrame::OnToggleToolbar(wxCommandEvent& WXUNUSED(event)) |
475 | { | |
476 | wxToolBar *tbar = GetToolBar(); | |
477 | ||
478 | if ( !tbar ) | |
479 | { | |
480 | RecreateToolbar(); | |
481 | } | |
482 | else | |
483 | { | |
484 | delete tbar; | |
485 | ||
486 | SetToolBar(NULL); | |
487 | } | |
488 | } | |
489 | ||
f6bcfd97 BP |
490 | void MyFrame::OnToggleAnotherToolbar(wxCommandEvent& WXUNUSED(event)) |
491 | { | |
492 | if ( m_tbar ) | |
493 | { | |
494 | delete m_tbar; | |
495 | m_tbar = NULL; | |
496 | } | |
497 | else | |
498 | { | |
ec483b11 VZ |
499 | long style = GetToolBar()->GetWindowStyle(); |
500 | style &= ~wxTB_HORIZONTAL; | |
501 | style |= wxTB_VERTICAL; | |
502 | ||
f6bcfd97 BP |
503 | m_tbar = new wxToolBar(this, -1, |
504 | wxDefaultPosition, wxDefaultSize, | |
ec483b11 VZ |
505 | style); |
506 | ||
69c14ebe VZ |
507 | m_tbar->SetMargins(4, 4); |
508 | ||
ec483b11 | 509 | m_tbar->AddRadioTool(wxID_NEW, _T("First"), wxBITMAP(new)); |
c631abda VZ |
510 | m_tbar->AddRadioTool(wxID_OPEN, _T("Second"), wxBITMAP(open)); |
511 | m_tbar->AddRadioTool(wxID_SAVE, _T("Third"), wxBITMAP(save)); | |
ec483b11 VZ |
512 | m_tbar->AddSeparator(); |
513 | m_tbar->AddTool(wxID_HELP, _T("Help"), wxBITMAP(help)); | |
514 | ||
f6bcfd97 BP |
515 | m_tbar->Realize(); |
516 | } | |
517 | ||
518 | LayoutChildren(); | |
519 | } | |
520 | ||
5ef2e633 VZ |
521 | void MyFrame::OnToggleToolbarSize(wxCommandEvent& WXUNUSED(event)) |
522 | { | |
523 | m_smallToolbar = !m_smallToolbar; | |
ad9bb75f | 524 | |
5ef2e633 | 525 | RecreateToolbar(); |
7fb23305 VZ |
526 | } |
527 | ||
98066234 VZ |
528 | void MyFrame::OnToggleToolbarRows(wxCommandEvent& WXUNUSED(event)) |
529 | { | |
530 | // m_rows may be only 1 or 2 | |
531 | m_rows = 3 - m_rows; | |
532 | ||
533 | GetToolBar()->SetRows(m_horzToolbar ? m_rows : 10 / m_rows); | |
534 | ||
9fb35cf1 | 535 | //RecreateToolbar(); -- this is unneeded |
98066234 VZ |
536 | } |
537 | ||
5ef2e633 | 538 | void MyFrame::OnToggleToolbarOrient(wxCommandEvent& WXUNUSED(event)) |
7fb23305 | 539 | { |
5ef2e633 | 540 | m_horzToolbar = !m_horzToolbar; |
7fb23305 | 541 | |
5ef2e633 | 542 | RecreateToolbar(); |
14d1ccd8 JS |
543 | } |
544 | ||
47908e25 | 545 | void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event)) |
14d1ccd8 | 546 | { |
13437238 | 547 | Close(TRUE); |
14d1ccd8 JS |
548 | } |
549 | ||
e08bbf37 | 550 | void MyFrame::OnAbout(wxCommandEvent& event) |
14d1ccd8 | 551 | { |
e08bbf37 VZ |
552 | if ( event.IsChecked() ) |
553 | m_textWindow->WriteText( _T("Help button down now.\n") ); | |
554 | else | |
555 | m_textWindow->WriteText( _T("Help button up now.\n") ); | |
556 | ||
2b5f62a0 | 557 | (void)wxMessageBox(_T("wxWindows toolbar sample"), _T("About wxToolBar")); |
13437238 | 558 | } |
14d1ccd8 | 559 | |
13437238 JS |
560 | void MyFrame::OnToolLeftClick(wxCommandEvent& event) |
561 | { | |
e179bd65 RR |
562 | wxString str; |
563 | str.Printf( _T("Clicked on tool %d\n"), event.GetId()); | |
564 | m_textWindow->WriteText( str ); | |
ad9bb75f | 565 | |
e179bd65 RR |
566 | if (event.GetId() == wxID_COPY) |
567 | { | |
7fb23305 | 568 | DoEnablePrint(); |
e179bd65 | 569 | } |
ad9bb75f | 570 | |
e179bd65 RR |
571 | if (event.GetId() == wxID_CUT) |
572 | { | |
7fb23305 | 573 | DoToggleHelp(); |
e179bd65 | 574 | } |
1c4f8f8d | 575 | |
97d7bfb8 RR |
576 | if (event.GetId() == wxID_PRINT) |
577 | { | |
578 | DoDeletePrint(); | |
579 | } | |
14d1ccd8 JS |
580 | } |
581 | ||
1c383dba VZ |
582 | void MyFrame::OnCombo(wxCommandEvent& event) |
583 | { | |
584 | wxLogStatus(_T("Combobox string '%s' selected"), event.GetString().c_str()); | |
585 | } | |
586 | ||
7fb23305 VZ |
587 | void MyFrame::DoEnablePrint() |
588 | { | |
2b5f62a0 VZ |
589 | if ( !m_nPrint ) |
590 | return; | |
591 | ||
ad4ae6ed | 592 | wxToolBarBase *tb = GetToolBar(); |
2b5f62a0 | 593 | tb->EnableTool(wxID_PRINT, !tb->GetToolEnabled(wxID_PRINT)); |
7fb23305 VZ |
594 | } |
595 | ||
97d7bfb8 RR |
596 | void MyFrame::DoDeletePrint() |
597 | { | |
2b5f62a0 VZ |
598 | if ( !m_nPrint ) |
599 | return; | |
1c4f8f8d | 600 | |
2b5f62a0 | 601 | wxToolBarBase *tb = GetToolBar(); |
97d7bfb8 | 602 | tb->DeleteTool( wxID_PRINT ); |
2b5f62a0 VZ |
603 | |
604 | m_nPrint--; | |
97d7bfb8 RR |
605 | } |
606 | ||
7fb23305 VZ |
607 | void MyFrame::DoToggleHelp() |
608 | { | |
ad4ae6ed | 609 | wxToolBarBase *tb = GetToolBar(); |
7fb23305 VZ |
610 | tb->ToggleTool( wxID_HELP, !tb->GetToolState( wxID_HELP ) ); |
611 | } | |
612 | ||
5ef2e633 VZ |
613 | void MyFrame::OnUpdateCopyAndCut(wxUpdateUIEvent& event) |
614 | { | |
229de929 JS |
615 | if (m_textWindow) |
616 | event.Enable( m_textWindow->CanCopy() ); | |
5ef2e633 VZ |
617 | } |
618 | ||
a1f79c1e VZ |
619 | void MyFrame::OnChangeToolTip(wxCommandEvent& WXUNUSED(event)) |
620 | { | |
621 | GetToolBar()->SetToolShortHelp(wxID_NEW, _T("New toolbar button")); | |
622 | } | |
623 | ||
ec483b11 VZ |
624 | void MyFrame::OnToolbarStyle(wxCommandEvent& event) |
625 | { | |
626 | long style = GetToolBar()->GetWindowStyle(); | |
627 | style &= ~(wxTB_NOICONS | wxTB_TEXT); | |
628 | ||
629 | switch ( event.GetId() ) | |
630 | { | |
631 | case IDM_TOOLBAR_SHOW_TEXT: | |
632 | style |= wxTB_NOICONS | wxTB_TEXT; | |
633 | break; | |
634 | ||
635 | case IDM_TOOLBAR_SHOW_ICONS: | |
636 | // nothing to do | |
637 | break; | |
638 | ||
639 | case IDM_TOOLBAR_SHOW_BOTH: | |
640 | style |= wxTB_TEXT; | |
641 | } | |
642 | ||
643 | GetToolBar()->SetWindowStyle(style); | |
644 | } | |
645 | ||
bdc72a22 VZ |
646 | void MyFrame::OnInsertPrint(wxCommandEvent& WXUNUSED(event)) |
647 | { | |
2b5f62a0 | 648 | m_nPrint++; |
bdc72a22 | 649 | |
2b5f62a0 VZ |
650 | wxToolBarBase *tb = GetToolBar(); |
651 | tb->InsertTool(0, wxID_PRINT, _T("New print"), | |
652 | wxBITMAP(print), wxNullBitmap, | |
653 | wxITEM_NORMAL, | |
654 | _T("Delete this tool"), | |
655 | _T("This button was inserted into the toolbar")); | |
656 | ||
657 | // must call Realize() after adding a new button | |
658 | tb->Realize(); | |
bdc72a22 VZ |
659 | } |
660 | ||
13437238 JS |
661 | void MyFrame::OnToolEnter(wxCommandEvent& event) |
662 | { | |
ad4ae6ed VZ |
663 | if (event.GetSelection() > -1) |
664 | { | |
665 | wxString str; | |
666 | str.Printf(_T("This is tool number %d"), event.GetSelection()); | |
667 | SetStatusText(str); | |
668 | } | |
669 | else | |
2b5f62a0 | 670 | SetStatusText(_T("")); |
13437238 | 671 | } |
14d1ccd8 | 672 |