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
);
129 void OnCombo(wxCommandEvent
& event
);
131 void OnUpdateCopyAndCut(wxUpdateUIEvent
& event
);
132 void OnUpdateToggleHorzText(wxUpdateUIEvent
& event
);
133 void OnUpdateToggleRadioBtn(wxUpdateUIEvent
& event
)
134 { event
.Enable( m_tbar
!= NULL
); }
137 void DoEnablePrint();
138 void DoDeletePrint();
141 void LayoutChildren();
147 size_t m_rows
; // 1 or 2 only
149 // the number of print buttons we have (they're added/removed dynamically)
152 // store toolbar position for future use
153 Positions m_toolbarPosition
;
155 wxTextCtrl
*m_textWindow
;
159 // the path to the custom bitmap for the test toolbar tool
162 DECLARE_EVENT_TABLE()
165 // ----------------------------------------------------------------------------
167 // ----------------------------------------------------------------------------
169 const int ID_TOOLBAR
= 500;
171 static const long TOOLBAR_STYLE
= wxTB_FLAT
| wxTB_DOCKABLE
| wxTB_TEXT
;
175 IDM_TOOLBAR_TOGGLETOOLBARSIZE
= 200,
176 IDM_TOOLBAR_TOGGLETOOLBARROWS
,
177 IDM_TOOLBAR_TOGGLETOOLTIPS
,
178 IDM_TOOLBAR_TOGGLECUSTOMDISABLED
,
179 IDM_TOOLBAR_ENABLEPRINT
,
180 IDM_TOOLBAR_DELETEPRINT
,
181 IDM_TOOLBAR_INSERTPRINT
,
182 IDM_TOOLBAR_TOGGLEHELP
,
183 IDM_TOOLBAR_TOGGLERADIOBTN1
,
184 IDM_TOOLBAR_TOGGLERADIOBTN2
,
185 IDM_TOOLBAR_TOGGLERADIOBTN3
,
186 IDM_TOOLBAR_TOGGLE_TOOLBAR
,
187 IDM_TOOLBAR_TOGGLE_HORIZONTAL_TEXT
,
188 IDM_TOOLBAR_TOGGLE_ANOTHER_TOOLBAR
,
189 IDM_TOOLBAR_CHANGE_TOOLTIP
,
190 IDM_TOOLBAR_SHOW_TEXT
,
191 IDM_TOOLBAR_SHOW_ICONS
,
192 IDM_TOOLBAR_SHOW_BOTH
,
193 IDM_TOOLBAR_CUSTOM_PATH
,
194 IDM_TOOLBAR_TOP_ORIENTATION
,
195 IDM_TOOLBAR_LEFT_ORIENTATION
,
196 IDM_TOOLBAR_BOTTOM_ORIENTATION
,
197 IDM_TOOLBAR_RIGHT_ORIENTATION
,
206 // ----------------------------------------------------------------------------
208 // ----------------------------------------------------------------------------
210 // Notice that wxID_HELP will be processed for the 'About' menu and the toolbar
213 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
214 EVT_SIZE(MyFrame::OnSize
)
216 EVT_MENU(wxID_EXIT
, MyFrame::OnQuit
)
217 EVT_MENU(wxID_HELP
, MyFrame::OnAbout
)
219 EVT_MENU(IDM_TOOLBAR_TOGGLE_TOOLBAR
, MyFrame::OnToggleToolbar
)
220 EVT_MENU(IDM_TOOLBAR_TOGGLE_ANOTHER_TOOLBAR
, MyFrame::OnToggleAnotherToolbar
)
221 EVT_MENU(IDM_TOOLBAR_TOGGLE_HORIZONTAL_TEXT
, MyFrame::OnToggleHorizontalText
)
223 EVT_MENU_RANGE(IDM_TOOLBAR_TOP_ORIENTATION
, IDM_TOOLBAR_RIGHT_ORIENTATION
, MyFrame::OnChangeOrientation
)
224 EVT_MENU(IDM_TOOLBAR_TOGGLETOOLBARSIZE
, MyFrame::OnToggleToolbarSize
)
225 EVT_MENU(IDM_TOOLBAR_TOGGLETOOLBARROWS
, MyFrame::OnToggleToolbarRows
)
226 EVT_MENU(IDM_TOOLBAR_TOGGLETOOLTIPS
, MyFrame::OnToggleTooltips
)
227 EVT_MENU(IDM_TOOLBAR_TOGGLECUSTOMDISABLED
, MyFrame::OnToggleCustomDisabled
)
229 EVT_MENU(IDM_TOOLBAR_ENABLEPRINT
, MyFrame::OnEnablePrint
)
230 EVT_MENU(IDM_TOOLBAR_DELETEPRINT
, MyFrame::OnDeletePrint
)
231 EVT_MENU(IDM_TOOLBAR_INSERTPRINT
, MyFrame::OnInsertPrint
)
232 EVT_MENU(IDM_TOOLBAR_TOGGLEHELP
, MyFrame::OnToggleHelp
)
233 EVT_MENU_RANGE(IDM_TOOLBAR_TOGGLERADIOBTN1
, IDM_TOOLBAR_TOGGLERADIOBTN3
,
234 MyFrame::OnToggleRadioBtn
)
235 EVT_MENU(IDM_TOOLBAR_CHANGE_TOOLTIP
, MyFrame::OnChangeToolTip
)
237 EVT_MENU_RANGE(IDM_TOOLBAR_SHOW_TEXT
, IDM_TOOLBAR_SHOW_BOTH
,
238 MyFrame::OnToolbarStyle
)
240 EVT_MENU(IDM_TOOLBAR_CUSTOM_PATH
, MyFrame::OnToolbarCustomBitmap
)
242 EVT_MENU(wxID_ANY
, MyFrame::OnToolLeftClick
)
244 EVT_COMBOBOX(ID_COMBO
, MyFrame::OnCombo
)
246 EVT_TOOL_RCLICKED(wxID_ANY
, MyFrame::OnToolRightClick
)
248 EVT_UPDATE_UI(wxID_COPY
, MyFrame::OnUpdateCopyAndCut
)
249 EVT_UPDATE_UI(wxID_CUT
, MyFrame::OnUpdateCopyAndCut
)
251 EVT_UPDATE_UI_RANGE(IDM_TOOLBAR_TOGGLERADIOBTN1
,
252 IDM_TOOLBAR_TOGGLERADIOBTN3
,
253 MyFrame::OnUpdateToggleRadioBtn
)
254 EVT_UPDATE_UI(IDM_TOOLBAR_TOGGLE_HORIZONTAL_TEXT
,
255 MyFrame::OnUpdateToggleHorzText
)
258 // ============================================================================
260 // ============================================================================
262 // ----------------------------------------------------------------------------
264 // ----------------------------------------------------------------------------
268 // The `main program' equivalent, creating the windows and returning the
272 // Create the main frame window
273 MyFrame
* frame
= new MyFrame((wxFrame
*) NULL
, wxID_ANY
,
274 _T("wxToolBar Sample"),
275 wxPoint(100, 100), wxSize(550, 300));
280 frame
->SetStatusText(_T("Hello, wxWidgets"));
283 wxInitAllImageHandlers();
290 void MyFrame::RecreateToolbar()
293 // On Windows CE, we should not delete the
294 // previous toolbar in case it contains the menubar.
295 // We'll try to accommodate this usage in due course.
296 wxToolBar
* toolBar
= CreateToolBar();
298 // delete and recreate the toolbar
299 wxToolBarBase
*toolBar
= GetToolBar();
300 long style
= toolBar
? toolBar
->GetWindowStyle() : TOOLBAR_STYLE
;
306 style
&= ~(wxTB_HORIZONTAL
| wxTB_VERTICAL
| wxTB_BOTTOM
| wxTB_RIGHT
| wxTB_HORZ_LAYOUT
);
307 switch( m_toolbarPosition
)
319 style
|= wxTB_BOTTOM
;
323 if ( m_showTooltips
)
324 style
&= ~wxTB_NO_TOOLTIPS
;
326 style
|= wxTB_NO_TOOLTIPS
;
328 if ( style
& wxTB_TEXT
&& !(style
& wxTB_NOICONS
) && m_horzText
)
329 style
|= wxTB_HORZ_LAYOUT
;
331 toolBar
= CreateToolBar(style
, ID_TOOLBAR
);
348 wxBitmap toolBarBitmaps
[Tool_Max
];
351 #define INIT_TOOL_BMP(bmp) \
352 toolBarBitmaps[Tool_##bmp] = wxBitmap(bmp##_xpm)
353 #else // !USE_XPM_BITMAPS
354 #define INIT_TOOL_BMP(bmp) \
355 toolBarBitmaps[Tool_##bmp] = wxBITMAP(bmp)
356 #endif // USE_XPM_BITMAPS/!USE_XPM_BITMAPS
363 INIT_TOOL_BMP(paste
);
364 INIT_TOOL_BMP(print
);
367 int w
= toolBarBitmaps
[Tool_new
].GetWidth(),
368 h
= toolBarBitmaps
[Tool_new
].GetHeight();
370 if ( !m_smallToolbar
)
375 for ( size_t n
= Tool_new
; n
< WXSIZEOF(toolBarBitmaps
); n
++ )
378 wxBitmap(toolBarBitmaps
[n
].ConvertToImage().Scale(w
, h
));
382 toolBar
->SetToolBitmapSize(wxSize(w
, h
));
384 toolBar
->AddTool(wxID_NEW
, _T("New"),
385 toolBarBitmaps
[Tool_new
], wxNullBitmap
, wxITEM_NORMAL
,
386 _T("New file"), _T("This is help for new file tool"));
387 toolBar
->AddTool(wxID_OPEN
, _T("Open"),
388 toolBarBitmaps
[Tool_open
], wxNullBitmap
, wxITEM_NORMAL
,
389 _T("Open file"), _T("This is help for open file tool"));
391 // the generic toolbar doesn't really support this
392 #if wxUSE_TOOLBAR_NATIVE && !defined(__WXX11__) || defined(__WXUNIVERSAL__)
393 // adding a combo to a vertical toolbar is not very smart
394 if ( !( toolBar
->IsVertical() ) )
396 wxComboBox
*combo
= new wxComboBox(toolBar
, ID_COMBO
, wxEmptyString
, wxDefaultPosition
, wxSize(100,-1) );
397 combo
->Append(_T("This"));
398 combo
->Append(_T("is a"));
399 combo
->Append(_T("combobox"));
400 combo
->Append(_T("in a"));
401 combo
->Append(_T("toolbar"));
402 toolBar
->AddControl(combo
);
404 wxSpinCtrl
*spin
= new wxSpinCtrl( toolBar
, ID_SPIN
, wxT("0"), wxDefaultPosition
, wxSize(80,wxDefaultCoord
), 0, 0, 100 );
405 toolBar
->AddControl( spin
);
407 wxTextCtrl
*text
= new wxTextCtrl( toolBar
, -1, wxT("text"), wxDefaultPosition
, wxSize(80,wxDefaultCoord
) );
408 toolBar
->AddControl( text
);
410 wxSearchCtrl
*srch
= new wxSearchCtrl( toolBar
, -1, wxT("xx"), wxDefaultPosition
, wxSize(80,wxDefaultCoord
), wxSUNKEN_BORDER
);
411 toolBar
->AddControl( srch
);
413 #endif // toolbars which don't support controls
415 toolBar
->AddTool(wxID_SAVE
, _T("Save"), toolBarBitmaps
[Tool_save
], _T("Toggle button 1"), wxITEM_CHECK
);
416 toolBar
->AddTool(wxID_COPY
, _T("Copy"), toolBarBitmaps
[Tool_copy
], _T("Toggle button 2"), wxITEM_CHECK
);
417 toolBar
->AddTool(wxID_CUT
, _T("Cut"), toolBarBitmaps
[Tool_cut
], _T("Toggle/Untoggle help button"));
418 toolBar
->AddTool(wxID_PASTE
, _T("Paste"), toolBarBitmaps
[Tool_paste
], _T("Paste"));
420 if ( m_useCustomDisabled
)
422 wxBitmap
bmpDisabled(w
, h
);
425 dc
.SelectObject(bmpDisabled
);
426 dc
.DrawBitmap(toolBarBitmaps
[Tool_print
], 0, 0);
428 wxPen
pen(*wxRED
, 5);
430 dc
.DrawLine(0, 0, w
, h
);
433 toolBar
->AddTool(wxID_PRINT
, _T("Print"), toolBarBitmaps
[Tool_print
],
438 toolBar
->AddTool(wxID_PRINT
, _T("Print"), toolBarBitmaps
[Tool_print
],
439 _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."));
442 toolBar
->AddSeparator();
443 toolBar
->AddTool(wxID_HELP
, _T("Help"), toolBarBitmaps
[Tool_help
], _T("Help button"), wxITEM_CHECK
);
445 if ( !m_pathBmp
.empty() )
447 // create a tool with a custom bitmap for testing
448 wxImage
img(m_pathBmp
);
451 if ( img
.GetWidth() > w
&& img
.GetHeight() > h
)
452 img
= img
.GetSubImage(wxRect(0, 0, w
, h
));
454 toolBar
->AddSeparator();
455 toolBar
->AddTool(wxID_ANY
, _T("Custom"), img
);
459 // after adding the buttons to the toolbar, must call Realize() to reflect
463 toolBar
->SetRows(!(toolBar
->IsVertical()) ? m_rows
: 10 / m_rows
);
466 // ----------------------------------------------------------------------------
468 // ----------------------------------------------------------------------------
470 // Define my frame constructor
471 MyFrame::MyFrame(wxFrame
* parent
,
473 const wxString
& title
,
477 : wxFrame(parent
, id
, title
, pos
, size
, style
)
481 m_smallToolbar
= true;
483 m_useCustomDisabled
= false;
484 m_showTooltips
= true;
490 // Give it a status line
495 SetIcon(wxICON(mondrian
));
498 wxMenu
*tbarMenu
= new wxMenu
;
499 tbarMenu
->AppendCheckItem(IDM_TOOLBAR_TOGGLE_TOOLBAR
,
500 _T("Toggle &toolbar\tCtrl-Z"),
501 _T("Show or hide the toolbar"));
503 tbarMenu
->AppendCheckItem(IDM_TOOLBAR_TOGGLE_ANOTHER_TOOLBAR
,
504 _T("Toggle &another toolbar\tCtrl-A"),
505 _T("Show/hide another test toolbar"));
507 tbarMenu
->AppendCheckItem(IDM_TOOLBAR_TOGGLE_HORIZONTAL_TEXT
,
508 _T("Toggle hori&zontal text\tCtrl-H"),
509 _T("Show text under/alongside the icon"));
511 tbarMenu
->AppendCheckItem(IDM_TOOLBAR_TOGGLETOOLBARSIZE
,
512 _T("&Toggle toolbar size\tCtrl-S"),
513 _T("Toggle between big/small toolbar"));
515 tbarMenu
->AppendCheckItem(IDM_TOOLBAR_TOGGLETOOLBARROWS
,
516 _T("Toggle number of &rows\tCtrl-R"),
517 _T("Toggle number of toolbar rows between 1 and 2"));
519 tbarMenu
->AppendCheckItem(IDM_TOOLBAR_TOGGLETOOLTIPS
,
520 _T("Show &tooltips\tCtrl-L"),
521 _T("Show tooltips for the toolbar tools"));
523 tbarMenu
->AppendCheckItem(IDM_TOOLBAR_TOGGLECUSTOMDISABLED
,
524 _T("Use c&ustom disabled images\tCtrl-U"),
525 _T("Switch between using system-generated and custom disabled images"));
528 tbarMenu
->AppendSeparator();
529 tbarMenu
->AppendRadioItem(IDM_TOOLBAR_TOP_ORIENTATION
,
530 _T("Set toolbar at the top of the window"),
531 _T("Set toolbar at the top of the window"));
532 tbarMenu
->AppendRadioItem(IDM_TOOLBAR_LEFT_ORIENTATION
,
533 _T("Set toolbar at the left of the window"),
534 _T("Set toolbar at the left of the window"));
535 tbarMenu
->AppendRadioItem(IDM_TOOLBAR_BOTTOM_ORIENTATION
,
536 _T("Set toolbar at the bottom of the window"),
537 _T("Set toolbar at the bottom of the window"));
538 tbarMenu
->AppendRadioItem(IDM_TOOLBAR_RIGHT_ORIENTATION
,
539 _T("Set toolbar at the right edge of the window"),
540 _T("Set toolbar at the right edge of the window"));
541 tbarMenu
->AppendSeparator();
543 tbarMenu
->Append(IDM_TOOLBAR_ENABLEPRINT
, _T("&Enable print button\tCtrl-E"));
544 tbarMenu
->Append(IDM_TOOLBAR_DELETEPRINT
, _T("&Delete print button\tCtrl-D"));
545 tbarMenu
->Append(IDM_TOOLBAR_INSERTPRINT
, _T("&Insert print button\tCtrl-I"));
546 tbarMenu
->Append(IDM_TOOLBAR_TOGGLEHELP
, _T("Toggle &help button\tCtrl-T"));
547 tbarMenu
->AppendSeparator();
548 tbarMenu
->Append(IDM_TOOLBAR_TOGGLERADIOBTN1
, _T("Toggle &1st radio button\tCtrl-1"));
549 tbarMenu
->Append(IDM_TOOLBAR_TOGGLERADIOBTN2
, _T("Toggle &2nd radio button\tCtrl-2"));
550 tbarMenu
->Append(IDM_TOOLBAR_TOGGLERADIOBTN3
, _T("Toggle &3rd radio button\tCtrl-3"));
551 tbarMenu
->AppendSeparator();
552 tbarMenu
->Append(IDM_TOOLBAR_CHANGE_TOOLTIP
, _T("Change tool tip"));
553 tbarMenu
->AppendSeparator();
554 tbarMenu
->AppendRadioItem(IDM_TOOLBAR_SHOW_TEXT
, _T("Show &text\tCtrl-Alt-T"));
555 tbarMenu
->AppendRadioItem(IDM_TOOLBAR_SHOW_ICONS
, _T("Show &icons\tCtrl-Alt-I"));
556 tbarMenu
->AppendRadioItem(IDM_TOOLBAR_SHOW_BOTH
, _T("Show &both\tCtrl-Alt-B"));
557 tbarMenu
->AppendSeparator();
558 tbarMenu
->Append(IDM_TOOLBAR_CUSTOM_PATH
, _T("Custom &bitmap...\tCtrl-B"));
560 wxMenu
*fileMenu
= new wxMenu
;
561 fileMenu
->Append(wxID_EXIT
, _T("E&xit\tAlt-X"), _T("Quit toolbar sample") );
563 wxMenu
*helpMenu
= new wxMenu
;
564 helpMenu
->Append(wxID_HELP
, _T("&About"), _T("About toolbar sample"));
566 wxMenuBar
* menuBar
= new wxMenuBar( wxMB_DOCKABLE
);
568 menuBar
->Append(fileMenu
, _T("&File"));
569 menuBar
->Append(tbarMenu
, _T("&Toolbar"));
570 menuBar
->Append(helpMenu
, _T("&Help"));
572 // Associate the menu bar with the frame
575 menuBar
->Check(IDM_TOOLBAR_SHOW_BOTH
, true);
576 menuBar
->Check(IDM_TOOLBAR_TOGGLETOOLTIPS
, true);
578 menuBar
->Check(IDM_TOOLBAR_TOP_ORIENTATION
, true );
579 m_toolbarPosition
= TOOLBAR_TOP
;
580 // Create the toolbar
583 m_textWindow
= new wxTextCtrl(this, wxID_ANY
, wxEmptyString
, wxDefaultPosition
, wxDefaultSize
, wxTE_MULTILINE
);
588 wxToolBar
* MyFrame::OnCreateToolBar(long style
,
590 const wxString
& name
)
592 return (wxToolBar
*)new wxToolBarSimple(this, id
,
593 wxDefaultPosition
, wxDefaultSize
,
597 #endif // USE_GENERIC_TBAR
599 void MyFrame::LayoutChildren()
601 wxSize size
= GetClientSize();
606 m_tbar
->SetSize(0, 0, wxDefaultCoord
, size
.y
);
608 offset
= m_tbar
->GetSize().x
;
615 m_textWindow
->SetSize(offset
, 0, size
.x
- offset
, size
.y
);
618 void MyFrame::OnSize(wxSizeEvent
& event
)
630 void MyFrame::OnToggleToolbar(wxCommandEvent
& WXUNUSED(event
))
632 wxToolBar
*tbar
= GetToolBar();
646 void MyFrame::OnToggleHorizontalText(wxCommandEvent
& WXUNUSED(event
))
648 m_horzText
= !m_horzText
;
653 void MyFrame::OnToggleAnotherToolbar(wxCommandEvent
& WXUNUSED(event
))
662 long style
= GetToolBar() ? GetToolBar()->GetWindowStyle()
664 style
&= ~wxTB_HORIZONTAL
;
665 style
|= wxTB_VERTICAL
;
667 m_tbar
= new wxToolBar(this, wxID_ANY
,
668 wxDefaultPosition
, wxDefaultSize
,
671 m_tbar
->SetMargins(4, 4);
673 m_tbar
->AddRadioTool(IDM_TOOLBAR_OTHER_1
, _T("First"), wxBITMAP(new));
674 m_tbar
->AddRadioTool(IDM_TOOLBAR_OTHER_2
, _T("Second"), wxBITMAP(open
));
675 m_tbar
->AddRadioTool(IDM_TOOLBAR_OTHER_3
, _T("Third"), wxBITMAP(save
));
676 m_tbar
->AddSeparator();
677 m_tbar
->AddTool(wxID_HELP
, _T("Help"), wxBITMAP(help
));
685 void MyFrame::OnToggleToolbarSize(wxCommandEvent
& WXUNUSED(event
))
687 m_smallToolbar
= !m_smallToolbar
;
692 void MyFrame::OnToggleToolbarRows(wxCommandEvent
& WXUNUSED(event
))
694 // m_rows may be only 1 or 2
697 GetToolBar()->SetRows(!(GetToolBar()->IsVertical()) ? m_rows
: 10 / m_rows
);
699 //RecreateToolbar(); -- this is unneeded
702 void MyFrame::OnToggleTooltips(wxCommandEvent
& WXUNUSED(event
))
704 m_showTooltips
= !m_showTooltips
;
709 void MyFrame::OnToggleCustomDisabled(wxCommandEvent
& WXUNUSED(event
))
711 m_useCustomDisabled
= !m_useCustomDisabled
;
716 void MyFrame::OnChangeOrientation(wxCommandEvent
& event
)
718 switch( event
.GetId() )
720 case IDM_TOOLBAR_LEFT_ORIENTATION
:
721 m_toolbarPosition
= TOOLBAR_LEFT
;
723 case IDM_TOOLBAR_TOP_ORIENTATION
:
724 m_toolbarPosition
= TOOLBAR_TOP
;
726 case IDM_TOOLBAR_RIGHT_ORIENTATION
:
727 m_toolbarPosition
= TOOLBAR_RIGHT
;
729 case IDM_TOOLBAR_BOTTOM_ORIENTATION
:
730 m_toolbarPosition
= TOOLBAR_BOTTOM
;
736 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
741 void MyFrame::OnAbout(wxCommandEvent
& event
)
743 if ( event
.IsChecked() )
744 m_textWindow
->WriteText( _T("Help button down now.\n") );
746 m_textWindow
->WriteText( _T("Help button up now.\n") );
748 (void)wxMessageBox(_T("wxWidgets toolbar sample"), _T("About wxToolBar"));
751 void MyFrame::OnToolLeftClick(wxCommandEvent
& event
)
754 str
.Printf( _T("Clicked on tool %d\n"), event
.GetId());
755 m_textWindow
->WriteText( str
);
757 if (event
.GetId() == wxID_COPY
)
762 if (event
.GetId() == wxID_CUT
)
767 if (event
.GetId() == wxID_PRINT
)
773 void MyFrame::OnToolRightClick(wxCommandEvent
& event
)
775 m_textWindow
->AppendText(
776 wxString::Format(_T("Tool %d right clicked.\n"),
777 (int) event
.GetInt()));
780 void MyFrame::OnCombo(wxCommandEvent
& event
)
782 wxLogStatus(_T("Combobox string '%s' selected"), event
.GetString().c_str());
785 void MyFrame::DoEnablePrint()
790 wxToolBarBase
*tb
= GetToolBar();
791 tb
->EnableTool(wxID_PRINT
, !tb
->GetToolEnabled(wxID_PRINT
));
794 void MyFrame::DoDeletePrint()
799 wxToolBarBase
*tb
= GetToolBar();
800 tb
->DeleteTool( wxID_PRINT
);
805 void MyFrame::DoToggleHelp()
807 wxToolBarBase
*tb
= GetToolBar();
808 tb
->ToggleTool( wxID_HELP
, !tb
->GetToolState( wxID_HELP
) );
811 void MyFrame::OnUpdateCopyAndCut(wxUpdateUIEvent
& event
)
813 event
.Enable( m_textWindow
->CanCopy() );
816 void MyFrame::OnUpdateToggleHorzText(wxUpdateUIEvent
& event
)
818 wxToolBar
*tbar
= GetToolBar();
819 event
.Enable( tbar
&&
820 tbar
->HasFlag(wxTB_TEXT
) &&
821 !tbar
->HasFlag(wxTB_NOICONS
) );
824 void MyFrame::OnChangeToolTip(wxCommandEvent
& WXUNUSED(event
))
826 GetToolBar()->SetToolShortHelp(wxID_NEW
, _T("New toolbar button"));
829 void MyFrame::OnToolbarStyle(wxCommandEvent
& event
)
831 long style
= GetToolBar()->GetWindowStyle();
832 style
&= ~(wxTB_NOICONS
| wxTB_TEXT
);
834 switch ( event
.GetId() )
836 case IDM_TOOLBAR_SHOW_TEXT
:
837 style
|= wxTB_NOICONS
| wxTB_TEXT
;
840 case IDM_TOOLBAR_SHOW_ICONS
:
844 case IDM_TOOLBAR_SHOW_BOTH
:
848 GetToolBar()->SetWindowStyle(style
);
851 void MyFrame::OnToolbarCustomBitmap(wxCommandEvent
& WXUNUSED(event
))
853 m_pathBmp
= wxFileSelector(_T("Custom bitmap path"));
858 void MyFrame::OnInsertPrint(wxCommandEvent
& WXUNUSED(event
))
862 wxToolBarBase
*tb
= GetToolBar();
863 tb
->InsertTool(0, wxID_PRINT
, _T("New print"),
864 wxBITMAP(print
), wxNullBitmap
,
866 _T("Delete this tool"),
867 _T("This button was inserted into the toolbar"));
869 // must call Realize() after adding a new button
873 void MyFrame::OnToggleRadioBtn(wxCommandEvent
& event
)
877 m_tbar
->ToggleTool(IDM_TOOLBAR_OTHER_1
+
878 event
.GetId() - IDM_TOOLBAR_TOGGLERADIOBTN1
, true);