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 // 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
56 // ----------------------------------------------------------------------------
58 // ----------------------------------------------------------------------------
60 #if !defined(__WXMSW__) && !defined(__WXPM__)
61 #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
83 // ----------------------------------------------------------------------------
85 // ----------------------------------------------------------------------------
87 // Define a new application
88 class MyApp
: public wxApp
95 class MyFrame
: public wxFrame
98 MyFrame(wxFrame
*parent
,
99 wxWindowID id
= wxID_ANY
,
100 const wxString
& title
= _T("wxToolBar Sample"),
101 const wxPoint
& pos
= wxDefaultPosition
,
102 const wxSize
& size
= wxDefaultSize
,
103 long style
= wxDEFAULT_FRAME_STYLE
|wxCLIP_CHILDREN
|wxNO_FULL_REPAINT_ON_RESIZE
);
105 void PopulateToolbar(wxToolBarBase
* toolBar
);
106 void RecreateToolbar();
108 void OnQuit(wxCommandEvent
& event
);
109 void OnAbout(wxCommandEvent
& event
);
111 void OnSize(wxSizeEvent
& event
);
113 void OnToggleToolbar(wxCommandEvent
& event
);
114 void OnToggleAnotherToolbar(wxCommandEvent
& event
);
115 void OnToggleHorizontalText(wxCommandEvent
& WXUNUSED(event
));
117 void OnToggleToolbarSize(wxCommandEvent
& event
);
118 void OnChangeOrientation(wxCommandEvent
& event
);
119 void OnToggleToolbarRows(wxCommandEvent
& event
);
120 void OnToggleTooltips(wxCommandEvent
& event
);
121 void OnToggleCustomDisabled(wxCommandEvent
& event
);
123 void OnEnablePrint(wxCommandEvent
& WXUNUSED(event
)) { DoEnablePrint(); }
124 void OnDeletePrint(wxCommandEvent
& WXUNUSED(event
)) { DoDeletePrint(); }
125 void OnInsertPrint(wxCommandEvent
& event
);
126 void OnChangeToolTip(wxCommandEvent
& event
);
127 void OnToggleHelp(wxCommandEvent
& WXUNUSED(event
)) { DoToggleHelp(); }
128 void OnToggleRadioBtn(wxCommandEvent
& event
);
130 void OnToolbarStyle(wxCommandEvent
& event
);
131 void OnToolbarCustomBitmap(wxCommandEvent
& event
);
133 void OnToolLeftClick(wxCommandEvent
& event
);
134 void OnToolRightClick(wxCommandEvent
& event
);
135 void OnToolDropdown(wxCommandEvent
& event
);
137 void OnCombo(wxCommandEvent
& event
);
139 void OnUpdateCopyAndCut(wxUpdateUIEvent
& event
);
140 void OnUpdateToggleHorzText(wxUpdateUIEvent
& event
);
141 void OnUpdateToggleRadioBtn(wxUpdateUIEvent
& event
)
142 { event
.Enable( m_tbar
!= NULL
); }
145 void DoEnablePrint();
146 void DoDeletePrint();
149 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 // store toolbar position for future use
161 Positions m_toolbarPosition
;
163 wxTextCtrl
*m_textWindow
;
166 wxToolBar
*m_extraToolBar
;
170 // the path to the custom bitmap for the test toolbar tool
173 DECLARE_EVENT_TABLE()
176 // ----------------------------------------------------------------------------
178 // ----------------------------------------------------------------------------
180 const int ID_TOOLBAR
= 500;
182 static const long TOOLBAR_STYLE
= wxTB_FLAT
| wxTB_DOCKABLE
| wxTB_TEXT
;
186 IDM_TOOLBAR_TOGGLETOOLBARSIZE
= 200,
187 IDM_TOOLBAR_TOGGLETOOLBARROWS
,
188 IDM_TOOLBAR_TOGGLETOOLTIPS
,
189 IDM_TOOLBAR_TOGGLECUSTOMDISABLED
,
190 IDM_TOOLBAR_ENABLEPRINT
,
191 IDM_TOOLBAR_DELETEPRINT
,
192 IDM_TOOLBAR_INSERTPRINT
,
193 IDM_TOOLBAR_TOGGLEHELP
,
194 IDM_TOOLBAR_TOGGLERADIOBTN1
,
195 IDM_TOOLBAR_TOGGLERADIOBTN2
,
196 IDM_TOOLBAR_TOGGLERADIOBTN3
,
197 IDM_TOOLBAR_TOGGLE_TOOLBAR
,
198 IDM_TOOLBAR_TOGGLE_HORIZONTAL_TEXT
,
199 IDM_TOOLBAR_TOGGLE_ANOTHER_TOOLBAR
,
200 IDM_TOOLBAR_CHANGE_TOOLTIP
,
201 IDM_TOOLBAR_SHOW_TEXT
,
202 IDM_TOOLBAR_SHOW_ICONS
,
203 IDM_TOOLBAR_SHOW_BOTH
,
204 IDM_TOOLBAR_CUSTOM_PATH
,
205 IDM_TOOLBAR_TOP_ORIENTATION
,
206 IDM_TOOLBAR_LEFT_ORIENTATION
,
207 IDM_TOOLBAR_BOTTOM_ORIENTATION
,
208 IDM_TOOLBAR_RIGHT_ORIENTATION
,
217 // ----------------------------------------------------------------------------
219 // ----------------------------------------------------------------------------
221 // Notice that wxID_HELP will be processed for the 'About' menu and the toolbar
224 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
225 EVT_SIZE(MyFrame::OnSize
)
227 EVT_MENU(wxID_EXIT
, MyFrame::OnQuit
)
228 EVT_MENU(wxID_HELP
, MyFrame::OnAbout
)
230 EVT_MENU(IDM_TOOLBAR_TOGGLE_TOOLBAR
, MyFrame::OnToggleToolbar
)
231 EVT_MENU(IDM_TOOLBAR_TOGGLE_ANOTHER_TOOLBAR
, MyFrame::OnToggleAnotherToolbar
)
232 EVT_MENU(IDM_TOOLBAR_TOGGLE_HORIZONTAL_TEXT
, MyFrame::OnToggleHorizontalText
)
234 EVT_MENU_RANGE(IDM_TOOLBAR_TOP_ORIENTATION
, IDM_TOOLBAR_RIGHT_ORIENTATION
, MyFrame::OnChangeOrientation
)
235 EVT_MENU(IDM_TOOLBAR_TOGGLETOOLBARSIZE
, MyFrame::OnToggleToolbarSize
)
236 EVT_MENU(IDM_TOOLBAR_TOGGLETOOLBARROWS
, MyFrame::OnToggleToolbarRows
)
237 EVT_MENU(IDM_TOOLBAR_TOGGLETOOLTIPS
, MyFrame::OnToggleTooltips
)
238 EVT_MENU(IDM_TOOLBAR_TOGGLECUSTOMDISABLED
, MyFrame::OnToggleCustomDisabled
)
240 EVT_MENU(IDM_TOOLBAR_ENABLEPRINT
, MyFrame::OnEnablePrint
)
241 EVT_MENU(IDM_TOOLBAR_DELETEPRINT
, MyFrame::OnDeletePrint
)
242 EVT_MENU(IDM_TOOLBAR_INSERTPRINT
, MyFrame::OnInsertPrint
)
243 EVT_MENU(IDM_TOOLBAR_TOGGLEHELP
, MyFrame::OnToggleHelp
)
244 EVT_MENU_RANGE(IDM_TOOLBAR_TOGGLERADIOBTN1
, IDM_TOOLBAR_TOGGLERADIOBTN3
,
245 MyFrame::OnToggleRadioBtn
)
246 EVT_MENU(IDM_TOOLBAR_CHANGE_TOOLTIP
, MyFrame::OnChangeToolTip
)
248 EVT_MENU_RANGE(IDM_TOOLBAR_SHOW_TEXT
, IDM_TOOLBAR_SHOW_BOTH
,
249 MyFrame::OnToolbarStyle
)
251 EVT_MENU(IDM_TOOLBAR_CUSTOM_PATH
, MyFrame::OnToolbarCustomBitmap
)
253 EVT_MENU(wxID_ANY
, MyFrame::OnToolLeftClick
)
255 EVT_COMBOBOX(ID_COMBO
, MyFrame::OnCombo
)
257 EVT_TOOL_RCLICKED(wxID_ANY
, MyFrame::OnToolRightClick
)
259 EVT_TOOL_DROPDOWN(wxID_ANY
, MyFrame::OnToolDropdown
)
261 EVT_UPDATE_UI(wxID_COPY
, MyFrame::OnUpdateCopyAndCut
)
262 EVT_UPDATE_UI(wxID_CUT
, MyFrame::OnUpdateCopyAndCut
)
264 EVT_UPDATE_UI_RANGE(IDM_TOOLBAR_TOGGLERADIOBTN1
,
265 IDM_TOOLBAR_TOGGLERADIOBTN3
,
266 MyFrame::OnUpdateToggleRadioBtn
)
267 EVT_UPDATE_UI(IDM_TOOLBAR_TOGGLE_HORIZONTAL_TEXT
,
268 MyFrame::OnUpdateToggleHorzText
)
271 // ============================================================================
273 // ============================================================================
275 // ----------------------------------------------------------------------------
277 // ----------------------------------------------------------------------------
281 // The `main program' equivalent, creating the windows and returning the
285 if ( !wxApp::OnInit() )
288 // Create the main frame window
289 MyFrame
* frame
= new MyFrame((wxFrame
*) NULL
, wxID_ANY
,
290 _T("wxToolBar Sample"),
291 wxPoint(100, 100), wxSize(550, 300));
296 frame
->SetStatusText(_T("Hello, wxWidgets"));
299 wxInitAllImageHandlers();
306 void MyFrame::RecreateToolbar()
309 // On Windows CE, we should not delete the
310 // previous toolbar in case it contains the menubar.
311 // We'll try to accommodate this usage in due course.
312 wxToolBar
* toolBar
= CreateToolBar();
314 // delete and recreate the toolbar
315 wxToolBarBase
*toolBar
= GetToolBar();
316 long style
= toolBar
? toolBar
->GetWindowStyle() : TOOLBAR_STYLE
;
322 style
&= ~(wxTB_HORIZONTAL
| wxTB_VERTICAL
| wxTB_BOTTOM
| wxTB_RIGHT
| wxTB_HORZ_LAYOUT
);
323 switch( m_toolbarPosition
)
335 style
|= wxTB_BOTTOM
;
339 if ( m_showTooltips
)
340 style
&= ~wxTB_NO_TOOLTIPS
;
342 style
|= wxTB_NO_TOOLTIPS
;
344 if ( style
& wxTB_TEXT
&& !(style
& wxTB_NOICONS
) && m_horzText
)
345 style
|= wxTB_HORZ_LAYOUT
;
347 toolBar
= CreateToolBar(style
, ID_TOOLBAR
);
350 PopulateToolbar(toolBar
);
353 void MyFrame::PopulateToolbar(wxToolBarBase
* toolBar
)
369 wxBitmap toolBarBitmaps
[Tool_Max
];
372 #define INIT_TOOL_BMP(bmp) \
373 toolBarBitmaps[Tool_##bmp] = wxBitmap(bmp##_xpm)
374 #else // !USE_XPM_BITMAPS
375 #define INIT_TOOL_BMP(bmp) \
376 toolBarBitmaps[Tool_##bmp] = wxBITMAP(bmp)
377 #endif // USE_XPM_BITMAPS/!USE_XPM_BITMAPS
384 INIT_TOOL_BMP(paste
);
385 INIT_TOOL_BMP(print
);
388 int w
= toolBarBitmaps
[Tool_new
].GetWidth(),
389 h
= toolBarBitmaps
[Tool_new
].GetHeight();
391 if ( !m_smallToolbar
)
396 for ( size_t n
= Tool_new
; n
< WXSIZEOF(toolBarBitmaps
); n
++ )
399 wxBitmap(toolBarBitmaps
[n
].ConvertToImage().Scale(w
, h
));
403 toolBar
->SetToolBitmapSize(wxSize(w
, h
));
405 toolBar
->AddTool(wxID_NEW
, _T("New"),
406 toolBarBitmaps
[Tool_new
], wxNullBitmap
, wxITEM_DROPDOWN
,
407 _T("New file"), _T("This is help for new file tool"));
409 wxMenu
* menu
= new wxMenu
;
410 menu
->Append(wxID_ANY
, _T("&First dummy item"));
411 menu
->Append(wxID_ANY
, _T("&Second dummy item"));
412 menu
->AppendSeparator();
413 menu
->Append(wxID_EXIT
, _T("Exit"));
414 toolBar
->SetDropdownMenu(wxID_NEW
, menu
);
416 toolBar
->AddTool(wxID_OPEN
, _T("Open"),
417 toolBarBitmaps
[Tool_open
], wxNullBitmap
, wxITEM_NORMAL
,
418 _T("Open file"), _T("This is help for open file tool"));
420 // the generic toolbar doesn't really support this
421 #if wxUSE_TOOLBAR_NATIVE && !defined(__WXX11__) || defined(__WXUNIVERSAL__)
422 // adding a combo to a vertical toolbar is not very smart
423 if ( !( toolBar
->IsVertical() ) )
425 wxComboBox
*combo
= new wxComboBox(toolBar
, ID_COMBO
, wxEmptyString
, wxDefaultPosition
, wxSize(100,-1) );
426 combo
->Append(_T("This"));
427 combo
->Append(_T("is a"));
428 combo
->Append(_T("combobox"));
429 combo
->Append(_T("in a"));
430 combo
->Append(_T("toolbar"));
431 toolBar
->AddControl(combo
, _T("Combo Label"));
433 wxSpinCtrl
*spin
= new wxSpinCtrl( toolBar
, ID_SPIN
, wxT("0"), wxDefaultPosition
, wxSize(80,wxDefaultCoord
), 0, 0, 100 );
434 toolBar
->AddControl( spin
);
436 wxTextCtrl
*text
= new wxTextCtrl( toolBar
, -1, wxT("text"), wxDefaultPosition
, wxSize(80,wxDefaultCoord
) );
437 toolBar
->AddControl( text
);
439 wxSearchCtrl
*srch
= new wxSearchCtrl( toolBar
, -1, wxT("xx"), wxDefaultPosition
, wxSize(80,wxDefaultCoord
), wxSUNKEN_BORDER
);
440 toolBar
->AddControl( srch
);
442 #endif // toolbars which don't support controls
444 toolBar
->AddTool(wxID_SAVE
, _T("Save"), toolBarBitmaps
[Tool_save
], _T("Toggle button 1"), wxITEM_CHECK
);
445 toolBar
->AddTool(wxID_COPY
, _T("Copy"), toolBarBitmaps
[Tool_copy
], _T("Toggle button 2"), wxITEM_CHECK
);
446 toolBar
->AddTool(wxID_CUT
, _T("Cut"), toolBarBitmaps
[Tool_cut
], _T("Toggle/Untoggle help button"));
447 toolBar
->AddTool(wxID_PASTE
, _T("Paste"), toolBarBitmaps
[Tool_paste
], _T("Paste"));
449 if ( m_useCustomDisabled
)
451 wxBitmap
bmpDisabled(w
, h
);
454 dc
.SelectObject(bmpDisabled
);
455 dc
.DrawBitmap(toolBarBitmaps
[Tool_print
], 0, 0);
457 wxPen
pen(*wxRED
, 5);
459 dc
.DrawLine(0, 0, w
, h
);
462 toolBar
->AddTool(wxID_PRINT
, _T("Print"), toolBarBitmaps
[Tool_print
],
467 toolBar
->AddTool(wxID_PRINT
, _T("Print"), toolBarBitmaps
[Tool_print
],
468 _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."));
471 toolBar
->AddSeparator();
472 toolBar
->AddTool(wxID_HELP
, _T("Help"), toolBarBitmaps
[Tool_help
], _T("Help button"), wxITEM_CHECK
);
474 if ( !m_pathBmp
.empty() )
476 // create a tool with a custom bitmap for testing
477 wxImage
img(m_pathBmp
);
480 if ( img
.GetWidth() > w
&& img
.GetHeight() > h
)
481 img
= img
.GetSubImage(wxRect(0, 0, w
, h
));
483 toolBar
->AddSeparator();
484 toolBar
->AddTool(wxID_ANY
, _T("Custom"), img
);
488 // after adding the buttons to the toolbar, must call Realize() to reflect
492 toolBar
->SetRows(!(toolBar
->IsVertical()) ? m_rows
: 10 / m_rows
);
495 // ----------------------------------------------------------------------------
497 // ----------------------------------------------------------------------------
499 // Define my frame constructor
500 MyFrame::MyFrame(wxFrame
* parent
,
502 const wxString
& title
,
506 : wxFrame(parent
, id
, title
, pos
, size
, style
)
510 m_smallToolbar
= true;
512 m_useCustomDisabled
= false;
513 m_showTooltips
= true;
519 // Give it a status line
524 SetIcon(wxICON(mondrian
));
527 wxMenu
*tbarMenu
= new wxMenu
;
528 tbarMenu
->AppendCheckItem(IDM_TOOLBAR_TOGGLE_TOOLBAR
,
529 _T("Toggle &toolbar\tCtrl-Z"),
530 _T("Show or hide the toolbar"));
532 tbarMenu
->AppendCheckItem(IDM_TOOLBAR_TOGGLE_ANOTHER_TOOLBAR
,
533 _T("Toggle &another toolbar\tCtrl-A"),
534 _T("Show/hide another test toolbar"));
536 tbarMenu
->AppendCheckItem(IDM_TOOLBAR_TOGGLE_HORIZONTAL_TEXT
,
537 _T("Toggle hori&zontal text\tCtrl-H"),
538 _T("Show text under/alongside the icon"));
540 tbarMenu
->AppendCheckItem(IDM_TOOLBAR_TOGGLETOOLBARSIZE
,
541 _T("&Toggle toolbar size\tCtrl-S"),
542 _T("Toggle between big/small toolbar"));
544 tbarMenu
->AppendCheckItem(IDM_TOOLBAR_TOGGLETOOLBARROWS
,
545 _T("Toggle number of &rows\tCtrl-R"),
546 _T("Toggle number of toolbar rows between 1 and 2"));
548 tbarMenu
->AppendCheckItem(IDM_TOOLBAR_TOGGLETOOLTIPS
,
549 _T("Show &tooltips\tCtrl-L"),
550 _T("Show tooltips for the toolbar tools"));
552 tbarMenu
->AppendCheckItem(IDM_TOOLBAR_TOGGLECUSTOMDISABLED
,
553 _T("Use c&ustom disabled images\tCtrl-U"),
554 _T("Switch between using system-generated and custom disabled images"));
557 tbarMenu
->AppendSeparator();
558 tbarMenu
->AppendRadioItem(IDM_TOOLBAR_TOP_ORIENTATION
,
559 _T("Set toolbar at the top of the window"),
560 _T("Set toolbar at the top of the window"));
561 tbarMenu
->AppendRadioItem(IDM_TOOLBAR_LEFT_ORIENTATION
,
562 _T("Set toolbar at the left of the window"),
563 _T("Set toolbar at the left of the window"));
564 tbarMenu
->AppendRadioItem(IDM_TOOLBAR_BOTTOM_ORIENTATION
,
565 _T("Set toolbar at the bottom of the window"),
566 _T("Set toolbar at the bottom of the window"));
567 tbarMenu
->AppendRadioItem(IDM_TOOLBAR_RIGHT_ORIENTATION
,
568 _T("Set toolbar at the right edge of the window"),
569 _T("Set toolbar at the right edge of the window"));
570 tbarMenu
->AppendSeparator();
572 tbarMenu
->Append(IDM_TOOLBAR_ENABLEPRINT
, _T("&Enable print button\tCtrl-E"));
573 tbarMenu
->Append(IDM_TOOLBAR_DELETEPRINT
, _T("&Delete print button\tCtrl-D"));
574 tbarMenu
->Append(IDM_TOOLBAR_INSERTPRINT
, _T("&Insert print button\tCtrl-I"));
575 tbarMenu
->Append(IDM_TOOLBAR_TOGGLEHELP
, _T("Toggle &help button\tCtrl-T"));
576 tbarMenu
->AppendSeparator();
577 tbarMenu
->Append(IDM_TOOLBAR_TOGGLERADIOBTN1
, _T("Toggle &1st radio button\tCtrl-1"));
578 tbarMenu
->Append(IDM_TOOLBAR_TOGGLERADIOBTN2
, _T("Toggle &2nd radio button\tCtrl-2"));
579 tbarMenu
->Append(IDM_TOOLBAR_TOGGLERADIOBTN3
, _T("Toggle &3rd radio button\tCtrl-3"));
580 tbarMenu
->AppendSeparator();
581 tbarMenu
->Append(IDM_TOOLBAR_CHANGE_TOOLTIP
, _T("Change tool tip"));
582 tbarMenu
->AppendSeparator();
583 tbarMenu
->AppendRadioItem(IDM_TOOLBAR_SHOW_TEXT
, _T("Show &text\tCtrl-Alt-T"));
584 tbarMenu
->AppendRadioItem(IDM_TOOLBAR_SHOW_ICONS
, _T("Show &icons\tCtrl-Alt-I"));
585 tbarMenu
->AppendRadioItem(IDM_TOOLBAR_SHOW_BOTH
, _T("Show &both\tCtrl-Alt-B"));
586 tbarMenu
->AppendSeparator();
587 tbarMenu
->Append(IDM_TOOLBAR_CUSTOM_PATH
, _T("Custom &bitmap...\tCtrl-B"));
589 wxMenu
*fileMenu
= new wxMenu
;
590 fileMenu
->Append(wxID_EXIT
, _T("E&xit\tAlt-X"), _T("Quit toolbar sample") );
592 wxMenu
*helpMenu
= new wxMenu
;
593 helpMenu
->Append(wxID_HELP
, _T("&About"), _T("About toolbar sample"));
595 wxMenuBar
* menuBar
= new wxMenuBar( wxMB_DOCKABLE
);
597 menuBar
->Append(fileMenu
, _T("&File"));
598 menuBar
->Append(tbarMenu
, _T("&Toolbar"));
599 menuBar
->Append(helpMenu
, _T("&Help"));
601 // Associate the menu bar with the frame
604 menuBar
->Check(IDM_TOOLBAR_SHOW_BOTH
, true);
605 menuBar
->Check(IDM_TOOLBAR_TOGGLETOOLTIPS
, true);
607 menuBar
->Check(IDM_TOOLBAR_TOP_ORIENTATION
, true );
608 m_toolbarPosition
= TOOLBAR_TOP
;
610 // Create the toolbar
613 m_panel
= new wxPanel(this, wxID_ANY
);
614 #if USE_UNMANAGED_TOOLBAR
615 m_extraToolBar
= new wxToolBar(m_panel
, wxID_ANY
, wxDefaultPosition
, wxDefaultSize
, wxTB_TEXT
|wxTB_FLAT
|wxTB_TOP
);
616 PopulateToolbar(m_extraToolBar
);
618 m_extraToolBar
= NULL
;
621 m_textWindow
= new wxTextCtrl(m_panel
, wxID_ANY
, wxEmptyString
, wxDefaultPosition
, wxDefaultSize
, wxTE_MULTILINE
);
623 wxBoxSizer
* sizer
= new wxBoxSizer(wxVERTICAL
);
624 m_panel
->SetSizer(sizer
);
626 sizer
->Add(m_extraToolBar
, 0, wxEXPAND
, 0);
627 sizer
->Add(m_textWindow
, 1, wxEXPAND
, 0);
630 void MyFrame::LayoutChildren()
632 wxSize size
= GetClientSize();
637 m_tbar
->SetSize(0, 0, wxDefaultCoord
, size
.y
);
639 offset
= m_tbar
->GetSize().x
;
646 m_panel
->SetSize(offset
, 0, size
.x
- offset
, size
.y
);
649 void MyFrame::OnSize(wxSizeEvent
& event
)
661 void MyFrame::OnToggleToolbar(wxCommandEvent
& WXUNUSED(event
))
663 wxToolBar
*tbar
= GetToolBar();
677 void MyFrame::OnToggleHorizontalText(wxCommandEvent
& WXUNUSED(event
))
679 m_horzText
= !m_horzText
;
684 void MyFrame::OnToggleAnotherToolbar(wxCommandEvent
& WXUNUSED(event
))
693 long style
= GetToolBar() ? GetToolBar()->GetWindowStyle()
695 style
&= ~wxTB_HORIZONTAL
;
696 style
|= wxTB_VERTICAL
;
698 m_tbar
= new wxToolBar(this, wxID_ANY
,
699 wxDefaultPosition
, wxDefaultSize
,
702 m_tbar
->SetMargins(4, 4);
704 m_tbar
->AddRadioTool(IDM_TOOLBAR_OTHER_1
, _T("First"), wxBITMAP(new));
705 m_tbar
->AddRadioTool(IDM_TOOLBAR_OTHER_2
, _T("Second"), wxBITMAP(open
));
706 m_tbar
->AddRadioTool(IDM_TOOLBAR_OTHER_3
, _T("Third"), wxBITMAP(save
));
707 m_tbar
->AddSeparator();
708 m_tbar
->AddTool(wxID_HELP
, _T("Help"), wxBITMAP(help
));
716 void MyFrame::OnToggleToolbarSize(wxCommandEvent
& WXUNUSED(event
))
718 m_smallToolbar
= !m_smallToolbar
;
723 void MyFrame::OnToggleToolbarRows(wxCommandEvent
& WXUNUSED(event
))
725 // m_rows may be only 1 or 2
728 GetToolBar()->SetRows(!(GetToolBar()->IsVertical()) ? m_rows
: 10 / m_rows
);
730 //RecreateToolbar(); -- this is unneeded
733 void MyFrame::OnToggleTooltips(wxCommandEvent
& WXUNUSED(event
))
735 m_showTooltips
= !m_showTooltips
;
740 void MyFrame::OnToggleCustomDisabled(wxCommandEvent
& WXUNUSED(event
))
742 m_useCustomDisabled
= !m_useCustomDisabled
;
747 void MyFrame::OnChangeOrientation(wxCommandEvent
& event
)
749 switch( event
.GetId() )
751 case IDM_TOOLBAR_LEFT_ORIENTATION
:
752 m_toolbarPosition
= TOOLBAR_LEFT
;
754 case IDM_TOOLBAR_TOP_ORIENTATION
:
755 m_toolbarPosition
= TOOLBAR_TOP
;
757 case IDM_TOOLBAR_RIGHT_ORIENTATION
:
758 m_toolbarPosition
= TOOLBAR_RIGHT
;
760 case IDM_TOOLBAR_BOTTOM_ORIENTATION
:
761 m_toolbarPosition
= TOOLBAR_BOTTOM
;
767 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
772 void MyFrame::OnAbout(wxCommandEvent
& event
)
774 if ( event
.IsChecked() )
775 m_textWindow
->WriteText( _T("Help button down now.\n") );
777 m_textWindow
->WriteText( _T("Help button up now.\n") );
779 (void)wxMessageBox(_T("wxWidgets toolbar sample"), _T("About wxToolBar"));
782 void MyFrame::OnToolLeftClick(wxCommandEvent
& event
)
785 str
.Printf( _T("Clicked on tool %d\n"), event
.GetId());
786 m_textWindow
->WriteText( str
);
788 if (event
.GetId() == wxID_COPY
)
793 if (event
.GetId() == wxID_CUT
)
798 if (event
.GetId() == wxID_PRINT
)
804 void MyFrame::OnToolRightClick(wxCommandEvent
& event
)
806 m_textWindow
->AppendText(
807 wxString::Format(_T("Tool %d right clicked.\n"),
808 (int) event
.GetInt()));
811 void MyFrame::OnCombo(wxCommandEvent
& event
)
813 wxLogStatus(_T("Combobox string '%s' selected"), event
.GetString().c_str());
816 void MyFrame::DoEnablePrint()
821 wxToolBarBase
*tb
= GetToolBar();
822 tb
->EnableTool(wxID_PRINT
, !tb
->GetToolEnabled(wxID_PRINT
));
825 void MyFrame::DoDeletePrint()
830 wxToolBarBase
*tb
= GetToolBar();
831 tb
->DeleteTool( wxID_PRINT
);
836 void MyFrame::DoToggleHelp()
838 wxToolBarBase
*tb
= GetToolBar();
839 tb
->ToggleTool( wxID_HELP
, !tb
->GetToolState( wxID_HELP
) );
842 void MyFrame::OnUpdateCopyAndCut(wxUpdateUIEvent
& event
)
844 event
.Enable( m_textWindow
->CanCopy() );
847 void MyFrame::OnUpdateToggleHorzText(wxUpdateUIEvent
& event
)
849 wxToolBar
*tbar
= GetToolBar();
850 event
.Enable( tbar
&&
851 tbar
->HasFlag(wxTB_TEXT
) &&
852 !tbar
->HasFlag(wxTB_NOICONS
) );
855 void MyFrame::OnChangeToolTip(wxCommandEvent
& WXUNUSED(event
))
857 GetToolBar()->SetToolShortHelp(wxID_NEW
, _T("New toolbar button"));
860 void MyFrame::OnToolbarStyle(wxCommandEvent
& event
)
862 long style
= GetToolBar()->GetWindowStyle();
863 style
&= ~(wxTB_NOICONS
| wxTB_TEXT
);
865 switch ( event
.GetId() )
867 case IDM_TOOLBAR_SHOW_TEXT
:
868 style
|= wxTB_NOICONS
| wxTB_TEXT
;
871 case IDM_TOOLBAR_SHOW_ICONS
:
875 case IDM_TOOLBAR_SHOW_BOTH
:
879 GetToolBar()->SetWindowStyle(style
);
882 void MyFrame::OnToolbarCustomBitmap(wxCommandEvent
& WXUNUSED(event
))
884 m_pathBmp
= wxFileSelector(_T("Custom bitmap path"));
889 void MyFrame::OnInsertPrint(wxCommandEvent
& WXUNUSED(event
))
893 wxToolBarBase
*tb
= GetToolBar();
894 tb
->InsertTool(0, wxID_PRINT
, _T("New print"),
895 wxBITMAP(print
), wxNullBitmap
,
897 _T("Delete this tool"),
898 _T("This button was inserted into the toolbar"));
900 // must call Realize() after adding a new button
904 void MyFrame::OnToggleRadioBtn(wxCommandEvent
& event
)
908 m_tbar
->ToggleTool(IDM_TOOLBAR_OTHER_1
+
909 event
.GetId() - IDM_TOOLBAR_TOGGLERADIOBTN1
, true);
913 void MyFrame::OnToolDropdown(wxCommandEvent
& event
)
916 str
.Printf( _T("Dropdown on tool %d\n"), event
.GetId());
917 m_textWindow
->WriteText( str
);