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