moving forward
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@52050 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -20,6 +20,7 @@
|
|||||||
number of application could offer WYSIWYG under Unix. Equally,
|
number of application could offer WYSIWYG under Unix. Equally,
|
||||||
wxWidgets offered its own printing implementation using PostScript
|
wxWidgets offered its own printing implementation using PostScript
|
||||||
which never really matched the screen display.
|
which never really matched the screen display.
|
||||||
|
|
||||||
Starting with version 2.8.X, the GNOME project provides printing
|
Starting with version 2.8.X, the GNOME project provides printing
|
||||||
support through the libgnomeprint and libgnomeprintui libraries
|
support through the libgnomeprint and libgnomeprintui libraries
|
||||||
by which especially the font problem is mostly solved. Beginning
|
by which especially the font problem is mostly solved. Beginning
|
||||||
@@ -33,6 +34,7 @@
|
|||||||
Note that the application will not require the GNOME print libraries
|
Note that the application will not require the GNOME print libraries
|
||||||
to be installed in order to run (there will be no dependency on
|
to be installed in order to run (there will be no dependency on
|
||||||
these libraries).
|
these libraries).
|
||||||
|
|
||||||
In version GTK+ 2.10, support for printing has been added to GTK+
|
In version GTK+ 2.10, support for printing has been added to GTK+
|
||||||
itself. Beginning with version wxWidgets 2.9.X, the GTK+ port of
|
itself. Beginning with version wxWidgets 2.9.X, the GTK+ port of
|
||||||
wxWidgets can make use of this feature
|
wxWidgets can make use of this feature
|
||||||
|
@@ -12,16 +12,20 @@
|
|||||||
|
|
||||||
Classes: #wxValidator, #wxTextValidator,
|
Classes: #wxValidator, #wxTextValidator,
|
||||||
#wxGenericValidator
|
#wxGenericValidator
|
||||||
|
|
||||||
The aim of the validator concept is to make dialogs very much easier to write.
|
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
|
A validator is an object that can be plugged into a control (such as a wxTextCtrl), and
|
||||||
mediates between C++ data and the control, transferring the data in either direction
|
mediates between C++ data and the control, transferring the data in either direction
|
||||||
and validating it. It also is able to intercept events generated
|
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.
|
by the control, providing filtering behaviour without the need to derive a new control class.
|
||||||
|
|
||||||
You can use a stock validator, such as #wxTextValidator (which does text
|
You can use a stock validator, such as #wxTextValidator (which does text
|
||||||
control data transfer, validation and filtering) and
|
control data transfer, validation and filtering) and
|
||||||
#wxGenericValidator (which does data transfer for a range of controls);
|
#wxGenericValidator (which does data transfer for a range of controls);
|
||||||
or you can write your own.
|
or you can write your own.
|
||||||
@b Example
|
|
||||||
|
@section example Example
|
||||||
|
|
||||||
Here is an example of wxTextValidator usage.
|
Here is an example of wxTextValidator usage.
|
||||||
|
|
||||||
@code
|
@code
|
||||||
@@ -32,12 +36,10 @@
|
|||||||
|
|
||||||
In this example, the text validator object provides the following functionality:
|
In this example, the text validator object provides the following functionality:
|
||||||
|
|
||||||
|
@li It transfers the value of g_data.m_string (a wxString variable) to the wxTextCtrl when
|
||||||
It transfers the value of g_data.m_string (a wxString variable) to the wxTextCtrl when
|
|
||||||
the dialog is initialised.
|
the dialog is initialised.
|
||||||
It transfers the wxTextCtrl data back to this variable when the dialog is dismissed.
|
@li It transfers the wxTextCtrl data back to this variable when the dialog is dismissed.
|
||||||
It filters input characters so that only alphabetic characters are allowed.
|
@li It filters input characters so that only alphabetic characters are allowed.
|
||||||
|
|
||||||
|
|
||||||
The validation and filtering of input is accomplished in two ways. When a character is input,
|
The validation and filtering of input is accomplished in two ways. When a character is input,
|
||||||
wxTextValidator checks the character against the allowed filter flag (wxFILTER_ALPHA in this case). If
|
wxTextValidator checks the character against the allowed filter flag (wxFILTER_ALPHA in this case). If
|
||||||
@@ -45,28 +47,39 @@
|
|||||||
The second type of validation is performed when the dialog is about to be dismissed, so if
|
The second type of validation is performed when the dialog is about to be dismissed, so if
|
||||||
the default string contained invalid characters already, a dialog box is shown giving the
|
the default string contained invalid characters already, a dialog box is shown giving the
|
||||||
error, and the dialog is not dismissed.
|
error, and the dialog is not dismissed.
|
||||||
@b Anatomy of a validator
|
|
||||||
|
@section anatomy Anatomy of a validator
|
||||||
|
|
||||||
A programmer creating a new validator class should provide the following functionality.
|
A programmer creating a new validator class should provide the following functionality.
|
||||||
|
|
||||||
A validator constructor is responsible for allowing the programmer to specify the kind
|
A validator constructor is responsible for allowing the programmer to specify the kind
|
||||||
of validation required, and perhaps a pointer to a C++ variable that is used for storing the
|
of validation required, and perhaps a pointer to a C++ variable that is used for storing the
|
||||||
data for the control. If such a variable address is not supplied by the user, then
|
data for the control. If such a variable address is not supplied by the user, then
|
||||||
the validator should store the data internally.
|
the validator should store the data internally.
|
||||||
|
|
||||||
The wxValidator::Validate member function should return
|
The wxValidator::Validate 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.
|
an appropriate message if data was not valid.
|
||||||
|
|
||||||
The wxValidator::TransferToWindow member function should
|
The wxValidator::TransferToWindow member function should
|
||||||
transfer the data from the validator or associated C++ variable to the control.
|
transfer the data from the validator or associated C++ variable to the control.
|
||||||
|
|
||||||
The wxValidator::TransferFromWindow member function should
|
The wxValidator::TransferFromWindow member function should
|
||||||
transfer the data from the control to the validator or associated C++ variable.
|
transfer the data from the control to the validator or associated C++ variable.
|
||||||
|
|
||||||
There should be a copy constructor, and a wxValidator::Clone function
|
There should be a copy constructor, and a wxValidator::Clone function
|
||||||
which returns a copy of the validator object. This is important because validators
|
which returns a copy of the validator object. This is important because validators
|
||||||
are passed by reference to window constructors, and must therefore be cloned internally.
|
are passed by reference to window constructors, and must therefore be cloned internally.
|
||||||
|
|
||||||
You can optionally define event handlers for the validator, to implement filtering. These handlers
|
You can optionally define event handlers for the validator, to implement filtering. These handlers
|
||||||
will capture events before the control itself does.
|
will capture events before the control itself does.
|
||||||
For an example implementation, see the valtext.h and valtext.cpp files in the wxWidgets library.
|
For an example implementation, see the valtext.h and valtext.cpp files in the wxWidgets library.
|
||||||
@b How validators interact with dialogs
|
|
||||||
|
@section dialogs How validators interact with dialogs
|
||||||
|
|
||||||
For validators to work correctly, validator functions must be called at the right times during
|
For validators to work correctly, validator functions must be called at the right times during
|
||||||
dialog initialisation and dismissal.
|
dialog initialisation and dismissal.
|
||||||
|
|
||||||
When a wxDialog::Show is called (for a modeless dialog)
|
When a wxDialog::Show is called (for a modeless dialog)
|
||||||
or wxDialog::ShowModal is called (for a modal dialog),
|
or wxDialog::ShowModal is called (for a modal dialog),
|
||||||
the function wxWindow::InitDialog is automatically called.
|
the function wxWindow::InitDialog is automatically called.
|
||||||
@@ -77,7 +90,7 @@
|
|||||||
function for each. Thus, data is transferred from C++ variables to the dialog
|
function for each. Thus, data is transferred from C++ variables to the dialog
|
||||||
just as the dialog is being shown.
|
just as the dialog is being shown.
|
||||||
|
|
||||||
If you are using a window or panel instead of a dialog, you will need to
|
@note If you are using a window or panel instead of a dialog, you will need to
|
||||||
call wxWindow::InitDialog explicitly before showing the
|
call wxWindow::InitDialog explicitly before showing the
|
||||||
window.
|
window.
|
||||||
|
|
||||||
@@ -88,6 +101,7 @@
|
|||||||
call wxWindow::TransferDataFromWindow and
|
call wxWindow::TransferDataFromWindow and
|
||||||
return if this failed. It is then safe to end the dialog by calling EndModal (if modal)
|
return if this failed. It is then safe to end the dialog by calling EndModal (if modal)
|
||||||
or Show (if modeless).
|
or Show (if modeless).
|
||||||
|
|
||||||
In fact, wxDialog contains a default command event handler for the wxID_OK button. It goes like
|
In fact, wxDialog contains a default command event handler for the wxID_OK button. It goes like
|
||||||
this:
|
this:
|
||||||
|
|
||||||
@@ -109,6 +123,7 @@
|
|||||||
|
|
||||||
So if using validators and a normal OK button, you may not even need to write any
|
So if using validators and a normal OK button, you may not even need to write any
|
||||||
code for handling dialog dismissal.
|
code for handling dialog dismissal.
|
||||||
|
|
||||||
If you load your dialog from a resource file, you will need to iterate through the controls
|
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.
|
setting validators, since validators can't be specified in a dialog resource.
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user