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

  1. Syntax10.Scn.Fnt
  2. Syntax10i.Scn.Fnt
  3. StampElems
  4. Alloc
  5. 3 May 95
  6. Syntax10b.Scn.Fnt
  7. Chicago10.Scn.Fnt
  8. MODULE DialogStaticTexts;
  9.     (** Markus Knasm
  10. ller 22.Jun.94 - 
  11.     IMPORT DialogFrames, Dialogs, DialogTexts, Display, Display1, Files, Fonts, GraphicUtils, In, Oberon, TextFrames, Texts, Viewers;
  12.     CONST MM = 1; W* = 40; H* = 20; CR = 0DX; black = 15;
  13.     TYPE
  14.         Item* = POINTER TO ItemDesc;
  15.         ItemDesc* = RECORD(Dialogs.ObjectDesc)
  16.             fnt-: Fonts.Font;   (** the font with which the text is shown *)
  17.             s-: ARRAY 64 OF CHAR;  (** the text which is shown *) 
  18.             a-: INTEGER; (** alignment 0 = left 1 = center 2 = right see GraphicUtils *)
  19.         END;
  20.     VAR w0: Texts.Writer;
  21.     PROCEDURE (t: Item) Draw* (x, y: INTEGER; f: Display.Frame);
  22.     (** displays the object at (x, y) in frame f *)
  23.         VAR ox, oy, w, h, yh, cx, mode: INTEGER;
  24.     BEGIN
  25.         t.GetDim (ox, oy, w, h); 
  26.         IF t.selected THEN 
  27.             mode := Display.invert;
  28.             Display1.Line (f, black, x, y, x, y + h - 1, mode);
  29.             Display1.Line (f, black, x, y, x + w - 1, y, mode);
  30.             Display1.Line (f, black, x + w - 1, y, x + w - 1, y + h - 1, mode);
  31.             Display1.Line (f, black, x, y + h - 1, x + w - 1, y + h - 1, mode) 
  32.         ELSE 
  33.             mode := Display.paint 
  34.         END;
  35.         yh := y + (h DIV 2) - ((t.fnt.minY + t.fnt.maxY) DIV 2);
  36.         IF h - (yh - y) > t.fnt.maxY THEN GraphicUtils.DrawString (f, t.s, x+ 3, yh, w - 4, t.fnt, mode, t.a, cx) END;
  37.     END Draw;
  38.     PROCEDURE (t: Item) Copy* (VAR dup: Dialogs.Object);
  39.     (** allocates dup and makes a deep copy of o. Before calling this methode dup should be equal NIL *)
  40.         VAR x: Item;
  41.     BEGIN
  42.         IF dup = NIL THEN NEW (x); dup := x ELSE x := dup(Item) END; 
  43.         t.Copy^ (dup); x.fnt := t.fnt; COPY (t.s, x.s); x.a := t.a
  44.     END Copy;
  45.     PROCEDURE (t: Item) Load* (VAR r: Files.Rider);
  46.     (** reads the object from rider r *)
  47.         VAR fntname: ARRAY 32 OF CHAR; ch: CHAR; pos: LONGINT;
  48.     BEGIN 
  49.         t.Load^ (r); pos := Files.Pos (r); Files.Read (r, ch);
  50.         IF ch = 1X THEN (* new version *)
  51.             Files.ReadInt (r, t.a);
  52.         ELSE
  53.             Files.Set (r, Files.Base (r), pos); t.a := GraphicUtils.center
  54.         END;
  55.         Files.ReadString (r, fntname); t.fnt := Fonts.This (fntname); Files.ReadString (r, t.s)
  56.     END Load;
  57.     PROCEDURE (t: Item) Store* (VAR r: Files.Rider);
  58.     (** writes the object to rider r *)
  59.     BEGIN t.Store^ (r); Files.Write (r, 1X); Files.WriteInt (r, t.a); Files.WriteString (r, t.fnt.name); Files.WriteString (r, t.s);
  60.     END Store;
  61.     PROCEDURE (t: Item) Print* (x, y: INTEGER);
  62.     (** prints the object at printer coordinates (x, y) *)
  63.         VAR w, h, ox, oy, yh, cx: INTEGER;
  64.     BEGIN
  65.         t.GetPDim (ox, oy, w, h);
  66.         cx := (t.fnt.minY + t.fnt.maxY) DIV 2; cx := SHORT (cx * Dialogs.dUnit DIV Dialogs.pUnit);
  67.         yh := y + (h DIV 2) - cx;
  68.         IF h - (yh - y) > t.fnt.maxY THEN GraphicUtils.PrintString (t.s, x + 3, yh, w- 4, t.fnt, t.a, cx) END
  69.     END Print;
  70.     PROCEDURE (t: Item) SetFont* (fnt: Fonts.Font);
  71.     (** sets the font with which the text is shown *)
  72.     BEGIN t.Hide; t.fnt := fnt; t.Restore; IF t.panel # NIL THEN t.panel.MarkMenu END
  73.     END SetFont;
  74.     PROCEDURE (t: Item) SetString* (s: ARRAY OF CHAR);
  75.     (** sets the text which is shown *)
  76.     BEGIN t.Hide; COPY (s, t.s); t.Restore; IF t.panel # NIL THEN t.panel.MarkMenu END
  77.     END SetString;
  78.     PROCEDURE (t: Item) SetAlign* (a: INTEGER);
  79.     (** sets the alignment of the string 0 = left 1 = center 2 = right *)
  80.     BEGIN t.Hide; t.a := a; t.Restore; IF t.panel # NIL THEN t.panel.MarkMenu END
  81.     END SetAlign;
  82.     PROCEDURE (t: Item) Handle* (f: Display.Frame; VAR m: Display.FrameMsg);
  83.     (** handles messages which were sent to frame f *)
  84.         VAR t1: Texts.Text;
  85.     BEGIN
  86.         t.Handle^ (f, m);
  87.         WITH f: DialogFrames.Frame DO 
  88.             WITH m: Oberon.InputMsg DO
  89.                 IF m.id = Oberon.track THEN
  90.                     IF (m.keys = {MM}) & (t.cmd[0] # 0X) THEN 
  91.                         DialogTexts.GetParText (t.par, t.panel, t1);
  92.                         t.CallCmd (f, Viewers.This (m.X, m.Y), t1) 
  93.                     ELSE Oberon.DrawCursor (Oberon.Mouse, Oberon.Arrow, m.X, m.Y)
  94.                     END
  95.                 END
  96.             ELSE
  97.             END
  98.         ELSE
  99.         END
  100.     END Handle;
  101.     PROCEDURE WriteToObjectStr (o: DialogTexts.Item; n: ARRAY OF CHAR);
  102.         VAR t: Texts.Text; 
  103.     BEGIN
  104.         t := o.GetText (); Texts.WriteString (w0, n); Texts.Append (t, w0.buf);
  105.     END WriteToObjectStr;
  106.     PROCEDURE WriteToObjectInt (o: DialogTexts.Item; n: INTEGER);
  107.         VAR t: Texts.Text;
  108.     BEGIN
  109.         t := o.GetText (); Texts.WriteInt (w0, n, 0); Texts.Append (t, w0.buf);
  110.     END WriteToObjectInt;
  111.     PROCEDURE (t: Item) Edit*;
  112.     (** opens a dialog for editing the properties of the object *)
  113.         VAR 
  114.             on: Dialogs.Object; os, string, align: DialogTexts.Item; s: Item; p: Dialogs.Panel; 
  115.             t1: Texts.Text; fnt: Fonts.Font; st: ARRAY 16 OF CHAR;
  116.     BEGIN
  117.         t.Edit^ (); p := Dialogs.editPanel;
  118.         NEW (string); string.Init; 
  119.         string.SetName ("string"); string.SetDim (245, -30, 140, 19, FALSE); p.Insert (string, FALSE); 
  120.         (* ---- *)  ASSERT (Dialogs.res = Dialogs.ok);
  121.         NEW (s); s.Init; s.SetDim (196, -30, 40, 20, FALSE); 
  122.         s.SetString ("String"); fnt := Fonts.This ("Syntax10.Scn.Fnt"); s.SetFont (fnt);
  123.         p.Insert (s, FALSE); 
  124.         (* ---- *)  ASSERT (Dialogs.res = Dialogs.ok);
  125.         NEW (s); s.Init; s.SetDim (2, - 176, 35, 20, FALSE);
  126.         s.SetString ("Align"); fnt := Fonts.This ("Syntax10.Scn.Fnt"); s.SetFont (fnt);
  127.         p.Insert (s, FALSE);
  128.         (* ---- *)  ASSERT (Dialogs.res = Dialogs.ok);
  129.         NEW (align); align.Init; 
  130.         align.SetName ("align"); align.SetDim (38, - 176, 40, 19, FALSE); p.Insert (align, FALSE); 
  131.         (* ---- *)  ASSERT (Dialogs.res = Dialogs.ok);
  132.         WriteToObjectStr (string, t.s); 
  133.         t1 := string.GetText (); Texts.ChangeLooks (t1, 0, t1.len, {0}, t.fnt, 0, 0);
  134.         IF t.a = 0 THEN COPY ("left", st);
  135.         ELSIF t.a = 1 THEN COPY ("center", st);
  136.         ELSE COPY ("right", st)
  137.         END;
  138.         WriteToObjectStr (align, st);
  139.     END Edit;
  140.     PROCEDURE (t: Item) Update* (p: Dialogs.Panel);
  141.     (** sets the properties of the object to the values defined in the dialog p opened with Edit *)
  142.         VAR os: Dialogs.Object; t1: Texts.Text; r: Texts.Reader; ch: CHAR; str: ARRAY 64 OF CHAR; i: INTEGER; s: Texts.Scanner;
  143.     BEGIN
  144.         t.Update^ (p); 
  145.         os := p.NamedObject ("string"); t1 := os(DialogTexts.Item).GetText ();
  146.         Texts.OpenReader (r, t1, 0); Texts.Read (r, ch); i := 0;
  147.         IF (r.fnt # NIL) & (r.fnt # t.fnt) THEN t.SetFont (r.fnt) END;
  148.         WHILE ~ r.eot DO 
  149.              str[i] := ch; INC (i); Texts.Read (r, ch);
  150.         END;
  151.         str[i] := 0X; 
  152.         IF str # t.s THEN t.SetString (str) END;
  153.         os := p.NamedObject ("align"); t1 := os(DialogTexts.Item).GetText ();
  154.         Texts.OpenScanner (s, t1, 0); Texts.Scan (s);
  155.         IF s.class = Texts.Int THEN i := SHORT (s.i) 
  156.         ELSIF s.class = Texts.Name THEN
  157.             IF s.s[0] = "l" THEN i := GraphicUtils.left
  158.             ELSIF s.s[0] = "c" THEN i := GraphicUtils.center
  159.             ELSE i := GraphicUtils.right
  160.             END
  161.         ELSE i := GraphicUtils.center END;
  162.         IF i # t.a THEN t.a := i; t.Hide; t.Restore END
  163.     END Update;
  164.     PROCEDURE Insert*;
  165.     (** Insert ([name] [x y w h] | ^ ) inserts a static text - item in the panel containing the caret position *)
  166.         VAR x, y, x1, y1, w, h: INTEGER; t: Item; p: Dialogs.Panel; name: ARRAY 64 OF CHAR; r: Texts.Reader; ch: CHAR;
  167.     BEGIN 
  168.         NEW (t);  
  169.         DialogFrames.GetCaretPosition(p, x, y);
  170.         IF (p # NIL) THEN 
  171.             t.Init; t.fnt := Fonts.This ("Syntax10.Scn.Fnt"); 
  172.             In.Open; Texts.OpenReader (r, Oberon.Par.text, 0); Texts.Read (r, ch);
  173.             In.Name (name);
  174.             IF ~In.Done THEN COPY ("", name); In.Open ELSE t.fnt := r.fnt END;
  175.             COPY (name, t.s); t.SetName (name); 
  176.             In.Int (x1); In.Int (y1); In.Int (w); In.Int (h);
  177.             IF ~In.Done THEN x1 := x; y1 := y; w := W; h := H 
  178.             ELSE
  179.                 IF w < 0 THEN w := W END;
  180.                 IF h < 0 THEN h := H END
  181.             END;
  182.             y := GraphicUtils.GetStringLength (name, t.fnt) + 5;
  183.             IF y > w THEN x := w; w := y END;
  184.             t.SetDim (x1, y1, w, h, FALSE); t.a := GraphicUtils.center; p.Insert (t, FALSE);
  185.             IF Dialogs.res = Dialogs.objectWouldOverlap THEN 
  186.                 t.SetDim (x1, y1, y, h, FALSE); p.Insert (t, FALSE)
  187.             END
  188.         ELSE
  189.             Dialogs.res := Dialogs.noPanelSelected 
  190.         END;
  191.         IF Dialogs.res # 0 THEN Dialogs.Error ("DialogStaticTexts") END;
  192.     END Insert;
  193.     PROCEDURE SetString*;
  194.     (** SetString ({ch} | ^) sets the string of the static text item at the caret to str *)
  195.         VAR o: Dialogs.Object; p: Dialogs.Panel; str: ARRAY 64 OF CHAR; ch: CHAR; i: INTEGER;
  196.     BEGIN 
  197.         In.Open; In.Char (ch); i := 0;
  198.         WHILE In.Done & (ch = " ") DO In.Char (ch) END; (* skip leading blanks *)
  199.         IF ~ In.Done THEN 
  200.             Dialogs.res := Dialogs.wrongInput
  201.         ELSE 
  202.             WHILE In.Done & (ch # CR) & (ch # "~") & (i < 63) DO str[i] := ch; INC (i); In.Char (ch) END; 
  203.             str[i] := 0X;
  204.             DialogFrames.FindObject (o, p);
  205.             IF (Dialogs.res = Dialogs.ok) & (o IS Item) THEN 
  206.                 o(Item).SetString (str); o(Item).SetFont (Fonts.This ("Syntax10.Scn.Fnt")) 
  207.             END 
  208.         END;
  209.         IF Dialogs.res # Dialogs.ok THEN Dialogs.Error ("DialogStaticTexts") END
  210.     END SetString;
  211.     PROCEDURE GetString*;
  212.     (** writes the component s of the static text item under the caret to the log viewer *)
  213.         VAR o: Dialogs.Object; p: Dialogs.Panel; str: ARRAY 64 OF CHAR;
  214.     BEGIN
  215.         DialogFrames.FindObject (o, p);
  216.         IF Dialogs.res = Dialogs.ok THEN
  217.             IF o IS Item THEN
  218.                 COPY (o(Item).s, str);
  219.                 Texts.WriteString (w0, "String:"); Texts.WriteString (w0, str); Texts.WriteLn (w0);
  220.                 Texts.Append (Oberon.Log, w0.buf)
  221.             ELSE
  222.                 Dialogs.res := Dialogs.objectNotFound
  223.             END
  224.         END;
  225.         IF Dialogs.res # Dialogs.ok THEN Dialogs.Error ("DialogStaticTexts") END
  226.     END GetString;
  227. BEGIN Texts.OpenWriter (w0)
  228. END DialogStaticTexts.
  229.