home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Datafile PD-CD 5
/
DATAFILE_PDCD5.iso
/
utilities
/
v
/
vista
/
!Manual
/
manual
/
wins
< prev
Wrap
Text File
|
1996-01-09
|
17KB
|
483 lines
<html>
<title>Derived Windows</title>
<h1>Derived Windows</h1>
The Window class provides facilities for the manipulation of basic windows. In
order to provide more functional windows, it is necessary to define new
classes based on the Window class. The Window class has a set of virtual
member functions which may be replaced by a derived class in order to
enhance the functionality.
<p>
Vista includes a set of useful functional windows which may be used
by the program. Again, if the functionality of the windows defined i
not sufficient, it is a simple matter of deriving a new class from
them.
<p>
The derived windows supplied with Vista are:
<p>
<ul>
<li><a href="file:wins#dbox">DialogueBox:</a> - An input/output device
<li><a href="file:wins#grid">IconGrid:</a> - A window like a Filer
<li><a href="file:wins#save">SaveBox:</a> - The standard Save box
<li><a href="file:wins#prog">ProgramInfo:</a> - The standard Program Info box
</ul>
<p>
<hr>
<p>
<a name="dbox"></a>
<h2>DialogueBox</h2>
The DialogueBox class implements a generic data input/output mechanism.
It consists of a window which contains a set of <a href="file:wins#attr">attributes.</a>
An attribute
is a piece of data that may be modified by the user. It appears as
an icon in the window.
<p>
The Dialogue Box class is defined as:
<hr>
<pre>
class DialogueBox : public Window, public Thread
{
public:
DialogueBox (Task *t, char *tname, int cancel = -1, int ok = -1, char *menu = 0) ;
virtual ~DialogueBox() ;
void click (int mx, int my, int buttons, int icon) ;
void key(int icon, int x, int y, int height, int index, int code) ;
virtual void show() ;
virtual void hide() ;
void run() ;
void close() ;
Icon *find_icon (int icon) { return NULL ; }
virtual void cancel(int button) ;
virtual void ok(int button) ;
void add_attribute (Attribute *attr) ;
void create_attribute (int iconnum, char *str) ;
void create_attribute (int iconnum, int &num) ;
void create_attribute (int iconnum, bool &value) ;
void create_attribute (int num_values, bool *values, ...) ;
void create_attribute (Icon *icon, char *str) ;
void create_attribute (Icon *icon, int &num) ;
void create_attribute (Icon *icon, bool &num) ;
void next_attribute (int icon) ;
void prev_attribute (int icon) ;
protected:
Attribute *attributes ;
Attribute *last_attribute ;
Icon *cancel_icon ;
Icon *ok_icon ;
ThreadSemaphore *waiting ;
int from_menu ;
public:
int cancelled ;
} ;
</pre>
<hr>
<p>
It is derived from both the Window and Thread classes. This means that it
behaves like both classes. It appears as a window on the screen, but also
runs as a thread.
<p>
The normal operation for a dialogue box is for the user to display it on the
screen, fill in some of the fields and click on either the OK or Cancel button.
If the OK button is clicked, the attributes are committed, otherwise the values
entered by the user are discarded. It is normally necessary for the program
to wait for the user to enter the data before it can continue.
<p>
The DialogueBox is created by use of the constructor. This is supplied with the
following parameters:
<p>
<ol>
<li>The task
<li>The name of the window template
<li>The icon number for the 'Cancel' icon (-1 = none)
<li>The icon number for the 'OK' icon (-1 = none)
<li>The name of a menu (0 = none)
</ol>
<p>
The dialogue box does not appear on the screen. To do this, the 'show()'
function must be called. This causes the window to appear on the screen
and the thread started. The thread terminates when the user has closed the
dialogue box by clicking on OK or Cancel (or by otherwise causing the
window to close). Usually the function which opened the dialogue box will
be waiting the the user to fill it in.
<p>
<a name="attr"></a>
<h3>Attributes</h3>
When defining a dialogue box, a new class should be derived from the
DialogueBox base class. This new class should contain all the attributes
to be filled in by the user. An attribute consists of 2 parts:
<p>
<ol>
<li>A piece of data which will contain the value of the attribute
<li>A user interface allowing the user to modify the value.
</ol>
<p>
In order to tie these 2 parts together, you need to tell the DialogueBox
class what they are. The functions 'create_attribute' allow the dialogue
box to be told of all the attributes it contains.
<p>
For example, consider the following dialogue box:
<pre>
class PersonDetails : public DialogueBox
{
public:
PersonDetails(Task *t) : DialogueBox (t, "details", 1, 2)
{
strcpy (name, "") ;
age = 21 ;
create_attribute (3, name) ;
create_attribute (4, age) ;
}
~PersonDetails() {}
// attributes
char name[32] ;
int age ;
} ;
</pre>
This dialogue box is created from a template called "details" and
has an OK and a Cancel button. The OK button has icon number 2 and the
Cancel button is icon 1.
<p>
There are 2 attributes:
<p>
<ol>
<li><b>name</b> - a string (icon number 3)
<li><b>age</b> - an integral number (icon number 4)
</ol>
<p>
The constructor initialises the values for the attributes and tells the
DialogueBox class the icon number and data address of each. The icons
representing the attributes should be writeable icons so that the user
may fill them in.
<p>
When the user clicks on the OK button, the values he has types in to the
icons are copied into the attributes value. If he clicks on Cancel, the
values types in are ignored. Also, clicking on Cancel sets a variable
called 'cancelled' inside the DialogueBox and this can be interrogated
by the caller.
<p>
Attributes may also be created manually by creating an object of a type
derived from the type 'Attribute'. This is an abstract class which has
a number of specific attribute types derived from it. The attribute
types are:
<p>
<ol>
<li><b>StringAttribute</b> - the value is a string
<li><b>BoolAttribute</b> - the value is a boolean
<li><b>IntegerAttribute</b> - the value is an integer
<li><b>SetAttribute</b> - the value is a set of boolean values (array of words)
</ol>
<p>
Once the attribute has been created it is automatically added to the dialogue box
and deleted when the dialogue box is deleted.
<p>
<h3>Displaying a Dialogue Box</h3>
In order to cause a dialogue box to appear on the screen, the function
'show()' is called. This opens the window and starts the thread running.
The function that called 'show()' may then wait for the user to fill in
and close the dialogue box by use of the 'sleep()' function.
<p>
For example, if we wanted to open the PersonDetails dialogue box and
wait for the user to fill in the name and age, we would write the following
code:
<pre>
void fill_in_details(Task *task)
{
PersonDetails details (task) ; // create the DialogueBox
details.show() ; // show it on the screen
task->sleep (&details) ; // sleep until it is closed
if (!details.cancelled) // check if input was cancelled
{
// use the attribute values from details.
}
}
</pre>
The destructor for the PersonDetails dialogue box will be called
at the end of the function when the variable 'details' goes out
of scope.
<p>
If the dialogue box is attached to a menu selection it will behave
differently. When Vista informs the task or window that the
appropriate menu selection has been made, the menu handler function
simply opens the DialogueBox. If the user then moves the mouse
back over the menu, or clicks outside the dialogue box, it will
be closed.
<p>
The code for opening a dialogue box off a menu selection would be:
<pre>
void MyWin::menu (MenuItem items[])
{
switch (items[0])
{
case DETAILS:
{
PersonDetails details (task) ;
details.show() ;
task->sleep (&details) ;
if (!details.cancelled)
{
}