LibreOffice Module sc (master)  1
vbacondition.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 #include "vbacondition.hxx"
21 #include <ooo/vba/excel/XlFormatConditionOperator.hpp>
22 #include <ooo/vba/excel/XFormatCondition.hpp>
23 #include <com/sun/star/sheet/XCellRangeAddressable.hpp>
24 #include <com/sun/star/sheet/XSheetCondition.hpp>
25 #include <basic/sberrors.hxx>
26 
27 using namespace ::ooo::vba;
28 using namespace ::com::sun::star;
29 
30 const sal_Int32 ISFORMULA = 98765432;
31 
32 template< typename... Ifc >
33 ScVbaCondition< Ifc... >::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 {
35  mxAddressable.set( xParent, uno::UNO_QUERY_THROW );
36 }
37 
38 template< typename... Ifc >
39 sheet::ConditionOperator
41 {
42  sheet::ConditionOperator aRetAPIOperator = sheet::ConditionOperator_NONE;
43  sal_Int32 nOperator = 0;
44  if ( _aOperator >>= nOperator )
45  {
46  switch(nOperator)
47  {
48  case excel::XlFormatConditionOperator::xlBetween:
49  aRetAPIOperator = sheet::ConditionOperator_BETWEEN;
50  break;
51  case excel::XlFormatConditionOperator::xlNotBetween:
52  aRetAPIOperator = sheet::ConditionOperator_NOT_BETWEEN;
53  break;
54  case excel::XlFormatConditionOperator::xlEqual:
55  aRetAPIOperator = sheet::ConditionOperator_EQUAL;
56  break;
57  case excel::XlFormatConditionOperator::xlNotEqual:
58  aRetAPIOperator = sheet::ConditionOperator_NOT_EQUAL;
59  break;
60  case excel::XlFormatConditionOperator::xlGreater:
61  aRetAPIOperator = sheet::ConditionOperator_GREATER;
62  break;
63  case excel::XlFormatConditionOperator::xlLess:
64  aRetAPIOperator = sheet::ConditionOperator_LESS;
65  break;
66  case excel::XlFormatConditionOperator::xlGreaterEqual:
67  aRetAPIOperator = sheet::ConditionOperator_GREATER_EQUAL;
68  break;
69  case excel::XlFormatConditionOperator::xlLessEqual:
70  aRetAPIOperator = sheet::ConditionOperator_LESS_EQUAL;
71  break;
72  default:
73  aRetAPIOperator = sheet::ConditionOperator_NONE;
74  break;
75  }
76  }
77  return aRetAPIOperator;
78 }
79 
80 template< typename... Ifc >
81 OUString
83 {
84  return mxSheetCondition->getFormula1();
85 }
86 
87 template< typename... Ifc >
88 OUString
90 {
91  return mxSheetCondition->getFormula2();
92 }
93 
94 template< typename... Ifc >
95 sal_Int32
96 ScVbaCondition< Ifc... >::Operator(bool _bIncludeFormulaValue)
97 {
98  sal_Int32 retvalue = -1;
99  sheet::ConditionOperator aConditionalOperator = mxSheetCondition->getOperator();
100  switch (aConditionalOperator)
101  {
102  case sheet::ConditionOperator_EQUAL:
103  retvalue = excel::XlFormatConditionOperator::xlEqual;
104  break;
105  case sheet::ConditionOperator_NOT_EQUAL:
106  retvalue = excel::XlFormatConditionOperator::xlNotEqual;
107  break;
108  case sheet::ConditionOperator_GREATER:
109  retvalue = excel::XlFormatConditionOperator::xlGreater;
110  break;
111  case sheet::ConditionOperator_GREATER_EQUAL:
112  retvalue = excel::XlFormatConditionOperator::xlGreaterEqual;
113  break;
114  case sheet::ConditionOperator_LESS:
115  retvalue = excel::XlFormatConditionOperator::xlLess;
116  break;
117  case sheet::ConditionOperator_LESS_EQUAL:
118  retvalue = excel::XlFormatConditionOperator::xlLessEqual;
119  break;
120  case sheet::ConditionOperator_BETWEEN:
121  retvalue = excel::XlFormatConditionOperator::xlBetween;
122  break;
123  case sheet::ConditionOperator_NOT_BETWEEN:
124  retvalue = excel::XlFormatConditionOperator::xlNotBetween;
125  break;
126  case sheet::ConditionOperator_FORMULA:
127  if (_bIncludeFormulaValue)
128  {
129  //#FIXME huh what's this all about
130  // from helperapi/impl/.../calc/ConditionImpl
131  retvalue = ISFORMULA;
132  break;
133  }
134  [[fallthrough]]; //TODO ???
135  case sheet::ConditionOperator_NONE:
136  default:
137  DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED, "Operator not supported");
138  break;
139  }
140  return retvalue;
141 }
142 
144 
145 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static css::sheet::ConditionOperator retrieveAPIOperator(const css::uno::Any &_aOperator)
css::uno::Reference< css::sheet::XCellRangeAddressable > mxAddressable
virtual OUString SAL_CALL Formula2() override
const sal_Int32 ISFORMULA
ScVbaCondition(const css::uno::Reference< ov::XHelperInterface > &xParent, const css::uno::Reference< css::uno::XComponentContext > &xContext, const css::uno::Reference< css::sheet::XSheetCondition > &_xSheetCondition)
virtual sal_Int32 SAL_CALL Operator() override=0
virtual OUString SAL_CALL Formula1() override
#define ERRCODE_BASIC_METHOD_FAILED