Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / sw / source / filter / html / htmlfld.cxx
blobc1eff7ef7cb764ee9ca6793874657d8647eca612
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
21 #include <com/sun/star/document/XDocumentProperties.hpp>
22 #include <com/sun/star/frame/XModel.hpp>
23 #include <o3tl/string_view.hxx>
24 #include <osl/diagnose.h>
25 #include <docsh.hxx>
26 #include <IDocumentFieldsAccess.hxx>
27 #include <svtools/htmltokn.h>
28 #include <svl/numformat.hxx>
29 #include <svl/zforlist.hxx>
30 #include <unotools/useroptions.hxx>
31 #include <fmtfld.hxx>
32 #include <ndtxt.hxx>
33 #include <doc.hxx>
34 #include <fldbas.hxx>
35 #include <docufld.hxx>
36 #include <flddat.hxx>
37 #include "htmlfld.hxx"
38 #include "swhtml.hxx"
40 using namespace nsSwDocInfoSubType;
41 using namespace ::com::sun::star;
43 namespace {
45 struct HTMLNumFormatTableEntry
47 std::string_view pName;
48 NfIndexTableOffset eFormat;
53 HTMLOptionEnum<SwFieldIds> const aHTMLFieldTypeTable[] =
55 { OOO_STRING_SW_HTML_FT_author, SwFieldIds::Author },
56 { OOO_STRING_SW_HTML_FT_sender, SwFieldIds::ExtUser },
57 { "DATE", SwFieldIds::Date },
58 { "TIME", SwFieldIds::Time },
59 { OOO_STRING_SW_HTML_FT_datetime, SwFieldIds::DateTime },
60 { OOO_STRING_SW_HTML_FT_page, SwFieldIds::PageNumber },
61 { OOO_STRING_SW_HTML_FT_docinfo, SwFieldIds::DocInfo },
62 { OOO_STRING_SW_HTML_FT_docstat, SwFieldIds::DocStat },
63 { OOO_STRING_SW_HTML_FT_filename, SwFieldIds::Filename },
64 { nullptr, SwFieldIds(0) }
67 HTMLNumFormatTableEntry const aHTMLDateFieldFormatTable[] =
69 { "SSYS", NF_DATE_SYSTEM_SHORT },
70 { "LSYS", NF_DATE_SYSTEM_LONG },
71 { "DMY", NF_DATE_SYS_DDMMYY, },
72 { "DMYY", NF_DATE_SYS_DDMMYYYY, },
73 { "DMMY", NF_DATE_SYS_DMMMYY, },
74 { "DMMYY", NF_DATE_SYS_DMMMYYYY, },
75 { "DMMMY", NF_DATE_DIN_DMMMMYYYY },
76 { "DMMMYY", NF_DATE_DIN_DMMMMYYYY },
77 { "DDMMY", NF_DATE_SYS_NNDMMMYY },
78 { "DDMMMY", NF_DATE_SYS_NNDMMMMYYYY },
79 { "DDMMMYY", NF_DATE_SYS_NNDMMMMYYYY },
80 { "DDDMMMY", NF_DATE_SYS_NNNNDMMMMYYYY },
81 { "DDDMMMYY", NF_DATE_SYS_NNNNDMMMMYYYY },
82 { "MY", NF_DATE_SYS_MMYY },
83 { "MD", NF_DATE_DIN_MMDD },
84 { "YMD", NF_DATE_DIN_YYMMDD },
85 { "YYMD", NF_DATE_DIN_YYYYMMDD },
86 { {}, NF_NUMERIC_START }
89 HTMLNumFormatTableEntry const aHTMLTimeFieldFormatTable[] =
91 { "SYS", NF_TIME_HHMMSS },
92 { "SSMM24", NF_TIME_HHMM },
93 { "SSMM12", NF_TIME_HHMMAMPM },
94 { {}, NF_NUMERIC_START }
97 HTMLOptionEnum<SvxNumType> const aHTMLPageNumFieldFormatTable[] =
99 { OOO_STRING_SW_HTML_FF_uletter, SVX_NUM_CHARS_UPPER_LETTER },
100 { OOO_STRING_SW_HTML_FF_lletter, SVX_NUM_CHARS_LOWER_LETTER },
101 { OOO_STRING_SW_HTML_FF_uroman, SVX_NUM_ROMAN_UPPER },
102 { OOO_STRING_SW_HTML_FF_lroman, SVX_NUM_ROMAN_LOWER },
103 { OOO_STRING_SW_HTML_FF_arabic, SVX_NUM_ARABIC },
104 { OOO_STRING_SW_HTML_FF_none, SVX_NUM_NUMBER_NONE },
105 { OOO_STRING_SW_HTML_FF_char, SVX_NUM_CHAR_SPECIAL },
106 { OOO_STRING_SW_HTML_FF_page, SVX_NUM_PAGEDESC },
107 { OOO_STRING_SW_HTML_FF_ulettern, SVX_NUM_CHARS_UPPER_LETTER_N },
108 { OOO_STRING_SW_HTML_FF_llettern, SVX_NUM_CHARS_LOWER_LETTER_N },
109 { nullptr, SvxNumType(0) }
112 HTMLOptionEnum<SwExtUserSubType> const aHTMLExtUsrFieldSubTable[] =
114 { OOO_STRING_SW_HTML_FS_company, EU_COMPANY },
115 { OOO_STRING_SW_HTML_FS_firstname, EU_FIRSTNAME },
116 { OOO_STRING_SW_HTML_FS_name, EU_NAME },
117 { OOO_STRING_SW_HTML_FS_shortcut, EU_SHORTCUT },
118 { OOO_STRING_SW_HTML_FS_street, EU_STREET },
119 { OOO_STRING_SW_HTML_FS_country, EU_COUNTRY },
120 { OOO_STRING_SW_HTML_FS_zip, EU_ZIP },
121 { OOO_STRING_SW_HTML_FS_city, EU_CITY },
122 { OOO_STRING_SW_HTML_FS_title, EU_TITLE },
123 { OOO_STRING_SW_HTML_FS_position, EU_POSITION },
124 { OOO_STRING_SW_HTML_FS_pphone, EU_PHONE_PRIVATE },
125 { OOO_STRING_SW_HTML_FS_cphone, EU_PHONE_COMPANY },
126 { OOO_STRING_SW_HTML_FS_fax, EU_FAX },
127 { OOO_STRING_SW_HTML_FS_email, EU_EMAIL },
128 { OOO_STRING_SW_HTML_FS_state, EU_STATE },
129 { nullptr, SwExtUserSubType(0) }
132 HTMLOptionEnum<SwAuthorFormat> const aHTMLAuthorFieldFormatTable[] =
134 { OOO_STRING_SW_HTML_FF_name, AF_NAME },
135 { OOO_STRING_SW_HTML_FF_shortcut, AF_SHORTCUT },
136 { nullptr, SwAuthorFormat(0) }
139 HTMLOptionEnum<SwPageNumSubType> const aHTMLPageNumFieldSubTable[] =
141 { OOO_STRING_SW_HTML_FS_random, PG_RANDOM },
142 { OOO_STRING_SW_HTML_FS_next, PG_NEXT },
143 { OOO_STRING_SW_HTML_FS_prev, PG_PREV },
144 { nullptr, SwPageNumSubType(0) }
147 // UGLY: these are extensions of nsSwDocInfoSubType (in inc/docufld.hxx)
148 // these are necessary for importing document info fields written by
149 // older versions of OOo (< 3.0) which did not have DI_CUSTOM fields
150 const SwDocInfoSubType DI_INFO1 = DI_SUBTYPE_END + 1;
151 const SwDocInfoSubType DI_INFO2 = DI_SUBTYPE_END + 2;
152 const SwDocInfoSubType DI_INFO3 = DI_SUBTYPE_END + 3;
153 const SwDocInfoSubType DI_INFO4 = DI_SUBTYPE_END + 4;
155 HTMLOptionEnum<sal_uInt16> const aHTMLDocInfoFieldSubTable[] =
157 { OOO_STRING_SW_HTML_FS_title, DI_TITLE },
158 { OOO_STRING_SW_HTML_FS_theme, DI_SUBJECT },
159 { OOO_STRING_SW_HTML_FS_keys, DI_KEYS },
160 { OOO_STRING_SW_HTML_FS_comment, DI_COMMENT },
161 { "INFO1", DI_INFO1 },
162 { "INFO2", DI_INFO2 },
163 { "INFO3", DI_INFO3 },
164 { "INFO4", DI_INFO4 },
165 { OOO_STRING_SW_HTML_FS_custom, DI_CUSTOM },
166 { OOO_STRING_SW_HTML_FS_create, DI_CREATE },
167 { OOO_STRING_SW_HTML_FS_change, DI_CHANGE },
168 { nullptr, 0 }
171 HTMLOptionEnum<sal_uInt16> const aHTMLDocInfoFieldFormatTable[] =
173 { OOO_STRING_SW_HTML_FF_author, DI_SUB_AUTHOR },
174 { OOO_STRING_SW_HTML_FF_time, DI_SUB_TIME },
175 { OOO_STRING_SW_HTML_FF_date, DI_SUB_DATE },
176 { nullptr, 0 }
179 HTMLOptionEnum<SwDocStatSubType> const aHTMLDocStatFieldSubTable[] =
181 { OOO_STRING_SW_HTML_FS_page, DS_PAGE },
182 { OOO_STRING_SW_HTML_FS_para, DS_PARA },
183 { OOO_STRING_SW_HTML_FS_word, DS_WORD },
184 { OOO_STRING_SW_HTML_FS_char, DS_CHAR },
185 { OOO_STRING_SW_HTML_FS_tbl, DS_TBL },
186 { OOO_STRING_SW_HTML_FS_grf, DS_GRF },
187 { OOO_STRING_SW_HTML_FS_ole, DS_OLE },
188 { nullptr, SwDocStatSubType(0) }
191 HTMLOptionEnum<SwFileNameFormat> const aHTMLFileNameFieldFormatTable[] =
193 { OOO_STRING_SW_HTML_FF_name, FF_NAME },
194 { OOO_STRING_SW_HTML_FF_pathname, FF_PATHNAME },
195 { OOO_STRING_SW_HTML_FF_path, FF_PATH },
196 { OOO_STRING_SW_HTML_FF_name_noext, FF_NAME_NOEXT },
197 { nullptr, SwFileNameFormat(0) }
200 SvxNumType SwHTMLParser::GetNumType( std::u16string_view rStr, SvxNumType nDfltType )
202 const HTMLOptionEnum<SvxNumType> *pOptEnums = aHTMLPageNumFieldFormatTable;
203 while( pOptEnums->pName )
205 if( o3tl::equalsIgnoreAsciiCase( rStr, pOptEnums->pName ) )
206 return pOptEnums->nValue;
207 pOptEnums++;
209 return nDfltType;
212 void SwHTMLParser::NewField()
214 bool bKnownType = false, bFixed = false,
215 bHasNumFormat = false, bHasNumValue = false;
216 SwFieldIds nType = SwFieldIds::Database;
217 OUString aValue, aNumFormat, aNumValue, aName;
218 const HTMLOption *pSubOption=nullptr, *pFormatOption=nullptr;
220 const HTMLOptions& rHTMLOptions = GetOptions();
221 size_t i;
223 for ( i = rHTMLOptions.size(); i; )
225 const HTMLOption& rOption = rHTMLOptions[--i];
226 switch( rOption.GetToken() )
228 case HtmlOptionId::TYPE:
229 bKnownType = rOption.GetEnum( nType, aHTMLFieldTypeTable );
230 break;
231 case HtmlOptionId::SUBTYPE:
232 pSubOption = &rOption;
233 break;
234 case HtmlOptionId::FORMAT:
235 pFormatOption = &rOption;
236 break;
237 case HtmlOptionId::NAME:
238 aName = rOption.GetString();
239 break;
240 case HtmlOptionId::VALUE:
241 aValue = rOption.GetString();
242 break;
243 case HtmlOptionId::SDNUM:
244 aNumFormat = rOption.GetString();
245 bHasNumFormat = true;
246 break;
247 case HtmlOptionId::SDVAL:
248 aNumValue = rOption.GetString();
249 bHasNumValue = true;
250 break;
251 case HtmlOptionId::SDFIXED:
252 bFixed = true;
253 break;
254 default: break;
258 if( !bKnownType )
259 return;
261 // Author and sender are only inserted as a variable field if the document
262 // was last changed by ourself or nobody changed it and it was created
263 // by ourself. Otherwise it will be a fixed field.
264 if( !bFixed &&
265 (SwFieldIds::ExtUser == nType ||
266 SwFieldIds::Author == nType) )
268 SvtUserOptions aOpt;
269 const OUString& rUser = aOpt.GetFullName();
270 SwDocShell *pDocShell(m_xDoc->GetDocShell());
271 OSL_ENSURE(pDocShell, "no SwDocShell");
272 if (pDocShell) {
273 uno::Reference<document::XDocumentPropertiesSupplier> xDPS(
274 pDocShell->GetModel(), uno::UNO_QUERY_THROW);
275 uno::Reference<document::XDocumentProperties> xDocProps(
276 xDPS->getDocumentProperties());
277 OSL_ENSURE(xDocProps.is(), "Doc has no DocumentProperties");
278 const OUString& rChanged = xDocProps->getModifiedBy();
279 const OUString& rCreated = xDocProps->getAuthor();
280 if( rUser.isEmpty() ||
281 (!rChanged.isEmpty() ? rUser != rChanged : rUser != rCreated) )
282 bFixed = true;
286 SwFieldIds nWhich = nType;
287 if( SwFieldIds::Date==nType || SwFieldIds::Time==nType )
288 nWhich = SwFieldIds::DateTime;
290 SwFieldType* pType = m_xDoc->getIDocumentFieldsAccess().GetSysFieldType( nWhich );
291 std::unique_ptr<SwField> xNewField;
292 bool bInsOnEndTag = false;
294 switch( nType )
296 case SwFieldIds::ExtUser:
297 if( pSubOption )
299 SwExtUserSubType nSub;
300 sal_uLong nFormat = 0;
301 if( bFixed )
303 nFormat |= AF_FIXED;
304 bInsOnEndTag = true;
306 if( pSubOption->GetEnum( nSub, aHTMLExtUsrFieldSubTable ) )
307 xNewField.reset(new SwExtUserField(static_cast<SwExtUserFieldType*>(pType), nSub, nFormat));
309 break;
311 case SwFieldIds::Author:
313 SwAuthorFormat nFormat = AF_NAME;
314 if( pFormatOption )
315 pFormatOption->GetEnum( nFormat, aHTMLAuthorFieldFormatTable );
316 if( bFixed )
318 nFormat = static_cast<SwAuthorFormat>(static_cast<int>(nFormat) | AF_FIXED);
319 bInsOnEndTag = true;
322 xNewField.reset(new SwAuthorField(static_cast<SwAuthorFieldType*>(pType), nFormat));
324 break;
326 case SwFieldIds::Date:
327 case SwFieldIds::Time:
329 sal_uInt32 nNumFormat = 0;
330 DateTime aDateTime( DateTime::SYSTEM );
331 sal_Int64 nTime = aDateTime.GetTime();
332 sal_Int32 nDate = aDateTime.GetDate();
333 sal_uInt16 nSub = 0;
334 bool bValidFormat = false;
335 HTMLNumFormatTableEntry const * pFormatTable;
337 if( SwFieldIds::Date==nType )
339 nSub = DATEFLD;
340 pFormatTable = aHTMLDateFieldFormatTable;
341 if( !aValue.isEmpty() )
342 nDate = aValue.toInt32();
344 else
346 nSub = TIMEFLD;
347 pFormatTable = aHTMLTimeFieldFormatTable;
348 if( !aValue.isEmpty() )
349 nTime = static_cast<sal_uLong>(aValue.toInt32());
351 if( !aValue.isEmpty() )
352 nSub |= FIXEDFLD;
354 SvNumberFormatter *pFormatter = m_xDoc->GetNumberFormatter();
355 if( pFormatOption )
357 const OUString& rFormat = pFormatOption->GetString();
358 for( int k = 0; !pFormatTable[k].pName.empty(); ++k )
360 if( rFormat.equalsIgnoreAsciiCaseAscii( pFormatTable[k].pName ) )
362 nNumFormat = pFormatter->GetFormatIndex(
363 pFormatTable[k].eFormat, LANGUAGE_SYSTEM);
364 bValidFormat = true;
365 break;
369 if( !bValidFormat )
370 nNumFormat = pFormatter->GetFormatIndex( pFormatTable[i].eFormat,
371 LANGUAGE_SYSTEM);
373 xNewField.reset(new SwDateTimeField(static_cast<SwDateTimeFieldType *>(pType), nSub, nNumFormat));
375 if (nSub & FIXEDFLD)
376 static_cast<SwDateTimeField *>(xNewField.get())->SetDateTime(DateTime(Date(nDate), tools::Time(nTime)));
378 break;
380 case SwFieldIds::DateTime:
381 if( bHasNumFormat )
383 sal_uInt16 nSub = 0;
385 SvNumberFormatter *pFormatter = m_xDoc->GetNumberFormatter();
386 sal_uInt32 nNumFormat;
387 LanguageType eLang;
388 double dValue = GetTableDataOptionsValNum(
389 nNumFormat, eLang, aNumValue, aNumFormat,
390 *m_xDoc->GetNumberFormatter() );
391 SvNumFormatType nFormatType = pFormatter->GetType( nNumFormat );
392 switch( nFormatType )
394 case SvNumFormatType::DATE: nSub = DATEFLD; break;
395 case SvNumFormatType::TIME: nSub = TIMEFLD; break;
396 default: break;
399 if( nSub )
401 if( bHasNumValue )
402 nSub |= FIXEDFLD;
404 xNewField.reset(new SwDateTimeField(static_cast<SwDateTimeFieldType *>(pType), nSub, nNumFormat));
405 if (bHasNumValue)
406 static_cast<SwDateTimeField*>(xNewField.get())->SetValue(dValue);
409 break;
411 case SwFieldIds::PageNumber:
412 if( pSubOption )
414 SwPageNumSubType nSub;
415 if( pSubOption->GetEnum( nSub, aHTMLPageNumFieldSubTable ) )
417 SvxNumType nFormat = SVX_NUM_PAGEDESC;
418 if( pFormatOption )
419 pFormatOption->GetEnum( nFormat, aHTMLPageNumFieldFormatTable );
421 short nOff = 0;
423 if( nFormat!=SVX_NUM_CHAR_SPECIAL && !aValue.isEmpty() )
424 nOff = static_cast<short>(aValue.toInt32());
425 else if( nSub == PG_NEXT )
426 nOff = 1;
427 else if( nSub == PG_PREV )
428 nOff = -1;
430 if( nFormat==SVX_NUM_CHAR_SPECIAL &&
431 nSub==PG_RANDOM )
432 nFormat = SVX_NUM_PAGEDESC;
434 xNewField.reset(new SwPageNumberField(static_cast<SwPageNumberFieldType*>(pType), nSub, nFormat, nOff));
435 if (nFormat == SVX_NUM_CHAR_SPECIAL)
436 static_cast<SwPageNumberField*>(xNewField.get())->SetUserString(aValue);
439 break;
441 case SwFieldIds::DocInfo:
442 if( pSubOption )
444 sal_uInt16 nSub;
445 if( pSubOption->GetEnum( nSub, aHTMLDocInfoFieldSubTable ) )
447 sal_uInt16 nExtSub = 0;
448 if( DI_CREATE==static_cast<SwDocInfoSubType>(nSub) ||
449 DI_CHANGE==static_cast<SwDocInfoSubType>(nSub) )
451 nExtSub = DI_SUB_AUTHOR;
452 if( pFormatOption )
453 pFormatOption->GetEnum( nExtSub, aHTMLDocInfoFieldFormatTable );
454 nSub |= nExtSub;
457 sal_uInt32 nNumFormat = 0;
458 double dValue = 0;
459 if( bHasNumFormat && (DI_SUB_DATE==nExtSub || DI_SUB_TIME==nExtSub) )
461 LanguageType eLang;
462 dValue = GetTableDataOptionsValNum(
463 nNumFormat, eLang, aNumValue, aNumFormat,
464 *m_xDoc->GetNumberFormatter() );
465 bFixed &= bHasNumValue;
467 else
468 bHasNumValue = false;
470 if( nSub >= DI_INFO1 && nSub <= DI_INFO4 && aName.isEmpty() )
472 // backward compatibility for OOo 2:
473 // map to names stored in AddMetaUserDefined
474 aName = m_InfoNames[nSub - DI_INFO1];
475 nSub = DI_CUSTOM;
478 if( bFixed )
480 nSub |= DI_SUB_FIXED;
481 bInsOnEndTag = true;
484 xNewField.reset(new SwDocInfoField(static_cast<SwDocInfoFieldType *>(pType), nSub, aName, nNumFormat));
485 if (bHasNumValue)
486 static_cast<SwDocInfoField*>(xNewField.get())->SetValue(dValue);
489 break;
491 case SwFieldIds::DocStat:
492 if( pSubOption )
494 SwDocStatSubType nSub;
495 if( pSubOption->GetEnum( nSub, aHTMLDocStatFieldSubTable ) )
497 SvxNumType nFormat = SVX_NUM_ARABIC;
498 if( pFormatOption )
499 pFormatOption->GetEnum( nFormat, aHTMLPageNumFieldFormatTable );
500 xNewField.reset(new SwDocStatField(static_cast<SwDocStatFieldType*>(pType), nSub, nFormat));
501 m_bUpdateDocStat |= (DS_PAGE != nSub);
504 break;
506 case SwFieldIds::Filename:
508 SwFileNameFormat nFormat = FF_NAME;
509 if( pFormatOption )
510 pFormatOption->GetEnum( nFormat, aHTMLFileNameFieldFormatTable );
511 if( bFixed )
513 nFormat = static_cast<SwFileNameFormat>(static_cast<int>(nFormat) | FF_FIXED);
514 bInsOnEndTag = true;
517 xNewField.reset(new SwFileNameField(static_cast<SwFileNameFieldType*>(pType), nFormat));
519 break;
520 default:
524 if (!xNewField)
525 return;
527 if (bInsOnEndTag)
529 m_xField = std::move(xNewField);
531 else
533 m_xDoc->getIDocumentContentOperations().InsertPoolItem(*m_pPam, SwFormatField(*xNewField));
534 xNewField.reset();
536 m_bInField = true;
539 void SwHTMLParser::EndField()
541 if (m_xField)
543 switch (m_xField->Which())
545 case SwFieldIds::DocInfo:
546 OSL_ENSURE( static_cast<SwDocInfoField*>(m_xField.get())->IsFixed(),
547 "Field DocInfo should not have been saved" );
548 static_cast<SwDocInfoField*>(m_xField.get())->SetExpansion( m_aContents );
549 break;
551 case SwFieldIds::ExtUser:
552 OSL_ENSURE( static_cast<SwExtUserField*>(m_xField.get())->IsFixed(),
553 "Field ExtUser should not have been saved" );
554 static_cast<SwExtUserField*>(m_xField.get())->SetExpansion( m_aContents );
555 break;
557 case SwFieldIds::Author:
558 OSL_ENSURE( static_cast<SwAuthorField*>(m_xField.get())->IsFixed(),
559 "Field Author should not have been saved" );
560 static_cast<SwAuthorField*>(m_xField.get())->SetExpansion( m_aContents );
561 break;
563 case SwFieldIds::Filename:
564 OSL_ENSURE( static_cast<SwFileNameField*>(m_xField.get())->IsFixed(),
565 "Field FileName should not have been saved" );
566 static_cast<SwFileNameField*>(m_xField.get())->SetExpansion( m_aContents );
567 break;
568 default: break;
571 m_xDoc->getIDocumentContentOperations().InsertPoolItem( *m_pPam, SwFormatField(*m_xField) );
572 m_xField.reset();
575 m_bInField = false;
576 m_aContents.clear();
579 void SwHTMLParser::InsertFieldText()
581 if (m_xField)
583 // append the current text part to the text
584 m_aContents += aToken;
588 void SwHTMLParser::InsertCommentText( std::string_view pTag )
590 bool bEmpty = m_aContents.isEmpty();
591 if( !bEmpty )
592 m_aContents += "\n";
594 m_aContents += aToken;
595 if( bEmpty && !pTag.empty() )
597 m_aContents = OUString::Concat("HTML: <") + OUString::createFromAscii(pTag) + ">" + m_aContents;
601 void SwHTMLParser::InsertComment( const OUString& rComment, std::string_view pTag )
603 OUString aComment( rComment );
604 if( !pTag.empty() )
606 aComment += "</" +
607 OUString::createFromAscii(pTag) +
608 ">";
611 // MIB 24.06.97: If a PostIt should be insert after a space, we
612 // will insert before the space. Then there are less problems
613 // during formatting. (bug #40483#)
614 const sal_Int32 nPos = m_pPam->GetPoint()->GetContentIndex();
615 SwTextNode *pTextNd = m_pPam->GetPointNode().GetTextNode();
616 bool bMoveFwd = false;
617 if (nPos>0 && pTextNd && (' ' == pTextNd->GetText()[nPos-1]))
619 bMoveFwd = true;
621 SwNodeOffset nNodeIdx = m_pPam->GetPoint()->GetNodeIndex();
622 const sal_Int32 nIdx = m_pPam->GetPoint()->GetContentIndex();
623 for( auto i = m_aSetAttrTab.size(); i > 0; )
625 HTMLAttr *pAttr = m_aSetAttrTab[--i];
626 if( pAttr->GetStartParagraphIdx() != nNodeIdx ||
627 pAttr->GetStartContent() != nIdx )
628 break;
630 if( RES_TXTATR_FIELD == pAttr->m_pItem->Which() &&
631 SwFieldIds::Script == static_cast<const SwFormatField *>(pAttr->m_pItem.get())->GetField()->GetTyp()->Which() )
633 bMoveFwd = false;
634 break;
638 if( bMoveFwd )
639 m_pPam->Move( fnMoveBackward );
642 SwPostItField aPostItField(
643 static_cast<SwPostItFieldType*>(m_xDoc->getIDocumentFieldsAccess().GetSysFieldType( SwFieldIds::Postit )),
644 OUString(), aComment, OUString(), OUString(), DateTime(DateTime::SYSTEM));
645 InsertAttr( SwFormatField( aPostItField ), false );
647 if( bMoveFwd )
648 m_pPam->Move( fnMoveForward );
651 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */