Line data Source code
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 :
21 : #include "WrappedProperty.hxx"
22 : #include "macros.hxx"
23 : #include <com/sun/star/drawing/LineStyle.hpp>
24 :
25 : using namespace ::com::sun::star;
26 : using ::com::sun::star::uno::Any;
27 : using ::com::sun::star::uno::Reference;
28 :
29 :
30 : //.............................................................................
31 : namespace chart
32 : {
33 : //.............................................................................
34 :
35 13864 : WrappedProperty::WrappedProperty( const OUString& rOuterName, const OUString& rInnerName)
36 : : m_aOuterName( rOuterName )
37 13864 : , m_aInnerName( rInnerName )
38 : {
39 13864 : }
40 15910 : WrappedProperty::~WrappedProperty()
41 : {
42 15910 : }
43 :
44 13863 : const OUString& WrappedProperty::getOuterName() const
45 : {
46 13863 : return m_aOuterName;
47 : }
48 :
49 3531 : OUString WrappedProperty::getInnerName() const
50 : {
51 3531 : return m_aInnerName;
52 : }
53 :
54 672 : Any WrappedProperty::convertInnerToOuterValue( const Any& rInnerValue ) const
55 : {
56 672 : return rInnerValue;
57 : }
58 646 : Any WrappedProperty::convertOuterToInnerValue( const Any& rOuterValue ) const
59 : {
60 646 : return rOuterValue;
61 : }
62 :
63 653 : void WrappedProperty::setPropertyValue( const Any& rOuterValue, const Reference< beans::XPropertySet >& xInnerPropertySet ) const
64 : throw (beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException)
65 : {
66 653 : if(xInnerPropertySet.is())
67 653 : xInnerPropertySet->setPropertyValue( this->getInnerName(), this->convertOuterToInnerValue( rOuterValue ) );
68 653 : }
69 :
70 514 : Any WrappedProperty::getPropertyValue( const Reference< beans::XPropertySet >& xInnerPropertySet ) const
71 : throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
72 : {
73 514 : Any aRet;
74 514 : if( xInnerPropertySet.is() )
75 : {
76 514 : aRet = xInnerPropertySet->getPropertyValue( this->getInnerName() );
77 514 : aRet = this->convertInnerToOuterValue( aRet );
78 : }
79 514 : return aRet;
80 : }
81 :
82 0 : void WrappedProperty::setPropertyToDefault( const Reference< beans::XPropertyState >& xInnerPropertyState ) const
83 : throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException)
84 : {
85 0 : if( xInnerPropertyState.is() && !this->getInnerName().isEmpty() )
86 0 : xInnerPropertyState->setPropertyToDefault(this->getInnerName());
87 : else
88 : {
89 0 : Reference< beans::XPropertySet > xInnerProp( xInnerPropertyState, uno::UNO_QUERY );
90 0 : setPropertyValue( getPropertyDefault( xInnerPropertyState ), xInnerProp );
91 : }
92 0 : }
93 :
94 140 : Any WrappedProperty::getPropertyDefault( const Reference< beans::XPropertyState >& xInnerPropertyState ) const
95 : throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
96 : {
97 140 : Any aRet;
98 140 : if( xInnerPropertyState.is() )
99 : {
100 140 : aRet = xInnerPropertyState->getPropertyDefault( this->getInnerName() );
101 140 : aRet = this->convertInnerToOuterValue( aRet );
102 : }
103 140 : return aRet;
104 : }
105 :
106 2500 : beans::PropertyState WrappedProperty::getPropertyState( const Reference< beans::XPropertyState >& xInnerPropertyState ) const
107 : throw (beans::UnknownPropertyException, uno::RuntimeException)
108 : {
109 2500 : beans::PropertyState aState = beans::PropertyState_DIRECT_VALUE;
110 2500 : OUString aInnerName( this->getInnerName() );
111 2500 : if( xInnerPropertyState.is() && !aInnerName.isEmpty() )
112 1510 : aState = xInnerPropertyState->getPropertyState( aInnerName );
113 : else
114 : {
115 : try
116 : {
117 990 : Reference< beans::XPropertySet > xInnerProp( xInnerPropertyState, uno::UNO_QUERY );
118 1980 : uno::Any aValue = this->getPropertyValue( xInnerProp );
119 990 : if( !aValue.hasValue() )
120 0 : aState = beans::PropertyState_DEFAULT_VALUE;
121 : else
122 : {
123 990 : uno::Any aDefault = this->getPropertyDefault( xInnerPropertyState );
124 990 : if( aValue == aDefault )
125 820 : aState = beans::PropertyState_DEFAULT_VALUE;
126 990 : }
127 : }
128 0 : catch( const beans::UnknownPropertyException& ex )
129 : {
130 : ASSERT_EXCEPTION( ex );
131 : }
132 : }
133 2500 : return aState;
134 : }
135 :
136 : //.............................................................................
137 : } //namespace chart
138 : //.............................................................................
139 :
140 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|