home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #6 / amigamamagazinepolishissue1998.iso / coders / jËzyki_programowania / oberon / system / lineelems.mod (.txt) < prev    next >
Oberon Text  |  2012-04-20  |  5KB  |  133 lines

  1. Syntax10.Scn.Fnt
  2. Syntax10b.Scn.Fnt
  3. MODULE LineElems;    (** CAS 15-Oct-91 / 28-Sep-93 **)
  4.     (* mh 12.1.93: elimination of WriteNum, ReadNum for Oberon V2.2 *)
  5.     IMPORT
  6.         SYSTEM, Input, Display, Viewers, Files, Fonts, Printer, Texts, Oberon,
  7.         TextFrames, TextPrinter;
  8.     CONST
  9.         autoVOpt* = 0; tabVOpt* = 1; autoHOpt* = 2; doubleOpt* = 3;
  10.         mm = TextFrames.mm; Scale = mm DIV 10;
  11.         unit = TextFrames.Unit; Unit = TextPrinter.Unit;
  12.         MinW = unit; MinH = 1*Scale;
  13.     TYPE
  14.         Elem* = POINTER TO ElemDesc;
  15.         ElemDesc* = RECORD(Texts.ElemDesc)
  16.             opts*: SET;
  17.             h: LONGINT    (*used to cache true height of hair lines*)
  18.         END;
  19.     PROCEDURE Max(x, y: LONGINT): LONGINT;
  20.     BEGIN
  21.         IF x > y THEN RETURN x ELSE RETURN y END
  22.     END Max;
  23.     (* portable I/O *)
  24.     PROCEDURE WriteSet (VAR r: Files.Rider; s: SET);
  25.     BEGIN Files.WriteNum(r, SYSTEM.VAL(LONGINT, s))
  26.     END WriteSet;
  27.     PROCEDURE ReadSet (VAR r: Files.Rider; VAR s: SET);
  28.     BEGIN Files.ReadNum(r, SYSTEM.VAL(LONGINT, s))
  29.     END ReadSet;
  30.     (* handle line elements *)
  31.     PROCEDURE Prepare* (E: Elem; pos, indent: LONGINT; printing: BOOLEAN);
  32.         VAR P: TextFrames.Parc; pbeg: LONGINT; i: INTEGER;
  33.     BEGIN TextFrames.ParcBefore(Texts.ElemBase(E), pos, P, pbeg);
  34.         IF autoVOpt IN E.opts THEN E.W := Max(P.width - indent, MinW)
  35.         ELSIF tabVOpt IN E.opts THEN i := 0;
  36.             WHILE (i < P.nofTabs) & (P.tab[i] - indent < 5*Scale) DO INC(i) END;
  37.             IF i < P.nofTabs THEN E.W := P.tab[i] - indent ELSE E.W := MinW END
  38.         END;
  39.         IF autoHOpt IN E.opts THEN E.h := Max(P.lsp, MinH) END;
  40.         IF printing THEN E.H := E.h
  41.         ELSE
  42.             IF doubleOpt IN E.opts THEN E.H := Max(E.h, 3*unit) ELSE E.H := Max(E.h, unit) END
  43.         END
  44.     END Prepare;
  45.     PROCEDURE Draw* (E: Elem; x0, y0: INTEGER; col: SHORTINT);
  46.         VAR w, h: INTEGER;
  47.     BEGIN w := SHORT(Max(E.W, unit) DIV unit); h := SHORT(E.H DIV unit);
  48.         IF doubleOpt IN E.opts THEN h := SHORT(Max(1, h DIV 3));
  49.             Display.ReplConst(col, x0, y0 + 2 * h, w, h, Display.replace)
  50.         END;
  51.         Display.ReplConst(col, x0, y0, w, h, Display.replace)
  52.     END Draw;
  53.     PROCEDURE Print* (E: Elem; x0, y0: INTEGER; col: SHORTINT);
  54.         VAR w, h: INTEGER;
  55.     BEGIN w := SHORT(E.W DIV Unit); h := SHORT(E.H DIV Unit);
  56.         IF doubleOpt IN E.opts THEN h := SHORT(Max(1, h DIV 3));
  57.             Printer.ReplConst(x0, y0 + SHORT(Max(4, 3 * h)), w, h)
  58.         END;
  59.         Printer.ReplConst(x0, y0, w, h)
  60.     END Print;
  61.     PROCEDURE Load* (E: Elem; VAR r: Files.Rider);
  62.     BEGIN ReadSet(r, E.opts); Files.ReadNum(r, E.h)
  63.     END Load;
  64.     PROCEDURE Store* (E: Elem; VAR r: Files.Rider);
  65.     BEGIN WriteSet(r, E.opts); Files.WriteNum(r, E.h)
  66.     END Store;
  67.     PROCEDURE Copy* (SE, DE: Elem);
  68.     BEGIN Texts.CopyElem(SE, DE); DE.opts := SE.opts; DE.h := SE.h
  69.     END Copy;
  70.     PROCEDURE Handle* (E: Texts.Elem; VAR msg: Texts.ElemMsg);
  71.         VAR e: Elem;
  72.     BEGIN
  73.         WITH E: Elem DO
  74.             IF msg IS TextFrames.DisplayMsg THEN
  75.                 WITH msg: TextFrames.DisplayMsg DO
  76.                     IF msg.prepare THEN Prepare(E, msg.pos, msg.indent, FALSE)
  77.                     ELSE Draw(E, msg.X0, msg.Y0, msg.col)
  78.                     END
  79.                 END
  80.             ELSIF msg IS TextPrinter.PrintMsg THEN
  81.                 WITH msg: TextPrinter.PrintMsg DO
  82.                     IF msg.prepare THEN Prepare(E, msg.pos, msg.indent, TRUE)
  83.                     ELSE Print(E, msg.X0, msg.Y0, msg.col)
  84.                     END
  85.                 END
  86.             ELSIF msg IS Texts.IdentifyMsg THEN
  87.                 WITH msg: Texts.IdentifyMsg DO msg.mod := "LineElems"; msg.proc := "Alloc" END
  88.             ELSIF msg IS Texts.FileMsg THEN
  89.                 WITH msg: Texts.FileMsg DO
  90.                     IF msg.id = Texts.load THEN Load(E, msg.r)
  91.                     ELSIF msg.id = Texts.store THEN Store(E, msg.r)
  92.                     END
  93.                 END
  94.             ELSIF msg IS Texts.CopyMsg THEN NEW(e); Copy(E, e); msg(Texts.CopyMsg).e := e
  95.             END
  96.         END
  97.     END Handle;
  98.     PROCEDURE Alloc*;
  99.         VAR e: Elem;
  100.     BEGIN NEW(e); e.handle := Handle; Texts.new := e
  101.     END Alloc;
  102.     PROCEDURE Insert*;    (** "^" | ( ("auto" | "tab" | W) ("auto" | H) ["double"] ) **)
  103.         VAR S: Texts.Scanner; w, h: LONGINT; opts: SET; ok: BOOLEAN;
  104.             text: Texts.Text; beg, end, time: LONGINT; e: Elem; m: TextFrames.InsertElemMsg;
  105.     BEGIN Texts.OpenScanner(S, Oberon.Par.text, Oberon.Par.pos); Texts.Scan(S);
  106.         IF (S.line = 0) & (S.class = Texts.Char) & (S.c = "^") THEN
  107.             Oberon.GetSelection(text, beg, end, time);
  108.             IF time >= 0 THEN Texts.OpenScanner(S, text, beg); Texts.Scan(S) END
  109.         END;
  110.         opts := {}; ok := TRUE;
  111.         IF (S.line = 0) & (S.class = Texts.Name) & (S.s = "auto") THEN INCL(opts, autoVOpt); w := MinW
  112.         ELSIF (S.line = 0) & (S.class = Texts.Name) & (S.s = "tab") THEN INCL(opts, tabVOpt); w := MinW
  113.         ELSIF (S.line = 0) & (S.class = Texts.Int) & (1 <= S.i) & (S.i <= 10000) THEN w := S.i * Scale
  114.         ELSE ok := FALSE
  115.         END;
  116.         Texts.Scan(S);
  117.         IF (S.line = 0) & (S.class = Texts.Name) & (S.s = "auto") THEN INCL(opts, autoHOpt); h := MinH
  118.         ELSIF (S.line = 0) & (S.class = Texts.Int) & (1 <= S.i) & (S.i <= 100) THEN h := S.i * Scale
  119.         ELSE ok := FALSE
  120.         END;
  121.         Texts.Scan(S);
  122.         IF (S.line = 0) & (S.class = Texts.Name) & (S.s = "double") THEN INCL(opts, doubleOpt); h := 3 * h END;
  123.         IF ok THEN NEW(e); e.W := w; e.H := h; e.handle := Handle; e.opts := opts; e.h := h; m.e := e;
  124.             Oberon.FocusViewer.handle(Oberon.FocusViewer, m)
  125.         END
  126.     END Insert;
  127. END LineElems.
  128.     LineElems.Insert ^
  129.         auto auto double    tab auto double    3 auto double
  130.         auto 6 double    tab 1 double    1 1 double
  131.         auto auto    tab auto    3 auto
  132.         auto 1    tab 1    1 1
  133.