xref: /trunk/main/svx/inc/svx/dialcontrol.hxx (revision ee093554)
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 #include <boost/scoped_ptr.hpp>
33 
34 class NumericField;
35 
36 namespace svx {
37 
38 // ============================================================================
39 
40 class DialControlBmp : public VirtualDevice
41 {
42 public:
43     explicit            DialControlBmp( Window& rParent );
44 
45     void                InitBitmap( const Size& rSize, const Font& rFont );
46     void                CopyBackground( const DialControlBmp& rSrc );
47     void                DrawBackground( const Size& rSize, bool bEnabled );
48     virtual void        DrawBackground();
49     virtual void        DrawElements( const String& rText, sal_Int32 nAngle );
50 
51 protected:
52     Rectangle           maRect;
53     bool                mbEnabled;
54 
55 private:
56     const Color&        GetBackgroundColor() const;
57     const Color&        GetTextColor() const;
58     const Color&        GetScaleLineColor() const;
59     const Color&        GetButtonLineColor() const;
60     const Color&        GetButtonFillColor( bool bMain ) const;
61 
62     void                Init( const Size& rSize );
63 
64     Window&             mrParent;
65     long                mnCenterX;
66     long                mnCenterY;
67 };
68 
69 /** This control allows to input a rotation angle, visualized by a dial.
70 
71     Usage: A single click sets a rotation angle rounded to steps of 15 degrees.
72     Dragging with the left mouse button sets an exact rotation angle. Pressing
73     the ESCAPE key during mouse drag cancels the operation and restores the old
74     state of the control.
75 
76     It is possible to link a numeric field to this control using the function
77     SetLinkedField(). The DialControl will take full control of this numeric
78     field:
79     -   Sets the rotation angle to the numeric field in mouse operations.
80     -   Shows the value entered/modified in the numeric field.
81     -   Enables/disables/shows/hides the field according to own state changes.
82  */
83 class SVX_DLLPUBLIC DialControl : public Control
84 {
85 public:
86     explicit            DialControl( Window* pParent, const Size& rSize, const Font& rFont, WinBits nWinStyle = 0 );
87     explicit            DialControl( Window* pParent, const Size& rSize, WinBits nWinStyle = 0 );
88     explicit            DialControl( Window* pParent, const ResId& rResId );
89     virtual             ~DialControl();
90 
91     virtual void        Paint( const Rectangle& rRect );
92 
93     virtual void        StateChanged( StateChangedType nStateChange );
94     virtual void        DataChanged( const DataChangedEvent& rDCEvt );
95 
96     virtual void        MouseButtonDown( const MouseEvent& rMEvt );
97     virtual void        MouseMove( const MouseEvent& rMEvt );
98     virtual void        MouseButtonUp( const MouseEvent& rMEvt );
99     virtual void        KeyInput( const KeyEvent& rKEvt );
100     virtual void        LoseFocus();
101 
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();
106 
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 );
111 
112     /** Links the passed numeric edit field to the control (bi-directional). */
113     void                SetLinkedField( NumericField* pField );
114     /** Returns the linked numeric edit field, or 0. */
115     NumericField*       GetLinkedField() const;
116 
117     /** The passed handler is called whenever the totation value changes. */
118     void                SetModifyHdl( const Link& rLink );
119     /** Returns the current modify handler. */
120     const Link&         GetModifyHdl() const;
121 
122 protected:
123     struct DialControl_Impl
124     {
125         ::boost::scoped_ptr<DialControlBmp>      mpBmpEnabled;
126         ::boost::scoped_ptr<DialControlBmp>      mpBmpDisabled;
127         ::boost::scoped_ptr<DialControlBmp>      mpBmpBuffered;
128         Link                maModifyHdl;
129         NumericField*       mpLinkField;
130         Size                maWinSize;
131         Font                maWinFont;
132         sal_Int32           mnAngle;
133         sal_Int32           mnOldAngle;
134         long                mnCenterX;
135         long                mnCenterY;
136         bool                mbNoRot;
137 
138         explicit            DialControl_Impl( Window& rParent );
139         void                Init( const Size& rWinSize, const Font& rWinFont );
140     };
141     std::auto_ptr< DialControl_Impl > mpImpl;
142 
143     virtual void        HandleMouseEvent( const Point& rPos, bool bInitial );
144     virtual void        HandleEscapeEvent();
145 
146     void                SetRotation( sal_Int32 nAngle, bool bBroadcast );
147 
148     void                Init( const Size& rWinSize, const Font& rWinFont );
149     void                Init( const Size& rWinSize );
150 
151 private:
152     void                InvalidateControl();
153 
154     void                ImplSetFieldLink( const Link& rLink );
155 
156 
157     DECL_LINK( LinkedFieldModifyHdl, NumericField* );
158 };
159 
160 // ============================================================================
161 
162 /** Wrapper for usage of a DialControl in item connections. */
163 class SVX_DLLPUBLIC DialControlWrapper : public sfx::SingleControlWrapper< DialControl, sal_Int32 >
164 {
165 public:
166     explicit            DialControlWrapper( DialControl& rDial );
167 
168     virtual bool        IsControlDontKnow() const;
169     virtual void        SetControlDontKnow( bool bSet );
170 
171     virtual sal_Int32   GetControlValue() const;
172     virtual void        SetControlValue( sal_Int32 nValue );
173 };
174 
175 // ----------------------------------------------------------------------------
176 
177 /** An item<->control connection for a DialControl. */
178 typedef sfx::ItemControlConnection< sfx::Int32ItemWrapper, DialControlWrapper > DialControlConnection;
179 
180 // ============================================================================
181 
182 } // namespace svx
183 
184 #endif
185 
186