1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir #include "vbaformatcondition.hxx" 28*cdf0e10cSrcweir #include "vbaformatconditions.hxx" 29*cdf0e10cSrcweir #include <ooo/vba/excel/XlFormatConditionType.hpp> 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir using namespace ::ooo::vba; 32*cdf0e10cSrcweir using namespace ::com::sun::star; 33*cdf0e10cSrcweir 34*cdf0e10cSrcweir ScVbaFormatConditions* 35*cdf0e10cSrcweir lcl_getScVbaFormatConditionsPtr( const uno::Reference< excel::XFormatConditions >& xFormatConditions ) throw ( script::BasicErrorException ) 36*cdf0e10cSrcweir { 37*cdf0e10cSrcweir ScVbaFormatConditions* pFormatConditions = static_cast< ScVbaFormatConditions* >( xFormatConditions.get() ); 38*cdf0e10cSrcweir if ( !pFormatConditions ) 39*cdf0e10cSrcweir DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString() ); 40*cdf0e10cSrcweir return pFormatConditions; 41*cdf0e10cSrcweir } 42*cdf0e10cSrcweir 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 ) 43*cdf0e10cSrcweir { 44*cdf0e10cSrcweir mxSheetConditionalEntries = lcl_getScVbaFormatConditionsPtr( moFormatConditions )->getSheetConditionalEntries(); 45*cdf0e10cSrcweir 46*cdf0e10cSrcweir mxSheetConditionalEntry = _xSheetConditionalEntry; 47*cdf0e10cSrcweir msStyleName = mxStyle->getName(); 48*cdf0e10cSrcweir } 49*cdf0e10cSrcweir 50*cdf0e10cSrcweir 51*cdf0e10cSrcweir void SAL_CALL 52*cdf0e10cSrcweir ScVbaFormatCondition::Delete( ) throw (script::BasicErrorException, uno::RuntimeException) 53*cdf0e10cSrcweir { 54*cdf0e10cSrcweir ScVbaFormatConditions* pFormatConditions = lcl_getScVbaFormatConditionsPtr( moFormatConditions ); 55*cdf0e10cSrcweir pFormatConditions->removeFormatCondition(msStyleName, sal_True); 56*cdf0e10cSrcweir notifyRange(); 57*cdf0e10cSrcweir } 58*cdf0e10cSrcweir 59*cdf0e10cSrcweir void SAL_CALL 60*cdf0e10cSrcweir ScVbaFormatCondition::Modify( ::sal_Int32 _nType, const uno::Any& _aOperator, const uno::Any& _aFormula1, const uno::Any& _aFormula2 ) throw (script::BasicErrorException, uno::RuntimeException) 61*cdf0e10cSrcweir { 62*cdf0e10cSrcweir try 63*cdf0e10cSrcweir { 64*cdf0e10cSrcweir ScVbaFormatConditions* pFormatConditions = lcl_getScVbaFormatConditionsPtr( moFormatConditions ); 65*cdf0e10cSrcweir pFormatConditions->removeFormatCondition(msStyleName, sal_False); 66*cdf0e10cSrcweir pFormatConditions->Add(_nType, _aOperator, _aFormula1, _aFormula2, mxStyle); 67*cdf0e10cSrcweir } 68*cdf0e10cSrcweir catch (uno::Exception& ) 69*cdf0e10cSrcweir { 70*cdf0e10cSrcweir DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString() ); 71*cdf0e10cSrcweir } 72*cdf0e10cSrcweir } 73*cdf0e10cSrcweir 74*cdf0e10cSrcweir uno::Reference< excel::XInterior > SAL_CALL 75*cdf0e10cSrcweir ScVbaFormatCondition::Interior( ) throw (script::BasicErrorException, uno::RuntimeException) 76*cdf0e10cSrcweir { 77*cdf0e10cSrcweir return mxStyle->Interior(); 78*cdf0e10cSrcweir } 79*cdf0e10cSrcweir 80*cdf0e10cSrcweir uno::Reference< excel::XFont > SAL_CALL 81*cdf0e10cSrcweir ScVbaFormatCondition::Font( ) throw (script::BasicErrorException, uno::RuntimeException) 82*cdf0e10cSrcweir { 83*cdf0e10cSrcweir return mxStyle->Font(); 84*cdf0e10cSrcweir } 85*cdf0e10cSrcweir uno::Any SAL_CALL 86*cdf0e10cSrcweir ScVbaFormatCondition::Borders( const uno::Any& Index ) throw (script::BasicErrorException, uno::RuntimeException) 87*cdf0e10cSrcweir { return mxStyle->Borders( Index ); 88*cdf0e10cSrcweir } 89*cdf0e10cSrcweir 90*cdf0e10cSrcweir sheet::ConditionOperator 91*cdf0e10cSrcweir ScVbaFormatCondition::retrieveAPIType(sal_Int32 _nVBAType, const uno::Reference< sheet::XSheetCondition >& _xSheetCondition ) throw ( script::BasicErrorException ) 92*cdf0e10cSrcweir { 93*cdf0e10cSrcweir sheet::ConditionOperator aAPIType = sheet::ConditionOperator_NONE; 94*cdf0e10cSrcweir switch (_nVBAType) 95*cdf0e10cSrcweir { 96*cdf0e10cSrcweir case excel::XlFormatConditionType::xlExpression: 97*cdf0e10cSrcweir aAPIType = sheet::ConditionOperator_FORMULA; 98*cdf0e10cSrcweir break; 99*cdf0e10cSrcweir case excel::XlFormatConditionType::xlCellValue: 100*cdf0e10cSrcweir if ( _xSheetCondition.is() && (_xSheetCondition->getOperator() == sheet::ConditionOperator_FORMULA ) ) 101*cdf0e10cSrcweir aAPIType = sheet::ConditionOperator_NONE; 102*cdf0e10cSrcweir break; 103*cdf0e10cSrcweir default: 104*cdf0e10cSrcweir DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString() ); 105*cdf0e10cSrcweir } 106*cdf0e10cSrcweir return aAPIType; 107*cdf0e10cSrcweir } 108*cdf0e10cSrcweir 109*cdf0e10cSrcweir void 110*cdf0e10cSrcweir ScVbaFormatCondition::setFormula1( const uno::Any& _aFormula1) throw ( script::BasicErrorException ) 111*cdf0e10cSrcweir { 112*cdf0e10cSrcweir // getA1Formula *SHOULD* detect whether the formula is r1c1 or A1 syntax 113*cdf0e10cSrcweir // and if R1C1 convert to A1 114*cdf0e10cSrcweir ScVbaFormatCondition_BASE::setFormula1( uno::makeAny( lcl_getScVbaFormatConditionsPtr( moFormatConditions )->getA1Formula(_aFormula1) ) ); 115*cdf0e10cSrcweir } 116*cdf0e10cSrcweir 117*cdf0e10cSrcweir void 118*cdf0e10cSrcweir ScVbaFormatCondition::setFormula2( const uno::Any& _aFormula2) throw ( script::BasicErrorException ) 119*cdf0e10cSrcweir { 120*cdf0e10cSrcweir ScVbaFormatCondition_BASE::setFormula1( uno::makeAny( lcl_getScVbaFormatConditionsPtr( moFormatConditions )->getA1Formula(_aFormula2)) ); 121*cdf0e10cSrcweir } 122*cdf0e10cSrcweir 123*cdf0e10cSrcweir ::sal_Int32 SAL_CALL 124*cdf0e10cSrcweir ScVbaFormatCondition::Type( ) throw ( script::BasicErrorException, uno::RuntimeException ) 125*cdf0e10cSrcweir { 126*cdf0e10cSrcweir sal_Int32 nReturnType = 0; 127*cdf0e10cSrcweir if ( mxSheetCondition->getOperator() == sheet::ConditionOperator_FORMULA) 128*cdf0e10cSrcweir nReturnType = excel::XlFormatConditionType::xlExpression; 129*cdf0e10cSrcweir else 130*cdf0e10cSrcweir nReturnType = excel::XlFormatConditionType::xlCellValue; 131*cdf0e10cSrcweir return nReturnType; 132*cdf0e10cSrcweir } 133*cdf0e10cSrcweir 134*cdf0e10cSrcweir 135*cdf0e10cSrcweir ::sal_Int32 136*cdf0e10cSrcweir ScVbaFormatCondition::Operator( sal_Bool bVal ) throw (script::BasicErrorException ) 137*cdf0e10cSrcweir { 138*cdf0e10cSrcweir return ScVbaFormatCondition_BASE::Operator( bVal ); 139*cdf0e10cSrcweir } 140*cdf0e10cSrcweir ::sal_Int32 SAL_CALL 141*cdf0e10cSrcweir ScVbaFormatCondition::Operator( ) throw (script::BasicErrorException, uno::RuntimeException) 142*cdf0e10cSrcweir { 143*cdf0e10cSrcweir return ScVbaFormatCondition_BASE::Operator( sal_True ); 144*cdf0e10cSrcweir } 145*cdf0e10cSrcweir 146*cdf0e10cSrcweir void 147*cdf0e10cSrcweir ScVbaFormatCondition::notifyRange() throw ( script::BasicErrorException ) 148*cdf0e10cSrcweir { 149*cdf0e10cSrcweir try 150*cdf0e10cSrcweir { 151*cdf0e10cSrcweir mxParentRangePropertySet->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ConditionalFormat") ), uno::makeAny( mxSheetConditionalEntries) ); 152*cdf0e10cSrcweir } 153*cdf0e10cSrcweir catch (uno::Exception& ) 154*cdf0e10cSrcweir { 155*cdf0e10cSrcweir DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString() ); 156*cdf0e10cSrcweir } 157*cdf0e10cSrcweir } 158*cdf0e10cSrcweir 159*cdf0e10cSrcweir rtl::OUString& 160*cdf0e10cSrcweir ScVbaFormatCondition::getServiceImplName() 161*cdf0e10cSrcweir { 162*cdf0e10cSrcweir static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaFormatCondition") ); 163*cdf0e10cSrcweir return sImplName; 164*cdf0e10cSrcweir } 165*cdf0e10cSrcweir 166*cdf0e10cSrcweir uno::Sequence< rtl::OUString > 167*cdf0e10cSrcweir ScVbaFormatCondition::getServiceNames() 168*cdf0e10cSrcweir { 169*cdf0e10cSrcweir static uno::Sequence< rtl::OUString > aServiceNames; 170*cdf0e10cSrcweir if ( aServiceNames.getLength() == 0 ) 171*cdf0e10cSrcweir { 172*cdf0e10cSrcweir aServiceNames.realloc( 1 ); 173*cdf0e10cSrcweir aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.FormatCondition" ) ); 174*cdf0e10cSrcweir } 175*cdf0e10cSrcweir return aServiceNames; 176*cdf0e10cSrcweir } 177