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  if ( isUnoTunnelId<ScHeaderFooterContentObj>(rId) )
139  {
140  return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_IntPtr>(this));
141  }
142  return 0;
143 }
144 
145 const uno::Sequence<sal_Int8>& ScHeaderFooterContentObj::getUnoTunnelId()
146 {
147  static const UnoTunnelIdInit theScHeaderFooterContentObjUnoTunnelId;
148  return theScHeaderFooterContentObjUnoTunnelId.getSeq();
149 }
150 
152  const uno::Reference<sheet::XHeaderFooterContent>& rObj)
153 {
154  return comphelper::getUnoTunnelImplementation<ScHeaderFooterContentObj>(rObj);
155 }
156 
158  const EditTextObject* pCenter,
159  const EditTextObject* pRight )
160 {
161  uno::Reference<css::sheet::XHeaderFooterContent> xThis(this);
165 }
166 
168  uno::WeakReference<sheet::XHeaderFooterContent> const & xContent, ScHeaderFooterPart nP, const EditTextObject* pTextObj) :
169  mpTextObj(pTextObj ? pTextObj->Clone() : nullptr),
170  xContentObj( xContent ),
171  nPart( nP ),
172  bDataValid(false)
173 {
174 }
175 
177 {
178  SolarMutexGuard aGuard; // needed for EditEngine dtor
179 
180  pForwarder.reset();
181  pEditEngine.reset();
182 }
183 
185 {
186  if (!pEditEngine)
187  {
188  SfxItemPool* pEnginePool = EditEngine::CreatePool();
189  pEnginePool->FreezeIdRanges();
190  std::unique_ptr<ScHeaderEditEngine> pHdrEngine(new ScHeaderEditEngine( pEnginePool ));
191 
192  pHdrEngine->EnableUndo( false );
193  pHdrEngine->SetRefMapMode(MapMode(MapUnit::MapTwip));
194 
195  // default font must be set, independently of document
196  // -> use global pool from module
197 
198  SfxItemSet aDefaults( pHdrEngine->GetEmptyItemSet() );
199  const ScPatternAttr& rPattern = SC_MOD()->GetPool().GetDefaultItem(ATTR_PATTERN);
200  rPattern.FillEditItemSet( &aDefaults );
201  // FillEditItemSet adjusts font height to 1/100th mm,
202  // but for header/footer twips is needed, as in the PatternAttr:
203  aDefaults.Put( rPattern.GetItem(ATTR_FONT_HEIGHT).CloneSetWhich(EE_CHAR_FONTHEIGHT) );
204  aDefaults.Put( rPattern.GetItem(ATTR_CJK_FONT_HEIGHT).CloneSetWhich(EE_CHAR_FONTHEIGHT_CJK) ) ;
205  aDefaults.Put( rPattern.GetItem(ATTR_CTL_FONT_HEIGHT).CloneSetWhich(EE_CHAR_FONTHEIGHT_CTL) );
206  pHdrEngine->SetDefaults( aDefaults );
207 
210  pHdrEngine->SetData( aData );
211 
212  pEditEngine = std::move(pHdrEngine);
214  }
215 
216  if (bDataValid)
217  return pForwarder.get();
218 
219  if (mpTextObj)
220  pEditEngine->SetTextCurrentDefaults(*mpTextObj);
221 
222  bDataValid = true;
223  return pForwarder.get();
224 }
225 
227 {
228  if (pEditEngine)
229  {
230  mpTextObj = pEditEngine->CreateTextObject();
231  }
232 }
233 
235 {
236  mpTextObj = rEditEngine.CreateTextObject();
237  bDataValid = false;
238 }
239 
241  const uno::WeakReference<sheet::XHeaderFooterContent>& xContent, ScHeaderFooterPart nP, const EditTextObject* pTextObj) :
242  aTextData(xContent, nP, pTextObj)
243 {
244  // ScHeaderFooterTextData acquires rContent
245  // pUnoText is created on demand (getString/setString work without it)
246 }
247 
249 {
250  if (!mxUnoText.is())
251  {
252  // can't be aggregated because getString/setString is handled here
254  mxUnoText.set(new SvxUnoText(&aEditSrc, lcl_GetHdFtPropertySet(), uno::Reference<text::XText>()));
255  }
256 }
257 
259 
261 {
262  return aTextData.GetTextObject();
263 }
264 
266 {
267  if (!mxUnoText.is())
269  return *mxUnoText;
270 }
271 
272 // XText
273 
274 uno::Reference<text::XTextCursor> SAL_CALL ScHeaderFooterTextObj::createTextCursor()
275 {
276  SolarMutexGuard aGuard;
277  return new ScHeaderFooterTextCursor( this );
278 }
279 
280 uno::Reference<text::XTextCursor> SAL_CALL ScHeaderFooterTextObj::createTextCursorByRange(
281  const uno::Reference<text::XTextRange>& aTextPosition )
282 {
283  SolarMutexGuard aGuard;
284  if (!mxUnoText.is())
286  return mxUnoText->createTextCursorByRange(aTextPosition);
288 }
289 
291 {
292  OUString aDummy("???");
293  rData.aTitle = aDummy;
294  rData.aLongDocName = aDummy;
295  rData.aShortDocName = aDummy;
296  rData.aTabName = aDummy;
297  rData.nPageNo = 1;
298  rData.nTotalPages = 99;
299 }
300 
302 {
303  SolarMutexGuard aGuard;
304  OUString aRet;
305  const EditTextObject* pData;
306 
307  uno::Reference<css::sheet::XHeaderFooterContent> xContentObj = aTextData.GetContentObj();
308  if (!xContentObj.is())
309  throw css::uno::RuntimeException(
310  "ScHeaderFooterTextObj::getString: no ContentObj");
311 
313 
314  switch ( aTextData.GetPart() )
315  {
317  pData = pObj->GetLeftEditObject();
318  break;
320  pData = pObj->GetCenterEditObject();
321  break;
323  pData = pObj->GetRightEditObject();
324  break;
325  default:
326  SAL_WARN("sc.ui","unexpected enum value of ScHeaderFooterPart");
327  pData = nullptr;
328  }
329 
330  if (pData)
331  {
332  // for pure text, no font info is needed in pool defaults
334 
336  FillDummyFieldData( aData );
337  aEditEngine.SetData( aData );
338 
339  aEditEngine.SetTextCurrentDefaults(*pData);
340  aRet = ScEditUtil::GetSpaceDelimitedString( aEditEngine );
341  }
342  return aRet;
343 }
344 
345 void SAL_CALL ScHeaderFooterTextObj::setString( const OUString& aText )
346 {
347  SolarMutexGuard aGuard;
348 
349  // for pure text, no font info is needed in pool defaults
351  aEditEngine.SetTextCurrentDefaults( aText );
352  aTextData.UpdateData(aEditEngine);
353 }
354 
355 void SAL_CALL ScHeaderFooterTextObj::insertString( const uno::Reference<text::XTextRange>& xRange,
356  const OUString& aString, sal_Bool bAbsorb )
357 {
358  SolarMutexGuard aGuard;
359  if (!mxUnoText.is())
361  mxUnoText->insertString( xRange, aString, bAbsorb );
362 }
363 
365  const uno::Reference<text::XTextRange>& xRange,
366  sal_Int16 nControlCharacter, sal_Bool bAbsorb )
367 {
368  SolarMutexGuard aGuard;
369  if (!mxUnoText.is())
371  mxUnoText->insertControlCharacter( xRange, nControlCharacter, bAbsorb );
372 }
373 
375  const uno::Reference<text::XTextRange >& xRange,
376  const uno::Reference<text::XTextContent >& xContent,
377  sal_Bool bAbsorb )
378 {
379  SolarMutexGuard aGuard;
380  if ( xContent.is() && xRange.is() )
381  {
382  ScEditFieldObj* pHeaderField = comphelper::getUnoTunnelImplementation<ScEditFieldObj>( xContent );
383 
384  SvxUnoTextRangeBase* pTextRange =
385  comphelper::getUnoTunnelImplementation<ScHeaderFooterTextCursor>( xRange );
386 
387  if ( pHeaderField && !pHeaderField->IsInserted() && pTextRange )
388  {
389  SvxEditSource* pEditSource = pTextRange->GetEditSource();
390  ESelection aSelection(pTextRange->GetSelection());
391 
392  if (!bAbsorb)
393  {
394  // don't replace -> append at end
395  aSelection.Adjust();
396  aSelection.nStartPara = aSelection.nEndPara;
397  aSelection.nStartPos = aSelection.nEndPos;
398  }
399 
400  SvxFieldItem aItem(pHeaderField->CreateFieldItem());
401 
402  SvxTextForwarder* pForwarder = pEditSource->GetTextForwarder();
403  pForwarder->QuickInsertField( aItem, aSelection );
404  pEditSource->UpdateData();
405 
406  // new selection: a digit
407  aSelection.Adjust();
408  aSelection.nEndPara = aSelection.nStartPara;
409  aSelection.nEndPos = aSelection.nStartPos + 1;
410 
411  uno::Reference<text::XTextRange> xTextRange;
412  switch ( aTextData.GetPart() )
413  {
415  xTextRange = aTextData.GetContentObj()->getLeftText();
416  break;
418  xTextRange = aTextData.GetContentObj()->getCenterText();
419  break;
421  xTextRange = aTextData.GetContentObj()->getRightText();
422  break;
423  }
424 
425  pHeaderField->InitDoc(xTextRange, std::make_unique<ScHeaderFooterEditSource>(aTextData), aSelection);
426 
427  // for bAbsorb=FALSE, the new selection must be behind the inserted content
428  // (the xml filter relies on this)
429  if (!bAbsorb)
430  aSelection.nStartPos = aSelection.nEndPos;
431 
432  pTextRange->SetSelection( aSelection );
433 
434  return;
435  }
436  }
437 
438  if (!mxUnoText.is())
440  mxUnoText->insertTextContent( xRange, xContent, bAbsorb );
441 }
442 
444  const uno::Reference<text::XTextContent>& xContent )
445 {
446  SolarMutexGuard aGuard;
447  if ( xContent.is() )
448  {
449  ScEditFieldObj* pHeaderField = comphelper::getUnoTunnelImplementation<ScEditFieldObj>(xContent);
450  if ( pHeaderField && pHeaderField->IsInserted() )
451  {
453  pHeaderField->DeleteField();
454  return;
455  }
456  }
457  if (!mxUnoText.is())
459  mxUnoText->removeTextContent( xContent );
460 }
461 
462 uno::Reference<text::XText> SAL_CALL ScHeaderFooterTextObj::getText()
463 {
464  SolarMutexGuard aGuard;
465  if (!mxUnoText.is())
467  return mxUnoText->getText();
468 }
469 
470 uno::Reference<text::XTextRange> SAL_CALL ScHeaderFooterTextObj::getStart()
471 {
472  SolarMutexGuard aGuard;
473  if (!mxUnoText.is())
475  return mxUnoText->getStart();
476 }
477 
478 uno::Reference<text::XTextRange> SAL_CALL ScHeaderFooterTextObj::getEnd()
479 {
480  SolarMutexGuard aGuard;
481  if (!mxUnoText.is())
483  return mxUnoText->getEnd();
484 }
485 
486 // XTextFieldsSupplier
487 
488 uno::Reference<container::XEnumerationAccess> SAL_CALL ScHeaderFooterTextObj::getTextFields()
489 {
490  SolarMutexGuard aGuard;
491  // all fields
492  return new ScHeaderFieldsObj(aTextData);
493 }
494 
495 uno::Reference<container::XNameAccess> SAL_CALL ScHeaderFooterTextObj::getTextFieldMasters()
496 {
497  // this does not exists in Calc (?)
498  return nullptr;
499 }
500 
501 // XTextRangeMover
502 
504  const uno::Reference<text::XTextRange>& xRange,
505  sal_Int16 nParagraphs )
506 {
507  SolarMutexGuard aGuard;
508  if (!mxUnoText.is())
510  mxUnoText->moveTextRange( xRange, nParagraphs );
511 }
512 
513 // XEnumerationAccess
514 
515 uno::Reference<container::XEnumeration> SAL_CALL ScHeaderFooterTextObj::createEnumeration()
516 {
517  SolarMutexGuard aGuard;
518  if (!mxUnoText.is())
520  return mxUnoText->createEnumeration();
521 }
522 
523 // XElementAccess
524 
526 {
527  SolarMutexGuard aGuard;
528  if (!mxUnoText.is())
530  return mxUnoText->getElementType();
531 }
532 
534 {
535  SolarMutexGuard aGuard;
536  if (!mxUnoText.is())
538  return mxUnoText->hasElements();
539 }
540 
542  SvxUnoTextCursor( rText.GetUnoText() ),
543  mxTextObj( &rText )
544 {
545 }
546 
548 {
549 }
550 
551 // SvxUnoTextCursor methods reimplemented here to return the right objects:
552 
553 uno::Reference<text::XText> SAL_CALL ScCellTextCursor::getText()
554 {
555  return mxTextObj;
556 }
557 
558 uno::Reference<text::XTextRange> SAL_CALL ScCellTextCursor::getStart()
559 {
560  SolarMutexGuard aGuard;
561 
563 
565 
566  ESelection aNewSel(GetSelection());
567  aNewSel.nEndPara = aNewSel.nStartPara;
568  aNewSel.nEndPos = aNewSel.nStartPos;
569  pNew->SetSelection( aNewSel );
570 
571  return static_cast<SvxUnoTextRangeBase*>(pNew.get());
572 }
573 
574 uno::Reference<text::XTextRange> SAL_CALL ScCellTextCursor::getEnd()
575 {
576  SolarMutexGuard aGuard;
577 
579 
581 
582  ESelection aNewSel(GetSelection());
583  aNewSel.nStartPara = aNewSel.nEndPara;
584  aNewSel.nStartPos = aNewSel.nEndPos;
585  pNew->SetSelection( aNewSel );
586 
587  return static_cast<SvxUnoTextRangeBase*>(pNew.get());
588 }
589 
590 // XUnoTunnel
591 
593 
595  SvxUnoTextCursor( rText->GetUnoText() ),
596  rTextObj( rText )
597 {}
598 
600 
601 // SvxUnoTextCursor methods reimplemented here to return the right objects:
602 
603 uno::Reference<text::XText> SAL_CALL ScHeaderFooterTextCursor::getText()
604 {
605  SolarMutexGuard aGuard;
606  return rTextObj;
607 }
608 
609 uno::Reference<text::XTextRange> SAL_CALL ScHeaderFooterTextCursor::getStart()
610 {
611  SolarMutexGuard aGuard;
612 
614 
616 
617  ESelection aNewSel(GetSelection());
618  aNewSel.nEndPara = aNewSel.nStartPara;
619  aNewSel.nEndPos = aNewSel.nStartPos;
620  pNew->SetSelection( aNewSel );
621 
622  return static_cast<SvxUnoTextRangeBase*>(pNew.get());
623 }
624 
625 uno::Reference<text::XTextRange> SAL_CALL ScHeaderFooterTextCursor::getEnd()
626 {
627  SolarMutexGuard aGuard;
628 
630 
632 
633  ESelection aNewSel(GetSelection());
634  aNewSel.nStartPara = aNewSel.nEndPara;
635  aNewSel.nStartPos = aNewSel.nEndPos;
636  pNew->SetSelection( aNewSel );
637 
638  return static_cast<SvxUnoTextRangeBase*>(pNew.get());
639 }
640 
641 // XUnoTunnel
642 
644 
645 ScDrawTextCursor::ScDrawTextCursor( const uno::Reference<text::XText>& xParent,
646  const SvxUnoTextBase& rText ) :
647  SvxUnoTextCursor( rText ),
648  xParentText( xParent )
649 
650 {
651 }
652 
654 {
655 }
656 
657 // SvxUnoTextCursor methods reimplemented here to return the right objects:
658 
659 uno::Reference<text::XText> SAL_CALL ScDrawTextCursor::getText()
660 {
661  SolarMutexGuard aGuard;
662  return xParentText;
663 }
664 
665 uno::Reference<text::XTextRange> SAL_CALL ScDrawTextCursor::getStart()
666 {
667  SolarMutexGuard aGuard;
668 
670 
672 
673  ESelection aNewSel(GetSelection());
674  aNewSel.nEndPara = aNewSel.nStartPara;
675  aNewSel.nEndPos = aNewSel.nStartPos;
676  pNew->SetSelection( aNewSel );
677 
678  return static_cast<SvxUnoTextRangeBase*>(pNew.get());
679 }
680 
681 uno::Reference<text::XTextRange> SAL_CALL ScDrawTextCursor::getEnd()
682 {
683  SolarMutexGuard aGuard;
684 
686 
688 
689  ESelection aNewSel(GetSelection());
690  aNewSel.nStartPara = aNewSel.nEndPara;
691  aNewSel.nStartPos = aNewSel.nEndPos;
692  pNew->SetSelection( aNewSel );
693 
694  return static_cast<SvxUnoTextRangeBase*>(pNew.get());
695 }
696 
697 // XUnoTunnel
698 
700 
702 {
703  SfxItemPool* pEnginePool = EditEngine::CreatePool();
704  pEnginePool->SetDefaultMetric( MapUnit::Map100thMM );
705  pEnginePool->FreezeIdRanges();
706 
707  pEditEngine.reset( new ScFieldEditEngine(nullptr, pEnginePool, nullptr, true) ); // TRUE: become owner of pool
709  pOriginalSource.reset( new ScSimpleEditSource( pForwarder.get() ) );
710 }
711 
713 {
714  SolarMutexGuard aGuard; // needed for EditEngine dtor
715 
716  pOriginalSource.reset();
717  pForwarder.reset();
718  pEditEngine.reset();
719 }
720 
722  SvxUnoText( GetOriginalSource(), ScCellObj::GetEditPropertySet(), uno::Reference<text::XText>() )
723 {
724 }
725 
727 {
728 }
729 
731 {
732  GetEditEngine()->SetTextCurrentDefaults( rTextObject );
733 
734  ESelection aSel;
735  ::GetSelection( aSel, GetEditSource()->GetTextForwarder() );
736  SetSelection( aSel );
737 }
738 
739 std::unique_ptr<EditTextObject> ScEditEngineTextObj::CreateTextObject()
740 {
741  return GetEditEngine()->CreateTextObject();
742 }
743 
745  pDocShell( pDocSh ),
746  aCellPos( rP ),
747  bDataValid( false ),
748  bInUpdate( false ),
749  bDirty( false ),
750  bDoUpdate( true )
751 {
752  if (pDocShell)
754 }
755 
757 {
758  SolarMutexGuard aGuard; // needed for EditEngine dtor
759 
760  if (pDocShell)
761  {
764  }
765  else
766  pEditEngine.reset();
767 
768  pForwarder.reset();
769 
770  pOriginalSource.reset();
771 }
772 
774 {
775  if (!pOriginalSource)
777  return pOriginalSource.get();
778 }
779 
781 {
782  if (!pEditEngine)
783  {
784  if ( pDocShell )
785  {
786  ScDocument& rDoc = pDocShell->GetDocument();
788  }
789  else
790  {
791  SfxItemPool* pEnginePool = EditEngine::CreatePool();
792  pEnginePool->FreezeIdRanges();
793  pEditEngine.reset( new ScFieldEditEngine(nullptr, pEnginePool, nullptr, true) );
794  }
795  // currently, GetPortions doesn't work if UpdateMode is sal_False,
796  // this will be fixed (in EditEngine) by src600
797 // pEditEngine->SetUpdateMode( sal_False );
798  pEditEngine->EnableUndo( false );
799  if (pDocShell)
800  pEditEngine->SetRefDevice(pDocShell->GetRefDevice());
801  else
802  pEditEngine->SetRefMapMode(MapMode(MapUnit::Map100thMM));
804  }
805 
806  if (bDataValid)
807  return pForwarder.get();
808 
809  if (pDocShell)
810  {
811  ScDocument& rDoc = pDocShell->GetDocument();
812 
813  SfxItemSet aDefaults( pEditEngine->GetEmptyItemSet() );
814  if( const ScPatternAttr* pPattern =
815  rDoc.GetPattern( aCellPos.Col(), aCellPos.Row(), aCellPos.Tab() ) )
816  {
817  pPattern->FillEditItemSet( &aDefaults );
818  pPattern->FillEditParaItems( &aDefaults ); // including alignment etc. (for reading)
819  }
820 
821  ScRefCellValue aCell(rDoc, aCellPos);
822  if (aCell.meType == CELLTYPE_EDIT)
823  {
824  const EditTextObject* pObj = aCell.mpEditText;
825  pEditEngine->SetTextNewDefaults(*pObj, aDefaults);
826  }
827  else
828  {
829  sal_uInt32 nFormat = rDoc.GetNumberFormat(aCellPos);
830  OUString aText;
831  ScCellFormat::GetInputString(aCell, nFormat, aText, *rDoc.GetFormatTable(), rDoc);
832  if (!aText.isEmpty())
833  pEditEngine->SetTextNewDefaults(aText, aDefaults);
834  else
835  pEditEngine->SetDefaults(aDefaults);
836  }
837  }
838 
839  bDataValid = true;
840  return pForwarder.get();
841 }
842 
844 {
845  if ( bDoUpdate )
846  {
847  OSL_ENSURE(pEditEngine != nullptr, "no EditEngine for UpdateData()");
848  if ( pDocShell && pEditEngine )
849  {
850  // during the own UpdateData call, bDataValid must not be reset,
851  // or things like attributes after the text would be lost
852  // (are not stored in the cell)
853  bInUpdate = true; // prevents bDataValid from being reset
854  pDocShell->GetDocFunc().PutData(aCellPos, *pEditEngine, true); // always as text
855 
856  bInUpdate = false;
857  bDirty = false;
858  }
859  }
860  else
861  bDirty = true;
862 }
863 
865 {
866  const SfxHintId nId = rHint.GetId();
867  if ( nId == SfxHintId::Dying )
868  {
869  pDocShell = nullptr; // invalid now
870 
871  pForwarder.reset();
872  pEditEngine.reset(); // EditEngine uses document's pool
873  }
874  else if ( nId == SfxHintId::DataChanged )
875  {
876  if (!bInUpdate) // not for own UpdateData calls
877  bDataValid = false; // text has to be read from the cell again
878  }
879 }
880 
882  ScCellTextData( pDocSh, rP ),
883  SvxUnoText( GetOriginalSource(), ScCellObj::GetEditPropertySet(), uno::Reference<text::XText>() )
884 {
885 }
886 
887 ScCellTextObj::~ScCellTextObj() COVERITY_NOEXCEPT_FALSE
888 {
889 }
890 
891 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
ScDocShell * pDocShell
Definition: textuno.hxx:329
virtual css::uno::Type SAL_CALL getElementType() override
Definition: textuno.cxx:525
OUString aLongDocName
Definition: editutil.hxx:208
void Adjust()
SfxHintId
sal_Int32 nStartPara
virtual ~ScHeaderFooterTextCursor() override
Definition: textuno.cxx:599
virtual css::uno::Reference< css::text::XTextRange > SAL_CALL getStart() override
Definition: textuno.cxx:609
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:118
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
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:594
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:558
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:3691
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:574
ScHeaderFooterPart
Definition: textuno.hxx:50
ScCellTextData(ScDocShell *pDocSh, const ScAddress &rP)
Definition: textuno.cxx:744
virtual css::uno::Reference< css::text::XText > SAL_CALL getText() override
Definition: textuno.cxx:603
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
virtual ~ScDrawTextCursor() override
Definition: textuno.cxx:653
static const css::uno::Sequence< sal_Int8 > & getUnoTunnelId()
Definition: textuno.cxx:145
virtual sal_Bool SAL_CALL hasElements() override
Definition: textuno.cxx:533
void FreezeIdRanges()
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:756
ScCellTextObj(ScDocShell *pDocSh, const ScAddress &rP)
Definition: textuno.cxx:881
std::unique_ptr< ScCellEditSource > pOriginalSource
Definition: textuno.hxx:333
Generic UNO wrapper for edit engine's field item in cells, headers, and footers.
Definition: fielduno.hxx:162
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:665
const EditTextObject * mpEditText
Definition: cellvalue.hxx:109
ScHeaderFooterTextData(const ScHeaderFooterTextData &)=delete
std::unique_ptr< SvxEditEngineForwarder > pForwarder
Definition: textuno.hxx:303
const ESelection & GetSelection() const
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:364
static const SvxItemPropertySet * lcl_GetHdFtPropertySet()
Definition: textuno.cxx:52
OUString aShortDocName
Definition: editutil.hxx:209
virtual ~ScHeaderFooterTextObj() override
Definition: textuno.cxx:258
const EditTextObject * GetLeftEditObject() const
Definition: textuno.cxx:95
sal_Int32 nEndPos
virtual SvxTextForwarder * GetTextForwarder()
Definition: textuno.cxx:780
void Init(const EditTextObject *pLeft, const EditTextObject *pCenter, const EditTextObject *pRight)
Definition: textuno.cxx:157
static void FillDummyFieldData(ScHeaderFieldData &rData)
Definition: textuno.cxx:290
SC_DLLPUBLIC const ScPatternAttr * GetPattern(SCCOL nCol, SCROW nRow, SCTAB nTab) const
Definition: document.cxx:4785
virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() override
Definition: textuno.cxx:515
virtual void SAL_CALL removeTextContent(const css::uno::Reference< css::text::XTextContent > &xContent) override
Definition: textuno.cxx:443
virtual css::uno::Reference< css::container::XEnumerationAccess > SAL_CALL getTextFields() override
Definition: textuno.cxx:488
constexpr OUStringLiteral aData
static rtl::Reference< ScHeaderFooterContentObj > getImplementation(const css::uno::Reference< css::sheet::XHeaderFooterContent > &rObj)
Definition: textuno.cxx:151
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:681
void UpdateData()
Definition: textuno.cxx:843
SC_DLLPUBLIC SvNumberFormatter * GetFormatTable() const
Definition: documen2.cxx:440
sal_Int32 nEndPara
tools::Long nTotalPages
Definition: editutil.hxx:213
void SetTextCurrentDefaults(const EditTextObject &rTextObject)
SetText and apply defaults already set.
Definition: editutil.cxx:598
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:478
std::unique_ptr< EditTextObject > CreateTextObject()
Definition: textuno.cxx:739
ScCellTextCursor(ScCellObj &rText)
Definition: textuno.cxx:541
ScHeaderFooterTextObj(const css::uno::WeakReference< css::sheet::XHeaderFooterContent > &xContent, ScHeaderFooterPart nP, const EditTextObject *pTextObj)
Definition: textuno.cxx:240
#define SVX_UNOEDIT_NUMBERING_PROPERTIE
#define SC_MOD()
Definition: scmod.hxx:249
virtual css::uno::Reference< css::container::XNameAccess > SAL_CALL getTextFieldMasters() override
Definition: textuno.cxx:495
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:1151
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
virtual ~ScEditEngineTextObj() override
Definition: textuno.cxx:726
SCCOL Col() const
Definition: address.hxx:266
css::uno::Reference< css::text::XText > xParentText
Definition: textuno.hxx:271
const SvxUnoText & GetUnoText()
Definition: textuno.cxx:265
static SfxItemPool * CreatePool()
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:374
CellType meType
Definition: cellvalue.hxx:105
ScHeaderFooterTextData aTextData
Definition: textuno.hxx:145
void SetText(const EditTextObject &rTextObject)
Definition: textuno.cxx:730
std::unique_ptr< ScFieldEditEngine > pEditEngine
Definition: textuno.hxx:331
virtual ~ScCellTextCursor() override
Definition: textuno.cxx:547
virtual css::uno::Reference< css::text::XTextCursor > SAL_CALL createTextCursorByRange(const css::uno::Reference< css::text::XTextRange > &aTextPosition) override
Definition: textuno.cxx:280
void SetDefaultMetric(MapUnit eNewMetric)
#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 EditTextObject * GetTextObject() const
Definition: textuno.cxx:260
std::unique_ptr< ScFieldEditEngine > CreateFieldEditEngine()
Definition: documen2.cxx:1119
const EditTextObject * GetCenterEditObject() const
Definition: textuno.cxx:100
#define SVX_UNOEDIT_PARA_PROPERTIES
ScCellEditSource * GetOriginalSource()
Definition: textuno.cxx:773
void DisposeFieldEditEngine(std::unique_ptr< ScFieldEditEngine > &rpEditEngine)
Definition: documen2.cxx:1142
virtual css::uno::Reference< css::text::XText > SAL_CALL getText() override
Definition: textuno.cxx:553
really derive cell from range?
Definition: cellsuno.hxx:628
void RemoveUnoObject(SfxListener &rObject)
Definition: documen3.cxx:906
virtual css::uno::Reference< css::text::XTextRange > SAL_CALL getStart() override
Definition: textuno.cxx:470
SvxTextForwarder * GetTextForwarder()
Definition: textuno.cxx:184
const ScDocument & GetDocument() const
Definition: docsh.hxx:216
static OUString GetSpaceDelimitedString(const EditEngine &rEngine)
Retrieves string with paragraphs delimited by spaces.
Definition: editutil.cxx:97
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:355
virtual css::uno::Reference< css::text::XTextCursor > SAL_CALL createTextCursor() override
Definition: textuno.cxx:274
SvxEditSource * GetEditSource() const
virtual ~ScCellTextObj() COVERITY_NOEXCEPT_FALSE override
Definition: textuno.cxx:887
virtual void SAL_CALL moveTextRange(const css::uno::Reference< css::text::XTextRange > &xRange, sal_Int16 nParagraphs) override
Definition: textuno.cxx:503
#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:864
virtual css::uno::Reference< css::text::XText > SAL_CALL getText() override
Definition: textuno.cxx:462
virtual OUString SAL_CALL getString() override
Definition: textuno.cxx:301
ScDocFunc & GetDocFunc()
Definition: docsh.hxx:218
virtual css::uno::Reference< css::text::XTextRange > SAL_CALL getEnd() override
Definition: textuno.cxx:625
void SetSelection(const ESelection &rSelection)
std::unique_ptr< ScEditEngineDefaulter > pEditEngine
Definition: textuno.hxx:302
virtual css::uno::Reference< css::text::XText > SAL_CALL getCenterText() override
Definition: textuno.cxx:119
const css::uno::Sequence< sal_Int8 > & getSeq() const
ScHeaderFooterPart GetPart() const
Definition: textuno.hxx:125
constexpr TypedWhichId< SvxFontHeightItem > ATTR_FONT_HEIGHT(101)
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:345
virtual css::uno::Reference< css::text::XText > SAL_CALL getText() override
Definition: textuno.cxx:659
OutputDevice * GetRefDevice()
Definition: docsh3.cxx:465
#define CONVERT_TWIPS
sal_Int32 nStartPos