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