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 #include "precompiled_chart2.hxx"
25
26 #include "WrappedAutomaticPositionProperties.hxx"
27 #include "FastPropertyIdRanges.hxx"
28 #include "macros.hxx"
29 #include <com/sun/star/beans/PropertyAttribute.hpp>
30 #include <com/sun/star/chart2/RelativePosition.hpp>
31
32 using namespace ::com::sun::star;
33 using ::com::sun::star::uno::Any;
34 using ::com::sun::star::uno::Reference;
35 using ::com::sun::star::uno::Sequence;
36 using ::com::sun::star::beans::Property;
37 using ::rtl::OUString;
38
39 //.............................................................................
40 namespace chart
41 {
42 namespace wrapper
43 {
44
45 class WrappedAutomaticPositionProperty : public WrappedProperty
46 {
47 public:
48 WrappedAutomaticPositionProperty();
49 virtual ~WrappedAutomaticPositionProperty();
50
51 virtual void setPropertyValue( const Any& rOuterValue, const Reference< beans::XPropertySet >& xInnerPropertySet ) const
52 throw (beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException);
53 virtual Any getPropertyValue( const Reference< beans::XPropertySet >& xInnerPropertySet ) const
54 throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException);
55 virtual Any getPropertyDefault( const Reference< beans::XPropertyState >& xInnerPropertyState ) const
56 throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException);
57 };
58
WrappedAutomaticPositionProperty()59 WrappedAutomaticPositionProperty::WrappedAutomaticPositionProperty()
60 : ::chart::WrappedProperty( C2U( "AutomaticPosition" ), rtl::OUString() )
61 {
62 }
~WrappedAutomaticPositionProperty()63 WrappedAutomaticPositionProperty::~WrappedAutomaticPositionProperty()
64 {
65 }
66
setPropertyValue(const Any & rOuterValue,const Reference<beans::XPropertySet> & xInnerPropertySet) const67 void WrappedAutomaticPositionProperty::setPropertyValue( const Any& rOuterValue, const Reference< beans::XPropertySet >& xInnerPropertySet ) const
68 throw (beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException)
69 {
70 if( xInnerPropertySet.is() )
71 {
72 bool bNewValue = true;
73 if( ! (rOuterValue >>= bNewValue) )
74 throw lang::IllegalArgumentException( C2U("Property AutomaticPosition requires value of type boolean"), 0, 0 );
75
76 try
77 {
78 if( bNewValue )
79 {
80 Any aRelativePosition( xInnerPropertySet->getPropertyValue( C2U( "RelativePosition" ) ) );
81 if( aRelativePosition.hasValue() )
82 xInnerPropertySet->setPropertyValue( C2U( "RelativePosition" ), Any() );
83 }
84 }
85 catch( uno::Exception & ex )
86 {
87 ASSERT_EXCEPTION( ex );
88 }
89 }
90 }
91
getPropertyValue(const Reference<beans::XPropertySet> & xInnerPropertySet) const92 Any WrappedAutomaticPositionProperty::getPropertyValue( const Reference< beans::XPropertySet >& xInnerPropertySet ) const
93 throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
94 {
95 Any aRet( getPropertyDefault( Reference< beans::XPropertyState >( xInnerPropertySet, uno::UNO_QUERY ) ) );
96 if( xInnerPropertySet.is() )
97 {
98 Any aRelativePosition( xInnerPropertySet->getPropertyValue( C2U( "RelativePosition" ) ) );
99 if( !aRelativePosition.hasValue() )
100 aRet <<= true;
101 }
102 return aRet;
103 }
104
getPropertyDefault(const Reference<beans::XPropertyState> &) const105 Any WrappedAutomaticPositionProperty::getPropertyDefault( const Reference< beans::XPropertyState >& /*xInnerPropertyState*/ ) const
106 throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
107 {
108 Any aRet;
109 aRet <<= false;
110 return aRet;
111 }
112
113 namespace
114 {
115 enum
116 {
117 PROP_CHART_AUTOMATIC_POSITION = FAST_PROPERTY_ID_START_CHART_AUTOPOSITION_PROP
118 };
119
lcl_addWrappedProperties(std::vector<WrappedProperty * > & rList)120 void lcl_addWrappedProperties( std::vector< WrappedProperty* >& rList )
121 {
122 rList.push_back( new WrappedAutomaticPositionProperty() );
123 }
124
125 }//anonymous namespace
126
127 //-----------------------------------------------------------------------------
128 //-----------------------------------------------------------------------------
129 //-----------------------------------------------------------------------------
addProperties(::std::vector<Property> & rOutProperties)130 void WrappedAutomaticPositionProperties::addProperties( ::std::vector< Property > & rOutProperties )
131 {
132 rOutProperties.push_back(
133 Property( C2U( "AutomaticPosition" ),
134 PROP_CHART_AUTOMATIC_POSITION,
135 ::getBooleanCppuType(),
136 beans::PropertyAttribute::BOUND
137 | beans::PropertyAttribute::MAYBEDEFAULT ));
138 }
139
140 //-----------------------------------------------------------------------------
141 //-----------------------------------------------------------------------------
142
addWrappedProperties(std::vector<WrappedProperty * > & rList)143 void WrappedAutomaticPositionProperties::addWrappedProperties( std::vector< WrappedProperty* >& rList )
144 {
145 lcl_addWrappedProperties( rList );
146 }
147
148 } //namespace wrapper
149 } //namespace chart
150 //.............................................................................
151