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 <sfx2/itemconnect.hxx>
26 #include <svx/svxdllapi.h>
34 class SAL_WARN_UNUSED DialControlBmp
: public VirtualDevice
37 explicit DialControlBmp( vcl::Window
& rParent
);
39 void InitBitmap(const vcl::Font
& rFont
);
40 void SetSize(const Size
& rSize
);
41 void CopyBackground( const DialControlBmp
& rSrc
);
42 void DrawBackground( const Size
& rSize
, bool bEnabled
);
43 void DrawBackground();
44 void DrawElements( const OUString
& rText
, sal_Int32 nAngle
);
51 const Color
& GetBackgroundColor() const;
52 const Color
& GetTextColor() const;
53 const Color
& GetScaleLineColor() const;
54 const Color
& GetButtonLineColor() const;
55 const Color
& GetButtonFillColor( bool bMain
) const;
59 vcl::Window
& mrParent
;
64 /** This control allows to input a rotation angle, visualized by a dial.
66 Usage: A single click sets a rotation angle rounded to steps of 15 degrees.
67 Dragging with the left mouse button sets an exact rotation angle. Pressing
68 the ESCAPE key during mouse drag cancels the operation and restores the old
71 It is possible to link a numeric field to this control using the function
72 SetLinkedField(). The DialControl will take full control of this numeric
74 - Sets the rotation angle to the numeric field in mouse operations.
75 - Shows the value entered/modified in the numeric field.
76 - Enables/disables/shows/hides the field according to own state changes.
78 class SVX_DLLPUBLIC SAL_WARN_UNUSED DialControl
: public Control
81 explicit DialControl( vcl::Window
* pParent
, WinBits nBits
);
83 virtual void Paint(vcl::RenderContext
& rRenderContext
, const Rectangle
& rRect
) SAL_OVERRIDE
;
85 virtual void StateChanged( StateChangedType nStateChange
) SAL_OVERRIDE
;
86 virtual void DataChanged( const DataChangedEvent
& rDCEvt
) SAL_OVERRIDE
;
88 virtual void MouseButtonDown( const MouseEvent
& rMEvt
) SAL_OVERRIDE
;
89 virtual void MouseMove( const MouseEvent
& rMEvt
) SAL_OVERRIDE
;
90 virtual void MouseButtonUp( const MouseEvent
& rMEvt
) SAL_OVERRIDE
;
91 virtual void KeyInput( const KeyEvent
& rKEvt
) SAL_OVERRIDE
;
92 virtual void LoseFocus() SAL_OVERRIDE
;
94 virtual Size
GetOptimalSize() const SAL_OVERRIDE
;
95 virtual void Resize() SAL_OVERRIDE
;
97 /** Returns true, if the control is not in "don't care" state. */
98 bool HasRotation() const;
99 /** Sets the control to "don't care" state. */
100 void SetNoRotation();
102 /** Returns the current rotation angle in 1/100 degrees. */
103 sal_Int32
GetRotation() const;
104 /** Sets the rotation to the passed value (in 1/100 degrees). */
105 void SetRotation( sal_Int32 nAngle
);
107 /** Links the passed numeric edit field to the control (bi-directional).
109 * field value is usign given decimal places
110 * default is 0 which means field values are in degrees,
111 * 2 means 100th of degree
113 void SetLinkedField( NumericField
* pField
, sal_Int32 nDecimalPlaces
= 0);
115 /** The passed handler is called whenever the totation value changes. */
116 void SetModifyHdl( const Link
<>& rLink
);
118 /** Save value for later comparison */
121 /** Compare value with the saved value */
122 bool IsValueModified();
125 struct DialControl_Impl
127 ScopedVclPtr
<DialControlBmp
> mxBmpEnabled
;
128 ScopedVclPtr
<DialControlBmp
> mxBmpDisabled
;
129 ScopedVclPtr
<DialControlBmp
> mxBmpBuffered
;
131 VclPtr
<NumericField
> mpLinkField
;
132 sal_Int32 mnLinkedFieldValueMultiplyer
;
136 sal_Int32 mnInitialAngle
;
137 sal_Int32 mnOldAngle
;
142 explicit DialControl_Impl( vcl::Window
& rParent
);
143 void Init( const Size
& rWinSize
, const vcl::Font
& rWinFont
);
144 void SetSize( const Size
& rWinSize
);
146 std::unique_ptr
< DialControl_Impl
> mpImpl
;
148 virtual void HandleMouseEvent( const Point
& rPos
, bool bInitial
);
149 void HandleEscapeEvent();
151 void SetRotation( sal_Int32 nAngle
, bool bBroadcast
);
153 void Init( const Size
& rWinSize
, const vcl::Font
& rWinFont
);
154 void Init( const Size
& rWinSize
);
157 void InvalidateControl();
159 void ImplSetFieldLink( const Link
<>& rLink
);
162 DECL_LINK( LinkedFieldModifyHdl
, NumericField
* );
165 /** Wrapper for usage of a DialControl in item connections. */
166 class SVX_DLLPUBLIC SAL_WARN_UNUSED DialControlWrapper
: public sfx::SingleControlWrapper
< DialControl
, sal_Int32
>
169 explicit DialControlWrapper( DialControl
& rDial
);
171 virtual bool IsControlDontKnow() const SAL_OVERRIDE
;
172 virtual void SetControlDontKnow( bool bSet
) SAL_OVERRIDE
;
174 virtual sal_Int32
GetControlValue() const SAL_OVERRIDE
;
175 virtual void SetControlValue( sal_Int32 nValue
) SAL_OVERRIDE
;
178 /** An item<->control connection for a DialControl. */
179 typedef sfx::ItemControlConnection
< sfx::Int32ItemWrapper
, DialControlWrapper
> DialControlConnection
;
185 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */