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"
34 #include "wx/filedlg.h"
36 // define this to use XPMs everywhere (by default, BMPs are used under Win)
37 // BMPs use less space, but aren't compiled into the executable on other platforms
39 #define USE_XPM_BITMAPS 0
41 #define USE_XPM_BITMAPS 1
44 #if USE_XPM_BITMAPS && defined(__WXMSW__) && !wxUSE_XPM_IN_MSW
45 #error You need to enable XPM support to use XPM bitmaps with toolbar!
46 #endif // USE_XPM_BITMAPS
48 // ----------------------------------------------------------------------------
50 // ----------------------------------------------------------------------------
52 #if !defined(__WXMSW__) && !defined(__WXPM__)
53 #include "mondrian.xpm"
57 #include "bitmaps/new.xpm"
58 #include "bitmaps/open.xpm"
59 #include "bitmaps/save.xpm"
60 #include "bitmaps/copy.xpm"
61 #include "bitmaps/cut.xpm"
62 #include "bitmaps/preview.xpm" // paste XPM
63 #include "bitmaps/print.xpm"
64 #include "bitmaps/help.xpm"
65 #endif // USE_XPM_BITMAPS
67 // ----------------------------------------------------------------------------
69 // ----------------------------------------------------------------------------
71 // Define a new application
72 class MyApp
: public wxApp
79 class MyFrame
: public wxFrame
82 MyFrame(wxFrame
*parent
,
83 wxWindowID id
= wxID_ANY
,
84 const wxString
& title
= _T("wxToolBar Sample"),
85 const wxPoint
& pos
= wxDefaultPosition
,
86 const wxSize
& size
= wxDefaultSize
,
87 long style
= wxDEFAULT_FRAME_STYLE
|wxCLIP_CHILDREN
|wxNO_FULL_REPAINT_ON_RESIZE
);
89 void RecreateToolbar();
91 void OnQuit(wxCommandEvent
& event
);
92 void OnAbout(wxCommandEvent
& event
);
94 void OnSize(wxSizeEvent
& event
);
96 void OnToggleToolbar(wxCommandEvent
& event
);
97 void OnToggleAnotherToolbar(wxCommandEvent
& event
);
98 void OnToggleHorizontalText(wxCommandEvent
& WXUNUSED(event
));
100 void OnToggleToolbarSize(wxCommandEvent
& event
);
101 void OnToggleToolbarOrient(wxCommandEvent
& event
);
102 void OnToggleToolbarRows(wxCommandEvent
& event
);
103 void OnToggleTooltips(wxCommandEvent
& event
);
104 void OnToggleCustomDisabled(wxCommandEvent
& event
);
106 void OnEnablePrint(wxCommandEvent
& WXUNUSED(event
)) { DoEnablePrint(); }
107 void OnDeletePrint(wxCommandEvent
& WXUNUSED(event
)) { DoDeletePrint(); }
108 void OnInsertPrint(wxCommandEvent
& event
);
109 void OnChangeToolTip(wxCommandEvent
& event
);
110 void OnToggleHelp(wxCommandEvent
& WXUNUSED(event
)) { DoToggleHelp(); }
111 void OnToggleRadioBtn(wxCommandEvent
& event
);
113 void OnToolbarStyle(wxCommandEvent
& event
);
114 void OnToolbarCustomBitmap(wxCommandEvent
& event
);
116 void OnToolLeftClick(wxCommandEvent
& event
);
117 void OnToolRightClick(wxCommandEvent
& event
);
118 void OnToolEnter(wxCommandEvent
& event
);
120 void OnCombo(wxCommandEvent
& event
);
122 void OnUpdateCopyAndCut(wxUpdateUIEvent
& event
);
123 void OnUpdateToggleHorzText(wxUpdateUIEvent
& event
);
124 void OnUpdateToggleRadioBtn(wxUpdateUIEvent
& event
)
125 { event
.Enable( m_tbar
!= NULL
); }
128 void DoEnablePrint();
129 void DoDeletePrint();
132 void LayoutChildren();
139 size_t m_rows
; // 1 or 2 only
141 // the number of print buttons we have (they're added/removed dynamically)
144 wxTextCtrl
*m_textWindow
;
148 // the path to the custom bitmap for the test toolbar tool
151 DECLARE_EVENT_TABLE()
154 // ----------------------------------------------------------------------------
156 // ----------------------------------------------------------------------------
158 const int ID_TOOLBAR
= 500;
160 static const long TOOLBAR_STYLE
= wxTB_FLAT
| wxTB_DOCKABLE
| wxTB_TEXT
;
164 IDM_TOOLBAR_TOGGLETOOLBARSIZE
= 200,
165 IDM_TOOLBAR_TOGGLETOOLBARORIENT
,
166 IDM_TOOLBAR_TOGGLETOOLBARROWS
,
167 IDM_TOOLBAR_TOGGLETOOLTIPS
,
168 IDM_TOOLBAR_TOGGLECUSTOMDISABLED
,
169 IDM_TOOLBAR_ENABLEPRINT
,
170 IDM_TOOLBAR_DELETEPRINT
,
171 IDM_TOOLBAR_INSERTPRINT
,
172 IDM_TOOLBAR_TOGGLEHELP
,
173 IDM_TOOLBAR_TOGGLERADIOBTN1
,
174 IDM_TOOLBAR_TOGGLERADIOBTN2
,
175 IDM_TOOLBAR_TOGGLERADIOBTN3
,
176 IDM_TOOLBAR_TOGGLE_TOOLBAR
,
177 IDM_TOOLBAR_TOGGLE_HORIZONTAL_TEXT
,
178 IDM_TOOLBAR_TOGGLE_ANOTHER_TOOLBAR
,
179 IDM_TOOLBAR_CHANGE_TOOLTIP
,
180 IDM_TOOLBAR_SHOW_TEXT
,
181 IDM_TOOLBAR_SHOW_ICONS
,
182 IDM_TOOLBAR_SHOW_BOTH
,
183 IDM_TOOLBAR_CUSTOM_PATH
,
192 // ----------------------------------------------------------------------------
194 // ----------------------------------------------------------------------------
196 // Notice that wxID_HELP will be processed for the 'About' menu and the toolbar
199 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
200 EVT_SIZE(MyFrame::OnSize
)
202 EVT_MENU(wxID_EXIT
, MyFrame::OnQuit
)
203 EVT_MENU(wxID_HELP
, MyFrame::OnAbout
)
205 EVT_MENU(IDM_TOOLBAR_TOGGLE_TOOLBAR
, MyFrame::OnToggleToolbar
)
206 EVT_MENU(IDM_TOOLBAR_TOGGLE_ANOTHER_TOOLBAR
, MyFrame::OnToggleAnotherToolbar
)
207 EVT_MENU(IDM_TOOLBAR_TOGGLE_HORIZONTAL_TEXT
, MyFrame::OnToggleHorizontalText
)
209 EVT_MENU(IDM_TOOLBAR_TOGGLETOOLBARSIZE
, MyFrame::OnToggleToolbarSize
)
210 EVT_MENU(IDM_TOOLBAR_TOGGLETOOLBARORIENT
, MyFrame::OnToggleToolbarOrient
)
211 EVT_MENU(IDM_TOOLBAR_TOGGLETOOLBARROWS
, MyFrame::OnToggleToolbarRows
)
212 EVT_MENU(IDM_TOOLBAR_TOGGLETOOLTIPS
, MyFrame::OnToggleTooltips
)
213 EVT_MENU(IDM_TOOLBAR_TOGGLECUSTOMDISABLED
, MyFrame::OnToggleCustomDisabled
)
215 EVT_MENU(IDM_TOOLBAR_ENABLEPRINT
, MyFrame::OnEnablePrint
)
216 EVT_MENU(IDM_TOOLBAR_DELETEPRINT
, MyFrame::OnDeletePrint
)
217 EVT_MENU(IDM_TOOLBAR_INSERTPRINT
, MyFrame::OnInsertPrint
)
218 EVT_MENU(IDM_TOOLBAR_TOGGLEHELP
, MyFrame::OnToggleHelp
)
219 EVT_MENU_RANGE(IDM_TOOLBAR_TOGGLERADIOBTN1
, IDM_TOOLBAR_TOGGLERADIOBTN3
,
220 MyFrame::OnToggleRadioBtn
)
221 EVT_MENU(IDM_TOOLBAR_CHANGE_TOOLTIP
, MyFrame::OnChangeToolTip
)
223 EVT_MENU_RANGE(IDM_TOOLBAR_SHOW_TEXT
, IDM_TOOLBAR_SHOW_BOTH
,
224 MyFrame::OnToolbarStyle
)
226 EVT_MENU(IDM_TOOLBAR_CUSTOM_PATH
, MyFrame::OnToolbarCustomBitmap
)
228 EVT_MENU(wxID_ANY
, MyFrame::OnToolLeftClick
)
230 EVT_COMBOBOX(ID_COMBO
, MyFrame::OnCombo
)
232 EVT_TOOL_ENTER(ID_TOOLBAR
, MyFrame::OnToolEnter
)
233 EVT_TOOL_RCLICKED(wxID_ANY
, MyFrame::OnToolRightClick
)
235 EVT_UPDATE_UI(wxID_COPY
, MyFrame::OnUpdateCopyAndCut
)
236 EVT_UPDATE_UI(wxID_CUT
, MyFrame::OnUpdateCopyAndCut
)
238 EVT_UPDATE_UI_RANGE(IDM_TOOLBAR_TOGGLERADIOBTN1
,
239 IDM_TOOLBAR_TOGGLERADIOBTN3
,
240 MyFrame::OnUpdateToggleRadioBtn
)
241 EVT_UPDATE_UI(IDM_TOOLBAR_TOGGLE_HORIZONTAL_TEXT
,
242 MyFrame::OnUpdateToggleHorzText
)
245 // ============================================================================
247 // ============================================================================
249 // ----------------------------------------------------------------------------
251 // ----------------------------------------------------------------------------
255 // The `main program' equivalent, creating the windows and returning the
259 // Create the main frame window
260 MyFrame
* frame
= new MyFrame((wxFrame
*) NULL
, wxID_ANY
,
261 _T("wxToolBar Sample"),
262 wxPoint(100, 100), wxSize(550, 300));
267 frame
->SetStatusText(_T("Hello, wxWidgets"));
270 wxInitAllImageHandlers();
277 void MyFrame::RecreateToolbar()
280 // On Windows CE, we should not delete the
281 // previous toolbar in case it contains the menubar.
282 // We'll try to accommodate this usage in due course.
283 wxToolBar
* toolBar
= CreateToolBar();
285 // delete and recreate the toolbar
286 wxToolBarBase
*toolBar
= GetToolBar();
287 long style
= toolBar
? toolBar
->GetWindowStyle() : TOOLBAR_STYLE
;
293 style
&= ~(wxTB_HORIZONTAL
| wxTB_VERTICAL
| wxTB_HORZ_LAYOUT
);
294 style
|= m_horzToolbar
? wxTB_HORIZONTAL
: wxTB_VERTICAL
;
296 if ( m_showTooltips
)
297 style
&= ~wxTB_NO_TOOLTIPS
;
299 style
|= wxTB_NO_TOOLTIPS
;
301 if ( style
& wxTB_TEXT
&& !(style
& wxTB_NOICONS
) && m_horzText
)
302 style
|= wxTB_HORZ_LAYOUT
;
304 toolBar
= CreateToolBar(style
, ID_TOOLBAR
);
321 wxBitmap toolBarBitmaps
[Tool_Max
];
324 #define INIT_TOOL_BMP(bmp) \
325 toolBarBitmaps[Tool_##bmp] = wxBitmap(bmp##_xpm)
326 #else // !USE_XPM_BITMAPS
327 #define INIT_TOOL_BMP(bmp) \
328 toolBarBitmaps[Tool_##bmp] = wxBITMAP(bmp)
329 #endif // USE_XPM_BITMAPS/!USE_XPM_BITMAPS
336 INIT_TOOL_BMP(paste
);
337 INIT_TOOL_BMP(print
);
340 int w
= toolBarBitmaps
[Tool_new
].GetWidth(),
341 h
= toolBarBitmaps
[Tool_new
].GetHeight();
343 if ( !m_smallToolbar
)
348 for ( size_t n
= Tool_new
; n
< WXSIZEOF(toolBarBitmaps
); n
++ )
351 wxBitmap(toolBarBitmaps
[n
].ConvertToImage().Scale(w
, h
));
355 toolBar
->SetToolBitmapSize(wxSize(w
, h
));
357 toolBar
->AddTool(wxID_NEW
, _T("New"), toolBarBitmaps
[Tool_new
], _T("New file"));
358 toolBar
->AddTool(wxID_OPEN
, _T("Open"), toolBarBitmaps
[Tool_open
], _T("Open file"));
360 // the generic toolbar doesn't really support this
361 #if wxUSE_TOOLBAR_NATIVE && !defined(__WXX11__) || defined(__WXUNIVERSAL__)
362 // adding a combo to a vertical toolbar is not very smart
365 wxComboBox
*combo
= new wxComboBox(toolBar
, ID_COMBO
, wxEmptyString
, wxDefaultPosition
, wxSize(200,wxDefaultCoord
) );
366 combo
->Append(_T("This"));
367 combo
->Append(_T("is a"));
368 combo
->Append(_T("combobox"));
369 combo
->Append(_T("in a"));
370 combo
->Append(_T("toolbar"));
371 toolBar
->AddControl(combo
);
373 #endif // toolbars which don't support controls
375 toolBar
->AddTool(wxID_SAVE
, _T("Save"), toolBarBitmaps
[Tool_save
], _T("Toggle button 1"), wxITEM_CHECK
);
376 toolBar
->AddTool(wxID_COPY
, _T("Copy"), toolBarBitmaps
[Tool_copy
], _T("Toggle button 2"), wxITEM_CHECK
);
377 toolBar
->AddTool(wxID_CUT
, _T("Cut"), toolBarBitmaps
[Tool_cut
], _T("Toggle/Untoggle help button"));
378 toolBar
->AddTool(wxID_PASTE
, _T("Paste"), toolBarBitmaps
[Tool_paste
], _T("Paste"));
380 if ( m_useCustomDisabled
)
382 wxBitmap
bmpDisabled(w
, h
);
385 dc
.SelectObject(bmpDisabled
);
386 dc
.DrawBitmap(toolBarBitmaps
[Tool_print
], 0, 0);
388 wxPen
pen(*wxRED
, 5);
390 dc
.DrawLine(0, 0, w
, h
);
393 toolBar
->AddTool(wxID_PRINT
, _T("Print"), toolBarBitmaps
[Tool_print
],
398 toolBar
->AddTool(wxID_PRINT
, _T("Print"), toolBarBitmaps
[Tool_print
],
399 _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."));
402 toolBar
->AddSeparator();
403 toolBar
->AddTool(wxID_HELP
, _T("Help"), toolBarBitmaps
[Tool_help
], _T("Help button"), wxITEM_CHECK
);
405 if ( !m_pathBmp
.empty() )
407 // create a tool with a custom bitmap for testing
408 wxImage
img(m_pathBmp
);
411 if ( img
.GetWidth() > w
&& img
.GetHeight() > h
)
412 img
= img
.GetSubImage(wxRect(0, 0, w
, h
));
414 toolBar
->AddSeparator();
415 toolBar
->AddTool(wxID_ANY
, _T("Custom"), img
);
419 // after adding the buttons to the toolbar, must call Realize() to reflect
423 toolBar
->SetRows(m_horzToolbar
? m_rows
: 10 / m_rows
);
426 // ----------------------------------------------------------------------------
428 // ----------------------------------------------------------------------------
430 // Define my frame constructor
431 MyFrame::MyFrame(wxFrame
* parent
,
433 const wxString
& title
,
437 : wxFrame(parent
, id
, title
, pos
, size
, style
)
441 m_smallToolbar
= true;
442 m_horzToolbar
= true;
444 m_useCustomDisabled
= false;
445 m_showTooltips
= true;
451 // Give it a status line
456 SetIcon(wxICON(mondrian
));
459 wxMenu
*tbarMenu
= new wxMenu
;
460 tbarMenu
->AppendCheckItem(IDM_TOOLBAR_TOGGLE_TOOLBAR
,
461 _T("Toggle &toolbar\tCtrl-Z"),
462 _T("Show or hide the toolbar"));
464 tbarMenu
->AppendCheckItem(IDM_TOOLBAR_TOGGLE_ANOTHER_TOOLBAR
,
465 _T("Toggle &another toolbar\tCtrl-A"),
466 _T("Show/hide another test toolbar"));
468 tbarMenu
->AppendCheckItem(IDM_TOOLBAR_TOGGLE_HORIZONTAL_TEXT
,
469 _T("Toggle hori&zontal text\tCtrl-H"),
470 _T("Show text under/alongside the icon"));
472 tbarMenu
->AppendCheckItem(IDM_TOOLBAR_TOGGLETOOLBARSIZE
,
473 _T("&Toggle toolbar size\tCtrl-S"),
474 _T("Toggle between big/small toolbar"));
476 tbarMenu
->AppendCheckItem(IDM_TOOLBAR_TOGGLETOOLBARORIENT
,
477 _T("Toggle toolbar &orientation\tCtrl-O"),
478 _T("Toggle toolbar orientation"));
480 tbarMenu
->AppendCheckItem(IDM_TOOLBAR_TOGGLETOOLBARROWS
,
481 _T("Toggle number of &rows\tCtrl-R"),
482 _T("Toggle number of toolbar rows between 1 and 2"));
484 tbarMenu
->AppendCheckItem(IDM_TOOLBAR_TOGGLETOOLTIPS
,
485 _T("Show &tooltips\tCtrl-L"),
486 _T("Show tooltips for the toolbar tools"));
488 tbarMenu
->AppendCheckItem(IDM_TOOLBAR_TOGGLECUSTOMDISABLED
,
489 _T("Use c&ustom disabled images\tCtrl-U"),
490 _T("Switch between using system-generated and custom disabled images"));
493 tbarMenu
->AppendSeparator();
495 tbarMenu
->Append(IDM_TOOLBAR_ENABLEPRINT
, _T("&Enable print button\tCtrl-E"));
496 tbarMenu
->Append(IDM_TOOLBAR_DELETEPRINT
, _T("&Delete print button\tCtrl-D"));
497 tbarMenu
->Append(IDM_TOOLBAR_INSERTPRINT
, _T("&Insert print button\tCtrl-I"));
498 tbarMenu
->Append(IDM_TOOLBAR_TOGGLEHELP
, _T("Toggle &help button\tCtrl-T"));
499 tbarMenu
->AppendSeparator();
500 tbarMenu
->Append(IDM_TOOLBAR_TOGGLERADIOBTN1
, _T("Toggle &1st radio button\tCtrl-1"));
501 tbarMenu
->Append(IDM_TOOLBAR_TOGGLERADIOBTN2
, _T("Toggle &2nd radio button\tCtrl-2"));
502 tbarMenu
->Append(IDM_TOOLBAR_TOGGLERADIOBTN3
, _T("Toggle &3rd radio button\tCtrl-3"));
503 tbarMenu
->AppendSeparator();
504 tbarMenu
->Append(IDM_TOOLBAR_CHANGE_TOOLTIP
, _T("Change tool tip"));
505 tbarMenu
->AppendSeparator();
506 tbarMenu
->AppendRadioItem(IDM_TOOLBAR_SHOW_TEXT
, _T("Show &text\tCtrl-Alt-T"));
507 tbarMenu
->AppendRadioItem(IDM_TOOLBAR_SHOW_ICONS
, _T("Show &icons\tCtrl-Alt-I"));
508 tbarMenu
->AppendRadioItem(IDM_TOOLBAR_SHOW_BOTH
, _T("Show &both\tCtrl-Alt-B"));
509 tbarMenu
->AppendSeparator();
510 tbarMenu
->Append(IDM_TOOLBAR_CUSTOM_PATH
, _T("Custom &bitmap...\tCtrl-B"));
512 wxMenu
*fileMenu
= new wxMenu
;
513 fileMenu
->Append(wxID_EXIT
, _T("E&xit\tAlt-X"), _T("Quit toolbar sample") );
515 wxMenu
*helpMenu
= new wxMenu
;
516 helpMenu
->Append(wxID_HELP
, _T("&About"), _T("About toolbar sample"));
518 wxMenuBar
* menuBar
= new wxMenuBar( wxMB_DOCKABLE
);
520 menuBar
->Append(fileMenu
, _T("&File"));
521 menuBar
->Append(tbarMenu
, _T("&Toolbar"));
522 menuBar
->Append(helpMenu
, _T("&Help"));
524 // Associate the menu bar with the frame
527 menuBar
->Check(IDM_TOOLBAR_SHOW_BOTH
, true);
528 menuBar
->Check(IDM_TOOLBAR_TOGGLETOOLTIPS
, true);
530 // Create the toolbar
533 m_textWindow
= new wxTextCtrl(this, wxID_ANY
, wxEmptyString
, wxPoint(0, 0), wxDefaultSize
, wxTE_MULTILINE
);
536 void MyFrame::LayoutChildren()
538 wxSize size
= GetClientSize();
543 m_tbar
->SetSize(0, 0, wxDefaultCoord
, size
.y
);
545 offset
= m_tbar
->GetSize().x
;
552 m_textWindow
->SetSize(offset
, 0, size
.x
- offset
, size
.y
);
555 void MyFrame::OnSize(wxSizeEvent
& event
)
567 void MyFrame::OnToggleToolbar(wxCommandEvent
& WXUNUSED(event
))
569 wxToolBar
*tbar
= GetToolBar();
583 void MyFrame::OnToggleHorizontalText(wxCommandEvent
& WXUNUSED(event
))
585 m_horzText
= !m_horzText
;
590 void MyFrame::OnToggleAnotherToolbar(wxCommandEvent
& WXUNUSED(event
))
599 long style
= GetToolBar() ? GetToolBar()->GetWindowStyle()
601 style
&= ~wxTB_HORIZONTAL
;
602 style
|= wxTB_VERTICAL
;
604 m_tbar
= new wxToolBar(this, wxID_ANY
,
605 wxDefaultPosition
, wxDefaultSize
,
608 m_tbar
->SetMargins(4, 4);
610 m_tbar
->AddRadioTool(IDM_TOOLBAR_OTHER_1
, _T("First"), wxBITMAP(new));
611 m_tbar
->AddRadioTool(IDM_TOOLBAR_OTHER_2
, _T("Second"), wxBITMAP(open
));
612 m_tbar
->AddRadioTool(IDM_TOOLBAR_OTHER_3
, _T("Third"), wxBITMAP(save
));
613 m_tbar
->AddSeparator();
614 m_tbar
->AddTool(wxID_HELP
, _T("Help"), wxBITMAP(help
));
622 void MyFrame::OnToggleToolbarSize(wxCommandEvent
& WXUNUSED(event
))
624 m_smallToolbar
= !m_smallToolbar
;
629 void MyFrame::OnToggleToolbarRows(wxCommandEvent
& WXUNUSED(event
))
631 // m_rows may be only 1 or 2
634 GetToolBar()->SetRows(m_horzToolbar
? m_rows
: 10 / m_rows
);
636 //RecreateToolbar(); -- this is unneeded
639 void MyFrame::OnToggleTooltips(wxCommandEvent
& WXUNUSED(event
))
641 m_showTooltips
= !m_showTooltips
;
646 void MyFrame::OnToggleCustomDisabled(wxCommandEvent
& WXUNUSED(event
))
648 m_useCustomDisabled
= !m_useCustomDisabled
;
653 void MyFrame::OnToggleToolbarOrient(wxCommandEvent
& WXUNUSED(event
))
655 m_horzToolbar
= !m_horzToolbar
;
660 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
665 void MyFrame::OnAbout(wxCommandEvent
& event
)
667 if ( event
.IsChecked() )
668 m_textWindow
->WriteText( _T("Help button down now.\n") );
670 m_textWindow
->WriteText( _T("Help button up now.\n") );
672 (void)wxMessageBox(_T("wxWidgets toolbar sample"), _T("About wxToolBar"));
675 void MyFrame::OnToolLeftClick(wxCommandEvent
& event
)
678 str
.Printf( _T("Clicked on tool %d\n"), event
.GetId());
679 m_textWindow
->WriteText( str
);
681 if (event
.GetId() == wxID_COPY
)
686 if (event
.GetId() == wxID_CUT
)
691 if (event
.GetId() == wxID_PRINT
)
697 void MyFrame::OnToolRightClick(wxCommandEvent
& event
)
699 m_textWindow
->AppendText(
700 wxString::Format(_T("Tool %d right clicked.\n"),
701 (int) event
.GetInt()));
704 void MyFrame::OnCombo(wxCommandEvent
& event
)
706 wxLogStatus(_T("Combobox string '%s' selected"), event
.GetString().c_str());
709 void MyFrame::DoEnablePrint()
714 wxToolBarBase
*tb
= GetToolBar();
715 tb
->EnableTool(wxID_PRINT
, !tb
->GetToolEnabled(wxID_PRINT
));
718 void MyFrame::DoDeletePrint()
723 wxToolBarBase
*tb
= GetToolBar();
724 tb
->DeleteTool( wxID_PRINT
);
729 void MyFrame::DoToggleHelp()
731 wxToolBarBase
*tb
= GetToolBar();
732 tb
->ToggleTool( wxID_HELP
, !tb
->GetToolState( wxID_HELP
) );
735 void MyFrame::OnUpdateCopyAndCut(wxUpdateUIEvent
& event
)
737 event
.Enable( m_textWindow
->CanCopy() );
740 void MyFrame::OnUpdateToggleHorzText(wxUpdateUIEvent
& event
)
742 wxToolBar
*tbar
= GetToolBar();
743 event
.Enable( tbar
&&
744 tbar
->HasFlag(wxTB_TEXT
) &&
745 !tbar
->HasFlag(wxTB_NOICONS
) );
748 void MyFrame::OnChangeToolTip(wxCommandEvent
& WXUNUSED(event
))
750 GetToolBar()->SetToolShortHelp(wxID_NEW
, _T("New toolbar button"));
753 void MyFrame::OnToolbarStyle(wxCommandEvent
& event
)
755 long style
= GetToolBar()->GetWindowStyle();
756 style
&= ~(wxTB_NOICONS
| wxTB_TEXT
);
758 switch ( event
.GetId() )
760 case IDM_TOOLBAR_SHOW_TEXT
:
761 style
|= wxTB_NOICONS
| wxTB_TEXT
;
764 case IDM_TOOLBAR_SHOW_ICONS
:
768 case IDM_TOOLBAR_SHOW_BOTH
:
772 GetToolBar()->SetWindowStyle(style
);
775 void MyFrame::OnToolbarCustomBitmap(wxCommandEvent
& WXUNUSED(event
))
777 m_pathBmp
= wxFileSelector(_T("Custom bitmap path"));
782 void MyFrame::OnInsertPrint(wxCommandEvent
& WXUNUSED(event
))
786 wxToolBarBase
*tb
= GetToolBar();
787 tb
->InsertTool(0, wxID_PRINT
, _T("New print"),
788 wxBITMAP(print
), wxNullBitmap
,
790 _T("Delete this tool"),
791 _T("This button was inserted into the toolbar"));
793 // must call Realize() after adding a new button
797 void MyFrame::OnToolEnter(wxCommandEvent
& event
)
800 if (event
.GetSelection() > -1)
803 str
.Printf(_T("This is tool number %d"), event
.GetSelection());
807 SetStatusText(wxEmptyString
);
810 #endif // wxUSE_STATUSBAR
813 void MyFrame::OnToggleRadioBtn(wxCommandEvent
& event
)
817 m_tbar
->ToggleTool(IDM_TOOLBAR_OTHER_1
+
818 event
.GetId() - IDM_TOOLBAR_TOGGLERADIOBTN1
, true);