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