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