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

Generated by: LCOV version 1.11