]>
Commit | Line | Data |
---|---|---|
14d1ccd8 | 1 | ///////////////////////////////////////////////////////////////////////////// |
fc6bbc6d | 2 | // Name: toolbar.cpp |
14d1ccd8 JS |
3 | // Purpose: wxToolBar sample |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 04/01/98 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Julian Smart | |
ad9bb75f | 9 | // Licence: wxWindows licence |
14d1ccd8 JS |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
ad9bb75f VZ |
12 | // ============================================================================ |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
19 | ||
14d1ccd8 | 20 | // For compilers that support precompilation, includes "wx/wx.h". |
92a19c2e | 21 | #include "wx/wxprec.h" |
14d1ccd8 JS |
22 | |
23 | #ifdef __BORLANDC__ | |
ad9bb75f | 24 | #pragma hdrstop |
14d1ccd8 JS |
25 | #endif |
26 | ||
27 | #ifndef WX_PRECOMP | |
5f4d35b8 | 28 | #include "wx/wx.h" |
14d1ccd8 JS |
29 | #endif |
30 | ||
5f4d35b8 WS |
31 | #include "wx/toolbar.h" |
32 | #include "wx/log.h" | |
33 | #include "wx/image.h" | |
5e3b8b93 | 34 | #include "wx/filedlg.h" |
b529726e RR |
35 | #include "wx/spinctrl.h" |
36 | #include "wx/srchctrl.h" | |
8bbe427f | 37 | |
f6bcfd97 | 38 | // define this to use XPMs everywhere (by default, BMPs are used under Win) |
0ed1d09c | 39 | // BMPs use less space, but aren't compiled into the executable on other platforms |
f6bcfd97 BP |
40 | #ifdef __WXMSW__ |
41 | #define USE_XPM_BITMAPS 0 | |
42 | #else | |
43 | #define USE_XPM_BITMAPS 1 | |
44 | #endif | |
45 | ||
f6bcfd97 BP |
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 | |
49 | ||
079b2f6b JS |
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 | |
55 | ||
ad9bb75f VZ |
56 | // ---------------------------------------------------------------------------- |
57 | // resources | |
58 | // ---------------------------------------------------------------------------- | |
14d1ccd8 | 59 | |
5f4d35b8 | 60 | #if !defined(__WXMSW__) && !defined(__WXPM__) |
ad9bb75f | 61 | #include "mondrian.xpm" |
5f4d35b8 WS |
62 | #endif |
63 | ||
64 | #if USE_XPM_BITMAPS | |
ad9bb75f VZ |
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" | |
5ef2e633 | 70 | #include "bitmaps/preview.xpm" // paste XPM |
ad9bb75f | 71 | #include "bitmaps/print.xpm" |
ad9bb75f | 72 | #include "bitmaps/help.xpm" |
f6bcfd97 | 73 | #endif // USE_XPM_BITMAPS |
ad9bb75f | 74 | |
7a976304 VZ |
75 | enum Positions |
76 | { | |
77 | TOOLBAR_LEFT, | |
78 | TOOLBAR_TOP, | |
79 | TOOLBAR_RIGHT, | |
80 | TOOLBAR_BOTTOM | |
81 | }; | |
82 | ||
ad9bb75f VZ |
83 | // ---------------------------------------------------------------------------- |
84 | // classes | |
85 | // ---------------------------------------------------------------------------- | |
86 | ||
87 | // Define a new application | |
5ef2e633 | 88 | class MyApp : public wxApp |
ad9bb75f VZ |
89 | { |
90 | public: | |
91 | bool OnInit(); | |
ad9bb75f | 92 | }; |
47908e25 | 93 | |
ad9bb75f VZ |
94 | // Define a new frame |
95 | class MyFrame: public wxFrame | |
96 | { | |
97 | public: | |
98 | MyFrame(wxFrame *parent, | |
bc2ec626 | 99 | wxWindowID id = wxID_ANY, |
ab1ca7b3 | 100 | const wxString& title = _T("wxToolBar Sample"), |
ad9bb75f VZ |
101 | const wxPoint& pos = wxDefaultPosition, |
102 | const wxSize& size = wxDefaultSize, | |
229de929 | 103 | long style = wxDEFAULT_FRAME_STYLE|wxCLIP_CHILDREN|wxNO_FULL_REPAINT_ON_RESIZE); |
14d1ccd8 | 104 | |
079b2f6b | 105 | void PopulateToolbar(wxToolBarBase* toolBar); |
5ef2e633 VZ |
106 | void RecreateToolbar(); |
107 | ||
ad9bb75f VZ |
108 | void OnQuit(wxCommandEvent& event); |
109 | void OnAbout(wxCommandEvent& event); | |
110 | ||
f6bcfd97 BP |
111 | void OnSize(wxSizeEvent& event); |
112 | ||
ba0abe3c | 113 | void OnToggleToolbar(wxCommandEvent& event); |
f6bcfd97 | 114 | void OnToggleAnotherToolbar(wxCommandEvent& event); |
96dc4236 | 115 | void OnToggleHorizontalText(wxCommandEvent& WXUNUSED(event)); |
f6bcfd97 | 116 | |
5ef2e633 | 117 | void OnToggleToolbarSize(wxCommandEvent& event); |
7a976304 | 118 | void OnChangeOrientation(wxCommandEvent& event); |
98066234 | 119 | void OnToggleToolbarRows(wxCommandEvent& event); |
6a1b3ead | 120 | void OnToggleTooltips(wxCommandEvent& event); |
8d0a7b56 | 121 | void OnToggleCustomDisabled(wxCommandEvent& event); |
5ef2e633 | 122 | |
ad4ae6ed VZ |
123 | void OnEnablePrint(wxCommandEvent& WXUNUSED(event)) { DoEnablePrint(); } |
124 | void OnDeletePrint(wxCommandEvent& WXUNUSED(event)) { DoDeletePrint(); } | |
bdc72a22 | 125 | void OnInsertPrint(wxCommandEvent& event); |
a1f79c1e | 126 | void OnChangeToolTip(wxCommandEvent& event); |
ad4ae6ed | 127 | void OnToggleHelp(wxCommandEvent& WXUNUSED(event)) { DoToggleHelp(); } |
3bf4189d | 128 | void OnToggleRadioBtn(wxCommandEvent& event); |
ad9bb75f | 129 | |
ec483b11 | 130 | void OnToolbarStyle(wxCommandEvent& event); |
5e3b8b93 | 131 | void OnToolbarCustomBitmap(wxCommandEvent& event); |
ec483b11 | 132 | |
ad9bb75f | 133 | void OnToolLeftClick(wxCommandEvent& event); |
e052a316 | 134 | void OnToolRightClick(wxCommandEvent& event); |
a9a0ceca | 135 | void OnToolDropdown(wxCommandEvent& event); |
ad9bb75f | 136 | |
1c383dba VZ |
137 | void OnCombo(wxCommandEvent& event); |
138 | ||
5ef2e633 | 139 | void OnUpdateCopyAndCut(wxUpdateUIEvent& event); |
96dc4236 | 140 | void OnUpdateToggleHorzText(wxUpdateUIEvent& event); |
3bf4189d VZ |
141 | void OnUpdateToggleRadioBtn(wxUpdateUIEvent& event) |
142 | { event.Enable( m_tbar != NULL ); } | |
5ef2e633 | 143 | |
ad9bb75f VZ |
144 | private: |
145 | void DoEnablePrint(); | |
97d7bfb8 | 146 | void DoDeletePrint(); |
ad9bb75f VZ |
147 | void DoToggleHelp(); |
148 | ||
f6bcfd97 BP |
149 | void LayoutChildren(); |
150 | ||
5ef2e633 | 151 | bool m_smallToolbar, |
8d0a7b56 | 152 | m_horzText, |
6a1b3ead VZ |
153 | m_useCustomDisabled, |
154 | m_showTooltips; | |
98066234 VZ |
155 | size_t m_rows; // 1 or 2 only |
156 | ||
2b5f62a0 VZ |
157 | // the number of print buttons we have (they're added/removed dynamically) |
158 | size_t m_nPrint; | |
159 | ||
7a976304 VZ |
160 | // store toolbar position for future use |
161 | Positions m_toolbarPosition; | |
162 | ||
f6bcfd97 BP |
163 | wxTextCtrl *m_textWindow; |
164 | ||
079b2f6b JS |
165 | wxPanel *m_panel; |
166 | wxToolBar *m_extraToolBar; | |
167 | ||
f6bcfd97 | 168 | wxToolBar *m_tbar; |
ad9bb75f | 169 | |
5e3b8b93 VZ |
170 | // the path to the custom bitmap for the test toolbar tool |
171 | wxString m_pathBmp; | |
172 | ||
ad9bb75f VZ |
173 | DECLARE_EVENT_TABLE() |
174 | }; | |
175 | ||
176 | // ---------------------------------------------------------------------------- | |
177 | // constants | |
178 | // ---------------------------------------------------------------------------- | |
179 | ||
180 | const int ID_TOOLBAR = 500; | |
181 | ||
dd46ee66 | 182 | static const long TOOLBAR_STYLE = wxTB_FLAT | wxTB_DOCKABLE | wxTB_TEXT; |
86f65864 | 183 | |
ad9bb75f | 184 | enum |
14d1ccd8 | 185 | { |
5ef2e633 | 186 | IDM_TOOLBAR_TOGGLETOOLBARSIZE = 200, |
98066234 | 187 | IDM_TOOLBAR_TOGGLETOOLBARROWS, |
6a1b3ead | 188 | IDM_TOOLBAR_TOGGLETOOLTIPS, |
8d0a7b56 | 189 | IDM_TOOLBAR_TOGGLECUSTOMDISABLED, |
ad9bb75f | 190 | IDM_TOOLBAR_ENABLEPRINT, |
97d7bfb8 | 191 | IDM_TOOLBAR_DELETEPRINT, |
bdc72a22 | 192 | IDM_TOOLBAR_INSERTPRINT, |
1c383dba | 193 | IDM_TOOLBAR_TOGGLEHELP, |
3bf4189d VZ |
194 | IDM_TOOLBAR_TOGGLERADIOBTN1, |
195 | IDM_TOOLBAR_TOGGLERADIOBTN2, | |
196 | IDM_TOOLBAR_TOGGLERADIOBTN3, | |
ba0abe3c | 197 | IDM_TOOLBAR_TOGGLE_TOOLBAR, |
96dc4236 | 198 | IDM_TOOLBAR_TOGGLE_HORIZONTAL_TEXT, |
f6bcfd97 | 199 | IDM_TOOLBAR_TOGGLE_ANOTHER_TOOLBAR, |
a1f79c1e | 200 | IDM_TOOLBAR_CHANGE_TOOLTIP, |
ec483b11 VZ |
201 | IDM_TOOLBAR_SHOW_TEXT, |
202 | IDM_TOOLBAR_SHOW_ICONS, | |
203 | IDM_TOOLBAR_SHOW_BOTH, | |
5e3b8b93 | 204 | IDM_TOOLBAR_CUSTOM_PATH, |
7a976304 VZ |
205 | IDM_TOOLBAR_TOP_ORIENTATION, |
206 | IDM_TOOLBAR_LEFT_ORIENTATION, | |
5b2acc3a | 207 | IDM_TOOLBAR_BOTTOM_ORIENTATION, |
7a976304 | 208 | IDM_TOOLBAR_RIGHT_ORIENTATION, |
3bf4189d VZ |
209 | IDM_TOOLBAR_OTHER_1, |
210 | IDM_TOOLBAR_OTHER_2, | |
211 | IDM_TOOLBAR_OTHER_3, | |
212 | ||
5b2acc3a RR |
213 | ID_COMBO = 1000, |
214 | ID_SPIN = 1001 | |
ad9bb75f | 215 | }; |
14d1ccd8 | 216 | |
ad9bb75f VZ |
217 | // ---------------------------------------------------------------------------- |
218 | // event tables | |
219 | // ---------------------------------------------------------------------------- | |
14d1ccd8 | 220 | |
ad9bb75f VZ |
221 | // Notice that wxID_HELP will be processed for the 'About' menu and the toolbar |
222 | // help button. | |
14d1ccd8 | 223 | |
ad9bb75f | 224 | BEGIN_EVENT_TABLE(MyFrame, wxFrame) |
f6bcfd97 BP |
225 | EVT_SIZE(MyFrame::OnSize) |
226 | ||
ad9bb75f VZ |
227 | EVT_MENU(wxID_EXIT, MyFrame::OnQuit) |
228 | EVT_MENU(wxID_HELP, MyFrame::OnAbout) | |
14d1ccd8 | 229 | |
ba0abe3c | 230 | EVT_MENU(IDM_TOOLBAR_TOGGLE_TOOLBAR, MyFrame::OnToggleToolbar) |
f6bcfd97 | 231 | EVT_MENU(IDM_TOOLBAR_TOGGLE_ANOTHER_TOOLBAR, MyFrame::OnToggleAnotherToolbar) |
96dc4236 | 232 | EVT_MENU(IDM_TOOLBAR_TOGGLE_HORIZONTAL_TEXT, MyFrame::OnToggleHorizontalText) |
f6bcfd97 | 233 | |
7a976304 | 234 | EVT_MENU_RANGE(IDM_TOOLBAR_TOP_ORIENTATION, IDM_TOOLBAR_RIGHT_ORIENTATION, MyFrame::OnChangeOrientation) |
5ef2e633 | 235 | EVT_MENU(IDM_TOOLBAR_TOGGLETOOLBARSIZE, MyFrame::OnToggleToolbarSize) |
98066234 | 236 | EVT_MENU(IDM_TOOLBAR_TOGGLETOOLBARROWS, MyFrame::OnToggleToolbarRows) |
6a1b3ead | 237 | EVT_MENU(IDM_TOOLBAR_TOGGLETOOLTIPS, MyFrame::OnToggleTooltips) |
8d0a7b56 | 238 | EVT_MENU(IDM_TOOLBAR_TOGGLECUSTOMDISABLED, MyFrame::OnToggleCustomDisabled) |
5ef2e633 | 239 | |
ad9bb75f | 240 | EVT_MENU(IDM_TOOLBAR_ENABLEPRINT, MyFrame::OnEnablePrint) |
97d7bfb8 | 241 | EVT_MENU(IDM_TOOLBAR_DELETEPRINT, MyFrame::OnDeletePrint) |
bdc72a22 | 242 | EVT_MENU(IDM_TOOLBAR_INSERTPRINT, MyFrame::OnInsertPrint) |
ad9bb75f | 243 | EVT_MENU(IDM_TOOLBAR_TOGGLEHELP, MyFrame::OnToggleHelp) |
3bf4189d VZ |
244 | EVT_MENU_RANGE(IDM_TOOLBAR_TOGGLERADIOBTN1, IDM_TOOLBAR_TOGGLERADIOBTN3, |
245 | MyFrame::OnToggleRadioBtn) | |
a1f79c1e | 246 | EVT_MENU(IDM_TOOLBAR_CHANGE_TOOLTIP, MyFrame::OnChangeToolTip) |
14d1ccd8 | 247 | |
ec483b11 VZ |
248 | EVT_MENU_RANGE(IDM_TOOLBAR_SHOW_TEXT, IDM_TOOLBAR_SHOW_BOTH, |
249 | MyFrame::OnToolbarStyle) | |
250 | ||
5e3b8b93 VZ |
251 | EVT_MENU(IDM_TOOLBAR_CUSTOM_PATH, MyFrame::OnToolbarCustomBitmap) |
252 | ||
bc2ec626 | 253 | EVT_MENU(wxID_ANY, MyFrame::OnToolLeftClick) |
14d1ccd8 | 254 | |
1c383dba VZ |
255 | EVT_COMBOBOX(ID_COMBO, MyFrame::OnCombo) |
256 | ||
e052a316 | 257 | EVT_TOOL_RCLICKED(wxID_ANY, MyFrame::OnToolRightClick) |
5ef2e633 | 258 | |
a9a0ceca VZ |
259 | EVT_TOOL_DROPDOWN(wxID_ANY, MyFrame::OnToolDropdown) |
260 | ||
5ef2e633 VZ |
261 | EVT_UPDATE_UI(wxID_COPY, MyFrame::OnUpdateCopyAndCut) |
262 | EVT_UPDATE_UI(wxID_CUT, MyFrame::OnUpdateCopyAndCut) | |
96dc4236 | 263 | |
3bf4189d VZ |
264 | EVT_UPDATE_UI_RANGE(IDM_TOOLBAR_TOGGLERADIOBTN1, |
265 | IDM_TOOLBAR_TOGGLERADIOBTN3, | |
266 | MyFrame::OnUpdateToggleRadioBtn) | |
96dc4236 VZ |
267 | EVT_UPDATE_UI(IDM_TOOLBAR_TOGGLE_HORIZONTAL_TEXT, |
268 | MyFrame::OnUpdateToggleHorzText) | |
ad9bb75f | 269 | END_EVENT_TABLE() |
14d1ccd8 | 270 | |
ad9bb75f VZ |
271 | // ============================================================================ |
272 | // implementation | |
273 | // ============================================================================ | |
14d1ccd8 | 274 | |
ad9bb75f VZ |
275 | // ---------------------------------------------------------------------------- |
276 | // MyApp | |
277 | // ---------------------------------------------------------------------------- | |
14d1ccd8 | 278 | |
ad9bb75f | 279 | IMPLEMENT_APP(MyApp) |
14d1ccd8 | 280 | |
ad9bb75f VZ |
281 | // The `main program' equivalent, creating the windows and returning the |
282 | // main frame | |
283 | bool MyApp::OnInit() | |
284 | { | |
45e6e6f8 VZ |
285 | if ( !wxApp::OnInit() ) |
286 | return false; | |
287 | ||
ad9bb75f | 288 | // Create the main frame window |
bc2ec626 | 289 | MyFrame* frame = new MyFrame((wxFrame *) NULL, wxID_ANY, |
ab1ca7b3 | 290 | _T("wxToolBar Sample"), |
5e3b8b93 | 291 | wxPoint(100, 100), wxSize(550, 300)); |
14d1ccd8 | 292 | |
bc2ec626 | 293 | frame->Show(true); |
7fb23305 | 294 | |
8520f137 | 295 | #if wxUSE_STATUSBAR |
be5a51fb | 296 | frame->SetStatusText(_T("Hello, wxWidgets")); |
0cfc2a92 | 297 | #endif |
7fb23305 | 298 | |
5e3b8b93 VZ |
299 | wxInitAllImageHandlers(); |
300 | ||
7fb23305 VZ |
301 | SetTopWindow(frame); |
302 | ||
bc2ec626 | 303 | return true; |
14d1ccd8 JS |
304 | } |
305 | ||
5ef2e633 | 306 | void MyFrame::RecreateToolbar() |
14d1ccd8 | 307 | { |
bf95a04f JS |
308 | #ifdef __WXWINCE__ |
309 | // On Windows CE, we should not delete the | |
310 | // previous toolbar in case it contains the menubar. | |
34621cc5 | 311 | // We'll try to accommodate this usage in due course. |
bf95a04f JS |
312 | wxToolBar* toolBar = CreateToolBar(); |
313 | #else | |
5ef2e633 | 314 | // delete and recreate the toolbar |
ad4ae6ed | 315 | wxToolBarBase *toolBar = GetToolBar(); |
ec483b11 VZ |
316 | long style = toolBar ? toolBar->GetWindowStyle() : TOOLBAR_STYLE; |
317 | ||
5ef2e633 | 318 | delete toolBar; |
14d1ccd8 | 319 | |
5ef2e633 VZ |
320 | SetToolBar(NULL); |
321 | ||
7a976304 VZ |
322 | style &= ~(wxTB_HORIZONTAL | wxTB_VERTICAL | wxTB_BOTTOM | wxTB_RIGHT | wxTB_HORZ_LAYOUT); |
323 | switch( m_toolbarPosition ) | |
324 | { | |
325 | case TOOLBAR_LEFT: | |
326 | style |= wxTB_LEFT; | |
327 | break; | |
328 | case TOOLBAR_TOP: | |
329 | style |= wxTB_TOP; | |
330 | break; | |
331 | case TOOLBAR_RIGHT: | |
332 | style |= wxTB_RIGHT; | |
333 | break; | |
334 | case TOOLBAR_BOTTOM: | |
5b2acc3a | 335 | style |= wxTB_BOTTOM; |
7a976304 VZ |
336 | break; |
337 | } | |
96dc4236 | 338 | |
6a1b3ead VZ |
339 | if ( m_showTooltips ) |
340 | style &= ~wxTB_NO_TOOLTIPS; | |
341 | else | |
342 | style |= wxTB_NO_TOOLTIPS; | |
343 | ||
96dc4236 VZ |
344 | if ( style & wxTB_TEXT && !(style & wxTB_NOICONS) && m_horzText ) |
345 | style |= wxTB_HORZ_LAYOUT; | |
5ef2e633 VZ |
346 | |
347 | toolBar = CreateToolBar(style, ID_TOOLBAR); | |
bf95a04f | 348 | #endif |
5ef2e633 | 349 | |
079b2f6b JS |
350 | PopulateToolbar(toolBar); |
351 | } | |
352 | ||
353 | void MyFrame::PopulateToolbar(wxToolBarBase* toolBar) | |
354 | { | |
5ef2e633 | 355 | // Set up toolbar |
8d0a7b56 VZ |
356 | enum |
357 | { | |
358 | Tool_new, | |
359 | Tool_open, | |
360 | Tool_save, | |
361 | Tool_copy, | |
362 | Tool_cut, | |
363 | Tool_paste, | |
364 | Tool_print, | |
365 | Tool_help, | |
366 | Tool_Max | |
367 | }; | |
368 | ||
369 | wxBitmap toolBarBitmaps[Tool_Max]; | |
5ef2e633 | 370 | |
f6bcfd97 | 371 | #if USE_XPM_BITMAPS |
8d0a7b56 VZ |
372 | #define INIT_TOOL_BMP(bmp) \ |
373 | toolBarBitmaps[Tool_##bmp] = wxBitmap(bmp##_xpm) | |
f6bcfd97 | 374 | #else // !USE_XPM_BITMAPS |
8d0a7b56 VZ |
375 | #define INIT_TOOL_BMP(bmp) \ |
376 | toolBarBitmaps[Tool_##bmp] = wxBITMAP(bmp) | |
f6bcfd97 | 377 | #endif // USE_XPM_BITMAPS/!USE_XPM_BITMAPS |
40515a21 | 378 | |
8d0a7b56 VZ |
379 | INIT_TOOL_BMP(new); |
380 | INIT_TOOL_BMP(open); | |
381 | INIT_TOOL_BMP(save); | |
382 | INIT_TOOL_BMP(copy); | |
383 | INIT_TOOL_BMP(cut); | |
384 | INIT_TOOL_BMP(paste); | |
385 | INIT_TOOL_BMP(print); | |
386 | INIT_TOOL_BMP(help); | |
387 | ||
388 | int w = toolBarBitmaps[Tool_new].GetWidth(), | |
389 | h = toolBarBitmaps[Tool_new].GetHeight(); | |
390 | ||
5ef2e633 VZ |
391 | if ( !m_smallToolbar ) |
392 | { | |
8d0a7b56 VZ |
393 | w *= 2; |
394 | h *= 2; | |
395 | ||
396 | for ( size_t n = Tool_new; n < WXSIZEOF(toolBarBitmaps); n++ ) | |
40515a21 VZ |
397 | { |
398 | toolBarBitmaps[n] = | |
368d59f0 | 399 | wxBitmap(toolBarBitmaps[n].ConvertToImage().Scale(w, h)); |
40515a21 | 400 | } |
5ef2e633 | 401 | } |
14d1ccd8 | 402 | |
6a1b3ead VZ |
403 | toolBar->SetToolBitmapSize(wxSize(w, h)); |
404 | ||
e112f019 | 405 | toolBar->AddTool(wxID_NEW, _T("New"), |
a9a0ceca | 406 | toolBarBitmaps[Tool_new], wxNullBitmap, wxITEM_DROPDOWN, |
e112f019 | 407 | _T("New file"), _T("This is help for new file tool")); |
a9a0ceca VZ |
408 | |
409 | wxMenu* menu = new wxMenu; | |
410 | menu->Append(wxID_ANY, _T("&First dummy item")); | |
411 | menu->Append(wxID_ANY, _T("&Second dummy item")); | |
412 | menu->AppendSeparator(); | |
413 | menu->Append(wxID_EXIT, _T("Exit")); | |
414 | toolBar->SetDropdownMenu(wxID_NEW, menu); | |
415 | ||
e112f019 VZ |
416 | toolBar->AddTool(wxID_OPEN, _T("Open"), |
417 | toolBarBitmaps[Tool_open], wxNullBitmap, wxITEM_NORMAL, | |
418 | _T("Open file"), _T("This is help for open file tool")); | |
14d1ccd8 | 419 | |
aae91497 | 420 | // the generic toolbar doesn't really support this |
27cc9142 | 421 | #if wxUSE_TOOLBAR_NATIVE && !defined(__WXX11__) || defined(__WXUNIVERSAL__) |
5ef2e633 | 422 | // adding a combo to a vertical toolbar is not very smart |
7a976304 | 423 | if ( !( toolBar->IsVertical() ) ) |
5ef2e633 | 424 | { |
b529726e | 425 | wxComboBox *combo = new wxComboBox(toolBar, ID_COMBO, wxEmptyString, wxDefaultPosition, wxSize(100,-1) ); |
2b5f62a0 VZ |
426 | combo->Append(_T("This")); |
427 | combo->Append(_T("is a")); | |
428 | combo->Append(_T("combobox")); | |
429 | combo->Append(_T("in a")); | |
430 | combo->Append(_T("toolbar")); | |
cdb11cb9 | 431 | toolBar->AddControl(combo, _T("Combo Label")); |
6bbb8a8d | 432 | |
b529726e RR |
433 | wxSpinCtrl *spin = new wxSpinCtrl( toolBar, ID_SPIN, wxT("0"), wxDefaultPosition, wxSize(80,wxDefaultCoord), 0, 0, 100 ); |
434 | toolBar->AddControl( spin ); | |
cdb11cb9 | 435 | |
b529726e RR |
436 | wxTextCtrl *text = new wxTextCtrl( toolBar, -1, wxT("text"), wxDefaultPosition, wxSize(80,wxDefaultCoord) ); |
437 | toolBar->AddControl( text ); | |
cdb11cb9 | 438 | |
b529726e RR |
439 | wxSearchCtrl *srch = new wxSearchCtrl( toolBar, -1, wxT("xx"), wxDefaultPosition, wxSize(80,wxDefaultCoord), wxSUNKEN_BORDER ); |
440 | toolBar->AddControl( srch ); | |
5ef2e633 | 441 | } |
ad4ae6ed | 442 | #endif // toolbars which don't support controls |
14d1ccd8 | 443 | |
8d0a7b56 VZ |
444 | toolBar->AddTool(wxID_SAVE, _T("Save"), toolBarBitmaps[Tool_save], _T("Toggle button 1"), wxITEM_CHECK); |
445 | toolBar->AddTool(wxID_COPY, _T("Copy"), toolBarBitmaps[Tool_copy], _T("Toggle button 2"), wxITEM_CHECK); | |
446 | toolBar->AddTool(wxID_CUT, _T("Cut"), toolBarBitmaps[Tool_cut], _T("Toggle/Untoggle help button")); | |
447 | toolBar->AddTool(wxID_PASTE, _T("Paste"), toolBarBitmaps[Tool_paste], _T("Paste")); | |
448 | ||
449 | if ( m_useCustomDisabled ) | |
450 | { | |
451 | wxBitmap bmpDisabled(w, h); | |
452 | { | |
453 | wxMemoryDC dc; | |
454 | dc.SelectObject(bmpDisabled); | |
455 | dc.DrawBitmap(toolBarBitmaps[Tool_print], 0, 0); | |
456 | ||
457 | wxPen pen(*wxRED, 5); | |
458 | dc.SetPen(pen); | |
459 | dc.DrawLine(0, 0, w, h); | |
460 | } | |
461 | ||
462 | toolBar->AddTool(wxID_PRINT, _T("Print"), toolBarBitmaps[Tool_print], | |
463 | bmpDisabled); | |
464 | } | |
465 | else | |
466 | { | |
467 | toolBar->AddTool(wxID_PRINT, _T("Print"), toolBarBitmaps[Tool_print], | |
468 | _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.")); | |
469 | } | |
470 | ||
40515a21 | 471 | toolBar->AddSeparator(); |
8d0a7b56 | 472 | toolBar->AddTool(wxID_HELP, _T("Help"), toolBarBitmaps[Tool_help], _T("Help button"), wxITEM_CHECK); |
13437238 | 473 | |
5e3b8b93 VZ |
474 | if ( !m_pathBmp.empty() ) |
475 | { | |
476 | // create a tool with a custom bitmap for testing | |
477 | wxImage img(m_pathBmp); | |
478 | if ( img.Ok() ) | |
479 | { | |
480 | if ( img.GetWidth() > w && img.GetHeight() > h ) | |
481 | img = img.GetSubImage(wxRect(0, 0, w, h)); | |
482 | ||
483 | toolBar->AddSeparator(); | |
484 | toolBar->AddTool(wxID_ANY, _T("Custom"), img); | |
485 | } | |
486 | } | |
487 | ||
5ef2e633 VZ |
488 | // after adding the buttons to the toolbar, must call Realize() to reflect |
489 | // the changes | |
490 | toolBar->Realize(); | |
98066234 | 491 | |
7a976304 | 492 | toolBar->SetRows(!(toolBar->IsVertical()) ? m_rows : 10 / m_rows); |
14d1ccd8 JS |
493 | } |
494 | ||
ad9bb75f VZ |
495 | // ---------------------------------------------------------------------------- |
496 | // MyFrame | |
497 | // ---------------------------------------------------------------------------- | |
13437238 JS |
498 | |
499 | // Define my frame constructor | |
7fb23305 VZ |
500 | MyFrame::MyFrame(wxFrame* parent, |
501 | wxWindowID id, | |
502 | const wxString& title, | |
503 | const wxPoint& pos, | |
504 | const wxSize& size, | |
505 | long style) | |
506 | : wxFrame(parent, id, title, pos, size, style) | |
14d1ccd8 | 507 | { |
f6bcfd97 | 508 | m_tbar = NULL; |
98066234 | 509 | |
bc2ec626 | 510 | m_smallToolbar = true; |
bc2ec626 | 511 | m_horzText = false; |
8d0a7b56 | 512 | m_useCustomDisabled = false; |
6a1b3ead VZ |
513 | m_showTooltips = true; |
514 | ||
98066234 | 515 | m_rows = 1; |
2b5f62a0 | 516 | m_nPrint = 1; |
ad9bb75f | 517 | |
8520f137 | 518 | #if wxUSE_STATUSBAR |
ad9bb75f VZ |
519 | // Give it a status line |
520 | CreateStatusBar(); | |
0cfc2a92 | 521 | #endif |
ad9bb75f VZ |
522 | |
523 | // Give it an icon | |
524 | SetIcon(wxICON(mondrian)); | |
525 | ||
526 | // Make a menubar | |
527 | wxMenu *tbarMenu = new wxMenu; | |
ba0abe3c | 528 | tbarMenu->AppendCheckItem(IDM_TOOLBAR_TOGGLE_TOOLBAR, |
2b5f62a0 VZ |
529 | _T("Toggle &toolbar\tCtrl-Z"), |
530 | _T("Show or hide the toolbar")); | |
ba0abe3c VZ |
531 | |
532 | tbarMenu->AppendCheckItem(IDM_TOOLBAR_TOGGLE_ANOTHER_TOOLBAR, | |
2b5f62a0 VZ |
533 | _T("Toggle &another toolbar\tCtrl-A"), |
534 | _T("Show/hide another test toolbar")); | |
ba0abe3c | 535 | |
96dc4236 VZ |
536 | tbarMenu->AppendCheckItem(IDM_TOOLBAR_TOGGLE_HORIZONTAL_TEXT, |
537 | _T("Toggle hori&zontal text\tCtrl-H"), | |
538 | _T("Show text under/alongside the icon")); | |
539 | ||
ba0abe3c | 540 | tbarMenu->AppendCheckItem(IDM_TOOLBAR_TOGGLETOOLBARSIZE, |
2b5f62a0 VZ |
541 | _T("&Toggle toolbar size\tCtrl-S"), |
542 | _T("Toggle between big/small toolbar")); | |
ba0abe3c | 543 | |
ba0abe3c | 544 | tbarMenu->AppendCheckItem(IDM_TOOLBAR_TOGGLETOOLBARROWS, |
2b5f62a0 VZ |
545 | _T("Toggle number of &rows\tCtrl-R"), |
546 | _T("Toggle number of toolbar rows between 1 and 2")); | |
5ef2e633 | 547 | |
6a1b3ead VZ |
548 | tbarMenu->AppendCheckItem(IDM_TOOLBAR_TOGGLETOOLTIPS, |
549 | _T("Show &tooltips\tCtrl-L"), | |
550 | _T("Show tooltips for the toolbar tools")); | |
551 | ||
8d0a7b56 VZ |
552 | tbarMenu->AppendCheckItem(IDM_TOOLBAR_TOGGLECUSTOMDISABLED, |
553 | _T("Use c&ustom disabled images\tCtrl-U"), | |
554 | _T("Switch between using system-generated and custom disabled images")); | |
555 | ||
556 | ||
7a976304 VZ |
557 | tbarMenu->AppendSeparator(); |
558 | tbarMenu->AppendRadioItem(IDM_TOOLBAR_TOP_ORIENTATION, | |
559 | _T("Set toolbar at the top of the window"), | |
560 | _T("Set toolbar at the top of the window")); | |
561 | tbarMenu->AppendRadioItem(IDM_TOOLBAR_LEFT_ORIENTATION, | |
562 | _T("Set toolbar at the left of the window"), | |
563 | _T("Set toolbar at the left of the window")); | |
564 | tbarMenu->AppendRadioItem(IDM_TOOLBAR_BOTTOM_ORIENTATION, | |
5b2acc3a RR |
565 | _T("Set toolbar at the bottom of the window"), |
566 | _T("Set toolbar at the bottom of the window")); | |
7a976304 VZ |
567 | tbarMenu->AppendRadioItem(IDM_TOOLBAR_RIGHT_ORIENTATION, |
568 | _T("Set toolbar at the right edge of the window"), | |
569 | _T("Set toolbar at the right edge of the window")); | |
5ef2e633 VZ |
570 | tbarMenu->AppendSeparator(); |
571 | ||
5e3b8b93 VZ |
572 | tbarMenu->Append(IDM_TOOLBAR_ENABLEPRINT, _T("&Enable print button\tCtrl-E")); |
573 | tbarMenu->Append(IDM_TOOLBAR_DELETEPRINT, _T("&Delete print button\tCtrl-D")); | |
574 | tbarMenu->Append(IDM_TOOLBAR_INSERTPRINT, _T("&Insert print button\tCtrl-I")); | |
575 | tbarMenu->Append(IDM_TOOLBAR_TOGGLEHELP, _T("Toggle &help button\tCtrl-T")); | |
a1f79c1e | 576 | tbarMenu->AppendSeparator(); |
5e3b8b93 VZ |
577 | tbarMenu->Append(IDM_TOOLBAR_TOGGLERADIOBTN1, _T("Toggle &1st radio button\tCtrl-1")); |
578 | tbarMenu->Append(IDM_TOOLBAR_TOGGLERADIOBTN2, _T("Toggle &2nd radio button\tCtrl-2")); | |
579 | tbarMenu->Append(IDM_TOOLBAR_TOGGLERADIOBTN3, _T("Toggle &3rd radio button\tCtrl-3")); | |
3bf4189d | 580 | tbarMenu->AppendSeparator(); |
5e3b8b93 | 581 | tbarMenu->Append(IDM_TOOLBAR_CHANGE_TOOLTIP, _T("Change tool tip")); |
ec483b11 | 582 | tbarMenu->AppendSeparator(); |
f5e6e431 VZ |
583 | tbarMenu->AppendRadioItem(IDM_TOOLBAR_SHOW_TEXT, _T("Show &text\tCtrl-Alt-T")); |
584 | tbarMenu->AppendRadioItem(IDM_TOOLBAR_SHOW_ICONS, _T("Show &icons\tCtrl-Alt-I")); | |
585 | tbarMenu->AppendRadioItem(IDM_TOOLBAR_SHOW_BOTH, _T("Show &both\tCtrl-Alt-B")); | |
5e3b8b93 VZ |
586 | tbarMenu->AppendSeparator(); |
587 | tbarMenu->Append(IDM_TOOLBAR_CUSTOM_PATH, _T("Custom &bitmap...\tCtrl-B")); | |
b487a08f | 588 | |
ad9bb75f | 589 | wxMenu *fileMenu = new wxMenu; |
2b5f62a0 | 590 | fileMenu->Append(wxID_EXIT, _T("E&xit\tAlt-X"), _T("Quit toolbar sample") ); |
ad9bb75f | 591 | |
ad9bb75f | 592 | wxMenu *helpMenu = new wxMenu; |
2b5f62a0 | 593 | helpMenu->Append(wxID_HELP, _T("&About"), _T("About toolbar sample")); |
ad9bb75f VZ |
594 | |
595 | wxMenuBar* menuBar = new wxMenuBar( wxMB_DOCKABLE ); | |
596 | ||
2b5f62a0 VZ |
597 | menuBar->Append(fileMenu, _T("&File")); |
598 | menuBar->Append(tbarMenu, _T("&Toolbar")); | |
599 | menuBar->Append(helpMenu, _T("&Help")); | |
ad9bb75f VZ |
600 | |
601 | // Associate the menu bar with the frame | |
602 | SetMenuBar(menuBar); | |
603 | ||
bc2ec626 | 604 | menuBar->Check(IDM_TOOLBAR_SHOW_BOTH, true); |
6a1b3ead | 605 | menuBar->Check(IDM_TOOLBAR_TOGGLETOOLTIPS, true); |
c631abda | 606 | |
7a976304 VZ |
607 | menuBar->Check(IDM_TOOLBAR_TOP_ORIENTATION, true ); |
608 | m_toolbarPosition = TOOLBAR_TOP; | |
079b2f6b | 609 | |
ad9bb75f | 610 | // Create the toolbar |
5ef2e633 | 611 | RecreateToolbar(); |
949b8e62 | 612 | |
079b2f6b JS |
613 | m_panel = new wxPanel(this, wxID_ANY); |
614 | #if USE_UNMANAGED_TOOLBAR | |
615 | m_extraToolBar = new wxToolBar(m_panel, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTB_TEXT|wxTB_FLAT|wxTB_TOP); | |
616 | PopulateToolbar(m_extraToolBar); | |
617 | #else | |
618 | m_extraToolBar = NULL; | |
619 | #endif | |
620 | ||
621 | m_textWindow = new wxTextCtrl(m_panel, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE); | |
622 | ||
623 | wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL); | |
624 | m_panel->SetSizer(sizer); | |
625 | if (m_extraToolBar) | |
626 | sizer->Add(m_extraToolBar, 0, wxEXPAND, 0); | |
627 | sizer->Add(m_textWindow, 1, wxEXPAND, 0); | |
5ef2e633 | 628 | } |
ad9bb75f | 629 | |
f6bcfd97 BP |
630 | void MyFrame::LayoutChildren() |
631 | { | |
632 | wxSize size = GetClientSize(); | |
633 | ||
634 | int offset; | |
635 | if ( m_tbar ) | |
636 | { | |
7a7d2a14 | 637 | m_tbar->SetSize(0, 0, wxDefaultCoord, size.y); |
f6bcfd97 BP |
638 | |
639 | offset = m_tbar->GetSize().x; | |
640 | } | |
641 | else | |
642 | { | |
643 | offset = 0; | |
644 | } | |
645 | ||
079b2f6b | 646 | m_panel->SetSize(offset, 0, size.x - offset, size.y); |
f6bcfd97 BP |
647 | } |
648 | ||
649 | void MyFrame::OnSize(wxSizeEvent& event) | |
650 | { | |
651 | if ( m_tbar ) | |
652 | { | |
653 | LayoutChildren(); | |
654 | } | |
655 | else | |
656 | { | |
657 | event.Skip(); | |
658 | } | |
659 | } | |
660 | ||
ba0abe3c VZ |
661 | void MyFrame::OnToggleToolbar(wxCommandEvent& WXUNUSED(event)) |
662 | { | |
663 | wxToolBar *tbar = GetToolBar(); | |
664 | ||
665 | if ( !tbar ) | |
666 | { | |
667 | RecreateToolbar(); | |
668 | } | |
669 | else | |
670 | { | |
671 | delete tbar; | |
672 | ||
673 | SetToolBar(NULL); | |
674 | } | |
675 | } | |
676 | ||
96dc4236 VZ |
677 | void MyFrame::OnToggleHorizontalText(wxCommandEvent& WXUNUSED(event)) |
678 | { | |
679 | m_horzText = !m_horzText; | |
680 | ||
681 | RecreateToolbar(); | |
682 | } | |
683 | ||
f6bcfd97 BP |
684 | void MyFrame::OnToggleAnotherToolbar(wxCommandEvent& WXUNUSED(event)) |
685 | { | |
686 | if ( m_tbar ) | |
687 | { | |
688 | delete m_tbar; | |
689 | m_tbar = NULL; | |
690 | } | |
691 | else | |
692 | { | |
8927d6d1 VZ |
693 | long style = GetToolBar() ? GetToolBar()->GetWindowStyle() |
694 | : TOOLBAR_STYLE; | |
ec483b11 VZ |
695 | style &= ~wxTB_HORIZONTAL; |
696 | style |= wxTB_VERTICAL; | |
697 | ||
bc2ec626 | 698 | m_tbar = new wxToolBar(this, wxID_ANY, |
f6bcfd97 | 699 | wxDefaultPosition, wxDefaultSize, |
ec483b11 VZ |
700 | style); |
701 | ||
69c14ebe VZ |
702 | m_tbar->SetMargins(4, 4); |
703 | ||
3bf4189d VZ |
704 | m_tbar->AddRadioTool(IDM_TOOLBAR_OTHER_1, _T("First"), wxBITMAP(new)); |
705 | m_tbar->AddRadioTool(IDM_TOOLBAR_OTHER_2, _T("Second"), wxBITMAP(open)); | |
706 | m_tbar->AddRadioTool(IDM_TOOLBAR_OTHER_3, _T("Third"), wxBITMAP(save)); | |
ec483b11 VZ |
707 | m_tbar->AddSeparator(); |
708 | m_tbar->AddTool(wxID_HELP, _T("Help"), wxBITMAP(help)); | |
709 | ||
f6bcfd97 BP |
710 | m_tbar->Realize(); |
711 | } | |
712 | ||
713 | LayoutChildren(); | |
714 | } | |
715 | ||
5ef2e633 VZ |
716 | void MyFrame::OnToggleToolbarSize(wxCommandEvent& WXUNUSED(event)) |
717 | { | |
718 | m_smallToolbar = !m_smallToolbar; | |
ad9bb75f | 719 | |
5ef2e633 | 720 | RecreateToolbar(); |
7fb23305 VZ |
721 | } |
722 | ||
98066234 VZ |
723 | void MyFrame::OnToggleToolbarRows(wxCommandEvent& WXUNUSED(event)) |
724 | { | |
725 | // m_rows may be only 1 or 2 | |
726 | m_rows = 3 - m_rows; | |
727 | ||
7a976304 | 728 | GetToolBar()->SetRows(!(GetToolBar()->IsVertical()) ? m_rows : 10 / m_rows); |
98066234 | 729 | |
9fb35cf1 | 730 | //RecreateToolbar(); -- this is unneeded |
98066234 VZ |
731 | } |
732 | ||
6a1b3ead VZ |
733 | void MyFrame::OnToggleTooltips(wxCommandEvent& WXUNUSED(event)) |
734 | { | |
735 | m_showTooltips = !m_showTooltips; | |
736 | ||
737 | RecreateToolbar(); | |
738 | } | |
739 | ||
8d0a7b56 VZ |
740 | void MyFrame::OnToggleCustomDisabled(wxCommandEvent& WXUNUSED(event)) |
741 | { | |
742 | m_useCustomDisabled = !m_useCustomDisabled; | |
743 | ||
744 | RecreateToolbar(); | |
745 | } | |
746 | ||
7a976304 | 747 | void MyFrame::OnChangeOrientation(wxCommandEvent& event) |
7fb23305 | 748 | { |
7a976304 VZ |
749 | switch( event.GetId() ) |
750 | { | |
751 | case IDM_TOOLBAR_LEFT_ORIENTATION: | |
752 | m_toolbarPosition = TOOLBAR_LEFT; | |
753 | break; | |
754 | case IDM_TOOLBAR_TOP_ORIENTATION: | |
755 | m_toolbarPosition = TOOLBAR_TOP; | |
756 | break; | |
757 | case IDM_TOOLBAR_RIGHT_ORIENTATION: | |
758 | m_toolbarPosition = TOOLBAR_RIGHT; | |
759 | break; | |
760 | case IDM_TOOLBAR_BOTTOM_ORIENTATION: | |
761 | m_toolbarPosition = TOOLBAR_BOTTOM; | |
762 | break; | |
763 | } | |
5ef2e633 | 764 | RecreateToolbar(); |
14d1ccd8 JS |
765 | } |
766 | ||
47908e25 | 767 | void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event)) |
14d1ccd8 | 768 | { |
bc2ec626 | 769 | Close(true); |
14d1ccd8 JS |
770 | } |
771 | ||
e08bbf37 | 772 | void MyFrame::OnAbout(wxCommandEvent& event) |
14d1ccd8 | 773 | { |
e08bbf37 VZ |
774 | if ( event.IsChecked() ) |
775 | m_textWindow->WriteText( _T("Help button down now.\n") ); | |
776 | else | |
777 | m_textWindow->WriteText( _T("Help button up now.\n") ); | |
778 | ||
be5a51fb | 779 | (void)wxMessageBox(_T("wxWidgets toolbar sample"), _T("About wxToolBar")); |
13437238 | 780 | } |
14d1ccd8 | 781 | |
13437238 JS |
782 | void MyFrame::OnToolLeftClick(wxCommandEvent& event) |
783 | { | |
e179bd65 RR |
784 | wxString str; |
785 | str.Printf( _T("Clicked on tool %d\n"), event.GetId()); | |
786 | m_textWindow->WriteText( str ); | |
ad9bb75f | 787 | |
e179bd65 RR |
788 | if (event.GetId() == wxID_COPY) |
789 | { | |
7fb23305 | 790 | DoEnablePrint(); |
e179bd65 | 791 | } |
ad9bb75f | 792 | |
e179bd65 RR |
793 | if (event.GetId() == wxID_CUT) |
794 | { | |
7fb23305 | 795 | DoToggleHelp(); |
e179bd65 | 796 | } |
1c4f8f8d | 797 | |
97d7bfb8 RR |
798 | if (event.GetId() == wxID_PRINT) |
799 | { | |
800 | DoDeletePrint(); | |
801 | } | |
14d1ccd8 JS |
802 | } |
803 | ||
e052a316 VZ |
804 | void MyFrame::OnToolRightClick(wxCommandEvent& event) |
805 | { | |
806 | m_textWindow->AppendText( | |
60c474a0 MB |
807 | wxString::Format(_T("Tool %d right clicked.\n"), |
808 | (int) event.GetInt())); | |
e052a316 VZ |
809 | } |
810 | ||
1c383dba VZ |
811 | void MyFrame::OnCombo(wxCommandEvent& event) |
812 | { | |
813 | wxLogStatus(_T("Combobox string '%s' selected"), event.GetString().c_str()); | |
814 | } | |
815 | ||
7fb23305 VZ |
816 | void MyFrame::DoEnablePrint() |
817 | { | |
2b5f62a0 VZ |
818 | if ( !m_nPrint ) |
819 | return; | |
820 | ||
ad4ae6ed | 821 | wxToolBarBase *tb = GetToolBar(); |
2b5f62a0 | 822 | tb->EnableTool(wxID_PRINT, !tb->GetToolEnabled(wxID_PRINT)); |
7fb23305 VZ |
823 | } |
824 | ||
97d7bfb8 RR |
825 | void MyFrame::DoDeletePrint() |
826 | { | |
2b5f62a0 VZ |
827 | if ( !m_nPrint ) |
828 | return; | |
1c4f8f8d | 829 | |
2b5f62a0 | 830 | wxToolBarBase *tb = GetToolBar(); |
97d7bfb8 | 831 | tb->DeleteTool( wxID_PRINT ); |
2b5f62a0 VZ |
832 | |
833 | m_nPrint--; | |
97d7bfb8 RR |
834 | } |
835 | ||
7fb23305 VZ |
836 | void MyFrame::DoToggleHelp() |
837 | { | |
ad4ae6ed | 838 | wxToolBarBase *tb = GetToolBar(); |
7fb23305 VZ |
839 | tb->ToggleTool( wxID_HELP, !tb->GetToolState( wxID_HELP ) ); |
840 | } | |
841 | ||
5ef2e633 VZ |
842 | void MyFrame::OnUpdateCopyAndCut(wxUpdateUIEvent& event) |
843 | { | |
96dc4236 VZ |
844 | event.Enable( m_textWindow->CanCopy() ); |
845 | } | |
846 | ||
847 | void MyFrame::OnUpdateToggleHorzText(wxUpdateUIEvent& event) | |
848 | { | |
849 | wxToolBar *tbar = GetToolBar(); | |
850 | event.Enable( tbar && | |
851 | tbar->HasFlag(wxTB_TEXT) && | |
852 | !tbar->HasFlag(wxTB_NOICONS) ); | |
5ef2e633 VZ |
853 | } |
854 | ||
a1f79c1e VZ |
855 | void MyFrame::OnChangeToolTip(wxCommandEvent& WXUNUSED(event)) |
856 | { | |
857 | GetToolBar()->SetToolShortHelp(wxID_NEW, _T("New toolbar button")); | |
858 | } | |
859 | ||
ec483b11 VZ |
860 | void MyFrame::OnToolbarStyle(wxCommandEvent& event) |
861 | { | |
862 | long style = GetToolBar()->GetWindowStyle(); | |
863 | style &= ~(wxTB_NOICONS | wxTB_TEXT); | |
864 | ||
865 | switch ( event.GetId() ) | |
866 | { | |
867 | case IDM_TOOLBAR_SHOW_TEXT: | |
868 | style |= wxTB_NOICONS | wxTB_TEXT; | |
869 | break; | |
870 | ||
871 | case IDM_TOOLBAR_SHOW_ICONS: | |
872 | // nothing to do | |
873 | break; | |
874 | ||
875 | case IDM_TOOLBAR_SHOW_BOTH: | |
876 | style |= wxTB_TEXT; | |
877 | } | |
878 | ||
879 | GetToolBar()->SetWindowStyle(style); | |
880 | } | |
881 | ||
5e3b8b93 VZ |
882 | void MyFrame::OnToolbarCustomBitmap(wxCommandEvent& WXUNUSED(event)) |
883 | { | |
884 | m_pathBmp = wxFileSelector(_T("Custom bitmap path")); | |
885 | ||
886 | RecreateToolbar(); | |
887 | } | |
888 | ||
bdc72a22 VZ |
889 | void MyFrame::OnInsertPrint(wxCommandEvent& WXUNUSED(event)) |
890 | { | |
2b5f62a0 | 891 | m_nPrint++; |
bdc72a22 | 892 | |
2b5f62a0 VZ |
893 | wxToolBarBase *tb = GetToolBar(); |
894 | tb->InsertTool(0, wxID_PRINT, _T("New print"), | |
895 | wxBITMAP(print), wxNullBitmap, | |
896 | wxITEM_NORMAL, | |
897 | _T("Delete this tool"), | |
898 | _T("This button was inserted into the toolbar")); | |
899 | ||
900 | // must call Realize() after adding a new button | |
901 | tb->Realize(); | |
bdc72a22 VZ |
902 | } |
903 | ||
3bf4189d VZ |
904 | void MyFrame::OnToggleRadioBtn(wxCommandEvent& event) |
905 | { | |
906 | if ( m_tbar ) | |
907 | { | |
908 | m_tbar->ToggleTool(IDM_TOOLBAR_OTHER_1 + | |
909 | event.GetId() - IDM_TOOLBAR_TOGGLERADIOBTN1, true); | |
910 | } | |
911 | } | |
a9a0ceca VZ |
912 | |
913 | void MyFrame::OnToolDropdown(wxCommandEvent& event) | |
914 | { | |
915 | wxString str; | |
916 | str.Printf( _T("Dropdown on tool %d\n"), event.GetId()); | |
917 | m_textWindow->WriteText( str ); | |
918 | ||
919 | event.Skip(); | |
920 | } |