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>
34  const uno::Reference<XHelperInterface>& xParent,
35  const uno::Reference<uno::XComponentContext>& xContext,
36  const uno::Reference<sheet::XSheetCondition>& _xSheetCondition)
37  : ScVbaCondition_BASE(xParent, xContext)
38  , mxSheetCondition(_xSheetCondition)
39 {
40  mxAddressable.set(xParent, uno::UNO_QUERY_THROW);
41 }
42 
43 template <typename... Ifc>
44 sheet::ConditionOperator ScVbaCondition<Ifc...>::retrieveAPIOperator(const uno::Any& _aOperator)
45 {
46  sheet::ConditionOperator aRetAPIOperator = sheet::ConditionOperator_NONE;
47  sal_Int32 nOperator = 0;
48  if (_aOperator >>= nOperator)
49  {
50  switch (nOperator)
51  {
52  case excel::XlFormatConditionOperator::xlBetween:
53  aRetAPIOperator = sheet::ConditionOperator_BETWEEN;
54  break;
55  case excel::XlFormatConditionOperator::xlNotBetween:
56  aRetAPIOperator = sheet::ConditionOperator_NOT_BETWEEN;
57  break;
58  case excel::XlFormatConditionOperator::xlEqual:
59  aRetAPIOperator = sheet::ConditionOperator_EQUAL;
60  break;
61  case excel::XlFormatConditionOperator::xlNotEqual:
62  aRetAPIOperator = sheet::ConditionOperator_NOT_EQUAL;
63  break;
64  case excel::XlFormatConditionOperator::xlGreater:
65  aRetAPIOperator = sheet::ConditionOperator_GREATER;
66  break;
67  case excel::XlFormatConditionOperator::xlLess:
68  aRetAPIOperator = sheet::ConditionOperator_LESS;
69  break;
70  case excel::XlFormatConditionOperator::xlGreaterEqual:
71  aRetAPIOperator = sheet::ConditionOperator_GREATER_EQUAL;
72  break;
73  case excel::XlFormatConditionOperator::xlLessEqual:
74  aRetAPIOperator = sheet::ConditionOperator_LESS_EQUAL;
75  break;
76  default:
77  aRetAPIOperator = sheet::ConditionOperator_NONE;
78  break;
79  }
80  }
81  return aRetAPIOperator;
82 }
83 
84 template <typename... Ifc> OUString ScVbaCondition<Ifc...>::Formula1()
85 {
86  return mxSheetCondition->getFormula1();
87 }
88 
89 template <typename... Ifc> OUString ScVbaCondition<Ifc...>::Formula2()
90 {
91  return mxSheetCondition->getFormula2();
92 }
93 
94 template <typename... Ifc> sal_Int32 ScVbaCondition<Ifc...>::Operator(bool _bIncludeFormulaValue)
95 {
96  sal_Int32 retvalue = -1;
97  sheet::ConditionOperator aConditionalOperator = mxSheetCondition->getOperator();
98  switch (aConditionalOperator)
99  {
100  case sheet::ConditionOperator_EQUAL:
101  retvalue = excel::XlFormatConditionOperator::xlEqual;
102  break;
103  case sheet::ConditionOperator_NOT_EQUAL:
104  retvalue = excel::XlFormatConditionOperator::xlNotEqual;
105  break;
106  case sheet::ConditionOperator_GREATER:
107  retvalue = excel::XlFormatConditionOperator::xlGreater;
108  break;
109  case sheet::ConditionOperator_GREATER_EQUAL:
110  retvalue = excel::XlFormatConditionOperator::xlGreaterEqual;
111  break;
112  case sheet::ConditionOperator_LESS:
113  retvalue = excel::XlFormatConditionOperator::xlLess;
114  break;
115  case sheet::ConditionOperator_LESS_EQUAL:
116  retvalue = excel::XlFormatConditionOperator::xlLessEqual;
117  break;
118  case sheet::ConditionOperator_BETWEEN:
119  retvalue = excel::XlFormatConditionOperator::xlBetween;
120  break;
121  case sheet::ConditionOperator_NOT_BETWEEN:
122  retvalue = excel::XlFormatConditionOperator::xlNotBetween;
123  break;
124  case sheet::ConditionOperator_FORMULA:
125  if (_bIncludeFormulaValue)
126  {
127  //#FIXME huh what's this all about
128  // from helperapi/impl/.../calc/ConditionImpl
129  retvalue = ISFORMULA;
130  break;
131  }
132  [[fallthrough]]; //TODO ???
133  case sheet::ConditionOperator_NONE:
134  default:
135  DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED, u"Operator not supported");
136  break;
137  }
138  return retvalue;
139 }
140 
142 
143 /* 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
float u
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