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