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 <cppuhelper/compbase.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 typedef cppu::WeakComponentImplHelper<
164  css::text::XTextField,
165  css::beans::XPropertySet,
166  css::lang::XUnoTunnel,
167  css::lang::XServiceInfo> ScEditFieldObj_Base;
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  // XPropertySet
224  virtual css::uno::Reference< css::beans::XPropertySetInfo >
225  SAL_CALL getPropertySetInfo() override;
226  virtual void SAL_CALL setPropertyValue( const OUString& aPropertyName,
227  const css::uno::Any& aValue ) override;
228  virtual css::uno::Any SAL_CALL getPropertyValue( const OUString& PropertyName ) override;
229  virtual void SAL_CALL addPropertyChangeListener( const OUString& aPropertyName,
230  const css::uno::Reference< css::beans::XPropertyChangeListener >& xListener ) override;
231  virtual void SAL_CALL removePropertyChangeListener( const OUString& aPropertyName,
232  const css::uno::Reference< css::beans::XPropertyChangeListener >& aListener ) override;
233  virtual void SAL_CALL addVetoableChangeListener( const OUString& PropertyName,
234  const css::uno::Reference< css::beans::XVetoableChangeListener >& aListener ) override;
235  virtual void SAL_CALL removeVetoableChangeListener( const OUString& PropertyName,
236  const css::uno::Reference< css::beans::XVetoableChangeListener >& aListener ) override;
237 
238  // XUnoTunnel
240 
241  // XServiceInfo
242  virtual OUString SAL_CALL getImplementationName() override;
243  virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
244  virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
245 
246  // XTypeProvider
247  virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override;
248  virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() override;
249 };
250 
251 /* 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: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:176
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:174
virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() override
Definition: fielduno.cxx:1179
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:1300
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:180
virtual OUString SAL_CALL getImplementationName() override
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
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: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:1287
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:1271
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: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:1276
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
Definition: fielduno.cxx:1281
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
cppu::WeakComponentImplHelper< css::text::XTextField, css::beans::XPropertySet, css::lang::XUnoTunnel, css::lang::XServiceInfo > ScEditFieldObj_Base
Generic UNO wrapper for edit engine's field item in cells, headers, and footers.
Definition: fielduno.hxx:167
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:67
virtual void SAL_CALL addPropertyChangeListener(const OUString &aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener > &xListener) override
ScDocShell * pDocShell
Definition: fielduno.hxx:63
virtual void SAL_CALL setPropertyValue(const OUString &aPropertyName, const css::uno::Any &aValue) override
Definition: fielduno.cxx:1186
virtual void SAL_CALL addRefreshListener(const css::uno::Reference< css::util::XRefreshListener > &l) override
Definition: fielduno.cxx:554
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:1218