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