LibreOffice Module svx (master) 1
clipfmtitem.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <sal/config.h>
21
22#include <vector>
23
24#include <svx/clipfmtitem.hxx>
25#include <com/sun/star/frame/status/ClipboardFormats.hpp>
26
28{
29 std::vector<OUString> aFmtNms;
30 std::vector<SotClipboardFormatId> aFmtIds;
31
33};
34
36
39{
40}
41
43 : SfxPoolItem( rCpy ),
44 pImpl( new SvxClipboardFormatItem_Impl( *rCpy.pImpl ) )
45{
46}
47
49{
50}
51
52bool SvxClipboardFormatItem::QueryValue( css::uno::Any& rVal, sal_uInt8 /*nMemberId*/ ) const
53{
54 sal_uInt16 nCount = Count();
55
56 css::frame::status::ClipboardFormats aClipFormats;
57
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++ )
63 {
64 pIdentifiers[n] = static_cast<sal_Int64>(GetClipbrdFormatId( n ));
65 pNames[n] = GetClipbrdFormatName( n );
66 }
67
68 rVal <<= aClipFormats;
69 return true;
70}
71
72bool SvxClipboardFormatItem::PutValue( const css::uno::Any& rVal, sal_uInt8 /*nMemberId*/ )
73{
74 css::frame::status::ClipboardFormats aClipFormats;
75 if ( rVal >>= aClipFormats )
76 {
77 sal_uInt16 nCount = sal_uInt16( aClipFormats.Identifiers.getLength() );
78
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 );
83
84 return true;
85 }
86
87 return false;
88}
89
91{
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;
97
98 int nRet = 1;
99 for( sal_uInt16 n = 0, nEnd = rCmp.pImpl->aFmtNms.size(); n < nEnd; ++n )
100 {
101 if( pImpl->aFmtIds[ n ] != rCmp.pImpl->aFmtIds[ n ] ||
102 pImpl->aFmtNms[n] != rCmp.pImpl->aFmtNms[n] )
103 {
104 nRet = 0;
105 break;
106 }
107 }
108
109 return nRet;
110}
111
113{
114 return new SvxClipboardFormatItem( *this );
115}
116
118{
119 sal_uInt16 nPos = pImpl->aFmtNms.size();
120
121 pImpl->aFmtNms.insert( pImpl->aFmtNms.begin() + nPos, OUString());
122 pImpl->aFmtIds.insert( pImpl->aFmtIds.begin() + nPos, nId );
123}
124
126 sal_uInt16 nPos )
127{
128 if( nPos > pImpl->aFmtNms.size() )
129 nPos = pImpl->aFmtNms.size();
130
131 pImpl->aFmtNms.insert(pImpl->aFmtNms.begin() + nPos, rName);
132 pImpl->aFmtIds.insert( pImpl->aFmtIds.begin()+nPos, nId );
133}
134
136{
137 return pImpl->aFmtIds.size();
138}
139
141{
142 return pImpl->aFmtIds[ nPos ];
143}
144
145OUString const & SvxClipboardFormatItem::GetClipbrdFormatName( sal_uInt16 nPos ) const
146{
147 return pImpl->aFmtNms[nPos];
148}
149
150
151/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual bool PutValue(const css::uno::Any &rVal, sal_uInt8 nMemberId) override
Definition: clipfmtitem.cxx:72
OUString const & GetClipbrdFormatName(sal_uInt16 nPos) const
virtual SvxClipboardFormatItem * Clone(SfxItemPool *pPool=nullptr) const override
void AddClipbrdFormat(SotClipboardFormatId nId)
sal_uInt16 Count() const
SvxClipboardFormatItem(TypedWhichId< SvxClipboardFormatItem > nId)
Definition: clipfmtitem.cxx:37
static SfxPoolItem * CreateDefault()
Definition: clipfmtitem.cxx:35
virtual ~SvxClipboardFormatItem() override
Definition: clipfmtitem.cxx:48
SotClipboardFormatId GetClipbrdFormatId(sal_uInt16 nPos) const
virtual bool QueryValue(css::uno::Any &rVal, sal_uInt8 nMemberId=0) const override
Definition: clipfmtitem.cxx:52
virtual bool operator==(const SfxPoolItem &) const override
Definition: clipfmtitem.cxx:90
std::unique_ptr< SvxClipboardFormatItem_Impl > pImpl
Definition: clipfmtitem.hxx:57
int nCount
SotClipboardFormatId
sal_Int64 n
sal_uInt16 nPos
sal_Int16 nId
std::vector< SotClipboardFormatId > aFmtIds
Definition: clipfmtitem.cxx:30
std::vector< OUString > aFmtNms
Definition: clipfmtitem.cxx:29
unsigned char sal_uInt8