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 28*cdf0e10cSrcweir #include "vbacondition.hxx" 29*cdf0e10cSrcweir #include <ooo/vba/excel/XlFormatConditionOperator.hpp> 30*cdf0e10cSrcweir #include <ooo/vba/excel/XFormatCondition.hpp> 31*cdf0e10cSrcweir #include <com/sun/star/table/XCellRange.hpp> 32*cdf0e10cSrcweir #include <com/sun/star/sheet/XCellRangeAddressable.hpp> 33*cdf0e10cSrcweir 34*cdf0e10cSrcweir using namespace ::ooo::vba; 35*cdf0e10cSrcweir using namespace ::com::sun::star; 36*cdf0e10cSrcweir 37*cdf0e10cSrcweir const sal_Int32 ISFORMULA = 98765432; 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir template< typename Ifc1 > 40*cdf0e10cSrcweir ScVbaCondition< Ifc1 >::ScVbaCondition( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext > & xContext, const uno::Reference< sheet::XSheetCondition >& _xSheetCondition ) : ScVbaCondition_BASE( xParent, xContext ), mxSheetCondition( _xSheetCondition ) 41*cdf0e10cSrcweir { 42*cdf0e10cSrcweir mxAddressable.set( xParent, uno::UNO_QUERY_THROW ); 43*cdf0e10cSrcweir } 44*cdf0e10cSrcweir 45*cdf0e10cSrcweir template< typename Ifc1 > 46*cdf0e10cSrcweir sheet::ConditionOperator 47*cdf0e10cSrcweir ScVbaCondition< Ifc1 >::retrieveAPIOperator( const uno::Any& _aOperator) throw ( script::BasicErrorException ) 48*cdf0e10cSrcweir { 49*cdf0e10cSrcweir sheet::ConditionOperator aRetAPIOperator = sheet::ConditionOperator_NONE; 50*cdf0e10cSrcweir sal_Int32 nOperator = 0; 51*cdf0e10cSrcweir if ( (_aOperator >>= nOperator ) ) 52*cdf0e10cSrcweir { 53*cdf0e10cSrcweir switch(nOperator) 54*cdf0e10cSrcweir { 55*cdf0e10cSrcweir case excel::XlFormatConditionOperator::xlBetween: 56*cdf0e10cSrcweir aRetAPIOperator = sheet::ConditionOperator_BETWEEN; 57*cdf0e10cSrcweir break; 58*cdf0e10cSrcweir case excel::XlFormatConditionOperator::xlNotBetween: 59*cdf0e10cSrcweir aRetAPIOperator = sheet::ConditionOperator_NOT_BETWEEN; 60*cdf0e10cSrcweir break; 61*cdf0e10cSrcweir case excel::XlFormatConditionOperator::xlEqual: 62*cdf0e10cSrcweir aRetAPIOperator = sheet::ConditionOperator_EQUAL; 63*cdf0e10cSrcweir break; 64*cdf0e10cSrcweir case excel::XlFormatConditionOperator::xlNotEqual: 65*cdf0e10cSrcweir aRetAPIOperator = sheet::ConditionOperator_NOT_EQUAL; 66*cdf0e10cSrcweir break; 67*cdf0e10cSrcweir case excel::XlFormatConditionOperator::xlGreater: 68*cdf0e10cSrcweir aRetAPIOperator = sheet::ConditionOperator_GREATER; 69*cdf0e10cSrcweir break; 70*cdf0e10cSrcweir case excel::XlFormatConditionOperator::xlLess: 71*cdf0e10cSrcweir aRetAPIOperator = sheet::ConditionOperator_LESS; 72*cdf0e10cSrcweir break; 73*cdf0e10cSrcweir case excel::XlFormatConditionOperator::xlGreaterEqual: 74*cdf0e10cSrcweir aRetAPIOperator = sheet::ConditionOperator_GREATER_EQUAL; 75*cdf0e10cSrcweir break; 76*cdf0e10cSrcweir case excel::XlFormatConditionOperator::xlLessEqual: 77*cdf0e10cSrcweir aRetAPIOperator = sheet::ConditionOperator_LESS_EQUAL; 78*cdf0e10cSrcweir break; 79*cdf0e10cSrcweir default: 80*cdf0e10cSrcweir aRetAPIOperator = sheet::ConditionOperator_NONE; 81*cdf0e10cSrcweir break; 82*cdf0e10cSrcweir } 83*cdf0e10cSrcweir } 84*cdf0e10cSrcweir return aRetAPIOperator; 85*cdf0e10cSrcweir } 86*cdf0e10cSrcweir 87*cdf0e10cSrcweir template< typename Ifc1 > 88*cdf0e10cSrcweir rtl::OUString 89*cdf0e10cSrcweir ScVbaCondition< Ifc1 >::Formula1( ) throw ( script::BasicErrorException, uno::RuntimeException ) 90*cdf0e10cSrcweir { 91*cdf0e10cSrcweir return mxSheetCondition->getFormula1(); 92*cdf0e10cSrcweir } 93*cdf0e10cSrcweir 94*cdf0e10cSrcweir template< typename Ifc1 > 95*cdf0e10cSrcweir rtl::OUString 96*cdf0e10cSrcweir ScVbaCondition< Ifc1 >::Formula2( ) throw ( script::BasicErrorException, uno::RuntimeException ) 97*cdf0e10cSrcweir { 98*cdf0e10cSrcweir return mxSheetCondition->getFormula2(); 99*cdf0e10cSrcweir } 100*cdf0e10cSrcweir 101*cdf0e10cSrcweir template< typename Ifc1 > 102*cdf0e10cSrcweir void 103*cdf0e10cSrcweir ScVbaCondition< Ifc1 >::setFormula1( const uno::Any& _aFormula1) throw ( script::BasicErrorException ) 104*cdf0e10cSrcweir { 105*cdf0e10cSrcweir rtl::OUString sFormula; 106*cdf0e10cSrcweir if ( (_aFormula1 >>= sFormula )) 107*cdf0e10cSrcweir { 108*cdf0e10cSrcweir mxSheetCondition->setFormula1( sFormula ); 109*cdf0e10cSrcweir table::CellRangeAddress aCellRangeAddress = mxAddressable->getRangeAddress(); 110*cdf0e10cSrcweir table::CellAddress aCellAddress( aCellRangeAddress.Sheet, aCellRangeAddress.StartColumn, aCellRangeAddress.StartRow ); 111*cdf0e10cSrcweir mxSheetCondition->setSourcePosition(aCellAddress); 112*cdf0e10cSrcweir } 113*cdf0e10cSrcweir } 114*cdf0e10cSrcweir 115*cdf0e10cSrcweir template< typename Ifc1 > 116*cdf0e10cSrcweir void 117*cdf0e10cSrcweir ScVbaCondition< Ifc1 >::setFormula2( const uno::Any& _aFormula2) throw ( script::BasicErrorException ) 118*cdf0e10cSrcweir { 119*cdf0e10cSrcweir rtl::OUString sFormula2; 120*cdf0e10cSrcweir // #TODO surely this can't be right? 121*cdf0e10cSrcweir // ( from helperapi/impl/.../calc/ConditionImpl.java 122*cdf0e10cSrcweir if ( (_aFormula2 >>= sFormula2 )) 123*cdf0e10cSrcweir mxSheetCondition->setFormula1(sFormula2); 124*cdf0e10cSrcweir } 125*cdf0e10cSrcweir 126*cdf0e10cSrcweir template< typename Ifc1 > 127*cdf0e10cSrcweir sal_Int32 128*cdf0e10cSrcweir ScVbaCondition< Ifc1 >::Operator(sal_Bool _bIncludeFormulaValue) throw ( script::BasicErrorException ) 129*cdf0e10cSrcweir { 130*cdf0e10cSrcweir sal_Int32 retvalue = -1; 131*cdf0e10cSrcweir sheet::ConditionOperator aConditionalOperator = mxSheetCondition->getOperator(); 132*cdf0e10cSrcweir switch (aConditionalOperator) 133*cdf0e10cSrcweir { 134*cdf0e10cSrcweir case sheet::ConditionOperator_EQUAL: 135*cdf0e10cSrcweir retvalue = excel::XlFormatConditionOperator::xlEqual; 136*cdf0e10cSrcweir break; 137*cdf0e10cSrcweir case sheet::ConditionOperator_NOT_EQUAL: 138*cdf0e10cSrcweir retvalue = excel::XlFormatConditionOperator::xlNotEqual; 139*cdf0e10cSrcweir break; 140*cdf0e10cSrcweir case sheet::ConditionOperator_GREATER: 141*cdf0e10cSrcweir retvalue = excel::XlFormatConditionOperator::xlGreater; 142*cdf0e10cSrcweir break; 143*cdf0e10cSrcweir case sheet::ConditionOperator_GREATER_EQUAL: 144*cdf0e10cSrcweir retvalue = excel::XlFormatConditionOperator::xlGreaterEqual; 145*cdf0e10cSrcweir break; 146*cdf0e10cSrcweir case sheet::ConditionOperator_LESS: 147*cdf0e10cSrcweir retvalue = excel::XlFormatConditionOperator::xlLess; 148*cdf0e10cSrcweir break; 149*cdf0e10cSrcweir case sheet::ConditionOperator_LESS_EQUAL: 150*cdf0e10cSrcweir retvalue = excel::XlFormatConditionOperator::xlLessEqual; 151*cdf0e10cSrcweir break; 152*cdf0e10cSrcweir case sheet::ConditionOperator_BETWEEN: 153*cdf0e10cSrcweir retvalue = excel::XlFormatConditionOperator::xlBetween; 154*cdf0e10cSrcweir break; 155*cdf0e10cSrcweir case sheet::ConditionOperator_NOT_BETWEEN: 156*cdf0e10cSrcweir retvalue = excel::XlFormatConditionOperator::xlNotBetween; 157*cdf0e10cSrcweir break; 158*cdf0e10cSrcweir case sheet::ConditionOperator_FORMULA: 159*cdf0e10cSrcweir if (_bIncludeFormulaValue) 160*cdf0e10cSrcweir { 161*cdf0e10cSrcweir //#FIXME huh what's this all about 162*cdf0e10cSrcweir // from helperapi/impl/.../calc/ConditionImpl 163*cdf0e10cSrcweir retvalue = ISFORMULA; 164*cdf0e10cSrcweir break; 165*cdf0e10cSrcweir } 166*cdf0e10cSrcweir case sheet::ConditionOperator_NONE: 167*cdf0e10cSrcweir default: 168*cdf0e10cSrcweir DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Operator not supported"))); 169*cdf0e10cSrcweir break; 170*cdf0e10cSrcweir } 171*cdf0e10cSrcweir return retvalue; 172*cdf0e10cSrcweir } 173*cdf0e10cSrcweir 174*cdf0e10cSrcweir template class ScVbaCondition< excel::XFormatCondition >; 175*cdf0e10cSrcweir 176