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