LCOV - code coverage report
Current view: top level - svx/source/items - grfitem.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 43 77 55.8 %
Date: 2012-08-25 Functions: 6 10 60.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 19 70 27.1 %

           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 <tools/stream.hxx>
      30                 :            : #include <svx/grfcrop.hxx>
      31                 :            : #include <editeng/itemtype.hxx>
      32                 :            : #include <com/sun/star/text/GraphicCrop.hpp>
      33                 :            : 
      34                 :            : using namespace ::com::sun::star;
      35                 :            : 
      36                 :            : #define TWIP_TO_MM100(TWIP)     ((TWIP) >= 0 ? (((TWIP)*127L+36L)/72L) : (((TWIP)*127L-36L)/72L))
      37                 :            : #define MM100_TO_TWIP(MM100)    ((MM100) >= 0 ? (((MM100)*72L+63L)/127L) : (((MM100)*72L-63L)/127L))
      38                 :            : //TYPEINIT1_FACTORY( SvxGrfCrop, SfxPoolItem , new  SvxGrfCrop(0))
      39                 :            : 
      40                 :            : /******************************************************************************
      41                 :            :  *  Implementierung     class SwCropGrf
      42                 :            :  ******************************************************************************/
      43                 :            : 
      44                 :         95 : SvxGrfCrop::SvxGrfCrop( sal_uInt16 nItemId )
      45                 :            :     : SfxPoolItem( nItemId ),
      46                 :         95 :     nLeft( 0 ), nRight( 0 ), nTop( 0 ), nBottom( 0 )
      47                 :         95 : {}
      48                 :            : 
      49                 :       4185 : SvxGrfCrop::SvxGrfCrop( sal_Int32 nL, sal_Int32 nR,
      50                 :            :                         sal_Int32 nT, sal_Int32 nB, sal_uInt16 nItemId )
      51                 :            :     : SfxPoolItem( nItemId ),
      52                 :       4185 :     nLeft( nL ), nRight( nR ), nTop( nT ), nBottom( nB )
      53                 :       4185 : {}
      54                 :            : 
      55                 :       4262 : SvxGrfCrop::~SvxGrfCrop()
      56                 :            : {
      57         [ -  + ]:       4262 : }
      58                 :            : 
      59                 :         63 : int SvxGrfCrop::operator==( const SfxPoolItem& rAttr ) const
      60                 :            : {
      61                 :            :     DBG_ASSERT( SfxPoolItem::operator==( rAttr ), "not equal attributes" );
      62                 :         63 :     return nLeft    == ((const SvxGrfCrop&)rAttr).GetLeft() &&
      63                 :         63 :            nRight   == ((const SvxGrfCrop&)rAttr).GetRight() &&
      64                 :         63 :            nTop     == ((const SvxGrfCrop&)rAttr).GetTop() &&
      65 [ +  - ][ +  -  :        189 :            nBottom  == ((const SvxGrfCrop&)rAttr).GetBottom();
             +  -  +  - ]
      66                 :            : }
      67                 :            : 
      68                 :          0 : SfxPoolItem* SvxGrfCrop::Create( SvStream& rStrm, sal_uInt16 nVersion ) const
      69                 :            : {
      70                 :            :     sal_Int32 top, left, right, bottom;
      71 [ #  # ][ #  # ]:          0 :     rStrm >> top >> left >> right >> bottom;
         [ #  # ][ #  # ]
      72                 :            : 
      73         [ #  # ]:          0 :     if( GRFCROP_VERSION_SWDEFAULT == nVersion )
      74                 :          0 :         top = -top, bottom = -bottom, left = -left, right = -right;
      75                 :            : 
      76         [ #  # ]:          0 :     SvxGrfCrop* pNew = (SvxGrfCrop*)Clone();
      77                 :          0 :     pNew->SetLeft( left );
      78                 :          0 :     pNew->SetRight( right );
      79                 :          0 :     pNew->SetTop( top );
      80                 :          0 :     pNew->SetBottom( bottom );
      81                 :          0 :     return pNew;
      82                 :            : }
      83                 :            : 
      84                 :            : 
      85                 :          0 : SvStream& SvxGrfCrop::Store( SvStream& rStrm, sal_uInt16 nVersion ) const
      86                 :            : {
      87                 :          0 :     sal_Int32 left = GetLeft(), right = GetRight(),
      88                 :          0 :             top = GetTop(), bottom = GetBottom();
      89         [ #  # ]:          0 :     if( GRFCROP_VERSION_SWDEFAULT == nVersion )
      90                 :          0 :         top = -top, bottom = -bottom, left = -left, right = -right;
      91                 :            : 
      92                 :          0 :     rStrm << top << left << right << bottom;
      93                 :            : 
      94                 :          0 :     return rStrm;
      95                 :            : }
      96                 :            : 
      97                 :            : 
      98                 :            : 
      99                 :          4 : bool SvxGrfCrop::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
     100                 :            : {
     101                 :          4 :     sal_Bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
     102                 :          4 :     nMemberId &= ~CONVERT_TWIPS;
     103                 :          4 :     text::GraphicCrop aRet;
     104                 :          4 :     aRet.Left   = nLeft;
     105                 :          4 :     aRet.Right  = nRight;
     106                 :          4 :     aRet.Top    = nTop;
     107                 :          4 :     aRet.Bottom = nBottom;
     108                 :            : 
     109         [ +  - ]:          4 :     if( bConvert )
     110                 :            :     {
     111         [ +  - ]:          4 :        aRet.Right   = TWIP_TO_MM100(aRet.Right );
     112         [ +  - ]:          4 :        aRet.Top     = TWIP_TO_MM100(aRet.Top );
     113         [ +  - ]:          4 :        aRet.Left    = TWIP_TO_MM100(aRet.Left   );
     114         [ +  - ]:          4 :        aRet.Bottom  = TWIP_TO_MM100(aRet.Bottom);
     115                 :            :     }
     116                 :            : 
     117                 :            : 
     118         [ +  - ]:          4 :     rVal <<= aRet;
     119                 :          4 :     return true;
     120                 :            : }
     121                 :            : 
     122                 :         34 : bool SvxGrfCrop::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
     123                 :            : {
     124                 :         34 :     sal_Bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
     125                 :         34 :     nMemberId &= ~CONVERT_TWIPS;
     126                 :         34 :     text::GraphicCrop aVal;
     127                 :            : 
     128 [ -  + ][ +  - ]:         34 :     if(!(rVal >>= aVal))
     129                 :          0 :         return false;
     130         [ +  + ]:         34 :     if( bConvert )
     131                 :            :     {
     132         [ +  - ]:          4 :        aVal.Right   = MM100_TO_TWIP(aVal.Right );
     133         [ +  - ]:          4 :        aVal.Top     = MM100_TO_TWIP(aVal.Top );
     134         [ +  - ]:          4 :        aVal.Left    = MM100_TO_TWIP(aVal.Left   );
     135         [ +  - ]:          4 :        aVal.Bottom  = MM100_TO_TWIP(aVal.Bottom);
     136                 :            :     }
     137                 :            : 
     138                 :         34 :     nLeft   = aVal.Left  ;
     139                 :         34 :     nRight  = aVal.Right ;
     140                 :         34 :     nTop    = aVal.Top   ;
     141                 :         34 :     nBottom = aVal.Bottom;
     142                 :         34 :     return  true;
     143                 :            : }
     144                 :            : 
     145                 :          0 : SfxItemPresentation SvxGrfCrop::GetPresentation(
     146                 :            :     SfxItemPresentation ePres, SfxMapUnit eCoreUnit, SfxMapUnit /*ePresUnit*/,
     147                 :            :     String &rText, const IntlWrapper* pIntl ) const
     148                 :            : {
     149                 :          0 :     rText.Erase();
     150         [ #  # ]:          0 :     switch( ePres )
     151                 :            :     {
     152                 :            :     case SFX_ITEM_PRESENTATION_NAMELESS:
     153                 :            :     case SFX_ITEM_PRESENTATION_COMPLETE:
     154         [ #  # ]:          0 :         if( SFX_ITEM_PRESENTATION_COMPLETE == ePres )
     155                 :            :         {
     156         [ #  # ]:          0 :             ( rText.AssignAscii( "L: " )) += ::GetMetricText( GetLeft(),
     157         [ #  # ]:          0 :                                             eCoreUnit, SFX_MAPUNIT_MM, pIntl );
     158         [ #  # ]:          0 :             ( rText.AppendAscii( " R: " )) += ::GetMetricText( GetRight(),
     159         [ #  # ]:          0 :                                             eCoreUnit, SFX_MAPUNIT_MM, pIntl );
     160         [ #  # ]:          0 :             ( rText.AppendAscii( " T: " )) += ::GetMetricText( GetTop(),
     161         [ #  # ]:          0 :                                             eCoreUnit, SFX_MAPUNIT_MM, pIntl );
     162         [ #  # ]:          0 :             ( rText.AppendAscii( " B: " )) += ::GetMetricText( GetBottom(),
     163         [ #  # ]:          0 :                                             eCoreUnit, SFX_MAPUNIT_MM, pIntl );
     164                 :            :         }
     165                 :          0 :         break;
     166                 :            : 
     167                 :            :     default:
     168                 :          0 :         ePres = SFX_ITEM_PRESENTATION_NONE;
     169                 :          0 :         break;
     170                 :            :     }
     171                 :          0 :     return ePres;
     172                 :            : }
     173                 :            : 
     174                 :            : 
     175                 :            : 
     176                 :            : 
     177                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10