Line data Source code
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 <svl/itemprop.hxx>
28 : #include <editeng/editdata.hxx>
29 : #include <com/sun/star/text/XTextField.hpp>
30 : #include <com/sun/star/lang/XServiceInfo.hpp>
31 : #include <com/sun/star/container/XContainer.hpp>
32 : #include <com/sun/star/lang/XUnoTunnel.hpp>
33 : #include <com/sun/star/container/XEnumerationAccess.hpp>
34 : #include <com/sun/star/container/XIndexAccess.hpp>
35 : #include <com/sun/star/beans/XPropertySet.hpp>
36 : #include <com/sun/star/util/XRefreshable.hpp>
37 : #include <com/sun/star/util/DateTime.hpp>
38 : #include <cppuhelper/component.hxx>
39 : #include <cppuhelper/implbase5.hxx>
40 : #include <cppuhelper/implbase4.hxx>
41 : #include <osl/mutex.hxx>
42 :
43 : #include <boost/noncopyable.hpp>
44 : #include <boost/scoped_ptr.hpp>
45 :
46 : class ScEditSource;
47 : class SvxFieldItem;
48 : class SvxFieldData;
49 : class ScEditFieldObj;
50 : class ScDocShell;
51 : class ScHeaderFooterTextData;
52 :
53 : class ScCellFieldsObj : public cppu::WeakImplHelper5<
54 : com::sun::star::container::XEnumerationAccess,
55 : com::sun::star::container::XIndexAccess,
56 : com::sun::star::container::XContainer,
57 : com::sun::star::util::XRefreshable,
58 : com::sun::star::lang::XServiceInfo >,
59 : public SfxListener
60 : {
61 : private:
62 : com::sun::star::uno::Reference<com::sun::star::text::XTextRange> mxContent;
63 : ScDocShell* pDocShell;
64 : ScAddress aCellPos;
65 : ScEditSource* mpEditSource;
66 : /// List of refresh listeners.
67 : cppu::OInterfaceContainerHelper* mpRefreshListeners;
68 : /// mutex to lock the InterfaceContainerHelper
69 : osl::Mutex aMutex;
70 :
71 : com::sun::star::uno::Reference<
72 : com::sun::star::text::XTextField>
73 : GetObjectByIndex_Impl(sal_Int32 Index) const;
74 :
75 : public:
76 : ScCellFieldsObj(
77 : const com::sun::star::uno::Reference<com::sun::star::text::XTextRange>& xContent,
78 : ScDocShell* pDocSh, const ScAddress& rPos);
79 : virtual ~ScCellFieldsObj();
80 :
81 : virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) SAL_OVERRIDE;
82 :
83 : // XIndexAccess
84 : virtual sal_Int32 SAL_CALL getCount() throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
85 : virtual ::com::sun::star::uno::Any SAL_CALL getByIndex( sal_Int32 Index )
86 : throw(::com::sun::star::lang::IndexOutOfBoundsException,
87 : ::com::sun::star::lang::WrappedTargetException,
88 : ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
89 :
90 : // XEnumerationAccess
91 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XEnumeration > SAL_CALL
92 : createEnumeration() throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
93 :
94 : // XElementAccess
95 : virtual ::com::sun::star::uno::Type SAL_CALL getElementType()
96 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
97 : virtual sal_Bool SAL_CALL hasElements() throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
98 :
99 : // XContainer
100 : virtual void SAL_CALL addContainerListener( const ::com::sun::star::uno::Reference<
101 : ::com::sun::star::container::XContainerListener >& xListener )
102 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
103 : virtual void SAL_CALL removeContainerListener( const ::com::sun::star::uno::Reference<
104 : ::com::sun::star::container::XContainerListener >& xListener )
105 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
106 :
107 : // XRefreshable
108 : virtual void SAL_CALL refresh( )
109 : throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
110 : virtual void SAL_CALL addRefreshListener( const ::com::sun::star::uno::Reference<
111 : ::com::sun::star::util::XRefreshListener >& l )
112 : throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
113 : virtual void SAL_CALL removeRefreshListener( const ::com::sun::star::uno::Reference<
114 : ::com::sun::star::util::XRefreshListener >& l )
115 : throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
116 :
117 : // XServiceInfo
118 : virtual OUString SAL_CALL getImplementationName()
119 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
120 : virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName )
121 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
122 : virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames()
123 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
124 : };
125 :
126 : class ScHeaderFieldsObj : public cppu::WeakImplHelper5<
127 : com::sun::star::container::XEnumerationAccess,
128 : com::sun::star::container::XIndexAccess,
129 : com::sun::star::container::XContainer,
130 : com::sun::star::util::XRefreshable,
131 : com::sun::star::lang::XServiceInfo >
132 : {
133 : private:
134 : ScHeaderFooterTextData& mrData;
135 : ScEditSource* mpEditSource;
136 :
137 : /// List of refresh listeners.
138 : cppu::OInterfaceContainerHelper* mpRefreshListeners;
139 : /// mutex to lock the InterfaceContainerHelper
140 : osl::Mutex aMutex;
141 :
142 : com::sun::star::uno::Reference<
143 : com::sun::star::text::XTextField>
144 : GetObjectByIndex_Impl(sal_Int32 Index) const;
145 :
146 : public:
147 : ScHeaderFieldsObj(ScHeaderFooterTextData& rData);
148 : virtual ~ScHeaderFieldsObj();
149 :
150 : // XIndexAccess
151 : virtual sal_Int32 SAL_CALL getCount() throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
152 : virtual ::com::sun::star::uno::Any SAL_CALL getByIndex( sal_Int32 Index )
153 : throw(::com::sun::star::lang::IndexOutOfBoundsException,
154 : ::com::sun::star::lang::WrappedTargetException,
155 : ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
156 :
157 : // XEnumerationAccess
158 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XEnumeration > SAL_CALL
159 : createEnumeration() throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
160 :
161 : // XElementAccess
162 : virtual ::com::sun::star::uno::Type SAL_CALL getElementType()
163 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
164 : virtual sal_Bool SAL_CALL hasElements() throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
165 :
166 : // XContainer
167 : virtual void SAL_CALL addContainerListener( const ::com::sun::star::uno::Reference<
168 : ::com::sun::star::container::XContainerListener >& xListener )
169 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
170 : virtual void SAL_CALL removeContainerListener( const ::com::sun::star::uno::Reference<
171 : ::com::sun::star::container::XContainerListener >& xListener )
172 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
173 :
174 : // XRefreshable
175 : virtual void SAL_CALL refresh( )
176 : throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
177 : virtual void SAL_CALL addRefreshListener( const ::com::sun::star::uno::Reference<
178 : ::com::sun::star::util::XRefreshListener >& l )
179 : throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
180 : virtual void SAL_CALL removeRefreshListener( const ::com::sun::star::uno::Reference<
181 : ::com::sun::star::util::XRefreshListener >& l )
182 : throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
183 :
184 : // XServiceInfo
185 : virtual OUString SAL_CALL getImplementationName()
186 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
187 : virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName )
188 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
189 : virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames()
190 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
191 : };
192 :
193 : /**
194 : * Generic UNO wrapper for edit engine's field item in cells, headers, and
195 : * footers.
196 : */
197 : class ScEditFieldObj : public cppu::WeakImplHelper4<
198 : com::sun::star::text::XTextField,
199 : com::sun::star::beans::XPropertySet,
200 : com::sun::star::lang::XUnoTunnel,
201 : com::sun::star::lang::XServiceInfo>,
202 : public ScMutexHelper,
203 : public ::cppu::OComponentHelper,
204 : private boost::noncopyable
205 : {
206 : const SfxItemPropertySet* pPropSet;
207 : ScEditSource* mpEditSource;
208 : ESelection aSelection;
209 :
210 : sal_Int32 meType;
211 : boost::scoped_ptr<SvxFieldData> mpData;
212 : com::sun::star::uno::Reference<com::sun::star::text::XTextRange> mpContent;
213 :
214 : com::sun::star::util::DateTime maDateTime;
215 : sal_Int32 mnNumFormat;
216 : bool mbIsDate:1;
217 : bool mbIsFixed:1;
218 :
219 : private:
220 : ScEditFieldObj(); // disabled
221 :
222 : SvxFieldData* getData();
223 :
224 : void setPropertyValueURL(const OUString& rName, const com::sun::star::uno::Any& rVal);
225 : com::sun::star::uno::Any getPropertyValueURL(const OUString& rName);
226 :
227 : void setPropertyValueFile(const OUString& rName, const com::sun::star::uno::Any& rVal);
228 : com::sun::star::uno::Any getPropertyValueFile(const OUString& rName);
229 :
230 : void setPropertyValueDateTime(const OUString& rName, const com::sun::star::uno::Any& rVal);
231 : com::sun::star::uno::Any getPropertyValueDateTime(const OUString& rName);
232 :
233 : void setPropertyValueSheet(const OUString& rName, const com::sun::star::uno::Any& rVal);
234 :
235 : public:
236 : static const com::sun::star::uno::Sequence<sal_Int8>& getUnoTunnelId();
237 : static ScEditFieldObj* getImplementation(const com::sun::star::uno::Reference<com::sun::star::text::XTextContent>& xObj);
238 :
239 : ScEditFieldObj(
240 : const com::sun::star::uno::Reference<com::sun::star::text::XTextRange>& rContent,
241 : ScEditSource* pEditSrc, sal_Int32 eType, const ESelection& rSel);
242 : virtual ~ScEditFieldObj();
243 :
244 6 : sal_Int32 GetFieldType() const { return meType;}
245 : void DeleteField();
246 : bool IsInserted() const;
247 : SvxFieldItem CreateFieldItem();
248 : void InitDoc(
249 : const com::sun::star::uno::Reference<com::sun::star::text::XTextRange>& rContent,
250 : ScEditSource* pEditSrc, const ESelection& rSel);
251 :
252 : // XTextField
253 : virtual OUString SAL_CALL getPresentation( sal_Bool bShowCommand )
254 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
255 :
256 : // XTextContent
257 : virtual void SAL_CALL attach( const ::com::sun::star::uno::Reference<
258 : ::com::sun::star::text::XTextRange >& xTextRange )
259 : throw(::com::sun::star::lang::IllegalArgumentException,
260 : ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
261 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::text::XTextRange > SAL_CALL
262 : getAnchor() throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
263 :
264 : // XComponent
265 : virtual void SAL_CALL dispose() throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
266 : virtual void SAL_CALL addEventListener( const ::com::sun::star::uno::Reference<
267 : ::com::sun::star::lang::XEventListener >& xListener )
268 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
269 : virtual void SAL_CALL removeEventListener( const ::com::sun::star::uno::Reference<
270 : ::com::sun::star::lang::XEventListener >& aListener )
271 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
272 :
273 : // XPropertySet
274 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo >
275 : SAL_CALL getPropertySetInfo()
276 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
277 : virtual void SAL_CALL setPropertyValue( const OUString& aPropertyName,
278 : const ::com::sun::star::uno::Any& aValue )
279 : throw (::com::sun::star::beans::UnknownPropertyException,
280 : ::com::sun::star::beans::PropertyVetoException,
281 : ::com::sun::star::lang::IllegalArgumentException,
282 : ::com::sun::star::lang::WrappedTargetException,
283 : ::com::sun::star::uno::RuntimeException,
284 : std::exception) SAL_OVERRIDE;
285 : virtual ::com::sun::star::uno::Any SAL_CALL getPropertyValue(
286 : const OUString& PropertyName )
287 : throw(::com::sun::star::beans::UnknownPropertyException,
288 : ::com::sun::star::lang::WrappedTargetException,
289 : ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
290 : virtual void SAL_CALL addPropertyChangeListener( const OUString& aPropertyName,
291 : const ::com::sun::star::uno::Reference<
292 : ::com::sun::star::beans::XPropertyChangeListener >& xListener )
293 : throw(::com::sun::star::beans::UnknownPropertyException,
294 : ::com::sun::star::lang::WrappedTargetException,
295 : ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
296 : virtual void SAL_CALL removePropertyChangeListener( const OUString& aPropertyName,
297 : const ::com::sun::star::uno::Reference<
298 : ::com::sun::star::beans::XPropertyChangeListener >& aListener )
299 : throw(::com::sun::star::beans::UnknownPropertyException,
300 : ::com::sun::star::lang::WrappedTargetException,
301 : ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
302 : virtual void SAL_CALL addVetoableChangeListener( const OUString& PropertyName,
303 : const ::com::sun::star::uno::Reference<
304 : ::com::sun::star::beans::XVetoableChangeListener >& aListener )
305 : throw(::com::sun::star::beans::UnknownPropertyException,
306 : ::com::sun::star::lang::WrappedTargetException,
307 : ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
308 : virtual void SAL_CALL removeVetoableChangeListener( const OUString& PropertyName,
309 : const ::com::sun::star::uno::Reference<
310 : ::com::sun::star::beans::XVetoableChangeListener >& aListener )
311 : throw(::com::sun::star::beans::UnknownPropertyException,
312 : ::com::sun::star::lang::WrappedTargetException,
313 : ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
314 :
315 : // XUnoTunnel
316 : virtual sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence<
317 : sal_Int8 >& aIdentifier )
318 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
319 :
320 : // XServiceInfo
321 : virtual OUString SAL_CALL getImplementationName()
322 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
323 : virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName )
324 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
325 : virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames()
326 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
327 :
328 : // XTypeProvider
329 : virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes()
330 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
331 : virtual ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId()
332 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
333 : };
334 :
335 : #endif
336 :
337 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|