bump product version to 5.0.4.1
[LibreOffice.git] / svx / source / items / clipfmtitem.cxx
blobc16ba6f244904b051c1aebe94e439ce5bb1b7ebd
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() {}
33 SvxClipboardFormatItem_Impl( const SvxClipboardFormatItem_Impl& );
36 TYPEINIT1_FACTORY( SvxClipboardFormatItem, SfxPoolItem , new SvxClipboardFormatItem(0));
38 SvxClipboardFormatItem_Impl::SvxClipboardFormatItem_Impl(
39 const SvxClipboardFormatItem_Impl& rCpy )
40 : aFmtNms(rCpy.aFmtNms)
41 , aFmtIds(rCpy.aFmtIds)
45 SvxClipboardFormatItem::SvxClipboardFormatItem( sal_uInt16 nId )
46 : SfxPoolItem( nId ), pImpl( new SvxClipboardFormatItem_Impl )
50 SvxClipboardFormatItem::SvxClipboardFormatItem( const SvxClipboardFormatItem& rCpy )
51 : SfxPoolItem( rCpy.Which() ),
52 pImpl( new SvxClipboardFormatItem_Impl( *rCpy.pImpl ) )
56 SvxClipboardFormatItem::~SvxClipboardFormatItem()
58 delete pImpl;
61 bool SvxClipboardFormatItem::QueryValue( com::sun::star::uno::Any& rVal, sal_uInt8 /*nMemberId*/ ) const
63 sal_uInt16 nCount = Count();
65 ::com::sun::star::frame::status::ClipboardFormats aClipFormats;
67 aClipFormats.Identifiers.realloc( nCount );
68 aClipFormats.Names.realloc( nCount );
69 for ( sal_uInt16 n=0; n < nCount; n++ )
71 aClipFormats.Identifiers[n] = (sal_Int64)GetClipbrdFormatId( n );
72 aClipFormats.Names[n] = GetClipbrdFormatName( n );
75 rVal <<= aClipFormats;
76 return true;
79 bool SvxClipboardFormatItem::PutValue( const ::com::sun::star::uno::Any& rVal, sal_uInt8 /*nMemberId*/ )
81 ::com::sun::star::frame::status::ClipboardFormats aClipFormats;
82 if ( rVal >>= aClipFormats )
84 sal_uInt16 nCount = sal_uInt16( aClipFormats.Identifiers.getLength() );
86 pImpl->aFmtIds.clear();
87 pImpl->aFmtNms.clear();
88 for ( sal_uInt16 n=0; n < nCount; ++n )
89 AddClipbrdFormat( static_cast<SotClipboardFormatId>(aClipFormats.Identifiers[n]), aClipFormats.Names[n], n );
91 return true;
94 return false;
97 bool SvxClipboardFormatItem::operator==( const SfxPoolItem& rComp ) const
99 const SvxClipboardFormatItem& rCmp = static_cast<const SvxClipboardFormatItem&>(rComp);
100 if(rCmp.pImpl->aFmtNms.size() != pImpl->aFmtNms.size())
101 return false;
103 int nRet = 1;
104 for( sal_uInt16 n = 0, nEnd = rCmp.pImpl->aFmtNms.size(); n < nEnd; ++n )
106 if( pImpl->aFmtIds[ n ] != rCmp.pImpl->aFmtIds[ n ] ||
107 pImpl->aFmtNms[n] != rCmp.pImpl->aFmtNms[n] )
109 nRet = 0;
110 break;
114 return nRet;
117 SfxPoolItem* SvxClipboardFormatItem::Clone( SfxItemPool * /*pPool*/ ) const
119 return new SvxClipboardFormatItem( *this );
122 void SvxClipboardFormatItem::AddClipbrdFormat( SotClipboardFormatId nId, sal_uInt16 nPos )
124 if( nPos > pImpl->aFmtNms.size() )
125 nPos = pImpl->aFmtNms.size();
127 pImpl->aFmtNms.insert(pImpl->aFmtNms.begin() + nPos, OUString());
128 pImpl->aFmtIds.insert( pImpl->aFmtIds.begin()+nPos, nId );
131 void SvxClipboardFormatItem::AddClipbrdFormat( SotClipboardFormatId nId, const OUString& rName,
132 sal_uInt16 nPos )
134 if( nPos > pImpl->aFmtNms.size() )
135 nPos = pImpl->aFmtNms.size();
137 pImpl->aFmtNms.insert(pImpl->aFmtNms.begin() + nPos, rName);
138 pImpl->aFmtIds.insert( pImpl->aFmtIds.begin()+nPos, nId );
141 sal_uInt16 SvxClipboardFormatItem::Count() const
143 return pImpl->aFmtIds.size();
146 SotClipboardFormatId SvxClipboardFormatItem::GetClipbrdFormatId( sal_uInt16 nPos ) const
148 return pImpl->aFmtIds[ nPos ];
151 const OUString SvxClipboardFormatItem::GetClipbrdFormatName( sal_uInt16 nPos ) const
153 return pImpl->aFmtNms[nPos];
157 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */