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_chartcontroller.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 virtual Any getPropertyValue( const Reference< beans::XPropertySet >& xInnerPropertySet ) const; 53 virtual Any getPropertyDefault( const Reference< beans::XPropertyState >& xInnerPropertyState ) const; 54 }; 55 56 WrappedAutomaticPositionProperty::WrappedAutomaticPositionProperty() 57 : ::chart::WrappedProperty( C2U( "AutomaticPosition" ), rtl::OUString() ) 58 { 59 } 60 WrappedAutomaticPositionProperty::~WrappedAutomaticPositionProperty() 61 { 62 } 63 64 void WrappedAutomaticPositionProperty::setPropertyValue( const Any& rOuterValue, const Reference< beans::XPropertySet >& xInnerPropertySet ) const 65 { 66 if( xInnerPropertySet.is() ) 67 { 68 bool bNewValue = true; 69 if( ! (rOuterValue >>= bNewValue) ) 70 throw lang::IllegalArgumentException( C2U("Property AutomaticPosition requires value of type boolean"), 0, 0 ); 71 72 try 73 { 74 if( bNewValue ) 75 { 76 Any aRelativePosition( xInnerPropertySet->getPropertyValue( C2U( "RelativePosition" ) ) ); 77 if( aRelativePosition.hasValue() ) 78 xInnerPropertySet->setPropertyValue( C2U( "RelativePosition" ), Any() ); 79 } 80 } 81 catch( uno::Exception & ex ) 82 { 83 ASSERT_EXCEPTION( ex ); 84 } 85 } 86 } 87 88 Any WrappedAutomaticPositionProperty::getPropertyValue( const Reference< beans::XPropertySet >& xInnerPropertySet ) const 89 { 90 Any aRet( getPropertyDefault( Reference< beans::XPropertyState >( xInnerPropertySet, uno::UNO_QUERY ) ) ); 91 if( xInnerPropertySet.is() ) 92 { 93 Any aRelativePosition( xInnerPropertySet->getPropertyValue( C2U( "RelativePosition" ) ) ); 94 if( !aRelativePosition.hasValue() ) 95 aRet <<= true; 96 } 97 return aRet; 98 } 99 100 Any WrappedAutomaticPositionProperty::getPropertyDefault( const Reference< beans::XPropertyState >& /*xInnerPropertyState*/ ) const 101 { 102 Any aRet; 103 aRet <<= false; 104 return aRet; 105 } 106 107 namespace 108 { 109 enum 110 { 111 PROP_CHART_AUTOMATIC_POSITION = FAST_PROPERTY_ID_START_CHART_AUTOPOSITION_PROP 112 }; 113 114 void lcl_addWrappedProperties( std::vector< WrappedProperty* >& rList ) 115 { 116 rList.push_back( new WrappedAutomaticPositionProperty() ); 117 } 118 119 }//anonymous namespace 120 121 //----------------------------------------------------------------------------- 122 //----------------------------------------------------------------------------- 123 //----------------------------------------------------------------------------- 124 void WrappedAutomaticPositionProperties::addProperties( ::std::vector< Property > & rOutProperties ) 125 { 126 rOutProperties.push_back( 127 Property( C2U( "AutomaticPosition" ), 128 PROP_CHART_AUTOMATIC_POSITION, 129 ::getBooleanCppuType(), 130 beans::PropertyAttribute::BOUND 131 | beans::PropertyAttribute::MAYBEDEFAULT )); 132 } 133 134 //----------------------------------------------------------------------------- 135 //----------------------------------------------------------------------------- 136 137 void WrappedAutomaticPositionProperties::addWrappedProperties( std::vector< WrappedProperty* >& rList ) 138 { 139 lcl_addWrappedProperties( rList ); 140 } 141 142 } //namespace wrapper 143 } //namespace chart 144 //............................................................................. 145