xref: /aoo41x/main/sc/inc/fielduno.hxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef SC_FIELDUNO_HXX
29 #define SC_FIELDUNO_HXX
30 
31 #include "address.hxx"
32 #include "mutexhlp.hxx"
33 
34 #include <svl/lstner.hxx>
35 #include <svl/itemprop.hxx>
36 #include <editeng/editdata.hxx>
37 #include <com/sun/star/text/XTextField.hpp>
38 #include <com/sun/star/lang/XServiceInfo.hpp>
39 #include <com/sun/star/container/XContainer.hpp>
40 #include <com/sun/star/lang/XUnoTunnel.hpp>
41 #include <com/sun/star/container/XEnumerationAccess.hpp>
42 #include <com/sun/star/container/XIndexAccess.hpp>
43 #include <com/sun/star/beans/XPropertySet.hpp>
44 #include <com/sun/star/util/XRefreshable.hpp>
45 #include <cppuhelper/component.hxx>
46 #include <cppuhelper/implbase5.hxx>
47 #include <osl/mutex.hxx>
48 
49 class SvxEditSource;
50 class SvxFieldItem;
51 class ScCellFieldObj;
52 class ScHeaderFieldObj;
53 class ScHeaderFooterContentObj;
54 class ScDocShell;
55 
56 
57 //------------------------------------------------------------------
58 
59 
60 class ScCellFieldsObj : public cppu::WeakImplHelper5<
61 							com::sun::star::container::XEnumerationAccess,
62 							com::sun::star::container::XIndexAccess,
63 							com::sun::star::container::XContainer,
64                             com::sun::star::util::XRefreshable,
65 							com::sun::star::lang::XServiceInfo >,
66 						public SfxListener
67 {
68 private:
69 	ScDocShell*				pDocShell;
70 	ScAddress				aCellPos;
71 	SvxEditSource*			pEditSource;
72     ///	List of refresh listeners.
73 	cppu::OInterfaceContainerHelper* mpRefreshListeners;
74     /// mutex to lock the InterfaceContainerHelper
75     osl::Mutex              aMutex;
76 
77 	ScCellFieldObj*			GetObjectByIndex_Impl(sal_Int32 Index) const;
78 
79 public:
80 							ScCellFieldsObj(ScDocShell* pDocSh, const ScAddress& rPos);
81 	virtual					~ScCellFieldsObj();
82 
83 	virtual void			Notify( SfxBroadcaster& rBC, const SfxHint& rHint );
84 
85 							// XIndexAccess
86 	virtual sal_Int32 SAL_CALL getCount() throw(::com::sun::star::uno::RuntimeException);
87 	virtual ::com::sun::star::uno::Any SAL_CALL getByIndex( sal_Int32 Index )
88 								throw(::com::sun::star::lang::IndexOutOfBoundsException,
89 									::com::sun::star::lang::WrappedTargetException,
90 									::com::sun::star::uno::RuntimeException);
91 
92 							// XEnumerationAccess
93 	virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XEnumeration > SAL_CALL
94 							createEnumeration() throw(::com::sun::star::uno::RuntimeException);
95 
96 							// XElementAccess
97 	virtual ::com::sun::star::uno::Type SAL_CALL getElementType()
98 								throw(::com::sun::star::uno::RuntimeException);
99 	virtual sal_Bool SAL_CALL hasElements() throw(::com::sun::star::uno::RuntimeException);
100 
101 							// XContainer
102 	virtual void SAL_CALL	addContainerListener( const ::com::sun::star::uno::Reference<
103 								::com::sun::star::container::XContainerListener >& xListener )
104 									throw(::com::sun::star::uno::RuntimeException);
105 	virtual void SAL_CALL	removeContainerListener( const ::com::sun::star::uno::Reference<
106 								::com::sun::star::container::XContainerListener >& xListener )
107 									throw(::com::sun::star::uno::RuntimeException);
108 
109                             // XRefreshable
110     virtual void SAL_CALL refresh(  )
111                                     throw (::com::sun::star::uno::RuntimeException);
112     virtual void SAL_CALL addRefreshListener( const ::com::sun::star::uno::Reference<
113                                 ::com::sun::star::util::XRefreshListener >& l )
114                                     throw (::com::sun::star::uno::RuntimeException);
115     virtual void SAL_CALL removeRefreshListener( const ::com::sun::star::uno::Reference<
116                                 ::com::sun::star::util::XRefreshListener >& l )
117                                     throw (::com::sun::star::uno::RuntimeException);
118 
119 							// XServiceInfo
120 	virtual ::rtl::OUString SAL_CALL getImplementationName()
121 								throw(::com::sun::star::uno::RuntimeException);
122 	virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName )
123 								throw(::com::sun::star::uno::RuntimeException);
124 	virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames()
125 								throw(::com::sun::star::uno::RuntimeException);
126 };
127 
128 
129 class ScCellFieldObj : public ScMutexHelper,
130 						public ::cppu::OComponentHelper,
131 						public ::com::sun::star::text::XTextField,
132 						public ::com::sun::star::beans::XPropertySet,
133 						public ::com::sun::star::lang::XUnoTunnel,
134 						public ::com::sun::star::lang::XServiceInfo,
135 						public SfxListener
136 {
137 private:
138 	const SfxItemPropertySet*		pPropSet;
139 	ScDocShell*				pDocShell;
140 	ScAddress				aCellPos;
141 	SvxEditSource*			pEditSource;
142 	ESelection				aSelection;
143 
144 	String					aUrl;				// Inhalt, wenn noch nicht eingefuegt (nur dann!)
145 	String					aRepresentation;
146 	String					aTarget;
147 
148 	ScCellFieldObj(); // disabled
149 public:
150 							ScCellFieldObj(ScDocShell* pDocSh, const ScAddress& rPos,
151 											const ESelection& rSel);
152 	virtual					~ScCellFieldObj();
153 
154 	virtual void			Notify( SfxBroadcaster& rBC, const SfxHint& rHint );
155 
156 							// per getImplementation gerufen:
157 	void					DeleteField();
158 	sal_Bool					IsInserted() const		{ return pEditSource != NULL; }
159 	SvxFieldItem			CreateFieldItem();
160 	void					InitDoc( ScDocShell* pDocSh, const ScAddress& rPos,
161 										const ESelection& rSel );
162 
163 	virtual ::com::sun::star::uno::Any SAL_CALL queryAggregation(
164 								const ::com::sun::star::uno::Type & rType )
165 									throw(::com::sun::star::uno::RuntimeException);
166 	virtual ::com::sun::star::uno::Any SAL_CALL queryInterface(
167 								const ::com::sun::star::uno::Type & rType )
168 									throw(::com::sun::star::uno::RuntimeException);
169 	virtual void SAL_CALL	acquire() throw();
170 	virtual void SAL_CALL	release() throw();
171 
172 							// XTextField
173 	virtual ::rtl::OUString SAL_CALL getPresentation( sal_Bool bShowCommand )
174 								throw(::com::sun::star::uno::RuntimeException);
175 
176 							// XTextContent
177 	virtual void SAL_CALL	attach( const ::com::sun::star::uno::Reference<
178 								::com::sun::star::text::XTextRange >& xTextRange )
179 									throw(::com::sun::star::lang::IllegalArgumentException,
180 											::com::sun::star::uno::RuntimeException);
181 	virtual ::com::sun::star::uno::Reference< ::com::sun::star::text::XTextRange > SAL_CALL
182 							getAnchor() throw(::com::sun::star::uno::RuntimeException);
183 
184 							// XComponent
185 	virtual void SAL_CALL	dispose() throw(::com::sun::star::uno::RuntimeException);
186 	virtual void SAL_CALL	addEventListener( const ::com::sun::star::uno::Reference<
187 								::com::sun::star::lang::XEventListener >& xListener )
188 									throw(::com::sun::star::uno::RuntimeException);
189 	virtual void SAL_CALL	removeEventListener( const ::com::sun::star::uno::Reference<
190 								::com::sun::star::lang::XEventListener >& aListener )
191 									throw(::com::sun::star::uno::RuntimeException);
192 
193 							// XPropertySet
194 	virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo >
195 							SAL_CALL getPropertySetInfo()
196 								throw(::com::sun::star::uno::RuntimeException);
197 	virtual void SAL_CALL	setPropertyValue( const ::rtl::OUString& aPropertyName,
198 									const ::com::sun::star::uno::Any& aValue )
199 								throw(::com::sun::star::beans::UnknownPropertyException,
200 									::com::sun::star::beans::PropertyVetoException,
201 									::com::sun::star::lang::IllegalArgumentException,
202 									::com::sun::star::lang::WrappedTargetException,
203 									::com::sun::star::uno::RuntimeException);
204 	virtual ::com::sun::star::uno::Any SAL_CALL getPropertyValue(
205 									const ::rtl::OUString& PropertyName )
206 								throw(::com::sun::star::beans::UnknownPropertyException,
207 									::com::sun::star::lang::WrappedTargetException,
208 									::com::sun::star::uno::RuntimeException);
209 	virtual void SAL_CALL	addPropertyChangeListener( const ::rtl::OUString& aPropertyName,
210 									const ::com::sun::star::uno::Reference<
211 										::com::sun::star::beans::XPropertyChangeListener >& xListener )
212 								throw(::com::sun::star::beans::UnknownPropertyException,
213 									::com::sun::star::lang::WrappedTargetException,
214 									::com::sun::star::uno::RuntimeException);
215 	virtual void SAL_CALL	removePropertyChangeListener( const ::rtl::OUString& aPropertyName,
216 									const ::com::sun::star::uno::Reference<
217 										::com::sun::star::beans::XPropertyChangeListener >& aListener )
218 								throw(::com::sun::star::beans::UnknownPropertyException,
219 									::com::sun::star::lang::WrappedTargetException,
220 									::com::sun::star::uno::RuntimeException);
221 	virtual void SAL_CALL	addVetoableChangeListener( const ::rtl::OUString& PropertyName,
222 									const ::com::sun::star::uno::Reference<
223 										::com::sun::star::beans::XVetoableChangeListener >& aListener )
224 								throw(::com::sun::star::beans::UnknownPropertyException,
225 									::com::sun::star::lang::WrappedTargetException,
226 									::com::sun::star::uno::RuntimeException);
227 	virtual void SAL_CALL	removeVetoableChangeListener( const ::rtl::OUString& PropertyName,
228 									const ::com::sun::star::uno::Reference<
229 										::com::sun::star::beans::XVetoableChangeListener >& aListener )
230 								throw(::com::sun::star::beans::UnknownPropertyException,
231 									::com::sun::star::lang::WrappedTargetException,
232 									::com::sun::star::uno::RuntimeException);
233 
234 							// XUnoTunnel
235 	virtual sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence<
236 									sal_Int8 >& aIdentifier )
237 								throw(::com::sun::star::uno::RuntimeException);
238 
239 	static const com::sun::star::uno::Sequence<sal_Int8>& getUnoTunnelId();
240 	static ScCellFieldObj* getImplementation( const com::sun::star::uno::Reference<
241 									com::sun::star::text::XTextContent> xObj );
242 
243 							// XServiceInfo
244 	virtual ::rtl::OUString SAL_CALL getImplementationName()
245 								throw(::com::sun::star::uno::RuntimeException);
246 	virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName )
247 								throw(::com::sun::star::uno::RuntimeException);
248 	virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames()
249 								throw(::com::sun::star::uno::RuntimeException);
250 
251 							// XTypeProvider
252 	virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes()
253 								throw(::com::sun::star::uno::RuntimeException);
254 	virtual ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId()
255 								throw(::com::sun::star::uno::RuntimeException);
256 };
257 
258 //------------------------------------------------------------------
259 
260 class ScHeaderFieldsObj : public cppu::WeakImplHelper5<
261 							com::sun::star::container::XEnumerationAccess,
262 							com::sun::star::container::XIndexAccess,
263 							com::sun::star::container::XContainer,
264                             com::sun::star::util::XRefreshable,
265 							com::sun::star::lang::XServiceInfo >
266 {
267 private:
268 	ScHeaderFooterContentObj*	pContentObj;
269 	sal_uInt16						nPart;
270 	sal_uInt16						nType;
271 	SvxEditSource*				pEditSource;
272 
273     ///	List of refresh listeners.
274 	cppu::OInterfaceContainerHelper* mpRefreshListeners;
275     /// mutex to lock the InterfaceContainerHelper
276     osl::Mutex                  aMutex;
277 
278 	ScHeaderFieldObj*		GetObjectByIndex_Impl(sal_Int32 Index) const;
279 
280 public:
281 							ScHeaderFieldsObj(ScHeaderFooterContentObj* pContent,
282 												sal_uInt16 nP, sal_uInt16 nT);
283 	virtual					~ScHeaderFieldsObj();
284 
285 							// XIndexAccess
286 	virtual sal_Int32 SAL_CALL getCount() throw(::com::sun::star::uno::RuntimeException);
287 	virtual ::com::sun::star::uno::Any SAL_CALL getByIndex( sal_Int32 Index )
288 								throw(::com::sun::star::lang::IndexOutOfBoundsException,
289 									::com::sun::star::lang::WrappedTargetException,
290 									::com::sun::star::uno::RuntimeException);
291 
292 							// XEnumerationAccess
293 	virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XEnumeration > SAL_CALL
294 							createEnumeration() throw(::com::sun::star::uno::RuntimeException);
295 
296 							// XElementAccess
297 	virtual ::com::sun::star::uno::Type SAL_CALL getElementType()
298 								throw(::com::sun::star::uno::RuntimeException);
299 	virtual sal_Bool SAL_CALL hasElements() throw(::com::sun::star::uno::RuntimeException);
300 
301 							// XContainer
302 	virtual void SAL_CALL	addContainerListener( const ::com::sun::star::uno::Reference<
303 								::com::sun::star::container::XContainerListener >& xListener )
304 									throw(::com::sun::star::uno::RuntimeException);
305 	virtual void SAL_CALL	removeContainerListener( const ::com::sun::star::uno::Reference<
306 								::com::sun::star::container::XContainerListener >& xListener )
307 									throw(::com::sun::star::uno::RuntimeException);
308 
309                             // XRefreshable
310     virtual void SAL_CALL refresh(  )
311                                     throw (::com::sun::star::uno::RuntimeException);
312     virtual void SAL_CALL addRefreshListener( const ::com::sun::star::uno::Reference<
313                                 ::com::sun::star::util::XRefreshListener >& l )
314                                     throw (::com::sun::star::uno::RuntimeException);
315     virtual void SAL_CALL removeRefreshListener( const ::com::sun::star::uno::Reference<
316                                 ::com::sun::star::util::XRefreshListener >& l )
317                                     throw (::com::sun::star::uno::RuntimeException);
318 
319                             // XServiceInfo
320 	virtual ::rtl::OUString SAL_CALL getImplementationName()
321 								throw(::com::sun::star::uno::RuntimeException);
322 	virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName )
323 								throw(::com::sun::star::uno::RuntimeException);
324 	virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames()
325 								throw(::com::sun::star::uno::RuntimeException);
326 };
327 
328 
329 class ScHeaderFieldObj : public ScMutexHelper,
330 							public ::cppu::OComponentHelper,
331 							public ::com::sun::star::text::XTextField,
332 							public ::com::sun::star::beans::XPropertySet,
333 							public ::com::sun::star::lang::XUnoTunnel,
334 							public ::com::sun::star::lang::XServiceInfo
335 {
336 private:
337 	const SfxItemPropertySet*   pPropSet;
338 	ScHeaderFooterContentObj*	pContentObj;
339 	sal_uInt16						nPart;
340 	sal_uInt16						nType;
341 	SvxEditSource*				pEditSource;
342 	ESelection					aSelection;
343 	sal_Int16					nFileFormat;		// enum SvxFileFormat, valid if not inserted
344 
345     ScHeaderFieldObj(); // disabled
346 public:
347 							ScHeaderFieldObj(ScHeaderFooterContentObj* pContent, sal_uInt16 nP,
348 											sal_uInt16 nT, const ESelection& rSel);
349 	virtual					~ScHeaderFieldObj();
350 
351 							// per getImplementation gerufen:
352 	void					DeleteField();
353 	sal_Bool					IsInserted() const		{ return pEditSource != NULL; }
354 	SvxFieldItem			CreateFieldItem();
355 	void					InitDoc( ScHeaderFooterContentObj* pContent, sal_uInt16 nP,
356 										const ESelection& rSel );
357 
358 	virtual ::com::sun::star::uno::Any SAL_CALL queryAggregation(
359 								const ::com::sun::star::uno::Type & rType )
360 									throw(::com::sun::star::uno::RuntimeException);
361 	virtual ::com::sun::star::uno::Any SAL_CALL queryInterface(
362 								const ::com::sun::star::uno::Type & rType )
363 									throw(::com::sun::star::uno::RuntimeException);
364 	virtual void SAL_CALL	acquire() throw();
365 	virtual void SAL_CALL	release() throw();
366 
367 							// XTextField
368 	virtual ::rtl::OUString SAL_CALL getPresentation( sal_Bool bShowCommand )
369 								throw(::com::sun::star::uno::RuntimeException);
370 
371 							// XTextContent
372 	virtual void SAL_CALL	attach( const ::com::sun::star::uno::Reference<
373 								::com::sun::star::text::XTextRange >& xTextRange )
374 									throw(::com::sun::star::lang::IllegalArgumentException,
375 											::com::sun::star::uno::RuntimeException);
376 	virtual ::com::sun::star::uno::Reference< ::com::sun::star::text::XTextRange > SAL_CALL
377 							getAnchor() throw(::com::sun::star::uno::RuntimeException);
378 
379 							// XComponent
380 	virtual void SAL_CALL	dispose() throw(::com::sun::star::uno::RuntimeException);
381 	virtual void SAL_CALL	addEventListener( const ::com::sun::star::uno::Reference<
382 								::com::sun::star::lang::XEventListener >& xListener )
383 									throw(::com::sun::star::uno::RuntimeException);
384 	virtual void SAL_CALL	removeEventListener( const ::com::sun::star::uno::Reference<
385 								::com::sun::star::lang::XEventListener >& aListener )
386 									throw(::com::sun::star::uno::RuntimeException);
387 
388 							// XPropertySet
389 	virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo >
390 							SAL_CALL getPropertySetInfo()
391 								throw(::com::sun::star::uno::RuntimeException);
392 	virtual void SAL_CALL	setPropertyValue( const ::rtl::OUString& aPropertyName,
393 									const ::com::sun::star::uno::Any& aValue )
394 								throw(::com::sun::star::beans::UnknownPropertyException,
395 									::com::sun::star::beans::PropertyVetoException,
396 									::com::sun::star::lang::IllegalArgumentException,
397 									::com::sun::star::lang::WrappedTargetException,
398 									::com::sun::star::uno::RuntimeException);
399 	virtual ::com::sun::star::uno::Any SAL_CALL getPropertyValue(
400 									const ::rtl::OUString& PropertyName )
401 								throw(::com::sun::star::beans::UnknownPropertyException,
402 									::com::sun::star::lang::WrappedTargetException,
403 									::com::sun::star::uno::RuntimeException);
404 	virtual void SAL_CALL	addPropertyChangeListener( const ::rtl::OUString& aPropertyName,
405 									const ::com::sun::star::uno::Reference<
406 										::com::sun::star::beans::XPropertyChangeListener >& xListener )
407 								throw(::com::sun::star::beans::UnknownPropertyException,
408 									::com::sun::star::lang::WrappedTargetException,
409 									::com::sun::star::uno::RuntimeException);
410 	virtual void SAL_CALL	removePropertyChangeListener( const ::rtl::OUString& aPropertyName,
411 									const ::com::sun::star::uno::Reference<
412 										::com::sun::star::beans::XPropertyChangeListener >& aListener )
413 								throw(::com::sun::star::beans::UnknownPropertyException,
414 									::com::sun::star::lang::WrappedTargetException,
415 									::com::sun::star::uno::RuntimeException);
416 	virtual void SAL_CALL	addVetoableChangeListener( const ::rtl::OUString& PropertyName,
417 									const ::com::sun::star::uno::Reference<
418 										::com::sun::star::beans::XVetoableChangeListener >& aListener )
419 								throw(::com::sun::star::beans::UnknownPropertyException,
420 									::com::sun::star::lang::WrappedTargetException,
421 									::com::sun::star::uno::RuntimeException);
422 	virtual void SAL_CALL	removeVetoableChangeListener( const ::rtl::OUString& PropertyName,
423 									const ::com::sun::star::uno::Reference<
424 										::com::sun::star::beans::XVetoableChangeListener >& aListener )
425 								throw(::com::sun::star::beans::UnknownPropertyException,
426 									::com::sun::star::lang::WrappedTargetException,
427 									::com::sun::star::uno::RuntimeException);
428 
429 							// XUnoTunnel
430 	virtual sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence<
431 									sal_Int8 >& aIdentifier )
432 								throw(::com::sun::star::uno::RuntimeException);
433 
434 	static const com::sun::star::uno::Sequence<sal_Int8>& getUnoTunnelId();
435 	static ScHeaderFieldObj* getImplementation( const com::sun::star::uno::Reference<
436 									com::sun::star::text::XTextContent> xObj );
437 
438 							// XServiceInfo
439 	virtual ::rtl::OUString SAL_CALL getImplementationName()
440 								throw(::com::sun::star::uno::RuntimeException);
441 	virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName )
442 								throw(::com::sun::star::uno::RuntimeException);
443 	virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames()
444 								throw(::com::sun::star::uno::RuntimeException);
445 
446 							// XTypeProvider
447 	virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes()
448 								throw(::com::sun::star::uno::RuntimeException);
449 	virtual ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId()
450 								throw(::com::sun::star::uno::RuntimeException);
451 };
452 
453 #endif
454 
455