1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "vbacondition.hxx"
21 #include <ooo/vba/excel/XlFormatConditionOperator.hpp>
22 #include <ooo/vba/excel/XFormatCondition.hpp>
23 #include <com/sun/star/table/XCellRange.hpp>
24 #include <com/sun/star/sheet/XCellRangeAddressable.hpp>
26 using namespace ::ooo::vba
;
27 using namespace ::com::sun::star
;
29 const sal_Int32 ISFORMULA
= 98765432;
31 template< typename Ifc1
>
32 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
)
34 mxAddressable
.set( xParent
, uno::UNO_QUERY_THROW
);
37 template< typename Ifc1
>
38 sheet::ConditionOperator
39 ScVbaCondition
< Ifc1
>::retrieveAPIOperator( const uno::Any
& _aOperator
) throw ( script::BasicErrorException
)
41 sheet::ConditionOperator aRetAPIOperator
= sheet::ConditionOperator_NONE
;
42 sal_Int32 nOperator
= 0;
43 if ( (_aOperator
>>= nOperator
) )
47 case excel::XlFormatConditionOperator::xlBetween
:
48 aRetAPIOperator
= sheet::ConditionOperator_BETWEEN
;
50 case excel::XlFormatConditionOperator::xlNotBetween
:
51 aRetAPIOperator
= sheet::ConditionOperator_NOT_BETWEEN
;
53 case excel::XlFormatConditionOperator::xlEqual
:
54 aRetAPIOperator
= sheet::ConditionOperator_EQUAL
;
56 case excel::XlFormatConditionOperator::xlNotEqual
:
57 aRetAPIOperator
= sheet::ConditionOperator_NOT_EQUAL
;
59 case excel::XlFormatConditionOperator::xlGreater
:
60 aRetAPIOperator
= sheet::ConditionOperator_GREATER
;
62 case excel::XlFormatConditionOperator::xlLess
:
63 aRetAPIOperator
= sheet::ConditionOperator_LESS
;
65 case excel::XlFormatConditionOperator::xlGreaterEqual
:
66 aRetAPIOperator
= sheet::ConditionOperator_GREATER_EQUAL
;
68 case excel::XlFormatConditionOperator::xlLessEqual
:
69 aRetAPIOperator
= sheet::ConditionOperator_LESS_EQUAL
;
72 aRetAPIOperator
= sheet::ConditionOperator_NONE
;
76 return aRetAPIOperator
;
79 template< typename Ifc1
>
81 ScVbaCondition
< Ifc1
>::Formula1( ) throw ( script::BasicErrorException
, uno::RuntimeException
)
83 return mxSheetCondition
->getFormula1();
86 template< typename Ifc1
>
88 ScVbaCondition
< Ifc1
>::Formula2( ) throw ( script::BasicErrorException
, uno::RuntimeException
)
90 return mxSheetCondition
->getFormula2();
93 template< typename Ifc1
>
95 ScVbaCondition
< Ifc1
>::setFormula1( const uno::Any
& _aFormula1
) throw ( script::BasicErrorException
)
98 if ( (_aFormula1
>>= sFormula
))
100 mxSheetCondition
->setFormula1( sFormula
);
101 table::CellRangeAddress aCellRangeAddress
= mxAddressable
->getRangeAddress();
102 table::CellAddress
aCellAddress( aCellRangeAddress
.Sheet
, aCellRangeAddress
.StartColumn
, aCellRangeAddress
.StartRow
);
103 mxSheetCondition
->setSourcePosition(aCellAddress
);
107 template< typename Ifc1
>
109 ScVbaCondition
< Ifc1
>::setFormula2( const uno::Any
& _aFormula2
) throw ( script::BasicErrorException
)
112 // #TODO surely this can't be right?
113 // ( from helperapi/impl/.../calc/ConditionImpl.java
114 if ( (_aFormula2
>>= sFormula2
))
115 mxSheetCondition
->setFormula1(sFormula2
);
118 template< typename Ifc1
>
120 ScVbaCondition
< Ifc1
>::Operator(bool _bIncludeFormulaValue
) throw ( script::BasicErrorException
)
122 sal_Int32 retvalue
= -1;
123 sheet::ConditionOperator aConditionalOperator
= mxSheetCondition
->getOperator();
124 switch (aConditionalOperator
)
126 case sheet::ConditionOperator_EQUAL
:
127 retvalue
= excel::XlFormatConditionOperator::xlEqual
;
129 case sheet::ConditionOperator_NOT_EQUAL
:
130 retvalue
= excel::XlFormatConditionOperator::xlNotEqual
;
132 case sheet::ConditionOperator_GREATER
:
133 retvalue
= excel::XlFormatConditionOperator::xlGreater
;
135 case sheet::ConditionOperator_GREATER_EQUAL
:
136 retvalue
= excel::XlFormatConditionOperator::xlGreaterEqual
;
138 case sheet::ConditionOperator_LESS
:
139 retvalue
= excel::XlFormatConditionOperator::xlLess
;
141 case sheet::ConditionOperator_LESS_EQUAL
:
142 retvalue
= excel::XlFormatConditionOperator::xlLessEqual
;
144 case sheet::ConditionOperator_BETWEEN
:
145 retvalue
= excel::XlFormatConditionOperator::xlBetween
;
147 case sheet::ConditionOperator_NOT_BETWEEN
:
148 retvalue
= excel::XlFormatConditionOperator::xlNotBetween
;
150 case sheet::ConditionOperator_FORMULA
:
151 if (_bIncludeFormulaValue
)
153 //#FIXME huh what's this all about
154 // from helperapi/impl/.../calc/ConditionImpl
155 retvalue
= ISFORMULA
;
158 case sheet::ConditionOperator_NONE
:
160 DebugHelper::basicexception(SbERR_METHOD_FAILED
, OUString("Operator not supported"));
166 template class ScVbaCondition
< excel::XFormatCondition
>;
168 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */