ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/scrollbar.C
(Generate patch)

Comparing rxvt-unicode/src/scrollbar.C (file contents):
Revision 1.15 by pcg, Thu Apr 8 20:31:45 2004 UTC vs.
Revision 1.42 by ayin, Sat Dec 29 14:43:44 2007 UTC

1/*--------------------------------*-C-*---------------------------------* 1/*----------------------------------------------------------------------*
2 * File: scrollbar.C 2 * File: scrollbar.C
3 *----------------------------------------------------------------------* 3 *----------------------------------------------------------------------*
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 Marc Lehmann <pcg@goof.com> 9 * Copyright (c) 2004-2006 Marc Lehmann <pcg@goof.com>
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.
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 *----------------------------------------------------------------------*/ 24 *----------------------------------------------------------------------*/
25 25
26#include "../config.h" /* NECESSARY */ 26#include "../config.h" /* NECESSARY */
27#include "rxvt.h" /* NECESSARY */ 27#include "rxvt.h" /* NECESSARY */
28#include "scrollbar.intpro" /* PROTOS for internal routines */
29 28
30/*----------------------------------------------------------------------*/ 29/*----------------------------------------------------------------------*/
31 30
32/* 31/*
33 * 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
34 */ 33 */
35int 34int
36rxvt_term::scrollbar_mapping (int map) 35rxvt_term::scrollbar_mapping (int map)
37{ 36{
38 int change = 0; 37 int change = 0;
39 38
40#ifdef HAVE_SCROLLBARS 39#ifdef HAVE_SCROLLBARS
41 if (map && !scrollbar_visible ()) 40 if (map)
42 { 41 {
43 scrollBar.setIdle (); 42 scrollBar.setIdle ();
43
44 if (!scrollBar.win) 44 if (!scrollBar.win)
45 resize_scrollbar (); 45 resize_scrollbar ();
46
46 if (scrollBar.win) 47 if (scrollBar.win)
47 { 48 {
48 XMapWindow (display->display, scrollBar.win); 49 XMapWindow (dpy, scrollBar.win);
49 change = 1; 50 change = 1;
50 } 51 }
51 } 52 }
52 else if (!map && scrollbar_visible ()) 53 else
53 { 54 {
54 scrollBar.state = 0; 55 scrollBar.state = 0;
55 XUnmapWindow (display->display, scrollBar.win); 56 XUnmapWindow (dpy, scrollBar.win);
56 change = 1; 57 change = 1;
57 } 58 }
58#endif 59#endif
60
59 return change; 61 return change;
60} 62}
61 63
62void 64void
63rxvt_term::resize_scrollbar () 65rxvt_term::resize_scrollbar ()
67 69
68#define R_SCROLLBEG_XTERM 0 70#define R_SCROLLBEG_XTERM 0
69#define R_SCROLLEND_XTERM szHint.height 71#define R_SCROLLEND_XTERM szHint.height
70#define R_SCROLLBEG_NEXT 0 72#define R_SCROLLBEG_NEXT 0
71#define R_SCROLLEND_NEXT szHint.height - (SB_BUTTON_TOTAL_HEIGHT + \ 73#define R_SCROLLEND_NEXT szHint.height - (SB_BUTTON_TOTAL_HEIGHT + \
72 SB_PADDING) 74 SB_PADDING)
73#define R_SCROLLBEG_RXVT (scrollBar.width + 1) + sb_shadow 75#define R_SCROLLBEG_RXVT (scrollBar.width + 1) + scrollBar.shadow
74#define R_SCROLLEND_RXVT szHint.height - R_SCROLLBEG_RXVT - \ 76#define R_SCROLLEND_RXVT szHint.height - R_SCROLLBEG_RXVT - \
75 (2 * sb_shadow) 77 (2 * scrollBar.shadow)
76 78
77#if defined(PLAIN_SCROLLBAR) 79#if defined(PLAIN_SCROLLBAR)
78 if (scrollBar.style == R_SB_PLAIN) 80 if (scrollBar.style == R_SB_PLAIN)
79 { 81 {
80 scrollBar.beg = R_SCROLLBEG_XTERM; 82 scrollBar.beg = R_SCROLLBEG_XTERM;
108#endif 110#endif
109 111
110 if (!scrollBar.win) 112 if (!scrollBar.win)
111 { 113 {
112 /* create the scrollbar window */ 114 /* create the scrollbar window */
113 scrollBar.win = XCreateSimpleWindow (display->display, 115 scrollBar.win = XCreateSimpleWindow (dpy,
114 TermWin.parent[0], 116 parent[0],
115 window_sb_x, 0, 117 window_sb_x, 0,
116 scrollbar_TotalWidth (), 118 scrollbar_TotalWidth (),
117 szHint.height, 119 szHint.height,
118 0, 120 0,
119 PixColors[Color_fg], 121 pix_colors[Color_fg],
120 PixColors[Color_bg]); 122 pix_colors[Color_border]);
121#ifdef DEBUG_X
122 XStoreName (display->display, scrollBar.win, "scrollbar");
123#endif
124 XDefineCursor (display->display, scrollBar.win, leftptr_cursor); 123 XDefineCursor (dpy, scrollBar.win, leftptr_cursor);
125 124
126 XSelectInput (display->display, scrollBar.win, 125 XSelectInput (dpy, scrollBar.win,
127 ExposureMask | ButtonPressMask | ButtonReleaseMask 126 ExposureMask | ButtonPressMask | ButtonReleaseMask
128 | Button1MotionMask | Button2MotionMask 127 | Button1MotionMask | Button2MotionMask
129 | Button3MotionMask); 128 | Button3MotionMask);
130 scrollbar_ev.start (display, scrollBar.win); 129 scrollbar_ev.start (display, scrollBar.win);
131 130
133 } 132 }
134 133
135 scrollbar_show (1); 134 scrollbar_show (1);
136 135
137 if (delayed_init) 136 if (delayed_init)
138 XMapWindow (display->display, scrollBar.win); 137 XMapWindow (dpy, scrollBar.win);
139#endif 138#endif
140} 139}
141 140
142/* 141/*
143 * Update current scrollbar view w.r.t. slider heights, etc. 142 * Update current scrollbar view w.r.t. slider heights, etc.
146rxvt_term::scrollbar_show (int update) 145rxvt_term::scrollbar_show (int update)
147{ 146{
148 int ret = 0; 147 int ret = 0;
149#ifdef HAVE_SCROLLBARS 148#ifdef HAVE_SCROLLBARS
150 int top, bot, len, adj; 149 int top, bot, len, adj;
150 int scrollbar_len = 0;
151 151
152 if (!scrollbar_visible ()) 152 if (!scrollBar.state)
153 return 0; 153 return 0;
154 154
155 if (update) 155 if (update)
156 { 156 {
157 top = (TermWin.nscrolled - TermWin.view_start); 157 top = view_start - top_row;
158 bot = top + (TermWin.nrow - 1); 158 bot = top + (nrow - 1);
159 len = max ((TermWin.nscrolled + (TermWin.nrow - 1)), 1); 159 len = max (nrow - 1 - top_row, 1);
160 adj = (((bot - top) * scrollbar_size ()) % len) > 0 ? 1 : 0; 160 adj = (((bot - top) * scrollbar_size ()) % len) > 0 ? 1 : 0;
161 161
162 scrollBar.top = (scrollBar.beg + (top * scrollbar_size ()) / len); 162 scrollBar.top = (scrollBar.beg + (top * scrollbar_size ()) / len);
163 scrollbar_len = ((bot - top) * scrollbar_size ()) / len + 163 scrollbar_len = ((bot - top) * scrollbar_size ()) / len +
164 scrollbar_minheight () + adj; 164 scrollbar_minheight () + adj;
201 201
202# if (defined(NEXT_SCROLLBAR) || defined(XTERM_SCROLLBAR) || defined(PLAIN_SCROLLBAR)) 202# if (defined(NEXT_SCROLLBAR) || defined(XTERM_SCROLLBAR) || defined(PLAIN_SCROLLBAR))
203 if (scrollstyle) 203 if (scrollstyle)
204 { 204 {
205# ifdef NEXT_SCROLLBAR 205# ifdef NEXT_SCROLLBAR
206 if (STRNCASECMP (scrollstyle, "next", 4) == 0) 206 if (strncasecmp (scrollstyle, "next", 4) == 0)
207 style = R_SB_NEXT; 207 style = R_SB_NEXT;
208# endif 208# endif
209# ifdef XTERM_SCROLLBAR 209# ifdef XTERM_SCROLLBAR
210 if (STRNCASECMP (scrollstyle, "xterm", 5) == 0) 210 if (strncasecmp (scrollstyle, "xterm", 5) == 0)
211 style = R_SB_XTERM; 211 style = R_SB_XTERM;
212# endif 212# endif
213# ifdef PLAIN_SCROLLBAR 213# ifdef PLAIN_SCROLLBAR
214 if (STRNCASECMP (scrollstyle, "plain", 5) == 0) 214 if (strncasecmp (scrollstyle, "plain", 5) == 0)
215 style = R_SB_PLAIN; 215 style = R_SB_PLAIN;
216# endif 216# endif
217 217
218 } 218 }
219# endif 219# endif
228 228
229 if (style != R_SB_NEXT) /* dishonour request - for now */ 229 if (style != R_SB_NEXT) /* dishonour request - for now */
230 if (thickness && (i = atoi (thickness)) >= SB_WIDTH_MINIMUM) 230 if (thickness && (i = atoi (thickness)) >= SB_WIDTH_MINIMUM)
231 width = min (i, SB_WIDTH_MAXIMUM); 231 width = min (i, SB_WIDTH_MAXIMUM);
232 232
233# if defined(RXVT_SCROLLBAR) 233# ifdef RXVT_SCROLLBAR
234 if (! (Options & Opt_scrollBar_floating) && style == R_SB_RXVT) 234 if (! option (Opt_scrollBar_floating) && style == R_SB_RXVT)
235 sb_shadow = SHADOW; 235 scrollBar.shadow = SHADOW_WIDTH;
236# endif 236# endif
237 237
238 scrollBar.style = style; 238 scrollBar.style = style;
239 scrollBar.width = width; 239 scrollBar.width = width;
240 240
241 /* scrollbar_align = R_SB_ALIGN_CENTRE; */ 241 /* scrollbar_align = R_SB_ALIGN_CENTRE; */
242 if (scrollalign) 242 if (scrollalign)
243 { 243 {
244 if (STRNCASECMP (scrollalign, "top", 3) == 0) 244 if (strncasecmp (scrollalign, "top", 3) == 0)
245 scrollbar_align = R_SB_ALIGN_TOP; 245 scrollbar_align = R_SB_ALIGN_TOP;
246 else if (STRNCASECMP (scrollalign, "bottom", 6) == 0) 246 else if (strncasecmp (scrollalign, "bottom", 6) == 0)
247 scrollbar_align = R_SB_ALIGN_BOTTOM; 247 scrollbar_align = R_SB_ALIGN_BOTTOM;
248 } 248 }
249#endif 249#endif
250} 250}
251 251

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines