texts
stringlengths 0
715k
| names
stringlengths 8
91
|
---|---|
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 = "
- YYYYMMDD, nn, ...
"
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 # NIL 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, TextModels, TextMappers, TextViews;
PROCEDURE Do*;
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; (* no defaults for Views.Old *)
v := Views.Old(Views.ask, loc, name, conv); (* ask user for a file and open it as a view *)
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 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, TextModels, TextMappers, TextViews;
PROCEDURE Do*;
VAR loc: Files.Locator; name: Files.Name; conv: Converters.Converter;
v: Views.View; t: TextModels.Model; f: TextMappers.Formatter;
res: INTEGER;
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("appendix");
Views.Register(v, Views.ask, loc, name, conv, res) (* ask the user where to save the document *)
END
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 = "
- YYYYMMDD, nn, ...
"
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.b := 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 |
MODULE ObxTabViews;
(**
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 StdTabViews, Views, Strings, Dialog, StdLog,
ObxCalc, ObxCubes;
VAR
st: StdTabViews.View;
calc: Views.View;
PROCEDURE New* (): StdTabViews.View;
VAR v: Views.View;
BEGIN
st := StdTabViews.dir.New();
calc := ObxCalc.New(); v := ObxCubes.New();
st.SetItem(0, 'Cube', v);
st.SetItem(1, 'Calc 1', calc);
st.SetItem(2, 'Calc 2', calc);
st.SetNotifier("ObxTabViews.Notify");
RETURN st
END New;
PROCEDURE Deposit*;
BEGIN
Views.Deposit(New())
END Deposit;
PROCEDURE AddNewCalc*;
VAR s: ARRAY 4 OF CHAR;
BEGIN
Strings.IntToString(st.NofTabs(), s);
st.SetItem(st.NofTabs(), 'Calc ' + s, calc)
END AddNewCalc;
PROCEDURE DeleteTab*;
VAR i: INTEGER; s: Dialog.String; v: Views.View;
BEGIN
IF st.NofTabs() > 0 THEN
FOR i := st.Index() TO st.NofTabs() - 2 DO
st.GetItem(i + 1, s, v); st.SetItem(i, s, v)
END;
st.SetNofTabs(st.NofTabs() - 1)
END
END DeleteTab;
PROCEDURE Notify* (v: StdTabViews.View; from, to: INTEGER);
BEGIN
StdLog.String("Notify: "); StdLog.Int(from); StdLog.Int(to); StdLog.Ln
END Notify;
END ObxTabViews.
| Obx/Mod/TabViews.odc |
MODULE ObxTickers;
(**
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, Ports, Properties, Services, Stores, Models;
CONST minVersion = 0; maxVersion = 0;
TYPE
Ticks = POINTER TO ARRAY OF INTEGER;
View = POINTER TO RECORD (Views.View)
ticks: Ticks;
last: INTEGER;
offset: INTEGER
END;
Action = POINTER TO RECORD (Services.Action) END;
Msg = RECORD (Models.Message)
consumed: BOOLEAN
END;
VAR
action: Action;
actionIsActive: BOOLEAN;
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;
PROCEDURE (a: Action) Do;
VAR msg: Msg;
BEGIN
msg.consumed := FALSE;
Views.Omnicast(msg);
IF msg.consumed THEN
Services.DoLater(action, Services.Ticks() + Services.resolution DIV 5)
ELSE
actionIsActive := FALSE
END
END Do;
(* view *)
PROCEDURE (v: View) Externalize (VAR wr: Stores.Writer);
VAR i, len: INTEGER;
BEGIN
wr.WriteVersion(maxVersion);
wr.WriteInt(v.offset);
wr.WriteInt(v.last);
len := LEN(v.ticks); wr.WriteInt(len);
FOR i := 0 TO len - 1 DO wr.WriteInt(v.ticks[i]) END
END Externalize;
PROCEDURE (v: View) Internalize (VAR rd: Stores.Reader);
VAR version, i, len: INTEGER;
BEGIN
rd.ReadVersion(minVersion, maxVersion, version);
IF ~rd.cancelled THEN
rd.ReadInt(v.offset);
rd.ReadInt(v.last);
rd.ReadInt(len); NEW(v.ticks, len);
FOR i := 0 TO len - 1 DO rd.ReadInt(v.ticks[i]) END
END
END Internalize;
PROCEDURE (v: View) CopyFromSimpleView (source: Views.View);
VAR i, len: INTEGER;
BEGIN
WITH source: View DO
v.offset := source.offset;
v.last := source.last;
len := LEN(source.ticks);
NEW(v.ticks, len);
FOR i := 0 TO len - 1 DO v.ticks[i] := source.ticks[i] END
END
END CopyFromSimpleView;
PROCEDURE (v: View) HandlePropMsg (VAR msg: Properties.Message);
BEGIN
WITH msg: Properties.SizePref DO
IF (msg.w = Views.undefined) OR (msg.h = Views.undefined) THEN
msg.w := 50 * Ports.mm; msg.h := 10 * Ports.mm
END
ELSE
END
END HandlePropMsg;
PROCEDURE (v: View) HandleModelMsg (VAR msg: Models.Message);
VAR len, m: INTEGER;
BEGIN
WITH msg: Msg DO
len := LEN(v.ticks);
m := v.ticks[v.last];
IF UniRand() > 0.5 THEN INC(m) ELSE DEC(m) END;
v.last := (v.last + 1) MOD len;
v.ticks[v.last] := m;
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 w, h, x, y0, ylast, p, p1, len, len2, i, j: INTEGER; ticks: Ticks;
BEGIN
IF ~actionIsActive THEN
Services.DoLater(action, Services.now);
actionIsActive := TRUE
END;
v.context.GetSize(w, h);
len := LEN(v.ticks); len2 := 1 + w DIV f.dot;
IF len2 > len THEN (* allocate new array and copy data *)
NEW(ticks, len2);
i := 0; WHILE i <= v.last DO ticks[i] := v.ticks[i]; INC(i) END;
j := i + len2 - len; WHILE i < len DO ticks[j] := v.ticks[i]; INC(i); INC(j) END;
v.ticks := ticks; len := len2
END;
(* adjust offset so that the last point is visible *)
ylast := (v.ticks[v.last] + v.offset) * f.dot;
IF ylast > h DIV 2 THEN DEC(v.offset)
ELSIF ylast < -h DIV 2 THEN INC(v.offset)
END;
p := (v.last - (len2 - 1)) MOD len; (* index of first entry *)
x := 0; y0 := h DIV 2 + v.offset * f.dot;
WHILE p # v.last DO
p1 := (p + 1) MOD len;
f.DrawLine(x, y0 + v.ticks[p] * f.dot, x + f.dot, y0 + v.ticks[p1] * f.dot, 0, Ports.red);
x := x + f.dot; p := p1
END;
f.DrawLine(l, y0, r, y0, 0, Ports.black)
END Restore;
(* commands *)
PROCEDURE Deposit*;
VAR v: View;
BEGIN
NEW(v); NEW(v.ticks, 142);
v.last := 0; v.offset := 0;
Views.Deposit(v)
END Deposit;
BEGIN
NEW(action); actionIsActive := FALSE; seed := SHORT(Services.Ticks())
END ObxTickers.
| Obx/Mod/Tickers.odc |
MODULE ObxTrap;
(**
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, Views, Controllers;
VAR global: INTEGER;
PROCEDURE Do*;
VAR i: INTEGER; str: Dialog.String; v: Views.View;
BEGIN
str := "String";
global := 13;
v := Controllers.FocusView();
i := 777;
str[i] := "*" (* index out of range, since the Dialog.String array only contains 256 elements *)
END Do;
END ObxTrap. | Obx/Mod/Trap.odc |
MODULE ObxTwins;
(**
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, Services, Stores, Models, Views, Controllers, Properties, TextViews;
CONST
minVersion = 3; maxVersion = 3; (* old versions 0 .. 2 of ObxTwin views cannot be read anymore *)
border = Ports.mm;
TYPE
Identity = POINTER TO RECORD (Models.Model) END; (* dummy model *)
Context = POINTER TO RECORD (Models.Context)
base: View; (* container view *)
view: Views.View; (* contained view *)
l, t, r, b: INTEGER (* cached bounding box of contained view *)
END;
View = POINTER TO RECORD (Views.View)
top, bottom: Context;
ident: Identity; (* temporary dummy model *)
focus: Context (* current focus; either top or bottom *)
END;
(* Context *)
PROCEDURE (c: Context) ThisModel (): Models.Model;
BEGIN
RETURN NIL (* don't give the embedded views information about the dummy twin model *)
END ThisModel;
PROCEDURE (c: Context) GetSize (OUT w, h: INTEGER);
BEGIN
w := c.r - c.l;
h := c.b - c.t
END GetSize;
PROCEDURE (c: Context) MakeVisible (l, t, r, b: INTEGER);
VAR w, h, sep: INTEGER;
BEGIN
IF c.base.top = c THEN (* top view *)
c.base.context.MakeVisible(l + border, t + border, r + border, b + border)
ELSE (* bottom view *)
c.base.context.GetSize(w, h); sep := h DIV 3;
c.base.context.MakeVisible(l + border, t + sep + border, r + border, b + sep + border)
END
END MakeVisible;
PROCEDURE (c: Context) Consider (VAR p: Models.Proposal);
BEGIN
c.base.context.Consider(p)
END Consider;
PROCEDURE (c: Context) Normalize (): BOOLEAN;
BEGIN
RETURN c.base.context.Normalize()
END Normalize;
PROCEDURE NewContext (v: Views.View; base: View): Context;
VAR c: Context;
BEGIN
NEW(c);
c.view := v; c.base := base;
v.InitContext(c); Stores.Join(v, base);
RETURN c
END NewContext;
PROCEDURE CopyOf (source: Context; shallow: BOOLEAN; base: View): Context;
VAR v: Views.View;
BEGIN
v := Views.CopyOf(source.view, shallow );
RETURN NewContext(v, base)
END CopyOf;
(* View *)
PROCEDURE RecalcLayout (v: View);
VAR w, h, sep: INTEGER; c: Context;
BEGIN
v.context.GetSize(w, h);
sep := h DIV 3; (* separate the two views at 1/3 of the container's height *)
c := v.top; c.l := border; c.t := border; c.r := w - border; c.b := sep - border;
c := v.bottom; c.l := border; c.t := sep + border; c.r := w - border; c.b := h - border
END RecalcLayout;
PROCEDURE SetFocus (v: Views.View; x, y: INTEGER): BOOLEAN;
VAR p: Properties.FocusPref;
BEGIN (* determine whether v should be focused when the mouse is clicked at (x, y) in v *)
p.hotFocus := FALSE;
p.atLocation := TRUE; p.x := x; p.y := y;
p.setFocus := FALSE;
Views.HandlePropMsg(v, p);
RETURN p.setFocus
END SetFocus;
PROCEDURE (v: View) CopyFromModelView (source: Views.View; model: Models.Model);
VAR shallow: BOOLEAN;
BEGIN
WITH source: View DO
shallow := model = source.ident; (* shallow copy if both views share the same model *)
Stores.Join(v, model);
v.top := CopyOf(source.top, shallow, v);
v.bottom := CopyOf(source.bottom, shallow, v);
v.ident := model(Identity);
v.focus := v.bottom
END
END CopyFromModelView;
PROCEDURE (v: View) Internalize (VAR rd: Stores.Reader);
VAR version: INTEGER; h: Views.View;
BEGIN
rd.ReadVersion(minVersion, maxVersion, version);
IF ~rd.cancelled THEN
Views.ReadView(rd, h); v.top := NewContext(h, v);
Views.ReadView(rd, h); v.bottom := NewContext(h, v);
NEW(v.ident); Stores.Join(v, v.ident);
v.focus := v.bottom
END
END Internalize;
PROCEDURE (v: View) Externalize (VAR wr: Stores.Writer);
BEGIN
wr.WriteVersion(maxVersion);
Views.WriteView(wr, v.top.view);
Views.WriteView(wr, v.bottom.view)
END Externalize;
PROCEDURE (v: View) Neutralize;
BEGIN
v.focus.view.Neutralize
END Neutralize;
PROCEDURE (v: View) ThisModel (): Models.Model;
BEGIN
RETURN v.ident
END ThisModel;
PROCEDURE (v: View) Restore (f: Views.Frame; l, t, r, b: INTEGER);
VAR d: INTEGER; c: Context;
BEGIN
RecalcLayout(v);
(* install the subframes for the subviews *)
c := v.top; Views.InstallFrame(f, c.view, c.l, c.t, 0, v.focus = c);
c := v.bottom; Views.InstallFrame(f, c.view, c.l, c.t, 1, v.focus = c);
(* draw frame around the subviews *)
d := 2 * f.dot;
c := v.top;
IF (c.t - d < c.b + d) & (c.l - d < c.r + d) THEN f.DrawRect(c.l - d, c.t - d, c.r + d, c.b + d, f.dot, Ports.black) END;
c := v.bottom;
IF (c.t - d < c.b + d) & (c.l - d < c.r + d) THEN f.DrawRect(c.l - d, c.t - d, c.r + d, c.b + d, f.dot, Ports.black) END
END Restore;
PROCEDURE (v: View) HandleCtrlMsg (f: Views.Frame; VAR msg: Views.CtrlMessage;
VAR focus: Views.View);
VAR g: Views.Frame; newFocus: Context; mMsg: Controllers.MarkMsg;
w, h, sep: INTEGER;
BEGIN
WITH msg: Controllers.CursorMessage DO
v.context.GetSize(w, h);
sep := h DIV 3;
IF msg.y >= sep THEN newFocus := v.bottom ELSE newFocus := v.top END;
focus := newFocus.view;
IF (newFocus # v.focus) & ((msg IS Controllers.TrackMsg) OR (msg IS Controllers.DropMsg)) &
SetFocus(focus, msg.x, msg.y) THEN
(* remove marks in old focus *)
mMsg.show := FALSE; mMsg.focus := TRUE;
g := Views.ThisFrame(f, v.focus.view); IF g # NIL THEN Views.ForwardCtrlMsg(g, mMsg) END;
v.focus := newFocus; (* set new focus *)
(* set marks in new focus *)
mMsg.show := TRUE; mMsg.focus := TRUE;
g := Views.ThisFrame(f, v.focus.view); IF g # NIL THEN Views.ForwardCtrlMsg(g, mMsg) END
END
(* the following scrolling-oriented messages are always sent to bottom view, independent of focus *)
| msg: Controllers.PollSectionMsg DO
g := Views.ThisFrame(f, v.bottom.view); IF g # NIL THEN Views.ForwardCtrlMsg(g, msg) END;
IF msg.vertical & ~msg.done THEN
msg.valid := FALSE; msg.done := TRUE (* disable default-scrolling *)
END
| msg: Controllers.ScrollMsg DO
g := Views.ThisFrame(f, v.bottom.view); IF g # NIL THEN Views.ForwardCtrlMsg(g, msg) END;
IF msg.vertical THEN msg.done := TRUE END
| msg: Controllers.PageMsg DO
focus := v.bottom.view
ELSE (* all other messages are sent to the focus, however *)
focus := v.focus.view
END
(* the assignment to focus signals that the view v wants to forward the message to the
corresponding embedded view *)
END HandleCtrlMsg;
PROCEDURE (v: View) HandlePropMsg (VAR msg: Views.PropMessage);
CONST defW = 80 * Ports.mm; defH = 60 * Ports.mm;
BEGIN
WITH msg: Properties.SizePref DO
IF msg.w = Views.undefined THEN msg.w := defW END;
IF msg.h = Views.undefined THEN msg.h := defH END
| msg: Properties.ResizePref DO
msg.verFitToWin := TRUE (* make view always as high as window *)
ELSE
Views.HandlePropMsg(v.bottom.view, msg)
END
END HandlePropMsg;
PROCEDURE (v: View) ConsiderFocusRequestBy (view: Views.View);
BEGIN
IF view = v.top.view THEN
v.focus := v.top
ELSIF view = v.bottom.view THEN
v.focus := v.bottom
ELSE
HALT(20)
END
END ConsiderFocusRequestBy;
PROCEDURE NewTwin* (top, bottom: Views.View): Views.View;
VAR v: View;
BEGIN
NEW(v);
v.top := NewContext(top, v); v.bottom := NewContext(bottom, v);
NEW(v.ident); Stores.Join(v, v.ident); v.focus := v.bottom;
RETURN v
END NewTwin;
(* example twin view with two embedded text views *)
PROCEDURE New* (): Views.View;
BEGIN
RETURN NewTwin(TextViews.dir.New(NIL), TextViews.dir.New(NIL))
END New;
PROCEDURE Deposit*;
BEGIN
Views.Deposit(New())
END Deposit;
END ObxTwins.
| Obx/Mod/Twins.odc |
MODULE ObxUnitConv;
(**
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, Dialog;
VAR
par*: RECORD metric*, inch*, point*: REAL; metricUnit*: Dialog.List END;
metricUnits: ARRAY 4 OF INTEGER;
PROCEDURE NotifyMetric* (op, from, to: INTEGER);
VAR units: REAL;
BEGIN
units := par.metric * metricUnits[par.metricUnit.index] * Ports.mm;
par.inch := units / Ports.inch; par.point := units / Ports.point;
Dialog.Update(par)
END NotifyMetric;
PROCEDURE NotifyInch* (op, from, to: INTEGER);
VAR units: REAL;
BEGIN
units := par.inch * Ports.inch;
par.metric := units / metricUnits[par.metricUnit.index] / Ports.mm; par.point := units / Ports.point;
Dialog.Update(par)
END NotifyInch;
PROCEDURE NotifyPoint* (op, from, to: INTEGER);
VAR units: REAL;
BEGIN
units := par.point * Ports.point;
par.metric := units / metricUnits[par.metricUnit.index] / Ports.mm; par.inch := units / Ports.inch;
Dialog.Update(par)
END NotifyPoint;
BEGIN
par.metricUnit.SetLen(4);
par.metricUnit.SetItem(0, "mm"); metricUnits[0] := 1;
par.metricUnit.SetItem(1, "cm"); metricUnits[1] := 10;
par.metricUnit.SetItem(2, "m"); metricUnits[2] := 1000;
par.metricUnit.SetItem(3, "km"); metricUnits[3] := 1000000
END ObxUnitConv.
| Obx/Mod/UnitConv.odc |
MODULE ObxViews0;
(**
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, Ports;
TYPE View = POINTER TO RECORD (Views.View) END;
PROCEDURE (v: View) Restore (f: Views.Frame; l, t, r, b: INTEGER);
BEGIN
f.DrawRect(l, t, r, b, Ports.fill, Ports.red)
END Restore;
PROCEDURE Deposit*;
VAR v: View;
BEGIN
NEW(v); Views.Deposit(v)
END Deposit;
END ObxViews0.
| Obx/Mod/Views0.odc |
MODULE ObxViews1;
(**
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, Ports, Properties;
TYPE View = POINTER TO RECORD (Views.View) END;
PROCEDURE (v: View) Restore (f: Views.Frame; l, t, r, b: INTEGER);
BEGIN
f.DrawRect(l, t, r, b, Ports.fill, Ports.red)
END Restore;
PROCEDURE (v: View) HandlePropMsg (VAR msg: Properties.Message);
BEGIN
WITH msg: Properties.SizePref DO
IF (msg.w = Views.undefined) OR (msg.h = Views.undefined) THEN
msg.w := 20 * Ports.mm; msg.h := 10 * Ports.mm
END
ELSE (* ignore other messages *)
END
END HandlePropMsg;
PROCEDURE Deposit*;
VAR v: View;
BEGIN
NEW(v); Views.Deposit(v)
END Deposit;
END ObxViews1.
| Obx/Mod/Views1.odc |
MODULE ObxViews10;
(**
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 Fonts, Ports, Views, Controllers, Properties;
CONST d = 20 * Ports.point;
TYPE
View = POINTER TO RECORD (Views.View)
i: INTEGER; (* position of next free slot in string *)
s: ARRAY 256 OF CHAR (* string *)
END;
PROCEDURE (v: View) Restore (f: Views.Frame; l, t, r, b: INTEGER);
BEGIN
f.DrawString(d, d, Ports.black, v.s, Fonts.dir.Default())
END Restore;
PROCEDURE (v: View) HandleCtrlMsg (f: Views.Frame;
VAR msg: Controllers.Message;
VAR focus: Views.View);
BEGIN
WITH msg: Controllers.EditMsg DO
IF msg.op = Controllers.pasteChar THEN (* accept typing *)
v.s[v.i] := msg.char; INC(v.i); v.s[v.i] := 0X; (* append character to string *)
Views.Update(v, Views.keepFrames) (* restore v in any frame that displays it *)
END
ELSE (* ignore other messages *)
END
END HandleCtrlMsg;
PROCEDURE (v:View) HandlePropMsg (VAR msg: Properties.Message);
BEGIN
WITH msg: Properties.SizePref DO
IF (msg.w = Views.undefined) OR (msg.h = Views.undefined) THEN
msg.w := 10 * d; msg.h := 2 * d
END
| msg: Properties.FocusPref DO
msg.setFocus := TRUE
ELSE
END
END HandlePropMsg;
PROCEDURE Deposit*;
VAR v: View;
BEGIN
NEW(v); v.s := ""; v.i := 0;
Views.Deposit(v)
END Deposit;
END ObxViews10.
| Obx/Mod/Views10.odc |
MODULE ObxViews11;
(**
project = "BlackBox"
organization = "www.oberon.ch"
contributors = "Oberon microsystems"
version = "System/Rsrc/About"
copyright = "System/Rsrc/About"
license = "Docu/BB-License"
purpose = "Same as ObxViews10, but the view's string can be stored and copied"
changes = "
- YYYYMMDD, nn, ...
"
issues = "
- ...
"
**)
IMPORT Fonts, Ports, Stores, Views, Controllers, Properties;
CONST d = 20 * Ports.point;
TYPE
View = POINTER TO RECORD (Views.View)
i: INTEGER; (* position of next free slot in string *)
s: ARRAY 256 OF CHAR (* string *)
END;
PROCEDURE (v: View) Internalize (VAR rd: Stores.Reader);
VAR version: INTEGER;
BEGIN
rd.ReadVersion(0, 0, version);
IF ~rd.cancelled THEN
rd.ReadInt(v.i); rd.ReadString(v.s)
END
END Internalize;
PROCEDURE (v: View) Externalize (VAR wr: Stores.Writer);
BEGIN
wr.WriteVersion(0);
wr.WriteInt(v.i); wr.WriteString(v.s)
END Externalize;
PROCEDURE (v: View) CopyFromSimpleView (source: Views.View);
BEGIN
WITH source: View DO
v.i := source.i; v.s := source.s
END
END CopyFromSimpleView;
PROCEDURE (v: View) Restore (f: Views.Frame; l, t, r, b: INTEGER);
BEGIN
f.DrawString(d, d, Ports.black, v.s, Fonts.dir.Default())
END Restore;
PROCEDURE (v: View) HandleCtrlMsg (f: Views.Frame;
VAR msg: Controllers.Message;
VAR focus: Views.View);
BEGIN
WITH msg: Controllers.EditMsg DO
IF msg.op = Controllers.pasteChar THEN (* accept typing *)
v.s[v.i] := msg.char; INC(v.i); v.s[v.i] := 0X; (* append character to string *)
Views.SetDirty(v); (* mark view's document as dirty *)
Views.Update(v, Views.keepFrames) (* restore v in any frame that displays it *)
END
ELSE (* ignore other messages *)
END
END HandleCtrlMsg;
PROCEDURE (v:View) HandlePropMsg (VAR msg: Properties.Message);
BEGIN
WITH msg: Properties.SizePref DO
IF (msg.w = Views.undefined) OR (msg.h = Views.undefined) THEN
msg.w := 10 * d; msg.h := 2 * d
END
| msg: Properties.FocusPref DO
msg.setFocus := TRUE
ELSE
END
END HandlePropMsg;
PROCEDURE Deposit*;
VAR v: View;
BEGIN
NEW(v); v.s := ""; v.i := 0;
Views.Deposit(v)
END Deposit;
END ObxViews11.
| Obx/Mod/Views11.odc |
MODULE ObxViews12;
(**
project = "BlackBox"
organization = "www.oberon.ch"
contributors = "Oberon microsystems"
version = "System/Rsrc/About"
copyright = "System/Rsrc/About"
license = "Docu/BB-License"
purpose = "Same as ObxViews11, but uses a separate model for the string"
changes = "
- YYYYMMDD, nn, ...
"
issues = "
- ...
"
**)
IMPORT Fonts, Ports, Stores, Models, Views, Controllers, Properties;
CONST d = 20 * Ports.point;
TYPE
Model = POINTER TO RECORD (Models.Model)
i: INTEGER; (* position of next free slot in string *)
s: ARRAY 256 OF CHAR (* string *)
END;
View = POINTER TO RECORD (Views.View)
model: Model
END;
(* Model *)
PROCEDURE (m: Model) Internalize (VAR rd: Stores.Reader);
VAR version: INTEGER;
BEGIN
rd.ReadVersion(0, 0, version);
IF ~rd.cancelled THEN
rd.ReadInt(m.i); rd.ReadString(m.s)
END
END Internalize;
PROCEDURE (m: Model) Externalize (VAR wr: Stores.Writer);
BEGIN
wr.WriteVersion(0);
wr.WriteInt(m.i); wr.WriteString(m.s)
END Externalize;
PROCEDURE (m: Model) CopyFrom (source: Stores.Store);
BEGIN
WITH source: Model DO
m.i := source.i; m.s := source.s
END
END CopyFrom;
(* View *)
PROCEDURE (v: View) Internalize (VAR rd: Stores.Reader);
VAR version: INTEGER; st: Stores.Store;
BEGIN
rd.ReadVersion(0, 0, version);
IF ~rd.cancelled THEN
rd.ReadStore(st);
v.model := st(Model)
END
END Internalize;
PROCEDURE (v: View) Externalize (VAR wr: Stores.Writer);
BEGIN
wr.WriteVersion(0);
wr.WriteStore(v.model)
END Externalize;
PROCEDURE (v: View) CopyFromModelView (source: Views.View; model: Models.Model);
BEGIN
v.model := model(Model)
END CopyFromModelView;
PROCEDURE (v: View) Restore (f: Views.Frame; l, t, r, b: INTEGER);
BEGIN
f.DrawString(d, d, Ports.black, v.model.s, Fonts.dir.Default())
END Restore;
PROCEDURE (v: View) ThisModel (): Models.Model;
BEGIN
RETURN v.model
END ThisModel;
PROCEDURE (v: View) HandleModelMsg (VAR msg: Models.Message);
BEGIN
Views.Update(v, Views.keepFrames) (* restore v in any frame that displays it *)
END HandleModelMsg;
PROCEDURE (v: View) HandleCtrlMsg (f: Views.Frame;
VAR msg: Controllers.Message;
VAR focus: Views.View);
VAR m: Model; umsg: Models.UpdateMsg;
BEGIN
WITH msg: Controllers.EditMsg DO
IF msg.op = Controllers.pasteChar THEN
m := v.model;
m.s[m.i] := msg.char; INC(m.i);
m.s[m.i] := 0X; (* append character to string *)
Views.SetDirty(v); (* mark view's document as dirty *)
Models.Broadcast(m, umsg) (* update all views on this model *)
END
ELSE (* ignore other messages *)
END
END HandleCtrlMsg;
PROCEDURE (v:View) HandlePropMsg (VAR msg: Properties.Message);
BEGIN
WITH msg: Properties.SizePref DO
IF (msg.w = Views.undefined) OR (msg.h = Views.undefined) THEN
msg.w := 10 * d; msg.h := 2 * d
END
| msg: Properties.FocusPref DO
msg.setFocus := TRUE
ELSE
END
END HandlePropMsg;
PROCEDURE Deposit*;
VAR v: View; m: Model;
BEGIN
NEW(m); m.i := 0; m.s := "";
NEW(v); v.model := m; Stores.Join(v, m);
Views.Deposit(v)
END Deposit;
END ObxViews12.
| Obx/Mod/Views12.odc |
MODULE ObxViews13;
(**
project = "BlackBox"
organization = "www.oberon.ch"
contributors = "Oberon microsystems"
version = "System/Rsrc/About"
copyright = "System/Rsrc/About"
license = "Docu/BB-License"
purpose = "Same as ObxViews12, but generate undoable operations for character insertion"
changes = "
- YYYYMMDD, nn, ...
"
issues = "
- ...
"
**)
IMPORT Fonts, Ports, Stores, Models, Views, Controllers, Properties;
CONST d = 20 * Ports.point;
TYPE
Model = POINTER TO RECORD (Models.Model)
i: INTEGER; (* position of next free slot in string *)
s: ARRAY 256 OF CHAR (* string *)
END;
View = POINTER TO RECORD (Views.View)
model: Model
END;
PasteCharOp = POINTER TO RECORD (Stores.Operation)
model: Model;
char: CHAR;
do: BOOLEAN
END;
(* PasteCharOp *)
PROCEDURE (op: PasteCharOp) Do;
VAR m: Model; msg: Models.UpdateMsg;
BEGIN
m := op.model;
IF op.do THEN (* do operation's transformation *)
m.s[m.i] := op.char; INC(m.i) (* insert character into string *)
ELSE (* undo operation's transformation *)
DEC(m.i) (* remove character from string *)
END;
m.s[m.i] := 0X;
op.do := ~op.do; (* toggle between "do" and "undo" *)
Models.Broadcast(m, msg) (* update all views on this model *)
END Do;
PROCEDURE NewPasteCharOp (m: Model; char: CHAR): PasteCharOp;
VAR op: PasteCharOp;
BEGIN
NEW(op); op.model := m; op.char := char; op.do := TRUE;
RETURN op
END NewPasteCharOp;
(* Model *)
PROCEDURE (m: Model) Internalize (VAR rd: Stores.Reader);
VAR version: INTEGER;
BEGIN
rd.ReadVersion(0, 0, version);
IF ~rd.cancelled THEN
rd.ReadInt(m.i); rd.ReadString(m.s)
END
END Internalize;
PROCEDURE (m: Model) Externalize (VAR wr: Stores.Writer);
BEGIN
wr.WriteVersion(0);
wr.WriteInt(m.i); wr.WriteString(m.s)
END Externalize;
PROCEDURE (m: Model) CopyFrom (source: Stores.Store);
BEGIN
WITH source: Model DO
m.i := source.i; m.s := source.s
END
END CopyFrom;
(* View *)
PROCEDURE (v: View) Internalize (VAR rd: Stores.Reader);
VAR version: INTEGER; st: Stores.Store;
BEGIN
rd.ReadVersion(0, 0, version);
IF ~rd.cancelled THEN
rd.ReadStore(st);
v.model := st(Model)
END
END Internalize;
PROCEDURE (v: View) Externalize (VAR wr: Stores.Writer);
BEGIN
wr.WriteVersion(0);
wr.WriteStore(v.model)
END Externalize;
PROCEDURE (v: View) CopyFromModelView (source: Views.View; model: Models.Model);
BEGIN
v.model := model(Model)
END CopyFromModelView;
PROCEDURE (v: View) Restore (f: Views.Frame; l, t, r, b: INTEGER);
BEGIN
f.DrawString(d, d, Ports.black, v.model.s, Fonts.dir.Default())
END Restore;
PROCEDURE (v: View) ThisModel (): Models.Model;
BEGIN
RETURN v.model
END ThisModel;
PROCEDURE (v: View) HandleModelMsg (VAR msg: Models.Message);
BEGIN
Views.Update(v, Views.keepFrames) (* restore v in any frame that displays it *)
END HandleModelMsg;
PROCEDURE (v: View) HandleCtrlMsg (f: Views.Frame;
VAR msg: Controllers.Message;
VAR focus: Views.View);
VAR op: Stores.Operation;
BEGIN
WITH msg: Controllers.EditMsg DO
IF msg.op = Controllers.pasteChar THEN
op := NewPasteCharOp(v.model, msg.char); (* generate operation *)
Models.Do(v.model, "Typing", op) (* execute operation *)
END
ELSE (* ignore other messages *)
END
END HandleCtrlMsg;
PROCEDURE (v:View) HandlePropMsg (VAR msg: Properties.Message);
BEGIN
WITH msg: Properties.SizePref DO
IF (msg.w = Views.undefined) OR (msg.h = Views.undefined) THEN
msg.w := 10 * d; msg.h := 2 * d
END
| msg: Properties.FocusPref DO
msg.setFocus := TRUE
ELSE
END
END HandlePropMsg;
PROCEDURE Deposit*;
VAR v: View; m: Model;
BEGIN
NEW(m); m.i := 0; m.s := "";
NEW(v); v.model := m; Stores.Join(v, m);
Views.Deposit(v)
END Deposit;
END ObxViews13.
| Obx/Mod/Views13.odc |
MODULE ObxViews14;
(**
project = "BlackBox"
organization = "www.oberon.ch"
contributors = "Oberon microsystems"
version = "System/Rsrc/About"
copyright = "System/Rsrc/About"
license = "Docu/BB-License"
purpose = "Same as ObxViews13, but interfaces and implementations separated,
and operation directly in Insert procedure"
changes = "
- YYYYMMDD, nn, ...
"
issues = "
- ...
"
**)
IMPORT Fonts, Ports, Stores, Models, Views, Controllers, Properties;
CONST d = 20 * Ports.point;
TYPE
Model* = POINTER TO ABSTRACT RECORD (Models.Model) END;
ModelDirectory* = POINTER TO ABSTRACT RECORD END;
View* = POINTER TO ABSTRACT RECORD (Views.View) END;
Directory* = POINTER TO ABSTRACT RECORD END;
StdModel = POINTER TO RECORD (Model)
i: INTEGER; (* position of next free slot in string *)
s: ARRAY 256 OF CHAR (* string *)
END;
StdModelDirectory = POINTER TO RECORD (ModelDirectory) END;
StdView = POINTER TO RECORD (View)
model: Model
END;
StdDirectory = POINTER TO RECORD (Directory) END;
PasteCharOp = POINTER TO RECORD (Stores.Operation)
model: StdModel;
char: CHAR;
do: BOOLEAN
END;
VAR
mdir-: ModelDirectory;
dir-: Directory;
(* Model *)
PROCEDURE (m: Model) Insert* (char: CHAR), NEW, ABSTRACT;
PROCEDURE (m: Model) Remove*, NEW, ABSTRACT;
PROCEDURE (m: Model) GetString* (OUT s: ARRAY OF CHAR), NEW, ABSTRACT;
(* ModelDirectory *)
PROCEDURE (d: ModelDirectory) New* (): Model, NEW, ABSTRACT;
(* PasteCharOp *)
PROCEDURE (op: PasteCharOp) Do;
VAR m: StdModel; msg: Models.UpdateMsg;
BEGIN
m := op.model;
IF op.do THEN (* do operation's transformation *)
m.s[m.i] := op.char; INC(m.i);
ELSE (* undo operation's transformation *)
DEC(m.i) (* remove character from string *)
END;
m.s[m.i] := 0X;
op.do := ~op.do; (* toggle between "do" and "undo" *)
Models.Broadcast(m, msg) (* update all views on this model *)
END Do;
(* StdModel *)
PROCEDURE (m: StdModel) Internalize (VAR rd: Stores.Reader);
VAR version: INTEGER;
BEGIN
rd.ReadVersion(0, 0, version);
IF ~rd.cancelled THEN
rd.ReadInt(m.i); rd.ReadString(m.s)
END
END Internalize;
PROCEDURE (m: StdModel) Externalize (VAR wr: Stores.Writer);
BEGIN
wr.WriteVersion(0);
wr.WriteInt(m.i); wr.WriteString(m.s)
END Externalize;
PROCEDURE (m: StdModel) CopyFrom (source: Stores.Store);
BEGIN
WITH source: StdModel DO
m.i := source.i; m.s := source.s
END
END CopyFrom;
PROCEDURE (m: StdModel) Insert (char: CHAR);
VAR op: PasteCharOp;
BEGIN
NEW(op); op.model := m; op.char := char; op.do := TRUE;
Models.Do(m, "insertion", op)
END Insert;
PROCEDURE (m: StdModel) Remove;
VAR msg: Models.UpdateMsg;
BEGIN
DEC(m.i); m.s[m.i] := 0X;
Models.Broadcast(m, msg) (* update all views on this model *)
END Remove;
PROCEDURE (m: StdModel) GetString (OUT s: ARRAY OF CHAR);
BEGIN
s := m.s$
END GetString;
(* StdModelDirectory *)
PROCEDURE (d: StdModelDirectory) New (): Model;
VAR m: StdModel;
BEGIN
NEW(m); m.s := ""; m.i := 0; RETURN m
END New;
(* Directory *)
PROCEDURE (d: Directory) New* (m: Model): View, NEW, ABSTRACT;
(* StdView *)
PROCEDURE (v: StdView) Internalize (VAR rd: Stores.Reader);
VAR version: INTEGER; st: Stores.Store;
BEGIN
rd.ReadVersion(0, 0, version);
IF ~rd.cancelled THEN
rd.ReadStore(st);
IF st IS Model THEN
v.model := st(Model)
ELSE
(* concrete model implementation couldn't be loaded->
an alien store was created *)
rd.TurnIntoAlien(Stores.alienComponent)
(* internalization of v is cancelled *)
END
END
END Internalize;
PROCEDURE (v: StdView) Externalize (VAR wr: Stores.Writer);
BEGIN
wr.WriteVersion(0);
wr.WriteStore(v.model)
END Externalize;
PROCEDURE (v: StdView) CopyFromModelView (source: Views.View; model: Models.Model);
BEGIN
WITH source: StdView DO
v.model := model(Model)
END
END CopyFromModelView;
PROCEDURE (v: StdView) Restore (f: Views.Frame; l, t, r, b: INTEGER);
VAR s: ARRAY 256 OF CHAR;
BEGIN
v.model.GetString(s);
f.DrawString(d, d, Ports.black, s, Fonts.dir.Default())
END Restore;
PROCEDURE (v: StdView) ThisModel (): Models.Model;
BEGIN
RETURN v.model
END ThisModel;
PROCEDURE (v: StdView) HandleModelMsg (VAR msg: Models.Message);
BEGIN
Views.Update(v, Views.keepFrames) (* restore v in any frame that displays it *)
END HandleModelMsg;
PROCEDURE (v: StdView) HandleCtrlMsg (f: Views.Frame;
VAR msg: Controllers.Message;
VAR focus: Views.View);
BEGIN
WITH msg: Controllers.EditMsg DO
IF msg.op = Controllers.pasteChar THEN
v.model.Insert(msg.char)
END
ELSE (* ignore other messages *)
END
END HandleCtrlMsg;
PROCEDURE (v:StdView) HandlePropMsg (VAR msg: Properties.Message);
BEGIN
WITH msg: Properties.SizePref DO
IF (msg.w = Views.undefined) OR (msg.h = Views.undefined) THEN
msg.w := 10 * d; msg.h := 2 *d
END
| msg: Properties.FocusPref DO
msg.setFocus := TRUE
ELSE
END
END HandlePropMsg;
(* StdDirectory *)
PROCEDURE (d: StdDirectory) New* (m: Model): View;
VAR v: StdView;
BEGIN
ASSERT(m # NIL, 20);
NEW(v); v.model := m; Stores.Join(v, m);
RETURN v
END New;
PROCEDURE Deposit*;
VAR v: View;
BEGIN
v := dir.New(mdir.New());
Views.Deposit(v)
END Deposit;
PROCEDURE SetModelDir* (d: ModelDirectory);
BEGIN
ASSERT(d # NIL, 20);
mdir := d
END SetModelDir;
PROCEDURE SetDir* (d: Directory);
BEGIN
ASSERT(d # NIL, 20);
dir := d
END SetDir;
PROCEDURE Init;
VAR md: StdModelDirectory; d: StdDirectory;
BEGIN
NEW(md); mdir := md;
NEW(d); dir := d
END Init;
BEGIN
Init
END ObxViews14.
| Obx/Mod/Views14.odc |
MODULE ObxViews2;
(**
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, Ports, Properties;
TYPE View = POINTER TO RECORD (Views.View) END;
PROCEDURE (v: View) Restore (f: Views.Frame; l, t, r, b: INTEGER);
BEGIN
f.DrawRect(l, t, r, b, Ports.fill, Ports.red)
END Restore;
PROCEDURE (v: View) HandlePropMsg (VAR msg: Properties.Message);
CONST min = 5 * Ports.mm; max = 50 * Ports.mm;
BEGIN
WITH msg: Properties.SizePref DO
IF (msg.w = Views.undefined) OR (msg.h = Views.undefined) THEN
msg.w := 20 * Ports.mm; msg.h := 10 * Ports.mm
ELSE
Properties.ProportionalConstraint(2, 1, msg.fixedW, msg.fixedH,
msg.w, msg.h);
IF msg.h < min THEN
msg.h := min; msg.w := 2 * min
ELSIF msg.h > max THEN
msg.h := max; msg.w := 2 * max
END
END
ELSE (* ignore other messages *)
END
END HandlePropMsg;
PROCEDURE Deposit*;
VAR v: View;
BEGIN
NEW(v); Views.Deposit(v)
END Deposit;
END ObxViews2.
| Obx/Mod/Views2.odc |
MODULE ObxViews3;
(**
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, Ports, Properties;
TYPE View = POINTER TO RECORD (Views.View) END;
PROCEDURE (v: View) Restore (f: Views.Frame; l, t, r, b: INTEGER);
BEGIN
f.DrawRect(l, t, r, b, Ports.fill, Ports.red)
END Restore;
PROCEDURE (v: View) HandlePropMsg (VAR msg: Properties.Message);
CONST min = 5 * Ports.mm; max = 50 * Ports.mm;
BEGIN
WITH msg: Properties.SizePref DO
IF (msg.w = Views.undefined) OR (msg.h = Views.undefined) THEN
msg.w := 20 * Ports.mm; msg.h := 10 * Ports.mm
ELSE
Properties.ProportionalConstraint(2, 1, msg.fixedW, msg.fixedH,
msg.w, msg.h);
IF msg.h < min THEN
msg.h := min; msg.w := 2 * min
ELSIF msg.h > max THEN
msg.h := max; msg.w := 2 * max
END
END
| msg: Properties.ResizePref DO
msg.horFitToWin := TRUE; msg.verFitToWin := TRUE
ELSE (* ignore other messages *)
END
END HandlePropMsg;
PROCEDURE Deposit*;
VAR v: View;
BEGIN
NEW(v); Views.Deposit(v)
END Deposit;
END ObxViews3.
| Obx/Mod/Views3.odc |
MODULE ObxViews4;
(**
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, Ports, Properties, Controllers;
TYPE View = POINTER TO RECORD (Views.View) END;
PROCEDURE (v: View) Restore (f: Views.Frame; l, t, r, b: INTEGER);
BEGIN
f.DrawRect(l, t, r, b, Ports.fill, Ports.red)
END Restore;
PROCEDURE (v: View) HandlePropMsg (VAR msg: Properties.Message);
CONST min = 5 * Ports.mm; max = 50 * Ports.mm;
BEGIN
WITH msg: Properties.SizePref DO
IF (msg.w = Views.undefined) OR (msg.h = Views.undefined) THEN
msg.w := 20 * Ports.mm; msg.h := 10 * Ports.mm
ELSE
Properties.ProportionalConstraint(2, 1, msg.fixedW, msg.fixedH,
msg.w, msg.h);
IF msg.h < min THEN
msg.h := min; msg.w := 2 * min
ELSIF msg.h > max THEN
msg.h := max; msg.w := 2 * max
END
END
| msg: Properties.ResizePref DO
msg.horFitToWin := TRUE; msg.verFitToWin := TRUE
| msg: Properties.FocusPref DO
msg.setFocus := TRUE
ELSE (* ignore other messages *)
END
END HandlePropMsg;
PROCEDURE (v: View) HandleCtrlMsg (f: Views.Frame;
VAR msg: Controllers.Message; VAR focus: Views.View);
BEGIN
WITH msg: Controllers.PollOpsMsg DO
msg.valid := {Controllers.paste}; msg.selectable := TRUE;
msg.type := "Obx.Tutorial"
ELSE (* ignore other messages *)
END
END HandleCtrlMsg;
PROCEDURE Deposit*;
VAR v: View;
BEGIN
NEW(v); Views.Deposit(v)
END Deposit;
END ObxViews4.
| Obx/Mod/Views4.odc |
MODULE ObxViews5;
(**
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, Ports, Properties, Controllers;
TYPE
View = POINTER TO RECORD (Views.View)
x, y: INTEGER
END;
PROCEDURE (v: View) Restore (f: Views.Frame; l, t, r, b: INTEGER);
BEGIN
f.DrawRect(l, t, r, b, Ports.fill, Ports.red);
f.DrawLine(v.x, t, v.x, b, 0, Ports.white); f.DrawLine(l, v.y, r, v.y, 0, Ports.white)
END Restore;
PROCEDURE (v: View) HandlePropMsg (VAR msg: Properties.Message);
CONST min = 5 * Ports.mm; max = 50 * Ports.mm;
BEGIN
WITH msg: Properties.SizePref DO
IF (msg.w = Views.undefined) OR (msg.h = Views.undefined) THEN
msg.w := 20 * Ports.mm; msg.h := 10 * Ports.mm
ELSE
Properties.ProportionalConstraint(2, 1, msg.fixedW, msg.fixedH,
msg.w, msg.h);
IF msg.h < min THEN msg.h := min; msg.w := 2 * min
ELSIF msg.h > max THEN msg.h := max; msg.w := 2 * max
END
END
| msg: Properties.ResizePref DO
msg.horFitToWin := TRUE; msg.verFitToWin := TRUE
| msg: Properties.FocusPref DO
msg.setFocus := TRUE
ELSE (* ignore other messages *)
END
END HandlePropMsg;
PROCEDURE (v: View) HandleCtrlMsg (f: Views.Frame;
VAR msg: Controllers.Message;
VAR focus: Views.View);
VAR x, y, w, h: INTEGER; m: SET; isDown: BOOLEAN;
BEGIN
WITH msg: Controllers.PollOpsMsg DO
msg.valid := {Controllers.paste}; msg.selectable := TRUE;
msg.type := "Obx.Tutorial"
| msg: Controllers.EditMsg DO
IF msg.op = Controllers.pasteChar THEN (* cursor keys *)
IF msg.char = 1DX THEN INC(v.x, Ports.mm)
ELSIF msg.char = 1CX THEN DEC(v.x, Ports.mm)
ELSIF msg.char = 1EX THEN DEC(v.y, Ports.mm)
ELSIF msg.char = 1FX THEN INC(v.y, Ports.mm)
END;
Views.Update(v, Views.keepFrames)
END
| msg: Controllers.TrackMsg DO
v.x := msg.x; v.y := msg.y;
v.context.GetSize(w, h); v.Restore(f, 0, 0, w, h);
REPEAT
f.Input(x, y, m, isDown);
IF (x # v.x) OR (y # v.y) THEN
v.x := x; v.y := y; v.Restore(f, 0, 0, w, h)
END
UNTIL ~isDown;
Views.Update(v, Views.keepFrames)
| msg: Controllers.PollCursorMsg DO
msg.cursor := Ports.graphicsCursor
ELSE (* ignore other messages *)
END
END HandleCtrlMsg;
PROCEDURE Deposit*;
VAR v: View;
BEGIN
NEW(v); v.x := 0; v.y := 0; Views.Deposit(v)
END Deposit;
END ObxViews5.
| Obx/Mod/Views5.odc |
MODULE ObxViews6;
(**
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, Ports, Properties, Controllers;
TYPE
View = POINTER TO RECORD (Views.View)
x, y: INTEGER;
c: Ports.Color
END;
PROCEDURE (v: View) Restore (f: Views.Frame; l, t, r, b: INTEGER);
BEGIN
f.DrawRect(l, t, r, b, Ports.fill, v.c);
f.DrawLine(v.x, t, v.x, b, 0, Ports.white); f.DrawLine(l, v.y, r, v.y, 0, Ports.white)
END Restore;
PROCEDURE (v: View) HandlePropMsg (VAR msg: Properties.Message);
CONST min = 5 * Ports.mm; max = 50 * Ports.mm;
VAR stdProp: Properties.StdProp; prop: Properties.Property;
BEGIN
WITH msg: Properties.SizePref DO
IF (msg.w = Views.undefined) OR (msg.h = Views.undefined) THEN
msg.w := 20 * Ports.mm; msg.h := 10 * Ports.mm
ELSE
Properties.ProportionalConstraint(2, 1, msg.fixedW, msg.fixedH,
msg.w, msg.h);
IF msg.h < min THEN msg.h := min; msg.w := 2 * min
ELSIF msg.h > max THEN msg.h := max; msg.w := 2 * max
END
END
| msg: Properties.ResizePref DO
msg.horFitToWin := TRUE; msg.verFitToWin := TRUE
| msg: Properties.FocusPref DO
msg.setFocus := TRUE
| msg: Properties.PollMsg DO
NEW(stdProp);
stdProp.color.val := v.c;
stdProp.valid := {Properties.color};
stdProp.known := {Properties.color};
Properties.Insert(msg.prop, stdProp)
| msg: Properties.SetMsg DO
prop := msg.prop;
WHILE prop # NIL DO
WITH prop: Properties.StdProp DO
IF Properties.color IN prop.valid THEN v.c := prop.color.val END
ELSE
END;
prop := prop.next
END;
Views.Update(v, Views.keepFrames)
ELSE (* ignore other messages *)
END
END HandlePropMsg;
PROCEDURE (v: View) HandleCtrlMsg (f: Views.Frame;
VAR msg: Controllers.Message;
VAR focus: Views.View);
VAR x, y, w, h: INTEGER; m: SET; isDown: BOOLEAN;
BEGIN
WITH msg: Controllers.PollOpsMsg DO
msg.valid := {Controllers.paste}; msg.selectable := TRUE;
msg.type := "Obx.Tutorial"
| msg: Controllers.EditMsg DO
IF msg.op = Controllers.pasteChar THEN
IF msg.char = 1DX THEN INC(v.x, Ports.mm)
ELSIF msg.char = 1CX THEN DEC(v.x, Ports.mm)
ELSIF msg.char = 1EX THEN DEC(v.y, Ports.mm)
ELSIF msg.char = 1FX THEN INC(v.y, Ports.mm)
END;
Views.Update(v, Views.keepFrames)
END
| msg: Controllers.TrackMsg DO
v.x := msg.x; v.y := msg.y; v.context.GetSize(w, h); v.Restore(f, 0, 0, w, h);
REPEAT
f.Input(x, y, m, isDown);
IF (x # v.x) OR (y # v.y) THEN
v.x := x; v.y := y; v.Restore(f, 0, 0, w, h)
END
UNTIL ~isDown;
Views.Update(v, Views.keepFrames)
| msg: Controllers.PollCursorMsg DO
msg.cursor := Ports.graphicsCursor
ELSE (* ignore other messages *)
END
END HandleCtrlMsg;
PROCEDURE Deposit*;
VAR v: View;
BEGIN
NEW(v); v.x := 0; v.y := 0; v.c := Ports.black; Views.Deposit(v)
END Deposit;
END ObxViews6.
| Obx/Mod/Views6.odc |
MODULE ObxWordEdit;
(**
project = "BlackBox"
organization = "www.oberon.ch"
contributors = "Oberon microsystems"
version = "System/Rsrc/About"
copyright = "System/Rsrc/About"
license = "Docu/BB-License"
purpose = "Some examples of how the Word Automation Interface 9.0 can be used."
changes = "
- YYYYMMDD, nn, ...
"
issues = "
- ...
"
**)
IMPORT CtlWord9, CtlT, StdLog, Fonts, Services;
VAR
app: CtlWord9.Application;
connectDoc: CtlWord9.Document;
PROCEDURE GetApplication (): CtlWord9.Application;
BEGIN
RETURN app
END GetApplication;
(* Connecting / Disconnecting *)
PROCEDURE Connect*;
(* Connects to a Word application. If Word is not running, it is started. *)
BEGIN
connectDoc := CtlWord9.NewDocument();
connectDoc.Windows().Item(CtlT.Int(1)).PUTVisible(FALSE);
app := connectDoc.Application();
StdLog.String(' Connected to Word.'); StdLog.Ln()
END Connect;
PROCEDURE Disconnect*;
(* Disconnects from Word. If nobody else is using the application, it is terminated. *)
BEGIN
connectDoc.Close(NIL, NIL, NIL);
app := NIL;
StdLog.String(' Disconnected to Word.'); StdLog.Ln()
END Disconnect;
(* Starting / Quitting *)
PROCEDURE Start*;
(* Starts a new Word application. *)
BEGIN
app := CtlWord9.NewApplication();
app.Options().PUTSmartCutPaste(FALSE);
app.PUTVisible(TRUE);
StdLog.String(' Word started.'); StdLog.Ln()
END Start;
PROCEDURE Quit*;
(* Quits Word. *)
BEGIN
app.Quit(CtlT.Bool(FALSE),NIL,NIL); app := NIL;
StdLog.String(' Word quited.'); StdLog.Ln()
END Quit;
PROCEDURE Restart*;
(* Restarts Word. *)
BEGIN
Quit; Start
END Restart;
(* File *)
PROCEDURE NewDoc*;
(* Creates a new document using CtlWord9.NewDocument() and makes it visible. *)
(* The document is created in the oldest running Word. If there is no Word running, it is started. *)
VAR doc: CtlWord9.Document;
BEGIN
doc := CtlWord9.NewDocument();
doc.Windows().Item(CtlT.Int(1)).PUTVisible(TRUE);
StdLog.String("New Document created. "); StdLog.Ln
END NewDoc;
PROCEDURE CreateDoc*;
(* Creates a new, visible document using CtlWord9.Application.Documents().Add. *)
(* It is only visible, if the application is visible. *)
VAR doc: CtlWord9.Document;
BEGIN
doc := GetApplication().Documents().Add(NIL, NIL, NIL, CtlT.Bool(TRUE));
StdLog.String(' Document '); StdLog.String(doc.FullName());
StdLog.String(' created.'); StdLog.Ln
END CreateDoc;
PROCEDURE CreateInvisibleDoc*;
(* Creates a new, invisible document. It is also invisible, if the application is visible. *)
VAR doc: CtlWord9.Document;
BEGIN
doc := GetApplication().Documents().Add(NIL, NIL, NIL, CtlT.Bool(FALSE));
StdLog.String(' Document '); StdLog.String(doc.FullName());
StdLog.String(' created invisible.'); StdLog.Ln
END CreateInvisibleDoc;
PROCEDURE OpenDoc (filename: ARRAY OF CHAR);
(* Opens the file filename. *)
VAR doc: CtlWord9.Document;
BEGIN
doc := GetApplication().Documents().Open(CtlT.Str(filename),NIL,NIL,NIL,NIL,NIL,NIL,NIL,NIL,NIL,NIL,NIL);
StdLog.String(' Document '); StdLog.String(doc.FullName());
StdLog.String(' opened.'); StdLog.Ln
END OpenDoc;
PROCEDURE OpenDocTest*;
(* Opens a test file. *)
BEGIN
OpenDoc('D:\Users\Juerg\test.doc')
END OpenDocTest;
PROCEDURE CloseDoc*;
(* Closes the active document without saving. *)
VAR doc: CtlWord9.Document; name: CtlT.Strg;
BEGIN
doc := GetApplication().ActiveDocument();
name := doc.FullName();
doc.Close(CtlT.Int(CtlWord9.wdDoNotSaveChanges),NIL,NIL);
StdLog.String(' Document '); StdLog.String(name);
StdLog.String(' closed.'); StdLog.Ln
END CloseDoc;
PROCEDURE SaveAndCloseDoc*;
(* Saves the active document and closes it. *)
VAR doc: CtlWord9.Document; name: CtlT.Strg;
BEGIN
doc := GetApplication().ActiveDocument();
name := doc.FullName();
doc.Close(CtlT.Int(CtlWord9.wdSaveChanges),NIL,NIL);
StdLog.String(' Document '); StdLog.String(name);
StdLog.String(' saved and closed.'); StdLog.Ln
END SaveAndCloseDoc;
PROCEDURE SaveDoc*;
(* Saves the active document. *)
VAR doc: CtlWord9.Document;
BEGIN
doc := GetApplication().ActiveDocument();
doc.Save;
StdLog.String(' Document '); StdLog.String(doc.FullName());
StdLog.String(' saved.'); StdLog.Ln
END SaveDoc;
PROCEDURE Print*;
(* Prints the active document. *)
VAR doc: CtlWord9.Document;
BEGIN
doc := GetApplication().ActiveDocument();
doc.PrintOut(NIL,NIL,NIL,NIL,NIL,NIL,NIL,NIL,NIL,NIL,NIL,NIL,NIL,NIL,NIL,NIL,NIL,NIL);
StdLog.String(' Document '); StdLog.String(doc.FullName());
StdLog.String(' printed.'); StdLog.Ln
END Print;
(* Application *)
PROCEDURE DispDocs*;
(* Displays the full names of all the open documents. *)
VAR count, i: INTEGER; docs: CtlWord9.Documents;
BEGIN
docs := GetApplication().Documents();
count := docs.Count();
StdLog.Int(count); StdLog.String(' Documents available.'); StdLog.Ln;
FOR i := 1 TO count DO
StdLog.String(docs.Item(CtlT.Int(i)).FullName()); StdLog.Ln
END
END DispDocs;
PROCEDURE DispFontNames*;
(* Displays the names of the available fonts in Word. *)
VAR fontNames : CtlWord9.FontNames; count, i: INTEGER;
BEGIN
fontNames := GetApplication().FontNames();
count := fontNames.Count();
StdLog.Int(count);
StdLog.String(' FontNames available.');
StdLog.Ln;
FOR i := 1 TO count DO
StdLog.String(fontNames.Item(i)); StdLog.Ln
END
END DispFontNames;
PROCEDURE DispBBFontNames*;
(* Displays the names of the available fonts in BlackBox. There are more than in Word. *)
VAR t: Fonts.TypefaceInfo;
BEGIN
StdLog.String(' BB FontNames:');
t := Fonts.dir.TypefaceList();
WHILE t # NIL DO
StdLog.String(t.typeface); StdLog.Ln;
t := t.next
END
END DispBBFontNames;
PROCEDURE DispLanguages*;
(* Displays the languages available in Word. *)
VAR count: INTEGER; languages: CtlWord9.Languages; lang: CtlWord9.Language; enum: CtlT.Enumerator;
BEGIN
languages := GetApplication().Languages();
count := languages.Count();
StdLog.Int(count); StdLog.String(' Languages available.'); StdLog.Ln;
enum:= languages._NewEnum();
lang := CtlWord9.ThisLanguage(enum.First());
WHILE lang # NIL DO
StdLog.String(lang.NameLocal());
StdLog.Ln;
lang := CtlWord9.ThisLanguage(enum.Next())
END
END DispLanguages;
PROCEDURE DispLanguagesAndDictionaries*;
(* Displays the languages available in Word and whether they have a dictionary. *)
(* Attention: ActiveSpellingDictionary traps if there is no dictionary available... *)
VAR count: INTEGER; languages : CtlWord9.Languages; lang: CtlWord9.Language; enum:CtlT.Enumerator;
BEGIN
languages := GetApplication().Languages();
count := languages.Count();
StdLog.Int(count); StdLog.String(' Languages available.'); StdLog.Ln;
enum:= languages._NewEnum();
lang := CtlWord9.ThisLanguage(enum.First());
WHILE lang # NIL DO
StdLog.String(lang.NameLocal());
IF lang.ActiveSpellingDictionary() # NIL THEN
StdLog.String(' (Dict)')
END;
StdLog.Ln;
lang := CtlWord9.ThisLanguage(enum.Next())
END
END DispLanguagesAndDictionaries;
PROCEDURE UseSmartCutPaste*;
(* Sets the option SmartCutPaste. *)
BEGIN
GetApplication().Options().PUTSmartCutPaste(TRUE);
StdLog.String(' SmartCutPaste turned on.'); StdLog.Ln
END UseSmartCutPaste;
(* Visibility *)
PROCEDURE MakeWordVisible*;
(* Makes all documents visible, also the ones that were created invisible. *)
BEGIN
GetApplication().PUTVisible(TRUE);
StdLog.String(' Word made visible.'); StdLog.Ln
END MakeWordVisible;
PROCEDURE MakeWordInvisible*;
(* Makes all documents invisible. *)
BEGIN
GetApplication().PUTVisible(FALSE);
StdLog.String(' Word made invisible.'); StdLog.Ln
END MakeWordInvisible;
PROCEDURE MakeWinVisible*;
(* Makes the first window of the active document visible. *)
BEGIN
GetApplication().ActiveDocument().Windows().Item(CtlT.Int(1)).PUTVisible(TRUE);
StdLog.String(' Window made visible.'); StdLog.Ln
END MakeWinVisible;
PROCEDURE MakeWinInvisible*;
(* Makes the first window of the active document invisible. *)
BEGIN
GetApplication().ActiveDocument().Windows().Item(CtlT.Int(1)).PUTVisible(FALSE);
StdLog.String(' Window made invisible.'); StdLog.Ln
END MakeWinInvisible;
PROCEDURE IsWinVisible*;
(* Displays whether the first window of the active document is visible. *)
BEGIN
StdLog.Bool(GetApplication().ActiveDocument().Windows().Item(CtlT.Int(1)).Visible()); StdLog.Ln
END IsWinVisible;
(* Document *)
PROCEDURE Undo*;
(* Undoes the last action. Actions, such a typing characters, can be merged to one action by Word. *)
VAR doc: CtlWord9.Document;
BEGIN
doc := GetApplication().ActiveDocument();
IF doc.Undo(CtlT.Int(1)) THEN
StdLog.String(' Undone.')
ELSE
StdLog.String(' Undo not possible.')
END;
StdLog.Ln
END Undo;
PROCEDURE Redo*;
(* Redoes the last undone action. *)
VAR doc: CtlWord9.Document;
BEGIN
doc := GetApplication().ActiveDocument();
IF doc.Redo(CtlT.Int(1)) THEN
StdLog.String(' Redone.')
ELSE
StdLog.String(' Redo not possible.')
END;
StdLog.Ln
END Redo;
PROCEDURE Protect*;
(* Protects the active document. *)
BEGIN
GetApplication().ActiveDocument().Protect(CtlWord9.wdAllowOnlyFormFields, NIL, NIL);
StdLog.String('Document locked.'); StdLog.Ln
END Protect;
PROCEDURE Unprotect*;
(* Unprotects the active document. *)
BEGIN
GetApplication().ActiveDocument().Unprotect(NIL);
StdLog.String('Document unlocked.'); StdLog.Ln
END Unprotect;
(* Accessing the Content of a Document *)
PROCEDURE DispContent*;
(* Displays the content of the active document. *)
VAR doc: CtlWord9.Document;
BEGIN
doc := GetApplication().ActiveDocument();
StdLog.String('Document content: ');
StdLog.String(doc.Content().Text()); StdLog.Ln
END DispContent;
PROCEDURE DispParagraphs*;
(* Displays the paragraphs of the active document. *)
VAR count, i: INTEGER; doc: CtlWord9.Document; paras: CtlWord9.Paragraphs;
BEGIN
doc := GetApplication().ActiveDocument();
paras := doc.Paragraphs();
count := paras.Count();
StdLog.Int(count); StdLog.String(' Paragraphs available.'); StdLog.Ln;
FOR i := 1 TO count DO
StdLog.String(paras.Item(i).Range().Text());
StdLog.Ln; StdLog.Ln
END
END DispParagraphs;
PROCEDURE DispListParagraphs*;
(* Displays the ListParagraphs of the active document. *)
VAR count, i: INTEGER; doc: CtlWord9.Document; paras: CtlWord9.ListParagraphs;
BEGIN
doc := GetApplication().ActiveDocument();
paras := doc.ListParagraphs();
count := paras.Count();
StdLog.Int(count); StdLog.String(' ListParagraphs available.'); StdLog.Ln;
FOR i := 1 TO count DO
StdLog.String(paras.Item(i).Range().Text());
StdLog.Ln; StdLog.Ln
END
END DispListParagraphs;
PROCEDURE DispLists*;
(* Displays the Lists of the active document. *)
VAR count, i: INTEGER; doc: CtlWord9.Document; lists: CtlWord9.Lists;
BEGIN
doc := GetApplication().ActiveDocument();
lists := doc.Lists();
count := lists.Count();
StdLog.Int(count); StdLog.String(' Lists available.'); StdLog.Ln;
FOR i := 1 TO count DO
StdLog.String(lists.Item(i).Range().Text());
StdLog.Ln; StdLog.Ln
END
END DispLists;
PROCEDURE DispWords*;
(* Displays the Words of the active document, using the CtlWord9.Document.Words method. *)
VAR count, i: INTEGER; doc: CtlWord9.Document; words: CtlWord9.Words;
BEGIN
doc := GetApplication().ActiveDocument();
words := doc.Words();
count := words.Count();
StdLog.Int(count); StdLog.String(' Words available.'); StdLog.Ln;
FOR i := 1 TO count DO
StdLog.String(words.Item(i).Text()); StdLog.Ln
END
END DispWords;
PROCEDURE DispWords2*;
(* Displays the Words of the active document, using the CtlWord9.Range.Next method. *)
VAR len: INTEGER; doc: CtlWord9.Document; r: CtlWord9.Range;
BEGIN
doc := GetApplication().ActiveDocument();
len := doc.Characters().Count();
r := doc.Range(CtlT.Int(0),CtlT.Int(0));
StdLog.String(' Words: '); StdLog.Ln;
REPEAT
r := r.Next(CtlT.Int(CtlWord9.wdWord), NIL);
StdLog.String(r.Text()); StdLog.Ln
UNTIL r.End() >= len
END DispWords2;
PROCEDURE DispWords3*;
(* Displays the Words of the active document, using the CtlWord9.Range.MoveEnd method. *)
VAR moved, lastEnd: INTEGER; doc: CtlWord9.Document; r: CtlWord9.Range;
BEGIN
doc := GetApplication().ActiveDocument();
r := doc.Range(CtlT.Int(0),CtlT.Int(0));
lastEnd := -1;
StdLog.String(' Words: '); StdLog.Ln;
REPEAT
lastEnd := r.End();
moved := r.MoveEnd(CtlT.Int(CtlWord9.wdWord), CtlT.Int(1));
StdLog.String(r.Text()); StdLog.Ln;
r.Collapse(CtlT.Int(CtlWord9.wdCollapseEnd))
UNTIL lastEnd = r.End()
END DispWords3;
PROCEDURE DispCharacters*;
(* Displays the Characters of the active document. *)
VAR count, i: INTEGER; doc: CtlWord9.Document; chars: CtlWord9.Characters;
BEGIN
doc := GetApplication().ActiveDocument();
chars := doc.Characters();
count := chars.Count();
StdLog.Int(count); StdLog.String(' Characters available.'); StdLog.Ln;
FOR i := 1 TO count DO
StdLog.String(chars.Item(i).Text()); StdLog.String(' ')
END
END DispCharacters;
PROCEDURE DispSentences*;
(* Displays the Sentences of the active document. *)
VAR count, i: INTEGER; doc: CtlWord9.Document; sentences: CtlWord9.Sentences;
BEGIN
doc := GetApplication().ActiveDocument();
sentences := doc.Sentences();
count := sentences.Count();
StdLog.Int(count); StdLog.String(' Sentences available.'); StdLog.Ln;
FOR i := 1 TO count DO
StdLog.String(sentences.Item(i).Text());
StdLog.Ln; StdLog.Ln
END
END DispSentences;
PROCEDURE DispStoryRanges*;
(* Displays the StoryRanges of the active document. *)
VAR count, i: INTEGER; doc: CtlWord9.Document; storyRanges: CtlWord9.StoryRanges;
BEGIN
doc := GetApplication().ActiveDocument();
storyRanges := doc.StoryRanges();
count := storyRanges.Count();
StdLog.Int(count); StdLog.String(' StoryRanges available.'); StdLog.Ln;
FOR i := 1 TO count DO
StdLog.String(storyRanges.Item(i).Text());
StdLog.Ln; StdLog.Ln
END
END DispStoryRanges;
PROCEDURE DispRuns*;
(* Should write the runs of the active document, but it does not work! How can we get the runs? *)
VAR len: INTEGER; doc: CtlWord9.Document; r: CtlWord9.Range;
BEGIN
doc := GetApplication().ActiveDocument();
len := doc.Characters().Count();
r := doc.Range(CtlT.Int(0),CtlT.Int(0));
StdLog.String('Runs: '); StdLog.Ln;
REPEAT
r := r.Next(CtlT.Int(CtlWord9.wdCharacterFormatting), NIL);
StdLog.String(r.Text()); StdLog.Ln
UNTIL r.End() >= len
END DispRuns;
(* Editing Text *)
PROCEDURE AppendThisText*;
(* Appends "This Text" to the end of the active document. This means that it is insert in front of the last 0DX. *)
VAR doc: CtlWord9.Document;
BEGIN
doc := GetApplication().ActiveDocument();
doc.Content().InsertAfter('This Text');
StdLog.String('This Text appended.'); StdLog.Ln
END AppendThisText;
PROCEDURE OverwriteLastCharWithA*;
(* Overwrites the last character, which is always a 0DX, with "A". Word then inserts a new 0DX at the end. *)
VAR count: INTEGER; doc: CtlWord9.Document;
BEGIN
doc := GetApplication().ActiveDocument();
count := doc.Characters().Count();
doc.Range(CtlT.Int(count-1), CtlT.Int(count)).PUTText('A');
StdLog.String('Last Character overwritten.'); StdLog.Ln
END OverwriteLastCharWithA;
PROCEDURE CopyText*;
(* Copies and inserts the first 10 chars at the beginning of the active document. *)
VAR doc: CtlWord9.Document; text: CtlT.Strg;
BEGIN
doc := GetApplication().ActiveDocument();
text := doc.Range(CtlT.Int(0),CtlT.Int(10)).Text();
doc.Range(CtlT.Int(0),CtlT.Int(0)).PUTText(text);
StdLog.String('Text copied.'); StdLog.Ln
END CopyText;
PROCEDURE CopyFormattedText*;
(* Copies and inserts the first 10 chars at the beginning of the active document, formatted. *)
VAR doc: CtlWord9.Document; formattedText: CtlWord9.Range;
BEGIN
doc := GetApplication().ActiveDocument();
formattedText := doc.Range(CtlT.Int(0),CtlT.Int(10)).FormattedText();
doc.Range(CtlT.Int(0),CtlT.Int(0)).PUTFormattedText(formattedText);
StdLog.String('Formatted text copied.'); StdLog.Ln
END CopyFormattedText;
PROCEDURE DeleteText*;
(* Deletes the first 10 character of the active document. *)
VAR doc: CtlWord9.Document;
BEGIN
doc := GetApplication().ActiveDocument();
doc.Range(CtlT.Int(0),CtlT.Int(10)).PUTText('');
StdLog.String('Text deleted.'); StdLog.Ln
END DeleteText;
(* Font *)
PROCEDURE Disp2ndParagraphFontName*;
(* Displays the name of the font of the 2nd paragraph of the active document, if it is defined. *)
VAR doc: CtlWord9.Document; fontName: ARRAY 100 OF CHAR;
BEGIN
doc := GetApplication().ActiveDocument();
fontName := doc.Paragraphs().Item(2).Range().Font().Name()$;
IF fontName[0] = 0X THEN
StdLog.String('2nd Paragraph Font Name is not defined (result = empty string)')
ELSE
StdLog.String('2nd Paragraph Font Name = '); StdLog.String(fontName)
END;
StdLog.Ln
END Disp2ndParagraphFontName;
PROCEDURE Is1stParagraphBold*;
(* Displays whether the 1st paragraph of the active document is bold or not, if it is defined. *)
VAR bold: INTEGER; doc: CtlWord9.Document;
BEGIN
doc := GetApplication().ActiveDocument();
bold := doc.Paragraphs().Item(1).Range().Bold();
StdLog.String('The first paragraph ');
IF bold = 0 THEN
StdLog.String('is Not Bold')
ELSIF bold = -1 THEN
StdLog.String('is Bold')
ELSE
StdLog.String('is neither Bold nor Not Bold')
END;
StdLog.String(' (result = '); StdLog.Int(bold); StdLog.String(')'); StdLog.Ln
END Is1stParagraphBold;
PROCEDURE Disp1stParagraphFontSize*;
(* Displays the size of the font of the 1st paragraph of the active document, if it is defined. *)
VAR size: SHORTREAL; doc: CtlWord9.Document;
BEGIN
doc := GetApplication().ActiveDocument();
StdLog.String('The first paragraph: size =');
size := doc.Paragraphs().Item(1).Range().Font().Size();
IF size # CtlWord9.wdUndefined THEN
StdLog.Real(size)
ELSE
StdLog.String('undefined (result = '); StdLog.Real(size); StdLog.String(' )')
END;
StdLog.Ln
END Disp1stParagraphFontSize;
(* Performance *)
PROCEDURE Performance*;
CONST
wordTries = 1000;
bbTries = 100000000;
VAR start, counterTime, wordTime, bbTime : LONGINT; i : INTEGER; opt: CtlWord9.Options;
PROCEDURE Put (newValue: BOOLEAN);
VAR value: BOOLEAN;
BEGIN
value := newValue
END Put;
BEGIN
IF app = NIL THEN Start END;
opt := GetApplication().Options();
start:= Services.Ticks();
FOR i := 1 TO wordTries DO END;
counterTime := Services.Ticks() - start;
start:= Services.Ticks();
FOR i := 1 TO wordTries DO opt.PUTSmartCutPaste(TRUE) END;
wordTime := Services.Ticks() - start - counterTime;
StdLog.Int(wordTries);
StdLog.String(" PUTSmartCutPaste took ");
StdLog.Real(wordTime / Services.resolution);
StdLog.String(" sec."); StdLog.Ln;
start:= Services.Ticks();
FOR i := 1 TO bbTries DO END;
counterTime := Services.Ticks() - start;
start := Services.Ticks();
FOR i := 1 TO bbTries DO Put(TRUE) END;
bbTime := Services.Ticks() - start - counterTime;
StdLog.Int(bbTries);
StdLog.String(" BlackBox procedure calls took ");
StdLog.Real(bbTime / Services.resolution);
StdLog.String(" sec."); StdLog.Ln;
StdLog.String("Properties are ");
StdLog.Int( (wordTime * bbTries) DIV (bbTime * wordTries));
StdLog.String(" times slower."); StdLog.Ln
END Performance;
END ObxWordEdit.
| Obx/Mod/WordEdit.odc |
MODULE ObxWrappers;
(**
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, Stores, Models, Views, Controllers, Properties, StdLog;
CONST minVersion = 2; maxVersion = 2;
TYPE
View = POINTER TO RECORD (Views.View)
inner: Views.View (* v # NIL *)
END;
PROCEDURE (v: View) Internalize (VAR rd: Stores.Reader);
VAR version: INTEGER;
BEGIN
rd.ReadVersion(minVersion, maxVersion, version);
IF ~rd.cancelled THEN
Views.ReadView(rd, v.inner) (* generate Views.Alien if necessary *)
END
END Internalize;
PROCEDURE (v: View) Externalize (VAR wr: Stores.Writer);
BEGIN
wr.WriteVersion(maxVersion);
Views.WriteView(wr, v.inner) (* handle Views.Alien if necessary *)
END Externalize;
PROCEDURE (v: View) CopyFromModelView (source: Views.View; model: Models.Model);
BEGIN
WITH source: View DO
IF model = NIL THEN
v.inner := Views.CopyOf(source.inner, Views.deep)
ELSE
v.inner := Views.CopyWithNewModel(source.inner, model)
END
END
END CopyFromModelView;
PROCEDURE (v: View) ThisModel (): Models.Model;
BEGIN
RETURN v.inner.ThisModel()
END ThisModel;
PROCEDURE (v: View) InitContext (context: Models.Context);
BEGIN
v.InitContext^(context);
v.inner.InitContext(context) (* wrapper and wrapped view share the same context *)
END InitContext;
PROCEDURE (v: View) Neutralize;
BEGIN
v.inner.Neutralize
END Neutralize;
(* GetNewFrame: wrapper uses standard frame *)
(* GetBackground: wrapper has no intrinsic background color *)
PROCEDURE (v: View) Restore (f: Views.Frame; l, t, r, b: INTEGER);
BEGIN
Views.InstallFrame(f, v.inner, 0, 0, 0, TRUE) (* create and install wrapped view's frame *)
END Restore;
(* RestoreMarks: wrapper has no intrinsic marks, wrapped view's RestoreMarks is called by framework *)
(* HandleModelMsg: framework performs message propagation *)
(* HandleViewMsg: framework performs message propagation *)
PROCEDURE (v: View) HandleCtrlMsg (f: Views.Frame; VAR msg: Controllers.Message; VAR focus: Views.View);
BEGIN
(* here comes the behavior which is specific to this wrapper -
it modifies the wrapped view's behavior *)
WITH msg: Controllers.EditMsg DO
(* sample special behavior: copy typing into log *)
IF msg.op = Controllers.pasteChar THEN StdLog.Char(msg.char); StdLog.Ln END
ELSE
END;
focus := v.inner (* forward all controller messages to wrapped view *)
END HandleCtrlMsg;
PROCEDURE (v: View) HandlePropMsg (VAR msg: Properties.Message);
BEGIN
Views.HandlePropMsg(v.inner, msg) (* forward all property messages to wrapped view *)
END HandlePropMsg;
PROCEDURE Wrap*;
VAR poll: Controllers.PollOpsMsg; w: View; replace: Controllers.ReplaceViewMsg;
BEGIN
Controllers.PollOps(poll);
IF (poll.singleton # NIL) & ~(poll.singleton IS View) THEN
NEW(w); w.inner := poll.singleton; Stores.Join(w, w.inner);
replace.old := poll.singleton; replace.new := w;
Controllers.Forward(replace)
ELSE Dialog.Beep
END
END Wrap;
PROCEDURE Unwrap*;
VAR poll: Controllers.PollOpsMsg; replace: Controllers.ReplaceViewMsg;
BEGIN
Controllers.PollOps(poll);
IF (poll.singleton # NIL) & (poll.singleton IS View) THEN
replace.old := poll.singleton; replace.new := poll.singleton(View).inner;
Controllers.Forward(replace)
ELSE Dialog.Beep
END
END Unwrap;
END ObxWrappers.
| Obx/Mod/Wrappers.odc |
Obx/Rsrc/Actions.odc |
|
Obx/Rsrc/BlackBox.odc |
|
Obx/Rsrc/Controls.odc |
|
Obx/Rsrc/Cubes.odc |
|
Obx/Rsrc/Dialog.odc |
|
Obx/Rsrc/FileTree.odc |
|
MENU "Примеры"
"Примеры производителя" "" "StdCmds.OpenBrowser('Obx/Docu/ru/Sys-Map', 'Примеры производителя')" ""
SEPARATOR
"Создание простых диалогов" "" "StdCmds.OpenBrowser('i21диал/Создание простых диалогов.odc', 'Создание простых диалогов')" ""
"Пошаговая разработка" "" "StdCmds.OpenBrowser('i21прим/Docu.Пошаговая разработка/0. Пошаговая разработка.odc', 'Пошаговая разработка: обзор')" ""
SEPARATOR
"Игра Тетрис..." "" "i21примТетрис.НоваяИгра" ""
"Игра Блэкбокс..." "" "StdCmds.OpenAuxDialog('Obx/Rsrc/BlackBox', 'Игра Блэкбокс')" ""
END
"Hello0" "" "ObxHello0.Do" ""
"Hello1" "" "ObxHello1.Do" ""
"Open0..." "" "ObxOpen0.Do" ""
"Open1..." "" "ObxOpen1.Do" ""
"Capitalize Text" "" "ObxCaps.Do" "TextCmds.SelectionGuard"
"Open Mail Template" "" "StdCmds.OpenDoc('Obx/Samples/MMTmpl')" ""
"Merge..." "" "ObxMMerge.Merge" "TextCmds.FocusGuard"
"Show Directory" "" "ObxLinks.Directory('')" ""
SEPARATOR
"Orders..." "" "StdCmds.OpenAuxDialog('Obx/Rsrc/Orders', 'Order Processing')" ""
"Controls..." "" "StdCmds.OpenAuxDialog('Obx/Rsrc/Controls', 'ObxControls Demo')" ""
"Dialog..." "" "StdCmds.OpenAuxDialog('Obx/Rsrc/Dialog', 'ObxDialog Demo')" ""
"File Tree..." "" "StdCmds.OpenAuxDialog('Obx/Rsrc/FileTree', 'ObxFileTree Demo')" ""
"Tab View..." "" "ObxTabViews.Deposit; StdCmds.Open" ""
SEPARATOR
"Trap!" "" "ObxTrap.Do" ""
"Простые числа..." "" "StdCmds.OpenAuxDialog('Obx/Rsrc/Actions', 'Вычисление простых чисел')" ""
"Вычислить факториал" "" "ObxFact.Compute" "TextCmds.SelectionGuard"
"Упростить" "" "ObxRatCalc.Simplify" "TextCmds.SelectionGuard"
"Аппроксимировать" "" "ObxRatCalc.Approximate" "TextCmds.SelectionGuard"
SEPARATOR
"New Pattern" "" "ObxPatterns.Deposit; StdCmds.Open" ""
"New Calculator" "" "ObxCalc.Deposit; StdCmds.Open" ""
"New Omosi" "" "ObxOmosi.Deposit; StdCmds.Open" ""
"New Cube" "" "ObxCubes.Deposit; StdCmds.Open" ""
"Cube Colors..." "" "StdCmds.OpenToolDialog('Obx/Rsrc/Cubes', 'Cube Colors')" ""
"New Checkerboard" "" "ObxScroll.Deposit; StdCmds.Open" ""
SEPARATOR
"Insert Button" "" "ObxButtons.Deposit; StdCmds.PasteView" "StdCmds.PasteViewGuard"
"New Ticker" "" "ObxTickers.Deposit; StdCmds.Open" ""
SEPARATOR
"New Lines" "" "ObxLines.Deposit; StdCmds.Open" ""
"New Graph" "" "ObxGraphs.Deposit; StdCmds.Open" ""
SEPARATOR
"Wrap" "" "ObxWrappers.Wrap" "StdCmds.SingletonGuard"
"Unwrap" "" "ObxWrappers.Unwrap" "StdCmds.SingletonGuard"
SEPARATOR
"New Twin" "" "ObxTwins.Deposit; StdCmds.Open" ""
"Focus Magic Control" "" "ObxContIter.Do" "StdCmds.ContainerGuard"
MENU "Tut"
"Phone Database..." "" "StdCmds.OpenAuxDialog('Obx/Rsrc/PhoneUI', 'Phone Database')" ""
"Phone Database 1..." "" "StdCmds.OpenAuxDialog('Obx/Rsrc/PhoneUI1', 'Phone Database')" ""
"Right-Shift Selection" "" "ObxControlShifter.Shift" "FormCmds.SelectionGuard"
"List Labels" "" "ObxLabelLister.List" "FormCmds.FocusGuard"
"Generate Report 0" "" "ObxPDBRep0.GenReport" ""
"Generate Report 1" "" "ObxPDBRep1.GenReport" ""
"Generate Report 2" "" "ObxPDBRep2.GenReport" ""
"Generate Report 3" "" "ObxPDBRep3.GenReport" ""
"Generate Report 4" "" "ObxPDBRep4.GenReport" ""
"Count Atoms" "" "ObxCount0.Do" "TextCmds.SelectionGuard"
"Count Symbols" "" "ObxCount1.Do" "TextCmds.SelectionGuard"
"Lookup 0" "" "ObxLookup0.Do" "TextCmds.SelectionGuard"
"Lookup 1" "" "ObxLookup1.Do" "TextCmds.SelectionGuard"
SEPARATOR
"New View 0" "" "ObxViews0.Deposit; StdCmds.Open" ""
"New View 1" "" "ObxViews1.Deposit; StdCmds.Open" ""
"New View 2" "" "ObxViews2.Deposit; StdCmds.Open" ""
"New View 3" "" "ObxViews3.Deposit; StdCmds.Open" ""
"New View 4" "" "ObxViews4.Deposit; StdCmds.Open" ""
"New View 5" "" "ObxViews5.Deposit; StdCmds.Open" ""
"New View 6" "" "ObxViews6.Deposit; StdCmds.Open" ""
SEPARATOR
"New View 10" "" "ObxViews10.Deposit; StdCmds.Open" ""
"New View 11" "" "ObxViews11.Deposit; StdCmds.Open" ""
"New View 12" "" "ObxViews12.Deposit; StdCmds.Open" ""
"New View 13" "" "ObxViews13.Deposit; StdCmds.Open" ""
"New View 14" "" "ObxViews14.Deposit; StdCmds.Open" ""
END
MENU "New" ("Obx.Tutorial")
"Beep" "" "Dialog.Beep" ""
END
MENU "Блэкбокс" ("ObxBlackBox.View")
"Показать решение" "" "ObxBlackBox.ShowSolution" "ObxBlackBox.ShowSolutionGuard"
"Новые атомы" "" "ObxBlackBox.New" ""
"Правила" "" "StdCmds.OpenBrowser('Obx/Docu/ru/BB-Rules', 'Правила игры Блэкбокс')" ""
END
| Obx/Rsrc/Menus.odc |
Obx/Rsrc/Orders.odc |
|
Obx/Rsrc/Orders1.odc |
|
Obx/Rsrc/PhoneUI.odc |
|
Obx/Rsrc/PhoneUI1.odc |
|
STRINGS
Lookup Lookup
ObxConv.ImportTEXT Obx Text File
Off Switch Off
On Switch On
list[0] Daffy Duck
list[1] Wile E. Coyote
list[2] Scrooge Mc Duck
list[3] Huey Lewis
list[4] Thomas Dewey
CtrlCol.Prop ObxCtrlCol.InitDialog; StdCmds.OpenToolDialog('Obx/Rsrc/CtrlCol', 'Properties')
(Obx)Actions (Obx)Actions
Upper Bound Предел
Start Начать
(Obx)BlackBox (Obx)BlackBox
Size of the board Размер поля
Number of hidden Atoms Число скрытых атомов
Open Начать
Obx/Mod/BlackBox Obx/Mod/BlackBox
atoms Атомов:
score Счёт:
| Obx/Rsrc/Strings.odc |
Name Address0 Address1 State Country
Mr. A. Hill 39 Sunstreet Moon City Alabama USA
Mr. G. Ernst Feldweg 28 Hochdorf Bayern Deutschland
Ms. P. Thompson 12 Oak Ave. Littletown N.Carolina USA
Mr. W. Trou 81, rue Paris Mantes IledeParis France | Obx/Samples/MMData.odc |
Obx/Samples/MMTmpl.odc |
|
Obx/Samples/Omosi1.odc |
|
Obx/Samples/Omosi2.odc |
|
Obx/Samples/Omosi3.odc |
|
Obx/Samples/Omosi4.odc |
|
Obx/Samples/Omosi5.odc |
|
Obx/Samples/Omosi6.odc |
|
OleClient
This module has a private interface, it is only used internally.
| Ole/Docu/Client.odc |
OleData
This module has a private interface, it is only used internally.
| Ole/Docu/Data.odc |
OleServer
This module has a private interface, it is only used internally.
| Ole/Docu/Server.odc |
OleStorage
This module has a private interface, it is only used internally.
| Ole/Docu/Storage.odc |
Map to the Ole Subsystem
Views OLE wrapper views
| Ole/Docu/Sys-Map.odc |
OleViews
DEFINITION OleViews;
IMPORT CtlT, Views;
PROCEDURE NewObjectView (name: ARRAY OF CHAR): Views.View;
PROCEDURE NewObjectViewFromClipboard (): Views.View;
PROCEDURE Deposit (name: ARRAY OF CHAR);
PROCEDURE IsObjectView (v: Views.View): BOOLEAN;
PROCEDURE IsAutoView (v: Views.View): BOOLEAN;
PROCEDURE OleObject (v: Views.View): CtlT.Interface;
PROCEDURE AutoObject (v: Views.View): CtlT.Object;
PROCEDURE Connect (sink: CtlT.OutObject; source: Views.View);
END OleViews.
OleViews provides a programming interface for OLE objects used as views in BlackBox.
PROCEDURE NewObjectView (name: ARRAY OF CHAR): Views.View
Instantiates an OLE object of a given type. name can either be a valid OLE class name (e.g., "Excel.Sheet") or a GUID (global unique identifier) in string form, provided it is a valid class identifier (e.g., "{00020820-0000-0000-C000-000000000046}"). If instatiantion failed, the return value is NIL.
PROCEDURE NewObjectViewFromClipboard (): Views.View
Instantiates the OLE object currently contained in the clipboard. Returns NIL if there is no OLE object on the clipboard.
PROCEDURE Deposit (name: ARRAY OF CHAR)
Deposit command for new OLE objects of a given type. name can either be a valid OLE class name (e.g., "Excel.Sheet") or a GUID (global unique identifier) in string form, provided it is a valid class identifier (e.g., "{00020820-0000-0000-C000-000000000046}").
PROCEDURE IsObjectView (v: Views.View): BOOLEAN
Return TRUE if the given View is an OLE object, FALSE otherwise.
PROCEDURE IsAutoView (v: Views.View): BOOLEAN
Return TRUE if the given View is an OLE Automation object (an object which supports the IDispatch interface), FALSE otherwise.
PROCEDURE OleObject (v: Views.View): CtlT.Interface
Returns the IUnknown interface of the object contained in v as an automation controller object. Only useful in conjunction with the Direct-To-COM compiler (DTC). For information about automation controller objects see the CtlDocu. NIL is returned if v is not an OLE object.
PROCEDURE AutoObject (v: Views.View): CtlT.Object
Returns the automation controller object associated with v. For information about automation controller objects see the CtlDocu. NIL is returned if v is not an OLE Automation object.
PROCEDURE Connect (sink: CtlT.OutObject; source: Views.View)
Connects the automation controller callback object sink to an OLE object contained in the view source. For information about automation controller objects see the CtlDocu.
| Ole/Docu/Views.odc |
MODULE OleClient;
(**
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
SYSTEM, COM, WinApi, WinOle, WinOleCtl, WinOleAut, WinOleDlg,
OleStorage, OleData, OleServer,
Meta, Dialog, Services, Ports, Stores, Sequencers, Models, Views, Controllers,
Properties, Containers, Controls,
StdDialog, Log, HostPorts, HostWindows, HostMenus;
CONST
debug = FALSE;
minModelVersion = 0; maxModelVersion = 1;
minViewVersion = 0; maxViewVersion = 0;
ObjectID = "{00000001-1000-11cf-adf0-444553540000}"; (* BlackBox views *)
miscStatus = WinOle.OLEMISC_RECOMPOSEONRESIZE
+ WinOle.OLEMISC_CANTLINKINSIDE
+ WinOle.OLEMISC_RENDERINGISDEVICEINDEPENDENT;
oleUnit = Ports.mm DIV 100;
TYPE
IOleClientSite = POINTER TO RECORD (WinOle.IOleClientSite)
ias: IAdviseSink;
iips: IOleInPlaceSite;
obj: Model;
frame: Views.Frame;
wnd: WinApi.HWND
END;
IAdviseSink = POINTER TO RECORD (WinOle.IAdviseSink)
site: IOleClientSite;
obj: Model
END;
IOleInPlaceSite = POINTER TO RECORD (WinOle.IOleInPlaceSite)
site: IOleClientSite;
obj: Model
END;
IOleInPlaceUIWindow = POINTER TO RECORD (WinOle.IOleInPlaceUIWindow)
wnd: WinApi.HWND;
iipao: WinOle.IOleInPlaceActiveObject
END;
WinHook = POINTER TO RECORD (HostWindows.Hook)
iipw: IOleInPlaceUIWindow
END;
IOleInPlaceFrame = POINTER TO RECORD (WinOle.IOleInPlaceFrame)
objWnd: WinApi.HWND; (* for menu handling *)
iipao: WinOle.IOleInPlaceActiveObject
END;
FrameHook = POINTER TO RECORD (HostWindows.Hook) END;
Sink = POINTER TO RECORD
next: Sink;
(*
obj: CtlT.OutObject;
*)
point: WinOle.IConnectionPoint;
cookie: INTEGER
END;
View = POINTER TO RECORD (Views.View)
model: Model;
hasNotifier: BOOLEAN
END;
Model = POINTER TO RECORD (Models.Model)
site: IOleClientSite;
advConn: INTEGER;
open: BOOLEAN;
objUnk: COM.IUnknown;
objView: WinOle.IViewObject2;
objObj: WinOle.IOleObject;
objIPObj: WinOle.IOleInPlaceObject; (* # NIL: in place open *)
stg: WinOle.IStorage;
flags: SET;
w, h: INTEGER; (* actual site size (units) *)
rw, rh: INTEGER; (* actual pos rect size (pixels) *)
guard: BOOLEAN;
focusGuard: BOOLEAN;
onServer: BOOLEAN;
view: View;
link: ARRAY 256 OF CHAR;
sinks: Sink
END;
Frame = POINTER TO RECORD (Views.Frame) END;
Notifier = POINTER TO RECORD (Sequencers.Notifier)
model: Model
END;
Deactivator = POINTER TO RECORD (Services.Action)
obj: Model
END;
UpdateMsg = RECORD (Models.UpdateMsg)
checkSize: BOOLEAN
END;
(*
ObjectValue = RECORD (Meta.Value)
obj*: CtlT.OutObject
END;
*)
ProcValue = RECORD (Meta.Value)
open*: PROCEDURE(v: Views.View)
END;
Op = POINTER TO RECORD (Stores.Operation)
model: Model;
link: ARRAY 256 OF CHAR
END;
VAR
appFrame: IOleInPlaceFrame;
winMenu: WinApi.HMENU;
hAccel: WinApi.HACCEL;
nAccel: INTEGER;
menuBar: WinApi.HMENU;
(* ----------callback linking ---------- *)
PROCEDURE Connect* (v: Views.View; iid: COM.GUID; disp: WinOleAut.IDispatch);
VAR res: COM.RESULT; cont: WinOle.IConnectionPointContainer; point: WinOle.IConnectionPoint; sink: Sink;
BEGIN
WITH v: View DO
res := v.model.objUnk.QueryInterface(COM.ID(cont), cont);
IF res >= 0 THEN
res := cont.FindConnectionPoint(iid, point);
IF res >= 0 THEN
NEW(sink); sink.point := point;
res := point.Advise(disp, sink.cookie);
IF res >= 0 THEN
sink.next := v.model.sinks; v.model.sinks := sink
END
END
END
ELSE
END
END Connect;
PROCEDURE Disconnect (model: Model);
VAR res: COM.RESULT; sink: Sink;
BEGIN
sink := model.sinks;
WHILE sink # NIL DO
res := sink.point.Unadvise(sink.cookie);
sink := sink.next
END;
model.sinks := NIL
END Disconnect;
PROCEDURE OpenLink (model: Model);
VAR item: Meta.Item; pv: ProcValue; ok: BOOLEAN;
BEGIN
IF model.link # "" THEN
Meta.LookupPath(model.link, item);
IF item.obj = Meta.procObj THEN
item.GetVal(pv, ok);
IF ok THEN pv.open(model.view)
ELSE Dialog.ShowParamMsg("#System:HasWrongType", model.link, "", "")
END
ELSE Dialog.ShowParamMsg("#System:NotFound", model.link, "", "")
END
END
END OpenLink;
(*
PROCEDURE OpenLinks (model: Model);
VAR item: Meta.Item; ov: ObjectValue; ok: BOOLEAN; iid: COM.GUID; res: COM.RESULT;
cont: WinOle.IConnectionPointContainer; disp: WinOleAut.IDispatch; point: WinOle.IConnectionPoint;
i, j: INTEGER; name: ARRAY 256 OF CHAR; sink: Sink;
BEGIN
i := 0;
WHILE model.link[i] # 0X DO
WHILE (model.link[i] # 0X) & (model.link[i] <= ",") DO INC(i) END;
j := 0;
WHILE model.link[i] > "," DO name[j] := model.link[i]; INC(j); INC(i) END;
name[j] := 0X;
IF name # "" THEN
Meta.LookupPath(name, item);
IF item.obj # Meta.undef THEN
IF (item.obj = Meta.typObj) & (item.typ = Meta.ptrTyp) THEN item.GetBaseType(item) END;
IF (item.obj = Meta.typObj) & (item.typ = Meta.recTyp) & item.Is(ov) THEN
(* item.Allocate(ov); *) ov.obj := item.New()(CtlT.OutObject);
res := model.objUnk.QueryInterface(COM.ID(cont), cont);
IF res >= 0 THEN
ov.obj.GetIID(iid);
res := cont.FindConnectionPoint(iid, point);
IF res >= 0 THEN
disp := CtlT.Disp(ov.obj); ASSERT(disp # NIL);
NEW(sink); sink.obj := ov.obj; sink.point := point;
res := point.Advise(disp, sink.cookie);
IF res >= 0 THEN
sink.next := model.sinks; model.sinks := sink;
res := model.objUnk.QueryInterface(COM.ID(disp), disp);
IF res >= 0 THEN sink.obj.source := CtlT.Obj(disp) END
END
ELSE Dialog.ShowParamMsg("#System:HasWrongType", name, "", "")
END
ELSE HALT(100)
END
ELSE Dialog.ShowParamMsg("#System:HasWrongType", name, "", "")
END
ELSE Dialog.ShowParamMsg("#System:NotFound", name, "", "")
END
END
END
END OpenLinks;
PROCEDURE CloseLinks (model: Model);
VAR res: COM.RESULT; sink: Sink; iid: COM.GUID;
BEGIN
sink := model.sinks;
WHILE sink # NIL DO
res := sink.point.Unadvise(sink.cookie);
sink.obj.source := NIL;
sink := sink.next
END;
model.sinks := NIL
END CloseLinks;
*)
PROCEDURE PollProp (model: Model; VAR list: Properties.Property);
VAR p: Controls.Prop; res: COM.RESULT; cont: WinOle.IConnectionPointContainer;
BEGIN
res := model.objUnk.QueryInterface(COM.ID(cont), cont);
IF res >= 0 THEN
NEW(p);
p.valid := {Controls.link}; p.known := p.valid;
p.link := model.link$;
Properties.Insert(list, p)
END
END PollProp;
PROCEDURE SetProp (model: Model; p: Properties.Property);
VAR res: COM.RESULT; cont: WinOle.IConnectionPointContainer; op: Op;
BEGIN
res := model.objUnk.QueryInterface(COM.ID(cont), cont);
IF res >= 0 THEN
WHILE p # NIL DO
WITH p: Controls.Prop DO
IF Controls.link IN p.valid THEN
NEW(op); op.model := model; op.link := p.link$;
Models.Do(model, "#System:SetProp", op)
END
ELSE
END;
p := p.next
END
END
END SetProp;
PROCEDURE (op: Op) Do;
VAR link: ARRAY 256 OF CHAR;
BEGIN
(*
Disconnect(op.model);
*)
link := op.model.link$; op.model.link := op.link$; op.link := link$;
OpenLink(op.model)
END Do;
(* ---------- auxiliary ---------- *)
PROCEDURE Visible (m: Model; f: Views.Frame): BOOLEAN;
VAR g: Views.Frame; ctrl: Containers.Controller;
BEGIN
IF m.flags * WinOleCtl.OLEMISC_INVISIBLEATRUNTIME = {} THEN RETURN TRUE
ELSE
g := Views.HostOf(f);
IF (g = NIL) OR ~(g.view IS Containers.View) THEN RETURN TRUE
ELSE
ctrl := g.view(Containers.View).ThisController();
RETURN Containers.mask * ctrl.opts # Containers.mask
END
END
END Visible;
PROCEDURE GenGlobalMedium (hg: WinApi.HGLOBAL; unk: COM.IUnknown; VAR sm: WinOle.STGMEDIUM);
BEGIN
sm.tymed := WinOle.TYMED_HGLOBAL;
sm.u.hGlobal := hg;
sm.pUnkForRelease := unk
END GenGlobalMedium;
PROCEDURE MediumGlobal (VAR sm: WinOle.STGMEDIUM): WinApi.HGLOBAL;
BEGIN
ASSERT(sm.tymed = WinOle.TYMED_HGLOBAL, 20);
RETURN sm.u.hGlobal
END MediumGlobal;
PROCEDURE GenStorageMedium (stg: WinOle.IStorage; unk: COM.IUnknown; VAR sm: WinOle.STGMEDIUM);
BEGIN
sm.u.hGlobal := 0;
sm.tymed := WinOle.TYMED_ISTORAGE;
sm.u.pstg := stg;
sm.pUnkForRelease := unk
END GenStorageMedium;
PROCEDURE MediumStorage (VAR sm: WinOle.STGMEDIUM): WinOle.IStorage;
BEGIN
ASSERT(sm.tymed = WinOle.TYMED_ISTORAGE, 20);
RETURN sm.u.pstg
END MediumStorage;
PROCEDURE DoVerb (obj: Model; f: Views.Frame; verb: SHORTINT);
VAR res: COM.RESULT; w, h: INTEGER; rect: WinApi.RECT;
BEGIN
obj.site.frame := f;
IF f # NIL THEN
f.view.context.GetSize(w, h);
rect.left := f.gx DIV f.unit;
rect.top := f.gy DIV f.unit;
rect.right := (f.gx + w) DIV f.unit;
rect.bottom := (f.gy + h) DIV f.unit;
obj.rw := w DIV f.unit;
obj.rh := h DIV f.unit;
IF debug THEN Log.Int(rect.left); Log.Int(rect.top); Log.Int(rect.right); Log.Int(rect.bottom); Log.Ln END;
res := obj.objObj.DoVerb(verb, NIL, obj.site, 0, f.rider(HostPorts.Rider).port.wnd, rect)
ELSE
rect.left := 0; rect.top := 0; rect.right := 0; rect.bottom := 0;
res := obj.objObj.DoVerb(verb, NIL, obj.site, 0, 0, rect)
END
END DoVerb;
PROCEDURE UpdateSizes (v: View; checkSize, setRect: BOOLEAN);
VAR obj: Model; f: Views.Frame; host: Views.Frame; p: HostPorts.Port; res: COM.RESULT;
pos, clip: WinApi.RECT; size: WinApi.SIZE; w, h, ow, oh: INTEGER;
c: Containers.Controller; s: Views.View; g: BOOLEAN;
BEGIN
obj := v.model; f := obj.site.frame;
IF (f # NIL) & ((f.rider = NIL) OR (obj.objIPObj = NIL) OR (f.view # v)) THEN f := NIL END;
IF checkSize THEN
IF debug THEN Log.String("check sizes"); Log.Ln END;
res := obj.objObj.GetExtent(WinOle.DVASPECT_CONTENT, size);
IF res = WinApi.S_OK THEN
ow := size.cx * oleUnit; oh := size.cy * oleUnit;
v.context.GetSize(w, h);
IF (w # ow) OR (h # oh) THEN
IF debug THEN Log.String(" set size"); Log.Int(ow); Log.Int(oh); Log.Ln END;
Controllers.SetCurrentPath(Controllers.targetPath);
c := Containers.Focus();
Controllers.ResetCurrentPath();
s := c.Singleton();
IF f # NIL THEN host := Views.HostOf(f) END;
g := obj.focusGuard; obj.focusGuard := TRUE;
v.context.SetSize(ow, oh);
v.model.w := ow; v.model.h := oh;
IF f # NIL THEN
IF host # NIL THEN (* restore saved frame *)
IF debug THEN Log.String(" restore frame"); Log.Ln END;
Views.ValidateRoot(Views.RootOf(host));
f := Views.ThisFrame(host, v);
obj.site.frame := f
END;
c.SetFocus(v) (* restore focus *)
ELSIF (s # NIL) & (s # c.Singleton()) THEN c.SetSingleton(s) (* restore selection *)
END;
obj.focusGuard := g
END
END
END;
IF f # NIL THEN
v.context.GetSize(w, h); w := w DIV f.unit; h := h DIV f.unit;
IF w > obj.rw THEN obj.rw := w; setRect := TRUE END;
IF h > obj.rh THEN obj.rh := h; setRect := TRUE END;
IF setRect THEN
pos.left := f.gx DIV f.unit; pos.top := f.gy DIV f.unit;
pos.right := pos.left + obj.rw; pos.bottom := pos.top + obj.rh;
p := f.rider(HostPorts.Rider).port;
clip.left := 0; clip.top := 0; clip.right := p.w; clip.bottom := p.h;
IF debug THEN Log.String("set object rects"); Log.Int(obj.rw); Log.Int(obj.rh); Log.Ln END;
res := obj.objIPObj.SetObjectRects(pos, clip)
END
END
END UpdateSizes;
PROCEDURE GetAccelTable* (VAR a: WinApi.HACCEL; VAR n: INTEGER);
VAR res: INTEGER; m: HostMenus.Menu; data: ARRAY 128 OF WinApi.ACCEL; f: BYTE; i: StdDialog.Item;
BEGIN
IF menuBar # HostMenus.menuBar THEN (* update table *)
IF hAccel # 0 THEN res := WinApi.DestroyAcceleratorTable(hAccel) END;
nAccel := 0; m := HostMenus.menus;
WHILE m # NIL DO
IF m.class IN {0, 2, 4} THEN
i := m.firstItem;
WHILE (i # NIL) & (nAccel < LEN(data)) DO
WITH i: HostMenus.Item DO
IF i.code # 0 THEN
f := WinApi.FVIRTKEY;
IF i.shift THEN INC(f, WinApi.FSHIFT) END;
IF i.ctrl THEN INC(f, WinApi.FCONTROL) END;
data[nAccel].key := SHORT(i.code);
data[nAccel].cmd := SHORT(i.id);
data[nAccel].fVirt := SHORT(CHR(f));
INC(nAccel)
END
END;
i := i.next
END
END;
m := m.next
END;
hAccel := WinApi.CreateAcceleratorTable(data[0], nAccel);
IF debug THEN Log.String("new accel table"); Log.Int(nAccel); Log.Int(hAccel); Log.Ln END;
IF hAccel = 0 THEN nAccel := 0 END;
menuBar := HostMenus.menuBar
END;
a := hAccel; n := nAccel
END GetAccelTable;
(* ---------- IOleClientSite ---------- *)
PROCEDURE (this: IOleClientSite) QueryInterface (IN iid: COM.GUID; OUT int: COM.IUnknown): COM.RESULT;
BEGIN
IF COM.QUERY(this, iid, int)
OR COM.QUERY(this.ias, iid, int)
OR COM.QUERY(this.iips, iid, int) THEN RETURN WinApi.S_OK
ELSE RETURN WinApi.E_NOINTERFACE
END
END QueryInterface;
PROCEDURE (this: IOleClientSite) SaveObject (): COM.RESULT;
VAR res: COM.RESULT; ips: WinOle.IPersistStorage;
BEGIN
IF debug THEN Log.String("do save object"); Log.Ln END;
IF (this.obj # NIL) & (this.obj.objUnk # NIL) THEN
res := this.obj.objUnk.QueryInterface(COM.ID(ips), ips);
ASSERT(res >= 0, 100);
res := WinOle.OleSave(ips, this.obj.stg, 1);
ASSERT(res >= 0, 101);
res := ips.SaveCompleted(NIL);
ASSERT(res >= 0, 102);
RETURN WinApi.S_OK
ELSE
RETURN WinApi.E_FAIL
END
END SaveObject;
PROCEDURE (this: IOleClientSite) GetMoniker (
assign, which: INTEGER; OUT mk: WinOle.IMoniker
): COM.RESULT;
BEGIN
RETURN WinApi.E_NOTIMPL
END GetMoniker;
PROCEDURE (this: IOleClientSite) GetContainer (OUT container: WinOle.IOleContainer): COM.RESULT;
BEGIN
RETURN WinApi.E_NOTIMPL
END GetContainer;
PROCEDURE (this: IOleClientSite) ShowObject (): COM.RESULT;
BEGIN
IF debug THEN Log.String("do show object"); Log.Ln END;
(* Container.MakeVisible(object) *)
RETURN WinApi.S_OK
END ShowObject;
PROCEDURE (this: IOleClientSite) OnShowWindow (show: WinApi.BOOL): COM.RESULT;
VAR msg: UpdateMsg;
BEGIN
IF debug THEN Log.String("do show window"); Log.Ln END;
this.obj.open := show # 0; msg.checkSize := FALSE;
Models.Broadcast(this.obj, msg);
RETURN WinApi.S_OK
END OnShowWindow;
PROCEDURE (this: IOleClientSite) RequestNewObjectLayout (): COM.RESULT;
BEGIN
IF debug THEN Log.String("request new layout"); Log.Ln END;
RETURN WinApi.E_NOTIMPL
END RequestNewObjectLayout;
(* ---------- IAdviseSink ---------- *)
PROCEDURE (this: IAdviseSink) OnDataChange (
IN format: WinOle.FORMATETC; IN medium: WinOle.STGMEDIUM
);
BEGIN
IF debug THEN Log.String("on data change"); Log.Ln END
END OnDataChange;
PROCEDURE (this: IAdviseSink) OnViewChange (aspect: SET; index: INTEGER);
VAR msg: UpdateMsg; ips: WinOle.IPersistStorage; res: COM.RESULT; seq: ANYPTR;
BEGIN
IF debug THEN Log.String("on view change"); Log.Ln END;
msg.checkSize := TRUE;
IF ~this.obj.guard THEN Models.Broadcast(this.obj, msg) END;
IF WinOle.OleIsRunning(this.obj.objObj) # 0 THEN (* check dirty *)
res := this.obj.objUnk.QueryInterface(COM.ID(ips), ips);
IF (res >= 0) & (ips.IsDirty() # WinApi.S_FALSE) THEN
IF debug THEN Log.String("set dirty"); Log.Int(ips.IsDirty()); Log.Ln END;
IF this.obj.Domain() # NIL THEN
seq := this.obj.Domain().GetSequencer();
IF seq # NIL THEN
seq(Sequencers.Sequencer).SetDirty(TRUE)
END
ELSIF debug THEN Log.String("nil domain !!!"); Log.Ln
END
END
END
END OnViewChange;
PROCEDURE (this: IAdviseSink) OnRename (moniker: WinOle.IMoniker);
BEGIN
IF debug THEN Log.String("on rename"); Log.Ln END
END OnRename;
PROCEDURE (this: IAdviseSink) OnSave ();
BEGIN
IF debug THEN Log.String("on save"); Log.Ln END
END OnSave;
PROCEDURE (this: IAdviseSink) OnClose ();
BEGIN
IF debug THEN Log.String("on close"); Log.Ln END;
this.obj.open := FALSE
END OnClose;
(* ---------- IOleInPlaceSite ---------- *)
PROCEDURE (this: IOleInPlaceSite) GetWindow (OUT wnd: WinApi.HWND): COM.RESULT;
BEGIN
IF debug THEN Log.String("ip site: get window"); Log.Ln END;
IF this.site.frame # NIL THEN
wnd := this.site.frame.rider(HostPorts.Rider).port.wnd;
RETURN WinApi.S_OK
ELSE RETURN WinApi.E_FAIL
END
END GetWindow;
PROCEDURE (this: IOleInPlaceSite) ContextSensitiveHelp (enter: WinApi.BOOL): COM.RESULT;
BEGIN
IF debug THEN Log.String("ip site: context help"); Log.Ln END;
RETURN WinApi.S_OK
END ContextSensitiveHelp;
PROCEDURE (this: IOleInPlaceSite) CanInPlaceActivate (): COM.RESULT;
BEGIN
IF debug THEN Log.String("ip site: can activate"); Log.Ln END;
IF this.site.frame # NIL THEN RETURN WinApi.S_OK
ELSE RETURN WinApi.S_FALSE
END
END CanInPlaceActivate;
PROCEDURE (this: IOleInPlaceSite) OnInPlaceActivate (): COM.RESULT;
VAR res: COM.RESULT; host: Views.Frame; c: Containers.Controller; style: SET;
BEGIN
IF debug THEN Log.String("ip site: on activate"); Log.Ln END;
res := this.obj.objUnk.QueryInterface(COM.ID(this.obj.objIPObj), this.obj.objIPObj);
IF this.site.frame # NIL THEN
this.site.wnd := this.site.frame.rider(HostPorts.Rider).port.wnd;
style := SYSTEM.VAL(SET, WinApi.GetWindowLong(this.site.wnd, -16));
res := WinApi.SetWindowLong(this.site.wnd, -16, SYSTEM.VAL(INTEGER, style + {25}));
host := Views.HostOf(this.site.frame);
IF (host # NIL) & (host.view IS Containers.View) THEN
c := host.view(Containers.View).ThisController();
c.SetFocus(this.site.frame.view)
END
END;
res := this.site.OnShowWindow(1);
RETURN WinApi.S_OK
END OnInPlaceActivate;
PROCEDURE (this: IOleInPlaceSite) OnUIActivate (): COM.RESULT;
VAR f: Views.Frame; p: HostPorts.Port; win: HostWindows.Window;
BEGIN
IF debug THEN Log.String("ip site: on ui activate"); Log.Ln END;
(* remove user interface *)
f := this.site.frame; p := f.rider(HostPorts.Rider).port;
win := SYSTEM.VAL(HostWindows.Window, WinApi.GetWindowLong(p.wnd, 0));
OleServer.RemoveUI(win);
RETURN WinApi.S_OK
END OnUIActivate;
PROCEDURE (this: IOleInPlaceSite) GetWindowContext (OUT frame: WinOle.IOleInPlaceFrame;
OUT doc: WinOle.IOleInPlaceUIWindow;
OUT pos, clip: WinApi.RECT;
VAR info: WinOle.OLEINPLACEFRAMEINFO): COM.RESULT;
VAR pwin: IOleInPlaceUIWindow; whk: WinHook; fhk: FrameHook; p: HostPorts.Port; f: Views.Frame;
w, h: INTEGER; win: HostWindows.Window; outerSite: WinOle.IOleInPlaceSite; r1, r2: WinApi.RECT;
BEGIN
IF debug THEN Log.String("ip site: get context"); Log.Ln END;
IF this.site.frame = NIL THEN RETURN WinApi.E_FAIL END;
f := this.site.frame; p := f.rider(HostPorts.Rider).port;
pos.left := f.gx DIV f.unit; pos.top := f.gy DIV f.unit;
(*
f.view.context.GetSize(w, h);
*)
pos.right := pos.left + this.obj.rw; pos.bottom := pos.top + this.obj.rh;
clip.left := 0; clip.top := 0; clip.right := p.w; clip.bottom := p.h;
win := SYSTEM.VAL(HostWindows.Window, WinApi.GetWindowLong(p.wnd, 0));
outerSite := OleServer.ContextOf(win);
IF outerSite # NIL THEN
RETURN outerSite.GetWindowContext(frame, doc, r1, r2, info)
ELSE
IF appFrame = NIL THEN
NEW(appFrame);
NEW(fhk); HostWindows.mainHook := fhk
END;
frame := appFrame;
NEW(pwin); doc := pwin; pwin.wnd := p.wnd;
NEW(whk); win.hook := whk; whk.iipw := pwin;
info.fMDIApp := 1;
info.hwndFrame := HostWindows.main;
GetAccelTable(info.haccel, info.cAccelEntries);
RETURN WinApi.S_OK
END
END GetWindowContext;
PROCEDURE (this: IOleInPlaceSite) Scroll (scrollExtent: WinApi.SIZE): COM.RESULT;
BEGIN
IF debug THEN Log.String("ip site: scroll"); Log.Ln END;
(* scroll document *)
RETURN WinApi.S_OK
END Scroll;
PROCEDURE (d: Deactivator) Do;
VAR res: COM.RESULT;
BEGIN
IF d.obj.objIPObj # NIL THEN
res := d.obj.objIPObj.InPlaceDeactivate()
END
END Do;
PROCEDURE (this: IOleInPlaceSite) OnUIDeactivate (undoable: WinApi.BOOL): COM.RESULT;
VAR res: COM.RESULT; win: HostWindows.Window; done: BOOLEAN; d: Deactivator;
BEGIN
IF debug THEN Log.String("ip site: ui deactivate"); Log.Ln END;
(* restore user interface *)
win := SYSTEM.VAL(HostWindows.Window, WinApi.GetWindowLong(this.site.wnd, 0));
OleServer.ResetUI(win, done);
IF ~done & (appFrame # NIL) THEN
IF debug THEN Log.String("reset oberon/f user interface"); Log.Ln END;
res := appFrame.SetMenu(0, 0, 0);
res := appFrame.SetBorderSpace(NIL)
END;
NEW(d); d.obj := this.obj;
Services.DoLater(d, Services.now);
RETURN WinApi.S_OK
END OnUIDeactivate;
PROCEDURE (this: IOleInPlaceSite) OnInPlaceDeactivate (): COM.RESULT;
VAR host: Views.Frame; c: Containers.Controller; style: SET; res: INTEGER;
BEGIN
res := this.site.OnShowWindow(0);
IF debug THEN Log.String("ip site: deactivate"); Log.Ln END;
IF this.site.frame # NIL THEN
IF ~this.obj.guard THEN
host := Views.HostOf(this.site.frame);
IF (host # NIL) & (host.view IS Containers.View) THEN
c := host.view(Containers.View).ThisController();
IF debug THEN Log.String("remove focus"); Log.Ln END;
c.SetFocus(NIL);
c.SetSingleton(this.site.frame.view)
END
END;
style := SYSTEM.VAL(SET, WinApi.GetWindowLong(this.site.wnd, -16));
res := WinApi.SetWindowLong(this.site.wnd, -16, SYSTEM.VAL(INTEGER, style - {25}))
END;
(* minimal undo support *)
DoVerb(this.obj, NIL, WinOle.OLEIVERB_DISCARDUNDOSTATE);
this.obj.objIPObj := NIL;
RETURN WinApi.S_OK
END OnInPlaceDeactivate;
PROCEDURE (this: IOleInPlaceSite) DiscardUndoState (): COM.RESULT;
BEGIN
IF debug THEN Log.String("ip site: discard undo"); Log.Ln END;
(* no undo state *)
RETURN WinApi.E_NOTIMPL
END DiscardUndoState;
PROCEDURE (this: IOleInPlaceSite) DeactivateAndUndo (): COM.RESULT;
VAR res: COM.RESULT;
BEGIN
IF debug THEN Log.String("ip site: deactivate & undo"); Log.Ln END;
res := this.obj.objIPObj.InPlaceDeactivate();
RETURN WinApi.S_OK
END DeactivateAndUndo;
PROCEDURE (this: IOleInPlaceSite) OnPosRectChange (IN posRect: WinApi.RECT): COM.RESULT;
VAR pos, clip: WinApi.RECT; res: COM.RESULT; p: HostPorts.Port; f: Views.Frame; w, h: INTEGER;
host: Views.Frame; c: Containers.Controller; g: BOOLEAN; v: Views.View; size: WinApi.SIZE;
BEGIN
f := this.site.frame;
IF (f = NIL) OR (f.rider = NIL) THEN RETURN WinApi.E_FAIL END;
host := Views.HostOf(f); v := f.view;
p := f.rider(HostPorts.Rider).port;
IF debug THEN
Log.String("ip site: on pos rect change");
Log.Int((posRect.right - posRect.left) * f.unit DIV oleUnit);
Log.Int((posRect.bottom - posRect.top) * f.unit DIV oleUnit);
Log.Ln;
res := this.obj.objObj.GetExtent(WinOle.DVASPECT_CONTENT, size);
IF res = WinApi.S_OK THEN
Log.String(" get extent");
Log.Int(size.cx); Log.Int(size.cy)
ELSE
Log.String(" get extent failed")
END;
Log.Ln;
v.context.GetSize(w, h);
Log.String(" get size");
Log.Int(w DIV oleUnit); Log.Int(h DIV oleUnit);
Log.Ln
END;
this.obj.rw := posRect.right - posRect.left;
this.obj.rh := posRect.bottom - posRect.top;
UpdateSizes(this.site.frame.view(View), TRUE, TRUE);
(*
g := this.obj.focusGuard; this.obj.focusGuard := TRUE;
v.context.SetSize((posRect.right - posRect.left) * f.unit, (posRect.bottom - posRect.top) * f.unit);
IF host # NIL THEN (* update saved frame *)
Views.ValidateRoot(Views.RootOf(host));
f := Views.ThisFrame(host, v);
this.site.frame := f;
END;
IF this.obj.objIPObj # NIL THEN
pos.left := f.gx DIV f.unit; pos.top := f.gy DIV f.unit;
v.context.GetSize(w, h);
pos.right := pos.left + w DIV f.unit; pos.bottom := pos.top + h DIV f.unit;
clip.left := 0; clip.top := 0; clip.right := p.w; clip.bottom := p.h;
IF debug THEN Log.String("set object rects"); Log.Ln END;
res := this.obj.objIPObj.SetObjectRects(pos, clip);
IF (host # NIL) & (host.view IS Containers.View) THEN
c := host.view(Containers.View).ThisController();
c.SetFocus(v)
END
END;
this.obj.focusGuard := g;
*)
RETURN WinApi.S_OK
END OnPosRectChange;
(* ---------- IOleInPlaceUIWindow ---------- *)
PROCEDURE (this: IOleInPlaceUIWindow) GetWindow (OUT wnd: WinApi.HWND): COM.RESULT;
BEGIN
IF debug THEN Log.String("ip win: get window"); Log.Ln END;
wnd := this.wnd;
RETURN WinApi.S_OK
END GetWindow;
PROCEDURE (this: IOleInPlaceUIWindow) ContextSensitiveHelp (enter: WinApi.BOOL): COM.RESULT;
VAR res: COM.RESULT;
BEGIN
IF debug THEN Log.String("ip win: context help"); Log.Ln END;
IF this.iipao # NIL THEN res := this.iipao.ContextSensitiveHelp(enter) END;
RETURN WinApi.S_OK
END ContextSensitiveHelp;
PROCEDURE (this: IOleInPlaceUIWindow) GetBorder (OUT border: WinApi.RECT): COM.RESULT;
VAR res: INTEGER;
BEGIN
res := WinApi.GetClientRect(this.wnd, border);
IF debug THEN
Log.String("ip win: get border");
Log.Int(border.left); Log.Int(border.top);
Log.Int(border.right); Log.Int(border.bottom);
Log.Ln
END;
RETURN WinApi.S_OK
END GetBorder;
PROCEDURE (this: IOleInPlaceUIWindow) RequestBorderSpace (
IN width: WinOle.BORDERWIDTHS
): COM.RESULT;
BEGIN
IF debug THEN
Log.String("ip win: request space");
Log.Int(width.left); Log.Int(width.top);
Log.Int(width.right); Log.Int(width.bottom);
Log.Ln
END;
RETURN WinApi.INPLACE_E_NOTOOLSPACE
END RequestBorderSpace;
PROCEDURE (this: IOleInPlaceUIWindow) SetBorderSpace (
IN [nil] width: WinOle.BORDERWIDTHS
): COM.RESULT;
BEGIN
IF debug THEN
Log.String("ip win: set space");
IF VALID(width) THEN
Log.Int(width.left); Log.Int(width.top);
Log.Int(width.right); Log.Int(width.bottom)
ELSE Log.String(" nil")
END;
Log.Ln
END;
IF ~VALID(width) OR (width.left = 0) & (width.top = 0) & (width.right = 0) & (width.bottom = 0) THEN
RETURN WinApi.S_OK
ELSE RETURN WinApi.OLE_E_INVALIDRECT
END
END SetBorderSpace;
PROCEDURE (this: IOleInPlaceUIWindow) SetActiveObject (
obj: WinOle.IOleInPlaceActiveObject; name: WinApi.PtrWSTR
): COM.RESULT;
BEGIN
IF debug THEN Log.String("ip win: set active obj"); Log.Ln END;
this.iipao := obj;
RETURN WinApi.S_OK
END SetActiveObject;
(* ---------- WinHook ---------- *)
PROCEDURE (hk: WinHook) Activate (do: BOOLEAN);
VAR res: COM.RESULT;
BEGIN
IF (hk.iipw # NIL) & (hk.iipw.iipao # NIL) THEN
IF do THEN res := hk.iipw.iipao.OnDocWindowActivate(1)
ELSE
res := hk.iipw.iipao.OnDocWindowActivate(0);
res := WinApi.SendMessage(HostWindows.client, 560, HostMenus.menuBar, winMenu);
res := WinApi.DrawMenuBar(HostWindows.main);
HostWindows.SetMainBorderWidth(0, 0, 0, 0);
HostMenus.isCont := FALSE
END
END
END Activate;
PROCEDURE (hk: WinHook) Focus (do: BOOLEAN);
VAR res: COM.RESULT; wnd: WinApi.HWND;
BEGIN
IF do & (hk.iipw # NIL) & (hk.iipw.iipao # NIL) THEN
res := hk.iipw.iipao.GetWindow(wnd);
res := WinApi.SetFocus(wnd)
END
END Focus;
PROCEDURE (hk: WinHook) Resize (w, h: INTEGER);
VAR res: COM.RESULT; rect: WinApi.RECT;
BEGIN
IF (hk.iipw # NIL) & (hk.iipw.iipao # NIL) THEN
res := WinApi.GetClientRect(hk.iipw.wnd, rect);
res := hk.iipw.iipao.ResizeBorder(rect, hk.iipw, 0)
END
END Resize;
(* ---------- IOleInPlaceFrame ---------- *)
PROCEDURE (this: IOleInPlaceFrame) GetWindow (OUT wnd: WinApi.HWND): COM.RESULT;
BEGIN
IF debug THEN Log.String("ip frame: get window"); Log.Ln END;
wnd := HostWindows.main;
RETURN WinApi.S_OK
END GetWindow;
PROCEDURE (this: IOleInPlaceFrame) ContextSensitiveHelp (enter: WinApi.BOOL): COM.RESULT;
VAR res: COM.RESULT;
BEGIN
IF debug THEN Log.String("ip frame: context help"); Log.Ln END;
IF this.iipao # NIL THEN res := this.iipao.ContextSensitiveHelp(enter) END;
RETURN WinApi.S_OK
END ContextSensitiveHelp;
PROCEDURE (this: IOleInPlaceFrame) GetBorder (OUT border: WinApi.RECT): COM.RESULT;
BEGIN
HostWindows.GetMainBorder(border.left, border.top, border.right, border.bottom);
IF debug THEN
Log.String("ip frame: get border");
Log.Int(border.left); Log.Int(border.top);
Log.Int(border.right); Log.Int(border.bottom);
Log.Ln
END;
RETURN WinApi.S_OK
END GetBorder;
PROCEDURE (this: IOleInPlaceFrame) RequestBorderSpace (IN width: WinOle.BORDERWIDTHS): COM.RESULT;
BEGIN
IF debug THEN
Log.String("ip frame: request space");
Log.Int(width.left); Log.Int(width.top);
Log.Int(width.right); Log.Int(width.bottom);
Log.Ln
END;
RETURN WinApi.S_OK
END RequestBorderSpace;
PROCEDURE (this: IOleInPlaceFrame) SetBorderSpace (IN [nil] width: WinOle.BORDERWIDTHS): COM.RESULT;
BEGIN
IF debug THEN
Log.String("ip frame: set space");
IF VALID(width) THEN
Log.Int(width.left); Log.Int(width.top);
Log.Int(width.right); Log.Int(width.bottom)
ELSE Log.String(" nil")
END;
Log.Ln
END;
IF VALID(width) THEN
HostWindows.SetMainBorderWidth(width.left, width.top, width.right, width.bottom)
ELSE
HostWindows.SetMainBorderWidth(0, 0, 0, 0)
END;
RETURN WinApi.S_OK
END SetBorderSpace;
PROCEDURE (this: IOleInPlaceFrame) SetActiveObject (obj: WinOle.IOleInPlaceActiveObject;
name: WinApi.PtrWSTR): COM.RESULT;
BEGIN
IF debug THEN Log.String("ip frame: set active obj"); Log.Ln END;
this.iipao := obj;
RETURN WinApi.S_OK
END SetActiveObject;
PROCEDURE (this: IOleInPlaceFrame) InsertMenus (menu: WinApi.HMENU;
VAR widths: WinOle.OLEMENUGROUPWIDTHS): COM.RESULT;
VAR res, n, p: INTEGER; m: HostMenus.Menu; ss: ARRAY 256 OF SHORTCHAR;
BEGIN
IF debug THEN Log.String("ip frame: insert menus"); Log.Ln END;
m := HostMenus.menus; p := 0;
WHILE p < 6 DO
WHILE (m # NIL) & (m.class < p) DO m := m.next END;
n := 0;
WHILE (m # NIL) & (m.class = p) DO
ss := SHORT(m.menu$);
res := WinApi.AppendMenu(menu, WinApi.MF_POPUP, m.menuH, ss);
m := m.next; INC(n)
END;
widths.width[p] := n;
INC(p, 2)
END;
m := HostMenus.menus;
WHILE (m # NIL) & ~m.isWinMenu DO m := m.next END;
IF m # NIL THEN winMenu := m.menuH ELSE winMenu := 0 END;
RETURN WinApi.S_OK
END InsertMenus;
PROCEDURE (this: IOleInPlaceFrame) SetMenu (menu: WinApi.HMENU; oleMenu: WinOle.HOLEMENU;
activeObj: WinApi.HWND): COM.RESULT;
VAR res: INTEGER;
BEGIN
IF debug THEN Log.String("ip frame: set menu"); Log.Int(menu); Log.Ln END;
IF menu # 0 THEN
this.objWnd := activeObj;
res := WinApi.SendMessage(HostWindows.client, 560, menu, winMenu);
HostMenus.isCont := TRUE
ELSIF this.objWnd # 0 THEN
this.objWnd := 0;
res := WinApi.SendMessage(HostWindows.client, 560, HostMenus.menuBar, winMenu);
HostMenus.isCont := FALSE
END;
res := WinApi.DrawMenuBar(HostWindows.main);
RETURN WinOle.OleSetMenuDescriptor(oleMenu, HostWindows.main, activeObj, this, this.iipao)
END SetMenu;
PROCEDURE (this: IOleInPlaceFrame) RemoveMenus (menu: WinApi.HMENU): COM.RESULT;
VAR m: HostMenus.Menu; i: INTEGER; sm: WinApi.HMENU; res: INTEGER;
BEGIN
IF debug THEN Log.String("ip frame: remove menus"); Log.Ln END;
i := WinApi.GetMenuItemCount(menu);
WHILE i > 0 DO
DEC(i); sm := WinApi.GetSubMenu(menu, i);
m := HostMenus.menus;
WHILE (m # NIL) & (m.menuH # sm) DO m := m.next END;
IF m # NIL THEN res := WinApi.RemoveMenu(menu, i, WinApi.MF_BYPOSITION) END
END;
RETURN WinApi.S_OK
END RemoveMenus;
PROCEDURE (this: IOleInPlaceFrame) SetStatusText (text: WinApi.PtrWSTR): COM.RESULT;
VAR res, i: INTEGER; str: ARRAY 256 OF SHORTCHAR;
BEGIN
IF debug THEN Log.String("ip frame: set status"); Log.Ln END;
IF Dialog.showsStatus THEN
IF text # NIL THEN
i := 0;
WHILE (i < LEN(str) - 1) & (text[i] # 0X) DO str[i] := SHORT(text[i]); INC(i) END;
str[i] := 0X;
res := WinApi.SetWindowText(HostWindows.status, str);
res := WinApi.UpdateWindow(HostWindows.status)
END;
RETURN WinApi.S_OK
ELSE
RETURN WinApi.E_FAIL
END
END SetStatusText;
PROCEDURE (this: IOleInPlaceFrame) EnableModeless (enable: WinApi.BOOL): COM.RESULT;
BEGIN
IF debug THEN Log.String("ip frame: enable modeless"); Log.Ln END;
(* enable/disable modeless dialogs *)
RETURN WinApi.S_OK
END EnableModeless;
PROCEDURE (this: IOleInPlaceFrame) TranslateAccelerator (IN msg: WinApi.MSG; id: SHORTINT): COM.RESULT;
VAR res: COM.RESULT; r: INTEGER; m: WinApi.MSG;
BEGIN
IF debug THEN Log.String("ip frame: translate accelerator"); Log.Int(id); Log.Ln END;
res := WinApi.S_OK;
IF (id >= 100) & (id < HostMenus.lastId) THEN
r := WinApi.SendMessage(HostWindows.main, 273, id + 65536, 0)
ELSE
m := msg;
r := WinApi.TranslateMDISysAccel(HostWindows.client, m);
IF r = 0 THEN res := WinApi.S_FALSE END
END;
RETURN res
END TranslateAccelerator;
(* ---------- FrameHook ---------- *)
PROCEDURE (hk: FrameHook) Activate (do: BOOLEAN);
VAR res: COM.RESULT;
BEGIN
IF (appFrame # NIL) & (appFrame.iipao # NIL) THEN
IF do THEN res := appFrame.iipao.OnFrameWindowActivate(1)
ELSE res := appFrame.iipao.OnFrameWindowActivate(0)
END
END
END Activate;
PROCEDURE (hk: FrameHook) Resize (w, h: INTEGER);
VAR res: COM.RESULT; rect: WinApi.RECT;
BEGIN
IF (appFrame # NIL) & (appFrame.iipao # NIL) THEN
HostWindows.GetMainBorder(rect.left, rect.top, rect.right, rect.bottom);
res := appFrame.iipao.ResizeBorder(rect, appFrame, 1)
END
END Resize;
PROCEDURE (hk: FrameHook) Focus (on: BOOLEAN), EMPTY;
(* ---------- View ---------- *)
PROCEDURE (v: View) GetNewFrame (VAR frame: Views.Frame);
VAR f: Frame;
BEGIN
NEW(f); frame := f
END GetNewFrame;
PROCEDURE InitModel(v: View; m: Model);
BEGIN
v.model := m; Stores.Join(v, m);
IF m.view = NIL THEN m.view := v END;
OpenLink(m)
END InitModel;
PROCEDURE (v: View) Internalize (VAR rd: Stores.Reader);
VAR thisVersion: INTEGER; s: Stores.Store;
BEGIN
v.Internalize^(rd); IF rd.cancelled THEN RETURN END;
rd.ReadVersion(minViewVersion, 1 (* maxViewVersion *), thisVersion); IF rd.cancelled THEN RETURN END;
rd.ReadStore(s); ASSERT(s # NIL, 100); ASSERT(s IS Model, 101);
InitModel(v, s(Model))
END Internalize;
PROCEDURE (v: View) Externalize (VAR wr: Stores.Writer);
BEGIN
v.Externalize^(wr);
wr.WriteVersion(maxViewVersion);
wr.WriteStore(v.model)
END Externalize;
(*
PROCEDURE (v: View) PropagateDomain;
BEGIN
Stores.InitDomain(v.model, v.Domain())
END PropagateDomain;
*)
PROCEDURE (v: View) CopyFromModelView (source: Views.View; model: Models.Model);
BEGIN
InitModel(v, model(Model))
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 res: COM.RESULT; dc: WinApi.HDC; rect, wrect: WinApi.RECT; w, h: INTEGER;
size: WinApi.SIZE; g: BOOLEAN; p: HostPorts.Port; s: SET; fl, ft, fr, fb: INTEGER;
n: Notifier;
BEGIN
IF ~v.hasNotifier & (v.Domain() # NIL)
& (v.Domain().GetSequencer() # NIL) & (v.Domain().GetSequencer() IS Sequencers.Sequencer) THEN
NEW(n); n.model := v.model;
v.Domain().GetSequencer()(Sequencers.Sequencer).InstallNotifier(n);
v.hasNotifier := TRUE
END;
IF (v.model.objObj # NIL) & (v.model.objView # NIL) & Visible(v.model, f) THEN
v.context.GetSize(w, h);
IF (w # v.model.w) OR (h # v.model.h) THEN
size.cx := w DIV oleUnit; size.cy := h DIV oleUnit;
g := v.model.guard; v.model.guard := TRUE;
IF WinOle.OleIsRunning(v.model.objObj) # 0 THEN
IF debug THEN Log.String("set size (running)"); Log.Int(size.cx); Log.Int(size.cy); Log.Ln END;
res := v.model.objObj.SetExtent(WinOle.DVASPECT_CONTENT, size)
ELSIF v.model.flags * WinOle.OLEMISC_RECOMPOSEONRESIZE # {} THEN
res := WinOle.OleRun(v.model.objUnk);
IF debug THEN Log.String("set size (recomp)"); Log.Int(size.cx); Log.Int(size.cy); Log.Ln END;
res := v.model.objObj.SetExtent(WinOle.DVASPECT_CONTENT, size);
res := v.model.objObj.Update();
res := v.model.objObj.Close(WinOle.OLECLOSE_SAVEIFDIRTY)
END;
v.model.w := w; v.model.h := h;
v.model.guard := g
END;
p := f.rider(HostPorts.Rider).port; dc := p.dc;
rect.left := f.gx DIV f.unit;
rect.top := f.gy DIV f.unit;
rect.right := (f.gx + w) DIV f.unit;
rect.bottom := (f.gy + h) DIV f.unit;
wrect.left := 0;
wrect.top := 0;
wrect.right := p.w;
wrect.bottom := p.h;
res := WinApi.SaveDC(dc);
IF p.wnd # 0 THEN res := WinApi.SelectClipRgn(dc, 0) END;
f.rider.GetRect(fl, ft, fr, fb);
res := WinApi.IntersectClipRect(dc, fl, ft, fr, fb);
s := WinApi.SetTextAlign(dc, {});
res := v.model.objView.Draw(WinOle.DVASPECT_CONTENT, -1, 0, NIL, 0, dc, rect, wrect, NIL, 0);
h := WinApi.RestoreDC(dc, -1);
IF debug THEN
IF p.wnd # 0 THEN
Log.String("draw"); Log.Int(res);
Log.Int(SYSTEM.VAL(INTEGER, p));
Log.Int(p.wnd); Log.Int(dc);
Log.Int(rect.left); Log.Int(rect.top); Log.Int(rect.right); Log.Int(rect.bottom);
Log.Int(wrect.left); Log.Int(wrect.top); Log.Int(wrect.right); Log.Int(wrect.bottom);
Log.Ln
ELSE
Log.String("draw (p)"); Log.Int(res);
Log.Int(SYSTEM.VAL(INTEGER, p));
Log.Int(p.wnd); Log.Int(dc);
Log.Int(rect.left); Log.Int(rect.top); Log.Int(rect.right); Log.Int(rect.bottom);
Log.Int(wrect.left); Log.Int(wrect.top); Log.Int(wrect.right); Log.Int(wrect.bottom);
Log.Ln
END
END
END
END Restore;
PROCEDURE (v: View) RestoreMarks (f: Views.Frame; l, t, r, b: INTEGER);
BEGIN
IF v.model.open & ((v.model.objIPObj = NIL) OR (v.model.site.frame # f))
& ~v.model.focusGuard & ~Views.IsPrinterFrame(f) THEN
f.MarkRect(l, t, r, b, Ports.fill, HostPorts.focusPat, TRUE)
END
END RestoreMarks;
PROCEDURE (v: View) HandleModelMsg (VAR msg: Models.Message);
VAR res: COM.RESULT; size: WinApi.SIZE; ow, oh, w, h: INTEGER;
c: Containers.Controller; s: Views.View; path: BOOLEAN;
BEGIN
WITH msg: UpdateMsg DO
IF debug THEN Log.String("update"); Log.Ln END;
UpdateSizes(v, msg.checkSize, FALSE);
(*
res := v.model.objView.GetExtent(WinOle.DVASPECT_CONTENT, -1, NIL, size);
IF debug THEN Log.String("update"); Log.Int(size.cx); Log.Int(size.cy); Log.Ln END;
IF res = WinApi.S_OK THEN
ow := size.cx * oleUnit; oh := size.cy * oleUnit;
v.context.GetSize(w, h);
IF (w # ow) OR (h # oh) THEN
IF debug THEN Log.String("set size"); Log.Int(size.cx); Log.Int(size.cy); Log.Ln END;
path := Controllers.path;
Controllers.SetCurrentPath(Controllers.targetPath);
c := Containers.Focus();
Controllers.SetCurrentPath(path);
s := c.Singleton();
v.context.SetSize(ow, oh);
IF c.Singleton() # s THEN c.SetSingleton(s) END;
v.model.w := ow; v.model.h := oh
END;
END;
*)
Views.Update(v, Views.keepFrames)
ELSE
END
END HandleModelMsg;
PROCEDURE (v: View) HandleCtrlMsg (f: Views.Frame; VAR msg: Controllers.Message; VAR focus: Views.View);
VAR res: COM.RESULT; g: BOOLEAN;
BEGIN
WITH msg: Controllers.MarkMsg DO
IF msg.focus & ~v.model.focusGuard THEN
g := v.model.guard; v.model.guard := TRUE;
IF ~msg.show THEN (* defocus *)
IF debug THEN Log.String("defocus"); Log.Ln END;
IF v.model.objIPObj # NIL THEN
res := v.model.objIPObj.InPlaceDeactivate()
END;
(*
ELSIF msg.show & (v.model.flags * WinOle.OLEMISC_INSIDEOUT # {}) THEN
DoVerb(v.model, f, WinOle.OLEIVERB_SHOW)
*)
END;
v.model.guard := g
END
| msg: Controllers.TrackMsg DO
IF v.model.flags * WinOle.OLEMISC_INSIDEOUT # {} THEN
DoVerb(v.model, f, WinOle.OLEIVERB_SHOW)
END
ELSE
END
END HandleCtrlMsg;
PROCEDURE (v: View) HandlePropMsg (VAR msg: Properties.Message);
VAR size: WinApi.SIZE; res: COM.RESULT; i: INTEGER;
iev: WinOle.IEnumOLEVERB; ov: ARRAY 1 OF WinOle.OLEVERB; pstr: WinApi.PtrWSTR;
BEGIN
WITH msg: Properties.SizePref DO
IF (msg.w = Views.undefined) OR (msg.h = Views.undefined) THEN
res := v.model.objView.GetExtent(WinOle.DVASPECT_CONTENT, -1, NIL, size);
IF res >= 0 THEN
IF debug THEN Log.String("get size (prefs)"); Log.Int(size.cx); Log.Int(size.cy); Log.Ln END;
msg.w := size.cx * (Ports.mm DIV 100);
msg.h := size.cy * (Ports.mm DIV 100)
ELSE
IF debug THEN Log.String("get size (prefs) (no size)"); Log.Ln END;
msg.w := 60 * Ports.mm;
msg.h := 60 * Ports.mm
END
END
| msg: Properties.FocusPref DO
IF v.model.flags * WinOle.OLEMISC_INSIDEOUT # {} THEN
msg.hotFocus := TRUE
END
| msg: Properties.PollMsg DO
PollProp(v.model, msg.prop)
| msg: Properties.SetMsg DO
SetProp(v.model, msg.prop)
| msg: Properties.PollVerbMsg DO
res := v.model.objObj.EnumVerbs(iev);
IF res >= 0 THEN
REPEAT
res := iev.Next(1, ov, NIL)
UNTIL (res # WinApi.S_OK) OR (ov[0].lVerb = msg.verb);
IF res = WinApi.S_OK THEN
i := 0;
IF ov[0].lpszVerbName # NIL THEN
WHILE ov[0].lpszVerbName[i] # 0X DO msg.label[i] := SHORT(ov[0].lpszVerbName[i]); INC(i) END
END;
msg.label[i] := 0X;
msg.disabled := 0 IN ov[0].fuFlags;
msg.checked := 3 IN ov[0].fuFlags
END
END
| msg: Properties.DoVerbMsg DO
DoVerb(v.model, msg.frame, SHORT(msg.verb))
| msg: HostMenus.TypeMsg DO
res := v.model.objObj.GetUserType(WinOle.USERCLASSTYPE_SHORT, pstr);
IF res >= 0 THEN
i := 0;
WHILE pstr[i] # 0X DO msg.type[i] := SHORT(pstr[i]); INC(i) END;
msg.type[i] := 0X;
WinOle.CoTaskMemFree(SYSTEM.VAL(WinApi.PtrVoid, pstr))
END
ELSE
END
END HandlePropMsg;
(* ---------- Frame ---------- *)
PROCEDURE (f: Frame) SetOffset (gx, gy: INTEGER);
VAR obj: Model; pos, clip: WinApi.RECT; w, h: INTEGER; p: HostPorts.Port; res: COM.RESULT;
BEGIN
f.SetOffset^(gx, gy);
obj := f.view(View).model;
IF (obj.site.frame = f) & (obj.objIPObj # NIL) THEN
IF debug THEN Log.String("set offset"); Log.Ln END;
UpdateSizes(f.view(View), FALSE, TRUE)
(*
IF debug THEN Log.String("set object rects"); Log.Ln END;
p := f.rider(HostPorts.Rider).port;
pos.left := f.gx DIV f.unit; pos.top := f.gy DIV f.unit;
f.view.context.GetSize(w, h);
pos.right := pos.left + w DIV f.unit; pos.bottom := pos.top + h DIV f.unit;
clip.left := 0; clip.top := 0; clip.right := p.w; clip.bottom := p.h;
res := obj.objIPObj.SetObjectRects(pos, clip);
*)
END
END SetOffset;
PROCEDURE (f: Frame) Close;
BEGIN
(*f.Close^;*)
IF f = f.view(View).model.site.frame THEN
f.view(View).model.site.frame := NIL
END
END Close;
(* ---------- Model ---------- *)
PROCEDURE Init (model: Model);
VAR res: COM.RESULT; ilb: WinOle.ILockBytes;
BEGIN
NEW(model.site); model.site.obj := model;
NEW(model.site.ias, model.site); model.site.ias.obj := model; model.site.ias.site := model.site;
NEW(model.site.iips, model.site); model.site.iips.obj := model; model.site.iips.site := model.site;
res := WinOle.CreateILockBytesOnHGlobal(0, 1, ilb);
ASSERT(res >= 0, 100);
res := WinOle.StgCreateDocfileOnILockBytes(ilb,
WinOle.STGM_CREATE + WinOle.STGM_READWRITE + WinOle.STGM_SHARE_EXCLUSIVE, 0, model.stg);
ASSERT(res >= 0, 101)
END Init;
PROCEDURE Setup (model: Model; object: COM.IUnknown);
VAR res: COM.RESULT; size: WinApi.SIZE; a, b: ARRAY 64 OF CHAR;
BEGIN
model.objUnk := object;
res := object.QueryInterface(COM.ID(model.objView), model.objView);
ASSERT(res >= 0, 102);
res := model.objView.SetAdvise(WinOle.DVASPECT_CONTENT, {}, model.site.ias);
ASSERT(res >= 0, 103);
res := object.QueryInterface(COM.ID(model.objObj), model.objObj);
ASSERT(res >= 0, 104);
res := model.objObj.SetClientSite(model.site);
ASSERT(res >= 0, 105);
res := model.objObj.Advise(model.site.ias, model.advConn);
IF debug THEN Log.String("setup "); Log.Int(model.advConn); Log.Ln END;
(*
res := WinOle.OleSetContainedObject(object, 1);
ASSERT(res >= 0, 107);
*)
a := "BlackBox"; b := "BlackBox Document";
res := model.objObj.SetHostNames(a, b);
IF debug & (res < 0) THEN Log.String("set host names"); Log.Int(res); Log.Ln END;
model.open := FALSE;
res := model.objObj.GetMiscStatus(WinOle.DVASPECT_CONTENT, model.flags);
res := model.objView.GetExtent(WinOle.DVASPECT_CONTENT, -1, NIL, size);
IF debug THEN Log.String("get size (setup)"); Log.Int(size.cx); Log.Int(size.cy); Log.Ln END;
model.w := size.cx * oleUnit; model.h := size.cy * oleUnit;
(*
OpenLinks(model)
*)
END Setup;
PROCEDURE (n: Notifier) Notify (VAR msg: Sequencers.Message);
VAR model: Model; res: COM.RESULT;
BEGIN
IF msg IS Sequencers.RemoveMsg THEN
model := n.model;
Disconnect(model);
IF debug THEN Log.String("release "); Log.Int(model.advConn); Log.Ln END;
IF model.objView # NIL THEN
res := model.objView.SetAdvise(WinOle.DVASPECT_CONTENT, {}, NIL);
model.objView := NIL
END;
IF model.objObj # NIL THEN
res := model.objObj.Close(WinOle.OLECLOSE_SAVEIFDIRTY);
res := model.objObj.SetClientSite(NIL);
res := model.objObj.Unadvise(model.advConn);
model.objObj := NIL
END;
model.objUnk := NIL
END
END Notify;
(*
PROCEDURE (model: Model) PropagateDomain;
VAR n: Notifier; d: Stores.Domain;
BEGIN
OpenLink(model);
NEW(n); n.model := model; d := model.Domain();
WITH d: Sequencers.Sequencer DO d.InstallNotifier(n) ELSE END
END PropagateDomain;
*)
PROCEDURE (model: Model) Internalize (VAR rd: Stores.Reader);
VAR thisVersion: INTEGER; stg: WinOle.IStorage; ilb: WinOle.ILockBytes;
res: COM.RESULT; object: COM.IUnknown;
BEGIN
model.Internalize^(rd); IF rd.cancelled THEN RETURN END;
rd.ReadVersion(minModelVersion, maxModelVersion, thisVersion); IF rd.cancelled THEN RETURN END;
Init(model);
IF thisVersion = 1 THEN rd.ReadXString(model.link) END;
ilb := OleStorage.NewReadILockBytes(rd.rider);
ASSERT(ilb # NIL);
res := WinOle.StgOpenStorageOnILockBytes(ilb, NIL,
WinOle.STGM_DIRECT + WinOle.STGM_READWRITE + WinOle.STGM_SHARE_EXCLUSIVE, NIL, 0, stg);
ASSERT(res >= 0, 100);
res := stg.CopyTo(0, NIL, NIL, model.stg);
res := WinOle.OleLoad(model.stg, COM.ID(object), model.site, object);
ASSERT(res >= 0, 101);
res := ilb.Flush(); (* resynchronise reader *)
Setup(model, object)
END Internalize;
PROCEDURE (model: Model) Externalize (VAR wr: Stores.Writer);
VAR stg: WinOle.IStorage; res: COM.RESULT; ips: WinOle.IPersistStorage; ilb: WinOle.ILockBytes; g: BOOLEAN;
BEGIN
g := model.guard; model.guard := TRUE;
IF debug THEN Log.String("externalize (m)"); Log.Ln END;
model.Externalize^(wr);
IF model.link # "" THEN wr.WriteVersion(1); wr.WriteXString(model.link)
ELSE wr.WriteVersion(0)
END;
ilb := OleStorage.NewWriteILockBytes(wr.rider);
res := WinOle.StgCreateDocfileOnILockBytes(ilb, WinOle.STGM_CREATE
+ WinOle.STGM_READWRITE + WinOle.STGM_SHARE_EXCLUSIVE, 0, stg);
ASSERT(res >= 0, 100);
IF debug THEN Log.String("externalize (1)"); Log.Ln END;
res := model.objUnk.QueryInterface(COM.ID(ips), ips);
ASSERT(res >= 0, 101);
IF debug THEN Log.String("externalize (2)"); Log.Ln END;
res := WinOle.OleSave(ips, stg, 0);
ASSERT(res >= 0, 102);
IF debug THEN Log.String("externalize (3)"); Log.Ln END;
res := ilb.Flush(); (* resynchronise writer *)
IF debug THEN Log.String("externalize (4)"); Log.Ln END;
res := ips.SaveCompleted(NIL);
ASSERT(res >= 0, 103);
model.guard := g;
IF debug THEN Log.String("externalized (m)"); Log.Ln END
END Externalize;
PROCEDURE (model: Model) CopyFrom (source: Stores.Store);
VAR res: COM.RESULT; ips: WinOle.IPersistStorage; object: COM.IUnknown;
BEGIN
WITH source: Model DO
Init(model);
res := source.objUnk.QueryInterface(COM.ID(ips), ips);
ASSERT(res >= 0, 100);
res := WinOle.OleSave(ips, model.stg, 0);
ASSERT(res >= 0, 101);
res := ips.SaveCompleted(NIL);
ASSERT(res >= 0, 102);
res := WinOle.OleLoad(model.stg, COM.ID(object), model.site, object);
model.link := source.link$;
Setup(model, object)
END
END CopyFrom;
(*
PROCEDURE (model: Model) InitFrom (source: Models.Model);
VAR res: COM.RESULT; ips: WinOle.IPersistStorage; object: COM.IUnknown;
BEGIN
WITH source: Model DO
Init(model);
res := source.objUnk.QueryInterface(COM.ID(ips), ips);
ASSERT(res >= 0, 100);
res := WinOle.OleSave(ips, model.stg, 0);
ASSERT(res >= 0, 101);
res := ips.SaveCompleted(NIL);
ASSERT(res >= 0, 102);
res := WinOle.OleLoad(model.stg, COM.ID(object), model.site, object);
model.link := source.link$;
Setup(model, object)
END
END InitFrom;
*)
(* ---------- import / export ---------- *)
PROCEDURE ImportInfo* (VAR med: WinOle.STGMEDIUM; VAR type: Stores.TypeName;
OUT w, h, rx, ry: INTEGER; OUT isSingle: BOOLEAN);
VAR hnd: WinApi.HGLOBAL; p: WinOle.PtrOBJECTDESCRIPTOR; res: INTEGER;
BEGIN
hnd := MediumGlobal(med);
p := SYSTEM.VAL(WinOle.PtrOBJECTDESCRIPTOR, WinApi.GlobalLock(hnd));
type := "OleClient.View";
w := p.sizel.cx * oleUnit;
h := p.sizel.cy * oleUnit;
rx := p.pointl.x * oleUnit;
ry := p.pointl.x * oleUnit;
isSingle := TRUE;
res := WinApi.GlobalUnlock(hnd)
END ImportInfo;
PROCEDURE Import* (
VAR med: WinOle.STGMEDIUM; OUT v: Views.View; OUT w, h: INTEGER; OUT isSingle: BOOLEAN
);
VAR cv: View; model: Model; res: COM.RESULT; object: COM.IUnknown;
BEGIN
OleServer.Import(med, v, w, h, isSingle);
IF v = NIL THEN (* no BlackBox object *)
NEW(model); Init(model);
res := WinOle.OleCreateFromData(OleData.dataObj, COM.ID(object),
WinOle.OLERENDER_DRAW, NIL, model.site, model.stg, object);
ASSERT(res >= 0, 100);
Setup(model, object);
NEW(cv); InitModel(cv, model);
v := cv; w := 0; h := 0; isSingle := TRUE
END
END Import;
PROCEDURE ExportInfo* (
v: Views.View; w, h, x, y: INTEGER; isSingle: BOOLEAN; VAR med: WinOle.STGMEDIUM
);
VAR hnd: WinApi.HGLOBAL; p: WinOle.PtrOBJECTDESCRIPTOR; id: COM.GUID; stat: SET;
res, size, nlen, slen: INTEGER; name, source: ARRAY 256 OF CHAR; sp: WinApi.PtrWSTR;
BEGIN
ASSERT(med.tymed = {}, 20);
WITH v: View DO
res := v.model.objObj.GetUserClassID(id);
res := v.model.objObj.GetMiscStatus(WinOle.DVASPECT_CONTENT, stat);
res := v.model.objObj.GetUserType(WinOle.USERCLASSTYPE_FULL, sp)
ELSE
id := ObjectID;
stat := miscStatus;
res := WinOle.OleRegGetUserType(ObjectID, WinOle.USERCLASSTYPE_FULL, sp)
END;
IF sp # NIL THEN
name := sp^$;
WinOle.CoTaskMemFree(SYSTEM.VAL(WinApi.PtrVoid, sp))
ELSE name := ""
END;
nlen := 0; slen := 0;
WHILE name[nlen] # 0X DO INC(nlen) END;
nlen := 2 * (nlen + 1);
WHILE Dialog.appName[slen] # 0X DO source[slen] := Dialog.appName[slen]; INC(slen) END;
source[slen] := 0X;
slen := 2 * (slen + 1);
size := 52 + nlen + slen;
hnd := WinApi.GlobalAlloc(WinApi.GMEM_DDESHARE + WinApi.GMEM_MOVEABLE, size);
IF hnd # 0 THEN
p := SYSTEM.VAL(WinOle.PtrOBJECTDESCRIPTOR, WinApi.GlobalLock(hnd));
p.cbSize := size;
p.clsid := id;
p.dwDrawAspect := WinOle.DVASPECT_CONTENT;
p.sizel.cx := w DIV oleUnit;
p.sizel.cy := h DIV oleUnit;
p.pointl.x := x DIV oleUnit;
p.pointl.y := y DIV oleUnit;
p.dwStatus := stat;
p.dwFullUserTypeName := 52;
p.dwSrcOfCopy := 52 + nlen;
SYSTEM.MOVE(SYSTEM.ADR(name), SYSTEM.ADR(p^) + 52, nlen);
SYSTEM.MOVE(SYSTEM.ADR(source), SYSTEM.ADR(p^) + 52 + nlen, slen);
res := WinApi.GlobalUnlock(hnd);
GenGlobalMedium(hnd, NIL, med)
END
END ExportInfo;
PROCEDURE Export* (v: Views.View; w, h, x, y: INTEGER; isSingle: BOOLEAN; VAR med: WinOle.STGMEDIUM);
VAR stg: WinOle.IStorage; res: COM.RESULT; ilb: WinOle.ILockBytes; ips: WinOle.IPersistStorage;
BEGIN
WITH v: View DO
IF med.tymed = WinOle.TYMED_ISTORAGE THEN
stg := MediumStorage(med)
ELSE
res := WinOle.CreateILockBytesOnHGlobal(0, 1, ilb);
ASSERT(res >= 0, 110);
res := WinOle.StgCreateDocfileOnILockBytes(ilb, WinOle.STGM_CREATE
+ WinOle.STGM_READWRITE + WinOle.STGM_SHARE_EXCLUSIVE, 0, stg);
ASSERT(res >= 0, 111);
GenStorageMedium(stg, NIL, med)
END;
res := v.model.objUnk.QueryInterface(COM.ID(ips), ips);
ASSERT(res >= 0, 112);
res := WinOle.OleSave(ips, stg, 0);
ASSERT(res >= 0, 113);
res := ips.SaveCompleted(NIL);
ASSERT(res >= 0, 114)
END
END Export;
(* ---------- commands ---------- *)
PROCEDURE InsertObject*;
VAR v: View; model: Model; res: COM.RESULT; pmfp: WinApi.PtrMETAFILEPICT;
p: WinOleDlg.OLEUIINSERTOBJECT; w: HostWindows.Window;
fname: ARRAY 260 OF SHORTCHAR; guids: ARRAY 1 OF COM.GUID; object: COM.IUnknown;
c: Containers.Controller; f: Views.Frame; v1: Views.View;
BEGIN
NEW(model); Init(model);
w := HostWindows.dir.First();
guids[0] := ObjectID;
p.cbStruct := SIZE(WinOleDlg.OLEUIINSERTOBJECT);
p.dwFlags := WinOleDlg.IOF_DISABLELINK + WinOleDlg.IOF_SELECTCREATENEW
+ WinOleDlg.IOF_CREATENEWOBJECT + WinOleDlg.IOF_CREATEFILEOBJECT
+ WinOleDlg.IOF_DISABLEDISPLAYASICON;
(*
+ WinOleDlg.IOF_SHOWINSERTCONTROL;
*)
p.hWndOwner := w.wnd;
p.lpszCaption := NIL;
p.lpfnHook := NIL;
p.lCustData := 0;
p.hInstance := 0;
p.lpszTemplate := NIL;
p.hResource := 0;
p.lpszFile := fname;
p.cchFile := LEN(fname);
p.cClsidExclude := LEN(guids);
p.lpClsidExclude := guids;
p.iid := COM.ID(object);
p.oleRender := WinOle.OLERENDER_DRAW;
p.lpFormatEtc := NIL;
p.lpIOleClientSite := model.site;
p.lpIStorage := model.stg;
p.ppvObj := SYSTEM.ADR(object);
p.sc := WinApi.S_OK;
p.hMetaPict := 0;
res := WinOleDlg.OleUIInsertObject(p);
IF res = WinOleDlg.OLEUI_OK THEN
IF p.hMetaPict # 0 THEN
pmfp := SYSTEM.VAL(WinApi.PtrMETAFILEPICT, WinApi.GlobalLock(p.hMetaPict));
res := WinApi.DeleteMetaFile(pmfp.hMF);
res := WinApi.GlobalUnlock(p.hMetaPict);
res := WinApi.GlobalFree(p.hMetaPict)
END;
Setup(model, object);
NEW(v); InitModel(v, model);
Controllers.PasteView(v, Views.undefined, Views.undefined, FALSE);
(*
Windows.dir.Update(w);
*)
c := Containers.Focus();
c.GetFirstView(FALSE, v1);
WHILE (v1 # NIL) & (~(v1 IS View) OR (v1(View).model # model)) DO c.GetNextView(FALSE, v1) END;
IF v1 # NIL THEN
v := v1(View);
c.SetSingleton(v);
f := Controllers.FocusFrame();
Views.ValidateRoot(Views.RootOf(f));
f := Views.ThisFrame(f, v);
IF debug THEN Log.String("Object created ("); Log.Int(SYSTEM.VAL(INTEGER, f)); Log.Char(")"); Log.Ln
END;
DoVerb(model, f, WinOle.OLEIVERB_SHOW)
END
ELSIF res # WinOleDlg.OLEUI_CANCEL THEN
IF debug THEN
Log.String("Object creation failed ("); Log.Int(res); Log.Char(")");
IF res = WinOleDlg.OLEUI_IOERR_SCODEHASERROR THEN Log.String(" ("); Log.Int(p.sc); Log.Char(")")
END;
Log.Ln
END
END
END InsertObject;
PROCEDURE PasteSpecial*;
VAR res: INTEGER; p: WinOleDlg.OLEUIPASTESPECIAL; win: HostWindows.Window;
guids: ARRAY 1 OF COM.GUID; pmfp: WinApi.PtrMETAFILEPICT;
entries: ARRAY 16 OF WinOleDlg.OLEUIPASTEENTRY; key: Dialog.String;
conv: ARRAY 16 OF OleData.Converter; str: ARRAY 16, 2, 64 OF SHORTCHAR;
c: OleData.Converter; n: INTEGER; msg: Controllers.EditMsg;
BEGIN
win := HostWindows.dir.First();
guids[0] := ObjectID;
n := 0; c := OleData.convList;
WHILE (c # NIL) & (n < LEN(entries)) DO
IF (c.imp # "") & ~(OleData.info IN c.opts) THEN
entries[n].fmtetc := c.format;
IF c.type # "" THEN
key := "#Host:" + c.imp; Dialog.MapString(key, key); str[n, 0] := SHORT(key$);
key := "#Host:" + c.type; Dialog.MapString(key, key); str[n, 1] := SHORT(key$);
entries[n].lpstrFormatName := str[n, 0];
entries[n].lpstrResultText := str[n, 1]
ELSE
entries[n].lpstrFormatName := "%s";
entries[n].lpstrResultText := "%s"
END;
entries[n].dwFlags := WinOleDlg.OLEUIPASTE_PASTEONLY;
conv[n] := c; INC(n)
END;
c := c.next
END;
p.cbStruct := SIZE(WinOleDlg.OLEUIPASTESPECIAL);
p.dwFlags := WinOleDlg.PSF_DISABLEDISPLAYASICON;
p.hWndOwner := win.wnd;
p.lpszCaption := NIL;
p.lpfnHook := NIL;
p.lCustData := 0;
p.hInstance := 0;
p.lpszTemplate := NIL;
p.hResource := 0;
p.lpSrcDataObj := NIL;
p.arrPasteEntries := SYSTEM.ADR(entries[0]);
p.cPasteEntries := n;
p.arrLinkTypes := NIL;
p.cLinkTypes := 0;
p.cClsidExclude := LEN(guids);
p.lpClsidExclude := guids;
p.hMetaPict := 0;
res := WinOleDlg.OleUIPasteSpecial(p);
IF res # WinOleDlg.OLEUI_CANCEL THEN
ASSERT(res = WinOleDlg.OLEUI_OK, 100);
ASSERT((p.nSelectedIndex >= 0) & (p.nSelectedIndex < n), 101);
OleData.GetDataViewUsing(
p.lpSrcDataObj, conv[p.nSelectedIndex], msg.view, msg.w, msg.h, msg.isSingle);
IF (msg.view = NIL) & (p.nSelectedIndex + 1 < n)
& (conv[p.nSelectedIndex].imp = conv[p.nSelectedIndex + 1].imp)
THEN
OleData.GetDataViewUsing(
p.lpSrcDataObj, conv[p.nSelectedIndex + 1], msg.view, msg.w, msg.h, msg.isSingle)
END;
IF msg.view # NIL THEN
msg.op := Controllers.paste; msg.clipboard := TRUE;
Controllers.Forward(msg)
END;
IF p.hMetaPict # 0 THEN
pmfp := SYSTEM.VAL(WinApi.PtrMETAFILEPICT, WinApi.GlobalLock(p.hMetaPict));
res := WinApi.DeleteMetaFile(pmfp.hMF);
res := WinApi.GlobalUnlock(p.hMetaPict);
res := WinApi.GlobalFree(p.hMetaPict)
END
END
END PasteSpecial;
PROCEDURE NewView* (clsid: COM.GUID): Views.View;
VAR unk: COM.IUnknown; res: COM.RESULT; m: Model; v: View;
BEGIN
NEW(m); Init(m);
res := WinOle.OleCreate(clsid, COM.ID(unk), WinOle.OLERENDER_DRAW, NIL, m.site, m.stg, unk);
IF res = WinApi.S_OK THEN
Setup(m, unk);
NEW(v); InitModel(v, m); RETURN v
ELSIF debug THEN Log.String("NewView: "); Log.Int(res); Log.Ln
END;
RETURN NIL
END NewView;
(*
PROCEDURE NewViewFrom* (unk: COM.IUnknown): Views.View;
VAR res: COM.RESULT; ips: WinOle.IPersistStorage; new: COM.IUnknown; m: Model; v: View;
BEGIN
res := unk.QueryInterface(COM.ID(ips), ips);
IF res = WinApi.S_OK THEN
NEW(m); Init(m);
res := WinOle.OleSave(ips, m.stg, 0);
ASSERT(res >= 0, 100);
res := ips.SaveCompleted(NIL);
ASSERT(res >= 0, 101);
res := WinOle.OleLoad(m.stg, COM.ID(new), m.site, new);
Setup(m, new);
NEW(v); InitModel(v, m); RETURN v
END;
RETURN NIL
END NewViewFrom;
*)
PROCEDURE NewViewFrom* (unk: COM.IUnknown): Views.View;
VAR res: COM.RESULT; dobj: WinOle.IDataObject; new: COM.IUnknown; m: Model; v: View;
BEGIN
res := unk.QueryInterface(COM.ID(dobj), dobj);
IF res = WinApi.S_OK THEN
NEW(m); Init(m);
res := WinOle.OleCreateFromData(
dobj, COM.ID(new), WinOle.OLERENDER_DRAW, NIL, m.site, m.stg, new);
IF res >= 0 THEN
Setup(m, new);
NEW(v); InitModel(v, m); RETURN v
END
END;
RETURN NIL
END NewViewFrom;
PROCEDURE NewViewFromCB* (): Views.View;
VAR res: COM.RESULT; dobj: WinOle.IDataObject; new: COM.IUnknown; m: Model; v: View;
BEGIN
res := WinOle.OleGetClipboard(dobj);
IF res >= 0 THEN
NEW(m); Init(m);
res := WinOle.OleCreateFromData(
dobj, COM.ID(new), WinOle.OLERENDER_DRAW, NIL, m.site, m.stg, new);
IF res >= 0 THEN
Setup(m, new);
NEW(v); InitModel(v, m); RETURN v
END
END;
RETURN NIL
END NewViewFromCB;
PROCEDURE IUnknown* (v: Views.View): COM.IUnknown;
BEGIN
IF v IS View THEN RETURN v(View).model.objUnk
ELSE RETURN NIL
END
END IUnknown;
PROCEDURE TranslateOleKeys (VAR msg: WinApi.MSG; VAR done: BOOLEAN);
VAR res: COM.RESULT;
BEGIN
IF (appFrame # NIL) & (appFrame.iipao # NIL) THEN
res := appFrame.iipao.TranslateAccelerator(msg);
IF res = WinApi.S_OK THEN done := TRUE END
END
END TranslateOleKeys;
BEGIN
HostMenus.TranslateOleKeys1 := TranslateOleKeys
END OleClient.
| Ole/Mod/Client.odc |
MODULE OleData; (* SP410 *)
(**
project = "BlackBox"
organization = "www.oberon.ch"
contributors = "Oberon microsystems", Alexander Iljin
version = "System/Rsrc/About"
copyright = "System/Rsrc/About"
license = "Docu/BB-License"
changes = "
- 20080215, Fyodor Tkachov, reviewed
- 20061012, ai, Updated procedures MemFile.NewReader and MemFile.NewWriter to reuse existing riders.
"
issues = "
- ...
"
**)
IMPORT
SYSTEM, COM, WinOle, WinApi, Log,
Files, Strings, Meta, Dialog, Services, Ports, Stores, Models, Views, Properties, Containers,
HostPorts;
CONST
debug = FALSE;
(* opts *)
stream* = 0;
storage* = 1;
file* = 2;
info* = 16;
single* = 17;
select* = 18;
obfTag = 6F4F4443H;
TYPE
Exporter* = PROCEDURE (
v: Views.View; w, h, rx, ry: INTEGER; isSingle: BOOLEAN; VAR med: WinOle.STGMEDIUM);
Importer* = PROCEDURE (
VAR med: WinOle.STGMEDIUM; OUT v: Views.View; OUT w, h: INTEGER; OUT isSingle: BOOLEAN);
InfoImporter* = PROCEDURE (
VAR med: WinOle.STGMEDIUM; VAR type: Stores.TypeName;
OUT w, h, rx, ry: INTEGER; OUT isSingle: BOOLEAN);
IDataObject* = POINTER TO RECORD (WinOle.IDataObject)
view-: Views.View;
w-, h-, rx, ry: INTEGER;
isSingle, useSel: BOOLEAN;
type: Stores.TypeName
END;
Converter* = POINTER TO RECORD
next-: Converter;
imp-, exp-: Dialog.String;
type-: Stores.TypeName;
format-: WinOle.FORMATETC;
opts-: SET
END;
ExpVal = RECORD (Meta.Value) p: Exporter END;
ImpVal = RECORD (Meta.Value) p: Importer END;
InfoVal = RECORD (Meta.Value) p: InfoImporter END;
MetaFileContext = POINTER TO RECORD (Models.Context)
(*domain: Stores.Domain;*)
w, h: INTEGER
END;
MetaFileView = POINTER TO RECORD (Views.View)
view: Views.View;
END;
IEnumFORMATETC = POINTER TO RECORD (WinOle.IEnumFORMATETC)
cur: INTEGER;
num: INTEGER;
data: POINTER TO ARRAY OF RECORD c: WinOle.FORMATETC END;
END;
Info = POINTER TO InfoDesc;
InfoDesc = RECORD [untagged]
type: Stores.TypeName;
w, h, rx, ry: INTEGER;
isSingle: BOOLEAN;
END;
MemFile = POINTER TO RECORD (Files.File)
mem: WinApi.HGLOBAL;
len: INTEGER;
owner: BOOLEAN
END;
MemReader = POINTER TO RECORD (Files.Reader)
base: MemFile;
pos: INTEGER
END;
MemWriter = POINTER TO RECORD (Files.Writer)
base: MemFile;
pos: INTEGER;
END;
MemPtr = POINTER TO ARRAY [untagged] OF BYTE;
VAR
dataObj-: WinOle.IDataObject; (* for importers *)
convList-: Converter;
unit: INTEGER; (* screen resolution *)
(* Auxiliary procedures *)
PROCEDURE GenFormatEtc (format: SHORTINT; aspect: SET; tymed: SET; VAR f: WinOle.FORMATETC);
BEGIN
f.cfFormat := format;
f.ptd := NIL;
f.dwAspect := aspect;
f.lindex := -1;
f.tymed := tymed
END GenFormatEtc;
PROCEDURE GenMetafileMedium (
mf: WinApi.HMETAFILEPICT; unk: COM.IUnknown; VAR sm: WinOle.STGMEDIUM
);
BEGIN
sm.tymed := WinOle.TYMED_MFPICT;
sm.u.hMetaFilePict := mf;
sm.pUnkForRelease := unk
END GenMetafileMedium;
PROCEDURE GenStreamMedium (stm: WinOle.IStream; unk: COM.IUnknown; VAR sm: WinOle.STGMEDIUM);
BEGIN
sm.tymed := WinOle.TYMED_ISTREAM;
sm.u.pstm := stm;
sm.pUnkForRelease := unk
END GenStreamMedium;
PROCEDURE GenGlobalMedium (hg: WinApi.HGLOBAL; unk: COM.IUnknown; VAR sm: WinOle.STGMEDIUM);
BEGIN
sm.tymed := WinOle.TYMED_HGLOBAL;
sm.u.hGlobal := hg;
sm.pUnkForRelease := unk
END GenGlobalMedium;
PROCEDURE MediumStream (VAR sm: WinOle.STGMEDIUM): WinOle.IStream;
BEGIN
IF sm.tymed = WinOle.TYMED_ISTREAM THEN RETURN sm.u.pstm
ELSE RETURN NIL
END
END MediumStream;
PROCEDURE MediumGlobal (VAR sm: WinOle.STGMEDIUM): WinApi.HGLOBAL;
BEGIN
IF sm.tymed = WinOle.TYMED_HGLOBAL THEN RETURN sm.u.hGlobal
ELSE RETURN 0
END
END MediumGlobal;
PROCEDURE GetCommand (name: Dialog.String; VAR val: Meta.Value; VAR ok: BOOLEAN);
VAR i: Meta.Item;
BEGIN
Meta.LookupPath(name, i);
IF (i.obj = Meta.procObj) OR (i.obj = Meta.varObj) & (i.typ = Meta.procTyp) THEN
i.GetVal(val, ok)
ELSE ok := FALSE
END
END GetCommand;
PROCEDURE Eql (IN f, g: WinOle.FORMATETC): BOOLEAN;
BEGIN
RETURN (f.cfFormat = g.cfFormat) & (f.ptd = g.ptd) & (f.dwAspect = g.dwAspect)
& (f.lindex = g.lindex) & (f.tymed * g.tymed # {})
END Eql;
PROCEDURE Equiv (IN f, g: WinOle.FORMATETC): BOOLEAN;
BEGIN
RETURN (f.cfFormat = g.cfFormat) & (f.ptd = g.ptd) & (f.dwAspect = g.dwAspect)
& (f.lindex = g.lindex)
END Equiv;
PROCEDURE Compatible (c: Converter; VAR view: Views.View; isSingle: BOOLEAN): BOOLEAN;
BEGIN
RETURN ((c.type = "") OR Services.Is(view, c.type))
& (~(single IN c.opts) OR isSingle)
& (~(select IN c.opts) OR ~isSingle)
END Compatible;
PROCEDURE Setup (data: IDataObject);
VAR v: Views.View; c: Containers.Controller; m: Containers.Model;
p: Properties.BoundsPref; dx, dy: INTEGER;
BEGIN
c := data.view(Containers.View).ThisController();
m := c.SelectionCopy();
(*
v := Services.Clone(data.view)(Views.View);
v.InitModel(m); v.CopyFrom(data.view);
*)
v := Views.CopyWithNewModel(data.view, m);
p.w := Views.undefined; p.h := Views.undefined; Views.HandlePropMsg(v, p);
data.view := v; data.w := p.w; data.h := p.h; data.useSel := FALSE
END Setup;
(* IEnumFORMATETC *)
PROCEDURE CreateIEnumFORMATETC (num: INTEGER; VAR data: ARRAY OF WinOle.FORMATETC;
VAR enum: WinOle.IEnumFORMATETC);
VAR i, n: INTEGER; new: IEnumFORMATETC;
BEGIN
NEW(new);
IF new # NIL THEN
new.cur := 0;
new.num := num;
NEW(new.data, num);
i := 0;
WHILE i < num DO new.data[i].c := data[i]; INC(i) END;
enum := new
END
END CreateIEnumFORMATETC;
PROCEDURE (this: IEnumFORMATETC) Next (num: INTEGER;
OUT elem: ARRAY [untagged] OF WinOle.FORMATETC; OUT [nil] fetched: INTEGER
): COM.RESULT;
VAR n: INTEGER;
BEGIN
n := 0;
IF VALID(fetched) THEN fetched := 0
ELSIF num # 1 THEN RETURN WinApi.E_POINTER
END;
IF this.cur < this.num THEN
WHILE (this.cur < this.num) & (num > 0) DO
elem[n] := this.data[this.cur].c;
INC(this.cur); INC(n); DEC(num)
END;
IF VALID(fetched) THEN fetched := n END;
RETURN WinApi.S_OK
END;
RETURN WinApi.S_FALSE
END Next;
PROCEDURE (this: IEnumFORMATETC) Skip (num: INTEGER): COM.RESULT;
BEGIN
IF this.cur + num < this.num THEN
INC(this.cur, num); RETURN WinApi.S_OK
ELSE RETURN WinApi.S_FALSE
END
END Skip;
PROCEDURE (this: IEnumFORMATETC) Reset (): COM.RESULT;
BEGIN
this.cur := 0; RETURN WinApi.S_OK
END Reset;
PROCEDURE (this: IEnumFORMATETC) Clone (OUT enum: WinOle.IEnumFORMATETC): COM.RESULT;
VAR new: IEnumFORMATETC;
BEGIN
NEW(new);
IF new # NIL THEN
new.num := this.num;
new.cur := this.cur;
new.data := this.data;
enum := new;
RETURN WinApi.S_OK
ELSE RETURN WinApi.E_OUTOFMEMORY
END
END Clone;
(* Metafile Pictures *)
(*
PROCEDURE (c: MetaFileContext) ThisDomain (): Stores.Domain;
BEGIN
RETURN c.domain
END ThisDomain;
*)
PROCEDURE (c: MetaFileContext) ThisModel (): Models.Model;
BEGIN
RETURN NIL
END ThisModel;
PROCEDURE (c: MetaFileContext) GetSize (OUT w, h: INTEGER);
BEGIN
w := c.w; h := c.h
END GetSize;
PROCEDURE (c: MetaFileContext) SetSize (w, h: INTEGER);
END SetSize;
PROCEDURE (c: MetaFileContext) Normalize (): BOOLEAN;
BEGIN
RETURN TRUE
END Normalize;
PROCEDURE (d: MetaFileView) Restore (f: Views.Frame; l, t, r, b: INTEGER);
BEGIN
Views.InstallFrame(f, d.view, 0, 0, 0, FALSE)
END Restore;
PROCEDURE (d: MetaFileView) GetNewFrame (VAR frame: Views.Frame);
VAR f: Views.RootFrame;
BEGIN
NEW(f); frame := f
END GetNewFrame;
PROCEDURE (d: MetaFileView) GetBackground (VAR color: Ports.Color);
BEGIN
color := Ports.background
END GetBackground;
(*
PROCEDURE (d: MetaFileView) PropagateDomain;
BEGIN
Stores.InitDomain(d.view, d.domain)
END PropagateDomain;
*)
PROCEDURE Paint (dc: WinApi.HDC; v: Views.View; w, h, unit: INTEGER);
VAR d: MetaFileView; c: MetaFileContext; p: HostPorts.Port; f: Views.RootFrame; g: Views.Frame;
(* m: Models.Model; *)
BEGIN
NEW(p);
p.Init(unit, Ports.screen);
p.SetSize(w, h);
p.SetDC(dc, 0);
NEW(c);
(*
m := v.ThisModel();
IF (m # NIL) & (m.domain # NIL) THEN
c.domain := m.domain
ELSE
c.domain := Models.NewDomain()
END;
*)
(*
IF v.domain # NIL THEN
c.domain := v.domain
ELSE
c.domain := Models.NewDomain()
END;
*)
c.w := w * p.unit;
c.h := h * p.unit;
NEW(d);
d.view := Views.CopyOf(v, Views.shallow);
Stores.Join(d, d.view);
d.InitContext(c);
d.view.InitContext(c);
(* Stores.InitDomain(d, c.domain); *)
(* Stores.InitDomain(d.view, c.domain); *)
Stores.InitDomain(d);
d.GetNewFrame(g); f := g(Views.RootFrame); f.ConnectTo(p);
Views.SetRoot(f, d, FALSE, {});
Views.AdaptRoot(f);
Views.RestoreRoot(f, 0, 0, c.w, c.h);
END Paint;
(* ---------- MemFiles ---------- *)
PROCEDURE (r: MemReader) Base (): Files.File;
BEGIN
RETURN r.base
END Base;
PROCEDURE (r: MemReader) Pos (): INTEGER;
BEGIN
RETURN r.pos
END Pos;
PROCEDURE (r: MemReader) SetPos (pos: INTEGER);
BEGIN
ASSERT(pos >= 0, 22); ASSERT(pos <= r.base.len, 21);
r.pos := pos; r.eof := FALSE
END SetPos;
PROCEDURE (r: MemReader) ReadByte (OUT x: BYTE);
VAR res: INTEGER; p: MemPtr;
BEGIN
ASSERT(r.base.mem # 0, 20);
IF r.pos < r.base.len THEN
p := SYSTEM.VAL(MemPtr, WinApi.GlobalLock(r.base.mem));
x := p[r.pos]; INC(r.pos);
res := WinApi.GlobalUnlock(r.base.mem)
ELSE
x := 0; r.eof := TRUE
END
END ReadByte;
PROCEDURE (r: MemReader) ReadBytes (VAR x: ARRAY OF BYTE; beg, len: INTEGER);
VAR res: INTEGER; p: MemPtr;
BEGIN
ASSERT(r.base.mem # 0, 20);
ASSERT(beg >= 0, 21);
IF len > 0 THEN
ASSERT(beg + len <= LEN(x), 23);
IF r.pos + len <= r.base.len THEN
p := SYSTEM.VAL(MemPtr, WinApi.GlobalLock(r.base.mem));
SYSTEM.MOVE(SYSTEM.ADR(p[r.pos]), SYSTEM.ADR(x[beg]), len);
INC(r.pos, len);
res := WinApi.GlobalUnlock(r.base.mem)
ELSE
r.eof := TRUE
END
ELSE ASSERT(len = 0, 22)
END
END ReadBytes;
PROCEDURE (w: MemWriter) Base (): Files.File;
BEGIN
RETURN w.base
END Base;
PROCEDURE (w: MemWriter) Pos (): INTEGER;
BEGIN
RETURN w.pos
END Pos;
PROCEDURE (w: MemWriter) SetPos (pos: INTEGER);
BEGIN
ASSERT(pos >= 0, 22); ASSERT(pos <= w.base.len, 21);
w.pos := pos
END SetPos;
PROCEDURE (w: MemWriter) WriteByte (x: BYTE);
VAR res, size: INTEGER; p: MemPtr;
BEGIN
ASSERT(w.base.mem # 0, 20);
IF w.pos >= w.base.len THEN
w.base.len := w.pos + 1;
size := WinApi.GlobalSize(w.base.mem);
IF size < w.base.len THEN
w.base.mem := WinApi.GlobalReAlloc(w.base.mem, w.base.len + 1024,
WinApi.GMEM_DDESHARE + WinApi.GMEM_MOVEABLE)
END
END;
p := SYSTEM.VAL(MemPtr, WinApi.GlobalLock(w.base.mem));
p[w.pos] := x; INC(w.pos);
res := WinApi.GlobalUnlock(w.base.mem)
END WriteByte;
PROCEDURE (w: MemWriter) WriteBytes (IN x: ARRAY OF BYTE; beg, len: INTEGER);
VAR res, size: INTEGER; p: MemPtr;
BEGIN
ASSERT(w.base.mem # 0, 20);
ASSERT(beg >= 0, 21);
IF len > 0 THEN
ASSERT(beg + len <= LEN(x), 23);
IF w.pos + len > w.base.len THEN
w.base.len := w.pos + len;
size := WinApi.GlobalSize(w.base.mem);
IF size < w.base.len THEN
w.base.mem := WinApi.GlobalReAlloc(w.base.mem, w.base.len + 1024,
WinApi.GMEM_DDESHARE + WinApi.GMEM_MOVEABLE)
END
END;
p := SYSTEM.VAL(MemPtr, WinApi.GlobalLock(w.base.mem));
SYSTEM.MOVE(SYSTEM.ADR(x[beg]), SYSTEM.ADR(p[w.pos]), len);
INC(w.pos, len);
res := WinApi.GlobalUnlock(w.base.mem)
ELSE ASSERT(len = 0, 22)
END
END WriteBytes;
PROCEDURE (f: MemFile) Length (): INTEGER;
BEGIN
RETURN f.len
END Length;
PROCEDURE (f: MemFile) NewReader (old: Files.Reader): Files.Reader;
VAR r: MemReader;
BEGIN
ASSERT(f.mem # 0, 20);
(* 20061012, ai: this was simply NEW(r) *)
IF (old = NIL) OR ~(old IS MemReader) THEN NEW(r)
ELSE r := old(MemReader)
END;
r.base := f;
r.pos := 0;
r.eof := FALSE;
RETURN r
END NewReader;
PROCEDURE (f: MemFile) NewWriter (old: Files.Writer): Files.Writer;
VAR w: MemWriter;
BEGIN
ASSERT(f.mem # 0, 20);
(* 20061012, ai: this was simply NEW(w) *)
IF (old = NIL) OR ~(old IS MemWriter) THEN NEW(w)
ELSE w := old(MemWriter)
END;
w.base := f;
w.pos := f.len;
RETURN w
END NewWriter;
PROCEDURE (f: MemFile) Register (name: Files.Name; type: Files.Type; ask: BOOLEAN; OUT res: INTEGER);
BEGIN
res := -1
END Register;
PROCEDURE (f: MemFile) Close;
END Close;
PROCEDURE (f: MemFile) Flush;
END Flush;
PROCEDURE (f: MemFile) FINALIZE;
BEGIN
IF f.owner THEN f.mem := WinApi.GlobalFree(f.mem) END
END FINALIZE;
PROCEDURE NewMemFile (mem: WinApi.HGLOBAL; owner: BOOLEAN): Files.File;
VAR f: MemFile;
BEGIN
NEW(f);
f.mem := mem;
f.len := WinApi.GlobalSize(mem);
f.owner := owner;
RETURN f
END NewMemFile;
(* standard exporters *)
PROCEDURE ExportNative* (
v: Views.View; w, h, x, y: INTEGER; isSingle: BOOLEAN; VAR med: WinOle.STGMEDIUM
);
VAR hnd: WinApi.HGLOBAL; f: Files.File; wr: Stores.Writer; res: COM.RESULT;
BEGIN
ASSERT(med.tymed = {}, 20);
hnd := WinApi.GlobalAlloc(WinApi.GMEM_DDESHARE + WinApi.GMEM_MOVEABLE, 1024);
f := NewMemFile(hnd, FALSE);
wr.ConnectTo(f);
wr.SetPos(0);
wr.WriteInt(obfTag);
wr.WriteInt(0);
wr.WriteInt(w);
wr.WriteInt(h);
IF isSingle THEN wr.WriteSChar(1X) ELSE wr.WriteSChar(0X) END;
wr.WriteStore(v);
GenGlobalMedium(hnd, NIL, med)
END ExportNative;
PROCEDURE ExportInfo* (
v: Views.View; w, h, x, y: INTEGER; isSingle: BOOLEAN; VAR med: WinOle.STGMEDIUM
);
VAR hnd: WinApi.HGLOBAL; p: Info; res: INTEGER;
BEGIN
ASSERT(med.tymed = {}, 20);
hnd := WinApi.GlobalAlloc(WinApi.GMEM_DDESHARE + WinApi.GMEM_MOVEABLE, SIZE(InfoDesc));
IF hnd # 0 THEN
p := SYSTEM.VAL(Info, WinApi.GlobalLock(hnd));
Services.GetTypeName(v, p.type);
p.w := w; p.h := h; p.rx := x; p.ry := y;
p.isSingle := isSingle;
res := WinApi.GlobalUnlock(hnd);
GenGlobalMedium(hnd, NIL, med)
END
END ExportInfo;
PROCEDURE ExportPicture* (
v: Views.View; w, h, x, y: INTEGER; isSingle: BOOLEAN; VAR med: WinOle.STGMEDIUM
);
VAR dc: WinApi.HDC; mf: WinApi.HMETAFILE; mp: WinApi.PtrMETAFILEPICT;
rc: WinApi.RECT; res: INTEGER; hm: WinApi.HMETAFILEPICT;
bp: Properties.BoundsPref; sp: Properties.SizePref;
BEGIN
ASSERT(med.tymed = {}, 20);
IF (w = Views.undefined) OR (h = Views.undefined) THEN
bp.w := Views.undefined; bp.h := Views.undefined;
Views.HandlePropMsg(v, bp);
w := bp.w; h := bp.h
END;
IF (w = Views.undefined) OR (h = Views.undefined) THEN
sp.w := Views.undefined; sp.h := Views.undefined;
sp.fixedW := FALSE; sp.fixedH := FALSE;
Views.HandlePropMsg(v, sp);
w := sp.w; h := sp.h
END;
(*
w := w DIV (Ports.mm DIV 100); h := h DIV (Ports.mm DIV 100); (* w, h in mm/100 *)
*)
dc := WinApi.CreateMetaFileA(NIL);
IF dc # 0 THEN
res := WinApi.SetMapMode(dc, WinApi.MM_ANISOTROPIC);
res := WinApi.SetWindowOrgEx(dc, 0, 0, NIL);
res := WinApi.SetWindowExtEx(dc, w DIV unit, h DIV unit, NIL);
IF v # NIL THEN Paint(dc, v, w DIV unit, h DIV unit, unit) END;
mf := WinApi.CloseMetaFile(dc);
IF mf # 0 THEN
hm := WinApi.GlobalAlloc(
WinApi.GMEM_DDESHARE + WinApi.GMEM_MOVEABLE, SIZE(WinApi.METAFILEPICT));
IF hm # 0 THEN
mp := SYSTEM.VAL(WinApi.PtrMETAFILEPICT, WinApi.GlobalLock(hm));
mp.hMF := mf;
mp.mm := WinApi.MM_ANISOTROPIC;
mp.xExt := w DIV (Ports.mm DIV 100); (* himetric units *)
mp.yExt := h DIV (Ports.mm DIV 100);
res := WinApi.GlobalUnlock(hm);
GenMetafileMedium(hm, NIL, med)
ELSE res := WinApi.DeleteMetaFile(mf)
END
END
END
END ExportPicture;
(* standard importers *)
PROCEDURE ImportNative* (VAR med: WinOle.STGMEDIUM; OUT v: Views.View;
OUT w, h: INTEGER; OUT isSingle: BOOLEAN);
VAR hnd: WinApi.HGLOBAL; f: Files.File; r: Stores.Reader; s: Stores.Store;
tag, version, res: COM.RESULT; ch: SHORTCHAR;
BEGIN
v := NIL;
hnd := MediumGlobal(med);
med.u.hGlobal := 0;
f := NewMemFile(hnd, TRUE);
r.ConnectTo(f); r.SetPos(0);
r.ReadInt(tag);
IF tag = obfTag THEN
r.ReadInt(version);
r.ReadInt(w);
r.ReadInt(h);
r.ReadSChar(ch); isSingle := ch # 0X;
r.ReadStore(s);
v := s(Views.View)
END
END ImportNative;
PROCEDURE ImportInfo* (VAR med: WinOle.STGMEDIUM; VAR type: Stores.TypeName;
OUT w, h, rx, ry: INTEGER; OUT isSingle: BOOLEAN);
VAR s: Stores.Store; hnd: WinApi.HANDLE; p: Info; res: INTEGER;
BEGIN
hnd := MediumGlobal(med);
IF hnd # 0 THEN
p := SYSTEM.VAL(Info, WinApi.GlobalLock(hnd));
type := p.type;
w := p.w; h := p.h; rx := p.rx; ry := p.ry;
isSingle := p.isSingle;
res := WinApi.GlobalUnlock(hnd)
END
END ImportInfo;
(* IDataObject *)
PROCEDURE (this: IDataObject) GetData* (IN format: WinOle.FORMATETC;
OUT medium: WinOle.STGMEDIUM): COM.RESULT;
VAR c: Converter; val: ExpVal; ok: BOOLEAN;
BEGIN
c := convList;
WHILE (c # NIL) & ((c.exp = "")
OR ~Compatible(c, this.view, this.isSingle)
OR ~Eql(c.format, format)) DO c := c.next END;
IF c # NIL THEN
GetCommand(c.exp, val, ok);
medium.tymed := {};
IF ok THEN
IF this.useSel & ~(info IN c.opts) THEN Setup(this) END;
val.p(this.view, this.w, this.h, this.rx, this.ry, this.isSingle, medium);
RETURN WinApi.S_OK
ELSE
IF debug THEN Log.String(c.exp); Log.String(" failed"); Log.Ln END;
RETURN WinApi.E_UNEXPECTED
END
ELSE RETURN WinApi.DV_E_FORMATETC
END
END GetData;
PROCEDURE (this: IDataObject) GetDataHere* (IN format: WinOle.FORMATETC;
VAR medium: WinOle.STGMEDIUM): COM.RESULT;
VAR c: Converter; val: ExpVal; ok: BOOLEAN;
BEGIN
IF format.tymed * (WinOle.TYMED_ISTORAGE + WinOle.TYMED_ISTREAM) # {} THEN
c := convList;
WHILE (c # NIL) & ((c.exp = "")
OR ~Compatible(c, this.view, this.isSingle)
OR ~Eql(c.format, format)) DO c := c.next END;
IF (c # NIL) & (medium.tymed = c.format.tymed) THEN
GetCommand(c.exp, val, ok);
IF ok THEN
IF this.useSel & ~(info IN c.opts) THEN Setup(this) END;
val.p(this.view, this.w, this.h, this.rx, this.ry, this.isSingle, medium);
RETURN WinApi.S_OK
ELSE
IF debug THEN Log.String(c.exp); Log.String(" failed"); Log.Ln END;
RETURN WinApi.E_UNEXPECTED
END
ELSE RETURN WinApi.DV_E_FORMATETC
END
ELSE RETURN WinApi.DV_E_FORMATETC
END
END GetDataHere;
PROCEDURE (this: IDataObject) QueryGetData* (IN format: WinOle.FORMATETC): COM.RESULT;
VAR c: Converter;
BEGIN
c := convList;
WHILE (c # NIL) & ((c.exp = "")
OR ~Compatible(c, this.view, this.isSingle)
OR ~Eql(c.format, format)) DO c := c.next END;
IF c # NIL THEN RETURN WinApi.S_OK
ELSE RETURN WinApi.DV_E_FORMATETC
END
END QueryGetData;
PROCEDURE (this: IDataObject) GetCanonicalFormatEtc* (IN formatIn: WinOle.FORMATETC;
OUT formatOut: WinOle.FORMATETC): COM.RESULT;
BEGIN
RETURN WinApi.DATA_S_SAMEFORMATETC
END GetCanonicalFormatEtc;
PROCEDURE (this: IDataObject) SetData* (IN format: WinOle.FORMATETC;
IN medium: WinOle.STGMEDIUM; release: WinApi.BOOL): COM.RESULT;
BEGIN
RETURN WinApi.DV_E_FORMATETC
END SetData;
PROCEDURE (this: IDataObject) EnumFormatEtc* (direction: SET;
OUT enum: WinOle.IEnumFORMATETC): COM.RESULT;
VAR format: ARRAY 32 OF WinOle.FORMATETC; p: WinOle.IEnumFORMATETC;
n, i: INTEGER; c: Converter;
BEGIN
IF direction = WinOle.DATADIR_GET THEN
n := 0; c := convList;
WHILE (n < LEN(format)) & (c # NIL) DO
IF (c.exp # "") & Compatible(c, this.view, this.isSingle) THEN
format[n] := c.format; i := 0;
WHILE ~Equiv(format[i], c.format) DO INC(i) END;
IF i = n THEN INC(n)
ELSE format[i].tymed := format[i].tymed + c.format.tymed
END
END;
c := c.next
END;
IF n > 0 THEN
CreateIEnumFORMATETC(n, format, p);
IF p # NIL THEN enum := p; RETURN WinApi.S_OK
ELSE RETURN WinApi.E_OUTOFMEMORY
END
ELSE RETURN WinApi.E_FAIL
END
ELSE
RETURN WinApi.E_NOTIMPL
END
END EnumFormatEtc;
PROCEDURE (this: IDataObject) DAdvise* (IN format: WinOle.FORMATETC; flags: SET;
advSink: WinOle.IAdviseSink; OUT connection: INTEGER): COM.RESULT;
BEGIN
RETURN WinApi.E_FAIL
END DAdvise;
PROCEDURE (this: IDataObject) DUnadvise* (connection: INTEGER): COM.RESULT;
BEGIN
RETURN WinApi.E_FAIL
END DUnadvise;
PROCEDURE (this: IDataObject) EnumDAdvise* (OUT enum: WinOle.IEnumSTATDATA): COM.RESULT;
BEGIN
RETURN WinApi.E_FAIL
END EnumDAdvise;
(* import/export *)
PROCEDURE DataConvTo* (data: WinOle.IDataObject; type: Stores.TypeName): BOOLEAN;
VAR t: Stores.TypeName; c: Converter; v: Views.View; res: COM.RESULT; ok, s: BOOLEAN;
med: WinOle.STGMEDIUM; ival: InfoVal; w, h, x, y: INTEGER;
BEGIN
v := NIL; c := convList;
WHILE c # NIL DO
IF c.imp # "" THEN
IF (type = "") OR (c.type # "") & Services.Extends(c.type, type) THEN
IF data.QueryGetData(c.format) = WinApi.S_OK THEN RETURN TRUE END
ELSIF info IN c.opts THEN
res := data.GetData(c.format, med);
IF res >= 0 THEN
GetCommand(c.imp, ival, ok); t := "";
IF ok THEN ival.p(med, t, w, h, x, y, s)
ELSIF debug THEN Log.String(c.imp); Log.String(" failed (c)"); Log.Ln
END;
WinOle.ReleaseStgMedium(med);
IF t = type THEN RETURN TRUE END
END
END
END;
c := c.next
END;
RETURN FALSE
END DataConvTo;
PROCEDURE GetDataView* (data: WinOle.IDataObject; type: Stores.TypeName; OUT v: Views.View;
OUT w, h: INTEGER; OUT isSingle: BOOLEAN);
VAR t: Stores.TypeName; c: Converter; val: ImpVal; ival: InfoVal; ok, s: BOOLEAN;
res: COM.RESULT; med: WinOle.STGMEDIUM; x, y: INTEGER;
BEGIN
v := NIL; t := ""; c := convList;
WHILE (c # NIL) & (v = NIL) DO
IF c.imp # "" THEN
IF info IN c.opts THEN
IF type # "" THEN
res := data.GetData(c.format, med); t := "";
IF debug THEN Log.String("Get Data "); Log.String(c.imp); Log.String(c.exp); Log.Int(res); Log.Ln
END;
IF res >= 0 THEN
GetCommand(c.imp, ival, ok);
IF ok THEN ival.p(med, t, w, h, x, y, s)
ELSIF debug THEN Log.String(c.imp); Log.String(" failed (i)"); Log.Ln
END;
WinOle.ReleaseStgMedium(med)
END
END
ELSIF (type = "") OR (c.type # "") & Services.Extends(c.type, type)
OR (c.type = "") & (t # "") & Services.Extends(t, type) THEN
IF debug THEN Log.String("query"); Log.Int(data.QueryGetData(c.format)); Log.Ln END;
res := data.GetData(c.format, med);
IF debug THEN Log.String("Get Data "); Log.String(c.imp); Log.String(c.exp); Log.Int(res); Log.Ln END;
IF res >= 0 THEN
GetCommand(c.imp, val, ok);
IF ok THEN
dataObj := data; val.p(med, v, w, h, isSingle); dataObj := NIL
ELSIF debug THEN Log.String(c.imp); Log.String(" failed (g)"); Log.Ln
END;
WinOle.ReleaseStgMedium(med)
END
END
END;
c := c.next
END
END GetDataView;
PROCEDURE GetDataViewUsing* (data: WinOle.IDataObject; c: Converter; OUT v: Views.View;
OUT w, h: INTEGER; OUT isSingle: BOOLEAN);
VAR val: ImpVal; ok: BOOLEAN; res: COM.RESULT; med: WinOle.STGMEDIUM;
BEGIN
ASSERT(c # NIL, 20);
ASSERT(c.imp # "", 21);
ASSERT(~(info IN c.opts), 22);
v := NIL;
res := data.GetData(c.format, med);
IF debug THEN Log.String("Get Data "); Log.String(c.imp); Log.String(c.exp); Log.Int(res); Log.Ln END;
IF res >= 0 THEN
GetCommand(c.imp, val, ok);
IF ok THEN
dataObj := data; val.p(med, v, w, h, isSingle); dataObj := NIL
ELSIF debug THEN Log.String(c.imp); Log.String(" failed (g)"); Log.Ln
END;
WinOle.ReleaseStgMedium(med)
END
END GetDataViewUsing;
PROCEDURE GetTextDataView* (data: WinOle.IDataObject; OUT v: Views.View;
OUT w, h: INTEGER; OUT isSingle: BOOLEAN);
VAR c: Converter;
BEGIN
v := NIL; c := convList;
WHILE (c # NIL) & (c.imp # "OleData.ImportNative") DO c := c.next END;
IF c # NIL THEN GetDataViewUsing(data, c, v, w, h, isSingle) END;
IF v = NIL THEN
c := convList;
WHILE (c # NIL) & (c.imp # "HostTextConv.ImportDRichText") DO c := c.next END;
IF c # NIL THEN GetDataViewUsing(data, c, v, w, h, isSingle) END;
END;
IF v = NIL THEN
GetDataView(data, "", v, w, h, isSingle)
END
END GetTextDataView;
PROCEDURE GetDataType* (data: WinOle.IDataObject; OUT type: Stores.TypeName;
OUT w, h, x, y: INTEGER; OUT isSingle: BOOLEAN);
VAR t: Stores.TypeName; c: Converter; res: COM.RESULT; med: WinOle.STGMEDIUM;
ival: InfoVal; ok: BOOLEAN;
BEGIN
type := ""; c := convList;
WHILE (c # NIL) & (type = "") DO
IF c.imp # "" THEN
IF info IN c.opts THEN
res := data.GetData(c.format, med);
IF res >= 0 THEN
GetCommand(c.imp, ival, ok);
IF ok THEN ival.p(med, type, w, h, x, y, isSingle)
ELSIF debug THEN Log.String(c.imp); Log.String(" failed (t)"); Log.Ln
END;
WinOle.ReleaseStgMedium(med)
END
ELSIF c.type # "" THEN
IF data.QueryGetData(c.format) = WinApi.S_OK THEN
type := c.type; isSingle := FALSE;
w := 0; h := 0; x := 0; y := 0
END
END
END;
c := c.next
END
END GetDataType;
(* creation *)
PROCEDURE ViewData* (v: Views.View; w, h: INTEGER; isSingle: BOOLEAN): IDataObject;
VAR new: IDataObject;
BEGIN
NEW(new); new.view := v; new.w := w; new.h := h; new.rx := 0; new.ry := 0;
new.isSingle := isSingle; new.useSel := FALSE;
IF v # NIL THEN Services.GetTypeName(v, new.type) ELSE new.type := "*" END;
RETURN new
END ViewData;
PROCEDURE ViewDropData* (v: Views.View; w, h, rx, ry: INTEGER; isSingle, useSel: BOOLEAN): IDataObject;
VAR new: IDataObject;
BEGIN
IF useSel THEN
ASSERT(~isSingle, 20);
ASSERT(v IS Containers.View, 21);
ASSERT(v(Containers.View).ThisController() # NIL, 22)
END;
NEW(new); new.view := v; new.w := w; new.h := h; new.rx := rx; new.ry := ry;
new.isSingle := isSingle; new.useSel := useSel;
IF v # NIL THEN Services.GetTypeName(v, new.type) ELSE new.type := "*" END;
RETURN new
END ViewDropData;
PROCEDURE SetView* (data: IDataObject; v: Views.View; w, h: INTEGER);
BEGIN
data.view := v; data.w := w; data.h := h;
IF v # NIL THEN Services.GetTypeName(v, data.type) ELSE data.type := "*" END;
END SetView;
(* registration *)
PROCEDURE Register* (imp, exp, format: Dialog.String; type: Stores.TypeName; opts: SET);
VAR c, f: Converter; tymed: SET; cbf: SHORTINT; fmt: ARRAY 256 OF SHORTCHAR;
BEGIN
tymed := WinOle.TYMED_HGLOBAL;
IF format = "TEXT" THEN cbf := WinApi.CF_TEXT
ELSIF format = "BITMAP" THEN cbf := WinApi.CF_BITMAP; tymed := WinOle.TYMED_GDI
ELSIF format = "METAFILEPICT" THEN cbf := WinApi.CF_METAFILEPICT; tymed := WinOle.TYMED_MFPICT
ELSIF format = "SYLK" THEN cbf := WinApi.CF_SYLK
ELSIF format = "DIF" THEN cbf := WinApi.CF_DIF
ELSIF format = "TIFF" THEN cbf := WinApi.CF_TIFF
ELSIF format = "OEMTEXT" THEN cbf := WinApi.CF_OEMTEXT
ELSIF format = "DIB" THEN cbf := WinApi.CF_DIB; tymed := WinOle.TYMED_GDI
ELSIF format = "PALETTE" THEN cbf := WinApi.CF_PALETTE
ELSIF format = "PENDATA" THEN cbf := WinApi.CF_PENDATA
ELSIF format = "RIFF" THEN cbf := WinApi.CF_RIFF
ELSIF format = "WAVE" THEN cbf := WinApi.CF_WAVE
ELSIF format = "UNICODETEXT" THEN cbf := WinApi.CF_UNICODETEXT
ELSIF format = "ENHMETAFILE" THEN cbf := WinApi.CF_ENHMETAFILE; tymed := WinOle.TYMED_ENHMF
ELSIF format = "HDROP" THEN cbf := WinApi.CF_HDROP
ELSIF format = "LOCALE" THEN cbf := WinApi.CF_LOCALE
ELSE fmt := SHORT(format$); cbf := SHORT(WinApi.RegisterClipboardFormat(fmt))
END;
IF stream IN opts THEN tymed := WinOle.TYMED_ISTREAM
ELSIF storage IN opts THEN tymed := WinOle.TYMED_ISTORAGE
ELSIF file IN opts THEN tymed := WinOle.TYMED_FILE
END;
NEW(c); c.imp := imp; c.exp := exp; c.type := type; c.opts := opts;
GenFormatEtc(cbf, WinOle.DVASPECT_CONTENT, tymed, c.format);
IF convList = NIL THEN convList := c
ELSE f := convList;
WHILE f.next # NIL DO f := f.next END;
f.next := c
END
END Register;
(* debug *)
PROCEDURE DumpData* (data: WinOle.IDataObject);
VAR type: Stores.TypeName; c: Converter; val: ImpVal; ival: InfoVal; ok, s: BOOLEAN;
res: COM.RESULT; med: WinOle.STGMEDIUM; w, h, x, y: INTEGER; v: Views.View;
BEGIN
c := convList;
WHILE c # NIL DO
IF c.imp # "" THEN
res := data.QueryGetData(c.format);
IF res >= 0 THEN
Log.String(c.imp); Log.Char(" ");
res := data.GetData(c.format, med);
IF res >= 0 THEN
Log.String(" read ");
IF info IN c.opts THEN
Log.String("(i) ");
GetCommand(c.imp, ival, ok);
IF ok THEN
type := "";
ival.p(med, type, w, h, x, y, s);
Log.String(type);
Log.Int(w); Log.Int(h); Log.Int(x); Log.Int(y);
IF s THEN Log.String(" singleton") END
ELSE
Log.String("failed");
END
ELSE
GetCommand(c.imp, val, ok);
IF ok THEN
v := NIL;
dataObj := data; val.p(med, v, w, h, s); dataObj := NIL;
IF v # NIL THEN
Services.GetTypeName(v, type);
Log.String(type);
Log.Int(w); Log.Int(h);
IF s THEN Log.String(" singleton") END
ELSE
Log.String("NIL")
END
ELSE
Log.String("failed");
END
END;
WinOle.ReleaseStgMedium(med);
Log.Ln
END
END
END;
c := c.next
END
END DumpData;
PROCEDURE Init;
VAR res: INTEGER; dc: WinApi.HDC;
BEGIN
dc := WinApi.GetDC(0);
unit := 914400 DIV WinApi.GetDeviceCaps(dc, 90);
res := WinApi.ReleaseDC(0, dc)
END Init;
BEGIN
Init
END OleData.
| Ole/Mod/Data.odc |
MODULE OleServer;
(**
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
SYSTEM, COM, WinOle, WinApi,
OleStorage, OleData, StdDialog,
Kernel, Files, Services, Ports, Dialog, Stores, Sequencers, Views,
Controllers, Properties, Converters, Containers, Documents, Windows,
TextViews, Log, HostPorts, HostDialog, HostWindows, HostMenus;
CONST
debug = FALSE;
ObjectID = "{00000001-1000-11cf-adf0-444553540000}";
streamStr = "CONTENTS";
cbFormat = 200H;
obfTag = 6F4F4443H;
miscStatus = WinOle.OLEMISC_RECOMPOSEONRESIZE
+ WinOle.OLEMISC_CANTLINKINSIDE
+ WinOle.OLEMISC_RENDERINGISDEVICEINDEPENDENT;
oleUnit = Ports.mm DIV 100;
borderW = 5 * Ports.point;
fixed = 31; (* controller option *)
TYPE
IClassFactory = POINTER TO RECORD (WinOle.IClassFactory) END;
Object = POINTER TO RECORD (COM.IUnknown)
ioo: IOleObject;
ido: IDataObject;
ips: IPersistStorage;
iipo: IOleInPlaceObject;
iipao: IOleInPlaceActiveObject;
ics: WinOle.IOleClientSite;
iips: WinOle.IOleInPlaceSite; (* # NIL => in place open *)
iipf: WinOle.IOleInPlaceFrame;
iipw: WinOle.IOleInPlaceUIWindow;
fInfo: WinOle.OLEINPLACEFRAMEINFO;
idah: WinOle.IDataAdviseHolder;
ioah: WinOle.IOleAdviseHolder;
isg: WinOle.IStorage;
ism: WinOle.IStream;
rsm: WinOle.IStream;
menu: WinApi.HMENU;
oleMenu: WinOle.HOLEMENU;
menuType: Stores.TypeName;
w, h: INTEGER;
view: Views.View;
seq: Sequencers.Sequencer;
win: HostWindows.Window; (* # NIL => open *)
embedded: BOOLEAN;
update: BOOLEAN;
uiActive: BOOLEAN;
useMenu: BOOLEAN;
unit: INTEGER (* scaling when in place open *)
END;
IOleObject = POINTER TO RECORD (WinOle.IOleObject)
obj: Object
END;
IDataObject = POINTER TO RECORD (WinOle.IDataObject)
obj: Object;
data: OleData.IDataObject
END;
IPersistStorage = POINTER TO EXTENSIBLE RECORD (WinOle.IPersistStorage)
obj: Object
END;
IOleInPlaceObject = POINTER TO RECORD (WinOle.IOleInPlaceObject);
obj: Object
END;
IOleInPlaceActiveObject = POINTER TO RECORD (WinOle.IOleInPlaceActiveObject)
obj: Object
END;
Window = POINTER TO RECORD (HostWindows.Window)
obj: Object
END;
WinDir = POINTER TO RECORD (HostWindows.Directory)
obj: Object;
host: WinApi.HWND;
pos, clip: WinApi.RECT;
END;
Action = POINTER TO RECORD (Services.Action)
w: Window
END;
Verb = POINTER TO RECORD
verb: INTEGER;
name: ARRAY 64 OF CHAR;
disabled, checked: BOOLEAN;
next: Verb
END;
IEnumOLEVERB = POINTER TO RECORD (WinOle.IEnumOLEVERB)
first, cur: Verb
END;
VAR
factory: IClassFactory;
token: INTEGER;
winDir: WinDir;
(* ---------- auxiliary ---------- *)
PROCEDURE Max (x, y: INTEGER): INTEGER;
BEGIN
IF x > y THEN RETURN x ELSE RETURN y END
END Max;
PROCEDURE Min (x, y: INTEGER): INTEGER;
BEGIN
IF x < y THEN RETURN x ELSE RETURN y END
END Min;
PROCEDURE GenGlobalMedium (hg: WinApi.HGLOBAL; unk: COM.IUnknown; VAR sm: WinOle.STGMEDIUM);
BEGIN
sm.tymed := WinOle.TYMED_HGLOBAL;
sm.u.hGlobal := hg;
sm.pUnkForRelease := unk
END GenGlobalMedium;
PROCEDURE MediumGlobal (VAR sm: WinOle.STGMEDIUM): WinApi.HGLOBAL;
BEGIN
ASSERT(sm.tymed = WinOle.TYMED_HGLOBAL, 20);
RETURN sm.u.hGlobal
END MediumGlobal;
PROCEDURE GenStorageMedium (stg: WinOle.IStorage; unk: COM.IUnknown; VAR sm: WinOle.STGMEDIUM);
TYPE PS = POINTER TO RECORD t: SET; s: WinOle.IStorage; u: COM.IUnknown END;
VAR ps: PS;
BEGIN
sm.u.hGlobal := 0;
sm.tymed := WinOle.TYMED_ISTORAGE;
sm.u.pstg := stg;
sm.pUnkForRelease := unk
END GenStorageMedium;
PROCEDURE MediumStorage (VAR sm: WinOle.STGMEDIUM): WinOle.IStorage;
BEGIN
ASSERT(sm.tymed = WinOle.TYMED_ISTORAGE, 20);
RETURN sm.u.pstg
END MediumStorage;
PROCEDURE NewString (VAR str: ARRAY OF CHAR): WinApi.PtrWSTR;
VAR n: INTEGER; p: WinApi.PtrWSTR;
BEGIN
n := 0; WHILE str[n] # 0X DO INC(n) END;
p := SYSTEM.VAL(WinApi.PtrWSTR, WinOle.CoTaskMemAlloc(SIZE(CHAR) * (n + 1)));
p^ := str$;
RETURN p
END NewString;
PROCEDURE CheckVerb (v: Views.View; n: INTEGER; VAR pvm: Properties.PollVerbMsg);
BEGIN
pvm.verb := SHORT(n);
pvm.label := "";
pvm.disabled := FALSE; pvm.checked := FALSE;
IF v # NIL THEN Views.HandlePropMsg(v, pvm) END
END CheckVerb;
(* ---------- IClassFactory ---------- *)
PROCEDURE (this: IClassFactory) CreateInstance (outer: COM.IUnknown; IN [iid] iid: COM.GUID;
OUT [new] int: COM.IUnknown): COM.RESULT;
VAR res: COM.RESULT; new: Object;
BEGIN
IF debug THEN Log.String("create instance"); Log.Ln END;
IF outer = NIL THEN
NEW(new);
IF new # NIL THEN
NEW(new.ioo, new); NEW(new.ido, new); NEW(new.ips, new); NEW(new.iipo, new);
NEW(new.iipao); (* separate component *)
IF (new.ioo # NIL) & (new.ido # NIL) & (new.ips # NIL) & (new.iipo # NIL) & (new.iipao # NIL) THEN
new.ioo.obj := new;
new.ido.obj := new;
new.ido.data := OleData.ViewData(NIL, 0, 0, TRUE);
new.ips.obj := new;
new.iipo.obj := new;
new.iipao.obj := new;
new.embedded := FALSE;
res := new.QueryInterface(iid, int);
IF res >= 0 THEN HostMenus.Lock END;
IF debug THEN Log.String("c lock "); Log.Int(HostMenus.locks); Log.Ln END;
ELSE res := WinApi.E_OUTOFMEMORY
END
ELSE res := WinApi.E_OUTOFMEMORY
END
ELSE res := WinApi.CLASS_E_NOAGGREGATION
END;
RETURN res
END CreateInstance;
PROCEDURE (this: IClassFactory) LockServer (lock: WinApi.BOOL): COM.RESULT;
BEGIN
IF lock # 0 THEN HostMenus.Lock ELSE HostMenus.Unlock END;
IF debug THEN Log.String("lock server "); Log.Int(lock); Log.Int(HostMenus.locks); Log.Ln END;
RETURN WinApi.S_OK
END LockServer;
(* IEnumOLEVERB *)
PROCEDURE (this: IEnumOLEVERB) Next (num: INTEGER; OUT elem: ARRAY [untagged] OF WinOle.OLEVERB;
OUT [nil] fetched: INTEGER): COM.RESULT;
VAR n: INTEGER; flags: SET;
BEGIN
n := 0;
IF VALID(fetched) THEN fetched := 0
ELSIF num # 1 THEN RETURN WinApi.E_POINTER
END;
IF this.cur # NIL THEN
WHILE (this.cur # NIL) & (num > 0) DO
elem[n].lVerb := this.cur.verb;
elem[n].lpszVerbName := NewString(this.cur.name);
flags := {};
IF this.cur.disabled THEN INCL(flags, 0) END;
IF this.cur.checked THEN INCL(flags, 3) END;
elem[n].fuFlags := flags;
IF this.cur.verb >= 0 THEN
elem[n].grfAttribs := WinOle.OLEVERBATTRIB_ONCONTAINERMENU
ELSE
elem[n].grfAttribs := {}
END;
this.cur := this.cur.next; INC(n); DEC(num)
END;
IF VALID(fetched) THEN fetched := n END;
RETURN WinApi.S_OK
END;
RETURN WinApi.S_FALSE
END Next;
PROCEDURE (this: IEnumOLEVERB) Skip (num: INTEGER): COM.RESULT;
BEGIN
WHILE (num > 0) & (this.cur # NIL) DO this.cur := this.cur.next; DEC(num) END;
IF this.cur # NIL THEN RETURN WinApi.S_OK
ELSE RETURN WinApi.S_FALSE
END
END Skip;
PROCEDURE (this: IEnumOLEVERB) Reset (): COM.RESULT;
BEGIN
this.cur := this.first;
RETURN WinApi.S_OK
END Reset;
PROCEDURE (this: IEnumOLEVERB) Clone (OUT enum: WinOle.IEnumOLEVERB): COM.RESULT;
VAR new: IEnumOLEVERB;
BEGIN
NEW(new);
IF new # NIL THEN
new.first := this.first;
new.cur := this.cur;
enum := new;
RETURN WinApi.S_OK
ELSE RETURN WinApi.E_OUTOFMEMORY
END
END Clone;
(*
(* ---------- Object Release Patch ---------- *) (* VERY BIG HACK !!!!!!!!! *)
PROCEDURE^ (this: Object) InPlaceDeactivate ();
PROCEDURE ObjectRelease (this: Object): LONGINT;
VAR n: LONGINT; msg: Sequencers.RemoveMsg;
BEGIN
n := Kernel.Release(SYSTEM.VAL(LONGINT, this));
IF debug THEN Log.String("release "); Log.Int(n); Log.Ln END;
IF n = 0 THEN
IF this.iips # NIL THEN this.InPlaceDeactivate END;
this.ics := NIL; this.idah := NIL; this.ioah := NIL;
IF this.seq # NIL THEN this.seq.Notify(msg) END;
HostMenus.Unlock;
IF debug THEN Log.String("r unlock "); Log.Int(HostMenus.locks); Log.Ln END;
Kernel.Cleanup
END;
RETURN n
END ObjectRelease;
PROCEDURE PatchObjectRelease;
CONST releaseMethOff = -4;
BEGIN
SYSTEM.PUT(SYSTEM.ADR(Object) + releaseMethOff, SYSTEM.ADR(ObjectRelease))
END PatchObjectRelease;
*)
(* ---------- Object ---------- *)
PROCEDURE^ (this: Object) InPlaceDeactivate (), NEW;
PROCEDURE (this: Object) RELEASE;
VAR msg: Sequencers.RemoveMsg;
BEGIN
IF this.iips # NIL THEN this.InPlaceDeactivate END;
this.ics := NIL; this.idah := NIL; this.ioah := NIL;
IF this.seq # NIL THEN this.seq.Notify(msg) END;
HostMenus.Unlock;
IF debug THEN Log.String("r unlock "); Log.Int(HostMenus.locks); Log.Ln END;
Kernel.Cleanup
END RELEASE;
PROCEDURE (this: Object) QueryInterface (IN iid: COM.GUID; OUT int: COM.IUnknown): COM.RESULT;
BEGIN
IF debug THEN Log.String("query interface"); Log.Ln END;
IF COM.QUERY(this, iid, int)
OR COM.QUERY(this.ioo, iid, int)
OR COM.QUERY(this.ido, iid, int)
OR COM.QUERY(this.ips, iid, int)
OR COM.QUERY(this.iipo, iid, int) THEN RETURN WinApi.S_OK
ELSE RETURN WinApi.E_NOINTERFACE
END
END QueryInterface;
PROCEDURE (this: Object) GetMenuType (VAR changed: BOOLEAN), NEW;
VAR ops: Controllers.PollOpsMsg;
BEGIN
ops.type := ""; this.win.ForwardCtrlMsg(ops);
IF ops.type # this.menuType THEN
changed := TRUE;
this.menuType := ops.type$
ELSE
changed := FALSE
END
END GetMenuType;
PROCEDURE (this: Object) InPlaceMenuCreate (), NEW;
VAR menu: WinApi.HMENU; res, i, p, n: INTEGER; widths: WinOle.OLEMENUGROUPWIDTHS;
m: HostMenus.Menu; ss: ARRAY 256 OF SHORTCHAR;
BEGIN
IF debug THEN Log.String("create menu"); Log.Ln END;
i := 0; WHILE i < 6 DO widths.width[i] := 0; INC(i) END;
menu := WinApi.CreateMenu();
res := this.iipf.InsertMenus(menu, widths);
m := HostMenus.menus; p := 0; i := 0;
WHILE p < 6 DO
WHILE (m # NIL) & (m.class <= p) DO m := m.next END;
INC(i, widths.width[p]); INC(p); n := 0;
WHILE (m # NIL) & (m.class = p) DO
IF (m.type = "") OR (m.type = this.menuType) THEN
ss := SHORT(m.menu$);
res := WinApi.InsertMenu(menu, i, WinApi.MF_POPUP + WinApi.MF_BYPOSITION, m.menuH, ss);
INC(n); INC(i)
END;
m := m.next;
END;
widths.width[p] := n; INC(p)
END;
this.menu := menu;
this.oleMenu := WinOle.OleCreateMenuDescriptor(menu, widths);
IF debug THEN Log.String("menu created"); Log.Ln END;
END InPlaceMenuCreate;
PROCEDURE (this: Object) InPlaceMenuDestroy (), NEW;
VAR res: COM.RESULT; i: INTEGER; m: HostMenus.Menu; sm: WinApi.HMENU;
BEGIN
IF debug THEN Log.String("destroy menu"); Log.Ln END;
res := WinOle.OleDestroyMenuDescriptor(this.oleMenu);
this.oleMenu := 0;
i := WinApi.GetMenuItemCount(this.menu);
WHILE i > 0 DO
DEC(i); sm := WinApi.GetSubMenu(this.menu, i);
m := HostMenus.menus;
WHILE (m # NIL) & (m.menuH # sm) DO m := m.next END;
IF m # NIL THEN res := WinApi.RemoveMenu(this.menu, i, WinApi.MF_BYPOSITION) END
END;
IF this.iipf # NIL THEN res := this.iipf.RemoveMenus(this.menu) END;
res := WinApi.DestroyMenu(this.menu);
this.menu := 0;
IF debug THEN Log.String("menu destroyed"); Log.Ln END;
END InPlaceMenuDestroy;
PROCEDURE (this: Object) UIActivate (): COM.RESULT, NEW;
VAR res: COM.RESULT; dumy: BOOLEAN; rect: WinApi.RECT;
BEGIN
IF debug THEN Log.String("ui activate"); Log.Ln END;
IF this.iips # NIL THEN res := this.iips.OnUIActivate() END;
res := WinApi.SetFocus(this.win.wnd);
HostWindows.ActivateWindow(this.win, TRUE);
IF this.iipf # NIL THEN res := this.iipf.SetActiveObject(this.iipao, "") END;
IF this.iipw # NIL THEN res := this.iipw.SetActiveObject(this.iipao, "") END;
this.GetMenuType(dumy);
this.InPlaceMenuCreate;
res := this.iipf.SetMenu(this.menu, this.oleMenu, HostWindows.main);
this.useMenu := TRUE;
HostMenus.isObj := TRUE;
rect.left := 0; rect.top := 0; rect.right := 0; rect.bottom := 0;
IF this.iipf # NIL THEN res := this.iipf.SetBorderSpace(rect) END;
IF this.iipw # NIL THEN res := this.iipw.SetBorderSpace(rect) END;
this.uiActive := TRUE;
IF debug THEN Log.String("ui active"); Log.Ln END;
RETURN WinApi.S_OK
END UIActivate;
PROCEDURE (this: Object) UIDeactivate (), NEW;
VAR res: COM.RESULT;
BEGIN
IF debug THEN Log.String("ui deactivate"); Log.Ln END;
IF this.iipf # NIL THEN res := this.iipf.SetMenu(0, 0, 0) END;
this.useMenu := FALSE;
this.InPlaceMenuDestroy;
IF this.win # NIL THEN HostWindows.ActivateWindow(this.win, FALSE) END;
IF this.iipf # NIL THEN res := this.iipf.SetActiveObject(NIL, NIL) END;
IF this.iipw # NIL THEN res := this.iipw.SetActiveObject(NIL, NIL) END;
IF this.iips # NIL THEN res := this.iips.OnUIDeactivate(0) END;
HostMenus.isObj := FALSE;
this.uiActive := FALSE;
IF debug THEN Log.String("ui deactive"); Log.Ln END;
END UIDeactivate;
PROCEDURE (this: Object) InPlaceActivate (site: WinOle.IOleClientSite; ui: BOOLEAN): COM.RESULT, NEW;
VAR res: COM.RESULT; host: WinApi.HWND;
d: Documents.Document; c: Containers.Controller; w: Windows.Window;
BEGIN
IF site # NIL THEN
IF this.iips = NIL THEN
IF debug THEN Log.String("try in place"); Log.Ln END;
res := site.QueryInterface(COM.ID(this.iips), this.iips);
IF res < 0 THEN RETURN res END;
res := this.iips.CanInPlaceActivate();
IF res = WinApi.S_OK THEN
IF debug THEN Log.String("in place activate"); Log.Ln END;
res := this.iips.OnInPlaceActivate();
(* undodeactivates := TRUE *)
res := this.iips.GetWindow(host);
this.fInfo.cb := SIZE(WinOle.OLEINPLACEFRAMEINFO);
res := this.iips.GetWindowContext(this.iipf, this.iipw, winDir.pos, winDir.clip, this.fInfo);
(* open window *)
this.view := Views.CopyOf(this.view, Views.shallow);
winDir.obj := this; winDir.host := host;
Windows.SetDir(winDir);
d := Documents.dir.New(this.view, this.w, this.h);
c := d.ThisController();
c.SetOpts(c.opts - {Documents.pageWidth..Documents.winHeight} + {31});
StdDialog.Open(d, "", NIL, "", NIL, TRUE, FALSE, FALSE, FALSE, TRUE);
w := Windows.dir.First();
this.seq := w.seq;
this.win := w(Window);
OleData.SetView(this.ido.data, this.view, this.w, this.h);
Windows.SetDir(Windows.stdDir);
IF this.ics # NIL THEN res := this.ics.ShowObject() END;
IF debug THEN Log.String("in place active"); Log.Ln END;
ELSE
this.iips := NIL;
RETURN WinApi.E_FAIL
END
END;
IF ui THEN res := this.UIActivate() END;
IF this.iips # NIL THEN (* minimal undo support *)
res := this.iips.DiscardUndoState()
END
ELSE RETURN WinApi.E_INVALIDARG
END;
RETURN WinApi.S_OK
END InPlaceActivate;
PROCEDURE (this: Object) CheckViewUpdate (), NEW;
VAR res: COM.RESULT; w, h: INTEGER; v: Views.View; changed: BOOLEAN;
BEGIN
IF (this.win # NIL) & (this.win.doc # NIL) THEN
v := this.win.doc.ThisView();
v.context.GetSize(w, h);
IF (v # this.view) OR (w # this.w) OR (h # this.h) THEN
this.view := v; this.w := w; this.h := h;
OleData.SetView(this.ido.data, v, w, h);
this.update := TRUE
END
END;
IF this.update & (this.idah # NIL) & (this.iips = NIL) THEN
IF debug THEN Log.String("on data change"); Log.Ln END;
res := this.idah.SendOnDataChange(this.ido, 0, {});
this.update := FALSE
END;
(* check menus *)
IF (this.win # NIL) & (this.iipf # NIL) & (this.menu # 0) & (Windows.dir.Focus(Controllers.targetPath) = this.win)
THEN
this.GetMenuType(changed);
IF changed THEN
this.InPlaceMenuDestroy(); this.InPlaceMenuCreate;
IF this.useMenu THEN
res := this.iipf.SetMenu(this.menu, this.oleMenu, HostWindows.main)
END
END
END
END CheckViewUpdate;
PROCEDURE (this: Object) InPlaceDeactivate (), NEW;
VAR res: COM.RESULT;
BEGIN
IF debug THEN Log.String("in place deactivate"); Log.Ln END;
this.UIDeactivate;
IF this.win # NIL THEN this.win.Close(); this.win := NIL END;
IF this.iips # NIL THEN res := this.iips.OnInPlaceDeactivate() END;
this.iips := NIL; this.iipf := NIL; this.iipw := NIL;
this.CheckViewUpdate;
Kernel.Cleanup;
IF debug THEN Log.String("in place deactive"); Log.Ln END;
END InPlaceDeactivate;
PROCEDURE (this: Object) Open (), NEW;
VAR res: COM.RESULT; v: Views.View; d: Documents.Document; c: Containers.Controller; w: Windows.Window;
BEGIN
IF this.win = NIL THEN
IF this.view = NIL THEN
IF debug THEN Log.String("show new"); Log.Ln END;
v := TextViews.dir.New(NIL)
ELSE
IF debug THEN Log.String("show old"); Log.Ln END;
v := Views.CopyOf(this.view, Views.shallow);
END;
winDir.obj := this;
Windows.SetDir(winDir);
d := Documents.dir.New(v, this.w, this.h);
c := d.ThisController();
c.SetOpts(c.opts - {Documents.pageWidth..Documents.winHeight});
Views.OpenAux(d, "BlackBox Object");
w := Windows.dir.First();
this.view := v;
this.seq := w.seq;
this.win := w(Window);
OleData.SetView(this.ido.data, this.view, this.w, this.h);
Windows.SetDir(Windows.stdDir)
END;
Windows.dir.Select(this.win, Windows.lazy);
IF this.ics # NIL THEN res := this.ics.ShowObject() END;
IF this.ics # NIL THEN res := this.ics.OnShowWindow(1) END;
END Open;
PROCEDURE (this: Object) CustomVerb (
verb: INTEGER; IN msg: WinApi.MSG; activeSite: WinOle.IOleClientSite;
index: INTEGER; parent: WinApi.HWND; IN posRect: WinApi.RECT
): COM.RESULT, NEW;
VAR res: COM.RESULT; pvm: Properties.PollVerbMsg; dvm: Properties.DoVerbMsg;
BEGIN
CheckVerb(this.view, 0, pvm);
IF pvm.label = "" THEN
IF verb = 0 THEN
RETURN this.ioo.DoVerb(WinOle.OLEIVERB_SHOW, msg, activeSite, index, parent, posRect)
ELSIF verb = 1 THEN
RETURN this.ioo.DoVerb(WinOle.OLEIVERB_OPEN, msg, activeSite, index, parent, posRect)
ELSE
DEC(verb)
END
END;
CheckVerb(this.view, verb, pvm);
IF pvm.label = "" THEN
res := this.ioo.DoVerb(0, msg, activeSite, index, parent, posRect);
RETURN WinApi.OLEOBJ_S_INVALIDVERB
END;
dvm.frame := NIL;
dvm.verb := SHORT(verb);
Views.HandlePropMsg(this.view, dvm);
RETURN WinApi.S_OK
END CustomVerb;
(* ---------- IOleObject ---------- *)
PROCEDURE (this: IOleObject) SetClientSite (site: WinOle.IOleClientSite): COM.RESULT;
BEGIN
this.obj.ics := site;
IF site = NIL THEN Kernel.Cleanup END;
RETURN WinApi.S_OK
END SetClientSite;
PROCEDURE (this: IOleObject) GetClientSite (OUT site: WinOle.IOleClientSite): COM.RESULT;
BEGIN
site := this.obj.ics;
RETURN WinApi.S_OK
END GetClientSite;
PROCEDURE (this: IOleObject) SetHostNames (app, obj: WinApi.PtrWSTR): COM.RESULT;
BEGIN
this.obj.embedded := TRUE;
RETURN WinApi.S_OK
END SetHostNames;
PROCEDURE (this: IOleObject) Close (saveOption: INTEGER): COM.RESULT;
VAR res: COM.RESULT; dirty: BOOLEAN; r: INTEGER; q: BOOLEAN;
BEGIN
IF (this.obj.view = NIL) OR (this.obj.seq # NIL) & this.obj.seq.Dirty() THEN
IF saveOption = WinOle.OLECLOSE_SAVEIFDIRTY THEN
IF this.obj.ics # NIL THEN res := this.obj.ics.SaveObject() END;
IF this.obj.ioah # NIL THEN res := this.obj.ioah.SendOnSave() END
ELSIF saveOption = WinOle.OLECLOSE_PROMPTSAVE THEN
IF this.obj.win # NIL THEN HostDialog.CloseDialog(this.obj.win, q, r)
ELSE r := HostDialog.save
END;
IF r = HostDialog.save THEN
IF this.obj.ics # NIL THEN res := this.obj.ics.SaveObject() END;
IF this.obj.ioah # NIL THEN res := this.obj.ioah.SendOnSave() END
ELSIF r = HostDialog.cancel THEN
RETURN WinApi.OLE_E_PROMPTSAVECANCELLED
END
END
END;
IF this.obj.win # NIL THEN Windows.dir.Close(this.obj.win) END;
Kernel.Cleanup;
RETURN WinApi.S_OK
END Close;
PROCEDURE (this: IOleObject) SetMoniker (which: INTEGER; mk: WinOle.IMoniker): COM.RESULT;
BEGIN
RETURN WinApi.E_NOTIMPL
END SetMoniker;
PROCEDURE (this: IOleObject) GetMoniker (assign, which: INTEGER; OUT mk: WinOle.IMoniker): COM.RESULT;
BEGIN
RETURN WinApi.E_NOTIMPL
END GetMoniker;
PROCEDURE (this: IOleObject) InitFromData (obj: WinOle.IDataObject; creation: WinApi.BOOL;
reserved: INTEGER): COM.RESULT;
BEGIN
RETURN WinApi.E_NOTIMPL
END InitFromData;
PROCEDURE (this: IOleObject) GetClipboardData (reserved: INTEGER; OUT obj: WinOle.IDataObject
): COM.RESULT;
BEGIN
RETURN WinApi.E_NOTIMPL
END GetClipboardData;
PROCEDURE (this: IOleObject) DoVerb (
verb: INTEGER; IN msg: WinApi.MSG; activeSite: WinOle.IOleClientSite;
index: INTEGER; parent: WinApi.HWND; IN posRect: WinApi.RECT
): COM.RESULT;
VAR res: COM.RESULT; v: Views.View; d: Documents.Document; pvm: Properties.PollVerbMsg;
c: Containers.Controller; w: Windows.Window; vw, vh: INTEGER; dvm: Properties.DoVerbMsg;
BEGIN
CASE verb OF
| WinOle.OLEIVERB_HIDE:
IF this.obj.iips # NIL THEN
this.obj.InPlaceDeactivate()
ELSE
IF this.obj.win # NIL THEN Windows.dir.Close(this.obj.win) END;
IF this.obj.ics # NIL THEN res := this.obj.ics.OnShowWindow(0) END;
Kernel.Cleanup
END
| WinOle.OLEIVERB_PRIMARY, WinOle.OLEIVERB_SHOW:
IF this.obj.win = NIL THEN
res := this.obj.InPlaceActivate(activeSite, TRUE);
IF res # WinApi.S_OK THEN this.obj.Open END
END
| WinOle.OLEIVERB_OPEN:
IF this.obj.iips # NIL THEN this.obj.InPlaceDeactivate END;
this.obj.Open
| WinOle.OLEIVERB_INPLACEACTIVATE:
RETURN this.obj.InPlaceActivate(activeSite, FALSE)
| WinOle.OLEIVERB_UIACTIVATE:
RETURN this.obj.InPlaceActivate(activeSite, TRUE)
| WinOle.OLEIVERB_DISCARDUNDOSTATE:
(* discard undo *)
ELSE
IF verb >= 0 THEN RETURN this.obj.CustomVerb(verb, msg, activeSite, index, parent, posRect)
ELSE RETURN WinApi.E_NOTIMPL
END
END;
RETURN WinApi.S_OK
END DoVerb;
PROCEDURE (this: IOleObject) EnumVerbs (OUT enum: WinOle.IEnumOLEVERB): COM.RESULT;
VAR e: IEnumOLEVERB; v, last: Verb; pvm: Properties.PollVerbMsg; i, j: INTEGER;
BEGIN
NEW(e);
IF e # NIL THEN
NEW(v); v.verb := -3; v.name := "Hide"; e.first := v; last := v;
NEW(v); v.verb := -2; v.name := "Open"; last.next := v; last := v;
NEW(v); v.verb := -1; v.name := "Show"; last.next := v; last := v;
i := 0; j := 0;
CheckVerb(this.obj.view, 0, pvm);
IF pvm.label = "" THEN
NEW(v); v.verb := i; INC(i); last.next := v; last := v;
Dialog.MapString("#Host:Edit", v.name);
NEW(v); v.verb := i; INC(i); last.next := v; last := v;
Dialog.MapString("#Host:Open", v.name);
INC(j);
CheckVerb(this.obj.view, j, pvm)
END;
WHILE pvm.label # "" DO
NEW(v); v.verb := i; INC(i); last.next := v; last := v;
Dialog.MapString(pvm.label, v.name);
v.disabled := pvm.disabled;
v.checked := pvm.checked;
INC(j);
CheckVerb(this.obj.view, j, pvm)
END;
e.cur := e.first; enum := e;
RETURN WinApi.S_OK
ELSE RETURN WinApi.E_OUTOFMEMORY
END
END EnumVerbs;
PROCEDURE (this: IOleObject) Update (): COM.RESULT;
BEGIN
RETURN WinApi.S_OK
END Update;
PROCEDURE (this: IOleObject) IsUpToDate (): COM.RESULT;
BEGIN
RETURN WinApi.S_OK
END IsUpToDate;
PROCEDURE (this: IOleObject) GetUserClassID (OUT id: COM.GUID): COM.RESULT;
BEGIN
id := ObjectID;
RETURN WinApi.S_OK
END GetUserClassID;
PROCEDURE (this: IOleObject) GetUserType (form: INTEGER; OUT type: WinApi.PtrWSTR): COM.RESULT;
BEGIN
RETURN WinApi.OLE_S_USEREG
END GetUserType;
PROCEDURE (this: IOleObject) SetExtent (aspect: SET; IN size: WinApi.SIZE): COM.RESULT;
VAR res: COM.RESULT;
BEGIN
IF aspect * WinOle.DVASPECT_CONTENT # {} THEN
IF debug THEN Log.String("set extent"); Log.Int(size.cx); Log.Int(size.cy); Log.Ln END;
this.obj.w := size.cx * oleUnit; this.obj.h := size.cy * oleUnit;
OleData.SetView(this.obj.ido.data, this.obj.view, this.obj.w, this.obj.h);
IF this.obj.win # NIL THEN
this.obj.view.context.SetSize(this.obj.w, this.obj.h)
END;
IF debug THEN Log.String("on data change (se)"); Log.Ln END;
IF this.obj.idah # NIL THEN res := this.obj.idah.SendOnDataChange(this.obj.ido, 0, {}) END;
RETURN WinApi.S_OK
ELSE RETURN WinApi.E_FAIL
END
END SetExtent;
PROCEDURE (this: IOleObject) GetExtent (aspect: SET; OUT size: WinApi.SIZE): COM.RESULT;
BEGIN
IF aspect * WinOle.DVASPECT_CONTENT # {} THEN
this.obj.CheckViewUpdate;
IF (this.obj.w # 0) & (this.obj.h # 0) THEN
size.cx := this.obj.w DIV oleUnit; size.cy := this.obj.h DIV oleUnit;
IF debug THEN Log.String("get extent"); Log.Int(size.cx); Log.Int(size.cy); Log.Ln END;
RETURN WinApi.S_OK
END
END;
RETURN WinApi.E_FAIL
END GetExtent;
PROCEDURE (this: IOleObject) Advise (sink: WinOle.IAdviseSink; OUT connection: INTEGER): COM.RESULT;
VAR res: COM.RESULT;
BEGIN
IF this.obj.ioah = NIL THEN
res := WinOle.CreateOleAdviseHolder(this.obj.ioah);
IF res < 0 THEN RETURN res END
END;
RETURN this.obj.ioah.Advise(sink, connection)
END Advise;
PROCEDURE (this: IOleObject) Unadvise (connection: INTEGER): COM.RESULT;
BEGIN
IF this.obj.ioah # NIL THEN
RETURN this.obj.ioah.Unadvise(connection)
ELSE RETURN WinApi.E_FAIL
END
END Unadvise;
PROCEDURE (this: IOleObject) EnumAdvise (OUT enum: WinOle.IEnumSTATDATA): COM.RESULT;
BEGIN
IF this.obj.ioah # NIL THEN
RETURN this.obj.ioah.EnumAdvise(enum)
ELSE RETURN WinApi.E_FAIL
END
END EnumAdvise;
PROCEDURE (this: IOleObject) GetMiscStatus (aspect: SET; OUT status: SET): COM.RESULT;
BEGIN
status := miscStatus;
RETURN WinApi.S_OK
END GetMiscStatus;
PROCEDURE (this: IOleObject) SetColorScheme (IN pal: WinApi.LOGPALETTE): COM.RESULT;
BEGIN
RETURN WinApi.E_NOTIMPL
END SetColorScheme;
(* ---------- IDataObject ---------- *)
PROCEDURE (this: IDataObject) GetData (IN format: WinOle.FORMATETC;
OUT medium: WinOle.STGMEDIUM): COM.RESULT;
BEGIN
IF debug THEN Log.String("get data"); Log.Ln END;
RETURN this.data.GetData(format, medium)
END GetData;
PROCEDURE (this: IDataObject) GetDataHere (IN format: WinOle.FORMATETC;
VAR medium: WinOle.STGMEDIUM): COM.RESULT;
BEGIN
IF debug THEN Log.String("get data here"); Log.Ln END;
RETURN this.data.GetDataHere(format, medium)
END GetDataHere;
PROCEDURE (this: IDataObject) QueryGetData (IN format: WinOle.FORMATETC): COM.RESULT;
BEGIN
IF debug THEN Log.String("query get data"); Log.Ln END;
RETURN this.data.QueryGetData(format)
END QueryGetData;
PROCEDURE (this: IDataObject) GetCanonicalFormatEtc (IN formatIn: WinOle.FORMATETC;
OUT formatOut: WinOle.FORMATETC): COM.RESULT;
BEGIN
RETURN WinApi.DATA_S_SAMEFORMATETC
END GetCanonicalFormatEtc;
PROCEDURE (this: IDataObject) SetData (IN format: WinOle.FORMATETC;
IN medium: WinOle.STGMEDIUM; release: WinApi.BOOL): COM.RESULT;
BEGIN
RETURN WinApi.DV_E_FORMATETC
END SetData;
PROCEDURE (this: IDataObject) EnumFormatEtc (
direction: SET; OUT enum: WinOle.IEnumFORMATETC
): COM.RESULT;
BEGIN
RETURN this.data.EnumFormatEtc(direction, enum)
END EnumFormatEtc;
PROCEDURE (this: IDataObject) DAdvise (
IN format: WinOle.FORMATETC; flags: SET; advSink: WinOle.IAdviseSink; OUT connection: INTEGER
): COM.RESULT;
VAR res: COM.RESULT;
BEGIN
IF this.obj.idah = NIL THEN
res := WinOle.CreateDataAdviseHolder(this.obj.idah);
IF res < 0 THEN RETURN res END
END;
RETURN this.obj.idah.Advise(this, format, flags, advSink, connection)
END DAdvise;
PROCEDURE (this: IDataObject) DUnadvise (connection: INTEGER): COM.RESULT;
BEGIN
IF this.obj.idah # NIL THEN
RETURN this.obj.idah.Unadvise(connection)
ELSE RETURN WinApi.E_FAIL
END
END DUnadvise;
PROCEDURE (this: IDataObject) EnumDAdvise (OUT enum: WinOle.IEnumSTATDATA): COM.RESULT;
BEGIN
IF this.obj.idah # NIL THEN
RETURN this.obj.idah.EnumAdvise(enum)
ELSE RETURN WinApi.E_FAIL
END
END EnumDAdvise;
(* ---------- IPersistStorage ---------- *)
PROCEDURE (this: IPersistStorage) GetClassID* (OUT id: COM.GUID): COM.RESULT, EXTENSIBLE;
BEGIN
id := ObjectID;
RETURN WinApi.S_OK
END GetClassID;
PROCEDURE (this: IPersistStorage) IsDirty (): COM.RESULT;
BEGIN
IF (this.obj.view = NIL) OR (this.obj.seq # NIL) & this.obj.seq.Dirty() THEN RETURN WinApi.S_OK
ELSE RETURN WinApi.S_FALSE
END
END IsDirty;
PROCEDURE (this: IPersistStorage) InitNew (stg: WinOle.IStorage): COM.RESULT;
VAR res: COM.RESULT; ps: WinApi.PtrWSTR;
BEGIN
IF debug THEN Log.String("init new"); Log.Ln END;
IF stg # NIL THEN
res := stg.CreateStream(streamStr,
WinOle.STGM_DIRECT + WinOle.STGM_CREATE
+ WinOle.STGM_READWRITE + WinOle.STGM_SHARE_EXCLUSIVE,
0, 0, this.obj.ism);
IF res >= 0 THEN
res := WinOle.OleRegGetUserType(ObjectID, WinOle.USERCLASSTYPE_SHORT, ps);
res := WinOle.WriteFmtUserTypeStg(stg, cbFormat, ps);
WinOle.CoTaskMemFree(SYSTEM.VAL(WinApi.PtrVoid, ps));
this.obj.isg := stg;
this.obj.w := 60 * Ports.mm;
this.obj.h := 60 * Ports.mm;
this.obj.rsm := NIL;
this.obj.view := TextViews.dir.New(NIL);
this.obj.seq := NIL;
this.obj.win := NIL;
OleData.SetView(this.obj.ido.data, this.obj.view, this.obj.w, this.obj.h);
RETURN WinApi.S_OK
ELSE RETURN res
END
ELSE RETURN WinApi.E_POINTER
END
END InitNew;
PROCEDURE (this: IPersistStorage) Load (stg: WinOle.IStorage): COM.RESULT;
VAR res: COM.RESULT; tag, version: INTEGER; is: BOOLEAN;
BEGIN
IF debug THEN Log.String("load"); Log.Ln END;
IF stg # NIL THEN
res := stg.OpenStream(streamStr, 0,
WinOle.STGM_DIRECT + WinOle.STGM_READWRITE + WinOle.STGM_SHARE_EXCLUSIVE,
0, this.obj.ism);
IF res >= 0 THEN
res := WinOle.CreateStreamOnHGlobal(0, 1, this.obj.rsm);
res := this.obj.ism.CopyTo(this.obj.rsm, MAX(LONGINT), NIL, NIL);
OleStorage.ImportFromStream(this.obj.rsm, this.obj.view, this.obj.w, this.obj.h, is);
IF this.obj.view # NIL THEN
this.obj.seq := NIL;
this.obj.win := NIL;
this.obj.isg := stg;
OleData.SetView(this.obj.ido.data, this.obj.view, this.obj.w, this.obj.h);
RETURN WinApi.S_OK
END
END;
RETURN WinApi.STG_E_READFAULT
ELSE RETURN WinApi.E_POINTER
END
END Load;
PROCEDURE (this: IPersistStorage) Save (stg: WinOle.IStorage; sameAsLoad: WinApi.BOOL): COM.RESULT;
VAR stm: WinOle.IStream; res: COM.RESULT; ps: WinApi.PtrWSTR;
BEGIN
IF sameAsLoad # 0 THEN
IF debug THEN Log.String("save same"); Log.Ln END;
stm := this.obj.ism;
ELSIF stg # NIL THEN
IF debug THEN Log.String("save"); Log.Ln END;
res := stg.CreateStream(streamStr,
WinOle.STGM_DIRECT + WinOle.STGM_CREATE
+ WinOle.STGM_READWRITE + WinOle.STGM_SHARE_EXCLUSIVE,
0, 0, stm);
IF res < 0 THEN RETURN res END;
res := WinOle.OleRegGetUserType(ObjectID, WinOle.USERCLASSTYPE_SHORT, ps);
res := WinOle.WriteFmtUserTypeStg(stg, cbFormat, ps);
WinOle.CoTaskMemFree(SYSTEM.VAL(WinApi.PtrVoid, ps));
ELSE RETURN WinApi.E_POINTER
END;
this.obj.CheckViewUpdate;
OleStorage.ExportToStream(stm, this.obj.view, this.obj.w, this.obj.h, TRUE);
IF this.obj.seq # NIL THEN
this.obj.seq.BeginModification(Sequencers.notUndoable, NIL);
this.obj.seq.EndModification(Sequencers.notUndoable, NIL); (* clear sequencer *)
this.obj.seq.SetDirty(FALSE)
END;
RETURN WinApi.S_OK
END Save;
PROCEDURE (this: IPersistStorage) SaveCompleted (new: WinOle.IStorage): COM.RESULT;
VAR res: COM.RESULT;
BEGIN
IF debug THEN Log.String("save completed"); Log.Ln END;
IF new # NIL THEN
res := new.OpenStream(streamStr, 0,
WinOle.STGM_DIRECT + WinOle.STGM_READWRITE + WinOle.STGM_SHARE_EXCLUSIVE,
0, this.obj.ism);
IF res >= 0 THEN
this.obj.isg := new;
ELSE RETURN res
END
END;
IF this.obj.ioah # NIL THEN res := this.obj.ioah.SendOnSave() END;
RETURN WinApi.S_OK
END SaveCompleted;
PROCEDURE (this: IPersistStorage) HandsOffStorage (): COM.RESULT;
VAR n: INTEGER;
BEGIN
this.obj.ism := NIL; this.obj.isg := NIL;
RETURN WinApi.S_OK
END HandsOffStorage;
(* ---------- IOleInPlaceObject ---------- *)
PROCEDURE (this: IOleInPlaceObject) GetWindow (OUT wnd: WinApi.HWND): COM.RESULT;
BEGIN
IF debug THEN Log.String("iipo: get window"); Log.Ln END;
wnd := this.obj.win.wnd;
ASSERT(wnd # 0, 100);
RETURN WinApi.S_OK
END GetWindow;
PROCEDURE (this: IOleInPlaceObject) ContextSensitiveHelp (enter: WinApi.BOOL): COM.RESULT;
BEGIN
IF debug THEN Log.String("iipo: context help"); Log.Ln END;
RETURN WinApi.S_OK
END ContextSensitiveHelp;
PROCEDURE (this: IOleInPlaceObject) InPlaceDeactivate (): COM.RESULT;
BEGIN
IF debug THEN Log.String("iipo: ip deactivate"); Log.Ln END;
this.obj.InPlaceDeactivate;
RETURN WinApi.S_OK
END InPlaceDeactivate;
PROCEDURE (this: IOleInPlaceObject) UIDeactivate (): COM.RESULT;
BEGIN
IF debug THEN Log.String("iipo: ui deactivate"); Log.Ln END;
this.obj.UIDeactivate;
RETURN WinApi.S_OK
END UIDeactivate;
PROCEDURE (this: IOleInPlaceObject) SetObjectRects (IN pos, clip: WinApi.RECT): COM.RESULT;
VAR l, t, r, b, bw, u, res: INTEGER;
BEGIN
IF debug THEN Log.String("iipo: set rect"); Log.Ln END;
u := this.obj.unit;
bw := borderW DIV HostWindows.unit;
l := Max(pos.left - bw, clip.left);
t := Max(pos.top - bw, clip.top);
r := Min(pos.right + bw, clip.right);
b := Min(pos.bottom + bw, clip.bottom);
res := WinApi.SetWindowPos(this.obj.win.wnd, 0, l, t, r - l, b - t, WinApi.SWP_NOZORDER);
this.obj.win.SetSize(r - l, b - t);
l := Min(bw, pos.left - clip.left) * u;
t := Min(bw, pos.top - clip.top) * u;
(*
r := l + (pos.right - pos.left) * u;
b := t + (pos.bottom - pos.top) * u;
*)
r := l + this.obj.w;
b := t + this.obj.h;
this.obj.win.doc.SetRect(l, t, r, b);
RETURN WinApi.S_OK
END SetObjectRects;
PROCEDURE (this: IOleInPlaceObject) ReactivateAndUndo (): COM.RESULT;
BEGIN
IF debug THEN Log.String("iipo: reactivate & undo"); Log.Ln END;
RETURN WinApi.S_OK
END ReactivateAndUndo;
(* ---------- IOleInPlaceActiveObject ---------- *)
PROCEDURE (this: IOleInPlaceActiveObject) GetWindow (OUT wnd: WinApi.HWND): COM.RESULT;
BEGIN
IF debug THEN Log.String("iipao: get window"); Log.Ln END;
wnd := this.obj.win.wnd;
RETURN WinApi.S_OK
END GetWindow;
PROCEDURE (this: IOleInPlaceActiveObject) ContextSensitiveHelp (enter: WinApi.BOOL): COM.RESULT;
BEGIN
IF debug THEN Log.String("iipao: context help"); Log.Ln END;
RETURN WinApi.S_OK
END ContextSensitiveHelp;
PROCEDURE (this: IOleInPlaceActiveObject) TranslateAccelerator (IN msg: WinApi.MSG): COM.RESULT;
BEGIN
IF debug THEN Log.String("iipao: translate acc"); Log.Ln END;
RETURN WinApi.S_FALSE
END TranslateAccelerator;
PROCEDURE (this: IOleInPlaceActiveObject) OnFrameWindowActivate (activate: WinApi.BOOL): COM.RESULT;
VAR res: COM.RESULT;
BEGIN
IF debug THEN Log.String("iipao: on frame active "); Log.Int(activate); Log.Ln END;
IF (this.obj.iipf # NIL) & (this.obj.iipw = NIL) THEN
IF activate # 0 THEN
HostWindows.ActivateWindow(this.obj.win, TRUE);
HostMenus.isObj := TRUE
ELSE
HostWindows.ActivateWindow(this.obj.win, FALSE);
HostMenus.isObj := FALSE
END
END;
RETURN WinApi.S_OK
END OnFrameWindowActivate;
PROCEDURE (this: IOleInPlaceActiveObject) OnDocWindowActivate (activate: WinApi.BOOL): COM.RESULT;
VAR res: COM.RESULT;
BEGIN
IF debug THEN Log.String("iipao: on win active"); Log.Int(activate); Log.Ln END;
IF this.obj.iipf # NIL THEN
IF activate # 0 THEN
IF this.obj.uiActive THEN res := this.obj.iipf.SetActiveObject(this, "") END;
HostWindows.ActivateWindow(this.obj.win, TRUE);
HostMenus.isObj := TRUE;
IF this.obj.menu # 0 THEN
res := this.obj.iipf.SetMenu(this.obj.menu, this.obj.oleMenu, HostWindows.main);
this.obj.useMenu := TRUE
END
ELSE
IF this.obj.menu # 0 THEN
res := this.obj.iipf.SetMenu(0, 0, 0);
this.obj.useMenu := FALSE
END;
HostWindows.ActivateWindow(this.obj.win, FALSE);
HostMenus.isObj := FALSE;
IF this.obj.uiActive THEN res := this.obj.iipf.SetActiveObject(NIL, NIL) END
END
END;
RETURN WinApi.S_OK
END OnDocWindowActivate;
PROCEDURE (this: IOleInPlaceActiveObject) ResizeBorder (IN border: WinApi.RECT;
win: WinOle.IOleInPlaceUIWindow; frameWin: WinApi.BOOL): COM.RESULT;
BEGIN
IF debug THEN Log.String("iipao: resize border"); Log.Ln END;
RETURN WinApi.S_OK
END ResizeBorder;
PROCEDURE (this: IOleInPlaceActiveObject) EnableModeless (enable: WinApi.BOOL): COM.RESULT;
BEGIN
IF debug THEN Log.String("iipao: enable modeless"); Log.Ln END;
RETURN WinApi.S_OK
END EnableModeless;
(* ---------- Window ---------- *)
PROCEDURE (w: Window) BroadcastViewMsg (VAR msg: Views.Message);
VAR res: COM.RESULT;
BEGIN
w.BroadcastViewMsg^(msg);
IF msg.view = w.obj.view THEN w.obj.update := TRUE END
END BroadcastViewMsg;
PROCEDURE (w: Window) ForwardCtrlMsg (VAR msg: Views.CtrlMessage);
VAR c, dc: Containers.Controller;
BEGIN
w.ForwardCtrlMsg^(msg);
WITH msg: Controllers.EditMsg DO
IF (msg.op = Controllers.pasteChar) & (msg.char = 1BX) & (31 IN msg.modifiers) & w.obj.uiActive THEN
w.obj.InPlaceDeactivate()
END
ELSE
END
END ForwardCtrlMsg;
PROCEDURE (w: Window) Close;
VAR res: COM.RESULT;
BEGIN
IF w.obj.uiActive THEN
IF debug THEN Log.String("close -> deactivate"); Log.Ln END;
w.obj.InPlaceDeactivate()
ELSE
IF debug THEN Log.String("close window"); Log.Ln END;
w.obj.CheckViewUpdate;
SYSTEM.PUT(SYSTEM.ADR(w.sub), TRUE); (* don't send remove msg *)
w.Close^;
IF (w.obj.ics # NIL) & (w.obj.iips = NIL) THEN res := w.obj.ics.OnShowWindow(0) END;
IF debug THEN Log.String("close window c"); Log.Ln END;
w.obj.win := NIL
END
END Close;
(* ---------- Action ---------- *)
PROCEDURE (a: Action) Do;
VAR res: COM.RESULT; w, h: INTEGER;
BEGIN
IF a.w.frame # NIL THEN
a.w.obj.CheckViewUpdate;
Services.DoLater(a, Services.Ticks() + Services.resolution)
END
END Do;
(* ---------- WinDir ---------- *)
PROCEDURE (d: WinDir) New (): HostWindows.Window;
VAR w: Windows.Window; sw: Window; a: Action;
BEGIN
IF d.obj # NIL THEN
NEW(sw); sw.obj := d.obj;
NEW(a); a.w := sw; Services.DoLater(a, Services.now);
RETURN sw
ELSE
w := Windows.stdDir.New(); RETURN w(HostWindows.Window)
END
END New;
PROCEDURE (d: WinDir) Open (w: Windows.Window; doc: Documents.Document; flags: SET; name: Views.Title;
loc: Files.Locator; fname: Files.Name; conv: Converters.Converter);
VAR l, t, r, b, bw, u, u1, res: INTEGER; style: SET; wnd: WinApi.HWND; c: Containers.Controller; dc: WinApi.HDC;
BEGIN
IF (d.obj # NIL) & (d.obj.iips # NIL) THEN (* open in place *)
WITH w: Window DO
IF debug THEN Log.String("open window in place"); Log.Ln END;
flags := flags + {Windows.noHScroll, Windows.noVScroll, Windows.noResize, HostWindows.inPlace};
u := d.obj.w DIV (d.pos.right - d.pos.left);
u1 := d.obj.h DIV (d.pos.bottom - d.pos.top);
IF u1 > u THEN u := u1 END;
d.unit := u;
d.Open^(w, doc, flags, name, loc, fname, conv);
(*
u := HostWindows.unit;
*)
bw := borderW DIV HostWindows.unit;
l := Max(d.pos.left - bw, d.clip.left);
t := Max(d.pos.top - bw, d.clip.top);
r := Min(d.pos.right + bw, d.clip.right);
b := Min(d.pos.bottom + bw, d.clip.bottom);
style := {30}; (* child *)
wnd := WinApi.CreateWindowEx({}, "Oberon Dlg", "", style, l, t, r - l, b - t,
d.host, 0, WinApi.GetModuleHandle(NIL), SYSTEM.VAL(INTEGER, w));
ASSERT(wnd # 0, 100);
dc := WinApi.GetDC(wnd);
w.port(HostPorts.Port).SetDC(dc, wnd);
w.SetSize(r - l, b - t);
l := Min(bw, d.pos.left - d.clip.left) * u;
t := Min(bw, d.pos.top - d.clip.top) * u;
(*
r := l + (d.pos.right - d.pos.left) * u;
b := t + (d.pos.bottom - d.pos.top) * u;
*)
IF debug THEN Log.Int(d.obj.w); Log.Int(d.obj.h); Log.Ln END;
r := l + d.obj.w;
b := t + d.obj.h;
w.doc.SetRect(l, t, r, b);
res := WinApi.ShowWindow(wnd, 1);
d.obj.unit := u;
IF debug THEN
style := SYSTEM.VAL(SET, WinApi.GetWindowLong(wnd, -16));
Log.Set(style);
Log.Ln
END;
c := w.doc.ThisController();
c.SetFocus(w.doc.ThisView())
END
ELSE
d.Open^(w, doc, flags, name, loc, fname, conv)
END;
d.obj := NIL
END Open;
(* ---------- import / export ---------- *)
PROCEDURE Export* (v: Views.View; w, h, x, y: INTEGER; isSingle: BOOLEAN; VAR med: WinOle.STGMEDIUM);
VAR stg: WinOle.IStorage; stm: WinOle.IStream; res: COM.RESULT; ilb: WinOle.ILockBytes; ps: WinApi.PtrWSTR;
BEGIN
IF debug THEN Log.String("export"); Log.Ln END;
IF med.tymed = WinOle.TYMED_ISTORAGE THEN
stg := MediumStorage(med)
ELSE
res := WinOle.CreateILockBytesOnHGlobal(0, 1, ilb);
ASSERT(res >= 0, 110);
res := WinOle.StgCreateDocfileOnILockBytes(ilb, WinOle.STGM_CREATE
+ WinOle.STGM_READWRITE + WinOle.STGM_SHARE_EXCLUSIVE, 0, stg);
ASSERT(res >= 0, 111);
GenStorageMedium(stg, NIL, med)
END;
res := WinOle.WriteClassStg(stg, ObjectID);
ASSERT(res >= 0, 112);
res := stg.CreateStream(streamStr, WinOle.STGM_CREATE
+ WinOle.STGM_READWRITE + WinOle.STGM_SHARE_EXCLUSIVE, 0, 0, stm);
ASSERT(res >= 0, 113);
res := WinOle.OleRegGetUserType(ObjectID, WinOle.USERCLASSTYPE_SHORT, ps);
res := WinOle.WriteFmtUserTypeStg(stg, cbFormat, ps);
WinOle.CoTaskMemFree(SYSTEM.VAL(WinApi.PtrVoid, ps));
ASSERT(res >= 0, 114);
OleStorage.ExportToStream(stm, v, w, h, isSingle);
res := stg.Commit({});
ASSERT(res >= 0, 115)
END Export;
PROCEDURE Import* (
VAR med: WinOle.STGMEDIUM; VAR v: Views.View; VAR w, h: INTEGER; VAR isSingle: BOOLEAN
);
VAR stg: WinOle.IStorage; res: COM.RESULT; id: COM.GUID; stm, stm2: WinOle.IStream;
BEGIN
IF debug THEN Log.String("import"); Log.Ln END;
stg := MediumStorage(med);
res := WinOle.ReadClassStg(stg, id);
IF (res = WinApi.S_OK) & (id = ObjectID) THEN
res := stg.OpenStream(streamStr, 0,
WinOle.STGM_DIRECT + WinOle.STGM_READWRITE + WinOle.STGM_SHARE_EXCLUSIVE,
0, stm);
ASSERT(res >= 0, 110);
res := WinOle.CreateStreamOnHGlobal(0, 1, stm2);
ASSERT(res >= 0, 111);
res := stm.CopyTo(stm2, MAX(LONGINT), NIL, NIL);
ASSERT(res >= 0, 112);
OleStorage.ImportFromStream(stm2, v, w, h, isSingle);
ELSE
v := NIL
END
END Import;
(* ---------- commands ---------- *)
PROCEDURE ContextOf* (w: Windows.Window): WinOle.IOleInPlaceSite;
BEGIN
WITH w: Window DO
IF w.obj # NIL THEN RETURN w.obj.iips END
ELSE RETURN NIL
END
END ContextOf;
PROCEDURE RemoveUI* (w: Windows.Window);
VAR res: COM.RESULT;
BEGIN
WITH w: Window DO
IF (w.obj # NIL) & (w.obj.iips # NIL) & w.obj.uiActive THEN
IF debug THEN Log.String("remove ui"); Log.Ln END;
IF w.obj.iipf # NIL THEN res := w.obj.iipf.SetActiveObject(NIL, NIL) END;
IF w.obj.iipw # NIL THEN res := w.obj.iipw.SetActiveObject(NIL, NIL) END;
IF (w.obj.iipf # NIL) & (w.obj.menu # 0) THEN
res := w.obj.iipf.SetMenu(0, 0, 0);
w.obj.useMenu := FALSE
END;
(*
HostWindows.ActivateWindow(w, FALSE);
*)
END
ELSE
END
END RemoveUI;
PROCEDURE ResetUI* (w: Windows.Window; VAR done: BOOLEAN);
VAR res: COM.RESULT; rect: WinApi.RECT;
BEGIN
done := FALSE;
WITH w: Window DO
IF (w.obj # NIL) & (w.obj.iips # NIL) & w.obj.uiActive THEN
IF debug THEN Log.String("reset ui"); Log.Ln END;
IF w.obj.iipf # NIL THEN res := w.obj.iipf.SetActiveObject(w.obj.iipao, "") END;
IF w.obj.iipw # NIL THEN res := w.obj.iipw.SetActiveObject(w.obj.iipao, "") END;
IF (w.obj.iipf # NIL) & (w.obj.menu # 0) THEN
res := w.obj.iipf.SetMenu(w.obj.menu, w.obj.oleMenu, HostWindows.main);
w.obj.useMenu := TRUE
END;
rect.left := 0; rect.top := 0; rect.right := 0; rect.bottom := 0;
IF w.obj.iipf # NIL THEN res := w.obj.iipf.SetBorderSpace(rect) END;
IF w.obj.iipw # NIL THEN res := w.obj.iipw.SetBorderSpace(rect) END;
(*
HostWindows.ActivateWindow(w, TRUE);
*)
done := TRUE
END
ELSE
END
END ResetUI;
PROCEDURE ShowOleStatus (w: Windows.Window; s: ARRAY OF CHAR);
VAR res: COM.RESULT;
BEGIN
WITH w: Window DO
IF w.obj.iipf # NIL THEN
res := w.obj.iipf.SetStatusText(s)
END
ELSE
END
END ShowOleStatus;
PROCEDURE UpdateOleMenus ();
VAR w: Windows.Window; res: COM.RESULT;
BEGIN
w := Windows.dir.First();
WHILE w # NIL DO
WITH w: Window DO
IF (w.obj.iipf # NIL) & (w.obj.menu # 0) THEN
w.obj.InPlaceMenuDestroy(); w.obj.InPlaceMenuCreate();
IF w.obj.useMenu THEN
res := w.obj.iipf.SetMenu(w.obj.menu, w.obj.oleMenu, HostWindows.main)
END
END
ELSE
END;
w := Windows.dir.Next(w)
END
END UpdateOleMenus;
PROCEDURE TranslateOleKeys (VAR msg: WinApi.MSG; VAR done: BOOLEAN);
VAR w: Windows.Window; res: COM.RESULT;
BEGIN
w := Windows.dir.First(); done := FALSE;
IF w # NIL THEN
WITH w: Window DO
IF w.obj.iipf # NIL THEN
res := WinOle.OleTranslateAccelerator(w.obj.iipf, w.obj.fInfo, msg);
IF res = WinApi.S_OK THEN done := TRUE END
END
ELSE
END
END
END TranslateOleKeys;
PROCEDURE Register;
VAR res: COM.RESULT;
BEGIN
NEW(factory);
res := WinOle.CoRegisterClassObject(ObjectID, factory,
WinOle.CLSCTX_LOCAL_SERVER, WinOle.REGCLS_MULTIPLEUSE, token);
END Register;
PROCEDURE Unregister;
VAR res: COM.RESULT; n: INTEGER; p: Object;
BEGIN
IF token # 0 THEN
res := WinOle.CoRevokeClassObject(token)
END
END Unregister;
BEGIN
NEW(winDir);
HostDialog.ShowOleStatus := ShowOleStatus;
HostMenus.UpdateOleMenus := UpdateOleMenus;
HostMenus.TranslateOleKeys2 := TranslateOleKeys;
Register
CLOSE
Unregister
END OleServer.
OleServer.xy OleServer.Close
DevDecoder.Decode OleServer
| Ole/Mod/Server.odc |
MODULE OleStorage;
(**
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 Log,
SYSTEM, COM, WinApi, WinOle, Files, Stores, Views;
CONST
debug = FALSE;
obfTag = 6F4F4443H;
TYPE
ILockBytes = POINTER TO RECORD (WinOle.ILockBytes)
org: INTEGER;
len: INTEGER; (* org + len <= file.Length() *)
file: Files.File; (* file # NIL *)
rd: Files.Reader; (* (rd # NIL) & (rd.Base() = file) *)
wr: Files.Writer (* (wr = NIL) OR (wr.Base() = file) *)
END;
StreamFile = POINTER TO RECORD (Files.File)
stream: WinOle.IStream;
org: LONGINT;
len: INTEGER;
pos: INTEGER (* actual seek pos of stream *)
END;
StreamReader = POINTER TO RECORD (Files.Reader)
base: StreamFile;
pos: INTEGER
END;
StreamWriter = POINTER TO RECORD (Files.Writer)
base: StreamFile;
pos: INTEGER;
END;
(* ---------- ILockBytes ---------- *)
PROCEDURE (this: ILockBytes) ReadAt (offset: LONGINT; buf: WinApi.PtrVoid;
len: INTEGER; OUT [nil] read: INTEGER): COM.RESULT;
TYPE P = POINTER TO ARRAY [untagged] 2000000000 OF BYTE;
VAR p: P;
BEGIN
IF debug THEN
Log.String("read@"); Log.Int(SHORT(offset)); Log.Int(len);
END;
IF (len > 0) & (offset < this.len) THEN
this.rd.SetPos(SHORT(this.org + offset));
IF offset + len > this.len THEN len := SHORT(this.len - offset) END;
p := SYSTEM.VAL(P, buf);
this.rd.ReadBytes(p^, 0, len)
ELSE len := 0
END;
IF VALID(read) THEN read := len END;
IF debug THEN
Log.Int(len);
Log.Int(p[0]); Log.Int(p[1]); Log.Int(p[2]); Log.Int(p[3]);
Log.Ln
END;
RETURN WinApi.S_OK
END ReadAt;
PROCEDURE (this: ILockBytes) WriteAt (offset: LONGINT; buf: WinApi.PtrVoid;
len: INTEGER; OUT [nil] written: INTEGER): COM.RESULT;
TYPE P = POINTER TO ARRAY [untagged] 2000000000 OF BYTE;
VAR res: COM.RESULT; p: P;
BEGIN
p := SYSTEM.VAL(P, buf);
IF debug THEN
Log.String("write@"); Log.Int(SHORT(offset)); Log.Int(len);
Log.Int(p[0]); Log.Int(p[1]); Log.Int(p[2]); Log.Int(p[3]);
Log.Ln
END;
IF this.wr # NIL THEN
IF len > 0 THEN
IF offset > this.len THEN res := this.SetSize(offset) END;
this.wr.SetPos(SHORT(this.org + offset));
this.wr.WriteBytes(p^, 0, len);
IF offset + len > this.len THEN this.len := SHORT(offset + len) END
ELSE len := 0
END;
IF VALID(written) THEN written := len END;
IF debug THEN Log.String("written"); Log.Ln END;
RETURN WinApi.S_OK
ELSE
IF VALID(written) THEN written := 0 END;
RETURN WinApi.STG_E_ACCESSDENIED
END
END WriteAt;
PROCEDURE (this: ILockBytes) Flush (): COM.RESULT;
TYPE A4 = ARRAY 4 OF BYTE;
BEGIN
IF debug THEN Log.String("flush"); Log.Ln END;
IF this.wr # NIL THEN
this.wr.SetPos(this.org - 4);
this.wr.WriteBytes(SYSTEM.VAL(A4, this.len), 0, 4);
this.file.Flush();
this.wr.SetPos(this.org + this.len)
ELSE
this.rd.SetPos(this.org + this.len)
END;
IF debug THEN Log.String("flushed"); Log.Ln END;
RETURN WinApi.S_OK
END Flush;
PROCEDURE (this: ILockBytes) SetSize (size: LONGINT): COM.RESULT;
VAR len: INTEGER; buf: ARRAY 256 OF BYTE;
BEGIN
IF debug THEN Log.String("set size"); Log.Int(SHORT(size)); Log.Ln END;
IF this.wr # NIL THEN
IF size > this.len THEN (* enlarge file *)
this.wr.SetPos(this.org + this.len);
len := SHORT(size - this.len);
WHILE len > 256 DO this.wr.WriteBytes(buf, 0, 256); DEC(len, 256) END;
this.wr.WriteBytes(buf, 0, len);
END;
this.len := SHORT(size);
RETURN WinApi.S_OK
ELSE RETURN WinApi.STG_E_ACCESSDENIED
END
END SetSize;
PROCEDURE (this: ILockBytes) LockRegion (offset, len: LONGINT; lockType: SET): COM.RESULT;
BEGIN
RETURN WinApi.STG_E_INVALIDFUNCTION
END LockRegion;
PROCEDURE (this: ILockBytes) UnlockRegion (offset, len: LONGINT; lockType: SET): COM.RESULT;
BEGIN
RETURN WinApi.STG_E_INVALIDFUNCTION
END UnlockRegion;
PROCEDURE (this: ILockBytes) Stat (OUT statStg: WinOle.STATSTG; statflag: INTEGER): COM.RESULT;
BEGIN
IF debug THEN Log.String("stat"); Log.Ln END;
statStg.pwcsName := NIL;
statStg.type := WinOle.STGTY_LOCKBYTES;
statStg.cbSize := this.len;
statStg.mtime := 0;
statStg.ctime := 0;
statStg.atime := 0;
statStg.grfMode := WinOle.STGM_DIRECT + WinOle.STGM_CREATE + WinOle.STGM_SHARE_EXCLUSIVE;
IF this.wr # NIL THEN statStg.grfMode := statStg.grfMode + WinOle.STGM_READWRITE
ELSE statStg.grfMode := statStg.grfMode + WinOle.STGM_READ
END;
statStg.grfLocksSupported := {};
statStg.clsid := WinOle.GUID_NULL;
statStg.grfStateBits := {};
statStg.dwStgFmt := WinOle.STGFMT_FILE;
IF debug THEN Log.String("stat end"); Log.Ln END;
RETURN WinApi.S_OK
END Stat;
(* ---------- StreamReader ---------- *)
PROCEDURE (r: StreamReader) Base (): Files.File;
BEGIN
RETURN r.base
END Base;
PROCEDURE (r: StreamReader) Pos (): INTEGER;
BEGIN
RETURN r.pos
END Pos;
PROCEDURE (r: StreamReader) SetPos (pos: INTEGER);
VAR res: COM.RESULT;
BEGIN
ASSERT(pos >= 0, 22); ASSERT(pos <= r.base.len, 21);
r.pos := pos; r.eof := FALSE
END SetPos;
PROCEDURE (r: StreamReader) ReadByte (OUT x: BYTE);
VAR res: COM.RESULT;
BEGIN
IF r.pos < r.base.len THEN
IF r.pos # r.base.pos THEN
res := r.base.stream.Seek(r.base.org + r.pos, WinOle.STREAM_SEEK_SET, NIL);
r.base.pos := r.pos
END;
res := r.base.stream.Read(SYSTEM.ADR(x), 1, NIL);
INC(r.pos); INC(r.base.pos);
ELSE
x := 0; r.eof := TRUE
END
END ReadByte;
PROCEDURE (r: StreamReader) ReadBytes (VAR x: ARRAY OF BYTE; beg, len: INTEGER);
VAR res: COM.RESULT;
BEGIN
ASSERT(beg >= 0, 21);
IF len > 0 THEN
ASSERT(beg + len <= LEN(x), 23);
IF r.pos + len <= r.base.len THEN
IF r.pos # r.base.pos THEN
res := r.base.stream.Seek(r.base.org + r.pos, WinOle.STREAM_SEEK_SET, NIL);
r.base.pos := r.pos
END;
res := r.base.stream.Read(SYSTEM.ADR(x[beg]), len, NIL);
INC(r.pos, len); INC(r.base.pos, len)
ELSE
r.eof := TRUE
END
ELSE ASSERT(len = 0, 22)
END
END ReadBytes;
(* ---------- StreamWriter ---------- *)
PROCEDURE (w: StreamWriter) Base (): Files.File;
BEGIN
RETURN w.base
END Base;
PROCEDURE (w: StreamWriter) Pos (): INTEGER;
BEGIN
RETURN w.pos
END Pos;
PROCEDURE (w: StreamWriter) SetPos (pos: INTEGER);
VAR res: COM.RESULT;
BEGIN
ASSERT(pos >= 0, 22); ASSERT(pos <= w.base.len, 21);
w.pos := pos
END SetPos;
PROCEDURE (w: StreamWriter) WriteByte (x: BYTE);
VAR res: COM.RESULT;
BEGIN
IF w.pos # w.base.pos THEN
res := w.base.stream.Seek(w.base.org + w.pos, WinOle.STREAM_SEEK_SET, NIL);
w.base.pos := w.pos
END;
res := w.base.stream.Write(SYSTEM.ADR(x), 1, NIL);
INC(w.pos); INC(w.base.pos);
IF w.pos > w.base.len THEN w.base.len := w.pos END
END WriteByte;
PROCEDURE (w: StreamWriter) WriteBytes (IN x: ARRAY OF BYTE; beg, len: INTEGER);
VAR res: COM.RESULT;
BEGIN
ASSERT(beg >= 0, 21);
IF len > 0 THEN
ASSERT(beg + len <= LEN(x), 23);
IF w.pos # w.base.pos THEN
res := w.base.stream.Seek(w.base.org + w.pos, WinOle.STREAM_SEEK_SET, NIL);
w.base.pos := w.pos
END;
res := w.base.stream.Write(SYSTEM.ADR(x[beg]), len, NIL);
INC(w.pos, len); INC(w.base.pos, len);
IF w.pos > w.base.len THEN w.base.len := w.pos END
ELSE ASSERT(len = 0, 22)
END
END WriteBytes;
(* ---------- StreamFile ---------- *)
PROCEDURE (f: StreamFile) Length (): INTEGER;
BEGIN
RETURN f.len
END Length;
PROCEDURE (f: StreamFile) NewReader (old: Files.Reader): Files.Reader;
VAR r: StreamReader;
BEGIN
ASSERT(f.stream # NIL, 20);
NEW(r); r.base := f;
r.pos := 0; r.eof := FALSE;
RETURN r
END NewReader;
PROCEDURE (f: StreamFile) NewWriter (old: Files.Writer): Files.Writer;
VAR w: StreamWriter;
BEGIN
ASSERT(f.stream # NIL, 20);
NEW(w); w.base := f;
w.pos := f.len;
RETURN w
END NewWriter;
PROCEDURE (f: StreamFile) Flush;
VAR res: COM.RESULT;
BEGIN
ASSERT(f.stream # NIL, 20);
res := f.stream.Commit(WinOle.STGC_DEFAULT)
END Flush;
PROCEDURE (f: StreamFile) Close;
BEGIN
IF f.stream # NIL THEN
f.Flush;
f.stream := NIL;
END
END Close;
PROCEDURE (f: StreamFile) Register (name: Files.Name; type: Files.Type; ask: BOOLEAN; OUT res: INTEGER);
BEGIN
res := 10
END Register;
(* ---------- file creation ---------- *)
PROCEDURE NewStreamFile* (stream: WinOle.IStream): Files.File;
VAR f: StreamFile; res: COM.RESULT; y: LONGINT;
BEGIN
NEW(f);
f.stream := stream;
res := stream.Seek(0, WinOle.STREAM_SEEK_CUR, f.org);
res := stream.Seek(0, WinOle.STREAM_SEEK_END, y);
DEC(y, f.org);
IF y > MAX(INTEGER) THEN y := MAX(INTEGER) END;
f.len := SHORT(y);
res := stream.Seek(f.org, WinOle.STREAM_SEEK_SET, NIL);
f.pos := 0;
RETURN f
END NewStreamFile;
PROCEDURE NewWriteILockBytes* (wr: Files.Writer): WinOle.ILockBytes;
VAR new: ILockBytes;
BEGIN
IF debug THEN Log.String("new write"); Log.Ln END;
NEW(new);
IF new = NIL THEN RETURN NIL END;
wr.WriteByte(0); wr.WriteByte(0); wr.WriteByte(0); wr.WriteByte(0); (* length *)
new.len := 0;
new.org := wr.Pos();
new.file := wr.Base();
new.rd := new.file.NewReader(NIL);
new.wr := wr;
RETURN new
END NewWriteILockBytes;
PROCEDURE NewReadILockBytes* (rd: Files.Reader): WinOle.ILockBytes;
TYPE A4 = ARRAY 4 OF BYTE;
VAR new: ILockBytes;
BEGIN
IF debug THEN Log.String("new read"); Log.Ln END;
NEW(new);
IF new = NIL THEN RETURN NIL END;
rd.ReadBytes(SYSTEM.VAL(A4, new.len), 0, 4);
new.org := rd.Pos();
new.file := rd.Base();
new.rd := rd;
new.wr := NIL;
RETURN new
END NewReadILockBytes;
(* stream import/export *)
PROCEDURE GenStreamMedium (stm: WinOle.IStream; unk: COM.IUnknown; VAR sm: WinOle.STGMEDIUM);
BEGIN
sm.tymed := WinOle.TYMED_ISTREAM;
sm.u.pstm := stm;
sm.pUnkForRelease := unk
END GenStreamMedium;
PROCEDURE MediumStream (VAR sm: WinOle.STGMEDIUM): WinOle.IStream;
BEGIN
ASSERT(sm.tymed = WinOle.TYMED_ISTREAM, 20);
RETURN SYSTEM.VAL(WinOle.IStream, sm.u.pstm)
END MediumStream;
PROCEDURE ExportToStream* (stream: WinOle.IStream; v: Views.View; w, h: INTEGER; isSingle: BOOLEAN);
VAR f: Files.File; wr: Stores.Writer; res: COM.RESULT;
BEGIN
res := stream.Seek(0, WinOle.STREAM_SEEK_SET, NIL);
f := NewStreamFile(stream);
wr.ConnectTo(f);
wr.SetPos(0);
wr.WriteInt(obfTag);
wr.WriteInt(0);
wr.WriteInt(w);
wr.WriteInt(h);
IF isSingle THEN wr.WriteSChar(1X) ELSE wr.WriteSChar(0X) END;
wr.WriteStore(v);
f.Close
END ExportToStream;
PROCEDURE ExportOberon* (
v: Views.View; w, h, x, y: INTEGER; isSingle: BOOLEAN; VAR med: WinOle.STGMEDIUM
);
VAR stream: WinOle.IStream; res: COM.RESULT;
BEGIN
IF med.tymed = WinOle.TYMED_ISTREAM THEN (* use old stream *)
stream := MediumStream(med)
ELSE (* create new temporary stream *)
res := WinOle.CreateStreamOnHGlobal(0, 1, stream);
GenStreamMedium(stream, NIL, med)
END;
ExportToStream(stream, v, w, h, isSingle)
END ExportOberon;
PROCEDURE ImportFromStream* (stream: WinOle.IStream; VAR v: Views.View;
VAR w, h: INTEGER; VAR isSingle: BOOLEAN);
VAR f: Files.File; r: Stores.Reader; s: Stores.Store; tag, version, res: COM.RESULT; ch: SHORTCHAR;
BEGIN
v := NIL;
res := stream.Seek(0, WinOle.STREAM_SEEK_SET, NIL);
f := NewStreamFile(stream);
r.ConnectTo(f); r.SetPos(0);
r.ReadInt(tag);
IF tag = obfTag THEN
r.ReadInt(version);
r.ReadInt(w);
r.ReadInt(h);
r.ReadSChar(ch); isSingle := ch # 0X;
r.ReadStore(s);
v := s(Views.View)
END
END ImportFromStream;
PROCEDURE ImportOberon* (VAR med: WinOle.STGMEDIUM; VAR v: Views.View;
VAR w, h: INTEGER; VAR isSingle: BOOLEAN);
VAR stream: WinOle.IStream;
BEGIN
stream := MediumStream(med);
ImportFromStream(stream, v, w, h, isSingle)
END ImportOberon;
END OleStorage.
OleStorage?
DevDecoder.Decode OleStorage
| Ole/Mod/Storage.odc |
MODULE OleViews;
(**
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 COM, WinApi, WinOle, WinOleAut, CtlT, Properties, Views, Containers, Windows, OleServer, OleClient;
(* client wrappers *)
PROCEDURE NewObjectView* (name: ARRAY OF CHAR): Views.View;
VAR clsid: COM.GUID; res: COM.RESULT;
BEGIN
IF name[0] = "{" THEN res := WinOle.CLSIDFromString(name, clsid)
ELSE res := WinOle.CLSIDFromProgID(name, clsid)
END;
IF res = WinApi.S_OK THEN RETURN OleClient.NewView(clsid)
ELSE RETURN NIL
END
END NewObjectView;
(*
PROCEDURE NewObjectViewFrom* (obj: CtlT.Object): Views.View;
VAR disp: WinOleAut.IDispatch;
BEGIN
disp := CtlT.Disp(obj);
RETURN OleClient.NewViewFrom(disp)
END NewObjectViewFrom;
*)
PROCEDURE NewObjectViewFromClipboard* (): Views.View;
BEGIN
RETURN OleClient.NewViewFromCB()
END NewObjectViewFromClipboard;
PROCEDURE IsObjectView* (v: Views.View): BOOLEAN;
VAR unk: COM.IUnknown;
BEGIN
unk := OleClient.IUnknown(v);
RETURN unk # NIL
END IsObjectView;
PROCEDURE IsAutoView* (v: Views.View): BOOLEAN;
VAR unk: COM.IUnknown; disp: WinOleAut.IDispatch; res: COM.RESULT;
BEGIN
unk := OleClient.IUnknown(v);
IF unk # NIL THEN
res := unk.QueryInterface(COM.ID(disp), disp);
RETURN res = WinApi.S_OK
ELSE RETURN FALSE
END
END IsAutoView;
PROCEDURE OleObject* (v: Views.View): CtlT.Interface;
VAR unk: COM.IUnknown;
BEGIN
unk := OleClient.IUnknown(v);
IF unk # NIL THEN RETURN CtlT.Intfce(unk)
ELSE RETURN NIL
END
END OleObject;
PROCEDURE AutoObject* (v: Views.View): CtlT.Object;
VAR unk: COM.IUnknown; disp: WinOleAut.IDispatch; res: COM.RESULT;
BEGIN
unk := OleClient.IUnknown(v);
IF unk # NIL THEN
res := unk.QueryInterface(COM.ID(disp), disp);
IF res = WinApi.S_OK THEN RETURN CtlT.Obj(disp) END
END;
RETURN NIL
END AutoObject;
PROCEDURE Deposit* (name: ARRAY OF CHAR);
VAR v: Views.View;
BEGIN
v := NewObjectView(name);
IF v # NIL THEN Views.Deposit(v) END
END Deposit;
(*
PROCEDURE Activate*;
VAR v, dv: Views.View; msg: Properties.DoVerbMsg; w: Windows.Window; f: Views.Frame;
BEGIN
v := Containers.FocusSingleton();
IF v # NIL THEN
w := Windows.dir.Focus(TRUE);
IF w # NIL THEN
dv := w.doc.ThisView();
f := Views.ThisFrame(w.frame, dv);
msg.frame := Views.ThisFrame(f, v);
msg.verb := WinOle.OLEIVERB_SHOW;
Views.HandlePropMsg(v, msg)
END
END
END Activate;
*)
PROCEDURE Connect* (sink: CtlT.OutObject; source: Views.View);
VAR iid: COM.GUID; disp: WinOleAut.IDispatch;
BEGIN
sink.GetIID(iid); disp := CtlT.Disp(sink);
OleClient.Connect(source, iid, disp)
END Connect;
(*
(* server wrappers *)
PROCEDURE NewViewObject* (v: Views.View): CtlT.Interface;
BEGIN
ASSERT(v.context = NIL, 20);
END NewViewObject;
PROCEDURE IsViewObject* (i: CtlT.Interface): BOOLEAN;
BEGIN
END IsViewObject;
PROCEDURE View* (i: CtlT.Interface): Views.View;
BEGIN
END View;
*)
END OleViews.
| Ole/Mod/Views.odc |
StdApi
DEFINITION StdApi;
IMPORT Views;
PROCEDURE CloseDialog (OUT closedView: Views.View);
PROCEDURE OpenAux (file, title: ARRAY OF CHAR; OUT v: Views.View);
PROCEDURE OpenAuxDialog (file, title: ARRAY OF CHAR; OUT v: Views.View);
PROCEDURE OpenBrowser (file, title: ARRAY OF CHAR; OUT v: Views.View);
PROCEDURE OpenCopyOf (file: ARRAY OF CHAR; OUT v: Views.View);
PROCEDURE OpenDoc (file: ARRAY OF CHAR; OUT v: Views.View);
PROCEDURE OpenToolDialog (file, title: ARRAY OF CHAR; OUT v: Views.View);
END StdApi.
StdApi is programming interface to many of the services provided by StdCmds. Since StdCmds is intended to be used in menus, hyperlinks etc., it is not always suitable as a programming interface. StdApi provides the exact same functionality but with a more "programmable" interface.
PROCEDURE CloseDialog (OUT closedView: Views.View)
This command closes the currently focused window. If the window is a document window and its contents dirty, an error message will be displayed. The root view of the closed window is returned in closedView. If CloseDialog failed NIL is returned.
PROCEDURE OpenAux (file, title: ARRAY OF CHAR; OUT v: Views.View)
Takes a file specification of a BlackBox document and a window title as parameters, and opens an auxiliary window with the specified title. Parameter file must be the path name of a file. The root view of the opened window is returned in v. If OpenAux fails NIL is returned in v.
Auxiliary windows are used for displaying temporary editable data.
PROCEDURE OpenAuxDialog (file, title: ARRAY OF CHAR; OUT v: Views.View)
Takes a file specification of a BlackBox document and a window title as parameters, and opens a dialog with the specified document. The dialog is opened as an auxiliary window. Parameter file must be the path name of a file. The root view of the opened window is returned in v. If OpenAuxDialog fails NIL is returned in v.
Auxiliary dialogs are used for self-contained dialogs, i.e., data entry masks or parameter entry masks for commands.
In contrast to OpenAux, OpenAuxDialog turns the opened document into mask mode if it is a container (-> Containers), and opens it into a dialog window if the underlying platform distinguishes between document and dialog windows (e.g. as in Windows).
PROCEDURE OpenBrowser (file, title: ARRAY OF CHAR; OUT v: Views.View)
Takes a file specification of a BlackBox document and a window title as parameters, and opens the specified document in an auxiliary window. The window contents is not editable, but can be selected. Parameter file must be the path name of a file. The root view of the opened window is returned in v. If OpenBrowser fails NIL is returned in v.
Browser windows are used for displaying documentation. It is possible to select and copy out browser window contents. It is possible to apply find & replace commands, the Info->Interface command, etc.
PROCEDURE OpenCopyOf (file: ARRAY OF CHAR; OUT v: Views.View)
Opens a new document and uses the document specified by file as a template to initialize the new document. If successful the root view of the new document is returned in v otherwise NIL is returned in v.
PROCEDURE OpenDoc (file: ARRAY OF CHAR; OUT v: Views.View)
Takes a file specification of a BlackBox document as parameter, and opens the document in a document window. Parameter file must be the path name of a file. If the same file is already open in an existing document window, this window is brought to the top, instead of opening a new window. The root view of the opened window (or window brought to the top) is returned in v. If OpenDoc fails NIL is returned in v.
Document windows are used for displaying persistent editable data.
PROCEDURE OpenToolDialog (file, title: ARRAY OF CHAR; OUT v: Views.View)
Takes a file specification of an BlackBox document and a window title as parameters, and opens a dialog with the specified document. The dialog is opened as tool window. Parameter file must be the path name of a file. The root view of the opened window is returned in v. If OpenAuxDialog fails NIL is returned in v.
Tool dialogs are used for dialogs which operate on document windows beneath them, e.g., a Find & Replace dialog which operates on a text under it. Otherwise it is identical to OpenAuxDialog.
| Std/Docu/Api.odc |
StdCFrames
This is a private module of BlackBox. Its existence is necessary for BlackBox to work correctly.
| Std/Docu/CFrames.odc |
StdClocks
DEFINITION StdClocks;
IMPORT Views;
PROCEDURE Deposit;
PROCEDURE New (): Views.View;
END StdClocks.
This module implements a simple clock view.
Typical menu command:
"Insert Clock" "" "StdClocks.Deposit; StdCmds.PasteView" "StdCmds.PasteViewGuard"
PROCEDURE New (): Views.View
Factory function for standard clocks.
PROCEDURE Deposit
Deposit command for standard clocks.
| Std/Docu/Clocks.odc |
StdCmds
DEFINITION StdCmds;
IMPORT Dialog, Ports, Fonts;
VAR
allocator: Dialog.String;
layout: RECORD
wType, hType: INTEGER;
width, height: REAL
END;
size: RECORD
size: INTEGER
END;
PROCEDURE Bold;
PROCEDURE BoldGuard (VAR par: Dialog.Par);
PROCEDURE CaretGuard (VAR par: Dialog.Par);
PROCEDURE Clear;
PROCEDURE CloseDialog;
PROCEDURE Color (color: Ports.Color);
PROCEDURE ColorGuard (color: INTEGER; VAR par: Dialog.Par);
PROCEDURE ContainerGuard (VAR par: Dialog.Par);
PROCEDURE CopyProp;
PROCEDURE DefaultFont;
PROCEDURE DefaultFontGuard (VAR par: Dialog.Par);
PROCEDURE DefaultOnDoubleClick (op, from, to: INTEGER);
PROCEDURE DeselectAll;
PROCEDURE Font (typeface: Fonts.Typeface);
PROCEDURE HeightGuard (VAR par: Dialog.Par);
PROCEDURE InitLayoutDialog;
PROCEDURE InitSizeDialog;
PROCEDURE Italic;
PROCEDURE ItalicGuard (VAR par: Dialog.Par);
PROCEDURE ModelViewGuard (VAR par: Dialog.Par);
PROCEDURE New;
PROCEDURE NewWindow;
PROCEDURE Open;
PROCEDURE OpenAsAuxDialog;
PROCEDURE OpenAsToolDialog;
PROCEDURE OpenAux (file, title: ARRAY OF CHAR);
PROCEDURE OpenAuxDialog (file, title: ARRAY OF CHAR);
PROCEDURE OpenBrowser (file, title: ARRAY OF CHAR);
PROCEDURE OpenDoc (file: ARRAY OF CHAR);
PROCEDURE OpenToolDialog (file, title: ARRAY OF CHAR);
PROCEDURE PasteCharGuard (VAR par: Dialog.Par);
PROCEDURE PasteLCharGuard (VAR par: Dialog.Par);
PROCEDURE PasteProp;
PROCEDURE PasteView;
PROCEDURE PasteViewGuard (VAR par: Dialog.Par);
PROCEDURE Plain;
PROCEDURE PlainGuard (VAR par: Dialog.Par);
PROCEDURE ReadOnlyGuard (VAR par: Dialog.Par);
PROCEDURE RecalcAllSizes;
PROCEDURE RecalcFocusSize;
PROCEDURE Redo;
PROCEDURE RedoGuard (VAR par: Dialog.Par);
PROCEDURE RestoreAll;
PROCEDURE SelectAll;
PROCEDURE SelectAllGuard (VAR par: Dialog.Par);
PROCEDURE SelectDocument;
PROCEDURE SelectNextView;
PROCEDURE SelectionGuard (VAR par: Dialog.Par);
PROCEDURE SetBrowserMode;
PROCEDURE SetBrowserModeGuard (VAR par: Dialog.Par);
PROCEDURE SetEditMode;
PROCEDURE SetEditModeGuard (VAR par: Dialog.Par);
PROCEDURE SetLayout;
PROCEDURE SetLayoutMode;
PROCEDURE SetLayoutModeGuard (VAR par: Dialog.Par);
PROCEDURE SetMaskMode;
PROCEDURE SetMaskModeGuard (VAR par: Dialog.Par);
PROCEDURE SetSize;
PROCEDURE ShowProp;
PROCEDURE ShowPropGuard (VAR par: Dialog.Par);
PROCEDURE SingletonGuard (VAR par: Dialog.Par);
PROCEDURE Size (size: INTEGER);
PROCEDURE SizeGuard (size: INTEGER; VAR par: Dialog.Par);
PROCEDURE Strikeout;
PROCEDURE StrikeoutGuard (VAR par: Dialog.Par);
PROCEDURE ToggleNoFocus;
PROCEDURE ToggleNoFocusGuard (VAR par: Dialog.Par);
PROCEDURE TypeNotifier (op, from, to: INTEGER);
PROCEDURE TypefaceGuard (VAR par: Dialog.Par);
PROCEDURE Underline;
PROCEDURE UnderlineGuard (VAR par: Dialog.Par);
PROCEDURE Undo;
PROCEDURE UndoGuard (VAR par: Dialog.Par);
PROCEDURE UpdateAll;
PROCEDURE WidthGuard (VAR par: Dialog.Par);
PROCEDURE WindowGuard (VAR par: Dialog.Par);
END StdCmds.
StdCmds is a command package which contains many commands and guards which are typically used in menu items (->StdMenuTool) or in hyperlinks (->StdLinks).
The module exports more commands which are not described here; these are the commands and guards for menu items of the Windows standard menus. See the Menus text for how these commands are used (only on Windows; under Mac OS, the standard commands do not appear explicitly in the menu specifications).
VAR allocator: Dialog.String
This string contains the command sequence that is executed when the user invokes the Files->New command. By default, it is set to "TextViews.Deposit; StdCmds.Open". This string may be changed in the Config module.
VAR layout: RECORD
Interactor for root view layout (Tools->Document Size...). The size of the outermost view of a document (root view) may be determined in several different ways. Either it is equal to the window size, to the paper size minus the margins defined in the PageSetup dialog, or to a particular fixed size. The vertical and horizontal directions can be defined independently.
wType, hType: INTEGER wType IN {0..2} & hType IN {0..2}
Determines whether the root view size (horizontical/vertical) has a fixed size (0), the size defined by the PageSetup dialog (1), or by the window (2).
width, height: REAL valid iff wType/hType = 1
The root view width/height in centimeters.
VAR size: RECORD
Interactor for setting the font size.
size: INTEGER size >= 6
Font size in points (-> Fonts).
PROCEDURE Bold
PROCEDURE BoldGuard (VAR par: Dialog.Par)
PROCEDURE CaretGuard (VAR par: Dialog.Par)
Disables menu item if there is no current caret, i.e., no selection of length 0.
PROCEDURE Clear
PROCEDURE CloseDialog
This command can be used from within a control to close the window in which the control is embedded. It can only be used as reaction to interactive manipulation of the control, i.e., when the mouse is clicked in the control or when it receives keyboard input. If the window is a document window and its contents dirty, an error message will be displayed.
Pre
must be called in interaction with control 20
PROCEDURE Color (color: Ports.Color)
Set selection to the given color value (-> Ports.Color).
PROCEDURE ColorGuard (color: INTEGER; VAR par: Dialog.Par)
Guard for the Color command.
PROCEDURE CopyProp
Collect properties of current selection, so that they can be used later on for pasting them again.
PROCEDURE ContainerGuard (VAR par: Dialog.Par)
Guard for making sure that the focus is a container view (-> Containers.View).
PROCEDURE DefaultFont
Set selection to the default typeface.
PROCEDURE DefaultFontGuard (VAR par: Dialog.Par)
Guard for the DefaultFont command.
PROCEDURE DefaultOnDoubleClick (op, from, to: INTEGER)
A standard notifier which "clicks" the default button when its control is double-clicked. Typically, this is used in selection boxes or combo boxes.
PROCEDURE DeselectAll
Remove the selection in the focus view.
PROCEDURE Font (typeface: Fonts.Typeface)
PROCEDURE HeightGuard (VAR par: Dialog.Par)
Guard command which sets par.readOnly if layout.hType # 0, i.e., if mode is not "fixed".
PROCEDURE InitLayoutDialog
Initialization command for layout interactor.
PROCEDURE InitSizeDialog
Initialization command for size interactor.
PROCEDURE Italic
Set selection to italicized text.
PROCEDURE ItalicGuard (VAR par: Dialog.Par)
Guard for Italic command.
PROCEDURE ModelViewGuard (VAR par: Dialog.Par)
Guard for NewWindow command (checks that the focus view's ThisModel method does not return NIL).
PROCEDURE New
Open a new untitled document, using the command sequence in variable allocator.
PROCEDURE NewWindow
Guard: ModelViewGuard
Opens another window onto the same document as the front window's.
PROCEDURE Open
Guard: a view was deposited
Takes a deposited view from the global view queue and opens it in a new window.
PROCEDURE OpenAsAuxDialog
Opens another window onto the same document as the front window's; this window works as an auxiliary dialog box.
PROCEDURE OpenAsToolDialog
Opens another window onto the same document as the front window's; this window works as a tool dialog box.
PROCEDURE OpenAux (file, title: ARRAY OF CHAR)
Takes a file specification of an BlackBox document and a window title as parameters, and opens an auxiliary window with the specified title. Parameter file must be the path name of a file.
Auxiliary windows are used for displaying temporary editable data.
Example:
"StdCmds.OpenAux('Form/Rsrc/Menus', 'Form Menus')"
PROCEDURE OpenAuxDialog (file, title: ARRAY OF CHAR)
Takes a file specification of an BlackBox document and a window title as parameters, and opens a dialog with the specified document. The dialog is opened as an auxiliary window. Parameter file must be the path name of a file.
Auxiliary dialogs are used for self-contained dialogs, i.e., data entry masks or parameter entry masks for commands.
In contrast to OpenAux, OpenAuxDialog turns the opened document into mask mode if it is a container (-> Containers), and opens it into a dialog window if the underlying platform distinguishes between document and dialog windows (e.g. as in Windows).
Example:
"StdCmds.OpenAuxDialog('Form/Rsrc/Cmds', 'New Form')"
PROCEDURE OpenBrowser (file, title: ARRAY OF CHAR)
Takes a file specification of an BlackBox document and a window title as parameters, and opens the specified document in an auxiliary window. The window contents is not editable, but can be selected. Parameter file must be the path name of a file.
Browser windows are used for displaying documentation. It is possible to select and copy out browser window contents. It is possible to apply find & replace commands, the Info->Interface command, etc.
Example:
"StdCmds.OpenBrowser('Form/Docu/Models', 'FormModels Docu')"
PROCEDURE OpenDoc (file: ARRAY OF CHAR)
Takes a file specification of an BlackBox document as parameter, and opens the document in a document window. Parameter file must be the path name of a file. If the same file is already open in an existing document window, this window is brought to the top, instead of opening a new window.
Document windows are used for displaying persistent editable data.
Example:
"StdCmds.OpenDoc('System/Rsrc/Menus')"
PROCEDURE OpenToolDialog (file, title: ARRAY OF CHAR)
Takes a file specification of an BlackBox document and a window title as parameters, and opens a dialog with the specified document. The dialog is opened as tool window. Parameter file must be the path name of a file.
Tool dialogs are used for dialogs which operate on document windows beneath them, e.g., a Find & Replace dialog which operates on a text under it. Otherwise it is identical to OpenAuxDialog.
Example:
"DevInspector.InitDialog; StdCmds.OpenToolDialog('Dev/Rsrc/Inspect', 'Inspect')"
PROCEDURE PasteCharGuard (VAR par: Dialog.Par)
Disables menu item if entering a character is currently not possible.
PROCEDURE PasteLCharGuard (VAR par: Dialog.Par)
Obsolete.
PROCEDURE PasteProp
Guard: a property was collected (-> CopyProp)
Takes the previously copied properties and applies them to the current selection.
PROCEDURE PasteView
Guard: a view was deposited
Takes a deposited view from the global view queue and pastes it to the focus.
PROCEDURE PasteViewGuard (VAR par: Dialog.Par)
Disables menu item if pasting a view is currently not possible.
PROCEDURE Plain
Sets the selection to plain text (not italicized, not bold, not underlined).
PROCEDURE PlainGuard
Guard for the Plain command.
PROCEDURE ReadOnlyGuard (VAR par: Dialog.Par)
Makes a control read-only, by setting par.readOnly to TRUE.
PROCEDURE RecalcAllSizes
Recalculates the sizes of all visible views. Must be called after font metrics are changed.
PROCEDURE RecalcFocusSize
Recalculates the size of the focus view.
PROCEDURE Redo
Redo the most recently undone command.
PROCEDURE RedoGuard
Guard for the Redo command.
PROCEDURE RestoreAll
Forces a restoration of all visible views.
PROCEDURE SelectAll
Selects the whole contents of the focus view.
PROCEDURE SelectAllGuard
Guard for the SelectAll command.
PROCEDURE SelectDocument
Selects the root view (the outermost container) of the front window.
PROCEDURE SelectNextView
If a singleton view is selected in a container, this command selects the next view in the container in a round-robin fashion.
PROCEDURE SelectionGuard (VAR par: Dialog.Par)
Disables menu item if there is no current selection.
PROCEDURE SetBrowserMode
Guard: SetBrowserModeGuard
Sets the selected container in browser mode. If no container is selected the outer most container is set in browser mode. This mode is common for texts used for documentation purposes.
PROCEDURE SetBrowserModeGuard (VAR par: Dialog.Par)
Guard for procedure SetBrowserMode. Sets par.checked if appropriate.
PROCEDURE SetEditMode
Guard: SetEditModeGuard
Sets the selected container in edit mode. If no container is selected the outer most container is set in edit mode. This mode is common for editable texts.
PROCEDURE SetEditModeGuard (VAR par: Dialog.Par)
Guard for procedure SetEditMode. Sets par.checked if appropriate.
PROCEDURE SetLayout
Applies the interactor values in layout. To set up layout to the selected view, InitLayoutDialog needs to be called first.
PROCEDURE SetLayoutMode
Guard: SetLayoutModeGuard
Sets the selected container in layout mode. If no container is selected the outer most container is set in layout mode. This mode is common for editable forms.
PROCEDURE SetLayoutModeGuard (VAR par: Dialog.Par)
Guard for procedure SetLayoutMode. Sets par.checked if appropriate.
PROCEDURE SetMaskMode
Guard: SetMaskModeGuard
Sets the selected container in mask mode. If no container is selected the outer most container is set in mask mode. This mode is common for forms used as dialogs.
PROCEDURE SetMaskModeGuard (VAR par: Dialog.Par)
Guard for procedure SetMaskMode. Sets par.checked if appropriate.
PROCEDURE SetSize
Command for setting the selection to the size given in the size interactor.
PROCEDURE ShowProp
Shows the properties of the selection in the focus view.
PROCEDURE ShowPropGuard
Guard for the ShowProp command.
PROCEDURE SingletonGuard (VAR par: Dialog.Par)
Disables menu item if there is no current selection, or if the selection doesn't encompass exactly one embedded view.
PROCEDURE Size (size: INTEGER)
Sets the selection to the given size, in points (-> Fonts).
PROCEDURE SizeGuard (size: INTEGER; VAR par: Dialog.Par)
Guard for the Size command.
PROCEDURE Strikeout
Sets the selection to the strikeout style.
PROCEDURE StrikeoutGuard (VAR par: Dialog.Par)
Guard for the Strikeout command.
PROCEDURE ToggleNoFocus
Makes a focusable container non-focusable, or vice versa, by changing its mode in an appropriate way (-> Containers).
PROCEDURE ToggleNoFocusGuard (VAR par: Dialog.Par)
Guard for the ToggleNoFocus command.
PROCEDURE TypeNotifier (op, from, to: INTEGER)
PROCEDURE TypefaceGuard (VAR par: Dialog.Par)
Guard for the Font command.
PROCEDURE Underline
Sets the selection to the underline style.
PROCEDURE UnderlineGuard (VAR par: Dialog.Par)
Guard for the Underline command.
PROCEDURE Undo
Undoes the most recent command.
PROCEDURE UndoGuard (VAR par: Dialog.Par)
Guard for the Undo command.
PROCEDURE UpdateAll
PROCEDURE WidthGuard (VAR par: Dialog.Par)
Guard command which sets par.readOnly if layout.wType # 0, i.e., if mode is not "fixed".
PROCEDURE WindowGuard (VAR par: Dialog.Par)
| Std/Docu/Cmds.odc |
StdCoder
DEFINITION StdCoder;
IMPORT TextModels, Views, Dialog;
TYPE
ParList = RECORD
list: Dialog.Selection;
storeAs: Dialog.String
END;
VAR par: ParList;
PROCEDURE CloseDialog;
PROCEDURE Decode;
PROCEDURE DecodeAllFromText (text: TextModels.Model; beg: INTEGER; ask: BOOLEAN);
PROCEDURE EncodeDocument;
PROCEDURE EncodeFile;
PROCEDURE EncodeFileList;
PROCEDURE EncodeFocus;
PROCEDURE EncodeSelection;
PROCEDURE EncodedInText (text: TextModels.Model; beg: INTEGER): TextModels.Model;
PROCEDURE EncodedView (v: Views.View): TextModels.Model;
PROCEDURE ListEncodedMaterial;
PROCEDURE Select (op, from, to: INTEGER);
PROCEDURE StoreAll;
PROCEDURE StoreSelection;
PROCEDURE StoreSelectionGuard (VAR p: Dialog.Par);
PROCEDURE StoreSingle;
PROCEDURE StoreSingleGuard (VAR p: Dialog.Par);
END StdCoder.
StdCoder (or Coder for short) can be used to encode a document, a view, a text stretch, or files into a textual form. The encoding uses characters that are expected not to be changed by any mail system. White space characters (blanks, tabs, new lines, etc.) may be added or removed arbitrarily, because they are ignored upon decoding.
Upon decoding a document or a text stretch a new window will be opened. Files will be stored on disk.
Suggested menu items, as they are standard in menu Tools:
"Encode Document" "" "StdCoder.EncodeDocument" "StdCmds.WindowGuard"
"Encode Selection" "" "StdCoder.EncodeSelection" "TextCmds.SelectionGuard"
"Encode File..." "" "StdCoder.EncodeFile" ""
"Encode File List" "" "StdCoder.EncodeFileList" "TextCmds.SelectionGuard"
"Decode..." "" "StdCoder.Decode" "TextCmds.FocusGuard"
"About Encoded Material" "" "StdCoder.ListEncodedMaterial" "TextCmds.FocusGuard"
PROCEDURE EncodeDocument
Guard: StdCmds.WindowGuard
Encodes the document in the current front window and opens a new window with the generated code.
PROCEDURE EncodeSelection
Guard: TextCmds.SelectionGuard
Encodes the current text selection, and opens a new window with the generated code.
PROCEDURE EncodeFile
Encodes one file determined through the standard file opening dialog and opens a new window with the generated code.
PROCEDURE EncodeFileList
Guard: TextCmds.SelectionGuard
Encodes several files and opens a new window with the generated code.
A list of valid file names must be selected. File names must be specified with their complete path name relative to the BlackBox directory. Use the slash character ("/") to separate the individual parts of the path name. (Example: Std/Code/Coder .)
The path name is stored along with the encoding to allow for easy decoding of entire file packages. However, sometimes a file is kept in a different place than where it should be installed later. In such a case, a destination path name can be specified. The path name to be used during decoding can be given after an "arrow" ("=>").
Example: NewStd/Code/NewCoder => Std/Code/Coder will lead to encoding of the file NewCoder in the directory NewStd/Code, but for decoding the name Std/Code/Coder will be used.
PROCEDURE Decode
Guard: TextCmds.FocusGuard
Decodes the information in the encoded text contained by the front window. The command scans for "StdCoder.Decode" as a tag that marks the begin of a code sequence. This allows e-mail headers and other text to precede the actual code. If a text selection is active in the front window, scanning will start at the begin of that selection.
Depending on the kind of encoded data, that is, on the command used for encoding, one of the following actions will be taken:
- if a document was encoded (EncodeDocument, EncodeSelection), it is opened in a new window.
- if a single file was encoded (EncodeFile), the standard file store dialog is opened allowing the user to store the file.
- if a list of files was encoded (EncodeFileList), a special dialog is opened allowing the user to select files for decoding. The path names included during the encoding are shown in a list. One or several files can be selected from that list. After pressing a command button the selected files will be decoded. If only one file is selected, the path name can be changed or the standard file store dialog can be used to browse the directory hierarchy. Via another command button all files can be decoded and stored under the listed names, regardless of the selection.
Note: The dialog should always be closed using the cancel button to allow StdCoder to release resources allocated temporarily to manage the dialog.
PROCEDURE ListEncodedMaterial
Guard: TextCmds.FocusGuard
Opens a text informing about what is encoded in the text displyed by the focus window. Like Decode, the command scans for a tag that marks the beginning of a code sequence.
In the programming interface, two further procedures are available:
PROCEDURE DecodeAllFromText (text: TextModels.Model; beg: INTEGER; ask: BOOLEAN);
Works like Decode, but uses the passed text as source instead of the focus. At text position beg a search for the tag is started and the text following the tag is processed. Like with Decode, encoded documents are opened in windows and single files are stored via the standard store dialog. If the code was generated through EncodeFileList, the behavior depends on the value of the parameter ask. If it equals to TRUE, a dialog is displayed as done by Decode and the user is put into control. If it equals to FALSE, no dialog is displayed, but all files are decoded and installed under the name stored with them. This behavior corresponds to pressing the "Decode All" button in the dialog.
PROCEDURE EncodedView (v: Views.View): TextModels.Model;
Generates a text containing the encoding of the passed view.
PROCEDURE EncodedInText (text: TextModels.Model; beg: INTEGER): TextModels.Model;
Generates a text containing information about what is encoded in "text". | Std/Docu/Coder.odc |
StdDebug
DEFINITION StdDebug;
END StdDebug.
For a distribution version of an BlackBox application or component, use this limited version of the BlackBox debugger. It is not permitted to distribute the full debugger (DevDebug). This limited version doesn't allow to follow pointers and similar interactions, it only creates a passive display of the error state. Since this is a text document that can be saved, it enables the user to send error information to the developer (e.g., via StdCoder).
StdDebug is installed during startup of BlackBox, if the full DevDebug could not be found.
| Std/Docu/Debug.odc |
StdDialog
This is a private module of BlackBox. Its existence is necessary for BlackBox to work correctly.
| Std/Docu/Dialog.odc |
StdETHConv
DEFINITION StdETHConv;
IMPORT Files, Stores, TextModels;
PROCEDURE ImportETHDoc (f: Files.File; OUT s: Stores.Store);
PROCEDURE ImportOberon (f: Files.File): TextModels.Model;
END StdETHConv.
Module StdETHConv provides an importer for ETH Oberon V4 text files.
PROCEDURE ImportETHDoc (f: Files.File; OUT s: Stores.Store)
Importer for Oberon V4 text files. Can be registered by module Config with the statement:
Windows:
Converters.Register("StdETHConv.ImportETHDoc", "", "TextViews.View", ".ETH", {})
Mac OS:
Converters.Register("StdETHConv.ImportETHDoc", "", "TextViews.View", ".Ob.", {})
PROCEDURE ImportOberon (f: Files.File): TextModels.Model
Directly converts an Oberon V4 text file into a BlackBox text, without using the converter mechanism of module Converters.
| Std/Docu/ETHConv.odc |
StdFolds
DEFINITION StdFolds;
IMPORT TextModels, Views, Dialog;
CONST expanded = FALSE; collapsed = TRUE;
TYPE
Label = ARRAY 32 OF CHAR;
Fold = POINTER TO RECORD (Views.View)
leftSide-, collapsed-: BOOLEAN;
label-: Label;
(fold: Fold) Flip, NEW;
(fold: Fold) FlipNested, NEW;
(fold: Fold) HiddenText (): TextModels.Model, NEW;
(fold: Fold) MatchingFold (): Fold, NEW
END;
Directory = POINTER TO ABSTRACT RECORD
(d: Directory) New (collapsed: BOOLEAN; label: Label;
hiddenText: TextModels.Model): Fold, NEW, ABSTRACT
END;
VAR
foldData: RECORD
nested, all: BOOLEAN;
findLabel, newLabel: Label
END;
dir-, stdDir-: Directory;
PROCEDURE CollapseFolds (text: TextModels.Model; nested: BOOLEAN; IN label: ARRAY OF CHAR);
PROCEDURE ExpandFolds (text: TextModels.Model; nested: BOOLEAN; IN label: ARRAY OF CHAR);
PROCEDURE Collapse;
PROCEDURE Expand;
PROCEDURE ZoomOut;
PROCEDURE ZoomIn;
PROCEDURE Overlaps (text: TextModels.Model; beg, end: INTEGER): BOOLEAN;
PROCEDURE Insert (text: TextModels.Model; label: Label; beg, end: INTEGER; collapsed: BOOLEAN);
PROCEDURE CreateGuard (VAR par: Dialog.Par);
PROCEDURE Create (state: INTEGER);
PROCEDURE SetDir (d: Directory);
PROCEDURE FindFirstFold;
PROCEDURE FindNextFold;
PROCEDURE CollapseLabel;
PROCEDURE ExpandLabel;
PROCEDURE SetLabel;
PROCEDURE SetLabelGuard (VAR p: Dialog.Par);
PROCEDURE FindLabelGuard (VAR par: Dialog.Par);
END StdFolds.
Fold views, also called folds, are views that always appear in pairs. They are only meaningful when embedded in texts. A pair, called the left and right fold, brackets a stretch of text and represent a second piece of text that is hidden. By clicking at a fold with the mouse, the stretch of text between the left and right fold is replaced with the hidden text, and the text that originally appeared between the folds becomes the hidden text. Clicking a second time at the same fold restores the original state. Because the primary use of folds is to hide longer stretches of text and replace them with a usually much shorter placeholder, a fold is said to be either in expanded or collapsed state. Try it!
This is a piece of text enclosed by folds in expanded modetext between collapsed folds
Folds can be nested, but the stretch between one pair of folds must not partially overlap another. Hierarchically nested folds are often used in program texts. By hiding a sequence of statements and writing a short comment between the collapsed folds, the resulting program text can be explored interactively in a top-down manner. Try it with this example!
PROCEDURE Enter (id: INTEGER; name: TextMappers.String; value: REAL);
VAR n, h, p: Node;
BEGIN
NEW(n); n.id := id; n.name := name; n.value := value;create new node n
h := list; p := NIL;
WHILE (h # NIL) & (h.id <= id) DO p := h; h := h.next END;search position in list
IF p # NIL THEN
p.next := ninsert between p and h
ELSE
list := ninsert at beginning
END;
n.next := hinsert in list
END Enter;enter a new value into the list
Instead of clicking manually through a deep hierarchy of folds, you can hold down the modifier key while clicking at the fold. This expands or collapses a fold and all nested folds.
The following menu entries operate on folds. Create Fold in menu Tools inserts a new pair of folds in the focus text. The current text selection in the focus text will be bracketed by the newly inserted folds. Expand All in menu Tools expands all folds in the focus text. Similarly, Collapse All collapses all folds in the focus text.
Fold... in menu Tools opens a property inspector that lets you manipulate the folds in the focus text. The inspector looks like this:
Find First searches in the focus text for the first occurence of a fold. If All is checked then the the very first fold in the text is selected. If All is not checked then Find First searches for a fold which has a label equal to the search criteria specified in the Find field. Find Next finds the next fold using the same criteria as Find First.
Collapse collapses all folds in the focus text which comply to the search critera specified by All and Find. If Nested is checked the folds are searched for contained folds and these are also collapsed.
Expand expands folds using All, Find and Nested in the same way as Collapse.
When a fold is found or when a fold in the focus text is selected by the user its label is displayd in the field next to the Set Label button. The label can be changed by typing a new label into the field and clicking on Set Label.
To describe the pre- and postconditions of procedures exported from StdFolds, we use the following pseudo-procedures.
Pos(f) designates the position of the fold view f in its hosting text.
0 <= Pos(f) < text.Length().
Stretch(p1, p2) stands for the text stretch [p1, p2) if p1 < p2 holds, or if p2 <= p1, then it denotes the text stretch [p2, p1).
Flipped(f) denotes the fold f in its dual, "flipped" state.
f.state = collapsed <=> Flipped(f).state = expanded.
Typical menu commands (typically in the Tools menu, some commands may be omitted in the standard distribution):
MENU
"Create Fold" "" "StdFolds.Create(1)" "StdFolds.CreateGuard"
"Expand All" "" "StdFolds.Expand" ""
"Collapse All" "" "StdFolds.Collapse" ""
"Fold..." "" "StdCmds.OpenToolDialog('Std/Rsrc/Folds', 'Zoom')" ""
END
CONST collapsed, expanded
Possible values of field Fold.collapsed.
TYPE Label
String type for label property values.
TYPE Fold (Views.View)
View type of a fold.
leftSide-: BOOLEAN
Determines whether the view is the left or right element of a pair.
collapsed-: BOOLEAN
Determines whether the fold view currently is in expanded or collapsed state.
label-: Label
A string indicating the label property of the fold. If the fold has no label associated with it, label = "" holds.
PROCEDURE (fold: Fold) Flip
NEW
Changes the state of fold. The text stretch S between fold and fold.MatchingFold() is replaced by the text fold.HiddenText(). The stretch S will be the new hidden text.
Pre
fold # NIL 20
Post
(fold.MatchingFold() # NIL) & fold.collapsed'
~fold.collapsed
(fold.MatchingFold() # NIL) & ~fold.collapsed'
fold.collapsed
fold.MatchingFold() = NIL
no effect
PROCEDURE (fold: Fold) FlipNested
NEW
Changes the state of fold, and all fold views f between fold and fold.MatchingFold() for which f.state = fold.state.
Pre
fold # NIL 20
Post
(fold.MatchingFold() # NIL) & fold.collapsed'
~fold.collapsed
For all folds f between fold and fold.MatchingFold(): ~f.collapsed
(fold.MatchingFold() # NIL) & ~fold.collapsed'
fold.collapsed
For all folds f between fold and fold.MatchingFold(): f.collapsed
fold.MatchingFold() = NIL
no effect
PROCEDURE (fold: Fold) HiddenText (): TextModels.Model
NEW
Returns the text stretch that is currently hidden by the pair (fold, fold.MatchingFold()). The text should not be modified. If the hidden text stretch is of length zero, NIL is returned.
Pre
fold # NIL 20
Post
fold.MatchingFold() # NIL
[ let p1 := Pos(Flipped(fold)), p2 := Pos(Flipped(fold).MatchingFold() ]
ABS(p2 - p1) = 1 => result = NIL
ABS(p2 - p1) > 1 => result is Stretch(p1, p2)
fold.MatchingFold() = NIL
result = NIL
PROCEDURE (fold: Fold) MatchingFold (): Fold
NEW
Returns the matching fold view to fold, or NIL if none can be found.
Pre
fold # NIL 20
Post
~(fold.context IS TextModels.Context)
result = NIL
fold.context IS TextModels.Context
(fold.kind = left) & (result.kind = right) & Pos(fold) < Pos(result)
& (For all folds f with Pos(fold) < Pos(f) < Pos(result):
(f.MatchingFold() # NIL) & (Pos(fold) < Pos(f.MatchingFold() < Pos(result))
OR (fold.kind = right) & (result.kind = left) & (Pos(fold) > Pos(result)
& (For all folds f with Pos(result) < Pos(f) < Pos(fold):
(f.Matching # NIL) & (Pos(result) < Pos(f.MatchingFold() < Pos(fold))
OR result = NIL
TYPE Directory
ABSTRACT
Directory for fold views.
PROCEDURE (d: Directory) New (collapsed: BOOLEAN; IN label: Label;
hiddenText: TextModels.Model): Fold
NEW, ABSTRACT
Create a new fold view in state collapsed, with label, and with the text hiddenText. If hiddenText is NIL, it is a right fold, otherwise it is a left fold.
Post
result.leftSide = (hiddenText # NIL)
result.collapsed = collapsed
result.label = label
result.HiddenText() = hiddenText
PROCEDURE CollapseFolds (text: TextModels.Model; nested: BOOLEAN;
IN label: ARRAY OF CHAR)
If nested holds and label = "", all folds f in text with ~f.collapsed are flipped. If ~nested, only the outermost folds in the nesting hierarchy are flipped. If label # "", only folds with f.label = label are flipped.
Pre
text # NIL 20
PROCEDURE ExpandFolds (text: TextModels.Model; nested: BOOLEAN;
IN label: ARRAY OF CHAR)
If nested holds and label = "", all folds f in text with f.collapsed are flipped. If ~nested, only the outermost folds in the nesting hierarchy are flipped. If label # "", only folds with f.label = label are flipped.
Pre
20 text # NIL
PROCEDURE Collapse
Guard: TextCmds.FocusGuard
Collapse all fold views in the focus text.
PROCEDURE Expand
Guard: TextCmds.FocusGuard
Expand all fold views in the focus text.
PROCEDURE ZoomOut
Guard: TextCmds.FocusGuard
Collapse all outermost expanded fold views in the focus text.
PROCEDURE ZoomIn
Guard: TextCmds.FocusGuard
Expand all outermost collapsed views in the focus text.
PROCEDURE Overlaps (text: TextModels.Model; beg, end: INTEGER): BOOLEAN
Returns TRUE if the text stretch [beg, end) in text partially overlaps a pair (f, f.MatchingFold()) of fold views.
Pre
text # NIL 20
(beg >= 0) & (end <= text.Length()) & (beg <= end) 21
PROCEDURE Insert (text: TextModels.Model; IN label: Label; beg, end: INTEGER; collapsed: BOOLEAN)
Inserts a new pair (f1, f2) of fold views into text. The new pair will bracket the text stretch [beg, end). Flag collapsed determines whether the fold is inserted in collapsed or in expanded state.
Pre
text # NIL 20
(beg >= 0) & (end <= text.Length()) & (beg <= end) 21
Post
the text stretch [beg, end) does not partially overlap a pair of folds
Pos(f1) = beg
Pos(f2) = end+1
f1.MatchingFold() = f2
f1.collapsed = f2.collapsed
f1.HiddenText() = NIL
the text stretch [beg, end) partially overlaps a pair of folds
nothing is done
PROCEDURE CreateGuard (VAR par: Dialog.Par)
Sets par.disabled to TRUE when the text selection in the current focus text partially overlaps a pair (f, Matching(f)) of fold views. par.disabled is also set to TRUE if the focus text is shown in browser mode or mask mode, that is if the text cannot be modified.
PROCEDURE Create (state: INTEGER)
If CreateGuard holds, creates a a new pair of fold views and inserts them into the focus text, bracketing the current text selection or the caret position. Calls Insert(FocusText, selBeg, selEnd, state).
state = 0 generates a collapsed fold, state = 1 generates an expanded fold.
Pre
state IN {0, 1)
Post
state = 0
result.collapsed
state = 1
~result.collapsed
PROCEDURE SetDir (d: Directory)
Set directory.
The following variables and procedures are only used for the property inspector of the StdFolds.View:
VAR
foldData: RECORD
nested, all: BOOLEAN;
findLabel, newLabel: Label
END;
PROCEDURE FindFirstFold;
PROCEDURE FindNextFold;
PROCEDURE CollapseLabel;
PROCEDURE ExpandLabel;
PROCEDURE SetLabel;
PROCEDURE SetLabelGuard (VAR p: Dialog.Par);
PROCEDURE FindLabelGuard (VAR par: Dialog.Par);
| Std/Docu/Folds.odc |
StdHeaders
DEFINITION StdHeaders;
IMPORT Dialog, Views, Fonts, Properties;
CONST alternate = 0; number = 1; head = 2; foot = 3; showFoot = 4;
TYPE
Prop = POINTER TO RECORD (Properties.Property)
alternate: BOOLEAN;
showFoot: BOOLEAN;
number: NumberInfo;
head, foot: Banner
END;
Banner = RECORD
left, right: ARRAY 128 OF CHAR;
gap: INTEGER
END;
NumberInfo = RECORD
new: BOOLEAN;
first: INTEGER
END;
VAR
dialog: RECORD
alternate, showFoot: BOOLEAN;
number: NumberInfo;
head, foot: Banner
END;
PROCEDURE New (p: Prop; f: Fonts.Font): Views.View;
PROCEDURE Deposit;
PROCEDURE InitDialog;
PROCEDURE NewNumberGuard (VAR par: Dialog.Par);
PROCEDURE AlternateGuard (VAR par: Dialog.Par);
PROCEDURE HeaderGuard (VAR par: Dialog.Par);
PROCEDURE Set;
END StdHeaders.
This module implements views that can be embedded in BlackBox texts, to provide page headers and/or footers upon printing.
Typical menu command:
"Insert Header" "" "StdHeaders.Deposit; StdCmds.PasteView" "TextCmds.FocusGuard"
A header in a text is invisible, except if Text -> Show Marks has been executed. Selecting a header view and then executing Edit -> Show Properties... (or double-clicking on the view) opens a property sheet that allows to set the following properties:
- "alternate": if checked, this option causes left and right pages to be distinguished, so that they can have different headers and footers.
- "Show Foot": if checked, this option makes the header view display the footer, otherwise it displays the header (when it is visible at all).
- "Start with new page number": if checked, the user can enter the page number for the page in which the view is embedded. It allows to change page numbering within a single document.
- "Right Head", "Right Foot", "Left Head", "Left Foot": these are the properties of the right / left headers / footers. They are (one-line) strings. Optionally, these strings may contain macros, as described below.
- "Head gap", "Foot gap": determines the distance between header/footer and the text area, in points.
- "Font...": allows to set the font that is used for the headers and footers.
The following macros can be used in the header/footer strings:
&p - replaced by current page number as arabic numeral
&r - replaced by current page number as roman numeral
&R - replaced by current page number as capital roman numeral
&a - replaced by current page number as alphanumeric character
&A - replaced by current page number as capital alphanumeric character
&d - replaced by printing date
&t - replaced by printing time
&& - replaced by & character
&; - specifies split point
&f - filename with path/title
These macros are evaluated upon printing (or upon display, when the header view is visible). The macro "&;" indicates a split point, which is a position in the string where the string can be broken apart to allow for a better layout. For example, the string "Left margin&;Right margin" allows the string part "Left margin" to be positioned at the left side of the page, and the string "Right margin" at the right side of the page. The split point becomes a kind of "elastic spring" that pushes the left and right string parts apart.
CONST alternate, number, head, foot, showFoot
Property numbers for the properties that are supported by header views.
TYPE Prop (Properties.Property)
Property descriptor for header views.
alternate: BOOLEAN
Determines whether left and right pages have their own headers/footers.
showFoot: BOOLEAN
Determines whether a visible header view shows the header or the footer.
number: NumberInfo
Determines the way in which page numbers are shown.
head, foot: Banner
Determines the way in which headers and footers are shown.
TYPE Banner
Determines the header or footer of a page (or pair of pages if "alternate" is chosen).
left, right: ARRAY 128 OF CHAR
Strings for the left and right header/footer. Supports macros as described at the beginning of this text.
gap: INTEGER gap >= 0
Distance between header/footer and the body of the text.
TYPE NumberInfo
Determines the way pages are numbered.
new: BOOLEAN
Determines whether page numbering starts anew, using the page number first.
first: INTEGER first >= 0
The starting page number that is used for the page in which the header view is embedded.
VAR dialog
Interactor for the property sheet.
alternate: BOOLEAN
Determines whether left and right pages have their own headers/footers.
showFoot: BOOLEAN
Determines whether a visible header view shows the header or the footer.
number: NumberInfo
Determines the way in which page numbers are shown.
head, foot: Banner
Determines the way in which headers and footers are shown.
PROCEDURE New (p: Prop; f: Fonts.Font): Views.View
Create a new header view with the given properties.
PROCEDURE Deposit
Deposit command for header views.
The following procedures are used for the property sheet (Std/Rsrc/Headers).
PROCEDURE InitDialog
PROCEDURE NewNumberGuard (VAR par: Dialog.Par)
PROCEDURE AlternateGuard (VAR par: Dialog.Par)
PROCEDURE HeaderGuard (VAR par: Dialog.Par)
PROCEDURE Set
| Std/Docu/Headers.odc |
StdInterpreter
DEFINITION StdInterpreter;
END StdInterpreter.
Module StdInterpreter implements a plug-in service for BlackBox: an interpreter for some forms of Component Pascal procedure calls. A sequence of statements of the following forms are legal:
Proc = PROCEDURE
ProcI = PROCEDURE (x: INTEGER)
ProcII = PROCEDURE (x, y: INTEGER)
ProcS = PROCEDURE (s: ARRAY OF CHAR)
ProcSI = PROCEDURE (s: ARRAY OF CHAR; x: INTEGER)
ProcSII = PROCEDURE (s: ARRAY OF CHAR; x, y: INTEGER)
ProcSS = PROCEDURE (s, t: ARRAY OF CHAR)
ProcSSI = PROCEDURE (s, t: ARRAY OF CHAR; x: INTEGER)
ProcSSII = PROCEDURE (s, t: ARRAY OF CHAR; x, y: INTEGER)
ProcR = PROCEDURE (IN s: ARRAY OF CHAR);
ProcRI = PROCEDURE (IN s: ARRAY OF CHAR; x: INTEGER);
ProcRII = PROCEDURE (IN s: ARRAY OF CHAR; x, y: INTEGER);
ProcRS = PROCEDURE (IN s: ARRAY OF CHAR; t: ARRAY OF CHAR);
ProcRSI = PROCEDURE (IN s: ARRAY OF CHAR; t: ARRAY OF CHAR; x: INTEGER);
ProcRSII = PROCEDURE (IN s: ARRAY OF CHAR; t: ARRAY OF CHAR; x, y: INTEGER);
ProcSR = PROCEDURE (s: ARRAY OF CHAR; IN t: ARRAY OF CHAR);
ProcSRI = PROCEDURE (s: ARRAY OF CHAR; IN t: ARRAY OF CHAR; x: INTEGER);
ProcSRII = PROCEDURE (s: ARRAY OF CHAR; IN t: ARRAY OF CHAR; x, y: INTEGER);
ProcRR = PROCEDURE (IN s, t: ARRAY OF CHAR);
ProcRRI = PROCEDURE (IN s, t: ARRAY OF CHAR; x: INTEGER);
ProcRRII = PROCEDURE (IN s, t: ARRAY OF CHAR; x, y: INTEGER);
For example, a procedure call of type ProcII followed by a procedure call of type Proc could be the following string:
"TurtleDraw.GotoPos(35, 587); TurtleDraw.ShowPen".
Such statement sequences are used mainly in menu command configurations and in control properties.
Module StdInterpreter is installed during startup of BlackBox. Its service is made available through the procedure Dialog.Call.
| Std/Docu/Interpreter.odc |
StdLinks
DEFINITION StdLinks;
IMPORT Dialog, Views;
TYPE
Link = POINTER TO RECORD (Views.View)
leftSide-: BOOLEAN;
(v: Link) GetCmd (OUT cmd: ARRAY OF CHAR), NEW
END;
Target = POINTER TO RECORD (Views.View)
leftSide-: BOOLEAN;
(t: Target) GetIdent (OUT ident: ARRAY OF CHAR), NEW
END;
Directory = POINTER TO ABSTRACT RECORD
(d: Directory) NewLink (IN cmd: ARRAY OF CHAR): Link, NEW, ABSTRACT;
(d: Directory) NewTarget (IN ident: ARRAY OF CHAR): Target, NEW, ABSTRACT
END;
VAR
par-: Link;
dir-, stdDir-: Directory;
PROCEDURE CreateGuard (VAR par: Dialog.Par);
PROCEDURE CreateLink;
PROCEDURE CreateTarget;
PROCEDURE ShowTarget (ident: ARRAY OF CHAR);
PROCEDURE SetDir (d: Directory);
END StdLinks.
Link views, also called links, are views that always appear in pairs. They are only meaningful when embedded in texts. A pair brackets a stretch of text and contains a command. This an example of a link:
Alinktotheusermanual
If you do not see anything special to the left and right of the above text stretch, use Text>ShowMarks to make the views visible.
If you click on either the left or right link view, the command associated with the link is executed. Moreover, the entire text stretch between the link pair is active also. The mouse cursor changes its shape when it points to the active stretch.
If you hold down the modifier key when clicking on one of the link stretch, the two views are transformed into a textual form:
<StdCmds.OpenBrowser('System/Docu/User-Man', 'User Manual')>Alinktotheusermanual<>
The syntax is "<" command sequence ">" text stretch "<" ">". The command sequence usually consists of a StdCmds.OpenBrowser command. However, any command may be used, e.g., like in the following specification:
<Dialog.Beep; Dialog.Beep>beepbeep<>
To turn this specification into an active text stretch, select it (from and including the first "<", to and including the last ">") and then execute Tools>CreateLink.
You may have noticed that the name "link" thus just denotes the most typical use of link views. They are not inherently specialized for text linking. The behavior is completely determined by the command sequence associated with them.
In order to use link views for hypertext linking, it must be possible to use link commands which open a particular piece of text. The standard command for this purpose is StdCmds.OpenBrowser. For example, the command "StdCmds.OpenBrowser('Obx/Docu/Sys-Map', 'Map to the Obx Subsystem')" opens the Obx map text in browser mode.
Sometimes it is useful to have a command which, as a reaction to activating it via a link view, scrolls the text in which the link view is embedded, to a certain target position. This target position can be marked with a pair of target views, which are created in a similar way as link views. The command to scroll to a certain target view is ShowTarget. To determine which target to show, a target contains an arbitrary identifier name.
For example, the link view with the specification
<StdLinks.ShowTarget('first target')>showtarget<>
creates a link to a target given by the specification
<first target>this is the first target<>
MENU
"Create Link" "" "StdLinks.CreateLink" "StdLinks.CreateGuard"
"Create Target" "" "StdLinks.CreateTarget" "StdLinks.CreateGuard"
END
TYPE Link (Views.View)
View type for links.
leftSide-: BOOLEAN
Tells whether it is a left or a right view.
PROCEDURE (v: Link) GetCmd (OUT cmd: ARRAY OF CHAR)
NEW
Returns the link's command.
Post
leftSide = (cmd # "")
TYPE Target (Views.View)
View type for targets.
leftSide-: BOOLEAN
Tells whether it is a left or a right view.
PROCEDURE (t: Target) GetIdent (OUT ident: ARRAY OF CHAR)
NEW
Returns the target's identifier.
Post
leftSide = (ident # "")
TYPE Directory
ABSTRACT
Directory type for link/target views.
PROCEDURE (d: Directory) NewLink (IN cmd: ARRAY OF CHAR): Link
NEW, ABSTRACT
Returns a new link view with cmd as command string. It is a left view if cmd # "", otherwise a right view.
PROCEDURE (d: Directory) NewTarget (IN ident: ARRAY OF CHAR): Target
NEW, ABSTRACT
Returns a new target view with ident as identifier string. It is a left view if ident # "", otherwise a right view.
VAR par-: Link par # NIL exactly during the currently executed link command
A command in a link can get access to its (left) link view, and thus to its context, via this variable during the execution of the command.
VAR dir-, stdDir-: Directory
Link/target directories.
PROCEDURE CreateGuard (VAR par: Dialog.Par)
Menu guard procedure used for CreateLink and CreateTarget. par.disabled remains FALSE (i.e., the menu entry is not disabled) if the following holds. The focus view is a text view and the current text selection exactly covers a stretch of text with the syntax: "<" text ">" text "<>".
PROCEDURE CreateLink
Insert a link into the focus text. To create a link, a piece of text with the following syntax must be selected: "<" command sequence ">" arbitrary text "<>". The command sequence must not contain a ">" character. The stretch "<" command sequence ">" is replaced with the left link view. The stretch "<>" is replaced with the right link view. The link views can be hidden/shown with Text>ShowMarks and Text>HideMarks, resp. To edit the command sequence of a link, click on one of the link views with the modifier key pressed. This replaces the views with the original text.
PROCEDURE CreateTarget
Insert a target into the focus text. To create a target, a piece of text with the following syntax must be selected: "<" target identifier ">" arbitrary text "<>". The target identifier must not contain a ">" character. The stretch "<" target identifier ">" will be replaced with the left target view. The stretch "<>" will be replaced with the right target view. Target views can be hidden/shown with Text>ShowMarks and Text>HideMarks, resp. To edit the target identifier of an existing target, click on one of the views with the modifier key pressed. This replaces the views with the original text.
PROCEDURE ShowTarget (ident: ARRAY OF CHAR)
Searches the first target view in the focus text whose target identifier equals ident. If one is found, the text is scrolled such that the target view is shown on the first line, and the text stretch between the left and right target views is selected. (Note: if the text is opened in mask mode, the selection is not visible.)
PROCEDURE SetDir (d: Directory)
Sets the link/target view directory.
| Std/Docu/Links.odc |
StdLoader
This module has a private interface, it is only used internally.
| Std/Docu/Loader.odc |
StdLog
DEFINITION StdLog;
IMPORT TextViews, Views, TextRulers, TextModels;
CONST
charCode = -1; decimal = 10; hexadecimal = -2;
hideBase = FALSE; showBase = TRUE;
VAR
buf-: TextModels.Model;
defruler-: TextRulers.Ruler;
dir-: TextViews.Directory;
text-: TextModels.Model;
PROCEDURE Bool (x: BOOLEAN);
PROCEDURE Char (ch: CHAR);
PROCEDURE Int (i: INTEGER);
PROCEDURE IntForm (x: LONGINT; base, minWidth: INTEGER; fillCh: CHAR; showBase: BOOLEAN);
PROCEDURE Real (x: REAL);
PROCEDURE RealForm (x: REAL; precision, minW, expW: INTEGER; fillCh: CHAR);
PROCEDURE Set (x: SET);
PROCEDURE String (IN str: ARRAY OF CHAR);
PROCEDURE ParamMsg (IN msg, p0, p1, p2: ARRAY OF CHAR);
PROCEDURE Msg (IN msg: ARRAY OF CHAR);
PROCEDURE Tab;
PROCEDURE Para;
PROCEDURE Ln;
PROCEDURE View (v: Views.View);
PROCEDURE ViewForm (v: Views.View; w, h: INTEGER);
PROCEDURE New;
PROCEDURE Open;
PROCEDURE Clear;
PROCEDURE NewView (): TextViews.View;
PROCEDURE SetDefaultRuler (ruler: TextRulers.Ruler);
PROCEDURE SetDir (d: TextViews.Directory);
END StdLog.
Module StdLog provides a log text and procedures that simplify writing into the log text. Typically, log windows are only used during development, not for end user environments. The log window is opened by the following statement in procedure Config.Setup:
Dialog.Call("StdLog.Open", "", res)
CONST charCode
Possible value for parameter base of IntForm, asking for formatting integers following the syntax of Component Pascal numerical character literals. (For example, 0DX is the code for line, and 37X the code for "7".)
CONST decimal
Possible value for parameter base of IntForm, asking for formatting integers as decimal literals.
CONST hexadecimal
Possible value for parameter base of IntForm, asking for formatting integers as hexadecimal literals.
CONST hideBase
Possible value for parameter showBase of IntForm, asking for suppression of the base indicator.
CONST showBase
Possible value for parameter showBase of IntForm, asking for output of the base indicator.
PROCEDURE Bool (x: BOOLEAN)
Writes a Boolean value to the log.
Except for performance, equivalent to:
IF x THEN String("$TRUE") ELSE String("$FALSE") END
PROCEDURE Char (ch: CHAR)
Writes a character value to the log. For control characters the numerical literal form enclosed in spaces is written (e.g., " 9X " for a tab code).
Note that it is much more efficient to use String if more than one character needs to be written.
PROCEDURE Int (i: INTEGER)
Writes an integer value to the log.
Except for performance, equivalent to:
IntForm(x, decimal, 0, digitspace, showBase)
where digitspace = 8FX.
PROCEDURE IntForm (x: LONGINT; base, minWidth: INTEGER; fillCh: CHAR; showBase: BOOLEAN)
Write integer x. The numeral string used to represent the number is relative to base base. The total representation form will at least have a width of minWidth characters, where padding (if required) takes place to the left using characters as specified by fillCh. If nonђdecimal, the base can be requested to form part of the representation using showBase. The special value base = charCode renders the base suffix "X", while base = hexadecimal renders the suffix "H". All other nonђdecimal bases are represented by a trailing "%" followed by the decimal numerical literal representing the base value itself. Nonђdecimal representations of negative integers are formed using a baseђcomplement form of width minWidth. E.g., x = -3 renders for base = 16 and minWidth = 2 as "FD".
Pre
(base = charCode) OR (base = hexadecimal) OR ((base >= 2) & (base <= 16)) 20
minWidth >= 0 22
PROCEDURE Real (x: REAL)
Writes a real value to the log.
Except for performance, equivalent to:
WriteRealForm(x, 16, 0, 0, digitspace)
where digitspace = 8FX.
PROCEDURE RealForm (x: REAL; precision, minW, expW: INTEGER; fillCh: CHAR)
Write real x. The numeral string used to represent the number is either in fixed point or in scientific format, according to expW. precision denotes the number of valid decimal places (usually 7 for short reals and 16 for reals). minW denotes the minimal length in characters. If necessary, preceding fillCh will be inserted. Numbers are always rounded to the last valid and visible digit.
expW > 0: exponential format (scientific) with at least expW digits in the exponent.
expW = 0: fixpoint or floatingpoint format, depending on x.
expW < 0: fixpoint format with -expW digits after the decimal point.
For more details, see also the description of Strings.RealToStringForm.
Pre
precision > 0 20
0 <= minW 21
expW <= 3 22
PROCEDURE Set (x: SET)
Writes a set value to the log.
Except for performance, equivalent to:
VAR i: INTEGER;
Char("{"); i := MIN(SET);
WHILE x # {} DO
IF i IN x THEN
Int(i); EXCL(x, i);
IF (i + 2 <= MAX(SET)) & (i + 1 IN x) & (i + 2 IN x) THEN
String("..");
x := x - {i + 1, i + 2}; INC(i, 3);
WHILE (i <= MAX(SET)) & (i IN x) DO EXCL(x, i); INC(i) END;
Int(i - 1)
END;
IF x # {} THEN String(", ") END
END;
INC(i)
END;
Char("}")
PROCEDURE String (IN str: ARRAY OF CHAR)
Writes a string value to the log.
PROCEDURE ParamMsg (IN msg, p0, p1, p2: ARRAY OF CHAR)
Writes a parameterized message string value mapped by the Dialog.MapParamString facility to the log.
PROCEDURE Msg (IN msg: ARRAY OF CHAR)
Writes a message string value mapped by the Dialog.MapParamString facility to the log.
Except for performance, equivalent to:
ParamMsg(msg, "", "", "")
PROCEDURE Tab
Writes a tab character (9X) to the log.
PROCEDURE Para
Writes a paragraph character (0EX) to the log. Afterwards, it makes sure that the current end of the log text is visible.
PROCEDURE Ln
Writes a carriage return character (0DX) to the log. Afterwards, it makes sure that the current end of the log text is visible.
PROCEDURE View (v: Views.View)
Writes a view to the log. The size of the view is determined by the text container in cooperation with the view itself.
PROCEDURE ViewForm (v: Views.View; w, h: INTEGER)
Writes a view to the log, and forces it to a particular size given in w and h in universal units.
PROCEDURE New
Used internally.
PROCEDURE Open
Opens a log window if none is open, otherwise it brings the log window to the top.
PROCEDURE Clear
Clears the log text.
PROCEDURE NewView (): TextViews.View
Used internally.
PROCEDURE SetDefaultRuler (ruler: TextRulers.Ruler)
Sets the default ruler.
Pre
ruler # NIL 20
Post
defruler = ruler
PROCEDURE SetDir (d: TextViews.Directory)
Set up the directory object for log text views.
Pre
d # NIL 20
Post
dir = d
VAR buf-: TextModels.Model
The buffer used internally for minimizing screen refreshes.
VAR defruler-: TextRulers.Ruler
The log text's default ruler.
VAR dir-: TextViews.Directory
Used internally.
VAR text-: TextModels.Model
The log text.
| Std/Docu/Log.odc |
StdLogos
Used internally (views for the company logo of Oberon microsystems).
| Std/Docu/Logos.odc |
StdMenuTool
DEFINITION StdMenuTool;
IMPORT TextModels;
PROCEDURE UpdateFromText (text: TextModels.Model);
PROCEDURE UpdateMenus;
PROCEDURE UpdateAllMenus;
PROCEDURE ListAllMenus;
PROCEDURE ThisMenu;
END StdMenuTool.
The menu tool is used during startup of BlackBox to set up the menus.
Typical menu entries:
MENU
"&Menus" "" "StdCmds.OpenDoc('System/Rsrc/Menus')" ""
"&All Menus" "" "StdMenuTool.ListAllMenus" ""
"&Update Menus" "" "StdMenuTool.UpdateMenus" "TextCmds.FocusGuard"
"U&pdate All Menus" "" "StdMenuTool.UpdateAllMenus" ""
END
PROCEDURE UpdateFromText (text: TextModels.Model)
Clears all menus and builds up a new menu bar according to the menu specification in text.
PROCEDURE UpdateMenus
Guard: TextCmds.FocusGuard
Clears all menus and builds up a new menu bar according to the new menu specification in the focus text.
PROCEDURE UpdateAllMenus
Clears all menus and builds up a new menu bar according to the menu specification in System/Rsrc/Menus.
PROCEDURE ListAllMenus
Builds up a text with hyperlinks to all available menu configuration texts, i.e., each subsystem's /Rsrc/Menus text.
PROCEDURE ThisMenu
Used internally (in the hyperlinks of the INCLUDE statements).
| Std/Docu/MenuTool.odc |
StdScrollers
DEFINITION StdScrollers;
IMPORT Dialog, Properties;
CONST
horBar = 0; verBar = 1; horHide = 2; verHide = 3; width = 4; height = 5; savePos = 7; showBorder = 6;
TYPE
Prop = POINTER TO RECORD (Properties.Property)
horBar, verBar, horHide, verHide: BOOLEAN;
width, height: INTEGER;
showBorder, savePos: BOOLEAN
END;
VAR
dialog: RECORD
horizontal, vertical: RECORD
mode: INTEGER;
adapt: BOOLEAN;
size: REAL
END;
showBorder, savePos: BOOLEAN
END;
PROCEDURE AddScroller;
PROCEDURE RemoveScroller;
PROCEDURE InitDialog;
PROCEDURE Set;
PROCEDURE DialogGuard (VAR par: Dialog.Par);
PROCEDURE HeightGuard (VAR par: Dialog.Par);
PROCEDURE WidthGuard (VAR par: Dialog.Par);
PROCEDURE HorAdaptGuard (VAR par: Dialog.Par);
PROCEDURE VerAdaptGuard (VAR par: Dialog.Par);
END StdScrollers.
Module StdScrollers provides a wrapper view which can be wrapped around any other view to provide it with a horizontal and/or vertical scrollbar. For example, a text view in a form may be wrapped in a scroller in order to allow the scrolling of text that doesn't completely fit in the text view.
CONST horBar, verBar, horHide, verHide, width, height, savePos, showBorder
Property elements of the Prop descriptor.
TYPE Prop (Properties.Property)
Properties describing the attributes of a scroller view.
horBar: BOOLEAN
Is there a horizontal scrollbar?
verBar: BOOLEAN
Is there a vertical scrollbar?
horHide: BOOLEAN horHide -> horBar
Only valid if horBar. This leaves three legal possibilities:
~horBar scrollbar is never visible
horBar & horHide scrollbar is only visible when needed (appears or disappears automatically)
horBar & ~horHide scrollbar is always visible
verHide: BOOLEAN verHide -> verBar
Only valid if verBar. This leaves three legal possibilities:
~verBar scrollbar is never visible
verBar & verHide scrollbar is only visible when needed (appears or disappears automatically)
verBar & ~verHide scrollbar is always visible
width, height: INTEGER width >= 0 & height >= 0 [units]
Size of the wrapped view.
A value of 0 means that the wrapped view automatically adapts its size to the scroller (wrapper) view. Other values are fixed sizes.
showBorder: BOOLEAN
Display a border around the wrapped view.
savePos: BOOLEAN
Save the current scroll position when the wrapper is saved to disk, and makes scrolling undoable.
VAR
dialog: RECORD
Interactor for setting the scroller properties of a singleton selection.
horizontal, vertical: RECORD
Descriptor of scrollbar behavior for both dimensions.
mode: INTEGER mode IN {0, 1, 2}
0: never a scrollbar
1: automatic scrollbar
2: always a scrollbar
adapt: BOOLEAN
adapt: set size (width or height) to 0
~adapt: retain a fixed size
size: REAL
size in cm (Dialog.metricSystem) or in inches (~Dialog.metricSystem)
showBorder, savePos: BOOLEAN
Values according to property descriptor.
PROCEDURE AddScroller
Guard: StdCmds.SingletonGuard
Wraps a scroller around the selected view.
PROCEDURE RemoveScroller
Guard: StdCmds.SingletonGuard
Removes the scroller which is selected.
PROCEDURE InitDialog
Initializes variable dialog according to the selected scroller view.
PROCEDURE Set
Applies the newly defined properties to the selected scroller view.
PROCEDURE DialogGuard (VAR par: Dialog.Par)
PROCEDURE HeightGuard (VAR par: Dialog.Par)
PROCEDURE WidthGuard (VAR par: Dialog.Par)
PROCEDURE HorAdaptGuard (VAR par: Dialog.Par)
PROCEDURE VerAdaptGuard (VAR par: Dialog.Par)
Various guards for the Std/Rsrc/Scrollers dialog box.
| Std/Docu/Scrollers.odc |
StdStamps
DEFINITION StdStamps;
PROCEDURE Deposit;
...plus some other items used internally...
END StdStamps.
Stamps are views which indicate the date when the containing document has been saved the last time.
PROCEDURE Deposit
Deposit command for standard stamps.
...plus some other items used internally...
Clicking on the stamp view shows a history of when the document has been saved. Modifier-clicking on the stamp view opens a dialog box that allows to edit the comment associated with the current session.
| Std/Docu/Stamps.odc |
Map to the Std Subsystem
StdApi API for StdCmds
StdClocks analog clock views
StdCmds cmds of std menus
StdCoder ASCII coder
StdDebug minimal debugger
StdFolds fold views
StdHeaders headers / footers
StdLinks hyperlink views
StdLog standard output
StdMenuTool menu tool
StdStamps date stamp views
StdTables table controls
StdTabViews tabbed folder views
StdViewSizer set size of a view
| Std/Docu/Sys-Map.odc |
StdTables
DEFINITION StdTables;
IMPORT
Ports, Dialog, Views, Properties, Controls;
CONST
line = 0DX;
deselect = -1; select = -2; changed = -3;
layoutEditable = 0; dataEditable = 1; selectionStyle = 2;
noSelect = 0; cellSelect = 1; rowSelect = 2; colSelect = 3; crossSelect = 4;
TYPE
Table = RECORD
rows-, cols-: INTEGER;
(VAR tab: Table) SetSize (rows, cols: INTEGER), NEW;
(VAR tab: Table) SetItem (row, col: INTEGER; item: Dialog.String), NEW;
(VAR tab: Table) GetItem (row, col: INTEGER; OUT item: Dialog.String), NEW;
(VAR tab: Table) SetLabel (col: INTEGER; label: Dialog.String), NEW;
(VAR tab: Table) GetLabel (col: INTEGER; OUT label: Dialog.String), NEW;
(VAR tab: Table) HasSelection (): BOOLEAN, NEW;
(VAR tab: Table) GetSelection (OUT row, col: INTEGER), NEW;
(VAR tab: Table) Select (row, col: INTEGER), NEW;
(VAR tab: Table) Deselect, NEW;
(VAR tab: Table) SetAttr (l, t, r, b: INTEGER; style: SET; weight: INTEGER; color: Ports.Color), NEW;
(VAR tab: Table) GetAttr (row, col: INTEGER;
OUT style: SET; OUT weight: INTEGER; OUT color: Ports.Color), NEW
END;
Prop = POINTER TO RECORD (Properties.Property)
layoutEditable, dataEditable: BOOLEAN;
selectionStyle: INTEGER;
(p: Prop) IntersectWith (q: Properties.Property; OUT equal: BOOLEAN)
END;
Directory = POINTER TO ABSTRACT RECORD
(d: Directory) NewControl (p: Controls.Prop): Views.View, ABSTRACT, NEW
END;
VAR
dir-, stdDir-: Directory;
text: Dialog.String;
dlg: RECORD
layoutEditable, dataEditable: BOOLEAN;
selectionStyle: Dialog.List
END;
PROCEDURE InitDialog;
PROCEDURE Set;
PROCEDURE Guard (idx: INTEGER; VAR par: Dialog.Par);
PROCEDURE Notifier (idx, op, from, to: INTEGER);
PROCEDURE SetDir (d: Directory);
PROCEDURE DepositControl;
END StdTables.
Module StdTables implements a simple tabular control ("grid view"). To allow clients to create new table controls, a directory object is exported (StdTables.dir). As interactor, type StdTables.Table is provided.
Typical menu command:
"Insert Table" "" "StdTables.DepositControl; StdCmds.PasteView" "StdCmds.PasteViewGuard"
The property editor for the StdTables is the same as for normal controls. The fields, Link, Label, Guard and Notifier works in the same way as for other controls. In addition to the property editor, a special dialog for tables is offered, where one can choose the visual feedback of the selection in a table. Furthermore one can specify, whether the layout should be editable (column width), and whether the data in the cells should be editable.
CONST line
New line character for multiple line labels.
CONST deselect
Notifier op-code. Indicates that the cell at position row = from and column = to has been deselected.
CONST select
Notifier op-code. Indicates that the user has selected a cell at position row = from and column = to.
CONST changed
Notifier op-code. Indicates that the user has changed the contents of a cell in the table at position row = from and column = to.
CONST layoutEditable
Element of a control property's valid set. Determines, whether the layout editable property is valid.
CONST dataEditable
Element of a control property's valid set. Determines, whether the data editable property is valid.
CONST selectionStyle
Element of a control property's valid set. Determines, whether the selection style property is valid.
CONST noSelect, cellSelect, rowSelect, colSelect, crossSelect
Selection style property constants.
TYPE Table
Interactor for table controls.
rows-, cols-: INTEGER (rows >= 0) & (cols >= 0)
Number of rows and columns of the table.
PROCEDURE (VAR tab: Table) SetSize (rows, cols: INTEGER), NEW
Set size of the table.
Pre
20 (rows >= 0) & (cols >= 0)
21 ((cols > 0) OR ((cols = 0) & (rows = 0))
PROCEDURE (VAR tab: Table) SetItem (row, col: INTEGER; item: Dialog.String), NEW
Set contents of cell in row row and column col to item.
Pre
20 SetSize must have been called before
PROCEDURE (VAR tab: Table) GetItem (row, col: INTEGER; OUT item: Dialog.String), NEW
Get contents of cell in row row and column col.
Pre
20 SetSize must have been called before
PROCEDURE (VAR tab: Table) SetLabel (col: INTEGER; label: Dialog.String), NEW
Set contents of label of column col. For each occurence of the character StdTables.line in label a new line is created.
Pre
20 SetSize must have been called before
PROCEDURE (VAR tab: Table) GetLabel (col: INTEGER; OUT label: Dialog.String), NEW
Get contents of label of column col.
Pre
20 SetSize must have been called before
PROCEDURE (VAR tab: Table) HasSelection (): BOOLEAN, NEW
Returns, whether a cell in the table is currently selected.
PROCEDURE (VAR tab: Table) GetSelection (OUT row, col: INTEGER), NEW
Get coordinates (row and column) of the selected table cell.
Pre
20 SetSize must have been called before
21 tab.HasSelection()
PROCEDURE (VAR tab: Table) Select (row, col: INTEGER), NEW
Set selection in table to row row and column col.
Pre
20 SetSize must have been called before
Post
tab.HasSelection() = TRUE
PROCEDURE (VAR tab: Table) Deselect, NEW
Remove current selection in table, if any.
Pre
20 SetSize must have been called before
Post
tab.HasSelection() = FALSE
PROCEDURE (VAR tab: Table) SetAttr (l, t, r, b: INTEGER; style: SET; weight: INTEGER; color: Ports.Color), NEW
Sets the the attributes for a range of cells. style and weight affects the font for the cell and color is the color of the text in the cell. (For explanations of the parameters style and weight, see Fonts.Font.) The range is indicated by l and t being the column and row for the top left cell in the range, and r and b being the column and row of the bottom right cell in the range.
PROCEDURE (VAR tab: Table) GetAttr (row, col: INTEGER; OUT style: SET; OUT weight: INTEGER; OUT color: Ports.Color), NEW
Retrieves the current attribute values for the cell at position row, col in the table.
Pre
20 SetSize must have been called before
TYPE Prop
Table specific properties.
layoutEditable, dataEditable: BOOLEAN
Column width is editable by the user; data in table cells is editable by the user.
selectionStyle: INTEGER
Visual feedback of selections:
noSelect: no visual feedback
cellSelect: selected cell is high-lighted
rowSelect: all cells in selected row are high-lighted
colSelect: all cells in selected column are high-lighted
crossSelect: all cells in selected row and column are high-lighted
PROCEDURE (p: Prop) IntersectWith (q: Properties.Property; OUT equal: BOOLEAN)
Intersect table properties p with another property record q. Iff both are equal, equal is set to TRUE.
TYPE Directory
New controls can be created using the directory object StdTables.dir.
PROCEDURE (d: Directory) NewControl (p: Controls.Prop): Views.View, ABSTRACT, NEW
Create a new table control using properties p.
VAR dir-, stdDir-: Directory dir # NIL, stdDir # NIL, stable stdDir = d
Directory and standard directory objects for table controls.
VAR text: Dialog.String valid only during the editing of a cell
Contents of the cell currently being edited.
VAR dlg: RECORD
Interactor for table property dialog.
PROCEDURE InitDialog
Init table property dialog.
PROCEDURE Set
Set properties as selected in table property dialog.
PROCEDURE Guard (idx: INTEGER; VAR par: Dialog.Par)
Guard for table property dialog.
CASE idx OF
0: Layout Editable checkbox
1: Data Editable checkbox
2: Selection Style listbox
END
PROCEDURE Notifier (idx, op, from, to: INTEGER)
Notifier for table property dialog.
CASE idx OF
0: Layout Editable checkbox
1: Data Editable checkbox
2: Selection Style listbox
END
PROCEDURE SetDir (d: Directory)
Set directory object.
Pre
d # NIL 20
Post
stdDir' = NIL
stdDir = d
dir = d
PROCEDURE DepositControl
Deposit command for table controls.
| Std/Docu/Tables.odc |
StdTabViews
DEFINITION StdTabViews;
IMPORT Views, Dialog, StdCFrames;
CONST
noTab = -1;
TYPE
Directory = POINTER TO ABSTRACT RECORD
(d: Directory) New (): View, NEW, ABSTRACT
END;
Frame = POINTER TO ABSTRACT RECORD (StdCFrames.Frame)
(f: Frame) GetDispSize (OUT x, y, w, h: INTEGER), NEW, ABSTRACT;
(f: Frame) InDispArea (x, y: INTEGER): BOOLEAN, NEW, ABSTRACT;
(f: Frame) SetIndex (i: INTEGER), NEW
END;
FrameDirectory = POINTER TO ABSTRACT RECORD
(d: FrameDirectory) GetTabSize (VAR w, h: INTEGER), NEW, ABSTRACT;
(d: FrameDirectory) New (): Frame, NEW, ABSTRACT
END;
View = POINTER TO LIMITED RECORD (Views.View)
(tv: View) GetItem (i: INTEGER; OUT label: Dialog.String; OUT v: Views.View), NEW;
(tv: View) GetNewFrame (VAR frame: Views.Frame);
(tv: View) GetNotifier (OUT notifier: Dialog.String), NEW;
(tv: View) HandleCtrlMsg (f: Views.Frame; VAR msg: Views.CtrlMessage; VAR focus: Views.View);
(tv: View) Index (): INTEGER, NEW;
(tv: View) Neutralize;
(tv: View) NofTabs (): INTEGER, NEW;
(tv: View) Restore (f: Views.Frame; l, t, r, b: INTEGER);
(tv: View) SetIndex (i: INTEGER), NEW;
(tv: View) SetItem (i: INTEGER; label: Dialog.String; v: Views.View), NEW;
(tv: View) SetNofTabs (nofTabs: INTEGER), NEW;
(tv: View) SetNotifier (IN notifier: ARRAY OF CHAR), NEW
END;
NotifierProc = PROCEDURE (tv: View; from, to: INTEGER);
VAR
dir-: Directory;
dlg: RECORD
name, notifier: Dialog.String;
opt: INTEGER
END;
frameDir-: FrameDirectory;
frameStdDir-: FrameDirectory;
setFocus: BOOLEAN;
stdDir-: Directory;
PROCEDURE AddTab;
PROCEDURE BeginChanges (tv: View);
PROCEDURE Delete;
PROCEDURE DeleteGuard (VAR par: Dialog.Par);
PROCEDURE Deposit;
PROCEDURE EndChanges (tv: View);
PROCEDURE Focus (): View;
PROCEDURE InitDialog;
PROCEDURE LabelGuard (VAR par: Dialog.Par);
PROCEDURE LayoutModeGuard (VAR par: Dialog.Par);
PROCEDURE Left;
PROCEDURE MaskModeGuard (VAR par: Dialog.Par);
PROCEDURE ModeNotifier (op, from, to: INTEGER);
PROCEDURE NewGuard (VAR par: Dialog.Par);
PROCEDURE NotifierGuard (VAR par: Dialog.Par);
PROCEDURE Rename;
PROCEDURE RenameGuard (VAR par: Dialog.Par);
PROCEDURE Right;
PROCEDURE SetDir (d: Directory);
PROCEDURE SetFrameDir (d: FrameDirectory);
PROCEDURE SetGuard (VAR par: Dialog.Par);
PROCEDURE SetNotifier;
PROCEDURE This (v: Views.View): View;
END StdTabViews.
A StdTabViews.View displays a set of tabs to the user. Each tab consists of a label and a view. When the user clicks on the label, the associated view is displayed. Try it on the example below!
This example was created with FormViews but any Views.View can be used in the tabs.
There are two ways of creating StdTabViews: The tab can be created programmatically or it can be created using a graphical user interface. In most cases the graphical user interface is enough, and no programming is needed to create a StdTabViews.View. For more advanced use there exists a programming interface and this will be described further down.
To use the graphical user interface a StdTabViews.View needs to be dropped into a document or a form. This can be done by selecting the option Insert Tab View from the Controls menu. The new StdTabViews.View contains two tabs, called Tab1 and Tab2, and they each have an (empty) FormViews.View associated with them. A newly created tab looks like this:
The StdTabViews.View is fully functional, but a bit boring. If the StdTabViews.View is focused, each tab can be edited just like a normal form. Controls can be dropped into it and moved aound and their properties can be edited. Also this can be tried on the tab above.
To add, remove or edit the name of tabs the StdTabViews property editor needs to be started. This is done by selecting the tab and choosing "Edit->Object Properties...". The property editor looks like this:
The buttons and fields have the following meaning:
<-
Clicking on this button moves the current tab one step to the left. This can be used to changed the order of the tabs.
->
Clicking on this button moves the current tab one step to the right. This can be used to changed the order of the tabs.
Label
Displays the label of the current tab.
Rename
Sets the label of the currrent tab to the text displayed in the label field. An empty label is not allowed.
New Tab
Creats a new tab and adds it to the list. The label of the new tab is set to the text displayed in the label field. If the text field is empty no new tab can be created.
Delete
Removes the current tab from the tab view.
Notifier
Displays the name of the notifier that is associated with the tab view.
Set
Sets the notifier of the the tab view to the name displayed in the notifier field.
All tabs in Layout Mode
Sets all tabs in the Tab View in Layout Mode. Layout Mode is a container mode that allows for editing. For more information about container modes see About Container Modes futher down.
All tabs in Mask Mode
Sets all tabs in the Tab View in Mask Mode. Mask Mode is a container mode that doesn't allow selecting of contained views. This mode is used for displaying documents as dialogs. For more information about container modes see About Container Modes futher down.
About Notifiers
The notifier for StdTabViews is not the same as a notifier for normal Controls, but it works in a similar way. The signarure is different and there is just one type of notification sent. StdTabViews notifiers have the signature described by the type StdTabViews.NotifierProc.
The notifier is only called when the current tab is changed. When called, tv is the StdTabViews.View that the notification concerns, from is the tab that used to be the current tab and to is the new current tab.
When a tab is saved the index of the current tab is saved with it and when the tab is internalized the current tab is set to the index that was saved. This enables the designer of a dialog with a tab to control which tab is the current tab when the dialog is opened. It also provides a way to find a StdTabViews.View in a dialog. When the current tab is set for the first time during internalization the notifier is called with tv set to the new StdTabViews.View, from set to the constant noTab and to set to the index of the current tab saved in externalize.
This means that whenever a document with a StdTabViews.View inside is opened the notifier is called and this allows the application to bind to the StdTabViews.View if needed. This is an easy way to get to the programming interface described below.
About Container Modes
Containers can have different modes. A FormViews.View is a container and can for example be put in Layout Mode and Mask Mode. In Layout Mode it is possible to select contained views, such as Controls, and move them around. In Mask Mode, on the other hand, it is not possible to select or move around contained views.
Container modes can be changed using the Dev-menu but normally this is not needed. The normal way is to save a document in Edit or Layout Mode and then open it in the desired mode using the commands provided in StdCmds. A dialog, for example, is usually saved in Layout Mode and then opened in Mask Mode by using StdCmds.OpenAuxDialog.
The problem is that StdTabViews breaks this pattern since each tab can contain its own container with its own mode. It is needed to use the Dev-menu to put the tabs in the correct mode before saving a dialog. To use the container modes and the Dev-menu requires some knowledge about Containers. To avoid this requirement the radiobuttons "All tabs in Layout Mode" and "All tabs in Mask Mode" are provided. These buttons make it possible to set all tabs in Mask mode before saving the dialog or setting all tabs in Layout mode to edit the dialog, thus eliminating the need to use the Dev-menu.
CONST noTab
Constant used as from value to the notifier when a StdTabViews.View is internalize.
TYPE View = POINTER TO LIMITED RECORD (Views.View)
Allows the user to select different views by clicking on tabs.
PROCEDURE (tv: View) SetItem (i: INTEGER; label: Dialog.String; v: Views.View)
NEW
Adds a new tab to tv. The new tab gets label as its label and v as its view. i indicates the position of the tab among the other tabs. IF i is greater than tv.NofTabs() then then number of tabs in tv is increased, if not, the prevous tab at position i is overwritten. A deep copy of v is made before it is added to tv.
Pre
i >= 0
label # ""
v # NIL
PROCEDURE (tv: View) GetItem (i: INTEGER; OUT label: Dialog.String; OUT v: Views.View)
NEW
Retrievs the label and the view for tab i.
Pre
i >= 0
i < tv.NofTabs()
PROCEDURE (tv: View) SetNofTabs (nofTabs: INTEGER)
NEW
Makes sure that nofTabs tabs are available in tv.Note that SetItem also increases the number of tabs of the View if necessary, so SetNofTabs is strictly only necessary to decrease the number of tabs.
Pre
nofTabs >= 0
Post
tv.NofTabs() = nofTabs
PROCEDURE (tv: View) NofTabs (): INTEGER, NEW;
NEW
Retruns the number of tabs in tv.
Post
Returned value >= 0
PROCEDURE (tv: View) SetIndex (i: INTEGER)
NEW
Sets the current tab in tv, updates the view. The notifier is not called when tabs are changed by a call to SetIndex.
Pre
i >= 0
i < tv.NofTabs()
Post
tv.Index() = i
PROCEDURE (tv: View) Index (): INTEGER
NEW
Returns the index of the currently selected tab. The index is updated whenever a user clicks on a tab or whenever SetIndex is called.
Post
Returned value is >= 0 and < tv.NofTabs()
PROCEDURE (tv: View) SetNotifier (IN notifier: ARRAY OF CHAR)
NEW
Sets the notifier of tv to be notifier. notifier = "" is permitted and it is interpreted as meaning that tv has no notifer. For more information about notifiers, see the chapter About Notifiers above.
PROCEDURE (tv: View) GetNotifier (OUT notifier: Dialog.String)
NEW
Sets notifier to the value of the notifier of tv. notifer is the empty string if tv doesn't have a notifier.
TYPE Directory
ABSTRACT
Directory type for StdTabViews.View.
PROCEDURE (d: Directory) New (): View
NEW, ABSTRACT
Allocates and returns a new View.
TYPE NotifierProc = PROCEDURE (tv: View; from, to: INTEGER)
StdTabViews notification commands must have this signature. Through calls of notification procedures, an application can be notified when the selected tab of a StdTabViews.View is changed due to user interaction. The parameters have the following meaning:
tv = the StdTabViews.View where the tab was changed.
from = the selected tab before the change. Has the value noTab when the notifier is called from Internalize.
to = the new selected tab.
VAR dir-, stdDir-: Directory dir # NIL & stdDir # NIL
Directories for creating StdTabViews.Views.
PROCEDURE SetDir (d: Directory)
Set directory.
PROCEDURE Deposit
Allocate a new View using dir.New, adds two tabs to it and deposits it.
PROCEDURE This (v: Views.View): View
Traverserses view v and all its contained views (if any) and returns the first StdTabViews.View that is found. If no StdTabViews.View is found then NIL is returned.
Pre
v # NIL
PROCEDURE Focus (): View
Searches for a StdTabViews.View along the focus path. If one is found it is returned, if not NIL is returned. If more than one StdTabViews.View exists in the focus path it is undefinied which one will be returned.
PROCEDURE BeginChanges (tv: View)
Disables update of tv until a subsequent call to EndChanges. Each call to BeginChanges must be balanced by a call to EndChanges, otherwise a trap will occur (in StdTabViews.BalanceAction.Do). The calls may be nested. BeginChanges and EndChanges are provided to make it possible to do several changes to a StdTabViews.View without intermediate updates.
Pre
Number of calls to BeginChanges >= Number of calls to EndChanges, 20
PROCEDURE EndChanges (tv: View)
Enables update for tv again after a call to BeginChanges.
Pre
Number of calls to BeginChanges > Number of calls to EndChanges, 20
The following types, variables and procedures are only used internally to handle frames of StdTabViews:
TYPE Frame = POINTER TO ABSTRACT RECORD (StdCFrames.Frame)
TYPE FrameDirectory = POINTER TO ABSTRACT RECORD
VAR frameDir-, frameStdDir-: FrameDirectory
PROCEDURE SetFrameDir (d: FrameDirectory)
PROCEDURE (f: Frame) GetDispSize (OUT x, y, w, h: INTEGER), NEW, ABSTRACT
PROCEDURE (f: Frame) InDispArea (x, y: INTEGER): BOOLEAN, NEW, ABSTRACT
PROCEDURE (f: Frame) SetIndex (i: INTEGER), NEW
PROCEDURE (d: FrameDirectory) GetTabSize (VAR w, h: INTEGER), NEW, ABSTRACT
PROCEDURE (d: FrameDirectory) New (): Frame, NEW, ABSTRACT
The following types, variables and procedures are only used for the property inspector of the StdTabViews.View:
VAR dlg: RECORD
name, notifier: Dialog.String;
opt: INTEGER
END;
PROCEDURE AddTab
PROCEDURE Delete
PROCEDURE DeleteGuard (VAR par: Dialog.Par)
PROCEDURE InitDialog
PROCEDURE LabelGuard (VAR par: Dialog.Par)
PROCEDURE LayoutModeGuard (VAR par: Dialog.Par);
PROCEDURE Left
PROCEDURE MaskModeGuard (VAR par: Dialog.Par);
PROCEDURE ModeNotifier (op, from, to: INTEGER);
PROCEDURE NewGuard (VAR par: Dialog.Par)
PROCEDURE NotifierGuard (VAR par: Dialog.Par)
PROCEDURE Rename
PROCEDURE RenameGuard (VAR par: Dialog.Par)
PROCEDURE Right
PROCEDURE SetGuard (VAR par: Dialog.Par)
PROCEDURE SetNotifier
The following variable is only used internally:
VAR setFocus: BOOLEAN
| Std/Docu/TabViews.odc |
StdViewSizer
DEFINITION StdViewSizer;
IMPORT Dialog;
VAR
size: RECORD
typeName-: Dialog.String;
w, h: REAL
END;
PROCEDURE InitDialog;
PROCEDURE SetViewSize;
PROCEDURE SizeGuard (VAR par: Dialog.Par);
PROCEDURE UnitGuard (VAR par: Dialog.Par);
END StdViewSizer.
StdViewSizer is a command package allowing the user to resize views embedded in containers by specifying width and height as numbers. This is useful whenever dragging view borders with the mouse is not precise enough. The command package works on any singleton view.
For entry in a menu, the following line is recommended:
"View Size..." "" "StdViewSizer.InitDialog; StdCmds.OpenToolDialog('Std/Rsrc/ViewSizer', 'View Size')" "StdCmds.SingletonGuard"
VAR size: RECORD
Interactor for setting the view size.
typeName-: Dialog.String
Type of the current singleton view.
w: INTEGER
View width in cm or inch, depending on the value of Dialog.metricSystem.
h: INTEGER
View height in cm or inch, depending on the value of Dialog.metricSystem.
PROCEDURE InitDialog
Initialization command for size interactor.
PROCEDURE SetViewSize
Applies the interactor values in size. To set up size to the selected view, InitDialog needs to be called first.
PROCEDURE SizeGuard (VAR par: Dialog.Par)
Guard which ensures that the size interactor matches the current singleton selection. If there is no singleton selection, the guard disables.
PROCEDURE UnitGuard (VAR par: Dialog.Par)
Guard that sets par.label to "cm" or "inch" respectively, depending on the value of Dialog.metricSystem.
| Std/Docu/ViewSizer.odc |
Subsets and Splits