Branch libreoffice-5-0-4
[LibreOffice.git] / include / svx / dialcontrol.hxx
blobacc16f78122a4eb4fdc822d039a479d6aa0cbbe4
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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
23 #include <memory>
24 #include <vcl/ctrl.hxx>
25 #include <sfx2/itemconnect.hxx>
26 #include <svx/svxdllapi.h>
28 class NumericField;
30 namespace svx {
34 class SAL_WARN_UNUSED DialControlBmp : public VirtualDevice
36 public:
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 );
46 protected:
47 Rectangle maRect;
48 bool mbEnabled;
50 private:
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;
57 void Init();
59 vcl::Window& mrParent;
60 long mnCenterX;
61 long mnCenterY;
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
69 state of the control.
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
73 field:
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
80 public:
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).
108 * nDecimalPlaces:
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 */
119 void SaveValue();
121 /** Compare value with the saved value */
122 bool IsValueModified();
124 protected:
125 struct DialControl_Impl
127 ScopedVclPtr<DialControlBmp> mxBmpEnabled;
128 ScopedVclPtr<DialControlBmp> mxBmpDisabled;
129 ScopedVclPtr<DialControlBmp> mxBmpBuffered;
130 Link<> maModifyHdl;
131 VclPtr<NumericField> mpLinkField;
132 sal_Int32 mnLinkedFieldValueMultiplyer;
133 Size maWinSize;
134 vcl::Font maWinFont;
135 sal_Int32 mnAngle;
136 sal_Int32 mnInitialAngle;
137 sal_Int32 mnOldAngle;
138 long mnCenterX;
139 long mnCenterY;
140 bool mbNoRot;
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 );
156 private:
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 >
168 public:
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;
183 #endif
185 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */