LibreOffice Module framework (master) 1
constitemcontainer.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
22
23#include <com/sun/star/beans/PropertyAttribute.hpp>
24#include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
25
28#include <rtl/ref.hxx>
29
30using namespace cppu;
31using namespace com::sun::star::uno;
32using namespace com::sun::star::lang;
33using namespace com::sun::star::beans;
34using namespace com::sun::star::container;
35
36const int PROPHANDLE_UINAME = 1;
37constexpr OUStringLiteral PROPNAME_UINAME = u"UIName";
38
39namespace framework
40{
41
43{
44}
45
47{
48 ShareGuard aLock( rItemContainer.m_aShareMutex );
49 copyItemContainer( rItemContainer.m_aItemVector );
50}
51
52ConstItemContainer::ConstItemContainer( const Reference< XIndexAccess >& rSourceContainer, bool bFastCopy )
53{
54 // We also have to copy the UIName property
55 try
56 {
57 Reference< XPropertySet > xPropSet( rSourceContainer, UNO_QUERY );
58 if ( xPropSet.is() )
59 {
60 xPropSet->getPropertyValue("UIName") >>= m_aUIName;
61 }
62 }
63 catch ( const Exception& )
64 {
65 }
66
67 if ( !rSourceContainer.is() )
68 return;
69
70 try
71 {
72 sal_Int32 nCount = rSourceContainer->getCount();
73 m_aItemVector.reserve(nCount);
74 if ( bFastCopy )
75 {
76 for ( sal_Int32 i = 0; i < nCount; i++ )
77 {
79 if ( rSourceContainer->getByIndex( i ) >>= aPropSeq )
80 m_aItemVector.push_back( aPropSeq );
81 }
82 }
83 else
84 {
85 for ( sal_Int32 i = 0; i < nCount; i++ )
86 {
88 if ( rSourceContainer->getByIndex( i ) >>= aPropSeq )
89 {
90 sal_Int32 nContainerIndex = -1;
91 Reference< XIndexAccess > xIndexAccess;
92 for ( sal_Int32 j = 0; j < aPropSeq.getLength(); j++ )
93 {
94 if ( aPropSeq[j].Name == "ItemDescriptorContainer" )
95 {
96 aPropSeq[j].Value >>= xIndexAccess;
97 nContainerIndex = j;
98 break;
99 }
100 }
101
102 if ( xIndexAccess.is() && nContainerIndex >= 0 )
103 aPropSeq.getArray()[nContainerIndex].Value <<= deepCopyContainer( xIndexAccess );
104
105 m_aItemVector.push_back( aPropSeq );
106 }
107 }
108 }
109 }
110 catch ( const IndexOutOfBoundsException& )
111 {
112 }
113}
114
116{
117}
118
119// private
120void ConstItemContainer::copyItemContainer( const std::vector< Sequence< PropertyValue > >& rSourceVector )
121{
122 const sal_uInt32 nCount = rSourceVector.size();
123 for ( sal_uInt32 i = 0; i < nCount; i++ )
124 {
125 sal_Int32 nContainerIndex = -1;
126 Sequence< PropertyValue > aPropSeq( rSourceVector[i] );
127 Reference< XIndexAccess > xIndexAccess;
128 for ( sal_Int32 j = 0; j < aPropSeq.getLength(); j++ )
129 {
130 if ( aPropSeq[j].Name == "ItemDescriptorContainer" )
131 {
132 aPropSeq[j].Value >>= xIndexAccess;
133 nContainerIndex = j;
134 break;
135 }
136 }
137
138 if ( xIndexAccess.is() && nContainerIndex >= 0 )
139 aPropSeq.getArray()[nContainerIndex].Value <<= deepCopyContainer( xIndexAccess );
140
141 m_aItemVector.push_back( aPropSeq );
142 }
143}
144
146{
148 if ( rSubContainer.is() )
149 {
150 ItemContainer* pSource = dynamic_cast<ItemContainer*>( rSubContainer.get() );
152 if ( pSource )
153 pSubContainer = new ConstItemContainer( *pSource );
154 else
155 pSubContainer = new ConstItemContainer( rSubContainer );
156 xReturn = pSubContainer;
157 }
158
159 return xReturn;
160}
161
162// XElementAccess
164{
165 return ( !m_aItemVector.empty() );
166}
167
168// XIndexAccess
170{
171 return m_aItemVector.size();
172}
173
175{
176 if ( sal_Int32( m_aItemVector.size()) <= Index )
177 throw IndexOutOfBoundsException( OUString(), static_cast<OWeakObject *>(this) );
178 return Any( m_aItemVector[Index] );
179}
180
181namespace
182{
183 std::vector<comphelper::PropertyMapEntry> makePropertyMap(const css::uno::Sequence<css::beans::Property>& rProps)
184 {
185 std::vector<comphelper::PropertyMapEntry> aEntries;
186 for (auto const& it : rProps)
187 aEntries.emplace_back(it.Name, it.Handle, it.Type, it.Attributes, 0);
188 return aEntries;
189 }
190}
191
192// XPropertySet
194{
195 // Create structure of propertysetinfo for baseclass "OPropertySetHelper".
196 // (Use method "getInfoHelper()".)
197 static std::vector<comphelper::PropertyMapEntry> aPropertyInfos(makePropertyMap(getInfoHelper().getProperties()));
198 static Reference< XPropertySetInfo > xInfo(new comphelper::PropertySetInfo(aPropertyInfos));
199
200 return xInfo;
201}
202
203void SAL_CALL ConstItemContainer::setPropertyValue( const OUString&, const Any& )
204{
205}
206
207Any SAL_CALL ConstItemContainer::getPropertyValue( const OUString& PropertyName )
208{
209 if ( PropertyName == PROPNAME_UINAME )
210 return Any( m_aUIName );
211
212 throw UnknownPropertyException(PropertyName);
213}
214
215void SAL_CALL ConstItemContainer::addPropertyChangeListener( const OUString&, const css::uno::Reference< css::beans::XPropertyChangeListener >& )
216{
217}
218
219void SAL_CALL ConstItemContainer::removePropertyChangeListener( const OUString&, const css::uno::Reference< css::beans::XPropertyChangeListener >& )
220{
221 // Only read-only properties - do nothing
222}
223
224void SAL_CALL ConstItemContainer::addVetoableChangeListener( const OUString&, const css::uno::Reference< css::beans::XVetoableChangeListener >& )
225{
226 // Only read-only properties - do nothing
227}
228
229void SAL_CALL ConstItemContainer::removeVetoableChangeListener( const OUString&, const css::uno::Reference< css::beans::XVetoableChangeListener >& )
230{
231 // Only read-only properties - do nothing
232}
233
234// XFastPropertySet
235void SAL_CALL ConstItemContainer::setFastPropertyValue( sal_Int32, const css::uno::Any& )
236{
237}
238
240{
241 if ( nHandle == PROPHANDLE_UINAME )
242 return Any( m_aUIName );
243
244 throw UnknownPropertyException(OUString::number(nHandle));
245}
246
248{
249 // Define static member to give structure of properties to baseclass "OPropertySetHelper".
250 // "impl_getStaticPropertyDescriptor" is a non exported and static function, who will define a static propertytable.
251 // "true" say: Table is sorted by name.
252 static ::cppu::OPropertyArrayHelper ourInfoHelper( impl_getStaticPropertyDescriptor(), true );
253
254 return ourInfoHelper;
255}
256
257css::uno::Sequence< css::beans::Property > ConstItemContainer::impl_getStaticPropertyDescriptor()
258{
259 // Create a property array to initialize sequence!
260 // Table of all predefined properties of this class. It's used from OPropertySetHelper-class!
261 // Don't forget to change the defines (see begin of this file), if you add, change or delete a property in this list!!!
262 // It's necessary for methods of OPropertySetHelper.
263 // ATTENTION:
264 // YOU MUST SORT FOLLOW TABLE BY NAME ALPHABETICAL !!!
265
266 return
267 {
268 css::beans::Property( PROPNAME_UINAME, PROPHANDLE_UINAME ,
270 css::beans::PropertyAttribute::TRANSIENT | css::beans::PropertyAttribute::READONLY )
271 };
272}
273
274} // namespace framework
275
276/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
struct _ADOIndex Index
virtual void SAL_CALL setPropertyValue(const OUString &aPropertyName, const css::uno::Any &aValue) override
std::vector< css::uno::Sequence< css::beans::PropertyValue > > m_aItemVector
css::uno::Sequence< css::beans::Property > impl_getStaticPropertyDescriptor()
::cppu::IPropertyArrayHelper & getInfoHelper()
virtual css::uno::Any SAL_CALL getFastPropertyValue(sal_Int32 nHandle) override
virtual sal_Int32 SAL_CALL getCount() override
virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() override
css::uno::Reference< css::container::XIndexAccess > deepCopyContainer(const css::uno::Reference< css::container::XIndexAccess > &rSubContainer)
virtual void SAL_CALL removePropertyChangeListener(const OUString &aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener > &aListener) override
void copyItemContainer(const std::vector< css::uno::Sequence< css::beans::PropertyValue > > &rSourceVector)
virtual void SAL_CALL setFastPropertyValue(sal_Int32 nHandle, const css::uno::Any &aValue) override
virtual css::uno::Any SAL_CALL getByIndex(sal_Int32 Index) override
virtual sal_Bool SAL_CALL hasElements() override
virtual void SAL_CALL removeVetoableChangeListener(const OUString &PropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener > &aListener) override
virtual css::uno::Any SAL_CALL getPropertyValue(const OUString &PropertyName) override
virtual void SAL_CALL addVetoableChangeListener(const OUString &PropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener > &aListener) override
virtual void SAL_CALL addPropertyChangeListener(const OUString &aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener > &xListener) override
ShareableMutex m_aShareMutex
std::vector< css::uno::Sequence< css::beans::PropertyValue > > m_aItemVector
constexpr OUStringLiteral PROPNAME_UINAME
const int PROPHANDLE_UINAME
int nCount
float u
ScXMLEditAttributeMap::Entry const aEntries[]
int i
sal_Int32 nHandle
OUString Name
unsigned char sal_Bool