xref: /aoo42x/main/sw/inc/unofield.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 #ifndef _UNOFIELD_HXX
28 #define _UNOFIELD_HXX
29 
30 #include <com/sun/star/lang/XUnoTunnel.hpp>
31 #include <com/sun/star/util/XRefreshable.hpp>
32 #include <com/sun/star/util/XUpdatable.hpp>
33 #include <com/sun/star/text/XDependentTextField.hpp>
34 
35 #include <cppuhelper/implbase5.hxx>
36 
37 #include <calbck.hxx>
38 #include <unocoll.hxx>
39 #include <RefreshListenerContainer.hxx>
40 
41 
42 class SwFieldType;
43 class SwDoc;
44 class SwFmtFld;
45 class SwField;
46 class SwSetExpField;
47 class SwTextAPIObject;
48 
49 /* -----------------04.12.98 12:49-------------------
50  *
51  * --------------------------------------------------*/
52 class SwXFieldMaster : public cppu::WeakImplHelper4
53 <
54 	::com::sun::star::beans::XPropertySet,
55 	::com::sun::star::lang::XServiceInfo,
56 	::com::sun::star::lang::XUnoTunnel,
57 	::com::sun::star::lang::XComponent
58 >,
59 	public SwClient
60 {
61 	SwEventListenerContainer	aLstnrCntnr;
62     sal_uInt16                  nResTypeId;
63 	SwDoc* 						m_pDoc;
64 
65     sal_Bool                    m_bIsDescriptor;
66 
67 	String 						sParam1;	//Content / Database / NumberingSeparator
68 	String 						sParam2;    // -	/DataTablename
69 	String 						sParam3;    // -	/DataFieldName
70     String                      sParam4;
71     String                      sParam5;    // -    /DataBaseURL
72     String                      sParam6;    // -    /DataBaseResource
73 	double						fParam1;	// Value / -
74 	sal_Int8					nParam1;	// ChapterNumberingLevel
75 	sal_Bool					bParam1;    // IsExpression
76     sal_Int32                   nParam2;
77 
78 protected:
79 	virtual ~SwXFieldMaster();
80 	//SwClient
81 virtual void Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew);
82 
83 public:
84 
85 	SwXFieldMaster(SwDoc* pDoc, sal_uInt16 nResId);
86 	SwXFieldMaster(SwFieldType& rType, SwDoc* pDoc);
87 
88 
89 	TYPEINFO();
90 
91 	static const ::com::sun::star::uno::Sequence< sal_Int8 > & getUnoTunnelId();
92 
93 	//XUnoTunnel
94 	virtual sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& aIdentifier ) throw(::com::sun::star::uno::RuntimeException);
95 
96 	//XPropertySet
97     virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo(  ) throw(::com::sun::star::uno::RuntimeException);
98     virtual void SAL_CALL setPropertyValue( const ::rtl::OUString& aPropertyName, const ::com::sun::star::uno::Any& aValue ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
99     virtual ::com::sun::star::uno::Any SAL_CALL getPropertyValue( const ::rtl::OUString& PropertyName ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
100     virtual void SAL_CALL addPropertyChangeListener( const ::rtl::OUString& aPropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener >& xListener ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
101     virtual void SAL_CALL removePropertyChangeListener( const ::rtl::OUString& aPropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener >& aListener ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
102     virtual void SAL_CALL addVetoableChangeListener( const ::rtl::OUString& PropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XVetoableChangeListener >& aListener ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
103     virtual void SAL_CALL removeVetoableChangeListener( const ::rtl::OUString& PropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XVetoableChangeListener >& aListener ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
104 
105 	//XComponent
106 	virtual void SAL_CALL dispose(void) throw( ::com::sun::star::uno::RuntimeException );
107 	virtual void SAL_CALL addEventListener(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener > & aListener) throw( ::com::sun::star::uno::RuntimeException );
108 	virtual void SAL_CALL removeEventListener(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener > & aListener) throw( ::com::sun::star::uno::RuntimeException );
109 
110 	//XServiceInfo
111 	virtual rtl::OUString SAL_CALL getImplementationName(void) throw( ::com::sun::star::uno::RuntimeException );
112 	virtual sal_Bool SAL_CALL supportsService(const rtl::OUString& ServiceName) throw( ::com::sun::star::uno::RuntimeException );
113 	virtual ::com::sun::star::uno::Sequence< rtl::OUString > SAL_CALL getSupportedServiceNames(void) throw( ::com::sun::star::uno::RuntimeException );
114 
115 	static rtl::OUString GetProgrammaticName(const SwFieldType& rType, SwDoc& rDoc);
116 	static rtl::OUString LocalizeFormula(const SwSetExpField& rFld, const rtl::OUString& rFormula, sal_Bool bQuery);
117 
118     SwFieldType* GetFldType(sal_Bool bDontCreate = sal_False) const;
119 	SwDoc*		GetDoc() {return m_pDoc;}
120 
121 	sal_Bool		IsDescriptor()const  {return m_bIsDescriptor;}
122 	sal_uInt16 		GetResId() const {return nResTypeId;}
123 };
124 
125 struct SwFieldProperties_Impl;
126 class SwXTextField : public cppu::WeakImplHelper5
127 <
128 	::com::sun::star::text::XDependentTextField,
129 	::com::sun::star::lang::XServiceInfo,
130 	::com::sun::star::beans::XPropertySet,
131     ::com::sun::star::lang::XUnoTunnel,
132     ::com::sun::star::util::XUpdatable
133 >,
134 			public SwClient
135 {
136 	SwEventListenerContainer	aLstnrCntnr;
137 	const SwFmtFld* 			pFmtFld;
138 	SwDoc* 						m_pDoc;
139 	SwTextAPIObject*			m_pTextObject;
140 
141 	sal_Bool 						m_bIsDescriptor;
142     SwClient                        m_aFieldTypeClient; // required to access field master of not yet inserted fields
143     sal_Bool                        m_bCallUpdate;
144     sal_uInt16                      m_nServiceId;
145 	SwFieldProperties_Impl* 	m_pProps;
146 	String 						m_sTypeName;
147 
148 
149 	//SwFieldType* GetFldType() const { return (SwFieldType*)GetRegisteredIn(); }
150 	SwDoc* 		 GetDoc() {return m_pDoc;}
151 protected:
152 	virtual ~SwXTextField();
153     //SwClient
154    virtual void Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew);
155 
156 public:
157 	SwXTextField(sal_uInt16 nServiceId, SwDoc* pDoc=0);
158 	SwXTextField(const SwFmtFld& rFmt, SwDoc* pDoc);
159 
160 
161 	TYPEINFO();
162 
163 	static const ::com::sun::star::uno::Sequence< sal_Int8 > & getUnoTunnelId();
164 
165 	//XUnoTunnel
166 	virtual sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& aIdentifier ) throw(::com::sun::star::uno::RuntimeException);
167 
168 	//XDependentTextField
169 	virtual void SAL_CALL attachTextFieldMaster(const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > & xFieldMaster) throw( ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException );
170 	virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >  SAL_CALL getTextFieldMaster(void) throw( ::com::sun::star::uno::RuntimeException );
171 
172 	//XTextField
173 	virtual rtl::OUString SAL_CALL getPresentation(sal_Bool bShowCommand) throw( ::com::sun::star::uno::RuntimeException );
174 
175 	//XTextContent
176 	virtual void SAL_CALL attach(const ::com::sun::star::uno::Reference< ::com::sun::star::text::XTextRange > & xTextRange) throw( ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException );
177 	virtual ::com::sun::star::uno::Reference< ::com::sun::star::text::XTextRange >  SAL_CALL getAnchor(void) throw( ::com::sun::star::uno::RuntimeException );
178 
179 	//XComponent
180 	virtual void SAL_CALL dispose(void) throw( ::com::sun::star::uno::RuntimeException );
181 	virtual void SAL_CALL addEventListener(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener > & aListener) throw( ::com::sun::star::uno::RuntimeException );
182 	virtual void SAL_CALL removeEventListener(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener > & aListener) throw( ::com::sun::star::uno::RuntimeException );
183 
184 	//XPropertySet
185     virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo(  ) throw(::com::sun::star::uno::RuntimeException);
186     virtual void SAL_CALL setPropertyValue( const ::rtl::OUString& aPropertyName, const ::com::sun::star::uno::Any& aValue ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
187     virtual ::com::sun::star::uno::Any SAL_CALL getPropertyValue( const ::rtl::OUString& PropertyName ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
188     virtual void SAL_CALL addPropertyChangeListener( const ::rtl::OUString& aPropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener >& xListener ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
189     virtual void SAL_CALL removePropertyChangeListener( const ::rtl::OUString& aPropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener >& aListener ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
190     virtual void SAL_CALL addVetoableChangeListener( const ::rtl::OUString& PropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XVetoableChangeListener >& aListener ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
191     virtual void SAL_CALL removeVetoableChangeListener( const ::rtl::OUString& PropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XVetoableChangeListener >& aListener ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
192 
193 	//XServiceInfo
194 	virtual rtl::OUString SAL_CALL getImplementationName(void) throw( ::com::sun::star::uno::RuntimeException );
195 	virtual sal_Bool SAL_CALL supportsService(const rtl::OUString& ServiceName) throw( ::com::sun::star::uno::RuntimeException );
196 	virtual ::com::sun::star::uno::Sequence< rtl::OUString > SAL_CALL getSupportedServiceNames(void) throw( ::com::sun::star::uno::RuntimeException );
197 
198     //XUpdatable
199     virtual void SAL_CALL update(  ) throw (::com::sun::star::uno::RuntimeException);
200 
201 	void attachToRange(const ::com::sun::star::uno::Reference< ::com::sun::star::text::XTextRange > & xTextRange)throw( ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException );
202 
203 	const SwField*  	GetField() const;
204 	const SwFmtFld* 	GetFldFmt(){return GetField() ? pFmtFld : 0; };
205 
206 	void Invalidate();
207 
208     /// @return an SwXTextField, either an already existing one or a new one
209     static SwXTextField* CreateSwXTextField(SwDoc & rDoc, SwFmtFld const& rFmt);
210 };
211 
212 
213 typedef
214 cppu::WeakImplHelper2
215 <
216 	::com::sun::star::container::XNameAccess,
217 	::com::sun::star::lang::XServiceInfo
218 >
219 SwXTextFieldMastersBaseClass;
220 class SwXTextFieldMasters : public SwXTextFieldMastersBaseClass,
221 	public SwUnoCollection
222 {
223 protected:
224 	virtual ~SwXTextFieldMasters();
225 public:
226 	SwXTextFieldMasters(SwDoc* pDoc);
227 
228 
229 	//XNameAccess
230 	virtual ::com::sun::star::uno::Any SAL_CALL getByName(const rtl::OUString& Name) throw( ::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException );
231 	virtual ::com::sun::star::uno::Sequence< rtl::OUString > SAL_CALL getElementNames(void) throw( ::com::sun::star::uno::RuntimeException );
232 	virtual sal_Bool SAL_CALL hasByName(const rtl::OUString& Name) throw( ::com::sun::star::uno::RuntimeException );
233 
234 	//XElementAccess
235     virtual ::com::sun::star::uno::Type SAL_CALL getElementType(  ) throw(::com::sun::star::uno::RuntimeException);
236     virtual sal_Bool SAL_CALL hasElements(  ) throw(::com::sun::star::uno::RuntimeException);
237 
238 	//XServiceInfo
239 	virtual rtl::OUString SAL_CALL getImplementationName(void) throw( ::com::sun::star::uno::RuntimeException );
240 	virtual sal_Bool SAL_CALL supportsService(const rtl::OUString& ServiceName) throw( ::com::sun::star::uno::RuntimeException );
241 	virtual ::com::sun::star::uno::Sequence< rtl::OUString > SAL_CALL getSupportedServiceNames(void) throw( ::com::sun::star::uno::RuntimeException );
242 
243 
244 	static sal_Bool getInstanceName(const SwFieldType& rFldType, String& rName);
245 };
246 
247 /* -----------------21.12.98 10:26-------------------
248  *
249  * --------------------------------------------------*/
250 typedef
251 cppu::WeakImplHelper3
252 <
253 	::com::sun::star::container::XEnumerationAccess,
254 	::com::sun::star::lang::XServiceInfo,
255 	::com::sun::star::util::XRefreshable
256 >
257 SwXTextFieldTypesBaseClass;
258 class SwXTextFieldTypes : public SwXTextFieldTypesBaseClass,
259 		public SwUnoCollection
260 {
261     SwRefreshListenerContainer      aRefreshCont;
262 protected:
263 	virtual ~SwXTextFieldTypes();
264 public:
265 	SwXTextFieldTypes(SwDoc* pDoc);
266 
267 
268 	//XEnumerationAccess
269 	virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XEnumeration >  SAL_CALL createEnumeration(void) throw( ::com::sun::star::uno::RuntimeException );
270 
271 	//XElementAccess
272     virtual ::com::sun::star::uno::Type SAL_CALL getElementType(  ) throw(::com::sun::star::uno::RuntimeException);
273     virtual sal_Bool SAL_CALL hasElements(  ) throw(::com::sun::star::uno::RuntimeException);
274 
275 	// ::com::sun::star::util::XRefreshable
276     virtual void SAL_CALL refresh(  ) throw(::com::sun::star::uno::RuntimeException);
277     virtual void SAL_CALL addRefreshListener( const ::com::sun::star::uno::Reference< ::com::sun::star::util::XRefreshListener >& l ) throw(::com::sun::star::uno::RuntimeException);
278     virtual void SAL_CALL removeRefreshListener( const ::com::sun::star::uno::Reference< ::com::sun::star::util::XRefreshListener >& l ) throw(::com::sun::star::uno::RuntimeException);
279 
280 	//XServiceInfo
281 	virtual rtl::OUString SAL_CALL getImplementationName(void) throw( ::com::sun::star::uno::RuntimeException );
282 	virtual sal_Bool SAL_CALL supportsService(const rtl::OUString& ServiceName) throw( ::com::sun::star::uno::RuntimeException );
283 	virtual ::com::sun::star::uno::Sequence< rtl::OUString > SAL_CALL getSupportedServiceNames(void) throw( ::com::sun::star::uno::RuntimeException );
284 
285     // SwUnoCollection
286     virtual void    Invalidate();
287 };
288 
289 class SwXFieldEnumeration : public cppu::WeakImplHelper2
290 <
291 	::com::sun::star::container::XEnumeration,
292 	::com::sun::star::lang::XServiceInfo
293 >,
294 	public SwClient
295 {
296     ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::text::XTextField > > aItems;
297     sal_Int32       nNextIndex;     // index of next element to be returned
298 
299 	SwDoc* pDoc;
300 
301 protected:
302 	virtual ~SwXFieldEnumeration();
303 	//SwClient
304    virtual void Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew);
305 public:
306 	SwXFieldEnumeration(SwDoc* pDoc);
307 
308 	//XEnumeration
309 	virtual sal_Bool SAL_CALL hasMoreElements(void) throw( ::com::sun::star::uno::RuntimeException );
310 	virtual ::com::sun::star::uno::Any SAL_CALL nextElement(void) throw( ::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException );
311 
312 	//XServiceInfo
313 	virtual rtl::OUString SAL_CALL getImplementationName(void) throw( ::com::sun::star::uno::RuntimeException );
314 	virtual sal_Bool SAL_CALL supportsService(const rtl::OUString& ServiceName) throw( ::com::sun::star::uno::RuntimeException );
315 	virtual ::com::sun::star::uno::Sequence< rtl::OUString > SAL_CALL getSupportedServiceNames(void) throw( ::com::sun::star::uno::RuntimeException );
316 
317 };
318 #endif
319 
320 
321 
322