1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: clipfmtitem.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
34 #define _SVSTDARR_ULONGS
35 #define _SVSTDARR_STRINGSDTOR
37 #include <svtools/svstdarr.hxx>
38 #include <clipfmtitem.hxx>
39 #include <com/sun/star/frame/status/ClipboardFormats.hpp>
41 struct SvxClipboardFmtItem_Impl
43 SvStringsDtor aFmtNms
;
45 static String sEmptyStr
;
47 SvxClipboardFmtItem_Impl() : aFmtNms( 8, 8 ), aFmtIds( 8, 8 ) {}
48 SvxClipboardFmtItem_Impl( const SvxClipboardFmtItem_Impl
& );
51 String
SvxClipboardFmtItem_Impl::sEmptyStr
;
53 TYPEINIT1_FACTORY( SvxClipboardFmtItem
, SfxPoolItem
, new SvxClipboardFmtItem(0));
55 SvxClipboardFmtItem_Impl::SvxClipboardFmtItem_Impl(
56 const SvxClipboardFmtItem_Impl
& rCpy
)
58 aFmtIds
.Insert( &rCpy
.aFmtIds
, 0 );
59 for( USHORT n
= 0, nEnd
= rCpy
.aFmtNms
.Count(); n
< nEnd
; ++n
)
61 String
* pStr
= rCpy
.aFmtNms
[ n
];
63 pStr
= new String( *pStr
);
64 aFmtNms
.Insert( pStr
, n
);
68 SvxClipboardFmtItem::SvxClipboardFmtItem( USHORT nId
)
69 : SfxPoolItem( nId
), pImpl( new SvxClipboardFmtItem_Impl
)
73 SvxClipboardFmtItem::SvxClipboardFmtItem( const SvxClipboardFmtItem
& rCpy
)
74 : SfxPoolItem( rCpy
.Which() ),
75 pImpl( new SvxClipboardFmtItem_Impl( *rCpy
.pImpl
) )
79 SvxClipboardFmtItem::~SvxClipboardFmtItem()
84 BOOL
SvxClipboardFmtItem::QueryValue( com::sun::star::uno::Any
& rVal
, BYTE
/*nMemberId*/ ) const
86 USHORT nCount
= Count();
88 ::com::sun::star::frame::status::ClipboardFormats aClipFormats
;
90 aClipFormats
.Identifiers
.realloc( nCount
);
91 aClipFormats
.Names
.realloc( nCount
);
92 for ( USHORT n
=0; n
< nCount
; n
++ )
94 aClipFormats
.Identifiers
[n
] = (sal_Int64
)GetClipbrdFormatId( n
);
95 aClipFormats
.Names
[n
] = GetClipbrdFormatName( n
);
98 rVal
<<= aClipFormats
;
102 sal_Bool
SvxClipboardFmtItem::PutValue( const ::com::sun::star::uno::Any
& rVal
, BYTE
/*nMemberId*/ )
104 ::com::sun::star::frame::status::ClipboardFormats aClipFormats
;
105 if ( rVal
>>= aClipFormats
)
107 USHORT nCount
= USHORT( aClipFormats
.Identifiers
.getLength() );
109 pImpl
->aFmtIds
.Remove( 0, pImpl
->aFmtIds
.Count() );
110 pImpl
->aFmtNms
.Remove( 0, pImpl
->aFmtNms
.Count() );
111 for ( USHORT n
=0; n
< nCount
; n
++ )
112 AddClipbrdFormat( ULONG( aClipFormats
.Identifiers
[n
] ), aClipFormats
.Names
[n
], n
);
120 int SvxClipboardFmtItem::operator==( const SfxPoolItem
& rComp
) const
123 const SvxClipboardFmtItem
& rCmp
= (SvxClipboardFmtItem
&)rComp
;
124 if( rCmp
.pImpl
->aFmtNms
.Count() == pImpl
->aFmtNms
.Count() )
127 const String
* pStr1
, *pStr2
;
128 for( USHORT n
= 0, nEnd
= rCmp
.pImpl
->aFmtNms
.Count(); n
< nEnd
; ++n
)
130 if( pImpl
->aFmtIds
[ n
] != rCmp
.pImpl
->aFmtIds
[ n
] ||
131 ( (0 == ( pStr1
= pImpl
->aFmtNms
[ n
] )) ^
132 (0 == ( pStr2
= rCmp
.pImpl
->aFmtNms
[ n
] ) )) ||
133 ( pStr1
&& *pStr1
!= *pStr2
))
143 SfxPoolItem
* SvxClipboardFmtItem::Clone( SfxItemPool
* /*pPool*/ ) const
145 return new SvxClipboardFmtItem( *this );
148 void SvxClipboardFmtItem::AddClipbrdFormat( ULONG nId
, USHORT nPos
)
150 if( nPos
> pImpl
->aFmtNms
.Count() )
151 nPos
= pImpl
->aFmtNms
.Count();
153 pImpl
->aFmtNms
.Insert( pStr
, nPos
);
154 pImpl
->aFmtIds
.Insert( nId
, nPos
);
157 void SvxClipboardFmtItem::AddClipbrdFormat( ULONG nId
, const String
& rName
,
160 if( nPos
> pImpl
->aFmtNms
.Count() )
161 nPos
= pImpl
->aFmtNms
.Count();
162 String
* pStr
= new String( rName
);
163 pImpl
->aFmtNms
.Insert( pStr
, nPos
);
164 pImpl
->aFmtIds
.Insert( nId
, nPos
);
167 USHORT
SvxClipboardFmtItem::Count() const
169 return pImpl
->aFmtIds
.Count();
172 ULONG
SvxClipboardFmtItem::GetClipbrdFormatId( USHORT nPos
) const
174 return pImpl
->aFmtIds
[ nPos
];
177 const String
& SvxClipboardFmtItem::GetClipbrdFormatName( USHORT nPos
) const
179 const String
* pS
= pImpl
->aFmtNms
[ nPos
];
180 return pS
? *pS
: SvxClipboardFmtItem_Impl::sEmptyStr
;