1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_svx.hxx" 26 27 #define _SVSTDARR_ULONGS 28 #define _SVSTDARR_STRINGSDTOR 29 30 #include <svl/svstdarr.hxx> 31 #include <svx/clipfmtitem.hxx> 32 #include <com/sun/star/frame/status/ClipboardFormats.hpp> 33 34 struct SvxClipboardFmtItem_Impl 35 { 36 SvStringsDtor aFmtNms; 37 SvULongs aFmtIds; 38 static String sEmptyStr; 39 40 SvxClipboardFmtItem_Impl() : aFmtNms( 8, 8 ), aFmtIds( 8, 8 ) {} 41 SvxClipboardFmtItem_Impl( const SvxClipboardFmtItem_Impl& ); 42 }; 43 44 String SvxClipboardFmtItem_Impl::sEmptyStr; 45 46 TYPEINIT1_FACTORY( SvxClipboardFmtItem, SfxPoolItem , new SvxClipboardFmtItem(0)); 47 48 SvxClipboardFmtItem_Impl::SvxClipboardFmtItem_Impl( 49 const SvxClipboardFmtItem_Impl& rCpy ) 50 { 51 aFmtIds.Insert( &rCpy.aFmtIds, 0 ); 52 for( sal_uInt16 n = 0, nEnd = rCpy.aFmtNms.Count(); n < nEnd; ++n ) 53 { 54 String* pStr = rCpy.aFmtNms[ n ]; 55 if( pStr ) 56 pStr = new String( *pStr ); 57 aFmtNms.Insert( pStr, n ); 58 } 59 } 60 61 SvxClipboardFmtItem::SvxClipboardFmtItem( sal_uInt16 nId ) 62 : SfxPoolItem( nId ), pImpl( new SvxClipboardFmtItem_Impl ) 63 { 64 } 65 66 SvxClipboardFmtItem::SvxClipboardFmtItem( const SvxClipboardFmtItem& rCpy ) 67 : SfxPoolItem( rCpy.Which() ), 68 pImpl( new SvxClipboardFmtItem_Impl( *rCpy.pImpl ) ) 69 { 70 } 71 72 SvxClipboardFmtItem::~SvxClipboardFmtItem() 73 { 74 delete pImpl; 75 } 76 77 sal_Bool SvxClipboardFmtItem::QueryValue( com::sun::star::uno::Any& rVal, sal_uInt8 /*nMemberId*/ ) const 78 { 79 sal_uInt16 nCount = Count(); 80 81 ::com::sun::star::frame::status::ClipboardFormats aClipFormats; 82 83 aClipFormats.Identifiers.realloc( nCount ); 84 aClipFormats.Names.realloc( nCount ); 85 for ( sal_uInt16 n=0; n < nCount; n++ ) 86 { 87 aClipFormats.Identifiers[n] = (sal_Int64)GetClipbrdFormatId( n ); 88 aClipFormats.Names[n] = GetClipbrdFormatName( n ); 89 } 90 91 rVal <<= aClipFormats; 92 return sal_True; 93 } 94 95 sal_Bool SvxClipboardFmtItem::PutValue( const ::com::sun::star::uno::Any& rVal, sal_uInt8 /*nMemberId*/ ) 96 { 97 ::com::sun::star::frame::status::ClipboardFormats aClipFormats; 98 if ( rVal >>= aClipFormats ) 99 { 100 sal_uInt16 nCount = sal_uInt16( aClipFormats.Identifiers.getLength() ); 101 102 pImpl->aFmtIds.Remove( 0, pImpl->aFmtIds.Count() ); 103 pImpl->aFmtNms.Remove( 0, pImpl->aFmtNms.Count() ); 104 for ( sal_uInt16 n=0; n < nCount; n++ ) 105 AddClipbrdFormat( sal_uIntPtr( aClipFormats.Identifiers[n] ), aClipFormats.Names[n], n ); 106 107 return sal_True; 108 } 109 110 return sal_False; 111 } 112 113 int SvxClipboardFmtItem::operator==( const SfxPoolItem& rComp ) const 114 { 115 int nRet = 0; 116 const SvxClipboardFmtItem& rCmp = (SvxClipboardFmtItem&)rComp; 117 if( rCmp.pImpl->aFmtNms.Count() == pImpl->aFmtNms.Count() ) 118 { 119 nRet = 1; 120 const String* pStr1, *pStr2; 121 for( sal_uInt16 n = 0, nEnd = rCmp.pImpl->aFmtNms.Count(); n < nEnd; ++n ) 122 { 123 if( pImpl->aFmtIds[ n ] != rCmp.pImpl->aFmtIds[ n ] || 124 ( (0 == ( pStr1 = pImpl->aFmtNms[ n ] )) ^ 125 (0 == ( pStr2 = rCmp.pImpl->aFmtNms[ n ] ) )) || 126 ( pStr1 && *pStr1 != *pStr2 )) 127 { 128 nRet = 0; 129 break; 130 } 131 } 132 } 133 return nRet; 134 } 135 136 SfxPoolItem* SvxClipboardFmtItem::Clone( SfxItemPool * /*pPool*/ ) const 137 { 138 return new SvxClipboardFmtItem( *this ); 139 } 140 141 void SvxClipboardFmtItem::AddClipbrdFormat( sal_uIntPtr nId, sal_uInt16 nPos ) 142 { 143 if( nPos > pImpl->aFmtNms.Count() ) 144 nPos = pImpl->aFmtNms.Count(); 145 String* pStr = 0; 146 pImpl->aFmtNms.Insert( pStr, nPos ); 147 pImpl->aFmtIds.Insert( nId, nPos ); 148 } 149 150 void SvxClipboardFmtItem::AddClipbrdFormat( sal_uIntPtr nId, const String& rName, 151 sal_uInt16 nPos ) 152 { 153 if( nPos > pImpl->aFmtNms.Count() ) 154 nPos = pImpl->aFmtNms.Count(); 155 String* pStr = new String( rName ); 156 pImpl->aFmtNms.Insert( pStr, nPos ); 157 pImpl->aFmtIds.Insert( nId, nPos ); 158 } 159 160 sal_uInt16 SvxClipboardFmtItem::Count() const 161 { 162 return pImpl->aFmtIds.Count(); 163 } 164 165 sal_uIntPtr SvxClipboardFmtItem::GetClipbrdFormatId( sal_uInt16 nPos ) const 166 { 167 return pImpl->aFmtIds[ nPos ]; 168 } 169 170 const String& SvxClipboardFmtItem::GetClipbrdFormatName( sal_uInt16 nPos ) const 171 { 172 const String* pS = pImpl->aFmtNms[ nPos ]; 173 return pS ? *pS : SvxClipboardFmtItem_Impl::sEmptyStr; 174 } 175 176 177