xref: /aoo41x/main/vcl/source/control/spinbtn.cxx (revision cdf0e10c)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_vcl.hxx"
30*cdf0e10cSrcweir #include <tools/rcid.h>
31*cdf0e10cSrcweir #include <vcl/spin.h>
32*cdf0e10cSrcweir #include <vcl/event.hxx>
33*cdf0e10cSrcweir #include <vcl/spin.hxx>
34*cdf0e10cSrcweir 
35*cdf0e10cSrcweir // =======================================================================
36*cdf0e10cSrcweir 
37*cdf0e10cSrcweir void SpinButton::ImplInit( Window* pParent, WinBits nStyle )
38*cdf0e10cSrcweir {
39*cdf0e10cSrcweir     mbUpperIn     = sal_False;
40*cdf0e10cSrcweir     mbLowerIn     = sal_False;
41*cdf0e10cSrcweir     mbInitialUp   = sal_False;
42*cdf0e10cSrcweir     mbInitialDown = sal_False;
43*cdf0e10cSrcweir 
44*cdf0e10cSrcweir     mnMinRange  = 0;
45*cdf0e10cSrcweir     mnMaxRange  = 100;
46*cdf0e10cSrcweir     mnValue     = 0;
47*cdf0e10cSrcweir     mnValueStep = 1;
48*cdf0e10cSrcweir 
49*cdf0e10cSrcweir     maRepeatTimer.SetTimeout( GetSettings().GetMouseSettings().GetButtonStartRepeat() );
50*cdf0e10cSrcweir     maRepeatTimer.SetTimeoutHdl( LINK( this, SpinButton, ImplTimeout ) );
51*cdf0e10cSrcweir 
52*cdf0e10cSrcweir     mbRepeat = 0 != ( nStyle & WB_REPEAT );
53*cdf0e10cSrcweir 
54*cdf0e10cSrcweir     if ( nStyle & WB_HSCROLL )
55*cdf0e10cSrcweir         mbHorz = sal_True;
56*cdf0e10cSrcweir     else
57*cdf0e10cSrcweir         mbHorz = sal_False;
58*cdf0e10cSrcweir 
59*cdf0e10cSrcweir     Control::ImplInit( pParent, nStyle, NULL );
60*cdf0e10cSrcweir }
61*cdf0e10cSrcweir 
62*cdf0e10cSrcweir // -----------------------------------------------------------------------
63*cdf0e10cSrcweir 
64*cdf0e10cSrcweir SpinButton::SpinButton( Window* pParent, WinBits nStyle )
65*cdf0e10cSrcweir     :Control( WINDOW_SPINBUTTON )
66*cdf0e10cSrcweir     ,mbUpperIsFocused( sal_False )
67*cdf0e10cSrcweir {
68*cdf0e10cSrcweir     ImplInit( pParent, nStyle );
69*cdf0e10cSrcweir }
70*cdf0e10cSrcweir 
71*cdf0e10cSrcweir // -----------------------------------------------------------------------
72*cdf0e10cSrcweir 
73*cdf0e10cSrcweir SpinButton::SpinButton( Window* pParent, const ResId& rResId )
74*cdf0e10cSrcweir     :Control( WINDOW_SPINBUTTON )
75*cdf0e10cSrcweir     ,mbUpperIsFocused( sal_False )
76*cdf0e10cSrcweir {
77*cdf0e10cSrcweir     rResId.SetRT( RSC_SPINBUTTON );
78*cdf0e10cSrcweir     ImplInit( pParent, ImplInitRes( rResId ) );
79*cdf0e10cSrcweir     ImplLoadRes( rResId );
80*cdf0e10cSrcweir     Resize();
81*cdf0e10cSrcweir }
82*cdf0e10cSrcweir 
83*cdf0e10cSrcweir // -----------------------------------------------------------------------
84*cdf0e10cSrcweir 
85*cdf0e10cSrcweir SpinButton::~SpinButton()
86*cdf0e10cSrcweir {
87*cdf0e10cSrcweir }
88*cdf0e10cSrcweir 
89*cdf0e10cSrcweir // -----------------------------------------------------------------------
90*cdf0e10cSrcweir 
91*cdf0e10cSrcweir IMPL_LINK( SpinButton, ImplTimeout, Timer*, pTimer )
92*cdf0e10cSrcweir {
93*cdf0e10cSrcweir     if ( pTimer->GetTimeout() == GetSettings().GetMouseSettings().GetButtonStartRepeat() )
94*cdf0e10cSrcweir     {
95*cdf0e10cSrcweir         pTimer->SetTimeout( GetSettings().GetMouseSettings().GetButtonRepeat() );
96*cdf0e10cSrcweir         pTimer->Start();
97*cdf0e10cSrcweir     }
98*cdf0e10cSrcweir     else
99*cdf0e10cSrcweir     {
100*cdf0e10cSrcweir         if ( mbInitialUp )
101*cdf0e10cSrcweir             Up();
102*cdf0e10cSrcweir         else
103*cdf0e10cSrcweir             Down();
104*cdf0e10cSrcweir     }
105*cdf0e10cSrcweir 
106*cdf0e10cSrcweir     return 0;
107*cdf0e10cSrcweir }
108*cdf0e10cSrcweir 
109*cdf0e10cSrcweir // -----------------------------------------------------------------------
110*cdf0e10cSrcweir 
111*cdf0e10cSrcweir void SpinButton::Up()
112*cdf0e10cSrcweir {
113*cdf0e10cSrcweir     if ( ImplIsUpperEnabled() )
114*cdf0e10cSrcweir     {
115*cdf0e10cSrcweir         mnValue += mnValueStep;
116*cdf0e10cSrcweir         StateChanged( STATE_CHANGE_DATA );
117*cdf0e10cSrcweir 
118*cdf0e10cSrcweir         ImplMoveFocus( sal_True );
119*cdf0e10cSrcweir     }
120*cdf0e10cSrcweir 
121*cdf0e10cSrcweir     ImplCallEventListenersAndHandler( VCLEVENT_SPINBUTTON_UP, maUpHdlLink, this );
122*cdf0e10cSrcweir }
123*cdf0e10cSrcweir 
124*cdf0e10cSrcweir // -----------------------------------------------------------------------
125*cdf0e10cSrcweir 
126*cdf0e10cSrcweir void SpinButton::Down()
127*cdf0e10cSrcweir {
128*cdf0e10cSrcweir     if ( ImplIsLowerEnabled() )
129*cdf0e10cSrcweir     {
130*cdf0e10cSrcweir         mnValue -= mnValueStep;
131*cdf0e10cSrcweir         StateChanged( STATE_CHANGE_DATA );
132*cdf0e10cSrcweir 
133*cdf0e10cSrcweir         ImplMoveFocus( sal_False );
134*cdf0e10cSrcweir     }
135*cdf0e10cSrcweir 
136*cdf0e10cSrcweir     ImplCallEventListenersAndHandler( VCLEVENT_SPINBUTTON_DOWN, maDownHdlLink, this );
137*cdf0e10cSrcweir }
138*cdf0e10cSrcweir 
139*cdf0e10cSrcweir // -----------------------------------------------------------------------
140*cdf0e10cSrcweir 
141*cdf0e10cSrcweir void SpinButton::Resize()
142*cdf0e10cSrcweir {
143*cdf0e10cSrcweir     Control::Resize();
144*cdf0e10cSrcweir 
145*cdf0e10cSrcweir     Size aSize( GetOutputSizePixel() );
146*cdf0e10cSrcweir 	Point aTmpPoint;
147*cdf0e10cSrcweir     Rectangle aRect( aTmpPoint, aSize );
148*cdf0e10cSrcweir     if ( mbHorz )
149*cdf0e10cSrcweir     {
150*cdf0e10cSrcweir         maLowerRect = Rectangle( 0, 0, aSize.Width()/2, aSize.Height()-1 );
151*cdf0e10cSrcweir         maUpperRect = Rectangle( maLowerRect.TopRight(), aRect.BottomRight() );
152*cdf0e10cSrcweir     }
153*cdf0e10cSrcweir     else
154*cdf0e10cSrcweir     {
155*cdf0e10cSrcweir         maUpperRect = Rectangle( 0, 0, aSize.Width()-1, aSize.Height()/2 );
156*cdf0e10cSrcweir         maLowerRect = Rectangle( maUpperRect.BottomLeft(), aRect.BottomRight() );
157*cdf0e10cSrcweir     }
158*cdf0e10cSrcweir 
159*cdf0e10cSrcweir     ImplCalcFocusRect( ImplIsUpperEnabled() || !ImplIsLowerEnabled() );
160*cdf0e10cSrcweir 
161*cdf0e10cSrcweir     Invalidate();
162*cdf0e10cSrcweir }
163*cdf0e10cSrcweir 
164*cdf0e10cSrcweir // -----------------------------------------------------------------------
165*cdf0e10cSrcweir 
166*cdf0e10cSrcweir void SpinButton::Draw( OutputDevice* pDev, const Point& rPos, const Size& rSize, sal_uLong nFlags )
167*cdf0e10cSrcweir {
168*cdf0e10cSrcweir     Point       aPos  = pDev->LogicToPixel( rPos );
169*cdf0e10cSrcweir     Size        aSize = pDev->LogicToPixel( rSize );
170*cdf0e10cSrcweir 
171*cdf0e10cSrcweir     pDev->Push();
172*cdf0e10cSrcweir     pDev->SetMapMode();
173*cdf0e10cSrcweir     if ( !(nFlags & WINDOW_DRAW_MONO) )
174*cdf0e10cSrcweir 	{
175*cdf0e10cSrcweir 		// DecoView uses the FaceColor...
176*cdf0e10cSrcweir 		AllSettings aSettings = pDev->GetSettings();
177*cdf0e10cSrcweir 		StyleSettings aStyleSettings = aSettings.GetStyleSettings();
178*cdf0e10cSrcweir 		if ( IsControlBackground() )
179*cdf0e10cSrcweir 			aStyleSettings.SetFaceColor( GetControlBackground() );
180*cdf0e10cSrcweir 		else
181*cdf0e10cSrcweir 			aStyleSettings.SetFaceColor( GetSettings().GetStyleSettings().GetFaceColor() );
182*cdf0e10cSrcweir 
183*cdf0e10cSrcweir 		aSettings.SetStyleSettings( aStyleSettings );
184*cdf0e10cSrcweir 		pDev->SetSettings( aSettings );
185*cdf0e10cSrcweir 	}
186*cdf0e10cSrcweir 
187*cdf0e10cSrcweir     Rectangle   aRect( Point( 0, 0 ), aSize );
188*cdf0e10cSrcweir     Rectangle aLowerRect, aUpperRect;
189*cdf0e10cSrcweir     if ( mbHorz )
190*cdf0e10cSrcweir     {
191*cdf0e10cSrcweir         aLowerRect = Rectangle( 0, 0, aSize.Width()/2, aSize.Height()-1 );
192*cdf0e10cSrcweir         aUpperRect = Rectangle( aLowerRect.TopRight(), aRect.BottomRight() );
193*cdf0e10cSrcweir     }
194*cdf0e10cSrcweir     else
195*cdf0e10cSrcweir     {
196*cdf0e10cSrcweir         aUpperRect = Rectangle( 0, 0, aSize.Width()-1, aSize.Height()/2 );
197*cdf0e10cSrcweir         aLowerRect = Rectangle( aUpperRect.BottomLeft(), aRect.BottomRight() );
198*cdf0e10cSrcweir     }
199*cdf0e10cSrcweir 
200*cdf0e10cSrcweir     aUpperRect += aPos;
201*cdf0e10cSrcweir     aLowerRect += aPos;
202*cdf0e10cSrcweir 
203*cdf0e10cSrcweir     ImplDrawSpinButton( pDev, aUpperRect, aLowerRect, sal_False, sal_False,
204*cdf0e10cSrcweir                         IsEnabled() && ImplIsUpperEnabled(),
205*cdf0e10cSrcweir                         IsEnabled() && ImplIsLowerEnabled(), mbHorz, sal_True );
206*cdf0e10cSrcweir     pDev->Pop();
207*cdf0e10cSrcweir }
208*cdf0e10cSrcweir 
209*cdf0e10cSrcweir 
210*cdf0e10cSrcweir void SpinButton::Paint( const Rectangle& )
211*cdf0e10cSrcweir {
212*cdf0e10cSrcweir     HideFocus();
213*cdf0e10cSrcweir 
214*cdf0e10cSrcweir     sal_Bool bEnable = IsEnabled();
215*cdf0e10cSrcweir     ImplDrawSpinButton( this, maUpperRect, maLowerRect, mbUpperIn, mbLowerIn,
216*cdf0e10cSrcweir                         bEnable && ImplIsUpperEnabled(),
217*cdf0e10cSrcweir                         bEnable && ImplIsLowerEnabled(), mbHorz, sal_True );
218*cdf0e10cSrcweir 
219*cdf0e10cSrcweir     if ( HasFocus() )
220*cdf0e10cSrcweir         ShowFocus( maFocusRect );
221*cdf0e10cSrcweir }
222*cdf0e10cSrcweir 
223*cdf0e10cSrcweir // -----------------------------------------------------------------------
224*cdf0e10cSrcweir 
225*cdf0e10cSrcweir void SpinButton::MouseButtonDown( const MouseEvent& rMEvt )
226*cdf0e10cSrcweir {
227*cdf0e10cSrcweir     if ( maUpperRect.IsInside( rMEvt.GetPosPixel() ) && ( ImplIsUpperEnabled() ) )
228*cdf0e10cSrcweir     {
229*cdf0e10cSrcweir         mbUpperIn   = sal_True;
230*cdf0e10cSrcweir         mbInitialUp = sal_True;
231*cdf0e10cSrcweir         Invalidate( maUpperRect );
232*cdf0e10cSrcweir     }
233*cdf0e10cSrcweir     else if ( maLowerRect.IsInside( rMEvt.GetPosPixel() ) && ( ImplIsLowerEnabled() ) )
234*cdf0e10cSrcweir     {
235*cdf0e10cSrcweir         mbLowerIn     = sal_True;
236*cdf0e10cSrcweir         mbInitialDown = sal_True;
237*cdf0e10cSrcweir         Invalidate( maLowerRect );
238*cdf0e10cSrcweir     }
239*cdf0e10cSrcweir 
240*cdf0e10cSrcweir     if ( mbUpperIn || mbLowerIn )
241*cdf0e10cSrcweir     {
242*cdf0e10cSrcweir         Update();
243*cdf0e10cSrcweir         CaptureMouse();
244*cdf0e10cSrcweir         if ( mbRepeat )
245*cdf0e10cSrcweir             maRepeatTimer.Start();
246*cdf0e10cSrcweir     }
247*cdf0e10cSrcweir }
248*cdf0e10cSrcweir 
249*cdf0e10cSrcweir // -----------------------------------------------------------------------
250*cdf0e10cSrcweir 
251*cdf0e10cSrcweir void SpinButton::MouseButtonUp( const MouseEvent& )
252*cdf0e10cSrcweir {
253*cdf0e10cSrcweir     ReleaseMouse();
254*cdf0e10cSrcweir     if ( mbRepeat )
255*cdf0e10cSrcweir     {
256*cdf0e10cSrcweir         maRepeatTimer.Stop();
257*cdf0e10cSrcweir         maRepeatTimer.SetTimeout(GetSettings().GetMouseSettings().GetButtonStartRepeat() );
258*cdf0e10cSrcweir     }
259*cdf0e10cSrcweir 
260*cdf0e10cSrcweir     if ( mbUpperIn )
261*cdf0e10cSrcweir     {
262*cdf0e10cSrcweir         mbUpperIn   = sal_False;
263*cdf0e10cSrcweir         Invalidate( maUpperRect );
264*cdf0e10cSrcweir         Update();
265*cdf0e10cSrcweir         Up();
266*cdf0e10cSrcweir     }
267*cdf0e10cSrcweir     else if ( mbLowerIn )
268*cdf0e10cSrcweir     {
269*cdf0e10cSrcweir         mbLowerIn = sal_False;
270*cdf0e10cSrcweir         Invalidate( maLowerRect );
271*cdf0e10cSrcweir         Update();
272*cdf0e10cSrcweir         Down();
273*cdf0e10cSrcweir     }
274*cdf0e10cSrcweir 
275*cdf0e10cSrcweir     mbInitialUp = mbInitialDown = sal_False;
276*cdf0e10cSrcweir }
277*cdf0e10cSrcweir 
278*cdf0e10cSrcweir // -----------------------------------------------------------------------
279*cdf0e10cSrcweir 
280*cdf0e10cSrcweir void SpinButton::MouseMove( const MouseEvent& rMEvt )
281*cdf0e10cSrcweir {
282*cdf0e10cSrcweir     if ( !rMEvt.IsLeft() || (!mbInitialUp && !mbInitialDown) )
283*cdf0e10cSrcweir         return;
284*cdf0e10cSrcweir 
285*cdf0e10cSrcweir     if ( !maUpperRect.IsInside( rMEvt.GetPosPixel() ) &&
286*cdf0e10cSrcweir          mbUpperIn && mbInitialUp )
287*cdf0e10cSrcweir     {
288*cdf0e10cSrcweir         mbUpperIn = sal_False;
289*cdf0e10cSrcweir         maRepeatTimer.Stop();
290*cdf0e10cSrcweir         Invalidate( maUpperRect );
291*cdf0e10cSrcweir         Update();
292*cdf0e10cSrcweir     }
293*cdf0e10cSrcweir     else if ( !maLowerRect.IsInside( rMEvt.GetPosPixel() ) &&
294*cdf0e10cSrcweir               mbLowerIn & mbInitialDown )
295*cdf0e10cSrcweir     {
296*cdf0e10cSrcweir         mbLowerIn = sal_False;
297*cdf0e10cSrcweir         maRepeatTimer.Stop();
298*cdf0e10cSrcweir         Invalidate( maLowerRect );
299*cdf0e10cSrcweir         Update();
300*cdf0e10cSrcweir     }
301*cdf0e10cSrcweir     else if ( maUpperRect.IsInside( rMEvt.GetPosPixel() ) &&
302*cdf0e10cSrcweir               !mbUpperIn && mbInitialUp )
303*cdf0e10cSrcweir     {
304*cdf0e10cSrcweir         mbUpperIn = sal_True;
305*cdf0e10cSrcweir         if ( mbRepeat )
306*cdf0e10cSrcweir             maRepeatTimer.Start();
307*cdf0e10cSrcweir         Invalidate( maUpperRect );
308*cdf0e10cSrcweir         Update();
309*cdf0e10cSrcweir     }
310*cdf0e10cSrcweir     else if ( maLowerRect.IsInside( rMEvt.GetPosPixel() ) &&
311*cdf0e10cSrcweir               !mbLowerIn && mbInitialDown )
312*cdf0e10cSrcweir     {
313*cdf0e10cSrcweir         mbLowerIn = sal_True;
314*cdf0e10cSrcweir         if ( mbRepeat )
315*cdf0e10cSrcweir             maRepeatTimer.Start();
316*cdf0e10cSrcweir         Invalidate( maLowerRect );
317*cdf0e10cSrcweir         Update();
318*cdf0e10cSrcweir     }
319*cdf0e10cSrcweir }
320*cdf0e10cSrcweir 
321*cdf0e10cSrcweir // -----------------------------------------------------------------------
322*cdf0e10cSrcweir 
323*cdf0e10cSrcweir void SpinButton::KeyInput( const KeyEvent& rKEvt )
324*cdf0e10cSrcweir {
325*cdf0e10cSrcweir     KeyCode aCode = rKEvt.GetKeyCode();
326*cdf0e10cSrcweir 
327*cdf0e10cSrcweir     if ( !rKEvt.GetKeyCode().GetModifier() )
328*cdf0e10cSrcweir     {
329*cdf0e10cSrcweir         switch ( rKEvt.GetKeyCode().GetCode() )
330*cdf0e10cSrcweir         {
331*cdf0e10cSrcweir         case KEY_LEFT:
332*cdf0e10cSrcweir         case KEY_RIGHT:
333*cdf0e10cSrcweir         {
334*cdf0e10cSrcweir             sal_Bool bUp = KEY_RIGHT == rKEvt.GetKeyCode().GetCode();
335*cdf0e10cSrcweir             if ( mbHorz && !ImplMoveFocus( bUp ) )
336*cdf0e10cSrcweir                 bUp ? Up() : Down();
337*cdf0e10cSrcweir         }
338*cdf0e10cSrcweir         break;
339*cdf0e10cSrcweir 
340*cdf0e10cSrcweir         case KEY_UP:
341*cdf0e10cSrcweir         case KEY_DOWN:
342*cdf0e10cSrcweir         {
343*cdf0e10cSrcweir             sal_Bool bUp = KEY_UP == rKEvt.GetKeyCode().GetCode();
344*cdf0e10cSrcweir             if ( !mbHorz && !ImplMoveFocus( KEY_UP == rKEvt.GetKeyCode().GetCode() ) )
345*cdf0e10cSrcweir                 bUp ? Up() : Down();
346*cdf0e10cSrcweir         }
347*cdf0e10cSrcweir         break;
348*cdf0e10cSrcweir 
349*cdf0e10cSrcweir         case KEY_SPACE:
350*cdf0e10cSrcweir             mbUpperIsFocused ? Up() : Down();
351*cdf0e10cSrcweir             break;
352*cdf0e10cSrcweir 
353*cdf0e10cSrcweir         default:
354*cdf0e10cSrcweir             Control::KeyInput( rKEvt );
355*cdf0e10cSrcweir             break;
356*cdf0e10cSrcweir         }
357*cdf0e10cSrcweir     }
358*cdf0e10cSrcweir     else
359*cdf0e10cSrcweir         Control::KeyInput( rKEvt );
360*cdf0e10cSrcweir }
361*cdf0e10cSrcweir 
362*cdf0e10cSrcweir // -----------------------------------------------------------------------
363*cdf0e10cSrcweir 
364*cdf0e10cSrcweir void SpinButton::StateChanged( StateChangedType nType )
365*cdf0e10cSrcweir {
366*cdf0e10cSrcweir     switch ( nType )
367*cdf0e10cSrcweir     {
368*cdf0e10cSrcweir     case STATE_CHANGE_DATA:
369*cdf0e10cSrcweir     case STATE_CHANGE_ENABLE:
370*cdf0e10cSrcweir         Invalidate();
371*cdf0e10cSrcweir         break;
372*cdf0e10cSrcweir 
373*cdf0e10cSrcweir     case STATE_CHANGE_STYLE:
374*cdf0e10cSrcweir     {
375*cdf0e10cSrcweir         sal_Bool bNewRepeat = 0 != ( GetStyle() & WB_REPEAT );
376*cdf0e10cSrcweir         if ( bNewRepeat != mbRepeat )
377*cdf0e10cSrcweir         {
378*cdf0e10cSrcweir             if ( maRepeatTimer.IsActive() )
379*cdf0e10cSrcweir             {
380*cdf0e10cSrcweir                 maRepeatTimer.Stop();
381*cdf0e10cSrcweir                 maRepeatTimer.SetTimeout( GetSettings().GetMouseSettings().GetButtonStartRepeat() );
382*cdf0e10cSrcweir             }
383*cdf0e10cSrcweir             mbRepeat = bNewRepeat;
384*cdf0e10cSrcweir         }
385*cdf0e10cSrcweir 
386*cdf0e10cSrcweir         sal_Bool bNewHorz = 0 != ( GetStyle() & WB_HSCROLL );
387*cdf0e10cSrcweir         if ( bNewHorz != mbHorz )
388*cdf0e10cSrcweir         {
389*cdf0e10cSrcweir             mbHorz = bNewHorz;
390*cdf0e10cSrcweir             Resize();
391*cdf0e10cSrcweir         }
392*cdf0e10cSrcweir     }
393*cdf0e10cSrcweir     break;
394*cdf0e10cSrcweir     }
395*cdf0e10cSrcweir 
396*cdf0e10cSrcweir     Control::StateChanged( nType );
397*cdf0e10cSrcweir }
398*cdf0e10cSrcweir 
399*cdf0e10cSrcweir // -----------------------------------------------------------------------
400*cdf0e10cSrcweir 
401*cdf0e10cSrcweir void SpinButton::SetRangeMin( long nNewRange )
402*cdf0e10cSrcweir {
403*cdf0e10cSrcweir     SetRange( Range( nNewRange, GetRangeMax() ) );
404*cdf0e10cSrcweir }
405*cdf0e10cSrcweir 
406*cdf0e10cSrcweir // -----------------------------------------------------------------------
407*cdf0e10cSrcweir 
408*cdf0e10cSrcweir void SpinButton::SetRangeMax( long nNewRange )
409*cdf0e10cSrcweir {
410*cdf0e10cSrcweir     SetRange( Range( GetRangeMin(), nNewRange ) );
411*cdf0e10cSrcweir }
412*cdf0e10cSrcweir 
413*cdf0e10cSrcweir // -----------------------------------------------------------------------
414*cdf0e10cSrcweir 
415*cdf0e10cSrcweir void SpinButton::SetRange( const Range& rRange )
416*cdf0e10cSrcweir {
417*cdf0e10cSrcweir     // adjust rage
418*cdf0e10cSrcweir     Range aRange = rRange;
419*cdf0e10cSrcweir     aRange.Justify();
420*cdf0e10cSrcweir     long nNewMinRange = aRange.Min();
421*cdf0e10cSrcweir     long nNewMaxRange = aRange.Max();
422*cdf0e10cSrcweir 
423*cdf0e10cSrcweir     // do something only if old and new range differ
424*cdf0e10cSrcweir     if ( (mnMinRange != nNewMinRange) ||
425*cdf0e10cSrcweir          (mnMaxRange != nNewMaxRange) )
426*cdf0e10cSrcweir     {
427*cdf0e10cSrcweir         mnMinRange = nNewMinRange;
428*cdf0e10cSrcweir         mnMaxRange = nNewMaxRange;
429*cdf0e10cSrcweir 
430*cdf0e10cSrcweir         // adjust value to new range, if necessary
431*cdf0e10cSrcweir         if ( mnValue > mnMaxRange )
432*cdf0e10cSrcweir             mnValue = mnMaxRange;
433*cdf0e10cSrcweir         if ( mnValue < mnMinRange )
434*cdf0e10cSrcweir             mnValue = mnMinRange;
435*cdf0e10cSrcweir 
436*cdf0e10cSrcweir         StateChanged( STATE_CHANGE_DATA );
437*cdf0e10cSrcweir     }
438*cdf0e10cSrcweir }
439*cdf0e10cSrcweir 
440*cdf0e10cSrcweir // -----------------------------------------------------------------------
441*cdf0e10cSrcweir 
442*cdf0e10cSrcweir void SpinButton::SetValue( long nValue )
443*cdf0e10cSrcweir {
444*cdf0e10cSrcweir     // adjust, if necessary
445*cdf0e10cSrcweir     if ( nValue > mnMaxRange )
446*cdf0e10cSrcweir         nValue = mnMaxRange;
447*cdf0e10cSrcweir     if ( nValue < mnMinRange )
448*cdf0e10cSrcweir         nValue = mnMinRange;
449*cdf0e10cSrcweir 
450*cdf0e10cSrcweir     if ( mnValue != nValue )
451*cdf0e10cSrcweir     {
452*cdf0e10cSrcweir         mnValue = nValue;
453*cdf0e10cSrcweir         StateChanged( STATE_CHANGE_DATA );
454*cdf0e10cSrcweir     }
455*cdf0e10cSrcweir }
456*cdf0e10cSrcweir 
457*cdf0e10cSrcweir // -----------------------------------------------------------------------
458*cdf0e10cSrcweir 
459*cdf0e10cSrcweir void SpinButton::GetFocus()
460*cdf0e10cSrcweir {
461*cdf0e10cSrcweir     ShowFocus( maFocusRect );
462*cdf0e10cSrcweir     Control::GetFocus();
463*cdf0e10cSrcweir }
464*cdf0e10cSrcweir 
465*cdf0e10cSrcweir // -----------------------------------------------------------------------
466*cdf0e10cSrcweir 
467*cdf0e10cSrcweir void SpinButton::LoseFocus()
468*cdf0e10cSrcweir {
469*cdf0e10cSrcweir     HideFocus();
470*cdf0e10cSrcweir     Control::LoseFocus();
471*cdf0e10cSrcweir }
472*cdf0e10cSrcweir 
473*cdf0e10cSrcweir // -----------------------------------------------------------------------
474*cdf0e10cSrcweir 
475*cdf0e10cSrcweir sal_Bool SpinButton::ImplMoveFocus( sal_Bool _bUpper )
476*cdf0e10cSrcweir {
477*cdf0e10cSrcweir     if ( _bUpper == mbUpperIsFocused )
478*cdf0e10cSrcweir         return sal_False;
479*cdf0e10cSrcweir 
480*cdf0e10cSrcweir     HideFocus();
481*cdf0e10cSrcweir     ImplCalcFocusRect( _bUpper );
482*cdf0e10cSrcweir     if ( HasFocus() )
483*cdf0e10cSrcweir         ShowFocus( maFocusRect );
484*cdf0e10cSrcweir     return sal_True;
485*cdf0e10cSrcweir }
486*cdf0e10cSrcweir 
487*cdf0e10cSrcweir // -----------------------------------------------------------------------
488*cdf0e10cSrcweir 
489*cdf0e10cSrcweir void SpinButton::ImplCalcFocusRect( sal_Bool _bUpper )
490*cdf0e10cSrcweir {
491*cdf0e10cSrcweir     maFocusRect = _bUpper ? maUpperRect : maLowerRect;
492*cdf0e10cSrcweir     // inflate by some pixels
493*cdf0e10cSrcweir     maFocusRect.Left() += 2;
494*cdf0e10cSrcweir     maFocusRect.Top() += 2;
495*cdf0e10cSrcweir     maFocusRect.Right() -= 2;
496*cdf0e10cSrcweir     maFocusRect.Bottom() -= 2;
497*cdf0e10cSrcweir     mbUpperIsFocused = _bUpper;
498*cdf0e10cSrcweir }
499*cdf0e10cSrcweir 
500*cdf0e10cSrcweir // -----------------------------------------------------------------------
501*cdf0e10cSrcweir 
502*cdf0e10cSrcweir Rectangle* SpinButton::ImplFindPartRect( const Point& rPt )
503*cdf0e10cSrcweir {
504*cdf0e10cSrcweir     if( maUpperRect.IsInside( rPt ) )
505*cdf0e10cSrcweir         return &maUpperRect;
506*cdf0e10cSrcweir     else if( maLowerRect.IsInside( rPt ) )
507*cdf0e10cSrcweir         return &maLowerRect;
508*cdf0e10cSrcweir     else
509*cdf0e10cSrcweir         return NULL;
510*cdf0e10cSrcweir }
511*cdf0e10cSrcweir 
512*cdf0e10cSrcweir long SpinButton::PreNotify( NotifyEvent& rNEvt )
513*cdf0e10cSrcweir {
514*cdf0e10cSrcweir     long nDone = 0;
515*cdf0e10cSrcweir     const MouseEvent* pMouseEvt = NULL;
516*cdf0e10cSrcweir 
517*cdf0e10cSrcweir     if( (rNEvt.GetType() == EVENT_MOUSEMOVE) && (pMouseEvt = rNEvt.GetMouseEvent()) != NULL )
518*cdf0e10cSrcweir     {
519*cdf0e10cSrcweir         if( !pMouseEvt->GetButtons() && !pMouseEvt->IsSynthetic() && !pMouseEvt->IsModifierChanged() )
520*cdf0e10cSrcweir         {
521*cdf0e10cSrcweir             // trigger redraw if mouse over state has changed
522*cdf0e10cSrcweir             if( IsNativeControlSupported(CTRL_SPINBOX, PART_ENTIRE_CONTROL) ||
523*cdf0e10cSrcweir                 IsNativeControlSupported(CTRL_SPINBOX, PART_ALL_BUTTONS) )
524*cdf0e10cSrcweir             {
525*cdf0e10cSrcweir                 Rectangle* pRect = ImplFindPartRect( GetPointerPosPixel() );
526*cdf0e10cSrcweir                 Rectangle* pLastRect = ImplFindPartRect( GetLastPointerPosPixel() );
527*cdf0e10cSrcweir                 if( pRect != pLastRect || (pMouseEvt->IsLeaveWindow() || pMouseEvt->IsEnterWindow()) )
528*cdf0e10cSrcweir                 {
529*cdf0e10cSrcweir                     Region aRgn( GetActiveClipRegion() );
530*cdf0e10cSrcweir                     if( pLastRect )
531*cdf0e10cSrcweir                     {
532*cdf0e10cSrcweir                         SetClipRegion( *pLastRect );
533*cdf0e10cSrcweir                         Paint( *pLastRect );
534*cdf0e10cSrcweir                         SetClipRegion( aRgn );
535*cdf0e10cSrcweir                     }
536*cdf0e10cSrcweir                     if( pRect )
537*cdf0e10cSrcweir                     {
538*cdf0e10cSrcweir                         SetClipRegion( *pRect );
539*cdf0e10cSrcweir                         Paint( *pRect );
540*cdf0e10cSrcweir                         SetClipRegion( aRgn );
541*cdf0e10cSrcweir                     }
542*cdf0e10cSrcweir                 }
543*cdf0e10cSrcweir             }
544*cdf0e10cSrcweir         }
545*cdf0e10cSrcweir     }
546*cdf0e10cSrcweir 
547*cdf0e10cSrcweir     return nDone ? nDone : Control::PreNotify(rNEvt);
548*cdf0e10cSrcweir }
549*cdf0e10cSrcweir 
550*cdf0e10cSrcweir // -----------------------------------------------------------------------
551