Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / include / vcl / spin.hxx
blob3d77fa5c1f066fe139213071c68eec015c85dfde
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 class VCL_DLLPUBLIC SpinButton : public Control
31 private:
32 AutoTimer maRepeatTimer;
33 tools::Rectangle maUpperRect;
34 tools::Rectangle maLowerRect;
35 tools::Rectangle maFocusRect;
36 bool mbRepeat : 1;
37 bool mbUpperIn : 1;
38 bool mbLowerIn : 1;
39 bool mbInitialUp : 1;
40 bool mbInitialDown : 1;
41 bool mbHorz : 1;
42 bool mbUpperIsFocused : 1;
43 long mnMinRange;
44 long mnMaxRange;
45 long mnValue;
46 long mnValueStep;
48 SAL_DLLPRIVATE tools::Rectangle* ImplFindPartRect( const Point& rPt );
49 using Window::ImplInit;
50 SAL_DLLPRIVATE void ImplInit( vcl::Window* pParent, WinBits nStyle );
51 DECL_DLLPRIVATE_LINK( ImplTimeout, Timer*, void );
53 public:
54 explicit SpinButton( vcl::Window* pParent, WinBits nStyle );
56 void Up();
57 void Down();
59 virtual void Resize() override;
60 virtual void Paint( vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect ) override;
61 virtual void Draw( OutputDevice* pDev, const Point& rPos, const Size& rSize, DrawFlags nFlags ) override;
62 virtual void MouseButtonDown( const MouseEvent& rMEvt ) override;
63 virtual void MouseButtonUp( const MouseEvent& rMEvt ) override;
64 virtual void MouseMove( const MouseEvent& rMEvt ) override;
65 virtual void KeyInput( const KeyEvent& rKEvt ) override;
66 virtual void StateChanged( StateChangedType nStateChange ) override;
67 virtual void GetFocus() override;
68 virtual void LoseFocus() override;
70 void SetRangeMin( long nNewRange );
71 long GetRangeMin() const { return mnMinRange; }
72 void SetRangeMax( long nNewRange );
73 long GetRangeMax() const { return mnMaxRange; }
74 void SetRange( const Range& rRange );
75 void SetValue( long nValue );
76 long GetValue() const { return mnValue; }
77 void SetValueStep( long nNewStep ) { mnValueStep = nNewStep; }
78 long GetValueStep() const { return mnValueStep; }
79 virtual bool PreNotify( NotifyEvent& rNEvt ) override;
81 private:
82 // moves the focus to the upper or lower rect. Return sal_True if the focus rect actually changed.
83 SAL_DLLPRIVATE bool ImplMoveFocus( bool _bUpper );
84 SAL_DLLPRIVATE void ImplCalcFocusRect( bool _bUpper );
86 SAL_DLLPRIVATE bool ImplIsUpperEnabled( ) const
88 return mnValue + mnValueStep <= mnMaxRange;
90 SAL_DLLPRIVATE bool ImplIsLowerEnabled( ) const
92 return mnValue >= mnMinRange + mnValueStep;
96 #endif // INCLUDED_VCL_SPIN_HXX
98 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */