texts
stringlengths 0
1.24M
| names
stringlengths 13
33
|
---|---|
BlackBox Component Builder
Guided Tour
October 2021
This text is a quick introduction to the BlackBox Component Builder. Read it and follow the small hands-on examples to get a feeling for the way how BlackBox works.
Overview over the BlackBox Component Builder
The BlackBox Component Builder is an integrated development environment optimized for component-based software development. It consists of development tools, a library of reusable components, a framework that simplifies the development of robust custom components and applications, and a run-time environment for components.
In BlackBox, the development of applications and their components is done in Component Pascal. This language is a descendant of Pascal, Modula-2, and Oberon. It provides modern features such as objects, full type safety, components (in the form of modules), dynamic linking of components, and garbage collection. The entire BlackBox Component Builder is written in Component Pascal: all library components, all development tools including the Component Pascal compiler, and even the low-level run-time system with it's garbage collector. In spite of it's power, Component Pascal is a small language that is easy to learn and easy to teach.
The component library that comes with BlackBox contains components for user interface elements such as command buttons or checkboxes; various components that provide word processing functionality (Text subsystem); various components that provide layout management functionality for graphical user interfaces (Form subsystem); database access components (Sql subsystem); communication components (Comm subsystem); and a number of development tool components such as compiler, interface browser, debugger, and so on (Dev subsystem).
Component interactions are governed by the BlackBox Component Builder's Frameworks. These consist of a number of complementary programming interfaces. These interfaces are much simpler and safer, and platform-independent moreover, than basic APIs, such as the Windows APIs. For interactive applications, they define a quite unique compound document architecture. This architecture enables rapid application development (RAD), including the rapid development of new user interface components. The framework design strongly emphasizes robust component interaction. This is important for large-scale software projects that involve components from different sources and evolution of the software over long periods of time. To combine the productivity of a RAD environment with a high degree of architectural robustness was a major design goal for the BlackBox Component Builder. It was attempted to create an environment that is light-weight and flexible, yet doesn't sacrifice robustness and long-term maintainability of software produced with it. This was made possible by an architecture that decomposes the system into components with well-defined interfaces. Software is evolved incrementally, by adding, updating, or removing entire components.
The BlackBox run-time environment supports dynamic linking and loading (and unloading) of components. In this way, a system can be extended at run-time, without recompiling, relinking, or restarting existing code. Component objects (i.e., instances of classes contained in components) are automatically removed when they are not referenced anymore. This garbage collection service is a crucial safety feature of the run-time system, since it allows to prevent errors like memory leaks and dangling pointers, which are almost impossible to avoid in a heavily component-oriented system like BlackBox.
Views
Now let's have a look at some standard BlackBox components. Views are the most interesting objects implemented by BlackBox components; they can be embedded into documents or other views. Views can be edited and resized in place. This tour text contains several embedded views. Here is a first one: a picture view without editing capabilities.
A picture view as an example of a component object embedded in a compound document.
Other examples of views are controls such as command buttons, checkboxes, alarm indicators, oil level meters, and so on. More complex views can implement full-fledged editors such as spreadsheets or graphics editors. The most complex views in BlackBox are container views, i.e., views that may contain other views. Text views are an important example of BlackBox container views. You are now looking at such a text view. Further below, there is an embedded text view containing a small program. The following sections demonstrate how simple programs can be written and tested, and how a graphical user interface can be constructed.
Software development
The source code below is a fully editable text, showing the complete implementation of a small Component Pascal module. To compile the module, focus the embedded view by clicking into it (e.g., click on the keyword PROCEDURE), and then execute Compile from menu Dev. As a result, the module is compiled into fast native machine which is written to disk (the file Obx/Code/Hello0).
MODULE ObxHello0;
IMPORT StdLog;
PROCEDURE Do*;
BEGIN
StdLog.String("Hello World"); StdLog.Ln
END Do;
END ObxHello0.
ObxHello0 is a minimal "hello world" program in Component Pascal. It writes a single line to the system log text. Execute OpenLog from menu Info to display the system log, if it is not open already.
Exported items in Component Pascal modules are marked by a trailing asterisk; there are no separate header files, definition modules, or the like. Consistency of interfaces and implementations is fully checked by the compiler; version integrity is checked by the dynamic linker.
Module ObxHello0 exports a single command Do. Commands are exported Component Pascal procedures that can be called by the user; i.e., they can be executed directly from the user interface. There is no need for a central "main" procedure or top-level module. A command can be added to a menu, attached to a button, or executed directly from within a text. Select the string "ObxHello0.Do" below, and then execute command Execute in menu Dev:
ObxHello0.Do
When the compiler finds syntax errors, it flags them directly in the text. For example, the following module version erroneously imports the (nonexisting) module StdLok, instead of StdLog. Try to compile the module – the compiler inserts special embedded objects (error markers) flagging the errors that it found. The compiler also writes a report to the system log.
MODULE ObxHello0;
IMPORT StdLok;
PROCEDURE Do*;
BEGIN
StdLog.String("Hello World"); StdLog.Ln
END Do;
END ObxHello0.
By clicking on an error marker, a short error message is displayed in the status bar. Correct the mistake (replace the "k" in IMPORT StdLok by a "g"), and compile again. The marker disappears, and the module is compiled successfully.
The set of currently loaded modules can be inspected by clicking on the LoadedModules command in the Info menu. The interfaces of modules (loaded or not) can be displayed using the interface browser: select a module name and then execute ClientInterface from menu Info. For example, you may find out the interface of the following module:
Math
A module remains loaded until it is explicitly unloaded, or until the BlackBox Component Builder is restarted. To explicitly unload a module, select the module name and execute UnloadModuleList from menu Dev. For example, unload ObxHello0, modify the string "Hello world", recompile ObxHello0, and execute ObxHello0.Do again. Note that your changes do not affect the running system until after you have unloaded the old module. Such an explicit unloading is a very useful mechanism to allow major changes in multiple modules, while still using and working with the previous version. For simple top-level modules, (modules that are not imported by other modules), the command CompileAndUnload provides a convenient shortcut.
Linking programs to form documents
Besides the text and development subsystems, the BlackBox Component Builder also comes with a form subsystem, which includes a visual user interface designer. Forms can be data entry masks or dialog boxes.
The following module defines a simple record variable to be used for a data entry form.
MODULE ObxAddress1;
IMPORT Views, TextModels, TextMappers, TextViews;
VAR
adr*: RECORD
name*: ARRAY 64 OF CHAR;
city*: ARRAY 24 OF CHAR;
country*: ARRAY 16 OF CHAR;
customer*: INTEGER;
update*: BOOLEAN
END;
PROCEDURE OpenText*;
VAR t: TextModels.Model; f: TextMappers.Formatter; v: Views.View;
BEGIN
t := TextModels.dir.New(); (* create a new text editor object *)
f.ConnectTo(t); (* connect a formatter to this object *)
f.WriteString(adr.name); f.WriteTab;
f.WriteString(adr.city); f.WriteTab;
f.WriteString(adr.country); f.WriteTab;
f.WriteInt(adr.customer); f.WriteTab;
f.WriteBool(adr.update); f.WriteLn;
v := TextViews.dir.New(t); (* create a visual component for the text object *)
Views.OpenView(v) (* open the visual component in its own window *)
END OpenText;
END ObxAddress1.
After compiling the module, a dialog box can be created for the items exported by ObxAddress1 using command NewForm... from menu Controls. Just enter the name ObxAddress1 into the Link field, and then click on the OK button. The type information extracted by the compiler is available to the BlackBox Component Builder at run-time, and is used to automatically create a data-entry form for the record declaration above. The form has a simple default layout. This default layout may be edited, and then opened as a dialog using the Open as Aux Dialog command in menu Controls.
The text entry fields and the checkbox of the form are directly linked to the fields name, city, country, customer and update of the record ObxAddress1.adr. The button is linked to the command OpenText, i.e., to the procedure exported by module ObxAddress1. Clicking the button causes procedure OpenText to be called. As a result, a new text is created; a textual report based on the variable adr is written to this text; a new text view is created; and the view is opened in a window, displaying the report.
Text entry fields, checkboxes, and other so-called controls may have properties that could be inspected and modified by a suitable control property inspector. Instead of first writing a module and then creating an initial layout, as we have done above, the form can be constructed first, and the corresponding module written later. A BlackBox Component Builder dialog does not necessarily correspond to exactly one record variable. The individual controls of a dialog box may be linked to records in different modules, and a dialog box may also contain other views which are not controls, such as pictures.
A form can be saved from within the visual editor; thereafter it can be attached to a menu entry, or another dialog's button. Dialog boxes are saved in the standard document format, in a platform-independent way. This approach eliminates the need for an intermediate source code generator and allows to later modify the dialog boxes without having to recompile anything.
And more ...
After this first impression, you may want to consult your documentation for an in-depth coverage of the BlackBox Component Builder. Select the Contents item in the Help menu for an overview over the documentation. From there, the complete on-line documentation can be reached via hyperlinks.
How should you start to get acquainted with BlackBox? We suggest that you start with the introduction texts A Brief History of Pascal and Roadmap.
The documentation consists of four major parts:
•A user manual that describes the user interface and most important commands of the BlackBox Component Builder
•A tutorial that first introduces the general BlackBox design patterns (chapters 1 to 3). Graphical user interfaces, forms, and controls are discussed in chapter4. The text subsystem is explained in chapter5. The remaining chapter6 deals with view programming.
•Overview by Example is a rich source of examples, ordered by category and difficulty.
•The programmer's reference consists of one documentation file per module. Each subsystem has a Sys-Map text which contains links to the individual texts.
| Docu/Tour.odc |
Table of Contents ↑
6 View Construction
Views are the central abstraction in the BlackBox Component Builder. Everything revolves around views: most commands operate on views, windows display views, views can be internalized and externalized, views perform interaction with the user, and views may be embedded into other views.
6.1 Introduction
This view programming tutorial consists of four sections, each of which introduces a special aspect of view programming. The section "message handling" (chapters 6.2 to 6.5) explains how the behavior of a view is defined through the view's message handlers, i.e., how the answering of preferences, controller messages and properties influences the view's relation to its environment and the view's reaction on user input. The second section explains the aspect of the model-view separation which allows multi view editing (6.6). The next section shows how the undo/redo facility of the BlackBox Component Framework can be used if the content of a view is changed with the help of operation objects (6.7). In the last section the special structure of all extensible BlackBox Component Framework modules is explained, namely the separation of the interface and the implementation of a view (6.8). Directory objects are the key to this design pattern.
6.2 Message handling
In this section, we present a sequence of increasingly more versatile implementations of a view object which displays a rectangular colored area. In particular, this view will handle Preferences, Controller messages and Properties.
Every view is a subtype of the abstract type Views.View. The concrete extension must at least implement the abstract procedure Views.Restore that draws the view's contents. The first example of our view simply draws a red rectangle. This version is about the simplest possible view implementation. Its major components are the declaration of a Views.View extension, the implementation of a Views.Restore procedure which draws the contents of the view, and a command procedure which allocates and initializes the view:
MODULE ObxViews0;
IMPORT Views, Ports;
TYPE View = POINTER TO RECORD (Views.View) END;
PROCEDURE (v: View) Restore (f: Views.Frame; l, t, r, b: INTEGER);
BEGIN
f.DrawRect(l, t, r, b, Ports.fill, Ports.red)
END Restore;
PROCEDURE Deposit*;
VAR v: View;
BEGIN
NEW(v); Views.Deposit(v)
END Deposit;
END ObxViews0.
To execute this program, invoke the following command:
"ObxViews0.Deposit; StdCmds.Open"
The result of this command is shown in Figure 6-1.
Figure 6-1: Result of "ObxViews0.Deposit; StdCmds.Open"
This simple program is completely functional already. The procedure ObxViews0.Deposit puts a newly allocated view into a system queue. The command StdCmds.Open in the command string above removes a view from this queue, and opens it in a new window. Note that whole sequences of commands must be enclosed between quotes, while for single commands the quotes may be omitted.
Instead of opening the view in a window, it could be pasted into the focus container (e.g., a text or a form):
"ObxViews0.Deposit; StdCmds.PasteView" >< set the caret here before executing the command
Like StdCmds.Open, the command StdCmds.PasteView removes a view from the queue, but pastes it to the focus view. The above command sequence could also be used in a menu, for example.
Every document which contains an ObxViews0 view can be saved in a file, and this file can be opened again through the standard Open... menu entry. Our simple red rectangle will be displayed correctly in the newly opened document, provided the code file of the module ObxViews0 is available.
A view which has been opened in its own window can also be saved in a file. When opened again, the document then consists of this single view only.
Every view performs its output operations and mouse/keyboard polling via a Views.Frame object. In the above example, ObxViews0.View.Restore uses its frame parameter f to draw a rectangle. A frame can be regarded as a mapper object, in this case for both input and output simultaneously (here we need not be interested in the rider and carrier for this mapper, which are both defined in module Ports). A frame embodies coordinate transformations and clipping facilities.
If the view is displayed on the screen, the frame is a mapper on a screen port. If the view is printed, the frame is a mapper on a printer port. From the view's perspective, this difference is not relevant. Thus no special code is necessary to support printing.
The view may be copied and pasted into containers such as text views or form views. Additionally, the size of the view can be changed by selecting it and then manipulating the resize handles. All this functionality is offered by the BlackBox Component Framework and requires no further coding. If this default behavior is not convenient, it can be modified. In the following we will show how this is done.
6.3 Preference messages
You might have noticed that the size of a newly opened view is rather arbitrary. However, before opening the view, the framework sends the view a message with a proposed size. The view may adapt this proposal to its own needs. To do that, the message of type Properties.SizePref must be answered in the view's HandlePropMsg procedure. Before a view is displayed for the first time, the proposed size for the width and the height of the view is Views.undefined. The following version of our sample view draws a rectangle with a width of 2 cm and a height of 1 cm. Changes compared to the previous version are written in bold face.
MODULE ObxViews1;
IMPORT Views, Ports, Properties;
TYPE View = POINTER TO RECORD (Views.View) END;
PROCEDURE (v: View) Restore (f: Views.Frame; l, t, r, b: INTEGER);
BEGIN
f.DrawRect(l, t, r, b, Ports.fill, Ports.red)
END Restore;
PROCEDURE (v: View) HandlePropMsg (VAR msg: Properties.Message);
BEGIN
WITH msg: Properties.SizePref DO
IF (msg.w = Views.undefined) OR (msg.h = Views.undefined) THEN
msg.w := 20 * Ports.mm; msg.h := 10 * Ports.mm
END
ELSE (* ignore other messages *)
END
END HandlePropMsg;
PROCEDURE Deposit*;
VAR v: View;
BEGIN
NEW(v); Views.Deposit(v)
END Deposit;
END ObxViews1.
"ObxViews1.Deposit; StdCmds.Open"
Every newly generated view now assumes the desired predefined size. This is only possible because the view and its container cooperate, in this case via the Properties.SizePref message. A container is expected to send this message whenever it wants to change a view's size, and then adhere to the returned data. However, for the understanding of the BlackBox Component Framework it is essential to know that while a well-behaved container should follow this protocol, it is not required to do so. That's why such a message is called a preference. It describes merely a view's preference, so that the surrounding container can make allowances for the special needs of the view. But it is always the container which has the last word in such negotiations. For example, the container will not let embedded views become larger than itself. The standard document, text, and form containers are well-behaved in that they support all preferences defined in module Properties. Special containers, e.g. texts, may define additional preferences specific to their type of contents. It is important to note that a view can ignore all preferences it doesn't know or doesn't care about.
The Properties.SizePref allows us to restrict the possible values for the width and the height of a view. For example, we can enforce a minimal and a maximal size, or fix the height or width of the view, or specify a constraint between its width and height. The procedures Properties.ProportionalConstraint and Properties.GridConstraint are useful standard implementations to specify constraints. The next version of our view implementation specifies that the rectangle is always twice as wide as it is high. In addition, minimal and maximal values for the height (and thus also for the width) are specified. If the view is resized using the resize handles, the constraints are not violated. Try it out!
MODULE ObxViews2;
IMPORT Views, Ports, Properties;
TYPE View = POINTER TO RECORD (Views.View) END;
PROCEDURE (v: View) Restore (f: Views.Frame; l, t, r, b: INTEGER);
BEGIN
f.DrawRect(l, t, r, b, Ports.fill, Ports.red)
END Restore;
PROCEDURE (v: View) HandlePropMsg (VAR msg: Properties.Message);
CONST min = 5 * Ports.mm; max = 50 * Ports.mm;
BEGIN
WITH msg: Properties.SizePref DO
IF (msg.w = Views.undefined) OR (msg.h = Views.undefined) THEN
msg.w := 20 * Ports.mm; msg.h := 10 * Ports.mm
ELSE
Properties.ProportionalConstraint(2, 1, msg.fixedW, msg.fixedH, msg.w, msg.h);
IF msg.h < min THEN
msg.h := min; msg.w := 2 * min
ELSIF msg.h > max THEN
msg.h := max; msg.w := 2 * max
END
END
ELSE (* ignore other messages *)
END
END HandlePropMsg;
PROCEDURE Deposit*;
VAR v: View;
BEGIN
NEW(v); Views.Deposit(v)
END Deposit;
END ObxViews2.
"ObxViews2.Deposit; StdCmds.Open"
We will look at two other preferences in this tutorial. The first one is Properties.ResizePref.
TYPE
ResizePref = RECORD (Properties.Preference)
fixed,
horFitToPage, verFitToPage,
horFitToWin, verFitToWin: BOOLEAN (* OUT *)
END;
The receiver of this message may indicate that it doesn't wish to be resized, by setting fixed to TRUE. As a consequence, the view will not display resize handles when it is selected, i.e., it cannot be resized interactively. However, the Properties.SizePref message is still sent to the view, as the initial size still needs to be determined.
If a view is a root view, i.e., the outermost view in a document or window (e.g., if opened with StdCmds.Open), then the size of the window, the size of the view, or both might be changed.
However, sometimes it is convenient if the view size is automatically adapted whenever the window is resized, e.g., for help texts which should use as much screen estate as possible. For other views, it may be preferable that their size is not determined by the window, but rather by their contents, or by the page setup of the document in which they are embedded. A view can indicate such preferences by setting the horFitToWin, verFitToWin, horFitToPage, and verFitToPage flags in the Properties.SizePref message. These flags have no effect if the view is not a root view, i.e., if it is embedded deeper inside a document.
An automatic adaptation of the view size to the actual window size can be achieved by setting the fields horFitToWin and verFitToWin. The size of the view is then bound to the window, i.e., the user can change it directly by resizing the window.
Note that if the size of the view is bound to the size of the window (either by setting horFitToWin or verFitToWin), then no Properties.SizePref messages are sent to the view, i.e., the constraints specified through Properties.SizePref are no longer enforced. Additionally, the view does not display resize handles, regardless of the fixed flag.
By setting the fields horFitToPage or verFitToPage, the width or the height of the view can be bound to the actual printer page size. The width of a text view is usually bound to the width of the page size, and can be changed via the page setup mechanism of the underlying operating system. The following example enforces that the size of a root view is bound to the size of the window:
MODULE ObxViews3;
IMPORT Views, Ports, Properties;
TYPE View = POINTER TO RECORD (Views.View) END;
PROCEDURE (v: View) Restore (f: Views.Frame; l, t, r, b: INTEGER);
BEGIN
f.DrawRect(l, t, r, b, Ports.fill, Ports.red)
END Restore;
PROCEDURE (v: View) HandlePropMsg (VAR msg: Properties.Message);
CONST min = 5 * Ports.mm; max = 50 * Ports.mm;
BEGIN
WITH msg: Properties.SizePref DO
IF (msg.w = Views.undefined) OR (msg.h = Views.undefined) THEN
msg.w := 20 * Ports.mm; msg.h := 10 * Ports.mm
ELSE
Properties.ProportionalConstraint(2, 1, msg.fixedW, msg.fixedH, msg.w, msg.h);
IF msg.h < min THEN
msg.h := min; msg.w := 2 * min
ELSIF msg.h > max THEN
msg.h := max; msg.w := 2 * max
END
END
| msg: Properties.ResizePref DO
msg.horFitToWin := TRUE; msg.verFitToWin := TRUE
ELSE (* ignore other messages *)
END
END HandlePropMsg;
PROCEDURE Deposit*;
VAR v: View;
BEGIN
NEW(v); Views.Deposit(v)
END Deposit;
END ObxViews3.
"ObxViews3.Deposit; StdCmds.Open"
The next preference we look at is Properties.FocusPref.
TYPE
FocusPref = RECORD (Properties.Preference)
atLocation: BOOLEAN; (* IN *)
x, y: INTEGER; (* IN *)
hotFocus, setFocus, selectOnFocus: BOOLEAN (* OUT *)
END;
When an attempt is made to activate an embedded view, by clicking in it, then the Properties.FocusPref message is sent to the view. If this message is not answered the view is selected as a whole (a so-called singleton). This is the behavior of the views implemented in the examples above. To see this, place the caret on the next line and click on the commander below, then on the pasted view:
"ObxViews3.Deposit; StdCmds.PasteView" >< set the caret here before executing the command
This behavior is adequate if a view is passive. However, if the view contains editable contents, or if there are menu commands that operate on the view, the user should be able to focus the view. The focus is where keyboard input is sent to, where the current selection or caret are displayed (if there are any such marks), and where upon some menu commands operate. In fact, menus can be made to appear whenever a view is focused, and disappear as soon as the view loses focus (more on this below). A root view is always focused when its document window is focus (i.e., is the top window).
If an embedded view wants to become focus, it must answer the Properties.FocusPref message. The view can choose whether it wants to become focus permanently or if it wants only be focus as long as the mouse button is pressed. The latter is called a hot focus. A typical example of a hot focus is a command button. If a view wants to be a hot focus, it must set the flag hotFocus. The focus is then released immediately after the mouse is released. If a view wants to become focus permanently, then the flag setFocus must be set instead. setFocus should be set for all genuine editors, such that context-sensitive menu commands can be attached to the view. In addition to the setFocus flag, a view may set the selectOnFocus flag to indicate that upon focusing by keyboard, the view's contents should be selected. Text entry fields are prime examples for this behavior: the contents of a newly focused text entry field is selected, if the user focused it not by clicking in it, but by using the tabulator key.
If the user clicks in an unfocused view, then the atLocation flag is set by the framework before sending the message. The receiving view may decide whether to become focused depending on where the user clicked. The mouse position is passed to the view in the focus preference's x and y fields. Text rulers are examples of views which become focused depending on the mouse location. If you click in the icons or in the area below the scale of a ruler, the ruler is not focused. Otherwise it is focused. Try this out with the ruler below. If you don't see a ruler, execute the Show Marks command in the Text menu.
A view is not necessarily focused through a mouse click. In forms for example, the views can be selected using the tabulator key. There, the views do not become focused through a mouse click, and the atLocation field is accordingly set to FALSE by the framework.
The next version of our example will answer the FocusPref message and set the setFocus flag. This is done by adding the following statements to the previous example's HandlePropMsg procedure:
| msg: Properties.FocusPref DO
msg.setFocus := TRUE
If an embedded view is focused, the frame of the view is marked with a suitable focus border mark, and view-specific menus may appear while others disappear.
6.4 Controller messages
Other messages that may be interpreted by HandlePropMsg will be discussed later. Next we will see how a view can react on user input, e.g., on mouse clicks in the view or on commands called through a menu. For simple views this behavior is implemented in the procedure Views.HandleCtrlMsg. It is also possible to define a separate object, a so-called controller, that implements the interactive behavior of a view. Programming of controller objects is not described in this document, since controllers are only recommended for the most complex views.
TheViews.HandleCtrlMsg handler answers the controller messages sent to the view. A controller message is a message that is sent along exactly one path in a view hierarchy, the focus path. Every view on the focus path decides for itself whether it is the terminal of this path, i.e., whether it is the current focus, or whether the message should be forwarded to one of its embedded views. It is important to note that all controller messages which are not relevant for a particular view type can simply be ignored.
In order to be able to perform edit operations on the focus view, the framework must allow to somehow perform these operations. Mouse clicks and key strokes can always be issued. However, how the menus should look like may be decided by the view itself. For that purpose, the message Controllers.PollOpsMsg is sent to the view. Depending on its current state (e.g., its current selection) and depending on the contents of the clipboard, the focus view can inform the framework of which editing operations it currently supports. The valid operations are elements of the {Controllers.cut, Controllers.copy, Controllers.paste, Controllers.pasteView} set.
TYPE
PollOpsMsg = RECORD (Controllers.Message)
type: Stores.TypeName; (* OUT *)
pasteType: Stores.TypeName; (* IN *)
singleton: Views.View; (* OUT *)
selectable: BOOLEAN; (* OUT *)
valid: SET (* OUT *)
END;
The set of valid edit operations is returned in the valid field, where valid IN {Controllers.cut, Controllers.copy, Controllers.paste}. According to the set of valid operations, the corresponding menu entries in the Edit menu are enabled or disabled, e.g., Cut, Copy, Paste and PasteObject.... The field pasteType contains the concrete type of the view from which a copy would be pasted, if a paste operation occurred. Depending on this field, the view could decide whether it wants to support the paste operation or not. PollOpsMsg is sent when the user clicks in the menu bar. Its sole purpose is to enable or disable menu items, i.e., to provide user feedback.
If a view supports a selection of its contents, then selectable must be set to TRUE. As a consequence, the menu entry SelectAll will be enabled. The flag should be set regardless of whether a selection currently exists or not.
In the type field a type name may be passed. This name denotes a context for the focus view. This context is used to determine which menus are relevant for the focus view. As a convention, a view assigns the type name of its interface base type to type, e.g. "ObxViews4.View". A menu which indicates to be active on "ObxViews4.View" will be displayed if such a view is focus. The type name is used because it is easy to make unique, so that name collisions are avoided. The framework doesn't interpret the name.
The singleton field is only meaningful for container views. It denotes a container's currently selected view, if the selection consists of exactly one embedded view.
The following example view can become focus, supports the paste operation, and informs the framework that its contents is selectable. As a consequence, the menu entries Paste and Select All in the Edit menu are enabled. Additionally, it defines the context "Obx.Tutorial". Therefore the following menu appears whenever the view is focused; provided that the menu has been installed.
Note that the name of the context, in this case "Obx.Tutorial", by convention starts with the subsystem or a module name followed by a dot, in this case "Obx.". This is highly recommended, in order to make context names globally unique. Often, the name is simply the name of a view type, e.g., "TextViews.View".
A menu can either be defined in the global menu text System/Rsrc/Menus, or more appropriately in its own subsystem's menu text, in this case in Obx/Rsrc/Menus . The global menu text then only needs an INCLUDE "Obx" statement to make the Obx menus known.
MENU "New" ("Obx.Tutorial")
"Beep" "" "Dialog.Beep" ""
END
MODULE ObxViews4;
IMPORT Views, Ports, Properties, Controllers;
TYPE View = POINTER TO RECORD (Views.View) END;
PROCEDURE (v: View) Restore (f: Views.Frame; l, t, r, b: INTEGER);
BEGIN
f.DrawRect(l, t, r, b, Ports.fill, Ports.red)
END Restore;
PROCEDURE (v: View) HandlePropMsg (VAR msg: Properties.Message);
CONST min = 5 * Ports.mm; max = 50 * Ports.mm;
BEGIN
WITH msg: Properties.SizePref DO
IF (msg.w = Views.undefined) OR (msg.h = Views.undefined) THEN
msg.w := 20 * Ports.mm; msg.h := 10 * Ports.mm
ELSE
Properties.ProportionalConstraint(2, 1, msg.fixedW, msg.fixedH, msg.w, msg.h);
IF msg.h < min THEN
msg.h := min; msg.w := 2 * min
ELSIF msg.h > max THEN
msg.h := max; msg.w := 2 * max
END
END
| msg: Properties.ResizePref DO
msg.horFitToWin := TRUE; msg.verFitToWin := TRUE
| msg: Properties.FocusPref DO
msg.setFocus := TRUE
ELSE (* ignore other messages *)
END
END HandlePropMsg;
PROCEDURE (v: View) HandleCtrlMsg (f: Views.Frame;
VAR msg: Controllers.Message; VAR focus: Views.View);
BEGIN
WITH msg: Controllers.PollOpsMsg DO
msg.valid := {Controllers.paste}; msg.selectable := TRUE;
msg.type := "Obx.Tutorial"
ELSE (* ignore other messages *)
END
END HandleCtrlMsg;
PROCEDURE Deposit*;
VAR v: View;
BEGIN
NEW(v); Views.Deposit(v)
END Deposit;
END ObxViews4.
"ObxViews4.Deposit; StdCmds.PasteView" >< set the caret here before executing the command
Next we discuss how a view can react on actual edit messages. In particular, these are the Controllers.EditMsg for edit operations such as cut, copy, or paste, and the Controllers.TrackMsg for mouse clicks.
Whenever a key is pressed in a view or when a cut, copy or paste operation is invoked, a Controllers.EditMsg is sent to the focus view. The cut, copy and paste operations can only be generated through the environment (menu) if they have been announced with the Controllers.PollOpsMsg.
TYPE
EditMsg = RECORD (Controllers.RequestMessage)
op: INTEGER; (* IN *)
modifiers: SET; (* IN *)
char: CHAR; (* IN *)
view: Views.View; (* IN for paste, OUT for cut and copy *)
w, h: INTEGER; (* IN for paste, OUT for cut and copy *)
isSingle: BOOLEAN; (* IN for paste, OUT for cut and copy *)
clipboard: BOOLEAN (* IN *)
END;
The op field specifies which kind of operation has to be performed. If op = Controllers.cut then a copy of the focus view has to be generated. The contents of the new view is a copy of the focus view's selection. The new view is assigned to the view field. In addition, the selection is deleted in the focus view.
There is one special case: if the selection consists of exactly one view (a singleton), then a copy of the singleton should be copied to the view field, not a copy of the singleton's container. In this case, isSingle must be set to TRUE.
Except for the deletion of the selection, the same operations have to be performed if op = Controllers.copy.
If a key is pressed, then the op field has the value Controllers.pasteChar. The character to be pasted is stored in the char field. The modifiers set indicates control key has been pressed. In the latter case, the char field has to be interpreted as a control character.
The paste operation is the inverse of the copy operation: a copy of the contents of the view stored in the view field has to be copied into the focus view's contents. This operation is indicated by op = Controllers.paste. The view must know the type of the view whose contents is to be pasted and must decide how to insert the pasted view's contents into its own view. For example, a text field view should support copying from a text view only.
If isSingle is TRUE, or if the contents of view cannot be pasted because it has an unknown or incompatible type, a copy of view must be pasted. Of course, this is only possible in general containers, which allow the embedding of other views.
When pasting a complete view, the desired width and height of the pasted view are given in the fields w and h. These values can be treated as hints by the receiving view. If they are not suitable, others can be used.
Whenever the mouse button is pressed in the focus view, a Controllers.TrackMsg is sent to the view. The coordinates are specified in the x and y fields (of the base type Controllers.CursorMessage). The modifiers set indicates whether modifier keys have been pressed, or whether a double click has been performed. The platform independent modifiers are Controllers.doubleClick, Controllers.extend, Controllers.modify, Controllers.popup, and Controllers.pick. For the mapping of platform specific keys see platform specific modifiers. If the view wants to show a feedback while tracking the mouse, it needs to poll the mouse position in a loop, by calling the Input procedure of the passed frame. Input also returns information on whether the mouse has been released. Any feedback should directly be drawn into the frame in which the mouse button was pressed.
After the feedback loop, a possible modification of the view's contents need to be broadcast to all the frames that display the same view. Remember that the same document, and consequently all its embedded views, may be displayed in several windows (see Chapter 2). If an embedded view is visible in three windows, there exist three frames displaying the same view. Procedure Views.Update causes a restore of the view once in each of its visible frames.
As an example, we extend our view with a cross-hair marker that can be moved around. The coordinates of this marker are stored as additional fields in the view object. Note that if a view contains instance variables, it should implement the CopyFromSimpleView, Internalize and Externalize procedures in order to work properly. We refer to the next section of this view tutorial, which describes the purpose of these messages. In our example view, the marker can be moved around with the mouse, or through the cursor keys. When a cursor key is pressed, the focus view is informed by sending it an EditMsg with op = pasteChar.
From time to time a Controllers.PollCursorMsg is sent to the focus view. The view may set the form of the cursor depending on the coordinates of the mouse. The cursor field can be assigned a cursor out of {Ports.arrowCursor, Ports.textCursor, Ports.graphicsCursor, Ports.tableCursor, Ports.bitmapCursor}. The particular form of the cursor depends on the underlying operating system. In our example view, we set the cursor to a graphics cursor.
MODULE ObxViews5;
IMPORT Views, Ports, Properties, Controllers;
TYPE
View = POINTER TO RECORD (Views.View)
x, y: INTEGER
END;
PROCEDURE (v: View) Restore (f: Views.Frame; l, t, r, b: INTEGER);
BEGIN
f.DrawRect(l, t, r, b, Ports.fill, Ports.red);
f.DrawLine(v.x, t, v.x, b, 0, Ports.white); f.DrawLine(l, v.y, r, v.y,
0, Ports.white)
END Restore;
PROCEDURE (v: View) HandlePropMsg (VAR msg: Properties.Message);
CONST min = 5 * Ports.mm; max = 50 * Ports.mm;
BEGIN
WITH msg: Properties.SizePref DO
IF (msg.w = Views.undefined) OR (msg.h = Views.undefined) THEN
msg.w := 20 * Ports.mm; msg.h := 10 * Ports.mm
ELSE
Properties.ProportionalConstraint(2, 1, msg.fixedW, msg.fixedH, msg.w, msg.h);
IF msg.h < min THEN msg.h := min; msg.w := 2 * min
ELSIF msg.h > max THEN msg.h := max; msg.w := 2 * max
END
END
| msg: Properties.ResizePref DO
msg.horFitToWin := TRUE; msg.verFitToWin := TRUE
| msg: Properties.FocusPref DO
msg.setFocus := TRUE
ELSE (* ignore other messages *)
END
END HandlePropMsg;
PROCEDURE (v: View) HandleCtrlMsg (f: Views.Frame;
VAR msg: Controllers.Message;
VAR focus: Views.View);
VAR x, y, w, h: INTEGER; m: SET; isDown: BOOLEAN;
BEGIN
WITH msg: Controllers.PollOpsMsg DO
msg.valid := {Controllers.paste}; msg.selectable := TRUE;
msg.type := "Obx.Tutorial"
| msg: Controllers.EditMsg DO
IF msg.op = Controllers.pasteChar THEN (* cursor keys *)
IF msg.char = 1DX THEN INC(v.x, Ports.mm)
ELSIF msg.char = 1CX THEN DEC(v.x, Ports.mm)
ELSIF msg.char = 1EX THEN DEC(v.y, Ports.mm)
ELSIF msg.char = 1FX THEN INC(v.y, Ports.mm)
END;
Views.Update(v, Views.keepFrames)
END
| msg: Controllers.TrackMsg DO
v.x := msg.x; v.y := msg.y;
v.context.GetSize(w, h); v.Restore(f, 0, 0, w, h);
REPEAT
f.Input(x, y, m, isDown);
IF (x # v.x) OR (y # v.y) THEN
v.x := x; v.y := y; v.Restore(f, 0, 0, w, h)
END
UNTIL ~isDown;
Views.Update(v, Views.keepFrames)
| msg: Controllers.PollCursorMsg DO
msg.cursor := Ports.graphicsCursor
ELSE (* ignore other messages *)
END
END HandleCtrlMsg;
PROCEDURE Deposit*;
VAR v: View;
BEGIN
NEW(v); v.x := 0; v.y := 0; Views.Deposit(v)
END Deposit;
END ObxViews5.
"ObxViews5.Deposit; StdCmds.Open"
There exist many other controller messages which may be sent to a view, but which are beyond the scope of this tutorial. There are messages for the generic scrolling mechanism of the BlackBox Component Framework (Controllers.PollSectionMsg, Controllers.ScrollMsg, Controllers.PageMsg), messages which implement drag & drop (Controllers.PollDropMsg, Controllers.DropMsg, Controllers.TransferMessage) and messages which control the selection (Controllers.SelectMsg). For these and other controller messages we refer to the documentation of the Controllers module.
6.5 Properties
We want to close this section with a final extension of our view: the color of the view should be changeable through the Attributes menu. The general mechanism to get and set attributes of a view from its environment are properties. A view may know about attributes such as font, color, size, but it may also know about arbitrary other attributes. Properties are set with the Properties.SetMsg and inspected with the Properties.PollMsg. Properties in one of these messages are stored in a linked list. If a view gets a Properties.SetMsg it should traverse its property list and adjust those properties it knows about. A Properties.PollMsg is sent to the view to get its properties. The view should return all properties it knows about. Properties can be inserted into a message's property list with the Properties.Insert procedure.
Every property describes up to 32 attributes. The known set defines which attributes are known to the view. The view may also specify which attributes are read-only in the readOnly set. The valid set finally defines which attributes currently have a defined value. For example, if in a text several characters with different sizes are selected, then the attribute size is known to the view, but currently does not have a valid value. The selection is not homogeneous, and thus there is no single valid value.
TYPE
Property = POINTER TO ABSTRACT RECORD
next-: Properties.Property;
known, readOnly, valid: SET; (* valid and readOnly are subsets of known *)
(p: Property) IntersectWith (q: Properties.Property; OUT equal: BOOLEAN), NEW, ABSTRACT
END;
A special property is Properties.StdProp. This property encompasses font attributes as well as color, and it is known to the BlackBox environment. The supported attributes are Properties.color, Properties.typeface, Properties.size, Properties.style, Properites.weight. The fields in the property record hold the corresponding values.
TYPE
StdProp = POINTER TO RECORD (Properties.Property)
color: Dialog.Color;
typeface: Fonts.Typeface;
size: INTEGER;
style: RECORD
val, mask: SET
END;
weight: INTEGER
END;
The last version of our view only support the color attribute of the standard property. If it receives a Properties.PollMsg message, it returns a Properties.StdProp object where only the color field is set, and where only the color attribute is defined as known and valid. On a Properties.SetMsg, the property list must be searched for a standard property whose color field is valid. When the color has been changed, the view must be updated in all its frames.
MODULE ObxViews6;
IMPORT Views, Ports, Properties, Controllers;
TYPE
View = POINTER TO RECORD (Views.View)
x, y: INTEGER;
c: Ports.Color
END;
PROCEDURE (v: View) Restore (f: Views.Frame; l, t, r, b: INTEGER);
BEGIN
f.DrawRect(l, t, r, b, Ports.fill, v.c);
f.DrawLine(v.x, t, v.x, b, 0, Ports.white); f.DrawLine(l, v.y, r, v.y, 0, Ports.white)
END Restore;
PROCEDURE (v: View) HandlePropMsg (VAR msg: Properties.Message);
CONST min = 5 * Ports.mm; max = 50 * Ports.mm;
VAR stdProp: Properties.StdProp; prop: Properties.Property;
BEGIN
WITH msg: Properties.SizePref DO
IF (msg.w = Views.undefined) OR (msg.h = Views.undefined) THEN
msg.w := 20 * Ports.mm; msg.h := 10 * Ports.mm
ELSE
Properties.ProportionalConstraint(2, 1, msg.fixedW, msg.fixedH, msg.w, msg.h);
IF msg.h < min THEN msg.h := min; msg.w := 2 * min
ELSIF msg.h > max THEN msg.h := max; msg.w := 2 * max
END
END
| msg: Properties.ResizePref DO
msg.horFitToWin := TRUE; msg.verFitToWin := TRUE
| msg: Properties.FocusPref DO
msg.setFocus := TRUE
| msg: Properties.PollMsg DO
NEW(stdProp);
stdProp.color.val := v.c;
stdProp.valid := {Properties.color};
stdProp.known := {Properties.color};
Properties.Insert(msg.prop, stdProp)
| msg: Properties.SetMsg DO
prop := msg.prop;
WHILE prop # NIL DO
WITH prop: Properties.StdProp DO
IF Properties.color IN prop.valid THEN v.c := prop.color.val END
ELSE
END;
prop := prop.next
END;
Views.Update(v, Views.keepFrames)
ELSE (* ignore other messages *)
END
END HandlePropMsg;
PROCEDURE (v: View) HandleCtrlMsg (f: Views.Frame; VAR msg: Controllers.Message;
VAR focus: Views.View);
VAR x, y, w, h: INTEGER; m: SET; isDown: BOOLEAN;
BEGIN
WITH msg: Controllers.PollOpsMsg DO
msg.valid := {Controllers.paste}; msg.selectable := TRUE;
msg.type := "Obx.Tutorial"
| msg: Controllers.EditMsg DO
IF msg.op = Controllers.pasteChar THEN
IF msg.char = 1DX THEN INC(v.x, Ports.mm)
ELSIF msg.char = 1CX THEN DEC(v.x, Ports.mm)
ELSIF msg.char = 1EX THEN DEC(v.y, Ports.mm)
ELSIF msg.char = 1FX THEN INC(v.y, Ports.mm)
END;
Views.Update(v, Views.keepFrames)
END
| msg: Controllers.TrackMsg DO
v.x := msg.x; v.y := msg.y; v.context.GetSize(w, h); v.Restore(f, 0, 0, w, h);
REPEAT
f.Input(x, y, m, isDown);
IF (x # v.x) OR (y # v.y) THEN
v.x := x; v.y := y; v.Restore(f, 0, 0, w, h)
END
UNTIL ~isDown;
Views.Update(v, Views.keepFrames)
| msg: Controllers.PollCursorMsg DO
msg.cursor := Ports.graphicsCursor
ELSE (* ignore other messages *)
END
END HandleCtrlMsg;
PROCEDURE Deposit*;
VAR v: View;
BEGIN
NEW(v); v.x := 0; v.y := 0; v.c := Ports.black; Views.Deposit(v)
END Deposit;
END ObxViews6.
"ObxViews6.Deposit; StdCmds.PasteView" >< set the caret here before executing the command
6.6 Model-View separation
In this section, we present a sequence of five increasingly more versatile versions of a view object which displays a string that may be typed in by the user. This string represents the view-specific data which it displays. We will see that multi-view editing is possible if this string is represented by a separate model object.
Let us start with a first version of this view, where the string is stored in the view itself. Every view displays its own string. A string's length is limited to 255 characters, but no error handling is performed in the following demonstration programs.
MODULE ObxViews10;
IMPORT Fonts, Ports, Views, Controllers, Properties;
CONST d = 20 * Ports.point;
TYPE
View = POINTER TO RECORD (Views.View)
i: INTEGER; (* position of next free slot in string *)
s: ARRAY 256 OF CHAR (* string *)
END;
PROCEDURE (v: View) Restore (f: Views.Frame; l, t, r, b: INTEGER);
BEGIN
f.DrawString(d, d, Ports.black, v.s, Fonts.dir.Default())
END Restore;
PROCEDURE (v: View) HandleCtrlMsg (f: Views.Frame;
VAR msg: Controllers.Message;
VAR focus: Views.View);
BEGIN
WITH msg: Controllers.EditMsg DO
IF msg.op = Controllers.pasteChar THEN (* accept typing *)
v.s[v.i] := msg.char; INC(v.i); v.s[v.i] := 0X; (* append character to string *)
Views.Update(v, Views.keepFrames) (* restore v in any frame that displays it *)
END
ELSE (* ignore other messages *)
END
END HandleCtrlMsg;
PROCEDURE (v:View) HandlePropMsg (VAR msg: Properties.Message);
BEGIN
WITH msg: Properties.SizePref DO
IF (msg.w = Views.undefined) OR (msg.h = Views.undefined) THEN
msg.w := 10 * d; msg.h := 2 * d
END
| msg: Properties.FocusPref DO
msg.setFocus := TRUE
ELSE
END
END HandlePropMsg;
PROCEDURE Deposit*;
VAR v: View;
BEGIN
NEW(v); v.s := ""; v.i := 0;
Views.Deposit(v)
END Deposit;
END ObxViews10.
"ObxViews10.Deposit; StdCmds.Open"
As described in the last section, a character typed in is sent to the view in the form of a controller message record (Controllers.Message), to be handled by the view's HandleCtrlMsg procedure. This procedure is called with a Controllers.EditMsg as actual parameter when a character was typed in, and it reacts by inserting the character contained in the message into its field s. Afterwards, it causes the view to be restored; i.e., wherever the view is visible on the display it is redrawn in its new state, displaying the string that has become one character longer.
In the above example, a view contains a variable state (the view's string field s). This state should be saved when the window's contents are saved to disk. For this purpose, a view provides two procedures, called Internalize and Externalize, whose uses are shown in the next iteration of our example program:
MODULE ObxViews11;
(* Same as ObxViews10, but the view's string can be stored and copied *)
IMPORT Fonts, Ports, Stores, Views, Controllers, Properties;
CONST d = 20 * Ports.point;
TYPE
View = POINTER TO RECORD (Views.View)
i: INTEGER; (* position of next free slot in string *)
s: ARRAY 256 OF CHAR (* string *)
END;
PROCEDURE (v: View) Internalize (VAR rd: Stores.Reader);
VAR version: INTEGER;
BEGIN
rd.ReadVersion(0, 0, version);
IF ~rd.cancelled THEN
rd.ReadInt(v.i); rd.ReadString(v.s)
END
END Internalize;
PROCEDURE (v: View) Externalize (VAR wr: Stores.Writer);
BEGIN
wr.WriteVersion(0);
wr.WriteInt(v.i); wr.WriteString(v.s)
END Externalize;
PROCEDURE (v: View) CopyFromSimpleView (source: Views.View);
BEGIN
WITH source: View DO
v.i := source.i; v.s := source.s
END
END CopyFromSimpleView;
PROCEDURE (v: View) Restore (f: Views.Frame; l, t, r, b: INTEGER);
BEGIN
f.DrawString(d, d, Ports.black, v.s, Fonts.dir.Default())
END Restore;
PROCEDURE (v: View) HandleCtrlMsg (f: Views.Frame;
VAR msg: Controllers.Message;
VAR focus: Views.View);
BEGIN
WITH msg: Controllers.EditMsg DO
IF msg.op = Controllers.pasteChar THEN (* accept typing *)
v.s[v.i] := msg.char; INC(v.i); v.s[v.i] := 0X; (* append character to string *)
Views.SetDirty(v); (* mark view's document as dirty *)
Views.Update(v, Views.keepFrames) (* restore v in any frame that displays it *)
END
ELSE (* ignore other messages *)
END
END HandleCtrlMsg;
PROCEDURE (v:View) HandlePropMsg (VAR msg: Properties.Message);
BEGIN
WITH msg: Properties.SizePref DO
IF (msg.w = Views.undefined) OR (msg.h = Views.undefined) THEN
msg.w := 10 * d; msg.h := 2 * d
END
| msg: Properties.FocusPref DO
msg.setFocus := TRUE
ELSE
END
END HandlePropMsg;
PROCEDURE Deposit*;
VAR v: View;
BEGIN
NEW(v); v.s := ""; v.i := 0;
Views.Deposit(v)
END Deposit;
END ObxViews11.
A few comments about View.Internalize and View.Externalize are in order here: First, the two procedures have a reader, respectively a writer, as variable parameters. These file mappers are set up by BlackBox itself; a view simply uses them.
Second, View.Internalize must read exactly the same (amount of) data that View.Externalize has written.
Third, a user interface typically defines some visual distinction for documents that contain modified views, i.e., for "dirty" documents. Or it may require that when the user closes a dirty document, he or she should be asked whether to save it or not. In order to make this possible, a view must tell when its contents has been modified. This is done by the Views.BeginModification /Views.EndModification calls.
In addition to View.Internalize and View.Externalize, the above view implementation also implements a CopyFromSimpleView procedure. Such a procedure should copy the view's contents, given a source view of the same type. CopyFromSimpleView should usually have the same effect as if the source's contents were externalized on a temporary file, and then internalized again by the destination view. There can be exceptions, though. For example, a text copies even temporary embedded views such as error markers, but it doesn't externalize them.
A view that contains (mutable) state should implement CopyFromSimpleView, so that it can be printed. The reason that this is necessary is that the framework makes a shallow copy of a view that is being printed, in order to avoid the original view to be changed by pagination, scrolling, or similar modifications that may be performed during printing.
Basically, ObxViews11 has shown most of what is involved in implementing a simple view class. Such simple views are often sufficient; thus it is important that they are easy to implement. However, there are cases where a more advanced view design is in order. In particular, if a window normally can only display a small part of a view's contents, multi-view editing should be supported.
Multi-view editing means that there may be several views showing the same data. The typical application of this feature is to have two or more windows displaying the same document, each of these windows showing a different part of it in its own view. Thus, if a view's data has been changed, it and all the other affected views must be notified of the change, such that they can update the display accordingly.
The following sample program, which is the same as the previous one except that it supports multi-view editing, is roughly twice as long. This indicates that the design and implementation of such views is quite a bit more involved than that of simple views. It is a major design decision whether this additional complexity is warranted by its increased convenience.
MODULE ObxViews12;
(* Same as ObxViews11, but uses a separate model for the string *)
IMPORT Fonts, Ports, Stores, Models, Views, Controllers, Properties;
CONST d = 20 * Ports.point;
TYPE
Model = POINTER TO RECORD (Models.Model)
i: INTEGER; (* position of next free slot in string *)
s: ARRAY 256 OF CHAR (* string *)
END;
View = POINTER TO RECORD (Views.View)
model: Model
END;
(* Model *)
PROCEDURE (m: Model) Internalize (VAR rd: Stores.Reader);
VAR version: INTEGER;
BEGIN
rd.ReadVersion(0, 0, version);
IF ~rd.cancelled THEN
rd.ReadInt(m.i); rd.ReadString(m.s)
END
END Internalize;
PROCEDURE (m: Model) Externalize (VAR wr: Stores.Writer);
BEGIN
wr.WriteVersion(0);
wr.WriteInt(m.i); wr.WriteString(m.s)
END Externalize;
PROCEDURE (m: Model) CopyFrom (source: Stores.Store);
BEGIN
WITH source: Model DO
m.i := source.i; m.s := source.s
END
END CopyFrom;
(* View *)
PROCEDURE (v: View) Internalize (VAR rd: Stores.Reader);
VAR version: INTEGER; st: Stores.Store;
BEGIN
rd.ReadVersion(0, 0, version);
IF ~rd.cancelled THEN
rd.ReadStore(st);
v.model := st(Model)
END
END Internalize;
PROCEDURE (v: View) Externalize (VAR wr: Stores.Writer);
BEGIN
wr.WriteVersion(0);
wr.WriteStore(v.model)
END Externalize;
PROCEDURE (v: View) CopyFromModelView (source: Views.View;
model: Models.Model);
BEGIN
v.model := model(Model)
END CopyFromModelView;
PROCEDURE (v: View) Restore (f: Views.Frame; l, t, r, b: INTEGER);
BEGIN
f.DrawString(d, d, Ports.black, v.model.s, Fonts.dir.Default())
END Restore;
PROCEDURE (v: View) ThisModel (): Models.Model;
BEGIN
RETURN v.model
END ThisModel;
PROCEDURE (v: View) HandleModelMsg (VAR msg: Models.Message);
BEGIN
Views.Update(v, Views.keepFrames) (* restore v in any frame that displays it *)
END HandleModelMsg;
PROCEDURE (v: View) HandleCtrlMsg (f: Views.Frame;
VAR msg: Controllers.Message;
VAR focus: Views.View);
VAR m: Model; umsg: Models.UpdateMsg;
BEGIN
WITH msg: Controllers.EditMsg DO
IF msg.op = Controllers.pasteChar THEN
m := v.model;
m.s[m.i] := msg.char; INC(m.i);
m.s[m.i] := 0X; (* append character to string *)
Views.SetDirty(v); (* mark view's document as dirty *)
Models.Broadcast(m, umsg) (* update all views on this model *)
END
ELSE (* ignore other messages *)
END
END HandleCtrlMsg;
PROCEDURE (v:View) HandlePropMsg (VAR msg: Properties.Message);
BEGIN
WITH msg: Properties.SizePref DO
IF (msg.w = Views.undefined) OR (msg.h = Views.undefined) THEN
msg.w := 10 * d; msg.h := 2 * d
END
| msg: Properties.FocusPref DO
msg.setFocus := TRUE
ELSE
END
END HandlePropMsg;
PROCEDURE Deposit*;
VAR v: View; m: Model;
BEGIN
NEW(m); m.i := 0; m.s := "";
NEW(v); v.model := m; Stores.Join(v, m);
Views.Deposit(v)
END Deposit;
END ObxViews12.
"ObxViews12.Deposit; StdCmds.Open"
Multi-view editing is realized by factoring out the view's data into a separate data structure, called a model. This model is shared between all its views, i.e., each such view contains a pointer to the model:
Figure 6.2: Two Views on one Model
A model is, like a view, an extension of a Stores.Store, which is the base type for all persistent objects. Stores define the Internalize and Externalize procedures we've already met for a view. In ObxViews12, the model stores the string and its length, while the view stores the whole model! For this purpose, a Stores.Writer provides a WriteStore and a Stores.Reader provides a ReadStore procedure.
Stores may form arbitrary graphs. For example, one or several views may refer to the same model, both models and views are store extensions. A graph of stores that may be saved in a file is called a document. In order to recognize the boundary of a document upon externalization, stores are bound to a domain. All stores of a document refer to the same domain object (Stores.Domain).
Domains are also used as containers for operations, i.e., commands performed on some store which can be undone and redone (see next chapter). The operation history is associated with a domain. Furthermore, domains define the set of objects which get notified in a broadcast (either Views.Broadcast, Views.Domaincast or Models.Broadcast).
For more information on stores and domains, see the on-line documentation of module Stores.
Now that the model is separated from the view, copying is done by the model, not by the view anymore.
View.ThisModel returns the model of the view. Its default implementation returns NIL, which should be overridden in views that contain models. This procedure is used by the framework to find all views that display a given model, in order to implement model broadcasts, as described in the next paragraph.
Views with a model implement the procedure View.CopyFromModelView instead of View.CopyFromSimpleView. Like Internalize and Externalize, CopyFromSimpleView and CopyFromModelView are exported as implement-only procedures, i.e., they can only be implemented, but not called. They are called internally in module Views, in its CopyOf and CopyWithNewModel functions.
When a model changes, all views displaying it must be updated. For this purpose, a model broadcast is generated: A model broadcast notifies all views which display a particular model about a model modification that has happened. This gives each view the opportunity to restore its contents on the screen. A model broadcast is generated in the View.HandleCtrlMsg procedure by calling Models.Broadcast. The message is received by every view which contains the correct model, via its View.HandleModelMsg procedure.
This indirection becomes important if different types of views display the same model, e.g., a tabular view and a graphical view on a spreadsheet model; and if instead of restoring the whole view as has been done in our examples only the necessary parts of the views are restored. These necessary parts may be completely different for different types of views.
A very sophisticated model may be able to contain ("embed") arbitrary views as part of its contents. For example, a text view may display a text model which contains not only characters (its intrinsic contents), but also graphical or other views flowing along in the text stream.
The combination of multi-view editing and hierarchical view embedding can lead to the following situation, where two text views show the same text model, which in turn contains a graphics view. Each text view lives in its own window and thus has its own frame. The graphics view is unique however, since it is embedded in the text model, which is shared by both views. Nevertheless the graphics can be visible in both text views simultaneously, and thus there can be two frames for this one view:
Figure 6-3: Two Frames on one View
As a consequence, one and the same view may be visible in several places on the screen simultaneously. In this case, this means that when the view has changed, several places must be updated: the view must restore the necessary area once for every frame on this view. As a consequence, a notification mechanism must exist which lets the view update each of its frames. This is done in a similar way as the notification mechanism for model changes: with a view broadcast. Fortunately, there is a standard update mechanism in the framework which automatically handles this second broadcast level (see below).
We now can summarize the typical events that occur when a user interacts with a view:
Controller message handling:
1) Some controller message is sent to the focus view.
2) The focus view interprets the message and changes its model accordingly.
3) The model broadcasts a model message, describing the change that has been performed.
Model message handling:
4) Every view on this model receives the model message.
5) It determines how its display should change because of this model modification.
6) It broadcasts a view message, describing how its display should change.
View message handling:
7) The view receives the view notification message once for every frame on this view.
8) Every time, the view redraws the frame contents according to the view message.
This mechanism is fundamental to the BlackBox Component Framework. If you have understood it, you have mastered the most complicated part of a view implementation. Interpreting the various controller messages, which are defined in module Controllers, is more a matter of diligence than of understanding difficult new concepts. Moreover, you only need to interpret the controller messages in which you are interested, because messages that are not relevant can simply be ignored.
Usually, steps 6, 7, and 8 are handled automatically by the framework: the view merely calls Views.Update if a whole view should be updated, or Views.UpdateIn if some rectangular part of the view should be updated. Calls of these update procedures cause a lazy update, i.e., the framework adds up the region to be updated, but does not immediately cause any redrawing. Instead, the command first runs to completion, so that all data structures of the modified views are consistent again. Only the display of the views is still the same as before the command. But then the framework restores all views that have been marked for update. This means that for every frame that displays a view, the view's Restore method is called with this frame as argument. If the view is displayed in two (or more) frames in different windows, it is restored two (or more) times; once for every frame. When the framework starts restoring frames of a window, it temporarily redirects the drawing operations of a port into a background pixelmap buffer. When all frames of this window that need updating have been restored, the framework copies the pixelmap buffer to the screen pixelmap, and turns off the redirection of drawing operations.
The effect of this buffering mechanism and of the lazy update mechanism is that minimal flickering occurs. The lazy update mechanism means that even for complex editing operations, a given screen region is only restored once. This can reduce flickering, since flickering can occur when the same area is drawn several times in rapid succession. The buffering mechanism reduces flickering if drawing occurs in layers, from "bottom" to "top" (because this also means drawing several time in rapid succession). For example, you may first draw the background in one color, and then the a filled rectangle on top of it in another color. Thanks to the buffering mechanism, the user never sees the situation after the background is drawn, but before the rectangle is drawn.
The lazy update mechanism also has another advantage: it completely decouples the modification of a model from its drawing. Without this mechanism, it can become rather difficult to correctly perform screen updates for complex editing operations. For example, consider moving a selection of graphics objects in a graphics editor. The selected objects first must be deleted at their old position, this may mean that other objects that have been obscured by the selection now need to be drawn (but not the selected objects themselves!). Then the objects' positions are changed, and then they are redrawn at their new positions (if the source and target positions overlap, drawing has now happened twice). Drawing may have to be done several times, if there are several windows displaying the same data. But of course the change of object positions must only occur once. It is much less tricky to simply call Views.UpdateIn for all rectangles that (may) need updating, and to let the framework call the necessary Restore methods later!
Normally, the lazy update mechanism is sufficient. Thus a view programmer needs to use explicit view messages only if no complete restore in all frames of a view is desired. This is the case only for marks like selection, focus, or carets, or for rubberbanding or similar feedback effects during mouse tracking. Such marks can sometimes be handled more efficiently because they are involutory: applied twice, they have no effect. Thus marks are often switched on and off through custom view messages during a command, not through the delaying lazy update mechanism. But except for such light-weight marks, you should always use the lazy update mechanism described above. Note that there exists a method Ports.Frame.MarkRect explicitly for drawing such marks.
6.7 Operations
Now that we have seen the crucial ingredients of a view implementation, a less central feature can be presented. The next program is a variation of the above one, in which a controller message is not interpreted directly. Instead, an operation object is created and then executed. An operation provides a do / undo / redo capability, as shown in the program below.
The operation we define in this example is the PasteCharOp. The operation's Do procedure performs the desired modification, and must be involutory, i.e. when called twice, its effect must have been neutralized again. We use the flag PasteCharOp.do to specify whether the character PasteCharOp.char has to be inserted into or removed from the model PasteCharOp.m. In any case, the Do procedure has to update all views on the model PasteCharOp.m with a model broadcast.
The procedure NewPasteCharOp generates a new operation and the procedure Models.Do executes this operation, i.e., the operation's Do procedure is called and the operation is recorded for a later undo. The name of the operation as specified in the Models.Do command will appear in the Edit menu after the Undo or Redo entry respectively.
MODULE ObxViews13;
(* Same as ObxViews12, but generate undoable operations for character insertion *)
IMPORT Fonts, Ports, Stores, Models, Views, Controllers, Properties;
CONST d = 20 * Ports.point;
TYPE
Model = POINTER TO RECORD (Models.Model)
i: INTEGER; (* position of next free slot in string *)
s: ARRAY 256 OF CHAR (* string *)
END;
View = POINTER TO RECORD (Views.View)
model: Model
END;
PasteCharOp = POINTER TO RECORD (Stores.Operation)
model: Model;
char: CHAR;
do: BOOLEAN
END;
(* PasteCharOp *)
PROCEDURE (op: PasteCharOp) Do;
VAR m: Model; msg: Models.UpdateMsg;
BEGIN
m := op.model;
IF op.do THEN (* do operation's transformation *)
m.s[m.i] := op.char; INC(m.i) (* insert character into string *)
ELSE (* undo operation's transformation *)
DEC(m.i) (* remove character from string *)
END;
m.s[m.i] := 0X;
op.do := ~op.do; (* toggle between "do" and "undo" *)
Models.Broadcast(m, msg) (* update all views on this model *)
END Do;
PROCEDURE NewPasteCharOp (m: Model; char: CHAR): PasteCharOp;
VAR op: PasteCharOp;
BEGIN
NEW(op); op.model := m; op.char := char; op.do := TRUE;
RETURN op
END NewPasteCharOp;
(* Model *)
PROCEDURE (m: Model) Internalize (VAR rd: Stores.Reader);
VAR version: INTEGER;
BEGIN
rd.ReadVersion(0, 0, version);
IF ~rd.cancelled THEN
rd.ReadInt(m.i); rd.ReadString(m.s)
END
END Internalize;
PROCEDURE (m: Model) Externalize (VAR wr: Stores.Writer);
BEGIN
wr.WriteVersion(0);
wr.WriteInt(m.i); wr.WriteString(m.s)
END Externalize;
PROCEDURE (m: Model) CopyFrom (source: Stores.Store);
BEGIN
WITH source: Model DO
m.i := source.i; m.s := source.s
END
END CopyFrom;
(* View *)
PROCEDURE (v: View) Internalize (VAR rd: Stores.Reader);
VAR version: INTEGER; st: Stores.Store;
BEGIN
rd.ReadVersion(0, 0, version);
IF ~rd.cancelled THEN
rd.ReadStore(st);
v.model := st(Model)
END
END Internalize;
PROCEDURE (v: View) Externalize (VAR wr: Stores.Writer);
BEGIN
wr.WriteVersion(0);
wr.WriteStore(v.model)
END Externalize;
PROCEDURE (v: View) CopyFromModelView (source: Views.View; model: Models.Model);
BEGIN
v.model := model(Model)
END CopyFromModelView;
PROCEDURE (v: View) Restore (f: Views.Frame; l, t, r, b: INTEGER);
BEGIN
f.DrawString(d, d, Ports.black, v.model.s, Fonts.dir.Default())
END Restore;
PROCEDURE (v: View) ThisModel (): Models.Model;
BEGIN
RETURN v.model
END ThisModel;
PROCEDURE (v: View) HandleModelMsg (VAR msg: Models.Message);
BEGIN
Views.Update(v, Views.keepFrames) (* restore v in any frame that displays it *)
END HandleModelMsg;
PROCEDURE (v: View) HandleCtrlMsg (f: Views.Frame; VAR msg: Controllers.Message;
VAR focus: Views.View);
VAR op: Stores.Operation;
BEGIN
WITH msg: Controllers.EditMsg DO
IF msg.op = Controllers.pasteChar THEN
op := NewPasteCharOp(v.model, msg.char); (* generate operation *)
Models.Do(v.model, "Typing", op) (* execute operation *)
END
ELSE (* ignore other messages *)
END
END HandleCtrlMsg;
PROCEDURE (v:View) HandlePropMsg (VAR msg: Properties.Message);
BEGIN
WITH msg: Properties.SizePref DO
IF (msg.w = Views.undefined) OR (msg.h = Views.undefined) THEN
msg.w := 10 * d; msg.h := 2 * d
END
| msg: Properties.FocusPref DO
msg.setFocus := TRUE
ELSE
END
END HandlePropMsg;
PROCEDURE Deposit*;
VAR v: View; m: Model;
BEGIN
NEW(m); m.i := 0; m.s := "";
NEW(v); v.model := m; Stores.Join(v, m);
Views.Deposit(v)
END Deposit;
END ObxViews13.
"ObxViews13.Deposit; StdCmds.Open"
Further examples which use the undo/redo mechanism through operations can be found e.g. in ObxOmosi or ObxLines.
6.8 Separation of interface and implementation
As a last version of our sample view, we modify the previous variant by exporting the Model and View types, and by separating interface and implementation of these two types. In order to do the latter, so-called directory objects are introduced, which generate (hidden) default implementations of abstract data types. A user now might implement its own version of the abstract type and offer it through its own directory object, however he can not inherit from the default implementation and thus avoids the fragile base class problem.
Real BlackBox subsystems would additionally split the module into two modules, one for the model and one for the view. A third module with commands might be introduced, if the number and complexity of commands warrant it (e.g., TextModels, TextViews, and TextCmds). Even more complicated views would further split views into views and controllers, each in its own module.
MODULE ObxViews14;
(* Same as ObxViews13, but interfaces and implementations separated, and operation directly in Insert procedure *)
IMPORT Fonts, Ports, Stores, Models, Views, Controllers, Properties;
CONST d = 20 * Ports.point;
TYPE
Model* = POINTER TO ABSTRACT RECORD (Models.Model) END;
ModelDirectory* = POINTER TO ABSTRACT RECORD END;
View* = POINTER TO ABSTRACT RECORD (Views.View) END;
Directory* = POINTER TO ABSTRACT RECORD END;
StdModel = POINTER TO RECORD (Model)
i: INTEGER; (* position of next free slot in string *)
s: ARRAY 256 OF CHAR (* string *)
END;
StdModelDirectory = POINTER TO RECORD (ModelDirectory) END;
StdView = POINTER TO RECORD (View)
model: Model
END;
StdDirectory = POINTER TO RECORD (Directory) END;
PasteCharOp = POINTER TO RECORD (Stores.Operation)
model: StdModel;
char: CHAR;
do: BOOLEAN
END;
VAR
mdir-: ModelDirectory;
dir-: Directory;
(* Model *)
PROCEDURE (m: Model) Insert* (char: CHAR), NEW, ABSTRACT;
PROCEDURE (m: Model) Remove*, NEW, ABSTRACT;
PROCEDURE (m: Model) GetString* (OUT s: ARRAY OF CHAR), NEW, ABSTRACT;
(* ModelDirectory *)
PROCEDURE (d: ModelDirectory) New* (): Model, NEW, ABSTRACT;
(* PasteCharOp *)
PROCEDURE (op: PasteCharOp) Do;
VAR m: StdModel; msg: Models.UpdateMsg;
BEGIN
m := op.model;
IF op.do THEN (* do operation's transformation *)
m.s[m.i] := op.char; INC(m.i);
ELSE (* undo operation's transformation *)
DEC(m.i) (* remove character from string *)
END;
m.s[m.i] := 0X;
op.do := ~op.do; (* toggle between "do" and "undo" *)
Models.Broadcast(m, msg) (* update all views on this model *)
END Do;
(* StdModel *)
PROCEDURE (m: StdModel) Internalize (VAR rd: Stores.Reader);
VAR version: INTEGER;
BEGIN
rd.ReadVersion(0, 0, version);
IF ~rd.cancelled THEN
rd.ReadInt(m.i); rd.ReadString(m.s)
END
END Internalize;
PROCEDURE (m: StdModel) Externalize (VAR wr: Stores.Writer);
BEGIN
wr.WriteVersion(0);
wr.WriteInt(m.i); wr.WriteString(m.s)
END Externalize;
PROCEDURE (m: StdModel) CopyFrom (source: Stores.Store);
BEGIN
WITH source: StdModel DO
m.i := source.i; m.s := source.s
END
END CopyFrom;
PROCEDURE (m: StdModel) Insert (char: CHAR);
VAR op: PasteCharOp;
BEGIN
NEW(op); op.model := m; op.char := char; op.do := TRUE;
Models.Do(m, "insertion", op)
END Insert;
PROCEDURE (m: StdModel) Remove;
VAR msg: Models.UpdateMsg;
BEGIN
DEC(m.i); m.s[m.i] := 0X;
Models.Broadcast(m, msg) (* update all views on this model *)
END Remove;
PROCEDURE (m: StdModel) GetString (OUT s: ARRAY OF CHAR);
BEGIN
s := m.s$
END GetString;
(* StdModelDirectory *)
PROCEDURE (d: StdModelDirectory) New (): Model;
VAR m: StdModel;
BEGIN
NEW(m); m.s := ""; m.i := 0; RETURN m
END New;
(* Directory *)
PROCEDURE (d: Directory) New* (m: Model): View, NEW, ABSTRACT;
(* StdView *)
PROCEDURE (v: StdView) Internalize (VAR rd: Stores.Reader);
VAR version: INTEGER; st: Stores.Store;
BEGIN
rd.ReadVersion(0, 0, version);
IF ~rd.cancelled THEN
rd.ReadStore(st);
IF st IS Model THEN
v.model := st(Model)
ELSE
(* concrete model implementation couldn't be loaded->
an alien store was created *)
rd.TurnIntoAlien(Stores.alienComponent)
(* internalization of v is cancelled *)
END
END
END Internalize;
PROCEDURE (v: StdView) Externalize (VAR wr: Stores.Writer);
BEGIN
wr.WriteVersion(0);
wr.WriteStore(v.model)
END Externalize;
PROCEDURE (v: StdView) CopyFromModelView (source: Views.View; model: Models.Model);
BEGIN
WITH source: StdView DO
v.model := model(Model)
END
END CopyFromModelView;
PROCEDURE (v: StdView) Restore (f: Views.Frame; l, t, r, b: INTEGER);
VAR s: ARRAY 256 OF CHAR;
BEGIN
v.model.GetString(s);
f.DrawString(d, d, Ports.black, s, Fonts.dir.Default())
END Restore;
PROCEDURE (v: StdView) ThisModel (): Models.Model;
BEGIN
RETURN v.model
END ThisModel;
PROCEDURE (v: StdView) HandleModelMsg (VAR msg: Models.Message);
BEGIN
Views.Update(v, Views.keepFrames) (* restore v in any frame that displays it *)
END HandleModelMsg;
PROCEDURE (v: StdView) HandleCtrlMsg (f: Views.Frame;
VAR msg: Controllers.Message;
VAR focus: Views.View);
BEGIN
WITH msg: Controllers.EditMsg DO
IF msg.op = Controllers.pasteChar THEN
v.model.Insert(msg.char) (* undoable insertion *)
END
ELSE (* ignore other messages *)
END
END HandleCtrlMsg;
PROCEDURE (v:StdView) HandlePropMsg (VAR msg: Properties.Message);
BEGIN
WITH msg: Properties.SizePref DO
IF (msg.w = Views.undefined) OR (msg.h = Views.undefined) THEN
msg.w := 10 * d; msg.h := 2 *d
END
| msg: Properties.FocusPref DO
msg.setFocus := TRUE
ELSE
END
END HandlePropMsg;
(* StdDirectory *)
PROCEDURE (d: StdDirectory) New* (m: Model): View;
VAR v: StdView;
BEGIN
ASSERT(m # NIL, 20);
NEW(v); v.model := m; Stores.Join(v, m);
RETURN v
END New;
PROCEDURE Deposit*;
VAR v: View;
BEGIN
v := dir.New(mdir.New());
Views.Deposit(v)
END Deposit;
PROCEDURE SetModelDir* (d: ModelDirectory);
BEGIN
ASSERT(d # NIL, 20);
mdir := d
END SetModelDir;
PROCEDURE SetDir* (d: Directory);
BEGIN
ASSERT(d # NIL, 20);
dir := d
END SetDir;
PROCEDURE Init;
VAR md: StdModelDirectory; d: StdDirectory;
BEGIN
NEW(md); mdir := md;
NEW(d); dir := d
END Init;
BEGIN
Init
END ObxViews14.
"ObxViews14.Deposit; StdCmds.Open"
A simple example of a BlackBox module which follows this design is DevMarkers. The marker views are simple views without a model, therefore only a directory object to generate new views is offered. The second directory object DevMarkers.stdDir keeps the standard implementation provided by this module. It might be used to install back the default implementation or to reuse the default implementation (as an instance) in another component.
The separation of a type's definition from its implementation is recommended in the design of new BlackBox subsystems. However, simple view types which won't become publicly available or which are not meant to be extended can certainly dispense with this additional effort.
Note that the subsystem wizard (menu item Tools->Create Subsystem...) helps to generate templates for the different kinds of view. In particular, it is possible to generate separate model and view modules. The tool uses the template texts stored in Dev/Rsrc/New. You may want to study the files Models5, Views5, and Cmds5 in this directory.
Table of Contents ↑ | Docu/Tut-6.odc |
Appendix A:
A Brief History of Pascal
Algol
The language Component Pascal is the culmination of several decades of research. It is the youngest member of the Algol family of languages. Algol, defined in 1960, was the first high-level language with a readable, structured, and systematically defined syntax. While successful as a notation for mathematical algorithms, it lacked important data types, such as pointers or characters.
Pascal
In the late sixties, several proposals for an evolutionary successor to Algol were developed. The most successful one was Pascal, defined in 1970 by Prof. Niklaus Wirth at ETH Zrich, the Swiss Federal Institute of Technology. Besides cleaning up or leaving out some of Algol's more obscure features, Pascal added the capability to define new data types out of simpler existing ones. Pascal also supported dynamic data structures; i.e., data structures which can grow and shrink while a program is running. Pascal received a big boost when ETH released a Pascal compiler that produced a simple intermediate code for a virtual machine (P-code), instead of true native code for a particular machine. This simplified porting Pascal to other processor architectures considerably, because only a new P-code interpreter needed be written for this purpose, not a whole new compiler. One of these projects had been undertaken at the University of California, San Diego. Remarkably, this implementation (UCSD Pascal) didn't require a large and expensive mainframe computer, it ran on the then new Apple II personal computers. This gave Pascal a second important boost. The third one came when Borland released TurboPascal, a fast and inexpensive compiler, and integrated development environment for the IBM PC. Later, Borland revived its version of Pascal when it introduced the rapid application development environment Delphi.
Pascal has greatly influenced the design and evolution of many other languages, from Ada to Visual Basic.
Modula-2
In the mid-seventies, inspired by a sabbatical at the Xerox Palo Alto Research Center PARC, Wirth started a project to develop a new workstation computer. This workstation should be completely programmable in a high-level language, thus the language had to provide direct access to the underlying hardware. Furthermore, it had to support team programming and modern software engineering principles, such as abstract data types. These requirements led to the programming language Modula-2 (1979). Modula-2 retained the successful features of Pascal, and added a module system as well as a controlled way to circumvent the language's type system when doing low-level programming; e.g., when implementing device drivers. Modules could be added to the operating system at run-time. In fact, the whole operating system consisted of a collection of modules, without a distinguished kernel or similar artefact. Modules could be compiled and loaded separately, with complete type and version checking of their interfaces.
Modula-2 has made inroads in particular into safety-critical areas, such as traffic control systems.
Simula, Smalltalk, and Cedar
Wirth's interest remained with desktop computers, however, and again an important impulse came from Xerox PARC. PARC was the place where the workstation, the laser printer, the local area network, the bitmap display, and many other enabling technologies have been invented. Also, PARC adopted and made popular several older and barely known technologies, like the mouse, interactive graphics, and object-oriented programming. The latter concept, if not the term, was first applied to a high-level language in Simula (1966), another member of the Algol language family. As its name suggests, Simula used object-orientation primarily for simulation purposes. Xerox PARC's Smalltalk language (1983), however, used it for about anything. The Smalltalk project broke new ground also in user interface design: the graphical user interface (GUI) as we know it today was developed for the Smalltalk system.
At PARC, these ideas influenced other projects, e.g., the Cedar language, a Pascal-style language. Like Smalltalk and later Oberon, Cedar was not only the name of a language but also of an operating system. The Cedar operating system was impressive and powerful, but also complex and unstable.
Oberon
The Oberon project was initiated in 1985 at ETH by Wirth and his colleague Jrg Gutknecht. It was an attempt to distill the essence of Cedar into a comprehensive, but still comprehensible, workstation operating system. The resulting system became very small and efficient, working well with only 2 MB of RAM and 10 MB of disk space. An important reason for the small size of the Oberon system was its component-oriented design: instead of integrating all desirable features into one monolithic software colossus, the less frequently used software components (modules) could be implemented as extensions of the core system. Such components were only loaded when they were actually needed, and they could be shared by all applications.
Wirth realized that component-oriented programming required some features of object-oriented programming, such as information hiding, late binding, and polymorphism.
Information hiding was the great strength of Modula-2. Late binding was supported by Modula-2 in the form of procedure variables. However, polymorphism was lacking. For this reason, Wirth added type extension: a record type could be declared as an extension of another record type. An extended type could be used wherever one of its base types might be used.
But component-oriented programming is more than object-oriented programming. In a component-based system, a component may share its data structures with arbitrary other components, about which it doesn't know anything. These components usually don't know about each other's existence either. Such mutual ignorance makes the management of dynamic data structures, in particular the correct deallocation of unused memory, a fundamentally more difficult problem than in closed software systems. Consequently, it must be left to the language implementation to find out when memory is not used anymore, in order to safely reclaim it for later use. A system service which performs such an automatic storage reclamation is called a garbage collector. Garbage collection prevents two of the most evasive and downright dangerous programming errors: memory leaks (not giving free unused memory) and dangling pointers (releasing memory too early). Dangling pointers let one component destroy data structures that belong to other components. Such a violation of type safety must be prevented, because component-based systems may contain many third-party components of unknown quality (e.g., downloaded from the Internet).
While Algol-family languages always had a reputation of being safe, complete type safety (and thus garbage collection) still was a quantum leap forward. It also was the reason why complete compatibility with Modula-2 was not possible. The resulting revision of Modula-2 was called the same way as the system: Oberon.
Oberon's module system, like the one of Modula-2, provided information hiding for entire collections of types, not only for individual objects. This allowed to define and guarantee invariants spanning several cooperating objects. In other words: it allowed developers to invent higher-level safety mechanisms, by building on the basic module safety and type safety provided by a good Oberon implementation.
Orthodox object-oriented programming languages such as Smalltalk had neglected both typing (by not supporting types) and information hiding (by restricting it to objects and classes), which was a major step backwards as far as software engineering is concerned. Oberon reconciled the worlds of object-oriented and modular programming.
As a final requirement of component-oriented programming, it had to be possible to dynamically load new components. In Oberon, the unit of loading was the same as the unit of compilation: a module.
Component Pascal
In 1992, a cooperation with Prof. H. P. Mssenbck led to a few additions to the original Oberon language ("Oberon-2"). It became the de-facto standard of the language.
In 1997, the ETH spin-off Oberon microsystems, Inc. (with Wirth on its board of directors) made some small extensions to Oberon-2 and called it Component Pascal, to better express its focus (component-oriented programming) and its origin (Pascal). It is the industrial-strength version of Oberon, so to say.
The main thrust of the enhancements compared to Oberon-2 was to give the designer of a framework (i.e., of module interfaces that define abstract classes for a particular problem domain) more control over the framework's custom safety properties. The benefit is that it becomes easier to ascertain the integrity of a large component-based system, which is particularly important during iterative design cycles when the framework is being developed, and later when the system architecture must be refactored to enable further evolution and maintenance.
BlackBox
Oberon microsystems developed the BlackBox Component Framework starting in 1992 (originally it was called Oberon/F). This component-oriented framework is written in Component Pascal, and simplifies the development of graphical user interface components. It comes bundled with several BlackBox extension components, including a word processor, a visual designer, an SQL database access facility, an integrated development environment, and the Component Pascal run-time system. The complete package is an advanced yet light-weight rapid application development (RAD) tool for components, called BlackBox Component Builder. It is light-weight because it is completely built out of Component Pascal modules – including the kernel with the garbage collector, and the Component Pascal compiler itself. | Docu/Tut-A.odc |
Appendix B:
Differences between Pascal and Component Pascal
Eliminated Features
• Subrange types
Use a standard integer type instead.
• Enumeration types
Use integer constants instead.
• Arbitrary array ranges
Arrays are always defined over the integer range 0..length-1.
Example
A = ARRAY 16 OF INTEGER (* legal indices are in the range 0..15 *)
• No general sets
Type SET denotes the integer set which may include the elements 0..31.
• No explicit DISPOSE
Memory is reclaimed automatically by the garbage collector.
Instead of calling DISPOSE, simply set the variable to NIL.
• No variant records
Use record extension instead.
• No packed structures
Use SHORTCHAR or BYTE types for byte-sized values.
• No GOTO
• No PRED and SUCC standard functions
Use DEC or INC on integer values instead.
• No built-in input/output facilities
No file types. I/O is provided by library routines.
Changed Features
• Standard procedure ENTIER instead of ROUND
• Syntax for REAL constants
3.0E+4 but not 3.0e+4
• Syntax for pointer type declarations
P = POINTER TO R
instead of
P = ^R
• Syntax for case statement
"|" instead of ";" as case separator.
ELSE clause.
Example
CASE i * 3 - 1 OF
0: StdLog.String("zero")
| 1..9: StdLog.String("one to nine")
| 10, 20: StdLog.String("ten or twenty")
ELSE StdLog.String("something else")
END
• Procedure name must be repeated
Example
PROCEDURE DrawDot (x, y: INTEGER);
BEGIN
END DrawDot;
• Case is significant
Small letters are distinguished from capital letters.
Example "proc" is not the same as "Proc".
• String syntax
String literals are either enclosed between " or between '.
There cannot be both single and double quotes in one string.
String literals of length one are assignment-compatible to character variables.
Examples
"That's great" 'Write "hello world" to the screen'
ch := "x"
ch := 'x'
• Comments
Comments are enclosed between (* and *) and may be nested.
• Set brackets
Set constants are given between { and } instead of [ and ].
Example {0..2, 4, j..2 * k}
• Function syntax
Use keyword PROCEDURE for functions also, instead of FUNCTION.
Procedures with a return value always have a (possibly empty) parameter list in their declarations and in calls to them.
The function result is returned explicitly by a RETURN statement, instead of an assignment to the function name.
Example
PROCEDURE Fun (): INTEGER;
BEGIN
RETURN 5
END Fun;
instead of
FUNCTION Fun: INTEGER;
BEGIN
Fun := 5
END;
n := Fun() instead of n := Fun
• Declarations
The sequence of declarations is
{ ConstDecl | TypeDecl | VarDecl} {ProcDecl | ForwardDecl}
instead of
[ConstDecl] [TypeDecl] [VarDecl] {ProcDecl}.
Forward declarations are necessary if a procedure is used before it is defined.
Example
PROCEDURE ^ Proc;
instead of
PROCEDURE Proc; FORWARD;
• Procedure types
Procedures may not only be passed to parameters, but also to procedure-typed variables.
Example
TYPE P = PROCEDURE (x, y: INTEGER);
VAR v: P;
v := DrawDot; (* assign *)
v(3, 5); (* call DrawDot(3, 5) *)
• Explicit END instead of compound statement
BEGIN can only occur before a statement sequence, but not in it. IF, WHILE, and LOOP are always terminated by END.
• WITH statement
A WITH statement is a regional type guard, it does not imply a hidden variable and does not open a new scope. See language reference for more details.
• ELSIF
IF statements can have several branches.
Example
IF name = "top" THEN
StdLog.Int(0)
ELSIF name = "bottom" THEN
StdLog.Int(1)
ELSIF name = " charm" THEN
StdLog.Int(2)
ELSIF name = "beauty" THEN
StdLog.Int(3)
ELSE
StdLog.String("strange")
END
• BY instead of only DOWNTO in FOR
FOR loops may use any constant value as increment or decrement.
Example
FOR i := 15 TO 0 BY -1 DO StdLog.Int(i, 0) END
• Boolean expressions use short-circuit evaluation
A Boolean expression terminates as soon as its result can be determined.
Example
The following expression does not cause a run-time error when p = NIL:
IF (p # NIL) & (p.name = "quark") THEN
• Constant expressions
In constant declarations, not only literals, but also constant expressions are allowed.
Example
CONST
zero = ORD("0");
one = zero + 1;
• Different operators
# is used instead of <> for inequality test.
& is used instead of AND for logical conjunctions.
~ is used instead of NOT for logical negation.
• Explicit conversion to included type with SHORT
Type inclusion for numeric types allows to assign values of an included type to an including type. To assign in the other direction, the standard procedure SHORT must be used.
Example
int := shortint;
shortint := SHORT(int)
New Features
• Hexadecimal numbers and characters
Example
100H (* decimal 256 *)
0DX (* carriage return *)
• Additional numeric types
LONGINT, SHORTINT, BYTE, SHORTREAL have been added.
• Symmetric set difference
Sets can be subtracted.
• New standard procedures
The new standard procedures INC, DEC, INCL, EXCL, SIZE, ASH, HALT, ASSERT, LEN, LSH, MAX, MIN, BITS, CAP, ENTIER, LONG and SHORT have been added.
• LOOP with EXIT
There is a new loop statement with an explicit exit statement. See language report for more details.
• ARRAY OF CHAR can be compared
Character arrays can be compared with the =, #, <, >, <=, and >= operators.
• Open arrays, multidimensional arrays
Arrays without predefined sizes can be defined, possibly with several dimensions.
Examples
VAR a: POINTER TO ARRAY OF CHAR;
NEW(a, 16)
PROCEDURE ScalarProduct (a, b: ARRAY OF REAL; VAR c: ARRAY OF REAL);
TYPE Matrix = ARRAY OF ARRAY OF REAL;
PROCEDURE VectorProduct (a, b: ARRAY OF REAL; VAR c: Matrix);
• Pointer dereferencing is optional
The dereferencing operator ^ can be omitted.
Example
root.next.value := 5
instead of
root^.next^.value := 5
• Modules
Modules are the units of compilation, of information hiding, and of loading. Information hiding is one of the main features of object-oriented programming. Various levels of information hiding are possible: complete hiding, read-only / implement-only export, full export.
See language report for more details.
• Type extension
Record types (pointer types) can be extended, thus providing for polymorphism. Polymorphism is one of the main features of object-oriented programming.
• Methods
Procedures can be bound to record types (pointer types), thus providing late binding. Late binding is one of the main features of object-oriented programming. Such procedures are also called methods.
• String operator
The string (sequence of characters) that is contained in an array of character can be selected by using the $-selector.
• Record attributes
Records are non-extensible by default, but may be marked as EXTENSIBLE, ABSTRACT, or LIMITED.
• Method attributes
Methods are non-extensible by default, but may be marked as EXTENSIBLE, ABSTRACT, or EMTPY. Newly introduced methods must be marked as NEW.
| Docu/Tut-B.odc |
Tutorial:
Component-based Software Development with BlackBox
Table of Contents
Part I: Design Patterns
An introduction to the design patterns that are used throughout BlackBox.
To know these patterns makes it easier to understand and remember the
more detailed design decisions in the various BlackBox modules.
1 UserInteraction
1.1 User-friendliness
1.2 Event loops
1.3 Access by multiple users
1.4 Language-specific parameters
2 CompoundDocuments
2.1 Persistence
2.2 Display independence
2.3 Multi-view editing
2.4 Change propagation
2.5 Nested views
2.6 Delayed updates
2.7 Container modes
2.8 Event handling
2.9 Controls
3 BlackBoxDesignPractices
3.1 Language support
3.2 Modules and subsystems
3.3 Bottleneck interfaces
3.4 Object creation
Part II: Library
Demonstration how the most important library components
can be used: control, form, and text components.
4 Forms
4.1 Preliminaries
4.2 Phone book example
4.3 Interactors
4.4 Guards
4.5 Notifiers
4.6 Standard controls
4.7 Complex controls and interactors
4.8 Input validation
4.9 Accessing controls explicitly
4.10 Summary
5 Texts
5.1 Writing text
5.2 The Model-View-Controller pattern applied to texts
5.3 Reading text
5.4 Modifying text
5.5 Text scripts
5.6 Summary
Part III: View Construction
How new views can be developed, by giving a series of
examples that gradually become more sophisticated.
6 ViewConstruction
6.1 Introduction
6.2 Message handling
6.3 Preference messages
6.4 Controller messages
6.5 Properties
6.6 Model-View separation
6.7 Operations
6.8 Separation of interface and implementation
Appendix A: ABriefHistoryofPascal
Appendix B: DifferencesbetweenPascalandComponentPascal
| Docu/Tut-TOC.odc |
FigCmds
DEFINITION FigCmds;
IMPORT Dialog;
CONST
mm = 0; inch = 1; point = 2; fill = 3; hairline = 4;
VAR
TPropDlg: RECORD
thickness, type: INTEGER;
initiated: BOOLEAN
END;
arrowPropDlg: RECORD
type: INTEGER;
initiated: BOOLEAN
END;
gridDlg: RECORD
grid, gridDrawingFactor, unitType: INTEGER
END;
PROCEDURE SplitPoints;
PROCEDURE SplitPointsGuard(VAR par: Dialog.Par);
PROCEDURE JoinPoints;
PROCEDURE JoinPointsGuard(VAR par: Dialog.Par);
PROCEDURE SendToBack;
PROCEDURE SendToBackGuard(VAR par: Dialog.Par);
PROCEDURE BringToFront;
PROCEDURE BringToFrontGuard(VAR par: Dialog.Par);
PROCEDURE AddAnchor;
PROCEDURE AddAnchorGuard (VAR par: Dialog.Par);
PROCEDURE RemoveAnchor;
PROCEDURE RemoveAnchorGuard (VAR par: Dialog.Par);
PROCEDURE SelectAnchors;
PROCEDURE SelectAnchorsGuard (VAR par: Dialog.Par);
PROCEDURE TogglePointhiding;
PROCEDURE TogglePointhidingGuard (VAR par: Dialog.Par);
PROCEDURE ToggleGridhiding;
PROCEDURE ToggleGridhidingGuard (VAR par: Dialog.Par);
PROCEDURE ToggleGrid;
PROCEDURE ToggleGridGuard (VAR par: Dialog.Par);
PROCEDURE InitGridDialog;
PROCEDURE SetGrid;
PROCEDURE SetGridGuard (VAR par: Dialog.Par);
PROCEDURE GridNotifier (op, from, to: INTEGER);
PROCEDURE ForceToGrid;
PROCEDURE ForceToGridGuard (VAR par: Dialog.Par);
PROCEDURE Deposit;
PROCEDURE FocusGuard (VAR par: Dialog.Par);
PROCEDURE SelectionGuard (nofPoints: INTEGER; VAR par: Dialog.Par);
PROCEDURE ArrowDlgGuard (VAR par: Dialog.Par);
PROCEDURE ThicknessDlgGuard (VAR par: Dialog.Par);
PROCEDURE InitTPropDialog;
PROCEDURE SetTProp;
PROCEDURE InitArrowPropDialog;
PROCEDURE SetArrowProp;
PROCEDURE UpDownGuard (VAR par: Dialog.Par);
PROCEDURE UpDownNotifier (op, from, to: INTEGER);
PROCEDURE OpenExtensionDocu;
PROCEDURE OpenExtensionDocuGuard (VAR par: Dialog.Par);
END FigCmds.
FigCmds provides basic commands for Fig.
CONST mm, inch, point
Used in gridDlg.unitType and TPropDlg.type.
CONST fill, hairline
Used in TPropDlg.type.
VAR TPropDlg: RECORD
Used together with the /Fig/Rsrc/Thickns dialog.
thickness: INTEGER
The current "thickness" in universal units.
type: INTEGER
The current type.
initiated: BOOLEAN
TRUE if TPropDlg is initiated to meaningful values, FALSE otherwise.
VAR arrowPropDlg: RECORD
Used together with the /Fig/Rsrc/Lines dialog.
type: INTEGER
Hold the current type of line: FigModels.noArrow, FigModels.beginArrow, FigModels.endArrow or FigModels.doubleArrow. See the documentation for FigModels for more information about those constants.
initiated: BOOLEAN
TRUE if arrowPropDlg is initiated to meaningful values, FALSE otherwise.
VAR gridDlg: RECORD
Used together with the /Fig/Rsrc/Grid dialog.
grid: INTEGER
This variable holds the current grid size in universal units.
gridDrawingFactor: INTEGER
This variable hold the current grid drawing factor. A grid drawing factor of 5 will cause a line to be drawn for every 5th "grid unit"
unitType: INTEGER
The current unit type.
PROCEDURE SplitPoints
Guard: FigCmds.SplitPointsGuard
Splits a selected point by creating a new point for each of the point's dependent points and figures.The selected point is kept if it's a FigModels.ConstrainedPoint, otherwise it's deleted from the drawing.
PROCEDURE SplitPointsGuard (VAR par: Dialog.Par)
Disables the command if the focus view doesn't have exactly one selected point.
PROCEDURE JoinPoints
Guard: FigCmds.JoinPointsGuard
Joins all the selected points into one, restructuring their dependent points and figures in the process.
PROCEDURE JoinPointsGuard (VAR par: Dialog.Par)
Disables the command if the focus view doesn't have at least two selected points. A FigModels.ConstrainedPoint is only allowed as the join target (last selected point), and then only if it isn't depending on any other selected point.
PROCEDURE SendToBack
Guard: FigCmds.SendToBackGuard
Moves the selected figures to the back, behind all other figures.
PROCEDURE SendToBackGuard (VAR par: Dialog.Par)
Disables the command if the focus view doesn't have any selected figures.
PROCEDURE BringToFront
Guard: FigCmds.BringToFrontGuard
Moves the selected figures to the front, in front of all other figures.
PROCEDURE BringToFrontGuard (VAR par: Dialog.Par)
Disables the command if the focus view doesn't have any selected figures.
PROCEDURE AddAnchor
Guard: FigCmds.AddAnchorGuard
Adds an anchorpoint to a figure or a constrained point.
PROCEDURE AddAnchorGuard (VAR par: Dialog.Par)
The command is abled in these situations:
- If no figure is selected, one constrained point is selected, and the constrained point is expandable and
hasn't reached it's upper limit of anchorpoints.
- If one figure is selected, one or two points are selected, and the figure has to be expandable and hasn't
reached it's upper limit of anchorpoints. The points have to be anchorpoints to the figure. If only one
point is selected then it has to be a "end-anchorpoint" and the figure mustn't be cyclic. If two points are
selected they have to be adjacent anchorpoints.
PROCEDURE RemoveAnchor
Guard: FigCmds.RemoveAnchorGuard
Removes the selected anchorpoint from a figure or constrained point.
PROCEDURE RemoveAnchorGuard (VAR par: Dialog.Par)
The command is abled in these situations:
- If no figure is selected, and two points are selected. The last selected point is the constrained point
from which the anchorpoint is removed, and it has to be expandable and has more anchorpoints than
it's lower limit.
- If one figure and one point is selected, and the figure is expandable and has more anchorpoints than it's
lower limit.
PROCEDURE SelectAnchors;
Guard: FigCmds.SelectAnchorsGuard
Selects all the anchorpoints connected to a figure or constrained point.
PROCEDURE SelectAnchorsGuard (VAR par: Dialog.Par);
Disables the command if no objects are selected.
PROCEDURE TogglePointhiding
Guard: FigCmds.TogglePointhidingGuard.
Toggles whether or not points are shown in the focus view.
PROCEDURE TogglePointhidingGuard (VAR par: Dialog.Par)
This guard disables the current menu item if no FigViews.View has the focus.
PROCEDURE ToggleGridhiding
Guard: FigCmds.ToggleGridhidingGuard.
Toggles whether or not the grid is shown in the focus view.
PROCEDURE ToggleGridhidingGuard (VAR par: Dialog.Par)
This guard disables the current menu item if no FigViews.View has the focus.
PROCEDURE ToggleGrid
Guard: FigCmds.ToggleGridGuard.
Toggles whether the grid is enabled or disabled in the focus view.
PROCEDURE ToggleGridGuard (VAR par: Dialog.Par)
This guard disables the current menu item if no FigViews.View has the focus.
PROCEDURE InitGridDialog
Initializes the variables gridDlg.grid and gridDlg.gridDrawingFactor to match the focus FigViews.View.
PROCEDURE SetGrid
Guard: FigCmds.SetGridGuard.
Sets the size of the grid based on the variables gridDlg.grid and gridDlg.gridDrawingFactor. This command is used together with InitGridDialog in the Fig/Rsrc/Grid dialog.
PROCEDURE SetGridGuard (VAR par: Dialog.Par)
This guard disables the current menu item if no FigViews.View has the focus.
PROCEDURE GridNotifier (op, from, to: INTEGER)
Used in the /Fig/Rsrc/Grid dialog to prevent the updown controls to go below 1.
PROCEDURE ForceToGrid
Guard: FigCmds.ForceToGridGuard.
Forces all selected points to the grid.
PROCEDURE ForceToGridGuard (VAR par: Dialog.Par)
This guard disables the current menu item if no FigViews.View has the focus, no points are selected or if the grid is disabled.
PROCEDURE Deposit
Deposits a FigView in the view queue.
PROCEDURE FocusGuard (VAR par: Dialog.Par)
This guard disables the menu item if no FigViews.View has focus.
PROCEDURE SelectionGuard (nofPoints: INTEGER; VAR par: Dialog.Par)
This guard disables the menu item if less than nofPoints points are selected.
PROCEDURE ArrowDlgGuard (VAR par: Dialog.Par);
Checks whether arrowPropDlg is initiated or not.
PROCEDURE ThicknessDlgGuard (VAR par: Dialog.Par);
Checks whether TPropDlg is initiated or not.
PROCEDURE InitTPropDialog
This initializes the variable TPropDlg.
PROCEDURE SetTProp
Emits a FigModels.TProp based on TPropDlg.
PROCEDURE InitArrowPropDialog
This initializes the variable arrowPropDlg.
PROCEDURE SetArrowProp
Emits a FigModels.ArrowProp based on arrowPropDlg.
PROCEDURE UpDownGuard (VAR par: Dialog.Par)
Disables the updown control in the /Fig/Rsrc/Thickns dialog if TPropDlg.type is fill or hairline.
PROCEDURE UpDownNotifier (op, from, to: INTEGER)
Prevents the updown control in the /Fig/Rsrc/Thickns dialog to go below 1.
PROCEDURE OpenExtensionDocu
Guard: OpenExtensionDocuGuard
Opens the documentation of the latest figure or constrained Point.
PROCEDURE OpenExtensionDocuGuard (VAR par: Dialog.Par)
Guard for OpenExtensionDocu
Disables the command if no figure or constrained point is selected.
| Fig/Docu/Cmds.odc |
FigModels
DEFINITION FigModels;
IMPORT Stores, Models, Properties, Ports;
CONST
expandable = 0; cyclic = 1; minAnchors = 2; maxAnchors = 3;
thickness = 0;
undefined = -1;
noArrow = 1; beginArrow = 2; endArrow = 3; doubleArrow = 4;
type = 0;
TYPE
Model = POINTER TO LIMITED RECORD (Models.Model)
base-: ModelBase;
(m: Model) Points (): PointList, NEW;
(m: Model) Figures (): FigureList, NEW;
(m: Model) InsertCopy (source: Model; plist: PointList; flist: FigureList, OUT newPoints: PointList;
OUT newFigures: FigureList), NEW;
(m: Model) InsertObject (o: Object; anchors: PointList; x, y: INTEGER), NEW;
(m: Model) NewFreePoint (x, y: INTEGER): FreePoint, NEW;
(m: Model) RemoveObject (o: Object), NEW;
(m: Model) AddAnchor (o: Object; pos: INTEGER; OUT pnt: Point), NEW;
(m: Model) RemoveAnchor (o: Object; p: Point), NEW;
(m: Model) JoinPossible (plist: PointList; target: Point), NEW;
(m: Model) JoinPoints (plist: PointList; target: Point): BOOLEAN, NEW;
(m: Model) SplitPoint (p: Point), NEW;
(m: Model) MovePoints (plist: PointList; dx, dy: INTEGER), NEW;
(m: Model) MovePoint (p: Point; dx, dy: INTEGER), NEW;
(m: Model) MoveToGrid (plist: PointList; grid: INTEGER), NEW
(m: Model) BringToFront (flist: FigureList), NEW;
(m: Model) SendToBack (flist: FigureList), NEW;
(m: Model) CollectProperties (flist: FigureList; plist: PointList; OUT prop: Properties.Property), NEW;
(m: Model) EmitProperties (flist: FigureList; plist: PointList; prop: Properties.Property), NEW;
(m: Model) GetBoundingBox (plist: PointList; flist: FigureList; OUT l, t, r, b: INTEGER), NEW;
(m: Model) IncludedFigures (flist: FigureList; l, t, r, b: INTEGER): FigureList, NEW;
(m: Model) IntersectingFigures (flist: FigureList; l, t, r, b: INTEGER): FigureList, NEW;
(m: Model) TheseFigures (flist: FigureList; x, y: INTEGER): FigureList, NEW;
(m: Model) ThesePoints (plist: PointList; l, t, r, b: INTEGER): PointLisr, NEW;
(m: Model) ChooseFigures (flist: FigureList; c: FigureChooser): FigureList, NEW;
(m: Model) ChoosePoints (plist: PointList; c: PointChooser): PointList, NEW;
(m: Model) ThisFigureList (figs: ARRAY OF Figure): FigureList, NEW;
(m: Model) ThisPointList (pnts: ARRAY OF Point): PointList, NEW
END;
ModelBase = POINTER TO ABSTRACT RECORD (Stores.Store)
model-: Model;
(m: ModelBase) InitFrom- (source: ModelBase), NEW, ABSTRACT;
(m: ModelBase) InitModel- (model: Model), NEW, ABSTRACT;
(m: ModelBase) NewPointBase- (): PointBase, NEW, ABSTRACT;
(m: ModelBase) NewFigureBase- (): FigureBase, NEW, ABSTRACT;
(m: ModelBase) Points- (): PointList, NEW, ABSTRACT;
(m: ModelBase) Figures- (): FigureList, NEW, ABSTRACT;
(m: ModelBase) InsertCopy- (source: ModelBase; plist: PointList; flist: FigureList,
OUT newPoints: PointList; OUT newFigures: FigureList),
NEW, ABSTRACT;
(m: ModelBase) InsertObject- (o: Object; anchors: PointList; x, y: INTEGER), NEW, ABSTRACT;
(m: ModelBase) RemoveObject- (o: Object), NEW, ABSTRACT;
(m: ModelBase) AddAnchor- (o: Object; pos: INTEGER; p: Point), NEW, ABSTRACT;
(m: ModelBase) RemoveAnchor- (o: Object; p: Point), NEW, ABSTRACT;
(m: ModelBase) ChangeAnchor- (o: Object; p: Point; pos: INTEGER), NEW, ABSTRACT;
(m: ModelBase) MovePoints- (points: PointList; dx, dy: INTEGER), NEW, ABSTRACT;
(m: ModelBase) MovePoint- (p: Point; dx, dy: INTEGER), NEW, ABSTRACT;
(m: ModelBase) MoveToGrid- (plist: PointList; grid: INTEGER), NEW, ABSTRACT;
(m: ModelBase) BringToFront- (flist: FigureList), NEW, ABSTRACT;
(m: ModelBase) SendToBack- (flist: FigureList), NEW, ABSTRACT;
(m: ModelBase) ThisFigureList- (figs: ARRAY OF Figure): FigureList, NEW, ABSTRACT;
(m: ModelBase) ThisPointList- (pnts: ARRAY OF Point): PointList, NEW, ABSTRACT
END;
Object = POINTER TO ABSTRACT RECORD (Stores.Store) END;
Point = POINTER TO ABSTRACT RECORD (Object)
base-: PointBase;
(p: Point) Model (): Model, NEW;
(p: Point) X (): INTEGER, NEW;
(p: Point) Y (): INTEGER, NEW;
(p: Point) DependingFigures (): FigureList, NEW;
(p: Point) DependingPoints (): PointList, NEW
END;
PointBase = POINTER TO ABSTRACT RECORD (Stores.Store)
ext-: Point;
(p: PointBase) Model- (): Model, NEW, ABSTRACT;
(p: PointBase) X- (): INTEGER, NEW, ABSTRACT;
(p: PointBase) Y- (): INTEGER, NEW, ABSTRACT;
(p: PointBase) Anchors- (): PointList, NEW, ABSTRACT;
(p: PointBase) DependingFigures- (): FigureList, NEW, ABSTRACT;
(p: PointBase) DependingPoints- (): PointList, NEW, ABSTRACT
END;
FreePoint = POINTER TO LIMITED RECORD (Point) END;
ConstrainedPoint = POINTER TO ABSTRACT RECORD (Point)
(c: ConstrainedPoint) Action (), NEW, EMPTY;
(c: ConstrainedPoint) Anchors (): PointList, NEW;
(c: ConstrainedPoint) Calculate (VAR x, y: INTEGER), NEW, EMPTY;
(c: ConstrainedPoint) PollProp (OUT p: Properties.Property), NEW, EXTENSIBLE;
(c: ConstrainedPoint) SetProp (p: Properties.Property), NEW, EMPTY
END;
Figure = POINTER TO ABSTRACT RECORD (Object)
base-: FigureBase;
(fig: Figure) Model (): Model, NEW;
(fig: Figure) Anchors (): PointList, NEW;
(fig: Figure) Action, NEW, EMPTY;
(fig: Figure) GetBoundingBox (OUT l, t, r, b: INTEGER), NEW, EXTENSIBLE;
(fig: Figure) Draw (f: Ports.Frame; l, t, r, b: INTEGER), NEW, ABSTRACT;
(fig: Figure) Covers (x, y: INTEGER): BOOLEAN, NEW, EXTENSIBLE;
(fig: Figure) PollProp (OUT p: Properties.Property), NEW, EXTENSIBLE;
(fig: Figure) SetProp (p: Properties.Property), NEW, EMPTY
END;
FigureBase = POINTER TO ABSTRACT RECORD (Stores.Store)
ext-: Figure;
(f: FigureBase) Model- (): Model, NEW, ABSTRACT;
(f: FigureBase) Anchors- (): PointList, NEW, ABSTRACT
END;
AlienFigure = POINTER TO ABSTRACT RECORD (Figure)
store-: Stores.Alien;
(fig: AlienFigure) CopyDataFrom- (source: AlienFigure), NEW, EMPTY
END;
AlienPoint = POINTER TO ABSTRACT RECORD (ConstrainedPoint)
store-: Stores.Alien
(p: AlienPoint) CopyDataFrom- (source: AlienPoint), NEW, EMPTY
END;
PointList = POINTER TO ABSTRACT RECORD
(p: PointList) This (): Point, NEW, ABSTRACT;
(p: PointList) Next (): PointList, NEW, ABSTRACT
END;
FigureList = POINTER TO ABSTRACT RECORD
(f: FigureList) This (): Figure, NEW, ABSTRACT;
(f: FigureList) Next (): FigureList, NEW, ABSTRACT
END;
PointChooser = POINTER TO ABSTRACT RECORD
(c: PointChooser) Choose (p: Point): BOOLEAN, NEW, ABSTRACT
END;
FigureChooser = POINTER TO ABSTRACT RECORD
(c: FigureChooser) Choose (f: Figure): BOOLEAN, NEW, ABSTRACT
END;
Directory = POINTER TO ABSTRACT RECORD
(d: Directory) New (): Model, NEW;
(d: Directory) NewModelBase- (): ModelBase, NEW, ABSTRACT
END;
StdProp = POINTER TO RECORD (Properties.Property)
minAnchors, maxAnchors: INTEGER;
expandable, cyclic: BOOLEAN
END;
TProp = POINTER TO RECORD (Properties.Property)
thickness: INTEGER
END;
ArrowProp = POINTER TO RECORD (Properties.Property)
type: INTEGER
END;
UpdateMsg = EXTENSIBLE RECORD (Models.UpdateMsg)
l, t, r, b: INTEGER
END;
InsertMsg = RECORD (UpdateMsg)
insert: BOOLEAN;
figure: Figure;
point: Point
END;
AnchorMsg = RECORD (UpdateMsg)
add: BOOLEAN;
figure: Figure;
comppnt: ConstrainedPoint;
anchor: Point;
pos: INTEGER
END;
ChangeAnchorMsg = RECORD (UpdateMsg)
newPoint, oldPoint: Point;
figure: Figure;
compPoint: ConstrainedPoint;
pos: INTEGER
END;
VAR
dir-: Directory;
stdDir-: Directory;
PROCEDURE WritePoint (VAR wr: Stores.Writer; p: Point);
PROCEDURE WriteFigure (VAR wr: Stores.Writer; f: Figure);
PROCEDURE ReadPoint (VAR rd: Stores.Reader; OUT point: Point);
PROCEDURE ReadFigure (VAR rd: Stores.Reader; OUT figure: Figure);
PROCEDURE CloneOf (source: Model): Model;
PROCEDURE SetDir (d: Directory);
END FigModels.
FigModels are models which contain Points, functioning as anchors to Figures and ConstrainedPoints.
CONST expandable
Used in StdProp.valid, StdProp.known and StdProp.readOnly. A figure or constrained point with this option set is expandable, which means anchorpoints can be added to and removed from the figure/constrained point.
CONST cyclic
Used in StdProp.valid, StdProp.known and StdProp.readOnly. A figure or constrained point with this option set has a cyclic appearance. Example: a polygon is cyclic.
CONST minAnchors
Used in StdProp.valid, StdProp.known and StdProp.readOnly. A figure or constrained point with this option set has a minimum number of anchorpoints.
CONST maxAnchors
Used in StdProp.valid, StdProp.known and StdProp.readOnly. A figure or constrained point with this option set has a maximum number of anchorpoints.
CONST thickness
Used in TProp.valid, TProp.known and TProp.readOnly.
CONST undefined
Used in different situations:
- If StdProp.maxAnchorpoints is set to this value, then the figure or constrained point can be expanded
indefinitely with new anchorpoints.
- In InsertObject: If the object is a Figure, then the x and y parameters have to be set to this value. A
constrained point can have this value as it's coordinates. Then the points Calculate procedure must set the
coordinates to real values.
- In Calculate: If a constrained point's coodinates have this value, they have to be initialized to "real" values.
CONST noArrow
Used in ArrowProp.type to indicate that the figure has no arrow heads.
CONST beginArrow
Used in ArrowProp.type to indicate that the figure has one arrow head, pointing at it's first anchorpoint.
CONST endArrow
Used in ArrowProp.type to indicate that the figure has one arrow head, pointing at it's last anchorpoint.
CONST doubleArrow
Used in ArrowProp.type to indicate that the figure has two arrow heads, pointing at it's first and last anchorpoint.
CONST type
Used in ArrowProp.valid, ArrowProp.known and ArrowProp.readOnly.
TYPE Model
LIMITED
The model represents the client's interface of a drawing. The model is connected to a ModelBase that can be implemented by a third party. The model is represented graphically by a FigViews.View.
base-: ModelBase
The ModelBase that is connected to the model.
PROCEDURE (m: Model) Points (): PointList
NEW
Returns a list of all the points in the model.
PROCEDURE (m: Model) Figures (): FigureList
NEW
Returns a list of all the figures in the model.
PROCEDURE (m: Model) InsertCopy (source: Model; plist: PointList; flist: FigureList,
OUT newPoints: PointList; OUT newFigures: FigureList)
NEW
Copies the points and figures in plist and flist into m. plist and flist must belong to source. The points added to m are returned in newPoints, and the figures added to m are returned in newFigures (these points and figures belong to m). Constrained points that have all their anchorpoints in plist will be copied as ConstrainedPoints, otherwise they'll be transformed into FreePoints. Figures in flist will have their anchorpoints copied also, these points don't have to be in plist from the beginning.
Pre
For all points in plist:
plist.This().Model() = source 20
For all figures in flist:
flist.This().Model() = source 21
PROCEDURE (m: Model) InsertObject (o: Object; anchors: PointList; x, y: INTEGER)
NEW
Inserts o into m. anchors is the list of anchorpoints, if o is a Figure or a ConstrainedPoint. x and y are the coordinates if o is a ConstrainedPoint.
Pre
f # NIL 20
anchors # NIL 21
anchors.This().Model() = m 22
PROCEDURE (m: Model) NewFreePoint (x, y: INTEGER): FreePoint
NEW
Inserts a FreePoint in m at x, y. The newly inserted point is returned.
PROCEDURE (m: Model) RemoveObject (o: Object)
NEW
Removes o from m.
Pre
f # NIL 20
f.Model() = m 21
PROCEDURE (m: Model) AddAnchor (o: Object; pos: INTEGER; OUT pnt: Point)
NEW
Adds a new FreePoint as an anchorpoint to o. pos indicates the point's place in o's list of anchorpoints. The newly inserted point is returned in pnt.
Pre
p # NIL 20
f # NIL 21
p.Model() = m 22
f.Model() = m 23
pos >= 0 24
PROCEDURE (m: Model) RemoveAnchor (o: Object; p: Point)
NEW
Removes the point p from o's list of anchorpoints. p isn't removed from m.
Pre
p # NIL 20
f # NIL 21
p.Model() = m 22
f.Model() = m 23
PROCEDURE (m: Model) JoinPossible (plist: PointList; target: Point): BOOLEAN
NEW
Returns TRUE if the points in plist can be joined into target, otherwise FALSE is returned. The criteria for a join is the following:
- target may not be included in plist.
- No constrained points in plist.
- If target is a constrained point then target may not depend on any of the points in plist.
Pre
m # NIL 20
plist # NIL 21
target # NIL 22
plist.This().Model() = m 23
target.Model() = m 24
PROCEDURE (m: Model) JoinPoints (plist: PointList; target: Point)
NEW
Joins the points in plist into target if JoinPossible(m, plist, target) = TRUE. All figures and points connected to the points in plist will become connected to target instead, and the points in plist will be removed from m.
Pre
m # NIL 20
plist # NIL 21
target # NIL 22
plist.This().Model() = m 23
target.Model() = m 24
PROCEDURE (m: Model) SplitPoint (p: Point)
NEW
Splits p into new FreePoints. One FreePoint for each figure or constrained point connected to p will be created, and then the figures and constrained points will become connected to the new FreePoints instead.
If p is a ConstrainedPoint then it will become deselected, otherwise it will be removed from m.
Pre
m # NIL 20
p # NIL 21
p.Model() = m 22
PROCEDURE (m: Model) MovePoints (plist: PointList; dx, dy: INTEGER)
NEW
Moves all points in plist according the vector dx, dy.
Pre
plist.This().Model() = m 20
PROCEDURE (m: Model) MovePoint (p: Point; dx, dy: INTEGER)
NEW
Moves p according to the vector dx, dy.
Pre
p # NIL 20
PROCEDURE (m: Model) MoveToGrid (plist: PointList; grid: INTEGER)
NEW
Moves the points in plist so they lay on the grid (in universal units).
Pre
grid > 0 20
PROCEDURE (m: Model) BringToFront (flist: FigureList)
NEW
Moves all figures in flist in front of all other figures. The order of the flist figures will be kept as they are in m. This ordering might be different from the ordering in flist.
Pre
flist # NIL 20
flist.This().Model() = m 21
PROCEDURE (m: Model) SendToBack (flist: FigureList)
NEW
Moves all figures in flist behind all other figures. The order of the flist figures will be kept as they are in m. This ordering might be different from the ordering in flist.
Pre
flist # NIL 20
flist.This().Model() = m 21
PROCEDURE (m: Model) CollectProperties (flist: FigureList; plist: PointList; OUT prop: Properties.Property)
NEW
Collects the properties for the figures in flist and for the constrained points in plist. The properties are returned in prop.
PROCEDURE (m: Model) EmitProperties (flist: FigureList; plist: PointList; prop: Properties.Property)
NEW
Emits prop to all figures in flist and to all constrained points in plist.
Pre
m # NIL 20
PROCEDURE (m: Model) GetBoundingBox (plist: PointList; flist: FigureList; OUT l, t, r, b: INTEGER)
NEW
Get the box that contains all points in plist and all figures in flist. The bounding box is returned in l, t, r, b.
Pre
(plist # NIL) OR (flist # NIL) 20
PROCEDURE (m: Model) IncludedFigures (flist: FigureList; l, t, r, b: INTEGER): FigureList
NEW
Returns a list of the figures in flist that are within the box defined by l, t, r, b.
Pre
m # NIL 20
PROCEDURE (m: Model) IntersectingFigures (flist: FigureList; l, t, r, b: INTEGER): FigureList
NEW
Returns a list of the figures in flist which bounding box touches the box defined by l, t, r, b.
Pre
m # NIL 20
PROCEDURE (m: Model) TheseFigures (flist: FigureList; x, y: INTEGER): FigureList
NEW
Returns the figures from flist that covers x, y.
Pre
m # NIL 20
PROCEDURE (m: Model) ThesePoints (plist: PointList; l, t, r, b: INTEGER): PointList
NEW
Returns the points from plist that lays within l, t, r, b.
Pre
m # NIL 20
PROCEDURE (m: Model) ChooseFigures (flist: FigureList; c: FigureChooser): FigureList
NEW
Returns a list of the figures in flist for which c.Choose = TRUE.
Pre
c # NIL 20
flist.This().Model() = m 21
PROCEDURE (m: Model) ChoosePoints (plist: PointList; c: PointChooser): PointList
NEW
Returns a list of the points in plist for which c.Choose = TRUE.
Pre
c # NIL 20
plist.This().Model() = m 21
PROCEDURE (m: Model) ThisFigureList (figs: ARRAY OF Figure): FigureList
NEW
Returns a list containing the figures in figs, in the same order. The figures in figs must all belong to m.
PROCEDURE (m: Model) ThisPointList (pnts: ARRAY OF Point): PointList
NEW
Returns a list containing the points in pnts, in the same order. The points in pnts must all belong to m.
TYPE ModelBase
ABSTRACT
model-: Model
The Model connected to this ModelBase.
PROCEDURE (m: ModelBase) InitFrom- (source: ModelBase)
NEW, ABSTRACT
Initializes m based on source. source can often be ignored.
PROCEDURE (m: ModelBase) InitModel- (model: Model)
NEW, ABSTRACT
Initializes the model of all figures and points to model.
PROCEDURE (m: ModelBase) NewPointBase- (): PointBase
NEW, ABSTRACT
Returns an empty PointBase.
PROCEDURE (m: ModelBase) NewFigureBase- (): FigureBase
NEW, ABSTRACT
Returns an empty FigureBase.
PROCEDURE (m: ModelBase) Points- (): PointList
NEW, ABSTRACT
Returns a list containing all points in m. The first point in the list is the point that was inserted first in m, and the last in the list is the point inserted last.
PROCEDURE (m: ModelBase) Figures- (): FigureList
NEW, ABSTRACT
Returns a list containing all figures in the ModelBase. The first figure in the list is the figure that was inserted first in m, and the last in the list is the figure inserted last.
PROCEDURE (m: ModelBase) InsertCopy- (source: ModelBase; plist: PointList; flist: FigureList,
OUT newPoints: PointList; OUT newFigures: FigureList)
NEW, ABSTRACT
Copies the points and figures in plist and flist into m. The points added to m are returned in newPoints, and the figures added to m are returned in newFigures (these points and figures belong to m). Constrained points that have all their anchorpoints in plist will be copied as ConstrainedPoints, otherwise they'll be transformed into FreePoints. Figures in flist will have their anchorpoints copied also, these points don't have to be in plist from the beginning.
PROCEDURE (m: ModelBase) InsertObject- (o: Object; anchors: PointList; x, y: INTEGER)
NEW, ABSTRACT
Inserts o into m. anchors is the list of anchorpoints, if o is a Figure or a ConstrainedPoint. x and y are the coordinates if o is a Point.
PROCEDURE (m: ModelBase) RemoveObject- (o: Object)
NEW, ABSTRACT
Removes o from m.
PROCEDURE (m: ModelBase) AddAnchor- (o: Object; pos: INTEGER; p: Point)
NEW, ABSTRACT
PROCEDURE (m: ModelBase) RemoveAnchor- (o: Object; p: Point)
NEW, ABSTRACT
PROCEDURE (m: ModelBase) ChangeAnchor- (o: Object; p: Point; pos: INTEGER)
NEW, ABSTRACT
PROCEDURE (m: ModelBase) MovePoints- (points: PointList; dx, dy: INTEGER)
NEW, ABSTRACT
PROCEDURE (m: ModelBase) MovePoint- (p: Point; dx, dy: INTEGER)
NEW, ABSTRACT
PROCEDURE (m: ModelBase) MoveToGrid- (plist: PointList; grid: INTEGER)
NEW, ABSTRACT
PROCEDURE (m: ModelBase) BringToFront- (flist: FigureList)
NEW, ABSTRACT
PROCEDURE (m: ModelBase) SendToBack- (flist: FigureList)
NEW, ABSTRACT
PROCEDURE (m: ModelBase) ThisFigureList- (figs: ARRAY OF Figure): FigureList
NEW, ABSTRACT
PROCEDURE (m: ModelBase) ThisPointList- (pnts: ARRAY OF Point): PointList
NEW, ABSTRACT
TYPE Point
ABSTRACT
The base type for FreePoints and ConstrainedPoints.
base-: PointBase
All points are connected to a PointBase that contains basic information about the point.
PROCEDURE (p: Point) Model (): Model
NEW
Returns the model the point belongs to.
PROCEDURE (p: Point) X (): INTEGER
NEW
Returns the point's x-coordinate.
PROCEDURE (p: Point) Y (): INTEGER
NEW
REturns the point's y-coordinate.
PROCEDURE (p: Point) IsSelected (): BOOLEAN
NEW
Returns TRUE if the point is selected, FALSE if it isn't.
PROCEDURE (p: Point) SelectionTime (): INTEGER
NEW
Returns a timestamp of the point's last selection.
PROCEDURE (p: Point) DependingFigures (): PointList
NEW
Returns a list of all the constrained points that depend on this point.
PROCEDURE (p: Point) DependingPoints (): FigureList
NEW
Returns a list of all the figures that depend on this point.
TYPE PointBase
ABSTRACT
All points are connected to a PointBase containing basic information about the point. The PointBase is extended by the model provider.
ext-: Point
The point connected to this base.
PROCEDURE (p: PointBase) Model- (): Model
NEW, ABSTRACT
Returns the model the point belongs to.
PROCEDURE (p: PointBase) X- (): INTEGER
NEW, ABSTRACT
Returns the point's x-coordinate.
PROCEDURE (p: PointBase) Y- (): INTEGER
NEW, ABSTRACT
Returns the point's y-coordinate.
PROCEDURE (p: PointBase) IsSelected- (): BOOLEAN
NEW, ABSTRACT
Returns TRUE if the point is selected, FALSE if it isn't.
PROCEDURE (p: PointBase) SelectionTime- (): INTEGER
NEW, ABSTRACT
Returns a timestamp of the point's last selection.
PROCEDURE (p: PointBase) Anchors- (): PointList
NEW, ABSTRACT
Returns a list containing the anchorpoints of the point.
PROCEDURE (p: PointBase) DependingFigures- (): PointList
NEW, ABSTRACT
Returns a list of all the constrained points that depend on this point.
PROCEDURE (p: PointBase) DependingPoints- (): FigureList
NEW, ABSTRACT
Returns a list of all the figures that depend on this point.
TYPE FreePoint
LIMITED
A basic extension of Point. A FreePoint can be used as an anchorpoint to a ConstrainedPoint or a Figure. FreePoints don't have any anchorpoints.
TYPE ConstrainedPoint
ABSTRACT
Functions as a base type for ConstrainedPoint extensions.
PROCEDURE (c: ConstrainedPoint) Action-
NEW, EMPTY
ConstrainedPoints can be given an action, and the function of this procedure may vary. It may for instance open a dialog for changing the point's attributes.
PROCEDURE (c: ConstrainedPoint) Anchors (): PointList
NEW
Returns a list containing the anchorpoints of c.
PROCEDURE (c: ConstrainedPoint) Calculate (VAR x, y: INTEGER)
NEW, EMPTY
Calculates a new position for c. x, y is the wanted position, but the final position depends on the points freedom of movement. A call to this procedure doesn't change the position of the point.
PROCEDURE (c: ConstrainedPoint) PollProp- (OUT p: Properties.Property)
NEW, EXTENSIBLE
Returns all properties that c knows about. Returns NIL by default.
PROCEDURE (c: ConstrainedPoint) SetProp- (p: Properties.Property)
NEW, EMPTY
c scans p and sets its attributes according to know properties.
TYPE Figure
ABSTRACT
The base type for all Figure extensions.
base-: FigureBase
All figures are connected to a FigureBase that contains basic information about the figure.
PROCEDURE (fig: Figure) Model (): Model
NEW
Returns the model the figure belongs to.
PROCEDURE (fig: Figure) Anchors (): PointList
NEW
Returns a list containing the anchorpoints of fig.
PROCEDURE (fig: Figure) IsSelected (): BOOLEAN
NEW
Returns TRUE if the figure is selected, FALSE if it isn't.
PROCEDURE (fig: Figure) SelectionTime ():INTEGER
NEW
Returns a timestamp of the figures's last selection.
PROCEDURE (fig: Figure) Action-
NEW, EMPTY
Figures can be given an action, and the function of this procedure may vary. It may for instance open a dialog for changing the figure's attributes.
PROCEDURE (fig: Figure) GetBoundingBox- (OUT l, t, r, b: INTEGER)
NEW, ABSTRACT
This procedure calculates the bounding box of fig, and returns it in l, t, r, b.
PROCEDURE (fig: Figure) Draw- (f: Ports.Frame; l, t, r, b: INTEGER)
NEW, ABSTRACT
This procedure draws fig to the frame f. l, t, r, b is the clipping area.
PROCEDURE (fig: Figure) Covers- (x, y: INTEGER): BOOLEAN
NEW, EXTENSIBLE
Returns TRUE if fig covers the coordinates x, y. Default implementation returns TRUE if x, y is within the bounding box of the figure.
PROCEDURE (fig: Figure) PollProp- (OUT p: Properties.Property)
NEW, EXTENSIBLE
Returns all properties that fig knows about. Returns NIL by default.
PROCEDURE (fig: Figure) SetProp- (p: Properties.Property)
NEW, EMPTY
fig scans p and sets its attributes according to know properties.
TYPE FigureBase
ABSTRACT
All figures are connected to a FigureBase containing basic information about the figure. The FigureBase is extended by the model provider.
ext-: Figure
The figure connected to this base.
PROCEDURE (f: FigureBase) Model- (): Model
NEW, ABSTRACT
The model the figure belongs to.
PROCEDURE (f: FigureBase) IsSelected- (): BOOLEAN
NEW, ABSTRACT
Returns TRUE if the figure is selected, FALSE if it isn't.
PROCEDURE (f: FigureBase) SelectionTime- (): INTEGER
NEW, ABSTRACT
Returns a timestamp of the figure's last selection.
PROCEDURE (f: FigureBase) Anchors- (): PointList
NEW, ABSTRACT
Returns a list containing the anchorpoints of the figure.
TYPE AlienPoint
ABSTRACT
Unknown ConstrainedPoint extensions are made into an AlienPoint. Extended by the model provider.
store- Stores.Alien
The alien store enclosed by the AlienPoint extension.
TYPE AlienFigure
ABSTRACT
Unknown Figure extensions are made into an AlienFigure. Extended by the model provider.
store- Stores.Alien
The alien store enclosed by the AlienFigure extension.
TYPE PointList
ABSTRACT
A list of points. Extended by the model provider.
PROCEDURE (p: PointList) This (): Point
NEW, ABSTRACT
The point at the current node.
PROCEDURE (p: PointList) Next (): PointList
NEW, ABSTRACT
The next node in the list.
TYPE FigureList
ABSTRACT
A list of figures. Extended by the model provider.
PROCEDURE (f: FigureList) This (): Figure
NEW, ABSTRACT
The figure at the current node.
PROCEDURE (f: FigureList) Next (): FigureList
NEW, ABSTRACT
The next node in the list.
TYPE PointChooser
ABSTRACT
The PointChooser provides a way to find points that satisfies certain criteria.
PROCEDURE (c: PointChooser) Choose (p: Point): BOOLEAN
NEW, ABSTRACT
Returns TRUE if p satisfies some criteria defined by c, otherwise FALSE is returned.
Pre
p # NIL 20
TYPE FigureChooser
ABSTRACT
The FigureChooser provides a way to find figures that satisfies certain criteria.
PROCEDURE (c: FigureChooser) Choose (f: Figure): BOOLEAN
NEW, ABSTRACT
Returns TRUE if f satisfies some criteria defined by c, otherwise FALSE is returned.
Pre
f # NIL 20
TYPE Directory
ABSTRACT
Directory for models.
PROCEDURE (d: Directory) New (): Model
NEW, ABSTRACT
Returns a new model.
TYPE StdProp
Properties for figures that are needed by the editor.
minAnchorpoints: INTEGER
The minimum amount of anchorpoints the figure need.
maxAnchorpoints: INTEGER
The maximum amount of anchorpoints the figure can have.
expandable: BOOLEAN
TRUE if the figure is expandable (anchorpoints can be added or removed).
cyclic: BOOLEAN
TRUE if the figure is cyclic.
TYPE TProp
Properties for thickness.
thickness: INTEGER
The thickness in unversal units. 0 = hairline, Ports.fill = figure is filled.
TYPE ArrowProp
Properties for arrow-type figures.
type: INTEGER
The type of arrow. Can be set to noArrow, beginArrow, endArrow or doubleArrow.
TYPE UpdateMsg
Message notifying about changes in the model.
l, t, r, b: INTEGER
The area that needs to be restored.
TYPE InsertMsg
Message notifying about point or figure additions or removals.
insert: BOOLEAN
TRUE if a point or figure was added, FALSE if a point or figure was removed.
figure: Figure
The figure added or removed.
point: Point
The point added or removed.
TYPE SelectMsg
Message notifying about point or figure selections/deselections.
select: BOOLEAN
TRUE if a point or figure was selected, FALSE if a point or figure was deselected.
figure: Figure
The figure selected or deselected.
point: Point
The point selected or deselected.
TYPE AnchorMsg
Message notifying that an anchorpoint has been added to or removed from a figure.
add: BOOLEAN
TRUE if an anchorpoint was added, FALSE if an anchorpoint was removed.
figure: Figure
The figure involved in the addition or removal.
comppnt: ConstrainedPoint
The constrained point involved in the addition or removal.
anchor: Point
The point added or removed.
index: INTEGER
The point's index in the figure's list of anchorpoints.
TYPE ChangeAnchorMsg
Message notifying that an anchorpoint of a figure or constrained point was changed.
newPoint: Point
The new anchorpoint.
oldPoint: Point
The old anchorpoint.
figure: Figure
The figure involved.
compPoint: ConstrainedPoint
The constrained point involved.
index: INTEGER
The anchorpoint's index in the figure's or constrained point's list of anchorpoints.
VAR dir-: Directory
Holds directory object for models.
VAR stdDir-: Directory
Holds standard implementation of directory object for models.
PROCEDURE WritePoint (VAR wr: Stores.Writer; p: Point);
Writes to wr the point p (including its base object).
Pre
p # NIL 20
PROCEDURE WriteFigure (VAR wr: Stores.Writer; f: Figure);
Writes to wr the figure f (including its base object).
Pre
f # NIL 20
PROCEDURE ReadPoint (VAR rd: Stores.Reader; OUT point: Point);
Reads using rd the point point (including its base object) or an alien, if the required extension is not available.
PROCEDURE ReadFigure (VAR rd: Stores.Reader; OUT figure: Figure);
Reads using rd the figure figure (including its base object) or an alien, if the required extension is not available.
PROCEDURE CloneOf (source: Model): Model;
Allocates a new model of the same type as source.
Pre
source # NIL 20
PROCEDURE SetDir (d: Directory);
Sets the variable dir to d.
Pre
d # NIL 20
| Fig/Docu/Models.odc |
Map to the Fig Subsystem
User'sGuide
FigModelsdocu Models
FigViewsdocu Views
FigCmdsdocu Command package
FigBasic docu Basic figures
FigPointsdocu Points
Original version of Brahe editor:
Joakim Bjrklund - Niclas Forsen - Gabor Magyar - Peter Mitts
Changes and additions:
Joakim Bjrklund - Wolfgang Weck
Refactoring for BlackBox 2.0 as Fig subsystem
Ivan Denisov
| Fig/Docu/Sys-Map.odc |
Fig Graphical Editor
Simple, extensible graphical editor implemented as a BlackBox view.
It works by inserting free points into the drawing, and then connecting figures or constrained points to these. Points connected to figures or constrained points are called anchorpoints. Both free points and constrained points can become anchorpoints. So, we have the following basic entities:
FreePoint: The simplest building block. This point has total freedom, and can be moved around.
ConstrainedPoint: Constrained points must be connected to anchorpoints (either free or constrained),
and may have some freedom. The position of a constrained point is computed based on
its anchorpoints.
Figure: Some sort of geometrical shape, such as a line or circle. Figures must be connected
to anchorpoints (free or contrained).
The editor can be extended with new constrained points and figures, and a few basic figures and constrained points are included.
Some basic functionalities are supported:
- Deleting points and figures.
- Joining and spliting of points.
- Adding and removing anchorpoints.
- Changing of properties via the Attributes menu.
- Changing the order of displaying figures.
- A grid.
General info and basic operations
Free points are displayed as crosses. Constrained points are displayed as boxes, with a small dot in the middle. Figures are obviously displayed differently, depending on their type. Selected points are drawn with a thicker line. Selected figures have a thin outline based on their bounding box drawn around them.
To select a point or a figure, just click on it. By holding down the mouse button while draging, you can select all points or figures within a rectangular area. By holding down the Extend key you can keep the old selection. Clicking on an empty spot deselects everything.
In order to delete whatever is selected at the moment, press Backspace or Delete. Points that have depending points and depending figures that aren't selected, won't be deleted.
Figures and constrained points are activated by holding down the Alt (Windows)/Command (Mac) key and clicking on the figure or point, or by doubleclicking on the figure or point. If several figures or points occupy the same place, then this operation work on the top figure or point.
Move selected points by positioning the cursor arrow on top of one of the selected points and drag it. While the mouse button is down a shadow of the free points will be seen so you can position the points. When you're satisfied with their position, just release the button and the point will be moved. All selected points will be moved at the same time, and figures connected to the moved points will be redrawn accordingly. By holding down the Modifier key while moving points, a copy of the selection will be created at the new position. Figures' anchorpoints are also copied in addition to the selected points and figures. Constrained points are copied as constrained points only if all of their anchorpoints are selected, otherwise they're transformed into free points.
The selected points can also be moved using the cursor keys, and the points are then moved in a very fine grained maner. If the Modifier key is hold down when using the cursor keys, the points are moved on the grid. Note that it's not possible to copy points while moving with the cursor keys.
Points and figures can be cut, copied and pasted (using the Edit menu). Cut will delete everything possible from the selection. Figures' anchorpoints are also copied in addition to the selected points and figures. Constrained points are copied as constrained points only if all of their anchorpoints are selected, otherwise they're transformed into free points. To paste a previously cut/copied selection, first select a point to position the upper left corner of the selection, and the execute the paste command.
Inserting free points
To create a new free point just hold down the Modify key and click on an empty spot in the editor window, or doubleclick on an empty spot. If you also hold down the Extend key, the old selection will be kept.
Doubleclicking doesn't always work, and in that case you must insert a free point the "hard" way.
Inserting figures
In order to insert a new figure, you just select at least the minimum number of points needed and choose the wanted figure from the Brahe Extensions menu. The last selected points will be used. The unused points remain selected.
Inserting constrained points
Constrained points reposition themselves in order to always be in their correct position in relation to their anchorpoints. In order to insert a new constrained point, you just select at least the minimum number of points needed and execute the command from the Brahe Extensions menu. The last selected points will be used. The unused points remain selected.
Joining and splitting points
Splitting
Anchorpoints that are used for several figures and/or constrained points can be splitted. Select "Split Points" from the menu when you have one point selected. This operation creates new free points so that each and every one of the selected point's dependent points and figures have a copy of their own afterwards. The splitted point is deleted after the splitting, or just deselected if it's a constrained point.
Joining
Anchorpoints can be joined into one single point. Select "Join Points" from the Brahe menu when you have one or several points selected. This automatically adjusts all dependent points and figures to their new anchorpoint. The last selected point becomes the join target to which all figures and constrained points become connected.
Constrained point are only allowed to join if they are the join target, and then only if they don't depend on any of the other selected points.
Adding and removing anchorpoints
Figures and constrained points defined as BraheModels.expandable can have their anchorpoints removed or have new anchorpoints added.
Adding
Figure: Select the two anchorpoints between which you want to insert a new anchorpoint, then select the figure. The anchorpoints have to be connected directly to each other, and it must be possible to determine a single figure from those two anchorpoints, for this command to work. Then just choose "Add Anchor" from the Brahe menu to add a new anchorpoint to the figure. Figure not defined as BraheModels.cyclic can have a new anchorpoint added to either end by selecting just the single endpoint + the figure, and choosing "Add Anchor" from the Brahe menu.
Constrained Point:Select the constrained point, and the choose "Add Anchor" from the Brahe menu.
Removing
Figure: Select the anchorpoint that you want to remove, then select then figure. Then just choose "Remove Anchor" from the Brahe menu. Constrained points acting as anchorpoints can't be removed in this way.
Constrained Point: Select the anchorpoint, and then select the constrained point. Then choose "Remove Anchor" from the Braeh menu.
Changing the order of figures
In order to move figures to a position on top of all other figures, select the figures, and then select "Bring To Front" from the menu. If you instead select "Send To Back" the figures' new position will be behind all other figures. The order of the selected figures are kept.
Hiding and showing points
By choosing "Hide Points/Show Points" from the Brahe menu you can toggle the points' visibility. Selected points are always shown. No points, except selected ones, are printed. Points are shown as default.
Hiding and showing the grid
By choosing "Hide Grid/Show Grid" from the Brahe menu you can toggle the grid's visibility. An invisible grid is still enabled. The grid is shown as default.
Enabling and disabling the grid
By choosing "Enable Grid/Disable Grid" from the Brahe menu you can toggle the grid on and off. If the grid is enabled, all point insertions and moves are forced along the grid lines. The grid is enabled as default.
Force to Grid
By choosing "Force To Grid" from the Brahe menu, you can force all selected points to the nearest grid line. The grid has to be enabled for this command to work.
Set Grid Size...
By choosing "Set Grid Size..." you can change the grid through a dialog. Grid Drawing Factor determines how often a grid line should be drawn. A Grid Drawing factor of 2 will shown every second grid line, while a Grid Drawing Factor of 10 will shown every tenth grid line. The unit size can also be changed (mm, 1/16th inch or point). The default values are:
Unit size: Ports.mm
Grid: 3 * Unit size
Grid Drawing Factor: 3
| Fig/Docu/User-Man.odc |
FigViews
DEFINITION FigViews;
IMPORT Views, FigModels;
CONST
initialGrid = 108000;
initialGridDrawingFactor = 3;
points = 1; figures = 2; both = 3;
TYPE
View = POINTER TO ABSTRACT RECORD (Views.View)
(v: View) ThisModel (): FigModels.Model, EXTENSIBLE;
(v: View) GetGrid (OUT grid, gridDrawingFactor: INTEGER), NEW, ABSTRACT;
(v: View) SetGrid (grid, gridDrawingFactor: INTEGER), NEW, ABSTRACT;
(v: View) GridOn (): BOOLEAN, NEW, ABSTRACT;
(v: View) ShowingGrid (): BOOLEAN, NEW, ABSTRACT;
(v: View) ShowingPoints (): BOOLEAN, NEW, ABSTRACT;
(v: View) ToggleGrid, NEW, ABSTRACT;
(v: View) ToggleGridhiding, NEW, ABSTRACT;
(v: View) TogglePointhiding, NEW, ABSTRACT;
(v: View) RoundToGrid (VAR x, y: INTEGER), NEW, ABSTRACT;
(v: View) SelectAll, NEW, ABSTRACT;
(v: View) DeselectAll, NEW, ABSTRACT;
(v: View) SelectObject (o: FigModels.Object), NEW, ABSTRACT;
(v: View) DeselectObject (o: FigModels.Object), NEW, ABSTRACT;
(v: View) SelectedPoints (): FigModels.PointList, NEW, ABSTRACT;
(v: View) SelectedFigures (): FigModels.FigureList, NEW, ABSTRACT;
(v: View) SelectPoints (plist: FigModels.PointList), NEW, ABSTRACT;
(v: View) SelectFigures (flist: FigModels.FigureList), NEW, ABSTRACT;
(v: View) PopPoints (n: INTEGER; VAR plist: FigModels.PointList), NEW, ABSTRACT;
(v: View) PopFigures (n: INTEGER; VAR flist: FigModels.FigureList), NEW, ABSTRACT;
(v: View) GetSelections (n, type: INTEGER; OUT sel: ARRAY OF FigModels.Object),
NEW, ABSTRACT;
(v: View) IsSelected (o: FigModels.Object), NEW, ABSTRACT;
(v: View) LatestSelectedObject (type: INTEGER): FigModels.Object, NEW, ABSTRACT;
(v: View) NofSelectedObjects (type: INTEGER): INTEGER, NEW, ABSTRACT
END;
Directory = POINTER TO ABSTRACT RECORD
(d: Directory) New (m: FigModels.Model): View, NEW, ABSTRACT
END;
VAR
dir-: Directory;
stdDir-: Directory;
PROCEDURE Focus (): View;
PROCEDURE SetDir (d: Directory);
END FigViews.
FigView.View is the standard view for models as defined in FigModels.
CONST initialGrid = 108000;
The grid size for new views, in universal units (108000 = 3 * Ports.mm).
CONST initialGridDrawingFactor = 3;
The grid drawing factor for new views.
CONST points = 1;
Used in v.GetSelections, v.LatestSelectedObject and v.NofSelectedObjects as a value for the type parameter. Only points are considered.
CONST figures = 2;
Used in v.GetSelections, v.LatestSelectedObject and v.NofSelectedObjects as a value for the type parameter. Only figures are considered.
CONST both = 3;
Used in v.GetSelections, v.LatestSelectedObject and v.NofSelectedObjects as a value for the type parameter. Both points and figures are considered.
TYPE View
ABSTRACT
View for FigModels.Models.
PROCEDURE (v: View) ThisModel (): FigModels.Model;
EXTENSIBLE
Returns the view's model. Returns NIL by default if not extended.
PROCEDURE (v: View) GetGrid (OUT grid, gridDrawingFactor: INTEGER)
NEW, ABSTRACT
Returns the grid and gridDrawingFactor of the view. grid is in universal units.
PROCEDURE (v: View) SetGrid (grid, gridDrawingFactor: INTEGER)
NEW, ABSTRACT
Sets the view's grid and gridDrawingFactor. grid is in universal units.
Pre
grid > 0 20
gridDrawingFactor > 0 21
PROCEDURE (v: View) GridOn (): BOOLEAN
NEW, ABSTRACT
Returns TRUE is the grid is enabled.
PROCEDURE (v: View) ShowingGrid (): BOOLEAN
NEW, ABSTRACT
Returns TRUE is the grid is shown.
PROCEDURE (v: View) ShowingPoints (): BOOLEAN
NEW, ABSTRACT
Returns TRUE if non-selected points are shown.
PROCEDURE (v: View) ToggleGrid
NEW, ABSTRACT
Toggles the grid on and off.
PROCEDURE (v: View) ToggleGridhiding
NEW, ABSTRACT
Toggles the grid showing on and off.
PROCEDURE (v: View) TogglePointhiding
NEW, ABSTRACT
Toggle the point showing on and off.
PROCEDURE (v: View) RoundToGrid (VAR x, y: INTEGER)
NEW, ABSTRACT
Rounds x and y to nearest "grid point".
PROCEDURE (v: View) SelectAll
NEW, ABSTRACT
Selects all points and figures from the model.
PROCEDURE (v: View) DeselectAll
NEW, ABSTRACT
Deselects all points and figures.
PROCEDURE (v: View) SelectObject (o: FigModels.Object)
NEW, ABSTRACT
Selects the object o.
Pre
o # NIL 20
o IS FigModels.Point
o(FigModels.Point).Model() = v.ThisModel() 21
o IS FigModels.Figure
o(FigModels.Figure).Model() = v.ThisModel() 22
PROCEDURE (v: View) DeselectObject (o: FigModels.Object)
NEW, ABSTRACT
Deselects the object o.
Pre
o # NIL 20
o IS FigModels.Point
o(FigModels.Point).Model() = v.ThisModel() 21
o IS FigModels.Figure
o(FigModels.Figure).Model() = v.ThisModel() 22
PROCEDURE (v: View) SelectedPoints (): FigModels.PointList
NEW, ABSTRACT
Returns a list of all selected points.
PROCEDURE (v: View) SelectedFigures (): FigModels.FigureList
NEW, ABSTRACT
Returns a list of all selected figures.
PROCEDURE (v: View) SelectPoints (plist: FigModels.PointList)
NEW, ABSTRACT
Selects all points in plist.
PROCEDURE (v: View) SelectFigures (flist: FigModels.FigureList)
NEW, ABSTRACT
Selects all figures in flist.
PROCEDURE (v: View) PopPoints (n: INTEGER; OUT plist: FigModels.PointList)
NEW, ABSTRACT
plist contains a list of the n last selected points. The points returned in plist are deselected.
PRE
n > 0 20
n <= v.NofSelectedObjects(points) 21
PROCEDURE (v: View) PopFigures (n: INTEGER; OUT flist: FigModels.FigureList)
NEW, ABSTRACT
flist contains a list of the n last selected figures. The figures returned in flist are deselected.
PRE
n > 0 20
n <= v.NofSelectedObjects(figures) 21
PROCEDURE (v: View) GetSelections (n, type: INTEGER; OUT sel: ARRAY OF FigModels.Object)
NEW, ABSTRACT
Returns in sel the n latest selected objects of type.
PRE
n > 0 20
LEN(sel) >= n 21
PROCEDURE (v: View) IsSelected (o: FigModels.Object)
NEW, ABSTRACT
Returns TRUE if o is selected, otherwise FALSE.
Pre
o # NIL 20
o IS FigModels.Point
o(FigModels.Point).Model() = v.ThisModel() 21
o IS FigModels.Figure
o(FigModels.Figure).Model() = v.ThisModel() 22
PROCEDURE (v: View) LatestSelectedObject (type: INTEGER): FigModels.Object
NEW, ABSTRACT
Returns the latest selected object of type.
PROCEDURE (v: View) NofSelectedObjects (type: INTEGER): INTEGER
NEW, ABSTRACT
Returns the amount of selected objects of type.
TYPE Directory
ABSTRACT
Directory for views.
PROCEDURE (d: Directory) New (m: FigModels.Model): View
NEW, ABSTRACT
Returns a new view with m as its model.
Pre
m # NIL 20
VAR dir-: Directory
Holds directory object for views.
VAR stdDir-: Directory
Holds standard implementation of directory object for views.
PROCEDURE Focus (): View
Returns the View with the focus, or NIL if there is none.
PROCEDURE SetDir (d: Directory)
Sets the variable dir to d.
Pre
d # NIL 20
| Fig/Docu/Views.odc |
MODULE FigBasic;
IMPORT
Ports, Stores, Math, Properties, Models, Dialog, Fonts,
FigModels, FigViews;
CONST
string* = 0; vpos* = 1; hpos* = 2;
below* = 0; center* = 1; above* = 2;
currentVersion = 2; minVersion = 0; maxVersion = 2;
TYPE
(* Caption *)
Caption* = POINTER TO LIMITED RECORD (FigModels.Figure)
string: Dialog.String;
fnt: Fonts.Font;
col: Ports.Color;
l, t, r, b, baseline, vpos, hpos: INTEGER
END;
CaptionProp* = POINTER TO RECORD(Properties.Property)
string*: Dialog.String;
vpos*, hpos*: INTEGER
END;
SetCaptionPropOp = POINTER TO RECORD(Stores.Operation)
caption: Caption;
old, prop: Properties.Property
END;
(* Circle *)
Circle* = POINTER TO LIMITED RECORD (FigModels.Figure)
color: Ports.Color;
thickness: INTEGER
END;
SetCirclePropOp = POINTER TO RECORD (Stores.Operation)
c: Circle;
prop, old: Properties.Property
END;
(* Line *)
Line* = POINTER TO LIMITED RECORD (FigModels.Figure)
color: Ports.Color;
type: INTEGER;
thickness: INTEGER
END;
SetLinePropOp = POINTER TO RECORD (Stores.Operation)
line: Line;
old, prop: Properties.Property
END;
(* Oval *)
Oval* = POINTER TO LIMITED RECORD (FigModels.Figure)
color: Ports.Color;
thickness: INTEGER
END;
SetOvalPropOp = POINTER TO RECORD (Stores.Operation)
o: Oval;
prop, old: Properties.Property
END;
(* OpenBezier *)
OpenBezier* = POINTER TO LIMITED RECORD (FigModels.Figure)
color: Ports.Color;
type: INTEGER;
thickness: INTEGER
END;
SetOpenBezierPropOp = POINTER TO RECORD (Stores.Operation)
fig: OpenBezier;
old, prop: Properties.Property
END;
(* ClosedBezier *)
ClosedBezier* = POINTER TO LIMITED RECORD (FigModels.Figure)
color: Ports.Color;
thickness: INTEGER
END;
SetClosedBezierPropOp = POINTER TO RECORD (Stores.Operation)
f: ClosedBezier;
prop, old: Properties.Property
END;
(* Polygon *)
Polygon* = POINTER TO LIMITED RECORD (FigModels.Figure)
color: Ports.Color;
thickness: INTEGER
END;
SetPolygonPropOp = POINTER TO RECORD (Stores.Operation)
p: Polygon;
prop, old: Properties.Property
END;
(* Rectangle *)
Rectangle* = POINTER TO LIMITED RECORD (FigModels.Figure)
color: Ports.Color;
thickness: INTEGER
END;
SetPropOp = POINTER TO RECORD (Stores.Operation)
r: Rectangle;
prop, old: Properties.Property
END;
VAR
dlgCaption*: RECORD
string*: Dialog.String;
pos*: INTEGER
END;
(* Caption *)
PROCEDURE UpdateBox (c: Caption);
VAR asc, dsc, h, w: INTEGER; str: Dialog.String;
BEGIN
Dialog.MapString(c.string, str);
c.fnt.GetBounds(asc, dsc, w); h := asc + dsc; w := c.fnt.StringWidth(str);
IF c.vpos = center THEN c.b := h DIV 2 ELSIF c.vpos = above THEN c.b := 0 ELSE c.b := h END;
c.t := c.b - h; c.baseline := c.b - dsc;
IF c.hpos = center THEN c.r := w DIV 2 ELSIF c.hpos = above THEN c.r := w ELSE c.r := 0 END;
c.l := c.r - w
END UpdateBox;
PROCEDURE (p: CaptionProp) IntersectWith* (q: Properties.Property; OUT equal: BOOLEAN);
VAR valid: SET;
BEGIN
WITH q: CaptionProp DO
valid := p.valid * q.valid;
IF p.string # q.string THEN EXCL(valid, string) END;
IF p.vpos # q.vpos THEN EXCL(valid, vpos) END;
IF p.hpos # q.hpos THEN EXCL(valid, hpos) END;
equal := valid = p.valid; p.valid := valid
END
END IntersectWith;
PROCEDURE GetCaptionProperties (c: Caption; OUT p: Properties.Property);
VAR stdProp: Properties.StdProp; prop: CaptionProp;
BEGIN
NEW(stdProp);
stdProp.valid := {Properties.typeface, Properties.size, Properties.style, Properties.weight, Properties.color};
stdProp.known := stdProp.valid;
stdProp.typeface := c.fnt.typeface; stdProp.size := c.fnt.size; stdProp.style.val := c.fnt.style;
stdProp.style.mask := {Fonts.italic, Fonts.underline, Fonts.strikeout};
stdProp.weight := c.fnt.weight; stdProp.color.val := c.col;
p := stdProp;
NEW(prop); prop.string := c.string; prop.vpos := c.vpos; prop.hpos := c.hpos;
prop.valid := {string, vpos, hpos}; prop.known := p.valid;
Properties.Insert(p, prop)
END GetCaptionProperties;
PROCEDURE SetCaptionProperties (c: Caption; p: Properties.Property);
VAR size, weight: INTEGER; style: SET; typeface: Fonts.Typeface;
BEGIN
WHILE p # NIL DO
WITH p: Properties.StdProp DO
IF Properties.typeface IN p.valid THEN
typeface := p.typeface
ELSE
typeface := c.fnt.typeface
END;
IF Properties.size IN p.valid THEN size := p.size ELSE size := c.fnt.size END;
IF Properties.style IN p.valid THEN style := c.fnt.style - p.style.mask + (p.style.mask * p.style.val)
ELSE style := c.fnt.style
END;
IF Properties.weight IN p.valid THEN weight := p.weight ELSE weight := c.fnt.weight END;
IF (typeface # c.fnt.typeface) OR (size # c.fnt.size) OR (style # c.fnt.style) OR (weight # c.fnt.weight) THEN
c.fnt := Fonts.dir.This(typeface, size, style, weight)
END;
IF Properties.color IN p.valid THEN c.col := p.color.val END
| p: CaptionProp DO
IF string IN p.valid THEN c.string := p.string END;
IF vpos IN p.valid THEN c.vpos := p.vpos END;
IF hpos IN p.valid THEN c.hpos := p.hpos END
ELSE
END;
p := p.next
END
END SetCaptionProperties;
(* SetPropOp *)
PROCEDURE (op: SetCaptionPropOp) Do;
VAR p: Properties.Property; msg: Models.UpdateMsg;
BEGIN
p := op.prop; op.prop := op.old; op.old := p;
SetCaptionProperties(op.caption, p); UpdateBox(op.caption);
Models.Broadcast(op.caption.Model(), msg)
END Do;
PROCEDURE (c: Caption) Internalize- (VAR rd: Stores.Reader);
VAR version, size, weight: INTEGER; style: SET; typeface: Fonts.Typeface;
BEGIN
rd.ReadVersion(minVersion, maxVersion, version);
IF ~rd.cancelled THEN
rd.ReadString(c.string);
rd.ReadString(typeface); rd.ReadInt(size); rd.ReadSet(style); rd.ReadInt(weight);
c.fnt := Fonts.dir.This(typeface, size, style, weight);
rd.ReadInt(c.col); rd.ReadInt(c.vpos); rd.ReadInt(c.hpos);
UpdateBox(c)
END
END Internalize;
PROCEDURE (c: Caption) Externalize- (VAR wr: Stores.Writer);
VAR f: Fonts.Font;
BEGIN
wr.WriteVersion(currentVersion);
wr.WriteString(c.string);
f := c.fnt;
wr.WriteString(f.typeface); wr.WriteInt(f.size); wr.WriteSet(f.style); wr.WriteInt(f.weight);
wr.WriteInt(c.col); wr.WriteInt(c.vpos); wr.WriteInt(c.hpos)
END Externalize;
PROCEDURE (c: Caption) CopyFrom- (source: Stores.Store);
BEGIN
WITH source: Caption DO
c.string := source.string; c.fnt := source.fnt; c.col := source.col;
c.l := source.l; c.t := source.t; c.r := source.r; c.b := source.b; c.baseline := source.baseline;
c.vpos := source.vpos; c.hpos := source.hpos
END
END CopyFrom;
PROCEDURE (c: Caption) Draw* (f: Ports.Frame; l_, t_, r_, b_: INTEGER);
VAR fnt: Fonts.Font; str: Dialog.String;
BEGIN
fnt := c.fnt;
Dialog.MapString(c.string, str);
f.DrawString(c.l + c.Anchors().This().X(), c.baseline + c.Anchors().This().Y(), c.col, str, fnt)
END Draw;
PROCEDURE (c: Caption) GetBoundingBox* (OUT l, t, r, b: INTEGER);
BEGIN
l := c.Anchors().This().X() + c.l; t := c.Anchors().This().Y() + c.t;
r := c.Anchors().This().X() + c.r; b := c.Anchors().This().Y() + c.b
END GetBoundingBox;
PROCEDURE (c: Caption) PollProp* (OUT p: Properties.Property);
BEGIN
GetCaptionProperties(c, p)
END PollProp;
PROCEDURE (c: Caption) SetProp* (p: Properties.Property);
VAR equal: BOOLEAN; op: SetCaptionPropOp; prop, old: Properties.Property;
BEGIN
GetCaptionProperties(c, old); prop := Properties.CopyOf(p); Properties.Intersect(prop, old, equal);
IF ~equal THEN
NEW(op); op.caption := c; op.prop := Properties.CopyOf(p); op.old := old;
Models.Do(c.Model(), "Set Properties", op)
END
END SetProp;
PROCEDURE (c: Caption) Action*;
VAR res: INTEGER; cmd: Dialog.String;
BEGIN
Dialog.MapString("#Fig:Captions.Prop", cmd); Dialog.Call(cmd, "", res)
END Action;
PROCEDURE NewCaption* (string: Dialog.String; fnt: Fonts.Font; col: Ports.Color; vpos, hpos: INTEGER): Caption;
VAR c: Caption;
BEGIN
NEW(c); c.string := string; c.fnt := fnt; c.col := col; c.vpos := vpos; c.hpos := hpos; UpdateBox(c);
RETURN c
END NewCaption;
PROCEDURE InsertCaption*;
VAR m: FigModels.Model; p: FigModels.PointList; v: FigViews.View; c: Caption;
BEGIN
v := FigViews.Focus();
IF v # NIL THEN
m := v.ThisModel();
IF v.NofSelectedObjects(FigViews.points) # 0 THEN
v.PopPoints(1, p);
c := NewCaption("Caption", Fonts.dir.Default(), Ports.defaultColor, center, center);
m.InsertObject(c, p, FigModels.undefined, FigModels.undefined);
v.SelectObject(c)
END
END
END InsertCaption;
(* Property Editor *)
PROCEDURE InitCaptionDialog*;
VAR p: Properties.Property;
BEGIN
dlgCaption.string := ""; dlgCaption.pos := -1;
Properties.CollectProp(p);
WHILE (p # NIL) & ~(p IS CaptionProp) DO p := p.next END;
IF p # NIL THEN
WITH p: CaptionProp DO
IF string IN p.valid THEN dlgCaption.string := p.string END;
IF (vpos IN p.valid) & (hpos IN p.valid) THEN dlgCaption.pos := p.vpos + 4 * p.hpos END
END
END;
Dialog.Update(dlgCaption)
END InitCaptionDialog;
PROCEDURE SetCaption*;
VAR p: CaptionProp;
BEGIN
NEW(p);
p.string := dlgCaption.string; p.vpos := dlgCaption.pos MOD 4; p.hpos := dlgCaption.pos DIV 4;
p.known := {string, vpos, hpos}; p.valid := p.known;
IF dlgCaption.string = "" THEN EXCL(p.valid, string) END;
IF ((p.vpos # below) & (p.vpos # center) & (p.vpos # above))
OR ((p.hpos # below) & (p.hpos # center) & (p.hpos # above))
THEN EXCL(p.valid, vpos); EXCL(p.valid, hpos)
END;
IF p.valid # {} THEN Properties.EmitProp(NIL, p) END
END SetCaption;
(* Circle *)
PROCEDURE (c: Circle) CopyFrom- (source: Stores.Store);
BEGIN
WITH source: Circle DO
c.color := source.color;
c.thickness := source.thickness
END
END CopyFrom;
PROCEDURE (c: Circle) Externalize- (VAR wr: Stores.Writer);
BEGIN
wr.WriteVersion(currentVersion);
wr.WriteInt(c.color);
wr.WriteInt(c.thickness)
END Externalize;
PROCEDURE (c: Circle) Internalize- (VAR rd: Stores.Reader);
VAR version: INTEGER;
BEGIN
rd.ReadVersion(minVersion, maxVersion, version);
IF ~rd.cancelled THEN
rd.ReadInt(c.color);
IF version > 0 THEN rd.ReadInt(c.thickness) ELSE c.thickness := 0 END
END
END Internalize;
PROCEDURE (c: Circle) Covers* (x, y: INTEGER): BOOLEAN;
VAR radius, radius2, x0, x1, y0, y1, t: INTEGER;
BEGIN
x0 := c.Anchors().Next().This().X(); y0 := c.Anchors().Next().This().Y();
x1 := c.Anchors().This().X(); y1 := c.Anchors().This().Y();
radius := SHORT(ENTIER(Math.Sqrt(Math.IntPower(x0 - x1, 2) + Math.IntPower(y0 - y1, 2))));
x0 := c.Anchors().Next().This().X(); y0 := c.Anchors().Next().This().Y();
x1 := x; y1 := y;
radius2 := SHORT(ENTIER(Math.Sqrt(Math.IntPower(x0 - x1, 2) + Math.IntPower(y0 - y1, 2))));
IF c.thickness = Ports.fill THEN RETURN radius2 <= radius + Ports. mm
ELSE
t := c.thickness DIV 2; radius := radius - t;
RETURN (radius2 <= radius + t + Ports.mm) & (radius2 >= radius - t - Ports.mm)
END
END Covers;
PROCEDURE (c: Circle) Draw* (f: Ports.Frame; l_, t_, r_, b_: INTEGER);
VAR radius, x0, x1, y0, y1: INTEGER;
BEGIN
x0 := c.Anchors().Next().This().X(); y0 := c.Anchors().Next().This().Y();
x1 := c.Anchors().This().X(); y1 := c.Anchors().This().Y();
radius := SHORT(ENTIER(Math.Sqrt(Math.IntPower(x0 - x1, 2) + Math.IntPower(y0 - y1, 2))));
f.DrawOval(x0 - radius, y0 - radius, x0 + radius, y0 + radius, c.thickness, c.color)
END Draw;
PROCEDURE (c: Circle) GetBoundingBox* (OUT l, t, r, b: INTEGER);
VAR radius, tmp: INTEGER;
BEGIN
radius := SHORT(ENTIER(Math.Sqrt(Math.IntPower(c.Anchors().Next().This().X() - c.Anchors().This().X(), 2) + Math.IntPower(c.Anchors().Next().This().Y() - c.Anchors().This().Y(), 2))));
l := c.Anchors().Next().This().X() - radius; t := c.Anchors().Next().This().Y() - radius;
r := c.Anchors().Next().This().X() + radius; b := c.Anchors().Next().This().Y() + radius;
IF (r - l) < Ports.mm * 3 THEN tmp := (Ports.mm * 3 - (r - l)) DIV 2; DEC(l, tmp); INC(r, tmp) END;
IF (b - t) < Ports.mm * 3 THEN tmp := (Ports.mm * 3 - (b - t)) DIV 2; DEC(t, tmp); INC(b, tmp) END
END GetBoundingBox;
PROCEDURE GetCircleProperties (c: Circle; OUT p: Properties.Property);
VAR stdProp: Properties.StdProp;
TProp: FigModels.TProp;
BEGIN
NEW(stdProp); stdProp.color.val := c.color; stdProp.known := {Properties.color}; stdProp.valid := stdProp.known;
Properties.Insert(p, stdProp);
NEW(TProp); TProp.thickness := c.thickness; TProp.known := {FigModels.thickness}; TProp.valid := TProp.known;
Properties.Insert(p, TProp)
END GetCircleProperties;
PROCEDURE (c: Circle) PollProp* (OUT p: Properties.Property);
BEGIN
GetCircleProperties(c, p)
END PollProp;
PROCEDURE SetCircleProperties (c: Circle; p: Properties.Property);
BEGIN
WHILE p # NIL DO
WITH p: Properties.StdProp DO
IF Properties.color IN p.valid THEN c.color := p.color.val END
| p: FigModels.TProp DO
IF FigModels.thickness IN p.valid THEN c.thickness := p.thickness END
ELSE
END;
p := p.next
END
END SetCircleProperties;
PROCEDURE (op: SetCirclePropOp) Do;
VAR p: Properties.Property; msg: Models.UpdateMsg;
BEGIN
p := op.prop; op.prop := op.old; op.old := p;
SetCircleProperties(op.c, p);
Models.Broadcast(op.c.Model(), msg)
END Do;
PROCEDURE (c: Circle) SetProp* (p: Properties.Property);
VAR equal: BOOLEAN;
op: SetCirclePropOp;
prop, old: Properties.Property;
BEGIN
GetCircleProperties(c, old); prop := Properties.CopyOf(p); Properties.Intersect(prop, old, equal);
IF ~equal THEN
NEW(op); op.c := c; op.prop := Properties.CopyOf(p); op.old := old;
Models.Do(c.Model(), "SetProperties", op)
END
END SetProp;
PROCEDURE (c: Circle) Action*;
VAR res: INTEGER; cmd: ARRAY 256 OF CHAR;
BEGIN
Dialog.MapString("#Fig:Thickness.Prop", cmd); Dialog.Call(cmd, "", res)
END Action;
PROCEDURE NewCircle* (col: Ports.Color; thickness: INTEGER): Circle;
VAR c: Circle;
BEGIN
IF thickness # Ports.fill THEN ASSERT(thickness >= 0, 20) END;
NEW(c); c.color := col; c.thickness := thickness; RETURN c
END NewCircle;
PROCEDURE InsertCircle*;
VAR v: FigViews.View; m: FigModels.Model; p: FigModels.PointList; c: Circle;
BEGIN
v := FigViews.Focus();
IF v # NIL THEN
m := v.ThisModel();
IF (v.NofSelectedObjects(FigViews.points) >= 2) THEN
v.PopPoints(2, p); c := NewCircle(Ports.defaultColor, 0);
m.InsertObject(c, p, FigModels.undefined, FigModels.undefined);
v.SelectObject(c)
END
END
END InsertCircle;
(* Line *)
PROCEDURE GetLineProperties (line: Line; OUT p: Properties.Property);
VAR stdProp: Properties.StdProp;
braheProp: FigModels.StdProp;
prop:FigModels.ArrowProp;
TProp: FigModels.TProp;
BEGIN
NEW(stdProp);
stdProp.color.val := line.color;
stdProp.valid := {Properties.color}; stdProp.known := {Properties.color};
Properties.Insert(p, stdProp);
NEW(braheProp);
braheProp.maxAnchors := FigModels.undefined; braheProp.minAnchors := 2;
braheProp.expandable := TRUE; braheProp.cyclic := FALSE;
braheProp.valid := {FigModels.expandable, FigModels.cyclic, FigModels.minAnchors,
FigModels.maxAnchors};
braheProp.known := braheProp.valid;
Properties.Insert(p, braheProp);
NEW(prop); prop.type := line.type; prop.valid := {FigModels.type}; prop.known := prop.valid;
Properties.Insert(p, prop);
NEW(TProp); TProp.thickness := line.thickness;
TProp.known := {FigModels.thickness}; TProp.valid := TProp.known;
Properties.Insert(p, TProp)
END GetLineProperties;
PROCEDURE SetLineProperties (line: Line; p: Properties.Property);
BEGIN
WHILE p # NIL DO
WITH p: Properties.StdProp DO
IF Properties.color IN p.valid THEN line.color := p.color.val END
| p: FigModels.ArrowProp DO
IF FigModels.type IN p.valid THEN line.type := p.type END
| p: FigModels.TProp DO
IF FigModels.thickness IN p.valid THEN line.thickness := p.thickness END
ELSE
END;
p := p.next
END
END SetLineProperties;
(* SetPropOp *)
PROCEDURE (op: SetLinePropOp) Do;
VAR p: Properties.Property;
msg: Models.UpdateMsg;
BEGIN
p := op.prop; op.prop := op.old; op.old := p;
SetLineProperties(op.line, p);
Models.Broadcast(op.line.Model(), msg)
END Do;
PROCEDURE (line: Line) CopyFrom- (source: Stores.Store);
BEGIN
WITH source: Line DO
line.color := source.color;
line.type := source.type;
line.thickness := source.thickness
END
END CopyFrom;
PROCEDURE (line: Line) Externalize- (VAR wr: Stores.Writer);
BEGIN
wr.WriteVersion(currentVersion);
wr.WriteInt(line.color);
wr.WriteInt(line.type);
wr.WriteInt(line.thickness)
END Externalize;
PROCEDURE (line: Line) Internalize- (VAR rd: Stores.Reader);
VAR version: INTEGER;
BEGIN
rd.ReadVersion(minVersion, maxVersion, version);
IF ~rd.cancelled THEN
rd.ReadInt(line.color);
IF version = 0 THEN
line.type := FigModels.noArrow;
line.thickness := 0
ELSIF version = 1 THEN
rd.ReadInt(line.type);
line.thickness := 0
ELSIF version > 1 THEN
rd.ReadInt(line.type);
rd.ReadInt(line.thickness)
END
END
END Internalize;
PROCEDURE (line: Line) Covers* (x, y: INTEGER): BOOLEAN;
VAR r2: REAL; p: FigModels.PointList; a, b: FigModels.Point;
PROCEDURE IsClose (x0, y0: INTEGER; a, b: FigModels.Point; r2: REAL): BOOLEAN;
VAR x, y, dx, dy, ax, ay, bx, by, f, d: REAL;
BEGIN
ax := a.X(); ay := a.Y(); bx := b.X(); by := b.Y();
dx := bx - ax; dy := by - ay;
IF (dx # 0) OR (dy # 0) THEN
f := (dx * (x0 - ax) + dy * (y0 - ay)) / (dx * dx + dy * dy);
x := ax + dx * f; y := ay + dy * f
ELSE x := ax; y := ay
END;
d := Math.IntPower(x0 - x, 2) + Math.IntPower(y0 - y, 2);
IF d < r2 THEN
IF bx # x THEN RETURN (x - ax) / (bx - x) >= 0
ELSIF by # y THEN RETURN (y - ay) / (by - y) >= 0
ELSE RETURN TRUE
END
ELSE RETURN FALSE
END
END IsClose;
BEGIN
r2 := Math.IntPower(line.thickness DIV 2 + 2 * Ports.mm, 2);
p := line.Anchors(); a := p.This(); p := p.Next(); b := p.This();
WHILE (p # NIL) & ~IsClose(x, y, a, b, r2) DO
a := b; p := p.Next();
IF p # NIL THEN b := p.This() END
END;
RETURN p # NIL
END Covers;
PROCEDURE (line: Line) Draw* (f: Ports.Frame; l_, t_, r_, b_: INTEGER);
VAR p: FigModels.PointList;
arrLen, i, n, newX, newY, dx, dy: INTEGER;
arrAngle, angle: REAL;
A: POINTER TO ARRAY OF Ports.Point;
PROCEDURE Sign (x: INTEGER ) : INTEGER;
BEGIN IF x < 0 THEN RETURN - 1 ELSE RETURN 1 END
END Sign;
PROCEDURE GetPoint (x, y, dx, dy_: INTEGER; angle: REAL; len: INTEGER; VAR aX, aY: INTEGER);
BEGIN
aX := SHORT(x - ENTIER(Math.Cos(angle) * len) * Sign(dx));
aY := SHORT(y - ENTIER(Math.Sin(angle) * len) * Sign(dx))
END GetPoint;
PROCEDURE DrawArrow (f: Ports.Frame; x1, y1, x2, y2, len: INTEGER; col: Ports.Color);
VAR angle: REAL;
dx, dy: INTEGER;
ax1, ay1, ax2, ay2: INTEGER;
A: ARRAY 3 OF Ports.Point;
BEGIN
dx := x2 - x1; dy := y2 - y1;
IF dx # 0 THEN angle := Math.ArcTan (dy / dx) ELSE angle := Sign (dy) * (Math.Pi() / 2) END;
GetPoint (x2, y2, dx, dy, angle - arrAngle / 2, len, ax1, ay1);
GetPoint (x2, y2, dx, dy, angle + arrAngle / 2, len, ax2, ay2);
A[0].x := ax1; A[0].y := ay1; A[1].x := x2; A[1].y := y2; A[2].x := ax2; A[2].y := ay2;
f.DrawPath(A, 3, Ports.fill, col, Ports.closedPoly)
END DrawArrow;
BEGIN
arrLen := line.thickness * 2; arrAngle := Math.Pi() / 3;
IF arrLen < Ports.mm * 4 THEN arrLen := Ports.mm * 4 END;
p := line.Anchors(); i := 0; n := 0;
WHILE p # NIL DO INC(n); p := p.Next() END;
p := line.Anchors(); NEW(A, n);
WHILE p # NIL DO A[i].x := p.This().X(); A[i].y :=p.This().Y(); p := p.Next(); INC(i) END;
IF (line.type = FigModels.beginArrow) OR (line.type = FigModels.doubleArrow) THEN
DrawArrow(f, A[1].x, A[1].y, A[0].x, A[0].y, arrLen, line.color);
dx := A[0].x - A[1].x; dy := A[0].y - A[1].y;
IF dx # 0 THEN angle := Math.ArcTan (dy / dx) ELSE angle := Sign (dy) * (Math.Pi() / 2) END;
GetPoint(A[0].x, A[0].y, dx, dy, angle, arrLen - Ports.mm * 2, newX, newY);
A[0].x := newX; A[0].y := newY
END;
IF (line.type = FigModels.endArrow) OR (line.type = FigModels.doubleArrow) THEN
DrawArrow(f, A[n - 2].x, A[n - 2].y, A[n - 1].x, A[n - 1].y, arrLen, line.color);
dx := A[n - 1].x - A[n - 2].x; dy := A[n - 1].y - A[n - 2].y;
IF dx # 0 THEN angle := Math.ArcTan (dy / dx) ELSE angle := Sign (dy) * (Math.Pi() / 2) END;
GetPoint(A[n - 1].x, A[n - 1].y, dx, dy, angle, arrLen - Ports.mm * 2, newX, newY);
A[n - 1].x := newX; A[n - 1].y := newY
END;
f.DrawPath(A, i, line.thickness, line.color, Ports.openPoly)
END Draw;
PROCEDURE (line: Line) GetBoundingBox* (OUT l, t, r, b: INTEGER);
VAR x: INTEGER;
plist: FigModels.PointList;
BEGIN
plist := line.Anchors();
IF plist # NIL THEN
l := plist.This().X(); r := plist.This().X(); t := plist.This().Y(); b := plist.This().Y();
plist := plist.Next();
WHILE plist # NIL DO
l := MIN(l, plist.This().X()); r := MAX(r, plist.This().X());
t := MIN(t, plist.This().Y()); b := MAX(b, plist.This().Y());
plist := plist.Next()
END
END;
IF line.thickness > 0 THEN x := line.thickness DIV 2; DEC(l, x); DEC(t, x); INC(r, x); INC(b, x) END;
IF line.type # FigModels.noArrow THEN
x := line.thickness DIV 2;
IF x < Ports.mm * 2 THEN x := Ports.mm *2 END;
DEC(l, x); DEC(t, x); INC(r, x); INC(b, x)
END;
IF (r - l) < Ports.mm * 3 THEN x := (Ports.mm * 3 - (r - l)) DIV 2; DEC(l, x); INC(r, x) END;
IF (b - t) < Ports.mm * 3 THEN x := (Ports.mm * 3 - (b - t)) DIV 2; DEC(t, x); INC(b, x) END
END GetBoundingBox;
PROCEDURE (line: Line) PollProp* (OUT p: Properties.Property);
BEGIN
GetLineProperties(line, p)
END PollProp;
PROCEDURE (line: Line) SetProp* (p: Properties.Property);
VAR equal: BOOLEAN;
op: SetLinePropOp;
prop, old: Properties.Property;
BEGIN
GetLineProperties(line, old); prop := Properties.CopyOf(p); Properties.Intersect(prop, old, equal);
IF ~equal THEN
NEW(op); op.line := line; op.prop := Properties.CopyOf(p); op.old := old;
Models.Do(line.Model(), "Set Properties", op)
END
END SetProp;
PROCEDURE (line: Line) Action*;
VAR res: INTEGER; cmd: Dialog.String;
BEGIN
Dialog.MapString("#Fig:Line.Prop", cmd); Dialog.Call(cmd, "", res)
END Action;
PROCEDURE NewLine* (col: Ports.Color; type, thickness: INTEGER): Line;
VAR l: Line;
BEGIN
IF thickness # Ports.fill THEN ASSERT(thickness >= 0, 20) END;
NEW(l); l.color := col; l.type := type; l.thickness := thickness; RETURN l
END NewLine;
PROCEDURE InsertLine*;
VAR nrofsel: INTEGER; v: FigViews.View; m: FigModels.Model; p: FigModels.PointList; l: Line;
BEGIN
v:=FigViews.Focus();
IF v # NIL THEN
m := v.ThisModel();
nrofsel := v.NofSelectedObjects(FigViews.points);
IF nrofsel >= 2 THEN
v.PopPoints(nrofsel, p);
l := NewLine(Ports.defaultColor, FigModels.noArrow, 0);
m.InsertObject(l, p, FigModels.undefined, FigModels.undefined);
v.SelectObject(l)
END
END
END InsertLine;
(* Oval *)
PROCEDURE (o: Oval) CopyFrom- (source: Stores.Store);
BEGIN
WITH source: Oval DO
o.color := source.color; o.thickness := source.thickness
END
END CopyFrom;
PROCEDURE (o: Oval) Externalize- (VAR wr: Stores.Writer);
BEGIN
wr.WriteVersion(currentVersion);
wr.WriteInt(o.color); wr.WriteInt(o.thickness)
END Externalize;
PROCEDURE (o: Oval) Internalize- (VAR rd: Stores.Reader);
VAR version: INTEGER;
BEGIN
rd.ReadVersion(minVersion, maxVersion, version);
IF ~rd.cancelled THEN
rd.ReadInt(o.color); rd.ReadInt(o.thickness)
END
END Internalize;
PROCEDURE GetBounds (o: Oval; OUT l, t, r, b: INTEGER);
VAR h: INTEGER; p: FigModels.Point;
BEGIN
p := o.Anchors().This(); l := p.X(); t := p.Y();
p := o.Anchors().Next().This(); r := p.X(); b := p.Y();
IF l > r THEN h := l; l := r; r := h END;
IF t > b THEN h := t; t := b; b := h END
END GetBounds;
PROCEDURE (o: Oval) Covers* (x, y: INTEGER): BOOLEAN;
VAR l, t, r, b, d: INTEGER;
BEGIN
GetBounds(o, l, t, r, b); x := x - (l + r) DIV 2; y := y - (t + b) DIV 2;
IF o.thickness # Ports.fill THEN
d := o.thickness + 2 * Ports.mm;
RETURN (Math.IntPower(2 * x / (r - l - 2 * d), 2) + Math.IntPower(2 * y / (b - t - d), 2) >= 1)
& (Math.IntPower(2 * x / (r - l + 2 * Ports.mm), 2) + Math.IntPower(2 * y / (b - t + 2 * Ports.mm), 2) <= 1)
ELSE
RETURN (Math.IntPower(2 * x / (r - l + 2 * Ports.mm), 2) + Math.IntPower(2 * y / (b - t + 2 * Ports.mm), 2) <= 1)
END
END Covers;
PROCEDURE (o: Oval) Draw* (f: Ports.Frame; l_, t_, r_, b_: INTEGER);
VAR x0, y0, x1, y1: INTEGER;
BEGIN
GetBounds(o, x0, y0, x1, y1); f.DrawOval(x0, y0, x1, y1, o.thickness, o.color)
END Draw;
PROCEDURE (o: Oval) GetBoundingBox* (OUT l, t, r, b: INTEGER);
VAR h: INTEGER;
BEGIN
GetBounds(o, l, t, r, b);
IF r - l < Ports.mm * 3 THEN h := (Ports.mm * 3 - (r - l)) DIV 2; DEC(l, h); INC(r, h) END;
IF b - t < Ports.mm * 3 THEN h := (Ports.mm * 3 - (b - t)) DIV 2; DEC(t, h); INC(b, h) END
END GetBoundingBox;
PROCEDURE GetOvalProperties (o: Oval; OUT p: Properties.Property);
VAR stdProp: Properties.StdProp; tProp: FigModels.TProp;
BEGIN
NEW(stdProp);
stdProp.color.val := o.color; stdProp.known := {Properties.color}; stdProp.valid := stdProp.known;
Properties.Insert(p, stdProp);
NEW(tProp);
tProp.thickness := o.thickness; tProp.known := {FigModels.thickness}; tProp.valid := tProp.known;
Properties.Insert(p, tProp)
END GetOvalProperties;
PROCEDURE (o: Oval) PollProp* (OUT p: Properties.Property);
BEGIN
GetOvalProperties(o, p)
END PollProp;
PROCEDURE SetOvalProperties (o: Oval; p: Properties.Property);
BEGIN
WHILE p # NIL DO
WITH p: Properties.StdProp DO
IF Properties.color IN p.valid THEN o.color := p.color.val END
| p: FigModels.TProp DO
IF FigModels.thickness IN p.valid THEN o.thickness := p.thickness END
ELSE
END;
p := p.next
END
END SetOvalProperties;
PROCEDURE (op: SetOvalPropOp) Do;
VAR p: Properties.Property; msg: Models.UpdateMsg;
BEGIN
p := op.prop; op.prop := op.old; op.old := p;
SetOvalProperties(op.o, p);
Models.Broadcast(op.o.Model(), msg)
END Do;
PROCEDURE (o: Oval) SetProp* (p: Properties.Property);
VAR equal: BOOLEAN; op: SetOvalPropOp; prop, old: Properties.Property;
BEGIN
GetOvalProperties(o, old); prop := Properties.CopyOf(p); Properties.Intersect(prop, old, equal);
IF ~equal THEN
NEW(op); op.o := o; op.prop := Properties.CopyOf(p); op.old := old;
Models.Do(o.Model(), "Set Properties", op)
END
END SetProp;
PROCEDURE (o: Oval) Action*;
VAR res: INTEGER; cmd: ARRAY 256 OF CHAR;
BEGIN
Dialog.MapString("#Fig:Thickness.Prop", cmd); Dialog.Call(cmd, "", res)
END Action;
PROCEDURE NewOval* (col: Ports.Color; thickness: INTEGER): Oval;
VAR o: Oval;
BEGIN
IF thickness # Ports.fill THEN ASSERT(thickness >= 0, 20) END;
NEW(o); o.color := col; o.thickness := thickness; RETURN o
END NewOval;
PROCEDURE InsertOval*;
VAR v: FigViews.View; m: FigModels.Model; p: FigModels.PointList; o: Oval;
BEGIN
v := FigViews.Focus();
IF v # NIL THEN
m := v.ThisModel();
IF v.NofSelectedObjects(FigViews.points) >= 2 THEN
v.PopPoints(2, p); o := NewOval(Ports.defaultColor, 0);
m.InsertObject(o, p, FigModels.undefined, FigModels.undefined);
v.SelectObject(o)
END
END
END InsertOval;
(* OpenBezier *)
PROCEDURE GetOpenBezierProperties (fig: OpenBezier; OUT p: Properties.Property);
VAR stdProp: Properties.StdProp;
prop: FigModels.ArrowProp;
TProp: FigModels.TProp;
BEGIN
NEW(stdProp); stdProp.color.val := fig.color;
stdProp.valid := {Properties.color}; stdProp.known := {Properties.color};
Properties.Insert(p, stdProp);
NEW(prop); prop.type := fig.type; prop.valid := {FigModels.type}; prop.known := prop.valid;
Properties.Insert(p, prop);
NEW(TProp); TProp.thickness := fig.thickness;
TProp.known := {FigModels.thickness}; TProp.valid := TProp.known;
Properties.Insert(p, TProp)
END GetOpenBezierProperties;
PROCEDURE SetOpenBezierProperties (fig: OpenBezier; p: Properties.Property);
BEGIN
WHILE p # NIL DO
WITH p: Properties.StdProp DO
IF Properties.color IN p.valid THEN fig.color := p.color.val END
| p: FigModels.ArrowProp DO
IF FigModels.type IN p.valid THEN fig.type := p.type END
| p: FigModels.TProp DO
IF FigModels.thickness IN p.valid THEN fig.thickness := p.thickness END
ELSE
END;
p := p.next
END
END SetOpenBezierProperties;
(* SetOpenBezierPropOp *)
PROCEDURE (op: SetOpenBezierPropOp) Do;
VAR p: Properties.Property;
msg: Models.UpdateMsg;
BEGIN
p := op.prop; op.prop := op.old; op.old := p;
SetOpenBezierProperties(op.fig, p);
Models.Broadcast(op.fig.Model(), msg)
END Do;
PROCEDURE (fig: OpenBezier) CopyFrom- (source: Stores.Store);
BEGIN
WITH source: OpenBezier DO
fig.color := source.color;
fig.type := source.type;
fig.thickness := source.thickness
END
END CopyFrom;
PROCEDURE (fig: OpenBezier) Externalize- (VAR wr: Stores.Writer);
BEGIN
wr.WriteVersion(currentVersion);
wr.WriteInt(fig.color);
wr.WriteInt(fig.type);
wr.WriteInt(fig.thickness)
END Externalize;
PROCEDURE (fig: OpenBezier) Internalize- (VAR rd: Stores.Reader);
VAR version: INTEGER;
BEGIN
rd.ReadVersion(minVersion, maxVersion, version);
IF ~rd.cancelled THEN
rd.ReadInt(fig.color);
rd.ReadInt(fig.type);
rd.ReadInt(fig.thickness)
END
END Internalize;
PROCEDURE (fig: OpenBezier) Draw* (f: Ports.Frame; l_, t_, r_, b_: INTEGER);
VAR p: FigModels.PointList;
arrLen, i, n, newX, newY, dx, dy: INTEGER;
arrAngle, angle: REAL;
A: POINTER TO ARRAY OF Ports.Point;
PROCEDURE Sign (x: INTEGER ) : INTEGER;
BEGIN IF x < 0 THEN RETURN - 1 ELSE RETURN 1 END
END Sign;
PROCEDURE GetPoint (x, y, dx, dy_: INTEGER; angle: REAL; len: INTEGER; VAR aX, aY: INTEGER);
BEGIN
aX := SHORT(x - ENTIER(Math.Cos(angle) * len) * Sign(dx));
aY := SHORT(y - ENTIER(Math.Sin(angle) * len) * Sign(dx))
END GetPoint;
PROCEDURE DrawArrow (f: Ports.Frame; x1, y1, x2, y2, len: INTEGER; col: Ports.Color);
VAR angle: REAL;
dx, dy: INTEGER;
ax1, ay1, ax2, ay2: INTEGER;
A: ARRAY 3 OF Ports.Point;
BEGIN
dx := x2 - x1; dy := y2 - y1;
IF dx # 0 THEN angle := Math.ArcTan ( dy / dx ) ELSE angle := Sign (dy) * (Math.Pi() / 2) END;
GetPoint ( x2, y2, dx, dy, angle - arrAngle / 2, len, ax1, ay1);
GetPoint ( x2, y2, dx, dy, angle + arrAngle / 2, len, ax2, ay2);
A[0].x := ax1; A[0].y := ay1; A[1].x := x2; A[1].y := y2; A[2].x := ax2; A[2].y := ay2;
f.DrawPath(A, 3, Ports.fill, col, Ports.closedPoly)
END DrawArrow;
BEGIN
arrLen := fig.thickness * 2; arrAngle := Math.Pi() / 3;
IF arrLen < Ports.mm * 4 THEN arrLen := Ports.mm * 4 END;
p := fig.Anchors(); i := 0; n := 0;
WHILE p # NIL DO INC(n); p := p.Next() END;
p := fig.Anchors(); NEW(A, n);
WHILE p # NIL DO A[i].x := p.This().X(); A[i].y :=p.This().Y(); p := p.Next(); INC(i) END;
IF (fig.type = FigModels.beginArrow) OR (fig.type = FigModels.doubleArrow) THEN
DrawArrow(f, A[1].x, A[1].y, A[0].x, A[0].y, arrLen, fig.color);
dx := A[0].x - A[1].x; dy := A[0].y - A[1].y;
IF dx # 0 THEN angle := Math.ArcTan ( dy / dx ) ELSE angle := Sign (dy) * (Math.Pi() / 2) END;
GetPoint(A[0].x, A[0].y, dx, dy, angle, arrLen - Ports.mm * 2, newX, newY);
A[0].x := newX; A[0].y := newY
END;
IF (fig.type = FigModels.endArrow) OR (fig.type = FigModels.doubleArrow) THEN
DrawArrow(f, A[n - 2].x, A[n - 2].y, A[n - 1].x, A[n - 1].y, arrLen, fig.color);
dx := A[n - 1].x - A[n - 2].x; dy := A[n - 1].y - A[n - 2].y;
IF dx # 0 THEN angle := Math.ArcTan ( dy / dx ) ELSE angle := Sign (dy) * (Math.Pi() / 2) END;
GetPoint(A[n - 1].x, A[n - 1].y, dx, dy, angle, arrLen - Ports.mm * 2, newX, newY);
A[n - 1].x := newX; A[n - 1].y := newY
END;
f.DrawPath(A, i, fig.thickness, fig.color, Ports.openBezier)
END Draw;
PROCEDURE (fig: OpenBezier) GetBoundingBox* (OUT l, t, r, b: INTEGER);
VAR x: INTEGER;
plist: FigModels.PointList;
BEGIN
plist := fig.Anchors();
IF plist # NIL THEN
l := plist.This().X(); r := plist.This().X(); t := plist.This().Y(); b := plist.This().Y();
plist := plist.Next();
WHILE plist # NIL DO
l := MIN(l, plist.This().X()); r := MAX(r, plist.This().X());
t := MIN(t, plist.This().Y()); b := MAX(b, plist.This().Y());
plist := plist.Next()
END
END;
IF fig.thickness > 0 THEN x := fig.thickness DIV 2; DEC(l, x); DEC(t, x); INC(r, x); INC(b, x) END;
IF (r - l) < Ports.mm * 3 THEN x := (Ports.mm * 3 - (r - l)) DIV 2; DEC(l, x); INC(r, x) END;
IF (b - t) < Ports.mm * 3 THEN x := (Ports.mm * 3 - (b - t)) DIV 2; DEC(t, x); INC(b, x) END
END GetBoundingBox;
PROCEDURE (fig: OpenBezier) PollProp* (OUT p: Properties.Property);
BEGIN
GetOpenBezierProperties(fig, p)
END PollProp;
PROCEDURE (fig: OpenBezier) SetProp* (p: Properties.Property);
VAR equal: BOOLEAN;
op: SetOpenBezierPropOp;
prop, old: Properties.Property;
BEGIN
GetOpenBezierProperties(fig, old); prop := Properties.CopyOf(p); Properties.Intersect(prop, old, equal);
IF ~equal THEN
NEW(op); op.fig := fig; op.prop := Properties.CopyOf(p); op.old := old;
Models.Do(fig.Model(), "Set Properties", op)
END
END SetProp;
PROCEDURE (fig: OpenBezier) Action*;
VAR res: INTEGER; cmd: Dialog.String;
BEGIN
Dialog.MapString("#Fig:Bezier.Prop", cmd); Dialog.Call(cmd, "", res)
END Action;
PROCEDURE NewOpenBezier* (col: Ports.Color; type, thickness: INTEGER): OpenBezier;
VAR f: OpenBezier;
BEGIN
IF thickness # Ports.fill THEN ASSERT(thickness >= 0, 20) END;
NEW(f); f.color := col; f.type := type; f.thickness := thickness; RETURN f
END NewOpenBezier;
PROCEDURE InsertOpenBezier*;
VAR nrofsel: INTEGER;
v: FigViews.View; m: FigModels.Model; p: FigModels.PointList; f: OpenBezier;
BEGIN
v:=FigViews.Focus();
IF v # NIL THEN
m := v.ThisModel();
nrofsel := v.NofSelectedObjects(FigViews.points);
IF nrofsel >= 2 THEN
v.PopPoints(nrofsel, p); f := NewOpenBezier(Ports.defaultColor, FigModels.noArrow, 0);
m.InsertObject(f, p, FigModels.undefined, FigModels.undefined);
v.SelectObject(f)
END
END
END InsertOpenBezier;
PROCEDURE InsertOpenBezierGuard* (VAR par: Dialog.Par);
VAR v: FigViews.View;
n: INTEGER;
BEGIN
v := FigViews.Focus(); IF v # NIL THEN n := v.NofSelectedObjects(FigViews.points) END;
par.disabled := (v = NIL) OR (n < 4) OR (n MOD 3 # 1)
END InsertOpenBezierGuard;
(* ClosedBezier *)
PROCEDURE (fig: ClosedBezier) CopyFrom- (source: Stores.Store);
BEGIN
WITH source: ClosedBezier DO
fig.color := source.color;
fig.thickness := source.thickness
END
END CopyFrom;
PROCEDURE (fig: ClosedBezier) Externalize- (VAR wr: Stores.Writer);
BEGIN
wr.WriteVersion(currentVersion);
wr.WriteInt(fig.color);
wr.WriteInt(fig.thickness)
END Externalize;
PROCEDURE (fig: ClosedBezier) Internalize- (VAR rd: Stores.Reader);
VAR version: INTEGER;
BEGIN
rd.ReadVersion(minVersion, maxVersion, version);
IF ~rd.cancelled THEN
rd.ReadInt(fig.color);
rd.ReadInt(fig.thickness)
END
END Internalize;
PROCEDURE (fig: ClosedBezier) Draw* (f: Ports.Frame; l_, t_, r_, b_: INTEGER);
VAR p: FigModels.PointList;
A: POINTER TO ARRAY OF Ports.Point;
i, n: INTEGER;
BEGIN
p := fig.Anchors(); i := 0; n := 0;
WHILE p # NIL DO INC(n); p := p.Next() END;
p := fig.Anchors(); NEW(A, n);
WHILE p # NIL DO A[i].x := p.This().X(); A[i].y :=p.This().Y(); p := p.Next(); INC(i) END;
f.DrawPath(A, i, fig.thickness, fig.color, Ports.closedBezier)
END Draw;
PROCEDURE (fig: ClosedBezier) GetBoundingBox* (OUT l, t, r, b: INTEGER);
VAR x: INTEGER;
plist: FigModels.PointList;
BEGIN
plist := fig.Anchors();
IF plist # NIL THEN
l := plist.This().X(); r := plist.This().X();
t := plist.This().Y(); b := plist.This().Y();
plist := plist.Next();
WHILE plist # NIL DO
l := MIN(l, plist.This().X()); r := MAX(r, plist.This().X());
t := MIN(t, plist.This().Y()); b := MAX(b, plist.This().Y());
plist := plist.Next()
END
END;
IF fig.thickness > 0 THEN x := fig.thickness DIV 2; DEC(l, x); DEC(t, x); INC(r, x); INC(b, x) END;
IF (r - l) < Ports.mm * 3 THEN x := (Ports.mm * 3 - (r - l)) DIV 2; DEC(l, x); INC(r, x) END;
IF (b - t) < Ports.mm * 3 THEN x := (Ports.mm * 3 - (b - t)) DIV 2; DEC(t, x); INC(b, x) END
END GetBoundingBox;
PROCEDURE GetProperties (fig: ClosedBezier; OUT p: Properties.Property);
VAR stdProp: Properties.StdProp;
TProp: FigModels.TProp;
BEGIN
NEW(stdProp);
stdProp.color.val := fig.color;
stdProp.known := {Properties.color}; stdProp.valid := stdProp.known;
Properties.Insert(p, stdProp);
NEW(TProp);
TProp.thickness := fig.thickness;
TProp.known := {FigModels.thickness}; TProp.valid := TProp.known;
Properties.Insert(p, TProp)
END GetProperties;
PROCEDURE (fig: ClosedBezier) PollProp* (OUT p: Properties.Property);
BEGIN
GetProperties(fig, p)
END PollProp;
PROCEDURE SetProperties (fig: ClosedBezier; p: Properties.Property);
BEGIN
WHILE p # NIL DO
WITH p: Properties.StdProp DO
IF Properties.color IN p.valid THEN fig.color := p.color.val END
| p: FigModels.TProp DO
IF FigModels.thickness IN p.valid THEN fig.thickness := p.thickness END
ELSE
END;
p := p.next
END
END SetProperties;
PROCEDURE (op: SetClosedBezierPropOp) Do;
VAR p: Properties.Property; msg: Models.UpdateMsg;
BEGIN
p := op.prop; op.prop := op.old; op.old := p;
SetProperties(op.f, p);
Models.Broadcast(op.f.Model(), msg)
END Do;
PROCEDURE (fig: ClosedBezier) SetProp* (p: Properties.Property);
VAR equal: BOOLEAN;
op: SetClosedBezierPropOp;
prop, old: Properties.Property;
BEGIN
GetProperties(fig, old); prop := Properties.CopyOf(p); Properties.Intersect(prop, old, equal);
IF ~equal THEN
NEW(op); op.f := fig; op.prop := Properties.CopyOf(p); op.old := old;
Models.Do(fig.Model(), "SetProperties", op)
END
END SetProp;
PROCEDURE (fig: ClosedBezier) Action*;
VAR res: INTEGER; cmd: ARRAY 256 OF CHAR;
BEGIN
Dialog.MapString("#Fig:Thickness.Prop", cmd); Dialog.Call(cmd, "", res)
END Action;
PROCEDURE NewClosedBezier* (col: Ports.Color; thickness: INTEGER): ClosedBezier;
VAR f: ClosedBezier;
BEGIN
IF thickness # Ports.fill THEN ASSERT(thickness >= 0, 20) END;
NEW(f); f.color := col; f.thickness := thickness; RETURN f
END NewClosedBezier;
PROCEDURE InsertClosedBezier*;
VAR nrofsel: INTEGER;
v: FigViews.View; m: FigModels.Model; p: FigModels.PointList; f: ClosedBezier;
BEGIN
v := FigViews.Focus();
IF v # NIL THEN
m := v.ThisModel(); nrofsel := v.NofSelectedObjects(FigViews.points);
IF nrofsel >= 3 THEN
v.PopPoints(nrofsel, p); f := NewClosedBezier(Ports.defaultColor, 0);
m.InsertObject(f, p, FigModels.undefined, FigModels.undefined);
v.SelectObject(f)
END
END
END InsertClosedBezier;
PROCEDURE InsertClosedBezierGuard* (VAR par: Dialog.Par);
VAR v: FigViews.View;
n: INTEGER;
BEGIN
v := FigViews.Focus(); IF v # NIL THEN n := v.NofSelectedObjects(FigViews.points) END;
par.disabled := (v = NIL) OR (n < 3) OR (n MOD 3 # 0)
END InsertClosedBezierGuard;
(* Polygon *)
PROCEDURE (fig: Polygon) CopyFrom- (source: Stores.Store);
BEGIN
WITH source: Polygon DO
fig.color := source.color;
fig.thickness := source.thickness
END
END CopyFrom;
PROCEDURE (fig: Polygon) Externalize- (VAR wr: Stores.Writer);
BEGIN
wr.WriteVersion(currentVersion);
wr.WriteInt(fig.color);
wr.WriteInt(fig.thickness)
END Externalize;
PROCEDURE (fig: Polygon) Internalize- (VAR rd: Stores.Reader);
VAR version: INTEGER;
BEGIN
rd.ReadVersion(minVersion, maxVersion, version);
IF ~rd.cancelled THEN
rd.ReadInt(fig.color);
IF version > 0 THEN rd.ReadInt(fig.thickness) ELSE fig.thickness := 0 END
END
END Internalize;
PROCEDURE (fig: Polygon) Covers * (x, y: INTEGER): BOOLEAN;
VAR r2: REAL; p: FigModels.PointList; a, b: FigModels.Point;
l, t, r, bot: INTEGER;
PROCEDURE IsClose (x0, y0: INTEGER; a, b: FigModels.Point; r2: REAL): BOOLEAN;
VAR x, y, dx, dy, f, d: REAL;
BEGIN
dx := b.X() - a.X(); dy := b.Y() - a.Y();
IF (dx # 0) OR (dy # 0) THEN
f := (dx * (x0 - a.X()) + dy * (y0 - a.Y())) / (dx * dx + dy * dy);
x := a.X() + dx * f; y := a.Y() + dy * f
ELSE x := a.X(); y := a.Y()
END;
d := Math.IntPower(x0 - x, 2) + Math.IntPower(y0 - y, 2);
IF d < r2 THEN
IF b.X() # x THEN RETURN (x - a.X()) / (b.X() - x) >= 0
ELSIF b.Y() # y THEN RETURN (y - a.Y()) / (b.Y() - y) >= 0
ELSE RETURN TRUE
END
ELSE RETURN FALSE
END
END IsClose;
BEGIN
IF fig.thickness # Ports.fill THEN
r2 := Math.IntPower(fig.thickness DIV 2 + 2 * Ports.mm, 2);
p := fig.Anchors(); a := p.This(); p := p.Next(); b := p.This();
WHILE (p # NIL) & ~IsClose(x, y, a, b, r2) DO
a := b; p := p.Next(); IF p # NIL THEN b := p.This() END
END;
IF p # NIL THEN
RETURN p # NIL
ELSE
a := fig.Anchors().This(); RETURN IsClose(x, y, a, b, r2)
END
ELSE
fig.Model().GetBoundingBox(fig.Anchors(), NIL, l, t, r, bot);
RETURN (l <= x) & (x <= r) & (t <= y) & (y <= bot)
END
END Covers;
PROCEDURE (fig: Polygon) Draw* (f: Ports.Frame; l_, t_, r_, b_: INTEGER);
VAR p: FigModels.PointList;
A: POINTER TO ARRAY OF Ports.Point;
i, n: INTEGER;
BEGIN
p := fig.Anchors(); i := 0; n := 0;
WHILE p # NIL DO INC(n); p := p.Next() END;
p := fig.Anchors(); NEW(A, n);
WHILE p # NIL DO A[i].x := p.This().X(); A[i].y :=p.This().Y(); p := p.Next(); INC(i) END;
f.DrawPath(A, i, fig.thickness, fig.color, Ports.closedPoly)
END Draw;
PROCEDURE (fig: Polygon) GetBoundingBox* (OUT l, t, r, b: INTEGER);
VAR x: INTEGER;
plist: FigModels.PointList;
BEGIN
plist := fig.Anchors();
IF plist # NIL THEN
l := plist.This().X(); r := plist.This().X(); t := plist.This().Y(); b := plist.This().Y();
plist := plist.Next();
WHILE plist # NIL DO
l := MIN(l, plist.This().X()); r := MAX(r, plist.This().X());
t := MIN(t, plist.This().Y()); b := MAX(b, plist.This().Y());
plist := plist.Next()
END
END;
IF fig.thickness > 0 THEN x := fig.thickness DIV 2; DEC(l, x); DEC(t, x); INC(r, x); INC(b, x) END;
IF (r - l) < Ports.mm * 3 THEN x := (Ports.mm * 3 - (r - l)) DIV 2; DEC(l, x); INC(r, x) END;
IF (b - t) < Ports.mm * 3 THEN x := (Ports.mm * 3 - (b - t)) DIV 2; DEC(t, x); INC(b, x) END
END GetBoundingBox;
PROCEDURE GetPolygonProperties (fig: Polygon; OUT p: Properties.Property);
VAR stdProp: Properties.StdProp;
braheProp: FigModels.StdProp;
TProp: FigModels.TProp;
BEGIN
NEW(stdProp); stdProp.color.val := fig.color; stdProp.known := {Properties.color}; stdProp.valid := stdProp.known;
Properties.Insert(p, stdProp);
NEW(braheProp);
braheProp.maxAnchors := FigModels.undefined; braheProp.minAnchors := 3;
braheProp.expandable := TRUE; braheProp.cyclic := TRUE;
braheProp.valid := {FigModels.expandable, FigModels.cyclic,
FigModels.minAnchors, FigModels.maxAnchors};
braheProp.known := braheProp.valid;
Properties.Insert(p, braheProp);
NEW(TProp);
TProp.thickness := fig.thickness;
TProp.known := {FigModels.thickness};
TProp.valid := TProp.known;
Properties.Insert(p, TProp)
END GetPolygonProperties;
PROCEDURE (fig: Polygon) PollProp* (OUT p: Properties.Property);
BEGIN
GetPolygonProperties(fig, p)
END PollProp;
PROCEDURE SetPolygonProperties (fig: Polygon; p: Properties.Property);
BEGIN
WHILE p # NIL DO
WITH p: Properties.StdProp DO
IF Properties.color IN p.valid THEN fig.color := p.color.val END
| p: FigModels.TProp DO
IF FigModels.thickness IN p.valid THEN fig.thickness := p.thickness END
ELSE
END;
p := p.next
END
END SetPolygonProperties;
PROCEDURE (op: SetPolygonPropOp) Do;
VAR p: Properties.Property; msg: Models.UpdateMsg;
BEGIN
p := op.prop; op.prop := op.old; op.old := p;
SetPolygonProperties(op.p, p);
Models.Broadcast(op.p.Model(), msg)
END Do;
PROCEDURE (fig: Polygon) SetProp* (p: Properties.Property);
VAR equal: BOOLEAN;
op: SetPolygonPropOp;
prop, old: Properties.Property;
BEGIN
GetPolygonProperties(fig, old);
prop := Properties.CopyOf(p); Properties.Intersect(prop, old, equal);
IF ~equal THEN
NEW(op); op.p := fig; op.prop := Properties.CopyOf(p); op.old := old;
Models.Do(fig.Model(), "SetProperties", op)
END
END SetProp;
PROCEDURE (fig: Polygon) Action*;
VAR res: INTEGER; cmd: ARRAY 256 OF CHAR;
BEGIN
Dialog.MapString("#Fig:Thickness.Prop", cmd); Dialog.Call(cmd, "", res)
END Action;
PROCEDURE NewPolygon* (col: Ports.Color; thickness: INTEGER): Polygon;
VAR p: Polygon;
BEGIN
IF thickness # Ports.fill THEN ASSERT(thickness >= 0, 20) END;
NEW(p); p.color := col; p.thickness := thickness; RETURN p
END NewPolygon;
PROCEDURE InsertPolygon*;
VAR nrofsel: INTEGER;
v: FigViews.View; m: FigModels.Model; p: FigModels.PointList; fig: Polygon;
BEGIN
v := FigViews.Focus();
IF v # NIL THEN
m := v.ThisModel(); nrofsel := v.NofSelectedObjects(FigViews.points);
IF nrofsel >= 3 THEN
v.PopPoints(nrofsel, p); fig := NewPolygon(Ports.defaultColor, 0);
m.InsertObject(fig, p, FigModels.undefined, FigModels.undefined);
v.SelectObject(fig)
END
END
END InsertPolygon;
(* Rectangle *)
PROCEDURE (rect: Rectangle) CopyFrom- (source: Stores.Store);
BEGIN
WITH source: Rectangle DO
rect.color := source.color;
rect.thickness := source.thickness
END
END CopyFrom;
PROCEDURE (rect: Rectangle) Externalize- (VAR wr: Stores.Writer);
BEGIN
wr.WriteVersion(currentVersion);
wr.WriteInt(rect.color);
wr.WriteInt(rect.thickness)
END Externalize;
PROCEDURE (rect: Rectangle) Internalize- (VAR rd: Stores.Reader);
VAR version: INTEGER;
BEGIN
rd.ReadVersion(minVersion, maxVersion, version);
IF ~rd.cancelled THEN
rd.ReadInt(rect.color);
IF version > 0 THEN rd.ReadInt(rect.thickness) ELSE rect.thickness := 0 END
END
END Internalize;
PROCEDURE GetRectangleBounds (rect: Rectangle; OUT l, t, r, b: INTEGER);
VAR h: INTEGER; p: FigModels.Point;
BEGIN
p := rect.Anchors().This(); l := p.X(); t := p.Y();
p := rect.Anchors().Next().This(); r := p.X(); b := p.Y();
IF l > r THEN h := l; l := r; r := h END;
IF t > b THEN h := t; t := b; b := h END
END GetRectangleBounds;
PROCEDURE (rect: Rectangle) Covers* (x, y: INTEGER): BOOLEAN;
VAR l, t, r, b, th, d: INTEGER;
BEGIN
GetRectangleBounds(rect, l, t, r, b); d := Ports.mm * 2;
IF rect.thickness # Ports.fill THEN
th := rect.thickness;
RETURN ((l-d <= x) & (l+d+th >= x) OR (r-d-th <= x) & (r+d >= x)) & (t-d <= y) & (b+d >= y)
OR ((t-d <= y) & (t+d+th >= y) OR (b-d-th <= y) & (b+d >= y)) & (l-d <= x) & (r+d >= x)
ELSE
RETURN (l - d <= x) & (r + d >= x) & (t - d <= y) & (b + d >= y)
END
END Covers;
PROCEDURE (rect: Rectangle) Draw* (f: Ports.Frame; l_, t_, r_, b_: INTEGER);
VAR x0, y0, x1, y1: INTEGER;
BEGIN
GetRectangleBounds(rect, x0, y0, x1, y1);
f.DrawRect(x0, y0, x1, y1, rect.thickness, rect.color)
END Draw;
PROCEDURE (rect: Rectangle) GetBoundingBox* (OUT l, t, r, b: INTEGER);
VAR tmp: INTEGER;
BEGIN
GetRectangleBounds(rect, l, t, r, b);
IF (r - l) < Ports.mm * 3 THEN tmp := (Ports.mm * 3 - (r - l)) DIV 2; DEC(l, tmp); INC(r, tmp) END;
IF (b - t) < Ports.mm * 3 THEN tmp := (Ports.mm * 3 - (b - t)) DIV 2; DEC(t, tmp); INC(b, tmp) END
END GetBoundingBox;
PROCEDURE GetRectangleProperties (r: Rectangle; OUT p: Properties.Property);
VAR stdProp: Properties.StdProp; tProp: FigModels.TProp;
BEGIN
NEW(stdProp);
stdProp.color.val := r.color; stdProp.known := {Properties.color}; stdProp.valid := stdProp.known;
Properties.Insert(p, stdProp);
NEW(tProp);
tProp.thickness := r.thickness; tProp.known := {FigModels.thickness}; tProp.valid := tProp.known;
Properties.Insert(p, tProp)
END GetRectangleProperties;
PROCEDURE (rect: Rectangle) PollProp* (OUT p: Properties.Property);
BEGIN
GetRectangleProperties(rect, p)
END PollProp;
PROCEDURE SetRectangleProperties (r: Rectangle; p: Properties.Property);
BEGIN
WHILE p # NIL DO
WITH p: Properties.StdProp DO
IF Properties.color IN p.valid THEN r.color := p.color.val END
| p: FigModels.TProp DO
IF FigModels.thickness IN p.valid THEN r.thickness := p.thickness END
ELSE
END;
p := p.next
END
END SetRectangleProperties;
PROCEDURE (op: SetPropOp) Do;
VAR p: Properties.Property; msg: Models.UpdateMsg;
BEGIN
p := op.prop; op.prop := op.old; op.old := p;
SetRectangleProperties(op.r, p);
Models.Broadcast(op.r.Model(), msg)
END Do;
PROCEDURE (rect: Rectangle) SetProp* (p: Properties.Property);
VAR equal: BOOLEAN;
op: SetPropOp;
prop, old: Properties.Property;
BEGIN
GetRectangleProperties(rect, old); prop := Properties.CopyOf(p); Properties.Intersect(prop, old, equal);
IF ~equal THEN
NEW(op); op.r := rect; op.prop := Properties.CopyOf(p); op.old := old;
Models.Do(rect.Model(), "Set Properties", op)
END
END SetProp;
PROCEDURE (rect: Rectangle) Action*;
VAR res: INTEGER; cmd: ARRAY 256 OF CHAR;
BEGIN
Dialog.MapString("#Fig:Thickness.Prop", cmd); Dialog.Call(cmd, "", res)
END Action;
PROCEDURE NewRectangle* (col: Ports.Color; thickness: INTEGER): Rectangle;
VAR r: Rectangle;
BEGIN
IF thickness # Ports.fill THEN ASSERT(thickness >= 0, 20) END;
NEW(r); r.color := col; r.thickness := thickness; RETURN r
END NewRectangle;
PROCEDURE InsertRectangle*;
VAR v: FigViews.View; m: FigModels.Model; p: FigModels.PointList; r: Rectangle;
BEGIN
v := FigViews.Focus();
IF v # NIL THEN
m := v.ThisModel();
IF v.NofSelectedObjects(FigViews.points) >= 2 THEN
v.PopPoints(2, p); r := NewRectangle(Ports.defaultColor, 0);
m.InsertObject(r, p, FigModels.undefined, FigModels.undefined);
v.SelectObject(r)
END
END
END InsertRectangle;
END FigBasic.
| Fig/Mod/Basic.odc |
MODULE FigCmds;
IMPORT
Services, Ports, Properties, Stores, Models, Views, Dialog, StdCmds,
FigModels, FigViews;
CONST
mm* = 0; inch* = 1; point* = 2; fill* = 3; hairline* = 4;
VAR
gridDlg*: RECORD
grid*, gridDrawingFactor*: INTEGER;
unitType*: INTEGER
END;
TPropDlg*: RECORD
thickness*: INTEGER;
type*: INTEGER;
initiated*: BOOLEAN
END;
arrowPropDlg*: RECORD
type*: INTEGER;
initiated*: BOOLEAN
END;
PROCEDURE SelectAnchors*;
VAR i, nofSel: INTEGER; v: FigViews.View;
s: Stores.Store; sel: POINTER TO ARRAY OF FigModels.Object;
BEGIN
v := FigViews.Focus();
IF v # NIL THEN
nofSel := v.NofSelectedObjects(FigViews.both);
IF nofSel # 0 THEN
NEW(sel, nofSel); v.GetSelections(nofSel, FigViews.both, sel);
i := 0;
WHILE i # nofSel DO
s := sel[i];
WITH s: FigModels.ConstrainedPoint DO v.SelectPoints(s.Anchors())
| s: FigModels.Figure DO v.SelectPoints(s.Anchors())
ELSE
END;
INC(i)
END
END
END
END SelectAnchors;
PROCEDURE SelectAnchorsGuard*(VAR par: Dialog.Par);
VAR v: FigViews.View;
BEGIN
v := FigViews.Focus();
IF v # NIL THEN
par.disabled := v.NofSelectedObjects(FigViews.both) = 0
ELSE par.disabled := TRUE
END
END SelectAnchorsGuard;
PROCEDURE PollFigureProp (f: FigModels.Figure; OUT prop: FigModels.StdProp);
VAR p: Properties.Property;
BEGIN
f.PollProp(p); WHILE (p # NIL) & ~(p IS FigModels.StdProp) DO p := p.next END;
IF p # NIL THEN prop := p(FigModels.StdProp) ELSE prop := NIL END
END PollFigureProp;
PROCEDURE PollPointProp (c: FigModels.ConstrainedPoint; OUT prop: FigModels.StdProp);
VAR p: Properties.Property;
BEGIN
c.PollProp(p); WHILE (p # NIL) & ~(p IS FigModels.StdProp) DO p := p.next END;
IF p # NIL THEN prop := p(FigModels.StdProp) ELSE prop := NIL END
END PollPointProp;
PROCEDURE CanBeExtended (anchors: FigModels.PointList; prop: FigModels.StdProp): BOOLEAN;
PROCEDURE ListLength (l: FigModels.PointList): INTEGER;
VAR n: INTEGER;
BEGIN
n := 0; WHILE l # NIL DO INC(n); l := l.Next() END;
RETURN n
END ListLength;
BEGIN
RETURN (prop # NIL) & (FigModels.expandable IN prop.valid) & prop.expandable
& (FigModels.maxAnchors IN prop.valid)
& ((prop.maxAnchors = FigModels.undefined) OR (prop.maxAnchors > ListLength(anchors)))
END CanBeExtended;
PROCEDURE GetAddAnchorPar (OUT model: FigModels.Model; OUT view: FigViews.View;
OUT fig: FigModels.Figure; OUT pnt: FigModels.ConstrainedPoint;
OUT pos: INTEGER);
VAR nofP, nofF: INTEGER; v: FigViews.View;
m: FigModels.Model; prop: FigModels.StdProp; plist, q: FigModels.PointList;
p1, p2, q1, q2: FigModels.Point; f: FigModels.Figure; p: FigModels.ConstrainedPoint;
BEGIN
model := NIL; fig := NIL; pnt := NIL; v := FigViews.Focus(); view := v;
IF v # NIL THEN
m := v.ThisModel();
nofP := v.NofSelectedObjects(FigViews.points); nofF := v.NofSelectedObjects(FigViews.figures);
IF (nofF = 0) & (nofP = 1) THEN
p1 := v.SelectedPoints().This();
IF p1 IS FigModels.ConstrainedPoint THEN
p := p1(FigModels.ConstrainedPoint); PollPointProp(p, prop);
IF CanBeExtended(p.Anchors(), prop) THEN model := m; pnt := p; pos := 0 END
END
ELSIF (nofF = 1) & ((nofP = 1) OR (nofP = 2)) THEN
f := v.SelectedFigures().This(); PollFigureProp(f, prop);
IF CanBeExtended(f.Anchors(), prop) THEN
IF (nofP = 1) & (FigModels.cyclic IN prop.valid) & ~prop.cyclic THEN
plist := v.SelectedPoints(); p1 := plist.This(); plist := f.Anchors();
IF plist.This() = p1 THEN model := m; fig := f; pos := 0
ELSE
q := plist.Next(); pos := 1; WHILE q # NIL DO INC(pos); plist := q; q := plist.Next() END;
IF plist.This() = p1 THEN model := m; fig := f END
END
ELSIF nofP = 2 THEN
plist := v.SelectedPoints(); p1 := plist.This(); p2 := plist.Next().This();
plist := f.Anchors(); q := plist.Next();
IF q # NIL THEN
q1 := plist.This(); q2 := q.This(); pos := 1;
WHILE (q # NIL) & ((q1 # p1) OR (q2 # p2)) & ((q1 # p2) OR (q2 # p1)) DO
plist := q; q := plist.Next(); q1 := q2;
IF q # NIL THEN q2 := q.This() END;
INC(pos)
END;
IF q # NIL THEN model := m; fig := f
ELSIF (FigModels.cyclic IN prop.valid) & prop.cyclic
& ((q1 = p1) & (f.Anchors().This() = p2) OR (q1 = p2) & (f.Anchors().This() = p1))
THEN model := m; fig := f; pos := 0
END
END
END
END
END
END
END GetAddAnchorPar;
PROCEDURE AddAnchorGuard* (VAR par: Dialog.Par);
VAR pos: INTEGER; m: FigModels.Model; f: FigModels.Figure; p: FigModels.ConstrainedPoint;
v: FigViews.View;
BEGIN
GetAddAnchorPar(m, v, f, p, pos);
par.disabled := m = NIL;
IF f # NIL THEN par.label := "Add Anchor to Figure"
ELSIF p # NIL THEN par.label := "Add Anchor to Point"
ELSE par.label := "Add Anchor"
END
END AddAnchorGuard;
PROCEDURE AddAnchor*;
VAR pos: INTEGER; m: FigModels.Model; v: FigViews.View;
f: FigModels.Figure; new: FigModels.Point; p: FigModels.ConstrainedPoint;
BEGIN
GetAddAnchorPar(m, v, f, p, pos);
IF f # NIL THEN
m.AddAnchor(f, pos, new); v.DeselectAll; v.SelectObject(new); v.SelectObject(f)
ELSIF p # NIL THEN
m.AddAnchor(p, pos, new); m.MovePoint(p, 0, 0); v.DeselectAll; v.SelectObject(new)
END
END AddAnchor;
PROCEDURE CanBeReduced (anchors: FigModels.PointList; prop: FigModels.StdProp): BOOLEAN;
PROCEDURE ListLength (l: FigModels.PointList): INTEGER;
VAR n: INTEGER;
BEGIN
n := 0; WHILE l # NIL DO INC(n); l := l.Next() END;
RETURN n
END ListLength;
BEGIN
RETURN (prop # NIL) & (FigModels.expandable IN prop.valid) & prop.expandable
& (FigModels.minAnchors IN prop.valid)
& ((prop.minAnchors = FigModels.undefined) OR (prop.minAnchors < ListLength(anchors)))
END CanBeReduced;
PROCEDURE GetRemoveAnchorPar (OUT model: FigModels.Model; OUT view: FigViews.View;
OUT fig: FigModels.Figure; OUT pnt: FigModels.ConstrainedPoint;
OUT this: FigModels.Point);
VAR nofP, nofF: INTEGER; v: FigViews.View;
m: FigModels.Model; prop: FigModels.StdProp; plist: FigModels.PointList;
p1, p2: FigModels.Point; f: FigModels.Figure; p: FigModels.ConstrainedPoint;
BEGIN
model := NIL; fig := NIL; pnt := NIL; v := FigViews.Focus(); view := v;
IF v # NIL THEN
m := v.ThisModel();
nofP := v.NofSelectedObjects(FigViews.points); nofF := v.NofSelectedObjects(FigViews.figures);
IF (nofF = 0) & (nofP = 2) THEN
plist := v.SelectedPoints(); p1 := plist.This(); p2 := plist.Next().This();
IF p1 IS FigModels.ConstrainedPoint THEN
p := p1(FigModels.ConstrainedPoint); PollPointProp(p, prop);
IF CanBeReduced(p.Anchors(), prop) THEN
plist := p.Anchors(); WHILE (plist # NIL) & (plist.This() # p2) DO plist := plist.Next() END;
IF plist # NIL THEN model := m; pnt := p; this := p2 END
END
END
ELSIF (nofF = 1) & (nofP = 1) THEN
f := v.SelectedFigures().This(); PollFigureProp(f, prop);
IF CanBeReduced(f.Anchors(), prop) THEN
p1 := v.SelectedPoints().This(); plist := f.Anchors();
WHILE (plist # NIL) & (plist.This() # p1) DO plist := plist.Next() END;
IF plist # NIL THEN model := m; fig := f; this := p1 END
END
END
END
END GetRemoveAnchorPar;
PROCEDURE RemoveAnchorGuard* (VAR par: Dialog.Par);
VAR m: FigModels.Model; f: FigModels.Figure; this: FigModels.Point;
p: FigModels.ConstrainedPoint; v: FigViews.View;
BEGIN
GetRemoveAnchorPar(m, v, f, p, this);
par.disabled := m = NIL;
IF f # NIL THEN par.label := "Remove Anchor from Figure"
ELSIF p # NIL THEN par.label := "Remove Anchor from Point"
ELSE par.label := "Remove Anchor"
END
END RemoveAnchorGuard;
PROCEDURE RemoveAnchor*;
VAR m: FigModels.Model; v: FigViews.View;
f: FigModels.Figure; this: FigModels.Point; p: FigModels.ConstrainedPoint;
s: Stores.Operation;
BEGIN
GetRemoveAnchorPar(m, v, f, p, this);
IF f # NIL THEN
Models.BeginScript(m, "Remove Anchor from Figure", s);
m.RemoveAnchor(f, this);
IF this IS FigModels.FreePoint THEN m.RemoveObject(this) END;
Models.EndScript(m, s)
ELSIF p # NIL THEN
Models.BeginScript(m, "Remove Anchor from Point", s);
m.RemoveAnchor(p, this); m.MovePoint(p, 0, 0);
IF this IS FigModels.FreePoint THEN m.RemoveObject(this) END;
Models.EndScript(m, s)
END
END RemoveAnchor;
PROCEDURE SplitPoints*;
VAR v: FigViews.View;
m: FigModels.Model;
BEGIN
v := FigViews.Focus();
IF v # NIL THEN m := v.ThisModel(); m.SplitPoint(v.SelectedPoints().This()) END
END SplitPoints;
PROCEDURE SplitPointsGuard* (VAR par: Dialog.Par);
VAR v: FigViews.View;
BEGIN
v := FigViews.Focus();
par.disabled := (v = NIL) OR (v.NofSelectedObjects(FigViews.points) # 1)
END SplitPointsGuard;
PROCEDURE JoinPoints*;
VAR v: FigViews.View;
m: FigModels.Model;
BEGIN
v := FigViews.Focus();
IF v # NIL THEN m := v.ThisModel(); m.JoinPoints(v.SelectedPoints().Next(), v.SelectedPoints().This()) END
END JoinPoints;
PROCEDURE JoinPointsGuard* (VAR par: Dialog.Par);
VAR v: FigViews.View;
m: FigModels.Model;
BEGIN
v := FigViews.Focus(); IF v # NIL THEN m := v.ThisModel() END;
par.disabled := (v = NIL) OR (v.NofSelectedObjects(FigViews.points) < 2)
OR ~(m.JoinPossible(v.SelectedPoints().Next(), v.SelectedPoints().This()))
END JoinPointsGuard;
PROCEDURE SendToBack*;
VAR v: FigViews.View;
m: FigModels.Model;
BEGIN
v := FigViews.Focus();
IF v # NIL THEN m := v.ThisModel(); m.SendToBack(v.SelectedFigures()) END
END SendToBack;
PROCEDURE SendToBackGuard* (VAR par: Dialog.Par);
VAR v: FigViews.View;
BEGIN
v := FigViews.Focus();
par.disabled := (v = NIL) OR (v.SelectedFigures() = NIL)
END SendToBackGuard;
PROCEDURE BringToFront*;
VAR v: FigViews.View;
m: FigModels.Model;
BEGIN
v := FigViews.Focus();
IF v # NIL THEN m := v.ThisModel(); m.BringToFront(v.SelectedFigures()) END
END BringToFront;
PROCEDURE BringToFrontGuard* (VAR par: Dialog.Par);
VAR v: FigViews.View;
BEGIN
v := FigViews.Focus();
par.disabled := (v = NIL) OR (v.SelectedFigures() = NIL)
END BringToFrontGuard;
PROCEDURE SetGrid*;
VAR v: FigViews.View;
unit: INTEGER;
BEGIN
IF gridDlg.unitType = mm THEN unit := Ports.mm
ELSIF gridDlg.unitType = inch THEN unit := Ports.inch DIV 16
ELSIF gridDlg.unitType = point THEN unit := Ports.point
ELSE
END;
v := FigViews.Focus();
IF v # NIL THEN v.SetGrid(gridDlg.grid * unit, gridDlg.gridDrawingFactor) END
END SetGrid;
PROCEDURE SetGridGuard*(VAR par: Dialog.Par);
VAR v: FigViews.View;
BEGIN
v := FigViews.Focus();
par.disabled := (v = NIL)
END SetGridGuard;
PROCEDURE ToggleGrid*;
VAR v: FigViews.View;
BEGIN
v := FigViews.Focus();
IF v # NIL THEN v.ToggleGrid END
END ToggleGrid;
PROCEDURE ToggleGridGuard* (VAR par: Dialog.Par);
VAR v: FigViews.View;
BEGIN
v := FigViews.Focus();
IF v # NIL THEN
IF v.GridOn() THEN par.label := "Disable Grid" ELSE par.label := "Enable Grid" END
END;
par.disabled := (v = NIL)
END ToggleGridGuard;
PROCEDURE TogglePointhiding*;
VAR v: FigViews.View;
BEGIN
v := FigViews.Focus();
IF v # NIL THEN v.TogglePointhiding END
END TogglePointhiding;
PROCEDURE TogglePointhidingGuard* (VAR par: Dialog.Par);
VAR v: FigViews.View;
BEGIN
v := FigViews.Focus();
IF v # NIL THEN
IF v.ShowingPoints() THEN par.label := "Hide Points" ELSE par.label := "Show Points" END
END;
par.disabled := (v = NIL)
END TogglePointhidingGuard;
PROCEDURE ToggleGridhiding*;
VAR v: FigViews.View;
BEGIN
v := FigViews.Focus();
IF v # NIL THEN v.ToggleGridhiding END
END ToggleGridhiding;
PROCEDURE ToggleGridhidingGuard* (VAR par: Dialog.Par);
VAR v: FigViews.View;
BEGIN
v := FigViews.Focus();
IF v # NIL THEN
IF v.ShowingGrid() THEN par.label := "Hide Grid" ELSE par.label := "Show Grid" END
END;
par.disabled := (v = NIL)
END ToggleGridhidingGuard;
PROCEDURE ForceToGrid*;
VAR m: FigModels.Model; v: FigViews.View; grid, factor: INTEGER;
BEGIN
v := FigViews.Focus();
IF v # NIL THEN m:= v.ThisModel(); v.GetGrid(grid, factor); m.MoveToGrid(v.SelectedPoints(), grid) END
END ForceToGrid;
PROCEDURE ForceToGridGuard* (VAR par: Dialog.Par);
VAR v: FigViews.View;
BEGIN
v := FigViews.Focus();
par.disabled := (v = NIL) OR ~(v.GridOn()) OR (v.SelectedPoints() = NIL)
END ForceToGridGuard;
PROCEDURE InitGridDialog*;
VAR v: FigViews.View; unit: INTEGER;
BEGIN
v := FigViews.Focus();
IF gridDlg.unitType = mm THEN unit := Ports.mm
ELSIF gridDlg.unitType = inch THEN unit := Ports.inch DIV 16
ELSIF gridDlg.unitType = point THEN unit := Ports.point
ELSE
END;
IF v # NIL THEN
v.GetGrid(gridDlg.grid, gridDlg.gridDrawingFactor);
gridDlg.grid := gridDlg.grid DIV unit
END
END InitGridDialog;
PROCEDURE GetExtensionType (OUT typename: ARRAY OF CHAR; OUT isAlien, isFree: BOOLEAN);
VAR i, j: INTEGER; v: FigViews.View; object: FigModels.Object;
BEGIN
typename := "";
v := FigViews.Focus();
IF v # NIL THEN
object := v.LatestSelectedObject(FigViews.both);
IF object # NIL THEN
WITH object: FigModels.AlienFigure DO
isAlien := TRUE; isFree := FALSE; typename := "Alien Figure"
| object: FigModels.AlienPoint DO
isAlien := TRUE; isFree := FALSE; typename := "Alien Point"
| object: FigModels.ConstrainedPoint DO
isAlien := FALSE; isFree := FALSE; Services.GetTypeName(object, typename)
| object: FigModels.FreePoint DO
isAlien := FALSE; isFree := TRUE; typename := "Free Point"
| object: FigModels.Figure DO
isAlien := FALSE; isFree := FALSE; Services.GetTypeName(object, typename)
END;
END;
IF ~isAlien & ~isFree & (typename # "") THEN
i := 0; j := 5; WHILE typename[j] # "." DO typename[i] := typename[j]; INC(i); INC(j) END;
typename[i] := 0X
END
END
END GetExtensionType;
PROCEDURE OpenExtensionDocu*;
VAR isAlien, isFree: BOOLEAN; t: ARRAY 256 OF CHAR;
BEGIN
GetExtensionType(t, isAlien, isFree);
IF ~isAlien & ~isFree THEN StdCmds.OpenBrowser('Fig/Docu/' + t, t + ' Docu') END
END OpenExtensionDocu;
PROCEDURE OpenExtensionDocuGuard* (VAR par: Dialog.Par);
VAR isAlien, isFree: BOOLEAN; t: ARRAY 256 OF CHAR;
BEGIN
GetExtensionType(t, isAlien, isFree);
IF t # "" THEN par.label := t + " Docu" ELSE par.label := "... Docu" END;
par.disabled := (t = "") OR isAlien OR isFree
END OpenExtensionDocuGuard;
PROCEDURE Deposit*;
VAR v: FigViews.View;
BEGIN
v := FigViews.stdDir.New(FigModels.dir.New());
Views.Deposit(v)
END Deposit;
PROCEDURE SelectionGuard* (nofPoints: INTEGER; VAR par: Dialog.Par);
VAR v: FigViews.View;
BEGIN
v := FigViews.Focus();
par.disabled := (v = NIL) OR (v.NofSelectedObjects(FigViews.points) < nofPoints)
END SelectionGuard;
PROCEDURE FocusGuard* (VAR par: Dialog.Par);
VAR v: FigViews.View;
BEGIN
v := FigViews.Focus();
par.disabled := (v = NIL)
END FocusGuard;
PROCEDURE UpDownGuard* (VAR par: Dialog.Par);
BEGIN
par.disabled := (TPropDlg.type = fill) OR (TPropDlg.type = hairline) OR ~TPropDlg.initiated
END UpDownGuard;
PROCEDURE GridNotifier* (op, from_, to_: INTEGER);
BEGIN
IF op = Dialog.changed THEN
IF gridDlg.grid < 1 THEN gridDlg.grid := 1 END;
IF gridDlg.gridDrawingFactor < 1 THEN gridDlg.gridDrawingFactor := 1 END;
Dialog.Update(gridDlg)
END
END GridNotifier;
PROCEDURE UpDownNotifier* (op, from_, to_: INTEGER);
BEGIN
IF op = Dialog.changed THEN
IF TPropDlg.thickness < 1 THEN TPropDlg.thickness := 1 END;
Dialog.Update(TPropDlg)
END
END UpDownNotifier;
PROCEDURE InitTPropDialog*;
VAR p: Properties.Property;
BEGIN
TPropDlg.thickness := 0; TPropDlg.type := mm; TPropDlg.initiated := FALSE;
Properties.CollectProp(p); WHILE (p # NIL) & ~(p IS FigModels.TProp) DO p := p.next END;
IF p # NIL THEN
WITH p: FigModels.TProp DO
IF FigModels.thickness IN p.valid THEN
IF p.thickness = Ports.fill THEN TPropDlg.thickness := 1; TPropDlg.type := fill
ELSIF p.thickness = 0 THEN TPropDlg.thickness := 1; TPropDlg.type := hairline
ELSIF p.thickness MOD Ports.mm = 0 THEN
TPropDlg.thickness := p.thickness DIV Ports.mm; TPropDlg.type := mm
ELSIF p.thickness MOD (Ports.inch DIV 16) = 0 THEN
TPropDlg.thickness := p.thickness DIV (Ports.inch DIV 16); TPropDlg.type := inch
ELSIF p.thickness MOD Ports.point = 0 THEN
TPropDlg.thickness := p.thickness DIV Ports.point; TPropDlg.type := point
END;
TPropDlg.initiated := TRUE
END
END
END;
Dialog.Update(TPropDlg)
END InitTPropDialog;
PROCEDURE SetTProp*;
VAR p: FigModels.TProp; unit: INTEGER;
BEGIN
IF TPropDlg.type = mm THEN unit := Ports.mm
ELSIF TPropDlg.type = inch THEN unit := Ports.inch DIV 16
ELSIF TPropDlg.type = point THEN unit := Ports.point
ELSE
END;
NEW(p);
IF TPropDlg.type = fill THEN p.thickness := Ports.fill
ELSIF TPropDlg.type = hairline THEN p.thickness := 0
ELSE p.thickness := TPropDlg.thickness * unit
END;
p.known := {FigModels.thickness}; p.valid := p.known;
IF p.valid # {} THEN Properties.EmitProp(NIL, p) END
END SetTProp;
PROCEDURE ThicknessDlgGuard* (VAR par: Dialog.Par);
BEGIN
par.disabled := ~TPropDlg.initiated
END ThicknessDlgGuard;
PROCEDURE InitArrowPropDialog*;
VAR p: Properties.Property;
BEGIN
arrowPropDlg.type := 0; arrowPropDlg.initiated := FALSE;
Properties.CollectProp(p);
WHILE (p # NIL) & ~(p IS FigModels.ArrowProp) DO p := p.next END;
IF p # NIL THEN
WITH p: FigModels.ArrowProp DO
IF FigModels.type IN p.valid THEN
arrowPropDlg.type := p.type;
arrowPropDlg.initiated := TRUE
END
ELSE
END
END;
Dialog.Update(arrowPropDlg)
END InitArrowPropDialog;
PROCEDURE SetArrowProp*;
VAR p: FigModels.ArrowProp;
BEGIN
NEW(p); p.type := arrowPropDlg.type; p.known := {FigModels.type}; p.valid := p.known;
IF arrowPropDlg.type = 0 THEN EXCL(p.valid, FigModels.type) END;
IF p.valid # {} THEN Properties.EmitProp(NIL, p) END
END SetArrowProp;
PROCEDURE ArrowDlgGuard* (VAR par: Dialog.Par);
BEGIN
par.disabled := ~arrowPropDlg.initiated
END ArrowDlgGuard;
BEGIN
gridDlg.grid := FigViews.initialGrid; gridDlg.gridDrawingFactor := FigViews.initialGridDrawingFactor;
gridDlg.unitType := mm;
TPropDlg.type := hairline; TPropDlg.initiated := FALSE;
arrowPropDlg.type := FigModels.noArrow; arrowPropDlg.initiated := FALSE
END FigCmds.
| Fig/Mod/Cmds.odc |
MODULE FigModels;
IMPORT Dialog, Ports, Stores, Models, Properties;
CONST
undefined* = -1;
last = -1;
ok = 1; toBeMoved = 2;
currentStdVersion = 3; minStdVersion = 3; maxStdVersion = 3;
currentPBVersion = 1; minPBVersion = 1; maxPBVersion = 1;
(* StdProp *)
expandable* = 0; cyclic* = 1; minAnchors* = 2; maxAnchors* = 3;
(* TProp *)
thickness* = 0;
(* ArrowProp *)
noArrow* = 1; beginArrow* = 2; endArrow* = 3; doubleArrow* = 4;
type* = 0;
currentFWVersion = 4; minFWVersion = 4; maxFWVersion = 4;
TYPE
Model* = POINTER TO LIMITED RECORD (Models.Model)
base-: ModelBase
END;
ModelBase* = POINTER TO ABSTRACT RECORD (Stores.Store)
model-: Model
END;
Directory* = POINTER TO ABSTRACT RECORD END;
PointBase* = POINTER TO ABSTRACT RECORD (Stores.Store)
ext-: Point
END;
Object* = POINTER TO ABSTRACT RECORD (Stores.Store) END;
Point* = POINTER TO ABSTRACT RECORD (Object)
base-: PointBase
END;
FreePoint* = POINTER TO LIMITED RECORD (Point) END;
ConstrainedPoint* = POINTER TO ABSTRACT RECORD (Point) END;
AlienPoint* = POINTER TO LIMITED RECORD (ConstrainedPoint)
store-: Stores.Alien
END;
PointList* = POINTER TO ABSTRACT RECORD END;
(*
StdPointList = POINTER TO RECORD (PointList)
p: Point;
next: StdPointList
END;
*)
FigureBase* = POINTER TO ABSTRACT RECORD (Stores.Store)
ext-: Figure
END;
Figure* = POINTER TO ABSTRACT RECORD (Object)
base-: FigureBase
END;
AlienFigure* = POINTER TO LIMITED RECORD (Figure)
store-: Stores.Alien
END;
FigureList* = POINTER TO ABSTRACT RECORD END;
(*
StdFigureList = POINTER TO RECORD (FigureList)
f: Figure;
next: StdFigureList
END;
*)
PointChooser* = POINTER TO ABSTRACT RECORD END;
FigureChooser* = POINTER TO ABSTRACT RECORD END;
StdProp* = POINTER TO RECORD (Properties.Property)
minAnchors*, maxAnchors*: INTEGER;
expandable*, cyclic*: BOOLEAN
END;
TProp* = POINTER TO RECORD (Properties.Property)
thickness*: INTEGER
END;
ArrowProp* = POINTER TO RECORD (Properties.Property)
type*: INTEGER
END;
UpdateMsg* = EXTENSIBLE RECORD (Models.UpdateMsg)
l*, t*, r*, b*: INTEGER
END;
InsertMsg* = RECORD (UpdateMsg)
insert*: BOOLEAN;
figure*: Figure;
point*: Point
END;
AnchorMsg* = RECORD (UpdateMsg)
add*: BOOLEAN;
figure*: Figure;
comppnt*: ConstrainedPoint;
anchor*: Point;
pos*: INTEGER
END;
ChangeAnchorMsg* = RECORD (UpdateMsg)
newPoint*: Point;
oldPoint*: Point;
figure*: Figure;
compPoint*: ConstrainedPoint;
pos*: INTEGER
END;
ThesePointsChooser = POINTER TO RECORD (PointChooser)
l, t, r, b: INTEGER
END;
TheseFiguresChooser = POINTER TO RECORD (FigureChooser)
x, y: INTEGER
END;
IntersectingFiguresChooser = POINTER TO RECORD (FigureChooser)
l, t, r, b: INTEGER
END;
IncludedFiguresChooser = POINTER TO RECORD (FigureChooser)
l, t, r, b: INTEGER
END;
TYPE
StdPointBase = POINTER TO RECORD (PointBase)
m: Model;
x, y: INTEGER;
anchors: StdPointList;
dependingPoints: StdPointList;
dependingFigures: StdFigureList;
id: INTEGER
END;
StdPointList = POINTER TO RECORD (PointList)
p: Point;
next: StdPointList;
id: INTEGER
END;
StdFigureBase = POINTER TO RECORD (FigureBase)
m: Model;
anchors: StdPointList;
id: INTEGER
END;
StdFigureList = POINTER TO RECORD (FigureList)
f: Figure;
next: StdFigureList;
id: INTEGER
END;
StdModelBase = POINTER TO RECORD (ModelBase)
points: StdPointList;
figures: StdFigureList
END;
StdDirectory = POINTER TO RECORD (Directory) END;
MoveList = POINTER TO RECORD
p: Point;
x, y: INTEGER;
next: MoveList
END;
PointOp = POINTER TO RECORD (Stores.Operation)
insert: BOOLEAN;
model: StdModelBase;
point: Point;
pos: INTEGER
END;
FigureOp = POINTER TO RECORD (Stores.Operation)
insert: BOOLEAN;
model: StdModelBase;
figure: Figure;
pos: INTEGER
END;
FigureAnchorOp = POINTER TO RECORD (Stores.Operation)
add: BOOLEAN;
depID, anchorID: INTEGER;
model: StdModelBase;
anchor: Point;
fig: Figure
END;
PointAnchorOp = POINTER TO RECORD (Stores.Operation)
add: BOOLEAN;
depID, anchorID: INTEGER;
model: StdModelBase;
anchor: Point;
deppnt: ConstrainedPoint
END;
MoveOp = POINTER TO RECORD (Stores.Operation)
m: StdModelBase;
first: BOOLEAN;
list: MoveList
END;
SwapOp = POINTER TO RECORD (Stores.Operation)
model: StdModelBase;
flist: StdFigureList;
do, front: BOOLEAN
END;
LinkOp = POINTER TO RECORD (Stores.Operation)
model: StdModelBase;
target: Point;
source: Point;
sourceList: StdPointList;
figure: Figure;
point: ConstrainedPoint
END;
VAR
dir-, stdDir-: Directory;
alienFigures: StdFigureList;
alienPoints: StdPointList;
(* FigureList *)
PROCEDURE (f: FigureList) This* (): Figure, NEW, ABSTRACT;
PROCEDURE (f: FigureList) Next* (): FigureList, NEW, ABSTRACT;
(* PointList *)
PROCEDURE (p: PointList) This* (): Point, NEW, ABSTRACT;
PROCEDURE (p: PointList) Next* (): PointList, NEW, ABSTRACT;
(* StdFigureList
PROCEDURE (f: StdFigureList) This (): Figure;
BEGIN
RETURN f.f
END This;
PROCEDURE (f: StdFigureList) Next (): FigureList;
BEGIN
RETURN f.next
END Next;
*)
(* StdPointList
PROCEDURE (p: StdPointList) This (): Point;
BEGIN
RETURN p.p
END This;
PROCEDURE (p: StdPointList) Next (): PointList;
BEGIN
RETURN p.next
END Next;
*)
(* PointBase *)
PROCEDURE (p: PointBase) Model- (): Model, NEW, ABSTRACT;
PROCEDURE (p: PointBase) X- (): INTEGER, NEW, ABSTRACT;
PROCEDURE (p: PointBase) Y- (): INTEGER, NEW, ABSTRACT;
PROCEDURE (p: PointBase) Anchors- (): PointList, NEW, ABSTRACT;
PROCEDURE (p: PointBase) DependingPoints- (): PointList, NEW, ABSTRACT;
PROCEDURE (p: PointBase) DependingFigures- (): FigureList, NEW, ABSTRACT;
(* FigureBase *)
PROCEDURE (f: FigureBase) Model- ():Model, NEW, ABSTRACT;
PROCEDURE (f: FigureBase) Anchors- (): PointList, NEW, ABSTRACT;
(* Point *)
PROCEDURE (p: Point) Model* (): Model, NEW;
BEGIN
RETURN p.base.Model()
END Model;
PROCEDURE (p: Point) X* (): INTEGER, NEW;
BEGIN
RETURN p.base.X()
END X;
PROCEDURE (p: Point) Y* (): INTEGER, NEW;
BEGIN
RETURN p.base.Y()
END Y;
PROCEDURE (p: Point) DependingPoints* (): PointList, NEW;
BEGIN
RETURN p.base.DependingPoints()
END DependingPoints;
PROCEDURE (p: Point) DependingFigures* (): FigureList, NEW;
BEGIN
RETURN p.base.DependingFigures()
END DependingFigures;
(* Figure *)
PROCEDURE (fig: Figure) Model* (): Model, NEW;
BEGIN
RETURN fig.base.Model()
END Model;
PROCEDURE (fig: Figure) Anchors* (): PointList, NEW;
BEGIN
RETURN fig.base.Anchors()
END Anchors;
PROCEDURE (fig: Figure) Draw* (f: Ports.Frame; l, t, r, b: INTEGER), NEW, ABSTRACT;
PROCEDURE (fig: Figure) Action*, NEW, EMPTY;
PROCEDURE (fig: Figure) GetBoundingBox* (OUT l, t, r, b: INTEGER), NEW, EXTENSIBLE;
VAR plist : PointList; p: Point; x: INTEGER;
BEGIN
plist := fig.Anchors();
IF plist # NIL THEN
p := plist.This(); l := p.X(); r := p.X(); t := p.Y(); b := p.Y();
plist := plist.Next();
WHILE plist # NIL DO
p := plist.This(); l := MIN(l, p.X()); r := MAX(r, p.X()); t := MIN(t, p.Y()); b := MAX(b, p.Y());
plist := plist.Next()
END
END;
IF (r - l) < Ports.mm * 3 THEN x := (Ports.mm * 3 - (r - l)) DIV 2; DEC(l, x); INC(r, x) END;
IF (b - t) < Ports.mm * 3 THEN x := (Ports.mm * 3 - (b - t)) DIV 2; DEC(t, x); INC(b, x) END
END GetBoundingBox;
PROCEDURE (fig: Figure) Covers* (x, y: INTEGER): BOOLEAN, NEW, EXTENSIBLE;
VAR l, t, r, b: INTEGER;
BEGIN
fig.GetBoundingBox(l, t, r, b);
RETURN (l <= x) & (x <= r) & (t <= y) & (y <= b)
END Covers;
PROCEDURE (fig: Figure) PollProp* (OUT p: Properties.Property), NEW, EXTENSIBLE;
BEGIN
p := NIL
END PollProp;
PROCEDURE (fig: Figure) SetProp* (p: Properties.Property), NEW, EMPTY;
(* FreePoint *)
(* ConstrainedPoint *)
PROCEDURE (c: ConstrainedPoint) Anchors* (): PointList, NEW;
BEGIN
RETURN c.base.Anchors()
END Anchors;
PROCEDURE (c: ConstrainedPoint) PollProp* (OUT p: Properties.Property), NEW, EXTENSIBLE;
BEGIN
p := NIL
END PollProp;
PROCEDURE (c: ConstrainedPoint) SetProp* (p: Properties.Property), NEW, EMPTY;
PROCEDURE (c: ConstrainedPoint) Action*, NEW, EMPTY;
PROCEDURE (c: ConstrainedPoint) Calculate* (VAR x, y: INTEGER), NEW, EMPTY;
(* PointChooser *)
PROCEDURE (c: PointChooser) Choose* (p: Point): BOOLEAN, NEW, ABSTRACT;
(* FigureChooser *)
PROCEDURE (c: FigureChooser) Choose* (f: Figure): BOOLEAN, NEW, ABSTRACT;
(* Directory *)
PROCEDURE (d: Directory) NewModelBase- (): ModelBase, NEW, ABSTRACT;
PROCEDURE (d: Directory) New* (): Model, NEW;
VAR m: Model; base: ModelBase;
BEGIN
NEW(m); base := d.NewModelBase(); m.base := base; base.model := m;
Stores.Join(m, m.base);
RETURN m
END New;
(* ModelBase *)
PROCEDURE (m: ModelBase) InitFrom- (source: ModelBase), NEW, ABSTRACT;
PROCEDURE (m: ModelBase) Points- (): PointList, NEW, ABSTRACT;
PROCEDURE (m: ModelBase) Figures- (): FigureList, NEW, ABSTRACT;
PROCEDURE (m: ModelBase) InsertObject- (o: Object; anchors: PointList; x, y: INTEGER), NEW, ABSTRACT;
PROCEDURE (m: ModelBase) RemoveObject- (o: Object), NEW, ABSTRACT;
PROCEDURE (m: ModelBase) NewPointBase- (): PointBase, NEW, ABSTRACT;
PROCEDURE (m: ModelBase) NewFigureBase- (): FigureBase, NEW, ABSTRACT;
PROCEDURE (m: ModelBase) AddAnchor- (o: Object; pos: INTEGER; p: Point), NEW, ABSTRACT;
PROCEDURE (m: ModelBase) RemoveAnchor- (o: Object; p: Point), NEW, ABSTRACT;
PROCEDURE (m: ModelBase) ChangeAnchor- (o: Object; p: Point; pos: INTEGER), NEW, ABSTRACT;
PROCEDURE (m: ModelBase) BringToFront- (flist: FigureList), NEW, ABSTRACT;
PROCEDURE (m: ModelBase) SendToBack- (flist: FigureList), NEW, ABSTRACT;
PROCEDURE (m: ModelBase) ThisPointList- (pnts: ARRAY OF Point): PointList, NEW, ABSTRACT;
PROCEDURE (m: ModelBase) ThisFigureList- (figs: ARRAY OF Figure): FigureList, NEW, ABSTRACT;
PROCEDURE (m: ModelBase) MovePoint- (p: Point; dx, dy: INTEGER), NEW, ABSTRACT;
PROCEDURE (m: ModelBase) MovePoints- (plist: PointList; dx, dy: INTEGER), NEW, ABSTRACT;
PROCEDURE (m: ModelBase) MoveToGrid- (plist: PointList; grid: INTEGER), NEW, ABSTRACT;
PROCEDURE (m: ModelBase) InsertCopy- (source: ModelBase; plist: PointList; flist: FigureList;
OUT newPoints: PointList; OUT newFigures: FigureList),
NEW, ABSTRACT;
PROCEDURE (m: ModelBase) WriteData- (VAR wr: Stores.Writer), NEW, ABSTRACT;
PROCEDURE (m: ModelBase) ReadData- (VAR rd: Stores.Reader), NEW, ABSTRACT;
PROCEDURE (m: ModelBase) CopyDataFrom- (source: Stores.Store), NEW, ABSTRACT;
PROCEDURE (m: ModelBase) Externalize- (VAR wr: Stores.Writer);
BEGIN
wr.WriteVersion(currentFWVersion);
wr.WriteStore(m.model);
m.WriteData(wr)
END Externalize;
PROCEDURE (m: ModelBase) Internalize- (VAR rd: Stores.Reader);
VAR version: INTEGER; s: Stores.Store;
BEGIN
rd.ReadVersion(minFWVersion, maxFWVersion, version);
IF ~rd.cancelled THEN
rd.ReadStore(s);
IF s IS Model THEN
m.model := s(Model);
m.ReadData(rd)
ELSE
rd.TurnIntoAlien(Stores.alienComponent)
END
END
END Internalize;
PROCEDURE (m: ModelBase) CopyFrom- (source: Stores.Store);
END CopyFrom;
(* Model *)
PROCEDURE (m: Model) Points* (): PointList, NEW;
BEGIN
RETURN m.base.Points()
END Points;
PROCEDURE (m: Model) Figures* (): FigureList, NEW;
BEGIN
RETURN m.base.Figures()
END Figures;
PROCEDURE (m: Model) CopyFrom- (source: Stores.Store);
VAR s: Stores.Store;
BEGIN
WITH source: Model DO
s := Stores.CopyOf(source.base);
m.base := s(ModelBase); s(ModelBase).model := m;
m.base.CopyDataFrom(source.base)
END
END CopyFrom;
PROCEDURE (m: Model) Externalize- (VAR wr: Stores.Writer);
BEGIN
wr.WriteVersion(currentFWVersion);
wr.WriteStore(m.base)
END Externalize;
PROCEDURE (m: Model) Internalize- (VAR rd: Stores.Reader);
VAR s: Stores.Store; version: INTEGER;
BEGIN
rd.ReadVersion(minFWVersion, maxFWVersion, version);
IF ~rd.cancelled THEN
alienFigures := NIL; alienPoints := NIL;
rd.ReadStore(s);
IF s IS ModelBase THEN
m.base := s(ModelBase)
ELSE
rd.TurnIntoAlien(Stores.alienComponent)
END
END
END Internalize;
PROCEDURE (m: Model) MovePoint* (p: Point; dx, dy: INTEGER), NEW;
BEGIN
m.base.MovePoint(p, dx, dy)
END MovePoint;
PROCEDURE (m: Model) MovePoints* (plist: PointList; dx, dy: INTEGER), NEW;
BEGIN
m.base.MovePoints(plist, dx, dy)
END MovePoints;
PROCEDURE (m: Model) MoveToGrid* (plist: PointList; grid: INTEGER), NEW;
BEGIN
m.base.MoveToGrid(plist, grid)
END MoveToGrid;
PROCEDURE (m: Model) InsertCopy* (source: Model; plist: PointList; flist: FigureList;
OUT newPoints: PointList; OUT newFigures: FigureList
), NEW;
VAR script: Stores.Operation;
BEGIN
Models.BeginScript(m, "Copy", script);
m.base.InsertCopy(source.base, plist, flist, newPoints, newFigures);
Models.EndScript(m, script)
END InsertCopy;
PROCEDURE (m: Model) BringToFront* (flist: FigureList), NEW;
BEGIN
m.base.BringToFront(flist)
END BringToFront;
PROCEDURE (m: Model) SendToBack* (flist: FigureList), NEW;
BEGIN
m.base.SendToBack(flist)
END SendToBack;
PROCEDURE (m: Model) ThisPointList* (pnts: ARRAY OF Point): PointList, NEW;
BEGIN
RETURN m.base.ThisPointList(pnts)
END ThisPointList;
PROCEDURE (m: Model) ThisFigureList* (figs: ARRAY OF Figure): FigureList, NEW;
BEGIN
RETURN m.base.ThisFigureList(figs)
END ThisFigureList;
PROCEDURE (m: Model) ChoosePoints* (plist: PointList; c: PointChooser): PointList, NEW;
VAR tmplist: PointList; a, b: POINTER TO ARRAY OF Point; n, id: INTEGER; p: Point;
BEGIN
ASSERT(c # NIL, 20);
IF plist # NIL THEN ASSERT(plist.This().Model() = m, 21) END;
tmplist := plist; n := 0; WHILE tmplist # NIL DO tmplist := tmplist.Next(); INC(n) END;
IF n > 0 THEN
NEW(a, n); id := 0; tmplist := plist;
WHILE plist # NIL DO
p := plist.This();
IF c.Choose(p) THEN a[id] := p; INC(id) END;
plist := plist.Next()
END;
IF id > 0 THEN
NEW(b, id); FOR n := 0 TO id - 1 DO b[n] := a[n] END;
RETURN m.ThisPointList(b)
ELSE RETURN NIL
END
ELSE RETURN NIL
END
END ChoosePoints;
PROCEDURE (m: Model) ChooseFigures* (flist: FigureList; c: FigureChooser): FigureList, NEW;
VAR tmplist: FigureList; a, b: POINTER TO ARRAY OF Figure; n, id: INTEGER; f: Figure;
BEGIN
ASSERT(c # NIL, 20);
IF flist # NIL THEN ASSERT(flist.This().Model() = m, 21) END;
tmplist := flist; n := 0; WHILE tmplist # NIL DO tmplist := tmplist.Next(); INC(n) END;
IF n > 0 THEN
NEW(a, n); id := 0; tmplist := flist;
WHILE flist # NIL DO
f := flist.This();
IF c.Choose(f) THEN a[id] := f; INC(id) END;
flist := flist.Next()
END;
IF id > 0 THEN
NEW(b, id); FOR n := 0 TO id - 1 DO b[n] := a[n] END;
RETURN m.ThisFigureList(b)
ELSE RETURN NIL
END
ELSE RETURN NIL
END
END ChooseFigures;
PROCEDURE (m: Model) InsertObject* (o: Object; anchors: PointList; x, y: INTEGER), NEW;
VAR figbase: FigureBase; pntbase: PointBase; script: Stores.Operation;
BEGIN
ASSERT(o # NIL, 20);
ASSERT(anchors # NIL, 21);
ASSERT(anchors.This().Model() = m, 22);
ASSERT((o IS ConstrainedPoint) OR (o IS Figure), 23);
IF o IS ConstrainedPoint THEN
ASSERT((x >= 0) OR (x = undefined), 24);
ASSERT((y >= 0) OR (y = undefined), 25);
Models.BeginScript(m, "Insert Point", script);
pntbase := m.base.NewPointBase(); o(Point).base := pntbase; pntbase.ext := o(Point);
Stores.Join(o, pntbase); Stores.Join(m, o);
m.base.InsertObject(o, anchors, x, y);
Models.EndScript(m, script)
ELSIF o IS Figure THEN
ASSERT((x = undefined) & (y = undefined), 26);
Models.BeginScript(m, "Insert Figure", script);
figbase := m.base.NewFigureBase(); o(Figure).base := figbase; figbase.ext := o(Figure);
Stores.Join(o, figbase); Stores.Join(m, o);
m.base.InsertObject(o, anchors, undefined, undefined);
Models.EndScript(m, script)
END
END InsertObject;
PROCEDURE (m: Model) RemoveObject* (o: Object), NEW;
VAR script: Stores.Operation;
BEGIN
ASSERT(o # NIL, 20);
ASSERT((o IS Point) OR (o IS Figure), 21);
IF o IS Point THEN
ASSERT(o(Point).Model() = m, 22);
Models.BeginScript(m, "Remove Point", script);
m.base.RemoveObject(o(Point));
Models.EndScript(m, script)
ELSIF o IS Figure THEN
ASSERT(o(Figure).Model() = m, 23);
Models.BeginScript(m,"Remove Figure", script);
m.base.RemoveObject(o(Figure));
Models.EndScript(m, script)
END
END RemoveObject;
PROCEDURE (m: Model) NewFreePoint* (x, y: INTEGER): FreePoint, NEW;
VAR base: PointBase; pnt: FreePoint; script: Stores.Operation;
BEGIN
ASSERT(x >= 0, 21);
ASSERT(y >= 0, 22);
Models.BeginScript(m, "New Free Point", script);
base := m.base.NewPointBase(); NEW(pnt); pnt.base := base; base.ext := pnt;
Stores.Join(pnt, base); Stores.Join(m, pnt);
m.base.InsertObject(pnt, NIL, x, y);
Models.EndScript(m, script);
RETURN pnt
END NewFreePoint;
PROCEDURE PollProp (o: Object; OUT prop: StdProp);
VAR p: Properties.Property;
BEGIN
IF o IS Figure THEN o(Figure).PollProp(p)
ELSIF o IS ConstrainedPoint THEN o(ConstrainedPoint).PollProp(p)
END;
WHILE (p # NIL) & ~(p IS StdProp) DO p := p.next END;
IF p # NIL THEN prop := p(StdProp) ELSE prop := NIL END
END PollProp;
PROCEDURE CountAnchors (o: Object): INTEGER;
VAR plist: PointList;
n: INTEGER;
BEGIN
IF o IS ConstrainedPoint THEN plist := o(ConstrainedPoint).Anchors()
ELSIF o IS Figure THEN plist := o(Figure).Anchors()
END;
n := 0; WHILE plist # NIL DO INC(n); plist := plist.Next() END;
RETURN n
END CountAnchors;
PROCEDURE (m: Model) AddAnchor* (o: Object; pos: INTEGER; OUT pnt: Point), NEW;
VAR x, y, n, id: INTEGER; p0, p1: PointList; prop: StdProp; script: Stores.Operation;
BEGIN
ASSERT(o # NIL, 20);
ASSERT(pos >= 0, 21);
ASSERT((o IS ConstrainedPoint) OR (o IS Figure), 22);
IF o IS ConstrainedPoint THEN
ASSERT(o(ConstrainedPoint).Model() = m, 24);
p0 := o(ConstrainedPoint).Anchors(); p1 := o(ConstrainedPoint).Anchors()
ELSIF o IS Figure THEN
ASSERT(o(Figure).Model() = m, 25);
p0 := o(Figure).Anchors(); p1 := o(Figure).Anchors()
END;
n := CountAnchors(o); PollProp(o, prop);
IF prop # NIL THEN
IF (expandable IN prop.valid) & prop.expandable THEN
IF (maxAnchors IN prop.valid) & ((prop.maxAnchors = undefined)
OR (n < prop.maxAnchors)) THEN
IF pos = 0 THEN
WHILE p0.Next() # NIL DO p0 := p0.Next() END;
IF ((cyclic IN prop.valid) & prop.cyclic) OR (n = 1) THEN
x := (p0.This().X() + p1.This().X()) DIV 2; y := (p0.This().Y() + p1.This().Y()) DIV 2
ELSE
x := p1.This().X() + (p1.This().X() - p1.Next().This().X());
y := p1.This().Y() + (p1.This().Y() - p1.Next().This().Y())
END
ELSIF pos >= n THEN
IF p0.Next() # NIL THEN
WHILE (p0.Next().Next() # NIL) DO p0 := p0.Next() END;
IF (cyclic IN prop.valid) & prop.cyclic THEN
x := (p0.Next().This().X() + p1.This().X()) DIV 2;
y := (p0.Next().This().Y() + p1.This().Y()) DIV 2
ELSE
x := p0.Next().This().X() + (p0.Next().This().X() - p0.This().X());
y := p0.Next().This().Y() + (p0.Next().This().Y() - p0.This().Y())
END
ELSE x := p0.This().X() + Ports.mm * 10; y := p0.This().Y() + Ports.mm * 10
END
ELSE
id := 1; WHILE id # pos DO p0 := p0.Next(); INC(id) END;
x := (p0.This().X() + p0.Next().This().X()) DIV 2;
y := (p0.This().Y() + p0.Next().This().Y()) DIV 2
END;
Models.BeginScript(m, "Add Anchorpoint", script);
pnt := m.NewFreePoint(x, y);
m.base.AddAnchor(o, pos, pnt);
Models.EndScript(m, script)
END
END
END
END AddAnchor;
PROCEDURE (m: Model) RemoveAnchor* (o: Object; p: Point), NEW;
VAR n: INTEGER;
prop: StdProp;
plist: PointList;
BEGIN
ASSERT(o # NIL, 20);
ASSERT(p # NIL, 21);
ASSERT(p.Model() = m, 22);
ASSERT((o IS ConstrainedPoint) OR (o IS Figure), 23);
IF o IS ConstrainedPoint THEN
ASSERT(o(ConstrainedPoint).Model() = m, 24); plist := o(ConstrainedPoint).Anchors()
ELSIF o IS Figure THEN
ASSERT(o(Figure).Model() = m, 25); plist := o(Figure).Anchors()
END;
n := CountAnchors(o); PollProp(o, prop);
WHILE (plist # NIL) & (plist.This() # p) DO plist := plist.Next() END;
IF (prop # NIL) & (expandable IN prop.valid) & prop.expandable & (plist # NIL) & (minAnchors IN prop.valid)
& (n > prop.minAnchors)
THEN m.base.RemoveAnchor(o, p)
END
END RemoveAnchor;
PROCEDURE (m: Model) CollectProperties* (flist: FigureList; plist: PointList; OUT prop: Properties.Property), NEW;
VAR equal: BOOLEAN; p: Properties.Property;
figs: FigureList;
pnts: PointList;
BEGIN
figs := flist; pnts := plist;
IF figs # NIL THEN
figs.This().PollProp(prop); figs := figs.Next();
WHILE figs # NIL DO figs.This().PollProp(p); Properties.Intersect(prop, p, equal); figs := figs.Next() END
END;
IF pnts # NIL THEN
IF flist = NIL THEN
IF pnts.This() IS ConstrainedPoint THEN pnts.This()(ConstrainedPoint).PollProp(prop) END;
pnts := pnts.Next()
END;
WHILE pnts # NIL DO
IF pnts.This() IS ConstrainedPoint THEN
pnts.This()(ConstrainedPoint).PollProp(p); Properties.Intersect(prop, p, equal)
END;
pnts := pnts.Next()
END
END
END CollectProperties;
PROCEDURE (m: Model) EmitProperties* (flist: FigureList; plist: PointList; prop: Properties.Property), NEW;
VAR s: Stores.Operation;
BEGIN
ASSERT(m # NIL, 20);
Models.BeginScript(m, "Set Properties", s);
WHILE flist # NIL DO flist.This().SetProp(prop); flist := flist.Next() END;
WHILE plist # NIL DO
IF plist.This() IS ConstrainedPoint THEN plist.This()(ConstrainedPoint).SetProp(prop) END;
plist := plist.Next()
END;
Models.EndScript(m, s)
END EmitProperties;
PROCEDURE (m: Model) GetBoundingBox* (plist: PointList; flist: FigureList; OUT l, t, r, b: INTEGER), NEW;
VAR fl, ft, fr, fb: INTEGER;
BEGIN
ASSERT((plist # NIL) OR (flist # NIL), 20);
IF plist # NIL THEN
l := plist.This().X(); r := plist.This().X(); t := plist.This().Y(); b := plist.This().Y();
plist := plist.Next();
WHILE plist # NIL DO
l := MIN(l, plist.This().X()); r := MAX(r, plist.This().X()); t := MIN(t, plist.This().Y()); b := MAX(b, plist.This().Y());
plist := plist.Next()
END
ELSE flist.This().GetBoundingBox(l, t, r, b); flist := flist.Next()
END;
WHILE flist # NIL DO
flist.This().GetBoundingBox(fl, ft, fr, fb); l := MIN(l, fl); r := MAX(r, fr); t := MIN(t, ft); b := MAX(b, fb);
flist := flist.Next()
END
END GetBoundingBox;
PROCEDURE (m: Model) IncludedFigures* (flist: FigureList; l, t, r, b: INTEGER): FigureList, NEW;
VAR c: IncludedFiguresChooser;
BEGIN
NEW(c); c.l := l; c.t := t; c.r := r; c.b := b;
RETURN m.ChooseFigures(flist, c)
END IncludedFigures;
PROCEDURE (m: Model) IntersectingFigures* (flist: FigureList; l, t, r, b: INTEGER): FigureList, NEW;
VAR c: IntersectingFiguresChooser;
BEGIN
NEW(c); c.l := l; c.t := t; c.r := r; c.b := b;
RETURN m.ChooseFigures(flist, c)
END IntersectingFigures;
PROCEDURE (m: Model) TheseFigures* (flist: FigureList; x, y: INTEGER): FigureList, NEW;
VAR c: TheseFiguresChooser;
BEGIN
NEW(c); c.x := x; c.y := y;
RETURN m.ChooseFigures(flist, c)
END TheseFigures;
PROCEDURE (m: Model) ThesePoints* (plist: PointList; l, t, r, b: INTEGER): PointList, NEW;
VAR c: ThesePointsChooser;
BEGIN
NEW(c); c.l := l; c.t := t; c.r := r; c.b := b;
RETURN m.ChoosePoints(plist, c)
END ThesePoints;
PROCEDURE (m: Model) JoinPossible* ( plist: PointList; target: Point): BOOLEAN, NEW;
VAR jnp: BOOLEAN; (* Join NotPossble *)
tmplist: PointList;
PROCEDURE InList (p: Point; plist: PointList): BOOLEAN;
BEGIN
WHILE (plist # NIL) & (plist.This() # p) DO plist := plist.Next() END;
RETURN plist = NIL
END InList;
PROCEDURE DependingOnSelected (p: Point): BOOLEAN;
VAR q: PointList;
BEGIN
IF (p IS ConstrainedPoint) THEN
q := p(ConstrainedPoint).Anchors();
WHILE (q # NIL) & InList(q.This(), plist) & ~DependingOnSelected(q.This()) DO q := q.Next() END;
RETURN q # NIL
ELSE
RETURN FALSE
END
END DependingOnSelected;
BEGIN
ASSERT(plist # NIL, 21);
ASSERT(target # NIL, 22);
ASSERT(plist.This().Model() = m, 23);
ASSERT(target.Model() = m, 24);
jnp := FALSE;
tmplist := plist;
WHILE tmplist # NIL DO
IF tmplist.This() IS ConstrainedPoint THEN jnp := TRUE END;
tmplist := tmplist.Next()
END;
IF (target IS ConstrainedPoint) & ~(jnp) THEN jnp := DependingOnSelected(target) END;
tmplist := plist;
WHILE plist # NIL DO
IF plist.This() = target THEN jnp := TRUE END;
plist := plist.Next()
END;
RETURN ~jnp
END JoinPossible;
PROCEDURE (m: Model) JoinPoints* (plist: PointList; target: Point), NEW;
VAR tmppnt: Point;
tmplist, tmplist2, deppnts: PointList;
depfigs: FigureList;
script: Stores.Operation;
id: INTEGER;
BEGIN
ASSERT(plist # NIL, 21);
ASSERT(target # NIL, 22);
ASSERT(plist.This().Model() = m, 23);
ASSERT(target.Model() = m, 24);
IF m.JoinPossible(plist, target) THEN
Models.BeginScript(m, "Join Points", script);
tmplist := plist;
WHILE tmplist # NIL DO
m.MovePoint(tmplist.This(), target.X() - tmplist.This().X(), target.Y() - tmplist.This().Y());
depfigs := tmplist.This().DependingFigures();
WHILE depfigs # NIL DO
tmplist2 := depfigs.This().Anchors(); id := 1;
WHILE tmplist2.This() # tmplist.This() DO tmplist2 := tmplist2.Next(); INC(id) END;
m.base.ChangeAnchor(depfigs.This(), target, id);
depfigs := depfigs.Next()
END;
deppnts := tmplist.This().DependingPoints();
WHILE deppnts # NIL DO
tmplist2 := deppnts.This()(ConstrainedPoint).Anchors(); id := 1;
WHILE tmplist2.This() # tmplist.This() DO tmplist2 := tmplist2.Next(); INC(id) END;
m.base.ChangeAnchor(deppnts.This()(ConstrainedPoint), target, id);
deppnts := deppnts.Next()
END;
tmplist := tmplist.Next()
END;
tmplist := plist;
WHILE tmplist # NIL DO
tmppnt := tmplist.This(); tmplist := tmplist.Next(); m.base.RemoveObject(tmppnt)
END;
Models.EndScript(m, script)
END
END JoinPoints;
PROCEDURE (m: Model) SplitPoint* (p: Point), NEW;
VAR depfigs: FigureList;
deppnts, tmplist: PointList;
newpnt: Point;
offset, id: INTEGER;
script: Stores.Operation;
BEGIN
ASSERT(p # NIL, 21);
ASSERT(p.Model() = m, 22);
Models.BeginScript(m, "Split points", script);
offset := Ports.mm * 3;
depfigs := p.DependingFigures();
WHILE (depfigs # NIL) DO
tmplist := depfigs.This().Anchors(); id := 1;
WHILE tmplist.This() # p DO tmplist := tmplist.Next(); INC(id) END;
newpnt := m.NewFreePoint(p.X(), p.Y());
m.base.ChangeAnchor(depfigs.This(), newpnt, id);
m.MovePoint(newpnt, offset, 0); offset := offset + Ports.mm * 3;
depfigs := depfigs.Next()
END;
deppnts := p.DependingPoints();
WHILE (deppnts # NIL) DO
tmplist := deppnts.This()(ConstrainedPoint).Anchors(); id := 1;
WHILE tmplist.This() # p DO tmplist := tmplist.Next(); INC(id) END;
newpnt := m.NewFreePoint(p.X(), p.Y());
m.base.ChangeAnchor(deppnts.This()(ConstrainedPoint), newpnt, id);
m.MovePoint(newpnt, offset, 0);offset := offset + Ports.mm * 3;
deppnts := deppnts.Next()
END;
IF ~(p IS ConstrainedPoint) THEN m.base.RemoveObject(p) END;
Models.EndScript(m, script)
END SplitPoint;
(* StdProp *)
PROCEDURE (p: StdProp) IntersectWith* (q: Properties.Property; OUT equal: BOOLEAN);
VAR valid: SET;
BEGIN
WITH q: StdProp DO
p.known := p.known + q.known; valid := p.valid * q.valid;
IF p.expandable # q.expandable THEN EXCL(valid, expandable) END;
IF p.cyclic # q.cyclic THEN EXCL(valid, cyclic) END;
IF p.minAnchors # q.minAnchors THEN EXCL(valid, minAnchors) END;
IF p.maxAnchors # q.maxAnchors THEN EXCL(valid, maxAnchors) END;
equal := p.valid = valid; p.valid := valid
END
END IntersectWith;
(* TProp *)
PROCEDURE (p: TProp) IntersectWith* (q: Properties.Property; OUT equal: BOOLEAN);
VAR valid: SET;
BEGIN
WITH q: TProp DO
p.known := p.known + q.known; valid := p.valid * q.valid;
IF p.thickness # q.thickness THEN EXCL(valid, thickness) END;
equal := p.valid = valid; p.valid := valid
END
END IntersectWith;
(* ArrowProp *)
PROCEDURE (p: ArrowProp) IntersectWith* (q: Properties.Property; OUT equal: BOOLEAN);
VAR valid: SET;
BEGIN
WITH q: ArrowProp DO
valid := p.valid * q.valid;
IF p.type # q.type THEN EXCL(valid, type) END;
equal := valid = p.valid; p.valid := valid
END
END IntersectWith;
(* ThesePointsChooser *)
PROCEDURE (c: ThesePointsChooser) Choose (p: Point): BOOLEAN;
VAR x, y: INTEGER;
BEGIN
ASSERT(p # NIL, 20);
x := p.X(); y := p.Y();
RETURN (c.l <= x) & (x <= c.r) & (c.t <= y) & (y <= c.b)
END Choose;
(* TheseFiguresChooser *)
PROCEDURE (c: TheseFiguresChooser) Choose (f: Figure): BOOLEAN;
BEGIN
ASSERT(f # NIL, 20);
RETURN f.Covers(c.x, c.y)
END Choose;
(* IntersectingFiguresChooser *)
PROCEDURE (c: IntersectingFiguresChooser) Choose (f: Figure): BOOLEAN;
VAR l, t, r, b: INTEGER;
BEGIN
ASSERT(f # NIL, 20);
f.GetBoundingBox(l, t, r, b);
RETURN (c.r >= l) & (r >= c.l) & (c.b >= t) & (b >= c.t)
END Choose;
(* IncludedFiguresChooser *)
PROCEDURE (c: IncludedFiguresChooser) Choose (f: Figure): BOOLEAN;
VAR l, t, r, b: INTEGER;
BEGIN
ASSERT(f # NIL, 20);
f.GetBoundingBox(l, t, r, b);
RETURN (c.l <= l) & (c.r >= r) & (c.t <= t) & (c.b >= b)
END Choose;
(* AlienFigure *)
PROCEDURE (fig: AlienFigure) ExternalizeAs- (VAR s1: Stores.Store);
BEGIN
s1 := fig.store
END ExternalizeAs;
PROCEDURE (fig: AlienFigure) CopyFrom- (source: Stores.Store);
BEGIN
WITH source: AlienFigure DO
fig.store := source.store
ELSE
END
END CopyFrom;
PROCEDURE (fig: AlienFigure) Draw* (f: Ports.Frame; l, t, r, b: INTEGER);
VAR left, top, right, bottom: INTEGER; alienColor: Ports.Color;
BEGIN
fig.Model().GetBoundingBox(fig.Anchors(), NIL, left, top, right, bottom);
IF Ports.background # Ports.grey50 THEN alienColor := Ports.grey50 ELSE alienColor := Ports.grey25 END;
f.DrawRect(left, top, right, bottom, Ports.fill, alienColor);
f.DrawRect(left, top, right, bottom, 0, Ports.black);
f.DrawLine(left, top, right, bottom, 0, Ports.black);
f.DrawLine(left, bottom, right, top, 0, Ports.black)
END Draw;
PROCEDURE (fig: AlienFigure) GetBoundingBox* (OUT l, t, r, b: INTEGER);
BEGIN
fig.Model().GetBoundingBox(fig.Anchors(), NIL, l, t, r, b)
END GetBoundingBox;
(* AlienPoint *)
PROCEDURE (p: AlienPoint) ExternalizeAs- (VAR s1: Stores.Store);
BEGIN
s1 := p.store
END ExternalizeAs;
PROCEDURE (p: AlienPoint) CopyFrom- (source: Stores.Store);
BEGIN
WITH source: AlienPoint DO
p.store := source.store
END
END CopyFrom;
(* Proper procedures *)
PROCEDURE WritePoint* (VAR wr: Stores.Writer; p: Point);
BEGIN
ASSERT(p # NIL, 20);
wr.WriteStore(p); wr.WriteStore(p.base)
END WritePoint;
PROCEDURE WriteFigure* (VAR wr: Stores.Writer; f: Figure);
BEGIN
ASSERT(f # NIL, 20);
wr.WriteStore(f); wr.WriteStore(f(Figure).base)
END WriteFigure;
PROCEDURE ReadPoint* (VAR rd: Stores.Reader; OUT point: Point);
VAR s: Stores.Store; p: StdPointList; alienPnt: AlienPoint;
BEGIN
rd.ReadStore(s);
IF s IS Point THEN point := s(Point)
ELSE
p := alienPoints;
WHILE (p # NIL) & (p.p(AlienPoint).store # s) DO p := p.next END;
IF p # NIL THEN alienPnt := p.p(AlienPoint)
ELSE
NEW(alienPnt); alienPnt.store := s(Stores.Alien); Stores.Join(alienPnt, s);
NEW(p); p.p := alienPnt; p.next := alienPoints; alienPoints := p
END;
point := alienPnt
END;
rd.ReadStore(s);
IF ~rd.cancelled THEN point.base := s(PointBase); s(PointBase).ext := point END
END ReadPoint;
PROCEDURE ReadFigure* (VAR rd: Stores.Reader; OUT figure: Figure);
VAR s: Stores.Store; f: StdFigureList; alienFig: AlienFigure;
BEGIN
rd.ReadStore(s);
IF s IS Figure THEN figure := s(Figure)
ELSE
f := alienFigures;
WHILE (f # NIL) & (f.f(AlienFigure).store # s) DO f := f.next END;
IF f # NIL THEN alienFig := f.f(AlienFigure)
ELSE
NEW(alienFig); alienFig.store := s(Stores.Alien); Stores.Join(alienFig, s);
NEW(f); f.f := alienFig; f.next := alienFigures; alienFigures := f
END;
figure := alienFig
END;
rd.ReadStore(s);
IF ~rd.cancelled THEN figure.base := s(FigureBase); s(FigureBase).ext := figure END
END ReadFigure;
PROCEDURE CloneOf*(source: Model): Model;
VAR m: Model; s: Stores.Store;
BEGIN
ASSERT(source # NIL, 20);
NEW(m);
s := Stores.CopyOf(source.base);
m.base := s(ModelBase); s(ModelBase).model := m; Stores.Join(m, s);
m.base.InitFrom(source.base);
RETURN m
END CloneOf;
PROCEDURE SetDir*(d: Directory);
BEGIN
ASSERT (d # NIL, 20);
dir := d
END SetDir;
(* StdModel *)
(* Misc. procedures *)
PROCEDURE GiveFigureID (f: StdFigureList);
VAR i: INTEGER;
BEGIN
i := 1; WHILE (f # NIL) DO f.id := i; f.f.base(StdFigureBase).id := i; INC(i); f := f.next END
END GiveFigureID;
PROCEDURE GivePointID (p: StdPointList);
VAR i: INTEGER;
BEGIN
i := 1; WHILE (p # NIL) DO p.id := i; p.p.base(StdPointBase).id := i; INC(i); p := p.next END
END GivePointID;
PROCEDURE AlienDependencies (pnt: Point): BOOLEAN;
VAR points: PointList;
BEGIN
IF ~(pnt IS AlienPoint) THEN
points := pnt.DependingPoints();
WHILE (points # NIL) & ~(points.This() IS AlienPoint) & ~AlienDependencies(points.This()) DO
points := points.Next()
END;
RETURN points # NIL
ELSE RETURN FALSE
END
END AlienDependencies;
PROCEDURE ReadPointList (VAR rd: Stores.Reader; m: StdModelBase; OUT list: StdPointList);
VAR i: INTEGER; p: StdPointList; o: Point; (* alien: StdAlienPoint; *)
BEGIN
rd.ReadInt(i); p := NIL; list := NIL;
WHILE i # 0 DO
ReadPoint(rd, o);
IF p # NIL THEN NEW(p.next); p := p.next ELSE NEW(list); p := list END;
p.p := o;
DEC(i)
END
END ReadPointList;
PROCEDURE ReadFigureList (VAR rd: Stores.Reader; m: StdModelBase; OUT list: StdFigureList);
VAR i: INTEGER; p: StdFigureList; o: Figure; (* alien: StdAlienFigure; *)
BEGIN
rd.ReadInt(i); p := NIL; list := NIL;
WHILE i # 0 DO
ReadFigure(rd, o);
IF p # NIL THEN NEW(p.next); p := p.next ELSE NEW(list); p := list END;
p.f := o;
DEC(i)
END
END ReadFigureList;
PROCEDURE WritePointList (VAR wr: Stores.Writer; m: StdModelBase; list: StdPointList);
VAR i: INTEGER; p: StdPointList;
BEGIN
p := list; i := 0; WHILE p # NIL DO INC(i); p := p.next END;
wr.WriteInt(i);
p := list;
WHILE p # NIL DO
WritePoint(wr, p.p);
p := p.next
END
END WritePointList;
PROCEDURE WriteFigureList (VAR wr: Stores.Writer; m: StdModelBase; list: StdFigureList);
VAR i: INTEGER; p: StdFigureList;
BEGIN
p := list; i := 0; WHILE p # NIL DO INC(i); p := p.next END;
wr.WriteInt(i);
p := list;
WHILE p # NIL DO
WriteFigure(wr, p.f);
p := p.next
END
END WriteFigureList;
(* PointOp *)
PROCEDURE (op: PointOp) Do;
VAR m: StdModelBase;
pnt, plist, prev, tmppnt: StdPointList;
msg: InsertMsg;
BEGIN
m := op.model; GivePointID(m.points);
NEW(pnt); pnt.p := op.point;
IF op.insert THEN
plist := m.points;
IF plist = NIL THEN pnt.next := NIL; m.points := pnt
ELSE
IF op.pos = 1 THEN pnt.next := m.points; m.points := pnt
ELSE
WHILE plist.id < op.pos - 1 DO plist := plist.next END;
pnt.next := plist.next; plist.next := pnt
END
END;
IF pnt.p IS ConstrainedPoint THEN
plist := pnt.p.base(StdPointBase).anchors;
WHILE plist # NIL DO
NEW(tmppnt); tmppnt.p := pnt.p; tmppnt.next := plist.p.base(StdPointBase).dependingPoints;
plist.p.base(StdPointBase).dependingPoints := tmppnt; plist := plist.next
END
END
ELSE
prev := NIL; plist := m.points;
WHILE plist.id # op.pos DO prev := plist; plist := plist.next END;
IF prev # NIL THEN prev.next := plist.next ELSE m.points := plist.next END;
IF pnt.p IS ConstrainedPoint THEN
plist := pnt.p.base(StdPointBase).anchors;
WHILE plist # NIL DO
tmppnt := plist.p.base(StdPointBase).dependingPoints; prev := NIL;
WHILE tmppnt.p # op.point DO prev := tmppnt; tmppnt := tmppnt.next END;
IF prev # NIL THEN prev.next := tmppnt.next
ELSE plist.p.base(StdPointBase).dependingPoints := tmppnt.next
END;
plist := plist.next
END
END
END;
msg.l := op.point.X(); msg.t := op.point.Y(); msg.r := op.point.X(); msg.b := op.point.Y();
msg.point := op.point; msg.figure := NIL; msg.insert := op.insert;
op.insert := ~op.insert;
Models.Broadcast(m.model, msg)
END Do;
PROCEDURE NewPointOp (model: StdModelBase; point: Point; id: INTEGER; insert: BOOLEAN): PointOp;
VAR op: PointOp;
BEGIN
NEW(op); op.point := point; op.model := model; op.insert := insert; op.pos := id;
RETURN op
END NewPointOp;
(* FigureOp *)
PROCEDURE (op: FigureOp) Do;
VAR m: StdModelBase;
fig, flist, prev, tmpfig, tmplist: StdFigureList;
plist: StdPointList;
msg: InsertMsg;
BEGIN
m := op.model; GiveFigureID(m.figures);
NEW(fig); fig.f := op.figure;
IF op.insert THEN
flist := m.figures;
IF flist = NIL THEN fig.next := NIL; m.figures := fig
ELSE
IF op.pos = 1 THEN fig.next := m.figures; m.figures := fig
ELSE
WHILE flist.id < op.pos - 1 DO flist := flist.next END;
fig.next := flist.next; flist.next := fig
END
END;
plist := fig.f.base(StdFigureBase).anchors;
WHILE plist # NIL DO
NEW(tmpfig); tmpfig.f := fig.f; tmpfig.next := plist.p.base(StdPointBase).dependingFigures;
plist.p.base(StdPointBase).dependingFigures := tmpfig; plist := plist.next
END
ELSE
fig := NIL; prev := NIL; flist := m.figures;
WHILE flist.id # op.pos DO prev := flist; flist := flist.next END;
IF prev # NIL THEN prev.next := flist.next ELSE m.figures := flist.next END;
plist := op.figure.base(StdFigureBase).anchors;
WHILE plist # NIL DO
tmpfig := plist.p.base(StdPointBase).dependingFigures; prev := NIL;
WHILE tmpfig.f # op.figure DO prev := tmpfig; tmpfig := tmpfig.next END;
IF prev # NIL THEN prev.next := tmpfig.next
ELSE plist.p.base(StdPointBase).dependingFigures := tmpfig.next
END;
plist := plist.next
END
END;
NEW(tmplist); tmplist.f := op.figure; tmplist.next := NIL;
m.model.GetBoundingBox(NIL, tmplist, msg.l, msg.t, msg.r, msg.b);
msg.insert := op.insert; msg.figure := op.figure; msg.point := NIL;
op.insert := ~op.insert;
Models.Broadcast(m.model, msg)
END Do;
PROCEDURE NewFigureOp (m: StdModelBase; f: Figure; id: INTEGER; insert: BOOLEAN): FigureOp;
VAR op: FigureOp;
BEGIN
NEW(op); op.model := m; op.figure := f; op.pos := id; op.insert := insert;
RETURN op
END NewFigureOp;
(* FigureAnchorOp *)
PROCEDURE (op: FigureAnchorOp) Do;
VAR m: StdModelBase;
msg: AnchorMsg;
tmppnt, plist, prevpnt: StdPointList;
tmpfig, flist, prevfig, tmplist: StdFigureList;
l, t, r, b, ll, tt, rr, bb: INTEGER;
BEGIN
m := op.model;
NEW(tmplist); tmplist.f := op.fig; tmplist.next := NIL;
m.model.GetBoundingBox(NIL, tmplist, l, t, r, b);
IF op.add THEN
NEW(tmppnt); tmppnt.p := op.anchor;
GivePointID(op.fig.base(StdFigureBase).anchors);
plist := op.fig.base(StdFigureBase).anchors;
IF plist = NIL THEN tmppnt.next := NIL; op.fig.base(StdFigureBase).anchors := tmppnt
ELSE
IF op.anchorID = 1 THEN
tmppnt.next := op.fig.base(StdFigureBase).anchors;
op.fig.base(StdFigureBase).anchors := tmppnt
ELSE
WHILE plist.id < op.anchorID -1 DO plist := plist.next END;
tmppnt.next := plist.next; plist.next := tmppnt
END
END;
NEW(tmpfig); tmpfig.f := op.fig;
GiveFigureID(op.anchor.base(StdPointBase).dependingFigures);
flist := op.anchor.base(StdPointBase).dependingFigures;
IF flist = NIL THEN tmpfig.next := NIL; op.anchor.base(StdPointBase).dependingFigures := tmpfig
ELSE
IF op.depID = 1 THEN
tmpfig.next := op.anchor.base(StdPointBase).dependingFigures;
op.anchor.base(StdPointBase).dependingFigures := tmpfig
ELSE
WHILE flist.id < op.depID -1 DO flist := flist.next END;
tmpfig.next := flist.next; flist.next := tmpfig
END
END
ELSE
GivePointID(op.fig.base(StdFigureBase).anchors);
plist := op.fig.base(StdFigureBase).anchors; prevpnt := NIL;
WHILE plist.id # op.anchorID DO prevpnt := plist; plist := plist.next END;
IF prevpnt # NIL THEN prevpnt.next := plist.next
ELSE op.fig.base(StdFigureBase).anchors := plist.next
END;
GiveFigureID(op.anchor.base(StdPointBase).dependingFigures);
flist := op.anchor.base(StdPointBase).dependingFigures; prevfig := NIL;
WHILE flist.id # op.depID DO prevfig := flist; flist := flist.next END;
IF prevfig # NIL THEN prevfig.next := flist.next
ELSE op.anchor.base(StdPointBase).dependingFigures := flist.next
END
END;
m.model.GetBoundingBox(NIL, tmplist, ll, tt, rr, bb);
msg.l := MIN(l, ll); msg.t := MIN(t, tt); msg.r := MAX(r, rr); msg.b := MAX(b, bb);
msg.add := op.add; msg.anchor := op.anchor; msg.figure := op.fig;
msg.comppnt := NIL; msg.pos := op.anchorID;
op.add := ~op.add;
Models.Broadcast(m.model, msg)
END Do;
PROCEDURE NewFigureAnchorOp (m: StdModelBase; anchor: Point; f: Figure;
anchorID, depID: INTEGER; add: BOOLEAN): FigureAnchorOp;
VAR op: FigureAnchorOp;
plist: StdPointList;
flist: StdFigureList;
BEGIN
NEW(op); op.add := add; op.model := m; op.anchor := anchor; op.fig := f;
IF anchorID = last THEN
GivePointID(f.base(StdFigureBase).anchors);
plist := f.base(StdFigureBase).anchors;
IF plist = NIL THEN op.anchorID := 1
ELSE
WHILE plist.next # NIL DO plist := plist.next END;
op.anchorID := plist.id + 1
END
ELSE op.anchorID := anchorID
END;
IF depID = last THEN
GiveFigureID(anchor.base(StdPointBase).dependingFigures);
flist := anchor.base(StdPointBase).dependingFigures;
IF flist = NIL THEN op.depID := 1
ELSE
WHILE flist.next # NIL DO flist := flist.next END;
op.depID := flist.id + 1
END
ELSE op.depID := depID
END;
RETURN op
END NewFigureAnchorOp;
(* PointAnchorOp *)
PROCEDURE (op: PointAnchorOp) Do;
VAR m: StdModelBase; msg: AnchorMsg; tmppnt, plist, prevpnt, tmplist: StdPointList;
l, t, r, b, ll, tt, rr, bb: INTEGER;
BEGIN
m := op.model;
NEW(tmplist); tmplist.p := op.deppnt; tmplist.next := NIL;
m.model.GetBoundingBox(tmplist, NIL, l, t, r, b);
IF op.add THEN
NEW(tmppnt); tmppnt.p := op.anchor;
GivePointID(op.deppnt.base(StdPointBase).anchors);
plist := op.deppnt.base(StdPointBase).anchors;
IF plist = NIL THEN tmppnt.next := NIL; op.deppnt.base(StdPointBase).anchors := tmppnt
ELSE
IF op.anchorID = 1 THEN
tmppnt.next := op.deppnt.base(StdPointBase).anchors;
op.deppnt.base(StdPointBase).anchors := tmppnt
ELSE
WHILE plist.id < op.anchorID -1 DO plist := plist.next END;
tmppnt.next := plist.next; plist.next := tmppnt
END
END;
NEW(tmppnt); tmppnt.p := op.deppnt;
GivePointID(op.anchor.base(StdPointBase).dependingPoints);
plist := op.anchor.base(StdPointBase).dependingPoints;
IF plist = NIL THEN tmppnt.next := NIL; op.anchor.base(StdPointBase).dependingPoints := tmppnt
ELSE
IF op.depID = 1 THEN
tmppnt.next := op.anchor.base(StdPointBase).dependingPoints;
op.anchor.base(StdPointBase).dependingPoints := tmppnt
ELSE
WHILE plist.id < op.depID -1 DO plist := plist.next END;
tmppnt.next := plist.next; plist.next := tmppnt
END
END
ELSE
GivePointID(op.deppnt.base(StdPointBase).anchors);
plist := op.deppnt.base(StdPointBase).anchors; prevpnt := NIL;
WHILE plist.id # op.anchorID DO prevpnt := plist; plist := plist.next END;
IF prevpnt # NIL THEN prevpnt.next := plist.next
ELSE op.deppnt.base(StdPointBase).anchors := plist.next
END;
GivePointID(op.anchor.base(StdPointBase).dependingPoints);
plist := op.anchor.base(StdPointBase).dependingPoints; prevpnt := NIL;
WHILE plist.id # op.depID DO prevpnt := plist; plist := plist.next END;
IF prevpnt # NIL THEN prevpnt.next := plist.next
ELSE op.anchor.base(StdPointBase).dependingPoints := plist.next
END
END;
m.model.GetBoundingBox(tmplist, NIL, ll, tt, rr, bb);
msg.l := MIN(l, ll); msg.t := MIN(t, tt); msg.r := MAX(r, rr); msg.b := MAX(b, bb);
msg.add := op.add; msg.anchor := op.anchor; msg.comppnt := op.deppnt;
msg.figure := NIL; msg.pos := op.anchorID;
op.add := ~op.add;
Models.Broadcast(m.model, msg)
END Do;
PROCEDURE NewPointAnchorOp (m: StdModelBase; anchor: Point; deppnt: ConstrainedPoint;
anchorID, depID: INTEGER; add: BOOLEAN): PointAnchorOp;
VAR op: PointAnchorOp;
plist: StdPointList;
flist: StdFigureList;
BEGIN
NEW(op); op.add := add; op.model := m; op.anchor := anchor; op.deppnt := deppnt;
IF anchorID = last THEN
GivePointID(deppnt.base(StdPointBase).anchors);
plist := deppnt.base(StdPointBase).anchors;
IF plist = NIL THEN op.anchorID := 1
ELSE
WHILE plist.next # NIL DO plist := plist.next END;
op.anchorID := plist.id + 1
END
ELSE op.anchorID := anchorID
END;
IF depID = last THEN
GiveFigureID(anchor.base(StdPointBase).dependingFigures);
flist := anchor.base(StdPointBase).dependingFigures;
IF flist = NIL THEN op.depID := 1
ELSE
WHILE flist.next # NIL DO flist := flist.next END;
op.depID := flist.id + 1
END
ELSE op.depID := depID
END;
RETURN op
END NewPointAnchorOp;
(* MoveOp *)
PROCEDURE (op: MoveOp) Do;
VAR tmp: INTEGER; list: MoveList; msg: UpdateMsg;
l, t, r, b, ll, tt, rr, bb: INTEGER;
BEGIN
op.m.model.GetBoundingBox(op.m.points, op.m.figures, l, t, r, b);
IF op.first THEN op.first := FALSE
ELSE
list := op.list;
WHILE list # NIL DO
tmp := list.x; list.x := list.p.base(StdPointBase).x; list.p.base(StdPointBase).x := tmp;
tmp := list.y; list.y := list.p.base(StdPointBase).y; list.p.base(StdPointBase).y := tmp;
list := list.next
END
END;
op.m.model.GetBoundingBox(op.m.points, op.m.figures, ll, tt, rr, bb);
msg.l := MIN(l, ll); msg.t := MIN(t, tt); msg.r := MAX(r, rr); msg.b := MAX(b, bb);
Models.Broadcast(op.m.model, msg)
END Do;
(* SwapOp *)
PROCEDURE (op: SwapOp) Do;
VAR msg: UpdateMsg; p, prev, tmp, oplist: StdFigureList;
BEGIN
IF op.do THEN
oplist := op.flist; prev := NIL; p := op.model.figures;
WHILE oplist # NIL DO
WHILE p.f # oplist.f DO prev := p; p := p.next END;
IF prev = NIL THEN op.model.figures := p.next ELSE prev.next := p.next END;
p := p.next; oplist := oplist.next
END;
oplist := op.flist; p := NIL;
WHILE oplist # NIL DO
NEW(tmp); tmp.f := oplist.f; tmp.next := NIL;
IF p = NIL THEN p := tmp; prev := tmp ELSE prev.next := tmp; prev := tmp END;
oplist := oplist.next
END;
IF op.front THEN
prev := op.model.figures;
IF prev # NIL THEN
WHILE prev.next # NIL DO prev := prev.next END;
prev.next := p
ELSE op.model.figures := p
END
ELSE tmp.next := op.model.figures; op.model.figures := p
END
ELSE
IF op.front THEN
oplist := op.flist; p := op.model.figures; prev := NIL;
WHILE oplist.f # p.f DO prev := p; p := p.next END;
IF prev = NIL THEN op.model.figures := NIL ELSE prev.next := NIL END
ELSE
oplist := op.flist; prev := NIL; p := op.model.figures;
WHILE oplist # NIL DO prev := oplist; oplist := oplist.next END;
WHILE p.f # prev.f DO p := p.next END;
op.model.figures := p.next
END;
oplist := op.flist;
WHILE oplist # NIL DO
GiveFigureID(op.model.figures); NEW(tmp); tmp.f := oplist.f; p := op.model.figures;
IF p = NIL THEN tmp.next := NIL; op.model.figures := tmp
ELSE
IF oplist.id = 1 THEN tmp.next := op.model.figures; op.model.figures := tmp
ELSE
WHILE p.id < oplist.id - 1 DO p := p.next END;
tmp.next := p.next; p.next := tmp
END
END;
oplist := oplist.next
END
END;
op.model.model.GetBoundingBox(NIL, op.flist, msg.l, msg.t, msg.r, msg.b);
op.do := ~op.do;
Models.Broadcast(op.model.model, msg)
END Do;
PROCEDURE NewSwapOp (m: StdModelBase; flist: StdFigureList; do, front: BOOLEAN): SwapOp;
VAR op: SwapOp;
BEGIN
NEW(op); op.model := m; op.flist := flist; op.do := do; op.front := front;
RETURN op
END NewSwapOp;
(* LinkOp *)
PROCEDURE (op: LinkOp) Do;
VAR msg: ChangeAnchorMsg; tmppnt: Point;
anchors, pntlist, tmppntlist, tmppntlist2: StdPointList;
finished: BOOLEAN;
figlist, tmpfiglist, tmpfiglist2: StdFigureList;
l, t, r, b, ll, tt, rr, bb: INTEGER;
BEGIN
op.model.model.GetBoundingBox(op.model.points, op.model.figures, l, t, r, b);
IF op.figure # NIL THEN
anchors := op.figure.base(StdFigureBase).anchors; finished := FALSE;
WHILE (anchors # NIL) & (~finished) DO
IF anchors = op.sourceList THEN
anchors.p := op.target;
NEW(figlist); figlist.f := op.figure;
figlist.next := op.target.base(StdPointBase).dependingFigures;
op.target.base(StdPointBase).dependingFigures := figlist;
tmpfiglist := op.source.base(StdPointBase).dependingFigures; tmpfiglist2 := NIL;
WHILE tmpfiglist.f # op.figure DO tmpfiglist2 := tmpfiglist; tmpfiglist := tmpfiglist.next END;
IF tmpfiglist2 = NIL THEN op.source.base(StdPointBase).dependingFigures := tmpfiglist.next
ELSE tmpfiglist2.next := tmpfiglist.next
END;
finished := TRUE
ELSE anchors := anchors.next
END
END
ELSE
anchors := op.point.base(StdPointBase).anchors; finished := FALSE;
WHILE (anchors # NIL) & (~finished) DO
IF anchors = op.sourceList THEN
anchors.p := op.target;
NEW(pntlist); pntlist.p := op.point;
pntlist.next := op.target.base(StdPointBase).dependingPoints;
op.target.base(StdPointBase).dependingPoints := pntlist;
tmppntlist := op.source.base(StdPointBase).dependingPoints; tmppntlist2 := NIL;
WHILE tmppntlist.p(ConstrainedPoint) # op.point DO
tmppntlist2 := tmppntlist; tmppntlist := tmppntlist.next
END;
IF tmppntlist2 = NIL THEN op.source.base(StdPointBase).dependingPoints := tmppntlist.next
ELSE tmppntlist2.next := tmppntlist.next
END;
op.point(ConstrainedPoint).Calculate(
op.point.base(StdPointBase).x, op.point.base(StdPointBase).y);
finished := TRUE
ELSE anchors := anchors.next
END
END
END;
op.model.model.GetBoundingBox(op.model.points, op.model.figures, ll, tt, rr, bb);
msg.l := MIN(l, ll); msg.t := MIN(t, tt); msg.r := MAX(r, rr); msg.b := MAX(b, bb);
msg.newPoint := op.target; msg.oldPoint := op.source;
msg.figure := op.figure; msg.compPoint := op.point;
msg.pos := op.sourceList.id;
tmppnt := op.target; op.target := op.source; op.source := tmppnt;
Models.Broadcast(op.model.model, msg)
END Do;
PROCEDURE NewLinkOp (m: StdModelBase; target, source: Point;
sourceList: StdPointList; f: Figure; p: ConstrainedPoint): LinkOp;
VAR op: LinkOp;
BEGIN
NEW(op); op.model := m; op.target := target; op.source := source;
op.sourceList := sourceList; op.figure := f;op.point := p;
RETURN op
END NewLinkOp;
(* StdFigureList *)
PROCEDURE (f: StdFigureList) This (): Figure;
BEGIN
RETURN f.f
END This;
PROCEDURE (f: StdFigureList) Next (): FigureList;
BEGIN
RETURN f.next
END Next;
(* StdPointList *)
PROCEDURE (p: StdPointList) This (): Point;
BEGIN
RETURN p.p
END This;
PROCEDURE (p: StdPointList) Next (): PointList;
BEGIN
RETURN p.next
END Next;
(* StdPointBase *)
PROCEDURE (p: StdPointBase) Model (): Model;
BEGIN
RETURN p.m
END Model;
PROCEDURE (p: StdPointBase) X (): INTEGER;
BEGIN
RETURN p.x
END X;
PROCEDURE (p: StdPointBase) Y (): INTEGER;
BEGIN
RETURN p.y
END Y;
PROCEDURE (p: StdPointBase) Anchors (): PointList;
BEGIN
RETURN p.anchors
END Anchors;
PROCEDURE (p: StdPointBase) DependingPoints (): PointList;
BEGIN
RETURN p.dependingPoints
END DependingPoints;
PROCEDURE (p: StdPointBase) DependingFigures (): FigureList;
BEGIN
RETURN p.dependingFigures
END DependingFigures;
PROCEDURE (p: StdPointBase) Externalize (VAR wr: Stores.Writer);
BEGIN
wr.WriteVersion(currentPBVersion);
wr.WriteInt(p.x);
wr.WriteInt(p.y);
wr.WriteStore(p.m);
WritePointList(wr, NIL, p.dependingPoints);
WriteFigureList(wr, NIL, p.dependingFigures);
WritePointList(wr, NIL, p.anchors)
END Externalize;
PROCEDURE (p: StdPointBase) Internalize (VAR rd: Stores.Reader);
VAR version: INTEGER;
s: Stores.Store;
BEGIN
rd.ReadVersion(minPBVersion, maxPBVersion, version);
IF ~rd.cancelled THEN
rd.ReadInt(p.x);
rd.ReadInt(p.y);
rd.ReadStore(s);
IF s IS Model THEN p.m := s(Model) END;
ReadPointList(rd, NIL, p.dependingPoints);
ReadFigureList(rd, NIL, p.dependingFigures);
ReadPointList(rd, NIL, p.anchors)
END
END Internalize;
PROCEDURE (p: StdPointBase) CopyFrom (source: Stores.Store);
BEGIN
WITH source: StdPointBase DO
p.x := source.x; p.y := source.y
END
END CopyFrom;
(* StdFigureBase *)
PROCEDURE (f: StdFigureBase) Model (): Model;
BEGIN
RETURN f.m
END Model;
PROCEDURE (f: StdFigureBase) Anchors (): PointList;
BEGIN
RETURN f.anchors
END Anchors;
PROCEDURE (f: StdFigureBase) Externalize (VAR wr: Stores.Writer);
BEGIN
wr.WriteVersion(0);
wr.WriteStore(f.m);
WritePointList(wr, NIL, f.anchors)
END Externalize;
PROCEDURE (f: StdFigureBase) Internalize (VAR rd: Stores.Reader);
VAR version: INTEGER;
s: Stores.Store;
BEGIN
rd.ReadVersion(0, 0, version);
IF ~rd.cancelled THEN
rd.ReadStore(s);
IF s IS Model THEN f.m := s(Model) END;
ReadPointList(rd, NIL, f.anchors)
END
END Internalize;
PROCEDURE (f: StdFigureBase) CopyFrom (source: Stores.Store);
BEGIN
WITH source: StdFigureBase DO
ELSE
END
END CopyFrom;
(* StdModelBase *)
PROCEDURE (m: StdModelBase) InitFrom (source: ModelBase);
BEGIN
m.points := NIL; m.figures := NIL
END InitFrom;
PROCEDURE (m: StdModelBase) InsertCopyFrom (source: ModelBase;
plist: PointList; flist: FigureList;
OUT newPoints: PointList;
OUT newFigures: FigureList
), NEW;
VAR stores: ARRAY 5000 OF Stores.Store; index: INTEGER;
tmppnts, anchors, oldAnchors: PointList; tmpfigs: FigureList;
lastinsertedpnt, newAnchors, prevpnt, tmpstdpnts, newPlist, allPoints,stdpntlist, tmpplist: StdPointList;
prevfig, tmpstdfigs, allFigures, stdfiglist, tmpflist: StdFigureList;
point: Point; figure: Figure;
belongsTo: BOOLEAN; base: ModelBase;
PROCEDURE PointInList (pnt: Point; plist: PointList): BOOLEAN;
BEGIN
WHILE (plist # NIL) & (plist.This() # pnt) DO plist := plist.Next() END;
RETURN plist # NIL
END PointInList;
PROCEDURE SetPointID (pnt: Point; plist: StdPointList; id: INTEGER);
VAR tmp: StdPointList;
BEGIN
tmp := plist; WHILE (tmp # NIL) & (tmp.p # pnt) DO tmp := tmp.next END;
IF tmp # NIL THEN tmp.id := id END
END SetPointID;
PROCEDURE SetFigureID (fig: Figure; flist: StdFigureList; id: INTEGER);
VAR tmp: StdFigureList;
BEGIN
tmp := flist; WHILE (tmp # NIL) & (tmp.f # fig) DO tmp := tmp.next END;
IF tmp # NIL THEN tmp.id := id END
END SetFigureID;
PROCEDURE FindPointID (pnt: Point; plist: StdPointList): INTEGER;
VAR tmp: StdPointList;
BEGIN
tmp := plist; WHILE (tmp # NIL) & (tmp.p # pnt) DO tmp := tmp.next END;
RETURN tmp.id
END FindPointID;
PROCEDURE PointAnchorsAreInList (cpnt: ConstrainedPoint): BOOLEAN;
VAR plist: PointList;
BEGIN
plist := cpnt.Anchors();
WHILE (plist # NIL) & (plist.This().base(StdPointBase).id # 0) DO plist := plist.Next() END;
RETURN plist = NIL
END PointAnchorsAreInList;
PROCEDURE PointAnchorsAreInList2 (cpnt: ConstrainedPoint): BOOLEAN;
VAR plist: PointList;
BEGIN
plist := cpnt.Anchors();
WHILE (plist # NIL) & (FindPointID(plist.This(), allPoints) # 0) DO plist := plist.Next() END;
RETURN plist = NIL
END PointAnchorsAreInList2;
PROCEDURE ClonePoint (pnt: Point): Point;
VAR pnt2, anchors, lastinserted, tmppnts, p: StdPointList;
comppnt: ConstrainedPoint;
baspnt: FreePoint;
point: Point;
BEGIN
IF pnt.base(StdPointBase).id = 1 THEN
IF (pnt IS ConstrainedPoint) & PointAnchorsAreInList(pnt(ConstrainedPoint)) THEN
pnt.base(StdPointBase).id := index; INC(index);
comppnt := Stores.CopyOf(pnt)(ConstrainedPoint);
tmppnts := pnt(ConstrainedPoint).base(StdPointBase).anchors; anchors := NIL;
WHILE tmppnts # NIL DO
point := ClonePoint(tmppnts.This());
NEW(pnt2); pnt2.p := point; pnt2.next := NIL;
IF anchors = NIL THEN anchors := pnt2; lastinserted := pnt2
ELSE lastinserted.next := pnt2; lastinserted := pnt2
END;
tmppnts := tmppnts.next
END;
m.model.InsertObject(comppnt, anchors, pnt.X(), pnt.Y());
comppnt.base(StdPointBase).id := pnt.base(StdPointBase).id;
stores[comppnt.base(StdPointBase).id] := comppnt;
NEW(p); p.p := comppnt; p.next := NIL;
IF newPoints = NIL THEN
newPoints := p; prevpnt := p ELSE prevpnt.next := p; prevpnt := p
END;
RETURN comppnt
ELSE
pnt.base(StdPointBase).id := index; INC(index);
baspnt := m.model.NewFreePoint(pnt.X(), pnt.Y());
baspnt.base(StdPointBase).id := pnt.base(StdPointBase).id;
stores[baspnt.base(StdPointBase).id] := baspnt;
NEW(p); p.p := baspnt; p.next := NIL;
IF newPoints = NIL THEN
newPoints := p; prevpnt := p ELSE prevpnt.next := p; prevpnt := p
END;
RETURN baspnt
END
ELSE RETURN stores[pnt.base(StdPointBase).id](Point)
END
END ClonePoint;
PROCEDURE ClonePoint2 (pnt: Point): Point;
VAR pnt2, anchors, lastinserted, tmppnts: StdPointList;
points: PointList;
comppnt: ConstrainedPoint;
baspnt: FreePoint;
point: Point;
id: INTEGER;
BEGIN
id := FindPointID(pnt, allPoints);
IF id = 1 THEN
IF (pnt IS ConstrainedPoint) & PointAnchorsAreInList2(pnt(ConstrainedPoint)) THEN
SetPointID(pnt, allPoints, index); INC(index);
comppnt := Stores.CopyOf(pnt)(ConstrainedPoint);
points := pnt(ConstrainedPoint).Anchors(); anchors := NIL;
WHILE points # NIL DO
point := ClonePoint2(points.This());
NEW(pnt2); pnt2.p := point; pnt2.next := NIL;
IF anchors = NIL THEN anchors := pnt2; lastinserted := pnt2
ELSE lastinserted.next := pnt2; lastinserted := pnt2
END;
points := points.Next()
END;
m.model.InsertObject(comppnt, anchors, pnt.X(), pnt.Y());
stores[FindPointID(pnt, allPoints)] := comppnt;
NEW(tmppnts); tmppnts.p := comppnt; tmppnts.next := NIL;
IF newPoints = NIL THEN newPoints := tmppnts; prevpnt := tmppnts
ELSE prevpnt.next := tmppnts; prevpnt := tmppnts
END;
RETURN comppnt
ELSE
SetPointID(pnt, allPoints, index); INC(index);
baspnt := m.model.NewFreePoint(pnt.X(), pnt.Y());
stores[FindPointID(pnt, allPoints)] := baspnt;
NEW(tmppnts); tmppnts.p := baspnt; tmppnts.next := NIL;
IF newPoints = NIL THEN newPoints := tmppnts; prevpnt := tmppnts
ELSE prevpnt.next := tmppnts; prevpnt := tmppnts
END;
RETURN baspnt
END
ELSE RETURN stores[FindPointID(pnt, allPoints)](Point)
END
END ClonePoint2;
BEGIN
belongsTo := TRUE; tmppnts := plist;
WHILE (tmppnts # NIL) & belongsTo DO
belongsTo := tmppnts.This().Model().base = source; tmppnts := tmppnts.Next()
END;
ASSERT(belongsTo, 20);
belongsTo := TRUE; tmpfigs := flist;
WHILE (tmpfigs # NIL) & belongsTo DO
belongsTo := tmpfigs.This().Model().base = source; tmpfigs := tmpfigs.Next()
END;
ASSERT(belongsTo, 21);
newPoints := NIL; newFigures := NIL; prevfig := NIL; prevpnt := NIL; index := 2;
base := source;
WITH base: StdModelBase DO
(* Initialize the id of all points and figures in source to 0. *)
tmpstdpnts := base.points;
WHILE tmpstdpnts # NIL DO tmpstdpnts.p.base(StdPointBase).id := 0; tmpstdpnts := tmpstdpnts.next END;
tmpstdfigs := base.figures;
WHILE tmpstdfigs # NIL DO
tmpstdfigs.f.base(StdFigureBase).id := 0; tmpstdfigs := tmpstdfigs.next
END;
(* Include anchorpoints for figures in flist, if they're not in plist. *)
IF plist # NIL THEN newPlist := plist(StdPointList) ELSE newPlist := NIL END;
IF flist # NIL THEN tmpstdfigs := flist(StdFigureList) ELSE tmpstdfigs := NIL END;
WHILE tmpstdfigs # NIL DO
anchors := tmpstdfigs.This().Anchors();
WHILE anchors # NIL DO
IF ~PointInList(anchors.This(), newPlist) THEN
NEW(stdpntlist);
stdpntlist.p := anchors.This(); stdpntlist.next := newPlist; newPlist := stdpntlist
END;
anchors := anchors.Next()
END;
tmpstdfigs :=tmpstdfigs.next
END;
(* Set the id of all points and figures to be copied to 1. *)
IF flist # NIL THEN tmpstdfigs := flist(StdFigureList) ELSE tmpstdfigs := NIL END;
WHILE tmpstdfigs # NIL DO
tmpstdfigs.f.base(StdFigureBase).id := 1; tmpstdfigs := tmpstdfigs.next
END;
tmpstdpnts := newPlist;
WHILE tmpstdpnts # NIL DO
tmpstdpnts.p.base(StdPointBase).id := 1; tmpstdpnts := tmpstdpnts.next
END;
(* Copy the points in newPList. *)
tmpstdpnts := newPlist;
WHILE tmpstdpnts # NIL DO point := ClonePoint(tmpstdpnts.p); tmpstdpnts := tmpstdpnts.next END;
(* Copy the figures in flist. *)
tmpstdfigs := base.figures;
WHILE tmpstdfigs # NIL DO
IF (tmpstdfigs.f.base(StdFigureBase).id = 1) THEN
figure := Stores.CopyOf(tmpstdfigs.f)(Figure);
newAnchors := NIL; oldAnchors := tmpstdfigs.f.base(StdFigureBase).anchors;
(* Copy their anchorpoints. *)
WHILE oldAnchors # NIL DO
point := ClonePoint(oldAnchors.This());
NEW(stdpntlist); stdpntlist.p := point; stdpntlist.next := NIL;
IF newAnchors = NIL THEN newAnchors := stdpntlist; lastinsertedpnt := stdpntlist
ELSE lastinsertedpnt.next := stdpntlist; lastinsertedpnt := stdpntlist
END;
oldAnchors := oldAnchors.Next()
END;
m.model.InsertObject(figure, newAnchors, undefined, undefined);
figure.base(StdFigureBase).id := 0;
NEW(stdfiglist); stdfiglist.f := figure; stdfiglist.next := NIL;
IF newFigures = NIL THEN newFigures := stdfiglist; prevfig := stdfiglist
ELSE prevfig.next := stdfiglist; prevfig := stdfiglist
END
END;
tmpstdfigs := tmpstdfigs.next
END
| base: ModelBase DO
(* Copy all points in source to a StdPointList. *)
tmppnts := source.model.Points(); allPoints := NIL;
WHILE tmppnts # NIL DO
NEW(stdpntlist); stdpntlist.id := 0; stdpntlist.p := tmppnts.This(); stdpntlist.next := NIL;
IF allPoints = NIL THEN allPoints := stdpntlist; tmpplist := stdpntlist
ELSE tmpplist.next := stdpntlist; tmpplist := tmpplist.next
END;
tmppnts := tmppnts.Next()
END;
(* Copy all figures in source to a StdFigureList. *)
tmpfigs := source.model.Figures(); allFigures := NIL;
WHILE tmpfigs # NIL DO
NEW(stdfiglist); stdfiglist.id := 0; stdfiglist.f := tmpfigs.This(); stdfiglist.next := NIL;
IF allFigures = NIL THEN allFigures := stdfiglist; tmpflist := stdfiglist
ELSE tmpflist.next := stdfiglist; tmpflist := tmpflist.next
END;
tmpfigs := tmpfigs.Next()
END;
(* Include anchorpoints for figures in flist, if they're not in plist. *)
IF plist # NIL THEN newPlist := plist(StdPointList) ELSE newPlist := NIL END;
tmpfigs := flist;
WHILE tmpfigs # NIL DO
anchors := tmpfigs.This().Anchors();
WHILE anchors # NIL DO
IF ~PointInList(anchors.This(), newPlist) THEN
NEW(stdpntlist);
stdpntlist.p := anchors.This(); stdpntlist.next := newPlist; newPlist := stdpntlist
END;
anchors := anchors.Next()
END;
tmpfigs :=tmpfigs.Next()
END;
(* Set the id of all points and figures to be copied to 1. *)
tmpfigs := flist;
WHILE tmpfigs # NIL DO SetFigureID(tmpfigs.This(), allFigures, 1); tmpfigs := tmpfigs.Next() END;
tmppnts := newPlist;
WHILE tmppnts # NIL DO SetPointID(tmppnts.This(), allPoints, 1); tmppnts := tmppnts.Next() END;
(* Copy the points in plist. *)
tmppnts := newPlist;
WHILE tmppnts # NIL DO point := ClonePoint2(tmppnts.This()); tmppnts := tmppnts.Next() END;
(* Copy the figures in flist. *)
tmpstdfigs := allFigures;
WHILE tmpstdfigs # NIL DO
IF (tmpstdfigs.id = 1) THEN
figure := Stores.CopyOf(tmpstdfigs.f)(Figure);
newAnchors := NIL; oldAnchors := tmpstdfigs.f.Anchors();
(* Copy their anchorpoints. *)
WHILE oldAnchors # NIL DO
point := ClonePoint2(oldAnchors.This());
NEW(stdpntlist); stdpntlist.p := point; stdpntlist.next := NIL;
IF newAnchors = NIL THEN newAnchors := stdpntlist; lastinsertedpnt := stdpntlist
ELSE lastinsertedpnt.next := stdpntlist; lastinsertedpnt := stdpntlist
END;
oldAnchors := oldAnchors.Next()
END;
m.model.InsertObject(figure, newAnchors, undefined, undefined);
tmpstdfigs.id := 0;
NEW(stdfiglist); stdfiglist.f := figure; stdfiglist.next := NIL;
IF newFigures = NIL THEN newFigures := stdfiglist; prevfig := stdfiglist
ELSE prevfig.next := stdfiglist; prevfig := stdfiglist
END
END;
tmpstdfigs := tmpstdfigs.next
END
ELSE
END
END InsertCopyFrom;
PROCEDURE (m: StdModelBase) InsertCopy (source: ModelBase;
plist: PointList; flist: FigureList;
OUT newPoints: PointList;
OUT newFigures: FigureList);
BEGIN
m.InsertCopyFrom(source, plist, flist, newPoints, newFigures)
END InsertCopy;
PROCEDURE (m: StdModelBase) CopyDataFrom (source: Stores.Store);
VAR tmpfigs: FigureList;
tmppnts: PointList;
BEGIN
WITH source: StdModelBase DO
m.InsertCopyFrom(source, source.points, source.figures, tmppnts, tmpfigs)
| source: ModelBase DO
m.InsertCopyFrom(source, source.model.Points(), source.model.Figures(), tmppnts, tmpfigs)
ELSE
END
END CopyDataFrom;
PROCEDURE (m: StdModelBase) WriteData (VAR wr: Stores.Writer);
BEGIN
wr.WriteVersion(currentStdVersion);
WritePointList(wr, m, m.points);
WriteFigureList(wr, m, m.figures)
END WriteData;
PROCEDURE (m: StdModelBase) ReadData (VAR rd: Stores.Reader);
VAR version: INTEGER;
BEGIN
rd.ReadVersion(minStdVersion, maxStdVersion, version);
IF ~rd.cancelled THEN
(* alienFigures := NIL; alienPoints := NIL; *)
ReadPointList(rd, m, m.points);
ReadFigureList(rd, m, m.figures)
END
END ReadData;
PROCEDURE (m: StdModelBase) Points (): PointList;
BEGIN
RETURN m.points
END Points;
PROCEDURE (m: StdModelBase) Figures (): FigureList;
BEGIN
RETURN m.figures
END Figures;
PROCEDURE (m: StdModelBase) InsertObject (
o: Object; anchors: PointList; x, y: INTEGER
);
VAR plist, tmplist, newlist, prev: StdPointList; flist: StdFigureList; i: INTEGER;
BEGIN
newlist := NIL; prev := NIL;
WHILE anchors # NIL DO
NEW(tmplist); tmplist.p := anchors.This(); tmplist.next := NIL;
IF newlist = NIL THEN
newlist := tmplist; prev := tmplist
ELSE
prev.next := tmplist; prev := tmplist
END;
anchors := anchors.Next()
END;
IF o IS Figure THEN
o(Figure).base(StdFigureBase).m := m.model;
GiveFigureID(m.figures); flist := m.figures;
IF flist = NIL THEN i := 1
ELSE
WHILE flist.next # NIL DO flist := flist.next END;
i := flist.id + 1
END;
o(Figure).base(StdFigureBase).anchors := newlist;
Models.Do(m.model, "Insert Figure", NewFigureOp(m, o(Figure), i, TRUE))
ELSIF o IS Point THEN
o(Point).base(StdPointBase).m := m.model;
o(Point).base(StdPointBase).x := x; o(Point).base(StdPointBase).y := y;
GivePointID(m.points); plist := m.points;
IF plist = NIL THEN
i := 1
ELSE
WHILE plist.next # NIL DO plist := plist.next END;
i := plist.id + 1
END;
o(Point).base(StdPointBase).anchors := newlist;
Models.Do(m.model, "Insert Point", NewPointOp(m, o(Point), i, TRUE));
IF o IS ConstrainedPoint THEN
o(ConstrainedPoint).Calculate(
o(Point).base(StdPointBase).x, o(Point).base(StdPointBase).y
)
END
END
END InsertObject;
PROCEDURE (m: StdModelBase) RemoveObject (o: Object);
VAR plist: StdPointList; flist: StdFigureList;
BEGIN
IF o IS Figure THEN
flist := m.figures; GiveFigureID(flist); WHILE flist.f # o(Figure) DO flist := flist.next END;
Models.Do(m.model, "Remove Figure", NewFigureOp(m, o(Figure), flist.id, FALSE))
ELSIF o IS Point THEN
IF (o(Point).DependingPoints() = NIL) & (o(Point).DependingFigures() = NIL) THEN
plist := m.points; GivePointID(plist); WHILE plist.p # o(Point) DO plist := plist.next END;
Models.Do(m.model, "Remove Point", NewPointOp(m, o(Point), plist.id, FALSE))
END
END
END RemoveObject;
PROCEDURE (m: StdModelBase) MovePoints (plist: PointList; dx, dy: INTEGER);
VAR l, t, r, b: INTEGER;
tmplist: PointList;
deptbm, last: StdPointList;
op: MoveOp;
lastmove: MoveList;
PROCEDURE IsInList (p: Point; plist: PointList): BOOLEAN;
BEGIN
WHILE (plist # NIL) & (plist.This() # p) DO plist := plist.Next() END;
RETURN plist # NIL
END IsInList;
PROCEDURE Handle (p: Point);
VAR anchors, deppnts: PointList;
pnts: StdPointList;
movelist: MoveList;
isinlist: BOOLEAN;
BEGIN
IF p.base(StdPointBase).id # ok THEN
IF p IS ConstrainedPoint THEN
anchors := p(ConstrainedPoint).Anchors();
WHILE anchors # NIL DO Handle(anchors.This()); anchors := anchors.Next() END
END;
IF p.base(StdPointBase).id = toBeMoved THEN
p.base(StdPointBase).id := ok;
IF ~(p IS AlienPoint) & ~AlienDependencies(p) THEN
NEW(movelist); movelist.next := NIL; movelist.p := p;
IF op.list = NIL THEN op.list := movelist ELSE lastmove.next := movelist END;
lastmove := movelist; isinlist := IsInList(p, plist);
IF (p IS ConstrainedPoint) & isinlist THEN
movelist.x := p.X(); movelist.y := p.Y();
p.base(StdPointBase).x := p.X() + dx; p.base(StdPointBase).y := p.Y() + dy;
p(ConstrainedPoint).Calculate(p.base(StdPointBase).x, p.base(StdPointBase).y)
ELSIF (p IS ConstrainedPoint) & ~isinlist THEN
movelist.x := p.X(); movelist.y := p.Y();
p(ConstrainedPoint).Calculate(p.base(StdPointBase).x, p.base(StdPointBase).y)
ELSE
movelist.x := p.X(); movelist.y := p.Y();
p.base(StdPointBase).x := p.X() + dx; p.base(StdPointBase).y := p.Y() + dy
END;
deppnts := p.DependingPoints();
WHILE deppnts # NIL DO
IF deppnts.This().base(StdPointBase).id # toBeMoved THEN
NEW(pnts); pnts.p := deppnts.This(); pnts.next := NIL;
IF deptbm = NIL THEN deptbm := pnts ELSE last.next := pnts END;
last := pnts; pnts.p.base(StdPointBase).id := toBeMoved
END;
deppnts := deppnts.Next()
END
END
ELSE p.base(StdPointBase).id := ok
END
END
END Handle;
BEGIN
IF plist # NIL THEN
ASSERT(plist.This().Model() = m.model, 20);
m.model.GetBoundingBox(plist, NIL, l, t, r, b);
IF l + dx < 0 THEN dx := - l END;
IF t + dy < 0 THEN dy := - t END;
deptbm := NIL; last := NIL; lastmove := NIL; NEW(op); op.m := m; op.first := TRUE;
tmplist := m.model.Points();
WHILE tmplist # NIL DO tmplist.This().base(StdPointBase).id := 0; tmplist := tmplist.Next() END;
tmplist := plist;
WHILE tmplist # NIL DO
tmplist.This().base(StdPointBase).id := toBeMoved;
tmplist := tmplist.Next()
END;
tmplist := plist; WHILE tmplist # NIL DO Handle(tmplist.This()); tmplist := tmplist.Next() END;
tmplist := deptbm; WHILE tmplist # NIL DO Handle(tmplist.This()); tmplist := tmplist.Next() END;
IF op.list # NIL THEN Models.Do(m.model, " Move", op) END
END
END MovePoints;
PROCEDURE (m: StdModelBase) MovePoint (p: Point; dx, dy: INTEGER);
VAR plist: StdPointList;
BEGIN
ASSERT(p # NIL, 20);
NEW(plist); plist.p := p; plist.next := NIL;
m.model.MovePoints(plist, dx, dy)
END MovePoint;
PROCEDURE (m: StdModelBase) MoveToGrid (plist: PointList; grid: INTEGER);
VAR x0, y0: INTEGER;
s: Stores.Operation;
BEGIN
ASSERT(grid > 0, 20);
Models.BeginScript(m.model, "Move To Grid", s);
WHILE plist # NIL DO
IF ~(plist.This() IS ConstrainedPoint) THEN
x0 := plist.This().X() + grid DIV 2; x0 := x0 - x0 MOD grid;
y0 := plist.This().Y() + grid DIV 2; y0 := y0 - y0 MOD grid;
m.model.MovePoint(plist.This(), x0 - plist.This().X(), y0 - plist.This().Y())
END;
plist := plist.Next()
END;
Models.EndScript(m.model, s)
END MoveToGrid;
PROCEDURE (m: StdModelBase) BringToFront (flist: FigureList);
VAR figlist, oplist, node, prev: StdFigureList;
tmplist: FigureList;
i: INTEGER;
BEGIN
i := 1; oplist := NIL; prev := NIL; figlist := m.figures;
WHILE figlist # NIL DO
figlist.f.base(StdFigureBase).id := 0; figlist.id := i; INC(i); figlist := figlist.next
END;
tmplist := flist;
WHILE tmplist # NIL DO
tmplist.This().base(StdFigureBase).id := 1; tmplist := tmplist.Next()
END;
figlist := m.figures;
WHILE figlist # NIL DO
IF figlist.f.base(StdFigureBase).id = 1 THEN
NEW(node); IF oplist = NIL THEN oplist := node ELSE prev.next := node END;
prev := node; node.f := figlist.f; node.id := figlist.id; node.next := NIL
END;
figlist := figlist.next
END;
Models.Do(m.model, "Bring To Front", NewSwapOp(m, oplist, TRUE, TRUE))
END BringToFront;
PROCEDURE (m: StdModelBase) SendToBack (flist: FigureList);
VAR figlist, oplist, node, prev: StdFigureList;
tmplist: FigureList;
i: INTEGER;
BEGIN
i := 1; oplist := NIL; prev := NIL; figlist := m.figures;
WHILE figlist # NIL DO
figlist.f.base(StdFigureBase).id := 0; figlist.id := i; INC(i); figlist := figlist.next
END;
tmplist := flist;
WHILE tmplist # NIL DO tmplist.This().base(StdFigureBase).id := 1; tmplist := tmplist.Next() END;
figlist := m.figures;
WHILE figlist # NIL DO
IF figlist.f.base(StdFigureBase).id = 1 THEN
NEW(node); IF oplist = NIL THEN oplist := node ELSE prev.next := node END;
prev := node; node.f := figlist.f; node.id := figlist.id; node.next := NIL
END;
figlist := figlist.next
END;
Models.Do(m.model, "Send To Back", NewSwapOp(m, oplist, TRUE, FALSE))
END SendToBack;
PROCEDURE (m: StdModelBase) ChangeAnchor (o: Object; p: Point; pos: INTEGER);
VAR anchors: StdPointList;
BEGIN
IF o IS ConstrainedPoint THEN anchors := o(ConstrainedPoint).base(StdPointBase).anchors
ELSIF o IS Figure THEN anchors := o(Figure).base(StdFigureBase).anchors
END;
GivePointID(anchors); WHILE (anchors # NIL) & (anchors.id # pos) DO anchors := anchors.next END;
IF anchors # NIL THEN
IF o IS Figure THEN
Models.Do(m.model, "Change of Anchorpoint", NewLinkOp(m, p, anchors.p, anchors, o(Figure), NIL))
ELSIF o IS ConstrainedPoint THEN
Models.Do(m.model, "Change of Anchorpoint",
NewLinkOp(m, p, anchors.p, anchors, NIL, o(ConstrainedPoint)))
END
END
END ChangeAnchor;
PROCEDURE (m: StdModelBase) AddAnchor (o: Object; pos: INTEGER; p: Point);
BEGIN
WITH o : ConstrainedPoint DO
Models.Do(m.model, "Add Anchorpoint", NewPointAnchorOp(m, p, o, pos + 1, last, TRUE))
| o : Figure DO
Models.Do(m.model, "Add Anchorpoint", NewFigureAnchorOp(m, p, o, pos + 1, last, TRUE))
ELSE
END
END AddAnchor;
PROCEDURE (m: StdModelBase) RemoveAnchor (o: Object; p: Point);
VAR plist1, plist2: StdPointList;
flist: StdFigureList;
tmpaID, tmpdID: INTEGER;
BEGIN
tmpaID := 0; tmpdID := 0;
IF o IS Figure THEN
plist1 := o(Figure).base(StdFigureBase).anchors; flist := p.base(StdPointBase).dependingFigures;
GivePointID(plist1); GiveFigureID(flist);
WHILE (flist # NIL) & (flist.f # o(Figure)) DO flist := flist.next END;
IF flist # NIL THEN tmpdID := flist.id END
ELSIF o IS ConstrainedPoint THEN
plist1 := o(ConstrainedPoint).base(StdPointBase).anchors; plist2 := p.base(StdPointBase).dependingPoints;
GivePointID(plist1); GivePointID(plist2);
WHILE (plist2 # NIL) & (plist2.p # o(ConstrainedPoint)) DO plist2 := plist2.next END;
IF plist2 # NIL THEN tmpdID := plist2.id END
END;
WHILE (plist1 # NIL) & (plist1.p # p) DO plist1 := plist1.next END;
IF plist1 # NIL THEN tmpaID := plist1.id END;
IF (tmpaID # 0) & (tmpdID # 0) THEN
IF o IS ConstrainedPoint THEN
Models.Do(m.model, "Remove Anchorpoint",
NewPointAnchorOp(m, p, o(ConstrainedPoint), tmpaID, tmpdID, FALSE))
ELSIF o IS Figure THEN
Models.Do(m.model, "Remove Anchorpoint",
NewFigureAnchorOp(m, p, o(Figure), tmpaID, tmpdID, FALSE))
END
END
END RemoveAnchor;
PROCEDURE (m: StdModelBase) NewPointBase (): PointBase;
VAR base: StdPointBase;
BEGIN
NEW(base); base.m := NIL; base.x := 0; base.y := 0; base.id := 0;
base.anchors := NIL; base.dependingPoints := NIL; base.dependingFigures := NIL;
RETURN base
END NewPointBase;
PROCEDURE (m: StdModelBase) NewFigureBase (): FigureBase;
VAR base: StdFigureBase;
BEGIN
NEW(base); base.m := NIL; base.anchors := NIL; base.id := 0;
RETURN base
END NewFigureBase;
PROCEDURE (m: StdModelBase) ThisPointList (pnts: ARRAY OF Point): PointList;
VAR n, i : INTEGER;
plist, tmp: StdPointList;
allBelongs: BOOLEAN;
BEGIN
n := LEN(pnts); i := 0; allBelongs := TRUE; plist := NIL;
WHILE i < n DO
IF pnts[i].Model() # m.model THEN allBelongs := FALSE; i := n ELSE INC(i) END
END;
IF allBelongs THEN
i := n - 1; WHILE i >= 0 DO NEW(tmp); tmp.p := pnts[i]; tmp.next := plist; plist := tmp; DEC(i) END
END;
RETURN plist
END ThisPointList;
PROCEDURE (m: StdModelBase) ThisFigureList (figs: ARRAY OF Figure): FigureList;
VAR n, i : INTEGER; flist, tmp: StdFigureList; allBelongs: BOOLEAN;
BEGIN
n := LEN(figs); i := 0; allBelongs := TRUE; flist := NIL;
WHILE i < n DO
IF figs[i].Model() # m.model THEN allBelongs := FALSE; i := n ELSE INC(i) END
END;
IF allBelongs THEN
i := n - 1; WHILE i >= 0 DO NEW(tmp); tmp.f := figs[i]; tmp.next := flist; flist := tmp; DEC(i) END
END;
RETURN flist
END ThisFigureList;
(* StdDirectory *)
PROCEDURE (d: StdDirectory) NewModelBase (): ModelBase;
VAR m: StdModelBase;
BEGIN
NEW(m); m.points := NIL; m.figures := NIL;
RETURN m
END NewModelBase;
PROCEDURE Init*;
VAR d: StdDirectory;
BEGIN
NEW(d); SetDir(d)
END Init;
BEGIN
Init
END FigModels.
| Fig/Mod/Models.odc |
MODULE FigPoints;
IMPORT Stores, Math, Properties, Models, Dialog,
FigModels, FigViews;
CONST
currentVersion = 1; minVersion = 0; maxVersion = 1;
fixed* = 0; proportion* = 1;
TYPE
LinePoint* = POINTER TO LIMITED RECORD (FigModels.ConstrainedPoint)
fixed: BOOLEAN;
proportion: REAL
END;
LinePointDlg* = RECORD
fixed*: BOOLEAN;
percent*: INTEGER
END;
LinePointProportionProp* = POINTER TO RECORD (Properties.Property)
fixed*: BOOLEAN;
proportion*: REAL
END;
SetLinePointProportionOp = POINTER TO RECORD (Stores.Operation)
point: LinePoint;
old, prop: LinePointProportionProp
END;
CirclePoint* = POINTER TO LIMITED RECORD (FigModels.ConstrainedPoint) END;
CenterPoint* = POINTER TO LIMITED RECORD (FigModels.ConstrainedPoint) END;
CornerPoint* = POINTER TO LIMITED RECORD (FigModels.ConstrainedPoint)
xi, yi: INTEGER
END;
ParallelPoint* = POINTER TO LIMITED RECORD (FigModels.ConstrainedPoint) END;
RectanglePoint* = POINTER TO LIMITED RECORD (FigModels.ConstrainedPoint) END;
ProjectionPoint* = POINTER TO LIMITED RECORD (FigModels.ConstrainedPoint) END;
VAR
dlg*: LinePointDlg;
PROCEDURE Adjust (anchors: FigModels.PointList; fixed: BOOLEAN; proportion: REAL; VAR x, y: INTEGER);
VAR x0, y0, x1, y1, f : REAL; a: FigModels.Point;
BEGIN
a := anchors.This(); x1 := a.X(); y1 := a.Y();
a := anchors.Next().This(); x0 := a.X(); y0 := a.Y();
IF (x0 # x1) OR (y0 # y1) THEN
IF ((x = FigModels.undefined) & (y = FigModels.undefined)) OR fixed THEN f := proportion
ELSIF x = FigModels.undefined THEN x := SHORT(ENTIER((x1 - x0) / (y1 - y0) * (y - y0) + x0))
ELSIF y = FigModels.undefined THEN y := SHORT(ENTIER((y1 - y0) / (x1 - x0) * (x - x0) + y0))
ELSE f := ((x1 - x0) * (x - x0) + (y1 - y0) * (y - y0)) / ((x1 - x0) * (x1 - x0) + (y1 - y0) * (y1 - y0))
END;
x := SHORT(ENTIER(x0 + (x1 - x0) * f + 0.5)); y := SHORT(ENTIER(y0 + (y1 - y0) * f + 0.5))
ELSIF fixed THEN x := a.X(); y := a.Y()
END
END Adjust;
(* SetProportionOp *)
PROCEDURE (op: SetLinePointProportionOp) Do;
VAR p: LinePointProportionProp; point: LinePoint;
BEGIN
p := op.prop; op.prop := op.old; op.old := p;
point := op.point;
IF fixed IN p.valid THEN point.fixed := p.fixed END;
IF proportion IN p.valid THEN point.proportion := p.proportion END
END Do;
PROCEDURE SetProportionProp (p: LinePoint; old, prop: LinePointProportionProp);
VAR x0, x1, y0, y1: INTEGER;
op: SetLinePointProportionOp; s: Stores.Operation; m: FigModels.Model;
BEGIN
ASSERT((old # NIL) & (prop # NIL), 20);
NEW(op); op.point := p; op.old := old; op.prop := prop;
m := p.Model();
Models.BeginScript(m, "Set Properties", s);
Models.Do(m, "Set Properties", op);
x0 := p.X(); y0 := p.Y();
x1 := x0; y1 := y0; Adjust(p.Anchors(), TRUE, p.proportion, x1, y1);
m.MovePoint(p, x1 - x0, y1 - y0);
Models.EndScript(m, s)
END SetProportionProp;
PROCEDURE GetProportionProp (p: LinePoint; OUT prop: LinePointProportionProp);
VAR x, y, x0, y0, x1, y1: INTEGER; d: REAL; q: FigModels.PointList; a: FigModels.Point;
BEGIN
NEW(prop); prop.known := {fixed, proportion}; prop.valid := {fixed};
prop.fixed := p.fixed;
IF p.fixed THEN prop.proportion := p.proportion; INCL(prop.valid, proportion)
ELSE
x := p.X(); y := p.Y();
q := p.Anchors();
a := q.This(); x1 := a.X(); y1 := a.Y();
a := q.Next().This(); x0 := a.X(); y0 := a.Y();
d := Math.IntPower(x1 - x0, 2) + Math.IntPower(y1 - y0, 2);
IF d # 0 THEN
prop.proportion := Math.Sqrt((Math.IntPower(x - x0, 2) + Math.IntPower(y - y0, 2)) / d);
IF (x < x0) # (x1 < x0) THEN prop.proportion := -1 * prop.proportion END;
INCL(prop.valid, proportion)
END
END
END GetProportionProp;
(* ProportionProp *)
PROCEDURE (p: LinePointProportionProp) IntersectWith* (q: Properties.Property; OUT equal: BOOLEAN);
VAR valid: SET;
BEGIN
WITH q: LinePointProportionProp DO
p.known := p.known + q.known;
valid := p.valid * q.valid;
IF p.fixed # q.fixed THEN EXCL(valid, fixed) END;
IF p.proportion # q.proportion THEN EXCL(valid, proportion) END;
equal := p.valid = valid; p.valid := valid
END
END IntersectWith;
(* Point *)
PROCEDURE (p: LinePoint) Action*;
VAR res: INTEGER; cmd: ARRAY 256 OF CHAR;
BEGIN
Dialog.MapString("#Fig:Linepoint.Prop", cmd); Dialog.Call(cmd, "", res)
END Action;
PROCEDURE (p: LinePoint) PollProp* (OUT prop: Properties.Property);
VAR pprop: LinePointProportionProp;
BEGIN
GetProportionProp(p, pprop); prop := pprop
END PollProp;
PROCEDURE (p: LinePoint) SetProp* (prop: Properties.Property);
VAR old: LinePointProportionProp;
BEGIN
WHILE (prop # NIL) & ~(prop IS LinePointProportionProp) DO
prop := prop.next
END;
IF prop # NIL THEN
GetProportionProp(p, old);
SetProportionProp(p, old, prop(LinePointProportionProp))
END
END SetProp;
PROCEDURE (p: LinePoint) CopyFrom- (source: Stores.Store);
BEGIN
WITH source: LinePoint DO p.fixed := source.fixed; p.proportion := source.proportion END
END CopyFrom;
PROCEDURE (p: LinePoint) Externalize- (VAR wr: Stores.Writer);
BEGIN
wr.WriteVersion(currentVersion);
wr.WriteBool(p.fixed); wr.WriteReal(p.proportion)
END Externalize;
PROCEDURE (p: LinePoint) Internalize- (VAR rd: Stores.Reader);
VAR version: INTEGER;
BEGIN
rd.ReadVersion(minVersion, maxVersion, version);
IF ~rd.cancelled THEN
rd.ReadBool(p.fixed); rd.ReadReal(p.proportion)
END
END Internalize;
PROCEDURE (p: LinePoint) Calculate* (VAR x, y: INTEGER);
BEGIN
Adjust(p.Anchors(), p.fixed, p.proportion, x, y)
END Calculate;
PROCEDURE NewLinePoint* (fixed: BOOLEAN; proportion: REAL): LinePoint;
VAR p: LinePoint;
BEGIN
NEW(p); p.fixed := fixed; p.proportion := proportion; RETURN p
END NewLinePoint;
PROCEDURE InsertLinePoint*;
VAR v: FigViews.View; m: FigModels.Model; p: FigModels.PointList; pnt: LinePoint;
BEGIN
v := FigViews.Focus();
IF v # NIL THEN
m := v.ThisModel();
IF v.NofSelectedObjects(FigViews.points) > 1 THEN
v.PopPoints(2, p); pnt := NewLinePoint(FALSE, 0.5);
m.InsertObject(pnt, p, FigModels.undefined, FigModels.undefined);
v.SelectObject(pnt)
END
END
END InsertLinePoint;
PROCEDURE InsertLinePointMiddle*;
VAR v: FigViews.View; m: FigModels.Model; p: FigModels.PointList; pnt: LinePoint;
BEGIN
v := FigViews.Focus();
IF v # NIL THEN
m := v.ThisModel();
IF v.NofSelectedObjects(FigViews.points) > 1 THEN
v.PopPoints(2, p); pnt := NewLinePoint(TRUE, 0.5);
m.InsertObject(pnt, p, FigModels.undefined, FigModels.undefined);
v.SelectObject(pnt)
END
END
END InsertLinePointMiddle;
PROCEDURE InsertLinePointCont*;
VAR v: FigViews.View; m: FigModels.Model; p: FigModels.PointList; pnt: LinePoint;
BEGIN
v := FigViews.Focus();
IF v # NIL THEN
m := v.ThisModel();
IF v.NofSelectedObjects(FigViews.points) > 1 THEN
v.PopPoints(2, p); pnt := NewLinePoint(TRUE, 2);
m.InsertObject(pnt, p, FigModels.undefined, FigModels.undefined);
v.SelectObject(pnt)
END
END
END InsertLinePointCont;
(* LinePoint Dialog *)
PROCEDURE InitLinePointDialog*;
VAR p: Properties.Property;
BEGIN
Properties.CollectProp(p);
WHILE (p # NIL) & ~(p IS LinePointProportionProp) DO p := p.next END;
IF p # NIL THEN
WITH p: LinePointProportionProp DO
IF fixed IN p.valid THEN dlg.fixed := p.fixed ELSE dlg.fixed := FALSE END;
IF proportion IN p.valid THEN
dlg.percent := SHORT(ENTIER(p.proportion * 100 + 0.5))
ELSE dlg.percent := 0
END
END
ELSE dlg.fixed := FALSE; dlg.percent := 0
END;
Dialog.Update(dlg)
END InitLinePointDialog;
PROCEDURE SetLinePoint*;
VAR p: LinePointProportionProp;
BEGIN
NEW(p); p.known := {fixed, proportion}; p.valid := p.known;
p.fixed := dlg.fixed; p.proportion := dlg.percent / 100;
Properties.EmitProp(NIL, p)
END SetLinePoint;
(* CirclePoint *)
PROCEDURE (p: CirclePoint) Externalize- (VAR wr: Stores.Writer);
BEGIN
wr.WriteVersion(currentVersion)
END Externalize;
PROCEDURE (p: CirclePoint) Internalize- (VAR rd: Stores.Reader);
VAR version: INTEGER;
theta: REAL;
BEGIN
rd.ReadVersion(minVersion, maxVersion, version);
IF ~rd.cancelled THEN
IF version = 0 THEN rd.ReadReal(theta) ELSE END
END
END Internalize;
PROCEDURE (p: CirclePoint) Calculate* (VAR x, y: INTEGER);
VAR radius, length, length2, theta: REAL;
x0, y0, x1, y1: INTEGER;
BEGIN
x0 := p.Anchors().Next().This().X(); y0 := p.Anchors().Next().This().Y();
x1 := p.Anchors().This().X(); y1 := p.Anchors().This().Y();
radius := Math.Sqrt(Math.IntPower(x0 - x1, 2) + Math.IntPower(y0 - y1, 2));
IF (x = FigModels.undefined) & (y = FigModels.undefined) THEN
theta := 0.0;
x := SHORT(ENTIER(x0 + radius * Math.Cos(theta)));
y := SHORT(ENTIER(y0 - radius * Math.Sin(theta)))
ELSE
length := Math.Sqrt(Math.IntPower(x0 - x, 2) + Math.IntPower(y0 - y, 2));
length2 := Math.Sqrt(Math.IntPower(x0 - x, 2) + Math.IntPower(y0 - y0, 2));
IF length # 0 THEN theta := Math.ArcCos(length2 / length) ELSE theta := 0.0 END;
IF (x >= x0) & (y >= y0) THEN
x := SHORT(ENTIER(x0 + radius * Math.Cos(theta)));
y := SHORT(ENTIER(y0 + radius * Math.Sin(theta)))
ELSIF (x < x0) & (y < y0) THEN
x := SHORT(ENTIER(x0 - radius * Math.Cos(theta)));
y := SHORT(ENTIER(y0 - radius * Math.Sin(theta)))
ELSIF (x < x0) & (y >= y0) THEN
x := SHORT(ENTIER(x0 - radius * Math.Cos(theta)));
y := SHORT(ENTIER(y0 + radius * Math.Sin(theta)))
ELSE
x := SHORT(ENTIER(x0 + radius * Math.Cos(theta)));
y := SHORT(ENTIER(y0 - radius * Math.Sin(theta)))
END
END
END Calculate;
PROCEDURE NewCirclePoint* (): CirclePoint;
VAR p: CirclePoint;
BEGIN
NEW(p); RETURN p
END NewCirclePoint;
PROCEDURE InsertCirclePoint*;
VAR v: FigViews.View; m: FigModels.Model; p: FigModels.PointList; pnt: CirclePoint;
BEGIN
v := FigViews.Focus();
IF v # NIL THEN
m := v.ThisModel();
IF v.NofSelectedObjects(FigViews.points) > 1 THEN
v.PopPoints(2, p); pnt := NewCirclePoint();
m.InsertObject(pnt, p, FigModels.undefined, FigModels.undefined);
v.SelectObject(pnt)
END
END
END InsertCirclePoint;
(* CenterPoint *)
PROCEDURE (p: CenterPoint) Externalize- (VAR wr: Stores.Writer);
BEGIN
wr.WriteVersion(currentVersion)
END Externalize;
PROCEDURE (p: CenterPoint) Internalize- (VAR rd: Stores.Reader);
VAR version: INTEGER;
BEGIN
rd.ReadVersion(minVersion, maxVersion, version)
END Internalize;
PROCEDURE (p: CenterPoint) Calculate* (VAR x, y: INTEGER);
VAR x0, y0: REAL; n: INTEGER; q: FigModels.PointList; pnt: FigModels.Point;
BEGIN
q := p.Anchors(); x0 := 0; y0 := 0; n := 0;
WHILE q # NIL DO pnt := q.This(); x0 := x0 + pnt.X(); y0 := y0 + pnt.Y(); INC(n); q := q.Next() END;
x := SHORT(ENTIER(x0 / n + 0.5)); y := SHORT(ENTIER(y0 / n + 0.5))
END Calculate;
PROCEDURE (pnt: CenterPoint) PollProp* (OUT p: Properties.Property);
VAR prop: FigModels.StdProp;
BEGIN
NEW(prop);
prop.known := {FigModels.expandable, FigModels.cyclic,
FigModels.minAnchors, FigModels.maxAnchors};
prop.valid := prop.known;
prop.expandable := TRUE; prop.cyclic := TRUE;
prop.minAnchors := 2; prop.maxAnchors := FigModels.undefined;
p := prop
END PollProp;
PROCEDURE NewCenterPoint* (): CenterPoint;
VAR p: CenterPoint;
BEGIN
NEW(p); RETURN p
END NewCenterPoint;
PROCEDURE InsertCenterPoint*;
VAR n: INTEGER;
v: FigViews.View; m: FigModels.Model; p: FigModels.PointList; pnt: CenterPoint;
BEGIN
v := FigViews.Focus();
IF v # NIL THEN
m := v.ThisModel(); n := v.NofSelectedObjects(FigViews.points);
IF n > 1 THEN
v.PopPoints(n, p); pnt := NewCenterPoint();
m.InsertObject(pnt, p, FigModels.undefined, FigModels.undefined);
v.SelectObject(pnt)
END
END
END InsertCenterPoint;
(* CornerPoint *)
PROCEDURE (p: CornerPoint) CopyFrom- (source: Stores.Store);
BEGIN
WITH source: CornerPoint DO
p.xi := source.xi; p.yi := source.yi
END
END CopyFrom;
PROCEDURE (p: CornerPoint) Externalize- (VAR wr: Stores.Writer);
BEGIN
wr.WriteVersion(currentVersion);
wr.WriteInt(p.xi); wr.WriteInt(p.yi)
END Externalize;
PROCEDURE (p: CornerPoint) Internalize- (VAR rd: Stores.Reader);
VAR version: INTEGER;
BEGIN
rd.ReadVersion(minVersion, maxVersion, version);
IF ~rd.cancelled THEN
rd.ReadInt(p.xi); rd.ReadInt(p.yi)
END
END Internalize;
PROCEDURE (p: CornerPoint) Calculate* (VAR x, y: INTEGER);
VAR d1, d2: REAL; anc: ARRAY 2 OF FigModels.Point;
BEGIN
anc[0] := p.Anchors().This(); anc[1] := p.Anchors().Next().This();
d1 := Math.IntPower(anc[0].X() - x, 2) + Math.IntPower(anc[1].Y() - y, 2);
d2 := Math.IntPower(anc[1].X() - x, 2) + Math.IntPower(anc[0].Y() - y, 2);
IF d1 < d2 THEN p.xi := 0; p.yi := 1 ELSIF d1 > d2 THEN p.xi := 1; p.yi := 0 END;
x := anc[p.xi].X(); y := anc[p.yi].Y()
END Calculate;
PROCEDURE NewCornerPoint* (): CornerPoint;
VAR p: CornerPoint;
BEGIN
NEW(p); p.xi := 0; p.yi := 1; RETURN p
END NewCornerPoint;
PROCEDURE InsertCornerPoint*;
VAR v: FigViews.View; m: FigModels.Model; p: FigModels.PointList; pnt: CornerPoint;
BEGIN
v := FigViews.Focus();
IF v # NIL THEN
m := v.ThisModel();
IF v.NofSelectedObjects(FigViews.points) > 1 THEN
v.PopPoints(2, p); pnt := NewCornerPoint();
m.InsertObject(pnt, p, FigModels.undefined, FigModels.undefined);
v.SelectObject(pnt)
END
END
END InsertCornerPoint;
(* ParallelPoint *)
PROCEDURE (p: ParallelPoint) Externalize- (VAR wr: Stores.Writer);
BEGIN
wr.WriteVersion(currentVersion)
END Externalize;
PROCEDURE (p: ParallelPoint) Internalize- (VAR rd: Stores.Reader);
VAR version: INTEGER;
BEGIN
rd.ReadVersion(minVersion, maxVersion, version);
IF ~rd.cancelled THEN END
END Internalize;
PROCEDURE (p: ParallelPoint) Calculate* (VAR x, y: INTEGER);
BEGIN
x := p.Anchors().Next().Next().This().X() - p.Anchors().Next().This().X() + p.Anchors().This().X();
y := p.Anchors().Next().Next().This().Y() - p.Anchors().Next().This().Y() + p.Anchors().This().Y();
END Calculate;
PROCEDURE NewParallelPoint* (): ParallelPoint;
VAR p: ParallelPoint;
BEGIN
NEW(p); RETURN p
END NewParallelPoint;
PROCEDURE InsertParallelPoint*;
VAR v: FigViews.View; m: FigModels.Model; p: FigModels.PointList; pnt: ParallelPoint;
BEGIN
v := FigViews.Focus();
IF v # NIL THEN
m := v.ThisModel();
IF v.NofSelectedObjects(FigViews.points) > 2 THEN
v.PopPoints(3, p); pnt := NewParallelPoint();
m.InsertObject(pnt, p, FigModels.undefined, FigModels.undefined);
v.SelectObject(pnt)
END
END
END InsertParallelPoint;
(* RectanglePoint *)
PROCEDURE (p: RectanglePoint) Externalize- (VAR wr: Stores.Writer);
BEGIN
wr.WriteVersion(currentVersion)
END Externalize;
PROCEDURE (p: RectanglePoint) Internalize- (VAR rd: Stores.Reader);
VAR version: INTEGER;
BEGIN
rd.ReadVersion(minVersion, maxVersion, version);
IF ~rd.cancelled THEN END
END Internalize;
PROCEDURE (p: RectanglePoint) Calculate* (VAR x, y: INTEGER);
VAR p1, p2: FigModels.Point; l, t, r, b, d: INTEGER;
BEGIN
p1 := p.Anchors().This(); p2 := p.Anchors().Next().This();
l := MIN(p1.X(), p2.X()); r := MAX(p1.X(), p2.X()); t := MIN(p1.Y(), p2.Y()); b := MAX(p1.Y(), p2.Y());
IF x = FigModels.undefined THEN x := (l + r) DIV 2 END;
IF y = FigModels.undefined THEN y := (t + b) DIV 2 END;
x := MAX(l, MIN(r, x)); y := MAX(t, MIN(b, y));
d := MIN(MIN(x - l, r - x), MIN(y - t, b - y));
IF d # 0 THEN
IF d = x - l THEN x := l ELSIF d = r - x THEN x := r ELSIF d = y - t THEN y := t ELSE y := b END
END
END Calculate;
PROCEDURE NewRectanglePoint* (): RectanglePoint;
VAR p: RectanglePoint;
BEGIN
NEW(p); RETURN p
END NewRectanglePoint;
PROCEDURE InsertRectanglePoint*;
VAR v: FigViews.View; m: FigModels.Model; p: FigModels.PointList; pnt: RectanglePoint;
BEGIN
v := FigViews.Focus();
IF v # NIL THEN
m := v.ThisModel();
IF v.NofSelectedObjects(FigViews.points) > 1 THEN
v.PopPoints(2, p); pnt := NewRectanglePoint();
m.InsertObject(pnt, p, FigModels.undefined, FigModels.undefined);
v.SelectObject(pnt)
END
END
END InsertRectanglePoint;
(* ProjectionPoint *)
PROCEDURE (p: ProjectionPoint) Externalize- (VAR wr: Stores.Writer);
BEGIN
wr.WriteVersion(currentVersion)
END Externalize;
PROCEDURE (p: ProjectionPoint) Internalize- (VAR rd: Stores.Reader);
VAR version: INTEGER;
BEGIN
rd.ReadVersion(minVersion, maxVersion, version);
IF ~rd.cancelled THEN END
END Internalize;
PROCEDURE (p: ProjectionPoint) Calculate* (VAR x, y: INTEGER);
VAR x0, y0, x1, y1, x2, y2, f, l: REAL; q: FigModels.PointList; a: FigModels.Point;
BEGIN
q := p.Anchors(); a := q.This(); x0 := a.X(); y0 := a.Y(); (* point *)
q := q.Next(); a := q.This(); x1 := a.X(); y1 := a.Y(); (* projection line *)
q := q.Next(); a := q.This(); x2 := a.X(); y2 := a.Y(); (* projection line *)
l := ((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
IF l # 0 THEN f := ((x1 - x2) * (x0 - x2) + (y1 - y2) * (y0 - y2)) / l ELSE f := 0 END;
x := SHORT(ENTIER(x2 + (x1 - x2) * f)); y := SHORT(ENTIER(y2 + (y1 - y2) * f))
END Calculate;
PROCEDURE NewProjectionPoint* (): ProjectionPoint;
VAR p: ProjectionPoint;
BEGIN
NEW(p); RETURN p
END NewProjectionPoint;
PROCEDURE InsertProjectionPoint*;
VAR v: FigViews.View; m: FigModels.Model; p: FigModels.PointList; pnt: ProjectionPoint;
BEGIN
v := FigViews.Focus();
IF v # NIL THEN
m := v.ThisModel();
IF v.NofSelectedObjects(FigViews.points) > 2 THEN
v.PopPoints(3, p); pnt := NewProjectionPoint();
m.InsertObject(pnt, p, FigModels.undefined, FigModels.undefined);
v.SelectObject(pnt)
END
END
END InsertProjectionPoint;
END FigPoints.
| Fig/Mod/Points.odc |
MODULE FigViews;
IMPORT Stores, Ports, Math, Views, Controllers, Properties, Models,
FigModels;
CONST
initialGrid* = 3 * Ports.mm; initialGridDrawingFactor* = 3; pntSize = 4 * Ports.point;
windowsAltKey = 28; macCommandKey = 27;
rightDeleteKey = 07X; leftDeleteKey = 08X;
arrowLeft = 1CX; arrowRight = 1DX; arrowUp = 1EX; arrowDown = 1FX; tab = 9X;
minVersion = 3; maxVersion = 3; currentVersion = 3;
points* = 1; figures* = 2; both* = 3;
TYPE
ObjectList = POINTER TO RECORD
this: FigModels.Object;
next: ObjectList
END;
View* = POINTER TO ABSTRACT RECORD (Views.View) END;
Directory* = POINTER TO ABSTRACT RECORD END;
StdView = POINTER TO RECORD (View)
m: FigModels.Model;
selectedObjects: ObjectList;
nofSelectedPoints: INTEGER;
nofSelectedFigures: INTEGER;
showPoints: BOOLEAN;
showGrid: BOOLEAN;
grid: INTEGER;
gridDrawingFactor: INTEGER;
gridOn: BOOLEAN
END;
StdDirectory = POINTER TO RECORD (Directory) END;
VAR
dir-, stdDir-: Directory;
(* Misc. *)
PROCEDURE AlienDependencies (pnt: FigModels.Point): BOOLEAN;
VAR points: FigModels.PointList;
BEGIN
IF ~(pnt IS FigModels.AlienPoint) THEN
points := pnt.DependingPoints();
WHILE (points # NIL) & ~(points.This() IS FigModels.AlienPoint) & ~AlienDependencies(points.This()) DO
points := points.Next()
END;
RETURN points # NIL
ELSE RETURN FALSE
END
END AlienDependencies;
PROCEDURE Focus* (): View;
VAR v: Views.View;
BEGIN
v := Controllers.FocusView();
IF (v # NIL) & (v IS View) THEN RETURN v(View) ELSE RETURN NIL END
END Focus;
(* View *)
PROCEDURE (v: View) RoundToGrid* (VAR x, y: INTEGER), NEW, ABSTRACT;
PROCEDURE (v: View) SetGrid* (grid, gridDrawingFactor: INTEGER), NEW, ABSTRACT;
PROCEDURE (v: View) GetGrid* (OUT grid, gridDrawingFactor: INTEGER), NEW, ABSTRACT;
PROCEDURE (v: View) GridOn* (): BOOLEAN, NEW, ABSTRACT;
PROCEDURE (v: View) ShowingGrid* (): BOOLEAN, NEW, ABSTRACT;
PROCEDURE (v: View) ShowingPoints* (): BOOLEAN, NEW, ABSTRACT;
PROCEDURE (v: View) ToggleGrid*, NEW, ABSTRACT;
PROCEDURE (v: View) TogglePointhiding*, NEW, ABSTRACT;
PROCEDURE (v: View) ToggleGridhiding*, NEW, ABSTRACT;
PROCEDURE (v: View) SelectObject* (o: FigModels.Object), NEW, ABSTRACT;
PROCEDURE (v: View) DeselectObject* (o: FigModels.Object), NEW, ABSTRACT;
PROCEDURE (v: View) SelectAll*, NEW, ABSTRACT;
PROCEDURE (v: View) DeselectAll*, NEW, ABSTRACT;
PROCEDURE (v: View) NofSelectedObjects* (type: INTEGER): INTEGER, NEW, ABSTRACT;
PROCEDURE (v: View) LatestSelectedObject* (type: INTEGER): FigModels.Object, NEW, ABSTRACT;
PROCEDURE (v: View) GetSelections* (n, type: INTEGER; OUT sel: ARRAY OF FigModels.Object),
NEW, ABSTRACT;
PROCEDURE (v: View) IsSelected* (o: FigModels.Object): BOOLEAN, NEW, ABSTRACT;
PROCEDURE (v: View) PopPoints* (n: INTEGER; OUT plist: FigModels.PointList), NEW, ABSTRACT;
PROCEDURE (v: View) PopFigures* (n: INTEGER; OUT flist: FigModels.FigureList), NEW, ABSTRACT;
PROCEDURE (v: View) SelectedPoints* (): FigModels.PointList, NEW, ABSTRACT;
PROCEDURE (v: View) SelectedFigures* (): FigModels.FigureList, NEW, ABSTRACT;
PROCEDURE (v: View) SelectPoints* (plist: FigModels.PointList), NEW, ABSTRACT;
PROCEDURE (v: View) SelectFigures* (flist: FigModels.FigureList), NEW, ABSTRACT;
PROCEDURE (v: View) ThisModel* (): FigModels.Model, EXTENSIBLE;
BEGIN
RETURN NIL
END ThisModel;
(* Directory *)
PROCEDURE (d: Directory) New* (m: FigModels.Model): View, NEW, ABSTRACT;
(* StdView *)
PROCEDURE (v: StdView) SelectObject (o: FigModels.Object);
VAR olist: ObjectList;
BEGIN
ASSERT(o # NIL, 20);
IF o IS FigModels.Point THEN ASSERT(o(FigModels.Point).Model() = v.ThisModel(), 21)
ELSIF o IS FigModels.Figure THEN ASSERT(o(FigModels.Figure).Model() = v.ThisModel(), 22)
END;
NEW(olist); olist.this := o; olist.next := v.selectedObjects; v.selectedObjects := olist;
IF o IS FigModels.Point THEN INC(v.nofSelectedPoints)
ELSIF o IS FigModels.Figure THEN INC(v.nofSelectedFigures)
END;
Views.Update(v, Views.keepFrames)
END SelectObject;
PROCEDURE (v: StdView) DeselectObject (o: FigModels.Object);
VAR tmp, prev: ObjectList;
BEGIN
ASSERT(o # NIL, 20);
IF o IS FigModels.Point THEN ASSERT(o(FigModels.Point).Model() = v.ThisModel(), 21)
ELSIF o IS FigModels.Figure THEN ASSERT(o(FigModels.Figure).Model() = v.ThisModel(), 22)
END;
tmp := v.selectedObjects; prev := NIL;
WHILE (tmp # NIL) & (tmp.this # o) DO prev := tmp; tmp := tmp.next END;
IF tmp # NIL THEN
IF prev = NIL THEN v.selectedObjects := tmp.next
ELSE prev.next := tmp.next
END;
IF o IS FigModels.Point THEN DEC(v.nofSelectedPoints)
ELSIF o IS FigModels.Figure THEN DEC(v.nofSelectedFigures)
END
END;
Views.Update(v, Views.keepFrames)
END DeselectObject;
PROCEDURE (v: StdView) SelectAll;
VAR plist: FigModels.PointList;
p: FigModels.Point;
flist: FigModels.FigureList;
f: FigModels.Figure;
BEGIN
v.selectedObjects := NIL; v.nofSelectedPoints := 0; v.nofSelectedFigures := 0;
plist := v.m.Points(); WHILE plist # NIL DO p := plist.This(); v.SelectObject(p); plist := plist.Next() END;
flist := v.m.Figures(); WHILE flist # NIL DO f := flist.This(); v.SelectObject(f); flist := flist.Next() END
END SelectAll;
PROCEDURE GetBoundingBox (obj: ObjectList; OUT l, t, r, b: INTEGER);
VAR fl, ft, fr, fb, x, y: INTEGER; p: FigModels.Point;
BEGIN
ASSERT(obj # NIL, 20);
IF obj.this IS FigModels.Point THEN
p := obj.this(FigModels.Point); x := p.X(); y := p.Y();
l := x - pntSize; r := x + pntSize;
t :=y - pntSize; b := y + pntSize
ELSE
obj.this(FigModels.Figure).GetBoundingBox(fl, ft, fr, fb);
l := MIN(l, fl); r := MAX(r, fr); t := MIN(t, ft); b := MAX(b, fb)
END;
obj := obj.next;
WHILE obj # NIL DO
IF obj.this IS FigModels.Point THEN
p := obj.this(FigModels.Point); x := p.X(); y := p.Y();
l := MIN(l, x - pntSize); r := MAX(r, x + pntSize);
t := MIN(t, y - pntSize); b := MAX(b, y + pntSize)
ELSE
obj.this(FigModels.Figure).GetBoundingBox(fl, ft, fr, fb);
l := MIN(l, fl); r := MAX(r, fr); t := MIN(t, ft); b := MAX(b, fb)
END;
obj := obj.next
END
END GetBoundingBox;
PROCEDURE (v: StdView) DeselectAll;
VAR l, t, r, b: INTEGER;
BEGIN
IF v.selectedObjects # NIL THEN
GetBoundingBox(v.selectedObjects, l, t, r, b);
v.selectedObjects := NIL; v.nofSelectedPoints := 0; v.nofSelectedFigures := 0;
Views.UpdateIn(v, l - Ports.mm, t - Ports.mm, r + Ports.mm, b + Ports.mm, Views.keepFrames)
END
END DeselectAll;
PROCEDURE (v: StdView) NofSelectedObjects (type: INTEGER): INTEGER;
BEGIN
IF type = points THEN RETURN v.nofSelectedPoints
ELSIF type = figures THEN RETURN v.nofSelectedFigures
ELSIF type = both THEN RETURN v.nofSelectedPoints + v.nofSelectedFigures
ELSE RETURN 0
END
END NofSelectedObjects;
PROCEDURE (v: StdView) LatestSelectedObject (type: INTEGER): FigModels.Object;
VAR tmplist: ObjectList;
BEGIN
tmplist := v.selectedObjects;
IF (type = points) & (tmplist # NIL) THEN
WHILE (tmplist # NIL) & ~(tmplist.this IS FigModels.Point) DO tmplist := tmplist.next END;
IF tmplist = NIL THEN RETURN NIL
ELSE RETURN tmplist.this
END
ELSIF (type = figures) & (tmplist # NIL) THEN
WHILE (tmplist # NIL) & ~(tmplist.this IS FigModels.Figure) DO tmplist := tmplist.next END;
IF tmplist = NIL THEN RETURN NIL
ELSE RETURN tmplist.this
END
ELSIF (type = both) & (tmplist # NIL) THEN RETURN v.selectedObjects.this
ELSE RETURN NIL
END
END LatestSelectedObject;
PROCEDURE (v: StdView) GetSelections (n, type: INTEGER; OUT sel: ARRAY OF FigModels.Object);
VAR tmp: ObjectList;
index: INTEGER;
BEGIN
ASSERT(n > 0, 20); ASSERT(LEN(sel) >= n, 21);
tmp := v.selectedObjects; index := 0;
IF type = points THEN
WHILE (tmp # NIL) & (n > 0) DO
IF tmp.this IS FigModels.Point THEN
sel[index] := tmp.this(FigModels.Point); INC(index); DEC(n)
END;
tmp := tmp.next
END
ELSIF type = figures THEN
WHILE (tmp # NIL) & (n > 0) DO
IF tmp.this IS FigModels.Point THEN
sel[index] := tmp.this(FigModels.Point); INC(index); DEC(n)
END;
tmp := tmp.next
END
ELSIF type = both THEN
WHILE (tmp # NIL) & (n > 0) DO sel[index] := tmp.this; INC(index); DEC(n); tmp := tmp.next END
ELSE
END
END GetSelections;
PROCEDURE (v: StdView) IsSelected (o: FigModels.Object): BOOLEAN;
VAR tmplist: ObjectList;
BEGIN
ASSERT(o # NIL, 20);
IF o IS FigModels.Point THEN ASSERT(o(FigModels.Point).Model() = v.ThisModel(), 21)
ELSIF o IS FigModels.Figure THEN ASSERT(o(FigModels.Figure).Model() = v.ThisModel(), 22)
END;
tmplist := v.selectedObjects; WHILE (tmplist # NIL) & (tmplist.this # o) DO tmplist := tmplist.next END;
RETURN tmplist # NIL
END IsSelected;
PROCEDURE (v: StdView) PopPoints (n: INTEGER; OUT plist: FigModels.PointList);
VAR a: POINTER TO ARRAY OF FigModels.Point;
tmp: ObjectList;
index: INTEGER;
BEGIN
ASSERT(n > 0, 20);
ASSERT(n <= v.NofSelectedObjects(points), 21);
NEW(a, n); tmp := v.selectedObjects; index := 0;
WHILE (tmp # NIL) & (n > 0) DO
IF tmp.this IS FigModels.Point THEN
a[index] := tmp.this(FigModels.Point);
v.DeselectObject(tmp.this); INC(index); DEC(n)
END;
tmp := tmp.next
END;
plist := v.m.ThisPointList(a);
Views.Update(v, Views.keepFrames)
END PopPoints;
PROCEDURE (v: StdView) PopFigures (n: INTEGER; OUT flist: FigModels.FigureList);
VAR a: POINTER TO ARRAY OF FigModels.Figure;
tmp: ObjectList;
index: INTEGER;
BEGIN
ASSERT(n > 0, 20);
ASSERT(n <= v.NofSelectedObjects(figures), 21);
NEW(a, n); tmp := v.selectedObjects; index := 0;
WHILE (tmp # NIL) & (n > 0) DO
IF tmp.this IS FigModels.Figure THEN
a[index] := tmp.this(FigModels.Figure);
v.DeselectObject(tmp.this); INC(index); DEC(n)
END;
tmp := tmp.next
END;
flist := v.m.ThisFigureList(a);
Views.Update(v, Views.keepFrames)
END PopFigures;
PROCEDURE (v: StdView) SelectedPoints (): FigModels.PointList;
VAR a: POINTER TO ARRAY OF FigModels.Point;
tmp: ObjectList;
index, n: INTEGER;
BEGIN
n := v.nofSelectedPoints; tmp := v.selectedObjects; index := 0;
IF n > 0 THEN NEW(a, n) END;
WHILE (tmp # NIL) & (n > 0) DO
IF tmp.this IS FigModels.Point THEN
a[index] := tmp.this(FigModels.Point); INC(index); DEC(n)
END;
tmp := tmp.next
END;
IF v.nofSelectedPoints > 0 THEN
RETURN v.m.ThisPointList(a)
ELSE
RETURN NIL
END
END SelectedPoints;
PROCEDURE (v: StdView) SelectedFigures (): FigModels.FigureList;
VAR a: POINTER TO ARRAY OF FigModels.Figure;
tmp: ObjectList;
index, n: INTEGER;
BEGIN
n := v.nofSelectedFigures; tmp := v.selectedObjects; index := 0;
IF n > 0 THEN NEW(a, n) END;
WHILE (tmp # NIL) & (n > 0) DO
IF tmp.this IS FigModels.Figure THEN a[index] := tmp.this(FigModels.Figure); INC(index); DEC(n) END;
tmp := tmp.next
END;
IF v.nofSelectedFigures > 0 THEN RETURN v.m.ThisFigureList(a) ELSE RETURN NIL END
END SelectedFigures;
PROCEDURE (v: StdView) SelectPoints (plist: FigModels.PointList);
BEGIN
WHILE plist # NIL DO v.SelectObject(plist.This()); plist := plist.Next() END
END SelectPoints;
PROCEDURE (v: StdView) SelectFigures (flist: FigModels.FigureList);
BEGIN
WHILE flist # NIL DO v.SelectObject(flist.This()); flist := flist.Next() END
END SelectFigures;
PROCEDURE (v: StdView) RoundToGrid (VAR x, y: INTEGER);
BEGIN
x := x + v.grid DIV 2; y := y + v.grid DIV 2; x := x - x MOD v.grid; y := y - y MOD v.grid
END RoundToGrid;
PROCEDURE (v: StdView) SetGrid (grid: INTEGER; gridDrawingFactor: INTEGER);
BEGIN
ASSERT(grid > 0, 20);
ASSERT(gridDrawingFactor > 0, 21);
v.grid := grid; v.gridDrawingFactor := gridDrawingFactor;
Views.Update(v, Views.keepFrames)
END SetGrid;
PROCEDURE (v: StdView) GetGrid (OUT grid, gridDrawingFactor: INTEGER);
BEGIN
grid := v.grid; gridDrawingFactor := v.gridDrawingFactor
END GetGrid;
PROCEDURE (v: StdView) GridOn (): BOOLEAN;
BEGIN
RETURN v.gridOn
END GridOn;
PROCEDURE (v: StdView) ShowingGrid (): BOOLEAN;
BEGIN
RETURN v.showGrid
END ShowingGrid;
PROCEDURE (v: StdView) ShowingPoints (): BOOLEAN;
BEGIN
RETURN v.showPoints
END ShowingPoints;
PROCEDURE (v: StdView) InitModel (m: Models.Model), NEW;
BEGIN
WITH m: FigModels.Model DO
v.m := m; Stores.Join(v, m);
v.selectedObjects := NIL; v.nofSelectedPoints := 0; v.nofSelectedFigures := 0;
v.showPoints := TRUE; v.showGrid := TRUE;
v.grid := initialGrid; v.gridDrawingFactor := initialGridDrawingFactor; v.gridOn := TRUE
END
END InitModel;
PROCEDURE (v: StdView) ThisModel (): FigModels.Model;
BEGIN
RETURN v.m
END ThisModel;
PROCEDURE (v: StdView) CopyFromModelView (source: Views.View; model: Models.Model);
BEGIN
WITH source: StdView DO
v.m := model(FigModels.Model);
v.showPoints := source.showPoints; v.showGrid := source.showGrid;
v.grid := source.grid; v.gridDrawingFactor := source.gridDrawingFactor; v.gridOn := source.gridOn
END
END CopyFromModelView;
PROCEDURE (v: StdView) Internalize (VAR rd: Stores.Reader);
VAR version: INTEGER;
s: Stores.Store;
BEGIN
rd.ReadVersion(minVersion, maxVersion, version);
IF ~rd.cancelled THEN
rd.ReadStore(s);
IF s IS FigModels.Model THEN
v.InitModel(s(FigModels.Model));
rd.ReadBool(v.showPoints); rd.ReadBool(v.showGrid);
rd.ReadInt(v.grid); rd.ReadInt(v.gridDrawingFactor); rd.ReadBool(v.gridOn)
ELSE rd.TurnIntoAlien(Stores.alienComponent)
END
END
END Internalize;
PROCEDURE (v: StdView) Externalize (VAR wr: Stores.Writer);
BEGIN
wr.WriteVersion(currentVersion);
wr.WriteStore(v.m);
wr.WriteBool(v.showPoints); wr.WriteBool(v.showGrid);
wr.WriteInt(v.grid); wr.WriteInt(v.gridDrawingFactor); wr.WriteBool(v.gridOn)
END Externalize;
PROCEDURE DrawPoint (f: Ports.Frame; p: FigModels.Point; x, y, s, color: INTEGER);
VAR bsize, csize, b: INTEGER; alienColor: Ports.Color;
BEGIN
bsize := (pntSize DIV f.unit) * f.unit; csize := (pntSize DIV f.unit) * f.unit; b := f.dot;
IF Ports.background # Ports.grey50 THEN
alienColor := Ports.grey50 ELSE alienColor := Ports.grey25
END;
IF p IS FigModels.AlienPoint THEN
f.DrawRect(x - (csize + b), y - (csize + b), x + (csize + b), y + (csize + b), Ports.fill, alienColor);
f.DrawRect(x - csize, y - csize, x + csize, y + csize, s, Ports.black);
f.DrawLine(x - f.dot, y - f.dot, x + f.dot, y + f.dot, 0, color)
ELSIF p IS FigModels.ConstrainedPoint THEN
f.DrawRect(x - (csize + b), y - (csize + b), x + (csize + b), y + (csize + b), Ports.fill, Ports.background);
f.DrawRect(x - csize, y - csize, x + csize, y + csize, s, color);
f.DrawRect(x - f.dot, y - f.dot, x + f.dot, y + f.dot, 0, color)
ELSE
f.DrawLine(x - bsize, y - bsize, x + bsize, y + bsize, s + f.dot * 2, Ports.background);
f.DrawLine(x - bsize, y + bsize, x + bsize, y - bsize, s + f.dot * 2, Ports.background);
f.DrawLine(x - bsize, y - bsize, x + bsize, y + bsize, s, color);
f.DrawLine(x - bsize, y + bsize, x + bsize, y - bsize, s, color)
END
END DrawPoint;
PROCEDURE Draw (v: StdView; f: Ports.Frame; l, t, r, b: INTEGER; showPoints: BOOLEAN);
VAR m: FigModels.Model; plist: FigModels.PointList; p: FigModels.Point; bl, bt, br, bb: INTEGER;
figs: FigModels.FigureList;
BEGIN
m := v.ThisModel();
figs := m.Figures();
WHILE figs # NIL DO figs.This().Draw(f, l, t, r, b); figs := figs.Next() END;
figs := v.SelectedFigures();
WHILE figs # NIL DO
figs.This().GetBoundingBox(bl, bt, br, bb);
f.MarkRect(bl - 2 * f.dot, bt - 2 * f.dot, br + 2 * f.dot, bb + 2 * f.dot, 2 * f.unit, Ports.hilite, Ports.show);
figs := figs.Next()
END;
IF showPoints THEN
plist := m.Points();
WHILE plist # NIL DO
p := plist.This(); DrawPoint(f, p, p.X(), p.Y(), 0, Ports.black); plist := plist.Next()
END
END;
plist := v.SelectedPoints();
WHILE plist # NIL DO
p := plist.This(); DrawPoint(f, p, p.X(), p.Y(), f.dot * 2, Ports.black); plist := plist.Next()
END
END Draw;
PROCEDURE (v: StdView) Restore (f: Views.Frame; l, t, r, b: INTEGER);
VAR k, x, y, w, h: INTEGER;
BEGIN
IF ~Views.IsPrinterFrame(f) THEN
IF v.showGrid THEN
k := v.grid * v.gridDrawingFactor; v.context.GetSize(w, h);
x := l - (l MOD k);
WHILE x <= w DO f.MarkRect(x, 0, x + f.unit, h, 0, Ports.dim50, Ports.show); INC(x, k) END;
y := t - (t MOD k);
WHILE y <= h DO f.MarkRect(0, y, w, y + f.unit, 0, Ports.dim50, Ports.show); INC(y, k) END
END;
Draw(v, f, l, t, r, b, v.showPoints)
ELSE Draw(v, f, l, t, r, b, FALSE)
END
END Restore;
PROCEDURE (v: StdView) ToggleGrid;
BEGIN
v.gridOn := ~v.gridOn;
Views.Update(v, Views.keepFrames)
END ToggleGrid;
PROCEDURE (v: StdView) TogglePointhiding;
BEGIN
v.showPoints := ~v.showPoints;
Views.Update(v, Views.keepFrames)
END TogglePointhiding;
PROCEDURE (v: StdView) ToggleGridhiding;
BEGIN
v.showGrid := ~v.showGrid;
Views.Update(v, Views.keepFrames)
END ToggleGridhiding;
(* Model Messages *)
PROCEDURE (v: StdView) HandleModelMsg (VAR msg: Models.Message);
BEGIN
WITH msg: FigModels.InsertMsg DO
IF ~msg.insert & (msg.figure = NIL) THEN v.DeselectObject(msg.point)
ELSIF ~msg.insert & (msg.point = NIL) THEN v.DeselectObject(msg.figure)
END;
Views.Update(v, Views.keepFrames)
| msg: FigModels.AnchorMsg DO Views.Update(v, Views.keepFrames)
| msg: FigModels.ChangeAnchorMsg DO Views.Update(v, Views.keepFrames)
| msg: FigModels.UpdateMsg DO Views.Update(v, Views.keepFrames)
| msg: Models.UpdateMsg DO Views.Update(v, Views.keepFrames)
ELSE
END
END HandleModelMsg;
(* Control Messages *)
(* SelectMessage Handling *)
(* EditMessage Handling *)
PROCEDURE DeleteSelection (v: StdView);
VAR m: FigModels.Model;
flist: FigModels.FigureList;
plist: FigModels.PointList;
s: Stores.Operation;
PROCEDURE DeletePoint (p: FigModels.Point);
VAR plist: FigModels.PointList;
BEGIN
plist := p.DependingPoints(); WHILE plist # NIL DO DeletePoint(plist.This()); plist := plist.Next() END;
IF (p.DependingPoints() = NIL) & (p.DependingFigures() = NIL) & v.IsSelected(p) THEN
m.RemoveObject(p)
END
END DeletePoint;
BEGIN
m := v.m;
Models.BeginScript(m, "Delete", s);
flist := v.SelectedFigures(); WHILE flist # NIL DO m.RemoveObject(flist.This()); flist := flist.Next() END;
plist := v.SelectedPoints(); WHILE plist # NIL DO DeletePoint(plist.This()); plist := plist.Next() END;
Models.EndScript(m, s)
END DeleteSelection;
PROCEDURE CopyToNewView (v: StdView; OUT w, h: INTEGER; OUT new: Views.View);
VAR l, t, r, b: INTEGER;
copy: FigModels.Model;
flist: FigModels.FigureList;
plist: FigModels.PointList;
BEGIN
copy := FigModels.CloneOf(v.m)(FigModels.Model);
copy.InsertCopy(v.m, v.SelectedPoints(), v.SelectedFigures(), plist, flist);
IF (copy.Points() # NIL) OR (copy.Figures() # NIL) THEN
copy.GetBoundingBox(copy.Points(), copy.Figures(), l, t, r, b);
copy.MovePoints(copy.Points(), -l, -t);
w := r - l; h := b - t; new := Views.CopyWithNewModel(v, copy)
END
END CopyToNewView;
PROCEDURE Paste (into: StdView; insert: View);
VAR m0, m: FigModels.Model;
p: FigModels.Point;
flist: FigModels.FigureList;
plist: FigModels.PointList;
s: Stores.Operation;
BEGIN
m0 := into.m; m := insert.ThisModel(); p := into.SelectedPoints().This();
Models.BeginScript(m0, "Paste", s);
m0.InsertCopy(m, m.Points(), m.Figures(), plist, flist); m0.MovePoints(plist, p.X(), p.Y());
Models.EndScript(m0, s);
into.DeselectAll;
into.SelectPoints(plist); into.SelectFigures(flist)
END Paste;
PROCEDURE MoveByKey (v: StdView; key: CHAR; dist: INTEGER);
VAR m: FigModels.Model;
BEGIN
m := v.m;
CASE key OF
arrowLeft: m.MovePoints(v.SelectedPoints(), -dist, 0)
| arrowRight: m.MovePoints(v.SelectedPoints(), dist, 0)
| arrowUp: m.MovePoints(v.SelectedPoints(), 0, -dist)
| arrowDown: m.MovePoints(v.SelectedPoints(), 0, dist)
END
END MoveByKey;
PROCEDURE Edit (v: StdView; f: Views.Frame; VAR msg: Controllers.EditMsg);
VAR plist: FigModels.PointList;
BEGIN
IF msg.op = Controllers.pasteChar THEN
IF (msg.char = rightDeleteKey) OR (msg.char = leftDeleteKey) THEN DeleteSelection(v)
ELSIF (msg.char >= arrowLeft) & (msg.char <= arrowDown) THEN
IF Controllers.modify IN msg.modifiers THEN MoveByKey(v, msg.char, v.grid)
ELSE MoveByKey(v, msg.char, f.dot)
END
ELSIF (msg.char = tab) & (v.NofSelectedObjects(points) # 0) THEN v.PopPoints(1, plist)
END
ELSIF (msg.op = Controllers.paste) & (msg.view IS View) THEN Paste(v , msg.view(View))
ELSIF msg.op = Controllers.copy THEN CopyToNewView (v, msg.w, msg.h, msg.view)
ELSIF msg.op = Controllers.cut THEN CopyToNewView (v, msg.w, msg.h, msg.view); DeleteSelection(v)
END
END Edit;
(* TrackMessage & PollCursorMessage Handling *)
PROCEDURE CheckHits (v: StdView; x, y: INTEGER; OUT p: FigModels.Point; OUT f: FigModels.Figure);
VAR d, dist: REAL;
pnt, min: FigModels.Point;
plist: FigModels.PointList;
flist, q: FigModels.FigureList;
BEGIN
plist := v.m.Points(); min := NIL; dist := 2 * Math.IntPower(MAX(INTEGER), 2);
WHILE plist # NIL DO
pnt := plist.This(); d := Math.IntPower(pnt.X() - x, 2) + Math.IntPower(pnt.Y() - y, 2);
IF d <= dist THEN min := pnt; dist := d END;
plist := plist.Next()
END;
IF (min # NIL) &
((v.gridOn & (2 * ABS(min.X() - x) <= v.grid) & (2 * ABS(min.Y() - y) <= v.grid))
OR (dist <= Math.IntPower(pntSize, 2)))
THEN p := min
ELSE p := NIL
END;
flist := v.m.TheseFigures(v.m.Figures(), x, y);
IF flist # NIL THEN
q := flist.Next(); WHILE q # NIL DO flist := q; q := flist.Next() END;
f := flist.This()
ELSE f := NIL
END
END CheckHits;
PROCEDURE ThisCursor (v: StdView; x, y: INTEGER; frame: Views.Frame): INTEGER;
VAR modifiers: SET;
isDown: BOOLEAN;
p: FigModels.Point;
f: FigModels.Figure;
BEGIN
CheckHits(v, x, y, p, f); frame.Input(x, y, modifiers, isDown);
IF (p # NIL) OR ((f # NIL) & ~(Controllers.modify IN modifiers)) THEN RETURN Ports.arrowCursor
ELSE RETURN Ports.graphicsCursor
END
END ThisCursor;
PROCEDURE InvertRect (f: Views.Frame; x0, y0, x1, y1: INTEGER);
VAR l, t, r, b: INTEGER;
BEGIN
IF x0 <= x1 THEN l := x0; r := x1 ELSE l := x1; r := x0 END;
IF y0 <= y1 THEN t := y0; b := y1 ELSE t := y1; b := y0 END;
f.MarkRect(l, t, r, b, 0, Ports.dim75, TRUE)
END InvertRect;
PROCEDURE TrackOnBackground (v: StdView; f: Views.Frame; x0, y0: INTEGER; modifiers: SET);
VAR x, y, x1, y1: INTEGER;
mod: SET;
isDown: BOOLEAN;
BEGIN
f.SetCursor(Ports.graphicsCursor);
x1 := x0; y1 := y0; InvertRect(f, x0, y0, x1, y1);
REPEAT
f.Input(x, y, mod, isDown); modifiers := modifiers + mod;
IF (x # x1) OR (y # y1) THEN
InvertRect(f, x0, y0, x1, y1); x1 := x; y1 := y; InvertRect(f, x0, y0, x1, y1)
END
UNTIL ~isDown OR ({Controllers.modify, Controllers.doubleClick} * modifiers # {});
InvertRect(f, x0, y0, x1, y1);
IF isDown THEN
REPEAT f.Input(x, y, mod, isDown); modifiers := modifiers + mod UNTIL ~isDown;
IF ~(Controllers.extend IN modifiers) THEN v.DeselectAll END;
IF {Controllers.modify, Controllers.doubleClick} * modifiers # {} THEN
IF v.gridOn THEN v.RoundToGrid(x, y) END;
IF (x >= f.l) & (x <= f.r) & (y >= f.t) & (y <= f.b) THEN v.SelectObject(v.m.NewFreePoint(x, y)) END
END
ELSE
IF ~(Controllers.extend IN modifiers) THEN v.DeselectAll END;
IF x0 > x THEN x := x0; x0 := x1 END;
IF y0 > y THEN y := y0; y0 := y1 END;
v.SelectPoints(v.m.ThesePoints(v.m.Points(), x0, y0, x, y));
v.SelectFigures(v.m.IncludedFigures(v.m.Figures(), x0, y0, x, y))
END
END TrackOnBackground;
PROCEDURE TrackMove (v: StdView; f: Views.Frame; x0, y0: INTEGER; modifiers: SET);
VAR x, y, dx, dy, l, t, r, b, res, col: INTEGER;
mod: SET;
isDown: BOOLEAN;
m: FigModels.Model;
plist: FigModels.PointList;
p: FigModels.Point;
flist: FigModels.FigureList;
BEGIN
f.SetCursor(Ports.graphicsCursor);
f.SaveRect(f.l, f.t, f.r, f.b, res);
v.m.GetBoundingBox(v.SelectedPoints(), NIL, l, t, r, b);
IF Ports.background # Ports.grey25 THEN col := Ports.grey25 ELSE col := Ports.grey50 END;
IF v.gridOn THEN v.RoundToGrid(x0, y0) END;
dx := 0; dy := 0;
REPEAT
f.Input(x, y, mod, isDown); modifiers := modifiers + mod;
IF v.gridOn THEN v.RoundToGrid(x, y) END;
IF (dx # MAX(-l, x - x0)) OR (dy # MAX(-t, y - y0)) THEN
dx := MAX(-l, x - x0); dy := MAX(-t, y - y0);
f.RestoreRect(f.l, f.t, f.r, f.b, Ports.keepBuffer);
plist := v.SelectedPoints();
WHILE plist # NIL DO
p := plist.This();
IF ~(p IS FigModels.ConstrainedPoint) THEN
DrawPoint(f, p, p.X() + dx, p.Y() + dy, f.dot * 2, col)
END;
plist := plist.Next()
END
END
UNTIL ~isDown;
f.RestoreRect(f.l, f.t, f.r, f.b, Ports.disposeBuffer);
IF (dx # 0) OR (dy # 0) THEN
IF Controllers.modify IN modifiers THEN
m := FigModels.CloneOf(v.m)(FigModels.Model);
m.InsertCopy(v.m, v.SelectedPoints(), v.SelectedFigures(), plist, flist);
m.MovePoints(m.Points(), dx, dy);
v.m.InsertCopy(m, m.Points(), m.Figures(), plist, flist);
v.DeselectAll(); v.SelectPoints(plist); v.SelectFigures(flist)
ELSE v.m.MovePoints(v.SelectedPoints(), dx, dy)
END
END
END TrackMove;
PROCEDURE TrackOnPoint (v: StdView; f: Views.Frame; x0, y0: INTEGER; modifiers: SET; p: FigModels.Point);
VAR x, y: INTEGER;
mod: SET;
isDown, isSelected: BOOLEAN;
BEGIN
f.SetCursor(Ports.arrowCursor);
isSelected := v.IsSelected(p);
REPEAT f.Input(x, y, mod, isDown); modifiers := modifiers + mod
UNTIL ~isDown OR ((x # x0) OR (y # y0)) & isSelected;
IF isDown THEN TrackMove(v, f, x0, y0, modifiers)
ELSIF (p IS FigModels.ConstrainedPoint)
& ({macCommandKey, windowsAltKey, Controllers.doubleClick} * modifiers # {})
THEN p(FigModels.ConstrainedPoint).Action
ELSIF Controllers.extend IN modifiers THEN
IF v.IsSelected(p) THEN v.DeselectObject(p) ELSE v.SelectObject(p) END
ELSE v.DeselectAll; v.SelectObject(p)
END
END TrackOnPoint;
PROCEDURE TrackOnFigure (v: StdView; f: Views.Frame; x0, y0: INTEGER; modifiers: SET;
fig: FigModels.Figure);
VAR x, y: INTEGER;
mod: SET;
isDown: BOOLEAN;
BEGIN
f.SetCursor(Ports.arrowCursor);
REPEAT f.Input(x, y, mod, isDown); modifiers := modifiers + mod
UNTIL ~isDown OR (Controllers.modify IN modifiers)
OR (Math.IntPower(x - x0, 2) + Math.IntPower(y - y0, 2) > Math.IntPower(pntSize, 2));
IF isDown THEN TrackOnBackground (v, f, x0, y0, modifiers)
ELSIF {macCommandKey, windowsAltKey, Controllers.doubleClick} * modifiers # {} THEN fig.Action
ELSIF Controllers.extend IN modifiers THEN
IF v.IsSelected(fig) THEN v.DeselectObject(fig) ELSE v.SelectObject(fig) END
ELSE v.DeselectAll; v.SelectObject(fig)
END
END TrackOnFigure;
PROCEDURE Track (v: StdView; f: Views.Frame; VAR msg: Controllers.TrackMsg);
VAR pnt: FigModels.Point;
fig: FigModels.Figure;
BEGIN
CheckHits(v, msg.x, msg.y, pnt, fig);
IF pnt # NIL THEN TrackOnPoint(v, f, msg.x, msg.y, msg.modifiers, pnt)
ELSIF fig # NIL THEN TrackOnFigure(v, f, msg.x, msg.y, msg.modifiers, fig)
ELSE TrackOnBackground(v, f, msg.x, msg.y, msg.modifiers)
END
END Track;
(* ControllersMessage Handling *)
PROCEDURE (v: StdView) HandleCtrlMsg (f: Views.Frame; VAR msg: Controllers.Message;
VAR focus: Views.View);
BEGIN
WITH msg: Controllers.PollOpsMsg DO
msg.type := "FigViews.View"; msg.selectable := TRUE;
IF (v.SelectedPoints() = NIL) & (v.SelectedFigures() = NIL) THEN msg.valid :={}
ELSIF v.NofSelectedObjects(points) = 1 THEN
msg.valid := {Controllers.paste, Controllers.copy, Controllers.cut}
ELSE msg.valid := {Controllers.copy, Controllers.cut}
END
| msg: Properties.CollectMsg DO Views.HandlePropMsg(v, msg.poll)
| msg: Properties.EmitMsg DO Views.HandlePropMsg(v, msg.set)
| msg: Controllers.SelectMsg DO IF msg.set THEN v.SelectAll ELSE v.DeselectAll END
| msg: Controllers.EditMsg DO Edit(v, f, msg)
| msg: Controllers.TrackMsg DO Track(v, f, msg)
| msg: Controllers.PollCursorMsg DO msg.cursor := ThisCursor(v, msg.x, msg.y, f)
ELSE (* unknown message type, ignore *)
END
END HandleCtrlMsg;
(* Property Messages *)
PROCEDURE SetBoundsPref (v: StdView; VAR msg: Properties.BoundsPref);
VAR l, t: INTEGER;
BEGIN
IF (v.m.Points() # NIL) OR (v.m.Figures() # NIL) THEN
v.m.GetBoundingBox(v.m.Points(), v.m.Figures(), l, t, msg.h, msg.w)
ELSE msg.w := 0; msg.h := 0
END
END SetBoundsPref;
PROCEDURE (v: StdView) HandlePropMsg (VAR msg: Properties.Message);
BEGIN
WITH msg: Properties.FocusPref DO msg.setFocus := TRUE
| msg: Properties.SizePref DO
IF (msg.w = Views.undefined) OR (msg.h = Views.undefined) THEN
msg.w := 60 * Ports.mm; msg.h := 40 * Ports.mm
END
| msg: Properties.BoundsPref DO SetBoundsPref(v, msg)
| msg: Properties.ResizePref DO msg.horFitToWin := TRUE; msg.verFitToWin := TRUE
| msg: Properties.PollMsg DO v.m.CollectProperties(v.SelectedFigures(), v.SelectedPoints(), msg.prop)
| msg: Properties.SetMsg DO v.m.EmitProperties(v.SelectedFigures(), v.SelectedPoints(), msg.prop)
ELSE
END
END HandlePropMsg;
(* StdDirectory *)
PROCEDURE (d: StdDirectory) New (m: FigModels.Model): View;
VAR v: StdView;
BEGIN
ASSERT(m # NIL, 20);
NEW(v); v.InitModel(m); RETURN v
END New;
PROCEDURE SetDir*(d: Directory);
BEGIN
ASSERT (d # NIL, 20);
dir := d
END SetDir;
PROCEDURE Init;
VAR d: StdDirectory;
BEGIN
NEW(d); stdDir := d; dir := d
END Init;
BEGIN
Init
END FigViews.
| Fig/Mod/Views.odc |
Fig/Rsrc/Captions.odc |
|
Fig/Rsrc/Grid.odc |
|
Fig/Rsrc/Linepoint.odc |
|
Fig/Rsrc/Lines.odc |
|
MENU "#Fig:Figures" ("FigViews.View")
"#Fig:Line" "" "FigBasic.InsertLine" "FigCmds.SelectionGuard(2)"
"#Fig:Rectangle" "" "FigBasic.InsertRectangle" "FigCmds.SelectionGuard(2)"
"#Fig:Circle" "" "FigBasic.InsertCircle" "FigCmds.SelectionGuard(2)"
"#Fig:Oval" "" "FigBasic.InsertOval" "FigCmds.SelectionGuard(2)"
"#Fig:Polygon" "" "FigBasic.InsertPolygon" "FigCmds.SelectionGuard(3)"
"#Fig:Open Bezier" "" "FigBasic.InsertOpenBezier" "FigBasic.InsertOpenBezierGuard"
"#Fig:Closed Bezier" "" "FigBasic.InsertClosedBezier" "FigBasic.InsertClosedBezierGuard"
"#Fig:Caption" "" "FigBasic.InsertCaption" "FigCmds.SelectionGuard(1)"
SEPARATOR
"#Fig:Point on Line" "" "FigPoints.InsertLinePoint" "FigCmds.SelectionGuard(2)"
"#Fig:Continuation" "" "FigPoints.InsertLinePointCont" "FigCmds.SelectionGuard(2)"
"#Fig:Point on Rectangle" "" "FigPoints.InsertRectanglePoint" "FigCmds.SelectionGuard(2)"
"#Fig:Point in Corner" "" "FigPoints.InsertCornerPoint" "FigCmds.SelectionGuard(2)"
"#Fig:Point on Circle" "" "FigPoints.InsertCirclePoint" "FigCmds.SelectionGuard(2)"
"#Fig:Projection" "" "FigPoints.InsertProjectionPoint" "FigCmds.SelectionGuard(3)"
"#Fig:Parallel" "" "FigPoints.InsertParallelPoint" "FigCmds.SelectionGuard(3)"
"#Fig:Center Point" "" "FigPoints.InsertCenterPoint" "FigCmds.SelectionGuard(2)"
SEPARATOR
"#Fig:Split Points" "" "FigCmds.SplitPoints" "FigCmds.SplitPointsGuard"
"#Fig:Join Points" "" "FigCmds.JoinPoints" "FigCmds.JoinPointsGuard"
"#Fig:Send To Back" "" "FigCmds.SendToBack" "FigCmds.SendToBackGuard"
"#Fig:Bring To Front" "" "FigCmds.BringToFront" "FigCmds.BringToFrontGuard"
"#Fig:Add Anchor" "" "FigCmds.AddAnchor" "FigCmds.AddAnchorGuard"
"#Fig:Remove Anchor" "" "FigCmds.RemoveAnchor" "FigCmds.RemoveAnchorGuard"
"#Fig:Select All Anchors" "" "FigCmds.SelectAnchors" "FigCmds.SelectAnchorsGuard"
SEPARATOR
"#Fig:Hide Points" "" "FigCmds.TogglePointhiding" "FigCmds.TogglePointhidingGuard"
"#Fig:Hide Grid" "" "FigCmds.ToggleGridhiding" "FigCmds.ToggleGridhidingGuard"
"#Fig:Grid On" "" "FigCmds.ToggleGrid" "FigCmds.ToggleGridGuard"
"#Fig:Force To Grid" "" "FigCmds.ForceToGrid" "FigCmds.ForceToGridGuard"
"#Fig:Set Grid Size..." "" "FigCmds.InitGridDialog; StdCmds.OpenToolDialog('Fig/Rsrc/Grid', 'Grid Size')" "FigCmds.SetGridGuard"
END
| Fig/Rsrc/Menus.odc |
STRINGS
Captions.Prop FigBasic.InitCaptionDialog; StdCmds.OpenToolDialog('Fig/Rsrc/Captions', 'Captions')
Line.Prop FigCmds.InitArrowPropDialog; FigCmds.InitTPropDialog; StdCmds.OpenToolDialog('Fig/Rsrc/Lines', 'Lines')
Thickness.Prop FigCmds.InitTPropDialog; StdCmds.OpenToolDialog('Fig/Rsrc/Thickns', 'Thickness')
Bezier.Prop FigCmds.InitArrowPropDialog; FigCmds.InitTPropDialog; StdCmds.OpenToolDialog('Fig/Rsrc/Lines', 'Bezier')
Linepoint.Prop FigPoints.InitLinePointDialog; StdCmds.OpenToolDialog('Fig/Rsrc/Linepoint', 'Linepoint')
| Fig/Rsrc/Strings.odc |
Fig/Rsrc/Thickns.odc |
|
FormCmds
DEFINITION FormCmds;
IMPORT Dialog;
VAR
grid: RECORD
resolution: INTEGER;
metricSystem: BOOLEAN
END;
PROCEDURE AlignLeft;
PROCEDURE AlignRight;
PROCEDURE AlignTop;
PROCEDURE AlignBottom;
PROCEDURE AlignToRow;
PROCEDURE AlignToColumn;
PROCEDURE InitGridDialog;
PROCEDURE SetGrid;
PROCEDURE SelectOffGridViews;
PROCEDURE ForceToGrid;
PROCEDURE SetAsFirst;
PROCEDURE SetAsLast;
PROCEDURE SortViews;
PROCEDURE InsertAround;
PROCEDURE FocusGuard (VAR par: Dialog.Par);
PROCEDURE SelectionGuard (VAR par: Dialog.Par);
PROCEDURE SingletonGuard (VAR par: Dialog.Par);
END FormCmds.
Command package for form views. Its main purpose is to support layout editing, through various alignment and grid control commands.
A possible menu using the above commands:
MENU "Layout" ("FormViews.View")
"Align &Left" "" "FormCmds.AlignLeft" "FormCmds.SelectionGuard"
"Align &Right" "" "FormCmds.AlignRight" "FormCmds.SelectionGuard"
"Align &Top" "" "FormCmds.AlignTop" "FormCmds.SelectionGuard"
"Align &Bottom" "" "FormCmds.AlignBottom" "FormCmds.SelectionGuard"
"Align To Ro&w" "" "FormCmds.AlignToRow" "FormCmds.SelectionGuard"
"Align To &Column" "" "FormCmds.AlignToColumn" "FormCmds.SelectionGuard"
SEPARATOR
"Set &Grid..." "" "FormCmds.InitGridDialog;
StdCmds.OpenToolDialog('Form/Rsrc/Cmds', 'Set Grid')"
"FormCmds.FocusGuard"
"&Select Off-Grid Views" "" "FormCmds.SelectOffGridViews" ""
"&Force To Grid" "" "FormCmds.ForceToGrid" "FormCmds.SelectionGuard"
SEPARATOR
"Set F&irst/Back" "" "FormCmds.SetAsFirst" "FormCmds.SingletonGuard"
"Set L&ast/Front" "" "FormCmds.SetAsLast" "FormCmds.SingletonGuard"
"Sort &Views" "" "FormCmds.SortViews" "FormCmds.FocusGuard"
SEPARATOR
"Insert Group Box" "" "FormCmds.InsertAround" "FormCmds.FocusGuard"
END
VAR grid: RECORD
Interactor for the grid dialog box (Form/Rsrc/Cmds).
resolution: INTEGER resolution > 0
If metricSystem, then resolution specifies how many grid positions exist for one millimeter.
If ~metricSystem, then resolution specifies how many grid positions exist for 1/16 inch.
A higher value means that higher precision is possible.
metricSystem: BOOLEAN
Determines whether the metric system (millimeters) is used or not (1/16 inches).
PROCEDURE AlignLeft
Guard: FormCmds.SelectionGuard
Move all selected views such that their left sides are aligned to the leftmost view in the selection.
PROCEDURE AlignRight
Guard: FormCmds.SelectionGuard
Move all selected views such that their right sides are aligned to the rightmost view in the selection.
PROCEDURE AlignTop
Guard: FormCmds.SelectionGuard
Move all selected views such that their top sides are aligned to the topmost view in the selection.
PROCEDURE AlignBottom
Guard: FormCmds.SelectionGuard
Move all selected views such that their bottom sides are aligned to the bottommost view in the selection.
PROCEDURE AlignToRow
Guard: FormCmds.SelectionGuard
Move all selected views such that their vertical centers become aligned horizontally.
PROCEDURE AlignToColumn
Guard: FormCmds.SelectionGuard
Move all selected views such that their horizontal centers become aligned vertically.
PROCEDURE InitGridDialog
Guard: FormCmds.FocusGuard
Sets up grid.resolution and grid.metricSystem according to the values of the focus controller.
PROCEDURE SetGrid
Guard: FormCmds.FocusGuard
Sets the focus view's grid and gridFactor to the values determined by grid.resolution and grid.metricSystem.
PROCEDURE SelectOffGridViews
Guard: FormCmds.FocusGuard
Selects all views in the focus form whose top-left corners don't lie on the grid.
PROCEDURE ForceToGrid
Guard: FormCmds.FocusGuard
Moves all views in the focus form such that their top-left corners come to lie on the grid.
PROCEDURE SetAsFirst
Guard: FormCmds.SingletonGuard
Sets the selected view to the first position ("bottom").
PROCEDURE SetAsLast
Guard: FormCmds.SingletonGuard
Sets the selected view to the last position ("top").
PROCEDURE SortViews
Guard: FormCmds.FocusGuard
Sorts the back-to-front order of all views in a form such that they are geometrically sorted, i.e., a view whose upper edge is further up, or at the same hight but further to the left, is considered to come before ("lower") than the other one.
PROCEDURE InsertAround
Guard: FormCmds.SelectionGuard
Inserts a group box around the currently selected views.
PROCEDURE FocusGuard (VAR par: Dialog.Par)
This guard disables the current menu item if the current front focus isn't a form view.
PROCEDURE SelectionGuard (VAR par: Dialog.Par)
This guard disables the current menu item if the current front focus isn't a form view, or if it doesn't contain a selection.
PROCEDURE SingletonGuard (VAR par: Dialog.Par)
This guard disables the current menu item if the current front focus isn't a form view, or if it doesn't contain a singleton.
| Form/Docu/Cmds.odc |
FormControllers
DEFINITION FormControllers;
IMPORT Views, Controllers, Containers, FormModels, FormViews;
CONST noSelection = Containers.noSelection; noFocus = Containers.noFocus;
TYPE
Controller = POINTER TO ABSTRACT RECORD (Containers.Controller)
form-: FormModels.Model;
view-: FormViews.View;
(c: Controller) ThisView (): FormViews.View, EXTENSIBLE;
(c: Controller) Select (view: Views.View), NEW, ABSTRACT;
(c: Controller) Deselect (view: Views.View), NEW, ABSTRACT;
(c: Controller) IsSelected (view: Views.View): BOOLEAN, NEW, ABSTRACT;
(c: Controller) GetSelection (): List, NEW, ABSTRACT;
(c: Controller) SetSelection (l: List), NEW, ABSTRACT
END;
Directory = POINTER TO ABSTRACT RECORD (Controllers.Directory)
(d: Directory) New (): Controller, EXTENSIBLE;
(d: Directory) NewController (opts: SET): Controller, ABSTRACT
END;
List = POINTER TO RECORD
next: List;
view: Views.View
END;
VAR dir-, stdDir-: Directory;
PROCEDURE Focus (): Controller;
PROCEDURE Insert (c: Controller; view: Views.View; l, t, r, b: INTEGER);
PROCEDURE SetDir (d: Directory);
PROCEDURE Install;
END FormControllers.
FormControllers are standard controllers for FormViews. Note that forms can only be used in a non-modal way, i.e., a program doesn't wait until the user is finished with the form. In other words: the user is in control, not the computer.
TYPE Controller (Containers.Controller)
ABSTRACT
Standard controllers for form views.
form-: FormModels.Model form # NIL
The controller's model.
view-: FormViews.View view # NIL & view.ThisModel() = form
The controller's view.
PROCEDURE (c: Controller) ThisView (): FormViews.View
EXTENSIBLE
Covariant narrowing of function result.
PROCEDURE (c: Controller) Select (view: Views.View)
NEW, ABSTRACT
Adds a view to the current selection, if it isn't selected already.
Pre
view in c.form 20
~(noSel IN c.opts) 21
Post
c.IsSelected(view)
c.ThisFocus() = NIL
PROCEDURE (c: Controller) Deselect (view: Views.View)
NEW, ABSTRACT
Removes a view from the current selection, if it is selected.
Pre
view in c.form 20
Post
~c.IsSelected(view)
PROCEDURE (c: Controller) IsSelected (view: Views.View): BOOLEAN
NEW, ABSTRACT
Determines whether the given view is currently selected or not. NIL is not considered selected.
Pre
view = NIL OR view in c.form 20
PROCEDURE (c: Controller) GetSelection (): List
NEW, ABSTRACT
Returns the list of selected subviews.
Post
all views of the result list are in c.form
PROCEDURE (c: Controller) SetSelection (l: List)
NEW, ABSTRACT
Removes the existing selection, and selects the subviews of l.
Pre
all views of l are in c.form 20
TYPE Directory
ABSTRACT
Directory for form view controllers.
PROCEDURE (d: Directory) New (): Controller
EXTENSIBLE
Covariant extension of Controllers.Directory.New.
PROCEDURE (d: Directory) NewController (opts: SET): Controller
ABSTRACT
Covariant extension of Controllers.Directory.NewController.
VAR dir-, stdDir-: Directory dir # NIL & stdDir # NIL
Controller directories.
PROCEDURE Focus (): Controller
Returns the focus controller, if the focus currently is a form view, otherwise it returns NIL.
PROCEDURE Insert (c: Controller; view: Views.View; l, t, r, b: INTEGER)
Inserts view into c's view at the position (l, t, r, b). If necessary, the position is slightly corrected (rounded) such that view's top-left corner comes to lie on the grid. The size of view is not changed, however.
PROCEDURE SetDir (d: Directory)
Set directory d.
Pre
d # NIL 20
Post
dir = d
PROCEDURE Install
Used internally.
| Form/Docu/Controllers.odc |
Form Subsystem
Developer Manual
See TutorialFormSubsystem
| Form/Docu/Dev-Man.odc |
FormGen
DEFINITION FormGen;
IMPORT Dialog;
VAR
new: RECORD
link: Dialog.String
END;
PROCEDURE Create;
PROCEDURE Empty;
PROCEDURE CreateGuard (VAR par: Dialog.Par);
END FormGen.
FormGen is a generator for a form layout. It takes the name of an interactor variable (any exported record) as input and creates a default layout for the fields of the interactor. The following list describes the mapping from field types to controls.
BYTE, SHORTINT, INTEGER Field
SHORTREAL, REAL Field
ARRAY OF CHAR Field
BOOLEAN CheckBox
Dates.Date DateField
Dates.Time TimeField
Dialog.Color ColorField
Dialog.Currency Field
Dialog.List ListBox
Dialog.Selection SelectionBox
Dialog.Combo ComboBox
Alternatively, a dialog for all interactors of a module can be generated, by entering the module name into the dialog box field. In this case, a group box is generated for every exported record variable, and a command button for every exported parameterless procedure.
A possible menu using the above commands:
MENU "Form"
"&New Form..." "" "StdCmds.OpenAuxDialog('Form/Rsrc/Gen', 'New Form')" ""
END
VAR new
Interactor for the form generator dialog.
link: Dialog.String
The name of the interactor for which a default layout should be generated. The name must be an identifier qualified with the module name, e.g., "FormGen.new", or only a module name, e.g., "FormGen".
PROCEDURE Create
Guard: CreateGuard
Create a default layout for the interactor specified in link.
PROCEDURE Empty
Create an empty form layout.
PROCEDURE CreateGuard
Guard for Create.
| Form/Docu/Gen.odc |
FormModels
DEFINITION FormModels;
IMPORT Ports, Models, Views, Containers;
CONST minView Size = 4 * Ports.point; maxViewSize = 1000 * Ports.mm;
TYPE
Model = POINTER TO ABSTRACT RECORD (Containers.Model)
(m: Model) Insert (v: Views.View; l, t, r, b: INTEGER), NEW, ABSTRACT;
(m: Model) Delete (v: Views.View), NEW, ABSTRACT;
(m: Model) Resize (v: Views.View; l, t, r, b: INTEGER), NEW, ABSTRACT;
(m: Model) PutAbove (v, pos: Views.View), NEW, ABSTRACT;
(m: Model) Move (v: Views.View; dx, dy: INTEGER), NEW, ABSTRACT;
(m: Model) Copy (VAR v: Views.View; dx, dy: INTEGER), NEW, ABSTRACT;
(m: Model) NewReader (old: Reader): Reader, NEW, ABSTRACT;
(m: Model) NewWriter (old: Writer): Writer, NEW, ABSTRACT;
(m: Model) ViewAt (x, y: INTEGER): Views.View, NEW, ABSTRACT;
(m: Model) NofViews (): INTEGER, NEW, ABSTRACT
END;
Directory = POINTER TO ABSTRACT RECORD
(d: Directory) New (): Model, NEW, ABSTRACT
END;
Context = POINTER TO ABSTRACT RECORD (Models.Context)
(c: Context) ThisModel (): Model, ABSTRACT;
(c: Context) GetRect (OUT l, t, r, b: INTEGER), NEW, ABSTRACT
END;
Reader = POINTER TO ABSTRACT RECORD
view: Views.View;
l, t, r, b: INTEGER;
(r: Reader) Set (pos: Views.View), NEW, ABSTRACT;
(r: Reader) ReadView (OUT v: Views.View), NEW, ABSTRACT
END;
Writer = POINTER TO ABSTRACT RECORD
(w: Writer) Set (pos: Views.View), NEW, ABSTRACT;
(w: Writer) WriteView (v: Views.View; l, t, r, b: INTEGER), NEW, ABSTRACT
END;
UpdateMsg = RECORD (Models.UpdateMsg)
l, t, r, b: INTEGER
END;
VAR dir-, stdDir-: Directory;
PROCEDURE New (): Model;
PROCEDURE CloneOf (source: Model): Model;
PROCEDURE Copy (source: Model): Model;
PROCEDURE SetDir (d: Directory);
END FormModels.
FormModels are container models which contain views. They have no further intrinsic contents. Form models can be used to arrange rectangular views in arbitrary layouts. Their main use is as data entry forms and as dialog box layouts.
CONST minViewSize
This is the minimal width and height of a view which is embedded in a form model.
CONST maxViewSize
This is the maximal width and height of a view which is embedded in a form model.
TYPE Model (Containers.Model)
ABSTRACT
Form models are container models (-> Containers), which may contain rectangular views and nothing else.
PROCEDURE (m: Model) Insert (v: Views.View; l, t, r, b: INTEGER)
NEW, ABSTRACT, Operation
Insert view v with bounding box (l, t, r, b).
Pre
v # NIL 20
v.context = NIL 22
l <= r 23
t <= b 24
Post
v in m
v.context # NIL & v.context.ThisModel() = m
PROCEDURE (m: Model) Delete (v: Views.View)
NEW, ABSTRACT, Operation
Remove v from m.
Pre
v in m 20
Post
~(v in m)
PROCEDURE (m: Model) Resize (v: Views.View; l, t, r, b: INTEGER)
NEW, ABSTRACT, Operation
Redefine bounding box of v.
Pre
v in m 20
l <= r 21
t <= b 22
PROCEDURE (m: Model) PutAbove (v, pos: Views.View)
NEW, ABSTRACT, Operation
Change the vertical order of view v, such that it comes to lie directly above p if pos # NIL, otherwise it is put to the bottom of the view list.
Pre
v in m 20
pos = NIL OR pos in m 21
PROCEDURE (m: Model) Move (v: Views.View; dx, dy: INTEGER)
NEW, ABSTRACT, Operation
Move view v by (dx, dy), without changing its size.
Pre
v in m 20
PROCEDURE (m: Model) Copy (VAR v: Views.View; dx, dy: INTEGER)
NEW, ABSTRACT, Operation
Create a copy of v and put it at v's bounding box shifted by (dx, dy). Parameter v returns the copy.
Pre
v # NIL 20
v.context # NIL 21
v.context.ThisModel() = m 22
Post
v # NIL & v # v'
PROCEDURE (m: Model) NewReader (old: Reader): Reader
NEW, ABSTRACT
Returns a reader connected to m. An old reader may be passed as input parameter, if it isn't in use anymore.
Post
result # NIL
PROCEDURE (m: Model) NewWriter (old: Writer): Writer
NEW, ABSTRACT
Returns a writer connected to m. An old writer may be passed as input parameter, if it isn't in use anymore.
Post
result # NIL
PROCEDURE (m: Model) ViewAt (x, y: INTEGER): Views.View
NEW, ABSTRACT
Returns the topmost view in m which encloses position (x, y).
Post
result # NIL
where (l, t, r, b) is the bounding box of v: (l <= x <= r) & (t <= y <= b)
result = NIL
no view at (x, y)
PROCEDURE (m: Model) NofViews (): INTEGER
NEW, ABSTRACT
Returns the number of views currently in m.
Post
result >= 0
TYPE Directory
ABSTRACT
Directory for the allocation of concrete form models.
PROCEDURE (d: Directory) New (): Model
NEW, ABSTRACT
Create and return a new concrete form model.
Post
result # NIL
TYPE Context (Models.Context)
NEW, ABSTRACT
Context of a view in a form.
PROCEDURE (c: Context) ThisModel (): Model
ABSTRACT
Returns the form which contains the context. Covariant narrowing of result type.
PROCEDURE (c: Context) GetRect (OUT l, t, r, b: INTEGER)
NEW, ABSTRACT
Returns the bounding box of the context's view.
Post
l < r & t < b
TYPE Reader
ABSTRACT
Input rider on a form model.
view: Views.View
Most recently read view.
l, t, r, b: INTEGER view # NIL => l < r & t < b
Bounding box of most recently read view.
PROCEDURE (r: Reader) Set (pos: Views.View)
NEW, ABSTRACT
Set position of reader r to the view above pos (i.e., the next view to be read will be the one directly above pos) or to the bottom if pos = NIL.
Pre
pos in Base(r) OR pos = NIL 20
PROCEDURE (r: Reader) ReadView (OUT v: Views.View)
NEW, ABSTRACT
Reads the next view, in ascending order. If there is none, v is set to NIL. The reader's view and l, t, r, b fields will be set accordingly (l, t, r, b are undefined if view is NIL).
Post
v = r.view
TYPE Writer
ABSTRACT
Output rider on a form.
PROCEDURE (w: Writer) Set (pos: Views.View)
Interface
Set position of writer w to the view above pos (i.e., the next view to be written will be inserted directly above pos) or to the bottom if pos = NIL.
Pre
pos in Base(r) OR pos = NIL 20
PROCEDURE (w: Writer) WriteView (v: Views.View; l, t, r, b: INTEGER)
NEW, ABSTRACT
Insert view v at the current position in w's form.
Pre
v # NIL 20
v.context = NIL 22
l <= r 23
t <= b 24
Post
v.context # NIL
TYPE UpdateMsg
This message indicates that a rectangular part of a form needs to be updated on the screen.
The receiver must not switch on any marks as a reaction to having received this message.
UpdateMsgs are sent by concrete form model implementations after any view modifications.
UpdateMsgs are not extended.
VAR dir-, stdDir-: Directory; dir # NIL & stdDir # NIL
Form model directories.
PROCEDURE New (): Model
Returns a new model. Equivalent to dir.New().
Post
result # NIL
PROCEDURE CloneOf (source: Model): Model
Returns a new empty model of the same type as source.
Pre
source # NIL 20
Post
result # NIL
PROCEDURE Copy (source: Model): Model
Returns a new model of the same type as source, with a copy of the contents of source.
Pre
source # NIL 20
Post
result # NIL
PROCEDURE SetDir (d: Directory)
Assign directory.
Pre
d # NIL 20
Post
dir = d
| Form/Docu/Models.odc |
Map to the Form Subsystem
UserManual
FormCmds form command package
FormGen creation of default layout
FormControllers form controllers
FormViews form views
FormModels form models
| Form/Docu/Sys-Map.odc |
Form Subsystem
User Manual
Contents
1 CreatingandSavingForms
2 BasicEditing
3 NavigationKeys
4 Drag&Drop
5 Drag&Pick
6 LayoutandMaskModes
7 ControlsandInteractors
8 ControlProperties
The form subsystem implements a simple form editor, which can be used to create dialog boxes or data entry masks.
1 Creating and Saving Forms
The command Controls->NewForm... creates dialog boxes and other forms that match exported global variables. All such forms are nonmodal. Almost all dialog boxes in BlackBox are nonmodal, as long as the conventions for the underlying platform permit.
To get started, enter "TextCmds.find" into the Link field of the Controls->NewForm... dialog box. By clicking the default button, a dialog box is automatically created which has fields Find and Replace, and buttons like Find Next and Replace All. These fields and buttons directly match the record fields of variable find in module TextCmds. To verify this, select the string "TextCmds.find", and execute command Info->Interface. The browser will display the definition of the record type.
The size of a form view can be adjusted by selecting the whole document (Edit->SelectDocument) and then dragging the graphical handles.
The dialog box created by Controls->NewForm... exhibits a simple default arrangement of controls (e.g., buttons, edit fields), shown as an editable layout. The controls may be re-arranged, renamed, or otherwise modified using the menus Layout and Controls. The former menu appears automatically whenever a form becomes focused.
Instead of creating an initial layout out of an existing global variable, form creation may start with an empty form (click on the NewForm dialog box's Empty button), and then successively insert new controls via the Controls menu. Later, such controls may be linked to suitable global variables.
An edited dialog box can be saved by saving the window of the form layout. The BlackBox Component Framework saves dialog boxes in the standard document format. By convention, BlackBox forms are saved in the appropriate Rsrc directory (-> Subsystems and Global Modules). For example, the standard Text->Find&Replace dialog box is stored in Text/Rsrc/Find.
2 Basic Editing
A view can be inserted into a form layout by invoking one of the Insert Xyz commands of menu Controls, e.g., the command Controls->Insert Command Button. Arbitrary other views could also be inserted, or copied from the clipboard or via drag & drop.
Views in a form can be selected. If one single view is selected ( a "singleton"), it shows resize handles that can be manipulated to change the view's size. If several views are selected, they show a selection mark like singletons do, but no resize handles.
A view can be selected either by clicking in it, or by dragging over an area which intersects the view(s). If the shift key is pressed during selection, the newly touched view(s) are toggled, i.e., a selected view is deselected and vice versa. If the shift key is not pressed during selection, any existing selection is removed prior to creating the new selection. Consequently, a simple click outside of any view removes the existing selection and does not create a new one. Pressing esc achieves the same effect.
Some attributes of selected views can be modified using the Attributes menu. In this way, the typeface, style, and size of the labels of many controls can be changed.
The command Controls->Insert Group Box works like the other insert commands, with one exception: if there is a selection, the group box is placed and sized such that it forms a bounding box around the selected views.
A selection can be cut, copied, and pasted using the clipboard. It can be deleted with the backspace or delete keys.
Menu Layout contains a variety of commands which are useful for editing a form layout. The Align Left, Align Right, Align Top, and Align Bottom commands align the left, right, top, or bottom borders of all selected views. Alignment occurs to the view which lies furthest in the alignment direction. For example, Align Left finds the selected view whose left border lies furthest left, and then moves all other views (without resizing them) so that their left borders are aligned to the same x-coordinate.
Align To Row aligns all selected views in vertical direction, so that all their vertical centers come to lie on the same y-coordinate, which is the average of the old y-coordinates. Similarly, Align To Column aligns all selected view in the horizontal direction, so that they form a single column.
The dialog box Set Grid... allows to set the grid. Most commands which move or resize a view round the view's borders to this grid. The dialog box allows you to choose between a grid based on millimeters or on 1/16 inches. The grid resolution allows you to specify how many grid values exist for these units (for one millimeter, or for one sixteenth of an inch). A higher value means preciser placement is possible. Roughly every centimeter or half an inch, dotted lines are drawn on the grid, as visual aids for editing.
Select Off-Grid Views selects all views of which at least one of its four borders is not aligned to the form's grid. Force To Grid shifts and resizes them by a minimal distance so that they are aligned again.
Conceptually the views are arranged in z-order, i.e., each view is either "above" or "below" another view. Normally, views in a form should not overlap, and thus this z-ordering has no immediate effect. But the same ordering is used for moving the focus between controls, by using the tab key. The focus is moved from the bottom-most towards the top-most view when tabbing through a dialog box. The commands Set First/Back and Set Last/Front allow to change the z-order of a selected singleton. Sort Views sorts the z-orders of all views in a form such that a view further to the left and top is reached before another view (which is further "up" in the hierarchy). This command can be applied after a layout has been edited, to update the z-order to make it intuitive again.
Recalc Focus Size operates on a focused form layout view. It calculates the bounding box of the views which are contained in the form, offsets this bounding box by a small margin, and then sets the form view's width and height to this size. This is more convenient than using Edit->SelectDocument and then resizing the view manually.
The commands Set Default Button and Set Cancel Button make a selected button into a default or a cancel button. A default button reacts to the input of a return or enter key as if the mouse had been pressed inside; a cancel button reacts to the input of an esc key as if the mouse had been pressed inside.
Like other views that have separate models, a form view can be opened in several windows simultaneously.
3 Navigation Keys
Arrow keys can be used to move a selection to the left, right, upwards, or downwards by one point. If the ctrl key is pressed before the arrow key, the selection moves by a larger distance.
4 Drag & Drop
When clicking into a selection, and moving the cursor around, the selected views can be moved around accordingly. Moving occurs on a grid, the minimal distance is the same as when using the ctrl key together with an arrow key.
By holding down the ctrl key when the mouse button is released at the end of dragging, copies of the selected views are dropped, and become selected.
Drag & Drop also works across windows, and even between different containers. If a singleton is dragged & dropped into another kind of container (e.g., a text container), then a copy of this view is dropped. If a whole selection is dropped, the selected views are wrapped into a form view and this form view is dropped to the other container.
5 Drag & Pick
Drag & Pick is also supported in forms. In forms, another view's size can be picked up. This is very convenient for layout editing. For example, select several controls which have different sizes, hold down the alt key (or, alternatively, use the middle mouse button), and then drag to another view. When you release the mouse over this view, all selected views will be made the same size as this one.
6 Layout and Mask Modes
Forms can be used in two different modes. Normally, a form is used in layout mode, i.e. its layout can be freely edited. The views (typically controls) embedded in a form however, cannot be edited directly, because they can only be selected, but not focused. For layout editing, it would be very inconvenient if a click in one of the form's controls would focus it, instead of only selecting it. Forms are saved in layout mode, and opened in document windows.
For using a form as a dialog box or data entry mask, a form can be opened in mask mode instead, in an auxiliary window (data entry mask) or in a tool window (dialog box for the manipulation of a document beneath the dialog box). A form in mask mode cannot be modified. However, its embedded views may be focused, e.g. a text entry field may be focused, or a button may be clicked. In contrast to layout mode, embedded views cannot be selected, resized, or moved around.
In mask mode, no focus border is shown around the currently focused view. In layout mode, a grid is shown.
When a form in layout mode is focus, another window can be opened in mask mode, by using either Controls->Open As Tool Dialog or Controls->Open As Aux Dialog. In this way, a form can be tried out while it is still being edited. Layout changes in the layout mode form are immediately reflected in the other window, and input in the other window is immediately reflected in the layout.
Forms need not be saved in mask mode. They are saved in layout mode, and thus can be opened, edited, and saved again via the normal File menu commands. A data entry mask is opened via the StdCmds.OpenAuxDialog command; and a dialog box is opened via the StdCmds.OpenToolDialog command. These commands open a form document into an auxiliary/tool window and force it into mask mode. For example, the following commands show the difference between the two modes by opening the same (layout mode) form in the two possible ways:
"StdCmds.OpenAuxDialog('Form/Rsrc/Gen', 'New Form')"
"StdCmds.OpenToolDialog('Text/Rsrc/Cmds', 'Find & Replace')"
"StdCmds.OpenDoc('Form/Rsrc/Gen')"
"StdCmds.OpenDoc('Text/Rsrc/Cmds')"
The latter two commands correspond to the File->Open command and allow editing.
The difference between auxiliary and tool dialog boxes is that auxiliary dialog boxes are self-contained, e.g. dialog boxes to set up configuration parameters or data entry masks. Tool dialog boxes on the other hand operate on windows below them, e.g. the Find&Replace dialog box operates on the text beneath the dialog box.
These OpenAuxDialog/OpenToolDialog commands accept portable path names as input. A portable path name is a string which denotes a file in a machine-independent way. It uses the "/" character as separator, i.e. like in Unix or the World-Wide Web.
These commands are usually applied in menu items, for example the following command sequence:
"TextCmds.InitFindDialog; StdCmds.OpenToolDialog('Text/Rsrc/Find', 'Find & Replace')"
In this command sequence, the first command initializes the TextCmds.find interactor with the currently selected text stretch. The second command opens a dialog box with the Text/Rsrc/Find file's form, whose controls are linked to the interactor's fields upon opening of the dialog box.
See also modules FormGen, TextCmds, and StdCmds.
7 Controls and Interactors
Controls are specialized views. Like every view, any control can be inserted into any general container, be it a text, a spreadsheet, or whatever other container is available. However, most controls are put into forms.
Each control can be linked to a variable, more exactly to the field of a globally declared record variable, a so-called interactor. When the control is allocated (newly created or read from a document), BlackBox tries to link the control to its variable, using the advanced metaprogramming capabilities of the BlackBox Component Framework core. In this way, the link between control and variable can be built up automatically when a dialog box is created or loaded, and correct linking (which includes correct typing) can be guaranteed even after a dialog box layout had been edited. The separation of interactor from controls makes it possible to hide many user-interface details from a program, e.g. the layout of a dialog box or other "cosmetic" properties of controls.
The BlackBox Component Framework provides command buttons, check boxes, radio buttons, fields, captions, list boxes, selection boxes, combo boxes, date, time, color, up/down fields, and groups as standard controls.
8 Control Properties
Controls have various properties, e.g. the label displayed in a button, or the interactor field to which the control is linked. The inspector is a tool used to inspect and to modify the properties of standard controls. To open the inspector dialog box on a control, first select the control, and then execute Edit->ObjectProperties....
To learn more about the inspector, see the documentation for module DevInspector.
For more information on the Form subsystem's programming interface, consult the on-line documentation of the modules FormModels, FormViews, FormControllers, FormGen, FormCmds, and Controls. Note that most of these modules are distributed in source form also, and thus serve as an example of a complex subsystem. Simpler examples are given in the Obx subsystem, in particular the examples ObxAddress0, ObxAddress1, ObxAddress2, ObxOrders, ObxControls, and ObxDialog. A tutorial on the form subsystem is given in Chapter4 of the accompanying book on component software and the BlackBox Component Framework.
| Form/Docu/User-Man.odc |
FormViews
DEFINITION FormViews;
IMPORT Ports, Views, Controllers, Containers, FormModels;
CONST minBorder = 4 * Ports.point; maxBorder = 100 * Ports.mm;
TYPE
View = POINTER TO ABSTRACT RECORD (Containers.View)
(v: View) ThisModel (): FormModels.Model, EXTENSIBLE;
(v: View) SetBorder (border: INTEGER), NEW, ABSTRACT;
(v: View) Border (): INTEGER, NEW, ABSTRACT;
(v: View) SetGrid (grid, gridFactor: INTEGER), NEW, ABSTRACT;
(v: View) Grid (): INTEGER, NEW, ABSTRACT;
(v: View) GridFactor (): INTEGER, NEW, ABSTRACT;
(v: View) SetBackground (background: Ports.Color), NEW, ABSTRACT
END;
Directory = POINTER TO ABSTRACT RECORD
(d: Directory) New (f: FormModels.Model): View, NEW, ABSTRACT
END;
VAR
dir-, stdDir-: Directory;
ctrldir-: Controllers.Directory;
PROCEDURE Focus (): View;
PROCEDURE FocusModel (): FormModels.Model;
PROCEDURE RoundToGrid (v: View; VAR x, y: INTEGER);
PROCEDURE New (): View;
PROCEDURE Deposit;
PROCEDURE SetDir (d: Directory);
PROCEDURE SetCtrlDir (d: Containers.Directory);
END FormViews.
FormViews are the standard views on FormModels.
CONST minBorder, maxBorder
The border of a form view is the minimal distance between any of the view borders and the bounding box of the embedded views. The preferred border can be set to a value in the range [minBorder .. maxBorder].
TYPE View (Views.View)
ABSTRACT
PROCEDURE (v: View) ThisModel (): FormModels.Model
EXTENSIBLE
Result type is narrowed.
PROCEDURE (v: View) SetBorder (border: INTEGER)
NEW, ABSTRACT, Operation
Sets the view's preferred border (preferred minimal distance between any view edge and the closest embedded view).
Pre
border >= 0 20
Post
border < minBoder
v.border = minBorder
border > maxBorder
v.border = maxBorder
minBorder <= border <= maxBorder
v.border = border
PROCEDURE (v: View) Border (): INTEGER
NEW, ABSTRACT
Returns the view's border.
Post
minBorder <= result <= maxBorder
PROCEDURE (v: View) SetGrid (grid, gridFactor: INTEGER)
NEW, ABSTRACT, Operation
Sets the view's preferred grid (preferred grid on which any embedded view's top-left corner should be aligned) and grid factor (when the grid is shown, every gridFactor-th grid unit a dotted line is displayed).
Pre
grid > 0 20
gridFactor > 0 21
Post
v.Grid() = grid & v.GridFactor() = gridFactor
PROCEDURE (v: View) Grid (): INTEGER
NEW, ABSTRACT
Returns the current grid.
Post
result > 0
PROCEDURE (v: View) GridFactor (): INTEGER
NEW, ABSTRACT
Returns the current grid factor.
Post
result > 0
PROCEDURE (v: View) SetBackground (background: Ports.Color)
NEW, ABSTRACT
Sets a form's background color. Default is Ports.dialogBackground.
TYPE Directory
ABSTRACT
Directory for form views.
PROCEDURE (d: Directory) New (m: FormModels.Model): View
Interface
Return a new view on m
Pre
m # NIL 20
Post
result # NIL
result.ThisModel() = m
VAR dir, stdDir-: Directory dir # NIL & stdDir # NIL
Directory and standard directory for form views.
VAR ctrldir-: Controllers.Directory ctrldir # NIL
Form controller directory, installed by module FormControllers upon loading.
PROCEDURE Focus (): View
Returns the focus form view, if it is one.
PROCEDURE FocusModel (): FormModels.Model
Returns the model of the focus form view, if it is one.
PROCEDURE RoundToGrid (v: View; VAR x, y: INTEGER)
Rounds the coordinate (x, y) to the closest point on v's grid.
Pre
v # NIL 20
x > 0 & y > 0 21
Post
x MOD v.grid = 0
y MOD v.grid = 0
PROCEDURE New (): View
Returns a new form view with a new empty form model, i.e., returns FormViews.dir.New(FormModels.dir.New()).
PROCEDURE Deposit
Deposit creates a new form view with a new empty form model and deposits the view.
Deposit is called internally.
PROCEDURE SetDir (d: Directory)
Assigns view directory.
Pre
d # NIL 20
Post
dir = d
PROCEDURE SetCtrlDir (d: Containers.Directory)
Assigns the controller directory for form views.
Pre
d # NIL 20
| Form/Docu/Views.odc |
MODULE FormCmds;
(**
project = "BlackBox"
organization = "www.oberon.ch"
contributors = "Oberon microsystems"
version = "System/Rsrc/About"
copyright = "System/Rsrc/About"
license = "Docu/BB-License"
purpose = ""
changes = "
- YYYYMMDD, nn, ...
"
issues = "
- ...
"
**)
IMPORT
Strings, Dialog, Ports, Stores, Models, Views, Properties, Controls, Containers,
FormModels, FormViews, FormControllers, StdCmds;
CONST
mm = Ports.mm; inch16th = Ports.inch DIV 16;
left = 0; top = 1; right = 2; bottom = 3; row = 4; column = 5;
VAR
grid*: RECORD
resolution*: INTEGER; (* resolution > 0 *)
metricSystem*: BOOLEAN
END;
find*: RECORD
from*, to*: ARRAY 256 OF CHAR;
link*, label*, guard*, notifier*: BOOLEAN;
END;
PROCEDURE FindExtrema (c: FormControllers.Controller; OUT l, t, r, b, h, v: INTEGER;
OUT s: FormControllers.List);
VAR n: INTEGER; p: FormControllers. List; q: FormModels.Reader; w: Views.View;
BEGIN (* there is at least one view selected *)
l := MAX(INTEGER); t := MAX(INTEGER); r := MIN(INTEGER); b := MIN(INTEGER);
h := 0; v := 0; n := 0; s := NIL;
q := c.form.NewReader(NIL); q.Set(NIL); q.ReadView(w);
WHILE w # NIL DO
IF c.IsSelected(w) THEN
INC(h, q.l); INC(h, q.r); INC(v, q.t); INC(v, q.b); INC(n, 2);
NEW(p); p.next := s; s := p; p.view := w;
IF q.l < l THEN l := q.l END;
IF q.t < t THEN t := q.t END;
IF q.r > r THEN r := q.r END;
IF q.b > b THEN b := q.b END
END;
q.ReadView(w)
END;
h := h DIV n; v := v DIV n
END FindExtrema;
PROCEDURE Move (c: FormControllers.Controller; s: FormControllers. List; p, side: INTEGER;
name: Stores.OpName);
VAR script: Stores.Operation; w, h: INTEGER; l, t, r, b: INTEGER; s0: FormControllers.List;
BEGIN
s0 := s;
Models.BeginScript(c.form, name, script);
WHILE s # NIL DO
s.view.context(FormModels.Context).GetRect(l, t, r, b); w := r - l; h := b - t;
IF side = left THEN
l := p; r := l + w
ELSIF side = top THEN
t := p; b := t + h
ELSIF side = right THEN
r := p; l := r - w
ELSIF side = bottom THEN
b := p; t := b - h
ELSIF side = row THEN
t := p - h DIV 2; b := t + h
ELSIF side = column THEN
l := p - w DIV 2; r := l + w
END;
c.form.Resize(s.view, l, t, r, b);
s := s.next
END;
Models.EndScript(c.form, script);
WHILE s0 # NIL DO c.Select(s0.view); s0 := s0.next END
END Move;
PROCEDURE AlignLeft*;
(** Guard: SelectionGuard **)
VAR c: FormControllers.Controller; l, t, r, b, h, v: INTEGER; s: FormControllers.List;
BEGIN
c := FormControllers.Focus();
IF (c # NIL) & c.HasSelection() THEN
FindExtrema(c, l, t, r, b, h, v, s); Move(c, s, l, left, "#Form:AlignLeft")
END
END AlignLeft;
PROCEDURE AlignRight*;
(** Guard: SelectionGuard **)
VAR c: FormControllers.Controller; l, t, r, b, h, v: INTEGER; s: FormControllers.List;
BEGIN
c := FormControllers.Focus();
IF (c # NIL) & c.HasSelection() THEN
FindExtrema(c, l, t, r, b, h, v, s); Move(c, s, r, right, "#Form:AlignRight")
END
END AlignRight;
PROCEDURE AlignTop*;
(** Guard: SelectionGuard **)
VAR c: FormControllers.Controller; l, t, r, b, h, v: INTEGER; s: FormControllers.List;
BEGIN
c := FormControllers.Focus();
IF (c # NIL) & c.HasSelection() THEN
FindExtrema(c, l, t, r, b, h, v, s); Move(c, s, t, top, "#Form:AlignTop")
END
END AlignTop;
PROCEDURE AlignBottom*;
(** Guard: SelectionGuard **)
VAR c: FormControllers.Controller; l, t, r, b, h, v: INTEGER; s: FormControllers.List;
BEGIN
c := FormControllers.Focus();
IF (c # NIL) & c.HasSelection() THEN
FindExtrema(c, l, t, r, b, h, v, s); Move(c, s, b, bottom, "#Form:AlignBottom")
END
END AlignBottom;
PROCEDURE AlignToRow*;
(** Guard: SelectionGuard **)
VAR c: FormControllers.Controller; l, t, r, b, h, v: INTEGER; s: FormControllers.List;
BEGIN
c := FormControllers.Focus();
IF (c # NIL) & c.HasSelection() THEN
FindExtrema(c, l, t, r, b, h, v, s); Move(c, s, v, row, "#Form:AlignHorizontal")
END
END AlignToRow;
PROCEDURE AlignToColumn*;
(** Guard: SelectionGuard **)
VAR c: FormControllers.Controller; l, t, r, b, h, v: INTEGER; s: FormControllers.List;
BEGIN
c := FormControllers.Focus();
IF (c # NIL) & c.HasSelection() THEN
FindExtrema(c, l, t, r, b, h, v, s); Move(c, s, h, column, "#Form:AlignVertical")
END
END AlignToColumn;
PROCEDURE SelectOffGridViews*;
VAR c: FormControllers.Controller; v: Views.View; h: FormModels.Reader;
l, t, r, b, l0, t0, r0, b0: INTEGER;
BEGIN
c := FormControllers.Focus();
IF c # NIL THEN
c.SelectAll(FALSE);
h := c.form.NewReader(NIL);
h.ReadView(v);
WHILE v # NIL DO
v.context(FormModels.Context).GetRect(l, t, r, b);
l0 := l; t0 := t; r0 := r; b0 := b;
FormViews.RoundToGrid(c.view, l0, t0);
FormViews.RoundToGrid(c.view, r0, b0);
IF (l0 # l) OR (t0 # t) OR (r0 # r) OR (b0 # b) THEN c.Select(v) END;
h.ReadView(v)
END
END
END SelectOffGridViews;
PROCEDURE Selection (c: FormControllers.Controller): FormControllers.List;
VAR p, q: FormControllers. List; h: FormModels.Reader; v: Views.View;
BEGIN
p := NIL;
h := c.form.NewReader(NIL); h.Set(NIL); h.ReadView(v);
WHILE v # NIL DO
IF c.IsSelected(v) THEN NEW(q); q.next := p; p := q; q.view := v END;
h.ReadView(v)
END;
RETURN p
END Selection;
PROCEDURE ForceToGrid*;
(** Guard: SelectionGuard **)
VAR c: FormControllers.Controller;
l, t, r, b: INTEGER; sel, sel0: FormControllers.List; s: Stores.Operation;
BEGIN
c := FormControllers.Focus();
IF (c # NIL) & c.HasSelection() THEN
Models.BeginScript(c.form, "#Form:ForceToGrid", s);
sel := Selection(c); sel0 := sel;
WHILE sel # NIL DO
sel.view.context(FormModels.Context).GetRect(l, t, r, b);
FormViews.RoundToGrid(c.view, l, t);
FormViews.RoundToGrid(c.view, r, b);
c.form.Resize(sel.view, l, t, r, b);
sel := sel.next
END;
Models.EndScript(c.form, s);
WHILE sel0 # NIL DO c.Select(sel0.view); sel0 := sel0.next END
END
END ForceToGrid;
PROCEDURE SortViews*;
(** Guard: FocusGuard **)
VAR c: FormControllers.Controller; script: Stores.Operation;
r: FormModels.Reader; p, q: Views.View;
PROCEDURE IsAbove (p, q: Views.View): BOOLEAN;
VAR l0, l1, t0, t1, r, b: INTEGER;
BEGIN
p.context(FormModels.Context).GetRect(l0, t0, r, b);
q.context(FormModels.Context).GetRect(l1, t1, r, b);
RETURN (t0 < t1) OR (t0 = t1) & (l0 <= l1)
END IsAbove;
BEGIN
c := FormControllers.Focus();
IF (c # NIL) & (c.form.NofViews() > 1) THEN
c.SelectAll(FALSE);
Models.BeginScript(c.form, "#Form:ChangeZOrder", script);
r := c.form.NewReader(NIL);
REPEAT (* bubble sort *)
r.Set(NIL); r.ReadView(p); r.ReadView(q);
WHILE (q # NIL) & IsAbove(p, q) DO p := q; r.ReadView(q) END;
IF q # NIL THEN c.form.PutAbove(p, q) END
UNTIL q = NIL;
Models.EndScript(c.form, script);
c.SelectAll(TRUE)
END
END SortViews;
PROCEDURE SetAsFirst*;
(** Guard: SingletonGuard **)
(** send to back **)
VAR c: FormControllers.Controller; v: Views.View;
BEGIN
c := FormControllers.Focus();
IF c # NIL THEN
v := c.Singleton();
IF v # NIL THEN
c.form.PutAbove(v, NIL);
c.SetSingleton(v)
END
END
END SetAsFirst;
PROCEDURE SetAsLast*;
(** Guard: SingletonGuard **)
(** bring to front **)
VAR c: FormControllers.Controller; v, p, q: Views.View; r: FormModels.Reader;
BEGIN
c := FormControllers.Focus();
IF c # NIL THEN
v := c.Singleton();
IF v # NIL THEN
r := c.form.NewReader(NIL); r.Set(v); p := v;
REPEAT q := p; r.ReadView(p) UNTIL p = NIL;
c.form.PutAbove(v, q);
c.SetSingleton(v)
END
END
END SetAsLast;
PROCEDURE InsertAround*;
(** Guard: SelectionGuard **)
CONST d = 3 * Ports.mm;
VAR c: FormControllers.Controller; v: Views.View; rd: FormModels.Reader; l, t, r, b: INTEGER;
s: Stores.Operation;
BEGIN
ASSERT(Views.Available() = 1, 20);
c := FormControllers.Focus();
IF (c # NIL) & c.HasSelection() THEN
l := MAX(INTEGER); t := MAX(INTEGER); r := MIN(INTEGER); b := MIN(INTEGER);
rd := c.form.NewReader(NIL); rd.ReadView(v);
WHILE v # NIL DO
IF c.IsSelected(v) THEN
IF rd.l < l THEN l := rd.l END;
IF rd.t < t THEN t := rd.t END;
IF rd.r > r THEN r := rd.r END;
IF rd.b > b THEN b := rd.b END
END;
rd.ReadView(v)
END;
ASSERT(l < r, 100);
DEC(l, d); DEC(t, 3 * d); INC(r, d); INC(b, d);
FormViews.RoundToGrid(c.view, l, t);
FormViews.RoundToGrid(c.view, r, b);
Views.Fetch(v);
Models.BeginScript(c.form, "#Form:InsertAround", s);
c.form.Insert(v, l, t, r, b);
c.form.PutAbove(v, NIL);
Models.EndScript(c.form, s);
c.SetSingleton(v)
ELSE
StdCmds.PasteView
END
END InsertAround;
PROCEDURE InitGridDialog*;
(** Guard: FocusGuard **)
VAR c: FormControllers.Controller; g: INTEGER;
BEGIN
c := FormControllers.Focus();
IF c # NIL THEN
g := c.view.Grid();
IF g MOD mm = 0 THEN
grid.resolution := g DIV mm;
grid.metricSystem := TRUE
ELSIF g MOD inch16th = 0 THEN
grid.resolution := g DIV inch16th;
grid.metricSystem := FALSE
ELSIF Dialog.metricSystem THEN
grid.resolution := g DIV mm;
grid.metricSystem := TRUE
ELSE
grid.resolution := g DIV inch16th;
grid.metricSystem := FALSE
END;
Dialog.Update(grid)
END
END InitGridDialog;
PROCEDURE SetGrid*;
(** Guard: FocusGuard **)
VAR c: FormControllers.Controller; n: INTEGER;
BEGIN
c := FormControllers.Focus();
IF (c # NIL) & (grid.resolution > 0) THEN
IF grid.metricSystem THEN
n := 10 DIV grid.resolution;
IF n < 1 THEN n := 1 END;
c.view.SetGrid(grid.resolution * mm, n)
ELSE
n := 8 DIV grid.resolution;
IF n < 1 THEN n := 1 END;
c.view.SetGrid(grid.resolution * inch16th, n)
END
END
END SetGrid;
(** renaming of controls **)
PROCEDURE Rename*;
(** Guard: StdCmds.ContainerGuard **)
VAR c: Containers.Controller; v: Views.View;
msg: Properties.PollMsg; p, q: Properties.Property;
setMsg: Properties.SetMsg;
PROCEDURE Replace(VAR s: ARRAY OF CHAR; IN from, to: ARRAY OF CHAR);
VAR pos: INTEGER;
BEGIN
Strings.Find(s, from, 0, pos);
WHILE pos >= 0 DO
Strings.Replace(s, pos, LEN(from$), to);
Strings.Find(s, from, pos + LEN(to$), pos);
END
END Replace;
BEGIN
c := Containers.Focus();
IF c # NIL THEN
c.GetFirstView(Containers.any, v);
WHILE v # NIL DO
msg.prop := NIL; Views.HandlePropMsg(v, msg);
p := msg.prop; WHILE (p # NIL) & ~(p IS Controls.Prop) DO p := p.next END;
IF p # NIL THEN
q := Properties.CopyOf(p);
WITH q: Controls.Prop DO
IF find.label & (Controls.label IN q.valid) THEN Replace(q.label, find.from, find.to) END;
IF find.link & (Controls.link IN q.valid) THEN Replace(q.link, find.from, find.to) END;
IF find.guard & (Controls.guard IN q.valid) THEN Replace(q.guard, find.from, find.to) END;
IF find.notifier & (Controls.notifier IN q.valid) THEN Replace(q.notifier, find.from, find.to) END
END;
setMsg.prop := q;
Views.HandlePropMsg(v, setMsg);
END;
c.GetNextView(Containers.any, v)
END
END
END Rename;
(** standard form-related guards **)
PROCEDURE FocusGuard* (VAR par: Dialog.Par);
(** in non-FormView menus; otherwise implied by menu type **)
BEGIN
par.disabled := FormViews.Focus() = NIL
END FocusGuard;
PROCEDURE SelectionGuard* (VAR par: Dialog.Par);
(** in non-FormView menus; otherwise use "SelectionGuard" **)
VAR c: FormControllers.Controller;
BEGIN
c := FormControllers.Focus();
par.disabled := (c = NIL) OR ~c.HasSelection()
END SelectionGuard;
PROCEDURE SingletonGuard* (VAR par: Dialog.Par);
(** in non-FormView menus; otherwise use "SingletonGuard" **)
VAR c: FormControllers.Controller;
BEGIN
c := FormControllers.Focus();
par.disabled := (c = NIL) OR (c.Singleton() = NIL)
END SingletonGuard;
BEGIN
find.link := TRUE; find.label := TRUE; find.guard := TRUE; find.notifier := TRUE
END FormCmds.
| Form/Mod/Cmds.odc |
MODULE FormControllers;
(**
project = "BlackBox"
organization = "www.oberon.ch"
contributors = "Oberon microsystems"
version = "System/Rsrc/About"
copyright = "System/Rsrc/About"
license = "Docu/BB-License"
purpose = ""
changes = "
- 20080904, mf, StdController.IsSelected: conformance with contract improved
- 20160719, center #117, fixes for non-local drop behavior
"
issues = "
- ...
"
**)
IMPORT
Services, Ports, Stores, Models, Views, Controllers, Properties, Containers,
FormModels, FormViews;
CONST
noSelection* = Containers.noSelection; noFocus* = Containers.noFocus;
rdel = 7X; ldel = 8X;
arrowLeft = 1CX; arrowRight = 1DX; arrowUp = 1EX; arrowDown = 1FX;
(* range of currently supported versions *)
minVersion = 0; maxBaseVersion = 0; maxStdVersion = 0;
TYPE
Controller* = POINTER TO ABSTRACT RECORD (Containers.Controller)
form-: FormModels.Model;
view-: FormViews.View
END;
Directory* = POINTER TO ABSTRACT RECORD (Containers.Directory) END;
List* = POINTER TO RECORD
next*: List;
view*: Views.View
END;
StdController = POINTER TO RECORD (Controller)
sel: List; (* (sel = NIL) OR (c.ThisFocus() = NIL) *)
reader: FormModels.Reader;
lastX, lastY: INTEGER
END;
StdDirectory = POINTER TO RECORD (Directory) END;
MarkMsg = RECORD (Views.Message)
list: List;
show: BOOLEAN
END;
PollFocusMsg = RECORD (Controllers.PollFocusMsg)
c: Controller
END;
VAR dir-, stdDir-: Directory;
(** Controller **)
PROCEDURE (c: Controller) Internalize2- (VAR rd: Stores.Reader), EXTENSIBLE;
VAR thisVersion: INTEGER;
BEGIN
rd.ReadVersion(minVersion, maxBaseVersion, thisVersion)
END Internalize2;
PROCEDURE (c: Controller) Externalize2- (VAR wr: Stores.Writer), EXTENSIBLE;
BEGIN
wr.WriteVersion(maxBaseVersion)
END Externalize2;
PROCEDURE (c: Controller) InitView2* (view: Views.View), EXTENSIBLE;
BEGIN
IF view # NIL THEN
ASSERT(view IS FormViews.View, 25);
c.view := view(FormViews.View); c.form := c.view.ThisModel()
ELSE
c.form := NIL; c.view := NIL
END
END InitView2;
PROCEDURE (c: Controller) ThisView* (): FormViews.View, EXTENSIBLE;
BEGIN
RETURN c.view
END ThisView;
PROCEDURE (c: Controller) Select* (view: Views.View), NEW, ABSTRACT;
PROCEDURE (c: Controller) Deselect* (view: Views.View), NEW, ABSTRACT;
PROCEDURE (c: Controller) IsSelected* (view: Views.View): BOOLEAN, NEW, ABSTRACT;
PROCEDURE (c: Controller) GetSelection* (): List, NEW, ABSTRACT;
PROCEDURE (c: Controller) SetSelection* (l: List), NEW, ABSTRACT;
(** Directory **)
PROCEDURE (d: Directory) NewController* (opts: SET): Controller, ABSTRACT;
PROCEDURE (d: Directory) New* (): Controller, EXTENSIBLE;
BEGIN
RETURN d.NewController({})
END New;
(* auxiliary procedures *)
PROCEDURE MarkList (c: StdController; f: Views.Frame; h: List; show: BOOLEAN);
VAR l, t, r, b, s: INTEGER;
BEGIN
IF ~(Containers.noSelection IN c.opts) THEN
s := 2 * f.unit;
WHILE h # NIL DO
c.view.GetRect(f, h.view, l, t, r, b);
f.MarkRect(l - s, t - s, r + s, b + s, s, Ports.hilite, show);
h := h.next
END
END
END MarkList;
PROCEDURE Toggle (c: StdController; view: Views.View);
BEGIN
IF c.IsSelected(view) THEN c.Deselect(view) ELSE c.Select(view) END
END Toggle;
(* StdController *)
PROCEDURE (c: StdController) Internalize2 (VAR rd: Stores.Reader);
VAR thisVersion: INTEGER;
BEGIN
c.Internalize2^(rd);
IF ~rd.cancelled THEN
rd.ReadVersion(minVersion, maxStdVersion, thisVersion);
c.sel := NIL; c.lastX := -1
END
END Internalize2;
PROCEDURE (c: StdController) Externalize2 (VAR wr: Stores.Writer);
BEGIN
c.Externalize2^(wr);
wr.WriteVersion(maxStdVersion)
END Externalize2;
PROCEDURE (c: StdController) CopyFrom (source: Stores.Store);
BEGIN
c.CopyFrom^(source);
c.sel := NIL; c.lastX := -1
END CopyFrom;
PROCEDURE (c: StdController) RestoreMarks2 (f: Views.Frame; l, t, r, b: INTEGER);
BEGIN
IF (c.lastX <= f.l ) OR (c.lastX >= f.r) OR (c.lastY <= f.t) OR (c.lastY >= f.b) THEN
c.lastX := (f.l + f.r) DIV 2; c.lastY := (f.t + f.b) DIV 2
END
END RestoreMarks2;
PROCEDURE (c: StdController) HandleViewMsg (f: Views.Frame; VAR msg: Views.Message);
BEGIN
WITH msg: MarkMsg DO
MarkList(c, f, msg.list, msg.show)
ELSE
c.HandleViewMsg^(f, msg)
END
END HandleViewMsg;
PROCEDURE (c: StdController) HandleCtrlMsg (f: Views.Frame; VAR msg: Views.CtrlMessage;
VAR focus: Views.View);
BEGIN
WITH msg: PollFocusMsg DO
c.HandleCtrlMsg^(f, msg, focus);
msg.c := c
ELSE
c.HandleCtrlMsg^(f, msg, focus)
END
END HandleCtrlMsg;
(* subclass hooks *)
PROCEDURE (c: StdController) GetContextType (OUT type: Stores.TypeName);
BEGIN
type := "FormViews.View"
END GetContextType;
PROCEDURE (c: StdController) GetValidOps (OUT valid: SET);
BEGIN
valid := {Controllers.pasteChar, Controllers.paste};
IF c.sel # NIL THEN valid := valid + {Controllers.cut, Controllers.copy} END
END GetValidOps;
PROCEDURE (c: StdController) NativeModel (model: Models.Model): BOOLEAN;
BEGIN
ASSERT(model # NIL, 20);
RETURN model IS FormModels.Model
END NativeModel;
PROCEDURE (c: StdController) NativeView (view: Views.View): BOOLEAN;
BEGIN
ASSERT(view # NIL, 20);
RETURN view IS FormViews.View
END NativeView;
PROCEDURE (c: StdController) NativeCursorAt (f: Views.Frame; x, y: INTEGER): INTEGER;
BEGIN
ASSERT(f # NIL, 20);
RETURN Ports.graphicsCursor
END NativeCursorAt;
PROCEDURE (c: StdController) MakeViewVisible (v: Views.View);
VAR l, t, r, b: INTEGER;
BEGIN
ASSERT(v # NIL, 20);
ASSERT(v.context # NIL, 21);
ASSERT(v.context.ThisModel() = c.form, 22);
v.context(FormModels.Context).GetRect(l, t, r, b);
c.view.context.MakeVisible(l, t, r, b)
END MakeViewVisible;
PROCEDURE (c: StdController) GetFirstView (selection: BOOLEAN; OUT v: Views.View);
VAR rd: FormModels.Reader;
BEGIN
IF selection THEN
IF c.sel # NIL THEN v := c.sel.view ELSE v := NIL END
ELSE
rd := c.form.NewReader(c.reader); c.reader := rd;
rd.ReadView(v)
END
END GetFirstView;
PROCEDURE (c: StdController) GetNextView (selection: BOOLEAN; VAR v: Views.View);
VAR h: List; rd: FormModels.Reader;
BEGIN (* could be optimized *)
ASSERT(v # NIL, 20);
IF selection THEN
h := c.sel; WHILE (h # NIL) & (h.view # v) DO h := h.next END; ASSERT(h # NIL, 21);
IF h.next # NIL THEN v := h.next.view ELSE v := NIL END
ELSE
rd := c.form.NewReader(c.reader); c.reader := rd;
rd.Set(v); rd.ReadView(v)
END
END GetNextView;
PROCEDURE (c: StdController) GetSelectionBounds (f: Views.Frame; OUT x, y, w, h: INTEGER);
VAR g: Views.Frame; sel: List; l, t, r, b, gw, gh, border: INTEGER;
BEGIN
IF c.Singleton() # NIL THEN
c.GetSelectionBounds^(f, x, y, w, h)
ELSE
l := MAX(INTEGER); t := MAX(INTEGER); r := MIN(INTEGER); b := MIN(INTEGER);
sel := c.sel;
WHILE sel # NIL DO
g := Views.ThisFrame(f, sel.view);
IF g # NIL THEN
sel.view.context.GetSize(gw, gh);
IF g.gx < l THEN l := g.gx END;
IF g.gy < t THEN t := g.gy END;
IF g.gx + gw > r THEN r := g.gx + gw END;
IF g.gy + gh > b THEN b := g.gy + gh END;
END;
sel := sel.next
END;
IF (l < r) & (t < b) THEN
border := c.view.Border();
x := l - f.gx - border; y := t - f.gy - border;
w := r - l + 2 * border; h := b - t + 2 * border
ELSE
x := 0; y := 0; w := 0; h := 0
END
END
END GetSelectionBounds;
PROCEDURE (c: StdController) MarkDropTarget (src, dst: Views.Frame;
sx, sy, dx, dy, w, h, rx, ry: INTEGER;
type: Stores.TypeName;
isSingle, show: BOOLEAN);
CONST dm = 4 * Ports.point; dp = 18 * Ports.point;
VAR vx, vy, l, t, r, b: INTEGER; sc: Containers.Controller; s: Views.View;
BEGIN (* cf. Drop *)
IF ~isSingle & (src # NIL) & (src.view IS FormViews.View) THEN (* mark local form selection *)
vx := dx - sx; vy := dy - sy;
sc := src.view(FormViews.View).ThisController();
IF sc # NIL THEN
WITH sc: Controller DO
sc.GetFirstView(Containers.selection, s);
WHILE s # NIL DO
s.context(FormModels.Context).GetRect(l, t, r, b); w := r - l; h := b - t;
INC(l, vx); INC(t, vy); FormViews.RoundToGrid(c.view, l, t);
dst.MarkRect(l, t, l + w, t + h, 0, Ports.invert, show);
sc.GetNextView(Containers.selection, s)
END
END
END
ELSIF (w > 0) & (h > 0) THEN (* mark non-local form or singleton selection *)
vx := dx - rx; vy := dy - ry;
FormViews.RoundToGrid(c.view, vx, vy);
IF ~isSingle & Services.Extends(type, "FormViews.View") THEN (* general form selection *)
dst.MarkRect(vx - dm, vy, vx + dp, vy + dst.unit, 0, Ports.invert, show);
dst.MarkRect(vx, vy - dm, vx + dst.unit, vy + dp, 0, Ports.invert, show);
INC(vx, w); INC(vy, h);
dst.MarkRect(vx - dp, vy, vx + dm, vy + dst.unit, 0, Ports.invert, show);
dst.MarkRect(vx, vy - dp, vx + dst.unit, vy + dm, 0, Ports.invert, show)
ELSE (* singleton selection *)
dst.MarkRect(vx, vy, vx + w, vy + h, 0, Ports.invert, show)
END
ELSE (* cross-hair mark for non-form, non-singleton selections *)
FormViews.RoundToGrid(c.view, dx, dy);
dst.MarkRect(dx - dm, dy, dx + dp, dy + dst.unit, 0, Ports.invert, show);
dst.MarkRect(dx, dy - dm, dx + dst.unit, dy + dp, 0, Ports.invert, show)
END
END MarkDropTarget;
PROCEDURE (c: StdController) TrackMarks (f: Views.Frame; x, y: INTEGER;
units, extend, add: BOOLEAN);
VAR dx, dy, x0, y0, dx0, dy0: INTEGER; isDown: BOOLEAN; h: Views.View; m: SET;
PROCEDURE InvertRect (f: Views.Frame; x, y, dx, dy: INTEGER);
VAR l, t, r, b: INTEGER;
BEGIN
IF dx >= 0 THEN l := x; r := x + dx ELSE l := x + dx; r := x END;
IF dy >= 0 THEN t := y; b := y + dy ELSE t := y + dy; b := y END;
f.MarkRect(l, t, r, b, 0, Ports.dim50, TRUE)
END InvertRect;
PROCEDURE SelectArea (c: StdController; l, t, r, b: INTEGER; toggle: BOOLEAN);
VAR h: INTEGER; rd: FormModels.Reader; v: Views.View; p, q: List; empty: BOOLEAN;
BEGIN
IF l > r THEN h := l; l := r; r := h END;
IF t > b THEN h := t; t := b; b := h END;
rd := c.form.NewReader(c.reader); c.reader := rd;
rd.ReadView(v); p := NIL; empty := c.sel = NIL;
WHILE v # NIL DO
IF (rd.l < r) & (rd.t < b) & (rd.r > l) & (rd.b > t) THEN
IF toggle THEN Toggle(c, v)
ELSIF ~empty THEN c.Select(v)
ELSE NEW(q); q.next := p; p := q; q.view := v
END
END;
rd.ReadView(v)
END;
(* this optimization prevents the appearance of a temporary singleton *)
IF ~toggle & empty THEN c.SetSelection(p) END
END SelectArea;
BEGIN
dx := 0; dy := 0; (* vector from (x, y) *)
InvertRect(f, x, y, dx, dy);
REPEAT
f.Input(x0, y0, m, isDown);
dx0 := x0 - x; dy0 := y0 - y;
IF (dx0 # dx) OR (dy0 # dy) THEN
InvertRect(f, x, y, dx, dy);
dx := dx0; dy := dy0;
InvertRect(f, x, y, dx, dy)
END
UNTIL ~isDown;
InvertRect(f, x, y, dx, dy);
c.lastX := x0; c.lastY := y0;
IF (dx # 0) OR (dy # 0) THEN
SelectArea(c, x, y, x + dx, y + dy, extend OR add)
ELSE
h := c.form.ViewAt(x, y);
IF h # NIL THEN
IF extend OR add THEN Toggle(c, h) ELSE c.Select(h) END
END
END
END TrackMarks;
PROCEDURE (c: StdController) Resize (view: Views.View; l, t, r, b: INTEGER);
BEGIN
c.form.Resize(view, l, t, r, b)
END Resize;
PROCEDURE (c: StdController) DeleteSelection;
VAR script: Stores.Operation; h: List;
BEGIN
Models.BeginScript(c.form, "#System:Deletion", script);
h := c.sel; WHILE h # NIL DO c.form.Delete(h.view); h := h.next END;
Models.EndScript(c.form, script)
END DeleteSelection;
PROCEDURE MoveRelativeLocalSel (c: StdController; src, dst: Views.Frame;
dx, dy: INTEGER; grid: BOOLEAN);
VAR script: Stores.Operation; sel, h: List; l, t, r, b, newl, newt: INTEGER;
BEGIN
IF (dx # 0) OR (dy # 0) THEN
sel := c.GetSelection();
Models.BeginScript(c.form, "#System:Moving", script);
h := sel;
WHILE h # NIL DO
h.view.context(FormModels.Context).GetRect(l, t, r, b);
newl := l + dx; newt := t + dy;
IF grid THEN FormViews.RoundToGrid(c.view, newl, newt) END;
c.form.Move(h.view, newl - l, newt - t);
h := h.next
END;
Models.EndScript(c.form, script);
c.SetSelection(sel)
END
END MoveRelativeLocalSel;
PROCEDURE (c: StdController) MoveLocalSelection (src, dst: Views.Frame; sx, sy,
dx, dy: INTEGER);
BEGIN
MoveRelativeLocalSel(c, src, dst, dx - sx, dy - sy, TRUE)
END MoveLocalSelection;
PROCEDURE (c: StdController) CopyLocalSelection (src, dst: Views.Frame; sx, sy,
dx, dy: INTEGER);
VAR script: Stores.Operation; q: Views.View; h, s, t: List;
BEGIN
dx := dx - sx; dy := dy - sy;
IF (dx # 0) OR (dy # 0) THEN
FormViews.RoundToGrid(c.view, dx, dy);
Models.BeginScript(c.form, "#System:Copying", script);
h := c.GetSelection(); s := NIL;
WHILE h # NIL DO
q := h.view; c.form.Copy(q, dx, dy);
NEW(t); t.next := s; s := t; t.view := q;
h := h.next
END;
Models.EndScript(c.form, script);
c.SetSelection(s)
END
END CopyLocalSelection;
PROCEDURE (c: StdController) SelectionCopy (): Containers.Model;
VAR f: FormModels.Model; rd: FormModels.Reader; wr: FormModels.Writer;
v: Views.View; dx, dy: INTEGER;
PROCEDURE GetOffset (p: List; border: INTEGER; OUT dx, dy: INTEGER);
VAR l, t, vl, vt, vr, vb: INTEGER;
BEGIN
IF p # NIL THEN
l := MAX(INTEGER); t := MAX(INTEGER);
WHILE p # NIL DO
p.view.context(FormModels.Context).GetRect(vl, vt, vr, vb);
IF vl < l THEN l := vl END;
IF vt < t THEN t := vt END;
p := p.next
END;
dx := l - border; dy := t - border
ELSE
dx := 0; dy := 0
END
END GetOffset;
BEGIN
f := FormModels.CloneOf(c.form);
GetOffset(c.sel, c.view.Border(), dx, dy);
rd := c.form.NewReader(NIL); wr := f.NewWriter(NIL);
rd.ReadView(v);
WHILE v # NIL DO
IF c.IsSelected(v) THEN
wr.WriteView(Views.CopyOf(v, Views.deep), rd.l - dx, rd.t - dy, rd.r - dx, rd.b - dy)
END;
rd.ReadView(v)
END;
RETURN f
END SelectionCopy;
PROCEDURE (c: StdController) NativePaste (m: Models.Model; f: Views.Frame);
VAR x, y, cw, ch: INTEGER; v: Views.View; rd: FormModels.Reader;
wr: FormModels.Writer; n, i: INTEGER; script: Stores.Operation;
BEGIN
x := c.lastX; y := c.lastY;
c.view.context.GetSize(cw, ch);
IF (x <= f.l) OR (x >= f.r) OR (y <= f.t) OR (y >= f.b) THEN
x := (f.l + f.r) DIV 2; y := (f.r + f.b) DIV 2
END;
c.lastX := x; c.lastY := y;
FormViews.RoundToGrid(c.view, x, y);
WITH m: FormModels.Model DO
Models.BeginScript(c.form, "#System:Insertion", script);
rd := m.NewReader(NIL); wr := c.form.NewWriter(NIL); wr.Set(c.form.Top());
rd.ReadView(v); n := 0;
WHILE v # NIL DO
wr.WriteView(Views.CopyOf(v, Views.shallow), x + rd.l, y + rd.t, x + rd.r, y + rd.b);
INC(n);
rd.ReadView(v)
END;
Models.EndScript(c.form, script);
(* n views have been inserted at the top => select them *)
c.SelectAll(Containers.deselect);
i := c.form.NofViews() - n; ASSERT(i >= 0, 100);
rd := c.form.NewReader(rd);
WHILE i # 0 DO rd.ReadView(v); DEC(i) END; (* skip old views *)
WHILE n # 0 DO rd.ReadView(v); c.Select(v); DEC(n) END
END
END NativePaste;
PROCEDURE (c: StdController) ArrowChar (f: Views.Frame; ch: CHAR; units, select: BOOLEAN);
VAR d: INTEGER;
BEGIN
IF units THEN d := c.view.Grid() ELSE d := f.unit END;
IF ch = arrowLeft THEN
MoveRelativeLocalSel(c, f, f, -d, 0, units)
ELSIF ch = arrowRight THEN
MoveRelativeLocalSel(c, f, f, +d, 0, units)
ELSIF ch = arrowUp THEN
MoveRelativeLocalSel(c, f, f, 0, -d, units)
ELSIF ch = arrowDown THEN
MoveRelativeLocalSel(c, f, f, 0, +d, units)
END
END ArrowChar;
PROCEDURE (c: StdController) ControlChar (f: Views.Frame; ch: CHAR);
BEGIN
IF (ch = ldel) OR (ch = rdel) THEN c.DeleteSelection END
END ControlChar;
PROCEDURE (c: StdController) PasteChar (ch: CHAR);
END PasteChar;
PROCEDURE (c: StdController) PasteView (f: Views.Frame; v: Views.View; w, h: INTEGER);
VAR minW, maxW, minH, maxH, x, y: INTEGER;
BEGIN
x := c.lastX; y := c.lastY;
IF (x <= f.l) OR (x >= f.r) OR (y <= f.t) OR (y >= f.b) THEN
x := (f.l + f.r) DIV 2; y := (f.t + f.b) DIV 2
END;
c.lastX := x; c.lastY := y;
FormViews.RoundToGrid(c.view, x, y);
c.form.GetEmbeddingLimits(minW, maxW, minH, maxH);
Properties.PreferredSize(v, minW, maxW, minH, maxH, minW, minH, w, h);
c.form.Insert(v, x, y, x + w, y + h); c.Select(v)
END PasteView;
PROCEDURE (c: StdController) Drop (src, dst: Views.Frame; sx, sy, dx, dy,
w, h, rx, ry: INTEGER; v: Views.View; isSingle: BOOLEAN);
VAR minW, maxW, minH, maxH, l, t, sw, sh: INTEGER;
s: Views.View; p, q: List;
m: FormModels.Model; rd: FormModels.Reader; wr: FormModels.Writer;
script: Stores.Operation;
BEGIN (* cf. MarkDropTarget *)
DEC(dx, rx); DEC(dy, ry);
IF ~isSingle & (v IS FormViews.View) THEN
Models.BeginScript(c.form, "#System:Insertion", script);
m := v(FormViews.View).ThisModel();
rd := m.NewReader(NIL); wr := c.form.NewWriter(NIL);
rd.ReadView(s); p := NIL;
WHILE s # NIL DO
l := rd.l + dx; t := rd.t + dy; sw := rd.r - rd.l; sh := rd.b - rd.t;
FormViews.RoundToGrid(c.view, l, t);
s := Views.CopyOf(s, Views.shallow);
wr.WriteView(s, l, t, l + sw, t + sh);
NEW(q); q.next := p; p := q; q.view := s;
rd.ReadView(s)
END;
Models.EndScript(c.form, script); (* this line was added *)
c.SetSelection(p)
ELSE
FormViews.RoundToGrid(c.view, dx, dy);
c.form.GetEmbeddingLimits(minW, maxW, minH, maxH);
Properties.PreferredSize(v, minW, maxW, minH, maxH, minW, minH, w, h);
c.form.Insert(v, dx, dy, dx + w, dy + h); c.Select(v)
END
END Drop;
(* selection *)
PROCEDURE (c: StdController) HasSelection (): BOOLEAN;
BEGIN
RETURN c.sel # NIL
END HasSelection;
PROCEDURE (c: StdController) Selectable (): BOOLEAN;
BEGIN
RETURN c.form.NofViews() # 0
END Selectable;
PROCEDURE (c: StdController) SetSingleton (s: Views.View);
VAR l: List;
BEGIN
c.SetSingleton^(s);
IF s # NIL THEN NEW(l); l.view := s; c.sel := l ELSE c.sel := NIL END
END SetSingleton;
PROCEDURE (c: StdController) SelectAll (select: BOOLEAN);
VAR s: FormModels.Reader; v: Views.View; l, h: List; msg: MarkMsg;
BEGIN
IF select THEN
ASSERT(~(Containers.noSelection IN c.opts), 20);
c.SetFocus(NIL);
s := c.form.NewReader(c.reader); c.reader := s;
s.Set(NIL); s.ReadView(v);
IF c.form.NofViews() = 1 THEN
ASSERT(v # NIL, 100);
c.SetSingleton(v)
ELSE
IF (c.sel # NIL) & (c.sel.next = NIL) THEN c.SetSingleton(NIL) END;
l := NIL;
WHILE v # NIL DO
IF ~c.IsSelected(v) THEN NEW(h); h.next := l; l := h; h.view := v END;
s.ReadView(v)
END;
msg.list := l;
h := c.sel; WHILE (h # NIL) & (h.next # NIL) DO h := h.next END;
IF h = NIL THEN c.sel := l ELSE h.next := l END;
IF msg.list # NIL THEN msg.show := TRUE; Views.Broadcast(c.view, msg) END
END
ELSIF c.sel # NIL THEN
IF c.sel.next = NIL THEN (* singleton *)
c.SetSingleton(NIL)
ELSE
msg.list := c.sel; c.sel := NIL;
msg.show := FALSE; Views.Broadcast(c.view, msg)
END
END
END SelectAll;
PROCEDURE (c: StdController) InSelection (f: Views.Frame; x, y: INTEGER): BOOLEAN;
VAR g: Views.Frame;
BEGIN
g := Views.FrameAt(f, x, y);
IF g # NIL THEN
RETURN c.IsSelected(g.view)
ELSE
RETURN FALSE
END
END InSelection;
PROCEDURE (c: StdController) MarkSelection (f: Views.Frame; show: BOOLEAN);
BEGIN
IF c.sel = NIL THEN (* skip *)
ELSIF c.sel.next = NIL THEN
Containers.MarkSingleton(c, f, show)
ELSE
MarkList(c, f, c.sel, show)
END
END MarkSelection;
(* caret *)
PROCEDURE (c: StdController) HasCaret (): BOOLEAN;
BEGIN
RETURN TRUE
END HasCaret;
PROCEDURE (c: StdController) MarkCaret (f: Views.Frame; show: BOOLEAN);
END MarkCaret;
(* FormController protocol *)
PROCEDURE (c: StdController) Select (view: Views.View);
VAR l, h, sel: List; msg: MarkMsg;
BEGIN
ASSERT(view # NIL, 20); ASSERT(view.context.ThisModel() = c.form, 21);
ASSERT(~(Containers.noSelection IN c.opts), 22);
l := c.sel; WHILE (l # NIL) & (l.view # view) DO l := l.next END;
IF l = NIL THEN (* view is not yet selected *)
sel := c.sel;
IF sel = NIL THEN
c.SetSingleton(view)
ELSE
NEW(l); l.view := view;
IF sel.next = NIL THEN
c.SetSingleton(NIL); ASSERT(c.sel = NIL, 100);
l.next := sel; c.sel := l;
msg.list := l
ELSE
l.next := sel; c.sel := l;
NEW(h); h.view := view;
msg.list := h
END;
msg.show := TRUE; Views.Broadcast(c.view, msg)
END
END
END Select;
PROCEDURE (c: StdController) Deselect (view: Views.View);
VAR l, h: List; msg: MarkMsg;
BEGIN
ASSERT(view # NIL, 20); ASSERT(view.context.ThisModel() = c.form, 21);
l := c.sel; h := NIL; WHILE (l # NIL) & (l.view # view) DO h := l; l := l.next END;
IF l # NIL THEN (* l is selection node of view, h its predecessor *)
IF (h = NIL) & (l.next = NIL) THEN (* singleton *)
c.SetSingleton(NIL)
ELSE
IF h = NIL THEN c.sel := l.next ELSE h.next := l.next END;
msg.list:= l; l.next := NIL; msg.show := FALSE; Views.Broadcast(c.view, msg);
IF (c.sel # NIL) & (c.sel.next = NIL) THEN (* singleton *)
view := c.sel.view;
msg.list := c.sel; c.sel := NIL;
msg.show := TRUE; Views.Broadcast(c.view, msg);
c.SetSingleton(view)
END
END
END
END Deselect;
PROCEDURE (c: StdController) IsSelected (view: Views.View): BOOLEAN;
VAR l: List;
BEGIN
IF view # NIL THEN
ASSERT(view.context.ThisModel() = c.form, 20);
l := c.sel; WHILE (l # NIL) & (l.view # view) DO l := l.next END;
RETURN l # NIL
ELSE
RETURN FALSE
END
END IsSelected;
PROCEDURE (c: StdController) GetSelection (): List;
VAR l, h, s: List;
BEGIN
l := NIL; s := c.sel;
WHILE s # NIL DO NEW(h); h.next := l; l := h; h.view := s.view; s := s.next END;
RETURN l
END GetSelection;
PROCEDURE (c: StdController) SetSelection (l: List);
VAR msg: MarkMsg;
BEGIN
c.SelectAll(FALSE); ASSERT(c.sel = NIL, 100);
IF l = NIL THEN (* skip *)
ELSIF l.next = NIL THEN
c.SetSingleton(l.view)
ELSE
msg.list := l; c.sel := l;
msg.show := TRUE; Views.Broadcast(c.view, msg)
END
END SetSelection;
(* StdDirectory *)
PROCEDURE (d: StdDirectory) NewController (opts: SET): Controller;
VAR c: StdController;
BEGIN
NEW(c); c.SetOpts(opts); RETURN c
END NewController;
(** miscellaneous **)
PROCEDURE Focus* (): Controller;
VAR msg: PollFocusMsg;
BEGIN
msg.c := NIL;
Controllers.Forward(msg);
RETURN msg.c
END Focus;
PROCEDURE Insert* (c: Controller; view: Views.View; l, t, r, b: INTEGER);
VAR w, h: INTEGER;
BEGIN
w := r - l; h := b - t;
FormViews.RoundToGrid(c.view, l, t);
c.form.Insert(view, l, t, l + w, t + h)
END Insert;
PROCEDURE SetDir* (d: Directory);
BEGIN
ASSERT(d # NIL, 20); dir := d
END SetDir;
PROCEDURE Install*;
BEGIN
FormViews.SetCtrlDir(dir)
END Install;
PROCEDURE Init;
VAR d: StdDirectory;
BEGIN
NEW(d); SetDir(d); stdDir := d
END Init;
BEGIN
Init
END FormControllers.
| Form/Mod/Controllers.odc |
MODULE FormGen;
(**
project = "BlackBox"
organization = "www.oberon.ch"
contributors = "Oberon microsystems"
version = "System/Rsrc/About"
copyright = "System/Rsrc/About"
license = "Docu/BB-License"
purpose = ""
changes = "
- YYYYMMDD, nn, ...
"
issues = "
- ...
"
**)
IMPORT
Strings, Meta, Dates, Files, Ports, Views, Properties, Dialog, Containers, Documents,
Controls, StdDialog, StdCmds, FormModels, FormViews, FormControllers;
CONST
defaultDelta = 4 * Ports.point;
minW = 10 * Ports.mm; minH = 4 * Ports.mm;
maxW = 200 * Ports.mm; maxH = 50 * Ports.mm;
TYPE
ProcVal = RECORD (Meta.Value)
p: PROCEDURE
END;
VAR
new*: RECORD
link*: Dialog.String
END;
list: RECORD (Meta.Value) p*: POINTER TO Dialog.List END;
select: RECORD (Meta.Value) p*: POINTER TO Dialog.Selection END;
combo: RECORD (Meta.Value) p*: POINTER TO Dialog.Combo END;
date: RECORD (Meta.Value) p*: POINTER TO Dates.Date END;
time: RECORD (Meta.Value) p*: POINTER TO Dates.Time END;
color: RECORD (Meta.Value) p*: POINTER TO Dialog.Color END;
currency: RECORD (Meta.Value) p*: POINTER TO Dialog.Currency END;
tree: RECORD (Meta.Value) p*: POINTER TO Dialog.Tree END;
PROCEDURE GetSize (v: Views.View; VAR w, h: INTEGER);
BEGIN
w := Views.undefined; h := Views.undefined;
Properties.PreferredSize(v, minW, maxW, minH, maxH, minW, minH, w, h)
END GetSize;
PROCEDURE Gen (f: FormModels.Model; fv: FormViews.View; VAR path, name: ARRAY OF CHAR;
wr: FormModels.Writer; var: Meta.Item; VAR x, y, max: INTEGER; VAR first: BOOLEAN);
VAR v, str: Views.View; dummy, delta, x0, y0, m, w, h, i: INTEGER; n: Meta.Name;
p: Controls.Prop; s: Meta.Scanner; elem: Meta.Item; ok, back: BOOLEAN; pv: ProcVal;
BEGIN
dummy := 0; delta := defaultDelta; FormViews.RoundToGrid(fv, dummy, delta);
NEW(p); p.guard := ""; p.notifier := ""; p.label := ""; p.level := 0;
p.opt[0] := FALSE; p.opt[1] := FALSE; p.opt[2] := FALSE; p.opt[3] := FALSE; p.opt[4] := FALSE;
back := FALSE;
FormViews.RoundToGrid(fv, x, y);
v := NIL; w := Views.undefined; x0 := x; y0 := y;
IF (name[0] >= "0") & (name[0] <= "9") THEN p.link := path + "[" + name + "]"
ELSIF name # "" THEN p.link := path + "." + name
ELSE p.link := path$
END;
IF var.obj = Meta.modObj THEN (* traverse module *)
s.ConnectTo(var); s.Scan; m := 0;
WHILE ~ s.eos DO
s.GetObjName(n);
Gen(f, fv, p.link, n, wr, s.this, x, y, m, first);
s.Scan
END;
IF m > max THEN max := m END;
ELSIF var.obj = Meta.procObj THEN
var.GetVal(pv, ok);
IF ok THEN (* command *)
IF first THEN p.opt[Controls.default] := TRUE END;
p.label := name$; v := Controls.dir.NewPushButton(p);
p.opt[Controls.default] := FALSE; first := FALSE
END
ELSIF var.obj = Meta.varObj THEN
IF (var.typ IN {Meta.byteTyp, Meta.sIntTyp, Meta.longTyp, Meta.intTyp, Meta.sRealTyp, Meta.realTyp})
OR (var.typ = Meta.arrTyp) & (var.BaseTyp() = Meta.charTyp) THEN
p.opt[Controls.left] := TRUE; v := Controls.dir.NewField(p)
ELSIF var.typ = Meta.boolTyp THEN
p.label := name$; v := Controls.dir.NewCheckBox(p)
ELSIF var.typ = Meta.procTyp THEN
var.GetVal(pv, ok);
IF ok THEN (* command *)
IF first THEN p.opt[Controls.default] := TRUE END;
p.label := name$; v := Controls.dir.NewPushButton(p);
p.opt[Controls.default] := FALSE; first := FALSE
END
ELSIF var.typ = Meta.recTyp THEN
IF var.Is(list) THEN v := Controls.dir.NewListBox(p)
ELSIF var.Is(select) THEN v := Controls.dir.NewSelectionBox(p)
ELSIF var.Is(combo) THEN v := Controls.dir.NewComboBox(p)
ELSIF var.Is(date) THEN v := Controls.dir.NewDateField(p)
ELSIF var.Is(time) THEN v := Controls.dir.NewTimeField(p)
ELSIF var.Is(color) THEN v := Controls.dir.NewColorField(p)
ELSIF var.Is(currency) THEN p.opt[Controls.left] := TRUE; v := Controls.dir.NewField(p)
ELSIF var.Is(tree) THEN
p.opt[Controls.haslines] := TRUE; p.opt[Controls.hasbuttons] := TRUE;
p.opt[Controls.atroot] := TRUE; p.opt[Controls.foldericons] := TRUE;
v := Controls.dir.NewTreeControl(p)
ELSE (* traverse record *)
s.ConnectTo(var); s.Scan; m := 0;
IF name # "" THEN INC(x, delta); INC(y, 4 * delta) END;
WHILE ~ s.eos DO
s.GetObjName(n);
Gen(f, fv, p.link, n, wr, s.this, x, y, m, first);
s.Scan
END;
IF m > max THEN max := m END;
IF (name # "") & (m > 0) THEN (* insert group *)
p.label := name$; v := Controls.dir.NewGroup(p);
w := m; x := x0; h := y + delta - y0; y := y0; back := TRUE
END
END
ELSIF var.typ = Meta.arrTyp THEN (* traverse array *)
i := 0; m := 0;
IF name # "" THEN INC(x, delta); INC(y, 4 * delta) END;
WHILE i < var.Len() DO
var.Index(i, elem);
Strings.IntToString(i, n);
Gen(f, fv, p.link, n, wr, elem, x, y, m, first);
INC(i)
END;
IF m > max THEN max := m END;
IF (name # "") & (m > 0) THEN (* insert group *)
p.label := name$; v := Controls.dir.NewGroup(p);
w := m; x := x0; h := y + delta - y0; y := y0; back := TRUE
END
END
END;
IF v # NIL THEN
IF (name # "") & (p.label = "") THEN
p.label := name$;
str := Controls.dir.NewCaption(p); GetSize(str, w, h);
wr.WriteView(str, x, y, x + w, y + h); INC(x, w + delta);
FormViews.RoundToGrid(fv, x, y)
END;
IF ~back THEN GetSize(v, w, h) END;
wr.WriteView(v, x, y, x + w, y + h); INC(x, w + delta);
IF back THEN f.PutAbove(v, NIL) END;
y := y + h + delta
END;
IF x > max THEN max := x END;
x := x0
END Gen;
PROCEDURE NewDialog (name: ARRAY OF CHAR): Views.View;
VAR var: Meta.Item; x, y, max: INTEGER; wr: FormModels.Writer; d: Documents.Document;
f: FormModels.Model; v: FormViews.View; first: BOOLEAN; n: ARRAY 4 OF CHAR;
c: Containers.Controller;
BEGIN
f := NIL; v := NIL;
Meta.LookupPath(name, var);
IF (var.obj = Meta.varObj) OR (var.obj = Meta.modObj) THEN
x := defaultDelta; y := defaultDelta; max := 50 * Ports.point; first := TRUE;
f := FormModels.dir.New();
v := FormViews.dir.New(f); c := v.ThisController();
IF c # NIL THEN
c.SetOpts(Containers.layout)
ELSE
v.SetController(FormControllers.dir.NewController(Containers.layout))
END;
wr := f.NewWriter(NIL); wr.Set(NIL); n := "";
Gen(f, v, name, n, wr, var, x, y, max, first);
d := Documents.dir.New(v, max, y)
ELSE Dialog.ShowParamMsg("#Form:VariableNotFound", name, "", "")
END;
RETURN v
END NewDialog;
PROCEDURE Create*;
VAR v: Views.View; i, j: INTEGER; mod, name: Files.Name; loc: Files.Locator;
w: FormViews.View; c: Containers.Controller;
BEGIN
v := NIL;
IF new.link = "" THEN
w := FormViews.dir.New(FormModels.dir.New()); c := w.ThisController();
IF c # NIL THEN
c.SetOpts({FormControllers.noFocus})
ELSE
w.SetController(FormControllers.dir.NewController({FormControllers.noFocus}))
END;
v := w
ELSE
v := NewDialog(new.link)
END;
IF v # NIL THEN
mod := new.link$; new.link := ""; name := "";
StdCmds.CloseDialog;
IF mod # "" THEN
i := 0; WHILE (mod[i] # 0X) & (mod[i] # ".") DO INC(i) END;
IF mod[i] # 0X THEN (* module.variable *)
mod[i] := 0X; INC(i); j := 0;
WHILE mod[i] # 0X DO name[j] := mod[i]; INC(i); INC(j) END;
name[j] := 0X
END;
StdDialog.GetSubLoc(mod, "Rsrc", loc, mod);
IF name = "" THEN name := mod$ END;
loc.res := 77
ELSE
loc := NIL; name := ""
END;
Views.Open(v, loc, name, NIL);
Views.BeginModification(Views.notUndoable, v);
Views.EndModification(Views.notUndoable, v)
END
END Create;
PROCEDURE Empty*;
BEGIN
new.link := ""; Create
END Empty;
PROCEDURE CreateGuard* (VAR par: Dialog.Par);
BEGIN
IF new.link = "" THEN par.disabled := TRUE END
END CreateGuard;
END FormGen.
| Form/Mod/Gen.odc |
MODULE FormModels;
(**
project = "BlackBox"
organization = "www.oberon.ch"
contributors = "Oberon microsystems"
version = "System/Rsrc/About"
copyright = "System/Rsrc/About"
license = "Docu/BB-License"
purpose = ""
changes = "
- YYYYMMDD, nn, ...
"
issues = "
- ...
"
**)
IMPORT Ports, Stores, Models, Views, Properties, Containers;
CONST
minViewSize* = 4 * Ports.point; (** size of smallest embedded view **)
maxViewSize* = 1000 * Ports.mm; (** size of largest embedded view **)
(* range of currently supported versions *)
minVersion = 0; maxBaseVersion = 0; maxStdVersion = 0;
TYPE
(* interface types *)
Model* = POINTER TO ABSTRACT RECORD (Containers.Model) END;
Directory* = POINTER TO ABSTRACT RECORD END;
Context* = POINTER TO ABSTRACT RECORD (Models.Context) END;
Reader* = POINTER TO ABSTRACT RECORD
view*: Views.View; (** most recently read view **)
l*, t*, r*, b*: INTEGER (** bounding box of most recently read view **)
END;
Writer* = POINTER TO ABSTRACT RECORD END;
UpdateMsg* = RECORD (Models.UpdateMsg)
(** the receiver of this message must not switch on any marks **)
l*, t*, r*, b*: INTEGER (** (l < r) & (b < t) **)
END;
(* concrete types *)
StdDirectory = POINTER TO RECORD (Directory) END;
StdModel = POINTER TO RECORD (Model)
contexts: StdContext (* list of views in form, ordered from bottom to top *)
END;
StdContext = POINTER TO RECORD (Context)
next: StdContext; (* next upper view *)
form: StdModel; (* form # NIL *)
view: Views.View; (* view # NIL *)
l, t, r, b: INTEGER (* (r - l >= minViewSize) & (b - t >= minViewSize) *)
END;
StdReader = POINTER TO RECORD (Reader)
form: StdModel; (* form # NIL *)
pos: StdContext (* next ReadView: read view above pos *)
END;
StdWriter = POINTER TO RECORD (Writer)
form: StdModel; (* form # NIL *)
pos: StdContext (* next WriteView: insert view above pos *)
END;
FormOp = POINTER TO RECORD (Stores.Operation)
del, ins: StdContext; (* ((del = NIL) # (ins = NIL)) OR (del = ins) *)
pos: StdContext (* ins # NIL => next Do: insert ins above pos *)
END;
ResizeOp = POINTER TO RECORD (Stores.Operation)
context: StdContext; (* context # NIL *)
l, t, r, b: INTEGER (* (r - l >= minViewSize) & (b - t >= minViewSize) *)
END;
ReplaceViewOp = POINTER TO RECORD (Stores.Operation)
context: StdContext; (* context # NIL *)
view: Views.View (* view # NIL *)
END;
VAR dir-, stdDir-: Directory; (** (dir # NIL) & (stdDir # NIL) **)
(** Model **)
PROCEDURE (f: Model) GetEmbeddingLimits* (OUT minW, maxW,
minH, maxH: INTEGER), EXTENSIBLE;
BEGIN
minH := minViewSize; minW := minViewSize;
maxH := maxViewSize; maxW := maxViewSize
END GetEmbeddingLimits;
PROCEDURE (f: Model) Insert* (v: Views.View; l, t, r, b: INTEGER), NEW, ABSTRACT;
(**
v # NIL 20
v.init 21
v.context = NIL 22
l <= r 23
t <= b 24
**)
PROCEDURE (f: Model) Delete* (v: Views.View), NEW, ABSTRACT;
(** v in f 20 **)
PROCEDURE (f: Model) Resize* (v: Views.View; l, t, r, b: INTEGER), NEW, ABSTRACT;
(**
v in f 20
l <= r 21
t <= b 22
**)
PROCEDURE (f: Model) Top* (): Views.View, NEW, ABSTRACT;
PROCEDURE (f: Model) PutAbove* (v, pos: Views.View), NEW, ABSTRACT;
(**
v in f 20
(pos = NIL) OR (pos in f) 21
**)
PROCEDURE (f: Model) Move* (v: Views.View; dx, dy: INTEGER), NEW, ABSTRACT;
(** v in f 20 **)
PROCEDURE (f: Model) Copy* (VAR v: Views.View; dx, dy: INTEGER), NEW, ABSTRACT;
(** v in f 20 **)
PROCEDURE (f: Model) NewReader* (old: Reader): Reader, NEW, ABSTRACT;
PROCEDURE (f: Model) NewWriter* (old: Writer): Writer, NEW, ABSTRACT;
PROCEDURE (f: Model) ViewAt* (x, y: INTEGER): Views.View, NEW, ABSTRACT;
PROCEDURE (f: Model) NofViews* (): INTEGER, NEW, ABSTRACT;
(** Directory **)
PROCEDURE (d: Directory) New* (): Model, NEW, ABSTRACT;
(** Context **)
PROCEDURE (c: Context) ThisModel* (): Model, ABSTRACT;
PROCEDURE (c: Context) GetRect* (OUT l, t, r, b: INTEGER), NEW, ABSTRACT;
(** Reader **)
PROCEDURE (rd: Reader) Set* (pos: Views.View), NEW, ABSTRACT;
(** (pos = NIL) OR (pos in r's form) 20 **)
PROCEDURE (rd: Reader) ReadView* (OUT v: Views.View), NEW, ABSTRACT;
(** Writer **)
PROCEDURE (wr: Writer) Set* (pos: Views.View), NEW, ABSTRACT;
(** (pos = NIL) OR (pos in w's form) 20 **)
PROCEDURE (wr: Writer) WriteView* (v: Views.View; l, t, r, b: INTEGER), NEW, ABSTRACT;
(**
v # NIL 20
v.init 21
v.context = NIL 22
l <= r 23
t <= b 24
**)
(* StdModel *)
PROCEDURE ThisContext (f: StdModel; view: Views.View): StdContext;
VAR c: StdContext;
BEGIN
c := f.contexts; WHILE (c # NIL) & (c.view # view) DO c := c.next END;
RETURN c
END ThisContext;
PROCEDURE NewContext (form: StdModel; view: Views.View; l, t, r, b: INTEGER): StdContext;
VAR c: StdContext;
BEGIN
ASSERT(form # NIL, 100); ASSERT(view.context = NIL, 101);
IF r - l < minViewSize THEN r := l + minViewSize END;
IF b - t < minViewSize THEN b := t + minViewSize END;
NEW(c); c.form := form; c.view := view; c.l := l; c.t := t; c.r := r; c.b := b;
Stores.Join(form, view);
view.InitContext(c);
RETURN c
END NewContext;
PROCEDURE InsertAbove (c, pos: StdContext);
BEGIN
IF pos = NIL THEN
c.next := NIL; c.form.contexts := c
ELSE
c.next := pos.next; pos.next := c
END
END InsertAbove;
PROCEDURE (f: StdModel) Internalize (VAR rd: Stores.Reader);
VAR thisVersion, l, t, r, b, x: INTEGER; top, h: StdContext; v: Views.View;
BEGIN
rd.ReadVersion(minVersion, maxStdVersion, thisVersion);
IF ~rd.cancelled THEN
rd.ReadVersion(0, 0, thisVersion); rd.ReadInt(x); (* backward compatibility with Rel. 1.3 *)
Views.ReadView(rd, v); top := NIL;
WHILE v # NIL DO
rd.ReadInt(l); rd.ReadInt(t); rd.ReadInt(r); rd.ReadInt(b);
h := NewContext(f, v, l, t, r, b);
InsertAbove(h, top); top := h;
Views.ReadView(rd, v)
END
END
END Internalize;
PROCEDURE (f: StdModel) Externalize (VAR wr: Stores.Writer);
VAR c: StdContext;
BEGIN
wr.WriteVersion(maxStdVersion);
wr.WriteVersion(0); wr.WriteInt(0); (* backward compatibility with Rel. 1.3 *)
c := f.contexts;
WHILE c # NIL DO
IF Stores.ExternalizeProxy(c.view) # NIL THEN
Views.WriteView(wr, c.view);
wr.WriteInt(c.l); wr.WriteInt(c.t);
wr.WriteInt(c.r); wr.WriteInt(c.b)
END;
c := c.next
END;
wr.WriteStore(NIL)
END Externalize;
PROCEDURE (f: StdModel) CopyFrom (source: Stores.Store);
VAR c, top, h: StdContext;
BEGIN
WITH source: StdModel DO
c := source.contexts; top := NIL;
WHILE c # NIL DO
h := NewContext(f, Views.CopyOf(c.view, Views.deep), c.l, c.t, c.r, c.b);
InsertAbove(h, top); top := h;
c := c.next
END
END
END CopyFrom;
PROCEDURE (f: StdModel) InitFrom (source: Containers.Model);
BEGIN
f.contexts := NIL
END InitFrom;
PROCEDURE (f: StdModel) ReplaceView (old, new: Views.View);
VAR op: ReplaceViewOp; c: StdContext;
BEGIN
c := ThisContext(f, old); ASSERT(c # NIL, 20);
ASSERT(new # NIL, 21); ASSERT((new.context = NIL) OR (new.context = c), 23);
IF old # new THEN
(* Stores.InitDomain(new, f.domain); *) Stores.Join(f, new);
new.InitContext(c); (* both views share same context *)
NEW(op); op.context := c; op.view := new;
Models.Do(f, "#System:ReplaceView", op)
END
END ReplaceView;
PROCEDURE (f: StdModel) Insert (v: Views.View; l, t, r, b: INTEGER);
VAR op: FormOp; c, h, top: StdContext;
BEGIN
ASSERT(v # NIL, 20); ASSERT(v.context = NIL, 22);
ASSERT(l <= r, 23); ASSERT(t <= b, 24);
h := f.contexts; top := NIL; WHILE h # NIL DO top := h; h := h.next END;
c := NewContext(f, v, l, t, r, b);
NEW(op); op.del := NIL; op.ins := c; op.pos := top;
Models.Do(f, "#System:Insertion", op)
END Insert;
PROCEDURE (f: StdModel) Delete (v: Views.View);
VAR op: FormOp; c: StdContext;
BEGIN
c := ThisContext(f, v); ASSERT(c # NIL, 20);
NEW(op); op.del := c; op.ins := NIL; op.pos := NIL;
Models.Do(f, "#System:Deletion", op)
END Delete;
PROCEDURE (f: StdModel) Resize (v: Views.View; l, t, r, b: INTEGER);
VAR op: ResizeOp; c: StdContext;
BEGIN
c := ThisContext(f, v); ASSERT(c # NIL, 20);
ASSERT(r >= l, 21); ASSERT(b >= t, 22);
IF r - l < minViewSize THEN r := l + minViewSize END;
IF b - t < minViewSize THEN b := t + minViewSize END;
NEW(op); op.context := c; op.l := l; op.t := t; op.r := r; op.b := b;
Models.Do(f, "#System:Resizing", op)
END Resize;
PROCEDURE (f: StdModel) Top (): Views.View;
VAR h, top: StdContext;
BEGIN
top := NIL; h := f.contexts;
WHILE h # NIL DO top := h; h := h.next END;
IF top # NIL THEN RETURN top.view ELSE RETURN NIL END
END Top;
PROCEDURE (f: StdModel) PutAbove (v, pos: Views.View);
VAR op: FormOp; c, d: StdContext;
BEGIN
c := ThisContext(f, v); ASSERT(c # NIL, 20);
d := ThisContext(f, pos); ASSERT((pos = NIL) OR (d # NIL), 21);
IF v # pos THEN
NEW(op); op.del := c; op.ins := c; op.pos := d;
Models.Do(f, "#Form:ChangeZOrder", op)
END
END PutAbove;
PROCEDURE (f: StdModel) Move (v: Views.View; dx, dy: INTEGER);
VAR op: ResizeOp; c: StdContext;
BEGIN
c := ThisContext(f, v); ASSERT(c # NIL, 20);
IF (dx # 0) OR (dy # 0) THEN
NEW(op); op.context := c;
op.l := c.l + dx; op.t := c.t + dy; op.r := c.r + dx; op.b := c.b + dy;
Models.Do(f, "#System:Moving", op)
END
END Move;
PROCEDURE (f: StdModel) Copy (VAR v: Views.View; dx, dy: INTEGER);
VAR op: FormOp; c, h, top: StdContext;
BEGIN
c := ThisContext(f, v); ASSERT(c # NIL, 20);
h := f.contexts; top := NIL; WHILE h # NIL DO top := h; h := h.next END;
h := NewContext(f, Views.CopyOf(v, Views.deep), c.l + dx, c.t + dy, c.r + dx, c.b + dy);
NEW(op); op.del := NIL; op.ins := h; op.pos := top;
Models.Do(f, "#System:Copying", op);
v := h.view
END Copy;
PROCEDURE (f: StdModel) NewReader (old: Reader): Reader;
VAR r: StdReader;
BEGIN
IF (old = NIL) OR ~(old IS StdReader) THEN NEW(r) ELSE r := old(StdReader) END;
r.view := NIL; r.l := 0; r.t := 0; r.r := 0; r.b := 0;
r.form := f; r.pos := NIL;
RETURN r
END NewReader;
PROCEDURE (f: StdModel) NewWriter (old: Writer): Writer;
VAR w: StdWriter;
BEGIN
IF (old = NIL) OR ~(old IS StdWriter) THEN NEW(w) ELSE w := old(StdWriter) END;
w.form := f; w.pos := NIL;
RETURN w
END NewWriter;
PROCEDURE (f: StdModel) ViewAt (x, y: INTEGER): Views.View;
VAR c, top: StdContext;
BEGIN
c := f.contexts; top := NIL;
WHILE c # NIL DO
IF (x >= c.l) & (y >= c.t) & (x < c.r) & (y < c.b) THEN top := c END;
c := c.next
END;
IF top = NIL THEN RETURN NIL ELSE RETURN top.view END
END ViewAt;
PROCEDURE (f: StdModel) NofViews (): INTEGER;
VAR c: StdContext; n: INTEGER;
BEGIN
n := 0; c := f.contexts; WHILE c # NIL DO INC(n); c := c.next END;
RETURN n
END NofViews;
(* StdContext *)
PROCEDURE (c: StdContext) ThisModel (): Model;
BEGIN
RETURN c.form
END ThisModel;
PROCEDURE (c: StdContext) GetSize (OUT w, h: INTEGER);
BEGIN
w := c.r - c.l; h := c.b - c.t
END GetSize;
PROCEDURE (c: StdContext) SetSize (w, h: INTEGER);
VAR w0, h0: INTEGER;
BEGIN
w0 := c.r - c.l; h0 := c.b - c.t; ASSERT(w0 > 0, 100); ASSERT(h0 > 0, 101);
Properties.PreferredSize(
c.view, minViewSize, maxViewSize, minViewSize, maxViewSize, w0, h0, w, h);
IF (w # w0) OR (h # h0) THEN
c.form.Resize(c.view, c.l, c.t, c.l + w, c.t + h)
END
END SetSize;
PROCEDURE (c: StdContext) Normalize (): BOOLEAN;
BEGIN
RETURN FALSE
END Normalize;
PROCEDURE (c: StdContext) GetRect (OUT l, t, r, b: INTEGER);
BEGIN
l := c.l; t := c.t; r := c.r; b := c.b
END GetRect;
(* StdDirectory *)
PROCEDURE (d: StdDirectory) New (): Model;
VAR f: StdModel;
BEGIN
NEW(f); RETURN f
END New;
(* StdReader *)
PROCEDURE (rd: StdReader) Set (pos: Views.View);
VAR c: StdContext;
BEGIN
IF pos = NIL THEN c := NIL ELSE c := ThisContext(rd.form, pos); ASSERT(c # NIL, 20) END;
rd.view := NIL; rd.l := 0; rd.t := 0; rd.r := 0; rd.b := 0;
rd.pos := c
END Set;
PROCEDURE (rd: StdReader) ReadView (OUT v: Views.View);
VAR c: StdContext;
BEGIN
c := rd.pos;
IF c = NIL THEN c := rd.form.contexts ELSE c := c.next END;
IF c # NIL THEN
rd.view := c.view; rd.l := c.l; rd.t := c.t; rd.r := c.r; rd.b := c.b;
rd.pos := c
ELSE
rd.view := NIL; rd.l := 0; rd.t := 0; rd.r := 0; rd.b := 0
END;
v := rd.view
END ReadView;
(* StdWriter *)
PROCEDURE (wr: StdWriter) Set (pos: Views.View);
VAR c: StdContext;
BEGIN
IF pos = NIL THEN c := NIL ELSE c := ThisContext(wr.form, pos); ASSERT(c # NIL, 20) END;
wr.pos := c
END Set;
PROCEDURE (wr: StdWriter) WriteView (v: Views.View; l, t, r, b: INTEGER);
VAR op: FormOp; c: StdContext;
BEGIN
ASSERT(v # NIL, 20); ASSERT(v.context = NIL, 22);
ASSERT(l <= r, 23); ASSERT(t <= b, 24);
c := NewContext(wr.form, v, l, t, r, b);
NEW(op); op.del := NIL; op.ins := c; op.pos := wr.pos;
wr.pos := c;
Models.Do(wr.form, "#System:Insertion", op)
END WriteView;
(* operations *)
PROCEDURE Update (c: StdContext);
VAR msg: UpdateMsg;
BEGIN
msg.l := c.l; msg.t := c.t; msg.r := c.r; msg.b := c.b; Models.Broadcast(c.form, msg)
END Update;
PROCEDURE (op: FormOp) Do;
VAR f: StdModel; c, p, pos: StdContext;
BEGIN
(* delete *)
pos := NIL;
c := op.del;
IF c # NIL THEN
f := c.form; ASSERT(f # NIL, 100);
p := f.contexts; ASSERT(p # NIL, 101);
IF p = c THEN
f.contexts := c.next
ELSE
WHILE p.next # c DO p := p.next; ASSERT(p # NIL, 102) END;
pos := p; p.next := c.next
END;
c.next := NIL;
Update(c)
END;
(* insert *)
c := op.ins;
IF c # NIL THEN
f := c.form; ASSERT(f # NIL, 103);
p := f.contexts;
IF op.pos = NIL THEN
c.next := f.contexts; f.contexts := c
ELSE
c.next := op.pos.next; op.pos.next := c
END;
Update(c)
END;
(* swap ins and del for undo *)
p := op.del; op.del := op.ins; op.ins := p; op.pos := pos
END Do;
PROCEDURE (op: ResizeOp) Do;
VAR c: StdContext; l, t, r, b: INTEGER;
BEGIN
c := op.context;
(* save old state of context *)
l := c.l; t := c.t; r := c.r; b := c.b;
Update(c);
(* set new state of context *)
c.l := op.l; c.t := op.t; c.r := op.r; c.b := op.b;
Update(c);
(* old state is new undo state *)
op.l := l; op.t := t; op.r := r; op.b := b
END Do;
PROCEDURE (op: ReplaceViewOp) Do;
VAR c: StdContext; view: Views.View;
BEGIN
c := op.context;
(* save old state of context *)
view := c.view;
(* set new state of context *)
c.view := op.view;
Update(c);
(* old state is new undo state *)
op.view := view
END Do;
(** miscellaneous **)
PROCEDURE New* (): Model;
BEGIN
RETURN dir.New()
END New;
PROCEDURE CloneOf* (source: Model): Model;
BEGIN
ASSERT(source # NIL, 20);
RETURN Containers.CloneOf(source)(Model)
END CloneOf;
PROCEDURE Copy* (source: Model): Model;
BEGIN
ASSERT(source # NIL, 20);
RETURN Stores.CopyOf(source)(Model)
END Copy;
PROCEDURE SetDir* (d: Directory);
(** d # NIL 20 **)
BEGIN
ASSERT(d # NIL, 20); dir := d
END SetDir;
PROCEDURE Init;
VAR d: StdDirectory;
BEGIN
NEW(d); dir := d; stdDir := d
END Init;
BEGIN
Init
END FormModels.
| Form/Mod/Models.odc |
MODULE FormViews;
(**
project = "BlackBox"
organization = "www.oberon.ch"
contributors = "Oberon microsystems"
version = "System/Rsrc/About"
copyright = "System/Rsrc/About"
license = "Docu/BB-License"
purpose = ""
changes = "
- YYYYMMDD, nn, ...
"
issues = "
- ...
"
**)
IMPORT Dialog, Ports, Stores, Models, Views, Controllers, Properties, Containers, FormModels;
CONST
(** minimal border between form view and any embedded view: **)
minBorder* = 4 * Ports.point; maxBorder* = 100 * Ports.mm;
maxSize = 600 * Ports.mm;
(* range of currently supported versions *)
minVersion = 0; maxBaseVersion = 2; maxStdVersion = 1;
TYPE
View* = POINTER TO ABSTRACT RECORD (Containers.View) END;
Directory* = POINTER TO ABSTRACT RECORD END;
StdView = POINTER TO RECORD (View)
border: INTEGER;
grid: INTEGER; (* grid > 0 *)
gridFactor: INTEGER; (* gridFactor > 0 *)
background: Ports.Color;
cache: FormModels.Reader (* reuse form reader *)
END;
StdDirectory = POINTER TO RECORD (Directory) END;
ViewOp = POINTER TO RECORD (Stores.Operation)
view: StdView; (* view # NIL *)
border: INTEGER; (* border >= minBorder *)
grid: INTEGER; (* grid > 0 *)
gridFactor: INTEGER; (* gridFactor > 0 *)
background: Ports.Color
END;
VAR
dir-, stdDir-: Directory;
ctrldir-: Containers.Directory;
(** View **)
PROCEDURE (v: View) Internalize2- (VAR rd: Stores.Reader), EXTENSIBLE;
VAR thisVersion: INTEGER;
BEGIN
IF ~rd.cancelled THEN
rd.ReadVersion(minVersion, maxBaseVersion, thisVersion);
IF~ rd.cancelled THEN
IF thisVersion IN {0, 1} THEN
WITH v: StdView DO (* backward compatibility with Rel. 1.3 *)
rd.ReadInt(v.border);
rd.ReadInt(v.grid);
rd.ReadXInt(v.gridFactor);
IF thisVersion = 1 THEN
rd.ReadInt(v.background)
ELSE
v.background := Ports.defaultColor
END
END
END
END
END
END Internalize2;
PROCEDURE (v: View) Externalize2- (VAR wr: Stores.Writer), EXTENSIBLE;
BEGIN
wr.WriteVersion(maxBaseVersion)
END Externalize2;
PROCEDURE (v: View) ThisModel* (): FormModels.Model, EXTENSIBLE;
VAR m: Containers.Model;
BEGIN
m := v.ThisModel^();
IF m = NIL THEN RETURN NIL ELSE RETURN m(FormModels.Model) END
END ThisModel;
PROCEDURE (v: View) SetBorder* (border: INTEGER), NEW, ABSTRACT;
(** border >= 0 20 **)
PROCEDURE (v: View) Border* (): INTEGER, NEW, ABSTRACT;
PROCEDURE (v: View) SetGrid* (grid, gridFactor: INTEGER), NEW, ABSTRACT;
(**
grid > 0 20
gridFactor > 0 21
**)
PROCEDURE (v: View) Grid* (): INTEGER, NEW, ABSTRACT;
PROCEDURE (v: View) GridFactor* (): INTEGER, NEW, ABSTRACT;
PROCEDURE (v: View) SetBackground* (background: Ports.Color), NEW, ABSTRACT;
(** Directory **)
PROCEDURE (d: Directory) New* (f: FormModels.Model): View, NEW, ABSTRACT;
(**
f # NIL 20
f.init 21
**)
(* ViewOp *)
PROCEDURE (op: ViewOp) Do;
VAR border, grid, gridFactor: INTEGER; background: Ports.Color;
BEGIN
(* save old state of view *)
border := op.view.border; grid := op.view.grid; gridFactor := op.view.gridFactor;
background := op.view.background;
(* set new state of view *)
op.view.border := op.border; op.view.grid := op.grid; op.view.gridFactor := op.gridFactor;
op.view.background := op.background;
Views.Update(op.view, Views.keepFrames);
(* old state is new undo state *)
op.border := border; op.grid := grid; op.gridFactor := gridFactor;
op.background := background
END Do;
(* StdView *)
PROCEDURE (v: StdView) Internalize2 (VAR rd: Stores.Reader);
VAR thisVersion: INTEGER;
BEGIN
v.Internalize2^(rd);
IF ~rd.cancelled THEN
rd.ReadVersion(minVersion, maxStdVersion, thisVersion);
IF thisVersion # 0 THEN
rd.ReadInt(v.border);
rd.ReadInt(v.grid);
rd.ReadInt(v.gridFactor);
rd.ReadInt(v.background)
END
END
END Internalize2;
PROCEDURE (v: StdView) Externalize2 (VAR wr: Stores.Writer);
BEGIN
v.Externalize2^(wr);
wr.WriteVersion(maxStdVersion);
wr.WriteInt(v.border);
wr.WriteInt(v.grid);
wr.WriteInt(v.gridFactor);
wr.WriteInt(v.background)
END Externalize2;
PROCEDURE (v: StdView) CopyFromModelView2 (source: Views.View; model: Models.Model);
BEGIN
WITH source: StdView DO
v.border := source.border;
v.grid := source.grid;
v.gridFactor := source.gridFactor;
v.background := source.background
END
END CopyFromModelView2;
PROCEDURE (d: StdView) AcceptableModel (m: Containers.Model): BOOLEAN;
BEGIN
RETURN m IS FormModels.Model
END AcceptableModel;
PROCEDURE (v: StdView) InitModel2 (m: Containers.Model);
BEGIN
ASSERT(m IS FormModels.Model, 23)
END InitModel2;
PROCEDURE (v: StdView) GetRect (f: Views.Frame; view: Views.View; OUT l, t, r, b: INTEGER);
BEGIN
view.context(FormModels.Context).GetRect(l, t, r, b)
END GetRect;
PROCEDURE (v: StdView) SetBorder (border: INTEGER);
VAR op: ViewOp;
BEGIN
ASSERT(border >= 0, 20);
IF border < minBorder THEN
border := minBorder
ELSIF border > maxBorder THEN
border := maxBorder
END;
NEW(op); op.view := v; op.border := border;
op.grid := v.grid; op.gridFactor := v.gridFactor;
op.background := v.background;
Views.Do(v, "#Form:BorderChange", op)
END SetBorder;
PROCEDURE (v: StdView) Border (): INTEGER;
BEGIN
RETURN v.border
END Border;
PROCEDURE (v: StdView) SetGrid (grid, gridFactor: INTEGER);
VAR op: ViewOp;
BEGIN
ASSERT(grid > 0, 20); ASSERT(gridFactor > 0, 21);
NEW(op); op.view := v; op.border := v.border;
op.grid := grid; op.gridFactor := gridFactor;
op.background := v.background;
Views.Do(v, "#Form:GridChange", op)
END SetGrid;
PROCEDURE (v: StdView) Grid (): INTEGER;
BEGIN
RETURN v.grid
END Grid;
PROCEDURE (v: StdView) GridFactor (): INTEGER;
BEGIN
RETURN v.gridFactor
END GridFactor;
PROCEDURE (v: StdView) SetBackground (background: Ports.Color);
VAR op: ViewOp;
BEGIN
NEW(op); op.view := v; op.border := v.border;
op.grid := v.grid; op.gridFactor := v.gridFactor;
op.background := background;
Views.Do(v, "#Form:BackgroundChange", op)
END SetBackground;
PROCEDURE (v: StdView) GetBackground (VAR color: Ports.Color);
BEGIN
IF v.background = Ports.defaultColor THEN
color := Ports.dialogBackground
ELSE
color := v.background
END
END GetBackground;
PROCEDURE (v: StdView) Restore (f: Views.Frame; l, t, r, b: INTEGER);
VAR form: FormModels.Model; ctrl: Containers.Controller;
focus, q: Views.View; k, w, h, x, y: INTEGER; s: FormModels.Reader;
BEGIN
form := v.ThisModel();
IF form # NIL THEN
ctrl := v.ThisController();
IF ctrl # NIL THEN focus := ctrl.ThisFocus() ELSE focus := NIL END;
s := form.NewReader(v.cache); v.cache := s;
s.Set(NIL); s.ReadView(q); k := 0;
WHILE q # NIL DO
IF (s.r >= l) & (s.b >= t) & (s.l < r) & (s.t < b) THEN
Views.InstallFrame(f, q, s.l, s.t, k, q = focus)
END;
s.ReadView(q); INC(k)
END
ELSE
f.DrawRect(l, t, r, b, Ports.fill, Ports.grey12)
END;
IF (ctrl # NIL) & ~(Containers.noCaret IN ctrl.opts) THEN
k := v.grid * v.gridFactor; ASSERT(k > 0, 100);
v.context.GetSize(w, h);
IF w > maxSize THEN w := maxSize END;
IF h > maxSize THEN h := maxSize END;
x := l - l MOD k;
WHILE x <= w DO
f.MarkRect(x, 0, x + f.unit, h, Ports.fill, Ports.dim50, Ports.show);
INC(x, k)
END;
y := t - t MOD k;
WHILE y <= h DO
f.MarkRect(0, y, w, y + f.unit, Ports.fill, Ports.dim50, Ports.show);
INC(y, k)
END
END
END Restore;
PROCEDURE (v: StdView) HandleModelMsg2 (VAR msg: Models.Message);
BEGIN
WITH msg: Models.UpdateMsg DO
WITH msg: FormModels.UpdateMsg DO
Views.UpdateIn(v, msg.l, msg.t, msg.r, msg.b, Views.rebuildFrames)
ELSE
Views.Update(v, Views.rebuildFrames) (* catch all update messages *)
END
ELSE
END
END HandleModelMsg2;
PROCEDURE GetBounds (v: StdView; VAR w, h: INTEGER);
VAR form: FormModels.Model; r, b: INTEGER; p: FormModels.Reader; q: Views.View;
BEGIN
form := v.ThisModel();
IF form # NIL THEN
p := form.NewReader(v.cache); v.cache := p;
p.Set(NIL); (* set reader to bottom of view list *)
p.ReadView(q); (* read bottom-most view *)
IF q # NIL THEN
r := 0; b := 0;
WHILE q # NIL DO
IF p.r > r THEN r := p.r END;
IF p.b > b THEN b := p.b END;
p.ReadView(q)
END;
w := r + v.border; h := b + v.border
ELSE
w := 0; h := 0
END
ELSE
w := 0; h := 0
END
END GetBounds;
PROCEDURE AssertRange (border: INTEGER; VAR w, h: INTEGER);
VAR min: INTEGER;
BEGIN (* prevent illegal values *)
min := 2 * border + FormModels.minViewSize;
IF w = Views.undefined THEN w := 100 * Ports.mm
ELSIF w < min THEN w := min
ELSIF w > maxSize THEN w := maxSize
END;
IF h = Views.undefined THEN h := 70 * Ports.mm
ELSIF h < min THEN h := min
ELSIF h > maxSize THEN h := maxSize
END
END AssertRange;
PROCEDURE (v: StdView) HandlePropMsg2 (VAR p: Properties.Message);
VAR sp: Properties.StdProp; q: Properties.Property;
BEGIN
WITH p: Properties.BoundsPref DO
GetBounds(v, p.w, p.h)
| p: Properties.SizePref DO
AssertRange(v.border, p.w, p.h)
| p: Properties.PollMsg DO
NEW(sp); sp.valid := {Properties.color}; sp.known := sp.valid;
sp.color.val := v.background; p.prop := sp
| p: Properties.SetMsg DO
q := p.prop;
WHILE q # NIL DO
WITH q: Properties.StdProp DO
IF (Properties.color IN q.valid) & (q.color.val # v.background) THEN
v.SetBackground(q.color.val)
END;
ELSE
END;
q :=q.next
END
| p: Containers.DropPref DO
p.okToDrop := TRUE
ELSE
END
END HandlePropMsg2;
(* StdDirectory *)
PROCEDURE (d: StdDirectory) New (f: FormModels.Model): View;
VAR v: StdView; grid, gridFactor: INTEGER;
BEGIN
ASSERT(f # NIL, 20);
NEW(v); v.InitModel(f);
IF ctrldir # NIL THEN v.SetController(ctrldir.New()) END;
v.SetBorder(minBorder);
IF Dialog.metricSystem THEN
grid := 2 * Ports.mm; gridFactor := 5 (* place at 2 mm resolution *)
ELSE
grid := Ports.inch DIV 16; gridFactor := 8 (* place at 1/16 inch resolution *)
END;
v.SetGrid(grid, gridFactor);
v.background := Ports.defaultColor;
RETURN v
END New;
(** miscellaneous **)
PROCEDURE Focus* (): View;
VAR v: Views.View;
BEGIN
v := Controllers.FocusView();
IF (v # NIL) & (v IS View) THEN RETURN v(View) ELSE RETURN NIL END
END Focus;
PROCEDURE FocusModel* (): FormModels.Model;
VAR v: View;
BEGIN
v := Focus();
IF v # NIL THEN RETURN v.ThisModel() ELSE RETURN NIL END
END FocusModel;
PROCEDURE RoundToGrid* (v: View; VAR x, y: INTEGER);
VAR grid: INTEGER;
BEGIN
grid := v.Grid();
x := x + grid DIV 2;
y := y + grid DIV 2;
x := x - x MOD grid;
y := y - y MOD grid
END RoundToGrid;
PROCEDURE New* (): View;
BEGIN
RETURN dir.New(FormModels.dir.New())
END New;
PROCEDURE Deposit*;
BEGIN
Views.Deposit(New())
END Deposit;
PROCEDURE SetDir* (d: Directory);
BEGIN
ASSERT(d # NIL, 20); dir := d
END SetDir;
PROCEDURE SetCtrlDir* (d: Containers.Directory);
BEGIN
ASSERT(d # NIL, 20); ctrldir := d
END SetCtrlDir;
PROCEDURE Init;
VAR d: StdDirectory; res: INTEGER;
BEGIN
Dialog.Call("FormControllers.Install", "#Form:CntrlInstallFailed", res);
NEW(d); dir := d; stdDir := d
END Init;
BEGIN
Init
END FormViews.
| Form/Mod/Views.odc |
Form/Rsrc/Cmds.odc |
|
Form/Rsrc/Cmds2.odc |
|
Form/Rsrc/Gen.odc |
|
MENU "#Form:&Layout" ("FormViews.View")
"#Form:&Align Left" "" "FormCmds.AlignLeft" "FormCmds.SelectionGuard"
"#Form:&Align Right" "" "FormCmds.AlignRight" "FormCmds.SelectionGuard"
"#Form:&Align Top" "" "FormCmds.AlignTop" "FormCmds.SelectionGuard"
"#Form:&Align Bottom" "" "FormCmds.AlignBottom" "FormCmds.SelectionGuard"
"#Form:&Align To Row" "" "FormCmds.AlignToRow" "FormCmds.SelectionGuard"
"#Form:&Align To Column" "" "FormCmds.AlignToColumn" "FormCmds.SelectionGuard"
SEPARATOR
"#Form:&Set Grid..." "" "FormCmds.InitGridDialog; StdCmds.OpenToolDialog('Form/Rsrc/Cmds', '#Form:Set Grid')"
"FormCmds.FocusGuard"
"#Form:&Select Off-Grid Views" "" "FormCmds.SelectOffGridViews" ""
"#Form:&Force To Grid" "" "FormCmds.ForceToGrid" "FormCmds.SelectionGuard"
SEPARATOR
"#Form:&Set First/Back" "" "FormCmds.SetAsFirst" "FormCmds.SingletonGuard"
"#Form:&Set Last/Front" "F5" "FormCmds.SetAsLast" "FormCmds.SingletonGuard"
"#Form:&Sort Views" "" "FormCmds.SortViews" ""
SEPARATOR
"#Form:&Replace..." "" "StdCmds.OpenToolDialog('Form/Rsrc/Cmds2', '#Form:Replace Strings in Control Fields')"
"StdCmds.ContainerGuard"
SEPARATOR
"#Form:&Recalc Focus Size" "" "StdCmds.RecalcFocusSize" ""
END
| Form/Rsrc/Menus.odc |
STRINGS
&Layout Layout
&Align Left Align &Left
&Align Right Align &Right
&Align Top Align &Top
&Align Bottom Align &Bottom
&Align To Row Align To Ro&w
&Align To Column Align To &Column
&Set Grid... Set &Grid...
&Select Off-Grid Views &Select Off-Grid Views
&Force To Grid &Force To Grid
&Set First/Back Set F&irst/Back
&Set Last/Front Set L&ast/Front
&Sort Views Sort &Views
&Replace... Replace...
&Recalc Focus Size R&ecalc Focus Size
mm &mm
1/16 &inch 1/16 &inch
Empty &Empty
Guard Field Guard Field
Link: &Link:
Label Field Label Field
Link Field Link Field
Notifier Field Notifier Field
Set Set
Set Grid Set Grid
Replace: Replace:
Replace All Replace &All
Replace Strings in Control Fields Replace Strings in Control Fields
Resolution: &Resolution:
with: with:
in: in:
AlignBottom Align Bottom
AlignHorizontal Align Horizontal
AlignLeft Align Left
AlignRight Align Right
AlignTop Align Top
AlignVertical Align Vertical
BorderChange Border Change
ChangeZOrder Change Z Order
CntrlInstallFailed form controller installation failed
ForceToGrid Force to Grid
Globals Globals
GridChange Grid Change
InsertAround Insert Around
ModuleNotFound module ^0 not found
SetEnabled Set Enabled
SetName Set Name
VariableNoRecord variable ^0 is not a record or NIL pointer
VariableNotFound variable ^0 not found
VariableNotFoundIn variable ^0 not found in ^1
FormViews.StdViewDesc standard Form view
FormModels.StdModelDesc standard Form model
FormControllers.StdControllerDesc standard Form controller
| Form/Rsrc/Strings.odc |
Helpdesk's Adviser (Ratgeber fr Benutzerservice)
Helmut Zinn, IG Metall, Frankfurt am Main, Germany
The Helpdesk Adviser is a collection of tools to support the work at a help desk. Many questions come up repeatedly and therefore we collect questions and answeres and organize them by creating a subdirectory for every group of problem.
There are two possibilities to open a document in BlackBox: 1st in browser mode (StdCmds.OpenBrowser) and 2nd in edit mode (StdCmds.OpenDoc). We need both to edit and view documents respectively. When following links, the new document should be opened in the same mode as the current one is in. Therefore, a simple
extension was easily defined and quickly programmed: the new command InfoCmds.OpenDoc.
The Helpdesk Adviser was copied to our department server. As the adviser grows, it becomes more and more cumbersome to copy all documents to the server every day. Hence, we created a BlackBox program called Update, which can compare two directory trees and list all the files that were changed, added, or deleted.
Based on this list, we can run an update to copy exactly new files and those that were changed. Old files, no longer existing in the original, are deleted.
Recently, a cross-reference builder, a search module, and a check link module have been added.
Now we are working on a HTML importer and exporter. All tags that are not translated are in a tag view. The tag views can be created, expanded, collapsed, shown and hidden.
The Helpdesk Adviser is in use since October 1996. Today (5th September 2000) it manages about 1700 documents.
| Info/Docu/Abstract.odc |
Control Commands in Windows 7
To open… (Menpunkt) Run Commands…
On Screen Keyboard (Bildschirmtastatur) "InfoCmds.Start('osk')"
Character Map (Zeichentabelle) "InfoCmds.Start('charmap')"
Windows Magnifier (Bildschirmlupe) "InfoCmds.Start('magnify')"
Private Character Editor "InfoCmds.Start('eudcedit')"
Calculator "InfoCmds.Start('calc')"
System Information "InfoCmds.Start('msinfo32')"
System Configuration Utility "InfoCmds.Start('msconfig')"
Direct X Troubleshooter "InfoCmds.Start('dxdiag')"
Quicktime "InfoCmds.Start('QuickTime.cpl')"
Flash Player "InfoCmds.Start('FlashPlayerCPLApp.cpl')"
SQL Client Configuration "InfoCmds.Start('cliconfg')"
ODBC Data Source Administrator "InfoCmds.Start('odbcad32')"
Component Services "InfoCmds.Start('dcomcnfg')"
Task Manager "InfoCmds.Start('taskmgr')"
Logs You Out Of Windows "InfoCmds.Start('logoff')"
Shuts Down Windows "InfoCmds.Start('shutdown')"
Systemsteuerung
Control Panel "InfoCmds.Start2('control')"
Display Properties "InfoCmds.Start2('control desktop')"
... Auflsung "InfoCmds.Start2('control desk.cpl')"
... DPI Scaling "InfoCmds.Start('dpiscaling')"
... with Appearance Tab Preselected "InfoCmds.Start2('control color')"
... Color Management "InfoCmds.Start('colorcpl')"
Automatische Updates "InfoCmds.Start2('control wuaucpl.cpl')"
Benutzerkonten "InfoCmds.Start2('control nusrmgr.cpl')"
??? "InfoCmds.Start2('control collab.cpl')"
Blootooth-Konfiguration "InfoCmds.Start2('control bthprops.cpl')"
Datenquellen (ODBC) "InfoCmds.Start2('control odbccp32.cpl')"
Date and Time Properties "InfoCmds.Start2('control timedate.cpl')"
Drahtlose Verbindung "InfoCmds.Start2('control irprops.cpl')"
Drahtlose Verbindung "InfoCmds.Start2('control infrared')"
Printers and Faxes "InfoCmds.Start2('control printers')"
Accessibility Options (Eingabehilfe) "InfoCmds.Start2('control access.cpl')"
Power Configuration (Energieoptionen) "InfoCmds.Start2('control powercfg.cpl')"
Game Controllers "InfoCmds.Start2('control joy.cpl')"
Scheduled Tasks "InfoCmds.Start2('control schedtasks')"
Grafikcontoller "InfoCmds.Start2('control igfxcpl.cpl')"
Add Hardware Wizard "InfoCmds.Start2('control hdwwiz.cpl')"
Internet Properties "InfoCmds.Start2('control inetcpl.cpl')"
Mail "InfoCmds.Start2('control MLCFG32.CPL')"
Mouse Properties "InfoCmds.Start2('control main.cpl')"
Mouse Properties "InfoCmds.Start2('control mouse')"
Touchpad Properties "InfoCmds.Start2('control TabletPC.cpl')"
Netzwerkinstallationsassistent "InfoCmds.Start2('control netsetup.cpl')"
Network Connections "InfoCmds.Start2('control ncpa.cpl')"
Network Connections "InfoCmds.Start2('control netconnections')"
Folders Optionen "InfoCmds.Start2('control folders')"
User Password "InfoCmds.Start2('control userpasswords')"
QuickTime "InfoCmds.Start2('control QuickTime.cpl')"
Regional Settings "InfoCmds.Start2('control intl.cpl')"
Regions- und Sprachoptionen "InfoCmds.Start2('control international')"
Scanner und Kameras "InfoCmds.Start2('control sticpl.cpl')"
Scanner und Kameras "InfoCmds.Start2('control scannercamera')"
Fonts Folder "InfoCmds.Start2('control fonts')"
Windows Security Center "InfoCmds.Start2('control wscui.cpl')"
Add or Remove Programs "InfoCmds.Start2('control appwiz.cpl')"
... Windows Components "InfoCmds.Start2('control appwiz.cpl,,2')"
... Program Access & Defaults "InfoCmds.Start2('control appwiz.cpl,,3')"
Sounds and Audio Properties "InfoCmds.Start2('control mmsys.cpl')"
Sprachein-/ausgabe "InfoCmds.Start2('control speech')"
System Properties "InfoCmds.Start2('control sysdm.cpl')"
Tablet- und Schrifteinstellungen "InfoCmds.Start2('control tabletpc.cpl')"
Keyboard Properties "InfoCmds.Start2('control keyboard')"
Keyboard Properties "InfoCmds.Start2('control main.cpl @1')"
Phone and Modem Options "InfoCmds.Start2('control telephon.cpl')"
Phone Dialer "InfoCmds.Start('dialer')"
Remote Access Phonebook "InfoCmds.Start('rasphone')"
Administrative Tools (Verwaltung) "InfoCmds.Start2('control admintools')"
VirusScan "InfoCmds.Start2('control Avsmcpa.cpl')"
Windows Firewall "InfoCmds.Start2('control firewall.cpl')"
Firewall Control Panel "InfoCmds.Start2('FirewallControlPanel')"
Firewall Settings "InfoCmds.Start2('FirewallSettings')"
Windows Firewall with Advanced Security "InfoCmds.Start2('wf.msc')"
Verwalten (MMC)
Computer Management "InfoCmds.Start('compmgmt.msc')"
Users and Groups "InfoCmds.Start('lusrmgr.msc')"
Disk Management (Datentrgerverwaltung) "InfoCmds.Start('diskmgmt.msc')"
Defragmentierung "InfoCmds.Start('dfrg.msc')"
Services (Dienste) "InfoCmds.Start('services.msc')"
Event Viewer (Ereignisanzeige) "InfoCmds.Start('eventvwr.msc')"
Faxdienstverwaltung "InfoCmds.Start('faxserv.msc')"
Shared Folders (Freigegebene Ordner) "InfoCmds.Start('fsmgmt.msc')"
Device Manager (Gertemanager) "InfoCmds.Start('devmgmt.msc')"
Group Policy Editor (Gruppenrichtlinien) "InfoCmds.Start('gpedit.msc')"
Indexdienst "InfoCmds.Start('ciadv.msc')"
Internetauthentifizierungsdienst "InfoCmds.Start('ias.msc')"
Komponentendienste "InfoCmds.Start('comexp.msc')"
Performance Monitor "InfoCmds.Start('perfmon.msc')"
Printer Management "InfoCmds.Start('printmanagement.msc')"
Policy (Richtlinien) "InfoCmds.Start('rsop.msc')"
Security Settings "InfoCmds.Start('secpol.msc')"
Wechselmedien "InfoCmds.Start('ntmsmgr.msc')"
Windows Management Infrastructure "InfoCmds.Start('wmimgmt.msc')"
Certificate Manager "InfoCmds.Start('certmgr.msc')"
Office & Windows
Back up or Restore your stored ...
... User Names and Passwords "InfoCmds.Start('credwiz')"
Backup Status and Utility "InfoCmds.Start('sdclt')"
Windows System Security Tool "InfoCmds.Start('syskey')"
System Recovery "InfoCmds.Start('rstrui')"
Command Prompt "InfoCmds.Start('cmd')"
Disk Cleanup Utility "InfoCmds.Start('cleanmgr')"
Driver Verifier Utility "InfoCmds.Start('verifier')"
File Signature Verification Tool "InfoCmds.Start('sigverif')"
Microsoft Malicious Software Removal Tool "InfoCmds.Start('mrt')"
Registry Editor "InfoCmds.Start('regedit')"
Microsoft Access "InfoCmds.Start('msaccess')"
Microsoft Excel "InfoCmds.Start('excel')"
Microsoft Frontpage "InfoCmds.Start('frontpg')"
Microsoft Movie Maker "InfoCmds.Start('moviemk')"
Microsoft Paint "InfoCmds.Start('mspaint')"
Microsoft Powerpoint "InfoCmds.Start('powerpnt')"
Microsoft Word "InfoCmds.Start('winword')"
Picture from Camera or Scanner "InfoCmds.Start('wiaacmgr')"
Remote Desktop "InfoCmds.Start('mstsc')"
Remote Assistance "InfoCmds.Start('msra')"
Shared Creation Wizard "InfoCmds.Start('shrpubw')"
Syncronization Center "InfoCmds.Start('mobsync')"
Windows Mobility Center "InfoCmds.Start('mblctr')"
Software Licensing (Windows Activation) "InfoCmds.Start('slui')"
Sound Recorder "InfoCmds.Start('soundrecorder')"
Sound Volume "InfoCmds.Start('sndvol')"
System Properties
... Advanced tab preselected "InfoCmds.Start('SystemPropertiesAdvanced')"
... Computer Name tab preselected "InfoCmds.Start('SystemPropertiesComputerName')"
... Data Execution Prevention preselected "InfoCmds.Start('SystemPropertiesDataExecutionPrevention')"
... Hardware options preselected "InfoCmds.Start('SystemPropertiesHardware')"
... Performance options preselected "InfoCmds.Start('SystemPropertiesPerformance')"
... Protection options preselected "InfoCmds.Start('SystemPropertiesProtection')"
... Remote options preselected "InfoCmds.Start('SystemPropertiesRemote')"
Trusted Platform Module Initialization Wizard "InfoCmds.Start('TpmInit')"
Notepad "InfoCmds.Start('notepad')"
Paint "InfoCmds.Start('pbrush')"
WordPad "InfoCmds.Start('write')"
Windows Address Book (Contacts) "InfoCmds.Start('wab')"
Windows Address Book Import Utility "InfoCmds.Start('wabmig')"
Windows Media Player "InfoCmds.Start('wmplayer')"
Windows Update "InfoCmds.Start('wuapp')"
Windows Update Standalone Installer "InfoCmds.Start('wusa')"
Windows Version "InfoCmds.Start('winver')"
Ende.
| Info/Docu/Control-Commands.odc |
The Helpdesk's Adviser
Basically I use the subsystem Info for my Helpdesk's Adviser. First read the Abstract of my speaking from the BlackBox Developer Meeting on 5th September 2000. It gives you an good overview about this tool.
Then look at the PowerPoint slides online at http://www.zinnamturm.eu/doc/Helpdesk.pps (441 kByte). Save this slides at Info/Docu/Helpdesk.pps.
Now you can read the PowerPoint slidesoffline and some notes to it. Further I used the subsystems Desktop, Dos and Html with Helpdesk's Adviser.
Little German => English Dictionary:
Benutzerservice => Helpdesk
Ratgeber => Adviser
Stichwortverzeichnis => cross reference list
Uhl => users help line
All source code for the helpdesk's adviser program are available here. The data documents are not included. So all files
in the directories and their access via menus
Help/... [Infodesk][Helpdesk]
Help/Infodesk/... [Infodesk][Infodesk]
Help/Uhl/... [Infodesk][Uhl]
Help/Additional/Homepage/... [Infodesk][Component Pascal Collections]
are missing. The reasons are:
- most of the documents are in German
- the documents are company specific and of no interest of anybody else outside.
- some documents are company confidential
- other environment (helpdesk) other problems.
Everybody can use my programs and create their own helpdesk by collecting problems and solutions. Every problem with its solution is just one odc document. All this documents linked together via InfoCmds.OpenDoc.
Maybe you would like to adapt the Menus to your own needs and then "StdMenuTool.UpdateAllMenus"
| Info/Docu/Helpdesk.odc |
BlackBox Developers Meeting - Helpdesk's Adviser
Slide 1: Helpdesk's Adviser
The Helpdesk Adviser is a collection of tools to support the work at the helpdesk.
Chapter 1. Question and answer
Slide 2: 1.1 The Starting Point
...
The solutions are in the head of the staff. Not everybody knows everything.
The one who knows isn't available right now and we won't reinvent the wheel.
Slide 3: 1.2 The Collections
The first step is we collect the solutions.
...
Slide 4: 1.3 And the Folder Structure
I call the main folder 'Uhl' (Users Help Line). There is a directory for every topic.
Every directory has a lot of documents. The structure of the document is:
Headline
The description of the Problem
The solution
The date of last change at the bottom line.
Slide 5: 1.4 The Starting Page
And this is the starting page. All topics found in the starting page.
This page grows with the adviser. It didn't look like this at the beginning.
Every topic is a link to a document which containing a list of contents.
Every entry in the list of contents is a link to a document.
Slide 6: 1.5 The Tools
We need BlackBox and 4 subsystems: Info, Desktop, Dos & Html.
To really getting started we need the module InfoCmds only.
The subsystem Dos used for updating.
The other Info modules used for searching
And the last Subsystem Html is optional.
Chapter 2. How to organize it?
Slide 7: 2.1 Links
...
I would like to propagate the state of document through the link.
If the document is in browser mode, the link should open the next document in browser mode.
If the document is in edit mode, the link should open the document in edit mode.
Slide 8: 2.2 Specification of InfoCmds
I build my own command InfoCmds.OpenDoc which open a document in browser or edit mode depending
on the global Boolean variable. This command is using in the same way as StdCmds.OpenDoc.
Slide 9: 2.3 Implementation of InfoCmds
The first implentation is very easy.
Slide 10: 2.4 The Local Network
The master pc used for developing the program, used for insert new document and used for maintenance
the old documents. The server has all documents, which are free to used. The users have access to the
documents via his/her workstations.
At the beginning some years ago there was an Alpha Server. Today it is an NT-Server. The server just
works as a file share and provide the access. The program is running on the PC.
The document can be changed on the maste PC or on the server. We need a tool for replication. More about this tool in the next chapter.
Slide 11: 2.5 Installations
On the server we install the BlackBox without the development subsystem. We add the Info subsystem
and the Uhl folders. The starting module is changing to opens the starting page automatically.
The workstation needs only a shortcut to the program BlackBox.exe at the server. The program is running
on the workstation. The helpdesk adviser is used in browser mode.
On the master pc I install the BlackBox including the development subsystem, the Info Subsystem and the
Uhl folders. Additionally a persistent desktop program is installed. At the start of Blackbox it opens all documents, we worked on at the last session.
Chapter 3. Solution changes and updates.
Slide 12: 3.1 The World is always Changing
As I told earlier the data must be synchronize between master PC and the server. We implement a
replication into 2 steps: The first step compares the folders and list all difference in a document and the second step run through that document and updates the change.
The reason is: Between step 1 & 2 we can proof the change and desire if we update or not.
Slide 13: 3.2 The Update Program
Here is the user interface of update program.
Quick Compare: takes care of file length and file date only.
Not Quick Compare: compares contents of the files byte by byte.
Short List: Only directories compared which on both side exist.
Long List: All directories compared.
Slide 14: 3.3 Sample Output of Compare
Here is a sample output of compare. It is a normal BlackBox document...
Based on this list, we can run an update to copy exactly new files and those that were changed. Old files,
no longer existing in the original, are deleted.
Slide 15: 3.4 Sign and switches
This slide shows the definition of sign and the behaviour of the switches.
Slide 16: 3.5 The Rules of Updating
These rules are looking quite complicated, but they are easy. They descript how the program works.
Chapter 4. Where are the documents?
Slide 17: 4.1 Build a cross-reference list
Normally we can find a document through the list of topics and then through the list of contents. But what
can we do if I have a keyword only? Every book has an index. The helpdesk adviser should have one too.
I divide the cross-reference program into two modules: InfoCrossRef builds the list and InfoIndex uses it.
Of course it is a linked list.
Slide 18: 4.2 What Is a Word?
This was the most difficult question for programming the cross-reference list.
Slide 19: 4.3 Search thru all documents
I would like to point out that the BlackBox command "Search In Docu" is not suitable for this task. But it is
very good template to write a search command for our helpdesk adviser.
Slide 20: 4.4 Is every document reachable?
Sometimes things go wrong. We put in a new document and we never find it again. So we have to look
thru an other way.
Chapter 5. Html-Converter
Slide 21: 5.1 Html import and export
The helpdesk's adviser is in use internally by the staff. The next step is provide access via the intranet. Is it possible to translate them automatically to html? Yes it is. We wrote an converter, which can translate the documents.
Slide 22: 5.2 Link fix
After we wrote a program, which translate all odc documents to html documents and vice versa. I realised
that there is a different approach for relative link.
Slide 23: 5.3 Tag views
On the left side we see the structure of a html document. On the right side there is an example how tags
handle in BlackBox documents. All tags that are not translated are in a tag view. The tag views can be
created, expanded, collapsed, shown and hidden.
Slide 24: 5.4 What Is Missing
It works. It is useful, but it has its limitations. With this slide we look forward. What can be added next the Xhmtl subsystem? This is a short list of wishes and open questions. Lets have a dream.
x There are no tabulators in html. Should tabulators translate to tables?
x Tables translation in both direction are not handle yet.
x Images and graphics too.
And so on.
Average diskspace of one document:
in BlackBox (.odc) 4 kByte
in BlackBox converted to html 5 kByte
in MS Word (.odc) 22 kByte
in MS Word converted to html 13 kByte
Slide 25: The End
Now I am at the end of my speaking. I hope: You are now ready to quench the fire. You have look over the
wall. You enjoy it. And you know the way: How it is going on.
The end.
| Info/Docu/Notes.odc |
Info Quick-Start
Copyright 2000-2022, by HelmutZinn
Version 24-July-2023
This program is free software; you can redistribute it and/or modify it under the terms of the "BlackBox Component Builder Open Source License".
Saved from 'Component Pascal Collection' url http://www.zinnamturm.eu
Check, collect, link, replace & search all documents
The Info subsystem is a collection of tools to manage links and documents. It supports the following tasks:
● Open a document in the same mode (browser or edit) as the current one
● Start a program via link
● Translate a website
● Search through all documents
● Create link list (table of contents)
● Collect the documents
● Correct text & links via change list
● Build Cross-reference (subject index)
● Check filenames
● Check links
● Replace in all documents
If you insert the following link in a odc document
<InfoCmds.Start('http://www.oberon.ch')>OberonMicrosystems<>
then you have a link to the website of ...
If you insert the following link in a odc document
<InfoCmds.Start('mailto:[email protected]')>mailto:[email protected]<>
then you can send a mail to ...
Another application of this subsystem is to translate a website. Select an url in your text document (e.g.: http://www.oberoncore.ru) and press the key Shift+Ctrl+L simultaneously. You get the translation of the oberonecore website from Russian to English.
Contents:
1 Installation
2 Howtouseit?
3 Changelog
4 Reference
1 Installation Up
1. Preconditions.
Check that you have installed the Pac subsystem.
Check that you have installed the Ctls subsystem.
Check that you have installed the TboxTimer subsystem.
Check that you have installed the Dos subsystem.
2. Unpack all files via Tools -> Decode.
List of contents:
Info/Docu/Quick-Start.odc
Info/Docu/Abstract.odc
Info/Docu/Control-Commands.odc
Info/Docu/Helpdesk.odc
Info/Docu/Notes.odc
Info/Docu/Shell-Commands.odc
Info/Mod/Catalog.odc
Info/Mod/CheckFilenames.odc
Info/Mod/CheckLinks.odc
Info/Mod/Cmds.odc
Info/Mod/Collect.odc
Info/Mod/Dialog.odc
Info/Mod/ForEachEntry.odc
Info/Mod/ForEachFile.odc
Info/Mod/Index.odc
Info/Mod/Links.odc
Info/Mod/Log.odc
Info/Mod/Look.odc
Info/Mod/MissingLinks.odc
Info/Mod/ReplaceLinks.odc
Info/Mod/ReplaceTexts.odc
Info/Mod/Search.odc
Info/Mod/Trans.odc
Info/Mod/Web.odc
Info/Rsrc/CheckFilenames1.odc
Info/Rsrc/CheckFilenames2.odc
Info/Rsrc/CheckLinks.odc
Info/Rsrc/CollectDocuments.odc
Info/Rsrc/CreateCatalog.odc
Info/Rsrc/CreateLinks.odc
Info/Rsrc/LinkList.odc
Info/Rsrc/Menus.odc
Info/Rsrc/Replace.odc
Info/Rsrc/Search.odc
Info/Rsrc/Strings.odc
Info/Rsrc/Web.odc
Info/Rsrc/de/Strings.odc
List of contents
3. Compile the following Modules
"DevCompiler.CompileThis"
InfoDialog InfoLog InfoCmds InfoTrans InfoForEachEntry InfoForEachFile
InfoCatalog InfoLook InfoIndex InfoSearch InfoCheckFilenames
InfoLinks InfoReplaceLinks InfoReplaceTexts InfoCollect InfoMissingLinks InfoCheckLinks InfoWeb
Replace in Winapi the definition of the PROCEDURE GetFullPathNameW* against the following one
and compile WinApi.
PROCEDURE GetFullPathNameW* (lpFileName: PtrWSTR; nBufferLength: INTEGER; lpBuffer: PtrWSTR; VAR [nil] lpFilePart: PtrWSTR): INTEGER;
(*END GetFullPathNameW;*)
CPC Notes: If you have a compiling errors
4. Update menus:
"StdMenuTool.UpdateAllMenus"
6. Change the configuration in the file System/Mod/Config.odc for autostart of helpdesk
MODULE Config;
IMPORT Dialog, Converters, OleData, InfoCmds, HostMenus, StdLinks, TextCmds;
PROCEDURE Setup*;
BEGIN
...
(* Dialog.Call("StdLog.Open", "", res); *)
InfoCmds.SetBrowserMode;
InfoCmds.OpenTopic('Uhl/');
HostMenus.TileHorizontal;
TextCmds.find.ignoreCase := TRUE;
END Setup;
END Config.
and compile it.
This change is done for the stand alone user version only. After the start of BlackBox it automaticlly opens the document Uhl/Inhalt.odc in browser mode and expand it over the whole window. At the developer station I use the subsystem Desktop instead.
Ready
2 How to use it? Up
2.1Openadocumentinthesamemode(browseroredit)asthecurrentone
2.2Startaprogramvialink
2.3Translateawebsite
2.4Searchthroughalldocuments
2.5Createlinklist(tableofcontents)
2.6Collectthedocuments
2.7Correcttext&linksviachangelist
2.8BuildCross-reference(subjectindex)
2.9Checkfilenames
2.10Checklinks
2.11Replaceinalldocuments
2.1 Open a document in the same mode (browser or edit) as the current one
Blackbox documents knows 4 states: browser mode, edit mode, hide marks and show marks. You can change this states via menus:
Set Edit Mode Dev -> Edit Mode "StdCmds.SetEditMode"
Set Browser Mode Dev -> Browser Mode "StdCmds.SetBrowserMode"
Show Marks Text -> Show Marks "TextCmds.ToggleMarks"
Hide Marks Text -> Hide Marks "TextCmds.ToggleMarks"
The frameworks provides 2 procedures for opening documents:
"StdCmds.OpenBrowser('Std/Docu/Links', 'Docu StdLinks')" Open Docu StdLinks in Browser Mode
"StdCmds.OpenDoc('Std/Docu/Links')" Open Docu StdLinks in Edit Mode
The Subsystem Info adds the procedure:
"InfoCmds.OpenDoc('Std/Docu/Links')" Open Docu StdLinks in the current Mode
which opens a document in the same state as the current one is open. For creating and editing links please read the StdLinks documentation.
2.2 Start a program via link
In the above descriptions we used links for opening Blackbox documents. Now we start other Windows programs via a link.
Starting the windows explorer
"InfoCmds.Start('shell:MyComputerFolder')" shell:MyComputerFolder
"InfoCmds.Start('shell:Desktop')" shell:Desktop
"InfoCmds.Start2('explorer /e, D:\Blackbox\ProjectAll\')" explorer /e, D:\Blackbox\ProjectAll\
You find a list of shell commands in Info/Docu/Shell-Commands
Starting command line
"InfoCmds.Start('cmd')" cmd
"InfoCmds.Start2('cmd /k dir')" cmd /k dir
"InfoCmds.Start2('cmd /k ipconfig/all')" cmd /k ipconfig/all
Starting a windows control programs
"InfoCmds.Start('compmgmt.msc')" compmgmt.msc
"InfoCmds.Start('control')" control
"InfoCmds.Start2('control nusrmgr.cpl')" control nusrmgr.cpl
"InfoCmds.Start2('control admintools')" control admintools
You find a list of control commands in Info/Docu/Control-Commands
Open Office documents
"InfoCmds.Start('Info/Docu/Helpdesk.pps')" Info/Docu/Helpdesk.pps
"InfoCmds.Start('Info/Docu/Dictionary.xls')" Info/Docu/Dictionary.xls
Open a website
"InfoCmds.Start('iexplore')" iexplore
"InfoCmds.Start('http://www.oberon.ch')" http://www.oberon.ch
"InfoCmds.Start('http://www.zinnamturm.eu')" http://www.zinnamturm.eu
Writing a email
"InfoCmds.Start('mailto:[email protected]')" mailto:[email protected]
2.3 Translate a website
For translating a website just select an url in your text document and open the menu Infodesk -> Translate Website...
Men:
Infodesk -> Translate Website...
or
"TextCmds.InitFindDialog; StdCmds.OpenToolDialog('Info/Rsrc/Web', 'Translate Website')"
Another way is to press the key Shift+Ctrl+L to get the bing or google translation of the selected website.
E.g.:
Select the url below
http://www.oberoncore.ru
and then press the key Shift+Ctrl+L
You get the bing translation of the oberonecore website from Russian to English.
2.4 Search through all documents
You can search in all documents starting at the Source directory.
Men:
Infodesk -> Search... -> Search In All Docu
or
"TextCmds.InitFindDialog; StdCmds.OpenToolDialog('Info/Rsrc/Search', 'Search')"
If the field 'Filter:' is empty then it search in *.* all files.
If the field 'Filter:' contains 'odc' then it search in *.odc documents files only.
If the field 'Filter:' contains 'osf' then it search in *.osf files only.
Note: See 2.8 for creating the Cross-Reference list.
2.5 Create link list (table of contents)
You have a directory and you would like to create a link list to all those documents in the directory for easy access.
Men:
Infodesk -> Link Documents... -> Create Link List
or
"StdCmds.OpenToolDialog('Info/Rsrc/CreateLinks', '#Info:Link Documents')"
Note: This document is discarded after closing. You have to save it manally if you would like to keep it.
2.6 Collect the documents
In the focus document there are a lot of links. Now you can create a file list of all linked documents.
Men:
Infodesk -> Collect & Move Documents... -> Create File List
or
"StdCmds.OpenToolDialog('Info/Rsrc/CollectDocuments', '#Info:Collect & Move Documents')"
Note: Look at the Log for links not insert into the file list.
To work thru the file list and collect all files into the destination directory.
Men:
Infodesk -> Collect Documents... -> Move Files
2.7 Correct text & links via change list
After moving the files to the destination some links may be broken. You can use the file list for fixing those links or creating your own document for a list of changes separated by tabs.
auto
find 1 replace 1
find 2 replace 2
and so on ...
In the first line the word "auto" is need for enable the commands. It protects the form against running the commands while another document has the fucus. If the focus is on your list of changes then use
Men:
Infodesk -> Collect Documents... -> Correct Links
Infodesk -> Collect Documents... -> Correct Texts
The command "Correct Links" or "Correct Text" works thru the list and does the changes in all documents.
See 2.11 to do one replace without a list.
Note: Beware, both commands changed all documents without request. Look at the Log to see which documents was changed.
2.8 Build Cross-reference (subject index)
Men:
Infodesk -> Build Reference... -> New Index
or
"StdCmds.OpenToolDialog('Info/Rsrc/CreateCatalog', '#Info:Build Reference')"
New Index will scan through all files and generate an index of all words, except those listed as trivial. Trival word should be listet in Info/Rsrc/Strings following a "Tab" and a "." (Period).
STRINGS
a .
are .
do .
does .
is .
the .
If the field 'Filter:' is empty it looks at *.* all files.
If the field 'Filter:' contains 'odc' then it looks at *.odc documents files only.
If the field 'Filter:' contains 'osf' then it looks at *.osf files only.
<InfoCmds.SetTopic('Help/Uhl/'); InfoLook.FindInIndex>Stichwortverzeichnis<> --> open file "Help/Uhl/Index.odc"
2.9 Check filenames
A filename should be no longer than 64 characters and the complete name including the path should be no longer than 260 characters. This utility finds too long file names and too deep pathes. It can correct it automatically or interaktive. Choose the switch "Testrun" for testing without changing anything. Often I get trouble with national language characters in filename. They can automatically translated.
Men:
Infodesk -> Check Filenames...
or
"StdCmds.OpenToolDialog('Info/Rsrc/CheckFilenames1', '#Info:Check Filenames')"
2.10 Check links
Is every document reachable via link? Are all links working? You find it out with
Men:
Infodesk -> Check Links...
or
"StdCmds.OpenToolDialog('Info/Rsrc/CheckLinks', '#Info:Check Links')"
2.11 Replace in all documents
If one file move to another directory then you would like to change all links to that file. To do the replace thru all documents use
Men:
Infodesk -> Replace in all Documents... -> Replace Texts
Infodesk -> Replace in all Documents... -> Replace Links
or
"TextCmds.InitFindDialog; StdCmds.OpenToolDialog('Info/Rsrc/Replace', '#Info:Replace in all Documents')"
See 2.7 to do replace with a list of changes.
Note: Beware, both commands changed all documents without request. Read the Log to see which documents was changed.
3 Change log Up
May 2015: New MODULE InfoWeb added for translate a website
March 2014: Adapt according to the CPC Edition of BlackBox 1.7
4 Reference Up
My thanks for the help to Dominik Gruntz mailto:[email protected]
and Werner Braun mailto:[email protected]
Use it and enjoy! - salos y disfrtalos! - Bonne utilisation - Приятного использования - Powodzenia - Viel Spa
Helmut Zinn
[email protected]
| Info/Docu/Quick-Start.odc |
Shell Commands in Windows 7
on command line use: start shell:...
Daten Shell Commands
shell:MyComputerFolder
shell:UsersFilesFolder shell:Public shell:Libraries
1. Desktop: shell:Desktop shell:Common Desktop
2. Downloads: shell:Downloads shell:CommonDownloads
3. Eigene Bilder: shell:My Pictures shell:CommonPictures shell:PicturesLibrary
4. Eigene Dokumente: shell:Personal shell:Common Documents shell:DocumentsLibrary
5. Eigene Musik: shell:My Music shell:CommonMusic shell:MusicLibrary
6. Eigene Videos: shell:My Video shell:CommonVideo shell:VideosLibrary
7. Favoriten: shell:Favorites
8. Gespeicherte Spiele: shell:SavedGames
9. Kontakte: shell:Contacts
10. Links: shell:Links
11. Suchvorgnge: shell:Searches
12. TV-Aufzeichnungen shell:RecordedTVLibrary
shell:SampleMusic
shell:SamplePictures
shell:SamplePlaylists
shell:SampleVideos
Profil Shell Commands
shell:UserProfiles
Temporre Internetdateien shell:Cache
shell:Cookies
shell:CD Burning
shell:History
shell:Recent
shell:RecycleBinFolder
shell:SendTo
shell:AppData shell:Common AppData
shell:Local AppData
shell:LocalAppDataLow
Menu Shell Commands
Men shell:Start Menu shell:Common Start Menu
Programme shell:Programs shell:Common Programs
Autostart shell:Startup shell:Common Startup
System Shell Commands
shell:AppUpdatesFolder
shell:ChangeRemoveProgramsFolder
shell:Common Administrative Tools
shell:Common Templates
shell:CommonRingtones
shell:ConflictFolder
shell:ConnectionsFolder
shell:ControlPanelFolder
shell:CredentialManager
shell:CryptoKeys
shell:Default Gadgets
shell:Device Metadata Store
shell:DpapiKeys
shell:Fonts
shell:Gadgets
shell:GameTasks
shell:Games
shell:ImplicitAppShortcuts
shell:InternetFolder
shell:NetHood
shell:NetworkPlacesFolder
shell:PrintHood
shell:PrintersFolder
shell:Profile
shell:ProgramFiles
shell:ProgramFilesCommon
shell:ProgramFilesCommonX86
shell:ProgramFilesX86
shell:PublicGameTasks
shell:Quick Launch
shell:ResourceDir
shell:Ringtones
shell:SearchHomeFolder
shell:SyncCenterFolder
shell:SyncResultsFolder
shell:SyncSetupFolder
shell:System
shell:SystemCertificates
shell:SystemX86
shell:Templates
shell:User Pinned
shell:Windows
Ende.
| Info/Docu/Shell-Commands.odc |
MODULE InfoCatalog;
(* Helmut Zinn *)
(* Build the TableofContents *)
(* InfoCatalog.CreateTableOfContents *)
(* "StdCmds.OpenToolDialog('Info/Rsrc/CreateCatalog', 'Build Reference')" *)
IMPORT
DosKeyboard, (* DosSort, *) Files, Fonts, InfoDialog, Ports,
StdFolds, StdLinks, StdStamps, TextMappers, TextModels, TextRulers, TextViews, Views;
VAR
fm: TextMappers.Formatter;
count: INTEGER;
PROCEDUREWriteRuler;
CONST mm = Ports.mm; (* universal units *)
VAR ruler: TextRulers.Ruler;
BEGIN
ruler := TextRulers.dir.New(NIL);
TextRulers.AddTab(ruler, 4 * mm);
TextRulers.AddTab(ruler, 130 * mm);
TextRulers.MakeRightTab(ruler);
TextRulers.AddTab(ruler, 150 * mm);
TextRulers.MakeRightTab(ruler);
TextRulers.AddTab(ruler, 165 * mm);
TextRulers.MakeRightTab(ruler);
fm.WriteView(ruler)
END WriteRuler;
PROCEDURE WriteLink (VAR fm: TextMappers.Formatter; IN path, comment: ARRAY OF CHAR; file: Files.FileInfo);
VAR cmd: ARRAY 512 OF CHAR;
BEGIN
IF file = NIL THEN
cmd := "InfoCmds.Start('" + path$ + "')";
ELSE
IF file.type = "odc" THEN cmd := "InfoCmds.OpenDoc('" ELSE cmd := "InfoCmds.Start('" END;
cmd := cmd + path$ + '/' + file.name$ + "')";
fm.WriteTab;
END;
fm.WriteView(StdLinks.dir.NewLink(cmd));
fm.rider.SetAttr(TextModels.NewColor(fm.rider.attr, Ports.blue));
IF comment$ # '' THEN
fm.WriteString(comment$)
ELSIF file = NIL THEN
fm.WriteString(path$)
ELSE
fm.WriteString(file.name$)
END;
fm.rider.SetAttr(TextModels.NewColor(fm.rider.attr, Ports.black));
fm.WriteView(StdLinks.dir.NewLink(""));
IF file # NIL THEN
IF InfoDialog.param.listDate THEN
fm.WriteTab;
(*
fm.WriteInt(file.length);
*)
fm.WriteTab;
IF file.modified.day < 10 THEN fm.WriteChar(' ') END;
fm.WriteInt(file.modified.day);
fm.WriteString(".");
IF file.modified.month < 10 THEN fm.WriteChar('0') END;
fm.WriteInt(file.modified.month);
fm.WriteString(".");
fm.WriteInt(file.modified.year);
fm.WriteTab;
IF file.modified.hour < 10 THEN fm.WriteChar(' ') END;
fm.WriteInt(file.modified.hour);
fm.WriteString(":");
IF file.modified.minute < 10 THEN fm.WriteChar('0') END;
fm.WriteInt(file.modified.minute);
fm.WriteString(":");
IF file.modified.second < 10 THEN fm.WriteChar('0') END;
fm.WriteInt(file.modified.second);
END;
fm.WriteLn;
END;
END WriteLink;
PROCEDURE WriteHeader (IN note, path, name: ARRAY OF CHAR);
BEGIN
fm.rider.SetAttr(TextModels.NewWeight(fm.rider.attr, Fonts.bold));
WriteLink(fm, path$, name$, NIL);
fm.rider.SetAttr(TextModels.NewWeight(fm.rider.attr, Fonts.normal));
fm.WriteString(note);
fm.WriteLn;
END WriteHeader;
PROCEDURE WriteOpenFold (IN path, comment: ARRAY OF CHAR);
VAR
mdFold: TextModels.Model;
fmFold: TextMappers.Formatter;
fold: StdFolds.Fold;
BEGIN
mdFold := TextModels.dir.New();
fmFold.ConnectTo(mdFold);
fmFold.WriteString(' [');
WriteLink(fmFold, path$, comment$, NIL);
fmFold.WriteString('] ');
fold := StdFolds.dir.New(StdFolds.expanded, "", mdFold);
fm.WriteView(fold);
END WriteOpenFold;
PROCEDUREWriteCloseFold;
VAR fold: StdFolds.Fold; len: INTEGER;
BEGIN
fold := StdFolds.dir.New(StdFolds.expanded, "", NIL);
fm.WriteView(fold);
fold.Flip; (* swap long-form text, now between the two fold views, with hidden short-form text *)
len := fm.rider.Base().Length(); (* determine the text carrier's new length *)
fm.SetPos(len) (* position the formatter to the end of the text *)
END WriteCloseFold;
PROCEDURE ListAllFiles (IN path: ARRAY OF CHAR);
VAR
root: Files.Locator; locs: Files.LocInfo; files: Files.FileInfo;
begFold, endFold: INTEGER;
BEGIN
INC(count); InfoDialog.ShowStatus(count, path);
WriteHeader("", path, "");
fm.WriteLn;
(* generate a list of all files *)
root := Files.dir.This(path);
files := Files.dir.FileList(root);
(* DosSort.FileList(files); *)
WHILE ~DosKeyboard.Break() & (files # NIL) DO
IF (InfoDialog.param.filter$ = '') OR (InfoDialog.param.filter$ = files.type$) THEN
WriteLink(fm, path, "", files);
END;
files := files.next
END;
(* generate list of all locations *)
root := Files.dir.This(path);
locs := Files.dir.LocList(root);
(* DosSort.LocList(locs); *)
WHILE ~DosKeyboard.Break() & (locs # NIL) DO
fm.WriteTab;
IF InfoDialog.param.include THEN
begFold := fm.Pos();
fm.WriteLn;
ListAllFiles(path + locs.name$ + '/');
fm.WriteLn;
WriteHeader(" Continue", path, "");
endFold := fm.Pos();
(* write the folded part *)
fm.SetPos(begFold); WriteOpenFold(path$ + locs.name$ + '/', locs.name$);
fm.SetPos(endFold + 1); fm.WriteTab; WriteCloseFold;
ELSE
fm.WriteChar('[');
WriteLink(fm, path$ + '/' + locs.name$, locs.name$, NIL);
fm.WriteChar(']');
END;
fm.WriteLn;
locs := locs.next
END;
END ListAllFiles;
PROCEDURE CreateTableOfContents*;
VAR
md: TextModels.Model; vw: Views.View;
BEGIN
InfoDialog.ProofParam;
md := TextModels.dir.New();
fm.ConnectTo(md); fm.SetPos(0);
count := 0;
WriteRuler;
ListAllFiles(InfoDialog.param.source);
fm.WriteLn; fm.WriteString('Ende. '); fm.WriteView(StdStamps.New()); fm.WriteLn;
vw := TextViews.dir.New(md);
Views.OpenView(vw);
IF DosKeyboard.Break() THEN
DosKeyboard.ResetBreak;
ELSE
(* Aufgabe ausgefhrt *)
END;
END CreateTableOfContents;
END InfoCatalog.
| Info/Mod/Catalog.odc |
MODULE InfoCheckFilenames;
(* Helmut Zinn - *)
(* "StdCmds.OpenToolDialog('Info/Rsrc/CheckFilenames1', 'Check Filenames')" *)
IMPORT
Dialog, (* DosFiles, DosSort, *) Files, Fonts, InfoCmds, InfoTrans, PacDirChoose, Ports,
Services, Strings, StdCmds, StdLinks, StdLog, TboxTimer, TextModels, WinApi;
CONST
n1 = 64;
n2 = 260;
speed = 50;
keep = 8;
linkcommand = 'InfoCmds.Start'; (* Alternativ: linkcommand = 'LibMisc.ShellExecute'; *)
underline = FALSE;
TYPE
Node = POINTER TO RECORD
root: Files.Locator;
locs: Files.LocInfo;
files: Files.FileInfo;
n: LONGINT;
len: INTEGER;
state: INTEGER;
last: Node;
END;
Action = POINTER TO RECORD (Services.Action)
pos: Node;
END;
VAR
dialog*: RECORD
source*: ARRAY n2 + 1 OF CHAR;
path-: ARRAY n2 + 1 OF CHAR;
oldname-: Files.Name;
newname*: Files.Name;
include*: BOOLEAN;
interaktive*: BOOLEAN;
trapOnError*: BOOLEAN;
testOnly*: BOOLEAN; (* test run only, no change done *)
renameLongNames*: BOOLEAN; (* cut long names to its bound *)
deleteEmptyFolders*: BOOLEAN; (* delete directories while it is empty *)
replaceSpecialChar*: BOOLEAN; (* replace blanks & national language character *)
toLowercase*: BOOLEAN; (* convert filename to lower case *)
cntLocations-: LONGINT; (* total number of directories *)
cntFiles-: LONGINT; (* total number of files *)
cntBytes-: LONGINT; (* total number of bytes used *)
cntToolong-: LONGINT; (* number of files where the filename is too long *)
cntToodeep-: LONGINT; (* number of files where the path is too long *)
cntEmpty-: LONGINT; (* number of files where the directory is empty *)
cntSpecialChar-: LONGINT; (* number of files where the its name has special characters *)
cntRenamed-: LONGINT; (* number of files renamed *)
cntDeleted-: LONGINT; (* number of directories deleted *)
cntSkip-: LONGINT; (* operation not done *)
cntError-: LONGINT; (* file already exist or write protected *)
END;
a: Action;
task: INTEGER;
running, waiting: BOOLEAN;
PROCEDURE ShowResError (res: INTEGER);
BEGIN
StdLog.String('==> Error: ');
CASE res OF
| 1: StdLog.String('invalid parameter (name or locator)');
| 2: StdLog.String('location or file not found');
| 3: StdLog.String('file already exists');
| 4: StdLog.String('write-protection');
| 5: StdLog.String('io error');
| 6: StdLog.String('access denied');
| 7: StdLog.String('illegal file type');
| 8: StdLog.String('cancelled');
ELSE StdLog.Int(res);
END;
StdLog.Ln;
StdLog.Open;
IF dialog.trapOnError THEN ASSERT(res = 0) END;
END ShowResError;
(* Choose folder to proof *)
PROCEDURE FixSrcRoot* (IN path: Files.Name);
BEGIN
dialog.source := path$; dialog.path := path$; dialog.oldname := ''; dialog.newname := '';
Dialog.Update(dialog);
END FixSrcRoot;
PROCEDURE BrowseSource*;
BEGIN
PacDirChoose.Choose(FixSrcRoot);
END BrowseSource;
(* Outputs to Log window *)
PROCEDURE WriteMapString (IN note: ARRAY OF CHAR);
VAR
msg: ARRAY 256 OF CHAR;
BEGIN
Dialog.MapString(note, msg); StdLog.String(msg$);
END WriteMapString;
PROCEDURE WriteLink (IN path: ARRAY OF CHAR);
VAR
attr: TextModels.Attributes;
beg, end: INTEGER;
cmd, msg: ARRAY n2+32 OF CHAR;
BEGIN
cmd := linkcommand + "('" + path$ + "')";
msg := path$;
StdLog.View(StdLinks.dir.NewLink(cmd));
StdLog.String(msg);
end := StdLog.text.Length(); beg := end - LEN(msg$);
NEW(attr);
attr.InitFromProp(StdLog.text.Prop(beg, end));
attr := TextModels.NewColor(attr, Ports.blue);
IF underline THEN attr := TextModels.NewStyle(attr, {Fonts.underline}) END;
StdLog.text.SetAttr(beg, end, attr);
StdLog.View(StdLinks.dir.NewLink(""));
END WriteLink;
(* Change / remove file / folder names *)
PROCEDURE Exist (IN path: ARRAY OF CHAR; IN old: Files.Name): BOOLEAN;
VAR
loc: Files.Locator;
file: Files.File;
BEGIN
loc := Files.dir.This(path$);
file := Files.dir.Old(loc, old, Files.shared);
IF file = NIL THEN RETURN FALSE ELSE RETURN TRUE END;
END Exist;
PROCEDURE RenameFile (IN path: ARRAY OF CHAR; IN old, new: Files.Name);
VAR
loc: Files.Locator;
BEGIN
(* Can't rename if path + oldname is longer than 260 characters. File-IO-Error 2: location or file not found. *)
StdLog.String('> Rename to: '); WriteLink(path$); StdLog.String(new$); StdLog.Ln;
loc := Files.dir.This(path);
Files.dir.Rename(loc, old, new, Files.ask);
IF loc.res = 0 THEN
INC(dialog.cntRenamed)
ELSE
INC(dialog.cntError);
StdLog.String('<<< File-IO-Error '); StdLog.Int(loc.res); StdLog.String(' >>>'); StdLog.Ln;
ShowResError(loc.res);
END;
END RenameFile;
PROCEDURE DeleteFile (IN path: ARRAY OF CHAR; IN old: Files.Name);
VAR
loc: Files.Locator;
BEGIN
StdLog.String('> Delete file: '); WriteLink(path$); StdLog.String(old$); StdLog.Ln;
loc := Files.dir.This(path$);
Files.dir.Delete(loc, old$);
IF loc.res = 0 THEN
INC(dialog.cntDeleted)
ELSE
INC(dialog.cntError);
StdLog.String('<<< File-IO-Error '); StdLog.Int(loc.res); StdLog.String(' >>>'); StdLog.Ln;
ShowResError(loc.res);
END;
END DeleteFile;
PROCEDURE DeleteFolder (IN path: ARRAY OF CHAR);
VAR
res: INTEGER;
BEGIN
StdLog.String('> Delete folder: '); WriteLink(path$); StdLog.Ln;
res := WinApi.RemoveDirectoryW(path);
IF res = 1 THEN
INC(dialog.cntDeleted)
ELSE
INC(dialog.cntError);
StdLog.String('<<< Win-Api-Error '); StdLog.Int(res); StdLog.String(' >>>'); StdLog.Ln;
(* DosFiles.ShowApiError; *)
IF dialog.trapOnError THEN ASSERT(res = 1) END;
END;
END DeleteFolder;
(* Proof the names *)
PROCEDURE BuildNewName (IN old: ARRAY OF CHAR; OUT new: ARRAY OF CHAR);
VAR i, j: INTEGER;
BEGIN
IF dialog.replaceSpecialChar THEN
j := 0;
FOR i := 0 TO LEN(old$) DO
new[j] := InfoTrans.TransChar1(old[i]);
INC(j);
END;
new[j] := 0X;
InfoTrans.Trim(new);
ELSE
new := old$;
END;
IF dialog.toLowercase THEN
Strings.ToLower(new, new);
END;
IF LEN(new$) > n1 THEN
FOR i := 4+keep TO 0 BY -1 DO
new[n1-i] := new[LEN(new$)-i];
END;
END;
END BuildNewName;
PROCEDURE CheckSpecialChar (IN path, name: ARRAY OF CHAR);
VAR
i, n: INTEGER;
ok : BOOLEAN;
BEGIN
n := LEN(name$); ok := TRUE;
IF dialog.replaceSpecialChar OR ~dialog.toLowercase THEN
i := 0;
WHILE ok & (i < n) DO
IF (name[i] <=20X) OR (name[i] >= 7FX) THEN ok := FALSE END;
INC(i);
END;
END;
IF dialog.toLowercase THEN
i := 0;
WHILE ok & (i < n) DO
IF (name[i] >='A') OR (name[i] <= 'Z') THEN ok := FALSE END;
INC(i);
END;
END;
IF ~ok THEN
INC(dialog.cntSpecialChar);
IF dialog.replaceSpecialChar OR dialog.toLowercase THEN
IF dialog.testOnly THEN
StdLog.Ln; StdLog.String('Name with special character:'); StdLog.Ln;
StdLog.Tab; WriteLink(path$); StdLog.Ln;
StdLog.Tab; StdLog.String(name$); StdLog.Ln;
ELSE
BuildNewName(dialog.oldname, dialog.newname); task := 1; (* Rename File *)
END;
END;
END;
END CheckSpecialChar;
PROCEDURE CheckName (IN path, name: ARRAY OF CHAR);
VAR
ok: BOOLEAN;
BEGIN
IF (LEN(name$) <= n1) THEN
ok := TRUE;
ELSE
ok := FALSE;
INC(dialog.cntToolong);
IF dialog.renameLongNames THEN
IF dialog.testOnly OR (LEN(path$) + LEN(name$) + 1 >= n2) THEN
StdLog.Ln; StdLog.String('Filename too long:'); StdLog.Ln;
StdLog.Tab; WriteLink(path$); StdLog.Ln;
StdLog.Tab; StdLog.String(name$); StdLog.Ln;
ELSE
BuildNewName(dialog.oldname, dialog.newname); task := 1; (* Rename File *)
END;
END;
END;
CheckSpecialChar(path, name);
END CheckName;
PROCEDURE CheckDeep (IN path, name: ARRAY OF CHAR; VAR ok: BOOLEAN);
BEGIN
IF (LEN(path$) + LEN(name$) + 1 < n2) THEN
ok := TRUE;
ELSE
ok := FALSE;
INC(dialog.cntToodeep);
IF dialog.testOnly & dialog.renameLongNames THEN
StdLog.Ln; StdLog.String('Path too deep:'); StdLog.Ln;
StdLog.Tab; WriteLink(path$); StdLog.Ln;
StdLog.Tab; StdLog.String(name$); StdLog.Ln;
END;
END;
END CheckDeep;
(* Commandos for the first form *)
PROCEDURE Init;
BEGIN
dialog.path := dialog.source$; dialog.oldname := ''; dialog.newname := '';
dialog.cntLocations := 0; dialog.cntFiles := 0; dialog.cntBytes := 0;
dialog.cntToolong := 0; dialog.cntToodeep := 0; dialog.cntEmpty := 0;
dialog.cntLocations := 0; dialog.cntFiles := 0; dialog.cntBytes := 0;
dialog.cntToolong := 0; dialog.cntToodeep := 0; dialog.cntEmpty := 0; dialog.cntSpecialChar:= 0;
dialog.cntRenamed := 0; dialog.cntDeleted := 0; dialog.cntSkip := 0; dialog.cntError := 0;
Dialog.Update(dialog);
END Init;
PROCEDURE Start*;
BEGIN
TboxTimer.Start;
Init;
NEW(a);
NEW(a.pos);
a.pos.last := NIL;
a.pos.state := 1;
running := TRUE;
waiting := FALSE;
Services.DoLater(a, Services.now);
END Start;
PROCEDURE Stop*;
BEGIN
IF (a # NIL) & (a.pos = NIL) & running THEN
dialog.oldname := ''; Dialog.Update(dialog);
StdLog.Ln;
StdLog.Int(dialog.cntLocations); StdLog.String(" folders"); StdLog.Ln;
StdLog.Int(dialog.cntFiles); StdLog.String(" files"); StdLog.Ln;
StdLog.Int(dialog.cntBytes); StdLog.String(" Bytes"); StdLog.Ln;
StdLog.Ln;
StdLog.Int(dialog.cntToolong); StdLog.String(" names are too long"); StdLog.Ln;
StdLog.Int(dialog.cntToodeep); StdLog.String(" paths are too long"); StdLog.Ln;
StdLog.Int(dialog.cntEmpty); StdLog.String(" folders/files are empty"); StdLog.Ln;
StdLog.Int(dialog.cntSpecialChar); StdLog.String(" names with special characters"); StdLog.Ln;
StdLog.Ln;
IF ~dialog.testOnly THEN
StdLog.Int(dialog.cntRenamed); StdLog.String(" files renamed"); StdLog.Ln;
StdLog.Int(dialog.cntDeleted); StdLog.String(" directories deleted"); StdLog.Ln;
StdLog.Int(dialog.cntSkip); StdLog.String(" operation not done"); StdLog.Ln;
StdLog.Int(dialog.cntError); StdLog.String(" errors"); StdLog.Ln;
StdLog.Ln;
END;
a := NIL;
TboxTimer.Stop;
END;
running := FALSE;
END Stop;
PROCEDURE Continue*; (* and Skip *)
BEGIN
running := TRUE;
waiting := FALSE;
Services.DoLater(a, Services.now)
END Continue;
(* Commandos for the second form *)
PROCEDURE Accept;
BEGIN
CASE task OF
0: (* No Task - Nothing To Do *)
| 1: (* Delete Or Rename Long File Names *)
IF dialog.newname$ = '' THEN
DeleteFile(dialog.path$, dialog.oldname$);
ELSE
RenameFile(dialog.path$, dialog.oldname$, dialog.newname$);
END;
| 2: (* Delete Empty Folders *)
DeleteFolder(dialog.path$+dialog.oldname$);
ELSE
(* Task Not Done *)
INC(dialog.cntSkip);
END;
END Accept;
PROCEDURE ShowFolder*;
BEGIN
InfoCmds.Start(dialog.path$)
END ShowFolder;
PROCEDURE CopyName*;
BEGIN
IF dialog.newname$ # dialog.oldname$ THEN
dialog.newname := dialog.oldname;
ELSE
dialog.newname := '';
END;
Dialog.Update(dialog);
END CopyName;
PROCEDURE Rename*;
BEGIN
INC(a.pos.n);
task := 1; Accept; Continue;
END Rename;
PROCEDURE Skip*;
BEGIN
task := 3; Accept; Continue;
END Skip;
PROCEDURE Delete*;
BEGIN
(* task 1 or 2 *) Accept; Continue;
END Delete;
(* Enable / Disable Commands *)
PROCEDURE StartGuard* (VAR par: Dialog.Par);
BEGIN
IF ~running THEN par.disabled := FALSE ELSE par.disabled := TRUE END;
END StartGuard;
PROCEDURE StopGuard* (VAR par: Dialog.Par);
BEGIN
IF running THEN par.disabled := FALSE ELSE par.disabled := TRUE END;
END StopGuard;
PROCEDURE ContinueGuard* (VAR par: Dialog.Par);
BEGIN
IF (a # NIL) & ~running THEN par.disabled := FALSE ELSE par.disabled := TRUE END;
END ContinueGuard;
PROCEDURE ShowFolderGuard* (VAR par: Dialog.Par);
BEGIN
IF dialog.path # '' THEN par.disabled := FALSE ELSE par.disabled := TRUE END;
END ShowFolderGuard;
PROCEDURE CopyNameGuard* (VAR par: Dialog.Par);
BEGIN
IF dialog.newname$ # dialog.oldname$ THEN
par.label := "#Info:Copy Name";
ELSE
par.label := "#Info:Clear Name";
END;
IF waiting THEN par.disabled := FALSE ELSE par.disabled := TRUE END;
END CopyNameGuard;
PROCEDURE RenameGuard* (VAR par: Dialog.Par);
VAR
n: INTEGER;
BEGIN
n := LEN(dialog.newname$);
IF waiting & (n > 0) & (n <= n1) THEN par.disabled := FALSE ELSE par.disabled := TRUE END;
END RenameGuard;
PROCEDURE SkipGuard* (VAR par: Dialog.Par);
BEGIN
IF waiting THEN par.disabled := FALSE ELSE par.disabled := TRUE END;
END SkipGuard;
PROCEDURE DeleteGuard* (VAR par: Dialog.Par);
VAR
n: INTEGER;
BEGIN
n := LEN(dialog.newname$);
IF waiting & (n = 0) THEN par.disabled := FALSE ELSE par.disabled := TRUE END;
END DeleteGuard;
(* Check all file names *)
PROCEDURE (a: Action) Do;
VAR
cnt: INTEGER;
ok: BOOLEAN;
p: Node;
BEGIN
cnt := 0;
task := 0;
dialog.newname := '';
WHILE (a.pos # NIL) & (cnt < speed) & (task = 0) DO
INC(cnt);
CASE a.pos.state OF
1: (* State 1: Read location & file list *)
INC(dialog.cntLocations);
a.pos.root := Files.dir.This(dialog.path$);
a.pos.files := Files.dir.FileList(a.pos.root); (* DosSort.FileList(a.pos.files); *)
a.pos.locs := Files.dir.LocList(a.pos.root); (* DosSort.LocList(a.pos.locs); *)
a.pos.n := 0;
a.pos.len := LEN(dialog.path$);
a.pos.state := 2;
| 2: (* State 2: Proof all file name *)
IF a.pos.files # NIL THEN
INC(a.pos.n);
INC(dialog.cntFiles);
dialog.oldname := a.pos.files.name$;
dialog.cntBytes := dialog.cntBytes + a.pos.files.length;
Dialog.Update(dialog);
CheckName(dialog.path$, dialog.oldname$);
CheckDeep(dialog.path$, dialog.oldname$, ok);
a.pos.files := a.pos.files.next
ELSE
a.pos.state := 3;
END;
| 3: (* State 3: Proof location name and look at their files *)
IF a.pos.locs # NIL THEN
dialog.oldname := a.pos.locs.name$;
Dialog.Update(dialog);
CheckName(dialog.path$, dialog.oldname$);
CheckDeep(dialog.path$, dialog.oldname$, ok);
IF ok & dialog.include THEN
dialog.path := dialog.path$ + a.pos.locs.name$ + "/";
a.pos.locs := a.pos.locs.next;
NEW(p);
p.last := a.pos;
a.pos := p;
a.pos.state := 1;
ELSE
a.pos.locs := a.pos.locs.next;
END;
ELSE
a.pos.state := 4;
END;
| 4: (* State 4: All done for this location - next location *)
dialog.oldname := '';
dialog.newname := '';
IF a.pos.n = 0 THEN
INC(dialog.cntEmpty);
Dialog.Update(dialog);
IF dialog.deleteEmptyFolders THEN
IF dialog.testOnly THEN
StdLog.Ln; StdLog.String('Folder is empty:'); StdLog.Ln;
StdLog.Tab; WriteLink(dialog.path$); StdLog.Ln;
ELSE
task := 2; (* Delete Folder *)
END;
END;
END;
IF a.pos.last # NIL THEN
a.pos.last.n := a.pos.last.n + a.pos.n;
Strings.Extract(dialog.path, a.pos.last.len, a.pos.len-a.pos.last.len-1, dialog.oldname);
END;
a.pos := a.pos.last;
IF a.pos # NIL THEN dialog.path[a.pos.len] := 0X END;
(*
(* Sonderfall: Delete Profiles *)
(* Can't read and delete files with names like .java, .hotjava, .jinit ... *)
IF (dialog.oldname$ = 'Profiles') OR (dialog.oldname$ = 'profiles') THEN
DosFiles.RemoveTree(dialog.path$+dialog.oldname$+'/');
DosFiles.RemoveDir(dialog.path$+dialog.oldname$);
task := 0;
END;
*)
END;
Dialog.Update(dialog);
END;
IF (task # 0) & dialog.interaktive THEN
(* wait for user's choice *)
waiting := TRUE;
StdCmds.OpenToolDialog('Info/Rsrc/CheckFilenames2', 'Replace Filenames');
ELSE
Accept;
IF (a.pos # NIL) & running THEN Continue ELSE Stop END
END;
END Do;
BEGIN
running := FALSE;
waiting := FALSE;
dialog.source := 'D:/BlackBox/';
dialog.include := TRUE; dialog.interaktive := TRUE;
dialog.trapOnError := FALSE; dialog.testOnly := TRUE;
dialog.renameLongNames := FALSE; dialog.deleteEmptyFolders := FALSE;
dialog.replaceSpecialChar := FALSE; dialog.toLowercase := FALSE;
Init;
END InfoCheckFilenames.
| Info/Mod/CheckFilenames.odc |
MODULE InfoCheckLinks;
(* Helmut Zinn *)
IMPORT
Converters, Dialog, DosKeyboard, (* DosSort, *)
Files, Fonts, InfoDialog, InfoMissingLinks, Kernel, Ports, StdCmds, StdFolds, StdLinks,
Strings, TextCmds, TextControllers, TextMappers, TextModels, TextViews, Views;
CONST
(*
maxLength = 256;
linkcommand = 'InfoCmds.Start'; (* Alternativ: linkcommand = 'LibMisc.ShellExecute'; *)
underline = FALSE;
*)
linkCommand = "InfoCheckLinks.Open('";
org = TRUE; (* source *)
ref = FALSE; (* link to source *)
TYPE
Iterator = POINTER TO RECORD
root: Files.Locator;
locs: Files.LocInfo;
files: Files.FileInfo
END;
VAR
default, link: TextModels.Attributes;
docList: InfoMissingLinks.DocList;
count: INTEGER;
PROCEDURE MakeDocName (VAR name: Files.Name);
BEGIN
Kernel.MakeFileName(name, ""); (* Append Extension *)
END MakeDocName;
PROCEDURE New (root: Files.Locator): Iterator;
VAR i: Iterator;
BEGIN
NEW(i); i.root := root; i.locs := Files.dir.LocList(root); i.files := Files.dir.FileList(root);
(* DosSort.LocList(i.locs); *)
(* DosSort.FileList(i.files); *)
RETURN i
END New;
PROCEDURE ReadLoc (i: Iterator; VAR loc: Files.Locator; VAR name: Files.Name);
BEGIN
IF i.locs # NIL THEN
loc := i.root.This(i.locs.name); ASSERT(loc # NIL, 60);
name := i.locs.name$;
i.locs := i.locs.next
ELSE
loc := NIL; name := ""
END
END ReadLoc;
PROCEDURE ReadFile (i: Iterator; OUT name: Files.Name; OUT type: Files.Type);
BEGIN
IF i.files # NIL THEN
name := i.files.name$;
type := i.files.type$;
i.files := i.files.next
ELSE
name := "";
type := ""
END
END ReadFile;
PROCEDURE Delimiter (ch: CHAR): BOOLEAN;
BEGIN
RETURN (ch = "'") OR (ch = '"') OR (ch = "/") OR (ch = "\")
END Delimiter;
PROCEDURE Stale (IN s: ARRAY OF CHAR): BOOLEAN;
VAR i, j, p: INTEGER; ch: CHAR; loc: Files.Locator; name: Files.Name; t: ARRAY 1024 OF CHAR;
path: ARRAY 256 OF CHAR;
BEGIN
i := 0; ch := s[0]; WHILE (ch # 0X) & (ch # "(") DO INC(i); ch := s[i] END;
IF ch = "(" THEN
t := s$; t[i] := 0X;
IF (t = "InfoCmds.Start") OR (t = "InfoCmds.Start2") OR (t = "LibMisc.ShellExecute")
OR (t = "Dialog.RunExternal") OR (t = "Dialog.OpenExternal") THEN
p := i;
INC(i); ch := s[i]; WHILE (ch # 0X) & (ch # "'") & (ch # '"') DO INC(i); ch := s[i] END;
FOR j := 0 TO 6 DO
INC(i);
t[j] := s[i];
END;
t[7] := 0X; IF t = "mailto:" THEN RETURN FALSE END; (* use ok *)
t[6] := 0X; IF t = "https:" THEN RETURN FALSE END; (* use ok *)
t[6] := 0X; IF t = "shell:" THEN RETURN FALSE END; (* use ok *)
t[5] := 0X; IF t = "http:" THEN RETURN FALSE END; (* use ok *)
t[4] := 0X; IF t = "ftp:" THEN RETURN FALSE END; (* use ok *)
t[4] := 0X; IF t = "www." THEN RETURN FALSE END; (* use ok *)
IF t[0] = "'" THEN RETURN TRUE END; (* wrong use *)
i := p;
t := s$; t[i] := 0X;
END;
IF (t = "StdCmds.OpenBrowser") OR (t = "StdCmds.OpenDoc") OR (t = "StdCmds.OpenAuxDialog")
OR (t = "InfoCmds.OpenDoc")
OR (t = "StdCmds.OpenDoc")
OR (t = "InfoCmds.Start") OR (t = "InfoCmds.Start2") OR (t = "LibMisc.ShellExecute")
OR (t = "Dialog.RunExternal") OR (t = "Dialog.OpenExternal") THEN
INC(i); ch := s[i]; WHILE (ch # 0X) & (ch # "'") & (ch # '"') DO INC(i); ch := s[i] END;
IF ch # 0X THEN
loc := Files.dir.This("");
path := "";
REPEAT
j := 0;
INC(i); ch := s[i]; WHILE ~Delimiter(ch) DO t[j] := ch; INC(j); INC(i); ch := s[i] END;
t[j] := 0X;
IF (ch = "/") OR (ch = "\") THEN loc := loc.This(t); path := path + t + '/' END
UNTIL (ch # "/") & (ch # "\");
IF t$ = "" THEN RETURN Files.dir.FileList(loc) = NIL END; (* directory only - no filename *)
t[255] := 0X; (* truncate string *)
name := t$; MakeDocName(name);
IF Files.dir.Old(loc, name, Files.shared) = NIL THEN (* file not found *)
RETURN TRUE (* file not found *)
ELSE
InfoMissingLinks.Insert(docList, path, name, ref); (* --> out = link to source *)
RETURN FALSE (* file found *)
END
ELSE
RETURN TRUE (* wrong syntax *)
END
ELSE
RETURN FALSE (* unknown kind of command *)
END
ELSE
RETURN FALSE (* unknown kind of command *)
END
END Stale;
PROCEDURE GetCmd (IN path, file: Files.Name; pos: INTEGER; OUT cmd: ARRAY OF CHAR);
VAR p, bug0, bug1, bug2: ARRAY 128 OF CHAR;
BEGIN
Strings.IntToString(pos, p);
bug0 := linkCommand + path + "', '";
bug1 := bug0 + file + "', ";
bug2 := bug1 + p + ")";
cmd := bug2$
END GetCmd;
PROCEDURE CheckCmd (IN s: ARRAY OF CHAR): BOOLEAN;
VAR pos: INTEGER;
BEGIN
IF TextCmds.find.find$ = "" THEN RETURN TRUE END;
Strings.Find(s, TextCmds.find.find$, 0, pos);
RETURN pos >= 0;
END CheckCmd;
PROCEDURE CheckDoc (IN path, file: Files.Name; t: TextModels.Model; VAR f: TextMappers.Formatter;
check: BOOLEAN; VAR hit: BOOLEAN);
VAR r: TextModels.Reader; v: Views.View; cmd, cmd0: ARRAY 1024 OF CHAR;
BEGIN
IF InfoDialog.param.expand THEN StdFolds.ExpandFolds(t, TRUE, '') END;
INC(count);
InfoDialog.ShowStatus(count, path$ + file$);
r := t.NewReader(NIL);
r.ReadView(v);
WHILE v # NIL DO
WITH v: StdLinks.Link DO
IF v.leftSide THEN
v.GetCmd(cmd);
IF (cmd # "") & (~check OR Stale(cmd)) (* & CheckCmd(cmd) *) THEN
hit := TRUE;
f.WriteTab; f.WriteTab;
GetCmd(path, file, r.Pos() - 1, cmd0);
f.WriteView(StdLinks.dir.NewLink(cmd0));
f.rider.SetAttr(link);
f.WriteString(cmd);
f.rider.SetAttr(default);
f.WriteView(StdLinks.dir.NewLink(""));
f.WriteLn
END
END
ELSE
END;
r.ReadView(v)
END
END CheckDoc;
PROCEDURE CheckLoc (IN path: Files.Name; loc: Files.Locator;
VAR f: TextMappers.Formatter; check: BOOLEAN);
VAR i: Iterator; fpath, fname: Files.Name; ftype: Files.Type;
v: Views.View; conv: Converters.Converter;
label, label0: INTEGER; hit, hit0: BOOLEAN;
BEGIN
label := f.Pos(); hit := FALSE;
i := New(loc);
ReadFile(i, fname, ftype);
IF fname # "" THEN f.WriteString(path); f.WriteLn END;
hit := FALSE;
WHILE ~DosKeyboard.Break() & (fname # "") DO
MakeDocName(fname);
IF check THEN InfoMissingLinks.Insert(docList, path, fname, org) END; (* --> in = source *)
IF ftype$ = 'odc' THEN
label0 := f.Pos(); hit0 := FALSE;
conv := NIL;
v := Views.Old(Views.dontAsk, loc, fname, conv);
IF (v # NIL) & (v IS TextViews.View) THEN
f.WriteTab; f.WriteString(fname); f.WriteLn;
CheckDoc(path, fname, v(TextViews.View).ThisModel(), f, check, hit0);
IF ~hit0 THEN f.SetPos(label0) END;
hit := hit OR hit0;
END;
END;
ReadFile(i, fname, ftype)
END;
IF ~hit THEN f.SetPos(label) END;
IF InfoDialog.param.include THEN
ReadLoc(i, loc, fname);
WHILE ~DosKeyboard.Break() & (loc # NIL) DO
fpath := path + fname + "/";
CheckLoc(fpath, loc, f, check);
ReadLoc(i, loc, fname)
END;
END;
END CheckLoc;
PROCEDURE Check* (check: BOOLEAN);
VAR root: Files.Locator;
out: TextModels.Model; f: TextMappers.Formatter; title: Views.Title;
v: TextViews.View; path: Files.Name;
BEGIN
InfoDialog.ProofParam;
count := 0;
out := TextModels.dir.New(); f.ConnectTo(out);
IF check THEN
Dialog.MapString("#Info:InconsistentLinks", title);
InfoMissingLinks.New(docList)
ELSE
Dialog.MapString("#Info:Links", title)
END;
v := TextViews.dir.New(out);
Views.OpenAux(v, title); (* set Browser mode: *)
IF check THEN f.WriteString('Link failed:'); f.WriteLn; f.WriteLn END;
default := TextModels.dir.attr;
link := TextModels.NewColor(default, Ports.blue); link := TextModels.NewStyle(link, {Fonts.underline});
path := InfoDialog.param.source$;
root := Files.dir.This(path);
CheckLoc(path, root, f, check);
IF check THEN
f.WriteLn; InfoMissingLinks.Display(f, docList); f.WriteLn; f.WriteString('Ende.'); f.WriteLn
END;
out.Delete(f.Pos(), out.Length());
default := NIL; link := NIL; docList := NIL;
IF DosKeyboard.Break() THEN
DosKeyboard.ResetBreak;
ELSE
Dialog.ShowStatus("");
END;
END Check;
PROCEDURE PathToLoc (IN path: ARRAY OF CHAR; OUT loc: Files.Locator);
VAR i, j: INTEGER; ch: CHAR; name: ARRAY 256 OF CHAR;
BEGIN
loc := Files.dir.This("");
IF path # "" THEN
i := 0; j := 0;
REPEAT
ch := path[i]; INC(i);
IF (ch = "/") OR (ch = 0X) THEN name[j] := 0X; j := 0; loc := loc.This(name)
ELSE name[j] := ch; INC(j)
END
UNTIL (ch = 0X) OR (loc.res # 0)
END
END PathToLoc;
PROCEDURE Open* (path, file: ARRAY OF CHAR; pos: INTEGER);
VAR loc: Files.Locator; v: Views.View; bug: Files.Name; c: TextControllers.Controller;
BEGIN
ASSERT(file # "", 20); ASSERT(pos >= 0, 21);
PathToLoc(path, loc); ASSERT(loc # NIL, 22);
bug := file$;
v := Views.OldView(loc, bug);
IF v # NIL THEN
WITH v: TextViews.View DO
v.DisplayMarks(TextViews.show);
Views.Open(v, loc, bug, NIL);
c := v.ThisController()(TextControllers.Controller);
c.SetCaret(pos);
v.ShowRange(pos, pos + 1, TextViews.focusOnly)
ELSE
HALT(23)
END
END
END Open;
PROCEDURE ListLinks*;
(** Guard: CommandGuard **)
BEGIN
StdCmds.CloseDialog; Check(FALSE)
END ListLinks;
PROCEDURE CheckLinks*;
(** Guard: CommandGuard **)
BEGIN
StdCmds.CloseDialog; Check(TRUE)
END CheckLinks;
END InfoCheckLinks.
| Info/Mod/CheckLinks.odc |
MODULE InfoCmds;
(* Helmut Zinn - *)
IMPORT
Containers, Controllers, Dialog, HostDialog, InfoDialog, StdApi, StdFolds,
TextCmds, TextViews, Views, WinApi;
TYPE DocList = POINTER TO RECORD
filename: ARRAY 256 OF CHAR;
editable: BOOLEAN;
last, next: DocList;
END;
VAR
current: DocList;
editable: BOOLEAN;
PROCEDURE KeepInMind (IN file: ARRAY OF CHAR);
VAR doc: DocList;
BEGIN
IF (current = NIL) OR (current.filename$ # file$) THEN
NEW(doc);
doc.filename := file$;
doc.editable := editable;
doc.last := NIL;
doc.next := NIL;
IF current # NIL THEN
current .next := doc;
doc.last := current;
END;
current := doc;
END;
END KeepInMind;
PROCEDURE SetEditMode*;
VAR v: Views.View; c: Containers.Controller;
BEGIN
v := Controllers.FocusView();
IF (v # NIL) & (v IS Containers.View) THEN
c := v(Containers.View).ThisController();
IF c # NIL THEN
Views.BeginModification(Views.invisible, v);
c.SetOpts(c.opts - {Containers.noFocus, Containers.noSelection} - {Containers.noCaret});
Views.EndModification(Views.invisible, v);
END;
END;
editable := TRUE; IF current # NIL THEN current.editable := TRUE END;
IF (v # NIL) & (v IS TextViews.View) THEN
(* ShowMarks *)
v(TextViews.View).DisplayMarks(TextViews.show)
END;
END SetEditMode;
PROCEDURE SetBrowserMode*;
VAR v: Views.View; c: Containers.Controller;
BEGIN
v := Controllers.FocusView();
IF (v # NIL) & (v IS Containers.View) THEN
c := v(Containers.View).ThisController();
IF c # NIL THEN
Views.BeginModification(Views.invisible, v);
c.SetOpts(c.opts - {Containers.noFocus, Containers.noSelection} + {Containers.noCaret});
Views.EndModification(Views.invisible, v);
END;
END;
editable := FALSE; IF current # NIL THEN current.editable := FALSE END;
IF (v # NIL) & (v IS TextViews.View) THEN
(* HideMarks *)
v(TextViews.View).DisplayMarks(TextViews.hide)
END;
END SetBrowserMode;
PROCEDURE SetEditModeGuard* (VAR par: Dialog.Par);
BEGIN
IF editable THEN par.checked := TRUE ELSE par.checked := FALSE END;
END SetEditModeGuard;
PROCEDURE SetBrowserModeGuard* (VAR par: Dialog.Par);
BEGIN
IF ~editable THEN par.checked := TRUE ELSE par.checked := FALSE END;
END SetBrowserModeGuard;
PROCEDURE OpenDoc* (IN file: ARRAY OF CHAR);
VAR v: Views.View;
BEGIN
KeepInMind(file);
StdApi.OpenDoc(file, v);
IF (v # NIL) & (v IS Containers.View) THEN
IF editable THEN SetEditMode ELSE SetBrowserMode END;
END;
END OpenDoc;
PROCEDURE Select* (IN pat: ARRAY OF CHAR);
BEGIN
IF InfoDialog.param.expand THEN StdFolds.Expand END;
TextCmds.find.find := pat$;
TextCmds.find.ignoreCase := TRUE;
TextCmds.FindFirst('');
Dialog.Update(TextCmds.find);
END Select;
PROCEDURE Start* (IN file: ARRAY OF CHAR);
(* Do Command: Start program or Open file *)
VAR fullname: ARRAY 260 OF CHAR; res: INTEGER; np: WinApi.PtrWSTR;
BEGIN
res := WinApi.ShellExecuteW(0, '', file, '', '', WinApi.SW_SHOWNORMAL);
IF res = WinApi.ERROR_FILE_NOT_FOUND THEN
(* if failed then translate relative filenames to absolute filenames and try again *)
res := WinApi.GetFullPathNameW(file, LEN(fullname), fullname, np);
res := WinApi.ShellExecuteW(0, '', fullname, '', '', WinApi.SW_SHOWNORMAL);
END;
IF res <= 32 THEN
Dialog.ShowParamMsg("#System:FailedToOpen", file, "", "")
END;
END Start;
PROCEDURE Start2* (IN command: ARRAY OF CHAR);
(* Do Command including parameters *)
BEGIN
HostDialog.Start(command$);
END Start2;
PROCEDURE SetTopic* (IN root: ARRAY OF CHAR);
BEGIN
InfoDialog.param.source := root$;
InfoDialog.ProofParam;
END SetTopic;
PROCEDURE OpenTopic* (IN root: ARRAY OF CHAR);
BEGIN
SetTopic(root);
OpenDoc(InfoDialog.param.source$ + 'Inhalt');
END OpenTopic;
PROCEDURE LastDoc*;
BEGIN
IF (current # NIL) & (current.last # NIL) THEN
current := current.last; editable := current.editable;
OpenDoc(current.filename);
END;
END LastDoc;
PROCEDURE NextDoc*;
BEGIN
IF (current # NIL) & (current.next # NIL) THEN
current := current.next; editable := current.editable;
OpenDoc(current.filename);
END;
END NextDoc;
PROCEDURE LastDocGuard* (VAR p: Dialog.Par);
BEGIN
p.disabled := (current = NIL) OR (current.last = NIL)
END LastDocGuard;
PROCEDURE NextDocGuard* (VAR p: Dialog.Par);
BEGIN
p.disabled := (current = NIL) OR (current.next = NIL)
END NextDocGuard;
BEGIN
current := NIL;
editable := TRUE;
END InfoCmds.
| Info/Mod/Cmds.odc |
MODULE InfoCollect;
(*
Collect all files used in the link document
Helmut Zinn -
InfoCollect.Run
*)
IMPORT
DosFileCmds, DosKeyboard, HostFiles, InfoDialog, StdLinks, StdLog, Strings,
TextControllers, TextMappers, TextModels, TextViews, Views;
CONST
pathLen = HostFiles.pathLen;
VAR
dst: ARRAY pathLen OF CHAR;
cnt: INTEGER;
PROCEDURE InitFilename (IN filespec: ARRAY OF CHAR);
BEGIN
cnt := 0;
dst := filespec$;
END InitFilename;
PROCEDURE CreateFilename (OUT filespec: ARRAY OF CHAR);
VAR
sequentialNumber: ARRAY 32 OF CHAR;
BEGIN
INC(cnt);
Strings.IntToStringForm(cnt, 10, 3, '0', FALSE, sequentialNumber);
filespec := dst + sequentialNumber$;
END CreateFilename;
PROCEDURE ExtractFilename (IN cmd: ARRAY OF CHAR; OUT filespec: ARRAY OF CHAR);
VAR a, b, n: INTEGER; s1, s2, s3: ARRAY 256 OF CHAR;
BEGIN
a := 0;
WHILE (cmd[a] # 0X) & (cmd[a] # "'") DO INC(a) END;
b := a + 1;
WHILE (cmd[b] # 0X) & (cmd[b] # "'") DO INC(b) END;
n := LEN(cmd$);
IF b > n THEN b := a + 1 END;
IF b > n THEN n := b + 1 END;
Strings.Extract(cmd, 0, a + 1, s1); (* in front of a - including a *)
Strings.Extract(cmd, a + 1, b - a - 1, s2); (* between a and b *)
Strings.Extract(cmd, b, n - b, s3); (* behind b - including b *)
(* check cmd *)
IF (s1 = "InfoCmds.OpenDoc('") & (s3[0] = "'") & (s3[1] = ")") THEN
filespec := s2$;
ELSE
filespec := "";
StdLog.String('Link not insert into the file list: '); StdLog.String(cmd); StdLog.Ln;
(*
StdLog.String(s1); StdLog.Ln;
StdLog.String(s2); StdLog.Ln;
StdLog.String(s3); StdLog.Ln;
*)
END;
END ExtractFilename;
PROCEDURE TruncateTitle (IN str: ARRAY OF CHAR; OUT title: Views.Title);
VAR s1, s2: Views.Title; n: INTEGER;
BEGIN
n := LEN(str$);
IF n > 63 THEN
Strings.Extract(str, 0, 29, s1);
Strings.Extract(str, n - 29, 29, s2);
title := s1$ + " ... " + s2$
ELSE
title := str$;
END;
END TruncateTitle;
PROCEDURE FileList* (destination: ARRAY OF CHAR);
VAR
t: TextModels.Model; f: TextMappers.Formatter; tv: TextViews.View; title: Views.Title;
cn: TextControllers.Controller;
r: TextModels.Reader;
v: Views.View;
cmd, srcFilespec, dstFilespec: ARRAY pathLen OF CHAR;
BEGIN
InitFilename(destination);
t := TextModels.dir.New();
f.ConnectTo(t);
f.WriteString("auto"); f.WriteLn;
cn := TextControllers.Focus();
IF cn # NIL THEN
r := cn.text.NewReader(NIL);
r.ReadView(v);
WHILE ~DosKeyboard.Break() & (v # NIL) DO
WITH v: StdLinks.Link DO
IF v.leftSide THEN
v.GetCmd(cmd);
ExtractFilename(cmd, srcFilespec);
IF srcFilespec # "" THEN (* if not directory then *)
f.WriteString(srcFilespec); f.WriteTab;
CreateFilename(dstFilespec);
f.WriteString(dstFilespec); f.WriteLn;
END;
END
ELSE
END;
r.ReadView(v)
END;
IF DosKeyboard.Break() THEN DosKeyboard.ResetBreak END;
END;
tv := TextViews.dir.New(t);
TruncateTitle(destination, title);
(* set Browser mode: *)
Views.OpenAux(tv, title)
END FileList;
PROCEDURE CreateFileList*;
BEGIN
InfoDialog.ProofParam;
FileList(InfoDialog.param.source);
END CreateFileList;
PROCEDURE ReadField (VAR sc: TextMappers.Scanner; OUT s: ARRAY OF CHAR);
VAR ch: CHAR; i: INTEGER;
BEGIN
i := 0;
ch := sc.rider.char;
WHILE (ch = TextModels.line) OR (ch = TextModels.tab) OR (ch = TextModels.para) DO
sc.rider.ReadChar(ch)
END;
WHILE ~(sc.rider.eot
OR (ch = TextModels.line) OR (ch = TextModels.tab) OR (ch = TextModels.para) OR (i > 254)) DO
s[i] := ch; INC(i);
sc.rider.ReadChar(ch);
END;
s[i] := 0X;
END ReadField;
PROCEDURE MoveFiles*;
VAR
cn: TextControllers.Controller;
sc: TextMappers.Scanner;
ch: CHAR;
srcFilespec, dstFilespec: ARRAY pathLen OF CHAR;
BEGIN
StdLog.Ln; StdLog.String("Move Files started ..."); StdLog.Ln;
cn := TextControllers.Focus();
IF cn # NIL THEN
sc.ConnectTo(cn.text);
sc.Scan; (* skip auto *)
sc.rider.ReadChar(ch);
WHILE ~DosKeyboard.Break() & ~sc.rider.eot DO
ReadField(sc, srcFilespec);
ReadField(sc, dstFilespec);
DosFileCmds.Copy(srcFilespec + ".odc", dstFilespec + ".odc");
DosFileCmds.Delete(srcFilespec + ".odc");
sc.rider.ReadChar(ch);
END;
IF DosKeyboard.Break() THEN DosKeyboard.ResetBreak END;
END;
StdLog.String("Move Files done."); StdLog.Ln;
END MoveFiles;
END InfoCollect.
| Info/Mod/Collect.odc |
MODULE InfoDialog;
(*
Dialog for creating link list, collection files and correcting links
Helmut Zinn -
"StdCmds.OpenToolDialog('Info/Rsrc/CreateLinks', 'Create Links')"
"StdCmds.OpenToolDialog('Info/Rsrc/CollectFiles', 'Collect Files')"
*)
IMPORT
Dialog, Files, HostFiles, PacDirChoose, Strings, TextCmds, TextControllers, TextMappers;
CONST
pathLen = HostFiles.pathLen;
VAR
param*: RECORD
source*: ARRAY pathLen OF CHAR;
filter*: ARRAY 16 OF CHAR;
useRelativePath*: BOOLEAN;
include*, expand*: BOOLEAN;
sortHit*, listDate*: BOOLEAN;
END;
relative: BOOLEAN;
workingDir: ARRAY pathLen OF CHAR;
(* used by UpdateGuard *)
cn: TextControllers.Controller;
sc: TextMappers.Scanner;
PROCEDURE GetWorkingPath (VAR workingDir: ARRAY OF CHAR);
VAR i: INTEGER; loc: Files.Locator;
BEGIN
loc := Files.dir.This("");
workingDir := loc(HostFiles.Locator).path$ + '/';
FOR i := 0 TO LEN(workingDir$) DO
IF workingDir[i] = '\' THEN workingDir[i] := '/' END;
END;
END GetWorkingPath;
PROCEDURE Initialise;
BEGIN
param.source := "Archiv/Help/Uhl/";
param.filter := 'odc';
param.useRelativePath := TRUE;
param.include := TRUE;
param.expand := FALSE;
param.sortHit := TRUE;
param.listDate := FALSE;
TextCmds.find.ignoreCase := TRUE;
(* BlackBox Working Directory *)
GetWorkingPath(workingDir);
PacDirChoose.SetStartingPath(workingDir+param.source);
(* Show the Directory path relative to Working Directory *)
relative := param.useRelativePath;
END Initialise;
(* Browse directory *)
PROCEDURE FixRoot* (IN path: Files.Name);
VAR i, n: INTEGER;
BEGIN
IF param.useRelativePath THEN
i := 0;
n := LEN(workingDir$);
WHILE (i < n) & (CAP(workingDir[i]) = CAP(Strings.Upper(path[i]))) DO INC(i) END;
IF i < n THEN i := 0; relative := FALSE ELSE i := n; relative := TRUE END;
Strings.Extract(path$, i, LEN(path$) - i, param.source);
ELSE
IF relative THEN param.source := workingDir$ + path$ ELSE param.source := path$ END;
relative := FALSE;
END;
Dialog.Update(param);
END FixRoot;
PROCEDURE BrowseSource*;
BEGIN
PacDirChoose.Choose(FixRoot);
END BrowseSource;
(* Check parameters & show status *)
PROCEDURE ProofParam*;
VAR i, n: INTEGER;
BEGIN
FOR i := 0 TO LEN(param.source$) - 1 DO
IF param.source[i] = '\' THEN param.source[i] := '/' END;
END;
n := LEN(param.source$);
IF (n > 0) & (param.source[n - 1] # '/') THEN param.source := param.source + '/' END;
IF param.source = '/' THEN param.source := '' END;
Dialog.Update(param);
END ProofParam;
PROCEDURE ShowStatus* (count: INTEGER; IN msg: ARRAY OF CHAR);
VAR
s: ARRAY 10 OF CHAR;
note: ARRAY 128 OF CHAR;
BEGIN
Strings.IntToString(count, s);
Strings.Extract(s$ + ' ' + msg$, 0, 127, note);
Dialog.ShowStatus(note$);
END ShowStatus;
(* Guards & Notifiers - TextCmds.FocusGuard used too *)
PROCEDURE ReplaceGuard* (VAR par: Dialog.Par);
BEGIN
par.disabled := (TextCmds.find.find$ = "") OR (TextCmds.find.replace$ = "");
END ReplaceGuard;
PROCEDURE UpdateGuard* (VAR par: Dialog.Par);
BEGIN
par.disabled := TRUE;
cn := TextControllers.Focus();
IF cn # NIL THEN
sc.ConnectTo(cn.text);
sc.Scan;
IF (sc.type = TextMappers.string) & (sc.string = "auto") THEN par.disabled := FALSE END;
END;
END UpdateGuard;
PROCEDURE UseRelativePathNotifier* (op, from, to: INTEGER);
BEGIN
IF op = Dialog.changed THEN
FixRoot(param.source$);
Dialog.Update(param);
END;
END UseRelativePathNotifier;
BEGIN
Initialise;
END InfoDialog.
| Info/Mod/Dialog.odc |
MODULE InfoForEachEntry;
(*
Do for all entries in the list
Helmut Zinn -
*)
IMPORT
Dialog, DosKeyboard, StdCmds, StdLog, Strings,
TextCmds, TextControllers, TextMappers, TextModels;
TYPE
Function = PROCEDURE (IN path, file: ARRAY OF CHAR; t: TextModels.Model; VAR hit: INTEGER);
PROCEDURE Log (IN path, file: ARRAY OF CHAR; t: TextModels.Model; VAR hit: INTEGER);
BEGIN
hit := 1;
(*
StdLog.String(TextCmds.find.find); StdLog.Tab;
StdLog.String(TextCmds.find.replace); StdLog.Ln;
*)
END Log;
PROCEDURE ReadField (VAR sc: TextMappers.Scanner; OUT s: ARRAY OF CHAR);
VAR ch: CHAR; i: INTEGER;
BEGIN
i := 0;
ch := sc.rider.char;
WHILE (ch = TextModels.line) OR (ch = TextModels.tab) OR (ch = TextModels.para) DO
sc.rider.ReadChar(ch)
END;
WHILE ~(sc.rider.eot
OR (ch = TextModels.line) OR (ch = TextModels.tab) OR (ch = TextModels.para) OR (i > 254)) DO
s[i] := ch; INC(i);
sc.rider.ReadChar(ch);
END;
s[i] := 0X;
END ReadField;
PROCEDURE Do* (Task: Function; IN path, filename: ARRAY OF CHAR; t: TextModels.Model; VAR count: INTEGER);
VAR
cn: TextControllers.Controller;
sc: TextMappers.Scanner;
ch: CHAR;
firstField, secondField: ARRAY 256 OF CHAR;
hit: INTEGER;
BEGIN
count := 0;
hit := 0;
cn := TextControllers.Focus();
IF cn # NIL THEN
sc.ConnectTo(cn.text);
sc.Scan; (* skip auto *)
IF (sc.type = TextMappers.string) & (sc.string = "auto") THEN
sc.rider.ReadChar(ch);
WHILE ~DosKeyboard.Break() & ~sc.rider.eot DO
ReadField(sc, firstField);
ReadField(sc, secondField);
TextCmds.find.find := firstField$;
TextCmds.find.replace := secondField$;
IF TextCmds.find.ignoreCase THEN
Strings.ToLower(TextCmds.find.find, TextCmds.find.find);
END;
Dialog.Update(TextCmds.find);
Task(path, filename, t, hit); (* do the task for each pair of fields *)
count := count + hit;
sc.rider.ReadChar(ch);
END;
END;
END;
END Do;
PROCEDURE LogList*;
VAR count: INTEGER;
BEGIN
(* StdCmds.OpenToolDialog('Info/Rsrc/ReplaceAll', 'Replace in all Docu'); *)
Do(Log, "", "", NIL, count);
StdLog.Int(count); StdLog.String(" entries."); StdLog.Ln;
END LogList;
END InfoForEachEntry.
| Info/Mod/ForEachEntry.odc |
MODULE InfoForEachFile;
(*
Do for all documents
Helmut Zinn -
"InfoForEachFile.Test"
*)
IMPORT
Dialog, DosKeyboard, (* DosSort, *) Files, StdLog, Strings;
TYPE
Function = PROCEDURE (IN path, filename, filetype: ARRAY OF CHAR);
VAR
Task: Function;
includeSubdirectories: BOOLEAN;
count: INTEGER;
PROCEDURE Log (IN path, filename, filetype: ARRAY OF CHAR);
BEGIN
StdLog.Int(count); StdLog.Char(' '); StdLog.String(filename); StdLog.Ln;
END Log;
PROCEDURE Search (IN path: ARRAY OF CHAR);
VAR
files: Files.FileInfo; dirs: Files.LocInfo;
loc: Files.Locator; p: Files.Name;
BEGIN
loc := Files.dir.This(path);
files := Files.dir.FileList(loc);
(* DosSort.FileList(files); *)
WHILE ~DosKeyboard.Break() & (files # NIL) DO
INC(count);
Strings.IntToString(count, p);
p := p + ' ' + path + files.name;
Dialog.ShowStatus(p);
Task(path, files.name, files.type); (* do the task for each file *)
files := files.next
END;
IF includeSubdirectories THEN
loc := Files.dir.This(path);
dirs := Files.dir.LocList(loc);
(* DosSort.LocList(dirs); *)
WHILE ~DosKeyboard.Break() & (dirs # NIL) DO
p := path + dirs.name + "/";
Search(p);
dirs := dirs.next
END;
END;
END Search;
PROCEDURE Do* (task: Function; IN path: ARRAY OF CHAR; include: BOOLEAN);
BEGIN
Task := task;
includeSubdirectories := include;
count := 0;
Search(path);
Dialog.ShowStatus("");
IF DosKeyboard.Break() THEN DosKeyboard.ResetBreak END;
END Do;
PROCEDURE Test*;
BEGIN
Do(Log, "Help/", TRUE);
END Test;
END InfoForEachFile.
| Info/Mod/ForEachFile.odc |
MODULE InfoIndex;
(* Helmut Zinn *)
(* Build the Cross-Referenz List *)
(*
InfoIndex.CreateNewIndex will scan through all files and generate an index of all words,
except those listed as trivial.
Trival word should be listet in Info/Rsrc/Strings following a "Tab" and a "." (Period).
*)
IMPORT
Converters, Dialog, Documents, DosKeyboard, (* DosSort, *)
Files, Fonts, InfoDialog, InfoLook, Models, Ports, StdCmds,
StdFolds, StdLog, Strings, TextCmds, TextMappers, TextModels, TextViews, Views;
CONST
minWordLen = 2;
maxWordLen = 32;
rootChar = "0"; (* first letter is zero *)
fileName = "Index.odc";
TYPE
DocNames = POINTER TO RECORD
path: InfoLook.DynString;
name: InfoLook.DynString;
next: DocNames
END;
RefList = POINTER TO RECORD
docNum: INTEGER;
count: INTEGER; (* word occurrences within document *)
next: RefList
END;
WordTree = POINTER TO RECORD
word: InfoLook.DynString;
ref: RefList;
count: INTEGER; (* word occurrences across documents *)
left, right: WordTree
END;
VAR
cntDir, cntFiles, cntWords, cntRefs: INTEGER;
dName: DocNames;
wTree: WordTree;
label: ARRAY 8 OF CHAR;
cmdstr: ARRAY 512 OF CHAR;
docStr: ARRAY 512 OF CHAR;
wordChar: ARRAY 2 OF CHAR;
str: ARRAY 4 OF CHAR;
PROCEDUREWriteOpenFold (VARf: TextMappers.Formatter; IN label: ARRAYOFCHAR);
VAR
fold: StdFolds.Fold;
t: TextModels.Model;
BEGIN
t := TextModels.dir.NewFromString(' ' + label + ' '); (* convert label string into a text model *)
fold := StdFolds.dir.New(StdFolds.expanded, label$, t);
f.WriteView(fold);
f.WriteLn;
END WriteOpenFold;
PROCEDUREWriteCloseFold (VAR f: TextMappers.Formatter);
VAR
fold: StdFolds.Fold;
len: INTEGER;
BEGIN
fold := StdFolds.dir.New(StdFolds.expanded, "", NIL);
f.WriteView(fold);
fold.Flip; (* swap long-form text, now between the two fold views, with hidden short-form text *)
len := f.rider.Base().Length(); (* determine the text carrier's new length *)
f.SetPos(len) (* position the formatter to the end of the text *)
END WriteCloseFold;
PROCEDURE (wTree: WordTree) Write (VAR f: TextMappers.Formatter; VAR letter: CHAR), NEW;
(*
-- moved to top - stack overflow at recursion - need redesign
VAR
label: ARRAY 8 OF CHAR;
cmdstr: ARRAY 256 OF CHAR;
docStr: ARRAY 512 OF CHAR;
wordChar: ARRAY 2 OF CHAR;
str: ARRAY 4 OF CHAR;
*)
PROCEDURE AppendDocLinksFiFo (doc: RefList); (* WriteDocLinksFiFo *)
(* Appending encoded docNum and count to docStr.
Due to recursion, this proc. will process the document
at the far end of the link (d1) first. *)
BEGIN
IF doc.next # NIL THEN
AppendDocLinksFiFo(doc.next) (* dive to the bottom *)
END;
IF LEN(docStr$) > 200 THEN
(* Overflow: StdLog.String (wTree.name^); StdLog.Ln; *)
Strings.IntToString(wTree.count, label);
cmdstr := "InfoLook.Expand('" + wTree.word^$ + "', '" + docStr + "')";
InfoLook.WriteLink(f, label, cmdstr);
f.WriteString(" + ");
docStr := "";
END;
Strings.IntToString(doc.docNum, label);
docStr := docStr + label + " ";
Strings.IntToString(doc.count, label);
docStr := docStr + label + " ";
END AppendDocLinksFiFo;
BEGIN
IF ~DosKeyboard.Break() & (wTree.left # NIL) THEN wTree.left.Write(f, letter) END;
IF ~DosKeyboard.Break() THEN
Strings.ToUpper(wTree.word^, wordChar);
IF wordChar[0] # letter THEN
(* About to start a new letter; fold the previous *)
WriteCloseFold(f);
f.WriteLn;
letter := wordChar[0]; (* new letter *)
str[0] := letter;
str[1] := CHR(0);
InfoDialog.ShowStatus(cntFiles, str$);
WriteOpenFold(f, str$);
END;
f.WriteString(wTree.word^); f.WriteTab;
(* The document numbers are linked with the first one at the far end:
wTree.ref -> dn -> ... -> d3 -> d2 -> d1 -> NIL *)
(* --- WriteDocLinksFiFo(wTree.ref) - Using AppendDocLinksFiFo produces a "small" index. *)
docStr := "";
AppendDocLinksFiFo(wTree.ref); (* appending to docStr *)
Strings.IntToString(wTree.count, label);
cmdstr := "InfoLook.Expand('" + wTree.word^$ + "', '" + docStr + "')";
InfoLook.WriteLink(f, label, cmdstr);
f.WriteLn;
END;
IF ~DosKeyboard.Break() & (wTree.right # NIL) THEN wTree.right.Write(f, letter) END
END Write;
PROCEDURE WriteCrossReferenceList (docList: DocNames; wTree: WordTree);
VAR
t: TextModels.Model;
f: TextMappers.Formatter;
letter: CHAR;
lettersBeg: INTEGER;
new, mono: TextModels.Attributes;
v: TextViews.View;
loc: Files.Locator;
filename: Files.Name;
conv: Converters.Converter;
res: INTEGER;
str: ARRAY 4 OF CHAR;
PROCEDURE GetDocNamesFiFo (docPN: DocNames);
(* Due to recursion, this proc. will process the document path/name
at the far end of the link (d1) first. *)
BEGIN
IF docPN.next # NIL THEN
GetDocNamesFiFo(docPN.next)
ELSE
f.WriteInt(cntFiles); f.WriteLn
END;
f.WriteString(docPN.path); f.WriteTab;
f.WriteString(docPN.name); f.WriteLn;
END GetDocNamesFiFo;
BEGIN
t := TextModels.dir.New(); (* create a new, empty text *)
f.ConnectTo(t); (* connect a formatter to the text *)
(* Write document list *)
WriteOpenFold(f, InfoDialog.param.source$ + "Documents");
GetDocNamesFiFo(docList);
WriteCloseFold(f);
f.WriteLn;
(* Write word list *)
new := f.rider.attr;
new := TextModels.NewSize(new, 12 * Fonts.point);
f.rider.SetAttr(new); (* change current attributes of formatter *)
f.WriteLn;
letter := rootChar;
lettersBeg := t.Length(); (* we'll start applying the mono font here *)
str[0] := letter;
str[1] := CHR(0);
InfoDialog.ShowStatus(cntFiles, str$);
WriteOpenFold(f, str$);
wTree.Write(f, letter);
WriteCloseFold(f); (* Z *)
InfoDialog.ShowStatus(cntFiles, str$);
(* Picking a fixed-width font for the folds' capital letters *)
mono := f.rider.attr; (* save plain text attributes for later use *)
mono := TextModels.NewTypeface(mono, "Courier New");
mono := TextModels.NewSize(mono, 16 * Fonts.point);
mono := TextModels.NewColor(mono, Ports.red);
t.SetAttr(lettersBeg, t.Length(), mono);
(* Open View in BrowserMode *)
StdCmds.CloseDialog;
v := TextViews.dir.New(t);
Views.OpenView(v);
IF ~DosKeyboard.Break() THEN
loc := Files.dir.This(InfoDialog.param.source);
filename := fileName;
conv := NIL;
Views.Register(v, Views.ask, loc, filename, conv, res);
END;
END WriteCrossReferenceList;
PROCEDURE NewWordTree (): WordTree;
VAR
wTree: WordTree;
doc: RefList;
BEGIN
NEW(wTree);
NEW(wTree.word, 2);
wTree.word[0] := rootChar; wTree.word[1] := 0X;
NEW(doc); doc.docNum := 0; doc.next := NIL; (* to please WriteDocListFiFo *)
wTree.ref := doc;
wTree.count := 0;
wTree.left := NIL; wTree.right := NIL;
RETURN wTree
END NewWordTree;
PROCEDURE (t: WordTree) NameHigherThan (newName: ARRAY OF CHAR): BOOLEAN, NEW;
VAR
oldUpper, newUpper: ARRAY 256 OF CHAR;
BEGIN
IF TextCmds.find.ignoreCase THEN
RETURN t.word^ > newName;
END;
Strings.ToUpper(t.word^, oldUpper);
Strings.ToUpper(newName, newUpper);
IF oldUpper = newUpper THEN
RETURN t.word^ > newName
ELSE
RETURN oldUpper > newUpper
END
END NameHigherThan;
PROCEDURE (t: WordTree) Insert (newName: ARRAY OF CHAR), NEW;
VAR
p, father: WordTree;
doc: RefList;
BEGIN
p := t;
REPEAT
father := p;
IF newName = p.word^ THEN
(* Found word in tree *)
IF cntFiles # p.ref.docNum THEN
(* Current document not same as where word was found last *)
INC(cntRefs);
NEW(doc); doc.docNum := cntFiles; doc.count := 0;
doc.next := p.ref; p.ref := doc
END;
INC(p.count); INC(p.ref.count); RETURN
END;
IF p.NameHigherThan(newName) THEN
p := p.left
ELSE
p := p.right
END
UNTIL p = NIL;
INC(cntWords);
NEW(p); p.left := NIL; p.right := NIL;
p.word := InfoLook.MakeDynString(newName$);
INC(cntRefs);
NEW(doc); doc.docNum := cntFiles;
doc.next := NIL; p.ref := doc;
p.count := 1; doc.count := 1;
IF father.NameHigherThan(newName) THEN
father.left := p
ELSE
father.right := p
END
END Insert;
PROCEDURE IsLetter (ch: CHAR): BOOLEAN;
BEGIN
IF ('A' <= ch) & (ch <= 'Z') THEN RETURN TRUE END;
IF ('a' <= ch) & (ch <= 'z') THEN RETURN TRUE END;
(*
[192] [193] [194] [195] [196] [197] [198] [199]
[200] [201] [202] [203] [204] [205] [206] [207]
[208] [209] [210] [211] [212] [213] [214] [215]
[216] [217] [218] [219] [220] [221] [222] [223]
[224] [225] [226] [227] [228] [229] [230] [231]
[232] [233] [234] [235] [236] [237] [238] [239]
[240] [241] [242] [243] [244] [245] [246] [247]
[248] [249] [250] [251] [252] [253] [254] [255]
*)
IF ('' <= ch) & (ch <= '') THEN RETURN TRUE END;
IF ('' <= ch) & (ch <= '') THEN RETURN TRUE END;
IF ('' <= ch) & (ch <= '') THEN RETURN TRUE END;
RETURN FALSE;
END IsLetter;
PROCEDURE IsDigit (ch: CHAR): BOOLEAN;
BEGIN
RETURN (('0' <= ch) & (ch <= '9'));
END IsDigit;
PROCEDURE ReadWord (r: TextModels.Reader; VAR word: ARRAY OF CHAR);
VAR
i: INTEGER;
ch: CHAR;
BEGIN
REPEAT
i := 0;
r.ReadChar(ch);
WHILE ~r.eot & ~IsLetter(ch) & ~IsDigit(ch) DO (* skip until letter *)
r.ReadChar(ch)
END;
WHILE ~r.eot & (IsLetter(ch) OR IsDigit(ch) OR (ch = TextModels.softhyphen)) DO (* scan word *)
(* # $ % & ( ) * + - / _ . , [ ] *)
IF ch # TextModels.softhyphen THEN
IF TextCmds.find.ignoreCase THEN ch := Strings.Lower(ch); END;
IF i < maxWordLen - 1 THEN word[i] := ch; INC(i) END;
END;
r.ReadChar(ch)
END;
word[i] := 0X;
UNTIL r.eot OR (i >= minWordLen);
END ReadWord;
PROCEDURE ScanDoc (IN path: ARRAY OF CHAR; IN fname: Files.Name; m: TextModels.Model);
VAR
r: TextModels.Reader;
word, lexWord, wordFromMap: ARRAY 256 OF CHAR;
BEGIN
r := m.NewReader(NIL);
r.SetPos(0);
WHILE ~r.eot DO
ReadWord(r, word);
IF word # "" THEN
lexWord := "#Info:" + word$;
Dialog.MapString(lexWord$, wordFromMap);
IF wordFromMap # "." THEN
(* Die Aufgabe fr das Dokument ausfhren, z.B.: HostCmds.Print *)
wTree.Insert(word);
END;
(* Skip coded text *)
IF (word = "StdCoder") OR (word = "PacCoder") OR (word = "Decode")
OR (word = "stdcoder") OR (word = "paccoder") OR (word = "decode") THEN
REPEAT
ReadWord(r, word);
UNTIL (word = "end") OR (word = "AtEndOfEncoding") OR (word = "atendofencoding") OR r.eot;
END
END
END
END ScanDoc;
PROCEDURE InsertIntoNameList (IN path, name: ARRAY OF CHAR);
VAR docPN: DocNames;
BEGIN
NEW(docPN);
docPN.path := InfoLook.MakeDynString(path$);
docPN.name := InfoLook.MakeDynString(name$);
docPN.next := dName; dName := docPN;
END InsertIntoNameList;
PROCEDURE ScanLoc (path: ARRAY OF CHAR);
VAR
root: Files.Locator;
locs: Files.LocInfo;
files: Files.FileInfo;
conv: Converters.Converter;
m: Models.Model;
vw: Views.View;
BEGIN
INC(cntDir);
root := Files.dir.This(path);
files := Files.dir.FileList(root);
(* DosSort.FileList(files); *)
(* for all documents in the directory do *)
WHILE ~DosKeyboard.Break() & (files # NIL) DO
(* The Extension files.type$ is always lower case *)
IF (InfoDialog.param.filter$ = '') OR (InfoDialog.param.filter$ = files.type$) THEN
INC(cntFiles);
InfoDialog.ShowStatus(cntFiles, path$ + files.name$);
InsertIntoNameList(path, files.name);
conv := NIL;
vw := Views.Old(Views.dontAsk, root, files.name, conv);
IF vw IS Documents.Document THEN vw := vw(Documents.Document).ThisView() END;
IF(vw # NIL) & (vw IS TextViews.View) THEN
m := vw.ThisModel();
WITH m: TextModels.Model DO
IF InfoDialog.param.expand THEN StdFolds.ExpandFolds(m, TRUE, '') END;
ScanDoc(path, files.name, m)
END;
END;
END;
files := files.next
END;
IF InfoDialog.param.include THEN
locs := Files.dir.LocList(root);
(* DosSort.LocList(locs); *)
(* for all subdirectories in the directory do *)
WHILE ~DosKeyboard.Break() & (locs # NIL) DO
ScanLoc(path$ + locs.name$ + "/");
locs := locs.next
END;
END;
END ScanLoc;
PROCEDURE CreateNewIndex*;
BEGIN
InfoDialog.ProofParam;
Dialog.showsStatus := TRUE;
cntDir := 0; cntFiles := 0; cntWords := 0; cntRefs := 0;
dName := NIL;
wTree := NewWordTree();
ScanLoc(InfoDialog.param.source);
IF ~DosKeyboard.Break() THEN
WriteCrossReferenceList(dName, wTree);
END;
IF DosKeyboard.Break() THEN
DosKeyboard.ResetBreak;
ELSE
StdLog.String(InfoDialog.param.source); StdLog.Ln;
StdLog.Char(" "); StdLog.Int(cntDir); StdLog.String(" Directories"); StdLog.Ln;
StdLog.Char(" "); StdLog.Int(cntFiles); StdLog.String(" Documents"); StdLog.Ln;
StdLog.Char(" "); StdLog.Int(cntWords); StdLog.String(" Words"); StdLog.Ln;
StdLog.Char(" "); StdLog.Int(cntRefs); StdLog.String(" Reference"); StdLog.Ln;
InfoDialog.ShowStatus(cntFiles, '');
Dialog.Beep (* done *)
END;
wTree := NIL;
dName := NIL;
END CreateNewIndex;
END InfoIndex.
| Info/Mod/Index.odc |
MODULE InfoLinks;
(*
-- Create a link list about the contents of a dieretory.
-- This module is a modified ObxLinks version.
-- Other samples are
-- DosListCmds, Epse21ObxModules, Epse21SysModules, S4System & TboxBook
-- Helmut Zinn
--
-- "InfoLinks.Directory('')"
-- "InfoLinks.Directory('Archiv/')"
--
-- "StdCmds.OpenToolDialog('Dos/Rsrc/ListCmds', '#Dos:List File or Directory')"
-- "StdCmds.OpenToolDialog('Info/Rsrc/CreateLinks', '#Info:Link Documents')"
-- "StdCmds.OpenToolDialog('Info/Rsrc/LinkList', '#Info:List Files')" <-- neu nicht fertig
--
-- InfoLinks.OpenExternal replace the Dialog.OpenExternal for using BlackBox in Wine
*)
IMPORT
Dialog, DosTextCmds, InfoDialog, InfoCmds,
Files, Fonts, Ports, StdLinks, StdStamps, Strings,
TextMappers, TextModels, TextViews, Views;
CONST
callXed = FALSE; (* use editor xed or blackbox - utf8 *)
underline = FALSE;
cmdLink = "InfoLinks.Directory('";
cmdExternal = "InfoLinks.OpenExternal('";
cmdOpen = "InfoCmds.OpenDoc('";
cmdStart = "InfoCmds.Start('";
end = "')";
PROCEDURE WriteLink (VAR fm: TextMappers.Formatter; IN cmd, path, name: ARRAY OF CHAR);
VAR
vw: Views.View;
BEGIN
vw := StdLinks.dir.NewLink(cmd + path + end);
fm.WriteView(vw); (* insert left link view in text *)
fm.WriteString(name);
vw := StdLinks.dir.NewLink("");
fm.WriteView(vw); (* insert right link view in text *)
fm.WriteLn;
END WriteLink;
PROCEDURE PathToLoc (IN path: ARRAY OF CHAR; OUT loc: Files.Locator);
VAR i, j: INTEGER; ch: CHAR; name: ARRAY 256 OF CHAR;
BEGIN
loc := Files.dir.This("");
IF path # "" THEN
i := 0; j := 0;
REPEAT
ch := path[i]; INC(i);
IF (ch = "/") OR (ch = 0X) THEN name[j] := 0X; j := 0; loc := loc.This(name)
ELSE name[j] := ch; INC(j)
END
UNTIL (ch = 0X) OR (loc.res # 0)
END
END PathToLoc;
PROCEDURE TruncateTitle (IN str: ARRAY OF CHAR; OUT title: Views.Title);
VAR s1, s2: Views.Title; n: INTEGER;
BEGIN
n := LEN(str$);
IF n > 63 THEN
Strings.Extract(str, 0, 29, s1);
Strings.Extract(str, n - 29, 29, s2);
title := s1$ + " ... " + s2$
ELSE
title := str$;
END;
END TruncateTitle;
PROCEDURE LastIndexOf (IN this: ARRAY OF CHAR; c: CHAR): INTEGER;
VAR k, n: INTEGER;
BEGIN
n := LEN(this$) - 1;
FOR k := 0 TO n DO
IF this[n - k] = c THEN RETURN n - k END
END;
RETURN - 1
END LastIndexOf;
PROCEDURE GetFilename (IN filename: ARRAY OF CHAR; OUT file: ARRAY OF CHAR);
VAR pos: INTEGER;
BEGIN
pos := LastIndexOf(filename, '.');
IF pos < 0 THEN
file := filename$;
ELSE
Strings.Extract(filename, 0, pos, file); (* before & without . *)
END;
END GetFilename;
PROCEDURE GetExtension (IN filename: ARRAY OF CHAR; OUT extension: ARRAY OF CHAR);
VAR pos, pos2, pos3: INTEGER;
BEGIN
(* Split "filename" into "file" & "extension" *)
pos := LastIndexOf(filename, '.');
pos2 := LastIndexOf(filename, '/');
pos3 := LastIndexOf(filename, '\');
IF (pos < 0) OR (pos < pos2) OR (pos < pos3) THEN
extension := "";
ELSE
Strings.Extract(filename, pos + 1, LEN(filename$) - pos, extension); (* behind . *)
END;
END GetExtension;
PROCEDURE Directory* (IN path: ARRAY OF CHAR);
VAR
tm: TextModels.Model; fm: TextMappers.Formatter; tv: TextViews.View;
textAttr, headerAttr, linkAttr: TextModels.Attributes;
loc: Files.Locator; li: Files.LocInfo; fi: Files.FileInfo;
fn, cmd: ARRAY 256 OF CHAR; title: Views.Title;
BEGIN
ASSERT((path="") OR (path[LEN(path$)-1] = "/"), 100);
tm := TextModels.dir.New();
fm.ConnectTo(tm);
(* text attribute *)
textAttr := fm.rider.attr;
textAttr := TextModels.NewTypeface(textAttr, "Calibri");
textAttr := TextModels.NewSize(textAttr, 12 * Fonts.point);
(* header attribute *)
headerAttr := textAttr;
headerAttr := TextModels.NewWeight(headerAttr, Fonts.bold);
headerAttr := TextModels.NewSize(headerAttr, 16 * Fonts.point);
(* link attribute *)
linkAttr := textAttr;
linkAttr := TextModels.NewColor(linkAttr, Ports.blue);
IF underline THEN
linkAttr := TextModels.NewStyle(linkAttr, linkAttr.font.style + {Fonts.underline});
END;
(* write head line *)
fm.rider.SetAttr(headerAttr); (* change current attributes of formatter *)
WriteLink(fm, cmdExternal, path, path);
fm.rider.SetAttr(textAttr); (* reset current attributes of formatter *)
(* list directories *)
fm.WriteLn;
fm.WriteString("Directories"); fm.WriteLn;
(* generate list of all locations *)
PathToLoc(path, loc);
li := Files.dir.LocList(loc);
WHILE li # NIL DO (* no particular sorting order is guaranteed *)
fm.rider.SetAttr(linkAttr); (* change current attributes of formatter *)
WriteLink(fm, cmdLink, path + li.name + '/', li.name);
fm.rider.SetAttr(textAttr); (* reset current attributes of formatter *)
li := li.next
END;
(* list files *)
fm.WriteLn;
fm.WriteString("Files"); fm.WriteLn;
(* generate a list of all files *)
fi := Files.dir.FileList(loc);
WHILE fi # NIL DO (* no particular sorting order is guaranteed *)
IF fi.type = "odc" THEN (* there is a converter for this file type *)
GetFilename(fi.name, fn);
cmd := cmdOpen;
ELSE
fn := fi.name$;
IF Dialog.IsWine() OR Dialog.IsLinux() THEN cmd := cmdExternal ELSE cmd := cmdStart END;
END;
fm.rider.SetAttr(linkAttr); (* change current attributes of formatter *)
WriteLink(fm, cmd, path + fn, fn);
fm.rider.SetAttr(textAttr); (* reset current attributes of formatter *)
fi := fi.next
END;
fm.WriteLn;
fm.WriteString("Ende. "); fm.WriteView(StdStamps.New()); fm.WriteLn;
(* open the view in Browser mode to show the result *)
tv := TextViews.dir.New(tm);
TruncateTitle(path, title);
Views.OpenAux(tv, title)
END Directory;
PROCEDURE CreateLinkList*;
BEGIN
InfoDialog.ProofParam;
Directory(InfoDialog.param.source);
END CreateLinkList;
PROCEDURE OpenExternal* (IN filename: ARRAY OF CHAR);
VAR file, extension: ARRAY 256 OF CHAR; call: INTEGER;
BEGIN
IF Dialog.IsWine() THEN
GetExtension(filename, extension);
file := filename$;
Strings.ToLower(extension, extension);
IF ('A' <= CAP(file[0])) & (CAP(file[0]) <= 'Z') & (file[1] = ':') THEN
Strings.Extract(file, 2, LEN(file$) - 2, file); (* cut drive letter *)
file := file;
END;
call := 0;
IF (extension = "odc") THEN call := 1
ELSIF (extension = "") THEN call := 2
ELSIF (extension = "htm") OR (extension = "html") THEN call := 3
ELSIF (extension = "jpg") OR (extension = "png") OR (extension = "bmp") THEN call := 4
ELSIF (extension = "odt") OR (extension = "doc") OR (extension = "docx") THEN call := 5
ELSIF (extension = "ods") OR (extension = "xls") OR (extension = "xlsx") THEN call := 5
ELSIF (extension = "odp") OR (extension = "ppt") OR (extension = "pptx") THEN call := 5
ELSIF (extension = "pdf") THEN call := 6
ELSIF (extension = "java") THEN call := 9
ELSIF (extension = "py") THEN call := 7
ELSIF (extension = "txt") OR (extension = "log") OR (extension = "sh") THEN
IF callXed THEN call := 8 (* editor *) ELSE call := 9 (* blackbox - utf8 *) END;
END;
CASE call OF
| 1: InfoCmds.OpenDoc(filename) (* blackbox - odc *)
| 2: Dialog.RunExternal('/usr/bin/nemo ' + '"' + file + '"') (* dateimanager *)
| 3: Dialog.RunExternal('/usr/bin/brave-browser ' + '"' + file + '"') (* internet browser *)
| 4: Dialog.RunExternal('/usr/bin/xviewer ' + '"' + file + '"') (* picture *)
| 5: Dialog.RunExternal('/usr/bin/libreoffice ' + '"' + file + '"') (* libre office *)
| 6: Dialog.RunExternal('/usr/bin/xreader ' + '"' + file + '"') (* acrobat *)
| 7: Dialog.RunExternal('/usr/bin/idle ' + '"' + file + '"') (* phyton idle *)
| 8: Dialog.RunExternal('/usr/bin/xed ' + '"' + file + '"') (* editor xed *)
| 9: DosTextCmds.OpenDocAs(filename, 'utf8') (* blackbox - utf8 *)
ELSE Dialog.OpenExternal(file)
END;
ELSE
Dialog.OpenExternal(filename)
END;
END OpenExternal;
END InfoLinks.
| Info/Mod/Links.odc |
MODULE InfoLog;
(*
Write the filename as Link into the StdLog windows
Helmut Zinn -
*)
IMPORT
Fonts, HostFiles, Ports, StdLinks, StdLog, Strings, TextCmds, TextModels;
CONST
pathLen = HostFiles.pathLen;
underline = FALSE;
PROCEDURE WriteLink* (IN path, filename: ARRAY OF CHAR);
VAR
attr: TextModels.Attributes;
beg, end: INTEGER;
cmd, msg: ARRAY pathLen + 32 OF CHAR;
BEGIN
cmd := "InfoCmds.OpenDoc('" + path$ + filename$ + "')";
msg := path$ + filename$;
StdLog.View(StdLinks.dir.NewLink(cmd));
StdLog.String(msg);
end := StdLog.text.Length(); beg := end - LEN(msg$);
NEW(attr); attr.InitFromProp(StdLog.text.Prop(beg, end));
attr := TextModels.NewColor(attr, Ports.blue);
IF underline THEN attr := TextModels.NewStyle(attr, {Fonts.underline}) END;
StdLog.text.SetAttr(beg, end, attr);
StdLog.View(StdLinks.dir.NewLink(""));
END WriteLink;
END InfoLog.
| Info/Mod/Log.odc |
MODULE InfoLook;
(* Helmut Zinn *)
(* Use the Cross-Referenz List *)
IMPORT
InfoCmds, InfoDialog, TextCmds, TextControllers, TextModels, TextMappers, TextViews, TextRulers, Views,
Containers, StdFolds, StdLinks, Fonts, Ports, Strings, Dialog;
CONST
maxLength = 256;
linkcommand = 'InfoCmds.Start'; (* Alternativ: linkcommand = 'LibMisc.ShellExecute'; *)
underline = FALSE;
TYPE
DynString* = POINTER TO ARRAY OF CHAR;
VAR
docCount: INTEGER;
docList: POINTER TO ARRAY OF RECORD
path: DynString;
name: DynString;
END;
PROCEDURE MakeDynString* (IN s: ARRAY OF CHAR): DynString;
VAR d: DynString;
BEGIN
NEW(d, LEN(s)+1); d^ := s$;
RETURN d;
END MakeDynString;
PROCEDURE NewRuler (): TextRulers.Ruler;
CONST mm = Ports.mm;
VAR p: TextRulers.Prop;
BEGIN
NEW(p);
p.valid := {TextRulers.right, TextRulers.tabs, TextRulers.opts};
p.opts.val := {TextRulers.rightFixed}; p.opts.mask := p.opts.val;
p.right := 100 * mm;
p.tabs.len := 1;
p.tabs.tab[0].stop := 80 * mm;
p.tabs.tab[0].type := {TextRulers.rightTab};
RETURN TextRulers.dir.NewFromProp(p)
END NewRuler;
PROCEDURE UnderlineBlue (VAR f: TextMappers.Formatter);
VAR new: TextModels.Attributes;
BEGIN
new := f.rider.attr;
new := TextModels.NewStyle(new, new.font.style + {Fonts.underline});
new := TextModels.NewColor(new, Ports.blue);
f.rider.SetAttr(new); (* change current attributes of formatter *)
END UnderlineBlue;
PROCEDURE Black (VAR f: TextMappers.Formatter);
VAR new: TextModels.Attributes;
BEGIN
new := f.rider.attr;
new := TextModels.NewStyle(new, new.font.style - {Fonts.underline});
new := TextModels.NewColor(new, Ports.black);
f.rider.SetAttr(new); (* change current attributes of formatter *)
END Black;
PROCEDURE WriteLink* (VARf:TextMappers.Formatter; IN label, cmdstr: ARRAY OF CHAR);
VAR v: Views.View;
BEGIN
v := StdLinks.dir.NewLink(cmdstr);
f.WriteView(v); (* insert left link view in text *)
UnderlineBlue(f);
f.WriteString(label); (* the string shown between the pair of link views *)
Black(f);
v := StdLinks.dir.NewLink("");
f.WriteView(v); (* insert right link view in text *)
END WriteLink;
PROCEDURE ReadUntilDelimiter (r: TextModels.Reader; delimiter: CHAR; VAR str: ARRAY OF CHAR);
VAR
i: INTEGER;
ch: CHAR;
BEGIN
i := 0;
r.ReadChar(ch);
WHILE ~r.eot & (ch # delimiter) DO
str[i] := ch; INC(i);
r.ReadChar(ch)
END;
str[i] := 0X
END ReadUntilDelimiter;
PROCEDURE Decode (str: ARRAY OF CHAR; VAR pos: INTEGER): INTEGER;
VAR
start: INTEGER;
intStr: ARRAY 8 OF CHAR;
num, res : INTEGER;
BEGIN
start := pos;
Strings.Find(str, " ", start, pos); IF pos = -1 THEN pos := LEN(str$) END;
Strings.Extract(str, start, pos-start, intStr);
Strings.StringToInt(intStr, num, res); ASSERT(res = 0);
pos := pos + 1;
RETURN num;
END Decode;
PROCEDURE LoadDocList;
VAR
c: TextControllers.Controller;
r: TextModels.Reader;
v: Views.View;
t: TextModels.Model;
i, res: INTEGER;
str: ARRAY 256 OF CHAR;
BEGIN
c := TextControllers.Focus();
StdFolds.CollapseFolds(c.text, FALSE, "Documents"); (* in case *)
r := c.text.NewReader(NIL);
r.SetPos(0);
r.ReadView(v); (* asking for a view, hoping for a fold *)
WITH v: StdFolds.Fold DO
t := v.HiddenText(); (* : TextModels.Model *)
r := t.NewReader(NIL); (* new use for an old reader *)
r.SetPos(0);
(* read docCount from fold *)
ReadUntilDelimiter(r, TextModels.line, str);
ReadUntilDelimiter(r, TextModels.line, str);
Strings.StringToInt(str, docCount, res);
(* read paths/names from fold *)
NEW(docList, docCount+1);
FOR i := 1 TO docCount DO
ReadUntilDelimiter(r, TextModels.tab, str);
docList[i].path := MakeDynString(str$);
ReadUntilDelimiter(r, TextModels.line, str);
docList[i].name := MakeDynString(str$);
END
END
END LoadDocList;
PROCEDURE Expand* (pat, docNumberList: ARRAY OF CHAR);
VAR
t: TextModels.Model;
f: TextMappers.Formatter;
c: Containers.Controller;
v: TextViews.View;
title: Views.Title;
a0: TextModels.Attributes;
start, docNum, count: INTEGER;
label: ARRAY 256 OF CHAR;
cmd: ARRAY 384 OF CHAR;
BEGIN
IF (docList = NIL) OR (docList[1].path$ # InfoDialog.param.source$) THEN
LoadDocList;
END;
t := TextModels.dir.New(); (* create a new, empty text *)
f.ConnectTo(t); (* connect a formatter to the text *)
f.WriteView(NewRuler());
a0 := f.rider.attr;
f.rider.SetAttr(TextModels.NewWeight(f.rider.attr, Fonts.bold));
Dialog.MapString("#Std:Location", cmd);
f.WriteString(cmd); f.WriteTab;
Dialog.MapString("#Std:Count", cmd);
f.WriteString(cmd); f.WriteLn;
f.rider.SetAttr(a0);
start := 0;
WHILE start < LEN(docNumberList$) DO
docNum := Decode(docNumberList, start);
count := Decode(docNumberList, start);
IF docList = NIL THEN
f.WriteInt(docNum)
ELSE
label := docList[docNum].path$ + docList[docNum].name$;
cmd := "InfoCmds.OpenDoc('" + label$ + "'); InfoCmds.Select('" + pat$ + "')";
WriteLink(f, label, cmd);
END;
f.WriteTab; f.WriteInt(count); f.WriteLn
END;
(* Open View in Browser mode ... *)
v := TextViews.dir.New(t);
Dialog.MapString("#Std:Looking for", title);
title := title$ +' "' + pat + '"';
Views.OpenAux(v, title);
c := v.ThisController();
c.SetOpts(c.opts + {Containers.noCaret});
END Expand;
PROCEDURE FindInIndex*;
VAR
c: TextControllers.Controller;
label: StdFolds.Label;
BEGIN
InfoDialog.ProofParam;
InfoCmds.OpenDoc(InfoDialog.param.source+'Index');
IF TextCmds.find.find # '' THEN
label[0] := TextCmds.find.find[0];
label[1] := 0X;
IF label # '' THEN
IF ('a' <= label[0]) & (label[1] <= 'z') THEN label[0] := CAP(label[0]);
ELSIF label[0] = '' THEN label[0] := '';
ELSIF label[0] = '' THEN label[0] := '';
ELSIF label[0] = '' THEN label[0] := '';
END;
c := TextControllers.Focus();
StdFolds.ExpandFolds(c.text, FALSE, label);
END;
TextCmds.FindFirst('');
END;
Dialog.Update(InfoDialog.param);
Dialog.Update(TextCmds.find);
END FindInIndex;
END InfoLook.
| Info/Mod/Look.odc |
MODULE InfoMissingLinks;
(* Helmut Zinn *)
IMPORT
Strings, Ports, Fonts, StdLinks, TextModels, TextMappers, TextViews, Views;
CONST
maxLength = 256;
linkcommand = 'InfoCmds.Start'; (* Alternativ: linkcommand = 'LibMisc.ShellExecute'; *)
underline = FALSE;
TYPE
DynString = POINTER TO ARRAY OF CHAR;
FileList = POINTER TO RECORD
name: DynString;
count: INTEGER;
org, ref: BOOLEAN;
next: FileList
END;
DirList* = POINTER TO RECORD
path: DynString;
file: FileList;
next: DirList;
END;
DocList* = DirList;
PROCEDURE MakeDynString (IN s: ARRAY OF CHAR): DynString;
VAR d: DynString;
BEGIN
NEW(d, LEN(s)+1); d^ := s$;
RETURN d;
END MakeDynString;
PROCEDURE New* (OUT docList: DocList);
BEGIN
docList := NIL;
END New;
PROCEDURE Insert* (VAR docList: DocList; IN path, name: ARRAY OF CHAR; quelle: BOOLEAN);
VAR
dirList: DirList;
fileList: FileList;
upath, uname: ARRAY 256 OF CHAR;
BEGIN
Strings.ToLower(path$, upath); Strings.ToLower(name$, uname);
dirList := docList;
WHILE (dirList # NIL) & (dirList.path$ # upath$) DO dirList := dirList.next END;
IF dirList = NIL THEN
NEW(dirList);
dirList.path := MakeDynString(upath$);
dirList.file := NIL;
dirList.next := docList;
docList := dirList;
END;
fileList := dirList.file;
WHILE (fileList # NIL) & (fileList.name$ # uname$) DO fileList := fileList.next END;
IF fileList = NIL THEN
NEW(fileList);
fileList.name := MakeDynString(uname$);
fileList.count := 0;
fileList.org := FALSE;
fileList.ref := FALSE;
fileList.next := dirList.file;
dirList.file := fileList;
ELSE
INC(fileList.count)
END;
IF quelle THEN fileList.org := TRUE ELSE fileList.ref := TRUE END;
END Insert;
PROCEDURE Display* (VAR f: TextMappers.Formatter; (* IN *) docList: DocList);
VAR
default, link: TextModels.Attributes;
cmd, msg: ARRAY 256 OF CHAR;
dirList: DirList;
fileList: FileList;
label: INTEGER; hit: BOOLEAN;
BEGIN
f.WriteString('Link missing:'); f.WriteLn; f.WriteLn;
default := TextModels.dir.attr;
link := TextModels.NewColor(default, Ports.blue); link := TextModels.NewStyle(link, {Fonts.underline});
dirList := docList;
WHILE dirList # NIL DO
label := f.Pos(); hit := FALSE;
f.WriteTab; f.WriteString(dirList.path$); f.WriteLn;
fileList := dirList.file;
WHILE fileList # NIL DO
(*
f.WriteString(dirList.path$); f.WriteString(fileList.name$); f.WriteTab; f.WriteInt(fileList.count); f.WriteLn;
*)
IF (fileList.count = 0) & fileList.org THEN
cmd := "InfoCmds.OpenDoc('" + dirList.path$ + fileList.name$ + "')";
msg := fileList.name$;
f.WriteTab; f.WriteTab;
f.WriteView(StdLinks.dir.NewLink(cmd));
f.rider.SetAttr(link);
f.WriteString(msg);
f.rider.SetAttr(default);
f.WriteView(StdLinks.dir.NewLink(""));
f.WriteLn;
hit := TRUE;
END;
fileList := fileList.next;
END;
IF ~hit THEN f.SetPos(label) END;
dirList := dirList.next;
END;
f.WriteLn; f.WriteString('Link outside:'); f.WriteLn; f.WriteLn;
default := TextModels.dir.attr;
link := TextModels.NewColor(default, Ports.blue); link := TextModels.NewStyle(link, {Fonts.underline});
dirList := docList;
WHILE dirList # NIL DO
label := f.Pos(); hit := FALSE;
f.WriteTab; f.WriteString(dirList.path$); f.WriteLn;
fileList := dirList.file;
WHILE fileList # NIL DO
(*
f.WriteString(dirList.path$); f.WriteString(fileList.name$); f.WriteTab; f.WriteInt(fileList.count); f.WriteLn;
*)
IF fileList.ref & ~fileList.org THEN
cmd := "InfoCmds.OpenDoc('" + dirList.path$ + fileList.name$ + "')";
msg := fileList.name$;
f.WriteTab; f.WriteTab;
f.WriteView(StdLinks.dir.NewLink(cmd));
f.rider.SetAttr(link);
f.WriteString(msg);
f.rider.SetAttr(default);
f.WriteView(StdLinks.dir.NewLink(""));
f.WriteLn;
hit := TRUE;
END;
fileList := fileList.next;
END;
IF ~hit THEN f.SetPos(label) END;
dirList := dirList.next;
END;
END Display;
PROCEDURE Test*;
VAR
docList: DocList;
path, name: ARRAY 256 OF CHAR;
t: TextModels.Model;
f: TextMappers.Formatter;
v: TextViews.View;
BEGIN
New(docList);
path := "Uhl/Epost/"; name := "ep1.odc"; Insert(docList, path, name, TRUE);
path := "Uhl/Epost/"; name := "ep3.odc"; Insert(docList, path, name, TRUE);
path := "Uhl/Epost/"; name := "ep2.odc"; Insert(docList, path, name, TRUE);
path := "Uhl/Epost/"; name := "ep3.odc"; Insert(docList, path, name, FALSE);
path := "Uhl/Outside/"; name := "ep4.odc"; Insert(docList, path, name, FALSE);
t := TextModels.dir.New(); (* create a new, empty text *)
f.ConnectTo(t); (* connect a formatter to the text *)
(* Open View in BrowserMode *)
v := TextViews.dir.New(t); (* create a new text view for t *)
Views.OpenAux(v, "Missing Links");
Display (f, docList);
t.Delete(f.Pos(), t.Length());
END Test;
END InfoMissingLinks.Test | Info/Mod/MissingLinks.odc |
MODULE InfoReplaceLinks;
(*
Replace Links
Helmut Zinn -
"StdCmds.OpenToolDialog('Info/Rsrc/ReplaceAll', 'Replace in all Docu')"
*)
IMPORT
Converters, Dialog, Files, InfoDialog, InfoForEachFile, InfoForEachEntry, InfoLog, Kernel,
StdFolds, StdLinks, StdLog, Strings, TextCmds, TextMappers, TextModels, TextViews, Views;
(*
uses
InfoDialog.param.source
InfoDialog.param.include
InfoDialog.param.expand
&
TextCmds.find.find
TextCmds.find.replace
TextCmds.find.ignoreCase
*)
VAR
single: BOOLEAN;
PROCEDURE MakeDocName (VAR name: Files.Name);
BEGIN
Kernel.MakeFileName(name, ""); (* Append Extension *)
END MakeDocName;
PROCEDURE Delimiter (ch: CHAR): BOOLEAN;
BEGIN
RETURN (ch = "'") OR (ch = '"') OR (ch = "/")
END Delimiter;
PROCEDURE Stale (IN s: ARRAY OF CHAR): BOOLEAN;
VAR
i, j: INTEGER; ch: CHAR; loc: Files.Locator; name: Files.Name;
t: ARRAY 1024 OF CHAR;
BEGIN
i := 0; ch := s[0]; WHILE (ch # 0X) & (ch # "(") DO INC(i); ch := s[i] END;
IF ch = "(" THEN
t := s$; t[i] := 0X;
IF (t = "StdCmds.OpenBrowser") OR (t = "StdCmds.OpenDoc")
OR (t = "StdCmds.OpenAuxDialog") OR (t = "InfoCmds.OpenDoc") THEN
INC(i); ch := s[i]; WHILE (ch # 0X) & (ch # "'") & (ch # '"') DO INC(i); ch := s[i] END;
IF ch # 0X THEN
loc := Files.dir.This("");
REPEAT
j := 0;
INC(i); ch := s[i]; WHILE ~Delimiter(ch) DO t[j] := ch; INC(j); INC(i); ch := s[i] END;
t[j] := 0X;
IF ch = "/" THEN loc := loc.This(t) END
UNTIL ch # "/";
name := t$; MakeDocName(name);
RETURN Files.dir.Old(loc, name, Files.shared) = NIL (* file not found *)
ELSE RETURN TRUE (* wrong syntax *)
END
ELSE RETURN FALSE (* unknown kind of command *)
END
ELSIF (t = "InfoCmds.Start") OR (t = "LibMisc.ShellExecute")
OR (t = "Dialog.OpenExternal") OR (t = "Dialog.RunExternal") THEN
RETURN FALSE;
ELSE RETURN FALSE (* unknown kind of command *)
END
END Stale;
PROCEDURE ChangeDoc (IN path, file: ARRAY OF CHAR; t: TextModels.Model; VAR hit: INTEGER);
VAR
r: TextModels.Reader; f: TextMappers.Formatter; v: Views.View;
pos, len: INTEGER; attr: TextModels.Attributes;
oldcmd, cmd: ARRAY 1024 OF CHAR;
BEGIN
IF InfoDialog.param.expand THEN StdFolds.ExpandFolds(t, TRUE, '') END;
hit := 0;
f.ConnectTo(t);
r := t.NewReader(NIL);
r.ReadView(v);
WHILE v # NIL DO
WITH v: StdLinks.Link DO
IF v.leftSide THEN
v.GetCmd(cmd);
IF TextCmds.find.ignoreCase THEN
Strings.ToLower(cmd, oldcmd)
ELSE
oldcmd := cmd
END;
len := LEN(TextCmds.find.find$);
Strings.Find(oldcmd, TextCmds.find.find, 0, pos);
IF pos >= 0 THEN
Strings.Replace(cmd, pos, len, TextCmds.find.replace);
IF ~(Stale(cmd)) THEN (* file found - link is ok *)
INC(hit);
(* StdLog.String(' Link changed: '); StdLog.String(cmd); StdLog.Ln; *)
pos := r.Pos();
attr := r.attr;
f.SetPos(pos - 1);
f.rider.SetAttr(attr);
f.WriteView(StdLinks.dir.NewLink(cmd));
t.Delete(pos, pos + 1);
ELSIF Stale(oldcmd) THEN
(* file not found at old position then the link is not ok *)
StdLog.String(' *** Link failed: '); StdLog.String(cmd); StdLog.Ln;
StdLog.String(' *** in file: '); InfoLog.WriteLink(path, file); StdLog.Ln;
END;
END
END
ELSE
END;
r.ReadView(v)
END;
END ChangeDoc;
PROCEDURE ChangeAllDoc (IN path, filename, filetype: ARRAY OF CHAR);
VAR
loc: Files.Locator; fname: Files.Name;
cv: Converters.Converter; vw: Views.View; md: TextModels.Model;
hit, res: INTEGER;
BEGIN
IF filetype = Kernel.docType THEN
loc := Files.dir.This(path);
fname := filename$; MakeDocName(fname);
cv := NIL;
vw := Views.Old(Views.dontAsk, loc, fname, cv);
IF (vw # NIL) & (vw IS TextViews.View) THEN
md := vw(TextViews.View).ThisModel();
IF single THEN
ChangeDoc(path, filename, md, hit);
ELSE
InfoForEachEntry.Do(ChangeDoc, path, filename, md, hit);
END;
IF hit > 0 THEN
StdLog.String('> Save file: '); StdLog.Int(hit); StdLog.String(' ');
InfoLog.WriteLink(path, filename); StdLog.Ln;
(* Views.OpenView(v); *)
cv := NIL;
Views.Register(vw, Views.dontAsk, loc, fname, cv, res);
ASSERT(res = 0, 100);
END;
END;
END;
END ChangeAllDoc;
PROCEDURE ReplaceLinks*;
BEGIN
single := TRUE;
InfoDialog.ProofParam;
StdLog.Ln;
StdLog.String("Replace Links started ..."); StdLog.Ln;
StdLog.String("Root Directory: "); StdLog.String(InfoDialog.param.source); StdLog.Ln;
IF TextCmds.find.ignoreCase THEN
Strings.ToLower(TextCmds.find.find, TextCmds.find.find);
Dialog.Update(TextCmds.find);
END;
InfoForEachFile.Do(ChangeAllDoc, InfoDialog.param.source, InfoDialog.param.include);
StdLog.String("Change All Links done."); StdLog.Ln;
END ReplaceLinks;
PROCEDURE ReplaceLinkList*;
BEGIN
single := FALSE;
InfoDialog.ProofParam;
StdLog.Ln;
StdLog.String("Replace Link List started ..."); StdLog.Ln;
StdLog.String("Root Directory: "); StdLog.String(InfoDialog.param.source); StdLog.Ln;
InfoForEachEntry.LogList;
InfoForEachFile.Do(ChangeAllDoc, InfoDialog.param.source, InfoDialog.param.include);
StdLog.String("Change Link List done."); StdLog.Ln;
END ReplaceLinkList;
END InfoReplaceLinks.
| Info/Mod/ReplaceLinks.odc |
MODULE InfoReplaceTexts;
(*
Replace Texts
Helmut Zinn -
"StdCmds.OpenToolDialog('Info/Rsrc/ReplaceAll', 'Replace in all Docu')"
*)
IMPORT
Converters, Dialog, Documents, Files, InfoDialog, InfoForEachEntry, InfoForEachFile, InfoLog,
StdFolds, StdLog, Stores, Strings, TextCmds, TextModels, TextViews, Views;
(*
uses
InfoDialog.param.source
InfoDialog.param.include
InfoDialog.param.expand
&
TextCmds.find.find
TextCmds.find.replace
TextCmds.find.ignoreCase
*)
VAR
single: BOOLEAN;
PROCEDURE ChangeDoc (IN path, file: ARRAY OF CHAR; md: TextModels.Model; VAR hit: INTEGER);
CONST
maxPat = 256;
VAR
rd: TextModels.Reader; i, j, a, b, e, nfd, nrp: INTEGER; ch: CHAR; ref: ARRAY maxPat OF CHAR;
wr: TextModels.Writer; buf: TextModels.Model; attr: TextModels.Attributes;
BEGIN
IF InfoDialog.param.expand THEN StdFolds.ExpandFolds(md, TRUE, '') END;
hit := 0;
nfd := LEN(TextCmds.find.find$);
nrp := LEN(TextCmds.find.replace$);
rd := md.NewReader(NIL);
rd.SetPos(0); rd.ReadChar(ch);
WHILE ~rd.eot DO
(* Find *)
ref[0] := ch; i := 0; j := 0; b := 0; e := 1;
WHILE ~rd.eot & (i < nfd) DO
IF (TextCmds.find.find[i] = ch)
OR (TextCmds.find.ignoreCase) & (Strings.Upper(TextCmds.find.find[i]) = Strings.Upper(ch))
THEN INC(i); j := (j + 1) MOD maxPat
ELSE i := 0; b := (b + 1) MOD maxPat; j := b
END;
IF j # e THEN ch := ref[j]
ELSE rd.ReadChar(ch); ref[j] := ch; e := (e + 1) MOD maxPat
END
END;
(* Replace *)
IF i = nfd THEN
INC(hit);
b := rd.Pos() - 1;
a := b - nfd;
buf := TextModels.CloneOf(md); wr := buf.NewWriter(NIL);
rd.SetPos(a); rd.ReadChar(ch); attr := rd.attr; wr.SetPos(0); wr.SetAttr(attr);
FOR i := 0 TO nrp - 1 DO
wr.WriteChar(TextCmds.find.replace[i]);
END;
md.Delete(a, b); md.Insert(a, buf, 0, nrp);
rd.SetPos(a + nrp);
END;
rd.ReadChar(ch);
END;
END ChangeDoc;
PROCEDURE ChangeAllDoc (IN path, filename, filetype: ARRAY OF CHAR);
VAR
loc: Files.Locator; fname: Files.Name;
cv: Converters.Converter; st: Stores.Store; vw: Views.View; md: TextModels.Model;
hit, res: INTEGER;
BEGIN
IF (InfoDialog.param.filter$ = '') OR (InfoDialog.param.filter$ = filetype$) THEN
loc := Files.dir.This(path);
fname := filename$;
(* search in converter list for a converter that can import a file of this type *)
cv := Converters.list; WHILE (cv # NIL) & (cv.fileType # filetype) DO cv := cv.next END;
Converters.Import(loc, filename$, cv, st);
vw := Views.Old(Views.dontAsk, loc, fname, cv);
IF (vw # NIL) & (vw IS Documents.Document) THEN
vw := vw(Documents.Document).ThisView()
END;
IF (vw # NIL) & (vw IS TextViews.View) THEN
md := vw(TextViews.View).ThisModel();
IF single THEN
ChangeDoc("", "", md, hit);
ELSE
InfoForEachEntry.Do(ChangeDoc, path, filename, md, hit);
END;
IF hit > 0 THEN
StdLog.String('> Save file: '); StdLog.Int(hit); StdLog.String(' ');
InfoLog.WriteLink(path, filename); StdLog.Ln;
(* Views.OpenView(vw); *)
Views.Register(vw, Views.dontAsk, loc, fname, cv, res);
ASSERT(res = 0, 100);
END;
END;
END;
END ChangeAllDoc;
PROCEDURE ReplaceTexts*;
BEGIN
single := TRUE;
InfoDialog.ProofParam;
StdLog.Ln;
StdLog.String("Replace Texts started ..."); StdLog.Ln;
StdLog.String("Root Directory: "); StdLog.String(InfoDialog.param.source); StdLog.Ln;
IF TextCmds.find.ignoreCase THEN
Strings.ToLower(TextCmds.find.find, TextCmds.find.find);
Dialog.Update(TextCmds.find);
END;
InfoForEachFile.Do(ChangeAllDoc, InfoDialog.param.source, InfoDialog.param.include);
StdLog.String("Replace All Text done."); StdLog.Ln;
END ReplaceTexts;
PROCEDURE ReplaceTextList*;
BEGIN
single := FALSE;
InfoDialog.ProofParam;
StdLog.Ln;
StdLog.String("Replace Text List started ..."); StdLog.Ln;
StdLog.String("Root Directory: "); StdLog.String(InfoDialog.param.source); StdLog.Ln;
InfoForEachEntry.LogList;
InfoForEachFile.Do(ChangeAllDoc, InfoDialog.param.source, InfoDialog.param.include);
StdLog.String("Replace Text List done."); StdLog.Ln;
END ReplaceTextList;
END InfoReplaceTexts.
| Info/Mod/ReplaceTexts.odc |
MODULE InfoSearch;
(* Helmut Zinn *)
IMPORT
Containers, Converters, Dialog, Documents, DosKeyboard, (* DosSort, *) Files, Fonts,
InfoDialog, Models, Ports, StdFolds, StdLinks, Stores, Strings, TextCmds, TextMappers,
TextModels, TextRulers, TextViews, Views;
CONST
maxPat = 64;
underline = FALSE;
TYPE
Pattern = ARRAY maxPat OF CHAR;
Text = POINTER TO RECORD
next: Text;
num: INTEGER;
title: Files.Name
END;
VAR
msg: ARRAY 256 OF CHAR;
w: TextMappers.Formatter;
count: INTEGER;
PROCEDURE List (list: Text; pat: Pattern);
VAR a0: TextModels.Attributes; cmd: ARRAY 384 OF CHAR; this, t: Text; max, cnt: INTEGER;
BEGIN
IF list = NIL THEN
Dialog.MapString("#Dev:NoMatchFound", cmd);
w.WriteString(cmd)
ELSE
cnt := 0;
a0 := w.rider.attr;
w.rider.SetAttr(TextModels.NewWeight(w.rider.attr, Fonts.bold));
Dialog.MapString("#Dev:Location", cmd);
w.WriteString(cmd); w.WriteTab;
Dialog.MapString("#Dev:Count", cmd);
w.WriteString(cmd); w.WriteLn;
w.rider.SetAttr(a0);
REPEAT
t := list; max := 1; this := NIL;
WHILE t # NIL DO
IF t.num >= max THEN
this := t;
IF InfoDialog.param.sortHit THEN max := t.num END;
END;
t := t.next
END;
IF this # NIL THEN
cnt := cnt + 1;
cmd := "InfoCmds.OpenDoc('" + this.title + "'); InfoCmds.Select('" + pat + "')";
w.WriteView(StdLinks.dir.NewLink(cmd));
w.rider.SetAttr(TextModels.NewColor(w.rider.attr, Ports.blue));
IF underline THEN w.rider.SetAttr(TextModels.NewStyle(w.rider.attr, {Fonts.underline})) END;
w.WriteString(this.title);
w.rider.SetAttr(a0);
w.WriteView(StdLinks.dir.NewLink(""));
w.WriteTab; w.WriteInt(this.num); w.WriteLn;
this.num := 0
END
UNTIL this = NIL;
w.WriteInt(cnt); w.WriteString(' Documents found'); w.WriteLn;
END;
END List;
PROCEDURE NewRuler (): TextRulers.Ruler;
CONST mm = Ports.mm;
VAR p: TextRulers.Prop;
BEGIN
NEW(p);
p.valid := {TextRulers.right, TextRulers.tabs, TextRulers.opts};
p.opts.val := {TextRulers.rightFixed}; p.opts.mask := p.opts.val;
p.right := 100 * mm;
p.tabs.len := 1;
p.tabs.tab[0].stop := 80 * mm;
p.tabs.tab[0].type := {TextRulers.rightTab};
RETURN TextRulers.dir.NewFromProp(p)
END NewRuler;
PROCEDURE ThisText (loc: Files.Locator; name: Files.Name): TextModels.Model;
VAR fi: Files.File; cn: Converters.Converter; st: Stores.Store; vw: Views.View; md: Models.Model;
BEGIN
fi := Files.dir.Old(loc, name$, Files.shared);
(* search in converter list for a converter that can import a file of this type *)
cn := Converters.list; WHILE (cn # NIL) & (cn.fileType # fi.type) DO cn := cn.next END;
Converters.Import(loc, name$, cn, st);
(* vw := Views.OldView(loc, name); -- wenn nur .odc Dateien *)
vw := Views.Old(Views.dontAsk, loc, name, cn);
IF vw = NIL THEN RETURN NIL END;
IF vw IS Documents.Document THEN vw := vw(Documents.Document).ThisView() END;
md := vw.ThisModel();
IF md = NIL THEN RETURN NIL END;
WITH md: TextModels.Model DO RETURN md ELSE RETURN NIL END;
END ThisText;
PROCEDURE SearchDoc (t: TextModels.Model; pat: Pattern; title: Files.Name; VAR list: Text);
VAR r: TextModels.Reader; num: INTEGER; i, j, b, e, n: INTEGER; ch: CHAR; ref: Pattern; l: Text;
BEGIN
IF InfoDialog.param.expand THEN StdFolds.ExpandFolds(t, TRUE, '') END;
n := 0; num := 0;
WHILE pat[n] # 0X DO INC(n) END;
r := t.NewReader(NIL);
r.SetPos(0); r.ReadChar(ch);
WHILE ~r.eot DO
ref[0] := ch; i := 0; j := 0; b := 0; e := 1;
WHILE ~r.eot & (i < n) DO
IF (pat[i] = ch) OR (TextCmds.find.ignoreCase) & (Strings.Upper(pat[i]) = Strings.Upper(ch))
THEN INC(i); j := (j + 1) MOD maxPat
ELSE i := 0; b := (b + 1) MOD maxPat; j := b
END;
IF j # e THEN ch := ref[j]
ELSE r.ReadChar(ch); ref[j] := ch; e := (e + 1) MOD maxPat
END
END;
IF i = n THEN INC(num) END
END;
IF num > 0 THEN
NEW(l); l.num := num; l.title := title; l.next := list; list := l
END
END SearchDoc;
PROCEDURE SearchLoc (path: ARRAY OF CHAR; VAR list: Text; pat: Pattern);
VAR
root: Files.Locator;
locs: Files.LocInfo;
files: Files.FileInfo;
t: TextModels.Model;
BEGIN
root := Files.dir.This(path);
files := Files.dir.FileList(root);
(* DosSort.FileList(files); *)
WHILE ~DosKeyboard.Break() & (files # NIL) DO
(* The Extension files.type$ is always lower case *)
IF (InfoDialog.param.filter$ = '') OR (InfoDialog.param.filter$ = files.type$) THEN
t := ThisText(root, files.name);
IF t # NIL THEN
INC(count);
InfoDialog.ShowStatus(count, msg$ + ' ' + path$ + files.name$);
SearchDoc(t, pat, path$ + files.name$, list)
END;
END;
files := files.next
END;
IF InfoDialog.param.include THEN
locs := Files.dir.LocList(root);
(* DosSort.LocList(locs); *)
WHILE ~DosKeyboard.Break() & (locs # NIL) DO
SearchLoc(path$ + locs.name$ + "/", list, pat);
locs := locs.next
END;
END;
END SearchLoc;
PROCEDURE SearchInAllDocuments*;
VAR
pat: Pattern;
log: TextModels.Model; v: Views.View; title: Views.Title; (* c: Containers.Controller; *) list: Text;
BEGIN
InfoDialog.ProofParam;
pat := TextCmds.find.find$;
IF pat # "" THEN
count := 0;
Dialog.MapString("#Dev:Searching", msg);
Dialog.ShowStatus(msg);
TextCmds.find.find := pat$;
log := TextModels.dir.New();
w.ConnectTo(log); w.SetPos(0);
Dialog.MapString("#Std:Search for", title);
Strings.Extract(title$ + ' "' + pat + '"', 0, 127, title);
w.WriteString(title); w.WriteLn;
SearchLoc(InfoDialog.param.source, list, pat);
List(list, pat);
v := TextViews.dir.New(log);
v(TextViews.View).SetDefaults(NewRuler(), TextViews.dir.defAttr);
Views.OpenView(v);
(*
Views.OpenAux(v, title);
(* set Browser mode: *)
c := v(Containers.View).ThisController();
c.SetOpts(c.opts + {Containers.noCaret});
*)
w.ConnectTo(NIL);
IF DosKeyboard.Break() THEN
DosKeyboard.ResetBreak;
ELSE
Dialog.ShowStatus("");
END;
END;
END SearchInAllDocuments;
PROCEDURE SearchGuard* (VAR par: Dialog.Par);
BEGIN
par.disabled := TextCmds.find.find$ = "";
END SearchGuard;
END InfoSearch.
| Info/Mod/Search.odc |
MODULE InfoTrans;
IMPORT
Strings;
CONST
substitute = "-"; (* substitute character *)
PROCEDURE TransChar1* (ch: CHAR): CHAR;
VAR res: CHAR;
BEGIN
CASE ch OF
0000X .. 001FX: res := substitute (* ASCII control character *)
| '\': res := substitute (* back slash *)
| '/': res := substitute (* forward slash *)
| ':': res := substitute (* colon *)
| '*': res := substitute (* asterisk *)
| '?': res := substitute (* question mark *)
| '"': res := substitute (* double quotes *)
| '<': res := substitute (* left angle bracket *)
| '>': res := substitute (* right angle bracket *)
| '|': res := substitute (* pipe *)
| '~': res := substitute (* tilde *)
| 007FX: res := substitute
| 0080X .. 009FX: res := substitute
| 00FFX: res := substitute
ELSE
res := ch
END;
RETURN res
END TransChar1;
PROCEDURE TransChar2* (ch: CHAR): CHAR;
VAR res: CHAR;
BEGIN
CASE ch OF
' ': res := substitute (* blank spaces *)
| '.': res := substitute (* period *)
| ';': res := substitute (* semicolon *)
| ',': res := substitute (* comma *)
| '#': res := substitute (* pound *)
| '%': res := substitute (* percent *)
| '&': res := substitute (* ampersand *)
| '{': res := substitute (* left curly bracket *)
| '}': res := substitute (* right curly bracket *)
| '$': res := substitute (* dollar sign *)
| '!': res := substitute (* exclamation point *)
| "'": res := substitute (* single quotes *)
| '@': res := substitute (* at sign *)
| '+': res := substitute (* plus sign *)
| '`': res := substitute (* backtick *)
| '=': res := substitute (* equal sign *)
| '(': res := substitute (* left bracket *)
| ')': res := substitute (* right bracket *)
| '[': res := substitute (* left squared bracket *)
| ']': res := substitute (* right squared bracket *)
ELSE
res := ch
END;
RETURN res
END TransChar2;
PROCEDURE TrimChar* (VAR source: ARRAY OF CHAR; ch: CHAR);
VAR a, b, i, k, n: INTEGER;
BEGIN
(* delete first, last and double char *)
a := 0; b := LEN(source$) - 1;
WHILE (a <= b) & (source[a] = ch) DO a := a + 1 END; (* first char *)
WHILE (a <= b) & (source[b] = ch) DO b := b - 1 END; (* last char *)
Strings.Extract(source, a, b - a + 1, source); (* Substr - delete first & last char *)
n := LEN(source$); (* delete double char - e.g. maximal 1 Blank zwischen den Wrter *)
FOR i := n - 1 TO 0 BY - 1 DO
IF (source[i] = ch) & (source[i + 1] = ch) THEN
FOR k := i TO n - 1 DO
source[k] := source[k + 1]
END;
END;
END;
END TrimChar;
PROCEDURE Trim* (VAR source: ARRAY OF CHAR);
BEGIN
TrimChar(source, ' '); (* trim spaces *)
TrimChar(source, substitute); (* trim substitute character *)
(*
TrimChar(source, '-'); (* trim hyphen *)
TrimChar(source, '_'); (* trim underscores *)
TrimChar(source, '.'); (* trim period *)
*)
END Trim;
PROCEDURE BuildNewName (IN old: ARRAY OF CHAR; OUT new: ARRAY OF CHAR);
VAR i, j: INTEGER;
BEGIN
j := 0;
FOR i := 0 TO LEN(old$) DO
CASE old[i] OF
' ': new[j] := '_';
| '': new[j] := 'A'; INC(j); new[j] := 'E';
| '': new[j] := 'a'; INC(j); new[j] := 'e';
| '': new[j] := 'O'; INC(j); new[j] := 'E';
| '': new[j] := 'o'; INC(j); new[j] := 'e';
| '': new[j] := 'U'; INC(j); new[j] := 'E';
| '': new[j] := 'u'; INC(j); new[j] := 'e';
| '': new[j] := 's'; INC(j); new[j] := 's';
ELSE new[j] := old[i];
END;
INC(j);
END;
new[j] := 0X;
END BuildNewName;
END InfoTrans.
| Info/Mod/Trans.odc |
MODULE InfoWeb;
(*
-- Translate Website with Bing or Google
-- Helmut Zinn
Test Website
http://forum.oberoncore.ru/viewtopic.php?f=116&t=2752
http%3A%2F%2Fforum.oberoncore.ru%2Fviewtopic.php%3Ff%3D116%26t%3D2752
*)
IMPORT
Dialog, StdLog, Strings, TextCmds, TextControllers;
CONST
bingTranslate = "http://www.microsofttranslator.com/bv.aspx?from=&to=en&a=";
googleTranslate = "https://translate.google.com/translate?hl=en&sl=auto&tl=en&u=";
VAR
translator*: INTEGER;
PROCEDURE Convert (VAR url: ARRAY OF CHAR);
VAR
i: INTEGER;
BEGIN
IF translator > 0 THEN
StdLog.String(url); StdLog.Ln;
FOR i := LEN(url$) - 1 TO 0 BY - 1 DO
CASE url[i] OF
| '&': Strings.Replace(url, i, 1, '%26');
| '/': Strings.Replace(url, i, 1, '%2F');
| ':': Strings.Replace(url, i, 1, '%3A');
| '=': Strings.Replace(url, i, 1, '%3D');
| '?': Strings.Replace(url, i, 1, '%3F');
ELSE
END;
END;
CASE translator OF
| 1: url := bingTranslate + url$;
| 2: url := googleTranslate + url$;
ELSE
END;
END;
END Convert;
PROCEDURE Start* (IN url: ARRAY OF CHAR);
VAR
s: ARRAY 256 OF CHAR;
BEGIN
s := url$;
IF s # '' THEN
Convert(s);
Dialog.OpenExternal(s$);
END;
END Start;
PROCEDURE ShowWebsite*;
BEGIN
Start(TextCmds.find.find);
END ShowWebsite;
PROCEDURE ShowOberonCoreForum*;
BEGIN
Dialog.OpenExternal('http://forum.oberoncore.ru/viewforum.php?f=116');
translator := 2;
Start('http://forum.oberoncore.ru/viewforum.php?f=116');
translator := 0;
END ShowOberonCoreForum;
PROCEDURE ExecuteSelection*;
VAR
c: TextControllers.Controller;
BEGIN
c := TextControllers.Focus();
IF (c # NIL) & c.HasSelection() THEN
TextCmds.InitFindDialog;
IF TextCmds.find.find[0] <= ' ' THEN
(* skip first 02X, tab & blank *)
Strings.Extract(TextCmds.find.find, 1, 256, TextCmds.find.find)
END;
Dialog.Update(TextCmds.find);
END;
Start(TextCmds.find.find);
END ExecuteSelection;
BEGIN
translator := 0;
END InfoWeb.
MENU "Infodesk"
"#Info:Translate Website..." "*5" "TextCmds.InitFindDialog; StdCmds.OpenToolDialog('Info/Rsrc/Web', '#Info:Translate Website')" ""
"#Info:Show Website" "*L" "InfoWeb.ExecuteSelection" "TextCmds.SelectionGuard"
END
| Info/Mod/Web.odc |
Info/Rsrc/CheckFilenames1.odc |
|
Info/Rsrc/CheckFilenames2.odc |
|
Info/Rsrc/CheckLinks.odc |
|
Info/Rsrc/CollectDocuments.odc |
|
Info/Rsrc/CreateCatalog.odc |
|
Info/Rsrc/CreateLinks.odc |
|
Info/Rsrc/LinkList.odc |
|
MENU "Infodesk"
"#Info:Translate Website..." "*5" "TextCmds.InitFindDialog; StdCmds.OpenToolDialog('Info/Rsrc/Web', '#Info:Translate Website')" ""
"#Info:Show Website" "*L" "InfoWeb.ExecuteSelection" "TextCmds.SelectionGuard"
"#Tbox:Find / Look at" "*F" "TboxTranslate.LookAt" ""
"#Tbox:Translate..." "*T" "StdCmds.OpenToolDialog('Tbox/Rsrc/Translate', '#Tbox:Translate')" ""
SEPARATOR
"#Info:Uhl" "" "InfoCmds.OpenTopic('Archiv/Help/Uhl')" ""
"#Info:Search..." "" "TextCmds.InitFindDialog; StdCmds.OpenToolDialog('Info/Rsrc/Search', '#Info:Search in all Documents')" ""
"#Info:Search files" "" "StdCmds.OpenToolDialog('Gft/Rsrc/SearchFiles', '#Info:Search files')" ""
SEPARATOR
"#Info:Last Document" "F7" "InfoCmds.LastDoc" "InfoCmds.LastDocGuard"
"#Info:Next Document" "F8" "InfoCmds.NextDoc" "InfoCmds.NextDocGuard"
SEPARATOR
"#Info:Edit Mode" "E" "InfoCmds.SetEditMode" "InfoCmds.SetEditModeGuard"
"#Info:Browser Mode" "B" "InfoCmds.SetBrowserMode" "InfoCmds.SetBrowserModeGuard"
SEPARATOR
"#Info:Link Documents..." "" "StdCmds.OpenToolDialog('Info/Rsrc/CreateLinks', '#Info:Link Documents')" ""
"#Info:Collect && Move Documents..." "" "StdCmds.OpenToolDialog('Info/Rsrc/CollectDocuments', '#Info:Collect & Move Documents')" ""
"#Info:Build Reference..." "" "StdCmds.OpenToolDialog('Info/Rsrc/CreateCatalog', '#Info:Build Reference')" ""
SEPARATOR
"#Info:Check Filenames..." "" "StdCmds.OpenToolDialog('Info/Rsrc/CheckFilenames1', '#Info:Check Filenames')" ""
"#Info:Check Links..." "" "StdCmds.OpenToolDialog('Info/Rsrc/CheckLinks', '#Info:Check Links')" ""
"#Info:Replace in all Documents..." "" "TextCmds.InitFindDialog; StdCmds.OpenToolDialog('Info/Rsrc/Replace', '#Info:Replace in all Documents')" ""
END
| Info/Rsrc/Menus.odc |
Info/Rsrc/Replace.odc |
|
Info/Rsrc/Search.odc |
|
STRINGS
Adviser Adviser
All Documents All Documents
Beg Beg
Bing Bing
Bing Translation Bing Translation
BlackBox BlackBox
Browser Mode Browser Mode
Build Reference Build Reference
Build Reference... Build Reference...
Bytes Bytes
CP Collections Component Pascal Collections
Cancel Cancel
Check Filenames Check Filenames
Check Filenames... Check Filenames...
Check Links Check Links
Check Links... Check Links...
Collect & Move Documents Collect & Move Documents
Collect Documents Collect Documents
Collect Documents... Collect Documents...
Continue Continue
Convert To Lower Case Convert to lower case
Correct Links Correct Links
Correct Texts Correct Texts
Create File List Create File List
Create Link List Create Link List
Delete Empty Folders Delete Empty Folders
Edit Mode Edit Mode
End End
Expand Folds Expand Folds
Filenames are too long Filenames are too long
Filenames can't change - already exist Filenames can't change - already exist
Filenames changed Filenames changed
Files Files
Filter: Filter:
Find Find
Find: Find:
Find First Find &First
Find Next Find &Next
Focus Document Focus Document
Folders Folders
Folders/Files are Empty Folders/Files are Empty
Found Found
Google Translation Google Translation
Helpdesk Helpdesk
Ignore Case Ignore Case
Include Subdirectories Include Subdirectories
Infodesk Infodesk
Interaktive Interaktive
Last Document Last Document
Leo Dictionary Leo Dictionary
Link Documents Link Documents
Link Documents... Link Documents...
List Date List Date
List Links List Links
MByte MByte
Move Files Move Files
Names are Too Long Names are Too Long
Names with Special Characters Names with Special Characters
New Index New Index
Next Document Next Document
Online Dic Online Dic
Options Options
Original Original
Paths are Too Deep Paths are Too Deep
Proof Proof
Rename Files Rename Files
Rename Files... Rename Files...
Rename Long Names Rename Long Names
Replace Replace
Replace Links Replace Links
Replace Texts ReplaceTexts
Replace Special Characters Replace Special Characters
Replace in all Documents Replace in all Documents
Replace in all Documents... Replace in all Documents...
Replace national language characters Replace national language characters
Replace: Replace:
Reverse Direction Reverse Direction
Search files Search files
Search In &Cross-Reference Search In &Cross-Reference
Search In All &Docu Search In All &Docu
Search in all Documents Search in all Documents
Search... Search...
Show Website Show Website
Sort Hit Sort Hit
Source Source
Source: Source:
Start Start
Statistic Statistic
Stop Stop
Table of Contents Table of Contents
Test Only Testrun - No Changes
Translate Website Translate Website
Trap on Error Trap on Error
Uhl Uhl
URL: URL:
Use Relative Path Use Relative Path
Update Adviser Update Adviser
Update Adviser... Update Adviser...
Update Notebook... Update Notebook...
Word: Word:
a .
ab .
aber .
ago .
all .
alle .
alles .
als .
also .
alt .
alte .
am .
an .
and .
any .
are .
art .
as .
at .
auch .
auf .
aus .
b .
bad .
be .
been .
bei .
beim .
big .
bis .
but .
by .
c .
can .
d .
da .
das .
dass .
dafr .
damit .
danach .
dann .
dazu .
dem .
den .
der .
des .
did .
die .
dies .
diese .
diesem .
diesen .
dieser .
dieses .
do .
does .
doing .
e .
ein .
eine .
einem .
einen .
einer .
eines .
er .
es .
f .
far .
few .
fr .
g .
go .
goes .
going .
got .
h .
haben .
had .
has .
hat .
have .
having .
he .
her .
here .
hier .
high .
his .
i .
ich .
id .
ihm .
ihn .
ihr .
ihre .
ihrem .
ihren .
ihrer .
ihres .
im .
immer .
in .
into .
is .
ist .
it .
its .
itself .
j .
ja .
jeder .
jedoch .
jetzt .
just .
k .
kann .
keep .
keeping .
kein .
keine .
kind .
kommt .
knnen .
l .
last .
later .
latest .
least .
left .
less .
let .
lets .
lib .
little .
lo .
log .
lot .
m .
make .
makes .
making .
man .
many .
may .
maybe .
me .
means .
mehr .
might .
mir .
mit .
more .
much .
must .
mu .
my .
n .
nach .
need .
nein .
neu .
neue .
neuen .
never .
new .
news .
next .
nice .
no .
noch .
not .
now .
null .
nun .
nur .
o .
ob .
oder .
of .
off .
often .
ohne .
ok .
old .
on .
once .
one .
only .
open .
or .
os .
out .
over .
own .
p .
per .
pro .
q .
quick .
quickly .
r .
really .
right .
s .
same .
say .
says .
see .
seems .
set .
several .
should .
sich .
sie .
since .
sind .
slow .
small .
so .
some .
statt .
still .
stuff .
such .
sure .
sys .
t .
tab .
take .
tell .
than .
that .
the .
their .
them .
then .
there .
this .
those .
to .
too .
true .
u .
um .
und .
under .
unter .
until .
up .
update .
us .
use .
used .
user .
v .
very .
via .
vom .
von .
vor .
w .
wait .
waiting .
want .
war .
was .
way .
we .
weiter .
well .
wenn .
wer .
werden .
were .
what .
when .
where .
wheter .
which .
while .
who .
whole .
wie .
wieder .
will .
wir .
wird .
with .
within .
without .
wo .
would .
wurde .
wurden .
x .
y .
yes .
yet .
you .
your .
z .
zu .
zum .
zur .
| Info/Rsrc/Strings.odc |
Info/Rsrc/Web.odc |
|
Overview by Example: ObxActions
This example demonstrates how background tasks can be implemented using actions. An action is an object which performs some action later when the system is idle, i.e., between user interactions. An action can be scheduled to execute as soon as possible, or after some time has passed. Upon execution, an action may re-schedule itself for a later point in time. In this way, an action can operate as a background task, getting computation time whenever the system is idle. This strategy is called cooperative multitasking. For this to work, an action must not do massive computations, because this would reduce the responsiveness of the system. Longer calculations need to be broken down into less time consuming pieces. This is demonstrated by an algorithm which calculates prime numbers up to a given maximum, as a background task. An action is used to perform the stepwise calculation. Every newly found prime number is written into a text. This text is opened when the calculation is started and shows the progression of the background task. The action checks whether it has reached the Upper Bound set by the user. If this is not yet the case, it re-schedules itself for further execution.
In order to speed up the calculation the parameter Step Size can be set to a larger value. This increases the CPU workload and decreases the total response time on the one side but also decreases the responsiveness of the system on the other side. The particular values required for making this effect perceptible depend on the underlying platform's processing power.
"StdCmds.OpenAuxDialog('Obx/Rsrc/Actions', 'Prime Calculation')"
ObxActionssources
| Obx/Docu/Actions.odc |
Overview by Example: ObxAddress0
One of the hallmarks of modern user interfaces are modeless dialog boxes and data entry forms. They feature text entry fields, push buttons, check boxes, and a variety of other so-called controls. The BlackBox Component Builder addresses this issue in a unique way:
• new controls can be implemented in Component Pascal; they are nothing more than specialized views, there is no artifical distinction between control objects and document objects
• every view which may contain other views (i.e., a container view) may thus contain controls, there is no artifical distinction between control containers and document containers
• every general container view can be turned into an input mask when desired
• some controls can be directly linked to variables of a program
• linking is done automatically, taking into account type information about the variables in order to guarantee consistency
• initial form layouts can be generated automatically out of a record declaration
• forms can be edited interactively and stored as documents, no intermediate code generation is required
• forms can be used "live" while they are being edited
• form layouts may be created or manipulated by a Component Pascal program, if this is desired.
Some of these aspects can be demonstrated with the example below:
MODULE ObxAddress0;
VAR
adr*: RECORD
name*: ARRAY 64 OF CHAR;
city*: ARRAY 24 OF CHAR;
country*: ARRAY 16 OF CHAR;
customer*: INTEGER;
update*: BOOLEAN
END;
PROCEDURE OpenText*;
BEGIN
END OpenText;
END ObxAddress0.
Compile this module and then execute NewForm... in the Controls menu. A dialog will be opened. Now type "ObxAddress0" into its Link field, and then click on the default button. A new window with the form will be opened. This form layout can be edited, e.g., by moving the update checkbox somewhat to the right. (Note that you have modified the document by doing that, thus you will be asked whether to save it when you try to close it. Don't save this one.
Now execute the Open asAuxDialog command in the Controls menu. As a result, you get a fully functional dialog with the current layout. This mask can be used right away, i.e., when you click into the update check box, the variable ObxAddress0.adr.update will be toggled!
If you have several views on the same variable (e.g., both the layout and the mask window), all of them will reflect the changes that the user makes.
A form's controls are linked to a program variable in a similar way as a text view is linked to its text model. Both text views and controls are implementations of the interface type Views.View. The container of the above controls is a form view, itself also an implementation of Views.View. Form views, just as text views, are examples of container views: container views may contain some intrinsic contents (e.g., text pieces) as well as arbitrary other views. Form views are degenerated in that they have no intrinsic contents; they may only contain other views.
Instead of starting with a record declaration as in the above example, you may prefer to start with the interactive design of a dialog, and only later turn to the programming aspects. This is perfectly possible as well: click on the Empty command button to create a new empty form. It will be opened in a new window, and the Layout menu will appear. Using the commands in the Controls menu, new controls can be inserted into the form. The form can be saved in a file, and its controls may later be connected to program variables using a tool called the control property editor (see the description of the Edit menu in the User's Manual).
BlackBox Component Builder only supports modeless forms, whether used as data entry masks or as dialogs. Modal forms would force the user to complete a certain task before doing anything else, e.g., looking up additional information on his task. BlackBox follows the philosophy that the user should be in control, not the computer.
In this example we have seen how a form is used, from the perspective of a programmer as well as from the perspective of a user interface designer. Furthermore we have seen how an initial form layout can be generated automatically; how a form can be viewed (even simultaneously) both as a layout and as a dialog mask; and how a control, like any other view, may live in an arbitrary container view, not just in a form view.
| Obx/Docu/Address0.odc |
Overview by Example: ObxAddress1
This example combines some features of the previous examples: it takes the address record of ObxAddress1 and adds behavior to it. Such a record, whose fields are displayed by controls, is called an interactor.
The behavior for our example interactor is defined by the global OpenText procedure. It creates a new text, into which it writes all the fields of the address record. The fields are written as one line of text, separated by tabulators and terminated by a carriage return. A new text view on this text is then opened in a window.
MODULE ObxAddress1;
IMPORT Views, TextModels, TextMappers, TextViews;
VAR
adr*: RECORD
name*: ARRAY 64 OF CHAR;
city*: ARRAY 24 OF CHAR;
country*: ARRAY 16 OF CHAR;
customer*: INTEGER;
update*: BOOLEAN
END;
PROCEDURE OpenText*;
VAR t: TextModels.Model; f: TextMappers.Formatter; v: Views.View;
BEGIN
t := TextModels.dir.New();
f.ConnectTo(t);
f.WriteString(adr.name); f.WriteTab;
f.WriteString(adr.city); f.WriteTab;
f.WriteString(adr.country); f.WriteTab;
f.WriteInt(adr.customer); f.WriteTab;
f.WriteBool(adr.update); f.WriteLn;
v := TextViews.dir.New(t);
Views.OpenView(v)
END OpenText;
END ObxAddress1.
After the example has been compiled, and after a form has been created for it and turned into a dialog, you can enter something into the fields (note that customer only accepts numeric values). Then click on the OpenText button. A window will be opened with a contents similar to the following:
Oberon microsystems Technoparkstrasse 1 Zrich ZH 8005 Switzerland 1 $TRUE
In this example, we have seen how behavior can be added to interactors, by assigning global procedures to their procedure-typed fields.
| Obx/Docu/Address1.odc |
Overview by Example: ObxAddress2
This example combines features of earlier examples: it allows to enter an address via a mask, and a push button causes the entered data to be appended to a text in a file. Afterwards, the entered data is cleared again. Controls must be notified when a program modifies an interactor. For this purpose, there is the Dialog.Update procedure which takes an interactor as parameter.
MODULE ObxAddress2;
IMPORT Files, Converters, Views, Dialog, TextModels, TextMappers, TextViews;
VAR
adr*: RECORD
name*: ARRAY 64 OF CHAR;
city*: ARRAY 24 OF CHAR;
country*: ARRAY 16 OF CHAR;
customer: INTEGER;
update*: BOOLEAN
END;
PROCEDURE OpenText*;
VAR loc: Files.Locator; name: Files.Name; conv: Converters.Converter;
v: Views.View; t: TextModels.Model; f: TextMappers.Formatter;
BEGIN
loc := NIL; name := ""; conv := NIL;
v := Views.Old(Views.ask, loc, name, conv);
IF (v # NIL) & (v IS TextViews.View) THEN
t := v(TextViews.View).ThisModel();
f.ConnectTo(t);
f.SetPos(t.Length());
f.WriteString(adr.name); f.WriteTab;
f.WriteString(adr.city); f.WriteTab;
f.WriteString(adr.country); f.WriteTab;
f.WriteInt(adr.customer); f.WriteTab;
f.WriteBool(adr.update); f.WriteLn;
Views.OpenView(v);
adr.name := ""; adr.city := ""; adr.country := ""; adr.customer := 0; adr.update := FALSE;
Dialog.Update(adr) (* update all controls for adr *)
END
END OpenText;
END ObxAddress2.
| Obx/Docu/Address2.odc |
Overview by Example: ObxAscii
Many times the input data to a program is given as an ASCII text file, or a given program specification dictates that the output format be plain ASCII text. This example shows how to process ASCII text files with the BlackBox Component Builder and presents a sketch of a module that provides a simple interface to handle ASCII text files.
The BlackBox Component Builder departs from the traditional I/O model found in other libraries. Module Files provides classes that abstract files, file directories, and access paths to open files, rather than cramming everything into one abstraction. So-called readers and writers represent positions in an open file. Several readers and writers may be operating on the same file simultaneously. The file itself represents the data carrier proper and may contain arbitrary data.
Textual information is handled by the text subsystem. Similar to the file abstraction, module TextModels provides a data carrier class the text proper and classes for reading characters from, and inserting characters into a text. Module TextMappers provides formatting routines to write values of the basic types of the Component Pascal language to texts. It also provides a scanner class that reads texts and converts the characters into integers, reals, strings, etc.
Texts may be stored in different formats on files. An ASCII text is just a special case of a text that contains no style information. So-called converters are used to handle different file formats. A converter translates the byte stream in a file into a text object in memory, and vice-versa.
The file and text abstractions are simpler, yet more flexible and powerful than the traditional I/O model. As with everything, this flexibility has its price. The simple, linear processing of a (text-)file requires some more programming to initialize the converter, text and formatter objects before a text file can be read.
This example demonstrates how to process ASCII text files with BlackBox. Module ObxAscii implements a simple, traditional interface for formatted textual input and output. It is by no means complete. ObxAscii may however serve as a model for implementing a more complete interface.
The implementation of data type Text is hidden. This renders possible a different implementation than the one presented below, e.g. using a traditional I/O library.
The field done of type Text indicates the success of the last operation. Procedure Open opens an existing file for reading. Procedure NewText creates a new, empty text for writing. Mixed reading and writing on the same text is not very common and is therefore not supported in this simple model. For new texts to become permanent, procedure Register must be used to enter the file in the directory. Finally, a set of Write procedures produce formatted output and the corresponding Read procedures read formatted data from texts.
A scanner and a formatter are associated with each text. In order to read ASCII text files and convert them to text objects, the converter for importing text files is needed. The initialization code in the module body finds the appropriate converter in the list of registered file converters and keeps a reference to it in the global variable conv.
A locator and a string is used to specify a directory and a file name when calling Open or Register. If the locator is NIL, the string given in parameter name is interpreted as a path name. (We use the well-established cross-platform URL-syntax for path names, i.e., directory names are separated by / characters.) The procedure PathToFileSpec produces a locator and file name from a path name.
Procedure Open uses Converters.Import with the ASCII text file converter stored in the global variable conv to initialize a text object with the contents of the file. The scanner is initialized and set to the beginning of the text. Procedure NewText just creates a new, empty text and initializes the formatter. Procedure Register uses Converters.Export with the ASCII text file converter to externalize a text to a file.
The Read procedures first check whether the text has been opened for reading and then use the scanner to read the next token from the text. If the token read by the scanner matches the desired type, the field done is set to TRUE to indicate success. The Write procedures first check whether the text has been opened for writing, i.e., created with NewText, and then use the formatter to write values to the text.
ObxAsciisources
| Obx/Docu/Ascii.odc |
The rules for playing BlackBox
The objective of the game is to find the form of a hidden molecule. The molecule consists of several atoms which are placed on the grid. To find out more about the hidden molecule, rays must be fired into the grid. The rays may be deflected or even absorbed by the atoms. From the position where a fired ray leaves the grid, the positions of the atoms have to be deduced. Only the reaction of the atoms on the fired rays is available, thus the name black box for this game.
Below, the possible influences of the atoms on the rays are described and illustrated with examples.
1) If the ray hits an atom head-on then it is absorbed. This situation is marked with an A at the position where the ray went in.
2) If the ray comes towards an atom one square off head-on, it gets deflected 90 degrees away from the atom. The entry and exit positions are marked with a 1 in the example on the right. Absorbing takes priority over deflecting, thus the second ray from the right side becomes absorbed.
3) If the ray tries to pass between two atoms that are one square apart, it is reflected straight back. The ray will return to its entry position which will be marked with an R. This mark is also used if an atom is situated on the border and the ray goes in just one position beside the atom. In this case the ray is reflected even before it enters the board. This sitation is the most typical reason for a reflected ray. In the example to the right, four positions are marked from which fired rays have been reflected.
4) If the ray is neither absorbed nor reflected, the positions where the ray enters and leaves the black box are marked with the same number (the number of the actual guess). Note, that the path of the ray may be arbitrarily complicated.
How to play BlackBox
To start the game, open the BlackBoxdialogbox. You may install a command into your menu to open this dialog. In the dialog you can define the size of the board and the number of atoms the computer will hide for you. When you click onto the OK button, a new window will appear which contains a new BlackBox puzzle. At the bottom of the view the number of hidden atoms is indicated.
To fire a ray into the grid, click into one of the locations on the edge of the grid. The result will be displayed immediately. Obviously this operation cannot be undone.
To tell the program where you think an atom is, click on the grid location. This will tentatively place an atom at that location. If you later decide that the atom should not be there, click on the square again, and it will disappear. When you think you have placed all of the atoms correctly, press any key or select Show Solution from the BlackBox menu and the computer will check the atoms that you placed and reveal any that you missed or placed incorrectly. In addition, a score will be displayed. The smaller the score, the better the result. Every ray which has been fired is counted with two points, except for absorbed and reflected ones which are only counted with one point. Additionally, for every misplaced atom five points are added. For an eight by eight board with four hidden atoms the average score is between ten and fifteen. Once the solution has been shown, you can visualize the path a ray will follow by clicking into the edge of the grid while holding down the ctrl key.
If you execute the menu entry New Atoms, then the computer will hide a new molecule for you which consists of the same number of atoms as the last one.
If you want to generate a new puzzle for someone else, then place the atoms on the grid and select the Set New Atoms command. The number of the hidden atoms will be updated accordingly. You may save and mail such a puzzle to your friends.
Some background information
BlackBox has been invented by the English mathematician Dr. Eric W. Solomon. All the games he invented are distinguished by the fact that they are easy and simple, but very interesting. In other words, his games are in the spirit of Oberon, namely as simple as possible, but not simpler.
BlackBox got published in Germany under the names Logo and Ordo in 1978 but was withdrawn already two years later. It is now again available from the franjos company under its original name BlackBox in a nice edition (wooden stones and atoms made out of glass). Other games invented by Solomon are Sigma File and Vice Versa. The latter has also been published under the name Hyle.
The objective of the game is not to deduce the hidden position of all atoms completely, but rather to score with as few points as possible. Thus, in some situation it may be better to apply some intuition than firing additional rays.
The worst score is always p*5 where p is the number of hidden atoms. This score can be achieved if no ray is fired at all and if the atoms are placed arbitrarely. Note also, that it is not always possible to find the hidden atoms from the information one gets through the rays. The simplest example for a molecule consisting of 5 atoms is given in the example to the right. The position of the fifth atom in the center can not be deduced. There exist also a few examples with 4 atoms. Can you construct one?
Some nice examples
The following examples are ready for you to play.
| Obx/Docu/BB-Rules.odc |
Overview by Example: ObxBlackBox
This example implements the deductive game BlackBox, using the BlackBox Component Framework. The aim of the game is to guess the positions of atoms within an n by n grid by firing rays into a black box. The rays may be deflected or even absorbed. From the position where the ray leaves the grid one must try to deduce the position of the atoms. For more information about BlackBox and on how to play the game read the rules.
A main point of this example is to demonstrate one advantage of compound documents: The ObxBlackBox views which are implemented can directly be used in the documentation for illustration purposes. Neither additional code nor the use of a drawing program is required. Moreover, these views in the documentation are living elements and can be inspected and modified as desired.
This example also shows how a view-specific menu can be used. If a BlackBox view is the focus view, a special menu appears which offers BlackBox-specific commands that operate on the focus view. For this purpose, the following menu is installed in your Obx menu file (-> Menus):
MENU "BlackBox" ("ObxBlackBox.View")
"Show Solution" "" "ObxBlackBox.ShowSolution" "ObxBlackBox.ShowSolutionGuard"
SEPARATOR
"New Atoms" "" "ObxBlackBox.New" ""
"Set New Atoms" "" "ObxBlackBox.Set" ""
SEPARATOR
"Rules" "" "StdCmds.OpenBrowser('Obx/Docu/BB-Rules', 'BlackBox Rules')" ""
END
The first menu entry is enabled or disabled depending on the state of the focus view. A user-defined guard is added for this purpose. For more information about the commands themselves see the section on how to play BlackBox in the rules.
"StdCmds.OpenAuxDialog('Obx/Rsrc/BlackBox', 'BlackBox')"
ObxBlackBoxsources
| Obx/Docu/BlackBox.odc |
Overview by Example: ObxButtons
This example demonstrates how new controls can be implemented. A control is a visual object that allows to control some behavior of another part of the program. Examples of controls are buttons, sliders, check boxes, etc. In contrast to full-fledged editors, a control only makes sense in concert with its container and other controls contained therein. With the BlackBox Component Builder, a control is a specialized view. A standard selection of important controls is provided by the BlackBox Component Builder, others can be implemented by third parties. This article shows an example of a simple button control implementation.
Our example control has four properties: its current font, color, link, and label. The link is used by most BlackBox controls to bind them to some program elements. In our case, this program element is a Component Pascal command, i.e. an exported procedure. The label is the string displayed in the button.
Control properties can be inspected and modified with the control property inspector (module DevInspector). To try this, select the control, and then use the Properties... command in submenu Object of menu Edit.
What do we have to implement to make this control work? In the remainder of this text, we will go through various aspects of the control implementation as it is given in the corresponding listing. We will look at all the procedures which must be implemented for the control to work. As is typical for object- and component-oriented programming, these procedures are meant to be called by the environment, not by yourself. This is called the Hollywood Principle of Object-Oriented Programming: Don't call us, we call you.
Typically, a control is embedded in a form. When the form is saved in a file, it gives all embedded controls the opportunity to externalize themselves. When the form is read from a file, the form allocates the controls and lets them internalize themselves. A control programmer needs to implement two procedures for this purpose: Externalize and Internalize. In the listing you can see that the auxiliary procedures Views.WriteFont and Views.ReadFont are used. They relieve you from the cumbersome task of writing or reading a font's typeface, size, style, and weight separately.
To support copying operations (e.g., cut and paste), a view must be able to copy its contents to an empty clone of itself. For this purpose, the CopyFrom procedure copies the state of an existing control (source) to a newly allocated but not yet initialized control.
Our control must be able to redraw its outline and label, which is the purpose of the Restore procedure. It draws the label in the control's color and font. The label is horizontally centered. Note that the control doesn't need to draw the background, this is handled by the container. Only the foreground, i.e., the outline and the label are drawn.
Of course, the control should also be able to perform some action when the user clicks in it. Mouse clicks and other interaction events are handled by a view's HandleCtrlMsg procedure. In our example, this procedure only reacts upon mouse-down messages (events). Other interactions such as key presses are not handled, in order to make the example as simple as possible.
Basically, the procedure's implementation consist of a mouse tracking loop, which terminates when the user releases the (primary) mouse button. The loop is programmed such that the control's rectangle is inverted as long as the mouse is located over the control, and not inverted otherwise.
If the mouse is released over the control, the inversion is removed and the string in v.link passed to the Dialog.Call procedure. This procedure basically implements an interpreter for Component Pascal commands, i.e., strings such as "Dialog.Beep" can be executed at run-time.
BlackBox predefines some standard system and control properties. The system properties are the ones that can be changed via the Attributes menu, i.e., font and color. The control properties are the ones defined in module Controls, and changeable via the control property inspector. There is a message that BlackBox uses to poll a view's properties (Properties.PollMsg), and a message to modify a view's properties (Properties.SetMsg). Returning a control's properties is easy: allocate the suitable property descriptors (Properties.StdProp and Controls.Prop), assign their appropriate fields, i.e., typeface, size, style weight, link, and label, and signal that those are the valid properties that the control knows about. For the standard system properties, this is done in the auxiliary procedure GetStdProp. The other corresponding procedure SetStdProp is slightly more complicated, because for each property it must be tested whether it needs to be changed or retained. After all, the user may just have changed the control's color without changing the font.
The whole property handling is held together by the view's HandlePropMsg procedure, where the PollMsg and SetMsg messages are recognized. For SetMsg, all elements of its property list are traversed and existing system and control properties are picked out. This is done since obviously a control cannot set properties that it doesn't know.
Changes of the control's properties are bracketed by calls to Views.BeginModification and Views.EndModification. These procedures tell the BlackBox Framework that some operation was performed that cannot be undone. Undo support would not be much more complicated, but still a bit overkill for this example here.
The calls to Views.Update signal that the control's visible area should be restored as soon as the current command has terminated.
In HandlePropMsg, the control also answers some preferences. Preferences are messages that a container view (e.g., a form) sends to its contained views (e.g., the controls). Their purpose is to customize the container's behavior according to its contents. A container is not obliged to ask embedded views for their preferences, but "socially responsible" containers (e.g., texts and forms) do so. For example, a control which doesn't yet have a defined width or height is asked for its preferred size (Properties.SizeMsg). With the Properties.FocusPref preference, a view can influence how it is treated when the mouse is clicked in it. Our control indicates that it is a hot focus, i.e. it releases its focus immediately after the mouse is released.
Finally, the New procedure creates a new control, and the Deposit procedure deposits such a new control in a system queue of the BlackBox Framework. For example, the following command sequence can be used to put a new control into this queue:
"ObxButtons.Deposit; StdCmds.PasteView"
And already we are through with the discussion of the whole control implementation! Even though we haven't addressed some more advanced issues such as keyboard shortcuts for controls, and how a control can be linked to program variables instead of commands, it still is a complete control implementation.
ObxButtonssources
| Obx/Docu/Buttons.odc |
Overview by Example: ObxCalc
This example implements a simple pocket calculator view for integer numbers. The calculator can be used either with the keyboard or with the mouse. It is implemented as a stack calculator. The topmost entry of the stack is displayed. With the ^ key (or ENTER key on the keyboard) this value is duplicated and pushed onto the stack. The p-key performs a pop operation, that is the topmost entry gets replaced by the second one. With the s-key the two topmost entries of the stack can be swapped. Expressions must be evaluated using the reverse polish notation. The arithmetic operations replace the two topmost entries by the result. / stands for the quotient and for the remainder. For example, to add 12 and 25, the keys 12^25+ must be pressed. At the beginning, the stack is filled with zeroes.
The implementation is rather simple. The ObxCalc views are views which do not contain a model. Every view keeps its own stack. When a calculator is copied, the state of the copy gets initialized.
The state of a view is not externalized. This implies that any calculator loaded from a file is always in a cleared state.
From a view-programming point of view the following type-bound procedures are of interest:
Restore draws the view's contents.
HandleCtrlMsg handles all controller messages which are sent to the view, in particular when the mouse button (Controllers.TrackMsg) or when a key (Controllers.EditMsg) is pressed within the view.
HandlePropMsg handles the property messages which are sent to the view by its container. The container asks the view about its (preferred) size (Properties.SizePref), whether it is resizable (Properties.ResizePref) and whether it wants to become focus or not (Properties.FocusPref).
Externalize externalizes a version byte
Internalize reads the version byte and initializes a new view
With only these five procedures we get a fully working interactive view. The view can be saved to a file (without its internal state) and copied using Drag & Drop or Copy & Paste, it can be printed, and under Windows, it can be exported as ActiveX object into any ActiveX container.
"ObxCalc.Deposit; StdCmds.Open"
ObxCalcsources
| Obx/Docu/Calc.odc |
Overview by Example: ObxCaps
This example shows how the built-in text subsystem of the BlackBox Component Builder can be extended by new commands. To demonstrate this possibility, a command is shown which fetches the selection in the focus view (assuming the focus view is a text view), creates a new empty text, copies the selection into this new text (but with all small letters turned into capital letters), and then replaces the selection by the newly created text. In short, this command turns the selected text stretch into all capital letters.
MODULE ObxCaps;
IMPORT Stores, Models, TextModels, TextControllers;
PROCEDURE Do*;
VAR c: TextControllers.Controller; beg, end: INTEGER;
r: TextModels.Reader; ch: CHAR;
buf: TextModels.Model; w: TextModels.Writer; script: Stores.Operation;
BEGIN
c := TextControllers.Focus();
IF (c # NIL) & c.HasSelection() THEN
c.GetSelection(beg, end);
(* upper case text will be copied into this buffer *)
buf := TextModels.CloneOf(c.text); w := buf.NewWriter(NIL);
r := c.text.NewReader(NIL); r.SetPos(beg);
r.ReadChar(ch);
WHILE (r.Pos() <= end) & ~r.eot DO
IF (ch >= "a") & (ch <= "z") THEN ch := CAP(ch) END;
w.WriteChar(ch);
r.ReadChar(ch)
END;
Models.BeginScript(c.text, "Caps", script);
c.text.Delete(beg, end); c.text.Insert(beg, buf, 0, end - beg);
Models.EndScript(c.text, script)
END
END Do;
END ObxCaps.
As an example, select the test string several lines below, and then click on the following commander:
ObxCaps.Do
teSTstring834 .-st
You'll note that the selection has turned into all caps.
But now comes the surprise: execute UndoCaps in the Edit menu. As a result, the effect of the uppercase operation is undone! In the BlackBox Component Builder, most operations are undoable; this also holds for the Delete and Insert text procedures in the above example. Thus, you need to do nothing special in order to render such a command undoable!
However, you may have noticed that there is something special in the sample program: there is a BeginScript / EndScript pair of procedure calls before resp. after the calls to Delete / Insert. They bundle the sequence of a Delete followed by a Insert into one single compoundcommand, meaning that the user need not undo both of these operations individually, but rather in one single step.
In this example we have seen how an existing displayed text and its selection are accessed, how a buffer text is created, and how the selected text stretch is replaced by the buffer's contents.
| Obx/Docu/Caps.odc |
Overview by Example: ObxContIter
This example shows how to iterate over the views embedded in a container, whether it be a text container, a form container, etc. The command searches for the first embedded view whose label is "magic name". At first, the command gets the focus container on which to operate:
c := Containers.Focus();
This statement obtains the innermost general container's controller in the focus path, even if the container is in mask or browser mode and some control in the container is currently the innermost (non-container) view.
Every general container defines some order for the embedded views. For texts, this is the order of the views in the text, for forms it is the z-ordering, etc. The controller methods GetFirstView and GetNextView allow to iterate over the embedded views in the defined order:
c.GetFirstView(Containers.any, v);
c.GetNextView(Containers.any, v);
The first parameters denote whether all embedded views should be traversed (Containers.any) or only the selected views (Containers.selection).
The loop that searches for the specific control has the typical form of a search loop:
get first element;
WHILE (element # NIL) & ~(element is the right one) DO
get next element
END;
In our example, the condition in the WHILE loop is the following:
(v # NIL) & ~((v IS Controls.Control) & (v(Controls.Control).label = "magic name"))
The right-side term contains an expression that denotes "element is the right one", in this case:
(v IS Controls.Control) & (v(Controls.Control).label = "magic name")
This means that the element is a control, and its label is "magic name". The not-operator "~" inverts this condition, so that the loop continues as long as the right element has not yet been found.
Note that you shouldn't modify the selection during iteration over the selection. Also, you shouldn't insert into or delete from the container model during iteration.
ObxContItersources
| Obx/Docu/ContIter.odc |
Overview by Example: ObxControls
A change of an interactor field (i.e., a field of a globally declared record variable) may affect not only controls which are linked to this field, but others as well. For example, a command button may be disabled as long as a text field is empty, and become enabled when something is typed into the text field.
Guard commands
Such state changes of controls, which are the results of state changes in an interactor, are handled by guard commands. A guard is a command which may disable a control, may denote it as undefined, or may make it read-only. It does not have other side effects; in particular, it doesn't invoke an arbitrary action or change the state of an interactor. For that purpose, notifiers are used.
Notifier commands
A notifier is an optional command that can be bound to a control, using the control property editor (-> DevInspector). For example, a notifier command may write something into the status bar of a window when the mouse button is pressed, and clear the status bar when the mouse button is released again.
It is more typical, however, that a notifier changes the state of the interactor to which its control is linked; i.e., to change one or more of the interactor fields to which its control is not linked.
In this way, the change of one interactor field's value may cause a change of another field's value, via the former's notifier.
Example
The example illustrates guards and notifiers, as well as command button, radio button, and list box controls.
Imagine something whose size should be controlled via a dialog, with more skilled users getting more degrees of freedom. For example, this may be a dialog for a game, which allows the user to choose a skill level. A novice user only gets a default amount of money to invest in an economics simulation game, a more experienced user additionally may choose among three predefined choices, while a guru may enter any value he or she wants to use. In order to keep our example simple and to concentrate on the control behaviors, nothing as complex as a simulation game is implemented. Instead, the initial size of a square view can be controlled by the user, in a more or less flexible way that depends on the chosen skill level.
In our example, the skill level is implement as the class field of the data interactor in module ObxControls. It is an integer variable, to which a text entry field may be linked, or more appropriately, a number of radio buttons. The radio buttons are labeled beginner, advanced, expert, and guru. Depending on the currently selected class, the interactor's list field is adapted: for a beginner, the list box should be disabled, because there is no choice (the default is taken). For an advanced player, a choice between "small", "medium", and "large" are presented in addition to the "default" size. Obviously, the list box must be enabled if such a choice exists. "expert" players get even more choices, namely "tiny" and "huge". Note that if these choices appear, the list box becomes too small to show all choices simultaneously. As a consequence, the scroll bar of the list box becomes enabled.
"guru" players have even more freedom, they can type in the desired size numerically, in a text entry field which is read-only for all other skill levels. The command button Cancel closes the dialog without doing anything, the Open button starts the game, and the OK button starts the game and immediately closes the dialog.
Since we are mainly interested in how to implement the described behavior, we don't actually implement a game. Instead, the "game" merely consists in opening a new view, whose size is determined by the size chosen in the dialog (default, large, small, etc.)
With the New Form... menu command, a new dialog box for the ObxControls.data interactor can be created automatically. The layout of this dialog can be edited interactively, and the properties of the various controls can be set using the control property editor. They should be set up as in the table below:
Control Link Label Guard Notifier Level
Radio Button ObxControls.data.class &Beginner ObxControls.ClassNotify 0
Radio Button ObxControls.data.class &Advanced ObxControls.ClassNotify 1
Radio Button ObxControls.data.class &Expert ObxControls.ClassNotify 2
Radio Button ObxControls.data.class &Guru ObxControls.ClassNotify 3
List Box ObxControls.data.list ObxControls.ListGuard ObxControls.ListNotify
Text Field ObxControls.data.width ObxControls.WidthGuard
Command Button StdCmds.CloseDialog;
ObxControls.Open OK
Command Button ObxControls.Open &Open
"StdCmds.OpenAuxDialog('Obx/Rsrc/Controls', 'ObxControls Demo')"
ObxControlssources
| Obx/Docu/Controls.odc |
Overview by Example: ObxControlShifter
This example is described in chapter4 of the BlackBox tutorial.
| Obx/Docu/ControlShifter.odc |
Overview by Example: ObxConv
While most data files are BlackBox document files, it is sometimes necessary to deal with other file types as well: ASCII files, picture files, or files created by legacy applications. Sometimes it is sufficient to import such data once and then keep it in BlackBox documents, sometimes it is necessary to export data into some foreign file format, and it may even be desirable to import data from such a file format when opening a file, and to export data back into the same file format upon saving the file. Of course, the latter only works in a satisfying way if the conversion is truly invertible, i.e., both import and export are loss-free.
The example ObxConv shows a simple ASCII converter, which converts to and from standard BlackBox text views. The module consists of two commands, one is an importer and the other an exporter. Both commands have the same structure: in a loop over all characters of a text, each character is read (from a file or text) and then written (into a text or file).
Actually, the characters would have to be converted from the host platform's native character set to (or from) the portable character set used by the BlackBox Component Builder. This is not done here since it would not contribute to demonstrating the converter mechanism per se.
Each BlackBox Component Builder installation provides its own set of standard converters which are registered in module StdConfig and thus made available to the user when the system is started up. A programmer may install additional converters in procedure StdConfig.Setup, by calling the Converters.Register procedure:
Converters.Register("ObxConv.ImportText", "ObxConv.ExportText", "TextViews.View", "TXT", {})
StdConfig.Setup is called at the end of the BlackBox Component Builder's bootstrap process, i.e., when the core has been loaded successfully.
For each registered converter, there optionally may be a corresponding string mapping; to make the display of a list of importers/exporters more user-friendly. For example, the importer "ObxConv.ImportText" could be mapped to the more telling name "Obx Text" (in the standard file open dialog). The mapping is done in the Strings file in the Rsrc directory of the importer's subsystem, e.g. there is the following line in the Obx/Rsrc/Strings text:
ObxConv.ImportText Obx Text File
It is conceivable to implement compound converters: an HTML (Hypertext Markup Language) converter for example could use the standard ASCII converter of the BlackBox Component Builder (i.e., module StdTextConv) to perform a conversion from the platform's ASCII format to a BlackBox text. The created text could then be parsed and converted into an equivalent text which included some kind of hypertext link view instead of the textually specified hyperlinks.
ObxConvsources
| Obx/Docu/Conv.odc |
Overview by Example: ObxCount0
This example is described in chapter5 of the BlackBox tutorial.
| Obx/Docu/Count0.odc |
Overview by Example: ObxCount1
This example is described in chapter5 of the BlackBox tutorial.
| Obx/Docu/Count1.odc |
Overview by Example: ObxCtrls
"ObxCtrls.Deposit; StdCmds.PasteView"
| Obx/Docu/Ctrls.odc |
Overview by Example: ObxCubes
This example implements a simple rotating cube view. The cube rotates around two axes. It performs 10 state transformations per second and after 25.6 seconds it is back in its starting position. The example below shows a large cube rotating in front of a smaller one. Both cubes are embedded in a form view, which is embedded in the text view that you are currently reading:
What this example shows is the use of actions. Services.Actions are objects whose Do procedures are executed in a delayed fashion, when the system is idle. An action which re-installs itself whenever it is invoked as in this example operates as a non-preemptive background task.
This example also demonstrates a simple property editor through which the colors of the sides of a cube can be changed. To open the property editor click into the cube while holding down the ctrl key (or execute the command below to open the dialog). The property editor always shows the colors of the selected cube. The synchronization between the color fields in the dialog and the selected cube is also performed through the installed action. The colors of the sides are actually changed by a notifier which is attached to each color control in the property dialog. The color white is interpreted as invisible.
"ObxCubes.Deposit; StdCmds.Open"
"StdCmds.OpenToolDialog('Obx/Rsrc/Cubes', 'Cube Colors')"
ObxCubessources
| Obx/Docu/Cubes.odc |
Overview by Example: ObxDb
This example provides two commands to the user. The first, EnterData, takes a text selection as input, and reads it line by line. Each line should consist of an integer number, followed by a string, trailed by a real number. Each such tuple is entered into a globally anchored linear list, sorted by the integer value. The second command, ListData, generates a text which displays the data currently in the list.
ObxDbsources
ObxDb.EnterData ObxDb.ListData ObxDb.Reset
To try out the example, select the following lines, and then click the left commander above:
1 Cray 14.8
3 NEC 16.6
2 IBM 8.3
Now click the middle commander, as a result a window opens with the sorted input. If you repeat both steps, you'll note that the input has been added to the list a second time, and that consequently every item appears twice in the output.
This example has shown how a text can be scanned symbol by symbol, instead of character by character.
| Obx/Docu/Db.odc |
Overview by Example: ObxDialog
This example demonstrates list, selection, and combo interactor fields and their appropriate controls. Furthermore, notifiers and guards are used.
"StdCmds.OpenAuxDialog('Obx/Rsrc/Dialog', 'ObxDialog Demo')"
ObxDialogsources
| Obx/Docu/Dialog.odc |
Oberon by Example: ObxFact
This example demonstrates the use of module Integers, which implements arbitrary precision integers. The example implements the command ObxFact.Compute, which computes the factorial of an integer selected as text in a text view, and replaces the selection with the result.
Example:
25 -> 15511210043330985984000000
Note: The time required to compute a factorial grows exponentially with the size of the input. For numbers greater than 500 a considerable time will be needed.
ObxFactsources
| Obx/Docu/Fact.odc |
Overview by Example: ObxFileTree
This example illustrates the use of the TreeControl. The aim is to create a file browser similar to the Windows Explorer. To keep it simple, the user interface will consist of a text field, three buttons, and a TreeControl. When the user types a path to a directory in the text field and clicks on the Display button the files and folders in the given directory are shown in the tree. The user can browse the files and folders in the tree, and a double click on a file opens the file in BlackBox.
The Interactors
To achieve this user interface we need a Dialog.String variable to connect to the text field, we need two procedures to connect to the Display and Open buttons respectively, and we need a Dialog.Tree variable to connect to the TreeControl. We also need a notifier to connect to TreeControl. This notifier should detect a double click on a leaf in the tree and open the corresponding file.
The TreeControl has several properties which can be modified with the property inspector. For this example the default properties are sufficient. In particular the option "Folder icons" should be switched on. This option makes the TreeControl show icons in front of each node in the tree. The leaf nodes get a "file" icon and the nodes that have subnodes get a "folder" icon. This option gives our program the same look and feel as the Windows Explorer.
The only problem is that if a file directory does not contain any files it will be a leaf node and thus look like a file and not a folder. For this purpose the Dialog.TreeNode offers a method called ViewAsFolder, which makes a node in a tree display a folder icon even if it doesn't have any subnodes.
The Implemantation
To implement this, this example uses four procedures:
PROCEDURE BuildDirTree (loc: Files.Locator; parent: Dialog.TreeNode);
PROCEDURE Update*;
PROCEDURE Open*;
PROCEDURE OpenGuard* (VAR par: Dialog.Par);
BuildDirTree recursively adds files and folders to the tree, and also makes sure that the ViewAsFolder attribute is set for nodes that are folders. Update is the procedure that is connected to the Display command button in the user interface. This procedure clears the tree and then calls BuildDirTree. The procedure Open opens the selected folder or file. StdCmds.DefaultOnDoubleClick, which is set as the TreeControl's notifier procedure, executes the default command Open when the TreeControl is double-clicked.
"StdCmds.OpenToolDialog('Obx/Rsrc/FileTree', 'ObxFileTree Demo')"
ObxFileTreesources
| Obx/Docu/FileTree.odc |
Overview by Example: ObxFldCtrls
There is no separate documentation.
| Obx/Docu/FldCtrls.odc |
Overview by Example: ObxGraphs
This example is a view which implements simple bar charts. The implementation consists of a view and a model. The view contains the model, and the model contains a linear list of values. For each of these values, a bar is drawn when the view is restored in a frame. The current list of values can be inspected by clicking with the mouse into the view: as a result, an auxiliary window is opened containing a textual representation of the values. This list of numbers can be edited, selected, and then dropped into the graph view again, to change its current list of values. A model's data (the value list) is always replaced as a whole and never modified incrementally. For this reason, not only shallow but also deep copying of a model can be implemented by copying the model reference (the pointer value), rather than by cloning the model and its contents. The same immutability property has been used in example ObxLines already.
The most interesting part of this view implementation is the handling of drag & drop messages. In order to let the BlackBox Component Builder provide drop feedback (i.e., the temporary outline denoting a graph view as a possible target for dropping a piece of text) the Controllers.PollDropMsg must be handled. In order to actually execute a drop operation (i.e., to let the graph view consume the dropped piece of text), the Controllers.DropMsg must be handled. In our example, the dropped view isn't inserted into the drop target, but rather interpreted as a specification for its new contents.
The handling of the Properties.FocusPref preference is also noteworthy. By setting up this preference, a view can inform its container how it would like to be treated concerning focusing. If this message is not handled, a view is never permanently focused, except if it is the root view. This means that upon clicking into the view, the view gets selection handles, but not a focus border. The focus preference allows to modify this behavior.
Graph views are not meant to be targets of menu commands, i.e., it is not necessary to denote them as focusable. Since they should react on mouse clicks into their interior, they shouldn't be selected either. A view which normally is neither focused nor selected, but still should receive mouse clicks in it, is called a hot focus. A command button is a more typical example of a hot focus. A view can denote itself as a hot focus by setting the hotFocus field of the Properties.FocusPref preference to TRUE.
Truly editable views should set the setFocus field instead of the hotFocus field, so the focus is not lost when the user releases the mouse button.
ObxGraphssources
"ObxGraphs.Deposit; StdCmds.Open"
After having opened a graph view with the command above, select the list of numbers below
10 53 4 14 24 34 60 52 8
drag the selection over the graph view, and then drop it into the graph view. As a result, the graph view shows a number of grey bars, whose heights correspond to the above values (in millimeters). The bar's widths adapt such that all of them together occupy the whole view's width.
Now click into the graph view to get a list of its current values.
| Obx/Docu/Graphs.odc |