LibreOffice Module sc (master)  1
textuno.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 <memory>
21 #include <sal/config.h>
22 #include <sal/log.hxx>
23 
24 #include <scitems.hxx>
25 #include <editeng/eeitem.hxx>
26 #include <svx/svdpool.hxx>
27 #include <svx/svdobj.hxx>
28 #include <editeng/editeng.hxx>
29 #include <editeng/editobj.hxx>
30 #include <editeng/flditem.hxx>
31 #include <editeng/fhgtitem.hxx>
32 #include <editeng/unoprnms.hxx>
33 #include <editeng/unofored.hxx>
34 #include <vcl/svapp.hxx>
35 
36 #include <editeng/unoipset.hxx>
37 #include <textuno.hxx>
38 #include <fielduno.hxx>
39 #include <editsrc.hxx>
40 #include <docsh.hxx>
41 #include <editutil.hxx>
42 #include <miscuno.hxx>
43 #include <cellsuno.hxx>
44 #include <cellvalue.hxx>
45 #include <cellform.hxx>
46 #include <patattr.hxx>
47 #include <docfunc.hxx>
48 #include <scmod.hxx>
49 
50 using namespace com::sun::star;
51 
53 {
54  static const SvxItemPropertySet aHdFtPropertySet_Impl = [] {
55  static SfxItemPropertyMapEntry aHdFtPropertyMap_Impl[] =
56  {
60  SVX_UNOEDIT_NUMBERING_PROPERTIE, // for completeness of service ParagraphProperties
61  { u"", 0, css::uno::Type(), 0, 0 }
62  };
63 
64  // modify PropertyMap to include CONVERT_TWIPS flag for font height
65  // (headers/footers are in twips)
66 
67  SfxItemPropertyMapEntry* pEntry = aHdFtPropertyMap_Impl;
68  while (!pEntry->aName.isEmpty())
69  {
70  if ( ( pEntry->nWID == EE_CHAR_FONTHEIGHT ||
71  pEntry->nWID == EE_CHAR_FONTHEIGHT_CJK ||
72  pEntry->nWID == EE_CHAR_FONTHEIGHT_CTL ) &&
73  pEntry->nMemberId == MID_FONTHEIGHT )
74  {
75  pEntry->nMemberId |= CONVERT_TWIPS;
76  }
77 
78  ++pEntry;
79  }
80 
81  return SvxItemPropertySet(aHdFtPropertyMap_Impl, SdrObject::GetGlobalDrawObjectItemPool());
82  }();
83  return &aHdFtPropertySet_Impl;
84 }
85 
86 SC_SIMPLE_SERVICE_INFO( ScHeaderFooterContentObj, "ScHeaderFooterContentObj", "com.sun.star.sheet.HeaderFooterContent" )
87 SC_SIMPLE_SERVICE_INFO( ScHeaderFooterTextObj, "ScHeaderFooterTextObj", "stardiv.one.Text.Text" )
88 
90 {
91 }
92 
94 
96 {
97  return mxLeftText->GetTextObject();
98 }
99 
101 {
102  return mxCenterText->GetTextObject();
103 }
104 
106 {
107  return mxRightText->GetTextObject();
108 }
109 
110 // XHeaderFooterContent
111 
112 uno::Reference<text::XText> SAL_CALL ScHeaderFooterContentObj::getLeftText()
113 {
114  SolarMutexGuard aGuard;
115  uno::Reference<text::XText> xInt(*mxLeftText, uno::UNO_QUERY);
116  return xInt;
117 }
118 
119 uno::Reference<text::XText> SAL_CALL ScHeaderFooterContentObj::getCenterText()
120 {
121  SolarMutexGuard aGuard;
122  uno::Reference<text::XText> xInt(*mxCenterText, uno::UNO_QUERY);
123  return xInt;
124 }
125 
126 uno::Reference<text::XText> SAL_CALL ScHeaderFooterContentObj::getRightText()
127 {
128  SolarMutexGuard aGuard;
129  uno::Reference<text::XText> xInt(*mxRightText, uno::UNO_QUERY);
130  return xInt;
131 }
132 
133 // XUnoTunnel
134 
136  const uno::Sequence<sal_Int8 >& rId )
137 {
138  return comphelper::getSomethingImpl(rId, this);
139 }
140 
141 const uno::Sequence<sal_Int8>& ScHeaderFooterContentObj::getUnoTunnelId()
142 {
143  static const comphelper::UnoIdInit theScHeaderFooterContentObjUnoTunnelId;
144  return theScHeaderFooterContentObjUnoTunnelId.getSeq();
145 }
146 
148  const uno::Reference<sheet::XHeaderFooterContent>& rObj)
149 {
150  return comphelper::getFromUnoTunnel<ScHeaderFooterContentObj>(rObj);
151 }
152 
154  const EditTextObject* pCenter,
155  const EditTextObject* pRight )
156 {
157  uno::Reference<css::sheet::XHeaderFooterContent> xThis(this);
161 }
162 
164  uno::WeakReference<sheet::XHeaderFooterContent> const & xContent, ScHeaderFooterPart nP, const EditTextObject* pTextObj) :
165  mpTextObj(pTextObj ? pTextObj->Clone() : nullptr),
166  xContentObj( xContent ),
167  nPart( nP ),
168  bDataValid(false)
169 {
170 }
171 
173 {
174  SolarMutexGuard aGuard; // needed for EditEngine dtor
175 
176  pForwarder.reset();
177  pEditEngine.reset();
178 }
179 
181 {
182  if (!pEditEngine)
183  {
185  pEnginePool->FreezeIdRanges();
186  std::unique_ptr<ScHeaderEditEngine> pHdrEngine(new ScHeaderEditEngine( pEnginePool.get() ));
187 
188  pHdrEngine->EnableUndo( false );
189  pHdrEngine->SetRefMapMode(MapMode(MapUnit::MapTwip));
190 
191  // default font must be set, independently of document
192  // -> use global pool from module
193 
194  SfxItemSet aDefaults( pHdrEngine->GetEmptyItemSet() );
195  const ScPatternAttr& rPattern = SC_MOD()->GetPool().GetDefaultItem(ATTR_PATTERN);
196  rPattern.FillEditItemSet( &aDefaults );
197  // FillEditItemSet adjusts font height to 1/100th mm,
198  // but for header/footer twips is needed, as in the PatternAttr:
199  aDefaults.Put( rPattern.GetItem(ATTR_FONT_HEIGHT).CloneSetWhich(EE_CHAR_FONTHEIGHT) );
200  aDefaults.Put( rPattern.GetItem(ATTR_CJK_FONT_HEIGHT).CloneSetWhich(EE_CHAR_FONTHEIGHT_CJK) ) ;
201  aDefaults.Put( rPattern.GetItem(ATTR_CTL_FONT_HEIGHT).CloneSetWhich(EE_CHAR_FONTHEIGHT_CTL) );
202  pHdrEngine->SetDefaults( aDefaults );
203 
206  pHdrEngine->SetData( aData );
207 
208  pEditEngine = std::move(pHdrEngine);
210  }
211 
212  if (bDataValid)
213  return pForwarder.get();
214 
215  if (mpTextObj)
216  pEditEngine->SetTextCurrentDefaults(*mpTextObj);
217 
218  bDataValid = true;
219  return pForwarder.get();
220 }
221 
223 {
224  if (pEditEngine)
225  {
226  mpTextObj = pEditEngine->CreateTextObject();
227  }
228 }
229 
231 {
232  mpTextObj = rEditEngine.CreateTextObject();
233  bDataValid = false;
234 }
235 
237  const uno::WeakReference<sheet::XHeaderFooterContent>& xContent, ScHeaderFooterPart nP, const EditTextObject* pTextObj) :
238  aTextData(xContent, nP, pTextObj)
239 {
240  // ScHeaderFooterTextData acquires rContent
241  // pUnoText is created on demand (getString/setString work without it)
242 }
243 
245 {
246  if (!mxUnoText.is())
247  {
248  // can't be aggregated because getString/setString is handled here
250  mxUnoText.set(new SvxUnoText(&aEditSrc, lcl_GetHdFtPropertySet(), uno::Reference<text::XText>()));
251  }
252 }
253 
255 
257 {
258  return aTextData.GetTextObject();
259 }
260 
262 {
263  if (!mxUnoText.is())
265  return *mxUnoText;
266 }
267 
268 // XText
269 
270 uno::Reference<text::XTextCursor> SAL_CALL ScHeaderFooterTextObj::createTextCursor()
271 {
272  SolarMutexGuard aGuard;
273  return new ScHeaderFooterTextCursor( this );
274 }
275 
276 uno::Reference<text::XTextCursor> SAL_CALL ScHeaderFooterTextObj::createTextCursorByRange(
277  const uno::Reference<text::XTextRange>& aTextPosition )
278 {
279  SolarMutexGuard aGuard;
280  if (!mxUnoText.is())
282  return mxUnoText->createTextCursorByRange(aTextPosition);
284 }
285 
287 {
288  OUString aDummy("???");
289  rData.aTitle = aDummy;
290  rData.aLongDocName = aDummy;
291  rData.aShortDocName = aDummy;
292  rData.aTabName = aDummy;
293  rData.nPageNo = 1;
294  rData.nTotalPages = 99;
295 }
296 
298 {
299  SolarMutexGuard aGuard;
300  OUString aRet;
301  const EditTextObject* pData;
302 
303  uno::Reference<css::sheet::XHeaderFooterContent> xContentObj = aTextData.GetContentObj();
304  if (!xContentObj.is())
305  throw css::uno::RuntimeException(
306  "ScHeaderFooterTextObj::getString: no ContentObj");
307 
309 
310  switch ( aTextData.GetPart() )
311  {
313  pData = pObj->GetLeftEditObject();
314  break;
316  pData = pObj->GetCenterEditObject();
317  break;
319  pData = pObj->GetRightEditObject();
320  break;
321  default:
322  SAL_WARN("sc.ui","unexpected enum value of ScHeaderFooterPart");
323  pData = nullptr;
324  }
325 
326  if (pData)
327  {
328  // for pure text, no font info is needed in pool defaults
329  ScHeaderEditEngine aEditEngine( EditEngine::CreatePool().get() );
330 
332  FillDummyFieldData( aData );
333  aEditEngine.SetData( aData );
334 
335  aEditEngine.SetTextCurrentDefaults(*pData);
336  aRet = ScEditUtil::GetSpaceDelimitedString( aEditEngine );
337  }
338  return aRet;
339 }
340 
341 void SAL_CALL ScHeaderFooterTextObj::setString( const OUString& aText )
342 {
343  SolarMutexGuard aGuard;
344 
345  // for pure text, no font info is needed in pool defaults
346  ScHeaderEditEngine aEditEngine(EditEngine::CreatePool().get());
347  aEditEngine.SetTextCurrentDefaults( aText );
348  aTextData.UpdateData(aEditEngine);
349 }
350 
351 void SAL_CALL ScHeaderFooterTextObj::insertString( const uno::Reference<text::XTextRange>& xRange,
352  const OUString& aString, sal_Bool bAbsorb )
353 {
354  SolarMutexGuard aGuard;
355  if (!mxUnoText.is())
357  mxUnoText->insertString( xRange, aString, bAbsorb );
358 }
359 
361  const uno::Reference<text::XTextRange>& xRange,
362  sal_Int16 nControlCharacter, sal_Bool bAbsorb )
363 {
364  SolarMutexGuard aGuard;
365  if (!mxUnoText.is())
367  mxUnoText->insertControlCharacter( xRange, nControlCharacter, bAbsorb );
368 }
369 
371  const uno::Reference<text::XTextRange >& xRange,
372  const uno::Reference<text::XTextContent >& xContent,
373  sal_Bool bAbsorb )
374 {
375  SolarMutexGuard aGuard;
376  if ( xContent.is() && xRange.is() )
377  {
378  ScEditFieldObj* pHeaderField = comphelper::getFromUnoTunnel<ScEditFieldObj>( xContent );
379 
380  SvxUnoTextRangeBase* pTextRange =
381  comphelper::getFromUnoTunnel<ScHeaderFooterTextCursor>( xRange );
382 
383  if ( pHeaderField && !pHeaderField->IsInserted() && pTextRange )
384  {
385  SvxEditSource* pEditSource = pTextRange->GetEditSource();
386  ESelection aSelection(pTextRange->GetSelection());
387 
388  if (!bAbsorb)
389  {
390  // don't replace -> append at end
391  aSelection.Adjust();
392  aSelection.nStartPara = aSelection.nEndPara;
393  aSelection.nStartPos = aSelection.nEndPos;
394  }
395 
396  SvxFieldItem aItem(pHeaderField->CreateFieldItem());
397 
398  SvxTextForwarder* pForwarder = pEditSource->GetTextForwarder();
399  pForwarder->QuickInsertField( aItem, aSelection );
400  pEditSource->UpdateData();
401 
402  // new selection: a digit
403  aSelection.Adjust();
404  aSelection.nEndPara = aSelection.nStartPara;
405  aSelection.nEndPos = aSelection.nStartPos + 1;
406 
407  uno::Reference<text::XTextRange> xTextRange;
408  switch ( aTextData.GetPart() )
409  {
411  xTextRange = aTextData.GetContentObj()->getLeftText();
412  break;
414  xTextRange = aTextData.GetContentObj()->getCenterText();
415  break;
417  xTextRange = aTextData.GetContentObj()->getRightText();
418  break;
419  }
420 
421  pHeaderField->InitDoc(xTextRange, std::make_unique<ScHeaderFooterEditSource>(aTextData), aSelection);
422 
423  // for bAbsorb=FALSE, the new selection must be behind the inserted content
424  // (the xml filter relies on this)
425  if (!bAbsorb)
426  aSelection.nStartPos = aSelection.nEndPos;
427 
428  pTextRange->SetSelection( aSelection );
429 
430  return;
431  }
432  }
433 
434  if (!mxUnoText.is())
436  mxUnoText->insertTextContent( xRange, xContent, bAbsorb );
437 }
438 
440  const uno::Reference<text::XTextContent>& xContent )
441 {
442  SolarMutexGuard aGuard;
443  if ( xContent.is() )
444  {
445  ScEditFieldObj* pHeaderField = comphelper::getFromUnoTunnel<ScEditFieldObj>(xContent);
446  if ( pHeaderField && pHeaderField->IsInserted() )
447  {
449  pHeaderField->DeleteField();
450  return;
451  }
452  }
453  if (!mxUnoText.is())
455  mxUnoText->removeTextContent( xContent );
456 }
457 
458 uno::Reference<text::XText> SAL_CALL ScHeaderFooterTextObj::getText()
459 {
460  SolarMutexGuard aGuard;
461  if (!mxUnoText.is())
463  return mxUnoText->getText();
464 }
465 
466 uno::Reference<text::XTextRange> SAL_CALL ScHeaderFooterTextObj::getStart()
467 {
468  SolarMutexGuard aGuard;
469  if (!mxUnoText.is())
471  return mxUnoText->getStart();
472 }
473 
474 uno::Reference<text::XTextRange> SAL_CALL ScHeaderFooterTextObj::getEnd()
475 {
476  SolarMutexGuard aGuard;
477  if (!mxUnoText.is())
479  return mxUnoText->getEnd();
480 }
481 
482 // XTextFieldsSupplier
483 
484 uno::Reference<container::XEnumerationAccess> SAL_CALL ScHeaderFooterTextObj::getTextFields()
485 {
486  SolarMutexGuard aGuard;
487  // all fields
488  return new ScHeaderFieldsObj(aTextData);
489 }
490 
491 uno::Reference<container::XNameAccess> SAL_CALL ScHeaderFooterTextObj::getTextFieldMasters()
492 {
493  // this does not exists in Calc (?)
494  return nullptr;
495 }
496 
497 // XTextRangeMover
498 
500  const uno::Reference<text::XTextRange>& xRange,
501  sal_Int16 nParagraphs )
502 {
503  SolarMutexGuard aGuard;
504  if (!mxUnoText.is())
506  mxUnoText->moveTextRange( xRange, nParagraphs );
507 }
508 
509 // XEnumerationAccess
510 
511 uno::Reference<container::XEnumeration> SAL_CALL ScHeaderFooterTextObj::createEnumeration()
512 {
513  SolarMutexGuard aGuard;
514  if (!mxUnoText.is())
516  return mxUnoText->createEnumeration();
517 }
518 
519 // XElementAccess
520 
522 {
523  SolarMutexGuard aGuard;
524  if (!mxUnoText.is())
526  return mxUnoText->getElementType();
527 }
528 
530 {
531  SolarMutexGuard aGuard;
532  if (!mxUnoText.is())
534  return mxUnoText->hasElements();
535 }
536 
538  SvxUnoTextCursor( rText.GetUnoText() ),
539  mxTextObj( &rText )
540 {
541 }
542 
544 {
545 }
546 
547 // SvxUnoTextCursor methods reimplemented here to return the right objects:
548 
549 uno::Reference<text::XText> SAL_CALL ScCellTextCursor::getText()
550 {
551  return mxTextObj;
552 }
553 
554 uno::Reference<text::XTextRange> SAL_CALL ScCellTextCursor::getStart()
555 {
556  SolarMutexGuard aGuard;
557 
559 
561 
562  ESelection aNewSel(GetSelection());
563  aNewSel.nEndPara = aNewSel.nStartPara;
564  aNewSel.nEndPos = aNewSel.nStartPos;
565  pNew->SetSelection( aNewSel );
566 
567  return static_cast<SvxUnoTextRangeBase*>(pNew.get());
568 }
569 
570 uno::Reference<text::XTextRange> SAL_CALL ScCellTextCursor::getEnd()
571 {
572  SolarMutexGuard aGuard;
573 
575 
577 
578  ESelection aNewSel(GetSelection());
579  aNewSel.nStartPara = aNewSel.nEndPara;
580  aNewSel.nStartPos = aNewSel.nEndPos;
581  pNew->SetSelection( aNewSel );
582 
583  return static_cast<SvxUnoTextRangeBase*>(pNew.get());
584 }
585 
586 // XUnoTunnel
587 
589 
591  SvxUnoTextCursor( rText->GetUnoText() ),
592  rTextObj( rText )
593 {}
594 
596 
597 // SvxUnoTextCursor methods reimplemented here to return the right objects:
598 
599 uno::Reference<text::XText> SAL_CALL ScHeaderFooterTextCursor::getText()
600 {
601  SolarMutexGuard aGuard;
602  return rTextObj;
603 }
604 
605 uno::Reference<text::XTextRange> SAL_CALL ScHeaderFooterTextCursor::getStart()
606 {
607  SolarMutexGuard aGuard;
608 
610 
612 
613  ESelection aNewSel(GetSelection());
614  aNewSel.nEndPara = aNewSel.nStartPara;
615  aNewSel.nEndPos = aNewSel.nStartPos;
616  pNew->SetSelection( aNewSel );
617 
618  return static_cast<SvxUnoTextRangeBase*>(pNew.get());
619 }
620 
621 uno::Reference<text::XTextRange> SAL_CALL ScHeaderFooterTextCursor::getEnd()
622 {
623  SolarMutexGuard aGuard;
624 
626 
628 
629  ESelection aNewSel(GetSelection());
630  aNewSel.nStartPara = aNewSel.nEndPara;
631  aNewSel.nStartPos = aNewSel.nEndPos;
632  pNew->SetSelection( aNewSel );
633 
634  return static_cast<SvxUnoTextRangeBase*>(pNew.get());
635 }
636 
637 // XUnoTunnel
638 
640 
641 ScDrawTextCursor::ScDrawTextCursor( const uno::Reference<text::XText>& xParent,
642  const SvxUnoTextBase& rText ) :
643  SvxUnoTextCursor( rText ),
644  xParentText( xParent )
645 
646 {
647 }
648 
650 {
651 }
652 
653 // SvxUnoTextCursor methods reimplemented here to return the right objects:
654 
655 uno::Reference<text::XText> SAL_CALL ScDrawTextCursor::getText()
656 {
657  SolarMutexGuard aGuard;
658  return xParentText;
659 }
660 
661 uno::Reference<text::XTextRange> SAL_CALL ScDrawTextCursor::getStart()
662 {
663  SolarMutexGuard aGuard;
664 
666 
668 
669  ESelection aNewSel(GetSelection());
670  aNewSel.nEndPara = aNewSel.nStartPara;
671  aNewSel.nEndPos = aNewSel.nStartPos;
672  pNew->SetSelection( aNewSel );
673 
674  return static_cast<SvxUnoTextRangeBase*>(pNew.get());
675 }
676 
677 uno::Reference<text::XTextRange> SAL_CALL ScDrawTextCursor::getEnd()
678 {
679  SolarMutexGuard aGuard;
680 
682 
684 
685  ESelection aNewSel(GetSelection());
686  aNewSel.nStartPara = aNewSel.nEndPara;
687  aNewSel.nStartPos = aNewSel.nEndPos;
688  pNew->SetSelection( aNewSel );
689 
690  return static_cast<SvxUnoTextRangeBase*>(pNew.get());
691 }
692 
693 // XUnoTunnel
694 
696 
698 {
700  pEnginePool->SetDefaultMetric( MapUnit::Map100thMM );
701  pEnginePool->FreezeIdRanges();
702 
703  pEditEngine.reset( new ScFieldEditEngine(nullptr, pEnginePool.get(), nullptr, true) ); // TRUE: become owner of pool
705  pOriginalSource.reset( new ScSimpleEditSource( pForwarder.get() ) );
706 }
707 
709 {
710  SolarMutexGuard aGuard; // needed for EditEngine dtor
711 
712  pOriginalSource.reset();
713  pForwarder.reset();
714  pEditEngine.reset();
715 }
716 
718  SvxUnoText( GetOriginalSource(), ScCellObj::GetEditPropertySet(), uno::Reference<text::XText>() )
719 {
720 }
721 
723 {
724 }
725 
727 {
728  GetEditEngine()->SetTextCurrentDefaults( rTextObject );
729 
730  ESelection aSel;
731  ::GetSelection( aSel, GetEditSource()->GetTextForwarder() );
732  SetSelection( aSel );
733 }
734 
735 std::unique_ptr<EditTextObject> ScEditEngineTextObj::CreateTextObject()
736 {
737  return GetEditEngine()->CreateTextObject();
738 }
739 
741  pDocShell( pDocSh ),
742  aCellPos( rP ),
743  bDataValid( false ),
744  bInUpdate( false ),
745  bDirty( false ),
746  bDoUpdate( true )
747 {
748  if (pDocShell)
750 }
751 
753 {
754  SolarMutexGuard aGuard; // needed for EditEngine dtor
755 
756  if (pDocShell)
757  {
760  }
761  else
762  pEditEngine.reset();
763 
764  pForwarder.reset();
765 
766  pOriginalSource.reset();
767 }
768 
770 {
771  if (!pOriginalSource)
773  return pOriginalSource.get();
774 }
775 
777 {
778  if (!pEditEngine)
779  {
780  if ( pDocShell )
781  {
782  ScDocument& rDoc = pDocShell->GetDocument();
784  }
785  else
786  {
788  pEnginePool->FreezeIdRanges();
789  pEditEngine.reset( new ScFieldEditEngine(nullptr, pEnginePool.get(), nullptr, true) );
790  }
791  // currently, GetPortions doesn't work if UpdateMode is sal_False,
792  // this will be fixed (in EditEngine) by src600
793 // pEditEngine->SetUpdateMode( sal_False );
794  pEditEngine->EnableUndo( false );
795  if (pDocShell)
796  pEditEngine->SetRefDevice(pDocShell->GetRefDevice());
797  else
798  pEditEngine->SetRefMapMode(MapMode(MapUnit::Map100thMM));
800  }
801 
802  if (bDataValid)
803  return pForwarder.get();
804 
805  if (pDocShell)
806  {
807  ScDocument& rDoc = pDocShell->GetDocument();
808 
809  SfxItemSet aDefaults( pEditEngine->GetEmptyItemSet() );
810  if( const ScPatternAttr* pPattern =
811  rDoc.GetPattern( aCellPos.Col(), aCellPos.Row(), aCellPos.Tab() ) )
812  {
813  pPattern->FillEditItemSet( &aDefaults );
814  pPattern->FillEditParaItems( &aDefaults ); // including alignment etc. (for reading)
815  }
816 
817  ScRefCellValue aCell(rDoc, aCellPos);
818  if (aCell.meType == CELLTYPE_EDIT)
819  {
820  const EditTextObject* pObj = aCell.mpEditText;
821  pEditEngine->SetTextNewDefaults(*pObj, aDefaults);
822  }
823  else
824  {
825  sal_uInt32 nFormat = rDoc.GetNumberFormat(aCellPos);
826  OUString aText;
827  ScCellFormat::GetInputString(aCell, nFormat, aText, *rDoc.GetFormatTable(), rDoc);
828  if (!aText.isEmpty())
829  pEditEngine->SetTextNewDefaults(aText, aDefaults);
830  else
831  pEditEngine->SetDefaults(aDefaults);
832  }
833  }
834 
835  bDataValid = true;
836  return pForwarder.get();
837 }
838 
840 {
841  if ( bDoUpdate )
842  {
843  OSL_ENSURE(pEditEngine != nullptr, "no EditEngine for UpdateData()");
844  if ( pDocShell && pEditEngine )
845  {
846  // during the own UpdateData call, bDataValid must not be reset,
847  // or things like attributes after the text would be lost
848  // (are not stored in the cell)
849  bInUpdate = true; // prevents bDataValid from being reset
850  pDocShell->GetDocFunc().PutData(aCellPos, *pEditEngine, true); // always as text
851 
852  bInUpdate = false;
853  bDirty = false;
854  }
855  }
856  else
857  bDirty = true;
858 }
859 
861 {
862  const SfxHintId nId = rHint.GetId();
863  if ( nId == SfxHintId::Dying )
864  {
865  pDocShell = nullptr; // invalid now
866 
867  pForwarder.reset();
868  pEditEngine.reset(); // EditEngine uses document's pool
869  }
870  else if ( nId == SfxHintId::DataChanged )
871  {
872  if (!bInUpdate) // not for own UpdateData calls
873  bDataValid = false; // text has to be read from the cell again
874  }
875 }
876 
878  ScCellTextData( pDocSh, rP ),
879  SvxUnoText( GetOriginalSource(), ScCellObj::GetEditPropertySet(), uno::Reference<text::XText>() )
880 {
881 }
882 
883 ScCellTextObj::~ScCellTextObj() COVERITY_NOEXCEPT_FALSE
884 {
885 }
886 
887 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
ScDocShell * pDocShell
Definition: textuno.hxx:329
virtual css::uno::Type SAL_CALL getElementType() override
Definition: textuno.cxx:521
OUString aLongDocName
Definition: editutil.hxx:208
void Adjust()
SfxHintId
sal_Int32 nStartPara
virtual css::uno::Reference< css::text::XTextRange > SAL_CALL getStart() override
Definition: textuno.cxx:605
Data (incl.
Definition: editsrc.hxx:73
static void GetInputString(const ScRefCellValue &rCell, sal_uInt32 nFormat, OUString &rString, SvNumberFormatter &rFormatter, const ScDocument &rDoc, bool bFiltering=false)
Definition: cellform.cxx:119
constexpr TypedWhichId< ScPatternAttr > ATTR_PATTERN(156)
SCROW Row() const
Definition: address.hxx:261
bool IsInserted() const
Definition: fielduno.cxx:1113
uno3: SvxUnoTextCursor is not derived from XUnoTunnel, but should be (?)
Definition: textuno.hxx:215
std::unique_ptr< ContentProperties > pData
virtual ~ScEditEngineTextObj() noexcept override
Definition: textuno.cxx:722
void SetSelection(const ESelection &rSelection) noexcept
std::unique_ptr< EditTextObject > mpTextObj
Definition: textuno.hxx:105
virtual void QuickInsertField(const SvxFieldItem &rFld, const ESelection &rSel)=0
std::unique_ptr< SvxEditEngineForwarder > pForwarder
Definition: textuno.hxx:332
ScHeaderFooterTextCursor(rtl::Reference< ScHeaderFooterTextObj > const &rText)
Definition: textuno.cxx:590
virtual css::uno::Reference< css::text::XText > SAL_CALL getLeftText() override
Definition: textuno.cxx:112
virtual css::uno::Reference< css::text::XTextRange > SAL_CALL getStart() override
Definition: textuno.cxx:554
rtl::Reference< ScHeaderFooterTextObj > rTextObj
Definition: textuno.hxx:245
Reference
sal_Int16 nId
SC_DLLPUBLIC void GetNumberFormat(SCCOL nCol, SCROW nRow, SCTAB nTab, sal_uInt32 &rFormat) const
Definition: document.cxx:3672
ScAddress aCellPos
Definition: textuno.hxx:330
UNO3_GETIMPLEMENTATION2_IMPL(ScCellTextCursor, SvxUnoTextCursor)
virtual css::uno::Reference< css::text::XTextRange > SAL_CALL getEnd() override
Definition: textuno.cxx:570
ScHeaderFooterPart
Definition: textuno.hxx:50
ScCellTextData(ScDocShell *pDocSh, const ScAddress &rP)
Definition: textuno.cxx:740
virtual css::uno::Reference< css::text::XText > SAL_CALL getText() override
Definition: textuno.cxx:599
This is very similar to ScCellValue, except that it references the original value instead of copying ...
Definition: cellvalue.hxx:103
css::uno::Reference< css::sheet::XHeaderFooterContent > GetContentObj() const
Definition: textuno.hxx:126
static const css::uno::Sequence< sal_Int8 > & getUnoTunnelId()
Definition: textuno.cxx:141
virtual sal_Bool SAL_CALL hasElements() override
Definition: textuno.cxx:529
virtual ~ScHeaderFooterContentObj() override
Definition: textuno.cxx:93
constexpr TypedWhichId< SvxFontHeightItem > EE_CHAR_FONTHEIGHT(EE_CHAR_START+2)
SfxHintId GetId() const
virtual ~ScCellTextData() override
Definition: textuno.cxx:752
ScCellTextObj(ScDocShell *pDocSh, const ScAddress &rP)
Definition: textuno.cxx:877
std::unique_ptr< ScCellEditSource > pOriginalSource
Definition: textuno.hxx:333
virtual ~ScHeaderFooterTextCursor() noexcept override
Definition: textuno.cxx:595
static rtl::Reference< SfxItemPool > CreatePool()
rtl::Reference< SvxUnoText > mxUnoText
Definition: textuno.hxx:146
const EditTextObject * GetRightEditObject() const
Definition: textuno.cxx:105
virtual css::uno::Reference< css::text::XTextRange > SAL_CALL getStart() override
Definition: textuno.cxx:661
const EditTextObject * mpEditText
Definition: cellvalue.hxx:109
ScHeaderFooterTextData(const ScHeaderFooterTextData &)=delete
std::unique_ptr< SvxEditEngineForwarder > pForwarder
Definition: textuno.hxx:303
SCTAB Tab() const
Definition: address.hxx:270
virtual void SAL_CALL insertControlCharacter(const css::uno::Reference< css::text::XTextRange > &xRange, sal_Int16 nControlCharacter, sal_Bool bAbsorb) override
Definition: textuno.cxx:360
static const SvxItemPropertySet * lcl_GetHdFtPropertySet()
Definition: textuno.cxx:52
OUString aShortDocName
Definition: editutil.hxx:209
virtual ~ScHeaderFooterTextObj() override
Definition: textuno.cxx:254
const EditTextObject * GetLeftEditObject() const
Definition: textuno.cxx:95
sal_Int32 nEndPos
virtual SvxTextForwarder * GetTextForwarder()
Definition: textuno.cxx:776
void Init(const EditTextObject *pLeft, const EditTextObject *pCenter, const EditTextObject *pRight)
Definition: textuno.cxx:153
static void FillDummyFieldData(ScHeaderFieldData &rData)
Definition: textuno.cxx:286
SC_DLLPUBLIC const ScPatternAttr * GetPattern(SCCOL nCol, SCROW nRow, SCTAB nTab) const
Definition: document.cxx:4766
virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() override
Definition: textuno.cxx:511
virtual void SAL_CALL removeTextContent(const css::uno::Reference< css::text::XTextContent > &xContent) override
Definition: textuno.cxx:439
virtual css::uno::Reference< css::container::XEnumerationAccess > SAL_CALL getTextFields() override
Definition: textuno.cxx:484
constexpr OUStringLiteral aData
const css::uno::Sequence< sal_Int8 > & getSeq() const
static rtl::Reference< ScHeaderFooterContentObj > getImplementation(const css::uno::Reference< css::sheet::XHeaderFooterContent > &rObj)
Definition: textuno.cxx:147
exports com.sun.star. text
SvxFieldItem CreateFieldItem()
Definition: fielduno.cxx:1091
virtual css::uno::Reference< css::text::XTextRange > SAL_CALL getEnd() override
Definition: textuno.cxx:677
void UpdateData()
Definition: textuno.cxx:839
SC_DLLPUBLIC SvNumberFormatter * GetFormatTable() const
Definition: documen2.cxx:441
sal_Int32 nEndPara
tools::Long nTotalPages
Definition: editutil.hxx:213
void SetTextCurrentDefaults(const EditTextObject &rTextObject)
SetText and apply defaults already set.
Definition: editutil.cxx:596
ScDrawTextCursor(const css::uno::Reference< css::text::XText > &xParent, const SvxUnoTextBase &rText)
std::unique_ptr< ScEditEngineDefaulter > pEditEngine
Definition: textuno.hxx:108
constexpr TypedWhichId< SvxFontHeightItem > ATTR_CJK_FONT_HEIGHT(112)
Reference< XAnimationNode > Clone(const Reference< XAnimationNode > &xSourceNode, const SdPage *pSource, const SdPage *pTarget)
void InitDoc(const css::uno::Reference< css::text::XTextRange > &rContent, std::unique_ptr< ScEditSource > pEditSrc, const ESelection &rSel)
Definition: fielduno.cxx:1074
virtual css::uno::Reference< css::text::XTextRange > SAL_CALL getEnd() override
Definition: textuno.cxx:474
std::unique_ptr< EditTextObject > CreateTextObject()
Definition: textuno.cxx:735
ScCellTextCursor(ScCellObj &rText)
Definition: textuno.cxx:537
ScHeaderFooterTextObj(const css::uno::WeakReference< css::sheet::XHeaderFooterContent > &xContent, ScHeaderFooterPart nP, const EditTextObject *pTextObj)
Definition: textuno.cxx:236
#define SVX_UNOEDIT_NUMBERING_PROPERTIE
#define SC_MOD()
Definition: scmod.hxx:250
virtual css::uno::Reference< css::container::XNameAccess > SAL_CALL getTextFieldMasters() override
Definition: textuno.cxx:491
SvxEditSource * GetEditSource() const noexcept
rtl::Reference< ScCellObj > mxTextObj
Definition: textuno.hxx:217
OUString aTabName
Definition: editutil.hxx:210
std::unique_ptr< EditTextObject > CreateTextObject()
void PutData(const ScAddress &rPos, ScEditEngineDefaulter &rEngine, bool bApi)
Definition: docfunc.cxx:1153
float u
unsigned char sal_Bool
virtual SvxTextForwarder * GetTextForwarder()=0
ScHeaderFooterTextObj keeps the authoritative copy of ScHeaderFooterTextData that this class holds re...
Definition: editsrc.hxx:49
#define SC_SIMPLE_SERVICE_INFO(ClassName, ClassNameAscii, ServiceAscii)
Definition: miscuno.hxx:63
const EditTextObject * GetTextObject() const
Definition: textuno.hxx:128
constexpr TypedWhichId< SvxFontHeightItem > ATTR_CTL_FONT_HEIGHT(117)
#define SVX_UNOEDIT_FONT_PROPERTIES
Each of these instances represent, the left, center or right part of the header of footer of a page...
Definition: textuno.hxx:137
SCCOL Col() const
Definition: address.hxx:266
css::uno::Reference< css::text::XText > xParentText
Definition: textuno.hxx:271
const SvxUnoText & GetUnoText()
Definition: textuno.cxx:261
void AddUnoObject(SfxListener &rObject)
Definition: documen3.cxx:898
void DeleteField()
Definition: fielduno.cxx:1097
ScEditEngineDefaulter * GetEditEngine() const
Definition: textuno.hxx:311
void SetData(const ScHeaderFieldData &rNew)
Definition: editutil.hxx:230
virtual void SAL_CALL insertTextContent(const css::uno::Reference< css::text::XTextRange > &xRange, const css::uno::Reference< css::text::XTextContent > &xContent, sal_Bool bAbsorb) override
Definition: textuno.cxx:370
CellType meType
Definition: cellvalue.hxx:105
ScHeaderFooterTextData aTextData
Definition: textuno.hxx:145
virtual ~ScDrawTextCursor() noexcept override
Definition: textuno.cxx:649
void SetText(const EditTextObject &rTextObject)
Definition: textuno.cxx:726
std::unique_ptr< ScFieldEditEngine > pEditEngine
Definition: textuno.hxx:331
virtual css::uno::Reference< css::text::XTextCursor > SAL_CALL createTextCursorByRange(const css::uno::Reference< css::text::XTextRange > &aTextPosition) override
Definition: textuno.cxx:276
#define MID_FONTHEIGHT
virtual sal_Int64 SAL_CALL getSomething(const css::uno::Sequence< sal_Int8 > &aIdentifier) override
Definition: textuno.cxx:135
static SdrItemPool & GetGlobalDrawObjectItemPool()
constexpr TypedWhichId< SvxFontHeightItem > EE_CHAR_FONTHEIGHT_CTL(EE_CHAR_START+20)
const ESelection & GetSelection() const noexcept
sal_Int64 getSomethingImpl(const css::uno::Sequence< sal_Int8 > &rId, T *pThis, FallbackToGetSomethingOf< Base >={})
const EditTextObject * GetTextObject() const
Definition: textuno.cxx:256
std::unique_ptr< ScFieldEditEngine > CreateFieldEditEngine()
Definition: documen2.cxx:1122
const EditTextObject * GetCenterEditObject() const
Definition: textuno.cxx:100
#define SVX_UNOEDIT_PARA_PROPERTIES
ScCellEditSource * GetOriginalSource()
Definition: textuno.cxx:769
void DisposeFieldEditEngine(std::unique_ptr< ScFieldEditEngine > &rpEditEngine)
Definition: documen2.cxx:1144
virtual css::uno::Reference< css::text::XText > SAL_CALL getText() override
Definition: textuno.cxx:549
really derive cell from range?
Definition: cellsuno.hxx:633
void RemoveUnoObject(SfxListener &rObject)
Definition: documen3.cxx:906
virtual css::uno::Reference< css::text::XTextRange > SAL_CALL getStart() override
Definition: textuno.cxx:466
SvxTextForwarder * GetTextForwarder()
Definition: textuno.cxx:180
const ScDocument & GetDocument() const
Definition: docsh.hxx:216
static OUString GetSpaceDelimitedString(const EditEngine &rEngine)
Retrieves string with paragraphs delimited by spaces.
Definition: editutil.cxx:99
std::unique_ptr< ScSimpleEditSource > pOriginalSource
Definition: textuno.hxx:304
virtual css::uno::Reference< css::text::XText > SAL_CALL getRightText() override
Definition: textuno.cxx:126
tools::Long nPageNo
Definition: editutil.hxx:212
virtual void SAL_CALL insertString(const css::uno::Reference< css::text::XTextRange > &xRange, const OUString &aString, sal_Bool bAbsorb) override
Definition: textuno.cxx:351
virtual css::uno::Reference< css::text::XTextCursor > SAL_CALL createTextCursor() override
Definition: textuno.cxx:270
virtual ~ScCellTextObj() COVERITY_NOEXCEPT_FALSE override
Definition: textuno.cxx:883
virtual void SAL_CALL moveTextRange(const css::uno::Reference< css::text::XTextRange > &xRange, sal_Int16 nParagraphs) override
Definition: textuno.cxx:499
#define SAL_WARN(area, stream)
constexpr TypedWhichId< SvxFontHeightItem > EE_CHAR_FONTHEIGHT_CJK(EE_CHAR_START+19)
virtual void Notify(SfxBroadcaster &rBC, const SfxHint &rHint) override
Definition: textuno.cxx:860
virtual css::uno::Reference< css::text::XText > SAL_CALL getText() override
Definition: textuno.cxx:458
virtual OUString SAL_CALL getString() override
Definition: textuno.cxx:297
ScDocFunc & GetDocFunc()
Definition: docsh.hxx:218
virtual css::uno::Reference< css::text::XTextRange > SAL_CALL getEnd() override
Definition: textuno.cxx:621
std::unique_ptr< ScEditEngineDefaulter > pEditEngine
Definition: textuno.hxx:302
virtual css::uno::Reference< css::text::XText > SAL_CALL getCenterText() override
Definition: textuno.cxx:119
ScHeaderFooterPart GetPart() const
Definition: textuno.hxx:125
constexpr TypedWhichId< SvxFontHeightItem > ATTR_FONT_HEIGHT(101)
virtual ~ScCellTextCursor() noexcept override
Definition: textuno.cxx:543
std::unique_ptr< SvxEditEngineForwarder > pForwarder
Definition: textuno.hxx:109
virtual void UpdateData()=0
#define SVX_UNOEDIT_CHAR_PROPERTIES
virtual void SAL_CALL setString(const OUString &aString) override
Definition: textuno.cxx:341
virtual css::uno::Reference< css::text::XText > SAL_CALL getText() override
Definition: textuno.cxx:655
OutputDevice * GetRefDevice()
Definition: docsh3.cxx:466
#define CONVERT_TWIPS
sal_Int32 nStartPos