ui.cpp 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #define Uses_TKeys
  2. #define Uses_TApplication
  3. #define Uses_TEvent
  4. #define Uses_TRect
  5. #define Uses_TDialog
  6. #define Uses_TStaticText
  7. #define Uses_TButton
  8. #define Uses_TMenuBar
  9. #define Uses_TSubMenu
  10. #define Uses_TMenuItem
  11. #define Uses_TStatusLine
  12. #define Uses_TStatusItem
  13. #define Uses_TStatusDef
  14. #define Uses_TDeskTop
  15. #include <string>
  16. #include <tvision/tv.h>
  17. const int GreetThemCmd = 100;
  18. class THelloApp : public TApplication {
  19. public:
  20. THelloApp();
  21. virtual void handleEvent(TEvent &event);
  22. static TMenuBar *initMenuBar(TRect);
  23. static TStatusLine *initStatusLine(TRect);
  24. void set_hello(const std::string &new_line) { hello_line = new_line; }
  25. private:
  26. std::string hello_line;
  27. void greetingBox();
  28. };
  29. THelloApp::THelloApp()
  30. : TProgInit(&THelloApp::initStatusLine, &THelloApp::initMenuBar,
  31. &THelloApp::initDeskTop) {}
  32. void THelloApp::greetingBox() {
  33. TDialog *d = new TDialog(TRect(25, 5, 55, 16), "Hello, World!");
  34. d->insert(new TStaticText(TRect(3, 5, 15, 6), hello_line.c_str()));
  35. d->insert(new TButton(TRect(16, 2, 28, 4), "Terrific", cmCancel, bfNormal));
  36. d->insert(new TButton(TRect(16, 4, 28, 6), "Ok", cmCancel, bfNormal));
  37. d->insert(new TButton(TRect(16, 6, 28, 8), "Lousy", cmCancel, bfNormal));
  38. d->insert(new TButton(TRect(16, 8, 28, 10), "Cancel", cmCancel, bfNormal));
  39. deskTop->execView(d);
  40. destroy(d);
  41. }
  42. void THelloApp::handleEvent(TEvent &event) {
  43. TApplication::handleEvent(event);
  44. if (event.what == evCommand) {
  45. switch (event.message.command) {
  46. case GreetThemCmd:
  47. greetingBox();
  48. clearEvent(event);
  49. break;
  50. default:
  51. break;
  52. }
  53. }
  54. }
  55. TMenuBar *THelloApp::initMenuBar(TRect r) {
  56. r.b.y = r.a.y + 1;
  57. return new TMenuBar(
  58. r, *new TSubMenu("~F~ile", kbAltH) +
  59. *new TMenuItem("~G~reeting...", GreetThemCmd, kbAltG) + newLine() +
  60. *new TMenuItem("E~x~it", cmQuit, cmQuit, hcNoContext, "Alt-X"));
  61. }
  62. TStatusLine *THelloApp::initStatusLine(TRect r) {
  63. r.a.y = r.b.y - 1;
  64. return new TStatusLine(r,
  65. *new TStatusDef(0, 0xFFFF) +
  66. *new TStatusItem("~Alt-X~ Exit", kbAltX, cmQuit) +
  67. *new TStatusItem(0, kbF10, cmMenu));
  68. }
  69. extern "C" int ui_main(char *hello_line) {
  70. THelloApp helloWorld;
  71. helloWorld.set_hello(hello_line);
  72. helloWorld.run();
  73. return 0;
  74. }