| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- MODULE dialog;
- (* Press D for a form dialog, M for a message box, Esc to quit. *)
- FROM InOut IMPORT WriteString, WriteLn;
- IMPORT tv;
- VAR e : tv.Event; quit : BOOLEAN; st : tv.ViewPtr;
- iName, iCity, cOn, rFast, rSafe, cmd : INTEGER;
- s, msg : ARRAY [0..127] OF CHAR;
- BEGIN
- IF NOT tv.Init() THEN WriteString("not a tty"); WriteLn; HALT END;
- st := tv.NewView(tv.VText, 0, tv.Rows() - 1, tv.Cols(), 1);
- tv.SetText(st, " D: dialog M: message box Esc: quit");
- tv.AddView(tv.Desk(), st);
- tv.Finish;
- quit := FALSE;
- WHILE NOT quit DO
- IF tv.Resized() THEN tv.Finish END;
- IF tv.ReadEvent(e) THEN
- IF (e.kind = tv.evKey) AND (e.key = tv.kEsc) THEN
- quit := TRUE
- ELSIF (e.kind = tv.evKey) AND (e.key = tv.kChar) AND
- ((e.ch = VAL(CARDINAL, ORD('d'))) OR (e.ch = VAL(CARDINAL, ORD('D')))) THEN
- tv.Dialog("Options", 44, 12);
- iName := tv.DlgInput("Name:", "Modula-2");
- iCity := tv.DlgInput("City:", "Paris");
- cOn := tv.DlgCheck("Enabled", TRUE);
- rFast := tv.DlgRadio("Fast mode", TRUE);
- rSafe := tv.DlgRadio("Safe mode", FALSE);
- tv.DlgButton("OK", tv.cmOK);
- tv.DlgButton("Cancel", tv.cmCancel);
- cmd := tv.DlgRun();
- IF cmd = tv.cmOK THEN
- tv.DlgTextAt(iName, s);
- tv.CopyText(msg, "Name=");
- tv.AppendText(msg, s);
- tv.AppendText(msg, " Enabled=");
- IF tv.DlgValue(cOn) = 1 THEN tv.AppendText(msg, "yes")
- ELSE tv.AppendText(msg, "no") END;
- tv.AppendText(msg, " Fast=");
- IF tv.DlgValue(rFast) = 1 THEN tv.AppendText(msg, "yes")
- ELSE tv.AppendText(msg, "no") END;
- IF tv.MessageBox("Result", msg, tv.mbOK) = tv.cmOK THEN END
- END
- ELSIF (e.kind = tv.evKey) AND (e.key = tv.kChar) AND
- ((e.ch = VAL(CARDINAL, ORD('m'))) OR (e.ch = VAL(CARDINAL, ORD('M')))) THEN
- IF tv.MessageBox("Question", "Proceed with the operation?",
- tv.mbYesNo) = tv.cmYes THEN
- tv.Message("Info", "You chose Yes.")
- ELSE
- tv.Message("Info", "You chose No.")
- END
- END;
- IF NOT quit THEN tv.Finish END
- END
- END;
- tv.Done
- END dialog.
|