validate.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: validate.h
  3. // Purpose: wxWidgets validation sample
  4. // Author: Julian Smart
  5. // Modified by:
  6. // Created: 04/01/98
  7. // Copyright: (c) Julian Smart
  8. // Licence: wxWindows licence
  9. /////////////////////////////////////////////////////////////////////////////
  10. #include "wx/app.h"
  11. #include "wx/combobox.h"
  12. #include "wx/dialog.h"
  13. #include "wx/dynarray.h"
  14. #include "wx/frame.h"
  15. #include "wx/listbox.h"
  16. #include "wx/string.h"
  17. // Define a new application type
  18. class MyApp : public wxApp
  19. {
  20. public:
  21. bool OnInit();
  22. };
  23. // Define a new frame type
  24. class MyFrame : public wxFrame
  25. {
  26. public:
  27. MyFrame(wxFrame *frame, const wxString&title, int x, int y, int w, int h);
  28. void OnQuit(wxCommandEvent& event);
  29. void OnTestDialog(wxCommandEvent& event);
  30. void OnToggleBell(wxCommandEvent& event);
  31. private:
  32. wxListBox *m_listbox;
  33. bool m_silent;
  34. wxDECLARE_EVENT_TABLE();
  35. };
  36. class MyDialog : public wxDialog
  37. {
  38. public:
  39. MyDialog(wxWindow *parent, const wxString& title,
  40. const wxPoint& pos = wxDefaultPosition,
  41. const wxSize& size = wxDefaultSize,
  42. const long style = wxDEFAULT_DIALOG_STYLE);
  43. bool TransferDataToWindow();
  44. wxTextCtrl *m_text;
  45. wxComboBox *m_combobox;
  46. wxTextCtrl *m_numericTextInt;
  47. wxTextCtrl *m_numericTextDouble;
  48. };
  49. class MyData
  50. {
  51. public:
  52. MyData();
  53. // These data members are designed for transfer to and from
  54. // controls, via validators. For instance, a text control's
  55. // transferred value is a string:
  56. wxString m_string, m_string2;
  57. // Listboxes may permit multiple selections, so their state
  58. // is transferred to an integer-array class.
  59. wxArrayInt m_listbox_choices;
  60. // Comboboxes differ from listboxes--validators transfer
  61. // the string entered in the combobox's text-edit field.
  62. wxString m_combobox_choice;
  63. // variables handled by wxNumericTextValidator
  64. int m_intValue;
  65. double m_doubleValue;
  66. bool m_checkbox_state;
  67. int m_radiobox_choice;
  68. };
  69. class MyComboBoxValidator : public wxValidator
  70. {
  71. public:
  72. MyComboBoxValidator(const MyComboBoxValidator& tocopy) { m_var=tocopy.m_var; }
  73. MyComboBoxValidator(wxString* var) { m_var=var; }
  74. virtual bool Validate(wxWindow* parent);
  75. virtual wxObject* Clone() const { return new MyComboBoxValidator(*this); }
  76. // Called to transfer data to the window
  77. virtual bool TransferToWindow();
  78. // Called to transfer data from the window
  79. virtual bool TransferFromWindow();
  80. protected:
  81. wxString* m_var;
  82. };
  83. enum
  84. {
  85. VALIDATE_DIALOG_ID = wxID_HIGHEST,
  86. VALIDATE_TEST_DIALOG,
  87. VALIDATE_TOGGLE_BELL,
  88. VALIDATE_TEXT,
  89. VALIDATE_TEXT2,
  90. VALIDATE_LIST,
  91. VALIDATE_CHECK,
  92. VALIDATE_COMBO,
  93. VALIDATE_RADIO
  94. };