diff options
Diffstat (limited to 'oox/inc/oox/xls')
26 files changed, 1356 insertions, 752 deletions
diff --git a/oox/inc/oox/xls/biffhelper.hxx b/oox/inc/oox/xls/biffhelper.hxx index 5552a5e5ce52..7c34fc346010 100644 --- a/oox/inc/oox/xls/biffhelper.hxx +++ b/oox/inc/oox/xls/biffhelper.hxx @@ -442,6 +442,7 @@ const sal_uInt16 BIFF_ID_MTHREADSETTINGS = 0x089A; const sal_uInt16 BIFF_ID_MULTBLANK = 0x00BE; const sal_uInt16 BIFF_ID_MULTRK = 0x00BD; const sal_uInt16 BIFF_ID_NOTE = 0x001C; +const sal_uInt16 BIFF_ID_NOTESOUND = 0x0096; const sal_uInt16 BIFF2_ID_NUMBER = 0x0003; const sal_uInt16 BIFF3_ID_NUMBER = 0x0203; const sal_uInt16 BIFF_ID_OBJ = 0x005D; @@ -620,7 +621,7 @@ public: // BIFF12 import ---------------------------------------------------------- /** Reads a BIFF12 string with leading 16-bit or 32-bit length field. */ - static ::rtl::OUString readString( SequenceInputStream& rStrm, bool b32BitLen = true ); + static ::rtl::OUString readString( SequenceInputStream& rStrm, bool b32BitLen = true, bool bAllowNulChars = false ); // BIFF2-BIFF8 import ----------------------------------------------------- diff --git a/oox/inc/oox/xls/biffinputstream.hxx b/oox/inc/oox/xls/biffinputstream.hxx index 003ab28be34f..9f0ffa853ebc 100644 --- a/oox/inc/oox/xls/biffinputstream.hxx +++ b/oox/inc/oox/xls/biffinputstream.hxx @@ -242,30 +242,30 @@ public: // BinaryStreamBase interface (seeking) ----------------------------------- - /** Returns true, as the BIFF input stream is required to be seekable. */ - virtual bool isSeekable() const; + /** Returns the data size of the whole record without record headers. */ + virtual sal_Int64 size() const; /** Returns the position inside of the whole record content. */ virtual sal_Int64 tell() const; - /** Returns the data size of the whole record without record headers. */ - virtual sal_Int64 getLength() const; /** Seeks in record content to the specified position. */ virtual void seek( sal_Int64 nRecPos ); + /** Closes the input stream but not the wrapped stream. */ + virtual void close(); /** Returns the absolute position in the wrapped binary stream. */ sal_Int64 tellBase() const; /** Returns the total size of the wrapped binary stream. */ - sal_Int64 getBaseLength() const; + sal_Int64 sizeBase() const; // BinaryInputStream interface (stream read access) ----------------------- /** Reads nBytes bytes to the passed sequence. @return Number of bytes really read. */ - virtual sal_Int32 readData( StreamDataSequence& orData, sal_Int32 nBytes ); + virtual sal_Int32 readData( StreamDataSequence& orData, sal_Int32 nBytes, size_t nAtomSize = 1 ); /** Reads nBytes bytes and copies them to the passed buffer opMem. @return Number of bytes really read. */ - virtual sal_Int32 readMemory( void* opMem, sal_Int32 nBytes ); + virtual sal_Int32 readMemory( void* opMem, sal_Int32 nBytes, size_t nAtomSize = 1 ); /** Seeks forward inside the current record. */ - virtual void skip( sal_Int32 nBytes ); + virtual void skip( sal_Int32 nBytes, size_t nAtomSize = 1 ); /** Stream operator for integral and floating-point types. */ template< typename Type > @@ -352,9 +352,6 @@ public: // ------------------------------------------------------------------------ private: - /** Forwards calls of readValue() template functions to the record buffer. */ - virtual void readAtom( void* opMem, sal_uInt8 nSize ); - /** Initializes all members after base stream has been seeked to new record. */ void setupRecord(); /** Restarts the current record from the beginning. */ @@ -383,16 +380,9 @@ private: records, stores the length in mnComplRecSize. */ void calcRecordLength(); - /** Ensures that reading nBytes bytes is possible with next stream access. - @descr Stream must be located at the end of a raw record, and handling - of CONTINUE records must be enabled. - @return True if nBytes can be read from stream. */ - bool ensureRawReadSize( sal_uInt16 nBytes ); /** Returns the maximum size of raw data possible to read in one block. */ - sal_uInt16 getMaxRawReadSize( sal_Int32 nBytes ) const; + sal_uInt16 getMaxRawReadSize( sal_Int32 nBytes, size_t nAtomSize ) const; - /** Reads an array of Unicode characters and appends them to the passed buffer. */ - void appendUnicodeArray( ::rtl::OUStringBuffer& orBuffer, sal_uInt16 nChars, bool b16BitChars, bool bAllowNulChars ); /** Reads the BIFF8 Unicode string header fields. */ void readUniStringHeader( bool& orb16BitChars, sal_Int32& ornAddSize ); diff --git a/oox/inc/oox/xls/biffoutputstream.hxx b/oox/inc/oox/xls/biffoutputstream.hxx index ada646bd879a..7d03572be5ec 100644 --- a/oox/inc/oox/xls/biffoutputstream.hxx +++ b/oox/inc/oox/xls/biffoutputstream.hxx @@ -94,9 +94,6 @@ private: CONTINUE record, use setPortionSize(). Example: To write a sequence of 16-bit values where 4 values form a unit and cannot be split, call setPortionSize(8) first (4*2 bytes == 8). - - To write unicode character arrays, call writeUnicodeBuffer(). It creates - CONTINUE records and repeats the unicode string flag byte automatically. */ class BiffOutputStream : public BinaryOutputStream { @@ -113,47 +110,44 @@ public: /** Finishes the current record. Must be called for every started record. */ void endRecord(); - /** Sets size of data portion in bytes. 0 means no portions are used. */ - void setPortionSize( sal_uInt16 nSize ); + /** Sets size of data portion in bytes. 0 or 1 means no portions are used. */ + void setPortionSize( sal_uInt8 nSize ); // BinaryStreamBase interface (seeking) ----------------------------------- /** Returns the absolute position in the wrapped binary stream. */ sal_Int64 tellBase() const; /** Returns the total size of the wrapped binary stream. */ - sal_Int64 getBaseLength() const; + sal_Int64 sizeBase() const; // BinaryOutputStream interface (stream write access) --------------------- /** Writes the passed data sequence. */ - virtual void writeData( const StreamDataSequence& rData ); + virtual void writeData( const StreamDataSequence& rData, size_t nAtomSize = 1 ); /** Writes nBytes bytes from the passed buffer pMem. */ - virtual void writeMemory( const void* pMem, sal_Int32 nBytes ); + virtual void writeMemory( const void* pMem, sal_Int32 nBytes, size_t nAtomSize = 1 ); /** Writes a sequence of nBytes bytes with the passed value. */ - void fill( sal_uInt8 nValue, sal_Int32 nBytes ); - /** Writes a block of memory, ensures that it is not split to a CONTINUE record. */ - void writeBlock( const void* pMem, sal_uInt16 nBytes ); + void fill( sal_uInt8 nValue, sal_Int32 nBytes, size_t nAtomSize = 1 ); - /** Stream operator for integral and floating-point types. */ + /** Stream operator for all data types supported by the writeValue() function. */ template< typename Type > inline BiffOutputStream& operator<<( Type nValue ) { writeValue( nValue ); return *this; } // ------------------------------------------------------------------------ private: - /** Forwards calls of writeValue() template functions to the record buffer. */ - virtual void writeAtom( const void* pMem, sal_uInt8 nSize ); - /** Checks the remaining size in the current record, creates CONTINUE record if needed. */ void ensureRawBlock( sal_uInt16 nSize ); - /** Checks the remaining size in the current record and creates CONTINUE record if needed. + + /** Checks the remaining size in the current record and creates a CONTINUE + record if needed. @return Maximum size left for writing to current record. */ - sal_uInt16 prepareRawBlock( sal_Int32 nTotalSize ); + sal_uInt16 prepareWriteBlock( sal_Int32 nTotalSize, size_t nAtomSize ); private: prv::BiffOutputRecordBuffer maRecBuffer; /// Raw record data buffer. - sal_uInt16 mnPortionSize; /// Size of data portions. - sal_uInt16 mnPortionPos; /// Position in current portion. + sal_uInt8 mnPortionSize; /// Size of data portions. + sal_uInt8 mnPortionPos; /// Position in current portion. }; // ============================================================================ diff --git a/oox/inc/oox/xls/chartsheetfragment.hxx b/oox/inc/oox/xls/chartsheetfragment.hxx index 8dfedc5ba48e..2ff482ccd960 100644 --- a/oox/inc/oox/xls/chartsheetfragment.hxx +++ b/oox/inc/oox/xls/chartsheetfragment.hxx @@ -39,10 +39,8 @@ class ChartsheetFragment : public WorksheetFragmentBase { public: explicit ChartsheetFragment( - const WorkbookHelper& rHelper, - const ::rtl::OUString& rFragmentPath, - const ISegmentProgressBarRef& rxProgressBar, - sal_Int16 nSheet ); + const WorksheetHelper& rHelper, + const ::rtl::OUString& rFragmentPath ); protected: virtual ::oox::core::ContextHandlerRef onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ); @@ -67,9 +65,8 @@ class BiffChartsheetFragment : public BiffWorksheetFragmentBase { public: explicit BiffChartsheetFragment( - const BiffWorkbookFragmentBase& rParent, - const ISegmentProgressBarRef& rxProgressBar, - sal_Int16 nSheet ); + const WorksheetHelper& rHelper, + const BiffWorkbookFragmentBase& rParent ); /** Imports the entire sheet fragment, returns true, if EOF record has been reached. */ virtual bool importFragment(); diff --git a/oox/inc/oox/xls/commentsbuffer.hxx b/oox/inc/oox/xls/commentsbuffer.hxx index e87d52ff03a2..406a03534584 100644 --- a/oox/inc/oox/xls/commentsbuffer.hxx +++ b/oox/inc/oox/xls/commentsbuffer.hxx @@ -40,8 +40,11 @@ struct CommentModel { ::com::sun::star::table::CellRangeAddress maRange; /// Position of the comment in the worksheet. - RichStringRef mxText; /// Formatted text of the comment. - sal_Int32 mnAuthorId; /// Identifier of the comment's author. + RichStringRef mxText; /// Formatted text of the comment (not used in BIFF8). + ::rtl::OUString maAuthor; /// Comment author (BIFF8 only). + sal_Int32 mnAuthorId; /// Identifier of the comment's author (OOXML and BIFF12 only). + sal_uInt16 mnObjId; /// Drawing object identifier (BIFF8 only). + bool mbVisible; /// True = comment is always shown (BIFF2-BIFF8 only). explicit CommentModel(); }; @@ -57,6 +60,8 @@ public: void importComment( const AttributeList& rAttribs ); /** Imports a cell comment from the passed stream of a COMMENT record. */ void importComment( SequenceInputStream& rStrm ); + /** Imports a cell comment from the passed stream of a NOTE record. */ + void importNote( BiffInputStream& rStrm ); /** Creates and returns a new rich-string object for the comment text. */ RichStringRef createText(); @@ -65,6 +70,14 @@ public: void finalizeImport(); private: + /** Reads a BIFF2-BIFF5 NOTE record. */ + void importNoteBiff2( BiffInputStream& rStrm ); + /** Reads a BIFF8 NOTE record. */ + void importNoteBiff8( BiffInputStream& rStrm ); + /** Reads a NOTESOUND record. */ + void importNoteSound( BiffInputStream& rStrm ); + +private: CommentModel maModel; }; diff --git a/oox/inc/oox/xls/condformatbuffer.hxx b/oox/inc/oox/xls/condformatbuffer.hxx index fae6381f6402..7b651856036d 100644 --- a/oox/inc/oox/xls/condformatbuffer.hxx +++ b/oox/inc/oox/xls/condformatbuffer.hxx @@ -44,9 +44,9 @@ namespace xls { /** Model for a single rule in a conditional formatting. */ struct CondFormatRuleModel { - typedef ::std::vector< TokensFormulaContext > ContextVector; + typedef ::std::vector< ApiTokenSequence > ApiTokenSequenceVector; - ContextVector maFormulas; /// Formulas for rule conditions. + ApiTokenSequenceVector maFormulas; /// Formulas for rule conditions. ::rtl::OUString maText; /// Text for 'contains' rules. sal_Int32 mnPriority; /// Priority of this rule. sal_Int32 mnType; /// Type of the rule. diff --git a/oox/inc/oox/xls/defnamesbuffer.hxx b/oox/inc/oox/xls/defnamesbuffer.hxx index 5374c47f6a07..f26a51a1f04c 100644 --- a/oox/inc/oox/xls/defnamesbuffer.hxx +++ b/oox/inc/oox/xls/defnamesbuffer.hxx @@ -37,7 +37,6 @@ namespace com { namespace sun { namespace star { namespace oox { namespace xls { -class FormulaContext; class BiffInputStreamPos; // ============================================================================ @@ -91,15 +90,15 @@ public: /** Returns the original name as imported from or exported to the file. */ const ::rtl::OUString& getUpcaseModelName() const; /** Returns an Any with a SingleReference or ComplexReference, or an empty Any. */ - ::com::sun::star::uno::Any getReference( const ::com::sun::star::table::CellAddress& rBaseAddress ) const; + ::com::sun::star::uno::Any getReference( const ::com::sun::star::table::CellAddress& rBaseAddr ) const; protected: - /** Imports the OOXML formula string, using the passed formula context. */ - void importOoxFormula( FormulaContext& rContext, sal_Int16 nBaseSheet ); - /** Imports the BIFF12 formula, using the passed formula context. */ - void importBiff12Formula( FormulaContext& rContext, sal_Int16 nBaseSheet, SequenceInputStream& rStrm ); - /** Imports the BIFF formula, using the passed formula context. */ - void importBiffFormula( FormulaContext& rContext, sal_Int16 nBaseSheet, BiffInputStream& rStrm, const sal_uInt16* pnFmlaSize = 0 ); + /** Converts the OOXML formula string stored in the own model. */ + ApiTokenSequence importOoxFormula( sal_Int16 nBaseSheet ); + /** Imports the BIFF12 formula from the passed stream. */ + ApiTokenSequence importBiff12Formula( sal_Int16 nBaseSheet, SequenceInputStream& rStrm ); + /** Imports the BIFF formula from the passed stream. */ + ApiTokenSequence importBiffFormula( sal_Int16 nBaseSheet, BiffInputStream& rStrm, const sal_uInt16* pnFmlaSize = 0 ); /** Tries to convert the passed token sequence to a SingleReference or ComplexReference. */ void extractReference( const ApiTokenSequence& rTokens ); @@ -151,10 +150,10 @@ public: bool getAbsoluteRange( ::com::sun::star::table::CellRangeAddress& orRange ) const; private: - /** Imports the OOXML or BIFF12 formula, using the passed formula context. */ - void implImportOoxFormula( FormulaContext& rContext ); - /** Imports the BIFF formula, using the passed formula context. */ - void implImportBiffFormula( FormulaContext& rContext ); + /** Imports the OOXML or BIFF12 definition of the name. */ + void implImportOoxFormula(); + /** Imports the BIFF definition of the name. */ + void implImportBiffFormula(); private: typedef ::std::auto_ptr< StreamDataSequence > StreamDataSeqPtr; diff --git a/oox/inc/oox/xls/drawingbase.hxx b/oox/inc/oox/xls/drawingbase.hxx new file mode 100755 index 000000000000..01bf43a6434f --- /dev/null +++ b/oox/inc/oox/xls/drawingbase.hxx @@ -0,0 +1,147 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef OOX_XLS_DRAWINGBASE_HXX +#define OOX_XLS_DRAWINGBASE_HXX + +#include "oox/drawingml/drawingmltypes.hxx" +#include "oox/xls/worksheethelper.hxx" + +namespace oox { +namespace xls { + +// ============================================================================ + +/** Absolute position in a spreadsheet (in EMUs) independent from cells. */ +struct AnchorPointModel : public ::oox::drawingml::EmuPoint +{ + inline explicit AnchorPointModel() : ::oox::drawingml::EmuPoint( -1, -1 ) {} + inline bool isValid() const { return (X >= 0) && (Y >= 0); } +}; + +// ---------------------------------------------------------------------------- + +/** Absolute size in a spreadsheet (in EMUs). */ +struct AnchorSizeModel : public ::oox::drawingml::EmuSize +{ + inline explicit AnchorSizeModel() : ::oox::drawingml::EmuSize( -1, -1 ) {} + inline bool isValid() const { return (Width >= 0) && (Height >= 0); } +}; + +// ---------------------------------------------------------------------------- + +/** Position in spreadsheet (cell position and offset inside cell). */ +struct CellAnchorModel +{ + sal_Int32 mnCol; /// Column index. + sal_Int32 mnRow; /// Row index. + sal_Int64 mnColOffset; /// X offset inside the column. + sal_Int64 mnRowOffset; /// Y offset inside the row. + + explicit CellAnchorModel(); + inline bool isValid() const { return (mnCol >= 0) && (mnRow >= 0); } +}; + +// ---------------------------------------------------------------------------- + +/** Application-specific client data of a shape. */ +struct AnchorClientDataModel +{ + bool mbLocksWithSheet; + bool mbPrintsWithSheet; + + explicit AnchorClientDataModel(); +}; + +// ============================================================================ + +/** Contains the position of a shape in the spreadsheet. Supports different + shape anchor modes (absolute, one-cell, two-cell). */ +class ShapeAnchor : public WorksheetHelper +{ +public: + explicit ShapeAnchor( const WorksheetHelper& rHelper ); + + /** Imports the shape anchor (one of the elements xdr:absoluteAnchor, xdr:oneCellAnchor, xdr:twoCellAnchor). */ + void importAnchor( sal_Int32 nElement, const AttributeList& rAttribs ); + /** Imports the absolute anchor position from the xdr:pos element. */ + void importPos( const AttributeList& rAttribs ); + /** Imports the absolute anchor size from the xdr:ext element. */ + void importExt( const AttributeList& rAttribs ); + /** Imports the shape client data from the xdr:clientData element. */ + void importClientData( const AttributeList& rAttribs ); + /** Sets an attribute of the cell-dependent anchor position from xdr:from and xdr:to elements. */ + void setCellPos( sal_Int32 nElement, sal_Int32 nParentContext, const ::rtl::OUString& rValue ); + /** Imports the client anchor settings from a VML element. */ + void importVmlAnchor( const ::rtl::OUString& rAnchor ); + /** Imports the client anchor settings from a BIFF or DFF stream. */ + void importBiffAnchor( BinaryInputStream& rStrm ); + + /** Calculates the resulting shape anchor in EMUs. */ + ::oox::drawingml::EmuRectangle calcAnchorRectEmu( + const ::com::sun::star::awt::Size& rPageSizeHmm ) const; + /** Calculates the resulting shape anchor in 1/100 mm. */ + ::com::sun::star::awt::Rectangle calcAnchorRectHmm( + const ::com::sun::star::awt::Size& rPageSizeHmm ) const; + +private: + /** Converts the passed anchor to an absolute position in EMUs. */ + ::oox::drawingml::EmuPoint calcCellAnchorEmu( const CellAnchorModel& rModel ) const; + +private: + enum AnchorType + { + ANCHOR_INVALID, /// Anchor type is unknown. + ANCHOR_ABSOLUTE, /// Absolute anchor (top-left corner and size in absolute units). + ANCHOR_ONECELL, /// One-cell anchor (top-left corner at cell, size in absolute units). + ANCHOR_TWOCELL /// Two-cell anchor (top-left and bottom-right corner at cell). + }; + + /** Specifies how cell positions from CellAnchorModel have to be processed. */ + enum CellAnchorType + { + CELLANCHOR_EMU, /// Offsets are given in EMUs. + CELLANCHOR_PIXEL, /// Offsets are given in screen pixels. + CELLANCHOR_COLROW /// Offsets are given in fractions of column width or row height. + }; + + AnchorType meAnchorType; /// Type of this shape anchor. + CellAnchorType meCellAnchorType; /// Type of the cell anchor models. + AnchorPointModel maPos; /// Top-left position, if anchor is of type absolute. + AnchorSizeModel maSize; /// Anchor size, if anchor is not of type two-cell. + CellAnchorModel maFrom; /// Top-left position, if anchor is not of type absolute. + CellAnchorModel maTo; /// Bottom-right position, if anchor is of type two-cell. + AnchorClientDataModel maClientData; /// Shape client data. + sal_Int32 mnEditAs; /// Anchor mode as shown in the UI. +}; + +// ============================================================================ + +} // namespace xls +} // namespace oox + +#endif diff --git a/oox/inc/oox/xls/drawingfragment.hxx b/oox/inc/oox/xls/drawingfragment.hxx index 0d3360323a94..d71c1a25b436 100644 --- a/oox/inc/oox/xls/drawingfragment.hxx +++ b/oox/inc/oox/xls/drawingfragment.hxx @@ -37,6 +37,7 @@ #include "oox/vml/vmldrawing.hxx" #include "oox/vml/vmldrawingfragment.hxx" #include "oox/vml/vmltextbox.hxx" +#include "oox/xls/drawingbase.hxx" #include "oox/xls/excelhandlers.hxx" namespace oox { namespace ole { @@ -51,98 +52,6 @@ namespace xls { // DrawingML // ============================================================================ -/** Absolute position in spreadsheet (in EMUs) independent from cells. */ -struct AnchorPosModel : public ::oox::drawingml::EmuPoint -{ - inline explicit AnchorPosModel() : ::oox::drawingml::EmuPoint( -1, -1 ) {} - inline bool isValid() const { return (X >= 0) && (Y >= 0); } -}; - -// ---------------------------------------------------------------------------- - -/** Absolute size in spreadsheet (in EMUs). */ -struct AnchorSizeModel : public ::oox::drawingml::EmuSize -{ - inline explicit AnchorSizeModel() : ::oox::drawingml::EmuSize( -1, -1 ) {} - inline bool isValid() const { return (Width >= 0) && (Height >= 0); } -}; - -// ---------------------------------------------------------------------------- - -/** Position in spreadsheet (cell position and offset inside cell in EMUs). */ -struct AnchorCellModel -{ - sal_Int32 mnCol; /// Column index. - sal_Int32 mnRow; /// Row index. - sal_Int64 mnColOffset; /// X offset in column mnCol (EMUs). - sal_Int64 mnRowOffset; /// Y offset in row mnRow (EMUs). - - explicit AnchorCellModel(); - inline bool isValid() const { return (mnCol >= 0) && (mnRow >= 0); } -}; - -// ---------------------------------------------------------------------------- - -/** Application-specific client data of a shape. */ -struct AnchorClientDataModel -{ - bool mbLocksWithSheet; - bool mbPrintsWithSheet; - - explicit AnchorClientDataModel(); -}; - -// ============================================================================ - -/** Contains the position of a shape in the spreadsheet. Supports different - shape anchor modes (absolute, one-cell, two-cell). */ -class ShapeAnchor : public WorksheetHelper -{ -public: - explicit ShapeAnchor( const WorksheetHelper& rHelper ); - - /** Imports the shape anchor (one of the elements xdr:absoluteAnchor, xdr:oneCellAnchor, xdr:twoCellAnchor). */ - void importAnchor( sal_Int32 nElement, const AttributeList& rAttribs ); - /** Imports the absolute anchor position from the xdr:pos element. */ - void importPos( const AttributeList& rAttribs ); - /** Imports the absolute anchor size from the xdr:ext element. */ - void importExt( const AttributeList& rAttribs ); - /** Imports the shape client data from the xdr:clientData element. */ - void importClientData( const AttributeList& rAttribs ); - /** Sets an attribute of the cell-dependent anchor position from xdr:from and xdr:to elements. */ - void setCellPos( sal_Int32 nElement, sal_Int32 nParentContext, const ::rtl::OUString& rValue ); - /** Imports and converts the VML specific client anchor. */ - void importVmlAnchor( const ::rtl::OUString& rAnchor ); - - /** Returns true, if the anchor contains valid position and size settings. */ - bool isValidAnchor() const; - - /** Calculates the resulting shape anchor in 1/100 mm. */ - ::com::sun::star::awt::Rectangle - calcApiLocation( - const ::com::sun::star::awt::Size& rApiSheetSize, - const AnchorSizeModel& rEmuSheetSize ) const; - - /** Calculates the resulting shape anchor in EMUs. */ - ::com::sun::star::awt::Rectangle - calcEmuLocation( const AnchorSizeModel& rEmuSheetSize ) const; - -private: - enum AnchorType { ANCHOR_ABSOLUTE, ANCHOR_ONECELL, ANCHOR_TWOCELL, ANCHOR_VML, ANCHOR_INVALID }; - - AnchorType meType; /// Type of this shape anchor. - AnchorPosModel maPos; /// Top-left position, if anchor is of type absolute. - AnchorSizeModel maSize; /// Anchor size, if anchor is not of type two-cell. - AnchorCellModel maFrom; /// Top-left position, if anchor is not of type absolute. - AnchorCellModel maTo; /// Bottom-right position, if anchor is of type two-cell. - AnchorClientDataModel maClientData; /// Shape client data. - sal_Int32 mnEditAs; /// Anchor mode as shown in the UI. -}; - -typedef ::boost::shared_ptr< ShapeAnchor > ShapeAnchorRef; - -// ============================================================================ - class ShapeMacroAttacher : public ::oox::ole::VbaMacroAttacherBase { public: @@ -220,10 +129,10 @@ protected: virtual void onEndElement(); private: + typedef ::std::auto_ptr< ShapeAnchor > ShapeAnchorRef; + ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShapes > mxDrawPage; /// Drawing page of this sheet. - ::com::sun::star::awt::Size maApiSheetSize; /// Sheet size in 1/100 mm. - AnchorSizeModel maEmuSheetSize; /// Sheet size in EMU. ::oox::drawingml::ShapePtr mxShape; /// Current top-level shape. ShapeAnchorRef mxAnchor; /// Current anchor of top-level shape. }; diff --git a/oox/inc/oox/xls/drawingmanager.hxx b/oox/inc/oox/xls/drawingmanager.hxx new file mode 100755 index 000000000000..91fba91ee271 --- /dev/null +++ b/oox/inc/oox/xls/drawingmanager.hxx @@ -0,0 +1,521 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef OOX_XLS_DRAWINGMANAGER_HXX +#define OOX_XLS_DRAWINGMANAGER_HXX + +#include "oox/xls/drawingbase.hxx" + +namespace com { namespace sun { namespace star { + namespace drawing { class XDrawPage; } + namespace drawing { class XShape; } + namespace drawing { class XShapes; } +} } } + +namespace oox { namespace drawingml { class ShapePropertyMap; } } + +namespace oox { +namespace xls { + +// ============================================================================ + +const sal_uInt16 BIFF_OBJ_INVALID_ID = 0; + +// ============================================================================ +// Model structures for BIFF OBJ record data +// ============================================================================ + +/** This structure contains line formatting attributes from an OBJ record. */ +struct BiffObjLineModel +{ + sal_uInt8 mnColorIdx; /// Index into color palette. + sal_uInt8 mnStyle; /// Line dash style. + sal_uInt8 mnWidth; /// Line width. + bool mbAuto; /// True = automatic line format. + + explicit BiffObjLineModel(); + + /** Returns true, if the line formatting is visible (automatic or explicit). */ + bool isVisible() const; +}; + +// ============================================================================ + +/** This structure contains fill formatting attributes from an OBJ record. */ +struct BiffObjFillModel +{ + sal_uInt8 mnBackColorIdx; /// Index to color palette for background color. + sal_uInt8 mnPattColorIdx; /// Index to color palette for pattern foreground color. + sal_uInt8 mnPattern; /// Fill pattern. + bool mbAuto; /// True = automatic fill format. + + explicit BiffObjFillModel(); + + /** Returns true, if the fill formatting is visible (automatic or explicit). */ + bool isFilled() const; +}; + +// ============================================================================ + +/** This structure contains text formatting attributes from an OBJ record. */ +struct BiffObjTextModel +{ + sal_uInt16 mnTextLen; /// Length of the text (characters). + sal_uInt16 mnFormatSize; /// Size of the formatting array (bytes). + sal_uInt16 mnLinkSize; /// Size of the linked text formula (bytes). + sal_uInt16 mnDefFontId; /// Font index for default font formatting. + sal_uInt16 mnFlags; /// Additional flags. + sal_uInt16 mnOrientation; /// Text orientation. + sal_uInt16 mnButtonFlags; /// Additional flags for push buttons. + sal_uInt16 mnShortcut; /// Shortcut character. + sal_uInt16 mnShortcutEA; /// East-asian shortcut character. + + explicit BiffObjTextModel(); + + /** Reads text data from a BIFF3/BIFF4 OBJ record. */ + void readObj3( BiffInputStream& rStrm ); + /** Reads text data from a BIFF5 OBJ record. */ + void readObj5( BiffInputStream& rStrm ); + /** Reads text data from a BIFF8 TXO record. */ + void readTxo8( BiffInputStream& rStrm ); + + /** Returns the horizontal alignment of the text. */ + sal_uInt8 getHorAlign() const; + /** Returns the vertical alignment of the text. */ + sal_uInt8 getVerAlign() const; +}; + +// ============================================================================ +// BIFF drawing objects +// ============================================================================ + +class BiffDrawingBase; +class BiffDrawingObjectBase; +typedef ::boost::shared_ptr< BiffDrawingObjectBase > BiffDrawingObjectRef; + +// ---------------------------------------------------------------------------- + +class BiffDrawingObjectContainer +{ +public: + explicit BiffDrawingObjectContainer(); + + /** Returns true, if the object list is empty. */ + inline bool empty() const { return maObjects.empty(); } + + /** Appends the passed object to the list of objects. */ + void append( const BiffDrawingObjectRef& rxDrawingObj ); + /** Tries to insert the passed object into the last group or appends it. */ + void insertGrouped( const BiffDrawingObjectRef& rxDrawingObj ); + + /** Creates and inserts all UNO shapes into the passed shape container. */ + void convertAndInsert( BiffDrawingBase& rDrawing, + const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShapes >& rxShapes, + const ::com::sun::star::awt::Rectangle* pParentRect = 0 ) const; + +private: + typedef RefVector< BiffDrawingObjectBase > BiffDrawingObjectVector; + BiffDrawingObjectVector maObjects; +}; + +// ============================================================================ + +/** Base class for all BIFF drawing objects (OBJ records). */ +class BiffDrawingObjectBase : public WorksheetHelper +{ +public: + explicit BiffDrawingObjectBase( const WorksheetHelper& rHelper ); + virtual ~BiffDrawingObjectBase(); + + /** Reads the BIFF3 OBJ record, returns a new drawing object. */ + static BiffDrawingObjectRef importObjBiff3( const WorksheetHelper& rHelper, BiffInputStream& rStrm ); + /** Reads the BIFF4 OBJ record, returns a new drawing object. */ + static BiffDrawingObjectRef importObjBiff4( const WorksheetHelper& rHelper, BiffInputStream& rStrm ); + /** Reads the BIFF5 OBJ record, returns a new drawing object. */ + static BiffDrawingObjectRef importObjBiff5( const WorksheetHelper& rHelper, BiffInputStream& rStrm ); + /** Reads the BIFF8 OBJ record, returns a new drawing object. */ + static BiffDrawingObjectRef importObjBiff8( const WorksheetHelper& rHelper, BiffInputStream& rStrm ); + + /** Sets whether this is an area object (then its width and height must be greater than 0). */ + inline void setAreaObj( bool bAreaObj ) { mbAreaObj = bAreaObj; } + /** If set to true, the object supports a simple on-click macro and/or hyperlink. */ + inline void setSimpleMacro( bool bMacro ) { mbSimpleMacro = bMacro; } + + /** If set to false, the UNO shape will not be created, processed, or inserted into the draw page. */ + inline void setProcessShape( bool bProcess ) { mbProcessShape = bProcess; } + /** If set to false, the UNO shape will be created or processed, but not be inserted into the draw page. */ + inline void setInsertShape( bool bInsert ) { mbInsertShape = bInsert; } + /** If set to true, a new custom UNO shape will be created while in DFF import (BIFF8 only). */ + inline void setCustomDffObj( bool bCustom ) { mbCustomDff = bCustom; } + + /** Returns the object identifier from the OBJ record. */ + inline sal_uInt16 getObjId() const { return mnObjId; } + /** Returns the object type from the OBJ record. */ + inline sal_uInt16 getObjType() const { return mnObjType; } + + /** Returns true, if the object is hidden. */ + inline bool isHidden() const { return mbHidden; } + /** Returns true, if the object is visible. */ + inline bool isVisible() const { return mbVisible; } + /** Returns true, if the object is printable. */ + inline bool isPrintable() const { return mbPrintable; } + + /** Creates the UNO shape and inserts it into the passed shape container. */ + ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape > + convertAndInsert( BiffDrawingBase& rDrawing, + const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShapes >& rxShapes, + const ::com::sun::star::awt::Rectangle* pParentRect = 0 ) const; + +protected: + /** Reads the object name in a BIFF5 OBJ record. */ + void readNameBiff5( BiffInputStream& rStrm, sal_uInt16 nNameLen ); + /** Reads the macro link in a BIFF3 OBJ record. */ + void readMacroBiff3( BiffInputStream& rStrm, sal_uInt16 nMacroSize ); + /** Reads the macro link in a BIFF4 OBJ record. */ + void readMacroBiff4( BiffInputStream& rStrm, sal_uInt16 nMacroSize ); + /** Reads the macro link in a BIFF5 OBJ record. */ + void readMacroBiff5( BiffInputStream& rStrm, sal_uInt16 nMacroSize ); + /** Reads the contents of the ftMacro sub structure in an OBJ record. */ + void readMacroBiff8( BiffInputStream& rStrm ); + + /** Converts the passed line formatting to the passed property map. */ + void convertLineProperties( ::oox::drawingml::ShapePropertyMap& rPropMap, const BiffObjLineModel& rLineModel, sal_uInt16 nArrows = 0 ) const; + /** Converts the passed fill formatting to the passed property map. */ + void convertFillProperties( ::oox::drawingml::ShapePropertyMap& rPropMap, const BiffObjFillModel& rFillModel ) const; + /** Converts the passed frame flags to the passed property map. */ + void convertFrameProperties( ::oox::drawingml::ShapePropertyMap& rPropMap, sal_uInt16 nFrameFlags ) const; + + /** Derived classes read the contents of the a BIFF3 OBJ record from the passed stream. */ + virtual void implReadObjBiff3( BiffInputStream& rStrm, sal_uInt16 nMacroSize ); + /** Derived classes read the contents of the a BIFF4 OBJ record from the passed stream. */ + virtual void implReadObjBiff4( BiffInputStream& rStrm, sal_uInt16 nMacroSize ); + /** Derived classes read the contents of the a BIFF5 OBJ record from the passed stream. */ + virtual void implReadObjBiff5( BiffInputStream& rStrm, sal_uInt16 nNameLen, sal_uInt16 nMacroSize ); + /** Derived classes read the contents of the specified subrecord of a BIFF8 OBJ record from stream. */ + virtual void implReadObjBiff8SubRec( BiffInputStream& rStrm, sal_uInt16 nSubRecId, sal_uInt16 nSubRecSize ); + + /** Derived classes create the corresponding XShape and insert it into the passed container. */ + virtual ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape > + implConvertAndInsert( BiffDrawingBase& rDrawing, + const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShapes >& rxShapes, + const ::com::sun::star::awt::Rectangle& rShapeRect ) const = 0; + +private: + /** Reads the contents of a BIFF3 OBJ record. */ + void importObjBiff3( BiffInputStream& rStrm ); + /** Reads the contents of a BIFF4 OBJ record. */ + void importObjBiff4( BiffInputStream& rStrm ); + /** Reads the contents of a BIFF5 OBJ record. */ + void importObjBiff5( BiffInputStream& rStrm ); + /** Reads the contents of a BIFF8 OBJ record. */ + void importObjBiff8( BiffInputStream& rStrm ); + +private: + ShapeAnchor maAnchor; /// Position of the drawing object. + ::rtl::OUString maObjName; /// Name of the object. + ::rtl::OUString maMacroName; /// Name of an attached macro. + ::rtl::OUString maHyperlink; /// On-click hyperlink URL. + sal_uInt32 mnDffShapeId; /// Shape identifier from DFF stream (BIFF8 only). + sal_uInt32 mnDffFlags; /// Shape flags from DFF stream. + sal_uInt16 mnObjId; /// The object identifier (unique per drawing). + sal_uInt16 mnObjType; /// The object type from OBJ record. + bool mbHasAnchor; /// True = anchor has been initialized. + bool mbHidden; /// True = object is hidden. + bool mbVisible; /// True = object is visible (form controls). + bool mbPrintable; /// True = object is printable. + bool mbAreaObj; /// True = width and height must be greater than 0. + bool mbAutoMargin; /// True = set automatic text margin. + bool mbSimpleMacro; /// True = create simple macro link and hyperlink. + bool mbProcessShape; /// True = object is valid, do processing and insertion. + bool mbInsertShape; /// True = insert the UNO shape into the draw page. + bool mbCustomDff; /// True = recreate UNO shape in DFF import (BIFF8 only). +}; + +// ============================================================================ + +/** A placeholder object for unknown/unsupported object types. */ +class BiffPlaceholderObject : public BiffDrawingObjectBase +{ +public: + explicit BiffPlaceholderObject( const WorksheetHelper& rHelper ); + +protected: + /** Creates the corresponding XShape and insert it into the passed container. */ + virtual ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape > + implConvertAndInsert( BiffDrawingBase& rDrawing, + const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShapes >& rxShapes, + const ::com::sun::star::awt::Rectangle& rShapeRect ) const; +}; + +// ============================================================================ + +/** A group object that is able to contain other child objects. */ +class BiffGroupObject : public BiffDrawingObjectBase +{ +public: + explicit BiffGroupObject( const WorksheetHelper& rHelper ); + + /** Tries to insert the passed drawing object into this or a nested group. */ + bool tryInsert( const BiffDrawingObjectRef& rxDrawingObj ); + +protected: + /** Reads the contents of the a BIFF3 OBJ record from the passed stream. */ + virtual void implReadObjBiff3( BiffInputStream& rStrm, sal_uInt16 nMacroSize ); + /** Reads the contents of the a BIFF4 OBJ record from the passed stream. */ + virtual void implReadObjBiff4( BiffInputStream& rStrm, sal_uInt16 nMacroSize ); + /** Reads the contents of the a BIFF5 OBJ record from the passed stream. */ + virtual void implReadObjBiff5( BiffInputStream& rStrm, sal_uInt16 nNameLen, sal_uInt16 nMacroSize ); + + /** Creates the corresponding XShape and insert it into the passed container. */ + virtual ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape > + implConvertAndInsert( BiffDrawingBase& rDrawing, + const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShapes >& rxShapes, + const ::com::sun::star::awt::Rectangle& rShapeRect ) const; + +protected: + BiffDrawingObjectContainer maChildren; /// All child objects contained in this group object. + sal_uInt16 mnFirstUngrouped; /// Object identfier of first object not grouped into this group. +}; + +// ============================================================================ + +/** A simple line object. */ +class BiffLineObject : public BiffDrawingObjectBase +{ +public: + explicit BiffLineObject( const WorksheetHelper& rHelper ); + +protected: + /** Reads the contents of the a BIFF3 OBJ record from the passed stream. */ + virtual void implReadObjBiff3( BiffInputStream& rStrm, sal_uInt16 nMacroSize ); + /** Reads the contents of the a BIFF4 OBJ record from the passed stream. */ + virtual void implReadObjBiff4( BiffInputStream& rStrm, sal_uInt16 nMacroSize ); + /** Reads the contents of the a BIFF5 OBJ record from the passed stream. */ + virtual void implReadObjBiff5( BiffInputStream& rStrm, sal_uInt16 nNameLen, sal_uInt16 nMacroSize ); + + /** Creates the corresponding XShape and insert it into the passed container. */ + virtual ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape > + implConvertAndInsert( BiffDrawingBase& rDrawing, + const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShapes >& rxShapes, + const ::com::sun::star::awt::Rectangle& rShapeRect ) const; + +protected: + BiffObjLineModel maLineModel; /// Line formatting. + sal_uInt16 mnArrows; /// Line arrows. + sal_uInt8 mnStartPoint; /// Starting point. +}; + +// ============================================================================ + +/** A simple rectangle object (used as base class for oval objects). */ +class BiffRectObject : public BiffDrawingObjectBase +{ +public: + explicit BiffRectObject( const WorksheetHelper& rHelper ); + +protected: + /** Reads the fill model, the line model, and frame flags. */ + void readFrameData( BiffInputStream& rStrm ); + + /** Converts fill formatting, line formatting, and frame style. */ + void convertRectProperties( ::oox::drawingml::ShapePropertyMap& rPropMap ) const; + + /** Reads the contents of the a BIFF3 OBJ record from the passed stream. */ + virtual void implReadObjBiff3( BiffInputStream& rStrm, sal_uInt16 nMacroSize ); + /** Reads the contents of the a BIFF4 OBJ record from the passed stream. */ + virtual void implReadObjBiff4( BiffInputStream& rStrm, sal_uInt16 nMacroSize ); + /** Reads the contents of the a BIFF5 OBJ record from the passed stream. */ + virtual void implReadObjBiff5( BiffInputStream& rStrm, sal_uInt16 nNameLen, sal_uInt16 nMacroSize ); + + /** Creates the corresponding XShape and insert it into the passed container. */ + virtual ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape > + implConvertAndInsert( BiffDrawingBase& rDrawing, + const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShapes >& rxShapes, + const ::com::sun::star::awt::Rectangle& rShapeRect ) const; + +protected: + BiffObjFillModel maFillModel; /// Fill formatting. + BiffObjLineModel maLineModel; /// Line formatting. + sal_uInt16 mnFrameFlags; /// Additional flags. +}; + +// ============================================================================ + +/** A simple oval object. */ +class BiffOvalObject : public BiffRectObject +{ +public: + explicit BiffOvalObject( const WorksheetHelper& rHelper ); + +protected: + /** Creates the corresponding XShape and insert it into the passed container. */ + virtual ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape > + implConvertAndInsert( BiffDrawingBase& rDrawing, + const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShapes >& rxShapes, + const ::com::sun::star::awt::Rectangle& rShapeRect ) const; +}; + +// ============================================================================ + +/** A simple arc object. */ +class BiffArcObject : public BiffDrawingObjectBase +{ +public: + explicit BiffArcObject( const WorksheetHelper& rHelper ); + +protected: + /** Reads the contents of the a BIFF3 OBJ record from the passed stream. */ + virtual void implReadObjBiff3( BiffInputStream& rStrm, sal_uInt16 nMacroSize ); + /** Reads the contents of the a BIFF4 OBJ record from the passed stream. */ + virtual void implReadObjBiff4( BiffInputStream& rStrm, sal_uInt16 nMacroSize ); + /** Reads the contents of the a BIFF5 OBJ record from the passed stream. */ + virtual void implReadObjBiff5( BiffInputStream& rStrm, sal_uInt16 nNameLen, sal_uInt16 nMacroSize ); + + /** Creates the corresponding XShape and insert it into the passed container. */ + virtual ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape > + implConvertAndInsert( BiffDrawingBase& rDrawing, + const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShapes >& rxShapes, + const ::com::sun::star::awt::Rectangle& rShapeRect ) const; + +protected: + BiffObjFillModel maFillModel; /// Fill formatting. + BiffObjLineModel maLineModel; /// Line formatting. + sal_uInt8 mnQuadrant; /// Visible quadrant of the circle. +}; + +// ============================================================================ + +/** A simple polygon object. */ +class BiffPolygonObject : public BiffRectObject +{ +public: + explicit BiffPolygonObject( const WorksheetHelper& rHelper ); + +protected: + /** Reads the contents of the a BIFF4 OBJ record from the passed stream. */ + virtual void implReadObjBiff4( BiffInputStream& rStrm, sal_uInt16 nMacroSize ); + /** Reads the contents of the a BIFF5 OBJ record from the passed stream. */ + virtual void implReadObjBiff5( BiffInputStream& rStrm, sal_uInt16 nNameLen, sal_uInt16 nMacroSize ); + + /** Creates the corresponding XShape and insert it into the passed container. */ + virtual ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape > + implConvertAndInsert( BiffDrawingBase& rDrawing, + const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShapes >& rxShapes, + const ::com::sun::star::awt::Rectangle& rShapeRect ) const; + +private: + /** Reads the COORDLIST record following the OBJ record. */ + void importCoordList( BiffInputStream& rStrm ); + +protected: + typedef ::std::vector< ::com::sun::star::awt::Point > PointVector; + PointVector maCoords; /// Coordinates relative to bounding rectangle. + sal_uInt16 mnPolyFlags; /// Additional flags. + sal_uInt16 mnPointCount; /// Polygon point count. +}; + +// ============================================================================ +// BIFF drawing page +// ============================================================================ + +/** Base class for a container for all objects on a drawing page (in a + spreadsheet or in an embedded chart object). + + For BIFF import, it is needed to load all drawing objects before converting + them to UNO shapes. There might be some dummy drawing objects (e.g. the + dropdown buttons of autofilters) which have to be skipped. The information, + that a drawing object is a dummy object, may be located after the drawing + objects themselves. + + The BIFF8 format stores drawing objects in the DFF stream (stored + fragmented in MSODRAWING records), and in the OBJ records. The DFF stream + fragments are collected in a single stream, and the complete stream will be + processed afterwards. + */ +class BiffDrawingBase : public WorksheetHelper +{ +public: + explicit BiffDrawingBase( const WorksheetHelper& rHelper, + const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XDrawPage >& rxDrawPage ); + + /** Imports a plain OBJ record (without leading DFF data). */ + void importObj( BiffInputStream& rStrm ); + /** Sets the object with the passed identifier to be skipped on import. */ + void setSkipObj( sal_uInt16 nObjId ); + + /** Final processing after import of the all drawing objects. */ + void finalizeImport(); + + /** Creates a new UNO shape object, inserts it into the passed UNO shape + container, and sets the shape position and size. */ + ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape > + createAndInsertXShape( + const ::rtl::OUString& rService, + const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShapes >& rxShapes, + const ::com::sun::star::awt::Rectangle& rShapeRect ) const; + + /** Derived classes may want to know that a shape has been inserted. Will + be called from the convertAndInsert() implementation. */ + virtual void notifyShapeInserted( + const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape >& rxShape, + const ::com::sun::star::awt::Rectangle& rShapeRect ) = 0; + +protected: + /** Appends a new drawing object to the list of raw objects (without DFF data). */ + void appendRawObject( const BiffDrawingObjectRef& rxDrawingObj ); + +private: + typedef RefMap< sal_uInt16, BiffDrawingObjectBase > BiffDrawingObjectMapById; + typedef ::std::vector< sal_uInt16 > BiffObjIdVector; + + ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XDrawPage > + mxDrawPage; /// UNO draw page used to insert the shapes. + BiffDrawingObjectContainer maRawObjs; /// Drawing objects without DFF data. + BiffDrawingObjectMapById maObjMapId; /// Maps drawing objects by their object identifiers. + BiffObjIdVector maSkipObjs; /// Identifiers of all objects to be skipped. +}; + +// ---------------------------------------------------------------------------- + +/** Drawing manager of a single sheet. */ +class BiffSheetDrawing : public BiffDrawingBase +{ +public: + explicit BiffSheetDrawing( const WorksheetHelper& rHelper ); + + /** Called when a new UNO shape has been inserted into the draw page. */ + virtual void notifyShapeInserted( + const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape >& rxShape, + const ::com::sun::star::awt::Rectangle& rShapeRect ); +}; + +// ============================================================================ + +} // namespace xls +} // namespace oox + +#endif diff --git a/oox/inc/oox/xls/excelfilter.hxx b/oox/inc/oox/xls/excelfilter.hxx index 789cbc99cb07..1e10a91e25c2 100644 --- a/oox/inc/oox/xls/excelfilter.hxx +++ b/oox/inc/oox/xls/excelfilter.hxx @@ -34,23 +34,23 @@ namespace oox { namespace xls { -class WorkbookData; +class WorkbookGlobals; // ============================================================================ class ExcelFilterBase { public: - void registerWorkbookData( WorkbookData& rData ); - WorkbookData& getWorkbookData() const; - void unregisterWorkbookData(); + void registerWorkbookGlobals( WorkbookGlobals& rBookGlob ); + WorkbookGlobals& getWorkbookGlobals() const; + void unregisterWorkbookGlobals(); protected: explicit ExcelFilterBase(); virtual ~ExcelFilterBase(); private: - WorkbookData* mpData; + WorkbookGlobals* mpBookGlob; }; // ============================================================================ diff --git a/oox/inc/oox/xls/excelhandlers.hxx b/oox/inc/oox/xls/excelhandlers.hxx index 864f5f9a9e44..deaa5244b0d0 100644 --- a/oox/inc/oox/xls/excelhandlers.hxx +++ b/oox/inc/oox/xls/excelhandlers.hxx @@ -45,55 +45,24 @@ class WorkbookContextBase : public ::oox::core::ContextHandler2, public Workbook { public: template< typename ParentType > - explicit WorkbookContextBase( ParentType& rParent ); + inline explicit WorkbookContextBase( ParentType& rParent ) : + ::oox::core::ContextHandler2( rParent ), WorkbookHelper( rParent ) {} }; -// ---------------------------------------------------------------------------- - -template< typename ParentType > -WorkbookContextBase::WorkbookContextBase( ParentType& rParent ) : - ::oox::core::ContextHandler2( rParent ), - WorkbookHelper( rParent ) -{ -} - // ============================================================================ /** Context handler derived from the WorksheetHelper helper class. Used to import contexts in sheet fragments. */ -class WorksheetContextBase : public ::oox::core::ContextHandler2, public WorksheetHelperRoot +class WorksheetContextBase : public ::oox::core::ContextHandler2, public WorksheetHelper { public: template< typename ParentType > - explicit WorksheetContextBase( - ParentType& rParent, - const ISegmentProgressBarRef& rxProgressBar, - WorksheetType eSheetType, - sal_Int16 nSheet ); - - template< typename ParentType > - explicit WorksheetContextBase( ParentType& rParent ); + inline explicit WorksheetContextBase( ParentType& rParent ) : + ::oox::core::ContextHandler2( rParent ), WorksheetHelper( rParent ) {} }; -// ---------------------------------------------------------------------------- - -template< typename ParentType > -WorksheetContextBase::WorksheetContextBase( ParentType& rParent, - const ISegmentProgressBarRef& rxProgressBar, WorksheetType eSheetType, sal_Int16 nSheet ) : - ::oox::core::ContextHandler2( rParent ), - WorksheetHelperRoot( rParent, rxProgressBar, eSheetType, nSheet ) -{ -} - -template< typename ParentType > -WorksheetContextBase::WorksheetContextBase( ParentType& rParent ) : - ::oox::core::ContextHandler2( rParent ), - WorksheetHelperRoot( rParent ) -{ -} - // ============================================================================ /** Fragment handler derived from the WorkbookHelper helper class. @@ -114,17 +83,10 @@ public: Used to import sheet fragments. */ -class WorksheetFragmentBase : public ::oox::core::FragmentHandler2, public WorksheetHelperRoot +class WorksheetFragmentBase : public ::oox::core::FragmentHandler2, public WorksheetHelper { public: explicit WorksheetFragmentBase( - const WorkbookHelper& rHelper, - const ::rtl::OUString& rFragmentPath, - const ISegmentProgressBarRef& rxProgressBar, - WorksheetType eSheetType, - sal_Int16 nSheet ); - - explicit WorksheetFragmentBase( const WorksheetHelper& rHelper, const ::rtl::OUString& rFragmentPath ); }; @@ -164,15 +126,9 @@ protected: Used to import contexts in sheet fragments. */ -class BiffWorksheetContextBase : public BiffContextHandler, public WorksheetHelperRoot +class BiffWorksheetContextBase : public BiffContextHandler, public WorksheetHelper { protected: - explicit BiffWorksheetContextBase( - const WorkbookHelper& rHelper, - const ISegmentProgressBarRef& rxProgressBar, - WorksheetType eSheetType, - sal_Int16 nSheet ); - explicit BiffWorksheetContextBase( const WorksheetHelper& rHelper ); }; @@ -220,17 +176,6 @@ protected: */ BiffFragmentType startFragment( BiffType eBiff ); - /** Starts a new fragment at a specific position in the workbbok stream and - returns the fragment type. - - The passed record handle must specify the stream position of the BOF - record of the fragment substream. The function will try to start the - next record and read the contents of the BOF record, if extant. - - @return Fragment type according to the imported BOF record. - */ - BiffFragmentType startFragment( BiffType eBiff, sal_Int64 nRecHandle ); - /** Skips the current fragment up to its trailing EOF record. Skips all records until next EOF record. When this function returns, @@ -273,14 +218,12 @@ protected: Used to import sheet fragments. */ -class BiffWorksheetFragmentBase : public BiffFragmentHandler, public WorksheetHelperRoot +class BiffWorksheetFragmentBase : public BiffFragmentHandler, public WorksheetHelper { protected: explicit BiffWorksheetFragmentBase( - const BiffWorkbookFragmentBase& rParent, - const ISegmentProgressBarRef& rxProgressBar, - WorksheetType eSheetType, - sal_Int16 nSheet ); + const WorksheetHelper& rHelper, + const BiffWorkbookFragmentBase& rParent ); }; // ---------------------------------------------------------------------------- @@ -291,9 +234,8 @@ class BiffSkipWorksheetFragment : public BiffWorksheetFragmentBase { public: explicit BiffSkipWorksheetFragment( - const BiffWorkbookFragmentBase& rParent, - const ISegmentProgressBarRef& rxProgressBar, - sal_Int16 nSheet ); + const WorksheetHelper& rHelper, + const BiffWorkbookFragmentBase& rParent ); virtual bool importFragment(); }; diff --git a/oox/inc/oox/xls/formulabase.hxx b/oox/inc/oox/xls/formulabase.hxx index 013e63f3bf30..f7891c0ba940 100644 --- a/oox/inc/oox/xls/formulabase.hxx +++ b/oox/inc/oox/xls/formulabase.hxx @@ -28,6 +28,7 @@ #ifndef OOX_XLS_FORMULABASE_HXX #define OOX_XLS_FORMULABASE_HXX +#include <com/sun/star/beans/Pair.hpp> #include <com/sun/star/sheet/FormulaOpCodeMapEntry.hpp> #include <com/sun/star/sheet/FormulaToken.hpp> #include <com/sun/star/table/CellAddress.hpp> @@ -40,7 +41,6 @@ namespace com { namespace sun { namespace star { namespace sheet { class XFormulaOpCodeMapper; } namespace sheet { class XFormulaParser; } - namespace sheet { class XFormulaTokens; } } } } namespace oox { template< typename Type > class Matrix; } @@ -216,7 +216,20 @@ const sal_uInt16 BIFF_FUNC_CEILING = 288; /// Function identif const sal_uInt16 BIFF_FUNC_HYPERLINK = 359; /// Function identifier of the HYPERLINK function. const sal_uInt16 BIFF_FUNC_WEEKNUM = 465; /// Function identifier of the WEEKNUM function. -// reference helpers ========================================================== +// Formula type =============================================================== + +/** Enumerates all possible types of a formula. */ +enum FormulaType +{ + FORMULATYPE_CELL, /// Simple cell formula, or reference to a shared formula name. + FORMULATYPE_ARRAY, /// Array (matrix) formula. + FORMULATYPE_SHAREDFORMULA, /// Shared formula definition. + FORMULATYPE_CONDFORMAT, /// Condition of a conditional format rule. + FORMULATYPE_VALIDATION, /// Condition of a data validation. + FORMULATYPE_DEFINEDNAME /// Definition of a defined name. +}; + +// Reference helpers ========================================================== /** A 2D formula cell reference struct with relative flags. */ struct BinSingleRef2d @@ -250,11 +263,15 @@ struct BinComplexRef2d void readBiff8Data( BiffInputStream& rStrm, bool bRelativeAsOffset ); }; -// token vector, sequence ===================================================== +// Token vector, token sequence =============================================== typedef ::com::sun::star::sheet::FormulaToken ApiToken; typedef ::com::sun::star::uno::Sequence< ApiToken > ApiTokenSequence; +/** Contains the base address and type of a special token representing an array + formula or a shared formula (sal_False), or a table operation (sal_True). */ +typedef ::com::sun::star::beans::Pair< ::com::sun::star::table::CellAddress, sal_Bool > ApiSpecialTokenInfo; + /** A vector of formula tokens with additional convenience functions. */ class ApiTokenVector : public ::std::vector< ApiToken > { @@ -270,7 +287,7 @@ public: inline void append( sal_Int32 nOpCode, const Type& rData ) { append( nOpCode ) <<= rData; } }; -// token sequence iterator ==================================================== +// Token sequence iterator ==================================================== /** Token sequence iterator that is able to skip space tokens. */ class ApiTokenIterator @@ -297,7 +314,7 @@ private: const bool mbSkipSpaces; /// true = Skip whitespace tokens. }; -// list of API op-codes ======================================================= +// List of API op-codes ======================================================= /** Contains all API op-codes needed to build formulas with tokens. */ struct ApiOpCodes @@ -456,23 +473,23 @@ struct FunctionParamInfo bool mbValType; /// Data type (false = REFTYPE, true = VALTYPE). }; -// function data ============================================================== +// Function data ============================================================== /** This enumeration contains constants for all known external libraries containing supported sheet functions. */ enum FunctionLibraryType { - FUNCLIB_EUROTOOL, /// EuroTool add-in with EUROCONVERT function. - FUNCLIB_UNKNOWN /// Unknown library. + FUNCLIB_UNKNOWN = 0, /// Unknown library (must be zero). + FUNCLIB_EUROTOOL /// EuroTool add-in with EUROCONVERT function. }; // ---------------------------------------------------------------------------- /** Represents information for a spreadsheet function. - The member mpParamInfos points to an array of type information structures + The member mpParamInfos points to a C-array of type information structures for all parameters of the function. The last initialized structure - describing a regular parameter (member meValid == EXC_PARAMVALID_ALWAYS) in + describing a regular parameter (member meValid == FUNC_PARAM_REGULAR) in this array is used repeatedly for all following parameters supported by a function. */ @@ -490,7 +507,7 @@ struct FunctionInfo sal_uInt8 mnMaxParamCount; /// Maximum number of parameters. sal_uInt8 mnRetClass; /// BIFF token class of the return value. const FunctionParamInfo* mpParamInfos; /// Information about all parameters. - bool mbParamPairs; /// true = optional parameters are expected to appear in pairs. + bool mbParamPairs; /// True = optional parameters are expected to appear in pairs. bool mbVolatile; /// True = volatile function. bool mbExternal; /// True = external function in Calc. bool mbMacroFunc; /// True = macro sheet function or command. @@ -499,7 +516,7 @@ struct FunctionInfo typedef RefVector< FunctionInfo > FunctionInfoVector; -// function info parameter class iterator ===================================== +// Function info parameter class iterator ===================================== /** Iterator working on the mpParamInfos member of the FunctionInfo struct. @@ -525,7 +542,7 @@ private: bool mbParamPairs; }; -// base function provider ===================================================== +// Base function provider ===================================================== struct FunctionProviderImpl; @@ -566,7 +583,7 @@ private: FunctionProviderImplRef mxFuncImpl; /// Shared implementation between all copies of the provider. }; -// op-code and function provider ============================================== +// Op-code and function provider ============================================== struct OpCodeProviderImpl; @@ -577,7 +594,7 @@ class OpCodeProvider : public FunctionProvider // not derived from WorkbookHelpe { public: explicit OpCodeProvider( - const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& rxFactory, + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& rxModelFactory, FilterType eFilter, BiffType eBiff, bool bImportFilter ); virtual ~OpCodeProvider(); @@ -604,7 +621,7 @@ class ApiParserWrapper : public OpCodeProvider { public: explicit ApiParserWrapper( - const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& rxFactory, + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& rxModelFactory, const OpCodeProvider& rOpCodeProv ); /** Returns read/write access to the formula parser property set. */ @@ -621,74 +638,7 @@ private: PropertySet maParserProps; }; -// formula contexts =========================================================== - -class FormulaContext -{ -public: - inline void setBaseAddress( const ::com::sun::star::table::CellAddress& rBaseAddress ) - { maBaseAddress = rBaseAddress; } - - inline const ::com::sun::star::table::CellAddress& getBaseAddress() const { return maBaseAddress; } - inline bool isRelativeAsOffset() const { return mbRelativeAsOffset; } - inline bool is2dRefsAs3dRefs() const { return mb2dRefsAs3dRefs; } - inline bool isNulCharsAllowed() const { return mbAllowNulChars; } - - virtual void setTokens( const ApiTokenSequence& rTokens ) = 0; - virtual void setSharedFormula( const ::com::sun::star::table::CellAddress& rBaseAddr ); - -protected: - explicit FormulaContext( - bool bRelativeAsOffset, - bool b2dRefsAs3dRefs, - bool bAllowNulChars = false ); - virtual ~FormulaContext(); - -private: - ::com::sun::star::table::CellAddress maBaseAddress; - bool mbRelativeAsOffset; - bool mb2dRefsAs3dRefs; - bool mbAllowNulChars; -}; - -// ---------------------------------------------------------------------------- - -/** Stores the converted formula token sequence in a class member. */ -class TokensFormulaContext : public FormulaContext -{ -public: - explicit TokensFormulaContext( - bool bRelativeAsOffset, - bool b2dRefsAs3dRefs, - bool bAllowNulChars = false ); - - inline const ApiTokenSequence& getTokens() const { return maTokens; } - - virtual void setTokens( const ApiTokenSequence& rTokens ); - -private: - ApiTokenSequence maTokens; -}; - -// ---------------------------------------------------------------------------- - -/** Uses the com.sun.star.sheet.XFormulaTokens interface to set a token sequence. */ -class SimpleFormulaContext : public FormulaContext -{ -public: - explicit SimpleFormulaContext( - const ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XFormulaTokens >& rxTokens, - bool bRelativeAsOffset, - bool b2dRefsAs3dRefs, - bool bAllowNulChars = false ); - - virtual void setTokens( const ApiTokenSequence& rTokens ); - -private: - ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XFormulaTokens > mxTokens; -}; - -// formula parser/printer base class for filters ============================== +// Formula parser/printer base class for filters ============================== /** Base class for import formula parsers and export formula compilers. */ class FormulaProcessorBase : public OpCodeProvider, protected ApiOpCodes, public WorkbookHelper @@ -896,6 +846,24 @@ public: ::rtl::OUString& orString, const ApiTokenSequence& rTokens ) const; + /** Tries to extract information about a special token used for array + formulas, shared formulas, or table operations. + + @param orTokenInfo (output parameter) The extracted information about + the token. Contains the base address and the token type (sal_False + for array or shared formulas, sal_True for table operations). + + @param rTokens The token sequence to be parsed. If it contains exactly + one OPCODE_BAD token with special token information, this + information will be extracted. + + @return True = token sequence is valid, output parameter orTokenInfo + contains the token information extracted from the token sequence. + */ + bool extractSpecialTokenInfo( + ApiSpecialTokenInfo& orTokenInfo, + const ApiTokenSequence& rTokens ) const; + /** Converts a single string with separators in the passed formula token sequence to a list of string tokens. diff --git a/oox/inc/oox/xls/formulaparser.hxx b/oox/inc/oox/xls/formulaparser.hxx index c595993264d9..26752951abe4 100644 --- a/oox/inc/oox/xls/formulaparser.hxx +++ b/oox/inc/oox/xls/formulaparser.hxx @@ -87,6 +87,7 @@ private: const ApiToken* getSingleToken( const ApiToken* pToken, const ApiToken* pTokenEnd ) const; const ApiToken* skipParentheses( const ApiToken* pToken, const ApiToken* pTokenEnd ) const; const ApiToken* findParameters( ParameterPosVector& rParams, const ApiToken* pToken, const ApiToken* pTokenEnd ) const; + void appendEmptyParameter( const FunctionInfo& rFuncInfo, size_t nParam ); void appendCalcOnlyParameter( const FunctionInfo& rFuncInfo, size_t nParam ); void appendRequiredParameters( const FunctionInfo& rFuncInfo, size_t nParamCount ); @@ -113,38 +114,36 @@ public: virtual ~FormulaParser(); /** Converts an OOXML formula string. */ - void importFormula( - FormulaContext& rContext, + ApiTokenSequence importFormula( + const ::com::sun::star::table::CellAddress& rBaseAddr, const ::rtl::OUString& rFormulaString ) const; /** Imports and converts a BIFF12 token array from the passed stream. */ - void importFormula( - FormulaContext& rContext, + ApiTokenSequence importFormula( + const ::com::sun::star::table::CellAddress& rBaseAddr, + FormulaType eType, SequenceInputStream& rStrm ) const; /** Imports and converts a BIFF2-BIFF8 token array from the passed stream. @param pnFmlaSize Size of the token array. If null is passed, reads it from stream (1 byte in BIFF2, 2 bytes otherwise) first. */ - void importFormula( - FormulaContext& rContext, + ApiTokenSequence importFormula( + const ::com::sun::star::table::CellAddress& rBaseAddr, + FormulaType eType, BiffInputStream& rStrm, const sal_uInt16* pnFmlaSize = 0 ) const; + /** Converts the passed Boolean value to a similar formula. */ + ApiTokenSequence convertBoolToFormula( bool bValue ) const; + /** Converts the passed BIFF error code to a similar formula. */ - void convertErrorToFormula( - FormulaContext& rContext, - sal_uInt8 nErrorCode ) const; + ApiTokenSequence convertErrorToFormula( sal_uInt8 nErrorCode ) const; /** Converts the passed token index of a defined name to a formula calling that name. */ - void convertNameToFormula( - FormulaContext& rContext, - sal_Int32 nTokenIndex ) const; + ApiTokenSequence convertNameToFormula( sal_Int32 nTokenIndex ) const; /** Converts the passed number into a HYPERLINK formula with the passed URL. */ - void convertNumberToHyperlink( - FormulaContext& rContext, - const ::rtl::OUString& rUrl, - double fValue ) const; + ApiTokenSequence convertNumberToHyperlink( const ::rtl::OUString& rUrl, double fValue ) const; /** Converts the passed XML formula to an OLE link target. */ ::rtl::OUString importOleTargetLink( const ::rtl::OUString& rFormulaString ); @@ -153,9 +152,7 @@ public: ::rtl::OUString importOleTargetLink( SequenceInputStream& rStrm ); /** Imports and converts an OLE link target from the passed stream. */ - ::rtl::OUString importOleTargetLink( - BiffInputStream& rStrm, - const sal_uInt16* pnFmlaSize = 0 ) const; + ::rtl::OUString importOleTargetLink( BiffInputStream& rStrm, const sal_uInt16* pnFmlaSize = 0 ) const; /** Converts the passed formula to a macro name for a drawing shape. */ ::rtl::OUString importMacroName( const ::rtl::OUString& rFormulaString ); diff --git a/oox/inc/oox/xls/ooxformulaparser.hxx b/oox/inc/oox/xls/ooxformulaparser.hxx index 7bc1bbdd4909..f74a6ddf455b 100644 --- a/oox/inc/oox/xls/ooxformulaparser.hxx +++ b/oox/inc/oox/xls/ooxformulaparser.hxx @@ -46,10 +46,10 @@ class OOXMLFormulaPrinterImpl; typedef ::cppu::WeakImplHelper3< ::com::sun::star::lang::XServiceInfo, ::com::sun::star::lang::XInitialization, - ::com::sun::star::sheet::XFilterFormulaParser > OOXMLFormulaParserBase; + ::com::sun::star::sheet::XFilterFormulaParser > OOXMLFormulaParser_BASE; /** OOXML formula parser/compiler service for usage in ODF filters. */ -class OOXMLFormulaParser : public OOXMLFormulaParserBase +class OOXMLFormulaParser : public OOXMLFormulaParser_BASE { public: explicit OOXMLFormulaParser(); diff --git a/oox/inc/oox/xls/pivotcachebuffer.hxx b/oox/inc/oox/xls/pivotcachebuffer.hxx index 2e32d0faa7e5..eeb2d7a02dd9 100644 --- a/oox/inc/oox/xls/pivotcachebuffer.hxx +++ b/oox/inc/oox/xls/pivotcachebuffer.hxx @@ -31,6 +31,7 @@ #include <com/sun/star/table/CellAddress.hpp> #include <com/sun/star/table/CellRangeAddress.hpp> #include <com/sun/star/util/DateTime.hpp> +#include "oox/helper/containerhelper.hxx" #include "oox/helper/refvector.hxx" #include "oox/xls/workbookhelper.hxx" @@ -430,15 +431,15 @@ public: void writeSourceHeaderCells( WorksheetHelper& rSheetHelper ) const; /** Writes a source field item value into the passed sheet. */ void writeSourceDataCell( WorksheetHelper& rSheetHelper, - sal_Int32 nCol, sal_Int32 nRow, + sal_Int32 nColIdx, sal_Int32 nRowIdx, const PivotCacheItem& rItem ) const; /** Reads a PCRECORD record and writes all item values to the passed sheet. */ void importPCRecord( SequenceInputStream& rStrm, - WorksheetHelper& rSheetHelper, sal_Int32 nRow ) const; + WorksheetHelper& rSheetHelper, sal_Int32 nRowIdx ) const; /** Reads a PCITEM_INDEXLIST record and writes all item values to the passed sheet. */ void importPCItemIndexList( BiffInputStream& rStrm, - WorksheetHelper& rSheetHelper, sal_Int32 nRow ) const; + WorksheetHelper& rSheetHelper, sal_Int32 nRowIdx ) const; private: /** Reads the worksheet source range from the DCONREF record. */ @@ -456,6 +457,8 @@ private: void finalizeExternalSheetSource(); /** Creates a dummy sheet that will be filled with the pivot cache data. */ void prepareSourceDataSheet(); + /** Checks, if the row index has changed since last call, and initializes the sheet data buffer. */ + void updateSourceDataRow( WorksheetHelper& rSheetHelper, sal_Int32 nRow ) const; private: typedef RefVector< PivotCacheField > PivotCacheFieldVector; @@ -467,7 +470,9 @@ private: PCDefinitionModel maDefModel; /// Global pivot cache settings. PCSourceModel maSourceModel; /// Pivot cache source settings. PCWorksheetSourceModel maSheetSrcModel; /// Sheet source data if cache type is sheet. + ValueRangeSet maColSpans; /// Column spans used by SheetDataBuffer for optimized cell import. ::rtl::OUString maTargetUrl; /// URL of an external source document. + mutable sal_Int32 mnCurrRow; /// Current row index in dummy sheet. bool mbValidSource; /// True = pivot cache is based on supported data source. bool mbDummySheet; /// True = pivot cache is based on a dummy sheet. }; diff --git a/oox/inc/oox/xls/pivotcachefragment.hxx b/oox/inc/oox/xls/pivotcachefragment.hxx index 34a833e26525..8cb72b31a39c 100644 --- a/oox/inc/oox/xls/pivotcachefragment.hxx +++ b/oox/inc/oox/xls/pivotcachefragment.hxx @@ -81,7 +81,7 @@ class PivotCacheRecordsFragment : public WorksheetFragmentBase { public: explicit PivotCacheRecordsFragment( - const WorkbookHelper& rHelper, + const WorksheetHelper& rHelper, const ::rtl::OUString& rFragmentPath, const PivotCache& rPivotCache ); @@ -97,8 +97,8 @@ private: private: const PivotCache& mrPivotCache; - sal_Int32 mnCol; - sal_Int32 mnRow; + sal_Int32 mnColIdx; /// Relative column index in source data. + sal_Int32 mnRowIdx; /// Relative row index in source data. bool mbInRecord; }; @@ -126,7 +126,7 @@ class BiffPivotCacheRecordsContext : public BiffWorksheetContextBase { public: explicit BiffPivotCacheRecordsContext( - const WorkbookHelper& rHelper, + const WorksheetHelper& rHelper, const PivotCache& rPivotCache ); /** Reads the current record from stream and tries to insert a cell into @@ -142,7 +142,7 @@ private: const PivotCache& mrPivotCache; ColumnIndexVector maUnsharedCols; /// Column indexes of all unshared cache fields. size_t mnColIdx; /// Current index into maUnsharedCols. - sal_Int32 mnRow; /// Current row in source data (0-based). + sal_Int32 mnRowIdx; /// Current row in source data (0-based). bool mbHasShared; /// True = pivot cache contains fields with shared items. bool mbInRow; /// True = a data row has been started. }; diff --git a/oox/inc/oox/xls/richstring.hxx b/oox/inc/oox/xls/richstring.hxx index f21e2a021111..ab8313c35373 100644 --- a/oox/inc/oox/xls/richstring.hxx +++ b/oox/inc/oox/xls/richstring.hxx @@ -70,11 +70,13 @@ public: /** Returns the text data of this portion. */ inline const ::rtl::OUString& getText() const { return maText; } + /** Returns true, if the portion fontains font formatting. */ + inline bool hasFont() const { return mxFont.get() != 0; } - /** Converts the portion and appends it to the passed XText. */ + /** Converts the portion and replaces or appends to the passed XText. */ void convert( const ::com::sun::star::uno::Reference< ::com::sun::star::text::XText >& rxText, - sal_Int32 nXfId ); + const Font* pFont, bool bReplace ); private: ::rtl::OUString maText; /// Portion text. @@ -246,21 +248,30 @@ public: /** Imports a Unicode rich-string from the passed record stream. */ void importString( SequenceInputStream& rStrm, bool bRich ); - /** Imports a byte string from the passed BIFF stream. */ - void importByteString( BiffInputStream& rStrm, rtl_TextEncoding eDefaultTextEnc, BiffStringFlags nFlags = BIFF_STR_DEFAULT ); - /** Imports a Unicode rich-string from the passed BIFF stream. */ + /** Imports nChars byte characters from the passed BIFF stream and appends a new text portion. */ + void importCharArray( BiffInputStream& rStrm, sal_uInt16 nChars, rtl_TextEncoding eTextEnc ); + /** Imports a byte string from the passed BIFF stream and appends new text portions. */ + void importByteString( BiffInputStream& rStrm, rtl_TextEncoding eTextEnc, BiffStringFlags nFlags = BIFF_STR_DEFAULT ); + /** Imports a Unicode rich-string from the passed BIFF stream and appends new text portions. */ void importUniString( BiffInputStream& rStrm, BiffStringFlags nFlags = BIFF_STR_DEFAULT ); /** Final processing after import of all strings. */ void finalizeImport(); - /** Returns the plain text concatenated from all string portions. */ - ::rtl::OUString getPlainText() const; - - /** Converts the string and writes it into the passed XText. */ + /** Tries to extract a plain string from this object. Returns the string, + if there is only one unformatted portion. */ + bool extractPlainString( + ::rtl::OUString& orString, + const Font* pFirstPortionFont = 0 ) const; + + /** Converts the string and writes it into the passed XText. + @param rxText The XText interface of the target object. + @param bReplaceOld True = replace old contents of the text object. + @param pFirstPortionFont Optional font providing additional rich-text + formatting for the first text portion, e.g. font escapement. */ void convert( const ::com::sun::star::uno::Reference< ::com::sun::star::text::XText >& rxText, - sal_Int32 nXfId ) const; + const Font* pFirstPortionFont = 0 ) const; private: /** Creates, appends, and returns a new empty string portion. */ @@ -269,19 +280,19 @@ private: RichStringPhoneticRef createPhonetic(); /** Create base text portions from the passed string and character formatting. */ - void createFontPortions( const ::rtl::OString& rText, rtl_TextEncoding eDefaultTextEnc, FontPortionModelList& rPortions ); + void createTextPortions( const ::rtl::OString& rText, rtl_TextEncoding eTextEnc, FontPortionModelList& rPortions ); /** Create base text portions from the passed string and character formatting. */ - void createFontPortions( const ::rtl::OUString& rText, FontPortionModelList& rPortions ); + void createTextPortions( const ::rtl::OUString& rText, FontPortionModelList& rPortions ); /** Create phonetic text portions from the passed string and portion data. */ void createPhoneticPortions( const ::rtl::OUString& rText, PhoneticPortionModelList& rPortions, sal_Int32 nBaseLen ); private: - typedef RefVector< RichStringPortion > PortionVec; - typedef RefVector< RichStringPhonetic > PhoneticVec; + typedef RefVector< RichStringPortion > PortionVector; + typedef RefVector< RichStringPhonetic > PhoneticVector; - PortionVec maFontPortions; /// String portions with font data. + PortionVector maTextPortions; /// String portions with font data. PhoneticSettings maPhonSettings; /// Phonetic settings for this string. - PhoneticVec maPhonPortions; /// Phonetic text portions. + PhoneticVector maPhonPortions; /// Phonetic text portions. }; typedef ::boost::shared_ptr< RichString > RichStringRef; diff --git a/oox/inc/oox/xls/sharedformulabuffer.hxx b/oox/inc/oox/xls/sharedformulabuffer.hxx deleted file mode 100644 index 94b7572dcfd9..000000000000 --- a/oox/inc/oox/xls/sharedformulabuffer.hxx +++ /dev/null @@ -1,111 +0,0 @@ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -#ifndef OOX_XLS_SHAREDFORMULABUFFER_HXX -#define OOX_XLS_SHAREDFORMULABUFFER_HXX - -#include <map> -#include <memory> -#include "oox/xls/worksheethelper.hxx" - -namespace com { namespace sun { namespace star { - namespace sheet { class XFormulaTokens; } - namespace sheet { class XNamedRange; } -} } } - -namespace oox { -namespace xls { - -// ============================================================================ - -/** Formula context that supports shared formulas. */ -class ExtCellFormulaContext : public SimpleFormulaContext, public WorksheetHelper -{ -public: - explicit ExtCellFormulaContext( - const WorksheetHelper& rHelper, - const ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XFormulaTokens >& rxTokens, - const ::com::sun::star::table::CellAddress& rCellPos ); - - virtual void setSharedFormula( const ::com::sun::star::table::CellAddress& rBaseAddr ); -}; - -// ============================================================================ - -class SharedFormulaBuffer : public WorksheetHelper -{ -public: - explicit SharedFormulaBuffer( const WorksheetHelper& rHelper ); - - /** Imports a shared formula from a OOXML formula string. */ - void importSharedFmla( const ::rtl::OUString& rFormula, - const ::rtl::OUString& rSharedRange, sal_Int32 nId, - const ::com::sun::star::table::CellAddress& rBaseAddr ); - /** Imports a shared formula from a SHAREDFORMULA record in the passed stream */ - void importSharedFmla( SequenceInputStream& rStrm, - const ::com::sun::star::table::CellAddress& rBaseAddr ); - /** Imports a shared formula from a SHAREDFMLA record in the passed stream. */ - void importSharedFmla( BiffInputStream& rStrm, - const ::com::sun::star::table::CellAddress& rBaseAddr ); - - /** Inserts a shared formula with the passed base address into a cell - described by the passed formula context. */ - void setSharedFormulaCell( - ExtCellFormulaContext& rContext, - const ::com::sun::star::table::CellAddress& rBaseAddr ); - /** Inserts a shared formula with the passed base address into a cell - described by the passed formula context. */ - void setSharedFormulaCell( - ExtCellFormulaContext& rContext, - sal_Int32 nSharedId ); - -private: - ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XNamedRange > - createDefinedName( const BinAddress& rMapKey ); - - bool implSetSharedFormulaCell( - ExtCellFormulaContext& rContext, - const BinAddress& rMapKey ); - - void updateCachedCell( - const ::com::sun::star::table::CellAddress& rBaseAddr, - const BinAddress& rMapKey ); - -private: - typedef ::std::map< BinAddress, sal_Int32 > TokenIndexMap; - typedef ::std::auto_ptr< ExtCellFormulaContext > ContextPtr; - - TokenIndexMap maIndexMap; /// Maps shared formula base address to defined name identifier. - ContextPtr mxLastContext; /// Cached formula context for leading formula cell. -}; - -// ============================================================================ - -} // namespace xls -} // namespace oox - -#endif diff --git a/oox/inc/oox/xls/sharedstringsbuffer.hxx b/oox/inc/oox/xls/sharedstringsbuffer.hxx index eff8ab4e7738..936eb6766ef4 100644 --- a/oox/inc/oox/xls/sharedstringsbuffer.hxx +++ b/oox/inc/oox/xls/sharedstringsbuffer.hxx @@ -49,15 +49,12 @@ public: /** Final processing after import of all strings. */ void finalizeImport(); - /** Converts the specified string table entry. */ - void convertString( - const ::com::sun::star::uno::Reference< ::com::sun::star::text::XText >& rxText, - sal_Int32 nStringId, - sal_Int32 nXfId ) const; + /** Returns the specified string. */ + RichStringRef getString( sal_Int32 nStringId ) const; private: - typedef RefVector< RichString > StringVec; - StringVec maStrings; + typedef RefVector< RichString > StringVector; + StringVector maStrings; }; // ============================================================================ diff --git a/oox/inc/oox/xls/sheetdatabuffer.hxx b/oox/inc/oox/xls/sheetdatabuffer.hxx new file mode 100755 index 000000000000..6f61c8432e15 --- /dev/null +++ b/oox/inc/oox/xls/sheetdatabuffer.hxx @@ -0,0 +1,354 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef OOX_XLS_SHEETDATABUFFER_HXX +#define OOX_XLS_SHEETDATABUFFER_HXX + +#include <list> +#include <map> +#include "oox/xls/richstring.hxx" +#include "oox/xls/worksheethelper.hxx" + +namespace com { namespace sun { namespace star { + namespace sheet { class XNamedRange; } + namespace util { struct DateTime; } +} } } + +namespace oox { +namespace xls { + +// ============================================================================ + +/** Stores basic data about cell values and formatting. */ +struct CellModel +{ + ::com::sun::star::table::CellAddress + maCellAddr; /// The address of the current cell. + sal_Int32 mnCellType; /// Data type of the cell value. + sal_Int32 mnXfId; /// XF (cell formatting) identifier. + bool mbShowPhonetic; /// True = show phonetic text. + + explicit CellModel(); +}; + +// ---------------------------------------------------------------------------- + +/** Stores data about cell formulas. */ +struct CellFormulaModel +{ + ::com::sun::star::table::CellRangeAddress + maFormulaRef; /// Formula range for array/shared formulas and data tables. + sal_Int32 mnFormulaType; /// Type of the formula (regular, array, shared, table). + sal_Int32 mnSharedId; /// Identifier of a shared formula (OOXML only). + + explicit CellFormulaModel(); + + /** Returns true, if the passed cell address is valid for an array formula. */ + bool isValidArrayRef( const ::com::sun::star::table::CellAddress& rCellAddr ); + /** Returns true, if the passed cell address is valid for a shared formula. */ + bool isValidSharedRef( const ::com::sun::star::table::CellAddress& rCellAddr ); +}; + +// ---------------------------------------------------------------------------- + +/** Stores data about table operations. */ +struct DataTableModel +{ + ::rtl::OUString maRef1; /// First reference cell for table operations. + ::rtl::OUString maRef2; /// Second reference cell for table operations. + bool mb2dTable; /// True = 2-dimensional data table. + bool mbRowTable; /// True = row oriented data table. + bool mbRef1Deleted; /// True = first reference cell deleted. + bool mbRef2Deleted; /// True = second reference cell deleted. + + explicit DataTableModel(); +}; + +// ============================================================================ + +/** Stores position and contents of a range of cells for optimized import. */ +class CellBlock : public WorksheetHelper +{ +public: + explicit CellBlock( const WorksheetHelper& rHelper, const ValueRange& rColSpan, sal_Int32 nRow ); + + /** Returns true, if the end index of the passed colspan is greater than + the own column end index, or if the passed range has the same end index + but the start indexes do not match. */ + bool isBefore( const ValueRange& rColSpan ) const; + /** Returns true, if the cell block can be expanded with the passed colspan. */ + bool isExpandable( const ValueRange& rColSpan ) const; + /** Returns true, if the own colspan contains the passed column. */ + bool contains( sal_Int32 nCol ) const; + + /** Returns the specified cell from the last row in the cell buffer array. */ + ::com::sun::star::uno::Any& getCellAny( sal_Int32 nCol ); + /** Inserts a rich-string into the cell block. */ + void insertRichString( + const ::com::sun::star::table::CellAddress& rAddress, + const RichStringRef& rxString, + const Font* pFirstPortionFont ); + + /** Appends a new row to the cell buffer array. */ + void startNextRow(); + /** Writes all buffered cells into the Calc sheet. */ + void finalizeImport(); + +private: + /** Fills unused cells before passed index with empty strings. */ + void fillUnusedCells( sal_Int32 nIndex ); + +private: + /** Stores position and string data of a rich-string cell. */ + struct RichStringCell + { + ::com::sun::star::table::CellAddress + maCellAddr; /// The address of the rich-string cell. + RichStringRef mxString; /// The string with rich formatting. + const Font* mpFirstPortionFont; /// Font information from cell for first text portion. + + explicit RichStringCell( + const ::com::sun::star::table::CellAddress& rCellAddr, + const RichStringRef& rxString, + const Font* pFirstPortionFont ); + }; + typedef ::std::list< RichStringCell > RichStringCellList; + + ::com::sun::star::table::CellRangeAddress + maRange; /// Cell range covered by this cell block. + RichStringCellList maRichStrings; /// Cached rich-string cells. + ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > > + maCellArray; /// The array of cells of this cell block. + ::com::sun::star::uno::Any* + mpCurrCellRow; /// Pointer to first cell of current row (last row in maCellArray). + const sal_Int32 mnRowLength; /// Number of cells covered by row of this cell block. + sal_Int32 mnFirstFreeIndex; /// Relative index of first unused cell in current row. +}; + +// ============================================================================ + +/** Manages all cell blocks currently in use. */ +class CellBlockBuffer : public WorksheetHelper +{ +public: + explicit CellBlockBuffer( const WorksheetHelper& rHelper ); + + /** Sets column span information for a row. */ + void setColSpans( sal_Int32 nRow, const ValueRangeSet& rColSpans ); + + /** Tries to find a cell block. Recalculates the map of cell blocks, if the + passed cell address is located in another row than the last cell. */ + CellBlock* getCellBlock( const ::com::sun::star::table::CellAddress& rCellAddr ); + + /** Inserts all cells of all open cell blocks into the Calc document. */ + void finalizeImport(); + +private: + typedef ::std::map< sal_Int32, ValueRangeVector > ColSpanVectorMap; + typedef RefMap< sal_Int32, CellBlock > CellBlockMap; + + ColSpanVectorMap maColSpans; /// Buffereed column spans, mapped by row index. + CellBlockMap maCellBlocks; /// All open cell blocks, mapped by last (!) column of the block span. + CellBlockMap::iterator maCellBlockIt; /// Pointer to cell block currently in use. + sal_Int32 mnCurrRow; /// Current row index used for buffered cell import. +}; + +// ============================================================================ + +/** Manages the cell contents and cell formatting of a sheet. + */ +class SheetDataBuffer : public WorksheetHelper +{ +public: + explicit SheetDataBuffer( const WorksheetHelper& rHelper ); + + /** Sets column span information for a row. */ + void setColSpans( sal_Int32 nRow, const ValueRangeSet& rColSpans ); + + /** Inserts a blank cell (with formatting) into the sheet. */ + void setBlankCell( const CellModel& rModel ); + /** Inserts a value cell into the sheet. */ + void setValueCell( const CellModel& rModel, double fValue ); + /** Inserts a simple string cell into the sheet. */ + void setStringCell( const CellModel& rModel, const ::rtl::OUString& rText ); + /** Inserts a rich-string cell into the sheet. */ + void setStringCell( const CellModel& rModel, const RichStringRef& rxString ); + /** Inserts a shared string cell into the sheet. */ + void setStringCell( const CellModel& rModel, sal_Int32 nStringId ); + /** Inserts a date/time cell into the sheet and adjusts number format. */ + void setDateTimeCell( const CellModel& rModel, const ::com::sun::star::util::DateTime& rDateTime ); + /** Inserts a boolean cell into the sheet and adjusts number format. */ + void setBooleanCell( const CellModel& rModel, bool bValue ); + /** Inserts an error cell from the passed error code into the sheet. */ + void setErrorCell( const CellModel& rModel, const ::rtl::OUString& rErrorCode ); + /** Inserts an error cell from the passed BIFF error code into the sheet. */ + void setErrorCell( const CellModel& rModel, sal_uInt8 nErrorCode ); + /** Inserts a formula cell into the sheet. */ + void setFormulaCell( const CellModel& rModel, const ApiTokenSequence& rTokens ); + /** Inserts a shared formula cell into the sheet (OOXML only). */ + void setFormulaCell( const CellModel& rModel, sal_Int32 nSharedId ); + + /** Inserts the passed token array as array formula. */ + void createArrayFormula( + const ::com::sun::star::table::CellRangeAddress& rRange, + const ApiTokenSequence& rTokens ); + /** Sets a multiple table operation to the passed range. */ + void createTableOperation( + const ::com::sun::star::table::CellRangeAddress& rRange, + const DataTableModel& rModel ); + /** Creates a named range with a special name for a shared formula with the + specified identifier and formula definition (OOXML only). */ + void createSharedFormula( + sal_Int32 nSharedId, + const ApiTokenSequence& rTokens ); + /** Creates a named range with a special name for a shared formula with the + specified base address and formula definition (BIFF only). */ + void createSharedFormula( + const ::com::sun::star::table::CellAddress& rCellAddr, + const ApiTokenSequence& rTokens ); + + /** Sets default cell formatting for the specified range of rows. */ + void setRowFormat( sal_Int32 nRow, sal_Int32 nXfId, bool bCustomFormat ); + /** Merges the cells in the passed cell range. */ + void setMergedRange( const ::com::sun::star::table::CellRangeAddress& rRange ); + /** Sets a standard number format (constant from com.sun.star.util.NumberFormat) to the specified cell. */ + void setStandardNumFmt( + const ::com::sun::star::table::CellAddress& rCellAddr, + sal_Int16 nStdNumFmt ); + + /** Final processing after the sheet has been imported. */ + void finalizeImport(); + +private: + struct XfIdRowRange; + struct XfIdRange; + + /** Sets the passed formula token array into a cell. */ + void setCellFormula( + const ::com::sun::star::table::CellAddress& rCellAddr, + const ApiTokenSequence& rTokens ); + + /** Creates a named range with a special name for a shared formula with the + specified base address and formula definition. */ + void createSharedFormula( const BinAddress& rMapKey, const ApiTokenSequence& rTokens ); + /** Creates a formula token array representing the shared formula with the + passed identifier. */ + ApiTokenSequence resolveSharedFormula( const BinAddress& rMapKey ) const; + + /** Inserts the passed array formula into the sheet. */ + void finalizeArrayFormula( + const ::com::sun::star::table::CellRangeAddress& rRange, + const ApiTokenSequence& rTokens ) const; + /** Inserts the passed table operation into the sheet. */ + void finalizeTableOperation( + const ::com::sun::star::table::CellRangeAddress& rRange, + const DataTableModel& rModel ) const; + + /** Processes the cell formatting data of the passed cell. + @param nNumFmtId If set, overrides number format of the cell XF. */ + void setCellFormat( const CellModel& rModel, sal_Int32 nNumFmtId = -1 ); + + /** Writes all cell formatting attributes to the passed row range. */ + void writeXfIdRowRangeProperties( const XfIdRowRange& rXfIdRowRange ) const; + /** Writes all cell formatting attributes to the passed cell range. */ + void writeXfIdRangeProperties( const XfIdRange& rXfIdRange ) const; + /** Tries to merge the ranges last inserted in maXfIdRanges with existing ranges. */ + void mergeXfIdRanges(); + + /** Merges the passed merged range and updates right/bottom cell borders. */ + void finalizeMergedRange( const ::com::sun::star::table::CellRangeAddress& rRange ); + +private: + /** Stores cell range address and formula token array of an array formula. */ + typedef ::std::pair< ::com::sun::star::table::CellRangeAddress, ApiTokenSequence > ArrayFormula; + typedef ::std::list< ArrayFormula > ArrayFormulaList; + + /** Stores cell range address and settings of a table operation. */ + typedef ::std::pair< ::com::sun::star::table::CellRangeAddress, DataTableModel > TableOperation; + typedef ::std::list< TableOperation > TableOperationList; + + typedef ::std::map< BinAddress, sal_Int32 > SharedFormulaMap; + + /** Stores information about a range of rows with equal cell formatting. */ + struct XfIdRowRange + { + ValueRange maRowRange; /// Indexes of first and last row. + sal_Int32 mnXfId; /// XF identifier for the row range. + + explicit XfIdRowRange(); + bool intersects( const ::com::sun::star::table::CellRangeAddress& rRange ) const; + void set( sal_Int32 nRow, sal_Int32 nXfId ); + bool tryExpand( sal_Int32 nRow, sal_Int32 nXfId ); + }; + + /** Stores information about a range of cells with equal formatting. */ + struct XfIdRange + { + ::com::sun::star::table::CellRangeAddress + maRange; /// The formatted cell range. + sal_Int32 mnXfId; /// XF identifier for the range. + sal_Int32 mnNumFmtId; /// Number format overriding the XF. + + void set( const ::com::sun::star::table::CellAddress& rCellAddr, sal_Int32 nXfId, sal_Int32 nNumFmtId ); + bool tryExpand( const ::com::sun::star::table::CellAddress& rCellAddr, sal_Int32 nXfId, sal_Int32 nNumFmtId ); + bool tryMerge( const XfIdRange& rXfIdRange ); + }; + typedef ::std::map< BinAddress, XfIdRange > XfIdRangeMap; + + /** Stores information about a merged cell range. */ + struct MergedRange + { + ::com::sun::star::table::CellRangeAddress + maRange; /// The formatted cell range. + sal_Int32 mnHorAlign; /// Horizontal alignment in the range. + + explicit MergedRange( const ::com::sun::star::table::CellRangeAddress& rRange ); + explicit MergedRange( const ::com::sun::star::table::CellAddress& rAddress, sal_Int32 nHorAlign ); + bool tryExpand( const ::com::sun::star::table::CellAddress& rAddress, sal_Int32 nHorAlign ); + }; + typedef ::std::list< MergedRange > MergedRangeList; + + CellBlockBuffer maCellBlocks; /// Manages all open cell blocks. + ArrayFormulaList maArrayFormulas; /// All array formulas in the sheet. + TableOperationList maTableOperations; /// All table operations in the sheet. + SharedFormulaMap maSharedFormulas; /// Maps shared formula base address to defined name token index. + ::com::sun::star::table::CellAddress + maSharedFmlaAddr; /// Address of a cell containing a pending shared formula. + BinAddress maSharedBaseAddr; /// Base address of the pending shared formula. + XfIdRowRange maXfIdRowRange; /// Cached XF identifier for a range of rows. + XfIdRangeMap maXfIdRanges; /// Collected XF identifiers for cell ranges. + MergedRangeList maMergedRanges; /// Merged cell ranges. + MergedRangeList maCenterFillRanges; /// Merged cell ranges from 'center across' or 'fill' alignment. + bool mbPendingSharedFmla; /// True = maSharedFmlaAddr and maSharedBaseAddr are valid. +}; + +// ============================================================================ + +} // namespace xls +} // namespace oox + +#endif diff --git a/oox/inc/oox/xls/sheetdatacontext.hxx b/oox/inc/oox/xls/sheetdatacontext.hxx index fdbc0ba21231..c5104dec8e8b 100644 --- a/oox/inc/oox/xls/sheetdatacontext.hxx +++ b/oox/inc/oox/xls/sheetdatacontext.hxx @@ -30,22 +30,37 @@ #include "oox/xls/excelhandlers.hxx" #include "oox/xls/richstring.hxx" - -namespace com { namespace sun { namespace star { - namespace table { class XCell; } -} } } +#include "oox/xls/sheetdatabuffer.hxx" namespace oox { namespace xls { // ============================================================================ +/** Used as base for sheet data context classes. Provides fast access to often + used converter objects and sheet index, to improve performance. + */ +struct SheetDataContextBase +{ + AddressConverter& mrAddressConv; /// The address converter. + FormulaParser& mrFormulaParser; /// The formula parser. + SheetDataBuffer& mrSheetData; /// The sheet data buffer for cell content and formatting. + CellModel maCellData; /// Position, contents, formatting of current imported cell. + CellFormulaModel maFmlaData; /// Settings for a cell formula. + sal_Int16 mnSheet; /// Index of the current sheet. + + explicit SheetDataContextBase( const WorksheetHelper& rHelper ); + virtual ~SheetDataContextBase(); +}; + +// ============================================================================ + /** This class implements importing the sheetData element. The sheetData element contains all row settings and all cells in a single sheet of a spreadsheet document. */ -class SheetDataContext : public WorksheetContextBase +class SheetDataContext : public WorksheetContextBase, private SheetDataContextBase { public: explicit SheetDataContext( WorksheetFragmentBase& rFragment ); @@ -64,12 +79,20 @@ private: /** Imports row settings from a row element. */ void importRow( const AttributeList& rAttribs ); /** Imports cell settings from a c element. */ - void importCell( const AttributeList& rAttribs ); + bool importCell( const AttributeList& rAttribs ); /** Imports cell settings from an f element. */ void importFormula( const AttributeList& rAttribs ); - /** Imports a cell address and the following XF identifier. */ - void importCellHeader( SequenceInputStream& rStrm, CellType eCellType ); + /** Imports row settings from a ROW record. */ + void importRow( SequenceInputStream& rStrm ); + + /** Reads a cell address and the following XF identifier. */ + bool readCellHeader( SequenceInputStream& rStrm, CellType eCellType ); + /** Reads a cell formula for the current cell. */ + ApiTokenSequence readCellFormula( SequenceInputStream& rStrm ); + /** Reads the formula range used by shared formulas, arrays, and data tables. */ + bool readFormulaRef( SequenceInputStream& rStrm ); + /** Imports an empty cell from a CELL_BLANK or MULTCELL_BLANK record. */ void importCellBlank( SequenceInputStream& rStrm, CellType eCellType ); /** Imports a boolean cell from a CELL_BOOL, MULTCELL_BOOL, or FORMULA_BOOL record. */ @@ -87,30 +110,28 @@ private: /** Imports a string cell from a CELL_STRING, MULTCELL_STRING, or FORMULA_STRING record. */ void importCellString( SequenceInputStream& rStrm, CellType eCellType ); - /** Imports a cell formula for the current cell. */ - void importCellFormula( SequenceInputStream& rStrm ); - - /** Imports row settings from a ROW record. */ - void importRow( SequenceInputStream& rStrm ); /** Imports an array formula from an ARRAY record. */ void importArray( SequenceInputStream& rStrm ); - /** Imports a shared formula from a SHAREDFORMULA record. */ - void importSharedFmla( SequenceInputStream& rStrm ); /** Imports table operation from a DATATABLE record. */ void importDataTable( SequenceInputStream& rStrm ); + /** Imports a shared formula from a SHAREDFORMULA record. */ + void importSharedFmla( SequenceInputStream& rStrm ); private: - CellModel maCurrCell; /// Position and formatting of current imported cell. - DataTableModel maTableData; /// Additional data for table operation ranges. - BinAddress maCurrPos; /// Current position for binary import. - RichStringRef mxInlineStr; /// Inline rich string from 'is' element. + ::rtl::OUString maCellValue; /// Cell value string (OOXML only). + RichStringRef mxInlineStr; /// Inline rich string (OOXML only). + ApiTokenSequence maTokens; /// Formula token array (OOXML only). + DataTableModel maTableData; /// Settings for table operations. + BinAddress maCurrPos; /// Current cell position (BIFF12 only). + bool mbHasFormula; /// True = current cell has formula data (OOXML only). + bool mbValidRange; /// True = maFmlaData.maFormulaRef is valid (OOXML only). }; // ============================================================================ /** This class implements importing row settings and all cells of a sheet. */ -class BiffSheetDataContext : public BiffWorksheetContextBase +class BiffSheetDataContext : public BiffWorksheetContextBase, private SheetDataContextBase { public: explicit BiffSheetDataContext( const WorksheetHelper& rHelper ); @@ -119,13 +140,15 @@ public: virtual void importRecord( BiffInputStream& rStrm ); private: - /** Sets current cell according to the passed address. */ - void setCurrCell( const BinAddress& rAddr ); + /** Imports row settings from a ROW record. */ + void importRow( BiffInputStream& rStrm ); - /** Imports an XF identifier and sets the mnXfId member. */ - void importXfId( BiffInputStream& rStrm, bool bBiff2 ); - /** Imports a BIFF cell address and the following XF identifier. */ - void importCellHeader( BiffInputStream& rStrm, bool bBiff2 ); + /** Reads an XF identifier and initializes a new cell. */ + bool readCellXfId( BiffInputStream& rStrm, const BinAddress& rAddr, bool bBiff2 ); + /** Reads a BIFF cell address and the following XF identifier. */ + bool readCellHeader( BiffInputStream& rStrm, bool bBiff2 ); + /** Reads the formula range used by shared formulas, arrays, and data tables. */ + bool readFormulaRef( BiffInputStream& rStrm ); /** Imports a BLANK record describing a blank but formatted cell. */ void importBlank( BiffInputStream& rStrm ); @@ -148,20 +171,18 @@ private: /** Imports an RK record describing a numeric cell. */ void importRk( BiffInputStream& rStrm ); - /** Imports row settings from a ROW record. */ - void importRow( BiffInputStream& rStrm ); /** Imports an ARRAY record describing an array formula of a cell range. */ void importArray( BiffInputStream& rStrm ); - /** Imports a SHAREDFMLA record describing a shared formula in a cell range. */ - void importSharedFmla( BiffInputStream& rStrm ); /** Imports table operation from a DATATABLE or DATATABLE2 record. */ void importDataTable( BiffInputStream& rStrm ); + /** Imports a SHAREDFMLA record describing a shared formula in a cell range. */ + void importSharedFmla( BiffInputStream& rStrm ); private: - CellModel maCurrCell; /// Position and formatting of current imported cell. - sal_uInt32 mnFormulaIgnoreSize; /// Number of bytes to be ignored in FORMULA record. - sal_uInt32 mnArrayIgnoreSize; /// Number of bytes to be ignored in ARRAY record. - sal_uInt16 mnBiff2XfId; /// Current XF identifier from IXFE record. + sal_uInt32 mnFormulaSkipSize; /// Number of bytes to be ignored in FORMULA record. + sal_uInt32 mnArraySkipSize; /// Number of bytes to be ignored in ARRAY record. + sal_uInt16 mnBiff2XfId; /// Current XF identifier from IXFE record. + OptValue< bool > mobBiff2HasXfs; /// Select XF formatting or direct formatting in BIFF2. }; // ============================================================================ diff --git a/oox/inc/oox/xls/stylesbuffer.hxx b/oox/inc/oox/xls/stylesbuffer.hxx index 64a56968aa37..468476449cc3 100644 --- a/oox/inc/oox/xls/stylesbuffer.hxx +++ b/oox/inc/oox/xls/stylesbuffer.hxx @@ -790,6 +790,11 @@ public: /** Writes all formatting attributes to the passed property set. */ void writeToPropertySet( PropertySet& rPropSet ) const; + /** Converts formatting information from BIFF2 cell record data directly. */ + static void writeBiff2CellFormatToPropertySet( + const WorkbookHelper& rHelper, PropertySet& rPropSet, + sal_uInt8 nFlags1, sal_uInt8 nFlags2, sal_uInt8 nFlags3 ); + private: /** Sets 'attribute used' flags from the passed BIFF bit field. */ void setBiffUsedFlags( sal_uInt8 nUsedFlags ); diff --git a/oox/inc/oox/xls/workbookhelper.hxx b/oox/inc/oox/xls/workbookhelper.hxx index ecf824076ef5..049120aaaf40 100644 --- a/oox/inc/oox/xls/workbookhelper.hxx +++ b/oox/inc/oox/xls/workbookhelper.hxx @@ -108,47 +108,49 @@ class TableBuffer; class ThemeBuffer; class UnitConverter; class ViewSettings; -class WorkbookData; class WorkbookSettings; class WorksheetBuffer; +class WorkbookGlobals; +typedef ::boost::shared_ptr< WorkbookGlobals > WorkbookGlobalsRef; + /** Helper class to provice access to global workbook data. All classes derived from this helper class will have access to a singleton - object of type WorkbookData containing global workbook settings, buffers, - converters, etc. Nearly all classes in this filter implementation are - derived directly or indirectly from this class. + object of type WorkbookGlobals containing global workbook settings, + buffers, converters, etc. Nearly all classes in this filter implementation + are derived directly or indirectly from this class. - This class contains just a simple reference to the WorkbookData object to - prevent circular references, as the WorkbookData object contains a lot of - objects derived from this class. + This class contains just a simple reference to the WorkbookGlobals object + to prevent circular references, as the WorkbookGlobals object contains a + lot of objects derived from this class. */ class WorkbookHelper { public: - inline /*implicit*/ WorkbookHelper( WorkbookData& rBookData ) : mrBookData( rBookData ) {} + inline /*implicit*/ WorkbookHelper( WorkbookGlobals& rBookGlob ) : mrBookGlob( rBookGlob ) {} virtual ~WorkbookHelper(); + static WorkbookGlobalsRef constructGlobals( ExcelFilter& rFilter ); + static WorkbookGlobalsRef constructGlobals( ExcelBiffFilter& rFilter, BiffType eBiff ); + // filter ----------------------------------------------------------------- /** Returns the base filter object (base class of all filters). */ ::oox::core::FilterBase& getBaseFilter() const; - /** Returns a reference to the global service factory. */ - ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > - getGlobalFactory() const; /** Returns the file type of the current filter. */ FilterType getFilterType() const; /** Returns the filter progress bar. */ SegmentProgressBar& getProgressBar() const; /** Returns true, if the file is a multi-sheet document, or false if single-sheet. */ bool isWorkbookFile() const; - /** Returns the index of the current sheet in the Calc document. */ + /** Returns the index of the current Calc sheet, if filter currently processes a sheet. */ sal_Int16 getCurrentSheetIndex() const; - /** Sets the index of the current sheet in the Calc document. */ - void setCurrentSheetIndex( sal_Int16 nSheet ); - /** Sets the VBA project storage. */ + /** Sets the VBA project storage used to import VBA source code and forms. */ void setVbaProjectStorage( const StorageRef& rxVbaPrjStrg ); + /** Sets the index of the current Calc sheet, if filter currently processes a sheet. */ + void setCurrentSheetIndex( sal_Int16 nSheet ); /** Final conversion after importing the workbook. */ void finalizeWorkbookImport(); @@ -157,9 +159,6 @@ public: /** Returns a reference to the source/target spreadsheet document model. */ ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XSpreadsheetDocument > getDocument() const; - /** Returns a reference to the service factory of the spreadsheet document model. */ - ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > - getDocumentFactory() const; /** Returns a reference to the specified spreadsheet in the document model. */ ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XSpreadsheet > @@ -283,38 +282,7 @@ public: BiffCodecHelper& getCodecHelper() const; private: - WorkbookData& mrBookData; -}; - -// ============================================================================ - -namespace prv { - -typedef ::boost::shared_ptr< WorkbookData > WorkbookDataRef; - -struct WorkbookDataOwner -{ - explicit WorkbookDataOwner( WorkbookDataRef xBookData ); - virtual ~WorkbookDataOwner(); - WorkbookDataRef mxBookData; -}; - -} // namespace prv - -// ---------------------------------------------------------------------------- - -class WorkbookHelperRoot : private prv::WorkbookDataOwner, public WorkbookHelper -{ -public: - explicit WorkbookHelperRoot( ExcelFilter& rFilter ); - explicit WorkbookHelperRoot( ExcelBiffFilter& rFilter, BiffType eBiff ); - - /** Returns true, if this helper refers to a valid document. */ - bool isValid() const; - -private: - WorkbookHelperRoot( const WorkbookHelperRoot& ); - WorkbookHelperRoot& operator=( const WorkbookHelperRoot& ); + WorkbookGlobals& mrBookGlob; }; // ============================================================================ diff --git a/oox/inc/oox/xls/worksheetfragment.hxx b/oox/inc/oox/xls/worksheetfragment.hxx index 4fe3bf4240dd..d9cedee7b5e6 100644 --- a/oox/inc/oox/xls/worksheetfragment.hxx +++ b/oox/inc/oox/xls/worksheetfragment.hxx @@ -63,11 +63,8 @@ class WorksheetFragment : public WorksheetFragmentBase { public: explicit WorksheetFragment( - const WorkbookHelper& rHelper, - const ::rtl::OUString& rFragmentPath, - const ISegmentProgressBarRef& rxProgressBar, - WorksheetType eSheetType, - sal_Int16 nSheet ); + const WorksheetHelper& rHelper, + const ::rtl::OUString& rFragmentPath ); protected: virtual ::oox::core::ContextHandlerRef onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ); @@ -134,10 +131,8 @@ class BiffWorksheetFragment : public BiffWorksheetFragmentBase { public: explicit BiffWorksheetFragment( - const BiffWorkbookFragmentBase& rParent, - const ISegmentProgressBarRef& rxProgressBar, - WorksheetType eSheetType, - sal_Int16 nSheet ); + const WorksheetHelper& rHelper, + const BiffWorkbookFragmentBase& rParent ); virtual ~BiffWorksheetFragment(); /** Imports the entire worksheet fragment, returns true, if EOF record has been reached. */ @@ -168,6 +163,8 @@ private: void importLabelRanges( BiffInputStream& rStrm ); /** Imports the MEREDCELLS record and merges all cells in the document. */ void importMergedCells( BiffInputStream& rStrm ); + /** Imports the NOTE record containing a cell note. */ + void importNote( BiffInputStream& rStrm ); /** Imports the HORPAGEBREAKS or VERPAGEBREAKS record and inserts page breaks. */ void importPageBreaks( BiffInputStream& rStrm, bool bRowBreak ); /** Imports a pivot table. */ diff --git a/oox/inc/oox/xls/worksheethelper.hxx b/oox/inc/oox/xls/worksheethelper.hxx index 55bf1c044e30..e87599409528 100644 --- a/oox/inc/oox/xls/worksheethelper.hxx +++ b/oox/inc/oox/xls/worksheethelper.hxx @@ -28,6 +28,7 @@ #ifndef OOX_XLS_WORKSHEETHELPER_HXX #define OOX_XLS_WORKSHEETHELPER_HXX +#include "oox/helper/containerhelper.hxx" #include "oox/helper/progressbar.hxx" #include "oox/ole/olehelper.hxx" #include "oox/xls/addressconverter.hxx" @@ -44,7 +45,6 @@ namespace com { namespace sun { namespace star { namespace table { class XCellRange; } namespace table { class XTableColumns; } namespace table { class XTableRows; } - namespace util { struct DateTime; } } } } namespace oox { @@ -53,12 +53,15 @@ namespace xls { class AutoFilterBuffer; struct BinAddress; struct BinRange; +class BiffSheetDrawing; class BinRangeList; class CommentsBuffer; class CondFormatBuffer; +class Font; class PageSettings; class QueryTableBuffer; -class SharedFormulaBuffer; +class RichString; +class SheetDataBuffer; class SheetViewSettings; class VmlDrawing; class WorksheetSettings; @@ -79,47 +82,10 @@ enum WorksheetType // ============================================================================ -/** Stores some data about a cell. */ -struct CellModel -{ - ::com::sun::star::uno::Reference< ::com::sun::star::table::XCell > mxCell; - ::com::sun::star::table::CellAddress maAddress; - ::rtl::OUString maValueStr; /// String containing cell value data. - ::rtl::OUString maFormulaRef; /// String containing formula range for array/shared formulas. - sal_Int32 mnCellType; /// Data type of the cell. - sal_Int32 mnFormulaType; /// Type of the imported formula. - sal_Int32 mnSharedId; /// Shared formula identifier for current cell. - sal_Int32 mnXfId; /// XF identifier for the cell. - sal_Int32 mnNumFmtId; /// Forced number format for the cell. - bool mbHasValueStr; /// True = contents of maValueStr are valid. - bool mbShowPhonetic; /// True = show phonetic text. - - inline explicit CellModel() { reset(); } - void reset(); -}; - -// ---------------------------------------------------------------------------- - -/** Stores data about a data table a.k.a. multiple operation range. */ -struct DataTableModel -{ - ::rtl::OUString maRef1; /// String containing first reference cell for data table formulas. - ::rtl::OUString maRef2; /// String containing second reference cell for data table formulas. - bool mb2dTable; /// True = 2-dimensional data table. - bool mbRowTable; /// True = row oriented data table. - bool mbRef1Deleted; /// True = first reference cell deleted. - bool mbRef2Deleted; /// True = second reference cell deleted. - - explicit DataTableModel(); -}; - -// ---------------------------------------------------------------------------- - -/** Stores formatting data about a range of columns. */ +/** Stores settings and formatting data about a range of sheet columns. */ struct ColumnModel { - sal_Int32 mnFirstCol; /// 1-based (!) index of first column. - sal_Int32 mnLastCol; /// 1-based (!) index of last column. + ValueRange maRange; /// 1-based (!) range of the described columns. double mfWidth; /// Column width in number of characters. sal_Int32 mnXfId; /// Column default formatting. sal_Int32 mnLevel; /// Column outline level. @@ -129,17 +95,17 @@ struct ColumnModel explicit ColumnModel(); - /** Expands this entry with the passed column range, if column settings are equal. */ - bool tryExpand( const ColumnModel& rModel ); + /** Returns true, if this entry can be merged with the passed column range (column settings are equal). */ + bool isMergeable( const ColumnModel& rModel ) const; }; // ---------------------------------------------------------------------------- -/** Stores formatting data about a range of rows. */ +/** Stores settings and formatting data about a sheet row. */ struct RowModel { - sal_Int32 mnFirstRow; /// 1-based (!) index of first row. - sal_Int32 mnLastRow; /// 1-based (!) index of last row. + sal_Int32 mnRow; /// 1-based (!) index of the described row. + ValueRangeSet maColSpans; /// 0-based (!) column ranges of used cells. double mfHeight; /// Row height in points. sal_Int32 mnXfId; /// Row default formatting (see mbIsFormatted). sal_Int32 mnLevel; /// Row outline level. @@ -153,8 +119,10 @@ struct RowModel explicit RowModel(); - /** Expands this entry with the passed row range, if row settings are equal. */ - bool tryExpand( const RowModel& rModel ); + /** Inserts the passed column span into the row model. */ + void insertColSpan( const ValueRange& rColSpan ); + /** Returns true, if this entry can be merged with the passed row range (row settings are equal). */ + bool isMergeable( const RowModel& rModel ) const; }; // ---------------------------------------------------------------------------- @@ -215,12 +183,21 @@ struct ValidationModel // ============================================================================ // ============================================================================ -class WorksheetData; +class WorksheetGlobals; +typedef ::boost::shared_ptr< WorksheetGlobals > WorksheetGlobalsRef; class WorksheetHelper : public WorkbookHelper { public: - /*implicit*/ WorksheetHelper( WorksheetData& rSheetData ); + /*implicit*/ WorksheetHelper( WorksheetGlobals& rSheetGlob ); + + static WorksheetGlobalsRef constructGlobals( + const WorkbookHelper& rHelper, + const ISegmentProgressBarRef& rxProgressBar, + WorksheetType eSheetType, + sal_Int16 nSheet ); + + // ------------------------------------------------------------------------ /** Returns the type of this sheet. */ WorksheetType getSheetType() const; @@ -232,47 +209,13 @@ public: /** Returns the XCell interface for the passed cell address. */ ::com::sun::star::uno::Reference< ::com::sun::star::table::XCell > - getCell( - const ::com::sun::star::table::CellAddress& rAddress ) const; - /** Returns the XCell interface for the passed cell address string. */ - ::com::sun::star::uno::Reference< ::com::sun::star::table::XCell > - getCell( - const ::rtl::OUString& rAddressStr, - ::com::sun::star::table::CellAddress* opAddress = 0 ) const; - /** Returns the XCell interface for the passed cell address. */ - ::com::sun::star::uno::Reference< ::com::sun::star::table::XCell > - getCell( - const BinAddress& rBinAddress, - ::com::sun::star::table::CellAddress* opAddress = 0 ) const; - + getCell( const ::com::sun::star::table::CellAddress& rAddress ) const; /** Returns the XCellRange interface for the passed cell range address. */ ::com::sun::star::uno::Reference< ::com::sun::star::table::XCellRange > - getCellRange( - const ::com::sun::star::table::CellRangeAddress& rRange ) const; - /** Returns the XCellRange interface for the passed range address string. */ - ::com::sun::star::uno::Reference< ::com::sun::star::table::XCellRange > - getCellRange( - const ::rtl::OUString& rRangeStr, - ::com::sun::star::table::CellRangeAddress* opRange = 0 ) const; - /** Returns the XCellRange interface for the passed range address. */ - ::com::sun::star::uno::Reference< ::com::sun::star::table::XCellRange > - getCellRange( - const BinRange& rBinRange, - ::com::sun::star::table::CellRangeAddress* opRange = 0 ) const; - + getCellRange( const ::com::sun::star::table::CellRangeAddress& rRange ) const; /** Returns the XSheetCellRanges interface for the passed cell range addresses. */ ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XSheetCellRanges > getCellRangeList( const ApiCellRangeList& rRanges ) const; - /** Returns the XSheetCellRanges interface for the passed space-separated range list. */ - ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XSheetCellRanges > - getCellRangeList( - const ::rtl::OUString& rRangesStr, - ApiCellRangeList* opRanges = 0 ) const; - /** Returns the XSheetCellRanges interface for the passed range list. */ - ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XSheetCellRanges > - getCellRangeList( - const BinRangeList& rBinRanges, - ApiCellRangeList* opRanges = 0 ) const; /** Returns the address of the passed cell. The cell reference must be valid. */ static ::com::sun::star::table::CellAddress @@ -292,10 +235,10 @@ public: /** Returns the XTableColumns interface for a range of columns. */ ::com::sun::star::uno::Reference< ::com::sun::star::table::XTableColumns > - getColumns( sal_Int32 nFirstCol, sal_Int32 nLastCol ) const; + getColumns( const ValueRange& rColRange ) const; /** Returns the XTableRows interface for a range of rows. */ ::com::sun::star::uno::Reference< ::com::sun::star::table::XTableRows > - getRows( sal_Int32 nFirstRow, sal_Int32 nLastRow ) const; + getRows( const ValueRange& rRowRange ) const; /** Returns the XDrawPage interface of the draw page of the current sheet. */ ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XDrawPage > @@ -308,10 +251,8 @@ public: /** Returns the size of the entire drawing page in 1/100 mm. */ ::com::sun::star::awt::Size getDrawPageSize() const; - /** Returns the worksheet settings object. */ - WorksheetSettings& getWorksheetSettings() const; - /** Returns the buffer containing all shared formulas in this sheet. */ - SharedFormulaBuffer& getSharedFormulas() const; + /** Returns the buffer for cell contents and cell formatting. */ + SheetDataBuffer& getSheetData() const; /** Returns the conditional formattings in this sheet. */ CondFormatBuffer& getCondFormats() const; /** Returns the buffer for all cell comments in this sheet. */ @@ -320,66 +261,27 @@ public: AutoFilterBuffer& getAutoFilters() const; /** Returns the buffer for all web query tables in this sheet. */ QueryTableBuffer& getQueryTables() const; + /** Returns the worksheet settings object. */ + WorksheetSettings& getWorksheetSettings() const; /** Returns the page/print settings for this sheet. */ PageSettings& getPageSettings() const; /** Returns the view settings for this sheet. */ SheetViewSettings& getSheetViewSettings() const; - /** Returns the VML drawing page for this sheet. */ + /** Returns the VML drawing page for this sheet (OOXML/BIFF12 only). */ VmlDrawing& getVmlDrawing() const; - - /** Sets the passed string to the cell. */ - void setStringCell( - const ::com::sun::star::uno::Reference< ::com::sun::star::table::XCell >& rxCell, - const ::rtl::OUString& rText ) const; - /** Sets the shared string with the passed identifier to the cell. */ - void setSharedStringCell( - const ::com::sun::star::uno::Reference< ::com::sun::star::table::XCell >& rxCell, - sal_Int32 nStringId, - sal_Int32 nXfId ) const; - /** Sets the passed date/time value to the cell and adjusts number format. */ - void setDateTimeCell( - const ::com::sun::star::uno::Reference< ::com::sun::star::table::XCell >& rxCell, - const ::com::sun::star::util::DateTime& rDateTime ) const; - /** Sets the passed boolean value to the cell and adjusts number format. */ - void setBooleanCell( - const ::com::sun::star::uno::Reference< ::com::sun::star::table::XCell >& rxCell, - bool bValue ) const; - /** Sets the passed BIFF error code to the cell (by converting it to a formula). */ - void setErrorCell( - const ::com::sun::star::uno::Reference< ::com::sun::star::table::XCell >& rxCell, - const ::rtl::OUString& rErrorCode ) const; - /** Sets the passed BIFF error code to the cell (by converting it to a formula). */ - void setErrorCell( - const ::com::sun::star::uno::Reference< ::com::sun::star::table::XCell >& rxCell, - sal_uInt8 nErrorCode ) const; - /** Sets cell contents to the cell specified in the passed cell model. */ - void setCell( CellModel& orModel ) const; - - /** Sets a standard number format (constant from com.sun.star.util.NumberFormat) to the passed cell. */ - void setStandardNumFmt( - const ::com::sun::star::uno::Reference< ::com::sun::star::table::XCell >& rxCell, - sal_Int16 nStdNumFmt ) const; + /** Returns the BIFF drawing page for this sheet (BIFF2-BIFF8 only). */ + BiffSheetDrawing& getBiffDrawing() const; /** Changes the current sheet type. */ void setSheetType( WorksheetType eSheetType ); - /** Stores the cell formatting data of the current cell. */ - void setCellFormat( const CellModel& rModel ); - /** Merges the cells in the passed cell range. */ - void setMergedRange( const ::com::sun::star::table::CellRangeAddress& rRange ); /** Sets a column or row page break described in the passed struct. */ void setPageBreak( const PageBreakModel& rModel, bool bRowBreak ); /** Inserts the hyperlink URL into the spreadsheet. */ void setHyperlink( const HyperlinkModel& rModel ); /** Inserts the data validation settings into the spreadsheet. */ void setValidation( const ValidationModel& rModel ); - /** Sets a multiple table operation to the passed range. */ - void setTableOperation( - const ::com::sun::star::table::CellRangeAddress& rRange, - const DataTableModel& rModel ) const; /** Sets the passed label ranges to the current sheet. */ - void setLabelRanges( - const ApiCellRangeList& rColRanges, - const ApiCellRangeList& rRowRanges ); + void setLabelRanges( const ApiCellRangeList& rColRanges, const ApiCellRangeList& rRowRanges ); /** Sets the path to the DrawingML fragment of this sheet. */ void setDrawingPath( const ::rtl::OUString& rDrawingPath ); /** Sets the path to the legacy VML drawing fragment of this sheet. */ @@ -413,6 +315,26 @@ public: @descr Row default formatting is converted directly, other settings are cached and converted in the finalizeWorksheetImport() call. */ void setRowModel( const RowModel& rModel ); + /** Specifies that the passed row needs to set its height manually. */ + void setManualRowHeight( sal_Int32 nRow ); + + /** Inserts a value cell directly into the Calc sheet. */ + void putValue( + const ::com::sun::star::table::CellAddress& rAddress, + double fValue ) const; + /** Inserts a string cell directly into the Calc sheet. */ + void putString( + const ::com::sun::star::table::CellAddress& rAddress, + const ::rtl::OUString& rText ) const; + /** Inserts a rich-string cell directly into the Calc sheet. */ + void putRichString( + const ::com::sun::star::table::CellAddress& rAddress, + const RichString& rString, + const Font* pFirstPortionFont ) const; + /** Inserts a formula cell directly into the Calc sheet. */ + void putFormulaTokens( + const ::com::sun::star::table::CellAddress& rAddress, + const ApiTokenSequence& rTokens ) const; /** Initial conversion before importing the worksheet. */ void initializeWorksheetImport(); @@ -420,50 +342,7 @@ public: void finalizeWorksheetImport(); private: - WorksheetData& mrSheetData; -}; - -// ============================================================================ - -namespace prv { - -typedef ::boost::shared_ptr< WorksheetData > WorksheetDataRef; - -struct WorksheetDataOwner -{ - explicit WorksheetDataOwner( WorksheetDataRef xSheetData ); - virtual ~WorksheetDataOwner(); - WorksheetDataRef mxSheetData; -}; - -} // namespace prv - -// ---------------------------------------------------------------------------- - -class WorksheetHelperRoot : private prv::WorksheetDataOwner, public WorksheetHelper -{ -public: - /** Returns true, if this helper refers to an existing Calc sheet. */ - bool isValidSheet() const; - -protected: - /** Constructs from the passed data, creates and owns a new data object. */ - explicit WorksheetHelperRoot( - const WorkbookHelper& rHelper, - const ISegmentProgressBarRef& rxProgressBar, - WorksheetType eSheetType, - sal_Int16 nSheet ); - - /** Constructs from another sheet helper, does not create a data object. */ - explicit WorksheetHelperRoot( - const WorksheetHelper& rHelper ); - - /** Constructs from another sheet helper, shares ownership of the passed helper. */ - explicit WorksheetHelperRoot( - const WorksheetHelperRoot& rHelper ); - -private: - WorksheetHelperRoot& operator=( const WorksheetHelperRoot& ); + WorksheetGlobals& mrSheetGlob; }; // ============================================================================ |