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 
31 #include <pam.hxx>
32 #include <reffld.hxx>
33 #include <ddefld.hxx>
34 #include <usrfld.hxx>
35 #include <expfld.hxx>
36 #include <ndtxt.hxx>
37 #include <calc.hxx>
38 #include <hints.hxx>
40 #include <IDocumentMarkAccess.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
48 SwFormatField::SwFormatField( sal_uInt16 nWhich )
49  : SfxPoolItem( nWhich )
50  , SfxBroadcaster()
51  , mpTextField( nullptr )
52 {
53 }
54 
57  , SfxBroadcaster()
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 )
95  , SfxBroadcaster()
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 
152  case SwFieldIds::SetExp:
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 
175 void 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 
200 bool 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 
222 void SwFormatField::SwClientNotify( const SwModify& rModify, const SfxHint& rHint )
223 {
224  SwClient::SwClientNotify(rModify, rHint);
225  if (const auto pFieldHint = dynamic_cast<const SwFieldHint*>( &rHint ))
226  {
227  // replace field content by text
228  SwPaM* pPaM = pFieldHint->m_pPaM;
229  pPaM->DeleteMark(); // TODO: this is really hackish
230 
231  if( !mpTextField )
232  return;
233 
234  SwDoc& rDoc = pPaM->GetDoc();
235  const SwTextNode& rTextNode = mpTextField->GetTextNode();
236  pPaM->GetPoint()->nNode = rTextNode;
237  pPaM->GetPoint()->nContent.Assign( const_cast<SwTextNode*>(&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  } else if (rHint.GetId() == SfxHintId::SwLegacyModify)
245  {
246  auto pLegacyHint = static_cast<const sw::LegacyModifyHint*>(&rHint);
247  if( !mpTextField )
248  return;
249  UpdateTextNode(pLegacyHint->m_pOld, pLegacyHint->m_pNew);
250  } else if (const auto pFindForFieldHint = dynamic_cast<const sw::FindFormatForFieldHint*>( &rHint ))
251  {
252  if(pFindForFieldHint->m_rpFormat == nullptr && pFindForFieldHint->m_pField == GetField())
253  pFindForFieldHint->m_rpFormat = this;
254  } else if (const auto pFindForPostItIdHint = dynamic_cast<const sw::FindFormatForPostItIdHint*>( &rHint ))
255  {
256  auto pPostItField = dynamic_cast<SwPostItField*>(mpField.get());
257  if(pPostItField && pFindForPostItIdHint->m_rpFormat == nullptr && pFindForPostItIdHint->m_nPostItId == pPostItField->GetPostItId())
258  pFindForPostItIdHint->m_rpFormat = this;
259  } else if (const auto pCollectPostItsHint = dynamic_cast<const sw::CollectPostItsHint*>( &rHint ))
260  {
261  if(GetTextField() && IsFieldInDoc() && (!pCollectPostItsHint->m_bHideRedlines || !sw::IsFieldDeletedInModel(pCollectPostItsHint->m_rIDRA, *GetTextField())))
262  pCollectPostItsHint->m_rvFormatFields.push_back(this);
263  } else if (const auto pHasHiddenInfoHint = dynamic_cast<const sw::HasHiddenInformationNotesHint*>( &rHint ))
264  {
265  if(!pHasHiddenInfoHint->m_rbHasHiddenInformationNotes && GetTextField() && IsFieldInDoc())
266  pHasHiddenInfoHint->m_rbHasHiddenInformationNotes = true;
267  } else if (const auto pGatherNodeIndexHint = dynamic_cast<const sw::GatherNodeIndexHint*>( &rHint ))
268  {
269  if(auto pTextField = GetTextField())
270  pGatherNodeIndexHint->m_rvNodeIndex.push_back(pTextField->GetTextNode().GetIndex());
271  } else if (const auto pGatherRefFieldsHint = dynamic_cast<const sw::GatherRefFieldsHint*>( &rHint ))
272  {
273  if(!GetTextField() || pGatherRefFieldsHint->m_nType != GetField()->GetSubType())
274  return;
276  if(pNd && pNd->GetNodes().IsDocNodes())
277  pGatherRefFieldsHint->m_rvRFields.push_back(static_cast<SwGetRefField*>(GetField()));
278  } else if (const auto pGatherFieldsHint = dynamic_cast<const sw::GatherFieldsHint*>( &rHint ))
279  {
280  if(pGatherFieldsHint->m_bCollectOnlyInDocNodes)
281  {
282  if(!GetTextField())
283  return;
285  if(!pNd || !pNd->GetNodes().IsDocNodes())
286  return;
287  }
288  pGatherFieldsHint->m_rvFields.push_back(this);
289  }
290 }
291 
293 {
294  if (pOld && (RES_REMOVE_UNO_OBJECT == pOld->Which()))
295  { // invalidate cached UNO object
296  m_wXTextField = nullptr;
297  // ??? why does this Modify method not already do this?
299  return;
300  }
301 
302  if( !mpTextField )
303  return;
304 
305  // don't do anything, especially not expand!
306  if( pNew && pNew->Which() == RES_OBJECTDYING )
307  return;
308 
309  SwTextNode* pTextNd = &mpTextField->GetTextNode();
310  OSL_ENSURE( pTextNd, "Where is my Node?" );
311 
312  bool bTriggerNode = false;
313  bool bExpand = false;
314  const SfxPoolItem* pNodeOld = nullptr;
315  const SfxPoolItem* pNodeNew = nullptr;
316  if(pNew)
317  {
318  switch(pNew->Which())
319  {
321  // update GetRef fields
322  if( SwFieldIds::GetRef == mpField->GetTyp()->Which() )
323  {
324  // #i81002#
325  static_cast<SwGetRefField*>(mpField.get())->UpdateField( mpTextField );
326  }
327  break;
328  case RES_DOCPOS_UPDATE:
329  // handled in SwTextFrame::Modify()
330  bTriggerNode = true;
331  pNodeOld = pNew;
332  pNodeNew = this;
333  break;
334  case RES_ATTRSET_CHG:
335  case RES_FMT_CHG:
336  bTriggerNode = true;
337  pNodeOld = pOld;
338  pNodeNew = pNew;
339  break;
340  default:
341  break;
342  }
343  }
344  if(!bTriggerNode)
345  {
346  switch (mpField->GetTyp()->Which())
347  {
349  if( !pOld || pOld->Which() != RES_HIDDENPARA_PRINT ) {
350  bExpand =true;
351  break;
352  }
353  [[fallthrough]];
358  bTriggerNode = true;
359  pNodeNew = pNew;
360  break;
361  case SwFieldIds::User:
362  {
363  SwUserFieldType* pType = static_cast<SwUserFieldType*>(mpField->GetTyp());
364  if(!pType->IsValid())
365  {
366  SwCalc aCalc( pTextNd->GetDoc() );
367  pType->GetValue( aCalc );
368  }
369  bExpand = true;
370  }
371  break;
372  default:
373  bExpand = true;
374  break;
375  }
376  }
377  if(bTriggerNode)
378  pTextNd->TriggerNodeUpdate(sw::LegacyModifyHint(pNodeOld, pNodeNew));
379  if(bExpand)
380  {
381  bool bForceNotify = pOld == nullptr && pNew == nullptr;
382  if (bForceNotify)
383  {
384  // Force notify was added for conditional text fields, at least the below fields need
385  // no forced notify.
386  const SwField* pField = mpTextField->GetFormatField().GetField();
387  const SwFieldIds nWhich = pField->GetTyp()->Which();
388  if (nWhich == SwFieldIds::DocInfo)
389  {
390  auto pDocInfoField = static_cast<const SwDocInfoField*>(pField);
391  sal_uInt16 nSubType = pDocInfoField->GetSubType();
392  // Do not consider extended SubTypes.
393  nSubType &= 0xff;
394  switch (nSubType)
395  {
400  bForceNotify = false;
401  break;
402  }
403  }
404  }
405 
406  mpTextField->ExpandTextField(bForceNotify);
407  }
408 }
409 
411 {
412  if( RES_AUTOFMT_DOCNODE != rInfo.Which() || !mpTextField )
413  return true;
414  const SwTextNode* pTextNd = mpTextField->GetpTextNode();
415  return nullptr == pTextNd ||
416  &pTextNd->GetNodes() != static_cast<SwAutoFormatGetDocNode&>(rInfo).pNodes;
417 }
418 
420 {
421  return mpTextField != nullptr
423 }
424 
426 {
427  return mpTextField != nullptr
428  && mpTextField->GetpTextNode() != nullptr
430 }
431 
433 {
434  (void)xmlTextWriterStartElement(pWriter, BAD_CAST("SwFormatField"));
435  (void)xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("ptr"), "%p", this);
436  (void)xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("mpTextField"), "%p", mpTextField);
437 
438  SfxPoolItem::dumpAsXml(pWriter);
439  if (mpField) // pool default doesn't have one
440  {
441  mpField->dumpAsXml(pWriter);
442  }
443 
444  (void)xmlTextWriterEndElement(pWriter);
445 }
446 
447 // class SwTextField ////////////////////////////////////////////////////
448 
450  SwFormatField & rAttr,
451  sal_Int32 const nStartPos,
452  bool const bInClipboard)
453  : SwTextAttr( rAttr, nStartPos )
454 // fdo#39694 the ExpandField here may not give the correct result in all cases,
455 // but is better than nothing
456  , m_aExpand( rAttr.GetField()->ExpandField(bInClipboard, nullptr) )
457  , m_pTextNode( nullptr )
458 {
459  rAttr.SetTextField( *this );
460  SetHasDummyChar(true);
461 }
462 
464 {
465  SwFormatField & rFormatField( static_cast<SwFormatField &>(GetAttr()) );
466  if ( this == rFormatField.GetTextField() )
467  {
468  rFormatField.ClearTextField();
469  }
470 }
471 
473 {
474  return GetpTextNode() != nullptr
475  && GetpTextNode()->GetNodes().IsDocNodes();
476 }
477 
478 void SwTextField::ExpandTextField(const bool bForceNotify) const
479 {
480  OSL_ENSURE( m_pTextNode, "SwTextField: where is my TextNode?" );
481 
482  const SwField* pField = GetFormatField().GetField();
483  const OUString aNewExpand( pField->ExpandField(m_pTextNode->GetDoc().IsClipBoard(),
484  // can't do any better than this here...
486 
487  const SwFieldIds nWhich = pField->GetTyp()->Which();
488  const bool bSameExpandSimpleNotification
489  = SwFieldIds::Chapter != nWhich && SwFieldIds::PageNumber != nWhich
490  && SwFieldIds::RefPageGet != nWhich
491  // Page count fields to not use aExpand during formatting,
492  // therefore an invalidation of the text frame has to be triggered even if aNewExpand == aExpand:
493  && (SwFieldIds::DocStat != nWhich
494  || DS_PAGE != static_cast<const SwDocStatField*>(pField)->GetSubType())
495  && (SwFieldIds::GetExp != nWhich
496  || static_cast<const SwGetExpField*>(pField)->IsInBodyText());
497 
498  bool bHiddenParaChanged = false;
499  if (aNewExpand != m_aExpand || bSameExpandSimpleNotification)
500  bHiddenParaChanged = m_pTextNode->CalcHiddenParaField();
501 
502  if (aNewExpand == m_aExpand)
503  {
504  if ( bSameExpandSimpleNotification )
505  {
506  if( bHiddenParaChanged )
508  if ( !bForceNotify )
509  {
510  // done, if no further notification forced.
511  return;
512  }
513  }
514  }
515  else
516  m_aExpand = aNewExpand;
517 
518  const_cast<SwTextField*>(this)->NotifyContentChange( const_cast<SwFormatField&>(GetFormatField()) );
519 }
520 
522 {
523  OSL_ENSURE( m_pTextNode, "SwTextField: where is my TextNode?" );
524  OSL_ENSURE( pDest->m_pTextNode, "SwTextField: where is pDest's TextNode?" );
525 
528 
529  SwFormatField& rDestFormatField = const_cast<SwFormatField&>(pDest->GetFormatField());
530  const SwFieldIds nFieldWhich = rDestFormatField.GetField()->GetTyp()->Which();
531 
532  if( pIDFA != pDestIDFA )
533  {
534  // different documents, e.g. clipboard:
535  // register field type in target document
536  SwFieldType* pFieldType;
537  if( nFieldWhich != SwFieldIds::Database
538  && nFieldWhich != SwFieldIds::User
539  && nFieldWhich != SwFieldIds::SetExp
540  && nFieldWhich != SwFieldIds::Dde
541  && SwFieldIds::TableOfAuthorities != nFieldWhich )
542  {
543  pFieldType = pDestIDFA->GetSysFieldType( nFieldWhich );
544  }
545  else
546  {
547  pFieldType = pDestIDFA->InsertFieldType( *rDestFormatField.GetField()->GetTyp() );
548  }
549 
550  // DDE fields need special treatment
551  if( SwFieldIds::Dde == nFieldWhich )
552  {
553  if( rDestFormatField.GetTextField() )
554  {
555  static_cast<SwDDEFieldType*>(rDestFormatField.GetField()->GetTyp())->DecRefCnt();
556  }
557  static_cast<SwDDEFieldType*>(pFieldType)->IncRefCnt();
558  }
559 
560  OSL_ENSURE( pFieldType, "unknown FieldType" );
561  pFieldType->Add( &rDestFormatField ); // register at the field type
562  rDestFormatField.GetField()->ChgTyp( pFieldType );
563  }
564 
565  // update expression fields
566  if( nFieldWhich == SwFieldIds::SetExp
567  || nFieldWhich == SwFieldIds::GetExp
568  || nFieldWhich == SwFieldIds::HiddenText )
569  {
570  SwTextField* pField = const_cast<SwTextField*>(this);
571  pDestIDFA->UpdateExpFields( pField, true );
572  }
573  // table fields: external display
574  else if( SwFieldIds::Table == nFieldWhich
575  && static_cast<SwTableField*>(rDestFormatField.GetField())->IsIntrnlName() )
576  {
577  // convert internal (core) to external (UI) formula
578  const SwTableNode* pTableNd = m_pTextNode->FindTableNode();
579  if( pTableNd ) // in a table?
580  static_cast<SwTableField*>(rDestFormatField.GetField())->PtrToBoxNm( &pTableNd->GetTable() );
581  }
582 }
583 
585 {
586  //if not in undo section notify the change
588  m_pTextNode->TriggerNodeUpdate(sw::LegacyModifyHint(nullptr, &rFormatField));
589 }
590 
591 /*static*/
593  const SwTextField& rTextField,
594  std::shared_ptr< SwPaM >& rPamForTextField )
595 {
596  if (rTextField.GetpTextNode() == nullptr)
597  {
598  SAL_WARN("sw.core", "<SwTextField::GetPamForField> - missing <SwTextNode>");
599  return;
600  }
601 
602  const SwTextNode& rTextNode = rTextField.GetTextNode();
603 
604  rPamForTextField = std::make_shared<SwPaM>( rTextNode,
605  (rTextField.End() != nullptr) ? *(rTextField.End()) : ( rTextField.GetStart() + 1 ),
606  rTextNode,
607  rTextField.GetStart() );
608 
609 }
610 
611 /*static*/
612 void SwTextField::DeleteTextField( const SwTextField& rTextField )
613 {
614  if (rTextField.GetpTextNode() != nullptr)
615  {
616  std::shared_ptr< SwPaM > pPamForTextField;
617  GetPamForTextField(rTextField, pPamForTextField);
618  if (pPamForTextField != nullptr)
619  {
620  rTextField.GetTextNode().GetDoc().getIDocumentContentOperations().DeleteAndJoin(*pPamForTextField);
621  }
622  }
623 }
624 
625 // class SwTextInputField ///////////////////////////////////////////////
626 
627 // input field in-place editing
629  SwFormatField & rAttr,
630  sal_Int32 const nStart,
631  sal_Int32 const nEnd,
632  bool const bInClipboard )
633 
634  : SwTextAttr( rAttr, nStart )
635  , SwTextAttrNesting( rAttr, nStart, nEnd )
636  , SwTextField( rAttr, nStart, bInClipboard )
637  , m_bLockNotifyContentChange( false )
638 {
639  SetHasDummyChar( false );
640  SetHasContent( true );
641 }
642 
644 {
645 }
646 
648 {
650  {
651  return false;
652  }
654  return true;
655 }
656 
658 {
660 }
661 
663 {
665  {
667 
668  SwTextField::NotifyContentChange( rFormatField );
670 
672  }
673 }
674 
676 {
677  return GetFormatField().GetField()->ExpandField(false, nullptr/*ignored anyway*/);
678 }
679 
681 {
682  if ( !(IsFieldInDoc()
683  && GetStart() != (*End())) )
684  return;
685 
686  assert( (*End()) - GetStart() >= 2 &&
687  "<SwTextInputField::UpdateFieldContent()> - Are CH_TXT_ATR_INPUTFIELDSTART and/or CH_TXT_ATR_INPUTFIELDEND missing?" );
688  // skip CH_TXT_ATR_INPUTFIELDSTART character
689  const sal_Int32 nIdx = GetStart() + 1;
690  // skip CH_TXT_ATR_INPUTFIELDEND character
691  const sal_Int32 nLen = static_cast<sal_Int32>(std::max<sal_Int32>( 0, ( (*End()) - 1 - nIdx ) ));
692  const OUString aNewFieldContent = GetTextNode().GetExpandText(nullptr, nIdx, nLen);
693 
694  const SwField* pField = GetFormatField().GetField();
695  const SwInputField* pInputField = dynamic_cast<const SwInputField*>(pField);
696  if (pInputField)
697  const_cast<SwInputField*>(pInputField)->applyFieldContent( aNewFieldContent );
698 
699  const SwSetExpField* pExpField = dynamic_cast<const SwSetExpField*>(pField);
700  if (pExpField)
701  {
702  assert(pExpField->GetInputFlag());
703  const_cast<SwSetExpField*>(pExpField)->SetPar2(aNewFieldContent);
704  }
705  assert(pInputField || pExpField);
706 
707  // trigger update of fields for scenarios in which the Input Field's content is part of e.g. a table formula
709 }
710 
711 void SwTextInputField::UpdateTextNodeContent( const OUString& rNewContent )
712 {
713  assert(IsFieldInDoc() &&
714  "<SwTextInputField::UpdateTextNodeContent(..)> - misusage as Input Field is not in document content.");
715 
716  assert( (*End()) - GetStart() >= 2 &&
717  "<SwTextInputField::UpdateTextNodeContent(..)> - Are CH_TXT_ATR_INPUTFIELDSTART and/or CH_TXT_ATR_INPUTFIELDEND missing?" );
718  // skip CH_TXT_ATR_INPUTFIELDSTART character
719  const sal_Int32 nIdx = GetStart() + 1;
720  // skip CH_TXT_ATR_INPUTFIELDEND character
721  const sal_Int32 nDelLen = std::max<sal_Int32>( 0, ( (*End()) - 1 - nIdx ) );
722  SwIndex aIdx( &GetTextNode(), nIdx );
723  GetTextNode().ReplaceText( aIdx, nDelLen, rNewContent );
724 }
725 
726 // class SwTextAnnotationField //////////////////////////////////////////
727 
728 // text annotation field
730  SwFormatField & rAttr,
731  sal_Int32 const nStart,
732  bool const bInClipboard )
733  : SwTextAttr( rAttr, nStart )
734  , SwTextField( rAttr, nStart, bInClipboard )
735 {
736 }
737 
739 {
740 }
741 
743 {
744  auto pPostItField = dynamic_cast<const SwPostItField*>(GetFormatField().GetField());
745  assert(pPostItField);
746 
747  SwDoc& rDoc = static_cast<const SwPostItFieldType*>(pPostItField->GetTyp())->GetDoc();
748 
749  IDocumentMarkAccess* pMarksAccess = rDoc.getIDocumentMarkAccess();
750  IDocumentMarkAccess::const_iterator_t pMark = pMarksAccess->findAnnotationMark( pPostItField->GetName() );
751  return pMark != pMarksAccess->getAnnotationMarksEnd()
752  ? *pMark
753  : nullptr;
754 }
755 
756 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Instances of SwFields and those derived from it occur 0 to n times.
Definition: fldbas.hxx:240
virtual bool operator==(const SfxPoolItem &) const override
"Pure virtual methods" of SfxPoolItem.
Definition: atrfld.cxx:200
void DeleteMark()
Definition: pam.hxx:177
Definition: calc.hxx:192
SwTextField * mpTextField
Definition: fmtfld.hxx:89
void Add(SwClient *pDepend)
Definition: calbck.cxx:173
OUString m_aExpand
Definition: txtfld.hxx:33
The shared part of a user field.
Definition: usrfld.hxx:34
const SwField * GetField() const
Definition: fmtfld.hxx:110
void SetTextField(SwTextField &rTextField)
Definition: atrfld.cxx:190
virtual const_iterator_t getAnnotationMarksEnd() const =0
virtual const SwRootFrame * GetCurrentLayout() const =0
constexpr TypedWhichId< SwFormatChg > RES_FMT_CHG(162)
bool IsProtect() const
Definition: atrfld.cxx:425
void SetHasDummyChar(const bool bFlag)
Definition: txatbase.hxx:76
constexpr TypedWhichId< SwPtrMsgPoolItem > RES_REMOVE_UNO_OBJECT(181)
void TriggerNodeUpdate(const sw::LegacyModifyHint &)
for hanging TextFormatCollections somewhere else (Outline-Numbering!)
Definition: ndtxt.cxx:5228
SwNodeIndex nNode
Definition: pam.hxx:37
wrapper iterator: wraps iterator of implementation while hiding MarkBase class; only IMark instances ...
Base class of all fields.
Definition: fldbas.hxx:289
Provides access to the marks of a document.
Definition: doc.hxx:188
SwTextNode * m_pTextNode
Definition: txtfld.hxx:34
virtual void DeleteRange(SwPaM &)=0
Delete a range SwFlyFrameFormat.
SwTextNode * GetpTextNode() const
Definition: txtfld.hxx:49
virtual ~SwTextInputField() override
Definition: atrfld.cxx:643
IDocumentMarkAccess * getIDocumentMarkAccess()
Definition: docbm.cxx:1794
virtual void SwClientNotify(const SwModify &, const SfxHint &rHint) override
Definition: calbck.cxx:121
virtual bool DeleteAndJoin(SwPaM &, const bool bForceJoinNext=false)=0
complete delete of a given PaM
SwClient * Remove(SwClient *pDepend)
Definition: calbck.cxx:226
void InvalidateField()
Definition: atrfld.cxx:216
virtual bool GetInfo(SfxPoolItem &rInfo) const override
Definition: atrfld.cxx:410
IDocumentContentOperations const & getIDocumentContentOperations() const
Definition: doc.cxx:315
constexpr TypedWhichId< SwFormatField > RES_TXTATR_ANNOTATION(59)
For old documents the Field-Which IDs must be preserved !!!
SfxHintId GetId() const
virtual void UpdateExpFields(SwTextField *pField, bool bUpdateRefFields)=0
IDocumentFieldsAccess const & getIDocumentFieldsAccess() const
Definition: doc.cxx:357
constexpr TypedWhichId< SwDocPosUpdate > RES_DOCPOS_UPDATE(169)
SwIndex nContent
Definition: pam.hxx:38
const SwTextField * GetTextField() const
Definition: fmtfld.hxx:128
A wrapper around SfxPoolItem to store the start position of (usually) a text portion, with an optional end.
Definition: txatbase.hxx:41
virtual sal_uInt16 GetSubType() const override
Definition: docufld.cxx:1133
const SwDocInfoSubType DI_SUBJECT
Definition: docufld.hxx:71
bool CalcHiddenParaField()
Hidden Paragraph Field:
Definition: ndtxt.hxx:714
sal_Int32 GetStart() const
Definition: txatbase.hxx:86
virtual void NotifyContentChange(SwFormatField &rFormatField) override
Definition: atrfld.cxx:662
void SetField(std::unique_ptr< SwField > pField)
Sets current field.
Definition: atrfld.cxx:175
const SwTable & GetTable() const
Definition: node.hxx:499
void CopyTextField(SwTextField *pDest) const
Definition: atrfld.cxx:521
const SwFormatField & GetFormatField() const
Definition: txatbase.hxx:195
bool HasOnlyOneListener() const
Definition: calbck.hxx:198
virtual const_iterator_t findAnnotationMark(const OUString &rName) const =0
const IDocumentFieldsAccess & getIDocumentFieldsAccess() const
Provides access to the document fields administration interface.
Definition: node.cxx:2102
void ExpandTextField(const bool bForceNotify=false) const
Definition: atrfld.cxx:478
const SwDocInfoSubType DI_CUSTOM
Definition: docufld.hxx:79
virtual void SwClientNotify(const SwModify &rModify, const SfxHint &rHint) override
Definition: atrfld.cxx:222
virtual ~SwTextField() override
Definition: atrfld.cxx:463
virtual SwFieldType * ChgTyp(SwFieldType *)
Set new type (used for copying among documents).
Definition: fldbas.cxx:383
PaM is Point and Mark: a selection of the document model.
Definition: pam.hxx:136
SwTextField(SwFormatField &rAttr, sal_Int32 const nStart, bool const bInClipboard)
Definition: atrfld.cxx:449
struct _xmlTextWriter * xmlTextWriterPtr
bool Move(SwMoveFnCollection const &fnMove=fnMoveForward, SwGoInDoc fnGo=GoInContent)
Movement of cursor.
Definition: pam.cxx:504
OUString GetFieldContent() const
Definition: atrfld.cxx:675
virtual bool InsertString(const SwPaM &rRg, const OUString &, const SwInsertFlags nInsertMode=SwInsertFlags::EMPTYEXPAND)=0
Insert string into existing text node at position rRg.Point().
constexpr TypedWhichId< SwFormatField > RES_TXTATR_FIELD(RES_TXTATR_NOEND_BEGIN)
::sw::mark::IMark * GetAnnotationMark() const
Definition: atrfld.cxx:742
SwDoc & GetDoc()
Definition: node.hxx:212
const SwPosition * GetPoint() const
Definition: pam.hxx:207
bool IsFieldInDoc() const
Definition: atrfld.cxx:472
SwIndex & Assign(SwIndexReg *, sal_Int32)
Definition: index.cxx:206
Document fields related interfaces.
SwFormatField(sal_uInt16 nWhich)
Definition: atrfld.cxx:48
SwFieldIds
Definition: fldbas.hxx:44
std::unique_ptr< SwField > mpField
Definition: fmtfld.hxx:88
constexpr TypedWhichId< SwAttrSetChg > RES_ATTRSET_CHG(163)
Marks a character position inside a document model node.
Definition: index.hxx:33
constexpr TypedWhichId< SwAutoFormatGetDocNode > RES_AUTOFMT_DOCNODE(173)
double GetValue(SwCalc &rCalc)
Definition: usrfld.cxx:235
SwNodes & GetNodes()
Node is in which nodes-array/doc?
Definition: node.hxx:694
bool IsProtect() const
Is node in something that is protected (range, frame, table cells ...
Definition: node.cxx:426
constexpr TypedWhichId< SwRefMarkFieldUpdate > RES_REFMARKFLD_UPDATE(168)
virtual sal_uInt16 GetSubType() const
Definition: fldbas.cxx:337
void RegisterToFieldType(SwFieldType &)
Definition: atrfld.cxx:170
bool m_bLockNotifyContentChange
Definition: txtfld.hxx:101
IDocumentLayoutAccess const & getIDocumentLayoutAccess() const
Definition: doc.cxx:405
void ClearTextField()
Definition: atrfld.cxx:195
void SetHasContent(const bool bFlag)
Definition: txatbase.hxx:77
SwFieldType * GetTyp() const
Definition: fldbas.hxx:392
bool GetInputFlag() const
Definition: expfld.hxx:264
void SetFormatField(SwFormatField &rFormatField)
Definition: expfld.cxx:831
bool IsFieldInDoc() const
Definition: atrfld.cxx:419
bool IsValid() const
Definition: usrfld.hxx:78
SwTextNode is a paragraph in the document model.
Definition: ndtxt.hxx:79
void Broadcast(const SfxHint &rHint)
virtual ~SwFormatField() override
Definition: atrfld.cxx:131
OUString ExpandField(bool bCached, SwRootFrame const *pLayout) const
expand the field.
Definition: fldbas.cxx:465
SwTextAnnotationField(SwFormatField &rAttr, sal_Int32 const nStart, bool const bInClipboard)
Definition: atrfld.cxx:729
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) const
add 4th optional parameter indicating, when that a spa...
Definition: ndtxt.cxx:3359
void SetFieldsDirty(bool b)
Definition: docfld.hxx:164
bool IsFieldDeletedInModel(IDocumentRedlineAccess const &rIDRA, SwTextField const &rTextField)
void ReplaceText(const SwIndex &rStart, const sal_Int32 nDelLen, const OUString &rText)
replace nDelLen characters at rStart with rText in case the replacement does not fit, it is partially inserted up to the capacity of the node
Definition: ndtxt.cxx:3660
virtual SwFieldType * InsertFieldType(const SwFieldType &)=0
SwMoveFnCollection const & fnMoveForward
SwPam::Move()/Find() default argument.
Definition: paminit.cxx:59
virtual void NotifyContentChange(SwFormatField &rFormatField)
Definition: atrfld.cxx:584
void SetWhich(sal_uInt16 nId)
bool IsClipBoard() const
Definition: doc.hxx:963
virtual SwDocUpdateField & GetUpdateFields() const =0
css::uno::WeakReference< css::text::XTextField > m_wXTextField
Definition: fmtfld.hxx:86
bool LockNotifyContentChange()
Definition: atrfld.cxx:647
const sal_Int32 * End() const
Definition: txatbase.hxx:152
constexpr TypedWhichId< SwFormatField > RES_TXTATR_INPUTFIELD(55)
virtual void CallSwClientNotify(const SfxHint &rHint) const override
Definition: calbck.cxx:326
SwTableNode * FindTableNode()
Search table node, in which it is.
Definition: node.cxx:357
const SfxPoolItem & GetAttr() const
Definition: txatbase.hxx:163
void UnlockNotifyContentChange()
Definition: atrfld.cxx:657
#define SAL_WARN(area, stream)
bool IsDocNodes() const
Is the NodesArray the regular one of Doc? (and not the UndoNds, ...) Implementation in doc...
Definition: nodes.cxx:2329
const SwGetSetExpType GSE_STRING
String.
Definition: fldbas.hxx:202
SwDoc & GetDoc() const
Definition: pam.hxx:243
virtual SwFieldType * GetSysFieldType(const SwFieldIds eWhich) const =0
constexpr TypedWhichId< SwMsgPoolItem > RES_HIDDENPARA_PRINT(178)
void UpdateTextNode(const SfxPoolItem *pOld, const SfxPoolItem *pNew)
Definition: atrfld.cxx:292
const SwDocInfoSubType DI_CHANGE
Definition: docufld.hxx:75
void UpdateTextNodeContent(const OUString &rNewContent)
Definition: atrfld.cxx:711
virtual void SetMark()
Unless this is called, the getter method of Mark will return Point.
Definition: pam.cxx:478
virtual ~SwTextAnnotationField() override
Definition: atrfld.cxx:738
SwTextNode & GetTextNode() const
Definition: txtfld.hxx:53
const SwDocInfoSubType DI_TITLE
Definition: docufld.hxx:70
void dumpAsXml(xmlTextWriterPtr pWriter) const override
Definition: atrfld.cxx:432
SwTextInputField(SwFormatField &rAttr, sal_Int32 const nStart, sal_Int32 const nEnd, bool const bInClipboard)
Definition: atrfld.cxx:628
SwFieldIds Which() const
Definition: fldbas.hxx:272
static void GetPamForTextField(const SwTextField &rTextField, std::shared_ptr< SwPaM > &rPamForTextField)
Definition: atrfld.cxx:592
void SetFormatField(SwFormatField &rFormatField)
Definition: expfld.cxx:1238
sal_uInt16 Which() const
constexpr TypedWhichId< SwPtrMsgPoolItem > RES_OBJECTDYING(RES_MSG_BEGIN)
virtual SwFormatField * Clone(SfxItemPool *pPool=nullptr) const override
Definition: atrfld.cxx:211
void UpdateFieldContent()
Definition: atrfld.cxx:680
static void DeleteTextField(const SwTextField &rTextField)
Definition: atrfld.cxx:612
virtual void dumpAsXml(xmlTextWriterPtr pWriter) const
typedef void(CALLTYPE *GetFuncDataPtr)(sal_uInt16 &nNo