LibreOffice Module framework (master) 1
rootitemcontainer.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 <com/sun/star/lang/IndexOutOfBoundsException.hpp>
26#include <properties.h>
27
28#include <com/sun/star/beans/PropertyAttribute.hpp>
29#include <rtl/ref.hxx>
30
31using namespace cppu;
32using namespace com::sun::star::uno;
33using namespace com::sun::star::lang;
34using namespace com::sun::star::beans;
35using namespace com::sun::star::container;
36
37constexpr OUStringLiteral WRONG_TYPE_EXCEPTION
38 = u"Type must be css::uno::Sequence< css::beans::PropertyValue >";
39
40const int PROPHANDLE_UINAME = 1;
41constexpr OUStringLiteral PROPNAME_UINAME = u"UIName";
42
43namespace framework
44{
45
48 , ::cppu::OPropertySetHelper ( *static_cast< ::cppu::OBroadcastHelper* >(this) )
49{
50}
51
54 , ::cppu::OPropertySetHelper ( *static_cast< ::cppu::OBroadcastHelper* >(this) )
55{
56 // We also have to copy the UIName property
57 try
58 {
59 Reference< XPropertySet > xPropSet( rSourceContainer, UNO_QUERY );
60 if ( xPropSet.is() )
61 {
62 xPropSet->getPropertyValue("UIName") >>= m_aUIName;
63 }
64 }
65 catch ( const Exception& )
66 {
67 }
68
69 if ( !rSourceContainer.is() )
70 return;
71
72 sal_Int32 nCount = rSourceContainer->getCount();
73 try
74 {
75 for ( sal_Int32 i = 0; i < nCount; i++ )
76 {
78 if ( rSourceContainer->getByIndex( i ) >>= aPropSeq )
79 {
80 sal_Int32 nContainerIndex = -1;
81 Reference< XIndexAccess > xIndexAccess;
82 for ( sal_Int32 j = 0; j < aPropSeq.getLength(); j++ )
83 {
84 if ( aPropSeq[j].Name == "ItemDescriptorContainer" )
85 {
86 aPropSeq[j].Value >>= xIndexAccess;
87 nContainerIndex = j;
88 break;
89 }
90 }
91
92 if ( xIndexAccess.is() && nContainerIndex >= 0 )
93 aPropSeq.getArray()[nContainerIndex].Value <<= deepCopyContainer( xIndexAccess );
94
95 m_aItemVector.push_back( aPropSeq );
96 }
97 }
98 }
99 catch ( const IndexOutOfBoundsException& )
100 {
101 }
102}
103
105{
106}
107
109{
110 Any aRet = RootItemContainer_BASE::queryInterface( _rType );
111 if ( !aRet.hasValue() )
112 aRet = OPropertySetHelper::queryInterface( _rType );
113 return aRet;
114}
115
117{
119 RootItemContainer_BASE::getTypes(),
121 );
122}
123
125{
127 if ( rSubContainer.is() )
128 {
129 ConstItemContainer* pSource = dynamic_cast<ConstItemContainer*>( rSubContainer.get() );
130 rtl::Reference<ItemContainer> pSubContainer;
131 if ( pSource )
132 pSubContainer = new ItemContainer( *pSource, m_aShareMutex );
133 else
134 pSubContainer = new ItemContainer( rSubContainer, m_aShareMutex );
135 xReturn = pSubContainer;
136 }
137
138 return xReturn;
139}
140
141// XElementAccess
143{
144 ShareGuard aLock( m_aShareMutex );
145 return ( !m_aItemVector.empty() );
146}
147
148// XIndexAccess
149sal_Int32 SAL_CALL RootItemContainer::getCount()
150{
151 ShareGuard aLock( m_aShareMutex );
152 return m_aItemVector.size();
153}
154
156{
157 ShareGuard aLock( m_aShareMutex );
158 if ( sal_Int32( m_aItemVector.size()) <= Index )
159 throw IndexOutOfBoundsException( OUString(), static_cast<OWeakObject *>(this) );
160
161 return Any( m_aItemVector[Index] );
162}
163
164// XIndexContainer
165void SAL_CALL RootItemContainer::insertByIndex( sal_Int32 Index, const Any& aItem )
166{
168 if ( !(aItem >>= aSeq) )
169 throw IllegalArgumentException( WRONG_TYPE_EXCEPTION, static_cast<OWeakObject *>(this), 2 );
170
171 ShareGuard aLock( m_aShareMutex );
172 if ( sal_Int32( m_aItemVector.size()) == Index )
173 m_aItemVector.push_back( aSeq );
174 else if ( sal_Int32( m_aItemVector.size()) >Index )
175 {
176 std::vector< Sequence< PropertyValue > >::iterator aIter = m_aItemVector.begin();
177 aIter += Index;
178 m_aItemVector.insert( aIter, aSeq );
179 }
180 else
181 throw IndexOutOfBoundsException( OUString(), static_cast<OWeakObject *>(this) );
182}
183
184void SAL_CALL RootItemContainer::removeByIndex( sal_Int32 nIndex )
185{
186 ShareGuard aLock( m_aShareMutex );
187 if ( static_cast<sal_Int32>(m_aItemVector.size()) <= nIndex )
188 throw IndexOutOfBoundsException( OUString(), static_cast<OWeakObject *>(this) );
189
190 m_aItemVector.erase(m_aItemVector.begin() + nIndex);
191}
192
193void SAL_CALL RootItemContainer::replaceByIndex( sal_Int32 Index, const Any& aItem )
194{
196 if ( !(aItem >>= aSeq) )
197 throw IllegalArgumentException( WRONG_TYPE_EXCEPTION, static_cast<OWeakObject *>(this), 2 );
198
199 ShareGuard aLock( m_aShareMutex );
200 if ( sal_Int32( m_aItemVector.size()) <= Index )
201 throw IndexOutOfBoundsException( OUString(), static_cast<OWeakObject *>(this) );
202
204}
205
207{
208 return static_cast<OWeakObject *>(new ItemContainer( m_aShareMutex ));
209}
210
212{
213 return static_cast<OWeakObject *>(new ItemContainer( m_aShareMutex ));
214}
215
216// XPropertySet helper
218 Any& aOldValue ,
219 sal_Int32 nHandle ,
220 const Any& aValue )
221{
222 // Initialize state with sal_False !!!
223 // (Handle can be invalid)
224 bool bReturn = false;
225
226 switch( nHandle )
227 {
230 css::uno::Any(m_aUIName),
231 aValue,
232 aOldValue,
233 aConvertedValue);
234 break;
235 }
236
237 // Return state of operation.
238 return bReturn;
239}
240
242 const css::uno::Any& aValue )
243{
244 switch( nHandle )
245 {
247 aValue >>= m_aUIName;
248 break;
249 }
250}
251
252void SAL_CALL RootItemContainer::getFastPropertyValue( css::uno::Any& aValue ,
253 sal_Int32 nHandle ) const
254{
255 switch( nHandle )
256 {
258 aValue <<= m_aUIName;
259 break;
260 }
261}
262
264{
265 // Define static member to give structure of properties to baseclass "OPropertySetHelper".
266 // "impl_getStaticPropertyDescriptor" is a non exported and static function, who will define a static propertytable.
267 // "true" say: Table is sorted by name.
268 static ::cppu::OPropertyArrayHelper ourInfoHelper( impl_getStaticPropertyDescriptor(), true );
269
270 return ourInfoHelper;
271}
272
273css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL RootItemContainer::getPropertySetInfo()
274{
275 // Create structure of propertysetinfo for baseclass "OPropertySetHelper".
276 // (Use method "getInfoHelper()".)
277 static css::uno::Reference< css::beans::XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) );
278
279 return xInfo;
280}
281
282css::uno::Sequence< css::beans::Property > RootItemContainer::impl_getStaticPropertyDescriptor()
283{
284 // Create a property array to initialize sequence!
285 // Table of all predefined properties of this class. It's used from OPropertySetHelper-class!
286 // Don't forget to change the defines (see begin of this file), if you add, change or delete a property in this list!!!
287 // It's necessary for methods of OPropertySetHelper.
288 // ATTENTION:
289 // YOU MUST SORT FOLLOW TABLE BY NAME ALPHABETICAL !!!
290
291 return
292 {
293 css::beans::Property( PROPNAME_UINAME, PROPHANDLE_UINAME ,
295 css::beans::PropertyAttribute::TRANSIENT )
296 };
297}
298
299} // namespace framework
300
301/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
struct _ADOIndex Index
static css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL createPropertySetInfo(IPropertyArrayHelper &rProperties)
css::uno::Sequence< css::uno::Type > getTypes()
static bool willPropertyBeChanged(const css::uno::Any &aCurrentValue, const css::uno::Any &aNewValue, css::uno::Any &aOldValue, css::uno::Any &aChangedValue)
checks if given property will be changed by this settings.
Definition: properties.h:112
virtual void SAL_CALL getFastPropertyValue(css::uno::Any &aValue, sal_Int32 nHandle) const override
virtual void SAL_CALL replaceByIndex(sal_Int32 Index, const css::uno::Any &Element) override
virtual sal_Bool SAL_CALL hasElements() override
virtual void SAL_CALL setFastPropertyValue_NoBroadcast(sal_Int32 nHandle, const css::uno::Any &aValue) override
virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override
virtual css::uno::Any SAL_CALL getByIndex(sal_Int32 Index) override
std::vector< css::uno::Sequence< css::beans::PropertyValue > > m_aItemVector
virtual void SAL_CALL removeByIndex(sal_Int32 Index) override
virtual void SAL_CALL insertByIndex(sal_Int32 Index, const css::uno::Any &Element) override
virtual css::uno::Reference< css::uno::XInterface > SAL_CALL createInstanceWithArgumentsAndContext(const css::uno::Sequence< css::uno::Any > &Arguments, const css::uno::Reference< css::uno::XComponentContext > &Context) override
static css::uno::Sequence< css::beans::Property > impl_getStaticPropertyDescriptor()
virtual sal_Bool SAL_CALL convertFastPropertyValue(css::uno::Any &aConvertedValue, css::uno::Any &aOldValue, sal_Int32 nHandle, const css::uno::Any &aValue) 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 ::cppu::IPropertyArrayHelper &SAL_CALL getInfoHelper() override
virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type &type) override
virtual sal_Int32 SAL_CALL getCount() override
virtual css::uno::Reference< css::uno::XInterface > SAL_CALL createInstanceWithContext(const css::uno::Reference< css::uno::XComponentContext > &Context) override
virtual ~RootItemContainer() override
int nCount
float u
sal_Int32 nIndex
Sequence< sal_Int8 > aSeq
css::uno::Sequence< T > concatSequences(const css::uno::Sequence< T > &rS1, const Ss &... rSn)
Type
int i
sal_Int32 nHandle
constexpr OUStringLiteral WRONG_TYPE_EXCEPTION
constexpr OUStringLiteral PROPNAME_UINAME
const int PROPHANDLE_UINAME
unsigned char sal_Bool
std::mutex m_aMutex