Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #ifndef INCLUDED_VCL_SPIN_HXX
21 : #define INCLUDED_VCL_SPIN_HXX
22 :
23 : #include <tools/solar.h>
24 : #include <vcl/dllapi.h>
25 : #include <vcl/ctrl.hxx>
26 : #include <vcl/timer.hxx>
27 :
28 :
29 : // - SpinButton -
30 :
31 :
32 : class VCL_DLLPUBLIC SpinButton : public Control
33 : {
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;
52 :
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( ImplTimeout, Timer* );
57 :
58 : public:
59 : explicit SpinButton( vcl::Window* pParent, WinBits nStyle = 0 );
60 : virtual ~SpinButton();
61 :
62 : virtual void Up();
63 : virtual void Down();
64 :
65 : virtual void Resize() SAL_OVERRIDE;
66 : virtual void Paint( const Rectangle& rRect ) SAL_OVERRIDE;
67 : virtual void Draw( OutputDevice* pDev, const Point& rPos, const Size& rSize, sal_uLong nFlags ) SAL_OVERRIDE;
68 : virtual void MouseButtonDown( const MouseEvent& rMEvt ) SAL_OVERRIDE;
69 : virtual void MouseButtonUp( const MouseEvent& rMEvt ) SAL_OVERRIDE;
70 : virtual void MouseMove( const MouseEvent& rMEvt ) SAL_OVERRIDE;
71 : virtual void KeyInput( const KeyEvent& rKEvt ) SAL_OVERRIDE;
72 : virtual void StateChanged( StateChangedType nStateChange ) SAL_OVERRIDE;
73 : virtual void GetFocus() SAL_OVERRIDE;
74 : virtual void LoseFocus() SAL_OVERRIDE;
75 :
76 : void SetRangeMin( long nNewRange );
77 2 : long GetRangeMin() const { return mnMinRange; }
78 : void SetRangeMax( long nNewRange );
79 2 : long GetRangeMax() const { return mnMaxRange; }
80 : void SetRange( const Range& rRange );
81 : Range GetRange() const { return Range( GetRangeMin(), GetRangeMax() ); }
82 : void SetValue( long nValue );
83 0 : long GetValue() const { return mnValue; }
84 2 : void SetValueStep( long nNewStep ) { mnValueStep = nNewStep; }
85 0 : long GetValueStep() const { return mnValueStep; }
86 : virtual bool PreNotify( NotifyEvent& rNEvt ) SAL_OVERRIDE;
87 :
88 : void SetUpHdl( const Link& rLink ) { maUpHdlLink = rLink; }
89 : const Link& GetUpHdl() const { return maUpHdlLink; }
90 : void SetDownHdl( const Link& rLink ) { maDownHdlLink = rLink; }
91 : const Link& GetDownHdl() const { return maDownHdlLink; }
92 :
93 : private:
94 : // moves the focus to the upper or lower rect. Return sal_True if the focus rect actually changed.
95 : SAL_DLLPRIVATE bool ImplMoveFocus( bool _bUpper );
96 : SAL_DLLPRIVATE void ImplCalcFocusRect( bool _bUpper );
97 :
98 10 : SAL_DLLPRIVATE inline bool ImplIsUpperEnabled( ) const
99 : {
100 10 : return mnValue + mnValueStep <= mnMaxRange;
101 : }
102 4 : SAL_DLLPRIVATE inline bool ImplIsLowerEnabled( ) const
103 : {
104 4 : return mnValue >= mnMinRange + mnValueStep;
105 : }
106 : };
107 :
108 : #endif // INCLUDED_VCL_SPIN_HXX
109 :
110 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|