1*b3f79822SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*b3f79822SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*b3f79822SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*b3f79822SAndrew Rist * distributed with this work for additional information 6*b3f79822SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*b3f79822SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*b3f79822SAndrew Rist * "License"); you may not use this file except in compliance 9*b3f79822SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*b3f79822SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*b3f79822SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*b3f79822SAndrew Rist * software distributed under the License is distributed on an 15*b3f79822SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*b3f79822SAndrew Rist * KIND, either express or implied. See the License for the 17*b3f79822SAndrew Rist * specific language governing permissions and limitations 18*b3f79822SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*b3f79822SAndrew Rist *************************************************************/ 21*b3f79822SAndrew Rist 22*b3f79822SAndrew Rist 23cdf0e10cSrcweir #include "vbaformatcondition.hxx" 24cdf0e10cSrcweir #include "vbaformatconditions.hxx" 25cdf0e10cSrcweir #include <ooo/vba/excel/XlFormatConditionType.hpp> 26cdf0e10cSrcweir 27cdf0e10cSrcweir using namespace ::ooo::vba; 28cdf0e10cSrcweir using namespace ::com::sun::star; 29cdf0e10cSrcweir 30cdf0e10cSrcweir ScVbaFormatConditions* 31cdf0e10cSrcweir lcl_getScVbaFormatConditionsPtr( const uno::Reference< excel::XFormatConditions >& xFormatConditions ) throw ( script::BasicErrorException ) 32cdf0e10cSrcweir { 33cdf0e10cSrcweir ScVbaFormatConditions* pFormatConditions = static_cast< ScVbaFormatConditions* >( xFormatConditions.get() ); 34cdf0e10cSrcweir if ( !pFormatConditions ) 35cdf0e10cSrcweir DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString() ); 36cdf0e10cSrcweir return pFormatConditions; 37cdf0e10cSrcweir } 38cdf0e10cSrcweir ScVbaFormatCondition::ScVbaFormatCondition( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext > & xContext, const uno::Reference< sheet::XSheetConditionalEntry >& _xSheetConditionalEntry, const uno::Reference< excel::XStyle >& _xStyle, const uno::Reference< excel::XFormatConditions >& _xFormatConditions, const uno::Reference< css::beans::XPropertySet >& _xPropertySet ) throw ( css::uno::RuntimeException ) : ScVbaFormatCondition_BASE( xParent, xContext, uno::Reference< sheet::XSheetCondition >( _xSheetConditionalEntry, css::uno::UNO_QUERY_THROW ) ), moFormatConditions( _xFormatConditions ), mxStyle( _xStyle ), mxParentRangePropertySet( _xPropertySet ) 39cdf0e10cSrcweir { 40cdf0e10cSrcweir mxSheetConditionalEntries = lcl_getScVbaFormatConditionsPtr( moFormatConditions )->getSheetConditionalEntries(); 41cdf0e10cSrcweir 42cdf0e10cSrcweir mxSheetConditionalEntry = _xSheetConditionalEntry; 43cdf0e10cSrcweir msStyleName = mxStyle->getName(); 44cdf0e10cSrcweir } 45cdf0e10cSrcweir 46cdf0e10cSrcweir 47cdf0e10cSrcweir void SAL_CALL 48cdf0e10cSrcweir ScVbaFormatCondition::Delete( ) throw (script::BasicErrorException, uno::RuntimeException) 49cdf0e10cSrcweir { 50cdf0e10cSrcweir ScVbaFormatConditions* pFormatConditions = lcl_getScVbaFormatConditionsPtr( moFormatConditions ); 51cdf0e10cSrcweir pFormatConditions->removeFormatCondition(msStyleName, sal_True); 52cdf0e10cSrcweir notifyRange(); 53cdf0e10cSrcweir } 54cdf0e10cSrcweir 55cdf0e10cSrcweir void SAL_CALL 56cdf0e10cSrcweir ScVbaFormatCondition::Modify( ::sal_Int32 _nType, const uno::Any& _aOperator, const uno::Any& _aFormula1, const uno::Any& _aFormula2 ) throw (script::BasicErrorException, uno::RuntimeException) 57cdf0e10cSrcweir { 58cdf0e10cSrcweir try 59cdf0e10cSrcweir { 60cdf0e10cSrcweir ScVbaFormatConditions* pFormatConditions = lcl_getScVbaFormatConditionsPtr( moFormatConditions ); 61cdf0e10cSrcweir pFormatConditions->removeFormatCondition(msStyleName, sal_False); 62cdf0e10cSrcweir pFormatConditions->Add(_nType, _aOperator, _aFormula1, _aFormula2, mxStyle); 63cdf0e10cSrcweir } 64cdf0e10cSrcweir catch (uno::Exception& ) 65cdf0e10cSrcweir { 66cdf0e10cSrcweir DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString() ); 67cdf0e10cSrcweir } 68cdf0e10cSrcweir } 69cdf0e10cSrcweir 70cdf0e10cSrcweir uno::Reference< excel::XInterior > SAL_CALL 71cdf0e10cSrcweir ScVbaFormatCondition::Interior( ) throw (script::BasicErrorException, uno::RuntimeException) 72cdf0e10cSrcweir { 73cdf0e10cSrcweir return mxStyle->Interior(); 74cdf0e10cSrcweir } 75cdf0e10cSrcweir 76cdf0e10cSrcweir uno::Reference< excel::XFont > SAL_CALL 77cdf0e10cSrcweir ScVbaFormatCondition::Font( ) throw (script::BasicErrorException, uno::RuntimeException) 78cdf0e10cSrcweir { 79cdf0e10cSrcweir return mxStyle->Font(); 80cdf0e10cSrcweir } 81cdf0e10cSrcweir uno::Any SAL_CALL 82cdf0e10cSrcweir ScVbaFormatCondition::Borders( const uno::Any& Index ) throw (script::BasicErrorException, uno::RuntimeException) 83cdf0e10cSrcweir { return mxStyle->Borders( Index ); 84cdf0e10cSrcweir } 85cdf0e10cSrcweir 86cdf0e10cSrcweir sheet::ConditionOperator 87cdf0e10cSrcweir ScVbaFormatCondition::retrieveAPIType(sal_Int32 _nVBAType, const uno::Reference< sheet::XSheetCondition >& _xSheetCondition ) throw ( script::BasicErrorException ) 88cdf0e10cSrcweir { 89cdf0e10cSrcweir sheet::ConditionOperator aAPIType = sheet::ConditionOperator_NONE; 90cdf0e10cSrcweir switch (_nVBAType) 91cdf0e10cSrcweir { 92cdf0e10cSrcweir case excel::XlFormatConditionType::xlExpression: 93cdf0e10cSrcweir aAPIType = sheet::ConditionOperator_FORMULA; 94cdf0e10cSrcweir break; 95cdf0e10cSrcweir case excel::XlFormatConditionType::xlCellValue: 96cdf0e10cSrcweir if ( _xSheetCondition.is() && (_xSheetCondition->getOperator() == sheet::ConditionOperator_FORMULA ) ) 97cdf0e10cSrcweir aAPIType = sheet::ConditionOperator_NONE; 98cdf0e10cSrcweir break; 99cdf0e10cSrcweir default: 100cdf0e10cSrcweir DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString() ); 101cdf0e10cSrcweir } 102cdf0e10cSrcweir return aAPIType; 103cdf0e10cSrcweir } 104cdf0e10cSrcweir 105cdf0e10cSrcweir void 106cdf0e10cSrcweir ScVbaFormatCondition::setFormula1( const uno::Any& _aFormula1) throw ( script::BasicErrorException ) 107cdf0e10cSrcweir { 108cdf0e10cSrcweir // getA1Formula *SHOULD* detect whether the formula is r1c1 or A1 syntax 109cdf0e10cSrcweir // and if R1C1 convert to A1 110cdf0e10cSrcweir ScVbaFormatCondition_BASE::setFormula1( uno::makeAny( lcl_getScVbaFormatConditionsPtr( moFormatConditions )->getA1Formula(_aFormula1) ) ); 111cdf0e10cSrcweir } 112cdf0e10cSrcweir 113cdf0e10cSrcweir void 114cdf0e10cSrcweir ScVbaFormatCondition::setFormula2( const uno::Any& _aFormula2) throw ( script::BasicErrorException ) 115cdf0e10cSrcweir { 116cdf0e10cSrcweir ScVbaFormatCondition_BASE::setFormula1( uno::makeAny( lcl_getScVbaFormatConditionsPtr( moFormatConditions )->getA1Formula(_aFormula2)) ); 117cdf0e10cSrcweir } 118cdf0e10cSrcweir 119cdf0e10cSrcweir ::sal_Int32 SAL_CALL 120cdf0e10cSrcweir ScVbaFormatCondition::Type( ) throw ( script::BasicErrorException, uno::RuntimeException ) 121cdf0e10cSrcweir { 122cdf0e10cSrcweir sal_Int32 nReturnType = 0; 123cdf0e10cSrcweir if ( mxSheetCondition->getOperator() == sheet::ConditionOperator_FORMULA) 124cdf0e10cSrcweir nReturnType = excel::XlFormatConditionType::xlExpression; 125cdf0e10cSrcweir else 126cdf0e10cSrcweir nReturnType = excel::XlFormatConditionType::xlCellValue; 127cdf0e10cSrcweir return nReturnType; 128cdf0e10cSrcweir } 129cdf0e10cSrcweir 130cdf0e10cSrcweir 131cdf0e10cSrcweir ::sal_Int32 132cdf0e10cSrcweir ScVbaFormatCondition::Operator( sal_Bool bVal ) throw (script::BasicErrorException ) 133cdf0e10cSrcweir { 134cdf0e10cSrcweir return ScVbaFormatCondition_BASE::Operator( bVal ); 135cdf0e10cSrcweir } 136cdf0e10cSrcweir ::sal_Int32 SAL_CALL 137cdf0e10cSrcweir ScVbaFormatCondition::Operator( ) throw (script::BasicErrorException, uno::RuntimeException) 138cdf0e10cSrcweir { 139cdf0e10cSrcweir return ScVbaFormatCondition_BASE::Operator( sal_True ); 140cdf0e10cSrcweir } 141cdf0e10cSrcweir 142cdf0e10cSrcweir void 143cdf0e10cSrcweir ScVbaFormatCondition::notifyRange() throw ( script::BasicErrorException ) 144cdf0e10cSrcweir { 145cdf0e10cSrcweir try 146cdf0e10cSrcweir { 147cdf0e10cSrcweir mxParentRangePropertySet->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ConditionalFormat") ), uno::makeAny( mxSheetConditionalEntries) ); 148cdf0e10cSrcweir } 149cdf0e10cSrcweir catch (uno::Exception& ) 150cdf0e10cSrcweir { 151cdf0e10cSrcweir DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString() ); 152cdf0e10cSrcweir } 153cdf0e10cSrcweir } 154cdf0e10cSrcweir 155cdf0e10cSrcweir rtl::OUString& 156cdf0e10cSrcweir ScVbaFormatCondition::getServiceImplName() 157cdf0e10cSrcweir { 158cdf0e10cSrcweir static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaFormatCondition") ); 159cdf0e10cSrcweir return sImplName; 160cdf0e10cSrcweir } 161cdf0e10cSrcweir 162cdf0e10cSrcweir uno::Sequence< rtl::OUString > 163cdf0e10cSrcweir ScVbaFormatCondition::getServiceNames() 164cdf0e10cSrcweir { 165cdf0e10cSrcweir static uno::Sequence< rtl::OUString > aServiceNames; 166cdf0e10cSrcweir if ( aServiceNames.getLength() == 0 ) 167cdf0e10cSrcweir { 168cdf0e10cSrcweir aServiceNames.realloc( 1 ); 169cdf0e10cSrcweir aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.FormatCondition" ) ); 170cdf0e10cSrcweir } 171cdf0e10cSrcweir return aServiceNames; 172cdf0e10cSrcweir } 173