LCOV - code coverage report
Current view: top level - libreoffice/svx/source/items - grfitem.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 24 77 31.2 %
Date: 2012-12-27 Functions: 5 10 50.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <tools/stream.hxx>
      21             : #include <svx/grfcrop.hxx>
      22             : #include <editeng/itemtype.hxx>
      23             : #include <com/sun/star/text/GraphicCrop.hpp>
      24             : 
      25             : using namespace ::com::sun::star;
      26             : 
      27             : #define TWIP_TO_MM100(TWIP)     ((TWIP) >= 0 ? (((TWIP)*127L+36L)/72L) : (((TWIP)*127L-36L)/72L))
      28             : #define MM100_TO_TWIP(MM100)    ((MM100) >= 0 ? (((MM100)*72L+63L)/127L) : (((MM100)*72L-63L)/127L))
      29             : //TYPEINIT1_FACTORY( SvxGrfCrop, SfxPoolItem , new  SvxGrfCrop(0))
      30             : 
      31             : /******************************************************************************
      32             :  *  Implementierung     class SwCropGrf
      33             :  ******************************************************************************/
      34             : 
      35          10 : SvxGrfCrop::SvxGrfCrop( sal_uInt16 nItemId )
      36             :     : SfxPoolItem( nItemId ),
      37          10 :     nLeft( 0 ), nRight( 0 ), nTop( 0 ), nBottom( 0 )
      38          10 : {}
      39             : 
      40         456 : SvxGrfCrop::SvxGrfCrop( sal_Int32 nL, sal_Int32 nR,
      41             :                         sal_Int32 nT, sal_Int32 nB, sal_uInt16 nItemId )
      42             :     : SfxPoolItem( nItemId ),
      43         456 :     nLeft( nL ), nRight( nR ), nTop( nT ), nBottom( nB )
      44         456 : {}
      45             : 
      46         334 : SvxGrfCrop::~SvxGrfCrop()
      47             : {
      48         334 : }
      49             : 
      50          16 : int SvxGrfCrop::operator==( const SfxPoolItem& rAttr ) const
      51             : {
      52             :     DBG_ASSERT( SfxPoolItem::operator==( rAttr ), "not equal attributes" );
      53          16 :     return nLeft    == ((const SvxGrfCrop&)rAttr).GetLeft() &&
      54          16 :            nRight   == ((const SvxGrfCrop&)rAttr).GetRight() &&
      55          16 :            nTop     == ((const SvxGrfCrop&)rAttr).GetTop() &&
      56          64 :            nBottom  == ((const SvxGrfCrop&)rAttr).GetBottom();
      57             : }
      58             : 
      59           0 : SfxPoolItem* SvxGrfCrop::Create( SvStream& rStrm, sal_uInt16 nVersion ) const
      60             : {
      61             :     sal_Int32 top, left, right, bottom;
      62           0 :     rStrm >> top >> left >> right >> bottom;
      63             : 
      64           0 :     if( GRFCROP_VERSION_SWDEFAULT == nVersion )
      65           0 :         top = -top, bottom = -bottom, left = -left, right = -right;
      66             : 
      67           0 :     SvxGrfCrop* pNew = (SvxGrfCrop*)Clone();
      68           0 :     pNew->SetLeft( left );
      69           0 :     pNew->SetRight( right );
      70           0 :     pNew->SetTop( top );
      71           0 :     pNew->SetBottom( bottom );
      72           0 :     return pNew;
      73             : }
      74             : 
      75             : 
      76           0 : SvStream& SvxGrfCrop::Store( SvStream& rStrm, sal_uInt16 nVersion ) const
      77             : {
      78           0 :     sal_Int32 left = GetLeft(), right = GetRight(),
      79           0 :             top = GetTop(), bottom = GetBottom();
      80           0 :     if( GRFCROP_VERSION_SWDEFAULT == nVersion )
      81           0 :         top = -top, bottom = -bottom, left = -left, right = -right;
      82             : 
      83           0 :     rStrm << top << left << right << bottom;
      84             : 
      85           0 :     return rStrm;
      86             : }
      87             : 
      88             : 
      89             : 
      90           0 : bool SvxGrfCrop::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
      91             : {
      92           0 :     sal_Bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
      93           0 :     nMemberId &= ~CONVERT_TWIPS;
      94           0 :     text::GraphicCrop aRet;
      95           0 :     aRet.Left   = nLeft;
      96           0 :     aRet.Right  = nRight;
      97           0 :     aRet.Top    = nTop;
      98           0 :     aRet.Bottom = nBottom;
      99             : 
     100           0 :     if( bConvert )
     101             :     {
     102           0 :        aRet.Right   = TWIP_TO_MM100(aRet.Right );
     103           0 :        aRet.Top     = TWIP_TO_MM100(aRet.Top );
     104           0 :        aRet.Left    = TWIP_TO_MM100(aRet.Left   );
     105           0 :        aRet.Bottom  = TWIP_TO_MM100(aRet.Bottom);
     106             :     }
     107             : 
     108             : 
     109           0 :     rVal <<= aRet;
     110           0 :     return true;
     111             : }
     112             : 
     113           8 : bool SvxGrfCrop::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
     114             : {
     115           8 :     sal_Bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
     116           8 :     nMemberId &= ~CONVERT_TWIPS;
     117           8 :     text::GraphicCrop aVal;
     118             : 
     119           8 :     if(!(rVal >>= aVal))
     120           0 :         return false;
     121           8 :     if( bConvert )
     122             :     {
     123           0 :        aVal.Right   = MM100_TO_TWIP(aVal.Right );
     124           0 :        aVal.Top     = MM100_TO_TWIP(aVal.Top );
     125           0 :        aVal.Left    = MM100_TO_TWIP(aVal.Left   );
     126           0 :        aVal.Bottom  = MM100_TO_TWIP(aVal.Bottom);
     127             :     }
     128             : 
     129           8 :     nLeft   = aVal.Left  ;
     130           8 :     nRight  = aVal.Right ;
     131           8 :     nTop    = aVal.Top   ;
     132           8 :     nBottom = aVal.Bottom;
     133           8 :     return  true;
     134             : }
     135             : 
     136           0 : SfxItemPresentation SvxGrfCrop::GetPresentation(
     137             :     SfxItemPresentation ePres, SfxMapUnit eCoreUnit, SfxMapUnit /*ePresUnit*/,
     138             :     String &rText, const IntlWrapper* pIntl ) const
     139             : {
     140           0 :     rText.Erase();
     141           0 :     switch( ePres )
     142             :     {
     143             :     case SFX_ITEM_PRESENTATION_NAMELESS:
     144             :     case SFX_ITEM_PRESENTATION_COMPLETE:
     145           0 :         if( SFX_ITEM_PRESENTATION_COMPLETE == ePres )
     146             :         {
     147           0 :             ( rText.AssignAscii( "L: " )) += ::GetMetricText( GetLeft(),
     148           0 :                                             eCoreUnit, SFX_MAPUNIT_MM, pIntl );
     149           0 :             ( rText.AppendAscii( " R: " )) += ::GetMetricText( GetRight(),
     150           0 :                                             eCoreUnit, SFX_MAPUNIT_MM, pIntl );
     151           0 :             ( rText.AppendAscii( " T: " )) += ::GetMetricText( GetTop(),
     152           0 :                                             eCoreUnit, SFX_MAPUNIT_MM, pIntl );
     153           0 :             ( rText.AppendAscii( " B: " )) += ::GetMetricText( GetBottom(),
     154           0 :                                             eCoreUnit, SFX_MAPUNIT_MM, pIntl );
     155             :         }
     156           0 :         break;
     157             : 
     158             :     default:
     159           0 :         ePres = SFX_ITEM_PRESENTATION_NONE;
     160           0 :         break;
     161             :     }
     162           0 :     return ePres;
     163             : }
     164             : 
     165             : 
     166             : 
     167             : 
     168             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10