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 // ----------------------------------------------------------------------------
64 #include "mondrian.xpm"
65 #include "bitmaps/new.xpm"
66 #include "bitmaps/open.xpm"
67 #include "bitmaps/save.xpm"
68 #include "bitmaps/copy.xpm"
69 #include "bitmaps/cut.xpm"
70 #include "bitmaps/preview.xpm" // paste XPM
71 #include "bitmaps/print.xpm"
72 #include "bitmaps/help.xpm"
73 #endif // USE_XPM_BITMAPS
75 // ----------------------------------------------------------------------------
77 // ----------------------------------------------------------------------------
79 // Define a new application
80 class MyApp
: public wxApp
87 class MyFrame
: public wxFrame
90 MyFrame(wxFrame
*parent
,
91 wxWindowID id
= wxID_ANY
,
92 const wxString
& title
= _T("wxToolBar Sample"),
93 const wxPoint
& pos
= wxDefaultPosition
,
94 const wxSize
& size
= wxDefaultSize
,
95 long style
= wxDEFAULT_FRAME_STYLE
|wxCLIP_CHILDREN
|wxNO_FULL_REPAINT_ON_RESIZE
);
97 void RecreateToolbar();
99 void OnQuit(wxCommandEvent
& event
);
100 void OnAbout(wxCommandEvent
& event
);
102 void OnSize(wxSizeEvent
& event
);
104 void OnToggleToolbar(wxCommandEvent
& event
);
105 void OnToggleAnotherToolbar(wxCommandEvent
& event
);
106 void OnToggleHorizontalText(wxCommandEvent
& WXUNUSED(event
));
108 void OnToggleToolbarSize(wxCommandEvent
& event
);
109 void OnToggleToolbarOrient(wxCommandEvent
& event
);
110 void OnToggleToolbarRows(wxCommandEvent
& event
);
111 void OnToggleCustomDisabled(wxCommandEvent
& event
);
113 void OnEnablePrint(wxCommandEvent
& WXUNUSED(event
)) { DoEnablePrint(); }
114 void OnDeletePrint(wxCommandEvent
& WXUNUSED(event
)) { DoDeletePrint(); }
115 void OnInsertPrint(wxCommandEvent
& event
);
116 void OnChangeToolTip(wxCommandEvent
& event
);
117 void OnToggleHelp(wxCommandEvent
& WXUNUSED(event
)) { DoToggleHelp(); }
118 void OnToggleRadioBtn(wxCommandEvent
& event
);
120 void OnToolbarStyle(wxCommandEvent
& event
);
122 void OnToolLeftClick(wxCommandEvent
& event
);
123 void OnToolRightClick(wxCommandEvent
& event
);
124 void OnToolEnter(wxCommandEvent
& event
);
126 void OnCombo(wxCommandEvent
& event
);
128 void OnUpdateCopyAndCut(wxUpdateUIEvent
& event
);
129 void OnUpdateToggleHorzText(wxUpdateUIEvent
& event
);
130 void OnUpdateToggleRadioBtn(wxUpdateUIEvent
& event
)
131 { event
.Enable( m_tbar
!= NULL
); }
134 virtual wxToolBar
*OnCreateToolBar(long style
,
136 const wxString
& name
);
137 #endif // USE_GENERIC_TBAR
140 void DoEnablePrint();
141 void DoDeletePrint();
144 void LayoutChildren();
150 size_t m_rows
; // 1 or 2 only
152 // the number of print buttons we have (they're added/removed dynamically)
155 wxTextCtrl
*m_textWindow
;
159 DECLARE_EVENT_TABLE()
162 // ----------------------------------------------------------------------------
164 // ----------------------------------------------------------------------------
166 const int ID_TOOLBAR
= 500;
168 static const long TOOLBAR_STYLE
= wxTB_FLAT
| wxTB_DOCKABLE
| wxTB_TEXT
;
172 IDM_TOOLBAR_TOGGLETOOLBARSIZE
= 200,
173 IDM_TOOLBAR_TOGGLETOOLBARORIENT
,
174 IDM_TOOLBAR_TOGGLETOOLBARROWS
,
175 IDM_TOOLBAR_TOGGLECUSTOMDISABLED
,
176 IDM_TOOLBAR_ENABLEPRINT
,
177 IDM_TOOLBAR_DELETEPRINT
,
178 IDM_TOOLBAR_INSERTPRINT
,
179 IDM_TOOLBAR_TOGGLEHELP
,
180 IDM_TOOLBAR_TOGGLERADIOBTN1
,
181 IDM_TOOLBAR_TOGGLERADIOBTN2
,
182 IDM_TOOLBAR_TOGGLERADIOBTN3
,
183 IDM_TOOLBAR_TOGGLE_TOOLBAR
,
184 IDM_TOOLBAR_TOGGLE_HORIZONTAL_TEXT
,
185 IDM_TOOLBAR_TOGGLE_ANOTHER_TOOLBAR
,
186 IDM_TOOLBAR_CHANGE_TOOLTIP
,
187 IDM_TOOLBAR_SHOW_TEXT
,
188 IDM_TOOLBAR_SHOW_ICONS
,
189 IDM_TOOLBAR_SHOW_BOTH
,
198 // ----------------------------------------------------------------------------
200 // ----------------------------------------------------------------------------
202 // Notice that wxID_HELP will be processed for the 'About' menu and the toolbar
205 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
206 EVT_SIZE(MyFrame::OnSize
)
208 EVT_MENU(wxID_EXIT
, MyFrame::OnQuit
)
209 EVT_MENU(wxID_HELP
, MyFrame::OnAbout
)
211 EVT_MENU(IDM_TOOLBAR_TOGGLE_TOOLBAR
, MyFrame::OnToggleToolbar
)
212 EVT_MENU(IDM_TOOLBAR_TOGGLE_ANOTHER_TOOLBAR
, MyFrame::OnToggleAnotherToolbar
)
213 EVT_MENU(IDM_TOOLBAR_TOGGLE_HORIZONTAL_TEXT
, MyFrame::OnToggleHorizontalText
)
215 EVT_MENU(IDM_TOOLBAR_TOGGLETOOLBARSIZE
, MyFrame::OnToggleToolbarSize
)
216 EVT_MENU(IDM_TOOLBAR_TOGGLETOOLBARORIENT
, MyFrame::OnToggleToolbarOrient
)
217 EVT_MENU(IDM_TOOLBAR_TOGGLETOOLBARROWS
, MyFrame::OnToggleToolbarRows
)
218 EVT_MENU(IDM_TOOLBAR_TOGGLECUSTOMDISABLED
, MyFrame::OnToggleCustomDisabled
)
220 EVT_MENU(IDM_TOOLBAR_ENABLEPRINT
, MyFrame::OnEnablePrint
)
221 EVT_MENU(IDM_TOOLBAR_DELETEPRINT
, MyFrame::OnDeletePrint
)
222 EVT_MENU(IDM_TOOLBAR_INSERTPRINT
, MyFrame::OnInsertPrint
)
223 EVT_MENU(IDM_TOOLBAR_TOGGLEHELP
, MyFrame::OnToggleHelp
)
224 EVT_MENU_RANGE(IDM_TOOLBAR_TOGGLERADIOBTN1
, IDM_TOOLBAR_TOGGLERADIOBTN3
,
225 MyFrame::OnToggleRadioBtn
)
226 EVT_MENU(IDM_TOOLBAR_CHANGE_TOOLTIP
, MyFrame::OnChangeToolTip
)
228 EVT_MENU_RANGE(IDM_TOOLBAR_SHOW_TEXT
, IDM_TOOLBAR_SHOW_BOTH
,
229 MyFrame::OnToolbarStyle
)
231 EVT_MENU(wxID_ANY
, MyFrame::OnToolLeftClick
)
233 EVT_COMBOBOX(ID_COMBO
, MyFrame::OnCombo
)
235 EVT_TOOL_ENTER(ID_TOOLBAR
, MyFrame::OnToolEnter
)
236 EVT_TOOL_RCLICKED(wxID_ANY
, MyFrame::OnToolRightClick
)
238 EVT_UPDATE_UI(wxID_COPY
, MyFrame::OnUpdateCopyAndCut
)
239 EVT_UPDATE_UI(wxID_CUT
, MyFrame::OnUpdateCopyAndCut
)
241 EVT_UPDATE_UI_RANGE(IDM_TOOLBAR_TOGGLERADIOBTN1
,
242 IDM_TOOLBAR_TOGGLERADIOBTN3
,
243 MyFrame::OnUpdateToggleRadioBtn
)
244 EVT_UPDATE_UI(IDM_TOOLBAR_TOGGLE_HORIZONTAL_TEXT
,
245 MyFrame::OnUpdateToggleHorzText
)
248 // ============================================================================
250 // ============================================================================
252 // ----------------------------------------------------------------------------
254 // ----------------------------------------------------------------------------
258 // The `main program' equivalent, creating the windows and returning the
262 // Create the main frame window
263 MyFrame
* frame
= new MyFrame((wxFrame
*) NULL
, wxID_ANY
,
264 _T("wxToolBar Sample"),
266 wxDefaultPosition
, wxDefaultSize
268 wxPoint(100, 100), wxSize(550, 300)
275 frame
->SetStatusText(_T("Hello, wxWidgets"));
283 void MyFrame::RecreateToolbar()
286 // On Windows CE, we should not delete the
287 // previous toolbar in case it contains the menubar.
288 // We'll try to accommodate this usage in due course.
289 wxToolBar
* toolBar
= CreateToolBar();
291 // delete and recreate the toolbar
292 wxToolBarBase
*toolBar
= GetToolBar();
293 long style
= toolBar
? toolBar
->GetWindowStyle() : TOOLBAR_STYLE
;
299 style
&= ~(wxTB_HORIZONTAL
| wxTB_VERTICAL
| wxTB_HORZ_LAYOUT
);
300 style
|= m_horzToolbar
? wxTB_HORIZONTAL
: wxTB_VERTICAL
;
302 if ( style
& wxTB_TEXT
&& !(style
& wxTB_NOICONS
) && m_horzText
)
303 style
|= wxTB_HORZ_LAYOUT
;
305 toolBar
= CreateToolBar(style
, ID_TOOLBAR
);
322 wxBitmap toolBarBitmaps
[Tool_Max
];
325 #define INIT_TOOL_BMP(bmp) \
326 toolBarBitmaps[Tool_##bmp] = wxBitmap(bmp##_xpm)
327 #else // !USE_XPM_BITMAPS
328 #define INIT_TOOL_BMP(bmp) \
329 toolBarBitmaps[Tool_##bmp] = wxBITMAP(bmp)
330 #endif // USE_XPM_BITMAPS/!USE_XPM_BITMAPS
337 INIT_TOOL_BMP(paste
);
338 INIT_TOOL_BMP(print
);
341 int w
= toolBarBitmaps
[Tool_new
].GetWidth(),
342 h
= toolBarBitmaps
[Tool_new
].GetHeight();
344 if ( !m_smallToolbar
)
349 for ( size_t n
= Tool_new
; n
< WXSIZEOF(toolBarBitmaps
); n
++ )
352 wxBitmap(toolBarBitmaps
[n
].ConvertToImage().Scale(w
, h
));
355 toolBar
->SetToolBitmapSize(wxSize(w
, h
));
358 toolBar
->AddTool(wxID_NEW
, _T("New"), toolBarBitmaps
[Tool_new
], _T("New file"));
359 toolBar
->AddTool(wxID_OPEN
, _T("Open"), toolBarBitmaps
[Tool_open
], _T("Open file"));
361 // the generic toolbar doesn't really support this
362 #if (wxUSE_TOOLBAR_NATIVE && !USE_GENERIC_TBAR) && !defined(__WXX11__) || defined(__WXUNIVERSAL__)
363 // adding a combo to a vertical toolbar is not very smart
366 wxComboBox
*combo
= new wxComboBox(toolBar
, ID_COMBO
, _T(""), wxDefaultPosition
, wxSize(200,wxDefaultCoord
) );
367 combo
->Append(_T("This"));
368 combo
->Append(_T("is a"));
369 combo
->Append(_T("combobox"));
370 combo
->Append(_T("in a"));
371 combo
->Append(_T("toolbar"));
372 toolBar
->AddControl(combo
);
374 #endif // toolbars which don't support controls
376 toolBar
->AddTool(wxID_SAVE
, _T("Save"), toolBarBitmaps
[Tool_save
], _T("Toggle button 1"), wxITEM_CHECK
);
377 toolBar
->AddTool(wxID_COPY
, _T("Copy"), toolBarBitmaps
[Tool_copy
], _T("Toggle button 2"), wxITEM_CHECK
);
378 toolBar
->AddTool(wxID_CUT
, _T("Cut"), toolBarBitmaps
[Tool_cut
], _T("Toggle/Untoggle help button"));
379 toolBar
->AddTool(wxID_PASTE
, _T("Paste"), toolBarBitmaps
[Tool_paste
], _T("Paste"));
381 if ( m_useCustomDisabled
)
383 wxBitmap
bmpDisabled(w
, h
);
386 dc
.SelectObject(bmpDisabled
);
387 dc
.DrawBitmap(toolBarBitmaps
[Tool_print
], 0, 0);
389 wxPen
pen(*wxRED
, 5);
391 dc
.DrawLine(0, 0, w
, h
);
394 toolBar
->AddTool(wxID_PRINT
, _T("Print"), toolBarBitmaps
[Tool_print
],
399 toolBar
->AddTool(wxID_PRINT
, _T("Print"), toolBarBitmaps
[Tool_print
],
400 _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."));
403 toolBar
->AddSeparator();
404 toolBar
->AddTool(wxID_HELP
, _T("Help"), toolBarBitmaps
[Tool_help
], _T("Help button"), wxITEM_CHECK
);
406 // after adding the buttons to the toolbar, must call Realize() to reflect
410 toolBar
->SetRows(m_horzToolbar
? m_rows
: 10 / m_rows
);
413 // ----------------------------------------------------------------------------
415 // ----------------------------------------------------------------------------
417 // Define my frame constructor
418 MyFrame::MyFrame(wxFrame
* parent
,
420 const wxString
& title
,
424 : wxFrame(parent
, id
, title
, pos
, size
, style
)
428 m_smallToolbar
= true;
429 m_horzToolbar
= true;
431 m_useCustomDisabled
= false;
436 // Give it a status line
441 SetIcon(wxICON(mondrian
));
444 wxMenu
*tbarMenu
= new wxMenu
;
445 tbarMenu
->AppendCheckItem(IDM_TOOLBAR_TOGGLE_TOOLBAR
,
446 _T("Toggle &toolbar\tCtrl-Z"),
447 _T("Show or hide the toolbar"));
449 tbarMenu
->AppendCheckItem(IDM_TOOLBAR_TOGGLE_ANOTHER_TOOLBAR
,
450 _T("Toggle &another toolbar\tCtrl-A"),
451 _T("Show/hide another test toolbar"));
453 tbarMenu
->AppendCheckItem(IDM_TOOLBAR_TOGGLE_HORIZONTAL_TEXT
,
454 _T("Toggle hori&zontal text\tCtrl-H"),
455 _T("Show text under/alongside the icon"));
457 tbarMenu
->AppendCheckItem(IDM_TOOLBAR_TOGGLETOOLBARSIZE
,
458 _T("&Toggle toolbar size\tCtrl-S"),
459 _T("Toggle between big/small toolbar"));
461 tbarMenu
->AppendCheckItem(IDM_TOOLBAR_TOGGLETOOLBARORIENT
,
462 _T("Toggle toolbar &orientation\tCtrl-O"),
463 _T("Toggle toolbar orientation"));
465 tbarMenu
->AppendCheckItem(IDM_TOOLBAR_TOGGLETOOLBARROWS
,
466 _T("Toggle number of &rows\tCtrl-R"),
467 _T("Toggle number of toolbar rows between 1 and 2"));
469 tbarMenu
->AppendCheckItem(IDM_TOOLBAR_TOGGLECUSTOMDISABLED
,
470 _T("Use c&ustom disabled images\tCtrl-U"),
471 _T("Switch between using system-generated and custom disabled images"));
474 tbarMenu
->AppendSeparator();
476 tbarMenu
->Append(IDM_TOOLBAR_ENABLEPRINT
, _T("&Enable print button\tCtrl-E"), _T(""));
477 tbarMenu
->Append(IDM_TOOLBAR_DELETEPRINT
, _T("&Delete print button\tCtrl-D"), _T(""));
478 tbarMenu
->Append(IDM_TOOLBAR_INSERTPRINT
, _T("&Insert print button\tCtrl-I"), _T(""));
479 tbarMenu
->Append(IDM_TOOLBAR_TOGGLEHELP
, _T("Toggle &help button\tCtrl-T"), _T(""));
480 tbarMenu
->AppendSeparator();
481 tbarMenu
->Append(IDM_TOOLBAR_TOGGLERADIOBTN1
, _T("Toggle &1st radio button\tCtrl-1"), _T(""));
482 tbarMenu
->Append(IDM_TOOLBAR_TOGGLERADIOBTN2
, _T("Toggle &2nd radio button\tCtrl-2"), _T(""));
483 tbarMenu
->Append(IDM_TOOLBAR_TOGGLERADIOBTN3
, _T("Toggle &3rd radio button\tCtrl-3"), _T(""));
484 tbarMenu
->AppendSeparator();
485 tbarMenu
->Append(IDM_TOOLBAR_CHANGE_TOOLTIP
, _T("Change tool tip"), _T(""));
486 tbarMenu
->AppendSeparator();
487 tbarMenu
->AppendRadioItem(IDM_TOOLBAR_SHOW_TEXT
, _T("Show &text\tAlt-T"));
488 tbarMenu
->AppendRadioItem(IDM_TOOLBAR_SHOW_ICONS
, _T("Show &icons\tAlt-I"));
489 tbarMenu
->AppendRadioItem(IDM_TOOLBAR_SHOW_BOTH
, _T("Show &both\tAlt-B"));
491 wxMenu
*fileMenu
= new wxMenu
;
492 fileMenu
->Append(wxID_EXIT
, _T("E&xit\tAlt-X"), _T("Quit toolbar sample") );
494 wxMenu
*helpMenu
= new wxMenu
;
495 helpMenu
->Append(wxID_HELP
, _T("&About"), _T("About toolbar sample"));
497 wxMenuBar
* menuBar
= new wxMenuBar( wxMB_DOCKABLE
);
499 menuBar
->Append(fileMenu
, _T("&File"));
500 menuBar
->Append(tbarMenu
, _T("&Toolbar"));
501 menuBar
->Append(helpMenu
, _T("&Help"));
503 // Associate the menu bar with the frame
506 menuBar
->Check(IDM_TOOLBAR_SHOW_BOTH
, true);
508 // Create the toolbar
511 m_textWindow
= new wxTextCtrl(this, wxID_ANY
, _T(""), wxPoint(0, 0), wxDefaultSize
, wxTE_MULTILINE
);
516 wxToolBar
* MyFrame::OnCreateToolBar(long style
,
518 const wxString
& name
)
520 return (wxToolBar
*)new wxToolBarSimple(this, id
,
521 wxDefaultPosition
, wxDefaultSize
,
525 #endif // USE_GENERIC_TBAR
527 void MyFrame::LayoutChildren()
529 wxSize size
= GetClientSize();
534 m_tbar
->SetSize(wxDefaultCoord
, size
.y
);
537 offset
= m_tbar
->GetSize().x
;
544 m_textWindow
->SetSize(offset
, 0, size
.x
- offset
, size
.y
);
547 void MyFrame::OnSize(wxSizeEvent
& event
)
559 void MyFrame::OnToggleToolbar(wxCommandEvent
& WXUNUSED(event
))
561 wxToolBar
*tbar
= GetToolBar();
575 void MyFrame::OnToggleHorizontalText(wxCommandEvent
& WXUNUSED(event
))
577 m_horzText
= !m_horzText
;
582 void MyFrame::OnToggleAnotherToolbar(wxCommandEvent
& WXUNUSED(event
))
591 long style
= GetToolBar()->GetWindowStyle();
592 style
&= ~wxTB_HORIZONTAL
;
593 style
|= wxTB_VERTICAL
;
595 m_tbar
= new wxToolBar(this, wxID_ANY
,
596 wxDefaultPosition
, wxDefaultSize
,
599 m_tbar
->SetMargins(4, 4);
601 m_tbar
->AddRadioTool(IDM_TOOLBAR_OTHER_1
, _T("First"), wxBITMAP(new));
602 m_tbar
->AddRadioTool(IDM_TOOLBAR_OTHER_2
, _T("Second"), wxBITMAP(open
));
603 m_tbar
->AddRadioTool(IDM_TOOLBAR_OTHER_3
, _T("Third"), wxBITMAP(save
));
604 m_tbar
->AddSeparator();
605 m_tbar
->AddTool(wxID_HELP
, _T("Help"), wxBITMAP(help
));
613 void MyFrame::OnToggleToolbarSize(wxCommandEvent
& WXUNUSED(event
))
615 m_smallToolbar
= !m_smallToolbar
;
620 void MyFrame::OnToggleToolbarRows(wxCommandEvent
& WXUNUSED(event
))
622 // m_rows may be only 1 or 2
625 GetToolBar()->SetRows(m_horzToolbar
? m_rows
: 10 / m_rows
);
627 //RecreateToolbar(); -- this is unneeded
630 void MyFrame::OnToggleCustomDisabled(wxCommandEvent
& WXUNUSED(event
))
632 m_useCustomDisabled
= !m_useCustomDisabled
;
637 void MyFrame::OnToggleToolbarOrient(wxCommandEvent
& WXUNUSED(event
))
639 m_horzToolbar
= !m_horzToolbar
;
644 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
649 void MyFrame::OnAbout(wxCommandEvent
& event
)
651 if ( event
.IsChecked() )
652 m_textWindow
->WriteText( _T("Help button down now.\n") );
654 m_textWindow
->WriteText( _T("Help button up now.\n") );
656 (void)wxMessageBox(_T("wxWidgets toolbar sample"), _T("About wxToolBar"));
659 void MyFrame::OnToolLeftClick(wxCommandEvent
& event
)
662 str
.Printf( _T("Clicked on tool %d\n"), event
.GetId());
663 m_textWindow
->WriteText( str
);
665 if (event
.GetId() == wxID_COPY
)
670 if (event
.GetId() == wxID_CUT
)
675 if (event
.GetId() == wxID_PRINT
)
681 void MyFrame::OnToolRightClick(wxCommandEvent
& event
)
683 m_textWindow
->AppendText(
684 wxString::Format(_T("Tool %d right clicked.\n"),
685 (int) event
.GetInt()));
688 void MyFrame::OnCombo(wxCommandEvent
& event
)
690 wxLogStatus(_T("Combobox string '%s' selected"), event
.GetString().c_str());
693 void MyFrame::DoEnablePrint()
698 wxToolBarBase
*tb
= GetToolBar();
699 tb
->EnableTool(wxID_PRINT
, !tb
->GetToolEnabled(wxID_PRINT
));
702 void MyFrame::DoDeletePrint()
707 wxToolBarBase
*tb
= GetToolBar();
708 tb
->DeleteTool( wxID_PRINT
);
713 void MyFrame::DoToggleHelp()
715 wxToolBarBase
*tb
= GetToolBar();
716 tb
->ToggleTool( wxID_HELP
, !tb
->GetToolState( wxID_HELP
) );
719 void MyFrame::OnUpdateCopyAndCut(wxUpdateUIEvent
& event
)
721 event
.Enable( m_textWindow
->CanCopy() );
724 void MyFrame::OnUpdateToggleHorzText(wxUpdateUIEvent
& event
)
726 wxToolBar
*tbar
= GetToolBar();
727 event
.Enable( tbar
&&
728 tbar
->HasFlag(wxTB_TEXT
) &&
729 !tbar
->HasFlag(wxTB_NOICONS
) );
732 void MyFrame::OnChangeToolTip(wxCommandEvent
& WXUNUSED(event
))
734 GetToolBar()->SetToolShortHelp(wxID_NEW
, _T("New toolbar button"));
737 void MyFrame::OnToolbarStyle(wxCommandEvent
& event
)
739 long style
= GetToolBar()->GetWindowStyle();
740 style
&= ~(wxTB_NOICONS
| wxTB_TEXT
);
742 switch ( event
.GetId() )
744 case IDM_TOOLBAR_SHOW_TEXT
:
745 style
|= wxTB_NOICONS
| wxTB_TEXT
;
748 case IDM_TOOLBAR_SHOW_ICONS
:
752 case IDM_TOOLBAR_SHOW_BOTH
:
756 GetToolBar()->SetWindowStyle(style
);
759 void MyFrame::OnInsertPrint(wxCommandEvent
& WXUNUSED(event
))
763 wxToolBarBase
*tb
= GetToolBar();
764 tb
->InsertTool(0, wxID_PRINT
, _T("New print"),
765 wxBITMAP(print
), wxNullBitmap
,
767 _T("Delete this tool"),
768 _T("This button was inserted into the toolbar"));
770 // must call Realize() after adding a new button
774 void MyFrame::OnToolEnter(wxCommandEvent
& event
)
777 if (event
.GetSelection() > -1)
780 str
.Printf(_T("This is tool number %d"), event
.GetSelection());
784 SetStatusText(_T(""));
787 #endif // wxUSE_STATUSBAR
790 void MyFrame::OnToggleRadioBtn(wxCommandEvent
& event
)
794 m_tbar
->ToggleTool(IDM_TOOLBAR_OTHER_1
+
795 event
.GetId() - IDM_TOOLBAR_TOGGLERADIOBTN1
, true);