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"
35 #include "wx/spinctrl.h"
36 #include "wx/srchctrl.h"
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
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
50 // ----------------------------------------------------------------------------
52 // ----------------------------------------------------------------------------
54 #if !defined(__WXMSW__) && !defined(__WXPM__)
55 #include "mondrian.xpm"
59 #include "bitmaps/new.xpm"
60 #include "bitmaps/open.xpm"
61 #include "bitmaps/save.xpm"
62 #include "bitmaps/copy.xpm"
63 #include "bitmaps/cut.xpm"
64 #include "bitmaps/preview.xpm" // paste XPM
65 #include "bitmaps/print.xpm"
66 #include "bitmaps/help.xpm"
67 #endif // USE_XPM_BITMAPS
77 // ----------------------------------------------------------------------------
79 // ----------------------------------------------------------------------------
81 // Define a new application
82 class MyApp
: public wxApp
89 class MyFrame
: public wxFrame
92 MyFrame(wxFrame
*parent
,
93 wxWindowID id
= wxID_ANY
,
94 const wxString
& title
= _T("wxToolBar Sample"),
95 const wxPoint
& pos
= wxDefaultPosition
,
96 const wxSize
& size
= wxDefaultSize
,
97 long style
= wxDEFAULT_FRAME_STYLE
|wxCLIP_CHILDREN
|wxNO_FULL_REPAINT_ON_RESIZE
);
99 void RecreateToolbar();
101 void OnQuit(wxCommandEvent
& event
);
102 void OnAbout(wxCommandEvent
& event
);
104 void OnSize(wxSizeEvent
& event
);
106 void OnToggleToolbar(wxCommandEvent
& event
);
107 void OnToggleAnotherToolbar(wxCommandEvent
& event
);
108 void OnToggleHorizontalText(wxCommandEvent
& WXUNUSED(event
));
110 void OnToggleToolbarSize(wxCommandEvent
& event
);
111 void OnChangeOrientation(wxCommandEvent
& event
);
112 void OnToggleToolbarRows(wxCommandEvent
& event
);
113 void OnToggleTooltips(wxCommandEvent
& event
);
114 void OnToggleCustomDisabled(wxCommandEvent
& event
);
116 void OnEnablePrint(wxCommandEvent
& WXUNUSED(event
)) { DoEnablePrint(); }
117 void OnDeletePrint(wxCommandEvent
& WXUNUSED(event
)) { DoDeletePrint(); }
118 void OnInsertPrint(wxCommandEvent
& event
);
119 void OnChangeToolTip(wxCommandEvent
& event
);
120 void OnToggleHelp(wxCommandEvent
& WXUNUSED(event
)) { DoToggleHelp(); }
121 void OnToggleRadioBtn(wxCommandEvent
& event
);
123 void OnToolbarStyle(wxCommandEvent
& event
);
124 void OnToolbarCustomBitmap(wxCommandEvent
& event
);
126 void OnToolLeftClick(wxCommandEvent
& event
);
127 void OnToolRightClick(wxCommandEvent
& event
);
128 void OnToolDropdown(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 void DoEnablePrint();
139 void DoDeletePrint();
142 void LayoutChildren();
148 size_t m_rows
; // 1 or 2 only
150 // the number of print buttons we have (they're added/removed dynamically)
153 // store toolbar position for future use
154 Positions m_toolbarPosition
;
156 wxTextCtrl
*m_textWindow
;
160 // the path to the custom bitmap for the test toolbar tool
163 DECLARE_EVENT_TABLE()
166 // ----------------------------------------------------------------------------
168 // ----------------------------------------------------------------------------
170 const int ID_TOOLBAR
= 500;
172 static const long TOOLBAR_STYLE
= wxTB_FLAT
| wxTB_DOCKABLE
| wxTB_TEXT
;
176 IDM_TOOLBAR_TOGGLETOOLBARSIZE
= 200,
177 IDM_TOOLBAR_TOGGLETOOLBARROWS
,
178 IDM_TOOLBAR_TOGGLETOOLTIPS
,
179 IDM_TOOLBAR_TOGGLECUSTOMDISABLED
,
180 IDM_TOOLBAR_ENABLEPRINT
,
181 IDM_TOOLBAR_DELETEPRINT
,
182 IDM_TOOLBAR_INSERTPRINT
,
183 IDM_TOOLBAR_TOGGLEHELP
,
184 IDM_TOOLBAR_TOGGLERADIOBTN1
,
185 IDM_TOOLBAR_TOGGLERADIOBTN2
,
186 IDM_TOOLBAR_TOGGLERADIOBTN3
,
187 IDM_TOOLBAR_TOGGLE_TOOLBAR
,
188 IDM_TOOLBAR_TOGGLE_HORIZONTAL_TEXT
,
189 IDM_TOOLBAR_TOGGLE_ANOTHER_TOOLBAR
,
190 IDM_TOOLBAR_CHANGE_TOOLTIP
,
191 IDM_TOOLBAR_SHOW_TEXT
,
192 IDM_TOOLBAR_SHOW_ICONS
,
193 IDM_TOOLBAR_SHOW_BOTH
,
194 IDM_TOOLBAR_CUSTOM_PATH
,
195 IDM_TOOLBAR_TOP_ORIENTATION
,
196 IDM_TOOLBAR_LEFT_ORIENTATION
,
197 IDM_TOOLBAR_BOTTOM_ORIENTATION
,
198 IDM_TOOLBAR_RIGHT_ORIENTATION
,
207 // ----------------------------------------------------------------------------
209 // ----------------------------------------------------------------------------
211 // Notice that wxID_HELP will be processed for the 'About' menu and the toolbar
214 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
215 EVT_SIZE(MyFrame
::OnSize
)
217 EVT_MENU(wxID_EXIT
, MyFrame
::OnQuit
)
218 EVT_MENU(wxID_HELP
, MyFrame
::OnAbout
)
220 EVT_MENU(IDM_TOOLBAR_TOGGLE_TOOLBAR
, MyFrame
::OnToggleToolbar
)
221 EVT_MENU(IDM_TOOLBAR_TOGGLE_ANOTHER_TOOLBAR
, MyFrame
::OnToggleAnotherToolbar
)
222 EVT_MENU(IDM_TOOLBAR_TOGGLE_HORIZONTAL_TEXT
, MyFrame
::OnToggleHorizontalText
)
224 EVT_MENU_RANGE(IDM_TOOLBAR_TOP_ORIENTATION
, IDM_TOOLBAR_RIGHT_ORIENTATION
, MyFrame
::OnChangeOrientation
)
225 EVT_MENU(IDM_TOOLBAR_TOGGLETOOLBARSIZE
, MyFrame
::OnToggleToolbarSize
)
226 EVT_MENU(IDM_TOOLBAR_TOGGLETOOLBARROWS
, MyFrame
::OnToggleToolbarRows
)
227 EVT_MENU(IDM_TOOLBAR_TOGGLETOOLTIPS
, MyFrame
::OnToggleTooltips
)
228 EVT_MENU(IDM_TOOLBAR_TOGGLECUSTOMDISABLED
, MyFrame
::OnToggleCustomDisabled
)
230 EVT_MENU(IDM_TOOLBAR_ENABLEPRINT
, MyFrame
::OnEnablePrint
)
231 EVT_MENU(IDM_TOOLBAR_DELETEPRINT
, MyFrame
::OnDeletePrint
)
232 EVT_MENU(IDM_TOOLBAR_INSERTPRINT
, MyFrame
::OnInsertPrint
)
233 EVT_MENU(IDM_TOOLBAR_TOGGLEHELP
, MyFrame
::OnToggleHelp
)
234 EVT_MENU_RANGE(IDM_TOOLBAR_TOGGLERADIOBTN1
, IDM_TOOLBAR_TOGGLERADIOBTN3
,
235 MyFrame
::OnToggleRadioBtn
)
236 EVT_MENU(IDM_TOOLBAR_CHANGE_TOOLTIP
, MyFrame
::OnChangeToolTip
)
238 EVT_MENU_RANGE(IDM_TOOLBAR_SHOW_TEXT
, IDM_TOOLBAR_SHOW_BOTH
,
239 MyFrame
::OnToolbarStyle
)
241 EVT_MENU(IDM_TOOLBAR_CUSTOM_PATH
, MyFrame
::OnToolbarCustomBitmap
)
243 EVT_MENU(wxID_ANY
, MyFrame
::OnToolLeftClick
)
245 EVT_COMBOBOX(ID_COMBO
, MyFrame
::OnCombo
)
247 EVT_TOOL_RCLICKED(wxID_ANY
, MyFrame
::OnToolRightClick
)
249 EVT_TOOL_DROPDOWN(wxID_ANY
, MyFrame
::OnToolDropdown
)
251 EVT_UPDATE_UI(wxID_COPY
, MyFrame
::OnUpdateCopyAndCut
)
252 EVT_UPDATE_UI(wxID_CUT
, MyFrame
::OnUpdateCopyAndCut
)
254 EVT_UPDATE_UI_RANGE(IDM_TOOLBAR_TOGGLERADIOBTN1
,
255 IDM_TOOLBAR_TOGGLERADIOBTN3
,
256 MyFrame
::OnUpdateToggleRadioBtn
)
257 EVT_UPDATE_UI(IDM_TOOLBAR_TOGGLE_HORIZONTAL_TEXT
,
258 MyFrame
::OnUpdateToggleHorzText
)
261 // ============================================================================
263 // ============================================================================
265 // ----------------------------------------------------------------------------
267 // ----------------------------------------------------------------------------
271 // The `main program' equivalent, creating the windows and returning the
275 if ( !wxApp
::OnInit() )
278 // Create the main frame window
279 MyFrame
* frame
= new MyFrame((wxFrame
*) NULL
, wxID_ANY
,
280 _T("wxToolBar Sample"),
281 wxPoint(100, 100), wxSize(550, 300));
286 frame
->SetStatusText(_T("Hello, wxWidgets"));
289 wxInitAllImageHandlers();
296 void MyFrame
::RecreateToolbar()
299 // On Windows CE, we should not delete the
300 // previous toolbar in case it contains the menubar.
301 // We'll try to accommodate this usage in due course.
302 wxToolBar
* toolBar
= CreateToolBar();
304 // delete and recreate the toolbar
305 wxToolBarBase
*toolBar
= GetToolBar();
306 long style
= toolBar ? toolBar
->GetWindowStyle() : TOOLBAR_STYLE
;
312 style
&= ~(wxTB_HORIZONTAL
| wxTB_VERTICAL
| wxTB_BOTTOM
| wxTB_RIGHT
| wxTB_HORZ_LAYOUT
);
313 switch( m_toolbarPosition
)
325 style
|= wxTB_BOTTOM
;
329 if ( m_showTooltips
)
330 style
&= ~wxTB_NO_TOOLTIPS
;
332 style
|= wxTB_NO_TOOLTIPS
;
334 if ( style
& wxTB_TEXT
&& !(style
& wxTB_NOICONS
) && m_horzText
)
335 style
|= wxTB_HORZ_LAYOUT
;
337 toolBar
= CreateToolBar(style
, ID_TOOLBAR
);
354 wxBitmap toolBarBitmaps
[Tool_Max
];
357 #define INIT_TOOL_BMP(bmp) \
358 toolBarBitmaps[Tool_##bmp] = wxBitmap(bmp##_xpm)
359 #else // !USE_XPM_BITMAPS
360 #define INIT_TOOL_BMP(bmp) \
361 toolBarBitmaps[Tool_##bmp] = wxBITMAP(bmp)
362 #endif // USE_XPM_BITMAPS/!USE_XPM_BITMAPS
369 INIT_TOOL_BMP(paste
);
370 INIT_TOOL_BMP(print
);
373 int w
= toolBarBitmaps
[Tool_new
].GetWidth(),
374 h
= toolBarBitmaps
[Tool_new
].GetHeight();
376 if ( !m_smallToolbar
)
381 for ( size_t n
= Tool_new
; n
< WXSIZEOF(toolBarBitmaps
); n
++ )
384 wxBitmap(toolBarBitmaps
[n
].ConvertToImage().Scale(w
, h
));
388 toolBar
->SetToolBitmapSize(wxSize(w
, h
));
390 toolBar
->AddTool(wxID_NEW
, _T("New"),
391 toolBarBitmaps
[Tool_new
], wxNullBitmap
, wxITEM_DROPDOWN
,
392 _T("New file"), _T("This is help for new file tool"));
394 wxMenu
* menu
= new wxMenu
;
395 menu
->Append(wxID_ANY
, _T("&First dummy item"));
396 menu
->Append(wxID_ANY
, _T("&Second dummy item"));
397 menu
->AppendSeparator();
398 menu
->Append(wxID_EXIT
, _T("Exit"));
399 toolBar
->SetDropdownMenu(wxID_NEW
, menu
);
401 toolBar
->AddTool(wxID_OPEN
, _T("Open"),
402 toolBarBitmaps
[Tool_open
], wxNullBitmap
, wxITEM_NORMAL
,
403 _T("Open file"), _T("This is help for open file tool"));
405 // the generic toolbar doesn't really support this
406 #if wxUSE_TOOLBAR_NATIVE && !defined(__WXX11__) || defined(__WXUNIVERSAL__)
407 // adding a combo to a vertical toolbar is not very smart
408 if ( !( toolBar
->IsVertical() ) )
410 wxComboBox
*combo
= new wxComboBox(toolBar
, ID_COMBO
, wxEmptyString
, wxDefaultPosition
, wxSize(100,-1) );
411 combo
->Append(_T("This"));
412 combo
->Append(_T("is a"));
413 combo
->Append(_T("combobox"));
414 combo
->Append(_T("in a"));
415 combo
->Append(_T("toolbar"));
416 toolBar
->AddControl(combo
, _T("Combo Label"));
418 wxSpinCtrl
*spin
= new wxSpinCtrl( toolBar
, ID_SPIN
, wxT("0"), wxDefaultPosition
, wxSize(80,wxDefaultCoord
), 0, 0, 100 );
419 toolBar
->AddControl( spin
);
421 wxTextCtrl
*text
= new wxTextCtrl( toolBar
, -1, wxT("text"), wxDefaultPosition
, wxSize(80,wxDefaultCoord
) );
422 toolBar
->AddControl( text
);
424 wxSearchCtrl
*srch
= new wxSearchCtrl( toolBar
, -1, wxT("xx"), wxDefaultPosition
, wxSize(80,wxDefaultCoord
), wxSUNKEN_BORDER
);
425 toolBar
->AddControl( srch
);
427 #endif // toolbars which don't support controls
429 toolBar
->AddTool(wxID_SAVE
, _T("Save"), toolBarBitmaps
[Tool_save
], _T("Toggle button 1"), wxITEM_CHECK
);
430 toolBar
->AddTool(wxID_COPY
, _T("Copy"), toolBarBitmaps
[Tool_copy
], _T("Toggle button 2"), wxITEM_CHECK
);
431 toolBar
->AddTool(wxID_CUT
, _T("Cut"), toolBarBitmaps
[Tool_cut
], _T("Toggle/Untoggle help button"));
432 toolBar
->AddTool(wxID_PASTE
, _T("Paste"), toolBarBitmaps
[Tool_paste
], _T("Paste"));
434 if ( m_useCustomDisabled
)
436 wxBitmap
bmpDisabled(w
, h
);
439 dc
.SelectObject(bmpDisabled
);
440 dc
.DrawBitmap(toolBarBitmaps
[Tool_print
], 0, 0);
442 wxPen
pen(*wxRED
, 5);
444 dc
.DrawLine(0, 0, w
, h
);
447 toolBar
->AddTool(wxID_PRINT
, _T("Print"), toolBarBitmaps
[Tool_print
],
452 toolBar
->AddTool(wxID_PRINT
, _T("Print"), toolBarBitmaps
[Tool_print
],
453 _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."));
456 toolBar
->AddSeparator();
457 toolBar
->AddTool(wxID_HELP
, _T("Help"), toolBarBitmaps
[Tool_help
], _T("Help button"), wxITEM_CHECK
);
459 if ( !m_pathBmp
.empty() )
461 // create a tool with a custom bitmap for testing
462 wxImage
img(m_pathBmp
);
465 if ( img
.GetWidth() > w
&& img
.GetHeight() > h
)
466 img
= img
.GetSubImage(wxRect(0, 0, w
, h
));
468 toolBar
->AddSeparator();
469 toolBar
->AddTool(wxID_ANY
, _T("Custom"), img
);
473 // after adding the buttons to the toolbar, must call Realize() to reflect
477 toolBar
->SetRows(!(toolBar
->IsVertical()) ? m_rows
: 10 / m_rows
);
480 // ----------------------------------------------------------------------------
482 // ----------------------------------------------------------------------------
484 // Define my frame constructor
485 MyFrame
::MyFrame(wxFrame
* parent
,
487 const wxString
& title
,
491 : wxFrame(parent
, id
, title
, pos
, size
, style
)
495 m_smallToolbar
= true;
497 m_useCustomDisabled
= false;
498 m_showTooltips
= true;
504 // Give it a status line
509 SetIcon(wxICON(mondrian
));
512 wxMenu
*tbarMenu
= new wxMenu
;
513 tbarMenu
->AppendCheckItem(IDM_TOOLBAR_TOGGLE_TOOLBAR
,
514 _T("Toggle &toolbar\tCtrl-Z"),
515 _T("Show or hide the toolbar"));
517 tbarMenu
->AppendCheckItem(IDM_TOOLBAR_TOGGLE_ANOTHER_TOOLBAR
,
518 _T("Toggle &another toolbar\tCtrl-A"),
519 _T("Show/hide another test toolbar"));
521 tbarMenu
->AppendCheckItem(IDM_TOOLBAR_TOGGLE_HORIZONTAL_TEXT
,
522 _T("Toggle hori&zontal text\tCtrl-H"),
523 _T("Show text under/alongside the icon"));
525 tbarMenu
->AppendCheckItem(IDM_TOOLBAR_TOGGLETOOLBARSIZE
,
526 _T("&Toggle toolbar size\tCtrl-S"),
527 _T("Toggle between big/small toolbar"));
529 tbarMenu
->AppendCheckItem(IDM_TOOLBAR_TOGGLETOOLBARROWS
,
530 _T("Toggle number of &rows\tCtrl-R"),
531 _T("Toggle number of toolbar rows between 1 and 2"));
533 tbarMenu
->AppendCheckItem(IDM_TOOLBAR_TOGGLETOOLTIPS
,
534 _T("Show &tooltips\tCtrl-L"),
535 _T("Show tooltips for the toolbar tools"));
537 tbarMenu
->AppendCheckItem(IDM_TOOLBAR_TOGGLECUSTOMDISABLED
,
538 _T("Use c&ustom disabled images\tCtrl-U"),
539 _T("Switch between using system-generated and custom disabled images"));
542 tbarMenu
->AppendSeparator();
543 tbarMenu
->AppendRadioItem(IDM_TOOLBAR_TOP_ORIENTATION
,
544 _T("Set toolbar at the top of the window"),
545 _T("Set toolbar at the top of the window"));
546 tbarMenu
->AppendRadioItem(IDM_TOOLBAR_LEFT_ORIENTATION
,
547 _T("Set toolbar at the left of the window"),
548 _T("Set toolbar at the left of the window"));
549 tbarMenu
->AppendRadioItem(IDM_TOOLBAR_BOTTOM_ORIENTATION
,
550 _T("Set toolbar at the bottom of the window"),
551 _T("Set toolbar at the bottom of the window"));
552 tbarMenu
->AppendRadioItem(IDM_TOOLBAR_RIGHT_ORIENTATION
,
553 _T("Set toolbar at the right edge of the window"),
554 _T("Set toolbar at the right edge of the window"));
555 tbarMenu
->AppendSeparator();
557 tbarMenu
->Append(IDM_TOOLBAR_ENABLEPRINT
, _T("&Enable print button\tCtrl-E"));
558 tbarMenu
->Append(IDM_TOOLBAR_DELETEPRINT
, _T("&Delete print button\tCtrl-D"));
559 tbarMenu
->Append(IDM_TOOLBAR_INSERTPRINT
, _T("&Insert print button\tCtrl-I"));
560 tbarMenu
->Append(IDM_TOOLBAR_TOGGLEHELP
, _T("Toggle &help button\tCtrl-T"));
561 tbarMenu
->AppendSeparator();
562 tbarMenu
->Append(IDM_TOOLBAR_TOGGLERADIOBTN1
, _T("Toggle &1st radio button\tCtrl-1"));
563 tbarMenu
->Append(IDM_TOOLBAR_TOGGLERADIOBTN2
, _T("Toggle &2nd radio button\tCtrl-2"));
564 tbarMenu
->Append(IDM_TOOLBAR_TOGGLERADIOBTN3
, _T("Toggle &3rd radio button\tCtrl-3"));
565 tbarMenu
->AppendSeparator();
566 tbarMenu
->Append(IDM_TOOLBAR_CHANGE_TOOLTIP
, _T("Change tool tip"));
567 tbarMenu
->AppendSeparator();
568 tbarMenu
->AppendRadioItem(IDM_TOOLBAR_SHOW_TEXT
, _T("Show &text\tCtrl-Alt-T"));
569 tbarMenu
->AppendRadioItem(IDM_TOOLBAR_SHOW_ICONS
, _T("Show &icons\tCtrl-Alt-I"));
570 tbarMenu
->AppendRadioItem(IDM_TOOLBAR_SHOW_BOTH
, _T("Show &both\tCtrl-Alt-B"));
571 tbarMenu
->AppendSeparator();
572 tbarMenu
->Append(IDM_TOOLBAR_CUSTOM_PATH
, _T("Custom &bitmap...\tCtrl-B"));
574 wxMenu
*fileMenu
= new wxMenu
;
575 fileMenu
->Append(wxID_EXIT
, _T("E&xit\tAlt-X"), _T("Quit toolbar sample") );
577 wxMenu
*helpMenu
= new wxMenu
;
578 helpMenu
->Append(wxID_HELP
, _T("&About"), _T("About toolbar sample"));
580 wxMenuBar
* menuBar
= new wxMenuBar( wxMB_DOCKABLE
);
582 menuBar
->Append(fileMenu
, _T("&File"));
583 menuBar
->Append(tbarMenu
, _T("&Toolbar"));
584 menuBar
->Append(helpMenu
, _T("&Help"));
586 // Associate the menu bar with the frame
589 menuBar
->Check(IDM_TOOLBAR_SHOW_BOTH
, true);
590 menuBar
->Check(IDM_TOOLBAR_TOGGLETOOLTIPS
, true);
592 menuBar
->Check(IDM_TOOLBAR_TOP_ORIENTATION
, true );
593 m_toolbarPosition
= TOOLBAR_TOP
;
594 // Create the toolbar
597 m_textWindow
= new wxTextCtrl(this, wxID_ANY
, wxEmptyString
, wxDefaultPosition
, wxDefaultSize
, wxTE_MULTILINE
);
600 void MyFrame
::LayoutChildren()
602 wxSize size
= GetClientSize();
607 m_tbar
->SetSize(0, 0, wxDefaultCoord
, size
.y
);
609 offset
= m_tbar
->GetSize().x
;
616 m_textWindow
->SetSize(offset
, 0, size
.x
- offset
, size
.y
);
619 void MyFrame
::OnSize(wxSizeEvent
& event
)
631 void MyFrame
::OnToggleToolbar(wxCommandEvent
& WXUNUSED(event
))
633 wxToolBar
*tbar
= GetToolBar();
647 void MyFrame
::OnToggleHorizontalText(wxCommandEvent
& WXUNUSED(event
))
649 m_horzText
= !m_horzText
;
654 void MyFrame
::OnToggleAnotherToolbar(wxCommandEvent
& WXUNUSED(event
))
663 long style
= GetToolBar() ?
GetToolBar()->GetWindowStyle()
665 style
&= ~wxTB_HORIZONTAL
;
666 style
|= wxTB_VERTICAL
;
668 m_tbar
= new wxToolBar(this, wxID_ANY
,
669 wxDefaultPosition
, wxDefaultSize
,
672 m_tbar
->SetMargins(4, 4);
674 m_tbar
->AddRadioTool(IDM_TOOLBAR_OTHER_1
, _T("First"), wxBITMAP(new));
675 m_tbar
->AddRadioTool(IDM_TOOLBAR_OTHER_2
, _T("Second"), wxBITMAP(open
));
676 m_tbar
->AddRadioTool(IDM_TOOLBAR_OTHER_3
, _T("Third"), wxBITMAP(save
));
677 m_tbar
->AddSeparator();
678 m_tbar
->AddTool(wxID_HELP
, _T("Help"), wxBITMAP(help
));
686 void MyFrame
::OnToggleToolbarSize(wxCommandEvent
& WXUNUSED(event
))
688 m_smallToolbar
= !m_smallToolbar
;
693 void MyFrame
::OnToggleToolbarRows(wxCommandEvent
& WXUNUSED(event
))
695 // m_rows may be only 1 or 2
698 GetToolBar()->SetRows(!(GetToolBar()->IsVertical()) ? m_rows
: 10 / m_rows
);
700 //RecreateToolbar(); -- this is unneeded
703 void MyFrame
::OnToggleTooltips(wxCommandEvent
& WXUNUSED(event
))
705 m_showTooltips
= !m_showTooltips
;
710 void MyFrame
::OnToggleCustomDisabled(wxCommandEvent
& WXUNUSED(event
))
712 m_useCustomDisabled
= !m_useCustomDisabled
;
717 void MyFrame
::OnChangeOrientation(wxCommandEvent
& event
)
719 switch( event
.GetId() )
721 case IDM_TOOLBAR_LEFT_ORIENTATION
:
722 m_toolbarPosition
= TOOLBAR_LEFT
;
724 case IDM_TOOLBAR_TOP_ORIENTATION
:
725 m_toolbarPosition
= TOOLBAR_TOP
;
727 case IDM_TOOLBAR_RIGHT_ORIENTATION
:
728 m_toolbarPosition
= TOOLBAR_RIGHT
;
730 case IDM_TOOLBAR_BOTTOM_ORIENTATION
:
731 m_toolbarPosition
= TOOLBAR_BOTTOM
;
737 void MyFrame
::OnQuit(wxCommandEvent
& WXUNUSED(event
))
742 void MyFrame
::OnAbout(wxCommandEvent
& event
)
744 if ( event
.IsChecked() )
745 m_textWindow
->WriteText( _T("Help button down now.\n") );
747 m_textWindow
->WriteText( _T("Help button up now.\n") );
749 (void)wxMessageBox(_T("wxWidgets toolbar sample"), _T("About wxToolBar"));
752 void MyFrame
::OnToolLeftClick(wxCommandEvent
& event
)
755 str
.Printf( _T("Clicked on tool %d\n"), event
.GetId());
756 m_textWindow
->WriteText( str
);
758 if (event
.GetId() == wxID_COPY
)
763 if (event
.GetId() == wxID_CUT
)
768 if (event
.GetId() == wxID_PRINT
)
774 void MyFrame
::OnToolRightClick(wxCommandEvent
& event
)
776 m_textWindow
->AppendText(
777 wxString
::Format(_T("Tool %d right clicked.\n"),
778 (int) event
.GetInt()));
781 void MyFrame
::OnCombo(wxCommandEvent
& event
)
783 wxLogStatus(_T("Combobox string '%s' selected"), event
.GetString().c_str());
786 void MyFrame
::DoEnablePrint()
791 wxToolBarBase
*tb
= GetToolBar();
792 tb
->EnableTool(wxID_PRINT
, !tb
->GetToolEnabled(wxID_PRINT
));
795 void MyFrame
::DoDeletePrint()
800 wxToolBarBase
*tb
= GetToolBar();
801 tb
->DeleteTool( wxID_PRINT
);
806 void MyFrame
::DoToggleHelp()
808 wxToolBarBase
*tb
= GetToolBar();
809 tb
->ToggleTool( wxID_HELP
, !tb
->GetToolState( wxID_HELP
) );
812 void MyFrame
::OnUpdateCopyAndCut(wxUpdateUIEvent
& event
)
814 event
.Enable( m_textWindow
->CanCopy() );
817 void MyFrame
::OnUpdateToggleHorzText(wxUpdateUIEvent
& event
)
819 wxToolBar
*tbar
= GetToolBar();
820 event
.Enable( tbar
&&
821 tbar
->HasFlag(wxTB_TEXT
) &&
822 !tbar
->HasFlag(wxTB_NOICONS
) );
825 void MyFrame
::OnChangeToolTip(wxCommandEvent
& WXUNUSED(event
))
827 GetToolBar()->SetToolShortHelp(wxID_NEW
, _T("New toolbar button"));
830 void MyFrame
::OnToolbarStyle(wxCommandEvent
& event
)
832 long style
= GetToolBar()->GetWindowStyle();
833 style
&= ~(wxTB_NOICONS
| wxTB_TEXT
);
835 switch ( event
.GetId() )
837 case IDM_TOOLBAR_SHOW_TEXT
:
838 style
|= wxTB_NOICONS
| wxTB_TEXT
;
841 case IDM_TOOLBAR_SHOW_ICONS
:
845 case IDM_TOOLBAR_SHOW_BOTH
:
849 GetToolBar()->SetWindowStyle(style
);
852 void MyFrame
::OnToolbarCustomBitmap(wxCommandEvent
& WXUNUSED(event
))
854 m_pathBmp
= wxFileSelector(_T("Custom bitmap path"));
859 void MyFrame
::OnInsertPrint(wxCommandEvent
& WXUNUSED(event
))
863 wxToolBarBase
*tb
= GetToolBar();
864 tb
->InsertTool(0, wxID_PRINT
, _T("New print"),
865 wxBITMAP(print
), wxNullBitmap
,
867 _T("Delete this tool"),
868 _T("This button was inserted into the toolbar"));
870 // must call Realize() after adding a new button
874 void MyFrame
::OnToggleRadioBtn(wxCommandEvent
& event
)
878 m_tbar
->ToggleTool(IDM_TOOLBAR_OTHER_1
+
879 event
.GetId() - IDM_TOOLBAR_TOGGLERADIOBTN1
, true);
883 void MyFrame
::OnToolDropdown(wxCommandEvent
& event
)
886 str
.Printf( _T("Dropdown on tool %d\n"), event
.GetId());
887 m_textWindow
->WriteText( str
);