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 $
11 ** DESCRIPTION : Implementation of scrollbar class.
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
23 **************************************************************************/
25 /*****************************
27 Revision 1.1 2002-07-25 08:01:27 arjen
28 First checkin, AXE release 0.2
30 *****************************/
32 static const char *RCSID = "$Id: scroll.cpp,v 1.1 2002-07-25 08:01:27 arjen Exp $";
36 slider::slider(scrollbar *b) : frame(*b, 0, 0, 2)
41 SelectInput(ButtonPressMask|Button1MotionMask|ButtonReleaseMask, 1);
45 /*=========================================================================
46 ** NAME : EV_MotionNotify
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.
61 ** LAST MODIFIED : Apr 04, 1998
62 **=========================================================================
65 int slider::EV_MotionNotify(XMotionEvent ev)
67 bar->move_slider(bar->map_mouse(ev.y - slide_start_y));
72 /*=========================================================================
74 ** SYNOPSIS : void scrollbar::move_slider(int offset)
75 ** PARAMETERS : offset : change in the slider's position
76 ** RETURN VALUE : None
78 ** DESCRIPTION : Moves the slider within the scrollbar. Called when
79 ** the mouse is clicked in the scrollbar or when the
81 ** The offset is in logical coordinates.
87 ** LAST MODIFIED : Apr 04, 1998
88 **=========================================================================
91 void scrollbar::move_slider(int offset)
93 int physical_position;
98 // Clip the slider in its range.
102 if (position + slider_size > bar_size)
103 position = bar_size - slider_size;
105 scroll_size = Size();
106 physical_position = position * scroll_size.h / bar_size;
108 sl->Move(0, physical_position);
109 ParentMessage(SCROLL_POSITIONED);
112 /*=========================================================================
124 ** LAST MODIFIED : Aug 30, 1999
125 **=========================================================================
128 void scrollbar::SetSizes(unsigned s_bar, unsigned s_slider)
131 size physical_slider;
133 // Needs to recalculate the position in logical coordinates.
136 slider_size = s_slider;
138 scroll_size = Size();
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;
145 sl->Resize(physical_slider);