LibreOffice Module sc (master)  1
nameuno.hxx
Go to the documentation of this file.
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 #pragma once
21 
22 #include <svl/lstner.hxx>
23 #include "address.hxx"
24 #include "rangenam.hxx"
25 #include <formula/grammar.hxx>
26 #include <com/sun/star/sheet/XLabelRange.hpp>
27 #include <com/sun/star/sheet/XLabelRanges.hpp>
28 #include <com/sun/star/sheet/XCellRangeReferrer.hpp>
29 #include <com/sun/star/sheet/XNamedRange.hpp>
30 #include <com/sun/star/sheet/XFormulaTokens.hpp>
31 #include <com/sun/star/sheet/XNamedRanges.hpp>
32 #include <com/sun/star/container/XEnumerationAccess.hpp>
33 #include <com/sun/star/lang/XServiceInfo.hpp>
34 #include <com/sun/star/lang/XUnoTunnel.hpp>
35 #include <com/sun/star/beans/XPropertySet.hpp>
36 #include <com/sun/star/document/XActionLockable.hpp>
37 #include <cppuhelper/implbase.hxx>
38 #include <rtl/ref.hxx>
39 
40 namespace com::sun::star::container { class XNamed; }
41 
42 class ScDocShell;
43 class ScNamedRangesObj;
44 
45 class SC_DLLPUBLIC ScNamedRangeObj final : public ::cppu::WeakImplHelper<
46  css::sheet::XNamedRange,
47  css::sheet::XFormulaTokens,
48  css::sheet::XCellRangeReferrer,
49  css::beans::XPropertySet,
50  css::lang::XUnoTunnel,
51  css::lang::XServiceInfo >,
52  public SfxListener
53 {
54 private:
57  OUString aName;
58  css::uno::Reference< css::container::XNamed > mxSheet;
59 
60 private:
61 friend class ScVbaName;
62  ScRangeData* GetRangeData_Impl();
63  void Modify_Impl( const OUString* pNewName,
64  const ScTokenArray* pNewTokens, const OUString* pNewContent,
65  const ScAddress* pNewPos, const ScRangeData::Type* pNewType,
66  const formula::FormulaGrammar::Grammar eGrammar );
67  SCTAB GetTab_Impl();
68 
69 public:
70  ScNamedRangeObj( rtl::Reference< ScNamedRangesObj > const & xParent, ScDocShell* pDocSh, const OUString& rNm,
71  css::uno::Reference< css::container::XNamed > const & xSheet = css::uno::Reference< css::container::XNamed > ());
72  virtual ~ScNamedRangeObj() override;
73 
74  virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) override;
75 
77  virtual OUString SAL_CALL getContent() override;
78  virtual void SAL_CALL setContent( const OUString& aContent ) override;
79  virtual css::table::CellAddress SAL_CALL getReferencePosition() override;
80  virtual void SAL_CALL setReferencePosition(
81  const css::table::CellAddress& aReferencePosition ) override;
82  virtual sal_Int32 SAL_CALL getType() override;
83  virtual void SAL_CALL setType( sal_Int32 nType ) override;
84 
86  virtual css::uno::Sequence< css::sheet::FormulaToken > SAL_CALL getTokens() override;
87  virtual void SAL_CALL setTokens( const css::uno::Sequence< css::sheet::FormulaToken >& aTokens ) override;
88 
90  virtual OUString SAL_CALL getName() override;
91  virtual void SAL_CALL setName( const OUString& aName ) override;
92 
94  virtual css::uno::Reference< css::table::XCellRange > SAL_CALL
95  getReferredCells() override;
96 
98  virtual css::uno::Reference< css::beans::XPropertySetInfo >
99  SAL_CALL getPropertySetInfo() override;
100  virtual void SAL_CALL setPropertyValue( const OUString& aPropertyName,
101  const css::uno::Any& aValue ) override;
102  virtual css::uno::Any SAL_CALL getPropertyValue( const OUString& PropertyName ) override;
103  virtual void SAL_CALL addPropertyChangeListener( const OUString& aPropertyName,
104  const css::uno::Reference< css::beans::XPropertyChangeListener >& xListener ) override;
105  virtual void SAL_CALL removePropertyChangeListener( const OUString& aPropertyName,
106  const css::uno::Reference< css::beans::XPropertyChangeListener >& aListener ) override;
107  virtual void SAL_CALL addVetoableChangeListener( const OUString& PropertyName,
108  const css::uno::Reference< css::beans::XVetoableChangeListener >& aListener ) override;
109  virtual void SAL_CALL removeVetoableChangeListener( const OUString& PropertyName,
110  const css::uno::Reference< css::beans::XVetoableChangeListener >& aListener ) override;
111 
113  virtual sal_Int64 SAL_CALL getSomething( const css::uno::Sequence< sal_Int8 >& aIdentifier ) override;
114 
115  static const css::uno::Sequence<sal_Int8>& getUnoTunnelId();
116 
118  virtual OUString SAL_CALL getImplementationName() override;
119  virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
120  virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
121 };
122 
123 class ScNamedRangesObj : public ::cppu::WeakImplHelper<
124  css::sheet::XNamedRanges,
125  css::container::XEnumerationAccess,
126  css::container::XIndexAccess,
127  css::beans::XPropertySet,
128  css::document::XActionLockable,
129  css::lang::XServiceInfo >,
130  public SfxListener
131 {
132 private:
133 
138 
139  virtual rtl::Reference<ScNamedRangeObj> GetObjectByIndex_Impl(sal_uInt16 nIndex) = 0;
140  virtual rtl::Reference<ScNamedRangeObj> GetObjectByName_Impl(const OUString& aName) = 0;
141 
142  virtual ScRangeName* GetRangeName_Impl() = 0;
143  virtual SCTAB GetTab_Impl() = 0;
144 
145 protected:
146 
149  void lock();
150 
152  void unlock();
153 
154 public:
155  ScNamedRangesObj(ScDocShell* pDocSh);
156  virtual ~ScNamedRangesObj() override;
157 
158  virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) override;
159 
161 
163  virtual void SAL_CALL addNewByName( const OUString& aName, const OUString& aContent,
164  const css::table::CellAddress& aPosition, sal_Int32 nType ) override;
165  virtual void SAL_CALL addNewFromTitles( const css::table::CellRangeAddress& aSource,
166  css::sheet::Border aBorder ) override;
167  virtual void SAL_CALL removeByName( const OUString& aName ) override;
168  virtual void SAL_CALL outputList( const css::table::CellAddress& aOutputPosition ) override;
169 
171  virtual css::uno::Any SAL_CALL getByName( const OUString& aName ) override;
172  virtual css::uno::Sequence< OUString > SAL_CALL getElementNames() override;
173  virtual sal_Bool SAL_CALL hasByName( const OUString& aName ) override;
174 
176  virtual sal_Int32 SAL_CALL getCount() override;
177  virtual css::uno::Any SAL_CALL getByIndex( sal_Int32 Index ) override;
178 
180  virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL
181  createEnumeration() override;
182 
184  virtual css::uno::Type SAL_CALL getElementType() override;
185  virtual sal_Bool SAL_CALL hasElements() override;
186 
188  virtual css::uno::Reference< css::beans::XPropertySetInfo >
189  SAL_CALL getPropertySetInfo() override;
190  virtual void SAL_CALL setPropertyValue( const OUString& aPropertyName,
191  const css::uno::Any& aValue ) override;
192  virtual css::uno::Any SAL_CALL getPropertyValue(
193  const OUString& PropertyName ) override;
194  virtual void SAL_CALL addPropertyChangeListener( const OUString& aPropertyName,
195  const css::uno::Reference<
196  css::beans::XPropertyChangeListener >& xListener ) override;
197  virtual void SAL_CALL removePropertyChangeListener( const OUString& aPropertyName,
198  const css::uno::Reference< css::beans::XPropertyChangeListener >& aListener ) override;
199  virtual void SAL_CALL addVetoableChangeListener( const OUString& PropertyName,
200  const css::uno::Reference< css::beans::XVetoableChangeListener >& aListener ) override;
201  virtual void SAL_CALL removeVetoableChangeListener( const OUString& PropertyName,
202  const css::uno::Reference< css::beans::XVetoableChangeListener >& aListener ) override;
203 
205  virtual sal_Bool SAL_CALL isActionLocked() override;
206  virtual void SAL_CALL addActionLock() override;
207  virtual void SAL_CALL removeActionLock() override;
208  virtual void SAL_CALL setActionLocks( sal_Int16 nLock ) override;
209  virtual sal_Int16 SAL_CALL resetActionLocks() override;
210 
212  virtual OUString SAL_CALL getImplementationName() override;
213  virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
214  virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
215 };
216 
218 {
219 private:
220 
221  virtual rtl::Reference<ScNamedRangeObj> GetObjectByIndex_Impl(sal_uInt16 nIndex) override;
222  virtual rtl::Reference<ScNamedRangeObj> GetObjectByName_Impl(const OUString& aName) override;
223 
224  virtual ScRangeName* GetRangeName_Impl() override;
225  virtual SCTAB GetTab_Impl() override;
226 
227 public:
229  virtual ~ScGlobalNamedRangesObj() override;
230 };
231 
233 {
234 private:
235 
236  virtual rtl::Reference<ScNamedRangeObj> GetObjectByIndex_Impl(sal_uInt16 nIndex) override;
237  virtual rtl::Reference<ScNamedRangeObj> GetObjectByName_Impl(const OUString& aName) override;
238 
239  virtual ScRangeName* GetRangeName_Impl() override;
240  virtual SCTAB GetTab_Impl() override;
241 
242  css::uno::Reference< css::container::XNamed > mxSheet;
243 public:
244  ScLocalNamedRangesObj(ScDocShell* pDocSh, css::uno::Reference< css::container::XNamed > const & xNamed );
245  virtual ~ScLocalNamedRangesObj() override;
246 };
247 
248 class ScLabelRangeObj final : public ::cppu::WeakImplHelper<
249  css::sheet::XLabelRange,
250  css::lang::XServiceInfo >,
251  public SfxListener
252 {
253 private:
255  bool bColumn;
257 
258 private:
260  void Modify_Impl( const ScRange* pLabel, const ScRange* pData );
261 
262 public:
263  ScLabelRangeObj(ScDocShell* pDocSh, bool bCol, const ScRange& rR);
264  virtual ~ScLabelRangeObj() override;
265 
266  virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) override;
267 
269  virtual css::table::CellRangeAddress SAL_CALL getLabelArea() override;
270  virtual void SAL_CALL setLabelArea( const css::table::CellRangeAddress& aLabelArea ) override;
271  virtual css::table::CellRangeAddress SAL_CALL getDataArea() override;
272  virtual void SAL_CALL setDataArea( const css::table::CellRangeAddress& aDataArea ) override;
273 
275  virtual OUString SAL_CALL getImplementationName() override;
276  virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
277  virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
278 };
279 
280 class ScLabelRangesObj final : public ::cppu::WeakImplHelper<
281  css::sheet::XLabelRanges,
282  css::container::XEnumerationAccess,
283  css::lang::XServiceInfo >,
284  public SfxListener
285 {
286 private:
288  bool bColumn;
289 
291 
292 public:
293  ScLabelRangesObj(ScDocShell* pDocSh, bool bCol);
294  virtual ~ScLabelRangesObj() override;
295 
296  virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) override;
297 
299  virtual void SAL_CALL addNew( const css::table::CellRangeAddress& aLabelArea,
300  const css::table::CellRangeAddress& aDataArea ) override;
301  virtual void SAL_CALL removeByIndex( sal_Int32 nIndex ) override;
302 
304  virtual sal_Int32 SAL_CALL getCount() override;
305  virtual css::uno::Any SAL_CALL getByIndex( sal_Int32 Index ) override;
306 
308  virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL
309  createEnumeration() override;
310 
312  virtual css::uno::Type SAL_CALL getElementType() override;
313  virtual sal_Bool SAL_CALL hasElements() override;
314 
316  virtual OUString SAL_CALL getImplementationName() override;
317  virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
318  virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
319 };
320 
321 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual OUString SAL_CALL getName() override
Definition: vbaname.cxx:51
virtual rtl::Reference< ScNamedRangeObj > GetObjectByIndex_Impl(sal_uInt16 nIndex) override
Definition: nameuno.cxx:855
virtual css::table::CellRangeAddress SAL_CALL getLabelArea() override
XLabelRange.
Definition: nameuno.cxx:974
OUString getContent(const formula::FormulaGrammar::Grammar eGrammar)
Definition: vbaname.cxx:85
virtual sal_Bool SAL_CALL hasElements() override
Definition: nameuno.cxx:1156
virtual void SAL_CALL removeVetoableChangeListener(const OUString &PropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener > &aListener) override
sal_Int32 nIndex
virtual void SAL_CALL addNewByName(const OUString &aName, const OUString &aContent, const css::table::CellAddress &aPosition, sal_Int32 nType) override
XNamedRanges.
Definition: nameuno.cxx:465
virtual void SAL_CALL setName(const OUString &rName) override
Definition: vbaname.cxx:57
virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() override
XEnumerationAccess.
Definition: nameuno.cxx:579
virtual ScRangeName * GetRangeName_Impl() override
Definition: nameuno.cxx:883
virtual void SAL_CALL addNew(const css::table::CellRangeAddress &aLabelArea, const css::table::CellRangeAddress &aDataArea) override
XLabelRanges.
Definition: nameuno.cxx:1052
virtual css::uno::Any SAL_CALL getByName(const OUString &aName) override
XNameAccess.
Definition: nameuno.cxx:655
ScRangePair * GetData_Impl()
Definition: nameuno.cxx:922
css::uno::Reference< css::container::XNamed > mxSheet
Definition: nameuno.hxx:242
bool getType(BSTR name, Type &type)
ScLabelRangesObj(ScDocShell *pDocSh, bool bCol)
Definition: nameuno.cxx:1010
virtual void SAL_CALL setDataArea(const css::table::CellRangeAddress &aDataArea) override
Definition: nameuno.cxx:1002
virtual void SAL_CALL addPropertyChangeListener(const OUString &aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener > &xListener) override
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
virtual css::uno::Any SAL_CALL getByIndex(sal_Int32 Index) override
Definition: nameuno.cxx:1139
rtl::Reference< ScNamedRangesObj > mxParent
Definition: nameuno.hxx:55
virtual ~ScLabelRangeObj() override
Definition: nameuno.cxx:904
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual rtl::Reference< ScNamedRangeObj > GetObjectByName_Impl(const OUString &aName) override
Definition: nameuno.cxx:847
css::uno::Reference< css::container::XNamed > mxSheet
Definition: nameuno.hxx:58
virtual void SAL_CALL removeByName(const OUString &aName) override
Definition: nameuno.cxx:545
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual ScRangeName * GetRangeName_Impl()=0
ScRange aRange
criterion to find range
Definition: nameuno.hxx:256
virtual void SAL_CALL removeActionLock() override
Definition: nameuno.cxx:737
virtual void Notify(SfxBroadcaster &rBC, const SfxHint &rHint) override
Definition: nameuno.cxx:453
virtual rtl::Reference< ScNamedRangeObj > GetObjectByIndex_Impl(sal_uInt16 nIndex)=0
virtual css::uno::Any SAL_CALL getByIndex(sal_Int32 Index) override
Definition: nameuno.cxx:604
bool getPropertyValue(ValueType &rValue, css::uno::Reference< css::beans::XPropertySet > const &xPropSet, OUString const &propName)
virtual css::uno::Type SAL_CALL getElementType() override
XElementAccess.
Definition: nameuno.cxx:1149
OUString aName
Definition: nameuno.hxx:57
ScDocShell * pDocShell
Definition: nameuno.hxx:147
virtual void SAL_CALL addVetoableChangeListener(const OUString &PropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener > &aListener) override
bool IsModifyAndBroadcast() const
Definition: nameuno.hxx:160
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
ScDocShell * pDocShell
Definition: nameuno.hxx:56
virtual rtl::Reference< ScNamedRangeObj > GetObjectByName_Impl(const OUString &aName)=0
virtual void Notify(SfxBroadcaster &rBC, const SfxHint &rHint) override
Definition: nameuno.cxx:912
virtual sal_Int16 SAL_CALL resetActionLocks() override
Definition: nameuno.cxx:772
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual ~ScNamedRangesObj() override
Definition: nameuno.cxx:445
ScNamedRangesObj(ScDocShell *pDocSh)
Definition: nameuno.cxx:438
void Modify_Impl(const ScRange *pLabel, const ScRange *pData)
Definition: nameuno.cxx:935
virtual css::uno::Type SAL_CALL getElementType() override
XElementAccess.
Definition: nameuno.cxx:614
virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() override
XPropertySet.
Definition: nameuno.cxx:626
virtual void SAL_CALL addNewFromTitles(const css::table::CellRangeAddress &aSource, css::sheet::Border aBorder) override
Definition: nameuno.cxx:521
unsigned char sal_Bool
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual void Notify(SfxBroadcaster &rBC, const SfxHint &rHint) override
Definition: nameuno.cxx:1025
ScDocShell * pDocShell
Definition: nameuno.hxx:287
bool mbModifyAndBroadcast
if true, adding new name or modifying existing one will set the document 'modified' and broadcast the...
Definition: nameuno.hxx:137
bool setPropertyValue(uno::Sequence< beans::PropertyValue > &aProp, const OUString &aName, const uno::Any &aValue)
virtual sal_Int32 SAL_CALL getCount() override
XIndexAccess.
Definition: nameuno.cxx:587
virtual void SAL_CALL setPropertyValue(const OUString &aPropertyName, const css::uno::Any &aValue) override
Definition: nameuno.cxx:633
void unlock()
called from the XActionLockable interface methods on final unlock
Definition: nameuno.cxx:711
virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() override
XEnumerationAccess.
Definition: nameuno.cxx:1118
void setContent(const OUString &sContent, const formula::FormulaGrammar::Grammar eGrammar)
Definition: vbaname.cxx:100
virtual OUString SAL_CALL getImplementationName() override
XServiceInfo.
ScLocalNamedRangesObj(ScDocShell *pDocSh, css::uno::Reference< css::container::XNamed > const &xNamed)
Definition: nameuno.cxx:835
virtual rtl::Reference< ScNamedRangeObj > GetObjectByIndex_Impl(sal_uInt16 nIndex) override
Definition: nameuno.cxx:796
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
virtual sal_Bool SAL_CALL hasByName(const OUString &aName) override
Definition: nameuno.cxx:688
virtual SCTAB GetTab_Impl() override
Definition: nameuno.cxx:889
virtual void Notify(SfxBroadcaster &rBC, const SfxHint &rHint)
virtual css::table::CellRangeAddress SAL_CALL getDataArea() override
Definition: nameuno.cxx:992
rtl::Reference< ScLabelRangeObj > GetObjectByIndex_Impl(size_t nIndex)
Definition: nameuno.cxx:1037
virtual sal_Bool SAL_CALL hasElements() override
Definition: nameuno.cxx:620
virtual css::uno::Any SAL_CALL getPropertyValue(const OUString &PropertyName) override
Definition: nameuno.cxx:642
virtual void SAL_CALL outputList(const css::table::CellAddress &aOutputPosition) override
Definition: nameuno.cxx:569
virtual SCTAB GetTab_Impl() override
Definition: nameuno.cxx:830
virtual ~ScGlobalNamedRangesObj() override
Definition: nameuno.cxx:791
ScLabelRangeObj(ScDocShell *pDocSh, bool bCol, const ScRange &rR)
Definition: nameuno.cxx:896
void lock()
called from the XActionLockable interface methods on initial locking
Definition: nameuno.cxx:705
virtual rtl::Reference< ScNamedRangeObj > GetObjectByName_Impl(const OUString &aName) override
Definition: nameuno.cxx:818
virtual void SAL_CALL removeByIndex(sal_Int32 nIndex) override
Definition: nameuno.cxx:1084
virtual void SAL_CALL setLabelArea(const css::table::CellRangeAddress &aLabelArea) override
Definition: nameuno.cxx:984
virtual void SAL_CALL addActionLock() override
Definition: nameuno.cxx:724
virtual sal_Bool SAL_CALL isActionLocked() override
XActionLockable.
Definition: nameuno.cxx:718
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
QPRO_FUNC_TYPE nType
Definition: qproform.cxx:398
virtual ScRangeName * GetRangeName_Impl() override
Definition: nameuno.cxx:825
virtual ~ScLocalNamedRangesObj() override
Definition: nameuno.cxx:842
virtual OUString SAL_CALL getImplementationName() override
XServiceInfo.
virtual sal_Int32 SAL_CALL getCount() override
XIndexAccess.
Definition: nameuno.cxx:1126
virtual ~ScLabelRangesObj() override
Definition: nameuno.cxx:1017
virtual OUString SAL_CALL getImplementationName() override
virtual SCTAB GetTab_Impl()=0
struct _ADOIndex Index
virtual css::uno::Sequence< OUString > SAL_CALL getElementNames() override
Definition: nameuno.cxx:665
#define SC_DLLPUBLIC
Definition: scdllapi.h:27
virtual OUString SAL_CALL getImplementationName() override
XServiceInfo.
virtual void SAL_CALL removePropertyChangeListener(const OUString &aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener > &aListener) override
virtual void SAL_CALL setActionLocks(sal_Int16 nLock) override
Definition: nameuno.cxx:753
ScGlobalNamedRangesObj(ScDocShell *pDocSh)
Definition: nameuno.cxx:785
ScDocShell * pDocShell
Definition: nameuno.hxx:254
sal_Int16 SCTAB
Definition: types.hxx:22