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 1 to use wxToolBarSimple instead of the native one
37 #define USE_GENERIC_TBAR 0
39 // define this to use XPMs everywhere (by default, BMPs are used under Win)
40 // BMPs use less space, but aren't compiled into the executable on other platforms
42 #define USE_XPM_BITMAPS 0
44 #define USE_XPM_BITMAPS 1
48 #if !wxUSE_TOOLBAR_SIMPLE
49 #error wxToolBarSimple is not compiled in, set wxUSE_TOOLBAR_SIMPLE \
50 to 1 in setup.h and recompile the library.
52 #include "wx/tbarsmpl.h"
54 #endif // USE_GENERIC_TBAR
56 #if USE_XPM_BITMAPS && defined(__WXMSW__) && !wxUSE_XPM_IN_MSW
57 #error You need to enable XPM support to use XPM bitmaps with toolbar!
58 #endif // USE_XPM_BITMAPS
60 // ----------------------------------------------------------------------------
62 // ----------------------------------------------------------------------------
64 #if !defined(__WXMSW__) && !defined(__WXPM__)
65 #include "mondrian.xpm"
69 #include "bitmaps/new.xpm"
70 #include "bitmaps/open.xpm"
71 #include "bitmaps/save.xpm"
72 #include "bitmaps/copy.xpm"
73 #include "bitmaps/cut.xpm"
74 #include "bitmaps/preview.xpm" // paste XPM
75 #include "bitmaps/print.xpm"
76 #include "bitmaps/help.xpm"
77 #endif // USE_XPM_BITMAPS
79 // ----------------------------------------------------------------------------
81 // ----------------------------------------------------------------------------
83 // Define a new application
84 class MyApp
: public wxApp
91 class MyFrame
: public wxFrame
94 MyFrame(wxFrame
*parent
,
95 wxWindowID id
= wxID_ANY
,
96 const wxString
& title
= _T("wxToolBar Sample"),
97 const wxPoint
& pos
= wxDefaultPosition
,
98 const wxSize
& size
= wxDefaultSize
,
99 long style
= wxDEFAULT_FRAME_STYLE
|wxCLIP_CHILDREN
|wxNO_FULL_REPAINT_ON_RESIZE
);
101 void RecreateToolbar();
103 void OnQuit(wxCommandEvent
& event
);
104 void OnAbout(wxCommandEvent
& event
);
106 void OnSize(wxSizeEvent
& event
);
108 void OnToggleToolbar(wxCommandEvent
& event
);
109 void OnToggleAnotherToolbar(wxCommandEvent
& event
);
110 void OnToggleHorizontalText(wxCommandEvent
& WXUNUSED(event
));
112 void OnToggleToolbarSize(wxCommandEvent
& event
);
113 void OnToggleToolbarOrient(wxCommandEvent
& event
);
114 void OnToggleToolbarRows(wxCommandEvent
& event
);
115 void OnToggleTooltips(wxCommandEvent
& event
);
116 void OnToggleCustomDisabled(wxCommandEvent
& event
);
118 void OnEnablePrint(wxCommandEvent
& WXUNUSED(event
)) { DoEnablePrint(); }
119 void OnDeletePrint(wxCommandEvent
& WXUNUSED(event
)) { DoDeletePrint(); }
120 void OnInsertPrint(wxCommandEvent
& event
);
121 void OnChangeToolTip(wxCommandEvent
& event
);
122 void OnToggleHelp(wxCommandEvent
& WXUNUSED(event
)) { DoToggleHelp(); }
123 void OnToggleRadioBtn(wxCommandEvent
& event
);
125 void OnToolbarStyle(wxCommandEvent
& event
);
126 void OnToolbarCustomBitmap(wxCommandEvent
& event
);
128 void OnToolLeftClick(wxCommandEvent
& event
);
129 void OnToolRightClick(wxCommandEvent
& event
);
130 void OnToolEnter(wxCommandEvent
& event
);
132 void OnCombo(wxCommandEvent
& event
);
134 void OnUpdateCopyAndCut(wxUpdateUIEvent
& event
);
135 void OnUpdateToggleHorzText(wxUpdateUIEvent
& event
);
136 void OnUpdateToggleRadioBtn(wxUpdateUIEvent
& event
)
137 { event
.Enable( m_tbar
!= NULL
); }
140 virtual wxToolBar
*OnCreateToolBar(long style
,
142 const wxString
& name
);
143 #endif // USE_GENERIC_TBAR
146 void DoEnablePrint();
147 void DoDeletePrint();
150 void LayoutChildren();
157 size_t m_rows
; // 1 or 2 only
159 // the number of print buttons we have (they're added/removed dynamically)
162 wxTextCtrl
*m_textWindow
;
166 // the path to the custom bitmap for the test toolbar tool
169 DECLARE_EVENT_TABLE()
172 // ----------------------------------------------------------------------------
174 // ----------------------------------------------------------------------------
176 const int ID_TOOLBAR
= 500;
178 static const long TOOLBAR_STYLE
= wxTB_FLAT
| wxTB_DOCKABLE
| wxTB_TEXT
;
182 IDM_TOOLBAR_TOGGLETOOLBARSIZE
= 200,
183 IDM_TOOLBAR_TOGGLETOOLBARORIENT
,
184 IDM_TOOLBAR_TOGGLETOOLBARROWS
,
185 IDM_TOOLBAR_TOGGLETOOLTIPS
,
186 IDM_TOOLBAR_TOGGLECUSTOMDISABLED
,
187 IDM_TOOLBAR_ENABLEPRINT
,
188 IDM_TOOLBAR_DELETEPRINT
,
189 IDM_TOOLBAR_INSERTPRINT
,
190 IDM_TOOLBAR_TOGGLEHELP
,
191 IDM_TOOLBAR_TOGGLERADIOBTN1
,
192 IDM_TOOLBAR_TOGGLERADIOBTN2
,
193 IDM_TOOLBAR_TOGGLERADIOBTN3
,
194 IDM_TOOLBAR_TOGGLE_TOOLBAR
,
195 IDM_TOOLBAR_TOGGLE_HORIZONTAL_TEXT
,
196 IDM_TOOLBAR_TOGGLE_ANOTHER_TOOLBAR
,
197 IDM_TOOLBAR_CHANGE_TOOLTIP
,
198 IDM_TOOLBAR_SHOW_TEXT
,
199 IDM_TOOLBAR_SHOW_ICONS
,
200 IDM_TOOLBAR_SHOW_BOTH
,
201 IDM_TOOLBAR_CUSTOM_PATH
,
210 // ----------------------------------------------------------------------------
212 // ----------------------------------------------------------------------------
214 // Notice that wxID_HELP will be processed for the 'About' menu and the toolbar
217 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
218 EVT_SIZE(MyFrame::OnSize
)
220 EVT_MENU(wxID_EXIT
, MyFrame::OnQuit
)
221 EVT_MENU(wxID_HELP
, MyFrame::OnAbout
)
223 EVT_MENU(IDM_TOOLBAR_TOGGLE_TOOLBAR
, MyFrame::OnToggleToolbar
)
224 EVT_MENU(IDM_TOOLBAR_TOGGLE_ANOTHER_TOOLBAR
, MyFrame::OnToggleAnotherToolbar
)
225 EVT_MENU(IDM_TOOLBAR_TOGGLE_HORIZONTAL_TEXT
, MyFrame::OnToggleHorizontalText
)
227 EVT_MENU(IDM_TOOLBAR_TOGGLETOOLBARSIZE
, MyFrame::OnToggleToolbarSize
)
228 EVT_MENU(IDM_TOOLBAR_TOGGLETOOLBARORIENT
, MyFrame::OnToggleToolbarOrient
)
229 EVT_MENU(IDM_TOOLBAR_TOGGLETOOLBARROWS
, MyFrame::OnToggleToolbarRows
)
230 EVT_MENU(IDM_TOOLBAR_TOGGLETOOLTIPS
, MyFrame::OnToggleTooltips
)
231 EVT_MENU(IDM_TOOLBAR_TOGGLECUSTOMDISABLED
, MyFrame::OnToggleCustomDisabled
)
233 EVT_MENU(IDM_TOOLBAR_ENABLEPRINT
, MyFrame::OnEnablePrint
)
234 EVT_MENU(IDM_TOOLBAR_DELETEPRINT
, MyFrame::OnDeletePrint
)
235 EVT_MENU(IDM_TOOLBAR_INSERTPRINT
, MyFrame::OnInsertPrint
)
236 EVT_MENU(IDM_TOOLBAR_TOGGLEHELP
, MyFrame::OnToggleHelp
)
237 EVT_MENU_RANGE(IDM_TOOLBAR_TOGGLERADIOBTN1
, IDM_TOOLBAR_TOGGLERADIOBTN3
,
238 MyFrame::OnToggleRadioBtn
)
239 EVT_MENU(IDM_TOOLBAR_CHANGE_TOOLTIP
, MyFrame::OnChangeToolTip
)
241 EVT_MENU_RANGE(IDM_TOOLBAR_SHOW_TEXT
, IDM_TOOLBAR_SHOW_BOTH
,
242 MyFrame::OnToolbarStyle
)
244 EVT_MENU(IDM_TOOLBAR_CUSTOM_PATH
, MyFrame::OnToolbarCustomBitmap
)
246 EVT_MENU(wxID_ANY
, MyFrame::OnToolLeftClick
)
248 EVT_COMBOBOX(ID_COMBO
, MyFrame::OnCombo
)
250 EVT_TOOL_ENTER(ID_TOOLBAR
, MyFrame::OnToolEnter
)
251 EVT_TOOL_RCLICKED(wxID_ANY
, MyFrame::OnToolRightClick
)
253 EVT_UPDATE_UI(wxID_COPY
, MyFrame::OnUpdateCopyAndCut
)
254 EVT_UPDATE_UI(wxID_CUT
, MyFrame::OnUpdateCopyAndCut
)
256 EVT_UPDATE_UI_RANGE(IDM_TOOLBAR_TOGGLERADIOBTN1
,
257 IDM_TOOLBAR_TOGGLERADIOBTN3
,
258 MyFrame::OnUpdateToggleRadioBtn
)
259 EVT_UPDATE_UI(IDM_TOOLBAR_TOGGLE_HORIZONTAL_TEXT
,
260 MyFrame::OnUpdateToggleHorzText
)
263 // ============================================================================
265 // ============================================================================
267 // ----------------------------------------------------------------------------
269 // ----------------------------------------------------------------------------
273 // The `main program' equivalent, creating the windows and returning the
277 // Create the main frame window
278 MyFrame
* frame
= new MyFrame((wxFrame
*) NULL
, wxID_ANY
,
279 _T("wxToolBar Sample"),
280 wxPoint(100, 100), wxSize(550, 300));
285 frame
->SetStatusText(_T("Hello, wxWidgets"));
288 wxInitAllImageHandlers();
295 void MyFrame::RecreateToolbar()
298 // On Windows CE, we should not delete the
299 // previous toolbar in case it contains the menubar.
300 // We'll try to accommodate this usage in due course.
301 wxToolBar
* toolBar
= CreateToolBar();
303 // delete and recreate the toolbar
304 wxToolBarBase
*toolBar
= GetToolBar();
305 long style
= toolBar
? toolBar
->GetWindowStyle() : TOOLBAR_STYLE
;
311 style
&= ~(wxTB_HORIZONTAL
| wxTB_VERTICAL
| wxTB_HORZ_LAYOUT
);
312 style
|= m_horzToolbar
? wxTB_HORIZONTAL
: wxTB_VERTICAL
;
314 if ( m_showTooltips
)
315 style
&= ~wxTB_NO_TOOLTIPS
;
317 style
|= wxTB_NO_TOOLTIPS
;
319 if ( style
& wxTB_TEXT
&& !(style
& wxTB_NOICONS
) && m_horzText
)
320 style
|= wxTB_HORZ_LAYOUT
;
322 toolBar
= CreateToolBar(style
, ID_TOOLBAR
);
339 wxBitmap toolBarBitmaps
[Tool_Max
];
342 #define INIT_TOOL_BMP(bmp) \
343 toolBarBitmaps[Tool_##bmp] = wxBitmap(bmp##_xpm)
344 #else // !USE_XPM_BITMAPS
345 #define INIT_TOOL_BMP(bmp) \
346 toolBarBitmaps[Tool_##bmp] = wxBITMAP(bmp)
347 #endif // USE_XPM_BITMAPS/!USE_XPM_BITMAPS
354 INIT_TOOL_BMP(paste
);
355 INIT_TOOL_BMP(print
);
358 int w
= toolBarBitmaps
[Tool_new
].GetWidth(),
359 h
= toolBarBitmaps
[Tool_new
].GetHeight();
361 if ( !m_smallToolbar
)
366 for ( size_t n
= Tool_new
; n
< WXSIZEOF(toolBarBitmaps
); n
++ )
369 wxBitmap(toolBarBitmaps
[n
].ConvertToImage().Scale(w
, h
));
373 toolBar
->SetToolBitmapSize(wxSize(w
, h
));
375 toolBar
->AddTool(wxID_NEW
, _T("New"), toolBarBitmaps
[Tool_new
], _T("New file"));
376 toolBar
->AddTool(wxID_OPEN
, _T("Open"), toolBarBitmaps
[Tool_open
], _T("Open file"));
378 // the generic toolbar doesn't really support this
379 #if (wxUSE_TOOLBAR_NATIVE && !USE_GENERIC_TBAR) && !defined(__WXX11__) || defined(__WXUNIVERSAL__)
380 // adding a combo to a vertical toolbar is not very smart
383 wxComboBox
*combo
= new wxComboBox(toolBar
, ID_COMBO
, wxEmptyString
, wxDefaultPosition
, wxSize(200,wxDefaultCoord
) );
384 combo
->Append(_T("This"));
385 combo
->Append(_T("is a"));
386 combo
->Append(_T("combobox"));
387 combo
->Append(_T("in a"));
388 combo
->Append(_T("toolbar"));
389 toolBar
->AddControl(combo
);
391 #endif // toolbars which don't support controls
393 toolBar
->AddTool(wxID_SAVE
, _T("Save"), toolBarBitmaps
[Tool_save
], _T("Toggle button 1"), wxITEM_CHECK
);
394 toolBar
->AddTool(wxID_COPY
, _T("Copy"), toolBarBitmaps
[Tool_copy
], _T("Toggle button 2"), wxITEM_CHECK
);
395 toolBar
->AddTool(wxID_CUT
, _T("Cut"), toolBarBitmaps
[Tool_cut
], _T("Toggle/Untoggle help button"));
396 toolBar
->AddTool(wxID_PASTE
, _T("Paste"), toolBarBitmaps
[Tool_paste
], _T("Paste"));
398 if ( m_useCustomDisabled
)
400 wxBitmap
bmpDisabled(w
, h
);
403 dc
.SelectObject(bmpDisabled
);
404 dc
.DrawBitmap(toolBarBitmaps
[Tool_print
], 0, 0);
406 wxPen
pen(*wxRED
, 5);
408 dc
.DrawLine(0, 0, w
, h
);
411 toolBar
->AddTool(wxID_PRINT
, _T("Print"), toolBarBitmaps
[Tool_print
],
416 toolBar
->AddTool(wxID_PRINT
, _T("Print"), toolBarBitmaps
[Tool_print
],
417 _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."));
420 toolBar
->AddSeparator();
421 toolBar
->AddTool(wxID_HELP
, _T("Help"), toolBarBitmaps
[Tool_help
], _T("Help button"), wxITEM_CHECK
);
423 if ( !m_pathBmp
.empty() )
425 // create a tool with a custom bitmap for testing
426 wxImage
img(m_pathBmp
);
429 if ( img
.GetWidth() > w
&& img
.GetHeight() > h
)
430 img
= img
.GetSubImage(wxRect(0, 0, w
, h
));
432 toolBar
->AddSeparator();
433 toolBar
->AddTool(wxID_ANY
, _T("Custom"), img
);
437 // after adding the buttons to the toolbar, must call Realize() to reflect
441 toolBar
->SetRows(m_horzToolbar
? m_rows
: 10 / m_rows
);
444 // ----------------------------------------------------------------------------
446 // ----------------------------------------------------------------------------
448 // Define my frame constructor
449 MyFrame::MyFrame(wxFrame
* parent
,
451 const wxString
& title
,
455 : wxFrame(parent
, id
, title
, pos
, size
, style
)
459 m_smallToolbar
= true;
460 m_horzToolbar
= true;
462 m_useCustomDisabled
= false;
463 m_showTooltips
= true;
469 // Give it a status line
474 SetIcon(wxICON(mondrian
));
477 wxMenu
*tbarMenu
= new wxMenu
;
478 tbarMenu
->AppendCheckItem(IDM_TOOLBAR_TOGGLE_TOOLBAR
,
479 _T("Toggle &toolbar\tCtrl-Z"),
480 _T("Show or hide the toolbar"));
482 tbarMenu
->AppendCheckItem(IDM_TOOLBAR_TOGGLE_ANOTHER_TOOLBAR
,
483 _T("Toggle &another toolbar\tCtrl-A"),
484 _T("Show/hide another test toolbar"));
486 tbarMenu
->AppendCheckItem(IDM_TOOLBAR_TOGGLE_HORIZONTAL_TEXT
,
487 _T("Toggle hori&zontal text\tCtrl-H"),
488 _T("Show text under/alongside the icon"));
490 tbarMenu
->AppendCheckItem(IDM_TOOLBAR_TOGGLETOOLBARSIZE
,
491 _T("&Toggle toolbar size\tCtrl-S"),
492 _T("Toggle between big/small toolbar"));
494 tbarMenu
->AppendCheckItem(IDM_TOOLBAR_TOGGLETOOLBARORIENT
,
495 _T("Toggle toolbar &orientation\tCtrl-O"),
496 _T("Toggle toolbar orientation"));
498 tbarMenu
->AppendCheckItem(IDM_TOOLBAR_TOGGLETOOLBARROWS
,
499 _T("Toggle number of &rows\tCtrl-R"),
500 _T("Toggle number of toolbar rows between 1 and 2"));
502 tbarMenu
->AppendCheckItem(IDM_TOOLBAR_TOGGLETOOLTIPS
,
503 _T("Show &tooltips\tCtrl-L"),
504 _T("Show tooltips for the toolbar tools"));
506 tbarMenu
->AppendCheckItem(IDM_TOOLBAR_TOGGLECUSTOMDISABLED
,
507 _T("Use c&ustom disabled images\tCtrl-U"),
508 _T("Switch between using system-generated and custom disabled images"));
511 tbarMenu
->AppendSeparator();
513 tbarMenu
->Append(IDM_TOOLBAR_ENABLEPRINT
, _T("&Enable print button\tCtrl-E"));
514 tbarMenu
->Append(IDM_TOOLBAR_DELETEPRINT
, _T("&Delete print button\tCtrl-D"));
515 tbarMenu
->Append(IDM_TOOLBAR_INSERTPRINT
, _T("&Insert print button\tCtrl-I"));
516 tbarMenu
->Append(IDM_TOOLBAR_TOGGLEHELP
, _T("Toggle &help button\tCtrl-T"));
517 tbarMenu
->AppendSeparator();
518 tbarMenu
->Append(IDM_TOOLBAR_TOGGLERADIOBTN1
, _T("Toggle &1st radio button\tCtrl-1"));
519 tbarMenu
->Append(IDM_TOOLBAR_TOGGLERADIOBTN2
, _T("Toggle &2nd radio button\tCtrl-2"));
520 tbarMenu
->Append(IDM_TOOLBAR_TOGGLERADIOBTN3
, _T("Toggle &3rd radio button\tCtrl-3"));
521 tbarMenu
->AppendSeparator();
522 tbarMenu
->Append(IDM_TOOLBAR_CHANGE_TOOLTIP
, _T("Change tool tip"));
523 tbarMenu
->AppendSeparator();
524 tbarMenu
->AppendRadioItem(IDM_TOOLBAR_SHOW_TEXT
, _T("Show &text\tCtrl-Alt-T"));
525 tbarMenu
->AppendRadioItem(IDM_TOOLBAR_SHOW_ICONS
, _T("Show &icons\tCtrl-Alt-I"));
526 tbarMenu
->AppendRadioItem(IDM_TOOLBAR_SHOW_BOTH
, _T("Show &both\tCtrl-Alt-B"));
527 tbarMenu
->AppendSeparator();
528 tbarMenu
->Append(IDM_TOOLBAR_CUSTOM_PATH
, _T("Custom &bitmap...\tCtrl-B"));
530 wxMenu
*fileMenu
= new wxMenu
;
531 fileMenu
->Append(wxID_EXIT
, _T("E&xit\tAlt-X"), _T("Quit toolbar sample") );
533 wxMenu
*helpMenu
= new wxMenu
;
534 helpMenu
->Append(wxID_HELP
, _T("&About"), _T("About toolbar sample"));
536 wxMenuBar
* menuBar
= new wxMenuBar( wxMB_DOCKABLE
);
538 menuBar
->Append(fileMenu
, _T("&File"));
539 menuBar
->Append(tbarMenu
, _T("&Toolbar"));
540 menuBar
->Append(helpMenu
, _T("&Help"));
542 // Associate the menu bar with the frame
545 menuBar
->Check(IDM_TOOLBAR_SHOW_BOTH
, true);
546 menuBar
->Check(IDM_TOOLBAR_TOGGLETOOLTIPS
, true);
548 // Create the toolbar
551 m_textWindow
= new wxTextCtrl(this, wxID_ANY
, wxEmptyString
, wxPoint(0, 0), wxDefaultSize
, wxTE_MULTILINE
);
556 wxToolBar
* MyFrame::OnCreateToolBar(long style
,
558 const wxString
& name
)
560 return (wxToolBar
*)new wxToolBarSimple(this, id
,
561 wxDefaultPosition
, wxDefaultSize
,
565 #endif // USE_GENERIC_TBAR
567 void MyFrame::LayoutChildren()
569 wxSize size
= GetClientSize();
574 m_tbar
->SetSize(0, 0, wxDefaultCoord
, size
.y
);
576 offset
= m_tbar
->GetSize().x
;
583 m_textWindow
->SetSize(offset
, 0, size
.x
- offset
, size
.y
);
586 void MyFrame::OnSize(wxSizeEvent
& event
)
598 void MyFrame::OnToggleToolbar(wxCommandEvent
& WXUNUSED(event
))
600 wxToolBar
*tbar
= GetToolBar();
614 void MyFrame::OnToggleHorizontalText(wxCommandEvent
& WXUNUSED(event
))
616 m_horzText
= !m_horzText
;
621 void MyFrame::OnToggleAnotherToolbar(wxCommandEvent
& WXUNUSED(event
))
630 long style
= GetToolBar() ? GetToolBar()->GetWindowStyle()
632 style
&= ~wxTB_HORIZONTAL
;
633 style
|= wxTB_VERTICAL
;
635 m_tbar
= new wxToolBar(this, wxID_ANY
,
636 wxDefaultPosition
, wxDefaultSize
,
639 m_tbar
->SetMargins(4, 4);
641 m_tbar
->AddRadioTool(IDM_TOOLBAR_OTHER_1
, _T("First"), wxBITMAP(new));
642 m_tbar
->AddRadioTool(IDM_TOOLBAR_OTHER_2
, _T("Second"), wxBITMAP(open
));
643 m_tbar
->AddRadioTool(IDM_TOOLBAR_OTHER_3
, _T("Third"), wxBITMAP(save
));
644 m_tbar
->AddSeparator();
645 m_tbar
->AddTool(wxID_HELP
, _T("Help"), wxBITMAP(help
));
653 void MyFrame::OnToggleToolbarSize(wxCommandEvent
& WXUNUSED(event
))
655 m_smallToolbar
= !m_smallToolbar
;
660 void MyFrame::OnToggleToolbarRows(wxCommandEvent
& WXUNUSED(event
))
662 // m_rows may be only 1 or 2
665 GetToolBar()->SetRows(m_horzToolbar
? m_rows
: 10 / m_rows
);
667 //RecreateToolbar(); -- this is unneeded
670 void MyFrame::OnToggleTooltips(wxCommandEvent
& WXUNUSED(event
))
672 m_showTooltips
= !m_showTooltips
;
677 void MyFrame::OnToggleCustomDisabled(wxCommandEvent
& WXUNUSED(event
))
679 m_useCustomDisabled
= !m_useCustomDisabled
;
684 void MyFrame::OnToggleToolbarOrient(wxCommandEvent
& WXUNUSED(event
))
686 m_horzToolbar
= !m_horzToolbar
;
691 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
696 void MyFrame::OnAbout(wxCommandEvent
& event
)
698 if ( event
.IsChecked() )
699 m_textWindow
->WriteText( _T("Help button down now.\n") );
701 m_textWindow
->WriteText( _T("Help button up now.\n") );
703 (void)wxMessageBox(_T("wxWidgets toolbar sample"), _T("About wxToolBar"));
706 void MyFrame::OnToolLeftClick(wxCommandEvent
& event
)
709 str
.Printf( _T("Clicked on tool %d\n"), event
.GetId());
710 m_textWindow
->WriteText( str
);
712 if (event
.GetId() == wxID_COPY
)
717 if (event
.GetId() == wxID_CUT
)
722 if (event
.GetId() == wxID_PRINT
)
728 void MyFrame::OnToolRightClick(wxCommandEvent
& event
)
730 m_textWindow
->AppendText(
731 wxString::Format(_T("Tool %d right clicked.\n"),
732 (int) event
.GetInt()));
735 void MyFrame::OnCombo(wxCommandEvent
& event
)
737 wxLogStatus(_T("Combobox string '%s' selected"), event
.GetString().c_str());
740 void MyFrame::DoEnablePrint()
745 wxToolBarBase
*tb
= GetToolBar();
746 tb
->EnableTool(wxID_PRINT
, !tb
->GetToolEnabled(wxID_PRINT
));
749 void MyFrame::DoDeletePrint()
754 wxToolBarBase
*tb
= GetToolBar();
755 tb
->DeleteTool( wxID_PRINT
);
760 void MyFrame::DoToggleHelp()
762 wxToolBarBase
*tb
= GetToolBar();
763 tb
->ToggleTool( wxID_HELP
, !tb
->GetToolState( wxID_HELP
) );
766 void MyFrame::OnUpdateCopyAndCut(wxUpdateUIEvent
& event
)
768 event
.Enable( m_textWindow
->CanCopy() );
771 void MyFrame::OnUpdateToggleHorzText(wxUpdateUIEvent
& event
)
773 wxToolBar
*tbar
= GetToolBar();
774 event
.Enable( tbar
&&
775 tbar
->HasFlag(wxTB_TEXT
) &&
776 !tbar
->HasFlag(wxTB_NOICONS
) );
779 void MyFrame::OnChangeToolTip(wxCommandEvent
& WXUNUSED(event
))
781 GetToolBar()->SetToolShortHelp(wxID_NEW
, _T("New toolbar button"));
784 void MyFrame::OnToolbarStyle(wxCommandEvent
& event
)
786 long style
= GetToolBar()->GetWindowStyle();
787 style
&= ~(wxTB_NOICONS
| wxTB_TEXT
);
789 switch ( event
.GetId() )
791 case IDM_TOOLBAR_SHOW_TEXT
:
792 style
|= wxTB_NOICONS
| wxTB_TEXT
;
795 case IDM_TOOLBAR_SHOW_ICONS
:
799 case IDM_TOOLBAR_SHOW_BOTH
:
803 GetToolBar()->SetWindowStyle(style
);
806 void MyFrame::OnToolbarCustomBitmap(wxCommandEvent
& WXUNUSED(event
))
808 m_pathBmp
= wxFileSelector(_T("Custom bitmap path"));
813 void MyFrame::OnInsertPrint(wxCommandEvent
& WXUNUSED(event
))
817 wxToolBarBase
*tb
= GetToolBar();
818 tb
->InsertTool(0, wxID_PRINT
, _T("New print"),
819 wxBITMAP(print
), wxNullBitmap
,
821 _T("Delete this tool"),
822 _T("This button was inserted into the toolbar"));
824 // must call Realize() after adding a new button
828 void MyFrame::OnToolEnter(wxCommandEvent
& event
)
831 if (event
.GetSelection() > -1)
834 str
.Printf(_T("This is tool number %d"), event
.GetSelection());
838 SetStatusText(wxEmptyString
);
841 #endif // wxUSE_STATUSBAR
844 void MyFrame::OnToggleRadioBtn(wxCommandEvent
& event
)
848 m_tbar
->ToggleTool(IDM_TOOLBAR_OTHER_1
+
849 event
.GetId() - IDM_TOOLBAR_TOGGLERADIOBTN1
, true);