xref: /trunk/main/sc/source/filter/starcalc/scflt.cxx (revision b77af630)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_scfilt.hxx"
26 
27 
28 
29 // INCLUDE ---------------------------------------------------------------
30 
31 #include "scitems.hxx"
32 #include <editeng/eeitem.hxx>
33 
34 #include <svx/algitem.hxx>
35 #include <editeng/boxitem.hxx>
36 #include <editeng/brshitem.hxx>
37 #include <editeng/colritem.hxx>
38 #include <editeng/crsditem.hxx>
39 #include <editeng/editdata.hxx>
40 #include <editeng/editeng.hxx>
41 #include <editeng/editobj.hxx>
42 #include <editeng/fhgtitem.hxx>
43 #include <editeng/fontitem.hxx>
44 #include <editeng/lrspitem.hxx>
45 #include <svx/pageitem.hxx>
46 #include <editeng/postitem.hxx>
47 #include <editeng/sizeitem.hxx>
48 #include <editeng/udlnitem.hxx>
49 #include <editeng/ulspitem.hxx>
50 #include <editeng/wghtitem.hxx>
51 #include <svl/zforlist.hxx>
52 #include <svl/PasswordHelper.hxx>
53 #include <stdio.h>
54 #include <math.h>
55 #include <string.h>
56 
57 #include "global.hxx"
58 #include "sc.hrc"
59 #include "attrib.hxx"
60 #include "patattr.hxx"
61 #include "docpool.hxx"
62 #include "document.hxx"
63 #include "collect.hxx"
64 #include "rangenam.hxx"
65 #include "dbcolect.hxx"
66 #include "stlsheet.hxx"
67 #include "stlpool.hxx"
68 #include "filter.hxx"
69 #include "scflt.hxx"
70 #include "cell.hxx"
71 #include "scfobj.hxx"
72 #include "docoptio.hxx"
73 #include "viewopti.hxx"
74 #include "postit.hxx"
75 #include "globstr.hrc"
76 #include "ftools.hxx"
77 #include "tabprotection.hxx"
78 
79 #include "fprogressbar.hxx"
80 
81 using namespace com::sun::star;
82 
83 #define	DEFCHARSET			RTL_TEXTENCODING_MS_1252
84 
85 #define SC10TOSTRING(p)		String((p),DEFCHARSET)
86 
87 const SCCOL SC10MAXCOL = 255;   // #i85906# don't try to load more columns than there are in the file
88 
89 
90 /** Those strings are used with SC10TOSTRING() and strcmp() and such, hence
91     need to be 0-terminated. */
lcl_ReadFixedString(SvStream & rStream,void * pData,size_t nLen)92 static void lcl_ReadFixedString( SvStream& rStream, void* pData, size_t nLen )
93 {
94     sal_Char* pBuf = static_cast<sal_Char*>(pData);
95     if (!nLen)
96         pBuf[0] = 0;
97     else
98     {
99         rStream.Read( pBuf, nLen);
100         pBuf[nLen-1] = 0;
101     }
102 }
103 
104 
lcl_ReadFileHeader(SvStream & rStream,Sc10FileHeader & rFileHeader)105 static void lcl_ReadFileHeader(SvStream& rStream, Sc10FileHeader& rFileHeader)
106 {
107 	lcl_ReadFixedString( rStream, &rFileHeader.CopyRight, sizeof(rFileHeader.CopyRight));
108 	rStream >> rFileHeader.Version;
109 	rStream.Read(&rFileHeader.Reserved, sizeof(rFileHeader.Reserved));
110 }
111 
112 
lcl_ReadTabProtect(SvStream & rStream,Sc10TableProtect & rProtect)113 static void lcl_ReadTabProtect(SvStream& rStream, Sc10TableProtect& rProtect)
114 {
115 	lcl_ReadFixedString( rStream, &rProtect.PassWord, sizeof(rProtect.PassWord));
116 	rStream >> rProtect.Flags;
117 	rStream >> rProtect.Protect;
118 }
119 
120 
lcl_ReadSheetProtect(SvStream & rStream,Sc10SheetProtect & rProtect)121 static void lcl_ReadSheetProtect(SvStream& rStream, Sc10SheetProtect& rProtect)
122 {
123 	lcl_ReadFixedString( rStream, &rProtect.PassWord, sizeof(rProtect.PassWord));
124 	rStream >> rProtect.Flags;
125 	rStream >> rProtect.Protect;
126 }
127 
128 
lcl_ReadRGB(SvStream & rStream,Sc10Color & rColor)129 static void lcl_ReadRGB(SvStream& rStream, Sc10Color& rColor)
130 {
131 	rStream >> rColor.Dummy;
132 	rStream >> rColor.Blue;
133 	rStream >> rColor.Green;
134 	rStream >> rColor.Red;
135 }
136 
137 
lcl_ReadPalette(SvStream & rStream,Sc10Color * pPalette)138 static void lcl_ReadPalette(SvStream& rStream, Sc10Color* pPalette)
139 {
140 	for (sal_uInt16 i = 0; i < 16; i++)
141 		lcl_ReadRGB(rStream, pPalette[i]);
142 }
143 
144 
lcl_ReadValueFormat(SvStream & rStream,Sc10ValueFormat & rFormat)145 static void lcl_ReadValueFormat(SvStream& rStream, Sc10ValueFormat& rFormat)
146 {
147 	rStream >> rFormat.Format;
148 	rStream >> rFormat.Info;
149 }
150 
151 
lcl_ReadLogFont(SvStream & rStream,Sc10LogFont & rFont)152 static void lcl_ReadLogFont(SvStream& rStream, Sc10LogFont& rFont)
153 {
154 	rStream >> rFont.lfHeight;
155 	rStream >> rFont.lfWidth;
156 	rStream >> rFont.lfEscapement;
157 	rStream >> rFont.lfOrientation;
158 	rStream >> rFont.lfWeight;
159 	rStream >> rFont.lfItalic;
160 	rStream >> rFont.lfUnderline;
161 	rStream >> rFont.lfStrikeOut;
162 	rStream >> rFont.lfCharSet;
163 	rStream >> rFont.lfOutPrecision;
164 	rStream >> rFont.lfClipPrecision;
165 	rStream >> rFont.lfQuality;
166 	rStream >> rFont.lfPitchAndFamily;
167 	lcl_ReadFixedString( rStream, &rFont.lfFaceName, sizeof(rFont.lfFaceName));
168 }
169 
170 
lcl_ReadBlockRect(SvStream & rStream,Sc10BlockRect & rBlock)171 static void lcl_ReadBlockRect(SvStream& rStream, Sc10BlockRect& rBlock)
172 {
173 	rStream >> rBlock.x1;
174 	rStream >> rBlock.y1;
175 	rStream >> rBlock.x2;
176 	rStream >> rBlock.y2;
177 }
178 
179 
lcl_ReadHeadFootLine(SvStream & rStream,Sc10HeadFootLine & rLine)180 static void lcl_ReadHeadFootLine(SvStream& rStream, Sc10HeadFootLine& rLine)
181 {
182 	lcl_ReadFixedString( rStream, &rLine.Title, sizeof(rLine.Title));
183 	lcl_ReadLogFont(rStream, rLine.LogFont);
184 	rStream >> rLine.HorJustify;
185 	rStream >> rLine.VerJustify;
186 	rStream >> rLine.Raster;
187 	rStream >> rLine.Frame;
188 	lcl_ReadRGB(rStream, rLine.TextColor);
189 	lcl_ReadRGB(rStream, rLine.BackColor);
190 	lcl_ReadRGB(rStream, rLine.RasterColor);
191 	rStream >> rLine.FrameColor;
192 	rStream >> rLine.Reserved;
193 }
194 
195 
lcl_ReadPageFormat(SvStream & rStream,Sc10PageFormat & rFormat)196 static void lcl_ReadPageFormat(SvStream& rStream, Sc10PageFormat& rFormat)
197 {
198 	lcl_ReadHeadFootLine(rStream, rFormat.HeadLine);
199 	lcl_ReadHeadFootLine(rStream, rFormat.FootLine);
200 	rStream >> rFormat.Orientation;
201 	rStream >> rFormat.Width;
202 	rStream >> rFormat.Height;
203 	rStream >> rFormat.NonPrintableX;
204 	rStream >> rFormat.NonPrintableY;
205 	rStream >> rFormat.Left;
206 	rStream >> rFormat.Top;
207 	rStream >> rFormat.Right;
208 	rStream >> rFormat.Bottom;
209 	rStream >> rFormat.Head;
210 	rStream >> rFormat.Foot;
211 	rStream >> rFormat.HorCenter;
212 	rStream >> rFormat.VerCenter;
213 	rStream >> rFormat.PrintGrid;
214 	rStream >> rFormat.PrintColRow;
215 	rStream >> rFormat.PrintNote;
216 	rStream >> rFormat.TopBottomDir;
217 	lcl_ReadFixedString( rStream, &rFormat.PrintAreaName, sizeof(rFormat.PrintAreaName));
218 	lcl_ReadBlockRect(rStream, rFormat.PrintArea);
219 	rStream.Read(&rFormat.PrnZoom, sizeof(rFormat.PrnZoom));
220 	rStream >> rFormat.FirstPageNo;
221 	rStream >> rFormat.RowRepeatStart;
222 	rStream >> rFormat.RowRepeatEnd;
223 	rStream >> rFormat.ColRepeatStart;
224 	rStream >> rFormat.ColRepeatEnd;
225 	rStream.Read(&rFormat.Reserved, sizeof(rFormat.Reserved));
226 }
227 
228 
lcl_ReadGraphHeader(SvStream & rStream,Sc10GraphHeader & rHeader)229 static void lcl_ReadGraphHeader(SvStream& rStream, Sc10GraphHeader& rHeader)
230 {
231 	rStream >> rHeader.Typ;
232 	rStream >> rHeader.CarretX;
233 	rStream >> rHeader.CarretY;
234 	rStream >> rHeader.CarretZ;
235 	rStream >> rHeader.x;
236 	rStream >> rHeader.y;
237 	rStream >> rHeader.w;
238 	rStream >> rHeader.h;
239 	rStream >> rHeader.IsRelPos;
240 	rStream >> rHeader.DoPrint;
241 	rStream >> rHeader.FrameType;
242 	rStream >> rHeader.IsTransparent;
243 	lcl_ReadRGB(rStream, rHeader.FrameColor);
244 	lcl_ReadRGB(rStream, rHeader.BackColor);
245 	rStream.Read(&rHeader.Reserved, sizeof(rHeader.Reserved));
246 }
247 
248 
lcl_ReadImageHeaer(SvStream & rStream,Sc10ImageHeader & rHeader)249 static void lcl_ReadImageHeaer(SvStream& rStream, Sc10ImageHeader& rHeader)
250 {
251 	lcl_ReadFixedString( rStream, &rHeader.FileName, sizeof(rHeader.FileName));
252 	rStream >> rHeader.Typ;
253 	rStream >> rHeader.Linked;
254 	rStream >> rHeader.x1;
255 	rStream >> rHeader.y1;
256 	rStream >> rHeader.x2;
257 	rStream >> rHeader.y2;
258 	rStream >> rHeader.Size;
259 }
260 
261 
lcl_ReadChartHeader(SvStream & rStream,Sc10ChartHeader & rHeader)262 static void lcl_ReadChartHeader(SvStream& rStream, Sc10ChartHeader& rHeader)
263 {
264 	rStream >> rHeader.MM;
265 	rStream >> rHeader.xExt;
266 	rStream >> rHeader.yExt;
267 	rStream >> rHeader.Size;
268 }
269 
270 
lcl_ReadChartSheetData(SvStream & rStream,Sc10ChartSheetData & rSheetData)271 static void lcl_ReadChartSheetData(SvStream& rStream, Sc10ChartSheetData& rSheetData)
272 {
273 	rStream >> rSheetData.HasTitle;
274 	rStream >> rSheetData.TitleX;
275 	rStream >> rSheetData.TitleY;
276 	rStream >> rSheetData.HasSubTitle;
277 	rStream >> rSheetData.SubTitleX;
278 	rStream >> rSheetData.SubTitleY;
279 	rStream >> rSheetData.HasLeftTitle;
280 	rStream >> rSheetData.LeftTitleX;
281 	rStream >> rSheetData.LeftTitleY;
282 	rStream >> rSheetData.HasLegend;
283 	rStream >> rSheetData.LegendX1;
284 	rStream >> rSheetData.LegendY1;
285 	rStream >> rSheetData.LegendX2;
286 	rStream >> rSheetData.LegendY2;
287 	rStream >> rSheetData.HasLabel;
288 	rStream >> rSheetData.LabelX1;
289 	rStream >> rSheetData.LabelY1;
290 	rStream >> rSheetData.LabelX2;
291 	rStream >> rSheetData.LabelY2;
292 	rStream >> rSheetData.DataX1;
293 	rStream >> rSheetData.DataY1;
294 	rStream >> rSheetData.DataX2;
295 	rStream >> rSheetData.DataY2;
296 	rStream.Read(&rSheetData.Reserved, sizeof(rSheetData.Reserved));
297 }
298 
299 
lcl_ReadChartTypeData(SvStream & rStream,Sc10ChartTypeData & rTypeData)300 static void lcl_ReadChartTypeData(SvStream& rStream, Sc10ChartTypeData& rTypeData)
301 {
302 	rStream >> rTypeData.NumSets;
303 	rStream >> rTypeData.NumPoints;
304 	rStream >> rTypeData.DrawMode;
305 	rStream >> rTypeData.GraphType;
306 	rStream >> rTypeData.GraphStyle;
307 	lcl_ReadFixedString( rStream, &rTypeData.GraphTitle, sizeof(rTypeData.GraphTitle));
308 	lcl_ReadFixedString( rStream, &rTypeData.BottomTitle, sizeof(rTypeData.BottomTitle));
309 	sal_uInt16 i;
310 	for (i = 0; i < 256; i++)
311 		rStream >> rTypeData.SymbolData[i];
312 	for (i = 0; i < 256; i++)
313 		rStream >> rTypeData.ColorData[i];
314 	for (i = 0; i < 256; i++)
315 		rStream >> rTypeData.ThickLines[i];
316 	for (i = 0; i < 256; i++)
317 		rStream >> rTypeData.PatternData[i];
318 	for (i = 0; i < 256; i++)
319 		rStream >> rTypeData.LinePatternData[i];
320 	for (i = 0; i < 11; i++)
321 		rStream >> rTypeData.NumGraphStyles[i];
322 	rStream >> rTypeData.ShowLegend;
323 	for (i = 0; i < 256; i++)
324 		lcl_ReadFixedString( rStream, &rTypeData.LegendText[i], sizeof(Sc10ChartText));
325 	rStream >> rTypeData.ExplodePie;
326 	rStream >> rTypeData.FontUse;
327 	for (i = 0; i < 5; i++)
328 		rStream >> rTypeData.FontFamily[i];
329 	for (i = 0; i < 5; i++)
330 		rStream >> rTypeData.FontStyle[i];
331 	for (i = 0; i < 5; i++)
332 		rStream >> rTypeData.FontSize[i];
333 	rStream >> rTypeData.GridStyle;
334 	rStream >> rTypeData.Labels;
335 	rStream >> rTypeData.LabelEvery;
336 	for (i = 0; i < 50; i++)
337 		lcl_ReadFixedString( rStream, &rTypeData.LabelText[i], sizeof(Sc10ChartText));
338 	lcl_ReadFixedString( rStream, &rTypeData.LeftTitle, sizeof(rTypeData.LeftTitle));
339 	rStream.Read(&rTypeData.Reserved, sizeof(rTypeData.Reserved));
340 }
341 
lcl_PascalToDouble(sal_Char * tp6)342 double lcl_PascalToDouble(sal_Char* tp6)
343 {
344     sal_uInt8* pnUnsigned = reinterpret_cast< sal_uInt8* >( tp6 );
345     // biased exponent
346     sal_uInt8 be = pnUnsigned[ 0 ];
347     // lower 16 bits of mantissa
348     sal_uInt16 v1 = static_cast< sal_uInt16 >( pnUnsigned[ 2 ] * 256 + pnUnsigned[ 1 ] );
349     // next 16 bits of mantissa
350     sal_uInt16 v2 = static_cast< sal_uInt16 >( pnUnsigned[ 4 ] * 256 + pnUnsigned[ 3 ] );
351     // upper 7 bits of mantissa
352     sal_uInt8 v3 = static_cast< sal_uInt8 >( pnUnsigned[ 5 ] & 0x7F );
353     // sign bit
354     bool s = (pnUnsigned[ 5 ] & 0x80) != 0;
355 
356     if (be == 0)
357         return 0.0;
358     return (((((128 + v3) * 65536.0) + v2) * 65536.0 + v1) *
359         ldexp ((s ? -1.0 : 1.0), be - (129+39)));
360 }
361 
362 
lcl_ChangeColor(sal_uInt16 nIndex,Color & rColor)363 static void lcl_ChangeColor( sal_uInt16 nIndex, Color& rColor )
364 {
365 	ColorData aCol;
366 
367 	switch( nIndex )
368 		{
369 		case 1:		aCol = COL_RED;				break;
370 		case 2:		aCol = COL_GREEN;			break;
371 		case 3:		aCol = COL_BROWN;			break;
372 		case 4:		aCol = COL_BLUE;			break;
373 		case 5:		aCol = COL_MAGENTA;			break;
374 		case 6:		aCol = COL_CYAN;			break;
375 		case 7:		aCol = COL_GRAY;			break;
376 		case 8:		aCol = COL_LIGHTGRAY;		break;
377 		case 9:		aCol = COL_LIGHTRED;		break;
378 		case 10:	aCol = COL_LIGHTGREEN;		break;
379 		case 11:	aCol = COL_YELLOW;			break;
380 		case 12:	aCol = COL_LIGHTBLUE;		break;
381 		case 13:	aCol = COL_LIGHTMAGENTA;	break;
382 		case 14:	aCol = COL_LIGHTCYAN;		break;
383 		case 15:	aCol = COL_WHITE;			break;
384 		default:	aCol = COL_BLACK;
385 		}
386 
387 	rColor.SetColor( aCol );
388 }
389 
lcl_MakeOldPageStyleFormatName(sal_uInt16 i)390 String lcl_MakeOldPageStyleFormatName( sal_uInt16 i )
391 {
392 	String	aName = ScGlobal::GetRscString( STR_PAGESTYLE );
393 	aName.AppendAscii( " " );
394 	aName += String::CreateFromInt32( i + 1 );
395 
396 	return aName;
397 }
398 
399 
insert_new(ScCollection * pCollection,SvStream & rStream)400 template < typename T > sal_uLong insert_new( ScCollection* pCollection, SvStream& rStream )
401 {
402     T* pData = new (::std::nothrow) T( rStream);
403     sal_uLong nError = rStream.GetError();
404     if (pData)
405     {
406         if (nError)
407             delete pData;
408         else
409             pCollection->Insert( pData);
410     }
411     else
412         nError = errOutOfMemory;
413     return nError;
414 }
415 
416 //--------------------------------------------
417 // Font
418 //--------------------------------------------
419 
420 
Sc10FontData(SvStream & rStream)421 Sc10FontData::Sc10FontData(SvStream& rStream)
422 {
423 	rStream >> Height;
424 	rStream >> CharSet;
425 	rStream >> PitchAndFamily;
426 	sal_uInt16 nLen;
427 	rStream >> nLen;
428 	if (nLen < sizeof(FaceName))
429 		rStream.Read(FaceName, nLen);
430 	else
431 		rStream.SetError(ERRCODE_IO_WRONGFORMAT);
432 }
433 
434 
Sc10FontCollection(SvStream & rStream)435 Sc10FontCollection::Sc10FontCollection(SvStream& rStream) :
436 	ScCollection (4, 4),
437 	nError     (0)
438 {
439   sal_uInt16 ID;
440   rStream >> ID;
441   if (ID == FontID)
442   {
443 	sal_uInt16 nAnz;
444 	rStream >> nAnz;
445 	for (sal_uInt16 i=0; (i < nAnz) && (nError == 0); i++)
446 	{
447         nError = insert_new<Sc10FontData>( this, rStream);
448 	}
449   }
450   else
451   {
452 	DBG_ERROR( "FontID" );
453 	nError = errUnknownID;
454   }
455 }
456 
457 
458 //--------------------------------------------
459 // Benannte-Bereiche
460 //--------------------------------------------
461 
462 
Sc10NameData(SvStream & rStream)463 Sc10NameData::Sc10NameData(SvStream& rStream)
464 {
465 	sal_uInt8 nLen;
466 	rStream >> nLen;
467 	rStream.Read(Name, sizeof(Name) - 1);
468 	if (nLen >= sizeof(Name))
469 		nLen = sizeof(Name) - 1;
470 	Name[nLen] = 0;
471 
472 	rStream >> nLen;
473 	rStream.Read(Reference, sizeof(Reference) - 1);
474 	if (nLen >= sizeof(Reference))
475 		nLen = sizeof(Reference) - 1;
476 	Reference[nLen] = 0;
477 	rStream.Read(Reserved, sizeof(Reserved));
478 }
479 
480 
Sc10NameCollection(SvStream & rStream)481 Sc10NameCollection::Sc10NameCollection(SvStream& rStream) :
482 	ScCollection (4, 4),
483 	nError     (0)
484 {
485   sal_uInt16 ID;
486   rStream >> ID;
487   if (ID == NameID)
488   {
489 	sal_uInt16 nAnz;
490 	rStream >> nAnz;
491 	for (sal_uInt16 i=0; (i < nAnz) && (nError == 0); i++)
492 	{
493         nError = insert_new<Sc10NameData>( this, rStream);
494 	}
495   }
496   else
497   {
498 	DBG_ERROR( "NameID" );
499 	nError = errUnknownID;
500   }
501 }
502 
503 //--------------------------------------------
504 // Vorlagen
505 //--------------------------------------------
506 
507 
Sc10PatternData(SvStream & rStream)508 Sc10PatternData::Sc10PatternData(SvStream& rStream)
509 {
510   lcl_ReadFixedString( rStream, Name, sizeof(Name));
511   lcl_ReadValueFormat(rStream, ValueFormat);
512   lcl_ReadLogFont(rStream, LogFont);
513 
514   rStream >> Attr;
515   rStream >> Justify;
516   rStream >> Frame;
517   rStream >> Raster;
518   rStream >> nColor;
519   rStream >> FrameColor;
520   rStream >> Flags;
521   rStream >> FormatFlags;
522   rStream.Read(Reserved, sizeof(Reserved));
523 }
524 
525 
Sc10PatternCollection(SvStream & rStream)526 Sc10PatternCollection::Sc10PatternCollection(SvStream& rStream) :
527   ScCollection (4, 4),
528   nError     (0)
529 {
530   sal_uInt16 ID;
531   rStream >> ID;
532   if (ID == PatternID)
533   {
534 	sal_uInt16 nAnz;
535 	rStream >> nAnz;
536 	for (sal_uInt16 i=0; (i < nAnz) && (nError == 0); i++)
537 	{
538         nError = insert_new<Sc10PatternData>( this, rStream);
539 	}
540   }
541   else
542   {
543 	DBG_ERROR( "PatternID" );
544 	nError = errUnknownID;
545   }
546 }
547 
548 
549 //--------------------------------------------
550 // Datenbank
551 //--------------------------------------------
552 
553 
Sc10DataBaseData(SvStream & rStream)554 Sc10DataBaseData::Sc10DataBaseData(SvStream& rStream)
555 {
556 	lcl_ReadFixedString( rStream, &DataBaseRec.Name, sizeof(DataBaseRec.Name));
557 	rStream >> DataBaseRec.Tab;
558 	lcl_ReadBlockRect(rStream, DataBaseRec.Block);
559 	rStream >> DataBaseRec.RowHeader;
560 	rStream >> DataBaseRec.SortField0;
561 	rStream >> DataBaseRec.SortUpOrder0;
562 	rStream >> DataBaseRec.SortField1;
563 	rStream >> DataBaseRec.SortUpOrder1;
564 	rStream >> DataBaseRec.SortField2;
565 	rStream >> DataBaseRec.SortUpOrder2;
566 	rStream >> DataBaseRec.IncludeFormat;
567 
568 	rStream >> DataBaseRec.QueryField0;
569 	rStream >> DataBaseRec.QueryOp0;
570 	rStream >> DataBaseRec.QueryByString0;
571 	lcl_ReadFixedString( rStream, &DataBaseRec.QueryString0, sizeof(DataBaseRec.QueryString0));
572     DataBaseRec.QueryValue0 = ScfTools::ReadLongDouble(rStream);
573 
574 	rStream >> DataBaseRec.QueryConnect1;
575 	rStream >> DataBaseRec.QueryField1;
576 	rStream >> DataBaseRec.QueryOp1;
577 	rStream >> DataBaseRec.QueryByString1;
578 	lcl_ReadFixedString( rStream, &DataBaseRec.QueryString1, sizeof(DataBaseRec.QueryString1));
579     DataBaseRec.QueryValue1 = ScfTools::ReadLongDouble(rStream);
580 
581 	rStream >> DataBaseRec.QueryConnect2;
582 	rStream >> DataBaseRec.QueryField2;
583 	rStream >> DataBaseRec.QueryOp2;
584 	rStream >> DataBaseRec.QueryByString2;
585 	lcl_ReadFixedString( rStream, &DataBaseRec.QueryString2, sizeof(DataBaseRec.QueryString2));
586     DataBaseRec.QueryValue2 = ScfTools::ReadLongDouble(rStream);
587 }
588 
589 
Sc10DataBaseCollection(SvStream & rStream)590 Sc10DataBaseCollection::Sc10DataBaseCollection(SvStream& rStream) :
591   ScCollection (4, 4),
592   nError     (0)
593 {
594   sal_uInt16 ID;
595   rStream >> ID;
596   if (ID == DataBaseID)
597   {
598 	lcl_ReadFixedString( rStream, ActName, sizeof(ActName));
599 	sal_uInt16 nAnz;
600 	rStream >> nAnz;
601 	for (sal_uInt16 i=0; (i < nAnz) && (nError == 0); i++)
602 	{
603         nError = insert_new<Sc10DataBaseData>( this, rStream);
604 	}
605   }
606   else
607   {
608 	DBG_ERROR( "DataBaseID" );
609 	nError = errUnknownID;
610   }
611 }
612 
613 
operator ==(const Sc10LogFont & rData) const614 int Sc10LogFont::operator==( const Sc10LogFont& rData ) const
615 {
616 	return !strcmp( lfFaceName, rData.lfFaceName )
617 		&& lfHeight == rData.lfHeight
618 		&& lfWidth == rData.lfWidth
619 		&& lfEscapement == rData.lfEscapement
620 		&& lfOrientation == rData.lfOrientation
621 		&& lfWeight == rData.lfWeight
622 		&& lfItalic == rData.lfItalic
623 		&& lfUnderline == rData.lfUnderline
624 		&& lfStrikeOut == rData.lfStrikeOut
625 		&& lfCharSet == rData.lfCharSet
626 		&& lfOutPrecision == rData.lfOutPrecision
627 		&& lfClipPrecision == rData.lfClipPrecision
628 		&& lfQuality == rData.lfQuality
629 		&& lfPitchAndFamily == rData.lfPitchAndFamily;
630 }
631 
632 
operator ==(const Sc10Color & rColor) const633 int Sc10Color::operator==( const Sc10Color& rColor ) const
634 {
635 	return ((Red == rColor.Red) && (Green == rColor.Green) && (Blue == rColor.Blue));
636 }
637 
638 
operator ==(const Sc10HeadFootLine & rData) const639 int Sc10HeadFootLine::operator==( const Sc10HeadFootLine& rData ) const
640 {
641 	return !strcmp(Title, rData.Title)
642 		&& LogFont == rData.LogFont
643 		&& HorJustify == rData.HorJustify
644 		&& VerJustify == rData.VerJustify
645 		&& Raster == rData.Raster
646 		&& Frame == rData.Frame
647 		&& TextColor == rData.TextColor
648 		&& BackColor == rData.BackColor
649 		&& RasterColor == rData.RasterColor
650 		&& FrameColor == rData.FrameColor
651 		&& Reserved == rData.Reserved;
652 }
653 
654 
operator ==(const Sc10PageFormat & rData) const655 int Sc10PageFormat::operator==( const Sc10PageFormat& rData ) const
656 {
657 	return !strcmp(PrintAreaName, rData.PrintAreaName)
658 		&& HeadLine == rData.HeadLine
659 		&& FootLine == rData.FootLine
660 		&& Orientation == rData.Orientation
661 		&& Width == rData.Width
662 		&& Height == rData.Height
663 		&& NonPrintableX == rData.NonPrintableX
664 		&& NonPrintableY == rData.NonPrintableY
665 		&& Left == rData.Left
666 		&& Top == rData.Top
667 		&& Right == rData.Right
668 		&& Bottom == rData.Bottom
669 		&& Head == rData.Head
670 		&& Foot == rData.Foot
671 		&& HorCenter == rData.HorCenter
672 		&& VerCenter == rData.VerCenter
673 		&& PrintGrid == rData.PrintGrid
674 		&& PrintColRow == rData.PrintColRow
675 		&& PrintNote == rData.PrintNote
676 		&& TopBottomDir == rData.TopBottomDir
677 		&& FirstPageNo == rData.FirstPageNo
678 		&& RowRepeatStart == rData.RowRepeatStart
679 		&& RowRepeatEnd == rData.RowRepeatEnd
680 		&& ColRepeatStart == rData.ColRepeatStart
681 		&& ColRepeatEnd == rData.ColRepeatEnd
682 		&& !memcmp( PrnZoom, rData.PrnZoom, sizeof(PrnZoom) )
683 		&& !memcmp( &PrintArea, &rData.PrintArea, sizeof(PrintArea) );
684 }
685 
686 
InsertFormat(const Sc10PageFormat & rData)687 sal_uInt16 Sc10PageCollection::InsertFormat( const Sc10PageFormat& rData )
688 {
689 	for (sal_uInt16 i=0; i<nCount; i++)
690 		if (At(i)->aPageFormat == rData)
691 			return i;
692 
693     Insert( new Sc10PageData(rData) );
694 
695 	return nCount-1;
696 }
697 
698 
GetMixedCol(const sal_uInt8 nB,const sal_uInt8 nF,const sal_uInt16 nFak)699 static inline sal_uInt8 GetMixedCol( const sal_uInt8 nB, const sal_uInt8 nF, const sal_uInt16 nFak )
700 {
701 	sal_Int32		nT = nB - nF;
702 				nT *= ( sal_Int32 ) nFak;
703 				nT /= 0xFFFF;
704 				nT += nF;
705 	return ( sal_uInt8 ) nT;
706 }
GetMixedColor(const Color & rFore,const Color & rBack,sal_uInt16 nFact)707 static inline Color GetMixedColor( const Color& rFore, const Color& rBack, sal_uInt16 nFact )
708 {
709 	return Color(	GetMixedCol( rBack.GetRed(), rFore.GetRed(), nFact ),
710 					GetMixedCol( rBack.GetGreen(), rFore.GetGreen(), nFact ),
711 					GetMixedCol( rBack.GetBlue(), rFore.GetBlue(), nFact ) );
712 }
713 
714 
PutToDoc(ScDocument * pDoc)715 void Sc10PageCollection::PutToDoc( ScDocument* pDoc )
716 {
717 	ScStyleSheetPool* pStylePool = pDoc->GetStyleSheetPool();
718 	EditEngine aEditEngine( pDoc->GetEnginePool() );
719 	EditTextObject* pEmptyObject = aEditEngine.CreateTextObject();
720 
721 	for (sal_uInt16 i=0; i<nCount; i++)
722 	{
723 		Sc10PageFormat* pPage = &At(i)->aPageFormat;
724 
725 		pPage->Width = (short) ( pPage->Width * ( 72.0 / 72.27 ) + 0.5 );
726 		pPage->Height = (short) ( pPage->Height * ( 72.0 / 72.27 ) + 0.5 );
727 		pPage->Top = (short) ( pPage->Top * ( 72.0 / 72.27 ) + 0.5 );
728 		pPage->Bottom = (short) ( pPage->Bottom * ( 72.0 / 72.27 ) + 0.5 );
729 		pPage->Left = (short) ( pPage->Left * ( 72.0 / 72.27 ) + 0.5 );
730 		pPage->Right = (short) ( pPage->Right * ( 72.0 / 72.27 ) + 0.5 );
731 		pPage->Head = (short) ( pPage->Head * ( 72.0 / 72.27 ) + 0.5 );
732 		pPage->Foot = (short) ( pPage->Foot * ( 72.0 / 72.27 ) + 0.5 );
733 
734 		String aName = lcl_MakeOldPageStyleFormatName( i );
735 
736 		ScStyleSheet* pSheet = (ScStyleSheet*) &pStylePool->Make( aName,
737 									SFX_STYLE_FAMILY_PAGE,
738 									SFXSTYLEBIT_USERDEF | SCSTYLEBIT_STANDARD );
739         // #i68483# set page style name at sheet...
740         pDoc->SetPageStyle( static_cast< SCTAB >( i ), aName );
741 
742 		SfxItemSet* pSet = &pSheet->GetItemSet();
743 
744 		for (sal_uInt16 nHeadFoot=0; nHeadFoot<2; nHeadFoot++)
745 		{
746 			Sc10HeadFootLine* pHeadFootLine = nHeadFoot ? &pPage->FootLine : &pPage->HeadLine;
747 
748 			SfxItemSet aEditAttribs(aEditEngine.GetEmptyItemSet());
749             FontFamily eFam = FAMILY_DONTKNOW;
750 			switch (pPage->HeadLine.LogFont.lfPitchAndFamily & 0xF0)
751 			{
752 				case ffDontCare:	eFam = FAMILY_DONTKNOW;		break;
753 				case ffRoman:		eFam = FAMILY_ROMAN;		break;
754 				case ffSwiss:		eFam = FAMILY_SWISS;		break;
755 				case ffModern:		eFam = FAMILY_MODERN;		break;
756 				case ffScript:		eFam = FAMILY_SCRIPT;		break;
757 				case ffDecorative:	eFam = FAMILY_DECORATIVE;	break;
758 				default:	eFam = FAMILY_DONTKNOW;		break;
759 			}
760 			aEditAttribs.Put(	SvxFontItem(
761 									eFam,
762                                     SC10TOSTRING( pHeadFootLine->LogFont.lfFaceName ), EMPTY_STRING,
763                                     PITCH_DONTKNOW, RTL_TEXTENCODING_DONTKNOW, EE_CHAR_FONTINFO ),
764 								EE_CHAR_FONTINFO );
765             aEditAttribs.Put(   SvxFontHeightItem( Abs( pHeadFootLine->LogFont.lfHeight ), 100, EE_CHAR_FONTHEIGHT ),
766 								EE_CHAR_FONTHEIGHT);
767 
768 			Sc10Color nColor = pHeadFootLine->TextColor;
769 			Color TextColor( nColor.Red, nColor.Green, nColor.Blue );
770             aEditAttribs.Put(SvxColorItem(TextColor, EE_CHAR_COLOR), EE_CHAR_COLOR);
771 			// FontAttr
772 			if (pHeadFootLine->LogFont.lfWeight != fwNormal)
773                 aEditAttribs.Put(SvxWeightItem(WEIGHT_BOLD, EE_CHAR_WEIGHT), EE_CHAR_WEIGHT);
774 			if (pHeadFootLine->LogFont.lfItalic != 0)
775                 aEditAttribs.Put(SvxPostureItem(ITALIC_NORMAL, EE_CHAR_ITALIC), EE_CHAR_ITALIC);
776 			if (pHeadFootLine->LogFont.lfUnderline != 0)
777                 aEditAttribs.Put(SvxUnderlineItem(UNDERLINE_SINGLE, EE_CHAR_UNDERLINE), EE_CHAR_UNDERLINE);
778 			if (pHeadFootLine->LogFont.lfStrikeOut != 0)
779                 aEditAttribs.Put(SvxCrossedOutItem(STRIKEOUT_SINGLE, EE_CHAR_STRIKEOUT), EE_CHAR_STRIKEOUT);
780 			String aText( pHeadFootLine->Title, DEFCHARSET );
781 			aEditEngine.SetText( aText );
782 			aEditEngine.QuickSetAttribs( aEditAttribs, ESelection( 0, 0, 0, aText.Len() ) );
783 
784 			EditTextObject* pObject = aEditEngine.CreateTextObject();
785 			ScPageHFItem aHeaderItem(nHeadFoot ? ATTR_PAGE_FOOTERRIGHT : ATTR_PAGE_HEADERRIGHT);
786 			switch (pHeadFootLine->HorJustify)
787 			{
788 				case hjCenter:
789 					aHeaderItem.SetLeftArea(*pEmptyObject);
790 					aHeaderItem.SetCenterArea(*pObject);
791 					aHeaderItem.SetRightArea(*pEmptyObject);
792 					break;
793 				case hjRight:
794 					aHeaderItem.SetLeftArea(*pEmptyObject);
795 					aHeaderItem.SetCenterArea(*pEmptyObject);
796 					aHeaderItem.SetRightArea(*pObject);
797 					break;
798 				default:
799 					aHeaderItem.SetLeftArea(*pObject);
800 					aHeaderItem.SetCenterArea(*pEmptyObject);
801 					aHeaderItem.SetRightArea(*pEmptyObject);
802 					break;
803 			}
804 			delete pObject;
805 			pSet->Put( aHeaderItem );
806 
807 			SfxItemSet aSetItemItemSet( *pDoc->GetPool(),
808 								  ATTR_BACKGROUND, ATTR_BACKGROUND,
809 								  ATTR_BORDER, ATTR_SHADOW,
810 								  ATTR_PAGE_SIZE, ATTR_PAGE_SIZE,
811 								  ATTR_LRSPACE, ATTR_ULSPACE,
812 								  ATTR_PAGE_ON, ATTR_PAGE_SHARED,
813 								  0 );
814 			nColor = pHeadFootLine->BackColor;
815 			Color aBColor( nColor.Red, nColor.Green, nColor.Blue );
816 			nColor = pHeadFootLine->RasterColor;
817 			Color aRColor( nColor.Red, nColor.Green, nColor.Blue );
818 
819 			sal_uInt16 nFact;
820 			sal_Bool		bSwapCol = sal_False;
821 			switch (pHeadFootLine->Raster)
822 			{
823 			   case raNone:		nFact = 0xffff; bSwapCol = sal_True; break;
824 			   case raGray12:	nFact = (0xffff / 100) * 12;	break;
825 			   case raGray25:	nFact = (0xffff / 100) * 25;	break;
826 			   case raGray50:	nFact = (0xffff / 100) * 50;	break;
827 			   case raGray75:	nFact = (0xffff / 100) * 75;	break;
828 			   default:	nFact = 0xffff;
829 			}
830 			if( bSwapCol )
831                 aSetItemItemSet.Put( SvxBrushItem( GetMixedColor( aBColor, aRColor, nFact ), ATTR_BACKGROUND ) );
832 			else
833                 aSetItemItemSet.Put( SvxBrushItem( GetMixedColor( aRColor, aBColor, nFact ), ATTR_BACKGROUND ) );
834 
835 			if (pHeadFootLine->Frame != 0)
836 			{
837 			  sal_uInt16 nLeft = 0;
838 			  sal_uInt16 nTop = 0;
839 			  sal_uInt16 nRight = 0;
840 			  sal_uInt16 nBottom = 0;
841 			  sal_uInt16 fLeft   = (pHeadFootLine->Frame & 0x000F);
842 			  sal_uInt16 fTop    = (pHeadFootLine->Frame & 0x00F0) / 0x0010;
843 			  sal_uInt16 fRight  = (pHeadFootLine->Frame & 0x0F00) / 0x0100;
844 			  sal_uInt16 fBottom = (pHeadFootLine->Frame & 0xF000) / 0x1000;
845 			  if (fLeft > 1)
846 				nLeft = 50;
847 			  else if (fLeft > 0)
848 				nLeft = 20;
849 			  if (fTop > 1)
850 				nTop = 50;
851 			  else if (fTop > 0)
852 				nTop = 20;
853 			  if (fRight > 1)
854 				nRight = 50;
855 			  else if (fRight > 0)
856 				nRight = 20;
857 			  if (fBottom > 1)
858 				nBottom = 50;
859 			  else if (fBottom > 0)
860 				nBottom = 20;
861 			  Color  ColorLeft(COL_BLACK);
862 			  Color  ColorTop(COL_BLACK);
863 			  Color  ColorRight(COL_BLACK);
864 			  Color  ColorBottom(COL_BLACK);
865 			  sal_uInt16 cLeft   = (pHeadFootLine->FrameColor & 0x000F);
866 			  sal_uInt16 cTop    = (pHeadFootLine->FrameColor & 0x00F0) >> 4;
867 			  sal_uInt16 cRight  = (pHeadFootLine->FrameColor & 0x0F00) >> 8;
868 			  sal_uInt16 cBottom = (pHeadFootLine->FrameColor & 0xF000) >> 12;
869 			  lcl_ChangeColor(cLeft, ColorLeft);
870 			  lcl_ChangeColor(cTop, ColorTop);
871 			  lcl_ChangeColor(cRight, ColorRight);
872 			  lcl_ChangeColor(cBottom, ColorBottom);
873 			  SvxBorderLine aLine;
874               SvxBoxItem aBox( ATTR_BORDER );
875 			  aLine.SetOutWidth(nLeft);
876 			  aLine.SetColor(ColorLeft);
877 			  aBox.SetLine(&aLine, BOX_LINE_LEFT);
878 			  aLine.SetOutWidth(nTop);
879 			  aLine.SetColor(ColorTop);
880 			  aBox.SetLine(&aLine, BOX_LINE_TOP);
881 			  aLine.SetOutWidth(nRight);
882 			  aLine.SetColor(ColorRight);
883 			  aBox.SetLine(&aLine, BOX_LINE_RIGHT);
884 			  aLine.SetOutWidth(nBottom);
885 			  aLine.SetColor(ColorBottom);
886 			  aBox.SetLine(&aLine, BOX_LINE_BOTTOM);
887 
888 			  aSetItemItemSet.Put(aBox);
889 			}
890 
891 			pSet->Put( SvxULSpaceItem( 0, 0, ATTR_ULSPACE ) );
892 
893 			if (nHeadFoot==0)
894 				aSetItemItemSet.Put( SvxSizeItem( ATTR_PAGE_SIZE, Size( 0, pPage->Top - pPage->Head ) ) );
895 			else
896 				aSetItemItemSet.Put( SvxSizeItem( ATTR_PAGE_SIZE, Size( 0, pPage->Bottom - pPage->Foot ) ) );
897 
898 			aSetItemItemSet.Put(SfxBoolItem( ATTR_PAGE_ON, sal_True ));
899 			aSetItemItemSet.Put(SfxBoolItem( ATTR_PAGE_DYNAMIC, sal_False ));
900 			aSetItemItemSet.Put(SfxBoolItem( ATTR_PAGE_SHARED, sal_True ));
901 
902 			pSet->Put( SvxSetItem( nHeadFoot ? ATTR_PAGE_FOOTERSET : ATTR_PAGE_HEADERSET,
903 									aSetItemItemSet ) );
904 		}
905 
906 		SvxPageItem aPageItem(ATTR_PAGE);
907 		aPageItem.SetPageUsage( SVX_PAGE_ALL );
908 		aPageItem.SetLandscape( pPage->Orientation != 1 );
909 		aPageItem.SetNumType( SVX_ARABIC );
910 		pSet->Put(aPageItem);
911 
912 		pSet->Put(SvxLRSpaceItem( pPage->Left, pPage->Right, 0,0, ATTR_LRSPACE ));
913 		pSet->Put(SvxULSpaceItem( pPage->Top, pPage->Bottom, ATTR_ULSPACE ));
914 
915 		pSet->Put(SfxBoolItem( ATTR_PAGE_HORCENTER, pPage->HorCenter ));
916 		pSet->Put(SfxBoolItem( ATTR_PAGE_VERCENTER, pPage->VerCenter ));
917 
918 		//----------------
919 		// Area-Parameter:
920 		//----------------
921 		{
922 			ScRange* pRepeatRow = NULL;
923 			ScRange* pRepeatCol = NULL;
924 
925 			if ( pPage->ColRepeatStart >= 0 )
926 				pRepeatCol = new ScRange( static_cast<SCCOL> (pPage->ColRepeatStart), 0, 0 );
927 			if ( pPage->RowRepeatStart >= 0 )
928 				pRepeatRow = new ScRange( 0, static_cast<SCROW> (pPage->RowRepeatStart), 0 );
929 
930 
931 			if ( pRepeatRow || pRepeatCol )
932 			{
933 				//
934 				// an allen Tabellen setzen
935 				//
936                 for ( SCTAB nTab = 0, nTabCount = pDoc->GetTableCount(); nTab < nTabCount; ++nTab )
937 				{
938                     pDoc->SetRepeatColRange( nTab, pRepeatCol );
939                     pDoc->SetRepeatRowRange( nTab, pRepeatRow );
940 				}
941 			}
942 
943 			delete pRepeatRow;
944 			delete pRepeatCol;
945 		}
946 
947 		//-----------------
948 		// Table-Parameter:
949 		//-----------------
950 		pSet->Put( SfxBoolItem( ATTR_PAGE_NOTES,   pPage->PrintNote ) );
951 		pSet->Put( SfxBoolItem( ATTR_PAGE_GRID,    pPage->PrintGrid ) );
952 		pSet->Put( SfxBoolItem( ATTR_PAGE_HEADERS, pPage->PrintColRow ) );
953 		pSet->Put( SfxBoolItem( ATTR_PAGE_TOPDOWN, pPage->TopBottomDir ) );
954 		pSet->Put( ScViewObjectModeItem( ATTR_PAGE_CHARTS,   VOBJ_MODE_SHOW ) );
955 		pSet->Put( ScViewObjectModeItem( ATTR_PAGE_OBJECTS,  VOBJ_MODE_SHOW ) );
956 		pSet->Put( ScViewObjectModeItem( ATTR_PAGE_DRAWINGS, VOBJ_MODE_SHOW ) );
957 		pSet->Put( SfxUInt16Item( ATTR_PAGE_SCALE,
958 								  (sal_uInt16)( lcl_PascalToDouble( pPage->PrnZoom ) * 100 ) ) );
959 		pSet->Put( SfxUInt16Item( ATTR_PAGE_FIRSTPAGENO, 1 ) );
960 
961 		pSet->Put( SvxSizeItem( ATTR_PAGE_SIZE, Size( pPage->Width, pPage->Height ) ) );
962 	}
963 
964 	delete pEmptyObject;
965 }
966 
967 
Clone() const968 ScDataObject* Sc10PageData::Clone() const
969 {
970 	return new Sc10PageData(aPageFormat);
971 }
972 
973 
974 //--------------------------------------------
975 // Import
976 //--------------------------------------------
977 
978 
Sc10Import(SvStream & rStr,ScDocument * pDocument)979 Sc10Import::Sc10Import(SvStream& rStr, ScDocument* pDocument ) :
980 	rStream             (rStr),
981 	pDoc                (pDocument),
982 	pFontCollection     (NULL),
983 	pNameCollection     (NULL),
984 	pPatternCollection  (NULL),
985 	pDataBaseCollection (NULL),
986 	nError              (0),
987 	nShowTab			(0)
988 {
989 	pPrgrsBar = NULL;
990 }
991 
992 
~Sc10Import()993 Sc10Import::~Sc10Import()
994 {
995 	pDoc->CalcAfterLoad();
996 	pDoc->UpdateAllCharts();
997 
998 	delete pFontCollection;
999 	delete pNameCollection;
1000 	delete pPatternCollection;
1001 	delete pDataBaseCollection;
1002 
1003 	DBG_ASSERT( pPrgrsBar == NULL,
1004 		"*Sc10Import::Sc10Import(): Progressbar lebt noch!?" );
1005 }
1006 
1007 
Import()1008 sal_uLong Sc10Import::Import()
1009 {
1010     pPrgrsBar = new ScfStreamProgressBar( rStream, pDoc->GetDocumentShell() );
1011 
1012 	ScDocOptions aOpt = pDoc->GetDocOptions();
1013 	aOpt.SetDate( 1, 1, 1900 );
1014 	aOpt.SetYear2000( 18 + 1901 );		// ab SO51 src513e vierstellig
1015 	pDoc->SetDocOptions( aOpt );
1016 	pDoc->GetFormatTable()->ChangeNullDate( 1, 1, 1900 );
1017 
1018     LoadFileHeader();                           pPrgrsBar->Progress();
1019     if (!nError) { LoadFileInfo();              pPrgrsBar->Progress(); }
1020     if (!nError) { LoadEditStateInfo();         pPrgrsBar->Progress(); }
1021     if (!nError) { LoadProtect();               pPrgrsBar->Progress(); }
1022     if (!nError) { LoadViewColRowBar();         pPrgrsBar->Progress(); }
1023     if (!nError) { LoadScrZoom();               pPrgrsBar->Progress(); }
1024     if (!nError) { LoadPalette();               pPrgrsBar->Progress(); }
1025     if (!nError) { LoadFontCollection();        pPrgrsBar->Progress(); }
1026     if (!nError) { LoadNameCollection();        pPrgrsBar->Progress(); }
1027     if (!nError) { LoadPatternCollection();     pPrgrsBar->Progress(); }
1028     if (!nError) { LoadDataBaseCollection();    pPrgrsBar->Progress(); }
1029     if (!nError) { LoadTables();                pPrgrsBar->Progress(); }
1030     if (!nError) { LoadObjects();               pPrgrsBar->Progress(); }
1031     if (!nError) { ImportNameCollection();      pPrgrsBar->Progress(); }
1032 	pDoc->SetViewOptions( aSc30ViewOpt );
1033 
1034 #ifdef DBG_UTIL
1035 	if (nError)
1036 	{
1037 		DBG_ERROR( ByteString::CreateFromInt32( nError ).GetBuffer() );
1038 	}
1039 #endif
1040 
1041 	delete pPrgrsBar;
1042 #ifdef DBG_UTIL
1043 	pPrgrsBar = NULL;
1044 #endif
1045 
1046 	return nError;
1047 }
1048 
1049 
LoadFileHeader()1050 void Sc10Import::LoadFileHeader()
1051 {
1052 	Sc10FileHeader FileHeader;
1053 	lcl_ReadFileHeader(rStream, FileHeader);
1054 
1055 	nError = rStream.GetError();
1056 	if ( nError == 0 )
1057 	{
1058 		sal_Char Sc10CopyRight[32];
1059 		strcpy(Sc10CopyRight, "Blaise-Tabelle");    // #100211# - checked
1060 		Sc10CopyRight[14] = 10;
1061 		Sc10CopyRight[15] = 13;
1062 		Sc10CopyRight[16] = 0;
1063 		if ((strcmp(FileHeader.CopyRight, Sc10CopyRight) != 0)
1064 			|| (FileHeader.Version < 101)
1065 			|| (FileHeader.Version > 102))
1066 			nError = errUnknownFormat;
1067 	}
1068 }
1069 
1070 
LoadFileInfo()1071 void Sc10Import::LoadFileInfo()
1072 {
1073 	Sc10FileInfo FileInfo;
1074 	rStream.Read(&FileInfo, sizeof(FileInfo));
1075 
1076 	nError = rStream.GetError();
1077 	// Achtung Info Uebertragen
1078 }
1079 
1080 
1081 
LoadEditStateInfo()1082 void Sc10Import::LoadEditStateInfo()
1083 {
1084 	Sc10EditStateInfo EditStateInfo;
1085 	rStream.Read(&EditStateInfo, sizeof(EditStateInfo));
1086 
1087 	nError = rStream.GetError();
1088 	nShowTab = static_cast<SCTAB>(EditStateInfo.DeltaZ);
1089 	// Achtung Cursorposition und Offset der Tabelle Uebertragen (soll man das machen??)
1090 }
1091 
1092 
LoadProtect()1093 void Sc10Import::LoadProtect()
1094 {
1095 	lcl_ReadSheetProtect(rStream, SheetProtect);
1096 	nError = rStream.GetError();
1097 
1098     ScDocProtection aProtection;
1099     aProtection.setProtected(static_cast<bool>(SheetProtect.Protect));
1100     aProtection.setPassword(SC10TOSTRING(SheetProtect.PassWord));
1101     pDoc->SetDocProtection(&aProtection);
1102 }
1103 
1104 
LoadViewColRowBar()1105 void Sc10Import::LoadViewColRowBar()
1106 {
1107 	sal_uInt8 ViewColRowBar;
1108 	rStream >> ViewColRowBar;
1109 	nError = rStream.GetError();
1110 	aSc30ViewOpt.SetOption( VOPT_HEADER, (sal_Bool)ViewColRowBar );
1111 }
1112 
1113 
LoadScrZoom()1114 void Sc10Import::LoadScrZoom()
1115 {
1116 	// Achtung Zoom ist leider eine 6Byte TP real Zahl (keine Ahnung wie die Umzusetzen ist)
1117 	sal_Char cZoom[6];
1118 	rStream.Read(cZoom, sizeof(cZoom));
1119 	nError = rStream.GetError();
1120 }
1121 
1122 
LoadPalette()1123 void Sc10Import::LoadPalette()
1124 {
1125 	lcl_ReadPalette(rStream, TextPalette);
1126 	lcl_ReadPalette(rStream, BackPalette);
1127 	lcl_ReadPalette(rStream, RasterPalette);
1128 	lcl_ReadPalette(rStream, FramePalette);
1129 
1130 	nError = rStream.GetError();
1131 }
1132 
1133 
LoadFontCollection()1134 void Sc10Import::LoadFontCollection()
1135 {
1136 	pFontCollection = new Sc10FontCollection(rStream);
1137     if (!nError)
1138         nError = pFontCollection->GetError();
1139 }
1140 
1141 
LoadNameCollection()1142 void Sc10Import::LoadNameCollection()
1143 {
1144 	pNameCollection = new Sc10NameCollection(rStream);
1145     if (!nError)
1146         nError = pNameCollection->GetError();
1147 }
1148 
1149 
ImportNameCollection()1150 void Sc10Import::ImportNameCollection()
1151 {
1152 	ScRangeName*		pRN = pDoc->GetRangeName();
1153 
1154 	for (sal_uInt16 i = 0; i < pNameCollection->GetCount(); i++)
1155 	{
1156 		Sc10NameData*	pName = pNameCollection->At( i );
1157 		pRN->Insert( new ScRangeData(	pDoc,
1158 										SC10TOSTRING( pName->Name ),
1159 										SC10TOSTRING( pName->Reference ) ) );
1160 	}
1161 }
1162 
1163 
LoadPatternCollection()1164 void Sc10Import::LoadPatternCollection()
1165 {
1166 	pPatternCollection = new Sc10PatternCollection( rStream );
1167     if (!nError)
1168         nError = pPatternCollection->GetError();
1169     if (nError == errOutOfMemory)
1170         return;     // hopeless
1171 	ScStyleSheetPool* pStylePool = pDoc->GetStyleSheetPool();
1172 	for( sal_uInt16 i = 0 ; i < pPatternCollection->GetCount() ; i++ )
1173 	{
1174 		Sc10PatternData* pPattern = pPatternCollection->At( i );
1175 		String aName( pPattern->Name, DEFCHARSET );
1176 		SfxStyleSheetBase* pStyle = pStylePool->Find( aName, SFX_STYLE_FAMILY_PARA );
1177 		if( pStyle == NULL )
1178 			pStylePool->Make( aName, SFX_STYLE_FAMILY_PARA );
1179 		else
1180 		{
1181 			pPattern->Name[ 27 ] = 0;
1182 			strcat( pPattern->Name, "_Old" );       // #100211# - checked
1183 			aName = SC10TOSTRING( pPattern->Name );
1184 			pStylePool->Make( aName, SFX_STYLE_FAMILY_PARA );
1185 		}
1186 		pStyle = pStylePool->Find( aName, SFX_STYLE_FAMILY_PARA );
1187 		if( pStyle != NULL )
1188 		{
1189 			SfxItemSet &rItemSet = pStyle->GetItemSet();
1190 			// Font
1191 			if( ( pPattern->FormatFlags & pfFont ) == pfFont )
1192 			{
1193                 FontFamily eFam = FAMILY_DONTKNOW;
1194 				switch( pPattern->LogFont.lfPitchAndFamily & 0xF0 )
1195 				{
1196 					case ffDontCare   : eFam = FAMILY_DONTKNOW;		break;
1197 					case ffRoman      : eFam = FAMILY_ROMAN;		break;
1198 					case ffSwiss      : eFam = FAMILY_SWISS;		break;
1199 					case ffModern     : eFam = FAMILY_MODERN;		break;
1200 					case ffScript     : eFam = FAMILY_SCRIPT;		break;
1201 					case ffDecorative : eFam = FAMILY_DECORATIVE;	break;
1202 					default: eFam = FAMILY_DONTKNOW;		break;
1203 				}
1204                 rItemSet.Put( SvxFontItem( eFam, SC10TOSTRING( pPattern->LogFont.lfFaceName ), EMPTY_STRING,
1205                         PITCH_DONTKNOW, RTL_TEXTENCODING_DONTKNOW, ATTR_FONT ) );
1206                 rItemSet.Put( SvxFontHeightItem( Abs( pPattern->LogFont.lfHeight ), 100, ATTR_FONT_HEIGHT ) );
1207 				Color TextColor( COL_BLACK );
1208 				lcl_ChangeColor( ( pPattern->nColor & 0x000F ), TextColor );
1209                 rItemSet.Put( SvxColorItem( TextColor, ATTR_FONT_COLOR ) );
1210 				// FontAttr
1211 				if( pPattern->LogFont.lfWeight != fwNormal )
1212                     rItemSet.Put( SvxWeightItem( WEIGHT_BOLD, ATTR_FONT_WEIGHT ) );
1213 				if( pPattern->LogFont.lfItalic != 0 )
1214                     rItemSet.Put( SvxPostureItem( ITALIC_NORMAL, ATTR_FONT_POSTURE ) );
1215 				if( pPattern->LogFont.lfUnderline != 0 )
1216                     rItemSet.Put( SvxUnderlineItem( UNDERLINE_SINGLE, ATTR_FONT_UNDERLINE ) );
1217 				if( pPattern->LogFont.lfStrikeOut != 0 )
1218                     rItemSet.Put( SvxCrossedOutItem( STRIKEOUT_SINGLE, ATTR_FONT_CROSSEDOUT ) );
1219 			}
1220 			// Ausrichtung
1221 			if( ( pPattern->FormatFlags & pfJustify ) == pfJustify )
1222 			{
1223 				sal_uInt16 HorJustify = ( pPattern->Justify & 0x000F );
1224 				sal_uInt16 VerJustify = ( pPattern->Justify & 0x00F0 ) >> 4;
1225 				sal_uInt16 OJustify   = ( pPattern->Justify & 0x0F00 ) >> 8;
1226 				sal_uInt16 EJustify   = ( pPattern->Justify & 0xF000 ) >> 12;
1227 				if( HorJustify != 0 )
1228 					switch( HorJustify )
1229 					{
1230 						case hjLeft:
1231                             rItemSet.Put( SvxHorJustifyItem( SVX_HOR_JUSTIFY_LEFT, ATTR_HOR_JUSTIFY ) );
1232 							break;
1233 						case hjCenter:
1234                             rItemSet.Put( SvxHorJustifyItem( SVX_HOR_JUSTIFY_CENTER, ATTR_HOR_JUSTIFY ) );
1235 							break;
1236 						case hjRight:
1237                             rItemSet.Put( SvxHorJustifyItem( SVX_HOR_JUSTIFY_RIGHT, ATTR_HOR_JUSTIFY ) );
1238 							break;
1239 					}
1240 				if( VerJustify != 0 )
1241 					switch( VerJustify )
1242 					{
1243 						case vjTop:
1244                             rItemSet.Put( SvxVerJustifyItem( SVX_VER_JUSTIFY_TOP, ATTR_VER_JUSTIFY ) );
1245 							break;
1246 						case vjCenter:
1247                             rItemSet.Put( SvxVerJustifyItem( SVX_VER_JUSTIFY_CENTER, ATTR_VER_JUSTIFY ) );
1248 							break;
1249 						case vjBottom:
1250                             rItemSet.Put( SvxVerJustifyItem( SVX_VER_JUSTIFY_BOTTOM, ATTR_VER_JUSTIFY ) );
1251 							break;
1252 					}
1253 
1254 				if( ( OJustify & ojWordBreak ) == ojWordBreak )
1255 					rItemSet.Put( SfxBoolItem( sal_True ) );
1256 				if( ( OJustify & ojBottomTop ) == ojBottomTop )
1257                     rItemSet.Put( SfxInt32Item( ATTR_ROTATE_VALUE, 9000 ) );
1258 				else if( ( OJustify & ojTopBottom ) == ojTopBottom )
1259                     rItemSet.Put( SfxInt32Item( ATTR_ROTATE_VALUE, 27000 ) );
1260 
1261 				sal_Int16 Margin = Max( ( sal_uInt16 ) 20, ( sal_uInt16 ) ( EJustify * 20 ) );
1262 				if( ( ( OJustify & ojBottomTop ) == ojBottomTop ) )
1263                     rItemSet.Put( SvxMarginItem( 20, Margin, 20, Margin, ATTR_MARGIN ) );
1264 				else
1265                     rItemSet.Put( SvxMarginItem( Margin, 20, Margin, 20, ATTR_MARGIN ) );
1266 			}
1267 
1268 			// Frame
1269 			if( ( pPattern->FormatFlags & pfFrame ) == pfFrame )
1270 			{
1271 				if( pPattern->Frame != 0 )
1272 				{
1273 					sal_uInt16	nLeft	= 0;
1274 					sal_uInt16	nTop	= 0;
1275 					sal_uInt16	nRight	= 0;
1276 					sal_uInt16	nBottom	= 0;
1277 					sal_uInt16	fLeft	= ( pPattern->Frame & 0x000F );
1278 					sal_uInt16	fTop	= ( pPattern->Frame & 0x00F0 ) / 0x0010;
1279 					sal_uInt16	fRight	= ( pPattern->Frame & 0x0F00 ) / 0x0100;
1280 					sal_uInt16	fBottom	= ( pPattern->Frame & 0xF000 ) / 0x1000;
1281 
1282 					if( fLeft > 1 )
1283 						nLeft = 50;
1284 					else if( fLeft > 0 )
1285 						nLeft = 20;
1286 
1287 					if( fTop > 1 )
1288 						nTop = 50;
1289 					else if( fTop > 0 )
1290 						nTop = 20;
1291 
1292 					if( fRight > 1 )
1293 						nRight = 50;
1294 					else if( fRight > 0 )
1295 						nRight = 20;
1296 
1297 					if( fBottom > 1 )
1298 						nBottom = 50;
1299 					else if( fBottom > 0 )
1300 						nBottom = 20;
1301 
1302 					Color	ColorLeft( COL_BLACK );
1303 					Color	ColorTop( COL_BLACK );
1304 					Color	ColorRight( COL_BLACK );
1305 					Color	ColorBottom( COL_BLACK );
1306 
1307 					sal_uInt16	cLeft	= ( pPattern->FrameColor & 0x000F );
1308 					sal_uInt16	cTop	= ( pPattern->FrameColor & 0x00F0 ) >> 4;
1309 					sal_uInt16	cRight	= ( pPattern->FrameColor & 0x0F00 ) >> 8;
1310 					sal_uInt16	cBottom	= ( pPattern->FrameColor & 0xF000 ) >> 12;
1311 
1312 					lcl_ChangeColor( cLeft, ColorLeft );
1313 					lcl_ChangeColor( cTop, ColorTop );
1314 					lcl_ChangeColor( cRight, ColorRight );
1315 					lcl_ChangeColor( cBottom, ColorBottom );
1316 
1317 					SvxBorderLine	aLine;
1318                     SvxBoxItem      aBox( ATTR_BORDER );
1319 
1320 					aLine.SetOutWidth( nLeft );
1321 					aLine.SetColor( ColorLeft );
1322 					aBox.SetLine( &aLine, BOX_LINE_LEFT );
1323 					aLine.SetOutWidth( nTop );
1324 					aLine.SetColor( ColorTop );
1325 					aBox.SetLine( &aLine, BOX_LINE_TOP );
1326 					aLine.SetOutWidth( nRight );
1327 					aLine.SetColor( ColorRight );
1328 					aBox.SetLine( &aLine, BOX_LINE_RIGHT );
1329 					aLine.SetOutWidth( nBottom );
1330 					aLine.SetColor( ColorBottom );
1331 					aBox.SetLine( &aLine, BOX_LINE_BOTTOM );
1332 					rItemSet.Put( aBox );
1333 				}
1334 			}
1335 			// Raster
1336 			if( ( pPattern->FormatFlags & pfRaster ) == pfRaster )
1337 			{
1338 				if( pPattern->Raster != 0 )
1339 				{
1340 					sal_uInt16 nBColor = ( pPattern->nColor & 0x00F0 ) >> 4;
1341 					sal_uInt16 nRColor = ( pPattern->nColor & 0x0F00 ) >> 8;
1342 					Color aBColor( COL_BLACK );
1343 
1344 					lcl_ChangeColor( nBColor, aBColor );
1345 
1346 					if( nBColor == 0 )
1347 						aBColor.SetColor( COL_WHITE );
1348 					else if( nBColor == 15 )
1349 						aBColor.SetColor( COL_BLACK );
1350 
1351 					Color aRColor( COL_BLACK );
1352 					lcl_ChangeColor( nRColor, aRColor );
1353 					sal_uInt16 nFact;
1354 					sal_Bool		bSwapCol = sal_False;
1355 					sal_Bool		bSetItem = sal_True;
1356 					switch (pPattern->Raster)
1357 					{
1358 			   		case raNone:		nFact = 0xffff; bSwapCol = sal_True; bSetItem = (nBColor > 0); break;
1359 			   		case raGray12:	nFact = (0xffff / 100) * 12;	break;
1360 			   		case raGray25:	nFact = (0xffff / 100) * 25;	break;
1361 			   		case raGray50:	nFact = (0xffff / 100) * 50;	break;
1362 			   		case raGray75:	nFact = (0xffff / 100) * 75;	break;
1363 			   		default:	nFact = 0xffff; bSetItem = (nRColor < 15);
1364 					}
1365 					if ( bSetItem )
1366 					{
1367 						if( bSwapCol )
1368                             rItemSet.Put( SvxBrushItem( GetMixedColor( aBColor, aRColor, nFact ), ATTR_BACKGROUND ) );
1369 						else
1370                             rItemSet.Put( SvxBrushItem( GetMixedColor( aRColor, aBColor, nFact ), ATTR_BACKGROUND ) );
1371 					}
1372 				}
1373 			}
1374 			// ZahlenFormate
1375 			if( ( pPattern->ValueFormat.Format != 0 ) &&
1376 				( ( pPattern->FormatFlags & pfValue ) == pfValue ) )
1377 			{
1378 				sal_uLong nKey = 0;
1379 				ChangeFormat( pPattern->ValueFormat.Format, pPattern->ValueFormat.Info, nKey );
1380 				rItemSet.Put( SfxUInt32Item( ATTR_VALUE_FORMAT, ( sal_uInt32 ) nKey ) );
1381 			}
1382 
1383 			// Zellattribute (Schutz, Versteckt...)
1384 			if( ( pPattern->Flags != 0 ) &&
1385 				( ( pPattern->FormatFlags & pfProtection ) == pfProtection ) )
1386 			{
1387 				sal_Bool bProtect  = ( ( pPattern->Flags & paProtect ) == paProtect );
1388 				sal_Bool bHFormula = ( ( pPattern->Flags & paHideFormula ) == paHideFormula );
1389 				sal_Bool bHCell    = ( ( pPattern->Flags & paHideAll ) == paHideAll );
1390 				sal_Bool bHPrint   = ( ( pPattern->Flags & paHidePrint ) == paHidePrint );
1391 				rItemSet.Put( ScProtectionAttr( bProtect, bHFormula, bHCell, bHPrint ) );
1392 			}
1393 		} // if Style != 0
1394 	} // for (i = 0; i < GetCount()
1395 }
1396 
1397 
LoadDataBaseCollection()1398 void Sc10Import::LoadDataBaseCollection()
1399 {
1400 	pDataBaseCollection = new Sc10DataBaseCollection(rStream);
1401     if (!nError)
1402         nError = pDataBaseCollection->GetError();
1403     if (nError == errOutOfMemory)
1404         return;     // hopeless
1405 	for( sal_uInt16 i = 0 ; i < pDataBaseCollection->GetCount() ; i++ )
1406 	{
1407 		Sc10DataBaseData* pOldData = pDataBaseCollection->At(i);
1408 		ScDBData* pNewData = new ScDBData( SC10TOSTRING( pOldData->DataBaseRec.Name ),
1409 									( SCTAB ) pOldData->DataBaseRec.Tab,
1410 									( SCCOL ) pOldData->DataBaseRec.Block.x1,
1411 									( SCROW ) pOldData->DataBaseRec.Block.y1,
1412 									( SCCOL ) pOldData->DataBaseRec.Block.x2,
1413 									( SCROW ) pOldData->DataBaseRec.Block.y2,
1414 									sal_True,
1415 									( sal_Bool) pOldData->DataBaseRec.RowHeader );
1416 		pDoc->GetDBCollection()->Insert( pNewData );
1417 	}
1418 }
1419 
1420 
LoadTables()1421 void Sc10Import::LoadTables()
1422 {
1423 	Sc10PageCollection aPageCollection;
1424 
1425     sal_Int16 nTabCount;
1426     rStream >> nTabCount;
1427     for (sal_Int16 Tab = 0; (Tab < nTabCount) && (nError == 0); Tab++)
1428 	{
1429 		Sc10PageFormat   PageFormat;
1430 		sal_Int16            DataBaseIndex;
1431 		Sc10TableProtect TabProtect;
1432 		sal_Int16            TabNo;
1433 		sal_Char             TabName[128];
1434 		sal_uInt16           Display;
1435 		sal_uInt8             Visible;
1436 		sal_uInt16           ID;
1437 		sal_uInt16           DataCount;
1438 		sal_uInt16           DataStart;
1439 		sal_uInt16           DataEnd;
1440 		sal_uInt16           DataValue;
1441 		sal_uInt16           Count;
1442 		sal_uInt16           i;
1443 		String           aStr;	// Universal-Konvertierungs-String
1444 
1445 
1446 		lcl_ReadPageFormat(rStream, PageFormat);
1447 
1448         sal_uInt16 nAt = aPageCollection.InsertFormat(PageFormat);
1449 		String aPageName = lcl_MakeOldPageStyleFormatName( nAt );
1450 
1451 		pPrgrsBar->Progress();
1452 
1453 		rStream >> DataBaseIndex;
1454 
1455 		lcl_ReadTabProtect(rStream, TabProtect);
1456 
1457         ScTableProtection aProtection;
1458         aProtection.setProtected(static_cast<bool>(TabProtect.Protect));
1459         aProtection.setPassword(SC10TOSTRING(TabProtect.PassWord));
1460         pDoc->SetTabProtection(static_cast<SCTAB>(Tab), &aProtection);
1461 
1462 		rStream >> TabNo;
1463 
1464 		sal_uInt8 nLen;
1465 		rStream >> nLen;
1466 		rStream.Read(TabName, sizeof(TabName) - 1);
1467 		if (nLen >= sizeof(TabName))
1468 			nLen = sizeof(TabName) - 1;
1469 		TabName[nLen] = 0;
1470 
1471 		//----------------------------------------------------------
1472 		rStream >> Display;
1473 
1474 		if ( Tab == (sal_Int16)nShowTab )
1475 		{
1476 			ScVObjMode	eObjMode = VOBJ_MODE_SHOW;
1477 
1478 			aSc30ViewOpt.SetOption( VOPT_FORMULAS,	  IS_SET(dfFormula,Display) );
1479 			aSc30ViewOpt.SetOption( VOPT_NULLVALS,	  IS_SET(dfZerro,Display) );
1480 			aSc30ViewOpt.SetOption( VOPT_SYNTAX,	  IS_SET(dfSyntax,Display) );
1481 			aSc30ViewOpt.SetOption( VOPT_NOTES,		  IS_SET(dfNoteMark,Display) );
1482 			aSc30ViewOpt.SetOption( VOPT_VSCROLL,	  sal_True );
1483 			aSc30ViewOpt.SetOption( VOPT_HSCROLL,	  sal_True );
1484 			aSc30ViewOpt.SetOption( VOPT_TABCONTROLS, sal_True );
1485 			aSc30ViewOpt.SetOption( VOPT_OUTLINER,	  sal_True );
1486 			aSc30ViewOpt.SetOption( VOPT_GRID,		  IS_SET(dfGrid,Display) );
1487 
1488 			// VOPT_HEADER wird in LoadViewColRowBar() gesetzt
1489 
1490 			if ( IS_SET(dfObjectAll,Display) ) 			// Objekte anzeigen
1491 				eObjMode = VOBJ_MODE_SHOW;
1492 			else if ( IS_SET(dfObjectFrame,Display) )	// Objekte als Platzhalter
1493 				eObjMode = VOBJ_MODE_SHOW;
1494 			else if ( IS_SET(dfObjectNone,Display) )	// Objekte nicht anzeigen
1495 				eObjMode = VOBJ_MODE_HIDE;
1496 
1497 			aSc30ViewOpt.SetObjMode( VOBJ_TYPE_OLE,	  eObjMode );
1498 			aSc30ViewOpt.SetObjMode( VOBJ_TYPE_CHART, eObjMode );
1499 			aSc30ViewOpt.SetObjMode( VOBJ_TYPE_DRAW,  eObjMode );
1500 		}
1501 
1502 	/*	wofuer wird das benoetigt? Da in SC 1.0 die Anzeigeflags pro Tabelle gelten und nicht pro View
1503 		Dieses Flag in die ViewOptions eintragen bei Gelegenheit, Sollte der Stephan Olk machen
1504         sal_uInt16 nDisplayMask = 0xFFFF;
1505         sal_uInt16 nDisplayValue = 0;
1506 		if (Tab == 0)
1507 			nDisplayValue = Display;
1508 		else
1509 		{
1510 			sal_uInt16 nDiff = Display ^ nDisplayValue;
1511 			nDisplayMask &= ~nDiff;
1512 		}
1513 	*/
1514 		//--------------------------------------------------------------------
1515 		rStream >> Visible;
1516 
1517 		nError = rStream.GetError();
1518 		if (nError != 0) return;
1519 
1520 		if (TabNo == 0)
1521 			pDoc->RenameTab(static_cast<SCTAB> (TabNo), SC10TOSTRING( TabName ), sal_False);
1522 		else
1523 			pDoc->InsertTab(SC_TAB_APPEND, SC10TOSTRING( TabName ) );
1524 
1525 		pDoc->SetPageStyle( static_cast<SCTAB>(Tab), aPageName );
1526 
1527 		if (Visible == 0) pDoc->SetVisible(static_cast<SCTAB> (TabNo), sal_False);
1528 
1529 		// ColWidth
1530 		rStream >> ID;
1531 		if (ID != ColWidthID)
1532 		{
1533 			DBG_ERROR( "ColWidthID" );
1534 			nError = errUnknownID;
1535 			return;
1536 		}
1537 		rStream >> DataCount;
1538 		DataStart = 0;
1539 		for (i=0; i < DataCount; i++)
1540 		{
1541 			rStream >> DataEnd;
1542 			rStream >> DataValue;
1543 			for (SCCOL j = static_cast<SCCOL>(DataStart); j <= static_cast<SCCOL>(DataEnd); j++) pDoc->SetColWidth(j, static_cast<SCTAB> (TabNo), DataValue);
1544 			DataStart = DataEnd + 1;
1545 		}
1546 		pPrgrsBar->Progress();
1547 
1548 		// ColAttr
1549 		rStream >> ID;
1550 		if (ID != ColAttrID)
1551 		{
1552 			DBG_ERROR( "ColAttrID" );
1553 			nError = errUnknownID;
1554 			return;
1555 		}
1556 
1557 		rStream >> DataCount;
1558 		DataStart = 0;
1559 		for (i=0; i < DataCount; i++)
1560 		{
1561 			rStream >> DataEnd;
1562 			rStream >> DataValue;
1563 			if (DataValue != 0)
1564 			{
1565 				bool bPageBreak   = ((DataValue & crfSoftBreak) == crfSoftBreak);
1566 				bool bManualBreak = ((DataValue & crfHardBreak) == crfHardBreak);
1567 				bool bHidden = ((DataValue & crfHidden) == crfHidden);
1568                 for (SCCOL k = static_cast<SCCOL>(DataStart); k <= static_cast<SCCOL>(DataEnd); k++)
1569                 {
1570 					pDoc->SetColHidden(k, k, static_cast<SCTAB>(TabNo), bHidden);
1571                     pDoc->SetColBreak(k, static_cast<SCTAB> (TabNo), bPageBreak, bManualBreak);
1572                 }
1573 			}
1574 			DataStart = DataEnd + 1;
1575 		}
1576 		pPrgrsBar->Progress();
1577 
1578 		// RowHeight
1579 		rStream >> ID;
1580 		if (ID != RowHeightID)
1581 		{
1582 			DBG_ERROR( "RowHeightID" );
1583 			nError = errUnknownID;
1584 			return;
1585 		}
1586 
1587 		rStream >> DataCount;
1588 		DataStart = 0;
1589 		for (i=0; i < DataCount; i++)
1590 		{
1591 			rStream >> DataEnd;
1592 			rStream >> DataValue;
1593 			pDoc->SetRowHeightRange(static_cast<SCROW> (DataStart), static_cast<SCROW> (DataEnd), static_cast<SCTAB> (TabNo), DataValue);
1594 			DataStart = DataEnd + 1;
1595 		}
1596 		pPrgrsBar->Progress();
1597 
1598 		// RowAttr
1599 		rStream >> ID;
1600 		if (ID != RowAttrID)
1601 		{
1602 			DBG_ERROR( "RowAttrID" );
1603 			nError = errUnknownID;
1604 			return;
1605 		}
1606 
1607 		rStream >> DataCount;
1608 		DataStart = 0;
1609 		for (i=0; i < DataCount; i++)
1610 		{
1611 			rStream >> DataEnd;
1612 			rStream >> DataValue;
1613 			if (DataValue != 0)
1614 			{
1615 				bool bPageBreak   = ((DataValue & crfSoftBreak) == crfSoftBreak);
1616 				bool bManualBreak = ((DataValue & crfHardBreak) == crfHardBreak);
1617                 bool bHidden      = ((DataValue & crfHidden) == crfHidden);
1618                 for (SCROW l = static_cast<SCROW>(DataStart); l <= static_cast<SCROW>(DataEnd); l++)
1619                 {
1620                     pDoc->SetRowHidden(l, l, static_cast<SCTAB> (TabNo), bHidden);
1621                     pDoc->SetRowBreak(l, static_cast<SCTAB> (TabNo), bPageBreak, bManualBreak);
1622                 }
1623 			}
1624 			DataStart = DataEnd + 1;
1625 		}
1626 		pPrgrsBar->Progress();
1627 
1628 		// DataTable
1629 		rStream >> ID;
1630 		if (ID != TableID)
1631 		{
1632 			DBG_ERROR( "TableID" );
1633 			nError = errUnknownID;
1634 			return;
1635 		}
1636 		for (SCCOL Col = 0; (Col <= SC10MAXCOL) && (nError == 0); Col++)
1637 		{
1638 			rStream >> Count;
1639 			nError = rStream.GetError();
1640 			if ((Count != 0) && (nError == 0))
1641 				LoadCol(Col, static_cast<SCTAB> (TabNo));
1642 		}
1643 		DBG_ASSERT( nError == 0, "Stream" );
1644 	}
1645 	pPrgrsBar->Progress();
1646 
1647 	aPageCollection.PutToDoc( pDoc );
1648 }
1649 
1650 
LoadCol(SCCOL Col,SCTAB Tab)1651 void Sc10Import::LoadCol(SCCOL Col, SCTAB Tab)
1652 {
1653 	LoadColAttr(Col, Tab);
1654 
1655 	sal_uInt16 CellCount;
1656 	sal_uInt8   CellType;
1657 	sal_uInt16 Row;
1658 	rStream >> CellCount;
1659     SCROW nScCount = static_cast< SCROW >( CellCount );
1660     if (nScCount > MAXROW) nError = errUnknownFormat;
1661 	for (sal_uInt16 i = 0; (i < CellCount) && (nError == 0); i++)
1662 	{
1663 		rStream >> CellType;
1664 		rStream >> Row;
1665 		nError = rStream.GetError();
1666 		if (nError == 0)
1667 		{
1668 			switch (CellType)
1669 			{
1670 				case ctValue :
1671 				{
1672 					const SfxPoolItem* pValueFormat = pDoc->GetAttr(Col, static_cast<SCROW> (Row), Tab, ATTR_VALUE_FORMAT);
1673 					sal_uLong nFormat = ((SfxUInt32Item*)pValueFormat)->GetValue();
1674                     double Value = ScfTools::ReadLongDouble(rStream);
1675 
1676 					// Achtung hier ist eine Anpassung Notwendig wenn Ihr das Basisdatum aendert
1677 					// In StarCalc 1.0 entspricht 0 dem 01.01.1900
1678 					// if ((nFormat >= 30) && (nFormat <= 35))
1679 					// Value += 0;
1680 					if ((nFormat >= 40) && (nFormat <= 45))
1681 						Value /= 86400.0;
1682 					pDoc->SetValue(Col, static_cast<SCROW> (Row), Tab, Value);
1683 					break;
1684 				}
1685 				case ctString :
1686 				{
1687 					sal_uInt8 Len;
1688 					sal_Char s[256];
1689 					rStream >> Len;
1690 					rStream.Read(s, Len);
1691 					s[Len] = 0;
1692 
1693 					pDoc->SetString( Col, static_cast<SCROW> (Row), Tab, SC10TOSTRING( s ) );
1694 					break;
1695 				}
1696 				case ctFormula :
1697 				{
1698                     /*double Value =*/ ScfTools::ReadLongDouble(rStream);
1699 					sal_uInt8 Len;
1700 					sal_Char s[256+1];
1701 					rStream >> Len;
1702 					rStream.Read(&s[1], Len);
1703 					s[0] = '=';
1704 					s[Len + 1] = 0;
1705 					ScFormulaCell* pCell = new ScFormulaCell( pDoc, ScAddress( Col, static_cast<SCROW> (Row), Tab ) );
1706 					pCell->SetHybridFormula( SC10TOSTRING( s ),formula::FormulaGrammar::GRAM_NATIVE );
1707 					pDoc->PutCell( Col, static_cast<SCROW> (Row), Tab, pCell, (sal_Bool)sal_True );
1708 					break;
1709 				}
1710 				case ctNote :
1711 					break;
1712 				default :
1713 					nError = errUnknownFormat;
1714 					break;
1715 			}
1716 			sal_uInt16 NoteLen;
1717 			rStream >> NoteLen;
1718 			if (NoteLen != 0)
1719 			{
1720 				sal_Char* pNote = new sal_Char[NoteLen+1];
1721 				rStream.Read(pNote, NoteLen);
1722 				pNote[NoteLen] = 0;
1723                 String aNoteText( SC10TOSTRING(pNote));
1724                 delete [] pNote;
1725                 ScAddress aPos( Col, static_cast<SCROW>(Row), Tab );
1726                 ScNoteUtil::CreateNoteFromString( *pDoc, aPos, aNoteText, false, false );
1727 			}
1728 		}
1729 		pPrgrsBar->Progress();
1730 	}
1731 }
1732 
1733 
LoadColAttr(SCCOL Col,SCTAB Tab)1734 void Sc10Import::LoadColAttr(SCCOL Col, SCTAB Tab)
1735 {
1736 	Sc10ColAttr aFont;
1737 	Sc10ColAttr aAttr;
1738 	Sc10ColAttr aJustify;
1739 	Sc10ColAttr aFrame;
1740 	Sc10ColAttr aRaster;
1741 	Sc10ColAttr aValue;
1742 	Sc10ColAttr aColor;
1743 	Sc10ColAttr aFrameColor;
1744 	Sc10ColAttr aFlag;
1745 	Sc10ColAttr aPattern;
1746 
1747 	if (nError == 0) LoadAttr(aFont);
1748 	if (nError == 0) LoadAttr(aAttr);
1749 	if (nError == 0) LoadAttr(aJustify);
1750 	if (nError == 0) LoadAttr(aFrame);
1751 	if (nError == 0) LoadAttr(aRaster);
1752 	if (nError == 0) LoadAttr(aValue);
1753 	if (nError == 0) LoadAttr(aColor);
1754 	if (nError == 0) LoadAttr(aFrameColor);
1755 	if (nError == 0) LoadAttr(aFlag);
1756 	if (nError == 0) LoadAttr(aPattern);
1757 
1758 	if (nError == 0)
1759 	{
1760 		SCROW nStart;
1761 		SCROW nEnd;
1762 		sal_uInt16 i;
1763 		sal_uInt16 nLimit;
1764         sal_uInt16 nValue1;
1765 		Sc10ColData *pColData;
1766 
1767 		// Font (Name, Groesse)
1768 		nStart = 0;
1769 		nEnd = 0;
1770 		nLimit = aFont.Count;
1771 		pColData = aFont.pData;
1772 		for( i = 0 ; i < nLimit ; i++, pColData++ )
1773 		{
1774 			nEnd = static_cast<SCROW>(pColData->Row);
1775 			if ((nStart <= nEnd) && (pColData->Value))
1776 			{
1777                 FontFamily eFam = FAMILY_DONTKNOW;
1778 				Sc10FontData* pFont = pFontCollection->At(pColData->Value);
1779                 if (pFont)
1780                 {
1781                     switch (pFont->PitchAndFamily & 0xF0)
1782                     {
1783                         case ffDontCare   : eFam = FAMILY_DONTKNOW;		break;
1784                         case ffRoman      : eFam = FAMILY_ROMAN;		break;
1785                         case ffSwiss      : eFam = FAMILY_SWISS;		break;
1786                         case ffModern     : eFam = FAMILY_MODERN;		break;
1787                         case ffScript     : eFam = FAMILY_SCRIPT;		break;
1788                         case ffDecorative : eFam = FAMILY_DECORATIVE;	break;
1789                         default: eFam = FAMILY_DONTKNOW;		break;
1790                     }
1791                     ScPatternAttr aScPattern(pDoc->GetPool());
1792                     aScPattern.GetItemSet().Put(SvxFontItem(eFam, SC10TOSTRING( pFont->FaceName ), EMPTY_STRING,
1793                         PITCH_DONTKNOW, RTL_TEXTENCODING_DONTKNOW, ATTR_FONT ));
1794                     aScPattern.GetItemSet().Put(SvxFontHeightItem(Abs(pFont->Height), 100, ATTR_FONT_HEIGHT ));
1795                     pDoc->ApplyPatternAreaTab(Col, nStart, Col, nEnd, Tab, aScPattern);
1796                 }
1797 			}
1798 			nStart = nEnd + 1;
1799 		}
1800 
1801 	// Fontfarbe
1802 	nStart = 0;
1803 	nEnd = 0;
1804 	nLimit = aColor.Count;
1805 	pColData = aColor.pData;
1806 	for( i = 0 ; i < nLimit ; i++, pColData++ )
1807 	{
1808 		nEnd = static_cast<SCROW>(pColData->Row);
1809 		if ((nStart <= nEnd) && (pColData->Value))
1810 		{
1811 			Color TextColor(COL_BLACK);
1812 			lcl_ChangeColor((pColData->Value & 0x000F), TextColor);
1813 			ScPatternAttr aScPattern(pDoc->GetPool());
1814             aScPattern.GetItemSet().Put(SvxColorItem(TextColor, ATTR_FONT_COLOR ));
1815 			pDoc->ApplyPatternAreaTab(Col, nStart, Col, nEnd, Tab, aScPattern);
1816 		}
1817 		nStart = nEnd + 1;
1818 	}
1819 
1820 	// Fontattribute (Fett, Kursiv...)
1821 	nStart = 0;
1822 	nEnd = 0;
1823 	nLimit = aAttr.Count;
1824 	pColData = aAttr.pData;
1825 	for( i = 0 ; i < nLimit ; i++, pColData++ )
1826 	{
1827 		nEnd = static_cast<SCROW>(pColData->Row);
1828         nValue1 = pColData->Value;
1829         if ((nStart <= nEnd) && (nValue1))
1830 		{
1831 			ScPatternAttr aScPattern(pDoc->GetPool());
1832 			if ((nValue1 & atBold) == atBold)
1833              aScPattern.GetItemSet().Put(SvxWeightItem(WEIGHT_BOLD, ATTR_FONT_WEIGHT));
1834 			if ((nValue1 & atItalic) == atItalic)
1835              aScPattern.GetItemSet().Put(SvxPostureItem(ITALIC_NORMAL, ATTR_FONT_POSTURE));
1836 			if ((nValue1 & atUnderline) == atUnderline)
1837              aScPattern.GetItemSet().Put(SvxUnderlineItem(UNDERLINE_SINGLE, ATTR_FONT_UNDERLINE));
1838 			if ((nValue1 & atStrikeOut) == atStrikeOut)
1839              aScPattern.GetItemSet().Put(SvxCrossedOutItem(STRIKEOUT_SINGLE, ATTR_FONT_CROSSEDOUT));
1840 			pDoc->ApplyPatternAreaTab(Col, nStart, Col, nEnd, Tab, aScPattern);
1841 		}
1842 		nStart = nEnd + 1;
1843 	}
1844 
1845 	// Zellausrichtung
1846 	nStart = 0;
1847 	nEnd = 0;
1848 	nLimit = aJustify.Count;
1849 	pColData = aJustify.pData;
1850 	for( i = 0 ; i < nLimit ; i++, pColData++ )
1851 	{
1852 		nEnd = static_cast<SCROW>(pColData->Row);
1853         nValue1 = pColData->Value;
1854         if ((nStart <= nEnd) && (nValue1))
1855 		{
1856             ScPatternAttr aScPattern(pDoc->GetPool());
1857             sal_uInt16 HorJustify = (nValue1 & 0x000F);
1858             sal_uInt16 VerJustify = (nValue1 & 0x00F0) >> 4;
1859             sal_uInt16 OJustify   = (nValue1 & 0x0F00) >> 8;
1860             sal_uInt16 EJustify   = (nValue1 & 0xF000) >> 12;
1861 
1862 			switch (HorJustify)
1863 			{
1864 				case hjLeft:
1865                     aScPattern.GetItemSet().Put(SvxHorJustifyItem(SVX_HOR_JUSTIFY_LEFT, ATTR_HOR_JUSTIFY));
1866 					break;
1867 				case hjCenter:
1868                     aScPattern.GetItemSet().Put(SvxHorJustifyItem(SVX_HOR_JUSTIFY_CENTER, ATTR_HOR_JUSTIFY));
1869 					break;
1870 				case hjRight:
1871                     aScPattern.GetItemSet().Put(SvxHorJustifyItem(SVX_HOR_JUSTIFY_RIGHT, ATTR_HOR_JUSTIFY));
1872 					break;
1873 			}
1874 
1875 			switch (VerJustify)
1876 			{
1877 				case vjTop:
1878                     aScPattern.GetItemSet().Put(SvxVerJustifyItem(SVX_VER_JUSTIFY_TOP, ATTR_VER_JUSTIFY));
1879 					break;
1880 				case vjCenter:
1881                     aScPattern.GetItemSet().Put(SvxVerJustifyItem(SVX_VER_JUSTIFY_CENTER, ATTR_VER_JUSTIFY));
1882 					break;
1883 				case vjBottom:
1884                     aScPattern.GetItemSet().Put(SvxVerJustifyItem(SVX_VER_JUSTIFY_BOTTOM, ATTR_VER_JUSTIFY));
1885 					break;
1886 			}
1887 
1888 			if (OJustify & ojWordBreak)
1889                 aScPattern.GetItemSet().Put(SfxBoolItem(sal_True));
1890 			if (OJustify & ojBottomTop)
1891                 aScPattern.GetItemSet().Put(SfxInt32Item(ATTR_ROTATE_VALUE,9000));
1892 			else if (OJustify & ojTopBottom)
1893                 aScPattern.GetItemSet().Put(SfxInt32Item(ATTR_ROTATE_VALUE,27000));
1894 
1895 			sal_Int16 Margin = Max((sal_uInt16)20, (sal_uInt16)(EJustify * 20));
1896 			if (((OJustify & ojBottomTop) == ojBottomTop) || ((OJustify & ojBottomTop) == ojBottomTop))
1897                 aScPattern.GetItemSet().Put(SvxMarginItem(20, Margin, 20, Margin, ATTR_MARGIN));
1898 			else
1899                 aScPattern.GetItemSet().Put(SvxMarginItem(Margin, 20, Margin, 20, ATTR_MARGIN));
1900 			pDoc->ApplyPatternAreaTab(Col, nStart, Col, nEnd, Tab, aScPattern);
1901 		}
1902 	nStart = nEnd + 1;
1903 	}
1904 	// Umrandung
1905 	sal_Bool			bEnd = sal_False;
1906 	sal_uInt16			nColorIndex = 0;
1907 	sal_uInt16			nFrameIndex = 0;
1908 
1909 	// Special Fix...
1910 	const sal_uInt32	nHelpMeStart = 100;
1911 	sal_uInt32			nHelpMe = nHelpMeStart;
1912 	sal_uInt16			nColorIndexOld = nColorIndex;
1913 	sal_uInt16			nFrameIndexOld = nColorIndex;
1914 
1915 	nEnd = 0;
1916 	nStart = 0;
1917 	while( !bEnd && nHelpMe )
1918 	{
1919 		pColData = &aFrame.pData[ nFrameIndex ];
1920 
1921 		sal_uInt16	nValue	= pColData->Value;
1922 		sal_uInt16	nLeft	= 0;
1923 		sal_uInt16	nTop	= 0;
1924 		sal_uInt16	nRight	= 0;
1925 		sal_uInt16	nBottom	= 0;
1926 		sal_uInt16	fLeft	= ( nValue & 0x000F );
1927 		sal_uInt16	fTop	= ( nValue & 0x00F0 ) >> 4;
1928 		sal_uInt16	fRight	= ( nValue & 0x0F00 ) >> 8;
1929 		sal_uInt16	fBottom	= ( nValue & 0xF000 ) >> 12;
1930 
1931 		if( fLeft > 1 )
1932 			nLeft = 50;
1933 		else if( fLeft > 0 )
1934 			nLeft = 20;
1935 
1936 		if( fTop > 1 )
1937 			nTop = 50;
1938 		else if( fTop > 0 )
1939 			nTop = 20;
1940 
1941 		if( fRight > 1 )
1942 			nRight = 50;
1943 		else if( fRight > 0 )
1944 			nRight = 20;
1945 
1946 		if( fBottom > 1 )
1947 			nBottom = 50;
1948 		else if( fBottom > 0 )
1949 			nBottom = 20;
1950 
1951 		Color	ColorLeft( COL_BLACK );
1952 		Color	ColorTop( COL_BLACK );
1953 		Color	ColorRight( COL_BLACK );
1954 		Color	ColorBottom( COL_BLACK );
1955 		sal_uInt16	nFrmColVal	= aFrameColor.pData[ nColorIndex ].Value;
1956 		SCROW	nFrmColRow	= static_cast<SCROW>(aFrameColor.pData[ nColorIndex ].Row);
1957 		sal_uInt16	cLeft		= ( nFrmColVal & 0x000F );
1958 		sal_uInt16	cTop		= ( nFrmColVal & 0x00F0 ) >> 4;
1959 		sal_uInt16	cRight		= ( nFrmColVal & 0x0F00 ) >> 8;
1960 		sal_uInt16	cBottom		= ( nFrmColVal & 0xF000 ) >> 12;
1961 
1962 		lcl_ChangeColor( cLeft, ColorLeft );
1963 		lcl_ChangeColor( cTop, ColorTop );
1964 		lcl_ChangeColor( cRight, ColorRight );
1965 		lcl_ChangeColor( cBottom, ColorBottom );
1966 
1967 		if( static_cast<SCROW>(pColData->Row) < nFrmColRow )
1968 		{
1969 			nEnd = static_cast<SCROW>(pColData->Row);
1970 			if( nFrameIndex < ( aFrame.Count - 1 ) )
1971 				nFrameIndex++;
1972 		}
1973 		else if( static_cast<SCROW>(pColData->Row) > nFrmColRow )
1974 		{
1975 			nEnd = static_cast<SCROW>(aFrameColor.pData[ nColorIndex ].Row);
1976 			if( nColorIndex < ( aFrameColor.Count - 1 ) )
1977 				nColorIndex++;
1978 		}
1979 		else
1980 		{
1981 			nEnd = nFrmColRow;
1982 			if( nFrameIndex < (aFrame.Count - 1 ) )
1983 				nFrameIndex++;
1984 			if( nColorIndex < ( aFrameColor.Count - 1 ) )
1985 				nColorIndex++;
1986 		}
1987 		if( ( nStart <= nEnd ) && ( nValue != 0 ) )
1988 		{
1989             ScPatternAttr   aScPattern(pDoc->GetPool());
1990 			SvxBorderLine	aLine;
1991             SvxBoxItem      aBox( ATTR_BORDER );
1992 
1993 			aLine.SetOutWidth( nLeft );
1994 			aLine.SetColor( ColorLeft );
1995 			aBox.SetLine( &aLine, BOX_LINE_LEFT );
1996 
1997 			aLine.SetOutWidth( nTop );
1998 			aLine.SetColor( ColorTop );
1999 			aBox.SetLine( &aLine, BOX_LINE_TOP );
2000 
2001 			aLine.SetOutWidth( nRight );
2002 			aLine.SetColor( ColorRight );
2003 			aBox.SetLine( &aLine, BOX_LINE_RIGHT );
2004 
2005 			aLine.SetOutWidth( nBottom );
2006 			aLine.SetColor( ColorBottom );
2007 			aBox.SetLine( &aLine, BOX_LINE_BOTTOM );
2008 
2009             aScPattern.GetItemSet().Put( aBox );
2010             pDoc->ApplyPatternAreaTab( Col, nStart, Col, nEnd, Tab, aScPattern );
2011 		}
2012 		nStart = nEnd + 1;
2013 
2014 		bEnd = ( nFrameIndex == ( aFrame.Count - 1 ) ) && ( nColorIndex == ( aFrameColor.Count - 1 ) );
2015 
2016 		if( nColorIndexOld != nColorIndex || nFrameIndexOld != nFrameIndex )
2017 		{
2018 			nColorIndexOld = nColorIndex;
2019 			nFrameIndexOld = nFrameIndex;
2020 			nHelpMe = nHelpMeStart;
2021 		}
2022 		else
2023 			nHelpMe--;
2024 
2025 		pColData++;
2026 	}
2027 
2028 	// ACHTUNG: Code bis hier ueberarbeitet ... jetzt hab' ich keinen Bock mehr! (GT)
2029 
2030 	// Hintergrund (Farbe, Raster)
2031 	sal_uInt16		nRasterIndex = 0;
2032 	bEnd		= sal_False;
2033 	nColorIndex	= 0;
2034 	nEnd		= 0;
2035 	nStart		= 0;
2036 
2037 	// Special Fix...
2038 	nHelpMe		= nHelpMeStart;
2039 	sal_uInt16		nRasterIndexOld = nRasterIndex;
2040 
2041 	while( !bEnd && nHelpMe )
2042 	{
2043 		sal_uInt16	nBColor = ( aColor.pData[ nColorIndex ].Value & 0x00F0 ) >> 4;
2044 		sal_uInt16	nRColor = ( aColor.pData[ nColorIndex ].Value & 0x0F00 ) >> 8;
2045 		Color	aBColor( COL_BLACK );
2046 
2047 		lcl_ChangeColor( nBColor, aBColor );
2048 
2049 		if( nBColor == 0 )
2050 			aBColor.SetColor( COL_WHITE );
2051 		else if( nBColor == 15 )
2052 			aBColor.SetColor( COL_BLACK );
2053 
2054 		Color	aRColor( COL_BLACK );
2055 
2056 		lcl_ChangeColor( nRColor, aRColor );
2057 
2058         ScPatternAttr aScPattern( pDoc->GetPool() );
2059 
2060 		sal_uInt16 nFact;
2061 		sal_Bool		bSwapCol = sal_False;
2062 		sal_Bool		bSetItem = sal_True;
2063 		switch ( aRaster.pData[ nRasterIndex ].Value )
2064 		{
2065 		case raNone:		nFact = 0xffff; bSwapCol = sal_True; bSetItem = (nBColor > 0); break;
2066 		case raGray12:	nFact = (0xffff / 100) * 12;	break;
2067 		case raGray25:	nFact = (0xffff / 100) * 25;	break;
2068 		case raGray50:	nFact = (0xffff / 100) * 50;	break;
2069 		case raGray75:	nFact = (0xffff / 100) * 75;	break;
2070 		default:	nFact = 0xffff; bSetItem = (nRColor < 15);
2071 		}
2072 		if ( bSetItem )
2073 		{
2074 			if( bSwapCol )
2075                 aScPattern.GetItemSet().Put( SvxBrushItem( GetMixedColor( aBColor, aRColor, nFact ), ATTR_BACKGROUND ) );
2076 			else
2077                 aScPattern.GetItemSet().Put( SvxBrushItem( GetMixedColor( aRColor, aBColor, nFact ), ATTR_BACKGROUND ) );
2078 		}
2079 		if( aRaster.pData[ nRasterIndex ].Row < aColor.pData[ nColorIndex ].Row )
2080 		{
2081 			nEnd = static_cast<SCROW>(aRaster.pData[ nRasterIndex ].Row);
2082 			if( nRasterIndex < ( aRaster.Count - 1 ) )
2083 				nRasterIndex++;
2084 		}
2085 		else if( aRaster.pData[ nRasterIndex ].Row > aColor.pData[ nColorIndex ].Row )
2086 		{
2087 			nEnd = static_cast<SCROW>(aColor.pData[ nColorIndex ].Row);
2088 			if( nColorIndex < ( aColor.Count - 1 ) )
2089 				nColorIndex++;
2090 		}
2091 		else
2092 		{
2093 			nEnd = static_cast<SCROW>(aColor.pData[ nColorIndex ].Row);
2094 			if( nRasterIndex < ( aRaster.Count - 1 ) )
2095 				nRasterIndex++;
2096 			if( nColorIndex < ( aColor.Count - 1 ) )
2097 				nColorIndex++;
2098 		}
2099 		if( nStart <= nEnd )
2100             pDoc->ApplyPatternAreaTab( Col, nStart, Col, nEnd, Tab, aScPattern );
2101 
2102 		nStart = nEnd + 1;
2103 
2104 		bEnd = ( nRasterIndex == ( aRaster.Count - 1 ) ) && ( nColorIndex == ( aColor.Count - 1 ) );
2105 
2106 		if( nColorIndexOld != nColorIndex || nRasterIndexOld != nRasterIndex )
2107 		{
2108 			nColorIndexOld = nColorIndex;
2109 			nRasterIndexOld = nRasterIndex;
2110 			nHelpMe = nHelpMeStart;
2111 		}
2112 		else
2113 			nHelpMe--;
2114 
2115 		nHelpMe--;
2116 	}
2117 
2118 	// Zahlenformate
2119 	nStart = 0;
2120 	nEnd = 0;
2121 	nLimit = aValue.Count;
2122 	pColData = aValue.pData;
2123 	for (i=0; i<nLimit; i++, pColData++)
2124 	{
2125 		nEnd = static_cast<SCROW>(pColData->Row);
2126         nValue1 = pColData->Value;
2127         if ((nStart <= nEnd) && (nValue1))
2128 		{
2129 			sal_uLong  nKey    = 0;
2130             sal_uInt16 nFormat = (nValue1 & 0x00FF);
2131             sal_uInt16 nInfo   = (nValue1 & 0xFF00) >> 8;
2132 			ChangeFormat(nFormat, nInfo, nKey);
2133             ScPatternAttr aScPattern(pDoc->GetPool());
2134             aScPattern.GetItemSet().Put(SfxUInt32Item(ATTR_VALUE_FORMAT, (sal_uInt32)nKey));
2135             pDoc->ApplyPatternAreaTab(Col, nStart, Col, nEnd, Tab, aScPattern);
2136 		}
2137 		nStart = nEnd + 1;
2138 	}
2139 
2140 	// Zellattribute (Schutz, Versteckt...)
2141 	nStart = 0;
2142 	nEnd = 0;
2143 	for (i=0; i<aFlag.Count; i++)
2144 	{
2145 		nEnd = static_cast<SCROW>(aFlag.pData[i].Row);
2146 		if ((nStart <= nEnd) && (aFlag.pData[i].Value != 0))
2147 		{
2148 			sal_Bool bProtect  = ((aFlag.pData[i].Value & paProtect) == paProtect);
2149 			sal_Bool bHFormula = ((aFlag.pData[i].Value & paHideFormula) == paHideFormula);
2150 			sal_Bool bHCell    = ((aFlag.pData[i].Value & paHideAll) == paHideAll);
2151 			sal_Bool bHPrint   = ((aFlag.pData[i].Value & paHidePrint) == paHidePrint);
2152             ScPatternAttr aScPattern(pDoc->GetPool());
2153             aScPattern.GetItemSet().Put(ScProtectionAttr(bProtect, bHFormula, bHCell, bHPrint));
2154             pDoc->ApplyPatternAreaTab(Col, nStart, Col, nEnd, Tab, aScPattern);
2155 		}
2156 		nStart = nEnd + 1;
2157 	}
2158 
2159 	// ZellVorlagen
2160 	nStart = 0;
2161 	nEnd = 0;
2162 	ScStyleSheetPool* pStylePool = pDoc->GetStyleSheetPool();
2163 	for (i=0; i<aPattern.Count; i++)
2164 	{
2165 		nEnd = static_cast<SCROW>(aPattern.pData[i].Row);
2166 		if ((nStart <= nEnd) && (aPattern.pData[i].Value != 0))
2167 		{
2168 			sal_uInt16 nPatternIndex = (aPattern.pData[i].Value & 0x00FF) - 1;
2169 			Sc10PatternData* pPattern = pPatternCollection->At(nPatternIndex);
2170 			if (pPattern != NULL)
2171 			{
2172 				ScStyleSheet* pStyle = (ScStyleSheet*) pStylePool->Find(
2173 									SC10TOSTRING( pPattern->Name ), SFX_STYLE_FAMILY_PARA);
2174 
2175 				if (pStyle != NULL)
2176 					pDoc->ApplyStyleAreaTab(Col, nStart, Col, nEnd, Tab, *pStyle);
2177 			}
2178 		}
2179 		nStart = nEnd + 1;
2180 	}
2181   }
2182 }
2183 
2184 
LoadAttr(Sc10ColAttr & rAttr)2185 void Sc10Import::LoadAttr(Sc10ColAttr& rAttr)
2186 {
2187     // rAttr is not reused, otherwise we'd have to delete [] rAttr.pData;
2188     rStream >> rAttr.Count;
2189     if (rAttr.Count)
2190     {
2191         rAttr.pData = new (::std::nothrow) Sc10ColData[rAttr.Count];
2192         if (rAttr.pData != NULL)
2193         {
2194             for (sal_uInt16 i = 0; i < rAttr.Count; i++)
2195             {
2196                 rStream >> rAttr.pData[i].Row;
2197                 rStream >> rAttr.pData[i].Value;
2198             }
2199             nError = rStream.GetError();
2200         }
2201         else
2202         {
2203             nError = errOutOfMemory;
2204             rAttr.Count = 0;
2205         }
2206     }
2207 }
2208 
2209 
ChangeFormat(sal_uInt16 nFormat,sal_uInt16 nInfo,sal_uLong & nKey)2210 void Sc10Import::ChangeFormat(sal_uInt16 nFormat, sal_uInt16 nInfo, sal_uLong& nKey)
2211 {
2212   // Achtung: Die Formate werden nur auf die StarCalc 3.0 internen Formate gemappt
2213   //          Korrekterweise muessten zum Teil neue Formate erzeugt werden (sollte Stephan sich ansehen)
2214   nKey = 0;
2215   switch (nFormat)
2216   {
2217 	case vfStandard :
2218 	 if (nInfo > 0)
2219 	   nKey = 2;
2220 	 break;
2221 	case vfMoney :
2222 	 if (nInfo > 0)
2223 	   nKey = 21;
2224 	 else
2225 	   nKey = 20;
2226 	 break;
2227 	case vfThousend :
2228 	 if (nInfo > 0)
2229 	   nKey = 4;
2230 	 else
2231 	   nKey = 5;
2232 	 break;
2233 	case vfPercent :
2234 	 if (nInfo > 0)
2235 	   nKey = 11;
2236 	 else
2237 	   nKey = 10;
2238 	 break;
2239 	case vfExponent :
2240 	 nKey = 60;
2241 	 break;
2242 	case vfZerro :
2243 	 // Achtung kein Aequivalent
2244 	 break;
2245 	case vfDate :
2246 	  switch (nInfo)
2247 	  {
2248 		case df_NDMY_Long :
2249 		 nKey = 31;
2250 		 break;
2251 		case df_DMY_Long :
2252 		 nKey = 30;
2253 		 break;
2254 		case df_MY_Long :
2255 		 nKey = 32;
2256 		 break;
2257 		case df_NDM_Long :
2258 		 nKey = 31;
2259 		 break;
2260 		case df_DM_Long :
2261 		 nKey = 33;
2262 		 break;
2263 		case df_M_Long :
2264 		 nKey = 34;
2265 		 break;
2266 		case df_NDMY_Short :
2267 		 nKey = 31;
2268 		 break;
2269 		case df_DMY_Short :
2270 		 nKey = 30;
2271 		 break;
2272 		case df_MY_Short :
2273 		 nKey = 32;
2274 		 break;
2275 		case df_NDM_Short :
2276 		 nKey = 31;
2277 		 break;
2278 		case df_DM_Short :
2279 		 nKey = 33;
2280 		 break;
2281 		case df_M_Short :
2282 		 nKey = 34;
2283 		 break;
2284 		case df_Q_Long :
2285 		 nKey = 35;
2286 		 break;
2287 		case df_Q_Short :
2288 		 nKey = 35;
2289 		 break;
2290 		default :
2291 		 nKey = 30;
2292 		 break;
2293 	  }
2294 	  break;
2295 	case vfTime :
2296 	 switch (nInfo)
2297 	 {
2298 	   case tf_HMS_Long :
2299 		nKey = 41;
2300 		break;
2301 	   case tf_HM_Long :
2302 		nKey = 40;
2303 		break;
2304 	   case tf_HMS_Short :
2305 		nKey = 43;
2306 		break;
2307 	   case tf_HM_Short :
2308 		nKey = 42;
2309 		break;
2310 	   default :
2311 		nKey = 41;
2312 		break;
2313 	 }
2314 	 break;
2315 	case vfBoolean :
2316 	 nKey = 99;
2317 	 break;
2318 	case vfStandardRed :
2319 	 if (nInfo > 0)
2320 	   nKey = 2;
2321 	 break;
2322 	case vfMoneyRed :
2323 	 if (nInfo > 0)
2324 	   nKey = 23;
2325 	 else
2326 	   nKey = 22;
2327 	 break;
2328 	case vfThousendRed :
2329 	 if (nInfo > 0)
2330 	   nKey = 4;
2331 	 else
2332 	   nKey = 5;
2333 	 break;
2334 	case vfPercentRed :
2335 	 if (nInfo > 0)
2336 	   nKey = 11;
2337 	 else
2338 	   nKey = 10;
2339 	 break;
2340 	case vfExponentRed :
2341 	 nKey = 60;
2342 	 break;
2343 	case vfFormula :
2344 	 break;
2345 	case vfString :
2346 	 break;
2347 	default :
2348 	 break;
2349   }
2350 }
2351 
2352 
LoadObjects()2353 void Sc10Import::LoadObjects()
2354 {
2355   sal_uInt16 ID;
2356   rStream >> ID;
2357   if (rStream.IsEof()) return;
2358   if (ID == ObjectID)
2359   {
2360 #ifdef SC10_SHOW_OBJECTS
2361 	// Achtung nur zu Debugzwecken
2362 	//-----------------------------------
2363 	pDoc->InsertTab(SC_TAB_APPEND, "GraphObjects");
2364 	SCCOL nCol = 0;
2365 	SCROW nRow = 0;
2366 	SCTAB nTab = 0;
2367 	pDoc->GetTable("GraphObjects", nTab);
2368 	pDoc->SetString(nCol++, nRow, nTab, "ObjectTyp");
2369 	pDoc->SetString(nCol++, nRow, nTab, "Col");
2370 	pDoc->SetString(nCol++, nRow, nTab, "Row");
2371 	pDoc->SetString(nCol++, nRow, nTab, "Tab");
2372 	pDoc->SetString(nCol++, nRow, nTab, "X");
2373 	pDoc->SetString(nCol++, nRow, nTab, "Y");
2374 	pDoc->SetString(nCol++, nRow, nTab, "W");
2375 	pDoc->SetString(nCol++, nRow, nTab, "H");
2376 	//-----------------------------------
2377 #endif
2378 
2379 	sal_uInt16 nAnz;
2380 	rStream >> nAnz;
2381 	sal_Char Reserved[32];
2382 	rStream.Read(Reserved, sizeof(Reserved));
2383 	nError = rStream.GetError();
2384 	if ((nAnz > 0) && (nError == 0))
2385 	{
2386 	  sal_uInt8 ObjectType;
2387 	  Sc10GraphHeader GraphHeader;
2388 	  sal_Bool IsOleObject = sal_False; // Achtung dies ist nur ein Notnagel
2389 	  for (sal_uInt16 i = 0; (i < nAnz) && (nError == 0) && !rStream.IsEof() && !IsOleObject; i++)
2390 	  {
2391 		rStream >> ObjectType;
2392 		lcl_ReadGraphHeader(rStream, GraphHeader);
2393 
2394 		double nPPTX = ScGlobal::nScreenPPTX;
2395 		double nPPTY = ScGlobal::nScreenPPTY;
2396 
2397 		long nStartX = 0;
2398 		for (SCsCOL nX=0; nX<GraphHeader.CarretX; nX++)
2399 			nStartX += pDoc->GetColWidth(nX, static_cast<SCTAB>(GraphHeader.CarretZ));
2400 		nStartX = (long) ( nStartX * HMM_PER_TWIPS );
2401 		nStartX += (long) ( GraphHeader.x / nPPTX * HMM_PER_TWIPS );
2402 		long nSizeX = (long) ( GraphHeader.w / nPPTX * HMM_PER_TWIPS );
2403         long nStartY = pDoc->GetRowHeight( 0,
2404                 static_cast<SCsROW>(GraphHeader.CarretY) - 1,
2405                 static_cast<SCTAB>(GraphHeader.CarretZ));
2406 		nStartY = (long) ( nStartY * HMM_PER_TWIPS );
2407 		nStartY += (long) ( GraphHeader.y / nPPTY * HMM_PER_TWIPS );
2408 		long nSizeY = (long) ( GraphHeader.h / nPPTY * HMM_PER_TWIPS );
2409 
2410 #ifdef SC10_SHOW_OBJECTS
2411 		 // Achtung nur zu Debugzwecken
2412 		 //-----------------------------------
2413 		 nCol = 0;
2414 		 nRow++;
2415 		 switch (ObjectType)
2416 		 {
2417 		  case otOle :
2418 		   pDoc->SetString(nCol++, nRow, nTab, "Ole-Object");
2419 		   break;
2420 		  case otImage :
2421 		   pDoc->SetString(nCol++, nRow, nTab, "Image-Object");
2422 		   break;
2423 		  case otChart :
2424 		   pDoc->SetString(nCol++, nRow, nTab, "Chart-Object");
2425 		   break;
2426 		  default :
2427 		   pDoc->SetString(nCol++, nRow, nTab, "ERROR");
2428 		   break;
2429 		 }
2430 		 pDoc->SetValue(nCol++, nRow, nTab, GraphHeader.CarretX);
2431 		 pDoc->SetValue(nCol++, nRow, nTab, GraphHeader.CarretY);
2432 		 pDoc->SetValue(nCol++, nRow, nTab, GraphHeader.CarretZ);
2433 		 pDoc->SetValue(nCol++, nRow, nTab, GraphHeader.x);
2434 		 pDoc->SetValue(nCol++, nRow, nTab, GraphHeader.y);
2435 		 pDoc->SetValue(nCol++, nRow, nTab, GraphHeader.w);
2436 		 pDoc->SetValue(nCol++, nRow, nTab, GraphHeader.h);
2437 		 //-----------------------------------
2438 #endif
2439 
2440 		switch (ObjectType)
2441 		{
2442 		  case otOle :
2443 		   // Achtung hier muss sowas wie OleLoadFromStream passieren
2444 		   IsOleObject = sal_True;
2445 		   break;
2446 		  case otImage :
2447 		  {
2448 		   Sc10ImageHeader ImageHeader;
2449 		   lcl_ReadImageHeaer(rStream, ImageHeader);
2450 
2451 		   // Achtung nun kommen die Daten (Bitmap oder Metafile)
2452 		   // Typ = 1 Device Dependend Bitmap DIB
2453 		   // Typ = 2 MetaFile
2454 		   rStream.SeekRel(ImageHeader.Size);
2455 
2456 			if( ImageHeader.Typ != 1 && ImageHeader.Typ != 2 )
2457 				nError = errUnknownFormat;
2458 		   break;
2459 		  }
2460 		  case otChart :
2461 		  {
2462 			Sc10ChartHeader ChartHeader;
2463 			Sc10ChartSheetData ChartSheetData;
2464 			Sc10ChartTypeData* pTypeData = new (::std::nothrow) Sc10ChartTypeData;
2465             if (!pTypeData)
2466                 nError = errOutOfMemory;
2467             else
2468             {
2469                 lcl_ReadChartHeader(rStream, ChartHeader);
2470 
2471                 //!	altes Metafile verwenden ??
2472                 rStream.SeekRel(ChartHeader.Size);
2473 
2474                 lcl_ReadChartSheetData(rStream, ChartSheetData);
2475 
2476                 lcl_ReadChartTypeData(rStream, *pTypeData);
2477 
2478                 Rectangle aRect( Point(nStartX,nStartY), Size(nSizeX,nSizeY) );
2479                 Sc10InsertObject::InsertChart( pDoc, static_cast<SCTAB>(GraphHeader.CarretZ), aRect,
2480                         static_cast<SCTAB>(GraphHeader.CarretZ),
2481                         ChartSheetData.DataX1, ChartSheetData.DataY1,
2482                         ChartSheetData.DataX2, ChartSheetData.DataY2 );
2483 
2484                 delete pTypeData;
2485             }
2486 		  }
2487 		  break;
2488 		  default :
2489 		   nError = errUnknownFormat;
2490 		   break;
2491 		}
2492 		nError = rStream.GetError();
2493 	  }
2494 	}
2495   }
2496   else
2497   {
2498 	DBG_ERROR( "ObjectID" );
2499 	nError = errUnknownID;
2500   }
2501 }
2502 
2503 
2504 
2505 
2506 //-----------------------------------------------------------------------------------------------
2507 
ScImportStarCalc10(SvStream & rStream,ScDocument * pDocument)2508 FltError ScFormatFilterPluginImpl::ScImportStarCalc10( SvStream& rStream, ScDocument* pDocument )
2509 {
2510 	rStream.Seek( 0UL );
2511 	Sc10Import	aImport( rStream, pDocument );
2512 	return ( FltError ) aImport.Import();
2513 }
2514 
2515 
2516 
2517