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 <sal/config.h>
24 #include <svx/clipfmtitem.hxx>
25 #include <com/sun/star/frame/status/ClipboardFormats.hpp>
27 struct SvxClipboardFormatItem_Impl
29 std::vector
<OUString
> aFmtNms
;
30 std::vector
<SotClipboardFormatId
> aFmtIds
;
32 SvxClipboardFormatItem_Impl() {}
35 SfxPoolItem
* SvxClipboardFormatItem::CreateDefault() { return new SvxClipboardFormatItem(0); };
37 SvxClipboardFormatItem::SvxClipboardFormatItem( sal_uInt16 nId
)
38 : SfxPoolItem( nId
), pImpl( new SvxClipboardFormatItem_Impl
)
42 SvxClipboardFormatItem::SvxClipboardFormatItem( const SvxClipboardFormatItem
& rCpy
)
43 : SfxPoolItem( rCpy
),
44 pImpl( new SvxClipboardFormatItem_Impl( *rCpy
.pImpl
) )
48 SvxClipboardFormatItem::~SvxClipboardFormatItem()
52 bool SvxClipboardFormatItem::QueryValue( css::uno::Any
& rVal
, sal_uInt8
/*nMemberId*/ ) const
54 sal_uInt16 nCount
= Count();
56 css::frame::status::ClipboardFormats aClipFormats
;
58 aClipFormats
.Identifiers
.realloc( nCount
);
59 aClipFormats
.Names
.realloc( nCount
);
60 for ( sal_uInt16 n
=0; n
< nCount
; n
++ )
62 aClipFormats
.Identifiers
[n
] = static_cast<sal_Int64
>(GetClipbrdFormatId( n
));
63 aClipFormats
.Names
[n
] = GetClipbrdFormatName( n
);
66 rVal
<<= aClipFormats
;
70 bool SvxClipboardFormatItem::PutValue( const css::uno::Any
& rVal
, sal_uInt8
/*nMemberId*/ )
72 css::frame::status::ClipboardFormats aClipFormats
;
73 if ( rVal
>>= aClipFormats
)
75 sal_uInt16 nCount
= sal_uInt16( aClipFormats
.Identifiers
.getLength() );
77 pImpl
->aFmtIds
.clear();
78 pImpl
->aFmtNms
.clear();
79 for ( sal_uInt16 n
=0; n
< nCount
; ++n
)
80 AddClipbrdFormat( static_cast<SotClipboardFormatId
>(aClipFormats
.Identifiers
[n
]), aClipFormats
.Names
[n
], n
);
88 bool SvxClipboardFormatItem::operator==( const SfxPoolItem
& rComp
) const
90 if (!SfxPoolItem::operator==(rComp
))
92 const SvxClipboardFormatItem
& rCmp
= static_cast<const SvxClipboardFormatItem
&>(rComp
);
93 if(rCmp
.pImpl
->aFmtNms
.size() != pImpl
->aFmtNms
.size())
97 for( sal_uInt16 n
= 0, nEnd
= rCmp
.pImpl
->aFmtNms
.size(); n
< nEnd
; ++n
)
99 if( pImpl
->aFmtIds
[ n
] != rCmp
.pImpl
->aFmtIds
[ n
] ||
100 pImpl
->aFmtNms
[n
] != rCmp
.pImpl
->aFmtNms
[n
] )
110 SvxClipboardFormatItem
* SvxClipboardFormatItem::Clone( SfxItemPool
* /*pPool*/ ) const
112 return new SvxClipboardFormatItem( *this );
115 void SvxClipboardFormatItem::AddClipbrdFormat( SotClipboardFormatId nId
)
117 sal_uInt16 nPos
= pImpl
->aFmtNms
.size();
119 pImpl
->aFmtNms
.insert( pImpl
->aFmtNms
.begin() + nPos
, OUString());
120 pImpl
->aFmtIds
.insert( pImpl
->aFmtIds
.begin() + nPos
, nId
);
123 void SvxClipboardFormatItem::AddClipbrdFormat( SotClipboardFormatId nId
, const OUString
& rName
,
126 if( nPos
> pImpl
->aFmtNms
.size() )
127 nPos
= pImpl
->aFmtNms
.size();
129 pImpl
->aFmtNms
.insert(pImpl
->aFmtNms
.begin() + nPos
, rName
);
130 pImpl
->aFmtIds
.insert( pImpl
->aFmtIds
.begin()+nPos
, nId
);
133 sal_uInt16
SvxClipboardFormatItem::Count() const
135 return pImpl
->aFmtIds
.size();
138 SotClipboardFormatId
SvxClipboardFormatItem::GetClipbrdFormatId( sal_uInt16 nPos
) const
140 return pImpl
->aFmtIds
[ nPos
];
143 OUString
const & SvxClipboardFormatItem::GetClipbrdFormatName( sal_uInt16 nPos
) const
145 return pImpl
->aFmtNms
[nPos
];
149 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */