1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_svx.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #define _SVSTDARR_ULONGS 32*cdf0e10cSrcweir #define _SVSTDARR_STRINGSDTOR 33*cdf0e10cSrcweir 34*cdf0e10cSrcweir #include <svl/svstdarr.hxx> 35*cdf0e10cSrcweir #include <svx/clipfmtitem.hxx> 36*cdf0e10cSrcweir #include <com/sun/star/frame/status/ClipboardFormats.hpp> 37*cdf0e10cSrcweir 38*cdf0e10cSrcweir struct SvxClipboardFmtItem_Impl 39*cdf0e10cSrcweir { 40*cdf0e10cSrcweir SvStringsDtor aFmtNms; 41*cdf0e10cSrcweir SvULongs aFmtIds; 42*cdf0e10cSrcweir static String sEmptyStr; 43*cdf0e10cSrcweir 44*cdf0e10cSrcweir SvxClipboardFmtItem_Impl() : aFmtNms( 8, 8 ), aFmtIds( 8, 8 ) {} 45*cdf0e10cSrcweir SvxClipboardFmtItem_Impl( const SvxClipboardFmtItem_Impl& ); 46*cdf0e10cSrcweir }; 47*cdf0e10cSrcweir 48*cdf0e10cSrcweir String SvxClipboardFmtItem_Impl::sEmptyStr; 49*cdf0e10cSrcweir 50*cdf0e10cSrcweir TYPEINIT1_FACTORY( SvxClipboardFmtItem, SfxPoolItem , new SvxClipboardFmtItem(0)); 51*cdf0e10cSrcweir 52*cdf0e10cSrcweir SvxClipboardFmtItem_Impl::SvxClipboardFmtItem_Impl( 53*cdf0e10cSrcweir const SvxClipboardFmtItem_Impl& rCpy ) 54*cdf0e10cSrcweir { 55*cdf0e10cSrcweir aFmtIds.Insert( &rCpy.aFmtIds, 0 ); 56*cdf0e10cSrcweir for( sal_uInt16 n = 0, nEnd = rCpy.aFmtNms.Count(); n < nEnd; ++n ) 57*cdf0e10cSrcweir { 58*cdf0e10cSrcweir String* pStr = rCpy.aFmtNms[ n ]; 59*cdf0e10cSrcweir if( pStr ) 60*cdf0e10cSrcweir pStr = new String( *pStr ); 61*cdf0e10cSrcweir aFmtNms.Insert( pStr, n ); 62*cdf0e10cSrcweir } 63*cdf0e10cSrcweir } 64*cdf0e10cSrcweir 65*cdf0e10cSrcweir SvxClipboardFmtItem::SvxClipboardFmtItem( sal_uInt16 nId ) 66*cdf0e10cSrcweir : SfxPoolItem( nId ), pImpl( new SvxClipboardFmtItem_Impl ) 67*cdf0e10cSrcweir { 68*cdf0e10cSrcweir } 69*cdf0e10cSrcweir 70*cdf0e10cSrcweir SvxClipboardFmtItem::SvxClipboardFmtItem( const SvxClipboardFmtItem& rCpy ) 71*cdf0e10cSrcweir : SfxPoolItem( rCpy.Which() ), 72*cdf0e10cSrcweir pImpl( new SvxClipboardFmtItem_Impl( *rCpy.pImpl ) ) 73*cdf0e10cSrcweir { 74*cdf0e10cSrcweir } 75*cdf0e10cSrcweir 76*cdf0e10cSrcweir SvxClipboardFmtItem::~SvxClipboardFmtItem() 77*cdf0e10cSrcweir { 78*cdf0e10cSrcweir delete pImpl; 79*cdf0e10cSrcweir } 80*cdf0e10cSrcweir 81*cdf0e10cSrcweir sal_Bool SvxClipboardFmtItem::QueryValue( com::sun::star::uno::Any& rVal, sal_uInt8 /*nMemberId*/ ) const 82*cdf0e10cSrcweir { 83*cdf0e10cSrcweir sal_uInt16 nCount = Count(); 84*cdf0e10cSrcweir 85*cdf0e10cSrcweir ::com::sun::star::frame::status::ClipboardFormats aClipFormats; 86*cdf0e10cSrcweir 87*cdf0e10cSrcweir aClipFormats.Identifiers.realloc( nCount ); 88*cdf0e10cSrcweir aClipFormats.Names.realloc( nCount ); 89*cdf0e10cSrcweir for ( sal_uInt16 n=0; n < nCount; n++ ) 90*cdf0e10cSrcweir { 91*cdf0e10cSrcweir aClipFormats.Identifiers[n] = (sal_Int64)GetClipbrdFormatId( n ); 92*cdf0e10cSrcweir aClipFormats.Names[n] = GetClipbrdFormatName( n ); 93*cdf0e10cSrcweir } 94*cdf0e10cSrcweir 95*cdf0e10cSrcweir rVal <<= aClipFormats; 96*cdf0e10cSrcweir return sal_True; 97*cdf0e10cSrcweir } 98*cdf0e10cSrcweir 99*cdf0e10cSrcweir sal_Bool SvxClipboardFmtItem::PutValue( const ::com::sun::star::uno::Any& rVal, sal_uInt8 /*nMemberId*/ ) 100*cdf0e10cSrcweir { 101*cdf0e10cSrcweir ::com::sun::star::frame::status::ClipboardFormats aClipFormats; 102*cdf0e10cSrcweir if ( rVal >>= aClipFormats ) 103*cdf0e10cSrcweir { 104*cdf0e10cSrcweir sal_uInt16 nCount = sal_uInt16( aClipFormats.Identifiers.getLength() ); 105*cdf0e10cSrcweir 106*cdf0e10cSrcweir pImpl->aFmtIds.Remove( 0, pImpl->aFmtIds.Count() ); 107*cdf0e10cSrcweir pImpl->aFmtNms.Remove( 0, pImpl->aFmtNms.Count() ); 108*cdf0e10cSrcweir for ( sal_uInt16 n=0; n < nCount; n++ ) 109*cdf0e10cSrcweir AddClipbrdFormat( sal_uIntPtr( aClipFormats.Identifiers[n] ), aClipFormats.Names[n], n ); 110*cdf0e10cSrcweir 111*cdf0e10cSrcweir return sal_True; 112*cdf0e10cSrcweir } 113*cdf0e10cSrcweir 114*cdf0e10cSrcweir return sal_False; 115*cdf0e10cSrcweir } 116*cdf0e10cSrcweir 117*cdf0e10cSrcweir int SvxClipboardFmtItem::operator==( const SfxPoolItem& rComp ) const 118*cdf0e10cSrcweir { 119*cdf0e10cSrcweir int nRet = 0; 120*cdf0e10cSrcweir const SvxClipboardFmtItem& rCmp = (SvxClipboardFmtItem&)rComp; 121*cdf0e10cSrcweir if( rCmp.pImpl->aFmtNms.Count() == pImpl->aFmtNms.Count() ) 122*cdf0e10cSrcweir { 123*cdf0e10cSrcweir nRet = 1; 124*cdf0e10cSrcweir const String* pStr1, *pStr2; 125*cdf0e10cSrcweir for( sal_uInt16 n = 0, nEnd = rCmp.pImpl->aFmtNms.Count(); n < nEnd; ++n ) 126*cdf0e10cSrcweir { 127*cdf0e10cSrcweir if( pImpl->aFmtIds[ n ] != rCmp.pImpl->aFmtIds[ n ] || 128*cdf0e10cSrcweir ( (0 == ( pStr1 = pImpl->aFmtNms[ n ] )) ^ 129*cdf0e10cSrcweir (0 == ( pStr2 = rCmp.pImpl->aFmtNms[ n ] ) )) || 130*cdf0e10cSrcweir ( pStr1 && *pStr1 != *pStr2 )) 131*cdf0e10cSrcweir { 132*cdf0e10cSrcweir nRet = 0; 133*cdf0e10cSrcweir break; 134*cdf0e10cSrcweir } 135*cdf0e10cSrcweir } 136*cdf0e10cSrcweir } 137*cdf0e10cSrcweir return nRet; 138*cdf0e10cSrcweir } 139*cdf0e10cSrcweir 140*cdf0e10cSrcweir SfxPoolItem* SvxClipboardFmtItem::Clone( SfxItemPool * /*pPool*/ ) const 141*cdf0e10cSrcweir { 142*cdf0e10cSrcweir return new SvxClipboardFmtItem( *this ); 143*cdf0e10cSrcweir } 144*cdf0e10cSrcweir 145*cdf0e10cSrcweir void SvxClipboardFmtItem::AddClipbrdFormat( sal_uIntPtr nId, sal_uInt16 nPos ) 146*cdf0e10cSrcweir { 147*cdf0e10cSrcweir if( nPos > pImpl->aFmtNms.Count() ) 148*cdf0e10cSrcweir nPos = pImpl->aFmtNms.Count(); 149*cdf0e10cSrcweir String* pStr = 0; 150*cdf0e10cSrcweir pImpl->aFmtNms.Insert( pStr, nPos ); 151*cdf0e10cSrcweir pImpl->aFmtIds.Insert( nId, nPos ); 152*cdf0e10cSrcweir } 153*cdf0e10cSrcweir 154*cdf0e10cSrcweir void SvxClipboardFmtItem::AddClipbrdFormat( sal_uIntPtr nId, const String& rName, 155*cdf0e10cSrcweir sal_uInt16 nPos ) 156*cdf0e10cSrcweir { 157*cdf0e10cSrcweir if( nPos > pImpl->aFmtNms.Count() ) 158*cdf0e10cSrcweir nPos = pImpl->aFmtNms.Count(); 159*cdf0e10cSrcweir String* pStr = new String( rName ); 160*cdf0e10cSrcweir pImpl->aFmtNms.Insert( pStr, nPos ); 161*cdf0e10cSrcweir pImpl->aFmtIds.Insert( nId, nPos ); 162*cdf0e10cSrcweir } 163*cdf0e10cSrcweir 164*cdf0e10cSrcweir sal_uInt16 SvxClipboardFmtItem::Count() const 165*cdf0e10cSrcweir { 166*cdf0e10cSrcweir return pImpl->aFmtIds.Count(); 167*cdf0e10cSrcweir } 168*cdf0e10cSrcweir 169*cdf0e10cSrcweir sal_uIntPtr SvxClipboardFmtItem::GetClipbrdFormatId( sal_uInt16 nPos ) const 170*cdf0e10cSrcweir { 171*cdf0e10cSrcweir return pImpl->aFmtIds[ nPos ]; 172*cdf0e10cSrcweir } 173*cdf0e10cSrcweir 174*cdf0e10cSrcweir const String& SvxClipboardFmtItem::GetClipbrdFormatName( sal_uInt16 nPos ) const 175*cdf0e10cSrcweir { 176*cdf0e10cSrcweir const String* pS = pImpl->aFmtNms[ nPos ]; 177*cdf0e10cSrcweir return pS ? *pS : SvxClipboardFmtItem_Impl::sEmptyStr; 178*cdf0e10cSrcweir } 179*cdf0e10cSrcweir 180*cdf0e10cSrcweir 181