1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 #ifndef _SV_SPIN_HXX 25 #define _SV_SPIN_HXX 26 27 #include <vcl/sv.h> 28 #include <vcl/dllapi.h> 29 #include <vcl/ctrl.hxx> 30 #include <vcl/timer.hxx> 31 32 // -------------- 33 // - SpinButton - 34 // -------------- 35 36 class VCL_DLLPUBLIC SpinButton : public Control 37 { 38 private: 39 AutoTimer maRepeatTimer; 40 Rectangle maUpperRect; 41 Rectangle maLowerRect; 42 Rectangle maFocusRect; 43 sal_Bool mbRepeat : 1; 44 sal_Bool mbUpperIn : 1; 45 sal_Bool mbLowerIn : 1; 46 sal_Bool mbInitialUp : 1; 47 sal_Bool mbInitialDown : 1; 48 sal_Bool mbHorz : 1; 49 sal_Bool mbUpperIsFocused : 1; 50 Link maUpHdlLink; 51 Link maDownHdlLink; 52 long mnMinRange; 53 long mnMaxRange; 54 long mnValue; 55 long mnValueStep; 56 57 SAL_DLLPRIVATE Rectangle* ImplFindPartRect( const Point& rPt ); 58 using Window::ImplInit; 59 SAL_DLLPRIVATE void ImplInit( Window* pParent, WinBits nStyle ); 60 DECL_DLLPRIVATE_LINK( ImplTimeout, Timer* ); 61 62 public: 63 explicit SpinButton( Window* pParent, WinBits nStyle = 0 ); 64 explicit SpinButton( Window* pParent, const ResId& ); 65 virtual ~SpinButton(); 66 67 virtual void Up(); 68 virtual void Down(); 69 70 virtual void Resize(); 71 virtual void Paint( const Rectangle& rRect ); 72 virtual void Draw( OutputDevice* pDev, const Point& rPos, const Size& rSize, sal_uLong nFlags ); 73 virtual void MouseButtonDown( const MouseEvent& rMEvt ); 74 virtual void MouseButtonUp( const MouseEvent& rMEvt ); 75 virtual void MouseMove( const MouseEvent& rMEvt ); 76 virtual void KeyInput( const KeyEvent& rKEvt ); 77 virtual void StateChanged( StateChangedType nStateChange ); 78 virtual void GetFocus(); 79 virtual void LoseFocus(); 80 81 void SetRangeMin( long nNewRange ); GetRangeMin() const82 long GetRangeMin() const { return mnMinRange; } 83 void SetRangeMax( long nNewRange ); GetRangeMax() const84 long GetRangeMax() const { return mnMaxRange; } 85 void SetRange( const Range& rRange ); GetRange() const86 Range GetRange() const { return Range( GetRangeMin(), GetRangeMax() ); } 87 void SetValue( long nValue ); GetValue() const88 long GetValue() const { return mnValue; } SetValueStep(long nNewStep)89 void SetValueStep( long nNewStep ) { mnValueStep = nNewStep; } GetValueStep() const90 long GetValueStep() const { return mnValueStep; } 91 virtual long PreNotify( NotifyEvent& rNEvt ); 92 SetUpHdl(const Link & rLink)93 void SetUpHdl( const Link& rLink ) { maUpHdlLink = rLink; } GetUpHdl() const94 const Link& GetUpHdl() const { return maUpHdlLink; } SetDownHdl(const Link & rLink)95 void SetDownHdl( const Link& rLink ) { maDownHdlLink = rLink; } GetDownHdl() const96 const Link& GetDownHdl() const { return maDownHdlLink; } 97 98 private: 99 // moves the focus to the upper or lower rect. Return sal_True if the focus rect actually changed. 100 SAL_DLLPRIVATE sal_Bool ImplMoveFocus( sal_Bool _bUpper ); 101 SAL_DLLPRIVATE void ImplCalcFocusRect( sal_Bool _bUpper ); 102 ImplIsUpperEnabled() const103 SAL_DLLPRIVATE inline sal_Bool ImplIsUpperEnabled( ) const 104 { 105 return mnValue + mnValueStep <= mnMaxRange; 106 } ImplIsLowerEnabled() const107 SAL_DLLPRIVATE inline sal_Bool ImplIsLowerEnabled( ) const 108 { 109 return mnValue >= mnMinRange + mnValueStep; 110 } 111 }; 112 113 #endif // _SV_SPIN_HXX 114 115