Line data Source code
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 : #ifndef INCLUDED_SC_INC_FMTUNO_HXX
21 : #define INCLUDED_SC_INC_FMTUNO_HXX
22 :
23 : #include <vector>
24 :
25 : #include <formula/grammar.hxx>
26 : #include <svl/itemprop.hxx>
27 : #include <com/sun/star/sheet/XSheetConditionalEntries.hpp>
28 : #include <com/sun/star/sheet/XSheetCondition.hpp>
29 : #include <com/sun/star/sheet/XSheetCondition2.hpp>
30 : #include <com/sun/star/sheet/XSheetConditionalEntry.hpp>
31 : #include <com/sun/star/lang/XServiceInfo.hpp>
32 : #include <com/sun/star/container/XNameAccess.hpp>
33 : #include <com/sun/star/container/XEnumerationAccess.hpp>
34 : #include <com/sun/star/lang/XUnoTunnel.hpp>
35 : #include <com/sun/star/beans/XPropertySet.hpp>
36 :
37 : #include <com/sun/star/sheet/XMultiFormulaTokens.hpp>
38 : #include <com/sun/star/sheet/FormulaToken.hpp>
39 : #include <cppuhelper/implbase3.hxx>
40 : #include <cppuhelper/implbase4.hxx>
41 : #include <cppuhelper/implbase5.hxx>
42 : #include <com/sun/star/sheet/ConditionOperator2.hpp>
43 :
44 : #include "address.hxx"
45 : #include "conditio.hxx"
46 :
47 : class ScDocument;
48 : class ScTableConditionalEntry;
49 : class ScConditionalFormat;
50 : class ScValidationData;
51 :
52 186 : struct ScCondFormatEntryItem
53 : {
54 : css::uno::Sequence< css::sheet::FormulaToken > maTokens1;
55 : css::uno::Sequence< css::sheet::FormulaToken > maTokens2;
56 : OUString maExpr1;
57 : OUString maExpr2;
58 : OUString maExprNmsp1;
59 : OUString maExprNmsp2;
60 : OUString maPosStr; // formula position as text
61 : OUString maStyle; // display name as stored in ScStyleSheet
62 : ScAddress maPos;
63 : formula::FormulaGrammar::Grammar meGrammar1; // grammar used with maExpr1
64 : formula::FormulaGrammar::Grammar meGrammar2; // grammar used with maExpr2
65 : ScConditionMode meMode;
66 :
67 : // Make sure the grammar is initialized for API calls.
68 : ScCondFormatEntryItem();
69 : };
70 :
71 : class ScTableConditionalFormat : public cppu::WeakImplHelper5<
72 : com::sun::star::sheet::XSheetConditionalEntries,
73 : com::sun::star::container::XNameAccess,
74 : com::sun::star::container::XEnumerationAccess,
75 : com::sun::star::lang::XUnoTunnel,
76 : com::sun::star::lang::XServiceInfo >
77 : {
78 : private:
79 : std::vector<ScTableConditionalEntry*> aEntries;
80 :
81 : ScTableConditionalEntry* GetObjectByIndex_Impl(sal_uInt16 nIndex) const;
82 : void AddEntry_Impl(const ScCondFormatEntryItem& aEntry);
83 :
84 : ScTableConditionalFormat(); // disable
85 : public:
86 : ScTableConditionalFormat(ScDocument* pDoc, sal_uLong nKey,
87 : SCTAB nTab, formula::FormulaGrammar::Grammar eGrammar);
88 : virtual ~ScTableConditionalFormat();
89 :
90 : void FillFormat( ScConditionalFormat& rFormat, ScDocument* pDoc,
91 : formula::FormulaGrammar::Grammar eGrammar) const;
92 :
93 : // XSheetConditionalEntries
94 : virtual void SAL_CALL addNew( const ::com::sun::star::uno::Sequence<
95 : ::com::sun::star::beans::PropertyValue >& aConditionalEntry )
96 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
97 : virtual void SAL_CALL removeByIndex( sal_Int32 nIndex )
98 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
99 : virtual void SAL_CALL clear() throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
100 :
101 : // XIndexAccess
102 : virtual sal_Int32 SAL_CALL getCount() throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
103 : virtual ::com::sun::star::uno::Any SAL_CALL getByIndex( sal_Int32 Index )
104 : throw(::com::sun::star::lang::IndexOutOfBoundsException,
105 : ::com::sun::star::lang::WrappedTargetException,
106 : ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
107 :
108 : // XNameAccess
109 : virtual ::com::sun::star::uno::Any SAL_CALL getByName( const OUString& aName )
110 : throw(::com::sun::star::container::NoSuchElementException,
111 : ::com::sun::star::lang::WrappedTargetException,
112 : ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
113 : virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL getElementNames()
114 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
115 : virtual sal_Bool SAL_CALL hasByName( const OUString& aName )
116 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
117 :
118 : // XEnumerationAccess
119 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XEnumeration > SAL_CALL
120 : createEnumeration() throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
121 :
122 : // XElementAccess
123 : virtual ::com::sun::star::uno::Type SAL_CALL getElementType()
124 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
125 : virtual sal_Bool SAL_CALL hasElements() throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
126 :
127 : // XUnoTunnel
128 : virtual sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence<
129 : sal_Int8 >& aIdentifier )
130 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
131 :
132 : static const com::sun::star::uno::Sequence<sal_Int8>& getUnoTunnelId();
133 : static ScTableConditionalFormat* getImplementation( const com::sun::star::uno::Reference<
134 : com::sun::star::sheet::XSheetConditionalEntries> xObj );
135 :
136 : // XServiceInfo
137 : virtual OUString SAL_CALL getImplementationName()
138 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
139 : virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName )
140 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
141 : virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames()
142 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
143 : };
144 :
145 : class ScTableConditionalEntry : public cppu::WeakImplHelper3<
146 : com::sun::star::sheet::XSheetCondition2,
147 : com::sun::star::sheet::XSheetConditionalEntry,
148 : com::sun::star::lang::XServiceInfo >
149 : {
150 : private:
151 : ScCondFormatEntryItem aData;
152 :
153 : ScTableConditionalEntry(); // disabled
154 : public:
155 : ScTableConditionalEntry(const ScCondFormatEntryItem& aItem);
156 : virtual ~ScTableConditionalEntry();
157 :
158 : void GetData(ScCondFormatEntryItem& rData) const;
159 :
160 : // XSheetCondition
161 : virtual ::com::sun::star::sheet::ConditionOperator SAL_CALL getOperator()
162 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
163 : virtual sal_Int32 SAL_CALL getConditionOperator()
164 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
165 : virtual void SAL_CALL setOperator( ::com::sun::star::sheet::ConditionOperator nOperator )
166 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
167 : virtual void SAL_CALL setConditionOperator( sal_Int32 nOperator )
168 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
169 : virtual OUString SAL_CALL getFormula1() throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
170 : virtual void SAL_CALL setFormula1( const OUString& aFormula1 )
171 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
172 : virtual OUString SAL_CALL getFormula2() throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
173 : virtual void SAL_CALL setFormula2( const OUString& aFormula2 )
174 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
175 : virtual ::com::sun::star::table::CellAddress SAL_CALL getSourcePosition()
176 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
177 : virtual void SAL_CALL setSourcePosition( const ::com::sun::star::table::CellAddress& aSourcePosition )
178 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
179 :
180 : // XSheetConditionalEntry
181 : virtual OUString SAL_CALL getStyleName() throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
182 : virtual void SAL_CALL setStyleName( const OUString& aStyleName )
183 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
184 :
185 : // XServiceInfo
186 : virtual OUString SAL_CALL getImplementationName()
187 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
188 : virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName )
189 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
190 : virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames()
191 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
192 : };
193 :
194 : class ScTableValidationObj : public cppu::WeakImplHelper5<
195 : com::sun::star::sheet::XSheetCondition2,
196 : com::sun::star::sheet::XMultiFormulaTokens,
197 : com::sun::star::beans::XPropertySet,
198 : com::sun::star::lang::XUnoTunnel,
199 : com::sun::star::lang::XServiceInfo >
200 : {
201 : private:
202 : SfxItemPropertySet aPropSet;
203 : sal_uInt16 nMode; // enum ScConditionMode
204 : OUString aExpr1;
205 : OUString aExpr2;
206 : OUString maExprNmsp1;
207 : OUString maExprNmsp2;
208 : formula::FormulaGrammar::Grammar meGrammar1; // grammar used with aExpr1 and aExpr2
209 : formula::FormulaGrammar::Grammar meGrammar2; // grammar used with aExpr1 and aExpr2
210 : ::com::sun::star::uno::Sequence< ::com::sun::star::sheet::FormulaToken > aTokens1;
211 : ::com::sun::star::uno::Sequence< ::com::sun::star::sheet::FormulaToken > aTokens2;
212 : ScAddress aSrcPos;
213 : OUString aPosString; // formula position as text
214 : sal_uInt16 nValMode; // enum ScValidationMode
215 : bool bIgnoreBlank;
216 : sal_Int16 nShowList;
217 : bool bShowInput;
218 : OUString aInputTitle;
219 : OUString aInputMessage;
220 : bool bShowError;
221 : sal_uInt16 nErrorStyle; // enum ScValidErrorStyle
222 : OUString aErrorTitle;
223 : OUString aErrorMessage;
224 :
225 : void ClearData_Impl();
226 :
227 : ScTableValidationObj(); // disabled
228 : public:
229 : ScTableValidationObj(ScDocument* pDoc, sal_uLong nKey,
230 : const formula::FormulaGrammar::Grammar eGrammar);
231 : virtual ~ScTableValidationObj();
232 :
233 : ScValidationData* CreateValidationData( ScDocument* pDoc,
234 : formula::FormulaGrammar::Grammar eGrammar ) const;
235 :
236 : // XSheetCondition
237 : virtual ::com::sun::star::sheet::ConditionOperator SAL_CALL getOperator()
238 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
239 : virtual sal_Int32 SAL_CALL getConditionOperator()
240 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
241 : virtual void SAL_CALL setOperator( ::com::sun::star::sheet::ConditionOperator nOperator )
242 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
243 : virtual void SAL_CALL setConditionOperator( sal_Int32 nOperator )
244 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
245 : virtual OUString SAL_CALL getFormula1() throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
246 : virtual void SAL_CALL setFormula1( const OUString& aFormula1 )
247 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
248 : virtual OUString SAL_CALL getFormula2() throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
249 : virtual void SAL_CALL setFormula2( const OUString& aFormula2 )
250 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
251 : virtual ::com::sun::star::table::CellAddress SAL_CALL getSourcePosition()
252 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
253 : virtual void SAL_CALL setSourcePosition( const ::com::sun::star::table::CellAddress& aSourcePosition )
254 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
255 :
256 : // XMultiFormulaTokens
257 : virtual ::com::sun::star::uno::Sequence< ::com::sun::star::sheet::FormulaToken >
258 : SAL_CALL getTokens( sal_Int32 nIndex )
259 : throw(::com::sun::star::uno::RuntimeException,::com::sun::star::lang::IndexOutOfBoundsException, std::exception) SAL_OVERRIDE;
260 : virtual void SAL_CALL setTokens( sal_Int32 nIndex,
261 : const ::com::sun::star::uno::Sequence< ::com::sun::star::sheet::FormulaToken >& aTokens )
262 : throw(::com::sun::star::uno::RuntimeException,::com::sun::star::lang::IndexOutOfBoundsException, std::exception) SAL_OVERRIDE;
263 : virtual sal_Int32 SAL_CALL getCount() throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
264 :
265 : // XPropertySet
266 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo >
267 : SAL_CALL getPropertySetInfo()
268 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
269 : virtual void SAL_CALL setPropertyValue( const OUString& aPropertyName,
270 : const ::com::sun::star::uno::Any& aValue )
271 : throw(::com::sun::star::beans::UnknownPropertyException,
272 : ::com::sun::star::beans::PropertyVetoException,
273 : ::com::sun::star::lang::IllegalArgumentException,
274 : ::com::sun::star::lang::WrappedTargetException,
275 : ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
276 : virtual ::com::sun::star::uno::Any SAL_CALL getPropertyValue(
277 : const OUString& PropertyName )
278 : throw(::com::sun::star::beans::UnknownPropertyException,
279 : ::com::sun::star::lang::WrappedTargetException,
280 : ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
281 : virtual void SAL_CALL addPropertyChangeListener( const OUString& aPropertyName,
282 : const ::com::sun::star::uno::Reference<
283 : ::com::sun::star::beans::XPropertyChangeListener >& xListener )
284 : throw(::com::sun::star::beans::UnknownPropertyException,
285 : ::com::sun::star::lang::WrappedTargetException,
286 : ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
287 : virtual void SAL_CALL removePropertyChangeListener( const OUString& aPropertyName,
288 : const ::com::sun::star::uno::Reference<
289 : ::com::sun::star::beans::XPropertyChangeListener >& aListener )
290 : throw(::com::sun::star::beans::UnknownPropertyException,
291 : ::com::sun::star::lang::WrappedTargetException,
292 : ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
293 : virtual void SAL_CALL addVetoableChangeListener( const OUString& PropertyName,
294 : const ::com::sun::star::uno::Reference<
295 : ::com::sun::star::beans::XVetoableChangeListener >& aListener )
296 : throw(::com::sun::star::beans::UnknownPropertyException,
297 : ::com::sun::star::lang::WrappedTargetException,
298 : ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
299 : virtual void SAL_CALL removeVetoableChangeListener( const OUString& PropertyName,
300 : const ::com::sun::star::uno::Reference<
301 : ::com::sun::star::beans::XVetoableChangeListener >& aListener )
302 : throw(::com::sun::star::beans::UnknownPropertyException,
303 : ::com::sun::star::lang::WrappedTargetException,
304 : ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
305 :
306 : // XUnoTunnel
307 : virtual sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence<
308 : sal_Int8 >& aIdentifier )
309 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
310 :
311 : static const com::sun::star::uno::Sequence<sal_Int8>& getUnoTunnelId();
312 : static ScTableValidationObj* getImplementation( const com::sun::star::uno::Reference<
313 : com::sun::star::beans::XPropertySet> xObj );
314 :
315 : // XServiceInfo
316 : virtual OUString SAL_CALL getImplementationName()
317 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
318 : virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName )
319 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
320 : virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames()
321 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
322 : };
323 :
324 : #endif
325 :
326 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|