xref: /aoo42x/main/svx/inc/svx/dialcontrol.hxx (revision 3334a7e6)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef SVX_DIALCONTROL_HXX
25 #define SVX_DIALCONTROL_HXX
26 
27 #include <memory>
28 #include <vcl/ctrl.hxx>
29 #include <sfx2/itemconnect.hxx>
30 #include "svx/svxdllapi.h"
31 
32 class NumericField;
33 
34 namespace svx {
35 
36 // ============================================================================
37 
38 struct DialControl_Impl;
39 
40 /** This control allows to input a rotation angle, visualized by a dial.
41 
42     Usage: A single click sets a rotation angle rounded to steps of 15 degrees.
43     Dragging with the left mouse button sets an exact rotation angle. Pressing
44     the ESCAPE key during mouse drag cancels the operation and restores the old
45     state of the control.
46 
47     It is possible to link a numeric field to this control using the function
48     SetLinkedField(). The DialControl will take full control of this numeric
49     field:
50     -   Sets the rotation angle to the numeric field in mouse operations.
51     -   Shows the value entered/modified in the numeric field.
52     -   Enables/disables/shows/hides the field according to own state changes.
53  */
54 class SVX_DLLPUBLIC DialControl : public Control
55 {
56 public:
57     explicit            DialControl( Window* pParent, const Size& rSize, const Font& rFont, WinBits nWinStyle = 0 );
58     explicit            DialControl( Window* pParent, const Size& rSize, WinBits nWinStyle = 0 );
59     explicit            DialControl( Window* pParent, const ResId& rResId );
60     virtual             ~DialControl();
61 
62     virtual void        Paint( const Rectangle& rRect );
63 
64     virtual void        StateChanged( StateChangedType nStateChange );
65     virtual void        DataChanged( const DataChangedEvent& rDCEvt );
66 
67     virtual void        MouseButtonDown( const MouseEvent& rMEvt );
68     virtual void        MouseMove( const MouseEvent& rMEvt );
69     virtual void        MouseButtonUp( const MouseEvent& rMEvt );
70     virtual void        KeyInput( const KeyEvent& rKEvt );
71     virtual void        LoseFocus();
72 
73     /** Returns true, if the control is not in "don't care" state. */
74     bool                HasRotation() const;
75     /** Sets the control to "don't care" state. */
76     void                SetNoRotation();
77 
78     /** Returns the current rotation angle in 1/100 degrees. */
79     sal_Int32           GetRotation() const;
80     /** Sets the rotation to the passed value (in 1/100 degrees). */
81     void                SetRotation( sal_Int32 nAngle );
82 
83     /** Links the passed numeric edit field to the control (bi-directional). */
84     void                SetLinkedField( NumericField* pField );
85     /** Returns the linked numeric edit field, or 0. */
86     NumericField*       GetLinkedField() const;
87 
88     /** The passed handler is called whenever the totation value changes. */
89     void                SetModifyHdl( const Link& rLink );
90     /** Returns the current modify handler. */
91     const Link&         GetModifyHdl() const;
92 
93 private:
94     void                Init( const Size& rWinSize, const Font& rWinFont );
95     void                Init( const Size& rWinSize );
96     void                InvalidateControl();
97 
98     void                ImplSetRotation( sal_Int32 nAngle, bool bBroadcast );
99     void                ImplSetFieldLink( const Link& rLink );
100 
101     void                HandleMouseEvent( const Point& rPos, bool bInitial );
102     void                HandleEscapeEvent();
103 
104     DECL_LINK( LinkedFieldModifyHdl, NumericField* );
105 
106     std::auto_ptr< DialControl_Impl > mpImpl;
107 };
108 
109 // ============================================================================
110 
111 /** Wrapper for usage of a DialControl in item connections. */
112 class SVX_DLLPUBLIC DialControlWrapper : public sfx::SingleControlWrapper< DialControl, sal_Int32 >
113 {
114 public:
115     explicit            DialControlWrapper( DialControl& rDial );
116 
117     virtual bool        IsControlDontKnow() const;
118     virtual void        SetControlDontKnow( bool bSet );
119 
120     virtual sal_Int32   GetControlValue() const;
121     virtual void        SetControlValue( sal_Int32 nValue );
122 };
123 
124 // ----------------------------------------------------------------------------
125 
126 /** An item<->control connection for a DialControl. */
127 typedef sfx::ItemControlConnection< sfx::Int32ItemWrapper, DialControlWrapper > DialControlConnection;
128 
129 // ============================================================================
130 
131 } // namespace svx
132 
133 #endif
134 
135