LibreOffice Module sw (master) 1
atrfld.cxx
Go to the documentation of this file.
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 <fmtfld.hxx>
21
22#include <libxml/xmlwriter.h>
23
24#include <fldbas.hxx>
25#include <txtfld.hxx>
26#include <txtannotationfld.hxx>
27#include <docfld.hxx>
28#include <docufld.hxx>
29#include <doc.hxx>
30#include <unofield.hxx>
31
32#include <pam.hxx>
33#include <reffld.hxx>
34#include <ddefld.hxx>
35#include <usrfld.hxx>
36#include <expfld.hxx>
37#include <ndtxt.hxx>
38#include <hints.hxx>
42#include <fieldhint.hxx>
43#include <sal/log.hxx>
44#include <osl/diagnose.h>
45
46
47// constructor for default item in attribute-pool
48SwFormatField::SwFormatField( sal_uInt16 nWhich )
49 : SfxPoolItem( nWhich )
51 , mpTextField( nullptr )
52{
53}
54
58 , mpField( rField.CopyField() )
59 , mpTextField( nullptr )
60{
61 rField.GetTyp()->Add(this);
62 if ( mpField->GetTyp()->Which() == SwFieldIds::Input )
63 {
64 // input field in-place editing
66 static_cast<SwInputField*>(mpField.get())->SetFormatField( *this );
67 }
68 else if (mpField->GetTyp()->Which() == SwFieldIds::SetExp)
69 {
70 // see SwWrtShell::StartInputFieldDlg
71 SwSetExpField *const pSetField(static_cast<SwSetExpField *>(mpField.get()));
72 if (pSetField->GetInputFlag()
73 // only for string fields for now - inline editing of number fields
74 // tends to produce error messages...
75 && (static_cast<SwSetExpFieldType*>(pSetField->GetTyp())->GetType()
77 {
79 }
80 pSetField->SetFormatField(*this);
81 }
82 else if ( mpField->GetTyp()->Which() == SwFieldIds::Postit )
83 {
84 // text annotation field
86 }
87}
88
89// #i24434#
90// Since Items are used in ItemPool and in default constructed ItemSets with
91// full pool range, all items need to be clonable. Thus, this one needed to be
92// corrected
94 : SfxPoolItem( rAttr )
96 , mpTextField( nullptr )
97{
98 if ( !rAttr.mpField )
99 return;
100
101 rAttr.mpField->GetTyp()->Add(this);
102 mpField = rAttr.mpField->CopyField();
103 if ( mpField->GetTyp()->Which() == SwFieldIds::Input )
104 {
105 // input field in-place editing
107 SwInputField *pField = dynamic_cast<SwInputField*>(mpField.get());
108 assert(pField);
109 if (pField)
110 pField->SetFormatField( *this );
111 }
112 else if (mpField->GetTyp()->Which() == SwFieldIds::SetExp)
113 {
114 SwSetExpField *const pSetField(static_cast<SwSetExpField *>(mpField.get()));
115 if (pSetField->GetInputFlag()
116 && (static_cast<SwSetExpFieldType*>(pSetField->GetTyp())->GetType()
118 {
120 }
121 // see SwWrtShell::StartInputFieldDlg
122 pSetField->SetFormatField(*this);
123 }
124 else if ( mpField->GetTyp()->Which() == SwFieldIds::Postit )
125 {
126 // text annotation field
128 }
129}
130
132{
133 SwFieldType* pType = mpField ? mpField->GetTyp() : nullptr;
134
135 if (pType && pType->Which() == SwFieldIds::Database)
136 pType = nullptr; // DB field types destroy themselves
137
139 mpField.reset();
140
141 // some fields need to delete their field type
142 if( !(pType && pType->HasOnlyOneListener()) )
143 return;
144
145 bool bDel = false;
146 switch( pType->Which() )
147 {
148 case SwFieldIds::User:
149 bDel = static_cast<SwUserFieldType*>(pType)->IsDeleted();
150 break;
151
153 bDel = static_cast<SwSetExpFieldType*>(pType)->IsDeleted();
154 break;
155
156 case SwFieldIds::Dde:
157 bDel = static_cast<SwDDEFieldType*>(pType)->IsDeleted();
158 break;
159 default: break;
160 }
161
162 if( bDel )
163 {
164 // unregister before deleting
165 pType->Remove( this );
166 delete pType;
167 }
168}
169
171{
172 rType.Add(this);
173}
174
175void SwFormatField::SetField(std::unique_ptr<SwField> _pField)
176{
177 mpField = std::move(_pField);
178 if ( mpField->GetTyp()->Which() == SwFieldIds::Input )
179 {
180 static_cast<SwInputField* >(mpField.get())->SetFormatField( *this );
181 }
182 else if (mpField->GetTyp()->Which() == SwFieldIds::SetExp)
183 {
184 // see SwWrtShell::StartInputFieldDlg
185 static_cast<SwSetExpField *>(mpField.get())->SetFormatField(*this);
186 }
188}
189
191{
192 mpTextField = &rTextField;
193}
194
196{
197 mpTextField = nullptr;
198}
199
200bool SwFormatField::operator==( const SfxPoolItem& rAttr ) const
201{
202 assert(SfxPoolItem::operator==(rAttr));
203 return ( mpField
204 && static_cast<const SwFormatField&>(rAttr).mpField
205 && mpField->GetTyp() == static_cast<const SwFormatField&>(rAttr).mpField->GetTyp()
206 && mpField->GetFormat() == static_cast<const SwFormatField&>(rAttr).mpField->GetFormat() )
207 ||
208 ( !mpField && !static_cast<const SwFormatField&>(rAttr).mpField );
209}
210
212{
213 return new SwFormatField( *this );
214}
215
217{
218 const SwPtrMsgPoolItem aItem(RES_REMOVE_UNO_OBJECT, &static_cast<sw::BroadcastingModify&>(*this));
219 CallSwClientNotify(sw::LegacyModifyHint{ &aItem, &aItem });
220}
221
222void SwFormatField::SwClientNotify( const SwModify& rModify, const SfxHint& rHint )
223{
224 SwClient::SwClientNotify(rModify, rHint);
225 if (rHint.GetId() == SfxHintId::SwField)
226 {
227 const auto pFieldHint = static_cast<const SwFieldHint*>( &rHint );
228 // replace field content by text
229 SwPaM* pPaM = pFieldHint->m_pPaM;
230 pPaM->DeleteMark(); // TODO: this is really hackish
231
232 if( !mpTextField )
233 return;
234
235 SwDoc& rDoc = pPaM->GetDoc();
236 const SwTextNode& rTextNode = mpTextField->GetTextNode();
237 pPaM->GetPoint()->Assign(rTextNode, mpTextField->GetStart());
238
239 OUString const aEntry(mpField->ExpandField(rDoc.IsClipBoard(), pFieldHint->m_pLayout));
240 pPaM->SetMark();
241 pPaM->Move( fnMoveForward );
243 rDoc.getIDocumentContentOperations().InsertString( *pPaM, aEntry );
244 }
245 else if (rHint.GetId() == SfxHintId::SwLegacyModify)
246 {
247 if(!mpTextField)
248 return;
249 UpdateTextNode(rHint);
250 }
251 else if (rHint.GetId() == SfxHintId::SwFindFormatForField)
252 {
253 const auto pFindForFieldHint = static_cast<const sw::FindFormatForFieldHint*>( &rHint );
254 if(pFindForFieldHint->m_rpFormat == nullptr && pFindForFieldHint->m_pField == GetField())
255 pFindForFieldHint->m_rpFormat = this;
256 }
257 else if (rHint.GetId() == SfxHintId::SwFindFormatForPostItId)
258 {
259 const auto pFindForPostItIdHint = static_cast<const sw::FindFormatForPostItIdHint*>( &rHint );
260 auto pPostItField = dynamic_cast<SwPostItField*>(mpField.get());
261 if(pPostItField && pFindForPostItIdHint->m_rpFormat == nullptr && pFindForPostItIdHint->m_nPostItId == pPostItField->GetPostItId())
262 pFindForPostItIdHint->m_rpFormat = this;
263 }
264 else if (rHint.GetId() == SfxHintId::SwCollectPostIts)
265 {
266 const auto pCollectPostItsHint = static_cast<const sw::CollectPostItsHint*>( &rHint );
267 if(GetTextField() && IsFieldInDoc() && (!pCollectPostItsHint->m_bHideRedlines || !sw::IsFieldDeletedInModel(pCollectPostItsHint->m_rIDRA, *GetTextField())))
268 pCollectPostItsHint->m_rvFormatFields.push_back(this);
269 }
270 else if (rHint.GetId() == SfxHintId::SwHasHiddenInformationNotes)
271 {
272 const auto pHasHiddenInfoHint = static_cast<const sw::HasHiddenInformationNotesHint*>( &rHint );
273 if(!pHasHiddenInfoHint->m_rbHasHiddenInformationNotes && GetTextField() && IsFieldInDoc())
274 pHasHiddenInfoHint->m_rbHasHiddenInformationNotes = true;
275 }
276 else if (rHint.GetId() == SfxHintId::SwGatherNodeIndex)
277 {
278 const auto pGatherNodeIndexHint = static_cast<const sw::GatherNodeIndexHint*>( &rHint );
279 if(auto pTextField = GetTextField())
280 pGatherNodeIndexHint->m_rvNodeIndex.push_back(pTextField->GetTextNode().GetIndex());
281 }
282 else if (rHint.GetId() == SfxHintId::SwGatherRefFields)
283 {
284 const auto pGatherRefFieldsHint = static_cast<const sw::GatherRefFieldsHint*>( &rHint );
285 if(!GetTextField() || pGatherRefFieldsHint->m_nType != GetField()->GetSubType())
286 return;
288 if(pNd && pNd->GetNodes().IsDocNodes())
289 pGatherRefFieldsHint->m_rvRFields.push_back(static_cast<SwGetRefField*>(GetField()));
290 }
291 else if (rHint.GetId() == SfxHintId::SwGatherFields)
292 {
293 const auto pGatherFieldsHint = static_cast<const sw::GatherFieldsHint*>( &rHint );
294 if(pGatherFieldsHint->m_bCollectOnlyInDocNodes)
295 {
296 if(!GetTextField())
297 return;
299 if(!pNd || !pNd->GetNodes().IsDocNodes())
300 return;
301 }
302 pGatherFieldsHint->m_rvFields.push_back(this);
303 }
304 else if (rHint.GetId() == SfxHintId::SwDocPosUpdate)
305 {
306 UpdateDocPos(static_cast<const sw::DocPosUpdate*>(&rHint)->m_nDocPos);
307 }
308}
309
310namespace
311{
312 bool lcl_ExpandField(const SwFieldIds eId, const bool bHiddenParaPrint)
313 {
314 switch(eId)
315 {
317 return !bHiddenParaPrint;
322 return false;
323 default:
324 return true;
325 }
326
327 };
328 bool lcl_TriggerNode(const SwFieldIds eId)
329 {
330 switch(eId)
331 {
337 return true;
338 default:
339 return false;
340 }
341 }
342 void lcl_EnsureUserFieldValid(SwFieldType& rType)
343 {
344 if(rType.Which() != SwFieldIds::User)
345 return;
346 static_cast<SwUserFieldType*>(&rType)->EnsureValid();
347 }
348 bool lcl_NeedsForcedUpdate(const SwField& rField)
349 {
350 if (rField.GetTyp()->Which() == SwFieldIds::DocInfo)
351 {
352 auto pDocInfoField = static_cast<const SwDocInfoField*>(&rField);
353 sal_uInt16 nSubType = pDocInfoField->GetSubType();
354 // Do not consider extended SubTypes.
355 nSubType &= 0xff;
356 switch (nSubType)
357 {
362 return false;
363 }
364 }
365 return true;
366 }
367}
368
370{
371 if (!IsFieldInDoc())
372 return;
373
374 SwTextNode* pTextNd = &mpTextField->GetTextNode();
375 OSL_ENSURE(pTextNd, "Where is my Node?");
376
377 auto pType = mpField->GetTyp();
378 lcl_EnsureUserFieldValid(*pType);
379 if(lcl_TriggerNode(pType->Which()))
380 pTextNd->TriggerNodeUpdate(sw::LegacyModifyHint(nullptr, nullptr));
381 if(!lcl_ExpandField(pType->Which(), false))
382 return;
383
384 // Force notify was added for conditional text fields,
385 // at least the below fields need no forced notify.
386 bool bNeedForced = lcl_NeedsForcedUpdate(*mpTextField->GetFormatField().GetField());
387 mpTextField->ExpandTextField(bNeedForced);
388}
390{
391 if (!IsFieldInDoc())
392 return;
393 auto pTextNd = &mpTextField->GetTextNode();
394
395 pTextNd->UpdateDocPos(nDocPos, mpTextField->GetStart());
396}
398{
399 if(SfxHintId::SwLegacyModify != rHint.GetId())
400 return;
401 auto pLegacy = static_cast<const sw::LegacyModifyHint*>(&rHint);
402 auto pOld = pLegacy->m_pOld;
403 auto pNew = pLegacy->m_pNew;
404 if (pOld == nullptr && pNew == nullptr)
405 {
407 return;
408 }
409 else if (pOld && (RES_REMOVE_UNO_OBJECT == pOld->Which()))
410 { // invalidate cached UNO object
411 m_wXTextField.clear();
412 // ??? why does this Modify method not already do this?
413 CallSwClientNotify(sw::LegacyModifyHint(pOld, pNew));
414 return;
415 }
416
417 if (!IsFieldInDoc())
418 return;
419
420 // don't do anything, especially not expand!
421 if( pNew && pNew->Which() == RES_OBJECTDYING )
422 return;
423
424 SwTextNode* pTextNd = &mpTextField->GetTextNode();
425 OSL_ENSURE(pTextNd, "Where is my Node?");
426
427 bool bTriggerNode = pNew != nullptr;
428 bool bExpand = false;
429 if(pNew)
430 {
431 switch(pNew->Which())
432 {
433 case RES_ATTRSET_CHG:
434 case RES_FMT_CHG:
435 break;
436 default:
437 {
438 auto pType = mpField->GetTyp();
439 lcl_EnsureUserFieldValid(*pType);
440 bTriggerNode = lcl_TriggerNode(pType->Which());
441 bExpand = lcl_ExpandField(pType->Which(), pOld && pOld->Which() == RES_HIDDENPARA_PRINT);
442 pOld = nullptr;
443 }
444 }
445 }
446 if(bTriggerNode)
447 pTextNd->TriggerNodeUpdate(sw::LegacyModifyHint(pOld, pNew));
448 if(bExpand)
450}
451
453{
454 if( RES_AUTOFMT_DOCNODE != rInfo.Which() || !mpTextField )
455 return true;
456 const SwTextNode* pTextNd = mpTextField->GetpTextNode();
457 return nullptr == pTextNd ||
458 &pTextNd->GetNodes() != static_cast<SwAutoFormatGetDocNode&>(rInfo).pNodes;
459}
460
462{
463 return mpTextField != nullptr
465}
466
468{
469 return mpTextField != nullptr
470 && mpTextField->GetpTextNode() != nullptr
472}
473
475{
476 (void)xmlTextWriterStartElement(pWriter, BAD_CAST("SwFormatField"));
477 (void)xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("ptr"), "%p", this);
478 (void)xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("mpTextField"), "%p", mpTextField);
479
480 SfxPoolItem::dumpAsXml(pWriter);
481 if (mpField) // pool default doesn't have one
482 {
483 mpField->dumpAsXml(pWriter);
484 }
485
486 (void)xmlTextWriterEndElement(pWriter);
487}
488
489// class SwTextField ////////////////////////////////////////////////////
490
492 SwFormatField & rAttr,
493 sal_Int32 const nStartPos,
494 bool const bInClipboard)
495 : SwTextAttr( rAttr, nStartPos )
496// fdo#39694 the ExpandField here may not give the correct result in all cases,
497// but is better than nothing
498 , m_aExpand( rAttr.GetField()->ExpandField(bInClipboard, nullptr) )
499 , m_pTextNode( nullptr )
500{
501 rAttr.SetTextField( *this );
502 SetHasDummyChar(true);
503}
504
506{
507 SwFormatField & rFormatField( static_cast<SwFormatField &>(GetAttr()) );
508 if ( this == rFormatField.GetTextField() )
509 {
510 rFormatField.ClearTextField();
511 }
512}
513
515{
516 return GetpTextNode() != nullptr
518}
519
520void SwTextField::ExpandTextField(const bool bForceNotify) const
521{
522 OSL_ENSURE( m_pTextNode, "SwTextField: where is my TextNode?" );
523
524 const SwField* pField = GetFormatField().GetField();
525 const OUString aNewExpand( pField->ExpandField(m_pTextNode->GetDoc().IsClipBoard(),
526 // can't do any better than this here...
528
529 const SwFieldIds nWhich = pField->GetTyp()->Which();
530 const bool bSameExpandSimpleNotification
531 = SwFieldIds::Chapter != nWhich && SwFieldIds::PageNumber != nWhich
532 && SwFieldIds::RefPageGet != nWhich
533 // Page count fields to not use aExpand during formatting,
534 // therefore an invalidation of the text frame has to be triggered even if aNewExpand == aExpand:
535 && (SwFieldIds::DocStat != nWhich
536 || DS_PAGE != static_cast<const SwDocStatField*>(pField)->GetSubType())
537 && (SwFieldIds::GetExp != nWhich
538 || static_cast<const SwGetExpField*>(pField)->IsInBodyText());
539
540 bool bHiddenParaChanged = false;
541 if (aNewExpand != m_aExpand || bSameExpandSimpleNotification)
542 bHiddenParaChanged = m_pTextNode->CalcHiddenParaField();
543
544 if (aNewExpand == m_aExpand)
545 {
546 if ( bSameExpandSimpleNotification )
547 {
548 if( bHiddenParaChanged )
550 if ( !bForceNotify )
551 {
552 // done, if no further notification forced.
553 return;
554 }
555 }
556 }
557 else
558 m_aExpand = aNewExpand;
559
560 const_cast<SwTextField*>(this)->NotifyContentChange( const_cast<SwFormatField&>(GetFormatField()) );
561}
562
564{
565 OSL_ENSURE( m_pTextNode, "SwTextField: where is my TextNode?" );
566 OSL_ENSURE( pDest->m_pTextNode, "SwTextField: where is pDest's TextNode?" );
567
570
571 SwFormatField& rDestFormatField = const_cast<SwFormatField&>(pDest->GetFormatField());
572 const SwFieldIds nFieldWhich = rDestFormatField.GetField()->GetTyp()->Which();
573
574 if( pIDFA != pDestIDFA )
575 {
576 // different documents, e.g. clipboard:
577 // register field type in target document
578 SwFieldType* pFieldType;
579 if( nFieldWhich != SwFieldIds::Database
580 && nFieldWhich != SwFieldIds::User
581 && nFieldWhich != SwFieldIds::SetExp
582 && nFieldWhich != SwFieldIds::Dde
583 && SwFieldIds::TableOfAuthorities != nFieldWhich )
584 {
585 pFieldType = pDestIDFA->GetSysFieldType( nFieldWhich );
586 }
587 else
588 {
589 pFieldType = pDestIDFA->InsertFieldType( *rDestFormatField.GetField()->GetTyp() );
590 }
591
592 // DDE fields need special treatment
593 if( SwFieldIds::Dde == nFieldWhich )
594 {
595 if( rDestFormatField.GetTextField() )
596 {
597 static_cast<SwDDEFieldType*>(rDestFormatField.GetField()->GetTyp())->DecRefCnt();
598 }
599 static_cast<SwDDEFieldType*>(pFieldType)->IncRefCnt();
600 }
601
602 OSL_ENSURE( pFieldType, "unknown FieldType" );
603 pFieldType->Add( &rDestFormatField ); // register at the field type
604 rDestFormatField.GetField()->ChgTyp( pFieldType );
605 }
606
607 // update expression fields
608 if( nFieldWhich == SwFieldIds::SetExp
609 || nFieldWhich == SwFieldIds::GetExp
610 || nFieldWhich == SwFieldIds::HiddenText )
611 {
612 SwTextField* pField = const_cast<SwTextField*>(this);
613 pDestIDFA->UpdateExpFields( pField, true );
614 }
615 // table fields: external display
616 else if( SwFieldIds::Table == nFieldWhich
617 && static_cast<SwTableField*>(rDestFormatField.GetField())->IsIntrnlName() )
618 {
619 // convert internal (core) to external (UI) formula
620 const SwTableNode* pTableNd = m_pTextNode->FindTableNode();
621 if( pTableNd ) // in a table?
622 static_cast<SwTableField*>(rDestFormatField.GetField())->PtrToBoxNm( &pTableNd->GetTable() );
623 }
624}
625
627{
628 //if not in undo section notify the change
630 m_pTextNode->TriggerNodeUpdate(sw::LegacyModifyHint(nullptr, &rFormatField));
631}
632
633/*static*/
635 const SwTextField& rTextField,
636 std::shared_ptr< SwPaM >& rPamForTextField )
637{
638 if (rTextField.GetpTextNode() == nullptr)
639 {
640 SAL_WARN("sw.core", "<SwTextField::GetPamForField> - missing <SwTextNode>");
641 return;
642 }
643
644 const SwTextNode& rTextNode = rTextField.GetTextNode();
645
646 rPamForTextField = std::make_shared<SwPaM>( rTextNode,
647 (rTextField.End() != nullptr) ? *(rTextField.End()) : ( rTextField.GetStart() + 1 ),
648 rTextNode,
649 rTextField.GetStart() );
650
651}
652
653/*static*/
655{
656 if (rTextField.GetpTextNode() != nullptr)
657 {
658 std::shared_ptr< SwPaM > pPamForTextField;
659 GetPamForTextField(rTextField, pPamForTextField);
660 if (pPamForTextField != nullptr)
661 {
662 rTextField.GetTextNode().GetDoc().getIDocumentContentOperations().DeleteAndJoin(*pPamForTextField);
663 }
664 }
665}
666
667// class SwTextInputField ///////////////////////////////////////////////
668
669// input field in-place editing
671 SwFormatField & rAttr,
672 sal_Int32 const nStart,
673 sal_Int32 const nEnd,
674 bool const bInClipboard )
675
676 : SwTextAttr( rAttr, nStart )
677 , SwTextAttrNesting( rAttr, nStart, nEnd )
678 , SwTextField( rAttr, nStart, bInClipboard )
679 , m_bLockNotifyContentChange( false )
680{
681 SetHasDummyChar( false );
682 SetHasContent( true );
683}
684
686{
687}
688
690{
692 {
693 return false;
694 }
696 return true;
697}
698
700{
702}
703
705{
707 {
709
710 SwTextField::NotifyContentChange( rFormatField );
712
714 }
715}
716
718{
719 return GetFormatField().GetField()->ExpandField(false, nullptr/*ignored anyway*/);
720}
721
723{
724 if ( !(IsFieldInDoc()
725 && GetStart() != (*End())) )
726 return;
727
728 assert( (*End()) - GetStart() >= 2 &&
729 "<SwTextInputField::UpdateFieldContent()> - Are CH_TXT_ATR_INPUTFIELDSTART and/or CH_TXT_ATR_INPUTFIELDEND missing?" );
730 // skip CH_TXT_ATR_INPUTFIELDSTART character
731 const sal_Int32 nIdx = GetStart() + 1;
732 // skip CH_TXT_ATR_INPUTFIELDEND character
733 const sal_Int32 nLen = static_cast<sal_Int32>(std::max<sal_Int32>( 0, ( (*End()) - 1 - nIdx ) ));
734 const OUString aNewFieldContent = GetTextNode().GetExpandText(nullptr, nIdx, nLen);
735
736 const SwField* pField = GetFormatField().GetField();
737 const SwInputField* pInputField = dynamic_cast<const SwInputField*>(pField);
738 if (pInputField)
739 const_cast<SwInputField*>(pInputField)->applyFieldContent( aNewFieldContent );
740
741 const SwSetExpField* pExpField = dynamic_cast<const SwSetExpField*>(pField);
742 if (pExpField)
743 {
744 assert(pExpField->GetInputFlag());
745 const_cast<SwSetExpField*>(pExpField)->SetPar2(aNewFieldContent);
746 }
747 assert(pInputField || pExpField);
748
749 // trigger update of fields for scenarios in which the Input Field's content is part of e.g. a table formula
751}
752
753void SwTextInputField::UpdateTextNodeContent( const OUString& rNewContent )
754{
755 assert(IsFieldInDoc() &&
756 "<SwTextInputField::UpdateTextNodeContent(..)> - misusage as Input Field is not in document content.");
757
758 assert( (*End()) - GetStart() >= 2 &&
759 "<SwTextInputField::UpdateTextNodeContent(..)> - Are CH_TXT_ATR_INPUTFIELDSTART and/or CH_TXT_ATR_INPUTFIELDEND missing?" );
760 // skip CH_TXT_ATR_INPUTFIELDSTART character
761 const sal_Int32 nIdx = GetStart() + 1;
762 // skip CH_TXT_ATR_INPUTFIELDEND character
763 const sal_Int32 nDelLen = std::max<sal_Int32>( 0, ( (*End()) - 1 - nIdx ) );
764 SwContentIndex aIdx( &GetTextNode(), nIdx );
765 GetTextNode().ReplaceText( aIdx, nDelLen, rNewContent );
766}
767
768// class SwTextAnnotationField //////////////////////////////////////////
769
770// text annotation field
772 SwFormatField & rAttr,
773 sal_Int32 const nStart,
774 bool const bInClipboard )
775 : SwTextAttr( rAttr, nStart )
776 , SwTextField( rAttr, nStart, bInClipboard )
777{
778}
779
781{
782}
783
785{
786 auto pPostItField = dynamic_cast<const SwPostItField*>(GetFormatField().GetField());
787 assert(pPostItField);
788
789 SwDoc& rDoc = static_cast<const SwPostItFieldType*>(pPostItField->GetTyp())->GetDoc();
790
791 IDocumentMarkAccess* pMarksAccess = rDoc.getIDocumentMarkAccess();
792 IDocumentMarkAccess::const_iterator_t pMark = pMarksAccess->findAnnotationMark( pPostItField->GetName() );
793 return pMark != pMarksAccess->getAnnotationMarksEnd()
794 ? *pMark
795 : nullptr;
796}
797
799{ m_wXTextField = xTextField.get(); }
800
801/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual bool DeleteAndJoin(SwPaM &, SwDeleteFlags flags=SwDeleteFlags::Default)=0
complete delete of a given PaM
virtual void DeleteRange(SwPaM &)=0
Delete a range SwFlyFrameFormat.
virtual bool InsertString(const SwPaM &rRg, const OUString &, const SwInsertFlags nInsertMode=SwInsertFlags::EMPTYEXPAND)=0
Insert string into existing text node at position rRg.Point().
Document fields related interfaces.
virtual SwFieldType * GetSysFieldType(const SwFieldIds eWhich) const =0
virtual SwFieldType * InsertFieldType(const SwFieldType &)=0
virtual SwDocUpdateField & GetUpdateFields() const =0
virtual void UpdateExpFields(SwTextField *pField, bool bUpdateRefFields)=0
virtual const SwRootFrame * GetCurrentLayout() const =0
wrapper iterator: wraps iterator of implementation while hiding MarkBase class; only IMark instances ...
Provides access to the marks of a document.
virtual const_iterator_t getAnnotationMarksEnd() const =0
virtual const_iterator_t findAnnotationMark(const OUString &rName) const =0
void Broadcast(const SfxHint &rHint)
SfxHintId GetId() const
virtual void dumpAsXml(xmlTextWriterPtr pWriter) const
sal_uInt16 Which() const
void SetWhich(sal_uInt16 nId)
virtual void SwClientNotify(const SwModify &, const SfxHint &rHint) override
Definition: calbck.cxx:120
Marks a character position inside a document model content node (SwContentNode)
virtual sal_uInt16 GetSubType() const override
Definition: docufld.cxx:1154
void SetFieldsDirty(bool b)
Definition: docfld.hxx:178
Definition: doc.hxx:197
bool IsClipBoard() const
Definition: doc.hxx:978
IDocumentContentOperations const & getIDocumentContentOperations() const
Definition: doc.cxx:329
IDocumentFieldsAccess const & getIDocumentFieldsAccess() const
Definition: doc.cxx:371
IDocumentLayoutAccess const & getIDocumentLayoutAccess() const
Definition: doc.cxx:419
IDocumentMarkAccess * getIDocumentMarkAccess()
Definition: docbm.cxx:1890
Instances of SwFields and those derived from it occur 0 to n times.
Definition: fldbas.hxx:247
SwFieldIds Which() const
Definition: fldbas.hxx:276
Base class of all fields.
Definition: fldbas.hxx:296
virtual sal_uInt16 GetSubType() const
Definition: fldbas.cxx:355
OUString ExpandField(bool bCached, SwRootFrame const *pLayout) const
expand the field.
Definition: fldbas.cxx:491
virtual SwFieldType * ChgTyp(SwFieldType *)
Set new type (used for copying among documents).
Definition: fldbas.cxx:415
SwFieldType * GetTyp() const
Definition: fldbas.hxx:402
void UpdateDocPos(const SwTwips nDocPos)
Definition: atrfld.cxx:389
SwFormatField(sal_uInt16 nWhich)
Definition: atrfld.cxx:48
bool IsFieldInDoc() const
Definition: atrfld.cxx:461
virtual bool operator==(const SfxPoolItem &) const override
"Pure virtual methods" of SfxPoolItem.
Definition: atrfld.cxx:200
const SwField * GetField() const
Definition: fmtfld.hxx:131
std::unique_ptr< SwField > mpField
Definition: fmtfld.hxx:109
bool IsProtect() const
Definition: atrfld.cxx:467
unotools::WeakReference< SwXTextField > m_wXTextField
Definition: fmtfld.hxx:107
virtual ~SwFormatField() override
Definition: atrfld.cxx:131
const SwTextField * GetTextField() const
Definition: fmtfld.hxx:149
void SetTextField(SwTextField &rTextField)
Definition: atrfld.cxx:190
void UpdateTextNode(const SfxHint &rHint)
Definition: atrfld.cxx:397
virtual SwFormatField * Clone(SfxItemPool *pPool=nullptr) const override
Definition: atrfld.cxx:211
void SetField(std::unique_ptr< SwField > pField)
Sets current field.
Definition: atrfld.cxx:175
void InvalidateField()
Definition: atrfld.cxx:216
virtual void SwClientNotify(const SwModify &rModify, const SfxHint &rHint) override
Definition: atrfld.cxx:222
virtual bool GetInfo(SfxPoolItem &rInfo) const override
Definition: atrfld.cxx:452
void RegisterToFieldType(SwFieldType &)
Definition: atrfld.cxx:170
SAL_DLLPRIVATE void SetXTextField(rtl::Reference< SwXTextField > const &xTextField)
Definition: atrfld.cxx:798
void ForceUpdateTextNode()
Definition: atrfld.cxx:369
SwTextField * mpTextField
Definition: fmtfld.hxx:110
void dumpAsXml(xmlTextWriterPtr pWriter) const override
Definition: atrfld.cxx:474
void ClearTextField()
Definition: atrfld.cxx:195
bool IsInBodyText() const
Called by formatting.
Definition: expfld.hxx:139
void SetFormatField(SwFormatField &rFormatField)
Definition: expfld.cxx:1230
bool IsProtect() const
Is node in something that is protected (range, frame, table cells ... including anchor in case of fra...
Definition: node.cxx:449
SwNodes & GetNodes()
Node is in which nodes-array/doc?
Definition: node.hxx:706
SwDoc & GetDoc()
Definition: node.hxx:233
SwTableNode * FindTableNode()
Search table node, in which it is.
Definition: node.cxx:380
const IDocumentFieldsAccess & getIDocumentFieldsAccess() const
Provides access to the document fields administration interface.
Definition: node.cxx:2147
bool IsDocNodes() const
Is the NodesArray the regular one of Doc? (and not the UndoNds, ...) Implementation in doc....
Definition: nodes.cxx:2555
PaM is Point and Mark: a selection of the document model.
Definition: pam.hxx:188
virtual void SetMark()
Unless this is called, the getter method of Mark will return Point.
Definition: pam.cxx:643
bool Move(SwMoveFnCollection const &fnMove=fnMoveForward, SwGoInDoc fnGo=GoInContent)
Movement of cursor.
Definition: pam.cxx:657
SwDoc & GetDoc() const
Definition: pam.hxx:291
void DeleteMark()
Definition: pam.hxx:232
const SwPosition * GetPoint() const
Definition: pam.hxx:253
sal_uInt16 GetType() const
Definition: expfld.hxx:198
void SetFormatField(SwFormatField &rFormatField)
Definition: expfld.cxx:824
bool GetInputFlag() const
Definition: expfld.hxx:269
bool IsIntrnlName() const
Definition: cellfml.hxx:131
const SwTable & GetTable() const
Definition: node.hxx:542
::sw::mark::IMark * GetAnnotationMark() const
Definition: atrfld.cxx:784
virtual ~SwTextAnnotationField() override
Definition: atrfld.cxx:780
SwTextAnnotationField(SwFormatField &rAttr, sal_Int32 const nStart, bool const bInClipboard)
Definition: atrfld.cxx:771
A wrapper around SfxPoolItem to store the start position of (usually) a text portion,...
Definition: txatbase.hxx:44
const SfxPoolItem & GetAttr() const
Definition: txatbase.hxx:167
const sal_Int32 * End() const
Definition: txatbase.hxx:156
sal_Int32 GetStart() const
Definition: txatbase.hxx:88
void SetHasContent(const bool bFlag)
Definition: txatbase.hxx:79
void SetHasDummyChar(const bool bFlag)
Definition: txatbase.hxx:78
const SwFormatField & GetFormatField() const
Definition: txatbase.hxx:199
void CopyTextField(SwTextField *pDest) const
Definition: atrfld.cxx:563
SwTextNode & GetTextNode() const
Definition: txtfld.hxx:53
void ExpandTextField(const bool bForceNotify=false) const
Definition: atrfld.cxx:520
virtual ~SwTextField() override
Definition: atrfld.cxx:505
bool IsFieldInDoc() const
Definition: atrfld.cxx:514
SwTextNode * m_pTextNode
Definition: txtfld.hxx:34
OUString m_aExpand
Definition: txtfld.hxx:33
virtual void NotifyContentChange(SwFormatField &rFormatField)
Definition: atrfld.cxx:626
SwTextNode * GetpTextNode() const
Definition: txtfld.hxx:49
static void DeleteTextField(const SwTextField &rTextField)
Definition: atrfld.cxx:654
SwTextField(SwFormatField &rAttr, sal_Int32 const nStart, bool const bInClipboard)
Definition: atrfld.cxx:491
static void GetPamForTextField(const SwTextField &rTextField, std::shared_ptr< SwPaM > &rPamForTextField)
Definition: atrfld.cxx:634
bool m_bLockNotifyContentChange
Definition: txtfld.hxx:101
void UpdateTextNodeContent(const OUString &rNewContent)
Definition: atrfld.cxx:753
OUString GetFieldContent() const
Definition: atrfld.cxx:717
void UnlockNotifyContentChange()
Definition: atrfld.cxx:699
SwTextInputField(SwFormatField &rAttr, sal_Int32 const nStart, sal_Int32 const nEnd, bool const bInClipboard)
Definition: atrfld.cxx:670
void UpdateFieldContent()
Definition: atrfld.cxx:722
virtual ~SwTextInputField() override
Definition: atrfld.cxx:685
virtual void NotifyContentChange(SwFormatField &rFormatField) override
Definition: atrfld.cxx:704
bool LockNotifyContentChange()
Definition: atrfld.cxx:689
SwTextNode is a paragraph in the document model.
Definition: ndtxt.hxx:112
OUString GetExpandText(SwRootFrame const *pLayout, const sal_Int32 nIdx=0, const sal_Int32 nLen=-1, const bool bWithNum=false, const bool bAddSpaceAfterListLabelStr=false, const bool bWithSpacesForLevel=false, const ExpandMode eAdditionalMode=ExpandMode::ExpandFootnote|ExpandMode::HideFieldmarkCommands) const
add 4th optional parameter <bAddSpaceAfterListLabelStr> indicating, when <bWithNum = true> that a spa...
Definition: ndtxt.cxx:3505
bool CalcHiddenParaField()
Hidden Paragraph Field:
Definition: ndtxt.hxx:762
void UpdateDocPos(const SwTwips nDocPos, const sal_uInt32 nIndex)
Definition: ndtxt.cxx:5443
void ReplaceText(const SwContentIndex &rStart, const sal_Int32 nDelLen, const OUString &rText)
replace nDelLen characters at rStart with rText in case the replacement does not fit,...
Definition: ndtxt.cxx:3808
void TriggerNodeUpdate(const sw::LegacyModifyHint &)
for hanging TextFormatCollections somewhere else (Outline-Numbering!)
Definition: ndtxt.cxx:5449
The shared part of a user field.
Definition: usrfld.hxx:35
DocPosUpdate is sent to signal that only the frames from or to a specified document-global position h...
Definition: hints.hxx:146
struct _xmlTextWriter * xmlTextWriterPtr
@ DS_PAGE
Definition: docufld.hxx:54
SwFieldIds
Definition: fldbas.hxx:49
@ Database
For old documents the Field-Which IDs must be preserved !!!
@ TableOfAuthorities
constexpr TypedWhichId< SwPtrMsgPoolItem > RES_REMOVE_UNO_OBJECT(181)
constexpr TypedWhichId< SwMsgPoolItem > RES_HIDDENPARA_PRINT(178)
constexpr TypedWhichId< SwAttrSetChg > RES_ATTRSET_CHG(169)
constexpr TypedWhichId< SwFormatField > RES_TXTATR_ANNOTATION(60)
constexpr TypedWhichId< SwFormatField > RES_TXTATR_FIELD(RES_TXTATR_NOEND_BEGIN)
constexpr TypedWhichId< SwFormatField > RES_TXTATR_INPUTFIELD(55)
constexpr TypedWhichId< SwAutoFormatGetDocNode > RES_AUTOFMT_DOCNODE(176)
constexpr TypedWhichId< SwPtrMsgPoolItem > RES_OBJECTDYING(RES_FORMAT_MSG_BEGIN)
constexpr TypedWhichId< SwFormatChg > RES_FMT_CHG(168)
#define SAL_WARN(area, stream)
const SwDocInfoSubType DI_CUSTOM
Definition: docufld.hxx:80
const SwDocInfoSubType DI_CHANGE
Definition: docufld.hxx:76
const SwDocInfoSubType DI_SUBJECT
Definition: docufld.hxx:72
const SwDocInfoSubType DI_TITLE
Definition: docufld.hxx:71
const SwGetSetExpType GSE_STRING
String.
Definition: fldbas.hxx:207
bool IsFieldDeletedInModel(IDocumentRedlineAccess const &rIDRA, SwTextField const &rTextField)
SwMoveFnCollection const & fnMoveForward
SwPam::Move()/Find() default argument.
Definition: paminit.cxx:61
void Assign(const SwNode &rNd, SwNodeOffset nDelta, sal_Int32 nContentOffset=0)
These all set both nNode and nContent.
Definition: pam.cxx:231
std::vector< SwFormatField * > & m_rvFormatFields
Definition: fmtfld.hxx:58
SwFormatField *& m_rpFormat
Definition: fmtfld.hxx:47
std::vector< SwNodeOffset > & m_rvNodeIndex
Definition: fmtfld.hxx:72
const SfxPoolItem * m_pOld
Definition: calbck.hxx:77
tools::Long SwTwips
Definition: swtypes.hxx:51