1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #include "vbacondition.hxx" 29 #include <ooo/vba/excel/XlFormatConditionOperator.hpp> 30 #include <ooo/vba/excel/XFormatCondition.hpp> 31 #include <com/sun/star/table/XCellRange.hpp> 32 #include <com/sun/star/sheet/XCellRangeAddressable.hpp> 33 34 using namespace ::ooo::vba; 35 using namespace ::com::sun::star; 36 37 const sal_Int32 ISFORMULA = 98765432; 38 39 template< typename Ifc1 > 40 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 { 42 mxAddressable.set( xParent, uno::UNO_QUERY_THROW ); 43 } 44 45 template< typename Ifc1 > 46 sheet::ConditionOperator 47 ScVbaCondition< Ifc1 >::retrieveAPIOperator( const uno::Any& _aOperator) throw ( script::BasicErrorException ) 48 { 49 sheet::ConditionOperator aRetAPIOperator = sheet::ConditionOperator_NONE; 50 sal_Int32 nOperator = 0; 51 if ( (_aOperator >>= nOperator ) ) 52 { 53 switch(nOperator) 54 { 55 case excel::XlFormatConditionOperator::xlBetween: 56 aRetAPIOperator = sheet::ConditionOperator_BETWEEN; 57 break; 58 case excel::XlFormatConditionOperator::xlNotBetween: 59 aRetAPIOperator = sheet::ConditionOperator_NOT_BETWEEN; 60 break; 61 case excel::XlFormatConditionOperator::xlEqual: 62 aRetAPIOperator = sheet::ConditionOperator_EQUAL; 63 break; 64 case excel::XlFormatConditionOperator::xlNotEqual: 65 aRetAPIOperator = sheet::ConditionOperator_NOT_EQUAL; 66 break; 67 case excel::XlFormatConditionOperator::xlGreater: 68 aRetAPIOperator = sheet::ConditionOperator_GREATER; 69 break; 70 case excel::XlFormatConditionOperator::xlLess: 71 aRetAPIOperator = sheet::ConditionOperator_LESS; 72 break; 73 case excel::XlFormatConditionOperator::xlGreaterEqual: 74 aRetAPIOperator = sheet::ConditionOperator_GREATER_EQUAL; 75 break; 76 case excel::XlFormatConditionOperator::xlLessEqual: 77 aRetAPIOperator = sheet::ConditionOperator_LESS_EQUAL; 78 break; 79 default: 80 aRetAPIOperator = sheet::ConditionOperator_NONE; 81 break; 82 } 83 } 84 return aRetAPIOperator; 85 } 86 87 template< typename Ifc1 > 88 rtl::OUString 89 ScVbaCondition< Ifc1 >::Formula1( ) throw ( script::BasicErrorException, uno::RuntimeException ) 90 { 91 return mxSheetCondition->getFormula1(); 92 } 93 94 template< typename Ifc1 > 95 rtl::OUString 96 ScVbaCondition< Ifc1 >::Formula2( ) throw ( script::BasicErrorException, uno::RuntimeException ) 97 { 98 return mxSheetCondition->getFormula2(); 99 } 100 101 template< typename Ifc1 > 102 void 103 ScVbaCondition< Ifc1 >::setFormula1( const uno::Any& _aFormula1) throw ( script::BasicErrorException ) 104 { 105 rtl::OUString sFormula; 106 if ( (_aFormula1 >>= sFormula )) 107 { 108 mxSheetCondition->setFormula1( sFormula ); 109 table::CellRangeAddress aCellRangeAddress = mxAddressable->getRangeAddress(); 110 table::CellAddress aCellAddress( aCellRangeAddress.Sheet, aCellRangeAddress.StartColumn, aCellRangeAddress.StartRow ); 111 mxSheetCondition->setSourcePosition(aCellAddress); 112 } 113 } 114 115 template< typename Ifc1 > 116 void 117 ScVbaCondition< Ifc1 >::setFormula2( const uno::Any& _aFormula2) throw ( script::BasicErrorException ) 118 { 119 rtl::OUString sFormula2; 120 // #TODO surely this can't be right? 121 // ( from helperapi/impl/.../calc/ConditionImpl.java 122 if ( (_aFormula2 >>= sFormula2 )) 123 mxSheetCondition->setFormula1(sFormula2); 124 } 125 126 template< typename Ifc1 > 127 sal_Int32 128 ScVbaCondition< Ifc1 >::Operator(sal_Bool _bIncludeFormulaValue) throw ( script::BasicErrorException ) 129 { 130 sal_Int32 retvalue = -1; 131 sheet::ConditionOperator aConditionalOperator = mxSheetCondition->getOperator(); 132 switch (aConditionalOperator) 133 { 134 case sheet::ConditionOperator_EQUAL: 135 retvalue = excel::XlFormatConditionOperator::xlEqual; 136 break; 137 case sheet::ConditionOperator_NOT_EQUAL: 138 retvalue = excel::XlFormatConditionOperator::xlNotEqual; 139 break; 140 case sheet::ConditionOperator_GREATER: 141 retvalue = excel::XlFormatConditionOperator::xlGreater; 142 break; 143 case sheet::ConditionOperator_GREATER_EQUAL: 144 retvalue = excel::XlFormatConditionOperator::xlGreaterEqual; 145 break; 146 case sheet::ConditionOperator_LESS: 147 retvalue = excel::XlFormatConditionOperator::xlLess; 148 break; 149 case sheet::ConditionOperator_LESS_EQUAL: 150 retvalue = excel::XlFormatConditionOperator::xlLessEqual; 151 break; 152 case sheet::ConditionOperator_BETWEEN: 153 retvalue = excel::XlFormatConditionOperator::xlBetween; 154 break; 155 case sheet::ConditionOperator_NOT_BETWEEN: 156 retvalue = excel::XlFormatConditionOperator::xlNotBetween; 157 break; 158 case sheet::ConditionOperator_FORMULA: 159 if (_bIncludeFormulaValue) 160 { 161 //#FIXME huh what's this all about 162 // from helperapi/impl/.../calc/ConditionImpl 163 retvalue = ISFORMULA; 164 break; 165 } 166 case sheet::ConditionOperator_NONE: 167 default: 168 DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Operator not supported"))); 169 break; 170 } 171 return retvalue; 172 } 173 174 template class ScVbaCondition< excel::XFormatCondition >; 175 176