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#include <utility>
27
28using namespace ::ooo::vba;
29using namespace ::com::sun::star;
30
31const sal_Int32 ISFORMULA = 98765432;
32
33template <typename... Ifc>
34ScVbaCondition<Ifc...>::ScVbaCondition(const uno::Reference<XHelperInterface>& xParent,
35 const uno::Reference<uno::XComponentContext>& xContext,
36 uno::Reference<sheet::XSheetCondition> _xSheetCondition)
37 : ScVbaCondition_BASE(xParent, xContext)
38 , mxSheetCondition(std::move(_xSheetCondition))
39{
40 mxAddressable.set(xParent, uno::UNO_QUERY_THROW);
41}
42
43template <typename... Ifc>
44sheet::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
84template <typename... Ifc> OUString ScVbaCondition<Ifc...>::Formula1()
85{
86 return mxSheetCondition->getFormula1();
87}
88
89template <typename... Ifc> OUString ScVbaCondition<Ifc...>::Formula2()
90{
91 return mxSheetCondition->getFormula2();
92}
93
94template <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)
virtual OUString SAL_CALL Formula1() override
virtual OUString SAL_CALL Formula2() override
css::uno::Reference< css::sheet::XCellRangeAddressable > mxAddressable
virtual sal_Int32 SAL_CALL Operator() override=0
ScVbaCondition(const css::uno::Reference< ov::XHelperInterface > &xParent, const css::uno::Reference< css::uno::XComponentContext > &xContext, css::uno::Reference< css::sheet::XSheetCondition > _xSheetCondition)
float u
#define ERRCODE_BASIC_METHOD_FAILED
const sal_Int32 ISFORMULA