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 (const auto pLegacyHint = dynamic_cast<const sw::LegacyModifyHint*>( &rHint ))
245  {
246  if( !mpTextField )
247  return;
248  UpdateTextNode(pLegacyHint->m_pOld, pLegacyHint->m_pNew);
249  } else if (const auto pFindForFieldHint = dynamic_cast<const sw::FindFormatForFieldHint*>( &rHint ))
250  {
251  if(pFindForFieldHint->m_rpFormat == nullptr && pFindForFieldHint->m_pField == GetField())
252  pFindForFieldHint->m_rpFormat = this;
253  } else if (const auto pFindForPostItIdHint = dynamic_cast<const sw::FindFormatForPostItIdHint*>( &rHint ))
254  {
255  auto pPostItField = dynamic_cast<SwPostItField*>(mpField.get());
256  if(pPostItField && pFindForPostItIdHint->m_rpFormat == nullptr && pFindForPostItIdHint->m_nPostItId == pPostItField->GetPostItId())
257  pFindForPostItIdHint->m_rpFormat = this;
258  } else if (const auto pCollectPostItsHint = dynamic_cast<const sw::CollectPostItsHint*>( &rHint ))
259  {
260  if(GetTextField() && IsFieldInDoc() && (!pCollectPostItsHint->m_bHideRedlines || !sw::IsFieldDeletedInModel(pCollectPostItsHint->m_rIDRA, *GetTextField())))
261  pCollectPostItsHint->m_rvFormatFields.push_back(this);
262  } else if (const auto pHasHiddenInfoHint = dynamic_cast<const sw::HasHiddenInformationNotesHint*>( &rHint ))
263  {
264  if(!pHasHiddenInfoHint->m_rbHasHiddenInformationNotes && GetTextField() && IsFieldInDoc())
265  pHasHiddenInfoHint->m_rbHasHiddenInformationNotes = true;
266  } else if (const auto pGatherNodeIndexHint = dynamic_cast<const sw::GatherNodeIndexHint*>( &rHint ))
267  {
268  if(auto pTextField = GetTextField())
269  pGatherNodeIndexHint->m_rvNodeIndex.push_back(pTextField->GetTextNode().GetIndex());
270  } else if (const auto pGatherRefFieldsHint = dynamic_cast<const sw::GatherRefFieldsHint*>( &rHint ))
271  {
272  if(!GetTextField() || pGatherRefFieldsHint->m_nType != GetField()->GetSubType())
273  return;
275  if(pNd && pNd->GetNodes().IsDocNodes())
276  pGatherRefFieldsHint->m_rvRFields.push_back(static_cast<SwGetRefField*>(GetField()));
277  } else if (const auto pGatherFieldsHint = dynamic_cast<const sw::GatherFieldsHint*>( &rHint ))
278  {
279  if(pGatherFieldsHint->m_bCollectOnlyInDocNodes)
280  {
281  if(!GetTextField())
282  return;
284  if(!pNd || !pNd->GetNodes().IsDocNodes())
285  return;
286  }
287  pGatherFieldsHint->m_rvFields.push_back(this);
288  }
289 }
290 
292 {
293  if (pOld && (RES_REMOVE_UNO_OBJECT == pOld->Which()))
294  { // invalidate cached UNO object
295  m_wXTextField = nullptr;
296  // ??? why does this Modify method not already do this?
298  return;
299  }
300 
301  if( !mpTextField )
302  return;
303 
304  // don't do anything, especially not expand!
305  if( pNew && pNew->Which() == RES_OBJECTDYING )
306  return;
307 
308  SwTextNode* pTextNd = &mpTextField->GetTextNode();
309  OSL_ENSURE( pTextNd, "Where is my Node?" );
310 
311  bool bTriggerNode = false;
312  bool bExpand = false;
313  const SfxPoolItem* pNodeOld = nullptr;
314  const SfxPoolItem* pNodeNew = nullptr;
315  if(pNew)
316  {
317  switch(pNew->Which())
318  {
320  // update GetRef fields
321  if( SwFieldIds::GetRef == mpField->GetTyp()->Which() )
322  {
323  // #i81002#
324  static_cast<SwGetRefField*>(mpField.get())->UpdateField( mpTextField );
325  }
326  break;
327  case RES_DOCPOS_UPDATE:
328  // handled in SwTextFrame::Modify()
329  bTriggerNode = true;
330  pNodeOld = pNew;
331  pNodeNew = this;
332  break;
333  case RES_ATTRSET_CHG:
334  case RES_FMT_CHG:
335  bTriggerNode = true;
336  pNodeOld = pOld;
337  pNodeNew = pNew;
338  break;
339  default:
340  break;
341  }
342  }
343  if(!bTriggerNode)
344  {
345  switch (mpField->GetTyp()->Which())
346  {
348  if( !pOld || pOld->Which() != RES_HIDDENPARA_PRINT ) {
349  bExpand =true;
350  break;
351  }
352  [[fallthrough]];
357  bTriggerNode = true;
358  pNodeNew = pNew;
359  break;
360  case SwFieldIds::User:
361  {
362  SwUserFieldType* pType = static_cast<SwUserFieldType*>(mpField->GetTyp());
363  if(!pType->IsValid())
364  {
365  SwCalc aCalc( pTextNd->GetDoc() );
366  pType->GetValue( aCalc );
367  }
368  bExpand = true;
369  }
370  break;
371  default:
372  bExpand = true;
373  break;
374  }
375  }
376  if(bTriggerNode)
377  pTextNd->TriggerNodeUpdate(sw::LegacyModifyHint(pNodeOld, pNodeNew));
378  if(bExpand)
379  {
380  mpTextField->ExpandTextField( pOld == nullptr && pNew == nullptr );
381  }
382 }
383 
385 {
386  if( RES_AUTOFMT_DOCNODE != rInfo.Which() || !mpTextField )
387  return true;
388  const SwTextNode* pTextNd = mpTextField->GetpTextNode();
389  return nullptr == pTextNd ||
390  &pTextNd->GetNodes() != static_cast<SwAutoFormatGetDocNode&>(rInfo).pNodes;
391 }
392 
394 {
395  return mpTextField != nullptr
397 }
398 
400 {
401  return mpTextField != nullptr
402  && mpTextField->GetpTextNode() != nullptr
404 }
405 
407 {
408  (void)xmlTextWriterStartElement(pWriter, BAD_CAST("SwFormatField"));
409  (void)xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("ptr"), "%p", this);
410  (void)xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("mpTextField"), "%p", mpTextField);
411 
412  SfxPoolItem::dumpAsXml(pWriter);
413  if (mpField) // pool default doesn't have one
414  {
415  mpField->dumpAsXml(pWriter);
416  }
417 
418  (void)xmlTextWriterEndElement(pWriter);
419 }
420 
421 // class SwTextField ////////////////////////////////////////////////////
422 
424  SwFormatField & rAttr,
425  sal_Int32 const nStartPos,
426  bool const bInClipboard)
427  : SwTextAttr( rAttr, nStartPos )
428 // fdo#39694 the ExpandField here may not give the correct result in all cases,
429 // but is better than nothing
430  , m_aExpand( rAttr.GetField()->ExpandField(bInClipboard, nullptr) )
431  , m_pTextNode( nullptr )
432 {
433  rAttr.SetTextField( *this );
434  SetHasDummyChar(true);
435 }
436 
438 {
439  SwFormatField & rFormatField( static_cast<SwFormatField &>(GetAttr()) );
440  if ( this == rFormatField.GetTextField() )
441  {
442  rFormatField.ClearTextField();
443  }
444 }
445 
447 {
448  return GetpTextNode() != nullptr
449  && GetpTextNode()->GetNodes().IsDocNodes();
450 }
451 
452 void SwTextField::ExpandTextField(const bool bForceNotify) const
453 {
454  OSL_ENSURE( m_pTextNode, "SwTextField: where is my TextNode?" );
455 
456  const SwField* pField = GetFormatField().GetField();
457  const OUString aNewExpand( pField->ExpandField(m_pTextNode->GetDoc().IsClipBoard(),
458  // can't do any better than this here...
460 
461  const SwFieldIds nWhich = pField->GetTyp()->Which();
462  const bool bSameExpandSimpleNotification
463  = SwFieldIds::Chapter != nWhich && SwFieldIds::PageNumber != nWhich
464  && SwFieldIds::RefPageGet != nWhich
465  // Page count fields to not use aExpand during formatting,
466  // therefore an invalidation of the text frame has to be triggered even if aNewExpand == aExpand:
467  && (SwFieldIds::DocStat != nWhich
468  || DS_PAGE != static_cast<const SwDocStatField*>(pField)->GetSubType())
469  && (SwFieldIds::GetExp != nWhich
470  || static_cast<const SwGetExpField*>(pField)->IsInBodyText());
471 
472  bool bHiddenParaChanged = false;
473  if (aNewExpand != m_aExpand || bSameExpandSimpleNotification)
474  bHiddenParaChanged = m_pTextNode->CalcHiddenParaField();
475 
476  if (aNewExpand == m_aExpand)
477  {
478  if ( bSameExpandSimpleNotification )
479  {
480  if( bHiddenParaChanged )
482  if ( !bForceNotify )
483  {
484  // done, if no further notification forced.
485  return;
486  }
487  }
488  }
489  else
490  m_aExpand = aNewExpand;
491 
492  const_cast<SwTextField*>(this)->NotifyContentChange( const_cast<SwFormatField&>(GetFormatField()) );
493 }
494 
496 {
497  OSL_ENSURE( m_pTextNode, "SwTextField: where is my TextNode?" );
498  OSL_ENSURE( pDest->m_pTextNode, "SwTextField: where is pDest's TextNode?" );
499 
502 
503  SwFormatField& rDestFormatField = const_cast<SwFormatField&>(pDest->GetFormatField());
504  const SwFieldIds nFieldWhich = rDestFormatField.GetField()->GetTyp()->Which();
505 
506  if( pIDFA != pDestIDFA )
507  {
508  // different documents, e.g. clipboard:
509  // register field type in target document
510  SwFieldType* pFieldType;
511  if( nFieldWhich != SwFieldIds::Database
512  && nFieldWhich != SwFieldIds::User
513  && nFieldWhich != SwFieldIds::SetExp
514  && nFieldWhich != SwFieldIds::Dde
515  && SwFieldIds::TableOfAuthorities != nFieldWhich )
516  {
517  pFieldType = pDestIDFA->GetSysFieldType( nFieldWhich );
518  }
519  else
520  {
521  pFieldType = pDestIDFA->InsertFieldType( *rDestFormatField.GetField()->GetTyp() );
522  }
523 
524  // DDE fields need special treatment
525  if( SwFieldIds::Dde == nFieldWhich )
526  {
527  if( rDestFormatField.GetTextField() )
528  {
529  static_cast<SwDDEFieldType*>(rDestFormatField.GetField()->GetTyp())->DecRefCnt();
530  }
531  static_cast<SwDDEFieldType*>(pFieldType)->IncRefCnt();
532  }
533 
534  OSL_ENSURE( pFieldType, "unknown FieldType" );
535  pFieldType->Add( &rDestFormatField ); // register at the field type
536  rDestFormatField.GetField()->ChgTyp( pFieldType );
537  }
538 
539  // update expression fields
540  if( nFieldWhich == SwFieldIds::SetExp
541  || nFieldWhich == SwFieldIds::GetExp
542  || nFieldWhich == SwFieldIds::HiddenText )
543  {
544  SwTextField* pField = const_cast<SwTextField*>(this);
545  pDestIDFA->UpdateExpFields( pField, true );
546  }
547  // table fields: external display
548  else if( SwFieldIds::Table == nFieldWhich
549  && static_cast<SwTableField*>(rDestFormatField.GetField())->IsIntrnlName() )
550  {
551  // convert internal (core) to external (UI) formula
552  const SwTableNode* pTableNd = m_pTextNode->FindTableNode();
553  if( pTableNd ) // in a table?
554  static_cast<SwTableField*>(rDestFormatField.GetField())->PtrToBoxNm( &pTableNd->GetTable() );
555  }
556 }
557 
559 {
560  //if not in undo section notify the change
562  m_pTextNode->TriggerNodeUpdate(sw::LegacyModifyHint(nullptr, &rFormatField));
563 }
564 
565 /*static*/
567  const SwTextField& rTextField,
568  std::shared_ptr< SwPaM >& rPamForTextField )
569 {
570  if (rTextField.GetpTextNode() == nullptr)
571  {
572  SAL_WARN("sw.core", "<SwTextField::GetPamForField> - missing <SwTextNode>");
573  return;
574  }
575 
576  const SwTextNode& rTextNode = rTextField.GetTextNode();
577 
578  rPamForTextField = std::make_shared<SwPaM>( rTextNode,
579  (rTextField.End() != nullptr) ? *(rTextField.End()) : ( rTextField.GetStart() + 1 ),
580  rTextNode,
581  rTextField.GetStart() );
582 
583 }
584 
585 /*static*/
586 void SwTextField::DeleteTextField( const SwTextField& rTextField )
587 {
588  if (rTextField.GetpTextNode() != nullptr)
589  {
590  std::shared_ptr< SwPaM > pPamForTextField;
591  GetPamForTextField(rTextField, pPamForTextField);
592  if (pPamForTextField != nullptr)
593  {
594  rTextField.GetTextNode().GetDoc().getIDocumentContentOperations().DeleteAndJoin(*pPamForTextField);
595  }
596  }
597 }
598 
599 // class SwTextInputField ///////////////////////////////////////////////
600 
601 // input field in-place editing
603  SwFormatField & rAttr,
604  sal_Int32 const nStart,
605  sal_Int32 const nEnd,
606  bool const bInClipboard )
607 
608  : SwTextAttr( rAttr, nStart )
609  , SwTextAttrNesting( rAttr, nStart, nEnd )
610  , SwTextField( rAttr, nStart, bInClipboard )
611  , m_bLockNotifyContentChange( false )
612 {
613  SetHasDummyChar( false );
614  SetHasContent( true );
615 }
616 
618 {
619 }
620 
622 {
624  {
625  return false;
626  }
628  return true;
629 }
630 
632 {
634 }
635 
637 {
639  {
641 
642  SwTextField::NotifyContentChange( rFormatField );
644 
646  }
647 }
648 
650 {
651  return GetFormatField().GetField()->ExpandField(false, nullptr/*ignored anyway*/);
652 }
653 
655 {
656  if ( !(IsFieldInDoc()
657  && GetStart() != (*End())) )
658  return;
659 
660  assert( (*End()) - GetStart() >= 2 &&
661  "<SwTextInputField::UpdateFieldContent()> - Are CH_TXT_ATR_INPUTFIELDSTART and/or CH_TXT_ATR_INPUTFIELDEND missing?" );
662  // skip CH_TXT_ATR_INPUTFIELDSTART character
663  const sal_Int32 nIdx = GetStart() + 1;
664  // skip CH_TXT_ATR_INPUTFIELDEND character
665  const sal_Int32 nLen = static_cast<sal_Int32>(std::max<sal_Int32>( 0, ( (*End()) - 1 - nIdx ) ));
666  const OUString aNewFieldContent = GetTextNode().GetExpandText(nullptr, nIdx, nLen);
667 
668  const SwField* pField = GetFormatField().GetField();
669  const SwInputField* pInputField = dynamic_cast<const SwInputField*>(pField);
670  if (pInputField)
671  const_cast<SwInputField*>(pInputField)->applyFieldContent( aNewFieldContent );
672 
673  const SwSetExpField* pExpField = dynamic_cast<const SwSetExpField*>(pField);
674  if (pExpField)
675  {
676  assert(pExpField->GetInputFlag());
677  const_cast<SwSetExpField*>(pExpField)->SetPar2(aNewFieldContent);
678  }
679  assert(pInputField || pExpField);
680 
681  // trigger update of fields for scenarios in which the Input Field's content is part of e.g. a table formula
683 }
684 
685 void SwTextInputField::UpdateTextNodeContent( const OUString& rNewContent )
686 {
687  assert(IsFieldInDoc() &&
688  "<SwTextInputField::UpdateTextNodeContent(..)> - misusage as Input Field is not in document content.");
689 
690  assert( (*End()) - GetStart() >= 2 &&
691  "<SwTextInputField::UpdateTextNodeContent(..)> - Are CH_TXT_ATR_INPUTFIELDSTART and/or CH_TXT_ATR_INPUTFIELDEND missing?" );
692  // skip CH_TXT_ATR_INPUTFIELDSTART character
693  const sal_Int32 nIdx = GetStart() + 1;
694  // skip CH_TXT_ATR_INPUTFIELDEND character
695  const sal_Int32 nDelLen = std::max<sal_Int32>( 0, ( (*End()) - 1 - nIdx ) );
696  SwIndex aIdx( &GetTextNode(), nIdx );
697  GetTextNode().ReplaceText( aIdx, nDelLen, rNewContent );
698 }
699 
700 // class SwTextAnnotationField //////////////////////////////////////////
701 
702 // text annotation field
704  SwFormatField & rAttr,
705  sal_Int32 const nStart,
706  bool const bInClipboard )
707  : SwTextAttr( rAttr, nStart )
708  , SwTextField( rAttr, nStart, bInClipboard )
709 {
710 }
711 
713 {
714 }
715 
717 {
718  auto pPostItField = dynamic_cast<const SwPostItField*>(GetFormatField().GetField());
719  assert(pPostItField);
720 
721  SwDoc& rDoc = static_cast<const SwPostItFieldType*>(pPostItField->GetTyp())->GetDoc();
722 
723  IDocumentMarkAccess* pMarksAccess = rDoc.getIDocumentMarkAccess();
724  IDocumentMarkAccess::const_iterator_t pMark = pMarksAccess->findAnnotationMark( pPostItField->GetName() );
725  return pMark != pMarksAccess->getAnnotationMarksEnd()
726  ? *pMark
727  : nullptr;
728 }
729 
730 /* 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:191
SwTextField * mpTextField
Definition: fmtfld.hxx:89
void Add(SwClient *pDepend)
Definition: calbck.cxx:171
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:399
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:5267
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:187
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:617
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:224
void InvalidateField()
Definition: atrfld.cxx:216
virtual bool GetInfo(SfxPoolItem &rInfo) const override
Definition: atrfld.cxx:384
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 !!!
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 BorderLinePrimitive2D *pCandidateB assert(pCandidateA)
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
bool CalcHiddenParaField()
Hidden Paragraph Field:
Definition: ndtxt.hxx:709
sal_Int32 GetStart() const
Definition: txatbase.hxx:86
virtual void NotifyContentChange(SwFormatField &rFormatField) override
Definition: atrfld.cxx:636
void SetField(std::unique_ptr< SwField > pField)
Sets current field.
Definition: atrfld.cxx:175
const SwTable & GetTable() const
Definition: node.hxx:501
void CopyTextField(SwTextField *pDest) const
Definition: atrfld.cxx:495
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:2101
void ExpandTextField(const bool bForceNotify=false) const
Definition: atrfld.cxx:452
virtual void SwClientNotify(const SwModify &rModify, const SfxHint &rHint) override
Definition: atrfld.cxx:222
virtual ~SwTextField() override
Definition: atrfld.cxx:437
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:423
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:649
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:716
SwDoc & GetDoc()
Definition: node.hxx:212
const SwPosition * GetPoint() const
Definition: pam.hxx:207
bool IsFieldInDoc() const
Definition: atrfld.cxx:446
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:232
SwNodes & GetNodes()
Node is in which nodes-array/doc?
Definition: node.hxx:697
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:829
bool IsFieldInDoc() const
Definition: atrfld.cxx:393
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:703
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:3374
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:3675
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:558
void SetWhich(sal_uInt16 nId)
bool IsClipBoard() const
Definition: doc.hxx:964
virtual SwDocUpdateField & GetUpdateFields() const =0
css::uno::WeakReference< css::text::XTextField > m_wXTextField
Definition: fmtfld.hxx:86
bool LockNotifyContentChange()
Definition: atrfld.cxx:621
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:324
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:631
#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:291
void UpdateTextNodeContent(const OUString &rNewContent)
Definition: atrfld.cxx:685
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:712
SwTextNode & GetTextNode() const
Definition: txtfld.hxx:53
void dumpAsXml(xmlTextWriterPtr pWriter) const override
Definition: atrfld.cxx:406
SwTextInputField(SwFormatField &rAttr, sal_Int32 const nStart, sal_Int32 const nEnd, bool const bInClipboard)
Definition: atrfld.cxx:602
SwFieldIds Which() const
Definition: fldbas.hxx:272
static void GetPamForTextField(const SwTextField &rTextField, std::shared_ptr< SwPaM > &rPamForTextField)
Definition: atrfld.cxx:566
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:654
static void DeleteTextField(const SwTextField &rTextField)
Definition: atrfld.cxx:586
virtual void dumpAsXml(xmlTextWriterPtr pWriter) const
typedef void(CALLTYPE *GetFuncDataPtr)(sal_uInt16 &nNo