1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: vbacondition.cxx,v $
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
) )
58 case excel::XlFormatConditionOperator::xlBetween
:
59 aRetAPIOperator
= sheet::ConditionOperator_BETWEEN
;
61 case excel::XlFormatConditionOperator::xlNotBetween
:
62 aRetAPIOperator
= sheet::ConditionOperator_NOT_BETWEEN
;
64 case excel::XlFormatConditionOperator::xlEqual
:
65 aRetAPIOperator
= sheet::ConditionOperator_EQUAL
;
67 case excel::XlFormatConditionOperator::xlNotEqual
:
68 aRetAPIOperator
= sheet::ConditionOperator_NOT_EQUAL
;
70 case excel::XlFormatConditionOperator::xlGreater
:
71 aRetAPIOperator
= sheet::ConditionOperator_GREATER
;
73 case excel::XlFormatConditionOperator::xlLess
:
74 aRetAPIOperator
= sheet::ConditionOperator_LESS
;
76 case excel::XlFormatConditionOperator::xlGreaterEqual
:
77 aRetAPIOperator
= sheet::ConditionOperator_GREATER_EQUAL
;
79 case excel::XlFormatConditionOperator::xlLessEqual
:
80 aRetAPIOperator
= sheet::ConditionOperator_LESS_EQUAL
;
83 aRetAPIOperator
= sheet::ConditionOperator_NONE
;
87 return aRetAPIOperator
;
90 template< typename Ifc1
>
92 ScVbaCondition
< Ifc1
>::Formula1( ) throw ( script::BasicErrorException
, uno::RuntimeException
)
94 return mxSheetCondition
->getFormula1();
97 template< typename Ifc1
>
99 ScVbaCondition
< Ifc1
>::Formula2( ) throw ( script::BasicErrorException
, uno::RuntimeException
)
101 return mxSheetCondition
->getFormula2();
104 template< typename Ifc1
>
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
>
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
>
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
;
140 case sheet::ConditionOperator_NOT_EQUAL
:
141 retvalue
= excel::XlFormatConditionOperator::xlNotEqual
;
143 case sheet::ConditionOperator_GREATER
:
144 retvalue
= excel::XlFormatConditionOperator::xlGreater
;
146 case sheet::ConditionOperator_GREATER_EQUAL
:
147 retvalue
= excel::XlFormatConditionOperator::xlGreaterEqual
;
149 case sheet::ConditionOperator_LESS
:
150 retvalue
= excel::XlFormatConditionOperator::xlLess
;
152 case sheet::ConditionOperator_LESS_EQUAL
:
153 retvalue
= excel::XlFormatConditionOperator::xlLessEqual
;
155 case sheet::ConditionOperator_BETWEEN
:
156 retvalue
= excel::XlFormatConditionOperator::xlBetween
;
158 case sheet::ConditionOperator_NOT_BETWEEN
:
159 retvalue
= excel::XlFormatConditionOperator::xlNotBetween
;
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
;
169 case sheet::ConditionOperator_NONE
:
171 DebugHelper::exception(SbERR_METHOD_FAILED
, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Operator not supported")));
177 template class ScVbaCondition
< excel::XFormatCondition
>;