This Text was written for the Oberon System V1, so it is very old. Please read
and
to see what has changed. The Chapter "User's Guide" is replaced by
The Oberon Guide
System Release 1.2
rg Gutknecht
Abstract
This guide provides a concise and detailed description of the Oberon system on three different levels: the user's level, the level of programmers of tools, and the level of implementors of new viewer classes. In particular, the guide features a complete documentation of standard commands, a commented series of important interface definitions, and a tutorial collection of Oberon programs exemplifying the typical Oberon programming style.
Table of Contents
Abstract
Introduction
History
Design Principles
Acknowledgement
User's Guide (skiped, see
Commands and Tools
The Edit Tool Package
The System Tool Package
The Compiler Tool Package
The Miscellaneous Tool Package
The Backup Tool Package
Guide for Programmers of Commands
Oberon's module hierarchy
The Display System
The Text System
The Oberon Core
Tutorial Examples
Write time stamp to system log
Process selected text
Open viewer in system track, generate, and display text data
Open viewer in user track and display existing text
Grow text viewer
Process viewer text or sequence of texts, depending on context
Delete selected part of text in marked viewer
Copy most recently selected text part to caret's position
Copy font from visibly marked position to text selection
Move caret to next character written in italics
Guide for Programmers of Frame Classes and Viewer Types
Frames as Active Objects
Standard Menu Viewers
The Canonical Decomposition of an Application
Tutorial Examples 1: Frame oriented operations
Display text line within text frame
Track caret
Tutorial Examples 2: Text oriented operations
Save text in buffer
Insert contents of buffer in text
Literature
Ceres Workstation
Oberon Language
Oberon System
Introduction
History
Oberon is simultaneously the name of a project and of its outcome. The project was started by Niklaus Wirth and the author late in 1985 with the goal of developing a modern and portable operating system for personal workstations. Its results are an implementation of the system for the Ceres computer and a programming language (see section Literature).
The development of the language Oberon needs perhaps a short justification. It became quite inevitable because the type-system of available languages turned out to be too restrictive to express the desired data model in a natural and safe way. We refer to report for a definition of the new language, and to the third and fourth chapter of this text for some examples of its application.
Design Principles
For the present, we focus on the system Oberon, beginning with a brief overview of its design principles. The underlying dynamic model is extremely simple. There exists a single process acting as a common carrier of multiple tasks. This process repetitively interprets commands, which are the official entities of execution in Oberon. Commands are atomic actions operating on the global state of the system. Unlike customary interactive programs, they rigorously avoid direct dialogs with the system user.
The following typical examples indicate the bandwidth covered by the concept of command: Placing the caret, inserting a character into a text, selecting a piece of text, deleting a selected piece of text, applying a new font to a piece of text, searching a pattern in a text, compiling a software module, opening a viewer, backing up a sequence of files to diskette, and displaying a directory. We emphasize that the execution of a command always results in non-volatile information. For example, in the last example, this means that the displayed directory is a text that might immediately undergo further processing. Typically, commands report the outcome of their execution in the form of an entry in the system-log. Therefore, the log provides a complete protocol of the current session.
Commands are initiated by input actions. Apart from a few universal operations, every input action is connected with a displayed viewer, to which its further handling is delegated. A viewer in Oberon is a rectangular area on the screen that can display any kind of data. Most viewers feature a thin frame and a title-bar containing a menu. Any mouse-oriented input is handled by the viewer the mouse points to. Data from the keyboard is immediately passed over to the current so-called focus-viewer. We notice that command interpretation is a highly decentralized activity in Oberon and, as such, is a substantial contribution to what we consider as Oberon's most important quality, namely unlimited extensibility.
Implementing a new viewer type is a very powerful but also quite far-reaching method to extend the Oberon system. It is only appropriate in conjunction with the installation of a new class of displayable objects (for example graphics or tables). The fourth chapter will provide more insight into this topic.
A more moderate way to increase the system's functionality consists in adding new commands operating on objects of an already existing class (for example a language compiler operating on text). We shall see in the third chapter that Oberon's open and coherent modular architecture provides effective support for that. Practically all system ingredients and resources are directly accessible and usable via modular interfaces on as high a level of abstraction as possible.
We should deduce from the foregoing that there is no symbolic wall in Oberon separating actual users from developers. Users are encouraged to customize the system and tailor it to their individual needs by designing and implementing private commands and facilities. Little is "hardwired" in the system. However, there are several general conventions and existing tools. They are presented in the next chapter.
Acknowledgement
I gratefully acknowledge Niklaus Wirth's initiative and willingness for travelling through the adventures of designing and building a new workstation, a new language, and a new operating system, escpecially under the given severe restrictions of personal resources. Without his competence and extraordinary commitment this mammoth-project could not have been successfully completed. I am also very grateful for the possibility to include an extract of Niklaus Wirth's Draw guide in the first chapter. My thanks further go to the Oberon user's community, in particular to Martin Reiser, Hans-Peter M
ssenb
ck, and Beverly Sanders for their constructive critisism and valuable suggestions for improvements.
User's Guide
This chapter is skiped because
contents the same text but updated for System V4.
Guide for Programmers of Commands
In Oberon's modular hierarchy we recognize the following structural entities: The inner core, the outer core, the text system, the graphic system, the picture system, and a collection of tools.
Oberon's module hierarchy
Tool Packages Net Backup Compiler System Miscellaneous ColorSystem
Edit Draw Paint
Text System Graphic System Picture System
TextFrames GraphicFrames PictureFrames
Graphics Pictures
MenuViewers
Outer Core
Inner Core Printer Oberon
Texts
Modules Fonts
Files
FileDir Math MathL Reals Viewers
Drivers Kernel V24 SCC Diskette Input Display
The responsability of the inner core comprises memory management, file management, and program loading. The outer core additionally provides device drivers for network ports, keyboard, mouse, and display screens. Other parts of the outer core are viewer manager, elementary text management, and support for (remote) printing. Module Oberon represents the main interface between the outer core and its clients. It includes sections that are devoted to the current system configuration, to default strategies for track allocation and viewer placement, and to the support of command execution.
Module Display stands at the bottom of the display system hierarchy. The display area is considered as a plane with x and y coordinates. It includes both a black-and-white area and a color area. Raster operations are used to generate and copy rectangular areas on the display plane. Sections of the plane can be made visible by display control procedures. The visible parts of the display plane are structured as tracks and viewers, and they are managed by the viewer manager Viewers. Module Oberon defines a standard layout featuring one user track and one system track per display screen. Finally, module MenuViewers is a high-level viewer manager for standard viewers consisting of a title bar and a rectangular main area surrounded by a thin frame. Both title bar and main area are so-called frames. While the title bar is almost always a text frame (see next paragraph), the type of the main frame depends on the kind of viewer.
The text system, the graphic system, and the picture system are identical in structure. Each consists of a triple of linearly dependent modules. In the case of texts they are called Texts, TextFrames, and Edit. Texts defines the object type Text and exports intrinsic operations on texts. TextFrames defines the object type TextFrames.Frame and handles representations of texts within sub-frames of viewers. Edit provides additional (non-built-in) text-editing operations.
Modules at the top (like Edit) are tool packages. Typically, a tool package merely exports a collection of commands in the form of parameterless procedures. Tool modules make intensive use of facilities provided by lower level modules, in particular by the viewer system, the text system, and the central system module Oberon. It is essential that usual commands strictly operate on texts or graphics instead of accessing keyboard or screen directly.
We understand this chapter as a tutorial on implementing tool packages. First, we give a commented overview of the definitions of the most important lower-level modules. Then, we shall exemplify their usage by some typical excerpts from existing tools.
(*replicate pattern p in color col into block X, Y, W, H using operation mode,
proceeding from left to right and from bottom to top, starting at lower left corner*)
PROCEDURE ReplConst (col: INTEGER; X, Y, W, H, mode: INTEGER);
(*place "ones" in color col into block X, Y, W, H using operation mode*)
END Display.
Remarks:
1. The Ceres computer features a monochrome display whose position (lower left corner) is specified by the variables Left and Bottom, and whose width and height are given by the variables Width and Height. In fact, the drawing area is bigger; its y-coordinate ranges from -1248 to 799. Two sections can be made visible by the display control procedures, the first being characterized by {y| -1024 <= y < -224}, and the other by {y| 0 <= y < 800}.
2. If a color display is installed, the module's raster procedures can be used to generate and copy areas on the color screen. The position of the color area (lower left corner) is specified by the variables ColLeft and Bottom; its width and height are the same as for the monochrome display.
3. The postulated preconditions upon procedure parameters are not checked by the module; this is left to the calling modules which are held responsible for robustness.
dY, Y, H: INTEGER (*translation vector dY; new Y and H*)
END;
VAR Ancestor: Viewer; (*current menu viewer*)
PROCEDURE Handle (V: Display.Frame; VAR M: Display.FrameMsg);
(*standard handler for menu viewers*)
PROCEDURE New (Menu, Main: Display.Frame; menuH, X, Y: INTEGER): Viewer;
(*create and open at X, Y new menu viewer containing frames Menu and Main*)
END MenuViewers.
Remark:
Messages to menu viewers not affexting size and position are passed on to their subframes. The ancestor viewer is made available to the subframe handlers via the variable Ancestor. MenuViewers also creates new messages of type ModifyMsg requesting subframes to change size or vertical position (or both). dY represents a vertical translation vector, and Y and H specify the new position and height respectively.
(*write long real number x to W's buffer in hexadecimal form*)
PROCEDURE CopyElem (SE, DE: Elem);
(*copy all fields defined in the base type Elem*)
PROCEDURE ElemBase (E: Elem): Text;
(*text containing element*)
PROCEDURE ReadElem (VAR R: Reader);
(*read the next element at or after the current reader position*)
PROCEDURE ReadPrevElem (VAR R: Reader);
(*read the element before the reader position*)
PROCEDURE WriteElem (VAR W: Writer; e: Elem);
(*write element into writer buffer*)
END Texts.
Remark:
Open does not create a text object nor does it install a notifier procedure. Both actions are left to the calling modules. Typically, a calling module first creates a text object (or an extension of it) by using NEW, and then installs a notifier procedure. The main purpose of notifier procedures is requesting the display to re-establish consistency after a change in a text has occurred.
PROCEDURE Call (VAR name: ARRAY OF CHAR; par: ParList; new: BOOLEAN; VAR res: INTEGER);
(*call command name and pass parameter list par. Option new requests loading of module.
Done = (res = 0)*)
PROCEDURE GetSelection (VAR text: Texts.Text; VAR beg, end, time: LONGINT);
(*get most recent text selection. Text selection exists = (time >= 0)*)
PROCEDURE Install (T: Task);
(*install new task T*)
PROCEDURE Remove (T: Task);
(*remove installed task T*)
PROCEDURE Collect;
(*demand garbage collector*)
PROCEDURE SetFont* (fnt: Fonts.Font);
(*set current font*)
PROCEDURE SetColor* (col: SHORTINT);
(*set current color*)
PROCEDURE SetOffset* (voff: SHORTINT);
(*set current vertical offset*)
END Oberon.
Remark:
Installed tasks are considered to be background activities. They are activated by the central loop when no input events have been detected. For example, the garbage collector is implemented as an installed task. Notice that installed tasks may be invalidated after their host module has been unloaded (or replaced). Unsafe tasks are automatically removed after a system trap in order to avoid an infinite repetition of the same error.
is globally defined initialized by Texts.OpenWriter(W).
Remarks:
1. Normally, one (global) writer per module is sufficient.
2. If you desire a specific part of the output text to appear in a new font, for example in italics variant Syntax10i.Scn.Fnt, call Texts.SetFont(W,Fonts.This("Syntax10i.Scn.Fnt")) before writing this part and Texts.SetFont(W,Fonts.Default) before continuing to write ordinary text.
Texts.Write(W, " "); Texts.WriteDate(W, time, date);
Texts.WriteLn(W)
END Lister;
Remarks:
1. The above program generates its whole output text before displaying it. Alternatively, if you move the statement Texts.Append(T, W.buf) into the Lister-procedure, every generated directory entry is displayed immediately.
2. Oberon.AllocateSystemViewer(Oberon.Par.vwr.X, X, Y) is a standard proposal for the placing of a new system viewer within the track from which the command was called. Of course, individual algorithms are possible as well. For example, if the new viewer is desired to cover the bottom most viewer, except if the pointer overrides this, the algorithm is
PROCEDURE AllocateSystemViewer (DX: INTEGER; VAR X, Y: INTEGER);
VAR bot: Viewers.Viewer;
BEGIN
IF Oberon.Pointer.on THEN X := Oberon.Pointer.X; Y := Oberon.Pointer.Y
ELSE bot := Viewers.This(Oberon.SystemTrack(DX), 0); X := bot.X; Y := bot.H - Viewers.minH
END
END AllocateSystemViewer;
3. TextFrames.NewText generates a standard text frame. The following statement sequence produce a text frame with an individual handler and a customized geometry.
Open a viewer in user track and display existing text
PROCEDURE OpenText;
VAR par: Oberon.ParList; Text: TextFrames.Frame; S: Texts.Scanner;
V: Viewers.Viewer; X, Y: INTEGER;
BEGIN
par := Oberon.Par; (*access parameters*)
Text := par.frame(TextFrames.Frame); (*calling frame*)
TextFrames.Mark(Text, -1); (*arrow mark*)
Texts.OpenScanner(S, par.text, par.pos); (*open scanner at position of parameter list*)
Texts.Scan(S); (*get symbol*)
IF S.class = Texts.Name THEN
Oberon.AllocateUserViewer(par.vwr.X, X, Y);
V := MenuViewers.New(
TextFrames.NewMenu(S.s, StandardMenu);
TextFrames.NewText(TextFrames.Text(S.s), 0);
TextFrames.menuH, X, Y);
END;
TextFrames.Mark(Text, 1) (*restore position mark*)
END OpenText;
Remark:
Oberon.AllocateUserViewer(par.vwr.X, X, Y) is a standard proposal for the placing of a new viewer in the caller's user track. Again, individual algorithms are possible as well.
Grow viewer
PROCEDURE Grow;
VAR V, newV: Viewers.Viewer; M: Oberon.CopyMsg; N: Viewers.ViewerMsg; DH: INTEGER;
BEGIN
V := Oberon.Par.vwr; (*get originator viewer*)
DH := Oberon.DisplayHeight(V.X); (*get height of this track*)
IF V.H < Oberon.DisplayHeight(V.X) THEN (*if viewer is small*)
V.handle(V, M); newV := M.F(Viewers.Viewer); (*get a copy of the viewer*)
Viewers.Open(newV, V.X, DH); (*open new big viewer*)
N.id := Viewers.restore; newV.handle(newV, N) (*ask new viewer to draw itself*)
END
END Grow;
Remark:
The Grow command is generic in the sense that it can handle viewer instances of any (current or future) class. Typically (and unavoidably) generic commands use message passing instead of ordinary procedure calls. This object-oriented style will be explained in more detail in the next chapter. Also notice that actually a copy of the original viewer is opened in the new track. When this track is being closed later, the original viewer will reappear.
Process viewer text or sequence of texts, depending on context
PROCEDURE ProcessText;
VAR par: Oberon.ParList; Main: TextFrames.Frame; S: Texts.Scanner; T: Texts.Text;
BEGIN
par := Oberon.Par; (*access parameters*)
IF par.frame = par.vwr.dsc THEN (*command in menu frame*)
IF par.vwr.dsc.next IS TextFrames.Frame THEN
Main := par.vwr.dsc.next(TextFrames.Frame); (*main text frame*)
TextFrames.Mark(Main, -1) (*set arrow mark*)
Process(Main.text); (*process displayed text*)
TextFrames.Mark(Main, 1) (*restore position mark*)
END
ELSE (*command in main text frame*)
Main := par.frame(TextFrames.Frame);
TextFrames.Mark(Main, -1) (*set arrow mark*)
Texts.OpenScanner(S, par.text, par.pos); (*open scanner at position of parameter list*)
Texts.Scan(S); (*get first symbol*)
WHILE S.class = Texts.Name DO
Texts.Open(T, S.s); (*open text from file*)
Process(T); (*process this text*)
Texts.Scan(S) (*get next symbol*)
END;
TextFrames.Mark(Main, 1) (*restore position mark*)
END
END ProcessText;
Delete selected part of text in marked viewer
PROCEDURE Delete;
VAR Main: TextFrames.Frame; V: Viewers.Viewer;
BEGIN
V := Oberon.MarkedViewer(); (*get marked viewer*)
Main := V.dsc.next(TextFrames.Frame); (*main text frame of marked viewer*)
IF Main.sel > 0 THEN (*if there exists a selection*)
TextFrames.Show(Main, Max(0, pos - 200)); (*show text at pos*)
TextFrames.SetCaret(Main, pos) (*set caret to new position*)
END
END
END
END SearchItalics;
where Max is the maximum-function.
Guide for Programmers of new Frame Classes and Viewer Types
Frames as Active Objects
Frames are the basic entities of Oberon's display system. They are more-or-less autonomous rectangular areas on the display screen and may be nested. In particular, the display screen is hierarchically organized like this: Display > tracks > viewers > data frames. Display, tracks, and viewers are entities to be managed by the viewer handler module Viewers. Because of Oberon's tiling approach, all of these frames are totally visible or totally invisible, i.e. there is no partial overlapping on this level. There exists a class of standard viewers called menu-viewers (and handled by module MenuViewers). Every menu-viewer contains exactly two vertically adjacent data frames: A header frame (including title and menu) and a main data frame. The main frame of a menu-viewer can be regarded as a virtual display terminal representing the user interface to a certain application or task. It may itself be nested, i.e. contain further subframes. Because an individual command interpreter is associated with every frame, implementing a new class of data frames is a most powerful way of adding functionality to the Oberon system.
We have intentionally used the term class. As a matter of fact, frames are implemented in Oberon as active objects in the sense of object-oriented programming. Calls of frame-specific handling procedures are made by system routines in the form of message transfers. In particular, the central Oberon loop typically initiates reactions on user-input actions by sending appropriate messages to the respective viewers. We emphasize that employing the object-oriented programming paradigm in connection with the handling of frames is necessary in order to enable the kernel to call command interpreters whose identity is unknown to it.
Any handler that is associated with a certain viewer class, for example menu-viewers, is expected to handle messages from (at least) three different originators: From the viewer manager, from the document manager, and from the central loop. Messages from the viewer manager report on the state change of the viewer. For example, the viewer manager Viewers sends a message whenever a hidden viewer becomes visible (and must therefore restore its contents), or when the size of a viewer has changed because its lower neighbour was opened, changed, or closed. Messages from the document manager remind the viewer of updating its contents after an editing operation. Finally, messages from module Oberon notify the viewer of system-wide events, such as input events (for example, "mouse button i pressed at position X, Y") or an inquiry for the most recent text selection (regarded in Oberon as the standard input). The interpreter-part handling input events should be regarded as an editor that is bound to the viewer class. In the case of viewers displaying text, this is a text editor, in the case of graphics, it is a graphics editor, and in the case of a viewer representing a mailbox it is an editor for electronic mail.
A typical viewer handler (like the one associated with menu-viewers) processes viewer-oriented messages directly and delegates the handling of the more data-specific messages by passing them on to the viewer's subframes. Prime examples of viewer-oriented messages are requests to restore a viewer or change its size. Examples of data-specific messages are selecting an object or invoking a command by pointing to its name. Notice that new and finer-grained requests may evolve from processing of viewer-oriented message.s For example, a request to change the size of a menu-viewer is resolved in requests to change the size of one or both of its subframes. In summarizing, viewer handlers normally act both as mediators and originators of messages to be processed by the handlers of their subframes.
The Canonical Decomposition of an Application
Modularizing by separation of concerns is one of the most effective techniques applied to the design of large software systems. Our concept of a class of frames displaying data of a certain kind provides a perfect opportunity to demonstrate this technique. We can extract the following separate topics from the program implementing an interactive application: the tool package, the command interpreter, the display handler, and the data manager. The following tasks are assigned to these parts: Providing a collection of powerful and customized commands operating on the data of the given kind (tool package), reacting on input actions within the associated display frame (command interpreter), displaying the visible objects (display handler), and encapsulating the management of the data without any concern of how they are displayed (data manager). Typically, the data part comprises a set of editing operations. It maintains an internal data structure describing the current state of the data.
It is natural to try to assign a separate module to each of these parts. We soon see that the command interpreter part and the display manager are preferably combined in one module because both need to operate on the same associated display frame. This leads to the following canonical module configurations in the casess of standard texts, graphics, pictures, and MyData, for example:
Notice that the same data manager can in principle be used by different display handlers and command interpreters. Data managers serve as links between different applications and thus enable an optimal integration. For example, if the graphic system is based on module Texts for the management of text captions, then text can freely be exchanged between frames of these classes: Graphic frames and text frames are integrated.
Tutorial Example: Text Viewers
So far, we have not explained yet how objects and messages are realized in the Oberon language. In contrast to typical object-oriented programming systems, the complete set of messages understood by an object need not be specified together with the definition of the object class. Instead, Oberon explores a more flexible dual approach: Messages are typically defined in sender modules. For example, messages of the first of the above mentioned kinds are defined in module Viewers, messages of the second kind are defined in the respective editor module (TextFrames in the case of text), and messages of the third kind are defined in module Oberon which detects input events.
Roughly speaking, the Oberon language supports subclassing (by the type extension facility), but messages and message handlers are not institutionalized in the form of a language construct. We have implemented the above outlined scheme by making use of procedure variables, and by applying Oberon's record extension facility to objects and to messages.
We shall now exemplify this model with the help of standard text-viewers, i.e. menu-viewers whose subframes (menu and main) are text frames. The following exposition may serve as a tutorial and template for implementors of arbitrary frame classes or viewer types. We recall that the display data structure is a hierarchy of display frames. Restricting our explanations to text-viewers we have the following hierarchy of types:
Viewers.Track MenuViewers.Viewer
^ ^
Viewers.Viewer TextFrames.Frame
^ ^
Display.Frame
Module Display features the base types of frames and frame messages and the type of the message handler. The (empty) base message serves as a root in the (potentially unlimited) hierarchy of messages to be accepted by frames. Module Viewers provides the definition of type Viewer, which is an extension (variant) of type Display.Frame. Menu-viewers are a based on Viewers.Viewer an defined in module MenuViewers.
In definition of Display:
TYPE
Frame = POINTER TO FrameDesc;
FrameMsg = RECORD END;
Handler = PROCEDURE (Frame, VAR FrameMsg);
FrameDesc = RECORD
dsc, next: Frame; (*son, brother*)
X, Y, W, H: INTEGER;
handle: Handler
END;
In the definition of Viewers:
TYPE
Viewer = POINTER TO ViewerDesc;
ViewerDesc = RECORD (Display.FrameDesc)
state: INTEGER
END;
In the definition of MenuViewers:
TYPE
Viewer = POINTER TO ViewerDesc;
ViewerDesc = RECORD (Viewers.ViewerDesc)
menuH: INTEGER
END;
The following are the declarations of messages that are expected to be handled by every viewer. Note that they are distributed over several modules rather than concentrated in one place (as it would be the case in an "ordinary" object-oriented model).
In definition of Viewers:
ViewerMsg = RECORD (Display.FrameMsg)
id: INTEGER;
X, Y, W, H: INTEGER; (*new rectangle*)
state: INTEGER (*new state*)
END;
(*signals change of viewer state
id = 0: restore viewer
1: modify size at bottom
2: suspend viewer*)
In definition of TextFrames:
UpdateMsg = RECORD (Display.FrameMsg)
id: INTEGER; (*operation*)
text: Texts.Text; (*edited text*)
beg, end: LONGINT (*stretch*)
END;
(*signals change of contents
id = 0: stretch [beg, end[ replaced
1: stretch [beg, end[ inserted
2: stretch [beg, end[ deleted*)
In definition of Oberon:
InputMsg = RECORD (Display.FrameMsg)
id: INTEGER; (*operation*)
modes, keys: SET; (*mouse*)
X, Y: INTEGER; (*position*)
ch: CHAR (*character read*)
END;
(*signals input event
id = 0: track mouse
1: consume character*)
ControlMsg = RECORD (Display.FrameMsg)
id: INTEGER; (*operation*)
X, Y: INTEGER (*current location of the mous*)
END;
(*signals control action
id = 0: remove focus
1: remove all marks
2: : mark*)
SelectionMsg = RECORD (Display.FrameMsg)
time: LONGINT;
text: Texts.Text;
beg, end: LONGINT
END;
(*signals inquiry for most recent text selection*)
CopyOverMsg = RECORD (Display.FrameMsg)
text: Texts.Text;
beg, end: LONGINT
END;
(*receive text stretch [beg, end[*)
CopyMsg* = RECORD (Display.FrameMsg)
F: Display.Frame
END;
(*request for the creation of a copy of a text frame*)
We recall that high-level viewer managers like MenuViewers typically pass on most of the received messages to their subframes. In the course of (pre-)processing viewer-oriented requests, high-level viewer managers can also produce new messages. In the case of MenuViewers these are
ModifyMsg* = RECORD (Display.FrameMsg)
id: INTEGER; (*operation*)
dY, Y, H: INTEGER (*vector dY, new Y and H*)
END;
(*vertically move and extend or reduce frame at bottom*)
id = 0: extend frame
id = 1: reduce frame*)
dY represents a vertical translation vector showing upwards in the extend-case and showing downwards in the reduce-case. By definition, dY is always non-negative. Y and H specify the new position and height respectively.
In summary, essentially the same messages have to be handled by a viewer and its subframes, except that some of the messages are processed or preprocessed by the ancestor viewer already which, in turn, may result in sending new and finer-grained messages to its subframes.
A message is sent to a specific object simply by calling its installed handler. For example, F.handle(F, M) has the effect of sending message M to frame F. In case of text-frames, the installed handler is Handle. It is elaborated in module TextFrames. We now provide a tutorial sketch of this procedure. Notice that Handle makes extensive use of Oberon's type test (and type guard) facility in order to discriminate among the different message kinds.
1 PROCEDURE Handle (F: Display.Frame; VAR M: Display.FrameMsg);
2 VAR F1: Frame;
3 BEGIN
4 WITH F: Frame DO
5 IF M IS Oberon.InputMsg THEN
6 WITH M: Oberon.InputMsg DO
7 IF M.id = Oberon.track THEN Edit(F, M.X, M.Y, M.keys)
8 ELSIF M.id = Oberon.consume THEN
9 IF F.car # 0 THEN Write(F, M.ch, M.fnt, M.col, M.voff) END
12 END
13 END
14 ELSIF M IS Oberon.ControlMsg THEN
15 WITH M: Oberon.ControlMsg DO
16 IF M.id = Oberon.defocus THEN Defocus(F)
17 ELSIF M.id = Oberon.neutralize THEN Neutralize(F)
18 END
19 END
20 ELSIF M IS Oberon.SelectionMsg THEN
21 WITH M: Oberon.SelectionMsg DO GetSelection(F, M.text, M.beg, M.end, M.time) END
22 ELSIF M IS Oberon.CopyOverMsg THEN
23 WITH M: Oberon.CopyOverMsg DO CopyOver(F, M.text, M.beg, M.end) END
24 ELSIF M IS Oberon.CopyMsg THEN
25 WITH M: Oberon.CopyMsg DO Copy(F, F1); M.F := F1 END
26 ELSIF M IS MenuViewers.ModifyMsg THEN
27 WITH M: MenuViewers.ModifyMsg DO Modify(F, M.id, M.dY, M.Y, M.H) END
28 ELSIF M IS UpdateMsg THEN
29 WITH M: UpdateMsg DO
30 IF F.text = M.text THEN Update(F, M) END
31 END
32 END
33 END
34 END Handle;
Explanations:
1 procedure of type Display.Handler
2 auxiliary variable for frame copy (line 25). Needed because M.F is base type
4 type guard; F must be a text frame
5 type test; is message an Oberon input message?
6 type guard
7 if message demands mouse tracking
8 if message demands consuming then consume a character
9 if caret is active in this text frame
14 type test; is message an Oberon control message?
15 type guard
16 if message demands removing the caret
17 if message demands removing caret and selection
20 type test; is message an Oberon selection inquiry?
21 if so, register own selection if it is newer than candidate
22 type test; is message a copy-over-message?
23 if so, copy text stretch to caret's location in this frame
24 type test; is message a copy-message?
25 if so, produce a copy of this frame (initialized to empty)
26 type test; is message a modify-message?
27 if so, modify size or position of this frame (see below)
28 type test; is message an update message?
30 if so, check if changed text is represented in this frame and then update frame
We also provide the following refinement of the procedure TextFrames.Modify called in line 27 in TextFrames.Handle. It shows well how subframes of menu-viewers should react on a MenuViewers.ModifyMsg.
PROCEDURE Modify (F: Frame; id, dY, Y, H: INTEGER);
BEGIN
Mark(F, 0); RemoveMarks(F); (*remove position-bar, caret, and selection*)
IF id = MenuViewers.extend THEN
IF dY > 0 THEN (*if frame is to be moved*)
Display.CopyBlock(F.X, F.Y, F.W, F.H, F.X, F.Y + dY, 0); F.Y := F.Y + dY (*move original block*)
END;
Extend(F, Y) (*extend moved frame at its bottom*)
ELSIF id = MenuViewers.reduce THEN
Reduce(F, Y + dY); (*reduce original frame at its bottom*)
IF dY > 0 THEN (*if frame is to be moved*)
Display.CopyBlock(F.X, F.Y, F.W, F.H, F.X, Y, 0); F.Y := Y (*move reduced block*)
END
END;
IF F.H > 0 THEN Mark(F, 1) END (*restore position-bar*)
END Modify;
Remember that dY is always non-negative, and notice that the reduce-part of the procedure is the exact inverse of the extend-part.
Notice by the way that the above handler is used for the handling of both data-frames and standard header-frames. The two variants of text frames differ only by their background color. This fact testifies for a streamlined system design and is an example of the "today en-vogue" notion of code reusing.
The attentative and experienced reader may have noticed that the module TextFrames plays two very different roles. Its first role is that of a (late-bound) handler of messages sent to frame instances. The second role is that of a library of procedures operating on text frames. Examples are Edit, Write, CopyOverShow, SetCaret, and TrackWord. To the two roles of TextFrames correspond two different ways of treating text frames, namely as active objects individually reacting on messages, and as passive rectangles to be operated on conventionally by invoking procedures. The second way of treating frames might be of importance in cases where text frames are text boxes belonging to the contents of some more complex document.
Module TextFrames offers yet another choice, this time to potential implementors of handlers of subclasses of text frames: Either they implement their own handler by just adding increments, and then refer to Handle, or they compose an individual handler from the elements. For example, a designer of MailFrames might apply the first strategy. He might just add a few mail-oriented methods catching the mail-oriented messages, and then delegate all further processing to TextFrames.Handle. In contrast, an implementor of a new user-interface to text frames might prefer strategy 2.
We conclude this section by explaining briefly the flow of control after, for example, a character has been typed. We assume that the focus viewer is a text viewer and that the caret is set in its main data frame. First, the central loop Oberon detects the new character in the keyboard buffer. It then sends an input consume-message to the focus-viewer which, in turn, passes on this message to its main subframe. After that, the handler (command interpreter) of this subframe locates the caret within the underlying text and subsequently calls the Insert-procedure of the text data manager Texts. On that, Insert inserts the character in the text and (up-)calls the associated notifier which, in our case, is residing in TextFrames. The notifier then sends a broadcast-message of type TextFrames.UpdateMsg to all visible viewers. Every single of these viewers passes on this message to its subframes. If a subframe understands the message and finds itself involved in this update, it restores its contents by accessing the new data, again from the data manager Texts.
We now present some typical examples of implementations.
where FindPiece is the following auxiliary procedure:
PROCEDURE FindPiece (T: Text; pos: LONGINT; VAR org: LONGINT; VAR p: Piece);
VAR n: INTEGER;
BEGIN
IF pos < T.org THEN T.org := -1; T.pce := T.trailer END;
org := T.org; p := T.pce; (*from cache*)
n := 0;
WHILE pos >= org + p.len DO org := org + p.len; p := p.next; INC(n) END;
IF n > 50 THEN T.org := org; T.pce := p END (*to cache*)
END FindPiece;
and where the types Piece, Text, and Buffer are defined as follows. Notice that Piece is a private type, Texts.Text is the public projection of type Text, and Texts.Buffer is the public part of type Buffer.