fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / filter / rtf / eeimpars.cxx
blobc72336d30938e37f0fd530918266c5bc3a0d9ddd
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "scitems.hxx"
21 #include <editeng/eeitem.hxx>
23 #include <editeng/adjustitem.hxx>
24 #include <editeng/editobj.hxx>
25 #include <editeng/editview.hxx>
26 #include <editeng/escapementitem.hxx>
27 #include <editeng/langitem.hxx>
28 #include <svx/svdograf.hxx>
29 #include <svx/svdpage.hxx>
30 #include <editeng/scripttypeitem.hxx>
31 #include <svtools/htmlcfg.hxx>
32 #include <sfx2/sfxhtml.hxx>
33 #include <svtools/parhtml.hxx>
34 #include <svl/zforlist.hxx>
35 #include <vcl/virdev.hxx>
36 #include <vcl/svapp.hxx>
37 #include <unotools/syslocale.hxx>
38 #include <unotools/charclass.hxx>
39 #include <comphelper/string.hxx>
41 #include "eeimport.hxx"
42 #include "global.hxx"
43 #include "document.hxx"
44 #include "editutil.hxx"
45 #include "stlsheet.hxx"
46 #include "docpool.hxx"
47 #include "attrib.hxx"
48 #include "patattr.hxx"
49 #include "eeparser.hxx"
50 #include "drwlayer.hxx"
51 #include "rangenam.hxx"
52 #include "progress.hxx"
53 #include "stringutil.hxx"
54 #include <rowheightcontext.hxx>
55 #include "fuinsert.hxx"
57 #include "globstr.hrc"
59 #include <boost/scoped_ptr.hpp>
61 ScEEImport::ScEEImport( ScDocument* pDocP, const ScRange& rRange ) :
62 maRange( rRange ),
63 mpDoc( pDocP ),
64 mpParser( NULL )
66 const ScPatternAttr* pPattern = mpDoc->GetPattern(
67 maRange.aStart.Col(), maRange.aStart.Row(), maRange.aStart.Tab() );
68 mpEngine = new ScTabEditEngine(*pPattern, mpDoc->GetEditPool(), mpDoc->GetEditPool());
69 mpEngine->SetUpdateMode( false );
70 mpEngine->EnableUndo( false );
73 ScEEImport::~ScEEImport()
75 // Sequence important, or else we crash in some dtor!
76 // Is guaranteed as ScEEImport is base class
77 delete mpEngine; // After Parser!
80 sal_uLong ScEEImport::Read( SvStream& rStream, const OUString& rBaseURL )
82 sal_uLong nErr = mpParser->Read( rStream, rBaseURL );
84 SCCOL nEndCol;
85 SCROW nEndRow;
86 mpParser->GetDimensions( nEndCol, nEndRow );
87 if ( nEndCol != 0 )
89 nEndCol += maRange.aStart.Col() - 1;
90 if ( nEndCol > MAXCOL )
91 nEndCol = MAXCOL;
93 else
94 nEndCol = maRange.aStart.Col();
95 if ( nEndRow != 0 )
97 nEndRow += maRange.aStart.Row() - 1;
98 if ( nEndRow > MAXROW )
99 nEndRow = MAXROW;
101 else
102 nEndRow = maRange.aStart.Row();
103 maRange.aEnd.Set( nEndCol, nEndRow, maRange.aStart.Tab() );
105 return nErr;
108 void ScEEImport::WriteToDocument( bool bSizeColsRows, double nOutputFactor, SvNumberFormatter* pFormatter, bool bConvertDate )
110 ScProgress* pProgress = new ScProgress( mpDoc->GetDocumentShell(),
111 ScGlobal::GetRscString( STR_LOAD_DOC ), mpParser->ListSize() );
112 sal_uLong nProgress = 0;
114 SCCOL nStartCol, nEndCol;
115 SCROW nStartRow, nEndRow;
116 SCTAB nTab;
117 SCROW nOverlapRowMax, nLastMergedRow;
118 SCCOL nMergeColAdd;
119 nStartCol = maRange.aStart.Col();
120 nStartRow = maRange.aStart.Row();
121 nTab = maRange.aStart.Tab();
122 nEndCol = maRange.aEnd.Col();
123 nEndRow = maRange.aEnd.Row();
124 nOverlapRowMax = 0;
125 nMergeColAdd = 0;
126 nLastMergedRow = SCROW_MAX;
127 bool bHasGraphics = false;
128 ScEEParseEntry* pE;
129 if (!pFormatter)
130 pFormatter = mpDoc->GetFormatTable();
131 bool bNumbersEnglishUS = false;
132 if (pFormatter->GetLanguage() == LANGUAGE_SYSTEM)
134 // Automatic language option selected. Check for the global 'use US English' option.
135 SvxHtmlOptions aOpt;
136 bNumbersEnglishUS = aOpt.IsNumbersEnglishUS();
138 ScDocumentPool* pDocPool = mpDoc->GetPool();
139 ScRangeName* pRangeNames = mpDoc->GetRangeName();
140 for ( size_t i = 0, n = mpParser->ListSize(); i < n; ++i )
142 pE = mpParser->ListEntry( i );
143 SCROW nRow = nStartRow + pE->nRow;
144 if ( nRow != nLastMergedRow )
145 nMergeColAdd = 0;
146 SCCOL nCol = nStartCol + pE->nCol + nMergeColAdd;
147 // Determine RowMerge
148 // Pure ColMerge and ColMerge of the first MergeRow already done during parsing
149 if ( nRow <= nOverlapRowMax )
151 while ( nCol <= MAXCOL && mpDoc->HasAttrib( nCol, nRow, nTab,
152 nCol, nRow, nTab, HASATTR_OVERLAPPED ) )
154 nCol++;
155 nMergeColAdd++;
157 nLastMergedRow = nRow;
159 // Add for second run
160 pE->nCol = nCol;
161 pE->nRow = nRow;
162 if ( ValidCol(nCol) && ValidRow(nRow) )
164 SfxItemSet aSet = mpEngine->GetAttribs( pE->aSel );
165 // Remove default: we set left/right ourselves depending on Text or
166 // Number
167 // EditView.GetAttribs always returns complete Set filled with
168 // defaults
169 const SfxPoolItem& rItem = aSet.Get( EE_PARA_JUST );
170 if ( static_cast<const SvxAdjustItem&>(rItem).GetAdjust() == SVX_ADJUST_LEFT )
171 aSet.ClearItem( EE_PARA_JUST );
173 // Test whether simple String without mixed attributes
174 bool bSimple = ( pE->aSel.nStartPara == pE->aSel.nEndPara );
175 for (sal_uInt16 nId = EE_CHAR_START; nId <= EE_CHAR_END && bSimple; nId++)
177 const SfxPoolItem* pItem = 0;
178 SfxItemState eState = aSet.GetItemState( nId, true, &pItem );
179 if (eState == SfxItemState::DONTCARE)
180 bSimple = false;
181 else if (eState == SfxItemState::SET)
183 if ( nId == EE_CHAR_ESCAPEMENT ) // Super-/Subscript always via EE
185 if ( (SvxEscapement)static_cast<const SvxEscapementItem*>(pItem)->GetEnumValue()
186 != SVX_ESCAPEMENT_OFF )
187 bSimple = false;
191 if ( bSimple )
192 { // Contains field commands?
193 SfxItemState eFieldState = aSet.GetItemState( EE_FEATURE_FIELD, false );
194 if ( eFieldState == SfxItemState::DONTCARE || eFieldState == SfxItemState::SET )
195 bSimple = false;
198 // HTML
199 OUString aValStr, aNumStr;
200 double fVal;
201 sal_uInt32 nNumForm = 0;
202 LanguageType eNumLang = LANGUAGE_NONE;
203 if ( pE->pNumStr )
204 { // SDNUM needs to be if SDVAL
205 aNumStr = *pE->pNumStr;
206 if ( pE->pValStr )
207 aValStr = *pE->pValStr;
208 fVal = SfxHTMLParser::GetTableDataOptionsValNum(
209 nNumForm, eNumLang, aValStr, aNumStr, *pFormatter );
212 // Set attributes
213 ScPatternAttr aAttr( pDocPool );
214 aAttr.GetFromEditItemSet( &aSet );
215 SfxItemSet& rSet = aAttr.GetItemSet();
216 if (!aNumStr.isEmpty())
218 rSet.Put( SfxUInt32Item( ATTR_VALUE_FORMAT, nNumForm ) );
219 rSet.Put( SvxLanguageItem( eNumLang, ATTR_LANGUAGE_FORMAT ) );
221 const SfxItemSet& rESet = pE->aItemSet;
222 if ( rESet.Count() )
224 const SfxPoolItem* pItem;
225 if ( rESet.GetItemState( ATTR_BACKGROUND, false, &pItem) == SfxItemState::SET )
226 rSet.Put( *pItem );
227 if ( rESet.GetItemState( ATTR_BORDER, false, &pItem) == SfxItemState::SET )
228 rSet.Put( *pItem );
229 if ( rESet.GetItemState( ATTR_SHADOW, false, &pItem) == SfxItemState::SET )
230 rSet.Put( *pItem );
231 // HTML
232 if ( rESet.GetItemState( ATTR_HOR_JUSTIFY, false, &pItem) == SfxItemState::SET )
233 rSet.Put( *pItem );
234 if ( rESet.GetItemState( ATTR_VER_JUSTIFY, false, &pItem) == SfxItemState::SET )
235 rSet.Put( *pItem );
236 if ( rESet.GetItemState( ATTR_LINEBREAK, false, &pItem) == SfxItemState::SET )
237 rSet.Put( *pItem );
238 if ( rESet.GetItemState( ATTR_FONT_COLOR, false, &pItem) == SfxItemState::SET )
239 rSet.Put( *pItem );
240 if ( rESet.GetItemState( ATTR_FONT_UNDERLINE, false, &pItem) == SfxItemState::SET )
241 rSet.Put( *pItem );
242 // HTML LATIN/CJK/CTL script type dependent
243 const SfxPoolItem* pFont;
244 if ( rESet.GetItemState( ATTR_FONT, false, &pFont) != SfxItemState::SET )
245 pFont = 0;
246 const SfxPoolItem* pHeight;
247 if ( rESet.GetItemState( ATTR_FONT_HEIGHT, false, &pHeight) != SfxItemState::SET )
248 pHeight = 0;
249 const SfxPoolItem* pWeight;
250 if ( rESet.GetItemState( ATTR_FONT_WEIGHT, false, &pWeight) != SfxItemState::SET )
251 pWeight = 0;
252 const SfxPoolItem* pPosture;
253 if ( rESet.GetItemState( ATTR_FONT_POSTURE, false, &pPosture) != SfxItemState::SET )
254 pPosture = 0;
255 // Number format
256 const SfxPoolItem* pNumFmt = NULL;
257 if ( rESet.GetItemState(ATTR_VALUE_FORMAT, false, &pNumFmt) == SfxItemState::SET )
258 rSet.Put(*pNumFmt);
259 if ( pFont || pHeight || pWeight || pPosture )
261 OUString aStr( mpEngine->GetText( pE->aSel ) );
262 SvtScriptType nScriptType = mpDoc->GetStringScriptType( aStr );
263 const SvtScriptType nScripts[3] = { SvtScriptType::LATIN,
264 SvtScriptType::ASIAN, SvtScriptType::COMPLEX };
265 for ( sal_uInt8 j=0; j<3; ++j )
267 if ( nScriptType & nScripts[j] )
269 if ( pFont )
270 rSet.Put( *pFont, ScGlobal::GetScriptedWhichID(
271 nScripts[j], ATTR_FONT ));
272 if ( pHeight )
273 rSet.Put( *pHeight, ScGlobal::GetScriptedWhichID(
274 nScripts[j], ATTR_FONT_HEIGHT ));
275 if ( pWeight )
276 rSet.Put( *pWeight, ScGlobal::GetScriptedWhichID(
277 nScripts[j], ATTR_FONT_WEIGHT ));
278 if ( pPosture )
279 rSet.Put( *pPosture, ScGlobal::GetScriptedWhichID(
280 nScripts[j], ATTR_FONT_POSTURE ));
285 if ( pE->nColOverlap > 1 || pE->nRowOverlap > 1 )
286 { // Merged cells, with SfxItemSet.Put() is faster than
287 // with ScDocument.DoMerge() afterwards
288 ScMergeAttr aMerge( pE->nColOverlap, pE->nRowOverlap );
289 rSet.Put( aMerge );
290 SCROW nRO = 0;
291 if ( pE->nColOverlap > 1 )
292 mpDoc->ApplyFlagsTab( nCol+1, nRow,
293 nCol + pE->nColOverlap - 1, nRow, nTab,
294 SC_MF_HOR );
295 if ( pE->nRowOverlap > 1 )
297 nRO = nRow + pE->nRowOverlap - 1;
298 mpDoc->ApplyFlagsTab( nCol, nRow+1,
299 nCol, nRO , nTab,
300 SC_MF_VER );
301 if ( nRO > nOverlapRowMax )
302 nOverlapRowMax = nRO;
304 if ( pE->nColOverlap > 1 && pE->nRowOverlap > 1 )
305 mpDoc->ApplyFlagsTab( nCol+1, nRow+1,
306 nCol + pE->nColOverlap - 1, nRO, nTab,
307 SC_MF_HOR | SC_MF_VER );
309 const ScStyleSheet* pStyleSheet =
310 mpDoc->GetPattern( nCol, nRow, nTab )->GetStyleSheet();
311 aAttr.SetStyleSheet( const_cast<ScStyleSheet*>(pStyleSheet) );
312 mpDoc->SetPattern( nCol, nRow, nTab, aAttr, true );
314 // Add data
315 if (bSimple)
317 ScSetStringParam aParam;
318 aParam.mpNumFormatter = pFormatter;
319 aParam.mbDetectNumberFormat = true;
320 aParam.meSetTextNumFormat = ScSetStringParam::SpecialNumberOnly;
321 aParam.mbHandleApostrophe = false;
323 if (!aValStr.isEmpty())
324 mpDoc->SetValue( nCol, nRow, nTab, fVal );
325 else if ( !pE->aSel.HasRange() )
327 // maybe ALT text of IMG or similar
328 mpDoc->SetString( nCol, nRow, nTab, pE->aAltText, &aParam );
329 // If SelRange is completely empty, the succeeding text can be in the same paragraph!
331 else
333 OUString aStr;
334 if( pE->bEntirePara )
336 aStr = mpEngine->GetText( pE->aSel.nStartPara );
338 else
340 aStr = comphelper::string::strip(mpEngine->GetText(pE->aSel), ' ');
343 bool bTextFormat = false;
345 const SfxPoolItem* pNumFmt = NULL;
346 if (rSet.GetItemState(ATTR_VALUE_FORMAT, false, &pNumFmt) == SfxItemState::SET)
348 sal_uInt32 nNumFmt = static_cast<const SfxUInt32Item*>(pNumFmt)->GetValue();
349 sal_uInt16 nType = pFormatter->GetType(nNumFmt);
350 if (nType == css::util::NumberFormat::TEXT)
351 // Format is set to Text.
352 bTextFormat = true;
355 // TODO: RTF import should follow the language tag,
356 // currently this follows the HTML options for both, HTML
357 // and RTF.
358 if (bNumbersEnglishUS)
360 pFormatter->ChangeIntl( LANGUAGE_ENGLISH_US);
361 sal_uInt32 nIndex = pFormatter->GetStandardIndex( LANGUAGE_ENGLISH_US);
362 double fEnVal = 0.0;
363 if (pFormatter->IsNumberFormat( aStr, nIndex, fEnVal))
365 sal_uInt32 nNewIndex =
366 pFormatter->GetFormatForLanguageIfBuiltIn(
367 nIndex, LANGUAGE_SYSTEM);
368 OSL_ENSURE( nNewIndex != nIndex, "ScEEImport::WriteToDocument: NumbersEnglishUS not a built-in format?");
369 pFormatter->GetInputLineString( fEnVal, nNewIndex, aStr);
371 else
372 bTextFormat = true;
373 pFormatter->ChangeIntl( LANGUAGE_SYSTEM);
376 // #105460#, #i4180# String cells can't contain tabs or linebreaks
377 // -> replace with spaces
378 aStr = aStr.replaceAll( "\t", " " );
379 aStr = aStr.replaceAll( "\n", " " );
381 if (bTextFormat)
383 aParam.mbDetectNumberFormat = false;
384 aParam.meSetTextNumFormat = ScSetStringParam::Always;
386 else
387 aParam.mbDetectNumberFormat = bConvertDate;
389 mpDoc->SetString(nCol, nRow, nTab, aStr, &aParam);
392 else
394 // The cell will own the text object instance.
395 mpDoc->SetEditText(ScAddress(nCol,nRow,nTab), mpEngine->CreateTextObject(pE->aSel));
397 if ( pE->maImageList.size() )
398 bHasGraphics |= GraphicSize( nCol, nRow, nTab, pE );
399 if ( pE->pName )
400 { // Anchor Name => RangeName
401 if (!pRangeNames->findByUpperName(ScGlobal::pCharClass->uppercase(*pE->pName)))
403 ScRangeData* pData = new ScRangeData( mpDoc, *pE->pName,
404 ScAddress( nCol, nRow, nTab ) );
405 pRangeNames->insert( pData );
409 pProgress->SetStateOnPercent( ++nProgress );
411 if ( bSizeColsRows )
413 // Column widths
414 ColWidthsMap& rColWidths = mpParser->GetColWidths();
415 if ( !rColWidths.empty() )
417 nProgress = 0;
418 pProgress->SetState( nProgress, nEndCol - nStartCol + 1 );
419 for ( SCCOL nCol = nStartCol; nCol <= nEndCol; nCol++ )
421 sal_uInt16 nWidth = 0;
422 ColWidthsMap::const_iterator it = rColWidths.find( nCol );
423 if ( it != rColWidths.end() )
424 nWidth = it->second;
425 if ( nWidth )
426 mpDoc->SetColWidth( nCol, nTab, nWidth );
427 pProgress->SetState( ++nProgress );
430 DELETEZ( pProgress ); // SetOptimalHeight has its own ProgressBar
431 // Adjust line height, base is 100% zoom
432 Fraction aZoom( 1, 1 );
433 // Factor is printer to display ratio
434 double nPPTX = ScGlobal::nScreenPPTX * (double) aZoom / nOutputFactor;
435 double nPPTY = ScGlobal::nScreenPPTY * (double) aZoom;
436 ScopedVclPtrInstance< VirtualDevice > pVirtDev;
437 sc::RowHeightContext aCxt(nPPTX, nPPTY, aZoom, aZoom, pVirtDev);
438 aCxt.setExtraHeight(ScGlobal::nLastRowHeightExtra);
439 mpDoc->SetOptimalHeight(aCxt, 0, nEndRow, 0);
441 if ( !maRowHeights.empty() )
443 for ( SCROW nRow = nStartRow; nRow <= nEndRow; nRow++ )
445 RowHeightMap::const_iterator it = maRowHeights.find( nRow );
446 sal_uInt16 nHeight = it == maRowHeights.end() ? 0 : it->second;
447 if ( nHeight > mpDoc->GetRowHeight( nRow, nTab ) )
448 mpDoc->SetRowHeight( nRow, nTab, nHeight );
452 if ( bHasGraphics )
454 // Insert graphics
455 for ( size_t i = 0, nListSize = mpParser->ListSize(); i < nListSize; ++i )
457 pE = mpParser->ListEntry( i );
458 if ( !pE->maImageList.empty() )
460 SCCOL nCol = pE->nCol;
461 SCROW nRow = pE->nRow;
462 if ( ValidCol(nCol) && ValidRow(nRow) )
463 InsertGraphic( nCol, nRow, nTab, pE );
467 if ( pProgress )
468 delete pProgress;
471 bool ScEEImport::GraphicSize( SCCOL nCol, SCROW nRow, SCTAB /*nTab*/, ScEEParseEntry* pE )
473 if ( !pE->maImageList.size() )
474 return false;
475 bool bHasGraphics = false;
476 OutputDevice* pDefaultDev = Application::GetDefaultDevice();
477 long nWidth, nHeight;
478 nWidth = nHeight = 0;
479 sal_Char nDir = nHorizontal;
480 for ( sal_uInt32 i = 0; i < pE->maImageList.size() ; ++i )
482 ScHTMLImage* pI = &pE->maImageList[ i ];
483 if ( pI->pGraphic )
484 bHasGraphics = true;
485 Size aSizePix = pI->aSize;
486 aSizePix.Width() += 2 * pI->aSpace.X();
487 aSizePix.Height() += 2 * pI->aSpace.Y();
488 Size aLogicSize = pDefaultDev->PixelToLogic( aSizePix, MapMode( MAP_TWIP ) );
489 if ( nDir & nHorizontal )
490 nWidth += aLogicSize.Width();
491 else if ( nWidth < aLogicSize.Width() )
492 nWidth = aLogicSize.Width();
493 if ( nDir & nVertical )
494 nHeight += aLogicSize.Height();
495 else if ( nHeight < aLogicSize.Height() )
496 nHeight = aLogicSize.Height();
497 nDir = pI->nDir;
499 // Column widths
500 ColWidthsMap& rColWidths = mpParser->GetColWidths();
501 long nThisWidth = 0;
502 ColWidthsMap::const_iterator it = rColWidths.find( nCol );
503 if ( it != rColWidths.end() )
504 nThisWidth = it->second;
505 long nColWidths = nThisWidth;
506 SCCOL nColSpanCol = nCol + pE->nColOverlap;
507 for ( SCCOL nC = nCol + 1; nC < nColSpanCol; nC++ )
509 ColWidthsMap::const_iterator it2 = rColWidths.find( nC );
510 if ( it2 != rColWidths.end() )
511 nColWidths += it2->second;
513 if ( nWidth > nColWidths )
514 { // Only insert difference in first column
515 rColWidths[ nCol ] = nWidth - nColWidths + nThisWidth;
517 // Distribute line height difference between all affected lines
518 SCROW nRowSpan = pE->nRowOverlap;
519 nHeight /= nRowSpan;
520 if ( nHeight == 0 )
521 nHeight = 1; // For definite comparison
522 for ( SCROW nR = nRow; nR < nRow + nRowSpan; nR++ )
524 RowHeightMap::const_iterator it2 = maRowHeights.find( nR );
525 long nRowHeight = it2 == maRowHeights.end() ? 0 : it2->second;
526 if ( nHeight > nRowHeight )
528 maRowHeights[ nR ] = nHeight;
531 return bHasGraphics;
534 void ScEEImport::InsertGraphic( SCCOL nCol, SCROW nRow, SCTAB nTab,
535 ScEEParseEntry* pE )
537 if ( !pE->maImageList.size() )
538 return ;
539 ScDrawLayer* pModel = mpDoc->GetDrawLayer();
540 if (!pModel)
542 mpDoc->InitDrawLayer();
543 pModel = mpDoc->GetDrawLayer();
545 SdrPage* pPage = pModel->GetPage( static_cast<sal_uInt16>(nTab) );
546 OutputDevice* pDefaultDev = Application::GetDefaultDevice();
548 Point aCellInsertPos(
549 (long)((double) mpDoc->GetColOffset( nCol, nTab ) * HMM_PER_TWIPS),
550 (long)((double) mpDoc->GetRowOffset( nRow, nTab ) * HMM_PER_TWIPS) );
552 Point aInsertPos( aCellInsertPos );
553 Point aSpace;
554 Size aLogicSize;
555 sal_Char nDir = nHorizontal;
556 for ( sal_uInt32 i = 0; i < pE->maImageList.size(); ++i )
558 ScHTMLImage* pI = &pE->maImageList[ i ];
559 if ( nDir & nHorizontal )
560 { // Horizontal
561 aInsertPos.X() += aLogicSize.Width();
562 aInsertPos.X() += aSpace.X();
563 aInsertPos.Y() = aCellInsertPos.Y();
565 else
566 { // Vertical
567 aInsertPos.X() = aCellInsertPos.X();
568 aInsertPos.Y() += aLogicSize.Height();
569 aInsertPos.Y() += aSpace.Y();
571 // Add offset of Spacing
572 aSpace = pDefaultDev->PixelToLogic( pI->aSpace, MapMode( MAP_100TH_MM ) );
573 aInsertPos += aSpace;
575 Size aSizePix = pI->aSize;
576 aLogicSize = pDefaultDev->PixelToLogic( aSizePix, MapMode( MAP_100TH_MM ) );
578 // Limit size
579 ::ScLimitSizeOnDrawPage( aLogicSize, aInsertPos, pPage->GetSize() );
581 if ( pI->pGraphic )
583 Rectangle aRect ( aInsertPos, aLogicSize );
584 SdrGrafObj* pObj = new SdrGrafObj( *pI->pGraphic, aRect );
585 // calling SetGraphicLink here doesn't work
586 pObj->SetName( pI->aURL );
588 pPage->InsertObject( pObj );
590 // SetGraphicLink has to be used after inserting the object,
591 // otherwise an empty graphic is swapped in and the contact stuff crashes.
592 // See #i37444#.
593 pObj->SetGraphicLink( pI->aURL, ""/*TODO?*/, pI->aFilterName );
595 pObj->SetLogicRect( aRect ); // Only after InsertObject!
597 nDir = pI->nDir;
601 ScEEParser::ScEEParser( EditEngine* pEditP ) :
602 pEdit( pEditP ),
603 pPool( EditEngine::CreatePool() ),
604 pDocPool( new ScDocumentPool ),
605 nLastToken(0),
606 nColCnt(0),
607 nRowCnt(0),
608 nColMax(0),
609 nRowMax(0)
611 // pPool is foisted on SvxRTFParser at RTFIMP_START later on
612 pPool->SetSecondaryPool( pDocPool );
613 pPool->FreezeIdRanges();
614 NewActEntry( NULL );
617 ScEEParser::~ScEEParser()
619 delete pActEntry;
620 if ( !maList.empty() ) maList.clear();
622 // Don't delete Pool until the lists have been deleted
623 pPool->SetSecondaryPool( NULL );
624 SfxItemPool::Free(pDocPool);
625 SfxItemPool::Free(pPool);
628 void ScEEParser::NewActEntry( ScEEParseEntry* pE )
629 { // New free-flying pActEntry
630 pActEntry = new ScEEParseEntry( pPool );
631 pActEntry->aSel.nStartPara = (pE ? pE->aSel.nEndPara + 1 : 0);
632 pActEntry->aSel.nStartPos = 0;
635 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */