LCOV - code coverage report
Current view: top level - svx/source/dialog - dialcontrol.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 271 0.0 %
Date: 2012-08-25 Functions: 0 47 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 255 0.0 %

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

Generated by: LCOV version 1.10