Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / include / svx / dialcontrol.hxx
blobc12f3c97652b03ce71ee68572880b2d37e6a0813
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 {
33 class SAL_WARN_UNUSED DialControlBmp : public VirtualDevice
35 public:
36 explicit DialControlBmp( vcl::Window& rParent );
38 void InitBitmap(const vcl::Font& rFont);
39 void SetSize(const Size& rSize);
40 void CopyBackground( const DialControlBmp& rSrc );
41 void DrawBackground( const Size& rSize, bool bEnabled );
42 void DrawBackground();
43 void DrawElements( const OUString& rText, sal_Int32 nAngle );
45 protected:
46 tools::Rectangle maRect;
47 bool mbEnabled;
49 private:
50 const Color& GetBackgroundColor() const;
51 const Color& GetTextColor() const;
52 const Color& GetScaleLineColor() const;
53 const Color& GetButtonLineColor() const;
54 const Color& GetButtonFillColor( bool bMain ) const;
56 void Init();
58 vcl::Window& mrParent;
59 long mnCenterX;
60 long mnCenterY;
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
68 state of the control.
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
72 field:
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
79 public:
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 true, if the control is not in "don't care" state. */
97 bool HasRotation() const;
98 /** Sets the control to "don't care" state. */
99 void SetNoRotation();
101 /** Returns the current rotation angle in 1/100 degrees. */
102 sal_Int32 GetRotation() const;
103 /** Sets the rotation to the passed value (in 1/100 degrees). */
104 void SetRotation( sal_Int32 nAngle );
106 /** Links the passed numeric edit field to the control (bi-directional).
107 * nDecimalPlaces:
108 * field value is unsign given decimal places
109 * default is 0 which means field values are in degrees,
110 * 2 means 100th of degree
112 void SetLinkedField( NumericField* pField, sal_Int32 nDecimalPlaces = 0);
114 /** The passed handler is called whenever the rotation value changes. */
115 void SetModifyHdl( const Link<DialControl*,void>& rLink );
117 /** Save value for later comparison */
118 void SaveValue();
120 /** Compare value with the saved value */
121 bool IsValueModified();
123 protected:
124 struct DialControl_Impl
126 ScopedVclPtr<DialControlBmp> mxBmpEnabled;
127 ScopedVclPtr<DialControlBmp> mxBmpDisabled;
128 ScopedVclPtr<DialControlBmp> mxBmpBuffered;
129 Link<DialControl*,void> maModifyHdl;
130 VclPtr<NumericField> mpLinkField;
131 sal_Int32 mnLinkedFieldValueMultiplyer;
132 Size maWinSize;
133 vcl::Font maWinFont;
134 sal_Int32 mnAngle;
135 sal_Int32 mnInitialAngle;
136 sal_Int32 mnOldAngle;
137 long mnCenterX;
138 long mnCenterY;
139 bool mbNoRot;
141 explicit DialControl_Impl( vcl::Window& rParent );
142 void Init( const Size& rWinSize, const vcl::Font& rWinFont );
143 void SetSize( const Size& rWinSize );
145 std::unique_ptr< DialControl_Impl > mpImpl;
147 virtual void HandleMouseEvent( const Point& rPos, bool bInitial );
148 void HandleEscapeEvent();
150 void SetRotation( sal_Int32 nAngle, bool bBroadcast );
152 void Init( const Size& rWinSize, const vcl::Font& rWinFont );
153 void Init( const Size& rWinSize );
155 private:
156 void InvalidateControl();
158 DECL_LINK( LinkedFieldModifyHdl, Edit&, void );
159 DECL_LINK( LinkedFieldFocusHdl, Control&, void );
160 void LinkedFieldModifyHdl();
161 DECL_LINK(SpinFieldHdl, SpinField&, void);
164 /** Wrapper for usage of a DialControl in item connections. */
165 class SAL_WARN_UNUSED SVX_DLLPUBLIC DialControlWrapper : public sfx::SingleControlWrapper< DialControl, sal_Int32 >
167 public:
168 explicit DialControlWrapper( DialControl& rDial );
170 virtual bool IsControlDontKnow() const override;
171 virtual void SetControlDontKnow( bool bSet ) override;
173 virtual sal_Int32 GetControlValue() const override;
174 virtual void SetControlValue( sal_Int32 nValue ) override;
177 /** An item<->control connection for a DialControl. */
178 typedef sfx::ItemControlConnection< sfx::Int32ItemWrapper, DialControlWrapper > DialControlConnection;
182 #endif
184 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */