button.cpp 19 KB

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