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#include <unofield.hxx>
31
32#include <pam.hxx>
33#include <reffld.hxx>
34#include <ddefld.hxx>
35#include <usrfld.hxx>
36#include <expfld.hxx>
37#include <ndtxt.hxx>
38#include <calc.hxx>
39#include <hints.hxx>
43#include <fieldhint.hxx>
44#include <sal/log.hxx>
45#include <osl/diagnose.h>
46
47
48// constructor for default item in attribute-pool
49SwFormatField::SwFormatField( sal_uInt16 nWhich )
50 : SfxPoolItem( nWhich )
52 , mpTextField( nullptr )
53{
54}
55
59 , mpField( rField.CopyField() )
60 , mpTextField( nullptr )
61{
62 rField.GetTyp()->Add(this);
63 if ( mpField->GetTyp()->Which() == SwFieldIds::Input )
64 {
65 // input field in-place editing
67 static_cast<SwInputField*>(mpField.get())->SetFormatField( *this );
68 }
69 else if (mpField->GetTyp()->Which() == SwFieldIds::SetExp)
70 {
71 // see SwWrtShell::StartInputFieldDlg
72 SwSetExpField *const pSetField(static_cast<SwSetExpField *>(mpField.get()));
73 if (pSetField->GetInputFlag()
74 // only for string fields for now - inline editing of number fields
75 // tends to produce error messages...
76 && (static_cast<SwSetExpFieldType*>(pSetField->GetTyp())->GetType()
78 {
80 }
81 pSetField->SetFormatField(*this);
82 }
83 else if ( mpField->GetTyp()->Which() == SwFieldIds::Postit )
84 {
85 // text annotation field
87 }
88}
89
90// #i24434#
91// Since Items are used in ItemPool and in default constructed ItemSets with
92// full pool range, all items need to be clonable. Thus, this one needed to be
93// corrected
95 : SfxPoolItem( rAttr )
97 , mpTextField( nullptr )
98{
99 if ( !rAttr.mpField )
100 return;
101
102 rAttr.mpField->GetTyp()->Add(this);
103 mpField = rAttr.mpField->CopyField();
104 if ( mpField->GetTyp()->Which() == SwFieldIds::Input )
105 {
106 // input field in-place editing
108 SwInputField *pField = dynamic_cast<SwInputField*>(mpField.get());
109 assert(pField);
110 if (pField)
111 pField->SetFormatField( *this );
112 }
113 else if (mpField->GetTyp()->Which() == SwFieldIds::SetExp)
114 {
115 SwSetExpField *const pSetField(static_cast<SwSetExpField *>(mpField.get()));
116 if (pSetField->GetInputFlag()
117 && (static_cast<SwSetExpFieldType*>(pSetField->GetTyp())->GetType()
119 {
121 }
122 // see SwWrtShell::StartInputFieldDlg
123 pSetField->SetFormatField(*this);
124 }
125 else if ( mpField->GetTyp()->Which() == SwFieldIds::Postit )
126 {
127 // text annotation field
129 }
130}
131
133{
134 SwFieldType* pType = mpField ? mpField->GetTyp() : nullptr;
135
136 if (pType && pType->Which() == SwFieldIds::Database)
137 pType = nullptr; // DB field types destroy themselves
138
140 mpField.reset();
141
142 // some fields need to delete their field type
143 if( !(pType && pType->HasOnlyOneListener()) )
144 return;
145
146 bool bDel = false;
147 switch( pType->Which() )
148 {
149 case SwFieldIds::User:
150 bDel = static_cast<SwUserFieldType*>(pType)->IsDeleted();
151 break;
152
154 bDel = static_cast<SwSetExpFieldType*>(pType)->IsDeleted();
155 break;
156
157 case SwFieldIds::Dde:
158 bDel = static_cast<SwDDEFieldType*>(pType)->IsDeleted();
159 break;
160 default: break;
161 }
162
163 if( bDel )
164 {
165 // unregister before deleting
166 pType->Remove( this );
167 delete pType;
168 }
169}
170
172{
173 rType.Add(this);
174}
175
176void SwFormatField::SetField(std::unique_ptr<SwField> _pField)
177{
178 mpField = std::move(_pField);
179 if ( mpField->GetTyp()->Which() == SwFieldIds::Input )
180 {
181 static_cast<SwInputField* >(mpField.get())->SetFormatField( *this );
182 }
183 else if (mpField->GetTyp()->Which() == SwFieldIds::SetExp)
184 {
185 // see SwWrtShell::StartInputFieldDlg
186 static_cast<SwSetExpField *>(mpField.get())->SetFormatField(*this);
187 }
189}
190
192{
193 mpTextField = &rTextField;
194}
195
197{
198 mpTextField = nullptr;
199}
200
201bool SwFormatField::operator==( const SfxPoolItem& rAttr ) const
202{
203 assert(SfxPoolItem::operator==(rAttr));
204 return ( mpField
205 && static_cast<const SwFormatField&>(rAttr).mpField
206 && mpField->GetTyp() == static_cast<const SwFormatField&>(rAttr).mpField->GetTyp()
207 && mpField->GetFormat() == static_cast<const SwFormatField&>(rAttr).mpField->GetFormat() )
208 ||
209 ( !mpField && !static_cast<const SwFormatField&>(rAttr).mpField );
210}
211
213{
214 return new SwFormatField( *this );
215}
216
218{
219 const SwPtrMsgPoolItem aItem(RES_REMOVE_UNO_OBJECT, &static_cast<sw::BroadcastingModify&>(*this));
220 CallSwClientNotify(sw::LegacyModifyHint{ &aItem, &aItem });
221}
222
223void SwFormatField::SwClientNotify( const SwModify& rModify, const SfxHint& rHint )
224{
225 SwClient::SwClientNotify(rModify, rHint);
226 if (rHint.GetId() == SfxHintId::SwField)
227 {
228 const auto pFieldHint = static_cast<const SwFieldHint*>( &rHint );
229 // replace field content by text
230 SwPaM* pPaM = pFieldHint->m_pPaM;
231 pPaM->DeleteMark(); // TODO: this is really hackish
232
233 if( !mpTextField )
234 return;
235
236 SwDoc& rDoc = pPaM->GetDoc();
237 const SwTextNode& rTextNode = mpTextField->GetTextNode();
238 pPaM->GetPoint()->Assign(rTextNode, mpTextField->GetStart());
239
240 OUString const aEntry(mpField->ExpandField(rDoc.IsClipBoard(), pFieldHint->m_pLayout));
241 pPaM->SetMark();
242 pPaM->Move( fnMoveForward );
244 rDoc.getIDocumentContentOperations().InsertString( *pPaM, aEntry );
245 }
246 else if (rHint.GetId() == SfxHintId::SwLegacyModify)
247 {
248 auto pLegacyHint = static_cast<const sw::LegacyModifyHint*>(&rHint);
249 if( !mpTextField )
250 return;
251 UpdateTextNode(pLegacyHint->m_pOld, pLegacyHint->m_pNew);
252 }
253 else if (rHint.GetId() == SfxHintId::SwFindFormatForField)
254 {
255 const auto pFindForFieldHint = static_cast<const sw::FindFormatForFieldHint*>( &rHint );
256 if(pFindForFieldHint->m_rpFormat == nullptr && pFindForFieldHint->m_pField == GetField())
257 pFindForFieldHint->m_rpFormat = this;
258 }
259 else if (rHint.GetId() == SfxHintId::SwFindFormatForPostItId)
260 {
261 const auto pFindForPostItIdHint = static_cast<const sw::FindFormatForPostItIdHint*>( &rHint );
262 auto pPostItField = dynamic_cast<SwPostItField*>(mpField.get());
263 if(pPostItField && pFindForPostItIdHint->m_rpFormat == nullptr && pFindForPostItIdHint->m_nPostItId == pPostItField->GetPostItId())
264 pFindForPostItIdHint->m_rpFormat = this;
265 }
266 else if (rHint.GetId() == SfxHintId::SwCollectPostIts)
267 {
268 const auto pCollectPostItsHint = static_cast<const sw::CollectPostItsHint*>( &rHint );
269 if(GetTextField() && IsFieldInDoc() && (!pCollectPostItsHint->m_bHideRedlines || !sw::IsFieldDeletedInModel(pCollectPostItsHint->m_rIDRA, *GetTextField())))
270 pCollectPostItsHint->m_rvFormatFields.push_back(this);
271 }
272 else if (rHint.GetId() == SfxHintId::SwHasHiddenInformationNotes)
273 {
274 const auto pHasHiddenInfoHint = static_cast<const sw::HasHiddenInformationNotesHint*>( &rHint );
275 if(!pHasHiddenInfoHint->m_rbHasHiddenInformationNotes && GetTextField() && IsFieldInDoc())
276 pHasHiddenInfoHint->m_rbHasHiddenInformationNotes = true;
277 }
278 else if (rHint.GetId() == SfxHintId::SwGatherNodeIndex)
279 {
280 const auto pGatherNodeIndexHint = static_cast<const sw::GatherNodeIndexHint*>( &rHint );
281 if(auto pTextField = GetTextField())
282 pGatherNodeIndexHint->m_rvNodeIndex.push_back(pTextField->GetTextNode().GetIndex());
283 }
284 else if (rHint.GetId() == SfxHintId::SwGatherRefFields)
285 {
286 const auto pGatherRefFieldsHint = static_cast<const sw::GatherRefFieldsHint*>( &rHint );
287 if(!GetTextField() || pGatherRefFieldsHint->m_nType != GetField()->GetSubType())
288 return;
290 if(pNd && pNd->GetNodes().IsDocNodes())
291 pGatherRefFieldsHint->m_rvRFields.push_back(static_cast<SwGetRefField*>(GetField()));
292 }
293 else if (rHint.GetId() == SfxHintId::SwGatherFields)
294 {
295 const auto pGatherFieldsHint = static_cast<const sw::GatherFieldsHint*>( &rHint );
296 if(pGatherFieldsHint->m_bCollectOnlyInDocNodes)
297 {
298 if(!GetTextField())
299 return;
301 if(!pNd || !pNd->GetNodes().IsDocNodes())
302 return;
303 }
304 pGatherFieldsHint->m_rvFields.push_back(this);
305 }
306}
307
309{
310 if (pOld && (RES_REMOVE_UNO_OBJECT == pOld->Which()))
311 { // invalidate cached UNO object
312 m_wXTextField.clear();
313 // ??? why does this Modify method not already do this?
315 return;
316 }
317
318 if (!IsFieldInDoc())
319 return;
320
321 // don't do anything, especially not expand!
322 if( pNew && pNew->Which() == RES_OBJECTDYING )
323 return;
324
325 SwTextNode* pTextNd = &mpTextField->GetTextNode();
326 OSL_ENSURE( pTextNd, "Where is my Node?" );
327
328 bool bTriggerNode = false;
329 bool bExpand = false;
330 const SfxPoolItem* pNodeOld = nullptr;
331 const SfxPoolItem* pNodeNew = nullptr;
332 if(pNew)
333 {
334 switch(pNew->Which())
335 {
337 // update GetRef fields
338 if( SwFieldIds::GetRef == mpField->GetTyp()->Which() )
339 {
340 // #i81002#
341 static_cast<SwGetRefField*>(mpField.get())->UpdateField( mpTextField );
342 }
343 break;
345 // handled in SwTextFrame::Modify()
346 bTriggerNode = true;
347 pNodeOld = pNew;
348 pNodeNew = this;
349 break;
350 case RES_ATTRSET_CHG:
351 case RES_FMT_CHG:
352 bTriggerNode = true;
353 pNodeOld = pOld;
354 pNodeNew = pNew;
355 break;
356 default:
357 break;
358 }
359 }
360 if(!bTriggerNode)
361 {
362 switch (mpField->GetTyp()->Which())
363 {
365 if( !pOld || pOld->Which() != RES_HIDDENPARA_PRINT ) {
366 bExpand =true;
367 break;
368 }
369 [[fallthrough]];
374 bTriggerNode = true;
375 pNodeNew = pNew;
376 break;
377 case SwFieldIds::User:
378 {
379 SwUserFieldType* pType = static_cast<SwUserFieldType*>(mpField->GetTyp());
380 if(!pType->IsValid())
381 {
382 SwCalc aCalc( pTextNd->GetDoc() );
383 pType->GetValue( aCalc );
384 }
385 bExpand = true;
386 }
387 break;
388 default:
389 bExpand = true;
390 break;
391 }
392 }
393 if(bTriggerNode)
394 pTextNd->TriggerNodeUpdate(sw::LegacyModifyHint(pNodeOld, pNodeNew));
395 if(!bExpand)
396 return;
397
398 bool bForceNotify = pOld == nullptr && pNew == nullptr;
399 if (bForceNotify)
400 {
401 // Force notify was added for conditional text fields, at least the below fields need
402 // no forced notify.
403 const SwField* pField = mpTextField->GetFormatField().GetField();
404 const SwFieldIds nWhich = pField->GetTyp()->Which();
405 if (nWhich == SwFieldIds::DocInfo)
406 {
407 auto pDocInfoField = static_cast<const SwDocInfoField*>(pField);
408 sal_uInt16 nSubType = pDocInfoField->GetSubType();
409 // Do not consider extended SubTypes.
410 nSubType &= 0xff;
411 switch (nSubType)
412 {
417 bForceNotify = false;
418 break;
419 }
420 }
421 }
422
423 mpTextField->ExpandTextField(bForceNotify);
424}
425
427{
428 if( RES_AUTOFMT_DOCNODE != rInfo.Which() || !mpTextField )
429 return true;
430 const SwTextNode* pTextNd = mpTextField->GetpTextNode();
431 return nullptr == pTextNd ||
432 &pTextNd->GetNodes() != static_cast<SwAutoFormatGetDocNode&>(rInfo).pNodes;
433}
434
436{
437 return mpTextField != nullptr
439}
440
442{
443 return mpTextField != nullptr
444 && mpTextField->GetpTextNode() != nullptr
446}
447
449{
450 (void)xmlTextWriterStartElement(pWriter, BAD_CAST("SwFormatField"));
451 (void)xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("ptr"), "%p", this);
452 (void)xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("mpTextField"), "%p", mpTextField);
453
454 SfxPoolItem::dumpAsXml(pWriter);
455 if (mpField) // pool default doesn't have one
456 {
457 mpField->dumpAsXml(pWriter);
458 }
459
460 (void)xmlTextWriterEndElement(pWriter);
461}
462
463// class SwTextField ////////////////////////////////////////////////////
464
466 SwFormatField & rAttr,
467 sal_Int32 const nStartPos,
468 bool const bInClipboard)
469 : SwTextAttr( rAttr, nStartPos )
470// fdo#39694 the ExpandField here may not give the correct result in all cases,
471// but is better than nothing
472 , m_aExpand( rAttr.GetField()->ExpandField(bInClipboard, nullptr) )
473 , m_pTextNode( nullptr )
474{
475 rAttr.SetTextField( *this );
476 SetHasDummyChar(true);
477}
478
480{
481 SwFormatField & rFormatField( static_cast<SwFormatField &>(GetAttr()) );
482 if ( this == rFormatField.GetTextField() )
483 {
484 rFormatField.ClearTextField();
485 }
486}
487
489{
490 return GetpTextNode() != nullptr
492}
493
494void SwTextField::ExpandTextField(const bool bForceNotify) const
495{
496 OSL_ENSURE( m_pTextNode, "SwTextField: where is my TextNode?" );
497
498 const SwField* pField = GetFormatField().GetField();
499 const OUString aNewExpand( pField->ExpandField(m_pTextNode->GetDoc().IsClipBoard(),
500 // can't do any better than this here...
502
503 const SwFieldIds nWhich = pField->GetTyp()->Which();
504 const bool bSameExpandSimpleNotification
505 = SwFieldIds::Chapter != nWhich && SwFieldIds::PageNumber != nWhich
506 && SwFieldIds::RefPageGet != nWhich
507 // Page count fields to not use aExpand during formatting,
508 // therefore an invalidation of the text frame has to be triggered even if aNewExpand == aExpand:
509 && (SwFieldIds::DocStat != nWhich
510 || DS_PAGE != static_cast<const SwDocStatField*>(pField)->GetSubType())
511 && (SwFieldIds::GetExp != nWhich
512 || static_cast<const SwGetExpField*>(pField)->IsInBodyText());
513
514 bool bHiddenParaChanged = false;
515 if (aNewExpand != m_aExpand || bSameExpandSimpleNotification)
516 bHiddenParaChanged = m_pTextNode->CalcHiddenParaField();
517
518 if (aNewExpand == m_aExpand)
519 {
520 if ( bSameExpandSimpleNotification )
521 {
522 if( bHiddenParaChanged )
524 if ( !bForceNotify )
525 {
526 // done, if no further notification forced.
527 return;
528 }
529 }
530 }
531 else
532 m_aExpand = aNewExpand;
533
534 const_cast<SwTextField*>(this)->NotifyContentChange( const_cast<SwFormatField&>(GetFormatField()) );
535}
536
538{
539 OSL_ENSURE( m_pTextNode, "SwTextField: where is my TextNode?" );
540 OSL_ENSURE( pDest->m_pTextNode, "SwTextField: where is pDest's TextNode?" );
541
544
545 SwFormatField& rDestFormatField = const_cast<SwFormatField&>(pDest->GetFormatField());
546 const SwFieldIds nFieldWhich = rDestFormatField.GetField()->GetTyp()->Which();
547
548 if( pIDFA != pDestIDFA )
549 {
550 // different documents, e.g. clipboard:
551 // register field type in target document
552 SwFieldType* pFieldType;
553 if( nFieldWhich != SwFieldIds::Database
554 && nFieldWhich != SwFieldIds::User
555 && nFieldWhich != SwFieldIds::SetExp
556 && nFieldWhich != SwFieldIds::Dde
557 && SwFieldIds::TableOfAuthorities != nFieldWhich )
558 {
559 pFieldType = pDestIDFA->GetSysFieldType( nFieldWhich );
560 }
561 else
562 {
563 pFieldType = pDestIDFA->InsertFieldType( *rDestFormatField.GetField()->GetTyp() );
564 }
565
566 // DDE fields need special treatment
567 if( SwFieldIds::Dde == nFieldWhich )
568 {
569 if( rDestFormatField.GetTextField() )
570 {
571 static_cast<SwDDEFieldType*>(rDestFormatField.GetField()->GetTyp())->DecRefCnt();
572 }
573 static_cast<SwDDEFieldType*>(pFieldType)->IncRefCnt();
574 }
575
576 OSL_ENSURE( pFieldType, "unknown FieldType" );
577 pFieldType->Add( &rDestFormatField ); // register at the field type
578 rDestFormatField.GetField()->ChgTyp( pFieldType );
579 }
580
581 // update expression fields
582 if( nFieldWhich == SwFieldIds::SetExp
583 || nFieldWhich == SwFieldIds::GetExp
584 || nFieldWhich == SwFieldIds::HiddenText )
585 {
586 SwTextField* pField = const_cast<SwTextField*>(this);
587 pDestIDFA->UpdateExpFields( pField, true );
588 }
589 // table fields: external display
590 else if( SwFieldIds::Table == nFieldWhich
591 && static_cast<SwTableField*>(rDestFormatField.GetField())->IsIntrnlName() )
592 {
593 // convert internal (core) to external (UI) formula
594 const SwTableNode* pTableNd = m_pTextNode->FindTableNode();
595 if( pTableNd ) // in a table?
596 static_cast<SwTableField*>(rDestFormatField.GetField())->PtrToBoxNm( &pTableNd->GetTable() );
597 }
598}
599
601{
602 //if not in undo section notify the change
604 m_pTextNode->TriggerNodeUpdate(sw::LegacyModifyHint(nullptr, &rFormatField));
605}
606
607/*static*/
609 const SwTextField& rTextField,
610 std::shared_ptr< SwPaM >& rPamForTextField )
611{
612 if (rTextField.GetpTextNode() == nullptr)
613 {
614 SAL_WARN("sw.core", "<SwTextField::GetPamForField> - missing <SwTextNode>");
615 return;
616 }
617
618 const SwTextNode& rTextNode = rTextField.GetTextNode();
619
620 rPamForTextField = std::make_shared<SwPaM>( rTextNode,
621 (rTextField.End() != nullptr) ? *(rTextField.End()) : ( rTextField.GetStart() + 1 ),
622 rTextNode,
623 rTextField.GetStart() );
624
625}
626
627/*static*/
629{
630 if (rTextField.GetpTextNode() != nullptr)
631 {
632 std::shared_ptr< SwPaM > pPamForTextField;
633 GetPamForTextField(rTextField, pPamForTextField);
634 if (pPamForTextField != nullptr)
635 {
636 rTextField.GetTextNode().GetDoc().getIDocumentContentOperations().DeleteAndJoin(*pPamForTextField);
637 }
638 }
639}
640
641// class SwTextInputField ///////////////////////////////////////////////
642
643// input field in-place editing
645 SwFormatField & rAttr,
646 sal_Int32 const nStart,
647 sal_Int32 const nEnd,
648 bool const bInClipboard )
649
650 : SwTextAttr( rAttr, nStart )
651 , SwTextAttrNesting( rAttr, nStart, nEnd )
652 , SwTextField( rAttr, nStart, bInClipboard )
653 , m_bLockNotifyContentChange( false )
654{
655 SetHasDummyChar( false );
656 SetHasContent( true );
657}
658
660{
661}
662
664{
666 {
667 return false;
668 }
670 return true;
671}
672
674{
676}
677
679{
681 {
683
684 SwTextField::NotifyContentChange( rFormatField );
686
688 }
689}
690
692{
693 return GetFormatField().GetField()->ExpandField(false, nullptr/*ignored anyway*/);
694}
695
697{
698 if ( !(IsFieldInDoc()
699 && GetStart() != (*End())) )
700 return;
701
702 assert( (*End()) - GetStart() >= 2 &&
703 "<SwTextInputField::UpdateFieldContent()> - Are CH_TXT_ATR_INPUTFIELDSTART and/or CH_TXT_ATR_INPUTFIELDEND missing?" );
704 // skip CH_TXT_ATR_INPUTFIELDSTART character
705 const sal_Int32 nIdx = GetStart() + 1;
706 // skip CH_TXT_ATR_INPUTFIELDEND character
707 const sal_Int32 nLen = static_cast<sal_Int32>(std::max<sal_Int32>( 0, ( (*End()) - 1 - nIdx ) ));
708 const OUString aNewFieldContent = GetTextNode().GetExpandText(nullptr, nIdx, nLen);
709
710 const SwField* pField = GetFormatField().GetField();
711 const SwInputField* pInputField = dynamic_cast<const SwInputField*>(pField);
712 if (pInputField)
713 const_cast<SwInputField*>(pInputField)->applyFieldContent( aNewFieldContent );
714
715 const SwSetExpField* pExpField = dynamic_cast<const SwSetExpField*>(pField);
716 if (pExpField)
717 {
718 assert(pExpField->GetInputFlag());
719 const_cast<SwSetExpField*>(pExpField)->SetPar2(aNewFieldContent);
720 }
721 assert(pInputField || pExpField);
722
723 // trigger update of fields for scenarios in which the Input Field's content is part of e.g. a table formula
725}
726
727void SwTextInputField::UpdateTextNodeContent( const OUString& rNewContent )
728{
729 assert(IsFieldInDoc() &&
730 "<SwTextInputField::UpdateTextNodeContent(..)> - misusage as Input Field is not in document content.");
731
732 assert( (*End()) - GetStart() >= 2 &&
733 "<SwTextInputField::UpdateTextNodeContent(..)> - Are CH_TXT_ATR_INPUTFIELDSTART and/or CH_TXT_ATR_INPUTFIELDEND missing?" );
734 // skip CH_TXT_ATR_INPUTFIELDSTART character
735 const sal_Int32 nIdx = GetStart() + 1;
736 // skip CH_TXT_ATR_INPUTFIELDEND character
737 const sal_Int32 nDelLen = std::max<sal_Int32>( 0, ( (*End()) - 1 - nIdx ) );
738 SwContentIndex aIdx( &GetTextNode(), nIdx );
739 GetTextNode().ReplaceText( aIdx, nDelLen, rNewContent );
740}
741
742// class SwTextAnnotationField //////////////////////////////////////////
743
744// text annotation field
746 SwFormatField & rAttr,
747 sal_Int32 const nStart,
748 bool const bInClipboard )
749 : SwTextAttr( rAttr, nStart )
750 , SwTextField( rAttr, nStart, bInClipboard )
751{
752}
753
755{
756}
757
759{
760 auto pPostItField = dynamic_cast<const SwPostItField*>(GetFormatField().GetField());
761 assert(pPostItField);
762
763 SwDoc& rDoc = static_cast<const SwPostItFieldType*>(pPostItField->GetTyp())->GetDoc();
764
765 IDocumentMarkAccess* pMarksAccess = rDoc.getIDocumentMarkAccess();
766 IDocumentMarkAccess::const_iterator_t pMark = pMarksAccess->findAnnotationMark( pPostItField->GetName() );
767 return pMark != pMarksAccess->getAnnotationMarksEnd()
768 ? *pMark
769 : nullptr;
770}
771
773{ m_wXTextField = xTextField.get(); }
774
775/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
struct _xmlTextWriter * xmlTextWriterPtr
virtual bool DeleteAndJoin(SwPaM &, SwDeleteFlags flags=SwDeleteFlags::Default)=0
complete delete of a given PaM
virtual void DeleteRange(SwPaM &)=0
Delete a range SwFlyFrameFormat.
virtual bool InsertString(const SwPaM &rRg, const OUString &, const SwInsertFlags nInsertMode=SwInsertFlags::EMPTYEXPAND)=0
Insert string into existing text node at position rRg.Point().
Document fields related interfaces.
virtual SwFieldType * GetSysFieldType(const SwFieldIds eWhich) const =0
virtual SwFieldType * InsertFieldType(const SwFieldType &)=0
virtual SwDocUpdateField & GetUpdateFields() const =0
virtual void UpdateExpFields(SwTextField *pField, bool bUpdateRefFields)=0
virtual const SwRootFrame * GetCurrentLayout() const =0
wrapper iterator: wraps iterator of implementation while hiding MarkBase class; only IMark instances ...
Provides access to the marks of a document.
virtual const_iterator_t getAnnotationMarksEnd() const =0
virtual const_iterator_t findAnnotationMark(const OUString &rName) const =0
void Broadcast(const SfxHint &rHint)
SfxHintId GetId() const
virtual void dumpAsXml(xmlTextWriterPtr pWriter) const
sal_uInt16 Which() const
void SetWhich(sal_uInt16 nId)
Definition: calc.hxx:199
virtual void SwClientNotify(const SwModify &, const SfxHint &rHint) override
Definition: calbck.cxx:120
Marks a character position inside a document model content node (SwContentNode)
virtual sal_uInt16 GetSubType() const override
Definition: docufld.cxx:1141
void SetFieldsDirty(bool b)
Definition: docfld.hxx:178
Definition: doc.hxx:192
bool IsClipBoard() const
Definition: doc.hxx:967
IDocumentContentOperations const & getIDocumentContentOperations() const
Definition: doc.cxx:316
IDocumentFieldsAccess const & getIDocumentFieldsAccess() const
Definition: doc.cxx:358
IDocumentLayoutAccess const & getIDocumentLayoutAccess() const
Definition: doc.cxx:406
IDocumentMarkAccess * getIDocumentMarkAccess()
Definition: docbm.cxx:1793
Instances of SwFields and those derived from it occur 0 to n times.
Definition: fldbas.hxx:242
SwFieldIds Which() const
Definition: fldbas.hxx:273
Base class of all fields.
Definition: fldbas.hxx:292
virtual sal_uInt16 GetSubType() const
Definition: fldbas.cxx:342
OUString ExpandField(bool bCached, SwRootFrame const *pLayout) const
expand the field.
Definition: fldbas.cxx:484
virtual SwFieldType * ChgTyp(SwFieldType *)
Set new type (used for copying among documents).
Definition: fldbas.cxx:402
SwFieldType * GetTyp() const
Definition: fldbas.hxx:398
SwFormatField(sal_uInt16 nWhich)
Definition: atrfld.cxx:49
bool IsFieldInDoc() const
Definition: atrfld.cxx:435
virtual bool operator==(const SfxPoolItem &) const override
"Pure virtual methods" of SfxPoolItem.
Definition: atrfld.cxx:201
const SwField * GetField() const
Definition: fmtfld.hxx:130
std::unique_ptr< SwField > mpField
Definition: fmtfld.hxx:108
bool IsProtect() const
Definition: atrfld.cxx:441
unotools::WeakReference< SwXTextField > m_wXTextField
Definition: fmtfld.hxx:106
virtual ~SwFormatField() override
Definition: atrfld.cxx:132
const SwTextField * GetTextField() const
Definition: fmtfld.hxx:148
void SetTextField(SwTextField &rTextField)
Definition: atrfld.cxx:191
virtual SwFormatField * Clone(SfxItemPool *pPool=nullptr) const override
Definition: atrfld.cxx:212
void SetField(std::unique_ptr< SwField > pField)
Sets current field.
Definition: atrfld.cxx:176
void InvalidateField()
Definition: atrfld.cxx:217
virtual void SwClientNotify(const SwModify &rModify, const SfxHint &rHint) override
Definition: atrfld.cxx:223
virtual bool GetInfo(SfxPoolItem &rInfo) const override
Definition: atrfld.cxx:426
void RegisterToFieldType(SwFieldType &)
Definition: atrfld.cxx:171
SAL_DLLPRIVATE void SetXTextField(rtl::Reference< SwXTextField > const &xTextField)
Definition: atrfld.cxx:772
void UpdateTextNode(const SfxPoolItem *pOld, const SfxPoolItem *pNew)
Definition: atrfld.cxx:308
SwTextField * mpTextField
Definition: fmtfld.hxx:109
void dumpAsXml(xmlTextWriterPtr pWriter) const override
Definition: atrfld.cxx:448
void ClearTextField()
Definition: atrfld.cxx:196
bool IsInBodyText() const
Called by formatting.
Definition: expfld.hxx:139
void SetFormatField(SwFormatField &rFormatField)
Definition: expfld.cxx:1236
void Add(SwClient *pDepend)
Definition: calbck.cxx:172
SwClient * Remove(SwClient *pDepend)
Definition: calbck.cxx:225
bool HasOnlyOneListener() const
Definition: calbck.hxx:203
bool IsProtect() const
Is node in something that is protected (range, frame, table cells ... including anchor in case of fra...
Definition: node.cxx:439
SwNodes & GetNodes()
Node is in which nodes-array/doc?
Definition: node.hxx:722
SwDoc & GetDoc()
Definition: node.hxx:217
SwTableNode * FindTableNode()
Search table node, in which it is.
Definition: node.cxx:370
const IDocumentFieldsAccess & getIDocumentFieldsAccess() const
Provides access to the document fields administration interface.
Definition: node.cxx:2156
bool IsDocNodes() const
Is the NodesArray the regular one of Doc? (and not the UndoNds, ...) Implementation in doc....
Definition: nodes.cxx:2531
PaM is Point and Mark: a selection of the document model.
Definition: pam.hxx:187
virtual void SetMark()
Unless this is called, the getter method of Mark will return Point.
Definition: pam.cxx:642
bool Move(SwMoveFnCollection const &fnMove=fnMoveForward, SwGoInDoc fnGo=GoInContent)
Movement of cursor.
Definition: pam.cxx:668
SwDoc & GetDoc() const
Definition: pam.hxx:299
void DeleteMark()
Definition: pam.hxx:231
const SwPosition * GetPoint() const
Definition: pam.hxx:261
sal_uInt16 GetType() const
Definition: expfld.hxx:198
void SetFormatField(SwFormatField &rFormatField)
Definition: expfld.cxx:830
bool GetInputFlag() const
Definition: expfld.hxx:269
bool IsIntrnlName() const
Definition: cellfml.hxx:132
const SwTable & GetTable() const
Definition: node.hxx:522
::sw::mark::IMark * GetAnnotationMark() const
Definition: atrfld.cxx:758
virtual ~SwTextAnnotationField() override
Definition: atrfld.cxx:754
SwTextAnnotationField(SwFormatField &rAttr, sal_Int32 const nStart, bool const bInClipboard)
Definition: atrfld.cxx:745
A wrapper around SfxPoolItem to store the start position of (usually) a text portion,...
Definition: txatbase.hxx:44
const SfxPoolItem & GetAttr() const
Definition: txatbase.hxx:167
const sal_Int32 * End() const
Definition: txatbase.hxx:156
sal_Int32 GetStart() const
Definition: txatbase.hxx:88
void SetHasContent(const bool bFlag)
Definition: txatbase.hxx:79
void SetHasDummyChar(const bool bFlag)
Definition: txatbase.hxx:78
const SwFormatField & GetFormatField() const
Definition: txatbase.hxx:199
void CopyTextField(SwTextField *pDest) const
Definition: atrfld.cxx:537
SwTextNode & GetTextNode() const
Definition: txtfld.hxx:53
void ExpandTextField(const bool bForceNotify=false) const
Definition: atrfld.cxx:494
virtual ~SwTextField() override
Definition: atrfld.cxx:479
bool IsFieldInDoc() const
Definition: atrfld.cxx:488
SwTextNode * m_pTextNode
Definition: txtfld.hxx:34
OUString m_aExpand
Definition: txtfld.hxx:33
virtual void NotifyContentChange(SwFormatField &rFormatField)
Definition: atrfld.cxx:600
SwTextNode * GetpTextNode() const
Definition: txtfld.hxx:49
static void DeleteTextField(const SwTextField &rTextField)
Definition: atrfld.cxx:628
SwTextField(SwFormatField &rAttr, sal_Int32 const nStart, bool const bInClipboard)
Definition: atrfld.cxx:465
static void GetPamForTextField(const SwTextField &rTextField, std::shared_ptr< SwPaM > &rPamForTextField)
Definition: atrfld.cxx:608
bool m_bLockNotifyContentChange
Definition: txtfld.hxx:101
void UpdateTextNodeContent(const OUString &rNewContent)
Definition: atrfld.cxx:727
OUString GetFieldContent() const
Definition: atrfld.cxx:691
void UnlockNotifyContentChange()
Definition: atrfld.cxx:673
SwTextInputField(SwFormatField &rAttr, sal_Int32 const nStart, sal_Int32 const nEnd, bool const bInClipboard)
Definition: atrfld.cxx:644
void UpdateFieldContent()
Definition: atrfld.cxx:696
virtual ~SwTextInputField() override
Definition: atrfld.cxx:659
virtual void NotifyContentChange(SwFormatField &rFormatField) override
Definition: atrfld.cxx:678
bool LockNotifyContentChange()
Definition: atrfld.cxx:663
SwTextNode is a paragraph in the document model.
Definition: ndtxt.hxx:89
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|ExpandMode::HideFieldmarkCommands) const
add 4th optional parameter <bAddSpaceAfterListLabelStr> indicating, when <bWithNum = true> that a spa...
Definition: ndtxt.cxx:3468
bool CalcHiddenParaField()
Hidden Paragraph Field:
Definition: ndtxt.hxx:738
void ReplaceText(const SwContentIndex &rStart, const sal_Int32 nDelLen, const OUString &rText)
replace nDelLen characters at rStart with rText in case the replacement does not fit,...
Definition: ndtxt.cxx:3771
void TriggerNodeUpdate(const sw::LegacyModifyHint &)
for hanging TextFormatCollections somewhere else (Outline-Numbering!)
Definition: ndtxt.cxx:5402
The shared part of a user field.
Definition: usrfld.hxx:35
double GetValue(SwCalc &rCalc)
Definition: usrfld.cxx:236
bool IsValid() const
Definition: usrfld.hxx:78
virtual void CallSwClientNotify(const SfxHint &rHint) const override
Definition: calbck.cxx:325
@ DS_PAGE
Definition: docufld.hxx:54
SwFieldIds
Definition: fldbas.hxx:45
@ Database
For old documents the Field-Which IDs must be preserved !!!
@ TableOfAuthorities
constexpr TypedWhichId< SwPtrMsgPoolItem > RES_REMOVE_UNO_OBJECT(181)
constexpr TypedWhichId< SwRefMarkFieldUpdate > RES_REFMARKFLD_UPDATE(168)
constexpr TypedWhichId< SwMsgPoolItem > RES_HIDDENPARA_PRINT(178)
constexpr TypedWhichId< SwPtrMsgPoolItem > RES_OBJECTDYING(RES_MSG_BEGIN)
constexpr TypedWhichId< SwFormatField > RES_TXTATR_ANNOTATION(60)
constexpr TypedWhichId< SwDocPosUpdate > RES_DOCPOS_UPDATE(169)
constexpr TypedWhichId< SwFormatChg > RES_FMT_CHG(162)
constexpr TypedWhichId< SwFormatField > RES_TXTATR_FIELD(RES_TXTATR_NOEND_BEGIN)
constexpr TypedWhichId< SwAttrSetChg > RES_ATTRSET_CHG(163)
constexpr TypedWhichId< SwAutoFormatGetDocNode > RES_AUTOFMT_DOCNODE(173)
constexpr TypedWhichId< SwFormatField > RES_TXTATR_INPUTFIELD(55)
#define SAL_WARN(area, stream)
const SwDocInfoSubType DI_CUSTOM
Definition: docufld.hxx:80
const SwDocInfoSubType DI_CHANGE
Definition: docufld.hxx:76
const SwDocInfoSubType DI_SUBJECT
Definition: docufld.hxx:72
const SwDocInfoSubType DI_TITLE
Definition: docufld.hxx:71
const SwGetSetExpType GSE_STRING
String.
Definition: fldbas.hxx:203
bool IsFieldDeletedInModel(IDocumentRedlineAccess const &rIDRA, SwTextField const &rTextField)
SwMoveFnCollection const & fnMoveForward
SwPam::Move()/Find() default argument.
Definition: paminit.cxx:61
void Assign(const SwNode &rNd, SwNodeOffset nDelta, sal_Int32 nContentOffset=0)
These all set both nNode and nContent.
Definition: pam.cxx:230
std::vector< SwFormatField * > & m_rvFormatFields
Definition: fmtfld.hxx:57
SwFormatField *& m_rpFormat
Definition: fmtfld.hxx:46
std::vector< SwNodeOffset > & m_rvNodeIndex
Definition: fmtfld.hxx:71