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 | 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 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.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() (scrollbar_isUp () || scrollbar_isDn ()) |
|
|
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 | |
|
|
43 | #define scrollbar_minheight() (scrollBar.style == R_SB_NEXT \ |
|
|
44 | ? SCROLLNEXT_MINHEIGHT \ |
|
|
45 | : SCROLLRXVT_MINHEIGHT) |
|
|
46 | #define scrollbar_above_slider(y) ((y) < scrollBar.top) |
|
|
47 | #define scrollbar_below_slider(y) ((y) > scrollBar.bot) |
|
|
48 | #define scrollbar_position(y) ((y) - scrollBar.beg) |
|
|
49 | #define scrollbar_size() (scrollBar.end - scrollBar.beg \ |
|
|
50 | - scrollbar_minheight ()) |
|
|
51 | |
|
|
52 | #define R_SB_ALIGN_CENTRE 0 |
|
|
53 | #define R_SB_ALIGN_TOP 1 |
|
|
54 | #define R_SB_ALIGN_BOTTOM 2 |
|
|
55 | |
|
|
56 | #define R_SB_NEXT 1 |
|
|
57 | #define R_SB_XTERM 2 |
|
|
58 | #define R_SB_PLAIN 4 |
|
|
59 | #define R_SB_RXVT 8 |
|
|
60 | |
8 | |
61 | #define SB_WIDTH_NEXT 19 |
9 | #define SB_WIDTH_NEXT 19 |
62 | #define SB_WIDTH_XTERM 15 |
10 | #define SB_WIDTH_XTERM 15 |
63 | #define SB_WIDTH_PLAIN 7 |
11 | #define SB_WIDTH_PLAIN 7 |
64 | #ifndef SB_WIDTH_RXVT |
12 | #ifndef SB_WIDTH_RXVT |
… | |
… | |
80 | #define SB_BUTTON_BOTH_HEIGHT (SB_BUTTON_SINGLE_HEIGHT * 2) |
28 | #define SB_BUTTON_BOTH_HEIGHT (SB_BUTTON_SINGLE_HEIGHT * 2) |
81 | #define SB_BUTTON_TOTAL_HEIGHT (SB_BUTTON_BOTH_HEIGHT + SB_PADDING) |
29 | #define SB_BUTTON_TOTAL_HEIGHT (SB_BUTTON_BOTH_HEIGHT + SB_PADDING) |
82 | #define SB_BUTTON_BEVEL_X (SB_LEFT_PADDING) |
30 | #define SB_BUTTON_BEVEL_X (SB_LEFT_PADDING) |
83 | #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) |
84 | #define SB_THUMB_MIN_HEIGHT (SB_BUTTON_WIDTH - (SB_PADDING * 2)) |
32 | #define SB_THUMB_MIN_HEIGHT (SB_BUTTON_WIDTH - (SB_PADDING * 2)) |
|
|
33 | |
|
|
34 | enum sb_state { |
|
|
35 | STATE_OFF, |
|
|
36 | STATE_IDLE, |
|
|
37 | STATE_MOTION, |
|
|
38 | STATE_UP, |
|
|
39 | STATE_DOWN, |
|
|
40 | }; |
|
|
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 | |
|
|
55 | struct scrollBar_t |
|
|
56 | { |
|
|
57 | rxvt_term *term; |
|
|
58 | sb_state state; /* scrollbar state */ |
|
|
59 | char init; /* scrollbar has been initialised */ |
|
|
60 | int beg; /* slider sub-window begin height */ |
|
|
61 | int end; /* slider sub-window end height */ |
|
|
62 | int top; /* slider top position */ |
|
|
63 | int bot; /* slider bottom position */ |
|
|
64 | sb_style style; /* style: rxvt, xterm, next */ |
|
|
65 | int width; /* scrollbar width */ |
|
|
66 | int shadow; /* scrollbar shadow width */ |
|
|
67 | int last_bot; /* scrollbar last bottom position */ |
|
|
68 | int last_top; /* scrollbar last top position */ |
|
|
69 | int last_state; /* scrollbar last state */ |
|
|
70 | sb_align align; |
|
|
71 | Window win; |
|
|
72 | Cursor leftptr_cursor; |
|
|
73 | int (scrollBar_t::*update)(int); |
|
|
74 | void setup (rxvt_term *); |
|
|
75 | void resize (); |
|
|
76 | void map (int); |
|
|
77 | int show (int); |
|
|
78 | void destroy (); |
|
|
79 | |
|
|
80 | bool upButton (int y) |
|
|
81 | { |
|
|
82 | if (style == R_SB_NEXT) |
|
|
83 | return y > end && y <= end + width + 1; |
|
|
84 | if (style == R_SB_RXVT) |
|
|
85 | return y < beg; |
|
|
86 | return false; |
|
|
87 | } |
|
|
88 | bool dnButton (int y) |
|
|
89 | { |
|
|
90 | if (style == R_SB_NEXT) |
|
|
91 | return y > end + width + 1; |
|
|
92 | if (style == R_SB_RXVT) |
|
|
93 | return y > end; |
|
|
94 | return false; |
|
|
95 | } |
|
|
96 | int min_height () |
|
|
97 | { |
|
|
98 | return style == R_SB_NEXT ? SB_THUMB_MIN_HEIGHT : 10; |
|
|
99 | } |
|
|
100 | int size () |
|
|
101 | { |
|
|
102 | return max (end - beg - min_height (), 0); |
|
|
103 | } |
|
|
104 | int total_width () |
|
|
105 | { |
|
|
106 | return width + shadow * 2; |
|
|
107 | } |
|
|
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 | } |
|
|
120 | |
|
|
121 | |
|
|
122 | #if defined(NEXT_SCROLLBAR) |
|
|
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 | }; |
|
|
165 | |
85 | /* |
166 | /* |
86 | * +-------------+ |
167 | * +-------------+ |
87 | * | | <---< SB_PADDING |
168 | * | | <---< SB_PADDING |
88 | * | ::::::::::: | |
169 | * | ::::::::::: | |
89 | * | ::::::::::: | |
170 | * | ::::::::::: | |