Branch libreoffice-5-0-4
[LibreOffice.git] / include / vcl / spin.hxx
blob48c8b4e9463cd59d51526deb28cf2919a49a2df7
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_VCL_SPIN_HXX
21 #define INCLUDED_VCL_SPIN_HXX
23 #include <tools/solar.h>
24 #include <vcl/dllapi.h>
25 #include <vcl/ctrl.hxx>
26 #include <vcl/timer.hxx>
29 // - SpinButton -
32 class VCL_DLLPUBLIC SpinButton : public Control
34 private:
35 AutoTimer maRepeatTimer;
36 Rectangle maUpperRect;
37 Rectangle maLowerRect;
38 Rectangle maFocusRect;
39 bool mbRepeat : 1;
40 bool mbUpperIn : 1;
41 bool mbLowerIn : 1;
42 bool mbInitialUp : 1;
43 bool mbInitialDown : 1;
44 bool mbHorz : 1;
45 bool mbUpperIsFocused : 1;
46 Link<> maUpHdlLink;
47 Link<> maDownHdlLink;
48 long mnMinRange;
49 long mnMaxRange;
50 long mnValue;
51 long mnValueStep;
53 SAL_DLLPRIVATE Rectangle* ImplFindPartRect( const Point& rPt );
54 using Window::ImplInit;
55 SAL_DLLPRIVATE void ImplInit( vcl::Window* pParent, WinBits nStyle );
56 DECL_DLLPRIVATE_LINK_TYPED( ImplTimeout, Timer*, void );
58 public:
59 explicit SpinButton( vcl::Window* pParent, WinBits nStyle = 0 );
61 void Up();
62 void Down();
64 virtual void Resize() SAL_OVERRIDE;
65 virtual void Paint( vcl::RenderContext& rRenderContext, const Rectangle& rRect ) SAL_OVERRIDE;
66 virtual void Draw( OutputDevice* pDev, const Point& rPos, const Size& rSize, sal_uLong nFlags ) SAL_OVERRIDE;
67 virtual void MouseButtonDown( const MouseEvent& rMEvt ) SAL_OVERRIDE;
68 virtual void MouseButtonUp( const MouseEvent& rMEvt ) SAL_OVERRIDE;
69 virtual void MouseMove( const MouseEvent& rMEvt ) SAL_OVERRIDE;
70 virtual void KeyInput( const KeyEvent& rKEvt ) SAL_OVERRIDE;
71 virtual void StateChanged( StateChangedType nStateChange ) SAL_OVERRIDE;
72 virtual void GetFocus() SAL_OVERRIDE;
73 virtual void LoseFocus() SAL_OVERRIDE;
75 void SetRangeMin( long nNewRange );
76 long GetRangeMin() const { return mnMinRange; }
77 void SetRangeMax( long nNewRange );
78 long GetRangeMax() const { return mnMaxRange; }
79 void SetRange( const Range& rRange );
80 Range GetRange() const { return Range( GetRangeMin(), GetRangeMax() ); }
81 void SetValue( long nValue );
82 long GetValue() const { return mnValue; }
83 void SetValueStep( long nNewStep ) { mnValueStep = nNewStep; }
84 long GetValueStep() const { return mnValueStep; }
85 virtual bool PreNotify( NotifyEvent& rNEvt ) SAL_OVERRIDE;
87 void SetUpHdl( const Link<>& rLink ) { maUpHdlLink = rLink; }
88 const Link<>& GetUpHdl() const { return maUpHdlLink; }
89 void SetDownHdl( const Link<>& rLink ) { maDownHdlLink = rLink; }
90 const Link<>& GetDownHdl() const { return maDownHdlLink; }
92 private:
93 // moves the focus to the upper or lower rect. Return sal_True if the focus rect actually changed.
94 SAL_DLLPRIVATE bool ImplMoveFocus( bool _bUpper );
95 SAL_DLLPRIVATE void ImplCalcFocusRect( bool _bUpper );
97 SAL_DLLPRIVATE inline bool ImplIsUpperEnabled( ) const
99 return mnValue + mnValueStep <= mnMaxRange;
101 SAL_DLLPRIVATE inline bool ImplIsLowerEnabled( ) const
103 return mnValue >= mnMinRange + mnValueStep;
107 #endif // INCLUDED_VCL_SPIN_HXX
109 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */