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

  1. Syntax10.Scn.Fnt
  2. Syntax10i.Scn.Fnt
  3. StampElems
  4. Alloc
  5. 30 Dec 95
  6. Syntax10b.Scn.Fnt
  7. MODULE DialogKeplers; (* based on KeplerElems by J.Templ 27.09.93 *)
  8.     (** Markus Knasm
  9. ller 31 Oct 94 - 
  10.     IMPORT DialogFrames, Dialogs, DialogTexts, Display, Files, In, KeplerGraphs, KeplerFrames, KeplerPorts, MenuViewers, 
  11.         Oberon, TextFrames, TextPrinter, Texts, Viewers;
  12.     CONST 
  13.         MM = 1; ML = 0; MR = 2;
  14.         menu = "System.Close  System.Copy  System.Grow  DialogKeplers.Update ";
  15.         dUnit = TextFrames.Unit; pUnit = TextPrinter.Unit;
  16.         W* = 100; H* = 100; 
  17.     TYPE
  18.         Item* = POINTER TO ItemDesc;
  19.         ItemDesc* = RECORD(Dialogs.ObjectDesc)
  20.             graph*: KeplerGraphs.Graph;
  21.             dx, dy, grid: INTEGER;
  22.         END;
  23.         Frame = POINTER TO FrameDesc;
  24.         FrameDesc = RECORD (KeplerFrames.FrameDesc)
  25.             elem: Item
  26.         END;
  27.     PROCEDURE Max (x, y: INTEGER): INTEGER;
  28.     BEGIN IF x > y THEN RETURN x ELSE RETURN y END
  29.     END Max;
  30.     PROCEDURE CopyGraph (g: KeplerGraphs.Graph): KeplerGraphs.Graph;
  31.         VAR buf: Files.File; R: Files.Rider; o: KeplerGraphs.Object;
  32.     BEGIN
  33.         buf := Files.New ("");
  34.         Files.Set (R, buf, 0); KeplerGraphs.Reset;
  35.         KeplerGraphs.WriteObj (R, g);
  36.         Files.Set (R, buf, 0); KeplerGraphs.Reset;
  37.         KeplerGraphs.ReadObj (R, o);
  38.         RETURN o(KeplerGraphs.Graph)
  39.     END CopyGraph;
  40.     PROCEDURE (g: Item) Draw* (x, y: INTEGER; f: Display.Frame);
  41.     (** displays the object at (x, y) in frame f *)
  42.         VAR x0, y0, w, h, mode, col: INTEGER; f1: KeplerFrames.Frame;
  43.     BEGIN
  44.         g.GetDim (x0, y0, w, h); col := f(DialogFrames.Frame).col;
  45.         IF g.selected THEN mode := Display.invert ELSE mode := Display.replace END;
  46.         IF (g.graph = NIL) OR (x < f.X) OR (y < f.Y) OR (x + w > f.X + f.W) OR (y + h > f.Y + f.H) THEN
  47.             Display.ReplPatternC (f, Display.white, Display.grey1, x, y, w, h, 0, 0, mode)
  48.         ELSE
  49.             f1 := KeplerFrames.New (g.graph); f := f1; 
  50.             f1.X := x; f1.Y := y; f1.W := w; f1.H := h; 
  51.             f1.x0 := - g.dx; f1.y0 := - (f1.H * 4 + g.dy); f1.scale := 4;
  52.             IF g.graph.cons # NIL THEN g.graph.Draw (f1) ELSE f1.DrawRect (0, 0, 99, 99, col, mode) END
  53.         END
  54.     END Draw;
  55.     PROCEDURE (g: Item) Print* (x, y: INTEGER);
  56.     (** prints the object at printer coordinates (x, y) *)
  57.         VAR x0, y0, w, h: INTEGER; p: KeplerPorts.PrinterPort;
  58.     BEGIN
  59.         g.GetPDim (x0, y0, w, h);
  60.         NEW (p);
  61.         p.X := x; p.Y := y; p.W := 4 * w; p.H := 4  * h;
  62.         p.x0 := - g.dx; p.y0 := - (p.H + g.dy); p.scale := 1;
  63.         g.graph.Draw (p)
  64.     END Print;
  65.     PROCEDURE (g: Item) Copy* (VAR dup: Dialogs.Object);
  66.     (** allocates dup and makes a deep copy of o. Before calling this methode dup should be equal NIL *)
  67.         VAR x: Item; 
  68.     BEGIN
  69.         IF dup = NIL THEN NEW (x); dup := x ELSE x := dup(Item) END; 
  70.         g.Copy^ (dup); x.graph := CopyGraph (g.graph); x.dx := g.dx; x.dy := g.dy; x.grid := g.grid
  71.     END Copy;
  72.     PROCEDURE (g: Item) Load* (VAR r: Files.Rider);
  73.     (** reads the object from rider r *)
  74.         VAR o: KeplerGraphs.Object;
  75.     BEGIN 
  76.         g.Load^ (r); Files.ReadInt (r, g.dx); Files.ReadInt (r, g.dy);
  77.         Files.ReadInt (r, g.grid);
  78.         KeplerGraphs.Reset; KeplerGraphs.ReadObj (r, o); g.graph := o(KeplerGraphs.Graph)
  79.     END Load;
  80.     PROCEDURE (g: Item) Store* (VAR r: Files.Rider);
  81.     (** writes the object to rider r *)
  82.     BEGIN 
  83.         g.Store^ (r); Files.WriteInt (r, g.dx); Files.WriteInt (r, g.dy);
  84.         Files.WriteInt (r, g.grid);
  85.         KeplerGraphs.Reset; KeplerGraphs.WriteObj (r, g.graph)
  86.     END Store;
  87.     PROCEDURE (g: Item) Handle* (f: Display.Frame; VAR m: Display.FrameMsg);
  88.     (** handles messages which were sent to frame f *)
  89.         VAR t: Texts.Text;
  90.     BEGIN
  91.         g.Handle^ (f, m);
  92.         WITH f: DialogFrames.Frame DO
  93.             WITH m: Oberon.InputMsg DO
  94.                 IF (m.id = Oberon.track) THEN
  95.                     IF ((m.keys = {MM}) OR (m.keys = {MR}) OR (m.keys = {ML})) & (g.cmd[0] # 0X) THEN 
  96.                         DialogTexts.GetParText (g.par, g.panel, t);
  97.                         g.CallCmd (f, Viewers.This (m.X, m.Y), t) 
  98.                     ELSE Oberon.DrawCursor (Oberon.Mouse, Oberon.Arrow, m.X, m.Y)
  99.                     END
  100.                 END
  101.             ELSE
  102.             END
  103.         ELSE
  104.         END
  105.     END Handle;
  106.     PROCEDURE HandleFrame (f0: Display.Frame; VAR msg: Display.FrameMsg);
  107.         VAR f: Frame;
  108.     BEGIN
  109.         WITH f0: Frame DO
  110.             WITH msg: Oberon.CopyMsg DO
  111.                 NEW (f); msg.F := f; f^ := f0^
  112.             ELSE KeplerFrames.Handle (f0, msg)
  113.             END
  114.         END
  115.     END HandleFrame;
  116.     PROCEDURE (g: Item) Edit* ();
  117.     (** opens a graphic frame for editing the properties of the object *)
  118.         VAR v: Viewers.Viewer; f: Frame; x, y: INTEGER;
  119.     BEGIN
  120.         NEW (f); f.G := CopyGraph (g.graph); f.G.notify := KeplerFrames.NotifyDisplay;
  121.         f.handle := HandleFrame; f.grid := g.grid; f.scale := 4; f.x0 := 0; f.y0 := 0; f.elem := g;
  122.         Oberon.AllocateSystemViewer (Oberon.Mouse.X, x, y);
  123.         v := MenuViewers.New (TextFrames.NewMenu ("DialogKeplers.Graph", menu), f, TextFrames.menuH, x, y)
  124.     END Edit; 
  125.     PROCEDURE (g: Item) Open;
  126.         VAR b: KeplerPorts.BalloonPort; x, y, w, h: INTEGER;
  127.     BEGIN
  128.         NEW (b); KeplerPorts.InitBalloon (b);
  129.         g.graph.Draw (b); (* get bounding box *)
  130.         g.GetDim (x, y, w, h);
  131.         g.dx := b.X; g.dy := b.Y; w := Max (w, b.W DIV 4); h := Max (h, b.H DIV 4);
  132.         g.SetDim (x, y, w, h, g.overlapping)
  133.     END Open;
  134.     PROCEDURE Insert*;   
  135.     (** Insert (name | ^ ) inserts a graphic - item in the panel containing the caret position *)
  136.         VAR w, h, x, y, xh, yh: INTEGER; g: Item; p: Dialogs.Panel; name: ARRAY 64 OF CHAR;
  137.             graph: KeplerGraphs.Graph;
  138.     BEGIN 
  139.         NEW (g); 
  140.         DialogFrames.GetCaretPosition (p, x, y);
  141.         IF (p # NIL) THEN
  142.             g.Init; In.Open; In.Name (name);
  143.             IF ~In.Done THEN COPY ("", name); In.Open END;
  144.             g.SetName (name); 
  145.             graph := KeplerGraphs.Old (name);
  146.             IF graph = NIL THEN NEW (graph) END;
  147.             g.graph := graph; 
  148.             In.Int (xh); In.Int (yh); In.Int (w); In.Int (h);
  149.             IF In.Done THEN 
  150.                 x := xh; y := yh
  151.             ELSE
  152.                 w := W; h := H
  153.             END;
  154.             g.SetDim (x, y, w, h, FALSE); 
  155.             g.Open;
  156.             p.Insert (g, FALSE) 
  157.         ELSE
  158.             Dialogs.res := Dialogs.noPanelSelected
  159.         END;
  160.         IF Dialogs.res # 0 THEN Dialogs.Error ("DialogKeplers") END;
  161.     END Insert;
  162.     PROCEDURE Update*;
  163.         VAR v: Viewers.Viewer; f: Frame; g: KeplerGraphs.Graph;
  164.     BEGIN
  165.         v := Oberon.Par.vwr; f := v.dsc.next(Frame); 
  166.         g := f.G; g.All (0); (* deselect *) 
  167.         f.elem.graph := CopyGraph (f.G); f.elem.grid := f.grid;
  168.         f.elem.Open; f.elem.Restore; f.elem.panel.MarkMenu;
  169.     END Update;
  170. END DialogKeplers.
  171.