1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: slider.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_vcl.hxx"
37 #include <vcl/event.hxx>
38 #include <vcl/decoview.hxx>
39 #include <vcl/slider.hxx>
43 // =======================================================================
45 static long ImplMulDiv( long nNumber
, long nNumerator
, long nDenominator
)
47 double n
= ((double)nNumber
* (double)nNumerator
) / (double)nDenominator
;
51 // =======================================================================
53 #define SLIDER_DRAW_THUMB ((USHORT)0x0001)
54 #define SLIDER_DRAW_CHANNEL1 ((USHORT)0x0002)
55 #define SLIDER_DRAW_CHANNEL2 ((USHORT)0x0004)
56 #define SLIDER_DRAW_CHANNEL (SLIDER_DRAW_CHANNEL1 | SLIDER_DRAW_CHANNEL2)
57 #define SLIDER_DRAW_ALL (SLIDER_DRAW_THUMB | SLIDER_DRAW_CHANNEL)
59 #define SLIDER_STATE_CHANNEL1_DOWN ((USHORT)0x0001)
60 #define SLIDER_STATE_CHANNEL2_DOWN ((USHORT)0x0002)
61 #define SLIDER_STATE_THUMB_DOWN ((USHORT)0x0004)
63 #define SLIDER_THUMB_SIZE 9
64 #define SLIDER_THUMB_HALFSIZE 4
65 #define SLIDER_CHANNEL_OFFSET 0
66 #define SLIDER_CHANNEL_SIZE 4
67 #define SLIDER_CHANNEL_HALFSIZE 2
69 #define SLIDER_HEIGHT 16
71 #define SLIDER_VIEW_STYLE (WB_3DLOOK | WB_HORZ | WB_VERT)
73 // =======================================================================
75 void Slider::ImplInit( Window
* pParent
, WinBits nStyle
)
79 mnThumbPixPos
= 0; // between mnThumbPixOffset and mnThumbPixOffset+mnThumbPixRange
80 mnChannelPixOffset
= 0;
81 mnChannelPixRange
= 0;
83 mnChannelPixBottom
= 0;
93 meScrollType
= SCROLL_DONTKNOW
;
97 Control::ImplInit( pParent
, nStyle
, NULL
);
100 SetSizePixel( CalcWindowSizePixel() );
103 // -----------------------------------------------------------------------
105 Slider::Slider( Window
* pParent
, WinBits nStyle
) :
106 Control( WINDOW_SLIDER
)
108 ImplInit( pParent
, nStyle
);
111 // -----------------------------------------------------------------------
113 Slider::Slider( Window
* pParent
, const ResId
& rResId
) :
114 Control( WINDOW_SLIDER
)
116 rResId
.SetRT( RSC_SCROLLBAR
);
117 WinBits nStyle
= ImplInitRes( rResId
);
118 ImplInit( pParent
, nStyle
);
119 ImplLoadRes( rResId
);
121 if ( !(nStyle
& WB_HIDE
) )
125 // -----------------------------------------------------------------------
127 void Slider::ImplLoadRes( const ResId
& rResId
)
129 Control::ImplLoadRes( rResId
);
131 INT16 nMin
= ReadShortRes();
132 INT16 nMax
= ReadShortRes();
133 INT16 nThumbPos
= ReadShortRes();
134 INT16 nPage
= ReadShortRes();
135 INT16 nStep
= ReadShortRes();
136 /* INT16 nVisibleSize = */ ReadShortRes();
138 SetRange( Range( nMin
, nMax
) );
139 SetLineSize( nStep
);
140 SetPageSize( nPage
);
141 SetThumbPos( nThumbPos
);
144 // -----------------------------------------------------------------------
146 void Slider::ImplInitSettings()
148 Window
* pParent
= GetParent();
149 if ( pParent
->IsChildTransparentModeEnabled() && !IsControlBackground() )
151 EnableChildTransparentMode( TRUE
);
152 SetParentClipMode( PARENTCLIPMODE_NOCLIP
);
153 SetPaintTransparent( TRUE
);
158 EnableChildTransparentMode( FALSE
);
159 SetParentClipMode( 0 );
160 SetPaintTransparent( FALSE
);
162 if ( IsControlBackground() )
163 SetBackground( GetControlBackground() );
165 SetBackground( pParent
->GetBackground() );
169 // -----------------------------------------------------------------------
171 void Slider::ImplUpdateRects( BOOL bUpdate
)
173 Rectangle aOldThumbRect
= maThumbRect
;
175 if ( mnThumbPixRange
)
177 if ( GetStyle() & WB_HORZ
)
179 maThumbRect
.Left() = mnThumbPixPos
-SLIDER_THUMB_HALFSIZE
;
180 maThumbRect
.Right() = maThumbRect
.Left()+SLIDER_THUMB_SIZE
-1;
181 if ( mnChannelPixOffset
< maThumbRect
.Left() )
183 maChannel1Rect
.Left() = mnChannelPixOffset
;
184 maChannel1Rect
.Right() = maThumbRect
.Left()-1;
185 maChannel1Rect
.Top() = mnChannelPixTop
;
186 maChannel1Rect
.Bottom() = mnChannelPixBottom
;
189 maChannel1Rect
.SetEmpty();
190 if ( mnChannelPixOffset
+mnChannelPixRange
-1 > maThumbRect
.Right() )
192 maChannel2Rect
.Left() = maThumbRect
.Right()+1;
193 maChannel2Rect
.Right() = mnChannelPixOffset
+mnChannelPixRange
-1;
194 maChannel2Rect
.Top() = mnChannelPixTop
;
195 maChannel2Rect
.Bottom() = mnChannelPixBottom
;
198 maChannel2Rect
.SetEmpty();
202 maThumbRect
.Top() = mnThumbPixPos
-SLIDER_THUMB_HALFSIZE
;
203 maThumbRect
.Bottom() = maThumbRect
.Top()+SLIDER_THUMB_SIZE
-1;
204 if ( mnChannelPixOffset
< maThumbRect
.Top() )
206 maChannel1Rect
.Top() = mnChannelPixOffset
;
207 maChannel1Rect
.Bottom() = maThumbRect
.Top()-1;
208 maChannel1Rect
.Left() = mnChannelPixTop
;
209 maChannel1Rect
.Right() = mnChannelPixBottom
;
212 maChannel1Rect
.SetEmpty();
213 if ( mnChannelPixOffset
+mnChannelPixRange
-1 > maThumbRect
.Bottom() )
215 maChannel2Rect
.Top() = maThumbRect
.Bottom()+1;
216 maChannel2Rect
.Bottom() = mnChannelPixOffset
+mnChannelPixRange
-1;
217 maChannel2Rect
.Left() = mnChannelPixTop
;
218 maChannel2Rect
.Right() = mnChannelPixBottom
;
221 maChannel2Rect
.SetEmpty();
226 maChannel1Rect
.SetEmpty();
227 maChannel2Rect
.SetEmpty();
228 maThumbRect
.SetEmpty();
233 if ( aOldThumbRect
!= maThumbRect
)
235 Region
aInvalidRegion( aOldThumbRect
);
236 aInvalidRegion
.Union( maThumbRect
);
238 if( !IsBackground() && GetParent() )
240 const Point
aPos( GetPosPixel() );
241 aInvalidRegion
.Move( aPos
.X(), aPos
.Y() );
242 GetParent()->Invalidate( aInvalidRegion
, INVALIDATE_TRANSPARENT
| INVALIDATE_UPDATE
);
245 Invalidate( aInvalidRegion
);
250 // -----------------------------------------------------------------------
252 long Slider::ImplCalcThumbPos( long nPixPos
)
254 // Position berechnen
256 nCalcThumbPos
= ImplMulDiv( nPixPos
-mnThumbPixOffset
, mnMaxRange
-mnMinRange
, mnThumbPixRange
-1 );
257 nCalcThumbPos
+= mnMinRange
;
258 return nCalcThumbPos
;
261 // -----------------------------------------------------------------------
263 long Slider::ImplCalcThumbPosPix( long nPos
)
265 // Position berechnen
267 nCalcThumbPos
= ImplMulDiv( nPos
-mnMinRange
, mnThumbPixRange
-1, mnMaxRange
-mnMinRange
);
268 // Am Anfang und Ende des Sliders versuchen wir die Anzeige korrekt
270 if ( !nCalcThumbPos
&& (mnThumbPos
> mnMinRange
) )
272 if ( nCalcThumbPos
&&
273 (nCalcThumbPos
== mnThumbPixRange
-1) &&
274 (mnThumbPos
< mnMaxRange
) )
276 return nCalcThumbPos
+mnThumbPixOffset
;
279 // -----------------------------------------------------------------------
281 void Slider::ImplCalc( BOOL bUpdate
)
283 BOOL bInvalidateAll
= FALSE
;
287 long nOldChannelPixOffset
= mnChannelPixOffset
;
288 long nOldChannelPixRange
= mnChannelPixRange
;
289 long nOldChannelPixTop
= mnChannelPixTop
;
290 long nOldChannelPixBottom
= mnChannelPixBottom
;
294 maChannel1Rect
.SetEmpty();
295 maChannel2Rect
.SetEmpty();
296 maThumbRect
.SetEmpty();
298 Size aSize
= GetOutputSizePixel();
299 if ( GetStyle() & WB_HORZ
)
301 nCalcWidth
= aSize
.Width();
302 nCalcHeight
= aSize
.Height();
303 maThumbRect
.Top() = 0;
304 maThumbRect
.Bottom()= aSize
.Height()-1;
308 nCalcWidth
= aSize
.Height();
309 nCalcHeight
= aSize
.Width();
310 maThumbRect
.Left() = 0;
311 maThumbRect
.Right() = aSize
.Width()-1;
314 if ( nCalcWidth
>= SLIDER_THUMB_SIZE
)
316 mnThumbPixOffset
= SLIDER_THUMB_HALFSIZE
;
317 mnThumbPixRange
= nCalcWidth
-(SLIDER_THUMB_HALFSIZE
*2);
319 mnChannelPixOffset
= SLIDER_CHANNEL_OFFSET
;
320 mnChannelPixRange
= nCalcWidth
-(SLIDER_CHANNEL_OFFSET
*2);
321 mnChannelPixTop
= (nCalcHeight
/2)-SLIDER_CHANNEL_HALFSIZE
;
322 mnChannelPixBottom
= mnChannelPixTop
+SLIDER_CHANNEL_SIZE
-1;
327 mnChannelPixRange
= 0;
330 if ( (nOldChannelPixOffset
!= mnChannelPixOffset
) ||
331 (nOldChannelPixRange
!= mnChannelPixRange
) ||
332 (nOldChannelPixTop
!= mnChannelPixTop
) ||
333 (nOldChannelPixBottom
!= mnChannelPixBottom
) )
334 bInvalidateAll
= TRUE
;
339 if ( mnThumbPixRange
)
340 mnThumbPixPos
= ImplCalcThumbPosPix( mnThumbPos
);
342 if ( bUpdate
&& bInvalidateAll
)
347 ImplUpdateRects( bUpdate
);
350 // -----------------------------------------------------------------------
352 void Slider::ImplDraw( USHORT nDrawFlags
)
354 DecorationView
aDecoView( this );
356 const StyleSettings
& rStyleSettings
= GetSettings().GetStyleSettings();
357 BOOL bEnabled
= IsEnabled();
359 // Evt. noch offene Berechnungen nachholen
363 if ( (nDrawFlags
& SLIDER_DRAW_CHANNEL1
) && !maChannel1Rect
.IsEmpty() )
366 Rectangle aRect
= maChannel1Rect
;
367 SetLineColor( rStyleSettings
.GetShadowColor() );
368 if ( GetStyle() & WB_HORZ
)
370 DrawLine( aRect
.TopLeft(), Point( aRect
.Left(), aRect
.Bottom()-1 ) );
371 DrawLine( aRect
.TopLeft(), aRect
.TopRight() );
375 DrawLine( aRect
.TopLeft(), Point( aRect
.Right()-1, aRect
.Top() ) );
376 DrawLine( aRect
.TopLeft(), aRect
.BottomLeft() );
378 SetLineColor( rStyleSettings
.GetLightColor() );
379 if ( GetStyle() & WB_HORZ
)
381 DrawLine( aRect
.BottomLeft(), aRect
.BottomRight() );
382 nRectSize
= aRect
.GetWidth();
386 DrawLine( aRect
.TopRight(), aRect
.BottomRight() );
387 nRectSize
= aRect
.GetHeight();
394 if ( GetStyle() & WB_HORZ
)
399 if ( mnStateFlags
& SLIDER_STATE_CHANNEL1_DOWN
)
400 SetFillColor( rStyleSettings
.GetShadowColor() );
402 SetFillColor( rStyleSettings
.GetCheckedColor() );
407 if ( (nDrawFlags
& SLIDER_DRAW_CHANNEL2
) && !maChannel2Rect
.IsEmpty() )
410 Rectangle aRect
= maChannel2Rect
;
411 SetLineColor( rStyleSettings
.GetLightColor() );
412 if ( GetStyle() & WB_HORZ
)
414 DrawLine( aRect
.TopRight(), aRect
.BottomRight() );
415 DrawLine( aRect
.BottomLeft(), aRect
.BottomRight() );
416 nRectSize
= aRect
.GetWidth();
420 DrawLine( aRect
.BottomLeft(), aRect
.BottomRight() );
421 DrawLine( aRect
.TopRight(), aRect
.BottomRight() );
422 nRectSize
= aRect
.GetHeight();
427 SetLineColor( rStyleSettings
.GetShadowColor() );
428 if ( GetStyle() & WB_HORZ
)
429 DrawLine( aRect
.TopLeft(), Point( aRect
.Right()-1, aRect
.Top() ) );
431 DrawLine( aRect
.TopLeft(), Point( aRect
.Left(), aRect
.Bottom()-1 ) );
435 if ( GetStyle() & WB_HORZ
)
440 if ( mnStateFlags
& SLIDER_STATE_CHANNEL2_DOWN
)
441 SetFillColor( rStyleSettings
.GetShadowColor() );
443 SetFillColor( rStyleSettings
.GetCheckedColor() );
448 if ( nDrawFlags
& SLIDER_DRAW_THUMB
)
450 if ( !maThumbRect
.IsEmpty() )
455 if ( mnStateFlags
& SLIDER_STATE_THUMB_DOWN
)
456 nStyle
|= BUTTON_DRAW_PRESSED
;
457 aDecoView
.DrawButton( maThumbRect
, nStyle
);
461 SetLineColor( rStyleSettings
.GetShadowColor() );
462 SetFillColor( rStyleSettings
.GetCheckedColor() );
463 DrawRect( maThumbRect
);
469 // -----------------------------------------------------------------------
471 BOOL
Slider::ImplIsPageUp( const Point
& rPos
)
473 Size aSize
= GetOutputSizePixel();
474 Rectangle aRect
= maChannel1Rect
;
475 if ( GetStyle() & WB_HORZ
)
478 aRect
.Bottom() = aSize
.Height()-1;
483 aRect
.Right() = aSize
.Width()-1;
485 return aRect
.IsInside( rPos
);
488 // -----------------------------------------------------------------------
490 BOOL
Slider::ImplIsPageDown( const Point
& rPos
)
492 Size aSize
= GetOutputSizePixel();
493 Rectangle aRect
= maChannel2Rect
;
494 if ( GetStyle() & WB_HORZ
)
497 aRect
.Bottom() = aSize
.Height()-1;
502 aRect
.Right() = aSize
.Width()-1;
504 return aRect
.IsInside( rPos
);
507 // -----------------------------------------------------------------------
509 long Slider::ImplSlide( long nNewPos
, BOOL bCallEndSlide
)
511 long nOldPos
= mnThumbPos
;
512 SetThumbPos( nNewPos
);
513 long nDelta
= mnThumbPos
-nOldPos
;
525 // -----------------------------------------------------------------------
527 long Slider::ImplDoAction( BOOL bCallEndSlide
)
531 switch ( meScrollType
)
534 nDelta
= ImplSlide( mnThumbPos
-mnLineSize
, bCallEndSlide
);
537 case SCROLL_LINEDOWN
:
538 nDelta
= ImplSlide( mnThumbPos
+mnLineSize
, bCallEndSlide
);
542 nDelta
= ImplSlide( mnThumbPos
-mnPageSize
, bCallEndSlide
);
545 case SCROLL_PAGEDOWN
:
546 nDelta
= ImplSlide( mnThumbPos
+mnPageSize
, bCallEndSlide
);
550 nDelta
= ImplSlide( ImplCalcThumbPos( GetPointerPosPixel().X() ), bCallEndSlide
);
559 // -----------------------------------------------------------------------
561 void Slider::ImplDoMouseAction( const Point
& rMousePos
, BOOL bCallAction
)
563 USHORT nOldStateFlags
= mnStateFlags
;
564 BOOL bAction
= FALSE
;
566 switch ( meScrollType
)
570 const bool bUp
= ImplIsPageUp( rMousePos
), bDown
= ImplIsPageDown( rMousePos
);
574 bAction
= bCallAction
;
575 mnStateFlags
|= ( bUp
? SLIDER_STATE_CHANNEL1_DOWN
: SLIDER_STATE_CHANNEL2_DOWN
);
578 mnStateFlags
&= ~( SLIDER_STATE_CHANNEL1_DOWN
| SLIDER_STATE_CHANNEL2_DOWN
);
583 if ( ImplIsPageUp( rMousePos
) )
585 bAction
= bCallAction
;
586 mnStateFlags
|= SLIDER_STATE_CHANNEL1_DOWN
;
589 mnStateFlags
&= ~SLIDER_STATE_CHANNEL1_DOWN
;
592 case SCROLL_PAGEDOWN
:
593 if ( ImplIsPageDown( rMousePos
) )
595 bAction
= bCallAction
;
596 mnStateFlags
|= SLIDER_STATE_CHANNEL2_DOWN
;
599 mnStateFlags
&= ~SLIDER_STATE_CHANNEL2_DOWN
;
607 if ( ImplDoAction( FALSE
) )
609 // Update the channel complete
610 if ( mnDragDraw
& SLIDER_DRAW_CHANNEL
)
613 ImplDraw( mnDragDraw
);
617 else if ( nOldStateFlags
!= mnStateFlags
)
618 ImplDraw( mnDragDraw
);
621 // -----------------------------------------------------------------------
623 long Slider::ImplDoSlide( long nNewPos
)
625 if ( meScrollType
!= SCROLL_DONTKNOW
)
628 meScrollType
= SCROLL_DRAG
;
629 long nDelta
= ImplSlide( nNewPos
, TRUE
);
630 meScrollType
= SCROLL_DONTKNOW
;
634 // -----------------------------------------------------------------------
636 long Slider::ImplDoSlideAction( ScrollType eScrollType
)
638 if ( (meScrollType
!= SCROLL_DONTKNOW
) ||
639 (eScrollType
== SCROLL_DONTKNOW
) ||
640 (eScrollType
== SCROLL_DRAG
) )
643 meScrollType
= eScrollType
;
644 long nDelta
= ImplDoAction( TRUE
);
645 meScrollType
= SCROLL_DONTKNOW
;
649 // -----------------------------------------------------------------------
651 void Slider::MouseButtonDown( const MouseEvent
& rMEvt
)
653 if ( rMEvt
.IsLeft() )
655 const Point
& rMousePos
= rMEvt
.GetPosPixel();
656 USHORT nTrackFlags
= 0;
658 if ( maThumbRect
.IsInside( rMousePos
) )
661 meScrollType
= SCROLL_DRAG
;
662 mnDragDraw
= SLIDER_DRAW_THUMB
;
664 // Zusaetzliche Daten berechnen
665 Point aCenterPos
= maThumbRect
.Center();
666 if ( GetStyle() & WB_HORZ
)
667 mnMouseOff
= rMousePos
.X()-aCenterPos
.X();
669 mnMouseOff
= rMousePos
.Y()-aCenterPos
.Y();
671 // Im OS2-Look geben wir den Thumb gedrueckt aus
672 if ( GetSettings().GetStyleSettings().GetOptions() & STYLE_OPTION_OS2STYLE
)
674 mnStateFlags
|= SLIDER_STATE_THUMB_DOWN
;
675 ImplDraw( SLIDER_DRAW_THUMB
);
678 else if ( ImplIsPageUp( rMousePos
) )
680 if( GetStyle() & WB_SLIDERSET
)
681 meScrollType
= SCROLL_SET
;
684 nTrackFlags
= STARTTRACK_BUTTONREPEAT
;
685 meScrollType
= SCROLL_PAGEUP
;
688 mnDragDraw
= SLIDER_DRAW_CHANNEL
;
690 else if ( ImplIsPageDown( rMousePos
) )
692 if( GetStyle() & WB_SLIDERSET
)
693 meScrollType
= SCROLL_SET
;
696 nTrackFlags
= STARTTRACK_BUTTONREPEAT
;
697 meScrollType
= SCROLL_PAGEDOWN
;
700 mnDragDraw
= SLIDER_DRAW_CHANNEL
;
703 // Soll Tracking gestartet werden
704 if( meScrollType
!= SCROLL_DONTKNOW
)
706 // Startposition merken fuer Abbruch und EndScroll-Delta
707 mnStartPos
= mnThumbPos
;
708 ImplDoMouseAction( rMousePos
, meScrollType
!= SCROLL_SET
);
711 if( meScrollType
!= SCROLL_SET
)
712 StartTracking( nTrackFlags
);
717 // -----------------------------------------------------------------------
719 void Slider::MouseButtonUp( const MouseEvent
& )
721 if( SCROLL_SET
== meScrollType
)
723 // Button und PageRect-Status wieder herstellen
724 const USHORT nOldStateFlags
= mnStateFlags
;
726 mnStateFlags
&= ~( SLIDER_STATE_CHANNEL1_DOWN
| SLIDER_STATE_CHANNEL2_DOWN
| SLIDER_STATE_THUMB_DOWN
);
728 if ( nOldStateFlags
!= mnStateFlags
)
729 ImplDraw( mnDragDraw
);
732 ImplDoAction( TRUE
);
733 meScrollType
= SCROLL_DONTKNOW
;
737 // -----------------------------------------------------------------------
739 void Slider::Tracking( const TrackingEvent
& rTEvt
)
741 if ( rTEvt
.IsTrackingEnded() )
743 // Button und PageRect-Status wieder herstellen
744 USHORT nOldStateFlags
= mnStateFlags
;
745 mnStateFlags
&= ~(SLIDER_STATE_CHANNEL1_DOWN
| SLIDER_STATE_CHANNEL2_DOWN
|
746 SLIDER_STATE_THUMB_DOWN
);
747 if ( nOldStateFlags
!= mnStateFlags
)
748 ImplDraw( mnDragDraw
);
751 // Bei Abbruch, die alte ThumbPosition wieder herstellen
752 if ( rTEvt
.IsTrackingCanceled() )
754 long nOldPos
= mnThumbPos
;
755 SetThumbPos( mnStartPos
);
756 mnDelta
= mnThumbPos
-nOldPos
;
760 if ( meScrollType
== SCROLL_DRAG
)
762 // Wenn gedragt wurde, berechnen wir den Thumb neu, damit
763 // er wieder auf einer gerundeten ThumbPosition steht
767 if ( !mbFullDrag
&& (mnStartPos
!= mnThumbPos
) )
769 mnDelta
= mnThumbPos
-mnStartPos
;
775 mnDelta
= mnThumbPos
-mnStartPos
;
778 meScrollType
= SCROLL_DONTKNOW
;
782 const Point rMousePos
= rTEvt
.GetMouseEvent().GetPosPixel();
784 // Dragging wird speziell behandelt
785 if ( meScrollType
== SCROLL_DRAG
)
788 Point aCenterPos
= maThumbRect
.Center();
789 if ( GetStyle() & WB_HORZ
)
790 nMovePix
= rMousePos
.X()-(aCenterPos
.X()+mnMouseOff
);
792 nMovePix
= rMousePos
.Y()-(aCenterPos
.Y()+mnMouseOff
);
793 // Nur wenn sich Maus in die Scrollrichtung bewegt, muessen
797 mnThumbPixPos
+= nMovePix
;
798 if ( mnThumbPixPos
< mnThumbPixOffset
)
799 mnThumbPixPos
= mnThumbPixOffset
;
800 if ( mnThumbPixPos
> (mnThumbPixOffset
+mnThumbPixRange
-1) )
801 mnThumbPixPos
= mnThumbPixOffset
+mnThumbPixRange
-1;
802 long nOldPos
= mnThumbPos
;
803 mnThumbPos
= ImplCalcThumbPos( mnThumbPixPos
);
804 if ( nOldPos
!= mnThumbPos
)
808 if ( mbFullDrag
&& (nOldPos
!= mnThumbPos
) )
810 mnDelta
= mnThumbPos
-nOldPos
;
818 ImplDoMouseAction( rMousePos
, rTEvt
.IsTrackingRepeat() );
820 // Wenn Slider-Werte so umgesetzt wurden, das es nichts
821 // mehr zum Tracking gibt, dann berechen wir hier ab
827 // -----------------------------------------------------------------------
829 void Slider::KeyInput( const KeyEvent
& rKEvt
)
831 if ( !rKEvt
.GetKeyCode().GetModifier() )
833 switch ( rKEvt
.GetKeyCode().GetCode() )
836 ImplDoSlide( GetRangeMin() );
839 ImplDoSlide( GetRangeMax() );
844 ImplDoSlideAction( SCROLL_LINEUP
);
849 ImplDoSlideAction( SCROLL_LINEDOWN
);
853 ImplDoSlideAction( SCROLL_PAGEUP
);
857 ImplDoSlideAction( SCROLL_PAGEDOWN
);
861 Control::KeyInput( rKEvt
);
866 Control::KeyInput( rKEvt
);
869 // -----------------------------------------------------------------------
871 void Slider::Paint( const Rectangle
& )
873 ImplDraw( SLIDER_DRAW_ALL
);
876 // -----------------------------------------------------------------------
878 void Slider::Resize()
882 if ( IsReallyVisible() )
887 // -----------------------------------------------------------------------
889 void Slider::RequestHelp( const HelpEvent
& rHEvt
)
891 Control::RequestHelp( rHEvt
);
894 // -----------------------------------------------------------------------
896 void Slider::StateChanged( StateChangedType nType
)
898 Control::StateChanged( nType
);
900 if ( nType
== STATE_CHANGE_INITSHOW
)
902 else if ( nType
== STATE_CHANGE_DATA
)
904 if ( IsReallyVisible() && IsUpdateMode() )
907 else if ( nType
== STATE_CHANGE_UPDATEMODE
)
909 if ( IsReallyVisible() && IsUpdateMode() )
915 else if ( nType
== STATE_CHANGE_ENABLE
)
917 if ( IsReallyVisible() && IsUpdateMode() )
920 else if ( nType
== STATE_CHANGE_STYLE
)
922 if ( IsReallyVisible() && IsUpdateMode() )
924 if ( (GetPrevStyle() & SLIDER_VIEW_STYLE
) !=
925 (GetStyle() & SLIDER_VIEW_STYLE
) )
933 else if ( nType
== STATE_CHANGE_CONTROLBACKGROUND
)
940 // -----------------------------------------------------------------------
942 void Slider::DataChanged( const DataChangedEvent
& rDCEvt
)
944 Control::DataChanged( rDCEvt
);
946 if ( (rDCEvt
.GetType() == DATACHANGED_SETTINGS
) &&
947 (rDCEvt
.GetFlags() & SETTINGS_STYLE
) )
954 // -----------------------------------------------------------------------
958 maSlideHdl
.Call( this );
961 // -----------------------------------------------------------------------
963 void Slider::EndSlide()
965 maEndSlideHdl
.Call( this );
968 // -----------------------------------------------------------------------
970 void Slider::SetRangeMin( long nNewRange
)
972 SetRange( Range( nNewRange
, GetRangeMax() ) );
975 // -----------------------------------------------------------------------
977 void Slider::SetRangeMax( long nNewRange
)
979 SetRange( Range( GetRangeMin(), nNewRange
) );
982 // -----------------------------------------------------------------------
984 void Slider::SetRange( const Range
& rRange
)
987 Range aRange
= rRange
;
989 long nNewMinRange
= aRange
.Min();
990 long nNewMaxRange
= aRange
.Max();
992 // Wenn Range sich unterscheidet, dann neuen setzen
993 if ( (mnMinRange
!= nNewMinRange
) ||
994 (mnMaxRange
!= nNewMaxRange
) )
996 mnMinRange
= nNewMinRange
;
997 mnMaxRange
= nNewMaxRange
;
1000 if ( mnThumbPos
> mnMaxRange
)
1001 mnThumbPos
= mnMaxRange
;
1002 if ( mnThumbPos
< mnMinRange
)
1003 mnThumbPos
= mnMinRange
;
1005 StateChanged( STATE_CHANGE_DATA
);
1009 // -----------------------------------------------------------------------
1011 void Slider::SetThumbPos( long nNewThumbPos
)
1013 if ( nNewThumbPos
< mnMinRange
)
1014 nNewThumbPos
= mnMinRange
;
1015 if ( nNewThumbPos
> mnMaxRange
)
1016 nNewThumbPos
= mnMaxRange
;
1018 if ( mnThumbPos
!= nNewThumbPos
)
1020 mnThumbPos
= nNewThumbPos
;
1021 StateChanged( STATE_CHANGE_DATA
);
1025 // -----------------------------------------------------------------------
1027 Size
Slider::CalcWindowSizePixel()
1029 long nWidth
= mnMaxRange
-mnMinRange
+(SLIDER_THUMB_HALFSIZE
*2)+1;
1030 long nHeight
= SLIDER_HEIGHT
;
1032 if ( GetStyle() & WB_HORZ
)
1034 aSize
.Width() = nWidth
;
1035 aSize
.Height() = nHeight
;
1039 aSize
.Height() = nWidth
;
1040 aSize
.Width() = nHeight
;