LibreOffice Module chart2 (master) 1
WrappedProperty.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 <WrappedProperty.hxx>
21#include <com/sun/star/beans/XPropertySet.hpp>
22#include <com/sun/star/beans/XPropertyState.hpp>
23#include <utility>
25
26using namespace ::com::sun::star;
27using ::com::sun::star::uno::Any;
28using ::com::sun::star::uno::Reference;
29
30namespace chart
31{
32
33WrappedProperty::WrappedProperty( OUString aOuterName, OUString aInnerName)
34 : m_aOuterName(std::move( aOuterName ))
35 , m_aInnerName(std::move( aInnerName ))
36{
37}
39{
40}
41
43{
44 return m_aInnerName;
45}
46
47Any WrappedProperty::convertInnerToOuterValue( const Any& rInnerValue ) const
48{
49 return rInnerValue;
50}
51Any WrappedProperty::convertOuterToInnerValue( const Any& rOuterValue ) const
52{
53 return rOuterValue;
54}
55
56void WrappedProperty::setPropertyValue( const Any& rOuterValue, const Reference< beans::XPropertySet >& xInnerPropertySet ) const
57{
58 if(xInnerPropertySet.is())
59 xInnerPropertySet->setPropertyValue( getInnerName(), convertOuterToInnerValue( rOuterValue ) );
60}
61
63{
64 Any aRet;
65 if( xInnerPropertySet.is() )
66 {
67 aRet = xInnerPropertySet->getPropertyValue( getInnerName() );
68 aRet = convertInnerToOuterValue( aRet );
69 }
70 return aRet;
71}
72
74{
75 if( xInnerPropertyState.is() && !getInnerName().isEmpty() )
76 xInnerPropertyState->setPropertyToDefault(getInnerName());
77 else
78 {
79 Reference< beans::XPropertySet > xInnerProp( xInnerPropertyState, uno::UNO_QUERY );
80 setPropertyValue( getPropertyDefault( xInnerPropertyState ), xInnerProp );
81 }
82}
83
85{
86 Any aRet;
87 if( xInnerPropertyState.is() )
88 {
89 aRet = xInnerPropertyState->getPropertyDefault( getInnerName() );
90 aRet = convertInnerToOuterValue( aRet );
91 }
92 return aRet;
93}
94
95beans::PropertyState WrappedProperty::getPropertyState( const Reference< beans::XPropertyState >& xInnerPropertyState ) const
96{
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
102 {
103 try
104 {
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
110 {
111 uno::Any aDefault = getPropertyDefault( xInnerPropertyState );
112 if( aValue == aDefault )
113 aState = beans::PropertyState_DEFAULT_VALUE;
114 }
115 }
116 catch( const beans::UnknownPropertyException& )
117 {
118 DBG_UNHANDLED_EXCEPTION("chart2");
119 }
120 }
121 return aState;
122}
123
124} //namespace chart
125
126/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual css::uno::Any convertOuterToInnerValue(const css::uno::Any &rOuterValue) const
virtual css::beans::PropertyState getPropertyState(const css::uno::Reference< css::beans::XPropertyState > &xInnerPropertyState) const
virtual css::uno::Any getPropertyDefault(const css::uno::Reference< css::beans::XPropertyState > &xInnerPropertyState) const
virtual css::uno::Any getPropertyValue(const css::uno::Reference< css::beans::XPropertySet > &xInnerPropertySet) const
virtual void setPropertyToDefault(const css::uno::Reference< css::beans::XPropertyState > &xInnerPropertyState) const
virtual css::uno::Any convertInnerToOuterValue(const css::uno::Any &rInnerValue) const
virtual void setPropertyValue(const css::uno::Any &rOuterValue, const css::uno::Reference< css::beans::XPropertySet > &xInnerPropertySet) const
WrappedProperty(OUString aOuterName, OUString aInnerName)
The property visible to the outer PropertySet in the PropertySetWrapper may have a different name,...
virtual OUString getInnerName() const
#define DBG_UNHANDLED_EXCEPTION(...)
bool hasValue()