c85c0d676b6d20184aee7f56efcfc6676338c8f9
[dana/urxvt.git] / src / scrollbar-xterm.C
1 /*--------------------------------*-C-*---------------------------------*
2  * File:        scrollbar-xterm.c
3  *----------------------------------------------------------------------*
4  *
5  * Copyright (c) 1997,1998 mj olesen <olesen@me.QueensU.CA>
6  * Copyright (c) 1999-2001 Geoff Wing <gcw@pobox.com>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21  *----------------------------------------------------------------------*/
22
23 #include "../config.h"          /* NECESSARY */
24 #include "rxvt.h"               /* NECESSARY */
25 #include "scrollbar-xterm.intpro"       /* PROTOS for internal routines */
26
27 /*----------------------------------------------------------------------*/
28 #if defined(XTERM_SCROLLBAR)
29
30 #define x_stp_width     8
31 #define x_stp_height    2
32 const unsigned char x_stp_bits[] = { 0xaa, 0x55 };
33
34 int
35 rxvt_term::scrollbar_show_xterm (int update __attribute__((unused)), int last_top, int last_bot, int scrollbar_len)
36 {
37   int             xsb = 0;
38   int             sbwidth = scrollBar.width - 1;
39
40   if ((scrollBar.init & R_SB_XTERM) == 0)
41     {
42       XGCValues       gcvalue;
43
44       scrollBar.init |= R_SB_XTERM;
45       gcvalue.stipple = XCreateBitmapFromData(Xdisplay, scrollBar.win,
46                                               (char *)x_stp_bits, x_stp_width,
47                                               x_stp_height);
48       if (!gcvalue.stipple)
49         {
50           rxvt_print_error("can't create bitmap");
51           exit(EXIT_FAILURE);
52         }
53       gcvalue.fill_style = FillOpaqueStippled;
54       gcvalue.foreground = PixColors[Color_fg];
55       gcvalue.background = PixColors[Color_bg];
56
57       xscrollbarGC = XCreateGC(Xdisplay, scrollBar.win,
58                                GCForeground | GCBackground
59                                | GCFillStyle | GCStipple, &gcvalue);
60       gcvalue.foreground = PixColors[Color_border];
61       ShadowGC = XCreateGC(Xdisplay, scrollBar.win, GCForeground, &gcvalue);
62     }
63   /* instead of XClearWindow (Xdisplay, scrollBar.win); */
64   xsb = (Options & Opt_scrollBar_right) ? 1 : 0;
65   if (last_top < scrollBar.top)
66     XClearArea(Xdisplay, scrollBar.win,
67                sb_shadow + xsb, last_top,
68                sbwidth, (scrollBar.top - last_top), False);
69
70   if (scrollBar.bot < last_bot)
71     XClearArea(Xdisplay, scrollBar.win,
72                sb_shadow + xsb, scrollBar.bot,
73                sbwidth, (last_bot - scrollBar.bot), False);
74
75   /* scrollbar slider */
76   XFillRectangle(Xdisplay, scrollBar.win, xscrollbarGC,
77                  xsb + 1, scrollBar.top, sbwidth - 2, scrollbar_len);
78
79   XDrawLine(Xdisplay, scrollBar.win, ShadowGC,
80             xsb ? 0 : sbwidth, scrollBar.beg,
81             xsb ? 0 : sbwidth, scrollBar.end);
82   return 1;
83 }
84 #endif                          /* XTERM_SCROLLBAR */
85 /*----------------------- end-of-file (C source) -----------------------*/