xref: /trunk/main/sc/inc/nameuno.hxx (revision 9d37da743abb7db0a497688391f6e55a19f27c44)
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_NAMEUNO_HXX
25 #define SC_NAMEUNO_HXX
26 
27 #include <svl/lstner.hxx>
28 #include "address.hxx"
29 #include "formula/grammar.hxx"
30 #include <com/sun/star/sheet/XLabelRange.hpp>
31 #include <com/sun/star/sheet/XLabelRanges.hpp>
32 #include <com/sun/star/sheet/XCellRangeReferrer.hpp>
33 #include <com/sun/star/sheet/XNamedRange2.hpp>
34 #include <com/sun/star/sheet/XFormulaTokens.hpp>
35 #include <com/sun/star/sheet/XNamedRanges2.hpp>
36 #include <com/sun/star/container/XEnumerationAccess.hpp>
37 #include <com/sun/star/sheet/RangeScopeName.hpp>
38 #include <com/sun/star/lang/XServiceName.hpp>
39 #include <com/sun/star/lang/XServiceInfo.hpp>
40 #include <com/sun/star/lang/XUnoTunnel.hpp>
41 #include <com/sun/star/beans/XPropertySet.hpp>
42 #include <com/sun/star/document/XActionLockable.hpp>
43 #include <cppuhelper/implbase2.hxx>
44 #include <cppuhelper/implbase3.hxx>
45 #include <cppuhelper/implbase5.hxx>
46 #include <cppuhelper/implbase6.hxx>
47 
48 #include <global.hxx> //for EMPTY_STRING
49 
50 class ScDocShell;
51 class ScRangeData;
52 class ScTokenArray;
53 
54 
55 class ScNamedRangeObj : public ::cppu::WeakImplHelper6<
56                             ::com::sun::star::sheet::XNamedRange2,
57                             ::com::sun::star::sheet::XFormulaTokens,
58                             ::com::sun::star::sheet::XCellRangeReferrer,
59                             ::com::sun::star::beans::XPropertySet,
60                             ::com::sun::star::lang::XUnoTunnel,
61                             ::com::sun::star::lang::XServiceInfo >,
62                         public SfxListener
63 {
64 private:
65     ScDocShell*             pDocShell;
66     String                  aName;
67     String                  aScopeName;
68 
69 private:
70     ScRangeData*            GetRangeData_Impl();
71     void                    Modify_Impl( const String* pNewName,
72                                         const ScTokenArray* pNewTokens, const String* pNewContent,
73                                         const ScAddress* pNewPos, const sal_uInt16* pNewType,
74                                         const formula::FormulaGrammar::Grammar eGrammar, const String* pNewScopeName = NULL );
75 
76 public:
77                             ScNamedRangeObj(ScDocShell* pDocSh, const String& rNm, const String& rScopeName = EMPTY_STRING);
78     virtual                 ~ScNamedRangeObj();
79 
80     virtual void            Notify( SfxBroadcaster& rBC, const SfxHint& rHint );
81 
82                             // XNamedRange
83     virtual ::rtl::OUString SAL_CALL getContent();
84     virtual void SAL_CALL   setContent( const ::rtl::OUString& aContent );
85     virtual ::com::sun::star::table::CellAddress SAL_CALL getReferencePosition();
86     virtual void SAL_CALL   setReferencePosition(
87                                 const ::com::sun::star::table::CellAddress& aReferencePosition );
88     virtual sal_Int32       SAL_CALL getType();
89     virtual void SAL_CALL   setType( sal_Int32 nType );
90     virtual ::rtl::OUString SAL_CALL getScopeName();
91     virtual void SAL_CALL   setScopeAndRangeName( const ::rtl::OUString& aScopeName, const ::rtl::OUString& aRangeName );
92 
93                             // XFormulaTokens
94     virtual ::com::sun::star::uno::Sequence< ::com::sun::star::sheet::FormulaToken > SAL_CALL getTokens();
95     virtual void SAL_CALL   setTokens( const ::com::sun::star::uno::Sequence<
96                                     ::com::sun::star::sheet::FormulaToken >& aTokens );
97 
98                             // XNamed
99     virtual ::rtl::OUString SAL_CALL getName();
100     virtual void SAL_CALL   setName( const ::rtl::OUString& aName );
101 
102                             // XCellRangeReferrer
103     virtual ::com::sun::star::uno::Reference< ::com::sun::star::table::XCellRange > SAL_CALL
104                             getReferredCells();
105 
106                             // XPropertySet
107     virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo >
108                             SAL_CALL getPropertySetInfo();
109     virtual void SAL_CALL   setPropertyValue( const ::rtl::OUString& aPropertyName,
110                                     const ::com::sun::star::uno::Any& aValue );
111     virtual ::com::sun::star::uno::Any SAL_CALL getPropertyValue(
112                                     const ::rtl::OUString& PropertyName );
113     virtual void SAL_CALL   addPropertyChangeListener( const ::rtl::OUString& aPropertyName,
114                                     const ::com::sun::star::uno::Reference<
115                                         ::com::sun::star::beans::XPropertyChangeListener >& xListener );
116     virtual void SAL_CALL   removePropertyChangeListener( const ::rtl::OUString& aPropertyName,
117                                     const ::com::sun::star::uno::Reference<
118                                         ::com::sun::star::beans::XPropertyChangeListener >& aListener );
119     virtual void SAL_CALL   addVetoableChangeListener( const ::rtl::OUString& PropertyName,
120                                     const ::com::sun::star::uno::Reference<
121                                         ::com::sun::star::beans::XVetoableChangeListener >& aListener );
122     virtual void SAL_CALL   removeVetoableChangeListener( const ::rtl::OUString& PropertyName,
123                                     const ::com::sun::star::uno::Reference<
124                                         ::com::sun::star::beans::XVetoableChangeListener >& aListener );
125 
126                             // XUnoTunnel
127     virtual sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence<
128                                     sal_Int8 >& aIdentifier );
129 
130     static const com::sun::star::uno::Sequence<sal_Int8>& getUnoTunnelId();
131     static ScNamedRangeObj* getImplementation( const com::sun::star::uno::Reference<
132                                     com::sun::star::uno::XInterface> xObj );
133 
134                             // XServiceInfo
135     virtual ::rtl::OUString SAL_CALL getImplementationName();
136     virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName );
137     virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames();
138 
139                             // methods accessible via getImplementation()
140             void            SetContentWithGrammar( const ::rtl::OUString& aContent,
141                                     const formula::FormulaGrammar::Grammar eGrammar );
142 };
143 
144 
145 class ScNamedRangesObj : public ::cppu::WeakImplHelper5<
146                             ::com::sun::star::sheet::XNamedRanges2,
147                             ::com::sun::star::container::XEnumerationAccess,
148                             ::com::sun::star::container::XIndexAccess,
149                             ::com::sun::star::document::XActionLockable,
150                             ::com::sun::star::lang::XServiceInfo >,
151                         public SfxListener
152 {
153 private:
154     ScDocShell*             pDocShell;
155 
156     ScNamedRangeObj*        GetObjectByIndex_Impl(sal_uInt16 nIndex);
157     ScNamedRangeObj*        GetObjectByName_Impl(const ::rtl::OUString& aName);
158     ScNamedRangeObj*        GetObjectByScopeName_Impl(const ::rtl::OUString& aScopeName, const ::rtl::OUString& aRangeName);
159 
160     void ImplAddNewByScopeAndName(SCTAB aScope,const ::rtl::OUString& aRangeName, const ::rtl::OUString& aContent,
161                                 const ::com::sun::star::table::CellAddress& aPosition, sal_Int32 nType);
162 
163     void ImplRemoveByScopeAndName(SCTAB aScope,const ::rtl::OUString& aRangeName);
164 
165 protected:
166     /** called from the XActionLockable interface methods on initial locking */
167     virtual void            lock();
168 
169     /** called from the XActionLockable interface methods on final unlock */
170     virtual void            unlock();
171 
172 public:
173                             ScNamedRangesObj(ScDocShell* pDocSh);
174     virtual                 ~ScNamedRangesObj();
175 
176     virtual void            Notify( SfxBroadcaster& rBC, const SfxHint& rHint );
177 
178                             // XNamedRanges
179     virtual void SAL_CALL   addNewByName( const ::rtl::OUString& aName, const ::rtl::OUString& aContent,
180                                 const ::com::sun::star::table::CellAddress& aPosition, sal_Int32 nType );
181 
182     virtual void SAL_CALL   addNewByScopeName( const ::rtl::OUString& aScopeName,const ::rtl::OUString& aRangeName, const ::rtl::OUString& aContent,
183                                 const ::com::sun::star::table::CellAddress& aPosition, sal_Int32 nType );
184     virtual void SAL_CALL   addNewFromTitles( const ::com::sun::star::table::CellRangeAddress& aSource,
185                                 ::com::sun::star::sheet::Border aBorder );
186     virtual void SAL_CALL   removeByName( const ::rtl::OUString& aName );
187     virtual void SAL_CALL   removeByScopeName( const ::rtl::OUString& aScopeName, const ::rtl::OUString& aRangeName );
188     virtual void SAL_CALL   outputList( const ::com::sun::star::table::CellAddress& aOutputPosition );
189     virtual sal_Bool SAL_CALL hasByScopeName( const ::rtl::OUString& aScopeName, const ::rtl::OUString& aRangeName );
190     virtual ::com::sun::star::uno::Sequence< ::com::sun::star::sheet::RangeScopeName > SAL_CALL getElementScopeNames();
191     virtual ::com::sun::star::uno::Any SAL_CALL getByScopeName( const ::rtl::OUString& aScopeName, const ::rtl::OUString& aRangeName );
192 
193                             // XNameAccess
194     virtual ::com::sun::star::uno::Any SAL_CALL getByName( const ::rtl::OUString& aName );
195     virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getElementNames();
196     virtual sal_Bool SAL_CALL hasByName( const ::rtl::OUString& aName );
197 
198                             // XIndexAccess
199     virtual sal_Int32 SAL_CALL getCount();
200     virtual ::com::sun::star::uno::Any SAL_CALL getByIndex( sal_Int32 Index );
201 
202                             // XEnumerationAccess
203     virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XEnumeration > SAL_CALL
204                             createEnumeration();
205 
206                             // XElementAccess
207     virtual ::com::sun::star::uno::Type SAL_CALL getElementType();
208     virtual sal_Bool SAL_CALL hasElements();
209 
210                             // XActionLockable
211     virtual sal_Bool SAL_CALL isActionLocked();
212     virtual void SAL_CALL addActionLock();
213     virtual void SAL_CALL removeActionLock();
214     virtual void SAL_CALL setActionLocks( sal_Int16 nLock );
215     virtual sal_Int16 SAL_CALL resetActionLocks();
216 
217                             // XServiceInfo
218     virtual ::rtl::OUString SAL_CALL getImplementationName();
219     virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName );
220     virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames();
221 };
222 
223 
224 class ScLabelRangeObj : public ::cppu::WeakImplHelper2<
225                             ::com::sun::star::sheet::XLabelRange,
226                             ::com::sun::star::lang::XServiceInfo >,
227                         public SfxListener
228 {
229 private:
230     ScDocShell*             pDocShell;
231     sal_Bool                bColumn;
232     ScRange                 aRange;         // Kriterium um Bereich zu finden
233 
234 private:
235     ScRangePair*            GetData_Impl();
236     void                    Modify_Impl( const ScRange* pLabel, const ScRange* pData );
237 
238 public:
239                             ScLabelRangeObj(ScDocShell* pDocSh, sal_Bool bCol, const ScRange& rR);
240     virtual                 ~ScLabelRangeObj();
241 
242     virtual void            Notify( SfxBroadcaster& rBC, const SfxHint& rHint );
243 
244                             // XLabelRange
245     virtual ::com::sun::star::table::CellRangeAddress SAL_CALL getLabelArea();
246     virtual void SAL_CALL   setLabelArea( const ::com::sun::star::table::CellRangeAddress& aLabelArea );
247     virtual ::com::sun::star::table::CellRangeAddress SAL_CALL getDataArea();
248     virtual void SAL_CALL   setDataArea( const ::com::sun::star::table::CellRangeAddress& aDataArea );
249 
250                             // XServiceInfo
251     virtual ::rtl::OUString SAL_CALL getImplementationName();
252     virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName );
253     virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames();
254 };
255 
256 
257 class ScLabelRangesObj : public ::cppu::WeakImplHelper3<
258                             ::com::sun::star::sheet::XLabelRanges,
259                             ::com::sun::star::container::XEnumerationAccess,
260                             ::com::sun::star::lang::XServiceInfo >,
261                         public SfxListener
262 {
263 private:
264     ScDocShell*             pDocShell;
265     sal_Bool                    bColumn;
266 
267     ScLabelRangeObj*        GetObjectByIndex_Impl(sal_uInt16 nIndex);
268 
269 public:
270                             ScLabelRangesObj(ScDocShell* pDocSh, sal_Bool bCol);
271     virtual                 ~ScLabelRangesObj();
272 
273     virtual void            Notify( SfxBroadcaster& rBC, const SfxHint& rHint );
274 
275                             // XLabelRanges
276     virtual void SAL_CALL   addNew( const ::com::sun::star::table::CellRangeAddress& aLabelArea,
277                                 const ::com::sun::star::table::CellRangeAddress& aDataArea );
278     virtual void SAL_CALL   removeByIndex( sal_Int32 nIndex );
279 
280                             // XIndexAccess
281     virtual sal_Int32 SAL_CALL getCount();
282     virtual ::com::sun::star::uno::Any SAL_CALL getByIndex( sal_Int32 Index );
283 
284                             // XEnumerationAccess
285     virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XEnumeration > SAL_CALL
286                             createEnumeration();
287 
288                             // XElementAccess
289     virtual ::com::sun::star::uno::Type SAL_CALL getElementType();
290     virtual sal_Bool SAL_CALL hasElements();
291 
292                             // XServiceInfo
293     virtual ::rtl::OUString SAL_CALL getImplementationName();
294     virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName );
295     virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames();
296 };
297 
298 
299 
300 
301 #endif
302