Bug Summary

File:home/maarten/src/libreoffice/core/sw/source/core/unocore/unofield.cxx
Warning:line 1309, column 9
Called C++ object pointer is null

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-unknown-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name unofield.cxx -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -mframe-pointer=all -fmath-errno -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -fno-split-dwarf-inlining -debugger-tuning=gdb -resource-dir /usr/lib64/clang/11.0.0 -isystem /usr/include/libxml2 -D BOOST_ERROR_CODE_HEADER_ONLY -D BOOST_SYSTEM_NO_DEPRECATED -D CPPU_ENV=gcc3 -D LINUX -D OSL_DEBUG_LEVEL=1 -D SAL_LOG_INFO -D SAL_LOG_WARN -D UNIX -D UNX -D X86_64 -D _PTHREADS -D _REENTRANT -D SW_DLLIMPLEMENTATION -D SWUI_DLL_NAME="libswuilo.so" -D SYSTEM_LIBXML -D EXCEPTIONS_ON -D LIBO_INTERNAL_ONLY -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/icu/source -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/icu/source/i18n -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/icu/source/common -I /home/maarten/src/libreoffice/core/external/boost/include -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/boost -I /home/maarten/src/libreoffice/core/sw/source/core/inc -I /home/maarten/src/libreoffice/core/sw/source/filter/inc -I /home/maarten/src/libreoffice/core/sw/source/uibase/inc -I /home/maarten/src/libreoffice/core/sw/inc -I /home/maarten/src/libreoffice/core/workdir/SdiTarget/sw/sdi -I /home/maarten/src/libreoffice/core/include -I /usr/lib/jvm/java-11-openjdk-11.0.9.10-0.0.ea.fc33.x86_64/include -I /usr/lib/jvm/java-11-openjdk-11.0.9.10-0.0.ea.fc33.x86_64/include/linux -I /home/maarten/src/libreoffice/core/config_host -I /home/maarten/src/libreoffice/core/workdir/CustomTarget/officecfg/registry -I /home/maarten/src/libreoffice/core/workdir/CustomTarget/sw/generated -I /home/maarten/src/libreoffice/core/workdir/UnoApiHeadersTarget/udkapi/normal -I /home/maarten/src/libreoffice/core/workdir/UnoApiHeadersTarget/offapi/normal -I /home/maarten/src/libreoffice/core/workdir/UnoApiHeadersTarget/oovbaapi/normal -internal-isystem /usr/bin/../lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10 -internal-isystem /usr/bin/../lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10/x86_64-redhat-linux -internal-isystem /usr/bin/../lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10/backward -internal-isystem /usr/local/include -internal-isystem /usr/lib64/clang/11.0.0/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -O0 -Wno-missing-braces -std=c++17 -fdeprecated-macro -fdebug-compilation-dir /home/maarten/src/libreoffice/core -ferror-limit 19 -fvisibility hidden -fvisibility-inlines-hidden -stack-protector 2 -fgnuc-version=4.2.1 -fcxx-exceptions -fexceptions -debug-info-kind=constructor -analyzer-output=html -faddrsig -o /home/maarten/tmp/wis/scan-build-libreoffice/output/report/2020-10-07-141433-9725-1 -x c++ /home/maarten/src/libreoffice/core/sw/source/core/unocore/unofield.cxx

/home/maarten/src/libreoffice/core/sw/source/core/unocore/unofield.cxx

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

