--- rxvt-unicode/src/scrollbar.h 2008/01/29 13:57:23 1.13 +++ rxvt-unicode/src/scrollbar.h 2011/08/28 18:48:41 1.27 @@ -2,39 +2,80 @@ #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 SB_WIDTH_NEXT 19 +#define SB_WIDTH_XTERM 15 +#define SB_WIDTH_PLAIN 7 +#ifndef SB_WIDTH_RXVT +# define SB_WIDTH_RXVT 10 +#endif + +/* + * NeXT scrollbar defines + */ +#define SB_PADDING 1 +#define SB_BORDER_WIDTH 1 +#define SB_BEVEL_WIDTH_UPPER_LEFT 1 +#define SB_BEVEL_WIDTH_LOWER_RIGHT 2 +#define SB_LEFT_PADDING (SB_PADDING + SB_BORDER_WIDTH) +#define SB_MARGIN_SPACE (SB_PADDING * 2) +#define SB_BUTTON_WIDTH (SB_WIDTH_NEXT - SB_MARGIN_SPACE - SB_BORDER_WIDTH) +#define SB_BUTTON_HEIGHT (SB_BUTTON_WIDTH) +#define SB_BUTTON_SINGLE_HEIGHT (SB_BUTTON_HEIGHT + SB_PADDING) +#define SB_BUTTON_BOTH_HEIGHT (SB_BUTTON_SINGLE_HEIGHT * 2) +#define SB_BUTTON_TOTAL_HEIGHT (SB_BUTTON_BOTH_HEIGHT + SB_PADDING) +#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_OFF, + STATE_IDLE, STATE_MOTION, STATE_UP, STATE_DOWN, }; -struct scrollBar_t { - char state; /* scrollbar state */ +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; + 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 (rxvt_term::*update)(int, int, int, int); + int (scrollBar_t::*update)(int); + void setup (rxvt_term *); + void resize (); + void map (int); + int show (int); + void destroy (); bool upButton (int y) { @@ -52,50 +93,76 @@ return y > end; return false; } -}; + int min_height () + { + return style == R_SB_NEXT ? SB_THUMB_MIN_HEIGHT : 10; + } + int size () + { + return max (end - beg - min_height (), 0); + } + 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; + } -#define scrollbar_TotalWidth() (scrollBar.width + scrollBar.shadow * 2) -#define SCROLLNEXT_MINHEIGHT SB_THUMB_MIN_HEIGHT -#define SCROLLRXVT_MINHEIGHT 10 +#if defined(NEXT_SCROLLBAR) + GC blackGC, + whiteGC, + grayGC, + darkGC, + stippleGC; + Pixmap dimple, + upArrow, + downArrow, + upArrowHi, + downArrowHi; +#endif -#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 +#if defined(RXVT_SCROLLBAR) + GC scrollbarGC, + topShadowGC, + botShadowGC; +#endif -#define SB_WIDTH_NEXT 19 -#define SB_WIDTH_XTERM 15 -#define SB_WIDTH_PLAIN 7 -#ifndef SB_WIDTH_RXVT -# define SB_WIDTH_RXVT 10 +#if defined(XTERM_SCROLLBAR) + GC xscrollbarGC, + ShadowGC; #endif -/* - * NeXT scrollbar defines - */ -#define SB_PADDING 1 -#define SB_BORDER_WIDTH 1 -#define SB_BEVEL_WIDTH_UPPER_LEFT 1 -#define SB_BEVEL_WIDTH_LOWER_RIGHT 2 -#define SB_LEFT_PADDING (SB_PADDING + SB_BORDER_WIDTH) -#define SB_MARGIN_SPACE (SB_PADDING * 2) -#define SB_BUTTON_WIDTH (SB_WIDTH_NEXT - SB_MARGIN_SPACE - SB_BORDER_WIDTH) -#define SB_BUTTON_HEIGHT (SB_BUTTON_WIDTH) -#define SB_BUTTON_SINGLE_HEIGHT (SB_BUTTON_HEIGHT + SB_PADDING) -#define SB_BUTTON_BOTH_HEIGHT (SB_BUTTON_SINGLE_HEIGHT * 2) -#define SB_BUTTON_TOTAL_HEIGHT (SB_BUTTON_BOTH_HEIGHT + SB_PADDING) -#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)) +#if defined(PLAIN_SCROLLBAR) + GC pscrollbarGC; +#endif + +private: + // update style dependent data + void update_data (); + + // scrollbar-next.C + int show_next (int); + // scrollbar-rxvt.C + int show_rxvt (int); + // scrollbar-xterm.C + int show_xterm (int); + // scrollbar-plain.C + int show_plain (int); + + void init_next (); +}; + /* * +-------------+ * | | <---< SB_PADDING