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
75 // ----------------------------------------------------------------------------
77 // ----------------------------------------------------------------------------
79 // Define a new application
80 class MyApp
: public wxApp
87 class MyFrame
: public wxFrame
90 MyFrame(wxFrame
*parent
,
91 wxWindowID id
= wxID_ANY
,
92 const wxString
& title
= _T("wxToolBar Sample"),
93 const wxPoint
& pos
= wxDefaultPosition
,
94 const wxSize
& size
= wxDefaultSize
,
95 long style
= wxDEFAULT_FRAME_STYLE
|wxCLIP_CHILDREN
|wxNO_FULL_REPAINT_ON_RESIZE
);
97 void RecreateToolbar();
99 void OnQuit(wxCommandEvent
& event
);
100 void OnAbout(wxCommandEvent
& event
);
102 void OnSize(wxSizeEvent
& event
);
104 void OnToggleToolbar(wxCommandEvent
& event
);
105 void OnToggleAnotherToolbar(wxCommandEvent
& event
);
106 void OnToggleHorizontalText(wxCommandEvent
& WXUNUSED(event
));
108 void OnToggleToolbarSize(wxCommandEvent
& event
);
109 void OnChangeOrientation(wxCommandEvent
& event
);
110 void OnToggleToolbarRows(wxCommandEvent
& event
);
111 void OnToggleTooltips(wxCommandEvent
& event
);
112 void OnToggleCustomDisabled(wxCommandEvent
& event
);
114 void OnEnablePrint(wxCommandEvent
& WXUNUSED(event
)) { DoEnablePrint(); }
115 void OnDeletePrint(wxCommandEvent
& WXUNUSED(event
)) { DoDeletePrint(); }
116 void OnInsertPrint(wxCommandEvent
& event
);
117 void OnChangeToolTip(wxCommandEvent
& event
);
118 void OnToggleHelp(wxCommandEvent
& WXUNUSED(event
)) { DoToggleHelp(); }
119 void OnToggleRadioBtn(wxCommandEvent
& event
);
121 void OnToolbarStyle(wxCommandEvent
& event
);
122 void OnToolbarCustomBitmap(wxCommandEvent
& event
);
124 void OnToolLeftClick(wxCommandEvent
& event
);
125 void OnToolRightClick(wxCommandEvent
& event
);
127 void OnCombo(wxCommandEvent
& event
);
129 void OnUpdateCopyAndCut(wxUpdateUIEvent
& event
);
130 void OnUpdateToggleHorzText(wxUpdateUIEvent
& event
);
131 void OnUpdateToggleRadioBtn(wxUpdateUIEvent
& event
)
132 { event
.Enable( m_tbar
!= NULL
); }
135 void DoEnablePrint();
136 void DoDeletePrint();
139 void LayoutChildren();
145 size_t m_rows
; // 1 or 2 only
147 // the number of print buttons we have (they're added/removed dynamically)
150 // store toolbar position for future use
151 Positions m_toolbarPosition
;
153 wxTextCtrl
*m_textWindow
;
157 // the path to the custom bitmap for the test toolbar tool
160 DECLARE_EVENT_TABLE()
163 // ----------------------------------------------------------------------------
165 // ----------------------------------------------------------------------------
167 const int ID_TOOLBAR
= 500;
169 static const long TOOLBAR_STYLE
= wxTB_FLAT
| wxTB_DOCKABLE
| wxTB_TEXT
;
173 IDM_TOOLBAR_TOGGLETOOLBARSIZE
= 200,
174 IDM_TOOLBAR_TOGGLETOOLBARROWS
,
175 IDM_TOOLBAR_TOGGLETOOLTIPS
,
176 IDM_TOOLBAR_TOGGLECUSTOMDISABLED
,
177 IDM_TOOLBAR_ENABLEPRINT
,
178 IDM_TOOLBAR_DELETEPRINT
,
179 IDM_TOOLBAR_INSERTPRINT
,
180 IDM_TOOLBAR_TOGGLEHELP
,
181 IDM_TOOLBAR_TOGGLERADIOBTN1
,
182 IDM_TOOLBAR_TOGGLERADIOBTN2
,
183 IDM_TOOLBAR_TOGGLERADIOBTN3
,
184 IDM_TOOLBAR_TOGGLE_TOOLBAR
,
185 IDM_TOOLBAR_TOGGLE_HORIZONTAL_TEXT
,
186 IDM_TOOLBAR_TOGGLE_ANOTHER_TOOLBAR
,
187 IDM_TOOLBAR_CHANGE_TOOLTIP
,
188 IDM_TOOLBAR_SHOW_TEXT
,
189 IDM_TOOLBAR_SHOW_ICONS
,
190 IDM_TOOLBAR_SHOW_BOTH
,
191 IDM_TOOLBAR_CUSTOM_PATH
,
192 IDM_TOOLBAR_TOP_ORIENTATION
,
193 IDM_TOOLBAR_LEFT_ORIENTATION
,
194 IDM_TOOLBAR_BOTTOM_ORIENTATION
,
195 IDM_TOOLBAR_RIGHT_ORIENTATION
,
204 // ----------------------------------------------------------------------------
206 // ----------------------------------------------------------------------------
208 // Notice that wxID_HELP will be processed for the 'About' menu and the toolbar
211 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
212 EVT_SIZE(MyFrame::OnSize
)
214 EVT_MENU(wxID_EXIT
, MyFrame::OnQuit
)
215 EVT_MENU(wxID_HELP
, MyFrame::OnAbout
)
217 EVT_MENU(IDM_TOOLBAR_TOGGLE_TOOLBAR
, MyFrame::OnToggleToolbar
)
218 EVT_MENU(IDM_TOOLBAR_TOGGLE_ANOTHER_TOOLBAR
, MyFrame::OnToggleAnotherToolbar
)
219 EVT_MENU(IDM_TOOLBAR_TOGGLE_HORIZONTAL_TEXT
, MyFrame::OnToggleHorizontalText
)
221 EVT_MENU_RANGE(IDM_TOOLBAR_TOP_ORIENTATION
, IDM_TOOLBAR_RIGHT_ORIENTATION
, MyFrame::OnChangeOrientation
)
222 EVT_MENU(IDM_TOOLBAR_TOGGLETOOLBARSIZE
, MyFrame::OnToggleToolbarSize
)
223 EVT_MENU(IDM_TOOLBAR_TOGGLETOOLBARROWS
, MyFrame::OnToggleToolbarRows
)
224 EVT_MENU(IDM_TOOLBAR_TOGGLETOOLTIPS
, MyFrame::OnToggleTooltips
)
225 EVT_MENU(IDM_TOOLBAR_TOGGLECUSTOMDISABLED
, MyFrame::OnToggleCustomDisabled
)
227 EVT_MENU(IDM_TOOLBAR_ENABLEPRINT
, MyFrame::OnEnablePrint
)
228 EVT_MENU(IDM_TOOLBAR_DELETEPRINT
, MyFrame::OnDeletePrint
)
229 EVT_MENU(IDM_TOOLBAR_INSERTPRINT
, MyFrame::OnInsertPrint
)
230 EVT_MENU(IDM_TOOLBAR_TOGGLEHELP
, MyFrame::OnToggleHelp
)
231 EVT_MENU_RANGE(IDM_TOOLBAR_TOGGLERADIOBTN1
, IDM_TOOLBAR_TOGGLERADIOBTN3
,
232 MyFrame::OnToggleRadioBtn
)
233 EVT_MENU(IDM_TOOLBAR_CHANGE_TOOLTIP
, MyFrame::OnChangeToolTip
)
235 EVT_MENU_RANGE(IDM_TOOLBAR_SHOW_TEXT
, IDM_TOOLBAR_SHOW_BOTH
,
236 MyFrame::OnToolbarStyle
)
238 EVT_MENU(IDM_TOOLBAR_CUSTOM_PATH
, MyFrame::OnToolbarCustomBitmap
)
240 EVT_MENU(wxID_ANY
, MyFrame::OnToolLeftClick
)
242 EVT_COMBOBOX(ID_COMBO
, MyFrame::OnCombo
)
244 EVT_TOOL_RCLICKED(wxID_ANY
, MyFrame::OnToolRightClick
)
246 EVT_UPDATE_UI(wxID_COPY
, MyFrame::OnUpdateCopyAndCut
)
247 EVT_UPDATE_UI(wxID_CUT
, MyFrame::OnUpdateCopyAndCut
)
249 EVT_UPDATE_UI_RANGE(IDM_TOOLBAR_TOGGLERADIOBTN1
,
250 IDM_TOOLBAR_TOGGLERADIOBTN3
,
251 MyFrame::OnUpdateToggleRadioBtn
)
252 EVT_UPDATE_UI(IDM_TOOLBAR_TOGGLE_HORIZONTAL_TEXT
,
253 MyFrame::OnUpdateToggleHorzText
)
256 // ============================================================================
258 // ============================================================================
260 // ----------------------------------------------------------------------------
262 // ----------------------------------------------------------------------------
266 // The `main program' equivalent, creating the windows and returning the
270 // Create the main frame window
271 MyFrame
* frame
= new MyFrame((wxFrame
*) NULL
, wxID_ANY
,
272 _T("wxToolBar Sample"),
273 wxPoint(100, 100), wxSize(550, 300));
278 frame
->SetStatusText(_T("Hello, wxWidgets"));
281 wxInitAllImageHandlers();
288 void MyFrame::RecreateToolbar()
291 // On Windows CE, we should not delete the
292 // previous toolbar in case it contains the menubar.
293 // We'll try to accommodate this usage in due course.
294 wxToolBar
* toolBar
= CreateToolBar();
296 // delete and recreate the toolbar
297 wxToolBarBase
*toolBar
= GetToolBar();
298 long style
= toolBar
? toolBar
->GetWindowStyle() : TOOLBAR_STYLE
;
304 style
&= ~(wxTB_HORIZONTAL
| wxTB_VERTICAL
| wxTB_BOTTOM
| wxTB_RIGHT
| wxTB_HORZ_LAYOUT
);
305 switch( m_toolbarPosition
)
317 style
|= wxTB_BOTTOM
;
321 if ( m_showTooltips
)
322 style
&= ~wxTB_NO_TOOLTIPS
;
324 style
|= wxTB_NO_TOOLTIPS
;
326 if ( style
& wxTB_TEXT
&& !(style
& wxTB_NOICONS
) && m_horzText
)
327 style
|= wxTB_HORZ_LAYOUT
;
329 toolBar
= CreateToolBar(style
, ID_TOOLBAR
);
346 wxBitmap toolBarBitmaps
[Tool_Max
];
349 #define INIT_TOOL_BMP(bmp) \
350 toolBarBitmaps[Tool_##bmp] = wxBitmap(bmp##_xpm)
351 #else // !USE_XPM_BITMAPS
352 #define INIT_TOOL_BMP(bmp) \
353 toolBarBitmaps[Tool_##bmp] = wxBITMAP(bmp)
354 #endif // USE_XPM_BITMAPS/!USE_XPM_BITMAPS
361 INIT_TOOL_BMP(paste
);
362 INIT_TOOL_BMP(print
);
365 int w
= toolBarBitmaps
[Tool_new
].GetWidth(),
366 h
= toolBarBitmaps
[Tool_new
].GetHeight();
368 if ( !m_smallToolbar
)
373 for ( size_t n
= Tool_new
; n
< WXSIZEOF(toolBarBitmaps
); n
++ )
376 wxBitmap(toolBarBitmaps
[n
].ConvertToImage().Scale(w
, h
));
380 toolBar
->SetToolBitmapSize(wxSize(w
, h
));
382 toolBar
->AddTool(wxID_NEW
, _T("New"),
383 toolBarBitmaps
[Tool_new
], wxNullBitmap
, wxITEM_NORMAL
,
384 _T("New file"), _T("This is help for new file tool"));
385 toolBar
->AddTool(wxID_OPEN
, _T("Open"),
386 toolBarBitmaps
[Tool_open
], wxNullBitmap
, wxITEM_NORMAL
,
387 _T("Open file"), _T("This is help for open file tool"));
389 // the generic toolbar doesn't really support this
390 #if wxUSE_TOOLBAR_NATIVE && !defined(__WXX11__) || defined(__WXUNIVERSAL__)
391 // adding a combo to a vertical toolbar is not very smart
392 if ( !( toolBar
->IsVertical() ) )
394 wxComboBox
*combo
= new wxComboBox(toolBar
, ID_COMBO
, wxEmptyString
, wxDefaultPosition
, wxSize(200,wxDefaultCoord
) );
395 combo
->Append(_T("This"));
396 combo
->Append(_T("is a"));
397 combo
->Append(_T("combobox"));
398 combo
->Append(_T("in a"));
399 combo
->Append(_T("toolbar"));
400 toolBar
->AddControl(combo
);
402 //wxSpinCtrl *spin = new wxSpinCtrl( toolBar, ID_SPIN, wxT("0"), wxDefaultPosition, wxSize(80,wxDefaultCoord), 0, 100, 0 );
403 //toolBar->AddControl( spin );
405 #endif // toolbars which don't support controls
407 toolBar
->AddTool(wxID_SAVE
, _T("Save"), toolBarBitmaps
[Tool_save
], _T("Toggle button 1"), wxITEM_CHECK
);
408 toolBar
->AddTool(wxID_COPY
, _T("Copy"), toolBarBitmaps
[Tool_copy
], _T("Toggle button 2"), wxITEM_CHECK
);
409 toolBar
->AddTool(wxID_CUT
, _T("Cut"), toolBarBitmaps
[Tool_cut
], _T("Toggle/Untoggle help button"));
410 toolBar
->AddTool(wxID_PASTE
, _T("Paste"), toolBarBitmaps
[Tool_paste
], _T("Paste"));
412 if ( m_useCustomDisabled
)
414 wxBitmap
bmpDisabled(w
, h
);
417 dc
.SelectObject(bmpDisabled
);
418 dc
.DrawBitmap(toolBarBitmaps
[Tool_print
], 0, 0);
420 wxPen
pen(*wxRED
, 5);
422 dc
.DrawLine(0, 0, w
, h
);
425 toolBar
->AddTool(wxID_PRINT
, _T("Print"), toolBarBitmaps
[Tool_print
],
430 toolBar
->AddTool(wxID_PRINT
, _T("Print"), toolBarBitmaps
[Tool_print
],
431 _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."));
434 toolBar
->AddSeparator();
435 toolBar
->AddTool(wxID_HELP
, _T("Help"), toolBarBitmaps
[Tool_help
], _T("Help button"), wxITEM_CHECK
);
437 if ( !m_pathBmp
.empty() )
439 // create a tool with a custom bitmap for testing
440 wxImage
img(m_pathBmp
);
443 if ( img
.GetWidth() > w
&& img
.GetHeight() > h
)
444 img
= img
.GetSubImage(wxRect(0, 0, w
, h
));
446 toolBar
->AddSeparator();
447 toolBar
->AddTool(wxID_ANY
, _T("Custom"), img
);
451 // after adding the buttons to the toolbar, must call Realize() to reflect
455 toolBar
->SetRows(!(toolBar
->IsVertical()) ? m_rows
: 10 / m_rows
);
458 // ----------------------------------------------------------------------------
460 // ----------------------------------------------------------------------------
462 // Define my frame constructor
463 MyFrame::MyFrame(wxFrame
* parent
,
465 const wxString
& title
,
469 : wxFrame(parent
, id
, title
, pos
, size
, style
)
473 m_smallToolbar
= true;
475 m_useCustomDisabled
= false;
476 m_showTooltips
= true;
482 // Give it a status line
487 SetIcon(wxICON(mondrian
));
490 wxMenu
*tbarMenu
= new wxMenu
;
491 tbarMenu
->AppendCheckItem(IDM_TOOLBAR_TOGGLE_TOOLBAR
,
492 _T("Toggle &toolbar\tCtrl-Z"),
493 _T("Show or hide the toolbar"));
495 tbarMenu
->AppendCheckItem(IDM_TOOLBAR_TOGGLE_ANOTHER_TOOLBAR
,
496 _T("Toggle &another toolbar\tCtrl-A"),
497 _T("Show/hide another test toolbar"));
499 tbarMenu
->AppendCheckItem(IDM_TOOLBAR_TOGGLE_HORIZONTAL_TEXT
,
500 _T("Toggle hori&zontal text\tCtrl-H"),
501 _T("Show text under/alongside the icon"));
503 tbarMenu
->AppendCheckItem(IDM_TOOLBAR_TOGGLETOOLBARSIZE
,
504 _T("&Toggle toolbar size\tCtrl-S"),
505 _T("Toggle between big/small toolbar"));
507 tbarMenu
->AppendCheckItem(IDM_TOOLBAR_TOGGLETOOLBARROWS
,
508 _T("Toggle number of &rows\tCtrl-R"),
509 _T("Toggle number of toolbar rows between 1 and 2"));
511 tbarMenu
->AppendCheckItem(IDM_TOOLBAR_TOGGLETOOLTIPS
,
512 _T("Show &tooltips\tCtrl-L"),
513 _T("Show tooltips for the toolbar tools"));
515 tbarMenu
->AppendCheckItem(IDM_TOOLBAR_TOGGLECUSTOMDISABLED
,
516 _T("Use c&ustom disabled images\tCtrl-U"),
517 _T("Switch between using system-generated and custom disabled images"));
520 tbarMenu
->AppendSeparator();
521 tbarMenu
->AppendRadioItem(IDM_TOOLBAR_TOP_ORIENTATION
,
522 _T("Set toolbar at the top of the window"),
523 _T("Set toolbar at the top of the window"));
524 tbarMenu
->AppendRadioItem(IDM_TOOLBAR_LEFT_ORIENTATION
,
525 _T("Set toolbar at the left of the window"),
526 _T("Set toolbar at the left of the window"));
527 tbarMenu
->AppendRadioItem(IDM_TOOLBAR_BOTTOM_ORIENTATION
,
528 _T("Set toolbar at the bottom of the window"),
529 _T("Set toolbar at the bottom of the window"));
530 tbarMenu
->AppendRadioItem(IDM_TOOLBAR_RIGHT_ORIENTATION
,
531 _T("Set toolbar at the right edge of the window"),
532 _T("Set toolbar at the right edge of the window"));
533 tbarMenu
->AppendSeparator();
535 tbarMenu
->Append(IDM_TOOLBAR_ENABLEPRINT
, _T("&Enable print button\tCtrl-E"));
536 tbarMenu
->Append(IDM_TOOLBAR_DELETEPRINT
, _T("&Delete print button\tCtrl-D"));
537 tbarMenu
->Append(IDM_TOOLBAR_INSERTPRINT
, _T("&Insert print button\tCtrl-I"));
538 tbarMenu
->Append(IDM_TOOLBAR_TOGGLEHELP
, _T("Toggle &help button\tCtrl-T"));
539 tbarMenu
->AppendSeparator();
540 tbarMenu
->Append(IDM_TOOLBAR_TOGGLERADIOBTN1
, _T("Toggle &1st radio button\tCtrl-1"));
541 tbarMenu
->Append(IDM_TOOLBAR_TOGGLERADIOBTN2
, _T("Toggle &2nd radio button\tCtrl-2"));
542 tbarMenu
->Append(IDM_TOOLBAR_TOGGLERADIOBTN3
, _T("Toggle &3rd radio button\tCtrl-3"));
543 tbarMenu
->AppendSeparator();
544 tbarMenu
->Append(IDM_TOOLBAR_CHANGE_TOOLTIP
, _T("Change tool tip"));
545 tbarMenu
->AppendSeparator();
546 tbarMenu
->AppendRadioItem(IDM_TOOLBAR_SHOW_TEXT
, _T("Show &text\tCtrl-Alt-T"));
547 tbarMenu
->AppendRadioItem(IDM_TOOLBAR_SHOW_ICONS
, _T("Show &icons\tCtrl-Alt-I"));
548 tbarMenu
->AppendRadioItem(IDM_TOOLBAR_SHOW_BOTH
, _T("Show &both\tCtrl-Alt-B"));
549 tbarMenu
->AppendSeparator();
550 tbarMenu
->Append(IDM_TOOLBAR_CUSTOM_PATH
, _T("Custom &bitmap...\tCtrl-B"));
552 wxMenu
*fileMenu
= new wxMenu
;
553 fileMenu
->Append(wxID_EXIT
, _T("E&xit\tAlt-X"), _T("Quit toolbar sample") );
555 wxMenu
*helpMenu
= new wxMenu
;
556 helpMenu
->Append(wxID_HELP
, _T("&About"), _T("About toolbar sample"));
558 wxMenuBar
* menuBar
= new wxMenuBar( wxMB_DOCKABLE
);
560 menuBar
->Append(fileMenu
, _T("&File"));
561 menuBar
->Append(tbarMenu
, _T("&Toolbar"));
562 menuBar
->Append(helpMenu
, _T("&Help"));
564 // Associate the menu bar with the frame
567 menuBar
->Check(IDM_TOOLBAR_SHOW_BOTH
, true);
568 menuBar
->Check(IDM_TOOLBAR_TOGGLETOOLTIPS
, true);
570 menuBar
->Check(IDM_TOOLBAR_TOP_ORIENTATION
, true );
571 m_toolbarPosition
= TOOLBAR_TOP
;
572 // Create the toolbar
575 m_textWindow
= new wxTextCtrl(this, wxID_ANY
, wxEmptyString
, wxDefaultPosition
, wxDefaultSize
, wxTE_MULTILINE
);
580 wxToolBar
* MyFrame::OnCreateToolBar(long style
,
582 const wxString
& name
)
584 return (wxToolBar
*)new wxToolBarSimple(this, id
,
585 wxDefaultPosition
, wxDefaultSize
,
589 #endif // USE_GENERIC_TBAR
591 void MyFrame::LayoutChildren()
593 wxSize size
= GetClientSize();
598 m_tbar
->SetSize(0, 0, wxDefaultCoord
, size
.y
);
600 offset
= m_tbar
->GetSize().x
;
607 m_textWindow
->SetSize(offset
, 0, size
.x
- offset
, size
.y
);
610 void MyFrame::OnSize(wxSizeEvent
& event
)
622 void MyFrame::OnToggleToolbar(wxCommandEvent
& WXUNUSED(event
))
624 wxToolBar
*tbar
= GetToolBar();
638 void MyFrame::OnToggleHorizontalText(wxCommandEvent
& WXUNUSED(event
))
640 m_horzText
= !m_horzText
;
645 void MyFrame::OnToggleAnotherToolbar(wxCommandEvent
& WXUNUSED(event
))
654 long style
= GetToolBar() ? GetToolBar()->GetWindowStyle()
656 style
&= ~wxTB_HORIZONTAL
;
657 style
|= wxTB_VERTICAL
;
659 m_tbar
= new wxToolBar(this, wxID_ANY
,
660 wxDefaultPosition
, wxDefaultSize
,
663 m_tbar
->SetMargins(4, 4);
665 m_tbar
->AddRadioTool(IDM_TOOLBAR_OTHER_1
, _T("First"), wxBITMAP(new));
666 m_tbar
->AddRadioTool(IDM_TOOLBAR_OTHER_2
, _T("Second"), wxBITMAP(open
));
667 m_tbar
->AddRadioTool(IDM_TOOLBAR_OTHER_3
, _T("Third"), wxBITMAP(save
));
668 m_tbar
->AddSeparator();
669 m_tbar
->AddTool(wxID_HELP
, _T("Help"), wxBITMAP(help
));
677 void MyFrame::OnToggleToolbarSize(wxCommandEvent
& WXUNUSED(event
))
679 m_smallToolbar
= !m_smallToolbar
;
684 void MyFrame::OnToggleToolbarRows(wxCommandEvent
& WXUNUSED(event
))
686 // m_rows may be only 1 or 2
689 GetToolBar()->SetRows(!(GetToolBar()->IsVertical()) ? m_rows
: 10 / m_rows
);
691 //RecreateToolbar(); -- this is unneeded
694 void MyFrame::OnToggleTooltips(wxCommandEvent
& WXUNUSED(event
))
696 m_showTooltips
= !m_showTooltips
;
701 void MyFrame::OnToggleCustomDisabled(wxCommandEvent
& WXUNUSED(event
))
703 m_useCustomDisabled
= !m_useCustomDisabled
;
708 void MyFrame::OnChangeOrientation(wxCommandEvent
& event
)
710 switch( event
.GetId() )
712 case IDM_TOOLBAR_LEFT_ORIENTATION
:
713 m_toolbarPosition
= TOOLBAR_LEFT
;
715 case IDM_TOOLBAR_TOP_ORIENTATION
:
716 m_toolbarPosition
= TOOLBAR_TOP
;
718 case IDM_TOOLBAR_RIGHT_ORIENTATION
:
719 m_toolbarPosition
= TOOLBAR_RIGHT
;
721 case IDM_TOOLBAR_BOTTOM_ORIENTATION
:
722 m_toolbarPosition
= TOOLBAR_BOTTOM
;
728 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
733 void MyFrame::OnAbout(wxCommandEvent
& event
)
735 if ( event
.IsChecked() )
736 m_textWindow
->WriteText( _T("Help button down now.\n") );
738 m_textWindow
->WriteText( _T("Help button up now.\n") );
740 (void)wxMessageBox(_T("wxWidgets toolbar sample"), _T("About wxToolBar"));
743 void MyFrame::OnToolLeftClick(wxCommandEvent
& event
)
746 str
.Printf( _T("Clicked on tool %d\n"), event
.GetId());
747 m_textWindow
->WriteText( str
);
749 if (event
.GetId() == wxID_COPY
)
754 if (event
.GetId() == wxID_CUT
)
759 if (event
.GetId() == wxID_PRINT
)
765 void MyFrame::OnToolRightClick(wxCommandEvent
& event
)
767 m_textWindow
->AppendText(
768 wxString::Format(_T("Tool %d right clicked.\n"),
769 (int) event
.GetInt()));
772 void MyFrame::OnCombo(wxCommandEvent
& event
)
774 wxLogStatus(_T("Combobox string '%s' selected"), event
.GetString().c_str());
777 void MyFrame::DoEnablePrint()
782 wxToolBarBase
*tb
= GetToolBar();
783 tb
->EnableTool(wxID_PRINT
, !tb
->GetToolEnabled(wxID_PRINT
));
786 void MyFrame::DoDeletePrint()
791 wxToolBarBase
*tb
= GetToolBar();
792 tb
->DeleteTool( wxID_PRINT
);
797 void MyFrame::DoToggleHelp()
799 wxToolBarBase
*tb
= GetToolBar();
800 tb
->ToggleTool( wxID_HELP
, !tb
->GetToolState( wxID_HELP
) );
803 void MyFrame::OnUpdateCopyAndCut(wxUpdateUIEvent
& event
)
805 event
.Enable( m_textWindow
->CanCopy() );
808 void MyFrame::OnUpdateToggleHorzText(wxUpdateUIEvent
& event
)
810 wxToolBar
*tbar
= GetToolBar();
811 event
.Enable( tbar
&&
812 tbar
->HasFlag(wxTB_TEXT
) &&
813 !tbar
->HasFlag(wxTB_NOICONS
) );
816 void MyFrame::OnChangeToolTip(wxCommandEvent
& WXUNUSED(event
))
818 GetToolBar()->SetToolShortHelp(wxID_NEW
, _T("New toolbar button"));
821 void MyFrame::OnToolbarStyle(wxCommandEvent
& event
)
823 long style
= GetToolBar()->GetWindowStyle();
824 style
&= ~(wxTB_NOICONS
| wxTB_TEXT
);
826 switch ( event
.GetId() )
828 case IDM_TOOLBAR_SHOW_TEXT
:
829 style
|= wxTB_NOICONS
| wxTB_TEXT
;
832 case IDM_TOOLBAR_SHOW_ICONS
:
836 case IDM_TOOLBAR_SHOW_BOTH
:
840 GetToolBar()->SetWindowStyle(style
);
843 void MyFrame::OnToolbarCustomBitmap(wxCommandEvent
& WXUNUSED(event
))
845 m_pathBmp
= wxFileSelector(_T("Custom bitmap path"));
850 void MyFrame::OnInsertPrint(wxCommandEvent
& WXUNUSED(event
))
854 wxToolBarBase
*tb
= GetToolBar();
855 tb
->InsertTool(0, wxID_PRINT
, _T("New print"),
856 wxBITMAP(print
), wxNullBitmap
,
858 _T("Delete this tool"),
859 _T("This button was inserted into the toolbar"));
861 // must call Realize() after adding a new button
865 void MyFrame::OnToggleRadioBtn(wxCommandEvent
& event
)
869 m_tbar
->ToggleTool(IDM_TOOLBAR_OTHER_1
+
870 event
.GetId() - IDM_TOOLBAR_TOGGLERADIOBTN1
, true);