xref: /aoo41x/main/vcl/source/control/slider.cxx (revision 9f62ea84)
1*9f62ea84SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*9f62ea84SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*9f62ea84SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*9f62ea84SAndrew Rist  * distributed with this work for additional information
6*9f62ea84SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*9f62ea84SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*9f62ea84SAndrew Rist  * "License"); you may not use this file except in compliance
9*9f62ea84SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*9f62ea84SAndrew Rist  *
11*9f62ea84SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*9f62ea84SAndrew Rist  *
13*9f62ea84SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*9f62ea84SAndrew Rist  * software distributed under the License is distributed on an
15*9f62ea84SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*9f62ea84SAndrew Rist  * KIND, either express or implied.  See the License for the
17*9f62ea84SAndrew Rist  * specific language governing permissions and limitations
18*9f62ea84SAndrew Rist  * under the License.
19*9f62ea84SAndrew Rist  *
20*9f62ea84SAndrew Rist  *************************************************************/
21*9f62ea84SAndrew Rist 
22*9f62ea84SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_vcl.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #ifndef _SV_RC_H
28cdf0e10cSrcweir #include <tools/rc.h>
29cdf0e10cSrcweir #endif
30cdf0e10cSrcweir #include <vcl/event.hxx>
31cdf0e10cSrcweir #include <vcl/decoview.hxx>
32cdf0e10cSrcweir #include <vcl/slider.hxx>
33cdf0e10cSrcweir 
34cdf0e10cSrcweir 
35cdf0e10cSrcweir 
36cdf0e10cSrcweir // =======================================================================
37cdf0e10cSrcweir 
ImplMulDiv(long nNumber,long nNumerator,long nDenominator)38cdf0e10cSrcweir static long ImplMulDiv( long nNumber, long nNumerator, long nDenominator )
39cdf0e10cSrcweir {
40cdf0e10cSrcweir 	double n = ((double)nNumber * (double)nNumerator) / (double)nDenominator;
41cdf0e10cSrcweir 	return (long)n;
42cdf0e10cSrcweir }
43cdf0e10cSrcweir 
44cdf0e10cSrcweir // =======================================================================
45cdf0e10cSrcweir 
46cdf0e10cSrcweir #define SLIDER_DRAW_THUMB			((sal_uInt16)0x0001)
47cdf0e10cSrcweir #define SLIDER_DRAW_CHANNEL1		((sal_uInt16)0x0002)
48cdf0e10cSrcweir #define SLIDER_DRAW_CHANNEL2		((sal_uInt16)0x0004)
49cdf0e10cSrcweir #define SLIDER_DRAW_CHANNEL 		(SLIDER_DRAW_CHANNEL1 | SLIDER_DRAW_CHANNEL2)
50cdf0e10cSrcweir #define SLIDER_DRAW_ALL 			(SLIDER_DRAW_THUMB | SLIDER_DRAW_CHANNEL)
51cdf0e10cSrcweir 
52cdf0e10cSrcweir #define SLIDER_STATE_CHANNEL1_DOWN	((sal_uInt16)0x0001)
53cdf0e10cSrcweir #define SLIDER_STATE_CHANNEL2_DOWN	((sal_uInt16)0x0002)
54cdf0e10cSrcweir #define SLIDER_STATE_THUMB_DOWN 	((sal_uInt16)0x0004)
55cdf0e10cSrcweir 
56cdf0e10cSrcweir #define SLIDER_THUMB_SIZE			9
57cdf0e10cSrcweir #define SLIDER_THUMB_HALFSIZE		4
58cdf0e10cSrcweir #define SLIDER_CHANNEL_OFFSET		0
59cdf0e10cSrcweir #define SLIDER_CHANNEL_SIZE 		4
60cdf0e10cSrcweir #define SLIDER_CHANNEL_HALFSIZE 	2
61cdf0e10cSrcweir 
62cdf0e10cSrcweir #define SLIDER_HEIGHT				16
63cdf0e10cSrcweir 
64cdf0e10cSrcweir #define SLIDER_VIEW_STYLE			(WB_3DLOOK | WB_HORZ | WB_VERT)
65cdf0e10cSrcweir 
66cdf0e10cSrcweir // =======================================================================
67cdf0e10cSrcweir 
ImplInit(Window * pParent,WinBits nStyle)68cdf0e10cSrcweir void Slider::ImplInit( Window* pParent, WinBits nStyle )
69cdf0e10cSrcweir {
70cdf0e10cSrcweir 	mnThumbPixOffset	= 0;
71cdf0e10cSrcweir 	mnThumbPixRange 	= 0;
72cdf0e10cSrcweir 	mnThumbPixPos		= 0;	// between mnThumbPixOffset and mnThumbPixOffset+mnThumbPixRange
73cdf0e10cSrcweir 	mnChannelPixOffset	= 0;
74cdf0e10cSrcweir 	mnChannelPixRange	= 0;
75cdf0e10cSrcweir 	mnChannelPixTop 	= 0;
76cdf0e10cSrcweir 	mnChannelPixBottom	= 0;
77cdf0e10cSrcweir 
78cdf0e10cSrcweir 	mnMinRange			= 0;
79cdf0e10cSrcweir 	mnMaxRange			= 100;
80cdf0e10cSrcweir 	mnThumbPos			= 0;
81cdf0e10cSrcweir 	mnLineSize			= 1;
82cdf0e10cSrcweir 	mnPageSize			= 1;
83cdf0e10cSrcweir 	mnDelta 			= 0;
84cdf0e10cSrcweir 	mnDragDraw			= 0;
85cdf0e10cSrcweir 	mnStateFlags		= 0;
86cdf0e10cSrcweir 	meScrollType		= SCROLL_DONTKNOW;
87cdf0e10cSrcweir 	mbCalcSize			= sal_True;
88cdf0e10cSrcweir 	mbFullDrag			= sal_True;
89cdf0e10cSrcweir 
90cdf0e10cSrcweir 	Control::ImplInit( pParent, nStyle, NULL );
91cdf0e10cSrcweir 
92cdf0e10cSrcweir 	ImplInitSettings();
93cdf0e10cSrcweir 	SetSizePixel( CalcWindowSizePixel() );
94cdf0e10cSrcweir }
95cdf0e10cSrcweir 
96cdf0e10cSrcweir // -----------------------------------------------------------------------
97cdf0e10cSrcweir 
Slider(Window * pParent,WinBits nStyle)98cdf0e10cSrcweir Slider::Slider( Window* pParent, WinBits nStyle ) :
99cdf0e10cSrcweir 	Control( WINDOW_SLIDER )
100cdf0e10cSrcweir {
101cdf0e10cSrcweir 	ImplInit( pParent, nStyle );
102cdf0e10cSrcweir }
103cdf0e10cSrcweir 
104cdf0e10cSrcweir // -----------------------------------------------------------------------
105cdf0e10cSrcweir 
Slider(Window * pParent,const ResId & rResId)106cdf0e10cSrcweir Slider::Slider( Window* pParent, const ResId& rResId ) :
107cdf0e10cSrcweir 	Control( WINDOW_SLIDER )
108cdf0e10cSrcweir {
109cdf0e10cSrcweir 	rResId.SetRT( RSC_SCROLLBAR );
110cdf0e10cSrcweir 	WinBits nStyle = ImplInitRes( rResId );
111cdf0e10cSrcweir 	ImplInit( pParent, nStyle );
112cdf0e10cSrcweir 	ImplLoadRes( rResId );
113cdf0e10cSrcweir 
114cdf0e10cSrcweir 	if ( !(nStyle & WB_HIDE) )
115cdf0e10cSrcweir 		Show();
116cdf0e10cSrcweir }
117cdf0e10cSrcweir 
118cdf0e10cSrcweir // -----------------------------------------------------------------------
119cdf0e10cSrcweir 
ImplLoadRes(const ResId & rResId)120cdf0e10cSrcweir void Slider::ImplLoadRes( const ResId& rResId )
121cdf0e10cSrcweir {
122cdf0e10cSrcweir 	Control::ImplLoadRes( rResId );
123cdf0e10cSrcweir 
124cdf0e10cSrcweir 	sal_Int16 nMin			= ReadShortRes();
125cdf0e10cSrcweir 	sal_Int16 nMax			= ReadShortRes();
126cdf0e10cSrcweir 	sal_Int16 nThumbPos		= ReadShortRes();
127cdf0e10cSrcweir 	sal_Int16 nPage			= ReadShortRes();
128cdf0e10cSrcweir 	sal_Int16 nStep			= ReadShortRes();
129cdf0e10cSrcweir 	/* sal_Int16 nVisibleSize	= */ ReadShortRes();
130cdf0e10cSrcweir 
131cdf0e10cSrcweir 	SetRange( Range( nMin, nMax ) );
132cdf0e10cSrcweir 	SetLineSize( nStep );
133cdf0e10cSrcweir 	SetPageSize( nPage );
134cdf0e10cSrcweir 	SetThumbPos( nThumbPos );
135cdf0e10cSrcweir }
136cdf0e10cSrcweir 
137cdf0e10cSrcweir // -----------------------------------------------------------------------
138cdf0e10cSrcweir 
ImplInitSettings()139cdf0e10cSrcweir void Slider::ImplInitSettings()
140cdf0e10cSrcweir {
141cdf0e10cSrcweir 	Window* pParent = GetParent();
142cdf0e10cSrcweir 	if ( pParent->IsChildTransparentModeEnabled() && !IsControlBackground() )
143cdf0e10cSrcweir 	{
144cdf0e10cSrcweir 		EnableChildTransparentMode( sal_True );
145cdf0e10cSrcweir 		SetParentClipMode( PARENTCLIPMODE_NOCLIP );
146cdf0e10cSrcweir 		SetPaintTransparent( sal_True );
147cdf0e10cSrcweir 		SetBackground();
148cdf0e10cSrcweir 	}
149cdf0e10cSrcweir 	else
150cdf0e10cSrcweir 	{
151cdf0e10cSrcweir 		EnableChildTransparentMode( sal_False );
152cdf0e10cSrcweir 		SetParentClipMode( 0 );
153cdf0e10cSrcweir 		SetPaintTransparent( sal_False );
154cdf0e10cSrcweir 
155cdf0e10cSrcweir 		if ( IsControlBackground() )
156cdf0e10cSrcweir 			SetBackground( GetControlBackground() );
157cdf0e10cSrcweir 		else
158cdf0e10cSrcweir 			SetBackground( pParent->GetBackground() );
159cdf0e10cSrcweir 	}
160cdf0e10cSrcweir }
161cdf0e10cSrcweir 
162cdf0e10cSrcweir // -----------------------------------------------------------------------
163cdf0e10cSrcweir 
ImplUpdateRects(sal_Bool bUpdate)164cdf0e10cSrcweir void Slider::ImplUpdateRects( sal_Bool bUpdate )
165cdf0e10cSrcweir {
166cdf0e10cSrcweir 	Rectangle aOldThumbRect = maThumbRect;
167cdf0e10cSrcweir 	bool bInvalidateAll = false;
168cdf0e10cSrcweir 
169cdf0e10cSrcweir 	if ( mnThumbPixRange )
170cdf0e10cSrcweir 	{
171cdf0e10cSrcweir 		if ( GetStyle() & WB_HORZ )
172cdf0e10cSrcweir 		{
173cdf0e10cSrcweir 			maThumbRect.Left()		= mnThumbPixPos-SLIDER_THUMB_HALFSIZE;
174cdf0e10cSrcweir 			maThumbRect.Right() 	= maThumbRect.Left()+SLIDER_THUMB_SIZE-1;
175cdf0e10cSrcweir 			if ( mnChannelPixOffset < maThumbRect.Left() )
176cdf0e10cSrcweir 			{
177cdf0e10cSrcweir 				maChannel1Rect.Left()	= mnChannelPixOffset;
178cdf0e10cSrcweir 				maChannel1Rect.Right()	= maThumbRect.Left()-1;
179cdf0e10cSrcweir 				maChannel1Rect.Top()	= mnChannelPixTop;
180cdf0e10cSrcweir 				maChannel1Rect.Bottom() = mnChannelPixBottom;
181cdf0e10cSrcweir 			}
182cdf0e10cSrcweir 			else
183cdf0e10cSrcweir 				maChannel1Rect.SetEmpty();
184cdf0e10cSrcweir 			if ( mnChannelPixOffset+mnChannelPixRange-1 > maThumbRect.Right() )
185cdf0e10cSrcweir 			{
186cdf0e10cSrcweir 				maChannel2Rect.Left()	= maThumbRect.Right()+1;
187cdf0e10cSrcweir 				maChannel2Rect.Right()	= mnChannelPixOffset+mnChannelPixRange-1;
188cdf0e10cSrcweir 				maChannel2Rect.Top()	= mnChannelPixTop;
189cdf0e10cSrcweir 				maChannel2Rect.Bottom() = mnChannelPixBottom;
190cdf0e10cSrcweir 			}
191cdf0e10cSrcweir 			else
192cdf0e10cSrcweir 				maChannel2Rect.SetEmpty();
193cdf0e10cSrcweir 
194cdf0e10cSrcweir 			const Rectangle aControlRegion( Rectangle( Point(0,0), Size( SLIDER_THUMB_SIZE, 10 ) ) );
195cdf0e10cSrcweir 			Rectangle aThumbBounds, aThumbContent;
196cdf0e10cSrcweir             if ( GetNativeControlRegion( CTRL_SLIDER, PART_THUMB_HORZ,
197cdf0e10cSrcweir                                          aControlRegion, 0, ImplControlValue(), rtl::OUString(),
198cdf0e10cSrcweir                                          aThumbBounds, aThumbContent ) )
199cdf0e10cSrcweir             {
200cdf0e10cSrcweir                 maThumbRect.Left() = mnThumbPixPos - aThumbBounds.GetWidth()/2;
201cdf0e10cSrcweir                 maThumbRect.Right() = maThumbRect.Left() + aThumbBounds.GetWidth() - 1;
202cdf0e10cSrcweir                 bInvalidateAll = true;
203cdf0e10cSrcweir             }
204cdf0e10cSrcweir 		}
205cdf0e10cSrcweir 		else
206cdf0e10cSrcweir 		{
207cdf0e10cSrcweir 			maThumbRect.Top()		= mnThumbPixPos-SLIDER_THUMB_HALFSIZE;
208cdf0e10cSrcweir 			maThumbRect.Bottom()	= maThumbRect.Top()+SLIDER_THUMB_SIZE-1;
209cdf0e10cSrcweir 			if ( mnChannelPixOffset < maThumbRect.Top() )
210cdf0e10cSrcweir 			{
211cdf0e10cSrcweir 				maChannel1Rect.Top()	= mnChannelPixOffset;
212cdf0e10cSrcweir 				maChannel1Rect.Bottom() = maThumbRect.Top()-1;
213cdf0e10cSrcweir 				maChannel1Rect.Left()	= mnChannelPixTop;
214cdf0e10cSrcweir 				maChannel1Rect.Right()	= mnChannelPixBottom;
215cdf0e10cSrcweir 			}
216cdf0e10cSrcweir 			else
217cdf0e10cSrcweir 				maChannel1Rect.SetEmpty();
218cdf0e10cSrcweir 			if ( mnChannelPixOffset+mnChannelPixRange-1 > maThumbRect.Bottom() )
219cdf0e10cSrcweir 			{
220cdf0e10cSrcweir 				maChannel2Rect.Top()	= maThumbRect.Bottom()+1;
221cdf0e10cSrcweir 				maChannel2Rect.Bottom() = mnChannelPixOffset+mnChannelPixRange-1;
222cdf0e10cSrcweir 				maChannel2Rect.Left()	= mnChannelPixTop;
223cdf0e10cSrcweir 				maChannel2Rect.Right()	= mnChannelPixBottom;
224cdf0e10cSrcweir 			}
225cdf0e10cSrcweir 			else
226cdf0e10cSrcweir 				maChannel2Rect.SetEmpty();
227cdf0e10cSrcweir 
228cdf0e10cSrcweir 			const Rectangle aControlRegion( Rectangle( Point(0,0), Size( 10, SLIDER_THUMB_SIZE ) ) );
229cdf0e10cSrcweir 			Rectangle aThumbBounds, aThumbContent;
230cdf0e10cSrcweir             if ( GetNativeControlRegion( CTRL_SLIDER, PART_THUMB_VERT,
231cdf0e10cSrcweir                                          aControlRegion, 0, ImplControlValue(), rtl::OUString(),
232cdf0e10cSrcweir                                          aThumbBounds, aThumbContent ) )
233cdf0e10cSrcweir             {
234cdf0e10cSrcweir                 maThumbRect.Top() = mnThumbPixPos - aThumbBounds.GetHeight()/2;
235cdf0e10cSrcweir                 maThumbRect.Bottom() = maThumbRect.Top() + aThumbBounds.GetHeight() - 1;
236cdf0e10cSrcweir                 bInvalidateAll = true;
237cdf0e10cSrcweir             }
238cdf0e10cSrcweir 		}
239cdf0e10cSrcweir 	}
240cdf0e10cSrcweir 	else
241cdf0e10cSrcweir 	{
242cdf0e10cSrcweir 		maChannel1Rect.SetEmpty();
243cdf0e10cSrcweir 		maChannel2Rect.SetEmpty();
244cdf0e10cSrcweir 		maThumbRect.SetEmpty();
245cdf0e10cSrcweir 	}
246cdf0e10cSrcweir 
247cdf0e10cSrcweir 	if ( bUpdate )
248cdf0e10cSrcweir 	{
249cdf0e10cSrcweir 		if ( aOldThumbRect != maThumbRect )
250cdf0e10cSrcweir 		{
251cdf0e10cSrcweir 		    if( bInvalidateAll )
252cdf0e10cSrcweir 		        Invalidate();
253cdf0e10cSrcweir 		    else
254cdf0e10cSrcweir 		    {
255cdf0e10cSrcweir                 Region aInvalidRegion( aOldThumbRect );
256cdf0e10cSrcweir                 aInvalidRegion.Union( maThumbRect );
257cdf0e10cSrcweir 
258cdf0e10cSrcweir                 if( !IsBackground() && GetParent() )
259cdf0e10cSrcweir                 {
260cdf0e10cSrcweir                     const Point aPos( GetPosPixel() );
261cdf0e10cSrcweir                     aInvalidRegion.Move( aPos.X(), aPos.Y() );
262cdf0e10cSrcweir                     GetParent()->Invalidate( aInvalidRegion, INVALIDATE_TRANSPARENT | INVALIDATE_UPDATE );
263cdf0e10cSrcweir                 }
264cdf0e10cSrcweir                 else
265cdf0e10cSrcweir                     Invalidate( aInvalidRegion );
266cdf0e10cSrcweir             }
267cdf0e10cSrcweir 		}
268cdf0e10cSrcweir 	}
269cdf0e10cSrcweir }
270cdf0e10cSrcweir 
271cdf0e10cSrcweir // -----------------------------------------------------------------------
272cdf0e10cSrcweir 
ImplCalcThumbPos(long nPixPos)273cdf0e10cSrcweir long Slider::ImplCalcThumbPos( long nPixPos )
274cdf0e10cSrcweir {
275cdf0e10cSrcweir 	// Position berechnen
276cdf0e10cSrcweir 	long nCalcThumbPos;
277cdf0e10cSrcweir 	nCalcThumbPos = ImplMulDiv( nPixPos-mnThumbPixOffset, mnMaxRange-mnMinRange, mnThumbPixRange-1 );
278cdf0e10cSrcweir 	nCalcThumbPos += mnMinRange;
279cdf0e10cSrcweir 	return nCalcThumbPos;
280cdf0e10cSrcweir }
281cdf0e10cSrcweir 
282cdf0e10cSrcweir // -----------------------------------------------------------------------
283cdf0e10cSrcweir 
ImplCalcThumbPosPix(long nPos)284cdf0e10cSrcweir long Slider::ImplCalcThumbPosPix( long nPos )
285cdf0e10cSrcweir {
286cdf0e10cSrcweir 	// Position berechnen
287cdf0e10cSrcweir 	long nCalcThumbPos;
288cdf0e10cSrcweir 	nCalcThumbPos = ImplMulDiv( nPos-mnMinRange, mnThumbPixRange-1, mnMaxRange-mnMinRange );
289cdf0e10cSrcweir 	// Am Anfang und Ende des Sliders versuchen wir die Anzeige korrekt
290cdf0e10cSrcweir 	// anzuzeigen
291cdf0e10cSrcweir 	if ( !nCalcThumbPos && (mnThumbPos > mnMinRange) )
292cdf0e10cSrcweir 		nCalcThumbPos = 1;
293cdf0e10cSrcweir 	if ( nCalcThumbPos &&
294cdf0e10cSrcweir 		 (nCalcThumbPos == mnThumbPixRange-1) &&
295cdf0e10cSrcweir 		 (mnThumbPos < mnMaxRange) )
296cdf0e10cSrcweir 		nCalcThumbPos--;
297cdf0e10cSrcweir 	return nCalcThumbPos+mnThumbPixOffset;
298cdf0e10cSrcweir }
299cdf0e10cSrcweir 
300cdf0e10cSrcweir // -----------------------------------------------------------------------
301cdf0e10cSrcweir 
ImplCalc(sal_Bool bUpdate)302cdf0e10cSrcweir void Slider::ImplCalc( sal_Bool bUpdate )
303cdf0e10cSrcweir {
304cdf0e10cSrcweir 	sal_Bool bInvalidateAll = sal_False;
305cdf0e10cSrcweir 
306cdf0e10cSrcweir 	if ( mbCalcSize )
307cdf0e10cSrcweir 	{
308cdf0e10cSrcweir 		long nOldChannelPixOffset	= mnChannelPixOffset;
309cdf0e10cSrcweir 		long nOldChannelPixRange	= mnChannelPixRange;
310cdf0e10cSrcweir 		long nOldChannelPixTop		= mnChannelPixTop;
311cdf0e10cSrcweir 		long nOldChannelPixBottom	= mnChannelPixBottom;
312cdf0e10cSrcweir 		long nCalcWidth;
313cdf0e10cSrcweir 		long nCalcHeight;
314cdf0e10cSrcweir 
315cdf0e10cSrcweir 		maChannel1Rect.SetEmpty();
316cdf0e10cSrcweir 		maChannel2Rect.SetEmpty();
317cdf0e10cSrcweir 		maThumbRect.SetEmpty();
318cdf0e10cSrcweir 
319cdf0e10cSrcweir 		Size aSize = GetOutputSizePixel();
320cdf0e10cSrcweir 		if ( GetStyle() & WB_HORZ )
321cdf0e10cSrcweir 		{
322cdf0e10cSrcweir 			nCalcWidth			= aSize.Width();
323cdf0e10cSrcweir 			nCalcHeight 		= aSize.Height();
324cdf0e10cSrcweir 			maThumbRect.Top()	= 0;
325cdf0e10cSrcweir 			maThumbRect.Bottom()= aSize.Height()-1;
326cdf0e10cSrcweir 		}
327cdf0e10cSrcweir 		else
328cdf0e10cSrcweir 		{
329cdf0e10cSrcweir 			nCalcWidth			= aSize.Height();
330cdf0e10cSrcweir 			nCalcHeight 		= aSize.Width();
331cdf0e10cSrcweir 			maThumbRect.Left()	= 0;
332cdf0e10cSrcweir 			maThumbRect.Right() = aSize.Width()-1;
333cdf0e10cSrcweir 		}
334cdf0e10cSrcweir 
335cdf0e10cSrcweir 		if ( nCalcWidth >= SLIDER_THUMB_SIZE )
336cdf0e10cSrcweir 		{
337cdf0e10cSrcweir 			mnThumbPixOffset	= SLIDER_THUMB_HALFSIZE;
338cdf0e10cSrcweir 			mnThumbPixRange 	= nCalcWidth-(SLIDER_THUMB_HALFSIZE*2);
339cdf0e10cSrcweir 			mnThumbPixPos		= 0;
340cdf0e10cSrcweir 			mnChannelPixOffset	= SLIDER_CHANNEL_OFFSET;
341cdf0e10cSrcweir 			mnChannelPixRange	= nCalcWidth-(SLIDER_CHANNEL_OFFSET*2);
342cdf0e10cSrcweir 			mnChannelPixTop 	= (nCalcHeight/2)-SLIDER_CHANNEL_HALFSIZE;
343cdf0e10cSrcweir 			mnChannelPixBottom	= mnChannelPixTop+SLIDER_CHANNEL_SIZE-1;
344cdf0e10cSrcweir 		}
345cdf0e10cSrcweir 		else
346cdf0e10cSrcweir 		{
347cdf0e10cSrcweir 			mnThumbPixRange = 0;
348cdf0e10cSrcweir 			mnChannelPixRange = 0;
349cdf0e10cSrcweir 		}
350cdf0e10cSrcweir 
351cdf0e10cSrcweir 		if ( (nOldChannelPixOffset != mnChannelPixOffset) ||
352cdf0e10cSrcweir 			 (nOldChannelPixRange != mnChannelPixRange) ||
353cdf0e10cSrcweir 			 (nOldChannelPixTop != mnChannelPixTop) ||
354cdf0e10cSrcweir 			 (nOldChannelPixBottom != mnChannelPixBottom) )
355cdf0e10cSrcweir 			bInvalidateAll = sal_True;
356cdf0e10cSrcweir 
357cdf0e10cSrcweir 		mbCalcSize = sal_False;
358cdf0e10cSrcweir 	}
359cdf0e10cSrcweir 
360cdf0e10cSrcweir 	if ( mnThumbPixRange )
361cdf0e10cSrcweir 		mnThumbPixPos = ImplCalcThumbPosPix( mnThumbPos );
362cdf0e10cSrcweir 
363cdf0e10cSrcweir 	if ( bUpdate && bInvalidateAll )
364cdf0e10cSrcweir 	{
365cdf0e10cSrcweir 		Invalidate();
366cdf0e10cSrcweir 		bUpdate = sal_False;
367cdf0e10cSrcweir 	}
368cdf0e10cSrcweir 	ImplUpdateRects( bUpdate );
369cdf0e10cSrcweir }
370cdf0e10cSrcweir 
371cdf0e10cSrcweir // -----------------------------------------------------------------------
372cdf0e10cSrcweir 
ImplDraw(sal_uInt16 nDrawFlags)373cdf0e10cSrcweir void Slider::ImplDraw( sal_uInt16 nDrawFlags )
374cdf0e10cSrcweir {
375cdf0e10cSrcweir 	DecorationView			aDecoView( this );
376cdf0e10cSrcweir 	sal_uInt16					nStyle;
377cdf0e10cSrcweir 	const StyleSettings&	rStyleSettings = GetSettings().GetStyleSettings();
378cdf0e10cSrcweir 	sal_Bool					bEnabled = IsEnabled();
379cdf0e10cSrcweir 
380cdf0e10cSrcweir 	// Evt. noch offene Berechnungen nachholen
381cdf0e10cSrcweir 	if ( mbCalcSize )
382cdf0e10cSrcweir 		ImplCalc( sal_False );
383cdf0e10cSrcweir 
384cdf0e10cSrcweir     ControlPart nPart = (GetStyle() & WB_HORZ) ? PART_TRACK_HORZ_AREA : PART_TRACK_VERT_AREA;
385cdf0e10cSrcweir     ControlState   nState = ( IsEnabled() ? CTRL_STATE_ENABLED : 0 ) | ( HasFocus() ? CTRL_STATE_FOCUSED : 0 );
386cdf0e10cSrcweir     SliderValue    sldValue;
387cdf0e10cSrcweir 
388cdf0e10cSrcweir     sldValue.mnMin       = mnMinRange;
389cdf0e10cSrcweir     sldValue.mnMax       = mnMaxRange;
390cdf0e10cSrcweir     sldValue.mnCur       = mnThumbPos;
391cdf0e10cSrcweir     sldValue.maThumbRect = maThumbRect;
392cdf0e10cSrcweir 
393cdf0e10cSrcweir     if( IsMouseOver() )
394cdf0e10cSrcweir     {
395cdf0e10cSrcweir         if( maThumbRect.IsInside( GetPointerPosPixel() ) )
396cdf0e10cSrcweir             sldValue.mnThumbState |= CTRL_STATE_ROLLOVER;
397cdf0e10cSrcweir     }
398cdf0e10cSrcweir 
399cdf0e10cSrcweir     const Rectangle aCtrlRegion( Point(0,0), GetOutputSizePixel() );
400cdf0e10cSrcweir     bool bNativeOK = DrawNativeControl( CTRL_SLIDER, nPart,
401cdf0e10cSrcweir                                         aCtrlRegion, nState, sldValue, rtl::OUString() );
402cdf0e10cSrcweir     if( bNativeOK )
403cdf0e10cSrcweir         return;
404cdf0e10cSrcweir 
405cdf0e10cSrcweir 	if ( (nDrawFlags & SLIDER_DRAW_CHANNEL1) && !maChannel1Rect.IsEmpty() )
406cdf0e10cSrcweir 	{
407cdf0e10cSrcweir 		long		nRectSize;
408cdf0e10cSrcweir 		Rectangle	aRect = maChannel1Rect;
409cdf0e10cSrcweir 		SetLineColor( rStyleSettings.GetShadowColor() );
410cdf0e10cSrcweir 		if ( GetStyle() & WB_HORZ )
411cdf0e10cSrcweir 		{
412cdf0e10cSrcweir 			DrawLine( aRect.TopLeft(), Point( aRect.Left(), aRect.Bottom()-1 ) );
413cdf0e10cSrcweir 			DrawLine( aRect.TopLeft(), aRect.TopRight() );
414cdf0e10cSrcweir 		}
415cdf0e10cSrcweir 		else
416cdf0e10cSrcweir 		{
417cdf0e10cSrcweir 			DrawLine( aRect.TopLeft(), Point( aRect.Right()-1, aRect.Top() ) );
418cdf0e10cSrcweir 			DrawLine( aRect.TopLeft(), aRect.BottomLeft() );
419cdf0e10cSrcweir 		}
420cdf0e10cSrcweir 		SetLineColor( rStyleSettings.GetLightColor() );
421cdf0e10cSrcweir 		if ( GetStyle() & WB_HORZ )
422cdf0e10cSrcweir 		{
423cdf0e10cSrcweir 			DrawLine( aRect.BottomLeft(), aRect.BottomRight() );
424cdf0e10cSrcweir 			nRectSize = aRect.GetWidth();
425cdf0e10cSrcweir 		}
426cdf0e10cSrcweir 		else
427cdf0e10cSrcweir 		{
428cdf0e10cSrcweir 			DrawLine( aRect.TopRight(), aRect.BottomRight() );
429cdf0e10cSrcweir 			nRectSize = aRect.GetHeight();
430cdf0e10cSrcweir 		}
431cdf0e10cSrcweir 
432cdf0e10cSrcweir 		if ( nRectSize > 1 )
433cdf0e10cSrcweir 		{
434cdf0e10cSrcweir 			aRect.Left()++;
435cdf0e10cSrcweir 			aRect.Top()++;
436cdf0e10cSrcweir 			if ( GetStyle() & WB_HORZ )
437cdf0e10cSrcweir 				aRect.Bottom()--;
438cdf0e10cSrcweir 			else
439cdf0e10cSrcweir 				aRect.Right()--;
440cdf0e10cSrcweir 			SetLineColor();
441cdf0e10cSrcweir 			if ( mnStateFlags & SLIDER_STATE_CHANNEL1_DOWN )
442cdf0e10cSrcweir 				SetFillColor( rStyleSettings.GetShadowColor() );
443cdf0e10cSrcweir 			else
444cdf0e10cSrcweir 				SetFillColor( rStyleSettings.GetCheckedColor() );
445cdf0e10cSrcweir 			DrawRect( aRect );
446cdf0e10cSrcweir 		}
447cdf0e10cSrcweir 	}
448cdf0e10cSrcweir 
449cdf0e10cSrcweir 	if ( (nDrawFlags & SLIDER_DRAW_CHANNEL2) && !maChannel2Rect.IsEmpty() )
450cdf0e10cSrcweir 	{
451cdf0e10cSrcweir 		long		nRectSize;
452cdf0e10cSrcweir 		Rectangle	aRect = maChannel2Rect;
453cdf0e10cSrcweir 		SetLineColor( rStyleSettings.GetLightColor() );
454cdf0e10cSrcweir 		if ( GetStyle() & WB_HORZ )
455cdf0e10cSrcweir 		{
456cdf0e10cSrcweir 			DrawLine( aRect.TopRight(), aRect.BottomRight() );
457cdf0e10cSrcweir 			DrawLine( aRect.BottomLeft(), aRect.BottomRight() );
458cdf0e10cSrcweir 			nRectSize = aRect.GetWidth();
459cdf0e10cSrcweir 		}
460cdf0e10cSrcweir 		else
461cdf0e10cSrcweir 		{
462cdf0e10cSrcweir 			DrawLine( aRect.BottomLeft(), aRect.BottomRight() );
463cdf0e10cSrcweir 			DrawLine( aRect.TopRight(), aRect.BottomRight() );
464cdf0e10cSrcweir 			nRectSize = aRect.GetHeight();
465cdf0e10cSrcweir 		}
466cdf0e10cSrcweir 
467cdf0e10cSrcweir 		if ( nRectSize > 1 )
468cdf0e10cSrcweir 		{
469cdf0e10cSrcweir 			SetLineColor( rStyleSettings.GetShadowColor() );
470cdf0e10cSrcweir 			if ( GetStyle() & WB_HORZ )
471cdf0e10cSrcweir 				DrawLine( aRect.TopLeft(), Point( aRect.Right()-1, aRect.Top() ) );
472cdf0e10cSrcweir 			else
473cdf0e10cSrcweir 				DrawLine( aRect.TopLeft(), Point( aRect.Left(), aRect.Bottom()-1 ) );
474cdf0e10cSrcweir 
475cdf0e10cSrcweir 			aRect.Right()--;
476cdf0e10cSrcweir 			aRect.Bottom()--;
477cdf0e10cSrcweir 			if ( GetStyle() & WB_HORZ )
478cdf0e10cSrcweir 				aRect.Top()++;
479cdf0e10cSrcweir 			else
480cdf0e10cSrcweir 				aRect.Left()++;
481cdf0e10cSrcweir 			SetLineColor();
482cdf0e10cSrcweir 			if ( mnStateFlags & SLIDER_STATE_CHANNEL2_DOWN )
483cdf0e10cSrcweir 				SetFillColor( rStyleSettings.GetShadowColor() );
484cdf0e10cSrcweir 			else
485cdf0e10cSrcweir 				SetFillColor( rStyleSettings.GetCheckedColor() );
486cdf0e10cSrcweir 			DrawRect( aRect );
487cdf0e10cSrcweir 		}
488cdf0e10cSrcweir 	}
489cdf0e10cSrcweir 
490cdf0e10cSrcweir 	if ( nDrawFlags & SLIDER_DRAW_THUMB )
491cdf0e10cSrcweir 	{
492cdf0e10cSrcweir 		if ( !maThumbRect.IsEmpty() )
493cdf0e10cSrcweir 		{
494cdf0e10cSrcweir 			if ( bEnabled )
495cdf0e10cSrcweir 			{
496cdf0e10cSrcweir 				nStyle = 0;
497cdf0e10cSrcweir 				if ( mnStateFlags & SLIDER_STATE_THUMB_DOWN )
498cdf0e10cSrcweir 					nStyle |= BUTTON_DRAW_PRESSED;
499cdf0e10cSrcweir 				aDecoView.DrawButton( maThumbRect, nStyle );
500cdf0e10cSrcweir 			}
501cdf0e10cSrcweir 			else
502cdf0e10cSrcweir 			{
503cdf0e10cSrcweir 				SetLineColor( rStyleSettings.GetShadowColor() );
504cdf0e10cSrcweir 				SetFillColor( rStyleSettings.GetCheckedColor() );
505cdf0e10cSrcweir 				DrawRect( maThumbRect );
506cdf0e10cSrcweir 			}
507cdf0e10cSrcweir 		}
508cdf0e10cSrcweir 	}
509cdf0e10cSrcweir }
510cdf0e10cSrcweir 
511cdf0e10cSrcweir // -----------------------------------------------------------------------
512cdf0e10cSrcweir 
ImplIsPageUp(const Point & rPos)513cdf0e10cSrcweir sal_Bool Slider::ImplIsPageUp( const Point& rPos )
514cdf0e10cSrcweir {
515cdf0e10cSrcweir 	Size aSize = GetOutputSizePixel();
516cdf0e10cSrcweir 	Rectangle aRect = maChannel1Rect;
517cdf0e10cSrcweir 	if ( GetStyle() & WB_HORZ )
518cdf0e10cSrcweir 	{
519cdf0e10cSrcweir 		aRect.Top() 	= 0;
520cdf0e10cSrcweir 		aRect.Bottom()	= aSize.Height()-1;
521cdf0e10cSrcweir 	}
522cdf0e10cSrcweir 	else
523cdf0e10cSrcweir 	{
524cdf0e10cSrcweir 		aRect.Left()	= 0;
525cdf0e10cSrcweir 		aRect.Right()	= aSize.Width()-1;
526cdf0e10cSrcweir 	}
527cdf0e10cSrcweir 	return aRect.IsInside( rPos );
528cdf0e10cSrcweir }
529cdf0e10cSrcweir 
530cdf0e10cSrcweir // -----------------------------------------------------------------------
531cdf0e10cSrcweir 
ImplIsPageDown(const Point & rPos)532cdf0e10cSrcweir sal_Bool Slider::ImplIsPageDown( const Point& rPos )
533cdf0e10cSrcweir {
534cdf0e10cSrcweir 	Size aSize = GetOutputSizePixel();
535cdf0e10cSrcweir 	Rectangle aRect = maChannel2Rect;
536cdf0e10cSrcweir 	if ( GetStyle() & WB_HORZ )
537cdf0e10cSrcweir 	{
538cdf0e10cSrcweir 		aRect.Top() 	= 0;
539cdf0e10cSrcweir 		aRect.Bottom()	= aSize.Height()-1;
540cdf0e10cSrcweir 	}
541cdf0e10cSrcweir 	else
542cdf0e10cSrcweir 	{
543cdf0e10cSrcweir 		aRect.Left()	= 0;
544cdf0e10cSrcweir 		aRect.Right()	= aSize.Width()-1;
545cdf0e10cSrcweir 	}
546cdf0e10cSrcweir 	return aRect.IsInside( rPos );
547cdf0e10cSrcweir }
548cdf0e10cSrcweir 
549cdf0e10cSrcweir // -----------------------------------------------------------------------
550cdf0e10cSrcweir 
ImplSlide(long nNewPos,sal_Bool bCallEndSlide)551cdf0e10cSrcweir long Slider::ImplSlide( long nNewPos, sal_Bool bCallEndSlide )
552cdf0e10cSrcweir {
553cdf0e10cSrcweir 	long nOldPos = mnThumbPos;
554cdf0e10cSrcweir 	SetThumbPos( nNewPos );
555cdf0e10cSrcweir 	long nDelta = mnThumbPos-nOldPos;
556cdf0e10cSrcweir 	if ( nDelta )
557cdf0e10cSrcweir 	{
558cdf0e10cSrcweir 		mnDelta = nDelta;
559cdf0e10cSrcweir 		Slide();
560cdf0e10cSrcweir 		if ( bCallEndSlide )
561cdf0e10cSrcweir 			EndSlide();
562cdf0e10cSrcweir 		mnDelta = 0;
563cdf0e10cSrcweir 	}
564cdf0e10cSrcweir 	return nDelta;
565cdf0e10cSrcweir }
566cdf0e10cSrcweir 
567cdf0e10cSrcweir // -----------------------------------------------------------------------
568cdf0e10cSrcweir 
ImplDoAction(sal_Bool bCallEndSlide)569cdf0e10cSrcweir long Slider::ImplDoAction( sal_Bool bCallEndSlide )
570cdf0e10cSrcweir {
571cdf0e10cSrcweir 	long nDelta = 0;
572cdf0e10cSrcweir 
573cdf0e10cSrcweir 	switch ( meScrollType )
574cdf0e10cSrcweir 	{
575cdf0e10cSrcweir 		case SCROLL_LINEUP:
576cdf0e10cSrcweir 			nDelta = ImplSlide( mnThumbPos-mnLineSize, bCallEndSlide );
577cdf0e10cSrcweir 			break;
578cdf0e10cSrcweir 
579cdf0e10cSrcweir 		case SCROLL_LINEDOWN:
580cdf0e10cSrcweir 			nDelta = ImplSlide( mnThumbPos+mnLineSize, bCallEndSlide );
581cdf0e10cSrcweir 			break;
582cdf0e10cSrcweir 
583cdf0e10cSrcweir 		case SCROLL_PAGEUP:
584cdf0e10cSrcweir 			nDelta = ImplSlide( mnThumbPos-mnPageSize, bCallEndSlide );
585cdf0e10cSrcweir 			break;
586cdf0e10cSrcweir 
587cdf0e10cSrcweir 		case SCROLL_PAGEDOWN:
588cdf0e10cSrcweir 			nDelta = ImplSlide( mnThumbPos+mnPageSize, bCallEndSlide );
589cdf0e10cSrcweir 			break;
590cdf0e10cSrcweir 
591cdf0e10cSrcweir 		case SCROLL_SET:
592cdf0e10cSrcweir 		    nDelta = ImplSlide( ImplCalcThumbPos( GetPointerPosPixel().X() ), bCallEndSlide );
593cdf0e10cSrcweir 		    break;
594cdf0e10cSrcweir         default:
595cdf0e10cSrcweir             break;
596cdf0e10cSrcweir 	}
597cdf0e10cSrcweir 
598cdf0e10cSrcweir 	return nDelta;
599cdf0e10cSrcweir }
600cdf0e10cSrcweir 
601cdf0e10cSrcweir // -----------------------------------------------------------------------
602cdf0e10cSrcweir 
ImplDoMouseAction(const Point & rMousePos,sal_Bool bCallAction)603cdf0e10cSrcweir void Slider::ImplDoMouseAction( const Point& rMousePos, sal_Bool bCallAction )
604cdf0e10cSrcweir {
605cdf0e10cSrcweir 	sal_uInt16	nOldStateFlags = mnStateFlags;
606cdf0e10cSrcweir 	sal_Bool	bAction = sal_False;
607cdf0e10cSrcweir 
608cdf0e10cSrcweir 	switch ( meScrollType )
609cdf0e10cSrcweir 	{
610cdf0e10cSrcweir     	case( SCROLL_SET ):
611cdf0e10cSrcweir     	{
612cdf0e10cSrcweir     	    const bool bUp = ImplIsPageUp( rMousePos ), bDown = ImplIsPageDown( rMousePos );
613cdf0e10cSrcweir 
614cdf0e10cSrcweir 			if ( bUp || bDown )
615cdf0e10cSrcweir 			{
616cdf0e10cSrcweir 				bAction = bCallAction;
617cdf0e10cSrcweir 				mnStateFlags |= ( bUp ? SLIDER_STATE_CHANNEL1_DOWN : SLIDER_STATE_CHANNEL2_DOWN );
618cdf0e10cSrcweir 			}
619cdf0e10cSrcweir 			else
620cdf0e10cSrcweir 				mnStateFlags &= ~( SLIDER_STATE_CHANNEL1_DOWN | SLIDER_STATE_CHANNEL2_DOWN );
621cdf0e10cSrcweir 			break;
622cdf0e10cSrcweir     	}
623cdf0e10cSrcweir 
624cdf0e10cSrcweir 		case SCROLL_PAGEUP:
625cdf0e10cSrcweir 			if ( ImplIsPageUp( rMousePos ) )
626cdf0e10cSrcweir 			{
627cdf0e10cSrcweir 				bAction = bCallAction;
628cdf0e10cSrcweir 				mnStateFlags |= SLIDER_STATE_CHANNEL1_DOWN;
629cdf0e10cSrcweir 			}
630cdf0e10cSrcweir 			else
631cdf0e10cSrcweir 				mnStateFlags &= ~SLIDER_STATE_CHANNEL1_DOWN;
632cdf0e10cSrcweir 			break;
633cdf0e10cSrcweir 
634cdf0e10cSrcweir 		case SCROLL_PAGEDOWN:
635cdf0e10cSrcweir 			if ( ImplIsPageDown( rMousePos ) )
636cdf0e10cSrcweir 			{
637cdf0e10cSrcweir 				bAction = bCallAction;
638cdf0e10cSrcweir 				mnStateFlags |= SLIDER_STATE_CHANNEL2_DOWN;
639cdf0e10cSrcweir 			}
640cdf0e10cSrcweir 			else
641cdf0e10cSrcweir 				mnStateFlags &= ~SLIDER_STATE_CHANNEL2_DOWN;
642cdf0e10cSrcweir 			break;
643cdf0e10cSrcweir         default:
644cdf0e10cSrcweir             break;
645cdf0e10cSrcweir 	}
646cdf0e10cSrcweir 
647cdf0e10cSrcweir 	if ( bAction )
648cdf0e10cSrcweir 	{
649cdf0e10cSrcweir 		if ( ImplDoAction( sal_False ) )
650cdf0e10cSrcweir 		{
651cdf0e10cSrcweir 			// Update the channel complete
652cdf0e10cSrcweir 			if ( mnDragDraw & SLIDER_DRAW_CHANNEL )
653cdf0e10cSrcweir 			{
654cdf0e10cSrcweir 				Update();
655cdf0e10cSrcweir 				ImplDraw( mnDragDraw );
656cdf0e10cSrcweir 			}
657cdf0e10cSrcweir 		}
658cdf0e10cSrcweir 	}
659cdf0e10cSrcweir 	else if ( nOldStateFlags != mnStateFlags )
660cdf0e10cSrcweir 		ImplDraw( mnDragDraw );
661cdf0e10cSrcweir }
662cdf0e10cSrcweir 
663cdf0e10cSrcweir // -----------------------------------------------------------------------
664cdf0e10cSrcweir 
ImplDoSlide(long nNewPos)665cdf0e10cSrcweir long Slider::ImplDoSlide( long nNewPos )
666cdf0e10cSrcweir {
667cdf0e10cSrcweir 	if ( meScrollType != SCROLL_DONTKNOW )
668cdf0e10cSrcweir 		return 0;
669cdf0e10cSrcweir 
670cdf0e10cSrcweir 	meScrollType = SCROLL_DRAG;
671cdf0e10cSrcweir 	long nDelta = ImplSlide( nNewPos, sal_True );
672cdf0e10cSrcweir 	meScrollType = SCROLL_DONTKNOW;
673cdf0e10cSrcweir 	return nDelta;
674cdf0e10cSrcweir }
675cdf0e10cSrcweir 
676cdf0e10cSrcweir // -----------------------------------------------------------------------
677cdf0e10cSrcweir 
ImplDoSlideAction(ScrollType eScrollType)678cdf0e10cSrcweir long Slider::ImplDoSlideAction( ScrollType eScrollType )
679cdf0e10cSrcweir {
680cdf0e10cSrcweir 	if ( (meScrollType != SCROLL_DONTKNOW) ||
681cdf0e10cSrcweir 		 (eScrollType == SCROLL_DONTKNOW) ||
682cdf0e10cSrcweir 		 (eScrollType == SCROLL_DRAG) )
683cdf0e10cSrcweir 		return 0;
684cdf0e10cSrcweir 
685cdf0e10cSrcweir 	meScrollType = eScrollType;
686cdf0e10cSrcweir 	long nDelta = ImplDoAction( sal_True );
687cdf0e10cSrcweir 	meScrollType = SCROLL_DONTKNOW;
688cdf0e10cSrcweir 	return nDelta;
689cdf0e10cSrcweir }
690cdf0e10cSrcweir 
691cdf0e10cSrcweir // -----------------------------------------------------------------------
692cdf0e10cSrcweir 
MouseButtonDown(const MouseEvent & rMEvt)693cdf0e10cSrcweir void Slider::MouseButtonDown( const MouseEvent& rMEvt )
694cdf0e10cSrcweir {
695cdf0e10cSrcweir 	if ( rMEvt.IsLeft() )
696cdf0e10cSrcweir 	{
697cdf0e10cSrcweir 		const Point&	rMousePos = rMEvt.GetPosPixel();
698cdf0e10cSrcweir 		sal_uInt16			nTrackFlags = 0;
699cdf0e10cSrcweir 
700cdf0e10cSrcweir 		if ( maThumbRect.IsInside( rMousePos ) )
701cdf0e10cSrcweir 		{
702cdf0e10cSrcweir 			nTrackFlags 	= 0;
703cdf0e10cSrcweir 			meScrollType	= SCROLL_DRAG;
704cdf0e10cSrcweir 			mnDragDraw		= SLIDER_DRAW_THUMB;
705cdf0e10cSrcweir 
706cdf0e10cSrcweir 			// Zusaetzliche Daten berechnen
707cdf0e10cSrcweir 			Point aCenterPos = maThumbRect.Center();
708cdf0e10cSrcweir 			if ( GetStyle() & WB_HORZ )
709cdf0e10cSrcweir 				mnMouseOff = rMousePos.X()-aCenterPos.X();
710cdf0e10cSrcweir 			else
711cdf0e10cSrcweir 				mnMouseOff = rMousePos.Y()-aCenterPos.Y();
712cdf0e10cSrcweir 		}
713cdf0e10cSrcweir 		else if ( ImplIsPageUp( rMousePos ) )
714cdf0e10cSrcweir 		{
715cdf0e10cSrcweir 		    if( GetStyle() & WB_SLIDERSET )
716cdf0e10cSrcweir 		        meScrollType = SCROLL_SET;
717cdf0e10cSrcweir 		    else
718cdf0e10cSrcweir 		    {
719cdf0e10cSrcweir 			    nTrackFlags = STARTTRACK_BUTTONREPEAT;
720cdf0e10cSrcweir 			    meScrollType = SCROLL_PAGEUP;
721cdf0e10cSrcweir 			}
722cdf0e10cSrcweir 
723cdf0e10cSrcweir 			mnDragDraw = SLIDER_DRAW_CHANNEL;
724cdf0e10cSrcweir 		}
725cdf0e10cSrcweir 		else if ( ImplIsPageDown( rMousePos ) )
726cdf0e10cSrcweir 		{
727cdf0e10cSrcweir 		    if( GetStyle() & WB_SLIDERSET )
728cdf0e10cSrcweir 		        meScrollType = SCROLL_SET;
729cdf0e10cSrcweir 		    else
730cdf0e10cSrcweir 		    {
731cdf0e10cSrcweir 			    nTrackFlags = STARTTRACK_BUTTONREPEAT;
732cdf0e10cSrcweir 			    meScrollType = SCROLL_PAGEDOWN;
733cdf0e10cSrcweir 			}
734cdf0e10cSrcweir 
735cdf0e10cSrcweir 			mnDragDraw = SLIDER_DRAW_CHANNEL;
736cdf0e10cSrcweir 		}
737cdf0e10cSrcweir 
738cdf0e10cSrcweir 		// Soll Tracking gestartet werden
739cdf0e10cSrcweir 		if( meScrollType != SCROLL_DONTKNOW )
740cdf0e10cSrcweir 		{
741cdf0e10cSrcweir 			// Startposition merken fuer Abbruch und EndScroll-Delta
742cdf0e10cSrcweir 			mnStartPos = mnThumbPos;
743cdf0e10cSrcweir 			ImplDoMouseAction( rMousePos, meScrollType != SCROLL_SET );
744cdf0e10cSrcweir 			Update();
745cdf0e10cSrcweir 
746cdf0e10cSrcweir 			if( meScrollType != SCROLL_SET )
747cdf0e10cSrcweir 		        StartTracking( nTrackFlags );
748cdf0e10cSrcweir 		}
749cdf0e10cSrcweir 	}
750cdf0e10cSrcweir }
751cdf0e10cSrcweir 
752cdf0e10cSrcweir // -----------------------------------------------------------------------
753cdf0e10cSrcweir 
MouseButtonUp(const MouseEvent &)754cdf0e10cSrcweir void Slider::MouseButtonUp( const MouseEvent& )
755cdf0e10cSrcweir {
756cdf0e10cSrcweir     if( SCROLL_SET == meScrollType )
757cdf0e10cSrcweir     {
758cdf0e10cSrcweir 		// Button und PageRect-Status wieder herstellen
759cdf0e10cSrcweir 		const sal_uInt16 nOldStateFlags = mnStateFlags;
760cdf0e10cSrcweir 
761cdf0e10cSrcweir 		mnStateFlags &= ~( SLIDER_STATE_CHANNEL1_DOWN | SLIDER_STATE_CHANNEL2_DOWN | SLIDER_STATE_THUMB_DOWN );
762cdf0e10cSrcweir 
763cdf0e10cSrcweir 		if ( nOldStateFlags != mnStateFlags )
764cdf0e10cSrcweir 			ImplDraw( mnDragDraw );
765cdf0e10cSrcweir 
766cdf0e10cSrcweir 		mnDragDraw = 0;
767cdf0e10cSrcweir     	ImplDoAction( sal_True );
768cdf0e10cSrcweir     	meScrollType = SCROLL_DONTKNOW;
769cdf0e10cSrcweir     }
770cdf0e10cSrcweir }
771cdf0e10cSrcweir 
772cdf0e10cSrcweir // -----------------------------------------------------------------------
773cdf0e10cSrcweir 
Tracking(const TrackingEvent & rTEvt)774cdf0e10cSrcweir void Slider::Tracking( const TrackingEvent& rTEvt )
775cdf0e10cSrcweir {
776cdf0e10cSrcweir 	if ( rTEvt.IsTrackingEnded() )
777cdf0e10cSrcweir 	{
778cdf0e10cSrcweir 		// Button und PageRect-Status wieder herstellen
779cdf0e10cSrcweir 		sal_uInt16 nOldStateFlags = mnStateFlags;
780cdf0e10cSrcweir 		mnStateFlags &= ~(SLIDER_STATE_CHANNEL1_DOWN | SLIDER_STATE_CHANNEL2_DOWN |
781cdf0e10cSrcweir 						  SLIDER_STATE_THUMB_DOWN);
782cdf0e10cSrcweir 		if ( nOldStateFlags != mnStateFlags )
783cdf0e10cSrcweir 			ImplDraw( mnDragDraw );
784cdf0e10cSrcweir 		mnDragDraw = 0;
785cdf0e10cSrcweir 
786cdf0e10cSrcweir 		// Bei Abbruch, die alte ThumbPosition wieder herstellen
787cdf0e10cSrcweir 		if ( rTEvt.IsTrackingCanceled() )
788cdf0e10cSrcweir 		{
789cdf0e10cSrcweir 			long nOldPos = mnThumbPos;
790cdf0e10cSrcweir 			SetThumbPos( mnStartPos );
791cdf0e10cSrcweir 			mnDelta = mnThumbPos-nOldPos;
792cdf0e10cSrcweir 			Slide();
793cdf0e10cSrcweir 		}
794cdf0e10cSrcweir 
795cdf0e10cSrcweir 		if ( meScrollType == SCROLL_DRAG )
796cdf0e10cSrcweir 		{
797cdf0e10cSrcweir 			// Wenn gedragt wurde, berechnen wir den Thumb neu, damit
798cdf0e10cSrcweir 			// er wieder auf einer gerundeten ThumbPosition steht
799cdf0e10cSrcweir 			ImplCalc();
800cdf0e10cSrcweir 			Update();
801cdf0e10cSrcweir 
802cdf0e10cSrcweir 			if ( !mbFullDrag && (mnStartPos != mnThumbPos) )
803cdf0e10cSrcweir 			{
804cdf0e10cSrcweir 				mnDelta = mnThumbPos-mnStartPos;
805cdf0e10cSrcweir 				Slide();
806cdf0e10cSrcweir 				mnDelta = 0;
807cdf0e10cSrcweir 			}
808cdf0e10cSrcweir 		}
809cdf0e10cSrcweir 
810cdf0e10cSrcweir 		mnDelta = mnThumbPos-mnStartPos;
811cdf0e10cSrcweir 		EndSlide();
812cdf0e10cSrcweir 		mnDelta = 0;
813cdf0e10cSrcweir 		meScrollType = SCROLL_DONTKNOW;
814cdf0e10cSrcweir 	}
815cdf0e10cSrcweir 	else
816cdf0e10cSrcweir 	{
817cdf0e10cSrcweir 		const Point rMousePos = rTEvt.GetMouseEvent().GetPosPixel();
818cdf0e10cSrcweir 
819cdf0e10cSrcweir 		// Dragging wird speziell behandelt
820cdf0e10cSrcweir 		if ( meScrollType == SCROLL_DRAG )
821cdf0e10cSrcweir 		{
822cdf0e10cSrcweir 			long nMovePix;
823cdf0e10cSrcweir 			Point aCenterPos = maThumbRect.Center();
824cdf0e10cSrcweir 			if ( GetStyle() & WB_HORZ )
825cdf0e10cSrcweir 				nMovePix = rMousePos.X()-(aCenterPos.X()+mnMouseOff);
826cdf0e10cSrcweir 			else
827cdf0e10cSrcweir 				nMovePix = rMousePos.Y()-(aCenterPos.Y()+mnMouseOff);
828cdf0e10cSrcweir 			// Nur wenn sich Maus in die Scrollrichtung bewegt, muessen
829cdf0e10cSrcweir 			// wir etwas tun
830cdf0e10cSrcweir 			if ( nMovePix )
831cdf0e10cSrcweir 			{
832cdf0e10cSrcweir 				mnThumbPixPos += nMovePix;
833cdf0e10cSrcweir 				if ( mnThumbPixPos < mnThumbPixOffset )
834cdf0e10cSrcweir 					mnThumbPixPos = mnThumbPixOffset;
835cdf0e10cSrcweir 				if ( mnThumbPixPos > (mnThumbPixOffset+mnThumbPixRange-1) )
836cdf0e10cSrcweir 					mnThumbPixPos = mnThumbPixOffset+mnThumbPixRange-1;
837cdf0e10cSrcweir 				long nOldPos = mnThumbPos;
838cdf0e10cSrcweir 				mnThumbPos = ImplCalcThumbPos( mnThumbPixPos );
839cdf0e10cSrcweir 				if ( nOldPos != mnThumbPos )
840cdf0e10cSrcweir 				{
841cdf0e10cSrcweir 					ImplUpdateRects();
842cdf0e10cSrcweir 					Update();
843cdf0e10cSrcweir 					if ( mbFullDrag && (nOldPos != mnThumbPos) )
844cdf0e10cSrcweir 					{
845cdf0e10cSrcweir 						mnDelta = mnThumbPos-nOldPos;
846cdf0e10cSrcweir 						Slide();
847cdf0e10cSrcweir 						mnDelta = 0;
848cdf0e10cSrcweir 					}
849cdf0e10cSrcweir 				}
850cdf0e10cSrcweir 			}
851cdf0e10cSrcweir 		}
852cdf0e10cSrcweir 		else
853cdf0e10cSrcweir 			ImplDoMouseAction( rMousePos, rTEvt.IsTrackingRepeat() );
854cdf0e10cSrcweir 
855cdf0e10cSrcweir 		// Wenn Slider-Werte so umgesetzt wurden, das es nichts
856cdf0e10cSrcweir 		// mehr zum Tracking gibt, dann berechen wir hier ab
857cdf0e10cSrcweir 		if ( !IsVisible() )
858cdf0e10cSrcweir 			EndTracking();
859cdf0e10cSrcweir 	}
860cdf0e10cSrcweir }
861cdf0e10cSrcweir 
862cdf0e10cSrcweir // -----------------------------------------------------------------------
863cdf0e10cSrcweir 
KeyInput(const KeyEvent & rKEvt)864cdf0e10cSrcweir void Slider::KeyInput( const KeyEvent& rKEvt )
865cdf0e10cSrcweir {
866cdf0e10cSrcweir 	if ( !rKEvt.GetKeyCode().GetModifier() )
867cdf0e10cSrcweir 	{
868cdf0e10cSrcweir 		switch ( rKEvt.GetKeyCode().GetCode() )
869cdf0e10cSrcweir 		{
870cdf0e10cSrcweir 			case KEY_HOME:
871cdf0e10cSrcweir 				ImplDoSlide( GetRangeMin() );
872cdf0e10cSrcweir 				break;
873cdf0e10cSrcweir 			case KEY_END:
874cdf0e10cSrcweir 				ImplDoSlide( GetRangeMax() );
875cdf0e10cSrcweir 				break;
876cdf0e10cSrcweir 
877cdf0e10cSrcweir 			case KEY_LEFT:
878cdf0e10cSrcweir 			case KEY_UP:
879cdf0e10cSrcweir 				ImplDoSlideAction( SCROLL_LINEUP );
880cdf0e10cSrcweir 				break;
881cdf0e10cSrcweir 
882cdf0e10cSrcweir 			case KEY_RIGHT:
883cdf0e10cSrcweir 			case KEY_DOWN:
884cdf0e10cSrcweir 				ImplDoSlideAction( SCROLL_LINEDOWN );
885cdf0e10cSrcweir 				break;
886cdf0e10cSrcweir 
887cdf0e10cSrcweir 			case KEY_PAGEUP:
888cdf0e10cSrcweir 				ImplDoSlideAction( SCROLL_PAGEUP );
889cdf0e10cSrcweir 				break;
890cdf0e10cSrcweir 
891cdf0e10cSrcweir 			case KEY_PAGEDOWN:
892cdf0e10cSrcweir 				ImplDoSlideAction( SCROLL_PAGEDOWN );
893cdf0e10cSrcweir 				break;
894cdf0e10cSrcweir 
895cdf0e10cSrcweir 			default:
896cdf0e10cSrcweir 				Control::KeyInput( rKEvt );
897cdf0e10cSrcweir 				break;
898cdf0e10cSrcweir 		}
899cdf0e10cSrcweir 	}
900cdf0e10cSrcweir 	else
901cdf0e10cSrcweir 		Control::KeyInput( rKEvt );
902cdf0e10cSrcweir }
903cdf0e10cSrcweir 
904cdf0e10cSrcweir // -----------------------------------------------------------------------
905cdf0e10cSrcweir 
Paint(const Rectangle &)906cdf0e10cSrcweir void Slider::Paint( const Rectangle& )
907cdf0e10cSrcweir {
908cdf0e10cSrcweir 	ImplDraw( SLIDER_DRAW_ALL );
909cdf0e10cSrcweir }
910cdf0e10cSrcweir 
911cdf0e10cSrcweir // -----------------------------------------------------------------------
912cdf0e10cSrcweir 
Resize()913cdf0e10cSrcweir void Slider::Resize()
914cdf0e10cSrcweir {
915cdf0e10cSrcweir     Control::Resize();
916cdf0e10cSrcweir 	mbCalcSize = sal_True;
917cdf0e10cSrcweir 	if ( IsReallyVisible() )
918cdf0e10cSrcweir 		ImplCalc( sal_False );
919cdf0e10cSrcweir 	Invalidate();
920cdf0e10cSrcweir }
921cdf0e10cSrcweir 
922cdf0e10cSrcweir // -----------------------------------------------------------------------
923cdf0e10cSrcweir 
RequestHelp(const HelpEvent & rHEvt)924cdf0e10cSrcweir void Slider::RequestHelp( const HelpEvent& rHEvt )
925cdf0e10cSrcweir {
926cdf0e10cSrcweir 	Control::RequestHelp( rHEvt );
927cdf0e10cSrcweir }
928cdf0e10cSrcweir 
929cdf0e10cSrcweir // -----------------------------------------------------------------------
930cdf0e10cSrcweir 
StateChanged(StateChangedType nType)931cdf0e10cSrcweir void Slider::StateChanged( StateChangedType nType )
932cdf0e10cSrcweir {
933cdf0e10cSrcweir 	Control::StateChanged( nType );
934cdf0e10cSrcweir 
935cdf0e10cSrcweir 	if ( nType == STATE_CHANGE_INITSHOW )
936cdf0e10cSrcweir 		ImplCalc( sal_False );
937cdf0e10cSrcweir 	else if ( nType == STATE_CHANGE_DATA )
938cdf0e10cSrcweir 	{
939cdf0e10cSrcweir 		if ( IsReallyVisible() && IsUpdateMode() )
940cdf0e10cSrcweir 			ImplCalc( sal_True );
941cdf0e10cSrcweir 	}
942cdf0e10cSrcweir 	else if ( nType == STATE_CHANGE_UPDATEMODE )
943cdf0e10cSrcweir 	{
944cdf0e10cSrcweir 		if ( IsReallyVisible() && IsUpdateMode() )
945cdf0e10cSrcweir 		{
946cdf0e10cSrcweir 			ImplCalc( sal_False );
947cdf0e10cSrcweir 			Invalidate();
948cdf0e10cSrcweir 		}
949cdf0e10cSrcweir 	}
950cdf0e10cSrcweir 	else if ( nType == STATE_CHANGE_ENABLE )
951cdf0e10cSrcweir 	{
952cdf0e10cSrcweir 		if ( IsReallyVisible() && IsUpdateMode() )
953cdf0e10cSrcweir 			Invalidate();
954cdf0e10cSrcweir 	}
955cdf0e10cSrcweir 	else if ( nType == STATE_CHANGE_STYLE )
956cdf0e10cSrcweir 	{
957cdf0e10cSrcweir 		if ( IsReallyVisible() && IsUpdateMode() )
958cdf0e10cSrcweir 		{
959cdf0e10cSrcweir 			if ( (GetPrevStyle() & SLIDER_VIEW_STYLE) !=
960cdf0e10cSrcweir 				 (GetStyle() & SLIDER_VIEW_STYLE) )
961cdf0e10cSrcweir 			{
962cdf0e10cSrcweir 				mbCalcSize = sal_True;
963cdf0e10cSrcweir 				ImplCalc( sal_False );
964cdf0e10cSrcweir 				Invalidate();
965cdf0e10cSrcweir 			}
966cdf0e10cSrcweir 		}
967cdf0e10cSrcweir 	}
968cdf0e10cSrcweir 	else if ( nType == STATE_CHANGE_CONTROLBACKGROUND )
969cdf0e10cSrcweir 	{
970cdf0e10cSrcweir 		ImplInitSettings();
971cdf0e10cSrcweir 		Invalidate();
972cdf0e10cSrcweir 	}
973cdf0e10cSrcweir }
974cdf0e10cSrcweir 
975cdf0e10cSrcweir // -----------------------------------------------------------------------
976cdf0e10cSrcweir 
DataChanged(const DataChangedEvent & rDCEvt)977cdf0e10cSrcweir void Slider::DataChanged( const DataChangedEvent& rDCEvt )
978cdf0e10cSrcweir {
979cdf0e10cSrcweir 	Control::DataChanged( rDCEvt );
980cdf0e10cSrcweir 
981cdf0e10cSrcweir 	if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
982cdf0e10cSrcweir 		 (rDCEvt.GetFlags() & SETTINGS_STYLE) )
983cdf0e10cSrcweir 	{
984cdf0e10cSrcweir 		ImplInitSettings();
985cdf0e10cSrcweir 		Invalidate();
986cdf0e10cSrcweir 	}
987cdf0e10cSrcweir }
988cdf0e10cSrcweir 
989cdf0e10cSrcweir // -----------------------------------------------------------------------
990cdf0e10cSrcweir 
Slide()991cdf0e10cSrcweir void Slider::Slide()
992cdf0e10cSrcweir {
993cdf0e10cSrcweir 	maSlideHdl.Call( this );
994cdf0e10cSrcweir }
995cdf0e10cSrcweir 
996cdf0e10cSrcweir // -----------------------------------------------------------------------
997cdf0e10cSrcweir 
EndSlide()998cdf0e10cSrcweir void Slider::EndSlide()
999cdf0e10cSrcweir {
1000cdf0e10cSrcweir 	maEndSlideHdl.Call( this );
1001cdf0e10cSrcweir }
1002cdf0e10cSrcweir 
1003cdf0e10cSrcweir // -----------------------------------------------------------------------
1004cdf0e10cSrcweir 
SetRangeMin(long nNewRange)1005cdf0e10cSrcweir void Slider::SetRangeMin( long nNewRange )
1006cdf0e10cSrcweir {
1007cdf0e10cSrcweir 	SetRange( Range( nNewRange, GetRangeMax() ) );
1008cdf0e10cSrcweir }
1009cdf0e10cSrcweir 
1010cdf0e10cSrcweir // -----------------------------------------------------------------------
1011cdf0e10cSrcweir 
SetRangeMax(long nNewRange)1012cdf0e10cSrcweir void Slider::SetRangeMax( long nNewRange )
1013cdf0e10cSrcweir {
1014cdf0e10cSrcweir 	SetRange( Range( GetRangeMin(), nNewRange ) );
1015cdf0e10cSrcweir }
1016cdf0e10cSrcweir 
1017cdf0e10cSrcweir // -----------------------------------------------------------------------
1018cdf0e10cSrcweir 
SetRange(const Range & rRange)1019cdf0e10cSrcweir void Slider::SetRange( const Range& rRange )
1020cdf0e10cSrcweir {
1021cdf0e10cSrcweir 	// Range einpassen
1022cdf0e10cSrcweir 	Range aRange = rRange;
1023cdf0e10cSrcweir 	aRange.Justify();
1024cdf0e10cSrcweir 	long nNewMinRange = aRange.Min();
1025cdf0e10cSrcweir 	long nNewMaxRange = aRange.Max();
1026cdf0e10cSrcweir 
1027cdf0e10cSrcweir 	// Wenn Range sich unterscheidet, dann neuen setzen
1028cdf0e10cSrcweir 	if ( (mnMinRange != nNewMinRange) ||
1029cdf0e10cSrcweir 		 (mnMaxRange != nNewMaxRange) )
1030cdf0e10cSrcweir 	{
1031cdf0e10cSrcweir 		mnMinRange = nNewMinRange;
1032cdf0e10cSrcweir 		mnMaxRange = nNewMaxRange;
1033cdf0e10cSrcweir 
1034cdf0e10cSrcweir 		// Thumb einpassen
1035cdf0e10cSrcweir 		if ( mnThumbPos > mnMaxRange )
1036cdf0e10cSrcweir 			mnThumbPos = mnMaxRange;
1037cdf0e10cSrcweir 		if ( mnThumbPos < mnMinRange )
1038cdf0e10cSrcweir 			mnThumbPos = mnMinRange;
1039cdf0e10cSrcweir 
1040cdf0e10cSrcweir 		StateChanged( STATE_CHANGE_DATA );
1041cdf0e10cSrcweir 	}
1042cdf0e10cSrcweir }
1043cdf0e10cSrcweir 
1044cdf0e10cSrcweir // -----------------------------------------------------------------------
1045cdf0e10cSrcweir 
SetThumbPos(long nNewThumbPos)1046cdf0e10cSrcweir void Slider::SetThumbPos( long nNewThumbPos )
1047cdf0e10cSrcweir {
1048cdf0e10cSrcweir 	if ( nNewThumbPos < mnMinRange )
1049cdf0e10cSrcweir 		nNewThumbPos = mnMinRange;
1050cdf0e10cSrcweir 	if ( nNewThumbPos > mnMaxRange )
1051cdf0e10cSrcweir 		nNewThumbPos = mnMaxRange;
1052cdf0e10cSrcweir 
1053cdf0e10cSrcweir 	if ( mnThumbPos != nNewThumbPos )
1054cdf0e10cSrcweir 	{
1055cdf0e10cSrcweir 		mnThumbPos = nNewThumbPos;
1056cdf0e10cSrcweir 		StateChanged( STATE_CHANGE_DATA );
1057cdf0e10cSrcweir 	}
1058cdf0e10cSrcweir }
1059cdf0e10cSrcweir 
1060cdf0e10cSrcweir // -----------------------------------------------------------------------
1061cdf0e10cSrcweir 
CalcWindowSizePixel()1062cdf0e10cSrcweir Size Slider::CalcWindowSizePixel()
1063cdf0e10cSrcweir {
1064cdf0e10cSrcweir 	long nWidth = mnMaxRange-mnMinRange+(SLIDER_THUMB_HALFSIZE*2)+1;
1065cdf0e10cSrcweir 	long nHeight = SLIDER_HEIGHT;
1066cdf0e10cSrcweir 	Size aSize;
1067cdf0e10cSrcweir 	if ( GetStyle() & WB_HORZ )
1068cdf0e10cSrcweir 	{
1069cdf0e10cSrcweir 		aSize.Width()	= nWidth;
1070cdf0e10cSrcweir 		aSize.Height()	= nHeight;
1071cdf0e10cSrcweir 	}
1072cdf0e10cSrcweir 	else
1073cdf0e10cSrcweir 	{
1074cdf0e10cSrcweir 		aSize.Height()	= nWidth;
1075cdf0e10cSrcweir 		aSize.Width()	= nHeight;
1076cdf0e10cSrcweir 	}
1077cdf0e10cSrcweir 	return aSize;
1078cdf0e10cSrcweir }
1079