]>
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, |
3571e1ad | 131 | *m_chkCommandLink, |
32b8ec41 VZ |
132 | *m_chkDefault; |
133 | ||
3e764e2f | 134 | // more checkboxes for wxBitmapButton only |
d5b98eb9 | 135 | wxCheckBox *m_chkUsePressed, |
3e764e2f | 136 | *m_chkUseFocused, |
d5b98eb9 | 137 | *m_chkUseCurrent, |
3e764e2f VZ |
138 | *m_chkUseDisabled; |
139 | ||
d5b98eb9 | 140 | // and an image position choice used if m_chkTextAndBitmap is on |
233f10bf VZ |
141 | wxRadioBox *m_radioImagePos; |
142 | ||
32b8ec41 VZ |
143 | wxRadioBox *m_radioHAlign, |
144 | *m_radioVAlign; | |
145 | ||
8772bb08 | 146 | // the button itself and the sizer it is in |
32b8ec41 | 147 | wxButton *m_button; |
3571e1ad VZ |
148 | |
149 | #if wxUSE_COMMANDLINKBUTTON | |
150 | // same as m_button or NULL if not showing a command link button currently | |
151 | wxCommandLinkButton *m_cmdLnkButton; | |
152 | #endif // wxUSE_COMMANDLINKBUTTON | |
153 | ||
32b8ec41 VZ |
154 | wxSizer *m_sizerButton; |
155 | ||
156 | // the text entries for command parameters | |
157 | wxTextCtrl *m_textLabel; | |
158 | ||
3571e1ad VZ |
159 | #if wxUSE_COMMANDLINKBUTTON |
160 | wxTextCtrl *m_textNote; | |
161 | ||
162 | // used to hide or show button for changing note | |
163 | wxSizer *m_sizerNote; | |
164 | #endif // wxUSE_COMMANDLINKBUTTON | |
165 | ||
32b8ec41 | 166 | private: |
5e173f35 GD |
167 | DECLARE_EVENT_TABLE() |
168 | DECLARE_WIDGETS_PAGE(ButtonWidgetsPage) | |
32b8ec41 VZ |
169 | }; |
170 | ||
171 | // ---------------------------------------------------------------------------- | |
172 | // event tables | |
173 | // ---------------------------------------------------------------------------- | |
174 | ||
175 | BEGIN_EVENT_TABLE(ButtonWidgetsPage, WidgetsPage) | |
176 | EVT_BUTTON(ButtonPage_Button, ButtonWidgetsPage::OnButton) | |
177 | ||
178 | EVT_BUTTON(ButtonPage_Reset, ButtonWidgetsPage::OnButtonReset) | |
179 | EVT_BUTTON(ButtonPage_ChangeLabel, ButtonWidgetsPage::OnButtonChangeLabel) | |
3571e1ad | 180 | EVT_BUTTON(ButtonPage_ChangeNote, ButtonWidgetsPage::OnButtonChangeNote) |
32b8ec41 | 181 | |
206d3a16 JS |
182 | EVT_CHECKBOX(wxID_ANY, ButtonWidgetsPage::OnCheckOrRadioBox) |
183 | EVT_RADIOBOX(wxID_ANY, ButtonWidgetsPage::OnCheckOrRadioBox) | |
32b8ec41 VZ |
184 | END_EVENT_TABLE() |
185 | ||
186 | // ============================================================================ | |
187 | // implementation | |
188 | // ============================================================================ | |
189 | ||
d8d07a79 | 190 | #if defined(__WXUNIVERSAL__) |
d8a731ee | 191 | #define FAMILY_CTRLS UNIVERSAL_CTRLS |
d8d07a79 | 192 | #else |
f0fa4312 | 193 | #define FAMILY_CTRLS NATIVE_CTRLS |
d8d07a79 | 194 | #endif |
d8a731ee | 195 | |
9a83f860 | 196 | IMPLEMENT_WIDGETS_PAGE(ButtonWidgetsPage, wxT("Button"), FAMILY_CTRLS ); |
32b8ec41 | 197 | |
f2fdc4d5 | 198 | ButtonWidgetsPage::ButtonWidgetsPage(WidgetsBookCtrl *book, |
61c083e7 | 199 | wxImageList *imaglist) |
261357eb | 200 | : WidgetsPage(book, imaglist, button_xpm) |
32b8ec41 | 201 | { |
32b8ec41 | 202 | // init everything |
d5b98eb9 VZ |
203 | m_chkBitmapOnly = |
204 | m_chkTextAndBitmap = | |
32b8ec41 | 205 | m_chkFit = |
f2d7fdf7 | 206 | m_chkAuthNeeded = |
3571e1ad | 207 | m_chkCommandLink = |
3e764e2f | 208 | m_chkDefault = |
d5b98eb9 | 209 | m_chkUsePressed = |
3e764e2f | 210 | m_chkUseFocused = |
d5b98eb9 | 211 | m_chkUseCurrent = |
3e764e2f | 212 | m_chkUseDisabled = (wxCheckBox *)NULL; |
32b8ec41 | 213 | |
233f10bf | 214 | m_radioImagePos = |
32b8ec41 VZ |
215 | m_radioHAlign = |
216 | m_radioVAlign = (wxRadioBox *)NULL; | |
217 | ||
218 | m_textLabel = (wxTextCtrl *)NULL; | |
219 | ||
220 | m_button = (wxButton *)NULL; | |
221 | m_sizerButton = (wxSizer *)NULL; | |
453535a7 | 222 | } |
32b8ec41 | 223 | |
453535a7 WS |
224 | void ButtonWidgetsPage::CreateContent() |
225 | { | |
32b8ec41 VZ |
226 | wxSizer *sizerTop = new wxBoxSizer(wxHORIZONTAL); |
227 | ||
228 | // left pane | |
9a83f860 | 229 | wxStaticBox *box = new wxStaticBox(this, wxID_ANY, wxT("&Set style")); |
32b8ec41 VZ |
230 | |
231 | wxSizer *sizerLeft = new wxStaticBoxSizer(box, wxVERTICAL); | |
232 | ||
d5b98eb9 | 233 | m_chkBitmapOnly = CreateCheckBoxAndAddToSizer(sizerLeft, "&Bitmap only"); |
f2d7fdf7 | 234 | m_chkTextAndBitmap = CreateCheckBoxAndAddToSizer(sizerLeft, "Text &and bitmap"); |
9a83f860 | 235 | m_chkFit = CreateCheckBoxAndAddToSizer(sizerLeft, wxT("&Fit exactly")); |
f2d7fdf7 | 236 | m_chkAuthNeeded = CreateCheckBoxAndAddToSizer(sizerLeft, wxT("Require a&uth")); |
3571e1ad VZ |
237 | #if wxUSE_COMMANDLINKBUTTON |
238 | m_chkCommandLink = CreateCheckBoxAndAddToSizer(sizerLeft, wxT("Use command &link button")); | |
239 | #endif | |
9a83f860 | 240 | m_chkDefault = CreateCheckBoxAndAddToSizer(sizerLeft, wxT("&Default")); |
32b8ec41 | 241 | |
3e764e2f VZ |
242 | sizerLeft->AddSpacer(5); |
243 | ||
244 | wxSizer *sizerUseLabels = | |
d5b98eb9 VZ |
245 | new wxStaticBoxSizer(wxVERTICAL, this, |
246 | "&Use the following bitmaps in addition to the normal one?"); | |
247 | m_chkUsePressed = CreateCheckBoxAndAddToSizer(sizerUseLabels, | |
248 | "&Pressed (small help icon)"); | |
249 | m_chkUseFocused = CreateCheckBoxAndAddToSizer(sizerUseLabels, | |
250 | "&Focused (small error icon)"); | |
251 | m_chkUseCurrent = CreateCheckBoxAndAddToSizer(sizerUseLabels, | |
252 | "&Current (small warning icon)"); | |
253 | m_chkUseDisabled = CreateCheckBoxAndAddToSizer(sizerUseLabels, | |
254 | "&Disabled (broken image icon)"); | |
3e764e2f VZ |
255 | sizerLeft->Add(sizerUseLabels, wxSizerFlags().Expand().Border()); |
256 | ||
233f10bf VZ |
257 | sizerLeft->AddSpacer(10); |
258 | ||
259 | static const wxString dirs[] = | |
260 | { | |
261 | "left", "right", "top", "bottom", | |
262 | }; | |
263 | m_radioImagePos = new wxRadioBox(this, wxID_ANY, "Image &position", | |
264 | wxDefaultPosition, wxDefaultSize, | |
265 | WXSIZEOF(dirs), dirs); | |
266 | sizerLeft->Add(m_radioImagePos, 0, wxGROW | wxALL, 5); | |
3e764e2f | 267 | sizerLeft->AddSpacer(15); |
32b8ec41 VZ |
268 | |
269 | // should be in sync with enums Button[HV]Align! | |
270 | static const wxString halign[] = | |
271 | { | |
9a83f860 VZ |
272 | wxT("left"), |
273 | wxT("centre"), | |
274 | wxT("right"), | |
32b8ec41 VZ |
275 | }; |
276 | ||
277 | static const wxString valign[] = | |
278 | { | |
9a83f860 VZ |
279 | wxT("top"), |
280 | wxT("centre"), | |
281 | wxT("bottom"), | |
32b8ec41 VZ |
282 | }; |
283 | ||
9a83f860 | 284 | m_radioHAlign = new wxRadioBox(this, wxID_ANY, wxT("&Horz alignment"), |
32b8ec41 VZ |
285 | wxDefaultPosition, wxDefaultSize, |
286 | WXSIZEOF(halign), halign); | |
9a83f860 | 287 | m_radioVAlign = new wxRadioBox(this, wxID_ANY, wxT("&Vert alignment"), |
32b8ec41 VZ |
288 | wxDefaultPosition, wxDefaultSize, |
289 | WXSIZEOF(valign), valign); | |
290 | ||
291 | sizerLeft->Add(m_radioHAlign, 0, wxGROW | wxALL, 5); | |
292 | sizerLeft->Add(m_radioVAlign, 0, wxGROW | wxALL, 5); | |
293 | ||
294 | sizerLeft->Add(5, 5, 0, wxGROW | wxALL, 5); // spacer | |
295 | ||
9a83f860 | 296 | wxButton *btn = new wxButton(this, ButtonPage_Reset, wxT("&Reset")); |
32b8ec41 VZ |
297 | sizerLeft->Add(btn, 0, wxALIGN_CENTRE_HORIZONTAL | wxALL, 15); |
298 | ||
299 | // middle pane | |
9a83f860 | 300 | wxStaticBox *box2 = new wxStaticBox(this, wxID_ANY, wxT("&Operations")); |
32b8ec41 VZ |
301 | wxSizer *sizerMiddle = new wxStaticBoxSizer(box2, wxVERTICAL); |
302 | ||
303 | wxSizer *sizerRow = CreateSizerWithTextAndButton(ButtonPage_ChangeLabel, | |
9a83f860 | 304 | wxT("Change label"), |
206d3a16 | 305 | wxID_ANY, |
32b8ec41 | 306 | &m_textLabel); |
9a83f860 | 307 | m_textLabel->SetValue(wxT("&Press me!")); |
32b8ec41 VZ |
308 | sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5); |
309 | ||
3571e1ad VZ |
310 | #if wxUSE_COMMANDLINKBUTTON |
311 | m_sizerNote = CreateSizerWithTextAndButton(ButtonPage_ChangeNote, | |
312 | wxT("Change note"), | |
313 | wxID_ANY, | |
314 | &m_textNote); | |
315 | m_textNote->SetValue(wxT("Writes down button clicks in the log.")); | |
316 | ||
317 | sizerMiddle->Add(m_sizerNote, 0, wxALL | wxGROW, 5); | |
318 | #endif | |
319 | ||
32b8ec41 | 320 | // right pane |
552271d6 VZ |
321 | m_sizerButton = new wxBoxSizer(wxHORIZONTAL); |
322 | m_sizerButton->SetMinSize(150, 0); | |
32b8ec41 VZ |
323 | |
324 | // the 3 panes panes compose the window | |
325 | sizerTop->Add(sizerLeft, 0, wxGROW | (wxALL & ~wxLEFT), 10); | |
326 | sizerTop->Add(sizerMiddle, 1, wxGROW | wxALL, 10); | |
552271d6 | 327 | sizerTop->Add(m_sizerButton, 1, wxGROW | (wxALL & ~wxRIGHT), 10); |
32b8ec41 | 328 | |
3e764e2f | 329 | // do create the main control |
32b8ec41 | 330 | Reset(); |
3e764e2f | 331 | CreateButton(); |
552271d6 | 332 | |
32b8ec41 | 333 | SetSizer(sizerTop); |
32b8ec41 VZ |
334 | } |
335 | ||
32b8ec41 VZ |
336 | // ---------------------------------------------------------------------------- |
337 | // operations | |
338 | // ---------------------------------------------------------------------------- | |
339 | ||
340 | void ButtonWidgetsPage::Reset() | |
341 | { | |
d5b98eb9 | 342 | m_chkBitmapOnly->SetValue(false); |
206d3a16 | 343 | m_chkFit->SetValue(true); |
f2d7fdf7 | 344 | m_chkAuthNeeded->SetValue(false); |
d5b98eb9 | 345 | m_chkTextAndBitmap->SetValue(false); |
206d3a16 | 346 | m_chkDefault->SetValue(false); |
3571e1ad VZ |
347 | #if wxUSE_COMMANDLINKBUTTON |
348 | m_chkCommandLink->SetValue(false); | |
349 | #endif | |
32b8ec41 | 350 | |
d5b98eb9 | 351 | m_chkUsePressed->SetValue(true); |
3e764e2f | 352 | m_chkUseFocused->SetValue(true); |
d5b98eb9 | 353 | m_chkUseCurrent->SetValue(true); |
3e764e2f VZ |
354 | m_chkUseDisabled->SetValue(true); |
355 | ||
233f10bf | 356 | m_radioImagePos->SetSelection(ButtonImagePos_Left); |
32b8ec41 VZ |
357 | m_radioHAlign->SetSelection(ButtonHAlign_Centre); |
358 | m_radioVAlign->SetSelection(ButtonVAlign_Centre); | |
359 | } | |
360 | ||
361 | void ButtonWidgetsPage::CreateButton() | |
362 | { | |
363 | wxString label; | |
364 | if ( m_button ) | |
365 | { | |
3571e1ad VZ |
366 | #if wxUSE_COMMANDLINKBUTTON |
367 | if ( m_cmdLnkButton ) | |
368 | label = m_cmdLnkButton->GetMainLabel(); | |
369 | else | |
370 | #endif | |
371 | label = m_button->GetLabel(); | |
32b8ec41 VZ |
372 | |
373 | size_t count = m_sizerButton->GetChildren().GetCount(); | |
374 | for ( size_t n = 0; n < count; n++ ) | |
375 | { | |
9dd96c0f | 376 | m_sizerButton->Remove( 0 ); |
32b8ec41 VZ |
377 | } |
378 | ||
379 | delete m_button; | |
380 | } | |
552271d6 VZ |
381 | |
382 | if ( label.empty() ) | |
32b8ec41 | 383 | { |
552271d6 VZ |
384 | // creating for the first time or recreating a button after bitmap |
385 | // button | |
386 | label = m_textLabel->GetValue(); | |
32b8ec41 VZ |
387 | } |
388 | ||
1301e228 | 389 | int flags = ms_defaultFlags; |
32b8ec41 VZ |
390 | switch ( m_radioHAlign->GetSelection() ) |
391 | { | |
392 | case ButtonHAlign_Left: | |
c0495687 | 393 | flags |= wxBU_LEFT; |
32b8ec41 VZ |
394 | break; |
395 | ||
396 | default: | |
9a83f860 | 397 | wxFAIL_MSG(wxT("unexpected radiobox selection")); |
32b8ec41 VZ |
398 | // fall through |
399 | ||
400 | case ButtonHAlign_Centre: | |
32b8ec41 VZ |
401 | break; |
402 | ||
403 | case ButtonHAlign_Right: | |
c0495687 | 404 | flags |= wxBU_RIGHT; |
32b8ec41 VZ |
405 | break; |
406 | } | |
407 | ||
408 | switch ( m_radioVAlign->GetSelection() ) | |
409 | { | |
410 | case ButtonVAlign_Top: | |
c0495687 | 411 | flags |= wxBU_TOP; |
32b8ec41 VZ |
412 | break; |
413 | ||
414 | default: | |
9a83f860 | 415 | wxFAIL_MSG(wxT("unexpected radiobox selection")); |
32b8ec41 VZ |
416 | // fall through |
417 | ||
418 | case ButtonVAlign_Centre: | |
4ee8e5cd | 419 | // centre vertical alignment is the default (no style) |
32b8ec41 VZ |
420 | break; |
421 | ||
422 | case ButtonVAlign_Bottom: | |
c0495687 | 423 | flags |= wxBU_BOTTOM; |
32b8ec41 VZ |
424 | break; |
425 | } | |
426 | ||
3571e1ad VZ |
427 | #if wxUSE_COMMANDLINKBUTTON |
428 | m_sizerNote->Show(m_chkCommandLink->GetValue()); | |
429 | #endif | |
430 | ||
d5b98eb9 VZ |
431 | bool showsBitmap = false; |
432 | if ( m_chkBitmapOnly->GetValue() ) | |
552271d6 | 433 | { |
d5b98eb9 VZ |
434 | showsBitmap = true; |
435 | ||
552271d6 | 436 | wxBitmapButton *bbtn = new wxBitmapButton(this, ButtonPage_Button, |
9a83f860 | 437 | CreateBitmap(wxT("normal"))); |
d5b98eb9 | 438 | if ( m_chkUsePressed->GetValue() ) |
9a83f860 | 439 | bbtn->SetBitmapPressed(CreateBitmap(wxT("pushed"))); |
3e764e2f | 440 | if ( m_chkUseFocused->GetValue() ) |
9a83f860 | 441 | bbtn->SetBitmapFocus(CreateBitmap(wxT("focused"))); |
d5b98eb9 | 442 | if ( m_chkUseCurrent->GetValue() ) |
9a83f860 | 443 | bbtn->SetBitmapCurrent(CreateBitmap(wxT("hover"))); |
3e764e2f | 444 | if ( m_chkUseDisabled->GetValue() ) |
9a83f860 | 445 | bbtn->SetBitmapDisabled(CreateBitmap(wxT("disabled"))); |
552271d6 | 446 | m_button = bbtn; |
3571e1ad VZ |
447 | #if wxUSE_COMMANDLINKBUTTON |
448 | m_cmdLnkButton = NULL; | |
449 | #endif | |
552271d6 VZ |
450 | } |
451 | else // normal button | |
452 | { | |
3571e1ad VZ |
453 | #if wxUSE_COMMANDLINKBUTTON |
454 | m_cmdLnkButton = NULL; | |
455 | ||
456 | if ( m_chkCommandLink->GetValue() ) | |
457 | { | |
458 | m_cmdLnkButton = new wxCommandLinkButton(this, ButtonPage_Button, | |
459 | label, | |
460 | m_textNote->GetValue(), | |
461 | wxDefaultPosition, | |
462 | wxDefaultSize, | |
463 | flags); | |
464 | m_button = m_cmdLnkButton; | |
465 | } | |
466 | else | |
467 | #endif // wxUSE_COMMANDLINKBUTTON | |
468 | { | |
469 | m_button = new wxButton(this, ButtonPage_Button, label, | |
470 | wxDefaultPosition, wxDefaultSize, | |
471 | flags); | |
472 | } | |
552271d6 | 473 | } |
32b8ec41 | 474 | |
d5b98eb9 | 475 | if ( !showsBitmap && m_chkTextAndBitmap->GetValue() ) |
32b8ec41 | 476 | { |
d5b98eb9 VZ |
477 | showsBitmap = true; |
478 | ||
233f10bf VZ |
479 | static const wxDirection positions[] = |
480 | { | |
481 | wxLEFT, wxRIGHT, wxTOP, wxBOTTOM | |
482 | }; | |
483 | ||
484 | m_button->SetBitmap(wxArtProvider::GetIcon(wxART_INFORMATION), | |
485 | positions[m_radioImagePos->GetSelection()]); | |
d5b98eb9 VZ |
486 | |
487 | if ( m_chkUsePressed->GetValue() ) | |
488 | m_button->SetBitmapPressed(wxArtProvider::GetIcon(wxART_HELP)); | |
489 | if ( m_chkUseFocused->GetValue() ) | |
490 | m_button->SetBitmapFocus(wxArtProvider::GetIcon(wxART_ERROR)); | |
491 | if ( m_chkUseCurrent->GetValue() ) | |
492 | m_button->SetBitmapCurrent(wxArtProvider::GetIcon(wxART_WARNING)); | |
493 | if ( m_chkUseDisabled->GetValue() ) | |
494 | m_button->SetBitmapDisabled(wxArtProvider::GetIcon(wxART_MISSING_IMAGE)); | |
32b8ec41 | 495 | } |
32b8ec41 | 496 | |
d5b98eb9 VZ |
497 | m_chkUsePressed->Enable(showsBitmap); |
498 | m_chkUseFocused->Enable(showsBitmap); | |
499 | m_chkUseCurrent->Enable(showsBitmap); | |
500 | m_chkUseDisabled->Enable(showsBitmap); | |
501 | ||
f2d7fdf7 VZ |
502 | if ( m_chkAuthNeeded->GetValue() ) |
503 | m_button->SetAuthNeeded(); | |
504 | ||
32b8ec41 | 505 | if ( m_chkDefault->GetValue() ) |
32b8ec41 | 506 | m_button->SetDefault(); |
32b8ec41 | 507 | |
552271d6 VZ |
508 | AddButtonToSizer(); |
509 | ||
510 | m_sizerButton->Layout(); | |
511 | } | |
512 | ||
513 | void ButtonWidgetsPage::AddButtonToSizer() | |
514 | { | |
32b8ec41 VZ |
515 | if ( m_chkFit->GetValue() ) |
516 | { | |
552271d6 VZ |
517 | m_sizerButton->AddStretchSpacer(1); |
518 | m_sizerButton->Add(m_button, wxSizerFlags(0).Centre().Border()); | |
519 | m_sizerButton->AddStretchSpacer(1); | |
32b8ec41 | 520 | } |
552271d6 | 521 | else // take up the entire space |
32b8ec41 | 522 | { |
552271d6 | 523 | m_sizerButton->Add(m_button, wxSizerFlags(1).Expand().Border()); |
32b8ec41 | 524 | } |
32b8ec41 VZ |
525 | } |
526 | ||
527 | // ---------------------------------------------------------------------------- | |
528 | // event handlers | |
529 | // ---------------------------------------------------------------------------- | |
530 | ||
531 | void ButtonWidgetsPage::OnButtonReset(wxCommandEvent& WXUNUSED(event)) | |
532 | { | |
533 | Reset(); | |
534 | ||
535 | CreateButton(); | |
536 | } | |
537 | ||
c02e5a31 | 538 | void ButtonWidgetsPage::OnCheckOrRadioBox(wxCommandEvent& WXUNUSED(event)) |
32b8ec41 VZ |
539 | { |
540 | CreateButton(); | |
3571e1ad | 541 | Layout(); // make sure the text field for changing note displays correctly. |
32b8ec41 VZ |
542 | } |
543 | ||
544 | void ButtonWidgetsPage::OnButtonChangeLabel(wxCommandEvent& WXUNUSED(event)) | |
545 | { | |
3571e1ad VZ |
546 | #if wxUSE_COMMANDLINKBUTTON |
547 | if ( m_cmdLnkButton ) | |
548 | m_cmdLnkButton->SetMainLabel(m_textLabel->GetValue()); | |
549 | else | |
550 | #endif // wxUSE_COMMANDLINKBUTTON | |
551 | m_button->SetLabel(m_textLabel->GetValue()); | |
552 | ||
553 | m_sizerButton->Layout(); | |
554 | } | |
555 | ||
556 | void ButtonWidgetsPage::OnButtonChangeNote(wxCommandEvent& WXUNUSED(event)) | |
557 | { | |
558 | #if wxUSE_COMMANDLINKBUTTON | |
559 | m_cmdLnkButton->SetNote(m_textNote->GetValue()); | |
d46a35d0 VZ |
560 | |
561 | m_sizerButton->Layout(); | |
3571e1ad | 562 | #endif // wxUSE_COMMANDLINKBUTTON |
32b8ec41 VZ |
563 | } |
564 | ||
c02e5a31 | 565 | void ButtonWidgetsPage::OnButton(wxCommandEvent& WXUNUSED(event)) |
32b8ec41 | 566 | { |
9a83f860 | 567 | wxLogMessage(wxT("Test button clicked.")); |
32b8ec41 VZ |
568 | } |
569 | ||
552271d6 VZ |
570 | // ---------------------------------------------------------------------------- |
571 | // bitmap button stuff | |
572 | // ---------------------------------------------------------------------------- | |
573 | ||
574 | wxBitmap ButtonWidgetsPage::CreateBitmap(const wxString& label) | |
575 | { | |
576 | wxBitmap bmp(180, 70); // shouldn't hardcode but it's simpler like this | |
577 | wxMemoryDC dc; | |
578 | dc.SelectObject(bmp); | |
f2a4f50e | 579 | dc.SetBackground(wxBrush(*wxCYAN)); |
552271d6 | 580 | dc.Clear(); |
f2a4f50e | 581 | dc.SetTextForeground(*wxBLACK); |
9a83f860 VZ |
582 | dc.DrawLabel(wxStripMenuCodes(m_textLabel->GetValue()) + wxT("\n") |
583 | wxT("(") + label + wxT(" state)"), | |
552271d6 VZ |
584 | wxArtProvider::GetBitmap(wxART_INFORMATION), |
585 | wxRect(10, 10, bmp.GetWidth() - 20, bmp.GetHeight() - 20), | |
586 | wxALIGN_CENTRE); | |
587 | ||
588 | return bmp; | |
589 | } | |
590 |