In a typical GUI application you will want to do the following:
-
Initialize the values in a dialog box.
-
Post the dialog box to allow the user to make changes.
-
Collect the changes from the dialog box.
In addition, you may want the dialog box to update its state if some
application state is updated while the dialog box is posted. Data targets are
designed to make these tasks easier for the GUI programmer.
A data target acts as a bidirectional intermediary between some application
state and GUI widgets. More than one widget can be connected to a data target,
but a data target acts on only one piece of application state. When the user
uses the GUI to change a value, the application state monitored by the data
target is updated automatically. Conversely, when the application state is
updated, the widget connected to the data target is updated automatically.
As described in
Automatic GUI updating,
widgets can be in a push state or a pull state.
- Push state
-
In a push state the widgets are collecting and sending user input to the
application.
Figure 1
illustrates how a data target works with a widget that is in a push state. The
sequence is as follows:
-
First, the user enters a value of 7 in
the text field and then presses Enter.
-
This triggers the text field widget to send an (ID,
SEL_COMMAND) message to its target—the data target.
-
The data target responds by sending the sender—the text field widget—a
message requesting the value in the text field. The data target uses that value
to update the value of its data.
Figure 1. A data target with a text field widget in push state.
- Pull
state
-
In a pull state the widgets are interrogating the application to keep
up-to-date.
Figure 2
illustrates how a data target works with a widget that is in a pull state. The
sequence is as follows:
-
When the GUI is idle, it initiates a GUI update.
-
The GUI update triggers each widget to send an (ID,
SEL_UPDATE) message to its target.
-
In this case the data target responds by sending the sender—the text
field widget—a message telling it to set its value to the value of the data
target’s data.
Figure 2. A data target with a text field widget in a pull state.