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