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

  1. Syntax10.Scn.Fnt
  2. Syntax10i.Scn.Fnt
  3. StampElems
  4. Alloc
  5. 3 May 95
  6. Syntax10b.Scn.Fnt
  7. MODULE DialogListBoxes; 
  8.     (** Markus Knasm
  9. ller 12 Oct 94 -  
  10.     (* based on PopupElems MF 27.1.92 /MH/CM/MAH/HM *)
  11.     IMPORT DialogFrames, Dialogs, DialogTexts, Display, Display1, Files, GraphicUtils, In, Input, Oberon, TextFrames, Texts, Viewers; 
  12.     CONST 
  13.         W* = 50; H* = 70;
  14.         MR = 0; MM = 1; ML = 2; cancel = {MM, MR, ML}; CR = 0DX;
  15.         ehm = 4; evm = 3;    (*element: horizontal margin, vertical margin*)
  16.         mhm = 5; mvm = 2;
  17.         white = 0; grey1 = 12; grey2 = 13; grey3 = 14; black = 15;    
  18.     TYPE
  19.         Item* = POINTER TO ItemDesc;
  20.         ItemDesc* = RECORD(Dialogs.ObjectDesc)
  21.             menu-: Texts.Text;    (** displayed text *) 
  22.             n-: INTEGER;             (** number of lines in the text *)
  23.             lsp, dsc: INTEGER;
  24.             selline*: INTEGER;    (** most recently selected cmd *)
  25.             startcmd: INTEGER;    (* first displayed cmd *)
  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 Min (x, y: INTEGER): INTEGER;
  31.     BEGIN IF x < y THEN RETURN x ELSE RETURN y END
  32.     END Min;
  33.     PROCEDURE (b: Item) Draw* (x, y: INTEGER; f: Display.Frame);
  34.     (** displays the object at (x, y) in frame f *)
  35.         VAR bx, by, w, h, mode: INTEGER; 
  36.     BEGIN
  37.         b.GetDim (bx, by, w, h);
  38.         IF b.selected THEN mode := Display.invert ELSE mode := Display.replace END;
  39.         GraphicUtils.DrawMenu (f, b.menu, b.startcmd, b.selline, x, y, w, h, mode, b.n, b.lsp, b.dsc);
  40.     END Draw;
  41.     PROCEDURE (b: Item) Print* (x, y: INTEGER); 
  42.     (** prints the object at printer coordinates (x, y) *)
  43.         VAR ox, oy, ow, oh: INTEGER;
  44.     BEGIN b.GetPDim (ox, oy, ow, oh); GraphicUtils.PrintBox (x, y, ow, oh)
  45.     END Print;
  46.     PROCEDURE (b: Item) Init*;
  47.     (** initialies the object, should be called after allocating the object with NEW *)
  48.     BEGIN b.Init^; b.menu := TextFrames.Text (""); b.selline := 0; b.startcmd := 0;
  49.     END Init; 
  50.     PROCEDURE (b: Item) SetMenu* (t: Texts.Text);
  51.     (** sets the menu of the object to t and redraws the object *)
  52.     BEGIN b.selline := 0; b.menu := t; b.Restore
  53.     END SetMenu;
  54.     PROCEDURE (b: Item) Track (x, y: INTEGER; keys: SET; f: Display.Frame; p: Dialogs.Panel);
  55.         VAR keysum: SET; dummy: ARRAY 6 OF CHAR; bx, by, w, h: INTEGER; t: Texts.Text;
  56.     BEGIN
  57.         IF (keys = {MM}) OR (keys = {ML}) OR (keys = {MR}) THEN 
  58.             b.GetDim (bx, by, w, h);
  59.             bx := f.X + bx; by := f.Y + f.H + by; 
  60.             GraphicUtils.TrackMenu (f, b.menu, bx, by, w, h, b.n, b.lsp, b.dsc, b.startcmd, b.selline);
  61.             IF b.selline >= 0 THEN 
  62.                 b.Restore;    
  63.                 IF b.cmd[0] # 0X THEN
  64.                     DialogTexts.GetParText (b.par, b.panel, t);
  65.                     b.CallCmd (f, Viewers.This (x, y), t)
  66.                 END
  67.             END
  68.         ELSE Oberon.DrawCursor(Oberon.Mouse, Oberon.Arrow, x, y)
  69.         END
  70.     END Track; 
  71.     PROCEDURE (b: Item) Handle* (f: Display.Frame; VAR m: Display.FrameMsg);
  72.     (** handles messages which were sent to frame f *)
  73.     BEGIN
  74.         b.Handle^ (f, m);
  75.         WITH f: DialogFrames.Frame DO
  76.             WITH m: Oberon.InputMsg DO
  77.                 IF m.id = Oberon.track THEN b.Track (m.X, m.Y, m.keys, f, f.panel) END
  78.             ELSE
  79.             END
  80.         ELSE
  81.         END
  82.     END Handle;
  83.     PROCEDURE (b: Item) Copy* (VAR dup: Dialogs.Object);
  84.     (** allocates dup and makes a deep copy of o. Before calling this methode dup should be equal NIL *)
  85.         VAR x: Item; 
  86.     BEGIN
  87.         IF dup = NIL THEN NEW (x); dup := x ELSE x := dup(Item) END; 
  88.         b.Copy^ (dup); x.menu := TextFrames.Text (""); x.selline := b.selline; x.startcmd := b.startcmd;
  89.     END Copy;
  90.     PROCEDURE Insert*;
  91.     (** Insert (name [x y w h]| ^ ) inserts a listbox - item in the panel containing the caret position *)
  92.         VAR x, y, x1, y1, w, h: INTEGER; l: Item; p: Dialogs.Panel; name: ARRAY 64 OF CHAR; 
  93.     BEGIN 
  94.         NEW (l); In.Open; In.Name (name); 
  95.         DialogFrames.GetCaretPosition (p, x, y);
  96.         IF (p # NIL) THEN 
  97.             l.Init; In.Open; In.Name (name);
  98.             IF ~In.Done THEN COPY ("", name); In.Open END;
  99.             l.SetName (name); 
  100.             In. Int (x1); In.Int (y1); In.Int (w); In.Int (h);
  101.             IF ~ In.Done THEN x1 := x; y1 := y; w := W; h := H 
  102.             ELSE
  103.                 IF w < 0 THEN w := W END;
  104.                 IF h < 0 THEN h := H END;
  105.             END; 
  106.             l.SetDim (x1, y1, w, h, FALSE); p.Insert (l, FALSE) 
  107.         ELSE
  108.             Dialogs.res := Dialogs.noPanelSelected
  109.         END;
  110.         IF Dialogs.res # 0 THEN Dialogs.Error ("DialogListBoxes") END;
  111.     END Insert;
  112. END DialogListBoxes.    
  113.