1 #ifndef __YBUTTON_H 2 #define __YBUTTON_H 3 4 #include "ywindow.h" 5 #include "yaction.h" 6 7 class YMenu; 8 class YIcon; 9 10 class YButton: public YWindow { 11 public: 12 YButton(YWindow *parent, YAction action, YMenu *popup = nullptr); 13 virtual ~YButton(); 14 15 virtual void paint(Graphics &g, const YRect &r); 16 virtual void paintFocus(Graphics &g, const YRect &r); 17 virtual bool handleKey(const XKeyEvent &key); 18 virtual void handleButton(const XButtonEvent &button); 19 virtual void handleClick(const XButtonEvent &button, int count); 20 virtual void handleCrossing(const XCrossingEvent &crossing); 21 getAction()22 YAction getAction() const { return fAction; } 23 void setAction(YAction action); 24 void setPopup(YMenu * popup); 25 void setIcon(ref<YIcon> image, int size); 26 void setImage(ref<YImage> image); 27 void setText(const mstring &str, int hot = -1); getText()28 mstring getText() const { return fText; } hasImage()29 bool hasImage() const { return fImage != null; } hasText()30 bool hasText() const { return fText.nonempty(); } hasPopup()31 bool hasPopup() const { return fPopup; } 32 33 void setPressed(int pressed); 34 virtual bool isFocusTraversable(); 35 36 void updateSize(); 37 virtual void donePopup(YPopupWindow *popup); 38 39 virtual void popupMenu(); 40 virtual void updatePopup(); 41 setActionListener(YActionListener * listener)42 void setActionListener(YActionListener *listener) { fListener = listener; } getActionListener()43 YActionListener *getActionListener() const { return fListener; } 44 45 void setSelected(bool selected); 46 void setOver(bool over); 47 48 void setArmed(bool armed, bool mousedown); isPressed()49 bool isPressed() const { return fPressed; } isSelected()50 bool isSelected() const { return fSelected; } isArmed()51 bool isArmed() const { return fArmed; } isPopupActive()52 bool isPopupActive() const { return fPopupActive; } 53 54 virtual void actionPerformed(YAction action, unsigned int modifiers); 55 virtual YFont getFont(); 56 virtual YFont getActiveFont(); 57 virtual YFont getNormalFont(); 58 virtual YColor getColor(); 59 virtual YSurface getSurface(); 60 virtual YDimension getTextSize(); 61 62 void setEnabled(bool enabled); 63 64 protected: 65 bool fOver; 66 67 private: 68 void paint(Graphics &g, int const d, const YRect &r); 69 70 YAction fAction; 71 YMenu *fPopup; 72 ref<YIcon> fIcon; 73 int fIconSize; 74 ref<YImage> fImage; 75 mstring fText; 76 int fPressed; 77 bool fEnabled; 78 int fHotCharPos; 79 int hotKey; 80 81 YActionListener *fListener; 82 83 bool fSelected; 84 bool fArmed; 85 bool wasPopupActive; 86 bool fPopupActive; 87 88 void popup(bool mouseDown); 89 void popdown(); 90 91 protected: 92 static YColorName normalButtonBg; 93 static YColorName normalButtonFg; 94 95 static YColorName activeButtonBg; 96 static YColorName activeButtonFg; 97 98 private: 99 static YFont normalButtonFont; 100 static YFont activeButtonFont; 101 static int buttonObjectCount; 102 }; 103 104 #endif 105 106 // vim: set sw=4 ts=4 et: 107