/home/maarten/src/libreoffice/core/include/com/sun/star/uno/Reference.h

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#ifndef INCLUDED_COM_SUN_STAR_UNO_REFERENCE_H
20#define INCLUDED_COM_SUN_STAR_UNO_REFERENCE_H
21
22#include "sal/config.h"
23
24#include <cassert>
25#include <cstddef>
26
27#if defined LIBO_INTERNAL_ONLY1
28#include <type_traits>
29#endif
30
31#include "rtl/alloc.h"
32
33namespace com
34{
35namespace sun
36{
37namespace star
38{
39namespace uno
40{
41
42class RuntimeException;
43class XInterface;
44class Type;
45class Any;
46
47/** Enum defining UNO_REF_NO_ACQUIRE for setting reference without acquiring a given interface.
48 Deprecated, please use SAL_NO_ACQUIRE.
49 @deprecated
50*/
51enum UnoReference_NoAcquire
52{
53 /** This enum value can be used for creating a reference granting a given interface,
54 i.e. transferring ownership to it.
55 */
56 UNO_REF_NO_ACQUIRE
57};
58
59/** This base class serves as a base class for all template reference classes and
60 has been introduced due to compiler problems with templated operators ==, =!.
61*/
62class BaseReference
63{
64protected:
65 /** the interface pointer
66 */
67 XInterface * _pInterface;
68
69 /** Queries given interface for type rType.
70
71 @param pInterface interface pointer
72 @param rType interface type
73 @return interface of demanded type (may be null)
74 */
75 inline static XInterface * SAL_CALL iquery( XInterface * pInterface, const Type & rType );
76 /** Queries given interface for type rType.
77 Throws a RuntimeException if the demanded interface cannot be queried.
78
79 @param pInterface interface pointer
80 @param rType interface type
81 @return interface of demanded type
82 */
83 inline static XInterface * SAL_CALL iquery_throw( XInterface * pInterface, const Type & rType );
84
85public:
86 /** Gets interface pointer. This call does not acquire the interface.
87
88 @return UNacquired interface pointer
89 */
90 XInterface * SAL_CALL get() const
91 { return _pInterface; }
92
93 /** Checks if reference is null.
94
95 @return true if reference acquires an interface, i.e. true if it is not null
96 */
97 bool SAL_CALL is() const
98 { return (NULL__null != _pInterface); }
5
Assuming NULL is not equal to field '_pInterface'
6
Returning the value 1, which participates in a condition later
29
Returning the value 1, which participates in a condition later
99
100#if defined LIBO_INTERNAL_ONLY1
101 /** Checks if reference is null.
102
103 @return true if reference acquires an interface, i.e. true if it is not null
104 */
105 explicit operator bool() const
106 { return is(); }
107#endif
108
109 /** Equality operator: compares two interfaces
110 Checks if both references are null or refer to the same object.
111
112 @param pInterface another interface
113 @return true if both references are null or refer to the same object, false otherwise
114 */
115 inline bool SAL_CALL operator == ( XInterface * pInterface ) const;
116 /** Inequality operator: compares two interfaces
117 Checks if both references are null or refer to the same object.
118
119 @param pInterface another interface
120 @return false if both references are null or refer to the same object, true otherwise
121 */
122 inline bool SAL_CALL operator != ( XInterface * pInterface ) const;
123
124 /** Equality operator: compares two interfaces
125 Checks if both references are null or refer to the same object.
126
127 @param rRef another reference
128 @return true if both references are null or refer to the same object, false otherwise
129 */
130 inline bool SAL_CALL operator == ( const BaseReference & rRef ) const;
131 /** Inequality operator: compares two interfaces
132 Checks if both references are null or refer to the same object.
133
134 @param rRef another reference
135 @return false if both references are null or refer to the same object, true otherwise
136 */
137 inline bool SAL_CALL operator != ( const BaseReference & rRef ) const;
138
139 /** Needed by some STL containers.
140
141 @param rRef another reference
142 @return true, if this reference is less than rRef
143 */
144 inline bool SAL_CALL operator < ( const BaseReference & rRef ) const;
145};
146
147/** Enum defining UNO_QUERY for implicit interface query.
148*/
149enum UnoReference_Query
150{
151 /** This enum value can be used for implicit interface query.
152 */
153 UNO_QUERY
154};
155/** Enum defining UNO_QUERY_THROW for implicit interface query.
156 If the demanded interface is unavailable, then a RuntimeException is thrown.
157*/
158enum UnoReference_QueryThrow
159{
160 /** This enum value can be used for implicit interface query.
161 */
162 UNO_QUERY_THROW
163};
164/** Enum defining UNO_SET_THROW for throwing if attempts are made to assign a null
165 interface
166
167 @since UDK 3.2.8
168*/
169enum UnoReference_SetThrow
170{
171 UNO_SET_THROW
172};
173
174/** Template reference class for interface type derived from BaseReference.
175 A special constructor given the UNO_QUERY identifier queries interfaces
176 for reference type.
177*/
178template< class interface_type >
179class SAL_DLLPUBLIC_RTTI__attribute__ ((type_visibility("default"))) Reference : public BaseReference
180{
181 /** Queries given interface for type interface_type.
182
183 @param pInterface interface pointer
184 @return interface of demanded type (may be null)
185 */
186 inline static XInterface * SAL_CALL iquery( XInterface * pInterface );
187 /** Queries given interface for type interface_type.
188 Throws a RuntimeException if the demanded interface cannot be queried.
189
190 @param pInterface interface pointer
191 @return interface of demanded type
192 */
193 inline static XInterface * SAL_CALL iquery_throw( XInterface * pInterface );
194 /** Returns the given interface if it is not <NULL/>, throws a RuntimeException otherwise.
195
196 @param pInterface interface pointer
197 @return pInterface
198 */
199 inline static interface_type * SAL_CALL iset_throw( interface_type * pInterface );
200
201 /** Cast from an "interface pointer" (e.g., BaseReference::_pInterface) to a
202 pointer to this interface_type.
203
204 To work around ambiguities in the case of multiple-inheritance interface
205 types (which inherit XInterface more than once), use reinterpret_cast
206 (resp. a sequence of two static_casts, to avoid warnings about
207 reinterpret_cast used between related classes) to switch from a pointer
208 to XInterface to a pointer to this derived interface_type. In
209 principle, this is not guaranteed to work. In practice, it seems to
210 work on all supported platforms.
211 */
212 static interface_type * castFromXInterface(XInterface * p) {
213 return static_cast< interface_type * >(static_cast< void * >(p));
214 }
215
216 /** Cast from a pointer to this interface_type to an "interface pointer"
217 (e.g., BaseReference::_pInterface).
218
219 To work around ambiguities in the case of multiple-inheritance interface
220 types (which inherit XInterface more than once), use reinterpret_cast
221 (resp. a sequence of two static_casts, to avoid warnings about
222 reinterpret_cast used between related classes) to switch from a pointer
223 to this derived interface_type to a pointer to XInterface. In
224 principle, this is not guaranteed to work. In practice, it seems to
225 work on all supported platforms.
226 */
227 static XInterface * castToXInterface(interface_type * p) {
228 return static_cast< XInterface * >(static_cast< void * >(p));
229 }
230
231public:
232 /// @cond INTERNAL
233 // these are here to force memory de/allocation to sal lib.
234 static void * SAL_CALL operator new ( ::size_t nSize )
235 { return ::rtl_allocateMemory( nSize ); }
236 static void SAL_CALL operator delete ( void * pMem )
237 { ::rtl_freeMemory( pMem ); }
238 static void * SAL_CALL operator new ( ::size_t, void * pMem )
239 { return pMem; }
240 static void SAL_CALL operator delete ( void *, void * )
241 {}
242 /// @endcond
243
244 /** Destructor: Releases interface if set.
245 */
246 inline ~Reference() COVERITY_NOEXCEPT_FALSE;
247
248 /** Default Constructor: Sets null reference.
249 */
250 inline Reference();
251
252 /** Copy constructor: Copies interface reference.
253
254 @param rRef another reference
255 */
256 inline Reference( const Reference< interface_type > & rRef );
257
258#if defined LIBO_INTERNAL_ONLY1
259 /** Move constructor
260
261 @param rRef another reference
262 */
263 inline Reference( Reference< interface_type > && rRef ) noexcept;
264
265 /** Up-casting conversion constructor: Copies interface reference.
266
267 Does not work for up-casts to ambiguous bases. For the special case of
268 up-casting to Reference< XInterface >, see the corresponding conversion
269 operator.
270
271 @param rRef another reference
272 */
273 template< class derived_type >
274 inline Reference(
275 const Reference< derived_type > & rRef,
276 std::enable_if_t<
277 std::is_base_of_v<interface_type, derived_type>
278 && !std::is_same_v<interface_type, XInterface>, void *> = nullptr);
279#endif
280
281 /** Constructor: Sets given interface pointer.
282
283 @param pInterface an interface pointer
284 */
285 inline Reference( interface_type * pInterface );
286
287 /** Constructor: Sets given interface pointer without acquiring it.
288
289 @param pInterface another reference
290 @param dummy SAL_NO_ACQUIRE to force obvious distinction to other constructors
291 */
292 inline Reference( interface_type * pInterface, __sal_NoAcquire dummy);
293 /** Constructor: Sets given interface pointer without acquiring it.
294 Deprecated, please use SAL_NO_ACQUIRE version.
295
296 @deprecated
297 @param pInterface another reference
298 @param dummy UNO_REF_NO_ACQUIRE to force obvious distinction to other constructors
299 */
300 inline SAL_DEPRECATED("use SAL_NO_ACQUIRE version")__attribute__((deprecated("use SAL_NO_ACQUIRE version"))) Reference( interface_type * pInterface, UnoReference_NoAcquire dummy );
301
302 /** Constructor: Queries given interface for reference interface type (interface_type).
303
304 @param rRef another reference
305 @param dummy UNO_QUERY to force obvious distinction to other constructors
306 */
307 inline Reference( const BaseReference & rRef, UnoReference_Query dummy );
308 /** Constructor: Queries given interface for reference interface type (interface_type).
309
310 @param pInterface an interface pointer
311 @param dummy UNO_QUERY to force obvious distinction to other constructors
312 */
313 inline Reference( XInterface * pInterface, UnoReference_Query dummy);
314 /** Constructor: Queries given any for reference interface type (interface_type).
315
316 @param rAny an any
317 @param dummy UNO_QUERY to force obvious distinction to other constructors
318 */
319 inline Reference( const Any & rAny, UnoReference_Query dummy);
320 /** Constructor: Queries given interface for reference interface type (interface_type).
321 Throws a RuntimeException if the demanded interface cannot be queried.
322
323 @param rRef another reference
324 @param dummy UNO_QUERY_THROW to force obvious distinction
325 to other constructors
326 */
327 inline Reference( const BaseReference & rRef, UnoReference_QueryThrow dummy );
328#ifdef LIBO_INTERNAL_ONLY1
329 /**
330 Prevent code from calling the QUERY_THROW constructor, when they meant to use the SET_THROW constructor.
331 */
332 Reference( const Reference< interface_type > & rRef, UnoReference_QueryThrow dummy ) = delete;
333#endif
334 /** Constructor: Queries given interface for reference interface type (interface_type).
335 Throws a RuntimeException if the demanded interface cannot be queried.
336
337 @param pInterface an interface pointer
338 @param dummy UNO_QUERY_THROW to force obvious distinction
339 to other constructors
340 */
341 inline Reference( XInterface * pInterface, UnoReference_QueryThrow dummy );
342 /** Constructor: Queries given any for reference interface type (interface_type).
343 Throws a RuntimeException if the demanded interface cannot be queried.
344
345 @param rAny an any
346 @param dummy UNO_QUERY_THROW to force obvious distinction
347 to other constructors
348 */
349 inline Reference( const Any & rAny, UnoReference_QueryThrow dummy );
350 /** Constructor: assigns from the given interface of the same type. Throws a RuntimeException
351 if the source interface is NULL.
352
353 @param rRef another interface reference of the same type
354 @param dummy UNO_SET_THROW to distinguish from default copy constructor
355
356 @since UDK 3.2.8
357 */
358 inline Reference( const Reference< interface_type > & rRef, UnoReference_SetThrow dummy );
359 /** Constructor: assigns from the given interface of the same type. Throws a RuntimeException
360 if the source interface is NULL.
361
362 @param pInterface an interface pointer
363 @param dummy UNO_SET_THROW to distinguish from default assignment constructor
364
365 @since UDK 3.2.8
366 */
367 inline Reference( interface_type * pInterface, UnoReference_SetThrow dummy );
368
369 /** Cast operator to Reference< XInterface >: Reference objects are binary compatible and
370 any interface must be derived from com.sun.star.uno.XInterface.
371 This a useful direct cast possibility.
372 */
373 SAL_CALL operator const Reference< XInterface > & () const
374 { return * reinterpret_cast< const Reference< XInterface > * >( this ); }
375
376 /** Dereference operator: Used to call interface methods.
377
378 @return UNacquired interface pointer
379 */
380 interface_type * SAL_CALL operator -> () const {
381 assert(_pInterface != NULL)(static_cast <bool> (_pInterface != __null) ? void (0) :
__assert_fail ("_pInterface != NULL", "/home/maarten/src/libreoffice/core/include/com/sun/star/uno/Reference.h"
, 381, __extension__ __PRETTY_FUNCTION__))
;
382 return castFromXInterface(_pInterface);
383 }
384
385 /** Indirection operator.
386
387 @since LibreOffice 6.3
388 @return UNacquired interface reference
389 */
390 interface_type & SAL_CALL operator * () const {
391 assert(_pInterface != NULL)(static_cast <bool> (_pInterface != __null) ? void (0) :
__assert_fail ("_pInterface != NULL", "/home/maarten/src/libreoffice/core/include/com/sun/star/uno/Reference.h"
, 391, __extension__ __PRETTY_FUNCTION__))
;
392 return *castFromXInterface(_pInterface);
393 }
394
395 /** Gets interface pointer. This call does not acquire the interface.
396
397 @return UNacquired interface pointer
398 */
399 interface_type * SAL_CALL get() const
400 { return castFromXInterface(_pInterface); }
401
402 /** Clears reference, i.e. releases interface. Reference is null after clear() call.
403 */
404 inline void SAL_CALL clear();
405
406 /** Sets the given interface. An interface already set will be released.
407
408 @param rRef another reference
409 @return true, if non-null interface was set
410 */
411 inline bool SAL_CALL set( const Reference< interface_type > & rRef );
412 /** Sets the given interface. An interface already set will be released.
413
414 @param pInterface another interface
415 @return true, if non-null interface was set
416 */
417 inline bool SAL_CALL set( interface_type * pInterface );
418
419 /** Sets interface pointer without acquiring it. An interface already set will be released.
420
421 @param pInterface an interface pointer
422 @param dummy SAL_NO_ACQUIRE to force obvious distinction to set methods
423 @return true, if non-null interface was set
424 */
425 inline bool SAL_CALL set( interface_type * pInterface, __sal_NoAcquire dummy);
426 /** Sets interface pointer without acquiring it. An interface already set will be released.
427 Deprecated, please use SAL_NO_ACQUIRE version.
428
429 @deprecated
430 @param pInterface an interface pointer
431 @param dummy UNO_REF_NO_ACQUIRE to force obvious distinction to set methods
432 @return true, if non-null interface was set
433 */
434 inline SAL_DEPRECATED("use SAL_NO_ACQUIRE version")__attribute__((deprecated("use SAL_NO_ACQUIRE version"))) bool SAL_CALL set( interface_type * pInterface, UnoReference_NoAcquire dummy);
435
436 /** Queries given interface for reference interface type (interface_type) and sets it.
437 An interface already set will be released.
438
439 @param pInterface an interface pointer
440 @param dummy UNO_QUERY to force obvious distinction to set methods
441 @return true, if non-null interface was set
442 */
443 inline bool SAL_CALL set( XInterface * pInterface, UnoReference_Query dummy );
444 /** Queries given interface for reference interface type (interface_type) and sets it.
445 An interface already set will be released.
446
447 @param rRef another reference
448 @param dummy UNO_QUERY to force obvious distinction to set methods
449 @return true, if non-null interface was set
450 */
451 inline bool SAL_CALL set( const BaseReference & rRef, UnoReference_Query dummy);
452
453 /** Queries given any for reference interface type (interface_type)
454 and sets it. An interface already set will be released.
455
456 @param rAny
457 an Any containing an interface
458 @param dummy
459 UNO_QUERY to force obvious distinction
460 to set methods
461 @return
462 true, if non-null interface was set
463 */
464 inline bool set( Any const & rAny, UnoReference_Query dummy );
465
466 /** Queries given interface for reference interface type (interface_type) and sets it.
467 An interface already set will be released.
468 Throws a RuntimeException if the demanded interface cannot be set.
469
470 @param pInterface an interface pointer
471 @param dummy UNO_QUERY_THROW to force obvious distinction
472 to set methods
473 */
474 inline void SAL_CALL set( XInterface * pInterface, UnoReference_QueryThrow dummy );
475 /** Queries given interface for reference interface type (interface_type) and sets it.
476 An interface already set will be released.
477 Throws a RuntimeException if the demanded interface cannot be set.
478
479 @param rRef another reference
480 @param dummy UNO_QUERY_THROW to force obvious distinction
481 to set methods
482 */
483 inline void SAL_CALL set( const BaseReference & rRef, UnoReference_QueryThrow dummy );
484#ifdef LIBO_INTERNAL_ONLY1
485 /**
486 Prevent code from calling the QUERY_THROW version, when they meant to use the SET_THROW version.
487 */
488 void set( const Reference< interface_type > & rRef, UnoReference_QueryThrow dummy ) = delete;
489#endif
490
491 /** Queries given any for reference interface type (interface_type) and
492 sets it. An interface already set will be released.
493 Throws a RuntimeException if the demanded interface cannot be set.
494
495 @param rAny
496 an Any containing an interface
497 @param dummy
498 UNO_QUERY_THROW to force obvious distinction to set methods
499 */
500 inline void set( Any const & rAny, UnoReference_QueryThrow dummy);
501 /** sets the given interface
502 An interface already set will be released.
503 Throws a RuntimeException if the source interface is @b NULL.
504
505 @param pInterface an interface pointer
506 @param dummy UNO_SET_THROW to force obvious distinction to other set methods
507
508 @since UDK 3.2.8
509 */
510 inline void SAL_CALL set( interface_type * pInterface, UnoReference_SetThrow dummy);
511 /** sets the given interface
512 An interface already set will be released.
513 Throws a RuntimeException if the source interface is @b NULL.
514
515 @param rRef an interface reference
516 @param dummy UNO_SET_THROW to force obvious distinction to other set methods
517
518 @since UDK 3.2.8
519 */
520 inline void SAL_CALL set( const Reference< interface_type > & rRef, UnoReference_SetThrow dummy);
521
522
523 /** Assignment operator: Acquires given interface pointer and sets reference.
524 An interface already set will be released.
525
526 @param pInterface an interface pointer
527 @return this reference
528 */
529 inline Reference< interface_type > & SAL_CALL operator = ( interface_type * pInterface );
530 /** Assignment operator: Acquires given interface reference and sets reference.
531 An interface already set will be released.
532
533 @param rRef an interface reference
534 @return this reference
535 */
536 inline Reference< interface_type > & SAL_CALL operator = ( const Reference< interface_type > & rRef );
537#if defined LIBO_INTERNAL_ONLY1
538 /** Assignment move operator: Acquires given interface reference and sets reference.
539 An interface already set will be released.
540
541 @param rRef an interface reference
542 @return this reference
543 */
544 inline Reference< interface_type > & SAL_CALL operator = ( Reference< interface_type > && rRef ) noexcept;
545#endif
546 /** Queries given interface reference for type interface_type.
547
548 @param rRef interface reference
549 @return interface reference of demanded type (may be null)
550 */
551 SAL_WARN_UNUSED_RESULT[[nodiscard]] inline static Reference< interface_type > SAL_CALL query( const BaseReference & rRef );
552 /** Queries given interface for type interface_type.
553
554 @param pInterface interface pointer
555 @return interface reference of demanded type (may be null)
556 */
557 SAL_WARN_UNUSED_RESULT[[nodiscard]] inline static Reference< interface_type > SAL_CALL query( XInterface * pInterface );
558};
559
560}
561}
562}
563}
564
565#endif
566
567/* vim:set shiftwidth=4 softtabstop=4 expandtab: */