xref: /aoo4110/main/sw/source/core/unocore/unofield.cxx (revision b1cdbd2c)
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 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sw.hxx"
26 
27 
28 #include <swtypes.hxx>
29 #include <cmdid.h>
30 #include <doc.hxx>
31 #include <hints.hxx>
32 #include <fmtfld.hxx>
33 #include <txtfld.hxx>
34 #include <ndtxt.hxx>
35 #include <unomap.hxx>
36 #include <unoprnms.hxx>
37 #include <unotextrange.hxx>
38 #include <unotextcursor.hxx>
39 #include <unocoll.hxx>
40 #include <sfx2/linkmgr.hxx>
41 #include <docstat.hxx>
42 #include <editsh.hxx>
43 #include <viewsh.hxx>
44 #include <comphelper/types.hxx>
45 #include <comphelper/processfactory.hxx>
46 #include <com/sun/star/util/Time.hpp>
47 #include <com/sun/star/util/DateTimeRange.hpp>
48 #include <com/sun/star/util/DateTime.hpp>
49 #include <com/sun/star/util/Date.hpp>
50 #include <com/sun/star/beans/XFastPropertySet.hpp>
51 #include <com/sun/star/beans/XPropertyStateChangeListener.hpp>
52 #include <com/sun/star/beans/PropertyAttribute.hpp>
53 #include <com/sun/star/beans/XPropertyContainer.hpp>
54 
55 //undef to prevent error (from sfx2/docfile.cxx)
56 #undef SEQUENCE
57 #include <com/sun/star/text/SetVariableType.hpp>
58 #include <com/sun/star/text/WrapTextMode.hpp>
59 #include <com/sun/star/text/TextContentAnchorType.hpp>
60 #include <com/sun/star/text/PageNumberType.hpp>
61 #include <unofield.hxx>
62 #include <unocrsr.hxx>
63 #include <authfld.hxx>
64 #include <flddat.hxx>
65 #include <dbfld.hxx>
66 #include <usrfld.hxx>
67 #include <docufld.hxx>
68 #include <expfld.hxx>
69 #include <chpfld.hxx>
70 #include <flddropdown.hxx>
71 #include <poolfmt.hxx>
72 #include <poolfmt.hrc>
73 #include <pagedesc.hxx>
74 #include <docary.hxx>
75 #include <reffld.hxx>
76 #include <ddefld.hxx>
77 #include <SwStyleNameMapper.hxx>
78 #include <swunohelper.hxx>
79 #include <unofldmid.h>
80 #include <scriptinfo.hxx>
81 #include <tools/datetime.hxx>
82 #include <tools/urlobj.hxx>
83 #include <svx/dataaccessdescriptor.hxx>
84 #define _SVSTDARR_STRINGS
85 #include <svl/svstdarr.hxx>
86 #include <vos/mutex.hxx>
87 #include <vcl/svapp.hxx>
88 #include <textapi.hxx>
89 #include <editeng/outliner.hxx>
90 #include <docsh.hxx>
91 #include <fmtmeta.hxx> // MetaFieldManager
92 #include <switerator.hxx>
93 
94 
95 using ::rtl::OUString;
96 using namespace ::com::sun::star;
97 using namespace nsSwDocInfoSubType;
98 
99 #define COM_TEXT_FLDMASTER		"com.sun.star.text.FieldMaster."
100 
101 // case-corrected version of the first part for the service names (see #i67811)
102 #define COM_TEXT_FLDMASTER_CC   "com.sun.star.text.fieldmaster."
103 
104 // note: this thing is indexed as an array, so do not insert/remove entries!
105 static const sal_uInt16 aDocInfoSubTypeFromService[] =
106 {
107 	DI_CHANGE | DI_SUB_AUTHOR,	//PROPERTY_MAP_FLDTYP_DOCINFO_CHANGE_AUTHOR
108 	DI_CHANGE | DI_SUB_DATE,	//PROPERTY_MAP_FLDTYP_DOCINFO_CHANGE_DATE_TIME
109 	DI_EDIT | DI_SUB_TIME,		//PROPERTY_MAP_FLDTYP_DOCINFO_EDIT_TIME
110 	DI_COMMENT,					//PROPERTY_MAP_FLDTYP_DOCINFO_DESCRIPTION
111 	DI_CREATE | DI_SUB_AUTHOR,	//PROPERTY_MAP_FLDTYP_DOCINFO_CREATE_AUTHOR
112 	DI_CREATE | DI_SUB_DATE,	//PROPERTY_MAP_FLDTYP_DOCINFO_CREATE_DATE_TIME
113 	0,       					//DUMMY
114 	0, 		        			//DUMMY
115 	0, 			        		//DUMMY
116 	0, 			        		//DUMMY
117 	DI_CUSTOM,					//PROPERTY_MAP_FLDTYP_DOCINFO_CUSTOM
118 	DI_PRINT | DI_SUB_AUTHOR,	//PROPERTY_MAP_FLDTYP_DOCINFO_PRINT_AUTHOR
119 	DI_PRINT | DI_SUB_DATE,		//PROPERTY_MAP_FLDTYP_DOCINFO_PRINT_DATE_TIME
120 	DI_KEYS,					//PROPERTY_MAP_FLDTYP_DOCINFO_KEY_WORDS
121 	DI_THEMA,					//PROPERTY_MAP_FLDTYP_DOCINFO_SUBJECT
122 	DI_TITEL,					//PROPERTY_MAP_FLDTYP_DOCINFO_TITLE
123 	DI_DOCNO					//PROPERTY_MAP_FLDTYP_DOCINFO_REVISION
124 };
125 struct ServiceIdResId
126 {
127 	sal_uInt16 nResId;
128 	sal_uInt16 nServiceId;
129 };
130 static const ServiceIdResId aServiceToRes[] =
131 {
132 	{RES_DATETIMEFLD, 	SW_SERVICE_FIELDTYPE_DATETIME				},
133 	{RES_USERFLD, 		SW_SERVICE_FIELDTYPE_USER                   },
134 	{RES_SETEXPFLD, 		SW_SERVICE_FIELDTYPE_SET_EXP            }    ,
135 	{RES_GETEXPFLD, 		SW_SERVICE_FIELDTYPE_GET_EXP            }    ,
136 	{RES_FILENAMEFLD, 	SW_SERVICE_FIELDTYPE_FILE_NAME              },
137 	{RES_PAGENUMBERFLD, 	SW_SERVICE_FIELDTYPE_PAGE_NUM           }    ,
138 	{RES_AUTHORFLD, 		SW_SERVICE_FIELDTYPE_AUTHOR             }    ,
139 	{RES_CHAPTERFLD, 	SW_SERVICE_FIELDTYPE_CHAPTER                },
140 	{RES_GETREFFLD, 		SW_SERVICE_FIELDTYPE_GET_REFERENCE      }    ,
141 	{RES_HIDDENTXTFLD, 	SW_SERVICE_FIELDTYPE_CONDITIONED_TEXT       },
142 	{RES_POSTITFLD, 		SW_SERVICE_FIELDTYPE_ANNOTATION         }    ,
143 	{RES_INPUTFLD, 		SW_SERVICE_FIELDTYPE_INPUT                  },
144 	{RES_MACROFLD, 		SW_SERVICE_FIELDTYPE_MACRO                  },
145 	{RES_DDEFLD, 		SW_SERVICE_FIELDTYPE_DDE                    },
146 	{RES_HIDDENPARAFLD, 	SW_SERVICE_FIELDTYPE_HIDDEN_PARA        }    ,
147 	{RES_DOCINFOFLD, 	SW_SERVICE_FIELDTYPE_DOC_INFO               },
148 	{RES_TEMPLNAMEFLD, 	SW_SERVICE_FIELDTYPE_TEMPLATE_NAME          },
149 	{RES_EXTUSERFLD, 	SW_SERVICE_FIELDTYPE_USER_EXT               },
150 	{RES_REFPAGESETFLD, 	SW_SERVICE_FIELDTYPE_REF_PAGE_SET       }    ,
151 	{RES_REFPAGEGETFLD, 	SW_SERVICE_FIELDTYPE_REF_PAGE_GET       }    ,
152 	{RES_JUMPEDITFLD, 	SW_SERVICE_FIELDTYPE_JUMP_EDIT              },
153 	{RES_SCRIPTFLD, 		SW_SERVICE_FIELDTYPE_SCRIPT             }    ,
154 	{RES_DBNEXTSETFLD, 	SW_SERVICE_FIELDTYPE_DATABASE_NEXT_SET      },
155 	{RES_DBNUMSETFLD, 	SW_SERVICE_FIELDTYPE_DATABASE_NUM_SET       },
156 	{RES_DBSETNUMBERFLD, SW_SERVICE_FIELDTYPE_DATABASE_SET_NUM      } ,
157 	{RES_DBFLD, 			SW_SERVICE_FIELDTYPE_DATABASE           }    ,
158 	{RES_DBNAMEFLD,		SW_SERVICE_FIELDTYPE_DATABASE_NAME          },
159 	{RES_DOCSTATFLD, 	SW_SERVICE_FIELDTYPE_PAGE_COUNT             },
160 	{RES_DOCSTATFLD, 	SW_SERVICE_FIELDTYPE_PARAGRAPH_COUNT        },
161 	{RES_DOCSTATFLD, 	SW_SERVICE_FIELDTYPE_WORD_COUNT             },
162 	{RES_DOCSTATFLD, 	SW_SERVICE_FIELDTYPE_CHARACTER_COUNT        },
163 	{RES_DOCSTATFLD, 	SW_SERVICE_FIELDTYPE_TABLE_COUNT            },
164 	{RES_DOCSTATFLD, 	SW_SERVICE_FIELDTYPE_GRAPHIC_OBJECT_COUNT   },
165 	{RES_DOCSTATFLD, 	SW_SERVICE_FIELDTYPE_EMBEDDED_OBJECT_COUNT  },
166 	{RES_DOCINFOFLD, 	SW_SERVICE_FIELDTYPE_DOCINFO_CHANGE_AUTHOR  },
167 	{RES_DOCINFOFLD,		SW_SERVICE_FIELDTYPE_DOCINFO_CHANGE_DATE_TIME},
168 	{RES_DOCINFOFLD,		SW_SERVICE_FIELDTYPE_DOCINFO_EDIT_TIME       },
169 	{RES_DOCINFOFLD,		SW_SERVICE_FIELDTYPE_DOCINFO_DESCRIPTION     },
170 	{RES_DOCINFOFLD,		SW_SERVICE_FIELDTYPE_DOCINFO_CREATE_AUTHOR   },
171 	{RES_DOCINFOFLD,		SW_SERVICE_FIELDTYPE_DOCINFO_CREATE_DATE_TIME},
172 	{RES_DOCINFOFLD,		SW_SERVICE_FIELDTYPE_DOCINFO_CUSTOM          },
173 	{RES_DOCINFOFLD,		SW_SERVICE_FIELDTYPE_DOCINFO_PRINT_AUTHOR    },
174 	{RES_DOCINFOFLD,		SW_SERVICE_FIELDTYPE_DOCINFO_PRINT_DATE_TIME },
175 	{RES_DOCINFOFLD,		SW_SERVICE_FIELDTYPE_DOCINFO_KEY_WORDS       },
176 	{RES_DOCINFOFLD,		SW_SERVICE_FIELDTYPE_DOCINFO_SUBJECT         },
177 	{RES_DOCINFOFLD,		SW_SERVICE_FIELDTYPE_DOCINFO_TITLE           },
178 	{RES_INPUTFLD, 		SW_SERVICE_FIELDTYPE_INPUT_USER                  },
179 	{RES_HIDDENTXTFLD, 	SW_SERVICE_FIELDTYPE_HIDDEN_TEXT                 },
180 	{RES_AUTHORITY, 	SW_SERVICE_FIELDTYPE_BIBLIOGRAPHY                },
181 	{RES_COMBINED_CHARS,	SW_SERVICE_FIELDTYPE_COMBINED_CHARACTERS	 },
182 	{RES_DROPDOWN,	SW_SERVICE_FIELDTYPE_DROPDOWN	                     },
183     {RES_TABLEFLD,      SW_SERVICE_FIELDTYPE_TABLE_FORMULA              },
184 	{USHRT_MAX,			USHRT_MAX                                        }
185 };
186 //-----------------------------------------------------------------
lcl_ServiceIdToResId(sal_uInt16 nServiceId)187 sal_uInt16 lcl_ServiceIdToResId(sal_uInt16 nServiceId)
188 {
189 	const ServiceIdResId* pMap = aServiceToRes;
190 	while( USHRT_MAX != pMap->nServiceId && nServiceId != pMap->nServiceId )
191 			++pMap;
192 #ifdef DBG_UTIL
193 	if( USHRT_MAX == pMap->nServiceId )
194 		DBG_ERROR("service id not found");
195 #endif
196 	return pMap->nResId;
197 }
198 //-----------------------------------------------------------------
lcl_GetServiceForField(const SwField & rFld)199 sal_uInt16 lcl_GetServiceForField( const SwField& rFld )
200 {
201 	sal_uInt16 nWhich = rFld.Which(), nSrvId = USHRT_MAX;
202 	//special handling for some fields
203 	switch( nWhich )
204 	{
205 	case RES_INPUTFLD:
206 		if( INP_USR == (rFld.GetSubType() & 0x00ff) )
207 			nSrvId = SW_SERVICE_FIELDTYPE_INPUT_USER;
208 		break;
209 
210 	case RES_DOCINFOFLD:
211 		{
212 			sal_uInt16 nSubType = rFld.GetSubType();
213 			switch( (nSubType & 0xff))
214 			{
215 			case DI_CHANGE:
216 				nSrvId = ((nSubType&0x300) == DI_SUB_AUTHOR)
217 						? SW_SERVICE_FIELDTYPE_DOCINFO_CHANGE_AUTHOR
218 						: SW_SERVICE_FIELDTYPE_DOCINFO_CHANGE_DATE_TIME;
219 				break;
220 			case DI_CREATE:
221 				nSrvId = ((nSubType&0x300) == DI_SUB_AUTHOR)
222 						? SW_SERVICE_FIELDTYPE_DOCINFO_CREATE_AUTHOR
223 						: SW_SERVICE_FIELDTYPE_DOCINFO_CREATE_DATE_TIME;
224 				break;
225 			case DI_PRINT:
226 				nSrvId = ((nSubType&0x300) == DI_SUB_AUTHOR)
227 						? SW_SERVICE_FIELDTYPE_DOCINFO_PRINT_AUTHOR
228 						: SW_SERVICE_FIELDTYPE_DOCINFO_PRINT_DATE_TIME;
229 				break;
230 			case DI_EDIT:	nSrvId = SW_SERVICE_FIELDTYPE_DOCINFO_EDIT_TIME;break;
231 			case DI_COMMENT:nSrvId = SW_SERVICE_FIELDTYPE_DOCINFO_DESCRIPTION;break;
232 			case DI_KEYS:   nSrvId = SW_SERVICE_FIELDTYPE_DOCINFO_KEY_WORDS;break;
233 			case DI_THEMA:  nSrvId = SW_SERVICE_FIELDTYPE_DOCINFO_SUBJECT;	break;
234 			case DI_TITEL:  nSrvId = SW_SERVICE_FIELDTYPE_DOCINFO_TITLE;	break;
235 			case DI_DOCNO:  nSrvId = SW_SERVICE_FIELDTYPE_DOCINFO_REVISION;	break;
236 			case DI_CUSTOM: nSrvId = SW_SERVICE_FIELDTYPE_DOCINFO_CUSTOM;	break;
237 			}
238 		}
239 		break;
240 
241 	case RES_HIDDENTXTFLD:
242 		nSrvId = TYP_CONDTXTFLD == rFld.GetSubType()
243 						? SW_SERVICE_FIELDTYPE_CONDITIONED_TEXT
244 						: SW_SERVICE_FIELDTYPE_HIDDEN_TEXT;
245 		break;
246 
247 	case RES_DOCSTATFLD:
248 		{
249 			switch( rFld.GetSubType() )
250 			{
251 			case DS_PAGE: nSrvId = SW_SERVICE_FIELDTYPE_PAGE_COUNT; break;
252 			case DS_PARA: nSrvId = SW_SERVICE_FIELDTYPE_PARAGRAPH_COUNT; break;
253 			case DS_WORD: nSrvId = SW_SERVICE_FIELDTYPE_WORD_COUNT     ; break;
254 			case DS_CHAR: nSrvId = SW_SERVICE_FIELDTYPE_CHARACTER_COUNT; break;
255 			case DS_TBL:  nSrvId = SW_SERVICE_FIELDTYPE_TABLE_COUNT    ; break;
256 			case DS_GRF:  nSrvId = SW_SERVICE_FIELDTYPE_GRAPHIC_OBJECT_COUNT; break;
257 			case DS_OLE:  nSrvId = SW_SERVICE_FIELDTYPE_EMBEDDED_OBJECT_COUNT; break;
258 			}
259 		}
260 		break;
261 	}
262 	if( USHRT_MAX == nSrvId )
263 	{
264 		for( const ServiceIdResId* pMap = aServiceToRes;
265 				USHRT_MAX != pMap->nResId; ++pMap )
266 			if( nWhich == pMap->nResId )
267 			{
268 				nSrvId = pMap->nServiceId;
269 				break;
270 			}
271 	}
272 #ifdef DBG_UTIL
273 	if( USHRT_MAX == nSrvId )
274 		DBG_ERROR("resid not found");
275 #endif
276 	return nSrvId;
277 }
278 
lcl_GetPropMapIdForFieldType(sal_uInt16 nWhich)279 sal_uInt16 lcl_GetPropMapIdForFieldType( sal_uInt16 nWhich )
280 {
281 	sal_uInt16 nId;
282 	switch( nWhich )
283 	{
284 	case RES_USERFLD:	nId = PROPERTY_MAP_FLDMSTR_USER;			break;
285 	case RES_DBFLD:		nId = PROPERTY_MAP_FLDMSTR_DATABASE;		break;
286 	case RES_SETEXPFLD:	nId = PROPERTY_MAP_FLDMSTR_SET_EXP;			break;
287 	case RES_DDEFLD:	nId = PROPERTY_MAP_FLDMSTR_DDE;				break;
288 	case RES_AUTHORITY:	nId = PROPERTY_MAP_FLDMSTR_BIBLIOGRAPHY;	break;
289 	default:			nId = PROPERTY_MAP_FLDMSTR_DUMMY0;
290 	}
291 	return nId;
292 }
293 
294 
GetFieldTypeMId(const OUString & rProperty,const SwFieldType & rTyp)295 sal_uInt16 GetFieldTypeMId( const OUString& rProperty, const SwFieldType& rTyp )
296 {
297 	sal_uInt16 nId = lcl_GetPropMapIdForFieldType( rTyp.Which() );
298     const SfxItemPropertySet* pSet = aSwMapProvider.GetPropertySet( nId );
299     if( !pSet )
300 		nId = USHRT_MAX;
301 	else
302     {
303         const SfxItemPropertySimpleEntry* pEntry = pSet->getPropertyMap()->getByName(rProperty);
304         nId = pEntry ? pEntry->nWID : USHRT_MAX;
305     }
306 	return nId;
307 }
308 
lcl_GetPropertyMapOfService(sal_uInt16 nServiceId)309 sal_uInt16 lcl_GetPropertyMapOfService( sal_uInt16 nServiceId )
310 {
311 	sal_uInt16 nRet;
312 	switch ( nServiceId)
313 	{
314 	case SW_SERVICE_FIELDTYPE_DATETIME: nRet = PROPERTY_MAP_FLDTYP_DATETIME; break;
315 	case SW_SERVICE_FIELDTYPE_USER: nRet = PROPERTY_MAP_FLDTYP_USER; break;
316 	case SW_SERVICE_FIELDTYPE_SET_EXP: nRet = PROPERTY_MAP_FLDTYP_SET_EXP; break;
317 	case SW_SERVICE_FIELDTYPE_GET_EXP: nRet = PROPERTY_MAP_FLDTYP_GET_EXP; break;
318 	case SW_SERVICE_FIELDTYPE_FILE_NAME: nRet = PROPERTY_MAP_FLDTYP_FILE_NAME; break;
319 	case SW_SERVICE_FIELDTYPE_PAGE_NUM: nRet = PROPERTY_MAP_FLDTYP_PAGE_NUM; break;
320 	case SW_SERVICE_FIELDTYPE_AUTHOR: nRet = PROPERTY_MAP_FLDTYP_AUTHOR; break;
321 	case SW_SERVICE_FIELDTYPE_CHAPTER: nRet = PROPERTY_MAP_FLDTYP_CHAPTER; break;
322 	case SW_SERVICE_FIELDTYPE_GET_REFERENCE: nRet = PROPERTY_MAP_FLDTYP_GET_REFERENCE; break;
323 	case SW_SERVICE_FIELDTYPE_CONDITIONED_TEXT: nRet = PROPERTY_MAP_FLDTYP_CONDITIONED_TEXT; break;
324 	case SW_SERVICE_FIELDTYPE_ANNOTATION: nRet = PROPERTY_MAP_FLDTYP_ANNOTATION; break;
325 	case SW_SERVICE_FIELDTYPE_INPUT_USER:
326 	case SW_SERVICE_FIELDTYPE_INPUT: nRet = PROPERTY_MAP_FLDTYP_INPUT; break;
327 	case SW_SERVICE_FIELDTYPE_MACRO: nRet = PROPERTY_MAP_FLDTYP_MACRO; break;
328 	case SW_SERVICE_FIELDTYPE_DDE: nRet = PROPERTY_MAP_FLDTYP_DDE; break;
329 	case SW_SERVICE_FIELDTYPE_HIDDEN_PARA: nRet = PROPERTY_MAP_FLDTYP_HIDDEN_PARA; break;
330 	case SW_SERVICE_FIELDTYPE_DOC_INFO: nRet = PROPERTY_MAP_FLDTYP_DOC_INFO; break;
331 	case SW_SERVICE_FIELDTYPE_TEMPLATE_NAME: nRet = PROPERTY_MAP_FLDTYP_TEMPLATE_NAME; break;
332 	case SW_SERVICE_FIELDTYPE_USER_EXT: nRet = PROPERTY_MAP_FLDTYP_USER_EXT; break;
333 	case SW_SERVICE_FIELDTYPE_REF_PAGE_SET: nRet = PROPERTY_MAP_FLDTYP_REF_PAGE_SET; break;
334 	case SW_SERVICE_FIELDTYPE_REF_PAGE_GET: nRet = PROPERTY_MAP_FLDTYP_REF_PAGE_GET; break;
335 	case SW_SERVICE_FIELDTYPE_JUMP_EDIT: nRet = PROPERTY_MAP_FLDTYP_JUMP_EDIT; break;
336 	case SW_SERVICE_FIELDTYPE_SCRIPT: nRet = PROPERTY_MAP_FLDTYP_SCRIPT; break;
337 	case SW_SERVICE_FIELDTYPE_DATABASE_NEXT_SET: nRet = PROPERTY_MAP_FLDTYP_DATABASE_NEXT_SET; break;
338 	case SW_SERVICE_FIELDTYPE_DATABASE_NUM_SET: nRet = PROPERTY_MAP_FLDTYP_DATABASE_NUM_SET; break;
339 	case SW_SERVICE_FIELDTYPE_DATABASE_SET_NUM: nRet = PROPERTY_MAP_FLDTYP_DATABASE_SET_NUM; break;
340 	case SW_SERVICE_FIELDTYPE_DATABASE: nRet = PROPERTY_MAP_FLDTYP_DATABASE; break;
341 	case SW_SERVICE_FIELDTYPE_DATABASE_NAME: nRet = PROPERTY_MAP_FLDTYP_DATABASE_NAME; break;
342 	case SW_SERVICE_FIELDTYPE_TABLE_FORMULA: nRet = PROPERTY_MAP_FLDTYP_TABLE_FORMULA; break;
343 	case SW_SERVICE_FIELDTYPE_PAGE_COUNT:
344 	case SW_SERVICE_FIELDTYPE_PARAGRAPH_COUNT:
345 	case SW_SERVICE_FIELDTYPE_WORD_COUNT:
346 	case SW_SERVICE_FIELDTYPE_CHARACTER_COUNT:
347 	case SW_SERVICE_FIELDTYPE_TABLE_COUNT:
348 	case SW_SERVICE_FIELDTYPE_GRAPHIC_OBJECT_COUNT:
349 	case SW_SERVICE_FIELDTYPE_EMBEDDED_OBJECT_COUNT: nRet = PROPERTY_MAP_FLDTYP_DOCSTAT; break;
350 	case SW_SERVICE_FIELDTYPE_DOCINFO_CHANGE_AUTHOR:
351 	case SW_SERVICE_FIELDTYPE_DOCINFO_CREATE_AUTHOR:
352 	case SW_SERVICE_FIELDTYPE_DOCINFO_PRINT_AUTHOR: nRet = PROPERTY_MAP_FLDTYP_DOCINFO_AUTHOR; break;
353 	case SW_SERVICE_FIELDTYPE_DOCINFO_CHANGE_DATE_TIME:
354 	case SW_SERVICE_FIELDTYPE_DOCINFO_CREATE_DATE_TIME:
355 	case SW_SERVICE_FIELDTYPE_DOCINFO_PRINT_DATE_TIME: nRet = PROPERTY_MAP_FLDTYP_DOCINFO_DATE_TIME; break;
356 	case SW_SERVICE_FIELDTYPE_DOCINFO_EDIT_TIME: nRet = PROPERTY_MAP_FLDTYP_DOCINFO_EDIT_TIME; break;
357 	case SW_SERVICE_FIELDTYPE_DOCINFO_CUSTOM: nRet = PROPERTY_MAP_FLDTYP_DOCINFO_CUSTOM; break;
358 	case SW_SERVICE_FIELDTYPE_DOCINFO_DESCRIPTION:
359 	case SW_SERVICE_FIELDTYPE_DOCINFO_KEY_WORDS:
360 	case SW_SERVICE_FIELDTYPE_DOCINFO_SUBJECT:
361 	case SW_SERVICE_FIELDTYPE_DOCINFO_TITLE: nRet = PROPERTY_MAP_FLDTYP_DOCINFO_MISC; break;
362 	case SW_SERVICE_FIELDTYPE_DOCINFO_REVISION: nRet = PROPERTY_MAP_FLDTYP_DOCINFO_REVISION; break;
363 	case SW_SERVICE_FIELDTYPE_BIBLIOGRAPHY: nRet = PROPERTY_MAP_FLDTYP_BIBLIOGRAPHY; break;
364 	case SW_SERVICE_FIELDTYPE_DUMMY_0:
365 	case SW_SERVICE_FIELDTYPE_COMBINED_CHARACTERS: nRet = PROPERTY_MAP_FLDTYP_COMBINED_CHARACTERS; break;
366 	case SW_SERVICE_FIELDTYPE_DROPDOWN: nRet = PROPERTY_MAP_FLDTYP_DROPDOWN; break;
367 	case SW_SERVICE_FIELDTYPE_DUMMY_4:
368 	case SW_SERVICE_FIELDTYPE_DUMMY_5:
369 	case SW_SERVICE_FIELDTYPE_DUMMY_6:
370 	case SW_SERVICE_FIELDTYPE_DUMMY_7:
371                 nRet = PROPERTY_MAP_FLDTYP_DUMMY_0; break;
372 	case SW_SERVICE_FIELDMASTER_USER: nRet = PROPERTY_MAP_FLDMSTR_USER; break;
373 	case SW_SERVICE_FIELDMASTER_DDE: nRet = PROPERTY_MAP_FLDMSTR_DDE; break;
374 	case SW_SERVICE_FIELDMASTER_SET_EXP: nRet = PROPERTY_MAP_FLDMSTR_SET_EXP; break;
375 	case SW_SERVICE_FIELDMASTER_DATABASE: nRet = PROPERTY_MAP_FLDMSTR_DATABASE; break;
376 	case SW_SERVICE_FIELDMASTER_BIBLIOGRAPHY: nRet = PROPERTY_MAP_FLDMSTR_BIBLIOGRAPHY; break;
377 	case SW_SERVICE_FIELDMASTER_DUMMY2:
378 	case SW_SERVICE_FIELDMASTER_DUMMY3:
379 	case SW_SERVICE_FIELDMASTER_DUMMY4:
380 	case SW_SERVICE_FIELDMASTER_DUMMY5: nRet = PROPERTY_MAP_FLDMSTR_DUMMY0; break;
381 	case SW_SERVICE_FIELDTYPE_HIDDEN_TEXT: nRet = PROPERTY_MAP_FLDTYP_HIDDEN_TEXT; break;
382 	default:
383 		DBG_ERROR( "wrong service id" );
384 		nRet = USHRT_MAX;
385 	}
386 	return nRet;
387 }
388 
389 /******************************************************************
390  * SwXFieldMaster
391  ******************************************************************/
392 TYPEINIT1(SwXFieldMaster, SwClient);
393 
getUnoTunnelId()394 const uno::Sequence< sal_Int8 > & SwXFieldMaster::getUnoTunnelId()
395 {
396     static uno::Sequence< sal_Int8 > aSeq = ::CreateUnoTunnelId();
397 	return aSeq;
398 }
399 
getSomething(const uno::Sequence<sal_Int8> & rId)400 sal_Int64 SAL_CALL SwXFieldMaster::getSomething( const uno::Sequence< sal_Int8 >& rId )
401 	throw(uno::RuntimeException)
402 {
403     if( rId.getLength() == 16
404         && 0 == rtl_compareMemory( getUnoTunnelId().getConstArray(),
405 										rId.getConstArray(), 16 ) )
406     {
407 		return sal::static_int_cast< sal_Int64 >( reinterpret_cast< sal_IntPtr >(this) );
408     }
409 	return 0;
410 }
411 
getImplementationName(void)412 OUString SwXFieldMaster::getImplementationName(void) throw( uno::RuntimeException )
413 {
414 	return C2U("SwXFieldMaster");
415 }
416 
supportsService(const OUString & rServiceName)417 sal_Bool SwXFieldMaster::supportsService(const OUString& rServiceName) throw( uno::RuntimeException )
418 {
419     sal_Bool bRet = sal_False;
420     if(rServiceName.equalsAsciiL(
421 			RTL_CONSTASCII_STRINGPARAM("com.sun.star.text.TextFieldMaster")))
422         bRet = sal_True;
423     else
424     {
425 		const sal_Char* pEntry;
426         switch( nResTypeId )
427         {
428         case RES_USERFLD:	pEntry = "User"; 			break;
429         case RES_DBFLD:		pEntry = "Database"; 		break;
430         case RES_SETEXPFLD:	pEntry = "SetExpression";	break;
431         case RES_DDEFLD:	pEntry = "DDE";				break;
432         case RES_AUTHORITY:	pEntry = "Bibliography"; 	break;
433 		default: pEntry = 0;
434         }
435 		if( pEntry )
436 		{
437 			ByteString aTmp( RTL_CONSTASCII_STRINGPARAM(
438 							"com.sun.star.text.fieldmaster."));
439 			aTmp.Append( pEntry );
440 			bRet = rServiceName.equalsAsciiL(aTmp.GetBuffer(), aTmp.Len());
441 		}
442     }
443     return bRet;
444 }
445 
getSupportedServiceNames(void)446 uno::Sequence< OUString > SwXFieldMaster::getSupportedServiceNames(void) throw( uno::RuntimeException )
447 {
448     uno::Sequence< OUString > aRet(2);
449 	OUString* pArray = aRet.getArray();
450     pArray[0] = C2U("com.sun.star.text.TextFieldMaster");
451 
452 	const sal_Char* pEntry1;
453 	switch( nResTypeId )
454 	{
455 	case RES_USERFLD: 	pEntry1 = "User"; 			break;
456     case RES_DBFLD:	  	pEntry1 = "Database";		break;
457     case RES_SETEXPFLD:	pEntry1 = "SetExpression";	break;
458     case RES_DDEFLD:	pEntry1 = "DDE"; 			break;
459     case RES_AUTHORITY:	pEntry1 = "Bibliography";	break;
460 	default: pEntry1 = 0;
461 	}
462 	if( pEntry1 )
463 	{
464 		String s;
465 		s.AppendAscii( "com.sun.star.text.fieldmaster." ).AppendAscii( pEntry1 );
466 	    pArray[1] = s;
467 	}
468 	return aRet;
469 }
470 
SwXFieldMaster(SwDoc * pDoc,sal_uInt16 nResId)471 SwXFieldMaster::SwXFieldMaster(SwDoc* pDoc, sal_uInt16 nResId) :
472 	aLstnrCntnr( (XPropertySet*)this),
473 	nResTypeId(nResId),
474 	m_pDoc(pDoc),
475 	m_bIsDescriptor(sal_True),
476 	fParam1(0.),
477 	nParam1(-1),
478 	bParam1(sal_False),
479 	nParam2(0)
480 {
481     pDoc->GetPageDescFromPool(RES_POOLPAGE_STANDARD)->Add(this);
482 }
483 
SwXFieldMaster(SwFieldType & rType,SwDoc * pDoc)484 SwXFieldMaster::SwXFieldMaster(SwFieldType& rType, SwDoc* pDoc) :
485 	SwClient(&rType),
486 	aLstnrCntnr( (XPropertySet*)this),
487 	nResTypeId(rType.Which()),
488 	m_pDoc(pDoc),
489 	m_bIsDescriptor(sal_False),
490 	fParam1(0.),
491 	nParam1(-1),
492 	bParam1(sal_False)
493 {
494 
495 }
496 
~SwXFieldMaster()497 SwXFieldMaster::~SwXFieldMaster()
498 {
499 
500 }
501 
getPropertySetInfo(void)502 uno::Reference< beans::XPropertySetInfo >  SwXFieldMaster::getPropertySetInfo(void)
503 											throw( uno::RuntimeException )
504 {
505 	vos::OGuard  aGuard(Application::GetSolarMutex());
506     uno::Reference< beans::XPropertySetInfo >  aRef =
507                         aSwMapProvider.GetPropertySet(
508                                 lcl_GetPropMapIdForFieldType( nResTypeId ) )->getPropertySetInfo();
509 	return aRef;
510 }
511 
setPropertyValue(const OUString & rPropertyName,const uno::Any & rValue)512 void SwXFieldMaster::setPropertyValue( const OUString& rPropertyName,
513 									const uno::Any& rValue)
514 	throw( beans::UnknownPropertyException, beans::PropertyVetoException,
515 			lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException)
516 {
517 	vos::OGuard  aGuard(Application::GetSolarMutex());
518     SwFieldType* pType = GetFldType(sal_True);
519 	if(pType)
520 	{
521 		sal_Bool bSetValue = sal_True;
522 		if( rPropertyName.equalsAsciiL( SW_PROP_NAME(UNO_NAME_SUB_TYPE)))
523 		{
524 			const SvStringsDtor& rExtraArr = SwStyleNameMapper::GetExtraUINameArray();
525 			String sTypeName = pType->GetName();
526 			static sal_uInt16 nIds[] =
527 			{
528 				RES_POOLCOLL_LABEL_DRAWING - RES_POOLCOLL_EXTRA_BEGIN,
529 				RES_POOLCOLL_LABEL_ABB - RES_POOLCOLL_EXTRA_BEGIN,
530 				RES_POOLCOLL_LABEL_TABLE - RES_POOLCOLL_EXTRA_BEGIN,
531 				RES_POOLCOLL_LABEL_FRAME- RES_POOLCOLL_EXTRA_BEGIN,
532 				0
533 			};
534 			for(const sal_uInt16 * pIds = nIds; *pIds; ++pIds)
535 			{
536 				if(sTypeName ==	*rExtraArr[ *pIds ] )
537 				{
538 					bSetValue = sal_False;
539 					break;
540 				}
541 			}
542 		}
543         if ( bSetValue )
544         {
545             // nothing special to be done here for the properties
546             // UNO_NAME_DATA_BASE_NAME and UNO_NAME_DATA_BASE_URL.
547             // We just call PutValue (empty string is allowed).
548             // Thus the last property set will be used as Data Source.
549 
550             const sal_uInt16 nMemberValueId = GetFieldTypeMId( rPropertyName, *pType );
551             if ( USHRT_MAX != nMemberValueId )
552             {
553                 pType->PutValue( rValue, nMemberValueId );
554                 if ( pType->Which() == RES_USERFLD )
555                 {
556                     // trigger update of User field in order to get depending Input Fields updated.
557                     pType->UpdateFlds();
558                 }
559             }
560             else
561             {
562                 throw beans::UnknownPropertyException(
563                     OUString( RTL_CONSTASCII_USTRINGPARAM( "Unknown property: " ) ) + rPropertyName,
564                     static_cast< cppu::OWeakObject * >( this ) );
565             }
566         }
567     }
568 	else if(!pType && m_pDoc &&
569         ( rPropertyName.equalsAsciiL( SW_PROP_NAME(UNO_NAME_NAME))) )
570 	{
571 		OUString uTmp;
572 		rValue >>= uTmp;
573 		String sTypeName(uTmp);
574 		SwFieldType* pType2 = m_pDoc->GetFldType(nResTypeId, sTypeName, sal_False);
575 
576         String sTable(SW_RES(STR_POOLCOLL_LABEL_TABLE));
577 		String sDrawing(SW_RES(STR_POOLCOLL_LABEL_DRAWING));
578 		String sFrame(SW_RES(STR_POOLCOLL_LABEL_FRAME));
579 		String sIllustration(SW_RES(STR_POOLCOLL_LABEL_ABB));
580 
581 		if(pType2 ||
582 			(RES_SETEXPFLD == nResTypeId &&
583 			( sTypeName == sTable || sTypeName == sDrawing ||
584 			  sTypeName == sFrame || sTypeName == sIllustration )))
585 		{
586 			throw lang::IllegalArgumentException();
587 		}
588 		else
589 		{
590 			switch(nResTypeId)
591 			{
592 				case RES_USERFLD :
593 				{
594 					SwUserFieldType aType(m_pDoc, sTypeName);
595 					pType2 = m_pDoc->InsertFldType(aType);
596 					((SwUserFieldType*)pType2)->SetContent(sParam1);
597 					((SwUserFieldType*)pType2)->SetValue(fParam1);
598 					((SwUserFieldType*)pType2)->SetType(bParam1 ? nsSwGetSetExpType::GSE_EXPR : nsSwGetSetExpType::GSE_STRING);
599 				}
600 				break;
601                 case RES_DDEFLD :
602 				{
603 					SwDDEFieldType aType(sTypeName, sParam1,
604                         sal::static_int_cast< sal_uInt16 >(bParam1 ? sfx2::LINKUPDATE_ALWAYS : sfx2::LINKUPDATE_ONCALL));
605 					pType2 = m_pDoc->InsertFldType(aType);
606 				}
607 				break;
608 				case RES_SETEXPFLD :
609 				{
610 					SwSetExpFieldType aType(m_pDoc, sTypeName);
611 					if(sParam1.Len())
612 						aType.SetDelimiter( sParam1.GetChar(0));
613 					if(nParam1 > -1 && nParam1 < MAXLEVEL)
614 						aType.SetOutlineLvl(nParam1);
615 					pType2 = m_pDoc->InsertFldType(aType);
616 				}
617 				break;
618                 case RES_DBFLD :
619                 {
620                     ::GetString( rValue, sParam3 );
621                     pType = GetFldType();
622                 }
623                 break;
624 			}
625 			if(pType2)
626 			{
627 				pType2->Add(this);
628 				m_bIsDescriptor = sal_False;
629 			}
630 			else
631 				throw uno::RuntimeException();
632 		}
633 
634 		DBG_ASSERT(pType2, "kein FieldType gefunden!" );
635 	}
636 	else
637 	{
638 		switch( nResTypeId )
639 		{
640 		case RES_USERFLD:
641 			if(rPropertyName.equalsAsciiL( SW_PROP_NAME(UNO_NAME_CONTENT)))
642 				::GetString( rValue, sParam1 );
643 			else if(rPropertyName.equalsAsciiL( SW_PROP_NAME(UNO_NAME_VALUE )))
644 			{
645 				if(rValue.getValueType() != ::getCppuType(static_cast<const double*>(0)))
646 					throw lang::IllegalArgumentException();
647 				fParam1 = *(double*)rValue.getValue();
648 			}
649 			else if(rPropertyName.equalsAsciiL( SW_PROP_NAME(UNO_NAME_IS_EXPRESSION )))
650 			{
651 				if(rValue.getValueType() != ::getBooleanCppuType())
652 					throw lang::IllegalArgumentException();
653 				bParam1 = *(sal_Bool*)rValue.getValue();
654 			}
655 
656 			break;
657 		case RES_DBFLD:
658 			if(rPropertyName.equalsAsciiL( SW_PROP_NAME(UNO_NAME_DATA_BASE_NAME)))
659 				::GetString( rValue, sParam1 );
660             else if(rPropertyName.equalsAsciiL( SW_PROP_NAME(UNO_NAME_DATA_TABLE_NAME)))
661 				::GetString( rValue, sParam2 );
662             else if(rPropertyName.equalsAsciiL( SW_PROP_NAME(UNO_NAME_DATA_COLUMN_NAME)))
663 				::GetString( rValue, sParam3 );
664             else if(rPropertyName.equalsAsciiL( SW_PROP_NAME(UNO_NAME_DATA_COMMAND_TYPE)))
665                 rValue >>= nParam2;
666             if(rPropertyName.equalsAsciiL( SW_PROP_NAME(UNO_NAME_DATA_BASE_URL)))
667                 ::GetString( rValue, sParam5 );
668 
669             if((sParam1.Len() || sParam5.Len())
670                     && sParam2.Len() && sParam3.Len())
671                 GetFldType();
672 			break;
673 		case  RES_SETEXPFLD:
674 			if(rPropertyName.equalsAsciiL( SW_PROP_NAME(UNO_NAME_NUMBERING_SEPARATOR)))
675 				::GetString( rValue, sParam1 );
676 			else if(rPropertyName.equalsAsciiL( SW_PROP_NAME(UNO_NAME_CHAPTER_NUMBERING_LEVEL)))
677 				rValue >>= nParam1;
678 			break;
679 		case RES_DDEFLD:
680 			{
681 				sal_uInt16 nPart = rPropertyName.equalsAsciiL( SW_PROP_NAME(UNO_NAME_DDE_COMMAND_TYPE))  ? 0 :
682 						rPropertyName.equalsAsciiL( SW_PROP_NAME(UNO_NAME_DDE_COMMAND_FILE))  ? 1 :
683 						rPropertyName.equalsAsciiL( SW_PROP_NAME(UNO_NAME_DDE_COMMAND_ELEMENT))  ? 2 :
684 						rPropertyName.equalsAsciiL( SW_PROP_NAME(UNO_NAME_IS_AUTOMATIC_UPDATE)) ? 3 : USHRT_MAX;
685 				if(nPart  < 3 )
686 				{
687 					String sTmp;
688 					if(!sParam1.Len())
689                         (sParam1 = sfx2::cTokenSeperator)
690                                 += sfx2::cTokenSeperator;
691 
692                     sParam1.SetToken( nPart, sfx2::cTokenSeperator,
693 								::GetString( rValue, sTmp ));
694 				}
695 				else if(3 == nPart)
696 					bParam1 = *(sal_Bool*)rValue.getValue();
697 			}
698 			break;
699 		default:
700         	throw beans::UnknownPropertyException(OUString ( RTL_CONSTASCII_USTRINGPARAM ( "Unknown property: " ) ) + rPropertyName, static_cast < cppu::OWeakObject * > ( this ) );
701 		}
702 	}
703 }
704 
GetFldType(sal_Bool bDontCreate) const705 SwFieldType* SwXFieldMaster::GetFldType(sal_Bool bDontCreate) const
706 {
707     if(!bDontCreate && RES_DBFLD == nResTypeId && m_bIsDescriptor && m_pDoc)
708     {
709         SwDBData aData;
710 
711         // set DataSource
712         svx::ODataAccessDescriptor aAcc;
713         if( sParam1.Len() > 0 )
714             aAcc[ svx::daDataSource ]       <<= OUString(sParam1); // DataBaseName
715         else if( sParam5.Len() > 0 )
716             aAcc[ svx::daDatabaseLocation]  <<= OUString(sParam5); // DataBaseURL
717         aData.sDataSource = aAcc.getDataSource();
718 
719         aData.sCommand = sParam2;
720         aData.nCommandType = nParam2;
721         SwDBFieldType aType(m_pDoc, sParam3,  aData);
722         SwFieldType* pType = m_pDoc->InsertFldType(aType);
723         SwXFieldMaster* pThis = ((SwXFieldMaster*)this);
724         pType->Add(pThis);
725         pThis->m_bIsDescriptor = sal_False;
726     }
727     if(m_bIsDescriptor)
728         return 0;
729     else
730         return (SwFieldType*)GetRegisteredIn();
731 }
732 
733 
734 typedef SwFmtFld* SwFmtFldPtr;
735 SV_DECL_PTRARR(SwDependentFields, SwFmtFldPtr, 5, 5)
SV_IMPL_PTRARR(SwDependentFields,SwFmtFldPtr)736 SV_IMPL_PTRARR(SwDependentFields, SwFmtFldPtr)
737 
738 uno::Any SwXFieldMaster::getPropertyValue(const OUString& rPropertyName)
739 		throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException )
740 {
741 	vos::OGuard  aGuard(Application::GetSolarMutex());
742 	uno::Any aRet;
743     SwFieldType* pType = GetFldType(sal_True);
744     if( rPropertyName.equalsAsciiL( SW_PROP_NAME(UNO_NAME_INSTANCE_NAME)) )
745     {
746         String sName;
747         if(pType)
748             SwXTextFieldMasters::getInstanceName(*pType, sName);
749         aRet <<= OUString(sName);
750     }
751     else if(pType)
752 	{
753 		if(rPropertyName.equalsAsciiL( SW_PROP_NAME(UNO_NAME_NAME) ))
754 		{
755 			aRet <<= SwXFieldMaster::GetProgrammaticName(*pType, *GetDoc());
756 		}
757         else if(rPropertyName.equalsAsciiL( SW_PROP_NAME(UNO_NAME_DEPENDENT_TEXT_FIELDS)) )
758 		{
759 			//fill all text fields into a sequence
760 			SwDependentFields aFldArr;
761 			SwIterator<SwFmtFld,SwFieldType> aIter( *pType );
762 			SwFmtFldPtr pFld = aIter.First();
763 			while(pFld)
764 			{
765 				if(pFld->IsFldInDoc())
766 					aFldArr.Insert(pFld, aFldArr.Count());
767 				pFld = aIter.Next();
768 			}
769 
770 			uno::Sequence<uno::Reference <text::XDependentTextField> > aRetSeq(aFldArr.Count());
771 			uno::Reference<text::XDependentTextField>* pRetSeq = aRetSeq.getArray();
772             for(sal_uInt16 i = 0; i < aFldArr.Count(); i++)
773             {
774                 pFld = aFldArr.GetObject(i);
775                 SwXTextField * pInsert = SwXTextField::CreateSwXTextField(*GetDoc(), *pFld);
776 
777                 pRetSeq[i] = uno::Reference<text::XDependentTextField>(pInsert);
778             }
779 			aRet <<= aRetSeq;
780 		}
781 		else if(pType)
782 		{
783 			//TODO: Properties fuer die uebrigen Feldtypen einbauen
784 			sal_uInt16 nMId = GetFieldTypeMId( rPropertyName, *pType );
785 			if( USHRT_MAX != nMId )
786             {
787 				pType->QueryValue( aRet, nMId );
788 
789                 if( rPropertyName.equalsAsciiL( SW_PROP_NAME(UNO_NAME_DATA_BASE_NAME)) ||
790                     rPropertyName.equalsAsciiL( SW_PROP_NAME(UNO_NAME_DATA_BASE_URL)))
791                 {
792                     OUString aDataSource;
793                     aRet >>= aDataSource;
794                     aRet <<= OUString();
795 
796                     OUString *pStr = 0;     // only one of this properties will return
797                                             // a non-empty string.
798                     INetURLObject aObj;
799                     aObj.SetURL( aDataSource );
800                     sal_Bool bIsURL = aObj.GetProtocol() != INET_PROT_NOT_VALID;
801                     if (bIsURL && rPropertyName.equalsAsciiL( SW_PROP_NAME(UNO_NAME_DATA_BASE_URL)))
802                         pStr = &aDataSource;        // DataBaseURL
803                     else if (!bIsURL && rPropertyName.equalsAsciiL( SW_PROP_NAME(UNO_NAME_DATA_BASE_NAME)))
804                         pStr = &aDataSource;        // DataBaseName
805 
806                     if (pStr)
807                         aRet <<= *pStr;
808                 }
809             }
810             else
811         		throw beans::UnknownPropertyException(OUString ( RTL_CONSTASCII_USTRINGPARAM ( "Unknown property: " ) ) + rPropertyName, static_cast < cppu::OWeakObject * > ( this ) );
812 		}
813 		else
814 		{
815 			if(rPropertyName.equalsAsciiL( SW_PROP_NAME(UNO_NAME_DATA_COMMAND_TYPE)) )
816 				aRet <<= nParam2;
817 		}
818 	}
819 	else
820 	{
821 		if(rPropertyName.equalsAsciiL( SW_PROP_NAME(UNO_NAME_DATA_COMMAND_TYPE)) )
822 			aRet <<= nParam2;
823         else if(rPropertyName.equalsAsciiL( SW_PROP_NAME(UNO_NAME_DEPENDENT_TEXT_FIELDS)) )
824         {
825             uno::Sequence<uno::Reference <text::XDependentTextField> > aRetSeq(0);
826             aRet <<= aRetSeq;
827         }
828         else
829 		{
830 			const String* pStr = 0;
831 			String sStr;
832 			switch ( nResTypeId )
833 			{
834 			case RES_USERFLD:
835 				if( rPropertyName.equalsAsciiL( SW_PROP_NAME(UNO_NAME_CONTENT)) )
836 					pStr = &sParam1;
837 				else if(rPropertyName.equalsAsciiL( SW_PROP_NAME(UNO_NAME_VALUE )))
838 					aRet <<= fParam1;
839 				else if(rPropertyName.equalsAsciiL( SW_PROP_NAME(UNO_NAME_IS_EXPRESSION )))
840 					aRet.setValue(&bParam1, ::getBooleanCppuType());
841 				break;
842 			case RES_DBFLD:
843                 if(rPropertyName.equalsAsciiL( SW_PROP_NAME(UNO_NAME_DATA_BASE_NAME)) ||
844                    rPropertyName.equalsAsciiL( SW_PROP_NAME(UNO_NAME_DATA_BASE_URL)))
845                 {
846                     pStr = 0;   // only one of this properties will return
847                                 // a non-empty string.
848                     INetURLObject aObj;
849                     aObj.SetURL( sParam5 );  // SetSmartURL
850                     sal_Bool bIsURL = aObj.GetProtocol() != INET_PROT_NOT_VALID;
851                     if (bIsURL && rPropertyName.equalsAsciiL( SW_PROP_NAME(UNO_NAME_DATA_BASE_URL)))
852                         pStr = &sParam5;        // DataBaseURL
853                     else if ( rPropertyName.equalsAsciiL( SW_PROP_NAME(UNO_NAME_DATA_BASE_NAME)))
854                         pStr = &sParam1;            // DataBaseName
855                 }
856 				else if(rPropertyName.equalsAsciiL( SW_PROP_NAME(UNO_NAME_DATA_TABLE_NAME)))
857 					pStr = &sParam2;
858 				else if(rPropertyName.equalsAsciiL( SW_PROP_NAME(UNO_NAME_DATA_COLUMN_NAME)))
859 					pStr = &sParam3;
860 				break;
861 			case RES_SETEXPFLD:
862 				if(rPropertyName.equalsAsciiL( SW_PROP_NAME(UNO_NAME_NUMBERING_SEPARATOR)))
863 					pStr = &sParam1;
864 				else if(rPropertyName.equalsAsciiL( SW_PROP_NAME(UNO_NAME_CHAPTER_NUMBERING_LEVEL)))
865 					aRet <<= nParam1;
866 				break;
867 			case RES_DDEFLD:
868 				{
869 					sal_uInt16 nPart = rPropertyName.equalsAsciiL( SW_PROP_NAME(UNO_NAME_DDE_COMMAND_TYPE))  ? 0 :
870 						rPropertyName.equalsAsciiL( SW_PROP_NAME(UNO_NAME_DDE_COMMAND_FILE)) ? 1 :
871 							rPropertyName.equalsAsciiL( SW_PROP_NAME(UNO_NAME_DDE_COMMAND_ELEMENT))  ? 2 :
872 							rPropertyName.equalsAsciiL( SW_PROP_NAME(UNO_NAME_IS_AUTOMATIC_UPDATE)) ? 3 : USHRT_MAX;
873 					if(nPart  < 3 )
874                         pStr = &(sStr = sParam1.GetToken(nPart, sfx2::cTokenSeperator));
875 					else if(3 == nPart)
876 						aRet.setValue(&bParam1, ::getBooleanCppuType());
877 				}
878 				break;
879 			default:
880         		throw beans::UnknownPropertyException(OUString ( RTL_CONSTASCII_USTRINGPARAM ( "Unknown property: " ) ) + rPropertyName, static_cast < cppu::OWeakObject * > ( this ) );
881 			}
882 
883 			if( pStr )
884 				aRet <<= OUString( *pStr );
885 		}
886 	}
887 	return aRet;
888 }
889 
addPropertyChangeListener(const OUString &,const uno::Reference<beans::XPropertyChangeListener> &)890 void SwXFieldMaster::addPropertyChangeListener(const OUString& /*PropertyName*/, const uno::Reference< beans::XPropertyChangeListener > & /*aListener*/) throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException )
891 {
892 	DBG_WARNING("not implemented");
893 }
894 
removePropertyChangeListener(const OUString &,const uno::Reference<beans::XPropertyChangeListener> &)895 void SwXFieldMaster::removePropertyChangeListener(const OUString& /*PropertyName*/, const uno::Reference< beans::XPropertyChangeListener > & /*aListener*/) throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException )
896 {
897 	DBG_WARNING("not implemented");
898 }
899 
addVetoableChangeListener(const OUString &,const uno::Reference<beans::XVetoableChangeListener> &)900 void SwXFieldMaster::addVetoableChangeListener(const OUString& /*PropertyName*/, const uno::Reference< beans::XVetoableChangeListener > & /*aListener*/) throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException )
901 {
902 	DBG_WARNING("not implemented");
903 }
904 
removeVetoableChangeListener(const OUString &,const uno::Reference<beans::XVetoableChangeListener> &)905 void SwXFieldMaster::removeVetoableChangeListener(const OUString& /*PropertyName*/, const uno::Reference< beans::XVetoableChangeListener > & /*aListener*/) throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException )
906 {
907 	DBG_WARNING("not implemented");
908 }
909 
910 
dispose(void)911 void SwXFieldMaster::dispose(void) 			throw( uno::RuntimeException )
912 {
913     vos::OGuard aGuard( Application::GetSolarMutex() );
914 
915     SwFieldType* pFldType = GetFldType( sal_True );
916     if ( pFldType != NULL )
917     {
918         sal_uInt16 nTypeIdx = USHRT_MAX;
919         const SwFldTypes* pTypes = GetDoc()->GetFldTypes();
920         for ( sal_uInt16 i = 0; i < pTypes->Count(); i++ )
921         {
922             if ( ( *pTypes )[i] == pFldType )
923                 nTypeIdx = i;
924         }
925 
926         // zuerst alle Felder loeschen
927         SwIterator< SwFmtFld, SwFieldType > aIter( *pFldType );
928         SwFmtFld* pFld = aIter.First();
929         while ( pFld != NULL )
930         {
931             SwTxtFld* pTxtFld = pFld->GetTxtFld();
932             if ( pTxtFld != NULL
933                  && pTxtFld->GetTxtNode().GetNodes().IsDocNodes() )
934             {
935                 SwTxtFld::DeleteTxtFld( *pTxtFld );
936             }
937             pFld = aIter.Next();
938         }
939         // dann den FieldType loeschen
940         GetDoc()->RemoveFldType( nTypeIdx );
941     }
942     else
943         throw uno::RuntimeException();
944 }
945 
addEventListener(const uno::Reference<lang::XEventListener> & aListener)946 void SwXFieldMaster::addEventListener(const uno::Reference< lang::XEventListener > & aListener)
947 											throw( uno::RuntimeException )
948 {
949 	if(!GetRegisteredIn())
950 		throw uno::RuntimeException();
951 	aLstnrCntnr.AddListener(aListener);
952 }
953 
removeEventListener(const uno::Reference<lang::XEventListener> & aListener)954 void SwXFieldMaster::removeEventListener(const uno::Reference< lang::XEventListener > & aListener)
955 													throw( uno::RuntimeException )
956 {
957 	if(!GetRegisteredIn() || !aLstnrCntnr.RemoveListener(aListener))
958 		throw uno::RuntimeException();
959 }
960 
961 
Modify(const SfxPoolItem * pOld,const SfxPoolItem * pNew)962 void SwXFieldMaster::Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew)
963 {
964 	ClientModify(this, pOld, pNew);
965 	if(!GetRegisteredIn())
966 	{
967 		aLstnrCntnr.Disposing();
968 		m_pDoc = 0;
969 	}
970 }
971 
GetProgrammaticName(const SwFieldType & rType,SwDoc & rDoc)972 OUString SwXFieldMaster::GetProgrammaticName(const SwFieldType& rType, SwDoc& rDoc)
973 {
974 	OUString sRet(rType.GetName());
975 	if(RES_SETEXPFLD == rType.Which())
976 	{
977 		const SwFldTypes* pTypes = rDoc.GetFldTypes();
978 		for( sal_uInt16 i = 0; i <= INIT_FLDTYPES; i++ )
979 		{
980 			if((*pTypes)[i] == &rType)
981 			{
982 				sRet = SwStyleNameMapper::GetProgName ( sRet, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL );
983 				break;
984 			}
985 		}
986 	}
987 	return sRet;
988 }
989 
LocalizeFormula(const SwSetExpField & rFld,const OUString & rFormula,sal_Bool bQuery)990 OUString SwXFieldMaster::LocalizeFormula(
991 	const SwSetExpField& rFld,
992 	const OUString& rFormula,
993 	sal_Bool bQuery)
994 {
995 	const OUString sTypeName(rFld.GetTyp()->GetName());
996 	OUString sProgName = SwStyleNameMapper::GetProgName(sTypeName, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL );
997 	if(sProgName != sTypeName)
998 	{
999 		OUString sSource = bQuery ? sTypeName : sProgName;
1000 		OUString sDest = bQuery ? sProgName : sTypeName;
1001 		if(!rFormula.compareTo(sSource, sSource.getLength()))
1002 		{
1003 			OUString sTmpFormula = sDest;
1004 			sTmpFormula += rFormula.copy(sSource.getLength());
1005 			return sTmpFormula;
1006 		}
1007 	}
1008 	return rFormula;
1009 }
1010 
1011 
CreateSwXTextField(SwDoc & rDoc,SwFmtFld const & rFmt)1012 SwXTextField* SwXTextField::CreateSwXTextField(SwDoc & rDoc, SwFmtFld const& rFmt)
1013 {
1014     SwIterator<SwXTextField,SwFieldType> aIter(*rFmt.GetField()->GetTyp());
1015     SwXTextField * pField = 0;
1016     SwXTextField * pTemp = aIter.First();
1017     while (pTemp)
1018     {
1019         if (pTemp->GetFldFmt() == &rFmt)
1020         {
1021             pField = pTemp;
1022             break;
1023         }
1024         pTemp = aIter.Next();
1025     }
1026     return pField ? pField : new SwXTextField( rFmt, &rDoc );
1027 }
1028 
1029 /******************************************************************
1030  *
1031  ******************************************************************/
1032 struct SwFieldProperties_Impl
1033 {
1034 	String 		sPar1;
1035 	String 		sPar2;
1036 	String 		sPar3;
1037 	String 		sPar4;
1038     String      sPar5;
1039     String      sPar6;
1040 	Date 			aDate;
1041 	double 			fDouble;
1042 	uno::Sequence<beans::PropertyValue>	aPropSeq;
1043     uno::Sequence<OUString> aStrings;
1044 	util::DateTime*	pDateTime;
1045 
1046 	sal_Int32 		nSubType;
1047 	sal_Int32 		nFormat;
1048 	sal_uInt16 		nUSHORT1;
1049 	sal_uInt16 		nUSHORT2;
1050 	sal_Int16 		nSHORT1;
1051 	sal_Int8 		nByte1;
1052     sal_Bool        bFormatIsDefault;
1053 	sal_Bool 		bBool1;
1054 	sal_Bool 		bBool2;
1055 	sal_Bool 		bBool3;
1056     sal_Bool        bBool4;
1057 
SwFieldProperties_ImplSwFieldProperties_Impl1058 	SwFieldProperties_Impl():
1059 		fDouble(0.),
1060 		pDateTime(0),
1061 		nSubType(0),
1062 		nFormat(0),
1063 		nUSHORT1(0),
1064 		nUSHORT2(0),
1065 		nSHORT1(0),
1066 		nByte1(0),
1067         bFormatIsDefault(sal_True),
1068 		bBool1(sal_False),
1069 		bBool2(sal_False),
1070 		bBool3(sal_False),
1071         bBool4(sal_True) //Automatic language
1072 		{}
~SwFieldProperties_ImplSwFieldProperties_Impl1073 	~SwFieldProperties_Impl()
1074 		{delete pDateTime;}
1075 
1076 };
1077 
1078 TYPEINIT1(SwXTextField, SwClient);
1079 
getUnoTunnelId()1080 const uno::Sequence< sal_Int8 > & SwXTextField::getUnoTunnelId()
1081 {
1082     static uno::Sequence< sal_Int8 > aSeq = ::CreateUnoTunnelId();
1083 	return aSeq;
1084 }
1085 
getSomething(const uno::Sequence<sal_Int8> & rId)1086 sal_Int64 SAL_CALL SwXTextField::getSomething( const uno::Sequence< sal_Int8 >& rId )
1087 	throw(uno::RuntimeException)
1088 {
1089     if( rId.getLength() == 16
1090         && 0 == rtl_compareMemory( getUnoTunnelId().getConstArray(),
1091 										rId.getConstArray(), 16 ) )
1092     {
1093 		return sal::static_int_cast< sal_Int64 >( reinterpret_cast< sal_IntPtr >(this) );
1094     }
1095 	return 0;
1096 }
1097 
SwXTextField(sal_uInt16 nServiceId,SwDoc * pDoc)1098 SwXTextField::SwXTextField(
1099     sal_uInt16 nServiceId,
1100     SwDoc* pDoc )
1101     : m_aLstnrCntnr( (XTextContent*)this)
1102     , m_pFmtFld(0)
1103     , m_pDoc(pDoc)
1104     , m_pTextObject(0)
1105     , m_bIsDescriptor(nServiceId != USHRT_MAX)
1106     , m_bCallUpdate(sal_False)
1107     , m_nServiceId(nServiceId)
1108     , m_pProps( new SwFieldProperties_Impl() )
1109 {
1110     //Set visible as default!
1111     if ( SW_SERVICE_FIELDTYPE_SET_EXP == nServiceId
1112          || SW_SERVICE_FIELDTYPE_DATABASE_SET_NUM == nServiceId
1113          || SW_SERVICE_FIELDTYPE_DATABASE == nServiceId
1114          || SW_SERVICE_FIELDTYPE_DATABASE_NAME == nServiceId )
1115     {
1116         m_pProps->bBool2 = sal_True;
1117     }
1118     else if( SW_SERVICE_FIELDTYPE_TABLE_FORMULA == nServiceId )
1119     {
1120         m_pProps->bBool1 = sal_True;
1121     }
1122     if ( SW_SERVICE_FIELDTYPE_SET_EXP == nServiceId )
1123     {
1124         m_pProps->nUSHORT2 = USHRT_MAX;
1125     }
1126 
1127 }
1128 
SwXTextField(const SwFmtFld & rFmt,SwDoc * pDc)1129 SwXTextField::SwXTextField(
1130     const SwFmtFld& rFmt,
1131     SwDoc* pDc )
1132     : m_aLstnrCntnr( (XTextContent*)this)
1133     , m_pFmtFld(&rFmt)
1134     , m_pDoc(pDc)
1135     , m_pTextObject(0)
1136     , m_bIsDescriptor(sal_False)
1137     , m_bCallUpdate(sal_False)
1138     , m_nServiceId( lcl_GetServiceForField( *m_pFmtFld->GetField() ) )
1139     , m_pProps(0)
1140 {
1141     pDc->GetUnoCallBack()->Add(this);
1142 }
1143 
~SwXTextField()1144 SwXTextField::~SwXTextField()
1145 {
1146 	if ( m_pTextObject )
1147 	{
1148 		m_pTextObject->DisposeEditSource();
1149 		m_pTextObject->release();
1150 	}
1151 
1152 	delete m_pProps;
1153 }
1154 
attachTextFieldMaster(const uno::Reference<beans::XPropertySet> & xFieldMaster)1155 void SwXTextField::attachTextFieldMaster(const uno::Reference< beans::XPropertySet > & xFieldMaster)
1156 					throw( lang::IllegalArgumentException, uno::RuntimeException )
1157 {
1158 	vos::OGuard  aGuard(Application::GetSolarMutex());
1159 	if(!m_bIsDescriptor)
1160 		throw uno::RuntimeException();
1161 	uno::Reference< lang::XUnoTunnel > xMasterTunnel(xFieldMaster, uno::UNO_QUERY);
1162     if (!xMasterTunnel.is())
1163         throw lang::IllegalArgumentException();
1164 	SwXFieldMaster* pMaster = reinterpret_cast< SwXFieldMaster * >(
1165 			sal::static_int_cast< sal_IntPtr >( xMasterTunnel->getSomething( SwXFieldMaster::getUnoTunnelId()) ));
1166 
1167 	SwFieldType* pFieldType = pMaster ? pMaster->GetFldType() : 0;
1168 	if(pFieldType && pFieldType->Which() == lcl_ServiceIdToResId(m_nServiceId))
1169 	{
1170 		m_sTypeName = pFieldType->GetName();
1171         pFieldType->Add( &m_aFieldTypeClient );
1172 	}
1173 	else
1174 		throw lang::IllegalArgumentException();
1175 
1176 }
1177 
getTextFieldMaster(void)1178 uno::Reference< beans::XPropertySet >  SwXTextField::getTextFieldMaster(void) throw( uno::RuntimeException )
1179 {
1180 	vos::OGuard  aGuard(Application::GetSolarMutex());
1181     SwFieldType* pType = 0;
1182     if( m_bIsDescriptor && m_aFieldTypeClient.GetRegisteredIn() )
1183     {
1184         pType = (SwFieldType*)m_aFieldTypeClient.GetRegisteredIn();
1185     }
1186     else
1187     {
1188         if(!GetRegisteredIn())
1189             throw uno::RuntimeException();
1190         pType = m_pFmtFld->GetField()->GetTyp();
1191     }
1192 
1193     SwXFieldMaster* pMaster = SwIterator<SwXFieldMaster,SwFieldType>::FirstElement( *pType );
1194 	if(!pMaster)
1195 		pMaster = new SwXFieldMaster(*pType, GetDoc());
1196 
1197 	return pMaster;
1198 }
1199 
getPresentation(sal_Bool bShowCommand)1200 OUString SwXTextField::getPresentation(sal_Bool bShowCommand) throw( uno::RuntimeException )
1201 {
1202 	vos::OGuard  aGuard(Application::GetSolarMutex());
1203 
1204     SwField const*const pField = GetField();
1205     if (!pField)
1206     {
1207 		throw uno::RuntimeException();
1208     }
1209     ::rtl::OUString const ret( (bShowCommand)
1210             ? pField->GetFieldName()
1211             : pField->ExpandField(true) );
1212     return ret;
1213 }
1214 
attachToRange(const uno::Reference<text::XTextRange> & xTextRange)1215 void SwXTextField::attachToRange(
1216 		const uno::Reference< text::XTextRange > & xTextRange)
1217 	throw( lang::IllegalArgumentException, uno::RuntimeException )
1218 {
1219 	vos::OGuard  aGuard(Application::GetSolarMutex());
1220 	if(!m_bIsDescriptor)
1221 		throw uno::RuntimeException();
1222 	uno::Reference<lang::XUnoTunnel> xRangeTunnel( xTextRange, uno::UNO_QUERY);
1223 	SwXTextRange* pRange = 0;
1224 	OTextCursorHelper* pCursor = 0;
1225 	if(xRangeTunnel.is())
1226 	{
1227 		pRange 	= reinterpret_cast< SwXTextRange * >(
1228 				sal::static_int_cast< sal_IntPtr >( xRangeTunnel->getSomething( SwXTextRange::getUnoTunnelId()) ));
1229 		pCursor	= reinterpret_cast< OTextCursorHelper * >(
1230 				sal::static_int_cast< sal_IntPtr >( xRangeTunnel->getSomething( OTextCursorHelper::getUnoTunnelId()) ));
1231 	}
1232 
1233     SwDoc* pDoc = pRange ? (SwDoc*)pRange->GetDoc() : pCursor ? (SwDoc*)pCursor->GetDoc() : 0;
1234     //wurde ein FieldMaster attached, dann ist das Dokument schon festgelegt!
1235     if(pDoc && (!m_pDoc || m_pDoc == pDoc))
1236     {
1237         SwUnoInternalPaM aPam(*pDoc);
1238         ::sw::XTextRangeToSwPaM(aPam, xTextRange);
1239         SwField* pFld = 0;
1240         switch(m_nServiceId)
1241         {
1242         case SW_SERVICE_FIELDTYPE_ANNOTATION:
1243             {
1244                 SwFieldType* pFldType = pDoc->GetSysFldType(RES_POSTITFLD);
1245 
1246                 DateTime aDateTime;
1247                 if (m_pProps->pDateTime)
1248                 {
1249                     aDateTime.SetYear(m_pProps->pDateTime->Year);
1250                     aDateTime.SetMonth(m_pProps->pDateTime->Month);
1251                     aDateTime.SetDay(m_pProps->pDateTime->Day);
1252                     aDateTime.SetHour(m_pProps->pDateTime->Hours);
1253                     aDateTime.SetMin(m_pProps->pDateTime->Minutes);
1254                     aDateTime.SetSec(m_pProps->pDateTime->Seconds);
1255                 }
1256                 SwPostItField* pPostItField = new SwPostItField(
1257                     (SwPostItFieldType*)pFldType,
1258                     m_pProps->sPar2, // content
1259                     m_pProps->sPar1, // author
1260                     m_pProps->sPar3, // author's initials
1261                     m_pProps->sPar4, // name
1262                     aDateTime );
1263                 if ( m_pTextObject )
1264                 {
1265                     pPostItField->SetTextObject( m_pTextObject->CreateText() );
1266                     pPostItField->SetPar2(m_pTextObject->GetText());
1267                 }
1268                 pFld = pPostItField;
1269             }
1270             break;
1271 
1272         case SW_SERVICE_FIELDTYPE_SCRIPT:
1273             {
1274                 SwFieldType* pFldType = pDoc->GetSysFldType(RES_SCRIPTFLD);
1275                 pFld = new SwScriptField((SwScriptFieldType*)pFldType,
1276                     m_pProps->sPar1, m_pProps->sPar2,
1277                     m_pProps->bBool1);
1278             }
1279             break;
1280 
1281         case SW_SERVICE_FIELDTYPE_DATETIME:
1282             {
1283                 sal_uInt16 nSub = 0;
1284                 if(m_pProps->bBool1)
1285                     nSub |= FIXEDFLD;
1286                 if(m_pProps->bBool2)
1287                     nSub |= DATEFLD;
1288                 else
1289                     nSub |= TIMEFLD;
1290                 SwFieldType* pFldType = pDoc->GetSysFldType(RES_DATETIMEFLD);
1291                 pFld = new SwDateTimeField((SwDateTimeFieldType*)pFldType,
1292                     nSub, m_pProps->nFormat);
1293                 if(m_pProps->fDouble > 0.)
1294                     ((SwDateTimeField*)pFld)->SetValue( m_pProps->fDouble );
1295                 if(m_pProps->pDateTime)
1296                 {
1297                     uno::Any aVal; aVal <<= *m_pProps->pDateTime;
1298                     pFld->PutValue( aVal, FIELD_PROP_DATE_TIME );
1299                 }
1300                 ((SwDateTimeField*)pFld)->SetOffset(m_pProps->nSubType);
1301             }
1302             break;
1303 
1304         case SW_SERVICE_FIELDTYPE_FILE_NAME:
1305             {
1306                 SwFieldType* pFldType = pDoc->GetSysFldType(RES_FILENAMEFLD);
1307                 sal_Int32 nFormat = m_pProps->nFormat;
1308                 if(m_pProps->bBool2)
1309                     nFormat |= FF_FIXED;
1310                 pFld = new SwFileNameField((SwFileNameFieldType*)pFldType, nFormat);
1311                 if(m_pProps->sPar3.Len())
1312                     ((SwFileNameField*)pFld)->SetExpansion(m_pProps->sPar3);
1313                 uno::Any aFormat(&m_pProps->nFormat, ::getCppuType(&m_pProps->nFormat));
1314                 pFld->PutValue( aFormat, FIELD_PROP_FORMAT );
1315             }
1316             break;
1317 
1318         case SW_SERVICE_FIELDTYPE_TEMPLATE_NAME:
1319             {
1320                 SwFieldType* pFldType = pDoc->GetSysFldType(RES_TEMPLNAMEFLD);
1321                 pFld = new SwTemplNameField((SwTemplNameFieldType*)pFldType,
1322                     m_pProps->nFormat);
1323                 uno::Any aFormat(&m_pProps->nFormat, ::getCppuType(&m_pProps->nFormat));
1324                 pFld->PutValue(aFormat, FIELD_PROP_FORMAT);
1325             }
1326             break;
1327 
1328         case SW_SERVICE_FIELDTYPE_CHAPTER:
1329             {
1330                 SwFieldType* pFldType = pDoc->GetSysFldType(RES_CHAPTERFLD);
1331                 pFld = new SwChapterField((SwChapterFieldType*)pFldType, m_pProps->nUSHORT1);
1332                 ((SwChapterField*)pFld)->SetLevel(m_pProps->nByte1);
1333                 uno::Any aVal; aVal <<= (sal_Int16)m_pProps->nUSHORT1;
1334                 pFld->PutValue(aVal, FIELD_PROP_USHORT1 );
1335             }
1336             break;
1337         case SW_SERVICE_FIELDTYPE_AUTHOR:
1338             {
1339                 long nFormat = m_pProps->bBool1 ? AF_NAME : AF_SHORTCUT;
1340                 if(m_pProps->bBool2)
1341                     nFormat |= AF_FIXED;
1342 
1343                 SwFieldType* pFldType = pDoc->GetSysFldType(RES_AUTHORFLD);
1344                 pFld = new SwAuthorField((SwAuthorFieldType*)pFldType, nFormat);
1345                 ((SwAuthorField*)pFld)->SetExpansion(m_pProps->sPar1);
1346             }
1347             break;
1348 
1349         case SW_SERVICE_FIELDTYPE_CONDITIONED_TEXT:
1350         case SW_SERVICE_FIELDTYPE_HIDDEN_TEXT:
1351             {
1352                 SwFieldType* pFldType = pDoc->GetSysFldType(RES_HIDDENTXTFLD);
1353                 pFld = new SwHiddenTxtField(((SwHiddenTxtFieldType*)pFldType),
1354                     m_pProps->sPar1,
1355                     m_pProps->sPar2, m_pProps->sPar3,
1356                     static_cast< sal_uInt16 >(SW_SERVICE_FIELDTYPE_HIDDEN_TEXT == m_nServiceId ? TYP_HIDDENTXTFLD : TYP_CONDTXTFLD));
1357                 ((SwHiddenTxtField*)pFld)->SetValue(m_pProps->bBool1);
1358                 uno::Any aVal; aVal <<= (OUString)m_pProps->sPar4;
1359                 pFld->PutValue(aVal, FIELD_PROP_PAR4 );
1360             }
1361             break;
1362 
1363 			case SW_SERVICE_FIELDTYPE_HIDDEN_PARA:
1364 			{
1365 				SwFieldType* pFldType = pDoc->GetSysFldType(RES_HIDDENPARAFLD);
1366 				pFld = new SwHiddenParaField((SwHiddenParaFieldType*)pFldType,
1367 												m_pProps->sPar1);
1368                 ((SwHiddenParaField*)pFld)->SetHidden(m_pProps->bBool1);
1369 			}
1370 			break;
1371 			case SW_SERVICE_FIELDTYPE_GET_REFERENCE:
1372 			{
1373 				SwFieldType* pFldType = pDoc->GetSysFldType(RES_GETREFFLD);
1374 				pFld = new SwGetRefField((SwGetRefFieldType*)pFldType,
1375 							m_pProps->sPar1,
1376 							0,
1377 							0,
1378 							0);
1379 				if(m_pProps->sPar3.Len())
1380 					((SwGetRefField*)pFld)->SetExpand(m_pProps->sPar3);
1381 				uno::Any aVal; aVal <<=(sal_Int16)m_pProps->nUSHORT1;
1382 				pFld->PutValue(aVal, FIELD_PROP_USHORT1 );
1383 				aVal <<=(sal_Int16)m_pProps->nUSHORT2;
1384 				pFld->PutValue(aVal, FIELD_PROP_USHORT2 );
1385 				aVal <<=(sal_Int16)m_pProps->nSHORT1;
1386 				pFld->PutValue(aVal, FIELD_PROP_SHORT1 );
1387 			}
1388 			break;
1389 			case SW_SERVICE_FIELDTYPE_JUMP_EDIT:
1390 			{
1391 				SwFieldType* pFldType = pDoc->GetSysFldType(RES_JUMPEDITFLD);
1392 				pFld = new SwJumpEditField((SwJumpEditFieldType*)pFldType,
1393 						m_pProps->nUSHORT1, m_pProps->sPar2, m_pProps->sPar1);
1394 			}
1395 			break;
1396 			case SW_SERVICE_FIELDTYPE_DOCINFO_CHANGE_AUTHOR		:
1397 			case SW_SERVICE_FIELDTYPE_DOCINFO_CHANGE_DATE_TIME  :
1398 			case SW_SERVICE_FIELDTYPE_DOCINFO_EDIT_TIME         :
1399 			case SW_SERVICE_FIELDTYPE_DOCINFO_DESCRIPTION       :
1400 			case SW_SERVICE_FIELDTYPE_DOCINFO_CREATE_AUTHOR     :
1401 			case SW_SERVICE_FIELDTYPE_DOCINFO_CREATE_DATE_TIME  :
1402 			case SW_SERVICE_FIELDTYPE_DOCINFO_CUSTOM            :
1403 			case SW_SERVICE_FIELDTYPE_DOCINFO_PRINT_AUTHOR      :
1404 			case SW_SERVICE_FIELDTYPE_DOCINFO_PRINT_DATE_TIME   :
1405 			case SW_SERVICE_FIELDTYPE_DOCINFO_KEY_WORDS         :
1406 			case SW_SERVICE_FIELDTYPE_DOCINFO_SUBJECT           :
1407 			case SW_SERVICE_FIELDTYPE_DOCINFO_TITLE             :
1408 			case SW_SERVICE_FIELDTYPE_DOCINFO_REVISION          :
1409 			case SW_SERVICE_FIELDTYPE_DOC_INFO:
1410 			{
1411 				SwFieldType* pFldType = pDoc->GetSysFldType(RES_DOCINFOFLD);
1412 				sal_uInt16 nSubType = aDocInfoSubTypeFromService[
1413 						m_nServiceId - SW_SERVICE_FIELDTYPE_DOCINFO_CHANGE_AUTHOR];
1414 				if( SW_SERVICE_FIELDTYPE_DOCINFO_CHANGE_DATE_TIME == m_nServiceId ||
1415 					SW_SERVICE_FIELDTYPE_DOCINFO_CREATE_DATE_TIME == m_nServiceId ||
1416 					SW_SERVICE_FIELDTYPE_DOCINFO_PRINT_DATE_TIME == m_nServiceId ||
1417 					SW_SERVICE_FIELDTYPE_DOCINFO_EDIT_TIME == m_nServiceId )
1418 				{
1419 					if(m_pProps->bBool2) //IsDate
1420 					{
1421 						nSubType &= 0xf0ff;
1422 						nSubType |= DI_SUB_DATE;
1423 					}
1424 					else
1425 					{
1426 						nSubType &= 0xf0ff;
1427 						nSubType |= DI_SUB_TIME;
1428 					}
1429 				}
1430 				if(m_pProps->bBool1)
1431 					nSubType |= DI_SUB_FIXED;
1432 				pFld = new SwDocInfoField((SwDocInfoFieldType*)pFldType, nSubType, m_pProps->sPar4, m_pProps->nFormat);
1433 				if(m_pProps->sPar3.Len())
1434 					((SwDocInfoField*)pFld)->SetExpansion(m_pProps->sPar3);
1435 			}
1436 			break;
1437 			case SW_SERVICE_FIELDTYPE_USER_EXT:
1438 			{
1439 				sal_Int32 nFormat = 0;
1440 				if(m_pProps->bBool1)
1441 					nFormat = AF_FIXED;
1442 
1443 				SwFieldType* pFldType = pDoc->GetSysFldType(RES_EXTUSERFLD);
1444 				pFld = new SwExtUserField((SwExtUserFieldType*)pFldType, m_pProps->nUSHORT1, nFormat);
1445 				((SwExtUserField*)pFld)->SetExpansion(m_pProps->sPar1);
1446 			}
1447 			break;
1448 			case SW_SERVICE_FIELDTYPE_USER:
1449 			{
1450 				SwFieldType* pFldType = pDoc->GetFldType(RES_USERFLD, m_sTypeName, sal_True);
1451 				if(!pFldType)
1452 					throw uno::RuntimeException();
1453 				sal_uInt16 nUserSubType = m_pProps->bBool1 ? nsSwExtendedSubType::SUB_INVISIBLE : 0;
1454 				if(m_pProps->bBool2)
1455 					nUserSubType |= nsSwExtendedSubType::SUB_CMD;
1456                 if(m_pProps->bFormatIsDefault &&
1457                     nsSwGetSetExpType::GSE_STRING == ((SwUserFieldType*)pFldType)->GetType())
1458                         m_pProps->nFormat = -1;
1459 				pFld = new SwUserField((SwUserFieldType*)pFldType,
1460 									nUserSubType,
1461 									m_pProps->nFormat);
1462 			}
1463 			break;
1464 			case SW_SERVICE_FIELDTYPE_REF_PAGE_SET:
1465 			{
1466 				SwFieldType* pFldType = pDoc->GetSysFldType(RES_REFPAGESETFLD);
1467 				pFld = new SwRefPageSetField( (SwRefPageSetFieldType*)pFldType,
1468 									m_pProps->nUSHORT1,
1469 									m_pProps->bBool1 );
1470 			}
1471 			break;
1472 			case SW_SERVICE_FIELDTYPE_REF_PAGE_GET:
1473 			{
1474 				SwFieldType* pFldType = pDoc->GetSysFldType(RES_REFPAGEGETFLD);
1475 				pFld = new SwRefPageGetField( (SwRefPageGetFieldType*)pFldType,
1476 												m_pProps->nUSHORT1 );
1477                 ((SwRefPageGetField*)pFld)->SetText(m_pProps->sPar1);
1478 			}
1479 			break;
1480 			case SW_SERVICE_FIELDTYPE_PAGE_NUM:
1481 			{
1482 				SwFieldType* pFldType = pDoc->GetSysFldType(RES_PAGENUMBERFLD);
1483 				pFld = new SwPageNumberField((SwPageNumberFieldType*)pFldType,
1484 												PG_RANDOM,
1485 												m_pProps->nFormat,
1486 												m_pProps->nUSHORT1);
1487 				((SwPageNumberField*)pFld)->SetUserString(m_pProps->sPar1);
1488                 uno::Any aVal; aVal <<= m_pProps->nSubType;
1489                 pFld->PutValue( aVal, FIELD_PROP_SUBTYPE );
1490             }
1491 			break;
1492 			case SW_SERVICE_FIELDTYPE_DDE:
1493 			{
1494 				SwFieldType* pFldType = pDoc->GetFldType(RES_DDEFLD, m_sTypeName, sal_True);
1495 				if(!pFldType)
1496 					throw uno::RuntimeException();
1497 				pFld = new SwDDEField( (SwDDEFieldType*)pFldType );
1498 			}
1499 			break;
1500 			case SW_SERVICE_FIELDTYPE_DATABASE_NAME:
1501 			{
1502 				SwFieldType* pFldType = pDoc->GetSysFldType(RES_DBNAMEFLD);
1503 				SwDBData aData;
1504 				aData.sDataSource = m_pProps->sPar1;
1505 				aData.sCommand = m_pProps->sPar2;
1506 				aData.nCommandType = m_pProps->nSHORT1;
1507 				pFld = new SwDBNameField((SwDBNameFieldType*)pFldType, aData);
1508                 sal_uInt16  nSubType = pFld->GetSubType();
1509                 if(m_pProps->bBool2)
1510                     nSubType &= ~nsSwExtendedSubType::SUB_INVISIBLE;
1511                 else
1512                     nSubType |= nsSwExtendedSubType::SUB_INVISIBLE;
1513                 pFld->SetSubType(nSubType);
1514             }
1515 			break;
1516 			case SW_SERVICE_FIELDTYPE_DATABASE_NEXT_SET:
1517 			{
1518 				SwDBData aData;
1519 				aData.sDataSource = m_pProps->sPar1;
1520 				aData.sCommand = m_pProps->sPar2;
1521 				aData.nCommandType = m_pProps->nSHORT1;
1522 				SwFieldType* pFldType = pDoc->GetSysFldType(RES_DBNEXTSETFLD);
1523 				pFld = new SwDBNextSetField((SwDBNextSetFieldType*)pFldType,
1524 						m_pProps->sPar3, aEmptyStr,
1525 						aData);
1526             }
1527 			break;
1528 			case SW_SERVICE_FIELDTYPE_DATABASE_NUM_SET:
1529 			{
1530 				SwDBData aData;
1531 				aData.sDataSource = m_pProps->sPar1;
1532 				aData.sCommand = m_pProps->sPar2;
1533 				aData.nCommandType = m_pProps->nSHORT1;
1534 				pFld = new SwDBNumSetField( (SwDBNumSetFieldType*)
1535 					pDoc->GetSysFldType(RES_DBNUMSETFLD),
1536 					m_pProps->sPar3,
1537 					String::CreateFromInt32(m_pProps->nFormat),
1538 					aData );
1539             }
1540 			break;
1541 			case SW_SERVICE_FIELDTYPE_DATABASE_SET_NUM:
1542 			{
1543 				SwDBData aData;
1544 				aData.sDataSource = m_pProps->sPar1;
1545 				aData.sCommand = m_pProps->sPar2;
1546 				aData.nCommandType = m_pProps->nSHORT1;
1547 				pFld = new SwDBSetNumberField((SwDBSetNumberFieldType*)
1548 						pDoc->GetSysFldType(RES_DBSETNUMBERFLD),
1549 						aData,
1550 						m_pProps->nUSHORT1);
1551 				((SwDBSetNumberField*)pFld)->SetSetNumber(m_pProps->nFormat);
1552                 sal_uInt16  nSubType = pFld->GetSubType();
1553                 if(m_pProps->bBool2)
1554                     nSubType &= ~nsSwExtendedSubType::SUB_INVISIBLE;
1555                 else
1556                     nSubType |= nsSwExtendedSubType::SUB_INVISIBLE;
1557                 pFld->SetSubType(nSubType);
1558             }
1559 			break;
1560 			case SW_SERVICE_FIELDTYPE_DATABASE:
1561 			{
1562 				SwFieldType* pFldType = pDoc->GetFldType(RES_DBFLD, m_sTypeName, sal_False);
1563 				if(!pFldType)
1564 					throw uno::RuntimeException();
1565 				pFld = new SwDBField((SwDBFieldType*)pFldType, m_pProps->nFormat);
1566 				((SwDBField*)pFld)->InitContent(m_pProps->sPar1);
1567                 sal_uInt16  nSubType = pFld->GetSubType();
1568                 if(m_pProps->bBool2)
1569                     nSubType &= ~nsSwExtendedSubType::SUB_INVISIBLE;
1570                 else
1571                     nSubType |= nsSwExtendedSubType::SUB_INVISIBLE;
1572                 pFld->SetSubType(nSubType);
1573 			}
1574 			break;
1575 			case SW_SERVICE_FIELDTYPE_SET_EXP:
1576 			{
1577 				SwFieldType* pFldType = pDoc->GetFldType(RES_SETEXPFLD, m_sTypeName, sal_True);
1578 				if(!pFldType)
1579 					throw uno::RuntimeException();
1580                 //#93192# detect the field type's sub type and set an appropriate number format
1581                 if(m_pProps->bFormatIsDefault &&
1582                     nsSwGetSetExpType::GSE_STRING == ((SwSetExpFieldType*)pFldType)->GetType())
1583                         m_pProps->nFormat = -1;
1584                 pFld = new SwSetExpField((SwSetExpFieldType*)pFldType,
1585 					m_pProps->sPar2,
1586                     m_pProps->nUSHORT2 != USHRT_MAX ?  //#i79471# the field can have a number format or a number_ing_ format
1587                     m_pProps->nUSHORT2 : m_pProps->nFormat);
1588 
1589 				sal_uInt16	nSubType = pFld->GetSubType();
1590 				if(m_pProps->bBool2)
1591 					nSubType &= ~nsSwExtendedSubType::SUB_INVISIBLE;
1592 				else
1593 					nSubType |= nsSwExtendedSubType::SUB_INVISIBLE;
1594 				if(m_pProps->bBool3)
1595 					nSubType |= nsSwExtendedSubType::SUB_CMD;
1596 				else
1597 					nSubType &= ~nsSwExtendedSubType::SUB_CMD;
1598 				pFld->SetSubType(nSubType);
1599 				((SwSetExpField*)pFld)->SetSeqNumber( m_pProps->nUSHORT1 );
1600 				((SwSetExpField*)pFld)->SetInputFlag(m_pProps->bBool1);
1601 				((SwSetExpField*)pFld)->SetPromptText(m_pProps->sPar3);
1602 				if(m_pProps->sPar4.Len())
1603 					((SwSetExpField*)pFld)->ChgExpStr(m_pProps->sPar4);
1604 
1605 			}
1606 			break;
1607 			case SW_SERVICE_FIELDTYPE_GET_EXP:
1608 			{
1609 				sal_uInt16 nSubType;
1610 				switch(m_pProps->nSubType)
1611 				{
1612                     case text::SetVariableType::STRING: nSubType = nsSwGetSetExpType::GSE_STRING;   break;
1613                     case text::SetVariableType::VAR:        nSubType = nsSwGetSetExpType::GSE_EXPR;  break;
1614 					//case text::SetVariableType::SEQUENCE:   nSubType = nsSwGetSetExpType::GSE_SEQ;  break;
1615                     case text::SetVariableType::FORMULA:    nSubType = nsSwGetSetExpType::GSE_FORMULA; break;
1616 					default:
1617 						DBG_ERROR("wrong value");
1618 						nSubType = nsSwGetSetExpType::GSE_EXPR;
1619 				}
1620                 //make sure the SubType matches the field type
1621                 SwFieldType* pSetExpFld = pDoc->GetFldType(RES_SETEXPFLD, m_pProps->sPar1, sal_False);
1622                 bool bSetGetExpFieldUninitialized = false;
1623                 if( pSetExpFld )
1624                 {
1625                     if( nSubType != nsSwGetSetExpType::GSE_STRING &&
1626                         static_cast< SwSetExpFieldType* >(pSetExpFld)->GetType() == nsSwGetSetExpType::GSE_STRING )
1627                     nSubType = nsSwGetSetExpType::GSE_STRING;
1628 				}
1629 				else
1630                     bSetGetExpFieldUninitialized = true; // #i82544#
1631 
1632 				if(m_pProps->bBool2)
1633 					nSubType |= nsSwExtendedSubType::SUB_CMD;
1634 				else
1635 					nSubType &= ~nsSwExtendedSubType::SUB_CMD;
1636 				pFld = new SwGetExpField((SwGetExpFieldType*)
1637 						pDoc->GetSysFldType(RES_GETEXPFLD),
1638 						m_pProps->sPar1, nSubType, m_pProps->nFormat);
1639 				//TODO: SubType auswerten!
1640 				if(m_pProps->sPar4.Len())
1641 					((SwGetExpField*)pFld)->ChgExpStr(m_pProps->sPar4);
1642 				// #i82544#
1643                 if( bSetGetExpFieldUninitialized )
1644                     ((SwGetExpField*)pFld)->SetLateInitialization();
1645 			}
1646 			break;
1647 			case SW_SERVICE_FIELDTYPE_INPUT_USER:
1648 			case SW_SERVICE_FIELDTYPE_INPUT:
1649 			{
1650 				SwFieldType* pFldType = pDoc->GetFldType(RES_INPUTFLD, m_sTypeName, sal_True);
1651 				if(!pFldType)
1652 					throw uno::RuntimeException();
1653                 sal_uInt16 nInpSubType = sal::static_int_cast< sal_uInt16 >(SW_SERVICE_FIELDTYPE_INPUT_USER == m_nServiceId ? INP_USR : INP_TXT);
1654                 SwInputField * pTxtField =
1655                     new SwInputField( static_cast<SwInputFieldType*>(pFldType),
1656                                       m_pProps->sPar1,
1657                                       m_pProps->sPar2,
1658                                       nInpSubType );
1659                 pTxtField->SetHelp(m_pProps->sPar3);
1660                 pTxtField->SetToolTip(m_pProps->sPar4);
1661 
1662                 pFld = pTxtField;
1663 			}
1664 			break;
1665 			case SW_SERVICE_FIELDTYPE_MACRO:
1666 			{
1667 				SwFieldType* pFldType = pDoc->GetSysFldType(RES_MACROFLD);
1668 				String aName;
1669 
1670 				// support for Scripting Framework macros
1671 				if (m_pProps->sPar4.Len() != 0)
1672 				{
1673 					aName = m_pProps->sPar4;
1674 				}
1675 				else
1676 				{
1677 					SwMacroField::CreateMacroString(
1678 						aName, m_pProps->sPar1, m_pProps->sPar3 );
1679 				}
1680 				pFld = new SwMacroField((SwMacroFieldType*)pFldType, aName,
1681                                         m_pProps->sPar2);
1682 			}
1683 			break;
1684 			case SW_SERVICE_FIELDTYPE_PAGE_COUNT            :
1685 			case SW_SERVICE_FIELDTYPE_PARAGRAPH_COUNT       :
1686 			case SW_SERVICE_FIELDTYPE_WORD_COUNT            :
1687 			case SW_SERVICE_FIELDTYPE_CHARACTER_COUNT       :
1688 			case SW_SERVICE_FIELDTYPE_TABLE_COUNT           :
1689 			case SW_SERVICE_FIELDTYPE_GRAPHIC_OBJECT_COUNT  :
1690 			case SW_SERVICE_FIELDTYPE_EMBEDDED_OBJECT_COUNT :
1691 			{
1692 				sal_uInt16 nSubType = DS_PAGE;
1693 				switch(m_nServiceId)
1694 				{
1695 //					case SW_SERVICE_FIELDTYPE_PAGE_COUNT            : break;
1696 					case SW_SERVICE_FIELDTYPE_PARAGRAPH_COUNT       : nSubType = DS_PARA;break;
1697 					case SW_SERVICE_FIELDTYPE_WORD_COUNT            : nSubType = DS_WORD;break;
1698 					case SW_SERVICE_FIELDTYPE_CHARACTER_COUNT       : nSubType = DS_CHAR;break;
1699 					case SW_SERVICE_FIELDTYPE_TABLE_COUNT           : nSubType = DS_TBL;break;
1700 					case SW_SERVICE_FIELDTYPE_GRAPHIC_OBJECT_COUNT  : nSubType = DS_GRF;break;
1701 					case SW_SERVICE_FIELDTYPE_EMBEDDED_OBJECT_COUNT : nSubType = DS_OLE;break;
1702 				}
1703 				SwFieldType* pFldType = pDoc->GetSysFldType(RES_DOCSTATFLD);
1704 				pFld = new SwDocStatField((SwDocStatFieldType*)pFldType, nSubType, m_pProps->nUSHORT2);
1705 			}
1706 			break;
1707 			case SW_SERVICE_FIELDTYPE_BIBLIOGRAPHY:
1708 				pFld = new SwAuthorityField( (SwAuthorityFieldType*)
1709 						pDoc->InsertFldType(SwAuthorityFieldType(pDoc)),
1710 						aEmptyStr );
1711 				if(m_pProps->aPropSeq.getLength())
1712 				{
1713 					uno::Any aVal; aVal <<= m_pProps->aPropSeq;
1714 					pFld->PutValue( aVal, FIELD_PROP_PROP_SEQ );
1715 				}
1716 				break;
1717 			case SW_SERVICE_FIELDTYPE_COMBINED_CHARACTERS:
1718 				// create field
1719 				pFld = new SwCombinedCharField( (SwCombinedCharFieldType*)
1720 							pDoc->GetSysFldType(RES_COMBINED_CHARS),
1721 							m_pProps->sPar1);
1722 				break;
1723             case SW_SERVICE_FIELDTYPE_DROPDOWN:
1724                 pFld = new SwDropDownField
1725                     ((SwDropDownFieldType *)
1726                      pDoc->GetSysFldType(RES_DROPDOWN));
1727 
1728                 ((SwDropDownField *) pFld)->SetItems(m_pProps->aStrings);
1729                 ((SwDropDownField *) pFld)->SetSelectedItem(m_pProps->sPar1);
1730                 ((SwDropDownField *) pFld)->SetName(m_pProps->sPar2);
1731                 ((SwDropDownField *) pFld)->SetHelp(m_pProps->sPar3);
1732                 ((SwDropDownField *) pFld)->SetToolTip(m_pProps->sPar4);
1733                 break;
1734 
1735             case SW_SERVICE_FIELDTYPE_TABLE_FORMULA :
1736             {
1737 
1738 				// create field
1739                 sal_uInt16 nType = nsSwGetSetExpType::GSE_FORMULA;
1740                 if(m_pProps->bBool1)
1741                 {
1742                     nType |= nsSwExtendedSubType::SUB_CMD;
1743                     if(m_pProps->bFormatIsDefault)
1744                         m_pProps->nFormat = -1;
1745                 }
1746                 pFld = new SwTblField( (SwTblFieldType*)
1747 					pDoc->GetSysFldType(RES_TABLEFLD),
1748 					m_pProps->sPar2,
1749                     nType,
1750                     m_pProps->nFormat);
1751                ((SwTblField*)pFld)->ChgExpStr(m_pProps->sPar1);
1752             }
1753             break;
1754             default: DBG_ERROR("was ist das fuer ein Typ?");
1755         }
1756         if ( pFld )
1757         {
1758             pFld->SetAutomaticLanguage(!m_pProps->bBool4);
1759             SwFmtFld aFmt( *pFld );
1760 
1761             UnoActionContext aCont(pDoc);
1762             if ( aPam.HasMark()
1763                  && m_nServiceId != SW_SERVICE_FIELDTYPE_ANNOTATION )
1764             {
1765                 pDoc->DeleteAndJoin(aPam);
1766             }
1767 
1768             SwXTextCursor const*const pTextCursor( dynamic_cast<SwXTextCursor*>(pCursor) );
1769             const bool bForceExpandHints(
1770                 (pTextCursor)
1771                 ? pTextCursor->IsAtEndOfMeta()
1772                 : false );
1773             const SetAttrMode nInsertFlags =
1774                 (bForceExpandHints)
1775                 ? nsSetAttrMode::SETATTR_FORCEHINTEXPAND
1776                 : nsSetAttrMode::SETATTR_DEFAULT;
1777 
1778             if ( *aPam.GetPoint() != *aPam.GetMark()
1779                  && m_nServiceId == SW_SERVICE_FIELDTYPE_ANNOTATION )
1780             {
1781                 // Make sure we always insert the annotation at the end of the provided text range
1782                 SwPaM aEnd(*aPam.End(), *aPam.End());
1783                 pDoc->InsertPoolItem(aEnd, aFmt, nInsertFlags);
1784             }
1785             else
1786                 pDoc->InsertPoolItem(aPam, aFmt, nInsertFlags);
1787 
1788             SwTxtAttr* pTxtAttr = aPam.GetNode()->GetTxtNode()->GetFldTxtAttrAt( aPam.GetPoint()->nContent.GetIndex()-1, true );
1789             // was passiert mit dem Update der Felder ? (siehe fldmgr.cxx)
1790             if ( pTxtAttr != NULL )
1791             {
1792                 const SwFmtFld& rFld = pTxtAttr->GetFmtFld();
1793                 m_pFmtFld = &rFld;
1794 
1795                 if ( pTxtAttr->Which() == RES_TXTATR_ANNOTATION
1796                      && *aPam.GetPoint() != *aPam.GetMark() )
1797                 {
1798                     // create annotation mark
1799                     const SwPostItField* pPostItField = dynamic_cast< const SwPostItField* >(pTxtAttr->GetFmtFld().GetField());
1800                     ASSERT( pPostItField != NULL, "<SwXTextField::attachToRange(..)> - annotation field missing!" );
1801                     if ( pPostItField != NULL )
1802                     {
1803                         IDocumentMarkAccess* pMarksAccess = pDoc->getIDocumentMarkAccess();
1804                         pMarksAccess->makeAnnotationMark( aPam, pPostItField->GetName() );
1805                     }
1806                 }
1807             }
1808         }
1809         delete pFld;
1810 
1811         m_pDoc = pDoc;
1812         m_pDoc->GetUnoCallBack()->Add(this);
1813         m_bIsDescriptor = sal_False;
1814         if(m_aFieldTypeClient.GetRegisteredIn())
1815             const_cast<SwModify*>(m_aFieldTypeClient.GetRegisteredIn())->Remove(&m_aFieldTypeClient);
1816         DELETEZ(m_pProps);
1817         if(m_bCallUpdate)
1818             update();
1819     }
1820     else
1821         throw lang::IllegalArgumentException();
1822 }
1823 
attach(const uno::Reference<text::XTextRange> & xTextRange)1824 void SwXTextField::attach( const uno::Reference< text::XTextRange > & xTextRange )
1825     throw( lang::IllegalArgumentException, uno::RuntimeException )
1826 {
1827     vos::OGuard aGuard(Application::GetSolarMutex());
1828 
1829     if ( m_bIsDescriptor )
1830     {
1831         attachToRange( xTextRange );
1832     }
1833     else if ( m_pFmtFld != NULL
1834               && m_pDoc != NULL
1835               && m_nServiceId == SW_SERVICE_FIELDTYPE_ANNOTATION )
1836     {
1837         SwUnoInternalPaM aIntPam( *m_pDoc );
1838         if ( ::sw::XTextRangeToSwPaM( aIntPam, xTextRange ) )
1839         {
1840             // nothing to do, if the text range only covers the former annotation field
1841             if ( aIntPam.Start()->nNode != aIntPam.End()->nNode
1842                  || aIntPam.Start()->nContent.GetIndex() != aIntPam.End()->nContent.GetIndex()-1 )
1843             {
1844                 UnoActionContext aCont( m_pDoc );
1845                 // insert copy of annotation at new text range
1846                 SwPostItField* pPostItField = dynamic_cast< SwPostItField* >(m_pFmtFld->GetField()->CopyField());
1847                 SwFmtFld aFmtFld( *pPostItField );
1848                 delete pPostItField;
1849                 SwPaM aEnd( *aIntPam.End(), *aIntPam.End() );
1850                 m_pDoc->InsertPoolItem( aEnd, aFmtFld, nsSetAttrMode::SETATTR_DEFAULT );
1851                 // delete former annotation
1852                 {
1853                     const SwTxtFld* pTxtFld = m_pFmtFld->GetTxtFld();
1854                     SwTxtNode& rTxtNode = (SwTxtNode&)*pTxtFld->GetpTxtNode();
1855                     SwPaM aPam( rTxtNode, *pTxtFld->GetStart() );
1856                     aPam.SetMark();
1857                     aPam.Move();
1858                     GetDoc()->DeleteAndJoin(aPam);
1859                 }
1860                 // keep inserted annotation
1861                 {
1862                     SwTxtFld* pTxtAttr = aEnd.GetNode()->GetTxtNode()->GetFldTxtAttrAt( aEnd.End()->nContent.GetIndex()-1, true );
1863                     if ( pTxtAttr != NULL )
1864                     {
1865                         m_pFmtFld = &pTxtAttr->GetFmtFld();
1866 
1867                         if ( *aIntPam.GetPoint() != *aIntPam.GetMark() )
1868                         {
1869                             // create annotation mark
1870                             const SwPostItField* pPostItField = dynamic_cast< const SwPostItField* >(pTxtAttr->GetFmtFld().GetField());
1871                             ASSERT( pPostItField != NULL, "<SwXTextField::attach(..)> - annotation field missing!" );
1872                             if ( pPostItField != NULL )
1873                             {
1874                                 IDocumentMarkAccess* pMarksAccess = aIntPam.GetDoc()->getIDocumentMarkAccess();
1875                                 pMarksAccess->makeAnnotationMark( aIntPam, pPostItField->GetName() );
1876                             }
1877                         }
1878                     }
1879                 }
1880             }
1881         }
1882         else
1883             throw lang::IllegalArgumentException();
1884     }
1885     else
1886         throw lang::IllegalArgumentException();
1887 }
1888 
getAnchor(void)1889 uno::Reference< text::XTextRange >  SwXTextField::getAnchor(void) throw( uno::RuntimeException )
1890 {
1891     vos::OGuard aGuard( Application::GetSolarMutex() );
1892 
1893     uno::Reference< text::XTextRange > aRef;
1894 
1895     SwField* pField = (SwField*) GetField();
1896     if ( pField != NULL )
1897     {
1898         const SwTxtFld* pTxtFld = m_pFmtFld->GetTxtFld();
1899         if ( !pTxtFld )
1900             throw uno::RuntimeException();
1901 
1902         boost::shared_ptr< SwPaM > pPamForTxtFld;
1903         SwTxtFld::GetPamForTxtFld( *pTxtFld, pPamForTxtFld );
1904         if ( pPamForTxtFld.get() != NULL )
1905         {
1906             aRef = SwXTextRange::CreateXTextRange( *m_pDoc,
1907                                                    *(pPamForTxtFld->GetPoint()),
1908                                                    pPamForTxtFld->GetMark() );
1909         }
1910     }
1911     return aRef;
1912 
1913 }
1914 
1915 
dispose(void)1916 void SwXTextField::dispose(void) throw( uno::RuntimeException )
1917 {
1918     vos::OGuard aGuard( Application::GetSolarMutex() );
1919     SwField* pField = (SwField*) GetField();
1920     if ( pField != NULL )
1921     {
1922         UnoActionContext aContext( GetDoc() );
1923 
1924         ASSERT( m_pFmtFld->GetTxtFld(), "<SwXTextField::dispose()> - missing <SwTxtFld> --> crash" );
1925         SwTxtFld::DeleteTxtFld( *( m_pFmtFld->GetTxtFld() ) );
1926     }
1927 
1928     if ( m_pTextObject )
1929     {
1930         m_pTextObject->DisposeEditSource();
1931         m_pTextObject->release();
1932         m_pTextObject = 0;
1933     }
1934 }
1935 
addEventListener(const uno::Reference<lang::XEventListener> & aListener)1936 void SwXTextField::addEventListener(const uno::Reference< lang::XEventListener > & aListener) throw( uno::RuntimeException )
1937 {
1938 	if(!GetRegisteredIn())
1939 		throw uno::RuntimeException();
1940 	m_aLstnrCntnr.AddListener(aListener);
1941 }
1942 
removeEventListener(const uno::Reference<lang::XEventListener> & aListener)1943 void SwXTextField::removeEventListener(const uno::Reference< lang::XEventListener > & aListener) throw( uno::RuntimeException )
1944 {
1945 	if(!GetRegisteredIn() || !m_aLstnrCntnr.RemoveListener(aListener))
1946 		throw uno::RuntimeException();
1947 }
1948 
getPropertySetInfo(void)1949 uno::Reference< beans::XPropertySetInfo >  SwXTextField::getPropertySetInfo(void)
1950 		throw( uno::RuntimeException )
1951 {
1952 	vos::OGuard  aGuard(Application::GetSolarMutex());
1953 	//kein static
1954 	uno::Reference< beans::XPropertySetInfo >  aRef;
1955 	if(m_nServiceId != USHRT_MAX)
1956 	{
1957         const SfxItemPropertySet* pPropSet = aSwMapProvider.GetPropertySet(
1958 						lcl_GetPropertyMapOfService( m_nServiceId ));
1959         uno::Reference< beans::XPropertySetInfo >  xInfo = pPropSet->getPropertySetInfo();
1960 		// extend PropertySetInfo!
1961 		const uno::Sequence<beans::Property> aPropSeq = xInfo->getProperties();
1962 		aRef = new SfxExtItemPropertySetInfo(
1963             aSwMapProvider.GetPropertyMapEntries(PROPERTY_MAP_PARAGRAPH_EXTENSIONS),
1964 			aPropSeq );
1965 	}
1966 	else
1967 		throw uno::RuntimeException();
1968 	return aRef;
1969 }
1970 
setPropertyValue(const OUString & rPropertyName,const uno::Any & rValue)1971 void SwXTextField::setPropertyValue(const OUString& rPropertyName, const uno::Any& rValue)
1972 	throw( beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException,
1973 		lang::WrappedTargetException, uno::RuntimeException )
1974 {
1975 	vos::OGuard  aGuard(Application::GetSolarMutex());
1976 	SwField* pField = (SwField*)GetField();
1977     const SfxItemPropertySet* _pPropSet = aSwMapProvider.GetPropertySet(
1978 								lcl_GetPropertyMapOfService( m_nServiceId));
1979     const SfxItemPropertySimpleEntry*   pEntry = _pPropSet->getPropertyMap()->getByName(rPropertyName);
1980 
1981     if (!pEntry)
1982         throw beans::UnknownPropertyException(OUString ( RTL_CONSTASCII_USTRINGPARAM ( "Unknown property: " ) ) + rPropertyName, static_cast < cppu::OWeakObject * > ( this ) );
1983     if ( pEntry->nFlags & beans::PropertyAttribute::READONLY)
1984         throw beans::PropertyVetoException ( OUString ( RTL_CONSTASCII_USTRINGPARAM ( "Property is read-only: " ) ) + rPropertyName, static_cast < cppu::OWeakObject * > ( this ) );
1985 
1986     if ( pField )
1987     {
1988         // Sonderbehandlung Serienbrieffeld
1989         sal_uInt16 nWhich = pField->Which();
1990         if ( RES_DBFLD == nWhich
1991              && ( rPropertyName.equalsAsciiL( SW_PROP_NAME( UNO_NAME_DATA_BASE_NAME ) )
1992                   || rPropertyName.equalsAsciiL( SW_PROP_NAME( UNO_NAME_DATA_BASE_URL ) )
1993                   || rPropertyName.equalsAsciiL( SW_PROP_NAME( UNO_NAME_DATA_TABLE_NAME ) )
1994                   || rPropertyName.equalsAsciiL( SW_PROP_NAME( UNO_NAME_DATA_COLUMN_NAME ) ) ) )
1995         {
1996             // hier muss ein neuer Feldtyp angelegt werden und
1997             // das Feld an den neuen Typ umgehaengt werden
1998             DBG_WARNING( "not implemented" );
1999         }
2000         else
2001         {
2002             // -> #111840#
2003             SwDoc * pDoc = GetDoc();
2004 
2005             if (NULL != pDoc)
2006             {
2007                 const SwTxtFld* pTxtFld = m_pFmtFld->GetTxtFld();
2008                 if(!pTxtFld)
2009                     throw uno::RuntimeException();
2010                 SwPosition aPosition( pTxtFld->GetTxtNode() );
2011                 aPosition.nContent = *pTxtFld->GetStart();
2012                 pDoc->PutValueToField( aPosition, rValue, pEntry->nWID);
2013             }
2014             // <- #111840#
2015         }
2016         pField->PutValue( rValue, pEntry->nWID );
2017 
2018         //#i100374# notify SwPostIt about new field content
2019         if ( RES_POSTITFLD == nWhich && m_pFmtFld )
2020         {
2021             const_cast< SwFmtFld* >( m_pFmtFld )->Broadcast( SwFmtFldHint( 0, SWFMTFLD_CHANGED ) );
2022         }
2023 
2024         //#114571# changes of the expanded string have to be notified
2025         //#to the SwTxtFld
2026         if ( RES_DBFLD == nWhich && m_pFmtFld->GetTxtFld() )
2027         {
2028             m_pFmtFld->GetTxtFld()->ExpandTxtFld();
2029         }
2030 
2031         //#i100374# changing a document field should set the modify flag
2032         SwDoc* pDoc = GetDoc();
2033         if ( pDoc )
2034             pDoc->SetModified();
2035 
2036     }
2037     else if ( m_pProps )
2038     {
2039         String* pStr = 0;
2040         sal_Bool* pBool = 0;
2041         switch (pEntry->nWID)
2042         {
2043         case FIELD_PROP_PAR1:
2044             pStr = &m_pProps->sPar1;
2045             break;
2046         case FIELD_PROP_PAR2:
2047             pStr = &m_pProps->sPar2;
2048             break;
2049         case FIELD_PROP_PAR3:
2050             pStr = &m_pProps->sPar3;
2051             break;
2052         case FIELD_PROP_PAR4:
2053             pStr = &m_pProps->sPar4;
2054             break;
2055         case FIELD_PROP_FORMAT:
2056             rValue >>= m_pProps->nFormat;
2057             m_pProps->bFormatIsDefault = sal_False;
2058             break;
2059         case FIELD_PROP_SUBTYPE:
2060             m_pProps->nSubType = SWUnoHelper::GetEnumAsInt32( rValue );
2061             break;
2062         case FIELD_PROP_BYTE1:
2063             rValue >>= m_pProps->nByte1;
2064             break;
2065         case FIELD_PROP_BOOL1:
2066             pBool = &m_pProps->bBool1;
2067             break;
2068         case FIELD_PROP_BOOL2:
2069             pBool = &m_pProps->bBool2;
2070             break;
2071         case FIELD_PROP_BOOL3:
2072             pBool = &m_pProps->bBool3;
2073             break;
2074         case FIELD_PROP_BOOL4:
2075             pBool = &m_pProps->bBool4;
2076             break;
2077         case FIELD_PROP_DATE:
2078             {
2079             if ( rValue.getValueType() != ::getCppuType( static_cast< const util::Date* >( 0 ) ) )
2080                 throw lang::IllegalArgumentException();
2081 
2082             util::Date aTemp = *(const util::Date*) rValue.getValue();
2083             m_pProps->aDate = Date( aTemp.Day, aTemp.Month, aTemp.Year );
2084         }
2085             break;
2086         case FIELD_PROP_USHORT1:
2087             case FIELD_PROP_USHORT2:
2088             {
2089             sal_Int16 nVal = 0;
2090             rValue >>= nVal;
2091             if ( FIELD_PROP_USHORT1 == pEntry->nWID )
2092                 m_pProps->nUSHORT1 = nVal;
2093             else
2094                 m_pProps->nUSHORT2 = nVal;
2095         }
2096             break;
2097         case FIELD_PROP_SHORT1:
2098             rValue >>= m_pProps->nSHORT1;
2099             break;
2100         case FIELD_PROP_DOUBLE:
2101             if ( rValue.getValueType() != ::getCppuType( static_cast< const double* >( 0 ) ) )
2102                 throw lang::IllegalArgumentException();
2103             m_pProps->fDouble = *(double*) rValue.getValue();
2104             break;
2105 
2106         case FIELD_PROP_DATE_TIME:
2107             if ( !m_pProps->pDateTime )
2108                 m_pProps->pDateTime = new util::DateTime;
2109             rValue >>= ( *m_pProps->pDateTime );
2110             break;
2111         case FIELD_PROP_PROP_SEQ:
2112             rValue >>= m_pProps->aPropSeq;
2113             break;
2114         case FIELD_PROP_STRINGS:
2115             rValue >>= m_pProps->aStrings;
2116             break;
2117         }
2118         if ( pStr )
2119             ::GetString( rValue, *pStr );
2120         else if ( pBool )
2121         {
2122             if ( rValue.getValueType() == getCppuBooleanType() )
2123                 *pBool = *(sal_Bool*) rValue.getValue();
2124             else
2125                 throw lang::IllegalArgumentException();
2126         }
2127     }
2128     else
2129         throw uno::RuntimeException();
2130 }
2131 
getPropertyValue(const OUString & rPropertyName)2132 uno::Any SwXTextField::getPropertyValue(const OUString& rPropertyName)
2133 	throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException )
2134 {
2135 	vos::OGuard  aGuard(Application::GetSolarMutex());
2136 	uno::Any aRet;
2137 	const SwField* pField = GetField();
2138     const SfxItemPropertySet* _pPropSet = aSwMapProvider.GetPropertySet(
2139                                 lcl_GetPropertyMapOfService( m_nServiceId));
2140     const SfxItemPropertySimpleEntry*   pEntry = _pPropSet->getPropertyMap()->getByName(rPropertyName);
2141     if(!pEntry )
2142 	{
2143         const SfxItemPropertySet* _pParaPropSet = aSwMapProvider.GetPropertySet(PROPERTY_MAP_PARAGRAPH_EXTENSIONS);
2144         pEntry = _pParaPropSet->getPropertyMap()->getByName(rPropertyName);
2145 	}
2146     if (!pEntry)
2147         throw beans::UnknownPropertyException(OUString ( RTL_CONSTASCII_USTRINGPARAM ( "Unknown property: " ) ) + rPropertyName, static_cast < cppu::OWeakObject * > ( this ) );
2148 
2149     switch( pEntry->nWID )
2150 	{
2151 	case FN_UNO_TEXT_WRAP:
2152 		aRet <<= text::WrapTextMode_NONE;
2153 		break;
2154 	case FN_UNO_ANCHOR_TYPE:
2155 		aRet <<= text::TextContentAnchorType_AS_CHARACTER;
2156 		break;
2157 	case FN_UNO_ANCHOR_TYPES:
2158 		{
2159 			uno::Sequence<text::TextContentAnchorType> aTypes(1);
2160 			text::TextContentAnchorType* pArray = aTypes.getArray();
2161 			pArray[0] = text::TextContentAnchorType_AS_CHARACTER;
2162 			aRet.setValue(&aTypes, ::getCppuType(static_cast<uno::Sequence<text::TextContentAnchorType>*>(0)));
2163 		}
2164 		break;
2165 
2166 	default:
2167 		if( pField )
2168         {
2169             if (FIELD_PROP_IS_FIELD_USED      == pEntry->nWID ||
2170                 FIELD_PROP_IS_FIELD_DISPLAYED == pEntry->nWID)
2171             {
2172                 sal_Bool bIsFieldUsed       = sal_False;
2173                 sal_Bool bIsFieldDisplayed  = sal_False;
2174 
2175                 // in order to have the information about fields
2176                 // correctly evaluated the document needs a layout
2177                 // (has to be already formatted)
2178                 SwDoc *pDoc = GetDoc();
2179                 ViewShell *pViewShell = 0;
2180                 SwEditShell *pEditShell = pDoc ? pDoc->GetEditShell( &pViewShell ) : 0;
2181                 if (pEditShell)
2182                     pEditShell->CalcLayout();
2183                 else if (pViewShell) // a page preview has no SwEditShell it should only have a view shell
2184                     pViewShell->CalcLayout();
2185                 else
2186                     throw uno::RuntimeException();
2187 
2188                 // get text node for the text field
2189                 const SwFmtFld *pFldFmt = GetFldFmt();
2190                 const SwTxtFld* pTxtFld = pFldFmt ? pFldFmt->GetTxtFld() : 0;
2191                 if(!pTxtFld)
2192                     throw uno::RuntimeException();
2193                 const SwTxtNode& rTxtNode = pTxtFld->GetTxtNode();
2194 
2195                 // skip fields that are currently not in the document
2196                 // e.g. fields in undo or redo array
2197                 if (rTxtNode.GetNodes().IsDocNodes())
2198                 {
2199                     sal_Bool bFrame = 0 != rTxtNode.FindLayoutRect().Width(); // oder so
2200                     sal_Bool bHidden = rTxtNode.IsHidden();
2201                     if ( !bHidden )
2202                     {
2203                         xub_StrLen nHiddenStart;
2204                         xub_StrLen nHiddenEnd;
2205 
2206                         SwPosition aPosition( pTxtFld->GetTxtNode() );
2207                         aPosition.nContent = *pTxtFld->GetStart();
2208 
2209                         bHidden = SwScriptInfo::GetBoundsOfHiddenRange( pTxtFld->GetTxtNode(),
2210                                         *pTxtFld->GetStart(),
2211                                         nHiddenStart, nHiddenEnd );
2212                     }
2213 
2214                     // !bFrame && !bHidden: aller Wahrscheinlichkeit handelt es
2215                     // sich um ein Feld in einem unbenutzten Seitenstyle
2216                     //
2217                     // bHidden: Feld ist versteckt
2218                     // FME: Problem: Verstecktes Feld in unbenutzter Seitenvorlage =>
2219                     // bIsFieldUsed = true
2220                     // bIsFieldDisplayed = false
2221                     bIsFieldUsed       = bFrame || bHidden;
2222                     bIsFieldDisplayed  = bIsFieldUsed && !bHidden;
2223 				}
2224                 sal_Bool bRetVal = (FIELD_PROP_IS_FIELD_USED == pEntry->nWID) ?
2225 											bIsFieldUsed : bIsFieldDisplayed;
2226                 aRet.setValue( &bRetVal, ::getCppuBooleanType() );
2227 			}
2228             else
2229                 pField->QueryValue( aRet, pEntry->nWID );
2230         }
2231         else if( m_pProps )     // currently just a descriptor...
2232 		{
2233             switch(pEntry->nWID)
2234 			{
2235 			case FIELD_PROP_TEXT:
2236 				{
2237 					if (!m_pTextObject)
2238 					{
2239 						SwTextAPIEditSource* pObj = new SwTextAPIEditSource( m_pDoc );
2240 						m_pTextObject = new SwTextAPIObject( pObj );
2241 						m_pTextObject->acquire();
2242 					}
2243 
2244 					uno::Reference < text::XText > xText( m_pTextObject );
2245 					aRet <<= xText;
2246 					break;
2247 				}
2248 			case FIELD_PROP_PAR1:
2249 				aRet <<= OUString(m_pProps->sPar1);
2250 				break;
2251 			case FIELD_PROP_PAR2:
2252 				aRet <<= OUString(m_pProps->sPar2);
2253 				break;
2254 			case FIELD_PROP_PAR3:
2255 				aRet <<= OUString(m_pProps->sPar3);
2256 				break;
2257 			case FIELD_PROP_PAR4:
2258 				aRet <<= OUString(m_pProps->sPar4);
2259 				break;
2260 			case FIELD_PROP_FORMAT:
2261 				aRet <<= m_pProps->nFormat;
2262 				break;
2263 			case FIELD_PROP_SUBTYPE:
2264 				aRet <<= m_pProps->nSubType;
2265 				break;
2266 			case FIELD_PROP_BYTE1 :
2267 				aRet <<= m_pProps->nByte1;
2268 				break;
2269 			case FIELD_PROP_BOOL1 :
2270 				aRet.setValue(&m_pProps->bBool1, ::getCppuBooleanType());
2271 				break;
2272 			case FIELD_PROP_BOOL2 :
2273 				aRet.setValue(&m_pProps->bBool2, ::getCppuBooleanType());
2274 				break;
2275             case FIELD_PROP_BOOL3 :
2276                 aRet.setValue(&m_pProps->bBool3, ::getCppuBooleanType());
2277                 break;
2278             case FIELD_PROP_BOOL4 :
2279                 aRet.setValue(&m_pProps->bBool4, ::getCppuBooleanType());
2280                 break;
2281             case FIELD_PROP_DATE :
2282 				aRet.setValue(&m_pProps->aDate, ::getCppuType(static_cast<const util::Date*>(0)));
2283 				break;
2284 			case FIELD_PROP_USHORT1:
2285 				aRet <<= (sal_Int16)m_pProps->nUSHORT1;
2286 				break;
2287 			case FIELD_PROP_USHORT2:
2288 				aRet <<= (sal_Int16)m_pProps->nUSHORT2;
2289 				break;
2290 			case FIELD_PROP_SHORT1:
2291 				aRet <<= m_pProps->nSHORT1;
2292 				break;
2293 			case FIELD_PROP_DOUBLE:
2294 				aRet <<= m_pProps->fDouble;
2295 				break;
2296 			case FIELD_PROP_DATE_TIME :
2297 				if(m_pProps->pDateTime)
2298 					aRet <<= (*m_pProps->pDateTime);
2299 				break;
2300 			case FIELD_PROP_PROP_SEQ:
2301 				aRet <<= m_pProps->aPropSeq;
2302 				break;
2303 			case FIELD_PROP_STRINGS:
2304 				aRet <<= m_pProps->aStrings;
2305 				break;
2306             case FIELD_PROP_IS_FIELD_USED:
2307             case FIELD_PROP_IS_FIELD_DISPLAYED:
2308                 aRet.setValue( NULL, ::getCppuBooleanType() );
2309                 break;
2310             }
2311 		}
2312 		else
2313 			throw uno::RuntimeException();
2314 	}
2315 	return aRet;
2316 }
2317 
addPropertyChangeListener(const OUString &,const uno::Reference<beans::XPropertyChangeListener> &)2318 void SwXTextField::addPropertyChangeListener(const OUString& /*PropertyName*/, const uno::Reference< beans::XPropertyChangeListener > & /*aListener*/) throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException )
2319 {
2320 	DBG_WARNING("not implemented");
2321 }
2322 
removePropertyChangeListener(const OUString &,const uno::Reference<beans::XPropertyChangeListener> &)2323 void SwXTextField::removePropertyChangeListener(const OUString& /*PropertyName*/, const uno::Reference< beans::XPropertyChangeListener > & /*aListener*/) throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException )
2324 {
2325 	DBG_WARNING("not implemented");
2326 }
2327 
addVetoableChangeListener(const OUString &,const uno::Reference<beans::XVetoableChangeListener> &)2328 void SwXTextField::addVetoableChangeListener(const OUString& /*PropertyName*/, const uno::Reference< beans::XVetoableChangeListener > & /*aListener*/) throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException )
2329 {
2330 	DBG_WARNING("not implemented");
2331 }
2332 
removeVetoableChangeListener(const OUString &,const uno::Reference<beans::XVetoableChangeListener> &)2333 void SwXTextField::removeVetoableChangeListener(const OUString& /*PropertyName*/, const uno::Reference< beans::XVetoableChangeListener > & /*aListener*/) throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException )
2334 {
2335 	DBG_WARNING("not implemented");
2336 }
2337 
update()2338 void SwXTextField::update(  ) throw (uno::RuntimeException)
2339 {
2340     vos::OGuard  aGuard(Application::GetSolarMutex());
2341     const SwField* pFld = GetField();
2342     if(pFld)
2343     {
2344         switch(pFld->Which())
2345         {
2346             case RES_DATETIMEFLD:
2347             ((SwDateTimeField*)pFld)->SetDateTime( ::DateTime() );
2348             break;
2349 
2350             case RES_EXTUSERFLD:
2351             {
2352                 SwExtUserField* pExtUserFld = (SwExtUserField*)pFld;
2353                 pExtUserFld->SetExpansion( ((SwExtUserFieldType*)pFld->GetTyp())->Expand(
2354                                             pExtUserFld->GetSubType(),
2355                                             pExtUserFld->GetFormat() ) );
2356             }
2357             break;
2358 
2359             case RES_AUTHORFLD:
2360             {
2361                 SwAuthorField* pAuthorFld = (SwAuthorField*)pFld;
2362                 pAuthorFld->SetExpansion( ((SwAuthorFieldType*)pFld->GetTyp())->Expand(
2363                                             pAuthorFld->GetFormat() ) );
2364             }
2365             break;
2366 
2367             case RES_FILENAMEFLD:
2368             {
2369                 SwFileNameField* pFileNameFld = (SwFileNameField*)pFld;
2370                 pFileNameFld->SetExpansion( ((SwFileNameFieldType*)pFld->GetTyp())->Expand(
2371                                             pFileNameFld->GetFormat() ) );
2372             }
2373             break;
2374 
2375             case RES_DOCINFOFLD:
2376             {
2377                     SwDocInfoField* pDocInfFld = (SwDocInfoField*)pFld;
2378                     pDocInfFld->SetExpansion( ((SwDocInfoFieldType*)pFld->GetTyp())->Expand(
2379                                                 pDocInfFld->GetSubType(),
2380                                                 pDocInfFld->GetFormat(),
2381                                                 pDocInfFld->GetLanguage(),
2382                                                 pDocInfFld->GetName() ) );
2383             }
2384             break;
2385         }
2386         // Text formatting has to be triggered.
2387         const_cast< SwFmtFld* >( m_pFmtFld )->ModifyNotification( 0, 0 );
2388     }
2389     else
2390         m_bCallUpdate = sal_True;
2391 }
2392 
getImplementationName(void)2393 OUString SwXTextField::getImplementationName(void) throw( uno::RuntimeException )
2394 {
2395 	return C2U("SwXTextField");
2396 }
2397 
OldNameToNewName_Impl(const OUString & rOld)2398 static OUString OldNameToNewName_Impl( const OUString &rOld )
2399 {
2400 	static OUString aOldNamePart1( OUString::createFromAscii(".TextField.DocInfo.") );
2401 	static OUString aOldNamePart2( OUString::createFromAscii(".TextField.") );
2402 	static OUString aNewNamePart1( OUString::createFromAscii(".textfield.docinfo.") );
2403 	static OUString aNewNamePart2( OUString::createFromAscii(".textfield.") );
2404 	OUString sServiceNameCC( rOld );
2405 	sal_Int32 nIdx = sServiceNameCC.indexOf( aOldNamePart1 );
2406 	if (nIdx >= 0)
2407 		sServiceNameCC = sServiceNameCC.replaceAt( nIdx, aOldNamePart1.getLength(), aNewNamePart1 );
2408 	nIdx = sServiceNameCC.indexOf( aOldNamePart2 );
2409 	if (nIdx >= 0)
2410 		sServiceNameCC = sServiceNameCC.replaceAt( nIdx, aOldNamePart2.getLength(), aNewNamePart2 );
2411 	return sServiceNameCC;
2412 }
2413 
supportsService(const OUString & rServiceName)2414 sal_Bool SwXTextField::supportsService(const OUString& rServiceName) throw( uno::RuntimeException )
2415 {
2416 	OUString sServiceName = SwXServiceProvider::GetProviderName(m_nServiceId);
2417 
2418 	// case-corected version of service-name (see #i67811)
2419 	// (need to supply both because of compatibility to older versions)
2420 	OUString sServiceNameCC(  OldNameToNewName_Impl( sServiceName ) );
2421 
2422 	return sServiceName == rServiceName || sServiceNameCC == rServiceName ||
2423         rServiceName.equalsAsciiL(
2424 				RTL_CONSTASCII_STRINGPARAM("com.sun.star.text.TextContent"));
2425 }
2426 
getSupportedServiceNames(void)2427 uno::Sequence< OUString > SwXTextField::getSupportedServiceNames(void) throw( uno::RuntimeException )
2428 {
2429 	OUString sServiceName = SwXServiceProvider::GetProviderName(m_nServiceId);
2430 
2431 	// case-corected version of service-name (see #i67811)
2432 	// (need to supply both because of compatibility to older versions)
2433 	OUString sServiceNameCC(  OldNameToNewName_Impl( sServiceName ) );
2434 	sal_Int32 nLen = sServiceName == sServiceNameCC ? 2 : 3;
2435 
2436 	uno::Sequence< OUString > aRet( nLen );
2437 	OUString* pArray = aRet.getArray();
2438 	*pArray++ = sServiceName;
2439 	if (nLen == 3)
2440 		*pArray++ = sServiceNameCC;
2441 	*pArray++ = C2U("com.sun.star.text.TextContent");
2442 	return aRet;
2443 }
2444 
2445 
GetServiceId()2446 sal_uInt16 SwXTextField::GetServiceId()
2447 {
2448     return m_nServiceId;
2449 }
2450 
2451 
Invalidate()2452     void SwXTextField::Invalidate()
2453 {
2454 	if (GetRegisteredIn())
2455 	{
2456 		((SwModify*)GetRegisteredIn())->Remove(this);
2457 		m_aLstnrCntnr.Disposing();
2458 		m_pFmtFld = 0;
2459 		m_pDoc = 0;
2460 	}
2461 }
2462 
2463 
Modify(const SfxPoolItem * pOld,const SfxPoolItem * pNew)2464 void SwXTextField::Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew)
2465 {
2466 	switch( pOld ? pOld->Which() : 0 )
2467 	{
2468 	case RES_REMOVE_UNO_OBJECT:
2469 	case RES_OBJECTDYING:
2470 		if( (void*)GetRegisteredIn() == ((SwPtrMsgPoolItem *)pOld)->pObject )
2471 			Invalidate();
2472 		break;
2473 
2474 	case RES_FMT_CHG:
2475 		// wurden wir an das neue umgehaengt und wird das alte geloscht?
2476 		if( ((SwFmtChg*)pNew)->pChangedFmt == GetRegisteredIn() &&
2477 			((SwFmtChg*)pOld)->pChangedFmt->IsFmtInDTOR() )
2478 			Invalidate();
2479 		break;
2480 	case RES_FIELD_DELETED:
2481 		if( (void*)m_pFmtFld == ((SwPtrMsgPoolItem *)pOld)->pObject )
2482 			Invalidate();
2483 		break;
2484 	}
2485 }
2486 
GetField() const2487 const SwField*  SwXTextField::GetField() const
2488 {
2489     if ( GetRegisteredIn() && m_pFmtFld )
2490     {
2491         return m_pFmtFld->GetField();
2492     }
2493     return 0;
2494 }
2495 
2496 /******************************************************************
2497  * SwXTextFieldMasters
2498  ******************************************************************/
getImplementationName(void)2499 OUString SwXTextFieldMasters::getImplementationName(void) throw( uno::RuntimeException )
2500 {
2501 	return C2U("SwXTextFieldMasters");
2502 }
2503 
supportsService(const OUString & rServiceName)2504 sal_Bool SwXTextFieldMasters::supportsService(const OUString& rServiceName) throw( uno::RuntimeException )
2505 {
2506 	return rServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(
2507 							"com.sun.star.text.TextFieldMasters" ));
2508 }
2509 
getSupportedServiceNames(void)2510 uno::Sequence< OUString > SwXTextFieldMasters::getSupportedServiceNames(void) throw( uno::RuntimeException )
2511 {
2512 	uno::Sequence< OUString > aRet(1);
2513 	OUString* pArray = aRet.getArray();
2514 	pArray[0] = C2U("com.sun.star.text.TextFieldMasters");
2515 	return aRet;
2516 }
2517 
SwXTextFieldMasters(SwDoc * _pDoc)2518 SwXTextFieldMasters::SwXTextFieldMasters(SwDoc* _pDoc) :
2519 	SwUnoCollection(_pDoc)
2520 {
2521 }
2522 
~SwXTextFieldMasters()2523 SwXTextFieldMasters::~SwXTextFieldMasters()
2524 {
2525 
2526 }
2527 /*-----------------------------------------------------------------------
2528 	Iteration ueber nicht-Standard Feldtypen
2529 	USER/SETEXP/DDE/DATABASE
2530 	Der Name ist demnach:
2531     "com.sun.star.text.fieldmaster.User" + <Feltypname>
2532     "com.sun.star.text.fieldmaster.DDE" + <Feltypname>
2533     "com.sun.star.text.fieldmaster.SetExpression" + <Feltypname>
2534     "com.sun.star.text.fieldmaster.DataBase" + <Feltypname>
2535 
2536 	Falls wir grosszuegig werden wollen, dann koennte man com.sun.star.text
2537 	auch optional weglassen
2538   -----------------------------------------------------------------------*/
2539 
lcl_GetIdByName(String & rName,String & rTypeName)2540 sal_uInt16 lcl_GetIdByName( String& rName, String& rTypeName )
2541 {
2542     if( rName.EqualsAscii( COM_TEXT_FLDMASTER, 0, RTL_CONSTASCII_LENGTH(COM_TEXT_FLDMASTER ))
2543         ||  rName.EqualsAscii( COM_TEXT_FLDMASTER_CC, 0, RTL_CONSTASCII_LENGTH(COM_TEXT_FLDMASTER_CC )))
2544 		rName.Erase(0, 30);
2545 
2546 	sal_uInt16 nResId = USHRT_MAX;
2547 	xub_StrLen nFound = 0;
2548 	rTypeName = rName.GetToken( 0, '.', nFound );
2549 	if(rTypeName.EqualsAscii("User"))
2550 		nResId = RES_USERFLD;
2551 	else if(rTypeName.EqualsAscii("DDE"))
2552 		nResId = RES_DDEFLD;
2553 	else if(rTypeName.EqualsAscii("SetExpression"))
2554 	{
2555 		nResId = RES_SETEXPFLD;
2556 
2557         String sFldTypName( rName.GetToken( 1, '.' ));
2558         String sUIName( SwStyleNameMapper::GetSpecialExtraUIName( sFldTypName ) );
2559 
2560 		if( sUIName != sFldTypName )
2561 			rName.SetToken( 1, '.', sUIName );
2562 	}
2563 	else if(rTypeName.EqualsAscii("DataBase"))
2564 	{
2565 		rName.Erase( 0, RTL_CONSTASCII_LENGTH( "DataBase." ));
2566 		sal_uInt16 nDotCount = rName.GetTokenCount('.');
2567 		if( 2 <= nDotCount )
2568 		{
2569 			// #i51815#
2570 			//rName.SearchAndReplace('.', DB_DELIM);
2571 			//rName.SetChar( rName.SearchBackward( '.' ), DB_DELIM );
2572 
2573 			rName.InsertAscii( "DataBase.", 0 );
2574 			nResId = RES_DBFLD;
2575 		}
2576 	}
2577 	else if( rTypeName.EqualsAscii("Bibliography"))
2578 		nResId = RES_AUTHORITY;
2579 	return nResId;
2580 }
2581 
2582 //-----------------------------------------------------------------------------
getByName(const OUString & rName)2583 uno::Any SwXTextFieldMasters::getByName(const OUString& rName)
2584 	throw( container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException )
2585 {
2586 	vos::OGuard  aGuard(Application::GetSolarMutex());
2587 	if(!GetDoc())
2588 		throw uno::RuntimeException();
2589 
2590 	String sName(rName), sTypeName;
2591 	sal_uInt16 nResId = lcl_GetIdByName( sName, sTypeName );
2592 	if( USHRT_MAX == nResId )
2593 		throw container::NoSuchElementException();
2594 
2595 	sName.Erase(0, sTypeName.Len()+1);
2596 	SwFieldType* pType = GetDoc()->GetFldType(nResId, sName, sal_True);
2597 	if(!pType)
2598 		throw container::NoSuchElementException();
2599     SwXFieldMaster* pMaster = SwIterator<SwXFieldMaster,SwFieldType>::FirstElement( *pType );
2600 	if(!pMaster)
2601 		pMaster = new SwXFieldMaster(*pType, GetDoc());
2602 	uno::Reference< beans::XPropertySet >  aRef = pMaster;
2603 	uno::Any aRet(&aRef, ::getCppuType( static_cast<const uno::Reference<beans::XPropertySet>* >(0)));
2604 	return aRet;
2605 }
2606 
getInstanceName(const SwFieldType & rFldType,String & rName)2607 sal_Bool SwXTextFieldMasters::getInstanceName(
2608 	const SwFieldType& rFldType, String& rName)
2609 {
2610 	sal_Bool bRet = sal_True;
2611 	switch( rFldType.Which() )
2612 	{
2613 	case RES_USERFLD:
2614         rName.AppendAscii( RTL_CONSTASCII_STRINGPARAM( COM_TEXT_FLDMASTER_CC ));
2615 		rName.AppendAscii( RTL_CONSTASCII_STRINGPARAM( "User."));
2616 		rName += rFldType.GetName();
2617 		break;
2618 	case RES_DDEFLD:
2619         rName.AppendAscii( RTL_CONSTASCII_STRINGPARAM( COM_TEXT_FLDMASTER_CC ));
2620 		rName.AppendAscii( RTL_CONSTASCII_STRINGPARAM( "DDE."));
2621 		rName += rFldType.GetName();
2622 		break;
2623 
2624 	case RES_SETEXPFLD:
2625         rName.AppendAscii( RTL_CONSTASCII_STRINGPARAM( COM_TEXT_FLDMASTER_CC ));
2626 		rName.AppendAscii( RTL_CONSTASCII_STRINGPARAM( "SetExpression."));
2627         rName += String( SwStyleNameMapper::GetSpecialExtraProgName( rFldType.GetName() ) );
2628 		break;
2629 
2630 	case RES_DBFLD:
2631 		{
2632             rName.AppendAscii( RTL_CONSTASCII_STRINGPARAM( COM_TEXT_FLDMASTER_CC ));
2633 			rName.AppendAscii( RTL_CONSTASCII_STRINGPARAM( "DataBase."));
2634 			String sDBName(rFldType.GetName());
2635 			sDBName.SearchAndReplaceAll(DB_DELIM, '.');
2636 			rName += sDBName;
2637 		}
2638 		break;
2639 
2640 	case RES_AUTHORITY:
2641         rName.AppendAscii( RTL_CONSTASCII_STRINGPARAM( COM_TEXT_FLDMASTER_CC ));
2642 		rName.AppendAscii( RTL_CONSTASCII_STRINGPARAM( "Bibliography"));
2643 		break;
2644 
2645 	default:
2646 		bRet = sal_False;
2647 	}
2648 
2649 	return bRet;
2650 }
2651 
2652 
getElementNames(void)2653 uno::Sequence< OUString > SwXTextFieldMasters::getElementNames(void)
2654 	throw( uno::RuntimeException )
2655 {
2656 	vos::OGuard  aGuard(Application::GetSolarMutex());
2657 	if(!GetDoc())
2658 		throw uno::RuntimeException();
2659 
2660 	const SwFldTypes* pFldTypes = GetDoc()->GetFldTypes();
2661 	sal_uInt16 nCount = pFldTypes->Count();
2662 
2663 	SvStrings aFldNames;
2664 	String* pString = new String();
2665 	sal_uInt16 i;
2666 
2667 	for( i = 0; i < nCount; i++)
2668 	{
2669 		SwFieldType& rFldType = *((*pFldTypes)[i]);
2670 
2671 		if (SwXTextFieldMasters::getInstanceName(rFldType, *pString))
2672 		{
2673 			aFldNames.Insert(pString, aFldNames.Count());
2674 			pString = new String();
2675 		}
2676 	}
2677 	delete pString;
2678 
2679 	uno::Sequence< OUString > aSeq(aFldNames.Count());
2680 	OUString* pArray = aSeq.getArray();
2681 	for(i = 0; i < aFldNames.Count();i++)
2682 	{
2683 		pArray[i] = *aFldNames.GetObject(i);
2684 	}
2685 	aFldNames.DeleteAndDestroy(0, aFldNames.Count());
2686 
2687 	return aSeq;
2688 
2689 }
2690 
hasByName(const OUString & rName)2691 sal_Bool SwXTextFieldMasters::hasByName(const OUString& rName) throw( uno::RuntimeException )
2692 {
2693 	vos::OGuard  aGuard(Application::GetSolarMutex());
2694 	if(!GetDoc())
2695 		throw uno::RuntimeException();
2696 
2697 	String sName(rName), sTypeName;
2698 	sal_uInt16 nResId = lcl_GetIdByName( sName, sTypeName );
2699     sal_Bool bRet = sal_False;
2700     if( USHRT_MAX != nResId )
2701     {
2702         sName.Erase(0, sTypeName.Len()+1);
2703         bRet = USHRT_MAX != nResId && 0 != GetDoc()->GetFldType(nResId, sName, sal_True);
2704     }
2705 	return bRet;
2706 }
2707 
getElementType(void)2708 uno::Type  SwXTextFieldMasters::getElementType(void) throw( uno::RuntimeException )
2709 {
2710 	return ::getCppuType(static_cast<const uno::Reference<beans::XPropertySet>*>(0));
2711 
2712 }
2713 
hasElements(void)2714 sal_Bool SwXTextFieldMasters::hasElements(void) throw( uno::RuntimeException )
2715 {
2716 	vos::OGuard  aGuard(Application::GetSolarMutex());
2717 	if(!IsValid())
2718 		throw uno::RuntimeException();
2719 	return sal_True;
2720 }
2721 
2722 /******************************************************************
2723  *
2724  ******************************************************************/
2725 
getImplementationName(void)2726 OUString SwXTextFieldTypes::getImplementationName(void) throw( uno::RuntimeException )
2727 {
2728 	return C2U("SwXTextFieldTypes");
2729 }
2730 
supportsService(const OUString & rServiceName)2731 sal_Bool SwXTextFieldTypes::supportsService(const OUString& rServiceName) throw( uno::RuntimeException )
2732 {
2733 	return rServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(
2734 							"com.sun.star.text.TextFields" ));
2735 }
2736 
getSupportedServiceNames(void)2737 uno::Sequence< OUString > SwXTextFieldTypes::getSupportedServiceNames(void) throw( uno::RuntimeException )
2738 {
2739 	uno::Sequence< OUString > aRet(1);
2740 	OUString* pArray = aRet.getArray();
2741 	pArray[0] = C2U("com.sun.star.text.TextFields");
2742 	return aRet;
2743 }
2744 
SwXTextFieldTypes(SwDoc * _pDoc)2745 SwXTextFieldTypes::SwXTextFieldTypes(SwDoc* _pDoc) :
2746     SwUnoCollection (_pDoc),
2747     aRefreshCont    ( static_cast< XEnumerationAccess * >(this) )
2748 {
2749 }
2750 
~SwXTextFieldTypes()2751 SwXTextFieldTypes::~SwXTextFieldTypes()
2752 {
2753 }
2754 
Invalidate()2755 void SwXTextFieldTypes::Invalidate()
2756 {
2757     SwUnoCollection::Invalidate();
2758 	aRefreshCont.Disposing();
2759 }
2760 
createEnumeration(void)2761 uno::Reference< container::XEnumeration >  SwXTextFieldTypes::createEnumeration(void)
2762 	throw( uno::RuntimeException )
2763 {
2764 	vos::OGuard  aGuard(Application::GetSolarMutex());
2765 	if(!IsValid())
2766 		throw uno::RuntimeException();
2767 	return new SwXFieldEnumeration(GetDoc());
2768 }
2769 
2770 
getElementType(void)2771 uno::Type  SwXTextFieldTypes::getElementType(void) throw( uno::RuntimeException )
2772 {
2773 	return ::getCppuType(static_cast<const uno::Reference<text::XDependentTextField>*>(0));
2774 }
2775 
hasElements(void)2776 sal_Bool SwXTextFieldTypes::hasElements(void) throw( uno::RuntimeException )
2777 {
2778 	vos::OGuard  aGuard(Application::GetSolarMutex());
2779 	if(!IsValid())
2780 		throw uno::RuntimeException();
2781 	//es gibt sie immer
2782 	return sal_True;
2783 }
2784 
refresh(void)2785 void SwXTextFieldTypes::refresh(void)  throw( uno::RuntimeException )
2786 {
2787 	vos::OGuard  aGuard(Application::GetSolarMutex());
2788 	if(!IsValid())
2789 		throw uno::RuntimeException();
2790 	UnoActionContext aContext(GetDoc());
2791 	SwDocStat aDocStat;
2792 	GetDoc()->UpdateDocStat(aDocStat);
2793 	GetDoc()->UpdateFlds(0, sal_False);
2794 
2795     // call refresh listeners
2796     aRefreshCont.Refreshed();
2797 }
2798 
addRefreshListener(const uno::Reference<util::XRefreshListener> & l)2799 void SwXTextFieldTypes::addRefreshListener(const uno::Reference< util::XRefreshListener > & l)
2800 	throw( uno::RuntimeException )
2801 {
2802 	::vos::OGuard aGuard(Application::GetSolarMutex());
2803 	if ( !IsValid() )
2804 		throw uno::RuntimeException();
2805 	aRefreshCont.AddListener ( reinterpret_cast < const uno::Reference < lang::XEventListener > &> ( l ));
2806 }
2807 
removeRefreshListener(const uno::Reference<util::XRefreshListener> & l)2808 void SwXTextFieldTypes::removeRefreshListener(const uno::Reference< util::XRefreshListener > & l)
2809 	 throw( uno::RuntimeException )
2810 {
2811 	::vos::OGuard aGuard(Application::GetSolarMutex());
2812 	if ( !IsValid() || !aRefreshCont.RemoveListener ( reinterpret_cast < const uno::Reference < lang::XEventListener > &> ( l ) ) )
2813 		throw uno::RuntimeException();
2814 }
2815 /******************************************************************
2816  * SwXFieldEnumeration
2817  ******************************************************************/
2818 
getImplementationName(void)2819 OUString SwXFieldEnumeration::getImplementationName(void) throw( uno::RuntimeException )
2820 {
2821 	return C2U("SwXFieldEnumeration");
2822 }
2823 
supportsService(const OUString & rServiceName)2824 sal_Bool SwXFieldEnumeration::supportsService(const OUString& rServiceName) throw( uno::RuntimeException )
2825 {
2826 	return rServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(
2827 							"com.sun.star.text.FieldEnumeration" ));
2828 }
2829 
getSupportedServiceNames(void)2830 uno::Sequence< OUString > SwXFieldEnumeration::getSupportedServiceNames(void) throw( uno::RuntimeException )
2831 {
2832 	uno::Sequence< OUString > aRet(1);
2833 	OUString* pArray = aRet.getArray();
2834 	pArray[0] = C2U("com.sun.star.text.FieldEnumeration");
2835 	return aRet;
2836 }
2837 
SwXFieldEnumeration(SwDoc * pDc)2838 SwXFieldEnumeration::SwXFieldEnumeration(SwDoc* pDc) :
2839     nNextIndex(0),
2840 	pDoc(pDc)
2841 {
2842 	pDoc->GetPageDescFromPool(RES_POOLPAGE_STANDARD)->Add(this);
2843 
2844     // build sequence
2845     sal_Int32 nSize = 32;
2846     aItems.realloc( nSize );
2847     uno::Reference< text::XTextField > *pItems = aItems.getArray();
2848     sal_Int32 nFillPos = 0;
2849     //
2850     const SwFldTypes* pFldTypes = pDoc->GetFldTypes();
2851     sal_uInt16 nCount = pFldTypes->Count();
2852     for(sal_uInt16 nType = 0;  nType < nCount;  ++nType)
2853     {
2854         const SwFieldType *pCurType = pFldTypes->GetObject(nType);
2855         SwIterator<SwFmtFld,SwFieldType> aIter( *pCurType );
2856         const SwFmtFld* pCurFldFmt = aIter.First();
2857         while (pCurFldFmt)
2858         {
2859             const SwTxtFld *pTxtFld = pCurFldFmt->GetTxtFld();
2860             // skip fields that are currently not in the document
2861             // e.g. fields in undo or redo array
2862             sal_Bool bSkip = !pTxtFld ||
2863                          !pTxtFld->GetpTxtNode()->GetNodes().IsDocNodes();
2864             if (!bSkip)
2865                 pItems[ nFillPos++ ] = new SwXTextField(*pCurFldFmt, pDoc);
2866             pCurFldFmt = aIter.Next();
2867 
2868             // enlarge sequence if necessary
2869             if (aItems.getLength() == nFillPos)
2870             {
2871                 aItems.realloc( 2 * aItems.getLength() );
2872                 pItems = aItems.getArray();
2873             }
2874         }
2875     }
2876     // now handle meta-fields, which are not SwFields
2877     const ::std::vector< uno::Reference<text::XTextField> > MetaFields(
2878            pDc->GetMetaFieldManager().getMetaFields() );
2879     for (size_t i = 0; i < MetaFields.size(); ++i)
2880     {
2881         pItems[ nFillPos ] = MetaFields[i];
2882         nFillPos++;
2883 
2884         //FIXME UGLY
2885         // enlarge sequence if necessary
2886         if (aItems.getLength() == nFillPos)
2887         {
2888             aItems.realloc( 2 * aItems.getLength() );
2889             pItems = aItems.getArray();
2890         }
2891     }
2892     // resize sequence to actual used size
2893     aItems.realloc( nFillPos );
2894 }
2895 
~SwXFieldEnumeration()2896 SwXFieldEnumeration::~SwXFieldEnumeration()
2897 {
2898 
2899 }
2900 
hasMoreElements(void)2901 sal_Bool SwXFieldEnumeration::hasMoreElements(void)
2902     throw( uno::RuntimeException )
2903 {
2904 	vos::OGuard  aGuard(Application::GetSolarMutex());
2905     return nNextIndex < aItems.getLength();
2906 }
2907 
nextElement(void)2908 uno::Any SwXFieldEnumeration::nextElement(void)
2909 	throw( container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException )
2910 {
2911 	vos::OGuard  aGuard(Application::GetSolarMutex());
2912 
2913     if (!(nNextIndex < aItems.getLength()))
2914         throw container::NoSuchElementException();
2915 
2916 #if OSL_DEBUG_LEVEL > 1
2917     uno::Reference< text::XTextField > *pItems = aItems.getArray();
2918     (void)pItems;
2919 #endif
2920     uno::Reference< text::XTextField >  &rxFld = aItems.getArray()[ nNextIndex++ ];
2921     uno::Any aRet(&rxFld, ::getCppuType(static_cast<const uno::Reference<text::XTextField>*>(0)));
2922     rxFld = 0;  // free memory for item that is not longer used
2923     return aRet;
2924 }
2925 
Modify(const SfxPoolItem * pOld,const SfxPoolItem * pNew)2926 void SwXFieldEnumeration::Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew)
2927 {
2928 	ClientModify(this, pOld, pNew);
2929 	if(!GetRegisteredIn())
2930 		pDoc = 0;
2931 }
2932 
2933 
GetString(const uno::Any & rAny,String & rStr)2934 String& GetString( const uno::Any& rAny, String& rStr )
2935 {
2936 	OUString aStr;
2937 	rAny >>= aStr;
2938 	rStr = String( aStr );
2939 	return rStr;
2940 }
2941