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 .
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
;
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
46 Any
WrappedProperty::convertInnerToOuterValue( const Any
& rInnerValue
) const
50 Any
WrappedProperty::convertOuterToInnerValue( const Any
& rOuterValue
) const
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
64 if( xInnerPropertySet
.is() )
66 aRet
= xInnerPropertySet
->getPropertyValue( getInnerName() );
67 aRet
= convertInnerToOuterValue( aRet
);
72 void WrappedProperty::setPropertyToDefault( const Reference
< beans::XPropertyState
>& xInnerPropertyState
) const
74 if( xInnerPropertyState
.is() && !getInnerName().isEmpty() )
75 xInnerPropertyState
->setPropertyToDefault(getInnerName());
78 Reference
< beans::XPropertySet
> xInnerProp( xInnerPropertyState
, uno::UNO_QUERY
);
79 setPropertyValue( getPropertyDefault( xInnerPropertyState
), xInnerProp
);
83 Any
WrappedProperty::getPropertyDefault( const Reference
< beans::XPropertyState
>& xInnerPropertyState
) const
86 if( xInnerPropertyState
.is() )
88 aRet
= xInnerPropertyState
->getPropertyDefault( getInnerName() );
89 aRet
= convertInnerToOuterValue( 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
);
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
;
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");
125 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */