LibreOffice Module sc (master)  1
fielduno.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 #ifndef INCLUDED_SC_INC_FIELDUNO_HXX
21 #define INCLUDED_SC_INC_FIELDUNO_HXX
22 
23 #include "address.hxx"
24 #include "mutexhlp.hxx"
25 
26 #include <svl/lstner.hxx>
27 #include <editeng/editdata.hxx>
28 #include <com/sun/star/text/XTextField.hpp>
29 #include <com/sun/star/lang/XServiceInfo.hpp>
30 #include <com/sun/star/container/XContainer.hpp>
31 #include <com/sun/star/lang/XUnoTunnel.hpp>
32 #include <com/sun/star/container/XEnumerationAccess.hpp>
33 #include <com/sun/star/container/XIndexAccess.hpp>
34 #include <com/sun/star/beans/XPropertySet.hpp>
35 #include <com/sun/star/util/XRefreshable.hpp>
36 #include <com/sun/star/util/DateTime.hpp>
38 #include <cppuhelper/component.hxx>
39 #include <cppuhelper/implbase.hxx>
40 #include <osl/mutex.hxx>
41 
42 #include <memory>
43 
44 namespace comphelper { class OInterfaceContainerHelper2; }
45 
46 class ScEditSource;
47 class SvxFieldItem;
48 class SvxFieldData;
49 class ScDocShell;
51 class SfxItemPropertySet;
52 
53 class ScCellFieldsObj final : public cppu::WeakImplHelper<
54  css::container::XEnumerationAccess,
55  css::container::XIndexAccess,
56  css::container::XContainer,
57  css::util::XRefreshable,
58  css::lang::XServiceInfo >,
59  public SfxListener
60 {
61 private:
62  css::uno::Reference<css::text::XTextRange> mxContent;
65  std::unique_ptr<ScEditSource> mpEditSource;
67  std::unique_ptr<comphelper::OInterfaceContainerHelper2> mpRefreshListeners;
69  osl::Mutex aMutex;
70 
71  css::uno::Reference<css::text::XTextField>
72  GetObjectByIndex_Impl(sal_Int32 Index) const;
73 
74 public:
76  const css::uno::Reference<css::text::XTextRange>& xContent,
77  ScDocShell* pDocSh, const ScAddress& rPos);
78  virtual ~ScCellFieldsObj() override;
79 
80  virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) override;
81 
82  // XIndexAccess
83  virtual sal_Int32 SAL_CALL getCount() override;
84  virtual css::uno::Any SAL_CALL getByIndex( sal_Int32 Index ) override;
85 
86  // XEnumerationAccess
87  virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL
88  createEnumeration() override;
89 
90  // XElementAccess
91  virtual css::uno::Type SAL_CALL getElementType() override;
92  virtual sal_Bool SAL_CALL hasElements() override;
93 
94  // XContainer
95  virtual void SAL_CALL addContainerListener( const css::uno::Reference< css::container::XContainerListener >& xListener ) override;
96  virtual void SAL_CALL removeContainerListener( const css::uno::Reference< css::container::XContainerListener >& xListener ) override;
97 
98  // XRefreshable
99  virtual void SAL_CALL refresh( ) override;
100  virtual void SAL_CALL addRefreshListener( const css::uno::Reference< css::util::XRefreshListener >& l ) override;
101  virtual void SAL_CALL removeRefreshListener( const css::uno::Reference< css::util::XRefreshListener >& l ) override;
102 
103  // XServiceInfo
104  virtual OUString SAL_CALL getImplementationName() override;
105  virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
106  virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
107 };
108 
109 class ScHeaderFieldsObj final : public cppu::WeakImplHelper<
110  css::container::XEnumerationAccess,
111  css::container::XIndexAccess,
112  css::container::XContainer,
113  css::util::XRefreshable,
114  css::lang::XServiceInfo >
115 {
116 private:
118  std::unique_ptr<ScEditSource> mpEditSource;
119 
121  std::unique_ptr<comphelper::OInterfaceContainerHelper2> mpRefreshListeners;
123  osl::Mutex aMutex;
124 
125  css::uno::Reference< css::text::XTextField>
126  GetObjectByIndex_Impl(sal_Int32 Index) const;
127 
128 public:
130  virtual ~ScHeaderFieldsObj() override;
131 
132  // XIndexAccess
133  virtual sal_Int32 SAL_CALL getCount() override;
134  virtual css::uno::Any SAL_CALL getByIndex( sal_Int32 Index ) override;
135 
136  // XEnumerationAccess
137  virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL
138  createEnumeration() override;
139 
140  // XElementAccess
141  virtual css::uno::Type SAL_CALL getElementType() override;
142  virtual sal_Bool SAL_CALL hasElements() override;
143 
144  // XContainer
145  virtual void SAL_CALL addContainerListener( const css::uno::Reference< css::container::XContainerListener >& xListener ) override;
146  virtual void SAL_CALL removeContainerListener( const css::uno::Reference< css::container::XContainerListener >& xListener ) override;
147 
148  // XRefreshable
149  virtual void SAL_CALL refresh( ) override;
150  virtual void SAL_CALL addRefreshListener( const css::uno::Reference< css::util::XRefreshListener >& l ) override;
151  virtual void SAL_CALL removeRefreshListener( const css::uno::Reference< css::util::XRefreshListener >& l ) override;
152 
153  // XServiceInfo
154  virtual OUString SAL_CALL getImplementationName() override;
155  virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
156  virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
157 };
158 
163 class ScEditFieldObj final : public cppu::WeakImplHelper<
164  css::text::XTextField,
165  css::beans::XPropertySet,
166  css::lang::XUnoTunnel,
167  css::lang::XServiceInfo>,
168  public ScMutexHelper,
170 {
171  ScEditFieldObj() = delete;
172  ScEditFieldObj(const ScEditFieldObj&) = delete;
173  const ScEditFieldObj& operator=(const ScEditFieldObj&) = delete;
174 
176  std::unique_ptr<ScEditSource> mpEditSource;
178 
179  sal_Int32 meType;
180  std::unique_ptr<SvxFieldData> mpData;
181  css::uno::Reference<css::text::XTextRange> mpContent;
182 
183  css::util::DateTime maDateTime;
184  sal_Int32 mnNumFormat;
185  bool mbIsDate:1;
186  bool mbIsFixed:1;
187 
188 private:
190 
191  void setPropertyValueURL(const OUString& rName, const css::uno::Any& rVal);
192  css::uno::Any getPropertyValueURL(const OUString& rName);
193 
194  void setPropertyValueFile(const OUString& rName, const css::uno::Any& rVal);
195  css::uno::Any getPropertyValueFile(const OUString& rName);
196 
197  void setPropertyValueDateTime(const OUString& rName, const css::uno::Any& rVal);
198  css::uno::Any getPropertyValueDateTime(const OUString& rName);
199 
200  void setPropertyValueSheet(const OUString& rName, const css::uno::Any& rVal);
201 
202 public:
204  const css::uno::Reference<css::text::XTextRange>& rContent,
205  std::unique_ptr<ScEditSource> pEditSrc, sal_Int32 eType, const ESelection& rSel);
206  virtual ~ScEditFieldObj() override;
207 
208  sal_Int32 GetFieldType() const { return meType;}
209  void DeleteField();
210  bool IsInserted() const;
212  void InitDoc(
213  const css::uno::Reference<css::text::XTextRange>& rContent,
214  std::unique_ptr<ScEditSource> pEditSrc, const ESelection& rSel);
215 
216  // XTextField
217  virtual OUString SAL_CALL getPresentation( sal_Bool bShowCommand ) override;
218 
219  // XTextContent
220  virtual void SAL_CALL attach( const css::uno::Reference< css::text::XTextRange >& xTextRange ) override;
221  virtual css::uno::Reference< css::text::XTextRange > SAL_CALL
222  getAnchor() override;
223 
224  // XComponent
225  virtual void SAL_CALL dispose() override;
226  virtual void SAL_CALL addEventListener( const css::uno::Reference< css::lang::XEventListener >& xListener ) override;
227  virtual void SAL_CALL removeEventListener( const css::uno::Reference< css::lang::XEventListener >& aListener ) override;
228 
229  // XPropertySet
230  virtual css::uno::Reference< css::beans::XPropertySetInfo >
231  SAL_CALL getPropertySetInfo() override;
232  virtual void SAL_CALL setPropertyValue( const OUString& aPropertyName,
233  const css::uno::Any& aValue ) override;
234  virtual css::uno::Any SAL_CALL getPropertyValue( const OUString& PropertyName ) override;
235  virtual void SAL_CALL addPropertyChangeListener( const OUString& aPropertyName,
236  const css::uno::Reference< css::beans::XPropertyChangeListener >& xListener ) override;
237  virtual void SAL_CALL removePropertyChangeListener( const OUString& aPropertyName,
238  const css::uno::Reference< css::beans::XPropertyChangeListener >& aListener ) override;
239  virtual void SAL_CALL addVetoableChangeListener( const OUString& PropertyName,
240  const css::uno::Reference< css::beans::XVetoableChangeListener >& aListener ) override;
241  virtual void SAL_CALL removeVetoableChangeListener( const OUString& PropertyName,
242  const css::uno::Reference< css::beans::XVetoableChangeListener >& aListener ) override;
243 
244  // XUnoTunnel
246 
247  // XServiceInfo
248  virtual OUString SAL_CALL getImplementationName() override;
249  virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
250  virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
251 
252  // XTypeProvider
253  virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override;
254  virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() override;
255 };
256 
257 #endif
258 
259 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::unique_ptr< ScEditSource > mpEditSource
Definition: fielduno.hxx:176
Type
virtual OUString SAL_CALL getPresentation(sal_Bool bShowCommand) override
Definition: fielduno.cxx:1120
virtual OUString SAL_CALL getImplementationName() override
std::unique_ptr< SvxFieldData > mpData
Definition: fielduno.hxx:180
virtual void SAL_CALL addVetoableChangeListener(const OUString &PropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener > &aListener) override
std::unique_ptr< ScEditSource > mpEditSource
Definition: fielduno.hxx:65
osl::Mutex aMutex
mutex to lock the InterfaceContainerHelper
Definition: fielduno.hxx:123
virtual void SAL_CALL removeContainerListener(const css::uno::Reference< css::container::XContainerListener > &xListener) override
Definition: fielduno.cxx:536
bool IsInserted() const
Definition: fielduno.cxx:1113
ESelection aSelection
Definition: fielduno.hxx:177
std::unique_ptr< ScEditSource > mpEditSource
Definition: fielduno.hxx:118
virtual css::uno::Reference< css::text::XTextRange > SAL_CALL getAnchor() override
Definition: fielduno.cxx:1171
signed char sal_Int8
const SfxItemPropertySet * pPropSet
Definition: fielduno.hxx:175
virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() override
Definition: fielduno.cxx:1198
virtual void SAL_CALL refresh() override
Definition: fielduno.cxx:543
virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() override
Definition: fielduno.cxx:373
ScHeaderFooterTextData & mrData
Definition: fielduno.hxx:117
virtual css::uno::Type SAL_CALL getElementType() override
Definition: fielduno.cxx:512
virtual ~ScCellFieldsObj() override
Definition: fielduno.cxx:284
virtual void Notify(SfxBroadcaster &rBC, const SfxHint &rHint) override
Definition: fielduno.cxx:305
virtual void SAL_CALL addContainerListener(const css::uno::Reference< css::container::XContainerListener > &xListener) override
Definition: fielduno.cxx:379
#define UNO3_GETIMPLEMENTATION_DECL(classname)
virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() override
Definition: fielduno.cxx:1320
css::uno::Reference< css::text::XTextRange > mxContent
Definition: fielduno.hxx:62
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
void setPropertyValueURL(const OUString &rName, const css::uno::Any &rVal)
Definition: fielduno.cxx:622
css::uno::Reference< css::text::XTextRange > mpContent
Definition: fielduno.hxx:181
virtual OUString SAL_CALL getImplementationName() override
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
Generic UNO wrapper for edit engine's field item in cells, headers, and footers.
Definition: fielduno.hxx:163
std::unique_ptr< comphelper::OInterfaceContainerHelper2 > mpRefreshListeners
List of refresh listeners.
Definition: fielduno.hxx:121
virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() override
Definition: fielduno.cxx:524
ScAddress aCellPos
Definition: fielduno.hxx:64
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual void SAL_CALL removeRefreshListener(const css::uno::Reference< css::util::XRefreshListener > &l) override
Definition: fielduno.cxx:565
virtual void SAL_CALL attach(const css::uno::Reference< css::text::XTextRange > &xTextRange) override
Definition: fielduno.cxx:1158
css::uno::Reference< css::text::XTextField > GetObjectByIndex_Impl(sal_Int32 Index) const
Definition: fielduno.cxx:448
ScEditFieldObj()=delete
virtual void SAL_CALL removeContainerListener(const css::uno::Reference< css::container::XContainerListener > &xListener) override
Definition: fielduno.cxx:385
SvxFieldItem CreateFieldItem()
Definition: fielduno.cxx:1091
sal_Int32 meType
Definition: fielduno.hxx:179
css::uno::Reference< css::text::XTextField > GetObjectByIndex_Impl(sal_Int32 Index) const
Definition: fielduno.cxx:321
virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override
Definition: fielduno.cxx:1307
css::uno::Any getPropertyValueFile(const OUString &rName)
Definition: fielduno.cxx:770
virtual void SAL_CALL refresh() override
Definition: fielduno.cxx:392
virtual sal_Int32 SAL_CALL getCount() override
Definition: fielduno.cxx:492
void InitDoc(const css::uno::Reference< css::text::XTextRange > &rContent, std::unique_ptr< ScEditSource > pEditSrc, const ESelection &rSel)
Definition: fielduno.cxx:1074
virtual ~ScHeaderFieldsObj() override
Definition: fielduno.cxx:430
virtual OUString SAL_CALL getImplementationName() override
Definition: fielduno.cxx:1291
virtual void SAL_CALL removePropertyChangeListener(const OUString &aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener > &aListener) override
virtual void SAL_CALL addContainerListener(const css::uno::Reference< css::container::XContainerListener > &xListener) override
Definition: fielduno.cxx:530
osl::Mutex aMutex
mutex to lock the InterfaceContainerHelper
Definition: fielduno.hxx:69
unsigned char sal_Bool
virtual ~ScEditFieldObj() override
Definition: fielduno.cxx:1087
virtual sal_Bool SAL_CALL hasElements() override
Definition: fielduno.cxx:367
css::util::DateTime maDateTime
Definition: fielduno.hxx:183
SvxFieldData & getData()
Definition: fielduno.cxx:575
void setPropertyValueFile(const OUString &rName, const css::uno::Any &rVal)
Definition: fielduno.cxx:737
css::uno::Any getPropertyValueDateTime(const OUString &rName)
Definition: fielduno.cxx:894
virtual sal_Int32 SAL_CALL getCount() override
Definition: fielduno.cxx:340
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
Definition: fielduno.cxx:1296
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
Definition: fielduno.cxx:1301
ScHeaderFieldsObj(ScHeaderFooterTextData &rData)
Definition: fielduno.cxx:424
void DeleteField()
Definition: fielduno.cxx:1097
virtual void SAL_CALL addRefreshListener(const css::uno::Reference< css::util::XRefreshListener > &l) override
Definition: fielduno.cxx:403
sal_Int32 GetFieldType() const
Definition: fielduno.hxx:208
css::uno::Any getPropertyValueURL(const OUString &rName)
Definition: fielduno.cxx:688
virtual void SAL_CALL removeRefreshListener(const css::uno::Reference< css::util::XRefreshListener > &l) override
Definition: fielduno.cxx:414
sal_Int32 mnNumFormat
Definition: fielduno.hxx:184
virtual css::uno::Any SAL_CALL getByIndex(sal_Int32 Index) override
Definition: fielduno.cxx:502
std::unique_ptr< comphelper::OInterfaceContainerHelper2 > mpRefreshListeners
List of refresh listeners.
Definition: fielduno.hxx:67
virtual void SAL_CALL dispose() override
Definition: fielduno.cxx:1179
virtual void SAL_CALL addPropertyChangeListener(const OUString &aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener > &xListener) override
virtual void SAL_CALL addEventListener(const css::uno::Reference< css::lang::XEventListener > &xListener) override
Definition: fielduno.cxx:1184
ScDocShell * pDocShell
Definition: fielduno.hxx:63
virtual void SAL_CALL setPropertyValue(const OUString &aPropertyName, const css::uno::Any &aValue) override
Definition: fielduno.cxx:1205
virtual void SAL_CALL addRefreshListener(const css::uno::Reference< css::util::XRefreshListener > &l) override
Definition: fielduno.cxx:554
virtual void SAL_CALL removeEventListener(const css::uno::Reference< css::lang::XEventListener > &aListener) override
Definition: fielduno.cxx:1190
virtual css::uno::Any SAL_CALL getByIndex(sal_Int32 Index) override
Definition: fielduno.cxx:351
virtual css::uno::Type SAL_CALL getElementType() override
Definition: fielduno.cxx:361
void setPropertyValueDateTime(const OUString &rName, const css::uno::Any &rVal)
Definition: fielduno.cxx:800
void setPropertyValueSheet(const OUString &rName, const css::uno::Any &rVal)
Definition: fielduno.cxx:999
struct _ADOIndex Index
virtual void SAL_CALL removeVetoableChangeListener(const OUString &PropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener > &aListener) override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual sal_Bool SAL_CALL hasElements() override
Definition: fielduno.cxx:518
ScCellFieldsObj(const css::uno::Reference< css::text::XTextRange > &xContent, ScDocShell *pDocSh, const ScAddress &rPos)
Definition: fielduno.cxx:272
const ScEditFieldObj & operator=(const ScEditFieldObj &)=delete
virtual css::uno::Any SAL_CALL getPropertyValue(const OUString &PropertyName) override
Definition: fielduno.cxx:1237