home *** CD-ROM | disk | FTP | other *** search
- <html>
- <title>Introduction</title>
- <h1>Introduction</h1>
-
- Vista is a C++ class library written specifically for RISC OS (version
- 3.10 or later). It is designed to be easy to use for the beginner and
- powerful enough to satisfy the most experienced programmers. It
- provides a set of base classes from which the user can derive his own
- classes to suit his application. The basic idea is that a Vista class on
- its own will provide a basic operation (such as display a window on
- the screen). If the user wishes to do something else other than
- that provided by the Vista class, he will need to derive a new one,
- inheriting the Vista class, and write his own code to do as he wishes.
- <p>
- Vista is a complete environment in which RISC OS WIMP programs may be
- written. The environment interacts with the Operating System through
- a set of C++ classes. The classes provide an interface to the
- base operating system routines which suits the C++ programming
- paradigm, as well as providing additional functionality not available
- to users of other libraries.
- <p>
- Vista is based around four fairly complex classes:
- <ul>
- <li><a href="file:cintro#task">Task</a>:
- <li><a href="file:cintro#thread">Thread</a>:
- <li><a href="file:cintro#window">Window</a>:
- <li><a href="file:cintro#icon">Icon</a>:
- </ul>
- <p>
- A <a href = "file:cintro#task">Task</a> is the framework in which a program based on Vista runs.
- <p>
- It consists
- of a set of <a href="file:cintro#window">Windows.</a>
- The task keeps track of the Windows it owns.
- <p>
- Each
- Window can contain a number of <a href="file:cintro#icon">Icons.</a>
- An Icon can be something like
- a button which the user can press.
- <p>
- A <a href="file:cintro#thread">Thread</a>is an object that behaves
- like a 'process' within a task. Threads run until they terminate, but
- are scheduled by the library to share the CPU, much like the processes
- in a pre-emptive operating system. They share program and data
- space with all other threads.
- <p>
- An important feature of Vista is the <a href="file:cintro#thread">pre-emptive multithreading.</a> A
- program written for RISC OS running under the WIMP must call the
- OS routine Wimp_Poll continually in order to let other tasks
- run and have events delivered to it. This imposes a structure
- on the code which must have an 'event loop'. While this is
- appropriate for simple event based programs, it can become
- restrictive when imposed on complex programs which are
- not inherently event based.
- <p>
- A program written under Vista does not have this structure imposed
- on it. The program can be written in any fashion, but Vista will
- ensure that the OS is called at the appropriate frequency. This
- allows the program to, say, enter a tight loop during a calculation
- lasting a few minutes. Multithreading is an important programming
- technique which has gained popularity in recent years. It allows
- a program to execute in a pseudo-parallel fashion in a single
- task. It has many powerful features of which the Vista user can
- now make use.
- <p>
- This manual will attempt to guide the newcomer through writing a Vista
- application and will also serve as a reference when the library is
- more familiar.
- <p>
-
- <p>
- <a name="concepts"></a>
- <h2>Concepts</h2>
-
- Those familiar with programming RISC OS under the WIMP will be aware
- of the method in which a program executes. After a brief initialisation
- period, the program places an icon on the iconbar and enters a forever
- loop calling Wimp_Poll and acting on the events returned from it. This
- program structure is fine for purely event driven programs, but can become
- limiting when dealing with other types of program. For example, the
- Easy C/C++ compiler is not event driven, so it must have a timer
- set up to call Wimp_Poll for it at the correct frequency. This is
- a contrived situation which is viewed as an aberration and is
- best avoided.
- <p>
- Vista is different. It provides a simple framework in which your
- program consists of a set of objects, all of which have operations
- invoked on them. An object can be viewed as a piece of 'living data'.
- When writing a program using Vista, there is no need to have an
- event loop as Vista does this for you. Vista receives the events
- from the operating system and invokes the appropriate function
- in an appropriate object.
- <p>
- A normal WIMP program displays a few windows on the screen and allows
- the user to do things with them. Vista also allows the windows
- to contain 'Objects'. An Object is something inside a window that
- needs to be drawn. Examples are sprites, lines, blocks of text, etc.
- Once the program has created the objects, the objects themselves
- are responsible for redrawing so the application doesn't need to
- care about them.
- <p>
-
- <a name="use"></a>
- <h2>How to use Vista</h2>
-
- To go about writing a program using Vista you first need to decide on
- what windows will be in your program. Once you decide on the type
- of windows that will appear, you need to define a class derived
- from the class Window for each type.
- Generally speaking, there will be one source file and one header file
- for each major class in the program.
- <p>
- After deciding on the windows, you need to decide what the windows are
- going to do. A window will receive input from the user by actions
- such as mouse clicks, menu selections, dragging etc. Each window
- type needs to define functions for each form of input it is
- willing to accept. For example, if you are going to deal with
- mouse clicks, define a function called 'click' conforming to the
- function of the same name in the Window class:
- <pre>
-
- void click(int mx, int my, int buttons, int icon) ;
-
- </pre>
- In C++, by defining a function in a derived class with the same
- "signature" as a virtual function in a base class, you are
- overriding the base class function. This means that your
- click function will receive all mouse click events instead of
- that in the Window class. Note that you must copy the signature
- of the virtual function exactly (except for the names of the
- parameters of course). This means it must have the same
- return type, same name and same parameter types.
- <p>
- Next, you can decide on the shape of your windows including the
- Icons you want in it. For an icon to be use as output, you
- need to make it into an instance of the Vista class 'Icon'.
- If your icon is just used for input, you don't need to make
- it into an 'Icon' instance, just deal with it in the
- window 'click' function instead. If an icon is an 'Icon'
- instance it will always receive input in preference to the
- window's input functions.
- <p>
- Another important aspect of a Vista program is the functionality
- of the Task class. You will need to derive a new class from
- the 'Task' Vista class and provide some action functions as
- you do for windows. Tasks generally act on icon bar clicks
- and menu selections. They can receive messages from other
- tasks through 'Channels' they have defined.
- <p>
- It is also important to keep in mind that Vista is a multi-threaded
- library. This is implemented by use of low level OS feature
- known as 'Callbacks'. A callback is activated on a timer which
- must only be running when the OS has switched the task as being the
- 'current task'. Vista ensures this by switching off the
- timer just before calling Wimp_Poll, and back on again when
- the task regains control. Therefore, you <b>must not</b>
- call any OS routine that switched control to another
- task directly. The only 2 routines that do this are Wimp_Poll
- and Wimp_StartTask. Vista supplies a 'spawn' function as
- veneer around Wimp_StartTask, and handles all Wimp_Poll
- calls itself. You should never call these routines yourself.
- <p>
- Another feature of the multi-threading is that the task is never
- 'busy'. This means you should never have the need to use
- the 'hourglass' as you can receive events at all times. This
- might have some design implications on strictly single-threaded
- designs (which are rare in C++).
- <p>
- Vista is supplied with a few powerful 'tools' which are really
- composite icons. Examples of these are the Adjuster, Slider and
- Popup tools. These are as specified in the RISC OS Style Guide
- and behave as expected. Because they are derived from the
- Icon class, they are accessed just like a normal icon and
- are very easy to use. For example, to set a Meter to a certain
- value, use the call:
- <pre>
-
- meter->write (value) ;
-
- </pre>
- And to read the value of an adjuster, use:
- <pre>
-
- adjuster->read (value) ;
-
- </pre>
- Vista is also supplied with a set of useful windows which are derived
- from the Window class. These are things like a DialogueBox class
- or an IconGrid (a window which behaves like a Filer directory viewer).
- These derived windows can be used in your programs.
- <p>
- Another supplied feature is a set of 'Objects'. These are things within
- a Window like a piece of text or a sprite or drawfile. These, in themselves,
- may not be exactly as required by your applications, but you can derive
- new objects from them to supply the required functionality.
- <p>
- Finally, Vista is supplied with a few example programs which you are
- encouraged to look at, understand and copy. More examples may
- come in the future, but it is hoped that the set supplied are
- sufficient to give you a taste of the power of the library.
- <p>
-
- <a name="idents"></a>
- <h2>Defined Identifiers</h2>
- Like any program, Vista has a set of identifiers that it uses. You cannot
- use these identifiers in your programs if you include the Vista
- headers. The identifiers used by Vista are used for class names and are:
- <ul>
- <li>Channel
- <li>DataSave
- <li>DeferredDelete
- <li>Icon
- <li>IconSet
- <li>Menu
- <li>MenuItem
- <li>MsgTrans
- <li>Object
- <li>IconObject
- <li>RawSpriteObject
- <li>TextObject
- <li>LineObject
- <li>FontObject
- <li>DrawObject
- <li>SpriteObject
- <li>Task
- <li>ControlThread
- <li>DebugWin
- <li>sprite_area
- <li>TaskError
- <li>TemplateEntry
- <li>Template
- <li>Thread
- <li>ThreadResource
- <li>ThreadTimer
- <li>ThreadPipe
- <li>ThreadSemaphore
- <li>MainThread
- <li>ResourceThread
- <li>ThreadManager
- <li>Adjuster
- <li>Meter
- <li>Slider
- <li>Popup
- <li>MouseTracker
- <li>Window
- <li>IconGrid
- <li>DialogueBox
- <li>Attribute
- <li>StringAtribute
- <li>IntegerAttribute
- <li>BoolAttribute
- <li>SetAttribute
- <li>CancelButton
- <li>OKButton
- <li>SaveBox
- <li>SaverFile
- <li>ProgramInfo
- </ul>
- In addition, there are two functions with signatures 'dprintf (char*...)'
- and 'print (char*...)' defined. All other functions are class member
- functions and so are coded with the class name.
- </html>
-