LCOV - code coverage report
Current view: top level - libreoffice/svl/source/items - ptitem.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1 60 1.7 %
Date: 2012-12-27 Functions: 1 15 6.7 %
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             : 
      21             : #include <svl/ptitem.hxx>
      22             : #include <com/sun/star/uno/Any.hxx>
      23             : #include <com/sun/star/awt/Point.hpp>
      24             : #include <tools/stream.hxx>
      25             : 
      26             : #include <svl/poolitem.hxx>
      27             : #include <svl/memberid.hrc>
      28             : 
      29             : using namespace ::com::sun::star;
      30             : // STATIC DATA -----------------------------------------------------------
      31             : 
      32             : DBG_NAME(SfxPointItem)
      33             : 
      34             : #define TWIP_TO_MM100(TWIP)     ((TWIP) >= 0 ? (((TWIP)*127L+36L)/72L) : (((TWIP)*127L-36L)/72L))
      35             : #define MM100_TO_TWIP(MM100)    ((MM100) >= 0 ? (((MM100)*72L+63L)/127L) : (((MM100)*72L-63L)/127L))
      36             : 
      37             : // -----------------------------------------------------------------------
      38             : 
      39          18 : TYPEINIT1_AUTOFACTORY(SfxPointItem, SfxPoolItem);
      40             : 
      41             : // -----------------------------------------------------------------------
      42             : 
      43           0 : SfxPointItem::SfxPointItem()
      44             : {
      45             :     DBG_CTOR(SfxPointItem, 0);
      46           0 : }
      47             : 
      48             : // -----------------------------------------------------------------------
      49             : 
      50           0 : SfxPointItem::SfxPointItem( sal_uInt16 nW, const Point& rVal ) :
      51             :     SfxPoolItem( nW ),
      52           0 :     aVal( rVal )
      53             : {
      54             :     DBG_CTOR(SfxPointItem, 0);
      55           0 : }
      56             : 
      57             : // -----------------------------------------------------------------------
      58             : 
      59           0 : SfxPointItem::SfxPointItem( const SfxPointItem& rItem ) :
      60             :     SfxPoolItem( rItem ),
      61           0 :     aVal( rItem.aVal )
      62             : {
      63             :     DBG_CTOR(SfxPointItem, 0);
      64           0 : }
      65             : 
      66             : // -----------------------------------------------------------------------
      67             : 
      68           0 : SfxItemPresentation SfxPointItem::GetPresentation
      69             : (
      70             :     SfxItemPresentation     /*ePresentation*/,
      71             :     SfxMapUnit              /*eCoreMetric*/,
      72             :     SfxMapUnit              /*ePresentationMetric*/,
      73             :     XubString&              rText,
      74             :     const IntlWrapper *
      75             : )   const
      76             : {
      77             :     DBG_CHKTHIS(SfxPointItem, 0);
      78           0 :     rText = UniString::CreateFromInt32(aVal.X());
      79           0 :     rText.AppendAscii(RTL_CONSTASCII_STRINGPARAM(", "));
      80           0 :     rText += UniString::CreateFromInt32(aVal.Y());
      81           0 :     rText.AppendAscii(RTL_CONSTASCII_STRINGPARAM(", "));
      82           0 :     return SFX_ITEM_PRESENTATION_NAMELESS;
      83             : }
      84             : 
      85             : // -----------------------------------------------------------------------
      86             : 
      87           0 : int SfxPointItem::operator==( const SfxPoolItem& rItem ) const
      88             : {
      89             :     DBG_CHKTHIS(SfxPointItem, 0);
      90             :     DBG_ASSERT( SfxPoolItem::operator==( rItem ), "unequal type" );
      91           0 :     return ((SfxPointItem&)rItem).aVal == aVal;
      92             : }
      93             : 
      94             : // -----------------------------------------------------------------------
      95             : 
      96           0 : SfxPoolItem* SfxPointItem::Clone(SfxItemPool *) const
      97             : {
      98             :     DBG_CHKTHIS(SfxPointItem, 0);
      99           0 :     return new SfxPointItem( *this );
     100             : }
     101             : 
     102             : // -----------------------------------------------------------------------
     103             : 
     104           0 : SfxPoolItem* SfxPointItem::Create(SvStream &rStream, sal_uInt16 ) const
     105             : {
     106             :     DBG_CHKTHIS(SfxPointItem, 0);
     107           0 :     Point aStr;
     108           0 :     rStream >> aStr;
     109           0 :     return new SfxPointItem(Which(), aStr);
     110             : }
     111             : 
     112             : // -----------------------------------------------------------------------
     113             : 
     114           0 : SvStream& SfxPointItem::Store(SvStream &rStream, sal_uInt16 ) const
     115             : {
     116             :     DBG_CHKTHIS(SfxPointItem, 0);
     117           0 :     rStream << aVal;
     118           0 :     return rStream;
     119             : }
     120             : 
     121             : // -----------------------------------------------------------------------
     122             : 
     123           0 : bool SfxPointItem::QueryValue( uno::Any& rVal,
     124             :                                sal_uInt8 nMemberId ) const
     125             : {
     126           0 :     sal_Bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
     127           0 :     awt::Point aTmp(aVal.X(), aVal.Y());
     128           0 :     if( bConvert )
     129             :     {
     130           0 :         aTmp.X = TWIP_TO_MM100(aTmp.X);
     131           0 :         aTmp.Y = TWIP_TO_MM100(aTmp.Y);
     132             :     }
     133           0 :     nMemberId &= ~CONVERT_TWIPS;
     134           0 :     switch ( nMemberId )
     135             :     {
     136           0 :         case 0: rVal <<= aTmp; break;
     137           0 :         case MID_X: rVal <<= aTmp.X; break;
     138           0 :         case MID_Y: rVal <<= aTmp.Y; break;
     139           0 :         default: OSL_FAIL("Wrong MemberId!"); return true;
     140             :     }
     141             : 
     142           0 :     return true;
     143             : }
     144             : 
     145             : // -----------------------------------------------------------------------
     146             : 
     147           0 : bool SfxPointItem::PutValue( const uno::Any& rVal,
     148             :                              sal_uInt8 nMemberId )
     149             : {
     150           0 :     sal_Bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
     151           0 :     nMemberId &= ~CONVERT_TWIPS;
     152           0 :     bool bRet = false;
     153           0 :     awt::Point aValue;
     154           0 :     sal_Int32 nVal = 0;
     155           0 :     if ( !nMemberId )
     156             :     {
     157           0 :         bRet = ( rVal >>= aValue );
     158           0 :         if( bConvert )
     159             :         {
     160           0 :             aValue.X = MM100_TO_TWIP(aValue.X);
     161           0 :             aValue.Y = MM100_TO_TWIP(aValue.Y);
     162             :         }
     163             :     }
     164             :     else
     165             :     {
     166           0 :         bRet = ( rVal >>= nVal );
     167           0 :         if( bConvert )
     168           0 :             nVal = MM100_TO_TWIP( nVal );
     169             :     }
     170             : 
     171           0 :     if ( bRet )
     172             :     {
     173           0 :         switch ( nMemberId )
     174             :         {
     175           0 :             case 0: aVal.setX( aValue.X ); aVal.setY( aValue.Y ); break;
     176           0 :             case MID_X: aVal.setX( nVal ); break;
     177           0 :             case MID_Y: aVal.setY( nVal ); break;
     178           0 :             default: OSL_FAIL("Wrong MemberId!"); return false;
     179             :         }
     180             :     }
     181             : 
     182           0 :     return bRet;
     183             : }
     184             : 
     185             : 
     186             : 
     187             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10