Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / svx / source / items / clipfmtitem.cxx
blobcaae609f6204b9f1b19a1a29f8998cf11ef7fcbc
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
22 #include <vector>
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(TypedWhichId<SvxClipboardFormatItem>(0)); };
37 SvxClipboardFormatItem::SvxClipboardFormatItem( TypedWhichId<SvxClipboardFormatItem> 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 auto pIdentifiers = aClipFormats.Identifiers.getArray();
60 aClipFormats.Names.realloc( nCount );
61 auto pNames = aClipFormats.Names.getArray();
62 for ( sal_uInt16 n=0; n < nCount; n++ )
64 pIdentifiers[n] = static_cast<sal_Int64>(GetClipbrdFormatId( n ));
65 pNames[n] = GetClipbrdFormatName( n );
68 rVal <<= aClipFormats;
69 return true;
72 bool SvxClipboardFormatItem::PutValue( const css::uno::Any& rVal, sal_uInt8 /*nMemberId*/ )
74 css::frame::status::ClipboardFormats aClipFormats;
75 if ( rVal >>= aClipFormats )
77 sal_uInt16 nCount = sal_uInt16( aClipFormats.Identifiers.getLength() );
79 pImpl->aFmtIds.clear();
80 pImpl->aFmtNms.clear();
81 for ( sal_uInt16 n=0; n < nCount; ++n )
82 AddClipbrdFormat( static_cast<SotClipboardFormatId>(aClipFormats.Identifiers[n]), aClipFormats.Names[n], n );
84 return true;
87 return false;
90 bool SvxClipboardFormatItem::operator==( const SfxPoolItem& rComp ) const
92 if (!SfxPoolItem::operator==(rComp))
93 return false;
94 const SvxClipboardFormatItem& rCmp = static_cast<const SvxClipboardFormatItem&>(rComp);
95 if(rCmp.pImpl->aFmtNms.size() != pImpl->aFmtNms.size())
96 return false;
98 int nRet = 1;
99 for( sal_uInt16 n = 0, nEnd = rCmp.pImpl->aFmtNms.size(); n < nEnd; ++n )
101 if( pImpl->aFmtIds[ n ] != rCmp.pImpl->aFmtIds[ n ] ||
102 pImpl->aFmtNms[n] != rCmp.pImpl->aFmtNms[n] )
104 nRet = 0;
105 break;
109 return nRet;
112 SvxClipboardFormatItem* SvxClipboardFormatItem::Clone( SfxItemPool * /*pPool*/ ) const
114 return new SvxClipboardFormatItem( *this );
117 void SvxClipboardFormatItem::AddClipbrdFormat( SotClipboardFormatId nId )
119 sal_uInt16 nPos = pImpl->aFmtNms.size();
121 pImpl->aFmtNms.insert( pImpl->aFmtNms.begin() + nPos, OUString());
122 pImpl->aFmtIds.insert( pImpl->aFmtIds.begin() + nPos, nId );
125 void SvxClipboardFormatItem::AddClipbrdFormat( SotClipboardFormatId nId, const OUString& rName,
126 sal_uInt16 nPos )
128 if( nPos > pImpl->aFmtNms.size() )
129 nPos = pImpl->aFmtNms.size();
131 pImpl->aFmtNms.insert(pImpl->aFmtNms.begin() + nPos, rName);
132 pImpl->aFmtIds.insert( pImpl->aFmtIds.begin()+nPos, nId );
135 sal_uInt16 SvxClipboardFormatItem::Count() const
137 return pImpl->aFmtIds.size();
140 SotClipboardFormatId SvxClipboardFormatItem::GetClipbrdFormatId( sal_uInt16 nPos ) const
142 return pImpl->aFmtIds[ nPos ];
145 OUString const & SvxClipboardFormatItem::GetClipbrdFormatName( sal_uInt16 nPos ) const
147 return pImpl->aFmtNms[nPos];
151 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */