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