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