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

  1. Syntax10.Scn.Fnt
  2. Syntax10i.Scn.Fnt
  3. StampElems
  4. Alloc
  5. 15 Feb 95
  6. Syntax10b.Scn.Fnt
  7. MODULE DialogCheckBoxes; 
  8.     (** Markus Knasm
  9. ller 25.May.94 -  
  10.     IMPORT DialogFrames, Dialogs, DialogTexts, Display, Display1, Files, In, Input, Oberon, Printer, TextFrames, Texts, Viewers;
  11.     CONST ML = 0; MM = 1; MR = 2; W* = 20; H* = W; white = 0; black = 15;
  12.     TYPE
  13.         Item* = POINTER TO ItemDesc;
  14.         ItemDesc* = RECORD(Dialogs.ObjectDesc)
  15.             on-: BOOLEAN (** state of the checkbox *)
  16.         END;
  17.     PROCEDURE (b: Item) Draw* (x, y: INTEGER; f: Display.Frame);
  18.     (** displays the object at (x, y) in frame f *)
  19.         VAR mode, w, h, bx, by: INTEGER; 
  20.     BEGIN
  21.         b.GetDim (bx, by, w, h); DEC (w); DEC (h);
  22.         IF b.selected THEN mode := Display.invert ELSE mode := Display.replace END;
  23.         Display1.Line (f, white, x, y, x + w, y, mode); Display1.Line (f, black, x, y, x, y + h, mode);
  24.         Display1.Line (f, white, x + w, y, x + w, y + h, mode); Display1.Line (f, black, x, y + h, x + w, y + h, mode);
  25.         IF b.on & (w > 8) & (h > 8) THEN 
  26.             Display1.Line (f, black, x + 4, y + 4, x + w - 4, y + h - 4, mode); Display1.Line (f, black, x + 4, y + h - 4, x + w - 4, y + 4, mode);
  27.             Display1.Line (f, black, x + 5, y + 4, x + w - 4, y + h - 5, mode); Display1.Line (f, black, x + 4, y + 5, x + w - 5, y + h - 4, mode);
  28.             Display1.Line (f, black, x + 5, y + h - 4, x + w - 4, y + 5, mode); Display1.Line (f, black, x + 4, y + h - 5, x + w - 5, y + 4, mode)    
  29.         END
  30.     END Draw;
  31.     PROCEDURE (b: Item) Print* (x, y: INTEGER);
  32.     (** prints the object at printer coordinates (x, y) *)
  33.         VAR h, w, ox, oy: INTEGER;
  34.     BEGIN
  35.         b.GetPDim (ox, oy, w, h);
  36.         Printer.Line (x, y, x + w, y); Printer.Line (x, y, x , y + h);
  37.         Printer.Line (x + w, y , x + w, y + h); Printer.Line (x, y + h, x + w, y + h);
  38.         IF b.on THEN
  39.             Printer.Line (x, y, x + w, y + h); Printer.Line (x, y + h, x + w, y)
  40.         END;
  41.     END Print;
  42.     PROCEDURE (b: Item) ChangeValue* (value: BOOLEAN);
  43.     (** changes the state of the item *)
  44.     BEGIN
  45.         IF b.on & ~ value THEN b.Hide END; 
  46.         b.on := value; b.Restore
  47.     END ChangeValue;
  48.     PROCEDURE (b: Item) Copy* (VAR dup: Dialogs.Object);
  49.     (** allocates dup and makes a deep copy of o. Before calling this methode dup should be equal NIL *)
  50.         VAR x: Item; 
  51.     BEGIN
  52.         IF dup = NIL THEN NEW (x); dup := x ELSE x := dup(Item) END; 
  53.         b.Copy^ (dup); x.on := b.on
  54.     END Copy;
  55.     PROCEDURE (b: Item) Track (x, y: INTEGER; keys: SET; f: Display.Frame; p: Dialogs.Panel);
  56.         VAR keysum: SET; t: Texts.Text;
  57.     BEGIN
  58.         IF (keys = {MM}) OR (keys = {ML}) OR (keys = {MR}) THEN 
  59.             keysum := keys;
  60.             REPEAT 
  61.                 Input.Mouse(keys, x, y); keysum := keysum + keys;
  62.                 Oberon.DrawCursor(Oberon.Mouse, Oberon.Arrow, x, y)
  63.             UNTIL keys = {};
  64.             IF (keysum = {MM}) OR (keysum = {ML}) OR (keysum = {MR}) THEN 
  65.                 b.ChangeValue (~ b.on); 
  66.                 DialogTexts.GetParText (b.par, b.panel, t);
  67.                 b.CallCmd (f, Viewers.This (x, y), t)
  68.             END
  69.         ELSE Oberon.DrawCursor(Oberon.Mouse, Oberon.Arrow, x, y)
  70.         END
  71.     END Track;    
  72.     PROCEDURE (b: Item) Handle* (f: Display.Frame; VAR m: Display.FrameMsg);
  73.     (** handles messages which were sent to frame f *)
  74.     BEGIN
  75.         b.Handle^ (f, m);
  76.         WITH f: DialogFrames.Frame DO
  77.             WITH m: Oberon.InputMsg DO
  78.                 IF m.id = Oberon.track THEN b.Track (m.X, m.Y, m.keys, f, f.panel) END
  79.             ELSE
  80.             END
  81.         ELSE
  82.         END
  83.     END Handle;
  84.     PROCEDURE Insert*;
  85.     (** Insert ([name] [x y w h]| ^ ) inserts a checkbox - item in the panel containing the caret position *)
  86.         VAR x, y, x1, y1, w, h: INTEGER; b: Item; p: Dialogs.Panel; name: ARRAY 64 OF CHAR; 
  87.     BEGIN 
  88.         NEW (b);  
  89.         DialogFrames.GetCaretPosition (p, x, y);
  90.         IF (p # NIL) THEN 
  91.             b.Init; b.on := FALSE; 
  92.             In.Open; In.Name (name);
  93.             IF ~In.Done THEN COPY ("", name); In.Open END;
  94.             b.SetName (name); 
  95.             In.Int (x1); In.Int (y1); In.Int (w); In.Int (h);
  96.             IF ~In.Done THEN x1 := x; y1 := y; w := W; h := H 
  97.             ELSE 
  98.                 IF w < 0 THEN w := W END;
  99.                 IF h < 0 THEN h := H END
  100.             END;
  101.             b.SetDim (x1, y1, w, h, FALSE); p.Insert (b, FALSE) 
  102.         ELSE
  103.             Dialogs.res := Dialogs.noPanelSelected
  104.         END;
  105.         IF Dialogs.res # 0 THEN Dialogs.Error ("DialogCheckBoxes") END
  106.     END Insert;
  107. END DialogCheckBoxes.
  108.