X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/a660d684eda27638bca0384b2058911a31c8e845..852b6c3ce7baa055da25f5254f6ee2eee0cd79b7:/docs/latex/wx/tvalidat.tex diff --git a/docs/latex/wx/tvalidat.tex b/docs/latex/wx/tvalidat.tex index 2709a704c6..93105606a5 100644 --- a/docs/latex/wx/tvalidat.tex +++ b/docs/latex/wx/tvalidat.tex @@ -1,6 +1,7 @@ -\section{Validator overview}\label{validatoroverview} +\section{wxValidator overview}\label{validatoroverview} -Classes: \helpref{wxValidator}{wxvalidator}, \helpref{wxTextValidator}{wxtextvalidator} +Classes: \helpref{wxValidator}{wxvalidator}, \helpref{wxTextValidator}{wxtextvalidator}, +\helpref{wxGenericValidator}{wxgenericvalidator} The aim of the validator concept is to make dialogs very much easier to write. A validator is an object that can be plugged into a control (such as a wxTextCtrl), and @@ -8,15 +9,17 @@ mediates between C++ data and the control, transferring the data in either direc and validating it. It also is able to intercept events generated by the control, providing filtering behaviour without the need to derive a new control class. -You can use a stock validator, such as \helpref{wxTextValidator}{wxtextvalidator}; or -you can write your own. +You can use a stock validator, such as \helpref{wxTextValidator}{wxtextvalidator} (which does text +control data transfer, validation and filtering) and +\helpref{wxGenericValidator}{wxgenericvalidator} (which does data transfer for a range of controls); +or you can write your own. \wxheading{Example} Here is an example of wxTextValidator usage. \begin{verbatim} - wxTextCtrl *txt1 = new wxTextCtrl(this, VALIDATE_TEXT, "", + wxTextCtrl *txt1 = new wxTextCtrl(this, -1, wxT(""), wxPoint(10, 10), wxSize(100, 80), 0, wxTextValidator(wxFILTER_ALPHA, &g_data.m_string)); \end{verbatim} @@ -47,7 +50,7 @@ data for the control. If such a variable address is not supplied by the user, th the validator should store the data internally. The \helpref{wxValidator::Validate}{wxvalidatorvalidate} member function should return -TRUE if the data in the control (not the C++ variable) is valid. It should also show +true if the data in the control (not the C++ variable) is valid. It should also show an appropriate message if data was not valid. The \helpref{wxValidator::TransferToWindow}{wxvalidatortransfertowindow} member function should @@ -63,7 +66,7 @@ are passed by reference to window constructors, and must therefore be cloned int You can optionally define event handlers for the validator, to implement filtering. These handlers will capture events before the control itself does. -For an example implementation, see the valtext.h and valtext.cpp files in the wxWindows library. +For an example implementation, see the valtext.h and valtext.cpp files in the wxWidgets library. \wxheading{How validators interact with dialogs} @@ -85,7 +88,7 @@ call \helpref{wxWindow::InitDialog}{wxwindowinitdialog} explicitly before showin window.} When the user clicks on a button, for example the OK button, the application should -first call \helpref{wxWindow::Validate}{wxwindowvalidate}, which returns FALSE if +first call \helpref{wxWindow::Validate}{wxwindowvalidate}, which returns false if any of the child window validators failed to validate the window data. The button handler should return immediately if validation failed. Secondly, the application should call \helpref{wxWindow::TransferDataFromWindow}{wxwindowtransferdatafromwindow} and @@ -98,19 +101,22 @@ this: \begin{verbatim} void wxDialog::OnOK(wxCommandEvent& event) { - if ( Validate() && TransferDataFromWindow() ) - { + if ( Validate() && TransferDataFromWindow() ) + { if ( IsModal() ) EndModal(wxID_OK); else { - SetReturnCode(wxID_OK); - this->Show(FALSE); + SetReturnCode(wxID_OK); + this->Show(false); } - } + } } \end{verbatim} So if using validators and a normal OK button, you may not even need to write any code for handling dialog dismissal. +If you load your dialog from a resource file, you will need to iterate through the controls +setting validators, since validators can't be specified in a dialog resource. +