1 #ifndef YSCROLLBAR_H 2 #define YSCROLLBAR_H 3 4 #include "ywindow.h" 5 #include "ytimer.h" 6 7 #define SCROLLBAR_MIN 8 8 9 class YScrollBar; 10 11 class YScrollBarListener { 12 public: 13 virtual void scroll(YScrollBar *scroll, int delta) = 0; 14 virtual void move(YScrollBar *scroll, int pos) = 0; 15 protected: ~YScrollBarListener()16 virtual ~YScrollBarListener() {} 17 }; 18 19 class YScrollBar: public YWindow, public YTimerListener { 20 public: 21 enum Orientation { 22 Vertical, Horizontal 23 }; 24 25 YScrollBar(Orientation anOrientation, YWindow *aParent); 26 virtual ~YScrollBar(); 27 getOrientation()28 Orientation getOrientation() const { return fOrientation; } getMaximum()29 int getMaximum() const { return fMaximum; } getMinimum()30 int getMinimum() const { return fMinimum; } getVisibleAmount()31 int getVisibleAmount() const { return fVisibleAmount; } getUnitIncrement()32 int getUnitIncrement() const { return fUnitIncrement; } getBlockIncrement()33 int getBlockIncrement() const { return fBlockIncrement; } getValue()34 int getValue() const { return fValue; } 35 36 void enable(); 37 void setOrientation(Orientation anOrientation); 38 void setMaximum(int aMaximum); 39 void setMinimum(int aMinimum); 40 void setVisibleAmount(int aVisibleAmount); 41 void setUnitIncrement(int anUnitIncrement); 42 void setBlockIncrement(int aBlockIncrement); 43 void setValue(int aValue); 44 void setValues(int aValue, int aVisibleAmount, int aMin, int aMax); 45 46 bool handleScrollKeys(const XKeyEvent &key); 47 bool handleScrollMouse(const XButtonEvent &button); 48 49 private: 50 Orientation fOrientation; 51 int fMaximum; 52 int fMinimum; 53 int fValue; 54 int fVisibleAmount; 55 int fUnitIncrement; 56 int fBlockIncrement; 57 public: 58 void scroll(int delta); 59 void move(int pos); 60 61 virtual void configure(const YRect2& r); 62 virtual void repaint(); 63 virtual void paint(Graphics &g, const YRect &r); 64 virtual void handleExpose(const XExposeEvent &expose); 65 virtual void handleButton(const XButtonEvent &button); 66 virtual void handleMotion(const XMotionEvent &motion); 67 virtual bool handleTimer(YTimer *timer); 68 virtual void handleDNDEnter(); 69 virtual void handleDNDLeave(); 70 virtual void handleDNDPosition(int x, int y); setScrollBarListener(YScrollBarListener * notify)71 void setScrollBarListener(YScrollBarListener *notify) { fListener = notify; } 72 static YColor background(); 73 static void reverseVideo(); 74 75 private: 76 enum ScrollOp { 77 goUp, goDown, goPageUp, goPageDown, goPosition, goNone 78 } fScrollTo; 79 80 void doScroll(); 81 void getCoord(int &beg, int &end, int &min, int &max, int &nn); 82 ScrollOp getOp(int x, int y); 83 84 int fGrabDelta; 85 YScrollBarListener *fListener; 86 bool fDNDScroll; 87 bool fConfigured; 88 bool fExposed; 89 static lazy<YTimer> fScrollTimer; 90 }; 91 92 #endif 93 94 // vim: set sw=4 ts=4 et: 95