lok: vcl: fix multiple floatwin removal case more robustly.
[LibreOffice.git] / ucbhelper / source / provider / contentinfo.cxx
blob1d52bdf3cc11a863e9673342179428880530f259
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 /**************************************************************************
21 TODO
22 **************************************************************************
24 *************************************************************************/
25 #include <com/sun/star/beans/PropertyValue.hpp>
26 #include <com/sun/star/ucb/UnsupportedCommandException.hpp>
27 #include <com/sun/star/ucb/XPropertySetRegistry.hpp>
28 #include <com/sun/star/beans/XPropertySetInfo.hpp>
29 #include <com/sun/star/ucb/XCommandInfo.hpp>
31 #include <cppuhelper/queryinterface.hxx>
32 #include <osl/mutex.hxx>
33 #include <ucbhelper/contenthelper.hxx>
34 #include <ucbhelper/contentinfo.hxx>
35 #include <ucbhelper/macros.hxx>
37 using namespace com::sun::star;
40 // PropertySetInfo Implementation.
43 namespace ucbhelper {
45 PropertySetInfo::PropertySetInfo(
46 const uno::Reference< css::ucb::XCommandEnvironment >& rxEnv,
47 ContentImplHelper* pContent )
48 : m_xEnv( rxEnv ),
49 m_pContent( pContent )
54 // virtual
55 PropertySetInfo::~PropertySetInfo()
60 // XInterface methods.
62 void SAL_CALL PropertySetInfo::acquire()
63 throw()
65 OWeakObject::acquire();
68 void SAL_CALL PropertySetInfo::release()
69 throw()
71 OWeakObject::release();
74 css::uno::Any SAL_CALL PropertySetInfo::queryInterface( const css::uno::Type & rType )
76 css::uno::Any aRet = cppu::queryInterface( rType,
77 static_cast< lang::XTypeProvider* >(this),
78 static_cast< beans::XPropertySetInfo* >(this)
80 return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType );
83 // XTypeProvider methods.
84 XTYPEPROVIDER_IMPL_2( PropertySetInfo,
85 lang::XTypeProvider,
86 beans::XPropertySetInfo );
89 // XPropertySetInfo methods.
92 // virtual
93 uno::Sequence< beans::Property > SAL_CALL PropertySetInfo::getProperties()
95 if ( !m_pProps )
97 osl::MutexGuard aGuard( m_aMutex );
98 if ( !m_pProps )
101 // Get info for core ( native) properties.
106 uno::Sequence< beans::Property > aProps
107 = m_pContent->getProperties( m_xEnv );
108 m_pProps.reset(new uno::Sequence< beans::Property >( aProps ));
110 catch ( uno::RuntimeException const & )
112 throw;
114 catch ( uno::Exception const & )
116 m_pProps.reset(new uno::Sequence< beans::Property >( 0 ));
120 // Get info for additional properties.
123 uno::Reference< css::ucb::XPersistentPropertySet >
124 xSet ( m_pContent->getAdditionalPropertySet( false ) );
126 if ( xSet.is() )
128 // Get property set info.
129 uno::Reference< beans::XPropertySetInfo > xInfo(
130 xSet->getPropertySetInfo() );
131 if ( xInfo.is() )
133 const uno::Sequence< beans::Property >& rAddProps
134 = xInfo->getProperties();
135 sal_Int32 nAddProps = rAddProps.getLength();
136 if ( nAddProps > 0 )
138 sal_Int32 nPos = m_pProps->getLength();
139 m_pProps->realloc( nPos + nAddProps );
141 beans::Property* pProps = m_pProps->getArray();
142 const beans::Property* pAddProps
143 = rAddProps.getConstArray();
145 for ( sal_Int32 n = 0; n < nAddProps; ++n, ++nPos )
146 pProps[ nPos ] = pAddProps[ n ];
152 return *m_pProps;
156 // virtual
157 beans::Property SAL_CALL PropertySetInfo::getPropertyByName(
158 const OUString& aName )
160 beans::Property aProp;
161 if ( queryProperty( aName, aProp ) )
162 return aProp;
164 throw beans::UnknownPropertyException();
168 // virtual
169 sal_Bool SAL_CALL PropertySetInfo::hasPropertyByName(
170 const OUString& Name )
172 beans::Property aProp;
173 return queryProperty( Name, aProp );
177 // Non-Interface methods.
180 void PropertySetInfo::reset()
182 osl::MutexGuard aGuard( m_aMutex );
183 m_pProps.reset();
187 bool PropertySetInfo::queryProperty(
188 const OUString& rName, beans::Property& rProp )
190 osl::MutexGuard aGuard( m_aMutex );
192 getProperties();
194 const beans::Property* pProps = m_pProps->getConstArray();
195 sal_Int32 nCount = m_pProps->getLength();
196 for ( sal_Int32 n = 0; n < nCount; ++n )
198 const beans::Property& rCurrProp = pProps[ n ];
199 if ( rCurrProp.Name == rName )
201 rProp = rCurrProp;
202 return true;
206 return false;
210 // CommandProcessorInfo Implementation.
213 CommandProcessorInfo::CommandProcessorInfo(
214 const uno::Reference< css::ucb::XCommandEnvironment >& rxEnv,
215 ContentImplHelper* pContent )
216 : m_xEnv( rxEnv ),
217 m_pContent( pContent )
222 // virtual
223 CommandProcessorInfo::~CommandProcessorInfo()
228 // XInterface methods.
231 void SAL_CALL CommandProcessorInfo::acquire()
232 throw()
234 OWeakObject::acquire();
237 void SAL_CALL CommandProcessorInfo::release()
238 throw()
240 OWeakObject::release();
243 css::uno::Any SAL_CALL CommandProcessorInfo::queryInterface( const css::uno::Type & rType )
245 css::uno::Any aRet = cppu::queryInterface( rType,
246 static_cast< lang::XTypeProvider* >(this),
247 static_cast< css::ucb::XCommandInfo* >(this)
249 return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType );
252 // XTypeProvider methods.
255 XTYPEPROVIDER_IMPL_2( CommandProcessorInfo,
256 lang::XTypeProvider,
257 css::ucb::XCommandInfo );
260 // XCommandInfo methods.
263 // virtual
264 uno::Sequence< css::ucb::CommandInfo > SAL_CALL
265 CommandProcessorInfo::getCommands()
267 if ( !m_pCommands )
269 osl::MutexGuard aGuard( m_aMutex );
270 if ( !m_pCommands )
273 // Get info for commands.
278 uno::Sequence< css::ucb::CommandInfo > aCmds
279 = m_pContent->getCommands( m_xEnv );
280 m_pCommands.reset(new uno::Sequence< css::ucb::CommandInfo >( aCmds ));
282 catch ( uno::RuntimeException const & )
284 throw;
286 catch ( uno::Exception const & )
288 m_pCommands.reset(new uno::Sequence< css::ucb::CommandInfo >( 0 ));
292 return *m_pCommands;
296 // virtual
297 css::ucb::CommandInfo SAL_CALL
298 CommandProcessorInfo::getCommandInfoByName(
299 const OUString& Name )
301 css::ucb::CommandInfo aInfo;
302 if ( queryCommand( Name, aInfo ) )
303 return aInfo;
305 throw css::ucb::UnsupportedCommandException();
309 // virtual
310 css::ucb::CommandInfo SAL_CALL
311 CommandProcessorInfo::getCommandInfoByHandle( sal_Int32 Handle )
313 css::ucb::CommandInfo aInfo;
314 if ( queryCommand( Handle, aInfo ) )
315 return aInfo;
317 throw css::ucb::UnsupportedCommandException();
321 // virtual
322 sal_Bool SAL_CALL CommandProcessorInfo::hasCommandByName(
323 const OUString& Name )
325 css::ucb::CommandInfo aInfo;
326 return queryCommand( Name, aInfo );
330 // virtual
331 sal_Bool SAL_CALL CommandProcessorInfo::hasCommandByHandle( sal_Int32 Handle )
333 css::ucb::CommandInfo aInfo;
334 return queryCommand( Handle, aInfo );
338 // Non-Interface methods.
341 void CommandProcessorInfo::reset()
343 osl::MutexGuard aGuard( m_aMutex );
344 m_pCommands.reset();
348 bool CommandProcessorInfo::queryCommand(
349 const OUString& rName,
350 css::ucb::CommandInfo& rCommand )
352 osl::MutexGuard aGuard( m_aMutex );
354 getCommands();
356 const css::ucb::CommandInfo* pCommands
357 = m_pCommands->getConstArray();
358 sal_Int32 nCount = m_pCommands->getLength();
359 for ( sal_Int32 n = 0; n < nCount; ++n )
361 const css::ucb::CommandInfo& rCurrCommand = pCommands[ n ];
362 if ( rCurrCommand.Name == rName )
364 rCommand = rCurrCommand;
365 return true;
369 return false;
373 bool CommandProcessorInfo::queryCommand(
374 sal_Int32 nHandle,
375 css::ucb::CommandInfo& rCommand )
377 osl::MutexGuard aGuard( m_aMutex );
379 getCommands();
381 const css::ucb::CommandInfo* pCommands = m_pCommands->getConstArray();
382 sal_Int32 nCount = m_pCommands->getLength();
383 for ( sal_Int32 n = 0; n < nCount; ++n )
385 const css::ucb::CommandInfo& rCurrCommand = pCommands[ n ];
386 if ( rCurrCommand.Handle == nHandle )
388 rCommand = rCurrCommand;
389 return true;
393 return false;
396 } // namespace ucbhelper
398 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */