home *** CD-ROM | disk | FTP | other *** search
-
- Some ideas behind Dreamscape
- ==============================
- (This page needs updating)
-
- Contents
- --------
- * RISC OS vs the world
- * Inheritance vs object aggregation
- * The Command class
- * Auto-created objects
- * Shared objects
- * Problems with object aggregation
-
-
- RISC OS vs the world
- --------------------
- The RISC OS GUI is very different to other GUIs. Other GUIs usually have a
- few of the following limitations:
-
- * Pull-down menus at the top of the screen or at the top of windows
- * The concept of the 'active window', which is at the front and has the
- input focus
- * An application is a window, and documents are windows within this
- window
- * Modal dialogue boxes - these lock out the rest of the screen
-
- But in RISC OS, tasks don't have to put an icon on the icon bar, and the
- windows they open don't have to be documents. Menus are not pull down, they
- are pop up.
-
- Since the RISC OS GUI does not have as many limitations, the hierarchy of
- classes is a lot less strict. See the V Reference Manual and the V View of
- the World for an example of another class library - V is a Freeware class
- library for GUIs such as Windows.
-
-
- Inheritance vs object aggregation
- ---------------------------------
- If you wanted to create a class for viewing a picture in a window, there are
- two ways you could do it. The first is using inheritance, where a
- PictureView class is-a Window. For example:
-
- class PictureView: public Window {
- Picture *picture;
- public:
- PictureView(Picture *picture);
- ~PictureView();
- };
-
- Instead, you could object aggregation, where PictureView has-a Window:
-
- class PictureView {
- Picture *picture;
- Window window;
- public:
- PictureView(Picture *picture);
- ~PictureView();
- };
-
- Object aggregation is a lot more versatile, and inheritance tends to be
- over-used. With inheritance, you can have problems inheriting a base class
- with virtual functions twice.
-
- In the second PictureView example, instead of containing a Window object,
- PictureView could contain a pointer to a Window. This would allow you to
- change the window that PictureView uses without having to delete and
- re-create PictureView.
-
- In fact, the Toolbox makes use of object aggregation. For example, a SaveAs
- object isn't itself a Window object - you can't manipulate its gadgets
- directly. Instead, the SaveAs object contains a Window object, which can be
- read using a SaveAs method.
-
-
- The Command class
- -----------------
- The Command class is used extensively in event handling in Dreamscape. It is
- very simple and looks like this:
-
- class Command {
- virtual void execute() = 0;
- };
-
- Other classes can then be derived from this that do specific things. For
- example, the class ShowWindowCommand can have a Window object attached to it
- and when execute() is called, it shows the window on the screen.
-
- You can write a class derived from Command that performs an action, and
- attach it to a menu entry. Later you might decide to change the user
- interface, so you could just attach it to a toolbar button instead. That's
- the advantage of the Command approach - it's very generalised.
-
-
- Auto-created objects
- --------------------
- One thing about the Toolbox is that you can attach objects to other objects
- in the resource file, and when the second object is created when the program
- is run, the first object is automatically created as well.
-
- Dreamscape supports these auto-created objects. For example, toolbars can be
- attached to window objects. When the method get_etl_toolbar() for the Window
- class is called, it returns a pointer to a Window class. The C++ Window
- object is created if it hadn't been previously created - Toolbox object
- client handles are used for this. The C++ Window object will later be deleted
- when the Toolbox auto-deleted event is received.
-
- Gadgets and menu entries are created in a similar way. A C++ Gadget or
- MenuEntry object is created when the Window or Menu method get_gadget() or
- get_entry() is called respectively.
-
- Objects that have their auto-create flag set are auto-created by the Toolbox
- when the program is started, although the program won't be able to access
- these objects - it's best for the program to explicitly create them itself.
-
- Since auto-create objects don't exist in Wimp templates, some of this would
- not work in a future Wimp version of Dreamscape. For example, toolbars would
- have to be created and attached explicitly - programs that do this would work
- under the Toolbox version as well.
-
-
- Shared objects
- --------------
- There is no explicit support for shared objects in Dreamscape. In some cases
- shared objects will be useful, in others, they will produce slightly strange
- behaivour.
-
- For example, if you created two C++ Window objects from one resource file
- template that is set as shared, the client handle for the shared object
- created will only point to one of the C++ Window objects. So any events
- occuring on this window will only be delivered to one C++ window.
-
- On the other hand, shared objects are useful when they are used as attached
- objects that are created automatically when their parent object is created. A
- document window could have a shared menu attached to it, so as long as menu
- details are set when the menu is shown (as opposed to as soon as changes are
- made), things will work out okay. This is also slightly more efficient than
- making a menu a static member of a class, as the menu is only created when
- their is one of its parent windows in existance.
-
-
- Problems with object aggregation
- --------------------------------
- There are problems with object aggregation. For example, if a SaveAs class
- used object aggregation it would contain a Window object, instead of being
- derived from Window:
-
- class SaveAs {
- Window window;
- ...
- };
-
- But what happens when you want to attach your Save as window to a menu tree?
- The prototype for the function in the MenuEntry class to attach windows to
- menu entries could be:
-
- void set_leaf(Window *window);
-
- But that only lets you attach Window objects, or objects derived from Window.
- We don't want to derive SaveAs from Window, though, because we don't want,
- for example, the gadgets in the Window class to be accessible. And anyway,
- under the Toolbox a SaveAs object has-a Window, not is-a Window.
-
- The solution is for both Window and SaveAs to inherit from a common base
- class, BaseWindow, although only Window would provide, for example, gadget
- handling. The prototype for the function in MenuEntry becomes:
-
- void set_leaf(BaseWindow *window);
-
-
- Mark Seaborn
- mailto:mseaborn@argonet.co.uk
- http://www.argonet.co.uk/users/mseaborn/
-