home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Datafile PD-CD 5
/
DATAFILE_PDCD5.iso
/
utilities
/
v
/
vista
/
!Manual
/
manual
/
cintro
< prev
next >
Wrap
Text File
|
1996-01-25
|
8KB
|
191 lines
<html>
<title>Class Introduction</title>
<h1>Class Introduction</h1>
Vista contains a set of C++ classes. There 4 main classes.
This section will serve as an introduction to the main classes.
<p>
<a name="task"></a>
<h2>Task</h2>
This class represents the task in which the Vista program is running. It
is the main controlling loop for the program and looks after all the
resources of the program (Windows, messages, etc).
<p>
To create a new basic Task, 3 parameters are required:
<p>
<ol>
<li>The name to give to the task. This is the name that appears in the
Task display.
<li>The application name. This is used to construct the application's
"world". A variable constructed out of this name followed by
$Dir (eg EasyC$Dir) is used as the root directory for the application.
All the resources for the application are found under this root.
<li>The name of the sprite which will appear on the Icon Bar. This
must be in the WIMP's sprite pool.
</ol>
<p>
In addition to these 3 parameters, the Task can be given the name of a
menu to display when the user clicks 'menu' over the Icon Bar icon. See
the section on menus later.
<p>
So, to create a new task, the following line would suffice:
<pre>
Task *my_task = new Task ("My new Task", "MyTask", "mytask") ;
</pre>
There are 3 constructors available for Tasks. Each one manifests itself
differently:
<p>
<ol>
<li><a href="file:task#ct1">Basic task</a> with icon on the icon bar given the icon name
<li>Task <a href="file:task#ct2">without an icon</a> on the icon bar
<li>A task with an icon on the icon bar given an <a href="file:task#ct3">existing Icon</a>.
</ol>
<p>
Each of the constructors also has some default parameters to allow control
over the advanced RISC OS 3 features such as message lists and icon
positioning.
<p>
The task needs resources. These consist of:
<p>
<ol>
<li>A set of templates (filename: Templates)
<li>A set of messages (filename: Messages)
<li>A set of menus (filename: Menus)
</ol>
<p>
All these resources must be held under a directory called Resources in the
task's root dir. The Resources directory itself must contain a file
called Country (of type Text) containing one line. The line is the
name of another directory which contains the actual Templates, Messages
and Menus files. For example, if the country for which the application
is created is Uganda, then the Country file contains one line: Uganda\n
and the directory structure looks like:
<p>
<img src="dirs">
<p>
Other resources are also required, such as !Sprites, !Boot and !Run files.
Information on these can be found in the usual RISC OS manuals.
<p>
<p>
Once a Task has been created, it may be run. This is achieved by use of
the 'run' method of the class. This takes no parameters and does
not usually return:
<pre>
my_task->run() ;
</pre>
It enters a polling loop calling SWI Wimp_Poll until it is told to
shutdown or stop.
<p>
When the task is running, events are distributed to the objects in the
task by calling virtual functions in the objects. Each event causes
a Thread to be created to handle it. The thread terminates when the
event has been dealt with. The fact that each event is dealt with in
a thread means that the task can to anything a thread can do, such as
sleep or perform a long winded calculation without having to split
it up to return to poll the operating system.
<p>
Use of the multithreading will mean the end of the usual delays and
'hourglass' pointer inherent in single threaded tasks.
<p>
For more detail, click <a href="file:task">here</a>
<p>
<a name="thread"></a>
<h2>Thread</h2>
As described above, a Task is a RISC OS task. It appears in the
'Task Display' dialogue box available from the Green Acorn symbol
on the desktop. The operating system takes care of the switching
between the various tasks on calls to SWI Wimp_Poll. Inside a task
it is useful to be able to run more than one part of the
program at once. The Thread class acts like a pre-emptive
process inside a RISC OS task. All the threads in a task
run simultaneously and can communicate with each other. The
threads are preempted by the Vista library so that the CPU
time can be shared among them.
<p>
Each time a task receives an event from the operating system, it
spawns a new Thread to deal with the event. The thread then
executes along side all other threads, each being interrupted
by Vista. This allows the event handling code to behave in any
way it likes, without having to worry about returning to
call Wimp_Poll.
<p>
While threads are running they may sleep waiting for a 'resource'.
Resources are things like timers, flags and even other threads.
Thus a thread can sleep for a period of time or until another
thread has finished.
<p>
Like other classes within Vista, the intention is that the programmer
will derive his own thread classes from those supplied and override
the virtual functions.
<p>
For more detail, click <a href="file:thread">here</a>
<p>
<a name="window"></a>
<h2>Window</h2>
A Window represents a window on the screen. The intention is that the base
class Window is used to derive other classes for the actual windows which
are used in the application.
<p>
A Window may be created as part of a task or as part of another window. If it
is part of a task it can be moved around the screen by dragging. If it is part
of a window it is moved and redrawn when its parent window is moved. It cannot
be moved independently. A window created in this way is called a 'pane' in the
PRM.
<p>
The classes derived from the base class Window should contain local data required
for that window as class members. The class should provide functions for the
virtual functions of the Window class if it wishes to override the default
action of those functions. For example, by default the 'open' method simply
opens the window (and any sub-windows). If you want to do other things as
well as this (or instead I suppose) then you should provide a function with the
same name ('open') and taking the same parameters. This new function will
be called instead of the defaut one when the window needs to be opened.
<p>
For more detail, click <a href="file:window">here</a>
<p>
<a name="icon"></a>
<h2>Icon</h2>
An Icon represents one or more WIMP icons. When you create an Icon, you give it
the icon numbers of the WIMP icons to which it maps. When the user click on
any of these WIMP icons, a function within the Icon is called. Icons may be:
<p>
<ul>
<li>created
<li>deleted
<li>moved
<li>selected
<li>faded
<li>printed to
<li>read from
<li>dragged
</ul>
<p>
In addition, the Icon is informed of user clicks and key presses through calls to
virtual functions. If you derive a new class from the Icon base class you can
provide functions to override the default behaviour of these functions.
<p>
An icon has a 'user reference' which it is given when it is created. This is a
void * type which can point to anything you require. The idea of this is that
you can attach data to an Icon and get access to this data when something happens
to cause the Icon to be activated (clicked for example). To do this, simply
read the member 'user_ref' in the Icon.
<p>
Vista contains a number of higher level Icons which are derived from the Icon
base class. These are referred to as 'tools' and are detailed later in this
document. An example of a tool is a 'Slider' which allows the user to set the
length of a meter bar by clicking on arrows (this is actually provided).
<p>
For more detail, click <a href="file:icon">here</a>
</html>