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?
297  NotifyClients(pOld, pNew);
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  xmlTextWriterStartElement(pWriter, BAD_CAST("SwFormatField"));
409  xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("ptr"), "%p", this);
410  xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("mpTextField"), "%p", mpTextField);
411 
412  SfxPoolItem::dumpAsXml(pWriter);
413  mpField->dumpAsXml(pWriter);
414 
415  xmlTextWriterEndElement(pWriter);
416 }
417 
418 // class SwTextField ////////////////////////////////////////////////////
419 
421  SwFormatField & rAttr,
422  sal_Int32 const nStartPos,
423  bool const bInClipboard)
424  : SwTextAttr( rAttr, nStartPos )
425 // fdo#39694 the ExpandField here may not give the correct result in all cases,
426 // but is better than nothing
427  , m_aExpand( rAttr.GetField()->ExpandField(bInClipboard, nullptr) )
428  , m_pTextNode( nullptr )
429 {
430  rAttr.SetTextField( *this );
431  SetHasDummyChar(true);
432 }
433 
435 {
436  SwFormatField & rFormatField( static_cast<SwFormatField &>(GetAttr()) );
437  if ( this == rFormatField.GetTextField() )
438  {
439  rFormatField.ClearTextField();
440  }
441 }
442 
444 {
445  return GetpTextNode() != nullptr
446  && GetpTextNode()->GetNodes().IsDocNodes();
447 }
448 
449 void SwTextField::ExpandTextField(const bool bForceNotify) const
450 {
451  OSL_ENSURE( m_pTextNode, "SwTextField: where is my TextNode?" );
452 
453  const SwField* pField = GetFormatField().GetField();
454  const OUString aNewExpand( pField->ExpandField(m_pTextNode->GetDoc().IsClipBoard(),
455  // can't do any better than this here...
457 
458  const SwFieldIds nWhich = pField->GetTyp()->Which();
459  const bool bSameExpandSimpleNotification
460  = SwFieldIds::Chapter != nWhich && SwFieldIds::PageNumber != nWhich
461  && SwFieldIds::RefPageGet != nWhich
462  // Page count fields to not use aExpand during formatting,
463  // therefore an invalidation of the text frame has to be triggered even if aNewExpand == aExpand:
464  && (SwFieldIds::DocStat != nWhich
465  || DS_PAGE != static_cast<const SwDocStatField*>(pField)->GetSubType())
466  && (SwFieldIds::GetExp != nWhich
467  || static_cast<const SwGetExpField*>(pField)->IsInBodyText());
468 
469  bool bHiddenParaChanged = false;
470  if (aNewExpand != m_aExpand || bSameExpandSimpleNotification)
471  bHiddenParaChanged = m_pTextNode->CalcHiddenParaField();
472 
473  if (aNewExpand == m_aExpand)
474  {
475  if ( bSameExpandSimpleNotification )
476  {
477  if( bHiddenParaChanged )
479  if ( !bForceNotify )
480  {
481  // done, if no further notification forced.
482  return;
483  }
484  }
485  }
486  else
487  m_aExpand = aNewExpand;
488 
489  const_cast<SwTextField*>(this)->NotifyContentChange( const_cast<SwFormatField&>(GetFormatField()) );
490 }
491 
493 {
494  OSL_ENSURE( m_pTextNode, "SwTextField: where is my TextNode?" );
495  OSL_ENSURE( pDest->m_pTextNode, "SwTextField: where is pDest's TextNode?" );
496 
499 
500  SwFormatField& rDestFormatField = const_cast<SwFormatField&>(pDest->GetFormatField());
501  const SwFieldIds nFieldWhich = rDestFormatField.GetField()->GetTyp()->Which();
502 
503  if( pIDFA != pDestIDFA )
504  {
505  // different documents, e.g. clipboard:
506  // register field type in target document
507  SwFieldType* pFieldType;
508  if( nFieldWhich != SwFieldIds::Database
509  && nFieldWhich != SwFieldIds::User
510  && nFieldWhich != SwFieldIds::SetExp
511  && nFieldWhich != SwFieldIds::Dde
512  && SwFieldIds::TableOfAuthorities != nFieldWhich )
513  {
514  pFieldType = pDestIDFA->GetSysFieldType( nFieldWhich );
515  }
516  else
517  {
518  pFieldType = pDestIDFA->InsertFieldType( *rDestFormatField.GetField()->GetTyp() );
519  }
520 
521  // DDE fields need special treatment
522  if( SwFieldIds::Dde == nFieldWhich )
523  {
524  if( rDestFormatField.GetTextField() )
525  {
526  static_cast<SwDDEFieldType*>(rDestFormatField.GetField()->GetTyp())->DecRefCnt();
527  }
528  static_cast<SwDDEFieldType*>(pFieldType)->IncRefCnt();
529  }
530 
531  OSL_ENSURE( pFieldType, "unknown FieldType" );
532  pFieldType->Add( &rDestFormatField ); // register at the field type
533  rDestFormatField.GetField()->ChgTyp( pFieldType );
534  }
535 
536  // update expression fields
537  if( nFieldWhich == SwFieldIds::SetExp
538  || nFieldWhich == SwFieldIds::GetExp
539  || nFieldWhich == SwFieldIds::HiddenText )
540  {
541  SwTextField* pField = const_cast<SwTextField*>(this);
542  pDestIDFA->UpdateExpFields( pField, true );
543  }
544  // table fields: external display
545  else if( SwFieldIds::Table == nFieldWhich
546  && static_cast<SwTableField*>(rDestFormatField.GetField())->IsIntrnlName() )
547  {
548  // convert internal (core) to external (UI) formula
549  const SwTableNode* pTableNd = m_pTextNode->FindTableNode();
550  if( pTableNd ) // in a table?
551  static_cast<SwTableField*>(rDestFormatField.GetField())->PtrToBoxNm( &pTableNd->GetTable() );
552  }
553 }
554 
556 {
557  //if not in undo section notify the change
559  m_pTextNode->TriggerNodeUpdate(sw::LegacyModifyHint(nullptr, &rFormatField));
560 }
561 
562 /*static*/
564  const SwTextField& rTextField,
565  std::shared_ptr< SwPaM >& rPamForTextField )
566 {
567  if (rTextField.GetpTextNode() == nullptr)
568  {
569  SAL_WARN("sw.core", "<SwTextField::GetPamForField> - missing <SwTextNode>");
570  return;
571  }
572 
573  const SwTextNode& rTextNode = rTextField.GetTextNode();
574 
575  rPamForTextField = std::make_shared<SwPaM>( rTextNode,
576  (rTextField.End() != nullptr) ? *(rTextField.End()) : ( rTextField.GetStart() + 1 ),
577  rTextNode,
578  rTextField.GetStart() );
579 
580 }
581 
582 /*static*/
583 void SwTextField::DeleteTextField( const SwTextField& rTextField )
584 {
585  if (rTextField.GetpTextNode() != nullptr)
586  {
587  std::shared_ptr< SwPaM > pPamForTextField;
588  GetPamForTextField(rTextField, pPamForTextField);
589  if (pPamForTextField != nullptr)
590  {
591  rTextField.GetTextNode().GetDoc().getIDocumentContentOperations().DeleteAndJoin(*pPamForTextField);
592  }
593  }
594 }
595 
596 // class SwTextInputField ///////////////////////////////////////////////
597 
598 // input field in-place editing
600  SwFormatField & rAttr,
601  sal_Int32 const nStart,
602  sal_Int32 const nEnd,
603  bool const bInClipboard )
604 
605  : SwTextAttr( rAttr, nStart )
606  , SwTextAttrNesting( rAttr, nStart, nEnd )
607  , SwTextField( rAttr, nStart, bInClipboard )
608  , m_bLockNotifyContentChange( false )
609 {
610  SetHasDummyChar( false );
611  SetHasContent( true );
612 }
613 
615 {
616 }
617 
619 {
621  {
622  return false;
623  }
625  return true;
626 }
627 
629 {
631 }
632 
634 {
636  {
638 
639  SwTextField::NotifyContentChange( rFormatField );
641 
643  }
644 }
645 
647 {
648  return GetFormatField().GetField()->ExpandField(false, nullptr/*ignored anyway*/);
649 }
650 
652 {
653  if ( !(IsFieldInDoc()
654  && GetStart() != (*End())) )
655  return;
656 
657  assert( (*End()) - GetStart() >= 2 &&
658  "<SwTextInputField::UpdateFieldContent()> - Are CH_TXT_ATR_INPUTFIELDSTART and/or CH_TXT_ATR_INPUTFIELDEND missing?" );
659  // skip CH_TXT_ATR_INPUTFIELDSTART character
660  const sal_Int32 nIdx = GetStart() + 1;
661  // skip CH_TXT_ATR_INPUTFIELDEND character
662  const sal_Int32 nLen = static_cast<sal_Int32>(std::max<sal_Int32>( 0, ( (*End()) - 1 - nIdx ) ));
663  const OUString aNewFieldContent = GetTextNode().GetExpandText(nullptr, nIdx, nLen);
664 
665  const SwField* pField = GetFormatField().GetField();
666  const SwInputField* pInputField = dynamic_cast<const SwInputField*>(pField);
667  if (pInputField)
668  const_cast<SwInputField*>(pInputField)->applyFieldContent( aNewFieldContent );
669 
670  const SwSetExpField* pExpField = dynamic_cast<const SwSetExpField*>(pField);
671  if (pExpField)
672  {
673  assert(pExpField->GetInputFlag());
674  const_cast<SwSetExpField*>(pExpField)->SetPar2(aNewFieldContent);
675  }
676  assert(pInputField || pExpField);
677 
678  // trigger update of fields for scenarios in which the Input Field's content is part of e.g. a table formula
680 }
681 
682 void SwTextInputField::UpdateTextNodeContent( const OUString& rNewContent )
683 {
684  assert(IsFieldInDoc() &&
685  "<SwTextInputField::UpdateTextNodeContent(..)> - misusage as Input Field is not in document content.");
686 
687  assert( (*End()) - GetStart() >= 2 &&
688  "<SwTextInputField::UpdateTextNodeContent(..)> - Are CH_TXT_ATR_INPUTFIELDSTART and/or CH_TXT_ATR_INPUTFIELDEND missing?" );
689  // skip CH_TXT_ATR_INPUTFIELDSTART character
690  const sal_Int32 nIdx = GetStart() + 1;
691  // skip CH_TXT_ATR_INPUTFIELDEND character
692  const sal_Int32 nDelLen = std::max<sal_Int32>( 0, ( (*End()) - 1 - nIdx ) );
693  SwIndex aIdx( &GetTextNode(), nIdx );
694  GetTextNode().ReplaceText( aIdx, nDelLen, rNewContent );
695 }
696 
697 // class SwTextAnnotationField //////////////////////////////////////////
698 
699 // text annotation field
701  SwFormatField & rAttr,
702  sal_Int32 const nStart,
703  bool const bInClipboard )
704  : SwTextAttr( rAttr, nStart )
705  , SwTextField( rAttr, nStart, bInClipboard )
706 {
707 }
708 
710 {
711 }
712 
714 {
715  auto pPostItField = dynamic_cast<const SwPostItField*>(GetFormatField().GetField());
716  assert(pPostItField);
717 
718  SwDoc& rDoc = static_cast<const SwPostItFieldType*>(pPostItField->GetTyp())->GetDoc();
719 
720  IDocumentMarkAccess* pMarksAccess = rDoc.getIDocumentMarkAccess();
721  IDocumentMarkAccess::const_iterator_t pMark = pMarksAccess->findAnnotationMark( pPostItField->GetName() );
722  return pMark != pMarksAccess->getAnnotationMarksEnd()
723  ? *pMark
724  : nullptr;
725 }
726 
727 /* 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:199
OUString m_aExpand
Definition: txtfld.hxx:33
The shared part of a user field.
Definition: usrfld.hxx:35
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
bool IsProtect() const
Definition: atrfld.cxx:399
void SetHasDummyChar(const bool bFlag)
Definition: txatbase.hxx:72
void TriggerNodeUpdate(const sw::LegacyModifyHint &)
for hanging TextFormatCollections somewhere else (Outline-Numbering!)
Definition: ndtxt.cxx:5240
SwNodeIndex nNode
Definition: pam.hxx:37
wrapper iterator: wraps iterator of implementation while hiding MarkBase class; only IMark instances ...
constexpr TypedWhichId< SwDocPosUpdate > RES_DOCPOS_UPDATE(167)
Base class of all fields.
Definition: fldbas.hxx:289
Provides access to the marks of a document.
Definition: doc.hxx:186
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:614
IDocumentMarkAccess * getIDocumentMarkAccess()
Definition: docbm.cxx:1705
virtual void SwClientNotify(const SwModify &, const SfxHint &rHint) override
Definition: calbck.cxx:111
virtual bool DeleteAndJoin(SwPaM &, const bool bForceJoinNext=false)=0
complete delete of a given PaM
SwClient * Remove(SwClient *pDepend)
Definition: calbck.cxx:252
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
SwIndex nContent
Definition: pam.hxx:38
const BorderLinePrimitive2D *pCandidateB assert(pCandidateA)
const SwTextField * GetTextField() const
Definition: fmtfld.hxx:128
bool CalcHiddenParaField()
Hidden Paragraph Field:
Definition: ndtxt.hxx:712
sal_Int32 GetStart() const
Definition: txatbase.hxx:82
virtual void NotifyContentChange(SwFormatField &rFormatField) override
Definition: atrfld.cxx:633
constexpr TypedWhichId< SwAttrSetChg > RES_ATTRSET_CHG(161)
constexpr TypedWhichId< SwFormatChg > RES_FMT_CHG(160)
void SetField(std::unique_ptr< SwField > pField)
Sets current field.
Definition: atrfld.cxx:175
const SwTable & GetTable() const
Definition: node.hxx:500
void CopyTextField(SwTextField *pDest) const
Definition: atrfld.cxx:492
const SwFormatField & GetFormatField() const
Definition: txatbase.hxx:191
bool HasOnlyOneListener() const
Definition: calbck.hxx:224
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:2127
void ExpandTextField(const bool bForceNotify=false) const
Definition: atrfld.cxx:449
virtual void SwClientNotify(const SwModify &rModify, const SfxHint &rHint) override
Definition: atrfld.cxx:222
virtual ~SwTextField() override
Definition: atrfld.cxx:434
virtual SwFieldType * ChgTyp(SwFieldType *)
Set new type (used for copying among documents).
Definition: fldbas.cxx:381
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:420
struct _xmlTextWriter * xmlTextWriterPtr
bool Move(SwMoveFnCollection const &fnMove=fnMoveForward, SwGoInDoc fnGo=GoInContent)
Movement of cursor.
Definition: pam.cxx:502
OUString GetFieldContent() const
Definition: atrfld.cxx:646
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)
constexpr TypedWhichId< SwRefMarkFieldUpdate > RES_REFMARKFLD_UPDATE(166)
::sw::mark::IMark * GetAnnotationMark() const
Definition: atrfld.cxx:713
SwDoc & GetDoc()
Definition: node.hxx:211
const SwPosition * GetPoint() const
Definition: pam.hxx:207
bool IsFieldInDoc() const
Definition: atrfld.cxx:443
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
Marks a character position inside a document model node.
Definition: index.hxx:33
double GetValue(SwCalc &rCalc)
Definition: usrfld.cxx:232
SwNodes & GetNodes()
Node is in which nodes-array/doc?
Definition: node.hxx:696
bool IsProtect() const
Is node in something that is protected (range, frame, table cells ...
Definition: node.cxx:424
virtual sal_uInt16 GetSubType() const
Definition: fldbas.cxx:335
void RegisterToFieldType(SwFieldType &)
Definition: atrfld.cxx:170
bool m_bLockNotifyContentChange
Definition: txtfld.hxx:101
IDocumentLayoutAccess const & getIDocumentLayoutAccess() const
Definition: doc.cxx:405
constexpr TypedWhichId< SwPtrMsgPoolItem > RES_REMOVE_UNO_OBJECT(179)
void ClearTextField()
Definition: atrfld.cxx:195
void SetHasContent(const bool bFlag)
Definition: txatbase.hxx:73
SwFieldType * GetTyp() const
Definition: fldbas.hxx:392
bool GetInputFlag() const
Definition: expfld.hxx:264
void NotifyClients(const SfxPoolItem *pOldValue, const SfxPoolItem *pNewValue)
Definition: calbck.cxx:170
void SetFormatField(SwFormatField &rFormatField)
Definition: expfld.cxx:827
bool IsFieldInDoc() const
Definition: atrfld.cxx:393
bool IsValid() const
Definition: usrfld.hxx:79
SwTextNode is a paragraph in the document model.
Definition: ndtxt.hxx:80
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:455
SwTextAnnotationField(SwFormatField &rAttr, sal_Int32 const nStart, bool const bInClipboard)
Definition: atrfld.cxx:700
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:3345
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:3646
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:555
void SetWhich(sal_uInt16 nId)
bool IsClipBoard() const
Definition: doc.hxx:962
virtual SwDocUpdateField & GetUpdateFields() const =0
css::uno::WeakReference< css::text::XTextField > m_wXTextField
Definition: fmtfld.hxx:86
bool LockNotifyContentChange()
Definition: atrfld.cxx:618
constexpr TypedWhichId< SwMsgPoolItem > RES_HIDDENPARA_PRINT(176)
const sal_Int32 * End() const
Definition: txatbase.hxx:148
constexpr TypedWhichId< SwAutoFormatGetDocNode > RES_AUTOFMT_DOCNODE(171)
constexpr TypedWhichId< SwFormatField > RES_TXTATR_INPUTFIELD(55)
virtual void CallSwClientNotify(const SfxHint &rHint) const override
Definition: calbck.cxx:370
SwTableNode * FindTableNode()
Search table node, in which it is.
Definition: node.cxx:355
const SfxPoolItem & GetAttr() const
Definition: txatbase.hxx:159
void UnlockNotifyContentChange()
Definition: atrfld.cxx:628
#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:2320
const SwGetSetExpType GSE_STRING
String.
Definition: fldbas.hxx:202
SwDoc & GetDoc() const
Definition: pam.hxx:243
virtual SwFieldType * GetSysFieldType(const SwFieldIds eWhich) const =0
void UpdateTextNode(const SfxPoolItem *pOld, const SfxPoolItem *pNew)
Definition: atrfld.cxx:291
void UpdateTextNodeContent(const OUString &rNewContent)
Definition: atrfld.cxx:682
virtual void SetMark()
Unless this is called, the getter method of Mark will return Point.
Definition: pam.cxx:476
virtual ~SwTextAnnotationField() override
Definition: atrfld.cxx:709
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:599
SwFieldIds Which() const
Definition: fldbas.hxx:272
static void GetPamForTextField(const SwTextField &rTextField, std::shared_ptr< SwPaM > &rPamForTextField)
Definition: atrfld.cxx:563
void SetFormatField(SwFormatField &rFormatField)
Definition: expfld.cxx:1236
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:651
static void DeleteTextField(const SwTextField &rTextField)
Definition: atrfld.cxx:583
virtual void dumpAsXml(xmlTextWriterPtr pWriter) const