spinbtn.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Program: wxWidgets Widgets Sample
  3. // Name: spinbtn.cpp
  4. // Purpose: Part of the widgets sample showing wxSpinButton
  5. // Author: Vadim Zeitlin
  6. // Created: 16.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. #if wxUSE_SPINBTN
  22. // for all others, include the necessary headers
  23. #ifndef WX_PRECOMP
  24. #include "wx/log.h"
  25. #include "wx/bitmap.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/spinbutt.h"
  33. #include "wx/spinctrl.h"
  34. #include "wx/sizer.h"
  35. #include "wx/stattext.h"
  36. #include "widgets.h"
  37. #include "icons/spinbtn.xpm"
  38. // ----------------------------------------------------------------------------
  39. // constants
  40. // ----------------------------------------------------------------------------
  41. // control ids
  42. enum
  43. {
  44. SpinBtnPage_Reset = wxID_HIGHEST,
  45. SpinBtnPage_Clear,
  46. SpinBtnPage_SetValue,
  47. SpinBtnPage_SetMinAndMax,
  48. SpinBtnPage_SetBase,
  49. SpinBtnPage_CurValueText,
  50. SpinBtnPage_ValueText,
  51. SpinBtnPage_MinText,
  52. SpinBtnPage_MaxText,
  53. SpinBtnPage_BaseText,
  54. SpinBtnPage_SpinBtn,
  55. SpinBtnPage_SpinCtrl,
  56. SpinBtnPage_SpinCtrlDouble
  57. };
  58. // alignment radiobox values
  59. enum
  60. {
  61. Align_Left,
  62. Align_Centre,
  63. Align_Right
  64. };
  65. // ----------------------------------------------------------------------------
  66. // SpinBtnWidgetsPage
  67. // ----------------------------------------------------------------------------
  68. class SpinBtnWidgetsPage : public WidgetsPage
  69. {
  70. public:
  71. SpinBtnWidgetsPage(WidgetsBookCtrl *book, wxImageList *imaglist);
  72. virtual ~SpinBtnWidgetsPage(){};
  73. virtual wxControl *GetWidget() const { return m_spinbtn; }
  74. virtual Widgets GetWidgets() const
  75. {
  76. Widgets widgets(WidgetsPage::GetWidgets());
  77. widgets.push_back(m_spinctrl);
  78. widgets.push_back(m_spinctrldbl);
  79. return widgets;
  80. }
  81. virtual void RecreateWidget() { CreateSpin(); }
  82. // lazy creation of the content
  83. virtual void CreateContent();
  84. protected:
  85. // event handlers
  86. void OnButtonReset(wxCommandEvent& event);
  87. void OnButtonClear(wxCommandEvent& event);
  88. void OnButtonSetValue(wxCommandEvent& event);
  89. void OnButtonSetMinAndMax(wxCommandEvent& event);
  90. void OnButtonSetBase(wxCommandEvent& event);
  91. void OnCheckOrRadioBox(wxCommandEvent& event);
  92. void OnSpinBtn(wxSpinEvent& event);
  93. void OnSpinBtnUp(wxSpinEvent& event);
  94. void OnSpinBtnDown(wxSpinEvent& event);
  95. void OnSpinCtrl(wxSpinEvent& event);
  96. void OnSpinCtrlDouble(wxSpinDoubleEvent& event);
  97. void OnSpinText(wxCommandEvent& event);
  98. void OnSpinTextEnter(wxCommandEvent& event);
  99. void OnUpdateUIValueButton(wxUpdateUIEvent& event);
  100. void OnUpdateUIMinMaxButton(wxUpdateUIEvent& event);
  101. void OnUpdateUIBaseButton(wxUpdateUIEvent& event);
  102. void OnUpdateUIResetButton(wxUpdateUIEvent& event);
  103. void OnUpdateUICurValueText(wxUpdateUIEvent& event);
  104. // reset the spinbtn parameters
  105. void Reset();
  106. // (re)create the spinbtn
  107. void CreateSpin();
  108. // is this spinbtn value in range?
  109. bool IsValidValue(int val) const
  110. { return (val >= m_min) && (val <= m_max); }
  111. // the spinbtn range
  112. int m_min, m_max;
  113. // and numeric base
  114. int m_base;
  115. // the controls
  116. // ------------
  117. // the check/radio boxes for styles
  118. wxCheckBox *m_chkVert,
  119. *m_chkArrowKeys,
  120. *m_chkWrap,
  121. *m_chkProcessEnter;
  122. wxRadioBox *m_radioAlign;
  123. // the spinbtn and the spinctrl and the sizer containing them
  124. wxSpinButton *m_spinbtn;
  125. wxSpinCtrl *m_spinctrl;
  126. wxSpinCtrlDouble *m_spinctrldbl;
  127. wxSizer *m_sizerSpin;
  128. // the text entries for set value/range
  129. wxTextCtrl *m_textValue,
  130. *m_textMin,
  131. *m_textMax,
  132. *m_textBase;
  133. private:
  134. wxDECLARE_EVENT_TABLE();
  135. DECLARE_WIDGETS_PAGE(SpinBtnWidgetsPage)
  136. };
  137. // ----------------------------------------------------------------------------
  138. // event tables
  139. // ----------------------------------------------------------------------------
  140. wxBEGIN_EVENT_TABLE(SpinBtnWidgetsPage, WidgetsPage)
  141. EVT_BUTTON(SpinBtnPage_Reset, SpinBtnWidgetsPage::OnButtonReset)
  142. EVT_BUTTON(SpinBtnPage_SetValue, SpinBtnWidgetsPage::OnButtonSetValue)
  143. EVT_BUTTON(SpinBtnPage_SetMinAndMax, SpinBtnWidgetsPage::OnButtonSetMinAndMax)
  144. EVT_BUTTON(SpinBtnPage_SetBase, SpinBtnWidgetsPage::OnButtonSetBase)
  145. EVT_UPDATE_UI(SpinBtnPage_SetValue, SpinBtnWidgetsPage::OnUpdateUIValueButton)
  146. EVT_UPDATE_UI(SpinBtnPage_SetMinAndMax, SpinBtnWidgetsPage::OnUpdateUIMinMaxButton)
  147. EVT_UPDATE_UI(SpinBtnPage_SetBase, SpinBtnWidgetsPage::OnUpdateUIBaseButton)
  148. EVT_UPDATE_UI(SpinBtnPage_Reset, SpinBtnWidgetsPage::OnUpdateUIResetButton)
  149. EVT_UPDATE_UI(SpinBtnPage_CurValueText, SpinBtnWidgetsPage::OnUpdateUICurValueText)
  150. EVT_SPIN(SpinBtnPage_SpinBtn, SpinBtnWidgetsPage::OnSpinBtn)
  151. EVT_SPIN_UP(SpinBtnPage_SpinBtn, SpinBtnWidgetsPage::OnSpinBtnUp)
  152. EVT_SPIN_DOWN(SpinBtnPage_SpinBtn, SpinBtnWidgetsPage::OnSpinBtnDown)
  153. EVT_SPINCTRL(SpinBtnPage_SpinCtrl, SpinBtnWidgetsPage::OnSpinCtrl)
  154. EVT_SPINCTRLDOUBLE(SpinBtnPage_SpinCtrlDouble, SpinBtnWidgetsPage::OnSpinCtrlDouble)
  155. EVT_TEXT(SpinBtnPage_SpinCtrl, SpinBtnWidgetsPage::OnSpinText)
  156. EVT_TEXT_ENTER(SpinBtnPage_SpinCtrl, SpinBtnWidgetsPage::OnSpinTextEnter)
  157. EVT_TEXT(SpinBtnPage_SpinCtrlDouble, SpinBtnWidgetsPage::OnSpinText)
  158. EVT_TEXT_ENTER(SpinBtnPage_SpinCtrlDouble, SpinBtnWidgetsPage::OnSpinTextEnter)
  159. EVT_CHECKBOX(wxID_ANY, SpinBtnWidgetsPage::OnCheckOrRadioBox)
  160. EVT_RADIOBOX(wxID_ANY, SpinBtnWidgetsPage::OnCheckOrRadioBox)
  161. wxEND_EVENT_TABLE()
  162. // ============================================================================
  163. // implementation
  164. // ============================================================================
  165. #if defined(__WXUNIVERSAL__)
  166. #define FAMILY_CTRLS UNIVERSAL_CTRLS
  167. #else
  168. #define FAMILY_CTRLS NATIVE_CTRLS
  169. #endif
  170. IMPLEMENT_WIDGETS_PAGE(SpinBtnWidgetsPage, wxT("Spin"),
  171. FAMILY_CTRLS | EDITABLE_CTRLS
  172. );
  173. SpinBtnWidgetsPage::SpinBtnWidgetsPage(WidgetsBookCtrl *book,
  174. wxImageList *imaglist)
  175. : WidgetsPage(book, imaglist, spinbtn_xpm)
  176. {
  177. m_chkVert = NULL;
  178. m_chkArrowKeys = NULL;
  179. m_chkWrap = NULL;
  180. m_chkProcessEnter = NULL;
  181. m_radioAlign = NULL;
  182. m_spinbtn = NULL;
  183. m_spinctrl = NULL;
  184. m_spinctrldbl = NULL;
  185. m_textValue =
  186. m_textMin =
  187. m_textMax =
  188. m_textBase = NULL;
  189. m_min = 0;
  190. m_max = 10;
  191. m_base = 10;
  192. m_sizerSpin = NULL;
  193. }
  194. void SpinBtnWidgetsPage::CreateContent()
  195. {
  196. wxSizer *sizerTop = new wxBoxSizer(wxHORIZONTAL);
  197. // left pane
  198. wxStaticBox *box = new wxStaticBox(this, wxID_ANY, wxT("&Set style"));
  199. wxSizer *sizerLeft = new wxStaticBoxSizer(box, wxVERTICAL);
  200. m_chkVert = CreateCheckBoxAndAddToSizer(sizerLeft, wxT("&Vertical"));
  201. m_chkArrowKeys = CreateCheckBoxAndAddToSizer(sizerLeft, wxT("&Arrow Keys"));
  202. m_chkWrap = CreateCheckBoxAndAddToSizer(sizerLeft, wxT("&Wrap"));
  203. m_chkProcessEnter = CreateCheckBoxAndAddToSizer(sizerLeft,
  204. wxT("Process &Enter"));
  205. sizerLeft->Add(5, 5, 0, wxGROW | wxALL, 5); // spacer
  206. static const wxString halign[] =
  207. {
  208. wxT("left"),
  209. wxT("centre"),
  210. wxT("right"),
  211. };
  212. m_radioAlign = new wxRadioBox(this, wxID_ANY, wxT("&Text alignment"),
  213. wxDefaultPosition, wxDefaultSize,
  214. WXSIZEOF(halign), halign, 1);
  215. sizerLeft->Add(m_radioAlign, 0, wxGROW | wxALL, 5);
  216. sizerLeft->Add(5, 5, 0, wxGROW | wxALL, 5); // spacer
  217. wxButton *btn = new wxButton(this, SpinBtnPage_Reset, wxT("&Reset"));
  218. sizerLeft->Add(btn, 0, wxALIGN_CENTRE_HORIZONTAL | wxALL, 15);
  219. // middle pane
  220. wxStaticBox *box2 = new wxStaticBox(this, wxID_ANY,
  221. wxT("&Change spinbtn value"));
  222. wxSizer *sizerMiddle = new wxStaticBoxSizer(box2, wxVERTICAL);
  223. wxTextCtrl *text;
  224. wxSizer *sizerRow = CreateSizerWithTextAndLabel(wxT("Current value"),
  225. SpinBtnPage_CurValueText,
  226. &text);
  227. text->SetEditable(false);
  228. sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5);
  229. sizerRow = CreateSizerWithTextAndButton(SpinBtnPage_SetValue,
  230. wxT("Set &value"),
  231. SpinBtnPage_ValueText,
  232. &m_textValue);
  233. sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5);
  234. sizerRow = CreateSizerWithTextAndButton(SpinBtnPage_SetMinAndMax,
  235. wxT("&Min and max"),
  236. SpinBtnPage_MinText,
  237. &m_textMin);
  238. m_textMax = new wxTextCtrl(this, SpinBtnPage_MaxText, wxEmptyString);
  239. sizerRow->Add(m_textMax, 1, wxLEFT | wxALIGN_CENTRE_VERTICAL, 5);
  240. m_textMin->SetValue( wxString::Format(wxT("%d"), m_min) );
  241. m_textMax->SetValue( wxString::Format(wxT("%d"), m_max) );
  242. sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5);
  243. sizerRow = CreateSizerWithTextAndButton(SpinBtnPage_SetBase,
  244. "Set &base",
  245. SpinBtnPage_BaseText,
  246. &m_textBase);
  247. m_textBase->SetValue("10");
  248. sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5);
  249. // right pane
  250. wxSizer *sizerRight = new wxBoxSizer(wxVERTICAL);
  251. sizerRight->SetMinSize(150, 0);
  252. m_sizerSpin = sizerRight; // save it to modify it later
  253. Reset();
  254. CreateSpin();
  255. // the 3 panes panes compose the window
  256. sizerTop->Add(sizerLeft, 0, wxGROW | (wxALL & ~wxLEFT), 10);
  257. sizerTop->Add(sizerMiddle, 0, wxGROW | wxALL, 10);
  258. sizerTop->Add(sizerRight, 1, wxGROW | (wxALL & ~wxRIGHT), 10);
  259. // final initializations
  260. SetSizer(sizerTop);
  261. }
  262. // ----------------------------------------------------------------------------
  263. // operations
  264. // ----------------------------------------------------------------------------
  265. void SpinBtnWidgetsPage::Reset()
  266. {
  267. m_chkVert->SetValue(true);
  268. m_chkArrowKeys->SetValue(true);
  269. m_chkWrap->SetValue(false);
  270. m_chkProcessEnter->SetValue(false);
  271. m_radioAlign->SetSelection(Align_Right);
  272. }
  273. void SpinBtnWidgetsPage::CreateSpin()
  274. {
  275. int flags = ms_defaultFlags;
  276. bool isVert = m_chkVert->GetValue();
  277. if ( isVert )
  278. flags |= wxSP_VERTICAL;
  279. else
  280. flags |= wxSP_HORIZONTAL;
  281. if ( m_chkArrowKeys->GetValue() )
  282. flags |= wxSP_ARROW_KEYS;
  283. if ( m_chkWrap->GetValue() )
  284. flags |= wxSP_WRAP;
  285. if ( m_chkProcessEnter->GetValue() )
  286. flags |= wxTE_PROCESS_ENTER;
  287. int textFlags = 0;
  288. switch ( m_radioAlign->GetSelection() )
  289. {
  290. default:
  291. wxFAIL_MSG(wxT("unexpected radiobox selection"));
  292. // fall through
  293. case Align_Left:
  294. textFlags |= wxALIGN_LEFT; // no-op
  295. break;
  296. case Align_Centre:
  297. textFlags |= wxALIGN_CENTRE_HORIZONTAL;
  298. break;
  299. case Align_Right:
  300. textFlags |= wxALIGN_RIGHT;
  301. break;
  302. }
  303. int val = m_min;
  304. if ( m_spinbtn )
  305. {
  306. int valOld = m_spinbtn->GetValue();
  307. if ( !IsValidValue(valOld) )
  308. {
  309. val = valOld;
  310. }
  311. m_sizerSpin->Clear(true /* delete windows */);
  312. }
  313. m_spinbtn = new wxSpinButton(this, SpinBtnPage_SpinBtn,
  314. wxDefaultPosition, wxDefaultSize,
  315. flags);
  316. m_spinbtn->SetValue(val);
  317. m_spinbtn->SetRange(m_min, m_max);
  318. m_spinctrl = new wxSpinCtrl(this, SpinBtnPage_SpinCtrl,
  319. wxString::Format(wxT("%d"), val),
  320. wxDefaultPosition, wxDefaultSize,
  321. flags | textFlags,
  322. m_min, m_max, val);
  323. m_spinctrldbl = new wxSpinCtrlDouble(this, SpinBtnPage_SpinCtrlDouble,
  324. wxString::Format(wxT("%d"), val),
  325. wxDefaultPosition, wxDefaultSize,
  326. flags | textFlags,
  327. m_min, m_max, val, 0.1);
  328. // Add spacers, labels and spin controls to the sizer.
  329. m_sizerSpin->Add(0, 0, 1);
  330. m_sizerSpin->Add(new wxStaticText(this, wxID_ANY, wxT("wxSpinButton")),
  331. 0, wxALIGN_CENTRE | wxALL, 5);
  332. m_sizerSpin->Add(m_spinbtn, 0, wxALIGN_CENTRE | wxALL, 5);
  333. m_sizerSpin->Add(0, 0, 1);
  334. m_sizerSpin->Add(new wxStaticText(this, wxID_ANY, wxT("wxSpinCtrl")),
  335. 0, wxALIGN_CENTRE | wxALL, 5);
  336. m_sizerSpin->Add(m_spinctrl, 0, wxALIGN_CENTRE | wxALL, 5);
  337. m_sizerSpin->Add(0, 0, 1);
  338. m_sizerSpin->Add(new wxStaticText(this, wxID_ANY, wxT("wxSpinCtrlDouble")),
  339. 0, wxALIGN_CENTRE | wxALL, 5);
  340. m_sizerSpin->Add(m_spinctrldbl, 0, wxALIGN_CENTRE | wxALL, 5);
  341. m_sizerSpin->Add(0, 0, 1);
  342. m_sizerSpin->Layout();
  343. }
  344. // ----------------------------------------------------------------------------
  345. // event handlers
  346. // ----------------------------------------------------------------------------
  347. void SpinBtnWidgetsPage::OnButtonReset(wxCommandEvent& WXUNUSED(event))
  348. {
  349. Reset();
  350. CreateSpin();
  351. }
  352. void SpinBtnWidgetsPage::OnButtonSetMinAndMax(wxCommandEvent& WXUNUSED(event))
  353. {
  354. long minNew,
  355. maxNew = 0; // init to suppress compiler warning
  356. if ( !m_textMin->GetValue().ToLong(&minNew) ||
  357. !m_textMax->GetValue().ToLong(&maxNew) ||
  358. minNew > maxNew )
  359. {
  360. wxLogWarning(wxT("Invalid min/max values for the spinbtn."));
  361. return;
  362. }
  363. m_min = minNew;
  364. m_max = maxNew;
  365. wxString smax('9', m_textMax->GetValue().length());
  366. wxSize
  367. size = m_spinctrl->GetSizeFromTextSize(m_spinctrl->GetTextExtent(smax));
  368. m_spinctrl->SetMinSize(size);
  369. m_spinctrl->SetSize(size);
  370. smax += ".0";
  371. size = m_spinctrldbl->GetSizeFromTextSize(
  372. m_spinctrldbl->GetTextExtent(smax)
  373. );
  374. m_spinctrldbl->SetMinSize(size);
  375. m_spinctrldbl->SetSize(size);
  376. m_spinbtn->SetRange(minNew, maxNew);
  377. m_spinctrl->SetRange(minNew, maxNew);
  378. m_spinctrldbl->SetRange(minNew, maxNew);
  379. }
  380. void SpinBtnWidgetsPage::OnButtonSetBase(wxCommandEvent& WXUNUSED(event))
  381. {
  382. unsigned long base;
  383. if ( !m_textBase->GetValue().ToULong(&base) || !base )
  384. {
  385. wxLogWarning("Invalid base value.");
  386. return;
  387. }
  388. m_base = base;
  389. if ( !m_spinctrl->SetBase(m_base) )
  390. {
  391. wxLogWarning("Setting base %d failed.", m_base);
  392. }
  393. }
  394. void SpinBtnWidgetsPage::OnButtonSetValue(wxCommandEvent& WXUNUSED(event))
  395. {
  396. long val;
  397. if ( !m_textValue->GetValue().ToLong(&val) || !IsValidValue(val) )
  398. {
  399. wxLogWarning(wxT("Invalid spinbtn value."));
  400. return;
  401. }
  402. m_spinbtn->SetValue(val);
  403. m_spinctrl->SetValue(val);
  404. m_spinctrldbl->SetValue(val);
  405. }
  406. void SpinBtnWidgetsPage::OnUpdateUIValueButton(wxUpdateUIEvent& event)
  407. {
  408. long val;
  409. event.Enable( m_textValue->GetValue().ToLong(&val) && IsValidValue(val) );
  410. }
  411. void SpinBtnWidgetsPage::OnUpdateUIMinMaxButton(wxUpdateUIEvent& event)
  412. {
  413. long mn, mx;
  414. event.Enable( m_textMin->GetValue().ToLong(&mn) &&
  415. m_textMax->GetValue().ToLong(&mx) &&
  416. mn <= mx);
  417. }
  418. void SpinBtnWidgetsPage::OnUpdateUIBaseButton(wxUpdateUIEvent& event)
  419. {
  420. unsigned long base;
  421. event.Enable( m_textBase->GetValue().ToULong(&base) && base );
  422. }
  423. void SpinBtnWidgetsPage::OnUpdateUIResetButton(wxUpdateUIEvent& event)
  424. {
  425. event.Enable( !m_chkVert->GetValue() ||
  426. m_chkWrap->GetValue() ||
  427. m_chkProcessEnter->GetValue() );
  428. }
  429. void SpinBtnWidgetsPage::OnCheckOrRadioBox(wxCommandEvent& WXUNUSED(event))
  430. {
  431. CreateSpin();
  432. }
  433. void SpinBtnWidgetsPage::OnUpdateUICurValueText(wxUpdateUIEvent& event)
  434. {
  435. event.SetText( wxString::Format(wxT("%d"), m_spinbtn->GetValue()));
  436. }
  437. void SpinBtnWidgetsPage::OnSpinBtn(wxSpinEvent& event)
  438. {
  439. int value = event.GetInt();
  440. wxASSERT_MSG( value == m_spinbtn->GetValue(),
  441. wxT("spinbtn value should be the same") );
  442. wxLogMessage(wxT("Spin button value changed, now %d"), value);
  443. }
  444. void SpinBtnWidgetsPage::OnSpinBtnUp(wxSpinEvent& event)
  445. {
  446. wxLogMessage( wxT("Spin button value incremented, will be %d (was %d)"),
  447. event.GetInt(), m_spinbtn->GetValue() );
  448. }
  449. void SpinBtnWidgetsPage::OnSpinBtnDown(wxSpinEvent& event)
  450. {
  451. wxLogMessage( wxT("Spin button value decremented, will be %d (was %d)"),
  452. event.GetInt(), m_spinbtn->GetValue() );
  453. }
  454. void SpinBtnWidgetsPage::OnSpinCtrl(wxSpinEvent& event)
  455. {
  456. int value = event.GetInt();
  457. wxASSERT_MSG( value == m_spinctrl->GetValue(),
  458. wxT("spinctrl value should be the same") );
  459. wxLogMessage(wxT("Spin control value changed, now %d"), value);
  460. }
  461. void SpinBtnWidgetsPage::OnSpinCtrlDouble(wxSpinDoubleEvent& event)
  462. {
  463. double value = event.GetValue();
  464. wxLogMessage(wxT("Spin control value changed, now %g"), value);
  465. }
  466. void SpinBtnWidgetsPage::OnSpinText(wxCommandEvent& event)
  467. {
  468. wxLogMessage(wxT("Text changed in spin control, now \"%s\""),
  469. event.GetString().c_str());
  470. }
  471. void SpinBtnWidgetsPage::OnSpinTextEnter(wxCommandEvent& event)
  472. {
  473. wxLogMessage("\"Enter\" pressed in spin control, text is \"%s\"",
  474. event.GetString());
  475. }
  476. #endif // wxUSE_SPINBTN