set _NET_WM_USER_TIME on the window
[dana/urxvt.git] / src / scrollbar.h
1 #ifndef SCROLLBAR_H
2 #define SCROLLBAR_H
3
4 #include <X11/Xlib.h>
5
6 struct rxvt_term;
7
8 #define R_SB_NEXT               1
9 #define R_SB_XTERM              2
10 #define R_SB_PLAIN              4
11 #define R_SB_RXVT               8
12
13 #define R_SB_ALIGN_CENTRE       0
14 #define R_SB_ALIGN_TOP          1
15 #define R_SB_ALIGN_BOTTOM       2
16
17 #define SB_WIDTH_NEXT           19
18 #define SB_WIDTH_XTERM          15
19 #define SB_WIDTH_PLAIN          7
20 #ifndef SB_WIDTH_RXVT
21 # define SB_WIDTH_RXVT          10
22 #endif
23
24 /*
25  * NeXT scrollbar defines
26  */
27 #define SB_PADDING              1
28 #define SB_BORDER_WIDTH         1
29 #define SB_BEVEL_WIDTH_UPPER_LEFT       1
30 #define SB_BEVEL_WIDTH_LOWER_RIGHT      2
31 #define SB_LEFT_PADDING         (SB_PADDING + SB_BORDER_WIDTH)
32 #define SB_MARGIN_SPACE         (SB_PADDING * 2)
33 #define SB_BUTTON_WIDTH         (SB_WIDTH_NEXT - SB_MARGIN_SPACE - SB_BORDER_WIDTH)
34 #define SB_BUTTON_HEIGHT        (SB_BUTTON_WIDTH)
35 #define SB_BUTTON_SINGLE_HEIGHT (SB_BUTTON_HEIGHT + SB_PADDING)
36 #define SB_BUTTON_BOTH_HEIGHT   (SB_BUTTON_SINGLE_HEIGHT * 2)
37 #define SB_BUTTON_TOTAL_HEIGHT  (SB_BUTTON_BOTH_HEIGHT + SB_PADDING)
38 #define SB_BUTTON_BEVEL_X       (SB_LEFT_PADDING)
39 #define SB_BUTTON_FACE_X        (SB_BUTTON_BEVEL_X + SB_BEVEL_WIDTH_UPPER_LEFT)
40 #define SB_THUMB_MIN_HEIGHT     (SB_BUTTON_WIDTH - (SB_PADDING * 2))
41
42 enum sb_state {
43   STATE_IDLE = 1,
44   STATE_MOTION,
45   STATE_UP,
46   STATE_DOWN,
47 };
48
49 struct scrollBar_t
50 {
51   rxvt_term *term;
52   char            state;        /* scrollbar state                          */
53   char            init;         /* scrollbar has been initialised           */
54   unsigned int    beg;          /* slider sub-window begin height           */
55   unsigned int    end;          /* slider sub-window end height             */
56   unsigned int    top;          /* slider top position                      */
57   unsigned int    bot;          /* slider bottom position                   */
58   unsigned int    style;        /* style: rxvt, xterm, next                 */
59   unsigned int    width;        /* scrollbar width                          */
60   int             shadow;       /* scrollbar shadow width                   */
61   int             last_bot;     /* scrollbar last bottom position           */
62   int             last_top;     /* scrollbar last top position              */
63   int             last_state;   /* scrollbar last state                     */
64   unsigned char   align;
65   Window          win;
66   Cursor          leftptr_cursor;
67   int             (scrollBar_t::*update)(int);
68   void setup (rxvt_term *);
69   void resize ();
70   int map (int);
71   int show (int);
72   void destroy ();
73
74   bool upButton (int y)
75   {
76     if (style == R_SB_NEXT)
77       return y > end && y <= end + width + 1;
78     if (style == R_SB_RXVT)
79       return y < beg;
80     return false;
81   }
82   bool dnButton (int y)
83   {
84     if (style == R_SB_NEXT)
85       return y > end + width + 1;
86     if (style == R_SB_RXVT)
87       return y > end;
88     return false;
89   }
90   unsigned min_height ()
91   {
92     return style == R_SB_NEXT ? SB_THUMB_MIN_HEIGHT : 10;
93   }
94   unsigned size ()
95   {
96     return end - beg - min_height ();
97   }
98   unsigned total_width ()
99   {
100     return width + shadow * 2;
101   }
102
103 #if defined(NEXT_SCROLLBAR)
104   GC              blackGC,
105                   whiteGC,
106                   grayGC,
107                   darkGC,
108                   stippleGC;
109   Pixmap          dimple,
110                   upArrow,
111                   downArrow,
112                   upArrowHi,
113                   downArrowHi;
114 #endif
115
116 #if defined(RXVT_SCROLLBAR)
117   GC              scrollbarGC,
118                   topShadowGC,
119                   botShadowGC;
120 #endif
121
122 #if defined(XTERM_SCROLLBAR)
123   GC              xscrollbarGC,
124                   ShadowGC;
125 #endif
126
127 #if defined(PLAIN_SCROLLBAR)
128   GC              pscrollbarGC;
129 #endif
130
131 private:
132   // update style dependent data
133   void update_data ();
134
135   // scrollbar-next.C
136   int show_next (int);
137   // scrollbar-rxvt.C
138   int show_rxvt (int);
139   // scrollbar-xterm.C
140   int show_xterm (int);
141   // scrollbar-plain.C
142   int show_plain (int);
143
144   void init_next ();
145 };
146
147 #define scrollbar_above_slider(y)       ((y) < scrollBar.top)
148 #define scrollbar_below_slider(y)       ((y) > scrollBar.bot)
149 #define scrollbar_position(y)           ((y) - scrollBar.beg)
150
151  /*
152   *    +-------------+
153   *    |             | <---< SB_PADDING
154   *    | ::::::::::: |
155   *    | ::::::::::: |
156   *   '''''''''''''''''
157   *   ,,,,,,,,,,,,,,,,,
158   *    | ::::::::::: |
159   *    | ::::::::::: |
160   *    |  +---------------< SB_BEVEL_WIDTH_UPPER_LEFT
161   *    |  | :::::::: |
162   *    |  V :::: vv-------< SB_BEVEL_WIDTH_LOWER_RIGHT
163   *    | +---------+ |
164   *    | | ......%%| |
165   *    | | ......%%| |
166   *    | | .. ()..%%| |
167   *    | | ......%%| |
168   *    | | %%%%%%%%| |
169   *    | +---------+ | <.........................
170   *    |             | <---< SB_PADDING         :
171   *    | +---------+ | <-+..........            :---< SB_BUTTON_TOTAL_HEIGHT
172   *    | | ......%%| |   |         :            :
173   *    | | ../\..%%| |   |---< SB_BUTTON_HEIGHT :
174   *    | | %%%%%%%%| |   |         :            :
175   *    | +---------+ | <-+         :            :
176   *    |             |             :            :
177   *    | +---------+ | <-+         :---< SB_BUTTON_BOTH_HEIGHT
178   *    | | ......%%| |   |         :            :
179   *    | | ..\/..%%| |   |         :            :
180   *    | | %%%%%%%%| |   |---< SB_BUTTON_SINGLE_HEIGHT
181   *    | +---------+ |   |         :            :
182   *    |             |   |         :            :
183   *    +-------------+ <-+.........:............:
184   *    ^^|_________| :
185   *    ||     |      :
186   *    ||     +---< SB_BUTTON_WIDTH
187   *    ||            :
188   *    |+------< SB_PADDING
189   *    |:            :
190   *    +----< SB_BORDER_WIDTH
191   *     :            :
192   *     :............:
193   *           |
194   *           +---< SB_WIDTH_NEXT
195   */
196
197 #endif