xref: /trunk/main/sc/inc/fmtuno.hxx (revision 91144cd0085a7583d2099b982122deb2184ab956)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef SC_FMTUNO_HXX
25 #define SC_FMTUNO_HXX
26 
27 #include "address.hxx"
28 #include "conditio.hxx"
29 #include <formula/grammar.hxx>
30 #include <tools/list.hxx>
31 #include <svl/itemprop.hxx>
32 #include <com/sun/star/sheet/XSheetConditionalEntries.hpp>
33 #include <com/sun/star/sheet/XSheetCondition.hpp>
34 #include <com/sun/star/sheet/XSheetConditionalEntry.hpp>
35 #include <com/sun/star/lang/XServiceInfo.hpp>
36 #include <com/sun/star/container/XNameAccess.hpp>
37 #include <com/sun/star/container/XEnumerationAccess.hpp>
38 #include <com/sun/star/lang/XUnoTunnel.hpp>
39 #include <com/sun/star/beans/XPropertySet.hpp>
40 
41 #include <com/sun/star/sheet/XMultiFormulaTokens.hpp>
42 #include <com/sun/star/sheet/FormulaToken.hpp>
43 #include <cppuhelper/implbase3.hxx>
44 #include <cppuhelper/implbase4.hxx>
45 #include <cppuhelper/implbase5.hxx>
46 
47 
48 class ScDocument;
49 class ScTableConditionalEntry;
50 class ScConditionalFormat;
51 class ScValidationData;
52 
53 
54 struct ScCondFormatEntryItem
55 {
56     ::com::sun::star::uno::Sequence< ::com::sun::star::sheet::FormulaToken > maTokens1;
57     ::com::sun::star::uno::Sequence< ::com::sun::star::sheet::FormulaToken > maTokens2;
58     String              maExpr1;
59     String              maExpr2;
60     String              maExprNmsp1;
61     String              maExprNmsp2;
62     String              maPosStr;  // formula position as text
63     String              maStyle;   // display name as stored in ScStyleSheet
64     ScAddress           maPos;
65     formula::FormulaGrammar::Grammar meGrammar1; // grammar used with maExpr1
66     formula::FormulaGrammar::Grammar meGrammar2; // grammar used with maExpr2
67     ScConditionMode     meMode;
68 
69     // Make sure the grammar is initialized for API calls.
70     ScCondFormatEntryItem();
71 };
72 
73 class ScTableConditionalFormat : public cppu::WeakImplHelper5<
74                             com::sun::star::sheet::XSheetConditionalEntries,
75                             com::sun::star::container::XNameAccess,
76                             com::sun::star::container::XEnumerationAccess,
77                             com::sun::star::lang::XUnoTunnel,
78                             com::sun::star::lang::XServiceInfo >
79 {
80 private:
81     List    aEntries;
82 
83     ScTableConditionalEntry*    GetObjectByIndex_Impl(sal_uInt16 nIndex) const;
84     void                        AddEntry_Impl(const ScCondFormatEntryItem& aEntry);
85 
86     ScTableConditionalFormat(); // disable
87 public:
88                             ScTableConditionalFormat(ScDocument* pDoc, sal_uLong nKey,
89                                 formula::FormulaGrammar::Grammar eGrammar);
90     virtual                 ~ScTableConditionalFormat();
91 
92     void                    FillFormat( ScConditionalFormat& rFormat, ScDocument* pDoc,
93                                 formula::FormulaGrammar::Grammar eGrammar) const;
94 
95                             // XSheetConditionalEntries
96     virtual void SAL_CALL   addNew( const ::com::sun::star::uno::Sequence<
97                                     ::com::sun::star::beans::PropertyValue >& aConditionalEntry );
98     virtual void SAL_CALL   removeByIndex( sal_Int32 nIndex );
99     virtual void SAL_CALL   clear();
100 
101                             // XIndexAccess
102     virtual sal_Int32 SAL_CALL getCount();
103     virtual ::com::sun::star::uno::Any SAL_CALL getByIndex( sal_Int32 Index );
104 
105                             // XNameAccess
106     virtual ::com::sun::star::uno::Any SAL_CALL getByName( const ::rtl::OUString& aName );
107     virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getElementNames();
108     virtual sal_Bool SAL_CALL hasByName( const ::rtl::OUString& aName );
109 
110                             // XEnumerationAccess
111     virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XEnumeration > SAL_CALL
112                             createEnumeration();
113 
114                             // XElementAccess
115     virtual ::com::sun::star::uno::Type SAL_CALL getElementType();
116     virtual sal_Bool SAL_CALL hasElements();
117 
118                             // XUnoTunnel
119     virtual sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence<
120                                     sal_Int8 >& aIdentifier );
121 
122     static const com::sun::star::uno::Sequence<sal_Int8>& getUnoTunnelId();
123     static ScTableConditionalFormat* getImplementation( const com::sun::star::uno::Reference<
124                                     com::sun::star::sheet::XSheetConditionalEntries> xObj );
125 
126                             // XServiceInfo
127     virtual ::rtl::OUString SAL_CALL getImplementationName();
128     virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName );
129     virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames();
130 };
131 
132 
133 
134 class ScTableConditionalEntry : public cppu::WeakImplHelper3<
135                             com::sun::star::sheet::XSheetCondition,
136                             com::sun::star::sheet::XSheetConditionalEntry,
137                             com::sun::star::lang::XServiceInfo >
138 {
139 private:
140     ScCondFormatEntryItem       aData;
141 
142     ScTableConditionalEntry(); // disabled
143 public:
144                             ScTableConditionalEntry(const ScCondFormatEntryItem& aItem);
145     virtual                 ~ScTableConditionalEntry();
146 
147     void                    GetData(ScCondFormatEntryItem& rData) const;
148 
149                             // XSheetCondition
150     virtual ::com::sun::star::sheet::ConditionOperator SAL_CALL getOperator();
151     virtual void SAL_CALL   setOperator( ::com::sun::star::sheet::ConditionOperator nOperator );
152     virtual ::rtl::OUString SAL_CALL getFormula1();
153     virtual void SAL_CALL   setFormula1( const ::rtl::OUString& aFormula1 );
154     virtual ::rtl::OUString SAL_CALL getFormula2();
155     virtual void SAL_CALL   setFormula2( const ::rtl::OUString& aFormula2 );
156     virtual ::com::sun::star::table::CellAddress SAL_CALL getSourcePosition();
157     virtual void SAL_CALL setSourcePosition( const ::com::sun::star::table::CellAddress& aSourcePosition );
158 
159                             // XSheetConditionalEntry
160     virtual ::rtl::OUString SAL_CALL getStyleName();
161     virtual void SAL_CALL   setStyleName( const ::rtl::OUString& aStyleName );
162 
163                             // XServiceInfo
164     virtual ::rtl::OUString SAL_CALL getImplementationName();
165     virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName );
166     virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames();
167 };
168 
169 
170 
171 class ScTableValidationObj : public cppu::WeakImplHelper5<
172                             com::sun::star::sheet::XSheetCondition,
173                             com::sun::star::sheet::XMultiFormulaTokens,
174                             com::sun::star::beans::XPropertySet,
175                             com::sun::star::lang::XUnoTunnel,
176                             com::sun::star::lang::XServiceInfo >
177 {
178 private:
179     SfxItemPropertySet  aPropSet;
180     sal_uInt16              nMode;          // enum ScConditionMode
181     String              aExpr1;
182     String              aExpr2;
183     String              maExprNmsp1;
184     String              maExprNmsp2;
185     formula::FormulaGrammar::Grammar  meGrammar1;      // grammar used with aExpr1 and aExpr2
186     formula::FormulaGrammar::Grammar  meGrammar2;      // grammar used with aExpr1 and aExpr2
187     ::com::sun::star::uno::Sequence< ::com::sun::star::sheet::FormulaToken > aTokens1;
188     ::com::sun::star::uno::Sequence< ::com::sun::star::sheet::FormulaToken > aTokens2;
189     ScAddress           aSrcPos;
190     String              aPosString;     // formula position as text
191     sal_uInt16              nValMode;       // enum ScValidationMode
192     sal_Bool                bIgnoreBlank;
193     sal_Int16           nShowList;
194     sal_Bool                bShowInput;
195     String              aInputTitle;
196     String              aInputMessage;
197     sal_Bool                bShowError;
198     sal_uInt16              nErrorStyle;    // enum ScValidErrorStyle
199     String              aErrorTitle;
200     String              aErrorMessage;
201 
202     void                    ClearData_Impl();
203 
204     ScTableValidationObj(); // disabled
205 public:
206                             ScTableValidationObj(ScDocument* pDoc, sal_uLong nKey,
207                                                 const formula::FormulaGrammar::Grammar eGrammar);
208     virtual                 ~ScTableValidationObj();
209 
210     ScValidationData*       CreateValidationData( ScDocument* pDoc,
211                                                 formula::FormulaGrammar::Grammar eGrammar ) const;
212 
213                             // XSheetCondition
214     virtual ::com::sun::star::sheet::ConditionOperator SAL_CALL getOperator();
215     virtual void SAL_CALL   setOperator( ::com::sun::star::sheet::ConditionOperator nOperator );
216     virtual ::rtl::OUString SAL_CALL getFormula1();
217     virtual void SAL_CALL   setFormula1( const ::rtl::OUString& aFormula1 );
218     virtual ::rtl::OUString SAL_CALL getFormula2();
219     virtual void SAL_CALL   setFormula2( const ::rtl::OUString& aFormula2 );
220     virtual ::com::sun::star::table::CellAddress SAL_CALL getSourcePosition();
221     virtual void SAL_CALL setSourcePosition( const ::com::sun::star::table::CellAddress& aSourcePosition );
222 
223                             // XMultiFormulaTokens
224     virtual ::com::sun::star::uno::Sequence< ::com::sun::star::sheet::FormulaToken >
225                             SAL_CALL getTokens( sal_Int32 nIndex );
226     virtual void SAL_CALL setTokens( sal_Int32 nIndex,
227                                      const ::com::sun::star::uno::Sequence< ::com::sun::star::sheet::FormulaToken >& aTokens );
228     virtual sal_Int32 SAL_CALL getCount();
229 
230                             // XPropertySet
231     virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo >
232                             SAL_CALL getPropertySetInfo();
233     virtual void SAL_CALL   setPropertyValue( const ::rtl::OUString& aPropertyName,
234                                     const ::com::sun::star::uno::Any& aValue );
235     virtual ::com::sun::star::uno::Any SAL_CALL getPropertyValue(
236                                     const ::rtl::OUString& PropertyName );
237     virtual void SAL_CALL   addPropertyChangeListener( const ::rtl::OUString& aPropertyName,
238                                     const ::com::sun::star::uno::Reference<
239                                         ::com::sun::star::beans::XPropertyChangeListener >& xListener );
240     virtual void SAL_CALL   removePropertyChangeListener( const ::rtl::OUString& aPropertyName,
241                                     const ::com::sun::star::uno::Reference<
242                                         ::com::sun::star::beans::XPropertyChangeListener >& aListener );
243     virtual void SAL_CALL   addVetoableChangeListener( const ::rtl::OUString& PropertyName,
244                                     const ::com::sun::star::uno::Reference<
245                                         ::com::sun::star::beans::XVetoableChangeListener >& aListener );
246     virtual void SAL_CALL   removeVetoableChangeListener( const ::rtl::OUString& PropertyName,
247                                     const ::com::sun::star::uno::Reference<
248                                         ::com::sun::star::beans::XVetoableChangeListener >& aListener );
249 
250                             // XUnoTunnel
251     virtual sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence<
252                                     sal_Int8 >& aIdentifier );
253 
254     static const com::sun::star::uno::Sequence<sal_Int8>& getUnoTunnelId();
255     static ScTableValidationObj* getImplementation( const com::sun::star::uno::Reference<
256                                     com::sun::star::beans::XPropertySet> xObj );
257 
258                             // XServiceInfo
259     virtual ::rtl::OUString SAL_CALL getImplementationName();
260     virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName );
261     virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames();
262 };
263 
264 
265 #endif
266