]> git.saurik.com Git - wxWidgets.git/blob - samples/toolbar/toolbar.cpp
f6bc9457e8805c9b3e92dd56a3f337528f5c7498
[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
260 // Set up toolbar
261 wxBitmap toolBarBitmaps[8];
262
263 #if USE_XPM_BITMAPS
264 toolBarBitmaps[0] = wxBitmap(new_xpm);
265 toolBarBitmaps[1] = wxBitmap(open_xpm);
266 toolBarBitmaps[2] = wxBitmap(save_xpm);
267 toolBarBitmaps[3] = wxBitmap(copy_xpm);
268 toolBarBitmaps[4] = wxBitmap(cut_xpm);
269 toolBarBitmaps[5] = wxBitmap(paste_xpm);
270 toolBarBitmaps[6] = wxBitmap(print_xpm);
271 toolBarBitmaps[7] = wxBitmap(help_xpm);
272 #else // !USE_XPM_BITMAPS
273 toolBarBitmaps[0] = wxBITMAP(new);
274 toolBarBitmaps[1] = wxBITMAP(open);
275 toolBarBitmaps[2] = wxBITMAP(save);
276 toolBarBitmaps[3] = wxBITMAP(copy);
277 toolBarBitmaps[4] = wxBITMAP(cut);
278 toolBarBitmaps[5] = wxBITMAP(paste);
279 toolBarBitmaps[6] = wxBITMAP(print);
280 toolBarBitmaps[7] = wxBITMAP(help);
281 #endif // USE_XPM_BITMAPS/!USE_XPM_BITMAPS
282
283 if ( !m_smallToolbar )
284 {
285 int w = 2*toolBarBitmaps[0].GetWidth(),
286 h = 2*toolBarBitmaps[0].GetHeight();
287 for ( size_t n = 0; n < WXSIZEOF(toolBarBitmaps); n++ )
288 {
289 toolBarBitmaps[n] =
290 wxBitmap(toolBarBitmaps[n].ConvertToImage().Scale(w, h));
291 }
292
293 toolBar->SetToolBitmapSize(wxSize(w, h));
294 }
295
296 toolBar->AddTool(wxID_NEW, _T("New"), toolBarBitmaps[0], _T("New file"));
297 toolBar->AddTool(wxID_OPEN, _T("Open"), toolBarBitmaps[1], _T("Open file"));
298
299 // neither the generic nor Motif native toolbars really support this
300 #if (wxUSE_TOOLBAR_NATIVE && !USE_GENERIC_TBAR) && !defined(__WXMOTIF__) && !defined(__WXX11__)
301 // adding a combo to a vertical toolbar is not very smart
302 if ( m_horzToolbar )
303 {
304 wxComboBox *combo = new wxComboBox(toolBar, ID_COMBO, "", wxDefaultPosition, wxSize(200,-1) );
305 combo->Append("This");
306 combo->Append("is a");
307 combo->Append("combobox");
308 combo->Append("in a");
309 combo->Append("toolbar");
310 toolBar->AddControl(combo);
311 }
312 #endif // toolbars which don't support controls
313
314 toolBar->AddTool(wxID_SAVE, _T("Save"), toolBarBitmaps[2], _T("Toggle button 1"), wxITEM_CHECK);
315 toolBar->AddTool(wxID_COPY, _T("Copy"), toolBarBitmaps[3], _T("Toggle button 2"), wxITEM_CHECK);
316 toolBar->AddTool(wxID_CUT, _T("Cut"), toolBarBitmaps[4], _T("Toggle/Untoggle help button"));
317 toolBar->AddTool(wxID_PASTE, _T("Paste"), toolBarBitmaps[5], _T("Paste"));
318 toolBar->AddTool(wxID_PRINT, _T("Print"), toolBarBitmaps[6], _T("Delete this tool"));
319 toolBar->AddSeparator();
320 toolBar->AddTool(wxID_HELP, _T("Help"), toolBarBitmaps[7], _T("Help button"), wxITEM_CHECK);
321
322 // after adding the buttons to the toolbar, must call Realize() to reflect
323 // the changes
324 toolBar->Realize();
325
326 toolBar->SetRows(m_horzToolbar ? m_rows : 10 / m_rows);
327 }
328
329 // ----------------------------------------------------------------------------
330 // MyFrame
331 // ----------------------------------------------------------------------------
332
333 // Define my frame constructor
334 MyFrame::MyFrame(wxFrame* parent,
335 wxWindowID id,
336 const wxString& title,
337 const wxPoint& pos,
338 const wxSize& size,
339 long style)
340 : wxFrame(parent, id, title, pos, size, style)
341 {
342 m_tbar = NULL;
343 m_textWindow = new wxTextCtrl(this, -1, "", wxPoint(0, 0), wxSize(-1, -1), wxTE_MULTILINE);
344
345 m_smallToolbar = TRUE;
346 m_horzToolbar = TRUE;
347 m_rows = 1;
348
349 // Give it a status line
350 CreateStatusBar();
351
352 // Give it an icon
353 SetIcon(wxICON(mondrian));
354
355 // Make a menubar
356 wxMenu *tbarMenu = new wxMenu;
357 tbarMenu->AppendCheckItem(IDM_TOOLBAR_TOGGLE_TOOLBAR,
358 "Toggle &toolbar\tCtrl-Z",
359 "Show or hide the toolbar");
360
361 tbarMenu->AppendCheckItem(IDM_TOOLBAR_TOGGLE_ANOTHER_TOOLBAR,
362 "Toggle &another toolbar\tCtrl-A",
363 "Show/hide another test toolbar");
364
365 tbarMenu->AppendCheckItem(IDM_TOOLBAR_TOGGLETOOLBARSIZE,
366 "&Toggle toolbar size\tCtrl-S",
367 "Toggle between big/small toolbar");
368
369 tbarMenu->AppendCheckItem(IDM_TOOLBAR_TOGGLETOOLBARORIENT,
370 "Toggle toolbar &orientation\tCtrl-O",
371 "Toggle toolbar orientation");
372
373 tbarMenu->AppendCheckItem(IDM_TOOLBAR_TOGGLETOOLBARROWS,
374 "Toggle number of &rows\tCtrl-R",
375 "Toggle number of toolbar rows between 1 and 2");
376
377 tbarMenu->AppendSeparator();
378
379 tbarMenu->Append(IDM_TOOLBAR_ENABLEPRINT, "&Enable print button\tCtrl-E", "");
380 tbarMenu->Append(IDM_TOOLBAR_DELETEPRINT, "&Delete print button\tCtrl-D", "");
381 tbarMenu->Append(IDM_TOOLBAR_INSERTPRINT, "&Insert print button\tCtrl-I", "");
382 tbarMenu->Append(IDM_TOOLBAR_TOGGLEHELP, "Toggle &help button\tCtrl-T", "");
383 tbarMenu->AppendSeparator();
384 tbarMenu->Append(IDM_TOOLBAR_CHANGE_TOOLTIP, "Change tool tip", "");
385 tbarMenu->AppendSeparator();
386 tbarMenu->AppendRadioItem(IDM_TOOLBAR_SHOW_TEXT, "Show &text\tAlt-T");
387 tbarMenu->AppendRadioItem(IDM_TOOLBAR_SHOW_ICONS, "Show &icons\tAlt-I");
388 tbarMenu->AppendRadioItem(IDM_TOOLBAR_SHOW_BOTH, "Show &both\tAlt-B");
389
390 wxMenu *fileMenu = new wxMenu;
391 fileMenu->Append(wxID_EXIT, "E&xit\tAlt-X", "Quit toolbar sample" );
392
393 wxMenu *helpMenu = new wxMenu;
394 helpMenu->Append(wxID_HELP, "&About", "About toolbar sample");
395
396 wxMenuBar* menuBar = new wxMenuBar( wxMB_DOCKABLE );
397
398 menuBar->Append(fileMenu, "&File");
399 menuBar->Append(tbarMenu, "&Toolbar");
400 menuBar->Append(helpMenu, "&Help");
401
402 // Associate the menu bar with the frame
403 SetMenuBar(menuBar);
404
405 menuBar->Check(IDM_TOOLBAR_SHOW_BOTH, TRUE);
406
407 // Create the toolbar
408 RecreateToolbar();
409 }
410
411 #if USE_GENERIC_TBAR
412
413 wxToolBar* MyFrame::OnCreateToolBar(long style,
414 wxWindowID id,
415 const wxString& name)
416 {
417 return (wxToolBar *)new wxToolBarSimple(this, id,
418 wxDefaultPosition, wxDefaultSize,
419 style, name);
420 }
421
422 #endif // USE_GENERIC_TBAR
423
424 void MyFrame::LayoutChildren()
425 {
426 wxSize size = GetClientSize();
427
428 int offset;
429 if ( m_tbar )
430 {
431 m_tbar->SetSize(-1, size.y);
432 m_tbar->Move(0, 0);
433
434 offset = m_tbar->GetSize().x;
435 }
436 else
437 {
438 offset = 0;
439 }
440
441 m_textWindow->SetSize(offset, 0, size.x - offset, size.y);
442 }
443
444 void MyFrame::OnSize(wxSizeEvent& event)
445 {
446 if ( m_tbar )
447 {
448 LayoutChildren();
449 }
450 else
451 {
452 event.Skip();
453 }
454 }
455
456 void MyFrame::OnToggleToolbar(wxCommandEvent& WXUNUSED(event))
457 {
458 wxToolBar *tbar = GetToolBar();
459
460 if ( !tbar )
461 {
462 RecreateToolbar();
463 }
464 else
465 {
466 delete tbar;
467
468 SetToolBar(NULL);
469 }
470 }
471
472 void MyFrame::OnToggleAnotherToolbar(wxCommandEvent& WXUNUSED(event))
473 {
474 if ( m_tbar )
475 {
476 delete m_tbar;
477 m_tbar = NULL;
478 }
479 else
480 {
481 long style = GetToolBar()->GetWindowStyle();
482 style &= ~wxTB_HORIZONTAL;
483 style |= wxTB_VERTICAL;
484
485 m_tbar = new wxToolBar(this, -1,
486 wxDefaultPosition, wxDefaultSize,
487 style);
488
489 m_tbar->SetMargins(4, 4);
490
491 m_tbar->AddRadioTool(wxID_NEW, _T("First"), wxBITMAP(new));
492 m_tbar->AddRadioTool(wxID_OPEN, _T("Second"), wxBITMAP(open));
493 m_tbar->AddRadioTool(wxID_SAVE, _T("Third"), wxBITMAP(save));
494 m_tbar->AddSeparator();
495 m_tbar->AddTool(wxID_HELP, _T("Help"), wxBITMAP(help));
496
497 m_tbar->Realize();
498 }
499
500 LayoutChildren();
501 }
502
503 void MyFrame::OnToggleToolbarSize(wxCommandEvent& WXUNUSED(event))
504 {
505 m_smallToolbar = !m_smallToolbar;
506
507 RecreateToolbar();
508 }
509
510 void MyFrame::OnToggleToolbarRows(wxCommandEvent& WXUNUSED(event))
511 {
512 // m_rows may be only 1 or 2
513 m_rows = 3 - m_rows;
514
515 GetToolBar()->SetRows(m_horzToolbar ? m_rows : 10 / m_rows);
516
517 //RecreateToolbar(); -- this is unneeded
518 }
519
520 void MyFrame::OnToggleToolbarOrient(wxCommandEvent& WXUNUSED(event))
521 {
522 m_horzToolbar = !m_horzToolbar;
523
524 RecreateToolbar();
525 }
526
527 void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
528 {
529 Close(TRUE);
530 }
531
532 void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
533 {
534 (void)wxMessageBox("wxWindows toolbar sample", "About wxToolBar");
535 }
536
537 void MyFrame::OnToolLeftClick(wxCommandEvent& event)
538 {
539 wxString str;
540 str.Printf( _T("Clicked on tool %d\n"), event.GetId());
541 m_textWindow->WriteText( str );
542
543 if (event.GetId() == wxID_HELP)
544 {
545 if ( event.GetExtraLong() != 0 )
546 m_textWindow->WriteText( _T("Help button down now.\n") );
547 else
548 m_textWindow->WriteText( _T("Help button up now.\n") );
549 }
550
551 if (event.GetId() == wxID_COPY)
552 {
553 DoEnablePrint();
554 }
555
556 if (event.GetId() == wxID_CUT)
557 {
558 DoToggleHelp();
559 }
560
561 if (event.GetId() == wxID_PRINT)
562 {
563 DoDeletePrint();
564 }
565 }
566
567 void MyFrame::OnCombo(wxCommandEvent& event)
568 {
569 wxLogStatus(_T("Combobox string '%s' selected"), event.GetString().c_str());
570 }
571
572 void MyFrame::DoEnablePrint()
573 {
574 wxToolBarBase *tb = GetToolBar();
575 if (tb->GetToolEnabled(wxID_PRINT))
576 tb->EnableTool( wxID_PRINT, FALSE );
577 else
578 tb->EnableTool( wxID_PRINT, TRUE );
579 }
580
581 void MyFrame::DoDeletePrint()
582 {
583 wxToolBarBase *tb = GetToolBar();
584
585 tb->DeleteTool( wxID_PRINT );
586 }
587
588 void MyFrame::DoToggleHelp()
589 {
590 wxToolBarBase *tb = GetToolBar();
591 tb->ToggleTool( wxID_HELP, !tb->GetToolState( wxID_HELP ) );
592 }
593
594 void MyFrame::OnUpdateCopyAndCut(wxUpdateUIEvent& event)
595 {
596 event.Enable( m_textWindow->CanCopy() );
597 }
598
599 void MyFrame::OnChangeToolTip(wxCommandEvent& WXUNUSED(event))
600 {
601 GetToolBar()->SetToolShortHelp(wxID_NEW, _T("New toolbar button"));
602 }
603
604 void MyFrame::OnToolbarStyle(wxCommandEvent& event)
605 {
606 long style = GetToolBar()->GetWindowStyle();
607 style &= ~(wxTB_NOICONS | wxTB_TEXT);
608
609 switch ( event.GetId() )
610 {
611 case IDM_TOOLBAR_SHOW_TEXT:
612 style |= wxTB_NOICONS | wxTB_TEXT;
613 break;
614
615 case IDM_TOOLBAR_SHOW_ICONS:
616 // nothing to do
617 break;
618
619 case IDM_TOOLBAR_SHOW_BOTH:
620 style |= wxTB_TEXT;
621 }
622
623 GetToolBar()->SetWindowStyle(style);
624 }
625
626 void MyFrame::OnInsertPrint(wxCommandEvent& WXUNUSED(event))
627 {
628 wxBitmap bmp = wxBITMAP(print);
629
630 GetToolBar()->InsertTool(0, wxID_PRINT, bmp, wxNullBitmap,
631 FALSE, (wxObject *) NULL,
632 "Delete this tool",
633 "This button was inserted into the toolbar");
634
635 GetToolBar()->Realize();
636 }
637
638 void MyFrame::OnToolEnter(wxCommandEvent& event)
639 {
640 if (event.GetSelection() > -1)
641 {
642 wxString str;
643 str.Printf(_T("This is tool number %d"), event.GetSelection());
644 SetStatusText(str);
645 }
646 else
647 SetStatusText("");
648 }
649