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