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 class MyMiniControl
: public wxControl
90 MyMiniControl( wxWindow
*parent
) :
91 wxControl( parent
, -1, wxDefaultPosition
, wxSize(80,22), wxBORDER_SUNKEN
, wxDefaultValidator
, "MyMiniControl" )
95 void OnPaint(wxPaintEvent
&WXUNUSED(event
))
98 dc
.SetPen( *wxTRANSPARENT_PEN
);
99 dc
.SetBrush( *wxWHITE_BRUSH
);
100 wxSize size
= GetClientSize();
101 dc
.DrawRectangle( 0,0,size
.x
,size
.y
);
103 dc
.DrawText( "Focussed", 1,1 );
105 void OnSetFocus(wxFocusEvent
&WXUNUSED(event
))
110 void OnKillFocus(wxFocusEvent
&WXUNUSED(event
))
115 virtual wxSize
GetBestSize()
117 return wxSize(80,22);
119 virtual bool AcceptsFocus()
127 DECLARE_EVENT_TABLE()
130 BEGIN_EVENT_TABLE(MyMiniControl
, wxControl
)
131 EVT_PAINT(MyMiniControl::OnPaint
)
132 EVT_SET_FOCUS(MyMiniControl::OnSetFocus
)
133 EVT_KILL_FOCUS(MyMiniControl::OnKillFocus
)
138 // Define a new application
139 class MyApp
: public wxApp
145 // Define a new frame
146 class MyFrame
: public wxFrame
149 MyFrame(wxFrame
*parent
,
150 wxWindowID id
= wxID_ANY
,
151 const wxString
& title
= _T("wxToolBar Sample"),
152 const wxPoint
& pos
= wxDefaultPosition
,
153 const wxSize
& size
= wxDefaultSize
,
154 long style
= wxDEFAULT_FRAME_STYLE
|wxCLIP_CHILDREN
|wxNO_FULL_REPAINT_ON_RESIZE
);
156 void PopulateToolbar(wxToolBarBase
* toolBar
);
157 void RecreateToolbar();
159 void OnQuit(wxCommandEvent
& event
);
160 void OnAbout(wxCommandEvent
& event
);
162 void OnSize(wxSizeEvent
& event
);
164 void OnToggleToolbar(wxCommandEvent
& event
);
165 void OnToggleAnotherToolbar(wxCommandEvent
& event
);
166 void OnToggleHorizontalText(wxCommandEvent
& WXUNUSED(event
));
168 void OnToggleToolbarSize(wxCommandEvent
& event
);
169 void OnChangeOrientation(wxCommandEvent
& event
);
170 void OnToggleToolbarRows(wxCommandEvent
& event
);
171 void OnToggleTooltips(wxCommandEvent
& event
);
172 void OnToggleCustomDisabled(wxCommandEvent
& event
);
174 void OnEnablePrint(wxCommandEvent
& WXUNUSED(event
)) { DoEnablePrint(); }
175 void OnDeletePrint(wxCommandEvent
& WXUNUSED(event
)) { DoDeletePrint(); }
176 void OnInsertPrint(wxCommandEvent
& event
);
177 void OnChangeToolTip(wxCommandEvent
& event
);
178 void OnToggleHelp(wxCommandEvent
& WXUNUSED(event
)) { DoToggleHelp(); }
179 void OnToggleRadioBtn(wxCommandEvent
& event
);
181 void OnToolbarStyle(wxCommandEvent
& event
);
182 void OnToolbarCustomBitmap(wxCommandEvent
& event
);
184 void OnToolLeftClick(wxCommandEvent
& event
);
185 void OnToolRightClick(wxCommandEvent
& event
);
186 void OnToolDropdown(wxCommandEvent
& event
);
188 void OnCombo(wxCommandEvent
& event
);
190 void OnUpdateCopyAndCut(wxUpdateUIEvent
& event
);
191 void OnUpdateToggleHorzText(wxUpdateUIEvent
& event
);
192 void OnUpdateToggleRadioBtn(wxUpdateUIEvent
& event
)
193 { event
.Enable( m_tbar
!= NULL
); }
196 void DoEnablePrint();
197 void DoDeletePrint();
200 void LayoutChildren();
206 size_t m_rows
; // 1 or 2 only
208 // the number of print buttons we have (they're added/removed dynamically)
211 // store toolbar position for future use
212 Positions m_toolbarPosition
;
214 wxTextCtrl
*m_textWindow
;
217 wxToolBar
*m_extraToolBar
;
221 // the path to the custom bitmap for the test toolbar tool
224 DECLARE_EVENT_TABLE()
227 // ----------------------------------------------------------------------------
229 // ----------------------------------------------------------------------------
231 const int ID_TOOLBAR
= 500;
233 static const long TOOLBAR_STYLE
= wxTB_FLAT
| wxTB_DOCKABLE
| wxTB_TEXT
;
237 IDM_TOOLBAR_TOGGLETOOLBARSIZE
= 200,
238 IDM_TOOLBAR_TOGGLETOOLBARROWS
,
239 IDM_TOOLBAR_TOGGLETOOLTIPS
,
240 IDM_TOOLBAR_TOGGLECUSTOMDISABLED
,
241 IDM_TOOLBAR_ENABLEPRINT
,
242 IDM_TOOLBAR_DELETEPRINT
,
243 IDM_TOOLBAR_INSERTPRINT
,
244 IDM_TOOLBAR_TOGGLEHELP
,
245 IDM_TOOLBAR_TOGGLERADIOBTN1
,
246 IDM_TOOLBAR_TOGGLERADIOBTN2
,
247 IDM_TOOLBAR_TOGGLERADIOBTN3
,
248 IDM_TOOLBAR_TOGGLE_TOOLBAR
,
249 IDM_TOOLBAR_TOGGLE_HORIZONTAL_TEXT
,
250 IDM_TOOLBAR_TOGGLE_ANOTHER_TOOLBAR
,
251 IDM_TOOLBAR_CHANGE_TOOLTIP
,
252 IDM_TOOLBAR_SHOW_TEXT
,
253 IDM_TOOLBAR_SHOW_ICONS
,
254 IDM_TOOLBAR_SHOW_BOTH
,
255 IDM_TOOLBAR_CUSTOM_PATH
,
256 IDM_TOOLBAR_TOP_ORIENTATION
,
257 IDM_TOOLBAR_LEFT_ORIENTATION
,
258 IDM_TOOLBAR_BOTTOM_ORIENTATION
,
259 IDM_TOOLBAR_RIGHT_ORIENTATION
,
268 // ----------------------------------------------------------------------------
270 // ----------------------------------------------------------------------------
272 // Notice that wxID_HELP will be processed for the 'About' menu and the toolbar
275 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
276 EVT_SIZE(MyFrame::OnSize
)
278 EVT_MENU(wxID_EXIT
, MyFrame::OnQuit
)
279 EVT_MENU(wxID_HELP
, MyFrame::OnAbout
)
281 EVT_MENU(IDM_TOOLBAR_TOGGLE_TOOLBAR
, MyFrame::OnToggleToolbar
)
282 EVT_MENU(IDM_TOOLBAR_TOGGLE_ANOTHER_TOOLBAR
, MyFrame::OnToggleAnotherToolbar
)
283 EVT_MENU(IDM_TOOLBAR_TOGGLE_HORIZONTAL_TEXT
, MyFrame::OnToggleHorizontalText
)
285 EVT_MENU_RANGE(IDM_TOOLBAR_TOP_ORIENTATION
, IDM_TOOLBAR_RIGHT_ORIENTATION
, MyFrame::OnChangeOrientation
)
286 EVT_MENU(IDM_TOOLBAR_TOGGLETOOLBARSIZE
, MyFrame::OnToggleToolbarSize
)
287 EVT_MENU(IDM_TOOLBAR_TOGGLETOOLBARROWS
, MyFrame::OnToggleToolbarRows
)
288 EVT_MENU(IDM_TOOLBAR_TOGGLETOOLTIPS
, MyFrame::OnToggleTooltips
)
289 EVT_MENU(IDM_TOOLBAR_TOGGLECUSTOMDISABLED
, MyFrame::OnToggleCustomDisabled
)
291 EVT_MENU(IDM_TOOLBAR_ENABLEPRINT
, MyFrame::OnEnablePrint
)
292 EVT_MENU(IDM_TOOLBAR_DELETEPRINT
, MyFrame::OnDeletePrint
)
293 EVT_MENU(IDM_TOOLBAR_INSERTPRINT
, MyFrame::OnInsertPrint
)
294 EVT_MENU(IDM_TOOLBAR_TOGGLEHELP
, MyFrame::OnToggleHelp
)
295 EVT_MENU_RANGE(IDM_TOOLBAR_TOGGLERADIOBTN1
, IDM_TOOLBAR_TOGGLERADIOBTN3
,
296 MyFrame::OnToggleRadioBtn
)
297 EVT_MENU(IDM_TOOLBAR_CHANGE_TOOLTIP
, MyFrame::OnChangeToolTip
)
299 EVT_MENU_RANGE(IDM_TOOLBAR_SHOW_TEXT
, IDM_TOOLBAR_SHOW_BOTH
,
300 MyFrame::OnToolbarStyle
)
302 EVT_MENU(IDM_TOOLBAR_CUSTOM_PATH
, MyFrame::OnToolbarCustomBitmap
)
304 EVT_MENU(wxID_ANY
, MyFrame::OnToolLeftClick
)
306 EVT_COMBOBOX(ID_COMBO
, MyFrame::OnCombo
)
308 EVT_TOOL_RCLICKED(wxID_ANY
, MyFrame::OnToolRightClick
)
310 EVT_TOOL_DROPDOWN(wxID_ANY
, MyFrame::OnToolDropdown
)
312 EVT_UPDATE_UI(wxID_COPY
, MyFrame::OnUpdateCopyAndCut
)
313 EVT_UPDATE_UI(wxID_CUT
, MyFrame::OnUpdateCopyAndCut
)
315 EVT_UPDATE_UI_RANGE(IDM_TOOLBAR_TOGGLERADIOBTN1
,
316 IDM_TOOLBAR_TOGGLERADIOBTN3
,
317 MyFrame::OnUpdateToggleRadioBtn
)
318 EVT_UPDATE_UI(IDM_TOOLBAR_TOGGLE_HORIZONTAL_TEXT
,
319 MyFrame::OnUpdateToggleHorzText
)
322 // ============================================================================
324 // ============================================================================
326 // ----------------------------------------------------------------------------
328 // ----------------------------------------------------------------------------
332 // The `main program' equivalent, creating the windows and returning the
336 if ( !wxApp::OnInit() )
339 // Create the main frame window
340 MyFrame
* frame
= new MyFrame((wxFrame
*) NULL
, wxID_ANY
,
341 _T("wxToolBar Sample"),
342 wxPoint(100, 100), wxSize(550, 500));
347 frame
->SetStatusText(_T("Hello, wxWidgets"));
350 wxInitAllImageHandlers();
357 void MyFrame::RecreateToolbar()
360 // On Windows CE, we should not delete the
361 // previous toolbar in case it contains the menubar.
362 // We'll try to accommodate this usage in due course.
363 wxToolBar
* toolBar
= CreateToolBar();
365 // delete and recreate the toolbar
366 wxToolBarBase
*toolBar
= GetToolBar();
367 long style
= toolBar
? toolBar
->GetWindowStyle() : TOOLBAR_STYLE
;
373 style
&= ~(wxTB_HORIZONTAL
| wxTB_VERTICAL
| wxTB_BOTTOM
| wxTB_RIGHT
| wxTB_HORZ_LAYOUT
);
374 switch( m_toolbarPosition
)
386 style
|= wxTB_BOTTOM
;
390 if ( m_showTooltips
)
391 style
&= ~wxTB_NO_TOOLTIPS
;
393 style
|= wxTB_NO_TOOLTIPS
;
395 if ( style
& wxTB_TEXT
&& !(style
& wxTB_NOICONS
) && m_horzText
)
396 style
|= wxTB_HORZ_LAYOUT
;
398 toolBar
= CreateToolBar(style
, ID_TOOLBAR
);
401 PopulateToolbar(toolBar
);
404 void MyFrame::PopulateToolbar(wxToolBarBase
* toolBar
)
420 wxBitmap toolBarBitmaps
[Tool_Max
];
423 #define INIT_TOOL_BMP(bmp) \
424 toolBarBitmaps[Tool_##bmp] = wxBitmap(bmp##_xpm)
425 #else // !USE_XPM_BITMAPS
426 #define INIT_TOOL_BMP(bmp) \
427 toolBarBitmaps[Tool_##bmp] = wxBITMAP(bmp)
428 #endif // USE_XPM_BITMAPS/!USE_XPM_BITMAPS
435 INIT_TOOL_BMP(paste
);
436 INIT_TOOL_BMP(print
);
439 int w
= toolBarBitmaps
[Tool_new
].GetWidth(),
440 h
= toolBarBitmaps
[Tool_new
].GetHeight();
442 if ( !m_smallToolbar
)
447 for ( size_t n
= Tool_new
; n
< WXSIZEOF(toolBarBitmaps
); n
++ )
450 wxBitmap(toolBarBitmaps
[n
].ConvertToImage().Scale(w
, h
));
454 toolBar
->SetToolBitmapSize(wxSize(w
, h
));
456 toolBar
->AddTool(wxID_NEW
, _T("New"),
457 toolBarBitmaps
[Tool_new
], wxNullBitmap
, wxITEM_DROPDOWN
,
458 _T("New file"), _T("This is help for new file tool"));
460 wxMenu
* menu
= new wxMenu
;
461 menu
->Append(wxID_ANY
, _T("&First dummy item"));
462 menu
->Append(wxID_ANY
, _T("&Second dummy item"));
463 menu
->AppendSeparator();
464 menu
->Append(wxID_EXIT
, _T("Exit"));
465 toolBar
->SetDropdownMenu(wxID_NEW
, menu
);
467 toolBar
->AddTool(wxID_OPEN
, _T("Open"),
468 toolBarBitmaps
[Tool_open
], wxNullBitmap
, wxITEM_NORMAL
,
469 _T("Open file"), _T("This is help for open file tool"));
471 // the generic toolbar doesn't really support this
472 #if wxUSE_TOOLBAR_NATIVE && !defined(__WXX11__) || defined(__WXUNIVERSAL__)
473 // adding a combo to a vertical toolbar is not very smart
474 if ( !( toolBar
->IsVertical() ) )
476 wxComboBox
*combo
= new wxComboBox(toolBar
, ID_COMBO
, wxEmptyString
, wxDefaultPosition
, wxSize(100,-1) );
477 combo
->Append(_T("This"));
478 combo
->Append(_T("is a"));
479 combo
->Append(_T("combobox"));
480 combo
->Append(_T("in a"));
481 combo
->Append(_T("toolbar"));
482 toolBar
->AddControl(combo
, _T("Combo Label"));
484 wxSpinCtrl
*spin
= new wxSpinCtrl( toolBar
, ID_SPIN
, wxT("0"), wxDefaultPosition
, wxSize(80,wxDefaultCoord
), 0, 0, 100 );
485 toolBar
->AddControl( spin
);
487 wxTextCtrl
*text
= new wxTextCtrl( toolBar
, -1, wxT("text"), wxDefaultPosition
, wxSize(80,wxDefaultCoord
) );
488 toolBar
->AddControl( text
);
490 wxSearchCtrl
*srch
= new wxSearchCtrl( toolBar
, -1, wxT("xx"), wxDefaultPosition
, wxSize(80,wxDefaultCoord
), wxSUNKEN_BORDER
);
491 toolBar
->AddControl( srch
);
493 toolBar
->AddControl( new MyMiniControl( toolBar
) );
495 #endif // toolbars which don't support controls
497 toolBar
->AddTool(wxID_SAVE
, _T("Save"), toolBarBitmaps
[Tool_save
], _T("Toggle button 1"), wxITEM_CHECK
);
498 toolBar
->AddTool(wxID_COPY
, _T("Copy"), toolBarBitmaps
[Tool_copy
], _T("Toggle button 2"), wxITEM_CHECK
);
499 toolBar
->AddTool(wxID_CUT
, _T("Cut"), toolBarBitmaps
[Tool_cut
], _T("Toggle/Untoggle help button"));
500 toolBar
->AddTool(wxID_PASTE
, _T("Paste"), toolBarBitmaps
[Tool_paste
], _T("Paste"));
502 if ( m_useCustomDisabled
)
504 wxBitmap
bmpDisabled(w
, h
);
507 dc
.SelectObject(bmpDisabled
);
508 dc
.DrawBitmap(toolBarBitmaps
[Tool_print
], 0, 0);
510 wxPen
pen(*wxRED
, 5);
512 dc
.DrawLine(0, 0, w
, h
);
515 toolBar
->AddTool(wxID_PRINT
, _T("Print"), toolBarBitmaps
[Tool_print
],
520 toolBar
->AddTool(wxID_PRINT
, _T("Print"), toolBarBitmaps
[Tool_print
],
521 _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."));
524 toolBar
->AddSeparator();
525 toolBar
->AddTool(wxID_HELP
, _T("Help"), toolBarBitmaps
[Tool_help
], _T("Help button"), wxITEM_CHECK
);
527 if ( !m_pathBmp
.empty() )
529 // create a tool with a custom bitmap for testing
530 wxImage
img(m_pathBmp
);
533 if ( img
.GetWidth() > w
&& img
.GetHeight() > h
)
534 img
= img
.GetSubImage(wxRect(0, 0, w
, h
));
536 toolBar
->AddSeparator();
537 toolBar
->AddTool(wxID_ANY
, _T("Custom"), img
);
541 // after adding the buttons to the toolbar, must call Realize() to reflect
545 toolBar
->SetRows(!(toolBar
->IsVertical()) ? m_rows
: 10 / m_rows
);
548 // ----------------------------------------------------------------------------
550 // ----------------------------------------------------------------------------
552 // Define my frame constructor
553 MyFrame::MyFrame(wxFrame
* parent
,
555 const wxString
& title
,
559 : wxFrame(parent
, id
, title
, pos
, size
, style
)
563 m_smallToolbar
= true;
565 m_useCustomDisabled
= false;
566 m_showTooltips
= true;
572 // Give it a status line
577 SetIcon(wxICON(mondrian
));
580 wxMenu
*tbarMenu
= new wxMenu
;
581 tbarMenu
->AppendCheckItem(IDM_TOOLBAR_TOGGLE_TOOLBAR
,
582 _T("Toggle &toolbar\tCtrl-Z"),
583 _T("Show or hide the toolbar"));
585 tbarMenu
->AppendCheckItem(IDM_TOOLBAR_TOGGLE_ANOTHER_TOOLBAR
,
586 _T("Toggle &another toolbar\tCtrl-A"),
587 _T("Show/hide another test toolbar"));
589 tbarMenu
->AppendCheckItem(IDM_TOOLBAR_TOGGLE_HORIZONTAL_TEXT
,
590 _T("Toggle hori&zontal text\tCtrl-H"),
591 _T("Show text under/alongside the icon"));
593 tbarMenu
->AppendCheckItem(IDM_TOOLBAR_TOGGLETOOLBARSIZE
,
594 _T("&Toggle toolbar size\tCtrl-S"),
595 _T("Toggle between big/small toolbar"));
597 tbarMenu
->AppendCheckItem(IDM_TOOLBAR_TOGGLETOOLBARROWS
,
598 _T("Toggle number of &rows\tCtrl-R"),
599 _T("Toggle number of toolbar rows between 1 and 2"));
601 tbarMenu
->AppendCheckItem(IDM_TOOLBAR_TOGGLETOOLTIPS
,
602 _T("Show &tooltips\tCtrl-L"),
603 _T("Show tooltips for the toolbar tools"));
605 tbarMenu
->AppendCheckItem(IDM_TOOLBAR_TOGGLECUSTOMDISABLED
,
606 _T("Use c&ustom disabled images\tCtrl-U"),
607 _T("Switch between using system-generated and custom disabled images"));
610 tbarMenu
->AppendSeparator();
611 tbarMenu
->AppendRadioItem(IDM_TOOLBAR_TOP_ORIENTATION
,
612 _T("Set toolbar at the top of the window"),
613 _T("Set toolbar at the top of the window"));
614 tbarMenu
->AppendRadioItem(IDM_TOOLBAR_LEFT_ORIENTATION
,
615 _T("Set toolbar at the left of the window"),
616 _T("Set toolbar at the left of the window"));
617 tbarMenu
->AppendRadioItem(IDM_TOOLBAR_BOTTOM_ORIENTATION
,
618 _T("Set toolbar at the bottom of the window"),
619 _T("Set toolbar at the bottom of the window"));
620 tbarMenu
->AppendRadioItem(IDM_TOOLBAR_RIGHT_ORIENTATION
,
621 _T("Set toolbar at the right edge of the window"),
622 _T("Set toolbar at the right edge of the window"));
623 tbarMenu
->AppendSeparator();
625 tbarMenu
->Append(IDM_TOOLBAR_ENABLEPRINT
, _T("&Enable print button\tCtrl-E"));
626 tbarMenu
->Append(IDM_TOOLBAR_DELETEPRINT
, _T("&Delete print button\tCtrl-D"));
627 tbarMenu
->Append(IDM_TOOLBAR_INSERTPRINT
, _T("&Insert print button\tCtrl-I"));
628 tbarMenu
->Append(IDM_TOOLBAR_TOGGLEHELP
, _T("Toggle &help button\tCtrl-T"));
629 tbarMenu
->AppendSeparator();
630 tbarMenu
->Append(IDM_TOOLBAR_TOGGLERADIOBTN1
, _T("Toggle &1st radio button\tCtrl-1"));
631 tbarMenu
->Append(IDM_TOOLBAR_TOGGLERADIOBTN2
, _T("Toggle &2nd radio button\tCtrl-2"));
632 tbarMenu
->Append(IDM_TOOLBAR_TOGGLERADIOBTN3
, _T("Toggle &3rd radio button\tCtrl-3"));
633 tbarMenu
->AppendSeparator();
634 tbarMenu
->Append(IDM_TOOLBAR_CHANGE_TOOLTIP
, _T("Change tool tip"));
635 tbarMenu
->AppendSeparator();
636 tbarMenu
->AppendRadioItem(IDM_TOOLBAR_SHOW_TEXT
, _T("Show &text\tCtrl-Alt-T"));
637 tbarMenu
->AppendRadioItem(IDM_TOOLBAR_SHOW_ICONS
, _T("Show &icons\tCtrl-Alt-I"));
638 tbarMenu
->AppendRadioItem(IDM_TOOLBAR_SHOW_BOTH
, _T("Show &both\tCtrl-Alt-B"));
639 tbarMenu
->AppendSeparator();
640 tbarMenu
->Append(IDM_TOOLBAR_CUSTOM_PATH
, _T("Custom &bitmap...\tCtrl-B"));
642 wxMenu
*fileMenu
= new wxMenu
;
643 fileMenu
->Append(wxID_EXIT
, _T("E&xit\tAlt-X"), _T("Quit toolbar sample") );
645 wxMenu
*helpMenu
= new wxMenu
;
646 helpMenu
->Append(wxID_HELP
, _T("&About"), _T("About toolbar sample"));
648 wxMenuBar
* menuBar
= new wxMenuBar( wxMB_DOCKABLE
);
650 menuBar
->Append(fileMenu
, _T("&File"));
651 menuBar
->Append(tbarMenu
, _T("&Toolbar"));
652 menuBar
->Append(helpMenu
, _T("&Help"));
654 // Associate the menu bar with the frame
657 menuBar
->Check(IDM_TOOLBAR_SHOW_BOTH
, true);
658 menuBar
->Check(IDM_TOOLBAR_TOGGLETOOLTIPS
, true);
660 menuBar
->Check(IDM_TOOLBAR_TOP_ORIENTATION
, true );
661 m_toolbarPosition
= TOOLBAR_TOP
;
663 // Create the toolbar
666 m_panel
= new wxPanel(this, wxID_ANY
);
667 #if USE_UNMANAGED_TOOLBAR
668 m_extraToolBar
= new wxToolBar(m_panel
, wxID_ANY
, wxDefaultPosition
, wxDefaultSize
, wxTB_TEXT
|wxTB_FLAT
|wxTB_TOP
);
669 PopulateToolbar(m_extraToolBar
);
671 m_extraToolBar
= NULL
;
674 m_textWindow
= new wxTextCtrl(m_panel
, wxID_ANY
, wxEmptyString
, wxDefaultPosition
, wxDefaultSize
, wxTE_MULTILINE
);
676 wxBoxSizer
* sizer
= new wxBoxSizer(wxVERTICAL
);
677 m_panel
->SetSizer(sizer
);
679 sizer
->Add(m_extraToolBar
, 0, wxEXPAND
, 0);
681 sizer
->Add(m_textWindow
, 1, wxEXPAND
, 0);
684 control
= new wxControl( m_panel
, -1, wxPoint(30,20), wxSize(50,50), wxBORDER_SUNKEN
);
685 control
= new wxControl( m_panel
, -1, wxPoint(130,20), wxSize(50,50), wxBORDER_SIMPLE
);
686 control
= new wxControl( m_panel
, -1, wxPoint(230,20), wxSize(50,50), wxBORDER_RAISED
);
687 control
= new wxControl( m_panel
, -1, wxPoint(330,20), wxSize(50,50), wxBORDER_THEME
);
689 wxScrolledWindow
*scrolled
;
690 scrolled
= new wxScrolledWindow( m_panel
, -1, wxPoint(30,120), wxSize(80,80), wxHSCROLL
|wxVSCROLL
| wxBORDER_SUNKEN
);
691 scrolled
->SetVirtualSize(400,400);
692 scrolled
->SetScrollRate(10,10);
693 scrolled
= new wxScrolledWindow( m_panel
, -1, wxPoint(130,120), wxSize(80,80), wxHSCROLL
|wxVSCROLL
| wxBORDER_SIMPLE
);
694 scrolled
->SetVirtualSize(400,400);
695 scrolled
->SetScrollRate(10,10);
696 scrolled
= new wxScrolledWindow( m_panel
, -1, wxPoint(230,120), wxSize(80,80), wxHSCROLL
|wxVSCROLL
| wxBORDER_RAISED
);
697 scrolled
->SetVirtualSize(400,400);
698 scrolled
->SetScrollRate(10,10);
701 void MyFrame::LayoutChildren()
703 wxSize size
= GetClientSize();
708 m_tbar
->SetSize(0, 0, wxDefaultCoord
, size
.y
);
710 offset
= m_tbar
->GetSize().x
;
717 m_panel
->SetSize(offset
, 0, size
.x
- offset
, size
.y
);
720 void MyFrame::OnSize(wxSizeEvent
& event
)
732 void MyFrame::OnToggleToolbar(wxCommandEvent
& WXUNUSED(event
))
734 wxToolBar
*tbar
= GetToolBar();
748 void MyFrame::OnToggleHorizontalText(wxCommandEvent
& WXUNUSED(event
))
750 m_horzText
= !m_horzText
;
755 void MyFrame::OnToggleAnotherToolbar(wxCommandEvent
& WXUNUSED(event
))
764 long style
= GetToolBar() ? GetToolBar()->GetWindowStyle()
766 style
&= ~wxTB_HORIZONTAL
;
767 style
|= wxTB_VERTICAL
;
769 m_tbar
= new wxToolBar(this, wxID_ANY
,
770 wxDefaultPosition
, wxDefaultSize
,
773 m_tbar
->SetMargins(4, 4);
775 m_tbar
->AddRadioTool(IDM_TOOLBAR_OTHER_1
, _T("First"), wxBITMAP(new));
776 m_tbar
->AddRadioTool(IDM_TOOLBAR_OTHER_2
, _T("Second"), wxBITMAP(open
));
777 m_tbar
->AddRadioTool(IDM_TOOLBAR_OTHER_3
, _T("Third"), wxBITMAP(save
));
778 m_tbar
->AddSeparator();
779 m_tbar
->AddTool(wxID_HELP
, _T("Help"), wxBITMAP(help
));
787 void MyFrame::OnToggleToolbarSize(wxCommandEvent
& WXUNUSED(event
))
789 m_smallToolbar
= !m_smallToolbar
;
794 void MyFrame::OnToggleToolbarRows(wxCommandEvent
& WXUNUSED(event
))
796 // m_rows may be only 1 or 2
799 GetToolBar()->SetRows(!(GetToolBar()->IsVertical()) ? m_rows
: 10 / m_rows
);
801 //RecreateToolbar(); -- this is unneeded
804 void MyFrame::OnToggleTooltips(wxCommandEvent
& WXUNUSED(event
))
806 m_showTooltips
= !m_showTooltips
;
811 void MyFrame::OnToggleCustomDisabled(wxCommandEvent
& WXUNUSED(event
))
813 m_useCustomDisabled
= !m_useCustomDisabled
;
818 void MyFrame::OnChangeOrientation(wxCommandEvent
& event
)
820 switch( event
.GetId() )
822 case IDM_TOOLBAR_LEFT_ORIENTATION
:
823 m_toolbarPosition
= TOOLBAR_LEFT
;
825 case IDM_TOOLBAR_TOP_ORIENTATION
:
826 m_toolbarPosition
= TOOLBAR_TOP
;
828 case IDM_TOOLBAR_RIGHT_ORIENTATION
:
829 m_toolbarPosition
= TOOLBAR_RIGHT
;
831 case IDM_TOOLBAR_BOTTOM_ORIENTATION
:
832 m_toolbarPosition
= TOOLBAR_BOTTOM
;
838 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
843 void MyFrame::OnAbout(wxCommandEvent
& event
)
845 if ( event
.IsChecked() )
846 m_textWindow
->WriteText( _T("Help button down now.\n") );
848 m_textWindow
->WriteText( _T("Help button up now.\n") );
850 (void)wxMessageBox(_T("wxWidgets toolbar sample"), _T("About wxToolBar"));
853 void MyFrame::OnToolLeftClick(wxCommandEvent
& event
)
856 str
.Printf( _T("Clicked on tool %d\n"), event
.GetId());
857 m_textWindow
->WriteText( str
);
859 if (event
.GetId() == wxID_COPY
)
864 if (event
.GetId() == wxID_CUT
)
869 if (event
.GetId() == wxID_PRINT
)
875 void MyFrame::OnToolRightClick(wxCommandEvent
& event
)
877 m_textWindow
->AppendText(
878 wxString::Format(_T("Tool %d right clicked.\n"),
879 (int) event
.GetInt()));
882 void MyFrame::OnCombo(wxCommandEvent
& event
)
884 wxLogStatus(_T("Combobox string '%s' selected"), event
.GetString().c_str());
887 void MyFrame::DoEnablePrint()
892 wxToolBarBase
*tb
= GetToolBar();
893 tb
->EnableTool(wxID_PRINT
, !tb
->GetToolEnabled(wxID_PRINT
));
896 void MyFrame::DoDeletePrint()
901 wxToolBarBase
*tb
= GetToolBar();
902 tb
->DeleteTool( wxID_PRINT
);
907 void MyFrame::DoToggleHelp()
909 wxToolBarBase
*tb
= GetToolBar();
910 tb
->ToggleTool( wxID_HELP
, !tb
->GetToolState( wxID_HELP
) );
913 void MyFrame::OnUpdateCopyAndCut(wxUpdateUIEvent
& event
)
915 event
.Enable( m_textWindow
->CanCopy() );
918 void MyFrame::OnUpdateToggleHorzText(wxUpdateUIEvent
& event
)
920 wxToolBar
*tbar
= GetToolBar();
921 event
.Enable( tbar
&&
922 tbar
->HasFlag(wxTB_TEXT
) &&
923 !tbar
->HasFlag(wxTB_NOICONS
) );
926 void MyFrame::OnChangeToolTip(wxCommandEvent
& WXUNUSED(event
))
928 GetToolBar()->SetToolShortHelp(wxID_NEW
, _T("New toolbar button"));
931 void MyFrame::OnToolbarStyle(wxCommandEvent
& event
)
933 long style
= GetToolBar()->GetWindowStyle();
934 style
&= ~(wxTB_NOICONS
| wxTB_TEXT
);
936 switch ( event
.GetId() )
938 case IDM_TOOLBAR_SHOW_TEXT
:
939 style
|= wxTB_NOICONS
| wxTB_TEXT
;
942 case IDM_TOOLBAR_SHOW_ICONS
:
946 case IDM_TOOLBAR_SHOW_BOTH
:
950 GetToolBar()->SetWindowStyle(style
);
953 void MyFrame::OnToolbarCustomBitmap(wxCommandEvent
& WXUNUSED(event
))
955 m_pathBmp
= wxFileSelector(_T("Custom bitmap path"));
960 void MyFrame::OnInsertPrint(wxCommandEvent
& WXUNUSED(event
))
964 wxToolBarBase
*tb
= GetToolBar();
965 tb
->InsertTool(0, wxID_PRINT
, _T("New print"),
966 wxBITMAP(print
), wxNullBitmap
,
968 _T("Delete this tool"),
969 _T("This button was inserted into the toolbar"));
971 // must call Realize() after adding a new button
975 void MyFrame::OnToggleRadioBtn(wxCommandEvent
& event
)
979 m_tbar
->ToggleTool(IDM_TOOLBAR_OTHER_1
+
980 event
.GetId() - IDM_TOOLBAR_TOGGLERADIOBTN1
, true);
984 void MyFrame::OnToolDropdown(wxCommandEvent
& event
)
987 str
.Printf( _T("Dropdown on tool %d\n"), event
.GetId());
988 m_textWindow
->WriteText( str
);