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

  1. Syntax10.Scn.Fnt
  2. Syntax10i.Scn.Fnt
  3. StampElems
  4. Alloc
  5. 28 Nov 94
  6. Syntax10b.Scn.Fnt
  7. MODULE DialogUtils;
  8.     (** Markus Knasmueller 18.Nov.94 - 
  9.     IMPORT DialogButtons, DialogFrames, Dialogs, DialogStaticTexts, DialogTexts, Display, Files, Fonts, MenuViewers, Oberon, 
  10.         TextFrames, Texts, Viewers;
  11.     CONST
  12.         menu = "System.Close System.Copy System.Grow";
  13.     VAR 
  14.         msgbox*, prompt* : Dialogs.Panel; (** predefined dialogs *)
  15.         left, right, top, bot: INTEGER;
  16.     PROCEDURE Min (x, y: INTEGER): INTEGER;
  17.     BEGIN IF x < y THEN RETURN x ELSE RETURN y END
  18.     END Min;
  19.     PROCEDURE Init;
  20.         VAR s: DialogStaticTexts.Item; b: DialogButtons.Item; t: DialogTexts.Item;
  21.     BEGIN
  22.         (* --- init of prompt *)
  23.         NEW (prompt);
  24.         NEW (s); s.Init; s.SetDim (18, - 36, 200, 20, FALSE); s.SetName ("s");
  25.         s.SetFont (Fonts.This ("Syntax12b.Scn.Fnt"));
  26.         prompt.Insert (s, FALSE);
  27.         NEW (t); t.Init; t.SetDim (25, - 70, 100, 25, FALSE); t.SetName ("t");
  28.         prompt.Insert (t, FALSE);
  29.         NEW (b); b.Init; b.SetDim (165, - 70, 40, 25, FALSE); b.SetFont (Fonts.This ("Syntax12b.Scn.Fnt"));
  30.         b.SetName ("OK"); 
  31.         prompt.Insert (b, FALSE);
  32.         (* --- init of msgbox *)
  33.         NEW (msgbox); 
  34.         NEW (s); s.Init; s.SetDim (18, -36, 200, 20, FALSE); 
  35.         s.SetName ("s"); s.SetFont (Fonts.This ("Syntax12b.Scn.Fnt"));
  36.         msgbox.Insert (s, FALSE);
  37.         NEW (b); b.Init; b.SetDim (18, - 70, 40, 25, FALSE); b.SetFont (Fonts.This ("Syntax12b.Scn.Fnt"));
  38.         b.SetName ("OK"); 
  39.         msgbox.Insert (b, FALSE);
  40.     END Init;
  41.     PROCEDURE box (obj: Dialogs.Object; VAR done: BOOLEAN);
  42.         VAR x, y, w, h: INTEGER;
  43.     BEGIN
  44.         obj.GetDim (x, y, w, h);
  45.         IF x < left THEN left := x END;
  46.         IF y < bot THEN bot := y END;
  47.         IF x + w > right THEN right := x + w END;
  48.         IF y + h > top THEN top := y + h END
  49.     END box;
  50.     PROCEDURE Open* (p: Dialogs.Panel; x, y: INTEGER);
  51.     (** opens a viewer at x, y showing panel p. If it is possible the whole panel will be displayed *)
  52.         VAR df: DialogFrames.Frame; v, vmax: Viewers.Viewer; h, res: INTEGER; m: TextFrames.Frame; 
  53.             t: Texts.Text; buf: Texts.Buffer; 
  54.     BEGIN
  55.         NEW (df); df.Open (DialogFrames.Handle, p);
  56.         v := Viewers.This (x, 0); vmax := NIL; h := 0;
  57.         WHILE v.state > 1  DO 
  58.             IF v.H > h THEN vmax := v; h := v.H END;
  59.             v := Viewers.Next(v)
  60.         END;
  61.         IF vmax # NIL THEN
  62.             left := MAX (INTEGER); right := MIN(INTEGER); bot := MAX(INTEGER); top := MIN(INTEGER);
  63.             p.Enumerate (box);
  64.             y := Min(vmax.Y + ABS(bot) + 10 + TextFrames.menuH, vmax.Y + vmax.H - TextFrames.menuH - 2) 
  65.         END; 
  66.         IF Files.Old ("Dialog.Menu.Text") = NIL THEN 
  67.             m := TextFrames.NewMenu ("Msgbox.Dlg", menu)
  68.         ELSE 
  69.             m := TextFrames.NewMenu ("MsgBox.Dlg", "");
  70.             NEW (t); Texts.Open (t, "Dialog.Menu.Text");
  71.             NEW (buf); Texts.OpenBuf (buf); Texts.Save (t, 0, t.len, buf); Texts.Append (m.text, buf)
  72.         END;
  73.         v := MenuViewers.New (m, df, TextFrames.menuH, x, y);
  74.         IF p.cmd[0] # 0X THEN 
  75.             Dialogs.cmdPanel := p; Oberon.Call (p.cmd, Oberon.Par, FALSE, res)
  76.         END
  77.     END Open;
  78.     PROCEDURE Align1 (p: Dialogs.Panel; msg: ARRAY OF CHAR; VAR w: INTEGER);
  79.         VAR o: Dialogs.Object; s: DialogStaticTexts.Item; cx, cy, cw, ch, i, dx: INTEGER; pat: Display.Pattern;
  80.     BEGIN
  81.         o := p.NamedObject ("s"); s := o(DialogStaticTexts.Item); s.SetString (msg);
  82.         i := 0; w := 0; 
  83.         WHILE (s.s[i] # 0X) DO
  84.             Display.GetChar (s.fnt.raster, s.s[i], dx, cx, cy, cw, ch, pat);
  85.             INC (w, dx); INC (i) 
  86.         END;
  87.         INC (w, dx);
  88.         s.GetDim (cx, cy, cw, ch); s.SetDim (cx, cy, w, ch, FALSE);
  89.     END Align1;
  90.     PROCEDURE AlignMsgBox (p: Dialogs.Panel; msg, cmd: ARRAY OF CHAR);
  91.         VAR o: Dialogs.Object; b: DialogButtons.Item; w, cx, cy, cw, ch: INTEGER;
  92.     BEGIN
  93.         Align1 (p, msg, w);
  94.         o := p.NamedObject ("OK"); b := o(DialogButtons.Item); b.SetCmd (cmd);
  95.         b.GetDim (cx, cy, cw, ch); cx := cx + ABS (w - cw) DIV 2;
  96.         b.SetDim (cx, cy, cw, ch, FALSE);
  97.     END AlignMsgBox;
  98.     PROCEDURE AlignPanel (p: Dialogs.Panel; msg, cmd: ARRAY OF CHAR);
  99.         VAR o: Dialogs.Object; b: DialogButtons.Item; w: INTEGER;
  100.     BEGIN
  101.         Align1 (p, msg, w);
  102.         o := p. NamedObject ("OK"); b := o(DialogButtons.Item); b.SetCmd (cmd);
  103.     END AlignPanel;
  104.     PROCEDURE MessageBox* (x, y: INTEGER; msg, cmd: ARRAY OF CHAR);
  105.     (** creates and displays a panel at x, y  that contains message msg, and a pushbutton connected with cmd *)
  106.         VAR p: Dialogs.Panel; 
  107.     BEGIN
  108.         p := msgbox.Copy (); AlignMsgBox (p, msg, cmd); Open (p, x, y);
  109.     END MessageBox;
  110.     PROCEDURE Prompt* (x, y: INTEGER; msg, cmd: ARRAY OF CHAR);
  111.     (** creates and displays a panel at x, y that contains message msg, and a pushbutton connected with cmd and a text item named "t" *)
  112.         VAR p: Dialogs.Panel; 
  113.     BEGIN
  114.         p := prompt.Copy (); AlignPanel (p, msg, cmd); Open (p, x, y);
  115.     END Prompt;
  116. BEGIN Init
  117. END DialogUtils.
  118.