--- rxvt-unicode/src/scrollbar.h 2008/02/19 13:01:33 1.20 +++ rxvt-unicode/src/scrollbar.h 2011/08/28 18:48:41 1.27 @@ -2,18 +2,10 @@ #define SCROLLBAR_H #include +#include "rxvtutil.h" struct rxvt_term; -#define R_SB_NEXT 1 -#define R_SB_XTERM 2 -#define R_SB_PLAIN 4 -#define R_SB_RXVT 8 - -#define R_SB_ALIGN_CENTRE 0 -#define R_SB_ALIGN_TOP 1 -#define R_SB_ALIGN_BOTTOM 2 - #define SB_WIDTH_NEXT 19 #define SB_WIDTH_XTERM 15 #define SB_WIDTH_PLAIN 7 @@ -40,36 +32,48 @@ #define SB_THUMB_MIN_HEIGHT (SB_BUTTON_WIDTH - (SB_PADDING * 2)) enum sb_state { - STATE_IDLE = 1, + STATE_OFF, + STATE_IDLE, STATE_MOTION, STATE_UP, STATE_DOWN, }; -struct scrollBar_t { +enum sb_style { + R_SB_NEXT = 1, + R_SB_XTERM = 2, + R_SB_PLAIN = 4, + R_SB_RXVT = 8, +}; + +enum sb_align { + R_SB_ALIGN_CENTRE, + R_SB_ALIGN_TOP, + R_SB_ALIGN_BOTTOM, +}; + +struct scrollBar_t +{ rxvt_term *term; - char state; /* scrollbar state */ + sb_state state; /* scrollbar state */ char init; /* scrollbar has been initialised */ - unsigned int beg; /* slider sub-window begin height */ - unsigned int end; /* slider sub-window end height */ - unsigned int top; /* slider top position */ - unsigned int bot; /* slider bottom position */ - unsigned int style; /* style: rxvt, xterm, next */ - unsigned int width; /* scrollbar width */ + int beg; /* slider sub-window begin height */ + int end; /* slider sub-window end height */ + int top; /* slider top position */ + int bot; /* slider bottom position */ + sb_style style; /* style: rxvt, xterm, next */ + int width; /* scrollbar width */ int shadow; /* scrollbar shadow width */ int last_bot; /* scrollbar last bottom position */ int last_top; /* scrollbar last top position */ int last_state; /* scrollbar last state */ - int len; - unsigned char align; + sb_align align; Window win; Cursor leftptr_cursor; int (scrollBar_t::*update)(int); void setup (rxvt_term *); - // update style dependent data - void update_data (); void resize (); - int map (int); + void map (int); int show (int); void destroy (); @@ -89,18 +93,31 @@ return y > end; return false; } - unsigned min_height () + int min_height () { return style == R_SB_NEXT ? SB_THUMB_MIN_HEIGHT : 10; } - unsigned size () + int size () { - return end - beg - min_height (); + return max (end - beg - min_height (), 0); } - unsigned total_width () + int total_width () { return width + shadow * 2; } + bool above_slider (int y) + { + return y < top; + } + bool below_slider (int y) + { + return y > bot; + } + int position (int y) + { + return y - beg; + } + #if defined(NEXT_SCROLLBAR) GC blackGC, @@ -130,6 +147,10 @@ GC pscrollbarGC; #endif +private: + // update style dependent data + void update_data (); + // scrollbar-next.C int show_next (int); // scrollbar-rxvt.C @@ -139,14 +160,9 @@ // scrollbar-plain.C int show_plain (int); -private: void init_next (); }; -#define scrollbar_above_slider(y) ((y) < scrollBar.top) -#define scrollbar_below_slider(y) ((y) > scrollBar.bot) -#define scrollbar_position(y) ((y) - scrollBar.beg) - /* * +-------------+ * | | <---< SB_PADDING