xref: /aoo41x/main/vcl/source/control/scrbar.cxx (revision 13a3daf1)
19f62ea84SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
39f62ea84SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
49f62ea84SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
59f62ea84SAndrew Rist  * distributed with this work for additional information
69f62ea84SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
79f62ea84SAndrew Rist  * to you under the Apache License, Version 2.0 (the
89f62ea84SAndrew Rist  * "License"); you may not use this file except in compliance
99f62ea84SAndrew Rist  * with the License.  You may obtain a copy of the License at
109f62ea84SAndrew Rist  *
119f62ea84SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
129f62ea84SAndrew Rist  *
139f62ea84SAndrew Rist  * Unless required by applicable law or agreed to in writing,
149f62ea84SAndrew Rist  * software distributed under the License is distributed on an
159f62ea84SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
169f62ea84SAndrew Rist  * KIND, either express or implied.  See the License for the
179f62ea84SAndrew Rist  * specific language governing permissions and limitations
189f62ea84SAndrew Rist  * under the License.
199f62ea84SAndrew Rist  *
209f62ea84SAndrew Rist  *************************************************************/
219f62ea84SAndrew Rist 
229f62ea84SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_vcl.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "vcl/event.hxx"
28cdf0e10cSrcweir #include "vcl/sound.hxx"
29cdf0e10cSrcweir #include "vcl/decoview.hxx"
30cdf0e10cSrcweir #include "vcl/scrbar.hxx"
31cdf0e10cSrcweir #include "vcl/timer.hxx"
32cdf0e10cSrcweir 
33cdf0e10cSrcweir #include "svdata.hxx"
34cdf0e10cSrcweir 
35cdf0e10cSrcweir #include "rtl/string.hxx"
36cdf0e10cSrcweir #include "tools/rc.h"
37cdf0e10cSrcweir 
38cdf0e10cSrcweir 
39cdf0e10cSrcweir 
40cdf0e10cSrcweir using namespace rtl;
41cdf0e10cSrcweir 
42cdf0e10cSrcweir /*  #i77549#
43cdf0e10cSrcweir     HACK: for scrollbars in case of thumb rect, page up and page down rect we
44cdf0e10cSrcweir     abuse the HitTestNativeControl interface. All theming engines but aqua
45cdf0e10cSrcweir     are actually able to draw the thumb according to our internal representation.
46cdf0e10cSrcweir     However aqua draws a little outside. The canonical way would be to enhance the
47cdf0e10cSrcweir     HitTestNativeControl passing a ScrollbarValue additionally so all necessary
48cdf0e10cSrcweir     information is available in the call.
49cdf0e10cSrcweir     .
50cdf0e10cSrcweir     However since there is only this one small exception we will deviate a little and
51cdf0e10cSrcweir     instead pass the respective rect as control region to allow for a small correction.
52cdf0e10cSrcweir 
53cdf0e10cSrcweir     So all places using HitTestNativeControl on PART_THUMB_HORZ, PART_THUMB_VERT,
54cdf0e10cSrcweir     PART_TRACK_HORZ_LEFT, PART_TRACK_HORZ_RIGHT, PART_TRACK_VERT_UPPER, PART_TRACK_VERT_LOWER
55cdf0e10cSrcweir     do not use the control rectangle as region but the actuall part rectangle, making
56cdf0e10cSrcweir     only small deviations feasible.
57cdf0e10cSrcweir */
58cdf0e10cSrcweir 
59cdf0e10cSrcweir 
60cdf0e10cSrcweir // =======================================================================
61cdf0e10cSrcweir 
ImplMulDiv(long nNumber,long nNumerator,long nDenominator)62cdf0e10cSrcweir static long ImplMulDiv( long nNumber, long nNumerator, long nDenominator )
63cdf0e10cSrcweir {
64cdf0e10cSrcweir     double n = ((double)nNumber * (double)nNumerator) / (double)nDenominator;
65cdf0e10cSrcweir     return (long)n;
66cdf0e10cSrcweir }
67cdf0e10cSrcweir 
68cdf0e10cSrcweir // =======================================================================
69cdf0e10cSrcweir 
70cdf0e10cSrcweir #define SCRBAR_DRAW_BTN1            ((sal_uInt16)0x0001)
71cdf0e10cSrcweir #define SCRBAR_DRAW_BTN2            ((sal_uInt16)0x0002)
72cdf0e10cSrcweir #define SCRBAR_DRAW_PAGE1           ((sal_uInt16)0x0004)
73cdf0e10cSrcweir #define SCRBAR_DRAW_PAGE2           ((sal_uInt16)0x0008)
74cdf0e10cSrcweir #define SCRBAR_DRAW_THUMB           ((sal_uInt16)0x0010)
75cdf0e10cSrcweir #define SCRBAR_DRAW_BACKGROUND      ((sal_uInt16)0x0020)
76cdf0e10cSrcweir #define SCRBAR_DRAW_ALL             (SCRBAR_DRAW_BTN1 | SCRBAR_DRAW_BTN2 |  \
77cdf0e10cSrcweir                                      SCRBAR_DRAW_PAGE1 | SCRBAR_DRAW_PAGE2 |\
78cdf0e10cSrcweir                                      SCRBAR_DRAW_THUMB | SCRBAR_DRAW_BACKGROUND )
79cdf0e10cSrcweir 
80cdf0e10cSrcweir #define SCRBAR_STATE_BTN1_DOWN      ((sal_uInt16)0x0001)
81cdf0e10cSrcweir #define SCRBAR_STATE_BTN1_DISABLE   ((sal_uInt16)0x0002)
82cdf0e10cSrcweir #define SCRBAR_STATE_BTN2_DOWN      ((sal_uInt16)0x0004)
83cdf0e10cSrcweir #define SCRBAR_STATE_BTN2_DISABLE   ((sal_uInt16)0x0008)
84cdf0e10cSrcweir #define SCRBAR_STATE_PAGE1_DOWN     ((sal_uInt16)0x0010)
85cdf0e10cSrcweir #define SCRBAR_STATE_PAGE2_DOWN     ((sal_uInt16)0x0020)
86cdf0e10cSrcweir #define SCRBAR_STATE_THUMB_DOWN     ((sal_uInt16)0x0040)
87cdf0e10cSrcweir 
88cdf0e10cSrcweir #define SCRBAR_VIEW_STYLE           (WB_3DLOOK | WB_HORZ | WB_VERT)
89cdf0e10cSrcweir 
90cdf0e10cSrcweir struct ImplScrollBarData
91cdf0e10cSrcweir {
92cdf0e10cSrcweir 	AutoTimer		maTimer;			// Timer
93cdf0e10cSrcweir     sal_Bool            mbHide;
94cdf0e10cSrcweir 	Rectangle		maTrackRect; // TODO: move to ScrollBar class when binary incompatibility of ScrollBar class is no longer problematic
95cdf0e10cSrcweir };
96cdf0e10cSrcweir 
97cdf0e10cSrcweir // =======================================================================
98cdf0e10cSrcweir 
ImplInit(Window * pParent,WinBits nStyle)99cdf0e10cSrcweir void ScrollBar::ImplInit( Window* pParent, WinBits nStyle )
100cdf0e10cSrcweir {
101cdf0e10cSrcweir     mpData              = NULL;
102cdf0e10cSrcweir     mnThumbPixRange     = 0;
103cdf0e10cSrcweir     mnThumbPixPos       = 0;
104cdf0e10cSrcweir     mnThumbPixSize      = 0;
105cdf0e10cSrcweir     mnMinRange          = 0;
106cdf0e10cSrcweir     mnMaxRange          = 100;
107cdf0e10cSrcweir     mnThumbPos          = 0;
108cdf0e10cSrcweir     mnVisibleSize       = 0;
109cdf0e10cSrcweir     mnLineSize          = 1;
110cdf0e10cSrcweir     mnPageSize          = 1;
111cdf0e10cSrcweir     mnDelta             = 0;
112cdf0e10cSrcweir     mnDragDraw          = 0;
113cdf0e10cSrcweir     mnStateFlags        = 0;
114cdf0e10cSrcweir     meScrollType        = SCROLL_DONTKNOW;
115cdf0e10cSrcweir     meDDScrollType      = SCROLL_DONTKNOW;
116cdf0e10cSrcweir     mbCalcSize          = sal_True;
117cdf0e10cSrcweir     mbFullDrag          = 0;
118cdf0e10cSrcweir 
119cdf0e10cSrcweir     if( !mpData )  // TODO: remove when maTrackRect is no longer in mpData
120cdf0e10cSrcweir     {
121cdf0e10cSrcweir 	    mpData = new ImplScrollBarData;
122cdf0e10cSrcweir 		mpData->maTimer.SetTimeoutHdl( LINK( this, ScrollBar, ImplAutoTimerHdl ) );
123cdf0e10cSrcweir         mpData->mbHide = sal_False;
124cdf0e10cSrcweir     }
125cdf0e10cSrcweir 
126cdf0e10cSrcweir     ImplInitStyle( nStyle );
127cdf0e10cSrcweir     Control::ImplInit( pParent, nStyle, NULL );
128cdf0e10cSrcweir 
129cdf0e10cSrcweir     long nScrollSize = GetSettings().GetStyleSettings().GetScrollBarSize();
130cdf0e10cSrcweir     SetSizePixel( Size( nScrollSize, nScrollSize ) );
131cdf0e10cSrcweir     SetBackground();
132cdf0e10cSrcweir }
133cdf0e10cSrcweir 
134cdf0e10cSrcweir // -----------------------------------------------------------------------
135cdf0e10cSrcweir 
ImplInitStyle(WinBits nStyle)136cdf0e10cSrcweir void ScrollBar::ImplInitStyle( WinBits nStyle )
137cdf0e10cSrcweir {
138cdf0e10cSrcweir     if ( nStyle & WB_DRAG )
139cdf0e10cSrcweir         mbFullDrag = sal_True;
140cdf0e10cSrcweir     else
141cdf0e10cSrcweir         mbFullDrag = (GetSettings().GetStyleSettings().GetDragFullOptions() & DRAGFULL_OPTION_SCROLL) != 0;
142cdf0e10cSrcweir }
143cdf0e10cSrcweir 
144cdf0e10cSrcweir // -----------------------------------------------------------------------
145cdf0e10cSrcweir 
ScrollBar(Window * pParent,WinBits nStyle)146cdf0e10cSrcweir ScrollBar::ScrollBar( Window* pParent, WinBits nStyle ) :
147cdf0e10cSrcweir     Control( WINDOW_SCROLLBAR )
148cdf0e10cSrcweir {
149cdf0e10cSrcweir     ImplInit( pParent, nStyle );
150cdf0e10cSrcweir }
151cdf0e10cSrcweir 
152cdf0e10cSrcweir // -----------------------------------------------------------------------
153cdf0e10cSrcweir 
ScrollBar(Window * pParent,const ResId & rResId)154cdf0e10cSrcweir ScrollBar::ScrollBar( Window* pParent, const ResId& rResId ) :
155cdf0e10cSrcweir     Control( WINDOW_SCROLLBAR )
156cdf0e10cSrcweir {
157cdf0e10cSrcweir     rResId.SetRT( RSC_SCROLLBAR );
158cdf0e10cSrcweir     WinBits nStyle = ImplInitRes( rResId );
159cdf0e10cSrcweir     ImplInit( pParent, nStyle );
160cdf0e10cSrcweir     ImplLoadRes( rResId );
161cdf0e10cSrcweir 
162cdf0e10cSrcweir     if ( !(nStyle & WB_HIDE) )
163cdf0e10cSrcweir         Show();
164cdf0e10cSrcweir }
165cdf0e10cSrcweir 
166cdf0e10cSrcweir // -----------------------------------------------------------------------
167cdf0e10cSrcweir 
~ScrollBar()168cdf0e10cSrcweir ScrollBar::~ScrollBar()
169cdf0e10cSrcweir {
170cdf0e10cSrcweir     if( mpData )
171cdf0e10cSrcweir         delete mpData;
172cdf0e10cSrcweir }
173cdf0e10cSrcweir 
174cdf0e10cSrcweir // -----------------------------------------------------------------------
175cdf0e10cSrcweir 
ImplLoadRes(const ResId & rResId)176cdf0e10cSrcweir void ScrollBar::ImplLoadRes( const ResId& rResId )
177cdf0e10cSrcweir {
178cdf0e10cSrcweir     Control::ImplLoadRes( rResId );
179cdf0e10cSrcweir 
180cdf0e10cSrcweir     sal_Int16 nMin          = ReadShortRes();
181cdf0e10cSrcweir     sal_Int16 nMax          = ReadShortRes();
182cdf0e10cSrcweir     sal_Int16 nThumbPos     = ReadShortRes();
183cdf0e10cSrcweir     sal_Int16 nPage         = ReadShortRes();
184cdf0e10cSrcweir     sal_Int16 nStep         = ReadShortRes();
185cdf0e10cSrcweir     sal_Int16 nVisibleSize  = ReadShortRes();
186cdf0e10cSrcweir 
187cdf0e10cSrcweir     SetRange( Range( nMin, nMax ) );
188cdf0e10cSrcweir     SetLineSize( nStep );
189cdf0e10cSrcweir     SetPageSize( nPage );
190cdf0e10cSrcweir     SetVisibleSize( nVisibleSize );
191cdf0e10cSrcweir     SetThumbPos( nThumbPos );
192cdf0e10cSrcweir }
193cdf0e10cSrcweir 
194cdf0e10cSrcweir // -----------------------------------------------------------------------
195cdf0e10cSrcweir 
ImplUpdateRects(sal_Bool bUpdate)196cdf0e10cSrcweir void ScrollBar::ImplUpdateRects( sal_Bool bUpdate )
197cdf0e10cSrcweir {
198cdf0e10cSrcweir     sal_uInt16      nOldStateFlags  = mnStateFlags;
199cdf0e10cSrcweir     Rectangle   aOldPage1Rect = maPage1Rect;
200cdf0e10cSrcweir     Rectangle   aOldPage2Rect = maPage2Rect;
201cdf0e10cSrcweir     Rectangle   aOldThumbRect = maThumbRect;
202cdf0e10cSrcweir 
203cdf0e10cSrcweir     mnStateFlags  &= ~SCRBAR_STATE_BTN1_DISABLE;
204cdf0e10cSrcweir     mnStateFlags  &= ~SCRBAR_STATE_BTN2_DISABLE;
205cdf0e10cSrcweir 
206cdf0e10cSrcweir 	Rectangle& maTrackRect = mpData->maTrackRect; // TODO: remove when maTrackRect is no longer in mpData
207cdf0e10cSrcweir     if ( mnThumbPixRange )
208cdf0e10cSrcweir     {
209cdf0e10cSrcweir         if ( GetStyle() & WB_HORZ )
210cdf0e10cSrcweir         {
211cdf0e10cSrcweir             maThumbRect.Left()      = maTrackRect.Left()+mnThumbPixPos;
212cdf0e10cSrcweir             maThumbRect.Right()     = maThumbRect.Left()+mnThumbPixSize-1;
213cdf0e10cSrcweir             if ( !mnThumbPixPos )
214cdf0e10cSrcweir                 maPage1Rect.Right()     = RECT_EMPTY;
215cdf0e10cSrcweir             else
216cdf0e10cSrcweir                 maPage1Rect.Right()     = maThumbRect.Left()-1;
217cdf0e10cSrcweir             if ( mnThumbPixPos >= (mnThumbPixRange-mnThumbPixSize) )
218cdf0e10cSrcweir                 maPage2Rect.Right()     = RECT_EMPTY;
219cdf0e10cSrcweir             else
220cdf0e10cSrcweir             {
221cdf0e10cSrcweir                 maPage2Rect.Left()      = maThumbRect.Right()+1;
222cdf0e10cSrcweir                 maPage2Rect.Right()     = maTrackRect.Right();
223cdf0e10cSrcweir             }
224cdf0e10cSrcweir         }
225cdf0e10cSrcweir         else
226cdf0e10cSrcweir         {
227cdf0e10cSrcweir             maThumbRect.Top()       = maTrackRect.Top()+mnThumbPixPos;
228cdf0e10cSrcweir             maThumbRect.Bottom()    = maThumbRect.Top()+mnThumbPixSize-1;
229cdf0e10cSrcweir             if ( !mnThumbPixPos )
230cdf0e10cSrcweir                 maPage1Rect.Bottom()    = RECT_EMPTY;
231cdf0e10cSrcweir             else
232cdf0e10cSrcweir                 maPage1Rect.Bottom()    = maThumbRect.Top()-1;
233cdf0e10cSrcweir             if ( mnThumbPixPos >= (mnThumbPixRange-mnThumbPixSize) )
234cdf0e10cSrcweir                 maPage2Rect.Bottom()    = RECT_EMPTY;
235cdf0e10cSrcweir             else
236cdf0e10cSrcweir             {
237cdf0e10cSrcweir                 maPage2Rect.Top()       = maThumbRect.Bottom()+1;
238cdf0e10cSrcweir                 maPage2Rect.Bottom()    = maTrackRect.Bottom();
239cdf0e10cSrcweir             }
240cdf0e10cSrcweir         }
241cdf0e10cSrcweir     }
242cdf0e10cSrcweir     else
243cdf0e10cSrcweir     {
244cdf0e10cSrcweir         Size aScrBarSize = GetOutputSizePixel();
245cdf0e10cSrcweir         if ( GetStyle() & WB_HORZ )
246cdf0e10cSrcweir         {
247cdf0e10cSrcweir             const long nSpace = maTrackRect.Right() - maTrackRect.Left();
248cdf0e10cSrcweir             if ( nSpace > 0 )
249cdf0e10cSrcweir             {
250cdf0e10cSrcweir                 maPage1Rect.Left()   = maTrackRect.Left();
251cdf0e10cSrcweir                 maPage1Rect.Right()  = maTrackRect.Left() + (nSpace/2);
252cdf0e10cSrcweir                 maPage2Rect.Left()   = maPage1Rect.Right() + 1;
253cdf0e10cSrcweir                 maPage2Rect.Right()  = maTrackRect.Right();
254cdf0e10cSrcweir             }
255cdf0e10cSrcweir         }
256cdf0e10cSrcweir         else
257cdf0e10cSrcweir         {
258cdf0e10cSrcweir             const long nSpace = maTrackRect.Bottom() - maTrackRect.Top();
259cdf0e10cSrcweir             if ( nSpace > 0 )
260cdf0e10cSrcweir             {
261cdf0e10cSrcweir                 maPage1Rect.Top()    = maTrackRect.Top();
262cdf0e10cSrcweir                 maPage1Rect.Bottom() = maTrackRect.Top() + (nSpace/2);
263cdf0e10cSrcweir                 maPage2Rect.Top()    = maPage1Rect.Bottom() + 1;
264cdf0e10cSrcweir                 maPage2Rect.Bottom() = maTrackRect.Bottom();
265cdf0e10cSrcweir             }
266cdf0e10cSrcweir         }
267cdf0e10cSrcweir     }
268cdf0e10cSrcweir 
269cdf0e10cSrcweir     if( !IsNativeControlSupported(CTRL_SCROLLBAR, PART_ENTIRE_CONTROL) )
270cdf0e10cSrcweir     {
271cdf0e10cSrcweir         // disable scrollbar buttons only in VCL's own 'theme'
272cdf0e10cSrcweir         // as it is uncommon on other platforms
273cdf0e10cSrcweir         if ( mnThumbPos == mnMinRange )
274cdf0e10cSrcweir             mnStateFlags |= SCRBAR_STATE_BTN1_DISABLE;
275cdf0e10cSrcweir         if ( mnThumbPos >= (mnMaxRange-mnVisibleSize) )
276cdf0e10cSrcweir             mnStateFlags |= SCRBAR_STATE_BTN2_DISABLE;
277cdf0e10cSrcweir     }
278cdf0e10cSrcweir 
279cdf0e10cSrcweir     if ( bUpdate )
280cdf0e10cSrcweir     {
281cdf0e10cSrcweir         sal_uInt16 nDraw = 0;
282cdf0e10cSrcweir         if ( (nOldStateFlags & SCRBAR_STATE_BTN1_DISABLE) !=
283cdf0e10cSrcweir              (mnStateFlags & SCRBAR_STATE_BTN1_DISABLE) )
284cdf0e10cSrcweir             nDraw |= SCRBAR_DRAW_BTN1;
285cdf0e10cSrcweir         if ( (nOldStateFlags & SCRBAR_STATE_BTN2_DISABLE) !=
286cdf0e10cSrcweir              (mnStateFlags & SCRBAR_STATE_BTN2_DISABLE) )
287cdf0e10cSrcweir             nDraw |= SCRBAR_DRAW_BTN2;
288cdf0e10cSrcweir         if ( aOldPage1Rect != maPage1Rect )
289cdf0e10cSrcweir             nDraw |= SCRBAR_DRAW_PAGE1;
290cdf0e10cSrcweir         if ( aOldPage2Rect != maPage2Rect )
291cdf0e10cSrcweir             nDraw |= SCRBAR_DRAW_PAGE2;
292cdf0e10cSrcweir         if ( aOldThumbRect != maThumbRect )
293cdf0e10cSrcweir             nDraw |= SCRBAR_DRAW_THUMB;
294cdf0e10cSrcweir         ImplDraw( nDraw, this );
295cdf0e10cSrcweir     }
296cdf0e10cSrcweir }
297cdf0e10cSrcweir 
298cdf0e10cSrcweir // -----------------------------------------------------------------------
299cdf0e10cSrcweir 
ImplCalcThumbPos(long nPixPos)300cdf0e10cSrcweir long ScrollBar::ImplCalcThumbPos( long nPixPos )
301cdf0e10cSrcweir {
302cdf0e10cSrcweir     // Position berechnen
303cdf0e10cSrcweir     long nCalcThumbPos;
304cdf0e10cSrcweir     nCalcThumbPos = ImplMulDiv( nPixPos, mnMaxRange-mnVisibleSize-mnMinRange,
305cdf0e10cSrcweir                                 mnThumbPixRange-mnThumbPixSize );
306cdf0e10cSrcweir     nCalcThumbPos += mnMinRange;
307cdf0e10cSrcweir     return nCalcThumbPos;
308cdf0e10cSrcweir }
309cdf0e10cSrcweir 
310cdf0e10cSrcweir // -----------------------------------------------------------------------
311cdf0e10cSrcweir 
ImplCalcThumbPosPix(long nPos)312cdf0e10cSrcweir long ScrollBar::ImplCalcThumbPosPix( long nPos )
313cdf0e10cSrcweir {
314cdf0e10cSrcweir     long nCalcThumbPos;
315cdf0e10cSrcweir 
316cdf0e10cSrcweir     // Position berechnen
317cdf0e10cSrcweir     nCalcThumbPos = ImplMulDiv( nPos-mnMinRange, mnThumbPixRange-mnThumbPixSize,
318cdf0e10cSrcweir                                 mnMaxRange-mnVisibleSize-mnMinRange );
319cdf0e10cSrcweir 
320cdf0e10cSrcweir     // Am Anfang und Ende des ScrollBars versuchen wir die Anzeige korrekt
321cdf0e10cSrcweir     // anzuzeigen
322cdf0e10cSrcweir     if ( !nCalcThumbPos && (mnThumbPos > mnMinRange) )
323cdf0e10cSrcweir         nCalcThumbPos = 1;
324cdf0e10cSrcweir     if ( nCalcThumbPos &&
325cdf0e10cSrcweir          ((nCalcThumbPos+mnThumbPixSize) >= mnThumbPixRange) &&
326cdf0e10cSrcweir          (mnThumbPos < (mnMaxRange-mnVisibleSize)) )
327cdf0e10cSrcweir         nCalcThumbPos--;
328cdf0e10cSrcweir 
329cdf0e10cSrcweir     return nCalcThumbPos;
330cdf0e10cSrcweir }
331cdf0e10cSrcweir 
332cdf0e10cSrcweir // -----------------------------------------------------------------------
333cdf0e10cSrcweir 
ImplCalc(sal_Bool bUpdate)334cdf0e10cSrcweir void ScrollBar::ImplCalc( sal_Bool bUpdate )
335cdf0e10cSrcweir {
336cdf0e10cSrcweir     const Size aSize = GetOutputSizePixel();
337cdf0e10cSrcweir     const long nMinThumbSize = GetSettings().GetStyleSettings().GetMinThumbSize();;
338cdf0e10cSrcweir 
339cdf0e10cSrcweir 	Rectangle& maTrackRect = mpData->maTrackRect;  // TODO: remove when maTrackRect is no longer in mpData
340cdf0e10cSrcweir     if ( mbCalcSize )
341cdf0e10cSrcweir     {
342cdf0e10cSrcweir         const Rectangle aControlRegion( Point(0,0), aSize );
343cdf0e10cSrcweir         Rectangle aBtn1Region, aBtn2Region, aTrackRegion, aBoundingRegion;
344cdf0e10cSrcweir 
345cdf0e10cSrcweir         if ( GetStyle() & WB_HORZ )
346cdf0e10cSrcweir         {
347cdf0e10cSrcweir             if ( GetNativeControlRegion( CTRL_SCROLLBAR, PART_BUTTON_LEFT,
348cdf0e10cSrcweir                         aControlRegion, 0, ImplControlValue(), rtl::OUString(), aBoundingRegion, aBtn1Region ) &&
349cdf0e10cSrcweir                  GetNativeControlRegion( CTRL_SCROLLBAR, PART_BUTTON_RIGHT,
350cdf0e10cSrcweir                         aControlRegion, 0, ImplControlValue(), rtl::OUString(), aBoundingRegion, aBtn2Region ) )
351cdf0e10cSrcweir             {
352cdf0e10cSrcweir                 maBtn1Rect = aBtn1Region;
353cdf0e10cSrcweir                 maBtn2Rect = aBtn2Region;
354cdf0e10cSrcweir             }
355cdf0e10cSrcweir             else
356cdf0e10cSrcweir             {
357*13a3daf1SJuergen Schmidt                 if (aBtn1Region.IsEmpty() && aBtn2Region.IsEmpty())
358*13a3daf1SJuergen Schmidt                 {
359*13a3daf1SJuergen Schmidt                     Size aBtnSize( aSize.Height(), aSize.Height() );
360*13a3daf1SJuergen Schmidt                     maBtn2Rect.Top() = maBtn1Rect.Top();
361*13a3daf1SJuergen Schmidt                     maBtn2Rect.Left() = aSize.Width()-aSize.Height();
362*13a3daf1SJuergen Schmidt                     maBtn1Rect.SetSize( aBtnSize );
363*13a3daf1SJuergen Schmidt                     maBtn2Rect.SetSize( aBtnSize );
364*13a3daf1SJuergen Schmidt                 }
365*13a3daf1SJuergen Schmidt                 else
366*13a3daf1SJuergen Schmidt                 {
367*13a3daf1SJuergen Schmidt                     maBtn1Rect.SetEmpty();
368*13a3daf1SJuergen Schmidt                     maBtn2Rect.SetEmpty();
369*13a3daf1SJuergen Schmidt                 }
370cdf0e10cSrcweir             }
371cdf0e10cSrcweir 
372cdf0e10cSrcweir             if ( GetNativeControlRegion( CTRL_SCROLLBAR, PART_TRACK_HORZ_AREA,
373cdf0e10cSrcweir 	                 aControlRegion, 0, ImplControlValue(), rtl::OUString(), aBoundingRegion, aTrackRegion ) )
374*13a3daf1SJuergen Schmidt             {
375cdf0e10cSrcweir                 maTrackRect = aTrackRegion;
376*13a3daf1SJuergen Schmidt             }
377cdf0e10cSrcweir             else
378*13a3daf1SJuergen Schmidt             {
379*13a3daf1SJuergen Schmidt                 if ( ! maBtn1Rect.IsEmpty())
380*13a3daf1SJuergen Schmidt                     maTrackRect = Rectangle( maBtn1Rect.TopRight(), maBtn2Rect.BottomLeft() );
381*13a3daf1SJuergen Schmidt                 else
382*13a3daf1SJuergen Schmidt                     maTrackRect = aControlRegion;
383*13a3daf1SJuergen Schmidt             }
384cdf0e10cSrcweir 
385cdf0e10cSrcweir             // Check if available space is big enough for thumb ( min thumb size = ScrBar width/height )
386cdf0e10cSrcweir             mnThumbPixRange = maTrackRect.Right() - maTrackRect.Left();
387cdf0e10cSrcweir             if( mnThumbPixRange > 0 )
388cdf0e10cSrcweir             {
389cdf0e10cSrcweir                 maPage1Rect.Left()      = maTrackRect.Left();
390cdf0e10cSrcweir                 maPage1Rect.Bottom()	=
391cdf0e10cSrcweir                 maPage2Rect.Bottom()	=
392cdf0e10cSrcweir                 maThumbRect.Bottom()    = maTrackRect.Bottom();
393cdf0e10cSrcweir             }
394cdf0e10cSrcweir             else
395cdf0e10cSrcweir             {
396cdf0e10cSrcweir                 mnThumbPixRange = 0;
397cdf0e10cSrcweir                 maPage1Rect.SetEmpty();
398cdf0e10cSrcweir                 maPage2Rect.SetEmpty();
399cdf0e10cSrcweir             }
400cdf0e10cSrcweir         }
401cdf0e10cSrcweir         else
402cdf0e10cSrcweir         {
403cdf0e10cSrcweir             if ( GetNativeControlRegion( CTRL_SCROLLBAR, PART_BUTTON_UP,
404cdf0e10cSrcweir                         aControlRegion, 0, ImplControlValue(), rtl::OUString(), aBoundingRegion, aBtn1Region ) &&
405cdf0e10cSrcweir                  GetNativeControlRegion( CTRL_SCROLLBAR, PART_BUTTON_DOWN,
406cdf0e10cSrcweir                         aControlRegion, 0, ImplControlValue(), rtl::OUString(), aBoundingRegion, aBtn2Region ) )
407cdf0e10cSrcweir             {
408cdf0e10cSrcweir                 maBtn1Rect = aBtn1Region;
409cdf0e10cSrcweir                 maBtn2Rect = aBtn2Region;
410cdf0e10cSrcweir             }
411cdf0e10cSrcweir             else
412cdf0e10cSrcweir             {
413*13a3daf1SJuergen Schmidt                 if (aBtn1Region.IsEmpty() && aBtn2Region.IsEmpty())
414*13a3daf1SJuergen Schmidt                 {
415*13a3daf1SJuergen Schmidt                     const Size aBtnSize( aSize.Width(), aSize.Width() );
416*13a3daf1SJuergen Schmidt                     maBtn2Rect.Left()   = maBtn1Rect.Left();
417*13a3daf1SJuergen Schmidt                     maBtn2Rect.Top()    = aSize.Height()-aSize.Width();
418*13a3daf1SJuergen Schmidt                     maBtn1Rect.SetSize( aBtnSize );
419*13a3daf1SJuergen Schmidt                     maBtn2Rect.SetSize( aBtnSize );
420*13a3daf1SJuergen Schmidt                 }
421*13a3daf1SJuergen Schmidt                 else
422*13a3daf1SJuergen Schmidt                 {
423*13a3daf1SJuergen Schmidt                     maBtn1Rect.SetEmpty();
424*13a3daf1SJuergen Schmidt                     maBtn2Rect.SetEmpty();
425*13a3daf1SJuergen Schmidt                 }
426cdf0e10cSrcweir             }
427cdf0e10cSrcweir 
428cdf0e10cSrcweir             if ( GetNativeControlRegion( CTRL_SCROLLBAR, PART_TRACK_VERT_AREA,
429cdf0e10cSrcweir 	                 aControlRegion, 0, ImplControlValue(), rtl::OUString(), aBoundingRegion, aTrackRegion ) )
430cdf0e10cSrcweir                 maTrackRect = aTrackRegion;
431cdf0e10cSrcweir 			else
432*13a3daf1SJuergen Schmidt             {
433*13a3daf1SJuergen Schmidt                 if ( ! maBtn1Rect.IsEmpty())
434*13a3daf1SJuergen Schmidt                     maTrackRect = Rectangle( maBtn1Rect.BottomLeft()+Point(0,1), maBtn2Rect.TopRight() );
435*13a3daf1SJuergen Schmidt                 else
436*13a3daf1SJuergen Schmidt                     maTrackRect = aControlRegion;
437*13a3daf1SJuergen Schmidt             }
438cdf0e10cSrcweir 
439cdf0e10cSrcweir             // Check if available space is big enough for thumb
440cdf0e10cSrcweir             mnThumbPixRange = maTrackRect.Bottom() - maTrackRect.Top();
441cdf0e10cSrcweir             if( mnThumbPixRange > 0 )
442cdf0e10cSrcweir             {
443cdf0e10cSrcweir                 maPage1Rect.Top()       = maTrackRect.Top();
444cdf0e10cSrcweir                 maPage1Rect.Right()		=
445cdf0e10cSrcweir                 maPage2Rect.Right()		=
446cdf0e10cSrcweir                 maThumbRect.Right()     = maTrackRect.Right();
447cdf0e10cSrcweir             }
448cdf0e10cSrcweir             else
449cdf0e10cSrcweir 			{
450cdf0e10cSrcweir                 mnThumbPixRange = 0;
451cdf0e10cSrcweir                 maPage1Rect.SetEmpty();
452cdf0e10cSrcweir                 maPage2Rect.SetEmpty();
453cdf0e10cSrcweir             }
454cdf0e10cSrcweir         }
455cdf0e10cSrcweir 
456cdf0e10cSrcweir         if ( !mnThumbPixRange )
457cdf0e10cSrcweir             maThumbRect.SetEmpty();
458cdf0e10cSrcweir 
459cdf0e10cSrcweir         mbCalcSize = sal_False;
460cdf0e10cSrcweir     }
461cdf0e10cSrcweir 
462cdf0e10cSrcweir     if ( mnThumbPixRange )
463cdf0e10cSrcweir     {
464cdf0e10cSrcweir         // Werte berechnen
465cdf0e10cSrcweir         if ( (mnVisibleSize >= (mnMaxRange-mnMinRange)) ||
466cdf0e10cSrcweir              ((mnMaxRange-mnMinRange) <= 0) )
467cdf0e10cSrcweir         {
468cdf0e10cSrcweir             mnThumbPos      = mnMinRange;
469cdf0e10cSrcweir             mnThumbPixPos   = 0;
470cdf0e10cSrcweir             mnThumbPixSize  = mnThumbPixRange;
471cdf0e10cSrcweir         }
472cdf0e10cSrcweir         else
473cdf0e10cSrcweir         {
474cdf0e10cSrcweir             if ( mnVisibleSize )
475cdf0e10cSrcweir                 mnThumbPixSize = ImplMulDiv( mnThumbPixRange, mnVisibleSize, mnMaxRange-mnMinRange );
476cdf0e10cSrcweir             else
477cdf0e10cSrcweir             {
478cdf0e10cSrcweir                 if ( GetStyle() & WB_HORZ )
479cdf0e10cSrcweir                     mnThumbPixSize = maThumbRect.GetWidth();
480cdf0e10cSrcweir                 else
481cdf0e10cSrcweir                     mnThumbPixSize = maThumbRect.GetHeight();
482cdf0e10cSrcweir             }
483cdf0e10cSrcweir             if ( mnThumbPixSize < nMinThumbSize )
484cdf0e10cSrcweir                 mnThumbPixSize = nMinThumbSize;
485cdf0e10cSrcweir             if ( mnThumbPixSize > mnThumbPixRange )
486cdf0e10cSrcweir                 mnThumbPixSize = mnThumbPixRange;
487cdf0e10cSrcweir             mnThumbPixPos = ImplCalcThumbPosPix( mnThumbPos );
488cdf0e10cSrcweir         }
489cdf0e10cSrcweir     }
490cdf0e10cSrcweir 
491cdf0e10cSrcweir     // Wenn neu ausgegeben werden soll und wir schon ueber eine
492cdf0e10cSrcweir     // Aktion einen Paint-Event ausgeloest bekommen haben, dann
493cdf0e10cSrcweir     // geben wir nicht direkt aus, sondern invalidieren nur alles
494cdf0e10cSrcweir     if ( bUpdate && HasPaintEvent() )
495cdf0e10cSrcweir     {
496cdf0e10cSrcweir         Invalidate();
497cdf0e10cSrcweir         bUpdate = sal_False;
498cdf0e10cSrcweir     }
499cdf0e10cSrcweir     ImplUpdateRects( bUpdate );
500cdf0e10cSrcweir }
501cdf0e10cSrcweir 
502cdf0e10cSrcweir // -----------------------------------------------------------------------
503cdf0e10cSrcweir 
Draw(OutputDevice * pDev,const Point & rPos,const Size & rSize,sal_uLong nFlags)504cdf0e10cSrcweir void ScrollBar::Draw( OutputDevice* pDev, const Point& rPos, const Size& rSize, sal_uLong nFlags )
505cdf0e10cSrcweir {
506cdf0e10cSrcweir     Point       aPos  = pDev->LogicToPixel( rPos );
507cdf0e10cSrcweir     Size        aSize = pDev->LogicToPixel( rSize );
508cdf0e10cSrcweir     Rectangle   aRect( aPos, aSize );
509cdf0e10cSrcweir 
510cdf0e10cSrcweir     pDev->Push();
511cdf0e10cSrcweir     pDev->SetMapMode();
512cdf0e10cSrcweir     if ( !(nFlags & WINDOW_DRAW_MONO) )
513cdf0e10cSrcweir 	{
514cdf0e10cSrcweir 		// DecoView uses the FaceColor...
515cdf0e10cSrcweir 		AllSettings aSettings = pDev->GetSettings();
516cdf0e10cSrcweir 		StyleSettings aStyleSettings = aSettings.GetStyleSettings();
517cdf0e10cSrcweir 		if ( IsControlBackground() )
518cdf0e10cSrcweir 			aStyleSettings.SetFaceColor( GetControlBackground() );
519cdf0e10cSrcweir 		else
520cdf0e10cSrcweir 			aStyleSettings.SetFaceColor( GetSettings().GetStyleSettings().GetFaceColor() );
521cdf0e10cSrcweir 
522cdf0e10cSrcweir 		aSettings.SetStyleSettings( aStyleSettings );
523cdf0e10cSrcweir 		pDev->SetSettings( aSettings );
524cdf0e10cSrcweir 	}
525cdf0e10cSrcweir 
526cdf0e10cSrcweir     // for printing:
527cdf0e10cSrcweir     // -calculate the size of the rects
528cdf0e10cSrcweir     // -because this is zero-based add the correct offset
529cdf0e10cSrcweir     // -print
530cdf0e10cSrcweir     // -force recalculate
531cdf0e10cSrcweir 
532cdf0e10cSrcweir     if ( mbCalcSize )
533cdf0e10cSrcweir         ImplCalc( sal_False );
534cdf0e10cSrcweir 
535cdf0e10cSrcweir     maBtn1Rect+=aPos;
536cdf0e10cSrcweir     maBtn2Rect+=aPos;
537cdf0e10cSrcweir     maThumbRect+=aPos;
538cdf0e10cSrcweir     mpData->maTrackRect+=aPos; // TODO: update when maTrackRect is no longer in mpData
539cdf0e10cSrcweir     maPage1Rect+=aPos;
540cdf0e10cSrcweir     maPage2Rect+=aPos;
541cdf0e10cSrcweir 
542cdf0e10cSrcweir     ImplDraw( SCRBAR_DRAW_ALL, pDev );
543cdf0e10cSrcweir     pDev->Pop();
544cdf0e10cSrcweir 
545cdf0e10cSrcweir     mbCalcSize = sal_True;
546cdf0e10cSrcweir }
547cdf0e10cSrcweir 
548cdf0e10cSrcweir // -----------------------------------------------------------------------
549cdf0e10cSrcweir 
ImplDrawNative(sal_uInt16 nDrawFlags)550cdf0e10cSrcweir sal_Bool ScrollBar::ImplDrawNative( sal_uInt16 nDrawFlags )
551cdf0e10cSrcweir {
552cdf0e10cSrcweir     ScrollbarValue scrValue;
553cdf0e10cSrcweir 
554cdf0e10cSrcweir     sal_Bool bNativeOK = IsNativeControlSupported(CTRL_SCROLLBAR, PART_ENTIRE_CONTROL);
555cdf0e10cSrcweir     if( bNativeOK )
556cdf0e10cSrcweir     {
557cdf0e10cSrcweir         sal_Bool bHorz = (GetStyle() & WB_HORZ ? true : false);
558cdf0e10cSrcweir 
559cdf0e10cSrcweir         // Draw the entire background if the control supports it
560cdf0e10cSrcweir         if( IsNativeControlSupported(CTRL_SCROLLBAR, bHorz ? PART_DRAW_BACKGROUND_HORZ : PART_DRAW_BACKGROUND_VERT) )
561cdf0e10cSrcweir         {
562cdf0e10cSrcweir             ControlState		nState = ( IsEnabled() ? CTRL_STATE_ENABLED : 0 ) | ( HasFocus() ? CTRL_STATE_FOCUSED : 0 );
563cdf0e10cSrcweir 
564cdf0e10cSrcweir             scrValue.mnMin = mnMinRange;
565cdf0e10cSrcweir             scrValue.mnMax = mnMaxRange;
566cdf0e10cSrcweir             scrValue.mnCur = mnThumbPos;
567cdf0e10cSrcweir             scrValue.mnVisibleSize = mnVisibleSize;
568cdf0e10cSrcweir             scrValue.maThumbRect = maThumbRect;
569cdf0e10cSrcweir             scrValue.maButton1Rect = maBtn1Rect;
570cdf0e10cSrcweir             scrValue.maButton2Rect = maBtn2Rect;
571cdf0e10cSrcweir             scrValue.mnButton1State = ((mnStateFlags & SCRBAR_STATE_BTN1_DOWN) ? CTRL_STATE_PRESSED : 0) |
572cdf0e10cSrcweir 								((!(mnStateFlags & SCRBAR_STATE_BTN1_DISABLE)) ? CTRL_STATE_ENABLED : 0);
573cdf0e10cSrcweir             scrValue.mnButton2State = ((mnStateFlags & SCRBAR_STATE_BTN2_DOWN) ? CTRL_STATE_PRESSED : 0) |
574cdf0e10cSrcweir 								((!(mnStateFlags & SCRBAR_STATE_BTN2_DISABLE)) ? CTRL_STATE_ENABLED : 0);
575cdf0e10cSrcweir             scrValue.mnThumbState = nState | ((mnStateFlags & SCRBAR_STATE_THUMB_DOWN) ? CTRL_STATE_PRESSED : 0);
576cdf0e10cSrcweir             scrValue.mnPage1State = nState | ((mnStateFlags & SCRBAR_STATE_PAGE1_DOWN) ? CTRL_STATE_PRESSED : 0);
577cdf0e10cSrcweir             scrValue.mnPage2State = nState | ((mnStateFlags & SCRBAR_STATE_PAGE2_DOWN) ? CTRL_STATE_PRESSED : 0);
578cdf0e10cSrcweir 
579cdf0e10cSrcweir             if( IsMouseOver() )
580cdf0e10cSrcweir             {
581cdf0e10cSrcweir                 Rectangle* pRect = ImplFindPartRect( GetPointerPosPixel() );
582cdf0e10cSrcweir                 if( pRect )
583cdf0e10cSrcweir                 {
584cdf0e10cSrcweir                     if( pRect == &maThumbRect )
585cdf0e10cSrcweir                         scrValue.mnThumbState |= CTRL_STATE_ROLLOVER;
586cdf0e10cSrcweir                     else if( pRect == &maBtn1Rect )
587cdf0e10cSrcweir                         scrValue.mnButton1State |= CTRL_STATE_ROLLOVER;
588cdf0e10cSrcweir                     else if( pRect == &maBtn2Rect )
589cdf0e10cSrcweir                         scrValue.mnButton2State |= CTRL_STATE_ROLLOVER;
590cdf0e10cSrcweir                     else if( pRect == &maPage1Rect )
591cdf0e10cSrcweir                         scrValue.mnPage1State |= CTRL_STATE_ROLLOVER;
592cdf0e10cSrcweir                     else if( pRect == &maPage2Rect )
593cdf0e10cSrcweir                         scrValue.mnPage2State |= CTRL_STATE_ROLLOVER;
594cdf0e10cSrcweir                 }
595cdf0e10cSrcweir             }
596cdf0e10cSrcweir 
597cdf0e10cSrcweir             Rectangle aCtrlRegion;
598cdf0e10cSrcweir             aCtrlRegion.Union( maBtn1Rect );
599cdf0e10cSrcweir             aCtrlRegion.Union( maBtn2Rect );
600cdf0e10cSrcweir             aCtrlRegion.Union( maPage1Rect );
601cdf0e10cSrcweir             aCtrlRegion.Union( maPage2Rect );
602cdf0e10cSrcweir             aCtrlRegion.Union( maThumbRect );
603cdf0e10cSrcweir             bNativeOK = DrawNativeControl( CTRL_SCROLLBAR, (bHorz ? PART_DRAW_BACKGROUND_HORZ : PART_DRAW_BACKGROUND_VERT),
604cdf0e10cSrcweir                             aCtrlRegion, nState, scrValue, rtl::OUString() );
605cdf0e10cSrcweir         }
606cdf0e10cSrcweir         else
607cdf0e10cSrcweir       {
608cdf0e10cSrcweir         if ( (nDrawFlags & SCRBAR_DRAW_PAGE1) || (nDrawFlags & SCRBAR_DRAW_PAGE2) )
609cdf0e10cSrcweir         {
610cdf0e10cSrcweir             sal_uInt32	part1 = bHorz ? PART_TRACK_HORZ_LEFT : PART_TRACK_VERT_UPPER;
611cdf0e10cSrcweir             sal_uInt32	part2 = bHorz ? PART_TRACK_HORZ_RIGHT : PART_TRACK_VERT_LOWER;
612cdf0e10cSrcweir             Rectangle   aCtrlRegion1( maPage1Rect );
613cdf0e10cSrcweir             Rectangle   aCtrlRegion2( maPage2Rect );
614cdf0e10cSrcweir             ControlState nState1 = (IsEnabled() ? CTRL_STATE_ENABLED : 0) | (HasFocus() ? CTRL_STATE_FOCUSED : 0);
615cdf0e10cSrcweir             ControlState nState2 = nState1;
616cdf0e10cSrcweir 
617cdf0e10cSrcweir             nState1 |= ((mnStateFlags & SCRBAR_STATE_PAGE1_DOWN) ? CTRL_STATE_PRESSED : 0);
618cdf0e10cSrcweir             nState2 |= ((mnStateFlags & SCRBAR_STATE_PAGE2_DOWN) ? CTRL_STATE_PRESSED : 0);
619cdf0e10cSrcweir 
620cdf0e10cSrcweir             if( IsMouseOver() )
621cdf0e10cSrcweir             {
622cdf0e10cSrcweir                 Rectangle* pRect = ImplFindPartRect( GetPointerPosPixel() );
623cdf0e10cSrcweir                 if( pRect )
624cdf0e10cSrcweir                 {
625cdf0e10cSrcweir                     if( pRect == &maPage1Rect )
626cdf0e10cSrcweir                         nState1 |= CTRL_STATE_ROLLOVER;
627cdf0e10cSrcweir                     else if( pRect == &maPage2Rect )
628cdf0e10cSrcweir                         nState2 |= CTRL_STATE_ROLLOVER;
629cdf0e10cSrcweir                 }
630cdf0e10cSrcweir             }
631cdf0e10cSrcweir 
632cdf0e10cSrcweir             if ( nDrawFlags & SCRBAR_DRAW_PAGE1 )
633cdf0e10cSrcweir                 bNativeOK = DrawNativeControl( CTRL_SCROLLBAR, part1, aCtrlRegion1, nState1,
634cdf0e10cSrcweir                                 scrValue, rtl::OUString() );
635cdf0e10cSrcweir 
636cdf0e10cSrcweir             if ( nDrawFlags & SCRBAR_DRAW_PAGE2 )
637cdf0e10cSrcweir                 bNativeOK = DrawNativeControl( CTRL_SCROLLBAR, part2, aCtrlRegion2, nState2,
638cdf0e10cSrcweir                                 scrValue, rtl::OUString() );
639cdf0e10cSrcweir         }
640cdf0e10cSrcweir         if ( (nDrawFlags & SCRBAR_DRAW_BTN1) || (nDrawFlags & SCRBAR_DRAW_BTN2) )
641cdf0e10cSrcweir         {
642cdf0e10cSrcweir             sal_uInt32	part1 = bHorz ? PART_BUTTON_LEFT : PART_BUTTON_UP;
643cdf0e10cSrcweir             sal_uInt32	part2 = bHorz ? PART_BUTTON_RIGHT : PART_BUTTON_DOWN;
644cdf0e10cSrcweir             Rectangle  	aCtrlRegion1( maBtn1Rect );
645cdf0e10cSrcweir             Rectangle  	aCtrlRegion2( maBtn2Rect );
646cdf0e10cSrcweir             ControlState nState1 = HasFocus() ? CTRL_STATE_FOCUSED : 0;
647cdf0e10cSrcweir             ControlState nState2 = nState1;
648cdf0e10cSrcweir 
649cdf0e10cSrcweir             if ( !Window::IsEnabled() || !IsEnabled() )
650cdf0e10cSrcweir                 nState1 = (nState2 &= ~CTRL_STATE_ENABLED);
651cdf0e10cSrcweir             else
652cdf0e10cSrcweir                 nState1 = (nState2 |= CTRL_STATE_ENABLED);
653cdf0e10cSrcweir 
654cdf0e10cSrcweir             nState1 |= ((mnStateFlags & SCRBAR_STATE_BTN1_DOWN) ? CTRL_STATE_PRESSED : 0);
655cdf0e10cSrcweir             nState2 |= ((mnStateFlags & SCRBAR_STATE_BTN2_DOWN) ? CTRL_STATE_PRESSED : 0);
656cdf0e10cSrcweir 
657cdf0e10cSrcweir             if(mnStateFlags & SCRBAR_STATE_BTN1_DISABLE)
658cdf0e10cSrcweir                 nState1 &= ~CTRL_STATE_ENABLED;
659cdf0e10cSrcweir             if(mnStateFlags & SCRBAR_STATE_BTN2_DISABLE)
660cdf0e10cSrcweir                 nState2 &= ~CTRL_STATE_ENABLED;
661cdf0e10cSrcweir 
662cdf0e10cSrcweir             if( IsMouseOver() )
663cdf0e10cSrcweir             {
664cdf0e10cSrcweir                 Rectangle* pRect = ImplFindPartRect( GetPointerPosPixel() );
665cdf0e10cSrcweir                 if( pRect )
666cdf0e10cSrcweir                 {
667cdf0e10cSrcweir                     if( pRect == &maBtn1Rect )
668cdf0e10cSrcweir                         nState1 |= CTRL_STATE_ROLLOVER;
669cdf0e10cSrcweir                     else if( pRect == &maBtn2Rect )
670cdf0e10cSrcweir                         nState2 |= CTRL_STATE_ROLLOVER;
671cdf0e10cSrcweir                 }
672cdf0e10cSrcweir             }
673cdf0e10cSrcweir 
674cdf0e10cSrcweir             if ( nDrawFlags & SCRBAR_DRAW_BTN1 )
675cdf0e10cSrcweir                 bNativeOK = DrawNativeControl( CTRL_SCROLLBAR, part1, aCtrlRegion1, nState1,
676cdf0e10cSrcweir                                 scrValue, rtl::OUString() );
677cdf0e10cSrcweir 
678cdf0e10cSrcweir             if ( nDrawFlags & SCRBAR_DRAW_BTN2 )
679cdf0e10cSrcweir                 bNativeOK = DrawNativeControl( CTRL_SCROLLBAR, part2, aCtrlRegion2, nState2,
680cdf0e10cSrcweir                                 scrValue, rtl::OUString() );
681cdf0e10cSrcweir         }
682cdf0e10cSrcweir         if ( (nDrawFlags & SCRBAR_DRAW_THUMB) && !maThumbRect.IsEmpty() )
683cdf0e10cSrcweir         {
684cdf0e10cSrcweir             ControlState	nState = IsEnabled() ? CTRL_STATE_ENABLED : 0;
685cdf0e10cSrcweir             Rectangle		aCtrlRegion( maThumbRect );
686cdf0e10cSrcweir 
687cdf0e10cSrcweir             if ( mnStateFlags & SCRBAR_STATE_THUMB_DOWN )
688cdf0e10cSrcweir                 nState |= CTRL_STATE_PRESSED;
689cdf0e10cSrcweir 
690cdf0e10cSrcweir             if ( HasFocus() )
691cdf0e10cSrcweir                 nState |= CTRL_STATE_FOCUSED;
692cdf0e10cSrcweir 
693cdf0e10cSrcweir             if( IsMouseOver() )
694cdf0e10cSrcweir             {
695cdf0e10cSrcweir                 Rectangle* pRect = ImplFindPartRect( GetPointerPosPixel() );
696cdf0e10cSrcweir                 if( pRect )
697cdf0e10cSrcweir                 {
698cdf0e10cSrcweir                     if( pRect == &maThumbRect )
699cdf0e10cSrcweir                         nState |= CTRL_STATE_ROLLOVER;
700cdf0e10cSrcweir                 }
701cdf0e10cSrcweir             }
702cdf0e10cSrcweir 
703cdf0e10cSrcweir             bNativeOK = DrawNativeControl( CTRL_SCROLLBAR, (bHorz ? PART_THUMB_HORZ : PART_THUMB_VERT),
704cdf0e10cSrcweir                     aCtrlRegion, nState, scrValue, rtl::OUString() );
705cdf0e10cSrcweir         }
706cdf0e10cSrcweir       }
707cdf0e10cSrcweir     }
708cdf0e10cSrcweir     return bNativeOK;
709cdf0e10cSrcweir }
710cdf0e10cSrcweir 
ImplDraw(sal_uInt16 nDrawFlags,OutputDevice * pOutDev)711cdf0e10cSrcweir void ScrollBar::ImplDraw( sal_uInt16 nDrawFlags, OutputDevice* pOutDev )
712cdf0e10cSrcweir {
713cdf0e10cSrcweir     DecorationView          aDecoView( pOutDev );
714cdf0e10cSrcweir     Rectangle               aTempRect;
715cdf0e10cSrcweir     sal_uInt16                  nStyle;
716cdf0e10cSrcweir     const StyleSettings&    rStyleSettings = pOutDev->GetSettings().GetStyleSettings();
717cdf0e10cSrcweir     SymbolType              eSymbolType;
718cdf0e10cSrcweir     sal_Bool                    bEnabled = IsEnabled();
719cdf0e10cSrcweir 
720cdf0e10cSrcweir     // Evt. noch offene Berechnungen nachholen
721cdf0e10cSrcweir     if ( mbCalcSize )
722cdf0e10cSrcweir         ImplCalc( sal_False );
723cdf0e10cSrcweir 
724cdf0e10cSrcweir     Window *pWin = NULL;
725cdf0e10cSrcweir     if( pOutDev->GetOutDevType() == OUTDEV_WINDOW )
726cdf0e10cSrcweir         pWin = (Window*) pOutDev;
727cdf0e10cSrcweir 
728cdf0e10cSrcweir     // Draw the entire control if the native theme engine needs it
729cdf0e10cSrcweir     if ( nDrawFlags && pWin && pWin->IsNativeControlSupported(CTRL_SCROLLBAR, PART_DRAW_BACKGROUND_HORZ) )
730cdf0e10cSrcweir     {
731cdf0e10cSrcweir         ImplDrawNative( SCRBAR_DRAW_BACKGROUND );
732cdf0e10cSrcweir         return;
733cdf0e10cSrcweir     }
734cdf0e10cSrcweir 
735cdf0e10cSrcweir     if( (nDrawFlags & SCRBAR_DRAW_BTN1) && (!pWin || !ImplDrawNative( SCRBAR_DRAW_BTN1 ) ) )
736cdf0e10cSrcweir     {
737cdf0e10cSrcweir         nStyle = BUTTON_DRAW_NOLIGHTBORDER;
738cdf0e10cSrcweir         if ( mnStateFlags & SCRBAR_STATE_BTN1_DOWN )
739cdf0e10cSrcweir             nStyle |= BUTTON_DRAW_PRESSED;
740cdf0e10cSrcweir         aTempRect = aDecoView.DrawButton( maBtn1Rect, nStyle );
741cdf0e10cSrcweir         ImplCalcSymbolRect( aTempRect );
742cdf0e10cSrcweir         nStyle = 0;
743cdf0e10cSrcweir         if ( (mnStateFlags & SCRBAR_STATE_BTN1_DISABLE) || !bEnabled )
744cdf0e10cSrcweir             nStyle |= SYMBOL_DRAW_DISABLE;
745cdf0e10cSrcweir         if ( rStyleSettings.GetOptions() & STYLE_OPTION_SCROLLARROW )
746cdf0e10cSrcweir         {
747cdf0e10cSrcweir             if ( GetStyle() & WB_HORZ )
748cdf0e10cSrcweir                 eSymbolType = SYMBOL_ARROW_LEFT;
749cdf0e10cSrcweir             else
750cdf0e10cSrcweir                 eSymbolType = SYMBOL_ARROW_UP;
751cdf0e10cSrcweir         }
752cdf0e10cSrcweir         else
753cdf0e10cSrcweir         {
754cdf0e10cSrcweir             if ( GetStyle() & WB_HORZ )
755cdf0e10cSrcweir                 eSymbolType = SYMBOL_SPIN_LEFT;
756cdf0e10cSrcweir             else
757cdf0e10cSrcweir                 eSymbolType = SYMBOL_SPIN_UP;
758cdf0e10cSrcweir         }
759cdf0e10cSrcweir         aDecoView.DrawSymbol( aTempRect, eSymbolType, rStyleSettings.GetButtonTextColor(), nStyle );
760cdf0e10cSrcweir     }
761cdf0e10cSrcweir 
762cdf0e10cSrcweir     if ( (nDrawFlags & SCRBAR_DRAW_BTN2) && (!pWin || !ImplDrawNative( SCRBAR_DRAW_BTN2 ) ) )
763cdf0e10cSrcweir     {
764cdf0e10cSrcweir         nStyle = BUTTON_DRAW_NOLIGHTBORDER;
765cdf0e10cSrcweir         if ( mnStateFlags & SCRBAR_STATE_BTN2_DOWN )
766cdf0e10cSrcweir             nStyle |= BUTTON_DRAW_PRESSED;
767cdf0e10cSrcweir         aTempRect = aDecoView.DrawButton(  maBtn2Rect, nStyle );
768cdf0e10cSrcweir         ImplCalcSymbolRect( aTempRect );
769cdf0e10cSrcweir         nStyle = 0;
770cdf0e10cSrcweir         if ( (mnStateFlags & SCRBAR_STATE_BTN2_DISABLE) || !bEnabled )
771cdf0e10cSrcweir             nStyle |= SYMBOL_DRAW_DISABLE;
772cdf0e10cSrcweir         if ( rStyleSettings.GetOptions() & STYLE_OPTION_SCROLLARROW )
773cdf0e10cSrcweir         {
774cdf0e10cSrcweir             if ( GetStyle() & WB_HORZ )
775cdf0e10cSrcweir                 eSymbolType = SYMBOL_ARROW_RIGHT;
776cdf0e10cSrcweir             else
777cdf0e10cSrcweir                 eSymbolType = SYMBOL_ARROW_DOWN;
778cdf0e10cSrcweir         }
779cdf0e10cSrcweir         else
780cdf0e10cSrcweir         {
781cdf0e10cSrcweir             if ( GetStyle() & WB_HORZ )
782cdf0e10cSrcweir                 eSymbolType = SYMBOL_SPIN_RIGHT;
783cdf0e10cSrcweir             else
784cdf0e10cSrcweir                 eSymbolType = SYMBOL_SPIN_DOWN;
785cdf0e10cSrcweir         }
786cdf0e10cSrcweir         aDecoView.DrawSymbol( aTempRect, eSymbolType, rStyleSettings.GetButtonTextColor(), nStyle );
787cdf0e10cSrcweir     }
788cdf0e10cSrcweir 
789cdf0e10cSrcweir     pOutDev->SetLineColor();
790cdf0e10cSrcweir 
791cdf0e10cSrcweir     if ( (nDrawFlags & SCRBAR_DRAW_THUMB) && (!pWin || !ImplDrawNative( SCRBAR_DRAW_THUMB ) ) )
792cdf0e10cSrcweir     {
793cdf0e10cSrcweir         if ( !maThumbRect.IsEmpty() )
794cdf0e10cSrcweir         {
795cdf0e10cSrcweir             if ( bEnabled )
796cdf0e10cSrcweir             {
797cdf0e10cSrcweir                 nStyle = BUTTON_DRAW_NOLIGHTBORDER;
798cdf0e10cSrcweir                 aTempRect = aDecoView.DrawButton( maThumbRect, nStyle );
799cdf0e10cSrcweir             }
800cdf0e10cSrcweir             else
801cdf0e10cSrcweir             {
802cdf0e10cSrcweir                 pOutDev->SetFillColor( rStyleSettings.GetCheckedColor() );
803cdf0e10cSrcweir                 pOutDev->DrawRect( maThumbRect );
804cdf0e10cSrcweir             }
805cdf0e10cSrcweir         }
806cdf0e10cSrcweir     }
807cdf0e10cSrcweir 
808cdf0e10cSrcweir     if ( (nDrawFlags & SCRBAR_DRAW_PAGE1) && (!pWin || !ImplDrawNative( SCRBAR_DRAW_PAGE1 ) ) )
809cdf0e10cSrcweir     {
810cdf0e10cSrcweir         if ( mnStateFlags & SCRBAR_STATE_PAGE1_DOWN )
811cdf0e10cSrcweir             pOutDev->SetFillColor( rStyleSettings.GetShadowColor() );
812cdf0e10cSrcweir         else
813cdf0e10cSrcweir             pOutDev->SetFillColor( rStyleSettings.GetCheckedColor() );
814cdf0e10cSrcweir         pOutDev->DrawRect( maPage1Rect );
815cdf0e10cSrcweir     }
816cdf0e10cSrcweir     if ( (nDrawFlags & SCRBAR_DRAW_PAGE2) && (!pWin || !ImplDrawNative( SCRBAR_DRAW_PAGE2 ) ) )
817cdf0e10cSrcweir     {
818cdf0e10cSrcweir         if ( mnStateFlags & SCRBAR_STATE_PAGE2_DOWN )
819cdf0e10cSrcweir             pOutDev->SetFillColor( rStyleSettings.GetShadowColor() );
820cdf0e10cSrcweir         else
821cdf0e10cSrcweir             pOutDev->SetFillColor( rStyleSettings.GetCheckedColor() );
822cdf0e10cSrcweir         pOutDev->DrawRect( maPage2Rect );
823cdf0e10cSrcweir     }
824cdf0e10cSrcweir }
825cdf0e10cSrcweir 
826cdf0e10cSrcweir // -----------------------------------------------------------------------
827cdf0e10cSrcweir 
ImplScroll(long nNewPos,sal_Bool bCallEndScroll)828cdf0e10cSrcweir long ScrollBar::ImplScroll( long nNewPos, sal_Bool bCallEndScroll )
829cdf0e10cSrcweir {
830cdf0e10cSrcweir     long nOldPos = mnThumbPos;
831cdf0e10cSrcweir     SetThumbPos( nNewPos );
832cdf0e10cSrcweir     long nDelta = mnThumbPos-nOldPos;
833cdf0e10cSrcweir     if ( nDelta )
834cdf0e10cSrcweir     {
835cdf0e10cSrcweir         mnDelta = nDelta;
836cdf0e10cSrcweir         Scroll();
837cdf0e10cSrcweir         if ( bCallEndScroll )
838cdf0e10cSrcweir             EndScroll();
839cdf0e10cSrcweir         mnDelta = 0;
840cdf0e10cSrcweir     }
841cdf0e10cSrcweir     return nDelta;
842cdf0e10cSrcweir }
843cdf0e10cSrcweir 
844cdf0e10cSrcweir // -----------------------------------------------------------------------
845cdf0e10cSrcweir 
ImplDoAction(sal_Bool bCallEndScroll)846cdf0e10cSrcweir long ScrollBar::ImplDoAction( sal_Bool bCallEndScroll )
847cdf0e10cSrcweir {
848cdf0e10cSrcweir     long nDelta = 0;
849cdf0e10cSrcweir 
850cdf0e10cSrcweir     switch ( meScrollType )
851cdf0e10cSrcweir     {
852cdf0e10cSrcweir         case SCROLL_LINEUP:
853cdf0e10cSrcweir             nDelta = ImplScroll( mnThumbPos-mnLineSize, bCallEndScroll );
854cdf0e10cSrcweir             break;
855cdf0e10cSrcweir 
856cdf0e10cSrcweir         case SCROLL_LINEDOWN:
857cdf0e10cSrcweir             nDelta = ImplScroll( mnThumbPos+mnLineSize, bCallEndScroll );
858cdf0e10cSrcweir             break;
859cdf0e10cSrcweir 
860cdf0e10cSrcweir         case SCROLL_PAGEUP:
861cdf0e10cSrcweir             nDelta = ImplScroll( mnThumbPos-mnPageSize, bCallEndScroll );
862cdf0e10cSrcweir             break;
863cdf0e10cSrcweir 
864cdf0e10cSrcweir         case SCROLL_PAGEDOWN:
865cdf0e10cSrcweir             nDelta = ImplScroll( mnThumbPos+mnPageSize, bCallEndScroll );
866cdf0e10cSrcweir             break;
867cdf0e10cSrcweir         default:
868cdf0e10cSrcweir             ;
869cdf0e10cSrcweir     }
870cdf0e10cSrcweir 
871cdf0e10cSrcweir     return nDelta;
872cdf0e10cSrcweir }
873cdf0e10cSrcweir 
874cdf0e10cSrcweir // -----------------------------------------------------------------------
875cdf0e10cSrcweir 
ImplDoMouseAction(const Point & rMousePos,sal_Bool bCallAction)876cdf0e10cSrcweir void ScrollBar::ImplDoMouseAction( const Point& rMousePos, sal_Bool bCallAction )
877cdf0e10cSrcweir {
878cdf0e10cSrcweir     sal_uInt16  nOldStateFlags = mnStateFlags;
879cdf0e10cSrcweir     sal_Bool    bAction = sal_False;
880cdf0e10cSrcweir     sal_Bool    bHorizontal = ( GetStyle() & WB_HORZ )? sal_True: sal_False;
881cdf0e10cSrcweir     sal_Bool    bIsInside = sal_False;
882cdf0e10cSrcweir 
883cdf0e10cSrcweir     Point aPoint( 0, 0 );
884cdf0e10cSrcweir     Rectangle aControlRegion( aPoint, GetOutputSizePixel() );
885cdf0e10cSrcweir 
886cdf0e10cSrcweir     switch ( meScrollType )
887cdf0e10cSrcweir     {
888cdf0e10cSrcweir         case SCROLL_LINEUP:
889cdf0e10cSrcweir             if ( HitTestNativeControl( CTRL_SCROLLBAR, bHorizontal? PART_BUTTON_LEFT: PART_BUTTON_UP,
890cdf0e10cSrcweir                         aControlRegion, rMousePos, bIsInside )?
891cdf0e10cSrcweir                     bIsInside:
892cdf0e10cSrcweir                     maBtn1Rect.IsInside( rMousePos ) )
893cdf0e10cSrcweir             {
894cdf0e10cSrcweir                 bAction = bCallAction;
895cdf0e10cSrcweir                 mnStateFlags |= SCRBAR_STATE_BTN1_DOWN;
896cdf0e10cSrcweir             }
897cdf0e10cSrcweir             else
898cdf0e10cSrcweir                 mnStateFlags &= ~SCRBAR_STATE_BTN1_DOWN;
899cdf0e10cSrcweir             break;
900cdf0e10cSrcweir 
901cdf0e10cSrcweir         case SCROLL_LINEDOWN:
902cdf0e10cSrcweir             if ( HitTestNativeControl( CTRL_SCROLLBAR, bHorizontal? PART_BUTTON_RIGHT: PART_BUTTON_DOWN,
903cdf0e10cSrcweir                         aControlRegion, rMousePos, bIsInside )?
904cdf0e10cSrcweir                     bIsInside:
905cdf0e10cSrcweir                     maBtn2Rect.IsInside( rMousePos ) )
906cdf0e10cSrcweir             {
907cdf0e10cSrcweir                 bAction = bCallAction;
908cdf0e10cSrcweir                 mnStateFlags |= SCRBAR_STATE_BTN2_DOWN;
909cdf0e10cSrcweir             }
910cdf0e10cSrcweir             else
911cdf0e10cSrcweir                 mnStateFlags &= ~SCRBAR_STATE_BTN2_DOWN;
912cdf0e10cSrcweir             break;
913cdf0e10cSrcweir 
914cdf0e10cSrcweir         case SCROLL_PAGEUP:
915cdf0e10cSrcweir             // HitTestNativeControl, see remark at top of file
916cdf0e10cSrcweir             if ( HitTestNativeControl( CTRL_SCROLLBAR, bHorizontal? PART_TRACK_HORZ_LEFT: PART_TRACK_VERT_UPPER,
917cdf0e10cSrcweir                                        maPage1Rect, rMousePos, bIsInside )?
918cdf0e10cSrcweir                     bIsInside:
919cdf0e10cSrcweir                     maPage1Rect.IsInside( rMousePos ) )
920cdf0e10cSrcweir             {
921cdf0e10cSrcweir                 bAction = bCallAction;
922cdf0e10cSrcweir                 mnStateFlags |= SCRBAR_STATE_PAGE1_DOWN;
923cdf0e10cSrcweir             }
924cdf0e10cSrcweir             else
925cdf0e10cSrcweir                 mnStateFlags &= ~SCRBAR_STATE_PAGE1_DOWN;
926cdf0e10cSrcweir             break;
927cdf0e10cSrcweir 
928cdf0e10cSrcweir         case SCROLL_PAGEDOWN:
929cdf0e10cSrcweir             // HitTestNativeControl, see remark at top of file
930cdf0e10cSrcweir             if ( HitTestNativeControl( CTRL_SCROLLBAR, bHorizontal? PART_TRACK_HORZ_RIGHT: PART_TRACK_VERT_LOWER,
931cdf0e10cSrcweir                                        maPage2Rect, rMousePos, bIsInside )?
932cdf0e10cSrcweir                     bIsInside:
933cdf0e10cSrcweir                     maPage2Rect.IsInside( rMousePos ) )
934cdf0e10cSrcweir             {
935cdf0e10cSrcweir                 bAction = bCallAction;
936cdf0e10cSrcweir                 mnStateFlags |= SCRBAR_STATE_PAGE2_DOWN;
937cdf0e10cSrcweir             }
938cdf0e10cSrcweir             else
939cdf0e10cSrcweir                 mnStateFlags &= ~SCRBAR_STATE_PAGE2_DOWN;
940cdf0e10cSrcweir             break;
941cdf0e10cSrcweir         default:
942cdf0e10cSrcweir             ;
943cdf0e10cSrcweir     }
944cdf0e10cSrcweir 
945cdf0e10cSrcweir     if ( nOldStateFlags != mnStateFlags )
946cdf0e10cSrcweir         ImplDraw( mnDragDraw, this );
947cdf0e10cSrcweir     if ( bAction )
948cdf0e10cSrcweir         ImplDoAction( sal_False );
949cdf0e10cSrcweir }
950cdf0e10cSrcweir 
951cdf0e10cSrcweir // -----------------------------------------------------------------------
952cdf0e10cSrcweir 
ImplDragThumb(const Point & rMousePos)953cdf0e10cSrcweir void ScrollBar::ImplDragThumb( const Point& rMousePos )
954cdf0e10cSrcweir {
955cdf0e10cSrcweir     long nMovePix;
956cdf0e10cSrcweir     if ( GetStyle() & WB_HORZ )
957cdf0e10cSrcweir         nMovePix = rMousePos.X()-(maThumbRect.Left()+mnMouseOff);
958cdf0e10cSrcweir     else
959cdf0e10cSrcweir         nMovePix = rMousePos.Y()-(maThumbRect.Top()+mnMouseOff);
960cdf0e10cSrcweir 
961cdf0e10cSrcweir     // move thumb if necessary
962cdf0e10cSrcweir     if ( nMovePix )
963cdf0e10cSrcweir     {
964cdf0e10cSrcweir         mnThumbPixPos += nMovePix;
965cdf0e10cSrcweir         if ( mnThumbPixPos < 0 )
966cdf0e10cSrcweir             mnThumbPixPos = 0;
967cdf0e10cSrcweir         if ( mnThumbPixPos > (mnThumbPixRange-mnThumbPixSize) )
968cdf0e10cSrcweir             mnThumbPixPos = mnThumbPixRange-mnThumbPixSize;
969cdf0e10cSrcweir         long nOldPos = mnThumbPos;
970cdf0e10cSrcweir         mnThumbPos = ImplCalcThumbPos( mnThumbPixPos );
971cdf0e10cSrcweir         ImplUpdateRects();
972cdf0e10cSrcweir         if ( mbFullDrag && (nOldPos != mnThumbPos) )
973cdf0e10cSrcweir         {
974cdf0e10cSrcweir             mnDelta = mnThumbPos-nOldPos;
975cdf0e10cSrcweir             Scroll();
976cdf0e10cSrcweir             mnDelta = 0;
977cdf0e10cSrcweir         }
978cdf0e10cSrcweir     }
979cdf0e10cSrcweir }
980cdf0e10cSrcweir 
981cdf0e10cSrcweir // -----------------------------------------------------------------------
982cdf0e10cSrcweir 
MouseButtonDown(const MouseEvent & rMEvt)983cdf0e10cSrcweir void ScrollBar::MouseButtonDown( const MouseEvent& rMEvt )
984cdf0e10cSrcweir {
985cdf0e10cSrcweir     if ( rMEvt.IsLeft() || rMEvt.IsMiddle() )
986cdf0e10cSrcweir     {
987cdf0e10cSrcweir         const Point&    rMousePos = rMEvt.GetPosPixel();
988cdf0e10cSrcweir         sal_uInt16          nTrackFlags = 0;
989cdf0e10cSrcweir         sal_Bool            bHorizontal = ( GetStyle() & WB_HORZ )? sal_True: sal_False;
990cdf0e10cSrcweir         sal_Bool            bIsInside = sal_False;
991cdf0e10cSrcweir         sal_Bool            bDragToMouse = sal_False;
992cdf0e10cSrcweir 
993cdf0e10cSrcweir         Point aPoint( 0, 0 );
994cdf0e10cSrcweir         Rectangle aControlRegion( aPoint, GetOutputSizePixel() );
995cdf0e10cSrcweir 
996cdf0e10cSrcweir         if ( HitTestNativeControl( CTRL_SCROLLBAR, bHorizontal? PART_BUTTON_LEFT: PART_BUTTON_UP,
997cdf0e10cSrcweir                     aControlRegion, rMousePos, bIsInside )?
998cdf0e10cSrcweir                 bIsInside:
999cdf0e10cSrcweir                 maBtn1Rect.IsInside( rMousePos ) )
1000cdf0e10cSrcweir         {
1001cdf0e10cSrcweir             if ( !(mnStateFlags & SCRBAR_STATE_BTN1_DISABLE) )
1002cdf0e10cSrcweir             {
1003cdf0e10cSrcweir                 nTrackFlags     = STARTTRACK_BUTTONREPEAT;
1004cdf0e10cSrcweir                 meScrollType    = SCROLL_LINEUP;
1005cdf0e10cSrcweir                 mnDragDraw      = SCRBAR_DRAW_BTN1;
1006cdf0e10cSrcweir             }
1007cdf0e10cSrcweir             else
1008cdf0e10cSrcweir                 Sound::Beep( SOUND_DISABLE, this );
1009cdf0e10cSrcweir         }
1010cdf0e10cSrcweir         else if ( HitTestNativeControl( CTRL_SCROLLBAR, bHorizontal? PART_BUTTON_RIGHT: PART_BUTTON_DOWN,
1011cdf0e10cSrcweir                     aControlRegion, rMousePos, bIsInside )?
1012cdf0e10cSrcweir                 bIsInside:
1013cdf0e10cSrcweir                 maBtn2Rect.IsInside( rMousePos ) )
1014cdf0e10cSrcweir         {
1015cdf0e10cSrcweir             if ( !(mnStateFlags & SCRBAR_STATE_BTN2_DISABLE) )
1016cdf0e10cSrcweir             {
1017cdf0e10cSrcweir                 nTrackFlags     = STARTTRACK_BUTTONREPEAT;
1018cdf0e10cSrcweir                 meScrollType    = SCROLL_LINEDOWN;
1019cdf0e10cSrcweir                 mnDragDraw      = SCRBAR_DRAW_BTN2;
1020cdf0e10cSrcweir             }
1021cdf0e10cSrcweir             else
1022cdf0e10cSrcweir                 Sound::Beep( SOUND_DISABLE, this );
1023cdf0e10cSrcweir         }
1024cdf0e10cSrcweir         else
1025cdf0e10cSrcweir         {
1026cdf0e10cSrcweir             bool bThumbHit = HitTestNativeControl( CTRL_SCROLLBAR, bHorizontal? PART_THUMB_HORZ : PART_THUMB_VERT,
1027cdf0e10cSrcweir                                                    maThumbRect, rMousePos, bIsInside )
1028cdf0e10cSrcweir                              ? bIsInside : maThumbRect.IsInside( rMousePos );
1029cdf0e10cSrcweir             bool bDragHandling = rMEvt.IsMiddle() || bThumbHit || ImplGetSVData()->maNWFData.mbScrollbarJumpPage;
1030cdf0e10cSrcweir             if( bDragHandling )
1031cdf0e10cSrcweir             {
1032cdf0e10cSrcweir                 if( mpData )
1033cdf0e10cSrcweir                 {
1034cdf0e10cSrcweir                     mpData->mbHide = sal_True;  // disable focus blinking
1035cdf0e10cSrcweir                     if( HasFocus() )
1036cdf0e10cSrcweir                         ImplDraw( SCRBAR_DRAW_THUMB, this ); // paint without focus
1037cdf0e10cSrcweir                 }
1038cdf0e10cSrcweir 
1039cdf0e10cSrcweir                 if ( mnVisibleSize < mnMaxRange-mnMinRange )
1040cdf0e10cSrcweir                 {
1041cdf0e10cSrcweir                     nTrackFlags     = 0;
1042cdf0e10cSrcweir                     meScrollType    = SCROLL_DRAG;
1043cdf0e10cSrcweir                     mnDragDraw      = SCRBAR_DRAW_THUMB;
1044cdf0e10cSrcweir 
1045cdf0e10cSrcweir                     // calculate mouse offset
1046cdf0e10cSrcweir                     if( rMEvt.IsMiddle() || (ImplGetSVData()->maNWFData.mbScrollbarJumpPage && !bThumbHit) )
1047cdf0e10cSrcweir                     {
1048cdf0e10cSrcweir                         bDragToMouse = sal_True;
1049cdf0e10cSrcweir                         if ( GetStyle() & WB_HORZ )
1050cdf0e10cSrcweir                             mnMouseOff = maThumbRect.GetWidth()/2;
1051cdf0e10cSrcweir                         else
1052cdf0e10cSrcweir                             mnMouseOff = maThumbRect.GetHeight()/2;
1053cdf0e10cSrcweir                     }
1054cdf0e10cSrcweir                     else
1055cdf0e10cSrcweir                     {
1056cdf0e10cSrcweir                         if ( GetStyle() & WB_HORZ )
1057cdf0e10cSrcweir                             mnMouseOff = rMousePos.X()-maThumbRect.Left();
1058cdf0e10cSrcweir                         else
1059cdf0e10cSrcweir                             mnMouseOff = rMousePos.Y()-maThumbRect.Top();
1060cdf0e10cSrcweir                     }
1061cdf0e10cSrcweir 
1062cdf0e10cSrcweir                     mnStateFlags |= SCRBAR_STATE_THUMB_DOWN;
1063cdf0e10cSrcweir                     ImplDraw( mnDragDraw, this );
1064cdf0e10cSrcweir                 }
1065cdf0e10cSrcweir                 else
1066cdf0e10cSrcweir                     Sound::Beep( SOUND_DISABLE, this );
1067cdf0e10cSrcweir             }
1068cdf0e10cSrcweir             else if( HitTestNativeControl( CTRL_SCROLLBAR, bHorizontal? PART_TRACK_HORZ_AREA : PART_TRACK_VERT_AREA,
1069cdf0e10cSrcweir                                            aControlRegion, rMousePos, bIsInside )?
1070cdf0e10cSrcweir                 bIsInside : sal_True )
1071cdf0e10cSrcweir             {
1072cdf0e10cSrcweir                 nTrackFlags = STARTTRACK_BUTTONREPEAT;
1073cdf0e10cSrcweir 
1074cdf0e10cSrcweir                 // HitTestNativeControl, see remark at top of file
1075cdf0e10cSrcweir                 if ( HitTestNativeControl( CTRL_SCROLLBAR, bHorizontal? PART_TRACK_HORZ_LEFT : PART_TRACK_VERT_UPPER,
1076cdf0e10cSrcweir                                            maPage1Rect, rMousePos, bIsInside )?
1077cdf0e10cSrcweir                     bIsInside:
1078cdf0e10cSrcweir                     maPage1Rect.IsInside( rMousePos ) )
1079cdf0e10cSrcweir                 {
1080cdf0e10cSrcweir                     meScrollType    = SCROLL_PAGEUP;
1081cdf0e10cSrcweir                     mnDragDraw      = SCRBAR_DRAW_PAGE1;
1082cdf0e10cSrcweir                 }
1083cdf0e10cSrcweir                 else
1084cdf0e10cSrcweir                 {
1085cdf0e10cSrcweir                     meScrollType    = SCROLL_PAGEDOWN;
1086cdf0e10cSrcweir                     mnDragDraw      = SCRBAR_DRAW_PAGE2;
1087cdf0e10cSrcweir                 }
1088cdf0e10cSrcweir             }
1089cdf0e10cSrcweir         }
1090cdf0e10cSrcweir 
1091cdf0e10cSrcweir         // Soll Tracking gestartet werden
1092cdf0e10cSrcweir         if ( meScrollType != SCROLL_DONTKNOW )
1093cdf0e10cSrcweir         {
1094cdf0e10cSrcweir             // remember original position in case of abort or EndScroll-Delta
1095cdf0e10cSrcweir             mnStartPos = mnThumbPos;
1096cdf0e10cSrcweir             // #92906# Call StartTracking() before ImplDoMouseAction(), otherwise
1097cdf0e10cSrcweir             // MouseButtonUp() / EndTracking() may be called if somebody is spending
1098cdf0e10cSrcweir             // a lot of time in the scroll handler
1099cdf0e10cSrcweir             StartTracking( nTrackFlags );
1100cdf0e10cSrcweir             ImplDoMouseAction( rMousePos );
1101cdf0e10cSrcweir 
1102cdf0e10cSrcweir             if( bDragToMouse )
1103cdf0e10cSrcweir                 ImplDragThumb( rMousePos );
1104cdf0e10cSrcweir         }
1105cdf0e10cSrcweir     }
1106cdf0e10cSrcweir }
1107cdf0e10cSrcweir 
1108cdf0e10cSrcweir // -----------------------------------------------------------------------
1109cdf0e10cSrcweir 
Tracking(const TrackingEvent & rTEvt)1110cdf0e10cSrcweir void ScrollBar::Tracking( const TrackingEvent& rTEvt )
1111cdf0e10cSrcweir {
1112cdf0e10cSrcweir     if ( rTEvt.IsTrackingEnded() )
1113cdf0e10cSrcweir     {
1114cdf0e10cSrcweir         // Button und PageRect-Status wieder herstellen
1115cdf0e10cSrcweir         sal_uInt16 nOldStateFlags = mnStateFlags;
1116cdf0e10cSrcweir         mnStateFlags &= ~(SCRBAR_STATE_BTN1_DOWN | SCRBAR_STATE_BTN2_DOWN |
1117cdf0e10cSrcweir                           SCRBAR_STATE_PAGE1_DOWN | SCRBAR_STATE_PAGE2_DOWN |
1118cdf0e10cSrcweir                           SCRBAR_STATE_THUMB_DOWN);
1119cdf0e10cSrcweir         if ( nOldStateFlags != mnStateFlags )
1120cdf0e10cSrcweir             ImplDraw( mnDragDraw, this );
1121cdf0e10cSrcweir         mnDragDraw = 0;
1122cdf0e10cSrcweir 
1123cdf0e10cSrcweir         // Bei Abbruch, die alte ThumbPosition wieder herstellen
1124cdf0e10cSrcweir         if ( rTEvt.IsTrackingCanceled() )
1125cdf0e10cSrcweir         {
1126cdf0e10cSrcweir             long nOldPos = mnThumbPos;
1127cdf0e10cSrcweir             SetThumbPos( mnStartPos );
1128cdf0e10cSrcweir             mnDelta = mnThumbPos-nOldPos;
1129cdf0e10cSrcweir             Scroll();
1130cdf0e10cSrcweir         }
1131cdf0e10cSrcweir 
1132cdf0e10cSrcweir         if ( meScrollType == SCROLL_DRAG )
1133cdf0e10cSrcweir         {
1134cdf0e10cSrcweir             // Wenn gedragt wurde, berechnen wir den Thumb neu, damit
1135cdf0e10cSrcweir             // er wieder auf einer gerundeten ThumbPosition steht
1136cdf0e10cSrcweir             ImplCalc();
1137cdf0e10cSrcweir 
1138cdf0e10cSrcweir             if ( !mbFullDrag && (mnStartPos != mnThumbPos) )
1139cdf0e10cSrcweir             {
1140cdf0e10cSrcweir                 mnDelta = mnThumbPos-mnStartPos;
1141cdf0e10cSrcweir                 Scroll();
1142cdf0e10cSrcweir                 mnDelta = 0;
1143cdf0e10cSrcweir             }
1144cdf0e10cSrcweir         }
1145cdf0e10cSrcweir 
1146cdf0e10cSrcweir         mnDelta = mnThumbPos-mnStartPos;
1147cdf0e10cSrcweir         EndScroll();
1148cdf0e10cSrcweir         mnDelta = 0;
1149cdf0e10cSrcweir         meScrollType = SCROLL_DONTKNOW;
1150cdf0e10cSrcweir 
1151cdf0e10cSrcweir         if( mpData )
1152cdf0e10cSrcweir             mpData->mbHide = sal_False; // re-enable focus blinking
1153cdf0e10cSrcweir     }
1154cdf0e10cSrcweir     else
1155cdf0e10cSrcweir     {
1156cdf0e10cSrcweir         const Point rMousePos = rTEvt.GetMouseEvent().GetPosPixel();
1157cdf0e10cSrcweir 
1158cdf0e10cSrcweir         // Dragging wird speziell behandelt
1159cdf0e10cSrcweir         if ( meScrollType == SCROLL_DRAG )
1160cdf0e10cSrcweir             ImplDragThumb( rMousePos );
1161cdf0e10cSrcweir         else
1162cdf0e10cSrcweir             ImplDoMouseAction( rMousePos, rTEvt.IsTrackingRepeat() );
1163cdf0e10cSrcweir 
1164cdf0e10cSrcweir         // Wenn ScrollBar-Werte so umgesetzt wurden, das es nichts
1165cdf0e10cSrcweir         // mehr zum Tracking gibt, dann berechen wir hier ab
1166cdf0e10cSrcweir         if ( !IsVisible() || (mnVisibleSize >= (mnMaxRange-mnMinRange)) )
1167cdf0e10cSrcweir             EndTracking();
1168cdf0e10cSrcweir     }
1169cdf0e10cSrcweir }
1170cdf0e10cSrcweir 
1171cdf0e10cSrcweir // -----------------------------------------------------------------------
1172cdf0e10cSrcweir 
KeyInput(const KeyEvent & rKEvt)1173cdf0e10cSrcweir void ScrollBar::KeyInput( const KeyEvent& rKEvt )
1174cdf0e10cSrcweir {
1175cdf0e10cSrcweir     if ( !rKEvt.GetKeyCode().GetModifier() )
1176cdf0e10cSrcweir     {
1177cdf0e10cSrcweir         switch ( rKEvt.GetKeyCode().GetCode() )
1178cdf0e10cSrcweir         {
1179cdf0e10cSrcweir             case KEY_HOME:
1180cdf0e10cSrcweir                 DoScroll( 0 );
1181cdf0e10cSrcweir                 break;
1182cdf0e10cSrcweir 
1183cdf0e10cSrcweir             case KEY_END:
1184cdf0e10cSrcweir                 DoScroll( GetRangeMax() );
1185cdf0e10cSrcweir                 break;
1186cdf0e10cSrcweir 
1187cdf0e10cSrcweir             case KEY_LEFT:
1188cdf0e10cSrcweir             case KEY_UP:
1189cdf0e10cSrcweir                 DoScrollAction( SCROLL_LINEUP );
1190cdf0e10cSrcweir                 break;
1191cdf0e10cSrcweir 
1192cdf0e10cSrcweir             case KEY_RIGHT:
1193cdf0e10cSrcweir             case KEY_DOWN:
1194cdf0e10cSrcweir                 DoScrollAction( SCROLL_LINEDOWN );
1195cdf0e10cSrcweir                 break;
1196cdf0e10cSrcweir 
1197cdf0e10cSrcweir             case KEY_PAGEUP:
1198cdf0e10cSrcweir                 DoScrollAction( SCROLL_PAGEUP );
1199cdf0e10cSrcweir                 break;
1200cdf0e10cSrcweir 
1201cdf0e10cSrcweir             case KEY_PAGEDOWN:
1202cdf0e10cSrcweir                 DoScrollAction( SCROLL_PAGEDOWN );
1203cdf0e10cSrcweir                 break;
1204cdf0e10cSrcweir 
1205cdf0e10cSrcweir             default:
1206cdf0e10cSrcweir                 Control::KeyInput( rKEvt );
1207cdf0e10cSrcweir                 break;
1208cdf0e10cSrcweir         }
1209cdf0e10cSrcweir     }
1210cdf0e10cSrcweir     else
1211cdf0e10cSrcweir         Control::KeyInput( rKEvt );
1212cdf0e10cSrcweir }
1213cdf0e10cSrcweir 
1214cdf0e10cSrcweir // -----------------------------------------------------------------------
1215cdf0e10cSrcweir 
Paint(const Rectangle &)1216cdf0e10cSrcweir void ScrollBar::Paint( const Rectangle& )
1217cdf0e10cSrcweir {
1218cdf0e10cSrcweir     ImplDraw( SCRBAR_DRAW_ALL, this );
1219cdf0e10cSrcweir }
1220cdf0e10cSrcweir 
1221cdf0e10cSrcweir // -----------------------------------------------------------------------
1222cdf0e10cSrcweir 
Resize()1223cdf0e10cSrcweir void ScrollBar::Resize()
1224cdf0e10cSrcweir {
1225cdf0e10cSrcweir     Control::Resize();
1226cdf0e10cSrcweir     mbCalcSize = sal_True;
1227cdf0e10cSrcweir     if ( IsReallyVisible() )
1228cdf0e10cSrcweir         ImplCalc( sal_False );
1229cdf0e10cSrcweir     Invalidate();
1230cdf0e10cSrcweir }
1231cdf0e10cSrcweir 
1232cdf0e10cSrcweir // -----------------------------------------------------------------------
1233cdf0e10cSrcweir 
IMPL_LINK(ScrollBar,ImplAutoTimerHdl,AutoTimer *,EMPTYARG)1234cdf0e10cSrcweir IMPL_LINK( ScrollBar, ImplAutoTimerHdl, AutoTimer*, EMPTYARG )
1235cdf0e10cSrcweir {
1236cdf0e10cSrcweir     if( mpData && mpData->mbHide )
1237cdf0e10cSrcweir         return 0;
1238cdf0e10cSrcweir     ImplInvert();
1239cdf0e10cSrcweir     return 0;
1240cdf0e10cSrcweir }
1241cdf0e10cSrcweir 
ImplInvert()1242cdf0e10cSrcweir void ScrollBar::ImplInvert()
1243cdf0e10cSrcweir {
1244cdf0e10cSrcweir     Rectangle aRect( maThumbRect );
1245cdf0e10cSrcweir     if( aRect.getWidth() > 4 )
1246cdf0e10cSrcweir     {
1247cdf0e10cSrcweir         aRect.Left() += 2;
1248cdf0e10cSrcweir         aRect.Right() -= 2;
1249cdf0e10cSrcweir     }
1250cdf0e10cSrcweir     if( aRect.getHeight() > 4 )
1251cdf0e10cSrcweir     {
1252cdf0e10cSrcweir         aRect.Top() += 2;
1253cdf0e10cSrcweir         aRect.Bottom() -= 2;
1254cdf0e10cSrcweir     }
1255cdf0e10cSrcweir 
1256cdf0e10cSrcweir     Invert( aRect, 0 );
1257cdf0e10cSrcweir }
1258cdf0e10cSrcweir 
1259cdf0e10cSrcweir // -----------------------------------------------------------------------
1260cdf0e10cSrcweir 
GetFocus()1261cdf0e10cSrcweir void ScrollBar::GetFocus()
1262cdf0e10cSrcweir {
1263cdf0e10cSrcweir     if( !mpData )
1264cdf0e10cSrcweir     {
1265cdf0e10cSrcweir 	    mpData = new ImplScrollBarData;
1266cdf0e10cSrcweir 		mpData->maTimer.SetTimeoutHdl( LINK( this, ScrollBar, ImplAutoTimerHdl ) );
1267cdf0e10cSrcweir         mpData->mbHide = sal_False;
1268cdf0e10cSrcweir     }
1269cdf0e10cSrcweir     ImplInvert();   // react immediately
1270cdf0e10cSrcweir 	mpData->maTimer.SetTimeout( GetSettings().GetStyleSettings().GetCursorBlinkTime() );
1271cdf0e10cSrcweir     mpData->maTimer.Start();
1272cdf0e10cSrcweir     Control::GetFocus();
1273cdf0e10cSrcweir }
1274cdf0e10cSrcweir 
1275cdf0e10cSrcweir // -----------------------------------------------------------------------
1276cdf0e10cSrcweir 
LoseFocus()1277cdf0e10cSrcweir void ScrollBar::LoseFocus()
1278cdf0e10cSrcweir {
1279cdf0e10cSrcweir     if( mpData )
1280cdf0e10cSrcweir         mpData->maTimer.Stop();
1281cdf0e10cSrcweir     ImplDraw( SCRBAR_DRAW_THUMB, this );
1282cdf0e10cSrcweir 
1283cdf0e10cSrcweir     Control::LoseFocus();
1284cdf0e10cSrcweir }
1285cdf0e10cSrcweir 
1286cdf0e10cSrcweir // -----------------------------------------------------------------------
1287cdf0e10cSrcweir 
StateChanged(StateChangedType nType)1288cdf0e10cSrcweir void ScrollBar::StateChanged( StateChangedType nType )
1289cdf0e10cSrcweir {
1290cdf0e10cSrcweir     Control::StateChanged( nType );
1291cdf0e10cSrcweir 
1292cdf0e10cSrcweir     if ( nType == STATE_CHANGE_INITSHOW )
1293cdf0e10cSrcweir         ImplCalc( sal_False );
1294cdf0e10cSrcweir     else if ( nType == STATE_CHANGE_DATA )
1295cdf0e10cSrcweir     {
1296cdf0e10cSrcweir         if ( IsReallyVisible() && IsUpdateMode() )
1297cdf0e10cSrcweir             ImplCalc( sal_True );
1298cdf0e10cSrcweir     }
1299cdf0e10cSrcweir     else if ( nType == STATE_CHANGE_UPDATEMODE )
1300cdf0e10cSrcweir     {
1301cdf0e10cSrcweir         if ( IsReallyVisible() && IsUpdateMode() )
1302cdf0e10cSrcweir         {
1303cdf0e10cSrcweir             ImplCalc( sal_False );
1304cdf0e10cSrcweir             Invalidate();
1305cdf0e10cSrcweir         }
1306cdf0e10cSrcweir     }
1307cdf0e10cSrcweir     else if ( nType == STATE_CHANGE_ENABLE )
1308cdf0e10cSrcweir     {
1309cdf0e10cSrcweir         if ( IsReallyVisible() && IsUpdateMode() )
1310cdf0e10cSrcweir             Invalidate();
1311cdf0e10cSrcweir     }
1312cdf0e10cSrcweir     else if ( nType == STATE_CHANGE_STYLE )
1313cdf0e10cSrcweir     {
1314cdf0e10cSrcweir         ImplInitStyle( GetStyle() );
1315cdf0e10cSrcweir         if ( IsReallyVisible() && IsUpdateMode() )
1316cdf0e10cSrcweir         {
1317cdf0e10cSrcweir             if ( (GetPrevStyle() & SCRBAR_VIEW_STYLE) !=
1318cdf0e10cSrcweir                  (GetStyle() & SCRBAR_VIEW_STYLE) )
1319cdf0e10cSrcweir             {
1320cdf0e10cSrcweir                 mbCalcSize = sal_True;
1321cdf0e10cSrcweir                 ImplCalc( sal_False );
1322cdf0e10cSrcweir                 Invalidate();
1323cdf0e10cSrcweir             }
1324cdf0e10cSrcweir         }
1325cdf0e10cSrcweir     }
1326cdf0e10cSrcweir }
1327cdf0e10cSrcweir 
1328cdf0e10cSrcweir // -----------------------------------------------------------------------
1329cdf0e10cSrcweir 
DataChanged(const DataChangedEvent & rDCEvt)1330cdf0e10cSrcweir void ScrollBar::DataChanged( const DataChangedEvent& rDCEvt )
1331cdf0e10cSrcweir {
1332cdf0e10cSrcweir     Control::DataChanged( rDCEvt );
1333cdf0e10cSrcweir 
1334cdf0e10cSrcweir     if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
1335cdf0e10cSrcweir          (rDCEvt.GetFlags() & SETTINGS_STYLE) )
1336cdf0e10cSrcweir     {
1337cdf0e10cSrcweir         mbCalcSize = sal_True;
1338cdf0e10cSrcweir         ImplCalc( sal_False );
1339cdf0e10cSrcweir         Invalidate();
1340cdf0e10cSrcweir     }
1341cdf0e10cSrcweir }
1342cdf0e10cSrcweir 
1343cdf0e10cSrcweir // -----------------------------------------------------------------------
1344cdf0e10cSrcweir 
ImplFindPartRect(const Point & rPt)1345cdf0e10cSrcweir Rectangle* ScrollBar::ImplFindPartRect( const Point& rPt )
1346cdf0e10cSrcweir {
1347cdf0e10cSrcweir     sal_Bool    bHorizontal = ( GetStyle() & WB_HORZ )? sal_True: sal_False;
1348cdf0e10cSrcweir     sal_Bool    bIsInside = sal_False;
1349cdf0e10cSrcweir 
1350cdf0e10cSrcweir     Point aPoint( 0, 0 );
1351cdf0e10cSrcweir     Rectangle aControlRegion( aPoint, GetOutputSizePixel() );
1352cdf0e10cSrcweir 
1353cdf0e10cSrcweir     if( HitTestNativeControl( CTRL_SCROLLBAR, bHorizontal? PART_BUTTON_LEFT: PART_BUTTON_UP,
1354cdf0e10cSrcweir                 aControlRegion, rPt, bIsInside )?
1355cdf0e10cSrcweir             bIsInside:
1356cdf0e10cSrcweir             maBtn1Rect.IsInside( rPt ) )
1357cdf0e10cSrcweir         return &maBtn1Rect;
1358cdf0e10cSrcweir     else if( HitTestNativeControl( CTRL_SCROLLBAR, bHorizontal? PART_BUTTON_RIGHT: PART_BUTTON_DOWN,
1359cdf0e10cSrcweir                 aControlRegion, rPt, bIsInside )?
1360cdf0e10cSrcweir             bIsInside:
1361cdf0e10cSrcweir             maBtn2Rect.IsInside( rPt ) )
1362cdf0e10cSrcweir         return &maBtn2Rect;
1363cdf0e10cSrcweir     // HitTestNativeControl, see remark at top of file
1364cdf0e10cSrcweir     else if( HitTestNativeControl( CTRL_SCROLLBAR,  bHorizontal ? PART_TRACK_HORZ_LEFT : PART_TRACK_VERT_UPPER,
1365cdf0e10cSrcweir                 maPage1Rect, rPt, bIsInside)?
1366cdf0e10cSrcweir             bIsInside:
1367cdf0e10cSrcweir             maPage1Rect.IsInside( rPt ) )
1368cdf0e10cSrcweir         return &maPage1Rect;
1369cdf0e10cSrcweir     // HitTestNativeControl, see remark at top of file
1370cdf0e10cSrcweir     else if( HitTestNativeControl( CTRL_SCROLLBAR,  bHorizontal ? PART_TRACK_HORZ_RIGHT : PART_TRACK_VERT_LOWER,
1371cdf0e10cSrcweir                 maPage2Rect, rPt, bIsInside)?
1372cdf0e10cSrcweir             bIsInside:
1373cdf0e10cSrcweir             maPage2Rect.IsInside( rPt ) )
1374cdf0e10cSrcweir         return &maPage2Rect;
1375cdf0e10cSrcweir     // HitTestNativeControl, see remark at top of file
1376cdf0e10cSrcweir     else if( HitTestNativeControl( CTRL_SCROLLBAR,  bHorizontal ? PART_THUMB_HORZ : PART_THUMB_VERT,
1377cdf0e10cSrcweir                 maThumbRect, rPt, bIsInside)?
1378cdf0e10cSrcweir              bIsInside:
1379cdf0e10cSrcweir              maThumbRect.IsInside( rPt ) )
1380cdf0e10cSrcweir         return &maThumbRect;
1381cdf0e10cSrcweir     else
1382cdf0e10cSrcweir         return NULL;
1383cdf0e10cSrcweir }
1384cdf0e10cSrcweir 
PreNotify(NotifyEvent & rNEvt)1385cdf0e10cSrcweir long ScrollBar::PreNotify( NotifyEvent& rNEvt )
1386cdf0e10cSrcweir {
1387cdf0e10cSrcweir     long nDone = 0;
1388cdf0e10cSrcweir     const MouseEvent* pMouseEvt = NULL;
1389cdf0e10cSrcweir 
1390cdf0e10cSrcweir     if( (rNEvt.GetType() == EVENT_MOUSEMOVE) && (pMouseEvt = rNEvt.GetMouseEvent()) != NULL )
1391cdf0e10cSrcweir     {
1392cdf0e10cSrcweir         if( !pMouseEvt->GetButtons() && !pMouseEvt->IsSynthetic() && !pMouseEvt->IsModifierChanged() )
1393cdf0e10cSrcweir         {
1394cdf0e10cSrcweir             // trigger redraw if mouse over state has changed
1395cdf0e10cSrcweir             if( IsNativeControlSupported(CTRL_SCROLLBAR, PART_ENTIRE_CONTROL) )
1396cdf0e10cSrcweir             {
1397cdf0e10cSrcweir                 Rectangle* pRect = ImplFindPartRect( GetPointerPosPixel() );
1398cdf0e10cSrcweir                 Rectangle* pLastRect = ImplFindPartRect( GetLastPointerPosPixel() );
1399cdf0e10cSrcweir                 if( pRect != pLastRect || pMouseEvt->IsLeaveWindow() || pMouseEvt->IsEnterWindow() )
1400cdf0e10cSrcweir                 {
1401cdf0e10cSrcweir                     Region aRgn( GetActiveClipRegion() );
1402cdf0e10cSrcweir                     Region aClipRegion;
1403cdf0e10cSrcweir 
1404cdf0e10cSrcweir                     if ( pRect )
1405cdf0e10cSrcweir                         aClipRegion.Union( *pRect );
1406cdf0e10cSrcweir                     if ( pLastRect )
1407cdf0e10cSrcweir                         aClipRegion.Union( *pLastRect );
1408cdf0e10cSrcweir 
1409cdf0e10cSrcweir                     // Support for 3-button scroll bars
1410cdf0e10cSrcweir                     sal_Bool bHas3Buttons = IsNativeControlSupported( CTRL_SCROLLBAR, HAS_THREE_BUTTONS );
1411cdf0e10cSrcweir                     if ( bHas3Buttons && ( pRect == &maBtn1Rect || pLastRect == &maBtn1Rect ) )
1412cdf0e10cSrcweir                     {
1413cdf0e10cSrcweir                         aClipRegion.Union( maBtn2Rect );
1414cdf0e10cSrcweir                     }
1415cdf0e10cSrcweir 
1416cdf0e10cSrcweir                     SetClipRegion( aClipRegion );
1417cdf0e10cSrcweir                     Paint( aClipRegion.GetBoundRect() );
1418cdf0e10cSrcweir 
1419cdf0e10cSrcweir                     SetClipRegion( aRgn );
1420cdf0e10cSrcweir                 }
1421cdf0e10cSrcweir             }
1422cdf0e10cSrcweir         }
1423cdf0e10cSrcweir     }
1424cdf0e10cSrcweir 
1425cdf0e10cSrcweir     return nDone ? nDone : Control::PreNotify(rNEvt);
1426cdf0e10cSrcweir }
1427cdf0e10cSrcweir 
1428cdf0e10cSrcweir // -----------------------------------------------------------------------
1429cdf0e10cSrcweir 
Scroll()1430cdf0e10cSrcweir void ScrollBar::Scroll()
1431cdf0e10cSrcweir {
1432cdf0e10cSrcweir     ImplCallEventListenersAndHandler( VCLEVENT_SCROLLBAR_SCROLL, maScrollHdl, this );
1433cdf0e10cSrcweir }
1434cdf0e10cSrcweir 
1435cdf0e10cSrcweir // -----------------------------------------------------------------------
1436cdf0e10cSrcweir 
EndScroll()1437cdf0e10cSrcweir void ScrollBar::EndScroll()
1438cdf0e10cSrcweir {
1439cdf0e10cSrcweir     ImplCallEventListenersAndHandler( VCLEVENT_SCROLLBAR_ENDSCROLL, maEndScrollHdl, this );
1440cdf0e10cSrcweir }
1441cdf0e10cSrcweir 
1442cdf0e10cSrcweir // -----------------------------------------------------------------------
1443cdf0e10cSrcweir 
DoScroll(long nNewPos)1444cdf0e10cSrcweir long ScrollBar::DoScroll( long nNewPos )
1445cdf0e10cSrcweir {
1446cdf0e10cSrcweir     if ( meScrollType != SCROLL_DONTKNOW )
1447cdf0e10cSrcweir         return 0;
1448cdf0e10cSrcweir 
1449cdf0e10cSrcweir     meScrollType = SCROLL_DRAG;
1450cdf0e10cSrcweir     long nDelta = ImplScroll( nNewPos, sal_True );
1451cdf0e10cSrcweir     meScrollType = SCROLL_DONTKNOW;
1452cdf0e10cSrcweir     return nDelta;
1453cdf0e10cSrcweir }
1454cdf0e10cSrcweir 
1455cdf0e10cSrcweir // -----------------------------------------------------------------------
1456cdf0e10cSrcweir 
DoScrollAction(ScrollType eScrollType)1457cdf0e10cSrcweir long ScrollBar::DoScrollAction( ScrollType eScrollType )
1458cdf0e10cSrcweir {
1459cdf0e10cSrcweir     if ( (meScrollType != SCROLL_DONTKNOW) ||
1460cdf0e10cSrcweir          (eScrollType == SCROLL_DONTKNOW) ||
1461cdf0e10cSrcweir          (eScrollType == SCROLL_DRAG) )
1462cdf0e10cSrcweir         return 0;
1463cdf0e10cSrcweir 
1464cdf0e10cSrcweir     meScrollType = eScrollType;
1465cdf0e10cSrcweir     long nDelta = ImplDoAction( sal_True );
1466cdf0e10cSrcweir     meScrollType = SCROLL_DONTKNOW;
1467cdf0e10cSrcweir     return nDelta;
1468cdf0e10cSrcweir }
1469cdf0e10cSrcweir 
1470cdf0e10cSrcweir // -----------------------------------------------------------------------
1471cdf0e10cSrcweir 
SetRangeMin(long nNewRange)1472cdf0e10cSrcweir void ScrollBar::SetRangeMin( long nNewRange )
1473cdf0e10cSrcweir {
1474cdf0e10cSrcweir     SetRange( Range( nNewRange, GetRangeMax() ) );
1475cdf0e10cSrcweir }
1476cdf0e10cSrcweir 
1477cdf0e10cSrcweir // -----------------------------------------------------------------------
1478cdf0e10cSrcweir 
SetRangeMax(long nNewRange)1479cdf0e10cSrcweir void ScrollBar::SetRangeMax( long nNewRange )
1480cdf0e10cSrcweir {
1481cdf0e10cSrcweir     SetRange( Range( GetRangeMin(), nNewRange ) );
1482cdf0e10cSrcweir }
1483cdf0e10cSrcweir 
1484cdf0e10cSrcweir // -----------------------------------------------------------------------
1485cdf0e10cSrcweir 
SetRange(const Range & rRange)1486cdf0e10cSrcweir void ScrollBar::SetRange( const Range& rRange )
1487cdf0e10cSrcweir {
1488cdf0e10cSrcweir     // Range einpassen
1489cdf0e10cSrcweir     Range aRange = rRange;
1490cdf0e10cSrcweir     aRange.Justify();
1491cdf0e10cSrcweir     long nNewMinRange = aRange.Min();
1492cdf0e10cSrcweir     long nNewMaxRange = aRange.Max();
1493cdf0e10cSrcweir 
1494cdf0e10cSrcweir     // Wenn Range sich unterscheidet, dann neuen setzen
1495cdf0e10cSrcweir     if ( (mnMinRange != nNewMinRange) ||
1496cdf0e10cSrcweir          (mnMaxRange != nNewMaxRange) )
1497cdf0e10cSrcweir     {
1498cdf0e10cSrcweir         mnMinRange = nNewMinRange;
1499cdf0e10cSrcweir         mnMaxRange = nNewMaxRange;
1500cdf0e10cSrcweir 
1501cdf0e10cSrcweir         // Thumb einpassen
1502cdf0e10cSrcweir         if ( mnThumbPos > mnMaxRange-mnVisibleSize )
1503cdf0e10cSrcweir             mnThumbPos = mnMaxRange-mnVisibleSize;
1504cdf0e10cSrcweir         if ( mnThumbPos < mnMinRange )
1505cdf0e10cSrcweir             mnThumbPos = mnMinRange;
1506cdf0e10cSrcweir 
1507cdf0e10cSrcweir         StateChanged( STATE_CHANGE_DATA );
1508cdf0e10cSrcweir     }
1509cdf0e10cSrcweir }
1510cdf0e10cSrcweir 
1511cdf0e10cSrcweir // -----------------------------------------------------------------------
1512cdf0e10cSrcweir 
SetThumbPos(long nNewThumbPos)1513cdf0e10cSrcweir void ScrollBar::SetThumbPos( long nNewThumbPos )
1514cdf0e10cSrcweir {
1515cdf0e10cSrcweir     if ( nNewThumbPos > mnMaxRange-mnVisibleSize )
1516cdf0e10cSrcweir         nNewThumbPos = mnMaxRange-mnVisibleSize;
1517cdf0e10cSrcweir     if ( nNewThumbPos < mnMinRange )
1518cdf0e10cSrcweir         nNewThumbPos = mnMinRange;
1519cdf0e10cSrcweir 
1520cdf0e10cSrcweir     if ( mnThumbPos != nNewThumbPos )
1521cdf0e10cSrcweir     {
1522cdf0e10cSrcweir         mnThumbPos = nNewThumbPos;
1523cdf0e10cSrcweir         StateChanged( STATE_CHANGE_DATA );
1524cdf0e10cSrcweir     }
1525cdf0e10cSrcweir }
1526cdf0e10cSrcweir 
1527cdf0e10cSrcweir // -----------------------------------------------------------------------
1528cdf0e10cSrcweir 
SetVisibleSize(long nNewSize)1529cdf0e10cSrcweir void ScrollBar::SetVisibleSize( long nNewSize )
1530cdf0e10cSrcweir {
1531cdf0e10cSrcweir     if ( mnVisibleSize != nNewSize )
1532cdf0e10cSrcweir     {
1533cdf0e10cSrcweir         mnVisibleSize = nNewSize;
1534cdf0e10cSrcweir 
1535cdf0e10cSrcweir         // Thumb einpassen
1536cdf0e10cSrcweir         if ( mnThumbPos > mnMaxRange-mnVisibleSize )
1537cdf0e10cSrcweir             mnThumbPos = mnMaxRange-mnVisibleSize;
1538cdf0e10cSrcweir         if ( mnThumbPos < mnMinRange )
1539cdf0e10cSrcweir             mnThumbPos = mnMinRange;
1540cdf0e10cSrcweir         StateChanged( STATE_CHANGE_DATA );
1541cdf0e10cSrcweir     }
1542cdf0e10cSrcweir }
1543cdf0e10cSrcweir 
1544cdf0e10cSrcweir // =======================================================================
1545cdf0e10cSrcweir 
ImplInit(Window * pParent,WinBits nStyle)1546cdf0e10cSrcweir void ScrollBarBox::ImplInit( Window* pParent, WinBits nStyle )
1547cdf0e10cSrcweir {
1548cdf0e10cSrcweir     Window::ImplInit( pParent, nStyle, NULL );
1549cdf0e10cSrcweir 
1550cdf0e10cSrcweir     const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
1551cdf0e10cSrcweir     long nScrollSize = rStyleSettings.GetScrollBarSize();
1552cdf0e10cSrcweir     SetSizePixel( Size( nScrollSize, nScrollSize ) );
1553cdf0e10cSrcweir     ImplInitSettings();
1554cdf0e10cSrcweir }
1555cdf0e10cSrcweir 
1556cdf0e10cSrcweir // -----------------------------------------------------------------------
1557cdf0e10cSrcweir 
ScrollBarBox(Window * pParent,WinBits nStyle)1558cdf0e10cSrcweir ScrollBarBox::ScrollBarBox( Window* pParent, WinBits nStyle ) :
1559cdf0e10cSrcweir     Window( WINDOW_SCROLLBARBOX )
1560cdf0e10cSrcweir {
1561cdf0e10cSrcweir     ImplInit( pParent, nStyle );
1562cdf0e10cSrcweir }
1563cdf0e10cSrcweir 
1564cdf0e10cSrcweir // -----------------------------------------------------------------------
1565cdf0e10cSrcweir 
ScrollBarBox(Window * pParent,const ResId & rResId)1566cdf0e10cSrcweir ScrollBarBox::ScrollBarBox( Window* pParent, const ResId& rResId ) :
1567cdf0e10cSrcweir     Window( WINDOW_SCROLLBARBOX )
1568cdf0e10cSrcweir {
1569cdf0e10cSrcweir     rResId.SetRT( RSC_SCROLLBAR );
1570cdf0e10cSrcweir     ImplInit( pParent, ImplInitRes( rResId ) );
1571cdf0e10cSrcweir     ImplLoadRes( rResId );
1572cdf0e10cSrcweir }
1573cdf0e10cSrcweir 
1574cdf0e10cSrcweir // -----------------------------------------------------------------------
1575cdf0e10cSrcweir 
ImplInitSettings()1576cdf0e10cSrcweir void ScrollBarBox::ImplInitSettings()
1577cdf0e10cSrcweir {
1578cdf0e10cSrcweir     // Hack, damit man auch DockingWindows ohne Hintergrund bauen kann
1579cdf0e10cSrcweir     // und noch nicht alles umgestellt ist
1580cdf0e10cSrcweir     if ( IsBackground() )
1581cdf0e10cSrcweir     {
1582cdf0e10cSrcweir         Color aColor;
1583cdf0e10cSrcweir         if ( IsControlBackground() )
1584cdf0e10cSrcweir             aColor = GetControlBackground();
1585cdf0e10cSrcweir         else
1586cdf0e10cSrcweir             aColor = GetSettings().GetStyleSettings().GetFaceColor();
1587cdf0e10cSrcweir         SetBackground( aColor );
1588cdf0e10cSrcweir     }
1589cdf0e10cSrcweir }
1590cdf0e10cSrcweir 
1591cdf0e10cSrcweir // -----------------------------------------------------------------------
1592cdf0e10cSrcweir 
StateChanged(StateChangedType nType)1593cdf0e10cSrcweir void ScrollBarBox::StateChanged( StateChangedType nType )
1594cdf0e10cSrcweir {
1595cdf0e10cSrcweir     Window::StateChanged( nType );
1596cdf0e10cSrcweir 
1597cdf0e10cSrcweir     if ( nType == STATE_CHANGE_CONTROLBACKGROUND )
1598cdf0e10cSrcweir     {
1599cdf0e10cSrcweir         ImplInitSettings();
1600cdf0e10cSrcweir         Invalidate();
1601cdf0e10cSrcweir     }
1602cdf0e10cSrcweir }
1603cdf0e10cSrcweir 
1604cdf0e10cSrcweir // -----------------------------------------------------------------------
1605cdf0e10cSrcweir 
DataChanged(const DataChangedEvent & rDCEvt)1606cdf0e10cSrcweir void ScrollBarBox::DataChanged( const DataChangedEvent& rDCEvt )
1607cdf0e10cSrcweir {
1608cdf0e10cSrcweir     Window::DataChanged( rDCEvt );
1609cdf0e10cSrcweir 
1610cdf0e10cSrcweir     if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
1611cdf0e10cSrcweir          (rDCEvt.GetFlags() & SETTINGS_STYLE) )
1612cdf0e10cSrcweir     {
1613cdf0e10cSrcweir         ImplInitSettings();
1614cdf0e10cSrcweir         Invalidate();
1615cdf0e10cSrcweir     }
1616cdf0e10cSrcweir }
1617