… | |
… | |
34 | int |
34 | int |
35 | rxvt_term::scrollbar_mapping (int map) |
35 | rxvt_term::scrollbar_mapping (int map) |
36 | { |
36 | { |
37 | int change = 0; |
37 | int change = 0; |
38 | |
38 | |
39 | #ifdef HAVE_SCROLLBARS |
|
|
40 | if (map) |
39 | if (map) |
41 | { |
40 | { |
42 | scrollBar.setIdle (); |
41 | scrollBar.state = STATE_IDLE; |
43 | |
42 | |
44 | if (!scrollBar.win) |
43 | if (!scrollBar.win) |
45 | resize_scrollbar (); |
44 | resize_scrollbar (); |
46 | |
45 | |
47 | if (scrollBar.win) |
46 | if (scrollBar.win) |
… | |
… | |
54 | { |
53 | { |
55 | scrollBar.state = 0; |
54 | scrollBar.state = 0; |
56 | XUnmapWindow (dpy, scrollBar.win); |
55 | XUnmapWindow (dpy, scrollBar.win); |
57 | change = 1; |
56 | change = 1; |
58 | } |
57 | } |
59 | #endif |
|
|
60 | |
58 | |
61 | return change; |
59 | return change; |
62 | } |
60 | } |
63 | |
61 | |
64 | void |
62 | void |
65 | rxvt_term::resize_scrollbar () |
63 | rxvt_term::resize_scrollbar () |
66 | { |
64 | { |
67 | #ifdef HAVE_SCROLLBARS |
|
|
68 | int delayed_init = 0; |
65 | int delayed_init = 0; |
|
|
66 | int window_sb_x = 0; |
|
|
67 | |
|
|
68 | if (option (Opt_scrollBar_right)) |
|
|
69 | window_sb_x = szHint.width - scrollBar.total_width (); |
69 | |
70 | |
70 | #define R_SCROLLBEG_XTERM 0 |
71 | #define R_SCROLLBEG_XTERM 0 |
71 | #define R_SCROLLEND_XTERM szHint.height |
72 | #define R_SCROLLEND_XTERM szHint.height |
72 | #define R_SCROLLBEG_NEXT 0 |
73 | #define R_SCROLLBEG_NEXT 0 |
73 | #define R_SCROLLEND_NEXT szHint.height - (SB_BUTTON_TOTAL_HEIGHT + \ |
74 | #define R_SCROLLEND_NEXT szHint.height - (SB_BUTTON_TOTAL_HEIGHT + \ |
… | |
… | |
113 | { |
114 | { |
114 | /* create the scrollbar window */ |
115 | /* create the scrollbar window */ |
115 | scrollBar.win = XCreateSimpleWindow (dpy, |
116 | scrollBar.win = XCreateSimpleWindow (dpy, |
116 | parent[0], |
117 | parent[0], |
117 | window_sb_x, 0, |
118 | window_sb_x, 0, |
118 | scrollbar_TotalWidth (), |
119 | scrollBar.total_width (), |
119 | szHint.height, |
120 | szHint.height, |
120 | 0, |
121 | 0, |
121 | pix_colors[Color_fg], |
122 | pix_colors[Color_fg], |
122 | pix_colors[Color_border]); |
123 | pix_colors[Color_border]); |
123 | XDefineCursor (dpy, scrollBar.win, leftptr_cursor); |
124 | XDefineCursor (dpy, scrollBar.win, scrollBar.leftptr_cursor); |
124 | |
125 | |
125 | XSelectInput (dpy, scrollBar.win, |
126 | XSelectInput (dpy, scrollBar.win, |
126 | ExposureMask | ButtonPressMask | ButtonReleaseMask |
127 | ExposureMask | ButtonPressMask | ButtonReleaseMask |
127 | | Button1MotionMask | Button2MotionMask |
128 | | Button1MotionMask | Button2MotionMask |
128 | | Button3MotionMask); |
129 | | Button3MotionMask); |
129 | scrollbar_ev.start (display, scrollBar.win); |
130 | scrollbar_ev.start (display, scrollBar.win); |
130 | |
131 | |
131 | delayed_init = 1; |
132 | delayed_init = 1; |
132 | } |
133 | } |
|
|
134 | else |
|
|
135 | XMoveResizeWindow (dpy, scrollBar.win, |
|
|
136 | window_sb_x, 0, |
|
|
137 | scrollBar.total_width (), szHint.height); |
133 | |
138 | |
134 | scrollbar_show (1); |
139 | scrollbar_show (1); |
135 | |
140 | |
136 | if (delayed_init) |
141 | if (delayed_init) |
137 | XMapWindow (dpy, scrollBar.win); |
142 | XMapWindow (dpy, scrollBar.win); |
138 | #endif |
|
|
139 | } |
143 | } |
140 | |
144 | |
141 | /* |
145 | /* |
142 | * Update current scrollbar view w.r.t. slider heights, etc. |
146 | * Update current scrollbar view w.r.t. slider heights, etc. |
143 | */ |
147 | */ |
144 | int |
148 | int |
145 | rxvt_term::scrollbar_show (int update) |
149 | rxvt_term::scrollbar_show (int update) |
146 | { |
150 | { |
147 | int ret = 0; |
151 | int ret = 0; |
148 | #ifdef HAVE_SCROLLBARS |
|
|
149 | int top, bot, len, adj; |
|
|
150 | |
152 | |
151 | if (!scrollBar.state) |
153 | if (!scrollBar.state) |
152 | return 0; |
154 | return 0; |
153 | |
155 | |
154 | if (update) |
156 | if (update) |
155 | { |
157 | { |
156 | top = view_start - top_row; |
158 | int top = view_start - top_row; |
157 | bot = top + (nrow - 1); |
159 | int bot = top + (nrow - 1); |
158 | len = max (nrow - 1 - top_row, 1); |
160 | int len = max (nrow - 1 - top_row, 1); |
159 | adj = (((bot - top) * scrollbar_size ()) % len) > 0 ? 1 : 0; |
161 | int adj = (((bot - top) * scrollBar.size ()) % len) > 0 ? 1 : 0; |
160 | |
162 | |
161 | scrollBar.top = (scrollBar.beg + (top * scrollbar_size ()) / len); |
163 | scrollBar.top = (scrollBar.beg + (top * scrollBar.size ()) / len); |
162 | scrollBar.len = ((bot - top) * scrollbar_size ()) / len + |
164 | scrollBar.len = ((bot - top) * scrollBar.size ()) / len + |
163 | scrollbar_minheight () + adj; |
165 | scrollBar.min_height () + adj; |
164 | scrollBar.bot = (scrollBar.top + scrollBar.len); |
166 | scrollBar.bot = (scrollBar.top + scrollBar.len); |
165 | /* no change */ |
167 | /* no change */ |
166 | if (scrollBar.top == scrollBar.last_top |
168 | if (scrollBar.top == scrollBar.last_top |
167 | && scrollBar.bot == scrollBar.last_bot |
169 | && scrollBar.bot == scrollBar.last_bot |
168 | && (scrollBar.state == scrollBar.last_state || !scrollbar_isUpDn ())) |
170 | && (scrollBar.state == scrollBar.last_state |
|
|
171 | || !(scrollBar.state == STATE_UP || scrollBar.state == STATE_DOWN))) |
169 | return 0; |
172 | return 0; |
170 | } |
173 | } |
171 | |
174 | |
172 | ret = (this->*scrollBar.update) (update, scrollBar.last_top, scrollBar.last_bot, scrollBar.len); |
175 | ret = (this->*scrollBar.update) (update, scrollBar.last_top, scrollBar.last_bot, scrollBar.len); |
173 | |
176 | |
174 | scrollBar.last_top = scrollBar.top; |
177 | scrollBar.last_top = scrollBar.top; |
175 | scrollBar.last_bot = scrollBar.bot; |
178 | scrollBar.last_bot = scrollBar.bot; |
176 | scrollBar.last_state = scrollBar.state; |
179 | scrollBar.last_state = scrollBar.state; |
177 | #endif |
|
|
178 | |
180 | |
179 | return ret; |
181 | return ret; |
180 | } |
182 | } |
181 | |
183 | |
182 | void |
184 | void |
183 | rxvt_term::setup_scrollbar (const char *scrollalign, const char *scrollstyle, const char *thickness) |
185 | scrollBar_t::setup (rxvt_term *term) |
184 | { |
186 | { |
185 | #ifdef HAVE_SCROLLBARS |
|
|
186 | int i; |
187 | int i; |
187 | short style, width; |
188 | short style, width; |
|
|
189 | const char *scrollalign, *scrollstyle, *thickness; |
|
|
190 | |
|
|
191 | this->term = term; |
|
|
192 | scrollalign = term->rs[Rs_scrollBar_align]; |
|
|
193 | scrollstyle = term->rs[Rs_scrollstyle]; |
|
|
194 | thickness = term->rs[Rs_scrollBar_thickness]; |
188 | |
195 | |
189 | # if defined(RXVT_SCROLLBAR) |
196 | # if defined(RXVT_SCROLLBAR) |
190 | style = R_SB_RXVT; |
197 | style = R_SB_RXVT; |
191 | # elif defined(XTERM_SCROLLBAR) |
198 | # elif defined(XTERM_SCROLLBAR) |
192 | style = R_SB_XTERM; |
199 | style = R_SB_XTERM; |
… | |
… | |
228 | if (style != R_SB_NEXT) /* dishonour request - for now */ |
235 | if (style != R_SB_NEXT) /* dishonour request - for now */ |
229 | if (thickness && (i = atoi (thickness)) >= SB_WIDTH_MINIMUM) |
236 | if (thickness && (i = atoi (thickness)) >= SB_WIDTH_MINIMUM) |
230 | width = min (i, SB_WIDTH_MAXIMUM); |
237 | width = min (i, SB_WIDTH_MAXIMUM); |
231 | |
238 | |
232 | # ifdef RXVT_SCROLLBAR |
239 | # ifdef RXVT_SCROLLBAR |
233 | if (! option (Opt_scrollBar_floating) && style == R_SB_RXVT) |
240 | if (! term->option (Opt_scrollBar_floating) && style == R_SB_RXVT) |
234 | scrollBar.shadow = SHADOW_WIDTH; |
241 | shadow = SHADOW_WIDTH; |
235 | # endif |
242 | # endif |
236 | |
243 | |
237 | scrollBar.style = style; |
244 | this->style = style; |
238 | scrollBar.width = width; |
245 | this->width = width; |
239 | |
246 | |
240 | /* scrollBar.align = R_SB_ALIGN_CENTRE; */ |
247 | /* align = R_SB_ALIGN_CENTRE; */ |
241 | if (scrollalign) |
248 | if (scrollalign) |
242 | { |
249 | { |
243 | if (strncasecmp (scrollalign, "top", 3) == 0) |
250 | if (strncasecmp (scrollalign, "top", 3) == 0) |
244 | scrollBar.align = R_SB_ALIGN_TOP; |
251 | align = R_SB_ALIGN_TOP; |
245 | else if (strncasecmp (scrollalign, "bottom", 6) == 0) |
252 | else if (strncasecmp (scrollalign, "bottom", 6) == 0) |
246 | scrollBar.align = R_SB_ALIGN_BOTTOM; |
253 | align = R_SB_ALIGN_BOTTOM; |
247 | } |
254 | } |
248 | scrollBar.last_bot = scrollBar.last_state = -1; |
255 | last_bot = last_state = -1; |
249 | #endif |
256 | /* cursor scrollBar: Black-on-White */ |
|
|
257 | leftptr_cursor = XCreateFontCursor (term->dpy, XC_left_ptr); |
250 | } |
258 | } |
251 | |
259 | |
252 | /*----------------------- end-of-file (C source) -----------------------*/ |
260 | /*----------------------- end-of-file (C source) -----------------------*/ |
253 | |
261 | |