1 /*--------------------------------*-C-*---------------------------------*
3 *----------------------------------------------------------------------*
4 * $Id: scrollbar.C,v 1.2 2003-11-24 17:31:28 pcg Exp $
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>
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.
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.
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 *----------------------------------------------------------------------*/
26 #include "../config.h" /* NECESSARY */
27 #include "rxvt.h" /* NECESSARY */
28 #include "scrollbar.intpro" /* PROTOS for internal routines */
30 /*----------------------------------------------------------------------*/
33 * Map or unmap a scrollbar. Returns non-zero upon change of state
37 rxvt_scrollbar_mapping(pR_ int map)
40 #ifdef HAVE_SCROLLBARS
42 if (map && !scrollbar_visible(R)) {
44 if (!R->scrollBar.win)
45 rxvt_Resize_scrollBar(aR);
46 if (R->scrollBar.win) {
47 XMapWindow(R->Xdisplay, R->scrollBar.win);
50 } else if (!map && scrollbar_visible(R)) {
51 R->scrollBar.state = 0;
52 XUnmapWindow(R->Xdisplay, R->scrollBar.win);
61 rxvt_Resize_scrollBar(pR)
63 #ifdef HAVE_SCROLLBARS
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 + \
71 #define R_SCROLLBEG_RXVT (R->scrollBar.width + 1) + R->sb_shadow
72 #define R_SCROLLEND_RXVT R->szHint.height - R_SCROLLBEG_RXVT - \
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;
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;
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;
97 if (!R->scrollBar.win) {
98 /* create the scrollbar window */
99 R->scrollBar.win = XCreateSimpleWindow(R->Xdisplay,
100 R->TermWin.parent[0],
101 R->h->window_sb_x, 0,
102 scrollbar_TotalWidth(),
105 R->PixColors[Color_fg],
106 R->PixColors[Color_bg]);
108 XStoreName(R->Xdisplay, R->scrollBar.win, "scrollbar");
110 XDefineCursor(R->Xdisplay, R->scrollBar.win, R->h->pointer_leftptr);
111 XSelectInput(R->Xdisplay, R->scrollBar.win,
112 (ExposureMask | ButtonPressMask | ButtonReleaseMask
113 | Button1MotionMask | Button2MotionMask
114 | Button3MotionMask));
117 rxvt_scrollbar_show(aR_ 1);
119 XMapWindow(R->Xdisplay, R->scrollBar.win);
124 * Update current scrollbar view w.r.t. slider heights, etc.
128 rxvt_scrollbar_show(pR_ int update)
131 #ifdef HAVE_SCROLLBARS
132 int top, bot, len, adj;
134 if (!scrollbar_visible(R))
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;
143 R->scrollBar.top = (R->scrollBar.beg + (top * scrollbar_size()) / len);
144 R->h->scrollbar_len = ((bot - top) * scrollbar_size()) / len +
145 scrollbar_minheight() + adj;
146 R->scrollBar.bot = (R->scrollBar.top + R->h->scrollbar_len);
148 if (R->scrollBar.top == R->h->last_top
149 && R->scrollBar.bot == R->h->last_bot
150 && (R->scrollBar.state == R->h->last_state || !scrollbar_isUpDn()))
154 ret = R->scrollBar.update(aR_ update, R->h->last_top, R->h->last_bot,
155 R->h->scrollbar_len);
157 R->h->last_top = R->scrollBar.top;
158 R->h->last_bot = R->scrollBar.bot;
159 R->h->last_state = R->scrollBar.state;
167 rxvt_setup_scrollbar(pR_ const char *scrollalign, const char *scrollstyle, const char *thickness)
169 #ifdef HAVE_SCROLLBARS
173 # if defined(RXVT_SCROLLBAR) || !(defined(NEXT_SCROLLBAR) || defined(XTERM_SCROLLBAR))
176 # ifdef NEXT_SCROLLBAR
178 # elif defined(XTERM_SCROLLBAR)
183 # if (defined(NEXT_SCROLLBAR) || defined(XTERM_SCROLLBAR))
185 # ifdef NEXT_SCROLLBAR
186 if (STRNCASECMP(scrollstyle, "next", 4) == 0)
189 # ifdef XTERM_SCROLLBAR
190 if (STRNCASECMP(scrollstyle, "xterm", 5) == 0)
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;
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);
206 # if defined(RXVT_SCROLLBAR)
207 if (!(R->Options & Opt_scrollBar_floating) && style == R_SB_RXVT)
208 R->sb_shadow = SHADOW;
211 R->scrollBar.style = style;
212 R->scrollBar.width = width;
214 /* R->h->scrollbar_align = R_SB_ALIGN_CENTRE; */
216 if (STRNCASECMP(scrollalign, "top", 3) == 0)
217 R->h->scrollbar_align = R_SB_ALIGN_TOP;
218 else if (STRNCASECMP(scrollalign, "bottom", 6) == 0)
219 R->h->scrollbar_align = R_SB_ALIGN_BOTTOM;
224 /*----------------------- end-of-file (C source) -----------------------*/