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