xref: /aoo42x/main/svx/source/dialog/dialcontrol.cxx (revision ee093554)
1f6e50924SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3f6e50924SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4f6e50924SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5f6e50924SAndrew Rist  * distributed with this work for additional information
6f6e50924SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7f6e50924SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8f6e50924SAndrew Rist  * "License"); you may not use this file except in compliance
9f6e50924SAndrew Rist  * with the License.  You may obtain a copy of the License at
10f6e50924SAndrew Rist  *
11f6e50924SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12f6e50924SAndrew Rist  *
13f6e50924SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14f6e50924SAndrew Rist  * software distributed under the License is distributed on an
15f6e50924SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16f6e50924SAndrew Rist  * KIND, either express or implied.  See the License for the
17f6e50924SAndrew Rist  * specific language governing permissions and limitations
18f6e50924SAndrew Rist  * under the License.
19f6e50924SAndrew Rist  *
20f6e50924SAndrew Rist  *************************************************************/
21f6e50924SAndrew Rist 
22f6e50924SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_svx.hxx"
26cdf0e10cSrcweir #include "svx/dialcontrol.hxx"
27*ee093554SAndre Fischer #include "bmpmask.hrc"
28*ee093554SAndre Fischer #include <svx/dialmgr.hxx>
29*ee093554SAndre Fischer #include <tools/rcid.h>
30cdf0e10cSrcweir #include <math.h>
31cdf0e10cSrcweir #include <vcl/virdev.hxx>
32cdf0e10cSrcweir #include <vcl/svapp.hxx>
33cdf0e10cSrcweir #include <vcl/bitmap.hxx>
34cdf0e10cSrcweir #include <vcl/field.hxx>
35cdf0e10cSrcweir #include <svtools/colorcfg.hxx>
36cdf0e10cSrcweir 
37cdf0e10cSrcweir namespace svx {
38cdf0e10cSrcweir 
39cdf0e10cSrcweir // ============================================================================
40cdf0e10cSrcweir 
41cdf0e10cSrcweir const long DIAL_OUTER_WIDTH = 8;
42cdf0e10cSrcweir 
43cdf0e10cSrcweir // ============================================================================
44cdf0e10cSrcweir 
45cdf0e10cSrcweir 
46cdf0e10cSrcweir // ----------------------------------------------------------------------------
47cdf0e10cSrcweir 
DialControlBmp(Window & rParent)48cdf0e10cSrcweir DialControlBmp::DialControlBmp( Window& rParent ) :
49cdf0e10cSrcweir     VirtualDevice( rParent, 0, 0 ),
50*ee093554SAndre Fischer     mbEnabled( true ),
51*ee093554SAndre Fischer     mrParent( rParent )
52cdf0e10cSrcweir {
53cdf0e10cSrcweir     EnableRTL( sal_False );
54cdf0e10cSrcweir }
55cdf0e10cSrcweir 
InitBitmap(const Size & rSize,const Font & rFont)56cdf0e10cSrcweir void DialControlBmp::InitBitmap( const Size& rSize, const Font& rFont )
57cdf0e10cSrcweir {
58cdf0e10cSrcweir     Init( rSize );
59cdf0e10cSrcweir     SetFont( rFont );
60cdf0e10cSrcweir }
61cdf0e10cSrcweir 
CopyBackground(const DialControlBmp & rSrc)62cdf0e10cSrcweir void DialControlBmp::CopyBackground( const DialControlBmp& rSrc )
63cdf0e10cSrcweir {
64cdf0e10cSrcweir     Init( rSrc.maRect.GetSize() );
65cdf0e10cSrcweir     mbEnabled = rSrc.mbEnabled;
66cdf0e10cSrcweir     Point aPos;
67cdf0e10cSrcweir     DrawBitmapEx( aPos, rSrc.GetBitmapEx( aPos, maRect.GetSize() ) );
68cdf0e10cSrcweir }
69cdf0e10cSrcweir 
DrawBackground(const Size & rSize,bool bEnabled)70cdf0e10cSrcweir void DialControlBmp::DrawBackground( const Size& rSize, bool bEnabled )
71cdf0e10cSrcweir {
72cdf0e10cSrcweir     Init( rSize );
73cdf0e10cSrcweir     mbEnabled = bEnabled;
74cdf0e10cSrcweir     DrawBackground();
75cdf0e10cSrcweir }
76cdf0e10cSrcweir 
DrawElements(const String & rText,sal_Int32 nAngle)77cdf0e10cSrcweir void DialControlBmp::DrawElements( const String& rText, sal_Int32 nAngle )
78cdf0e10cSrcweir {
79cdf0e10cSrcweir     // *** rotated text ***
80cdf0e10cSrcweir 
81cdf0e10cSrcweir     Font aFont( GetFont() );
82cdf0e10cSrcweir     aFont.SetColor( GetTextColor() );
83cdf0e10cSrcweir     aFont.SetOrientation( static_cast< short >( (nAngle + 5) / 10 ) );  // Font uses 1/10 degrees
84cdf0e10cSrcweir     aFont.SetWeight( WEIGHT_BOLD );
85cdf0e10cSrcweir     SetFont( aFont );
86cdf0e10cSrcweir 
87cdf0e10cSrcweir     double fAngle = nAngle * F_PI180 / 100.0;
88cdf0e10cSrcweir     double fSin = sin( fAngle );
89cdf0e10cSrcweir     double fCos = cos( fAngle );
90cdf0e10cSrcweir     double fWidth = GetTextWidth( rText ) / 2.0;
91cdf0e10cSrcweir     double fHeight = GetTextHeight() / 2.0;
92cdf0e10cSrcweir     long nX = static_cast< long >( mnCenterX - fWidth * fCos - fHeight * fSin );
93cdf0e10cSrcweir     long nY = static_cast< long >( mnCenterY + fWidth * fSin - fHeight * fCos );
94cdf0e10cSrcweir     Rectangle aRect( nX, nY, 2 * mnCenterX - nX, 2 * mnCenterY - nY );
95cdf0e10cSrcweir     DrawText( aRect, rText, mbEnabled ? 0 : TEXT_DRAW_DISABLE );
96cdf0e10cSrcweir 
97cdf0e10cSrcweir     // *** drag button ***
98cdf0e10cSrcweir 
99cdf0e10cSrcweir     bool bMain = (nAngle % 4500) != 0;
100cdf0e10cSrcweir     SetLineColor( GetButtonLineColor() );
101cdf0e10cSrcweir     SetFillColor( GetButtonFillColor( bMain ) );
102cdf0e10cSrcweir 
103cdf0e10cSrcweir     nX = mnCenterX - static_cast< long >( (DIAL_OUTER_WIDTH / 2 - mnCenterX) * fCos );
104cdf0e10cSrcweir     nY = mnCenterY - static_cast< long >( (mnCenterY - DIAL_OUTER_WIDTH / 2) * fSin );
105cdf0e10cSrcweir     long nSize = bMain ? (DIAL_OUTER_WIDTH / 4) : (DIAL_OUTER_WIDTH / 2 - 1);
106cdf0e10cSrcweir     DrawEllipse( Rectangle( nX - nSize, nY - nSize, nX + nSize, nY + nSize ) );
107cdf0e10cSrcweir }
108cdf0e10cSrcweir 
109cdf0e10cSrcweir // private --------------------------------------------------------------------
110cdf0e10cSrcweir 
GetBackgroundColor() const111cdf0e10cSrcweir const Color& DialControlBmp::GetBackgroundColor() const
112cdf0e10cSrcweir {
113cdf0e10cSrcweir     return GetSettings().GetStyleSettings().GetDialogColor();
114cdf0e10cSrcweir }
115cdf0e10cSrcweir 
GetTextColor() const116cdf0e10cSrcweir const Color& DialControlBmp::GetTextColor() const
117cdf0e10cSrcweir {
118cdf0e10cSrcweir     return GetSettings().GetStyleSettings().GetLabelTextColor();
119cdf0e10cSrcweir }
120cdf0e10cSrcweir 
GetScaleLineColor() const121cdf0e10cSrcweir const Color& DialControlBmp::GetScaleLineColor() const
122cdf0e10cSrcweir {
123cdf0e10cSrcweir     const StyleSettings& rSett = GetSettings().GetStyleSettings();
124cdf0e10cSrcweir     return mbEnabled ? rSett.GetButtonTextColor() : rSett.GetDisableColor();
125cdf0e10cSrcweir }
126cdf0e10cSrcweir 
GetButtonLineColor() const127cdf0e10cSrcweir const Color& DialControlBmp::GetButtonLineColor() const
128cdf0e10cSrcweir {
129cdf0e10cSrcweir     const StyleSettings& rSett = GetSettings().GetStyleSettings();
130cdf0e10cSrcweir     return mbEnabled ? rSett.GetButtonTextColor() : rSett.GetDisableColor();
131cdf0e10cSrcweir }
132cdf0e10cSrcweir 
GetButtonFillColor(bool bMain) const133cdf0e10cSrcweir const Color& DialControlBmp::GetButtonFillColor( bool bMain ) const
134cdf0e10cSrcweir {
135cdf0e10cSrcweir     const StyleSettings& rSett = GetSettings().GetStyleSettings();
136cdf0e10cSrcweir     return mbEnabled ? (bMain ? rSett.GetMenuColor() : rSett.GetHighlightColor()) : rSett.GetDisableColor();
137cdf0e10cSrcweir }
138cdf0e10cSrcweir 
Init(const Size & rSize)139cdf0e10cSrcweir void DialControlBmp::Init( const Size& rSize )
140cdf0e10cSrcweir {
141cdf0e10cSrcweir     SetSettings( mrParent.GetSettings() );
142cdf0e10cSrcweir     maRect.SetPos( Point( 0, 0 ) );
143cdf0e10cSrcweir     maRect.SetSize( rSize );
144cdf0e10cSrcweir     mnCenterX = rSize.Width() / 2;
145cdf0e10cSrcweir     mnCenterY = rSize.Height() / 2;
146cdf0e10cSrcweir     SetOutputSize( rSize );
147cdf0e10cSrcweir     SetBackground();
148cdf0e10cSrcweir }
149cdf0e10cSrcweir 
DrawBackground()150cdf0e10cSrcweir void DialControlBmp::DrawBackground()
151cdf0e10cSrcweir {
152cdf0e10cSrcweir     // *** background with 3D effect ***
153cdf0e10cSrcweir 
154cdf0e10cSrcweir     SetLineColor();
155cdf0e10cSrcweir     SetFillColor();
156cdf0e10cSrcweir     Erase();
157cdf0e10cSrcweir 
158cdf0e10cSrcweir     EnableRTL( sal_True ); // #107807# draw 3D effect in correct direction
159cdf0e10cSrcweir 
160cdf0e10cSrcweir     sal_uInt8 nDiff = mbEnabled ? 0x18 : 0x10;
161cdf0e10cSrcweir     Color aColor;
162cdf0e10cSrcweir 
163cdf0e10cSrcweir     aColor = GetBackgroundColor();
164cdf0e10cSrcweir     SetFillColor( aColor );
165cdf0e10cSrcweir     DrawPie( maRect, maRect.TopRight(), maRect.TopCenter() );
166cdf0e10cSrcweir     DrawPie( maRect, maRect.BottomLeft(), maRect.BottomCenter() );
167cdf0e10cSrcweir 
168cdf0e10cSrcweir     aColor.DecreaseLuminance( nDiff );
169cdf0e10cSrcweir     SetFillColor( aColor );
170cdf0e10cSrcweir     DrawPie( maRect, maRect.BottomCenter(), maRect.TopRight() );
171cdf0e10cSrcweir 
172cdf0e10cSrcweir     aColor.DecreaseLuminance( nDiff );
173cdf0e10cSrcweir     SetFillColor( aColor );
174cdf0e10cSrcweir     DrawPie( maRect, maRect.BottomRight(), maRect.RightCenter() );
175cdf0e10cSrcweir 
176cdf0e10cSrcweir     aColor = GetBackgroundColor();
177cdf0e10cSrcweir     aColor.IncreaseLuminance( nDiff );
178cdf0e10cSrcweir     SetFillColor( aColor );
179cdf0e10cSrcweir     DrawPie( maRect, maRect.TopCenter(), maRect.BottomLeft() );
180cdf0e10cSrcweir 
181cdf0e10cSrcweir     aColor.IncreaseLuminance( nDiff );
182cdf0e10cSrcweir     SetFillColor( aColor );
183cdf0e10cSrcweir     DrawPie( maRect, maRect.TopLeft(), maRect.LeftCenter() );
184cdf0e10cSrcweir 
185cdf0e10cSrcweir     EnableRTL( sal_False );
186cdf0e10cSrcweir 
187cdf0e10cSrcweir     // *** calibration ***
188cdf0e10cSrcweir 
189cdf0e10cSrcweir     Point aStartPos( mnCenterX, mnCenterY );
190cdf0e10cSrcweir     Color aFullColor( GetScaleLineColor() );
191cdf0e10cSrcweir     Color aLightColor( GetBackgroundColor() );
192cdf0e10cSrcweir     aLightColor.Merge( aFullColor, 128 );
193cdf0e10cSrcweir 
194cdf0e10cSrcweir     for( int nAngle = 0; nAngle < 360; nAngle += 15 )
195cdf0e10cSrcweir     {
196cdf0e10cSrcweir         SetLineColor( (nAngle % 45) ? aLightColor : aFullColor );
197cdf0e10cSrcweir         double fAngle = nAngle * F_PI180;
198cdf0e10cSrcweir         long nX = static_cast< long >( -mnCenterX * cos( fAngle ) );
199cdf0e10cSrcweir         long nY = static_cast< long >( mnCenterY * sin( fAngle ) );
200cdf0e10cSrcweir         DrawLine( aStartPos, Point( mnCenterX - nX, mnCenterY - nY ) );
201cdf0e10cSrcweir     }
202cdf0e10cSrcweir 
203cdf0e10cSrcweir     // *** clear inner area ***
204cdf0e10cSrcweir 
205cdf0e10cSrcweir     SetLineColor();
206cdf0e10cSrcweir     SetFillColor( GetBackgroundColor() );
207cdf0e10cSrcweir     DrawEllipse( Rectangle( maRect.Left() + DIAL_OUTER_WIDTH, maRect.Top() + DIAL_OUTER_WIDTH,
208cdf0e10cSrcweir         maRect.Right() - DIAL_OUTER_WIDTH, maRect.Bottom() - DIAL_OUTER_WIDTH ) );
209cdf0e10cSrcweir }
210cdf0e10cSrcweir 
211cdf0e10cSrcweir 
212*ee093554SAndre Fischer 
213cdf0e10cSrcweir 
214cdf0e10cSrcweir // ----------------------------------------------------------------------------
215cdf0e10cSrcweir 
DialControl_Impl(Window & rParent)216*ee093554SAndre Fischer DialControl::DialControl_Impl::DialControl_Impl (
217*ee093554SAndre Fischer     Window& rParent ) :
218*ee093554SAndre Fischer     mpBmpEnabled(new DialControlBmp(rParent)),
219*ee093554SAndre Fischer     mpBmpDisabled(new DialControlBmp(rParent)),
220*ee093554SAndre Fischer     mpBmpBuffered(new DialControlBmp(rParent)),
221cdf0e10cSrcweir     mpLinkField( 0 ),
222cdf0e10cSrcweir     mnAngle( 0 ),
223cdf0e10cSrcweir     mbNoRot( false )
224cdf0e10cSrcweir {
225cdf0e10cSrcweir }
226cdf0e10cSrcweir 
Init(const Size & rWinSize,const Font & rWinFont)227*ee093554SAndre Fischer void DialControl::DialControl_Impl::Init( const Size& rWinSize, const Font& rWinFont )
228cdf0e10cSrcweir {
229cdf0e10cSrcweir     // "(x - 1) | 1" creates odd value <= x, to have a well-defined center pixel position
230cdf0e10cSrcweir     maWinSize = Size( (rWinSize.Width() - 1) | 1, (rWinSize.Height() - 1) | 1 );
231cdf0e10cSrcweir     maWinFont = rWinFont;
232cdf0e10cSrcweir 
233cdf0e10cSrcweir     mnCenterX = maWinSize.Width() / 2;
234cdf0e10cSrcweir     mnCenterY = maWinSize.Height() / 2;
235cdf0e10cSrcweir     maWinFont.SetTransparent( sal_True );
236cdf0e10cSrcweir 
237*ee093554SAndre Fischer     mpBmpEnabled->DrawBackground( maWinSize, true );
238*ee093554SAndre Fischer     mpBmpDisabled->DrawBackground( maWinSize, false );
239*ee093554SAndre Fischer     mpBmpBuffered->InitBitmap( maWinSize, maWinFont );
240cdf0e10cSrcweir }
241cdf0e10cSrcweir 
242cdf0e10cSrcweir // ============================================================================
243cdf0e10cSrcweir 
DialControl(Window * pParent,const Size & rSize,const Font & rFont,WinBits nWinStyle)244cdf0e10cSrcweir DialControl::DialControl( Window* pParent, const Size& rSize, const Font& rFont, WinBits nWinStyle ) :
245cdf0e10cSrcweir     Control( pParent, nWinStyle ),
246cdf0e10cSrcweir     mpImpl( new DialControl_Impl( *this ) )
247cdf0e10cSrcweir {
248cdf0e10cSrcweir     Init( rSize, rFont );
249cdf0e10cSrcweir }
250cdf0e10cSrcweir 
DialControl(Window * pParent,const Size & rSize,WinBits nWinStyle)251cdf0e10cSrcweir DialControl::DialControl( Window* pParent, const Size& rSize, WinBits nWinStyle ) :
252cdf0e10cSrcweir     Control( pParent, nWinStyle ),
253cdf0e10cSrcweir     mpImpl( new DialControl_Impl( *this ) )
254cdf0e10cSrcweir {
255cdf0e10cSrcweir     if( pParent )
256cdf0e10cSrcweir         Init( rSize, pParent->GetFont() );
257cdf0e10cSrcweir     else
258cdf0e10cSrcweir         Init( rSize );
259cdf0e10cSrcweir }
260cdf0e10cSrcweir 
DialControl(Window * pParent,const ResId & rResId)261cdf0e10cSrcweir DialControl::DialControl( Window* pParent, const ResId& rResId ) :
262cdf0e10cSrcweir     Control( pParent, rResId ),
263cdf0e10cSrcweir     mpImpl( new DialControl_Impl( *this ) )
264cdf0e10cSrcweir {
265cdf0e10cSrcweir     Init( GetOutputSizePixel() );
266cdf0e10cSrcweir }
267cdf0e10cSrcweir 
~DialControl()268cdf0e10cSrcweir DialControl::~DialControl()
269cdf0e10cSrcweir {
270cdf0e10cSrcweir }
271cdf0e10cSrcweir 
Paint(const Rectangle &)272cdf0e10cSrcweir void DialControl::Paint( const Rectangle&  )
273cdf0e10cSrcweir {
274cdf0e10cSrcweir     Point aPos;
275*ee093554SAndre Fischer     DrawBitmapEx( aPos, mpImpl->mpBmpBuffered->GetBitmapEx( aPos, mpImpl->maWinSize ) );
276cdf0e10cSrcweir }
277cdf0e10cSrcweir 
StateChanged(StateChangedType nStateChange)278cdf0e10cSrcweir void DialControl::StateChanged( StateChangedType nStateChange )
279cdf0e10cSrcweir {
280cdf0e10cSrcweir     if( nStateChange == STATE_CHANGE_ENABLE )
281cdf0e10cSrcweir         InvalidateControl();
282cdf0e10cSrcweir 
283cdf0e10cSrcweir     // update the linked edit field
284cdf0e10cSrcweir     if( mpImpl->mpLinkField )
285cdf0e10cSrcweir     {
286cdf0e10cSrcweir         NumericField& rField = *mpImpl->mpLinkField;
287cdf0e10cSrcweir         switch( nStateChange )
288cdf0e10cSrcweir         {
289cdf0e10cSrcweir             case STATE_CHANGE_VISIBLE:  rField.Show( IsVisible() );     break;
290cdf0e10cSrcweir             case STATE_CHANGE_ENABLE:   rField.Enable( IsEnabled() );   break;
291cdf0e10cSrcweir         }
292cdf0e10cSrcweir     }
293cdf0e10cSrcweir 
294cdf0e10cSrcweir     Control::StateChanged( nStateChange );
295cdf0e10cSrcweir }
296cdf0e10cSrcweir 
DataChanged(const DataChangedEvent & rDCEvt)297cdf0e10cSrcweir void DialControl::DataChanged( const DataChangedEvent& rDCEvt )
298cdf0e10cSrcweir {
299cdf0e10cSrcweir     if( (rDCEvt.GetType() == DATACHANGED_SETTINGS) && (rDCEvt.GetFlags() & SETTINGS_STYLE) )
300cdf0e10cSrcweir     {
301cdf0e10cSrcweir         Init( mpImpl->maWinSize, mpImpl->maWinFont );
302cdf0e10cSrcweir         InvalidateControl();
303cdf0e10cSrcweir     }
304cdf0e10cSrcweir     Control::DataChanged( rDCEvt );
305cdf0e10cSrcweir }
306cdf0e10cSrcweir 
MouseButtonDown(const MouseEvent & rMEvt)307cdf0e10cSrcweir void DialControl::MouseButtonDown( const MouseEvent& rMEvt )
308cdf0e10cSrcweir {
309cdf0e10cSrcweir     if( rMEvt.IsLeft() )
310cdf0e10cSrcweir     {
311cdf0e10cSrcweir         GrabFocus();
312cdf0e10cSrcweir         CaptureMouse();
313cdf0e10cSrcweir         mpImpl->mnOldAngle = mpImpl->mnAngle;
314cdf0e10cSrcweir         HandleMouseEvent( rMEvt.GetPosPixel(), true );
315cdf0e10cSrcweir     }
316cdf0e10cSrcweir     Control::MouseButtonDown( rMEvt );
317cdf0e10cSrcweir }
318cdf0e10cSrcweir 
MouseMove(const MouseEvent & rMEvt)319cdf0e10cSrcweir void DialControl::MouseMove( const MouseEvent& rMEvt )
320cdf0e10cSrcweir {
321cdf0e10cSrcweir     if( IsMouseCaptured() && rMEvt.IsLeft() )
322cdf0e10cSrcweir         HandleMouseEvent( rMEvt.GetPosPixel(), false );
323cdf0e10cSrcweir     Control::MouseMove(rMEvt );
324cdf0e10cSrcweir }
325cdf0e10cSrcweir 
MouseButtonUp(const MouseEvent & rMEvt)326cdf0e10cSrcweir void DialControl::MouseButtonUp( const MouseEvent& rMEvt )
327cdf0e10cSrcweir {
328cdf0e10cSrcweir     if( IsMouseCaptured() )
329cdf0e10cSrcweir     {
330cdf0e10cSrcweir         ReleaseMouse();
331cdf0e10cSrcweir         if( mpImpl->mpLinkField )
332cdf0e10cSrcweir             mpImpl->mpLinkField->GrabFocus();
333cdf0e10cSrcweir     }
334cdf0e10cSrcweir     Control::MouseButtonUp( rMEvt );
335cdf0e10cSrcweir }
336cdf0e10cSrcweir 
KeyInput(const KeyEvent & rKEvt)337cdf0e10cSrcweir void DialControl::KeyInput( const KeyEvent& rKEvt )
338cdf0e10cSrcweir {
339cdf0e10cSrcweir     const KeyCode& rKCode = rKEvt.GetKeyCode();
340cdf0e10cSrcweir     if( !rKCode.GetModifier() && (rKCode.GetCode() == KEY_ESCAPE) )
341cdf0e10cSrcweir         HandleEscapeEvent();
342cdf0e10cSrcweir     else
343cdf0e10cSrcweir         Control::KeyInput( rKEvt );
344cdf0e10cSrcweir }
345cdf0e10cSrcweir 
LoseFocus()346cdf0e10cSrcweir void DialControl::LoseFocus()
347cdf0e10cSrcweir {
348cdf0e10cSrcweir     // release captured mouse
349cdf0e10cSrcweir     HandleEscapeEvent();
350cdf0e10cSrcweir     Control::LoseFocus();
351cdf0e10cSrcweir }
352cdf0e10cSrcweir 
HasRotation() const353cdf0e10cSrcweir bool DialControl::HasRotation() const
354cdf0e10cSrcweir {
355cdf0e10cSrcweir     return !mpImpl->mbNoRot;
356cdf0e10cSrcweir }
357cdf0e10cSrcweir 
SetNoRotation()358cdf0e10cSrcweir void DialControl::SetNoRotation()
359cdf0e10cSrcweir {
360cdf0e10cSrcweir     if( !mpImpl->mbNoRot )
361cdf0e10cSrcweir     {
362cdf0e10cSrcweir         mpImpl->mbNoRot = true;
363cdf0e10cSrcweir         InvalidateControl();
364cdf0e10cSrcweir         if( mpImpl->mpLinkField )
365cdf0e10cSrcweir             mpImpl->mpLinkField->SetText( String() );
366cdf0e10cSrcweir     }
367cdf0e10cSrcweir }
368cdf0e10cSrcweir 
GetRotation() const369cdf0e10cSrcweir sal_Int32 DialControl::GetRotation() const
370cdf0e10cSrcweir {
371cdf0e10cSrcweir     return mpImpl->mnAngle;
372cdf0e10cSrcweir }
373cdf0e10cSrcweir 
SetRotation(sal_Int32 nAngle)374cdf0e10cSrcweir void DialControl::SetRotation( sal_Int32 nAngle )
375cdf0e10cSrcweir {
376*ee093554SAndre Fischer     SetRotation( nAngle, false );
377cdf0e10cSrcweir }
378cdf0e10cSrcweir 
SetLinkedField(NumericField * pField)379cdf0e10cSrcweir void DialControl::SetLinkedField( NumericField* pField )
380cdf0e10cSrcweir {
381cdf0e10cSrcweir     // remove modify handler from old linked field
382cdf0e10cSrcweir     ImplSetFieldLink( Link() );
383cdf0e10cSrcweir     // remember the new linked field
384cdf0e10cSrcweir     mpImpl->mpLinkField = pField;
385cdf0e10cSrcweir     // set modify handler at new linked field
386cdf0e10cSrcweir     ImplSetFieldLink( LINK( this, DialControl, LinkedFieldModifyHdl ) );
387cdf0e10cSrcweir }
388cdf0e10cSrcweir 
GetLinkedField() const389cdf0e10cSrcweir NumericField* DialControl::GetLinkedField() const
390cdf0e10cSrcweir {
391cdf0e10cSrcweir     return mpImpl->mpLinkField;
392cdf0e10cSrcweir }
393cdf0e10cSrcweir 
SetModifyHdl(const Link & rLink)394cdf0e10cSrcweir void DialControl::SetModifyHdl( const Link& rLink )
395cdf0e10cSrcweir {
396cdf0e10cSrcweir     mpImpl->maModifyHdl = rLink;
397cdf0e10cSrcweir }
398cdf0e10cSrcweir 
GetModifyHdl() const399cdf0e10cSrcweir const Link& DialControl::GetModifyHdl() const
400cdf0e10cSrcweir {
401cdf0e10cSrcweir     return mpImpl->maModifyHdl;
402cdf0e10cSrcweir }
403cdf0e10cSrcweir 
404cdf0e10cSrcweir // private --------------------------------------------------------------------
405cdf0e10cSrcweir 
Init(const Size & rWinSize,const Font & rWinFont)406cdf0e10cSrcweir void DialControl::Init( const Size& rWinSize, const Font& rWinFont )
407cdf0e10cSrcweir {
408cdf0e10cSrcweir     mpImpl->Init( rWinSize, rWinFont );
409cdf0e10cSrcweir     EnableRTL( sal_False ); // #107807# don't mirror mouse handling
410cdf0e10cSrcweir     SetOutputSizePixel( mpImpl->maWinSize );
411cdf0e10cSrcweir     SetBackground();
412cdf0e10cSrcweir }
413cdf0e10cSrcweir 
Init(const Size & rWinSize)414cdf0e10cSrcweir void DialControl::Init( const Size& rWinSize )
415cdf0e10cSrcweir {
416cdf0e10cSrcweir     Font aFont( OutputDevice::GetDefaultFont(
417cdf0e10cSrcweir         DEFAULTFONT_UI_SANS, Application::GetSettings().GetUILanguage(), DEFAULTFONT_FLAGS_ONLYONE ) );
418cdf0e10cSrcweir     Init( rWinSize, aFont );
419cdf0e10cSrcweir }
420cdf0e10cSrcweir 
InvalidateControl()421cdf0e10cSrcweir void DialControl::InvalidateControl()
422cdf0e10cSrcweir {
423*ee093554SAndre Fischer     mpImpl->mpBmpBuffered->CopyBackground( IsEnabled() ? *mpImpl->mpBmpEnabled : *mpImpl->mpBmpDisabled );
424cdf0e10cSrcweir     if( !mpImpl->mbNoRot )
425*ee093554SAndre Fischer         mpImpl->mpBmpBuffered->DrawElements( GetText(), mpImpl->mnAngle );
426cdf0e10cSrcweir     Invalidate();
427cdf0e10cSrcweir }
428cdf0e10cSrcweir 
SetRotation(sal_Int32 nAngle,bool bBroadcast)429*ee093554SAndre Fischer void DialControl::SetRotation( sal_Int32 nAngle, bool bBroadcast )
430cdf0e10cSrcweir {
431cdf0e10cSrcweir     bool bOldSel = mpImpl->mbNoRot;
432cdf0e10cSrcweir     mpImpl->mbNoRot = false;
433cdf0e10cSrcweir 
434cdf0e10cSrcweir     while( nAngle < 0 ) nAngle += 36000;
435cdf0e10cSrcweir     nAngle = (((nAngle + 50) / 100) * 100) % 36000;
436cdf0e10cSrcweir     if( !bOldSel || (mpImpl->mnAngle != nAngle) )
437cdf0e10cSrcweir     {
438cdf0e10cSrcweir         mpImpl->mnAngle = nAngle;
439cdf0e10cSrcweir         InvalidateControl();
440cdf0e10cSrcweir         if( mpImpl->mpLinkField )
441cdf0e10cSrcweir             mpImpl->mpLinkField->SetValue( static_cast< long >( GetRotation() / 100 ) );
442cdf0e10cSrcweir         if( bBroadcast )
443cdf0e10cSrcweir             mpImpl->maModifyHdl.Call( this );
444cdf0e10cSrcweir     }
445cdf0e10cSrcweir }
446cdf0e10cSrcweir 
ImplSetFieldLink(const Link & rLink)447cdf0e10cSrcweir void DialControl::ImplSetFieldLink( const Link& rLink )
448cdf0e10cSrcweir {
449cdf0e10cSrcweir     if( mpImpl->mpLinkField )
450cdf0e10cSrcweir     {
451cdf0e10cSrcweir         NumericField& rField = *mpImpl->mpLinkField;
452cdf0e10cSrcweir         rField.SetModifyHdl( rLink );
453cdf0e10cSrcweir         rField.SetUpHdl( rLink );
454cdf0e10cSrcweir         rField.SetDownHdl( rLink );
455cdf0e10cSrcweir         rField.SetFirstHdl( rLink );
456cdf0e10cSrcweir         rField.SetLastHdl( rLink );
457cdf0e10cSrcweir         rField.SetLoseFocusHdl( rLink );
458cdf0e10cSrcweir     }
459cdf0e10cSrcweir }
460cdf0e10cSrcweir 
HandleMouseEvent(const Point & rPos,bool bInitial)461cdf0e10cSrcweir void DialControl::HandleMouseEvent( const Point& rPos, bool bInitial )
462cdf0e10cSrcweir {
463cdf0e10cSrcweir     long nX = rPos.X() - mpImpl->mnCenterX;
464cdf0e10cSrcweir     long nY = mpImpl->mnCenterY - rPos.Y();
465cdf0e10cSrcweir     double fH = sqrt( static_cast< double >( nX ) * nX + static_cast< double >( nY ) * nY );
466cdf0e10cSrcweir     if( fH != 0.0 )
467cdf0e10cSrcweir     {
468cdf0e10cSrcweir         double fAngle = acos( nX / fH );
469cdf0e10cSrcweir         sal_Int32 nAngle = static_cast< sal_Int32 >( fAngle / F_PI180 * 100.0 );
470cdf0e10cSrcweir         if( nY < 0 )
471cdf0e10cSrcweir             nAngle = 36000 - nAngle;
472cdf0e10cSrcweir         if( bInitial )  // round to entire 15 degrees
473cdf0e10cSrcweir             nAngle = ((nAngle + 750) / 1500) * 1500;
474*ee093554SAndre Fischer         SetRotation( nAngle, true );
475cdf0e10cSrcweir     }
476cdf0e10cSrcweir }
477cdf0e10cSrcweir 
HandleEscapeEvent()478cdf0e10cSrcweir void DialControl::HandleEscapeEvent()
479cdf0e10cSrcweir {
480cdf0e10cSrcweir     if( IsMouseCaptured() )
481cdf0e10cSrcweir     {
482cdf0e10cSrcweir         ReleaseMouse();
483*ee093554SAndre Fischer         SetRotation( mpImpl->mnOldAngle, true );
484cdf0e10cSrcweir         if( mpImpl->mpLinkField )
485cdf0e10cSrcweir             mpImpl->mpLinkField->GrabFocus();
486cdf0e10cSrcweir     }
487cdf0e10cSrcweir }
488cdf0e10cSrcweir 
IMPL_LINK(DialControl,LinkedFieldModifyHdl,NumericField *,pField)489cdf0e10cSrcweir IMPL_LINK( DialControl, LinkedFieldModifyHdl, NumericField*, pField )
490cdf0e10cSrcweir {
491cdf0e10cSrcweir     if( pField )
492*ee093554SAndre Fischer         SetRotation( static_cast< sal_Int32 >( pField->GetValue() * 100 ), false );
493cdf0e10cSrcweir     return 0;
494cdf0e10cSrcweir }
495cdf0e10cSrcweir 
496cdf0e10cSrcweir // ============================================================================
497cdf0e10cSrcweir 
DialControlWrapper(DialControl & rDial)498cdf0e10cSrcweir DialControlWrapper::DialControlWrapper( DialControl& rDial ) :
499cdf0e10cSrcweir     SingleControlWrapperType( rDial )
500cdf0e10cSrcweir {
501cdf0e10cSrcweir }
502cdf0e10cSrcweir 
IsControlDontKnow() const503cdf0e10cSrcweir bool DialControlWrapper::IsControlDontKnow() const
504cdf0e10cSrcweir {
505cdf0e10cSrcweir     return !GetControl().HasRotation();
506cdf0e10cSrcweir }
507cdf0e10cSrcweir 
SetControlDontKnow(bool bSet)508cdf0e10cSrcweir void DialControlWrapper::SetControlDontKnow( bool bSet )
509cdf0e10cSrcweir {
510cdf0e10cSrcweir     if( bSet )
511cdf0e10cSrcweir         GetControl().SetNoRotation();
512cdf0e10cSrcweir }
513cdf0e10cSrcweir 
GetControlValue() const514cdf0e10cSrcweir sal_Int32 DialControlWrapper::GetControlValue() const
515cdf0e10cSrcweir {
516cdf0e10cSrcweir     return GetControl().GetRotation();
517cdf0e10cSrcweir }
518cdf0e10cSrcweir 
SetControlValue(sal_Int32 nValue)519cdf0e10cSrcweir void DialControlWrapper::SetControlValue( sal_Int32 nValue )
520cdf0e10cSrcweir {
521cdf0e10cSrcweir     GetControl().SetRotation( nValue );
522cdf0e10cSrcweir }
523cdf0e10cSrcweir 
524cdf0e10cSrcweir // ============================================================================
525cdf0e10cSrcweir 
526cdf0e10cSrcweir } // namespace svx
527cdf0e10cSrcweir 
528