Avoid potential negative array index access to cached text.
[LibreOffice.git] / chart2 / source / tools / WrappedProperty.cxx
blob8b0891c770f540f71736fbb331c5efe35ece8912
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 <utility>
24 #include <comphelper/diagnose_ex.hxx>
26 using namespace ::com::sun::star;
27 using ::com::sun::star::uno::Any;
28 using ::com::sun::star::uno::Reference;
30 namespace chart
33 WrappedProperty::WrappedProperty( OUString aOuterName, OUString aInnerName)
34 : m_aOuterName(std::move( aOuterName ))
35 , m_aInnerName(std::move( aInnerName ))
38 WrappedProperty::~WrappedProperty()
42 OUString WrappedProperty::getInnerName() const
44 return m_aInnerName;
47 Any WrappedProperty::convertInnerToOuterValue( const Any& rInnerValue ) const
49 return rInnerValue;
51 Any WrappedProperty::convertOuterToInnerValue( const Any& rOuterValue ) const
53 return rOuterValue;
56 void WrappedProperty::setPropertyValue( const Any& rOuterValue, const Reference< beans::XPropertySet >& xInnerPropertySet ) const
58 if(xInnerPropertySet.is())
59 xInnerPropertySet->setPropertyValue( getInnerName(), convertOuterToInnerValue( rOuterValue ) );
62 Any WrappedProperty::getPropertyValue( const Reference< beans::XPropertySet >& xInnerPropertySet ) const
64 Any aRet;
65 if( xInnerPropertySet.is() )
67 aRet = xInnerPropertySet->getPropertyValue( getInnerName() );
68 aRet = convertInnerToOuterValue( aRet );
70 return aRet;
73 void WrappedProperty::setPropertyToDefault( const Reference< beans::XPropertyState >& xInnerPropertyState ) const
75 if( xInnerPropertyState.is() && !getInnerName().isEmpty() )
76 xInnerPropertyState->setPropertyToDefault(getInnerName());
77 else
79 Reference< beans::XPropertySet > xInnerProp( xInnerPropertyState, uno::UNO_QUERY );
80 setPropertyValue( getPropertyDefault( xInnerPropertyState ), xInnerProp );
84 Any WrappedProperty::getPropertyDefault( const Reference< beans::XPropertyState >& xInnerPropertyState ) const
86 Any aRet;
87 if( xInnerPropertyState.is() )
89 aRet = xInnerPropertyState->getPropertyDefault( getInnerName() );
90 aRet = convertInnerToOuterValue( aRet );
92 return aRet;
95 beans::PropertyState WrappedProperty::getPropertyState( const Reference< beans::XPropertyState >& xInnerPropertyState ) const
97 beans::PropertyState aState = beans::PropertyState_DIRECT_VALUE;
98 OUString aInnerName( getInnerName() );
99 if( xInnerPropertyState.is() && !aInnerName.isEmpty() )
100 aState = xInnerPropertyState->getPropertyState( aInnerName );
101 else
105 Reference< beans::XPropertySet > xInnerProp( xInnerPropertyState, uno::UNO_QUERY );
106 uno::Any aValue = getPropertyValue( xInnerProp );
107 if( !aValue.hasValue() )
108 aState = beans::PropertyState_DEFAULT_VALUE;
109 else
111 uno::Any aDefault = getPropertyDefault( xInnerPropertyState );
112 if( aValue == aDefault )
113 aState = beans::PropertyState_DEFAULT_VALUE;
116 catch( const beans::UnknownPropertyException& )
118 DBG_UNHANDLED_EXCEPTION("chart2");
121 return aState;
124 } //namespace chart
126 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */