]>
Commit | Line | Data |
---|---|---|
32b8ec41 | 1 | ///////////////////////////////////////////////////////////////////////////// |
be5a51fb | 2 | // Program: wxWidgets Widgets Sample |
32b8ec41 VZ |
3 | // Name: button.cpp |
4 | // Purpose: Part of the widgets sample showing wxButton | |
5 | // Author: Vadim Zeitlin | |
6 | // Created: 10.04.01 | |
7 | // Id: $Id$ | |
8 | // Copyright: (c) 2001 Vadim Zeitlin | |
526954c5 | 9 | // Licence: wxWindows licence |
32b8ec41 VZ |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | // ============================================================================ | |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
19 | ||
20 | // for compilers that support precompilation, includes "wx/wx.h". | |
21 | #include "wx/wxprec.h" | |
22 | ||
23 | #ifdef __BORLANDC__ | |
24 | #pragma hdrstop | |
25 | #endif | |
26 | ||
27 | // for all others, include the necessary headers | |
28 | #ifndef WX_PRECOMP | |
3379ed37 | 29 | #include "wx/app.h" |
32b8ec41 VZ |
30 | #include "wx/log.h" |
31 | ||
552271d6 | 32 | #include "wx/bmpbuttn.h" |
32b8ec41 VZ |
33 | #include "wx/button.h" |
34 | #include "wx/checkbox.h" | |
35 | #include "wx/radiobox.h" | |
36 | #include "wx/statbox.h" | |
37 | #include "wx/textctrl.h" | |
38 | #endif | |
39 | ||
ff8ebfaf | 40 | #include "wx/artprov.h" |
32b8ec41 | 41 | #include "wx/sizer.h" |
552271d6 | 42 | #include "wx/dcmemory.h" |
3571e1ad | 43 | #include "wx/commandlinkbutton.h" |
32b8ec41 VZ |
44 | |
45 | #include "widgets.h" | |
ff8ebfaf | 46 | |
32b8ec41 VZ |
47 | #include "icons/button.xpm" |
48 | ||
49 | // ---------------------------------------------------------------------------- | |
50 | // constants | |
51 | // ---------------------------------------------------------------------------- | |
52 | ||
53 | // control ids | |
54 | enum | |
55 | { | |
f0fa4312 | 56 | ButtonPage_Reset = wxID_HIGHEST, |
32b8ec41 | 57 | ButtonPage_ChangeLabel, |
3571e1ad | 58 | ButtonPage_ChangeNote, |
32b8ec41 VZ |
59 | ButtonPage_Button |
60 | }; | |
61 | ||
62 | // radio boxes | |
233f10bf VZ |
63 | enum |
64 | { | |
65 | ButtonImagePos_Left, | |
66 | ButtonImagePos_Right, | |
67 | ButtonImagePos_Top, | |
68 | ButtonImagePos_Bottom | |
69 | }; | |
70 | ||
32b8ec41 VZ |
71 | enum |
72 | { | |
73 | ButtonHAlign_Left, | |
74 | ButtonHAlign_Centre, | |
75 | ButtonHAlign_Right | |
76 | }; | |
77 | ||
78 | enum | |
79 | { | |
80 | ButtonVAlign_Top, | |
81 | ButtonVAlign_Centre, | |
82 | ButtonVAlign_Bottom | |
83 | }; | |
84 | ||
85 | // ---------------------------------------------------------------------------- | |
86 | // ButtonWidgetsPage | |
87 | // ---------------------------------------------------------------------------- | |
88 | ||
89 | class ButtonWidgetsPage : public WidgetsPage | |
90 | { | |
91 | public: | |
f2fdc4d5 | 92 | ButtonWidgetsPage(WidgetsBookCtrl *book, wxImageList *imaglist); |
8f6eaec9 | 93 | virtual ~ButtonWidgetsPage(){}; |
32b8ec41 | 94 | |
195df7a7 | 95 | virtual wxControl *GetWidget() const { return m_button; } |
1301e228 | 96 | virtual void RecreateWidget() { CreateButton(); } |
195df7a7 | 97 | |
453535a7 WS |
98 | // lazy creation of the content |
99 | virtual void CreateContent(); | |
100 | ||
32b8ec41 VZ |
101 | protected: |
102 | // event handlers | |
103 | void OnCheckOrRadioBox(wxCommandEvent& event); | |
104 | ||
105 | void OnButton(wxCommandEvent& event); | |
106 | void OnButtonReset(wxCommandEvent& event); | |
107 | void OnButtonChangeLabel(wxCommandEvent& event); | |
3571e1ad | 108 | void OnButtonChangeNote(wxCommandEvent& event); |
32b8ec41 VZ |
109 | |
110 | // reset the wxButton parameters | |
111 | void Reset(); | |
112 | ||
113 | // (re)create the wxButton | |
114 | void CreateButton(); | |
115 | ||
552271d6 VZ |
116 | // add m_button to m_sizerButton using current value of m_chkFit |
117 | void AddButtonToSizer(); | |
118 | ||
119 | // helper function: create a bitmap for wxBitmapButton | |
120 | wxBitmap CreateBitmap(const wxString& label); | |
121 | ||
122 | ||
32b8ec41 VZ |
123 | // the controls |
124 | // ------------ | |
125 | ||
126 | // the check/radio boxes for styles | |
d5b98eb9 VZ |
127 | wxCheckBox *m_chkBitmapOnly, |
128 | *m_chkTextAndBitmap, | |
32b8ec41 | 129 | *m_chkFit, |
f2d7fdf7 | 130 | *m_chkAuthNeeded, |
b55bc1a2 | 131 | #if wxUSE_COMMANDLINKBUTTON |
3571e1ad | 132 | *m_chkCommandLink, |
b55bc1a2 | 133 | #endif // wxUSE_COMMANDLINKBUTTON |
95912bdd VZ |
134 | #if wxUSE_MARKUP |
135 | *m_chkUseMarkup, | |
136 | #endif // wxUSE_MARKUP | |
b4354db1 VZ |
137 | *m_chkDefault, |
138 | *m_chkUseBitmapClass; | |
32b8ec41 | 139 | |
3e764e2f | 140 | // more checkboxes for wxBitmapButton only |
d5b98eb9 | 141 | wxCheckBox *m_chkUsePressed, |
3e764e2f | 142 | *m_chkUseFocused, |
d5b98eb9 | 143 | *m_chkUseCurrent, |
3e764e2f VZ |
144 | *m_chkUseDisabled; |
145 | ||
d5b98eb9 | 146 | // and an image position choice used if m_chkTextAndBitmap is on |
233f10bf VZ |
147 | wxRadioBox *m_radioImagePos; |
148 | ||
32b8ec41 VZ |
149 | wxRadioBox *m_radioHAlign, |
150 | *m_radioVAlign; | |
151 | ||
8772bb08 | 152 | // the button itself and the sizer it is in |
32b8ec41 | 153 | wxButton *m_button; |
3571e1ad VZ |
154 | |
155 | #if wxUSE_COMMANDLINKBUTTON | |
156 | // same as m_button or NULL if not showing a command link button currently | |
157 | wxCommandLinkButton *m_cmdLnkButton; | |
158 | #endif // wxUSE_COMMANDLINKBUTTON | |
159 | ||
32b8ec41 VZ |
160 | wxSizer *m_sizerButton; |
161 | ||
162 | // the text entries for command parameters | |
163 | wxTextCtrl *m_textLabel; | |
164 | ||
3571e1ad VZ |
165 | #if wxUSE_COMMANDLINKBUTTON |
166 | wxTextCtrl *m_textNote; | |
167 | ||
168 | // used to hide or show button for changing note | |
169 | wxSizer *m_sizerNote; | |
170 | #endif // wxUSE_COMMANDLINKBUTTON | |
171 | ||
32b8ec41 | 172 | private: |
5e173f35 GD |
173 | DECLARE_EVENT_TABLE() |
174 | DECLARE_WIDGETS_PAGE(ButtonWidgetsPage) | |
32b8ec41 VZ |
175 | }; |
176 | ||
177 | // ---------------------------------------------------------------------------- | |
178 | // event tables | |
179 | // ---------------------------------------------------------------------------- | |
180 | ||
181 | BEGIN_EVENT_TABLE(ButtonWidgetsPage, WidgetsPage) | |
182 | EVT_BUTTON(ButtonPage_Button, ButtonWidgetsPage::OnButton) | |
183 | ||
184 | EVT_BUTTON(ButtonPage_Reset, ButtonWidgetsPage::OnButtonReset) | |
185 | EVT_BUTTON(ButtonPage_ChangeLabel, ButtonWidgetsPage::OnButtonChangeLabel) | |
3571e1ad | 186 | EVT_BUTTON(ButtonPage_ChangeNote, ButtonWidgetsPage::OnButtonChangeNote) |
32b8ec41 | 187 | |
206d3a16 JS |
188 | EVT_CHECKBOX(wxID_ANY, ButtonWidgetsPage::OnCheckOrRadioBox) |
189 | EVT_RADIOBOX(wxID_ANY, ButtonWidgetsPage::OnCheckOrRadioBox) | |
32b8ec41 VZ |
190 | END_EVENT_TABLE() |
191 | ||
192 | // ============================================================================ | |
193 | // implementation | |
194 | // ============================================================================ | |
195 | ||
d8d07a79 | 196 | #if defined(__WXUNIVERSAL__) |
d8a731ee | 197 | #define FAMILY_CTRLS UNIVERSAL_CTRLS |
d8d07a79 | 198 | #else |
f0fa4312 | 199 | #define FAMILY_CTRLS NATIVE_CTRLS |
d8d07a79 | 200 | #endif |
d8a731ee | 201 | |
9a83f860 | 202 | IMPLEMENT_WIDGETS_PAGE(ButtonWidgetsPage, wxT("Button"), FAMILY_CTRLS ); |
32b8ec41 | 203 | |
f2fdc4d5 | 204 | ButtonWidgetsPage::ButtonWidgetsPage(WidgetsBookCtrl *book, |
61c083e7 | 205 | wxImageList *imaglist) |
261357eb | 206 | : WidgetsPage(book, imaglist, button_xpm) |
32b8ec41 | 207 | { |
32b8ec41 | 208 | // init everything |
d5b98eb9 VZ |
209 | m_chkBitmapOnly = |
210 | m_chkTextAndBitmap = | |
32b8ec41 | 211 | m_chkFit = |
f2d7fdf7 | 212 | m_chkAuthNeeded = |
b55bc1a2 | 213 | #if wxUSE_COMMANDLINKBUTTON |
3571e1ad | 214 | m_chkCommandLink = |
b55bc1a2 | 215 | #endif // wxUSE_COMMANDLINKBUTTON |
95912bdd VZ |
216 | #if wxUSE_MARKUP |
217 | m_chkUseMarkup = | |
218 | #endif // wxUSE_MARKUP | |
3e764e2f | 219 | m_chkDefault = |
b4354db1 | 220 | m_chkUseBitmapClass = |
d5b98eb9 | 221 | m_chkUsePressed = |
3e764e2f | 222 | m_chkUseFocused = |
d5b98eb9 | 223 | m_chkUseCurrent = |
3e764e2f | 224 | m_chkUseDisabled = (wxCheckBox *)NULL; |
32b8ec41 | 225 | |
233f10bf | 226 | m_radioImagePos = |
32b8ec41 VZ |
227 | m_radioHAlign = |
228 | m_radioVAlign = (wxRadioBox *)NULL; | |
229 | ||
230 | m_textLabel = (wxTextCtrl *)NULL; | |
231 | ||
232 | m_button = (wxButton *)NULL; | |
233 | m_sizerButton = (wxSizer *)NULL; | |
453535a7 | 234 | } |
32b8ec41 | 235 | |
453535a7 WS |
236 | void ButtonWidgetsPage::CreateContent() |
237 | { | |
32b8ec41 VZ |
238 | wxSizer *sizerTop = new wxBoxSizer(wxHORIZONTAL); |
239 | ||
240 | // left pane | |
9a83f860 | 241 | wxStaticBox *box = new wxStaticBox(this, wxID_ANY, wxT("&Set style")); |
32b8ec41 VZ |
242 | |
243 | wxSizer *sizerLeft = new wxStaticBoxSizer(box, wxVERTICAL); | |
244 | ||
d5b98eb9 | 245 | m_chkBitmapOnly = CreateCheckBoxAndAddToSizer(sizerLeft, "&Bitmap only"); |
f2d7fdf7 | 246 | m_chkTextAndBitmap = CreateCheckBoxAndAddToSizer(sizerLeft, "Text &and bitmap"); |
9a83f860 | 247 | m_chkFit = CreateCheckBoxAndAddToSizer(sizerLeft, wxT("&Fit exactly")); |
f2d7fdf7 | 248 | m_chkAuthNeeded = CreateCheckBoxAndAddToSizer(sizerLeft, wxT("Require a&uth")); |
3571e1ad VZ |
249 | #if wxUSE_COMMANDLINKBUTTON |
250 | m_chkCommandLink = CreateCheckBoxAndAddToSizer(sizerLeft, wxT("Use command &link button")); | |
251 | #endif | |
95912bdd VZ |
252 | #if wxUSE_MARKUP |
253 | m_chkUseMarkup = CreateCheckBoxAndAddToSizer(sizerLeft, "Interpret &markup"); | |
254 | #endif // wxUSE_MARKUP | |
9a83f860 | 255 | m_chkDefault = CreateCheckBoxAndAddToSizer(sizerLeft, wxT("&Default")); |
32b8ec41 | 256 | |
b4354db1 VZ |
257 | m_chkUseBitmapClass = CreateCheckBoxAndAddToSizer(sizerLeft, |
258 | "Use wxBitmapButton"); | |
259 | m_chkUseBitmapClass->SetValue(true); | |
260 | ||
3e764e2f VZ |
261 | sizerLeft->AddSpacer(5); |
262 | ||
263 | wxSizer *sizerUseLabels = | |
d5b98eb9 VZ |
264 | new wxStaticBoxSizer(wxVERTICAL, this, |
265 | "&Use the following bitmaps in addition to the normal one?"); | |
266 | m_chkUsePressed = CreateCheckBoxAndAddToSizer(sizerUseLabels, | |
267 | "&Pressed (small help icon)"); | |
268 | m_chkUseFocused = CreateCheckBoxAndAddToSizer(sizerUseLabels, | |
269 | "&Focused (small error icon)"); | |
270 | m_chkUseCurrent = CreateCheckBoxAndAddToSizer(sizerUseLabels, | |
271 | "&Current (small warning icon)"); | |
272 | m_chkUseDisabled = CreateCheckBoxAndAddToSizer(sizerUseLabels, | |
273 | "&Disabled (broken image icon)"); | |
3e764e2f VZ |
274 | sizerLeft->Add(sizerUseLabels, wxSizerFlags().Expand().Border()); |
275 | ||
233f10bf VZ |
276 | sizerLeft->AddSpacer(10); |
277 | ||
278 | static const wxString dirs[] = | |
279 | { | |
280 | "left", "right", "top", "bottom", | |
281 | }; | |
282 | m_radioImagePos = new wxRadioBox(this, wxID_ANY, "Image &position", | |
283 | wxDefaultPosition, wxDefaultSize, | |
284 | WXSIZEOF(dirs), dirs); | |
285 | sizerLeft->Add(m_radioImagePos, 0, wxGROW | wxALL, 5); | |
3e764e2f | 286 | sizerLeft->AddSpacer(15); |
32b8ec41 VZ |
287 | |
288 | // should be in sync with enums Button[HV]Align! | |
289 | static const wxString halign[] = | |
290 | { | |
9a83f860 VZ |
291 | wxT("left"), |
292 | wxT("centre"), | |
293 | wxT("right"), | |
32b8ec41 VZ |
294 | }; |
295 | ||
296 | static const wxString valign[] = | |
297 | { | |
9a83f860 VZ |
298 | wxT("top"), |
299 | wxT("centre"), | |
300 | wxT("bottom"), | |
32b8ec41 VZ |
301 | }; |
302 | ||
9a83f860 | 303 | m_radioHAlign = new wxRadioBox(this, wxID_ANY, wxT("&Horz alignment"), |
32b8ec41 VZ |
304 | wxDefaultPosition, wxDefaultSize, |
305 | WXSIZEOF(halign), halign); | |
9a83f860 | 306 | m_radioVAlign = new wxRadioBox(this, wxID_ANY, wxT("&Vert alignment"), |
32b8ec41 VZ |
307 | wxDefaultPosition, wxDefaultSize, |
308 | WXSIZEOF(valign), valign); | |
309 | ||
310 | sizerLeft->Add(m_radioHAlign, 0, wxGROW | wxALL, 5); | |
311 | sizerLeft->Add(m_radioVAlign, 0, wxGROW | wxALL, 5); | |
312 | ||
313 | sizerLeft->Add(5, 5, 0, wxGROW | wxALL, 5); // spacer | |
314 | ||
9a83f860 | 315 | wxButton *btn = new wxButton(this, ButtonPage_Reset, wxT("&Reset")); |
32b8ec41 VZ |
316 | sizerLeft->Add(btn, 0, wxALIGN_CENTRE_HORIZONTAL | wxALL, 15); |
317 | ||
318 | // middle pane | |
9a83f860 | 319 | wxStaticBox *box2 = new wxStaticBox(this, wxID_ANY, wxT("&Operations")); |
32b8ec41 VZ |
320 | wxSizer *sizerMiddle = new wxStaticBoxSizer(box2, wxVERTICAL); |
321 | ||
322 | wxSizer *sizerRow = CreateSizerWithTextAndButton(ButtonPage_ChangeLabel, | |
9a83f860 | 323 | wxT("Change label"), |
206d3a16 | 324 | wxID_ANY, |
32b8ec41 | 325 | &m_textLabel); |
9a83f860 | 326 | m_textLabel->SetValue(wxT("&Press me!")); |
32b8ec41 VZ |
327 | sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5); |
328 | ||
3571e1ad VZ |
329 | #if wxUSE_COMMANDLINKBUTTON |
330 | m_sizerNote = CreateSizerWithTextAndButton(ButtonPage_ChangeNote, | |
331 | wxT("Change note"), | |
332 | wxID_ANY, | |
333 | &m_textNote); | |
334 | m_textNote->SetValue(wxT("Writes down button clicks in the log.")); | |
335 | ||
336 | sizerMiddle->Add(m_sizerNote, 0, wxALL | wxGROW, 5); | |
337 | #endif | |
338 | ||
32b8ec41 | 339 | // right pane |
552271d6 VZ |
340 | m_sizerButton = new wxBoxSizer(wxHORIZONTAL); |
341 | m_sizerButton->SetMinSize(150, 0); | |
32b8ec41 VZ |
342 | |
343 | // the 3 panes panes compose the window | |
344 | sizerTop->Add(sizerLeft, 0, wxGROW | (wxALL & ~wxLEFT), 10); | |
345 | sizerTop->Add(sizerMiddle, 1, wxGROW | wxALL, 10); | |
552271d6 | 346 | sizerTop->Add(m_sizerButton, 1, wxGROW | (wxALL & ~wxRIGHT), 10); |
32b8ec41 | 347 | |
3e764e2f | 348 | // do create the main control |
32b8ec41 | 349 | Reset(); |
3e764e2f | 350 | CreateButton(); |
552271d6 | 351 | |
32b8ec41 | 352 | SetSizer(sizerTop); |
32b8ec41 VZ |
353 | } |
354 | ||
32b8ec41 VZ |
355 | // ---------------------------------------------------------------------------- |
356 | // operations | |
357 | // ---------------------------------------------------------------------------- | |
358 | ||
359 | void ButtonWidgetsPage::Reset() | |
360 | { | |
d5b98eb9 | 361 | m_chkBitmapOnly->SetValue(false); |
206d3a16 | 362 | m_chkFit->SetValue(true); |
f2d7fdf7 | 363 | m_chkAuthNeeded->SetValue(false); |
d5b98eb9 | 364 | m_chkTextAndBitmap->SetValue(false); |
206d3a16 | 365 | m_chkDefault->SetValue(false); |
3571e1ad VZ |
366 | #if wxUSE_COMMANDLINKBUTTON |
367 | m_chkCommandLink->SetValue(false); | |
368 | #endif | |
95912bdd VZ |
369 | #if wxUSE_MARKUP |
370 | m_chkUseMarkup->SetValue(false); | |
371 | #endif // wxUSE_MARKUP | |
b4354db1 | 372 | m_chkUseBitmapClass->SetValue(true); |
32b8ec41 | 373 | |
d5b98eb9 | 374 | m_chkUsePressed->SetValue(true); |
3e764e2f | 375 | m_chkUseFocused->SetValue(true); |
d5b98eb9 | 376 | m_chkUseCurrent->SetValue(true); |
3e764e2f VZ |
377 | m_chkUseDisabled->SetValue(true); |
378 | ||
233f10bf | 379 | m_radioImagePos->SetSelection(ButtonImagePos_Left); |
32b8ec41 VZ |
380 | m_radioHAlign->SetSelection(ButtonHAlign_Centre); |
381 | m_radioVAlign->SetSelection(ButtonVAlign_Centre); | |
382 | } | |
383 | ||
384 | void ButtonWidgetsPage::CreateButton() | |
385 | { | |
386 | wxString label; | |
387 | if ( m_button ) | |
388 | { | |
3571e1ad VZ |
389 | #if wxUSE_COMMANDLINKBUTTON |
390 | if ( m_cmdLnkButton ) | |
391 | label = m_cmdLnkButton->GetMainLabel(); | |
392 | else | |
393 | #endif | |
394 | label = m_button->GetLabel(); | |
32b8ec41 VZ |
395 | |
396 | size_t count = m_sizerButton->GetChildren().GetCount(); | |
397 | for ( size_t n = 0; n < count; n++ ) | |
398 | { | |
9dd96c0f | 399 | m_sizerButton->Remove( 0 ); |
32b8ec41 VZ |
400 | } |
401 | ||
402 | delete m_button; | |
403 | } | |
552271d6 VZ |
404 | |
405 | if ( label.empty() ) | |
32b8ec41 | 406 | { |
552271d6 VZ |
407 | // creating for the first time or recreating a button after bitmap |
408 | // button | |
409 | label = m_textLabel->GetValue(); | |
32b8ec41 VZ |
410 | } |
411 | ||
1301e228 | 412 | int flags = ms_defaultFlags; |
32b8ec41 VZ |
413 | switch ( m_radioHAlign->GetSelection() ) |
414 | { | |
415 | case ButtonHAlign_Left: | |
c0495687 | 416 | flags |= wxBU_LEFT; |
32b8ec41 VZ |
417 | break; |
418 | ||
419 | default: | |
9a83f860 | 420 | wxFAIL_MSG(wxT("unexpected radiobox selection")); |
32b8ec41 VZ |
421 | // fall through |
422 | ||
423 | case ButtonHAlign_Centre: | |
32b8ec41 VZ |
424 | break; |
425 | ||
426 | case ButtonHAlign_Right: | |
c0495687 | 427 | flags |= wxBU_RIGHT; |
32b8ec41 VZ |
428 | break; |
429 | } | |
430 | ||
431 | switch ( m_radioVAlign->GetSelection() ) | |
432 | { | |
433 | case ButtonVAlign_Top: | |
c0495687 | 434 | flags |= wxBU_TOP; |
32b8ec41 VZ |
435 | break; |
436 | ||
437 | default: | |
9a83f860 | 438 | wxFAIL_MSG(wxT("unexpected radiobox selection")); |
32b8ec41 VZ |
439 | // fall through |
440 | ||
441 | case ButtonVAlign_Centre: | |
4ee8e5cd | 442 | // centre vertical alignment is the default (no style) |
32b8ec41 VZ |
443 | break; |
444 | ||
445 | case ButtonVAlign_Bottom: | |
c0495687 | 446 | flags |= wxBU_BOTTOM; |
32b8ec41 VZ |
447 | break; |
448 | } | |
449 | ||
3571e1ad VZ |
450 | #if wxUSE_COMMANDLINKBUTTON |
451 | m_sizerNote->Show(m_chkCommandLink->GetValue()); | |
452 | #endif | |
453 | ||
d5b98eb9 VZ |
454 | bool showsBitmap = false; |
455 | if ( m_chkBitmapOnly->GetValue() ) | |
552271d6 | 456 | { |
d5b98eb9 VZ |
457 | showsBitmap = true; |
458 | ||
b4354db1 VZ |
459 | wxButton *bbtn; |
460 | if ( m_chkUseBitmapClass->GetValue() ) | |
461 | { | |
462 | bbtn = new wxBitmapButton(this, ButtonPage_Button, | |
463 | CreateBitmap(wxT("normal"))); | |
464 | } | |
465 | else | |
466 | { | |
467 | bbtn = new wxButton(this, ButtonPage_Button); | |
468 | bbtn->SetBitmapLabel(CreateBitmap(wxT("normal"))); | |
469 | } | |
d5b98eb9 | 470 | if ( m_chkUsePressed->GetValue() ) |
9a83f860 | 471 | bbtn->SetBitmapPressed(CreateBitmap(wxT("pushed"))); |
3e764e2f | 472 | if ( m_chkUseFocused->GetValue() ) |
9a83f860 | 473 | bbtn->SetBitmapFocus(CreateBitmap(wxT("focused"))); |
d5b98eb9 | 474 | if ( m_chkUseCurrent->GetValue() ) |
9a83f860 | 475 | bbtn->SetBitmapCurrent(CreateBitmap(wxT("hover"))); |
3e764e2f | 476 | if ( m_chkUseDisabled->GetValue() ) |
9a83f860 | 477 | bbtn->SetBitmapDisabled(CreateBitmap(wxT("disabled"))); |
552271d6 | 478 | m_button = bbtn; |
3571e1ad VZ |
479 | #if wxUSE_COMMANDLINKBUTTON |
480 | m_cmdLnkButton = NULL; | |
481 | #endif | |
552271d6 VZ |
482 | } |
483 | else // normal button | |
484 | { | |
3571e1ad VZ |
485 | #if wxUSE_COMMANDLINKBUTTON |
486 | m_cmdLnkButton = NULL; | |
487 | ||
488 | if ( m_chkCommandLink->GetValue() ) | |
489 | { | |
490 | m_cmdLnkButton = new wxCommandLinkButton(this, ButtonPage_Button, | |
491 | label, | |
492 | m_textNote->GetValue(), | |
493 | wxDefaultPosition, | |
494 | wxDefaultSize, | |
495 | flags); | |
496 | m_button = m_cmdLnkButton; | |
497 | } | |
498 | else | |
499 | #endif // wxUSE_COMMANDLINKBUTTON | |
500 | { | |
501 | m_button = new wxButton(this, ButtonPage_Button, label, | |
502 | wxDefaultPosition, wxDefaultSize, | |
503 | flags); | |
504 | } | |
552271d6 | 505 | } |
32b8ec41 | 506 | |
d5b98eb9 | 507 | if ( !showsBitmap && m_chkTextAndBitmap->GetValue() ) |
32b8ec41 | 508 | { |
d5b98eb9 VZ |
509 | showsBitmap = true; |
510 | ||
233f10bf VZ |
511 | static const wxDirection positions[] = |
512 | { | |
513 | wxLEFT, wxRIGHT, wxTOP, wxBOTTOM | |
514 | }; | |
515 | ||
825ce0af | 516 | m_button->SetBitmap(wxArtProvider::GetIcon(wxART_INFORMATION, wxART_BUTTON), |
233f10bf | 517 | positions[m_radioImagePos->GetSelection()]); |
d5b98eb9 VZ |
518 | |
519 | if ( m_chkUsePressed->GetValue() ) | |
825ce0af | 520 | m_button->SetBitmapPressed(wxArtProvider::GetIcon(wxART_HELP, wxART_BUTTON)); |
d5b98eb9 | 521 | if ( m_chkUseFocused->GetValue() ) |
825ce0af | 522 | m_button->SetBitmapFocus(wxArtProvider::GetIcon(wxART_ERROR, wxART_BUTTON)); |
d5b98eb9 | 523 | if ( m_chkUseCurrent->GetValue() ) |
825ce0af | 524 | m_button->SetBitmapCurrent(wxArtProvider::GetIcon(wxART_WARNING, wxART_BUTTON)); |
d5b98eb9 | 525 | if ( m_chkUseDisabled->GetValue() ) |
825ce0af | 526 | m_button->SetBitmapDisabled(wxArtProvider::GetIcon(wxART_MISSING_IMAGE, wxART_BUTTON)); |
32b8ec41 | 527 | } |
32b8ec41 | 528 | |
b4354db1 VZ |
529 | m_chkUseBitmapClass->Enable(showsBitmap); |
530 | ||
d5b98eb9 VZ |
531 | m_chkUsePressed->Enable(showsBitmap); |
532 | m_chkUseFocused->Enable(showsBitmap); | |
533 | m_chkUseCurrent->Enable(showsBitmap); | |
534 | m_chkUseDisabled->Enable(showsBitmap); | |
535 | ||
f2d7fdf7 VZ |
536 | if ( m_chkAuthNeeded->GetValue() ) |
537 | m_button->SetAuthNeeded(); | |
538 | ||
32b8ec41 | 539 | if ( m_chkDefault->GetValue() ) |
32b8ec41 | 540 | m_button->SetDefault(); |
32b8ec41 | 541 | |
552271d6 VZ |
542 | AddButtonToSizer(); |
543 | ||
544 | m_sizerButton->Layout(); | |
545 | } | |
546 | ||
547 | void ButtonWidgetsPage::AddButtonToSizer() | |
548 | { | |
32b8ec41 VZ |
549 | if ( m_chkFit->GetValue() ) |
550 | { | |
552271d6 VZ |
551 | m_sizerButton->AddStretchSpacer(1); |
552 | m_sizerButton->Add(m_button, wxSizerFlags(0).Centre().Border()); | |
553 | m_sizerButton->AddStretchSpacer(1); | |
32b8ec41 | 554 | } |
552271d6 | 555 | else // take up the entire space |
32b8ec41 | 556 | { |
552271d6 | 557 | m_sizerButton->Add(m_button, wxSizerFlags(1).Expand().Border()); |
32b8ec41 | 558 | } |
32b8ec41 VZ |
559 | } |
560 | ||
561 | // ---------------------------------------------------------------------------- | |
562 | // event handlers | |
563 | // ---------------------------------------------------------------------------- | |
564 | ||
565 | void ButtonWidgetsPage::OnButtonReset(wxCommandEvent& WXUNUSED(event)) | |
566 | { | |
567 | Reset(); | |
568 | ||
569 | CreateButton(); | |
570 | } | |
571 | ||
c02e5a31 | 572 | void ButtonWidgetsPage::OnCheckOrRadioBox(wxCommandEvent& WXUNUSED(event)) |
32b8ec41 VZ |
573 | { |
574 | CreateButton(); | |
3571e1ad | 575 | Layout(); // make sure the text field for changing note displays correctly. |
32b8ec41 VZ |
576 | } |
577 | ||
578 | void ButtonWidgetsPage::OnButtonChangeLabel(wxCommandEvent& WXUNUSED(event)) | |
579 | { | |
95912bdd VZ |
580 | const wxString labelText = m_textLabel->GetValue(); |
581 | ||
3571e1ad VZ |
582 | #if wxUSE_COMMANDLINKBUTTON |
583 | if ( m_cmdLnkButton ) | |
95912bdd | 584 | m_cmdLnkButton->SetMainLabel(labelText); |
3571e1ad VZ |
585 | else |
586 | #endif // wxUSE_COMMANDLINKBUTTON | |
95912bdd VZ |
587 | { |
588 | #if wxUSE_MARKUP | |
589 | if ( m_chkUseMarkup->GetValue() ) | |
590 | m_button->SetLabelMarkup(labelText); | |
591 | else | |
592 | #endif // wxUSE_MARKUP | |
593 | m_button->SetLabel(labelText); | |
594 | } | |
3571e1ad VZ |
595 | |
596 | m_sizerButton->Layout(); | |
597 | } | |
598 | ||
599 | void ButtonWidgetsPage::OnButtonChangeNote(wxCommandEvent& WXUNUSED(event)) | |
600 | { | |
601 | #if wxUSE_COMMANDLINKBUTTON | |
602 | m_cmdLnkButton->SetNote(m_textNote->GetValue()); | |
d46a35d0 VZ |
603 | |
604 | m_sizerButton->Layout(); | |
3571e1ad | 605 | #endif // wxUSE_COMMANDLINKBUTTON |
32b8ec41 VZ |
606 | } |
607 | ||
c02e5a31 | 608 | void ButtonWidgetsPage::OnButton(wxCommandEvent& WXUNUSED(event)) |
32b8ec41 | 609 | { |
9a83f860 | 610 | wxLogMessage(wxT("Test button clicked.")); |
32b8ec41 VZ |
611 | } |
612 | ||
552271d6 VZ |
613 | // ---------------------------------------------------------------------------- |
614 | // bitmap button stuff | |
615 | // ---------------------------------------------------------------------------- | |
616 | ||
617 | wxBitmap ButtonWidgetsPage::CreateBitmap(const wxString& label) | |
618 | { | |
619 | wxBitmap bmp(180, 70); // shouldn't hardcode but it's simpler like this | |
620 | wxMemoryDC dc; | |
621 | dc.SelectObject(bmp); | |
f2a4f50e | 622 | dc.SetBackground(wxBrush(*wxCYAN)); |
552271d6 | 623 | dc.Clear(); |
f2a4f50e | 624 | dc.SetTextForeground(*wxBLACK); |
9a83f860 VZ |
625 | dc.DrawLabel(wxStripMenuCodes(m_textLabel->GetValue()) + wxT("\n") |
626 | wxT("(") + label + wxT(" state)"), | |
552271d6 VZ |
627 | wxArtProvider::GetBitmap(wxART_INFORMATION), |
628 | wxRect(10, 10, bmp.GetWidth() - 20, bmp.GetHeight() - 20), | |
629 | wxALIGN_CENTRE); | |
630 | ||
631 | return bmp; | |
632 | } | |
633 |