dialog.mod 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. MODULE dialog;
  2. (* Press D for a form dialog, M for a message box, Esc to quit. *)
  3. FROM InOut IMPORT WriteString, WriteLn;
  4. IMPORT tv;
  5. VAR e : tv.Event; quit : BOOLEAN; st : tv.ViewPtr;
  6. iName, iCity, cOn, rFast, rSafe, cmd : INTEGER;
  7. s, msg : ARRAY [0..127] OF CHAR;
  8. BEGIN
  9. IF NOT tv.Init() THEN WriteString("not a tty"); WriteLn; HALT END;
  10. st := tv.NewView(tv.VText, 0, tv.Rows() - 1, tv.Cols(), 1);
  11. tv.SetText(st, " D: dialog M: message box Esc: quit");
  12. tv.AddView(tv.Desk(), st);
  13. tv.Finish;
  14. quit := FALSE;
  15. WHILE NOT quit DO
  16. IF tv.Resized() THEN tv.Finish END;
  17. IF tv.ReadEvent(e) THEN
  18. IF (e.kind = tv.evKey) AND (e.key = tv.kEsc) THEN
  19. quit := TRUE
  20. ELSIF (e.kind = tv.evKey) AND (e.key = tv.kChar) AND
  21. ((e.ch = VAL(CARDINAL, ORD('d'))) OR (e.ch = VAL(CARDINAL, ORD('D')))) THEN
  22. tv.Dialog("Options", 44, 12);
  23. iName := tv.DlgInput("Name:", "Modula-2");
  24. iCity := tv.DlgInput("City:", "Paris");
  25. cOn := tv.DlgCheck("Enabled", TRUE);
  26. rFast := tv.DlgRadio("Fast mode", TRUE);
  27. rSafe := tv.DlgRadio("Safe mode", FALSE);
  28. tv.DlgButton("OK", tv.cmOK);
  29. tv.DlgButton("Cancel", tv.cmCancel);
  30. cmd := tv.DlgRun();
  31. IF cmd = tv.cmOK THEN
  32. tv.DlgTextAt(iName, s);
  33. tv.CopyText(msg, "Name=");
  34. tv.AppendText(msg, s);
  35. tv.AppendText(msg, " Enabled=");
  36. IF tv.DlgValue(cOn) = 1 THEN tv.AppendText(msg, "yes")
  37. ELSE tv.AppendText(msg, "no") END;
  38. tv.AppendText(msg, " Fast=");
  39. IF tv.DlgValue(rFast) = 1 THEN tv.AppendText(msg, "yes")
  40. ELSE tv.AppendText(msg, "no") END;
  41. IF tv.MessageBox("Result", msg, tv.mbOK) = tv.cmOK THEN END
  42. END
  43. ELSIF (e.kind = tv.evKey) AND (e.key = tv.kChar) AND
  44. ((e.ch = VAL(CARDINAL, ORD('m'))) OR (e.ch = VAL(CARDINAL, ORD('M')))) THEN
  45. IF tv.MessageBox("Question", "Proceed with the operation?",
  46. tv.mbYesNo) = tv.cmYes THEN
  47. tv.Message("Info", "You chose Yes.")
  48. ELSE
  49. tv.Message("Info", "You chose No.")
  50. END
  51. END;
  52. IF NOT quit THEN tv.Finish END
  53. END
  54. END;
  55. tv.Done
  56. END dialog.