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