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

  1. Syntax10.Scn.Fnt
  2. Syntax10i.Scn.Fnt
  3. StampElems
  4. Alloc
  5. 2 Feb 95
  6. Syntax10b.Scn.Fnt
  7. MODULE DialogElems;  
  8.     (** Markus Knasm
  9. ller 22 Jul 94 -  
  10.     IMPORT Dialog, DialogFrames, Dialogs, Display, Files, Input, MenuViewers, Oberon, Printer, TextFrames, TextPrinter, Texts, Viewers;
  11.     CONST
  12.         mm = TextFrames.mm; scale = mm DIV 10;
  13.         minW = 3 * mm; minH = minW; gripW = 15 * scale DIV TextFrames.Unit; gripH = gripW;
  14.         MR = 0; MM = 1; ML = 2;
  15.         menu = "System.Close  System.Copy  System.Grow  DialogElems.Update ";
  16.     TYPE
  17.         Elem* = POINTER TO ElemDesc;
  18.         ElemDesc* = RECORD(Texts.ElemDesc)
  19.             dialog*: Dialogs.Panel;
  20.             xg*, yg*: INTEGER;
  21.             sw*, sh*: LONGINT;
  22.             empty*: BOOLEAN;
  23.         END;
  24.         Frame = POINTER TO FrameDesc;
  25.         FrameDesc = RECORD (DialogFrames.FrameDesc)
  26.             elem: Elem
  27.         END;
  28.         x0, x1, y0, y1: INTEGER;
  29.         w: Texts.Writer;
  30.         dUnit, pUnit: LONGINT;
  31.     PROCEDURE Changed* (e: Elem);
  32.         VAR t: Texts.Text; pos: LONGINT;
  33.     BEGIN t := Texts.ElemBase (e); pos := Texts.ElemPos (e); t.notify (t, Texts.replace, pos , pos + 1)
  34.     END Changed;
  35.     PROCEDURE FlipGrip (x0, y0, w, h: INTEGER);
  36.     BEGIN Display.ReplConst (Display.white, x0 + w - gripW, y0, gripW, gripH, Display.invert)
  37.     END FlipGrip; 
  38.     PROCEDURE SetSize* (e: Elem; w, h: LONGINT);
  39.     BEGIN 
  40.         IF w < minW THEN w := minW END;
  41.         IF h < minH THEN h := minH END;
  42.         e.W := w; e.H := h; e.sw := w; e.sh := h;
  43.     END SetSize;    
  44.     PROCEDURE box (obj: Dialogs.Object; VAR done: BOOLEAN);
  45.         VAR x, y, w, h: INTEGER;
  46.     BEGIN
  47.         obj.GetDim (x, y, w, h);  y := ABS (y); 
  48.         IF x < x0 THEN x0 := x END;
  49.         IF x1 < x + w THEN x1 := x + w END;
  50.         IF y - h < y0 THEN y0 := y - h END;
  51.         IF y1 < y THEN y1 := y END;
  52.     END box;
  53.     PROCEDURE Open* (e: Elem; p: Dialogs.Panel; xg, yg: INTEGER; adjust: BOOLEAN);
  54.     BEGIN
  55.         e.dialog := p;
  56.         x0 := MAX (INTEGER); x1 := MIN (INTEGER); y0 := MAX (INTEGER); y1 := MIN (INTEGER);
  57.         p.Enumerate (box);
  58.         IF x0 = MAX (INTEGER) THEN e.empty := TRUE; e.xg := 0; e.yg := 0; SetSize (e, 0, 0);
  59.         ELSE 
  60.             y1 := y1 + y0; x1 := x1 + x0; x0 := 0; y0 := 0;
  61.             e.empty := FALSE;
  62.             IF adjust THEN 
  63.                 e.xg := -x0; e.yg := - y1; SetSize (e, LONG (x1 - x0) * dUnit, LONG (y1 - y0) * dUnit)
  64.             ELSE
  65.                 e.xg := xg; e.yg := yg; SetSize (e, e.W, e.H)
  66.             END
  67.         END;
  68.     END Open;
  69.     PROCEDURE Copy* (se, de: Elem);
  70.     BEGIN
  71.         se.W := se.sw; se.H := se.sh;
  72.         Texts.CopyElem (se, de); Open (de, se.dialog.Copy (), se.xg, se.yg, FALSE)
  73.     END Copy;
  74.     PROCEDURE OpenViewer* (e: Elem);
  75.         VAR v: Viewers.Viewer; f: Frame; x, y: INTEGER;
  76.     BEGIN
  77.         NEW (f); f.Open (Dialog.Handle, e.dialog.Copy ()); f.col := 11; f.elem := e;    
  78.         Oberon.AllocateUserViewer (Oberon.Mouse.X, x, y);
  79.         v := MenuViewers.New (TextFrames.NewMenu ("DialogElems.Panel", menu), f, TextFrames.menuH, x, y)
  80.     END OpenViewer;
  81.     PROCEDURE Track (e: Elem; keys: SET; x, y, x0, y0: INTEGER);
  82.         VAR keysum: SET; x1, y1, w, h: INTEGER; hit: BOOLEAN;
  83.     BEGIN
  84.         IF MM IN keys THEN 
  85.             x1 := x - x0; y1 := y - y0; keysum := keys;
  86.             w := SHORT (e.W DIV dUnit); h := SHORT (e.H DIV dUnit);
  87.             hit := ~ e.empty & (x1 >= w - gripW) & (0 <= y1) & (y1 < gripH);
  88.             IF hit THEN FlipGrip (x0, y0, w, h) END;
  89.             REPEAT
  90.                 Input.Mouse (keys, x, y); Oberon.DrawCursor (Oberon.Mouse, Oberon.Arrow, x, y);
  91.                 keysum := keysum + keys
  92.             UNTIL keys = {};
  93.             IF hit THEN FlipGrip (x0, y0, w, h) END;
  94.             IF keysum = {MM} THEN
  95.                 IF hit THEN INC (w, (x - x0) -x1); DEC (h, (y - y0) - y1);
  96.                     SetSize (e, LONG (w) * dUnit, LONG (h) * dUnit); Changed (e)
  97.                 ELSE
  98.                     OpenViewer (e)
  99.                 END
  100.             END
  101.         END
  102.     END Track;
  103.     PROCEDURE Handle* (e: Texts.Elem; VAR msg: Texts.ElemMsg);
  104.         VAR e1: Elem; x, y, w, h, res: INTEGER; f: DialogFrames.Frame; p: Dialogs.Panel; 
  105.     BEGIN
  106.         WITH e: Elem DO
  107.             WITH msg: TextFrames.DisplayMsg DO
  108.                 IF msg.prepare THEN 
  109.                     e.W := e.sw; e.H := e.sh
  110.                 ELSE
  111.                     x := msg.X0; y := msg.Y0; w := SHORT (e.W DIV dUnit); h := SHORT (e.H DIV dUnit);
  112.                     IF e.empty THEN
  113.                         Display.ReplPattern (Display.white, Display.grey1, x, y, w, h, Display.replace)
  114.                     ELSE
  115.                         NEW (f); f.Open (DialogFrames.Handle, e.dialog);
  116.                         f.X := x; f.Y := y; f.W := w; f.H := h;
  117.                         f.Restore(); FlipGrip (x, y, w, h); 
  118.                         msg.elemFrame := f
  119.                     END
  120.                 END
  121.             | msg: TextPrinter.PrintMsg DO     
  122.                 IF msg.prepare THEN
  123.                     e.W := 4 *  (e.sw DIV dUnit) * pUnit;  e.H := 4 * (e.sh DIV dUnit) * pUnit
  124.                 ELSE
  125.                     e.dialog.Print (msg.X0, msg.Y0 + SHORT (e.H DIV pUnit));
  126.                     e.W := e.sw; e.H := e.sh;
  127.                 END
  128.             | msg: Texts.IdentifyMsg DO
  129.                 msg.mod := "DialogElems"; msg.proc := "Alloc" 
  130.             | msg: Texts.FileMsg DO 
  131.                 IF msg.id = Texts.load THEN
  132.                     NEW (p); p.Load (msg.r); Files.ReadInt (msg.r, e.xg); Files.ReadInt (msg.r, e.yg); Open (e, p, e.xg, e.yg, FALSE)
  133.                 ELSIF msg.id = Texts.store THEN
  134.                     e.W := e.sw; e.H := e.sh;
  135.                     e.dialog.Store (msg.r); Files.WriteInt (msg.r, e.xg); Files.WriteInt (msg.r, e.yg)
  136.                 END
  137.             | msg: Texts.CopyMsg DO 
  138.                 NEW (e1); Copy (e, e1); msg(Texts.CopyMsg).e := e1
  139.             | msg: TextFrames.TrackMsg DO
  140.                 Track (e, msg.keys, msg.X, msg.Y, msg.X0, msg.Y0) 
  141.             | msg: TextFrames.FocusMsg DO
  142.                 f := msg.elemFrame (DialogFrames.Frame); f.Restore ();
  143.                 IF msg.focus & (f.panel.cmd[0] # 0X) THEN 
  144.                     Dialogs.cmdPanel := f.panel; 
  145.                     Oberon.Call (f.panel.cmd, Oberon.Par, FALSE, res)
  146.                 END;
  147.                 IF ~ msg.focus THEN FlipGrip (f.X, f.Y, f.W, f.H) END
  148.             ELSE
  149.             END
  150.         ELSE
  151.         END
  152.     END Handle;
  153.     PROCEDURE Alloc*;
  154.         VAR e: Elem;
  155.     BEGIN NEW (e); e.handle := Handle; Texts.new := e;
  156.     END Alloc;
  157.     PROCEDURE Insert*;
  158.         VAR s: Texts.Scanner; text: Texts.Text; beg, end, time: LONGINT; v: Viewers.Viewer; p: Dialogs.Panel; e: Elem; 
  159.             msg: TextFrames.InsertElemMsg; file: Files.File; r: Files.Rider;
  160.     BEGIN
  161.         Texts.OpenScanner (s, Oberon.Par.text, Oberon.Par.pos); Texts.Scan (s);
  162.         IF (s.class = Texts.Char) & (s.c = "^") THEN
  163.             Oberon.GetSelection (text, beg, end, time);
  164.             IF time >= 0 THEN Texts.OpenScanner (s, text, beg); Texts.Scan (s) END
  165.         END;
  166.         NEW (p);
  167.         IF (s.class = Texts.Char) & (s.c = "*") THEN
  168.             v := Oberon.MarkedViewer ();
  169.             IF (v.dsc # NIL) & (v.dsc.next # NIL) & (v.dsc.next IS DialogFrames.Frame) THEN
  170.                 p := v.dsc.next (DialogFrames.Frame).panel.Copy()
  171.             END
  172.         ELSIF s.class = Texts.Name THEN 
  173.             file := Files.Old (s.s); 
  174.             IF file # NIL THEN Files.Set (r, file, 0); p.Load (r);  END
  175.         END;    
  176.         NEW (e); e.handle := Handle; Open (e, p, 0, 0, TRUE);
  177.         msg.e := e; Oberon.FocusViewer.handle (Oberon.FocusViewer, msg)
  178.     END Insert;
  179.     PROCEDURE Update*;
  180.         VAR v: Viewers.Viewer; f: Frame; r: Texts.Reader; t: Texts.Text; ch: CHAR;
  181.     BEGIN
  182.         v := Oberon.Par.vwr; f := v.dsc.next(Frame); t := v.dsc(TextFrames.Frame).text;
  183.         f.panel.RemoveSelections (); Open (f.elem, f.panel.Copy (), 0, 0, TRUE); Changed (f.elem);
  184.         Texts.OpenReader (r, t, t.len - 1); Texts.Read (r, ch);
  185.         IF ch = "!" THEN Texts.Delete (t, t.len - 1, t.len) END
  186.     END Update;
  187. BEGIN dUnit := Dialogs.dUnit; pUnit := Dialogs.pUnit
  188. END DialogElems.
  189.