LCOV - code coverage report
Current view: top level - svx/source/items - grfitem.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 42 70 60.0 %
Date: 2014-11-03 Functions: 6 10 60.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             : #include <tools/mapunit.hxx>
      25             : 
      26             : using namespace ::com::sun::star;
      27             : 
      28         100 : SvxGrfCrop::SvxGrfCrop( sal_uInt16 nItemId )
      29             :     : SfxPoolItem( nItemId ),
      30         100 :     nLeft( 0 ), nRight( 0 ), nTop( 0 ), nBottom( 0 )
      31         100 : {}
      32             : 
      33        8966 : SvxGrfCrop::SvxGrfCrop( sal_Int32 nL, sal_Int32 nR,
      34             :                         sal_Int32 nT, sal_Int32 nB, sal_uInt16 nItemId )
      35             :     : SfxPoolItem( nItemId ),
      36        8966 :     nLeft( nL ), nRight( nR ), nTop( nT ), nBottom( nB )
      37        8966 : {}
      38             : 
      39       12869 : SvxGrfCrop::~SvxGrfCrop()
      40             : {
      41       12869 : }
      42             : 
      43        1624 : bool SvxGrfCrop::operator==( const SfxPoolItem& rAttr ) const
      44             : {
      45             :     DBG_ASSERT( SfxPoolItem::operator==( rAttr ), "not equal attributes" );
      46        1624 :     const SvxGrfCrop& rCrop = static_cast<const SvxGrfCrop&>(rAttr);
      47        2888 :     return nLeft    == rCrop.GetLeft() &&
      48        2522 :            nRight   == rCrop.GetRight() &&
      49        4026 :            nTop     == rCrop.GetTop() &&
      50        2768 :            nBottom  == rCrop.GetBottom();
      51             : }
      52             : 
      53           0 : SfxPoolItem* SvxGrfCrop::Create( SvStream& rStrm, sal_uInt16 nVersion ) const
      54             : {
      55             :     sal_Int32 top, left, right, bottom;
      56           0 :     rStrm.ReadInt32( top ).ReadInt32( left ).ReadInt32( right ).ReadInt32( bottom );
      57             : 
      58           0 :     if( GRFCROP_VERSION_SWDEFAULT == nVersion )
      59           0 :         top = -top, bottom = -bottom, left = -left, right = -right;
      60             : 
      61           0 :     SvxGrfCrop* pNew = static_cast<SvxGrfCrop*>(Clone());
      62           0 :     pNew->SetLeft( left );
      63           0 :     pNew->SetRight( right );
      64           0 :     pNew->SetTop( top );
      65           0 :     pNew->SetBottom( bottom );
      66           0 :     return pNew;
      67             : }
      68             : 
      69             : 
      70           0 : SvStream& SvxGrfCrop::Store( SvStream& rStrm, sal_uInt16 nVersion ) const
      71             : {
      72           0 :     sal_Int32 left = GetLeft(), right = GetRight(),
      73           0 :             top = GetTop(), bottom = GetBottom();
      74           0 :     if( GRFCROP_VERSION_SWDEFAULT == nVersion )
      75           0 :         top = -top, bottom = -bottom, left = -left, right = -right;
      76             : 
      77           0 :     rStrm.WriteInt32( top ).WriteInt32( left ).WriteInt32( right ).WriteInt32( bottom );
      78             : 
      79           0 :     return rStrm;
      80             : }
      81             : 
      82             : 
      83             : 
      84         710 : bool SvxGrfCrop::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
      85             : {
      86         710 :     bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
      87         710 :     text::GraphicCrop aRet;
      88         710 :     aRet.Left   = nLeft;
      89         710 :     aRet.Right  = nRight;
      90         710 :     aRet.Top    = nTop;
      91         710 :     aRet.Bottom = nBottom;
      92             : 
      93         710 :     if( bConvert )
      94             :     {
      95         126 :        aRet.Right   = convertTwipToMm100(aRet.Right );
      96         126 :        aRet.Top     = convertTwipToMm100(aRet.Top );
      97         126 :        aRet.Left    = convertTwipToMm100(aRet.Left   );
      98         126 :        aRet.Bottom  = convertTwipToMm100(aRet.Bottom);
      99             :     }
     100             : 
     101             : 
     102         710 :     rVal <<= aRet;
     103         710 :     return true;
     104             : }
     105             : 
     106         786 : bool SvxGrfCrop::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
     107             : {
     108         786 :     bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
     109         786 :     text::GraphicCrop aVal;
     110             : 
     111         786 :     if(!(rVal >>= aVal))
     112           0 :         return false;
     113         786 :     if( bConvert )
     114             :     {
     115         490 :        aVal.Right   = convertMm100ToTwip(aVal.Right );
     116         490 :        aVal.Top     = convertMm100ToTwip(aVal.Top );
     117         490 :        aVal.Left    = convertMm100ToTwip(aVal.Left   );
     118         490 :        aVal.Bottom  = convertMm100ToTwip(aVal.Bottom);
     119             :     }
     120             : 
     121         786 :     nLeft   = aVal.Left  ;
     122         786 :     nRight  = aVal.Right ;
     123         786 :     nTop    = aVal.Top   ;
     124         786 :     nBottom = aVal.Bottom;
     125         786 :     return  true;
     126             : }
     127             : 
     128           0 : bool SvxGrfCrop::GetPresentation(
     129             :     SfxItemPresentation ePres, SfxMapUnit eCoreUnit, SfxMapUnit /*ePresUnit*/,
     130             :     OUString &rText, const IntlWrapper* pIntl ) const
     131             : {
     132           0 :     rText = OUString();
     133           0 :     switch( ePres )
     134             :     {
     135             :     case SFX_ITEM_PRESENTATION_NAMELESS:
     136           0 :         return true;
     137             :     case SFX_ITEM_PRESENTATION_COMPLETE:
     138           0 :         rText = "L: "  + OUString(::GetMetricText( GetLeft(), eCoreUnit, SFX_MAPUNIT_MM, pIntl )) +
     139           0 :                 " R: " + OUString(::GetMetricText( GetRight(), eCoreUnit, SFX_MAPUNIT_MM, pIntl )) +
     140           0 :                 " T: " + OUString(::GetMetricText( GetTop(), eCoreUnit, SFX_MAPUNIT_MM, pIntl )) +
     141           0 :                 " B: " + OUString(::GetMetricText( GetBottom(), eCoreUnit, SFX_MAPUNIT_MM, pIntl ));
     142           0 :         return true;
     143             :         break;
     144             : 
     145             :     default:
     146           0 :         return false;
     147             :         break;
     148             :     }
     149             : }
     150             : 
     151             : 
     152             : 
     153             : 
     154             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10