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