]> git.saurik.com Git - wxWidgets.git/blame - samples/widgets/button.cpp
Split wxTextCompleter into a base class and wxTextCompleterSimple.
[wxWidgets.git] / samples / widgets / button.cpp
CommitLineData
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
54enum
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
63enum
64{
65 ButtonImagePos_Left,
66 ButtonImagePos_Right,
67 ButtonImagePos_Top,
68 ButtonImagePos_Bottom
69};
70
32b8ec41
VZ
71enum
72{
73 ButtonHAlign_Left,
74 ButtonHAlign_Centre,
75 ButtonHAlign_Right
76};
77
78enum
79{
80 ButtonVAlign_Top,
81 ButtonVAlign_Centre,
82 ButtonVAlign_Bottom
83};
84
85// ----------------------------------------------------------------------------
86// ButtonWidgetsPage
87// ----------------------------------------------------------------------------
88
89class ButtonWidgetsPage : public WidgetsPage
90{
91public:
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
101protected:
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
32b8ec41
VZ
137 *m_chkDefault;
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 171private:
5e173f35
GD
172 DECLARE_EVENT_TABLE()
173 DECLARE_WIDGETS_PAGE(ButtonWidgetsPage)
32b8ec41
VZ
174};
175
176// ----------------------------------------------------------------------------
177// event tables
178// ----------------------------------------------------------------------------
179
180BEGIN_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
189END_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 201IMPLEMENT_WIDGETS_PAGE(ButtonWidgetsPage, wxT("Button"), FAMILY_CTRLS );
32b8ec41 202
f2fdc4d5 203ButtonWidgetsPage::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 =
d5b98eb9 219 m_chkUsePressed =
3e764e2f 220 m_chkUseFocused =
d5b98eb9 221 m_chkUseCurrent =
3e764e2f 222 m_chkUseDisabled = (wxCheckBox *)NULL;
32b8ec41 223
233f10bf 224 m_radioImagePos =
32b8ec41
VZ
225 m_radioHAlign =
226 m_radioVAlign = (wxRadioBox *)NULL;
227
228 m_textLabel = (wxTextCtrl *)NULL;
229
230 m_button = (wxButton *)NULL;
231 m_sizerButton = (wxSizer *)NULL;
453535a7 232}
32b8ec41 233
453535a7
WS
234void ButtonWidgetsPage::CreateContent()
235{
32b8ec41
VZ
236 wxSizer *sizerTop = new wxBoxSizer(wxHORIZONTAL);
237
238 // left pane
9a83f860 239 wxStaticBox *box = new wxStaticBox(this, wxID_ANY, wxT("&Set style"));
32b8ec41
VZ
240
241 wxSizer *sizerLeft = new wxStaticBoxSizer(box, wxVERTICAL);
242
d5b98eb9 243 m_chkBitmapOnly = CreateCheckBoxAndAddToSizer(sizerLeft, "&Bitmap only");
f2d7fdf7 244 m_chkTextAndBitmap = CreateCheckBoxAndAddToSizer(sizerLeft, "Text &and bitmap");
9a83f860 245 m_chkFit = CreateCheckBoxAndAddToSizer(sizerLeft, wxT("&Fit exactly"));
f2d7fdf7 246 m_chkAuthNeeded = CreateCheckBoxAndAddToSizer(sizerLeft, wxT("Require a&uth"));
3571e1ad
VZ
247#if wxUSE_COMMANDLINKBUTTON
248 m_chkCommandLink = CreateCheckBoxAndAddToSizer(sizerLeft, wxT("Use command &link button"));
249#endif
95912bdd
VZ
250#if wxUSE_MARKUP
251 m_chkUseMarkup = CreateCheckBoxAndAddToSizer(sizerLeft, "Interpret &markup");
252#endif // wxUSE_MARKUP
9a83f860 253 m_chkDefault = CreateCheckBoxAndAddToSizer(sizerLeft, wxT("&Default"));
32b8ec41 254
3e764e2f
VZ
255 sizerLeft->AddSpacer(5);
256
257 wxSizer *sizerUseLabels =
d5b98eb9
VZ
258 new wxStaticBoxSizer(wxVERTICAL, this,
259 "&Use the following bitmaps in addition to the normal one?");
260 m_chkUsePressed = CreateCheckBoxAndAddToSizer(sizerUseLabels,
261 "&Pressed (small help icon)");
262 m_chkUseFocused = CreateCheckBoxAndAddToSizer(sizerUseLabels,
263 "&Focused (small error icon)");
264 m_chkUseCurrent = CreateCheckBoxAndAddToSizer(sizerUseLabels,
265 "&Current (small warning icon)");
266 m_chkUseDisabled = CreateCheckBoxAndAddToSizer(sizerUseLabels,
267 "&Disabled (broken image icon)");
3e764e2f
VZ
268 sizerLeft->Add(sizerUseLabels, wxSizerFlags().Expand().Border());
269
233f10bf
VZ
270 sizerLeft->AddSpacer(10);
271
272 static const wxString dirs[] =
273 {
274 "left", "right", "top", "bottom",
275 };
276 m_radioImagePos = new wxRadioBox(this, wxID_ANY, "Image &position",
277 wxDefaultPosition, wxDefaultSize,
278 WXSIZEOF(dirs), dirs);
279 sizerLeft->Add(m_radioImagePos, 0, wxGROW | wxALL, 5);
3e764e2f 280 sizerLeft->AddSpacer(15);
32b8ec41
VZ
281
282 // should be in sync with enums Button[HV]Align!
283 static const wxString halign[] =
284 {
9a83f860
VZ
285 wxT("left"),
286 wxT("centre"),
287 wxT("right"),
32b8ec41
VZ
288 };
289
290 static const wxString valign[] =
291 {
9a83f860
VZ
292 wxT("top"),
293 wxT("centre"),
294 wxT("bottom"),
32b8ec41
VZ
295 };
296
9a83f860 297 m_radioHAlign = new wxRadioBox(this, wxID_ANY, wxT("&Horz alignment"),
32b8ec41
VZ
298 wxDefaultPosition, wxDefaultSize,
299 WXSIZEOF(halign), halign);
9a83f860 300 m_radioVAlign = new wxRadioBox(this, wxID_ANY, wxT("&Vert alignment"),
32b8ec41
VZ
301 wxDefaultPosition, wxDefaultSize,
302 WXSIZEOF(valign), valign);
303
304 sizerLeft->Add(m_radioHAlign, 0, wxGROW | wxALL, 5);
305 sizerLeft->Add(m_radioVAlign, 0, wxGROW | wxALL, 5);
306
307 sizerLeft->Add(5, 5, 0, wxGROW | wxALL, 5); // spacer
308
9a83f860 309 wxButton *btn = new wxButton(this, ButtonPage_Reset, wxT("&Reset"));
32b8ec41
VZ
310 sizerLeft->Add(btn, 0, wxALIGN_CENTRE_HORIZONTAL | wxALL, 15);
311
312 // middle pane
9a83f860 313 wxStaticBox *box2 = new wxStaticBox(this, wxID_ANY, wxT("&Operations"));
32b8ec41
VZ
314 wxSizer *sizerMiddle = new wxStaticBoxSizer(box2, wxVERTICAL);
315
316 wxSizer *sizerRow = CreateSizerWithTextAndButton(ButtonPage_ChangeLabel,
9a83f860 317 wxT("Change label"),
206d3a16 318 wxID_ANY,
32b8ec41 319 &m_textLabel);
9a83f860 320 m_textLabel->SetValue(wxT("&Press me!"));
32b8ec41
VZ
321 sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5);
322
3571e1ad
VZ
323#if wxUSE_COMMANDLINKBUTTON
324 m_sizerNote = CreateSizerWithTextAndButton(ButtonPage_ChangeNote,
325 wxT("Change note"),
326 wxID_ANY,
327 &m_textNote);
328 m_textNote->SetValue(wxT("Writes down button clicks in the log."));
329
330 sizerMiddle->Add(m_sizerNote, 0, wxALL | wxGROW, 5);
331#endif
332
32b8ec41 333 // right pane
552271d6
VZ
334 m_sizerButton = new wxBoxSizer(wxHORIZONTAL);
335 m_sizerButton->SetMinSize(150, 0);
32b8ec41
VZ
336
337 // the 3 panes panes compose the window
338 sizerTop->Add(sizerLeft, 0, wxGROW | (wxALL & ~wxLEFT), 10);
339 sizerTop->Add(sizerMiddle, 1, wxGROW | wxALL, 10);
552271d6 340 sizerTop->Add(m_sizerButton, 1, wxGROW | (wxALL & ~wxRIGHT), 10);
32b8ec41 341
3e764e2f 342 // do create the main control
32b8ec41 343 Reset();
3e764e2f 344 CreateButton();
552271d6 345
32b8ec41 346 SetSizer(sizerTop);
32b8ec41
VZ
347}
348
32b8ec41
VZ
349// ----------------------------------------------------------------------------
350// operations
351// ----------------------------------------------------------------------------
352
353void ButtonWidgetsPage::Reset()
354{
d5b98eb9 355 m_chkBitmapOnly->SetValue(false);
206d3a16 356 m_chkFit->SetValue(true);
f2d7fdf7 357 m_chkAuthNeeded->SetValue(false);
d5b98eb9 358 m_chkTextAndBitmap->SetValue(false);
206d3a16 359 m_chkDefault->SetValue(false);
3571e1ad
VZ
360#if wxUSE_COMMANDLINKBUTTON
361 m_chkCommandLink->SetValue(false);
362#endif
95912bdd
VZ
363#if wxUSE_MARKUP
364 m_chkUseMarkup->SetValue(false);
365#endif // wxUSE_MARKUP
32b8ec41 366
d5b98eb9 367 m_chkUsePressed->SetValue(true);
3e764e2f 368 m_chkUseFocused->SetValue(true);
d5b98eb9 369 m_chkUseCurrent->SetValue(true);
3e764e2f
VZ
370 m_chkUseDisabled->SetValue(true);
371
233f10bf 372 m_radioImagePos->SetSelection(ButtonImagePos_Left);
32b8ec41
VZ
373 m_radioHAlign->SetSelection(ButtonHAlign_Centre);
374 m_radioVAlign->SetSelection(ButtonVAlign_Centre);
375}
376
377void ButtonWidgetsPage::CreateButton()
378{
379 wxString label;
380 if ( m_button )
381 {
3571e1ad
VZ
382#if wxUSE_COMMANDLINKBUTTON
383 if ( m_cmdLnkButton )
384 label = m_cmdLnkButton->GetMainLabel();
385 else
386#endif
387 label = m_button->GetLabel();
32b8ec41
VZ
388
389 size_t count = m_sizerButton->GetChildren().GetCount();
390 for ( size_t n = 0; n < count; n++ )
391 {
9dd96c0f 392 m_sizerButton->Remove( 0 );
32b8ec41
VZ
393 }
394
395 delete m_button;
396 }
552271d6
VZ
397
398 if ( label.empty() )
32b8ec41 399 {
552271d6
VZ
400 // creating for the first time or recreating a button after bitmap
401 // button
402 label = m_textLabel->GetValue();
32b8ec41
VZ
403 }
404
1301e228 405 int flags = ms_defaultFlags;
32b8ec41
VZ
406 switch ( m_radioHAlign->GetSelection() )
407 {
408 case ButtonHAlign_Left:
c0495687 409 flags |= wxBU_LEFT;
32b8ec41
VZ
410 break;
411
412 default:
9a83f860 413 wxFAIL_MSG(wxT("unexpected radiobox selection"));
32b8ec41
VZ
414 // fall through
415
416 case ButtonHAlign_Centre:
32b8ec41
VZ
417 break;
418
419 case ButtonHAlign_Right:
c0495687 420 flags |= wxBU_RIGHT;
32b8ec41
VZ
421 break;
422 }
423
424 switch ( m_radioVAlign->GetSelection() )
425 {
426 case ButtonVAlign_Top:
c0495687 427 flags |= wxBU_TOP;
32b8ec41
VZ
428 break;
429
430 default:
9a83f860 431 wxFAIL_MSG(wxT("unexpected radiobox selection"));
32b8ec41
VZ
432 // fall through
433
434 case ButtonVAlign_Centre:
4ee8e5cd 435 // centre vertical alignment is the default (no style)
32b8ec41
VZ
436 break;
437
438 case ButtonVAlign_Bottom:
c0495687 439 flags |= wxBU_BOTTOM;
32b8ec41
VZ
440 break;
441 }
442
3571e1ad
VZ
443#if wxUSE_COMMANDLINKBUTTON
444 m_sizerNote->Show(m_chkCommandLink->GetValue());
445#endif
446
d5b98eb9
VZ
447 bool showsBitmap = false;
448 if ( m_chkBitmapOnly->GetValue() )
552271d6 449 {
d5b98eb9
VZ
450 showsBitmap = true;
451
552271d6 452 wxBitmapButton *bbtn = new wxBitmapButton(this, ButtonPage_Button,
9a83f860 453 CreateBitmap(wxT("normal")));
d5b98eb9 454 if ( m_chkUsePressed->GetValue() )
9a83f860 455 bbtn->SetBitmapPressed(CreateBitmap(wxT("pushed")));
3e764e2f 456 if ( m_chkUseFocused->GetValue() )
9a83f860 457 bbtn->SetBitmapFocus(CreateBitmap(wxT("focused")));
d5b98eb9 458 if ( m_chkUseCurrent->GetValue() )
9a83f860 459 bbtn->SetBitmapCurrent(CreateBitmap(wxT("hover")));
3e764e2f 460 if ( m_chkUseDisabled->GetValue() )
9a83f860 461 bbtn->SetBitmapDisabled(CreateBitmap(wxT("disabled")));
552271d6 462 m_button = bbtn;
3571e1ad
VZ
463#if wxUSE_COMMANDLINKBUTTON
464 m_cmdLnkButton = NULL;
465#endif
552271d6
VZ
466 }
467 else // normal button
468 {
3571e1ad
VZ
469#if wxUSE_COMMANDLINKBUTTON
470 m_cmdLnkButton = NULL;
471
472 if ( m_chkCommandLink->GetValue() )
473 {
474 m_cmdLnkButton = new wxCommandLinkButton(this, ButtonPage_Button,
475 label,
476 m_textNote->GetValue(),
477 wxDefaultPosition,
478 wxDefaultSize,
479 flags);
480 m_button = m_cmdLnkButton;
481 }
482 else
483#endif // wxUSE_COMMANDLINKBUTTON
484 {
485 m_button = new wxButton(this, ButtonPage_Button, label,
486 wxDefaultPosition, wxDefaultSize,
487 flags);
488 }
552271d6 489 }
32b8ec41 490
d5b98eb9 491 if ( !showsBitmap && m_chkTextAndBitmap->GetValue() )
32b8ec41 492 {
d5b98eb9
VZ
493 showsBitmap = true;
494
233f10bf
VZ
495 static const wxDirection positions[] =
496 {
497 wxLEFT, wxRIGHT, wxTOP, wxBOTTOM
498 };
499
825ce0af 500 m_button->SetBitmap(wxArtProvider::GetIcon(wxART_INFORMATION, wxART_BUTTON),
233f10bf 501 positions[m_radioImagePos->GetSelection()]);
d5b98eb9
VZ
502
503 if ( m_chkUsePressed->GetValue() )
825ce0af 504 m_button->SetBitmapPressed(wxArtProvider::GetIcon(wxART_HELP, wxART_BUTTON));
d5b98eb9 505 if ( m_chkUseFocused->GetValue() )
825ce0af 506 m_button->SetBitmapFocus(wxArtProvider::GetIcon(wxART_ERROR, wxART_BUTTON));
d5b98eb9 507 if ( m_chkUseCurrent->GetValue() )
825ce0af 508 m_button->SetBitmapCurrent(wxArtProvider::GetIcon(wxART_WARNING, wxART_BUTTON));
d5b98eb9 509 if ( m_chkUseDisabled->GetValue() )
825ce0af 510 m_button->SetBitmapDisabled(wxArtProvider::GetIcon(wxART_MISSING_IMAGE, wxART_BUTTON));
32b8ec41 511 }
32b8ec41 512
d5b98eb9
VZ
513 m_chkUsePressed->Enable(showsBitmap);
514 m_chkUseFocused->Enable(showsBitmap);
515 m_chkUseCurrent->Enable(showsBitmap);
516 m_chkUseDisabled->Enable(showsBitmap);
517
f2d7fdf7
VZ
518 if ( m_chkAuthNeeded->GetValue() )
519 m_button->SetAuthNeeded();
520
32b8ec41 521 if ( m_chkDefault->GetValue() )
32b8ec41 522 m_button->SetDefault();
32b8ec41 523
552271d6
VZ
524 AddButtonToSizer();
525
526 m_sizerButton->Layout();
527}
528
529void ButtonWidgetsPage::AddButtonToSizer()
530{
32b8ec41
VZ
531 if ( m_chkFit->GetValue() )
532 {
552271d6
VZ
533 m_sizerButton->AddStretchSpacer(1);
534 m_sizerButton->Add(m_button, wxSizerFlags(0).Centre().Border());
535 m_sizerButton->AddStretchSpacer(1);
32b8ec41 536 }
552271d6 537 else // take up the entire space
32b8ec41 538 {
552271d6 539 m_sizerButton->Add(m_button, wxSizerFlags(1).Expand().Border());
32b8ec41 540 }
32b8ec41
VZ
541}
542
543// ----------------------------------------------------------------------------
544// event handlers
545// ----------------------------------------------------------------------------
546
547void ButtonWidgetsPage::OnButtonReset(wxCommandEvent& WXUNUSED(event))
548{
549 Reset();
550
551 CreateButton();
552}
553
c02e5a31 554void ButtonWidgetsPage::OnCheckOrRadioBox(wxCommandEvent& WXUNUSED(event))
32b8ec41
VZ
555{
556 CreateButton();
3571e1ad 557 Layout(); // make sure the text field for changing note displays correctly.
32b8ec41
VZ
558}
559
560void ButtonWidgetsPage::OnButtonChangeLabel(wxCommandEvent& WXUNUSED(event))
561{
95912bdd
VZ
562 const wxString labelText = m_textLabel->GetValue();
563
3571e1ad
VZ
564#if wxUSE_COMMANDLINKBUTTON
565 if ( m_cmdLnkButton )
95912bdd 566 m_cmdLnkButton->SetMainLabel(labelText);
3571e1ad
VZ
567 else
568#endif // wxUSE_COMMANDLINKBUTTON
95912bdd
VZ
569 {
570#if wxUSE_MARKUP
571 if ( m_chkUseMarkup->GetValue() )
572 m_button->SetLabelMarkup(labelText);
573 else
574#endif // wxUSE_MARKUP
575 m_button->SetLabel(labelText);
576 }
3571e1ad
VZ
577
578 m_sizerButton->Layout();
579}
580
581void ButtonWidgetsPage::OnButtonChangeNote(wxCommandEvent& WXUNUSED(event))
582{
583#if wxUSE_COMMANDLINKBUTTON
584 m_cmdLnkButton->SetNote(m_textNote->GetValue());
d46a35d0
VZ
585
586 m_sizerButton->Layout();
3571e1ad 587#endif // wxUSE_COMMANDLINKBUTTON
32b8ec41
VZ
588}
589
c02e5a31 590void ButtonWidgetsPage::OnButton(wxCommandEvent& WXUNUSED(event))
32b8ec41 591{
9a83f860 592 wxLogMessage(wxT("Test button clicked."));
32b8ec41
VZ
593}
594
552271d6
VZ
595// ----------------------------------------------------------------------------
596// bitmap button stuff
597// ----------------------------------------------------------------------------
598
599wxBitmap ButtonWidgetsPage::CreateBitmap(const wxString& label)
600{
601 wxBitmap bmp(180, 70); // shouldn't hardcode but it's simpler like this
602 wxMemoryDC dc;
603 dc.SelectObject(bmp);
f2a4f50e 604 dc.SetBackground(wxBrush(*wxCYAN));
552271d6 605 dc.Clear();
f2a4f50e 606 dc.SetTextForeground(*wxBLACK);
9a83f860
VZ
607 dc.DrawLabel(wxStripMenuCodes(m_textLabel->GetValue()) + wxT("\n")
608 wxT("(") + label + wxT(" state)"),
552271d6
VZ
609 wxArtProvider::GetBitmap(wxART_INFORMATION),
610 wxRect(10, 10, bmp.GetWidth() - 20, bmp.GetHeight() - 20),
611 wxALIGN_CENTRE);
612
613 return bmp;
614}
615