First checkin, AXE release 0.2
[AXE.git] / src / scroll.cpp
1
2 /**************************************************************************
3 **  (c) Copyright 1998, Andromeda Technology & Automation
4 ***************************************************************************
5 ** MODULE INFORMATION *
6 ***********************
7 **      FILE NAME      : scroll.cpp
8 **      SYSTEM NAME    : AXE - Andromeda X-windows Encapsulation
9 **      VERSION NUMBER : $Revision: 1.1 $
10 **
11 **  DESCRIPTION      :  Implementation of scrollbar class.
12 **
13 **  EXPORTED OBJECTS : 
14 **  LOCAL    OBJECTS : 
15 **  MODULES  USED    :
16 ***************************************************************************
17 **  ADMINISTRATIVE INFORMATION *
18 ********************************
19 **      ORIGINAL AUTHOR : Arjen Baart - arjen@andromeda.nl
20 **      CREATION DATE   : Mar 20, 1998
21 **      LAST UPDATE     : Apr 04, 1998
22 **      MODIFICATIONS   : 
23 **************************************************************************/
24
25 /*****************************
26    $Log: scroll.cpp,v $
27    Revision 1.1  2002-07-25 08:01:27  arjen
28    First checkin, AXE release 0.2
29
30 *****************************/
31
32 static const char *RCSID = "$Id: scroll.cpp,v 1.1 2002-07-25 08:01:27 arjen Exp $";
33
34 #include "scroll.h"
35
36 slider::slider(scrollbar *b) : frame(*b, 0, 0, 2)
37 {
38    bar = b;
39    slide_start_y = 7;
40    Resize(14,14);
41    SelectInput(ButtonPressMask|Button1MotionMask|ButtonReleaseMask, 1);
42    Map();
43 }
44
45 /*=========================================================================
46 **  NAME           : EV_MotionNotify
47 **  SYNOPSIS       :
48 **  PARAMETERS     :
49 **  RETURN VALUE   :
50 **
51 **  DESCRIPTION    : Move the mouse in the slider with button 1 pressed.
52 **                   move_slider() cannot be used directly because the
53 **                   motion is in physical coordinates and move_slider()
54 **                   needs an offset in logical coordinates. The function
55 **                   scrollbar::map_mouse() performs the translation.
56 **
57 **  VARS USED      :
58 **  VARS CHANGED   :
59 **  FUNCTIONS USED :
60 **  SEE ALSO       :
61 **  LAST MODIFIED  : Apr 04, 1998
62 **=========================================================================
63 */
64
65 int slider::EV_MotionNotify(XMotionEvent ev)
66 {
67    bar->move_slider(bar->map_mouse(ev.y - slide_start_y));
68
69    return 1;
70 }
71
72 /*=========================================================================
73 **  NAME           : move_slider
74 **  SYNOPSIS       : void scrollbar::move_slider(int offset)
75 **  PARAMETERS     : offset : change in the slider's position
76 **  RETURN VALUE   : None
77 **
78 **  DESCRIPTION    : Moves the slider within the scrollbar. Called when
79 **                   the mouse is clicked in the scrollbar or when the
80 **                   slider is dragged.
81 **                   The offset is in logical coordinates.
82 **
83 **  VARS USED      :
84 **  VARS CHANGED   :
85 **  FUNCTIONS USED :
86 **  SEE ALSO       :
87 **  LAST MODIFIED  : Apr 04, 1998
88 **=========================================================================
89 */
90
91 void scrollbar::move_slider(int offset)
92 {
93    int    physical_position;
94    size   scroll_size;
95
96    position += offset;
97
98    //  Clip the slider in its range.
99
100    if (position < 0)
101       position = 0;
102    if (position + slider_size > bar_size)
103       position = bar_size - slider_size;
104
105    scroll_size = Size();
106    physical_position = position * scroll_size.h / bar_size;
107
108    sl->Move(0, physical_position);
109    ParentMessage(SCROLL_POSITIONED);
110 }
111
112 /*=========================================================================
113 **  NAME           : SetSizes
114 **  SYNOPSIS       :
115 **  PARAMETERS     :
116 **  RETURN VALUE   :
117 **
118 **  DESCRIPTION    : 
119 **
120 **  VARS USED      :
121 **  VARS CHANGED   :
122 **  FUNCTIONS USED :
123 **  SEE ALSO       :
124 **  LAST MODIFIED  : Aug 30, 1999
125 **=========================================================================
126 */
127
128 void scrollbar::SetSizes(unsigned s_bar, unsigned s_slider)
129 {
130    size scroll_size;
131    size physical_slider;
132
133    //  Needs to recalculate the position in logical coordinates.
134
135    bar_size = s_bar;
136    slider_size = s_slider;
137
138    scroll_size = Size();
139
140    physical_slider.w = 14;
141    physical_slider.h = slider_size * scroll_size.h / bar_size;
142    if (physical_slider.h < 5)
143       physical_slider.h = 5;
144
145    sl->Resize(physical_slider);
146 }
147