Version 4.3.0.0.beta1, tag libreoffice-4.3.0.0.beta1
[LibreOffice.git] / include / svx / dialcontrol.hxx
blobe6b1c23eef840d2e6a84d7403e4e7085f2a12b8a
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 #include <boost/scoped_ptr.hpp>
30 class NumericField;
32 namespace svx {
36 class DialControlBmp : public VirtualDevice
38 public:
39 explicit DialControlBmp( Window& rParent );
41 void InitBitmap(const Font& rFont);
42 void SetSize(const Size& rSize);
43 void CopyBackground( const DialControlBmp& rSrc );
44 void DrawBackground( const Size& rSize, bool bEnabled );
45 virtual void DrawBackground();
46 virtual void DrawElements( const OUString& rText, sal_Int32 nAngle );
48 protected:
49 Rectangle maRect;
50 bool mbEnabled;
52 private:
53 const Color& GetBackgroundColor() const;
54 const Color& GetTextColor() const;
55 const Color& GetScaleLineColor() const;
56 const Color& GetButtonLineColor() const;
57 const Color& GetButtonFillColor( bool bMain ) const;
59 void Init();
61 Window& mrParent;
62 long mnCenterX;
63 long mnCenterY;
66 /** This control allows to input a rotation angle, visualized by a dial.
68 Usage: A single click sets a rotation angle rounded to steps of 15 degrees.
69 Dragging with the left mouse button sets an exact rotation angle. Pressing
70 the ESCAPE key during mouse drag cancels the operation and restores the old
71 state of the control.
73 It is possible to link a numeric field to this control using the function
74 SetLinkedField(). The DialControl will take full control of this numeric
75 field:
76 - Sets the rotation angle to the numeric field in mouse operations.
77 - Shows the value entered/modified in the numeric field.
78 - Enables/disables/shows/hides the field according to own state changes.
80 class SVX_DLLPUBLIC DialControl : public Control
82 public:
83 explicit DialControl( Window* pParent, WinBits nBits );
85 virtual ~DialControl();
87 virtual void Paint( const Rectangle& rRect ) SAL_OVERRIDE;
89 virtual void StateChanged( StateChangedType nStateChange ) SAL_OVERRIDE;
90 virtual void DataChanged( const DataChangedEvent& rDCEvt ) SAL_OVERRIDE;
92 virtual void MouseButtonDown( const MouseEvent& rMEvt ) SAL_OVERRIDE;
93 virtual void MouseMove( const MouseEvent& rMEvt ) SAL_OVERRIDE;
94 virtual void MouseButtonUp( const MouseEvent& rMEvt ) SAL_OVERRIDE;
95 virtual void KeyInput( const KeyEvent& rKEvt ) SAL_OVERRIDE;
96 virtual void LoseFocus() SAL_OVERRIDE;
98 virtual Size GetOptimalSize() const SAL_OVERRIDE;
99 virtual void Resize() SAL_OVERRIDE;
101 /** Returns true, if the control is not in "don't care" state. */
102 bool HasRotation() const;
103 /** Sets the control to "don't care" state. */
104 void SetNoRotation();
106 /** Returns the current rotation angle in 1/100 degrees. */
107 sal_Int32 GetRotation() const;
108 /** Sets the rotation to the passed value (in 1/100 degrees). */
109 void SetRotation( sal_Int32 nAngle );
111 /** Links the passed numeric edit field to the control (bi-directional).
112 * nDecimalPlaces:
113 * field value is usign given decimal places
114 * default is 0 which means field values are in degrees,
115 * 2 means 100th of degree
117 void SetLinkedField( NumericField* pField, sal_Int32 nDecimalPlaces = 0);
119 /** The passed handler is called whenever the totation value changes. */
120 void SetModifyHdl( const Link& rLink );
122 /** Save value for later comparison */
123 void SaveValue();
125 /** Compare value with the saved value */
126 bool IsValueModified();
128 protected:
129 struct DialControl_Impl
131 ::boost::scoped_ptr<DialControlBmp> mpBmpEnabled;
132 ::boost::scoped_ptr<DialControlBmp> mpBmpDisabled;
133 ::boost::scoped_ptr<DialControlBmp> mpBmpBuffered;
134 Link maModifyHdl;
135 NumericField* mpLinkField;
136 sal_Int32 mnLinkedFieldValueMultiplyer;
137 Size maWinSize;
138 Font maWinFont;
139 sal_Int32 mnAngle;
140 sal_Int32 mnInitialAngle;
141 sal_Int32 mnOldAngle;
142 long mnCenterX;
143 long mnCenterY;
144 bool mbNoRot;
146 explicit DialControl_Impl( Window& rParent );
147 void Init( const Size& rWinSize, const Font& rWinFont );
148 void SetSize( const Size& rWinSize );
150 std::auto_ptr< DialControl_Impl > mpImpl;
152 virtual void HandleMouseEvent( const Point& rPos, bool bInitial );
153 virtual void HandleEscapeEvent();
155 void SetRotation( sal_Int32 nAngle, bool bBroadcast );
157 void Init( const Size& rWinSize, const Font& rWinFont );
158 void Init( const Size& rWinSize );
160 private:
161 void InvalidateControl();
163 void ImplSetFieldLink( const Link& rLink );
166 DECL_LINK( LinkedFieldModifyHdl, NumericField* );
171 /** Wrapper for usage of a DialControl in item connections. */
172 class SVX_DLLPUBLIC DialControlWrapper : public sfx::SingleControlWrapper< DialControl, sal_Int32 >
174 public:
175 explicit DialControlWrapper( DialControl& rDial );
177 virtual bool IsControlDontKnow() const SAL_OVERRIDE;
178 virtual void SetControlDontKnow( bool bSet ) SAL_OVERRIDE;
180 virtual sal_Int32 GetControlValue() const SAL_OVERRIDE;
181 virtual void SetControlValue( sal_Int32 nValue ) SAL_OVERRIDE;
186 /** An item<->control connection for a DialControl. */
187 typedef sfx::ItemControlConnection< sfx::Int32ItemWrapper, DialControlWrapper > DialControlConnection;
191 } // namespace svx
193 #endif
195 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */