/src/libreoffice/include/vcl/toolkit/spin.hxx
Line | Count | Source |
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 | | #pragma once |
21 | | |
22 | | #if !defined(VCL_DLLIMPLEMENTATION) && !defined(TOOLKIT_DLLIMPLEMENTATION) && !defined(VCL_INTERNALS) |
23 | | #error "don't use this in new code" |
24 | | #endif |
25 | | |
26 | | #include <config_options.h> |
27 | | #include <vcl/dllapi.h> |
28 | | #include <vcl/ctrl.hxx> |
29 | | #include <vcl/timer.hxx> |
30 | | |
31 | | class UNLESS_MERGELIBS(VCL_DLLPUBLIC) SpinButton final : public Control |
32 | | { |
33 | | private: |
34 | | AutoTimer maRepeatTimer; |
35 | | tools::Rectangle maUpperRect; |
36 | | tools::Rectangle maLowerRect; |
37 | | tools::Rectangle maFocusRect; |
38 | | bool mbRepeat : 1; |
39 | | bool mbUpperIn : 1; |
40 | | bool mbLowerIn : 1; |
41 | | bool mbInitialUp : 1; |
42 | | bool mbInitialDown : 1; |
43 | | bool mbHorz : 1; |
44 | | bool mbUpperIsFocused : 1; |
45 | | tools::Long mnMinRange; |
46 | | tools::Long mnMaxRange; |
47 | | tools::Long mnValue; |
48 | | tools::Long mnValueStep; |
49 | | |
50 | | SAL_DLLPRIVATE tools::Rectangle* ImplFindPartRect( const Point& rPt ); |
51 | | DECL_DLLPRIVATE_LINK( ImplTimeout, Timer*, void ); |
52 | | |
53 | | public: |
54 | | explicit SpinButton( vcl::Window* pParent, WinBits nStyle ); |
55 | | |
56 | | void Up(); |
57 | | void Down(); |
58 | | |
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, SystemTextColorFlags 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; |
69 | | |
70 | | void SetRangeMin( tools::Long nNewRange ); |
71 | 0 | tools::Long GetRangeMin() const { return mnMinRange; } |
72 | | void SetRangeMax( tools::Long nNewRange ); |
73 | 0 | tools::Long GetRangeMax() const { return mnMaxRange; } |
74 | | void SetRange( const Range& rRange ); |
75 | | void SetValue( tools::Long nValue ); |
76 | 0 | tools::Long GetValue() const { return mnValue; } |
77 | 0 | void SetValueStep( tools::Long nNewStep ) { mnValueStep = nNewStep; } |
78 | 0 | tools::Long GetValueStep() const { return mnValueStep; } |
79 | | virtual bool PreNotify( NotifyEvent& rNEvt ) override; |
80 | | |
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 ); |
85 | | |
86 | | SAL_DLLPRIVATE bool ImplIsUpperEnabled( ) const |
87 | 0 | { |
88 | 0 | return mnValue + mnValueStep <= mnMaxRange; |
89 | 0 | } |
90 | | SAL_DLLPRIVATE bool ImplIsLowerEnabled( ) const |
91 | 0 | { |
92 | 0 | return mnValue >= mnMinRange + mnValueStep; |
93 | 0 | } |
94 | | }; |
95 | | |
96 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |