1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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_SVX_DIALCONTROL_HXX
21 #define INCLUDED_SVX_DIALCONTROL_HXX
24 #include <vcl/ctrl.hxx>
25 #include <vcl/customweld.hxx>
26 #include <vcl/field.hxx>
27 #include <vcl/virdev.hxx>
28 #include <svx/svxdllapi.h>
35 class SAL_WARN_UNUSED DialControlBmp final
: public VirtualDevice
38 explicit DialControlBmp(OutputDevice
& rReference
);
40 void InitBitmap(const vcl::Font
& rFont
);
41 void SetSize(const Size
& rSize
);
42 void CopyBackground( const DialControlBmp
& rSrc
);
43 void DrawBackground( const Size
& rSize
, bool bEnabled
);
44 void DrawBackground();
45 void DrawElements( const OUString
& rText
, sal_Int32 nAngle
);
48 const Color
& GetBackgroundColor() const;
49 const Color
& GetTextColor() const;
50 const Color
& GetScaleLineColor() const;
51 const Color
& GetButtonLineColor() const;
52 const Color
& GetButtonFillColor( bool bMain
) const;
56 tools::Rectangle maRect
;
58 OutputDevice
& mrParent
;
63 /** This control allows to input a rotation angle, visualized by a dial.
65 Usage: A single click sets a rotation angle rounded to steps of 15 degrees.
66 Dragging with the left mouse button sets an exact rotation angle. Pressing
67 the ESCAPE key during mouse drag cancels the operation and restores the old
70 It is possible to link a numeric field to this control using the function
71 SetLinkedField(). The DialControl will take full control of this numeric
73 - Sets the rotation angle to the numeric field in mouse operations.
74 - Shows the value entered/modified in the numeric field.
75 - Enables/disables/shows/hides the field according to own state changes.
77 class SAL_WARN_UNUSED SVX_DLLPUBLIC DialControl
: public Control
80 explicit DialControl( vcl::Window
* pParent
, WinBits nBits
);
82 virtual void Paint(vcl::RenderContext
& rRenderContext
, const tools::Rectangle
& rRect
) override
;
84 virtual void StateChanged( StateChangedType nStateChange
) override
;
85 virtual void DataChanged( const DataChangedEvent
& rDCEvt
) override
;
87 virtual void MouseButtonDown( const MouseEvent
& rMEvt
) override
;
88 virtual void MouseMove( const MouseEvent
& rMEvt
) override
;
89 virtual void MouseButtonUp( const MouseEvent
& rMEvt
) override
;
90 virtual void KeyInput( const KeyEvent
& rKEvt
) override
;
91 virtual void LoseFocus() override
;
93 virtual Size
GetOptimalSize() const override
;
94 virtual void Resize() override
;
96 /** Returns the current rotation angle in 1/100 degrees. */
97 sal_Int32
GetRotation() const;
98 /** Sets the rotation to the passed value (in 1/100 degrees). */
99 void SetRotation( sal_Int32 nAngle
);
101 /** The passed handler is called whenever the rotation value changes. */
102 void SetModifyHdl( const Link
<DialControl
*,void>& rLink
);
105 struct DialControl_Impl
107 ScopedVclPtr
<DialControlBmp
> mxBmpEnabled
;
108 ScopedVclPtr
<DialControlBmp
> mxBmpDisabled
;
109 ScopedVclPtr
<DialControlBmp
> mxBmpBuffered
;
110 Link
<DialControl
*,void> maModifyHdl
;
111 VclPtr
<NumericField
> mpLinkField
;
112 sal_Int32 mnLinkedFieldValueMultiplyer
;
116 sal_Int32 mnOldAngle
;
121 explicit DialControl_Impl( vcl::Window
& rParent
);
122 void Init( const Size
& rWinSize
, const vcl::Font
& rWinFont
);
123 void SetSize( const Size
& rWinSize
);
125 std::unique_ptr
< DialControl_Impl
> mpImpl
;
127 virtual void HandleMouseEvent( const Point
& rPos
, bool bInitial
);
128 void HandleEscapeEvent();
130 void SetRotation( sal_Int32 nAngle
, bool bBroadcast
);
132 void Init( const Size
& rWinSize
, const vcl::Font
& rWinFont
);
133 void Init( const Size
& rWinSize
);
136 void InvalidateControl();
138 DECL_LINK( LinkedFieldModifyHdl
, Edit
&, void );
139 void LinkedFieldModifyHdl();
142 class SAL_WARN_UNUSED SVX_DLLPUBLIC SvxDialControl
: public weld::CustomWidgetController
145 virtual void SetDrawingArea(weld::DrawingArea
* pDrawingArea
) override
;
147 virtual void Paint(vcl::RenderContext
& rRenderContext
, const tools::Rectangle
& rRect
) override
;
149 virtual void StyleUpdated() override
;
151 virtual bool MouseButtonDown( const MouseEvent
& rMEvt
) override
;
152 virtual bool MouseMove( const MouseEvent
& rMEvt
) override
;
153 virtual bool MouseButtonUp( const MouseEvent
& rMEvt
) override
;
154 virtual bool KeyInput(const KeyEvent
& rKEvt
) override
;
155 virtual void LoseFocus() override
;
157 virtual void Resize() override
;
159 /** Returns the current rotation angle in 1/100 degrees. */
160 sal_Int32
GetRotation() const;
161 /** Sets the rotation to the passed value (in 1/100 degrees). */
162 void SetRotation( sal_Int32 nAngle
);
163 /** Returns true, if the control is not in "don't care" state. */
164 bool HasRotation() const;
165 /** Sets the control to "don't care" state. */
166 void SetNoRotation();
168 /** Links the passed numeric edit field to the control (bi-directional).
170 * field value is unsign given decimal places
171 * default is 0 which means field values are in degrees,
172 * 2 means 100th of degree
174 void SetLinkedField(weld::SpinButton
* pField
, sal_Int32 nDecimalPlaces
= 0);
176 /** Save value for later comparison */
179 /** Compare value with the saved value */
180 bool IsValueModified();
182 const OUString
& GetText() const { return mpImpl
->maText
; }
183 void SetText(const OUString
& rText
) { mpImpl
->maText
= rText
; }
186 struct DialControl_Impl
188 ScopedVclPtr
<DialControlBmp
> mxBmpEnabled
;
189 ScopedVclPtr
<DialControlBmp
> mxBmpDisabled
;
190 ScopedVclPtr
<DialControlBmp
> mxBmpBuffered
;
192 weld::SpinButton
* mpLinkField
;
193 sal_Int32 mnLinkedFieldValueMultiplyer
;
197 sal_Int32 mnInitialAngle
;
198 sal_Int32 mnOldAngle
;
203 explicit DialControl_Impl(OutputDevice
& rReference
);
204 void Init( const Size
& rWinSize
, const vcl::Font
& rWinFont
);
205 void SetSize( const Size
& rWinSize
);
207 std::unique_ptr
< DialControl_Impl
> mpImpl
;
209 void HandleMouseEvent( const Point
& rPos
, bool bInitial
);
210 void HandleEscapeEvent();
212 void Init( const Size
& rWinSize
, const vcl::Font
& rWinFont
);
213 void Init( const Size
& rWinSize
);
216 void InvalidateControl();
218 DECL_LINK(LinkedFieldModifyHdl
, weld::SpinButton
&, void);
219 void LinkedFieldModifyHdl();
226 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */