*** empty log message ***
[dana/urxvt.git] / src / scrollbar-next.C
1 /*--------------------------------*-C-*---------------------------------*
2  * File:        scrollbar-next.C
3  *----------------------------------------------------------------------*
4  *
5  * Copyright (c) 1997,1998 mj olesen <olesen@me.QueensU.CA>
6  * Copyright (c) 1998      Alfredo K. Kojima <kojima@windowmaker.org>
7  *                              - N*XTstep like scrollbars
8  * Copyright (c) 1999-2001 Geoff Wing <gcw@pobox.com>
9  * Copyright (c) 2004      Marc Lehmann <pcg@goof.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
29 /*----------------------------------------------------------------------*/
30 #if defined(NEXT_SCROLLBAR)
31
32 #define n_stp_width     8
33 #define n_stp_height    2
34 const unsigned char n_stp_bits[] = { 0x55, 0xaa };
35
36 /*
37  * N*XTSTEP like scrollbar - written by Alfredo K. Kojima
38  */
39 #define SCROLLER_DIMPLE_WIDTH   6
40 #define SCROLLER_DIMPLE_HEIGHT  6
41 #define ARROW_WIDTH   13
42 #define ARROW_HEIGHT  13
43
44 const char     *const SCROLLER_DIMPLE[] =
45   {
46     ".%###.",
47     "%#%%%%",
48     "#%%...",
49     "#%..  ",
50     "#%.   ",
51     ".%.  ."
52   };
53 const char     *const SCROLLER_ARROW_UP[] =
54   {
55     ".............",
56     ".............",
57     "......%......",
58     "......#......",
59     ".....%#%.....",
60     ".....###.....",
61     "....%###%....",
62     "....#####....",
63     "...%#####%...",
64     "...#######...",
65     "..%#######%..",
66     ".............",
67     "............."
68   };
69 const char     *const SCROLLER_ARROW_DOWN[] =
70   {
71     ".............",
72     ".............",
73     "..%#######%..",
74     "...#######...",
75     "...%#####%...",
76     "....#####....",
77     "....%###%....",
78     ".....###.....",
79     ".....%#%.....",
80     "......#......",
81     "......%......",
82     ".............",
83     "............."
84   };
85 const char     *const HI_SCROLLER_ARROW_UP[] =
86   {
87     "             ",
88     "             ",
89     "      %      ",
90     "      %      ",
91     "     %%%     ",
92     "     %%%     ",
93     "    %%%%%    ",
94     "    %%%%%    ",
95     "   %%%%%%%   ",
96     "   %%%%%%%   ",
97     "  %%%%%%%%%  ",
98     "             ",
99     "             "
100   };
101 const char     *const HI_SCROLLER_ARROW_DOWN[] =
102   {
103     "             ",
104     "             ",
105     "  %%%%%%%%%  ",
106     "   %%%%%%%   ",
107     "   %%%%%%%   ",
108     "    %%%%%    ",
109     "    %%%%%    ",
110     "     %%%     ",
111     "     %%%     ",
112     "      %      ",
113     "      %      ",
114     "             ",
115     "             "
116   };
117
118 Pixmap
119 rxvt_term::renderPixmap (const char *const *data, int width, int height)
120 {
121   char            a;
122   int             x, y;
123   Pixmap          d;
124   GC              pointcolour;
125
126   d = XCreatePixmap (display->display, scrollBar.win, width, height, display->depth);
127
128   for (y = 0; y < height; y++)
129     {
130       for (x = 0; x < width; x++)
131         {
132           if ((a = data[y][x]) == ' ' || a == 'w')
133             pointcolour = whiteGC;
134           else if (a == '.' || a == 'l')
135             pointcolour = grayGC;
136           else if (a == '%' || a == 'd')
137             pointcolour = darkGC;
138           else          /* if (a == '#' || a == 'b' || a) */
139             pointcolour = blackGC;
140
141           XDrawPoint (display->display, d, pointcolour, x, y);
142         }
143     }
144   return d;
145 }
146
147 void
148 rxvt_term::init_scrollbar_stuff ()
149 {
150   XGCValues       gcvalue;
151   XColor          xcol;
152   Pixmap          stipple;
153   unsigned long   light, dark;
154   dDisp;
155
156   gcvalue.graphics_exposures = False;
157
158   gcvalue.foreground = pix_colors_focused[Color_Black];
159   blackGC = XCreateGC (disp, scrollBar.win,
160                       GCForeground | GCGraphicsExposures, &gcvalue);
161
162   gcvalue.foreground = pix_colors_focused[Color_White];
163   whiteGC = XCreateGC (disp, scrollBar.win,
164                       GCForeground | GCGraphicsExposures, &gcvalue);
165
166   xcol.red = 0xaeba;
167   xcol.green = 0xaaaa;
168   xcol.blue = 0xaeba;
169   xcol.pixel = pix_colors_focused[Color_scroll];
170   light = gcvalue.foreground = xcol.pixel;
171   grayGC = XCreateGC (disp, scrollBar.win,
172                      GCForeground | GCGraphicsExposures, &gcvalue);
173
174   xcol.red = 0x51aa;
175   xcol.green = 0x5555;
176   xcol.blue = 0x5144;
177   //if (!rXAllocColor (&xcol, "dark gray"))//TODO//D//
178   xcol.pixel = pix_colors_focused[Color_Grey25];
179   dark = gcvalue.foreground = xcol.pixel;
180   darkGC = XCreateGC (disp, scrollBar.win,
181                      GCForeground | GCGraphicsExposures, &gcvalue);
182
183   stipple = XCreateBitmapFromData (disp, scrollBar.win,
184                                   (char *)n_stp_bits, n_stp_width,
185                                   n_stp_height);
186
187   gcvalue.foreground = dark;
188   gcvalue.background = light;
189   gcvalue.fill_style = FillOpaqueStippled;
190   gcvalue.stipple = stipple;
191
192   /*    XSetWindowBackground (disp, scrollBar.win, pix_colors_focused[Color_Red]); */
193
194   stippleGC = XCreateGC (disp, scrollBar.win,
195                         GCForeground | GCBackground | GCStipple
196                         | GCFillStyle | GCGraphicsExposures, &gcvalue);
197
198   dimple = renderPixmap (SCROLLER_DIMPLE, SCROLLER_DIMPLE_WIDTH,
199                          SCROLLER_DIMPLE_HEIGHT);
200
201   upArrow = renderPixmap (SCROLLER_ARROW_UP, ARROW_WIDTH,
202                           ARROW_HEIGHT);
203   downArrow = renderPixmap (SCROLLER_ARROW_DOWN, ARROW_WIDTH,
204                             ARROW_HEIGHT);
205   upArrowHi = renderPixmap (HI_SCROLLER_ARROW_UP, ARROW_WIDTH,
206                             ARROW_HEIGHT);
207   downArrowHi = renderPixmap (HI_SCROLLER_ARROW_DOWN,
208                               ARROW_WIDTH, ARROW_HEIGHT);
209 }
210
211 /* Draw bevel & arrows */
212 void
213 rxvt_term::drawBevel (Drawable d, int x1, int y1, int w, int h)
214 {
215   int x2, y2;
216   dDisp;
217
218   x2 = x1 + w - 1;              /* right  point */
219   y2 = y1 + h - 1;              /* bottom point */
220   /* white top and left */
221   XDrawLine (disp, d, whiteGC, x1, y1, x2, y1);
222   XDrawLine (disp, d, whiteGC, x1, y1, x1, y2);
223   /* black bottom and right */
224   XDrawLine (disp, d, blackGC, x1, y2, x2, y2);
225   XDrawLine (disp, d, blackGC, x2, y1, x2, y2);
226   /* dark inside bottom and right */
227   x1++, y1++, x2--, y2--;       /* move in one point */
228   XDrawLine (disp, d, darkGC, x1, y2, x2, y2);
229   XDrawLine (disp, d, darkGC, x2, y1, x2, y2);
230 }
231
232 int
233 rxvt_term::scrollbar_show_next (int update, int last_top, int last_bot, int scrollbar_len)
234 {
235   int height = scrollBar.end + SB_BUTTON_TOTAL_HEIGHT + SB_PADDING;
236   Drawable s;
237   dDisp;
238
239   if ((scrollBar.init & R_SB_NEXT) == 0)
240     {
241       scrollBar.init |= R_SB_NEXT;
242       init_scrollbar_stuff ();
243     }
244
245   if (TermWin.nscrolled == 0 || !update)
246     {
247       XFillRectangle (disp, scrollBar.win, grayGC, 0, 0,
248                      SB_WIDTH_NEXT + 1, height);
249       XDrawRectangle (disp, scrollBar.win, blackGC, 0,
250                      -SB_BORDER_WIDTH, SB_WIDTH_NEXT,
251                      height + SB_BORDER_WIDTH);
252       XFillRectangle (disp, scrollBar.win, stippleGC,
253                      SB_LEFT_PADDING, 0, SB_BUTTON_WIDTH, height);
254     }
255
256   if (TermWin.nscrolled)
257     {
258       if (last_top < scrollBar.top || !update)
259         XFillRectangle (disp, scrollBar.win, stippleGC,
260                        SB_LEFT_PADDING, SB_PADDING + last_top,
261                        SB_BUTTON_WIDTH, scrollBar.top - last_top);
262
263       if (scrollBar.bot < last_bot || !update)
264         XFillRectangle (disp, scrollBar.win, stippleGC,
265                        SB_LEFT_PADDING, scrollBar.bot + SB_PADDING,
266                        SB_BUTTON_WIDTH, (last_bot - scrollBar.bot));
267
268       XFillRectangle (disp, scrollBar.win, grayGC,
269                      SB_LEFT_PADDING, scrollBar.top + SB_PADDING,
270                      SB_BUTTON_WIDTH, scrollbar_len);
271
272       XCopyArea (disp, dimple, scrollBar.win, whiteGC, 0, 0,
273                 SCROLLER_DIMPLE_WIDTH, SCROLLER_DIMPLE_HEIGHT,
274                 (SB_WIDTH_NEXT - SCROLLER_DIMPLE_WIDTH) / 2,
275                 scrollBar.top + SB_BEVEL_WIDTH_UPPER_LEFT +
276                 (scrollbar_len - SCROLLER_DIMPLE_HEIGHT) / 2);
277
278       drawBevel (scrollBar.win, SB_BUTTON_BEVEL_X,
279                  scrollBar.top + SB_PADDING, SB_BUTTON_WIDTH,
280                  scrollbar_len);
281       drawBevel (scrollBar.win, SB_BUTTON_BEVEL_X,
282                  height - SB_BUTTON_BOTH_HEIGHT, SB_BUTTON_WIDTH,
283                  SB_BUTTON_HEIGHT);
284       drawBevel (scrollBar.win, SB_BUTTON_BEVEL_X,
285                  height - SB_BUTTON_SINGLE_HEIGHT, SB_BUTTON_WIDTH,
286                  SB_BUTTON_HEIGHT);
287
288       s = (scrollbar_isUp ()) ? upArrowHi : upArrow;
289       XCopyArea (disp, s, scrollBar.win, whiteGC, 0, 0,
290                 ARROW_WIDTH, ARROW_HEIGHT, SB_BUTTON_FACE_X,
291                 height - SB_BUTTON_BOTH_HEIGHT + SB_BEVEL_WIDTH_UPPER_LEFT);
292
293       s = (scrollbar_isDn ()) ? downArrowHi : downArrow;
294       XCopyArea (disp, s, scrollBar.win, whiteGC, 0, 0,
295                 ARROW_WIDTH, ARROW_HEIGHT, SB_BUTTON_FACE_X,
296                 height - SB_BUTTON_SINGLE_HEIGHT + SB_BEVEL_WIDTH_UPPER_LEFT);
297     }
298
299   return 1;
300 }
301 #endif                          /* NEXT_SCROLLBAR */
302 /*----------------------- end-of-file (C source) -----------------------*/