… | |
… | |
4 | * |
4 | * |
5 | * Copyright (c) 1997,1998 mj olesen <olesen@me.QueensU.CA> |
5 | * Copyright (c) 1997,1998 mj olesen <olesen@me.QueensU.CA> |
6 | * Copyright (c) 1998 Alfredo K. Kojima <kojima@windowmaker.org> |
6 | * Copyright (c) 1998 Alfredo K. Kojima <kojima@windowmaker.org> |
7 | * - N*XTstep like scrollbars |
7 | * - N*XTstep like scrollbars |
8 | * Copyright (c) 1999-2001 Geoff Wing <gcw@pobox.com> |
8 | * Copyright (c) 1999-2001 Geoff Wing <gcw@pobox.com> |
9 | * Copyright (c) 2004-2006 Marc Lehmann <pcg@goof.com> |
9 | * Copyright (c) 2004-2006 Marc Lehmann <schmorp@schmorp.de> |
10 | * |
10 | * |
11 | * This program is free software; you can redistribute it and/or modify |
11 | * This program is free software; you can redistribute it and/or modify |
12 | * it under the terms of the GNU General Public License as published by |
12 | * it under the terms of the GNU General Public License as published by |
13 | * the Free Software Foundation; either version 2 of the License, or |
13 | * the Free Software Foundation; either version 2 of the License, or |
14 | * (at your option) any later version. |
14 | * (at your option) any later version. |
… | |
… | |
29 | /*----------------------------------------------------------------------*/ |
29 | /*----------------------------------------------------------------------*/ |
30 | |
30 | |
31 | /* |
31 | /* |
32 | * Map or unmap a scrollbar. Returns non-zero upon change of state |
32 | * Map or unmap a scrollbar. Returns non-zero upon change of state |
33 | */ |
33 | */ |
34 | int |
34 | void |
35 | scrollBar_t::map (int map) |
35 | scrollBar_t::map (int map) |
36 | { |
36 | { |
37 | int change = 0; |
|
|
38 | |
|
|
39 | if (map) |
37 | if (map) |
40 | { |
38 | { |
41 | state = STATE_IDLE; |
39 | state = STATE_IDLE; |
42 | |
40 | |
43 | if (!win) |
41 | if (!win) |
44 | resize (); |
42 | resize (); |
45 | |
43 | |
46 | if (win) |
44 | if (win) |
47 | { |
45 | { |
48 | XMapWindow (term->dpy, win); |
46 | XMapWindow (term->dpy, win); |
49 | change = 1; |
|
|
50 | } |
47 | } |
51 | } |
48 | } |
52 | else |
49 | else |
53 | { |
50 | { |
54 | state = 0; |
51 | state = STATE_OFF; |
55 | XUnmapWindow (term->dpy, win); |
52 | XUnmapWindow (term->dpy, win); |
56 | change = 1; |
|
|
57 | } |
53 | } |
58 | |
|
|
59 | return change; |
|
|
60 | } |
54 | } |
61 | |
55 | |
62 | void |
56 | void |
63 | scrollBar_t::resize () |
57 | scrollBar_t::resize () |
64 | { |
58 | { |
… | |
… | |
72 | |
66 | |
73 | if (!win) |
67 | if (!win) |
74 | { |
68 | { |
75 | /* create the scrollbar window */ |
69 | /* create the scrollbar window */ |
76 | win = XCreateSimpleWindow (term->dpy, |
70 | win = XCreateSimpleWindow (term->dpy, |
77 | term->parent[0], |
71 | term->parent, |
78 | window_sb_x, 0, |
72 | window_sb_x, 0, |
79 | total_width (), |
73 | total_width (), |
80 | term->szHint.height, |
74 | term->szHint.height, |
81 | 0, |
75 | 0, |
82 | term->pix_colors[Color_fg], |
76 | term->pix_colors[Color_fg], |
… | |
… | |
116 | if (refresh) |
110 | if (refresh) |
117 | { |
111 | { |
118 | int sb_top = term->view_start - term->top_row; |
112 | int sb_top = term->view_start - term->top_row; |
119 | int sb_bot = sb_top + (term->nrow - 1); |
113 | int sb_bot = sb_top + (term->nrow - 1); |
120 | int sb_len = max (term->nrow - 1 - term->top_row, 1); |
114 | int sb_len = max (term->nrow - 1 - term->top_row, 1); |
121 | int sb_size = (sb_bot - sb_top) * size (); |
|
|
122 | |
115 | |
123 | top = beg + (sb_top * size ()) / sb_len; |
116 | top = beg + (sb_top * size ()) / sb_len; |
124 | bot = top + sb_size / sb_len + min_height () + (sb_size % sb_len > 0); |
117 | bot = top + ecb_div_ru ((sb_bot - sb_top) * size (), sb_len) + min_height (); |
125 | /* no change */ |
118 | /* no change */ |
126 | if (top == last_top |
119 | if (top == last_top |
127 | && bot == last_bot |
120 | && bot == last_bot |
128 | && (state == last_state |
121 | && (state == last_state |
129 | || !(state == STATE_UP || state == STATE_DOWN))) |
122 | || !(state == STATE_UP || state == STATE_DOWN))) |
… | |
… | |
141 | |
134 | |
142 | void |
135 | void |
143 | scrollBar_t::setup (rxvt_term *term) |
136 | scrollBar_t::setup (rxvt_term *term) |
144 | { |
137 | { |
145 | int i; |
138 | int i; |
146 | short style, width; |
|
|
147 | const char *scrollalign, *scrollstyle, *thickness; |
139 | const char *scrollalign, *scrollstyle, *thickness; |
148 | |
140 | |
149 | this->term = term; |
141 | this->term = term; |
150 | scrollalign = term->rs[Rs_scrollBar_align]; |
142 | scrollalign = term->rs[Rs_scrollBar_align]; |
151 | scrollstyle = term->rs[Rs_scrollstyle]; |
143 | scrollstyle = term->rs[Rs_scrollstyle]; |
… | |
… | |
197 | # ifdef RXVT_SCROLLBAR |
189 | # ifdef RXVT_SCROLLBAR |
198 | if (! term->option (Opt_scrollBar_floating) && style == R_SB_RXVT) |
190 | if (! term->option (Opt_scrollBar_floating) && style == R_SB_RXVT) |
199 | shadow = SHADOW_WIDTH; |
191 | shadow = SHADOW_WIDTH; |
200 | # endif |
192 | # endif |
201 | |
193 | |
202 | this->style = style; |
|
|
203 | this->width = width; |
|
|
204 | |
|
|
205 | /* align = R_SB_ALIGN_CENTRE; */ |
194 | /* align = R_SB_ALIGN_CENTRE; */ |
206 | if (scrollalign) |
195 | if (scrollalign) |
207 | { |
196 | { |
208 | if (strncasecmp (scrollalign, "top", 3) == 0) |
197 | if (strncasecmp (scrollalign, "top", 3) == 0) |
209 | align = R_SB_ALIGN_TOP; |
198 | align = R_SB_ALIGN_TOP; |
210 | else if (strncasecmp (scrollalign, "bottom", 6) == 0) |
199 | else if (strncasecmp (scrollalign, "bottom", 6) == 0) |
211 | align = R_SB_ALIGN_BOTTOM; |
200 | align = R_SB_ALIGN_BOTTOM; |
212 | } |
201 | } |
213 | last_bot = last_state = -1; |
202 | last_state = STATE_OFF; |
214 | /* cursor scrollBar: Black-on-White */ |
203 | /* cursor scrollBar: Black-on-White */ |
215 | leftptr_cursor = XCreateFontCursor (term->dpy, XC_left_ptr); |
204 | leftptr_cursor = XCreateFontCursor (term->dpy, XC_left_ptr); |
216 | } |
205 | } |
217 | |
206 | |
218 | void |
207 | void |