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