1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
21 #include "unohelper.hxx"
23 #include <osl/diagnose.h>
25 #include <com/sun/star/uno/Reference.hxx>
26 #include <com/sun/star/uno/Sequence.hxx>
27 #include <com/sun/star/uno/XInterface.hpp>
28 #include <com/sun/star/uno/Exception.hpp>
29 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
30 #include <com/sun/star/beans/Property.hpp>
31 #include <com/sun/star/beans/XPropertySet.hpp>
32 #include <com/sun/star/beans/XPropertySetInfo.hpp>
33 #include <com/sun/star/beans/PropertyAttribute.hpp>
34 #include <comphelper/processfactory.hxx>
37 using com::sun::star::uno::Reference
;
38 using com::sun::star::uno::Sequence
;
39 using com::sun::star::uno::Exception
;
40 using com::sun::star::uno::XInterface
;
41 using com::sun::star::lang::XMultiServiceFactory
;
42 using com::sun::star::beans::Property
;
43 using com::sun::star::beans::XPropertySet
;
44 using com::sun::star::beans::XPropertySetInfo
;
45 using com::sun::star::beans::PropertyAttribute::READONLY
;
48 void xforms::copy( const Reference
<XPropertySet
>& xFrom
,
49 Reference
<XPropertySet
>& xTo
)
51 OSL_ENSURE( xFrom
.is(), "no source" );
52 OSL_ENSURE( xTo
.is(), "no target" );
54 // get property names & infos, and iterate over target properties
55 Sequence
<Property
> aProperties
=
56 xTo
->getPropertySetInfo()->getProperties();
57 sal_Int32 nProperties
= aProperties
.getLength();
58 const Property
* pProperties
= aProperties
.getConstArray();
59 Reference
<XPropertySetInfo
> xFromInfo
= xFrom
->getPropertySetInfo();
60 for( sal_Int32 n
= 0; n
< nProperties
; n
++ )
62 const OUString
& rName
= pProperties
[n
].Name
;
64 // if both set have the property, copy the value
65 // (catch and ignore exceptions, if any)
66 if( xFromInfo
->hasPropertyByName( rName
) )
70 Property aProperty
= xFromInfo
->getPropertyByName( rName
);
71 if ( ( aProperty
.Attributes
& READONLY
) == 0 )
72 xTo
->setPropertyValue(rName
, xFrom
->getPropertyValue( rName
));
74 catch( const Exception
& )
76 // ignore any errors; we'll copy as good as we can
79 // else: no property? then ignore.
83 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */