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