basemenu.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. #ifndef BDE_BASEMENU_H
  2. #define BDE_BASEMENU_H
  3. #include "widget.h"
  4. struct MenuItem {
  5. const char *action;
  6. const char *label;
  7. int state_id;
  8. MenuItem *submenu;
  9. unsigned long command_parameter1;
  10. unsigned long command_parameter2;
  11. const char *command_parameter3;
  12. const char *desc;
  13. Event evt;
  14. unichar shortkey;
  15. };
  16. typedef MenuItem PulldownMenu[];
  17. struct MenubarItem {
  18. const char *label;
  19. MenuItem *submenu;
  20. };
  21. typedef MenubarItem MenubarMenu[];
  22. class PopupMenu : public Widget {
  23. public:
  24. // The result of the user interaction:
  25. enum PostResult { mnuPrev, mnuNext, mnuSelect, mnuCancel };
  26. protected:
  27. MenuItem *mnu; // The menu.
  28. int count; // Number of menu items.
  29. int top; // If the menu is too long to fit the screen,
  30. // 'top' points to the first visible item.
  31. int current; // The highlightd item.
  32. PostResult post_result;
  33. PopupMenu *parent;
  34. private:
  35. void draw_frame();
  36. int get_optimal_width();
  37. int get_item_optimal_width(int item);
  38. void update_ancestors();
  39. void complete_menu(PulldownMenu mnu);
  40. void reposition(int x, int y);
  41. void end_modal(PostResult rslt);
  42. protected:
  43. virtual void show_hint(const char *hint) = 0;
  44. virtual void clear_other_popups() = 0;
  45. virtual bool get_item_state(int id) = 0;
  46. virtual Dispatcher *get_primary_target() = 0;
  47. virtual Dispatcher *get_secondary_target() = 0;
  48. virtual PopupMenu *create_popupmenu(PopupMenu *aParent, PulldownMenu mnu) = 0;
  49. virtual bool handle_event(const Event &evt);
  50. virtual void do_command(unsigned long parameter1, unsigned long parameter2,
  51. const char *parameter3) = 0;
  52. public:
  53. HAS_ACTIONS_MAP(PopupMenu, Dispatcher);
  54. HAS_BINDINGS_MAP(PopupMenu, Dispatcher);
  55. PopupMenu(PopupMenu *aParent, PulldownMenu aMnu);
  56. void init(PulldownMenu mnu);
  57. PostResult post(int x, int y, Event &evt);
  58. INTERACTIVE void prev_menu();
  59. INTERACTIVE void next_menu();
  60. INTERACTIVE void select();
  61. INTERACTIVE void cancel_menu();
  62. INTERACTIVE void screen_resize();
  63. INTERACTIVE void move_previous_item();
  64. INTERACTIVE void move_next_item();
  65. INTERACTIVE void move_first_item();
  66. INTERACTIVE void move_last_item();
  67. // from base Widget class:
  68. virtual bool is_dirty() const { return true; }
  69. virtual void invalidate_view() {}
  70. virtual void update();
  71. };
  72. class Menubar : public Widget {
  73. protected:
  74. MenubarItem *mnu;
  75. int count;
  76. int current;
  77. bool dirty;
  78. void set_current(int i);
  79. int get_ofs(int item);
  80. virtual void refresh_screen() = 0;
  81. virtual PopupMenu *create_popupmenu(PulldownMenu mnu) = 0;
  82. virtual bool handle_event(const Event &evt);
  83. public:
  84. HAS_ACTIONS_MAP(Menubar, Dispatcher);
  85. HAS_BINDINGS_MAP(Menubar, Dispatcher);
  86. Menubar();
  87. void init(MenubarItem *aMnu);
  88. void exec();
  89. INTERACTIVE void select();
  90. INTERACTIVE void next_menu();
  91. INTERACTIVE void prev_menu();
  92. INTERACTIVE void screen_resize();
  93. // from base Widget class:
  94. virtual bool is_dirty() const { return dirty; }
  95. virtual void invalidate_view() { dirty = true; }
  96. virtual void update();
  97. virtual void resize(int lines, int columns, int y, int x);
  98. };
  99. #endif