Syntax10.Scn.Fnt Syntax10i.Scn.Fnt StampElems Alloc 15 Feb 95 Syntax10b.Scn.Fnt MODULE DialogCheckBoxes; (** Markus Knasm ller 25.May.94 - IMPORT DialogFrames, Dialogs, DialogTexts, Display, Display1, Files, In, Input, Oberon, Printer, TextFrames, Texts, Viewers; CONST ML = 0; MM = 1; MR = 2; W* = 20; H* = W; white = 0; black = 15; TYPE Item* = POINTER TO ItemDesc; ItemDesc* = RECORD(Dialogs.ObjectDesc) on-: BOOLEAN (** state of the checkbox *) END; PROCEDURE (b: Item) Draw* (x, y: INTEGER; f: Display.Frame); (** displays the object at (x, y) in frame f *) VAR mode, w, h, bx, by: INTEGER; BEGIN b.GetDim (bx, by, w, h); DEC (w); DEC (h); IF b.selected THEN mode := Display.invert ELSE mode := Display.replace END; Display1.Line (f, white, x, y, x + w, y, mode); Display1.Line (f, black, x, y, x, y + h, mode); Display1.Line (f, white, x + w, y, x + w, y + h, mode); Display1.Line (f, black, x, y + h, x + w, y + h, mode); IF b.on & (w > 8) & (h > 8) THEN 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); 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); 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) END END Draw; PROCEDURE (b: Item) Print* (x, y: INTEGER); (** prints the object at printer coordinates (x, y) *) VAR h, w, ox, oy: INTEGER; BEGIN b.GetPDim (ox, oy, w, h); Printer.Line (x, y, x + w, y); Printer.Line (x, y, x , y + h); Printer.Line (x + w, y , x + w, y + h); Printer.Line (x, y + h, x + w, y + h); IF b.on THEN Printer.Line (x, y, x + w, y + h); Printer.Line (x, y + h, x + w, y) END; END Print; PROCEDURE (b: Item) ChangeValue* (value: BOOLEAN); (** changes the state of the item *) BEGIN IF b.on & ~ value THEN b.Hide END; b.on := value; b.Restore END ChangeValue; PROCEDURE (b: Item) Copy* (VAR dup: Dialogs.Object); (** allocates dup and makes a deep copy of o. Before calling this methode dup should be equal NIL *) VAR x: Item; BEGIN IF dup = NIL THEN NEW (x); dup := x ELSE x := dup(Item) END; b.Copy^ (dup); x.on := b.on END Copy; PROCEDURE (b: Item) Track (x, y: INTEGER; keys: SET; f: Display.Frame; p: Dialogs.Panel); VAR keysum: SET; t: Texts.Text; BEGIN IF (keys = {MM}) OR (keys = {ML}) OR (keys = {MR}) THEN keysum := keys; REPEAT Input.Mouse(keys, x, y); keysum := keysum + keys; Oberon.DrawCursor(Oberon.Mouse, Oberon.Arrow, x, y) UNTIL keys = {}; IF (keysum = {MM}) OR (keysum = {ML}) OR (keysum = {MR}) THEN b.ChangeValue (~ b.on); DialogTexts.GetParText (b.par, b.panel, t); b.CallCmd (f, Viewers.This (x, y), t) END ELSE Oberon.DrawCursor(Oberon.Mouse, Oberon.Arrow, x, y) END END Track; PROCEDURE (b: Item) Handle* (f: Display.Frame; VAR m: Display.FrameMsg); (** handles messages which were sent to frame f *) BEGIN b.Handle^ (f, m); WITH f: DialogFrames.Frame DO WITH m: Oberon.InputMsg DO IF m.id = Oberon.track THEN b.Track (m.X, m.Y, m.keys, f, f.panel) END ELSE END ELSE END END Handle; PROCEDURE Insert*; (** Insert ([name] [x y w h]| ^ ) inserts a checkbox - item in the panel containing the caret position *) VAR x, y, x1, y1, w, h: INTEGER; b: Item; p: Dialogs.Panel; name: ARRAY 64 OF CHAR; BEGIN NEW (b); DialogFrames.GetCaretPosition (p, x, y); IF (p # NIL) THEN b.Init; b.on := FALSE; In.Open; In.Name (name); IF ~In.Done THEN COPY ("", name); In.Open END; b.SetName (name); In.Int (x1); In.Int (y1); In.Int (w); In.Int (h); IF ~In.Done THEN x1 := x; y1 := y; w := W; h := H ELSE IF w < 0 THEN w := W END; IF h < 0 THEN h := H END END; b.SetDim (x1, y1, w, h, FALSE); p.Insert (b, FALSE) ELSE Dialogs.res := Dialogs.noPanelSelected END; IF Dialogs.res # 0 THEN Dialogs.Error ("DialogCheckBoxes") END END Insert; END DialogCheckBoxes.