app.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #include "app.h"
  2. #define Uses_TDialog
  3. #define Uses_TKeys
  4. #define Uses_TDeskTop
  5. #define Uses_TButton
  6. #define Uses_TStaticText
  7. #define Uses_TStatusLine
  8. #define Uses_TStatusDef
  9. #define Uses_TStatusItem
  10. #define Uses_TSubMenu
  11. #define Uses_TMenuBar
  12. #include <tvision/tv.h>
  13. THelloApp::THelloApp()
  14. : TProgInit(&THelloApp::initStatusLine, &THelloApp::initMenuBar,
  15. &THelloApp::initDeskTop) {}
  16. void THelloApp::greetingBox() {
  17. TDialog *d = new TDialog(TRect(25, 5, 55, 16), "Hello, World!");
  18. d->insert(new TStaticText(TRect(3, 5, 15, 6), hello_line.c_str()));
  19. d->insert(new TButton(TRect(16, 2, 28, 4), "Terrific", cmCancel, bfNormal));
  20. d->insert(new TButton(TRect(16, 4, 28, 6), "Ok", cmCancel, bfNormal));
  21. d->insert(new TButton(TRect(16, 6, 28, 8), "Lousy", cmCancel, bfNormal));
  22. d->insert(new TButton(TRect(16, 8, 28, 10), "Cancel", cmCancel, bfNormal));
  23. deskTop->execView(d);
  24. destroy(d);
  25. }
  26. void THelloApp::handleEvent(TEvent &event) {
  27. TApplication::handleEvent(event);
  28. if (event.what == evCommand) {
  29. switch (event.message.command) {
  30. case GreetThemCmd:
  31. greetingBox();
  32. clearEvent(event);
  33. break;
  34. case CallListCmd:
  35. if (TView *w = validView(new TItemWindow("test")))
  36. deskTop->insert(w);
  37. clearEvent(event);
  38. break;
  39. default:
  40. break;
  41. }
  42. }
  43. }
  44. TMenuBar *THelloApp::initMenuBar(TRect r) {
  45. r.b.y = r.a.y + 1;
  46. return new TMenuBar(
  47. r, *new TSubMenu("~F~ile", kbAltH) +
  48. *new TMenuItem("~G~reeting...", GreetThemCmd, kbAltG) +
  49. *new TMenuItem("~L~ist...", CallListCmd, kbAltL) + newLine() +
  50. *new TMenuItem("E~x~it", cmQuit, cmQuit, hcNoContext, "Alt-X"));
  51. }
  52. char text[100] = "init";
  53. const char *THintStatusLine::hint(ushort) { return text; }
  54. TStatusLine *THelloApp::initStatusLine(TRect r) {
  55. r.a.y = r.b.y - 1;
  56. return new THintStatusLine(
  57. r, *new TStatusDef(0, 50) +
  58. *new TStatusItem("~F10~ Menu", kbF10, cmMenu) +
  59. *new TStatusItem("~Alt-X~ Exit", kbAltX, cmQuit) +
  60. *new TStatusDef(50, 0xFFFF) + *new TStatusItem(0, kbF10, cmMenu) +
  61. *new TStatusItem("~F1~ Help", kbF1, cmHelp));
  62. }
  63. void THelloApp::idle() {
  64. if (statusLine != 0)
  65. statusLine->update();
  66. if (commandSetChanged == True) {
  67. message(this, evBroadcast, cmCommandSetChanged, 0);
  68. commandSetChanged = False;
  69. }
  70. }