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