xref: /aoo41x/main/svx/inc/svx/dialcontrol.hxx (revision ee093554)
13334a7e6SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
33334a7e6SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
43334a7e6SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
53334a7e6SAndrew Rist  * distributed with this work for additional information
63334a7e6SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
73334a7e6SAndrew Rist  * to you under the Apache License, Version 2.0 (the
83334a7e6SAndrew Rist  * "License"); you may not use this file except in compliance
93334a7e6SAndrew Rist  * with the License.  You may obtain a copy of the License at
103334a7e6SAndrew Rist  *
113334a7e6SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
123334a7e6SAndrew Rist  *
133334a7e6SAndrew Rist  * Unless required by applicable law or agreed to in writing,
143334a7e6SAndrew Rist  * software distributed under the License is distributed on an
153334a7e6SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
163334a7e6SAndrew Rist  * KIND, either express or implied.  See the License for the
173334a7e6SAndrew Rist  * specific language governing permissions and limitations
183334a7e6SAndrew Rist  * under the License.
193334a7e6SAndrew Rist  *
203334a7e6SAndrew Rist  *************************************************************/
213334a7e6SAndrew Rist 
223334a7e6SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef SVX_DIALCONTROL_HXX
25cdf0e10cSrcweir #define SVX_DIALCONTROL_HXX
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <memory>
28cdf0e10cSrcweir #include <vcl/ctrl.hxx>
29cdf0e10cSrcweir #include <sfx2/itemconnect.hxx>
30cdf0e10cSrcweir #include "svx/svxdllapi.h"
31cdf0e10cSrcweir 
32*ee093554SAndre Fischer #include <boost/scoped_ptr.hpp>
33*ee093554SAndre Fischer 
34cdf0e10cSrcweir class NumericField;
35cdf0e10cSrcweir 
36cdf0e10cSrcweir namespace svx {
37cdf0e10cSrcweir 
38cdf0e10cSrcweir // ============================================================================
39cdf0e10cSrcweir 
40*ee093554SAndre Fischer class DialControlBmp : public VirtualDevice
41*ee093554SAndre Fischer {
42*ee093554SAndre Fischer public:
43*ee093554SAndre Fischer     explicit            DialControlBmp( Window& rParent );
44*ee093554SAndre Fischer 
45*ee093554SAndre Fischer     void                InitBitmap( const Size& rSize, const Font& rFont );
46*ee093554SAndre Fischer     void                CopyBackground( const DialControlBmp& rSrc );
47*ee093554SAndre Fischer     void                DrawBackground( const Size& rSize, bool bEnabled );
48*ee093554SAndre Fischer     virtual void        DrawBackground();
49*ee093554SAndre Fischer     virtual void        DrawElements( const String& rText, sal_Int32 nAngle );
50*ee093554SAndre Fischer 
51*ee093554SAndre Fischer protected:
52*ee093554SAndre Fischer     Rectangle           maRect;
53*ee093554SAndre Fischer     bool                mbEnabled;
54*ee093554SAndre Fischer 
55*ee093554SAndre Fischer private:
56*ee093554SAndre Fischer     const Color&        GetBackgroundColor() const;
57*ee093554SAndre Fischer     const Color&        GetTextColor() const;
58*ee093554SAndre Fischer     const Color&        GetScaleLineColor() const;
59*ee093554SAndre Fischer     const Color&        GetButtonLineColor() const;
60*ee093554SAndre Fischer     const Color&        GetButtonFillColor( bool bMain ) const;
61*ee093554SAndre Fischer 
62*ee093554SAndre Fischer     void                Init( const Size& rSize );
63*ee093554SAndre Fischer 
64*ee093554SAndre Fischer     Window&             mrParent;
65*ee093554SAndre Fischer     long                mnCenterX;
66*ee093554SAndre Fischer     long                mnCenterY;
67*ee093554SAndre Fischer };
68cdf0e10cSrcweir 
69cdf0e10cSrcweir /** This control allows to input a rotation angle, visualized by a dial.
70cdf0e10cSrcweir 
71cdf0e10cSrcweir     Usage: A single click sets a rotation angle rounded to steps of 15 degrees.
72cdf0e10cSrcweir     Dragging with the left mouse button sets an exact rotation angle. Pressing
73cdf0e10cSrcweir     the ESCAPE key during mouse drag cancels the operation and restores the old
74cdf0e10cSrcweir     state of the control.
75cdf0e10cSrcweir 
76cdf0e10cSrcweir     It is possible to link a numeric field to this control using the function
77cdf0e10cSrcweir     SetLinkedField(). The DialControl will take full control of this numeric
78cdf0e10cSrcweir     field:
79cdf0e10cSrcweir     -   Sets the rotation angle to the numeric field in mouse operations.
80cdf0e10cSrcweir     -   Shows the value entered/modified in the numeric field.
81cdf0e10cSrcweir     -   Enables/disables/shows/hides the field according to own state changes.
82cdf0e10cSrcweir  */
83cdf0e10cSrcweir class SVX_DLLPUBLIC DialControl : public Control
84cdf0e10cSrcweir {
85cdf0e10cSrcweir public:
86cdf0e10cSrcweir     explicit            DialControl( Window* pParent, const Size& rSize, const Font& rFont, WinBits nWinStyle = 0 );
87cdf0e10cSrcweir     explicit            DialControl( Window* pParent, const Size& rSize, WinBits nWinStyle = 0 );
88cdf0e10cSrcweir     explicit            DialControl( Window* pParent, const ResId& rResId );
89cdf0e10cSrcweir     virtual             ~DialControl();
90cdf0e10cSrcweir 
91cdf0e10cSrcweir     virtual void        Paint( const Rectangle& rRect );
92cdf0e10cSrcweir 
93cdf0e10cSrcweir     virtual void        StateChanged( StateChangedType nStateChange );
94cdf0e10cSrcweir     virtual void        DataChanged( const DataChangedEvent& rDCEvt );
95cdf0e10cSrcweir 
96cdf0e10cSrcweir     virtual void        MouseButtonDown( const MouseEvent& rMEvt );
97cdf0e10cSrcweir     virtual void        MouseMove( const MouseEvent& rMEvt );
98cdf0e10cSrcweir     virtual void        MouseButtonUp( const MouseEvent& rMEvt );
99cdf0e10cSrcweir     virtual void        KeyInput( const KeyEvent& rKEvt );
100cdf0e10cSrcweir     virtual void        LoseFocus();
101cdf0e10cSrcweir 
102cdf0e10cSrcweir     /** Returns true, if the control is not in "don't care" state. */
103cdf0e10cSrcweir     bool                HasRotation() const;
104cdf0e10cSrcweir     /** Sets the control to "don't care" state. */
105cdf0e10cSrcweir     void                SetNoRotation();
106cdf0e10cSrcweir 
107cdf0e10cSrcweir     /** Returns the current rotation angle in 1/100 degrees. */
108cdf0e10cSrcweir     sal_Int32           GetRotation() const;
109cdf0e10cSrcweir     /** Sets the rotation to the passed value (in 1/100 degrees). */
110cdf0e10cSrcweir     void                SetRotation( sal_Int32 nAngle );
111cdf0e10cSrcweir 
112cdf0e10cSrcweir     /** Links the passed numeric edit field to the control (bi-directional). */
113cdf0e10cSrcweir     void                SetLinkedField( NumericField* pField );
114cdf0e10cSrcweir     /** Returns the linked numeric edit field, or 0. */
115cdf0e10cSrcweir     NumericField*       GetLinkedField() const;
116cdf0e10cSrcweir 
117cdf0e10cSrcweir     /** The passed handler is called whenever the totation value changes. */
118cdf0e10cSrcweir     void                SetModifyHdl( const Link& rLink );
119cdf0e10cSrcweir     /** Returns the current modify handler. */
120cdf0e10cSrcweir     const Link&         GetModifyHdl() const;
121cdf0e10cSrcweir 
122*ee093554SAndre Fischer protected:
123*ee093554SAndre Fischer     struct DialControl_Impl
124*ee093554SAndre Fischer     {
125*ee093554SAndre Fischer         ::boost::scoped_ptr<DialControlBmp>      mpBmpEnabled;
126*ee093554SAndre Fischer         ::boost::scoped_ptr<DialControlBmp>      mpBmpDisabled;
127*ee093554SAndre Fischer         ::boost::scoped_ptr<DialControlBmp>      mpBmpBuffered;
128*ee093554SAndre Fischer         Link                maModifyHdl;
129*ee093554SAndre Fischer         NumericField*       mpLinkField;
130*ee093554SAndre Fischer         Size                maWinSize;
131*ee093554SAndre Fischer         Font                maWinFont;
132*ee093554SAndre Fischer         sal_Int32           mnAngle;
133*ee093554SAndre Fischer         sal_Int32           mnOldAngle;
134*ee093554SAndre Fischer         long                mnCenterX;
135*ee093554SAndre Fischer         long                mnCenterY;
136*ee093554SAndre Fischer         bool                mbNoRot;
137*ee093554SAndre Fischer 
138*ee093554SAndre Fischer         explicit            DialControl_Impl( Window& rParent );
139*ee093554SAndre Fischer         void                Init( const Size& rWinSize, const Font& rWinFont );
140*ee093554SAndre Fischer     };
141*ee093554SAndre Fischer     std::auto_ptr< DialControl_Impl > mpImpl;
142*ee093554SAndre Fischer 
143*ee093554SAndre Fischer     virtual void        HandleMouseEvent( const Point& rPos, bool bInitial );
144*ee093554SAndre Fischer     virtual void        HandleEscapeEvent();
145*ee093554SAndre Fischer 
146*ee093554SAndre Fischer     void                SetRotation( sal_Int32 nAngle, bool bBroadcast );
147*ee093554SAndre Fischer 
148cdf0e10cSrcweir     void                Init( const Size& rWinSize, const Font& rWinFont );
149cdf0e10cSrcweir     void                Init( const Size& rWinSize );
150*ee093554SAndre Fischer 
151*ee093554SAndre Fischer private:
152cdf0e10cSrcweir     void                InvalidateControl();
153cdf0e10cSrcweir 
154cdf0e10cSrcweir     void                ImplSetFieldLink( const Link& rLink );
155cdf0e10cSrcweir 
156cdf0e10cSrcweir 
157cdf0e10cSrcweir     DECL_LINK( LinkedFieldModifyHdl, NumericField* );
158cdf0e10cSrcweir };
159cdf0e10cSrcweir 
160cdf0e10cSrcweir // ============================================================================
161cdf0e10cSrcweir 
162cdf0e10cSrcweir /** Wrapper for usage of a DialControl in item connections. */
163cdf0e10cSrcweir class SVX_DLLPUBLIC DialControlWrapper : public sfx::SingleControlWrapper< DialControl, sal_Int32 >
164cdf0e10cSrcweir {
165cdf0e10cSrcweir public:
166cdf0e10cSrcweir     explicit            DialControlWrapper( DialControl& rDial );
167cdf0e10cSrcweir 
168cdf0e10cSrcweir     virtual bool        IsControlDontKnow() const;
169cdf0e10cSrcweir     virtual void        SetControlDontKnow( bool bSet );
170cdf0e10cSrcweir 
171cdf0e10cSrcweir     virtual sal_Int32   GetControlValue() const;
172cdf0e10cSrcweir     virtual void        SetControlValue( sal_Int32 nValue );
173cdf0e10cSrcweir };
174cdf0e10cSrcweir 
175cdf0e10cSrcweir // ----------------------------------------------------------------------------
176cdf0e10cSrcweir 
177cdf0e10cSrcweir /** An item<->control connection for a DialControl. */
178cdf0e10cSrcweir typedef sfx::ItemControlConnection< sfx::Int32ItemWrapper, DialControlWrapper > DialControlConnection;
179cdf0e10cSrcweir 
180cdf0e10cSrcweir // ============================================================================
181cdf0e10cSrcweir 
182cdf0e10cSrcweir } // namespace svx
183cdf0e10cSrcweir 
184cdf0e10cSrcweir #endif
185cdf0e10cSrcweir 
186