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/lang/XUnoTunnel.hpp>
34 #include <com/sun/star/beans/XPropertySet.hpp>
36 #include <com/sun/star/sheet/XMultiFormulaTokens.hpp>
37 #include <com/sun/star/sheet/FormulaToken.hpp>
38 #include <comphelper/servicehelper.hxx>
39 #include <cppuhelper/implbase.hxx>
41 #include "address.hxx"
42 #include "conditio.hxx"
45 class ScTableConditionalEntry
;
46 class ScValidationData
;
48 struct ScCondFormatEntryItem
50 css::uno::Sequence
< css::sheet::FormulaToken
> maTokens1
;
51 css::uno::Sequence
< css::sheet::FormulaToken
> maTokens2
;
56 OUString maPosStr
; // formula position as text
57 OUString maStyle
; // display name as stored in ScStyleSheet
59 formula::FormulaGrammar::Grammar meGrammar1
; // grammar used with maExpr1
60 formula::FormulaGrammar::Grammar meGrammar2
; // grammar used with maExpr2
61 ScConditionMode meMode
;
63 // Make sure the grammar is initialized for API calls.
64 ScCondFormatEntryItem();
67 class ScTableConditionalFormat final
: public cppu::WeakImplHelper
<
68 css::sheet::XSheetConditionalEntries
,
69 css::container::XNameAccess
,
70 css::container::XEnumerationAccess
,
71 css::lang::XUnoTunnel
,
72 css::lang::XServiceInfo
>
75 std::vector
<rtl::Reference
<ScTableConditionalEntry
>> maEntries
;
77 ScTableConditionalEntry
* GetObjectByIndex_Impl(sal_uInt16 nIndex
) const;
78 void AddEntry_Impl(const ScCondFormatEntryItem
& aEntry
);
80 ScTableConditionalFormat() = delete;
81 ScTableConditionalFormat(const ScDocument
* pDoc
, sal_uLong nKey
,
82 SCTAB nTab
, formula::FormulaGrammar::Grammar eGrammar
);
83 virtual ~ScTableConditionalFormat() override
;
85 void FillFormat( ScConditionalFormat
& rFormat
, ScDocument
& rDoc
,
86 formula::FormulaGrammar::Grammar eGrammar
) const;
88 // XSheetConditionalEntries
89 virtual void SAL_CALL
addNew( const css::uno::Sequence
< css::beans::PropertyValue
>& aConditionalEntry
) override
;
90 virtual void SAL_CALL
removeByIndex( sal_Int32 nIndex
) override
;
91 virtual void SAL_CALL
clear() override
;
94 virtual sal_Int32 SAL_CALL
getCount() override
;
95 virtual css::uno::Any SAL_CALL
getByIndex( sal_Int32 Index
) override
;
98 virtual css::uno::Any SAL_CALL
getByName( const OUString
& aName
) override
;
99 virtual css::uno::Sequence
< OUString
> SAL_CALL
getElementNames() override
;
100 virtual sal_Bool SAL_CALL
hasByName( const OUString
& aName
) override
;
102 // XEnumerationAccess
103 virtual css::uno::Reference
< css::container::XEnumeration
> SAL_CALL
104 createEnumeration() override
;
107 virtual css::uno::Type SAL_CALL
getElementType() override
;
108 virtual sal_Bool SAL_CALL
hasElements() override
;
111 UNO3_GETIMPLEMENTATION_DECL(ScTableConditionalFormat
)
114 virtual OUString SAL_CALL
getImplementationName() override
;
115 virtual sal_Bool SAL_CALL
supportsService( const OUString
& ServiceName
) override
;
116 virtual css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames() override
;
119 class ScTableConditionalEntry final
: public cppu::WeakImplHelper
<
120 css::sheet::XSheetCondition2
,
121 css::sheet::XSheetConditionalEntry
,
122 css::lang::XServiceInfo
>
125 ScCondFormatEntryItem aData
;
128 ScTableConditionalEntry() = delete;
129 ScTableConditionalEntry(ScCondFormatEntryItem aItem
);
130 virtual ~ScTableConditionalEntry() override
;
132 void GetData(ScCondFormatEntryItem
& rData
) const;
135 virtual css::sheet::ConditionOperator SAL_CALL
getOperator() override
;
136 virtual sal_Int32 SAL_CALL
getConditionOperator() override
;
137 virtual void SAL_CALL
setOperator( css::sheet::ConditionOperator nOperator
) override
;
138 virtual void SAL_CALL
setConditionOperator( sal_Int32 nOperator
) override
;
139 virtual OUString SAL_CALL
getFormula1() override
;
140 virtual void SAL_CALL
setFormula1( const OUString
& aFormula1
) override
;
141 virtual OUString SAL_CALL
getFormula2() override
;
142 virtual void SAL_CALL
setFormula2( const OUString
& aFormula2
) override
;
143 virtual css::table::CellAddress SAL_CALL
getSourcePosition() override
;
144 virtual void SAL_CALL
setSourcePosition( const css::table::CellAddress
& aSourcePosition
) override
;
146 // XSheetConditionalEntry
147 virtual OUString SAL_CALL
getStyleName() override
;
148 virtual void SAL_CALL
setStyleName( const OUString
& aStyleName
) override
;
151 virtual OUString SAL_CALL
getImplementationName() override
;
152 virtual sal_Bool SAL_CALL
supportsService( const OUString
& ServiceName
) override
;
153 virtual css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames() override
;
156 class ScTableValidationObj final
: public cppu::WeakImplHelper
<
157 css::sheet::XSheetCondition2
,
158 css::sheet::XMultiFormulaTokens
,
159 css::beans::XPropertySet
,
160 css::lang::XUnoTunnel
,
161 css::lang::XServiceInfo
>
164 SfxItemPropertySet aPropSet
;
165 ScConditionMode nMode
;
168 OUString maExprNmsp1
;
169 OUString maExprNmsp2
;
170 formula::FormulaGrammar::Grammar meGrammar1
; // grammar used with aExpr1 and aExpr2
171 formula::FormulaGrammar::Grammar meGrammar2
; // grammar used with aExpr1 and aExpr2
172 css::uno::Sequence
< css::sheet::FormulaToken
> aTokens1
;
173 css::uno::Sequence
< css::sheet::FormulaToken
> aTokens2
;
175 OUString aPosString
; // formula position as text
176 sal_uInt16 nValMode
; // enum ScValidationMode
180 OUString aInputTitle
;
181 OUString aInputMessage
;
183 sal_uInt16 nErrorStyle
; // enum ScValidErrorStyle
184 OUString aErrorTitle
;
185 OUString aErrorMessage
;
187 void ClearData_Impl();
191 ScTableValidationObj() = delete;
192 ScTableValidationObj(const ScDocument
& rDoc
, sal_uInt32 nKey
,
193 const formula::FormulaGrammar::Grammar eGrammar
);
194 virtual ~ScTableValidationObj() override
;
196 ScValidationData
* CreateValidationData( ScDocument
& rDoc
,
197 formula::FormulaGrammar::Grammar eGrammar
) const;
200 virtual css::sheet::ConditionOperator SAL_CALL
getOperator() override
;
201 virtual sal_Int32 SAL_CALL
getConditionOperator() override
;
202 virtual void SAL_CALL
setOperator( css::sheet::ConditionOperator nOperator
) override
;
203 virtual void SAL_CALL
setConditionOperator( sal_Int32 nOperator
) override
;
204 virtual OUString SAL_CALL
getFormula1() override
;
205 virtual void SAL_CALL
setFormula1( const OUString
& aFormula1
) override
;
206 virtual OUString SAL_CALL
getFormula2() override
;
207 virtual void SAL_CALL
setFormula2( const OUString
& aFormula2
) override
;
208 virtual css::table::CellAddress SAL_CALL
getSourcePosition() override
;
209 virtual void SAL_CALL
setSourcePosition( const css::table::CellAddress
& aSourcePosition
) override
;
211 // XMultiFormulaTokens
212 virtual css::uno::Sequence
< css::sheet::FormulaToken
>
213 SAL_CALL
getTokens( sal_Int32 nIndex
) override
;
214 virtual void SAL_CALL
setTokens( sal_Int32 nIndex
,
215 const css::uno::Sequence
< css::sheet::FormulaToken
>& aTokens
) override
;
216 virtual sal_Int32 SAL_CALL
getCount() override
;
219 virtual css::uno::Reference
< css::beans::XPropertySetInfo
>
220 SAL_CALL
getPropertySetInfo() override
;
221 virtual void SAL_CALL
setPropertyValue( const OUString
& aPropertyName
,
222 const css::uno::Any
& aValue
) override
;
223 virtual css::uno::Any SAL_CALL
getPropertyValue(
224 const OUString
& PropertyName
) override
;
225 virtual void SAL_CALL
addPropertyChangeListener( const OUString
& aPropertyName
,
226 const css::uno::Reference
< css::beans::XPropertyChangeListener
>& xListener
) override
;
227 virtual void SAL_CALL
removePropertyChangeListener( const OUString
& aPropertyName
,
228 const css::uno::Reference
< css::beans::XPropertyChangeListener
>& aListener
) override
;
229 virtual void SAL_CALL
addVetoableChangeListener( const OUString
& PropertyName
,
230 const css::uno::Reference
< css::beans::XVetoableChangeListener
>& aListener
) override
;
231 virtual void SAL_CALL
removeVetoableChangeListener( const OUString
& PropertyName
,
232 const css::uno::Reference
< css::beans::XVetoableChangeListener
>& aListener
) override
;
235 UNO3_GETIMPLEMENTATION_DECL(ScTableValidationObj
)
238 virtual OUString SAL_CALL
getImplementationName() override
;
239 virtual sal_Bool SAL_CALL
supportsService( const OUString
& ServiceName
) override
;
240 virtual css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames() override
;
243 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */