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