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

  1. Syntax10.Scn.Fnt
  2. Syntax10i.Scn.Fnt
  3. StampElems
  4. Alloc
  5. 25 Apr 95
  6. Syntax10b.Scn.Fnt
  7. Chicago10.Scn.Fnt
  8. MODULE DialogButtons;
  9.     (** extended version Markus Knasm
  10. ller 25.May.94 -   
  11.     (* includes a change from: Zhukov Victor <VIC@edge.paragraph.com>   VIC
  12.         now it acts as a button in Windows, when you with mouse button
  13.         pressed move mouse out of Button rectangle it pops back and on
  14.         releasing does not issue associated action *)
  15.     IMPORT DialogFrames, Dialogs, DialogStaticTexts, DialogTexts, Display, Files, Fonts, GraphicUtils, In, Input, 
  16.         Oberon, TextFrames, Texts, Viewers;
  17.     CONST ML = 0; MM = 1; MR = 2;  W* = 30; H* = 20; grey1 = 12; grey2 = 13; grey3 = 14; black = 15; white = 0;
  18.     TYPE
  19.         Item* = POINTER TO ItemDesc;
  20.         ItemDesc* = RECORD(Dialogs.ObjectDesc)
  21.             fnt-: Fonts.Font;  (** font that is used to display the name of the button *)
  22.         END;
  23.     VAR w0: Texts.Writer;
  24.     PROCEDURE (b: Item) Copy* (VAR dup: Dialogs.Object);
  25.     (** allocates dup and makes a deep copy of o. Before calling this methode dup should be equal NIL *)
  26.         VAR x: Item;
  27.     BEGIN
  28.         IF dup = NIL THEN NEW (x); dup := x ELSE x := dup(Item) END; 
  29.         b.Copy^ (dup); x.fnt := b.fnt; 
  30.     END Copy;
  31.     PROCEDURE (b: Item) Draw1 (x, y: INTEGER; pressed: BOOLEAN; f: Display.Frame);
  32.         VAR mode, w, h, yh, ox, oy, cx: INTEGER; 
  33.     BEGIN
  34.         b.GetDim (ox, oy, w, h); 
  35.         IF b.selected THEN mode := Display.invert ELSE mode := Display.paint END;
  36.         GraphicUtils.DrawBox (f, pressed, x, y, w, h, mode);
  37.         yh := y + (h DIV 2) - ((b.fnt.minY + b.fnt.maxY) DIV 2);
  38.         IF h - (yh - y)  > b.fnt.maxY THEN 
  39.             GraphicUtils.DrawString (f, b.name, x + 3, yh, w - 4, b.fnt, mode, GraphicUtils.center, cx) 
  40.         END
  41.     END Draw1;
  42.     PROCEDURE (b: Item) Draw* (x, y: INTEGER; f: Display.Frame);
  43.     (** displays the object at (x, y) in frame f *)
  44.     BEGIN b.Draw1 (x, y, FALSE, f)    
  45.     END Draw;
  46.     PROCEDURE (b: Item) Print* (x, y: INTEGER);
  47.     (** prints the object at printer coordinates (x, y) *)
  48.         VAR w, h, ox, oy, yh, cx: INTEGER; fnth: LONGINT;
  49.     BEGIN
  50.         b.GetPDim (ox, oy, w, h); GraphicUtils.PrintBox (x, y, w, h);  
  51.         fnth := ((b.fnt.maxY - b.fnt.minY) * Dialogs.dUnit) DIV Dialogs.pUnit DIV 2;
  52.         yh := y + (h DIV 2) - SHORT (fnth); 
  53.         IF h - (yh - y) > ((b.fnt.maxY * SHORT (Dialogs.dUnit)) DIV Dialogs.pUnit) THEN 
  54.             GraphicUtils.PrintString (b.name, x + 3, yh, w - 4, b.fnt, GraphicUtils.center, cx) 
  55.         END
  56.     END Print;
  57.     PROCEDURE (b: Item) Track (x, y: INTEGER; keys: SET; f: Display.Frame; p: Dialogs.Panel; x0, y0: INTEGER);
  58.         VAR bx, by, bw, bh: INTEGER; keysum: SET; t: Texts.Text; fPressed: BOOLEAN;
  59.     BEGIN
  60.         fPressed := TRUE;
  61.         b.GetDim (bx, by, bw, bh);
  62.         IF (keys = {ML}) OR (keys = {MM}) OR (keys = {MR}) THEN 
  63.             Oberon.RemoveMarks (x0 + bx, y0 + by, bw, bh);
  64.             b.Draw1 (x0 + bx, y0 + by, TRUE, f);
  65.             keysum := keys;
  66.             REPEAT 
  67.                 Input.Mouse(keys, x, y); keysum := keysum + keys;
  68.                 IF (x < x0 + bx) OR (x > x0 + bx + bw) OR (y < y0 + by) OR (y > y0 + by + bh) THEN
  69.                     IF fPressed THEN
  70.                         fPressed := FALSE;
  71.                         b.Draw1 (x0 + bx, y0 + by, fPressed, f);
  72.                     END
  73.                 ELSE
  74.                     IF ~fPressed THEN
  75.                         fPressed := TRUE;
  76.                         b.Draw1 (x0 + bx, y0 + by, fPressed, f);
  77.                     END
  78.                 END; (* VIC Jan 11 1995 *)
  79.                 Oberon.DrawCursor(Oberon.Mouse, Oberon.Arrow, x, y)
  80.             UNTIL keys = {};
  81.             Oberon.RemoveMarks(x0 + bx, y0 + by, bw, bh);
  82.             b.Draw1 (x0 + bx, y0 + by, FALSE, f);
  83.             IF ((keysum = {ML}) OR (keysum = {MM}) OR (keysum = {MR})) & fPressed THEN
  84.                 IF b.cmd[0] # 0X THEN
  85.                     DialogTexts.GetParText (b.par, p, t);
  86.                     b.CallCmd (f, Viewers.This (x, y), t)
  87.                 END
  88.             END
  89.         ELSE Oberon.DrawCursor(Oberon.Mouse, Oberon.Arrow, x, y)
  90.         END
  91.     END Track;
  92.     PROCEDURE (b: Item) Handle* (f: Display.Frame; VAR m: Display.FrameMsg);
  93.     (** handles messages which were sent to frame f *)
  94.     BEGIN
  95.         b.Handle^ (f, m);
  96.         WITH f: DialogFrames.Frame DO 
  97.             WITH m: Oberon.InputMsg DO
  98.                 IF m.id = Oberon.track THEN b.Track (m.X, m.Y, m.keys, f, f.panel, f.X, f.Y + f.H) END
  99.             ELSE
  100.             END
  101.         ELSE
  102.         END
  103.     END Handle;
  104.     PROCEDURE (b: Item) Load* (VAR r: Files.Rider);
  105.     (** reads the object from rider r *)
  106.         VAR fntname: ARRAY 32 OF CHAR;
  107.     BEGIN b.Load^( r); Files.ReadString (r, fntname); b.fnt := Fonts.This (fntname);  
  108.     END Load;
  109.     PROCEDURE (b: Item) Store* (VAR r: Files.Rider);
  110.     (** writes the object to rider r *)
  111.     BEGIN b.Store^ (r); Files.WriteString (r, b.fnt.name)
  112.     END Store;
  113.     PROCEDURE (b: Item) SetFont* (fnt: Fonts.Font);
  114.     (** sets the font with which the text is shown *)
  115.     BEGIN b.fnt := fnt; b.Restore (); IF b.panel # NIL THEN b.panel.MarkMenu END
  116.     END SetFont;
  117.     PROCEDURE WriteToObjectStr (o: DialogTexts.Item; VAR p: Dialogs.Panel; n: ARRAY OF CHAR);
  118.         VAR t: Texts.Text; 
  119.     BEGIN
  120.         t := o.GetText (); Texts.WriteString (w0, n); Texts.Append (t, w0.buf);
  121.     END WriteToObjectStr;
  122.     PROCEDURE (b: Item) Edit*;
  123.     (** opens a dialog for editing the properties of the object *)
  124.         VAR on: Dialogs.Object; t: Texts.Text; fnt: Fonts.Font; 
  125.     BEGIN
  126.         b.Edit^ (); 
  127.         on := Dialogs.editPanel.NamedObject ("name"); t := on(DialogTexts.Item).GetText ();
  128.         Texts.ChangeLooks (t, 0, t.len, {0}, b.fnt, 0, 0);
  129.     END Edit;
  130.     PROCEDURE (b: Item) Update* (p: Dialogs.Panel);
  131.     (** sets the properties of the object to the values defined in the dialog p opened with Edit *)
  132.         VAR o: Dialogs.Object; t: Texts.Text; r: Texts.Reader; ch: CHAR; 
  133.     BEGIN
  134.         o := p.NamedObject ("name"); t := o(DialogTexts.Item).GetText ();
  135.         Texts.OpenReader (r, t, 0); Texts.Read (r, ch); 
  136.         IF (r.fnt # NIL) & (r.fnt # b.fnt) THEN b.SetFont (r.fnt) END;
  137.         b.Update^ (p); 
  138.     END Update;
  139.     PROCEDURE Insert*;
  140.     (** Insert ([name] [x y w h] | ^ ) inserts a button - item in the panel containing the caret position *)
  141.         VAR x, y, x1, y1, w, h: INTEGER; b: Item; p: Dialogs.Panel; name: ARRAY 64 OF CHAR; r: Texts.Reader; ch: CHAR;
  142.     BEGIN 
  143.         NEW (b); 
  144.         DialogFrames.GetCaretPosition(p, x, y);
  145.         IF (p # NIL) THEN 
  146.             b.Init; b.fnt := Fonts.This ("Syntax10.Scn.Fnt"); 
  147.             In.Open; Texts.OpenReader (r, Oberon.Par.text, 0); Texts.Read (r, ch);
  148.             In.Name (name);
  149.             IF ~In.Done THEN 
  150.                 In.Open; In.String (name); 
  151.                 IF ~In.Done THEN COPY ("", name); In.Open ELSE b.fnt := r.fnt END
  152.             ELSE b.fnt := r.fnt 
  153.             END;
  154.             b.SetName (name); 
  155.             In.Int (x1); In.Int (y1); In.Int (w); In.Int (h);
  156.             IF ~In.Done THEN x1 := x; y1 := y; w := W; h := H 
  157.             ELSE
  158.                 IF w < 0 THEN w := W END;
  159.                 IF h < 0 THEN h := H END
  160.             END;
  161.             y := GraphicUtils.GetStringLength (name, b.fnt) + 9;
  162.             IF y > w THEN x := w; w := y END;
  163.             b.SetDim (x1, y1, w, h, FALSE); p.Insert (b, FALSE);
  164.             IF Dialogs.res = Dialogs.objectWouldOverlap THEN 
  165.                 b.SetDim (x1, y1, y, h, FALSE); p.Insert (b, FALSE)
  166.             END
  167.         ELSE
  168.             Dialogs.res := Dialogs.noPanelSelected 
  169.         END;
  170.         IF Dialogs.res # 0 THEN Dialogs.Error ("DialogButtons") END;
  171.     END Insert;
  172.     PROCEDURE DeInit;
  173.         VAR s: DialogStaticTexts.Item; b: Item; t: DialogTexts.Item;
  174.     BEGIN
  175.         NEW (Dialogs.deInit);
  176.         NEW (s); s.Init; s.SetDim (2, - 30, 35, 20, FALSE); 
  177.         s.SetString ("Name"); s.SetFont (Fonts.This ("Syntax10.Scn.Fnt")); 
  178.         Dialogs.deInit.Insert (s, FALSE);
  179.         NEW (s); s.Init; s.SetDim (13, - 57, 19, 20, FALSE); 
  180.         s.SetString ("X"); s.SetFont (Fonts.This ("Syntax10.Scn.Fnt")); 
  181.         Dialogs.deInit.Insert (s, FALSE);
  182.         NEW (s); s.Init; s.SetDim (13, - 87, 19, 20, FALSE); 
  183.         s.SetString ("Y"); s.SetFont (Fonts.This ("Syntax10.Scn.Fnt")); 
  184.         Dialogs.deInit.Insert (s, FALSE);
  185.         NEW (s); s.Init; s.SetDim (2, - 116, 35, 20, FALSE); 
  186.         s.SetString ("Cmd"); s.SetFont (Fonts.This ("Syntax10.Scn.Fnt")); 
  187.         Dialogs.deInit.Insert (s, FALSE);
  188.         NEW (s); s.Init; s.SetDim (122, - 57, 19, 20, FALSE); 
  189.         s.SetString ("W"); s.SetFont (Fonts.This ("Syntax10.Scn.Fnt")); 
  190.         Dialogs.deInit.Insert (s, FALSE);
  191.         NEW (s); s.Init; s.SetDim (122, - 87, 19, 20, FALSE); 
  192.         s.SetString ("H"); s.SetFont (Fonts.This ("Syntax10.Scn.Fnt")); 
  193.         Dialogs.deInit.Insert (s, FALSE);
  194.         NEW (s); s.Init; s.SetDim (2, - 146, 35, 20, FALSE);
  195.         s.SetString ("Par"); s.SetFont (Fonts.This ("Syntax10.Scn.Fnt")); 
  196.         Dialogs.deInit.Insert (s, FALSE);
  197.         NEW (b); b.Init; b.SetDim (195, - 72, 36, 21, FALSE); b.SetName ("Do");
  198.         b.SetFont (Fonts.This ("Syntax10.Scn.Fnt")); b.SetCmd ("Dialog.Do");
  199.         Dialogs.deInit.Insert (b, FALSE);
  200.         NEW (t); t.Init; t.SetDim (38, - 30, 144, 19, FALSE); t.SetName ("name");
  201.         Dialogs.deInit.Insert (t, FALSE);
  202.         NEW (t); t.Init; t.SetDim (38, - 59, 40, 19, FALSE); t.SetName ("x");
  203.         Dialogs.deInit.Insert (t, FALSE);
  204.         NEW (t); t.Init; t.SetDim (38, - 86, 40, 19, FALSE); t.SetName ("y");
  205.         Dialogs.deInit.Insert (t, FALSE);
  206.         NEW (t); t.Init; t.SetDim (38, - 116, 195, 19, FALSE); t.SetName ("cmd");
  207.         Dialogs.deInit.Insert (t, FALSE);
  208.         NEW (t); t.Init; t.SetDim (142, - 59, 40, 19, FALSE); t.SetName ("w");
  209.         Dialogs.deInit.Insert (t, FALSE);
  210.         NEW (t); t.Init; t.SetDim (142, - 86, 40, 19, FALSE); t.SetName ("h");
  211.         Dialogs.deInit.Insert (t, FALSE);
  212.         NEW (t); t.Init; t.SetDim (38, - 146, 195, 19, FALSE); t.SetName ("par");
  213.         Dialogs.deInit.Insert (t, FALSE)
  214.     END DeInit;
  215. BEGIN Texts.OpenWriter (w0); DeInit
  216. END DialogButtons.
  217.