1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxToolBar sample
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx/wx.h".
21 #include "wx/wxprec.h"
31 #include "wx/toolbar.h"
35 // define this to 1 to use wxToolBarSimple instead of the native one
36 #define USE_GENERIC_TBAR 0
38 // define this to use XPMs everywhere (by default, BMPs are used under Win)
39 // BMPs use less space, but aren't compiled into the executable on other platforms
41 #define USE_XPM_BITMAPS 0
43 #define USE_XPM_BITMAPS 1
47 #if !wxUSE_TOOLBAR_SIMPLE
48 #error wxToolBarSimple is not compiled in, set wxUSE_TOOLBAR_SIMPLE \
49 to 1 in setup.h and recompile the library.
51 #include "wx/tbarsmpl.h"
53 #endif // USE_GENERIC_TBAR
55 #if USE_XPM_BITMAPS && defined(__WXMSW__) && !wxUSE_XPM_IN_MSW
56 #error You need to enable XPM support to use XPM bitmaps with toolbar!
57 #endif // USE_XPM_BITMAPS
59 // ----------------------------------------------------------------------------
61 // ----------------------------------------------------------------------------
63 #if !defined(__WXMSW__) && !defined(__WXPM__)
64 #include "mondrian.xpm"
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"
73 #include "bitmaps/preview.xpm" // paste XPM
74 #include "bitmaps/print.xpm"
75 #include "bitmaps/help.xpm"
76 #endif // USE_XPM_BITMAPS
78 // ----------------------------------------------------------------------------
80 // ----------------------------------------------------------------------------
82 // Define a new application
83 class MyApp
: public wxApp
90 class MyFrame
: public wxFrame
93 MyFrame(wxFrame
*parent
,
94 wxWindowID id
= wxID_ANY
,
95 const wxString
& title
= _T("wxToolBar Sample"),
96 const wxPoint
& pos
= wxDefaultPosition
,
97 const wxSize
& size
= wxDefaultSize
,
98 long style
= wxDEFAULT_FRAME_STYLE
|wxCLIP_CHILDREN
|wxNO_FULL_REPAINT_ON_RESIZE
);
100 void RecreateToolbar();
102 void OnQuit(wxCommandEvent
& event
);
103 void OnAbout(wxCommandEvent
& event
);
105 void OnSize(wxSizeEvent
& event
);
107 void OnToggleToolbar(wxCommandEvent
& event
);
108 void OnToggleAnotherToolbar(wxCommandEvent
& event
);
109 void OnToggleHorizontalText(wxCommandEvent
& WXUNUSED(event
));
111 void OnToggleToolbarSize(wxCommandEvent
& event
);
112 void OnToggleToolbarOrient(wxCommandEvent
& event
);
113 void OnToggleToolbarRows(wxCommandEvent
& event
);
114 void OnToggleTooltips(wxCommandEvent
& event
);
115 void OnToggleCustomDisabled(wxCommandEvent
& event
);
117 void OnEnablePrint(wxCommandEvent
& WXUNUSED(event
)) { DoEnablePrint(); }
118 void OnDeletePrint(wxCommandEvent
& WXUNUSED(event
)) { DoDeletePrint(); }
119 void OnInsertPrint(wxCommandEvent
& event
);
120 void OnChangeToolTip(wxCommandEvent
& event
);
121 void OnToggleHelp(wxCommandEvent
& WXUNUSED(event
)) { DoToggleHelp(); }
122 void OnToggleRadioBtn(wxCommandEvent
& event
);
124 void OnToolbarStyle(wxCommandEvent
& event
);
126 void OnToolLeftClick(wxCommandEvent
& event
);
127 void OnToolRightClick(wxCommandEvent
& event
);
128 void OnToolEnter(wxCommandEvent
& event
);
130 void OnCombo(wxCommandEvent
& event
);
132 void OnUpdateCopyAndCut(wxUpdateUIEvent
& event
);
133 void OnUpdateToggleHorzText(wxUpdateUIEvent
& event
);
134 void OnUpdateToggleRadioBtn(wxUpdateUIEvent
& event
)
135 { event
.Enable( m_tbar
!= NULL
); }
138 virtual wxToolBar
*OnCreateToolBar(long style
,
140 const wxString
& name
);
141 #endif // USE_GENERIC_TBAR
144 void DoEnablePrint();
145 void DoDeletePrint();
148 void LayoutChildren();
155 size_t m_rows
; // 1 or 2 only
157 // the number of print buttons we have (they're added/removed dynamically)
160 wxTextCtrl
*m_textWindow
;
164 DECLARE_EVENT_TABLE()
167 // ----------------------------------------------------------------------------
169 // ----------------------------------------------------------------------------
171 const int ID_TOOLBAR
= 500;
173 static const long TOOLBAR_STYLE
= wxTB_FLAT
| wxTB_DOCKABLE
| wxTB_TEXT
;
177 IDM_TOOLBAR_TOGGLETOOLBARSIZE
= 200,
178 IDM_TOOLBAR_TOGGLETOOLBARORIENT
,
179 IDM_TOOLBAR_TOGGLETOOLBARROWS
,
180 IDM_TOOLBAR_TOGGLETOOLTIPS
,
181 IDM_TOOLBAR_TOGGLECUSTOMDISABLED
,
182 IDM_TOOLBAR_ENABLEPRINT
,
183 IDM_TOOLBAR_DELETEPRINT
,
184 IDM_TOOLBAR_INSERTPRINT
,
185 IDM_TOOLBAR_TOGGLEHELP
,
186 IDM_TOOLBAR_TOGGLERADIOBTN1
,
187 IDM_TOOLBAR_TOGGLERADIOBTN2
,
188 IDM_TOOLBAR_TOGGLERADIOBTN3
,
189 IDM_TOOLBAR_TOGGLE_TOOLBAR
,
190 IDM_TOOLBAR_TOGGLE_HORIZONTAL_TEXT
,
191 IDM_TOOLBAR_TOGGLE_ANOTHER_TOOLBAR
,
192 IDM_TOOLBAR_CHANGE_TOOLTIP
,
193 IDM_TOOLBAR_SHOW_TEXT
,
194 IDM_TOOLBAR_SHOW_ICONS
,
195 IDM_TOOLBAR_SHOW_BOTH
,
204 // ----------------------------------------------------------------------------
206 // ----------------------------------------------------------------------------
208 // Notice that wxID_HELP will be processed for the 'About' menu and the toolbar
211 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
212 EVT_SIZE(MyFrame::OnSize
)
214 EVT_MENU(wxID_EXIT
, MyFrame::OnQuit
)
215 EVT_MENU(wxID_HELP
, MyFrame::OnAbout
)
217 EVT_MENU(IDM_TOOLBAR_TOGGLE_TOOLBAR
, MyFrame::OnToggleToolbar
)
218 EVT_MENU(IDM_TOOLBAR_TOGGLE_ANOTHER_TOOLBAR
, MyFrame::OnToggleAnotherToolbar
)
219 EVT_MENU(IDM_TOOLBAR_TOGGLE_HORIZONTAL_TEXT
, MyFrame::OnToggleHorizontalText
)
221 EVT_MENU(IDM_TOOLBAR_TOGGLETOOLBARSIZE
, MyFrame::OnToggleToolbarSize
)
222 EVT_MENU(IDM_TOOLBAR_TOGGLETOOLBARORIENT
, MyFrame::OnToggleToolbarOrient
)
223 EVT_MENU(IDM_TOOLBAR_TOGGLETOOLBARROWS
, MyFrame::OnToggleToolbarRows
)
224 EVT_MENU(IDM_TOOLBAR_TOGGLETOOLTIPS
, MyFrame::OnToggleTooltips
)
225 EVT_MENU(IDM_TOOLBAR_TOGGLECUSTOMDISABLED
, MyFrame::OnToggleCustomDisabled
)
227 EVT_MENU(IDM_TOOLBAR_ENABLEPRINT
, MyFrame::OnEnablePrint
)
228 EVT_MENU(IDM_TOOLBAR_DELETEPRINT
, MyFrame::OnDeletePrint
)
229 EVT_MENU(IDM_TOOLBAR_INSERTPRINT
, MyFrame::OnInsertPrint
)
230 EVT_MENU(IDM_TOOLBAR_TOGGLEHELP
, MyFrame::OnToggleHelp
)
231 EVT_MENU_RANGE(IDM_TOOLBAR_TOGGLERADIOBTN1
, IDM_TOOLBAR_TOGGLERADIOBTN3
,
232 MyFrame::OnToggleRadioBtn
)
233 EVT_MENU(IDM_TOOLBAR_CHANGE_TOOLTIP
, MyFrame::OnChangeToolTip
)
235 EVT_MENU_RANGE(IDM_TOOLBAR_SHOW_TEXT
, IDM_TOOLBAR_SHOW_BOTH
,
236 MyFrame::OnToolbarStyle
)
238 EVT_MENU(wxID_ANY
, MyFrame::OnToolLeftClick
)
240 EVT_COMBOBOX(ID_COMBO
, MyFrame::OnCombo
)
242 EVT_TOOL_ENTER(ID_TOOLBAR
, MyFrame::OnToolEnter
)
243 EVT_TOOL_RCLICKED(wxID_ANY
, MyFrame::OnToolRightClick
)
245 EVT_UPDATE_UI(wxID_COPY
, MyFrame::OnUpdateCopyAndCut
)
246 EVT_UPDATE_UI(wxID_CUT
, MyFrame::OnUpdateCopyAndCut
)
248 EVT_UPDATE_UI_RANGE(IDM_TOOLBAR_TOGGLERADIOBTN1
,
249 IDM_TOOLBAR_TOGGLERADIOBTN3
,
250 MyFrame::OnUpdateToggleRadioBtn
)
251 EVT_UPDATE_UI(IDM_TOOLBAR_TOGGLE_HORIZONTAL_TEXT
,
252 MyFrame::OnUpdateToggleHorzText
)
255 // ============================================================================
257 // ============================================================================
259 // ----------------------------------------------------------------------------
261 // ----------------------------------------------------------------------------
265 // The `main program' equivalent, creating the windows and returning the
269 // Create the main frame window
270 MyFrame
* frame
= new MyFrame((wxFrame
*) NULL
, wxID_ANY
,
271 _T("wxToolBar Sample"),
273 wxDefaultPosition
, wxDefaultSize
275 wxPoint(100, 100), wxSize(550, 300)
282 frame
->SetStatusText(_T("Hello, wxWidgets"));
290 void MyFrame::RecreateToolbar()
293 // On Windows CE, we should not delete the
294 // previous toolbar in case it contains the menubar.
295 // We'll try to accommodate this usage in due course.
296 wxToolBar
* toolBar
= CreateToolBar();
298 // delete and recreate the toolbar
299 wxToolBarBase
*toolBar
= GetToolBar();
300 long style
= toolBar
? toolBar
->GetWindowStyle() : TOOLBAR_STYLE
;
306 style
&= ~(wxTB_HORIZONTAL
| wxTB_VERTICAL
| wxTB_HORZ_LAYOUT
);
307 style
|= m_horzToolbar
? wxTB_HORIZONTAL
: wxTB_VERTICAL
;
309 if ( m_showTooltips
)
310 style
&= ~wxTB_NO_TOOLTIPS
;
312 style
|= wxTB_NO_TOOLTIPS
;
314 if ( style
& wxTB_TEXT
&& !(style
& wxTB_NOICONS
) && m_horzText
)
315 style
|= wxTB_HORZ_LAYOUT
;
317 toolBar
= CreateToolBar(style
, ID_TOOLBAR
);
334 wxBitmap toolBarBitmaps
[Tool_Max
];
337 #define INIT_TOOL_BMP(bmp) \
338 toolBarBitmaps[Tool_##bmp] = wxBitmap(bmp##_xpm)
339 #else // !USE_XPM_BITMAPS
340 #define INIT_TOOL_BMP(bmp) \
341 toolBarBitmaps[Tool_##bmp] = wxBITMAP(bmp)
342 #endif // USE_XPM_BITMAPS/!USE_XPM_BITMAPS
349 INIT_TOOL_BMP(paste
);
350 INIT_TOOL_BMP(print
);
353 int w
= toolBarBitmaps
[Tool_new
].GetWidth(),
354 h
= toolBarBitmaps
[Tool_new
].GetHeight();
356 if ( !m_smallToolbar
)
361 for ( size_t n
= Tool_new
; n
< WXSIZEOF(toolBarBitmaps
); n
++ )
364 wxBitmap(toolBarBitmaps
[n
].ConvertToImage().Scale(w
, h
));
368 toolBar
->SetToolBitmapSize(wxSize(w
, h
));
370 toolBar
->AddTool(wxID_NEW
, _T("New"), toolBarBitmaps
[Tool_new
], _T("New file"));
371 toolBar
->AddTool(wxID_OPEN
, _T("Open"), toolBarBitmaps
[Tool_open
], _T("Open file"));
373 // the generic toolbar doesn't really support this
374 #if (wxUSE_TOOLBAR_NATIVE && !USE_GENERIC_TBAR) && !defined(__WXX11__) || defined(__WXUNIVERSAL__)
375 // adding a combo to a vertical toolbar is not very smart
378 wxComboBox
*combo
= new wxComboBox(toolBar
, ID_COMBO
, wxEmptyString
, wxDefaultPosition
, wxSize(200,wxDefaultCoord
) );
379 combo
->Append(_T("This"));
380 combo
->Append(_T("is a"));
381 combo
->Append(_T("combobox"));
382 combo
->Append(_T("in a"));
383 combo
->Append(_T("toolbar"));
384 toolBar
->AddControl(combo
);
386 #endif // toolbars which don't support controls
388 toolBar
->AddTool(wxID_SAVE
, _T("Save"), toolBarBitmaps
[Tool_save
], _T("Toggle button 1"), wxITEM_CHECK
);
389 toolBar
->AddTool(wxID_COPY
, _T("Copy"), toolBarBitmaps
[Tool_copy
], _T("Toggle button 2"), wxITEM_CHECK
);
390 toolBar
->AddTool(wxID_CUT
, _T("Cut"), toolBarBitmaps
[Tool_cut
], _T("Toggle/Untoggle help button"));
391 toolBar
->AddTool(wxID_PASTE
, _T("Paste"), toolBarBitmaps
[Tool_paste
], _T("Paste"));
393 if ( m_useCustomDisabled
)
395 wxBitmap
bmpDisabled(w
, h
);
398 dc
.SelectObject(bmpDisabled
);
399 dc
.DrawBitmap(toolBarBitmaps
[Tool_print
], 0, 0);
401 wxPen
pen(*wxRED
, 5);
403 dc
.DrawLine(0, 0, w
, h
);
406 toolBar
->AddTool(wxID_PRINT
, _T("Print"), toolBarBitmaps
[Tool_print
],
411 toolBar
->AddTool(wxID_PRINT
, _T("Print"), toolBarBitmaps
[Tool_print
],
412 _T("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."));
415 toolBar
->AddSeparator();
416 toolBar
->AddTool(wxID_HELP
, _T("Help"), toolBarBitmaps
[Tool_help
], _T("Help button"), wxITEM_CHECK
);
418 // after adding the buttons to the toolbar, must call Realize() to reflect
422 toolBar
->SetRows(m_horzToolbar
? m_rows
: 10 / m_rows
);
425 // ----------------------------------------------------------------------------
427 // ----------------------------------------------------------------------------
429 // Define my frame constructor
430 MyFrame::MyFrame(wxFrame
* parent
,
432 const wxString
& title
,
436 : wxFrame(parent
, id
, title
, pos
, size
, style
)
440 m_smallToolbar
= true;
441 m_horzToolbar
= true;
443 m_useCustomDisabled
= false;
444 m_showTooltips
= true;
450 // Give it a status line
455 SetIcon(wxICON(mondrian
));
458 wxMenu
*tbarMenu
= new wxMenu
;
459 tbarMenu
->AppendCheckItem(IDM_TOOLBAR_TOGGLE_TOOLBAR
,
460 _T("Toggle &toolbar\tCtrl-Z"),
461 _T("Show or hide the toolbar"));
463 tbarMenu
->AppendCheckItem(IDM_TOOLBAR_TOGGLE_ANOTHER_TOOLBAR
,
464 _T("Toggle &another toolbar\tCtrl-A"),
465 _T("Show/hide another test toolbar"));
467 tbarMenu
->AppendCheckItem(IDM_TOOLBAR_TOGGLE_HORIZONTAL_TEXT
,
468 _T("Toggle hori&zontal text\tCtrl-H"),
469 _T("Show text under/alongside the icon"));
471 tbarMenu
->AppendCheckItem(IDM_TOOLBAR_TOGGLETOOLBARSIZE
,
472 _T("&Toggle toolbar size\tCtrl-S"),
473 _T("Toggle between big/small toolbar"));
475 tbarMenu
->AppendCheckItem(IDM_TOOLBAR_TOGGLETOOLBARORIENT
,
476 _T("Toggle toolbar &orientation\tCtrl-O"),
477 _T("Toggle toolbar orientation"));
479 tbarMenu
->AppendCheckItem(IDM_TOOLBAR_TOGGLETOOLBARROWS
,
480 _T("Toggle number of &rows\tCtrl-R"),
481 _T("Toggle number of toolbar rows between 1 and 2"));
483 tbarMenu
->AppendCheckItem(IDM_TOOLBAR_TOGGLETOOLTIPS
,
484 _T("Show &tooltips\tCtrl-L"),
485 _T("Show tooltips for the toolbar tools"));
487 tbarMenu
->AppendCheckItem(IDM_TOOLBAR_TOGGLECUSTOMDISABLED
,
488 _T("Use c&ustom disabled images\tCtrl-U"),
489 _T("Switch between using system-generated and custom disabled images"));
492 tbarMenu
->AppendSeparator();
494 tbarMenu
->Append(IDM_TOOLBAR_ENABLEPRINT
, _T("&Enable print button\tCtrl-E"), wxEmptyString
);
495 tbarMenu
->Append(IDM_TOOLBAR_DELETEPRINT
, _T("&Delete print button\tCtrl-D"), wxEmptyString
);
496 tbarMenu
->Append(IDM_TOOLBAR_INSERTPRINT
, _T("&Insert print button\tCtrl-I"), wxEmptyString
);
497 tbarMenu
->Append(IDM_TOOLBAR_TOGGLEHELP
, _T("Toggle &help button\tCtrl-T"), wxEmptyString
);
498 tbarMenu
->AppendSeparator();
499 tbarMenu
->Append(IDM_TOOLBAR_TOGGLERADIOBTN1
, _T("Toggle &1st radio button\tCtrl-1"), wxEmptyString
);
500 tbarMenu
->Append(IDM_TOOLBAR_TOGGLERADIOBTN2
, _T("Toggle &2nd radio button\tCtrl-2"), wxEmptyString
);
501 tbarMenu
->Append(IDM_TOOLBAR_TOGGLERADIOBTN3
, _T("Toggle &3rd radio button\tCtrl-3"), wxEmptyString
);
502 tbarMenu
->AppendSeparator();
503 tbarMenu
->Append(IDM_TOOLBAR_CHANGE_TOOLTIP
, _T("Change tool tip"), wxEmptyString
);
504 tbarMenu
->AppendSeparator();
505 tbarMenu
->AppendRadioItem(IDM_TOOLBAR_SHOW_TEXT
, _T("Show &text\tAlt-T"));
506 tbarMenu
->AppendRadioItem(IDM_TOOLBAR_SHOW_ICONS
, _T("Show &icons\tAlt-I"));
507 tbarMenu
->AppendRadioItem(IDM_TOOLBAR_SHOW_BOTH
, _T("Show &both\tAlt-B"));
509 wxMenu
*fileMenu
= new wxMenu
;
510 fileMenu
->Append(wxID_EXIT
, _T("E&xit\tAlt-X"), _T("Quit toolbar sample") );
512 wxMenu
*helpMenu
= new wxMenu
;
513 helpMenu
->Append(wxID_HELP
, _T("&About"), _T("About toolbar sample"));
515 wxMenuBar
* menuBar
= new wxMenuBar( wxMB_DOCKABLE
);
517 menuBar
->Append(fileMenu
, _T("&File"));
518 menuBar
->Append(tbarMenu
, _T("&Toolbar"));
519 menuBar
->Append(helpMenu
, _T("&Help"));
521 // Associate the menu bar with the frame
524 menuBar
->Check(IDM_TOOLBAR_SHOW_BOTH
, true);
525 menuBar
->Check(IDM_TOOLBAR_TOGGLETOOLTIPS
, true);
527 // Create the toolbar
530 m_textWindow
= new wxTextCtrl(this, wxID_ANY
, wxEmptyString
, wxPoint(0, 0), wxDefaultSize
, wxTE_MULTILINE
);
535 wxToolBar
* MyFrame::OnCreateToolBar(long style
,
537 const wxString
& name
)
539 return (wxToolBar
*)new wxToolBarSimple(this, id
,
540 wxDefaultPosition
, wxDefaultSize
,
544 #endif // USE_GENERIC_TBAR
546 void MyFrame::LayoutChildren()
548 wxSize size
= GetClientSize();
553 m_tbar
->SetSize(0, 0, wxDefaultCoord
, size
.y
);
555 offset
= m_tbar
->GetSize().x
;
562 m_textWindow
->SetSize(offset
, 0, size
.x
- offset
, size
.y
);
565 void MyFrame::OnSize(wxSizeEvent
& event
)
577 void MyFrame::OnToggleToolbar(wxCommandEvent
& WXUNUSED(event
))
579 wxToolBar
*tbar
= GetToolBar();
593 void MyFrame::OnToggleHorizontalText(wxCommandEvent
& WXUNUSED(event
))
595 m_horzText
= !m_horzText
;
600 void MyFrame::OnToggleAnotherToolbar(wxCommandEvent
& WXUNUSED(event
))
609 long style
= GetToolBar() ? GetToolBar()->GetWindowStyle()
611 style
&= ~wxTB_HORIZONTAL
;
612 style
|= wxTB_VERTICAL
;
614 m_tbar
= new wxToolBar(this, wxID_ANY
,
615 wxDefaultPosition
, wxDefaultSize
,
618 m_tbar
->SetMargins(4, 4);
620 m_tbar
->AddRadioTool(IDM_TOOLBAR_OTHER_1
, _T("First"), wxBITMAP(new));
621 m_tbar
->AddRadioTool(IDM_TOOLBAR_OTHER_2
, _T("Second"), wxBITMAP(open
));
622 m_tbar
->AddRadioTool(IDM_TOOLBAR_OTHER_3
, _T("Third"), wxBITMAP(save
));
623 m_tbar
->AddSeparator();
624 m_tbar
->AddTool(wxID_HELP
, _T("Help"), wxBITMAP(help
));
632 void MyFrame::OnToggleToolbarSize(wxCommandEvent
& WXUNUSED(event
))
634 m_smallToolbar
= !m_smallToolbar
;
639 void MyFrame::OnToggleToolbarRows(wxCommandEvent
& WXUNUSED(event
))
641 // m_rows may be only 1 or 2
644 GetToolBar()->SetRows(m_horzToolbar
? m_rows
: 10 / m_rows
);
646 //RecreateToolbar(); -- this is unneeded
649 void MyFrame::OnToggleTooltips(wxCommandEvent
& WXUNUSED(event
))
651 m_showTooltips
= !m_showTooltips
;
656 void MyFrame::OnToggleCustomDisabled(wxCommandEvent
& WXUNUSED(event
))
658 m_useCustomDisabled
= !m_useCustomDisabled
;
663 void MyFrame::OnToggleToolbarOrient(wxCommandEvent
& WXUNUSED(event
))
665 m_horzToolbar
= !m_horzToolbar
;
670 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
675 void MyFrame::OnAbout(wxCommandEvent
& event
)
677 if ( event
.IsChecked() )
678 m_textWindow
->WriteText( _T("Help button down now.\n") );
680 m_textWindow
->WriteText( _T("Help button up now.\n") );
682 (void)wxMessageBox(_T("wxWidgets toolbar sample"), _T("About wxToolBar"));
685 void MyFrame::OnToolLeftClick(wxCommandEvent
& event
)
688 str
.Printf( _T("Clicked on tool %d\n"), event
.GetId());
689 m_textWindow
->WriteText( str
);
691 if (event
.GetId() == wxID_COPY
)
696 if (event
.GetId() == wxID_CUT
)
701 if (event
.GetId() == wxID_PRINT
)
707 void MyFrame::OnToolRightClick(wxCommandEvent
& event
)
709 m_textWindow
->AppendText(
710 wxString::Format(_T("Tool %d right clicked.\n"),
711 (int) event
.GetInt()));
714 void MyFrame::OnCombo(wxCommandEvent
& event
)
716 wxLogStatus(_T("Combobox string '%s' selected"), event
.GetString().c_str());
719 void MyFrame::DoEnablePrint()
724 wxToolBarBase
*tb
= GetToolBar();
725 tb
->EnableTool(wxID_PRINT
, !tb
->GetToolEnabled(wxID_PRINT
));
728 void MyFrame::DoDeletePrint()
733 wxToolBarBase
*tb
= GetToolBar();
734 tb
->DeleteTool( wxID_PRINT
);
739 void MyFrame::DoToggleHelp()
741 wxToolBarBase
*tb
= GetToolBar();
742 tb
->ToggleTool( wxID_HELP
, !tb
->GetToolState( wxID_HELP
) );
745 void MyFrame::OnUpdateCopyAndCut(wxUpdateUIEvent
& event
)
747 event
.Enable( m_textWindow
->CanCopy() );
750 void MyFrame::OnUpdateToggleHorzText(wxUpdateUIEvent
& event
)
752 wxToolBar
*tbar
= GetToolBar();
753 event
.Enable( tbar
&&
754 tbar
->HasFlag(wxTB_TEXT
) &&
755 !tbar
->HasFlag(wxTB_NOICONS
) );
758 void MyFrame::OnChangeToolTip(wxCommandEvent
& WXUNUSED(event
))
760 GetToolBar()->SetToolShortHelp(wxID_NEW
, _T("New toolbar button"));
763 void MyFrame::OnToolbarStyle(wxCommandEvent
& event
)
765 long style
= GetToolBar()->GetWindowStyle();
766 style
&= ~(wxTB_NOICONS
| wxTB_TEXT
);
768 switch ( event
.GetId() )
770 case IDM_TOOLBAR_SHOW_TEXT
:
771 style
|= wxTB_NOICONS
| wxTB_TEXT
;
774 case IDM_TOOLBAR_SHOW_ICONS
:
778 case IDM_TOOLBAR_SHOW_BOTH
:
782 GetToolBar()->SetWindowStyle(style
);
785 void MyFrame::OnInsertPrint(wxCommandEvent
& WXUNUSED(event
))
789 wxToolBarBase
*tb
= GetToolBar();
790 tb
->InsertTool(0, wxID_PRINT
, _T("New print"),
791 wxBITMAP(print
), wxNullBitmap
,
793 _T("Delete this tool"),
794 _T("This button was inserted into the toolbar"));
796 // must call Realize() after adding a new button
800 void MyFrame::OnToolEnter(wxCommandEvent
& event
)
803 if (event
.GetSelection() > -1)
806 str
.Printf(_T("This is tool number %d"), event
.GetSelection());
810 SetStatusText(wxEmptyString
);
813 #endif // wxUSE_STATUSBAR
816 void MyFrame::OnToggleRadioBtn(wxCommandEvent
& event
)
820 m_tbar
->ToggleTool(IDM_TOOLBAR_OTHER_1
+
821 event
.GetId() - IDM_TOOLBAR_TOGGLERADIOBTN1
, true);