Syntax10.Scn.Fnt Syntax10i.Scn.Fnt StampElems Alloc 10 Feb 95 Syntax10b.Scn.Fnt MODULE DialogRadioButtons; (** Markus Knasm ller 30 Jun 94 - IMPORT DialogFrames, DialogGroupBoxes, Dialogs, DialogTexts, Display, Display1, In, Input, Oberon, Printer, TextFrames, Texts, Viewers; CONST ML = 0; MM = 1; MR = 2; W* = 20; H* = W; grey1 = 12; grey2 = 13; grey3 = 14; black = 15; white = 0; p = 5; TYPE Item* = POINTER TO ItemDesc; ItemDesc* = RECORD(Dialogs.ObjectDesc) on-: BOOLEAN; (** state of the radiobutton *) END; VAR w: Texts.Writer; PROCEDURE Min (x, y: INTEGER): INTEGER; BEGIN IF x < y THEN RETURN x ELSE RETURN y END END Min; PROCEDURE (r: Item) Draw* (x, y: INTEGER; f: Display.Frame); (** displays the object at (x, y) in frame f *) VAR mode, w, h, rx, ry, i, y1, w2: INTEGER; BEGIN r.GetDim (rx, ry, w, h); DEC (w); DEC (h); w := Min (w, h); IF r.selected THEN mode := Display.invert ELSE mode := Display.replace END; w2 := w DIV 2; w := w2 * 2; (* VIC Jan 11 1995 *) IF r.on THEN Display1.Line (f, black, x, y + w2, x + w2, y + w, mode); Display1.Line (f, black, x + w, y + w2, x + w2, y + w, mode); Display1.Line (f, white, x, y + w2, x + w2, y, mode); Display1.Line (f, white, x + w, y + w2, x + w2, y, mode); FOR i := - ((w * p) DIV 20) TO 0 DO y1 := y + w2 + (w * p DIV 20) + i; Display1.Line (f, black, x + w2 + i, y1, x + w2 - i, y1, mode); END; FOR i := 0 TO ((w * p) DIV 20) DO y1 := y + w2 - i; Display1.Line (f, black, x + w2 - (w * p DIV 20) + i, y1, x + w2 + (w * p DIV 20) - i, y1, mode); END; ELSE Display1.Line (f, white, x, y + w2, x + w2, y + w, mode); Display1.Line (f, white, x + w, y + w2, x + w2, y + w, mode); Display1.Line (f, black, x, y + w2, x + w2, y, mode); Display1.Line (f, black, x + w, y + w2, x + w2, y, mode) END END Draw; PROCEDURE (r: Item) Print* (x, y: INTEGER); (** prints the object at printer coordinates (x, y) *) VAR w, h, rx, ry, i, y1: INTEGER; BEGIN r.GetPDim (rx, ry, w, h); DEC (w); DEC (h); w := Min (w, h); Printer.Line (x + w, y + (w DIV 2), x + (w DIV 2), y + w); Printer.Line (x + w, y + (w DIV 2), x + (w DIV 2), y); Printer.Line (x, y + (w DIV 2), x + (w DIV 2), y + w); Printer.Line (x, y + (w DIV 2), x + (w DIV 2), y); IF r.on THEN FOR i := - ((w * p) DIV 20) TO 0 DO y1 := y + (w DIV 2) + (w * p DIV 20) + i; Printer.Line (x + (w DIV 2) + i, y1, x + (w DIV 2) - i, y1); END; FOR i := 0 TO ((w * p) DIV 20) DO y1 := y + (w DIV 2) - i; Printer.Line (x + (w DIV 2) - (w * p DIV 20) + i, y1, x + (w DIV 2) + (w * p DIV 20) - i, y1); END; END END Print; PROCEDURE (r: 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; r.Copy^ (dup); x.on := r.on; END Copy; PROCEDURE (r: Item) ChangeValue* (value: BOOLEAN); (** changes the state of the item *) VAR g, o: Dialogs.Object; obArray: ARRAY 50 OF Dialogs.Object; nofelems, i: INTEGER; BEGIN IF r.on = value THEN RETURN END; r.Hide; r.on := value; r.Restore; IF value = FALSE THEN RETURN END; g := r.OverlappingObject (); IF g = NIL THEN RETURN END; WITH g: DialogGroupBoxes.Item DO g.GetObjects (obArray, nofelems); FOR i := 0 TO nofelems - 1 DO o := obArray[i]; IF o # r THEN WITH o: Item DO IF o.on THEN o.Hide; o.on := FALSE; o.Restore END ELSE END END END ELSE END END ChangeValue; PROCEDURE (r: Item) Track (x, y: INTEGER; keys: SET; f: Display.Frame; p: Dialogs.Panel); VAR keysum: SET; name: ARRAY 64 OF CHAR; dummy: ARRAY 6 OF CHAR; t: Texts.Text; BEGIN IF (keys = {ML}) OR (keys = {MM}) 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 = {ML}) OR (keysum = {MM}) OR (keysum = {MR}) & (~ r.on) THEN (* one button of a set is on at any time *) r.ChangeValue (TRUE); IF r.cmd[0] # 0X THEN DialogTexts.GetParText (r.par, r.panel, t); r.CallCmd (f, Viewers.This (x, y), t) END END ELSE Oberon.DrawCursor(Oberon.Mouse, Oberon.Arrow, x, y) END END Track; PROCEDURE (r: Item) Handle* (f: Display.Frame; VAR m: Display.FrameMsg); (** handles messages which were sent to frame f *) BEGIN r.Handle^ (f, m); WITH f: DialogFrames.Frame DO WITH m: Oberon.InputMsg DO IF m.id = Oberon.track THEN r.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 radiobutton - item in the panel containing the caret position *) VAR x, y, x1, y1, w, h: INTEGER; r: Item; p: Dialogs.Panel; name: ARRAY 64 OF CHAR; BEGIN NEW (r); DialogFrames.GetCaretPosition (p, x, y); IF (p # NIL) THEN r.Init; r.on := FALSE; In.Open; In.Name (name); IF ~In.Done THEN COPY ("", name); In.Open END; r.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; r.SetDim (x1, y1, w, h, FALSE); p.Insert (r, FALSE); ELSE Dialogs.res := Dialogs.noPanelSelected END; IF Dialogs.res # 0 THEN Dialogs.Error ("DialogRadioButtons") END; END Insert; BEGIN Texts.OpenWriter (w); END DialogRadioButtons.