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 
38  : SfxPoolItem( nId ), pImpl( new SvxClipboardFormatItem_Impl )
39 {
40 }
41 
43  : SfxPoolItem( rCpy ),
44  pImpl( new SvxClipboardFormatItem_Impl( *rCpy.pImpl ) )
45 {
46 }
47 
49 {
50 }
51 
52 bool 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 
72 bool 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 
145 OUString const & SvxClipboardFormatItem::GetClipbrdFormatName( sal_uInt16 nPos ) const
146 {
147  return pImpl->aFmtNms[nPos];
148 }
149 
150 
151 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SotClipboardFormatId GetClipbrdFormatId(sal_uInt16 nPos) const
OUString const & GetClipbrdFormatName(sal_uInt16 nPos) const
virtual bool operator==(const SfxPoolItem &) const override
Definition: clipfmtitem.cxx:90
sal_Int64 n
sal_uInt16 Count() const
virtual bool PutValue(const css::uno::Any &rVal, sal_uInt8 nMemberId) override
Definition: clipfmtitem.cxx:72
int nCount
SotClipboardFormatId
static SfxPoolItem * CreateDefault()
Definition: clipfmtitem.cxx:35
virtual SvxClipboardFormatItem * Clone(SfxItemPool *pPool=nullptr) const override
virtual bool QueryValue(css::uno::Any &rVal, sal_uInt8 nMemberId=0) const override
Definition: clipfmtitem.cxx:52
SvxClipboardFormatItem(sal_uInt16 nId)
Definition: clipfmtitem.cxx:37
std::vector< SotClipboardFormatId > aFmtIds
Definition: clipfmtitem.cxx:30
unsigned char sal_uInt8
virtual ~SvxClipboardFormatItem() override
Definition: clipfmtitem.cxx:48
void AddClipbrdFormat(SotClipboardFormatId nId)
std::unique_ptr< SvxClipboardFormatItem_Impl > pImpl
Definition: clipfmtitem.hxx:57
std::vector< OUString > aFmtNms
Definition: clipfmtitem.cxx:29
sal_uInt16 nPos