LibreOffice Module forms (master) 1
unohelper.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 "unohelper.hxx"
21
22#include <osl/diagnose.h>
23
24#include <com/sun/star/uno/Reference.hxx>
25#include <com/sun/star/uno/Sequence.hxx>
26#include <com/sun/star/uno/Exception.hpp>
27#include <com/sun/star/beans/Property.hpp>
28#include <com/sun/star/beans/XPropertySet.hpp>
29#include <com/sun/star/beans/XPropertySetInfo.hpp>
30#include <com/sun/star/beans/PropertyAttribute.hpp>
31
34using com::sun::star::uno::Exception;
35using com::sun::star::beans::Property;
37using com::sun::star::beans::XPropertySetInfo;
38using com::sun::star::beans::PropertyAttribute::READONLY;
39
41{
42 OSL_ENSURE(xFrom.is(), "no source");
43 OSL_ENSURE(xTo.is(), "no target");
44
45 // get property names & infos, and iterate over target properties
46 Sequence<Property> aProperties = xTo->getPropertySetInfo()->getProperties();
47 sal_Int32 nProperties = aProperties.getLength();
48 const Property* pProperties = aProperties.getConstArray();
49 Reference<XPropertySetInfo> xFromInfo = xFrom->getPropertySetInfo();
50 for (sal_Int32 n = 0; n < nProperties; n++)
51 {
52 const OUString& rName = pProperties[n].Name;
53
54 // if both set have the property, copy the value
55 // (catch and ignore exceptions, if any)
56 if (xFromInfo->hasPropertyByName(rName))
57 {
58 try
59 {
60 Property aProperty = xFromInfo->getPropertyByName(rName);
61 if ((aProperty.Attributes & READONLY) == 0)
62 xTo->setPropertyValue(rName, xFrom->getPropertyValue(rName));
63 }
64 catch (const Exception&)
65 {
66 // ignore any errors; we'll copy as good as we can
67 }
68 }
69 // else: no property? then ignore.
70 }
71}
72
73/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
PropertiesInfo aProperties
sal_Int64 n
class SAL_NO_VTABLE XPropertySet
void copy(const css::uno::Reference< css::beans::XPropertySet > &, css::uno::Reference< css::beans::XPropertySet > const &)
copy the properties from one PropertySet into the next
sal_Int32 nProperties