/src/libreoffice/include/svx/dialcontrol.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 | | #ifndef INCLUDED_SVX_DIALCONTROL_HXX |
21 | | #define INCLUDED_SVX_DIALCONTROL_HXX |
22 | | |
23 | | #include <memory> |
24 | | #include <vcl/virdev.hxx> |
25 | | #include <vcl/weld/MetricSpinButton.hxx> |
26 | | #include <vcl/weld/customweld.hxx> |
27 | | #include <svx/svxdllapi.h> |
28 | | |
29 | | namespace svx { |
30 | | |
31 | | |
32 | | class SAL_WARN_UNUSED DialControlBmp final : public VirtualDevice |
33 | | { |
34 | | public: |
35 | | explicit DialControlBmp(OutputDevice& rReference); |
36 | | |
37 | | void InitBitmap(const vcl::Font& rFont); |
38 | | void SetSize(const Size& rSize); |
39 | | void CopyBackground( const DialControlBmp& rSrc ); |
40 | | void DrawBackground( const Size& rSize, bool bEnabled ); |
41 | | void DrawBackground(); |
42 | | void DrawElements( const OUString& rText, Degree100 nAngle ); |
43 | | Color GetBackgroundColor() const override; |
44 | | |
45 | | private: |
46 | | const Color& GetTextColor() const; |
47 | | const Color& GetScaleLineColor() const; |
48 | | const Color& GetButtonLineColor() const; |
49 | | const Color& GetButtonFillColor( bool bMain ) const; |
50 | | |
51 | | void Init(); |
52 | | |
53 | | tools::Rectangle maRect; |
54 | | bool mbEnabled; |
55 | | OutputDevice& mrParent; |
56 | | tools::Long mnCenterX; |
57 | | tools::Long mnCenterY; |
58 | | }; |
59 | | |
60 | | /** This control allows to input a rotation angle, visualized by a dial. |
61 | | |
62 | | Usage: A single click sets a rotation angle rounded to steps of 15 degrees. |
63 | | Dragging with the left mouse button sets an exact rotation angle. Pressing |
64 | | the ESCAPE key during mouse drag cancels the operation and restores the old |
65 | | state of the control. |
66 | | |
67 | | It is possible to link a numeric field to this control using the function |
68 | | SetLinkedField(). The DialControl will take full control of this numeric |
69 | | field: |
70 | | - Sets the rotation angle to the numeric field in mouse operations. |
71 | | - Shows the value entered/modified in the numeric field. |
72 | | - Enables/disables/shows/hides the field according to own state changes. |
73 | | */ |
74 | | class SAL_WARN_UNUSED SVX_DLLPUBLIC DialControl final : public weld::CustomWidgetController |
75 | | { |
76 | | public: |
77 | | virtual void SetDrawingArea(weld::DrawingArea* pDrawingArea) override; |
78 | | |
79 | | virtual void Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect) override; |
80 | | |
81 | | virtual void StyleUpdated() override; |
82 | | |
83 | | virtual bool MouseButtonDown( const MouseEvent& rMEvt ) override; |
84 | | virtual bool MouseMove( const MouseEvent& rMEvt ) override; |
85 | | virtual bool MouseButtonUp( const MouseEvent& rMEvt ) override; |
86 | | virtual bool KeyInput(const KeyEvent& rKEvt) override; |
87 | | virtual void LoseFocus() override; |
88 | | |
89 | | virtual void Resize() override; |
90 | | |
91 | | /** Returns the current rotation angle in 1/100 degrees. */ |
92 | | Degree100 GetRotation() const; |
93 | | /** Sets the rotation to the passed value (in 1/100 degrees). */ |
94 | | void SetRotation( Degree100 nAngle ); |
95 | | /** Returns true, if the control is not in "don't care" state. */ |
96 | | bool HasRotation() const; |
97 | | /** Sets the control to "don't care" state. */ |
98 | | void SetNoRotation(); |
99 | | |
100 | | /** Links the passed numeric edit field to the control (bi-directional). |
101 | | * nDecimalPlaces: |
102 | | * field value is unsign given decimal places |
103 | | * default is 0 which means field values are in degrees, |
104 | | * 2 means 100th of degree |
105 | | */ |
106 | | void SetLinkedField(weld::MetricSpinButton* pField, sal_Int32 nDecimalPlaces = 0); |
107 | | |
108 | | /** Save value for later comparison */ |
109 | | void SaveValue(); |
110 | | |
111 | | /** Compare value with the saved value */ |
112 | | bool IsValueModified() const; |
113 | | |
114 | 0 | const OUString& GetText() const { return mpImpl->maText; } |
115 | 0 | void SetText(const OUString& rText) { mpImpl->maText = rText; } |
116 | | |
117 | | void SetModifyHdl( const Link<DialControl&,void>& rLink ); |
118 | | |
119 | | void Init( const Size& rWinSize ); |
120 | | |
121 | | void set_visible(bool bVisible) |
122 | 0 | { |
123 | 0 | if (bVisible) |
124 | 0 | Show(); |
125 | 0 | else |
126 | 0 | Hide(); |
127 | 0 | } |
128 | | private: |
129 | | struct SAL_DLLPRIVATE DialControl_Impl |
130 | | { |
131 | | ScopedVclPtr<DialControlBmp> mxBmpEnabled; |
132 | | ScopedVclPtr<DialControlBmp> mxBmpDisabled; |
133 | | ScopedVclPtr<DialControlBmp> mxBmpBuffered; |
134 | | Link<DialControl&,void> maModifyHdl; |
135 | | OUString maText; |
136 | | weld::MetricSpinButton* mpLinkField; |
137 | | sal_Int32 mnLinkedFieldValueMultiplyer; |
138 | | Size maWinSize; |
139 | | vcl::Font maWinFont; |
140 | | Degree100 mnAngle; |
141 | | Degree100 mnInitialAngle; |
142 | | Degree100 mnOldAngle; |
143 | | tools::Long mnCenterX; |
144 | | tools::Long mnCenterY; |
145 | | bool mbNoRot; |
146 | | |
147 | | explicit DialControl_Impl(OutputDevice& rReference); |
148 | | void Init( const Size& rWinSize, const vcl::Font& rWinFont ); |
149 | | void SetSize( const Size& rWinSize ); |
150 | | }; |
151 | | std::unique_ptr< DialControl_Impl > mpImpl; |
152 | | |
153 | | void HandleMouseEvent( const Point& rPos, bool bInitial ); |
154 | | void HandleEscapeEvent(); |
155 | | |
156 | | void SetRotation( Degree100 nAngle, bool bBroadcast ); |
157 | | |
158 | | void Init( const Size& rWinSize, const vcl::Font& rWinFont ); |
159 | | |
160 | | void InvalidateControl(); |
161 | | |
162 | | DECL_DLLPRIVATE_LINK(LinkedFieldModifyHdl, weld::MetricSpinButton&, void); |
163 | | }; |
164 | | |
165 | | } |
166 | | |
167 | | #endif |
168 | | |
169 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |