/src/libreoffice/svx/source/items/clipfmtitem.cxx
Line | Count | Source |
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 | | |
27 | | struct SvxClipboardFormatItem_Impl |
28 | | { |
29 | | std::vector<OUString> aFmtNms; |
30 | | std::vector<SotClipboardFormatId> aFmtIds; |
31 | | |
32 | 0 | SvxClipboardFormatItem_Impl() {} |
33 | | }; |
34 | | |
35 | 0 | SfxPoolItem* SvxClipboardFormatItem::CreateDefault() { return new SvxClipboardFormatItem(TypedWhichId<SvxClipboardFormatItem>(0)); }; |
36 | | |
37 | | SvxClipboardFormatItem::SvxClipboardFormatItem( TypedWhichId<SvxClipboardFormatItem> nId ) |
38 | 0 | : SfxPoolItem( nId ), m_pImpl( new SvxClipboardFormatItem_Impl ) |
39 | 0 | { |
40 | 0 | } |
41 | | |
42 | | SvxClipboardFormatItem::SvxClipboardFormatItem( const SvxClipboardFormatItem& rCpy ) |
43 | 0 | : SfxPoolItem( rCpy ), |
44 | 0 | m_pImpl( new SvxClipboardFormatItem_Impl( *rCpy.m_pImpl ) ) |
45 | 0 | { |
46 | 0 | } |
47 | | |
48 | | SvxClipboardFormatItem::~SvxClipboardFormatItem() |
49 | 0 | { |
50 | 0 | } |
51 | | |
52 | | bool SvxClipboardFormatItem::QueryValue( css::uno::Any& rVal, sal_uInt8 /*nMemberId*/ ) const |
53 | 0 | { |
54 | 0 | sal_uInt16 nCount = Count(); |
55 | |
|
56 | 0 | css::frame::status::ClipboardFormats aClipFormats; |
57 | |
|
58 | 0 | aClipFormats.Identifiers.realloc( nCount ); |
59 | 0 | auto pIdentifiers = aClipFormats.Identifiers.getArray(); |
60 | 0 | aClipFormats.Names.realloc( nCount ); |
61 | 0 | auto pNames = aClipFormats.Names.getArray(); |
62 | 0 | for ( sal_uInt16 n=0; n < nCount; n++ ) |
63 | 0 | { |
64 | 0 | pIdentifiers[n] = static_cast<sal_Int64>(GetClipbrdFormatId( n )); |
65 | 0 | pNames[n] = GetClipbrdFormatName( n ); |
66 | 0 | } |
67 | |
|
68 | 0 | rVal <<= aClipFormats; |
69 | 0 | return true; |
70 | 0 | } |
71 | | |
72 | | bool SvxClipboardFormatItem::PutValue( const css::uno::Any& rVal, sal_uInt8 /*nMemberId*/ ) |
73 | 0 | { |
74 | 0 | css::frame::status::ClipboardFormats aClipFormats; |
75 | 0 | if ( rVal >>= aClipFormats ) |
76 | 0 | { |
77 | 0 | sal_uInt16 nCount = sal_uInt16( aClipFormats.Identifiers.getLength() ); |
78 | |
|
79 | 0 | m_pImpl->aFmtIds.clear(); |
80 | 0 | m_pImpl->aFmtNms.clear(); |
81 | 0 | for ( sal_uInt16 n=0; n < nCount; ++n ) |
82 | 0 | AddClipbrdFormat( static_cast<SotClipboardFormatId>(aClipFormats.Identifiers[n]), aClipFormats.Names[n], n ); |
83 | |
|
84 | 0 | return true; |
85 | 0 | } |
86 | | |
87 | 0 | return false; |
88 | 0 | } |
89 | | |
90 | | bool SvxClipboardFormatItem::operator==( const SfxPoolItem& rComp ) const |
91 | 0 | { |
92 | 0 | if (!SfxPoolItem::operator==(rComp)) |
93 | 0 | return false; |
94 | 0 | const SvxClipboardFormatItem& rCmp = static_cast<const SvxClipboardFormatItem&>(rComp); |
95 | 0 | if(rCmp.m_pImpl->aFmtNms.size() != m_pImpl->aFmtNms.size()) |
96 | 0 | return false; |
97 | | |
98 | 0 | int nRet = 1; |
99 | 0 | for( sal_uInt16 n = 0, nEnd = rCmp.m_pImpl->aFmtNms.size(); n < nEnd; ++n ) |
100 | 0 | { |
101 | 0 | if( m_pImpl->aFmtIds[ n ] != rCmp.m_pImpl->aFmtIds[ n ] || |
102 | 0 | m_pImpl->aFmtNms[n] != rCmp.m_pImpl->aFmtNms[n] ) |
103 | 0 | { |
104 | 0 | nRet = 0; |
105 | 0 | break; |
106 | 0 | } |
107 | 0 | } |
108 | |
|
109 | 0 | return nRet; |
110 | 0 | } |
111 | | |
112 | | SvxClipboardFormatItem* SvxClipboardFormatItem::Clone( SfxItemPool * /*pPool*/ ) const |
113 | 0 | { |
114 | 0 | return new SvxClipboardFormatItem( *this ); |
115 | 0 | } |
116 | | |
117 | | void SvxClipboardFormatItem::AddClipbrdFormat( SotClipboardFormatId nId ) |
118 | 0 | { |
119 | 0 | sal_uInt16 nPos = m_pImpl->aFmtNms.size(); |
120 | |
|
121 | 0 | m_pImpl->aFmtNms.insert( m_pImpl->aFmtNms.begin() + nPos, OUString()); |
122 | 0 | m_pImpl->aFmtIds.insert( m_pImpl->aFmtIds.begin() + nPos, nId ); |
123 | 0 | } |
124 | | |
125 | | void SvxClipboardFormatItem::AddClipbrdFormat( SotClipboardFormatId nId, const OUString& rName, |
126 | | sal_uInt16 nPos ) |
127 | 0 | { |
128 | 0 | if( nPos > m_pImpl->aFmtNms.size() ) |
129 | 0 | nPos = m_pImpl->aFmtNms.size(); |
130 | |
|
131 | 0 | m_pImpl->aFmtNms.insert(m_pImpl->aFmtNms.begin() + nPos, rName); |
132 | 0 | m_pImpl->aFmtIds.insert( m_pImpl->aFmtIds.begin()+nPos, nId ); |
133 | 0 | } |
134 | | |
135 | | sal_uInt16 SvxClipboardFormatItem::Count() const |
136 | 0 | { |
137 | 0 | return m_pImpl->aFmtIds.size(); |
138 | 0 | } |
139 | | |
140 | | SotClipboardFormatId SvxClipboardFormatItem::GetClipbrdFormatId( sal_uInt16 nPos ) const |
141 | 0 | { |
142 | 0 | return m_pImpl->aFmtIds[ nPos ]; |
143 | 0 | } |
144 | | |
145 | | OUString const & SvxClipboardFormatItem::GetClipbrdFormatName( sal_uInt16 nPos ) const |
146 | 0 | { |
147 | 0 | return m_pImpl->aFmtNms[nPos]; |
148 | 0 | } |
149 | | |
150 | | |
151 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |