Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / chart2 / source / tools / WrappedProperty.cxx
blobee28aba86e68e42884ee0e3b0c56967c479aaa14
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 #include <WrappedProperty.hxx>
21 #include <com/sun/star/beans/XPropertySet.hpp>
22 #include <com/sun/star/beans/XPropertyState.hpp>
23 #include <tools/diagnose_ex.h>
25 using namespace ::com::sun::star;
26 using ::com::sun::star::uno::Any;
27 using ::com::sun::star::uno::Reference;
29 namespace chart
32 WrappedProperty::WrappedProperty( const OUString& rOuterName, const OUString& rInnerName)
33 : m_aOuterName( rOuterName )
34 , m_aInnerName( rInnerName )
37 WrappedProperty::~WrappedProperty()
41 OUString WrappedProperty::getInnerName() const
43 return m_aInnerName;
46 Any WrappedProperty::convertInnerToOuterValue( const Any& rInnerValue ) const
48 return rInnerValue;
50 Any WrappedProperty::convertOuterToInnerValue( const Any& rOuterValue ) const
52 return rOuterValue;
55 void WrappedProperty::setPropertyValue( const Any& rOuterValue, const Reference< beans::XPropertySet >& xInnerPropertySet ) const
57 if(xInnerPropertySet.is())
58 xInnerPropertySet->setPropertyValue( getInnerName(), convertOuterToInnerValue( rOuterValue ) );
61 Any WrappedProperty::getPropertyValue( const Reference< beans::XPropertySet >& xInnerPropertySet ) const
63 Any aRet;
64 if( xInnerPropertySet.is() )
66 aRet = xInnerPropertySet->getPropertyValue( getInnerName() );
67 aRet = convertInnerToOuterValue( aRet );
69 return aRet;
72 void WrappedProperty::setPropertyToDefault( const Reference< beans::XPropertyState >& xInnerPropertyState ) const
74 if( xInnerPropertyState.is() && !getInnerName().isEmpty() )
75 xInnerPropertyState->setPropertyToDefault(getInnerName());
76 else
78 Reference< beans::XPropertySet > xInnerProp( xInnerPropertyState, uno::UNO_QUERY );
79 setPropertyValue( getPropertyDefault( xInnerPropertyState ), xInnerProp );
83 Any WrappedProperty::getPropertyDefault( const Reference< beans::XPropertyState >& xInnerPropertyState ) const
85 Any aRet;
86 if( xInnerPropertyState.is() )
88 aRet = xInnerPropertyState->getPropertyDefault( getInnerName() );
89 aRet = convertInnerToOuterValue( aRet );
91 return aRet;
94 beans::PropertyState WrappedProperty::getPropertyState( const Reference< beans::XPropertyState >& xInnerPropertyState ) const
96 beans::PropertyState aState = beans::PropertyState_DIRECT_VALUE;
97 OUString aInnerName( getInnerName() );
98 if( xInnerPropertyState.is() && !aInnerName.isEmpty() )
99 aState = xInnerPropertyState->getPropertyState( aInnerName );
100 else
104 Reference< beans::XPropertySet > xInnerProp( xInnerPropertyState, uno::UNO_QUERY );
105 uno::Any aValue = getPropertyValue( xInnerProp );
106 if( !aValue.hasValue() )
107 aState = beans::PropertyState_DEFAULT_VALUE;
108 else
110 uno::Any aDefault = getPropertyDefault( xInnerPropertyState );
111 if( aValue == aDefault )
112 aState = beans::PropertyState_DEFAULT_VALUE;
115 catch( const beans::UnknownPropertyException& )
117 DBG_UNHANDLED_EXCEPTION("chart2");
120 return aState;
123 } //namespace chart
125 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */