1 #ifndef YMENU_H 2 #define YMENU_H 3 4 #include "ypopup.h" 5 #include "ytimer.h" 6 7 class YAction; 8 class YActionListener; 9 class YMenuItem; 10 11 class YMenu: public YPopupWindow, public YTimerListener { 12 public: 13 YMenu(YWindow *parent = nullptr); 14 virtual ~YMenu(); 15 16 virtual void sizePopup(int hspace); 17 virtual void activatePopup(int flags); 18 virtual void deactivatePopup(); 19 virtual void donePopup(YPopupWindow *popup); 20 21 virtual void paint(Graphics &g, const YRect &r); 22 23 virtual bool handleKey(const XKeyEvent &key); 24 virtual void handleButton(const XButtonEvent &button); 25 virtual void handleMotion(const XMotionEvent &motion); 26 virtual void handleMotionOutside(bool top, const XMotionEvent &motion); 27 virtual bool handleAutoScroll(const XMotionEvent &mouse); 28 virtual void configure(const YRect2& r2); handleExpose(const XExposeEvent & expose)29 virtual void handleExpose(const XExposeEvent &expose) {} 30 virtual void repaint(); 31 32 void trackMotion(const int x_root, const int y_root, const unsigned state, bool submenu); 33 34 YMenuItem *add(YMenuItem *item, const char *icons); 35 YMenuItem *addItem(const mstring &name, int hotCharPos, const mstring ¶m, YAction action, const char *icons); 36 YMenuItem *addItem(const mstring &name, int hotCharPos, YAction action, YMenu *submenu, const char *icons); 37 YMenuItem *addSubmenu(const mstring &name, int hotCharPos, YMenu *submenu, const char *icons); 38 39 YMenuItem *add(YMenuItem *item); 40 YMenuItem *addSorted(YMenuItem *item, bool duplicates, bool ignoreCase = false); 41 YMenuItem *addItem(const mstring &name, int hotCharPos, const mstring ¶m, YAction action); 42 YMenuItem *addItem(const mstring &name, int hotCharPos, YAction action, YMenu *submenu); 43 YMenuItem *addSubmenu(const mstring &name, int hotCharPos, YMenu *submenu); 44 void addSeparator(); 45 YMenuItem *addLabel(const mstring &name); 46 void removeAll(); 47 YMenuItem *findAction(YAction action); 48 YMenuItem *findSubmenu(const YMenu *sub); 49 YMenuItem *findName(const mstring &name, const int first = 0); 50 int findFirstLetRef(char firstLetter, int first, bool ignoreCase = true); 51 52 void enableCommand(YAction action); // 0 == All 53 void disableCommand(YAction action); // 0 == All 54 void checkCommand(YAction action, bool check); // 0 == All 55 itemCount()56 int itemCount() const { return fItems.getCount(); } getSelectedItem()57 int getSelectedItem() const { return selectedItem; } 58 bool lastIsSeparator() const; 59 YMenuItem *lastItem() const; getItem(int n)60 YMenuItem *getItem(int n) const { return fItems[n]; } setItem(int n,YMenuItem * ref)61 void setItem(int n, YMenuItem *ref) { fItems[n] = ref; return; } 62 void focusItem(int item); 63 isShared()64 bool isShared() const { return fShared; } setShared(bool shared)65 void setShared(bool shared) { fShared = shared; } 66 67 virtual void setActionListener(YActionListener *actionListener); getActionListener()68 virtual YActionListener *getActionListener() const { return fActionListener; } 69 70 virtual bool handleTimer(YTimer *timer); 71 virtual void raise(); 72 73 private: 74 YObjectArray<YMenuItem> fItems; 75 int selectedItem; 76 int paintedItem; 77 int paramPos; 78 int namePos; 79 YPopupWindow *fPopup; 80 YPopupWindow *fPopupActive; 81 bool fShared; 82 bool fRaised; 83 YActionListener *fActionListener; 84 int activatedX, activatedY; 85 int submenuItem; 86 87 GraphicsBuffer fGraphics; 88 ref<YPixmap> fGradient; 89 ref<YPixmap> fMenusel; 90 91 static YMenu *fPointedMenu; 92 static lazy<YTimer> fMenuTimer; 93 int fTimerX, fTimerY; 94 int fTimerSubmenuItem; 95 static int fAutoScrollDeltaX, fAutoScrollDeltaY; 96 static int fAutoScrollMouseX, fAutoScrollMouseY; 97 static int fMenuObjectCount; 98 99 void getOffsets(int &left, int &top, int &right, int &bottom); 100 void getArea(int &x, int &y, unsigned &w, unsigned &h); 101 102 void drawBackground(Graphics &g, int x, int y, int w, int h); 103 void drawSeparator(Graphics &g, int x, int y, unsigned w); 104 105 void drawSubmenuArrow(Graphics &g, YMenuItem *mitem, 106 int left, int top); 107 void paintItem(Graphics &g, const int i, const int l, const int t, 108 const int r, const int minY, const int maxY, const int eh, 109 const int top, const int bottom, const int pad); 110 111 void repaintItem(int item); 112 void paintItems(); 113 int findItemPos(int item, int &x, int &y, unsigned &h); 114 int findItem(int x, int y); 115 int findActiveItem(int cur, int direction); 116 int findHotItem(char k); 117 void activateSubMenu(int item, bool byMouse); 118 119 int activateItem(int modifiers, bool byMouse = false); 120 bool isCondCascade(int selectedItem); 121 int onCascadeButton(int selectedItem, int x, int y, bool checkPopup); 122 123 void autoScroll(int deltaX, int deltaY, int mx, int my, const XMotionEvent *motion); 124 void finishPopup(YMenuItem *item, YAction action, unsigned int modifiers); 125 void hideSubmenu(); 126 }; 127 128 class LazyMenu { 129 public: 130 virtual YMenu* ymenu() = 0; ~LazyMenu()131 virtual ~LazyMenu() {} 132 }; 133 134 extern ref<YPixmap> menubackPixmap; 135 extern ref<YPixmap> menuselPixmap; 136 extern ref<YPixmap> menusepPixmap; 137 138 extern ref<YImage> menubackPixbuf; 139 extern ref<YImage> menuselPixbuf; 140 extern ref<YImage> menusepPixbuf; 141 142 #endif 143 144 // vim: set sw=4 ts=4 et: 145