]> git.saurik.com Git - wxWidgets.git/blame - samples/toolbar/toolbar.cpp
SWIGged updates for wxGTK
[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>
8bbe427f 34
ad4ae6ed 35// define this to 1 to use wxToolBarSimple instead of the native one
9fb35cf1 36#define USE_GENERIC_TBAR 0
ad4ae6ed 37
f6bcfd97 38// define this to use XPMs everywhere (by default, BMPs are used under Win)
0ed1d09c 39// BMPs use less space, but aren't compiled into the executable on other platforms
f6bcfd97
BP
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
ba0abe3c 104 void OnToggleToolbar(wxCommandEvent& event);
f6bcfd97
BP
105 void OnToggleAnotherToolbar(wxCommandEvent& event);
106
5ef2e633
VZ
107 void OnToggleToolbarSize(wxCommandEvent& event);
108 void OnToggleToolbarOrient(wxCommandEvent& event);
98066234 109 void OnToggleToolbarRows(wxCommandEvent& event);
5ef2e633 110
ad4ae6ed
VZ
111 void OnEnablePrint(wxCommandEvent& WXUNUSED(event)) { DoEnablePrint(); }
112 void OnDeletePrint(wxCommandEvent& WXUNUSED(event)) { DoDeletePrint(); }
bdc72a22 113 void OnInsertPrint(wxCommandEvent& event);
a1f79c1e 114 void OnChangeToolTip(wxCommandEvent& event);
ad4ae6ed 115 void OnToggleHelp(wxCommandEvent& WXUNUSED(event)) { DoToggleHelp(); }
ad9bb75f 116
ec483b11
VZ
117 void OnToolbarStyle(wxCommandEvent& event);
118
ad9bb75f
VZ
119 void OnToolLeftClick(wxCommandEvent& event);
120 void OnToolEnter(wxCommandEvent& event);
121
1c383dba
VZ
122 void OnCombo(wxCommandEvent& event);
123
5ef2e633
VZ
124 void OnUpdateCopyAndCut(wxUpdateUIEvent& event);
125
ad4ae6ed
VZ
126#if USE_GENERIC_TBAR
127 virtual wxToolBar *OnCreateToolBar(long style,
128 wxWindowID id,
129 const wxString& name );
130#endif // USE_GENERIC_TBAR
131
ad9bb75f
VZ
132private:
133 void DoEnablePrint();
97d7bfb8 134 void DoDeletePrint();
ad9bb75f
VZ
135 void DoToggleHelp();
136
f6bcfd97
BP
137 void LayoutChildren();
138
5ef2e633
VZ
139 bool m_smallToolbar,
140 m_horzToolbar;
98066234
VZ
141 size_t m_rows; // 1 or 2 only
142
f6bcfd97
BP
143 wxTextCtrl *m_textWindow;
144
145 wxToolBar *m_tbar;
ad9bb75f 146
ad9bb75f
VZ
147 DECLARE_EVENT_TABLE()
148};
149
150// ----------------------------------------------------------------------------
151// constants
152// ----------------------------------------------------------------------------
153
154const int ID_TOOLBAR = 500;
155
34d26f42
RR
156static const long TOOLBAR_STYLE = wxTB_FLAT | wxTB_DOCKABLE | wxTB_TEXT ;
157// static const long TOOLBAR_STYLE = 0;
86f65864 158
ad9bb75f 159enum
14d1ccd8 160{
5ef2e633
VZ
161 IDM_TOOLBAR_TOGGLETOOLBARSIZE = 200,
162 IDM_TOOLBAR_TOGGLETOOLBARORIENT,
98066234 163 IDM_TOOLBAR_TOGGLETOOLBARROWS,
ad9bb75f 164 IDM_TOOLBAR_ENABLEPRINT,
97d7bfb8 165 IDM_TOOLBAR_DELETEPRINT,
bdc72a22 166 IDM_TOOLBAR_INSERTPRINT,
1c383dba 167 IDM_TOOLBAR_TOGGLEHELP,
ba0abe3c 168 IDM_TOOLBAR_TOGGLE_TOOLBAR,
f6bcfd97 169 IDM_TOOLBAR_TOGGLE_ANOTHER_TOOLBAR,
a1f79c1e 170 IDM_TOOLBAR_CHANGE_TOOLTIP,
ec483b11
VZ
171 IDM_TOOLBAR_SHOW_TEXT,
172 IDM_TOOLBAR_SHOW_ICONS,
173 IDM_TOOLBAR_SHOW_BOTH,
1c383dba
VZ
174
175 ID_COMBO = 1000
ad9bb75f 176};
14d1ccd8 177
ad9bb75f
VZ
178// ----------------------------------------------------------------------------
179// event tables
180// ----------------------------------------------------------------------------
14d1ccd8 181
ad9bb75f
VZ
182// Notice that wxID_HELP will be processed for the 'About' menu and the toolbar
183// help button.
14d1ccd8 184
ad9bb75f 185BEGIN_EVENT_TABLE(MyFrame, wxFrame)
f6bcfd97
BP
186 EVT_SIZE(MyFrame::OnSize)
187
ad9bb75f
VZ
188 EVT_MENU(wxID_EXIT, MyFrame::OnQuit)
189 EVT_MENU(wxID_HELP, MyFrame::OnAbout)
14d1ccd8 190
ba0abe3c 191 EVT_MENU(IDM_TOOLBAR_TOGGLE_TOOLBAR, MyFrame::OnToggleToolbar)
f6bcfd97
BP
192 EVT_MENU(IDM_TOOLBAR_TOGGLE_ANOTHER_TOOLBAR, MyFrame::OnToggleAnotherToolbar)
193
5ef2e633
VZ
194 EVT_MENU(IDM_TOOLBAR_TOGGLETOOLBARSIZE, MyFrame::OnToggleToolbarSize)
195 EVT_MENU(IDM_TOOLBAR_TOGGLETOOLBARORIENT, MyFrame::OnToggleToolbarOrient)
98066234 196 EVT_MENU(IDM_TOOLBAR_TOGGLETOOLBARROWS, MyFrame::OnToggleToolbarRows)
5ef2e633 197
ad9bb75f 198 EVT_MENU(IDM_TOOLBAR_ENABLEPRINT, MyFrame::OnEnablePrint)
97d7bfb8 199 EVT_MENU(IDM_TOOLBAR_DELETEPRINT, MyFrame::OnDeletePrint)
bdc72a22 200 EVT_MENU(IDM_TOOLBAR_INSERTPRINT, MyFrame::OnInsertPrint)
ad9bb75f 201 EVT_MENU(IDM_TOOLBAR_TOGGLEHELP, MyFrame::OnToggleHelp)
a1f79c1e 202 EVT_MENU(IDM_TOOLBAR_CHANGE_TOOLTIP, MyFrame::OnChangeToolTip)
14d1ccd8 203
ec483b11
VZ
204 EVT_MENU_RANGE(IDM_TOOLBAR_SHOW_TEXT, IDM_TOOLBAR_SHOW_BOTH,
205 MyFrame::OnToolbarStyle)
206
ad9bb75f 207 EVT_MENU(-1, MyFrame::OnToolLeftClick)
14d1ccd8 208
1c383dba
VZ
209 EVT_COMBOBOX(ID_COMBO, MyFrame::OnCombo)
210
ad9bb75f 211 EVT_TOOL_ENTER(ID_TOOLBAR, MyFrame::OnToolEnter)
5ef2e633
VZ
212
213 EVT_UPDATE_UI(wxID_COPY, MyFrame::OnUpdateCopyAndCut)
214 EVT_UPDATE_UI(wxID_CUT, MyFrame::OnUpdateCopyAndCut)
ad9bb75f 215END_EVENT_TABLE()
14d1ccd8 216
ad9bb75f
VZ
217// ============================================================================
218// implementation
219// ============================================================================
14d1ccd8 220
ad9bb75f
VZ
221// ----------------------------------------------------------------------------
222// MyApp
223// ----------------------------------------------------------------------------
14d1ccd8 224
ad9bb75f 225IMPLEMENT_APP(MyApp)
14d1ccd8 226
ad9bb75f
VZ
227// The `main program' equivalent, creating the windows and returning the
228// main frame
229bool MyApp::OnInit()
230{
231 // Create the main frame window
232 MyFrame* frame = new MyFrame((wxFrame *) NULL, -1,
233 "wxToolBar Sample",
c631abda 234 wxPoint(100, 100), wxSize(550, 300));
14d1ccd8 235
7fb23305
VZ
236 frame->Show(TRUE);
237
238 frame->SetStatusText("Hello, wxWindows");
239
240 SetTopWindow(frame);
241
242 return TRUE;
14d1ccd8
JS
243}
244
5ef2e633 245void MyFrame::RecreateToolbar()
14d1ccd8 246{
5ef2e633 247 // delete and recreate the toolbar
ad4ae6ed 248 wxToolBarBase *toolBar = GetToolBar();
ec483b11
VZ
249 long style = toolBar ? toolBar->GetWindowStyle() : TOOLBAR_STYLE;
250
5ef2e633 251 delete toolBar;
14d1ccd8 252
5ef2e633
VZ
253 SetToolBar(NULL);
254
ec483b11 255 style &= ~(wxTB_HORIZONTAL | wxTB_VERTICAL);
5ef2e633
VZ
256 style |= m_horzToolbar ? wxTB_HORIZONTAL : wxTB_VERTICAL;
257
258 toolBar = CreateToolBar(style, ID_TOOLBAR);
2b69aeaa 259 //toolBar->SetMargins( 4, 4 );
5ef2e633
VZ
260
261 // Set up toolbar
262 wxBitmap toolBarBitmaps[8];
263
f6bcfd97
BP
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
5ef2e633
VZ
274 toolBarBitmaps[0] = wxBITMAP(new);
275 toolBarBitmaps[1] = wxBITMAP(open);
40515a21
VZ
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);
f6bcfd97 282#endif // USE_XPM_BITMAPS/!USE_XPM_BITMAPS
40515a21 283
5ef2e633
VZ
284 if ( !m_smallToolbar )
285 {
40515a21
VZ
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] =
368d59f0 291 wxBitmap(toolBarBitmaps[n].ConvertToImage().Scale(w, h));
40515a21
VZ
292 }
293
294 toolBar->SetToolBitmapSize(wxSize(w, h));
5ef2e633 295 }
14d1ccd8 296
ec483b11
VZ
297 toolBar->AddTool(wxID_NEW, _T("New"), toolBarBitmaps[0], _T("New file"));
298 toolBar->AddTool(wxID_OPEN, _T("Open"), toolBarBitmaps[1], _T("Open file"));
14d1ccd8 299
ad4ae6ed 300 // neither the generic nor Motif native toolbars really support this
16c9a425 301#if (wxUSE_TOOLBAR_NATIVE && !USE_GENERIC_TBAR) && !defined(__WXMOTIF__) && !defined(__WXX11__)
5ef2e633
VZ
302 // adding a combo to a vertical toolbar is not very smart
303 if ( m_horzToolbar )
304 {
47c93b63 305 wxComboBox *combo = new wxComboBox(toolBar, ID_COMBO, "", wxDefaultPosition, wxSize(200,-1) );
5ef2e633
VZ
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 }
ad4ae6ed 313#endif // toolbars which don't support controls
14d1ccd8 314
ec483b11
VZ
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"));
40515a21 320 toolBar->AddSeparator();
ec483b11 321 toolBar->AddTool(wxID_HELP, _T("Help"), toolBarBitmaps[7], _T("Help button"), wxITEM_CHECK);
13437238 322
5ef2e633
VZ
323 // after adding the buttons to the toolbar, must call Realize() to reflect
324 // the changes
325 toolBar->Realize();
98066234
VZ
326
327 toolBar->SetRows(m_horzToolbar ? m_rows : 10 / m_rows);
14d1ccd8
JS
328}
329
ad9bb75f
VZ
330// ----------------------------------------------------------------------------
331// MyFrame
332// ----------------------------------------------------------------------------
13437238
JS
333
334// Define my frame constructor
7fb23305
VZ
335MyFrame::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)
14d1ccd8 342{
f6bcfd97 343 m_tbar = NULL;
e179bd65 344 m_textWindow = new wxTextCtrl(this, -1, "", wxPoint(0, 0), wxSize(-1, -1), wxTE_MULTILINE);
98066234 345
40515a21 346 m_smallToolbar = TRUE;
98066234
VZ
347 m_horzToolbar = TRUE;
348 m_rows = 1;
ad9bb75f
VZ
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;
ba0abe3c
VZ
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");
5ef2e633
VZ
377
378 tbarMenu->AppendSeparator();
379
fc6bbc6d
VZ
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", "");
a1f79c1e
VZ
384 tbarMenu->AppendSeparator();
385 tbarMenu->Append(IDM_TOOLBAR_CHANGE_TOOLTIP, "Change tool tip", "");
ec483b11
VZ
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");
b487a08f 390
ad9bb75f 391 wxMenu *fileMenu = new wxMenu;
ec483b11 392 fileMenu->Append(wxID_EXIT, "E&xit\tAlt-X", "Quit toolbar sample" );
ad9bb75f 393
ad9bb75f
VZ
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");
ad9bb75f
VZ
401 menuBar->Append(helpMenu, "&Help");
402
403 // Associate the menu bar with the frame
404 SetMenuBar(menuBar);
405
c631abda
VZ
406 menuBar->Check(IDM_TOOLBAR_SHOW_BOTH, TRUE);
407
ad9bb75f 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
ba0abe3c
VZ
457void 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
f6bcfd97
BP
473void MyFrame::OnToggleAnotherToolbar(wxCommandEvent& WXUNUSED(event))
474{
475 if ( m_tbar )
476 {
477 delete m_tbar;
478 m_tbar = NULL;
479 }
480 else
481 {
ec483b11
VZ
482 long style = GetToolBar()->GetWindowStyle();
483 style &= ~wxTB_HORIZONTAL;
484 style |= wxTB_VERTICAL;
485
f6bcfd97
BP
486 m_tbar = new wxToolBar(this, -1,
487 wxDefaultPosition, wxDefaultSize,
ec483b11
VZ
488 style);
489
490 m_tbar->AddRadioTool(wxID_NEW, _T("First"), wxBITMAP(new));
c631abda
VZ
491 m_tbar->AddRadioTool(wxID_OPEN, _T("Second"), wxBITMAP(open));
492 m_tbar->AddRadioTool(wxID_SAVE, _T("Third"), wxBITMAP(save));
ec483b11
VZ
493 m_tbar->AddSeparator();
494 m_tbar->AddTool(wxID_HELP, _T("Help"), wxBITMAP(help));
495
f6bcfd97
BP
496 m_tbar->Realize();
497 }
498
499 LayoutChildren();
500}
501
5ef2e633
VZ
502void MyFrame::OnToggleToolbarSize(wxCommandEvent& WXUNUSED(event))
503{
504 m_smallToolbar = !m_smallToolbar;
ad9bb75f 505
5ef2e633 506 RecreateToolbar();
7fb23305
VZ
507}
508
98066234
VZ
509void 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
9fb35cf1 516 //RecreateToolbar(); -- this is unneeded
98066234
VZ
517}
518
5ef2e633 519void MyFrame::OnToggleToolbarOrient(wxCommandEvent& WXUNUSED(event))
7fb23305 520{
5ef2e633 521 m_horzToolbar = !m_horzToolbar;
7fb23305 522
5ef2e633 523 RecreateToolbar();
14d1ccd8
JS
524}
525
47908e25 526void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
14d1ccd8 527{
13437238 528 Close(TRUE);
14d1ccd8
JS
529}
530
47908e25 531void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
14d1ccd8 532{
1d5b7a0b 533 (void)wxMessageBox("wxWindows toolbar sample", "About wxToolBar");
13437238 534}
14d1ccd8 535
13437238
JS
536void MyFrame::OnToolLeftClick(wxCommandEvent& event)
537{
e179bd65
RR
538 wxString str;
539 str.Printf( _T("Clicked on tool %d\n"), event.GetId());
540 m_textWindow->WriteText( str );
ad9bb75f 541
e179bd65
RR
542 if (event.GetId() == wxID_HELP)
543 {
ad9bb75f 544 if ( event.GetExtraLong() != 0 )
e179bd65
RR
545 m_textWindow->WriteText( _T("Help button down now.\n") );
546 else
547 m_textWindow->WriteText( _T("Help button up now.\n") );
548 }
ad9bb75f 549
e179bd65
RR
550 if (event.GetId() == wxID_COPY)
551 {
7fb23305 552 DoEnablePrint();
e179bd65 553 }
ad9bb75f 554
e179bd65
RR
555 if (event.GetId() == wxID_CUT)
556 {
7fb23305 557 DoToggleHelp();
e179bd65 558 }
1c4f8f8d 559
97d7bfb8
RR
560 if (event.GetId() == wxID_PRINT)
561 {
562 DoDeletePrint();
563 }
14d1ccd8
JS
564}
565
1c383dba
VZ
566void MyFrame::OnCombo(wxCommandEvent& event)
567{
568 wxLogStatus(_T("Combobox string '%s' selected"), event.GetString().c_str());
569}
570
7fb23305
VZ
571void MyFrame::DoEnablePrint()
572{
ad4ae6ed 573 wxToolBarBase *tb = GetToolBar();
7fb23305
VZ
574 if (tb->GetToolEnabled(wxID_PRINT))
575 tb->EnableTool( wxID_PRINT, FALSE );
576 else
577 tb->EnableTool( wxID_PRINT, TRUE );
578}
579
97d7bfb8
RR
580void MyFrame::DoDeletePrint()
581{
ad4ae6ed 582 wxToolBarBase *tb = GetToolBar();
1c4f8f8d 583
97d7bfb8
RR
584 tb->DeleteTool( wxID_PRINT );
585}
586
7fb23305
VZ
587void MyFrame::DoToggleHelp()
588{
ad4ae6ed 589 wxToolBarBase *tb = GetToolBar();
7fb23305
VZ
590 tb->ToggleTool( wxID_HELP, !tb->GetToolState( wxID_HELP ) );
591}
592
5ef2e633
VZ
593void MyFrame::OnUpdateCopyAndCut(wxUpdateUIEvent& event)
594{
595 event.Enable( m_textWindow->CanCopy() );
596}
597
a1f79c1e
VZ
598void MyFrame::OnChangeToolTip(wxCommandEvent& WXUNUSED(event))
599{
600 GetToolBar()->SetToolShortHelp(wxID_NEW, _T("New toolbar button"));
601}
602
ec483b11
VZ
603void 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
bdc72a22
VZ
625void MyFrame::OnInsertPrint(wxCommandEvent& WXUNUSED(event))
626{
5ef2e633 627 wxBitmap bmp = wxBITMAP(print);
bdc72a22 628
fc6bbc6d 629 GetToolBar()->InsertTool(0, wxID_PRINT, bmp, wxNullBitmap,
5ef2e633
VZ
630 FALSE, (wxObject *) NULL,
631 "Delete this tool",
632 "This button was inserted into the toolbar");
bdc72a22
VZ
633
634 GetToolBar()->Realize();
635}
636
13437238
JS
637void MyFrame::OnToolEnter(wxCommandEvent& event)
638{
ad4ae6ed
VZ
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("");
13437238 647}
14d1ccd8 648