1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_chart2.hxx"
26 
27 #include "WrappedProperty.hxx"
28 #include "macros.hxx"
29 #include <com/sun/star/drawing/LineStyle.hpp>
30 
31 using namespace ::com::sun::star;
32 using ::com::sun::star::uno::Any;
33 using ::com::sun::star::uno::Reference;
34 using ::rtl::OUString;
35 
36 
37 //.............................................................................
38 namespace chart
39 {
40 //.............................................................................
41 
WrappedProperty(const OUString & rOuterName,const OUString & rInnerName)42 WrappedProperty::WrappedProperty( const OUString& rOuterName, const OUString& rInnerName)
43                          : m_aOuterName( rOuterName )
44                          , m_aInnerName( rInnerName )
45 {
46 }
~WrappedProperty()47 WrappedProperty::~WrappedProperty()
48 {
49 }
50 
getOuterName() const51 const OUString& WrappedProperty::getOuterName() const
52 {
53     return m_aOuterName;
54 }
55 
56 //virtual
getInnerName() const57 ::rtl::OUString WrappedProperty::getInnerName() const
58 {
59     return m_aInnerName;
60 }
61 
convertInnerToOuterValue(const Any & rInnerValue) const62 Any WrappedProperty::convertInnerToOuterValue( const Any& rInnerValue ) const
63 {
64     return rInnerValue;
65 }
convertOuterToInnerValue(const Any & rOuterValue) const66 Any WrappedProperty::convertOuterToInnerValue( const Any& rOuterValue ) const
67 {
68     return rOuterValue;
69 }
70 
setPropertyValue(const Any & rOuterValue,const Reference<beans::XPropertySet> & xInnerPropertySet) const71 void WrappedProperty::setPropertyValue( const Any& rOuterValue, const Reference< beans::XPropertySet >& xInnerPropertySet ) const
72                 throw (beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException)
73 {
74     if(xInnerPropertySet.is())
75         xInnerPropertySet->setPropertyValue( this->getInnerName(), this->convertOuterToInnerValue( rOuterValue ) );
76 }
77 
getPropertyValue(const Reference<beans::XPropertySet> & xInnerPropertySet) const78 Any WrappedProperty::getPropertyValue( const Reference< beans::XPropertySet >& xInnerPropertySet ) const
79                         throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
80 {
81     Any aRet;
82     if( xInnerPropertySet.is() )
83     {
84         aRet = xInnerPropertySet->getPropertyValue( this->getInnerName() );
85         aRet = this->convertInnerToOuterValue( aRet );
86     }
87     return aRet;
88 }
89 
setPropertyToDefault(const Reference<beans::XPropertyState> & xInnerPropertyState) const90 void WrappedProperty::setPropertyToDefault( const Reference< beans::XPropertyState >& xInnerPropertyState ) const
91                         throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException)
92 {
93     if( xInnerPropertyState.is() && !this->getInnerName().isEmpty() )
94         xInnerPropertyState->setPropertyToDefault(this->getInnerName());
95     else
96     {
97         Reference< beans::XPropertySet > xInnerProp( xInnerPropertyState, uno::UNO_QUERY );
98         setPropertyValue( getPropertyDefault( xInnerPropertyState ), xInnerProp );
99     }
100 }
101 
getPropertyDefault(const Reference<beans::XPropertyState> & xInnerPropertyState) const102 Any WrappedProperty::getPropertyDefault( const Reference< beans::XPropertyState >& xInnerPropertyState ) const
103                         throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
104 {
105     Any aRet;
106     if( xInnerPropertyState.is() )
107     {
108         aRet = xInnerPropertyState->getPropertyDefault( this->getInnerName() );
109         aRet = this->convertInnerToOuterValue( aRet );
110     }
111     return aRet;
112 }
113 
getPropertyState(const Reference<beans::XPropertyState> & xInnerPropertyState) const114 beans::PropertyState WrappedProperty::getPropertyState( const Reference< beans::XPropertyState >& xInnerPropertyState ) const
115                         throw (beans::UnknownPropertyException, uno::RuntimeException)
116 {
117     beans::PropertyState aState = beans::PropertyState_DIRECT_VALUE;
118     rtl::OUString aInnerName( this->getInnerName() );
119     if( xInnerPropertyState.is() && !aInnerName.isEmpty() )
120         aState = xInnerPropertyState->getPropertyState( aInnerName );
121     else
122     {
123         try
124         {
125             Reference< beans::XPropertySet > xInnerProp( xInnerPropertyState, uno::UNO_QUERY );
126             uno::Any aValue = this->getPropertyValue( xInnerProp );
127             if( !aValue.hasValue() )
128                 aState = beans::PropertyState_DEFAULT_VALUE;
129             else
130             {
131                 uno::Any aDefault = this->getPropertyDefault( xInnerPropertyState );
132                 if( aValue == aDefault )
133                     aState = beans::PropertyState_DEFAULT_VALUE;
134             }
135         }
136         catch( beans::UnknownPropertyException& ex )
137         {
138             ASSERT_EXCEPTION( ex );
139         }
140     }
141     return aState;
142 }
143 
144 //.............................................................................
145 } //namespace chart
146 //.............................................................................
147