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 .
24 #include <formula/grammar.hxx>
25 #include <rtl/ref.hxx>
26 #include <svl/itemprop.hxx>
27 #include <com/sun/star/sheet/XSheetConditionalEntries.hpp>
28 #include <com/sun/star/sheet/XSheetCondition2.hpp>
29 #include <com/sun/star/sheet/XSheetConditionalEntry.hpp>
30 #include <com/sun/star/lang/XServiceInfo.hpp>
31 #include <com/sun/star/container/XNameAccess.hpp>
32 #include <com/sun/star/container/XEnumerationAccess.hpp>
33 #include <com/sun/star/beans/XPropertySet.hpp>
35 #include <com/sun/star/sheet/XMultiFormulaTokens.hpp>
36 #include <com/sun/star/sheet/FormulaToken.hpp>
37 #include <comphelper/servicehelper.hxx>
38 #include <cppuhelper/implbase.hxx>
40 #include "address.hxx"
41 #include "conditio.hxx"
44 class ScTableConditionalEntry
;
45 class ScValidationData
;
47 struct ScCondFormatEntryItem
49 css::uno::Sequence
< css::sheet::FormulaToken
> maTokens1
;
50 css::uno::Sequence
< css::sheet::FormulaToken
> maTokens2
;
55 OUString maPosStr
; // formula position as text
56 OUString maStyle
; // display name as stored in ScStyleSheet
58 formula::FormulaGrammar::Grammar meGrammar1
; // grammar used with maExpr1
59 formula::FormulaGrammar::Grammar meGrammar2
; // grammar used with maExpr2
60 ScConditionMode meMode
;
62 // Make sure the grammar is initialized for API calls.
63 ScCondFormatEntryItem();
66 class ScTableConditionalFormat final
: public cppu::WeakImplHelper
<
67 css::sheet::XSheetConditionalEntries
,
68 css::container::XNameAccess
,
69 css::container::XEnumerationAccess
,
70 css::lang::XServiceInfo
>
73 std::vector
<rtl::Reference
<ScTableConditionalEntry
>> maEntries
;
75 ScTableConditionalEntry
* GetObjectByIndex_Impl(sal_uInt16 nIndex
) const;
76 void AddEntry_Impl(const ScCondFormatEntryItem
& aEntry
);
78 ScTableConditionalFormat() = delete;
79 ScTableConditionalFormat(const ScDocument
* pDoc
, sal_uLong nKey
,
80 SCTAB nTab
, formula::FormulaGrammar::Grammar eGrammar
);
81 virtual ~ScTableConditionalFormat() override
;
83 void FillFormat( ScConditionalFormat
& rFormat
, ScDocument
& rDoc
,
84 formula::FormulaGrammar::Grammar eGrammar
) const;
86 // XSheetConditionalEntries
87 virtual void SAL_CALL
addNew( const css::uno::Sequence
< css::beans::PropertyValue
>& aConditionalEntry
) override
;
88 virtual void SAL_CALL
removeByIndex( sal_Int32 nIndex
) override
;
89 virtual void SAL_CALL
clear() override
;
92 virtual sal_Int32 SAL_CALL
getCount() override
;
93 virtual css::uno::Any SAL_CALL
getByIndex( sal_Int32 Index
) override
;
96 virtual css::uno::Any SAL_CALL
getByName( const OUString
& aName
) override
;
97 virtual css::uno::Sequence
< OUString
> SAL_CALL
getElementNames() override
;
98 virtual sal_Bool SAL_CALL
hasByName( const OUString
& aName
) override
;
100 // XEnumerationAccess
101 virtual css::uno::Reference
< css::container::XEnumeration
> SAL_CALL
102 createEnumeration() override
;
105 virtual css::uno::Type SAL_CALL
getElementType() override
;
106 virtual sal_Bool SAL_CALL
hasElements() override
;
109 virtual OUString SAL_CALL
getImplementationName() override
;
110 virtual sal_Bool SAL_CALL
supportsService( const OUString
& ServiceName
) override
;
111 virtual css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames() override
;
114 class ScTableConditionalEntry final
: public cppu::WeakImplHelper
<
115 css::sheet::XSheetCondition2
,
116 css::sheet::XSheetConditionalEntry
,
117 css::lang::XServiceInfo
>
120 ScCondFormatEntryItem aData
;
123 ScTableConditionalEntry() = delete;
124 ScTableConditionalEntry(ScCondFormatEntryItem aItem
);
125 virtual ~ScTableConditionalEntry() override
;
127 void GetData(ScCondFormatEntryItem
& rData
) const;
130 virtual css::sheet::ConditionOperator SAL_CALL
getOperator() override
;
131 virtual sal_Int32 SAL_CALL
getConditionOperator() override
;
132 virtual void SAL_CALL
setOperator( css::sheet::ConditionOperator nOperator
) override
;
133 virtual void SAL_CALL
setConditionOperator( sal_Int32 nOperator
) override
;
134 virtual OUString SAL_CALL
getFormula1() override
;
135 virtual void SAL_CALL
setFormula1( const OUString
& aFormula1
) override
;
136 virtual OUString SAL_CALL
getFormula2() override
;
137 virtual void SAL_CALL
setFormula2( const OUString
& aFormula2
) override
;
138 virtual css::table::CellAddress SAL_CALL
getSourcePosition() override
;
139 virtual void SAL_CALL
setSourcePosition( const css::table::CellAddress
& aSourcePosition
) override
;
141 // XSheetConditionalEntry
142 virtual OUString SAL_CALL
getStyleName() override
;
143 virtual void SAL_CALL
setStyleName( const OUString
& aStyleName
) override
;
146 virtual OUString SAL_CALL
getImplementationName() override
;
147 virtual sal_Bool SAL_CALL
supportsService( const OUString
& ServiceName
) override
;
148 virtual css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames() override
;
151 class ScTableValidationObj final
: public cppu::WeakImplHelper
<
152 css::sheet::XSheetCondition2
,
153 css::sheet::XMultiFormulaTokens
,
154 css::beans::XPropertySet
,
155 css::lang::XServiceInfo
>
158 SfxItemPropertySet aPropSet
;
159 ScConditionMode nMode
;
162 OUString maExprNmsp1
;
163 OUString maExprNmsp2
;
164 formula::FormulaGrammar::Grammar meGrammar1
; // grammar used with aExpr1 and aExpr2
165 formula::FormulaGrammar::Grammar meGrammar2
; // grammar used with aExpr1 and aExpr2
166 css::uno::Sequence
< css::sheet::FormulaToken
> aTokens1
;
167 css::uno::Sequence
< css::sheet::FormulaToken
> aTokens2
;
169 OUString aPosString
; // formula position as text
170 sal_uInt16 nValMode
; // enum ScValidationMode
174 OUString aInputTitle
;
175 OUString aInputMessage
;
177 sal_uInt16 nErrorStyle
; // enum ScValidErrorStyle
178 OUString aErrorTitle
;
179 OUString aErrorMessage
;
181 void ClearData_Impl();
185 ScTableValidationObj() = delete;
186 ScTableValidationObj(const ScDocument
& rDoc
, sal_uInt32 nKey
,
187 const formula::FormulaGrammar::Grammar eGrammar
);
188 virtual ~ScTableValidationObj() override
;
190 ScValidationData
* CreateValidationData( ScDocument
& rDoc
,
191 formula::FormulaGrammar::Grammar eGrammar
) const;
194 virtual css::sheet::ConditionOperator SAL_CALL
getOperator() override
;
195 virtual sal_Int32 SAL_CALL
getConditionOperator() override
;
196 virtual void SAL_CALL
setOperator( css::sheet::ConditionOperator nOperator
) override
;
197 virtual void SAL_CALL
setConditionOperator( sal_Int32 nOperator
) override
;
198 virtual OUString SAL_CALL
getFormula1() override
;
199 virtual void SAL_CALL
setFormula1( const OUString
& aFormula1
) override
;
200 virtual OUString SAL_CALL
getFormula2() override
;
201 virtual void SAL_CALL
setFormula2( const OUString
& aFormula2
) override
;
202 virtual css::table::CellAddress SAL_CALL
getSourcePosition() override
;
203 virtual void SAL_CALL
setSourcePosition( const css::table::CellAddress
& aSourcePosition
) override
;
205 // XMultiFormulaTokens
206 virtual css::uno::Sequence
< css::sheet::FormulaToken
>
207 SAL_CALL
getTokens( sal_Int32 nIndex
) override
;
208 virtual void SAL_CALL
setTokens( sal_Int32 nIndex
,
209 const css::uno::Sequence
< css::sheet::FormulaToken
>& aTokens
) override
;
210 virtual sal_Int32 SAL_CALL
getCount() override
;
213 virtual css::uno::Reference
< css::beans::XPropertySetInfo
>
214 SAL_CALL
getPropertySetInfo() override
;
215 virtual void SAL_CALL
setPropertyValue( const OUString
& aPropertyName
,
216 const css::uno::Any
& aValue
) override
;
217 virtual css::uno::Any SAL_CALL
getPropertyValue(
218 const OUString
& PropertyName
) override
;
219 virtual void SAL_CALL
addPropertyChangeListener( const OUString
& aPropertyName
,
220 const css::uno::Reference
< css::beans::XPropertyChangeListener
>& xListener
) override
;
221 virtual void SAL_CALL
removePropertyChangeListener( const OUString
& aPropertyName
,
222 const css::uno::Reference
< css::beans::XPropertyChangeListener
>& aListener
) override
;
223 virtual void SAL_CALL
addVetoableChangeListener( const OUString
& PropertyName
,
224 const css::uno::Reference
< css::beans::XVetoableChangeListener
>& aListener
) override
;
225 virtual void SAL_CALL
removeVetoableChangeListener( const OUString
& PropertyName
,
226 const css::uno::Reference
< css::beans::XVetoableChangeListener
>& aListener
) override
;
229 virtual OUString SAL_CALL
getImplementationName() override
;
230 virtual sal_Bool SAL_CALL
supportsService( const OUString
& ServiceName
) override
;
231 virtual css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames() override
;
234 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */