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  aClipFormats.Names.realloc( nCount );
60  for ( sal_uInt16 n=0; n < nCount; n++ )
61  {
62  aClipFormats.Identifiers[n] = static_cast<sal_Int64>(GetClipbrdFormatId( n ));
63  aClipFormats.Names[n] = GetClipbrdFormatName( n );
64  }
65 
66  rVal <<= aClipFormats;
67  return true;
68 }
69 
70 bool SvxClipboardFormatItem::PutValue( const css::uno::Any& rVal, sal_uInt8 /*nMemberId*/ )
71 {
72  css::frame::status::ClipboardFormats aClipFormats;
73  if ( rVal >>= aClipFormats )
74  {
75  sal_uInt16 nCount = sal_uInt16( aClipFormats.Identifiers.getLength() );
76 
77  pImpl->aFmtIds.clear();
78  pImpl->aFmtNms.clear();
79  for ( sal_uInt16 n=0; n < nCount; ++n )
80  AddClipbrdFormat( static_cast<SotClipboardFormatId>(aClipFormats.Identifiers[n]), aClipFormats.Names[n], n );
81 
82  return true;
83  }
84 
85  return false;
86 }
87 
89 {
90  if (!SfxPoolItem::operator==(rComp))
91  return false;
92  const SvxClipboardFormatItem& rCmp = static_cast<const SvxClipboardFormatItem&>(rComp);
93  if(rCmp.pImpl->aFmtNms.size() != pImpl->aFmtNms.size())
94  return false;
95 
96  int nRet = 1;
97  for( sal_uInt16 n = 0, nEnd = rCmp.pImpl->aFmtNms.size(); n < nEnd; ++n )
98  {
99  if( pImpl->aFmtIds[ n ] != rCmp.pImpl->aFmtIds[ n ] ||
100  pImpl->aFmtNms[n] != rCmp.pImpl->aFmtNms[n] )
101  {
102  nRet = 0;
103  break;
104  }
105  }
106 
107  return nRet;
108 }
109 
111 {
112  return new SvxClipboardFormatItem( *this );
113 }
114 
116 {
117  sal_uInt16 nPos = pImpl->aFmtNms.size();
118 
119  pImpl->aFmtNms.insert( pImpl->aFmtNms.begin() + nPos, OUString());
120  pImpl->aFmtIds.insert( pImpl->aFmtIds.begin() + nPos, nId );
121 }
122 
124  sal_uInt16 nPos )
125 {
126  if( nPos > pImpl->aFmtNms.size() )
127  nPos = pImpl->aFmtNms.size();
128 
129  pImpl->aFmtNms.insert(pImpl->aFmtNms.begin() + nPos, rName);
130  pImpl->aFmtIds.insert( pImpl->aFmtIds.begin()+nPos, nId );
131 }
132 
134 {
135  return pImpl->aFmtIds.size();
136 }
137 
139 {
140  return pImpl->aFmtIds[ nPos ];
141 }
142 
143 OUString const & SvxClipboardFormatItem::GetClipbrdFormatName( sal_uInt16 nPos ) const
144 {
145  return pImpl->aFmtNms[nPos];
146 }
147 
148 
149 /* 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:88
sal_Int64 n
sal_uInt16 Count() const
virtual bool PutValue(const css::uno::Any &rVal, sal_uInt8 nMemberId) override
Definition: clipfmtitem.cxx:70
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