… | |
… | |
2 | #define SCROLLBAR_H |
2 | #define SCROLLBAR_H |
3 | |
3 | |
4 | #include <X11/Xlib.h> |
4 | #include <X11/Xlib.h> |
5 | |
5 | |
6 | struct rxvt_term; |
6 | struct rxvt_term; |
7 | |
|
|
8 | typedef struct { |
|
|
9 | char state; /* scrollbar state */ |
|
|
10 | char init; /* scrollbar has been initialised */ |
|
|
11 | unsigned int beg; /* slider sub-window begin height */ |
|
|
12 | unsigned int end; /* slider sub-window end height */ |
|
|
13 | unsigned int top; /* slider top position */ |
|
|
14 | unsigned int bot; /* slider bottom position */ |
|
|
15 | unsigned int style; /* style: rxvt, xterm, next */ |
|
|
16 | unsigned int width; /* scrollbar width */ |
|
|
17 | int sb_shadow; /* scrollbar shadow width */ |
|
|
18 | Window win; |
|
|
19 | int (rxvt_term::*update)(int, int, int, int); |
|
|
20 | |
|
|
21 | void setIdle() { state = 1 ; } |
|
|
22 | void setMotion() { state = 'm'; } |
|
|
23 | void setUp() { state = 'U'; } |
|
|
24 | void setDn() { state = 'D'; } |
|
|
25 | } scrollBar_t; |
|
|
26 | |
|
|
27 | #define scrollbar_TotalWidth() (scrollBar.width + scrollBar.sb_shadow * 2) |
|
|
28 | #define scrollbar_isMotion() (scrollBar.state == 'm') |
|
|
29 | #define scrollbar_isUp() (scrollBar.state == 'U') |
|
|
30 | #define scrollbar_isDn() (scrollBar.state == 'D') |
|
|
31 | #define scrollbar_isUpDn() isupper (scrollBar.state) |
|
|
32 | #define isScrollbarWindow(w) (scrollBar.state && (w) == scrollBar.win) |
|
|
33 | |
|
|
34 | #define scrollbarnext_dnval() (scrollBar.end + (scrollBar.width + 1)) |
|
|
35 | #define scrollbarnext_upButton(y) ((y) > scrollBar.end \ |
|
|
36 | && (y) <= scrollbarnext_dnval ()) |
|
|
37 | #define scrollbarnext_dnButton(y) ((y) > scrollbarnext_dnval()) |
|
|
38 | #define SCROLLNEXT_MINHEIGHT SB_THUMB_MIN_HEIGHT |
|
|
39 | #define scrollbarrxvt_upButton(y) ((y) < scrollBar.beg) |
|
|
40 | #define scrollbarrxvt_dnButton(y) ((y) > scrollBar.end) |
|
|
41 | #define SCROLLRXVT_MINHEIGHT 10 |
|
|
42 | #define SCROLLXTERM_MINHEIGHT 10 |
|
|
43 | |
|
|
44 | #define scrollbar_minheight() (scrollBar.style == R_SB_NEXT \ |
|
|
45 | ? SCROLLNEXT_MINHEIGHT \ |
|
|
46 | : SCROLLRXVT_MINHEIGHT) |
|
|
47 | #define scrollbar_above_slider(y) ((y) < scrollBar.top) |
|
|
48 | #define scrollbar_below_slider(y) ((y) > scrollBar.bot) |
|
|
49 | #define scrollbar_position(y) ((y) - scrollBar.beg) |
|
|
50 | #define scrollbar_size() (scrollBar.end - scrollBar.beg \ |
|
|
51 | - scrollbar_minheight ()) |
|
|
52 | |
|
|
53 | #define R_SB_ALIGN_CENTRE 0 |
|
|
54 | #define R_SB_ALIGN_TOP 1 |
|
|
55 | #define R_SB_ALIGN_BOTTOM 2 |
|
|
56 | |
|
|
57 | #define R_SB_NEXT 1 |
|
|
58 | #define R_SB_XTERM 2 |
|
|
59 | #define R_SB_PLAIN 4 |
|
|
60 | #define R_SB_RXVT 8 |
|
|
61 | |
7 | |
62 | #define SB_WIDTH_NEXT 19 |
8 | #define SB_WIDTH_NEXT 19 |
63 | #define SB_WIDTH_XTERM 15 |
9 | #define SB_WIDTH_XTERM 15 |
64 | #define SB_WIDTH_PLAIN 7 |
10 | #define SB_WIDTH_PLAIN 7 |
65 | #ifndef SB_WIDTH_RXVT |
11 | #ifndef SB_WIDTH_RXVT |
… | |
… | |
81 | #define SB_BUTTON_BOTH_HEIGHT (SB_BUTTON_SINGLE_HEIGHT * 2) |
27 | #define SB_BUTTON_BOTH_HEIGHT (SB_BUTTON_SINGLE_HEIGHT * 2) |
82 | #define SB_BUTTON_TOTAL_HEIGHT (SB_BUTTON_BOTH_HEIGHT + SB_PADDING) |
28 | #define SB_BUTTON_TOTAL_HEIGHT (SB_BUTTON_BOTH_HEIGHT + SB_PADDING) |
83 | #define SB_BUTTON_BEVEL_X (SB_LEFT_PADDING) |
29 | #define SB_BUTTON_BEVEL_X (SB_LEFT_PADDING) |
84 | #define SB_BUTTON_FACE_X (SB_BUTTON_BEVEL_X + SB_BEVEL_WIDTH_UPPER_LEFT) |
30 | #define SB_BUTTON_FACE_X (SB_BUTTON_BEVEL_X + SB_BEVEL_WIDTH_UPPER_LEFT) |
85 | #define SB_THUMB_MIN_HEIGHT (SB_BUTTON_WIDTH - (SB_PADDING * 2)) |
31 | #define SB_THUMB_MIN_HEIGHT (SB_BUTTON_WIDTH - (SB_PADDING * 2)) |
|
|
32 | |
|
|
33 | enum sb_state { |
|
|
34 | STATE_OFF, |
|
|
35 | STATE_IDLE, |
|
|
36 | STATE_MOTION, |
|
|
37 | STATE_UP, |
|
|
38 | STATE_DOWN, |
|
|
39 | }; |
|
|
40 | |
|
|
41 | enum sb_style { |
|
|
42 | R_SB_NEXT = 1, |
|
|
43 | R_SB_XTERM = 2, |
|
|
44 | R_SB_PLAIN = 4, |
|
|
45 | R_SB_RXVT = 8, |
|
|
46 | }; |
|
|
47 | |
|
|
48 | enum sb_align { |
|
|
49 | R_SB_ALIGN_CENTRE, |
|
|
50 | R_SB_ALIGN_TOP, |
|
|
51 | R_SB_ALIGN_BOTTOM, |
|
|
52 | }; |
|
|
53 | |
|
|
54 | struct scrollBar_t |
|
|
55 | { |
|
|
56 | rxvt_term *term; |
|
|
57 | sb_state state; /* scrollbar state */ |
|
|
58 | char init; /* scrollbar has been initialised */ |
|
|
59 | unsigned int beg; /* slider sub-window begin height */ |
|
|
60 | unsigned int end; /* slider sub-window end height */ |
|
|
61 | unsigned int top; /* slider top position */ |
|
|
62 | unsigned int bot; /* slider bottom position */ |
|
|
63 | sb_style style; /* style: rxvt, xterm, next */ |
|
|
64 | unsigned int width; /* scrollbar width */ |
|
|
65 | int shadow; /* scrollbar shadow width */ |
|
|
66 | int last_bot; /* scrollbar last bottom position */ |
|
|
67 | int last_top; /* scrollbar last top position */ |
|
|
68 | int last_state; /* scrollbar last state */ |
|
|
69 | sb_align align; |
|
|
70 | Window win; |
|
|
71 | Cursor leftptr_cursor; |
|
|
72 | int (scrollBar_t::*update)(int); |
|
|
73 | void setup (rxvt_term *); |
|
|
74 | void resize (); |
|
|
75 | int map (int); |
|
|
76 | int show (int); |
|
|
77 | void destroy (); |
|
|
78 | |
|
|
79 | bool upButton (int y) |
|
|
80 | { |
|
|
81 | if (style == R_SB_NEXT) |
|
|
82 | return y > end && y <= end + width + 1; |
|
|
83 | if (style == R_SB_RXVT) |
|
|
84 | return y < beg; |
|
|
85 | return false; |
|
|
86 | } |
|
|
87 | bool dnButton (int y) |
|
|
88 | { |
|
|
89 | if (style == R_SB_NEXT) |
|
|
90 | return y > end + width + 1; |
|
|
91 | if (style == R_SB_RXVT) |
|
|
92 | return y > end; |
|
|
93 | return false; |
|
|
94 | } |
|
|
95 | unsigned min_height () |
|
|
96 | { |
|
|
97 | return style == R_SB_NEXT ? SB_THUMB_MIN_HEIGHT : 10; |
|
|
98 | } |
|
|
99 | unsigned size () |
|
|
100 | { |
|
|
101 | return end - beg - min_height (); |
|
|
102 | } |
|
|
103 | unsigned total_width () |
|
|
104 | { |
|
|
105 | return width + shadow * 2; |
|
|
106 | } |
|
|
107 | |
|
|
108 | #if defined(NEXT_SCROLLBAR) |
|
|
109 | GC blackGC, |
|
|
110 | whiteGC, |
|
|
111 | grayGC, |
|
|
112 | darkGC, |
|
|
113 | stippleGC; |
|
|
114 | Pixmap dimple, |
|
|
115 | upArrow, |
|
|
116 | downArrow, |
|
|
117 | upArrowHi, |
|
|
118 | downArrowHi; |
|
|
119 | #endif |
|
|
120 | |
|
|
121 | #if defined(RXVT_SCROLLBAR) |
|
|
122 | GC scrollbarGC, |
|
|
123 | topShadowGC, |
|
|
124 | botShadowGC; |
|
|
125 | #endif |
|
|
126 | |
|
|
127 | #if defined(XTERM_SCROLLBAR) |
|
|
128 | GC xscrollbarGC, |
|
|
129 | ShadowGC; |
|
|
130 | #endif |
|
|
131 | |
|
|
132 | #if defined(PLAIN_SCROLLBAR) |
|
|
133 | GC pscrollbarGC; |
|
|
134 | #endif |
|
|
135 | |
|
|
136 | private: |
|
|
137 | // update style dependent data |
|
|
138 | void update_data (); |
|
|
139 | |
|
|
140 | // scrollbar-next.C |
|
|
141 | int show_next (int); |
|
|
142 | // scrollbar-rxvt.C |
|
|
143 | int show_rxvt (int); |
|
|
144 | // scrollbar-xterm.C |
|
|
145 | int show_xterm (int); |
|
|
146 | // scrollbar-plain.C |
|
|
147 | int show_plain (int); |
|
|
148 | |
|
|
149 | void init_next (); |
|
|
150 | }; |
|
|
151 | |
|
|
152 | #define scrollbar_above_slider(y) ((y) < scrollBar.top) |
|
|
153 | #define scrollbar_below_slider(y) ((y) > scrollBar.bot) |
|
|
154 | #define scrollbar_position(y) ((y) - scrollBar.beg) |
|
|
155 | |
86 | /* |
156 | /* |
87 | * +-------------+ |
157 | * +-------------+ |
88 | * | | <---< SB_PADDING |
158 | * | | <---< SB_PADDING |
89 | * | ::::::::::: | |
159 | * | ::::::::::: | |
90 | * | ::::::::::: | |
160 | * | ::::::::::: | |