1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: dialcontrol.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef SVX_DIALCONTROL_HXX
32 #define SVX_DIALCONTROL_HXX
35 #include <vcl/ctrl.hxx>
36 #include <sfx2/itemconnect.hxx>
37 #include "svx/svxdllapi.h"
43 // ============================================================================
45 struct DialControl_Impl
;
47 /** This control allows to input a rotation angle, visualized by a dial.
49 Usage: A single click sets a rotation angle rounded to steps of 15 degrees.
50 Dragging with the left mouse button sets an exact rotation angle. Pressing
51 the ESCAPE key during mouse drag cancels the operation and restores the old
54 It is possible to link a numeric field to this control using the function
55 SetLinkedField(). The DialControl will take full control of this numeric
57 - Sets the rotation angle to the numeric field in mouse operations.
58 - Shows the value entered/modified in the numeric field.
59 - Enables/disables/shows/hides the field according to own state changes.
61 class SVX_DLLPUBLIC DialControl
: public Control
64 explicit DialControl( Window
* pParent
, const Size
& rSize
, const Font
& rFont
, WinBits nWinStyle
= 0 );
65 explicit DialControl( Window
* pParent
, const Size
& rSize
, WinBits nWinStyle
= 0 );
66 explicit DialControl( Window
* pParent
, const ResId
& rResId
);
67 virtual ~DialControl();
69 virtual void Paint( const Rectangle
& rRect
);
71 virtual void StateChanged( StateChangedType nStateChange
);
72 virtual void DataChanged( const DataChangedEvent
& rDCEvt
);
74 virtual void MouseButtonDown( const MouseEvent
& rMEvt
);
75 virtual void MouseMove( const MouseEvent
& rMEvt
);
76 virtual void MouseButtonUp( const MouseEvent
& rMEvt
);
77 virtual void KeyInput( const KeyEvent
& rKEvt
);
78 virtual void LoseFocus();
80 /** Returns true, if the control is not in "don't care" state. */
81 bool HasRotation() const;
82 /** Sets the control to "don't care" state. */
85 /** Returns the current rotation angle in 1/100 degrees. */
86 sal_Int32
GetRotation() const;
87 /** Sets the rotation to the passed value (in 1/100 degrees). */
88 void SetRotation( sal_Int32 nAngle
);
90 /** Links the passed numeric edit field to the control (bi-directional). */
91 void SetLinkedField( NumericField
* pField
);
92 /** Returns the linked numeric edit field, or 0. */
93 NumericField
* GetLinkedField() const;
95 /** The passed handler is called whenever the totation value changes. */
96 void SetModifyHdl( const Link
& rLink
);
97 /** Returns the current modify handler. */
98 const Link
& GetModifyHdl() const;
101 void Init( const Size
& rWinSize
, const Font
& rWinFont
);
102 void Init( const Size
& rWinSize
);
103 void InvalidateControl();
105 void ImplSetRotation( sal_Int32 nAngle
, bool bBroadcast
);
106 void ImplSetFieldLink( const Link
& rLink
);
108 void HandleMouseEvent( const Point
& rPos
, bool bInitial
);
109 void HandleEscapeEvent();
111 DECL_LINK( LinkedFieldModifyHdl
, NumericField
* );
113 std::auto_ptr
< DialControl_Impl
> mpImpl
;
116 // ============================================================================
118 /** Wrapper for usage of a DialControl in item connections. */
119 class SVX_DLLPUBLIC DialControlWrapper
: public sfx::SingleControlWrapper
< DialControl
, sal_Int32
>
122 explicit DialControlWrapper( DialControl
& rDial
);
124 virtual bool IsControlDontKnow() const;
125 virtual void SetControlDontKnow( bool bSet
);
127 virtual sal_Int32
GetControlValue() const;
128 virtual void SetControlValue( sal_Int32 nValue
);
131 // ----------------------------------------------------------------------------
133 /** An item<->control connection for a DialControl. */
134 typedef sfx::ItemControlConnection
< sfx::Int32ItemWrapper
, DialControlWrapper
> DialControlConnection
;
136 // ============================================================================