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 {
219  &static_cast<SwModify&>(*this)); // cast to base class (void*)
220  CallSwClientNotify(sw::LegacyModifyHint{ &item, &item });
221 }
222 
223 void SwFormatField::SwClientNotify( const SwModify& rModify, const SfxHint& rHint )
224 {
225  SwClient::SwClientNotify(rModify, rHint);
226  if (const auto pFieldHint = dynamic_cast<const SwFieldHint*>( &rHint ))
227  {
228  if( !mpTextField )
229  return;
230 
231  // replace field content by text
232  SwPaM* pPaM = pFieldHint->m_pPaM;
233  SwDoc* pDoc = pPaM->GetDoc();
234  const SwTextNode& rTextNode = mpTextField->GetTextNode();
235  pPaM->GetPoint()->nNode = rTextNode;
236  pPaM->GetPoint()->nContent.Assign( const_cast<SwTextNode*>(&rTextNode), mpTextField->GetStart() );
237 
238  OUString const aEntry(mpField->ExpandField(pDoc->IsClipBoard(), pFieldHint->m_pLayout));
239  pPaM->SetMark();
240  pPaM->Move( fnMoveForward );
242  pDoc->getIDocumentContentOperations().InsertString( *pPaM, aEntry );
243  } else if (const auto pLegacyHint = dynamic_cast<const sw::LegacyModifyHint*>( &rHint ))
244  {
245  if( !mpTextField )
246  return;
247  UpdateTextNode(pLegacyHint->m_pOld, pLegacyHint->m_pNew);
248  } else if (const auto pFindForFieldHint = dynamic_cast<const sw::FindFormatForFieldHint*>( &rHint ))
249  {
250  if(pFindForFieldHint->m_rpFormat == nullptr && pFindForFieldHint->m_pField == GetField())
251  pFindForFieldHint->m_rpFormat = this;
252  } else if (const auto pFindForPostItIdHint = dynamic_cast<const sw::FindFormatForPostItIdHint*>( &rHint ))
253  {
254  auto pPostItField = dynamic_cast<SwPostItField*>(mpField.get());
255  if(pPostItField && pFindForPostItIdHint->m_rpFormat == nullptr && pFindForPostItIdHint->m_nPostItId == pPostItField->GetPostItId())
256  pFindForPostItIdHint->m_rpFormat = this;
257  } else if (const auto pCollectPostItsHint = dynamic_cast<const sw::CollectPostItsHint*>( &rHint ))
258  {
259  if(GetTextField() && IsFieldInDoc() && (!pCollectPostItsHint->m_bHideRedlines || !sw::IsFieldDeletedInModel(pCollectPostItsHint->m_rIDRA, *GetTextField())))
260  pCollectPostItsHint->m_rvFormatFields.push_back(this);
261  } else if (const auto pHasHiddenInfoHint = dynamic_cast<const sw::HasHiddenInformationNotesHint*>( &rHint ))
262  {
263  if(!pHasHiddenInfoHint->m_rbHasHiddenInformationNotes && GetTextField() && IsFieldInDoc())
264  pHasHiddenInfoHint->m_rbHasHiddenInformationNotes = true;
265  } else if (const auto pGatherNodeIndexHint = dynamic_cast<const sw::GatherNodeIndexHint*>( &rHint ))
266  {
267  if(auto pTextField = GetTextField())
268  pGatherNodeIndexHint->m_rvNodeIndex.push_back(pTextField->GetTextNode().GetIndex());
269  } else if (const auto pGatherRefFieldsHint = dynamic_cast<const sw::GatherRefFieldsHint*>( &rHint ))
270  {
271  if(!GetTextField() || pGatherRefFieldsHint->m_nType != GetField()->GetSubType())
272  return;
274  if(pNd && pNd->GetNodes().IsDocNodes())
275  pGatherRefFieldsHint->m_rvRFields.push_back(static_cast<SwGetRefField*>(GetField()));
276  } else if (const auto pGatherFieldsHint = dynamic_cast<const sw::GatherFieldsHint*>( &rHint ))
277  {
278  if(pGatherFieldsHint->m_bCollectOnlyInDocNodes)
279  {
280  if(!GetTextField())
281  return;
283  if(!pNd || !pNd->GetNodes().IsDocNodes())
284  return;
285  }
286  pGatherFieldsHint->m_rvFields.push_back(this);
287  }
288 }
289 
291 {
292  if (pOld && (RES_REMOVE_UNO_OBJECT == pOld->Which()))
293  { // invalidate cached UNO object
294  m_wXTextField = nullptr;
295  // ??? why does this Modify method not already do this?
296  NotifyClients(pOld, pNew);
297  return;
298  }
299 
300  if( !mpTextField )
301  return;
302 
303  // don't do anything, especially not expand!
304  if( pNew && pNew->Which() == RES_OBJECTDYING )
305  return;
306 
307  SwTextNode* pTextNd = &mpTextField->GetTextNode();
308  OSL_ENSURE( pTextNd, "Where is my Node?" );
309 
310  bool bTriggerNode = false;
311  bool bExpand = false;
312  const SfxPoolItem* pNodeOld = nullptr;
313  const SfxPoolItem* pNodeNew = nullptr;
314  if(pNew)
315  {
316  switch(pNew->Which())
317  {
319  // update GetRef fields
320  if( SwFieldIds::GetRef == mpField->GetTyp()->Which() )
321  {
322  // #i81002#
323  static_cast<SwGetRefField*>(mpField.get())->UpdateField( mpTextField );
324  }
325  break;
326  case RES_DOCPOS_UPDATE:
327  // handled in SwTextFrame::Modify()
328  bTriggerNode = true;
329  pNodeOld = pNew;
330  pNodeNew = this;
331  break;
332  case RES_ATTRSET_CHG:
333  case RES_FMT_CHG:
334  bTriggerNode = true;
335  pNodeOld = pOld;
336  pNodeNew = pNew;
337  break;
338  default:
339  break;
340  }
341  }
342  if(!bTriggerNode)
343  {
344  switch (mpField->GetTyp()->Which())
345  {
347  if( !pOld || pOld->Which() != RES_HIDDENPARA_PRINT ) {
348  bExpand =true;
349  break;
350  }
351  [[fallthrough]];
356  bTriggerNode = true;
357  pNodeNew = pNew;
358  break;
359  case SwFieldIds::User:
360  {
361  SwUserFieldType* pType = static_cast<SwUserFieldType*>(mpField->GetTyp());
362  if(!pType->IsValid())
363  {
364  SwCalc aCalc( *pTextNd->GetDoc() );
365  pType->GetValue( aCalc );
366  }
367  bExpand = true;
368  }
369  break;
370  default:
371  bExpand = true;
372  break;
373  }
374  }
375  if(bTriggerNode)
376  {
377  pTextNd->ModifyNotification(pNodeOld, pNodeNew);
378  }
379  if(bExpand)
380  {
381  mpTextField->ExpandTextField( pOld == nullptr && pNew == nullptr );
382  }
383 }
384 
386 {
387  if( RES_AUTOFMT_DOCNODE != rInfo.Which() || !mpTextField )
388  return true;
389  const SwTextNode* pTextNd = mpTextField->GetpTextNode();
390  return nullptr == pTextNd ||
391  &pTextNd->GetNodes() != static_cast<SwAutoFormatGetDocNode&>(rInfo).pNodes;
392 }
393 
395 {
396  return mpTextField != nullptr
398 }
399 
401 {
402  return mpTextField != nullptr
403  && mpTextField->GetpTextNode() != nullptr
405 }
406 
408 {
409  xmlTextWriterStartElement(pWriter, BAD_CAST("SwFormatField"));
410  xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("ptr"), "%p", this);
411  xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("mpTextField"), "%p", mpTextField);
412 
413  SfxPoolItem::dumpAsXml(pWriter);
414  mpField->dumpAsXml(pWriter);
415 
416  xmlTextWriterEndElement(pWriter);
417 }
418 
419 // class SwTextField ////////////////////////////////////////////////////
420 
422  SwFormatField & rAttr,
423  sal_Int32 const nStartPos,
424  bool const bInClipboard)
425  : SwTextAttr( rAttr, nStartPos )
426 // fdo#39694 the ExpandField here may not give the correct result in all cases,
427 // but is better than nothing
428  , m_aExpand( rAttr.GetField()->ExpandField(bInClipboard, nullptr) )
429  , m_pTextNode( nullptr )
430 {
431  rAttr.SetTextField( *this );
432  SetHasDummyChar(true);
433 }
434 
436 {
437  SwFormatField & rFormatField( static_cast<SwFormatField &>(GetAttr()) );
438  if ( this == rFormatField.GetTextField() )
439  {
440  rFormatField.ClearTextField();
441  }
442 }
443 
445 {
446  return GetpTextNode() != nullptr
447  && GetpTextNode()->GetNodes().IsDocNodes();
448 }
449 
450 void SwTextField::ExpandTextField(const bool bForceNotify) const
451 {
452  OSL_ENSURE( m_pTextNode, "SwTextField: where is my TextNode?" );
453 
454  const SwField* pField = GetFormatField().GetField();
455  const OUString aNewExpand( pField->ExpandField(m_pTextNode->GetDoc()->IsClipBoard(),
456  // can't do any better than this here...
458 
459  const SwFieldIds nWhich = pField->GetTyp()->Which();
460  const bool bSameExpandSimpleNotification
461  = SwFieldIds::Chapter != nWhich && SwFieldIds::PageNumber != nWhich
462  && SwFieldIds::RefPageGet != nWhich
463  // Page count fields to not use aExpand during formatting,
464  // therefore an invalidation of the text frame has to be triggered even if aNewExpand == aExpand:
465  && (SwFieldIds::DocStat != nWhich
466  || DS_PAGE != static_cast<const SwDocStatField*>(pField)->GetSubType())
467  && (SwFieldIds::GetExp != nWhich
468  || static_cast<const SwGetExpField*>(pField)->IsInBodyText());
469 
470  bool bHiddenParaChanged = false;
471  if (aNewExpand != m_aExpand || bSameExpandSimpleNotification)
472  bHiddenParaChanged = m_pTextNode->CalcHiddenParaField();
473 
474  if (aNewExpand == m_aExpand)
475  {
476  if ( bSameExpandSimpleNotification )
477  {
478  if( bHiddenParaChanged )
479  {
480  m_pTextNode->ModifyNotification( nullptr, nullptr );
481  }
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  {
563  m_pTextNode->ModifyNotification(nullptr, &rFormatField);
564  }
565 }
566 
567 /*static*/
569  const SwTextField& rTextField,
570  std::shared_ptr< SwPaM >& rPamForTextField )
571 {
572  if (rTextField.GetpTextNode() == nullptr)
573  {
574  SAL_WARN("sw.core", "<SwTextField::GetPamForField> - missing <SwTextNode>");
575  return;
576  }
577 
578  const SwTextNode& rTextNode = rTextField.GetTextNode();
579 
580  rPamForTextField = std::make_shared<SwPaM>( rTextNode,
581  (rTextField.End() != nullptr) ? *(rTextField.End()) : ( rTextField.GetStart() + 1 ),
582  rTextNode,
583  rTextField.GetStart() );
584 
585 }
586 
587 /*static*/
588 void SwTextField::DeleteTextField( const SwTextField& rTextField )
589 {
590  if (rTextField.GetpTextNode() != nullptr)
591  {
592  std::shared_ptr< SwPaM > pPamForTextField;
593  GetPamForTextField(rTextField, pPamForTextField);
594  if (pPamForTextField != nullptr)
595  {
596  rTextField.GetTextNode().GetDoc()->getIDocumentContentOperations().DeleteAndJoin(*pPamForTextField);
597  }
598  }
599 }
600 
601 // class SwTextInputField ///////////////////////////////////////////////
602 
603 // input field in-place editing
605  SwFormatField & rAttr,
606  sal_Int32 const nStart,
607  sal_Int32 const nEnd,
608  bool const bInClipboard )
609 
610  : SwTextAttr( rAttr, nStart )
611  , SwTextAttrNesting( rAttr, nStart, nEnd )
612  , SwTextField( rAttr, nStart, bInClipboard )
613  , m_bLockNotifyContentChange( false )
614 {
615  SetHasDummyChar( false );
616  SetHasContent( true );
617 }
618 
620 {
621 }
622 
624 {
626  {
627  return false;
628  }
630  return true;
631 }
632 
634 {
636 }
637 
639 {
641  {
643 
644  SwTextField::NotifyContentChange( rFormatField );
646 
648  }
649 }
650 
652 {
653  return GetFormatField().GetField()->ExpandField(false, nullptr/*ignored anyway*/);
654 }
655 
657 {
658  if ( !(IsFieldInDoc()
659  && GetStart() != (*End())) )
660  return;
661 
662  assert( (*End()) - GetStart() >= 2 &&
663  "<SwTextInputField::UpdateFieldContent()> - Are CH_TXT_ATR_INPUTFIELDSTART and/or CH_TXT_ATR_INPUTFIELDEND missing?" );
664  // skip CH_TXT_ATR_INPUTFIELDSTART character
665  const sal_Int32 nIdx = GetStart() + 1;
666  // skip CH_TXT_ATR_INPUTFIELDEND character
667  const sal_Int32 nLen = static_cast<sal_Int32>(std::max<sal_Int32>( 0, ( (*End()) - 1 - nIdx ) ));
668  const OUString aNewFieldContent = GetTextNode().GetExpandText(nullptr, nIdx, nLen);
669 
670  const SwField* pField = GetFormatField().GetField();
671  const SwInputField* pInputField = dynamic_cast<const SwInputField*>(pField);
672  if (pInputField)
673  const_cast<SwInputField*>(pInputField)->applyFieldContent( aNewFieldContent );
674 
675  const SwSetExpField* pExpField = dynamic_cast<const SwSetExpField*>(pField);
676  if (pExpField)
677  {
678  assert(pExpField->GetInputFlag());
679  const_cast<SwSetExpField*>(pExpField)->SetPar2(aNewFieldContent);
680  }
681  assert(pInputField || pExpField);
682 
683  // trigger update of fields for scenarios in which the Input Field's content is part of e.g. a table formula
685 }
686 
687 void SwTextInputField::UpdateTextNodeContent( const OUString& rNewContent )
688 {
689  assert(IsFieldInDoc() &&
690  "<SwTextInputField::UpdateTextNodeContent(..)> - misusage as Input Field is not in document content.");
691 
692  assert( (*End()) - GetStart() >= 2 &&
693  "<SwTextInputField::UpdateTextNodeContent(..)> - Are CH_TXT_ATR_INPUTFIELDSTART and/or CH_TXT_ATR_INPUTFIELDEND missing?" );
694  // skip CH_TXT_ATR_INPUTFIELDSTART character
695  const sal_Int32 nIdx = GetStart() + 1;
696  // skip CH_TXT_ATR_INPUTFIELDEND character
697  const sal_Int32 nDelLen = std::max<sal_Int32>( 0, ( (*End()) - 1 - nIdx ) );
698  SwIndex aIdx( &GetTextNode(), nIdx );
699  GetTextNode().ReplaceText( aIdx, nDelLen, rNewContent );
700 }
701 
702 // class SwTextAnnotationField //////////////////////////////////////////
703 
704 // text annotation field
706  SwFormatField & rAttr,
707  sal_Int32 const nStart,
708  bool const bInClipboard )
709  : SwTextAttr( rAttr, nStart )
710  , SwTextField( rAttr, nStart, bInClipboard )
711 {
712 }
713 
715 {
716 }
717 
719 {
720  auto pPostItField = dynamic_cast<const SwPostItField*>(GetFormatField().GetField());
721  assert(pPostItField);
722 
723  SwDoc* pDoc = static_cast<const SwPostItFieldType*>(pPostItField->GetTyp())->GetDoc();
724  assert(pDoc != nullptr);
725 
726  IDocumentMarkAccess* pMarksAccess = pDoc->getIDocumentMarkAccess();
727  IDocumentMarkAccess::const_iterator_t pMark = pMarksAccess->findAnnotationMark( pPostItField->GetName() );
728  return pMark != pMarksAccess->getAnnotationMarksEnd()
729  ? *pMark
730  : nullptr;
731 }
732 
733 /* 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
Definition: calc.hxx:190
SwTextField * mpTextField
Definition: fmtfld.hxx:90
void Add(SwClient *pDepend)
Definition: calbck.cxx:217
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:111
void SetTextField(SwTextField &rTextField)
Definition: atrfld.cxx:190
virtual void ModifyNotification(const SfxPoolItem *pOld, const SfxPoolItem *pNew) override
Definition: node.hxx:475
virtual const_iterator_t getAnnotationMarksEnd() const =0
virtual const SwRootFrame * GetCurrentLayout() const =0
bool IsProtect() const
Definition: atrfld.cxx:400
void SetHasDummyChar(const bool bFlag)
Definition: txatbase.hxx:72
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:293
Provides access to the marks of a document.
Definition: doc.hxx:184
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:619
IDocumentMarkAccess * getIDocumentMarkAccess()
Definition: docbm.cxx:1682
virtual void SwClientNotify(const SwModify &, const SfxHint &rHint) override
Definition: calbck.cxx:108
virtual bool DeleteAndJoin(SwPaM &, const bool bForceJoinNext=false)=0
complete delete of a given PaM
SwClient * Remove(SwClient *pDepend)
Definition: calbck.cxx:259
void InvalidateField()
Definition: atrfld.cxx:216
virtual bool GetInfo(SfxPoolItem &rInfo) const override
Definition: atrfld.cxx:385
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:129
bool CalcHiddenParaField()
Hidden Paragraph Field:
Definition: ndtxt.hxx:710
sal_Int32 GetStart() const
Definition: txatbase.hxx:82
virtual void NotifyContentChange(SwFormatField &rFormatField) override
Definition: atrfld.cxx:638
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:497
void CopyTextField(SwTextField *pDest) const
Definition: atrfld.cxx:495
const SwFormatField & GetFormatField() const
Definition: txatbase.hxx:191
bool HasOnlyOneListener() const
Definition: calbck.hxx:223
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:2117
void ExpandTextField(const bool bForceNotify=false) const
Definition: atrfld.cxx:450
virtual void SwClientNotify(const SwModify &rModify, const SfxHint &rHint) override
Definition: atrfld.cxx:223
virtual ~SwTextField() override
Definition: atrfld.cxx:435
virtual SwFieldType * ChgTyp(SwFieldType *)
Set new type (used for copying among documents).
Definition: fldbas.cxx:369
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:421
struct _xmlTextWriter * xmlTextWriterPtr
bool Move(SwMoveFnCollection const &fnMove=fnMoveForward, SwGoInDoc fnGo=GoInContent)
Movement of cursor.
Definition: pam.cxx:501
OUString GetFieldContent() const
Definition: atrfld.cxx:651
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:718
const SwPosition * GetPoint() const
Definition: pam.hxx:207
bool IsFieldInDoc() const
Definition: atrfld.cxx:444
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
SwDoc * GetDoc()
Definition: node.hxx:702
std::unique_ptr< SwField > mpField
Definition: fmtfld.hxx:89
SwDoc * GetDoc() const
Definition: pam.hxx:243
Marks a character position inside a document model node.
Definition: index.hxx:33
double GetValue(SwCalc &rCalc)
Definition: usrfld.cxx:231
SwNodes & GetNodes()
Node is in which nodes-array/doc?
Definition: node.hxx:693
bool IsProtect() const
Is node in something that is protected (range, frame, table cells ...
Definition: node.cxx:421
virtual sal_uInt16 GetSubType() const
Definition: fldbas.cxx:323
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:396
bool GetInputFlag() const
Definition: expfld.hxx:265
void NotifyClients(const SfxPoolItem *pOldValue, const SfxPoolItem *pNewValue)
Definition: calbck.cxx:167
void SetFormatField(SwFormatField &rFormatField)
Definition: expfld.cxx:827
bool IsFieldInDoc() const
Definition: atrfld.cxx:394
bool IsValid() const
Definition: usrfld.hxx:77
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:443
SwTextAnnotationField(SwFormatField &rAttr, sal_Int32 const nStart, bool const bInClipboard)
Definition: atrfld.cxx:705
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:3378
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:3679
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:960
virtual SwDocUpdateField & GetUpdateFields() const =0
css::uno::WeakReference< css::text::XTextField > m_wXTextField
Definition: fmtfld.hxx:87
bool LockNotifyContentChange()
Definition: atrfld.cxx:623
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:376
SwTableNode * FindTableNode()
Search table node, in which it is.
Definition: node.cxx:352
const SfxPoolItem & GetAttr() const
Definition: txatbase.hxx:159
void UnlockNotifyContentChange()
Definition: atrfld.cxx:633
#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:2324
const SwGetSetExpType GSE_STRING
String.
Definition: fldbas.hxx:202
virtual SwFieldType * GetSysFieldType(const SwFieldIds eWhich) const =0
void UpdateTextNode(const SfxPoolItem *pOld, const SfxPoolItem *pNew)
Definition: atrfld.cxx:290
void UpdateTextNodeContent(const OUString &rNewContent)
Definition: atrfld.cxx:687
virtual void SetMark()
Unless this is called, the getter method of Mark will return Point.
Definition: pam.cxx:475
virtual ~SwTextAnnotationField() override
Definition: atrfld.cxx:714
SwTextNode & GetTextNode() const
Definition: txtfld.hxx:53
void dumpAsXml(xmlTextWriterPtr pWriter) const override
Definition: atrfld.cxx:407
SwTextInputField(SwFormatField &rAttr, sal_Int32 const nStart, sal_Int32 const nEnd, bool const bInClipboard)
Definition: atrfld.cxx:604
SwFieldIds Which() const
Definition: fldbas.hxx:272
static void GetPamForTextField(const SwTextField &rTextField, std::shared_ptr< SwPaM > &rPamForTextField)
Definition: atrfld.cxx:568
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:656
static void DeleteTextField(const SwTextField &rTextField)
Definition: atrfld.cxx:588
virtual void dumpAsXml(xmlTextWriterPtr pWriter) const