LibreOffice Module sc (master)  1
eeimpars.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 <scitems.hxx>
21 #include <editeng/eeitem.hxx>
22 
23 #include <editeng/adjustitem.hxx>
24 #include <editeng/editobj.hxx>
26 #include <editeng/langitem.hxx>
27 #include <o3tl/unit_conversion.hxx>
28 #include <svx/svdograf.hxx>
29 #include <svx/svdpage.hxx>
30 #include <svtools/htmlcfg.hxx>
31 #include <sfx2/sfxhtml.hxx>
32 #include <svl/zforlist.hxx>
33 #include <vcl/virdev.hxx>
34 #include <vcl/svapp.hxx>
35 #include <unotools/charclass.hxx>
36 #include <comphelper/string.hxx>
37 #include <osl/diagnose.h>
38 
39 #include <eeimport.hxx>
40 #include <global.hxx>
41 #include <document.hxx>
42 #include <editutil.hxx>
43 #include <docpool.hxx>
44 #include <attrib.hxx>
45 #include <patattr.hxx>
46 #include <eeparser.hxx>
47 #include <drwlayer.hxx>
48 #include <rangenam.hxx>
49 #include <progress.hxx>
50 #include <stringutil.hxx>
51 #include <rowheightcontext.hxx>
52 #include <fuinsert.hxx>
53 
54 #include <globstr.hrc>
55 #include <scresid.hxx>
56 
57 #include <memory>
58 
59 ScEEImport::ScEEImport( ScDocument* pDocP, const ScRange& rRange ) :
60  maRange( rRange ),
61  mpDoc( pDocP )
62 {
63  const ScPatternAttr* pPattern = mpDoc->GetPattern(
65  mpEngine.reset( new ScTabEditEngine(*pPattern, mpDoc->GetEditPool(), mpDoc, mpDoc->GetEditPool()) );
66  mpEngine->SetUpdateMode( false );
67  mpEngine->EnableUndo( false );
68 }
69 
71 {
72  // Sequence important, or else we crash in some dtor!
73  // Is guaranteed as ScEEImport is base class
74 }
75 
76 ErrCode ScEEImport::Read( SvStream& rStream, const OUString& rBaseURL )
77 {
78  ErrCode nErr = mpParser->Read( rStream, rBaseURL );
79 
80  SCCOL nEndCol;
81  SCROW nEndRow;
82  mpParser->GetDimensions( nEndCol, nEndRow );
83  if ( nEndCol != 0 )
84  {
85  nEndCol += maRange.aStart.Col() - 1;
86  if ( nEndCol > mpDoc->MaxCol() )
87  nEndCol = mpDoc->MaxCol();
88  }
89  else
90  nEndCol = maRange.aStart.Col();
91  if ( nEndRow != 0 )
92  {
93  nEndRow += maRange.aStart.Row() - 1;
94  if ( nEndRow > mpDoc->MaxRow() )
95  nEndRow = mpDoc->MaxRow();
96  }
97  else
98  nEndRow = maRange.aStart.Row();
99  maRange.aEnd.Set( nEndCol, nEndRow, maRange.aStart.Tab() );
100 
101  return nErr;
102 }
103 
104 namespace
105 {
106  bool IsValidSel(const ScTabEditEngine& rEngine, const ESelection& rSel)
107  {
108  const auto nParaCount = rEngine.GetParagraphCount();
109  return rSel.nStartPara < nParaCount && rSel.nEndPara < nParaCount;
110  }
111 }
112 
113 void ScEEImport::WriteToDocument( bool bSizeColsRows, double nOutputFactor, SvNumberFormatter* pFormatter, bool bConvertDate )
114 {
115  std::unique_ptr<ScProgress> pProgress( new ScProgress( mpDoc->GetDocumentShell(),
116  ScResId( STR_LOAD_DOC ), mpParser->ListSize(), true ) );
117  sal_uLong nProgress = 0;
118 
119  SCCOL nStartCol, nEndCol;
120  SCROW nStartRow, nEndRow;
121  SCTAB nTab;
122  SCROW nOverlapRowMax, nLastMergedRow;
123  SCCOL nMergeColAdd;
124  nStartCol = maRange.aStart.Col();
125  nStartRow = maRange.aStart.Row();
126  nTab = maRange.aStart.Tab();
127  nEndCol = maRange.aEnd.Col();
128  nEndRow = maRange.aEnd.Row();
129  nOverlapRowMax = 0;
130  nMergeColAdd = 0;
131  nLastMergedRow = SCROW_MAX;
132  bool bHasGraphics = false;
134  if (!pFormatter)
135  pFormatter = mpDoc->GetFormatTable();
136  bool bNumbersEnglishUS = false;
137  if (pFormatter->GetLanguage() == LANGUAGE_SYSTEM)
138  {
139  // Automatic language option selected. Check for the global 'use US English' option.
140  SvxHtmlOptions aOpt;
141  bNumbersEnglishUS = aOpt.IsNumbersEnglishUS();
142  }
143  ScDocumentPool* pDocPool = mpDoc->GetPool();
144  ScRangeName* pRangeNames = mpDoc->GetRangeName();
145  for ( size_t i = 0, n = mpParser->ListSize(); i < n; ++i )
146  {
147  pE = mpParser->ListEntry( i );
148  SCROW nRow = nStartRow + pE->nRow;
149  if ( nRow != nLastMergedRow )
150  nMergeColAdd = 0;
151  SCCOL nCol = nStartCol + pE->nCol + nMergeColAdd;
152  // Determine RowMerge
153  // Pure ColMerge and ColMerge of the first MergeRow already done during parsing
154  if (nRow <= nOverlapRowMax && mpDoc->ValidCol(nCol))
155  {
156  while ( nCol <= mpDoc->MaxCol() && mpDoc->HasAttrib( nCol, nRow, nTab,
157  nCol, nRow, nTab, HasAttrFlags::Overlapped ) )
158  {
159  nCol++;
160  nMergeColAdd++;
161  }
162  nLastMergedRow = nRow;
163  }
164  // Add for second run
165  pE->nCol = nCol;
166  pE->nRow = nRow;
167  if ( mpDoc->ValidCol(nCol) && mpDoc->ValidRow(nRow) )
168  {
169  SfxItemSet aSet = mpEngine->GetAttribs( pE->aSel );
170  // Remove default: we set left/right ourselves depending on Text or
171  // Number
172  // EditView.GetAttribs always returns complete Set filled with
173  // defaults
174  const SfxPoolItem& rItem = aSet.Get( EE_PARA_JUST );
175  if ( static_cast<const SvxAdjustItem&>(rItem).GetAdjust() == SvxAdjust::Left )
176  aSet.ClearItem( EE_PARA_JUST );
177 
178  // Test whether simple String without mixed attributes
179  bool bSimple = ( pE->aSel.nStartPara == pE->aSel.nEndPara );
180  for (sal_uInt16 nId = EE_CHAR_START; nId <= EE_CHAR_END && bSimple; nId++)
181  {
182  const SfxPoolItem* pItem = nullptr;
183  SfxItemState eState = aSet.GetItemState( nId, true, &pItem );
184  if (eState == SfxItemState::DONTCARE)
185  bSimple = false;
186  else if (eState == SfxItemState::SET)
187  {
188  if ( nId == EE_CHAR_ESCAPEMENT ) // Super-/Subscript always via EE
189  {
190  if ( static_cast<SvxEscapement>(static_cast<const SvxEscapementItem*>(pItem)->GetEnumValue())
191  != SvxEscapement::Off )
192  bSimple = false;
193  }
194  }
195  }
196  if ( bSimple )
197  { // Contains field commands?
198  SfxItemState eFieldState = aSet.GetItemState( EE_FEATURE_FIELD, false );
199  if ( eFieldState == SfxItemState::DONTCARE || eFieldState == SfxItemState::SET )
200  bSimple = false;
201  }
202 
203  // HTML
204  OUString aValStr, aNumStr;
205  double fVal = 0.0;
206  sal_uInt32 nNumForm = 0;
207  LanguageType eNumLang = LANGUAGE_NONE;
208  if ( pE->pNumStr )
209  { // SDNUM needs to be if SDVAL
210  aNumStr = *pE->pNumStr;
211  if ( pE->pValStr )
212  aValStr = *pE->pValStr;
214  nNumForm, eNumLang, aValStr, aNumStr, *pFormatter );
215  }
216 
217  // Set attributes
218  auto pAttr = std::make_unique<ScPatternAttr>( pDocPool );
219  pAttr->GetFromEditItemSet( &aSet );
220  SfxItemSet* pAttrItemSet = &pAttr->GetItemSet();
221  if (!aNumStr.isEmpty())
222  {
223  pAttrItemSet->Put( SfxUInt32Item( ATTR_VALUE_FORMAT, nNumForm ) );
224  pAttrItemSet->Put( SvxLanguageItem( eNumLang, ATTR_LANGUAGE_FORMAT ) );
225  }
226  const SfxItemSet& rESet = pE->aItemSet;
227  if ( rESet.Count() )
228  {
229  const SfxPoolItem* pItem;
230  if ( rESet.GetItemState( ATTR_BACKGROUND, false, &pItem) == SfxItemState::SET )
231  pAttrItemSet->Put( *pItem );
232  if ( rESet.GetItemState( ATTR_BORDER, false, &pItem) == SfxItemState::SET )
233  pAttrItemSet->Put( *pItem );
234  if ( rESet.GetItemState( ATTR_SHADOW, false, &pItem) == SfxItemState::SET )
235  pAttrItemSet->Put( *pItem );
236  // HTML
237  if ( rESet.GetItemState( ATTR_HOR_JUSTIFY, false, &pItem) == SfxItemState::SET )
238  pAttrItemSet->Put( *pItem );
239  if ( rESet.GetItemState( ATTR_VER_JUSTIFY, false, &pItem) == SfxItemState::SET )
240  pAttrItemSet->Put( *pItem );
241  if ( rESet.GetItemState( ATTR_LINEBREAK, false, &pItem) == SfxItemState::SET )
242  pAttrItemSet->Put( *pItem );
243  if ( rESet.GetItemState( ATTR_FONT_COLOR, false, &pItem) == SfxItemState::SET )
244  pAttrItemSet->Put( *pItem );
245  if ( rESet.GetItemState( ATTR_FONT_UNDERLINE, false, &pItem) == SfxItemState::SET )
246  pAttrItemSet->Put( *pItem );
247  // HTML LATIN/CJK/CTL script type dependent
248  const SfxPoolItem* pFont;
249  if ( rESet.GetItemState( ATTR_FONT, false, &pFont) != SfxItemState::SET )
250  pFont = nullptr;
251  const SfxPoolItem* pHeight;
252  if ( rESet.GetItemState( ATTR_FONT_HEIGHT, false, &pHeight) != SfxItemState::SET )
253  pHeight = nullptr;
254  const SfxPoolItem* pWeight;
255  if ( rESet.GetItemState( ATTR_FONT_WEIGHT, false, &pWeight) != SfxItemState::SET )
256  pWeight = nullptr;
257  const SfxPoolItem* pPosture;
258  if ( rESet.GetItemState( ATTR_FONT_POSTURE, false, &pPosture) != SfxItemState::SET )
259  pPosture = nullptr;
260  // Number format
261  const SfxPoolItem* pNumFmt = nullptr;
262  if ( rESet.GetItemState(ATTR_VALUE_FORMAT, false, &pNumFmt) == SfxItemState::SET )
263  pAttrItemSet->Put(*pNumFmt);
264  if ( pFont || pHeight || pWeight || pPosture )
265  {
266  OUString aStr( mpEngine->GetText( pE->aSel ) );
267  SvtScriptType nScriptType = mpDoc->GetStringScriptType( aStr );
268  const SvtScriptType nScripts[3] = { SvtScriptType::LATIN,
269  SvtScriptType::ASIAN, SvtScriptType::COMPLEX };
270  for (SvtScriptType nScript : nScripts)
271  {
272  if ( nScriptType & nScript )
273  {
274  if ( pFont )
275  {
276  pAttrItemSet->Put( pFont->CloneSetWhich(
278  }
279  if ( pHeight )
280  {
281  pAttrItemSet->Put( pHeight->CloneSetWhich(
283  }
284  if ( pWeight )
285  {
286  pAttrItemSet->Put( pWeight->CloneSetWhich(
288  }
289  if ( pPosture )
290  {
291  pAttrItemSet->Put( pPosture->CloneSetWhich(
293  }
294  }
295  }
296  }
297  }
298  if ( pE->nColOverlap > 1 || pE->nRowOverlap > 1 )
299  { // Merged cells, with SfxItemSet.Put() is faster than
300  // with ScDocument.DoMerge() afterwards
301  ScMergeAttr aMerge( pE->nColOverlap, pE->nRowOverlap );
302  pAttrItemSet->Put( aMerge );
303  SCROW nRO = 0;
304  if ( pE->nColOverlap > 1 )
305  mpDoc->ApplyFlagsTab( nCol+1, nRow,
306  nCol + pE->nColOverlap - 1, nRow, nTab,
307  ScMF::Hor );
308  if ( pE->nRowOverlap > 1 )
309  {
310  nRO = nRow + pE->nRowOverlap - 1;
311  mpDoc->ApplyFlagsTab( nCol, nRow+1,
312  nCol, nRO , nTab,
313  ScMF::Ver );
314  if ( nRO > nOverlapRowMax )
315  nOverlapRowMax = nRO;
316  }
317  if ( pE->nColOverlap > 1 && pE->nRowOverlap > 1 )
318  mpDoc->ApplyFlagsTab( nCol+1, nRow+1,
319  nCol + pE->nColOverlap - 1, nRO, nTab,
320  ScMF::Hor | ScMF::Ver );
321  }
322  const ScStyleSheet* pStyleSheet =
323  mpDoc->GetPattern( nCol, nRow, nTab )->GetStyleSheet();
324  pAttr->SetStyleSheet( const_cast<ScStyleSheet*>(pStyleSheet) );
325  auto rAttrItemSet2 = mpDoc->SetPattern( nCol, nRow, nTab, std::move(pAttr) )->GetItemSet();
326 
327  // Add data
328  if (bSimple)
329  {
330  ScSetStringParam aParam;
331  aParam.mpNumFormatter = pFormatter;
332  aParam.mbDetectNumberFormat = true;
334  aParam.mbHandleApostrophe = false;
335  aParam.mbCheckLinkFormula = true;
336 
337  if (!aValStr.isEmpty())
338  mpDoc->SetValue( nCol, nRow, nTab, fVal );
339  else if ( !pE->aSel.HasRange() )
340  {
341  // maybe ALT text of IMG or similar
342  mpDoc->SetString( nCol, nRow, nTab, pE->aAltText, &aParam );
343  // If SelRange is completely empty, the succeeding text can be in the same paragraph!
344  }
345  else
346  {
347  OUString aStr;
348  if( pE->bEntirePara )
349  {
350  aStr = mpEngine->GetText( pE->aSel.nStartPara );
351  }
352  else
353  {
354  aStr = comphelper::string::strip(mpEngine->GetText(pE->aSel), ' ');
355  }
356 
357  bool bTextFormat = false;
358 
359  const SfxPoolItem* pNumFmt = nullptr;
360  if (rAttrItemSet2.GetItemState(ATTR_VALUE_FORMAT, false, &pNumFmt) == SfxItemState::SET)
361  {
362  sal_uInt32 nNumFmt = static_cast<const SfxUInt32Item*>(pNumFmt)->GetValue();
363  SvNumFormatType nType = pFormatter->GetType(nNumFmt);
364  if (nType == SvNumFormatType::TEXT)
365  // Format is set to Text.
366  bTextFormat = true;
367  }
368 
369  // TODO: RTF import should follow the language tag,
370  // currently this follows the HTML options for both, HTML
371  // and RTF.
372  if (bNumbersEnglishUS)
373  {
374  pFormatter->ChangeIntl( LANGUAGE_ENGLISH_US);
375  sal_uInt32 nIndex = pFormatter->GetStandardIndex( LANGUAGE_ENGLISH_US);
376  double fEnVal = 0.0;
377  if (pFormatter->IsNumberFormat( aStr, nIndex, fEnVal))
378  {
379  sal_uInt32 nNewIndex =
380  pFormatter->GetFormatForLanguageIfBuiltIn(
381  nIndex, LANGUAGE_SYSTEM);
382  OSL_ENSURE( nNewIndex != nIndex, "ScEEImport::WriteToDocument: NumbersEnglishUS not a built-in format?");
383  pFormatter->GetInputLineString( fEnVal, nNewIndex, aStr);
384  }
385  else
386  bTextFormat = true;
387  pFormatter->ChangeIntl( LANGUAGE_SYSTEM);
388  }
389 
390  // #105460#, #i4180# String cells can't contain tabs or linebreaks
391  // -> replace with spaces
392  aStr = aStr.replaceAll( "\t", " " );
393  aStr = aStr.replaceAll( "\n", " " );
394 
395  if (bTextFormat)
396  {
397  aParam.mbDetectNumberFormat = false;
399  }
400  else
401  aParam.mbDetectNumberFormat = bConvertDate;
402 
403  mpDoc->SetString(nCol, nRow, nTab, aStr, &aParam);
404  }
405  }
406  else if (std::unique_ptr<EditTextObject> pTextObject = IsValidSel(*mpEngine, pE->aSel) ? mpEngine->CreateTextObject(pE->aSel) : nullptr)
407  {
408  // The cell will own the text object instance.
409  mpDoc->SetEditText(ScAddress(nCol,nRow,nTab), std::move(pTextObject));
410  }
411  if ( !pE->maImageList.empty() )
412  bHasGraphics |= GraphicSize( nCol, nRow, pE );
413  if ( pE->pName )
414  { // Anchor Name => RangeName
415  if (!pRangeNames->findByUpperName(ScGlobal::getCharClassPtr()->uppercase(*pE->pName)))
416  {
417  ScRangeData* pData = new ScRangeData( *mpDoc, *pE->pName,
418  ScAddress( nCol, nRow, nTab ) );
419  pRangeNames->insert( pData );
420  }
421  }
422  }
423  pProgress->SetStateOnPercent( ++nProgress );
424  }
425  if ( bSizeColsRows )
426  {
427  // Column widths
428  ColWidthsMap& rColWidths = mpParser->GetColWidths();
429  if ( !rColWidths.empty() )
430  {
431  nProgress = 0;
432  pProgress->SetState( nProgress, nEndCol - nStartCol + 1 );
433  for ( SCCOL nCol = nStartCol; nCol <= nEndCol; nCol++ )
434  {
435  sal_uInt16 nWidth = 0;
436  ColWidthsMap::const_iterator it = rColWidths.find( nCol );
437  if ( it != rColWidths.end() )
438  nWidth = it->second;
439  if ( nWidth )
440  mpDoc->SetColWidth( nCol, nTab, nWidth );
441  pProgress->SetState( ++nProgress );
442  }
443  }
444  pProgress.reset(); // SetOptimalHeight has its own ProgressBar
445  // Adjust line height, base is 100% zoom
446  Fraction aZoom( 1, 1 );
447  // Factor is printer to display ratio
448  double nPPTX = ScGlobal::nScreenPPTX * static_cast<double>(aZoom) / nOutputFactor;
449  double nPPTY = ScGlobal::nScreenPPTY * static_cast<double>(aZoom);
451  sc::RowHeightContext aCxt(mpDoc->MaxRow(), nPPTX, nPPTY, aZoom, aZoom, pVirtDev);
453  mpDoc->SetOptimalHeight(aCxt, 0, nEndRow, 0, true);
454 
455  if ( !maRowHeights.empty() )
456  {
457  for ( SCROW nRow = nStartRow; nRow <= nEndRow; nRow++ )
458  {
459  RowHeightMap::const_iterator it = maRowHeights.find( nRow );
460  sal_uInt16 nHeight = it == maRowHeights.end() ? 0 : it->second;
461  if ( nHeight > mpDoc->GetRowHeight( nRow, nTab ) )
462  mpDoc->SetRowHeight( nRow, nTab, nHeight );
463  }
464  }
465  }
466  if ( !bHasGraphics )
467  return;
468 
469  // Insert graphics
470  for ( size_t i = 0, nListSize = mpParser->ListSize(); i < nListSize; ++i )
471  {
472  pE = mpParser->ListEntry( i );
473  if ( !pE->maImageList.empty() )
474  {
475  SCCOL nCol = pE->nCol;
476  SCROW nRow = pE->nRow;
477  if ( mpDoc->ValidCol(nCol) && mpDoc->ValidRow(nRow) )
478  InsertGraphic( nCol, nRow, nTab, pE );
479  }
480  }
481 }
482 
484 {
485  if ( pE->maImageList.empty() )
486  return false;
487  bool bHasGraphics = false;
489  tools::Long nWidth, nHeight;
490  nWidth = nHeight = 0;
491  char nDir = nHorizontal;
492  for (const std::unique_ptr<ScHTMLImage> & pImage : pE->maImageList)
493  {
494  ScHTMLImage* pI = pImage.get();
495  if ( pI->pGraphic )
496  bHasGraphics = true;
497  Size aSizePix = pI->aSize;
498  aSizePix.AdjustWidth(2 * pI->aSpace.X() );
499  aSizePix.AdjustHeight(2 * pI->aSpace.Y() );
500  Size aLogicSize = pDefaultDev->PixelToLogic( aSizePix, MapMode( MapUnit::MapTwip ) );
501  if ( nDir & nHorizontal )
502  nWidth += aLogicSize.Width();
503  else if ( nWidth < aLogicSize.Width() )
504  nWidth = aLogicSize.Width();
505  if ( nDir & nVertical )
506  nHeight += aLogicSize.Height();
507  else if ( nHeight < aLogicSize.Height() )
508  nHeight = aLogicSize.Height();
509  nDir = pI->nDir;
510  }
511  // Column widths
512  ColWidthsMap& rColWidths = mpParser->GetColWidths();
513  tools::Long nThisWidth = 0;
514  ColWidthsMap::const_iterator it = rColWidths.find( nCol );
515  if ( it != rColWidths.end() )
516  nThisWidth = it->second;
517  tools::Long nColWidths = nThisWidth;
518  SCCOL nColSpanCol = nCol + pE->nColOverlap;
519  for ( SCCOL nC = nCol + 1; nC < nColSpanCol; nC++ )
520  {
521  ColWidthsMap::const_iterator it2 = rColWidths.find( nC );
522  if ( it2 != rColWidths.end() )
523  nColWidths += it2->second;
524  }
525  if ( nWidth > nColWidths )
526  { // Only insert difference in first column
527  rColWidths[ nCol ] = nWidth - nColWidths + nThisWidth;
528  }
529  // Distribute line height difference between all affected lines
530  SCROW nRowSpan = pE->nRowOverlap;
531  nHeight /= nRowSpan;
532  if ( nHeight == 0 )
533  nHeight = 1; // For definite comparison
534  for ( SCROW nR = nRow; nR < nRow + nRowSpan; nR++ )
535  {
536  RowHeightMap::const_iterator it2 = maRowHeights.find( nR );
537  tools::Long nRowHeight = it2 == maRowHeights.end() ? 0 : it2->second;
538  if ( nHeight > nRowHeight )
539  {
540  maRowHeights[ nR ] = nHeight;
541  }
542  }
543  return bHasGraphics;
544 }
545 
547  ScEEParseEntry* pE )
548 {
549  if ( pE->maImageList.empty() )
550  return ;
551  ScDrawLayer* pModel = mpDoc->GetDrawLayer();
552  if (!pModel)
553  {
554  mpDoc->InitDrawLayer();
555  pModel = mpDoc->GetDrawLayer();
556  }
557  SdrPage* pPage = pModel->GetPage( static_cast<sal_uInt16>(nTab) );
559 
560  Point aCellInsertPos(
563 
564  Point aInsertPos( aCellInsertPos );
565  Point aSpace;
566  Size aLogicSize;
567  char nDir = nHorizontal;
568  for (const std::unique_ptr<ScHTMLImage> & pImage : pE->maImageList)
569  {
570  ScHTMLImage* pI = pImage.get();
571  if ( nDir & nHorizontal )
572  { // Horizontal
573  aInsertPos.AdjustX(aLogicSize.Width() );
574  aInsertPos.AdjustX(aSpace.X() );
575  aInsertPos.setY( aCellInsertPos.Y() );
576  }
577  else
578  { // Vertical
579  aInsertPos.setX( aCellInsertPos.X() );
580  aInsertPos.AdjustY(aLogicSize.Height() );
581  aInsertPos.AdjustY(aSpace.Y() );
582  }
583  // Add offset of Spacing
584  aSpace = pDefaultDev->PixelToLogic( pI->aSpace, MapMode( MapUnit::Map100thMM ) );
585  aInsertPos += aSpace;
586 
587  Size aSizePix = pI->aSize;
588  aLogicSize = pDefaultDev->PixelToLogic( aSizePix, MapMode( MapUnit::Map100thMM ) );
589 
590  // Limit size
591  ::ScLimitSizeOnDrawPage( aLogicSize, aInsertPos, pPage->GetSize() );
592 
593  if ( pI->pGraphic )
594  {
595  tools::Rectangle aRect ( aInsertPos, aLogicSize );
596  SdrGrafObj* pObj = new SdrGrafObj(
597  *pModel,
598  *pI->pGraphic,
599  aRect);
600 
601  // calling SetGraphicLink here doesn't work
602  pObj->SetName( pI->aURL );
603 
604  pPage->InsertObject( pObj );
605 
606  // SetGraphicLink has to be used after inserting the object,
607  // otherwise an empty graphic is swapped in and the contact stuff crashes.
608  // See #i37444#.
609  pObj->SetGraphicLink( pI->aURL );
610 
611  pObj->SetLogicRect( aRect ); // Only after InsertObject!
612  }
613  nDir = pI->nDir;
614  }
615 }
616 
618  pEdit( pEditP ),
619  pPool( EditEngine::CreatePool() ),
620  pDocPool( new ScDocumentPool ),
621  nRtfLastToken(0),
622  nColCnt(0),
623  nRowCnt(0),
624  nColMax(0),
625  nRowMax(0)
626 {
627  // pPool is foisted on SvxRTFParser at RtfImportState::Start later on
628  pPool->SetSecondaryPool( pDocPool.get() );
629  pPool->FreezeIdRanges();
630  NewActEntry( nullptr );
631 }
632 
634 {
635  mxActEntry.reset();
636  maList.clear();
637 
638  // Don't delete Pool until the lists have been deleted
639  pPool->SetSecondaryPool( nullptr );
640  pDocPool.clear();
641  pPool.clear();
642 }
643 
645 { // New free-flying mxActEntry
646  mxActEntry = std::make_shared<ScEEParseEntry>(pPool.get());
647  mxActEntry->aSel.nStartPara = (pE ? pE->aSel.nEndPara + 1 : 0);
648  mxActEntry->aSel.nStartPos = 0;
649 }
650 
651 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void setExtraHeight(sal_uInt16 nH)
bool GraphicSize(SCCOL nCol, SCROW nRow, ScEEParseEntry *)
Definition: eeimpars.cxx:483
sal_uInt32 GetFormatForLanguageIfBuiltIn(sal_uInt32 nFormat, LanguageType eLnge=LANGUAGE_DONTKNOW)
std::vector< std::unique_ptr< ScHTMLImage > > maImageList
Definition: eeparser.hxx:63
constexpr double nPPTY
#define LANGUAGE_NONE
sal_Int32 nStartPara
sal_Int32 nIndex
ScDocument * mpDoc
Definition: eeimport.hxx:39
const char nHorizontal
Definition: eeparser.hxx:34
ScAddress aStart
Definition: address.hxx:499
Store parameters used in the ScDocument::SetString() method.
Definition: stringutil.hxx:34
constexpr TypedWhichId< SvxLanguageItem > ATTR_LANGUAGE_FORMAT(147)
bool mbHandleApostrophe
When true, treat input with a leading apostrophe as an escape character for a numeric value content...
Definition: stringutil.hxx:91
FormulaCommand pE
constexpr TypedWhichId< SvxBoxItem > ATTR_BORDER(150)
SfxItemSet aItemSet
Definition: eeparser.hxx:54
SCROW Row() const
Definition: address.hxx:261
#define LANGUAGE_ENGLISH_US
SvNumberFormatter * mpNumFormatter
Stores the pointer to the number formatter instance to be used during number format detection...
Definition: stringutil.hxx:70
std::unique_ptr< ContentProperties > pData
std::string GetValue
void SetName(const OUString &rStr, const bool bSetChanged=true)
void NewActEntry(const ScEEParseEntry *)
Definition: eeimpars.cxx:644
bool mbCheckLinkFormula
When true and the string results in a compiled formula, check the formula tokens for presence of func...
Definition: stringutil.hxx:100
OString strip(std::string_view rIn, char c)
ESelection aSel
Definition: eeparser.hxx:55
sal_uIntPtr sal_uLong
long Long
std::map< SCCOL, sal_uInt16 > ColWidthsMap
Definition: eeparser.hxx:95
SC_DLLPUBLIC ScRangeName * GetRangeName(SCTAB nTab) const
Definition: documen3.cxx:168
SC_DLLPUBLIC bool ApplyFlagsTab(SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow, SCTAB nTab, ScMF nFlags)
Definition: document.cxx:5038
constexpr Point convert(const Point &rPoint, o3tl::Length eFrom, o3tl::Length eTo)
sal_Int64 n
LanguageType GetLanguage() const
SvNumFormatType GetType(sal_uInt32 nFIndex) const
sal_Int16 nId
ScAddress aEnd
Definition: address.hxx:500
constexpr TypedWhichId< SvxAdjustItem > EE_PARA_JUST(EE_PARA_START+15)
constexpr TypedWhichId< SvxFontItem > ATTR_FONT(100)
SC_DLLPUBLIC void SetValue(SCCOL nCol, SCROW nRow, SCTAB nTab, const double &rVal)
Definition: document.cxx:3489
constexpr TypedWhichId< ScLineBreakCell > ATTR_LINEBREAK(139)
std::unique_ptr< ScTabEditEngine > mpEngine
Definition: eeimport.hxx:41
virtual void InsertObject(SdrObject *pObj, size_t nPos=SAL_MAX_SIZE)
const SCROW SCROW_MAX
Definition: address.hxx:55
SC_DLLPUBLIC bool HasAttrib(SCCOL nCol1, SCROW nRow1, SCTAB nTab1, SCCOL nCol2, SCROW nRow2, SCTAB nTab2, HasAttrFlags nMask) const
Definition: document.cxx:5205
SC_DLLPUBLIC SvtScriptType GetStringScriptType(const OUString &rString)
Definition: documen6.cxx:76
SC_DLLPUBLIC sal_uInt16 GetRowHeight(SCROW nRow, SCTAB nTab, bool bHiddenAsZero=true) const
Definition: document.cxx:4192
TextFormatPolicy meSetTextNumFormat
Determine when to set the 'Text' number format to the cell where the input string is being set...
Definition: stringutil.hxx:83
SC_DLLPUBLIC ScDocumentPool * GetPool()
Definition: document.cxx:6087
static OutputDevice * GetDefaultDevice()
constexpr tools::Long Width() const
SC_DLLPUBLIC SCROW MaxRow() const
Definition: document.hxx:872
constexpr TypedWhichId< SvxShadowItem > ATTR_SHADOW(152)
SC_DLLPUBLIC void SetColWidth(SCCOL nCol, SCTAB nTab, sal_uInt16 nNewWidth)
Definition: document.cxx:4114
sal_uInt32 GetStandardIndex(LanguageType eLnge=LANGUAGE_DONTKNOW)
bool bEntirePara
Definition: eeparser.hxx:73
static SC_DLLPUBLIC sal_uInt16 GetScriptedWhichID(SvtScriptType nScriptType, sal_uInt16 nWhich)
Map ATTR_((CJK|CTL)_)?FONT_...
Definition: global.cxx:865
ScEEImport(ScDocument *pDoc, const ScRange &rRange)
Definition: eeimpars.cxx:59
SCTAB Tab() const
Definition: address.hxx:270
SCROW nRowOverlap
Definition: eeparser.hxx:69
ScEEParser(EditEngine *)
Definition: eeimpars.cxx:617
bool IsNumbersEnglishUS() const
std::unique_ptr< Graphic > pGraphic
Definition: eeparser.hxx:44
SC_DLLPUBLIC const ScPatternAttr * GetPattern(SCCOL nCol, SCROW nRow, SCTAB nTab) const
Definition: document.cxx:4766
constexpr TypedWhichId< SvxUnderlineItem > ATTR_FONT_UNDERLINE(104)
constexpr double nPPTX
std::optional< OUString > pValStr
Definition: eeparser.hxx:57
SC_DLLPUBLIC bool SetEditText(const ScAddress &rPos, std::unique_ptr< EditTextObject > pEditText)
This method manages the lifecycle of the passed edit text object.
Definition: document.cxx:3425
bool ValidCol(SCCOL nCol, SCCOL nMaxCol)
Definition: address.hxx:92
SC_DLLPUBLIC bool SetString(SCCOL nCol, SCROW nRow, SCTAB nTab, const OUString &rString, const ScSetStringParam *pParam=nullptr)
Definition: document.cxx:3394
virtual ~ScEEParser()
Definition: eeimpars.cxx:633
SC_DLLPUBLIC ScDrawLayer * GetDrawLayer()
Definition: document.hxx:1058
SC_DLLPUBLIC ScRangeData * findByUpperName(const OUString &rName)
Definition: rangenam.cxx:681
SC_DLLPUBLIC SCCOL MaxCol() const
Definition: document.hxx:871
constexpr TypedWhichId< SvxPostureItem > ATTR_FONT_POSTURE(103)
SC_DLLPUBLIC SvNumberFormatter * GetFormatTable() const
Definition: documen2.cxx:440
SC_DLLPUBLIC void SetPattern(const ScAddress &, const ScPatternAttr &rAttr)
Definition: document.cxx:5075
sal_Int32 nEndPara
sal_uInt16 ClearItem(sal_uInt16 nWhich=0)
SC_DLLPUBLIC void InitDrawLayer(SfxObjectShell *pDocShell=nullptr)
Definition: documen9.cxx:98
SvtScriptType
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
const char nVertical
Definition: eeparser.hxx:35
int i
void Set(SCCOL nCol, SCROW nRow, SCTAB nTab)
Definition: address.hxx:405
#define LANGUAGE_SYSTEM
std::vector< std::shared_ptr< ScEEParseEntry > > maList
Definition: eeparser.hxx:105
sal_Int16 SCCOL
Definition: types.hxx:21
bool ValidCol(SCCOL nCol) const
Definition: document.hxx:874
constexpr TypedWhichId< SvxVerJustifyItem > ATTR_VER_JUSTIFY(132)
static SC_DLLPUBLIC double nScreenPPTY
Vertical pixel per twips factor.
Definition: global.hxx:578
Set Text number format only when the input string is considered a special number but we only want to ...
Definition: stringutil.hxx:51
Size GetSize() const
void ScLimitSizeOnDrawPage(Size &rSize, Point &rPos, const Size &rPage)
Definition: fuins1.cxx:58
Point aSpace
Definition: eeparser.hxx:41
sal_uInt16 Count() const
const ScStyleSheet * GetStyleSheet() const
Definition: patattr.hxx:126
const SdrPage * GetPage(sal_uInt16 nPgNum) const
std::unique_ptr< ScEEParser > mpParser
Definition: eeimport.hxx:43
RowHeightMap maRowHeights
Definition: eeimport.hxx:44
OUString uppercase(const OUString &rStr, sal_Int32 nPos, sal_Int32 nCount) const
constexpr sal_uInt16 EE_CHAR_START(EE_PARA_END+1)
static double GetTableDataOptionsValNum(sal_uInt32 &nNumForm, LanguageType &eNumLang, const OUString &aValStr, const OUString &aNumStr, SvNumberFormatter &rFormatter)
bool IsNumberFormat(const OUString &sString, sal_uInt32 &F_Index, double &fOutNumber, SvNumInputOptions eInputOptions=SvNumInputOptions::NONE)
void GetInputLineString(const double &fOutNumber, sal_uInt32 nFIndex, OUString &rOutString, bool bFiltering=false)
SC_DLLPUBLIC void SetRowHeight(SCROW nRow, SCTAB nTab, sal_uInt16 nNewHeight)
Definition: document.cxx:4126
constexpr TypedWhichId< SfxUInt32Item > ATTR_VALUE_FORMAT(146)
SvNumFormatType
virtual void SetLogicRect(const tools::Rectangle &rRect)
rtl::Reference< SfxItemPool > pPool
Definition: eeparser.hxx:103
constexpr sal_uInt16 EE_CHAR_END(EE_CHAR_START+32)
std::unique_ptr< SfxPoolItem > CloneSetWhich(sal_uInt16 nNewWhich) const
std::optional< OUString > pNumStr
Definition: eeparser.hxx:59
void SetGraphicLink(const OUString &rFileName)
SCCOL Col() const
Definition: address.hxx:266
sal_Int32 GetParagraphCount() const
SCCOL nColOverlap
Definition: eeparser.hxx:68
SAL_WARN_UNUSED_RESULT Point PixelToLogic(const Point &rDevicePt) const
constexpr TypedWhichId< SvxBrushItem > ATTR_BACKGROUND(148)
std::shared_ptr< ScEEParseEntry > mxActEntry
Definition: eeparser.hxx:106
SC_DLLPUBLIC bool SetOptimalHeight(sc::RowHeightContext &rCxt, SCROW nStartRow, SCROW nEndRow, SCTAB nTab, bool bApi)
Definition: document.cxx:4297
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
sal_Int32 SCROW
Definition: types.hxx:17
void InsertGraphic(SCCOL nCol, SCROW nRow, SCTAB nTab, ScEEParseEntry *)
Definition: eeimpars.cxx:546
bool ValidRow(SCROW nRow) const
Definition: document.hxx:875
OUString ScResId(std::string_view aId)
Definition: scdll.cxx:89
bool HasRange() const
bool mbDetectNumberFormat
When true, we try to detect special number format (dates etc) from the input string, when false, we only try to detect a basic decimal number format.
Definition: stringutil.hxx:77
SfxItemState
void ChangeIntl(LanguageType eLnge)
const SfxPoolItem & Get(sal_uInt16 nWhich, bool bSrchInParent=true) const
constexpr tools::Long Height() const
constexpr TypedWhichId< SvxEscapementItem > EE_CHAR_ESCAPEMENT(EE_CHAR_START+10)
if(aStr!=aBuf) UpdateName_Impl(m_xFollowLb.get()
tools::Long AdjustWidth(tools::Long n)
constexpr TypedWhichId< SvxWeightItem > ATTR_FONT_WEIGHT(102)
constexpr TypedWhichId< SvxHorJustifyItem > ATTR_HOR_JUSTIFY(129)
static SC_DLLPUBLIC const CharClass * getCharClassPtr()
Definition: global.cxx:1010
QPRO_FUNC_TYPE nType
Definition: qproform.cxx:400
static SC_DLLPUBLIC double nScreenPPTX
Horizontal pixel per twips factor.
Definition: global.hxx:576
virtual void WriteToDocument(bool bSizeColsRows=false, double nOutputFactor=1.0, SvNumberFormatter *pFormatter=nullptr, bool bConvertDate=true) override
Definition: eeimpars.cxx:113
Set Text number format if the input string can be parsed as a number or formula text.
Definition: stringutil.hxx:45
tools::Long AdjustHeight(tools::Long n)
ScRange maRange
Definition: eeimport.hxx:38
SC_DLLPUBLIC SfxItemPool * GetEditPool() const
Definition: documen2.cxx:446
OUString aURL
Definition: eeparser.hxx:39
SfxObjectShell * GetDocumentShell() const
Definition: document.hxx:1057
Size aSize
Definition: eeparser.hxx:40
virtual ~ScEEImport() override
Definition: eeimpars.cxx:70
constexpr sal_uInt16 EE_FEATURE_FIELD(EE_FEATURE_NOTCONV+1)
static SC_DLLPUBLIC::tools::Long nLastRowHeightExtra
Definition: global.hxx:585
std::optional< OUString > pName
Definition: eeparser.hxx:61
constexpr TypedWhichId< SvxColorItem > ATTR_FONT_COLOR(109)
constexpr TypedWhichId< SvxFontHeightItem > ATTR_FONT_HEIGHT(101)
OUString aAltText
Definition: eeparser.hxx:62
aStr
SC_DLLPUBLIC bool insert(ScRangeData *p, bool bReuseFreeIndex=true)
Insert object into set.
Definition: rangenam.cxx:814
virtual ErrCode Read(SvStream &rStream, const OUString &rBaseURL) override
Definition: eeimpars.cxx:76
SC_DLLPUBLIC sal_uLong GetColOffset(SCCOL nCol, SCTAB nTab, bool bHiddenAsZero=true) const
Definition: document.cxx:4255
B2DRange maRange
sal_Int16 SCTAB
Definition: types.hxx:22
rtl::Reference< SfxItemPool > pDocPool
Definition: eeparser.hxx:104
SC_DLLPUBLIC sal_uLong GetRowOffset(SCROW nRow, SCTAB nTab, bool bHiddenAsZero=true) const
Definition: document.cxx:4263