home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #6 / amigamamagazinepolishissue1998.iso / coders / jËzyki_programowania / oberon / system1 / dialogtexts.mod (.txt) < prev    next >
Oberon Text  |  1977-12-31  |  13KB  |  286 lines

  1. Syntax10.Scn.Fnt
  2. Syntax10i.Scn.Fnt
  3. StampElems
  4. Alloc
  5. 30 Jan 95
  6. Syntax10b.Scn.Fnt
  7. MODULE DialogTexts;
  8.     (** Markus Knasm
  9. ller  8 Jun 94 - 
  10.     IMPORT DialogFrames, Dialogs, Display, Files, GraphicUtils, In, MenuViewers, Oberon, Texts, TextFrames, Types, Viewers;
  11.     CONST 
  12.         W* = 70; H* = 22; white = 0; black = 15; grey1 = 11; minH = 16;
  13.         editMenu = "System.Close System.Copy System.Grow ";
  14.     TYPE
  15.         Item* = POINTER TO ItemDesc;
  16.         ItemDesc* = RECORD(Dialogs.ObjectDesc)
  17.             f: TextFrames.Frame;
  18.         END;
  19.         ChangeMsg = RECORD (Display.FrameMsg);
  20.             x, y: LONGINT;
  21.         END;
  22.     VAR 
  23.         w0: Texts.Writer; 
  24.         GetParText*: PROCEDURE (n: ARRAY OF CHAR; p: Dialogs.Panel; VAR t: Texts.Text);
  25.             (** returns the generated parameter t, defined by the text items of panel p, which names are contained in n *)
  26.     PROCEDURE (t: Item) Copy* (VAR dup: Dialogs.Object);
  27.     (** allocates dup and makes a deep copy of o. Before calling this methode dup should be equal NIL *)
  28.         VAR x: Item; t0: Texts.Text;
  29.     BEGIN
  30.         IF dup = NIL THEN NEW (x); dup := x ELSE x := dup(Item) END; 
  31.         t.Copy^ (dup);
  32.         NEW (t0); t0 := TextFrames.Text (""); x.f := TextFrames.NewText (t0, 0)
  33.     END Copy;
  34.     PROCEDURE (t: Item) GetText* (): Texts.Text;
  35.     (** returns the text of the item *)
  36.     BEGIN RETURN t.f.text
  37.     END GetText;
  38.     PROCEDURE (t: Item) SetSelection* (beg, end: LONGINT);
  39.     (** sets the selection to the interval [beg..end[ *)
  40.     BEGIN IF t.f # NIL THEN TextFrames.SetSelection (t.f, beg, end) END
  41.     END SetSelection;
  42.     PROCEDURE (t: Item) RemoveSelection*;
  43.     (** removes the selection *)
  44.     BEGIN IF t.f # NIL THEN TextFrames.RemoveSelection (t.f) END
  45.     END RemoveSelection;
  46.     PROCEDURE ParText (n: ARRAY OF CHAR; p: Dialogs.Panel; VAR t: Texts.Text);
  47.     (* returns the generated parameter t, defined by the text items of panel p, which names are contained in n *)
  48.         VAR t0, t1: Texts.Text; s: Texts.Scanner; o: Dialogs.Object;
  49.     BEGIN
  50.         t := TextFrames.Text (""); t0 := TextFrames.Text ("");
  51.         Texts.WriteString (w0, n); Texts.Append (t0, w0.buf);
  52.         Texts.OpenScanner (s, t0, 0); Texts.Scan (s);
  53.         WHILE (s.class # Texts.Char) OR (s.c # 0X) DO
  54.             IF s.class = Texts.Name THEN
  55.                 o := p.NamedObject (s.s);
  56.                 IF (o # NIL) & (o IS Item) THEN
  57.                     t1 := o(Item).GetText ();
  58.                     Texts.Save (t1, 0, t1.len, w0.buf); Texts.WriteString (w0, " ");
  59.                     Texts.Append (t, w0.buf)
  60.                 END
  61.             ELSIF s.class = Texts.String THEN
  62.                 Texts.WriteString (w0, s.s); Texts.Append (t, w0.buf)
  63.             END;
  64.             Texts.Scan (s)
  65.         END
  66.     END ParText;
  67.     PROCEDURE DrawFrame (f1, f: Display.Frame; m: BOOLEAN);
  68.         VAR mode: INTEGER;
  69.     BEGIN
  70.         IF m THEN mode := Display.invert ELSE mode := Display.replace END;
  71.         Display.ReplConstC (f1, black, f.X - 1, f.Y, 1, f.H + 1, mode); Display.ReplConstC (f1, white, f.X + f.W, f.Y, 1, f.H + 1, mode);
  72.         Display.ReplConstC (f1, white, f.X, f.Y, f.W - 1, 1, mode); Display.ReplConstC (f1, black, f.X, f.Y + f.H, f.W - 1, 1, mode)
  73.     END DrawFrame;
  74.     PROCEDURE Adjust (f: TextFrames.Frame; id, dY, y, h: INTEGER);
  75.         VAR m: MenuViewers.ModifyMsg;
  76.     BEGIN
  77.         m.id := id; m.dY := dY; m.Y := y; m.H := 0; f.handle (f, m);
  78.         m.id := id; m.dY := dY; m.Y := y; m.H := h; f.handle (f, m);
  79.     END Adjust; 
  80.     PROCEDURE (t: Item) Draw* (x, y: INTEGER; f: Display.Frame);
  81.     (** displays the object at (x, y) in frame f *)
  82.         VAR w, h, w1, h1, ox, oy: INTEGER; 
  83.     BEGIN
  84.         INC (x); t.GetDim (ox, oy, w, h); DEC (w, 2); DEC (h);
  85.         (* checks wether textframe is visible *)
  86.         IF (y + h <= f.Y) OR (y >= f.Y + f.H) OR (x + w <= f.X) OR (x >= f.X + f.W) THEN RETURN END;
  87.         (* corrects x and y such that the lower left coordinats of the textframes are visible *)
  88.         IF (x < f.X) & (x + w > f.X) THEN w := w - (f.X - x); x := f.X END;    
  89.         IF (y < f.Y) & (y + h > f.Y) THEN  h := h- (f.Y - y); y := f.Y END;
  90.         (* corrects wide and height such that the full textframe can be displayed *)
  91.         w1 := f.W - (x - f.X); h1 := f.H - (y - f.Y);
  92.         IF w1 < t.f.left THEN RETURN END;
  93.         IF w > w1 THEN w := w1 END; IF h > h1 THEN h := h1 END;
  94.         IF w < 0 THEN w := 0 END; IF h < 0 THEN h := 0 END;
  95.         t.f.X := x; t.f.Y := y; t.f.W := w; t.f.H := h; 
  96.         Oberon.RemoveMarks (f.X, f.Y, f.W, f.H); DrawFrame (f, t.f, t.selected);
  97.         t.f.barW := 0; t.f.left := 3; t.f.right := 3; t.f.bot := 0; t.f.top := 2;  
  98.         Adjust (t.f, MenuViewers.extend, 0, t.f.Y + 1, t.f.H - 1);
  99.     END Draw;
  100.     PROCEDURE (t: Item) Print* (x, y: INTEGER);
  101.     (** prints the object at printer coordinates (x, y) *)
  102.         VAR ox, oy, ow, oh: INTEGER;
  103.     BEGIN t.GetPDim (ox, oy, ow, oh); GraphicUtils.PrintBox (x, y, ow, oh)
  104.     END Print;
  105.     PROCEDURE (t: Item) Handle* (f: Display.Frame; VAR msg: Display.FrameMsg);
  106.     (** handles messages which were sent to frame f *)
  107.         VAR x, y, w, h, h1, xh, yh: INTEGER; v: Viewers.Viewer; msg1: Oberon.CopyMsg; 
  108.             f1: Display.Frame; cond: BOOLEAN; msg2: ChangeMsg; t1: Texts.Text;
  109.     BEGIN    
  110.         t.Handle^ (f, msg); t.GetDim (x, y, w, h);
  111.         (* checks textframe is visible ? *)
  112.         WITH f: DialogFrames.Frame DO
  113.             yh := f.Y + f.H + y; xh := f.X + x; 
  114.             IF yh < f.Y THEN h1 := h - f.Y + yh ELSE h1 := h END;
  115.             IF (yh + h <= f.Y) OR (yh >= f.Y + f.H) OR (xh + w <= f.X) OR (xh >= f.X + f.W) OR (h1 < minH) THEN RETURN END;
  116.             IF (f.X <= t.f.X) & (f.X + f.W >= t.f.X) & (f.Y <= t.f.Y) & (f.Y + f.H >= t.f.Y) THEN
  117.                 IF msg IS TextFrames.UpdateMsg THEN 
  118.                     IF msg(TextFrames.UpdateMsg).text = t.f.text THEN 
  119.                         t.f.handle (t.f, msg); msg2.x := f.X; msg2.y := f.Y; Viewers.Broadcast (msg2);
  120.                         IF (f.X > t.f.X) OR (f.X + f.W < t.f.X) OR (f.Y > t.f.Y) OR (f.Y + f.H < t.f.Y) THEN
  121.                             t.Draw (f.X + x, f.Y + f.H + y, f)
  122.                         END;
  123.                         IF t.cmd[0] # 0X THEN 
  124.                             GetParText (t.par, t.panel, t1);
  125.                             t.CallCmd (f, Viewers.This (xh, yh), t1) 
  126.                         END
  127.                     END
  128.                 ELSIF msg IS MenuViewers.ModifyMsg THEN
  129.                     IF msg(MenuViewers.ModifyMsg).id = MenuViewers.reduce THEN t.Restore END 
  130.                 ELSE 
  131.                     t.f.handle (t.f, msg); 
  132.                 END;
  133.             ELSE 
  134.                 cond := FALSE; 
  135.                 WITH msg: Oberon.InputMsg DO 
  136.                     IF (msg.id = Oberon.track) & 
  137.                         (msg.X >= xh) & (msg.X <= xh + w) & (msg.Y >= yh) & (msg.Y <= yh+ h) & (msg. keys # {}) THEN cond := TRUE; 
  138.                     END;
  139.                     IF msg.id = Oberon.defocus THEN cond := TRUE END
  140.                 | msg: ChangeMsg DO
  141.                      t.Draw (f.X + x, f.Y + f.H + y, f) 
  142.                 ELSE  
  143.                 END;
  144.                 IF cond THEN 
  145.                     TextFrames.RemoveCaret (t.f); t.Draw (f.X + x, f.Y + f.H + y, f); t.f.handle (t.f, msg) 
  146.                 END
  147.             END
  148.         ELSE
  149.         END; 
  150.     END Handle;
  151.     PROCEDURE (t: Item) Init*;
  152.     (** initialies the object, should be called after allocating the object with NEW *)
  153.         VAR h: Texts.Text;
  154.     BEGIN t.Init^; h := TextFrames.Text (""); t.f := TextFrames.NewText (h, 0);
  155.     END Init;
  156.     PROCEDURE Insert*;
  157.     (** Insert ([name] [x y w h] | ^ ) inserts a text - item in the panel containing the caret position *)
  158.         VAR x, y, x1, y1, w, h: INTEGER; t: Item; p: Dialogs.Panel; name: ARRAY 64 OF CHAR;
  159.     BEGIN
  160.         NEW (t);
  161.         DialogFrames.GetCaretPosition (p, x, y);
  162.         IF (p # NIL) THEN     
  163.             t.Init; In.Open; In.Name (name);
  164.             IF ~In.Done THEN COPY ("", name); In.Open END;
  165.             t.SetName (name); 
  166.             In.Int (x1); In.Int (y1); In.Int (w); In.Int (h);
  167.             IF ~In.Done THEN x1 := x; y1 := y; w := W; h := H 
  168.             ELSE
  169.                 IF w < 0 THEN w := W END;
  170.                 IF h < 0 THEN h := H END
  171.             END;
  172.             t.SetDim (x1, y1, w, h, FALSE); p.Insert (t, FALSE) 
  173.         ELSE
  174.             Dialogs.res := Dialogs.noPanelSelected
  175.         END;
  176.         IF Dialogs.res # 0 THEN Dialogs.Error ("DialogTexts") END;
  177.     END Insert;
  178.     PROCEDURE WriteToObjectInt (o: Dialogs.Object; VAR p: Dialogs.Panel; x: INTEGER);
  179.         VAR t: Texts.Text;
  180.     BEGIN
  181.         WITH o: Item DO
  182.             t := o.GetText (); Texts.WriteInt (w0, x, 1); Texts.Append (t, w0.buf);
  183.         END
  184.     END WriteToObjectInt;
  185.     PROCEDURE WriteToObjectStr (o: Dialogs.Object; VAR p: Dialogs.Panel; n: ARRAY OF CHAR);
  186.         VAR t: Texts.Text; ch: CHAR;
  187.     BEGIN
  188.         IF n[0] = 0X THEN RETURN END;
  189.         WITH o: Item DO
  190.             ch := CHR (34);   (* " *) 
  191.             IF (ORD (CAP(n[0])) < ORD ("A")) OR (ORD (CAP(n[0])) > ORD ("Z")) THEN Texts.Write (w0, ch) END;
  192.             t := o.GetText (); Texts.WriteString (w0, n); 
  193.             IF (ORD (CAP(n[0])) < ORD ("A")) OR (ORD (CAP(n[0])) > ORD ("Z")) THEN Texts.Write (w0, ch) END;
  194.             Texts.Append (t, w0.buf);
  195.         END
  196.     END WriteToObjectStr;
  197.     PROCEDURE Edit (o: Dialogs.Object);
  198.         VAR
  199.             x, y, nx, ny, nw, nh: INTEGER; nn, nc, np: ARRAY 64 OF CHAR;
  200.             ox, oy, ow, oh, on, oc, op: Dialogs.Object; deInit: Dialogs.Panel;
  201.             msg: DialogFrames.GetFrameMsg; file: Files.File; r: Files.Rider; type: Types.Type;
  202.             m: TextFrames.Frame; v: Viewers.Viewer; df: DialogFrames.Frame; t: Texts.Text;
  203.     BEGIN
  204.         Oberon.AllocateSystemViewer (Oberon.Mouse.X, x, y);
  205.         msg.p := Dialogs.editPanel; msg.f := NIL; Viewers.Broadcast (msg);
  206.         IF msg.f = NIL THEN
  207.             NEW (df); deInit := Dialogs.deInit.Copy (); 
  208.             df.Open (DialogFrames.Handle, deInit); 
  209.             Oberon.AllocateSystemViewer (Oberon.Mouse.X, x, y);
  210.             type := Types.TypeOf (o);
  211.             m := TextFrames.NewMenu (type.module.name, editMenu);
  212.             v := MenuViewers.New (m, df, TextFrames.menuH, x, y);
  213.         ELSE
  214.             deInit := Dialogs.deInit.Copy (); msg.f.panel := deInit; deInit.Restore;
  215.         END;
  216.         ox := deInit.NamedObject ("x");  oy := deInit.NamedObject ("y");
  217.         ow := deInit.NamedObject ("w"); oh := deInit.NamedObject ("h");
  218.         on := deInit.NamedObject ("name"); oc := deInit.NamedObject ("cmd");
  219.         op := deInit.NamedObject ("par");
  220.         o.GetDim (nx, ny, nw, nh); COPY (o.name, nn); COPY (o.cmd, nc); COPY (o.par, np);
  221.         WriteToObjectInt (ox,  deInit, nx); WriteToObjectInt (oy, deInit, ny);
  222.         WriteToObjectInt (ow, deInit, nw); WriteToObjectInt (oh, deInit, nh);
  223.         WriteToObjectStr (on, deInit, nn); WriteToObjectStr (oc, deInit, nc);
  224.         t := op(Item).GetText (); Texts.WriteString (w0, np); Texts.Append (t, w0.buf);
  225.         Dialogs.editPanel := deInit; Dialogs.editObject := o;
  226.     END Edit;
  227.     PROCEDURE Update (o: Dialogs.Object; deInit: Dialogs.Panel);
  228.         VAR 
  229.             o1: Dialogs.Object; st: ARRAY 64 OF CHAR;
  230.             ax, ay, aw, ah, nx, ny, nw, nh, res, res1, res2, res3, res4: INTEGER;
  231.         PROCEDURE ReadInt (o: Dialogs.Object; VAR x, res: INTEGER);
  232.             VAR s: Texts.Scanner; t: Texts.Text;
  233.         BEGIN
  234.             WITH o: Item DO 
  235.                 t := o.GetText (); Texts.OpenScanner (s, t, 0); Texts.Scan (s);
  236.                 IF (s.class = Texts.Int) THEN x := SHORT (s.i); res := Dialogs.ok ELSE res := Dialogs.wrongInput END
  237.             ELSE
  238.             END;
  239.         END ReadInt;
  240.         PROCEDURE ReadName (o: Dialogs.Object; VAR st: ARRAY OF CHAR ; VAR res: INTEGER);
  241.             VAR s: Texts.Scanner; t: Texts.Text; i: INTEGER;
  242.         BEGIN
  243.             WITH o: Item DO 
  244.                 t := o.GetText (); Texts.OpenScanner (s, t, 0); Texts.Scan (s);
  245.                 IF (s.class = Texts.Name) OR (s.class = Texts.String) THEN COPY (s.s, st); res := Dialogs.ok 
  246.                 ELSE res := Dialogs.wrongInput END
  247.             ELSE
  248.             END;
  249.         END ReadName;
  250.         PROCEDURE ReadPar (o: Dialogs.Object; VAR st: ARRAY OF CHAR; VAR res: INTEGER);
  251.             VAR r: Texts.Reader; t: Texts.Text; i: INTEGER; ch: CHAR;
  252.         BEGIN
  253.             WITH o: Item DO
  254.                 t := o.GetText (); Texts.OpenReader (r, t, 0); Texts.Read (r, ch); i := 0; res := Dialogs.ok;
  255.                 WHILE ~r.eot DO
  256.                     st[i] := ch; INC (i); Texts.Read (r, ch)
  257.                 END;
  258.                 st[i] := 0X
  259.             ELSE
  260.             END
  261.         END ReadPar;
  262.     BEGIN
  263.         o1 := deInit.NamedObject ("name"); ReadName (o1, st, res1);
  264.         IF res1 = Dialogs.ok THEN o.SetName (st); ELSE o.SetName ("") END;
  265.         IF Dialogs.res # Dialogs.ok THEN Dialogs.Error ("Dialog") END;
  266.         o1 := deInit.NamedObject ("cmd"); ReadName (o1, st, res1);
  267.         IF res1 = Dialogs.ok THEN o.SetCmd (st) ELSE o.SetCmd ("") END;
  268.         o1 := deInit.NamedObject ("par"); ReadPar (o1, st, res1);
  269.         IF res1 = Dialogs.ok THEN o.SetPar (st) ELSE o.SetPar ("") END;
  270.         o1 := deInit.NamedObject ("x"); ReadInt (o1, nx, res1);
  271.         o1 := deInit.NamedObject ("y"); ReadInt (o1, ny, res2);
  272.         o1 := deInit.NamedObject ("w"); ReadInt (o1, nw, res3);
  273.         o1 := deInit.NamedObject ("h"); ReadInt (o1, nh, res4);
  274.         IF (res1 # Dialogs.ok) OR (res2 # Dialogs.ok) OR (res3 # Dialogs.ok) OR (res4 # Dialogs.ok) THEN 
  275.             Dialogs.res := Dialogs.wrongInput; Dialogs.Error ("Dialog"); 
  276.         ELSE
  277.             o.GetDim (ax, ay, aw, ah); 
  278.             IF (ax # nx) OR (ay # ny) OR (aw # nw) OR (ah # nh) THEN
  279.                 o.SetDim (nx, ny, nw, nh, o.overlapping);
  280.                 IF Dialogs.res # Dialogs.ok THEN Dialogs.Error ("Dialog") END
  281.             END
  282.         END
  283.     END Update;
  284. BEGIN Texts.OpenWriter (w0); Dialogs.Edit := Edit; Dialogs.Update := Update; GetParText := ParText
  285. END DialogTexts.
  286.