Make wxValidator::SetWindow() virtual

Allow overriding the method called when the validator is associated with
the window, this can be convenient to perform some initialization on the
validator instance actually used as it can't be done on the initially
created object itself because it will be cloned by SetValidator(),
creating a new instance.

Also change SetWindow() to take wxWindow instead of wxWindowBase, this
still requires the cast in wxWindow::SetValidator(), but it's better to
have it there rather than in wxValidator and use the simpler type in the
public function signature.
This commit is contained in:
Vadim Zeitlin
2018-01-07 01:25:10 +01:00
parent 572fe37898
commit bfcd51cb6a
3 changed files with 15 additions and 9 deletions

View File

@@ -85,8 +85,11 @@ public:
/**
Associates a window with the validator.
This function is automatically called by wxWidgets when creating a wxWindow-derived
class instance which takes a wxValidator reference.
This function is automatically called by wxWidgets when creating a
wxWindow-derived class instance which takes a wxValidator reference.
Since wxWidgets 3.1.1, it can be overridden in custom validators in
order to perform any one-time initialization or checks of the window
when the validator is associated with it.
E.g.
@code
@@ -94,9 +97,9 @@ public:
wxTextValidator(wxFILTER_ALPHA, &g_data.m_string));
@endcode
will automatically link the wxTextValidator instance with the wxTextCtrl
instance.
instance and call SetWindow() method on the wxTextValidator object.
*/
void SetWindow(wxWindow* window);
virtual void SetWindow(wxWindow* window);
/**
This overridable function is called when the value in the window must