1*b3f79822SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*b3f79822SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*b3f79822SAndrew Rist * or more contributor license agreements. See the NOTICE file
5*b3f79822SAndrew Rist * distributed with this work for additional information
6*b3f79822SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*b3f79822SAndrew Rist * to you under the Apache License, Version 2.0 (the
8*b3f79822SAndrew Rist * "License"); you may not use this file except in compliance
9*b3f79822SAndrew Rist * with the License. You may obtain a copy of the License at
10*b3f79822SAndrew Rist *
11*b3f79822SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*b3f79822SAndrew Rist *
13*b3f79822SAndrew Rist * Unless required by applicable law or agreed to in writing,
14*b3f79822SAndrew Rist * software distributed under the License is distributed on an
15*b3f79822SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*b3f79822SAndrew Rist * KIND, either express or implied. See the License for the
17*b3f79822SAndrew Rist * specific language governing permissions and limitations
18*b3f79822SAndrew Rist * under the License.
19*b3f79822SAndrew Rist *
20*b3f79822SAndrew Rist *************************************************************/
21*b3f79822SAndrew Rist
22*b3f79822SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sc.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir
28cdf0e10cSrcweir
29cdf0e10cSrcweir //------------------------------------------------------------------------
30cdf0e10cSrcweir
31cdf0e10cSrcweir #include "scitems.hxx"
32cdf0e10cSrcweir #include <editeng/eeitem.hxx>
33cdf0e10cSrcweir
34cdf0e10cSrcweir
35cdf0e10cSrcweir #include <editeng/adjitem.hxx>
36cdf0e10cSrcweir #include <editeng/editobj.hxx>
37cdf0e10cSrcweir #include <editeng/editview.hxx>
38cdf0e10cSrcweir #include <editeng/escpitem.hxx>
39cdf0e10cSrcweir #include <editeng/langitem.hxx>
40cdf0e10cSrcweir #include <svx/svdograf.hxx>
41cdf0e10cSrcweir #include <svx/svdpage.hxx>
42cdf0e10cSrcweir #include <editeng/scripttypeitem.hxx>
43cdf0e10cSrcweir #include <svtools/htmlcfg.hxx>
44cdf0e10cSrcweir #include <sfx2/sfxhtml.hxx>
45cdf0e10cSrcweir #include <svtools/parhtml.hxx>
46cdf0e10cSrcweir #include <svl/zforlist.hxx>
47cdf0e10cSrcweir #include <vcl/virdev.hxx>
48cdf0e10cSrcweir #include <vcl/svapp.hxx>
49cdf0e10cSrcweir #include <unotools/syslocale.hxx>
50cdf0e10cSrcweir #include <unotools/charclass.hxx>
51cdf0e10cSrcweir
52cdf0e10cSrcweir #include "eeimport.hxx"
53cdf0e10cSrcweir #include "global.hxx"
54cdf0e10cSrcweir #include "document.hxx"
55cdf0e10cSrcweir #include "editutil.hxx"
56cdf0e10cSrcweir #include "stlsheet.hxx"
57cdf0e10cSrcweir #include "docpool.hxx"
58cdf0e10cSrcweir #include "attrib.hxx"
59cdf0e10cSrcweir #include "patattr.hxx"
60cdf0e10cSrcweir #include "cell.hxx"
61cdf0e10cSrcweir #include "eeparser.hxx"
62cdf0e10cSrcweir #include "drwlayer.hxx"
63cdf0e10cSrcweir #include "rangenam.hxx"
64cdf0e10cSrcweir #include "progress.hxx"
65cdf0e10cSrcweir
66cdf0e10cSrcweir #include "globstr.hrc"
67cdf0e10cSrcweir
68cdf0e10cSrcweir // in fuins1.cxx
69cdf0e10cSrcweir extern void ScLimitSizeOnDrawPage( Size& rSize, Point& rPos, const Size& rPage );
70cdf0e10cSrcweir
71cdf0e10cSrcweir //------------------------------------------------------------------------
72cdf0e10cSrcweir
ScEEImport(ScDocument * pDocP,const ScRange & rRange)73cdf0e10cSrcweir ScEEImport::ScEEImport( ScDocument* pDocP, const ScRange& rRange ) :
74cdf0e10cSrcweir maRange( rRange ),
75cdf0e10cSrcweir mpDoc( pDocP ),
76cdf0e10cSrcweir mpParser( NULL ),
77cdf0e10cSrcweir mpRowHeights( new Table )
78cdf0e10cSrcweir {
79cdf0e10cSrcweir const ScPatternAttr* pPattern = mpDoc->GetPattern(
80cdf0e10cSrcweir maRange.aStart.Col(), maRange.aStart.Row(), maRange.aStart.Tab() );
81cdf0e10cSrcweir mpEngine = new ScTabEditEngine( *pPattern, mpDoc->GetEditPool() );
82cdf0e10cSrcweir mpEngine->SetUpdateMode( sal_False );
83cdf0e10cSrcweir mpEngine->EnableUndo( sal_False );
84cdf0e10cSrcweir }
85cdf0e10cSrcweir
86cdf0e10cSrcweir
~ScEEImport()87cdf0e10cSrcweir ScEEImport::~ScEEImport()
88cdf0e10cSrcweir {
89cdf0e10cSrcweir // Reihenfolge wichtig, sonst knallt's irgendwann irgendwo in irgendeinem Dtor!
90cdf0e10cSrcweir // Ist gewaehrleistet, da ScEEImport Basisklasse ist
91cdf0e10cSrcweir delete mpEngine; // nach Parser!
92cdf0e10cSrcweir delete mpRowHeights;
93cdf0e10cSrcweir }
94cdf0e10cSrcweir
95cdf0e10cSrcweir
Read(SvStream & rStream,const String & rBaseURL)96cdf0e10cSrcweir sal_uLong ScEEImport::Read( SvStream& rStream, const String& rBaseURL )
97cdf0e10cSrcweir {
98cdf0e10cSrcweir sal_uLong nErr = mpParser->Read( rStream, rBaseURL );
99cdf0e10cSrcweir
100cdf0e10cSrcweir SCCOL nEndCol;
101cdf0e10cSrcweir SCROW nEndRow;
102cdf0e10cSrcweir mpParser->GetDimensions( nEndCol, nEndRow );
103cdf0e10cSrcweir if ( nEndCol != 0 )
104cdf0e10cSrcweir {
105cdf0e10cSrcweir nEndCol += maRange.aStart.Col() - 1;
106cdf0e10cSrcweir if ( nEndCol > MAXCOL )
107cdf0e10cSrcweir nEndCol = MAXCOL;
108cdf0e10cSrcweir }
109cdf0e10cSrcweir else
110cdf0e10cSrcweir nEndCol = maRange.aStart.Col();
111cdf0e10cSrcweir if ( nEndRow != 0 )
112cdf0e10cSrcweir {
113cdf0e10cSrcweir nEndRow += maRange.aStart.Row() - 1;
114cdf0e10cSrcweir if ( nEndRow > MAXROW )
115cdf0e10cSrcweir nEndRow = MAXROW;
116cdf0e10cSrcweir }
117cdf0e10cSrcweir else
118cdf0e10cSrcweir nEndRow = maRange.aStart.Row();
119cdf0e10cSrcweir maRange.aEnd.Set( nEndCol, nEndRow, maRange.aStart.Tab() );
120cdf0e10cSrcweir
121cdf0e10cSrcweir return nErr;
122cdf0e10cSrcweir }
123cdf0e10cSrcweir
124cdf0e10cSrcweir
WriteToDocument(sal_Bool bSizeColsRows,double nOutputFactor,SvNumberFormatter * pFormatter,bool bConvertDate)125cdf0e10cSrcweir void ScEEImport::WriteToDocument( sal_Bool bSizeColsRows, double nOutputFactor, SvNumberFormatter* pFormatter, bool bConvertDate )
126cdf0e10cSrcweir {
127cdf0e10cSrcweir ScProgress* pProgress = new ScProgress( mpDoc->GetDocumentShell(),
128cdf0e10cSrcweir ScGlobal::GetRscString( STR_LOAD_DOC ), mpParser->Count() );
129cdf0e10cSrcweir sal_uLong nProgress = 0;
130cdf0e10cSrcweir
131cdf0e10cSrcweir SCCOL nStartCol, nEndCol;
132cdf0e10cSrcweir SCROW nStartRow, nEndRow;
133cdf0e10cSrcweir SCTAB nTab;
134cdf0e10cSrcweir SCROW nOverlapRowMax, nLastMergedRow;
135cdf0e10cSrcweir SCCOL nMergeColAdd;
136cdf0e10cSrcweir nStartCol = maRange.aStart.Col();
137cdf0e10cSrcweir nStartRow = maRange.aStart.Row();
138cdf0e10cSrcweir nTab = maRange.aStart.Tab();
139cdf0e10cSrcweir nEndCol = maRange.aEnd.Col();
140cdf0e10cSrcweir nEndRow = maRange.aEnd.Row();
141cdf0e10cSrcweir nOverlapRowMax = 0;
142cdf0e10cSrcweir nMergeColAdd = 0;
143cdf0e10cSrcweir nLastMergedRow = SCROW_MAX;
144cdf0e10cSrcweir sal_Bool bHasGraphics = sal_False;
145cdf0e10cSrcweir ScEEParseEntry* pE;
146cdf0e10cSrcweir if (!pFormatter)
147cdf0e10cSrcweir pFormatter = mpDoc->GetFormatTable();
148cdf0e10cSrcweir bool bNumbersEnglishUS = false;
149cdf0e10cSrcweir if (pFormatter->GetLanguage() == LANGUAGE_SYSTEM)
150cdf0e10cSrcweir {
151cdf0e10cSrcweir // Automatic language option selected. Check for the global 'use US English' option.
152cdf0e10cSrcweir SvxHtmlOptions aOpt;
153cdf0e10cSrcweir bNumbersEnglishUS = aOpt.IsNumbersEnglishUS();
154cdf0e10cSrcweir }
155cdf0e10cSrcweir ScDocumentPool* pDocPool = mpDoc->GetPool();
156cdf0e10cSrcweir ScRangeName* pRangeNames = mpDoc->GetRangeName();
157cdf0e10cSrcweir for ( pE = mpParser->First(); pE; pE = mpParser->Next() )
158cdf0e10cSrcweir {
159cdf0e10cSrcweir SCROW nRow = nStartRow + pE->nRow;
160cdf0e10cSrcweir if ( nRow != nLastMergedRow )
161cdf0e10cSrcweir nMergeColAdd = 0;
162cdf0e10cSrcweir SCCOL nCol = nStartCol + pE->nCol + nMergeColAdd;
163cdf0e10cSrcweir // RowMerge feststellen, pures ColMerge und ColMerge der ersten
164cdf0e10cSrcweir // MergeRow bereits beim parsen
165cdf0e10cSrcweir if ( nRow <= nOverlapRowMax )
166cdf0e10cSrcweir {
167cdf0e10cSrcweir while ( nCol <= MAXCOL && mpDoc->HasAttrib( nCol, nRow, nTab,
168cdf0e10cSrcweir nCol, nRow, nTab, HASATTR_OVERLAPPED ) )
169cdf0e10cSrcweir {
170cdf0e10cSrcweir nCol++;
171cdf0e10cSrcweir nMergeColAdd++;
172cdf0e10cSrcweir }
173cdf0e10cSrcweir nLastMergedRow = nRow;
174cdf0e10cSrcweir }
175cdf0e10cSrcweir // fuer zweiten Durchlauf eintragen
176cdf0e10cSrcweir pE->nCol = nCol;
177cdf0e10cSrcweir pE->nRow = nRow;
178cdf0e10cSrcweir if ( ValidCol(nCol) && ValidRow(nRow) )
179cdf0e10cSrcweir {
180cdf0e10cSrcweir SfxItemSet aSet = mpEngine->GetAttribs( pE->aSel );
181cdf0e10cSrcweir // Default raus, wir setzen selber links/rechts je nachdem ob Text
182cdf0e10cSrcweir // oder Zahl; EditView.GetAttribs liefert immer kompletten Set
183cdf0e10cSrcweir // mit Defaults aufgefuellt
184cdf0e10cSrcweir const SfxPoolItem& rItem = aSet.Get( EE_PARA_JUST );
185cdf0e10cSrcweir if ( ((const SvxAdjustItem&)rItem).GetAdjust() == SVX_ADJUST_LEFT )
186cdf0e10cSrcweir aSet.ClearItem( EE_PARA_JUST );
187cdf0e10cSrcweir
188cdf0e10cSrcweir // Testen, ob einfacher String ohne gemischte Attribute
189cdf0e10cSrcweir sal_Bool bSimple = ( pE->aSel.nStartPara == pE->aSel.nEndPara );
190cdf0e10cSrcweir for (sal_uInt16 nId = EE_CHAR_START; nId <= EE_CHAR_END && bSimple; nId++)
191cdf0e10cSrcweir {
192cdf0e10cSrcweir const SfxPoolItem* pItem = 0;
193cdf0e10cSrcweir SfxItemState eState = aSet.GetItemState( nId, sal_True, &pItem );
194cdf0e10cSrcweir if (eState == SFX_ITEM_DONTCARE)
195cdf0e10cSrcweir bSimple = sal_False;
196cdf0e10cSrcweir else if (eState == SFX_ITEM_SET)
197cdf0e10cSrcweir {
198cdf0e10cSrcweir if ( nId == EE_CHAR_ESCAPEMENT ) // Hoch-/Tiefstellen immer ueber EE
199cdf0e10cSrcweir {
200cdf0e10cSrcweir if ( (SvxEscapement)((const SvxEscapementItem*)pItem)->GetEnumValue()
201cdf0e10cSrcweir != SVX_ESCAPEMENT_OFF )
202cdf0e10cSrcweir bSimple = sal_False;
203cdf0e10cSrcweir }
204cdf0e10cSrcweir }
205cdf0e10cSrcweir }
206cdf0e10cSrcweir if ( bSimple )
207cdf0e10cSrcweir { // Feldbefehle enthalten?
208cdf0e10cSrcweir SfxItemState eFieldState = aSet.GetItemState( EE_FEATURE_FIELD, sal_False );
209cdf0e10cSrcweir if ( eFieldState == SFX_ITEM_DONTCARE || eFieldState == SFX_ITEM_SET )
210cdf0e10cSrcweir bSimple = sal_False;
211cdf0e10cSrcweir }
212cdf0e10cSrcweir
213cdf0e10cSrcweir // HTML
214cdf0e10cSrcweir String aValStr, aNumStr;
215cdf0e10cSrcweir double fVal;
216cdf0e10cSrcweir sal_uInt32 nNumForm = 0;
217cdf0e10cSrcweir LanguageType eNumLang = LANGUAGE_NONE;
218cdf0e10cSrcweir if ( pE->pNumStr )
219cdf0e10cSrcweir { // SDNUM muss sein wenn SDVAL
220cdf0e10cSrcweir aNumStr = *pE->pNumStr;
221cdf0e10cSrcweir if ( pE->pValStr )
222cdf0e10cSrcweir aValStr = *pE->pValStr;
223cdf0e10cSrcweir fVal = SfxHTMLParser::GetTableDataOptionsValNum(
224cdf0e10cSrcweir nNumForm, eNumLang, aValStr, aNumStr, *pFormatter );
225cdf0e10cSrcweir }
226cdf0e10cSrcweir
227cdf0e10cSrcweir // Attribute setzen
228cdf0e10cSrcweir ScPatternAttr aAttr( pDocPool );
229cdf0e10cSrcweir aAttr.GetFromEditItemSet( &aSet );
230cdf0e10cSrcweir SfxItemSet& rSet = aAttr.GetItemSet();
231cdf0e10cSrcweir if ( aNumStr.Len() )
232cdf0e10cSrcweir {
233cdf0e10cSrcweir rSet.Put( SfxUInt32Item( ATTR_VALUE_FORMAT, nNumForm ) );
234cdf0e10cSrcweir rSet.Put( SvxLanguageItem( eNumLang, ATTR_LANGUAGE_FORMAT ) );
235cdf0e10cSrcweir }
236cdf0e10cSrcweir const SfxItemSet& rESet = pE->aItemSet;
237cdf0e10cSrcweir if ( rESet.Count() )
238cdf0e10cSrcweir {
239cdf0e10cSrcweir const SfxPoolItem* pItem;
240cdf0e10cSrcweir if ( rESet.GetItemState( ATTR_BACKGROUND, sal_False, &pItem) == SFX_ITEM_SET )
241cdf0e10cSrcweir rSet.Put( *pItem );
242cdf0e10cSrcweir if ( rESet.GetItemState( ATTR_BORDER, sal_False, &pItem) == SFX_ITEM_SET )
243cdf0e10cSrcweir rSet.Put( *pItem );
244cdf0e10cSrcweir if ( rESet.GetItemState( ATTR_SHADOW, sal_False, &pItem) == SFX_ITEM_SET )
245cdf0e10cSrcweir rSet.Put( *pItem );
246cdf0e10cSrcweir // HTML
247cdf0e10cSrcweir if ( rESet.GetItemState( ATTR_HOR_JUSTIFY, sal_False, &pItem) == SFX_ITEM_SET )
248cdf0e10cSrcweir rSet.Put( *pItem );
249cdf0e10cSrcweir if ( rESet.GetItemState( ATTR_VER_JUSTIFY, sal_False, &pItem) == SFX_ITEM_SET )
250cdf0e10cSrcweir rSet.Put( *pItem );
251cdf0e10cSrcweir if ( rESet.GetItemState( ATTR_LINEBREAK, sal_False, &pItem) == SFX_ITEM_SET )
252cdf0e10cSrcweir rSet.Put( *pItem );
253cdf0e10cSrcweir if ( rESet.GetItemState( ATTR_FONT_COLOR, sal_False, &pItem) == SFX_ITEM_SET )
254cdf0e10cSrcweir rSet.Put( *pItem );
255cdf0e10cSrcweir if ( rESet.GetItemState( ATTR_FONT_UNDERLINE, sal_False, &pItem) == SFX_ITEM_SET )
256cdf0e10cSrcweir rSet.Put( *pItem );
257cdf0e10cSrcweir // HTML LATIN/CJK/CTL script type dependent
258cdf0e10cSrcweir const SfxPoolItem* pFont;
259cdf0e10cSrcweir if ( rESet.GetItemState( ATTR_FONT, sal_False, &pFont) != SFX_ITEM_SET )
260cdf0e10cSrcweir pFont = 0;
261cdf0e10cSrcweir const SfxPoolItem* pHeight;
262cdf0e10cSrcweir if ( rESet.GetItemState( ATTR_FONT_HEIGHT, sal_False, &pHeight) != SFX_ITEM_SET )
263cdf0e10cSrcweir pHeight = 0;
264cdf0e10cSrcweir const SfxPoolItem* pWeight;
265cdf0e10cSrcweir if ( rESet.GetItemState( ATTR_FONT_WEIGHT, sal_False, &pWeight) != SFX_ITEM_SET )
266cdf0e10cSrcweir pWeight = 0;
267cdf0e10cSrcweir const SfxPoolItem* pPosture;
268cdf0e10cSrcweir if ( rESet.GetItemState( ATTR_FONT_POSTURE, sal_False, &pPosture) != SFX_ITEM_SET )
269cdf0e10cSrcweir pPosture = 0;
270cdf0e10cSrcweir if ( pFont || pHeight || pWeight || pPosture )
271cdf0e10cSrcweir {
272cdf0e10cSrcweir String aStr( mpEngine->GetText( pE->aSel ) );
273cdf0e10cSrcweir sal_uInt8 nScriptType = mpDoc->GetStringScriptType( aStr );
274cdf0e10cSrcweir const sal_uInt8 nScripts[3] = { SCRIPTTYPE_LATIN,
275cdf0e10cSrcweir SCRIPTTYPE_ASIAN, SCRIPTTYPE_COMPLEX };
276cdf0e10cSrcweir for ( sal_uInt8 i=0; i<3; ++i )
277cdf0e10cSrcweir {
278cdf0e10cSrcweir if ( nScriptType & nScripts[i] )
279cdf0e10cSrcweir {
280cdf0e10cSrcweir if ( pFont )
281cdf0e10cSrcweir rSet.Put( *pFont, ScGlobal::GetScriptedWhichID(
282cdf0e10cSrcweir nScripts[i], ATTR_FONT ));
283cdf0e10cSrcweir if ( pHeight )
284cdf0e10cSrcweir rSet.Put( *pHeight, ScGlobal::GetScriptedWhichID(
285cdf0e10cSrcweir nScripts[i], ATTR_FONT_HEIGHT ));
286cdf0e10cSrcweir if ( pWeight )
287cdf0e10cSrcweir rSet.Put( *pWeight, ScGlobal::GetScriptedWhichID(
288cdf0e10cSrcweir nScripts[i], ATTR_FONT_WEIGHT ));
289cdf0e10cSrcweir if ( pPosture )
290cdf0e10cSrcweir rSet.Put( *pPosture, ScGlobal::GetScriptedWhichID(
291cdf0e10cSrcweir nScripts[i], ATTR_FONT_POSTURE ));
292cdf0e10cSrcweir }
293cdf0e10cSrcweir }
294cdf0e10cSrcweir }
295cdf0e10cSrcweir }
296cdf0e10cSrcweir if ( pE->nColOverlap > 1 || pE->nRowOverlap > 1 )
297cdf0e10cSrcweir { // merged cells, mit SfxItemSet Put schneller als mit
298cdf0e10cSrcweir // nachtraeglichem ScDocument DoMerge
299cdf0e10cSrcweir ScMergeAttr aMerge( pE->nColOverlap, pE->nRowOverlap );
300cdf0e10cSrcweir rSet.Put( aMerge );
301cdf0e10cSrcweir SCROW nRO = 0;
302cdf0e10cSrcweir if ( pE->nColOverlap > 1 )
303cdf0e10cSrcweir mpDoc->ApplyFlagsTab( nCol+1, nRow,
304cdf0e10cSrcweir nCol + pE->nColOverlap - 1, nRow, nTab,
305cdf0e10cSrcweir SC_MF_HOR );
306cdf0e10cSrcweir if ( pE->nRowOverlap > 1 )
307cdf0e10cSrcweir {
308cdf0e10cSrcweir nRO = nRow + pE->nRowOverlap - 1;
309cdf0e10cSrcweir mpDoc->ApplyFlagsTab( nCol, nRow+1,
310cdf0e10cSrcweir nCol, nRO , nTab,
311cdf0e10cSrcweir SC_MF_VER );
312cdf0e10cSrcweir if ( nRO > nOverlapRowMax )
313cdf0e10cSrcweir nOverlapRowMax = nRO;
314cdf0e10cSrcweir }
315cdf0e10cSrcweir if ( pE->nColOverlap > 1 && pE->nRowOverlap > 1 )
316cdf0e10cSrcweir mpDoc->ApplyFlagsTab( nCol+1, nRow+1,
317cdf0e10cSrcweir nCol + pE->nColOverlap - 1, nRO, nTab,
318cdf0e10cSrcweir SC_MF_HOR | SC_MF_VER );
319cdf0e10cSrcweir }
320cdf0e10cSrcweir const ScStyleSheet* pStyleSheet =
321cdf0e10cSrcweir mpDoc->GetPattern( nCol, nRow, nTab )->GetStyleSheet();
322cdf0e10cSrcweir aAttr.SetStyleSheet( (ScStyleSheet*)pStyleSheet );
323cdf0e10cSrcweir mpDoc->SetPattern( nCol, nRow, nTab, aAttr, sal_True );
324cdf0e10cSrcweir
325cdf0e10cSrcweir // Daten eintragen
326cdf0e10cSrcweir if (bSimple)
327cdf0e10cSrcweir {
328cdf0e10cSrcweir if ( aValStr.Len() )
329cdf0e10cSrcweir mpDoc->SetValue( nCol, nRow, nTab, fVal );
330cdf0e10cSrcweir else if ( !pE->aSel.HasRange() )
331cdf0e10cSrcweir {
332cdf0e10cSrcweir // maybe ALT text of IMG or similar
333cdf0e10cSrcweir mpDoc->SetString( nCol, nRow, nTab, pE->aAltText, pFormatter );
334cdf0e10cSrcweir // wenn SelRange komplett leer kann nachfolgender Text im gleichen Absatz liegen!
335cdf0e10cSrcweir }
336cdf0e10cSrcweir else
337cdf0e10cSrcweir {
338cdf0e10cSrcweir String aStr;
339cdf0e10cSrcweir if( pE->bEntirePara )
340cdf0e10cSrcweir {
341cdf0e10cSrcweir aStr = mpEngine->GetText( pE->aSel.nStartPara );
342cdf0e10cSrcweir }
343cdf0e10cSrcweir else
344cdf0e10cSrcweir {
345cdf0e10cSrcweir aStr = mpEngine->GetText( pE->aSel );
346cdf0e10cSrcweir aStr.EraseLeadingAndTrailingChars();
347cdf0e10cSrcweir }
348cdf0e10cSrcweir
349cdf0e10cSrcweir // TODO: RTF import should follow the language tag,
350cdf0e10cSrcweir // currently this follows the HTML options for both, HTML
351cdf0e10cSrcweir // and RTF.
352cdf0e10cSrcweir bool bEnUsRecognized = false;
353cdf0e10cSrcweir if (bNumbersEnglishUS)
354cdf0e10cSrcweir {
355cdf0e10cSrcweir pFormatter->ChangeIntl( LANGUAGE_ENGLISH_US);
356cdf0e10cSrcweir sal_uInt32 nIndex = pFormatter->GetStandardIndex( LANGUAGE_ENGLISH_US);
357cdf0e10cSrcweir double fEnVal = 0.0;
358cdf0e10cSrcweir if (pFormatter->IsNumberFormat( aStr, nIndex, fEnVal))
359cdf0e10cSrcweir {
360cdf0e10cSrcweir bEnUsRecognized = true;
361cdf0e10cSrcweir sal_uInt32 nNewIndex =
362cdf0e10cSrcweir pFormatter->GetFormatForLanguageIfBuiltIn(
363cdf0e10cSrcweir nIndex, LANGUAGE_SYSTEM);
364cdf0e10cSrcweir DBG_ASSERT( nNewIndex != nIndex, "ScEEImport::WriteToDocument: NumbersEnglishUS not a built-in format?");
365cdf0e10cSrcweir pFormatter->GetInputLineString( fEnVal, nNewIndex, aStr);
366cdf0e10cSrcweir }
367cdf0e10cSrcweir pFormatter->ChangeIntl( LANGUAGE_SYSTEM);
368cdf0e10cSrcweir }
369cdf0e10cSrcweir
370cdf0e10cSrcweir // #105460#, #i4180# String cells can't contain tabs or linebreaks
371cdf0e10cSrcweir // -> replace with spaces
372cdf0e10cSrcweir aStr.SearchAndReplaceAll( (sal_Unicode)'\t', (sal_Unicode)' ' );
373cdf0e10cSrcweir aStr.SearchAndReplaceAll( (sal_Unicode)'\n', (sal_Unicode)' ' );
374cdf0e10cSrcweir
375cdf0e10cSrcweir if (bNumbersEnglishUS && !bEnUsRecognized)
376cdf0e10cSrcweir mpDoc->PutCell( nCol, nRow, nTab, new ScStringCell( aStr));
377cdf0e10cSrcweir else
378cdf0e10cSrcweir mpDoc->SetString( nCol, nRow, nTab, aStr, pFormatter, bConvertDate );
379cdf0e10cSrcweir }
380cdf0e10cSrcweir }
381cdf0e10cSrcweir else
382cdf0e10cSrcweir {
383cdf0e10cSrcweir EditTextObject* pObject = mpEngine->CreateTextObject( pE->aSel );
384cdf0e10cSrcweir mpDoc->PutCell( nCol, nRow, nTab, new ScEditCell( pObject,
385cdf0e10cSrcweir mpDoc, mpEngine->GetEditTextObjectPool() ) );
386cdf0e10cSrcweir delete pObject;
387cdf0e10cSrcweir }
388cdf0e10cSrcweir if ( pE->pImageList )
389cdf0e10cSrcweir bHasGraphics |= GraphicSize( nCol, nRow, nTab, pE );
390cdf0e10cSrcweir if ( pE->pName )
391cdf0e10cSrcweir { // Anchor Name => RangeName
392cdf0e10cSrcweir sal_uInt16 nIndex;
393cdf0e10cSrcweir if ( !pRangeNames->SearchName( *pE->pName, nIndex ) )
394cdf0e10cSrcweir {
395cdf0e10cSrcweir ScRangeData* pData = new ScRangeData( mpDoc, *pE->pName,
396cdf0e10cSrcweir ScAddress( nCol, nRow, nTab ) );
397cdf0e10cSrcweir pRangeNames->Insert( pData );
398cdf0e10cSrcweir }
399cdf0e10cSrcweir }
400cdf0e10cSrcweir }
401cdf0e10cSrcweir pProgress->SetStateOnPercent( ++nProgress );
402cdf0e10cSrcweir }
403cdf0e10cSrcweir if ( bSizeColsRows )
404cdf0e10cSrcweir {
405cdf0e10cSrcweir // Spaltenbreiten
406cdf0e10cSrcweir Table* pColWidths = mpParser->GetColWidths();
407cdf0e10cSrcweir if ( pColWidths->Count() )
408cdf0e10cSrcweir {
409cdf0e10cSrcweir nProgress = 0;
410cdf0e10cSrcweir pProgress->SetState( nProgress, nEndCol - nStartCol + 1 );
411cdf0e10cSrcweir for ( SCCOL nCol = nStartCol; nCol <= nEndCol; nCol++ )
412cdf0e10cSrcweir {
413cdf0e10cSrcweir sal_uInt16 nWidth = (sal_uInt16)(sal_uLong) pColWidths->Get( nCol );
414cdf0e10cSrcweir if ( nWidth )
415cdf0e10cSrcweir mpDoc->SetColWidth( nCol, nTab, nWidth );
416cdf0e10cSrcweir pProgress->SetState( ++nProgress );
417cdf0e10cSrcweir }
418cdf0e10cSrcweir }
419cdf0e10cSrcweir DELETEZ( pProgress ); // SetOptimalHeight hat seinen eigenen ProgressBar
420cdf0e10cSrcweir // Zeilenhoehen anpassen, Basis 100% Zoom
421cdf0e10cSrcweir Fraction aZoom( 1, 1 );
422cdf0e10cSrcweir double nPPTX = ScGlobal::nScreenPPTX * (double) aZoom
423cdf0e10cSrcweir / nOutputFactor; // Faktor ist Drucker zu Bildschirm
424cdf0e10cSrcweir double nPPTY = ScGlobal::nScreenPPTY * (double) aZoom;
425cdf0e10cSrcweir VirtualDevice aVirtDev;
426cdf0e10cSrcweir mpDoc->SetOptimalHeight( 0, nEndRow, 0,
427cdf0e10cSrcweir static_cast< sal_uInt16 >( ScGlobal::nLastRowHeightExtra ), &aVirtDev,
428cdf0e10cSrcweir nPPTX, nPPTY, aZoom, aZoom, sal_False );
429cdf0e10cSrcweir if ( mpRowHeights->Count() )
430cdf0e10cSrcweir {
431cdf0e10cSrcweir for ( SCROW nRow = nStartRow; nRow <= nEndRow; nRow++ )
432cdf0e10cSrcweir {
433cdf0e10cSrcweir sal_uInt16 nHeight = (sal_uInt16)(sal_uLong) mpRowHeights->Get( nRow );
434cdf0e10cSrcweir if ( nHeight > mpDoc->GetRowHeight( nRow, nTab ) )
435cdf0e10cSrcweir mpDoc->SetRowHeight( nRow, nTab, nHeight );
436cdf0e10cSrcweir }
437cdf0e10cSrcweir }
438cdf0e10cSrcweir }
439cdf0e10cSrcweir if ( bHasGraphics )
440cdf0e10cSrcweir { // Grafiken einfuegen
441cdf0e10cSrcweir for ( pE = mpParser->First(); pE; pE = mpParser->Next() )
442cdf0e10cSrcweir {
443cdf0e10cSrcweir if ( pE->pImageList )
444cdf0e10cSrcweir {
445cdf0e10cSrcweir SCCOL nCol = pE->nCol;
446cdf0e10cSrcweir SCROW nRow = pE->nRow;
447cdf0e10cSrcweir if ( ValidCol(nCol) && ValidRow(nRow) )
448cdf0e10cSrcweir InsertGraphic( nCol, nRow, nTab, pE );
449cdf0e10cSrcweir }
450cdf0e10cSrcweir }
451cdf0e10cSrcweir }
452cdf0e10cSrcweir if ( pProgress )
453cdf0e10cSrcweir delete pProgress;
454cdf0e10cSrcweir }
455cdf0e10cSrcweir
456cdf0e10cSrcweir
GraphicSize(SCCOL nCol,SCROW nRow,SCTAB,ScEEParseEntry * pE)457cdf0e10cSrcweir sal_Bool ScEEImport::GraphicSize( SCCOL nCol, SCROW nRow, SCTAB /*nTab*/,
458cdf0e10cSrcweir ScEEParseEntry* pE )
459cdf0e10cSrcweir {
460cdf0e10cSrcweir ScHTMLImageList* pIL = pE->pImageList;
461cdf0e10cSrcweir if ( !pIL || !pIL->Count() )
462cdf0e10cSrcweir return sal_False;
463cdf0e10cSrcweir sal_Bool bHasGraphics = sal_False;
464cdf0e10cSrcweir OutputDevice* pDefaultDev = Application::GetDefaultDevice();
465cdf0e10cSrcweir long nWidth, nHeight;
466cdf0e10cSrcweir nWidth = nHeight = 0;
467cdf0e10cSrcweir sal_Char nDir = nHorizontal;
468cdf0e10cSrcweir for ( ScHTMLImage* pI = pIL->First(); pI; pI = pIL->Next() )
469cdf0e10cSrcweir {
470cdf0e10cSrcweir if ( pI->pGraphic )
471cdf0e10cSrcweir bHasGraphics = sal_True;
472cdf0e10cSrcweir Size aSizePix = pI->aSize;
473cdf0e10cSrcweir aSizePix.Width() += 2 * pI->aSpace.X();
474cdf0e10cSrcweir aSizePix.Height() += 2 * pI->aSpace.Y();
475cdf0e10cSrcweir Size aLogicSize = pDefaultDev->PixelToLogic( aSizePix, MapMode( MAP_TWIP ) );
476cdf0e10cSrcweir if ( nDir & nHorizontal )
477cdf0e10cSrcweir nWidth += aLogicSize.Width();
478cdf0e10cSrcweir else if ( nWidth < aLogicSize.Width() )
479cdf0e10cSrcweir nWidth = aLogicSize.Width();
480cdf0e10cSrcweir if ( nDir & nVertical )
481cdf0e10cSrcweir nHeight += aLogicSize.Height();
482cdf0e10cSrcweir else if ( nHeight < aLogicSize.Height() )
483cdf0e10cSrcweir nHeight = aLogicSize.Height();
484cdf0e10cSrcweir nDir = pI->nDir;
485cdf0e10cSrcweir }
486cdf0e10cSrcweir // Spaltenbreiten
487cdf0e10cSrcweir Table* pColWidths = mpParser->GetColWidths();
488cdf0e10cSrcweir long nThisWidth = (long) pColWidths->Get( nCol );
489cdf0e10cSrcweir long nColWidths = nThisWidth;
490cdf0e10cSrcweir SCCOL nColSpanCol = nCol + pE->nColOverlap;
491cdf0e10cSrcweir for ( SCCOL nC = nCol + 1; nC < nColSpanCol; nC++ )
492cdf0e10cSrcweir {
493cdf0e10cSrcweir nColWidths += (long) pColWidths->Get( nC );
494cdf0e10cSrcweir }
495cdf0e10cSrcweir if ( nWidth > nColWidths )
496cdf0e10cSrcweir { // Differenz nur in der ersten Spalte eintragen
497cdf0e10cSrcweir if ( nThisWidth )
498cdf0e10cSrcweir pColWidths->Replace( nCol, (void*)(nWidth - nColWidths + nThisWidth) );
499cdf0e10cSrcweir else
500cdf0e10cSrcweir pColWidths->Insert( nCol, (void*)(nWidth - nColWidths) );
501cdf0e10cSrcweir }
502cdf0e10cSrcweir // Zeilenhoehen, Differenz auf alle betroffenen Zeilen verteilen
503cdf0e10cSrcweir SCROW nRowSpan = pE->nRowOverlap;
504cdf0e10cSrcweir nHeight /= nRowSpan;
505cdf0e10cSrcweir if ( nHeight == 0 )
506cdf0e10cSrcweir nHeight = 1; // fuer eindeutigen Vergleich
507cdf0e10cSrcweir for ( SCROW nR = nRow; nR < nRow + nRowSpan; nR++ )
508cdf0e10cSrcweir {
509cdf0e10cSrcweir long nRowHeight = (long) mpRowHeights->Get( nR );
510cdf0e10cSrcweir if ( nHeight > nRowHeight )
511cdf0e10cSrcweir {
512cdf0e10cSrcweir if ( nRowHeight )
513cdf0e10cSrcweir mpRowHeights->Replace( nR, (void*)nHeight );
514cdf0e10cSrcweir else
515cdf0e10cSrcweir mpRowHeights->Insert( nR, (void*)nHeight );
516cdf0e10cSrcweir }
517cdf0e10cSrcweir }
518cdf0e10cSrcweir return bHasGraphics;
519cdf0e10cSrcweir }
520cdf0e10cSrcweir
521cdf0e10cSrcweir
InsertGraphic(SCCOL nCol,SCROW nRow,SCTAB nTab,ScEEParseEntry * pE)522cdf0e10cSrcweir void ScEEImport::InsertGraphic( SCCOL nCol, SCROW nRow, SCTAB nTab,
523cdf0e10cSrcweir ScEEParseEntry* pE )
524cdf0e10cSrcweir {
525cdf0e10cSrcweir ScHTMLImageList* pIL = pE->pImageList;
526cdf0e10cSrcweir if ( !pIL || !pIL->Count() )
527cdf0e10cSrcweir return ;
528cdf0e10cSrcweir ScDrawLayer* pModel = mpDoc->GetDrawLayer();
529cdf0e10cSrcweir if (!pModel)
530cdf0e10cSrcweir {
531cdf0e10cSrcweir mpDoc->InitDrawLayer();
532cdf0e10cSrcweir pModel = mpDoc->GetDrawLayer();
533cdf0e10cSrcweir }
534cdf0e10cSrcweir SdrPage* pPage = pModel->GetPage( static_cast<sal_uInt16>(nTab) );
535cdf0e10cSrcweir OutputDevice* pDefaultDev = Application::GetDefaultDevice();
536cdf0e10cSrcweir
537cdf0e10cSrcweir Point aCellInsertPos(
538cdf0e10cSrcweir (long)((double) mpDoc->GetColOffset( nCol, nTab ) * HMM_PER_TWIPS),
539cdf0e10cSrcweir (long)((double) mpDoc->GetRowOffset( nRow, nTab ) * HMM_PER_TWIPS) );
540cdf0e10cSrcweir
541cdf0e10cSrcweir Point aInsertPos( aCellInsertPos );
542cdf0e10cSrcweir Point aSpace;
543cdf0e10cSrcweir Size aLogicSize;
544cdf0e10cSrcweir sal_Char nDir = nHorizontal;
545cdf0e10cSrcweir for ( ScHTMLImage* pI = pIL->First(); pI; pI = pIL->Next() )
546cdf0e10cSrcweir {
547cdf0e10cSrcweir if ( nDir & nHorizontal )
548cdf0e10cSrcweir { // horizontal
549cdf0e10cSrcweir aInsertPos.X() += aLogicSize.Width();
550cdf0e10cSrcweir aInsertPos.X() += aSpace.X();
551cdf0e10cSrcweir aInsertPos.Y() = aCellInsertPos.Y();
552cdf0e10cSrcweir }
553cdf0e10cSrcweir else
554cdf0e10cSrcweir { // vertikal
555cdf0e10cSrcweir aInsertPos.X() = aCellInsertPos.X();
556cdf0e10cSrcweir aInsertPos.Y() += aLogicSize.Height();
557cdf0e10cSrcweir aInsertPos.Y() += aSpace.Y();
558cdf0e10cSrcweir }
559cdf0e10cSrcweir // Offset des Spacings drauf
560cdf0e10cSrcweir aSpace = pDefaultDev->PixelToLogic( pI->aSpace, MapMode( MAP_100TH_MM ) );
561cdf0e10cSrcweir aInsertPos += aSpace;
562cdf0e10cSrcweir
563cdf0e10cSrcweir Size aSizePix = pI->aSize;
564cdf0e10cSrcweir aLogicSize = pDefaultDev->PixelToLogic( aSizePix, MapMode( MAP_100TH_MM ) );
565cdf0e10cSrcweir // Groesse begrenzen
566cdf0e10cSrcweir ::ScLimitSizeOnDrawPage( aLogicSize, aInsertPos, pPage->GetSize() );
567cdf0e10cSrcweir
568cdf0e10cSrcweir if ( pI->pGraphic )
569cdf0e10cSrcweir {
570cdf0e10cSrcweir Rectangle aRect ( aInsertPos, aLogicSize );
571cdf0e10cSrcweir SdrGrafObj* pObj = new SdrGrafObj( *pI->pGraphic, aRect );
572cdf0e10cSrcweir // #118522# calling SetGraphicLink here doesn't work
573cdf0e10cSrcweir pObj->SetName( pI->aURL );
574cdf0e10cSrcweir
575cdf0e10cSrcweir pPage->InsertObject( pObj );
576cdf0e10cSrcweir
577cdf0e10cSrcweir // #118522# SetGraphicLink has to be used after inserting the object,
578cdf0e10cSrcweir // otherwise an empty graphic is swapped in and the contact stuff crashes.
579cdf0e10cSrcweir // See #i37444#.
580cdf0e10cSrcweir pObj->SetGraphicLink( pI->aURL, pI->aFilterName );
581cdf0e10cSrcweir
582cdf0e10cSrcweir pObj->SetLogicRect( aRect ); // erst nach InsertObject !!!
583cdf0e10cSrcweir }
584cdf0e10cSrcweir nDir = pI->nDir;
585cdf0e10cSrcweir }
586cdf0e10cSrcweir }
587cdf0e10cSrcweir
588cdf0e10cSrcweir
ScEEParser(EditEngine * pEditP)589cdf0e10cSrcweir ScEEParser::ScEEParser( EditEngine* pEditP ) :
590cdf0e10cSrcweir pEdit( pEditP ),
591cdf0e10cSrcweir pPool( EditEngine::CreatePool() ),
592cdf0e10cSrcweir pDocPool( new ScDocumentPool ),
593cdf0e10cSrcweir pList( new ScEEParseList ),
594cdf0e10cSrcweir pColWidths( new Table ),
595cdf0e10cSrcweir nLastToken(0),
596cdf0e10cSrcweir nColCnt(0),
597cdf0e10cSrcweir nRowCnt(0),
598cdf0e10cSrcweir nColMax(0),
599cdf0e10cSrcweir nRowMax(0)
600cdf0e10cSrcweir {
601cdf0e10cSrcweir // pPool wird spaeter bei RTFIMP_START dem SvxRTFParser untergejubelt
602cdf0e10cSrcweir pPool->SetSecondaryPool( pDocPool );
603cdf0e10cSrcweir pPool->FreezeIdRanges();
604cdf0e10cSrcweir NewActEntry( NULL );
605cdf0e10cSrcweir }
606cdf0e10cSrcweir
607cdf0e10cSrcweir
~ScEEParser()608cdf0e10cSrcweir ScEEParser::~ScEEParser()
609cdf0e10cSrcweir {
610cdf0e10cSrcweir delete pActEntry;
611cdf0e10cSrcweir delete pColWidths;
612cdf0e10cSrcweir for ( ScEEParseEntry* pE = pList->First(); pE; pE = pList->Next() )
613cdf0e10cSrcweir delete pE;
614cdf0e10cSrcweir delete pList;
615cdf0e10cSrcweir
616cdf0e10cSrcweir // Pool erst loeschen nachdem die Listen geloescht wurden
617cdf0e10cSrcweir pPool->SetSecondaryPool( NULL );
618cdf0e10cSrcweir SfxItemPool::Free(pDocPool);
619cdf0e10cSrcweir SfxItemPool::Free(pPool);
620cdf0e10cSrcweir }
621cdf0e10cSrcweir
622cdf0e10cSrcweir
NewActEntry(ScEEParseEntry * pE)623cdf0e10cSrcweir void ScEEParser::NewActEntry( ScEEParseEntry* pE )
624cdf0e10cSrcweir { // neuer freifliegender pActEntry
625cdf0e10cSrcweir pActEntry = new ScEEParseEntry( pPool );
626cdf0e10cSrcweir pActEntry->aSel.nStartPara = (pE ? pE->aSel.nEndPara + 1 : 0);
627cdf0e10cSrcweir pActEntry->aSel.nStartPos = 0;
628cdf0e10cSrcweir }
629cdf0e10cSrcweir
630cdf0e10cSrcweir
631cdf0e10cSrcweir
632cdf0e10cSrcweir
633