1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <svx/clipfmtitem.hxx>
21 #include <com/sun/star/frame/status/ClipboardFormats.hpp>
23 #include <boost/ptr_container/ptr_vector.hpp>
25 struct SvxClipboardFmtItem_Impl
27 boost::ptr_vector
< boost::nullable
<OUString
> > aFmtNms
;
28 std::vector
<sal_uIntPtr
> aFmtIds
;
30 SvxClipboardFmtItem_Impl() {}
31 SvxClipboardFmtItem_Impl( const SvxClipboardFmtItem_Impl
& );
34 TYPEINIT1_FACTORY( SvxClipboardFmtItem
, SfxPoolItem
, new SvxClipboardFmtItem(0));
36 SvxClipboardFmtItem_Impl::SvxClipboardFmtItem_Impl(
37 const SvxClipboardFmtItem_Impl
& rCpy
)
38 : aFmtNms(rCpy
.aFmtNms
)
39 , aFmtIds(rCpy
.aFmtIds
)
43 SvxClipboardFmtItem::SvxClipboardFmtItem( sal_uInt16 nId
)
44 : SfxPoolItem( nId
), pImpl( new SvxClipboardFmtItem_Impl
)
48 SvxClipboardFmtItem::SvxClipboardFmtItem( const SvxClipboardFmtItem
& rCpy
)
49 : SfxPoolItem( rCpy
.Which() ),
50 pImpl( new SvxClipboardFmtItem_Impl( *rCpy
.pImpl
) )
54 SvxClipboardFmtItem::~SvxClipboardFmtItem()
59 bool SvxClipboardFmtItem::QueryValue( com::sun::star::uno::Any
& rVal
, sal_uInt8
/*nMemberId*/ ) const
61 sal_uInt16 nCount
= Count();
63 ::com::sun::star::frame::status::ClipboardFormats aClipFormats
;
65 aClipFormats
.Identifiers
.realloc( nCount
);
66 aClipFormats
.Names
.realloc( nCount
);
67 for ( sal_uInt16 n
=0; n
< nCount
; n
++ )
69 aClipFormats
.Identifiers
[n
] = (sal_Int64
)GetClipbrdFormatId( n
);
70 aClipFormats
.Names
[n
] = GetClipbrdFormatName( n
);
73 rVal
<<= aClipFormats
;
77 bool SvxClipboardFmtItem::PutValue( const ::com::sun::star::uno::Any
& rVal
, sal_uInt8
/*nMemberId*/ )
79 ::com::sun::star::frame::status::ClipboardFormats aClipFormats
;
80 if ( rVal
>>= aClipFormats
)
82 sal_uInt16 nCount
= sal_uInt16( aClipFormats
.Identifiers
.getLength() );
84 pImpl
->aFmtIds
.clear();
85 pImpl
->aFmtNms
.clear();
86 for ( sal_uInt16 n
=0; n
< nCount
; ++n
)
87 AddClipbrdFormat( sal_uIntPtr( aClipFormats
.Identifiers
[n
] ), aClipFormats
.Names
[n
], n
);
95 int SvxClipboardFmtItem::operator==( const SfxPoolItem
& rComp
) const
97 const SvxClipboardFmtItem
& rCmp
= (SvxClipboardFmtItem
&)rComp
;
98 if(rCmp
.pImpl
->aFmtNms
.size() != pImpl
->aFmtNms
.size())
102 for( sal_uInt16 n
= 0, nEnd
= rCmp
.pImpl
->aFmtNms
.size(); n
< nEnd
; ++n
)
104 if( pImpl
->aFmtIds
[ n
] != rCmp
.pImpl
->aFmtIds
[ n
] ||
105 ( pImpl
->aFmtNms
.is_null(n
) ^ rCmp
.pImpl
->aFmtNms
.is_null(n
) ) ||
106 ( !pImpl
->aFmtNms
.is_null(n
) && pImpl
->aFmtNms
[n
] != rCmp
.pImpl
->aFmtNms
[n
] ) )
116 SfxPoolItem
* SvxClipboardFmtItem::Clone( SfxItemPool
* /*pPool*/ ) const
118 return new SvxClipboardFmtItem( *this );
121 void SvxClipboardFmtItem::AddClipbrdFormat( sal_uIntPtr nId
, sal_uInt16 nPos
)
123 if( nPos
> pImpl
->aFmtNms
.size() )
124 nPos
= pImpl
->aFmtNms
.size();
126 pImpl
->aFmtNms
.insert(pImpl
->aFmtNms
.begin() + nPos
, 0);
127 pImpl
->aFmtIds
.insert( pImpl
->aFmtIds
.begin()+nPos
, nId
);
130 void SvxClipboardFmtItem::AddClipbrdFormat( sal_uIntPtr nId
, const OUString
& rName
,
133 if( nPos
> pImpl
->aFmtNms
.size() )
134 nPos
= pImpl
->aFmtNms
.size();
136 pImpl
->aFmtNms
.insert(pImpl
->aFmtNms
.begin() + nPos
, new OUString(rName
));
137 pImpl
->aFmtIds
.insert( pImpl
->aFmtIds
.begin()+nPos
, nId
);
140 sal_uInt16
SvxClipboardFmtItem::Count() const
142 return pImpl
->aFmtIds
.size();
145 sal_uIntPtr
SvxClipboardFmtItem::GetClipbrdFormatId( sal_uInt16 nPos
) const
147 return pImpl
->aFmtIds
[ nPos
];
150 const OUString
SvxClipboardFmtItem::GetClipbrdFormatName( sal_uInt16 nPos
) const
152 return pImpl
->aFmtNms
.is_null(nPos
) ? OUString() : pImpl
->aFmtNms
[nPos
];
156 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */