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 OnBottomToolbar(wxCommandEvent
& WXUNUSED(event
));
101 void OnToggleToolbarSize(wxCommandEvent
& event
);
102 void OnToggleToolbarOrient(wxCommandEvent
& event
);
103 void OnToggleToolbarRows(wxCommandEvent
& event
);
104 void OnToggleTooltips(wxCommandEvent
& event
);
105 void OnToggleCustomDisabled(wxCommandEvent
& event
);
107 void OnEnablePrint(wxCommandEvent
& WXUNUSED(event
)) { DoEnablePrint(); }
108 void OnDeletePrint(wxCommandEvent
& WXUNUSED(event
)) { DoDeletePrint(); }
109 void OnInsertPrint(wxCommandEvent
& event
);
110 void OnChangeToolTip(wxCommandEvent
& event
);
111 void OnToggleHelp(wxCommandEvent
& WXUNUSED(event
)) { DoToggleHelp(); }
112 void OnToggleRadioBtn(wxCommandEvent
& event
);
114 void OnToolbarStyle(wxCommandEvent
& event
);
115 void OnToolbarCustomBitmap(wxCommandEvent
& event
);
117 void OnToolLeftClick(wxCommandEvent
& event
);
118 void OnToolRightClick(wxCommandEvent
& event
);
119 void OnToolEnter(wxCommandEvent
& event
);
121 void OnCombo(wxCommandEvent
& event
);
123 void OnUpdateCopyAndCut(wxUpdateUIEvent
& event
);
124 void OnUpdateToggleHorzText(wxUpdateUIEvent
& event
);
125 void OnUpdateToggleRadioBtn(wxUpdateUIEvent
& event
)
126 { event
.Enable( m_tbar
!= NULL
); }
129 void DoEnablePrint();
130 void DoDeletePrint();
133 void LayoutChildren();
141 size_t m_rows
; // 1 or 2 only
143 // the number of print buttons we have (they're added/removed dynamically)
146 wxTextCtrl
*m_textWindow
;
150 // the path to the custom bitmap for the test toolbar tool
153 DECLARE_EVENT_TABLE()
156 // ----------------------------------------------------------------------------
158 // ----------------------------------------------------------------------------
160 const int ID_TOOLBAR
= 500;
162 static const long TOOLBAR_STYLE
= wxTB_FLAT
| wxTB_DOCKABLE
| wxTB_TEXT
;
166 IDM_TOOLBAR_TOGGLETOOLBARSIZE
= 200,
167 IDM_TOOLBAR_TOGGLETOOLBARORIENT
,
168 IDM_TOOLBAR_TOGGLETOOLBARROWS
,
169 IDM_TOOLBAR_TOGGLETOOLTIPS
,
170 IDM_TOOLBAR_TOGGLECUSTOMDISABLED
,
171 IDM_TOOLBAR_ENABLEPRINT
,
172 IDM_TOOLBAR_DELETEPRINT
,
173 IDM_TOOLBAR_INSERTPRINT
,
174 IDM_TOOLBAR_TOGGLEHELP
,
175 IDM_TOOLBAR_TOGGLERADIOBTN1
,
176 IDM_TOOLBAR_TOGGLERADIOBTN2
,
177 IDM_TOOLBAR_TOGGLERADIOBTN3
,
178 IDM_TOOLBAR_TOGGLE_TOOLBAR
,
179 IDM_TOOLBAR_TOGGLE_HORIZONTAL_TEXT
,
180 IDM_TOOLBAR_TOGGLE_ANOTHER_TOOLBAR
,
181 IDM_TOOLBAR_CHANGE_TOOLTIP
,
182 IDM_TOOLBAR_SHOW_TEXT
,
183 IDM_TOOLBAR_SHOW_ICONS
,
184 IDM_TOOLBAR_SHOW_BOTH
,
185 IDM_TOOLBAR_CUSTOM_PATH
,
186 IDM_TOOLBAR_BOTTOM_ORIENTATION
,
195 // ----------------------------------------------------------------------------
197 // ----------------------------------------------------------------------------
199 // Notice that wxID_HELP will be processed for the 'About' menu and the toolbar
202 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
203 EVT_SIZE(MyFrame::OnSize
)
205 EVT_MENU(wxID_EXIT
, MyFrame::OnQuit
)
206 EVT_MENU(wxID_HELP
, MyFrame::OnAbout
)
208 EVT_MENU(IDM_TOOLBAR_TOGGLE_TOOLBAR
, MyFrame::OnToggleToolbar
)
209 EVT_MENU(IDM_TOOLBAR_TOGGLE_ANOTHER_TOOLBAR
, MyFrame::OnToggleAnotherToolbar
)
210 EVT_MENU(IDM_TOOLBAR_TOGGLE_HORIZONTAL_TEXT
, MyFrame::OnToggleHorizontalText
)
212 EVT_MENU(IDM_TOOLBAR_BOTTOM_ORIENTATION
, MyFrame::OnBottomToolbar
)
213 EVT_MENU(IDM_TOOLBAR_TOGGLETOOLBARSIZE
, MyFrame::OnToggleToolbarSize
)
214 EVT_MENU(IDM_TOOLBAR_TOGGLETOOLBARORIENT
, MyFrame::OnToggleToolbarOrient
)
215 EVT_MENU(IDM_TOOLBAR_TOGGLETOOLBARROWS
, MyFrame::OnToggleToolbarRows
)
216 EVT_MENU(IDM_TOOLBAR_TOGGLETOOLTIPS
, MyFrame::OnToggleTooltips
)
217 EVT_MENU(IDM_TOOLBAR_TOGGLECUSTOMDISABLED
, MyFrame::OnToggleCustomDisabled
)
219 EVT_MENU(IDM_TOOLBAR_ENABLEPRINT
, MyFrame::OnEnablePrint
)
220 EVT_MENU(IDM_TOOLBAR_DELETEPRINT
, MyFrame::OnDeletePrint
)
221 EVT_MENU(IDM_TOOLBAR_INSERTPRINT
, MyFrame::OnInsertPrint
)
222 EVT_MENU(IDM_TOOLBAR_TOGGLEHELP
, MyFrame::OnToggleHelp
)
223 EVT_MENU_RANGE(IDM_TOOLBAR_TOGGLERADIOBTN1
, IDM_TOOLBAR_TOGGLERADIOBTN3
,
224 MyFrame::OnToggleRadioBtn
)
225 EVT_MENU(IDM_TOOLBAR_CHANGE_TOOLTIP
, MyFrame::OnChangeToolTip
)
227 EVT_MENU_RANGE(IDM_TOOLBAR_SHOW_TEXT
, IDM_TOOLBAR_SHOW_BOTH
,
228 MyFrame::OnToolbarStyle
)
230 EVT_MENU(IDM_TOOLBAR_CUSTOM_PATH
, MyFrame::OnToolbarCustomBitmap
)
232 EVT_MENU(wxID_ANY
, MyFrame::OnToolLeftClick
)
234 EVT_COMBOBOX(ID_COMBO
, MyFrame::OnCombo
)
236 EVT_TOOL_ENTER(ID_TOOLBAR
, MyFrame::OnToolEnter
)
237 EVT_TOOL_RCLICKED(wxID_ANY
, MyFrame::OnToolRightClick
)
239 EVT_UPDATE_UI(wxID_COPY
, MyFrame::OnUpdateCopyAndCut
)
240 EVT_UPDATE_UI(wxID_CUT
, MyFrame::OnUpdateCopyAndCut
)
242 EVT_UPDATE_UI_RANGE(IDM_TOOLBAR_TOGGLERADIOBTN1
,
243 IDM_TOOLBAR_TOGGLERADIOBTN3
,
244 MyFrame::OnUpdateToggleRadioBtn
)
245 EVT_UPDATE_UI(IDM_TOOLBAR_TOGGLE_HORIZONTAL_TEXT
,
246 MyFrame::OnUpdateToggleHorzText
)
249 // ============================================================================
251 // ============================================================================
253 // ----------------------------------------------------------------------------
255 // ----------------------------------------------------------------------------
259 // The `main program' equivalent, creating the windows and returning the
263 // Create the main frame window
264 MyFrame
* frame
= new MyFrame((wxFrame
*) NULL
, wxID_ANY
,
265 _T("wxToolBar Sample"),
266 wxPoint(100, 100), wxSize(550, 300));
271 frame
->SetStatusText(_T("Hello, wxWidgets"));
274 wxInitAllImageHandlers();
281 void MyFrame::RecreateToolbar()
284 // On Windows CE, we should not delete the
285 // previous toolbar in case it contains the menubar.
286 // We'll try to accommodate this usage in due course.
287 wxToolBar
* toolBar
= CreateToolBar();
289 // delete and recreate the toolbar
290 wxToolBarBase
*toolBar
= GetToolBar();
291 long style
= toolBar
? toolBar
->GetWindowStyle() : TOOLBAR_STYLE
;
297 style
&= ~(wxTB_HORIZONTAL
| wxTB_VERTICAL
| wxTB_BOTTOM
| wxTB_HORZ_LAYOUT
);
298 if( m_bottomToolbar
)
299 style
|= wxTB_BOTTOM
;
301 style
|= m_horzToolbar
? wxTB_HORIZONTAL
: wxTB_VERTICAL
;
303 if ( m_showTooltips
)
304 style
&= ~wxTB_NO_TOOLTIPS
;
306 style
|= wxTB_NO_TOOLTIPS
;
308 if ( style
& wxTB_TEXT
&& !(style
& wxTB_NOICONS
) && m_horzText
)
309 style
|= wxTB_HORZ_LAYOUT
;
311 toolBar
= CreateToolBar(style
, ID_TOOLBAR
);
328 wxBitmap toolBarBitmaps
[Tool_Max
];
331 #define INIT_TOOL_BMP(bmp) \
332 toolBarBitmaps[Tool_##bmp] = wxBitmap(bmp##_xpm)
333 #else // !USE_XPM_BITMAPS
334 #define INIT_TOOL_BMP(bmp) \
335 toolBarBitmaps[Tool_##bmp] = wxBITMAP(bmp)
336 #endif // USE_XPM_BITMAPS/!USE_XPM_BITMAPS
343 INIT_TOOL_BMP(paste
);
344 INIT_TOOL_BMP(print
);
347 int w
= toolBarBitmaps
[Tool_new
].GetWidth(),
348 h
= toolBarBitmaps
[Tool_new
].GetHeight();
350 if ( !m_smallToolbar
)
355 for ( size_t n
= Tool_new
; n
< WXSIZEOF(toolBarBitmaps
); n
++ )
358 wxBitmap(toolBarBitmaps
[n
].ConvertToImage().Scale(w
, h
));
362 toolBar
->SetToolBitmapSize(wxSize(w
, h
));
364 toolBar
->AddTool(wxID_NEW
, _T("New"), toolBarBitmaps
[Tool_new
], _T("New file"));
365 toolBar
->AddTool(wxID_OPEN
, _T("Open"), toolBarBitmaps
[Tool_open
], _T("Open file"));
367 // the generic toolbar doesn't really support this
368 #if wxUSE_TOOLBAR_NATIVE && !defined(__WXX11__) || defined(__WXUNIVERSAL__)
369 // adding a combo to a vertical toolbar is not very smart
372 wxComboBox
*combo
= new wxComboBox(toolBar
, ID_COMBO
, wxEmptyString
, wxDefaultPosition
, wxSize(200,wxDefaultCoord
) );
373 combo
->Append(_T("This"));
374 combo
->Append(_T("is a"));
375 combo
->Append(_T("combobox"));
376 combo
->Append(_T("in a"));
377 combo
->Append(_T("toolbar"));
378 toolBar
->AddControl(combo
);
380 //wxSpinCtrl *spin = new wxSpinCtrl( toolBar, ID_SPIN, wxT("0"), wxDefaultPosition, wxSize(80,wxDefaultCoord), 0, 100, 0 );
381 //toolBar->AddControl( spin );
383 #endif // toolbars which don't support controls
385 toolBar
->AddTool(wxID_SAVE
, _T("Save"), toolBarBitmaps
[Tool_save
], _T("Toggle button 1"), wxITEM_CHECK
);
386 toolBar
->AddTool(wxID_COPY
, _T("Copy"), toolBarBitmaps
[Tool_copy
], _T("Toggle button 2"), wxITEM_CHECK
);
387 toolBar
->AddTool(wxID_CUT
, _T("Cut"), toolBarBitmaps
[Tool_cut
], _T("Toggle/Untoggle help button"));
388 toolBar
->AddTool(wxID_PASTE
, _T("Paste"), toolBarBitmaps
[Tool_paste
], _T("Paste"));
390 if ( m_useCustomDisabled
)
392 wxBitmap
bmpDisabled(w
, h
);
395 dc
.SelectObject(bmpDisabled
);
396 dc
.DrawBitmap(toolBarBitmaps
[Tool_print
], 0, 0);
398 wxPen
pen(*wxRED
, 5);
400 dc
.DrawLine(0, 0, w
, h
);
403 toolBar
->AddTool(wxID_PRINT
, _T("Print"), toolBarBitmaps
[Tool_print
],
408 toolBar
->AddTool(wxID_PRINT
, _T("Print"), toolBarBitmaps
[Tool_print
],
409 _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."));
412 toolBar
->AddSeparator();
413 toolBar
->AddTool(wxID_HELP
, _T("Help"), toolBarBitmaps
[Tool_help
], _T("Help button"), wxITEM_CHECK
);
415 if ( !m_pathBmp
.empty() )
417 // create a tool with a custom bitmap for testing
418 wxImage
img(m_pathBmp
);
421 if ( img
.GetWidth() > w
&& img
.GetHeight() > h
)
422 img
= img
.GetSubImage(wxRect(0, 0, w
, h
));
424 toolBar
->AddSeparator();
425 toolBar
->AddTool(wxID_ANY
, _T("Custom"), img
);
429 // after adding the buttons to the toolbar, must call Realize() to reflect
433 toolBar
->SetRows(m_horzToolbar
? m_rows
: 10 / m_rows
);
436 // ----------------------------------------------------------------------------
438 // ----------------------------------------------------------------------------
440 // Define my frame constructor
441 MyFrame::MyFrame(wxFrame
* parent
,
443 const wxString
& title
,
447 : wxFrame(parent
, id
, title
, pos
, size
, style
)
451 m_smallToolbar
= true;
452 m_horzToolbar
= true;
453 m_bottomToolbar
= false;
455 m_useCustomDisabled
= false;
456 m_showTooltips
= true;
462 // Give it a status line
467 SetIcon(wxICON(mondrian
));
470 wxMenu
*tbarMenu
= new wxMenu
;
471 tbarMenu
->AppendCheckItem(IDM_TOOLBAR_TOGGLE_TOOLBAR
,
472 _T("Toggle &toolbar\tCtrl-Z"),
473 _T("Show or hide the toolbar"));
475 tbarMenu
->AppendCheckItem(IDM_TOOLBAR_TOGGLE_ANOTHER_TOOLBAR
,
476 _T("Toggle &another toolbar\tCtrl-A"),
477 _T("Show/hide another test toolbar"));
479 tbarMenu
->AppendCheckItem(IDM_TOOLBAR_TOGGLE_HORIZONTAL_TEXT
,
480 _T("Toggle hori&zontal text\tCtrl-H"),
481 _T("Show text under/alongside the icon"));
483 tbarMenu
->AppendCheckItem(IDM_TOOLBAR_TOGGLETOOLBARSIZE
,
484 _T("&Toggle toolbar size\tCtrl-S"),
485 _T("Toggle between big/small toolbar"));
487 tbarMenu
->AppendCheckItem(IDM_TOOLBAR_TOGGLETOOLBARORIENT
,
488 _T("Toggle toolbar &orientation\tCtrl-O"),
489 _T("Toggle toolbar orientation"));
491 tbarMenu
->AppendCheckItem(IDM_TOOLBAR_TOGGLETOOLBARROWS
,
492 _T("Toggle number of &rows\tCtrl-R"),
493 _T("Toggle number of toolbar rows between 1 and 2"));
495 tbarMenu
->AppendCheckItem(IDM_TOOLBAR_TOGGLETOOLTIPS
,
496 _T("Show &tooltips\tCtrl-L"),
497 _T("Show tooltips for the toolbar tools"));
499 tbarMenu
->AppendCheckItem(IDM_TOOLBAR_TOGGLECUSTOMDISABLED
,
500 _T("Use c&ustom disabled images\tCtrl-U"),
501 _T("Switch between using system-generated and custom disabled images"));
504 tbarMenu
->AppendCheckItem(IDM_TOOLBAR_BOTTOM_ORIENTATION
,
505 _T("Set toolbar at the bottom of the window"),
506 _T("Set toolbar at the bottom of the window"));
507 tbarMenu
->AppendSeparator();
509 tbarMenu
->Append(IDM_TOOLBAR_ENABLEPRINT
, _T("&Enable print button\tCtrl-E"));
510 tbarMenu
->Append(IDM_TOOLBAR_DELETEPRINT
, _T("&Delete print button\tCtrl-D"));
511 tbarMenu
->Append(IDM_TOOLBAR_INSERTPRINT
, _T("&Insert print button\tCtrl-I"));
512 tbarMenu
->Append(IDM_TOOLBAR_TOGGLEHELP
, _T("Toggle &help button\tCtrl-T"));
513 tbarMenu
->AppendSeparator();
514 tbarMenu
->Append(IDM_TOOLBAR_TOGGLERADIOBTN1
, _T("Toggle &1st radio button\tCtrl-1"));
515 tbarMenu
->Append(IDM_TOOLBAR_TOGGLERADIOBTN2
, _T("Toggle &2nd radio button\tCtrl-2"));
516 tbarMenu
->Append(IDM_TOOLBAR_TOGGLERADIOBTN3
, _T("Toggle &3rd radio button\tCtrl-3"));
517 tbarMenu
->AppendSeparator();
518 tbarMenu
->Append(IDM_TOOLBAR_CHANGE_TOOLTIP
, _T("Change tool tip"));
519 tbarMenu
->AppendSeparator();
520 tbarMenu
->AppendRadioItem(IDM_TOOLBAR_SHOW_TEXT
, _T("Show &text\tCtrl-Alt-T"));
521 tbarMenu
->AppendRadioItem(IDM_TOOLBAR_SHOW_ICONS
, _T("Show &icons\tCtrl-Alt-I"));
522 tbarMenu
->AppendRadioItem(IDM_TOOLBAR_SHOW_BOTH
, _T("Show &both\tCtrl-Alt-B"));
523 tbarMenu
->AppendSeparator();
524 tbarMenu
->Append(IDM_TOOLBAR_CUSTOM_PATH
, _T("Custom &bitmap...\tCtrl-B"));
526 wxMenu
*fileMenu
= new wxMenu
;
527 fileMenu
->Append(wxID_EXIT
, _T("E&xit\tAlt-X"), _T("Quit toolbar sample") );
529 wxMenu
*helpMenu
= new wxMenu
;
530 helpMenu
->Append(wxID_HELP
, _T("&About"), _T("About toolbar sample"));
532 wxMenuBar
* menuBar
= new wxMenuBar( wxMB_DOCKABLE
);
534 menuBar
->Append(fileMenu
, _T("&File"));
535 menuBar
->Append(tbarMenu
, _T("&Toolbar"));
536 menuBar
->Append(helpMenu
, _T("&Help"));
538 // Associate the menu bar with the frame
541 menuBar
->Check(IDM_TOOLBAR_SHOW_BOTH
, true);
542 menuBar
->Check(IDM_TOOLBAR_TOGGLETOOLTIPS
, true);
544 // Create the toolbar
547 m_textWindow
= new wxTextCtrl(this, wxID_ANY
, wxEmptyString
, wxDefaultPosition
, wxDefaultSize
, wxTE_MULTILINE
);
552 wxToolBar
* MyFrame::OnCreateToolBar(long style
,
554 const wxString
& name
)
556 return (wxToolBar
*)new wxToolBarSimple(this, id
,
557 wxDefaultPosition
, wxDefaultSize
,
561 #endif // USE_GENERIC_TBAR
563 void MyFrame::LayoutChildren()
565 wxSize size
= GetClientSize();
570 m_tbar
->SetSize(0, 0, wxDefaultCoord
, size
.y
);
572 offset
= m_tbar
->GetSize().x
;
579 m_textWindow
->SetSize(offset
, 0, size
.x
- offset
, size
.y
);
582 void MyFrame::OnSize(wxSizeEvent
& event
)
594 void MyFrame::OnToggleToolbar(wxCommandEvent
& WXUNUSED(event
))
596 wxToolBar
*tbar
= GetToolBar();
610 void MyFrame::OnToggleHorizontalText(wxCommandEvent
& WXUNUSED(event
))
612 m_horzText
= !m_horzText
;
617 void MyFrame::OnToggleAnotherToolbar(wxCommandEvent
& WXUNUSED(event
))
626 long style
= GetToolBar() ? GetToolBar()->GetWindowStyle()
628 style
&= ~wxTB_HORIZONTAL
;
629 style
|= wxTB_VERTICAL
;
631 m_tbar
= new wxToolBar(this, wxID_ANY
,
632 wxDefaultPosition
, wxDefaultSize
,
635 m_tbar
->SetMargins(4, 4);
637 m_tbar
->AddRadioTool(IDM_TOOLBAR_OTHER_1
, _T("First"), wxBITMAP(new));
638 m_tbar
->AddRadioTool(IDM_TOOLBAR_OTHER_2
, _T("Second"), wxBITMAP(open
));
639 m_tbar
->AddRadioTool(IDM_TOOLBAR_OTHER_3
, _T("Third"), wxBITMAP(save
));
640 m_tbar
->AddSeparator();
641 m_tbar
->AddTool(wxID_HELP
, _T("Help"), wxBITMAP(help
));
649 void MyFrame::OnToggleToolbarSize(wxCommandEvent
& WXUNUSED(event
))
651 m_smallToolbar
= !m_smallToolbar
;
656 void MyFrame::OnToggleToolbarRows(wxCommandEvent
& WXUNUSED(event
))
658 // m_rows may be only 1 or 2
661 GetToolBar()->SetRows(m_horzToolbar
? m_rows
: 10 / m_rows
);
663 //RecreateToolbar(); -- this is unneeded
666 void MyFrame::OnToggleTooltips(wxCommandEvent
& WXUNUSED(event
))
668 m_showTooltips
= !m_showTooltips
;
673 void MyFrame::OnToggleCustomDisabled(wxCommandEvent
& WXUNUSED(event
))
675 m_useCustomDisabled
= !m_useCustomDisabled
;
680 void MyFrame::OnToggleToolbarOrient(wxCommandEvent
& WXUNUSED(event
))
682 if( m_bottomToolbar
)
683 m_bottomToolbar
= false;
684 m_horzToolbar
= !m_horzToolbar
;
685 wxMenuBar
*menuBar
= GetMenuBar();
686 if( menuBar
->IsChecked( IDM_TOOLBAR_BOTTOM_ORIENTATION
) )
687 menuBar
->Check( IDM_TOOLBAR_BOTTOM_ORIENTATION
, false );
692 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
697 void MyFrame::OnAbout(wxCommandEvent
& event
)
699 if ( event
.IsChecked() )
700 m_textWindow
->WriteText( _T("Help button down now.\n") );
702 m_textWindow
->WriteText( _T("Help button up now.\n") );
704 (void)wxMessageBox(_T("wxWidgets toolbar sample"), _T("About wxToolBar"));
707 void MyFrame::OnToolLeftClick(wxCommandEvent
& event
)
710 str
.Printf( _T("Clicked on tool %d\n"), event
.GetId());
711 m_textWindow
->WriteText( str
);
713 if (event
.GetId() == wxID_COPY
)
718 if (event
.GetId() == wxID_CUT
)
723 if (event
.GetId() == wxID_PRINT
)
729 void MyFrame::OnToolRightClick(wxCommandEvent
& event
)
731 m_textWindow
->AppendText(
732 wxString::Format(_T("Tool %d right clicked.\n"),
733 (int) event
.GetInt()));
736 void MyFrame::OnCombo(wxCommandEvent
& event
)
738 wxLogStatus(_T("Combobox string '%s' selected"), event
.GetString().c_str());
741 void MyFrame::DoEnablePrint()
746 wxToolBarBase
*tb
= GetToolBar();
747 tb
->EnableTool(wxID_PRINT
, !tb
->GetToolEnabled(wxID_PRINT
));
750 void MyFrame::DoDeletePrint()
755 wxToolBarBase
*tb
= GetToolBar();
756 tb
->DeleteTool( wxID_PRINT
);
761 void MyFrame::DoToggleHelp()
763 wxToolBarBase
*tb
= GetToolBar();
764 tb
->ToggleTool( wxID_HELP
, !tb
->GetToolState( wxID_HELP
) );
767 void MyFrame::OnUpdateCopyAndCut(wxUpdateUIEvent
& event
)
769 event
.Enable( m_textWindow
->CanCopy() );
772 void MyFrame::OnUpdateToggleHorzText(wxUpdateUIEvent
& event
)
774 wxToolBar
*tbar
= GetToolBar();
775 event
.Enable( tbar
&&
776 tbar
->HasFlag(wxTB_TEXT
) &&
777 !tbar
->HasFlag(wxTB_NOICONS
) );
780 void MyFrame::OnChangeToolTip(wxCommandEvent
& WXUNUSED(event
))
782 GetToolBar()->SetToolShortHelp(wxID_NEW
, _T("New toolbar button"));
785 void MyFrame::OnToolbarStyle(wxCommandEvent
& event
)
787 long style
= GetToolBar()->GetWindowStyle();
788 style
&= ~(wxTB_NOICONS
| wxTB_TEXT
);
790 switch ( event
.GetId() )
792 case IDM_TOOLBAR_SHOW_TEXT
:
793 style
|= wxTB_NOICONS
| wxTB_TEXT
;
796 case IDM_TOOLBAR_SHOW_ICONS
:
800 case IDM_TOOLBAR_SHOW_BOTH
:
804 GetToolBar()->SetWindowStyle(style
);
807 void MyFrame::OnToolbarCustomBitmap(wxCommandEvent
& WXUNUSED(event
))
809 m_pathBmp
= wxFileSelector(_T("Custom bitmap path"));
814 void MyFrame::OnInsertPrint(wxCommandEvent
& WXUNUSED(event
))
818 wxToolBarBase
*tb
= GetToolBar();
819 tb
->InsertTool(0, wxID_PRINT
, _T("New print"),
820 wxBITMAP(print
), wxNullBitmap
,
822 _T("Delete this tool"),
823 _T("This button was inserted into the toolbar"));
825 // must call Realize() after adding a new button
829 void MyFrame::OnToolEnter(wxCommandEvent
& event
)
832 if (event
.GetSelection() > -1)
835 str
.Printf(_T("This is tool number %d"), event
.GetSelection());
839 SetStatusText(wxEmptyString
);
842 #endif // wxUSE_STATUSBAR
845 void MyFrame::OnToggleRadioBtn(wxCommandEvent
& event
)
849 m_tbar
->ToggleTool(IDM_TOOLBAR_OTHER_1
+
850 event
.GetId() - IDM_TOOLBAR_TOGGLERADIOBTN1
, true);
853 void MyFrame::OnBottomToolbar(wxCommandEvent
& WXUNUSED(event
) )
855 m_bottomToolbar
= !m_bottomToolbar
;
856 wxMenuBar
*menuBar
= GetMenuBar();
857 if( menuBar
->IsChecked( IDM_TOOLBAR_TOGGLETOOLBARORIENT
) )
858 menuBar
->Check( IDM_TOOLBAR_TOGGLETOOLBARORIENT
, false );
860 m_horzToolbar
= true;