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 #pragma once
21 
22 #include "address.hxx"
23 #include "mutexhlp.hxx"
24 
25 #include <svl/lstner.hxx>
26 #include <editeng/editdata.hxx>
27 #include <com/sun/star/text/XTextField.hpp>
28 #include <com/sun/star/lang/XServiceInfo.hpp>
29 #include <com/sun/star/container/XContainer.hpp>
30 #include <com/sun/star/lang/XUnoTunnel.hpp>
31 #include <com/sun/star/container/XEnumerationAccess.hpp>
32 #include <com/sun/star/container/XIndexAccess.hpp>
33 #include <com/sun/star/beans/XPropertySet.hpp>
34 #include <com/sun/star/util/XRefreshable.hpp>
35 #include <com/sun/star/util/DateTime.hpp>
37 #include <cppuhelper/component.hxx>
38 #include <cppuhelper/implbase.hxx>
39 #include <osl/mutex.hxx>
40 
41 #include <memory>
42 
43 namespace comphelper { class OInterfaceContainerHelper2; }
44 
45 class ScEditSource;
46 class SvxFieldItem;
47 class SvxFieldData;
48 class ScDocShell;
50 class SfxItemPropertySet;
51 
52 class ScCellFieldsObj final : public cppu::WeakImplHelper<
53  css::container::XEnumerationAccess,
54  css::container::XIndexAccess,
55  css::container::XContainer,
56  css::util::XRefreshable,
57  css::lang::XServiceInfo >,
58  public SfxListener
59 {
60 private:
61  css::uno::Reference<css::text::XTextRange> mxContent;
64  std::unique_ptr<ScEditSource> mpEditSource;
66  std::unique_ptr<comphelper::OInterfaceContainerHelper2> mpRefreshListeners;
68  osl::Mutex aMutex;
69 
70  css::uno::Reference<css::text::XTextField>
71  GetObjectByIndex_Impl(sal_Int32 Index) const;
72 
73 public:
75  const css::uno::Reference<css::text::XTextRange>& xContent,
76  ScDocShell* pDocSh, const ScAddress& rPos);
77  virtual ~ScCellFieldsObj() override;
78 
79  virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) override;
80 
81  // XIndexAccess
82  virtual sal_Int32 SAL_CALL getCount() override;
83  virtual css::uno::Any SAL_CALL getByIndex( sal_Int32 Index ) override;
84 
85  // XEnumerationAccess
86  virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL
87  createEnumeration() override;
88 
89  // XElementAccess
90  virtual css::uno::Type SAL_CALL getElementType() override;
91  virtual sal_Bool SAL_CALL hasElements() override;
92 
93  // XContainer
94  virtual void SAL_CALL addContainerListener( const css::uno::Reference< css::container::XContainerListener >& xListener ) override;
95  virtual void SAL_CALL removeContainerListener( const css::uno::Reference< css::container::XContainerListener >& xListener ) override;
96 
97  // XRefreshable
98  virtual void SAL_CALL refresh( ) override;
99  virtual void SAL_CALL addRefreshListener( const css::uno::Reference< css::util::XRefreshListener >& l ) override;
100  virtual void SAL_CALL removeRefreshListener( const css::uno::Reference< css::util::XRefreshListener >& l ) override;
101 
102  // XServiceInfo
103  virtual OUString SAL_CALL getImplementationName() override;
104  virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
105  virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
106 };
107 
108 class ScHeaderFieldsObj final : public cppu::WeakImplHelper<
109  css::container::XEnumerationAccess,
110  css::container::XIndexAccess,
111  css::container::XContainer,
112  css::util::XRefreshable,
113  css::lang::XServiceInfo >
114 {
115 private:
117  std::unique_ptr<ScEditSource> mpEditSource;
118 
120  std::unique_ptr<comphelper::OInterfaceContainerHelper2> mpRefreshListeners;
122  osl::Mutex aMutex;
123 
124  css::uno::Reference< css::text::XTextField>
125  GetObjectByIndex_Impl(sal_Int32 Index) const;
126 
127 public:
129  virtual ~ScHeaderFieldsObj() override;
130 
131  // XIndexAccess
132  virtual sal_Int32 SAL_CALL getCount() override;
133  virtual css::uno::Any SAL_CALL getByIndex( sal_Int32 Index ) override;
134 
135  // XEnumerationAccess
136  virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL
137  createEnumeration() override;
138 
139  // XElementAccess
140  virtual css::uno::Type SAL_CALL getElementType() override;
141  virtual sal_Bool SAL_CALL hasElements() override;
142 
143  // XContainer
144  virtual void SAL_CALL addContainerListener( const css::uno::Reference< css::container::XContainerListener >& xListener ) override;
145  virtual void SAL_CALL removeContainerListener( const css::uno::Reference< css::container::XContainerListener >& xListener ) override;
146 
147  // XRefreshable
148  virtual void SAL_CALL refresh( ) override;
149  virtual void SAL_CALL addRefreshListener( const css::uno::Reference< css::util::XRefreshListener >& l ) override;
150  virtual void SAL_CALL removeRefreshListener( const css::uno::Reference< css::util::XRefreshListener >& l ) override;
151 
152  // XServiceInfo
153  virtual OUString SAL_CALL getImplementationName() override;
154  virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
155  virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
156 };
157 
162 class ScEditFieldObj final : public cppu::WeakImplHelper<
163  css::text::XTextField,
164  css::beans::XPropertySet,
165  css::lang::XUnoTunnel,
166  css::lang::XServiceInfo>,
167  public ScMutexHelper,
169 {
170  ScEditFieldObj() = delete;
171  ScEditFieldObj(const ScEditFieldObj&) = delete;
172  const ScEditFieldObj& operator=(const ScEditFieldObj&) = delete;
173 
175  std::unique_ptr<ScEditSource> mpEditSource;
177 
178  sal_Int32 meType;
179  std::unique_ptr<SvxFieldData> mpData;
180  css::uno::Reference<css::text::XTextRange> mpContent;
181 
182  css::util::DateTime maDateTime;
183  sal_Int32 mnNumFormat;
184  bool mbIsDate:1;
185  bool mbIsFixed:1;
186 
187 private:
189 
190  void setPropertyValueURL(const OUString& rName, const css::uno::Any& rVal);
191  css::uno::Any getPropertyValueURL(const OUString& rName);
192 
193  void setPropertyValueFile(const OUString& rName, const css::uno::Any& rVal);
194  css::uno::Any getPropertyValueFile(const OUString& rName);
195 
196  void setPropertyValueDateTime(const OUString& rName, const css::uno::Any& rVal);
197  css::uno::Any getPropertyValueDateTime(const OUString& rName);
198 
199  void setPropertyValueSheet(const OUString& rName, const css::uno::Any& rVal);
200 
201 public:
203  const css::uno::Reference<css::text::XTextRange>& rContent,
204  std::unique_ptr<ScEditSource> pEditSrc, sal_Int32 eType, const ESelection& rSel);
205  virtual ~ScEditFieldObj() override;
206 
207  sal_Int32 GetFieldType() const { return meType;}
208  void DeleteField();
209  bool IsInserted() const;
211  void InitDoc(
212  const css::uno::Reference<css::text::XTextRange>& rContent,
213  std::unique_ptr<ScEditSource> pEditSrc, const ESelection& rSel);
214 
215  // XTextField
216  virtual OUString SAL_CALL getPresentation( sal_Bool bShowCommand ) override;
217 
218  // XTextContent
219  virtual void SAL_CALL attach( const css::uno::Reference< css::text::XTextRange >& xTextRange ) override;
220  virtual css::uno::Reference< css::text::XTextRange > SAL_CALL
221  getAnchor() override;
222 
223  // XComponent
224  virtual void SAL_CALL dispose() override;
225  virtual void SAL_CALL addEventListener( const css::uno::Reference< css::lang::XEventListener >& xListener ) override;
226  virtual void SAL_CALL removeEventListener( const css::uno::Reference< css::lang::XEventListener >& aListener ) override;
227 
228  // XPropertySet
229  virtual css::uno::Reference< css::beans::XPropertySetInfo >
230  SAL_CALL getPropertySetInfo() override;
231  virtual void SAL_CALL setPropertyValue( const OUString& aPropertyName,
232  const css::uno::Any& aValue ) override;
233  virtual css::uno::Any SAL_CALL getPropertyValue( const OUString& PropertyName ) override;
234  virtual void SAL_CALL addPropertyChangeListener( const OUString& aPropertyName,
235  const css::uno::Reference< css::beans::XPropertyChangeListener >& xListener ) override;
236  virtual void SAL_CALL removePropertyChangeListener( const OUString& aPropertyName,
237  const css::uno::Reference< css::beans::XPropertyChangeListener >& aListener ) override;
238  virtual void SAL_CALL addVetoableChangeListener( const OUString& PropertyName,
239  const css::uno::Reference< css::beans::XVetoableChangeListener >& aListener ) override;
240  virtual void SAL_CALL removeVetoableChangeListener( const OUString& PropertyName,
241  const css::uno::Reference< css::beans::XVetoableChangeListener >& aListener ) override;
242 
243  // XUnoTunnel
245 
246  // XServiceInfo
247  virtual OUString SAL_CALL getImplementationName() override;
248  virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
249  virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
250 
251  // XTypeProvider
252  virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override;
253  virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() override;
254 };
255 
256 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::unique_ptr< ScEditSource > mpEditSource
Definition: fielduno.hxx:175
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:179
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:64
osl::Mutex aMutex
mutex to lock the InterfaceContainerHelper
Definition: fielduno.hxx:122
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:176
std::unique_ptr< ScEditSource > mpEditSource
Definition: fielduno.hxx:117
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:174
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:116
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:61
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:180
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:162
std::unique_ptr< comphelper::OInterfaceContainerHelper2 > mpRefreshListeners
List of refresh listeners.
Definition: fielduno.hxx:120
virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() override
Definition: fielduno.cxx:524
ScAddress aCellPos
Definition: fielduno.hxx:63
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:178
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:68
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:182
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:207
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:183
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:66
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:62
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