Do not link rxvtc to ev_cpp.o, it does not use libev.
[dana/urxvt.git] / src / scrollbar-rxvt.C
1 /*----------------------------------------------------------------------*
2  * File:        scrollbar-rxvt.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  * Copyright (c) 2004-2006 Marc Lehmann <pcg@goof.com>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22  *----------------------------------------------------------------------*/
23
24 #include "../config.h"          /* NECESSARY */
25 #include "rxvt.h"               /* NECESSARY */
26
27 /*----------------------------------------------------------------------*/
28 #if defined(RXVT_SCROLLBAR)
29
30 static void
31 draw_shadow (scrollBar_t *sb, int x, int y, int w, int h)
32 {
33   int shadow;
34   Drawable d = sb->win;
35   Display *dpy = sb->term->dpy;
36
37   shadow = (w == 0 || h == 0) ? 1 : SHADOW_WIDTH;
38   w += x - 1;
39   h += y - 1;
40
41   for (; shadow-- > 0; x++, y++, w--, h--)
42     {
43       XDrawLine (dpy, d, sb->topShadowGC, x, y, w    , y    );
44       XDrawLine (dpy, d, sb->topShadowGC, x, y, x    , h    );
45       XDrawLine (dpy, d, sb->botShadowGC, w, h, w    , y + 1);
46       XDrawLine (dpy, d, sb->botShadowGC, w, h, x + 1, h    );
47     }
48 }
49
50 /* draw triangular button with a shadow of 2 pixels */
51 static void
52 draw_button (scrollBar_t *sb, int x, int y, int dirn)
53 {
54   unsigned int sz, sz2;
55   XPoint pt[3];
56   GC top, bot;
57   Drawable d = sb->win;
58   Display *dpy = sb->term->dpy;
59
60   sz = sb->width;
61   sz2 = sz / 2;
62
63   if ((dirn == UP && sb->state == STATE_UP)
64       || (dirn == DN && sb->state == STATE_DOWN))
65     {
66       top = sb->botShadowGC;
67       bot = sb->topShadowGC;
68     }
69   else
70     {
71       top = sb->topShadowGC;
72       bot = sb->botShadowGC;
73     }
74
75   /* fill triangle */
76   pt[0].x = x;
77   pt[1].x = x + sz - 1;
78   pt[2].x = x + sz2;
79
80   if (dirn == UP)
81     {
82       pt[0].y = pt[1].y = y + sz - 1;
83       pt[2].y = y;
84     }
85   else
86     {
87       pt[0].y = pt[1].y = y;
88       pt[2].y = y + sz - 1;
89     }
90
91   XFillPolygon (dpy, d, sb->scrollbarGC,
92                 pt, 3, Convex, CoordModeOrigin);
93
94   /* draw base */
95   XDrawLine (dpy, d, (dirn == UP ? bot : top),
96              pt[0].x, pt[0].y, pt[1].x, pt[1].y);
97
98   /* draw shadow on left */
99   pt[1].x = x + sz2 - 1;
100   pt[1].y = y + (dirn == UP ? 0 : sz - 1);
101   XDrawLine (dpy, d, top,
102              pt[0].x, pt[0].y, pt[1].x, pt[1].y);
103
104 #if SHADOW_WIDTH > 1
105   /* doubled */
106   pt[0].x++;
107
108   if (dirn == UP)
109     {
110       pt[0].y--;
111       pt[1].y++;
112     }
113   else
114     {
115       pt[0].y++;
116       pt[1].y--;
117     }
118
119   XDrawLine (dpy, d, top,
120              pt[0].x, pt[0].y, pt[1].x, pt[1].y);
121 #endif
122
123   /* draw shadow on right */
124   pt[1].x = x + sz - 1;
125   /*  pt[2].x = x + sz2; */
126   pt[1].y = y + (dirn == UP ? sz - 1 : 0);
127   pt[2].y = y + (dirn == UP ? 0 : sz - 1);
128   XDrawLine (dpy, d, bot,
129              pt[2].x, pt[2].y, pt[1].x, pt[1].y);
130
131 #if SHADOW_WIDTH > 1
132   /* doubled */
133   pt[1].x--;
134   if (dirn == UP)
135     {
136       pt[2].y++;
137       pt[1].y--;
138     }
139   else
140     {
141       pt[2].y--;
142       pt[1].y++;
143     }
144
145   XDrawLine (dpy, d, bot,
146              pt[2].x, pt[2].y, pt[1].x, pt[1].y);
147 #endif
148 }
149
150 int
151 scrollBar_t::show_rxvt (int update)
152 {
153   int sbshadow = shadow;
154   int sbwidth = (int)width;
155
156   if ((init & R_SB_RXVT) == 0)
157     {
158       XGCValues gcvalue;
159
160       init |= R_SB_RXVT;
161
162       gcvalue.foreground = term->pix_colors[Color_topShadow];
163       topShadowGC = XCreateGC (term->dpy, term->vt, GCForeground, &gcvalue);
164       gcvalue.foreground = term->pix_colors[Color_bottomShadow];
165       botShadowGC = XCreateGC (term->dpy, term->vt, GCForeground, &gcvalue);
166       gcvalue.foreground = term->pix_colors[ (term->depth <= 2 ? Color_fg : Color_scroll)];
167       scrollbarGC = XCreateGC (term->dpy, term->vt, GCForeground, &gcvalue);
168       if (sbshadow)
169         {
170           XSetWindowBackground (term->dpy, win, term->pix_colors_focused[Color_trough]);
171           XClearWindow (term->dpy, win);
172         }
173     }
174   else
175     {
176       if (update)
177         {
178           if (last_top < top)
179             XClearArea (term->dpy, win,
180                         sbshadow, last_top,
181                         sbwidth, (top - last_top),
182                         False);
183
184           if (bot < last_bot)
185             XClearArea (term->dpy, win,
186                         sbshadow, bot,
187                         sbwidth, (last_bot - bot),
188                         False);
189         }
190       else
191         XClearWindow (term->dpy, win);
192     }
193
194   /* scrollbar slider */
195 #ifdef SB_BORDER
196   {
197     int xofs;
198
199     if (term->option (Opt_scrollBar_right))
200       xofs = 0;
201     else
202       xofs = sbshadow ? sbwidth : sbwidth - 1;
203
204     XDrawLine (term->dpy, win, botShadowGC,
205                xofs, 0, xofs, end + sbwidth);
206   }
207 #endif
208
209   XFillRectangle (term->dpy, win, scrollbarGC,
210                   sbshadow, top, sbwidth,
211                   bot - top);
212
213   if (sbshadow)
214     /* trough shadow */
215     draw_shadow (this, 0, 0, sbwidth + 2 * sbshadow, end + (sbwidth + 1) + sbshadow);
216
217   /* shadow for scrollbar slider */
218   draw_shadow (this, sbshadow, top, sbwidth, bot - top);
219
220   /* Redraw scrollbar arrows */
221   draw_button (this, sbshadow, sbshadow, UP);
222   draw_button (this, sbshadow, end + 1,  DN);
223
224   return 1;
225 }
226 #endif /* RXVT_SCROLLBAR */
227 /*----------------------- end-of-file (C source) -----------------------*/
228