LCOV - code coverage report
Current view: top level - svx/source/items - clipfmtitem.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 42 68 61.8 %
Date: 2014-11-03 Functions: 17 21 81.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 <svx/clipfmtitem.hxx>
      21             : #include <com/sun/star/frame/status/ClipboardFormats.hpp>
      22             : 
      23             : #include <boost/ptr_container/ptr_vector.hpp>
      24             : 
      25        5320 : struct SvxClipboardFmtItem_Impl
      26             : {
      27             :     boost::ptr_vector< boost::nullable<OUString> > aFmtNms;
      28             :     std::vector<sal_uIntPtr> aFmtIds;
      29             : 
      30        2080 :     SvxClipboardFmtItem_Impl() {}
      31             :     SvxClipboardFmtItem_Impl( const SvxClipboardFmtItem_Impl& );
      32             : };
      33             : 
      34        6391 : TYPEINIT1_FACTORY( SvxClipboardFmtItem, SfxPoolItem , new  SvxClipboardFmtItem(0));
      35             : 
      36        3240 : SvxClipboardFmtItem_Impl::SvxClipboardFmtItem_Impl(
      37             :                             const SvxClipboardFmtItem_Impl& rCpy )
      38             :     : aFmtNms(rCpy.aFmtNms)
      39        3240 :     , aFmtIds(rCpy.aFmtIds)
      40             : {
      41        3240 : }
      42             : 
      43        2080 : SvxClipboardFmtItem::SvxClipboardFmtItem( sal_uInt16 nId )
      44        2080 :     : SfxPoolItem( nId ), pImpl( new SvxClipboardFmtItem_Impl )
      45             : {
      46        2080 : }
      47             : 
      48        3240 : SvxClipboardFmtItem::SvxClipboardFmtItem( const SvxClipboardFmtItem& rCpy )
      49        3240 :     : SfxPoolItem( rCpy.Which() ),
      50        3240 :     pImpl( new SvxClipboardFmtItem_Impl( *rCpy.pImpl ) )
      51             : {
      52        3240 : }
      53             : 
      54       14817 : SvxClipboardFmtItem::~SvxClipboardFmtItem()
      55             : {
      56        5320 :     delete pImpl;
      57        9497 : }
      58             : 
      59         937 : bool SvxClipboardFmtItem::QueryValue( com::sun::star::uno::Any& rVal, sal_uInt8 /*nMemberId*/ ) const
      60             : {
      61         937 :     sal_uInt16 nCount = Count();
      62             : 
      63         937 :     ::com::sun::star::frame::status::ClipboardFormats aClipFormats;
      64             : 
      65         937 :     aClipFormats.Identifiers.realloc( nCount );
      66         937 :     aClipFormats.Names.realloc( nCount );
      67         937 :     for ( sal_uInt16 n=0; n < nCount; n++ )
      68             :     {
      69           0 :         aClipFormats.Identifiers[n] = (sal_Int64)GetClipbrdFormatId( n );
      70           0 :         aClipFormats.Names[n] = GetClipbrdFormatName( n );
      71             :     }
      72             : 
      73         937 :     rVal <<= aClipFormats;
      74         937 :     return true;
      75             : }
      76             : 
      77         937 : bool SvxClipboardFmtItem::PutValue( const ::com::sun::star::uno::Any& rVal, sal_uInt8 /*nMemberId*/ )
      78             : {
      79         937 :     ::com::sun::star::frame::status::ClipboardFormats aClipFormats;
      80         937 :     if ( rVal >>= aClipFormats )
      81             :     {
      82         937 :         sal_uInt16 nCount = sal_uInt16( aClipFormats.Identifiers.getLength() );
      83             : 
      84         937 :         pImpl->aFmtIds.clear();
      85         937 :         pImpl->aFmtNms.clear();
      86         937 :         for ( sal_uInt16 n=0; n < nCount; ++n )
      87           0 :             AddClipbrdFormat( sal_uIntPtr( aClipFormats.Identifiers[n] ), aClipFormats.Names[n], n );
      88             : 
      89         937 :         return true;
      90             :     }
      91             : 
      92           0 :     return false;
      93             : }
      94             : 
      95         206 : bool SvxClipboardFmtItem::operator==( const SfxPoolItem& rComp ) const
      96             : {
      97         206 :     const SvxClipboardFmtItem& rCmp = static_cast<const SvxClipboardFmtItem&>(rComp);
      98         206 :     if(rCmp.pImpl->aFmtNms.size() != pImpl->aFmtNms.size())
      99           0 :         return false;
     100             : 
     101         206 :     int nRet = 1;
     102         206 :     for( sal_uInt16 n = 0, nEnd = rCmp.pImpl->aFmtNms.size(); n < nEnd; ++n )
     103             :     {
     104           0 :         if( pImpl->aFmtIds[ n ] != rCmp.pImpl->aFmtIds[ n ] ||
     105           0 :             ( pImpl->aFmtNms.is_null(n) != rCmp.pImpl->aFmtNms.is_null(n) ) ||
     106           0 :             ( !pImpl->aFmtNms.is_null(n) && pImpl->aFmtNms[n] != rCmp.pImpl->aFmtNms[n] ) )
     107             :         {
     108           0 :             nRet = 0;
     109           0 :             break;
     110             :         }
     111             :     }
     112             : 
     113         206 :     return nRet;
     114             : }
     115             : 
     116        3240 : SfxPoolItem* SvxClipboardFmtItem::Clone( SfxItemPool * /*pPool*/ ) const
     117             : {
     118        3240 :     return new SvxClipboardFmtItem( *this );
     119             : }
     120             : 
     121           0 : void SvxClipboardFmtItem::AddClipbrdFormat( sal_uIntPtr nId, sal_uInt16 nPos )
     122             : {
     123           0 :     if( nPos > pImpl->aFmtNms.size() )
     124           0 :         nPos = pImpl->aFmtNms.size();
     125             : 
     126           0 :     pImpl->aFmtNms.insert(pImpl->aFmtNms.begin() + nPos, 0);
     127           0 :     pImpl->aFmtIds.insert( pImpl->aFmtIds.begin()+nPos, nId );
     128           0 : }
     129             : 
     130           0 : void SvxClipboardFmtItem::AddClipbrdFormat( sal_uIntPtr nId, const OUString& rName,
     131             :                             sal_uInt16 nPos )
     132             : {
     133           0 :     if( nPos > pImpl->aFmtNms.size() )
     134           0 :         nPos = pImpl->aFmtNms.size();
     135             : 
     136           0 :     pImpl->aFmtNms.insert(pImpl->aFmtNms.begin() + nPos, new OUString(rName));
     137           0 :     pImpl->aFmtIds.insert( pImpl->aFmtIds.begin()+nPos, nId );
     138           0 : }
     139             : 
     140         937 : sal_uInt16 SvxClipboardFmtItem::Count() const
     141             : {
     142         937 :     return pImpl->aFmtIds.size();
     143             : }
     144             : 
     145           0 : sal_uIntPtr SvxClipboardFmtItem::GetClipbrdFormatId( sal_uInt16 nPos ) const
     146             : {
     147           0 :     return pImpl->aFmtIds[ nPos ];
     148             : }
     149             : 
     150           0 : const OUString SvxClipboardFmtItem::GetClipbrdFormatName( sal_uInt16 nPos ) const
     151             : {
     152           0 :     return pImpl->aFmtNms.is_null(nPos) ? OUString() : pImpl->aFmtNms[nPos];
     153             : }
     154             : 
     155             : 
     156             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10