texts
stringlengths
0
1.24M
names
stringlengths
13
33
Overview by Example: ObxHello0 After you have started the BlackBox Component Builder, you can open the file Hello0 in the Docu directory of the Obx directory. It contains exactly the text you are now reading. A first example of a Component Pascal module is given below, as an embedded text object: MODULE ObxHello0; IMPORT StdLog; PROCEDURE Do*; BEGIN StdLog.String("Hello World"); StdLog.Ln (* write string and 0DX into log *) END Do; END ObxHello0. To compile this module, its source code must first be focused (i.e., set the caret or selection in it). This is done by clicking somewhere in the above source code. Then execute the Compile command in the Dev menu. After the compilation, a message like compiling "ObxHello0" 32 0 appears in the Log window. It means that module ObxHello0 has been compiled successfully, that a code file has been written to disk containing the compiled code, that this module has a code size of 32 bytes and global variables of 0 bytes size, and that information about the module's interface has been written to disk in a symbol file. New symbol files are created whenever a module is compiled for the first time, or when its interface has changed. The interface of the above module consists of one exported procedure: ObxHello0.Do. In order to call this procedure, a commander can be used (the little round button below): ObxHello0.Do Click on this button to cause the following actions to occur: the code for ObxHello0 is loaded into memory, and then its procedure Do is executed. You see the result in the log window: Hello World When you click on the button again, BlackBox executes the command immediately, without loading the module's code again: once loaded, modules remain loaded unless they are removed explicitly. When clicked, a commander takes the string which follows it, and tries to interpret it as a Component Pascal command, i.e., as a module name followed by a dot, followed by the name of an exported, parameterless procedure. Try out the following examples: StdLog.Clear Dialog.Beep DevDebug.ShowLoadedModules The list of loaded modules can be inspected by executing the LoadedModules command in the Info menu, or by simply clicking in the appropriate commander above. It will generate a text similar to the following: module name bytes used clients compiled loaded Update ObxHello0 47 0 06.09.2016 15:11:34 06.09.2016 15:13:15 DevCompiler 7007 0 05.09.2016 11:52:13 06.09.2016 15:11:04 DevCPV486 35800 1 05.09.2016 11:52:13 06.09.2016 15:11:04 A module can be unloaded if its client count is zero, i.e., if it is not imported by any other module. In order to unload ObxHello0, focus its source text again and then execute Unload in the Dev menu. The following message will appear in the log window: ObxHello0 unloaded When you generate the list of loaded modules again, it will look as follows: module name bytes used clients compiled loaded Update DevCompiler 7007 0 05.09.2016 11:52:13 06.09.2016 15:11:04 DevCPV486 35800 1 05.09.2016 11:52:13 06.09.2016 15:11:04 Note that a module list is just a text which shows a snapshot of the loader state at a given point in time, it won't be updated automatically when you load or unload modules. You can print the text, save it in a file, or edit it without danger that it may be changed by the system. You can force an update by clicking on the blue update link in the text. In this first example, we have seen how a very simple module looks like, how it can be compiled, how its command can be executed, how commanders are used as convenient alternatives to menu entries during development, how the list of loaded modules can be inspected, and how a loaded module can be unloaded again.
Obx/Docu/Hello0.odc
Overview by Example: ObxHello1 Everything in the BlackBox Component Framework revolves around views. A view is a rectangular part of a document; a document consists of a hierarchy of nested views. What you are now looking at is a text view; below is another text view embedded in it: MODULE ObxHello1; IMPORT Views, TextModels, TextMappers, TextViews; PROCEDURE Do*; VAR t: TextModels.Model; f: TextMappers.Formatter; v: TextViews.View; BEGIN t := TextModels.dir.New(); (* create a new, empty text object *) f.ConnectTo(t); (* connect a formatter to the text *) f.WriteString("Hello World"); f.WriteLn; (* write a string and a 0DX into new text *) v := TextViews.dir.New(t); (* create a new text view for t *) Views.OpenView(v) (* open the view in a window *) END Do; END ObxHello1. ObxHello1.Do The embedded text view above contains a slightly more advanced hello world program than ObxHello0. It doesn't use module StdLog to write into the log window. Instead, it creates a new empty text, to which it connects a text formatter. A text formatter is an object which provides procedures to write variables of all basic Component Pascal types into a text. In the above example, a string and a carriage return are written to the text, which means that they are appended to the existing text. Since a newly created text is empty, t now contains exactly what the formatter has written into it. A text is an object which carries text and text attributes; i.e., a sequence of characters and information about font, color, and vertical offset of each character. However, a text does not know how to draw itself; this is the purpose of a text view. (Yes, what you are currently looking at is the rendering of such a view.) When a text view is created, it receives the text to be displayed as a parameter. Several views can be open on the same text simultaneously. When you edit in one view, the changes are propagated to all other views on the same text. When you create a text, you perform the steps outlined below: 1) create a text model 2) connect a text formatter to it 3) write the text's contents via the formatter 4) create a text view for the model 5) open the text view in a window In this example, we have seen how to use the text subsystem in order to create a new text.
Obx/Docu/Hello1.odc
Overview by Example: ObxLabelLister This example is described in chapter4 of the BlackBox tutorial.
Obx/Docu/LabelLister.odc
Overview by Example: ObxLines This example implements a view which allows to draw lines with the mouse. Beyond line drawing, the only interaction with such a view is through the keyboard: some characters are interpreted as colors, e.g. typing in an "r" sets a view's foreground color (in which the lines are drawn) to red. These two operations certainly don't constitute a graphics editor yet, but can serve as a sketch for a more useful implementation. Full undo/redo of the two operations is supported, however. The implementation of ObxLines is simple: there is a view, a model, and a line data structure. The model represents a view's graph, which consists of a linear list of lines. A line is described by its two end points (x0, y0) and (x1, y1). Each view has its own independent foreground color. There is an operation for the entry of a line (a model operation), and an operation for the change of a foreground color (a view operation). When a line is entered (or the entry is undone), its bounding box is restored. For this purpose, a suitable update message is defined. There are two interesting aspects of the ObxLines implementation: The contents of a graph, i.e., the linear list of lines, is immutable. This means that a line which has been inserted in a graph is never modified again. The list may become longer by adding another line with the mouse, but the existing line list itself remains unchanged. For example, an undo operation merely changes the graph to show a shorter piece of its line list, redo shows a larger piece of it again. An immutable data structure has the nice property that it can be freely shared: copying can be implemented merely by letting another pointer point to the same data structure. There is no danger that someone inadvertently changes data belonging to someone else (aliasing problem). This property is used in the example below when copying the model. The second interesting feature of ObxLines is the way rubberbanding is implemented. Rubberbanding is the feedback given when drawing a new line, as long as the mouse button is being held down. Procedure HandleCtrlMsg shows a typical implementation of such a mechanism: it consists of a polling loop, which repeatedly polls the mouse button's state. When the mouse has moved, the old rubberband line must be erased, and a new one must be drawn. Erasing the old rubberband line is done using a temporary buffer. Before entering the polling loop, the frame's visible area is saved in the frame's buffer (one buffer per frame is supported). In the polling loop, when the rubberband line must be erased, its bounding box is restored from the buffer. After the polling loop, the last rubberband line is erased the same way, except that the temporary buffer is disposed of simultaneously. With the HandlePropMsg procedure, the view indicates that it may be focused, so it can be edited in-place. This view has a separate model. Because of this, it implements the "model protocol" of a view, i.e., the methods CopyFromModelView, ThisModel, and HandleModelMsg. CopyFromModelView is a model-oriented refinement of CopyFrom; it must be implemented instead of CopyFrom. ThisModel simply returns the view's model. HandleModelMsg receives a model update message and translates it into an update of a view's region, which eventually leads to a restoration of this region on the screen. ObxLinessources "ObxLines.Deposit; StdCmds.Open"
Obx/Docu/Lines.odc
Overview by Example: ObxLinks This example demonstrates how a text can be created which contains link views. The text represents the contents of a directory. There is a link for each subdirectory, and a link for each file that can be converted into a view. Thus this example also demonstrates how files and locators are enumerated and how file converters are used. "ObxLinks.Directory('')" ObxLinkssources
Obx/Docu/Links.odc
Overview by Example: ObxLookup0 This example is described in chapter5 of the BlackBox tutorial.
Obx/Docu/Lookup0.odc
Overview by Example: ObxLookup1 This example is described in chapter5 of the BlackBox tutorial.
Obx/Docu/Lookup1.odc
Overview by Example: ObxMailMerge When a business wants to communicate something to all its customers, e.g. the announcement of a new product, it can send out form letters to all its existing customers. Each such letter has the same contents, except for a few differences like the name and address of the respective customer. Mail merge is the process of creating these form letters out of a letter template and a customer database. This example shows how the BlackBox Component Builder's built-in text component can be used to implement a simple mail merge extension. Figure 1. Mail Merge Process The following menu command is installed in menu Obx, to simplify trying out this example: ... "Merge..." "" "ObxMMerge.Merge" "TextCmds.FocusGuard" ... Before you execute Obx->Merge..., you need to open a mail merge template. For example, the following templatedocument (Obx/Samples/MMTmpl) and then execute the Obx->Merge... command. A dialog box will ask you for the address database: open the mail merge datadocument (Obx/Samples/MMData). As a result, a new text is created which contains a sequence of form letters. When you execute the ShowMarks command in the Text menu, you'll note that the individual letters are separated by page-breaking rulers (the right-most icon in a ruler). Now let's take a closer look at how the program is implemented. There is one command called Merge, which fetches the template text (the focus), searches for place holders in this text (the fields of the template), then lets the user open the database text, determines for each template field which column of the database text corresponds to the field, creates a new output text, adds an instance of the letter template for every row of the database text, and finally opens the text in a window. MODULE ObxMailMerge; PROCEDURE TmplFields (t: TextModels.Model): Field; PROCEDURE ThisDatabase (): TextModels.Model; PROCEDURE MergeFields (f: Field; t: TextModels.Model); PROCEDURE ReadTuple (f: Field; r: TextModels.Reader); PROCEDURE AppendInstance (f: Field; data, tmpl, out: TextModels.Model); PROCEDURE Merge*; END ObxMailMerge. Listing 2. Outline of the ObxMMerge Program There are five auxiliary procedures which are called by Merge: TmplFields analyzes the template text, and returns a list of fields for this text. Each field describes a place holder with its name and its position in the text. Place holders are specified as names between "<" and ">" characters, e.g., <Name>. ThisDatabase asks the user for a database document, and returns the text contained in this document. MergeFields determines for every template field the corresponding database column. To make this possible, the first row of the database text must contain the so-called meta data of the database. For mail merge applications, this is simply the symbolic name of every column, e.g., Name or City. This name must be identical to the name used in the template. Each row is terminated by a carriage return (0DX), and the fields of a row (i.e., the columns) are separated by tabs (09X). ReadTuple reads one row of the database text, and assigns the string occupied by one database field to every corresponding template field. AppendInstance appends a copy of the template text to the end of the output text, and then replaces all the place holders by the contents of their respective database fields. These replacements are done from the end of the appended text towards the beginning, so that from/to indices are not invalidated by replacements. This explains why the field list is built up in reverse order, last field first. Note that each replacement gets the text attributes of the first replaced character, i.e., if the place holder "<Name>" in bold face is replaced by the string "Joe", the resulting replacement will be 'Joe". ObxMMerge doesn't need to insert page-breaking rulers; instead, the template text contains such a ruler. ObxMMergesources
Obx/Docu/MMerge.odc
Overview by Example: ObxOmosi Further examples: Omosi1 Omosi2 Omosi3 Omosi4 Omosi5 Omosi6 An Omosi view consists of an area filled with triangles. Each of these triangles may take on one of four colors. By clicking on a triangle, it changes it color. By shift-clicking, several triangles can be selected, which will change colors simultaneously. By clicking on a triangle with the ctrl key held down, a color palette dialog pops up which allows to map this color state to another RGB color. ObxOmosisources "ObxOmosi.Deposit; StdCmds.Open"
Obx/Docu/Omosi.odc
Overview by Example: ObxOpen0 This example asks the user for a file, opens the document contained in the file, and appends a string to the text contained in the document. Finally, the text (in its text view) is opened in a window. MODULE ObxOpen0; IMPORT Files, Converters, Views, Dialog, TextModels, TextMappers, TextViews; TYPE OpenAction = POINTER TO RECORD (Dialog.GetAction) END; PROCEDURE (a: OpenAction) Do; VAR v: Views.View; t: TextModels.Model; f: TextMappers.Formatter; BEGIN IF ~a.cancel THEN v := Views.OldView(a.loc, a.name); IF (v # NIL) & (v IS TextViews.View) THEN (* make sure it is a text view *) t := v(TextViews.View).ThisModel(); (* get the text view's model *) f.ConnectTo(t); f.SetPos(t.Length()); (* set the formatter to the end of the text *) f.WriteString("appendix"); (* append a string *) Views.OpenView(v) (* open the text view in a window *) END END END Do; PROCEDURE Do*; VAR action: OpenAction; BEGIN (* ask user for a file and open it as a view *) NEW(action); Dialog.GetIntLocName("", NIL, action); END Do; END ObxOpen0. After compilation, you can try out the above example: ObxOpen0.Do With this example, we have seen how the contents of a document's root view can be accessed, and how this view can be opened in a window after its contents have been modified. In contrast to ObxHello1, an existing text has been modified; by first setting the formatter to its end, and then appending some new text. Note that similar to the previous examples, views play a central role. In contrast to traditional development systems and frameworks, files, windows, and applications play only a minor role in the BlackBox Component Framework, or have completely disappeared as abstractions of their own. On the other hand, the view has become a pivotal abstraction. It is an essential property of views that they may be nested, to form hierarchical documents. These aspects of the BlackBox Component Framework constitute a fundamental shift from monolithic applications to software components from interoperable programs to integrated components from automation islands to open environments from application-centered design to document-centered design
Obx/Docu/Open0.odc
Overview by Example: ObxOpen1 This example is a variation of the previous one; instead of opening a view it stores it back in some file. MODULE ObxOpen1; IMPORT Converters, Files, Views, Dialog, TextModels, TextMappers, TextViews; TYPE OpenAction = POINTER TO RECORD (Dialog.GetAction) END; SaveAction = POINTER TO RECORD (Dialog.GetAction) v: Views.View; END; PROCEDURE (a: SaveAction) Do; VAR res: INTEGER; conv: Converters.Converter; name: Files.Name; BEGIN IF ~a.cancel THEN IF a.converterName # "" THEN conv := Converters.list; WHILE (conv # NIL) & (conv.exp # a.converterName) DO conv := conv.next END ELSE conv := NIL END; name := a.name + "." + a.type; Views.Register(a.v, Views.dontAsk, a.loc, name, conv, res); END END Do; PROCEDURE (a: OpenAction) Do; VAR v: Views.View; t: TextModels.Model; f: TextMappers.Formatter; saveAction: SaveAction; BEGIN IF ~a.cancel THEN v := Views.OldView(a.loc, a.name); IF (v # NIL) & (v IS TextViews.View) THEN (* make sure it is a text view *) t := v(TextViews.View).ThisModel(); (* get the text view's model *) f.ConnectTo(t); f.SetPos(t.Length()); (* set the formatter to the end of the text *) f.WriteString("appendix"); (* append a string *) NEW(saveAction); saveAction.v := v; Dialog.GetExtLocName("", "", NIL, saveAction) END END END Do; PROCEDURE Do*; VAR action: OpenAction; BEGIN (* ask user for a file and open it as a view *) NEW(action); Dialog.GetIntLocName("", NIL, action) END Do; END ObxOpen1. ObxOpen1.Do In this example we have seen how a view can be stored into a file.
Obx/Docu/Open1.odc
Overview by Example: ObxOrders ObxOrders is a more realistic example of a program which uses forms for data entry and data manipulation. It lets the user enter new orders, browse through existing orders, and save all orders into a file, or load them from a file. A dialog always shows the current order. For this order, an invoice text can be generated, ready to be printed. The order data is stored in a very simple main memory database: each order is represented as a record, and the orders are connected in a doubly-linked ring with a dummy header element. One element of a ring thus contains a next and a prev pointer, as well as the data of one order. In this case, the data is directly represented as a variable of the interactor type which is used for data entry. Note that this approach is only possible in very simple cases; normally an interactor would only represent a subset of a tuple stored in the database, and the database representation would be independent of any specific interactor. The other aspect of our example program which is simpler than in typical applications is that the database is global: the doubly-linked ring is anchored in a global variable, so there is at most one order database open at any given point in time. This example has four noteworthy aspects: The procedure NewRuler shows how a new text ruler with specific properties can be created, and in procedure Invoice it can be seen how the text font style can be changed to bold and back to normal when creating a text. Thirdly, the dialog uses guard commands to disable and enable controls in the dialog: Depending on whether there currently is an open database, the data entry, invoice generation, etc. controls are enabled, otherwise disabled. Depending on whether the current order is the last (first) one, the Next (First) button is disabled, otherwise enabled. Fourth, the formatter procedure WriteView is used twice to insert a view into the text: first a ruler view is written, and a bit later a standard clock view is written to the text. ObxOrderssources Maindialog "Delete"dialog "StdCmds.OpenAuxDialog('Obx/Rsrc/Orders', 'Order Processing')" In Obx/Samples/Odata there is some sample data.
Obx/Docu/Orders.odc
Overview by Example: ObxParCmd This example shows how a command button's context can be accessed. For example, a button in a text may invoke a command, which reads the text immediately following the command. This text can be used as an input parameter to the command. ObxParCmd implements two commands which scan the text behind a command button for a string. In the first command, the string is written to the log: "this is a string following a command button" In this way, tool texts similar to the tools of the original ETH Oberon can be constructed. In the second example, the string following the button is executed as a command, thus operating in a similar way as a commander (-> DevCommanders): "DevDebug.ShowLoadedModules" ObxParCmdsources
Obx/Docu/ParCmd.odc
Overview by Example: ObxPatterns This view displays a series of concentric rectangles. The view contains no special state; its display is completely determined by its current size alone. The view implementation is very simple. However, there are three aspects of this program which are noteworthy: First, although the view has no state, it still extends the Internalize and Externalize procedures bound to type View. This is done only in order to store a version number of the view. It is strongly recommended to store such a version number even in the simplest of views, in order to provide file format extensibility for future versions of the view implementation. Second, the view contains no special state of its own. However, its display may differ, depending on its current size. A view does not manage its own size, since its size is completely determined by the context in which the view is embedded. A view can determine its current size by asking its context via the context's GetSize procedure. Third, while a view's size is completely controlled by its context, the context still may (but need not!) cooperate when the size is determined. For example, when a view is newly inserted into a container, the container may ask the view for its preferred size; or when it wants to change the embedded view's current size, it may give the view the opportunity to define constraints on its size, e.g., by limiting width or height to some minimal or maximal values. The container can cooperate by sending a size preference (Properties.SizePrefs) to the embedded view, containing the proposed sizes (which may be undefined). The view thus gets the opportunity to modify these values to indicate its preferences. ObxPatternssources "ObxPatterns.Deposit; StdCmds.Open" Note: in order to change the pattern view's size, first select it using command Edit->Select Document, then manipulate one of the resize handles.
Obx/Docu/Patterns.odc
Overview by Example: ObxPDBRep0 This example is described in chapter5 of the BlackBox tutorial.
Obx/Docu/PDBRep0.odc
Overview by Example: ObxPDBRep1 This example is described in chapter5 of the BlackBox tutorial.
Obx/Docu/PDBRep1.odc
Overview by Example: ObxPDBRep2 This example is described in chapter5 of the BlackBox tutorial.
Obx/Docu/PDBRep2.odc
Overview by Example: ObxPDBRep3 This example is described in chapter5 of the BlackBox tutorial.
Obx/Docu/PDBRep3.odc
Overview by Example: ObxPDBRep4 This example is described in chapter5 of the BlackBox tutorial.
Obx/Docu/PDBRep4.odc
Overview by Example: ObxPhoneDB This example is described in chapter3 of the BlackBox tutorial. DEFINITION ObxPhoneDB; TYPE String = ARRAY 32 OF CHAR; PROCEDURE LookupByIndex (index: INTEGER; OUT name, number: String); PROCEDURE LookupByName (name: String; OUT number: String); PROCEDURE LookupByNumber (number: String; OUT name: String); END ObxPhoneDB. Module ObxPhoneDB provides access to a phone database. Access may happen by index, by name, or by number. An entry consists of a name and a phone number string. Neither may be empty. The smallest index is 0, and all entries are contiguous. PROCEDURE LookupByIndex (index: INTEGER; OUT name, number: ARRAY OF CHAR) Return the <name, number> pair of entry index. If the index is too large, <"", ""> is returned. The procedure operates in constant time. Pre index >= 0 20 Post index is legal name # "" & number # "" index is not legal name = "" & number = "" PROCEDURE LookupByName (name: ARRAY OF CHAR; OUT number: ARRAY OF CHAR) Returns a phone number associated with name, or "" if no entry for name is found. The procedure operates in linear time, depending on the size of the database. Post name found number # "" name not found number = "" PROCEDURE LookupByNumber (number: ARRAY OF CHAR; OUT name: ARRAY OF CHAR) Returns the name associated with number, or "" if no entry for number is found. The procedure operates in linear time, depending on the size of the database. Post number found name # "" number not found name = ""
Obx/Docu/PhoneDB.odc
Overview by Example: ObxPhoneUI This example is described in chapter4 of the BlackBox tutorial.
Obx/Docu/PhoneUI.odc
Overview by Example: ObxPhoneUI1 This example is described in chapter4 of the BlackBox tutorial.
Obx/Docu/PhoneUI1.odc
Oberon by Example: ObxPi This example demonstrates the use of module Integers for computing with arbitrary precision decimals. The example implements the command ObxPi.WritePi, which computes n decimal digits of the constant Pi and writes the result into the log. The command ObxPi.Pi only computes Pi, without printing the result. It can be used to measure the efficiency of the arbitrary precision integer package. For computation, the rule Pi = 16 * atan(1/5) - 4 * atan(1/239) is used where atan is approximated with its Taylor series expansion at x = 0: atan(x) = x - x^3/3 + x^5/5 - x^7/7 + ... The computation is performed with integers only. Each decimal x is represented as integer x * 10^d where d is the number of decimal digits to the right of the decimal point. Arithmetic operations on decimals are performed using integer arithmetic. This way, the results are chopped, not rounded. For each operation, an error of at most one ulp may be introduced. Therefore, the computation of Pi is performed with some guard digits. The final result is chopped to the desired number of decimal digits. If you want to compute more digits of Pi you have to increase the number of guard digits. Use Ceiling(Log10(1.43*n)) guard digits in order to compute n digits of Pi. Example: "ObxPi.WritePi(1000)" 31415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989 ObxPisources
Obx/Docu/Pi.odc
Overview by Example: ObxRandom This example is adapted from the book "Programming in Oberon", by Wirth/Reiser.
Obx/Docu/Random.odc
Oberon by Example: ObxRatCalc This example implements a simplifier for rational numbers of arbitrary precision. Expressions to be simplified are built up from integer numbers, the operators "+", "-", "*", "/", "^", and parentheses. Exponents ("^") must be integer numbers and their absolute value must not exceed MAX(INTEGER). The result is either an integer or a rational number (command ObxRatCalc.Simplify), or a floating point number (ObxRatCalc.Approximate). The implementation of ObxRatCalc uses the Integersmodule, which provides a data type for arbitrary precision integers and operations on them. The calculator works on arithmetic expressions, such as the following: Source Expression ObxRatCalc.Simplify ObxRatCalc.Approximate ((100 + 27 - 2) / (-5 * (2 + 3))) ^ (-3) = -1 / 125 = -8*10^-3 999999999 * 999999999 / 81 = 12345678987654321 1234567890 / 987654321 = 137174210 / 109739369 = 1.2499999886093750001423828... 30.2 + 60.5 = 907 / 10 = 90.7 Note that the undo/redo mechanism can be used after an evaluation. Syntax of input: expression := ["-"] {term addop} term. term := {factor mulop} factor. factor := ("(" expression ")" | integer) ["^" factor]. integer := digit {digit} [ "." digit {digit} ]. addop := "+". mulop := "*" | "/". Menu entries in "Obx" menu: "Simplify" "" "ObxRatCalc.Simplify" "TextCmds.SelectionGuard" "Approximate" "" "ObxRatCalc.Approximate" "TextCmds.SelectionGuard" ObxRatCalcsources
Obx/Docu/RatCalc.odc
Overview by Example: ObxSample This example is described in chapter3 of the BlackBox tutorial.
Obx/Docu/Sample.odc
Oberon by Example: ObxScroll By default, a view is always displayed in full size where the preferred size can be specified through the Properties.SizePref message. However, sometimes the contents of a view is too large to be shown completely and therefore scrolling of the view's contents within its frame must be supported. An example of views that support scrolling are the text views. There exists a generic mechanism to implement scrolling by simply changing the scrolled frame's origin. The standard document container uses this feature. Every view which is opened in its own window is contained in a document container, therefore the generic mechanism is available to every root view. The same mechanism could also be offered for embedded views, through a wrapper which scrolls the view's frame on a pixel basis. However, if you want to support a scrolling behavior beyond pixel scrolling, or if the efficient implementation of a view depends on keeping frames small, then explicit handling of scrolling is necessary. In this example we describe the mechanism ("protocol") a view needs to implement in order to support scrolling. As an example we present the implementation of a 10 by 10 checkers board view (see Figure 1) which can be scrolled within its frame. If this view is scrolled line by line, then the view is displaced field by field. Additionally, this view can also be scrolled if it is embedded in any container that has scrollbars. To scroll an embedded view it must be focus and the ctrl key must be hold down when the cursor is over a scrollbar. Figure 1 If a view wants to support scrolling operations, it must store the current scroll position in its instance variables. In our example, the coordinates of the upper left field (e.g., (6,2)) describe the scroll position. Only the visible fields need to be drawn when the view is restored. To poll the current scroll state, the framework sends a Controllers.PollSectionMsg to the view. According to the information the view returns, the appearance of the scrollbars is determined. In this message, wholeSize denotes the width or height of the focus view's contents in arbitrary coordinates, and partSize describes the focus view's width or height in the same coordinates (i.e., how large is the view compared to the whole thing). The latter value is used to determine the size of the thumb in the scroll bar (varying thumb sizes are not supported by all window systems). The position of the thumb within the scroll bar is determined according to the value of the field partPos, which specifies the view's origin. The value of partPos must be greater or equal to zero and smaller or equal to the difference between the whole size and the part size. In our example, all these values are specified in terms of rows or columns. partSize is set to the view's width or height divided by the width or height of one field, and partPos is set to the coordinate of the upper left field. For the above example view the part size is four. The value of wholeSize depends on the scroll position. If the part size is smaller than the difference between the board size and the part position, then wholeSize is set to 10, i.e., to the board size. Otherwise, the part size is greater than the visible fields of the checkers board and this empty space has to be added to the whole size of the view. The latter situation may occur if the view is enlarged, as the scroll position does not change if the view is resized. When the view is scrolled, a Controllers.ScrollMsg is sent to the view. This message specifies whether a horizontal or a vertical scroll operation should be performed, and it also specifies whether the view should scroll by increments or decrements of one line or page, or whether it should scroll to a given absolute position. Here again we must assert that the view is not scrolled outside its frame. If absolute scrolling is performed, then the position to be scrolled to is specified in the same coordinates that the PollSectionMsg uses. All other methods in the source code are straight-forward. The CopyFrom method is needed to initialize a copy of the view with the same scroll position, and the Externalize and Internalize methods allow to make the scroll position persistent. Note, that the scroll position is only persistent for embedded views. For root views, the scroll position is normalized upon externalization, i.e., it is set to (0,0). Whether or not a view should normalize its persistent state is tested with the function Normalize which is defined in the context of the view. Embedded views keep their current scroll position when stored, i.e., the scroll position is not normalized. The HandlePropMsg method finally specifies the default size of a newly generated view (depending on its scroll position); it indicates that it wants to become focus (otherwise embedded checkers views could not be scrolled); and it indicates that the size of root views is automatically adapted to the window's size. The Deposit and DepositAt commands create and deposit a new checker view. If the scroll position is (x,y), then the default width of the view is 10-x times the cell size and the default height is 10-y times the cell size. Further improvements of this example are possible. For example, the scroll operations could be implemented as genuine operations that can be undone. Note however, that these operations should only be undoable for views which are not embedded in a root context. Use the Normalize method of the context to determine whether the operations need to be undoable or not. "ObxScroll.Deposit; StdCmds.Open" ObxScrollsources
Obx/Docu/Scroll.odc
Overview by Example: ObxStores There is no separate documentation.
Obx/Docu/Stores.odc
Map to "Overview by Example" Text Commands ObxHello0docu/sources write "Hello World" to log ObxHello1docu/sources write "Hello World" to new text ObxOpen0docu/sources open text document from a file ObxOpen1docu/sources modify a text document on a file ObxCapsdocu/sources change string to uppercase ObxDbdocu/sources manage sorted list of records ObxTabsdocu ObxTabssources transform some tabs into blanks ObxMMergedocu ObxMMergesources mail merge of template and database ObxParCmddocu ObxParCmdsources interpret text which follows a command button ObxLinksdocu ObxLinkssources create a directory text with hyperlinks ObxAsciidocu ObxAsciisources traditional text file I/O Form Commands ObxAddress0docu/sources declare interactor for address dialog ObxAddress1docu/sources write address to new text document ObxAddress2docu/sources append address to existing text document ObxOrdersdocu ObxOrderssources simple order processing example ObxControlsdocu ObxControlssources guards and notifiers ObxDialogdocu ObxDialogsources selection and combo boxes ObxUnitConvdocu ObxUnitConvsources dialog box that converts between inches and points ObxFileTreedocu ObxFileTreesources using a tree control to list files and directories Other Commands ObxTrapdocu ObxTrapsources trap demo ObxConvdocu ObxConvsources file converter ObxActionsdocu ObxActionssources actions as background tasks ObxFactdocu ObxFactsources factorials calculated with arbitrary precision integers ObxPidocu ObxPisources pi calculated with arbitrary precision integers ObxRatCalcdocu ObxRatCalcsources rational number calculator Simple Views ObxPatternsdocu ObxPatternssources view with rectangular pattern ObxCalcdocu ObxCalcsources calculator ObxOmosidocu ObxOmosisources editor for 3-D structures ObxCubesdocu ObxCubessources actions as animation engines (rotating cube) ObxTickersdocu ObxTickerssources actions as animation engines (stock ticker) ObxScrolldocu ObxScrollsources demonstration of scrolling mechanism Control Views ObxButtonsdocu ObxButtonssources how to implement your own controls not available ObxCtrls slider control not available ObxFldCtrls text field control with special behavior Editor Views ObxLinesdocu ObxLinessources view which allows to draw lines ObxGraphsdocu ObxGraphssources bar chart which interprets dropped text ObxBlackBoxdocu ObxBlackBoxsources deduction game Wrapper Views ObxWrappersdocu ObxWrapperssources sample wrapper view Special Container Views ObxTwinsdocu ObxTwinssources two vertically arranged text views ObxTabViewsdocu ObxTabViewssources tabbed views General Container Views Formsubsystemmap complete sources of form subsystem ObxContIterdocu ObxContItersources set focus in a particular control in some container Other Examples not available ObxStores example of how to use Stores as graph nodes Communication Examples (part of the Comm subsystem) CommObxStreamsServer implements a simple server using CommStreams docu sources CommObxStreamsClient implements a simple client using CommStreams docu sources Examples used in the Tutorial ObxSample, ObxPhoneDB, ObxPhoneUI, ObxPhoneUI1, ObxControlShifter, ObxLabelLister, ObxPDBRep0, ObxPDBRep1, ObxPDBRep2, ObxPDBRep3, ObxPDBRep 4, ObxCount0, ObxCount1, ObxLookup0, ObxLookup1, ObxViews0, ObxViews1, ObxViews2, ObxViews3, ObxViews4, ObxViews5, ObxViews6, ObxViews10, ObxViews11, ObxViews12, ObxViews13, ObxViews14.
Obx/Docu/Sys-Map.odc
Overview by Example: ObxTabs This example demonstrates a simple text transformation: the first, second and seventh tab character in each text line, starting from the beginning of a text selection, is transformed into a blank. Actually, this command was used to prepare some of the addresses to which the first issue of The Oberon Tribune was sent. ObxTabssources To use the command, select the beginning of the address list (i.e., the "Mr. Alan..." string) and then click on the commander below: ObxTabs.Convert Mr. Alan Taylor Moon, Inc. EDP department Upping Street 10 23987 Surlington Lunaland Ms. Dianna Gloor Future SW Corp. Marketing Manhatten Blvd. 93842 Powderdale Otherland
Obx/Docu/Tabs.odc
Overview by Example: ObxTabViews The property inspector for StdTabViews supplies a graphical user interface for creating and editing StdTabViews. This user interface is sufficient for most applications. However, if tabs need to be added and removed dynamically during runtime, the programming interface of StdTabViews needs to be used. This example creates a StdTabViews.View with three tabs to start with. Then new tabs can be added or the selected tab can be deleted in runtime. Any kind of views can be added to a StdTabViews.View. In this example one ObxCube-view is added and the same ObxCalc-view is added several times. This shows another charactaristic of StdTabViews; when a view is added it is copied. Eventhough the same view is used to create several tabs, they all have their own view internally. You can easily try this by typing a number into a calculator view, then changing tab to another calculator view and type in another number. When you switch back to the first calculator it still displays the first number. The example also installs a simple notifier which simply displays the notify message in the log. Here you can try the example: "ObxTabViews.Deposit; StdCmds.Open" To add a new calculator view, use this command: ObxTabViews.AddNewCalc To delete the selected tab, use this command: ObxTabViews.DeleteTab ObxTabViewssources
Obx/Docu/TabViews.odc
Overview by Example: ObxTickers This example implements a simple stock ticker. The curve which is displayed shows a random walk. The black line is the origin, at which the walk started. If the curve reaches the upper or lower end of the view, then the origin is moved accordingly. 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. "ObxTickers.Deposit; StdCmds.Open" ObxTickerssources
Obx/Docu/Tickers.odc
Overview by Example: ObxTrap This example contains a programming error which leads to a run-time trap. It can be used to gain experience with the trap mechanism and the information shown in the trap viewer. ObxTrap.Do ObxTrapsources
Obx/Docu/Trap.odc
Overview by Example: ObxTwins ObxTwins is an example of a container view. Container views come in mainly two flavours: dynamic containers, which may contain an arbitrary and variable number of other views that may be of any type. On the other hand, static containers contain an exactly predetermined number of views, and often the types and layout of these views are predetermined and cannot be changed. Our example shows the implementation of a static container; for an example of a dynamic container please see the formsubsystem. ObxTwins implements a view which shows two subviews, a smaller one at the top, and a larger one at the bottom. Both of these views are editable text views; one of them is the current focus. The two views are not treated exactly in the same way: the vertical scroll bar of the twin view always shows the state of the bottom view, even if the top view is focused. There are various ways in which such a twin view can be used. For example, the top view might be used to hold a database query, whose result appears in the bottom view. Or a "chatter" application could be written, with one's own input in the top view, and the partner's messages in the bottom view. The twin view anchors its embedded views in two context objects (extensions of Models.Context). Such a context contains a view, its bounding box, and a backpointer to the twin view. A context is the link between a container and a contained view; it allows the contained view to communicate with its container. For this purpose, the contained view has a pointer to its context. Via this pointer, the view can access its environment; e.g., to ask what its current size is, or to ask for a size change or another favour from its container. A context buffers the bounding box of its view; the twin may change the layout of the contained views by calling procedure RecalcLayout, which updates the two context objects in some appropriate way. In a more typical example, the top view would have a constant height for demonstration purposes, ObxTwins shows a more dynamic layout, where the widths remain constant, but the heights are 1/3 for the top view and 2/3 for the bottom view. The most interesting part of this example is the view's HandleCtrlMsg procedure. It handles incoming messages in three different ways. Normally, it just forwards the message to the currently focused subview. Messages which are related to scrolling (Controllers.PollSectionMsg, Controllers.ScrollMsg, Controllers.PageMsg) are always forwarded to the bottom view, independent of the current focus. And finally, cursor messages (Controllers.CursorMessage) are always forwarded to the view under the cursor position. The twin view can be implemented with or without its own model. In this example, an empty dummy model is used. It does not contain state, and it is not externalized/internalized. Its single purpose is to allow more flexible copy behavior. A view without model implements the CopyFromSimpleView method, which is always a deep copy. A view with a model implements the CopyFromModelView method instead, which may be used for a deep copy, a shallow copy, or the copying with a new model (Views.CopyWithNewModel). Note that if you have an application where it is not useful to have several windows open on the same twin view, then you can completely eliminate the twin view's model. These twins are unorthodox in that their embedded views are not contained in their shared model, as is usual for a normal BlackBox container. Rather, the embedded views are managed (via context objects) directly by the twin views, using separate copies of the embedded views if there are several twin views for the same twin model. The reason for this strange situation is that this allows the embedded views to become visible in different sizes and layouts, depending on the size or other properties of the specific twin view. In this case here, the view sizes are different depending on the twin view size, in particular its height. In effect, the embedded views are shallow-copied and thus behave like they had been opened directly in two different windows of the same document. For example, one text view may have hidden rulers and another one may have visible rulers, and the scrolling positions may be different. However, note that more orthodox containers would forego this flexibility and use a more standard way of treating the embedded views, by putting them into the twin model. ObxTwinssources "ObxTwins.Deposit; StdCmds.Open"
Obx/Docu/Twins.odc
Overview by Example: ObxUnitConv This example demonstrates a simple dialog box that allows to convert between inches and desktop publishing points. The dialog box is a form in mask mode, and embedded below in the text: ObxUnitConvsources
Obx/Docu/UnitConv.odc
Overview by Example: ObxViews0 This example is described in chapter6 of the BlackBox tutorial.
Obx/Docu/Views0.odc
Overview by Example: ObxViews1 This example is described in chapter6 of the BlackBox tutorial.
Obx/Docu/Views1.odc
Overview by Example: ObxViews10 This example is described in chapter6 of the BlackBox tutorial.
Obx/Docu/Views10.odc
Overview by Example: ObxViews11 This example is described in chapter6 of the BlackBox tutorial.
Obx/Docu/Views11.odc
Overview by Example: ObxViews12 This example is described in chapter6 of the BlackBox tutorial.
Obx/Docu/Views12.odc
Overview by Example: ObxViews13 This example is described in chapter6 of the BlackBox tutorial.
Obx/Docu/Views13.odc
Overview by Example: ObxViews14 This example is described in chapter6 of the BlackBox tutorial.
Obx/Docu/Views14.odc
Overview by Example: ObxViews2 This example is described in chapter6 of the BlackBox tutorial.
Obx/Docu/Views2.odc
Overview by Example: ObxViews3 This example is described in chapter6 of the BlackBox tutorial.
Obx/Docu/Views3.odc
Overview by Example: ObxViews4 This example is described in chapter6 of the BlackBox tutorial.
Obx/Docu/Views4.odc
Overview by Example: ObxViews5 This example is described in chapter6 of the BlackBox tutorial.
Obx/Docu/Views5.odc
Overview by Example: ObxViews6 This example is described in chapter6 of the BlackBox tutorial.
Obx/Docu/Views6.odc
Overview by Example: ObxWrappers This example implements a wrapper. Wrappers are views which contain other views. In particular, a wrapper may have the same size as the view(s) that it wraps. In this way, it can combine its own functionality with that of the wrapped view(s). For example • a debugging wrapper lists the messages received by the wrapped view into the log • a background wrapper adds a background color, over which its wrapped view is drawn (which typically has no background color, i.e., which has a transparent background) • a layer wrapper contains several layered views, e.g., a graph view overlaid by a caption view • a terminal wrapper contains a terminal session and wraps a standard text view displaying the log of the session • a bundling wrapper filters out controller messages, such that the wrapped view becomes read-only etc., the sky's the limit! Wrappers demonstrate the power of composition, i.e., how functionality of different objects can be combined in a very simple manner, without having to use complex language mechanisms such as inheritance. Our example wrapper simply echoes every key typed into the log. The wrapper implementation is noteworthy in three respects. First, a wrapper reuses the context of the view which it wraps, it has no context of its own. This is only possible because the wrapper is exactly as large as the wrapped view, because a shared context cannot return different sizes in its GetSize method. Second, it uses the wrapped view's model (if it has one!) as its own, this means that its ThisModel method returns the wrapped view's model, and that CopyFromModelView propagates the new model to the wrapped view. Third, the wrapper is implemented in a flexible way which allows it to wrap both views with or without models. This flexibility is concentrated in procedure CopyFromModelView (which admittedly is a bad name in those special cases where the wrapped views don't have models). ObxWrappers.Wrap (* select view (singleton) before calling this command *) ObxWrappers.Unwrap (* select view (singleton) before calling this command *) (* <== for example, select this view *) and then type in some characters, and see what happens in the log. ObxWrapperssources
Obx/Docu/Wrappers.odc
MODULE ObxActions; (** project = "BlackBox" organization = "www.oberon.ch" contributors = "Oberon microsystems" version = "System/Rsrc/About" copyright = "System/Rsrc/About" license = "Docu/BB-License" changes = " - 20150715, center #67, improvements for Obx->Primes... " issues = " - ... " **) IMPORT Services, Views, TextModels, TextMappers, TextViews, Math, Dialog; TYPE PrimeAction = POINTER TO RECORD (Services.Action) to, stepSize, current, divisor: INTEGER; f: TextMappers.Formatter END; VAR primeDlg*: RECORD to*, stepSize*: INTEGER; END; PROCEDURE Step (stepSize, to: INTEGER; VAR cur, divisor: INTEGER; f: TextMappers.Formatter); VAR end, sqrtCur: INTEGER; BEGIN WHILE (stepSize > 0) & (cur <= to) DO end := divisor + stepSize; sqrtCur := SHORT(ENTIER(Math.Sqrt(cur))); WHILE (divisor <= sqrtCur) & (divisor < end) & (cur MOD divisor # 0) DO divisor := divisor + 2 END; stepSize := end - divisor; IF divisor > sqrtCur THEN (* cur is a prime *) f.WriteInt(cur); f.WriteLn; divisor := 3; cur := cur + 2 ELSIF divisor < end THEN (* cur is not a prime, test next one *) divisor := 3; cur := cur + 2 ELSE (* time exhausted, continue test next time *) END END END Step; PROCEDURE (a: PrimeAction) Do; BEGIN Step(a.stepSize, a.to, a.current, a.divisor, a.f); IF a.current <= a.to THEN Services.DoLater(a, Services.now) ELSE Dialog.ShowMsg("prime number calculation finished") END ; END Do; PROCEDURE StartPrimes*; VAR a: PrimeAction; BEGIN NEW(a); a.to := primeDlg.to; a.stepSize := primeDlg.stepSize; a.current := 3; a.divisor := 3; IF a.stepSize < 1 THEN a.stepSize := 1 END ; a.f.ConnectTo(TextModels.dir.New()); a.f.WriteInt(2); a.f.WriteLn; Views.OpenAux(TextViews.dir.New(a.f.rider.Base()), ""); Services.DoLater(a, Services.now); Dialog.ShowMsg("prime number calculation started") END StartPrimes; BEGIN primeDlg.to := 1000; primeDlg.stepSize := 10 END ObxActions.
Obx/Mod/Actions.odc
MODULE ObxAddress0; (** project = "BlackBox" organization = "www.oberon.ch" contributors = "Oberon microsystems" version = "System/Rsrc/About" copyright = "System/Rsrc/About" license = "Docu/BB-License" changes = " - YYYYMMDD, nn, ... " issues = " - ... " **) 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.
Obx/Mod/Address0.odc
MODULE ObxAddress1; (** project = "BlackBox" organization = "www.oberon.ch" contributors = "Oberon microsystems" version = "System/Rsrc/About" copyright = "System/Rsrc/About" license = "Docu/BB-License" changes = " - YYYYMMDD, nn, ... " issues = " - ... " **) 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.
Obx/Mod/Address1.odc
MODULE ObxAddress2; (** project = "BlackBox" organization = "www.oberon.ch" contributors = "Oberon microsystems" version = "System/Rsrc/About" copyright = "System/Rsrc/About" license = "Docu/BB-License" changes = " - YYYYMMDD, nn, ... " issues = " - ... " **) 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/Mod/Address2.odc
MODULE ObxAscii; (** project = "BlackBox" organization = "www.oberon.ch" contributors = "Oberon microsystems" version = "System/Rsrc/About" copyright = "System/Rsrc/About" license = "Docu/BB-License" purpose = "formatted I/O from/to ASCII text files" changes = " - YYYYMMDD, nn, ... " issues = " - ... " **) IMPORT Files, Stores, Converters, TextModels, TextMappers, TextViews; TYPE Text* = POINTER TO RECORD done-: BOOLEAN; (* last operation was successful *) reading: BOOLEAN; form: TextMappers.Formatter; scan: TextMappers.Scanner END; VAR conv: Converters.Converter; PROCEDURE PathToFileSpec (IN path: ARRAY OF CHAR; OUT loc: Files.Locator; OUT name: Files.Name); VAR i, j: INTEGER; ch: CHAR; BEGIN i := 0; j := 0; loc := Files.dir.This(""); WHILE (loc.res = 0) & (i < LEN(path) - 1) & (j < LEN(name) - 1) & (path[i] # 0X) DO ch := path[i]; INC(i); IF (j > 0) & (ch = "/") THEN name[j] := 0X; j := 0; loc := loc.This(name) ELSE name[j] := ch; INC(j) END END; IF path[i] = 0X THEN name[j] := 0X ELSE loc.res := 1; name := "" END END PathToFileSpec; PROCEDURE Open* (loc: Files.Locator; IN name: ARRAY OF CHAR): Text; VAR s: Stores.Store; fname: Files.Name; text: Text; BEGIN IF loc = NIL THEN PathToFileSpec(name, loc, fname) ELSE fname := name$ END; IF loc.res = 0 THEN Converters.Import(loc, fname, conv, s); IF (s # NIL) & (s IS TextViews.View) THEN NEW(text); text.reading := TRUE; text.scan.ConnectTo(s(TextViews.View).ThisModel()); RETURN text ELSE RETURN NIL END ELSE RETURN NIL END END Open; PROCEDURE NewText* (): Text; VAR text: Text; BEGIN NEW(text); text.reading := FALSE; text.form.ConnectTo(TextModels.dir.New()); RETURN text END NewText; PROCEDURE Register* (t: Text; loc: Files.Locator; IN name: ARRAY OF CHAR); VAR fname: Files.Name; v: TextViews.View; BEGIN IF ~t.reading & (name # "") THEN IF loc = NIL THEN PathToFileSpec(name, loc, fname) ELSE fname := name$ END; IF loc.res = 0 THEN v := TextViews.dir.New(t.form.rider.Base()); Converters.Export(loc, fname, conv, v); t.done := TRUE ELSE t.done := FALSE END ELSE t.done := FALSE END END Register; PROCEDURE Eot* (t: Text): BOOLEAN; BEGIN RETURN t.reading & t.scan.rider.eot END Eot; PROCEDURE ReadChar* (t: Text; OUT c: CHAR); BEGIN ASSERT(t.reading, 20); t.scan.rider.ReadChar(c); t.done := ~t.scan.rider.eot END ReadChar; PROCEDURE ReadString* (t: Text; OUT s: ARRAY OF CHAR); BEGIN ASSERT(t.reading, 20); t.scan.Scan; t.done := t.scan.type = TextMappers.string; s := t.scan.string$ END ReadString; PROCEDURE ReadInt* (t: Text; OUT i: INTEGER); BEGIN ASSERT(t.reading, 20); t.scan.Scan; t.done := t.scan.type = TextMappers.int; i := t.scan.int END ReadInt; PROCEDURE WriteString* (t: Text; IN s: ARRAY OF CHAR); BEGIN ASSERT(~t.reading, 20); t.form.WriteString(s); t.done := TRUE END WriteString; PROCEDURE WriteLn* (t: Text); BEGIN ASSERT(~t.reading, 20); t.form.WriteLn; t.done := TRUE END WriteLn; PROCEDURE WriteInt* (t: Text; i: INTEGER); BEGIN ASSERT(~t.reading, 20); t.form.WriteInt(i); t.done := TRUE END WriteInt; BEGIN conv := Converters.list; WHILE (conv # NIL) & (conv.imp # "StdTextConv.ImportText") DO conv := conv.next END END ObxAscii.
Obx/Mod/Ascii.odc
MODULE ObxBlackBox; (** project = "BlackBox" organization = "www.oberon.ch" contributors = "Oberon microsystems" version = "System/Rsrc/About" copyright = "System/Rsrc/About" license = "Docu/BB-License" changes = " - YYYYMMDD, nn, ... " issues = " - ... " **) IMPORT Ports, Stores, Models, Views, Controllers, Properties, Fonts, Dialog, Services, Strings; CONST minVersion = 0; maxVersion = 0; minded = -3; marked = -4; markedAndMinded = -7; (* inside marks *) absorbed = -1; reflected = -2; (* outside marks *) TYPE Model = POINTER TO RECORD (Models.Model) board : POINTER TO ARRAY OF ARRAY OF BYTE; m, (* size of board *) p, (* number of atoms *) n, (* number of actual guess *) score: INTEGER; showsol: BOOLEAN END; Path = POINTER TO RECORD i, j: INTEGER; next: Path END; View = POINTER TO RECORD (Views.View) model: Model; i, j: INTEGER; d: INTEGER; font: Fonts.Font END; UpdateMsg = RECORD (Models.UpdateMsg) END; VAR para*: RECORD nrOfAtoms*, boardSize*: INTEGER END; seed: INTEGER; PROCEDURE UniRand (): REAL; CONST a = 16807; m = 2147483647; q = m DIV a; r = m MOD a; BEGIN seed := a*(seed MOD q) - r*(seed DIV q); IF seed <= 0 THEN seed := seed + m END; RETURN seed * (1.0/m) END UniRand; (* problem-specific part *) PROCEDURE Atom (m: Model; i,j: INTEGER): BOOLEAN; VAR b: BYTE; BEGIN b := m.board[i,j]; RETURN (b = minded) OR (b = markedAndMinded) END Atom; PROCEDURE Marked (m: Model; i,j: INTEGER): BOOLEAN; VAR b: BYTE; BEGIN b := m.board[i,j]; RETURN (b = marked) OR (b = markedAndMinded) END Marked; PROCEDURE Shoot (m: Model; i1, j1: INTEGER); VAR i, j, d, di, dj : INTEGER; BEGIN IF j1 = 0 THEN di := 0; dj := 1 ELSIF j1 = m.m+1 THEN di := 0; dj := -1 ELSIF i1 = 0 THEN di := 1; dj := 0 ELSIF i1 = m.m+1 THEN di := -1; dj := 0 END; i := i1; j := j1; IF ~Atom(m, i+di, j+dj) THEN REPEAT IF Atom(m, i+di+dj, j+di+dj) THEN d := di; di := -dj; dj := -d ELSIF Atom(m,i+di-dj, j-di+dj) THEN d := di; di := dj; dj := d ELSE i := i+di; j := j+dj END UNTIL (i=0) OR (i=m.m+1) OR (j=0) OR (j=m.m+1) OR Atom(m, i+di, j+dj); IF (i=0) OR (i=m.m+1) OR (j=0) OR (j=m.m+1) THEN IF (i = i1) & (j = j1) THEN m.board[i1, j1] := reflected ELSE INC(m.n); m.board[i,j] := SHORT(SHORT(m.n)); m.board[i1,j1] := SHORT(SHORT(m.n)) END ELSE m.board[i1,j1] := absorbed END ELSE m.board[i1,j1] := absorbed END END Shoot; PROCEDURE GetPath (m: Model; i, j: INTEGER; VAR p: Path); VAR d, di, dj : INTEGER; PROCEDURE AddPoint(i, j: INTEGER); VAR q: Path; BEGIN IF (p = NIL) OR (p.i # i) OR (p.j # j) THEN NEW(q); q.i := i; q.j := j; q.next := p; p := q END END AddPoint; BEGIN IF j = 0 THEN di := 0; dj := 1 ELSIF j = m.m+1 THEN di := 0; dj := -1 ELSIF i = 0 THEN di := 1; dj := 0 ELSIF i = m.m+1 THEN di := -1; dj := 0 END; IF ~Atom(m, i+di, j+dj) THEN AddPoint(i, j); REPEAT IF Atom(m, i+di+dj, j+di+dj) THEN d := di; di := -dj; dj := -d; AddPoint(i, j) ELSIF Atom(m, i+di-dj, j-di+dj) THEN d := di; di := dj; dj := d; AddPoint(i, j) ELSE i := i+di; j := j+dj END; UNTIL (i = 0) OR (i = m.m+1) OR (j = 0) OR (j = m.m+1) OR Atom(m, i+di, j+dj); IF ~((i = 0) OR (i = m.m+1) OR (j = 0) OR (j = m.m+1)) THEN i := i+di; j := j+dj END; AddPoint(i, j) END END GetPath; PROCEDURE NewPuzzle (m: Model); VAR i, j, k: INTEGER; BEGIN FOR i := 0 TO m.m+1 DO FOR j := 0 TO m.m+1 DO m.board[i,j] := 0 END END; k := 0; WHILE k < m.p DO i := 1 + SHORT(SHORT(ENTIER(UniRand()*m.m))); j := 1 + SHORT(SHORT(ENTIER(UniRand()*m.m))); IF ~Atom(m, i, j) THEN m.board[i,j] := minded; INC(k) END END END NewPuzzle; PROCEDURE Score (m: Model): INTEGER; VAR i, j, score, n: INTEGER; BEGIN score := 0; n := 0; FOR i := 0 TO m.m + 1 DO FOR j := 0 TO m.m + 1 DO IF (i = 0) OR (j = 0) OR (i = m.m+1) OR (j = m.m+1) THEN IF m.board[i,j] # 0 THEN INC(score) END ELSE IF Marked(m, i, j) THEN INC(n); IF ~Atom(m, i, j) THEN INC(score, 5) END END END END END; IF n < m.p THEN INC(score, 5 * (m.p - n)) END; RETURN score END Score; (* graphics part *) PROCEDURE DrawStringCentered (v: View; f: Ports.Frame; x, y: INTEGER; s: ARRAY OF CHAR); VAR asc, dsc, w: INTEGER; BEGIN v.font.GetBounds(asc, dsc, w); f.DrawString(x - v.font.StringWidth(s) DIV 2, y + asc DIV 2, Ports.black, s, v.font) END DrawStringCentered; PROCEDURE GetCoord (v: View; i, j: INTEGER; VAR x, y: INTEGER); BEGIN y := j * v.d + v.d DIV 2 + 1; x := i * v.d + v.d DIV 2 + 1; IF i = 0 THEN INC(x, v.d DIV 2) ELSIF i = v.model.m+1 THEN DEC(x, v.d DIV 2) ELSIF j = 0 THEN INC(y, v.d DIV 2) ELSIF j = v.model.m+1 THEN DEC(y, v.d DIV 2) END END GetCoord; (* Model *) PROCEDURE Init (m: Model); BEGIN m.m := para.boardSize; m.p := para.nrOfAtoms; NEW(m.board, m.m+2, m.m+2); NewPuzzle(m); m.n := 0; m.score := 0; m.showsol := FALSE END Init; PROCEDURE (m: Model) Externalize (VAR wr: Stores.Writer); VAR i, j: INTEGER; BEGIN wr.WriteVersion(maxVersion); wr.WriteInt(m.m); wr.WriteInt(m.p); wr.WriteInt(m.n); wr.WriteInt(m.score); wr.WriteBool(m.showsol); FOR i := 0 TO m.m+1 DO FOR j := 0 TO m.m+1 DO wr.WriteByte(m.board[i,j]) END END END Externalize; PROCEDURE (m: Model) Internalize (VAR rd: Stores.Reader); VAR version: INTEGER; i, j: INTEGER; BEGIN rd.ReadVersion(minVersion, maxVersion, version); IF ~rd.cancelled THEN rd.ReadInt(m.m); rd.ReadInt(m.p); rd.ReadInt(m.n); rd.ReadInt(m.score); rd.ReadBool(m.showsol); NEW(m.board, m.m+2, m.m+2); FOR i := 0 TO m.m+1 DO FOR j := 0 TO m.m+1 DO rd.ReadByte(m.board[i,j]) END END END END Internalize; PROCEDURE (m: Model) CopyFrom (source: Stores.Store); VAR i, j: INTEGER; BEGIN WITH source: Model DO Init(m); m.m := source.m; NEW(m.board, m.m+2, m.m+2); m.n := source.n; m.p := source.p; m.score := source.score; m.showsol := source.showsol; FOR i := 0 TO m.m+1 DO FOR j := 0 TO m.m+1 DO m.board[i,j] := source.board[i,j] END END END END CopyFrom; (* View *) PROCEDURE (v: View) Externalize (VAR wr: Stores.Writer); BEGIN wr.WriteVersion(maxVersion); wr.WriteInt(v.i); wr.WriteInt(v.j); wr.WriteStore(v.model) END Externalize; PROCEDURE (v: View) Internalize (VAR rd: Stores.Reader); VAR version: INTEGER; st: Stores.Store; BEGIN rd.ReadVersion(minVersion, maxVersion, version); IF ~rd.cancelled THEN rd.ReadInt(v.i); rd.ReadInt(v.j); rd.ReadStore(st); v.model := st(Model); v.d := 0; v.font := NIL END END Internalize; PROCEDURE (v: View) CopyFromModelView (source: Views.View; model: Models.Model); BEGIN ASSERT(model IS Model, 20); WITH source: View DO v.model := model(Model); v.i := source.i; v.j := source.j; v.d := source.d; v.font := source.font END END CopyFromModelView; PROCEDURE (v: View) ThisModel (): Models.Model; BEGIN RETURN v.model END ThisModel; PROCEDURE (v: View) Restore (f: Views.Frame; l, t, r, b: INTEGER); VAR w, h, d, x, y, x1, y1, asc, dsc, fw, i, j: INTEGER; p: Path; s: ARRAY 16 OF CHAR; BEGIN v.context.GetSize(w, h); d := w DIV (v.model.m + 2); IF (v.font = NIL) OR (v.d # d) THEN v.d := d; v.font := Fonts.dir.This("Chicago", d * 2 DIV 3, {}, Fonts.normal) END; FOR i := 1 TO v.model.m + 1 DO f.DrawLine(d, i * d,w - d, i * d, f.unit, 0); f.DrawLine(i * d, d, i * d,w - d, f.unit, 0) END; FOR i := 0 TO v.model.m + 1 DO FOR j := 0 TO v.model.m + 1 DO x := i * d + d DIV 2; y := j * d + d DIV 2; IF (i = 0) OR (i = v.model.m + 1) OR (j = 0) OR (j = v.model.m + 1) THEN IF v.model.board[i , j] = absorbed THEN DrawStringCentered(v, f, x, y, "A") ELSIF v.model.board[i , j] = reflected THEN DrawStringCentered(v, f, x, y, "R") ELSIF v.model.board[i, j] > 0 THEN Strings.IntToString(v.model.board[i, j], s); DrawStringCentered(v, f, x, y, s) END ELSE IF Marked(v.model, i, j) THEN r := (9 * d) DIV 20; f.DrawOval(x - r, y - r, x + r, y + r, Ports.fill, Ports.black) END; IF v.model.showsol & Atom(v.model, i, j) THEN r := d DIV 3; IF Marked(v.model, i, j) THEN f.DrawOval(x - r, y - r, x + r, y + r, Ports.fill, Ports.white) ELSE f.DrawOval(x - r, y - r, x + r, y + r, Ports.fill, Ports.black) END END END END END; IF (v.i > 0) OR (v.j > 0) THEN GetPath(v.model, v.i, v.j, p); IF p # NIL THEN GetCoord(v, p.i, p.j, x, y); p := p.next; WHILE p # NIL DO GetCoord(v, p.i, p.j, x1, y1); f.DrawLine(x, y, x1, y1, 2 * f.unit, 0); x := x1; y := y1; p := p.next END END END; Strings.IntToString(v.model.p, s); v.font.GetBounds(asc, dsc, fw); x := d; y := (v.model.m + 2) * d + (d + asc) DIV 2; f.DrawString(x, y, Ports.black, "Atoms: ", v.font); x := x + v.font.StringWidth("Atoms: "); f.DrawString(x, y, Ports.black, s, v.font); IF v.model.showsol THEN x := x + v.font.StringWidth(s); f.DrawString(x, y, Ports.black, " Score: ", v.font); x := x + v.font.StringWidth(" Score: "); Strings.IntToString(v.model.score, s); f.DrawString(x, y, Ports.black, s, v.font) END END Restore; PROCEDURE Track (v: View; f: Views.Frame; x, y: INTEGER; buttons: SET); VAR i, j: INTEGER; msg: UpdateMsg; BEGIN i := SHORT(x DIV v.d); j := SHORT(y DIV v.d); IF (i > 0) & (i <= v.model.m) & (j > 0) & (j <= v.model.m) THEN (* inside *) IF Marked(v.model, i, j) THEN INC(v.model.board[i, j], 4) ELSE DEC(v.model.board[i, j], 4) END ELSIF ((i = 0) OR (i = v.model.m + 1)) & (j > 0) & (j <= v.model.m) OR ((j = 0) OR (j = v.model.m + 1)) & (i > 0) & (i <= v.model.m) THEN IF v.model.board[i, j] = 0 THEN Shoot(v.model, i, j) END; IF v.model.showsol THEN IF Controllers.modify IN buttons THEN v.i := i; v.j := j ELSE v.i := 0; v.j := 0 END END END; Models.Broadcast(v.model, msg) END Track; PROCEDURE (v: View) HandleModelMsg (VAR msg: Models.Message); VAR w, h: INTEGER; BEGIN WITH msg: UpdateMsg DO IF ~v.model.showsol THEN v.i := 0; v.j := 0 END; (* adjust view to change of model *) v.context.GetSize(w, h); Views.UpdateIn(v, 0, 0, w, h, Views.keepFrames) ELSE END END HandleModelMsg; PROCEDURE^ ShowSolution*; PROCEDURE (v: View) HandleCtrlMsg (f: Views.Frame; VAR msg: Controllers.Message; VAR focus: Views.View); BEGIN WITH msg: Controllers.TrackMsg DO Track(v, f, msg.x, msg.y, msg.modifiers); Views.SetDirty(v) | msg: Controllers.PollOpsMsg DO msg.type := "ObxBlackBox.View" | msg: Controllers.EditMsg DO ShowSolution ELSE END END HandleCtrlMsg; PROCEDURE (v: View) HandlePropMsg (VAR msg: Properties.Message); BEGIN WITH msg: Properties.SizePref DO IF (msg.w > Views.undefined) & (msg.h > Views.undefined) THEN Properties.ProportionalConstraint(v.model.m, v.model.m + 1, msg.fixedW, msg.fixedH, msg.w, msg.h) ELSE msg.w := 100 * Ports.mm; msg.h := msg.w * (v.model.m + 1) DIV v.model.m; END; | msg: Properties.FocusPref DO msg.setFocus := TRUE ELSE END END HandlePropMsg; (* commands *) PROCEDURE Deposit*; VAR v: View; m: Model; BEGIN NEW(m); Init(m); NEW(v); v.model := m; Stores.Join(v, m); Views.Deposit(v) END Deposit; PROCEDURE ShowSolution*; VAR v : Views.View; msg: UpdateMsg; BEGIN v := Controllers.FocusView(); IF v # NIL THEN WITH v: View DO v.model.showsol := TRUE; v.model.score := Score(v.model); Models.Broadcast(v.model, msg) ELSE END END END ShowSolution; PROCEDURE ShowSolutionGuard* (VAR par: Dialog.Par); VAR v: Views.View; BEGIN v := Controllers.FocusView(); par.disabled := (v = NIL) OR ~(v IS View) OR v(View).model.showsol END ShowSolutionGuard; PROCEDURE New*; VAR v: Views.View; msg: UpdateMsg; BEGIN v := Controllers.FocusView(); IF v # NIL THEN WITH v: View DO NewPuzzle(v.model); v.model.n := 0; v.model.score := 0; v.model.showsol := FALSE; v.i := 0; v.j := 0; Models.Broadcast(v.model, msg) END END END New; PROCEDURE Set*; VAR v : Views.View; msg: UpdateMsg; i, j: INTEGER; BEGIN v := Controllers.FocusView(); IF v # NIL THEN WITH v: View DO v.model.p := 0; FOR i := 0 TO v.model.m + 1 DO FOR j := 0 TO v.model.m + 1 DO IF Marked(v.model, i, j) THEN INC(v.model.p); v.model.board[i,j] := minded ELSE v.model.board[i,j] := 0 END END END; v.model.n := 0; v.model.score := 0; v.model.showsol := FALSE; v.i := 0; v.j := 0; Models.Broadcast(v.model, msg) END END END Set; BEGIN seed := SHORT(Services.Ticks()); para.boardSize := 8; para.nrOfAtoms := 4 END ObxBlackBox.
Obx/Mod/BlackBox.odc
MODULE ObxButtons; (** project = "BlackBox" organization = "www.oberon.ch" contributors = "Oberon microsystems" version = "System/Rsrc/About" copyright = "System/Rsrc/About" license = "Docu/BB-License" changes = " - 20070413, mf, minor cleanup " issues = " - ... " **) IMPORT Dialog, Stores, Fonts, Ports, Views, Controllers, Properties, Controls; CONST minVersion = 0; maxVersion = 0; TYPE View = POINTER TO RECORD (Views.View) font: Fonts.Font; color: INTEGER; link: Dialog.String; label: ARRAY 256 OF CHAR END; PROCEDURE (v: View) Internalize (VAR rd: Stores.Reader); VAR version: INTEGER; BEGIN rd.ReadVersion(minVersion, maxVersion, version); IF ~rd.cancelled THEN Views.ReadFont(rd, v.font); rd.ReadInt(v.color); rd.ReadString(v.link); rd.ReadString(v.label) END END Internalize; PROCEDURE (v: View) Externalize (VAR wr: Stores.Writer); BEGIN wr.WriteVersion(maxVersion); Views.WriteFont(wr, v.font); wr.WriteInt(v.color); wr.WriteString(v.link); wr.WriteString(v.label) END Externalize; PROCEDURE (v: View) CopyFromSimpleView (source: Views.View); BEGIN WITH source: View DO v.font := source.font; v.color := source.color; v.link := source.link; v.label := source.label END END CopyFromSimpleView; PROCEDURE (v: View) Restore (f: Views.Frame; l, t, r, b: INTEGER); VAR w, h, x, y, asc, dsc, fw: INTEGER; BEGIN (* restore view at least in rectangle (l, t, r, b) *) v.context.GetSize(w, h); (* the container context maintains the view's size *) f.DrawRect(0, 0, w, h, f.dot, v.color); (* f.dot is close to one point, i.e. 1/72 inch *) x := (w - v.font.StringWidth(v.label)) DIV 2; v.font.GetBounds(asc, dsc, fw); y := h DIV 2 + (asc + dsc) DIV 3; f.DrawString(x, y, v.color, v.label, v.font) END Restore; PROCEDURE (v: View) HandleCtrlMsg ( f: Views.Frame; VAR msg: Controllers.Message; VAR focus: Views.View ); VAR x, y, w, h, res: INTEGER; modifiers: SET; inside, isDown: BOOLEAN; BEGIN WITH msg: Controllers.TrackMsg DO (* mouse button was pressed *) v.context.GetSize(w, h); f.MarkRect(0, 0, w, h, Ports.fill, Ports.invert, Ports.show); inside := TRUE; REPEAT (* mouse tracking loop *) f.Input(x, y, modifiers, isDown); IF inside # (x >= 0) & (y >= 0) & (x < w) & (y < h) THEN (* toggle state *) inside := ~inside; f.MarkRect(0, 0, w, h, Ports.fill, Ports.invert, inside) END UNTIL ~isDown; IF inside THEN (* mouse was released inside the control *) f.MarkRect(0, 0, w, h, Ports.fill, Ports.invert, Ports.hide); IF v.link # "" THEN Dialog.Call(v.link, "", res) (* interpret and execute the string in v.link *) END END ELSE (* ignore other messages *) END END HandleCtrlMsg; PROCEDURE GetStdProp (v: View): Properties.Property; VAR prop: Properties.StdProp; BEGIN NEW(prop); prop.color.val := v.color; prop.typeface := v.font.typeface; prop.size := v.font.size; prop.style.val := v.font.style; prop.weight := v.font.weight; prop.valid := {Properties.color..Properties.weight}; prop.known := prop.valid; RETURN prop END GetStdProp; PROCEDURE SetStdProp (v: View; prop: Properties.StdProp); VAR typeface: Fonts.Typeface; size: INTEGER; style: SET; weight: INTEGER; BEGIN IF Properties.color IN prop.valid THEN v.color := prop.color.val END; typeface := v.font.typeface; size := v.font.size; style := v.font.style; weight := v.font.weight; IF Properties.typeface IN prop.valid THEN typeface := prop.typeface END; IF Properties.size IN prop.valid THEN size := prop.size END; IF Properties.style IN prop.valid THEN style := prop.style.val END; IF Properties.weight IN prop.valid THEN weight := prop.weight END; v.font := Fonts.dir.This(typeface, size, style, weight); END SetStdProp; PROCEDURE (v: View) HandlePropMsg (VAR msg: Properties.Message); CONST defaultWidth = 20 * Ports.mm; defaultHeight = 7 * Ports.mm; VAR p: Controls.Prop; prop: Properties.Property; BEGIN WITH msg: Properties.FocusPref DO (* a button is a "hot focus", i.e. does not remain focused *) msg.hotFocus := TRUE | msg: Properties.SizePref DO (* return the default size of a button *) IF msg.w = Views.undefined THEN msg.w := defaultWidth END; IF msg.h = Views.undefined THEN msg.h := defaultHeight END | msg: Properties.PollMsg DO (* return the standard font, color, and control properties *) NEW(p); p.link := v.link; p.label := v.label$; p.valid := {Controls.link, Controls.label}; p.known := p.valid; Properties.Insert(msg.prop, p); Properties.Insert(msg.prop, GetStdProp(v)) | msg: Properties.SetMsg DO (* set the standard font, color, or control properties *) prop := msg.prop; WHILE prop # NIL DO WITH prop: Controls.Prop DO (* standard control properties *) Views.BeginModification(Views.notUndoable, v); IF Controls.link IN prop.valid THEN v.link := prop.link; END; IF Controls.label IN prop.valid THEN v.label := prop.label$ END; Views.EndModification(Views.notUndoable, v); Views.Update(v, Views.keepFrames) (* causes a delayed redrawing of the view *) | prop: Properties.StdProp DO (* standard font and color properties *) Views.BeginModification(Views.notUndoable, v); SetStdProp(v, prop); Views.EndModification(Views.notUndoable, v); Views.Update(v, Views.keepFrames) (* causes a delayed redrawing of the view *) ELSE END; prop := prop.next END ELSE (* ignore other messages *) END END HandlePropMsg; PROCEDURE New* (): Views.View; VAR v: View; BEGIN (* create a new button *) NEW(v); v.color := Ports.defaultColor; v.font := Fonts.dir.Default(); v.link := ""; v.label := ""; RETURN v END New; PROCEDURE Deposit*; BEGIN Views.Deposit(New()) END Deposit; END ObxButtons.
Obx/Mod/Buttons.odc
MODULE ObxCalc; (** project = "BlackBox" organization = "www.oberon.ch" contributors = "Oberon microsystems" version = "System/Rsrc/About" copyright = "System/Rsrc/About" license = "Docu/BB-License" changes = " - YYYYMMDD, nn, ... " issues = " - ... " **) IMPORT Stores, Ports, Views, Properties, Controllers, Dialog, Fonts, Strings; CONST minVersion = 0; maxVersion = 0; mm = Ports.mm; CR = 0DX; TYPE Stack = POINTER TO RECORD next: Stack; val: INTEGER END; View = POINTER TO RECORD (Views.View) stack: Stack; editMode, enterMode: BOOLEAN END; VAR font: Fonts.Font; labels: ARRAY 21 OF CHAR; PROCEDURE LocateField (v: View; f: Views.Frame; x, y: INTEGER; VAR i, j: INTEGER; VAR valid: BOOLEAN); BEGIN x := x DIV mm - 3; y := y DIV mm - 12; i := SHORT(x DIV 9); j := SHORT(y DIV 9); valid := (i >= 0) & (i < 4) & (j >= 0) & (j < 5) & (x MOD 9 < 7) & (y MOD 9 < 7) END LocateField; PROCEDURE SelectField (v: View; f: Ports.Frame; i, j: INTEGER); CONST point = Ports.point; VAR x, y: INTEGER; BEGIN x := (3 + i * 9) * mm; y := (12 + j * 9) * mm; f.MarkRect(x + point, y + point, x + 6 * mm - point, y + 6 * mm - point, Ports.fill, Ports.hilite, TRUE) END SelectField; PROCEDURE HandleKey (v: View; i, j: INTEGER); VAR k, n: INTEGER; s: Stack; BEGIN k := j*4 + i; s := v.stack; IF k IN {0, 1, 2, 3, 7, 11, 15} THEN IF s.next # NIL THEN IF k = 0 THEN (* swap *) s := s.next; v.stack.next := s.next; s.next := v.stack; v.stack := s ELSIF k = 1 THEN v.stack := s.next ELSIF k IN {2, 3} THEN IF s.val = 0 THEN Dialog.Beep ELSIF k = 2 THEN s.next.val := s.next.val MOD s.val; v.stack := s.next ELSE s.next.val := s.next.val DIV s.val; v.stack := s.next END ELSIF k = 7 THEN s.next.val := s.next.val * s.val; v.stack := s.next ELSIF k = 11 THEN s.next.val := s.next.val - s.val; v.stack := s.next ELSIF k = 15 THEN s.next.val := s.next.val + s.val; v.stack := s.next END ELSE IF k = 0 THEN NEW(s); s.val := 0; s.next := v.stack; v.stack := s ELSIF k = 11 THEN s.val := -s.val ELSIF k = 15 THEN (* skip *) ELSE s.val := 0 END END; v.editMode := FALSE ELSIF k = 18 THEN (* *) s.val := - s.val ELSIF k = 16THEN (* delete *) IF v.editMode THEN s.val := s.val DIV 10 ELSE s.val := 0; v.editMode := TRUE END ELSIF k = 19 THEN (* enter *) NEW(s); s.val := v.stack.val; s.next := v.stack; v.stack := s; v.editMode := FALSE ELSE (* edit operation *) IF k = 17 THEN (* 0 *) n := 0 ELSE n := (3-j)*3 + 1 + i END; IF ~v.editMode & ~v.enterMode THEN NEW(s); s.val := n; s.next := v.stack; v.stack := s; v.editMode := TRUE ELSIF ~v.editMode THEN s.val := n; v.editMode := TRUE ELSIF s.val >= 0 THEN IF s.val > (MAX(INTEGER) - n) DIV 10 THEN Dialog.Beep ELSE s.val := 10*s.val + n END ELSE IF s.val < (MIN(INTEGER) + n) DIV 10 THEN Dialog.Beep ELSE s.val := 10*s.val - n END END END; v.enterMode := k = 19; Views.Update(v, Views.keepFrames) END HandleKey; PROCEDURE Track (v: View; f: Views.Frame; x, y: INTEGER; buttons: SET); VAR i, j, i1, j1: INTEGER; isDown, valid, sel: BOOLEAN; m: SET; BEGIN LocateField(v, f, x, y, i, j, sel); IF sel THEN SelectField(v, f, i, j); REPEAT f.Input(x, y, m, isDown); LocateField(v, f, x, y, i1, j1, valid); IF ~valid OR (i1 # i) OR (j1 # j) THEN IF sel THEN sel := FALSE; SelectField(v, f, i, j) END ELSE IF ~sel THEN sel := TRUE; SelectField(v, f, i, j) END END UNTIL ~isDown; IF sel THEN HandleKey(v, i, j); SelectField(v, f, i, j) END END END Track; PROCEDURE Init (v: View); BEGIN NEW(v.stack); v.stack.val := 0; v.editMode := TRUE; v.enterMode := FALSE END Init; (* View *) PROCEDURE (v: View) Externalize (VAR wr: Stores.Writer); BEGIN wr.WriteVersion(maxVersion); END Externalize; PROCEDURE (v: View) Internalize (VAR rd: Stores.Reader); VAR version: INTEGER; BEGIN rd.ReadVersion(minVersion, maxVersion, version); IF ~rd.cancelled THEN Init(v) END END Internalize; PROCEDURE (v: View) CopyFromSimpleView (source: Views.View); BEGIN Init(v) END CopyFromSimpleView; PROCEDURE (v: View) Restore (f: Views.Frame; l, t, r, b: INTEGER); VAR i, j: INTEGER; x, y, asc, dsc, w: INTEGER; s: ARRAY 2 OF CHAR; display: ARRAY 12 OF CHAR; BEGIN Strings.IntToStringForm(v.stack.val, Strings.decimal, 11, " ", FALSE, display); f.DrawRect(0, 0, 40 * mm, 58 * mm, 0, Ports.black); f.DrawRect(3 * mm, 3 * mm, 37 * mm, 10 * mm, 0, Ports.black); f.DrawString(6 * mm, 8 * mm, Ports.black, display, font); j := 0; WHILE j # 5 DO i := 0; y := (12 + j * 9) * mm; WHILE i # 4 DO x := (3 + i * 9) * mm; f.DrawRect(x, y, x + 6 * mm, y + 6 * mm, 0, Ports.black); f.DrawRect(x + mm, y + 6 * mm, x + 7 * mm, y + 7 * mm, Ports.fill, Ports.black); f.DrawRect(x + 6 * mm, y + Ports.mm, x + 7 * mm, y + 7 * mm, Ports.fill, Ports.black); s[0] := labels[j * 4 + i]; s[1] := 0X; font.GetBounds(asc, dsc, w); f.DrawString(x + 3 * mm - w DIV 2, y + 3 * mm + asc DIV 2, Ports.black, s, font); INC(i) END; INC(j) END END Restore; PROCEDURE (v: View) HandleCtrlMsg (f: Views.Frame; VAR msg: Controllers.Message; VAR focus: Views.View); VAR i, j, k: INTEGER; BEGIN WITH msg: Controllers.TrackMsg DO Track(v, f, msg.x, msg.y, msg.modifiers) | msg: Controllers.EditMsg DO IF msg.op = Controllers.pasteChar THEN IF msg.char = CR THEN k := 19 ELSIF msg.char = 08X THEN k := 16 ELSE k := 0; WHILE (k # 20) & (CAP(labels[k]) # CAP(msg.char)) DO INC(k) END END; IF k < 20 THEN i := k MOD 4; j := k DIV 4; SelectField(v, f, i, j); HandleKey(v, i, j); SelectField(v, f, i, j) END END ELSE END END HandleCtrlMsg; PROCEDURE (v: View) HandlePropMsg (VAR msg: Properties.Message); BEGIN WITH msg: Properties.ResizePref DO msg.fixed := TRUE | msg: Properties.SizePref DO msg.w := 40 * mm; msg.h := 58 * mm | msg: Properties.FocusPref DO msg.setFocus := TRUE ELSE END END HandlePropMsg; (* commands *) PROCEDURE New* (): View; VAR v: View; BEGIN NEW(v); Init(v); RETURN v END New; PROCEDURE Deposit*; BEGIN Views.Deposit(New()) END Deposit; BEGIN font := Fonts.dir.This("Courier", 11 * Fonts.point, {}, Fonts.normal); labels := "sp/789*456-123+C0^" END ObxCalc.
Obx/Mod/Calc.odc
MODULE ObxCaps; (** project = "BlackBox" organization = "www.oberon.ch" contributors = "Oberon microsystems" version = "System/Rsrc/About" copyright = "System/Rsrc/About" license = "Docu/BB-License" changes = " - YYYYMMDD, nn, ... " issues = " - ... " **) 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.
Obx/Mod/Caps.odc
MODULE ObxContIter; (** project = "BlackBox" organization = "www.oberon.ch" contributors = "Oberon microsystems" version = "System/Rsrc/About" copyright = "System/Rsrc/About" license = "Docu/BB-License" changes = " - YYYYMMDD, nn, ... " issues = " - ... " **) IMPORT Views, Containers, Controls; PROCEDURE Do*; (** focus the first control whose label is "magic name" **) VAR c: Containers.Controller;v: Views.View; BEGIN c := Containers.Focus(); IF c # NIL THEN c.GetFirstView(Containers.any, v); WHILE (v # NIL) & ~((v IS Controls.Control) & (v(Controls.Control).label = "magic name")) DO c.GetNextView(Containers.any, v) END; IF v # NIL THEN c.SetFocus(v) END END END Do; END ObxContIter.
Obx/Mod/ContIter.odc
MODULE ObxControls; (** project = "BlackBox" organization = "www.oberon.ch" contributors = "Oberon microsystems" version = "System/Rsrc/About" copyright = "System/Rsrc/About" license = "Docu/BB-License" changes = " - YYYYMMDD, nn, ... " issues = " - ... " **) IMPORT Dialog, Ports, Properties, Views; CONST beginner = 0; advanced = 1; expert = 2; guru = 3; (* user classes *) TYPE View = POINTER TO RECORD (Views.View) size: INTEGER (* border size in mm *) END; VAR data*: RECORD class*: INTEGER; (* current user class *) list*: Dialog.List; (* list of currently available sizes, derived from class *) width*: INTEGER (* width of next view to be opened. Derived from class, or entered through a text entry field *) END; predef: ARRAY 6 OF INTEGER; (* table of predefined sizes *) PROCEDURE SetList; BEGIN IF data.class = beginner THEN data.list.SetLen(1); data.list.SetItem(0, "default") ELSIF data.class = advanced THEN data.list.SetLen(4); data.list.SetItem(0, "default"); data.list.SetItem(1, "small"); data.list.SetItem(2, "medium"); data.list.SetItem(3, "large"); ELSE data.list.SetLen(6); data.list.SetItem(0, "default"); data.list.SetItem(1, "small"); data.list.SetItem(2, "medium"); data.list.SetItem(3, "large"); data.list.SetItem(4, "tiny"); data.list.SetItem(5, "huge"); END END SetList; (* View *) PROCEDURE (v: View) CopyFromSimpleView (source: Views.View); BEGIN v.size := source(View).size END CopyFromSimpleView; PROCEDURE (v: View) Restore (f: Views.Frame; l, t, r, b: INTEGER); BEGIN (* fill view with a red square of size v.size *) IF v.size = 0 THEN v.size := predef[0] END; (* lazy initialization of size *) f.DrawRect(0, 0, v.size, v.size, Ports.fill, Ports.red) END Restore; PROCEDURE (v: View) HandlePropMsg (VAR msg: Views.PropMessage); BEGIN WITH msg: Properties.SizePref DO IF v.size = 0 THEN v.size := predef[0] END; (* lazy initialization of size *) msg.w := v.size; msg.h := v.size (* tell environment about desired width and height *) ELSE (* ignore other messages *) END END HandlePropMsg; (* notifiers *) PROCEDURE ClassNotify* (op, from, to: INTEGER); BEGIN (* react to change in data.class *) IF op = Dialog.changed THEN IF (to = beginner) OR (to = advanced) & (data.list.index > 3) THEN (* if class is reduced, make sure that selection contains legal elements *) data.list.index := 0; data.width := predef[0]; (* modify interactor *) Dialog.Update(data) (* redraw controls where necessary *) END; SetList; Dialog.UpdateList(data.list) (* reconstruct list box contents *) END END ClassNotify; PROCEDURE ListNotify* (op, from, to: INTEGER); BEGIN (* reacto to change in data.list (index to was selected) *) IF op = Dialog.changed THEN data.width := predef[to]; (* modify interactor *) Dialog.Update(data) (* redraw controls where necessary *) END END ListNotify; (* guards *) PROCEDURE ListGuard* (VAR par: Dialog.Par); BEGIN (* disable list box for a beginner *) par.disabled := data.class = beginner END ListGuard; PROCEDURE WidthGuard* (VAR par: Dialog.Par); BEGIN (* make text entry field read-only if user is not guru *) par.readOnly := data.class # guru END WidthGuard; (* commands *) PROCEDURE Open*; VAR v: View; BEGIN NEW(v); (* create and initialize a new view *) v.size := data.width * Ports.mm; (* define view's size in function of class *) Views.OpenAux(v, "Example") (* open the view in a window *) END Open; BEGIN (* initialization of global variables *) predef[0] := 40; predef[1] := 30; predef[2] := 50; (* predefined sizes *) predef[3] := 70; predef[4] := 20; predef[5] := 100; data.class := beginner; (* default values *) data.list.index := 0; data.width := predef[0]; SetList END ObxControls.
Obx/Mod/Controls.odc
MODULE ObxControlShifter; (** project = "BlackBox" organization = "www.oberon.ch" contributors = "Oberon microsystems" version = "System/Rsrc/About" copyright = "System/Rsrc/About" license = "Docu/BB-License" changes = " - YYYYMMDD, nn, ... " issues = " - ... " **) IMPORT Ports, FormControllers; PROCEDURE Shift*; VAR c: FormControllers.Controller; sel: FormControllers.List; BEGIN c := FormControllers.Focus(); IF (c # NIL) & c.HasSelection() THEN sel := c.GetSelection(); (* generates a list with references to the selected views *) WHILE sel # NIL DO c.form.Move(sel.view, 10 * Ports.mm, 0); (* move to the right *) sel := sel.next END END END Shift; END ObxControlShifter.
Obx/Mod/ControlShifter.odc
MODULE ObxConv; (** project = "BlackBox" organization = "www.oberon.ch" contributors = "Oberon microsystems" version = "System/Rsrc/About" copyright = "System/Rsrc/About" license = "Docu/BB-License" changes = " - YYYYMMDD, nn, ... " issues = " - ... " **) IMPORT Files, Stores, TextModels, TextViews; PROCEDURE ImportText* (f: Files.File; OUT s: Stores.Store); VAR r: Stores.Reader; t: TextModels.Model; w: TextModels.Writer; byte: SHORTCHAR; ch: CHAR; len: INTEGER; BEGIN ASSERT(f # NIL, 20); ASSERT(s = NIL, 21); (* ASSERT(f.type = "TEXT", 22); (* the type is platform specific*) *) r.ConnectTo(f); r.SetPos(0); len := f.Length(); t := TextModels.dir.New(); w := t.NewWriter(NIL); WHILE len # 0 DO r.ReadSChar(byte); ch := byte; (* should translate character set here *) w.WriteChar(ch); DEC(len) END; s := TextViews.dir.New(t) END ImportText; PROCEDURE ExportText* (s: Stores.Store; f: Files.File); VAR w: Stores.Writer; t: TextModels.Model; r: TextModels.Reader; len: INTEGER; ch: CHAR; byte: SHORTCHAR; BEGIN ASSERT(s # NIL, 20); ASSERT(f # NIL, 21); ASSERT(f.Length() = 0, 22); ASSERT(s IS TextViews.View, 23); w.ConnectTo(f); w.SetPos(0); t := s(TextViews.View).ThisModel(); len := t.Length(); r := t.NewReader(NIL); WHILE len # 0 DO r.ReadChar(ch); byte := SHORT(ch); (* should translate character set here *) w.WriteSChar(byte); DEC(len) END END ExportText; END ObxConv.
Obx/Mod/Conv.odc
MODULE ObxCount0; (** project = "BlackBox" organization = "www.oberon.ch" contributors = "Oberon microsystems" version = "System/Rsrc/About" copyright = "System/Rsrc/About" license = "Docu/BB-License" changes = " - YYYYMMDD, nn, ... " issues = " - ... " **) IMPORT TextModels, TextControllers, StdLog; PROCEDURE Do*; (** use TextCmds.SelectionGuard as guard for this command **) VAR c: TextControllers.Controller; from, to, schars, chars, views: INTEGER; rd: TextModels.Reader; BEGIN c := TextControllers.Focus(); IF (c # NIL) & c.HasSelection() THEN c.GetSelection(from, to); (* get selection range; from < to *) rd := c.text.NewReader(NIL); (* create a new reader for this text model *) rd.SetPos(from); (* set the reader to beginning of selection *) rd.Read; (* read the first element of the text selection *) schars := 0; chars := 0; views := 0; (* counter variables *) WHILE rd.Pos() # to DO (* read all elements of the text selection *) IF rd.view # NIL THEN (* element is a view *) INC(views) ELSIF rd.char < 100X THEN (* element is a Latin-1 character *) INC(schars) ELSE (* element is Unicode character *) INC(chars) END; rd.Read (* read next element of the text selection *) END; StdLog.String("Latin-1 characters: "); StdLog.Int(schars); StdLog.Ln; StdLog.String("Unicode characters: "); StdLog.Int(chars); StdLog.Ln; StdLog.String("Views: "); StdLog.Int(views); StdLog.Ln; StdLog.Ln END END Do; END ObxCount0.
Obx/Mod/Count0.odc
MODULE ObxCount1; (** project = "BlackBox" organization = "www.oberon.ch" contributors = "Oberon microsystems" version = "System/Rsrc/About" copyright = "System/Rsrc/About" license = "Docu/BB-License" changes = " - 20080904, et, Condition for loop termination corrected " issues = " - ... " **) IMPORT TextMappers, TextControllers, StdLog; PROCEDURE Do*; (** use TextCmds.SelectionGuard as guard for this command **) VAR c: TextControllers.Controller; from, to, ints, reals, strings: INTEGER; s: TextMappers.Scanner; BEGIN c := TextControllers.Focus(); IF (c # NIL) & c.HasSelection() THEN c.GetSelection(from, to); (* get selection range; from < to *) s.ConnectTo(c.text); (* connect scanner to this text model *) s.SetPos(from); (* set the reader to beginning of selection *) s.Scan; (* read the first symbol of the text selection *) ints := 0; reals := 0; strings := 0; (* counter variables *) WHILE s.start < to DO (* read all symbols starting in the text selection *) IF s.type = TextMappers.int THEN (* symbol is an integer number *) INC(ints) ELSIF s.type = TextMappers.real THEN (* symbol is a real number *) INC(reals) ELSIF s.type = TextMappers.string THEN (* symbol is a string/identifier *) INC(strings) END; s.Scan (* read next symbol of the text selection *) END; StdLog.String("Integers: "); StdLog.Int(ints); StdLog.Ln; StdLog.String("Reals: "); StdLog.Int(reals); StdLog.Ln; StdLog.String("Strings: "); StdLog.Int(strings); StdLog.Ln; StdLog.Ln END END Do; END ObxCount1.
Obx/Mod/Count1.odc
MODULE ObxCtrls; (** project = "BlackBox" organization = "www.oberon.ch" contributors = "Oberon microsystems" version = "System/Rsrc/About" copyright = "System/Rsrc/About" license = "Docu/BB-License" changes = " - YYYYMMDD, nn, ... " issues = " - ... " **) IMPORT Meta, Dialog, Ports, Stores, Views, Controllers, Properties, Controls; CONST minVersion = 0; maxVersion = 0; arrowUp = 1EX; arrowDown = 1FX; TYPE Control = POINTER TO RECORD (Controls.Control) END; VAR x*: INTEGER; PROCEDURE Paint (c: Control; f: Views.Frame); VAR w, h, y, val: INTEGER; BEGIN c.context.GetSize(w, h); IF ~c.disabled & c.item.Valid() THEN val := c.item.IntVal(); IF val < 0 THEN val := 0 ELSIF val > 100 THEN val := 100 END; y := f.dot + (h - 2 * f.dot) * (100 - val) DIV 100; IF val > 0 THEN f.DrawRect(f.dot, y, w - f.dot, h - f.dot, Ports.fill, Ports.blue) END; IF val < 100 THEN f.DrawRect(f.dot, f.dot, w - f.dot, y, Ports.fill, Ports.background) END ELSE f.DrawRect(f.dot, f.dot, w - f.dot, h - f.dot, Ports.fill, Ports.grey25) END; f.DrawRect(0, 0, w, h, f.dot, Ports.defaultColor) END Paint; PROCEDURE ChangeValue (c: Control; f: Views.Frame; new: INTEGER); VAR old: INTEGER; BEGIN old := c.item.IntVal(); IF new < 0 THEN new := 0 ELSIF new > 100 THEN new := 100 END; IF new # old THEN c.item.PutIntVal(new); Paint(c, f); Controls.Notify(c, f, Dialog.changed, old, new) END END ChangeValue; PROCEDURE Track (c: Control; f: Views.Frame; VAR msg: Controllers.TrackMsg); VAR x, y, y0, w, h: INTEGER; m: SET; isDown: BOOLEAN; BEGIN c.context.GetSize(w, h); DEC(h, 2 * f.dot); y0 := -1; REPEAT f.Input(x, y, m, isDown); IF y # y0 THEN ChangeValue(c, f, 100 - y * 100 DIV h); y0 := y END UNTIL ~isDown; END Track; PROCEDURE Edit (c: Control; f: Views.Frame; VAR msg: Controllers.EditMsg); VAR val: INTEGER; BEGIN IF msg.op = Controllers.pasteChar THEN val := c.item.IntVal(); IF msg.char = arrowUp THEN ChangeValue(c, f, val + 1) ELSIF msg.char = arrowDown THEN ChangeValue(c, f, val - 1) ELSE Dialog.Beep END END END Edit; (* Control *) PROCEDURE (c: Control) Internalize2 (VAR rd: Stores.Reader); VAR version: INTEGER; BEGIN rd.ReadVersion(minVersion, maxVersion, version) END Internalize2; PROCEDURE (c: Control) Externalize2 (VAR wr: Stores.Writer); BEGIN wr.WriteVersion(maxVersion) END Externalize2; PROCEDURE (c: Control) Restore (f: Views.Frame; l, t, r, b: INTEGER); BEGIN Paint(c, f) END Restore; PROCEDURE (c: Control) HandleCtrlMsg2 (f: Views.Frame; VAR msg: Controllers.Message; VAR focus: Views.View); BEGIN IF ~c.disabled & ~c.readOnly & c.item.Valid() THEN WITH msg: Controllers.PollCursorMsg DO msg.cursor := Ports.graphicsCursor | msg: Controllers.TrackMsg DO Track(c, f, msg) | msg: Controllers.EditMsg DO Edit(c, f, msg) ELSE END END END HandleCtrlMsg2; PROCEDURE (c: Control) HandlePropMsg2 (VAR msg: Properties.Message); BEGIN WITH msg: Properties.FocusPref DO IF ~c.disabled & ~c.readOnly THEN msg.setFocus := TRUE END | msg: Properties.SizePref DO msg.w := 10 * Ports.mm; msg.h := 50 * Ports.mm ELSE END END HandlePropMsg2; PROCEDURE (c: Control) CheckLink (VAR ok: BOOLEAN); BEGIN IF c.item.typ # Meta.intTyp THEN ok := FALSE END END CheckLink; PROCEDURE (c: Control) Update (f: Views.Frame; op, from, to: INTEGER); BEGIN Paint(c, f) END Update; PROCEDURE New* (p: Controls.Prop): Views.View; VAR c: Control; BEGIN NEW(c); Controls.OpenLink(c, p); RETURN c END New; PROCEDURE Deposit*; VAR p: Controls.Prop; BEGIN NEW(p); p.link := ""; p.label := ""; p.guard := ""; p.notifier := ""; Views.Deposit(New(p)) END Deposit; PROCEDURE Guard* (VAR par: Dialog.Par); BEGIN par.disabled := (x < 0) OR (x > 100) END Guard; END ObxCtrls.
Obx/Mod/Ctrls.odc
MODULE ObxCubes; (** project = "BlackBox" organization = "www.oberon.ch" contributors = "Oberon microsystems" version = "System/Rsrc/About" references = "Adopted from a program written in C in 1986 by Roland Karlsson, Swedish Institute for Computer Science (SICS), [email protected]" changes = " - YYYYMMDD, nn, ... " issues = " - ... " **) IMPORT Views, Ports, Properties, Services, Stores, Models, Math, Controllers, StdCmds, Containers, Dialog; CONST minVersion = 0; maxVersion = 1; pi2 = 255; invisible = Ports.white; TYPE Colors = ARRAY 6 OF Ports.Color; View = POINTER TO RECORD (Views.View) fi1, fi2: INTEGER; (* rotation angles *) colors: Colors (* colors of the six sides of the cube *) END; Action = POINTER TO RECORD (Services.Action) END; Msg = RECORD (Models.Message) consumed: BOOLEAN END; VAR para*: RECORD colors*: Colors END; action: Action; actionIsAlive: BOOLEAN; actual: View; sinus: ARRAY 256 OF INTEGER; (* property dialog *) PROCEDURE Singleton (): View; VAR v: Views.View; BEGIN Controllers.SetCurrentPath(Controllers.targetPath); v := Containers.FocusSingleton(); Controllers.ResetCurrentPath(); IF (v # NIL) & (v IS View) THEN RETURN v(View) ELSE RETURN NIL END END Singleton; PROCEDURE Notify* (op, from, to: INTEGER); VAR v: View; BEGIN v := Singleton(); IF v # NIL THEN v.colors := para.colors END END Notify; (* Action *) PROCEDURE (a: Action) Do; VAR msg: Msg; v: View; BEGIN msg.consumed := FALSE; Views.Omnicast(msg); IF msg.consumed THEN (* update Color Property Editor *) v := Singleton(); IF (v # NIL) & (actual # v) THEN para.colors := v.colors; Dialog.Update(para); actual := v END; Services.DoLater(a, Services.Ticks() + Services.resolution DIV 10) (* i.e. perform a full rotation through all 256 states in 25.6 seconds *) ELSE actionIsAlive := FALSE END END Do; (* View *) PROCEDURE (v: View) Externalize (VAR wr: Stores.Writer); VAR i: INTEGER; BEGIN wr.WriteVersion(maxVersion); wr.WriteInt(v.fi1); wr.WriteInt(v.fi2); FOR i := 0 TO 5 DO wr.WriteInt(v.colors[i]) END END Externalize; PROCEDURE (v: View) Internalize (VAR rd: Stores.Reader); VAR version: INTEGER; i: INTEGER; BEGIN rd.ReadVersion(minVersion, maxVersion, version); IF ~rd.cancelled THEN rd.ReadInt(v.fi1); rd.ReadInt(v.fi2); IF version = maxVersion THEN FOR i := 0 TO 5 DO rd.ReadInt(v.colors[i]) END ELSE FOR i := 0 TO 5 DO v.colors[i] := invisible END END END END Internalize; PROCEDURE (v: View) CopyFromSimpleView (source: Views.View); BEGIN WITH source: View DO v.fi1 := source.fi1; v.fi2 := source.fi2; v.colors := source.colors END END CopyFromSimpleView; PROCEDURE (v: View) HandlePropMsg (VAR msg: Properties.Message); BEGIN WITH msg: Properties.SizePref DO IF (msg.w > Views.undefined) & (msg.h > Views.undefined) THEN Properties.ProportionalConstraint(1, 1, msg.fixedW, msg.fixedH, msg.w, msg.h); IF msg.w < 10 * Ports.mm THEN msg.w := 10 * Ports.mm; msg.h := msg.w END ELSE msg.w := 40*Ports.mm; msg.h := msg.w; END | msg: Properties.FocusPref DO msg.hotFocus := TRUE ELSE END END HandlePropMsg; PROCEDURE (v: View) HandleCtrlMsg (f: Views.Frame; VAR msg: Controllers.Message; VAR focus: Views.View); VAR c: Containers.Controller; BEGIN WITH msg: Controllers.TrackMsg DO IF Controllers.modify IN msg.modifiers THEN c := Containers.Focus(); IF c.opts # Containers.mask THEN para.colors := v.colors; StdCmds.OpenToolDialog('Obx/Rsrc/Cubes', 'Cube Colors'); c.SetSingleton(v) END END ELSE END END HandleCtrlMsg; PROCEDURE (v: View) HandleModelMsg (VAR msg: Models.Message); BEGIN WITH msg: Msg DO v.fi1 := (v.fi1 + 7) MOD pi2; v.fi2 := (v.fi2 + 1) MOD pi2; msg.consumed := TRUE; Views.Update(v, Views.keepFrames) ELSE END END HandleModelMsg; PROCEDURE (v: View) Restore (f: Views.Frame; l, t, r, b: INTEGER); VAR fi1, fi2, a, c: INTEGER; p0h, p0v, p1h, p1v, p2h, p2v, p3h, p3v: INTEGER; w, h: INTEGER; e01, e12, e23, e30, e45, e56, e67, e74, e04, e15, e26, e37: BOOLEAN; p: ARRAY 4 OF Ports.Point; PROCEDURE DrawSides(visible: BOOLEAN); BEGIN IF (e01 & e12 & e23 & e30 = visible) & (v.colors[0] # invisible) THEN p[0].x := (p0h - c) * w; p[0].y := p0v * w; p[1].x := (p1h - c) * w; p[1].y := p1v * w; p[2].x := (p2h - c) * w; p[2].y := p2v * w; p[3].x := (p3h - c) * w; p[3].y := p3v * w; f.DrawPath(p, 4, Ports.fill, v.colors[0], Ports.closedPoly) END; IF (e45 & e56 & e67 & e74 = visible) & (v.colors[1] # invisible) THEN p[0].x := (p0h + c) * w; p[0].y := p0v * w; p[1].x := (p1h + c) * w; p[1].y := p1v * w; p[2].x := (p2h + c) * w; p[2].y := p2v * w; p[3].x := (p3h + c) * w; p[3].y := p3v * w; f.DrawPath(p, 4, Ports.fill, v.colors[1], Ports.closedPoly) END; IF (e01 & e15 & e45 & e04 = visible) & (v.colors[2] # invisible) THEN p[0].x := (p0h - c) * w; p[0].y := p0v * w; p[1].x := (p1h - c) * w; p[1].y := p1v * w; p[2].x := (p1h + c) * w; p[2].y := p1v * w; p[3].x := (p0h + c) * w; p[3].y := p0v * w; f.DrawPath(p, 4, Ports.fill, v.colors[2], Ports.closedPoly) END; IF (e12 & e26 & e56 & e15 = visible) & (v.colors[3] # invisible) THEN p[0].x := (p1h - c) * w; p[0].y := p1v * w; p[1].x := (p2h - c) * w; p[1].y := p2v * w; p[2].x := (p2h + c) * w; p[2].y := p2v * w; p[3].x := (p1h + c) * w; p[3].y := p1v * w; f.DrawPath(p, 4, Ports.fill, v.colors[3], Ports.closedPoly) END; IF (e23 & e37 & e67 & e26 = visible) & (v.colors[4] # invisible) THEN p[0].x := (p2h - c) * w; p[0].y := p2v * w; p[1].x := (p3h - c) * w; p[1].y := p3v * w; p[2].x := (p3h + c) * w; p[2].y := p3v * w; p[3].x := (p2h + c) * w; p[3].y := p2v * w; f.DrawPath(p, 4, Ports.fill, v.colors[4], Ports.closedPoly) END; IF (e30 & e04 & e74 & e37 = visible) & (v.colors[5] # invisible) THEN p[0].x := (p3h - c) * w; p[0].y := p3v * w; p[1].x := (p0h - c) * w; p[1].y := p0v * w; p[2].x := (p0h + c) * w; p[2].y := p0v * w; p[3].x := (p3h + c) * w; p[3].y := p3v * w; f.DrawPath(p, 4, Ports.fill, v.colors[5], Ports.closedPoly) END; IF e01 = visible THEN f.DrawLine((p0h - c) * w, p0v * w, (p1h - c) * w, p1v * w, 0, Ports.black) END; IF e12 = visible THEN f.DrawLine((p1h - c) * w, p1v * w, (p2h - c) * w, p2v * w, 0, Ports.black) END; IF e23 = visible THEN f.DrawLine((p2h - c) * w, p2v * w, (p3h - c) * w, p3v * w, 0, Ports.black) END; IF e30 = visible THEN f.DrawLine((p3h - c) * w, p3v * w, (p0h - c) * w, p0v * w, 0, Ports.black) END; IF e45 = visible THEN f.DrawLine((p0h + c) * w, p0v * w, (p1h + c) * w, p1v * w, 0, Ports.black) END; IF e56 = visible THEN f.DrawLine((p1h + c) * w, p1v * w, (p2h + c) * w, p2v * w, 0, Ports.black) END; IF e67 = visible THEN f.DrawLine((p2h + c) * w, p2v * w, (p3h + c) * w, p3v * w, 0, Ports.black) END; IF e74 = visible THEN f.DrawLine((p3h + c) * w, p3v * w, (p0h + c) * w, p0v * w, 0, Ports.black) END; IF e04 = visible THEN f.DrawLine((p0h + c) * w, p0v * w, (p0h - c) * w, p0v * w, 0, Ports.black) END; IF e15 = visible THEN f.DrawLine((p1h + c) * w, p1v * w, (p1h - c) * w, p1v * w, 0, Ports.black) END; IF e26 = visible THEN f.DrawLine((p2h + c) * w, p2v * w, (p2h - c) * w, p2v * w, 0, Ports.black) END; IF e37 = visible THEN f.DrawLine((p3h + c) * w, p3v * w, (p3h - c) * w, p3v * w, 0, Ports.black) END END DrawSides; BEGIN IF ~actionIsAlive THEN actionIsAlive := TRUE; Services.DoLater(action, Services.now) END; v.context.GetSize(w, h); w := (w DIV 170); fi1 := v.fi1; fi2 := v.fi2; a := sinus[fi2]; c := (sinus[(64 - fi2) MOD pi2] * 91) DIV 128; (* 91/128 := sqrt(2) *) p0v := 85 + sinus[fi1]; p0h := 85 + (a * sinus[(64 - fi1) MOD pi2]) DIV 64; p1v := 85 + sinus[(64 + fi1) MOD pi2]; p1h := 85 + (a * sinus[(-fi1) MOD pi2]) DIV 64; p2v := 85 + sinus[(128 + fi1) MOD pi2]; p2h := 85 + (a * sinus[(-64 - fi1) MOD pi2]) DIV 64; p3v := 85 + sinus[(192 + fi1) MOD pi2]; p3h := 85 + (a * sinus[(-128 - fi1) MOD pi2]) DIV 64; (* determine visibility of the twelve edges *) e01 := ~((((fi2 - 192) MOD pi2 < 64) & ((fi1 - 32) MOD pi2 < 128)) OR (((fi2 - 128) MOD pi2 < 64) & ((fi1 - 160) MOD pi2 < 128))); e12 := ~((((fi2 - 192) MOD pi2 < 64) & ((fi1 - 224) MOD pi2 < 128)) OR (((fi2 - 128) MOD pi2 < 64) & ((fi1 - 96) MOD pi2 < 128))); e23 := ~((((fi2 - 192) MOD pi2 < 64) & ((fi1 - 160) MOD pi2 < 128)) OR (((fi2 - 128) MOD pi2 < 64) & ((fi1 - 32) MOD pi2 < 128))); e30 := ~((((fi2 - 192) MOD pi2 < 64) & ((fi1 - 96) MOD pi2 < 128)) OR (((fi2 - 128) MOD pi2 < 64) & ((fi1 - 224) MOD pi2 < 128))); e45 := ~((((fi2) MOD pi2 < 64) & ((fi1 - 32) MOD pi2 < 128)) OR (((fi2 - 64) MOD pi2 < 64) & ((fi1 - 160) MOD pi2 < 128))); e56 := ~((((fi2) MOD pi2 < 64) & ((fi1 - 224) MOD pi2 < 128)) OR (((fi2 - 64) MOD pi2 < 64) & ((fi1 - 96) MOD pi2 < 128))); e67 := ~((((fi2) MOD pi2 < 64) & ((fi1 - 160) MOD pi2 < 128)) OR (((fi2 - 64) MOD pi2 < 64) & ((fi1 - 32) MOD pi2 < 128))); e74 := ~((((fi2) MOD pi2 < 64) & ((fi1 - 96) MOD pi2 < 128)) OR (((fi2 - 64) MOD pi2 < 64) & ((fi1 - 224) MOD pi2 < 128))); e04 := ~((((fi2 - 64) MOD pi2 < 128) & ((fi1 - 224) MOD pi2 < 64)) OR (((fi2 - 192) MOD pi2 < 128) & ((fi1 - 96) MOD pi2 < 64))); e15 := ~((((fi2 - 64) MOD pi2 < 128) & ((fi1 - 160) MOD pi2 < 64)) OR (((fi2 - 192) MOD pi2 < 128) & ((fi1 - 32) MOD pi2 < 64))); e26 := ~((((fi2 - 64) MOD pi2 < 128) & ((fi1 - 96) MOD pi2 < 64)) OR (((fi2 - 192) MOD pi2 < 128) & ((fi1 - 224) MOD pi2 < 64))); e37 := ~((((fi2 - 64) MOD pi2 < 128) & ((fi1 - 32) MOD pi2 < 64)) OR (((fi2 - 192) MOD pi2 < 128) & ((fi1 - 160) MOD pi2 < 64))); DrawSides(FALSE); (* draw hidden sides and edges *) DrawSides(TRUE) (* draw visible sides and edges *) END Restore; (* commands *) PROCEDURE New* (): View; VAR v: View; BEGIN NEW(v); v.fi1 := 0; v.fi2 := 0; v.colors := para.colors; RETURN v END New; PROCEDURE Deposit*; BEGIN Views.Deposit(New()) END Deposit; PROCEDURE InitData; VAR i: INTEGER; BEGIN (* Pi = 128 *) FOR i := 0 TO 255 DO sinus[i] := SHORT(ENTIER(0.5 + 64 * Math.Sin(i * 2 * Math.Pi() / 256))) END; para.colors[0] := Ports.green; para.colors[1] := Ports.blue; para.colors[2] := invisible; para.colors[3] := Ports.red; para.colors[4] := invisible; para.colors[5] := Ports.red + Ports.green (* yellow *) END InitData; BEGIN InitData; NEW(action); actionIsAlive := FALSE CLOSE IF actionIsAlive THEN Services.RemoveAction(action) END END ObxCubes.
Obx/Mod/Cubes.odc
MODULE ObxDb; (** project = "BlackBox" organization = "www.oberon.ch" contributors = "Oberon microsystems" version = "System/Rsrc/About" copyright = "System/Rsrc/About" license = "Docu/BB-License" changes = " - YYYYMMDD, nn, ... " issues = " - ... " **) IMPORT Views, TextModels, TextMappers, TextViews, TextControllers; CONST int = TextMappers.int; string = TextMappers.string; real = TextMappers.real; invalid = TextMappers.invalid; TYPE Node = POINTER TO RECORD next: Node; id: INTEGER; name: TextMappers.String; value: REAL END; VAR list: Node; PROCEDURE Enter (id: INTEGER; name: TextMappers.String; value: REAL); VAR n, h, p: Node; BEGIN (* insert a new tuple into the list at its correct position *) NEW(n); n.id := id; n.name := name; n.value := value; h := list; p := NIL; WHILE (h # NIL) & (h.id <= id) DO p := h; h := h.next END; IF p # NIL THEN (* insert between p and h *) p.next := n ELSE (* insert at beginning *) list := n END; n.next := h END Enter; PROCEDURE EnterData*; VAR c: TextControllers.Controller; beg, end: INTEGER; s: TextMappers.Scanner; id: INTEGER; name: TextMappers.String; value: REAL; BEGIN (* read a text selection and split it into an integer, string, and real field *) c := TextControllers.Focus(); IF (c # NIL) & c.HasSelection() THEN c.GetSelection(beg, end); s.ConnectTo(c.text); s.SetPos(beg); s.Scan; WHILE (s.type = TextMappers.int) & (s.Pos() <= end) DO IF s.type = int THEN id := s.int; s.Scan ELSE s.type := TextMappers.invalid END; IF s.type = string THEN name := s.string; s.Scan ELSE s.type := invalid END; IF s.type = real THEN value := SHORT(s.real); s.Scan ELSE s.type := invalid END; Enter(id, name, value) (* enter the new tuple into a global list *) END; c.SelectAll(FALSE) END END EnterData; PROCEDURE ListData*; VAR t: TextModels.Model; n: Node; f: TextMappers.Formatter; BEGIN (* write all entered tuples into a new text *) t := TextModels.dir.New(); f.ConnectTo(t); f.SetPos(0); n := list; WHILE n # NIL DO f.WriteInt(n.id); f.WriteTab; f.WriteString(n.name); f.WriteTab; (* WriteRealForm allows to format real numbers in a flexible way, here rounding to two digits after the comma *) f.WriteRealForm(n.value, 7, 0, -2, TextModels.digitspace); (* "-2" indicates 2 digits after comma *) f.WriteLn; n := n.next END; Views.OpenView(TextViews.dir.New(t)) END ListData; PROCEDURE Reset*; BEGIN (* release data structure so that garbage collector can reclaim memory *) list := NIL END Reset; END ObxDb.
Obx/Mod/Db.odc
MODULE ObxDialog; (** project = "BlackBox" organization = "www.oberon.ch" contributors = "Oberon microsystems" version = "System/Rsrc/About" copyright = "System/Rsrc/About" license = "Docu/BB-License" changes = " - 20150415, center #38, report passing receiver parameter IN to VAR " issues = " - ... " **) IMPORT Dialog; VAR dialog*: RECORD list*: Dialog.List; combo*: Dialog.Combo; sum-: INTEGER; disable*: BOOLEAN; elems*: INTEGER END; sel*: Dialog.Selection; (* hadled separately to avoid race condition in notifier *) PROCEDURE SetList (VAR l: Dialog.List; n: INTEGER); VAR i: INTEGER; BEGIN l.SetLen(n); i := 0; WHILE i # n DO CASE i OF | 0: l.SetItem(i, "zero") | 1: l.SetItem(i, "one") | 2: l.SetItem(i, "two") | 3: l.SetItem(i, "three") | 4: l.SetItem(i, "four") | 5: l.SetItem(i, "five") | 6: l.SetItem(i, "six") | 7: l.SetItem(i, "seven") | 8: l.SetItem(i, "eight") | 9: l.SetItem(i, "nine") | 10: l.SetItem(i, "ten") | 11: l.SetItem(i, "eleven") END; INC(i) END END SetList; PROCEDURE SelNotifier* (op, from, to: INTEGER); BEGIN IF op = Dialog.set THEN (* recalculate sum of selected numbers *) dialog.sum := (to - from + 1) * (to + from) DIV 2 ELSIF op = Dialog.excluded THEN (* correct sum after deselection of some numbers *) WHILE from <= to DO DEC(dialog.sum, from); INC(from) END ELSIF op = Dialog.included THEN (* correct sum after selection of some numbers *) WHILE from <= to DO INC(dialog.sum, from); INC(from) END END; Dialog.Update(dialog) (* show new dialog.sum *) END SelNotifier; PROCEDURE ElemsNotifier* (op, from, to: INTEGER); BEGIN IF op = Dialog.changed THEN IF dialog.elems < 0 THEN dialog.elems := 0; Dialog.Update(dialog) ELSIF dialog.elems > 12 THEN dialog.elems := 12; Dialog.Update(dialog) END; SetList(dialog.list, dialog.elems); (* rebuild list *) Dialog.UpdateList(dialog.list) (* update list *) END END ElemsNotifier; PROCEDURE ListGuard* (VAR par: Dialog.Par); BEGIN par.disabled := dialog.disable END ListGuard; BEGIN dialog.elems := 2; SetList(dialog.list, dialog.elems); sel.SetLen(12); sel.SetItem(0, "zero"); sel.SetItem(1, "one"); sel.SetItem(2, "two"); sel.SetItem(3, "three"); sel.SetItem(4, "four"); sel.SetItem(5, "five"); sel.SetItem(6, "six"); sel.SetItem(7, "seven"); sel.SetItem(8, "eight"); sel.SetItem(9, "nine"); sel.SetItem(10, "ten"); sel.SetItem(11, "eleven"); dialog.combo.SetLen(12); dialog.combo.SetItem(0, "zero"); dialog.combo.SetItem(1, "one"); dialog.combo.SetItem(2, "two"); dialog.combo.SetItem(3, "three"); dialog.combo.SetItem(4, "four"); dialog.combo.SetItem(5, "five"); dialog.combo.SetItem(6, "six"); dialog.combo.SetItem(7, "seven"); dialog.combo.SetItem(8, "eight"); dialog.combo.SetItem(9, "nine"); dialog.combo.SetItem(10, "ten"); dialog.combo.SetItem(11, "eleven") END ObxDialog.
Obx/Mod/Dialog.odc
MODULE ObxFact; (** project = "BlackBox" organization = "www.oberon.ch" contributors = "Oberon microsystems" version = "System/Rsrc/About" copyright = "System/Rsrc/About" license = "Docu/BB-License" changes = " - YYYYMMDD, nn, ... " issues = " - ... " **) IMPORT Stores, Models, TextModels, TextControllers, Integers; PROCEDURE Read(r: TextModels.Reader; VAR x: Integers.Integer); VAR i, len, beg: INTEGER; ch: CHAR; buf: POINTER TO ARRAY OF CHAR; BEGIN r.ReadChar(ch); WHILE ~r.eot & (ch <= " ") DO r.ReadChar(ch) END; ASSERT(~r.eot & (((ch >= "0") & (ch <= "9")) OR (ch = "-"))); beg := r.Pos() - 1; len := 0; REPEAT INC(len); r.ReadChar(ch) UNTIL r.eot OR (ch < "0") OR (ch > "9"); NEW(buf, len + 1); i := 0; r.SetPos(beg); REPEAT r.ReadChar(buf[i]); INC(i) UNTIL i = len; buf[i] := 0X; Integers.ConvertFromString(buf^, x) END Read; PROCEDURE Write(w: TextModels.Writer; x: Integers.Integer); VAR i: INTEGER; BEGIN IF Integers.Sign(x) < 0 THEN w.WriteChar("-") END; i := Integers.Digits10Of(x); IF i # 0 THEN REPEAT DEC(i); w.WriteChar(Integers.ThisDigit10(x, i)) UNTIL i = 0 ELSE w.WriteChar("0") END END Write; PROCEDURE Compute*; VAR beg, end, i, n: INTEGER; ch: CHAR; s: Stores.Operation; r: TextModels.Reader; w: TextModels.Writer; attr: TextModels.Attributes; c: TextControllers.Controller; x: Integers.Integer; BEGIN c := TextControllers.Focus(); IF (c # NIL) & c.HasSelection() THEN c.GetSelection(beg, end); r := c.text.NewReader(NIL); r.SetPos(beg); r.ReadChar(ch); WHILE ~r.eot & (beg < end) & (ch <= " ") DO r.ReadChar(ch); INC(beg) END; IF ~r.eot & (beg < end) THEN r.ReadPrev; Read(r, x); end := r.Pos(); r.ReadPrev; attr :=r.attr; IF (Integers.Sign(x) > 0) & (Integers.Compare(x, Integers.Long(MAX(LONGINT))) <= 0) THEN n := SHORT(Integers.Short(x)); i := 2; x := Integers.Long(1); WHILE i <= n DO x := Integers.Product(x, Integers.Long(i)); INC(i) END; Models.BeginScript(c.text, "computation", s); c.text.Delete(beg, end); w := c.text.NewWriter(NIL); w.SetPos(beg); w.SetAttr(attr); Write(w, x); Models.EndScript(c.text, s) END END END END Compute; END ObxFact. Menu entry: "Compute Factorial" "" "ObxFact.Compute" "TextCmds.SelectionGuard"
Obx/Mod/Fact.odc
MODULE ObxFileTree; (** project = "BlackBox" organization = "www.oberon.ch" contributors = "Oberon microsystems" version = "System/Rsrc/About" copyright = "System/Rsrc/About" license = "Docu/BB-License" changes = " - 20161216, center #144, inconsistent docu and usage of Files.Locator error codes " issues = " - ... " **) IMPORT Files, Converters, Views, Dialog; TYPE Dlg* = RECORD path*, currentPath: Dialog.String; tree*: Dialog.Tree END; VAR dlg*: Dlg; PROCEDURE BuildDirTree (loc: Files.Locator; parent: Dialog.TreeNode); VAR l: Files.LocInfo; f: Files.FileInfo; n: Dialog.TreeNode; BEGIN l := Files.dir.LocList(loc); WHILE l # NIL DO (* Recursively add directories *) n := dlg.tree.NewChild(parent, 0, l.name$); n.ViewAsFolder(TRUE); BuildDirTree(loc.This(l.name$), n); l := l.next END; f := Files.dir.FileList(loc); WHILE f # NIL DO n := dlg.tree.NewChild(parent, 0, f.name$); f := f.next END END BuildDirTree; PROCEDURE ThisLocator (IN path: ARRAY OF CHAR): Files.Locator; VAR i, j: INTEGER; ch: CHAR; loc: Files.Locator; dir: Dialog.String; BEGIN loc := Files.dir.This(""); i := 0; ch := path[0]; WHILE ch # 0X DO j := 0; WHILE (ch # 0X) & (ch # "/") DO dir[j] := ch; INC(j); INC(i); ch := path[i] END; dir[j] := 0X; loc := loc.This(dir); IF ch = "/" THEN INC(i); ch := path[i] END END; RETURN loc END ThisLocator; PROCEDURE Update*; VAR loc: Files.Locator; BEGIN IF (dlg.path # "") & (dlg.path[LEN(dlg.path$) - 1] # "/") & (dlg.path[LEN(dlg.path$) - 1] # "\") THEN dlg.path := dlg.path + "/" END; dlg.currentPath := dlg.path$; dlg.tree.DeleteAll(); loc := ThisLocator(dlg.path); IF loc.res = 0 THEN BuildDirTree(loc, NIL); Dialog.UpdateList(dlg.tree) END; Dialog.Update(dlg) END Update; PROCEDURE Open*; VAR n: Dialog.TreeNode; name, path, p: Dialog.String; loc: Files.Locator; fname: Files.Name; conv: Converters.Converter; v: Views.View; BEGIN n := dlg.tree.Selected(); IF n # NIL THEN IF ~n.IsFolder() THEN (* a leaf node is selected *) n.GetName(name); n := dlg.tree.Parent(n); path := ""; WHILE n # NIL DO n.GetName(p); path := p + "/" + path; n := dlg.tree.Parent(n) END; loc := ThisLocator(dlg.currentPath + path); IF loc.res = 0 THEN conv := NIL; fname := name$; v := Views.Old(Views.dontAsk, loc, fname, conv); IF v # NIL THEN Views.Open(v, loc, fname, conv) END ELSE Dialog.ShowStatus("file not found") END ELSIF ~n.IsExpanded() THEN n.SetExpansion(TRUE); Dialog.UpdateList(dlg.tree) END ELSE Dialog.ShowStatus("no selection") END END Open; PROCEDURE OpenGuard* (VAR par: Dialog.Par); VAR n: Dialog.TreeNode; BEGIN n := dlg.tree.Selected(); par.disabled := (n = NIL) OR (n.IsFolder() & n.IsExpanded()); IF (n # NIL) & ~n.IsFolder() THEN par.label := "&Open File" ELSE par.label := "&Open Folder" END END OpenGuard; END ObxFileTree.
Obx/Mod/FileTree.odc
MODULE ObxFldCtrls; (** project = "BlackBox" organization = "www.oberon.ch" contributors = "Oberon microsystems" version = "System/Rsrc/About" copyright = "System/Rsrc/About" license = "Docu/BB-License" changes = " - YYYYMMDD, nn, ... " issues = " - ... " **) IMPORT Strings, Meta, Dialog, Stores, Views, Controllers, Properties, Controls, StdCFrames; CONST minVersion = 0; maxVersion = 0; rdel = 07X; ldel = 08X; tab = 09X; ltab = 0AX; lineChar = 0DX; esc = 01BX; arrowLeft = 1CX; arrowRight = 1DX; arrowUp = 1EX; arrowDown = 1FX; maxLen = 13; TYPE Vector* = RECORD x*, y*: INTEGER END; VectorField = POINTER TO RECORD (Controls.Control) selection: INTEGER (* 0: no selection; 1: first part selected; 2: selection or caret in second part *) END; VAR test*: Vector; PROCEDURE GetVectorField (f: StdCFrames.Field; OUT str: ARRAY OF CHAR); VAR c: VectorField; v: Meta.Item; x, y: INTEGER; s1, s2: ARRAY 16 OF CHAR; BEGIN c := f.view(VectorField); IF c.item.Valid() THEN c.item.Lookup("x", v); x := v.IntVal(); c.item.Lookup("y", v); y := v.IntVal() ELSE x := 0; y := 0 END; s1[0] := CHR(x DIV 10 MOD 10 + ORD("0")); s1[1] := CHR(x MOD 10 + ORD("0")); s1[2] := 0X; IF y < 0 THEN y := 0 END; Strings.IntToString(y, s2); str := s1 + "/" + s2 END GetVectorField; PROCEDURE SetVectorField(f: StdCFrames.Field; IN str: ARRAY OF CHAR); VAR c: VectorField; v: Meta.Item; x, y, res: INTEGER; s: ARRAY 16 OF CHAR; BEGIN c := f.view(VectorField); x := (ORD(str[0]) - ORD("0")) * 10 + (ORD(str[1]) - ORD("0")); s := str$; s[0] := " "; s[1] := " "; s[2] := " "; Strings.StringToInt(s, y, res); IF (res = 0) & c.item.Valid() & ~c.readOnly THEN c.item.Lookup("x", v); v.PutIntVal(x); c.item.Lookup("y", v); v.PutIntVal(y); Controls.Notify(c, f, Dialog.changed, 0, 0) END END SetVectorField; PROCEDURE EqualVectorField (f: StdCFrames.Field; IN s1, s2: ARRAY OF CHAR): BOOLEAN; BEGIN RETURN s1 = s2 END EqualVectorField; PROCEDURE (c: VectorField) CopyFromSimpleView2 (source: Controls.Control); BEGIN c.selection := 0 END CopyFromSimpleView2; PROCEDURE (c: VectorField) Internalize2 (VAR rd: Stores.Reader); VAR version: INTEGER; BEGIN rd.ReadVersion(minVersion, maxVersion, version); c.selection := 0 END Internalize2; PROCEDURE (c: VectorField) Externalize2 (VAR wr: Stores.Writer); BEGIN wr.WriteVersion(maxVersion) END Externalize2; PROCEDURE (c: VectorField) GetNewFrame (VAR frame: Views.Frame); VAR f: StdCFrames.Field; BEGIN f := StdCFrames.dir.NewField(); f.disabled := c.disabled; f.undef := c.undef; f.readOnly := c.readOnly; f.font := c.font; f.maxLen := maxLen; f.left := c.prop.opt[Controls.left]; f.right := c.prop.opt[Controls.right]; f.Get := GetVectorField; f.Set := SetVectorField; f.Equal := EqualVectorField; frame := f END GetNewFrame; PROCEDURE (c: VectorField) Restore (f: Views.Frame; l, t, r, b: INTEGER); BEGIN WITH f: StdCFrames.Frame DO f.Restore(l, t, r, b) END END Restore; PROCEDURE (c: VectorField) HandleCtrlMsg2 (f: Views.Frame; VAR msg: Controllers.Message; VAR focus: Views.View); VAR ch: CHAR; a, b, x, x0: INTEGER; v: Meta.Item; BEGIN IF ~c.disabled & ~c.readOnly THEN WITH f: StdCFrames.Field DO WITH msg: Controllers.PollOpsMsg DO msg.valid := {Controllers.copy} | msg: Controllers.EditMsg DO IF msg.op = Controllers.pasteChar THEN ch := msg.char; IF c.selection = 2 THEN IF ch = arrowLeft THEN c.selection := 1; f.Select(0, 2) ELSIF (ch = ldel) OR (ch = rdel) OR (ch = arrowRight) OR ("0" <= ch) & (ch <= "9") THEN f.KeyDown(ch, msg.modifiers); f.Update ELSE Dialog.Beep END ELSIF c.item.Valid() THEN c.item.Lookup("x", v); x := v.IntVal(); x0 := x; IF ch = arrowRight THEN c.selection := 2; f.Select(3, MAX(INTEGER)) ELSIF ch = arrowUp THEN x := (x + 1) MOD 100 ELSIF ch = arrowDown THEN x := (x - 1) MOD 100 ELSIF ("0" <= ch) & (ch <= "9") THEN x := x * 10 MOD 100 + ORD(ch) - ORD("0") ELSE Dialog.Beep END; IF x # x0 THEN v.PutIntVal(x); Controls.Notify(c, f, Dialog.changed, 0, 0); f.Update; f.Select(0, 2) END END ELSE f.Edit(msg.op, msg.view, msg.w, msg.h, msg.isSingle, msg.clipboard) END | msg: Controllers.PollCursorMsg DO f.GetCursor(msg.x, msg.y, msg.modifiers, msg.cursor) | msg: Controllers.TrackMsg DO f.MouseDown(msg.x, msg.y, msg.modifiers); f.GetSelection(a, b); IF a >= 3 THEN c.selection := 2 ELSIF a >= 0 THEN c.selection := 1; f.Select(0, 2) END | msg: Controllers.MarkMsg DO f.Mark(msg.show, msg.focus); IF msg.focus THEN IF msg.show THEN (* set selection on focus *) c.selection := 1; f.Select(0, 2) ELSE (* remove selection on defocus *) c.selection := 0; f.Select(-1, -1) END END ELSE END END END END HandleCtrlMsg2; PROCEDURE (c: VectorField) HandlePropMsg2 (VAR msg: Properties.Message); BEGIN WITH msg: Properties.FocusPref DO IF ~c.disabled & ~c.readOnly THEN msg.setFocus := TRUE END | msg: Properties.SizePref DO StdCFrames.dir.GetFieldSize(maxLen, msg.w, msg.h) | msg: Controls.PropPref DO msg.valid := msg.valid + {Controls.left, Controls.right} (* to enable the property editor to correctly label these options, insert the following three lines into Dev/Rsrc/Strings (no leading tab characters, however!): ObxFldCtrls.VectorField Vector Field ObxFldCtrls.VectorField.Opt0 Left aligned ObxFldCtrls.VectorField.Opt1 Right aligned *) (* to handle font and color properties: handle type Properties.StdProp also *) ELSE END END HandlePropMsg2; PROCEDURE (c: VectorField) CheckLink (VAR ok: BOOLEAN); VAR mod, name: Meta.Name; BEGIN IF (c.item.typ = Meta.recTyp) THEN c.item.GetTypeName(mod, name); ok := (mod = "ObxFldCtrls") & (name = "Vector") ELSE ok := FALSE END END CheckLink; PROCEDURE (c: VectorField) Update (f: Views.Frame; op, from, to: INTEGER); BEGIN f(StdCFrames.Frame).Update; IF f.front & ~c.disabled THEN IF c.selection = 1 THEN f(StdCFrames.Field).Select(0, 1) ELSIF c.selection = 2 THEN f(StdCFrames.Field).Select(2, MAX(INTEGER)) END END END Update; PROCEDURE New* (p: Controls.Prop): Views.View; VAR c: VectorField; BEGIN NEW(c); Controls.OpenLink(c, p); RETURN c END New; PROCEDURE Deposit*; VAR p: Controls.Prop; BEGIN NEW(p); p.link := "ObxFldCtrls.test"; p.label := ""; p.guard := ""; p.notifier := ""; p.opt[Controls.left] := TRUE; Views.Deposit(New(p)) END Deposit; END ObxFldCtrls. "ObxFldCtrls.Deposit; StdCmds.PasteView"
Obx/Mod/FldCtrls.odc
MODULE ObxGraphs; (** project = "BlackBox" organization = "www.oberon.ch" contributors = "Oberon microsystems" version = "System/Rsrc/About" copyright = "System/Rsrc/About" license = "Docu/BB-License" changes = " - YYYYMMDD, nn, ... " issues = " - ... " **) IMPORT Services, Stores, Ports, Models, Views, Controllers, Properties, TextModels, TextViews, TextMappers; CONST minVersion = 0; maxVersion = 0; TYPE Value = POINTER TO RECORD next: Value; val: INTEGER END; Model = POINTER TO RECORD (Models.Model) values: Value END; View = POINTER TO RECORD (Views.View) model: Model END; ModelOp = POINTER TO RECORD (Stores.Operation) model: Model; values: Value END; PROCEDURE (op: ModelOp) Do; VAR v: Value; msg: Models.UpdateMsg; BEGIN v := op.model.values; op.model.values := op.values; op.values := v; (* swap *) Models.Broadcast(op.model, msg) END Do; PROCEDURE (m: Model) Internalize (VAR rd: Stores.Reader); VAR version: INTEGER; n: INTEGER; v, last: Value; BEGIN rd.ReadVersion(minVersion, maxVersion, version); IF ~rd.cancelled THEN last := NIL; rd.ReadInt(n); (* read number of values *) WHILE n # 0 DO NEW(v); rd.ReadInt(v.val); IF last = NIL THEN m.values := v ELSE last.next := v END; (* append value *) last := v; DEC(n) END END END Internalize; PROCEDURE (m: Model) Externalize (VAR wr: Stores.Writer); VAR v: Value; n: INTEGER; BEGIN wr.WriteVersion(maxVersion); v := m.values; n := 0; WHILE v # NIL DO INC(n); v := v.next END; wr.WriteInt(n); (* write number of values *) v := m.values; WHILE v # NIL DO wr.WriteInt(v.val); v := v.next END END Externalize; PROCEDURE (m: Model) CopyFrom (source: Stores.Store); BEGIN m.values := source(Model).values (* values are immutable and thus can be shared *) END CopyFrom; PROCEDURE (m: Model) SetValues (v: Value), NEW; VAR op: ModelOp; BEGIN NEW(op); op.model := m; op.values := v; Models.Do(m, "Set Values", op) END SetValues; PROCEDURE OpenData (v: View); VAR t: TextModels.Model; f: TextMappers.Formatter; h: Value; BEGIN t := TextModels.dir.New(); f.ConnectTo(t); h := v.model.values; WHILE h # NIL DO f.WriteInt(h.val); f.WriteLn; h := h.next END; Views.OpenAux(TextViews.dir.New(t), "Values") END OpenData; PROCEDURE DropData (t: TextModels.Model; v: View); VAR s: TextMappers.Scanner; first, last, h: Value; BEGIN s.ConnectTo(t); s.Scan; WHILE s.type = TextMappers.int DO NEW(h); h.val := s.int; IF last = NIL THEN first := h ELSE last.next := h END; last := h; s.Scan END; v.model.SetValues(first) END DropData; PROCEDURE (v: View) Internalize (VAR rd: Stores.Reader); VAR version: INTEGER; st: Stores.Store; BEGIN rd.ReadVersion(minVersion, maxVersion, version); IF ~rd.cancelled THEN rd.ReadStore(st); v.model := st(Model) END END Internalize; PROCEDURE (v: View) CopyFromModelView (source: Views.View; model: Models.Model); BEGIN ASSERT(model IS Model, 20); WITH source: View DO v.model := model(Model) END END CopyFromModelView; PROCEDURE (v: View) Externalize (VAR wr: Stores.Writer); BEGIN wr.WriteVersion(maxVersion); wr.WriteStore(v.model) END Externalize; PROCEDURE (v: View) ThisModel (): Models.Model; BEGIN RETURN v.model END ThisModel; PROCEDURE (v: View) Restore (f: Views.Frame; l, t, r, b: INTEGER); VAR h: Value; n: INTEGER; width, height, d, x: INTEGER; BEGIN h := v.model.values; n := 0; WHILE h # NIL DO INC(n); h := h.next END; (* count values *) IF n > 0 THEN v.context.GetSize(width, height); d := width DIV n; x := 0; h := v.model.values; WHILE h # NIL DO f.DrawRect(x, height - h.val * Ports.mm, x + d, height, Ports.fill, Ports.grey50); h := h.next; INC(x, d) END END END Restore; PROCEDURE (v: View) HandleModelMsg (VAR msg: Models.Message); BEGIN WITH msg: Models.UpdateMsg DO Views.Update(v, Views.keepFrames) ELSE END END HandleModelMsg; PROCEDURE (v: View) HandleCtrlMsg (f: Views.Frame; VAR msg: Views.CtrlMessage; VAR focus: Views.View); VAR x, y, w, h: INTEGER; modifiers: SET; isDown: BOOLEAN; BEGIN WITH msg: Controllers.TrackMsg DO REPEAT f.Input(x, y, modifiers, isDown) UNTIL ~isDown; v.context.GetSize(w, h); IF (x >= 0) & (y >= 0) & (x < w) & (y < h) THEN OpenData(v) END | msg: Controllers.PollDropMsg DO IF Services.Extends(msg.type, "TextViews.View") THEN msg.dest := f (* enable drop target feedback *) END | msg: Controllers.DropMsg DO IF msg.view IS TextViews.View THEN DropData(msg.view(TextViews.View).ThisModel(), v) (* interpret dropped text *) END ELSE END END HandleCtrlMsg; PROCEDURE (v: View) HandlePropMsg (VAR msg: Properties.Message); CONST min = 10 * Ports.mm; max = 160 * Ports.mm; pref = 90 * Ports.mm; BEGIN WITH msg: Properties.SizePref DO (* prevent illegal sizes *) IF msg.w = Views.undefined THEN msg.w := pref ELSIF msg.w < min THEN msg.w := min ELSIF msg.w > max THEN msg.w := max END; IF msg.h = Views.undefined THEN msg.h := pref ELSIF msg.h < min THEN msg.h := min ELSIF msg.h > max THEN msg.h := max END | msg: Properties.FocusPref DO msg.hotFocus := TRUE ELSE END END HandlePropMsg; PROCEDURE Deposit*; VAR m: Model; v: View; BEGIN NEW(m); NEW(v); v.model := m; Stores.Join(v, m); Views.Deposit(v) END Deposit; END ObxGraphs.
Obx/Mod/Graphs.odc
MODULE ObxHello0; (** project = "BlackBox" organization = "www.oberon.ch" contributors = "Oberon microsystems" version = "System/Rsrc/About" copyright = "System/Rsrc/About" license = "Docu/BB-License" changes = " - YYYYMMDD, nn, ... " issues = " - ... " **) IMPORT StdLog; PROCEDURE Do*; BEGIN StdLog.String("Hello World"); StdLog.Ln (* write string and 0DX into log *) END Do; END ObxHello0.
Obx/Mod/Hello0.odc
MODULE ObxHello1; (** project = "BlackBox" organization = "www.oberon.ch" contributors = "Oberon microsystems" version = "System/Rsrc/About" copyright = "System/Rsrc/About" license = "Docu/BB-License" changes = " - YYYYMMDD, nn, ... " issues = " - ... " **) IMPORT Views, TextModels, TextMappers, TextViews; PROCEDURE Do*; VAR t: TextModels.Model; f: TextMappers.Formatter; v: TextViews.View; BEGIN t := TextModels.dir.New(); (* create a new, empty text object *) f.ConnectTo(t); (* connect a formatter to the text *) f.WriteString("Hello World"); f.WriteLn; (* write a string and a 0DX into new text *) v := TextViews.dir.New(t); (* create a new text view for t *) Views.OpenView(v) (* open the view in a window *) END Do; END ObxHello1.
Obx/Mod/Hello1.odc
MODULE ObxLabelLister; (** project = "BlackBox" organization = "www.oberon.ch" contributors = "Oberon microsystems" version = "System/Rsrc/About" copyright = "System/Rsrc/About" license = "Docu/BB-License" changes = " - YYYYMMDD, nn, ... " issues = " - ... " **) IMPORT Views, Controls, FormModels, FormControllers, StdLog; PROCEDURE List*; VAR c: FormControllers.Controller; rd: FormModels.Reader; v: Views.View; BEGIN c := FormControllers.Focus(); IF c # NIL THEN rd := c.form.NewReader(NIL); rd.ReadView(v); WHILE v # NIL DO IF v IS Controls.Control THEN StdLog.String(v(Controls.Control).label); StdLog.Ln END; rd.ReadView(v) END END END List; END ObxLabelLister.
Obx/Mod/LabelLister.odc
MODULE ObxLines; (** project = "BlackBox" organization = "www.oberon.ch" contributors = "Oberon microsystems" version = "System/Rsrc/About" copyright = "System/Rsrc/About" license = "Docu/BB-License" changes = " - YYYYMMDD, nn, ... " issues = " - ... " **) IMPORT Stores, Ports, Models, Views, Controllers, Properties; CONST minVersion = 0; maxVersion = 0; TYPE Line = POINTER TO RECORD next: Line; x0, y0, x1, y1: INTEGER END; Model = POINTER TO RECORD (Models.Model) lines: Line END; View = POINTER TO RECORD (Views.View) color: Ports.Color; model: Model END; UpdateMsg = RECORD (Models.UpdateMsg) l, t, r, b: INTEGER END; LineOp = POINTER TO RECORD (Stores.Operation) model: Model; line: Line END; ColorOp = POINTER TO RECORD (Stores.Operation) view: View; color: Ports.Color END; PROCEDURE GetBox (x0, y0, x1, y1: INTEGER; VAR l, t, r, b: INTEGER); BEGIN IF x0 > x1 THEN l := x1; r := x0 ELSE l := x0; r := x1 END; IF y0 > y1 THEN t := y1; b := y0 ELSE t := y0; b := y1 END; INC(r, Ports.point); INC(b, Ports.point) END GetBox; PROCEDURE (op: LineOp) Do; VAR l: Line; msg: UpdateMsg; BEGIN l := op.line; IF l # op.model.lines THEN (* insert op.line *) ASSERT(l # NIL, 100); ASSERT(l.next = op.model.lines, 101); op.model.lines := l ELSE (* delete op.line *) ASSERT(l = op.model.lines, 102); op.model.lines := l.next END; GetBox(l.x0, l.y0, l.x1, l.y1, msg.l, msg.t, msg.r, msg.b); Models.Broadcast(op.model, msg) END Do; PROCEDURE (m: Model) Internalize (VAR rd: Stores.Reader); VAR version: INTEGER; x0: INTEGER; p: Line; BEGIN rd.ReadVersion(minVersion, maxVersion, version); IF ~rd.cancelled THEN rd.ReadInt(x0); m.lines := NIL; WHILE x0 # MIN(INTEGER) DO NEW(p); p.next := m.lines; m.lines := p; p.x0 := x0; rd.ReadInt(p.y0); rd.ReadInt(p.x1); rd.ReadInt(p.y1); rd.ReadInt(x0) END END END Internalize; PROCEDURE (m: Model) Externalize (VAR wr: Stores.Writer); VAR p: Line; BEGIN wr.WriteVersion(maxVersion); p := m.lines; WHILE p # NIL DO wr.WriteInt(p.x0); wr.WriteInt(p.y0); wr.WriteInt(p.x1); wr.WriteInt(p.y1); p := p.next END; wr.WriteInt(MIN(INTEGER)) END Externalize; PROCEDURE (m: Model) CopyFrom (source: Stores.Store); BEGIN m.lines := source(Model).lines (* lines are immutable and thus can be shared *) END CopyFrom; PROCEDURE (m: Model) Insert (x0, y0, x1, y1: INTEGER), NEW; VAR op: LineOp; p: Line; BEGIN NEW(op); op.model := m; NEW(p); p.next := m.lines; op.line := p; p.x0 := x0; p.y0 := y0; p.x1 := x1; p.y1 := y1; Models.Do(m, "Insert Line", op) END Insert; PROCEDURE (op: ColorOp) Do; VAR color: Ports.Color; BEGIN color := op.view.color; (* save old state *) op.view.color := op.color; (* set new state *) Views.Update(op.view, Views.keepFrames); (* restore everything *) op.color := color (* old state becomes new state for undo *) END Do; PROCEDURE (v: View) Internalize (VAR rd: Stores.Reader); VAR version: INTEGER; st: Stores.Store; BEGIN rd.ReadVersion(minVersion, maxVersion, version); IF ~rd.cancelled THEN rd.ReadInt(v.color); rd.ReadStore(st); v.model := st(Model) END END Internalize; PROCEDURE (v: View) Externalize (VAR wr: Stores.Writer); BEGIN wr.WriteVersion(maxVersion); wr.WriteInt(v.color); wr.WriteStore(v.model) END Externalize; PROCEDURE (v: View) CopyFromModelView (source: Views.View; model: Models.Model); BEGIN ASSERT(model IS Model, 20); WITH source: View DO v.model := model(Model); v.color := source.color END END CopyFromModelView; PROCEDURE (v: View) ThisModel (): Models.Model; BEGIN RETURN v.model END ThisModel; PROCEDURE (v: View) Restore (f: Views.Frame; l, t, r, b: INTEGER); VAR p: Line; BEGIN p := v.model.lines; WHILE p # NIL DO f.DrawLine(p.x0, p.y0, p.x1, p.y1, f.dot, v.color); p := p.next END END Restore; PROCEDURE (v: View) HandleModelMsg (VAR msg: Models.Message); BEGIN WITH msg: UpdateMsg DO Views.UpdateIn(v, msg.l, msg.t, msg.r, msg.b, Views.keepFrames) ELSE END END HandleModelMsg; PROCEDURE (v: View) SetColor (color: Ports.Color), NEW; VAR op: ColorOp; BEGIN NEW(op); op.view := v; op.color := color; Views.Do(v, "Set Color", op) END SetColor; PROCEDURE (v: View) HandleCtrlMsg (f: Views.Frame; VAR msg: Controllers.Message; VAR focus: Views.View); VAR x0, y0, x1, y1, x, y, res, l, t, r, b: INTEGER; modifiers: SET; isDown: BOOLEAN; BEGIN WITH msg: Controllers.TrackMsg DO x0 := msg.x; y0 := msg.y; x1 := x0; y1 := y0; f.SaveRect(f.l, f.t, f.r, f.b, res); (* operation was successful if res = 0 *) IF res = 0 THEN f.DrawLine(x0, y0, x1, y1, Ports.point, v.color) END; REPEAT f.Input(x, y, modifiers, isDown); IF (x # x1) OR (y # y1) THEN GetBox(x0, y0, x1, y1, l, t, r, b); f.RestoreRect(l, t, r, b, Ports.keepBuffer); x1 := x; y1 := y; IF res = 0 THEN f.DrawLine(x0, y0, x1, y1, Ports.point, v.color) END END UNTIL ~isDown; GetBox(x0, y0, x1, y1, l, t, r, b); f.RestoreRect(l, t, r, b, Ports.disposeBuffer); v.model.Insert(x0, y0, x1, y1) | msg: Controllers.EditMsg DO IF msg.op = Controllers.pasteChar THEN CASE msg.char OF | "B": v.SetColor(Ports.black) | "r": v.SetColor(Ports.red) | "g": v.SetColor(Ports.green) | "b": v.SetColor(Ports.blue) ELSE END END ELSE END END HandleCtrlMsg; PROCEDURE (v: View) HandlePropMsg (VAR msg: Properties.Message); BEGIN WITH msg: Properties.FocusPref DO msg.setFocus := TRUE ELSE END END HandlePropMsg; PROCEDURE Deposit*; VAR m: Model; v: View; BEGIN NEW(m); NEW(v); v.model := m; Stores.Join(v, m); Views.Deposit(v) END Deposit; END ObxLines.
Obx/Mod/Lines.odc
MODULE ObxLinks; (** project = "BlackBox" organization = "www.oberon.ch" contributors = "Oberon microsystems" version = "System/Rsrc/About" copyright = "System/Rsrc/About" license = "Docu/BB-License" changes = " - 20161216, center #144, inconsistent docu and usage of Files.Locator error codes " issues = " - ... " **) IMPORT Files, Stores, Converters, Fonts, Ports, Views, TextModels, TextMappers, TextViews, StdLinks; 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 Directory* (path: ARRAY OF CHAR); VAR t: TextModels.Model; f: TextMappers.Formatter; v: Views.View; tv: TextViews.View; old, new: TextModels.Attributes; conv: Converters.Converter; loc: Files.Locator; li: Files.LocInfo; fi: Files.FileInfo; str: ARRAY 256 OF CHAR; title: Views.Title; BEGIN t := TextModels.dir.New(); f.ConnectTo(t); f.WriteString("Directories"); f.WriteLn; old := f.rider.attr; (* save old text attributes for later use *) new := TextModels.NewStyle(old, old.font.style + {Fonts.underline}); (* use underline style *) new := TextModels.NewColor(new, Ports.blue); (* use blue color *) f.rider.SetAttr(new); (* change current attributes of formatter *) (* generate list of all locations *) PathToLoc(path, loc); li := Files.dir.LocList(loc); WHILE li # NIL DO (* no particular sorting order is guaranteed *) str := "ObxLinks.Directory('"; IF path # "" THEN str := str + path + "/" END; str := str + li.name + "')"; v := StdLinks.dir.NewLink(str); f.WriteView(v); (* insert left link view in text *) f.WriteString(li.name); v := StdLinks.dir.NewLink(""); f.WriteView(v); (* insert right link view in text *) f.WriteLn; li := li.next END; f.rider.SetAttr(old); (* reset current attributes of formatter *) f.WriteLn; f.WriteString("Files"); f.WriteLn; f.rider.SetAttr(new); (* change current attributes of formatter *) (* generate a list of all files *) fi := Files.dir.FileList(loc); WHILE fi # NIL DO (* no particular sorting order is guaranteed *) conv := Converters.list; WHILE (conv # NIL) & (conv.fileType # fi.type) DO conv := conv.next END; IF conv # NIL THEN (* there is a converter for this file type *) str := "ObxLinks.Open('"; str := str + path + "', '"; str := str + fi.name + "')"; v := StdLinks.dir.NewLink(str); f.WriteView(v); (* insert left link view in text *) f.WriteString(fi.name); v := StdLinks.dir.NewLink(""); f.WriteView(v); (* insert right link view in text *) f.WriteLn END; fi := fi.next END; tv := TextViews.dir.New(t); (* set Browser mode: *) title := "Directory of " + path; Views.OpenAux(tv, title) END Directory; PROCEDURE Open* (path, name: ARRAY OF CHAR); VAR loc: Files.Locator; f: Files.File; c: Converters.Converter; n: Files.Name; s: Stores.Store; BEGIN PathToLoc(path, loc); n := name$; IF loc.res = 0 THEN f := Files.dir.Old(loc, n, Files.shared); IF f # NIL THEN (* search in converter list for a converter that can import a file of this type *) c := Converters.list; WHILE (c # NIL) & (c.fileType # f.type) DO c := c.next END; IF c # NIL THEN Converters.Import(loc, n, c, s); WITH s: Views.View DO Views.Open(s, loc, n, c) ELSE END END END END END Open; END ObxLinks.
Obx/Mod/Links.odc
MODULE ObxLookup0; (** project = "BlackBox" organization = "www.oberon.ch" contributors = "Oberon microsystems" version = "System/Rsrc/About" copyright = "System/Rsrc/About" license = "Docu/BB-License" changes = " - YYYYMMDD, nn, ... " issues = " - ... " **) IMPORT TextModels, TextMappers, TextControllers, ObxPhoneDB; PROCEDURE Do*; (** use TextCmds.SelectionGuard as guard command **) VAR c: TextControllers.Controller; buf: TextModels.Model; from, to: INTEGER; s: TextMappers.Scanner; f: TextMappers.Formatter; number: ObxPhoneDB.String; BEGIN c := TextControllers.Focus(); IF (c # NIL) & c.HasSelection() THEN c.GetSelection(from, to); s.ConnectTo(c.text); s.SetPos(from); s.Scan; IF s.type = TextMappers.string THEN buf := TextModels.CloneOf(c.text); f.ConnectTo(buf); ObxPhoneDB.LookupByName(s.string$, number); f.WriteString(number); from := s.start; to := s.Pos() - 1; (* scanner has already read on character beyond string! *) c.text.Delete(from, to); (* delete name *) c.text.Insert(from, buf, 0, buf.Length()); (* move phone number from buffer into text *) c.SetSelection(from, from + LEN(number$)) (* select the phone number *) END END END Do; END ObxLookup0.
Obx/Mod/Lookup0.odc
MODULE ObxLookup1; (** project = "BlackBox" organization = "www.oberon.ch" contributors = "Oberon microsystems" version = "System/Rsrc/About" copyright = "System/Rsrc/About" license = "Docu/BB-License" changes = " - YYYYMMDD, nn, ... " issues = " - ... " **) IMPORT Stores, Models, TextModels, TextMappers, TextControllers, ObxPhoneDB; PROCEDURE Do*; (** use TextCmds.SelectionGuard as guard command **) VAR c: TextControllers.Controller; buf: TextModels.Model; from, to: INTEGER; s: TextMappers.Scanner; f: TextMappers.Formatter; number: ObxPhoneDB.String; script: Stores.Operation; BEGIN c := TextControllers.Focus(); IF (c # NIL) & c.HasSelection() THEN c.GetSelection(from, to); s.ConnectTo(c.text); s.SetPos(from); s.Scan; IF s.type = TextMappers.string THEN buf := TextModels.CloneOf(c.text); f.ConnectTo(buf); ObxPhoneDB.LookupByName(s.string$, number); f.WriteString(number); from := s.start; to := s.Pos() - 1; (* scanner has already read on character beyond string! *) Models.BeginScript(c.text, "#Obx:Lookup", script); c.text.Delete(from, to); (* delete name *) c.text.Insert(from, buf, 0, buf.Length()); (* move phone number from buffer into text *) Models.EndScript(c.text, script); c.SetSelection(from, from + LEN(number$)) (* select the phone number *) END END END Do; END ObxLookup1.
Obx/Mod/Lookup1.odc
MODULE ObxMMerge; (** project = "BlackBox" organization = "www.oberon.ch" contributors = "Oberon microsystems" version = "System/Rsrc/About" copyright = "System/Rsrc/About" license = "Docu/BB-License" changes = " - YYYYMMDD, nn, ... " issues = " - ... " **) (* note that as in the other sample programs, no error handling is performed *) IMPORT Files, Dialog, Views, TextModels, TextViews, TextControllers; CONST tab = 09X; TYPE Field = POINTER TO RECORD prev: Field; (* field list is sorted in reverse order *) name: ARRAY 24 OF CHAR; (* name of placeholder *) tmplFrom, tmplTo: INTEGER; (* character range used by placeholder in template *) index: INTEGER; (* column index of this field *) dataFrom, dataTo: INTEGER (* character range used by actual data in database *) END; PROCEDURE TmplFields (t: TextModels.Model): Field; (* returns a list of placeholder fields, in reverse order *) (* each field defines a text range and name of a placeholder *) (* the placeholder has the form "...<NameOfPlaceholder>..." *) VAR l, f: Field; r: TextModels.Reader; ch: CHAR; i: INTEGER; BEGIN l := NIL; r := t.NewReader(NIL); r.ReadChar(ch); WHILE ~r.eot DO IF ch = "<" THEN NEW(f); f.tmplFrom := r.Pos() - 1; r.ReadChar(ch); i := 0; WHILE ch # ">" DO f.name[i] := ch; INC(i); r.ReadChar(ch) END; f.name[i] := 0X; f.tmplTo := r.Pos(); f.dataFrom := -1; f.dataTo := -1; f.prev := l; l := f END; r.ReadChar(ch) END; RETURN l END TmplFields; PROCEDURE ThisDatabase (): TextModels.Model; VAR loc: Files.Locator; name: Files.Name; v: Views.View; t: TextModels.Model; BEGIN t := NIL; loc := NIL; name := ""; Dialog.GetIntSpec("", loc, name); IF loc # NIL THEN v := Views.OldView(loc, name); IF (v # NIL) & (v IS TextViews.View) THEN t := v(TextViews.View).ThisModel() END END; RETURN t END ThisDatabase; PROCEDURE MergeFields (f: Field; t: TextModels.Model); (* determine every template field's index in the data text's row of fields *) VAR r: TextModels.Reader; index, i: INTEGER; ch: CHAR; BEGIN r := t.NewReader(NIL); WHILE f # NIL DO (* iterate over all fields in the template *) f.index := -1; r.SetPos(0); index := 0; ch := tab; WHILE (ch = tab) & (f.index = -1) DO (* compare names of the fields *) REPEAT r.ReadChar(ch) UNTIL ch >= " "; i := 0; WHILE ch = f.name[i] DO r.ReadChar(ch); INC(i) END; IF (ch < " ") & (f.name[i] = 0X) THEN (* names match *) f.index := index ELSE (* no match; proceed to next data field *) WHILE ch >= " " DO r.ReadChar(ch) END END; INC(index) END; f := f.prev END END MergeFields; PROCEDURE ReadTuple (f: Field; r: TextModels.Reader); (* read tuple in data, and assign ranges to corresponding fields *) VAR index: INTEGER; from, to: INTEGER; ch: CHAR; g: Field; BEGIN index := 0; ch := tab; WHILE ch = tab DO REPEAT r.ReadChar(ch) UNTIL (ch = 0X) OR (ch >= " ") OR (ch = tab) OR (ch = 0DX); from := r.Pos() - 1; WHILE ch >= " " DO r.ReadChar(ch) END; to := r.Pos(); IF ~r.eot THEN DEC(to) END; g := f; WHILE g # NIL DO IF g.index = index THEN g.dataFrom := from; g.dataTo := to END; g := g.prev END; INC(index) END END ReadTuple; PROCEDURE AppendInstance (f: Field; data, tmpl, out: TextModels.Model); VAR start, from: INTEGER; r: TextModels.Reader; attr: TextModels.Attributes; BEGIN start := out.Length(); r := out.NewReader(NIL); out.InsertCopy(start, tmpl, 0, tmpl.Length()); (* append new copy of template *) WHILE f # NIL DO (* substitute placeholders, from end to beginning of template *) from := start + f.tmplFrom; r.SetPos(from); r.ReadRun(attr); (* save attributes *) out.Delete(from, from + f.tmplTo - f.tmplFrom); (* delete placeholder *) out.InsertCopy(from, data, f.dataFrom, f.dataTo); (* insert actual data *) out.SetAttr(from, from + f.dataTo - f.dataFrom, attr); (* set attributes *) f := f.prev END END AppendInstance; PROCEDURE Merge*; VAR c: TextControllers.Controller; tmpl, data, out: TextModels.Model; tmplFields: Field; r: TextModels.Reader; v: TextViews.View; BEGIN c := TextControllers.Focus(); IF c # NIL THEN tmpl := c.text; (* text template used for mail merge *) tmplFields := TmplFields(tmpl); (* determine fields in template *) data := ThisDatabase(); (* get text database for mail merge *) IF data # NIL THEN MergeFields(tmplFields, data); (* determine every template field's column in database *) out := TextModels.dir.New(); (* create output text *) r := data.NewReader(NIL); r.SetPos(0); ReadTuple(tmplFields, r); (* skip meta data *) REPEAT ReadTuple(tmplFields, r); (* read next data row *) AppendInstance(tmplFields, data, tmpl, out) (* append new instance of template *) UNTIL r.eot; v := TextViews.dir.New(out); Views.OpenView(v) (* open text view in window *) END END END Merge; END ObxMMerge.
Obx/Mod/MMerge.odc
MODULE ObxOmosi; (** project = "BlackBox" organization = "www.oberon.ch" contributors = "Oberon microsystems" version = "System/Rsrc/About" copyright = "System/Rsrc/About" license = "Docu/BB-License" changes = " - YYYYMMDD, nn, ... " issues = " - ... " **) IMPORT Ports, Stores, Views, Controllers, Properties, Dialog; CONST outside = -1; white = 0; top = 1; left = 2; right = 3; (* Kind *) gridDefault = FALSE; minVersion = 0; maxVersion = 1; TYPE Palette = ARRAY 4 OF Ports.Color; Kind = INTEGER; Field = RECORD kind: Kind; sel: BOOLEAN END; Row = ARRAY 8 OF Field; Model = ARRAY 15 OF Row; StdView = POINTER TO RECORD (Views.View) (* persistent state *) pal: Palette; mod: Model; (* non-persistent state *) sel: INTEGER; grid: BOOLEAN END; FieldPath = ARRAY 3 OF Ports.Point; FieldOp = POINTER TO RECORD (Stores.Operation) v: StdView; i, j: INTEGER; kind: Kind END; ColorOp = POINTER TO ColorOpDesc; ColorOpDesc = RECORD (Stores.Operation) v: StdView; n: INTEGER; col: Ports.Color END; UpdateMsg = RECORD (Views.Message) i, j: INTEGER END; PROCEDURE InitRow (VAR row: Row; k: INTEGER); VAR i, l, r: INTEGER; BEGIN l := (8 - k) DIV 2; r := 8 - l; i := 0; WHILE i # l DO row[i].kind := outside; INC(i) END; WHILE i # r DO row[i].kind := white; INC(i) END; WHILE i # 8 DO row[i].kind := outside; INC(i) END; i := 0; WHILE i # 8 DO row[i].sel := FALSE; INC(i) END END InitRow; PROCEDURE InitPalette (VAR p: Palette); BEGIN p[white] := Ports.white; p[top] := 0080FFH; p[left] := 004080H; p[right] := 000040H END InitPalette; PROCEDURE InitModel (VAR m: Model); VAR j: INTEGER; BEGIN InitRow(m[0], 2); InitRow(m[1], 4); InitRow(m[2], 6); j := 3; WHILE j # 12 DO InitRow(m[j], 8); INC(j) END; InitRow(m[12], 6); InitRow(m[13], 4); InitRow(m[14], 2) END InitModel; PROCEDURE H (s: INTEGER): INTEGER; BEGIN RETURN s * 500 DIV 866 END H; PROCEDURE GetFieldPath (v: StdView; f: Ports.Frame; i, j: INTEGER; OUT p: FieldPath); VAR w, h, s: INTEGER; BEGIN v.context.GetSize(w, h); s := (w - f.unit) DIV 8; h := H(s); IF ODD(i + j) THEN p[0].x := i * s; p[0].y := (j + 1) * h; p[1].x := (i + 1) * s; p[1].y := j * h; p[2].x := (i + 1) * s; p[2].y := (j + 2) * h ELSE p[0].x := i * s; p[0].y := j * h; p[1].x := (i + 1) * s; p[1].y := (j + 1) * h; p[2].x := i * s; p[2].y := (j + 2) * h END END GetFieldPath; PROCEDURE AdjustPath (f: Ports.Frame; i, j: INTEGER; VAR p: FieldPath); VAR d, e: INTEGER; BEGIN d := 2 * f.dot; e := 3 * f.dot; IF ODD(i + j) THEN INC(p[0].x, e); DEC(p[1].x, d); INC(p[1].y, e); DEC(p[2].x, d); DEC(p[2].y, e) ELSE INC(p[0].x, d); INC(p[0].y, e); DEC(p[1].x, e); INC(p[2].x, d); DEC(p[2].y, e) END END AdjustPath; PROCEDURE ValidField (v: StdView; i, j: INTEGER): BOOLEAN; BEGIN RETURN (0 <= i) & (i < 8) & (0 <= j) & (j < 15) & (v.mod[j, i].kind > outside) END ValidField; PROCEDURE DrawField (v: StdView; f: Ports.Frame; i, j: INTEGER); VAR col: Ports.Color; p: FieldPath; BEGIN IF ValidField(v, i, j) THEN col := v.pal[v.mod[j, i].kind]; GetFieldPath(v, f, i, j, p); f.DrawPath(p, 3, Ports.fill, col, Ports.closedPoly); IF v.grid THEN f.DrawPath(p, 3, 0, Ports.grey25, Ports.closedPoly) END; IF v.mod[j, i].sel THEN AdjustPath(f, i, j, p); f.DrawPath(p, 3, 0, 800000H, Ports.closedPoly) END END END DrawField; PROCEDURE SelectField (v: StdView; f: Ports.Frame; i, j: INTEGER; sel: BOOLEAN); BEGIN IF ValidField(v, i, j) & (v.mod[j, i].sel # sel) THEN v.mod[j, i].sel := sel; IF sel THEN INC(v.sel) ELSE DEC(v.sel) END; DrawField(v, f, i, j) END END SelectField; PROCEDURE LocateField (v: StdView; f: Views.Frame; x, y: INTEGER; OUT i, j: INTEGER); VAR u, w, h, s, sx, sy: INTEGER; BEGIN v.context.GetSize(w, h); s := (w - f.unit) DIV 8; u := f.unit; h := H(s); sx := x DIV s; sy := y DIV h; IF (0 <= sx) & (sx < 9) & (0 <= sy) & (sy < 16) THEN i := SHORT(sx); j := SHORT(sy); IF ODD(i + j) THEN IF (s - x) MOD s * (h DIV u) >= y MOD h * (s DIV u) THEN DEC(j) END ELSE IF x MOD s * (h DIV u) >= y MOD h * (s DIV u) THEN DEC(j) END END; IF (i = 8) OR (j = 15) OR (j >= 0) & (v.mod[j, i].kind = outside) THEN j := -1 END ELSE j := -1 END END LocateField; PROCEDURE Select (v: StdView; set: BOOLEAN); VAR i, j, sel: INTEGER; BEGIN j := 0; WHILE j # 15 DO i := 0; WHILE i # 8 DO v.mod[j, i].sel := set; INC(i) END; INC(j) END; IF set THEN sel := 64 ELSE sel := 0 END; IF v.sel # sel THEN v.sel := sel; Views.Update(v, Views.keepFrames) END END Select; PROCEDURE Track (v: StdView; f: Views.Frame; x, y: INTEGER; buttons: SET); VAR script: Stores.Operation; op: FieldOp; cop: ColorOp; col: Ports.Color; i, j, i0, j0, i1, j1: INTEGER; isDown, prevSel, setCol: BOOLEAN; m: SET; BEGIN LocateField(v, f, x, y, i, j); i0 := i; j0 := j; prevSel := ValidField(v, i, j) & v.mod[j, i].sel; IF ~prevSel & ~(Controllers.extend IN buttons) & (v.sel > 0) THEN j := 0; WHILE j # 15 DO i := 0; WHILE i # 8 DO IF v.mod[j, i].sel THEN SelectField(v, f, i, j, FALSE) END; INC(i) END; INC(j) END; v.sel := 0; i := i0; j := j0 END; SelectField(v, f, i, j, ~prevSel OR ~(Controllers.extend IN buttons)); REPEAT f.Input(x, y, m, isDown); LocateField(v, f, x, y, i1, j1); IF (i1 # i) OR (j1 # j) THEN IF ~(Controllers.extend IN buttons) THEN SelectField(v, f, i, j, FALSE) END; i := i1; j := j1; SelectField(v, f, i, j, ~prevSel OR ~(Controllers.extend IN buttons)) END UNTIL ~isDown; IF ~(Controllers.extend IN buttons) & ((i # i0) OR (j # j0) OR ~prevSel) THEN SelectField(v, f, i, j, FALSE) END; IF ValidField(v, i, j) THEN IF Controllers.modify IN buttons THEN Dialog.GetColor(v.pal[v.mod[j, i].kind], col, setCol); IF setCol THEN NEW(cop); cop.v := v; cop.n := v.mod[j, i].kind; cop.col := col; Views.Do(v, "Color Change", cop) END ELSIF ~(Controllers.extend IN buttons) THEN Views.BeginScript(v, "Omosi Change", script); j := 0; WHILE j # 15 DO i := 0; WHILE i # 8 DO IF (v.mod[j, i].sel OR (i = i1) & (j = j1)) & (v.mod[j, i].kind > outside) THEN NEW(op); op.v := v; op.i := i; op.j := j; op.kind := (v.mod[j, i].kind + 1) MOD 4; Views.Do(v, "", op) END; INC(i) END; INC(j) END; Views.EndScript(v, script) END END END Track; (* FieldOp *) PROCEDURE (op: FieldOp) Do; VAR k: Kind; msg: UpdateMsg; BEGIN k := op.v.mod[op.j, op.i].kind; op.v.mod[op.j, op.i].kind := op.kind; op.kind := k; msg.i := op.i; msg.j := op.j; Views.Broadcast(op.v, msg) END Do; (* ColorOp *) PROCEDURE (op: ColorOp) Do; VAR c: Ports.Color; BEGIN c := op.v.pal[op.n]; op.v.pal[op.n] := op.col; op.col := c; Views.Update(op.v, Views.keepFrames) END Do; (* View *) PROCEDURE (v: StdView) Externalize (VAR wr: Stores.Writer); VAR i, j: INTEGER; BEGIN wr.WriteVersion(maxVersion); i := 0; WHILE i # 4 DO wr.WriteInt(v.pal[i]); INC(i) END; j := 0; WHILE j # 15 DO i := 0; WHILE i # 8 DO wr.WriteInt(v.mod[j, i].kind); INC(i) END; INC(j) END END Externalize; PROCEDURE (v: StdView) Internalize (VAR rd: Stores.Reader); VAR i, j: INTEGER; version: INTEGER; BEGIN rd.ReadVersion(minVersion, maxVersion, version); IF ~rd.cancelled THEN i := 0; WHILE i # 4 DO rd.ReadInt(v.pal[i]); INC(i) END; j := 0; WHILE j # 15 DO i := 0; WHILE i # 8 DO rd.ReadInt(v.mod[j, i].kind); v.mod[j, i].sel := FALSE; INC(i) END; INC(j) END; v.grid := FALSE END END Internalize; PROCEDURE (v: StdView) CopyFromSimpleView (source: Views.View); BEGIN WITH source: StdView DO v.pal := source.pal; v.mod := source.mod; v.sel := source.sel; v.grid := gridDefault END END CopyFromSimpleView; PROCEDURE (v: StdView) Restore (f: Views.Frame; l, t, r, b: INTEGER); VAR i, j: INTEGER; BEGIN j := 0; WHILE j # 15 DO i := 0; WHILE i # 8 DO DrawField(v, f, i, j); INC(i) END; INC(j) END END Restore; PROCEDURE (v: StdView) HandleViewMsg (f: Views.Frame; VAR msg: Views.Message); BEGIN WITH msg: UpdateMsg DO DrawField(v, f, msg.i, msg.j) ELSE END END HandleViewMsg; PROCEDURE (v: StdView) HandleCtrlMsg (f: Views.Frame; VAR msg: Controllers.Message; VAR focus: Views.View); BEGIN WITH msg: Controllers.TrackMsg DO Track(v, f, msg.x, msg.y, msg.modifiers) | msg: Controllers.PollOpsMsg DO msg.selectable := TRUE | msg: Controllers.SelectMsg DO Select(v, msg.set) ELSE END END HandleCtrlMsg; PROCEDURE (v: StdView) HandlePropMsg (VAR msg: Properties.Message); CONST minW = 3 * Ports.mm; stdW = 7 * Ports.mm; (* per field *) BEGIN WITH msg: Properties.SizePref DO IF (msg.w > Views.undefined) & (msg.h > Views.undefined) THEN DEC(msg.h, 1 * Ports.mm); Properties.ProportionalConstraint(1000, 2 * H(1000), msg.fixedW, msg.fixedH, msg.w, msg.h); IF msg.w < 8 * minW THEN msg.w := 8 * minW; msg.h := 16 * H(minW) END ELSE msg.w := 8 * stdW; msg.h := 16 * H(stdW) END; INC(msg.h, 1 * Ports.mm) | msg: Properties.FocusPref DO msg.setFocus := TRUE ELSE END END HandlePropMsg; (* commands *) PROCEDURE Deposit*; VAR v: StdView; BEGIN NEW(v); InitPalette(v.pal); InitModel(v.mod); v.sel := 0; v.grid := FALSE; Views.Deposit(v) END Deposit; PROCEDURE ToggleGrid*; VAR v: Views.View; BEGIN v := Controllers.FocusView(); IF v # NIL THEN WITH v: StdView DO v.grid := ~v.grid; Views.Update(v, Views.keepFrames) ELSE END END END ToggleGrid; PROCEDURE ResetColors*; VAR v: Views.View; p0: Palette; script: Stores.Operation; cop: ColorOp; i: INTEGER; BEGIN v := Controllers.FocusView(); IF v # NIL THEN WITH v: StdView DO Views.BeginScript(v, "Reset Colors", script); InitPalette(p0); i := 0; WHILE i # 4 DO NEW(cop); cop.v := v; cop.n := i; cop.col := p0[i]; Views.Do(v, "", cop); INC(i) END; Views.EndScript(v, script) ELSE END END END ResetColors; END ObxOmosi.
Obx/Mod/Omosi.odc
MODULE ObxOpen0; (** project = "BlackBox" organization = "www.oberon.ch" contributors = "Oberon microsystems" version = "System/Rsrc/About" copyright = "System/Rsrc/About" license = "Docu/BB-License" changes = " - YYYYMMDD, nn, ... " issues = " - ... " **) IMPORT Files, Converters, Views, Dialog, TextModels, TextMappers, TextViews; TYPE OpenAction = POINTER TO RECORD (Dialog.GetAction) END; PROCEDURE (a: OpenAction) Do; VAR v: Views.View; t: TextModels.Model; f: TextMappers.Formatter; BEGIN IF ~a.cancel THEN v := Views.OldView(a.loc, a.name); IF (v # NIL) & (v IS TextViews.View) THEN (* make sure it is a text view *) t := v(TextViews.View).ThisModel(); (* get the text view's model *) f.ConnectTo(t); f.SetPos(t.Length()); (* set the formatter to the end of the text *) f.WriteString("appendix"); (* append a string *) Views.OpenView(v) (* open the text view in a window *) END END END Do; PROCEDURE Do*; VAR action: OpenAction; BEGIN (* ask user for a file and open it as a view *) NEW(action); Dialog.GetIntLocName("", NIL, action); END Do; END ObxOpen0.
Obx/Mod/Open0.odc
MODULE ObxOpen1; (** project = "BlackBox" organization = "www.oberon.ch" contributors = "Oberon microsystems" version = "System/Rsrc/About" copyright = "System/Rsrc/About" license = "Docu/BB-License" changes = " - YYYYMMDD, nn, ... " issues = " - ... " **) IMPORT Converters, Files, Views, Dialog, TextModels, TextMappers, TextViews; TYPE OpenAction = POINTER TO RECORD (Dialog.GetAction) END; SaveAction = POINTER TO RECORD (Dialog.GetAction) v: Views.View; END; PROCEDURE (a: SaveAction) Do; VAR res: INTEGER; conv: Converters.Converter; name: Files.Name; BEGIN IF ~a.cancel THEN IF a.converterName # "" THEN conv := Converters.list; WHILE (conv # NIL) & (conv.exp # a.converterName) DO conv := conv.next END ELSE conv := NIL END; name := a.name + "." + a.type; Views.Register(a.v, Views.dontAsk, a.loc, name, conv, res); END END Do; PROCEDURE (a: OpenAction) Do; VAR v: Views.View; t: TextModels.Model; f: TextMappers.Formatter; saveAction: SaveAction; BEGIN IF ~a.cancel THEN v := Views.OldView(a.loc, a.name); IF (v # NIL) & (v IS TextViews.View) THEN (* make sure it is a text view *) t := v(TextViews.View).ThisModel(); (* get the text view's model *) f.ConnectTo(t); f.SetPos(t.Length()); (* set the formatter to the end of the text *) f.WriteString("appendix"); (* append a string *) NEW(saveAction); saveAction.v := v; Dialog.GetExtLocName("", "", NIL, saveAction) END END END Do; PROCEDURE Do*; VAR action: OpenAction; BEGIN (* ask user for a file and open it as a view *) NEW(action); Dialog.GetIntLocName("odc", NIL, action) END Do; END ObxOpen1.
Obx/Mod/Open1.odc
MODULE ObxOrders; (** project = "BlackBox" organization = "www.oberon.ch" contributors = "Oberon microsystems" version = "System/Rsrc/About" copyright = "System/Rsrc/About" license = "Docu/BB-License" changes = " - YYYYMMDD, nn, ... " issues = " - ... " **) IMPORT Files, Dialog, Fonts, Stores, Views, TextModels, TextViews, TextMappers, TextRulers, StdCmds, StdStamps; CONST (* values for card field of interactor *) amex = 0; master = 1; visa = 2; (* prices in 1/100 Swiss Francs *) ofwinfullVal = 45000; ofmacfullVal = 45000; ofwineduVal = 15000; ofmaceduVal = 15000; odfVal = 5000; vatVal = 65; type = "dat"; (* file type *) TYPE Interactor* = RECORD name*, company*, adr1*, adr2*, adr3*, email*: ARRAY 128 OF CHAR; phone*, fax*: ARRAY 32 OF CHAR; ofwinfull*, ofmacfull*, ofwinedu*, ofmacedu*, odf*: INTEGER; card*: INTEGER; cardno*: ARRAY 24 OF CHAR; vat*: BOOLEAN END; Element = POINTER TO RECORD prev, next: Element; data: Interactor END; VAR par*: Interactor; root, cur: Element; (* header and current element of doubly-linked ring *) name: Files.Name; loc: Files.Locator; PROCEDURE ReadElem (VAR rd: Stores.Reader; e: Element); BEGIN rd.ReadString(e.data.name);rd.ReadString(e.data.company); rd.ReadString(e.data.adr1); rd.ReadString(e.data.adr2); rd.ReadString(e.data.adr3); rd.ReadString(e.data.email); rd.ReadString(e.data.phone); rd.ReadString(e.data.fax); rd.ReadString(e.data.cardno); rd.ReadInt(e.data.ofwinfull); rd.ReadInt(e.data.ofmacfull); rd.ReadInt(e.data.ofwinedu); rd.ReadInt(e.data.ofmacedu); rd.ReadInt(e.data.odf); rd.ReadInt(e.data.card); rd.ReadBool(e.data.vat) END ReadElem; PROCEDURE WriteElem (VAR wr: Stores.Writer; e: Element); BEGIN wr.WriteString(e.data.name); wr.WriteString(e.data.company); wr.WriteString(e.data.adr1); wr.WriteString(e.data.adr2); wr.WriteString(e.data.adr3); wr.WriteString(e.data.email); wr.WriteString(e.data.phone); wr.WriteString(e.data.fax); wr.WriteString(e.data.cardno); wr.WriteInt(e.data.ofwinfull); wr.WriteInt(e.data.ofmacfull); wr.WriteInt(e.data.ofwinedu); wr.WriteInt(e.data.ofmacedu); wr.WriteInt(e.data.odf); wr.WriteInt(e.data.card); wr.WriteBool(e.data.vat) END WriteElem; PROCEDURE Init; BEGIN cur := root; root.next := root; root.prev := root END Init; PROCEDURE Update; BEGIN par := cur.data; Dialog.Update(par) END Update; PROCEDURE Load*; VAR e: Element; f: Files.File; rd: Stores.Reader; count: INTEGER; BEGIN Dialog.GetIntSpec(type, loc, name); IF loc # NIL THEN f := Files.dir.Old(loc, name, Files.shared); IF (f # NIL) & (f.type = type) THEN rd.ConnectTo(f); rd.ReadInt(count); Init; WHILE count # 0 DO NEW(e); IF e # NIL THEN e.prev := cur; e.next := cur.next; e.prev.next := e; e.next.prev := e; ReadElem(rd, e); cur := e; DEC(count) ELSE Dialog.ShowMsg("out of memory"); Dialog.Beep; count := 0; root.next := root; root.prev := root; cur := root END END; Update ELSE Dialog.ShowMsg("cannot open file"); Dialog.Beep END END END Load; PROCEDURE Save*; VAR e: Element; f: Files.File; wr: Stores.Writer; count, res: INTEGER; BEGIN IF (loc = NIL) OR (name = "") THEN Dialog.GetExtSpec("", "", loc, name) END; IF (loc # NIL) & (name # "") THEN f := Files.dir.New(loc, Files.dontAsk); wr.ConnectTo(f); e := root.next; count := 0; WHILE e # root DO INC(count); e := e.next END; (* count elements *) wr.WriteInt(count); e := root.next; WHILE e # root DO WriteElem(wr, e); e := e.next END; (* write elements *) f.Register(name, type, Files.dontAsk, res); Init; name := ""; loc := NIL; (* close database *) Update END END Save; PROCEDURE Insert*; VAR e: Element; BEGIN NEW(e); IF e # NIL THEN (* insert new record at end of database *) IF cur # root THEN cur.data := par END; (* save current record, in case it was changed *) e.prev := root.prev; e.next := root; e.prev.next := e; e.next.prev := e; cur := e; Update ELSE Dialog.ShowMsg("out of memory"); Dialog.Beep END END Insert; PROCEDURE Delete*; BEGIN IF cur # root THEN StdCmds.CloseDialog; cur.next.prev := cur.prev; cur.prev.next := cur.next; cur := cur.prev; IF cur = root THEN cur := root.next END; Update END END Delete; PROCEDURE Next*; BEGIN IF cur.next # root THEN cur.data := par; cur := cur.next; Update END END Next; PROCEDURE Prev*; BEGIN IF cur.prev # root THEN cur.data := par; cur := cur.prev; Update END END Prev; PROCEDURE NonemptyGuard* (VAR par: Dialog.Par); BEGIN par.disabled := cur = root END NonemptyGuard; PROCEDURE NextGuard* (VAR par: Dialog.Par); BEGIN par.disabled := cur.next = root END NextGuard; PROCEDURE PrevGuard* (VAR par: Dialog.Par); BEGIN par.disabled := cur.prev = root END PrevGuard; PROCEDURE WriteLine (VAR f: TextMappers.Formatter; no, val: INTEGER; name: ARRAY OF CHAR; VAR total, vat: INTEGER); BEGIN IF no # 0 THEN val := no * val; f.WriteInt(no); f.WriteString(name); INC(total, val); INC(vat, val); f. WriteTab; f.WriteIntForm(val DIV 100, 10, 5, TextModels.digitspace, FALSE); f.WriteChar("."); f.WriteIntForm(val MOD 100, 10, 2, "0", FALSE); f.WriteLn END END WriteLine; PROCEDURE NewRuler (): TextRulers.Ruler; VAR r: TextRulers.Ruler; BEGIN r := TextRulers.dir.New(NIL); (* TextRulers.SetLeft(r, 30 * Ports.mm); TextRulers.SetRight(r, 165 * Ports.mm); TextRulers.AddTab(r, 130 * Ports.mm); *) RETURN r END NewRuler; PROCEDURE Invoice*; VAR v: TextViews.View; f: TextMappers.Formatter; a: TextModels.Attributes; total, vat: INTEGER; BEGIN IF cur # root THEN v := TextViews.dir.New(TextModels.dir.New()); f.ConnectTo(v.ThisModel()); f.WriteView(NewRuler()); (* create header of invoice *) f.WriteLn; f.WriteLn; f.WriteLn; f.WriteLn; f.WriteLn; f.WriteLn; f.WriteLn; f.WriteTab; f.WriteString("Basel, "); f.WriteView(StdStamps.New()); f.WriteLn; f.WriteLn; f.WriteLn; (* write address *) IF par.name # "" THEN f.WriteString(par.name); f.WriteLn END; IF par.company # "" THEN f.WriteString(par.company); f.WriteLn END; IF par.adr1 # "" THEN f.WriteString(par.adr1); f.WriteLn END; IF par.adr2 # "" THEN f.WriteString(par.adr2); f.WriteLn END; IF par.adr3 # "" THEN f.WriteString(par.adr3); f.WriteLn END; f.WriteLn; f.WriteLn; f.WriteLn; (* set bold font weight *) a := f.rider.attr; f.rider.SetAttr(TextModels.NewWeight(a, Fonts.bold)); f.WriteString("Invoice"); (* this string will appear in bold face *) f.rider.SetAttr(a); (* restore default weight *) f.WriteLn; f.WriteLn; f.WriteString("Creditcard: "); CASE par.card OF | amex: f.WriteString("American Express") | master: f.WriteString("Euro/MasterCard") | visa: f.WriteString("Visa") END; f.WriteLn; f.WriteLn; f.WriteLn; (* write products with subtotals *) total := 0; vat := 0; WriteLine(f, par.ofwinfull, ofwinfullVal, " ofwin full", total, vat); WriteLine(f, par.ofmacfull, ofmacfullVal, " ofmac full", total, vat); WriteLine(f, par.ofwinedu, ofwineduVal, " ofwin edu", total, vat); WriteLine(f, par.ofmacedu, ofmaceduVal, " ofmac edu", total, vat); WriteLine(f, par.odf, odfVal, " odf", total, vat); (* write vat *) IF par.vat THEN f.WriteLn; INC(total, (vat * vatVal) DIV 1000); (* vat is 6.5% *) f.WriteString("value added tax ("); f.WriteInt(vatVal DIV 10); f.WriteChar("."); f.WriteInt(vatVal MOD 10); f.WriteString("% on "); f.WriteInt(vat DIV 100); f.WriteChar("."); f.WriteIntForm(vat MOD 100, 10, 2, "0", FALSE); f.WriteString(")"); f.WriteTab; f.WriteIntForm((vat * vatVal) DIV 100000, 10, 5, TextModels.digitspace, FALSE); f.WriteChar("."); f.WriteIntForm(((vat * vatVal) DIV 1000) MOD 100, 10, 2, "0", FALSE); f.WriteLn END; (* write total *) f.WriteLn; f.WriteString("Total"); f.WriteTab; f.WriteIntForm(total DIV 100, 10, 5, TextModels.digitspace, FALSE); f.WriteChar("."); f.WriteIntForm(total MOD 100, 10, 2, "0", FALSE); f.WriteString(" sFr."); f.WriteLn; f.WriteLn; f.WriteLn; f.WriteLn; f.WriteLn; f.WriteLn; f.WriteLn; f.WriteLn; f.WriteLn; f.WriteString("The exporter of the products covered by this document declares that, except where otherwise clearly indicated, these products are of Swiss preferential origin."); f.WriteLn; Views.OpenAux(v, "Invoice") END END Invoice; BEGIN NEW(root); Init END ObxOrders.
Obx/Mod/Orders.odc
MODULE ObxParCmd; (** project = "BlackBox" organization = "www.oberon.ch" contributors = "Oberon microsystems" version = "System/Rsrc/About" copyright = "System/Rsrc/About" license = "Docu/BB-License" changes = " - YYYYMMDD, nn, ... " issues = " - ... " **) IMPORT Dialog, Models, Controls, TextModels, TextMappers, StdLog; PROCEDURE Connect (VAR s: TextMappers.Scanner; OUT done: BOOLEAN); VAR c: Models.Context; BEGIN done := FALSE; IF Controls.par # NIL THEN c := Controls.par.context; (* the context of an open view is never NIL *) WITH c: TextModels.Context DO s.ConnectTo(c.ThisModel()); s.SetPos(c.Pos() + 1); s.Scan; done := TRUE ELSE END END END Connect; PROCEDURE Do0*; VAR s: TextMappers.Scanner; done: BOOLEAN; BEGIN Connect(s, done); IF done THEN IF s.type = TextMappers.string THEN StdLog.String(s.string); StdLog.Ln (* write string after button to log *) END END END Do0; PROCEDURE Do1*; VAR s: TextMappers.Scanner; done: BOOLEAN; res: INTEGER; BEGIN Connect(s, done); IF done THEN IF s.type = TextMappers.string THEN Dialog.Call(s.string, " ", res) (* execute string after button as a command sequence *) END END END Do1; END ObxParCmd.
Obx/Mod/ParCmd.odc
MODULE ObxPatterns; (** project = "BlackBox" organization = "www.oberon.ch" contributors = "Oberon microsystems" version = "System/Rsrc/About" copyright = "System/Rsrc/About" license = "Docu/BB-License" changes = " - YYYYMMDD, nn, ... " issues = " - ... " **) IMPORT Ports, Stores, Views, Properties; CONST minVersion = 0; maxVersion = 0; TYPE View = POINTER TO RECORD (Views.View) END; PROCEDURE (v: View) Internalize (VAR rd: Stores.Reader); VAR version: INTEGER; BEGIN rd.ReadVersion(minVersion, maxVersion, version) END Internalize; PROCEDURE (v: View) Externalize (VAR wr: Stores.Writer); BEGIN wr.WriteVersion(maxVersion) END Externalize; PROCEDURE (v: View) Restore (f: Views.Frame; l, t, r, b: INTEGER); VAR w, h, d: INTEGER; col: INTEGER; colors: ARRAY 3 OF Ports.Color; BEGIN colors[0] := Ports.red; colors[1] := Ports.green; colors[2] := Ports.blue; v.context.GetSize(w, h); d := 4 * f.dot; col := 0; l := 0; t := 0; r := w; b := h; WHILE (r> l) & (b > t) DO f.DrawRect(l, t, r, b, f.dot, colors[col]); INC(l, d); INC(t, d); DEC(r, d); DEC(b, d); col := (col + 1) MOD 3 END END Restore; PROCEDURE (v: View) HandlePropMsg (VAR p: Properties.Message); CONST min = 10 * Ports.mm; max = 160 * Ports.mm; pref = 90 * Ports.mm; BEGIN WITH p: Properties.SizePref DO (* prevent illegal sizes *) IF p.w = Views.undefined THEN (* no preference for width -> skip *) ELSIF p.w < min THEN p.w := min ELSIF p.w > max THEN p.w := max END; IF p.h = Views.undefined THEN p.h := pref ELSIF p.h < min THEN p.h := min ELSIF p.h > max THEN p.h := max END ELSE END END HandlePropMsg; PROCEDURE Deposit*; VAR v: View; BEGIN NEW(v); Views.Deposit(v) END Deposit; END ObxPatterns.
Obx/Mod/Patterns.odc
MODULE ObxPDBRep0; (** project = "BlackBox" organization = "www.oberon.ch" contributors = "Oberon microsystems" version = "System/Rsrc/About" copyright = "System/Rsrc/About" license = "Docu/BB-License" changes = " - YYYYMMDD, nn, ... " issues = " - ... " **) IMPORT Views, TextModels, TextMappers, TextViews, ObxPhoneDB; PROCEDURE GenReport*; VAR t: TextModels.Model; f: TextMappers.Formatter; v: TextViews.View; i: INTEGER; name, number: ObxPhoneDB.String; BEGIN t := TextModels.dir.New(); (* create empty text carrier *) f.ConnectTo(t); (* connect a formatter to the text *) i := 0; ObxPhoneDB.LookupByIndex(i, name, number); WHILE name # "" DO f.WriteString(name); (* first string *) f.WriteTab; (* tab character *) f.WriteString(number); (* second string *) f.WriteLn; (* carriage return *) INC(i); ObxPhoneDB.LookupByIndex(i, name, number) END; v := TextViews.dir.New(t); (* create a text view for the text generated above *) Views.OpenView(v) (* open the text view in its own window *) END GenReport; END ObxPDBRep0.
Obx/Mod/PDBRep0.odc
MODULE ObxPDBRep1; (** project = "BlackBox" organization = "www.oberon.ch" contributors = "Oberon microsystems" version = "System/Rsrc/About" copyright = "System/Rsrc/About" license = "Docu/BB-License" changes = " - YYYYMMDD, nn, ... " issues = " - ... " **) IMPORT Ports, Views, TextModels, TextMappers, TextViews, ObxPhoneDB; PROCEDURE GenReport*; VAR t: TextModels.Model; f: TextMappers.Formatter; v: TextViews.View; i: INTEGER; name, number: ObxPhoneDB.String; default, green: TextModels.Attributes; BEGIN t := TextModels.dir.New(); (* create empty text carrier *) f.ConnectTo(t); (* connect a formatter to the text *) default := f.rider.attr; (* save old text attributes for later use *) green := TextModels.NewColor(default, Ports.green); (* use green color *) i := 0; ObxPhoneDB.LookupByIndex(i, name, number); WHILE name # "" DO f.rider.SetAttr(green); (* change current attributes of formatter's rider *) f.WriteString(name); (* first string *) f.rider.SetAttr(default); (* change current attributes of formatter's rider *) f.WriteTab; (* tab character *) f.WriteString(number); (* second string *) f.WriteLn; (* carriage return *) INC(i); ObxPhoneDB.LookupByIndex(i, name, number) END; v := TextViews.dir.New(t); (* create a text view for the text generated above *) Views.OpenView(v) (* open the text view in its own window *) END GenReport; END ObxPDBRep1.
Obx/Mod/PDBRep1.odc
MODULE ObxPDBRep2; (** project = "BlackBox" organization = "www.oberon.ch" contributors = "Oberon microsystems" version = "System/Rsrc/About" copyright = "System/Rsrc/About" license = "Docu/BB-License" changes = " - YYYYMMDD, nn, ... " issues = " - ... " **) IMPORT Ports, Views, TextModels, TextMappers, TextViews, TextRulers, ObxPhoneDB; PROCEDURE WriteRuler (VAR f:TextMappers.Formatter); CONST cm = 10 * Ports.mm; (* universal units *) VAR ruler: TextRulers.Ruler; BEGIN ruler := TextRulers.dir.New(NIL); TextRulers.AddTab(ruler, 4 * cm); (* define a tab stop, 4 cm from the left margin *) TextRulers.SetRight(ruler, 12 * cm); (* set right margin *) f.WriteView(ruler) (* a ruler is a view, thus can be written to the text *) END WriteRuler; PROCEDURE GenReport*; VAR t: TextModels.Model; f: TextMappers.Formatter; v: TextViews.View; i: INTEGER; name, number: ObxPhoneDB.String; BEGIN t := TextModels.dir.New(); (* create empty text carrier *) f.ConnectTo(t); (* connect a formatter to the text *) WriteRuler(f); i := 0; ObxPhoneDB.LookupByIndex(i, name, number); WHILE name # "" DO f.WriteString(name); (* first string *) f.WriteTab; (* tab character *) f.WriteString(number); (* second string *) f.WriteLn; (* carriage return *) INC(i); ObxPhoneDB.LookupByIndex(i, name, number) END; v := TextViews.dir.New(t); (* create a text view for the text generated above *) Views.OpenView(v) (* open the text view in its own window *) END GenReport; END ObxPDBRep2.
Obx/Mod/PDBRep2.odc
MODULE ObxPDBRep3; (** project = "BlackBox" organization = "www.oberon.ch" contributors = "Oberon microsystems" version = "System/Rsrc/About" copyright = "System/Rsrc/About" license = "Docu/BB-License" changes = " - YYYYMMDD, nn, ... " issues = " - ... " **) IMPORT Views, TextModels, TextMappers, TextViews, StdFolds, ObxPhoneDB; PROCEDURE WriteOpenFold (VAR f: TextMappers.Formatter; IN shortForm: ARRAY OF CHAR); VAR fold: StdFolds.Fold; t: TextModels.Model; BEGIN t := TextModels.dir.NewFromString(shortForm); (* convert a string into a text model *) fold := StdFolds.dir.New(StdFolds.expanded, "", t); f.WriteView(fold) END WriteOpenFold; PROCEDURE WriteCloseFold (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 GenReport*; VAR t: TextModels.Model; f: TextMappers.Formatter; v: TextViews.View; i: INTEGER; name, number: ObxPhoneDB.String; BEGIN t := TextModels.dir.New(); (* create empty text carrier *) f.ConnectTo(t); (* connect a formatter to the text *) i := 0; ObxPhoneDB.LookupByIndex(i, name, number); WHILE name # "" DO WriteOpenFold(f, name$); (* write left fold view into text, with name as its short-form text *) (* now write the long-form text *) f.WriteString(name); (* first string *) f.WriteTab; (* tab character *) f.WriteString(number); (* second string *) WriteCloseFold(f); (* write closing fold, and swap short- and long-form texts *) f.WriteLn; (* carriage return *) INC(i); ObxPhoneDB.LookupByIndex(i, name, number) END; v := TextViews.dir.New(t); (* create a text view for the text generated above *) Views.OpenView(v) (* open the text view in its own window *) END GenReport; END ObxPDBRep3.
Obx/Mod/PDBRep3.odc
MODULE ObxPDBRep4; (** project = "BlackBox" organization = "www.oberon.ch" contributors = "Oberon microsystems" version = "System/Rsrc/About" copyright = "System/Rsrc/About" license = "Docu/BB-License" changes = " - YYYYMMDD, nn, ... " issues = " - ... " **) IMPORT Views, TextModels, TextMappers, TextViews, StdLinks, StdLog, ObxPhoneDB; CONST cmdStart = "ObxPDBRep4.Log('"; cmdEnd = "')"; PROCEDURE GenReport*; VAR t: TextModels.Model; f: TextMappers.Formatter; v: TextViews.View; i: INTEGER; name, number: ObxPhoneDB.String; link: StdLinks.Link; cmd: ARRAY 128 OF CHAR; BEGIN t := TextModels.dir.New(); (* create empty text carrier *) f.ConnectTo(t); (* connect a formatter to the text *) i := 0; ObxPhoneDB.LookupByIndex(i, name, number); WHILE name # "" DO cmd := cmdStart + name + " " + number + cmdEnd; link := StdLinks.dir.NewLink(cmd); f.WriteView(link); f.WriteString(name); (* the string shown between the pair of link views *) link := StdLinks.dir.NewLink(""); f.WriteView(link); f.WriteLn; (* carriage return *) INC(i); ObxPhoneDB.LookupByIndex(i, name, number) END; v := TextViews.dir.New(t); (* create a text view for the text generated above *) Views.OpenView(v) (* open the text view in its own window *) END GenReport; PROCEDURE Log* (param: ARRAY OF CHAR); BEGIN StdLog.String(param); StdLog.Ln END Log; END ObxPDBRep4.
Obx/Mod/PDBRep4.odc
MODULE ObxPhoneDB; (** project = "BlackBox" organization = "www.oberon.ch" contributors = "Oberon microsystems" version = "System/Rsrc/About" copyright = "System/Rsrc/About" license = "Docu/BB-License" changes = " - YYYYMMDD, nn, ... " issues = " - ... " **) CONST maxLen = 32; (* maximum length of name/number strings *) maxEntries = 5; (* maximum number of entries in the database *) TYPE String* = ARRAY maxLen OF CHAR; Entry = RECORD name, number: String END; VAR db: ARRAY maxEntries OF Entry; PROCEDURE LookupByIndex* (index: INTEGER; OUT name, number: String); BEGIN (* given an index, return the corresponding <name, number> pair *) ASSERT(index >= 0); IF index < maxEntries THEN name := db[index].name; number := db[index].number ELSE name := ""; number := "" END END LookupByIndex; PROCEDURE LookupByName* (name: String; OUT number: String); VAR i: INTEGER; BEGIN (* given a name, find the corresponding phone number *) i := 0; WHILE (i # maxEntries) & (db[i].name # name) DO INC(i) END; IF i # maxEntries THEN (* name found in db[i] *) number := db[i].number ELSE (* name not found in db[0..maxEntries-1] *) number := "" END END LookupByName; PROCEDURE LookupByNumber* (number: String; OUT name: String); VAR i: INTEGER; BEGIN (* given a phone number, find the corresponding name *) i := 0; WHILE (i # maxEntries) & (db[i].number # number) DO INC(i) END; IF i # maxEntries THEN (* number found in db[i] *) name := db[i].name ELSE (* number not found in db[0..maxEntries-1] *) name := "" END END LookupByNumber; BEGIN (* initialization of database contents *) db[0].name := "Daffy Duck"; db[0].number := "310-555-1212"; db[1].name := "Wile E. Coyote"; db[1].number := "408-555-1212"; db[2].name := "Scrooge McDuck"; db[2].number := "206-555-1212"; db[3].name := "Huey Lewis"; db[3].number := "415-555-1212"; db[4].name := "Thomas Dewey"; db[4].number := "617-555-1212" END ObxPhoneDB.
Obx/Mod/PhoneDB.odc
MODULE ObxPhoneUI; (** project = "BlackBox" organization = "www.oberon.ch" contributors = "Oberon microsystems" version = "System/Rsrc/About" copyright = "System/Rsrc/About" license = "Docu/BB-License" changes = " - YYYYMMDD, nn, ... " issues = " - ... " **) IMPORT Dialog, ObxPhoneDB; VAR phone*: RECORD name*, number*: ObxPhoneDB.String; lookupByName*: BOOLEAN END; PROCEDURE Lookup*; BEGIN IF phone.lookupByName THEN ObxPhoneDB.LookupByName(phone.name, phone.number); IF phone.number = "" THEN phone.number := "not found" END ELSE ObxPhoneDB.LookupByNumber(phone.number, phone.name); IF phone.name = "" THEN phone.name := "not found" END END; Dialog.Update(phone) END Lookup; PROCEDURE LookupGuard* (VAR par: Dialog.Par); BEGIN (* disable if input string is empty *) par.disabled := phone.lookupByName & (phone.name = "") OR ~phone.lookupByName & (phone.number = "") END LookupGuard; PROCEDURE NameGuard* (VAR par: Dialog.Par); BEGIN (* make read-only if lookup is by number *) par.readOnly := ~phone.lookupByName END NameGuard; PROCEDURE NumberGuard* (VAR par: Dialog.Par); BEGIN (* make read-only if lookup is by name *) par.readOnly := phone.lookupByName END NumberGuard; END ObxPhoneUI.
Obx/Mod/PhoneUI.odc
MODULE ObxPhoneUI1; (** project = "BlackBox" organization = "www.oberon.ch" contributors = "Oberon microsystems" version = "System/Rsrc/About" copyright = "System/Rsrc/About" license = "Docu/BB-License" changes = " - YYYYMMDD, nn, ... " issues = " - ... " **) IMPORT Dialog, ObxPhoneDB; VAR phone*: RECORD name*, number*: ObxPhoneDB.String END; PROCEDURE NameNotifier* (op, from, to: INTEGER); BEGIN ObxPhoneDB.LookupByName(phone.name, phone.number); Dialog.Update(phone) END NameNotifier; PROCEDURE NumberNotifier* (op, from, to: INTEGER); BEGIN ObxPhoneDB.LookupByNumber(phone.number, phone.name); Dialog.Update(phone) END NumberNotifier; END ObxPhoneUI1.
Obx/Mod/PhoneUI1.odc
MODULE ObxPi; (** project = "BlackBox" organization = "www.oberon.ch" contributors = "Oberon microsystems" version = "System/Rsrc/About" copyright = "System/Rsrc/About" license = "Docu/BB-License" changes = " - YYYYMMDD, nn, ... " issues = " - ... " **) IMPORT Int := Integers, StdLog; PROCEDURE Pi* (digits: INTEGER): Int.Integer; (* entier(pi * 10^digits) *) VAR p1, p2, inc, sum: Int.Integer; guard, div: INTEGER; BEGIN (* pi = 16 * atan(1/5) - 4 * atan(1/239) *) (* atan(x) = x - x^3/3 + x^5/5 - x^7/7 + ... *) guard := 8; p1 := Int.Quotient(Int.Product(Int.Power(Int.Long(10), digits + guard), Int.Long(16)), Int.Long(5)); p2 := Int.Quotient(Int.Product(Int.Power(Int.Long(10), digits + guard), Int.Long(-4)), Int.Long(239)); sum := Int.Sum(p1, p2); div := 1; REPEAT p1 := Int.Quotient(p1, Int.Long(-5 * 5)); p2 := Int.Quotient(p2, Int.Long(-239 * 239)); INC(div, 2); inc := Int.Quotient(Int.Sum(p1, p2), Int.Long(div)); sum := Int.Sum(sum, inc) UNTIL Int.Sign(inc) = 0; RETURN Int.Quotient(sum, Int.Power(Int.Long(10), guard)) END Pi; PROCEDURE WritePi* (digits: INTEGER); VAR i: Int.Integer; s: ARRAY 10000 OF CHAR; BEGIN i := Pi(digits); Int.ConvertToString(i, s); StdLog.String(s); StdLog.Ln END WritePi; END ObxPi.
Obx/Mod/Pi.odc
MODULE ObxRandom; (** project = "BlackBox" organization = "www.oberon.ch" contributors = "Oberon microsystems" version = "System/Rsrc/About" references = "Martin Reiser, Niklaus Wirth, Programming In Oberon, ISBN 0201565439" changes = " - YYYYMMDD, nn, ... " issues = " - ... " **) VAR z: INTEGER; (* global variable *) PROCEDURE Uniform* (): REAL; CONST a = 16807; m = 2147483647; q = m DIV a; r = m MOD a; VAR gamma: INTEGER; BEGIN gamma := a * (z MOD q) - r * (z DIV q); IF gamma > 0 THEN z := gamma ELSE z := gamma + m END; RETURN z * (1.0 / m) (* value of the function *) END Uniform; PROCEDURE InitSeed* (seed: INTEGER); BEGIN z := seed END InitSeed; BEGIN z := 314159 (* initial value of seed *) END ObxRandom.
Obx/Mod/Random.odc
MODULE ObxRatCalc; (** project = "BlackBox" organization = "www.oberon.ch" contributors = "Oberon microsystems" version = "System/Rsrc/About" copyright = "System/Rsrc/About" license = "Docu/BB-License" changes = " - YYYYMMDD, nn, ... " issues = " - ... " **) IMPORT Stores, Models, Dialog, TextModels, TextControllers, TextMappers, Integers; CONST (* scanner classes *) stop = 0; int = 1; openPar = 2; closePar = 3; powOp = 4; mulOp = 5; addOp = 6; approximationLength = 40; TYPE Scanner = RECORD r: TextModels.Reader; nextCh: CHAR; end, level: INTEGER; pos: INTEGER; class: INTEGER; num, den: Integers.Integer; op: CHAR; error: BOOLEAN END; Expression = POINTER TO RECORD op: CHAR; sub1, sub2: Expression; int: Integers.Integer END; VAR zero, one, ten, hundred, maxExponent, minusOne: Integers.Integer; (* scanning *) PROCEDURE ReadInteger (r: TextModels.Reader; OUT nextCh: CHAR; OUT num, den: Integers.Integer); VAR i, j, l1, l2, beg: INTEGER; ch: CHAR; buf: POINTER TO ARRAY OF CHAR; BEGIN beg := r.Pos() - 1; l1 := 0; l2 := 0; REPEAT INC(l1); r.ReadChar(ch) UNTIL r.eot OR (ch < "0") OR (ch > "9"); IF ch = "." THEN r.ReadChar(ch); WHILE (ch >= "0") & (ch <= "9") DO INC(l2); r.ReadChar(ch) END END; NEW(buf, l1 + l2 + 1); i := 0; r.SetPos(beg); REPEAT r.ReadChar(buf[i]); INC(i) UNTIL i = l1; IF l2 # 0 THEN j := l2; r.ReadChar(ch); REPEAT r.ReadChar(buf[i]); INC(i); DEC(j) UNTIL j = 0 END; buf[i] := 0X; Integers.ConvertFromString(buf^, num); IF l2 # 0 THEN buf[0] := "1"; i := 1; REPEAT buf[i] := "0"; INC(i) UNTIL i = l2 + 1; buf[i] := 0X; Integers.ConvertFromString(buf^, den) ELSE den := NIL END; r.ReadChar(nextCh) END ReadInteger; PROCEDURE (VAR s: Scanner) Read, NEW; VAR ch: CHAR; BEGIN IF ~s.error THEN ch := s.nextCh; IF s.r.eot THEN s.pos := s.r.Pos() ELSE s.pos := s.r.Pos() - 1 END; WHILE ~s.r.eot & (s.r.Pos() <= s.end) & (ch <= " ") DO s.r.ReadChar(ch) END; IF ~s.r.eot & (s.r.Pos() <= s.end) THEN IF (ch >= "0") & (ch <= "9") THEN s.class := int; ReadInteger(s.r, ch, s.num, s.den) ELSIF (ch = "+") OR (ch = "-") THEN s.class := addOp; s.op := ch; s.r.ReadChar(ch) ELSIF (ch = "*") OR (ch = "/") THEN s.class := mulOp; s.op := ch; s.r.ReadChar(ch) ELSIF ch = "^" THEN s.class := powOp; s.op := ch; s.r.ReadChar(ch) ELSIF ch = "(" THEN s.class := openPar; INC(s.level); s.r.ReadChar(ch) ELSIF ch = ")" THEN s.class := closePar; DEC(s.level); s.r.ReadChar(ch) ELSE s.error := TRUE END ELSE s.class := stop END; s.nextCh := ch ELSE s.class := stop END END Read; PROCEDURE (VAR s: Scanner) ConnectTo (t: TextModels.Model; beg, end: INTEGER), NEW; VAR ch: CHAR; BEGIN s.r := t.NewReader(NIL); s.r.SetPos(beg); s.r.ReadChar(ch); WHILE ~s.r.eot & (beg < end) & (ch <= " ") DO s.r.ReadChar(ch); INC(beg) END; s.nextCh := ch; s.pos := beg; s.end := end; s.level := 0; s.error := FALSE END ConnectTo; (* parsing *) PROCEDURE^ ReadExpression (VAR s: Scanner; OUT exp: Expression); PROCEDURE ReadFactor (VAR s: Scanner; OUT exp: Expression); VAR e: Expression; BEGIN IF s.class = openPar THEN s.Read; ReadExpression(s, exp); s.error := s.error OR (s.class # closePar); s.Read ELSIF s.class = int THEN IF s.den = NIL THEN NEW(exp); exp.op := "i"; exp.int := s.num ELSE NEW(exp); exp.op := "/"; NEW(e); e.op := "i"; e.int := s.num; exp.sub1 := e; NEW(e); e.op := "i"; e.int := s.den; exp.sub2 := e END; s.Read ELSE s.error := TRUE END; IF ~s.error & (s.class = powOp) THEN NEW(e); e.op := s.op; e.sub1 := exp; exp := e; s.Read; ReadFactor(s, e.sub2) END END ReadFactor; PROCEDURE ReadTerm (VAR s: Scanner; OUT exp: Expression); VAR e: Expression; BEGIN ReadFactor(s, exp); WHILE ~s.error & (s.class = mulOp) DO NEW(e); e.op := s.op; e.sub1 := exp; exp := e; s.Read; ReadFactor(s, exp.sub2) END END ReadTerm; PROCEDURE ReadExpression (VAR s: Scanner; OUT exp: Expression); VAR e: Expression; BEGIN IF (s.class = addOp) & (s.op = "-") THEN s.Read; NEW(e); e.op := "i"; e.int := zero; NEW(exp); exp.op := "-"; exp.sub1 := e; ReadTerm(s, exp.sub2) ELSE ReadTerm(s, exp) END; WHILE ~s.error & (s.class = addOp) DO NEW(e); e.op := s.op; e.sub1 := exp; exp := e; s.Read; ReadTerm(s, exp.sub2) END END ReadExpression; (* evaluation *) PROCEDURE Normalize (VAR num, den: Integers.Integer); VAR g: Integers.Integer; BEGIN IF Integers.Sign(num) # 0 THEN g := Integers.GCD(num, den); num := Integers.Quotient(num, g); den := Integers.Quotient(den, g); IF Integers.Sign(den) < 0 THEN num := Integers.Product(num, minusOne); den := Integers.Abs(den) END ELSE den := one END END Normalize; PROCEDURE Evaluate (exp: Expression; OUT num, den: Integers.Integer; VAR error: INTEGER); VAR exponent: INTEGER; op: CHAR; n1, d1, n2, d2, g, h: Integers.Integer; BEGIN error := 0; op := exp.op; IF op = "i" THEN num := exp.int; den := one ELSE Evaluate(exp.sub1, n1, d1, error); IF error = 0 THEN Evaluate(exp.sub2, n2, d2, error); IF error = 0 THEN IF (op = "+") OR (op = "-") THEN g := Integers.GCD(d1, d2); h := Integers.Quotient(d2, g); IF op = "+" THEN num := Integers.Sum( Integers.Product(n1, h), Integers.Product(n2, Integers.Quotient(d1, g))) ELSE num := Integers.Difference( Integers.Product(n1, h), Integers.Product(n2, Integers.Quotient(d1, g))) END; den := Integers.Product(d1, h); Normalize(num, den) ELSIF op = "*" THEN num := Integers.Product(n1, n2); den := Integers.Product(d1, d2); Normalize(num, den) ELSIF op = "/" THEN IF Integers.Sign(n2) # 0 THEN num := Integers.Product(n1, d2); den := Integers.Product(d1, n2); Normalize(num, den) ELSE error := 1 END ELSIF op = "^" THEN IF Integers.Sign(n1) = 0 THEN num := n1; den := d1 ELSE IF Integers.Compare(d2, one) = 0 THEN IF Integers.Sign(n2) = 0 THEN num := one; den := one ELSE IF Integers.Sign(n2) < 0 THEN g := n1; n1 := d1; d1 := g; n2 := Integers.Abs(n2) END; IF Integers.Compare(n2, maxExponent) <= 0 THEN exponent := SHORT(Integers.Short(n2)); num := Integers.Power(n1, exponent); den := Integers.Power(d1, exponent); Normalize(num, den) ELSE error := 3 END END ELSE error := 2 END END ELSE HALT(99) END END END END END Evaluate; (* output *) PROCEDURE WriteInteger (w: TextModels.Writer; x: Integers.Integer); VAR i: INTEGER; BEGIN IF Integers.Sign(x) # 0 THEN IF Integers.Sign(x) < 0 THEN w.WriteChar("-") END; i := Integers.Digits10Of(x); REPEAT DEC(i); w.WriteChar(Integers.ThisDigit10(x, i)) UNTIL i = 0 ELSE w.WriteChar("0") END END WriteInteger; PROCEDURE Replace (t: TextModels.Model; VAR beg, end: INTEGER; n, d: Integers.Integer; a: TextModels.Attributes); VAR s: Stores.Operation; w: TextMappers.Formatter; BEGIN Models.BeginScript(t, "computation", s); t.Delete(beg, end); w.ConnectTo(t); w.SetPos(beg); w.rider.SetAttr(a); WriteInteger(w.rider, n); IF (Integers.Sign(n) # 0) & (Integers.Compare(d, one) # 0) THEN w.WriteString(" / "); WriteInteger(w.rider, d) END; Models.EndScript(t, s); end := w.Pos() END Replace; PROCEDURE ReplaceReal (t: TextModels.Model; VAR beg, end: INTEGER; n, d: Integers.Integer; a: TextModels.Attributes); VAR i, k, e: INTEGER; q, r: Integers.Integer; s: Stores.Operation; w: TextMappers.Formatter; BEGIN Models.BeginScript(t, "computation", s); t.Delete(beg, end); w.ConnectTo(t); w.SetPos(beg); w.rider.SetAttr(a); IF Integers.Sign(n) < 0 THEN w.WriteChar("-"); n := Integers.Abs(n) END; Integers.QuoRem(n, d, q, r); k := Integers.Digits10Of(q); IF k > approximationLength THEN DEC(k); e := k; w.WriteChar(Integers.ThisDigit10(q, k)); w.WriteChar("."); i := 1; REPEAT DEC(k); w.WriteChar(Integers.ThisDigit10(q, k)); INC(i) UNTIL i = approximationLength; w.WriteString("...*10^"); w.WriteInt(e) ELSE e := 0; IF (k = 0) & (Integers.Sign(r) # 0) & (Integers.Compare(Integers.Quotient(d, r), hundred) > 0) THEN REPEAT Integers.QuoRem(Integers.Product(ten, r), d, q, r); INC(e) UNTIL Integers.Sign(q) # 0 ELSIF k = 0 THEN k := 1 END; WriteInteger(w.rider, q); IF Integers.Sign(r) # 0 THEN w.WriteChar("."); REPEAT Integers.QuoRem(Integers.Product(ten, r), d, q, r); WriteInteger(w.rider, q); INC(k) UNTIL (Integers.Sign(r) = 0) OR (k = approximationLength); IF Integers.Sign(r) # 0 THEN w.WriteString("...") END END; IF e # 0 THEN w.WriteString("*10^-"); w.WriteInt(e) END END; Models.EndScript(t, s); end := w.Pos() END ReplaceReal; (* commands *) PROCEDURE Compute (approx: BOOLEAN); VAR beg, end, error: INTEGER; exp: Expression; s: Scanner; attr: TextModels.Attributes; c: TextControllers.Controller; num, den: Integers.Integer; BEGIN c := TextControllers.Focus(); IF (c # NIL) & c.HasSelection() THEN c.GetSelection(beg, end); s.ConnectTo(c.text, beg, end); attr := s.r.attr; beg := s.pos; s.Read; ReadExpression(s, exp); end := s.pos; IF ~s.error & (s.class = stop) THEN Evaluate(exp, num, den, error); IF error = 0 THEN IF approx THEN ReplaceReal(c.text, beg, end, num, den, attr) ELSE Replace(c.text, beg, end, num, den, attr) END; c.SetSelection(beg, end) ELSIF error = 1 THEN Dialog.ShowMsg("division by zero.") ELSIF error = 2 THEN Dialog.ShowMsg("non-integer exponent.") ELSIF error = 3 THEN Dialog.ShowMsg("exponent too large.") ELSE HALT(99) END ELSE Dialog.ShowMsg("syntax error."); c.SetCaret(s.pos) END END END Compute; PROCEDURE Simplify*; BEGIN Compute(FALSE) END Simplify; PROCEDURE Approximate*; BEGIN Compute(TRUE) END Approximate; BEGIN zero := Integers.Long(0); one := Integers.Long(1); ten := Integers.Long(10); hundred := Integers.Long(100); maxExponent := Integers.Long(1000000); minusOne := Integers.Long(-1) END ObxRatCalc.
Obx/Mod/RatCalc.odc
MODULE ObxSample; (** project = "BlackBox" organization = "www.oberon.ch" contributors = "Oberon microsystems" version = "System/Rsrc/About" copyright = "System/Rsrc/About" license = "Docu/BB-License" changes = " - YYYYMMDD, nn, ... " issues = " - ... " **) TYPE File* = POINTER TO RECORD len: INTEGER (* hidden instance variable *) END; Rider* = POINTER TO RECORD (* there may be several riders on one file *) file-: File; (* read-only instance variable *) eof*: BOOLEAN; (* fully exported instance variable *) pos: INTEGER (* hidden instance variable *) (* Invariant: (pos >= 0) & (pos < file.len) *) END; PROCEDURE (f: File) GetLength* (OUT length: INTEGER), NEW; BEGIN length := f.len END GetLength; PROCEDURE (rd: Rider) SetPos* (pos: INTEGER), NEW; BEGIN (* assert invariants, so that errors may not be propagated across components *) ASSERT(pos >= 0); ASSERT(pos < rd.file.len); rd.pos := pos END SetPos; (* ... *) END ObxSample.
Obx/Mod/Sample.odc
MODULE ObxScroll; (** project = "BlackBox" organization = "www.oberon.ch" contributors = "Oberon microsystems" version = "System/Rsrc/About" copyright = "System/Rsrc/About" license = "Docu/BB-License" changes = " - YYYYMMDD, nn, ... " issues = " - ... " **) IMPORT Stores, Fonts, Ports, Views, Controllers, Properties; CONST minVersion = 0; maxVersion = 0; cellSize = 7 * Ports.mm; boardSize = 10; TYPE View = POINTER TO RECORD (Views.View) x, y: INTEGER END; PROCEDURE (v: View) Externalize (VAR wr: Stores.Writer); BEGIN wr.WriteVersion(maxVersion); wr.WriteInt(v.x); wr.WriteInt(v.y) END Externalize; PROCEDURE (v: View) Internalize (VAR rd: Stores.Reader); VAR version: INTEGER; BEGIN rd.ReadVersion(minVersion, maxVersion, version); IF ~rd.cancelled THEN rd.ReadInt(v.x); rd.ReadInt(v.y) END END Internalize; PROCEDURE (v: View) CopyFromSimpleView (source: Views.View); BEGIN WITH source: View DO v.x := source.x; v.y := source.y END END CopyFromSimpleView; PROCEDURE (v: View) Restore (f: Views.Frame; l, t, r, b: INTEGER); VAR x, y, asc, dsc, w: INTEGER; color: Ports.Color; str: ARRAY 3 OF CHAR; font: Fonts.Font; BEGIN str := "00"; font := Fonts.dir.Default(); x := l DIV cellSize; IF Views.IsPrinterFrame(f) THEN r := r - r MOD cellSize END; WHILE (x * cellSize < r) & (v.x + x < boardSize) DO y := t DIV cellSize; IF Views.IsPrinterFrame(f) THEN b := b - b MOD cellSize END; WHILE (y * cellSize < b) & (v.y + y < boardSize) DO IF ODD(x + y + v.x + v.y) THEN color := Ports.black ELSE color := Ports.white END; f.DrawRect(x * cellSize, y * cellSize, (x + 1) * cellSize, (y + 1) * cellSize, Ports.fill, color); str[0] := CHR(ORD("0") + x + v.x); str[1] := CHR(ORD("0") + y + v.y); font.GetBounds(asc, dsc, w); f.DrawString( (x * cellSize + cellSize DIV 2) - font.StringWidth(str) DIV 2, (y * cellSize + cellSize DIV 2) + asc DIV 2, Ports.red, str, font); INC(y) END; INC(x) END END Restore; PROCEDURE (v: View) HandleCtrlMsg (f: Views.Frame; VAR msg: Views.CtrlMessage; VAR focus: Views.View); VAR val, vis, w, h: INTEGER; changed: BOOLEAN; BEGIN WITH msg: Controllers.PollSectionMsg DO v.context.GetSize(w, h); msg.focus := FALSE; (* v is not a container *) IF msg.vertical THEN msg.partSize := h DIV cellSize; msg.wholeSize := boardSize + MAX(0, msg.partSize + v.y - boardSize); msg.partPos := v.y ELSE msg.partSize := w DIV cellSize; msg.wholeSize := boardSize + MAX(0, msg.partSize + v.x - boardSize); msg.partPos := v.x END; msg.valid := (msg.partSize < msg.wholeSize); msg.done := TRUE | msg: Controllers.ScrollMsg DO v.context.GetSize(w, h); changed := FALSE; msg.focus := FALSE; (* v is not a container *) IF msg.vertical THEN val := v.y; vis := h DIV cellSize ELSE val := v.x; vis := w DIV cellSize END; CASE msg.op OF Controllers.decLine: IF val > 0 THEN DEC(val); changed := TRUE END | Controllers.incLine: IF val < boardSize - vis THEN INC(val); changed := TRUE END | Controllers.decPage: DEC(val, vis); changed := TRUE; IF val < 0THEN val := 0 END | Controllers.incPage: INC(val, vis); changed := TRUE; IF val > boardSize - vis THEN val := boardSize - vis END | Controllers.gotoPos: val := msg.pos; changed := TRUE END; IF msg.vertical THEN v.y := val ELSE v.x := val END; msg.done := TRUE; IF changed THEN Views.Update(v, Views.keepFrames) END | msg: Controllers.PageMsg DO v.context.GetSize(w, h); IF msg.op IN {Controllers.nextPageY, Controllers.gotoPageY} THEN vis := h DIV cellSize ELSE vis := w DIV cellSize END; CASE msg.op OF Controllers.nextPageX: INC(v.x, vis) | Controllers.nextPageY: INC(v.y, vis) | Controllers.gotoPageX: v.x := msg.pageX * vis | Controllers.gotoPageY: v.y := msg.pageY * vis END; msg.done := TRUE; msg.eox := v.x >= boardSize; msg.eoy := v.y >= boardSize ELSE END END HandleCtrlMsg; PROCEDURE (v: View) HandlePropMsg (VAR p: Properties.Message); BEGIN WITH p: Properties.SizePref DO IF p.w = Views.undefined THEN p.w := (boardSize - v.x) * cellSize END; IF p.h = Views.undefined THEN p.h := (boardSize - v.y) * cellSize END | p: Properties.ResizePref DO p.horFitToWin := TRUE; p.verFitToWin := TRUE | p: Properties.FocusPref DO p.setFocus := TRUE ELSE (* ignore other messages *) END END HandlePropMsg; PROCEDURE Deposit*; VAR v: View; BEGIN NEW(v); v.x := 0; v.y := 0; Views.Deposit(v) END Deposit; PROCEDURE DepositAt* (x, y: INTEGER); VAR v: View; BEGIN NEW(v); v.x := 0; v.y := 0; IF (x > 0) & (x < boardSize) THEN v.x := x END; IF (y > 0) & (y < boardSize) THEN v.y := y END; Views.Deposit(v) END DepositAt; END ObxScroll.
Obx/Mod/Scroll.odc
MODULE ObxStores; (** project = "BlackBox" organization = "www.oberon.ch" contributors = "Oberon microsystems" version = "System/Rsrc/About" copyright = "System/Rsrc/About" license = "Docu/BB-License" changes = " - 20080905, dd, Node.CopyFrom: case (source.a = NIL) corrected " issues = " - ... " **) (* This example illustrates the persistency service implemented by Stores. It is shown how a graph of linked nodes can be externalized and internalized, maintaining invariants like objects refered to through multiple pointers and cycles. Stores also offeres a mechanism to just copy such a graph. To run the example, click on the commanders below: ObxStores.WriteRead ObxStores.Copy *) IMPORT Dialog, Files, Stores; TYPE Node = POINTER TO RECORD (Stores.Store) a, b: Node END; (* Methods of Node *) PROCEDURE (n: Node) Externalize (VAR w: Stores.Writer); BEGIN w.WriteStore(n.a); w.WriteStore(n.b) END Externalize; PROCEDURE (n: Node) Internalize (VAR r: Stores.Reader); VAR s: Stores.Store; BEGIN r.ReadStore(s); IF (s # NIL) & (s IS Node) THEN n.a := s(Node) ELSE n.a := NIL END; r.ReadStore(s); IF (s # NIL) & (s IS Node) THEN n.b := s(Node) ELSE n.b := NIL END END Internalize; PROCEDURE (n: Node) CopyFrom (source: Stores.Store); BEGIN WITH source: Node DO IF source.a # NIL THEN n.a := Stores.CopyOf(source.a)(Node) ELSE n.a := NIL END; IF source.b # NIL THEN n.b := Stores.CopyOf(source.b)(Node) ELSE n.b := NIL END END END CopyFrom; (* Build and check a graph of Nodes *) PROCEDURE NewGraph (): Node; VAR n: Node; BEGIN NEW(n); NEW(n.a); Stores.Join(n, n.a); NEW(n.b); Stores.Join(n, n.b); n.a.a := n.b; n.a.b := NIL; n.b.a := n.a; n.b.b := n.b; RETURN n END NewGraph; PROCEDURE GraphOk (n: Node): BOOLEAN; BEGIN RETURN (n # n.a) & (n # n.b) & (n.a # n.b) & (n.a.a = n.b) & (n.a.b = NIL) & (n.b.a = n.a) & (n.b.b = n.b) & Stores.Joined(n, n.a) & Stores.Joined(n, n.b) END GraphOk; (* Demonstrate Ex- and Internalization *) PROCEDURE WriteRead*; VAR n, m: Node; f: Files.File; w: Stores.Writer; r: Stores.Reader; s: Stores.Store; BEGIN (* allocate and check new graph *) n := NewGraph(); ASSERT(GraphOk(n), 1); (* externalize graph to a temporary file *) f := Files.dir.Temp(); w.ConnectTo(f); w.WriteStore(n); (* read graph back from file *) r.ConnectTo(f); r.ReadStore(s); m := s(Node); (* check graph to be internalized with nodes correctly linked and joined *) ASSERT(GraphOk(m), 2); Dialog.ShowMsg("WriteRead test ok.") END WriteRead; (* Demonstrate Copying *) PROCEDURE Copy*; VAR n, m: Node; BEGIN (* allocate and check new graph *) n := NewGraph(); ASSERT(GraphOk(n), 1); (* copy entire graph *) m := Stores.CopyOf(n)(Node); (* check graph to be internalized with nodes correctly linked and joined *) ASSERT(GraphOk(m), 2); Dialog.ShowMsg("Copy test ok.") END Copy; END ObxStores.
Obx/Mod/Stores.odc
MODULE ObxTabs; (** project = "BlackBox" organization = "www.oberon.ch" contributors = "Oberon microsystems" version = "System/Rsrc/About" copyright = "System/Rsrc/About" license = "Docu/BB-License" changes = " - YYYYMMDD, nn, ... " issues = " - ... " **) IMPORT Views, TextModels, TextViews, TextControllers; CONST tab = 09X; line = 0DX; VAR field: ARRAY 256 OF CHAR; PROCEDURE ReadField (r: TextModels.Reader); VAR i: INTEGER; ch: CHAR; BEGIN (* read a field, which is a sequence of characters terminated by the end of text, or a tab or line character *) i := 0; r.ReadChar(ch); WHILE ~r.eot & (ch # tab) & (ch # line) DO field[i] := ch; INC(i); r.ReadChar(ch) END; field[i] := 0X END ReadField; PROCEDURE WriteField (w: TextModels.Writer); VAR i: INTEGER; ch: CHAR; BEGIN i := 0; ch := field[0]; WHILE ch # 0X DO w.WriteChar(ch); INC(i); ch := field[i] END END WriteField; PROCEDURE Convert*; VAR c: TextControllers.Controller; t: TextModels.Model; r: TextModels.Reader; w: TextModels.Writer; beg, end: INTEGER; BEGIN c := TextControllers.Focus(); IF (c # NIL) & c.HasSelection() THEN c.GetSelection(beg, end); r := c.text.NewReader(NIL); r.SetPos(beg); t := TextModels.CloneOf(c.text); w := t.NewWriter(NIL); ReadField(r); (* title *) WHILE ~r.eot DO WriteField(w); w.WriteChar(" "); ReadField(r); WriteField(w); w.WriteChar(" "); (* first name *) ReadField(r); WriteField(w); w.WriteChar(tab); (* name *) ReadField(r); WriteField(w); w.WriteChar(tab); (* company 1 *) ReadField(r); WriteField(w); w.WriteChar(tab); (* company 2 *) ReadField(r); WriteField(w); w.WriteChar(tab); (* address *) ReadField(r); WriteField(w); w.WriteChar(" "); (* ZIP *) ReadField(r); WriteField(w); w.WriteChar(tab); (* city *) ReadField(r); WriteField(w); w.WriteChar(line); (* country *) ReadField(r) (* title *) END; Views.OpenView(TextViews.dir.New(t)) END END Convert; END ObxTabs.
Obx/Mod/Tabs.odc