First checkin, AXE release 0.2
[AXE.git] / src / scroll.h
1
2 /**************************************************************************
3 **  (c) Copyright 1998, Andromeda Technology & Automation
4 ***************************************************************************
5 ** MODULE INFORMATION *
6 ***********************
7 **      FILE NAME      : scroll.h
8 **      SYSTEM NAME    : AXE - Andromeda X-windows Encapsulation
9 **      VERSION NUMBER : $Revision: 1.1 $
10 **
11 **  DESCRIPTION      :  Definition of scrollbar class.
12 **                      A scrollbar is a construction with two frames. The
13 **                      scrollbar itself and a slider that moves within
14 **                      the scrollbar.
15 **
16 **  EXPORTED OBJECTS : 
17 **  LOCAL    OBJECTS : 
18 **  MODULES  USED    :
19 ***************************************************************************
20 **  ADMINISTRATIVE INFORMATION *
21 ********************************
22 **      ORIGINAL AUTHOR : Arjen Baart - arjen@andromeda.nl
23 **      CREATION DATE   : Mar 20, 1998
24 **      LAST UPDATE     : Oct 09, 1999
25 **      MODIFICATIONS   : 
26 **************************************************************************/
27
28 /*****************************
29    $Log: scroll.h,v $
30    Revision 1.1  2002-07-25 08:01:27  arjen
31    First checkin, AXE release 0.2
32
33 *****************************/
34
35 /* static const char *RCSID = "$Id: scroll.h,v 1.1 2002-07-25 08:01:27 arjen Exp $"; */
36
37 #ifndef _SCROLL_H
38 #define _SCROLL_H
39
40 #include "frame.h"
41
42 class scrollbar;
43
44 /*
45 ///////////////////////////////////////////////////////////////////////////
46 //  NAME           : slider
47 //  BASECLASS      : frame
48 //  MEMBERS        :
49 //  OPERATORS      :
50 //  METHODS        :
51 //
52 //  DESCRIPTION    :
53 //
54 //  RELATIONS      :
55 //  SEE ALSO       :
56 //  LAST MODIFIED  : Oct 09, 1999
57 ///////////////////////////////////////////////////////////////////////////
58 */
59
60 class slider : public frame
61 {
62    scrollbar  *bar;
63
64    int        slide_start_y;
65
66 public:
67
68    slider(scrollbar *b);
69    
70    virtual int EV_ButtonPress(XButtonEvent ev)
71    {
72       slide_start_y = ev.y;
73
74       return 1;
75    }
76
77    virtual int EV_ButtonRelease(XButtonEvent ev)
78    {
79       return 1;
80    }
81
82    virtual int EV_MotionNotify(XMotionEvent ev);
83 };
84
85 /*
86 ///////////////////////////////////////////////////////////////////////////
87 //  NAME           : scrollbar
88 //  BASECLASS      : frame
89 //  MEMBERS        :
90 //  OPERATORS      :
91 //  METHODS        :
92 //
93 //  DESCRIPTION    :
94 //                   The bar_size, slider_size and position are defined
95 //                   in logical coordinates.
96 //                   The bar_size represents the size of the data being
97 //                   scrolled and corresponds to the total size of the
98 //                   scrollbar. The slider_size and position are mapped to
99 //                   physical coordinates using the ratio of the bar_size.
100 //
101 //                   physical coord = logical coord * window size / bar size.
102 //
103 //  RELATIONS      :
104 //  SEE ALSO       :
105 //  LAST MODIFIED  : Apr 03, 1998
106 ///////////////////////////////////////////////////////////////////////////
107 */
108
109 class scrollbar : public frame
110 {
111    slider  *sl;
112
113    unsigned   bar_size, slider_size;
114
115    int     position;
116
117 public:
118
119    scrollbar(window &par, unsigned size, int x, int y)
120       : frame(par, x, y, -2)
121    {
122       Resize(16, size);
123       bar_size = size;
124       slider_size = 16;
125       sl = new slider(this);
126       position = 0;
127       SelectInput(ButtonPressMask, 1);
128    }
129    
130    ~scrollbar()
131    {
132       delete sl;
133    }
134
135    //  Map physical pixel coordinate to logical coordinate.
136
137    int map_mouse(int mouse)
138    {
139       size scroll_size = Size();
140       int  physical;
141
142       physical =  mouse * (int)bar_size / scroll_size.h;
143
144       return  physical;
145    }
146
147    void move_slider(int offset);
148
149    virtual int EV_ButtonPress(XButtonEvent ev)
150    {
151       if (map_mouse(ev.y) > position)
152          move_slider(slider_size);
153       else
154          move_slider(-slider_size);
155
156       return 1;
157    }
158
159    operator int()
160    {
161       return position;
162    }
163
164    void SetSizes(unsigned s_bar, unsigned s_slider);
165 };
166
167 #endif /* _SCROLL_H */