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