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  {
100  rAttr.mpField->GetTyp()->Add(this);
101  mpField = rAttr.mpField->CopyField();
102  if ( mpField->GetTyp()->Which() == SwFieldIds::Input )
103  {
104  // input field in-place editing
106  SwInputField *pField = dynamic_cast<SwInputField*>(mpField.get());
107  assert(pField);
108  if (pField)
109  pField->SetFormatField( *this );
110  }
111  else if (mpField->GetTyp()->Which() == SwFieldIds::SetExp)
112  {
113  SwSetExpField *const pSetField(static_cast<SwSetExpField *>(mpField.get()));
114  if (pSetField->GetInputFlag()
115  && (static_cast<SwSetExpFieldType*>(pSetField->GetTyp())->GetType()
117  {
119  }
120  // see SwWrtShell::StartInputFieldDlg
121  pSetField->SetFormatField(*this);
122  }
123  else if ( mpField->GetTyp()->Which() == SwFieldIds::Postit )
124  {
125  // text annotation field
127  }
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  {
144  bool bDel = false;
145  switch( pType->Which() )
146  {
147  case SwFieldIds::User:
148  bDel = static_cast<SwUserFieldType*>(pType)->IsDeleted();
149  break;
150 
151  case SwFieldIds::SetExp:
152  bDel = static_cast<SwSetExpFieldType*>(pType)->IsDeleted();
153  break;
154 
155  case SwFieldIds::Dde:
156  bDel = static_cast<SwDDEFieldType*>(pType)->IsDeleted();
157  break;
158  default: break;
159  }
160 
161  if( bDel )
162  {
163  // unregister before deleting
164  pType->Remove( this );
165  delete pType;
166  }
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  NotifyClients(&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  const SwTextNode* pTextNd;
388  return RES_AUTOFMT_DOCNODE != rInfo.Which() ||
389  !mpTextField || nullptr == ( pTextNd = mpTextField->GetpTextNode() ) ||
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 )
478  {
479  m_pTextNode->ModifyNotification( nullptr, nullptr );
480  }
481  if ( !bForceNotify )
482  {
483  // done, if no further notification forced.
484  return;
485  }
486  }
487  }
488  else
489  m_aExpand = aNewExpand;
490 
491  const_cast<SwTextField*>(this)->NotifyContentChange( const_cast<SwFormatField&>(GetFormatField()) );
492 }
493 
495 {
496  OSL_ENSURE( m_pTextNode, "SwTextField: where is my TextNode?" );
497  OSL_ENSURE( pDest->m_pTextNode, "SwTextField: where is pDest's TextNode?" );
498 
501 
502  SwFormatField& rDestFormatField = const_cast<SwFormatField&>(pDest->GetFormatField());
503  const SwFieldIds nFieldWhich = rDestFormatField.GetField()->GetTyp()->Which();
504 
505  if( pIDFA != pDestIDFA )
506  {
507  // different documents, e.g. clipboard:
508  // register field type in target document
509  SwFieldType* pFieldType;
510  if( nFieldWhich != SwFieldIds::Database
511  && nFieldWhich != SwFieldIds::User
512  && nFieldWhich != SwFieldIds::SetExp
513  && nFieldWhich != SwFieldIds::Dde
514  && SwFieldIds::TableOfAuthorities != nFieldWhich )
515  {
516  pFieldType = pDestIDFA->GetSysFieldType( nFieldWhich );
517  }
518  else
519  {
520  pFieldType = pDestIDFA->InsertFieldType( *rDestFormatField.GetField()->GetTyp() );
521  }
522 
523  // DDE fields need special treatment
524  if( SwFieldIds::Dde == nFieldWhich )
525  {
526  if( rDestFormatField.GetTextField() )
527  {
528  static_cast<SwDDEFieldType*>(rDestFormatField.GetField()->GetTyp())->DecRefCnt();
529  }
530  static_cast<SwDDEFieldType*>(pFieldType)->IncRefCnt();
531  }
532 
533  OSL_ENSURE( pFieldType, "unknown FieldType" );
534  pFieldType->Add( &rDestFormatField ); // register at the field type
535  rDestFormatField.GetField()->ChgTyp( pFieldType );
536  }
537 
538  // update expression fields
539  if( nFieldWhich == SwFieldIds::SetExp
540  || nFieldWhich == SwFieldIds::GetExp
541  || nFieldWhich == SwFieldIds::HiddenText )
542  {
543  SwTextField* pField = const_cast<SwTextField*>(this);
544  pDestIDFA->UpdateExpFields( pField, true );
545  }
546  // table fields: external display
547  else if( SwFieldIds::Table == nFieldWhich
548  && static_cast<SwTableField*>(rDestFormatField.GetField())->IsIntrnlName() )
549  {
550  // convert internal (core) to external (UI) formula
551  const SwTableNode* pTableNd = m_pTextNode->FindTableNode();
552  if( pTableNd ) // in a table?
553  static_cast<SwTableField*>(rDestFormatField.GetField())->PtrToBoxNm( &pTableNd->GetTable() );
554  }
555 }
556 
558 {
559  //if not in undo section notify the change
561  {
562  m_pTextNode->ModifyNotification(nullptr, &rFormatField);
563  }
564 }
565 
566 /*static*/
568  const SwTextField& rTextField,
569  std::shared_ptr< SwPaM >& rPamForTextField )
570 {
571  if (rTextField.GetpTextNode() == nullptr)
572  {
573  SAL_WARN("sw.core", "<SwTextField::GetPamForField> - missing <SwTextNode>");
574  return;
575  }
576 
577  const SwTextNode& rTextNode = rTextField.GetTextNode();
578 
579  rPamForTextField = std::make_shared<SwPaM>( rTextNode,
580  (rTextField.End() != nullptr) ? *(rTextField.End()) : ( rTextField.GetStart() + 1 ),
581  rTextNode,
582  rTextField.GetStart() );
583 
584 }
585 
586 /*static*/
587 void SwTextField::DeleteTextField( const SwTextField& rTextField )
588 {
589  if (rTextField.GetpTextNode() != nullptr)
590  {
591  std::shared_ptr< SwPaM > pPamForTextField;
592  GetPamForTextField(rTextField, pPamForTextField);
593  if (pPamForTextField != nullptr)
594  {
595  rTextField.GetTextNode().GetDoc()->getIDocumentContentOperations().DeleteAndJoin(*pPamForTextField);
596  }
597  }
598 }
599 
600 // class SwTextInputField ///////////////////////////////////////////////
601 
602 // input field in-place editing
604  SwFormatField & rAttr,
605  sal_Int32 const nStart,
606  sal_Int32 const nEnd,
607  bool const bInClipboard )
608 
609  : SwTextAttr( rAttr, nStart )
610  , SwTextAttrNesting( rAttr, nStart, nEnd )
611  , SwTextField( rAttr, nStart, bInClipboard )
612  , m_bLockNotifyContentChange( false )
613 {
614  SetHasDummyChar( false );
615  SetHasContent( true );
616 }
617 
619 {
620 }
621 
623 {
625  {
626  return false;
627  }
629  return true;
630 }
631 
633 {
635 }
636 
638 {
640  {
642 
643  SwTextField::NotifyContentChange( rFormatField );
645 
647  }
648 }
649 
651 {
652  return GetFormatField().GetField()->ExpandField(false, nullptr/*ignored anyway*/);
653 }
654 
656 {
657  if ( IsFieldInDoc()
658  && GetStart() != (*End()) )
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 
686 void SwTextInputField::UpdateTextNodeContent( const OUString& rNewContent )
687 {
688  assert(IsFieldInDoc() &&
689  "<SwTextInputField::UpdateTextNodeContent(..)> - misusage as Input Field is not in document content.");
690 
691  assert( (*End()) - GetStart() >= 2 &&
692  "<SwTextInputField::UpdateTextNodeContent(..)> - Are CH_TXT_ATR_INPUTFIELDSTART and/or CH_TXT_ATR_INPUTFIELDEND missing?" );
693  // skip CH_TXT_ATR_INPUTFIELDSTART character
694  const sal_Int32 nIdx = GetStart() + 1;
695  // skip CH_TXT_ATR_INPUTFIELDEND character
696  const sal_Int32 nDelLen = std::max<sal_Int32>( 0, ( (*End()) - 1 - nIdx ) );
697  SwIndex aIdx( &GetTextNode(), nIdx );
698  GetTextNode().ReplaceText( aIdx, nDelLen, rNewContent );
699 }
700 
701 // class SwTextAnnotationField //////////////////////////////////////////
702 
703 // text annotation field
705  SwFormatField & rAttr,
706  sal_Int32 const nStart,
707  bool const bInClipboard )
708  : SwTextAttr( rAttr, nStart )
709  , SwTextField( rAttr, nStart, bInClipboard )
710 {
711 }
712 
714 {
715 }
716 
718 {
719  auto pPostItField = dynamic_cast<const SwPostItField*>(GetFormatField().GetField());
720  assert(pPostItField);
721 
722  SwDoc* pDoc = static_cast<const SwPostItFieldType*>(pPostItField->GetTyp())->GetDoc();
723  assert(pDoc != nullptr);
724 
725  IDocumentMarkAccess* pMarksAccess = pDoc->getIDocumentMarkAccess();
726  IDocumentMarkAccess::const_iterator_t pMark = pMarksAccess->findAnnotationMark( pPostItField->GetName() );
727  return pMark != pMarksAccess->getAnnotationMarksEnd()
728  ? *pMark
729  : nullptr;
730 }
731 
732 /* 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:184
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:399
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: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:618
IDocumentMarkAccess * getIDocumentMarkAccess()
Definition: docbm.cxx:1683
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:314
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:356
SwIndex nContent
Definition: pam.hxx:38
const SwTextField * GetTextField() const
Definition: fmtfld.hxx:129
bool CalcHiddenParaField()
Hidden Paragraph Field:
Definition: ndtxt.hxx:702
sal_Int32 GetStart() const
Definition: txatbase.hxx:82
virtual void NotifyContentChange(SwFormatField &rFormatField) override
Definition: atrfld.cxx:637
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:494
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:2075
void ExpandTextField(const bool bForceNotify=false) const
Definition: atrfld.cxx:449
virtual void SwClientNotify(const SwModify &rModify, const SfxHint &rHint) override
Definition: atrfld.cxx:223
virtual ~SwTextField() override
Definition: atrfld.cxx:434
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:420
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:650
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:717
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
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:37
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:419
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:404
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:393
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:704
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:3375
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:3676
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:557
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:87
bool LockNotifyContentChange()
Definition: atrfld.cxx:622
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)
SwTableNode * FindTableNode()
Search table node, in which it is.
Definition: node.cxx:350
const SfxPoolItem & GetAttr() const
Definition: txatbase.hxx:159
void UnlockNotifyContentChange()
Definition: atrfld.cxx:632
#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:2313
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:686
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:713
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:603
SwFieldIds Which() const
Definition: fldbas.hxx:272
static void GetPamForTextField(const SwTextField &rTextField, std::shared_ptr< SwPaM > &rPamForTextField)
Definition: atrfld.cxx:567
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:655
static void DeleteTextField(const SwTextField &rTextField)
Definition: atrfld.cxx:587
virtual void dumpAsXml(xmlTextWriterPtr pWriter) const