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 SVX_DIALCONTROL_HXX
21 #define SVX_DIALCONTROL_HXX
24 #include <vcl/ctrl.hxx>
25 #include <sfx2/itemconnect.hxx>
26 #include "svx/svxdllapi.h"
28 #include <boost/scoped_ptr.hpp>
34 // ============================================================================
36 class DialControlBmp
: public VirtualDevice
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 String
& rText
, sal_Int32 nAngle
);
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;
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
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
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
83 explicit DialControl( Window
* pParent
, const ResId
& rResId
);
84 explicit DialControl( Window
* pParent
, WinBits nBits
);
86 virtual ~DialControl();
88 virtual void Paint( const Rectangle
& rRect
);
90 virtual void StateChanged( StateChangedType nStateChange
);
91 virtual void DataChanged( const DataChangedEvent
& rDCEvt
);
93 virtual void MouseButtonDown( const MouseEvent
& rMEvt
);
94 virtual void MouseMove( const MouseEvent
& rMEvt
);
95 virtual void MouseButtonUp( const MouseEvent
& rMEvt
);
96 virtual void KeyInput( const KeyEvent
& rKEvt
);
97 virtual void LoseFocus();
99 virtual Size
GetOptimalSize() const;
100 virtual void Resize();
102 /** Returns true, if the control is not in "don't care" state. */
103 bool HasRotation() const;
104 /** Sets the control to "don't care" state. */
105 void SetNoRotation();
107 /** Returns the current rotation angle in 1/100 degrees. */
108 sal_Int32
GetRotation() const;
109 /** Sets the rotation to the passed value (in 1/100 degrees). */
110 void SetRotation( sal_Int32 nAngle
);
112 /** Links the passed numeric edit field to the control (bi-directional).
114 * field value is usign given decimal places
115 * default is 0 which means field values are in degrees,
116 * 2 means 100th of degree
118 void SetLinkedField( NumericField
* pField
, sal_Int32 nDecimalPlaces
= 0);
119 /** Returns the linked numeric edit field, or 0. */
120 NumericField
* GetLinkedField() const;
122 /** The passed handler is called whenever the totation value changes. */
123 void SetModifyHdl( const Link
& rLink
);
124 /** Returns the current modify handler. */
125 const Link
& GetModifyHdl() const;
127 /** Save value for later comparison */
130 /** Compare value with the saved value */
131 bool IsValueModified();
134 struct DialControl_Impl
136 ::boost::scoped_ptr
<DialControlBmp
> mpBmpEnabled
;
137 ::boost::scoped_ptr
<DialControlBmp
> mpBmpDisabled
;
138 ::boost::scoped_ptr
<DialControlBmp
> mpBmpBuffered
;
140 NumericField
* mpLinkField
;
141 sal_Int32 mnLinkedFieldValueMultiplyer
;
145 sal_Int32 mnInitialAngle
;
146 sal_Int32 mnOldAngle
;
151 explicit DialControl_Impl( Window
& rParent
);
152 void Init( const Size
& rWinSize
, const Font
& rWinFont
);
153 void SetSize( const Size
& rWinSize
);
155 std::auto_ptr
< DialControl_Impl
> mpImpl
;
157 virtual void HandleMouseEvent( const Point
& rPos
, bool bInitial
);
158 virtual void HandleEscapeEvent();
160 void SetRotation( sal_Int32 nAngle
, bool bBroadcast
);
162 void Init( const Size
& rWinSize
, const Font
& rWinFont
);
163 void Init( const Size
& rWinSize
);
166 void InvalidateControl();
168 void ImplSetFieldLink( const Link
& rLink
);
171 DECL_LINK( LinkedFieldModifyHdl
, NumericField
* );
174 // ============================================================================
176 /** Wrapper for usage of a DialControl in item connections. */
177 class SVX_DLLPUBLIC DialControlWrapper
: public sfx::SingleControlWrapper
< DialControl
, sal_Int32
>
180 explicit DialControlWrapper( DialControl
& rDial
);
182 virtual bool IsControlDontKnow() const;
183 virtual void SetControlDontKnow( bool bSet
);
185 virtual sal_Int32
GetControlValue() const;
186 virtual void SetControlValue( sal_Int32 nValue
);
189 // ----------------------------------------------------------------------------
191 /** An item<->control connection for a DialControl. */
192 typedef sfx::ItemControlConnection
< sfx::Int32ItemWrapper
, DialControlWrapper
> DialControlConnection
;
194 // ============================================================================
200 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */