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