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

  1. Syntax10.Scn.Fnt
  2. Syntax10i.Scn.Fnt
  3. StampElems
  4. Alloc
  5. 30 Dec 95
  6. Syntax10b.Scn.Fnt
  7. MODULE DialogComboBoxes;
  8.     (** Markus Knasm
  9. ller 30 Sep 94 -  
  10.     (* based on PopupElems MF 27.1.92 /MH/CM/MAH/HM *)
  11.     IMPORT
  12.         Bitmaps, DialogCheckBoxes, DialogFrames, DialogListBoxes, Dialogs, DialogSliders, DialogStaticTexts, DialogTexts,
  13.         Display, Files, Fonts, GraphicUtils, In, Input, MenuViewers, Oberon, Printer, TextFrames, Texts, Viewers;
  14.     CONST
  15.         mhm = 5; mvm = 2;    (*menu: horizontal margin, vertical margin*)
  16.         CR = 0DX; lbH = 100;
  17.         MR = 0; MM = 1; ML = 2; cancel = {ML, MM, MR};
  18.         W* = 60; H* = 22; minH = 20; downW = 9;
  19.         white = 0; grey1 = 12; grey2 = 13; grey3 = 14; black = 15;
  20.     TYPE
  21.         Item* = POINTER TO ItemDesc;
  22.         ItemDesc* = RECORD(Dialogs.ObjectDesc)
  23.             menu*: Texts.Text;    (** text of the list box *)
  24.             readonly*: BOOLEAN;    (** allows changes of the entry field without using the listbox *)
  25.             selline*: INTEGER;    (** last selected cmd *)
  26.             lbHeight*: INTEGER;    (** height of the listbox *)
  27.             n: INTEGER;        (** number of lines in the text *)
  28.             f: TextFrames.Frame
  29.         END;
  30.         ChangeMsg = RECORD (Display.FrameMsg);
  31.             x, y: LONGINT
  32.         END;
  33.     VAR w0: Texts.Writer;
  34.     PROCEDURE Max (x, y: INTEGER): INTEGER;
  35.     BEGIN
  36.         IF x > y THEN RETURN x ELSE RETURN y END
  37.     END Max;
  38.     PROCEDURE (b: 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.         b.Copy^ (dup); x.menu := TextFrames.Text (""); x.selline := b.selline; x.readonly := b.readonly;
  44.         x.lbHeight := b.lbHeight; x.f := TextFrames.NewText (TextFrames.Text (""), 0)
  45.     END Copy;
  46.     PROCEDURE (b: Item) Load* (VAR r: Files.Rider);
  47.     (** reads the object from rider r *)
  48.     BEGIN b.Load^ (r); Files.ReadBool (r, b.readonly); Files.ReadInt (r, b.lbHeight)
  49.     END Load;
  50.     PROCEDURE (b: Item) Store* (VAR r: Files.Rider);
  51.     (** writes the object to rider r *)
  52.     BEGIN b.Store^ (r); Files.WriteBool (r, b.readonly); Files.WriteInt (r, b.lbHeight)
  53.     END Store;
  54.     (* graphics *)
  55.     PROCEDURE (b: Item) Print* (x, y: INTEGER);
  56.     (** prints the object at printer coordinates (x, y) *)
  57.         VAR h, w, ox, oy, i, p: INTEGER;
  58.     BEGIN
  59.         b.GetPDim (ox, oy, w, h);
  60.         IF w > h THEN p := h; DEC (w, h) ELSE p := 0 END;
  61.         GraphicUtils.PrintBox (x, y, w, h);
  62.         IF p > SHORT (downW DIV Dialogs.dUnit * Dialogs.pUnit) THEN
  63.             i := (p - SHORT (downW DIV Dialogs.dUnit * Dialogs.pUnit)) DIV 2;
  64.             GraphicUtils.PrintPatternBox (DialogSliders.downArrow, x + w + 1, y, p, p, i, i)
  65.         END
  66.     END Print;
  67.     PROCEDURE DrawFrame (f1, f: Display.Frame; m: BOOLEAN);
  68.         VAR mode: INTEGER;
  69.     BEGIN
  70.         IF m THEN mode := Display.invert ELSE mode := Display.replace END;
  71.         Display.ReplConstC (f1, black, f.X - 1, f.Y, 1, f.H + 1, mode); Display.ReplConstC (f1, white, f.X + f.W, f.Y, 1, f.H + 1, mode);
  72.         Display.ReplConstC (f1, white, f.X, f.Y, f.W - 1, 1, mode); Display.ReplConstC (f1, black, f.X, f.Y + f.H, f.W - 1, 1, mode)
  73.     END DrawFrame;
  74.     PROCEDURE Adjust (f: TextFrames.Frame; id, dY, y, h: INTEGER);
  75.         VAR m: MenuViewers.ModifyMsg;
  76.     BEGIN
  77.         m.id := id; m.dY := dY; m.Y := y; m.H := 0; f.handle (f, m);
  78.         m.id := id; m.dY := dY; m.Y := y; m.H := h; f.handle (f, m)
  79.     END Adjust;
  80.     PROCEDURE (b: Item) Draw* (x, y: INTEGER; f: Display.Frame);
  81.     (** displays the object at (x, y) in frame f *)
  82.         VAR ox, oy, w, h, w1, h1, p, i: INTEGER; pat: Display.Pattern;
  83.     BEGIN
  84.         INC (x); b.GetDim (ox, oy, w, h); DEC (w, 2); DEC (h);
  85.         (* checks wether textframe is visible *)
  86.         IF (y + h <= f.Y) OR (y >= f.Y + f.H) OR (x + w <= f.X) OR (x >= f.X + f.W) THEN RETURN END;
  87.         (* corrects x and y such that the lower left coordinats of the textframes are visible *)
  88.         IF (x < f.X) & (x + w > f.X) THEN w := w - (f.X - x); x := f.X END;
  89.         IF (y < f.Y) & (y + h > f.Y) THEN  h := h- (f.Y - y); y := f.Y END;
  90.         (* corrects wide and height such that the full textframe can be displayed *)
  91.         w1 := f.W - (x - f.X); h1 := f.H - (y - f.Y);
  92.         IF w1 < b.f.left THEN RETURN END;
  93.         IF w > w1 THEN w := w1 END; IF h > h1 THEN h := h1 END;
  94.         IF w < 0 THEN w := 0 END; IF h < 0 THEN h := 0 END;
  95.         IF w > h THEN p := h; DEC (w, h) ELSE p := 0 END;
  96.         b.f.X := x; b.f.Y := y; b.f.W := w; b.f.H := h;
  97.         Oberon.RemoveMarks (f.X, f.Y, f.W, f.H); DrawFrame (f, b.f, b.selected);
  98.         b.f.barW := 0; b.f.left := 3; b.f.right := 3; b.f.bot := 1; b.f.top := 2;
  99.         Adjust (b.f, MenuViewers.extend, 0, b.f.Y + 1, b.f.H - 1);
  100.         IF p > downW THEN
  101.             i := (p - downW) DIV 2;
  102.             GraphicUtils.DrawPatternBox (f, FALSE, DialogSliders.downArrow, x + w + 1, y, p, p, i, i, Display.paint)
  103.         END
  104.     END Draw;
  105.     PROCEDURE NilNotifier (T: Texts.Text; op: INTEGER; beg, end: LONGINT);
  106.     END NilNotifier;
  107.     PROCEDURE (b: Item) Popup (x, y, w, h: INTEGER; f: Display.Frame);
  108.         VAR
  109.             menuX, menuY, menuW, menuH, p, i, lsp, dsc, sc, pos1, pos2: INTEGER; t1: Texts.Text;
  110.             r: Texts.Reader; keys: SET; ch: CHAR; bit: Bitmaps.Bitmap;
  111.     BEGIN
  112.         Oberon.RemoveMarks (x,y,w,h);
  113.         IF w > h THEN p := h ELSE p := 0 END;
  114.         IF p > downW THEN
  115.             i := (p - downW) DIV 2;
  116.             GraphicUtils.DrawPatternBox (f, TRUE, DialogSliders.downArrow, x + w - p + 1, y, p, p, i, i, Display.paint)
  117.         END;
  118.         menuW := w + 2 * mhm; menuH := Max (b.lbHeight, 40);
  119.         IF y - menuH >= 0 THEN menuY := y - menuH
  120.         ELSIF y + h + menuH <= Display.Height THEN menuY := y + h
  121.         ELSE menuY := 0
  122.         END;
  123.         IF x + menuW <= Display.Width THEN
  124.             menuX := x
  125.         ELSE
  126.             menuX := Max (x + w - menuW, 0)
  127.         END;
  128.         Oberon.RemoveMarks (menuX, menuY, menuW, menuH);
  129.         Oberon.FadeCursor (Oberon.Mouse);
  130.         bit := Bitmaps.New (menuW, menuH);
  131.         Bitmaps.CopyBlock (Bitmaps.Disp, bit, menuX, menuY, menuW, menuH, 0, 0, 0); sc := b.selline;
  132.         GraphicUtils.DrawMenu (NIL, b.menu, sc, b.selline, menuX, menuY, menuW, menuH, Display.replace, b.n, lsp, dsc);
  133.         GraphicUtils.TrackMenu (NIL, b.menu, menuX, menuY, menuW, menuH, b.n, lsp, dsc, sc, b.selline);
  134.         Oberon.FadeCursor (Oberon.Mouse);
  135.         Bitmaps.CopyBlock (bit, Bitmaps.Disp, 0, 0, menuW, menuH, menuX, menuY, 0);
  136.         IF p > downW THEN
  137.             i := (p - downW) DIV 2;
  138.             GraphicUtils.DrawPatternBox (f, FALSE, DialogSliders.downArrow, x + w - p + 1, y, p, p, i, i, Display.paint)
  139.         END;
  140.         IF (b.selline > -1) THEN
  141.             DialogTexts.GetParText (b.par, b.panel, t1);
  142.             GraphicUtils.Set( r, b.menu, b.selline); pos1 := SHORT (Texts.Pos (r));
  143.             WHILE (~ r.eot) & (ch # CR) DO Texts.Read (r, ch) END;
  144.             pos2 := SHORT (Texts.Pos (r));
  145.             Texts.Save (b.menu, pos1, pos2, w0.buf);
  146.             b.f.text.notify := NilNotifier;
  147.             Texts.Delete (b.f.text, 0, b.f.text.len);
  148.             b.f.text.notify := TextFrames.NotifyDisplay; Texts.Append (b.f.text, w0.buf)
  149.         END
  150.     END Popup;
  151.     PROCEDURE (b: Item) SetTitle* (t: Texts.Text);
  152.     (** sets the title of the item to t *)
  153.     BEGIN b.f.text := t; b.Restore
  154.     END SetTitle;
  155.     PROCEDURE (b: Item) GetTitle* (): Texts.Text;
  156.     (** returns the title of the item *)
  157.     BEGIN RETURN b.f.text
  158.     END GetTitle;
  159.     PROCEDURE (b: Item) Handle* (f: Display.Frame; VAR msg: Display.FrameMsg);
  160.     (** handles messages which were sent to frame f *)
  161.         VAR x, y, w, h, p, xh, yh, h1: INTEGER; v: Viewers.Viewer; msg1: Oberon.CopyMsg;
  162.             f1: Display.Frame; cond: BOOLEAN; msg2: ChangeMsg; t1: Texts.Text;
  163.     BEGIN
  164.         b.Handle^ (f, msg); b.GetDim (x, y, w, h);
  165.         IF w > h THEN p := h ELSE p := 0 END;
  166.         (* checks textframe is visible *)
  167.         WITH f: DialogFrames.Frame DO
  168.             yh := f.Y + f.H + y; xh := f.X + x;
  169.             WITH msg: Oberon.InputMsg DO
  170.                 IF (msg.id = Oberon.track) THEN
  171.                     IF (p > 0) &
  172.                             (msg.X >= xh + w - p) & (msg.X <= xh + w) & (msg.Y >= yh) & (msg.Y <= yh + h) & (msg.keys # {}) THEN
  173.                         b.Popup (xh, yh, w, h, f);
  174.                         RETURN
  175.                     ELSE Oberon.DrawCursor (Oberon.Mouse, Oberon.Arrow, msg.X, msg.Y);
  176.                     END
  177.                 END
  178.             ELSE
  179.             END;
  180.             IF yh < f.Y THEN h1 := h - f.Y + yh ELSE h1 := h END;
  181.             IF (yh + h <= f.Y) OR (yh >= f.Y + f.H) OR (xh + w <= f.X) OR (xh >= f.X + f.W) OR (h1 < minH) THEN RETURN END;
  182.             IF (b.readonly) & (msg IS Oberon.InputMsg) THEN RETURN END;
  183.             IF (f.X <= b.f.X) & (f.X + f.W >= b.f.X) & (f.Y <= b.f.Y) & (f.Y + f.H >= b.f.Y) THEN
  184.                 IF msg IS TextFrames.UpdateMsg THEN
  185.                     IF msg(TextFrames.UpdateMsg).text = b.f.text THEN
  186.                         b.f.handle (b.f, msg); msg2.x := f.X; msg2.y := f.Y; Viewers.Broadcast (msg2);
  187.                         IF (f.X > b.f.X) OR (f.X + f.W < b.f.X) OR (f.Y > b.f.Y) OR (f.Y + f.H < b.f.Y) THEN
  188.                             b.Draw (f.X + x, f.Y + f.H + y, f)
  189.                         END;
  190.                         IF b.cmd[0] # 0X THEN
  191.                             DialogTexts.GetParText (b.par, b.panel, t1);
  192.                             b.CallCmd (f, Viewers.This (xh, yh), t1)
  193.                         END
  194.                     END
  195.                 ELSIF msg IS MenuViewers.ModifyMsg THEN
  196.                     IF msg(MenuViewers.ModifyMsg).id = MenuViewers.reduce THEN b.Restore END
  197.                 ELSE
  198.                     b.f.handle (b.f, msg)
  199.                 END
  200.             ELSE
  201.                 cond := FALSE;
  202.                 WITH msg: Oberon.InputMsg DO
  203.                     IF (msg.id = Oberon.track) &
  204.                         (msg.X >= xh) & (msg.X <= xh + w) & (msg.Y >= yh) & (msg.Y <= yh + h) & (msg. keys # {}) THEN cond := TRUE
  205.                     END;
  206.                     IF msg.id = Oberon.defocus THEN cond := TRUE END
  207.                 | msg: ChangeMsg DO
  208.                         b.Draw (f.X + x, f.Y + f.H + y, f)
  209.                 ELSE
  210.                 END;
  211.                 IF cond THEN
  212.                     TextFrames.RemoveCaret (b.f); b.Draw (f.X + x, f.Y + f.H + y, f); b.f.handle (b.f, msg)
  213.                 END
  214.             END
  215.         ELSE
  216.         END
  217.     END Handle;
  218.     PROCEDURE (b: Item) Init*;
  219.     (** initialies the object, should be called after allocating the object with NEW *)
  220.     BEGIN
  221.         b.Init^; b.menu := TextFrames.Text ("");  b.f := TextFrames.NewText (TextFrames.Text (""), 0);
  222.         b.lbHeight := lbH
  223.     END Init;
  224.     PROCEDURE WriteToObjectInt (o: DialogTexts.Item; n: INTEGER);
  225.         VAR t: Texts.Text;
  226.     BEGIN
  227.         t := o.GetText (); Texts.WriteInt (w0, n, 0); Texts.Append (t, w0.buf)
  228.     END WriteToObjectInt;
  229.     PROCEDURE (b: Item) Edit*;
  230.     (** opens a dialog for editing the properties of the object *)
  231.         VAR on: Dialogs.Object; os, t: DialogTexts.Item; s: DialogStaticTexts.Item; c: DialogCheckBoxes.Item; t1: Texts.Text; fnt: Fonts.Font;
  232.     BEGIN
  233.         b.Edit^;
  234.         NEW (s); s.Init; s.SetDim (2, - 176, 35, 20, FALSE);
  235.         s.SetString ("lbHeight"); fnt := Fonts.This ("Syntax10.Scn.Fnt"); s.SetFont (fnt);
  236.         Dialogs.editPanel.Insert (s, FALSE);
  237.         (* ---- *)  ASSERT (Dialogs.res = Dialogs.ok);
  238.         NEW (t); t.Init; t.SetDim (38, - 176, 40, 19, FALSE); t.SetName ("LBh");
  239.         Dialogs.editPanel.Insert (t, FALSE);
  240.         (* ---- *)  ASSERT (Dialogs.res = Dialogs.ok);
  241.         WriteToObjectInt (t, b.lbHeight);
  242.         NEW (c); c.Init; c.SetDim (195, - 30, 20, 19, FALSE); c.SetName ("RO");
  243.         Dialogs.editPanel.Insert (c, FALSE);
  244.         (* ---- *)  ASSERT (Dialogs.res = Dialogs.ok);
  245.         c.ChangeValue (b.readonly);
  246.         NEW (s); s.Init; s.SetDim (215, - 30, 60, 22, FALSE);
  247.         s.SetString ("readonly"); fnt := Fonts.This ("Syntax10.Scn.Fnt"); s.SetFont (fnt);
  248.         Dialogs.editPanel.Insert (s, FALSE);
  249.         (* ---- *)  ASSERT (Dialogs.res = Dialogs.ok)
  250.     END Edit;
  251.     PROCEDURE (b: Item) Update* (p: Dialogs.Panel);
  252.     (** sets the properties of the object to the values defined in the dialog p opened with Edit *)
  253.         VAR o: Dialogs.Object; t1: Texts.Text; s: Texts.Scanner; ch: CHAR; str: ARRAY 64 OF CHAR; i: INTEGER; cond: BOOLEAN;
  254.     BEGIN
  255.         b.Update^ (p);
  256.         o := p.NamedObject ("LBh"); t1 := o(DialogTexts.Item).GetText ();
  257.         Texts.OpenScanner (s, t1, 0); Texts.Scan (s);
  258.         i := b.lbHeight;
  259.         IF (s.class = Texts.Int) & (s.i # i) THEN b.lbHeight := SHORT (s.i); b.panel.MarkMenu END;
  260.         o := p.NamedObject ("RO"); cond := o(DialogCheckBoxes.Item).on;
  261.         IF cond # b.readonly THEN b.readonly := cond; b.panel.MarkMenu END
  262.     END Update;
  263.     PROCEDURE ParText (n: ARRAY OF CHAR; p: Dialogs.Panel; VAR t: Texts.Text);
  264.     (* returns the generated parameter t, defined by the text items of panel p, which names are contained in n *)
  265.         VAR t0, t1: Texts.Text; s: Texts.Scanner; o: Dialogs.Object;
  266.     BEGIN
  267.         t := TextFrames.Text (""); t0 := TextFrames.Text ("");
  268.         Texts.WriteString (w0, n); Texts.Append (t0, w0.buf);
  269.         Texts.OpenScanner (s, t0, 0); Texts.Scan (s);
  270.         WHILE (s.class # Texts.Char) OR (s.c # 0X) DO
  271.             IF s.class = Texts.Name THEN
  272.                 o := p.NamedObject (s.s);
  273.                 IF (o # NIL) & (o IS DialogTexts.Item) THEN
  274.                     t1 := o(DialogTexts.Item).GetText ();
  275.                     Texts.Save (t1, 0, t1.len, w0.buf); Texts.WriteString (w0, " ");
  276.                     Texts.Append (t, w0.buf)
  277.                 ELSIF (o # NIL) & (o IS Item) THEN
  278.                     t1 := o(Item).GetTitle ();
  279.                     Texts.Save (t1, 0, t1.len, w0.buf); Texts.WriteString (w0, " ");
  280.                     Texts.Append (t, w0.buf)
  281.                 END
  282.             ELSIF s.class = Texts.String THEN
  283.                 Texts.WriteString (w0, s.s); Texts.Append (t, w0.buf)
  284.             END;
  285.             Texts.Scan (s)
  286.         END
  287.     END ParText;
  288.     PROCEDURE Insert*;
  289.     (** Insert ([name] [x y w h] | ^ ) inserts a combobox - item in the panel containing the caret position *)
  290.         VAR x, y, x1, y1, w, h: INTEGER; b: Item; p: Dialogs.Panel; name: ARRAY 64 OF CHAR;
  291.     BEGIN
  292.         NEW (b);
  293.         DialogFrames.GetCaretPosition (p, x, y);
  294.         IF (p # NIL) THEN
  295.             b.Init; In.Open; In.Name (name);
  296.             IF ~In.Done THEN COPY ("", name); In.Open END;
  297.             b.SetName (name);
  298.             In.Int (x1); In.Int (y1); In.Int (w); In.Int (h);
  299.             IF ~In.Done THEN x1 := x; y1 := y; w := W; h := H
  300.             ELSE
  301.                 IF w < 0 THEN w := W END;
  302.                 IF h < 0 THEN h := H END
  303.             END;
  304.             b.SetDim (x1, y1, w, h, FALSE); p.Insert (b, FALSE)
  305.         ELSE
  306.             Dialogs.res := Dialogs.noPanelSelected
  307.         END;
  308.         IF Dialogs.res # 0 THEN Dialogs.Error ("DialogComboBoxes") END
  309.     END Insert;
  310. BEGIN Texts.OpenWriter (w0); DialogTexts.GetParText := ParText
  311. END DialogComboBoxes.
  312.