update dev300-m57
[ooovba.git] / sc / source / filter / inc / xldumper.hxx
blobb35482955f71e60771f6ec1bd4a67376cc658fdd
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: xldumper.hxx,v $
10 * $Revision: 1.12 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef SC_XLDUMPER_HXX
32 #define SC_XLDUMPER_HXX
34 #include "fdumper.hxx"
36 #include <stack>
37 #include "fdumperdff.hxx"
38 #include "fdumperole.hxx"
39 #include "xlconst.hxx"
40 #include "xlstring.hxx"
41 #include "xlstyle.hxx"
43 #if SCF_INCL_DUMPER
45 class SfxMedium;
46 class SfxObjectShell;
47 class ScDocument;
48 struct XclImpRootData;
49 class XclImpRoot;
50 class XclImpStream;
51 class XclFunctionProvider;
53 namespace scf {
54 namespace dump {
55 namespace xls {
57 // ============================================================================
58 // ============================================================================
60 struct Address
62 sal_Int32 mnCol;
63 sal_Int32 mnRow;
64 inline explicit Address() : mnCol( 0 ), mnRow( 0 ) {}
65 void Read( XclImpStream& rStrm, bool bCol16Bit = true, bool bRow32Bit = false );
68 // ----------------------------------------------------------------------------
70 struct Range
72 Address maFirst;
73 Address maLast;
74 inline explicit Range() {}
75 void Read( XclImpStream& rStrm, bool bCol16Bit = true, bool bRow32Bit = false );
78 // ----------------------------------------------------------------------------
80 struct RangeList : public ::std::vector< Range >
82 inline explicit RangeList() {}
83 void Read( XclImpStream& rStrm, bool bCol16Bit = true, bool bRow32Bit = false );
86 // ============================================================================
88 struct FormulaAddress : public Address
90 bool mbRelCol;
91 bool mbRelRow;
92 inline explicit FormulaAddress() : mbRelCol( false ), mbRelRow( false ) {}
95 // ----------------------------------------------------------------------------
97 struct FormulaRange
99 FormulaAddress maFirst;
100 FormulaAddress maLast;
101 inline explicit FormulaRange() {}
104 // ============================================================================
106 class StringHelper : public ::scf::dump::StringHelper
108 public:
109 static void AppendAddrCol( String& rStr, sal_Int32 nCol, bool bRel );
110 static void AppendAddrRow( String& rStr, sal_Int32 nRow, bool bRel );
111 static void AppendAddrName( String& rStr, sal_Unicode cPrefix, sal_Int32 nColRow, bool bRel );
113 static void AppendAddress( String& rStr, const Address& rPos );
114 static void AppendRange( String& rStr, const Range& rRange );
115 static void AppendRangeList( String& rStr, const RangeList& rRanges );
117 static void AppendAddress( String& rStr, const FormulaAddress& rPos, bool bNameMode );
118 static void AppendRange( String& rStr, const FormulaRange& rRange, bool bNameMode );
121 // ============================================================================
122 // ============================================================================
124 class RecordHeaderObject : public RecordHeaderBase
126 public:
127 explicit RecordHeaderObject( const InputObjectBase& rParent );
129 inline bool IsMergeContRec() const { return mbMergeContRec; }
130 inline bool HasRecName( sal_uInt16 nRecId ) const { return GetRecNames()->HasName( nRecId ); }
132 void DumpRecordHeader( XclImpStream& rStrm );
134 protected:
135 virtual bool ImplIsValid() const;
137 private:
138 bool mbMergeContRec;
141 typedef ScfRef< RecordHeaderObject > RecHeaderObjectRef;
143 // ============================================================================
144 // ============================================================================
146 class BiffConfig : public Config
148 public:
149 explicit BiffConfig( const Config& rParent, XclBiff eBiff );
151 protected:
152 virtual bool ImplIsValid() const;
153 virtual NameListRef ImplGetNameList( const String& rKey ) const;
155 private:
156 XclBiff meBiff;
159 typedef ScfRef< BiffConfig > BiffConfigRef;
161 // ============================================================================
163 class RootData : public Base
165 public:
166 explicit RootData( SfxMedium& rMedium, XclBiff eBiff );
167 virtual ~RootData();
169 inline const XclImpRoot& GetRoot() const { return *mxRoot; }
171 rtl_TextEncoding GetTextEncoding() const;
172 void SetTextEncoding( rtl_TextEncoding eTextEnc );
174 protected:
175 virtual bool ImplIsValid() const;
177 private:
178 typedef ScfRef< ScDocument > ScDocumentRef;
179 typedef ScfRef< XclImpRootData > XclImpRootDataRef;
180 typedef ScfRef< XclImpRoot > XclImpRootRef;
182 ScDocumentRef mxDoc;
183 XclImpRootDataRef mxRootData;
184 XclImpRootRef mxRoot;
187 typedef ScfRef< RootData > RootDataRef;
189 // ============================================================================
191 class RootObjectBase : public WrappedStreamObject
193 public:
194 virtual ~RootObjectBase();
196 inline RootData& Root() const { return *mxRootData; }
197 inline const XclImpRoot& GetXclRoot() const { return mxRootData->GetRoot(); }
198 inline XclImpStream& GetXclStream() const { return *mxStrm; }
199 inline XclBiff GetBiff() const { return meBiff; }
201 protected:
202 explicit RootObjectBase();
203 void Construct( const ObjectBase& rParent, SvStream& rStrm, XclBiff eBiff );
204 void Construct( const OleStorageObject& rParentStrg, const String& rStrmName, XclBiff eBiff );
205 void Construct( const RootObjectBase& rParent );
207 virtual bool ImplIsValid() const;
208 virtual void ImplDumpExtendedHeader();
209 virtual ConfigRef ImplReconstructConfig();
210 virtual InputRef ImplReconstructInput();
212 String GetErrorName( sal_uInt8 nErrCode ) const;
214 // ------------------------------------------------------------------------
216 double WriteRkItem( const sal_Char* pcName, sal_Int32 nRk );
217 void WriteBooleanItem( const sal_Char* pcName, sal_uInt8 nBool );
218 void WriteErrorCodeItem( const sal_Char* pcName, sal_uInt8 nErrCode );
220 void WriteColIndexItem( const sal_Char* pcName, sal_Int32 nCol );
221 void WriteColRangeItem( const sal_Char* pcName, sal_Int32 nCol1, sal_Int32 nCol2 );
222 void WriteRowIndexItem( const sal_Char* pcName, sal_Int32 nRow );
223 void WriteRowRangeItem( const sal_Char* pcName, sal_Int32 nRow1, sal_Int32 nRow2 );
225 void WriteAddressItem( const sal_Char* pcName, const Address& rPos );
226 void WriteRangeItem( const sal_Char* pcName, const Range& rRange );
227 void WriteRangeListItem( const sal_Char* pcName, const RangeList& rRanges );
229 template< typename Type >
230 void WriteRectItem( const sal_Char* pcName,
231 Type nLeft, Type nTop, Type nWidth, Type nHeight,
232 const NameListWrapper& rListWrp = NO_LIST,
233 FormatType eFmtType = FORMATTYPE_DEC );
235 // ------------------------------------------------------------------------
237 String DumpString( const sal_Char* pcName = 0, XclStrFlags nFlags = EXC_STR_DEFAULT );
238 double DumpRk( const sal_Char* pcName = 0 );
239 sal_uInt8 DumpBoolean( const sal_Char* pcName = 0 );
240 sal_uInt8 DumpErrorCode( const sal_Char* pcName = 0 );
242 Color DumpRgbColor( const sal_Char* pcName = 0 );
243 rtl_TextEncoding DumpCodePage( const sal_Char* pcName = 0 );
244 void DumpFormulaResult( const sal_Char* pcName = 0 );
246 sal_Int32 DumpColIndex( const sal_Char* pcName = 0, bool bCol16Bit = true );
247 sal_Int32 DumpColRange( const sal_Char* pcName = 0, bool bCol16Bit = true );
248 sal_Int32 DumpRowIndex( const sal_Char* pcName = 0, bool bRow32Bit = false );
249 sal_Int32 DumpRowRange( const sal_Char* pcName = 0, bool bRow32Bit = false );
251 Address DumpAddress( const sal_Char* pcName = 0, bool bCol16Bit = true, bool bRow32Bit = false );
252 Range DumpRange( const sal_Char* pcName = 0, bool bCol16Bit = true, bool bRow32Bit = false );
253 void DumpRangeList( const sal_Char* pcName = 0, bool bCol16Bit = true, bool bRow32Bit = false );
255 void DumpConstArrayHeader( sal_uInt32& rnCols, sal_uInt32& rnRows );
256 String DumpConstValue();
258 template< typename Type >
259 void DumpRect( const sal_Char* pcName,
260 const NameListWrapper& rListWrp = NO_LIST,
261 FormatType eFmtType = FORMATTYPE_DEC );
263 // ------------------------------------------------------------------------
265 using WrappedStreamObject::Construct;
267 private:
268 void ConstructRootObjBase( XclBiff eBiff );
270 private:
271 typedef ScfRef< XclImpStream > XclImpStreamRef;
273 RootDataRef mxRootData;
274 BiffConfigRef mxBiffCfg;
275 XclImpStreamRef mxStrm;
276 XclBiff meBiff;
277 NameListRef mxBoolean;
278 NameListRef mxErrCodes;
279 NameListRef mxConstType;
280 NameListRef mxResultType;
283 // ----------------------------------------------------------------------------
285 template< typename Type >
286 void RootObjectBase::WriteRectItem( const sal_Char* pcName,
287 Type nLeft, Type nTop, Type nWidth, Type nHeight,
288 const NameListWrapper& rListWrp, FormatType eFmtType )
290 MultiItemsGuard aMultiGuard( Out() );
291 WriteEmptyItem( pcName );
292 WriteValueItem( "x-pos", nLeft, eFmtType, rListWrp );
293 WriteValueItem( "y-pos", nTop, eFmtType, rListWrp );
294 WriteValueItem( "x-size", nWidth, eFmtType, rListWrp );
295 WriteValueItem( "y-size", nHeight, eFmtType, rListWrp );
298 template< typename Type >
299 void RootObjectBase::DumpRect( const sal_Char* pcName,
300 const NameListWrapper& rListWrp, FormatType eFmtType )
302 Type nLeft, nTop, nWidth, nHeight;
303 *mxStrm >> nLeft >> nTop >> nWidth >> nHeight;
304 WriteRectItem( pcName, nLeft, nTop, nWidth, nHeight, rListWrp, eFmtType );
307 // ============================================================================
308 // ============================================================================
310 class SimpleObjectBase : public RootObjectBase
312 public:
313 virtual ~SimpleObjectBase();
315 protected:
316 inline explicit SimpleObjectBase() {}
317 void Construct( const RootObjectBase& rParent );
319 virtual void ImplDumpHeader();
320 virtual void ImplDumpFooter();
322 using RootObjectBase::Construct;
325 // ============================================================================
326 // ============================================================================
328 /** Stack to create a human readable formula string from a UPN token array. */
329 class FormulaStack
331 public:
332 explicit FormulaStack();
334 inline const String& GetFormulaString() const { return GetString( maFmlaStack ); }
335 inline const String& GetClassesString() const { return GetString( maClassStack ); }
337 void PushOperand( const StringWrapper& rOp, const String& rTokClass );
338 void PushOperand( const StringWrapper& rOp );
339 void PushUnaryOp( const StringWrapper& rLOp, const StringWrapper& rROp );
340 void PushBinaryOp( const StringWrapper& rOp );
341 void PushFuncOp( const StringWrapper& rFunc, const String& rTokClass, sal_uInt8 nParamCount );
343 inline void SetError() { mbError = true; }
344 void ReplaceOnTop( const String& rOld, const String& rNew );
346 private:
347 typedef ::std::stack< String > StringStack;
349 inline bool Check( bool bCond ) { return (mbError |= !bCond) == false; }
351 const String& GetString( const StringStack& rStack ) const;
352 void PushUnaryOp( StringStack& rStack, const String& rLOp, const String& rROp );
353 void PushBinaryOp( StringStack& rStack, const String& rOp );
354 void PushFuncOp( StringStack& rStack, const String& rOp, sal_uInt8 nParamCount );
356 private:
357 StringStack maFmlaStack;
358 StringStack maClassStack;
359 bool mbError;
362 // ============================================================================
364 class FormulaObject : public SimpleObjectBase
366 public:
367 explicit FormulaObject( const RootObjectBase& rParent );
368 virtual ~FormulaObject();
370 sal_uInt16 ReadFormulaSize();
371 sal_uInt16 DumpFormulaSize( const sal_Char* pcName = 0 );
373 void DumpCellFormula( const sal_Char* pcName, sal_uInt16 nSize );
374 void DumpCellFormula( const sal_Char* pcName = 0 );
375 void DumpNameFormula( const sal_Char* pcName, sal_uInt16 nSize );
376 void DumpNameFormula( const sal_Char* pcName = 0 );
378 protected:
379 virtual void ImplDumpHeader();
380 virtual void ImplDumpBody();
382 private:
383 void ConstructFmlaObj();
385 void DumpFormula( const sal_Char* pcName, sal_uInt16 nSize, bool bNameMode );
386 void DumpFormula( const sal_Char* pcName, bool bNameMode );
388 FormulaAddress CreateTokenAddress( sal_uInt16 nCol, sal_uInt16 nRow, bool bRelC, bool bRelR, bool bNameMode ) const;
389 String CreateFunc( sal_uInt16 nFuncIdx ) const;
390 String CreateRef( const String& rData ) const;
391 String CreateName( sal_uInt16 nNameIdx ) const;
392 String CreatePlaceHolder( size_t nIdx ) const;
393 String CreatePlaceHolder() const;
395 void WriteTokenAddressItem( const sal_Char* pcName, const FormulaAddress& rPos, bool bNameMode );
396 void WriteTokenAddress3dItem( const sal_Char* pcName, const String& rRef, const FormulaAddress& rPos, bool bNameMode );
397 void WriteTokenRangeItem( const sal_Char* pcName, const FormulaRange& rRange, bool bNameMode );
398 void WriteTokenRange3dItem( const sal_Char* pcName, const String& rRef, const FormulaRange& rRange, bool bNameMode );
400 sal_uInt16 DumpTokenFuncIdx();
401 sal_uInt16 DumpTokenCol( const sal_Char* pcName, bool& rbRelC, bool& rbRelR );
402 sal_uInt16 DumpTokenRow( const sal_Char* pcName, bool& rbRelC, bool& rbRelR );
403 FormulaAddress DumpTokenAddress( bool bNameMode );
404 FormulaRange DumpTokenRange( bool bNameMode );
405 String DumpTokenRefIdx();
406 void DumpTokenRefTabIdxs();
408 void DumpIntToken();
409 void DumpDoubleToken();
410 void DumpStringToken();
411 void DumpBoolToken();
412 void DumpErrorToken();
413 void DumpMissArgToken();
415 void DumpArrayToken( const String& rTokClass );
416 void DumpNameToken( const String& rTokClass );
417 void DumpNameXToken( const String& rTokClass );
418 void DumpRefToken( const String& rTokClass, bool bNameMode );
419 void DumpAreaToken( const String& rTokClass, bool bNameMode );
420 void DumpRefErrToken( const String& rTokClass, bool bArea );
421 void DumpRef3dToken( const String& rTokClass, bool bNameMode );
422 void DumpArea3dToken( const String& rTokClass, bool bNameMode );
423 void DumpRefErr3dToken( const String& rTokClass, bool bArea );
424 void DumpMemFuncToken( const String& rTokClass );
425 void DumpMemAreaToken( const String& rTokClass, bool bAddData );
427 void DumpExpToken( const StringWrapper& rName );
428 void DumpUnaryOpToken( const StringWrapper& rLOp, const StringWrapper& rROp );
429 void DumpBinaryOpToken( const StringWrapper& rOp );
430 void DumpFuncToken( const String& rTokClass );
431 void DumpFuncVarToken( const String& rTokClass );
432 void DumpCmdToken( const String& rTokClass );
434 void DumpSheetToken();
435 void DumpEndSheetToken();
436 bool DumpAttrToken();
438 bool DumpNlrToken();
439 void DumpNlrErrToken();
440 void DumpNlrColRowToken( const String& rTokClass, bool bAddData );
441 void DumpNlrRangeToken( const String& rTokClass, bool bAddData );
442 void DumpNlrRangeErrToken();
444 void DumpAddTokenData();
445 void DumpAddDataNlr( size_t nIdx );
446 void DumpAddDataArray( size_t nIdx );
447 void DumpAddDataMemArea( size_t nIdx );
449 private:
450 enum AddDataType { ADDDATA_NLR, ADDDATA_ARRAY, ADDDATA_MEMAREA };
452 typedef ScfRef< FormulaStack > FormulaStackRef;
453 typedef ScfRef< XclFunctionProvider > XclFuncProvRef;
454 typedef ::std::vector< AddDataType > AddDataTypeVec;
456 NameListRef mxTokens;
457 NameListRef mxClasses;
458 NameListRef mxFuncNames;
459 NameListRef mxParamCnt;
460 NameListRef mxRelFlags;
461 NameListRef mxNlrTypes;
462 NameListRef mxAttrTypes;
463 NameListRef mxSpTypes;
465 FormulaStackRef mxStack;
466 XclFuncProvRef mxFuncProv;
467 AddDataTypeVec maAddData;
468 String maRefPrefix;
469 const sal_Char* mpcName;
470 sal_uInt16 mnSize;
471 bool mbNameMode;
474 typedef ScfRef< FormulaObject > FormulaObjectRef;
476 // ============================================================================
477 // ============================================================================
479 class RecordStreamObject : public RootObjectBase
481 public:
482 explicit RecordStreamObject( const ObjectBase& rParent, SvStream& rStrm, XclBiff eBiff = EXC_BIFF_UNKNOWN );
483 explicit RecordStreamObject( const OleStorageObject& rParentStrg, const String& rStrmName, XclBiff eBiff = EXC_BIFF_UNKNOWN );
484 virtual ~RecordStreamObject();
486 protected:
487 inline explicit RecordStreamObject() {}
488 void Construct( const ObjectBase& rParent, SvStream& rStrm, XclBiff eBiff );
489 void Construct( const OleStorageObject& rParentStrg, const String& rStrmName, XclBiff eBiff );
491 virtual bool ImplIsValid() const;
492 virtual void ImplDumpBody();
494 virtual void ImplPreProcessRecord();
495 virtual void ImplDumpRecord();
496 virtual void ImplPostProcessRecord();
498 inline RecordHeaderObject& GetRecordHeader() const { return *mxHdrObj; }
499 inline FormulaObject& GetFormulaDumper() const { return *mxFmlaObj; }
500 inline DffDumpObject& GetDffDumper() const { return *mxDffObj; }
502 void DumpRepeatedRecordId();
504 using RootObjectBase::Construct;
506 private:
507 void ConstructRecStrmObj();
509 void DumpRecordBody();
510 void DumpSimpleRecord( const String& rRecData );
512 private:
513 String maProgressName;
514 RecHeaderObjectRef mxHdrObj;
515 FormulaObjectRef mxFmlaObj;
516 DffDumpObjectRef mxDffObj;
517 NameListRef mxSimpleRecs;
520 // ============================================================================
522 class WorkbookStreamObject : public RecordStreamObject
524 public:
525 explicit WorkbookStreamObject( const ObjectBase& rParent, SvStream& rStrm );
526 explicit WorkbookStreamObject( const OleStorageObject& rParentStrg, const String& rStrmName );
527 virtual ~WorkbookStreamObject();
529 protected:
530 virtual void ImplPreProcessRecord();
531 virtual void ImplDumpRecord();
532 virtual void ImplPostProcessRecord();
534 private:
535 void ConstructWbStrmObj();
537 const XclFontData* GetFontData( sal_uInt16 nFontIdx ) const;
538 sal_uInt16 GetXfData( sal_uInt16 nXfIdx ) const;
539 rtl_TextEncoding GetFontEncoding( sal_uInt16 nXfIdx ) const;
540 String CreateFontName( const XclFontData& rFontData ) const;
542 template< typename Type >
543 Type DumpPatternIdx( const sal_Char* pcName = 0 );
544 template< typename Type >
545 Type DumpColorIdx( const sal_Char* pcName = 0 );
547 sal_uInt16 DumpFontIdx( const sal_Char* pcName = 0 );
548 sal_uInt16 DumpFormatIdx( const sal_Char* pcName = 0 );
549 sal_uInt16 DumpXfIdx( const sal_Char* pcName = 0, bool bBiff2Style = false );
551 sal_uInt16 DumpCellHeader( bool bBiff2Style = false );
552 void DumpBoolErr();
554 void DumpFontRec();
555 void DumpFormatRec();
556 void DumpXfRec();
558 void DumpObjRec();
559 void DumpObjRec5();
560 void DumpObjRec8();
562 private:
563 typedef ::std::vector< XclFontData > XclFontDataVec;
565 NameListRef mxColors;
566 NameListRef mxBorderStyles;
567 NameListRef mxFillPatterns;
568 NameListRef mxFontNames;
569 NameListRef mxFormats;
570 XclFontDataVec maFontDatas;
571 ScfUInt16Vec maXfDatas;
572 sal_uInt16 mnFormatIdx;
573 sal_uInt16 mnPTRowFields;
574 sal_uInt16 mnPTColFields;
575 sal_uInt16 mnPTSxliIdx;
576 bool mbHasCodePage;
579 // ----------------------------------------------------------------------------
581 template< typename Type >
582 Type WorkbookStreamObject::DumpPatternIdx( const sal_Char* pcName )
584 return DumpDec< Type >( pcName ? pcName : "fill-pattern", mxFillPatterns );
587 template< typename Type >
588 Type WorkbookStreamObject::DumpColorIdx( const sal_Char* pcName )
590 return DumpDec< Type >( pcName ? pcName : "color-idx", mxColors );
593 // ============================================================================
595 class PivotCacheStreamObject : public RecordStreamObject
597 public:
598 explicit PivotCacheStreamObject( const ObjectBase& rParent, SvStream& rStrm );
599 explicit PivotCacheStreamObject( const OleStorageObject& rParentStrg, const String& rStrmName );
600 virtual ~PivotCacheStreamObject();
602 protected:
603 virtual void ImplDumpRecord();
606 // ============================================================================
608 class VbaProjectStreamObject : public OleStreamObject
610 public:
611 explicit VbaProjectStreamObject( const OleStorageObject& rParentStrg );
613 protected:
614 virtual void ImplDumpBody();
617 // ============================================================================
618 // ============================================================================
620 class PivotCacheStorageObject : public OleStorageObject
622 public:
623 explicit PivotCacheStorageObject( const OleStorageObject& rParentStrg );
625 protected:
626 virtual void ImplDumpBody();
629 // ============================================================================
631 class VbaProjectStorageObject : public OleStorageObject
633 public:
634 explicit VbaProjectStorageObject( const OleStorageObject& rParentStrg );
636 protected:
637 virtual void ImplDumpBody();
640 // ============================================================================
642 class VbaStorageObject : public OleStorageObject
644 public:
645 explicit VbaStorageObject( const OleStorageObject& rParentStrg );
647 protected:
648 virtual void ImplDumpBody();
651 // ============================================================================
653 class RootStorageObject : public OleStorageObject
655 public:
656 explicit RootStorageObject( const ObjectBase& rParent );
658 protected:
659 virtual void ImplDumpBody();
662 // ============================================================================
663 // ============================================================================
665 class Dumper : public DumperBase
667 public:
668 explicit Dumper( SfxMedium& rMedium, SfxObjectShell* pDocShell );
670 protected:
671 virtual void ImplDumpBody();
674 // ============================================================================
675 // ============================================================================
677 } // namespace xls
678 } // namespace dump
679 } // namespace scf
681 #endif
682 #endif