]> git.saurik.com Git - wxWidgets.git/blame - samples/toolbar/toolbar.cpp
Allow more than one line in a wxStaticText on iOS.
[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
14d1ccd8 7// Copyright: (c) Julian Smart
ad9bb75f 8// Licence: wxWindows licence
14d1ccd8
JS
9/////////////////////////////////////////////////////////////////////////////
10
ad9bb75f
VZ
11// ============================================================================
12// declarations
13// ============================================================================
14
15// ----------------------------------------------------------------------------
16// headers
17// ----------------------------------------------------------------------------
18
14d1ccd8 19// For compilers that support precompilation, includes "wx/wx.h".
92a19c2e 20#include "wx/wxprec.h"
14d1ccd8
JS
21
22#ifdef __BORLANDC__
ad9bb75f 23 #pragma hdrstop
14d1ccd8
JS
24#endif
25
26#ifndef WX_PRECOMP
5f4d35b8 27 #include "wx/wx.h"
14d1ccd8
JS
28#endif
29
5f4d35b8
WS
30#include "wx/toolbar.h"
31#include "wx/log.h"
32#include "wx/image.h"
5e3b8b93 33#include "wx/filedlg.h"
211df056 34#include "wx/colordlg.h"
b529726e 35#include "wx/srchctrl.h"
8bbe427f 36
f6bcfd97 37// define this to use XPMs everywhere (by default, BMPs are used under Win)
0ed1d09c 38// BMPs use less space, but aren't compiled into the executable on other platforms
bb5a9514 39#ifdef __WINDOWS__
f6bcfd97
BP
40 #define USE_XPM_BITMAPS 0
41#else
42 #define USE_XPM_BITMAPS 1
43#endif
44
079b2f6b
JS
45// If this is 1, the sample will test an extra toolbar identical to the
46// main one, but not managed by the frame. This can test subtle differences
47// in the way toolbars are handled, especially on Mac where there is one
48// native, 'installed' toolbar.
49#define USE_UNMANAGED_TOOLBAR 0
50
1be45608
VZ
51// Define this as 0 for the platforms not supporting controls in toolbars
52#define USE_CONTROLS_IN_TOOLBAR 1
53
ad9bb75f
VZ
54// ----------------------------------------------------------------------------
55// resources
56// ----------------------------------------------------------------------------
14d1ccd8 57
e7092398 58#ifndef wxHAS_IMAGES_IN_RESOURCES
3cb332c1 59 #include "../sample.xpm"
5f4d35b8
WS
60#endif
61
62#if USE_XPM_BITMAPS
ad9bb75f
VZ
63 #include "bitmaps/new.xpm"
64 #include "bitmaps/open.xpm"
65 #include "bitmaps/save.xpm"
66 #include "bitmaps/copy.xpm"
67 #include "bitmaps/cut.xpm"
5ef2e633 68 #include "bitmaps/preview.xpm" // paste XPM
ad9bb75f 69 #include "bitmaps/print.xpm"
ad9bb75f 70 #include "bitmaps/help.xpm"
f6bcfd97 71#endif // USE_XPM_BITMAPS
ad9bb75f 72
7a976304
VZ
73enum Positions
74{
75 TOOLBAR_LEFT,
76 TOOLBAR_TOP,
77 TOOLBAR_RIGHT,
78 TOOLBAR_BOTTOM
79};
80
ad9bb75f
VZ
81// ----------------------------------------------------------------------------
82// classes
83// ----------------------------------------------------------------------------
84
85// Define a new application
5ef2e633 86class MyApp : public wxApp
ad9bb75f
VZ
87{
88public:
89 bool OnInit();
ad9bb75f 90};
47908e25 91
ad9bb75f
VZ
92// Define a new frame
93class MyFrame: public wxFrame
94{
95public:
96 MyFrame(wxFrame *parent,
bc2ec626 97 wxWindowID id = wxID_ANY,
9a83f860 98 const wxString& title = wxT("wxToolBar Sample"),
ad9bb75f
VZ
99 const wxPoint& pos = wxDefaultPosition,
100 const wxSize& size = wxDefaultSize,
229de929 101 long style = wxDEFAULT_FRAME_STYLE|wxCLIP_CHILDREN|wxNO_FULL_REPAINT_ON_RESIZE);
1be45608 102 virtual ~MyFrame();
14d1ccd8 103
079b2f6b 104 void PopulateToolbar(wxToolBarBase* toolBar);
5ef2e633
VZ
105 void RecreateToolbar();
106
ad9bb75f
VZ
107 void OnQuit(wxCommandEvent& event);
108 void OnAbout(wxCommandEvent& event);
109
f6bcfd97
BP
110 void OnSize(wxSizeEvent& event);
111
ba0abe3c 112 void OnToggleToolbar(wxCommandEvent& event);
f6bcfd97 113 void OnToggleAnotherToolbar(wxCommandEvent& event);
96dc4236 114 void OnToggleHorizontalText(wxCommandEvent& WXUNUSED(event));
f6bcfd97 115
5ef2e633 116 void OnToggleToolbarSize(wxCommandEvent& event);
7a976304 117 void OnChangeOrientation(wxCommandEvent& event);
98066234 118 void OnToggleToolbarRows(wxCommandEvent& event);
6a1b3ead 119 void OnToggleTooltips(wxCommandEvent& event);
8d0a7b56 120 void OnToggleCustomDisabled(wxCommandEvent& event);
5ef2e633 121
ad4ae6ed
VZ
122 void OnEnablePrint(wxCommandEvent& WXUNUSED(event)) { DoEnablePrint(); }
123 void OnDeletePrint(wxCommandEvent& WXUNUSED(event)) { DoDeletePrint(); }
bdc72a22 124 void OnInsertPrint(wxCommandEvent& event);
a1f79c1e 125 void OnChangeToolTip(wxCommandEvent& event);
ad4ae6ed 126 void OnToggleHelp(wxCommandEvent& WXUNUSED(event)) { DoToggleHelp(); }
1be45608 127 void OnToggleSearch(wxCommandEvent& event);
3bf4189d 128 void OnToggleRadioBtn(wxCommandEvent& event);
ad9bb75f 129
ec483b11 130 void OnToolbarStyle(wxCommandEvent& event);
211df056 131 void OnToolbarBgCol(wxCommandEvent& event);
5e3b8b93 132 void OnToolbarCustomBitmap(wxCommandEvent& event);
ec483b11 133
ad9bb75f 134 void OnToolLeftClick(wxCommandEvent& event);
e052a316 135 void OnToolRightClick(wxCommandEvent& event);
a9a0ceca 136 void OnToolDropdown(wxCommandEvent& event);
ad9bb75f 137
1c383dba
VZ
138 void OnCombo(wxCommandEvent& event);
139
5ef2e633 140 void OnUpdateCopyAndCut(wxUpdateUIEvent& event);
96dc4236 141 void OnUpdateToggleHorzText(wxUpdateUIEvent& event);
3bf4189d
VZ
142 void OnUpdateToggleRadioBtn(wxUpdateUIEvent& event)
143 { event.Enable( m_tbar != NULL ); }
5ef2e633 144
ad9bb75f
VZ
145private:
146 void DoEnablePrint();
97d7bfb8 147 void DoDeletePrint();
ad9bb75f
VZ
148 void DoToggleHelp();
149
f6bcfd97
BP
150 void LayoutChildren();
151
5ef2e633 152 bool m_smallToolbar,
8d0a7b56 153 m_horzText,
6a1b3ead
VZ
154 m_useCustomDisabled,
155 m_showTooltips;
98066234
VZ
156 size_t m_rows; // 1 or 2 only
157
2b5f62a0
VZ
158 // the number of print buttons we have (they're added/removed dynamically)
159 size_t m_nPrint;
160
7a976304
VZ
161 // store toolbar position for future use
162 Positions m_toolbarPosition;
163
f6bcfd97
BP
164 wxTextCtrl *m_textWindow;
165
079b2f6b 166 wxPanel *m_panel;
1be45608 167#if USE_UNMANAGED_TOOLBAR
079b2f6b 168 wxToolBar *m_extraToolBar;
1be45608 169#endif
079b2f6b 170
f6bcfd97 171 wxToolBar *m_tbar;
ad9bb75f 172
5e3b8b93
VZ
173 // the path to the custom bitmap for the test toolbar tool
174 wxString m_pathBmp;
175
1be45608
VZ
176 // the search tool, initially NULL
177 wxToolBarToolBase *m_searchTool;
178
ad9bb75f
VZ
179 DECLARE_EVENT_TABLE()
180};
181
182// ----------------------------------------------------------------------------
183// constants
184// ----------------------------------------------------------------------------
185
186const int ID_TOOLBAR = 500;
187
dd46ee66 188static const long TOOLBAR_STYLE = wxTB_FLAT | wxTB_DOCKABLE | wxTB_TEXT;
86f65864 189
ad9bb75f 190enum
14d1ccd8 191{
1be45608
VZ
192 // toolbar menu items
193 IDM_TOOLBAR_TOGGLE_TOOLBAR = 200,
194 IDM_TOOLBAR_TOGGLE_HORIZONTAL_TEXT,
195 IDM_TOOLBAR_TOGGLE_ANOTHER_TOOLBAR,
196 IDM_TOOLBAR_TOGGLETOOLBARSIZE,
98066234 197 IDM_TOOLBAR_TOGGLETOOLBARROWS,
6a1b3ead 198 IDM_TOOLBAR_TOGGLETOOLTIPS,
8d0a7b56 199 IDM_TOOLBAR_TOGGLECUSTOMDISABLED,
ec483b11
VZ
200 IDM_TOOLBAR_SHOW_TEXT,
201 IDM_TOOLBAR_SHOW_ICONS,
202 IDM_TOOLBAR_SHOW_BOTH,
211df056 203 IDM_TOOLBAR_BG_COL,
5e3b8b93 204 IDM_TOOLBAR_CUSTOM_PATH,
7a976304
VZ
205 IDM_TOOLBAR_TOP_ORIENTATION,
206 IDM_TOOLBAR_LEFT_ORIENTATION,
5b2acc3a 207 IDM_TOOLBAR_BOTTOM_ORIENTATION,
7a976304 208 IDM_TOOLBAR_RIGHT_ORIENTATION,
3bf4189d
VZ
209 IDM_TOOLBAR_OTHER_1,
210 IDM_TOOLBAR_OTHER_2,
211 IDM_TOOLBAR_OTHER_3,
212
1be45608
VZ
213 // tools menu items
214 IDM_TOOLBAR_ENABLEPRINT,
215 IDM_TOOLBAR_DELETEPRINT,
216 IDM_TOOLBAR_INSERTPRINT,
217 IDM_TOOLBAR_TOGGLEHELP,
218 IDM_TOOLBAR_TOGGLESEARCH,
219 IDM_TOOLBAR_TOGGLERADIOBTN1,
220 IDM_TOOLBAR_TOGGLERADIOBTN2,
221 IDM_TOOLBAR_TOGGLERADIOBTN3,
222 IDM_TOOLBAR_CHANGE_TOOLTIP,
223
224 ID_COMBO = 1000
ad9bb75f 225};
14d1ccd8 226
ad9bb75f
VZ
227// ----------------------------------------------------------------------------
228// event tables
229// ----------------------------------------------------------------------------
14d1ccd8 230
ad9bb75f
VZ
231// Notice that wxID_HELP will be processed for the 'About' menu and the toolbar
232// help button.
14d1ccd8 233
ad9bb75f 234BEGIN_EVENT_TABLE(MyFrame, wxFrame)
f6bcfd97
BP
235 EVT_SIZE(MyFrame::OnSize)
236
ad9bb75f
VZ
237 EVT_MENU(wxID_EXIT, MyFrame::OnQuit)
238 EVT_MENU(wxID_HELP, MyFrame::OnAbout)
14d1ccd8 239
ba0abe3c 240 EVT_MENU(IDM_TOOLBAR_TOGGLE_TOOLBAR, MyFrame::OnToggleToolbar)
f6bcfd97 241 EVT_MENU(IDM_TOOLBAR_TOGGLE_ANOTHER_TOOLBAR, MyFrame::OnToggleAnotherToolbar)
96dc4236 242 EVT_MENU(IDM_TOOLBAR_TOGGLE_HORIZONTAL_TEXT, MyFrame::OnToggleHorizontalText)
f6bcfd97 243
7a976304 244 EVT_MENU_RANGE(IDM_TOOLBAR_TOP_ORIENTATION, IDM_TOOLBAR_RIGHT_ORIENTATION, MyFrame::OnChangeOrientation)
5ef2e633 245 EVT_MENU(IDM_TOOLBAR_TOGGLETOOLBARSIZE, MyFrame::OnToggleToolbarSize)
98066234 246 EVT_MENU(IDM_TOOLBAR_TOGGLETOOLBARROWS, MyFrame::OnToggleToolbarRows)
6a1b3ead 247 EVT_MENU(IDM_TOOLBAR_TOGGLETOOLTIPS, MyFrame::OnToggleTooltips)
8d0a7b56 248 EVT_MENU(IDM_TOOLBAR_TOGGLECUSTOMDISABLED, MyFrame::OnToggleCustomDisabled)
5ef2e633 249
ad9bb75f 250 EVT_MENU(IDM_TOOLBAR_ENABLEPRINT, MyFrame::OnEnablePrint)
97d7bfb8 251 EVT_MENU(IDM_TOOLBAR_DELETEPRINT, MyFrame::OnDeletePrint)
bdc72a22 252 EVT_MENU(IDM_TOOLBAR_INSERTPRINT, MyFrame::OnInsertPrint)
ad9bb75f 253 EVT_MENU(IDM_TOOLBAR_TOGGLEHELP, MyFrame::OnToggleHelp)
1be45608 254 EVT_MENU(IDM_TOOLBAR_TOGGLESEARCH, MyFrame::OnToggleSearch)
3bf4189d
VZ
255 EVT_MENU_RANGE(IDM_TOOLBAR_TOGGLERADIOBTN1, IDM_TOOLBAR_TOGGLERADIOBTN3,
256 MyFrame::OnToggleRadioBtn)
a1f79c1e 257 EVT_MENU(IDM_TOOLBAR_CHANGE_TOOLTIP, MyFrame::OnChangeToolTip)
14d1ccd8 258
ec483b11
VZ
259 EVT_MENU_RANGE(IDM_TOOLBAR_SHOW_TEXT, IDM_TOOLBAR_SHOW_BOTH,
260 MyFrame::OnToolbarStyle)
211df056 261 EVT_MENU(IDM_TOOLBAR_BG_COL, MyFrame::OnToolbarBgCol)
ec483b11 262
5e3b8b93
VZ
263 EVT_MENU(IDM_TOOLBAR_CUSTOM_PATH, MyFrame::OnToolbarCustomBitmap)
264
bc2ec626 265 EVT_MENU(wxID_ANY, MyFrame::OnToolLeftClick)
14d1ccd8 266
1c383dba
VZ
267 EVT_COMBOBOX(ID_COMBO, MyFrame::OnCombo)
268
e052a316 269 EVT_TOOL_RCLICKED(wxID_ANY, MyFrame::OnToolRightClick)
5ef2e633 270
a9a0ceca
VZ
271 EVT_TOOL_DROPDOWN(wxID_ANY, MyFrame::OnToolDropdown)
272
5ef2e633
VZ
273 EVT_UPDATE_UI(wxID_COPY, MyFrame::OnUpdateCopyAndCut)
274 EVT_UPDATE_UI(wxID_CUT, MyFrame::OnUpdateCopyAndCut)
96dc4236 275
3bf4189d
VZ
276 EVT_UPDATE_UI_RANGE(IDM_TOOLBAR_TOGGLERADIOBTN1,
277 IDM_TOOLBAR_TOGGLERADIOBTN3,
278 MyFrame::OnUpdateToggleRadioBtn)
96dc4236
VZ
279 EVT_UPDATE_UI(IDM_TOOLBAR_TOGGLE_HORIZONTAL_TEXT,
280 MyFrame::OnUpdateToggleHorzText)
ad9bb75f 281END_EVENT_TABLE()
14d1ccd8 282
ad9bb75f
VZ
283// ============================================================================
284// implementation
285// ============================================================================
14d1ccd8 286
ad9bb75f
VZ
287// ----------------------------------------------------------------------------
288// MyApp
289// ----------------------------------------------------------------------------
14d1ccd8 290
ad9bb75f 291IMPLEMENT_APP(MyApp)
14d1ccd8 292
ad9bb75f
VZ
293// The `main program' equivalent, creating the windows and returning the
294// main frame
295bool MyApp::OnInit()
296{
45e6e6f8
VZ
297 if ( !wxApp::OnInit() )
298 return false;
299
ad9bb75f 300 // Create the main frame window
bc2ec626 301 MyFrame* frame = new MyFrame((wxFrame *) NULL, wxID_ANY,
9a83f860 302 wxT("wxToolBar Sample"),
cc260109 303 wxPoint(100, 100), wxSize(650, 300));
14d1ccd8 304
bc2ec626 305 frame->Show(true);
7fb23305 306
8520f137 307#if wxUSE_STATUSBAR
9a83f860 308 frame->SetStatusText(wxT("Hello, wxWidgets"));
0cfc2a92 309#endif
7fb23305 310
5e3b8b93
VZ
311 wxInitAllImageHandlers();
312
bc2ec626 313 return true;
14d1ccd8
JS
314}
315
5ef2e633 316void MyFrame::RecreateToolbar()
14d1ccd8 317{
bf95a04f
JS
318#ifdef __WXWINCE__
319 // On Windows CE, we should not delete the
320 // previous toolbar in case it contains the menubar.
34621cc5 321 // We'll try to accommodate this usage in due course.
bf95a04f
JS
322 wxToolBar* toolBar = CreateToolBar();
323#else
5ef2e633 324 // delete and recreate the toolbar
ad4ae6ed 325 wxToolBarBase *toolBar = GetToolBar();
ec483b11
VZ
326 long style = toolBar ? toolBar->GetWindowStyle() : TOOLBAR_STYLE;
327
dea482c9
PC
328 if (toolBar && m_searchTool && m_searchTool->GetToolBar() == NULL)
329 {
330 // see ~MyFrame()
331 toolBar->AddTool(m_searchTool);
332 }
333 m_searchTool = NULL;
334
5ef2e633 335 delete toolBar;
14d1ccd8 336
5ef2e633
VZ
337 SetToolBar(NULL);
338
7a976304
VZ
339 style &= ~(wxTB_HORIZONTAL | wxTB_VERTICAL | wxTB_BOTTOM | wxTB_RIGHT | wxTB_HORZ_LAYOUT);
340 switch( m_toolbarPosition )
341 {
342 case TOOLBAR_LEFT:
343 style |= wxTB_LEFT;
344 break;
345 case TOOLBAR_TOP:
346 style |= wxTB_TOP;
347 break;
348 case TOOLBAR_RIGHT:
349 style |= wxTB_RIGHT;
350 break;
351 case TOOLBAR_BOTTOM:
5b2acc3a 352 style |= wxTB_BOTTOM;
7a976304
VZ
353 break;
354 }
96dc4236 355
6a1b3ead
VZ
356 if ( m_showTooltips )
357 style &= ~wxTB_NO_TOOLTIPS;
358 else
359 style |= wxTB_NO_TOOLTIPS;
360
96dc4236
VZ
361 if ( style & wxTB_TEXT && !(style & wxTB_NOICONS) && m_horzText )
362 style |= wxTB_HORZ_LAYOUT;
5ef2e633
VZ
363
364 toolBar = CreateToolBar(style, ID_TOOLBAR);
bf95a04f 365#endif
5ef2e633 366
079b2f6b
JS
367 PopulateToolbar(toolBar);
368}
369
370void MyFrame::PopulateToolbar(wxToolBarBase* toolBar)
371{
5ef2e633 372 // Set up toolbar
8d0a7b56
VZ
373 enum
374 {
375 Tool_new,
376 Tool_open,
377 Tool_save,
378 Tool_copy,
379 Tool_cut,
380 Tool_paste,
381 Tool_print,
382 Tool_help,
383 Tool_Max
384 };
385
386 wxBitmap toolBarBitmaps[Tool_Max];
5ef2e633 387
f6bcfd97 388#if USE_XPM_BITMAPS
8d0a7b56
VZ
389 #define INIT_TOOL_BMP(bmp) \
390 toolBarBitmaps[Tool_##bmp] = wxBitmap(bmp##_xpm)
f6bcfd97 391#else // !USE_XPM_BITMAPS
8d0a7b56
VZ
392 #define INIT_TOOL_BMP(bmp) \
393 toolBarBitmaps[Tool_##bmp] = wxBITMAP(bmp)
f6bcfd97 394#endif // USE_XPM_BITMAPS/!USE_XPM_BITMAPS
40515a21 395
8d0a7b56
VZ
396 INIT_TOOL_BMP(new);
397 INIT_TOOL_BMP(open);
398 INIT_TOOL_BMP(save);
399 INIT_TOOL_BMP(copy);
400 INIT_TOOL_BMP(cut);
401 INIT_TOOL_BMP(paste);
402 INIT_TOOL_BMP(print);
403 INIT_TOOL_BMP(help);
efdb961d 404
8d0a7b56
VZ
405 int w = toolBarBitmaps[Tool_new].GetWidth(),
406 h = toolBarBitmaps[Tool_new].GetHeight();
407
5ef2e633
VZ
408 if ( !m_smallToolbar )
409 {
8d0a7b56
VZ
410 w *= 2;
411 h *= 2;
412
413 for ( size_t n = Tool_new; n < WXSIZEOF(toolBarBitmaps); n++ )
40515a21
VZ
414 {
415 toolBarBitmaps[n] =
368d59f0 416 wxBitmap(toolBarBitmaps[n].ConvertToImage().Scale(w, h));
40515a21 417 }
5ef2e633 418 }
14d1ccd8 419
040d3c2e
VZ
420 // this call is actually unnecessary as the toolbar will adjust its tools
421 // size to fit the biggest icon used anyhow but it doesn't hurt neither
6a1b3ead
VZ
422 toolBar->SetToolBitmapSize(wxSize(w, h));
423
9a83f860 424 toolBar->AddTool(wxID_NEW, wxT("New"),
a9a0ceca 425 toolBarBitmaps[Tool_new], wxNullBitmap, wxITEM_DROPDOWN,
9a83f860 426 wxT("New file"), wxT("This is help for new file tool"));
a9a0ceca
VZ
427
428 wxMenu* menu = new wxMenu;
9a83f860
VZ
429 menu->Append(wxID_ANY, wxT("&First dummy item"));
430 menu->Append(wxID_ANY, wxT("&Second dummy item"));
a9a0ceca 431 menu->AppendSeparator();
9a83f860 432 menu->Append(wxID_EXIT, wxT("Exit"));
a9a0ceca
VZ
433 toolBar->SetDropdownMenu(wxID_NEW, menu);
434
9a83f860 435 toolBar->AddTool(wxID_OPEN, wxT("Open"),
e112f019 436 toolBarBitmaps[Tool_open], wxNullBitmap, wxITEM_NORMAL,
9a83f860 437 wxT("Open file"), wxT("This is help for open file tool"));
14d1ccd8 438
1be45608 439#if USE_CONTROLS_IN_TOOLBAR
5ef2e633 440 // adding a combo to a vertical toolbar is not very smart
1be45608 441 if ( !toolBar->IsVertical() )
5ef2e633 442 {
b529726e 443 wxComboBox *combo = new wxComboBox(toolBar, ID_COMBO, wxEmptyString, wxDefaultPosition, wxSize(100,-1) );
9a83f860
VZ
444 combo->Append(wxT("This"));
445 combo->Append(wxT("is a"));
446 combo->Append(wxT("combobox"));
447 combo->Append(wxT("in a"));
448 combo->Append(wxT("toolbar"));
449 toolBar->AddControl(combo, wxT("Combo Label"));
5ef2e633 450 }
1be45608 451#endif // USE_CONTROLS_IN_TOOLBAR
14d1ccd8 452
9a83f860 453 toolBar->AddTool(wxID_SAVE, wxT("Save"), toolBarBitmaps[Tool_save], wxT("Toggle button 1"), wxITEM_CHECK);
cc260109
VZ
454
455 toolBar->AddSeparator();
9a83f860
VZ
456 toolBar->AddTool(wxID_COPY, wxT("Copy"), toolBarBitmaps[Tool_copy], wxT("Toggle button 2"), wxITEM_CHECK);
457 toolBar->AddTool(wxID_CUT, wxT("Cut"), toolBarBitmaps[Tool_cut], wxT("Toggle/Untoggle help button"));
458 toolBar->AddTool(wxID_PASTE, wxT("Paste"), toolBarBitmaps[Tool_paste], wxT("Paste"));
cc260109 459 toolBar->AddSeparator();
8d0a7b56
VZ
460
461 if ( m_useCustomDisabled )
462 {
463 wxBitmap bmpDisabled(w, h);
464 {
465 wxMemoryDC dc;
466 dc.SelectObject(bmpDisabled);
467 dc.DrawBitmap(toolBarBitmaps[Tool_print], 0, 0);
468
469 wxPen pen(*wxRED, 5);
470 dc.SetPen(pen);
471 dc.DrawLine(0, 0, w, h);
472 }
473
9a83f860 474 toolBar->AddTool(wxID_PRINT, wxT("Print"), toolBarBitmaps[Tool_print],
8d0a7b56
VZ
475 bmpDisabled);
476 }
477 else
478 {
9a83f860
VZ
479 toolBar->AddTool(wxID_PRINT, wxT("Print"), toolBarBitmaps[Tool_print],
480 wxT("Delete this tool. This is a very long tooltip to test whether it does the right thing when the tooltip is more than Windows can cope with."));
8d0a7b56
VZ
481 }
482
cc260109
VZ
483 // add a stretchable space before the "Help" button to make it
484 // right-aligned
485 toolBar->AddStretchableSpace();
9a83f860 486 toolBar->AddTool(wxID_HELP, wxT("Help"), toolBarBitmaps[Tool_help], wxT("Help button"), wxITEM_CHECK);
13437238 487
5e3b8b93
VZ
488 if ( !m_pathBmp.empty() )
489 {
490 // create a tool with a custom bitmap for testing
491 wxImage img(m_pathBmp);
a1b806b9 492 if ( img.IsOk() )
5e3b8b93
VZ
493 {
494 if ( img.GetWidth() > w && img.GetHeight() > h )
495 img = img.GetSubImage(wxRect(0, 0, w, h));
496
497 toolBar->AddSeparator();
9a83f860 498 toolBar->AddTool(wxID_ANY, wxT("Custom"), img);
5e3b8b93
VZ
499 }
500 }
501
5ef2e633
VZ
502 // after adding the buttons to the toolbar, must call Realize() to reflect
503 // the changes
504 toolBar->Realize();
98066234 505
09c0ebcf
VZ
506 toolBar->SetRows(toolBar->IsVertical() ? toolBar->GetToolsCount() / m_rows
507 : m_rows);
14d1ccd8
JS
508}
509
ad9bb75f
VZ
510// ----------------------------------------------------------------------------
511// MyFrame
512// ----------------------------------------------------------------------------
13437238
JS
513
514// Define my frame constructor
7fb23305
VZ
515MyFrame::MyFrame(wxFrame* parent,
516 wxWindowID id,
517 const wxString& title,
518 const wxPoint& pos,
519 const wxSize& size,
520 long style)
521 : wxFrame(parent, id, title, pos, size, style)
14d1ccd8 522{
f6bcfd97 523 m_tbar = NULL;
98066234 524
bc2ec626 525 m_smallToolbar = true;
bc2ec626 526 m_horzText = false;
8d0a7b56 527 m_useCustomDisabled = false;
6a1b3ead 528 m_showTooltips = true;
b3514fd6 529 m_searchTool = NULL;
6a1b3ead 530
98066234 531 m_rows = 1;
2b5f62a0 532 m_nPrint = 1;
ad9bb75f 533
8520f137 534#if wxUSE_STATUSBAR
ad9bb75f
VZ
535 // Give it a status line
536 CreateStatusBar();
0cfc2a92 537#endif
ad9bb75f
VZ
538
539 // Give it an icon
3cb332c1 540 SetIcon(wxICON(sample));
ad9bb75f
VZ
541
542 // Make a menubar
543 wxMenu *tbarMenu = new wxMenu;
ba0abe3c 544 tbarMenu->AppendCheckItem(IDM_TOOLBAR_TOGGLE_TOOLBAR,
9a83f860
VZ
545 wxT("Toggle &toolbar\tCtrl-Z"),
546 wxT("Show or hide the toolbar"));
ba0abe3c
VZ
547
548 tbarMenu->AppendCheckItem(IDM_TOOLBAR_TOGGLE_ANOTHER_TOOLBAR,
9a83f860
VZ
549 wxT("Toggle &another toolbar\tCtrl-A"),
550 wxT("Show/hide another test toolbar"));
ba0abe3c 551
96dc4236 552 tbarMenu->AppendCheckItem(IDM_TOOLBAR_TOGGLE_HORIZONTAL_TEXT,
9a83f860
VZ
553 wxT("Toggle hori&zontal text\tCtrl-H"),
554 wxT("Show text under/alongside the icon"));
96dc4236 555
ba0abe3c 556 tbarMenu->AppendCheckItem(IDM_TOOLBAR_TOGGLETOOLBARSIZE,
9a83f860
VZ
557 wxT("&Toggle toolbar size\tCtrl-S"),
558 wxT("Toggle between big/small toolbar"));
ba0abe3c 559
ba0abe3c 560 tbarMenu->AppendCheckItem(IDM_TOOLBAR_TOGGLETOOLBARROWS,
9a83f860
VZ
561 wxT("Toggle number of &rows\tCtrl-R"),
562 wxT("Toggle number of toolbar rows between 1 and 2"));
5ef2e633 563
6a1b3ead 564 tbarMenu->AppendCheckItem(IDM_TOOLBAR_TOGGLETOOLTIPS,
9a83f860
VZ
565 wxT("Show &tooltips\tCtrl-L"),
566 wxT("Show tooltips for the toolbar tools"));
6a1b3ead 567
8d0a7b56 568 tbarMenu->AppendCheckItem(IDM_TOOLBAR_TOGGLECUSTOMDISABLED,
9a83f860
VZ
569 wxT("Use c&ustom disabled images\tCtrl-U"),
570 wxT("Switch between using system-generated and custom disabled images"));
8d0a7b56
VZ
571
572
7a976304
VZ
573 tbarMenu->AppendSeparator();
574 tbarMenu->AppendRadioItem(IDM_TOOLBAR_TOP_ORIENTATION,
9a83f860
VZ
575 wxT("Set toolbar at the top of the window"),
576 wxT("Set toolbar at the top of the window"));
7a976304 577 tbarMenu->AppendRadioItem(IDM_TOOLBAR_LEFT_ORIENTATION,
9a83f860
VZ
578 wxT("Set toolbar at the left of the window"),
579 wxT("Set toolbar at the left of the window"));
7a976304 580 tbarMenu->AppendRadioItem(IDM_TOOLBAR_BOTTOM_ORIENTATION,
9a83f860
VZ
581 wxT("Set toolbar at the bottom of the window"),
582 wxT("Set toolbar at the bottom of the window"));
7a976304 583 tbarMenu->AppendRadioItem(IDM_TOOLBAR_RIGHT_ORIENTATION,
9a83f860
VZ
584 wxT("Set toolbar at the right edge of the window"),
585 wxT("Set toolbar at the right edge of the window"));
5ef2e633
VZ
586 tbarMenu->AppendSeparator();
587
9a83f860
VZ
588 tbarMenu->AppendRadioItem(IDM_TOOLBAR_SHOW_TEXT, wxT("Show &text\tCtrl-Alt-T"));
589 tbarMenu->AppendRadioItem(IDM_TOOLBAR_SHOW_ICONS, wxT("Show &icons\tCtrl-Alt-I"));
590 tbarMenu->AppendRadioItem(IDM_TOOLBAR_SHOW_BOTH, wxT("Show &both\tCtrl-Alt-B"));
5e3b8b93 591 tbarMenu->AppendSeparator();
9a83f860
VZ
592 tbarMenu->Append(IDM_TOOLBAR_BG_COL, wxT("Choose bac&kground colour..."));
593 tbarMenu->Append(IDM_TOOLBAR_CUSTOM_PATH, wxT("Custom &bitmap...\tCtrl-B"));
b487a08f 594
1be45608 595 wxMenu *toolMenu = new wxMenu;
9a83f860
VZ
596 toolMenu->Append(IDM_TOOLBAR_ENABLEPRINT, wxT("&Enable print button\tCtrl-E"));
597 toolMenu->Append(IDM_TOOLBAR_DELETEPRINT, wxT("&Delete print button\tCtrl-D"));
598 toolMenu->Append(IDM_TOOLBAR_INSERTPRINT, wxT("&Insert print button\tCtrl-I"));
599 toolMenu->Append(IDM_TOOLBAR_TOGGLEHELP, wxT("Toggle &help button\tCtrl-T"));
600 toolMenu->AppendCheckItem(IDM_TOOLBAR_TOGGLESEARCH, wxT("Toggle &search field\tCtrl-F"));
1be45608 601 toolMenu->AppendSeparator();
9a83f860
VZ
602 toolMenu->Append(IDM_TOOLBAR_TOGGLERADIOBTN1, wxT("Toggle &1st radio button\tCtrl-1"));
603 toolMenu->Append(IDM_TOOLBAR_TOGGLERADIOBTN2, wxT("Toggle &2nd radio button\tCtrl-2"));
604 toolMenu->Append(IDM_TOOLBAR_TOGGLERADIOBTN3, wxT("Toggle &3rd radio button\tCtrl-3"));
1be45608 605 toolMenu->AppendSeparator();
9a83f860 606 toolMenu->Append(IDM_TOOLBAR_CHANGE_TOOLTIP, wxT("Change tooltip of \"New\""));
1be45608 607
ad9bb75f 608 wxMenu *fileMenu = new wxMenu;
9a83f860 609 fileMenu->Append(wxID_EXIT, wxT("E&xit\tAlt-X"), wxT("Quit toolbar sample") );
ad9bb75f 610
ad9bb75f 611 wxMenu *helpMenu = new wxMenu;
9a83f860 612 helpMenu->Append(wxID_HELP, wxT("&About"), wxT("About toolbar sample"));
ad9bb75f
VZ
613
614 wxMenuBar* menuBar = new wxMenuBar( wxMB_DOCKABLE );
615
9a83f860
VZ
616 menuBar->Append(fileMenu, wxT("&File"));
617 menuBar->Append(tbarMenu, wxT("&Toolbar"));
618 menuBar->Append(toolMenu, wxT("Tool&s"));
619 menuBar->Append(helpMenu, wxT("&Help"));
ad9bb75f
VZ
620
621 // Associate the menu bar with the frame
622 SetMenuBar(menuBar);
623
93ffd498 624 menuBar->Check(IDM_TOOLBAR_TOGGLE_TOOLBAR, true);
bc2ec626 625 menuBar->Check(IDM_TOOLBAR_SHOW_BOTH, true);
6a1b3ead 626 menuBar->Check(IDM_TOOLBAR_TOGGLETOOLTIPS, true);
c631abda 627
7a976304
VZ
628 menuBar->Check(IDM_TOOLBAR_TOP_ORIENTATION, true );
629 m_toolbarPosition = TOOLBAR_TOP;
079b2f6b 630
ad9bb75f 631 // Create the toolbar
5ef2e633 632 RecreateToolbar();
949b8e62 633
079b2f6b
JS
634 m_panel = new wxPanel(this, wxID_ANY);
635#if USE_UNMANAGED_TOOLBAR
636 m_extraToolBar = new wxToolBar(m_panel, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTB_TEXT|wxTB_FLAT|wxTB_TOP);
637 PopulateToolbar(m_extraToolBar);
079b2f6b 638#endif
ce00f59b 639
079b2f6b
JS
640 m_textWindow = new wxTextCtrl(m_panel, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE);
641
642 wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL);
643 m_panel->SetSizer(sizer);
1be45608 644#if USE_UNMANAGED_TOOLBAR
079b2f6b
JS
645 if (m_extraToolBar)
646 sizer->Add(m_extraToolBar, 0, wxEXPAND, 0);
1be45608 647#endif
079b2f6b 648 sizer->Add(m_textWindow, 1, wxEXPAND, 0);
5ef2e633 649}
ad9bb75f 650
1be45608
VZ
651MyFrame::~MyFrame()
652{
653 if ( m_searchTool && !m_searchTool->GetToolBar() )
654 {
655 // we currently can't delete a toolbar tool ourselves, so we have to
656 // attach it to the toolbar just for it to be deleted, this is pretty
657 // ugly and will need to be changed
658 GetToolBar()->AddTool(m_searchTool);
659 }
660}
661
f6bcfd97
BP
662void MyFrame::LayoutChildren()
663{
664 wxSize size = GetClientSize();
665
666 int offset;
667 if ( m_tbar )
668 {
7a7d2a14 669 m_tbar->SetSize(0, 0, wxDefaultCoord, size.y);
f6bcfd97
BP
670
671 offset = m_tbar->GetSize().x;
672 }
673 else
674 {
675 offset = 0;
676 }
677
079b2f6b 678 m_panel->SetSize(offset, 0, size.x - offset, size.y);
f6bcfd97
BP
679}
680
681void MyFrame::OnSize(wxSizeEvent& event)
682{
683 if ( m_tbar )
684 {
685 LayoutChildren();
686 }
687 else
688 {
689 event.Skip();
690 }
691}
692
ba0abe3c
VZ
693void MyFrame::OnToggleToolbar(wxCommandEvent& WXUNUSED(event))
694{
695 wxToolBar *tbar = GetToolBar();
696
697 if ( !tbar )
698 {
699 RecreateToolbar();
700 }
701 else
702 {
62f6be44
VZ
703 // notice that there is no need to call SetToolBar(NULL) here (although
704 // this it is harmless to do and it must be called if you do not delete
705 // the toolbar but keep it for later reuse), just delete the toolbar
706 // directly and it will reset the associated frame toolbar pointer
ba0abe3c 707 delete tbar;
ba0abe3c
VZ
708 }
709}
710
96dc4236
VZ
711void MyFrame::OnToggleHorizontalText(wxCommandEvent& WXUNUSED(event))
712{
713 m_horzText = !m_horzText;
714
715 RecreateToolbar();
716}
717
f6bcfd97
BP
718void MyFrame::OnToggleAnotherToolbar(wxCommandEvent& WXUNUSED(event))
719{
720 if ( m_tbar )
721 {
5276b0a5 722 wxDELETE(m_tbar);
f6bcfd97
BP
723 }
724 else
725 {
8927d6d1
VZ
726 long style = GetToolBar() ? GetToolBar()->GetWindowStyle()
727 : TOOLBAR_STYLE;
ec483b11
VZ
728 style &= ~wxTB_HORIZONTAL;
729 style |= wxTB_VERTICAL;
730
bc2ec626 731 m_tbar = new wxToolBar(this, wxID_ANY,
f6bcfd97 732 wxDefaultPosition, wxDefaultSize,
ec483b11
VZ
733 style);
734
69c14ebe
VZ
735 m_tbar->SetMargins(4, 4);
736
9a83f860
VZ
737 m_tbar->AddRadioTool(IDM_TOOLBAR_OTHER_1, wxT("First"), wxBITMAP(new));
738 m_tbar->AddRadioTool(IDM_TOOLBAR_OTHER_2, wxT("Second"), wxBITMAP(open));
739 m_tbar->AddRadioTool(IDM_TOOLBAR_OTHER_3, wxT("Third"), wxBITMAP(save));
ec483b11 740 m_tbar->AddSeparator();
9a83f860 741 m_tbar->AddTool(wxID_HELP, wxT("Help"), wxBITMAP(help));
ec483b11 742
f6bcfd97
BP
743 m_tbar->Realize();
744 }
745
746 LayoutChildren();
747}
748
5ef2e633
VZ
749void MyFrame::OnToggleToolbarSize(wxCommandEvent& WXUNUSED(event))
750{
751 m_smallToolbar = !m_smallToolbar;
ad9bb75f 752
5ef2e633 753 RecreateToolbar();
7fb23305
VZ
754}
755
98066234
VZ
756void MyFrame::OnToggleToolbarRows(wxCommandEvent& WXUNUSED(event))
757{
758 // m_rows may be only 1 or 2
759 m_rows = 3 - m_rows;
760
09c0ebcf
VZ
761 wxToolBar* const toolBar = GetToolBar();
762 toolBar->SetRows(toolBar->IsVertical() ? toolBar->GetToolsCount() / m_rows
763 : m_rows);
98066234 764
9fb35cf1 765 //RecreateToolbar(); -- this is unneeded
98066234
VZ
766}
767
6a1b3ead
VZ
768void MyFrame::OnToggleTooltips(wxCommandEvent& WXUNUSED(event))
769{
770 m_showTooltips = !m_showTooltips;
771
772 RecreateToolbar();
773}
774
8d0a7b56
VZ
775void MyFrame::OnToggleCustomDisabled(wxCommandEvent& WXUNUSED(event))
776{
777 m_useCustomDisabled = !m_useCustomDisabled;
778
779 RecreateToolbar();
780}
781
7a976304 782void MyFrame::OnChangeOrientation(wxCommandEvent& event)
7fb23305 783{
7a976304
VZ
784 switch( event.GetId() )
785 {
786 case IDM_TOOLBAR_LEFT_ORIENTATION:
787 m_toolbarPosition = TOOLBAR_LEFT;
788 break;
789 case IDM_TOOLBAR_TOP_ORIENTATION:
790 m_toolbarPosition = TOOLBAR_TOP;
791 break;
792 case IDM_TOOLBAR_RIGHT_ORIENTATION:
793 m_toolbarPosition = TOOLBAR_RIGHT;
794 break;
795 case IDM_TOOLBAR_BOTTOM_ORIENTATION:
796 m_toolbarPosition = TOOLBAR_BOTTOM;
797 break;
798 }
5ef2e633 799 RecreateToolbar();
14d1ccd8
JS
800}
801
47908e25 802void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
14d1ccd8 803{
bc2ec626 804 Close(true);
14d1ccd8
JS
805}
806
e08bbf37 807void MyFrame::OnAbout(wxCommandEvent& event)
14d1ccd8 808{
e08bbf37 809 if ( event.IsChecked() )
9a83f860 810 m_textWindow->WriteText( wxT("Help button down now.\n") );
e08bbf37 811 else
9a83f860 812 m_textWindow->WriteText( wxT("Help button up now.\n") );
e08bbf37 813
9a83f860 814 (void)wxMessageBox(wxT("wxWidgets toolbar sample"), wxT("About wxToolBar"));
13437238 815}
14d1ccd8 816
13437238
JS
817void MyFrame::OnToolLeftClick(wxCommandEvent& event)
818{
e179bd65 819 wxString str;
9a83f860 820 str.Printf( wxT("Clicked on tool %d\n"), event.GetId());
e179bd65 821 m_textWindow->WriteText( str );
ad9bb75f 822
e179bd65
RR
823 if (event.GetId() == wxID_COPY)
824 {
7fb23305 825 DoEnablePrint();
e179bd65 826 }
ad9bb75f 827
e179bd65
RR
828 if (event.GetId() == wxID_CUT)
829 {
7fb23305 830 DoToggleHelp();
e179bd65 831 }
1c4f8f8d 832
97d7bfb8
RR
833 if (event.GetId() == wxID_PRINT)
834 {
835 DoDeletePrint();
836 }
14d1ccd8
JS
837}
838
e052a316
VZ
839void MyFrame::OnToolRightClick(wxCommandEvent& event)
840{
841 m_textWindow->AppendText(
9a83f860 842 wxString::Format(wxT("Tool %d right clicked.\n"),
60c474a0 843 (int) event.GetInt()));
e052a316
VZ
844}
845
1c383dba
VZ
846void MyFrame::OnCombo(wxCommandEvent& event)
847{
9a83f860 848 wxLogStatus(wxT("Combobox string '%s' selected"), event.GetString().c_str());
1c383dba
VZ
849}
850
7fb23305
VZ
851void MyFrame::DoEnablePrint()
852{
2b5f62a0
VZ
853 if ( !m_nPrint )
854 return;
855
ad4ae6ed 856 wxToolBarBase *tb = GetToolBar();
2b5f62a0 857 tb->EnableTool(wxID_PRINT, !tb->GetToolEnabled(wxID_PRINT));
7fb23305
VZ
858}
859
97d7bfb8
RR
860void MyFrame::DoDeletePrint()
861{
2b5f62a0
VZ
862 if ( !m_nPrint )
863 return;
1c4f8f8d 864
2b5f62a0 865 wxToolBarBase *tb = GetToolBar();
97d7bfb8 866 tb->DeleteTool( wxID_PRINT );
2b5f62a0
VZ
867
868 m_nPrint--;
97d7bfb8
RR
869}
870
7fb23305
VZ
871void MyFrame::DoToggleHelp()
872{
ad4ae6ed 873 wxToolBarBase *tb = GetToolBar();
7fb23305
VZ
874 tb->ToggleTool( wxID_HELP, !tb->GetToolState( wxID_HELP ) );
875}
876
1be45608
VZ
877void MyFrame::OnToggleSearch(wxCommandEvent& WXUNUSED(event))
878{
1be45608
VZ
879 wxToolBarBase * const tb = GetToolBar();
880 if ( !m_searchTool )
881 {
882 wxSearchCtrl * const srch = new wxSearchCtrl(tb, wxID_ANY, "needle");
883 srch->SetMinSize(wxSize(80, -1));
cc260109 884 m_searchTool = tb->AddControl(srch);
1be45608
VZ
885 }
886 else // tool already exists
887 {
b3514fd6 888 wxControl * const win = m_searchTool->GetControl();
1be45608
VZ
889 if ( m_searchTool->GetToolBar() )
890 {
891 // attached now, remove it
b3514fd6 892 win->Hide();
1be45608
VZ
893 tb->RemoveTool(m_searchTool->GetId());
894 }
895 else // tool exists in detached state, attach it back
896 {
cc260109 897 tb->AddTool(m_searchTool);
b3514fd6 898 win->Show();
1be45608
VZ
899 }
900 }
b3514fd6
VZ
901
902 tb->Realize();
1be45608
VZ
903}
904
5ef2e633
VZ
905void MyFrame::OnUpdateCopyAndCut(wxUpdateUIEvent& event)
906{
96dc4236
VZ
907 event.Enable( m_textWindow->CanCopy() );
908}
909
910void MyFrame::OnUpdateToggleHorzText(wxUpdateUIEvent& event)
911{
912 wxToolBar *tbar = GetToolBar();
913 event.Enable( tbar &&
914 tbar->HasFlag(wxTB_TEXT) &&
915 !tbar->HasFlag(wxTB_NOICONS) );
5ef2e633
VZ
916}
917
a1f79c1e
VZ
918void MyFrame::OnChangeToolTip(wxCommandEvent& WXUNUSED(event))
919{
9a83f860 920 GetToolBar()->SetToolShortHelp(wxID_NEW, wxT("New toolbar button"));
a1f79c1e
VZ
921}
922
ec483b11
VZ
923void MyFrame::OnToolbarStyle(wxCommandEvent& event)
924{
925 long style = GetToolBar()->GetWindowStyle();
c66c8042 926 style &= ~(wxTB_NOICONS | wxTB_HORZ_TEXT);
ec483b11
VZ
927
928 switch ( event.GetId() )
929 {
930 case IDM_TOOLBAR_SHOW_TEXT:
c66c8042 931 style |= wxTB_NOICONS | (m_horzText ? wxTB_HORZ_TEXT : wxTB_TEXT);
ec483b11
VZ
932 break;
933
934 case IDM_TOOLBAR_SHOW_ICONS:
935 // nothing to do
936 break;
937
938 case IDM_TOOLBAR_SHOW_BOTH:
c66c8042 939 style |= (m_horzText ? wxTB_HORZ_TEXT : wxTB_TEXT);
ec483b11
VZ
940 }
941
942 GetToolBar()->SetWindowStyle(style);
943}
944
211df056
VZ
945void MyFrame::OnToolbarBgCol(wxCommandEvent& WXUNUSED(event))
946{
947 wxColour col = wxGetColourFromUser
948 (
949 this,
950 GetToolBar()->GetBackgroundColour(),
951 "Toolbar background colour"
952 );
953 if ( col.IsOk() )
954 {
955 GetToolBar()->SetBackgroundColour(col);
956 GetToolBar()->Refresh();
957 }
958}
959
5e3b8b93
VZ
960void MyFrame::OnToolbarCustomBitmap(wxCommandEvent& WXUNUSED(event))
961{
6541fd4b 962 m_pathBmp = wxLoadFileSelector("custom bitmap", "");
5e3b8b93
VZ
963
964 RecreateToolbar();
965}
966
bdc72a22
VZ
967void MyFrame::OnInsertPrint(wxCommandEvent& WXUNUSED(event))
968{
2b5f62a0 969 m_nPrint++;
bdc72a22 970
2b5f62a0 971 wxToolBarBase *tb = GetToolBar();
9a83f860 972 tb->InsertTool(0, wxID_PRINT, wxT("New print"),
2b5f62a0
VZ
973 wxBITMAP(print), wxNullBitmap,
974 wxITEM_NORMAL,
9a83f860
VZ
975 wxT("Delete this tool"),
976 wxT("This button was inserted into the toolbar"));
2b5f62a0
VZ
977
978 // must call Realize() after adding a new button
979 tb->Realize();
bdc72a22
VZ
980}
981
3bf4189d
VZ
982void MyFrame::OnToggleRadioBtn(wxCommandEvent& event)
983{
984 if ( m_tbar )
985 {
986 m_tbar->ToggleTool(IDM_TOOLBAR_OTHER_1 +
987 event.GetId() - IDM_TOOLBAR_TOGGLERADIOBTN1, true);
988 }
989}
a9a0ceca
VZ
990
991void MyFrame::OnToolDropdown(wxCommandEvent& event)
992{
993 wxString str;
9a83f860 994 str.Printf( wxT("Dropdown on tool %d\n"), event.GetId());
a9a0ceca
VZ
995 m_textWindow->WriteText( str );
996
997 event.Skip();
998}