--- rxvt-unicode/src/scrollbar.h 2007/12/29 12:03:39 1.1 +++ rxvt-unicode/src/scrollbar.h 2008/02/17 12:11:56 1.17 @@ -5,58 +5,15 @@ struct rxvt_term; -typedef struct { - char 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 */ - Window win; - int (rxvt_term::*update)(int, int, int, int); - - void setIdle() { state = 1 ; } - void setMotion() { state = 'm'; } - void setUp() { state = 'U'; } - void setDn() { state = 'D'; } -} scrollBar_t; - -#define scrollbar_isMotion() (scrollBar.state == 'm') -#define scrollbar_isUp() (scrollBar.state == 'U') -#define scrollbar_isDn() (scrollBar.state == 'D') -#define scrollbar_isUpDn() isupper (scrollBar.state) -#define isScrollbarWindow(w) (scrollBar.state && (w) == scrollBar.win) - -#define scrollbarnext_dnval() (scrollBar.end + (scrollBar.width + 1)) -#define scrollbarnext_upButton(y) ((y) > scrollBar.end \ - && (y) <= scrollbarnext_dnval ()) -#define scrollbarnext_dnButton(y) ((y) > scrollbarnext_dnval()) -#define SCROLLNEXT_MINHEIGHT SB_THUMB_MIN_HEIGHT -#define scrollbarrxvt_upButton(y) ((y) < scrollBar.beg) -#define scrollbarrxvt_dnButton(y) ((y) > scrollBar.end) -#define SCROLLRXVT_MINHEIGHT 10 -#define SCROLLXTERM_MINHEIGHT 10 - -#define scrollbar_minheight() (scrollBar.style == R_SB_NEXT \ - ? SCROLLNEXT_MINHEIGHT \ - : SCROLLRXVT_MINHEIGHT) -#define scrollbar_above_slider(y) ((y) < scrollBar.top) -#define scrollbar_below_slider(y) ((y) > scrollBar.bot) -#define scrollbar_position(y) ((y) - scrollBar.beg) -#define scrollbar_size() (scrollBar.end - scrollBar.beg \ - - scrollbar_minheight ()) - -#define R_SB_ALIGN_CENTRE 0 -#define R_SB_ALIGN_TOP 1 -#define R_SB_ALIGN_BOTTOM 2 - #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 @@ -81,6 +38,69 @@ #define SB_BUTTON_BEVEL_X (SB_LEFT_PADDING) #define SB_BUTTON_FACE_X (SB_BUTTON_BEVEL_X + SB_BEVEL_WIDTH_UPPER_LEFT) #define SB_THUMB_MIN_HEIGHT (SB_BUTTON_WIDTH - (SB_PADDING * 2)) + +enum sb_state { + STATE_IDLE = 1, + STATE_MOTION, + STATE_UP, + STATE_DOWN, +}; + +struct scrollBar_t { + rxvt_term *term; + char 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 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; + Window win; + Cursor leftptr_cursor; + int (rxvt_term::*update)(int, int, int, int); + void setup (rxvt_term *); + + bool upButton (int y) + { + if (style == R_SB_NEXT) + return y > end && y <= end + width + 1; + if (style == R_SB_RXVT) + return y < beg; + return false; + } + bool dnButton (int y) + { + if (style == R_SB_NEXT) + return y > end + width + 1; + if (style == R_SB_RXVT) + return y > end; + return false; + } + unsigned min_height () + { + return style == R_SB_NEXT ? SB_THUMB_MIN_HEIGHT : 10; + } + unsigned size () + { + return end - beg - min_height (); + } + unsigned total_width () + { + return width + shadow * 2; + } +}; + +#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