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