validate.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: validate.h
  3. // Purpose: interface of wxValidator
  4. // Author: wxWidgets team
  5. // Licence: wxWindows licence
  6. /////////////////////////////////////////////////////////////////////////////
  7. /**
  8. @class wxValidator
  9. wxValidator is the base class for a family of validator classes that
  10. mediate between a class of control, and application data.
  11. A validator has three major roles:
  12. -# To transfer data from a C++ variable or own storage to and from a
  13. control.
  14. -# To validate data in a control, and show an appropriate error message.
  15. -# To filter events (such as keystrokes), thereby changing the behaviour
  16. of the associated control.
  17. Validators can be plugged into controls dynamically.
  18. To specify a default, "null" validator, use ::wxDefaultValidator.
  19. For more information, please see @ref overview_validator.
  20. @library{wxcore}
  21. @category{validator}
  22. @stdobjects
  23. ::wxDefaultValidator
  24. @see @ref overview_validator, wxTextValidator, wxGenericValidator,
  25. wxIntegerValidator, wxFloatingPointValidator
  26. */
  27. class wxValidator : public wxEvtHandler
  28. {
  29. public:
  30. /**
  31. Constructor.
  32. */
  33. wxValidator();
  34. /**
  35. Destructor.
  36. */
  37. virtual ~wxValidator();
  38. /**
  39. All validator classes must implement the Clone() function, which
  40. returns an identical copy of itself.
  41. This is because validators are passed to control constructors as
  42. references which must be copied. Unlike objects such as pens and
  43. brushes, it does not make sense to have a reference counting scheme to
  44. do this cloning because all validators should have separate data.
  45. @return This base function returns @NULL.
  46. */
  47. virtual wxObject* Clone() const;
  48. /**
  49. Returns the window associated with the validator.
  50. */
  51. wxWindow* GetWindow() const;
  52. /**
  53. This functions switches on or turns off the error sound produced by the
  54. validators if an invalid key is pressed.
  55. @since 2.9.1
  56. @param suppress
  57. If @true, error sound is not played when a validator detects an
  58. error. If @false, error sound is enabled.
  59. */
  60. static void SuppressBellOnError(bool suppress = true);
  61. /**
  62. Returns if the error sound is currently disabled.
  63. */
  64. static bool IsSilent();
  65. /**
  66. Associates a window with the validator.
  67. This function is automatically called by wxWidgets when creating a wxWindow-derived
  68. class instance which takes a wxValidator reference.
  69. E.g.
  70. @code
  71. new wxTextCtrl(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0,
  72. wxTextValidator(wxFILTER_ALPHA, &g_data.m_string));
  73. @endcode
  74. will automatically link the wxTextValidator instance with the wxTextCtrl
  75. instance.
  76. */
  77. void SetWindow(wxWindow* window);
  78. /**
  79. This overridable function is called when the value in the window must
  80. be transferred to the validator.
  81. @return @false if there is a problem.
  82. */
  83. virtual bool TransferFromWindow();
  84. /**
  85. This overridable function is called when the value associated with the
  86. validator must be transferred to the window.
  87. @return @false if there is a problem.
  88. */
  89. virtual bool TransferToWindow();
  90. /**
  91. This overridable function is called when the value in the associated
  92. window must be validated.
  93. @param parent
  94. The parent of the window associated with the validator.
  95. @return @false if the value in the window is not valid; you may pop up
  96. an error dialog.
  97. */
  98. virtual bool Validate(wxWindow* parent);
  99. };
  100. /**
  101. An empty, "null" wxValidator instance.
  102. */
  103. const wxValidator wxDefaultValidator;