ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/scrollbar.C
Revision: 1.4
Committed: Tue Nov 25 17:11:33 2003 UTC (20 years, 6 months ago) by pcg
Content type: text/plain
Branch: MAIN
Changes since 1.3: +2 -2 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 pcg 1.1 /*--------------------------------*-C-*---------------------------------*
2     * File: scrollbar.c
3     *----------------------------------------------------------------------*
4 pcg 1.4 * $Id: scrollbar.C,v 1.3 2003/11/25 11:52:42 pcg Exp $
5 pcg 1.1 *
6     * Copyright (c) 1997,1998 mj olesen <olesen@me.QueensU.CA>
7     * Copyright (c) 1998 Alfredo K. Kojima <kojima@windowmaker.org>
8     * - N*XTstep like scrollbars
9     * Copyright (c) 1999-2001 Geoff Wing <gcw@pobox.com>
10     *
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
13     * the Free Software Foundation; either version 2 of the License, or
14     * (at your option) any later version.
15     *
16     * This program is distributed in the hope that it will be useful,
17     * but WITHOUT ANY WARRANTY; without even the implied warranty of
18     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19     * GNU General Public License for more details.
20     *
21     * You should have received a copy of the GNU General Public License
22     * along with this program; if not, write to the Free Software
23     * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24     *----------------------------------------------------------------------*/
25    
26     #include "../config.h" /* NECESSARY */
27     #include "rxvt.h" /* NECESSARY */
28     #include "scrollbar.intpro" /* PROTOS for internal routines */
29    
30     /*----------------------------------------------------------------------*/
31    
32     /*
33     * Map or unmap a scrollbar. Returns non-zero upon change of state
34     */
35     /* EXTPROTO */
36     int
37     rxvt_scrollbar_mapping(pR_ int map)
38     {
39     int change = 0;
40     #ifdef HAVE_SCROLLBARS
41    
42     if (map && !scrollbar_visible(R)) {
43     scrollbar_setIdle();
44     if (!R->scrollBar.win)
45     rxvt_Resize_scrollBar(aR);
46     if (R->scrollBar.win) {
47     XMapWindow(R->Xdisplay, R->scrollBar.win);
48     change = 1;
49     }
50     } else if (!map && scrollbar_visible(R)) {
51     R->scrollBar.state = 0;
52     XUnmapWindow(R->Xdisplay, R->scrollBar.win);
53     change = 1;
54     }
55     #endif
56     return change;
57     }
58    
59     /* EXTPROTO */
60     void
61     rxvt_Resize_scrollBar(pR)
62     {
63     #ifdef HAVE_SCROLLBARS
64     int delayed_init = 0;
65    
66     #define R_SCROLLBEG_XTERM 0
67     #define R_SCROLLEND_XTERM R->szHint.height
68     #define R_SCROLLBEG_NEXT 0
69     #define R_SCROLLEND_NEXT R->szHint.height - (SB_BUTTON_TOTAL_HEIGHT + \
70     SB_PADDING)
71     #define R_SCROLLBEG_RXVT (R->scrollBar.width + 1) + R->sb_shadow
72     #define R_SCROLLEND_RXVT R->szHint.height - R_SCROLLBEG_RXVT - \
73     (2 * R->sb_shadow)
74    
75     #if defined(XTERM_SCROLLBAR)
76     if (R->scrollBar.style == R_SB_XTERM) {
77     R->scrollBar.beg = R_SCROLLBEG_XTERM;
78     R->scrollBar.end = R_SCROLLEND_XTERM;
79     R->scrollBar.update = rxvt_scrollbar_show_xterm;
80     }
81     #endif
82     #if defined(NEXT_SCROLLBAR)
83     if (R->scrollBar.style == R_SB_NEXT) {
84     R->scrollBar.beg = R_SCROLLBEG_NEXT;
85     R->scrollBar.end = R_SCROLLEND_NEXT;
86     R->scrollBar.update = rxvt_scrollbar_show_next;
87     }
88     #endif
89     #if defined(RXVT_SCROLLBAR)
90     if (R->scrollBar.style == R_SB_RXVT) {
91     R->scrollBar.beg = R_SCROLLBEG_RXVT;
92     R->scrollBar.end = R_SCROLLEND_RXVT;
93     R->scrollBar.update = rxvt_scrollbar_show_rxvt;
94     }
95     #endif
96    
97     if (!R->scrollBar.win) {
98     /* create the scrollbar window */
99     R->scrollBar.win = XCreateSimpleWindow(R->Xdisplay,
100     R->TermWin.parent[0],
101 pcg 1.3 R->window_sb_x, 0,
102 pcg 1.1 scrollbar_TotalWidth(),
103     R->szHint.height,
104     0,
105     R->PixColors[Color_fg],
106     R->PixColors[Color_bg]);
107     #ifdef DEBUG_X
108     XStoreName(R->Xdisplay, R->scrollBar.win, "scrollbar");
109     #endif
110 pcg 1.4 XDefineCursor(R->Xdisplay, R->scrollBar.win, R->leftptr_cursor);
111 pcg 1.1 XSelectInput(R->Xdisplay, R->scrollBar.win,
112     (ExposureMask | ButtonPressMask | ButtonReleaseMask
113     | Button1MotionMask | Button2MotionMask
114     | Button3MotionMask));
115     delayed_init = 1;
116     }
117     rxvt_scrollbar_show(aR_ 1);
118     if (delayed_init)
119     XMapWindow(R->Xdisplay, R->scrollBar.win);
120     #endif
121     }
122    
123     /*
124     * Update current scrollbar view w.r.t. slider heights, etc.
125     */
126     /* EXTPROTO */
127     int
128     rxvt_scrollbar_show(pR_ int update)
129     {
130     int ret = 0;
131     #ifdef HAVE_SCROLLBARS
132     int top, bot, len, adj;
133    
134     if (!scrollbar_visible(R))
135     return 0;
136    
137     if (update) {
138     top = (R->TermWin.nscrolled - R->TermWin.view_start);
139     bot = top + (R->TermWin.nrow - 1);
140     len = max((R->TermWin.nscrolled + (R->TermWin.nrow - 1)), 1);
141     adj = (((bot - top) * scrollbar_size()) % len) > 0 ? 1 : 0;
142    
143     R->scrollBar.top = (R->scrollBar.beg + (top * scrollbar_size()) / len);
144 pcg 1.3 R->scrollbar_len = ((bot - top) * scrollbar_size()) / len +
145 pcg 1.1 scrollbar_minheight() + adj;
146 pcg 1.3 R->scrollBar.bot = (R->scrollBar.top + R->scrollbar_len);
147 pcg 1.1 /* no change */
148 pcg 1.3 if (R->scrollBar.top == R->last_top
149     && R->scrollBar.bot == R->last_bot
150     && (R->scrollBar.state == R->last_state || !scrollbar_isUpDn()))
151 pcg 1.1 return 0;
152     }
153    
154 pcg 1.3 ret = R->scrollBar.update(aR_ update, R->last_top, R->last_bot,
155     R->scrollbar_len);
156 pcg 1.1
157 pcg 1.3 R->last_top = R->scrollBar.top;
158     R->last_bot = R->scrollBar.bot;
159     R->last_state = R->scrollBar.state;
160 pcg 1.1
161     #endif
162     return ret;
163     }
164    
165     /* EXTPROTO */
166     void
167     rxvt_setup_scrollbar(pR_ const char *scrollalign, const char *scrollstyle, const char *thickness)
168     {
169     #ifdef HAVE_SCROLLBARS
170     int i;
171     short style, width;
172    
173     # if defined(RXVT_SCROLLBAR) || !(defined(NEXT_SCROLLBAR) || defined(XTERM_SCROLLBAR))
174     style = R_SB_RXVT;
175     # else
176     # ifdef NEXT_SCROLLBAR
177     style = R_SB_NEXT;
178     # elif defined(XTERM_SCROLLBAR)
179     style = R_SB_XTERM;
180     # endif
181     # endif
182    
183     # if (defined(NEXT_SCROLLBAR) || defined(XTERM_SCROLLBAR))
184     if (scrollstyle) {
185     # ifdef NEXT_SCROLLBAR
186     if (STRNCASECMP(scrollstyle, "next", 4) == 0)
187     style = R_SB_NEXT;
188     # endif
189     # ifdef XTERM_SCROLLBAR
190     if (STRNCASECMP(scrollstyle, "xterm", 5) == 0)
191     style = R_SB_XTERM;
192     # endif
193     }
194     # endif
195     if (style == R_SB_NEXT)
196     width = SB_WIDTH_NEXT;
197     else if (style == R_SB_XTERM)
198     width = SB_WIDTH_XTERM;
199     else /* if (style == R_SB_RXVT) */
200     width = SB_WIDTH_RXVT;
201    
202     if (style != R_SB_NEXT) /* dishonour request - for now */
203     if (thickness && (i = atoi(thickness)) >= SB_WIDTH_MINIMUM)
204     width = min(i, SB_WIDTH_MAXIMUM);
205    
206     # if defined(RXVT_SCROLLBAR)
207     if (!(R->Options & Opt_scrollBar_floating) && style == R_SB_RXVT)
208     R->sb_shadow = SHADOW;
209     # endif
210    
211     R->scrollBar.style = style;
212     R->scrollBar.width = width;
213    
214 pcg 1.3 /* R->scrollbar_align = R_SB_ALIGN_CENTRE; */
215 pcg 1.1 if (scrollalign) {
216     if (STRNCASECMP(scrollalign, "top", 3) == 0)
217 pcg 1.3 R->scrollbar_align = R_SB_ALIGN_TOP;
218 pcg 1.1 else if (STRNCASECMP(scrollalign, "bottom", 6) == 0)
219 pcg 1.3 R->scrollbar_align = R_SB_ALIGN_BOTTOM;
220 pcg 1.1 }
221     #endif
222     }
223    
224     /*----------------------- end-of-file (C source) -----------------------*/