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