diff options
Diffstat (limited to 'oox/inc/oox/xls')
56 files changed, 12487 insertions, 0 deletions
diff --git a/oox/inc/oox/xls/addressconverter.hxx b/oox/inc/oox/xls/addressconverter.hxx new file mode 100644 index 000000000000..11b5e74ccd5c --- /dev/null +++ b/oox/inc/oox/xls/addressconverter.hxx @@ -0,0 +1,691 @@ +/************************************************************************* + * + * 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_ADDRESSCONVERTER_HXX +#define OOX_XLS_ADDRESSCONVERTER_HXX + +#include <vector> +#include <com/sun/star/table/CellAddress.hpp> +#include <com/sun/star/table/CellRangeAddress.hpp> +#include "oox/xls/workbookhelper.hxx" + +namespace oox { +namespace xls { + +class BiffInputStream; +class BiffOutputStream; + +// ============================================================================ +// ============================================================================ + +/** A vector of com.sun.star.table.CellRangeAddress elements and additional + functionality. */ +class ApiCellRangeList : public ::std::vector< ::com::sun::star::table::CellRangeAddress > +{ +public: + inline explicit ApiCellRangeList() {} + + /** Returns the base address of this range list (top-left cell of first range). */ + ::com::sun::star::table::CellAddress + getBaseAddress() const; +}; + +// ============================================================================ + +/** A 2D cell address struct for binary filters. */ +struct BinAddress +{ + sal_Int32 mnCol; + sal_Int32 mnRow; + + inline explicit BinAddress() : mnCol( 0 ), mnRow( 0 ) {} + inline explicit BinAddress( sal_Int32 nCol, sal_Int32 nRow ) : mnCol( nCol ), mnRow( nRow ) {} + inline explicit BinAddress( const ::com::sun::star::table::CellAddress& rAddr ) : mnCol( rAddr.Column ), mnRow( rAddr.Row ) {} + + inline void set( sal_Int32 nCol, sal_Int32 nRow ) { mnCol = nCol; mnRow = nRow; } + inline void set( const ::com::sun::star::table::CellAddress& rAddr ) { mnCol = rAddr.Column; mnRow = rAddr.Row; } + + void read( SequenceInputStream& rStrm ); + void read( BiffInputStream& rStrm, bool bCol16Bit = true, bool bRow32Bit = false ); + void write( BiffOutputStream& rStrm, bool bCol16Bit = true, bool bRow32Bit = false ) const; +}; + +// ---------------------------------------------------------------------------- + +inline bool operator==( const BinAddress& rL, const BinAddress& rR ) +{ + return (rL.mnCol == rR.mnCol) && (rL.mnRow == rR.mnRow); +} + +inline bool operator<( const BinAddress& rL, const BinAddress& rR ) +{ + return (rL.mnCol < rR.mnCol) || ((rL.mnCol == rR.mnCol) && (rL.mnRow < rR.mnRow)); +} + +inline SequenceInputStream& operator>>( SequenceInputStream& rStrm, BinAddress& orPos ) +{ + orPos.read( rStrm ); + return rStrm; +} + +inline BiffInputStream& operator>>( BiffInputStream& rStrm, BinAddress& orPos ) +{ + orPos.read( rStrm ); + return rStrm; +} + +inline BiffOutputStream& operator<<( BiffOutputStream& rStrm, const BinAddress& rPos ) +{ + rPos.write( rStrm ); + return rStrm; +} + +// ============================================================================ + +/** A 2D cell range address struct for binary filters. */ +struct BinRange +{ + BinAddress maFirst; + BinAddress maLast; + + inline explicit BinRange() {} + inline explicit BinRange( const BinAddress& rAddr ) : maFirst( rAddr ), maLast( rAddr ) {} + inline explicit BinRange( const BinAddress& rFirst, const BinAddress& rLast ) : maFirst( rFirst ), maLast( rLast ) {} + inline explicit BinRange( sal_Int32 nCol1, sal_Int32 nRow1, sal_Int32 nCol2, sal_Int32 nRow2 ) : + maFirst( nCol1, nRow1 ), maLast( nCol2, nRow2 ) {} + inline explicit BinRange( const ::com::sun::star::table::CellAddress& rAddr ) : maFirst( rAddr ), maLast( rAddr ) {} + inline explicit BinRange( const ::com::sun::star::table::CellAddress& rFirst, const ::com::sun::star::table::CellAddress& rLast ) : maFirst( rFirst ), maLast( rLast ) {} + inline explicit BinRange( const ::com::sun::star::table::CellRangeAddress& rRange ) : maFirst( rRange.StartColumn, rRange.StartRow ), maLast( rRange.EndColumn, rRange.EndRow ) {} + + inline void set( const BinAddress& rFirst, const BinAddress& rLast ) + { maFirst = rFirst; maLast = rLast; } + inline void set( sal_Int32 nCol1, sal_Int32 nRow1, sal_Int32 nCol2, sal_Int32 nRow2 ) + { maFirst.set( nCol1, nRow1 ); maLast.set( nCol2, nRow2 ); } + inline void set( const ::com::sun::star::table::CellAddress& rFirst, const ::com::sun::star::table::CellAddress& rLast ) + { maFirst.set( rFirst ); maLast.set( rLast ); } + inline void set( const ::com::sun::star::table::CellRangeAddress& rRange ) + { maFirst.set( rRange.StartColumn, rRange.StartRow ); maLast.set( rRange.EndColumn, rRange.EndRow ); } + + inline sal_Int32 getColCount() const { return maLast.mnCol - maFirst.mnCol + 1; } + inline sal_Int32 getRowCount() const { return maLast.mnRow - maFirst.mnRow + 1; } + bool contains( const BinAddress& rAddr ) const; + + void read( SequenceInputStream& rStrm ); + void read( BiffInputStream& rStrm, bool bCol16Bit = true, bool bRow32Bit = false ); + void write( BiffOutputStream& rStrm, bool bCol16Bit = true, bool bRow32Bit = false ) const; +}; + +// ---------------------------------------------------------------------------- + +inline bool operator==( const BinRange& rL, const BinRange& rR ) +{ + return (rL.maFirst == rR.maFirst) && (rL.maLast == rR.maLast); +} + +inline bool operator<( const BinRange& rL, const BinRange& rR ) +{ + return (rL.maFirst < rR.maFirst) || ((rL.maFirst == rR.maFirst) && (rL.maLast < rR.maLast)); +} + +inline SequenceInputStream& operator>>( SequenceInputStream& rStrm, BinRange& orRange ) +{ + orRange.read( rStrm ); + return rStrm; +} + +inline BiffInputStream& operator>>( BiffInputStream& rStrm, BinRange& orRange ) +{ + orRange.read( rStrm ); + return rStrm; +} + +inline BiffOutputStream& operator<<( BiffOutputStream& rStrm, const BinRange& rRange ) +{ + rRange.write( rStrm ); + return rStrm; +} + +// ============================================================================ + +/** A 2D cell range address list for binary filters. */ +class BinRangeList : public ::std::vector< BinRange > +{ +public: + inline explicit BinRangeList() {} + + BinRange getEnclosingRange() const; + + void read( SequenceInputStream& rStrm ); + void read( BiffInputStream& rStrm, bool bCol16Bit = true, bool bRow32Bit = false ); + void write( BiffOutputStream& rStrm, bool bCol16Bit = true, bool bRow32Bit = false ) const; + void writeSubList( BiffOutputStream& rStrm, + size_t nBegin, size_t nCount, bool bCol16Bit = true, bool bRow32Bit = false ) const; +}; + +// ---------------------------------------------------------------------------- + +inline SequenceInputStream& operator>>( SequenceInputStream& rStrm, BinRangeList& orRanges ) +{ + orRanges.read( rStrm ); + return rStrm; +} + +inline BiffInputStream& operator>>( BiffInputStream& rStrm, BinRangeList& orRanges ) +{ + orRanges.read( rStrm ); + return rStrm; +} + +inline BiffOutputStream& operator<<( BiffOutputStream& rStrm, const BinRangeList& rRanges ) +{ + rRanges.write( rStrm ); + return rStrm; +} + +// ============================================================================ + +/** Different target types that can be encoded in a BIFF URL. */ +enum BiffTargetType +{ + BIFF_TARGETTYPE_URL, /// URL, URL with sheet name, or sheet name. + BIFF_TARGETTYPE_SAMESHEET, /// Target for special '!A1' syntax to refer to current sheet. + BIFF_TARGETTYPE_LIBRARY, /// Library directory in application installation. + BIFF_TARGETTYPE_DDE_OLE, /// DDE server/topic or OLE class/target. + BIFF_TARGETTYPE_UNKNOWN /// Unknown/unsupported target type. +}; + +// ============================================================================ +// ============================================================================ + +/** Converter for cell addresses and cell ranges for OOXML and BIFF filters. + */ +class AddressConverter : public WorkbookHelper +{ +public: + explicit AddressConverter( const WorkbookHelper& rHelper ); + + // ------------------------------------------------------------------------ + + /** Tries to parse the passed string for a 2d cell address in A1 notation. + + This function accepts all strings that match the regular expression + "[a-zA-Z]{1,6}0*[1-9][0-9]{0,8}" (without quotes), i.e. 1 to 6 letters + for the column index (translated to 0-based column indexes from 0 to + 321,272,405), and 1 to 9 digits for the 1-based row index (translated + to 0-based row indexes from 0 to 999,999,998). The row number part may + contain leading zeros, they will be ignored. It is up to the caller to + handle cell addresses outside of a specific valid range (e.g. the + entire spreadsheet). + + @param ornColumn (out-parameter) Returns the converted column index. + @param ornRow (out-parameter) returns the converted row index. + @param rString The string containing the cell address. + @param nStart Start index of string part in rString to be parsed. + @param nLength Length of string part in rString to be parsed. + + @return true = Parsed string was valid, returned values can be used. + */ + static bool parseOoxAddress2d( + sal_Int32& ornColumn, sal_Int32& ornRow, + const ::rtl::OUString& rString, + sal_Int32 nStart = 0, + sal_Int32 nLength = SAL_MAX_INT32 ); + + /** Tries to parse the passed string for a 2d cell range in A1 notation. + + This function accepts all strings that match the regular expression + "ADDR(:ADDR)?" (without quotes), where ADDR is a cell address accepted + by the parseOoxAddress2d() function of this class. It is up to the + caller to handle cell ranges outside of a specific valid range (e.g. + the entire spreadsheet). + + @param ornStartColumn (out-parameter) Returns the converted start column index. + @param ornStartRow (out-parameter) returns the converted start row index. + @param ornEndColumn (out-parameter) Returns the converted end column index. + @param ornEndRow (out-parameter) returns the converted end row index. + @param rString The string containing the cell address. + @param nStart Start index of string part in rString to be parsed. + @param nLength Length of string part in rString to be parsed. + + @return true = Parsed string was valid, returned values can be used. + */ + static bool parseOoxRange2d( + sal_Int32& ornStartColumn, sal_Int32& ornStartRow, + sal_Int32& ornEndColumn, sal_Int32& ornEndRow, + const ::rtl::OUString& rString, + sal_Int32 nStart = 0, + sal_Int32 nLength = SAL_MAX_INT32 ); + + /** Tries to parse an encoded name of an external link target in BIFF + documents, e.g. from EXTERNSHEET or SUPBOOK records. + + @param orClassName (out-parameter) DDE server name or OLE class name. + @param orTargetUrl (out-parameter) Target URL, DDE topic or OLE object name. + @param orSheetName (out-parameter) Sheet name in target document. + @param rBiffEncoded Encoded name of the external link target. + @param bFromDConRec True = path from DCONREF/DCONNAME/DCONBINAME records, false = other records. + + @return Type of the decoded target. + */ + BiffTargetType parseBiffTargetUrl( + ::rtl::OUString& orClassName, + ::rtl::OUString& orTargetUrl, + ::rtl::OUString& orSheetName, + const ::rtl::OUString& rBiffTargetUrl, + bool bFromDConRec = false ); + + // ------------------------------------------------------------------------ + + /** Returns the biggest valid cell address in the own Calc document. */ + inline const ::com::sun::star::table::CellAddress& + getMaxApiAddress() const { return maMaxApiPos; } + + /** Returns the biggest valid cell address in the imported/exported + Excel document. */ + inline const ::com::sun::star::table::CellAddress& + getMaxXlsAddress() const { return maMaxXlsPos; } + + /** Returns the biggest valid cell address in both Calc and the + imported/exported Excel document. */ + inline const ::com::sun::star::table::CellAddress& + getMaxAddress() const { return maMaxPos; } + + /** Returns the column overflow status. */ + inline bool isColOverflow() const { return mbColOverflow; } + /** Returns the row overflow status. */ + inline bool isRowOverflow() const { return mbRowOverflow; } + /** Returns the sheet overflow status. */ + inline bool isTabOverflow() const { return mbTabOverflow; } + + // ------------------------------------------------------------------------ + + /** Checks if the passed column index is valid. + + @param nCol The column index to check. + @param bTrackOverflow true = Update the internal overflow flag, if the + column index is outside of the supported limits. + @return true = Passed column index is valid (no index overflow). + */ + bool checkCol( sal_Int32 nCol, bool bTrackOverflow ); + + /** Checks if the passed row index is valid. + + @param nRow The row index to check. + @param bTrackOverflow true = Update the internal overflow flag, if the + row index is outside of the supported limits. + @return true = Passed row index is valid (no index overflow). + */ + bool checkRow( sal_Int32 nRow, bool bTrackOverflow ); + + /** Checks if the passed sheet index is valid. + + @param nSheet The sheet index to check. + @param bTrackOverflow true = Update the internal overflow flag, if the + sheet index is outside of the supported limits. + @return true = Passed sheet index is valid (no index overflow). + */ + bool checkTab( sal_Int16 nSheet, bool bTrackOverflow ); + + // ------------------------------------------------------------------------ + + /** Checks the passed cell address if it fits into the spreadsheet limits. + + @param rAddress The cell address to be checked. + @param bTrackOverflow true = Update the internal overflow flags, if + the address is outside of the supported sheet limits. + @return true = Passed address is valid (no index overflow). + */ + bool checkCellAddress( + const ::com::sun::star::table::CellAddress& rAddress, + bool bTrackOverflow ); + + /** Converts the passed string to a single cell address, without checking + any sheet limits. + + @param orAddress (out-parameter) Returns the converted cell address. + @param rString Cell address string in A1 notation. + @param nSheet Sheet index to be inserted into orAddress. + @return true = Cell address could be parsed from the passed string. + */ + bool convertToCellAddressUnchecked( + ::com::sun::star::table::CellAddress& orAddress, + const ::rtl::OUString& rString, + sal_Int16 nSheet ); + + /** Tries to convert the passed string to a single cell address. + + @param orAddress (out-parameter) Returns the converted cell address. + @param rString Cell address string in A1 notation. + @param nSheet Sheet index to be inserted into orAddress (will be checked). + @param bTrackOverflow true = Update the internal overflow flags, if + the address is outside of the supported sheet limits. + @return true = Converted address is valid (no index overflow). + */ + bool convertToCellAddress( + ::com::sun::star::table::CellAddress& orAddress, + const ::rtl::OUString& rString, + sal_Int16 nSheet, + bool bTrackOverflow ); + + /** Returns a valid cell address by moving it into allowed dimensions. + + @param rString Cell address string in A1 notation. + @param nSheet Sheet index for the returned address (will be checked). + @param bTrackOverflow true = Update the internal overflow flags, if + the address is outside of the supported sheet limits. + @return A valid API cell address struct. */ + ::com::sun::star::table::CellAddress + createValidCellAddress( + const ::rtl::OUString& rString, + sal_Int16 nSheet, + bool bTrackOverflow ); + + /** Converts the passed address to a single cell address, without checking + any sheet limits. + + @param orAddress (out-parameter) Returns the converted cell address. + @param rBinAddress Binary cell address struct. + @param nSheet Sheet index to be inserted into orAddress. + */ + void convertToCellAddressUnchecked( + ::com::sun::star::table::CellAddress& orAddress, + const BinAddress& rBinAddress, + sal_Int16 nSheet ); + + /** Tries to convert the passed address to a single cell address. + + @param orAddress (out-parameter) Returns the converted cell address. + @param rBinAddress Binary cell address struct. + @param nSheet Sheet index to be inserted into orAddress (will be checked). + @param bTrackOverflow true = Update the internal overflow flags, if + the address is outside of the supported sheet limits. + @return true = Converted address is valid (no index overflow). + */ + bool convertToCellAddress( + ::com::sun::star::table::CellAddress& orAddress, + const BinAddress& rBinAddress, + sal_Int16 nSheet, + bool bTrackOverflow ); + + /** Returns a valid cell address by moving it into allowed dimensions. + + @param rBinAddress Binary cell address struct. + @param nSheet Sheet index for the returned address (will be checked). + @param bTrackOverflow true = Update the internal overflow flags, if + the address is outside of the supported sheet limits. + @return A valid API cell address struct. */ + ::com::sun::star::table::CellAddress + createValidCellAddress( + const BinAddress& rBinAddress, + sal_Int16 nSheet, + bool bTrackOverflow ); + + // ------------------------------------------------------------------------ + + /** Checks the passed cell range if it fits into the spreadsheet limits. + + @param rRange The cell range address to be checked. + @param bAllowOverflow true = Allow ranges that start inside the + supported sheet limits but may end outside of these limits. + false = Do not allow ranges that overflow the supported limits. + @param bTrackOverflow true = Update the internal overflow flags, if + the passed range contains cells outside of the supported sheet + limits. + @return true = Cell range is valid. This function returns also true, + if only parts of the range are outside the current sheet limits and + such an overflow is allowed via parameter bAllowOverflow. Returns + false, if the entire range is outside the sheet limits, or if + overflow is not allowed via parameter bAllowOverflow. + */ + bool checkCellRange( + const ::com::sun::star::table::CellRangeAddress& rRange, + bool bAllowOverflow, bool bTrackOverflow ); + + /** Checks the passed cell range, may try to fit it to current sheet limits. + + First, this function reorders the column and row indexes so that the + starting indexes are less than or equal to the end indexes. Then, + depending on the parameter bAllowOverflow, the range is just checked or + cropped to the current sheet limits. + + @param orRange (in-out-parameter) Converts the passed cell range + into a valid cell range address. If the passed range contains cells + outside the currently supported spreadsheet limits, it will be + cropped to these limits. + @param bAllowOverflow true = Allow ranges that start inside the + supported sheet limits but may end outside of these limits. The + cell range returned in orRange will be cropped to these limits. + false = Do not allow ranges that overflow the supported limits. The + function will return false when the range overflows the sheet limits. + @param bTrackOverflow true = Update the internal overflow flags, if + the original range contains cells outside of the supported sheet + limits. + @return true = Converted range address is valid. This function + returns also true, if overflowing ranges are allowed via parameter + bAllowOverflow and the range has been cropped, but still contains + cells inside the current sheet limits. Returns false, if the entire + range is outside the sheet limits or overflowing ranges are not + allowed via parameter bAllowOverflow. + */ + bool validateCellRange( + ::com::sun::star::table::CellRangeAddress& orRange, + bool bAllowOverflow, bool bTrackOverflow ); + + /** Converts the passed string to a cell range address, without checking + any sheet limits. + + @param orRange (out-parameter) Returns the converted range address. + @param rString Cell range string in A1 notation. + @param nSheet Sheet index to be inserted into orRange. + @return true = Range address could be parsed from the passed string. + */ + bool convertToCellRangeUnchecked( + ::com::sun::star::table::CellRangeAddress& orRange, + const ::rtl::OUString& rString, + sal_Int16 nSheet ); + + /** Tries to convert the passed string to a cell range address. + + @param orRange (out-parameter) Returns the converted cell range + address. If the original range in the passed string contains cells + outside the currently supported spreadsheet limits, and parameter + bAllowOverflow is set to true, the range will be cropped to these + limits. Example: the range string "A1:ZZ100000" may be converted to + the range A1:IV65536. + @param rString Cell range string in A1 notation. + @param nSheet Sheet index to be inserted into orRange (will be checked). + @param bAllowOverflow true = Allow ranges that start inside the + supported sheet limits but may end outside of these limits. The + cell range returned in orRange will be cropped to these limits. + false = Do not allow ranges that overflow the supported limits. + @param bTrackOverflow true = Update the internal overflow flags, if + the original range contains cells outside of the supported sheet + limits. + @return true = Converted and returned range is valid. This function + returns also true, if overflowing ranges are allowed via parameter + bAllowOverflow and the range has been cropped, but still contains + cells inside the current sheet limits. Returns false, if the entire + range is outside the sheet limits or overflowing ranges are not + allowed via parameter bAllowOverflow. + */ + bool convertToCellRange( + ::com::sun::star::table::CellRangeAddress& orRange, + const ::rtl::OUString& rString, + sal_Int16 nSheet, + bool bAllowOverflow, bool bTrackOverflow ); + + /** Converts the passed range to a cell range address, without checking any + sheet limits. + + @param orRange (out-parameter) Returns the converted range address. + @param rBinRange Binary cell range struct. + @param nSheet Sheet index to be inserted into orRange. + */ + void convertToCellRangeUnchecked( + ::com::sun::star::table::CellRangeAddress& orRange, + const BinRange& rBinRange, + sal_Int16 nSheet ); + + /** Tries to convert the passed range to a cell range address. + + @param orRange (out-parameter) Returns the converted cell range + address. If the passed original range contains cells outside the + currently supported spreadsheet limits, and parameter bAllowOverflow + is set to true, the range will be cropped to these limits. + @param rBinRange Binary cell range struct. + @param nSheet Sheet index to be inserted into orRange (will be checked). + @param bAllowOverflow true = Allow ranges that start inside the + supported sheet limits but may end outside of these limits. The + cell range returned in orRange will be cropped to these limits. + false = Do not allow ranges that overflow the supported limits. + @param bTrackOverflow true = Update the internal overflow flags, if + the original range contains cells outside of the supported sheet + limits. + @return true = Converted and returned range is valid. This function + returns also true, if overflowing ranges are allowed via parameter + bAllowOverflow and the range has been cropped, but still contains + cells inside the current sheet limits. Returns false, if the entire + range is outside the sheet limits or if overflowing ranges are not + allowed via parameter bAllowOverflow. + */ + bool convertToCellRange( + ::com::sun::star::table::CellRangeAddress& orRange, + const BinRange& rBinRange, + sal_Int16 nSheet, + bool bAllowOverflow, bool bTrackOverflow ); + + // ------------------------------------------------------------------------ + + /** Checks the passed cell range list if it fits into the spreadsheet limits. + + @param rRanges The cell range list to be checked. + @param bAllowOverflow true = Allow ranges that start inside the + supported sheet limits but may end outside of these limits. + false = Do not allow ranges that overflow the supported limits. + @param bTrackOverflow true = Update the internal overflow flags, if + the passed range list contains cells outside of the supported sheet + limits. + @return true = All cell ranges are valid. This function returns also + true, if overflowing ranges are allowed via parameter bAllowOverflow + and only parts of the ranges are outside the current sheet limits. + Returns false, if one of the ranges is completely outside the sheet + limits or if overflowing ranges are not allowed via parameter + bAllowOverflow. + */ + bool checkCellRangeList( + const ApiCellRangeList& rRanges, + bool bAllowOverflow, bool bTrackOverflow ); + + /** Tries to restrict the passed cell range list to current sheet limits. + + @param orRanges (in-out-parameter) Restricts the cell range addresses + in the passed list to the current sheet limits and removes invalid + ranges from the list. + @param bTrackOverflow true = Update the internal overflow flags, if + the original ranges contain cells outside of the supported sheet + limits. + */ + void validateCellRangeList( + ApiCellRangeList& orRanges, + bool bTrackOverflow ); + + /** Tries to convert the passed string to a cell range list. + + @param orRanges (out-parameter) Returns the converted cell range + addresses. If a range in the passed string contains cells outside + the currently supported spreadsheet limits, it will be cropped to + these limits. Example: the range string "A1:ZZ100000" may be + converted to the range A1:IV65536. If a range is completely outside + the limits, it will be omitted. + @param rString Cell range list string in A1 notation, space separated. + @param nSheet Sheet index to be inserted into orRanges (will be checked). + @param bTrackOverflow true = Update the internal overflow flags, if + the original ranges contain cells outside of the supported sheet + limits. + */ + void convertToCellRangeList( + ApiCellRangeList& orRanges, + const ::rtl::OUString& rString, + sal_Int16 nSheet, + bool bTrackOverflow ); + + /** Tries to convert the passed range list to a cell range list. + + @param orRanges (out-parameter) Returns the converted cell range + addresses. If a range in the passed string contains cells outside + the currently supported spreadsheet limits, it will be cropped to + these limits. Example: the range string "A1:ZZ100000" may be + converted to the range A1:IV65536. If a range is completely outside + the limits, it will be omitted. + @param rBinRanges List of binary cell range objects. + @param nSheet Sheet index to be inserted into orRanges (will be checked). + @param bTrackOverflow true = Update the internal overflow flags, if + the original ranges contain cells outside of the supported sheet + limits. + */ + void convertToCellRangeList( + ApiCellRangeList& orRanges, + const BinRangeList& rBinRanges, + sal_Int16 nSheet, + bool bTrackOverflow ); + + // ------------------------------------------------------------------------ +private: + void initializeMaxPos( + sal_Int16 nMaxXlsTab, sal_Int32 nMaxXlsCol, sal_Int32 nMaxXlsRow ); + +private: + struct ControlCharacters + { + sal_Unicode mcThisWorkbook; /// Control character: Link to current workbook. + sal_Unicode mcExternal; /// Control character: Link to external workbook/sheet. + sal_Unicode mcThisSheet; /// Control character: Link to current sheet. + sal_Unicode mcInternal; /// Control character: Link to internal sheet. + sal_Unicode mcSameSheet; /// Control character: Link to same sheet (special '!A1' syntax). + + void set( + sal_Unicode cThisWorkbook, sal_Unicode cExternal, + sal_Unicode cThisSheet, sal_Unicode cInternal, + sal_Unicode cSameSheet ); + }; + + ::com::sun::star::table::CellAddress maMaxApiPos; /// Maximum valid cell address in Calc. + ::com::sun::star::table::CellAddress maMaxXlsPos; /// Maximum valid cell address in Excel. + ::com::sun::star::table::CellAddress maMaxPos; /// Maximum valid cell address in Calc/Excel. + ControlCharacters maLinkChars; /// Control characters for external link import (BIFF). + ControlCharacters maDConChars; /// Control characters for DCON* record import (BIFF). + bool mbColOverflow; /// Flag for "columns overflow". + bool mbRowOverflow; /// Flag for "rows overflow". + bool mbTabOverflow; /// Flag for "tables overflow". +}; + +// ============================================================================ + +} // namespace xls +} // namespace oox + +#endif diff --git a/oox/inc/oox/xls/autofilterbuffer.hxx b/oox/inc/oox/xls/autofilterbuffer.hxx new file mode 100755 index 000000000000..ddf083c2ea98 --- /dev/null +++ b/oox/inc/oox/xls/autofilterbuffer.hxx @@ -0,0 +1,279 @@ +/************************************************************************* + * + * 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_AUTOFILTERBUFFER_HXX +#define OOX_XLS_AUTOFILTERBUFFER_HXX + +#include <com/sun/star/table/CellRangeAddress.hpp> +#include "oox/helper/refvector.hxx" +#include "oox/xls/workbookhelper.hxx" + +namespace com { namespace sun { namespace star { + namespace sheet { struct TableFilterField2; } + namespace sheet { class XDatabaseRange; } + namespace sheet { class XSheetFilterDescriptor2; } +} } } + +namespace oox { +namespace xls { + +// ============================================================================ + +/** Contains UNO API filter settings for a column in a filtered range. */ +struct ApiFilterSettings +{ + typedef ::std::vector< ::com::sun::star::sheet::TableFilterField2 > FilterFieldVector; + + FilterFieldVector maFilterFields; /// List of UNO API filter settings. + OptValue< bool > mobNeedsRegExp; /// If set, requires regular expressions to be enabled/disabled. + + explicit ApiFilterSettings(); + + void appendField( bool bAnd, sal_Int32 nOperator, double fValue ); + void appendField( bool bAnd, sal_Int32 nOperator, const ::rtl::OUString& rValue ); +}; + +// ============================================================================ + +/** Base class for specific filter settings for a column in a filtered range. + */ +class FilterSettingsBase : public WorkbookHelper +{ +public: + explicit FilterSettingsBase( const WorkbookHelper& rHelper ); + + /** Derived classes import filter settings from the passed attribute list. */ + virtual void importAttribs( sal_Int32 nElement, const AttributeList& rAttribs ); + /** Derived classes import filter settings from the passed record. */ + virtual void importRecord( sal_Int32 nRecId, SequenceInputStream& rStrm ); + /** Derived classes import filter settings from the FILTERCOLUMN record. */ + virtual void importBiffRecord( BiffInputStream& rStrm, sal_uInt16 nFlags ); + + /** Derived classes return converted UNO API filter settings representing all filter settings. */ + virtual ApiFilterSettings finalizeImport( sal_Int32 nMaxCount ); +}; + +typedef ::boost::shared_ptr< FilterSettingsBase > FilterSettingsRef; + +// ============================================================================ + +/** Settings for a discrete filter, specifying a list of values to be shown in + the filtered range. + */ +class DiscreteFilter : public FilterSettingsBase +{ +public: + explicit DiscreteFilter( const WorkbookHelper& rHelper ); + + /** Imports filter settings from the filters and filter elements. */ + virtual void importAttribs( sal_Int32 nElement, const AttributeList& rAttribs ); + /** Imports filter settings from the FILTERS and FILTER records. */ + virtual void importRecord( sal_Int32 nRecId, SequenceInputStream& rStrm ); + + /** Returns converted UNO API filter settings representing all filter settings. */ + virtual ApiFilterSettings finalizeImport( sal_Int32 nMaxCount ); + +private: + typedef ::std::vector< ::rtl::OUString > FilterValueVector; + + FilterValueVector maValues; + sal_Int32 mnCalendarType; + bool mbShowBlank; +}; + +// ============================================================================ + +/** Settings for a top-10 filter. */ +class Top10Filter : public FilterSettingsBase +{ +public: + explicit Top10Filter( const WorkbookHelper& rHelper ); + + /** Imports filter settings from the filters and filter elements. */ + virtual void importAttribs( sal_Int32 nElement, const AttributeList& rAttribs ); + /** Imports filter settings from the FILTERS and FILTER records. */ + virtual void importRecord( sal_Int32 nRecId, SequenceInputStream& rStrm ); + /** Imports filter settings from the FILTERCOLUMN record. */ + virtual void importBiffRecord( BiffInputStream& rStrm, sal_uInt16 nFlags ); + + /** Returns converted UNO API filter settings representing all filter settings. */ + virtual ApiFilterSettings finalizeImport( sal_Int32 nMaxCount ); + +private: + double mfValue; /// Number of items or percentage. + bool mbTop; /// True = show top (greatest) items/percentage. + bool mbPercent; /// True = percentage, false = number of items. +}; + +// ============================================================================ + +/** A filter criterion for a custom filter. */ +struct FilterCriterionModel +{ + ::com::sun::star::uno::Any maValue; /// Comparison operand. + sal_Int32 mnOperator; /// Comparison operator. + sal_uInt8 mnDataType; /// Operand data type (BIFF only). + sal_uInt8 mnStrLen; /// Length of string operand (BIFF5-BIFF8 only). + + explicit FilterCriterionModel(); + + /** Sets the passed BIFF operator constant. */ + void setBiffOperator( sal_uInt8 nOperator ); + + /** Imports the criterion model from the passed BIFF12 stream. */ + void readBiffData( SequenceInputStream& rStrm ); + /** Imports the initial criterion data from the passed BIFF5/BIFF8 stream. */ + void readBiffData( BiffInputStream& rStrm ); + /** Imports the trailing string data from the passed BIFF5/BIFF8 stream. */ + void readString( BiffInputStream& rStrm, BiffType eBiff, rtl_TextEncoding eTextEnc ); +}; + +// ---------------------------------------------------------------------------- + +/** Settings for a custom filter, specifying one or two comparison operators + associated with some values. + */ +class CustomFilter : public FilterSettingsBase +{ +public: + explicit CustomFilter( const WorkbookHelper& rHelper ); + + /** Imports filter settings from the filters and filter elements. */ + virtual void importAttribs( sal_Int32 nElement, const AttributeList& rAttribs ); + /** Imports filter settings from the FILTERS and FILTER records. */ + virtual void importRecord( sal_Int32 nRecId, SequenceInputStream& rStrm ); + /** Imports filter settings from the FILTERCOLUMN record. */ + virtual void importBiffRecord( BiffInputStream& rStrm, sal_uInt16 nFlags ); + + /** Returns converted UNO API filter settings representing all filter settings. */ + virtual ApiFilterSettings finalizeImport( sal_Int32 nMaxCount ); + +private: + /** Apeends the passed filter criteriom, if it contains valid settings. */ + void appendCriterion( const FilterCriterionModel& rCriterion ); + +private: + typedef ::std::vector< FilterCriterionModel > FilterCriterionVector; + + FilterCriterionVector maCriteria; + bool mbAnd; +}; + +// ============================================================================ + +/** A column in a filtered range. Contains an object with specific filter + settings for the cells in the column. + */ +class FilterColumn : public WorkbookHelper +{ +public: + explicit FilterColumn( const WorkbookHelper& rHelper ); + + /** Imports auto filter column settings from the filterColumn element. */ + void importFilterColumn( const AttributeList& rAttribs ); + /** Imports auto filter column settings from the FILTERCOLUMN record. */ + void importFilterColumn( SequenceInputStream& rStrm ); + /** Imports auto filter column settings from the FILTERCOLUMN record. */ + void importFilterColumn( BiffInputStream& rStrm ); + + /** Creates and returns the specified filter settings object. */ + template< typename FilterSettingsType > + inline FilterSettingsBase& createFilterSettings() + { mxSettings.reset( new FilterSettingsType( *this ) ); return *mxSettings; } + + /** Returns the index of the column in the filtered range this object is related to. */ + inline sal_Int32 getColumnId() const { return mnColId; } + + /** Returns converted UNO API filter settings representing all filter + settings of this column. */ + ApiFilterSettings finalizeImport( sal_Int32 nMaxCount ); + +private: + FilterSettingsRef mxSettings; + sal_Int32 mnColId; + bool mbHiddenButton; + bool mbShowButton; +}; + +// ============================================================================ + +class AutoFilter : public WorkbookHelper +{ +public: + explicit AutoFilter( const WorkbookHelper& rHelper ); + + /** Imports auto filter settings from the autoFilter element. */ + void importAutoFilter( const AttributeList& rAttribs, sal_Int16 nSheet ); + /** Imports auto filter settings from the AUTOFILTER record. */ + void importAutoFilter( SequenceInputStream& rStrm, sal_Int16 nSheet ); + + /** Creates a new auto filter column and stores it internally. */ + FilterColumn& createFilterColumn(); + + /** Applies the filter to the passed filter descriptor. */ + void finalizeImport( const ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XSheetFilterDescriptor2 >& rxFilterDesc ); + +private: + typedef RefVector< FilterColumn > FilterColumnVector; + + FilterColumnVector maFilterColumns; + ::com::sun::star::table::CellRangeAddress maRange; +}; + +// ============================================================================ + +class AutoFilterBuffer : public WorkbookHelper +{ +public: + explicit AutoFilterBuffer( const WorkbookHelper& rHelper ); + + /** Creates a new auto filter and stores it internally. */ + AutoFilter& createAutoFilter(); + + /** Applies filter settings to a new database range object (used for sheet + autofilter or advanced filter as specified by built-in defined names). */ + void finalizeImport( sal_Int16 nSheet ); + + /** Applies the filters to the passed database range object. + @return True = this buffer contains valid auto filter settings. */ + bool finalizeImport( const ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XDatabaseRange >& rxDatabaseRange ); + +private: + /** Returns the auto filter object used to perform auto filtering. */ + AutoFilter* getActiveAutoFilter(); + +private: + typedef RefVector< AutoFilter > AutoFilterVector; + AutoFilterVector maAutoFilters; +}; + +// ============================================================================ + +} // namespace xls +} // namespace oox + +#endif diff --git a/oox/inc/oox/xls/autofiltercontext.hxx b/oox/inc/oox/xls/autofiltercontext.hxx new file mode 100644 index 000000000000..13508bbf5e63 --- /dev/null +++ b/oox/inc/oox/xls/autofiltercontext.hxx @@ -0,0 +1,114 @@ +/************************************************************************* + * + * 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_AUTOFILTERCONTEXT_HXX +#define OOX_XLS_AUTOFILTERCONTEXT_HXX + +#include "oox/xls/excelhandlers.hxx" + +namespace oox { +namespace xls { + +class AutoFilter; +class FilterColumn; +class FilterSettingsBase; + +// ============================================================================ + +class FilterSettingsContext : public WorksheetContextBase +{ +public: + explicit FilterSettingsContext( WorksheetContextBase& rParent, FilterSettingsBase& rFilterSettings ); + +protected: + virtual ::oox::core::ContextHandlerRef onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ); + virtual void onStartElement( const AttributeList& rAttribs ); + + virtual ::oox::core::ContextHandlerRef onCreateRecordContext( sal_Int32 nRecId, SequenceInputStream& rStrm ); + virtual void onStartRecord( SequenceInputStream& rStrm ); + +private: + FilterSettingsBase& mrFilterSettings; +}; + +// ============================================================================ + +class FilterColumnContext : public WorksheetContextBase +{ +public: + explicit FilterColumnContext( WorksheetContextBase& rParent, FilterColumn& rFilterColumn ); + +protected: + virtual ::oox::core::ContextHandlerRef onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ); + virtual void onStartElement( const AttributeList& rAttribs ); + + virtual ::oox::core::ContextHandlerRef onCreateRecordContext( sal_Int32 nRecId, SequenceInputStream& rStrm ); + virtual void onStartRecord( SequenceInputStream& rStrm ); + +private: + FilterColumn& mrFilterColumn; +}; + +// ============================================================================ + +class AutoFilterContext : public WorksheetContextBase +{ +public: + explicit AutoFilterContext( WorksheetFragmentBase& rFragment, AutoFilter& rAutoFilter ); + +protected: + virtual ::oox::core::ContextHandlerRef onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ); + virtual void onStartElement( const AttributeList& rAttribs ); + + virtual ::oox::core::ContextHandlerRef onCreateRecordContext( sal_Int32 nRecId, SequenceInputStream& rStrm ); + virtual void onStartRecord( SequenceInputStream& rStrm ); + +private: + AutoFilter& mrAutoFilter; +}; + +// ============================================================================ + +class BiffAutoFilterContext : public BiffWorksheetContextBase +{ +public: + explicit BiffAutoFilterContext( const WorksheetHelper& rHelper, AutoFilter& rAutoFilter ); + +protected: + /** Imports all records related to the current auto filter. */ + virtual void importRecord( BiffInputStream& rStrm ); + +private: + AutoFilter& mrAutoFilter; +}; + +// ============================================================================ + +} // namespace xls +} // namespace oox + +#endif diff --git a/oox/inc/oox/xls/biffcodec.hxx b/oox/inc/oox/xls/biffcodec.hxx new file mode 100644 index 000000000000..9b9157c7e494 --- /dev/null +++ b/oox/inc/oox/xls/biffcodec.hxx @@ -0,0 +1,187 @@ +/************************************************************************* + * + * 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_BIFFCODEC_HXX +#define OOX_XLS_BIFFCODEC_HXX + +#include <vector> +#include <comphelper/docpasswordhelper.hxx> +#include "oox/core/binarycodec.hxx" +#include "oox/xls/workbookhelper.hxx" + +namespace oox { +namespace xls { + +// ============================================================================ + +const sal_Int64 BIFF_RCF_BLOCKSIZE = 1024; + +// ============================================================================ + +/** Base class for BIFF stream decoders. */ +class BiffDecoderBase : public ::comphelper::IDocPasswordVerifier +{ +public: + explicit BiffDecoderBase(); + virtual ~BiffDecoderBase(); + + /** Derived classes return a clone of the decoder for usage in new streams. */ + inline BiffDecoderBase* clone() { return implClone(); } + + /** Implementation of the ::comphelper::IDocPasswordVerifier interface. */ + virtual ::comphelper::DocPasswordVerifierResult verifyPassword( const ::rtl::OUString& rPassword, ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& o_rEncryptionData ); + virtual ::comphelper::DocPasswordVerifierResult verifyEncryptionData( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& o_rEncryptionData ); + + /** Returns true, if the decoder has been initialized correctly. */ + inline bool isValid() const { return mbValid; } + + /** Decodes nBytes bytes and writes encrypted data into the buffer pnDestData. */ + void decode( + sal_uInt8* pnDestData, + const sal_uInt8* pnSrcData, + sal_Int64 nStreamPos, + sal_uInt16 nBytes ); + +private: + /** Derived classes return a clone of the decoder for usage in new streams. */ + virtual BiffDecoderBase* implClone() = 0; + + /** Derived classes implement password verification and initialization of + the decoder. */ + virtual ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue > implVerifyPassword( const ::rtl::OUString& rPassword ) = 0; + virtual bool implVerifyEncryptionData( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& rEncryptionData ) = 0; + + /** Implementation of decryption of a memory block. */ + virtual void implDecode( + sal_uInt8* pnDestData, + const sal_uInt8* pnSrcData, + sal_Int64 nStreamPos, + sal_uInt16 nBytes ) = 0; + +private: + bool mbValid; /// True = decoder is correctly initialized. +}; + +typedef ::boost::shared_ptr< BiffDecoderBase > BiffDecoderRef; + +// ============================================================================ + +/** Decodes BIFF stream contents that are encoded using the old XOR algorithm. */ +class BiffDecoder_XOR : public BiffDecoderBase +{ +public: + explicit BiffDecoder_XOR( sal_uInt16 nKey, sal_uInt16 nHash ); + +private: + /** Copy constructor for cloning. */ + BiffDecoder_XOR( const BiffDecoder_XOR& rDecoder ); + + /** Returns a clone of the decoder for usage in new streams. */ + virtual BiffDecoder_XOR* implClone(); + + /** Implements password verification and initialization of the decoder. */ + virtual ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue > implVerifyPassword( const ::rtl::OUString& rPassword ); + virtual bool implVerifyEncryptionData( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& rEncryptionData ); + + + /** Implementation of decryption of a memory block. */ + virtual void implDecode( + sal_uInt8* pnDestData, + const sal_uInt8* pnSrcData, + sal_Int64 nStreamPos, + sal_uInt16 nBytes ); + +private: + ::oox::core::BinaryCodec_XOR maCodec; /// Cipher algorithm implementation. + ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue > maEncryptionData; + sal_uInt16 mnKey; + sal_uInt16 mnHash; +}; + +// ============================================================================ + +/** Decodes BIFF stream contents that are encoded using the RC4 algorithm. */ +class BiffDecoder_RCF : public BiffDecoderBase +{ +public: + explicit BiffDecoder_RCF( + sal_uInt8 pnSalt[ 16 ], + sal_uInt8 pnVerifier[ 16 ], + sal_uInt8 pnVerifierHash[ 16 ] ); + +private: + /** Copy constructor for cloning. */ + BiffDecoder_RCF( const BiffDecoder_RCF& rDecoder ); + + /** Returns a clone of the decoder for usage in new streams. */ + virtual BiffDecoder_RCF* implClone(); + + /** Implements password verification and initialization of the decoder. */ + virtual ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue > implVerifyPassword( const ::rtl::OUString& rPassword ); + virtual bool implVerifyEncryptionData( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& rEncryptionData ); + + /** Implementation of decryption of a memory block. */ + virtual void implDecode( + sal_uInt8* pnDestData, + const sal_uInt8* pnSrcData, + sal_Int64 nStreamPos, + sal_uInt16 nBytes ); + +private: + ::oox::core::BinaryCodec_RCF maCodec; /// Cipher algorithm implementation. + ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue > maEncryptionData; + ::std::vector< sal_uInt8 > maSalt; + ::std::vector< sal_uInt8 > maVerifier; + ::std::vector< sal_uInt8 > maVerifierHash; +}; + +// ============================================================================ + +/** Helper for BIFF stream codecs. Holds the used codec object. */ +class BiffCodecHelper : public WorkbookHelper +{ +public: + explicit BiffCodecHelper( const WorkbookHelper& rHelper ); + + /** Implementation helper, reads the FILEPASS and returns a decoder object. */ + static BiffDecoderRef implReadFilePass( BiffInputStream& rStrm, BiffType eBiff ); + + /** Imports the FILEPASS record, asks for a password and sets a decoder at the stream. */ + bool importFilePass( BiffInputStream& rStrm ); + /** Clones the contained decoder object if existing and sets it at the passed stream. */ + void cloneDecoder( BiffInputStream& rStrm ); + +private: + BiffDecoderRef mxDecoder; /// The decoder for import filter. +}; + +// ============================================================================ + +} // namespace xls +} // namespace oox + +#endif diff --git a/oox/inc/oox/xls/biffdetector.hxx b/oox/inc/oox/xls/biffdetector.hxx new file mode 100644 index 000000000000..df372c76d7cc --- /dev/null +++ b/oox/inc/oox/xls/biffdetector.hxx @@ -0,0 +1,97 @@ +/************************************************************************* + * + * 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_BIFFDETECTOR_HXX +#define OOX_XLS_BIFFDETECTOR_HXX + +#include <com/sun/star/document/XExtendedFilterDetection.hpp> +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <cppuhelper/implbase2.hxx> +#include "oox/helper/storagebase.hxx" +#include "oox/xls/biffhelper.hxx" + +namespace com { namespace sun { namespace star { + namespace beans { struct PropertyValue; } + namespace uno { class XComponentContext; } +} } } + +namespace oox { class BinaryInputStream; } + +namespace oox { +namespace xls { + +// ============================================================================ + +/** Detection service for BIFF streams or storages. */ +class BiffDetector : public ::cppu::WeakImplHelper2< + ::com::sun::star::lang::XServiceInfo, + ::com::sun::star::document::XExtendedFilterDetection > +{ +public: + explicit BiffDetector( + const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext ) + throw( ::com::sun::star::uno::RuntimeException ); + + virtual ~BiffDetector(); + + /** Detects the BIFF version of the passed stream. */ + static BiffType detectStreamBiffVersion( BinaryInputStream& rInStream ); + + /** Detects the BIFF version and workbook stream name of the passed storage. */ + static BiffType detectStorageBiffVersion( + ::rtl::OUString& orWorkbookStreamName, + const StorageRef& rxStorage ); + + // com.sun.star.lang.XServiceInfo interface ------------------------------- + + virtual ::rtl::OUString SAL_CALL + getImplementationName() throw( ::com::sun::star::uno::RuntimeException ); + + virtual sal_Bool SAL_CALL + supportsService( const ::rtl::OUString& rService ) + throw( ::com::sun::star::uno::RuntimeException ); + + virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL + getSupportedServiceNames() throw( ::com::sun::star::uno::RuntimeException ); + + // com.sun.star.document.XExtendedFilterDetect interface ------------------ + + virtual ::rtl::OUString SAL_CALL + detect( ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& orDescriptor ) + throw( ::com::sun::star::uno::RuntimeException ); + +private: + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > + mxContext; +}; + +// ============================================================================ + +} // namespace xls +} // namespace oox + +#endif diff --git a/oox/inc/oox/xls/biffhelper.hxx b/oox/inc/oox/xls/biffhelper.hxx new file mode 100644 index 000000000000..9c0a57a83c04 --- /dev/null +++ b/oox/inc/oox/xls/biffhelper.hxx @@ -0,0 +1,668 @@ +/************************************************************************* + * + * 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_BIFFHELPER_HXX +#define OOX_XLS_BIFFHELPER_HXX + +#include "oox/helper/binarystreambase.hxx" + +namespace oox { class SequenceInputStream; } + +namespace oox { +namespace xls { + +class BiffInputStream; + +// BIFF12 record identifiers ================================================== + +const sal_Int32 BIFF12_ID_ARRAY = 0x01AA; +const sal_Int32 BIFF12_ID_AUTOFILTER = 0x00A1; +const sal_Int32 BIFF12_ID_AUTOSORTSCOPE = 0x01CB; +const sal_Int32 BIFF12_ID_BINARYINDEXBLOCK = 0x002A; +const sal_Int32 BIFF12_ID_BINARYINDEXROWS = 0x0028; +const sal_Int32 BIFF12_ID_BOOKVIEWS = 0x0087; +const sal_Int32 BIFF12_ID_BORDER = 0x002E; +const sal_Int32 BIFF12_ID_BORDERS = 0x0265; +const sal_Int32 BIFF12_ID_BRK = 0x018C; +const sal_Int32 BIFF12_ID_CALCPR = 0x009D; +const sal_Int32 BIFF12_ID_CELL_BLANK = 0x0001; +const sal_Int32 BIFF12_ID_CELL_BOOL = 0x0004; +const sal_Int32 BIFF12_ID_CELL_DOUBLE = 0x0005; +const sal_Int32 BIFF12_ID_CELL_ERROR = 0x0003; +const sal_Int32 BIFF12_ID_CELL_RK = 0x0002; +const sal_Int32 BIFF12_ID_CELL_RSTRING = 0x003E; +const sal_Int32 BIFF12_ID_CELL_SI = 0x0007; +const sal_Int32 BIFF12_ID_CELL_STRING = 0x0006; +const sal_Int32 BIFF12_ID_CELLSTYLE = 0x0030; +const sal_Int32 BIFF12_ID_CELLSTYLES = 0x026B; +const sal_Int32 BIFF12_ID_CELLSTYLEXFS = 0x0272; +const sal_Int32 BIFF12_ID_CELLXFS = 0x0269; +const sal_Int32 BIFF12_ID_CFCOLOR = 0x0234; +const sal_Int32 BIFF12_ID_CFRULE = 0x01CF; +const sal_Int32 BIFF12_ID_CHARTPAGESETUP = 0x028C; +const sal_Int32 BIFF12_ID_CHARTPROTECTION = 0x029D; +const sal_Int32 BIFF12_ID_CHARTSHEETPR = 0x028B; +const sal_Int32 BIFF12_ID_CHARTSHEETVIEW = 0x008D; +const sal_Int32 BIFF12_ID_CHARTSHEETVIEWS = 0x008B; +const sal_Int32 BIFF12_ID_COL = 0x003C; +const sal_Int32 BIFF12_ID_COLBREAKS = 0x018A; +const sal_Int32 BIFF12_ID_COLOR = 0x023C; +const sal_Int32 BIFF12_ID_COLORS = 0x01D9; +const sal_Int32 BIFF12_ID_COLORSCALE = 0x01D5; +const sal_Int32 BIFF12_ID_COLS = 0x0186; +const sal_Int32 BIFF12_ID_COMMENT = 0x027B; +const sal_Int32 BIFF12_ID_COMMENTAUTHOR = 0x0278; +const sal_Int32 BIFF12_ID_COMMENTAUTHORS = 0x0276; +const sal_Int32 BIFF12_ID_COMMENTLIST = 0x0279; +const sal_Int32 BIFF12_ID_COMMENTS = 0x0274; +const sal_Int32 BIFF12_ID_COMMENTTEXT = 0x027D; +const sal_Int32 BIFF12_ID_CONDFORMATTING = 0x01CD; +const sal_Int32 BIFF12_ID_CONNECTION = 0x00C9; +const sal_Int32 BIFF12_ID_CONNECTIONS = 0x01AD; +const sal_Int32 BIFF12_ID_CONTROL = 0x0284; +const sal_Int32 BIFF12_ID_CONTROLS = 0x0283; +const sal_Int32 BIFF12_ID_CUSTOMCHARTVIEW = 0x028F; +const sal_Int32 BIFF12_ID_CUSTOMCHARTVIEWS = 0x028D; +const sal_Int32 BIFF12_ID_CUSTOMFILTER = 0x00AE; +const sal_Int32 BIFF12_ID_CUSTOMFILTERS = 0x00AC; +const sal_Int32 BIFF12_ID_CUSTOMSHEETVIEW = 0x01A7; +const sal_Int32 BIFF12_ID_CUSTOMSHEETVIEWS = 0x01A6; +const sal_Int32 BIFF12_ID_CUSTOMWORKBOOKVIEW= 0x018D; +const sal_Int32 BIFF12_ID_DATABAR = 0x01D3; +const sal_Int32 BIFF12_ID_DATATABLE = 0x01AC; +const sal_Int32 BIFF12_ID_DATAVALIDATION = 0x0040; +const sal_Int32 BIFF12_ID_DATAVALIDATIONS = 0x023D; +const sal_Int32 BIFF12_ID_DDEITEMVALUES = 0x0242; +const sal_Int32 BIFF12_ID_DDEITEM_BOOL = 0x0248; +const sal_Int32 BIFF12_ID_DDEITEM_DOUBLE = 0x0244; +const sal_Int32 BIFF12_ID_DDEITEM_ERROR = 0x0245; +const sal_Int32 BIFF12_ID_DDEITEM_STRING = 0x0246; +const sal_Int32 BIFF12_ID_DEFINEDNAME = 0x0027; +const sal_Int32 BIFF12_ID_DIMENSION = 0x0094; +const sal_Int32 BIFF12_ID_DISCRETEFILTER = 0x00A7; +const sal_Int32 BIFF12_ID_DISCRETEFILTERS = 0x00A5; +const sal_Int32 BIFF12_ID_DRAWING = 0x0226; +const sal_Int32 BIFF12_ID_DXF = 0x01FB; +const sal_Int32 BIFF12_ID_DXFS = 0x01F9; +const sal_Int32 BIFF12_ID_EXTCELL_BLANK = 0x016F; +const sal_Int32 BIFF12_ID_EXTCELL_BOOL = 0x0171; +const sal_Int32 BIFF12_ID_EXTCELL_DOUBLE = 0x0170; +const sal_Int32 BIFF12_ID_EXTCELL_ERROR = 0x0172; +const sal_Int32 BIFF12_ID_EXTCELL_STRING = 0x0173; +const sal_Int32 BIFF12_ID_EXTERNALADDIN = 0x029B; +const sal_Int32 BIFF12_ID_EXTERNALBOOK = 0x0168; +const sal_Int32 BIFF12_ID_EXTERNALNAME = 0x0241; +const sal_Int32 BIFF12_ID_EXTERNALREF = 0x0163; +const sal_Int32 BIFF12_ID_EXTERNALREFS = 0x0161; +const sal_Int32 BIFF12_ID_EXTERNALSELF = 0x0165; +const sal_Int32 BIFF12_ID_EXTERNALSAME = 0x0166; +const sal_Int32 BIFF12_ID_EXTERNALSHEETS = 0x016A; +const sal_Int32 BIFF12_ID_EXTROW = 0x016E; +const sal_Int32 BIFF12_ID_EXTSHEETDATA = 0x016B; +const sal_Int32 BIFF12_ID_EXTERNALNAMEFLAGS = 0x024A; +const sal_Int32 BIFF12_ID_EXTSHEETNAMES = 0x0167; +const sal_Int32 BIFF12_ID_FILESHARING = 0x0224; +const sal_Int32 BIFF12_ID_FILEVERSION = 0x0080; +const sal_Int32 BIFF12_ID_FILL = 0x002D; +const sal_Int32 BIFF12_ID_FILLS = 0x025B; +const sal_Int32 BIFF12_ID_FILTERCOLUMN = 0x00A3; +const sal_Int32 BIFF12_ID_FONT = 0x002B; +const sal_Int32 BIFF12_ID_FONTS = 0x0263; +const sal_Int32 BIFF12_ID_FORMULA_STRING = 0x0008; +const sal_Int32 BIFF12_ID_FORMULA_DOUBLE = 0x0009; +const sal_Int32 BIFF12_ID_FORMULA_BOOL = 0x000A; +const sal_Int32 BIFF12_ID_FORMULA_ERROR = 0x000B; +const sal_Int32 BIFF12_ID_FUNCTIONGROUP = 0x0299; +const sal_Int32 BIFF12_ID_FUNCTIONGROUPS = 0x0298; +const sal_Int32 BIFF12_ID_HEADERFOOTER = 0x01DF; +const sal_Int32 BIFF12_ID_HYPERLINK = 0x01EE; +const sal_Int32 BIFF12_ID_ICONSET = 0x01D1; +const sal_Int32 BIFF12_ID_INDEXEDCOLORS = 0x0235; +const sal_Int32 BIFF12_ID_INPUTCELLS = 0x01F8; +const sal_Int32 BIFF12_ID_LEGACYDRAWING = 0x0227; +const sal_Int32 BIFF12_ID_MERGECELL = 0x00B0; +const sal_Int32 BIFF12_ID_MERGECELLS = 0x00B1; +const sal_Int32 BIFF12_ID_MRUCOLORS = 0x0239; +const sal_Int32 BIFF12_ID_MULTCELL_BLANK = 0x000C; +const sal_Int32 BIFF12_ID_MULTCELL_BOOL = 0x000F; +const sal_Int32 BIFF12_ID_MULTCELL_DOUBLE = 0x0010; +const sal_Int32 BIFF12_ID_MULTCELL_ERROR = 0x000E; +const sal_Int32 BIFF12_ID_MULTCELL_RK = 0x000D; +const sal_Int32 BIFF12_ID_MULTCELL_RSTRING = 0x003D; +const sal_Int32 BIFF12_ID_MULTCELL_SI = 0x0012; +const sal_Int32 BIFF12_ID_MULTCELL_STRING = 0x0011; +const sal_Int32 BIFF12_ID_NUMFMT = 0x002C; +const sal_Int32 BIFF12_ID_NUMFMTS = 0x0267; +const sal_Int32 BIFF12_ID_OLEOBJECT = 0x027F; +const sal_Int32 BIFF12_ID_OLEOBJECTS = 0x027E; +const sal_Int32 BIFF12_ID_OLESIZE = 0x0225; +const sal_Int32 BIFF12_ID_PAGEMARGINS = 0x01DC; +const sal_Int32 BIFF12_ID_PAGESETUP = 0x01DE; +const sal_Int32 BIFF12_ID_PANE = 0x0097; +const sal_Int32 BIFF12_ID_PCDEFINITION = 0x00B3; +const sal_Int32 BIFF12_ID_PCDFDISCRETEPR = 0x00E1; +const sal_Int32 BIFF12_ID_PCDFGROUPITEMS = 0x00DD; +const sal_Int32 BIFF12_ID_PCDFIELD = 0x00B7; +const sal_Int32 BIFF12_ID_PCDFIELDGROUP = 0x00DB; +const sal_Int32 BIFF12_ID_PCDFIELDS = 0x00B5; +const sal_Int32 BIFF12_ID_PCDFRANGEPR = 0x00DF; +const sal_Int32 BIFF12_ID_PCDFSHAREDITEMS = 0x00BD; +const sal_Int32 BIFF12_ID_PCDSHEETSOURCE = 0x00BB; +const sal_Int32 BIFF12_ID_PCDSOURCE = 0x00B9; +const sal_Int32 BIFF12_ID_PCITEM_ARRAY = 0x00BF; +const sal_Int32 BIFF12_ID_PCITEM_BOOL = 0x0016; +const sal_Int32 BIFF12_ID_PCITEM_DATE = 0x0019; +const sal_Int32 BIFF12_ID_PCITEM_DOUBLE = 0x0015; +const sal_Int32 BIFF12_ID_PCITEM_ERROR = 0x0017; +const sal_Int32 BIFF12_ID_PCITEM_INDEX = 0x001A; +const sal_Int32 BIFF12_ID_PCITEM_MISSING = 0x0014; +const sal_Int32 BIFF12_ID_PCITEM_STRING = 0x0018; +const sal_Int32 BIFF12_ID_PCITEMA_BOOL = 0x001D; +const sal_Int32 BIFF12_ID_PCITEMA_DATE = 0x0020; +const sal_Int32 BIFF12_ID_PCITEMA_DOUBLE = 0x001C; +const sal_Int32 BIFF12_ID_PCITEMA_ERROR = 0x001E; +const sal_Int32 BIFF12_ID_PCITEMA_MISSING = 0x001B; +const sal_Int32 BIFF12_ID_PCITEMA_STRING = 0x001F; +const sal_Int32 BIFF12_ID_PCRECORD = 0x0021; +const sal_Int32 BIFF12_ID_PCRECORDDT = 0x0022; +const sal_Int32 BIFF12_ID_PCRECORDS = 0x00C1; +const sal_Int32 BIFF12_ID_PHONETICPR = 0x0219; +const sal_Int32 BIFF12_ID_PICTURE = 0x0232; +const sal_Int32 BIFF12_ID_PIVOTAREA = 0x00F7; +const sal_Int32 BIFF12_ID_PIVOTCACHE = 0x0182; +const sal_Int32 BIFF12_ID_PIVOTCACHES = 0x0180; +const sal_Int32 BIFF12_ID_PRINTOPTIONS = 0x01DD; +const sal_Int32 BIFF12_ID_PTCOLFIELDS = 0x0137; +const sal_Int32 BIFF12_ID_PTDATAFIELD = 0x0125; +const sal_Int32 BIFF12_ID_PTDATAFIELDS = 0x0127; +const sal_Int32 BIFF12_ID_PTDEFINITION = 0x0118; +const sal_Int32 BIFF12_ID_PTFIELD = 0x011D; +const sal_Int32 BIFF12_ID_PTFIELDS = 0x011F; +const sal_Int32 BIFF12_ID_PTFILTER = 0x0259; +const sal_Int32 BIFF12_ID_PTFILTERS = 0x0257; +const sal_Int32 BIFF12_ID_PTFITEM = 0x011A; +const sal_Int32 BIFF12_ID_PTFITEMS = 0x011B; +const sal_Int32 BIFF12_ID_PTLOCATION = 0x013A; +const sal_Int32 BIFF12_ID_PTPAGEFIELD = 0x0121; +const sal_Int32 BIFF12_ID_PTPAGEFIELDS = 0x0123; +const sal_Int32 BIFF12_ID_PTREFERENCE = 0x00FB; +const sal_Int32 BIFF12_ID_PTREFERENCEITEM = 0x017E; +const sal_Int32 BIFF12_ID_PTREFERENCES = 0x00F9; +const sal_Int32 BIFF12_ID_PTROWFIELDS = 0x0135; +const sal_Int32 BIFF12_ID_QUERYTABLE = 0x01BF; +const sal_Int32 BIFF12_ID_QUERYTABLEREFRESH = 0x01C1; +const sal_Int32 BIFF12_ID_RGBCOLOR = 0x01DB; +const sal_Int32 BIFF12_ID_ROW = 0x0000; +const sal_Int32 BIFF12_ID_ROWBREAKS = 0x0188; +const sal_Int32 BIFF12_ID_SCENARIO = 0x01F6; +const sal_Int32 BIFF12_ID_SCENARIOS = 0x01F4; +const sal_Int32 BIFF12_ID_SELECTION = 0x0098; +const sal_Int32 BIFF12_ID_SHAREDFMLA = 0x01AB; +const sal_Int32 BIFF12_ID_SHEET = 0x009C; +const sal_Int32 BIFF12_ID_SHEETDATA = 0x0091; +const sal_Int32 BIFF12_ID_SHEETFORMATPR = 0x01E5; +const sal_Int32 BIFF12_ID_SHEETPR = 0x0093; +const sal_Int32 BIFF12_ID_SHEETPROTECTION = 0x0217; +const sal_Int32 BIFF12_ID_SHEETS = 0x008F; +const sal_Int32 BIFF12_ID_SHEETVIEW = 0x0089; +const sal_Int32 BIFF12_ID_SHEETVIEWS = 0x0085; +const sal_Int32 BIFF12_ID_SI = 0x0013; +const sal_Int32 BIFF12_ID_SST = 0x009F; +const sal_Int32 BIFF12_ID_STYLESHEET = 0x0116; +const sal_Int32 BIFF12_ID_TABLE = 0x0157; +const sal_Int32 BIFF12_ID_TABLEPART = 0x0295; +const sal_Int32 BIFF12_ID_TABLEPARTS = 0x0294; +const sal_Int32 BIFF12_ID_TABLESTYLEINFO = 0x0201; +const sal_Int32 BIFF12_ID_TABLESTYLES = 0x01FC; +const sal_Int32 BIFF12_ID_TOP10FILTER = 0x00AA; +const sal_Int32 BIFF12_ID_VOLTYPE = 0x0204; +const sal_Int32 BIFF12_ID_VOLTYPEMAIN = 0x0206; +const sal_Int32 BIFF12_ID_VOLTYPES = 0x0202; +const sal_Int32 BIFF12_ID_VOLTYPESTP = 0x020A; +const sal_Int32 BIFF12_ID_VOLTYPETR = 0x020B; +const sal_Int32 BIFF12_ID_WEBPR = 0x0105; +const sal_Int32 BIFF12_ID_WEBPRTABLES = 0x0107; +const sal_Int32 BIFF12_ID_WORKBOOK = 0x0083; +const sal_Int32 BIFF12_ID_WORKBOOKPR = 0x0099; +const sal_Int32 BIFF12_ID_WORKBOOKVIEW = 0x009E; +const sal_Int32 BIFF12_ID_WORKSHEET = 0x0081; +const sal_Int32 BIFF12_ID_XF = 0x002F; + +// BIFF2-BIFF8 record identifiers ============================================= + +/** An enumeration for all binary Excel file format types (BIFF types). */ +enum BiffType +{ + BIFF2 = 0, /// MS Excel 2.1. + BIFF3, /// MS Excel 3.0. + BIFF4, /// MS Excel 4.0. + BIFF5, /// MS Excel 5.0, MS Excel 7.0 (95). + BIFF8, /// MS Excel 8.0 (97), 9.0 (2000), 10.0 (XP), 11.0 (2003). + BIFF_UNKNOWN /// Unknown BIFF version. +}; + +const sal_uInt16 BIFF2_MAXRECSIZE = 2080; +const sal_uInt16 BIFF8_MAXRECSIZE = 8224; + +// record identifiers --------------------------------------------------------- + +const sal_uInt16 BIFF2_ID_ARRAY = 0x0021; +const sal_uInt16 BIFF3_ID_ARRAY = 0x0221; +const sal_uInt16 BIFF_ID_AUTOFILTER = 0x009D; +const sal_uInt16 BIFF2_ID_BLANK = 0x0001; +const sal_uInt16 BIFF3_ID_BLANK = 0x0201; +const sal_uInt16 BIFF2_ID_BOF = 0x0009; +const sal_uInt16 BIFF3_ID_BOF = 0x0209; +const sal_uInt16 BIFF4_ID_BOF = 0x0409; +const sal_uInt16 BIFF5_ID_BOF = 0x0809; +const sal_uInt16 BIFF_ID_BOOKBOOL = 0x00DA; +const sal_uInt16 BIFF_ID_BOOKEXT = 0x0863; +const sal_uInt16 BIFF2_ID_BOOLERR = 0x0005; +const sal_uInt16 BIFF3_ID_BOOLERR = 0x0205; +const sal_uInt16 BIFF_ID_BOTTOMMARGIN = 0x0029; +const sal_uInt16 BIFF_ID_CALCCOUNT = 0x000C; +const sal_uInt16 BIFF_ID_CALCMODE = 0x000D; +const sal_uInt16 BIFF_ID_CFHEADER = 0x01B0; +const sal_uInt16 BIFF_ID_CFRULE = 0x01B1; +const sal_uInt16 BIFF_ID_CFRULE12 = 0x087A; +const sal_uInt16 BIFF_ID_CFRULEEXT = 0x087B; +const sal_uInt16 BIFF_ID_CH3DDATAFORMAT = 0x105F; +const sal_uInt16 BIFF_ID_CHAREA = 0x101A; +const sal_uInt16 BIFF_ID_CHAREAFORMAT = 0x100A; +const sal_uInt16 BIFF_ID_CHATTACHEDLABEL = 0x100C; +const sal_uInt16 BIFF_ID_CHAXESSET = 0x1041; +const sal_uInt16 BIFF_ID_CHAXIS = 0x101D; +const sal_uInt16 BIFF_ID_CHAXISLINE = 0x1021; +const sal_uInt16 BIFF_ID_CHBAR = 0x1017; +const sal_uInt16 BIFF_ID_CHBEGIN = 0x1033; +const sal_uInt16 BIFF_ID_CHCHART = 0x1002; +const sal_uInt16 BIFF_ID_CHCHART3D = 0x103A; +const sal_uInt16 BIFF_ID_CHCHARTLINE = 0x101C; +const sal_uInt16 BIFF_ID_CHDATAFORMAT = 0x1006; +const sal_uInt16 BIFF_ID_CHDEFAULTTEXT = 0x1024; +const sal_uInt16 BIFF_ID_CHDROPBAR = 0x103D; +const sal_uInt16 BIFF_ID_CHECKCOMPAT = 0x088C; +const sal_uInt16 BIFF_ID_CHEND = 0x1034; +const sal_uInt16 BIFF_ID_CHESCHERFORMAT = 0x1066; +const sal_uInt16 BIFF_ID_CHFONT = 0x1026; +const sal_uInt16 BIFF_ID_CHFORMAT = 0x104E; +const sal_uInt16 BIFF_ID_CHFORMATRUNS = 0x1050; +const sal_uInt16 BIFF_ID_CHFRAME = 0x1032; +const sal_uInt16 BIFF_ID_CHFRAMEPOS = 0x104F; +const sal_uInt16 BIFF_ID_CHFRBLOCKBEGIN = 0x0852; +const sal_uInt16 BIFF_ID_CHFRBLOCKEND = 0x0853; +const sal_uInt16 BIFF_ID_CHFRCATEGORYPROPS = 0x0856; +const sal_uInt16 BIFF_ID_CHFREXTPROPS = 0x089E; +const sal_uInt16 BIFF_ID_CHFREXTPROPSCONT = 0x089F; +const sal_uInt16 BIFF_ID_CHFRINFO = 0x0850; +const sal_uInt16 BIFF_ID_CHFRLABELPROPS = 0x086B; +const sal_uInt16 BIFF_ID_CHFRLAYOUT = 0x089D; +const sal_uInt16 BIFF_ID_CHFRPLOTAREALAYOUT = 0x08A7; +const sal_uInt16 BIFF_ID_CHFRSHAPEPROPS = 0x08A4; +const sal_uInt16 BIFF_ID_CHFRTEXTPROPS = 0x08A5; +const sal_uInt16 BIFF_ID_CHFRUNITPROPS = 0x0857; +const sal_uInt16 BIFF_ID_CHFRWRAPPER = 0x0851; +const sal_uInt16 BIFF_ID_CHLABELRANGE = 0x1020; +const sal_uInt16 BIFF_ID_CHLABELRANGE2 = 0x1062; +const sal_uInt16 BIFF_ID_CHLEGEND = 0x1015; +const sal_uInt16 BIFF_ID_CHLINE = 0x1018; +const sal_uInt16 BIFF_ID_CHLINEFORMAT = 0x1007; +const sal_uInt16 BIFF_ID_CHMARKERFORMAT = 0x1009; +const sal_uInt16 BIFF_ID_CHOBJECTLINK = 0x1027; +const sal_uInt16 BIFF_ID_CHPICFORMAT = 0x103C; +const sal_uInt16 BIFF_ID_CHPIE = 0x1019; +const sal_uInt16 BIFF_ID_CHPIEEXT = 0x1061; +const sal_uInt16 BIFF_ID_CHPIEFORMAT = 0x100B; +const sal_uInt16 BIFF_ID_CHPIVOTFLAGS = 0x0859; +const sal_uInt16 BIFF5_ID_CHPIVOTREF = 0x1048; +const sal_uInt16 BIFF8_ID_CHPIVOTREF = 0x0858; +const sal_uInt16 BIFF_ID_CHPLOTFRAME = 0x1035; +const sal_uInt16 BIFF_ID_CHPLOTGROWTH = 0x1064; +const sal_uInt16 BIFF_ID_CHPROPERTIES = 0x1044; +const sal_uInt16 BIFF_ID_CHRADARLINE = 0x103E; +const sal_uInt16 BIFF_ID_CHRADARAREA = 0x1040; +const sal_uInt16 BIFF_ID_CHSCATTER = 0x101B; +const sal_uInt16 BIFF_ID_CHSERERRORBAR = 0x105B; +const sal_uInt16 BIFF_ID_CHSERGROUP = 0x1045; +const sal_uInt16 BIFF_ID_CHSERIES = 0x1003; +const sal_uInt16 BIFF_ID_CHSERIESFORMAT = 0x105D; +const sal_uInt16 BIFF_ID_CHSERPARENT = 0x104A; +const sal_uInt16 BIFF_ID_CHSERTRENDLINE = 0x104B; +const sal_uInt16 BIFF_ID_CHSOURCELINK = 0x1051; +const sal_uInt16 BIFF_ID_CHSTRING = 0x100D; +const sal_uInt16 BIFF_ID_CHSURFACE = 0x103F; +const sal_uInt16 BIFF_ID_CHTEXT = 0x1025; +const sal_uInt16 BIFF_ID_CHTICK = 0x101E; +const sal_uInt16 BIFF_ID_CHTYPEGROUP = 0x1014; +const sal_uInt16 BIFF_ID_CHVALUERANGE = 0x101F; +const sal_uInt16 BIFF_ID_CODENAME = 0x01BA; +const sal_uInt16 BIFF_ID_CODEPAGE = 0x0042; +const sal_uInt16 BIFF_ID_COLINFO = 0x007D; +const sal_uInt16 BIFF_ID_COLUMNDEFAULT = 0x0020; +const sal_uInt16 BIFF_ID_COLWIDTH = 0x0024; +const sal_uInt16 BIFF_ID_COMPRESSPICS = 0x089B; +const sal_uInt16 BIFF_ID_CONNECTION = 0x0876; +const sal_uInt16 BIFF_ID_CONT = 0x003C; +const sal_uInt16 BIFF_ID_COORDLIST = 0x00A9; +const sal_uInt16 BIFF_ID_COUNTRY = 0x008C; +const sal_uInt16 BIFF_ID_CRN = 0x005A; +const sal_uInt16 BIFF2_ID_DATATABLE = 0x0036; +const sal_uInt16 BIFF3_ID_DATATABLE = 0x0236; +const sal_uInt16 BIFF2_ID_DATATABLE2 = 0x0037; +const sal_uInt16 BIFF_ID_DATAVALIDATION = 0x01BE; +const sal_uInt16 BIFF_ID_DATAVALIDATIONS = 0x01B2; +const sal_uInt16 BIFF_ID_DATEMODE = 0x0022; +const sal_uInt16 BIFF_ID_DBCELL = 0x00D7; +const sal_uInt16 BIFF_ID_DBQUERY = 0x00DC; +const sal_uInt16 BIFF_ID_DCONBINAME = 0x01B5; +const sal_uInt16 BIFF_ID_DCONNAME = 0x0052; +const sal_uInt16 BIFF_ID_DCONREF = 0x0051; +const sal_uInt16 BIFF_ID_DEFCOLWIDTH = 0x0055; +const sal_uInt16 BIFF2_ID_DEFINEDNAME = 0x0018; +const sal_uInt16 BIFF3_ID_DEFINEDNAME = 0x0218; +const sal_uInt16 BIFF5_ID_DEFINEDNAME = 0x0018; +const sal_uInt16 BIFF2_ID_DEFROWHEIGHT = 0x0025; +const sal_uInt16 BIFF3_ID_DEFROWHEIGHT = 0x0225; +const sal_uInt16 BIFF_ID_DELTA = 0x0010; +const sal_uInt16 BIFF2_ID_DIMENSION = 0x0000; +const sal_uInt16 BIFF3_ID_DIMENSION = 0x0200; +const sal_uInt16 BIFF_ID_DXF = 0x088D; +const sal_uInt16 BIFF_ID_EOF = 0x000A; +const sal_uInt16 BIFF_ID_EXTERNALBOOK = 0x01AE; +const sal_uInt16 BIFF2_ID_EXTERNALNAME = 0x0023; +const sal_uInt16 BIFF3_ID_EXTERNALNAME = 0x0223; +const sal_uInt16 BIFF5_ID_EXTERNALNAME = 0x0023; +const sal_uInt16 BIFF_ID_EXTERNSHEET = 0x0017; +const sal_uInt16 BIFF_ID_EXTSST = 0x00FF; +const sal_uInt16 BIFF_ID_FILEPASS = 0x002F; +const sal_uInt16 BIFF_ID_FILESHARING = 0x005B; +const sal_uInt16 BIFF_ID_FILTERCOLUMN = 0x009E; +const sal_uInt16 BIFF_ID_FILTERMODE = 0x009B; +const sal_uInt16 BIFF2_ID_FONT = 0x0031; +const sal_uInt16 BIFF3_ID_FONT = 0x0231; +const sal_uInt16 BIFF5_ID_FONT = 0x0031; +const sal_uInt16 BIFF_ID_FONTCOLOR = 0x0045; +const sal_uInt16 BIFF_ID_FOOTER = 0x0015; +const sal_uInt16 BIFF_ID_FORCEFULLCALC = 0x08A3; +const sal_uInt16 BIFF2_ID_FORMAT = 0x001E; +const sal_uInt16 BIFF4_ID_FORMAT = 0x041E; +const sal_uInt16 BIFF2_ID_FORMULA = 0x0006; +const sal_uInt16 BIFF3_ID_FORMULA = 0x0206; +const sal_uInt16 BIFF4_ID_FORMULA = 0x0406; +const sal_uInt16 BIFF5_ID_FORMULA = 0x0006; +const sal_uInt16 BIFF_ID_GUTS = 0x0080; +const sal_uInt16 BIFF_ID_HCENTER = 0x0083; +const sal_uInt16 BIFF_ID_HEADER = 0x0014; +const sal_uInt16 BIFF_ID_HEADERFOOTER = 0x089C; +const sal_uInt16 BIFF_ID_HIDEOBJ = 0x008D; +const sal_uInt16 BIFF_ID_HORPAGEBREAKS = 0x001B; +const sal_uInt16 BIFF_ID_HYPERLINK = 0x01B8; +const sal_uInt16 BIFF3_ID_IMGDATA = 0x007F; +const sal_uInt16 BIFF8_ID_IMGDATA = 0x00E9; +const sal_uInt16 BIFF2_ID_INDEX = 0x000B; +const sal_uInt16 BIFF3_ID_INDEX = 0x020B; +const sal_uInt16 BIFF2_ID_INTEGER = 0x0002; +const sal_uInt16 BIFF_ID_INTERFACEHDR = 0x00E1; +const sal_uInt16 BIFF_ID_ITERATION = 0x0011; +const sal_uInt16 BIFF_ID_IXFE = 0x0044; +const sal_uInt16 BIFF2_ID_LABEL = 0x0004; +const sal_uInt16 BIFF3_ID_LABEL = 0x0204; +const sal_uInt16 BIFF_ID_LABELRANGES = 0x015F; +const sal_uInt16 BIFF_ID_LABELSST = 0x00FD; +const sal_uInt16 BIFF_ID_LEFTMARGIN = 0x0026; +const sal_uInt16 BIFF_ID_MERGEDCELLS = 0x00E5; +const sal_uInt16 BIFF_ID_MSODRAWING = 0x00EC; +const sal_uInt16 BIFF_ID_MSODRAWINGGROUP = 0x00EB; +const sal_uInt16 BIFF_ID_MSODRAWINGSEL = 0x00ED; +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 BIFF2_ID_NUMBER = 0x0003; +const sal_uInt16 BIFF3_ID_NUMBER = 0x0203; +const sal_uInt16 BIFF_ID_OBJ = 0x005D; +const sal_uInt16 BIFF_ID_OBJECTPROTECT = 0x0063; +const sal_uInt16 BIFF_ID_OLESIZE = 0x00DE; +const sal_uInt16 BIFF_ID_PAGELAYOUTVIEW = 0x088B; +const sal_uInt16 BIFF_ID_PAGESETUP = 0x00A1; +const sal_uInt16 BIFF_ID_PALETTE = 0x0092; +const sal_uInt16 BIFF_ID_PANE = 0x0041; +const sal_uInt16 BIFF_ID_PARAMQUERY = 0x00DC; +const sal_uInt16 BIFF_ID_PASSWORD = 0x0013; +const sal_uInt16 BIFF_ID_PCDEFINITION = 0x00C6; +const sal_uInt16 BIFF_ID_PCDEFINITION2 = 0x0122; +const sal_uInt16 BIFF_ID_PCDFDISCRETEPR = 0x00D9; +const sal_uInt16 BIFF_ID_PCDFIELD = 0x00C7; +const sal_uInt16 BIFF_ID_PCDFIELDINDEX = 0x0103; +const sal_uInt16 BIFF_ID_PCDFORMULAFIELD = 0x00F9; +const sal_uInt16 BIFF_ID_PCDFRANGEPR = 0x00D8; +const sal_uInt16 BIFF_ID_PCDFSQLTYPE = 0x01BB; +const sal_uInt16 BIFF_ID_PCDSOURCE = 0x00E3; +const sal_uInt16 BIFF_ID_PCITEM_BOOL = 0x00CA; +const sal_uInt16 BIFF_ID_PCITEM_DATE = 0x00CE; +const sal_uInt16 BIFF_ID_PCITEM_DOUBLE = 0x00C9; +const sal_uInt16 BIFF_ID_PCITEM_ERROR = 0x00CB; +const sal_uInt16 BIFF_ID_PCITEM_INDEXLIST = 0x00C8; +const sal_uInt16 BIFF_ID_PCITEM_INTEGER = 0x00CC; +const sal_uInt16 BIFF_ID_PCITEM_MISSING = 0x00CF; +const sal_uInt16 BIFF_ID_PCITEM_STRING = 0x00CD; +const sal_uInt16 BIFF_ID_PHONETICPR = 0x00EF; +const sal_uInt16 BIFF_ID_PICTURE = 0x00E9; +const sal_uInt16 BIFF_ID_PIVOTCACHE = 0x00D5; +const sal_uInt16 BIFF_ID_PRECISION = 0x000E; +const sal_uInt16 BIFF_ID_PRINTGRIDLINES = 0x002B; +const sal_uInt16 BIFF_ID_PRINTHEADERS = 0x002A; +const sal_uInt16 BIFF_ID_PROJEXTSHEET = 0x00A3; +const sal_uInt16 BIFF_ID_PROTECT = 0x0012; +const sal_uInt16 BIFF_ID_PTDATAFIELD = 0x00C5; +const sal_uInt16 BIFF_ID_PTDEFINITION = 0x00B0; +const sal_uInt16 BIFF_ID_PTDEFINITION2 = 0x00F1; +const sal_uInt16 BIFF_ID_PTFIELD = 0x00B1; +const sal_uInt16 BIFF_ID_PTFIELD2 = 0x0100; +const sal_uInt16 BIFF_ID_PTFITEM = 0x00B2; +const sal_uInt16 BIFF_ID_PTPAGEFIELDS = 0x00B6; +const sal_uInt16 BIFF_ID_PTROWCOLFIELDS = 0x00B4; +const sal_uInt16 BIFF_ID_PTROWCOLITEMS = 0x00B5; +const sal_uInt16 BIFF_ID_QUERYTABLE = 0x01AD; +const sal_uInt16 BIFF_ID_QUERYTABLEREFRESH = 0x0802; +const sal_uInt16 BIFF_ID_QUERYTABLESETTINGS = 0x0803; +const sal_uInt16 BIFF_ID_QUERYTABLESTRING = 0x0804; +const sal_uInt16 BIFF_ID_RECALCID = 0x01C1; +const sal_uInt16 BIFF_ID_REFMODE = 0x000F; +const sal_uInt16 BIFF_ID_RIGHTMARGIN = 0x0027; +const sal_uInt16 BIFF_ID_RK = 0x027E; +const sal_uInt16 BIFF2_ID_ROW = 0x0008; +const sal_uInt16 BIFF3_ID_ROW = 0x0208; +const sal_uInt16 BIFF_ID_RSTRING = 0x00D6; +const sal_uInt16 BIFF_ID_SAVERECALC = 0x005F; +const sal_uInt16 BIFF_ID_SCENARIO = 0x00AF; +const sal_uInt16 BIFF_ID_SCENARIOS = 0x00AE; +const sal_uInt16 BIFF_ID_SCL = 0x00A0; +const sal_uInt16 BIFF_ID_SCENPROTECT = 0x00DD; +const sal_uInt16 BIFF_ID_SCREENTIP = 0x0800; +const sal_uInt16 BIFF_ID_SELECTION = 0x001D; +const sal_uInt16 BIFF_ID_SHAREDFEATHEAD = 0x0867; +const sal_uInt16 BIFF_ID_SHAREDFMLA = 0x04BC; +const sal_uInt16 BIFF_ID_SHEET = 0x0085; +const sal_uInt16 BIFF_ID_SHEETEXT = 0x0862; +const sal_uInt16 BIFF_ID_SHEETHEADER = 0x008F; +const sal_uInt16 BIFF_ID_SHEETPR = 0x0081; +const sal_uInt16 BIFF_ID_SST = 0x00FC; +const sal_uInt16 BIFF_ID_STANDARDWIDTH = 0x0099; +const sal_uInt16 BIFF2_ID_STRING = 0x0007; +const sal_uInt16 BIFF3_ID_STRING = 0x0207; +const sal_uInt16 BIFF_ID_STYLE = 0x0293; +const sal_uInt16 BIFF_ID_STYLEEXT = 0x0892; +const sal_uInt16 BIFF_ID_TABLESTYLES = 0x088E; +const sal_uInt16 BIFF_ID_THEME = 0x0896; +const sal_uInt16 BIFF_ID_TOPMARGIN = 0x0028; +const sal_uInt16 BIFF_ID_TXO = 0x01B6; +const sal_uInt16 BIFF_ID_UNCALCED = 0x005E; +const sal_uInt16 BIFF_ID_USESELFS = 0x0160; +const sal_uInt16 BIFF_ID_VBAPROJECT = 0x00D3; +const sal_uInt16 BIFF_ID_VBAPROJECTEMPTY = 0x01BD; +const sal_uInt16 BIFF_ID_VCENTER = 0x0084; +const sal_uInt16 BIFF_ID_VERPAGEBREAKS = 0x001A; +const sal_uInt16 BIFF_ID_WINDOW1 = 0x003D; +const sal_uInt16 BIFF2_ID_WINDOW2 = 0x003E; +const sal_uInt16 BIFF3_ID_WINDOW2 = 0x023E; +const sal_uInt16 BIFF_ID_WRITEACCESS = 0x005C; +const sal_uInt16 BIFF_ID_XCT = 0x0059; +const sal_uInt16 BIFF2_ID_XF = 0x0043; +const sal_uInt16 BIFF3_ID_XF = 0x0243; +const sal_uInt16 BIFF4_ID_XF = 0x0443; +const sal_uInt16 BIFF5_ID_XF = 0x00E0; +const sal_uInt16 BIFF_ID_XFCRC = 0x087C; +const sal_uInt16 BIFF_ID_XFEXT = 0x087D; + +const sal_uInt16 BIFF_ID_UNKNOWN = SAL_MAX_UINT16; + +// OBJ subrecord identifiers -------------------------------------------------- + +const sal_uInt16 BIFF_ID_OBJEND = 0x0000; /// End of OBJ. +const sal_uInt16 BIFF_ID_OBJMACRO = 0x0004; /// Macro link. +const sal_uInt16 BIFF_ID_OBJBUTTON = 0x0005; /// Button data. +const sal_uInt16 BIFF_ID_OBJGMO = 0x0006; /// Group marker. +const sal_uInt16 BIFF_ID_OBJCF = 0x0007; /// Clipboard format. +const sal_uInt16 BIFF_ID_OBJFLAGS = 0x0008; /// Option flags. +const sal_uInt16 BIFF_ID_OBJPICTFMLA = 0x0009; /// OLE link formula. +const sal_uInt16 BIFF_ID_OBJCBLS = 0x000A; /// Check box/radio button data. +const sal_uInt16 BIFF_ID_OBJRBO = 0x000B; /// Radio button group data. +const sal_uInt16 BIFF_ID_OBJSBS = 0x000C; /// Scroll bar data. +const sal_uInt16 BIFF_ID_OBJNTS = 0x000C; /// Note data. +const sal_uInt16 BIFF_ID_OBJSBSFMLA = 0x000E; /// Scroll bar/list box/combo box cell link. +const sal_uInt16 BIFF_ID_OBJGBODATA = 0x000F; /// Group box data. +const sal_uInt16 BIFF_ID_OBJEDODATA = 0x0010; /// Edit box data. +const sal_uInt16 BIFF_ID_OBJRBODATA = 0x0011; /// Radio button group data. +const sal_uInt16 BIFF_ID_OBJCBLSDATA = 0x0012; /// Check box/radio button data. +const sal_uInt16 BIFF_ID_OBJLBSDATA = 0x0013; /// List box/combo box data. +const sal_uInt16 BIFF_ID_OBJCBLSFMLA = 0x0014; /// Check box/radio button cell link. +const sal_uInt16 BIFF_ID_OBJCMO = 0x0015; /// Common object settings. + +// record constants ----------------------------------------------------------- + +const sal_uInt16 BIFF_BOF_BIFF2 = 0x0200; +const sal_uInt16 BIFF_BOF_BIFF3 = 0x0300; +const sal_uInt16 BIFF_BOF_BIFF4 = 0x0400; +const sal_uInt16 BIFF_BOF_BIFF5 = 0x0500; +const sal_uInt16 BIFF_BOF_BIFF8 = 0x0600; + +const sal_uInt8 BIFF_ERR_NULL = 0x00; +const sal_uInt8 BIFF_ERR_DIV0 = 0x07; +const sal_uInt8 BIFF_ERR_VALUE = 0x0F; +const sal_uInt8 BIFF_ERR_REF = 0x17; +const sal_uInt8 BIFF_ERR_NAME = 0x1D; +const sal_uInt8 BIFF_ERR_NUM = 0x24; +const sal_uInt8 BIFF_ERR_NA = 0x2A; + +const sal_uInt8 BIFF_DATATYPE_EMPTY = 0; +const sal_uInt8 BIFF_DATATYPE_DOUBLE = 1; +const sal_uInt8 BIFF_DATATYPE_STRING = 2; +const sal_uInt8 BIFF_DATATYPE_BOOL = 4; +const sal_uInt8 BIFF_DATATYPE_ERROR = 16; + +const sal_uInt8 BIFF_BOOLERR_BOOL = 0; +const sal_uInt8 BIFF_BOOLERR_ERROR = 1; + +// BIFF8 unicode strings ------------------------------------------------------ + +const sal_uInt8 BIFF_STRF_16BIT = 0x01; +const sal_uInt8 BIFF_STRF_PHONETIC = 0x04; +const sal_uInt8 BIFF_STRF_RICH = 0x08; +const sal_uInt8 BIFF_STRF_UNKNOWN = 0xF2; + +// ============================================================================ + +/** Static helper functions for BIFF filters. */ +class BiffHelper +{ +public: + // conversion ------------------------------------------------------------- + + /** Converts the passed packed number to a double. */ + static double calcDoubleFromRk( sal_Int32 nRkValue ); + /** Converts the passed double to a packed number, returns true on success. */ + static bool calcRkFromDouble( sal_Int32& ornRkValue, double fValue ); + + /** Converts the passed BIFF error to a double containing the respective Calc error code. */ + static double calcDoubleFromError( sal_uInt8 nErrorCode ); + + /** Returns a text encoding from an Windows code page. + @return The corresponding text encoding or RTL_TEXTENCODING_DONTKNOW. */ + static rtl_TextEncoding calcTextEncodingFromCodePage( sal_uInt16 nCodePage ); + /** Returns a Windows code page from a text encoding. */ + static sal_uInt16 calcCodePageFromTextEncoding( rtl_TextEncoding eTextEnc ); + + // BIFF12 import ---------------------------------------------------------- + + /** Reads a BIFF12 string with leading 16-bit or 32-bit length field. */ + static ::rtl::OUString readString( SequenceInputStream& rStrm, bool b32BitLen = true ); + + // BIFF2-BIFF8 import ----------------------------------------------------- + + /** Returns true, if the current record of the stream is a BOF record. */ + static bool isBofRecord( BiffInputStream& rStrm ); + + /** Skips a block of records up to the specified end record. + + Skips all records until next end record. When this function returns, + the stream points to the end record, and the next call of the function + startNextRecord() at the stream will start the record following the end + record. + + The identifier of the record that is active while this function is + called is used as start record identifier. This identifier is used to + correctly skip embedded record blocks with the same start and end + record identifier. + + @return True = stream points to the end record. + */ + static bool skipRecordBlock( BiffInputStream& rStrm, sal_uInt16 nEndRecId ); + + /** Imports a picture from an IMGDATA record. */ + static void importImgData( StreamDataSequence& orDataSeq, BiffInputStream& rStrm, BiffType eBiff ); + +private: + BiffHelper(); // not implemented + ~BiffHelper(); // not implemented +}; + +// ---------------------------------------------------------------------------- + +/** BIFF12 stream operator for an ::rtl::OUString, reads 32-bit string length and Unicode array. */ +inline SequenceInputStream& operator>>( SequenceInputStream& rStrm, ::rtl::OUString& orString ) +{ + orString = BiffHelper::readString( rStrm ); + return rStrm; +} + +// ============================================================================ + +} // namespace xls +} // namespace oox + +#endif diff --git a/oox/inc/oox/xls/biffinputstream.hxx b/oox/inc/oox/xls/biffinputstream.hxx new file mode 100644 index 000000000000..003ab28be34f --- /dev/null +++ b/oox/inc/oox/xls/biffinputstream.hxx @@ -0,0 +1,446 @@ +/************************************************************************* + * + * 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_BIFFINPUTSTREAM_HXX +#define OOX_XLS_BIFFINPUTSTREAM_HXX + +#include <vector> +#include "oox/helper/binaryinputstream.hxx" +#include "oox/xls/biffhelper.hxx" +#include "oox/xls/biffcodec.hxx" + +namespace rtl { class OUStringBuffer; } + +namespace oox { +namespace xls { + +// ============================================================================ + +namespace prv { + +/** Buffers the contents of a raw record and encapsulates stream decoding. */ +class BiffInputRecordBuffer +{ +public: + explicit BiffInputRecordBuffer( BinaryInputStream& rInStrm ); + + /** Returns the wrapped binary base stream. */ + inline const BinaryInputStream& getBaseStream() const { return mrInStrm; } + + /** Sets a decoder object and decrypts buffered record data. */ + void setDecoder( const BiffDecoderRef& rxDecoder ); + /** Returns the current decoder object. */ + inline BiffDecoderRef getDecoder() const { return mxDecoder; } + /** Enables/disables usage of current decoder. */ + void enableDecoder( bool bEnable ); + + /** Restarts the stream at the passed position. Buffer is invalid until the + next call of startRecord() or startNextRecord(). */ + void restartAt( sal_Int64 nPos ); + + /** Reads the record header at the passed position. */ + bool startRecord( sal_Int64 nHeaderPos ); + /** Reads the next record header from the stream. */ + bool startNextRecord(); + /** Returns the start position of the record header in the core stream. */ + sal_uInt16 getNextRecId(); + + /** Returns the start position of the record header in the core stream. */ + inline sal_Int64 getRecHeaderPos() const { return mnHeaderPos; } + /** Returns the current record identifier. */ + inline sal_uInt16 getRecId() const { return mnRecId; } + /** Returns the current record size. */ + inline sal_uInt16 getRecSize() const { return mnRecSize; } + /** Returns the current read position in the current record body. */ + inline sal_uInt16 getRecPos() const { return mnRecPos; } + /** Returns the number of remaining bytes in the current record body. */ + inline sal_uInt16 getRecLeft() const { return mnRecSize - mnRecPos; } + + /** Reads nBytes bytes to the existing buffer opData. Must NOT overread the source buffer. */ + void read( void* opData, sal_uInt16 nBytes ); + /** Ignores nBytes bytes. Must NOT overread the buffer. */ + void skip( sal_uInt16 nBytes ); + +private: + /** Updates data buffer from stream, if needed. */ + void updateBuffer(); + /** Updates decoded data from original data. */ + void updateDecoded(); + +private: + typedef ::std::vector< sal_uInt8 > DataBuffer; + + BinaryInputStream& mrInStrm; /// Core input stream. + DataBuffer maOriginalData; /// Original data read from stream. + DataBuffer maDecodedData; /// Decoded data. + DataBuffer* mpCurrentData; /// Points to data buffer currently in use. + BiffDecoderRef mxDecoder; /// Decoder object. + sal_Int64 mnHeaderPos; /// Stream start position of current record header. + sal_Int64 mnBodyPos; /// Stream start position of current record body. + sal_Int64 mnBufferBodyPos; /// Stream start position of buffered data. + sal_Int64 mnNextHeaderPos; /// Stream start position of next record header. + sal_uInt16 mnRecId; /// Current record identifier. + sal_uInt16 mnRecSize; /// Current record size. + sal_uInt16 mnRecPos; /// Current position in record body. + bool mbValidHeader; /// True = valid record header. +}; + +} // namespace prv + +// ============================================================================ + +/** This class is used to read BIFF record streams. + + An instance is constructed with a BinaryInputStream object. The passed + stream is reset to its start while constructing this stream. + + To start reading a record call startNextRecord(). Now it is possible to + read all contents of the record using operator>>() or any of the read***() + functions. If some data exceeds the record size limit, the stream looks for + a following CONTINUE record and jumps automatically to it. It is NOT + allowed that an atomic data type is split into two records (e.g. 4 bytes of + a double in one record and the other 4 bytes in a following CONTINUE). + + Trying to read over the record limits results in a stream error. The + isValid() function indicates that by returning false. From now on the data + returned by the read functions is undefined. The error state will be reset, + if the record is reset (with the function resetRecord()), or if the next + record is started. + + To switch off the automatic lookup of CONTINUE records, use resetRecord() + with false parameter. This is useful e.g. on import of drawing layer data, + where sometimes solely CONTINUE records will occur. The automatic lookup + keeps switched off until the method resetRecord() is called with parameter + true. All other settings done on the stream (e.g. alternative CONTINUE + record identifier, enabled decryption, NUL substitution character) will be + reset to default values, if a new record is started. + + The import stream supports decrypting the stream data. The contents of a + record (not the record header) will be encrypted by Excel if the file has + been stored with password protection. The functions setDecoder() and + enableDecoder() control the usage of the decryption algorithms. + setDecoder() sets a new decryption algorithm and initially enables it. + enableDecoder( false ) may be used to stop the usage of the decryption + temporarily (sometimes record contents are never encrypted, e.g. all BOF + records or the stream position in SHEET records). Decryption will be + reenabled automatically, if a new record is started with the function + startNextRecord(). +*/ +class BiffInputStream : public BinaryInputStream +{ +public: + /** Constructs the BIFF record stream using the passed binary stream. + + @param rInStream + The base input stream. Must be seekable. Will be seeked to its + start position. + + @param bContLookup Automatic CONTINUE lookup on/off. + */ + explicit BiffInputStream( + BinaryInputStream& rInStream, + bool bContLookup = true ); + + // record control --------------------------------------------------------- + + /** Sets stream pointer to the start of the next record content. + + Ignores all CONTINUE records of the current record, if automatic + CONTINUE usage is switched on. + + @return False = no record found (end of stream). + */ + bool startNextRecord(); + + /** Sets stream pointer to the start of the content of the specified record. + + The handle of the current record can be received and stored using the + function getRecHandle() for later usage with this function. The record + handle is equivalent to the position of the underlying binary stream, + thus the function can be used to perform a hard seek to a specific + position, if it is sure that a record starts exactly at this position. + + @return False = no record found (invalid handle passed). + */ + bool startRecordByHandle( sal_Int64 nRecHandle ); + + /** Sets stream pointer to begin of record content. + + @param bContLookup + Automatic CONTINUE lookup on/off. In difference to other stream + settings, this setting is persistent until next call of this + function (because it is wanted to receive the next CONTINUE records + separately). + @param nAltContId + Sets an alternative record identifier for content continuation. + This value is reset automatically when a new record is started with + startNextRecord(). + */ + void resetRecord( + bool bContLookup, + sal_uInt16 nAltContId = BIFF_ID_UNKNOWN ); + + /** Sets stream pointer before current record and invalidates stream. + + The next call to startNextRecord() will start again the current record. + This can be used in situations where a loop or a function leaves on a + specific record, but the parent context expects to start this record by + itself. The stream is invalid as long as the first record has not been + started (it is not allowed to call any other stream operation then). + */ + void rewindRecord(); + + // decoder ---------------------------------------------------------------- + + /** Sets a new decoder object. + + Enables decryption of record contents for the rest of the stream. + */ + void setDecoder( const BiffDecoderRef& rxDecoder ); + + /** Enables/disables usage of current decoder. + + Decryption is reenabled automatically, if a new record is started using + the function startNextRecord(). + */ + void enableDecoder( bool bEnable = true ); + + // stream/record state and info ------------------------------------------- + + /** Returns the current record identifier. */ + inline sal_uInt16 getRecId() const { return mnRecId; } + /** Returns the record identifier of the following record. */ + sal_uInt16 getNextRecId(); + + /** Returns a unique handle for the current record that can be used with + the function startRecordByHandle(). */ + inline sal_Int64 getRecHandle() const { return mnRecHandle; } + + // BinaryStreamBase interface (seeking) ----------------------------------- + + /** Returns true, as the BIFF input stream is required to be seekable. */ + virtual bool isSeekable() 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 ); + + /** 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; + + // 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 ); + /** 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 ); + /** Seeks forward inside the current record. */ + virtual void skip( sal_Int32 nBytes ); + + /** Stream operator for integral and floating-point types. */ + template< typename Type > + inline BiffInputStream& operator>>( Type& ornValue ) { readValue( ornValue ); return *this; } + + // byte strings ----------------------------------------------------------- + + /** Reads 8/16 bit string length and character array, and returns the string. + @param b16BitLen + True = Read 16-bit string length field before the character array. + False = Read 8-bit string length field before the character array. + @param bAllowNulChars + True = NUL characters are inserted into the imported string. + False = NUL characters are replaced by question marks (default). + */ + ::rtl::OString readByteString( bool b16BitLen, bool bAllowNulChars = false ); + + /** Reads 8/16 bit string length and character array, and returns a Unicode string. + @param b16BitLen + True = Read 16-bit string length field before the character array. + False = Read 8-bit string length field before the character array. + @param eTextEnc The text encoding used to create the Unicode string. + @param bAllowNulChars + True = NUL characters are inserted into the imported string. + False = NUL characters are replaced by question marks (default). + */ + ::rtl::OUString readByteStringUC( bool b16BitLen, rtl_TextEncoding eTextEnc, bool bAllowNulChars = false ); + + /** Ignores 8/16 bit string length and character array. + @param b16BitLen + True = Read 16-bit string length field before the character array. + False = Read 8-bit string length field before the character array. + */ + void skipByteString( bool b16BitLen ); + + // Unicode strings -------------------------------------------------------- + + /** Reads nChars characters of a BIFF8 string, and returns the string. + @param nChars Number of characters to read from the stream. + @param b16BitChars + True = The character array contains 16-bit characters. + False = The character array contains truncated 8-bit characters. + @param bAllowNulChars + True = NUL characters are inserted into the imported string. + False = NUL characters are replaced by question marks (default). + */ + ::rtl::OUString readUniStringChars( sal_uInt16 nChars, bool b16BitChars, bool bAllowNulChars = false ); + + /** Reads 8-bit flags, extended header, nChar characters, extended data of + a BIFF8 string, and returns the string. + @param nChars Number of characters to read from the stream. + @param bAllowNulChars + True = NUL characters are inserted into the imported string. + False = NUL characters are replaced by question marks (default). + */ + ::rtl::OUString readUniStringBody( sal_uInt16 nChars, bool bAllowNulChars = false ); + + /** Reads 16-bit character count, 8-bit flags, extended header, character + array, extended data of a BIFF8 string, and returns the string. + @param bAllowNulChars + True = NUL characters are inserted into the imported string. + False = NUL characters are replaced by question marks (default). + */ + ::rtl::OUString readUniString( bool bAllowNulChars = false ); + + /** Ignores nChars characters of a BIFF8 string. + @param nChars Number of characters to skip in the stream. + @param b16BitChars + True = The character array contains 16-bit characters. + False = The character array contains truncated 8-bit characters. + */ + void skipUniStringChars( sal_uInt16 nChars, bool b16BitChars ); + + /** Ignores 8-bit flags, extended header, nChar characters, extended data + of a BIFF8 string. + @param nChars Number of characters to skip in the stream. + */ + void skipUniStringBody( sal_uInt16 nChars ); + + /** Ignores 16-bit character count, 8-bit flags, extended header, character + array, extended data of a BIFF8 string. + */ + void skipUniString(); + + // ------------------------------------------------------------------------ +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. */ + void restartRecord( bool bInvalidateRecSize ); + /** Sets stream pointer before specified record and invalidates stream. */ + void rewindToRecord( sal_Int64 nRecHandle ); + /** Returns true, if stream was able to start a valid record. */ + inline bool isInRecord() const { return mnRecHandle >= 0; } + + /** Returns true, if the passed ID is real or alternative continuation record ID. */ + bool isContinueId( sal_uInt16 nRecId ) const; + /** Goes to start of the next CONTINUE record. + @descr Stream must be located at the end of a raw record, and handling + of CONTINUE records must be enabled. + @return True if next CONTINUE record has been found and initialized. */ + bool jumpToNextContinue(); + /** Goes to start of the next CONTINUE record while reading strings. + @descr Stream must be located at the end of a raw record. If reading + has been started in a CONTINUE record, jumps to an existing following + CONTINUE record, even if handling of CONTINUE records is disabled (this + is a special handling for TXO string data). Reads additional Unicode + flag byte at start of the new raw record and sets or resets rb16BitChars. + @return True if next CONTINUE record has been found and initialized. */ + bool jumpToNextStringContinue( bool& rb16BitChars ); + /** Calculates the complete length of the current record including CONTINUE + 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; + + /** 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 ); + +private: + prv::BiffInputRecordBuffer maRecBuffer; /// Raw record data buffer. + + sal_Int64 mnRecHandle; /// Handle of current record. + sal_uInt16 mnRecId; /// Identifier of current record (not the CONTINUE ID). + sal_uInt16 mnAltContId; /// Alternative identifier for content continuation records. + + sal_Int64 mnCurrRecSize; /// Helper for record size and position. + sal_Int64 mnComplRecSize; /// Size of complete record data (with CONTINUEs). + bool mbHasComplRec; /// True = mnComplRecSize is valid. + + bool mbCont; /// True = automatic CONTINUE lookup enabled. +}; + +// ============================================================================ + +class BiffInputStreamPos +{ +public: + explicit BiffInputStreamPos( BiffInputStream& rStrm ); + + bool restorePosition(); + + inline BiffInputStream& getStream() { return mrStrm; } + +private: + BiffInputStream& mrStrm; + sal_Int64 mnRecHandle; + sal_Int64 mnRecPos; +}; + +// ============================================================================ + +/** Stores the current position of the passed stream on construction and + restores it automatically on destruction. */ +class BiffInputStreamPosGuard : private BiffInputStreamPos +{ +public: + explicit BiffInputStreamPosGuard( BiffInputStream& rStrm ); + ~BiffInputStreamPosGuard(); +}; + +// ============================================================================ + +} // namespace xls +} // namespace oox + +#endif diff --git a/oox/inc/oox/xls/biffoutputstream.hxx b/oox/inc/oox/xls/biffoutputstream.hxx new file mode 100644 index 000000000000..ada646bd879a --- /dev/null +++ b/oox/inc/oox/xls/biffoutputstream.hxx @@ -0,0 +1,164 @@ +/************************************************************************* + * + * 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_BIFFOUTPUTSTREAM_HXX +#define OOX_XLS_BIFFOUTPUTSTREAM_HXX + +#include <vector> +#include "oox/helper/binaryoutputstream.hxx" +#include "oox/xls/biffhelper.hxx" + +namespace oox { class BinaryOutputStream; } + +namespace oox { +namespace xls { + +// ============================================================================ + +namespace prv { + +/** Buffers the contents of a raw record. */ +class BiffOutputRecordBuffer +{ +public: + explicit BiffOutputRecordBuffer( + BinaryOutputStream& rOutStrm, + sal_uInt16 nMaxRecSize ); + + /** Returns the wrapped binary base stream. */ + inline const BinaryOutputStream& getBaseStream() const { return mrOutStrm; } + + /** Starts a new record. */ + void startRecord( sal_uInt16 nRecId ); + /** Finishes the current record. Must be called for every started record. */ + void endRecord(); + + /** Returns the number of remaining bytes in the current record body. */ + inline sal_uInt16 getRecLeft() const { return static_cast< sal_uInt16 >( mnMaxRecSize - maData.size() ); } + + /** Writes nBytes bytes from the existing buffer pData. Must NOT overwrite the destination buffer. */ + void write( const void* pData, sal_uInt16 nBytes ); + /** Writes a sequence of nBytes bytes with the passed value. */ + void fill( sal_uInt8 nValue, sal_uInt16 nBytes ); + +private: + typedef ::std::vector< sal_uInt8 > DataBuffer; + + BinaryOutputStream& mrOutStrm; /// Core ouput stream. + DataBuffer maData; /// Record data buffer. + sal_uInt16 mnMaxRecSize; /// Maximum size of record contents. + sal_uInt16 mnRecId; /// Current record identifier. + bool mbInRec; /// True = currently writing inside of a record. +}; + +} // namespace prv + +// ============================================================================ + +/** This class is used to write BIFF record streams. + + An instance is constructed with a BinaryOutputStream object and the + maximum size of BIFF record contents (e.g. 2080 bytes in BIFF2-BIFF5, or + 8224 bytes in BIFF8). + + To start writing a record, call startRecord() with the record identifier. + Each record must be closed by calling endRecord(). + + If some data exceeds the record size limit, a CONTINUE record will be + started automatically and the new data will be written to this record. If + specific data pieces must not be split into the current and a following + 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 +{ +public: + explicit BiffOutputStream( + BinaryOutputStream& rOutStream, + sal_uInt16 nMaxRecSize ); + + // record control --------------------------------------------------------- + + /** Starts a new record. */ + void startRecord( sal_uInt16 nRecId ); + + /** 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 ); + + // 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; + + // BinaryOutputStream interface (stream write access) --------------------- + + /** Writes the passed data sequence. */ + virtual void writeData( const StreamDataSequence& rData ); + /** Writes nBytes bytes from the passed buffer pMem. */ + virtual void writeMemory( const void* pMem, sal_Int32 nBytes ); + + /** 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 ); + + /** Stream operator for integral and floating-point types. */ + 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. + @return Maximum size left for writing to current record. */ + sal_uInt16 prepareRawBlock( sal_Int32 nTotalSize ); + +private: + prv::BiffOutputRecordBuffer maRecBuffer; /// Raw record data buffer. + sal_uInt16 mnPortionSize; /// Size of data portions. + sal_uInt16 mnPortionPos; /// Position in current portion. +}; + +// ============================================================================ + +} // namespace xls +} // namespace oox + +#endif diff --git a/oox/inc/oox/xls/chartsheetfragment.hxx b/oox/inc/oox/xls/chartsheetfragment.hxx new file mode 100644 index 000000000000..8dfedc5ba48e --- /dev/null +++ b/oox/inc/oox/xls/chartsheetfragment.hxx @@ -0,0 +1,83 @@ +/************************************************************************* + * + * 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_CHARTSHEETFRAGMENT_HXX +#define OOX_XLS_CHARTSHEETFRAGMENT_HXX + +#include "oox/xls/excelhandlers.hxx" + +namespace oox { +namespace xls { + +// ============================================================================ + +class ChartsheetFragment : public WorksheetFragmentBase +{ +public: + explicit ChartsheetFragment( + const WorkbookHelper& rHelper, + const ::rtl::OUString& rFragmentPath, + const ISegmentProgressBarRef& rxProgressBar, + sal_Int16 nSheet ); + +protected: + virtual ::oox::core::ContextHandlerRef onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ); + virtual void onCharacters( const ::rtl::OUString& rChars ); + + virtual ::oox::core::ContextHandlerRef onCreateRecordContext( sal_Int32 nRecId, SequenceInputStream& rStrm ); + + virtual const ::oox::core::RecordInfo* getRecordInfos() const; + virtual void initializeImport(); + virtual void finalizeImport(); + +private: + /** Imports the the relation identifier for the DrawingML part. */ + void importDrawing( const AttributeList& rAttribs ); + /** Imports the DRAWING record containing the relation identifier for the DrawingML part. */ + void importDrawing( SequenceInputStream& rStrm ); +}; + +// ============================================================================ + +class BiffChartsheetFragment : public BiffWorksheetFragmentBase +{ +public: + explicit BiffChartsheetFragment( + const BiffWorkbookFragmentBase& rParent, + const ISegmentProgressBarRef& rxProgressBar, + sal_Int16 nSheet ); + + /** Imports the entire sheet fragment, returns true, if EOF record has been reached. */ + virtual bool importFragment(); +}; + +// ============================================================================ + +} // namespace xls +} // namespace oox + +#endif diff --git a/oox/inc/oox/xls/commentsbuffer.hxx b/oox/inc/oox/xls/commentsbuffer.hxx new file mode 100644 index 000000000000..e87d52ff03a2 --- /dev/null +++ b/oox/inc/oox/xls/commentsbuffer.hxx @@ -0,0 +1,101 @@ +/************************************************************************* + * + * 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_COMMENTSBUFFER_HXX +#define OOX_XLS_COMMENTSBUFFER_HXX + +#include "oox/xls/richstring.hxx" +#include "oox/xls/worksheethelper.hxx" + +namespace oox { +namespace xls { + +// ============================================================================ + +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. + + explicit CommentModel(); +}; + +// ---------------------------------------------------------------------------- + +class Comment : public WorksheetHelper +{ +public: + explicit Comment( const WorksheetHelper& rHelper ); + + /** Imports a cell comment from the passed attributes of the comment element. */ + void importComment( const AttributeList& rAttribs ); + /** Imports a cell comment from the passed stream of a COMMENT record. */ + void importComment( SequenceInputStream& rStrm ); + + /** Creates and returns a new rich-string object for the comment text. */ + RichStringRef createText(); + + /** Finalizes the formatted string of the comment. */ + void finalizeImport(); + +private: + CommentModel maModel; +}; + +typedef ::boost::shared_ptr< Comment > CommentRef; + +// ============================================================================ + +class CommentsBuffer : public WorksheetHelper +{ +public: + explicit CommentsBuffer( const WorksheetHelper& rHelper ); + + /** Appends a new author to the list of comment authors. */ + void appendAuthor( const ::rtl::OUString& rAuthor ); + /** Creates and returns a new comment. */ + CommentRef createComment(); + + /** Finalizes the formatted string of all comments. */ + void finalizeImport(); + +private: + typedef ::std::vector< ::rtl::OUString > OUStringVector; + typedef RefVector< Comment > CommentVector; + + OUStringVector maAuthors; + CommentVector maComments; +}; + +// ============================================================================ + +} // namespace xls +} // namespace oox + +#endif diff --git a/oox/inc/oox/xls/commentsfragment.hxx b/oox/inc/oox/xls/commentsfragment.hxx new file mode 100644 index 000000000000..3751cde764f4 --- /dev/null +++ b/oox/inc/oox/xls/commentsfragment.hxx @@ -0,0 +1,70 @@ +/************************************************************************* + * + * 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_COMMENTSFRAGMENT_HXX +#define OOX_XLS_COMMENTSFRAGMENT_HXX + +#include "oox/xls/commentsbuffer.hxx" +#include "oox/xls/excelhandlers.hxx" + +namespace oox { +namespace xls { + +// ============================================================================ + +class CommentsFragment : public WorksheetFragmentBase +{ +public: + explicit CommentsFragment( + const WorksheetHelper& rHelper, + const ::rtl::OUString& rFragmentPath ); +protected: + virtual ::oox::core::ContextHandlerRef onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ); + virtual void onCharacters( const ::rtl::OUString& rChars ); + virtual void onEndElement(); + + virtual ::oox::core::ContextHandlerRef onCreateRecordContext( sal_Int32 nRecId, SequenceInputStream& rStrm ); + virtual void onEndRecord(); + + virtual const ::oox::core::RecordInfo* getRecordInfos() const; + +private: + /** Imports comment data from the comment element. */ + void importComment( const AttributeList& rAttribs ); + /** Imports comment data from the COMMENT record. */ + void importComment( SequenceInputStream& rStrm ); + +private: + CommentRef mxComment; +}; + +// ============================================================================ + +} // namespace xls +} // namespace oox + +#endif diff --git a/oox/inc/oox/xls/condformatbuffer.hxx b/oox/inc/oox/xls/condformatbuffer.hxx new file mode 100644 index 000000000000..fae6381f6402 --- /dev/null +++ b/oox/inc/oox/xls/condformatbuffer.hxx @@ -0,0 +1,193 @@ +/************************************************************************* + * + * 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_CONDFORMATBUFFER_HXX +#define OOX_XLS_CONDFORMATBUFFER_HXX + +#include <com/sun/star/sheet/ConditionOperator.hpp> +#include "oox/xls/formulaparser.hxx" +#include "oox/xls/worksheethelper.hxx" + +namespace com { namespace sun { namespace star { + namespace sheet { class XSheetConditionalEntries; } +} } } + +namespace oox { +namespace xls { + +// ============================================================================ + +/** Model for a single rule in a conditional formatting. */ +struct CondFormatRuleModel +{ + typedef ::std::vector< TokensFormulaContext > ContextVector; + + ContextVector 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. + sal_Int32 mnOperator; /// In cell-is rules: Comparison operator. + sal_Int32 mnTimePeriod; /// In time-period rules: Type of time period. + sal_Int32 mnRank; /// In top-10 rules: True = bottom, false = top. + sal_Int32 mnStdDev; /// In average rules: Number of std deviations. + sal_Int32 mnDxfId; /// Differential formatting identifier. + bool mbStopIfTrue; /// True = stop evaluating rules, if this rule is true. + bool mbBottom; /// In top-10 rules: True = bottom, false = top. + bool mbPercent; /// In top-10 rules: True = percent, false = rank. + bool mbAboveAverage; /// In average rules: True = above average, false = below. + bool mbEqualAverage; /// In average rules: True = include average, false = exclude. + + explicit CondFormatRuleModel(); + + /** Sets the passed BIFF operator for condition type cellIs. */ + void setBiffOperator( sal_Int32 nOperator ); + + /** Sets the passed BIFF12 text comparison type and operator. */ + void setBiff12TextType( sal_Int32 nOperator ); +}; + +// ============================================================================ + +class CondFormat; + +/** Represents a single rule in a conditional formatting. */ +class CondFormatRule : public WorksheetHelper +{ +public: + explicit CondFormatRule( const CondFormat& rCondFormat ); + + /** Imports rule settings from the cfRule element. */ + void importCfRule( const AttributeList& rAttribs ); + /** Appends a new condition formula string. */ + void appendFormula( const ::rtl::OUString& rFormula ); + + /** Imports rule settings from a CFRULE record. */ + void importCfRule( SequenceInputStream& rStrm ); + + /** Imports rule settings from a CFRULE record. */ + void importCfRule( BiffInputStream& rStrm, sal_Int32 nPriority ); + + /** Creates a conditional formatting rule in the Calc document. */ + void finalizeImport( + const ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XSheetConditionalEntries >& rxEntries ); + + /** Returns the priority of this rule. */ + inline sal_Int32 getPriority() const { return maModel.mnPriority; } + +private: + const CondFormat& mrCondFormat; + CondFormatRuleModel maModel; +}; + +typedef ::boost::shared_ptr< CondFormatRule > CondFormatRuleRef; + +// ============================================================================ + +/** Model for a conditional formatting object. */ +struct CondFormatModel +{ + ApiCellRangeList maRanges; /// Cell ranges for this conditional format. + bool mbPivot; /// Conditional formatting belongs to pivot table. + + explicit CondFormatModel(); +}; + +// ============================================================================ + +/** Represents a conditional formatting object with a list of affected cell ranges. */ +class CondFormat : public WorksheetHelper +{ +public: + explicit CondFormat( const WorksheetHelper& rHelper ); + + /** Imports settings from the conditionalFormatting element. */ + void importConditionalFormatting( const AttributeList& rAttribs ); + /** Imports a conditional formatting rule from the cfRule element. */ + CondFormatRuleRef importCfRule( const AttributeList& rAttribs ); + + /** Imports settings from the CONDFORMATTING record. */ + void importCondFormatting( SequenceInputStream& rStrm ); + /** Imports a conditional formatting rule from the CFRULE record. */ + void importCfRule( SequenceInputStream& rStrm ); + + /** Imports settings from the CFHEADER record. */ + void importCfHeader( BiffInputStream& rStrm ); + + /** Creates the conditional formatting in the Calc document. */ + void finalizeImport(); + + /** Returns the cell ranges this conditional formatting belongs to. */ + inline const ApiCellRangeList& getRanges() const { return maModel.maRanges; } + +private: + CondFormatRuleRef createRule(); + void insertRule( CondFormatRuleRef xRule ); + +private: + typedef RefMap< sal_Int32, CondFormatRule > CondFormatRuleMap; + + CondFormatModel maModel; /// Model of this conditional formatting. + CondFormatRuleMap maRules; /// Maps formatting rules by priority. +}; + +typedef ::boost::shared_ptr< CondFormat > CondFormatRef; + +// ============================================================================ + +class CondFormatBuffer : public WorksheetHelper +{ +public: + explicit CondFormatBuffer( const WorksheetHelper& rHelper ); + + /** Imports settings from the conditionalFormatting element. */ + CondFormatRef importConditionalFormatting( const AttributeList& rAttribs ); + /** Imports settings from the CONDFORMATTING record. */ + CondFormatRef importCondFormatting( SequenceInputStream& rStrm ); + /** Imports settings from the CFHEADER record. */ + void importCfHeader( BiffInputStream& rStrm ); + + /** Creates all conditional formattings in the Calc document. */ + void finalizeImport(); + + /** Converts an OOXML condition operator token to the API constant. */ + static ::com::sun::star::sheet::ConditionOperator + convertToApiOperator( sal_Int32 nToken ); + +private: + CondFormatRef createCondFormat(); + +private: + typedef RefVector< CondFormat > CondFormatVec; + CondFormatVec maCondFormats; /// All conditional formattings in a sheet. +}; + +// ============================================================================ + +} // namespace xls +} // namespace oox + +#endif diff --git a/oox/inc/oox/xls/condformatcontext.hxx b/oox/inc/oox/xls/condformatcontext.hxx new file mode 100644 index 000000000000..44c9fe592250 --- /dev/null +++ b/oox/inc/oox/xls/condformatcontext.hxx @@ -0,0 +1,62 @@ +/************************************************************************* + * + * 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_CONDFORMATCONTEXT_HXX +#define OOX_XLS_CONDFORMATCONTEXT_HXX + +#include "oox/xls/condformatbuffer.hxx" +#include "oox/xls/excelhandlers.hxx" + +namespace oox { +namespace xls { + +// ============================================================================ + +class CondFormatContext : public WorksheetContextBase +{ +public: + explicit CondFormatContext( WorksheetFragmentBase& rFragment ); + +protected: + virtual ::oox::core::ContextHandlerRef onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ); + virtual void onStartElement( const AttributeList& rAttribs ); + virtual void onCharacters( const ::rtl::OUString& rChars ); + + virtual ::oox::core::ContextHandlerRef onCreateRecordContext( sal_Int32 nRecId, SequenceInputStream& rStrm ); + virtual void onStartRecord( SequenceInputStream& rStrm ); + +private: + CondFormatRef mxCondFmt; + CondFormatRuleRef mxRule; +}; + +// ============================================================================ + +} // namespace xls +} // namespace oox + +#endif diff --git a/oox/inc/oox/xls/connectionsbuffer.hxx b/oox/inc/oox/xls/connectionsbuffer.hxx new file mode 100755 index 000000000000..98a5bea17bc6 --- /dev/null +++ b/oox/inc/oox/xls/connectionsbuffer.hxx @@ -0,0 +1,186 @@ +/************************************************************************* + * + * 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_CONNECTIONSBUFFER_HXX +#define OOX_XLS_CONNECTIONSBUFFER_HXX + +#include "oox/helper/refvector.hxx" +#include "oox/xls/workbookhelper.hxx" + +namespace oox { +namespace xls { + +// ============================================================================ + +const sal_Int32 BIFF12_CONNECTION_UNKNOWN = 0; +const sal_Int32 BIFF12_CONNECTION_ODBC = 1; +const sal_Int32 BIFF12_CONNECTION_DAO = 2; +const sal_Int32 BIFF12_CONNECTION_FILE = 3; +const sal_Int32 BIFF12_CONNECTION_HTML = 4; +const sal_Int32 BIFF12_CONNECTION_OLEDB = 5; +const sal_Int32 BIFF12_CONNECTION_TEXT = 6; +const sal_Int32 BIFF12_CONNECTION_ADO = 7; +const sal_Int32 BIFF12_CONNECTION_DSP = 8; + +// ============================================================================ + +/** Special properties for data connections representing web queries. */ +struct WebPrModel +{ + typedef ::std::vector< ::com::sun::star::uno::Any > TablesVector; + + TablesVector maTables; /// Names or indexes of the web query tables. + ::rtl::OUString maUrl; /// Source URL to refresh the data. + ::rtl::OUString maPostMethod; /// POST method to query data. + ::rtl::OUString maEditPage; /// Web page showing query data (for XML queries). + sal_Int32 mnHtmlFormat; /// Plain text, rich text, or HTML. + bool mbXml; /// True = XML query, false = HTML query. + bool mbSourceData; /// True = import XML source data referred by HTML table. + bool mbParsePre; /// True = parse preformatted sections (<pre> tag). + bool mbConsecutive; /// True = join consecutive delimiters. + bool mbFirstRow; /// True = use column withs of first row for entire <pre> tag. + bool mbXl97Created; /// True = web query created with Excel 97. + bool mbTextDates; /// True = read date values as text, false = parse dates. + bool mbXl2000Refreshed; /// True = refreshed with Excel 2000 or newer. + bool mbHtmlTables; /// True = HTML tables, false = entire document. + + explicit WebPrModel(); +}; + +// ---------------------------------------------------------------------------- + +/** Common properties of an external data connection. */ +struct ConnectionModel +{ + typedef ::std::auto_ptr< WebPrModel > WebPrModelPtr; + + WebPrModelPtr mxWebPr; /// Special settings for web queries. + ::rtl::OUString maName; /// Unique name of this connection. + ::rtl::OUString maDescription; /// User description of this connection. + ::rtl::OUString maSourceFile; /// URL of a source data file. + ::rtl::OUString maSourceConnFile; /// URL of a source connection file. + ::rtl::OUString maSsoId; /// Single sign-on identifier. + sal_Int32 mnId; /// Unique connection identifier. + sal_Int32 mnType; /// Data source type. + sal_Int32 mnReconnectMethod; /// Reconnection method. + sal_Int32 mnCredentials; /// Credentials method. + sal_Int32 mnInterval; /// Refresh interval in minutes. + bool mbKeepAlive; /// True = keep connection open after import. + bool mbNew; /// True = new connection, never updated. + bool mbDeleted; /// True = connection has been deleted. + bool mbOnlyUseConnFile; /// True = use maSourceConnFile, ignore mnReconnectMethod. + bool mbBackground; /// True = background refresh enabled. + bool mbRefreshOnLoad; /// True = refresh connection on import. + bool mbSaveData; /// True = save cached data with connection. + bool mbSavePassword; /// True = save password in connection string. + + explicit ConnectionModel(); + + WebPrModel& createWebPr(); +}; + +// ---------------------------------------------------------------------------- + +/** An external data connection (database, web query, etc.). */ +class Connection : public WorkbookHelper +{ +public: + explicit Connection( const WorkbookHelper& rHelper, sal_Int32 nConnId = -1 ); + + /** Imports connection settings from the connection element. */ + void importConnection( const AttributeList& rAttribs ); + /** Imports web query settings from the webPr element. */ + void importWebPr( const AttributeList& rAttribs ); + /** Imports web query table settings from the tables element. */ + void importTables( const AttributeList& rAttribs ); + /** Imports a web query table identifier from the m, s, or x element. */ + void importTable( const AttributeList& rAttribs, sal_Int32 nElement ); + + /** Imports connection settings from the CONNECTION record. */ + void importConnection( SequenceInputStream& rStrm ); + /** Imports web query settings from the WEBPR record. */ + void importWebPr( SequenceInputStream& rStrm ); + /** Imports web query table settings from the WEBPRTABLES record. */ + void importWebPrTables( SequenceInputStream& rStrm ); + /** Imports a web query table identifier from the PCITEM_MISSING, PCITEM_STRING, or PCITEM_INDEX record. */ + void importWebPrTable( SequenceInputStream& rStrm, sal_Int32 nRecId ); + + /** Imports connection settings from the DBQUERY record. */ + void importDbQuery( BiffInputStream& rStrm ); + /** Imports connection settings from the QUERYTABLESETTINGS record. */ + void importQueryTableSettings( BiffInputStream& rStrm ); + + /** Returns the unique connection identifier. */ + inline sal_Int32 getConnectionId() const { return maModel.mnId; } + /** Returns the source data type of the connection. */ + inline sal_Int32 getConnectionType() const { return maModel.mnType; } + /** Returns read-only access to the connection model data. */ + const ConnectionModel& getModel() const { return maModel; } + +private: + ConnectionModel maModel; +}; + +typedef ::boost::shared_ptr< Connection > ConnectionRef; + +// ============================================================================ + +class ConnectionsBuffer : public WorkbookHelper +{ +public: + explicit ConnectionsBuffer( const WorkbookHelper& rHelper ); + + /** Creates a new empty connection. */ + Connection& createConnection(); + /** Creates a new empty connection with a valid but unused identifier. */ + Connection& createConnectionWithId(); + + /** Maps all connections by their identifier. */ + void finalizeImport(); + + /** Returns a data connection by its unique identifier. */ + ConnectionRef getConnection( sal_Int32 nConnId ) const; + +private: + /** Inserts the passed connection into the map according to its identifier. */ + void insertConnectionToMap( const ConnectionRef& rxConnection ); + +private: + typedef RefVector< Connection > ConnectionVector; + typedef RefMap< sal_Int32, Connection > ConnectionMap; + + ConnectionVector maConnections; + ConnectionMap maConnectionsById; + sal_Int32 mnUnusedId; +}; + +// ============================================================================ + +} // namespace xls +} // namespace oox + +#endif diff --git a/oox/inc/oox/xls/connectionsfragment.hxx b/oox/inc/oox/xls/connectionsfragment.hxx new file mode 100644 index 000000000000..5a9a9085c6c5 --- /dev/null +++ b/oox/inc/oox/xls/connectionsfragment.hxx @@ -0,0 +1,78 @@ +/************************************************************************* + * + * 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_CONNECTIONSFRAGMENT_HXX +#define OOX_XLS_CONNECTIONSFRAGMENT_HXX + +#include "oox/xls/excelhandlers.hxx" + +namespace oox { +namespace xls { + +class Connection; + +// ============================================================================ + +class ConnectionContext : public WorkbookContextBase +{ +public: + explicit ConnectionContext( WorkbookFragmentBase& rParent, Connection& rConnection ); + +protected: + virtual ::oox::core::ContextHandlerRef onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ); + virtual void onStartElement( const AttributeList& rAttribs ); + + virtual ::oox::core::ContextHandlerRef onCreateRecordContext( sal_Int32 nRecId, SequenceInputStream& rStrm ); + virtual void onStartRecord( SequenceInputStream& rStrm ); + +private: + Connection& mrConnection; +}; + +// ============================================================================ + +class ConnectionsFragment : public WorkbookFragmentBase +{ +public: + explicit ConnectionsFragment( + const WorkbookHelper& rHelper, + const ::rtl::OUString& rFragmentPath ); + +protected: + virtual ::oox::core::ContextHandlerRef onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ); + virtual ::oox::core::ContextHandlerRef onCreateRecordContext( sal_Int32 nRecId, SequenceInputStream& rStrm ); + + virtual const ::oox::core::RecordInfo* getRecordInfos() const; + virtual void finalizeImport(); +}; + +// ============================================================================ + +} // namespace xls +} // namespace oox + +#endif diff --git a/oox/inc/oox/xls/defnamesbuffer.hxx b/oox/inc/oox/xls/defnamesbuffer.hxx new file mode 100644 index 000000000000..5374c47f6a07 --- /dev/null +++ b/oox/inc/oox/xls/defnamesbuffer.hxx @@ -0,0 +1,233 @@ +/************************************************************************* + * + * 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_DEFINEDNAMESBUFFER_HXX +#define OOX_XLS_DEFINEDNAMESBUFFER_HXX + +#include "oox/xls/formulabase.hxx" + +namespace com { namespace sun { namespace star { + namespace sheet { class XNamedRange; } +} } } + +namespace oox { +namespace xls { + +class FormulaContext; +class BiffInputStreamPos; + +// ============================================================================ + +// codes for built-in names +const sal_Unicode BIFF_DEFNAME_CONSOLIDATEAREA = '\x00'; +const sal_Unicode BIFF_DEFNAME_AUTOOPEN = '\x01'; // Sheet macro executed when workbook is opened. +const sal_Unicode BIFF_DEFNAME_AUTOCLOSE = '\x02'; // Sheet macro executed when workbook is closed. +const sal_Unicode BIFF_DEFNAME_EXTRACT = '\x03'; // Filter output destination for advanced filter. +const sal_Unicode BIFF_DEFNAME_DATABASE = '\x04'; +const sal_Unicode BIFF_DEFNAME_CRITERIA = '\x05'; // Filter criteria source range for advanced filter. +const sal_Unicode BIFF_DEFNAME_PRINTAREA = '\x06'; // Print ranges. +const sal_Unicode BIFF_DEFNAME_PRINTTITLES = '\x07'; // Rows/columns repeated on each page when printing. +const sal_Unicode BIFF_DEFNAME_RECORDER = '\x08'; +const sal_Unicode BIFF_DEFNAME_DATAFORM = '\x09'; +const sal_Unicode BIFF_DEFNAME_AUTOACTIVATE = '\x0A'; // Sheet macro executed when workbook is activated. +const sal_Unicode BIFF_DEFNAME_AUTODEACTIVATE = '\x0B'; // Sheet macro executed when workbook is deactivated. +const sal_Unicode BIFF_DEFNAME_SHEETTITLE = '\x0C'; +const sal_Unicode BIFF_DEFNAME_FILTERDATABASE = '\x0D'; // Sheet range autofilter or advanced filter works on. +const sal_Unicode BIFF_DEFNAME_UNKNOWN = '\x0E'; + +// ============================================================================ + +struct DefinedNameModel +{ + ::rtl::OUString maName; /// The original name. + ::rtl::OUString maFormula; /// The formula string. + sal_Int32 mnSheet; /// Sheet index for local names. + sal_Int32 mnFuncGroupId; /// Function group identifier. + bool mbMacro; /// True = Macro name (VBA or sheet macro). + bool mbFunction; /// True = function, false = command. + bool mbVBName; /// True = VBA macro, false = sheet macro. + bool mbHidden; /// True = name hidden in UI. + + explicit DefinedNameModel(); +}; + +// ============================================================================ + +/** Base class for defined names and external names. */ +class DefinedNameBase : public WorkbookHelper +{ +public: + explicit DefinedNameBase( const WorkbookHelper& rHelper ); + + /** Returns the original name as imported from or exported to the file. */ + inline const ::rtl::OUString& getModelName() const { return maModel.maName; } + /** Returns the name as used in the Calc document. */ + inline const ::rtl::OUString& getCalcName() const { return maCalcName; } + + /** 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; + +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 ); + + /** Tries to convert the passed token sequence to a SingleReference or ComplexReference. */ + void extractReference( const ApiTokenSequence& rTokens ); + +protected: + DefinedNameModel maModel; /// Model data for this defined name. + mutable ::rtl::OUString maUpModelName; /// Model name converted to uppercase ASCII. + ::rtl::OUString maCalcName; /// Final name used in the Calc document. + ::com::sun::star::uno::Any maRefAny; /// Single cell/range reference. +}; + +// ============================================================================ + +class DefinedName : public DefinedNameBase +{ +public: + explicit DefinedName( const WorkbookHelper& rHelper ); + + /** Sets the attributes for this defined name from the passed attribute set. */ + void importDefinedName( const AttributeList& rAttribs ); + /** Sets the formula string from the body of the definedName element. */ + void setFormula( const ::rtl::OUString& rFormula ); + /** Imports the defined name from a DEFINEDNAME record in the passed stream. */ + void importDefinedName( SequenceInputStream& rStrm ); + /** Imports the defined name from a DEFINEDNAME record in the passed BIFF stream. */ + void importDefinedName( BiffInputStream& rStrm, sal_Int16 nCalcSheet ); + + /** Creates a defined name in the Calc document. */ + void createNameObject(); + /** Converts the formula string or BIFF token array for this defined name. */ + void convertFormula(); + + /** Returns true, if this defined name is global in the document. */ + inline bool isGlobalName() const { return mnCalcSheet < 0; } + /** Returns true, if this defined name is a special builtin name. */ + inline bool isBuiltinName() const { return mcBuiltinId != BIFF_DEFNAME_UNKNOWN; } + /** Returns true, if this defined name is a macro function call. */ + inline bool isMacroFunction() const { return maModel.mbMacro && maModel.mbFunction; } + /** Returns true, if this defined name is a reference to a VBA macro. */ + inline bool isVBName() const { return maModel.mbMacro && maModel.mbVBName; } + + /** Returns the 0-based sheet index for local names, or -1 for global names. */ + inline sal_Int16 getLocalCalcSheet() const { return mnCalcSheet; } + /** Returns the built-in identifier of the defined name. */ + inline sal_Unicode getBuiltinId() const { return mcBuiltinId; } + /** Returns the token index used in API token arrays (com.sun.star.sheet.FormulaToken). */ + inline sal_Int32 getTokenIndex() const { return mnTokenIndex; } + /** Tries to resolve the defined name to an absolute cell range. */ + 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 ); + +private: + typedef ::std::auto_ptr< StreamDataSequence > StreamDataSeqPtr; + typedef ::std::auto_ptr< BiffInputStreamPos > BiffStreamPosPtr; + + ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XNamedRange > + mxNamedRange; /// XNamedRange interface of the defined name. + sal_Int32 mnTokenIndex; /// Name index used in API token array. + sal_Int16 mnCalcSheet; /// Calc sheet index for sheet-local names. + sal_Unicode mcBuiltinId; /// Identifier for built-in defined names. + StreamDataSeqPtr mxFormula; /// Formula data for BIFF12 import. + BiffStreamPosPtr mxBiffStrm; /// Cached BIFF stream for formula import. + sal_uInt16 mnFmlaSize; /// Cached BIFF formula size for formula import. +}; + +typedef ::boost::shared_ptr< DefinedName > DefinedNameRef; + +// ============================================================================ + +class DefinedNamesBuffer : public WorkbookHelper +{ +public: + explicit DefinedNamesBuffer( const WorkbookHelper& rHelper ); + + /** Sets the sheet index for local names (BIFF2-BIFF4 only). */ + void setLocalCalcSheet( sal_Int16 nCalcSheet ); + + /** Imports a defined name from the passed attribute set. */ + DefinedNameRef importDefinedName( const AttributeList& rAttribs ); + /** Imports a defined name from a DEFINEDNAME record in the passed stream. */ + void importDefinedName( SequenceInputStream& rStrm ); + /** Imports a defined name from a DEFINEDNAME record in the passed BIFF stream. */ + void importDefinedName( BiffInputStream& rStrm ); + + /** Creates all defined names in the document. */ + void finalizeImport(); + + /** Returns a defined name by zero-based index (order of appearence). */ + DefinedNameRef getByIndex( sal_Int32 nIndex ) const; + /** Returns a defined name by token index (index in XDefinedNames container). */ + DefinedNameRef getByTokenIndex( sal_Int32 nIndex ) const; + /** Returns a defined name by its model name. + @param nSheet The sheet index for local names or -1 for global names. + If no local name is found, tries to find a matching global name. + @return Reference to the defined name or empty reference. */ + DefinedNameRef getByModelName( const ::rtl::OUString& rModelName, sal_Int16 nCalcSheet = -1 ) const; + /** Returns a built-in defined name by its built-in identifier. + @param nSheet The sheet index of the built-in name. + @return Reference to the defined name or empty reference. */ + DefinedNameRef getByBuiltinId( sal_Unicode cBuiltinId, sal_Int16 nCalcSheet ) const; + +private: + DefinedNameRef createDefinedName(); + +private: + typedef ::std::pair< sal_Int16, ::rtl::OUString > SheetNameKey; + typedef ::std::pair< sal_Int16, sal_Unicode > BuiltinKey; + + typedef RefVector< DefinedName > DefNameVector; + typedef RefMap< SheetNameKey, DefinedName > DefNameNameMap; + typedef RefMap< BuiltinKey, DefinedName > DefNameBuiltinMap; + typedef RefMap< sal_Int32, DefinedName > DefNameTokenIdMap; + + DefNameVector maDefNames; /// List of all defined names in insertion order. + DefNameNameMap maModelNameMap; /// Maps all defined names by sheet index and model name. + DefNameBuiltinMap maBuiltinMap; /// Maps all defined names by sheet index and built-in identifier. + DefNameTokenIdMap maTokenIdMap; /// Maps all defined names by API token index. + sal_Int16 mnCalcSheet; /// Current sheet index for BIFF2-BIFF4 names (always sheet-local). +}; + +// ============================================================================ + +} // namespace xls +} // namespace oox + +#endif diff --git a/oox/inc/oox/xls/drawingfragment.hxx b/oox/inc/oox/xls/drawingfragment.hxx new file mode 100644 index 000000000000..0d3360323a94 --- /dev/null +++ b/oox/inc/oox/xls/drawingfragment.hxx @@ -0,0 +1,326 @@ +/************************************************************************* + * + * 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_DRAWINGFRAGMENT_HXX +#define OOX_XLS_DRAWINGFRAGMENT_HXX + +#include <com/sun/star/awt/Rectangle.hpp> +#include <com/sun/star/awt/Size.hpp> +#include "oox/drawingml/shape.hxx" +#include "oox/drawingml/shapegroupcontext.hxx" +#include "oox/ole/axcontrol.hxx" +#include "oox/ole/vbaproject.hxx" +#include "oox/vml/vmldrawing.hxx" +#include "oox/vml/vmldrawingfragment.hxx" +#include "oox/vml/vmltextbox.hxx" +#include "oox/xls/excelhandlers.hxx" + +namespace oox { namespace ole { + struct AxFontData; + class AxMorphDataModelBase; +} } + +namespace oox { +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: + explicit ShapeMacroAttacher( const ::rtl::OUString& rMacroName, + const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape >& rxShape ); + +private: + virtual void attachMacro( const ::rtl::OUString& rMacroUrl ); + +private: + ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape > mxShape; +}; + +// ============================================================================ + +class Shape : public ::oox::drawingml::Shape, public WorksheetHelper +{ +public: + explicit Shape( + const WorksheetHelper& rHelper, + const AttributeList& rAttribs, + const sal_Char* pcServiceName = 0 ); + +protected: + virtual void finalizeXShape( + ::oox::core::XmlFilterBase& rFilter, + const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShapes >& rxShapes ); + +private: + ::rtl::OUString maMacroName; +}; + +// ============================================================================ + +/** Context handler for creation of shapes embedded in group shapes. */ +class GroupShapeContext : public ::oox::drawingml::ShapeGroupContext, public WorksheetHelper +{ +public: + explicit GroupShapeContext( + ::oox::core::ContextHandler& rParent, + const WorksheetHelper& rHelper, + const ::oox::drawingml::ShapePtr& rxParentShape, + const ::oox::drawingml::ShapePtr& rxShape ); + + static ::oox::core::ContextHandlerRef + createShapeContext( + ::oox::core::ContextHandler& rParent, + const WorksheetHelper& rHelper, + sal_Int32 nElement, + const AttributeList& rAttribs, + const ::oox::drawingml::ShapePtr& rxParentShape, + ::oox::drawingml::ShapePtr* pxShape = 0 ); + +protected: + virtual ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastContextHandler > SAL_CALL + createFastChildContext( + sal_Int32 nElement, + const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastAttributeList >& rxAttribs ) + throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException); +}; + +// ============================================================================ + +/** Fragment handler for a complete sheet drawing. */ +class DrawingFragment : public WorksheetFragmentBase +{ +public: + explicit DrawingFragment( + const WorksheetHelper& rHelper, + const ::rtl::OUString& rFragmentPath ); + +protected: + virtual ::oox::core::ContextHandlerRef onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ); + virtual void onCharacters( const ::rtl::OUString& rChars ); + virtual void onEndElement(); + +private: + ::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. +}; + +// ============================================================================ +// VML +// ============================================================================ + +class VmlControlMacroAttacher : public ::oox::ole::VbaMacroAttacherBase +{ +public: + explicit VmlControlMacroAttacher( const ::rtl::OUString& rMacroName, + const ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexContainer >& rxCtrlFormIC, + sal_Int32 nCtrlIndex, sal_Int32 nCtrlType, sal_Int32 nDropStyle ); + +private: + virtual void attachMacro( const ::rtl::OUString& rMacroUrl ); + +private: + ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexContainer > mxCtrlFormIC; + sal_Int32 mnCtrlIndex; + sal_Int32 mnCtrlType; + sal_Int32 mnDropStyle; +}; + +// ============================================================================ + +class VmlDrawing : public ::oox::vml::Drawing, public WorksheetHelper +{ +public: + explicit VmlDrawing( const WorksheetHelper& rHelper ); + + /** Returns the drawing shape for a cell note at the specified position. */ + const ::oox::vml::ShapeBase* getNoteShape( const ::com::sun::star::table::CellAddress& rPos ) const; + + /** Filters cell note shapes. */ + virtual bool isShapeSupported( const ::oox::vml::ShapeBase& rShape ) const; + + /** Returns additional base names for automatic shape name creation. */ + virtual ::rtl::OUString getShapeBaseName( const ::oox::vml::ShapeBase& rShape ) const; + + /** Calculates the shape rectangle from a cell anchor string. */ + virtual bool convertClientAnchor( + ::com::sun::star::awt::Rectangle& orShapeRect, + const ::rtl::OUString& rShapeAnchor ) const; + + /** Creates a UNO control shape for legacy drawing controls. */ + virtual ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape > + createAndInsertClientXShape( + const ::oox::vml::ShapeBase& rShape, + const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShapes >& rxShapes, + const ::com::sun::star::awt::Rectangle& rShapeRect ) const; + + /** Updates the bounding box covering all shapes of this drawing. */ + virtual void notifyXShapeInserted( + const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape >& rxShape, + const ::com::sun::star::awt::Rectangle& rShapeRect, + const ::oox::vml::ShapeBase& rShape, bool bGroupChild ); + +private: + /** Converts the passed VML textbox text color to an OLE color. */ + sal_uInt32 convertControlTextColor( const ::rtl::OUString& rTextColor ) const; + /** Converts the passed VML textbox font to an ActiveX form control font. */ + void convertControlFontData( + ::oox::ole::AxFontData& rAxFontData, sal_uInt32& rnOleTextColor, + const ::oox::vml::TextFontModel& rFontModel ) const; + /** Converts the caption, the font settings, and the horizontal alignment + from the passed VML textbox to ActiveX form control settings. */ + void convertControlText( + ::oox::ole::AxFontData& rAxFontData, sal_uInt32& rnOleTextColor, ::rtl::OUString& rCaption, + const ::oox::vml::TextBox* pTextBox, sal_Int32 nTextHAlign ) const; + /** Converts the passed VML shape background formatting to ActiveX control formatting. */ + void convertControlBackground( + ::oox::ole::AxMorphDataModelBase& rAxModel, + const ::oox::vml::ShapeBase& rShape ) const; + +private: + ::oox::ole::ControlConverter maControlConv; + ::oox::vml::TextFontModel maListBoxFont; +}; + +// ============================================================================ + +class VmlDrawingFragment : public ::oox::vml::DrawingFragment, public WorksheetHelper +{ +public: + explicit VmlDrawingFragment( + const WorksheetHelper& rHelper, + const ::rtl::OUString& rFragmentPath ); + +protected: + virtual void finalizeImport(); +}; + +// ============================================================================ + +} // namespace xls +} // namespace oox + +#endif diff --git a/oox/inc/oox/xls/excelchartconverter.hxx b/oox/inc/oox/xls/excelchartconverter.hxx new file mode 100644 index 000000000000..a46d484f2074 --- /dev/null +++ b/oox/inc/oox/xls/excelchartconverter.hxx @@ -0,0 +1,61 @@ +/************************************************************************* + * + * 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_EXCELCHARTCONVERTER_HXX +#define OOX_XLS_EXCELCHARTCONVERTER_HXX + +#include "oox/drawingml/chart/chartconverter.hxx" +#include "oox/xls/workbookhelper.hxx" + +namespace oox { +namespace xls { + +// ============================================================================ + +class ExcelChartConverter : public ::oox::drawingml::chart::ChartConverter, public WorkbookHelper +{ +public: + explicit ExcelChartConverter( const WorkbookHelper& rHelper ); + virtual ~ExcelChartConverter(); + + /** Creates an external data provider that is able to use spreadsheet data. */ + virtual void createDataProvider( + const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XChartDocument >& rxChartDoc ); + + /** Creates a data sequence from the passed formula. */ + virtual ::com::sun::star::uno::Reference< ::com::sun::star::chart2::data::XDataSequence > + createDataSequence( + const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::data::XDataProvider >& rxDataProvider, + const ::oox::drawingml::chart::DataSequenceModel& rDataSeq ); +}; + +// ============================================================================ + +} // namespace xls +} // namespace oox + +#endif diff --git a/oox/inc/oox/xls/excelfilter.hxx b/oox/inc/oox/xls/excelfilter.hxx new file mode 100644 index 000000000000..789cbc99cb07 --- /dev/null +++ b/oox/inc/oox/xls/excelfilter.hxx @@ -0,0 +1,119 @@ +/************************************************************************* + * + * 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_EXCELFILTER_HXX +#define OOX_XLS_EXCELFILTER_HXX + +#include "oox/core/binaryfilterbase.hxx" +#include "oox/core/xmlfilterbase.hxx" + +namespace oox { +namespace xls { + +class WorkbookData; + +// ============================================================================ + +class ExcelFilterBase +{ +public: + void registerWorkbookData( WorkbookData& rData ); + WorkbookData& getWorkbookData() const; + void unregisterWorkbookData(); + +protected: + explicit ExcelFilterBase(); + virtual ~ExcelFilterBase(); + +private: + WorkbookData* mpData; +}; + +// ============================================================================ + +class ExcelFilter : public ::oox::core::XmlFilterBase, public ExcelFilterBase +{ +public: + explicit ExcelFilter( + const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext ) + throw( ::com::sun::star::uno::RuntimeException ); + virtual ~ExcelFilter(); + + virtual bool importDocument() throw(); + virtual bool exportDocument() throw(); + + virtual const ::oox::drawingml::Theme* getCurrentTheme() const; + virtual ::oox::vml::Drawing* getVmlDrawing(); + virtual const ::oox::drawingml::table::TableStyleListPtr getTableStyles(); + virtual ::oox::drawingml::chart::ChartConverter& getChartConverter(); + +private: + virtual GraphicHelper* implCreateGraphicHelper() const; + virtual ::oox::ole::VbaProject* implCreateVbaProject() const; + virtual ::rtl::OUString implGetImplementationName() const; +}; + +// ============================================================================ + +class ExcelBiffFilter : public ::oox::core::BinaryFilterBase, public ExcelFilterBase +{ +public: + explicit ExcelBiffFilter( + const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext ) + throw( ::com::sun::star::uno::RuntimeException ); + virtual ~ExcelBiffFilter(); + + virtual bool importDocument() throw(); + virtual bool exportDocument() throw(); + +private: + virtual GraphicHelper* implCreateGraphicHelper() const; + virtual ::oox::ole::VbaProject* implCreateVbaProject() const; + virtual ::rtl::OUString implGetImplementationName() const; +}; + +// ============================================================================ + +class ExcelVbaProjectFilter : public ExcelBiffFilter +{ +public: + explicit ExcelVbaProjectFilter( + const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext ) + throw( ::com::sun::star::uno::RuntimeException ); + + virtual bool importDocument() throw(); + virtual bool exportDocument() throw(); + +private: + virtual ::rtl::OUString implGetImplementationName() const; +}; + // ============================================================================ + +} // namespace xls +} // namespace oox + +#endif diff --git a/oox/inc/oox/xls/excelhandlers.hxx b/oox/inc/oox/xls/excelhandlers.hxx new file mode 100644 index 000000000000..864f5f9a9e44 --- /dev/null +++ b/oox/inc/oox/xls/excelhandlers.hxx @@ -0,0 +1,307 @@ +/************************************************************************* + * + * 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_EXCELHANDLERS_HXX +#define OOX_XLS_EXCELHANDLERS_HXX + +#include "oox/core/fragmenthandler2.hxx" +#include "oox/xls/worksheethelper.hxx" + +namespace oox { +namespace xls { + +// ============================================================================ +// ============================================================================ + +/** Context handler derived from the WorkbookHelper helper class. + + Used to import contexts in global workbook fragments. + */ +class WorkbookContextBase : public ::oox::core::ContextHandler2, public WorkbookHelper +{ +public: + template< typename ParentType > + explicit WorkbookContextBase( ParentType& 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 +{ +public: + template< typename ParentType > + explicit WorksheetContextBase( + ParentType& rParent, + const ISegmentProgressBarRef& rxProgressBar, + WorksheetType eSheetType, + sal_Int16 nSheet ); + + template< typename ParentType > + explicit WorksheetContextBase( ParentType& 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. + + Used to import global workbook fragments. + */ +class WorkbookFragmentBase : public ::oox::core::FragmentHandler2, public WorkbookHelper +{ +public: + explicit WorkbookFragmentBase( + const WorkbookHelper& rHelper, + const ::rtl::OUString& rFragmentPath ); +}; + +// ============================================================================ + +/** Fragment handler derived from the WorksheetHelper helper class. + + Used to import sheet fragments. + */ +class WorksheetFragmentBase : public ::oox::core::FragmentHandler2, public WorksheetHelperRoot +{ +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 ); +}; + +// ============================================================================ +// ============================================================================ + +/** Base class for all BIFF context handlers. + + Derived handlers have to implement the importRecord() function that has to + import the record the passed BIFF input stream currently points to. + */ +class BiffContextHandler +{ +public: + virtual ~BiffContextHandler(); + + /** Derived classes have to implement importing the current record. */ + virtual void importRecord( BiffInputStream& rStrm ) = 0; +}; + +// ---------------------------------------------------------------------------- + +/** Context handler derived from the WorkbookHelper helper class. + + Used to import contexts in global workbook fragments. + */ +class BiffWorkbookContextBase : public BiffContextHandler, public WorkbookHelper +{ +protected: + explicit BiffWorkbookContextBase( const WorkbookHelper& rHelper ); +}; + +// ---------------------------------------------------------------------------- + +/** Context handler derived from the WorksheetHelper helper class. + + Used to import contexts in sheet fragments. + */ +class BiffWorksheetContextBase : public BiffContextHandler, public WorksheetHelperRoot +{ +protected: + explicit BiffWorksheetContextBase( + const WorkbookHelper& rHelper, + const ISegmentProgressBarRef& rxProgressBar, + WorksheetType eSheetType, + sal_Int16 nSheet ); + + explicit BiffWorksheetContextBase( const WorksheetHelper& rHelper ); +}; + +// ============================================================================ + +/** An enumeration for all types of fragments in a BIFF workbook stream. */ +enum BiffFragmentType +{ + BIFF_FRAGMENT_GLOBALS, /// Workbook globals fragment. + BIFF_FRAGMENT_WORKSHEET, /// Worksheet fragment. + BIFF_FRAGMENT_CHARTSHEET, /// Chart sheet fragment. + BIFF_FRAGMENT_MACROSHEET, /// Macro sheet fragment. + BIFF_FRAGMENT_MODULESHEET, /// BIFF5 VB module fragment. + BIFF_FRAGMENT_EMPTYSHEET, /// Sheet fragment of unsupported type. + BIFF_FRAGMENT_WORKSPACE, /// BIFF4 workspace/workbook globals. + BIFF_FRAGMENT_UNKNOWN /// Unknown fragment/error. +}; + +// ---------------------------------------------------------------------------- + +class BiffFragmentHandler +{ +public: + /** Opens the stream with the passed full name. */ + explicit BiffFragmentHandler( + const ::oox::core::FilterBase& rFilter, + const ::rtl::OUString& rStrmName ); + + virtual ~BiffFragmentHandler(); + + /** Imports the fragment, returns true, if EOF record has been reached. */ + virtual bool importFragment() = 0; + +protected: + /** Returns the BIFF input stream of this fragment. */ + inline BiffInputStream& getInputStream() { return *mxBiffStrm; } + + /** Starts a new fragment in a workbbok stream and returns the fragment type. + + The passed stream must point before a BOF record. 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 ); + + /** 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, + stream points to the EOF record, and the next call of startNextRecord() + at the stream will start the record following the EOF record. + + Embedded fragments enclosed in BOF/EOF records (e.g. embedded chart + objects) are skipped correctly. + + @return True = stream points to the EOF record of the current fragment. + */ + bool skipFragment(); + +private: + typedef ::boost::shared_ptr< BinaryXInputStream > XInputStreamRef; + typedef ::boost::shared_ptr< BiffInputStream > BiffInputStreamRef; + + XInputStreamRef mxXInStrm; + BiffInputStreamRef mxBiffStrm; +}; + +// ---------------------------------------------------------------------------- + +/** Fragment handler derived from the WorkbookHelper helper class. + + Used to import global workbook fragments. + */ +class BiffWorkbookFragmentBase : public BiffFragmentHandler, public WorkbookHelper +{ +protected: + explicit BiffWorkbookFragmentBase( + const WorkbookHelper& rHelper, + const ::rtl::OUString& rStrmName, + bool bCloneDecoder = false ); +}; + +// ---------------------------------------------------------------------------- + +/** Fragment handler derived from the WorksheetHelper helper class. + + Used to import sheet fragments. + */ +class BiffWorksheetFragmentBase : public BiffFragmentHandler, public WorksheetHelperRoot +{ +protected: + explicit BiffWorksheetFragmentBase( + const BiffWorkbookFragmentBase& rParent, + const ISegmentProgressBarRef& rxProgressBar, + WorksheetType eSheetType, + sal_Int16 nSheet ); +}; + +// ---------------------------------------------------------------------------- + +/** Special fragment handler for worksheets that have to be skipped. + */ +class BiffSkipWorksheetFragment : public BiffWorksheetFragmentBase +{ +public: + explicit BiffSkipWorksheetFragment( + const BiffWorkbookFragmentBase& rParent, + const ISegmentProgressBarRef& rxProgressBar, + sal_Int16 nSheet ); + + virtual bool importFragment(); +}; + +// ============================================================================ +// ============================================================================ + +} // namespace xls +} // namespace oox + +#endif diff --git a/oox/inc/oox/xls/excelvbaproject.hxx b/oox/inc/oox/xls/excelvbaproject.hxx new file mode 100755 index 000000000000..96dabd08b5d7 --- /dev/null +++ b/oox/inc/oox/xls/excelvbaproject.hxx @@ -0,0 +1,65 @@ +/************************************************************************* + * + * 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_EXCELVBAPROJECT_HXX +#define OOX_XLS_EXCELVBAPROJECT_HXX + +#include "oox/ole/vbaproject.hxx" +#include "oox/dllapi.h" + +namespace com { namespace sun { namespace star { + namespace sheet { class XSpreadsheetDocument; } +} } } + +namespace oox { +namespace xls { + +// ============================================================================ + +/** Special implementation of the VBA project for the Excel filters. */ +class OOX_DLLPUBLIC ExcelVbaProject : public ::oox::ole::VbaProject +{ +public: + explicit ExcelVbaProject( + const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext, + const ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XSpreadsheetDocument >& rxDocument ); + +protected: + /** Adds dummy modules for sheets without imported code name. */ + virtual void prepareImport(); + +private: + ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XSpreadsheetDocument > + mxDocument; +}; + +// ============================================================================ + +} // namespace xls +} // namespace oox + +#endif diff --git a/oox/inc/oox/xls/externallinkbuffer.hxx b/oox/inc/oox/xls/externallinkbuffer.hxx new file mode 100644 index 000000000000..c616a2b97e97 --- /dev/null +++ b/oox/inc/oox/xls/externallinkbuffer.hxx @@ -0,0 +1,404 @@ +/************************************************************************* + * + * 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_EXTERNALLINKBUFFER_HXX +#define OOX_XLS_EXTERNALLINKBUFFER_HXX + +#include <com/sun/star/sheet/ExternalLinkInfo.hpp> +#include "oox/helper/containerhelper.hxx" +#include "oox/xls/defnamesbuffer.hxx" + +namespace com { namespace sun { namespace star { + namespace sheet { struct DDEItemInfo; } + namespace sheet { class XDDELink; } + namespace sheet { class XExternalDocLink; } + namespace sheet { class XExternalSheetCache; } +} } } + +namespace oox { namespace core { + class Relations; +} } + +namespace oox { +namespace xls { + +// ============================================================================ + +struct ExternalNameModel +{ + bool mbBuiltIn; /// Name is a built-in name. + bool mbNotify; /// Notify application on data change. + bool mbPreferPic; /// Picture link. + bool mbStdDocName; /// Name is the StdDocumentName for DDE. + bool mbOleObj; /// Name is an OLE object. + bool mbIconified; /// Iconified object link. + + explicit ExternalNameModel(); +}; + +// ============================================================================ + +class ExternalLink; + +class ExternalName : public DefinedNameBase +{ +public: + explicit ExternalName( const ExternalLink& rParentLink ); + + /** Appends the passed value to the result set. */ + template< typename Type > + inline void appendResultValue( const Type& rValue ) + { if( maCurrIt != maResults.end() ) (*maCurrIt++) <<= rValue; } + + /** Imports the definedName element. */ + void importDefinedName( const AttributeList& rAttribs ); + /** Imports the ddeItem element describing an item of a DDE link. */ + void importDdeItem( const AttributeList& rAttribs ); + /** Imports the values element containing the size of the DDE result matrix. */ + void importValues( const AttributeList& rAttribs ); + /** Imports the oleItem element describing an object of an OLE link. */ + void importOleItem( const AttributeList& rAttribs ); + + /** Imports the EXTERNALNAME record containing the name (only). */ + void importExternalName( SequenceInputStream& rStrm ); + /** Imports the EXTERNALNAMEFLAGS record containing the settings of an external name. */ + void importExternalNameFlags( SequenceInputStream& rStrm ); + /** Imports the DDEITEMVALUES record containing the size of the DDE result matrix. */ + void importDdeItemValues( SequenceInputStream& rStrm ); + /** Imports the DDEITEM_BOOL record containing a boolean value in a link result. */ + void importDdeItemBool( SequenceInputStream& rStrm ); + /** Imports the DDEITEM_DOUBLE record containing a double value in a link result. */ + void importDdeItemDouble( SequenceInputStream& rStrm ); + /** Imports the DDEITEM_ERROR record containing an error code in a link result. */ + void importDdeItemError( SequenceInputStream& rStrm ); + /** Imports the DDEITEM_STRING record containing a string in a link result. */ + void importDdeItemString( SequenceInputStream& rStrm ); + + /** Imports the EXTERNALNAME record from the passed stream. */ + void importExternalName( BiffInputStream& rStrm ); + + /** Returns true, if the name refers to an OLE object. */ + inline bool isOleObject() const { return maExtNameModel.mbOleObj; } + +#if 0 + /** Returns the sheet cache index if this is a sheet-local external name. */ + sal_Int32 getSheetCacheIndex() const; +#endif + + /** Returns the DDE item info needed by the XML formula parser. */ + bool getDdeItemInfo( + ::com::sun::star::sheet::DDEItemInfo& orItemInfo ) const; + + /** Returns the complete DDE link data of this DDE item. */ + bool getDdeLinkData( + ::rtl::OUString& orDdeServer, + ::rtl::OUString& orDdeTopic, + ::rtl::OUString& orDdeItem ); + +private: + /** Tries to convert the passed token sequence to an ExternalReference. */ + void extractExternalReference( const ApiTokenSequence& rTokens ); + /** Sets the size of the result matrix. */ + void setResultSize( sal_Int32 nColumns, sal_Int32 nRows ); + +private: + typedef Matrix< ::com::sun::star::uno::Any > ResultMatrix; + + const ExternalLink& mrParentLink; /// External link this name belongs to. + ExternalNameModel maExtNameModel; /// Additional name data. + ResultMatrix maResults; /// DDE/OLE link results. + ResultMatrix::iterator maCurrIt; /// Current position in result matrix. + sal_uInt32 mnStorageId; /// OLE storage identifier (BIFF). + ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XDDELink > + mxDdeLink; /// Interface of a DDE link. + bool mbDdeLinkCreated; /// True = already tried to create the DDE link. +}; + +typedef ::boost::shared_ptr< ExternalName > ExternalNameRef; + +// ============================================================================ + +/** Contains indexes for a range of sheets in the spreadsheet document. */ +class LinkSheetRange +{ +public: + inline explicit LinkSheetRange() { setDeleted(); } + inline explicit LinkSheetRange( sal_Int32 nFirst, sal_Int32 nLast ) { setRange( nFirst, nLast ); } + inline explicit LinkSheetRange( sal_Int32 nDocLink, sal_Int32 nFirst, sal_Int32 nLast ) { setExternalRange( nDocLink, nFirst, nLast ); } + + /** Sets this struct to deleted state. */ + void setDeleted(); + /** Sets this struct to "use current sheet" state. */ + void setSameSheet(); + /** Sets the passed absolute sheet range to the members of this struct. */ + void setRange( sal_Int32 nFirst, sal_Int32 nLast ); + /** Sets the passed external sheet cache range to the members of this struct. */ + void setExternalRange( sal_Int32 nDocLink, sal_Int32 nFirst, sal_Int32 nLast ); + + /** Returns true, if the sheet indexes are valid and different. */ + inline bool isDeleted() const { return mnFirst < 0; } + /** Returns true, if the sheet range points to an external document. */ + inline bool isExternal() const { return !isDeleted() && (meType == LINKSHEETRANGE_EXTERNAL); } + /** Returns true, if the sheet indexes are valid and different. */ + inline bool isSameSheet() const { return meType == LINKSHEETRANGE_SAMESHEET; } + /** Returns true, if the sheet indexes are valid and different. */ + inline bool is3dRange() const { return (0 <= mnFirst) && (mnFirst < mnLast); } + + inline sal_Int32 getDocLinkIndex() const { return mnDocLink; } + inline sal_Int32 getFirstSheet() const { return mnFirst; } + inline sal_Int32 getLastSheet() const { return mnLast; } + +private: + enum LinkSheetRangeType + { + LINKSHEETRANGE_INTERNAL, /// Sheet range in the own document. + LINKSHEETRANGE_EXTERNAL, /// Sheet range in an external document. + LINKSHEETRANGE_SAMESHEET /// Current sheet depending on context. + }; + + LinkSheetRangeType meType; /// Link sheet range type. + sal_Int32 mnDocLink; /// Document link token index for external links. + sal_Int32 mnFirst; /// Index of the first sheet or index of first external sheet cache. + sal_Int32 mnLast; /// Index of the last sheet or index of last external sheet cache. +}; + +// ============================================================================ + +enum ExternalLinkType +{ + LINKTYPE_SELF, /// Link refers to the current workbook. + LINKTYPE_SAME, /// Link refers to the current sheet. + LINKTYPE_INTERNAL, /// Link refers to a sheet in the own workbook. + LINKTYPE_EXTERNAL, /// Link refers to an external spreadsheet document. + LINKTYPE_ANALYSIS, /// Link refers to the Analysis add-in. + LINKTYPE_LIBRARY, /// Link refers to an external add-in. + LINKTYPE_DDE, /// DDE link. + LINKTYPE_OLE, /// OLE link. + LINKTYPE_MAYBE_DDE_OLE, /// Could be DDE or OLE link (BIFF only). + LINKTYPE_UNKNOWN /// Unknown or unsupported link type. +}; + +// ---------------------------------------------------------------------------- + +class ExternalLink : public WorkbookHelper +{ +public: + explicit ExternalLink( const WorkbookHelper& rHelper ); + + /** Imports the externalReference element containing the relation identifier. */ + void importExternalReference( const AttributeList& rAttribs ); + /** Imports the externalBook element describing an externally linked document. */ + void importExternalBook( const ::oox::core::Relations& rRelations, const AttributeList& rAttribs ); + /** Imports the sheetName element containing the sheet name in an externally linked document. */ + void importSheetName( const AttributeList& rAttribs ); + /** Imports the definedName element describing an external name. */ + void importDefinedName( const AttributeList& rAttribs ); + /** Imports the ddeLink element describing a DDE link. */ + void importDdeLink( const AttributeList& rAttribs ); + /** Imports the ddeItem element describing an item of a DDE link. */ + ExternalNameRef importDdeItem( const AttributeList& rAttribs ); + /** Imports the oleLink element describing an OLE link. */ + void importOleLink( const ::oox::core::Relations& rRelations, const AttributeList& rAttribs ); + /** Imports the oleItem element describing an object of an OLE link. */ + ExternalNameRef importOleItem( const AttributeList& rAttribs ); + + /** Imports the EXTERNALBOOK record describing an externally linked document, DDE link, or OLE link. */ + void importExternalBook( const ::oox::core::Relations& rRelations, SequenceInputStream& rStrm ); + /** Imports the EXTSHEETNAMES record containing the sheet names in an externally linked document. */ + void importExtSheetNames( SequenceInputStream& rStrm ); + /** Imports the EXTERNALNAME record describing an external name. */ + ExternalNameRef importExternalName( SequenceInputStream& rStrm ); + /** Imports the EXTERNALREF record from the passed stream. */ + void importExternalRef( SequenceInputStream& rStrm ); + /** Imports the EXTERNALSELF record from the passed stream. */ + void importExternalSelf( SequenceInputStream& rStrm ); + /** Imports the EXTERNALSAME record from the passed stream. */ + void importExternalSame( SequenceInputStream& rStrm ); + /** Imports the EXTERNALADDIN record from the passed stream. */ + void importExternalAddin( SequenceInputStream& rStrm ); + + /** Imports the EXTERNSHEET record from the passed stream. */ + void importExternSheet( BiffInputStream& rStrm ); + /** Imports the EXTERNALBOOK record from the passed stream. */ + void importExternalBook( BiffInputStream& rStrm ); + /** Imports the EXTERNALNAME record from the passed stream. */ + void importExternalName( BiffInputStream& rStrm ); + + /** Sets the link type to 'self reference'. */ + inline void setSelfLinkType() { meLinkType = LINKTYPE_SELF; } + + /** Returns the type of this external link. */ + inline ExternalLinkType getLinkType() const { return meLinkType; } + /** Returns true, if the link refers to the current workbook. */ + inline bool isInternalLink() const { return (meLinkType == LINKTYPE_SELF) || (meLinkType == LINKTYPE_INTERNAL); } + + /** Returns the relation identifier for the external link fragment. */ + inline const ::rtl::OUString& getRelId() const { return maRelId; } + /** Returns the class name of this external link. */ + inline const ::rtl::OUString& getClassName() const { return maClassName; } + /** Returns the target URL of this external link. */ + inline const ::rtl::OUString& getTargetUrl() const { return maTargetUrl; } + /** Returns the link info needed by the XML formula parser. */ + ::com::sun::star::sheet::ExternalLinkInfo getLinkInfo() const; + + /** Returns the type of the external library if this is a library link. */ + FunctionLibraryType getFuncLibraryType() const; + + /** Returns the internal Calc sheet index or for the passed sheet. */ + sal_Int16 getCalcSheetIndex( sal_Int32 nTabId = 0 ) const; + + /** Returns the token index of the external document. */ + sal_Int32 getDocumentLinkIndex() const; + /** Returns the external sheet cache index or for the passed sheet. */ + sal_Int32 getSheetCacheIndex( sal_Int32 nTabId = 0 ) const; + /** Returns the sheet cache of the external sheet with the passed index. */ + ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XExternalSheetCache > + getSheetCache( sal_Int32 nTabId ) const; + + /** Returns the internal sheet range or range of external sheet caches for the passed sheet range (BIFF only). */ + void getSheetRange( LinkSheetRange& orSheetRange, sal_Int32 nTabId1, sal_Int32 nTabId2 ) const; + + /** Returns the external name with the passed zero-based index. */ + ExternalNameRef getNameByIndex( sal_Int32 nIndex ) const; + +private: + void setExternalTargetUrl( const ::rtl::OUString& rTargetUrl, const ::rtl::OUString& rTargetType ); + void setDdeOleTargetUrl( const ::rtl::OUString& rClassName, const ::rtl::OUString& rTargetUrl, ExternalLinkType eLinkType ); + void parseExternalReference( const ::oox::core::Relations& rRelations, const ::rtl::OUString& rRelId ); + ::rtl::OUString parseBiffTargetUrl( const ::rtl::OUString& rBiffTargetUrl ); + + /** Creates an external locument link and the sheet cache for the passed sheet name. */ + void insertExternalSheet( const ::rtl::OUString& rSheetName ); + + ExternalNameRef createExternalName(); + +private: + typedef ::std::vector< sal_Int16 > Int16Vector; + typedef ::std::vector< sal_Int32 > Int32Vector; + typedef RefVector< ExternalName > ExternalNameVector; + + ExternalLinkType meLinkType; /// Type of this link object. + FunctionLibraryType meFuncLibType; /// Type of the function library, if link type is LINKTYPE_LIBRARY. + ::rtl::OUString maRelId; /// Relation identifier for the external link fragment. + ::rtl::OUString maClassName; /// DDE service, OLE class name. + ::rtl::OUString maTargetUrl; /// Target link, DDE topic, OLE target. + ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XExternalDocLink > + mxDocLink; /// Interface for an external document. + Int16Vector maCalcSheets; /// Internal sheet indexes. + Int32Vector maSheetCaches; /// External sheet cache indexes. + ExternalNameVector maExtNames; /// Defined names in external document. +}; + +typedef ::boost::shared_ptr< ExternalLink > ExternalLinkRef; + +// ============================================================================ + +/** Represents a REF entry in the BIFF12 EXTERNALSHEETS or in the BIFF8 + EXTERNSHEET record. + + This struct is used to map ref identifiers to external books (BIFF12: + EXTERNALREF records, BIFF8: EXTERNALBOOK records), and provides sheet + indexes into the sheet list of the external document. + */ +struct RefSheetsModel +{ + sal_Int32 mnExtRefId; /// Zero-based index into list of external documents. + sal_Int32 mnTabId1; /// Zero-based index to first sheet in external document. + sal_Int32 mnTabId2; /// Zero-based index to last sheet in external document. + + explicit RefSheetsModel(); + + void readBiff12Data( SequenceInputStream& rStrm ); + void readBiff8Data( BiffInputStream& rStrm ); +}; + +// ---------------------------------------------------------------------------- + +class ExternalLinkBuffer : public WorkbookHelper +{ +public: + explicit ExternalLinkBuffer( const WorkbookHelper& rHelper ); + + /** Imports the externalReference element containing . */ + ExternalLinkRef importExternalReference( const AttributeList& rAttribs ); + + /** Imports the EXTERNALREF record from the passed stream. */ + ExternalLinkRef importExternalRef( SequenceInputStream& rStrm ); + /** Imports the EXTERNALSELF record from the passed stream. */ + void importExternalSelf( SequenceInputStream& rStrm ); + /** Imports the EXTERNALSAME record from the passed stream. */ + void importExternalSame( SequenceInputStream& rStrm ); + /** Imports the EXTERNALADDIN record from the passed stream. */ + void importExternalAddin( SequenceInputStream& rStrm ); + /** Imports the EXTERNALSHEETS record from the passed stream. */ + void importExternalSheets( SequenceInputStream& rStrm ); + + /** Imports the EXTERNSHEET record from the passed stream. */ + ExternalLinkRef importExternSheet( BiffInputStream& rStrm ); + /** Imports the EXTERNALBOOK record from the passed stream. */ + ExternalLinkRef importExternalBook( BiffInputStream& rStrm ); + /** Imports the EXTERNALNAME record from the passed stream. */ + void importExternalName( BiffInputStream& rStrm ); + /** Imports the BIFF8 EXTERNSHEET record from the passed stream. */ + void importExternSheet8( BiffInputStream& rStrm ); + + /** Returns the sequence of link infos needed by the XML formula parser. */ + ::com::sun::star::uno::Sequence< ::com::sun::star::sheet::ExternalLinkInfo > + getLinkInfos() const; + + /** Returns the external link for the passed reference identifier. */ + ExternalLinkRef getExternalLink( sal_Int32 nRefId, bool bUseRefSheets = true ) const; + + /** Returns the sheet range for the specified reference (BIFF2-BIFF5 only). */ + LinkSheetRange getSheetRange( sal_Int32 nRefId, sal_Int16 nTabId1, sal_Int16 nTabId2 ) const; + /** Returns the sheet range for the specified reference (BIFF8 only). */ + LinkSheetRange getSheetRange( sal_Int32 nRefId ) const; + +private: + /** Creates a new external link and inserts it into the list of links. */ + ExternalLinkRef createExternalLink(); + + /** Returns the specified sheet indexes for a reference identifier. */ + const RefSheetsModel* getRefSheets( sal_Int32 nRefId ) const; + +private: + typedef RefVector< ExternalLink > ExternalLinkVec; + typedef ::std::vector< RefSheetsModel > RefSheetsModelVec; + + ExternalLinkRef mxSelfRef; /// Implicit self reference at index 0. + ExternalLinkVec maLinks; /// List of link structures for all kinds of links. + ExternalLinkVec maExtLinks; /// Real external links needed for formula parser. + RefSheetsModelVec maRefSheets; /// Sheet indexes for reference ids. + bool mbUseRefSheets; /// True = use maRefSheets list (BIFF12 only). +}; + +// ============================================================================ + +} // namespace xls +} // namespace oox + +#endif diff --git a/oox/inc/oox/xls/externallinkfragment.hxx b/oox/inc/oox/xls/externallinkfragment.hxx new file mode 100644 index 000000000000..0e1f293d2444 --- /dev/null +++ b/oox/inc/oox/xls/externallinkfragment.hxx @@ -0,0 +1,161 @@ +/************************************************************************* + * + * 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_EXTERNALLINKFRAGMENT_HXX +#define OOX_XLS_EXTERNALLINKFRAGMENT_HXX + +#include "oox/xls/excelhandlers.hxx" +#include "oox/xls/externallinkbuffer.hxx" + +namespace oox { +namespace xls { + +class ExternalLink; + +// ============================================================================ +// ============================================================================ + +/** This class implements importing the sheetData element in external sheets. + + The sheetData element embedded in the externalBook element contains cached + cells from externally linked sheets. + */ +class ExternalSheetDataContext : public WorkbookContextBase +{ +public: + explicit ExternalSheetDataContext( + WorkbookFragmentBase& rFragment, + const ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XExternalSheetCache >& rxSheetCache ); + +protected: + virtual ::oox::core::ContextHandlerRef onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ); + virtual void onCharacters( const ::rtl::OUString& rChars ); + + virtual ::oox::core::ContextHandlerRef onCreateRecordContext( sal_Int32 nRecId, SequenceInputStream& rStrm ); + +private: + /** Imports cell settings from a c element. */ + void importCell( const AttributeList& rAttribs ); + + /** Imports the EXTCELL_BLANK from the passed stream. */ + void importExtCellBlank( SequenceInputStream& rStrm ); + /** Imports the EXTCELL_BOOL from the passed stream. */ + void importExtCellBool( SequenceInputStream& rStrm ); + /** Imports the EXTCELL_DOUBLE from the passed stream. */ + void importExtCellDouble( SequenceInputStream& rStrm ); + /** Imports the EXTCELL_ERROR from the passed stream. */ + void importExtCellError( SequenceInputStream& rStrm ); + /** Imports the EXTCELL_STRING from the passed stream. */ + void importExtCellString( SequenceInputStream& rStrm ); + + /** Sets the passed cell value to the current position in the sheet cache. */ + void setCellValue( const ::com::sun::star::uno::Any& rValue ); + +private: + ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XExternalSheetCache > + mxSheetCache; /// The sheet cache used to store external cell values. + ::com::sun::star::table::CellAddress maCurrPos; /// Position of current cell. + sal_Int32 mnCurrType; /// Data type of current cell. +}; + +// ============================================================================ + +class ExternalLinkFragment : public WorkbookFragmentBase +{ +public: + explicit ExternalLinkFragment( + const WorkbookHelper& rHelper, + const ::rtl::OUString& rFragmentPath, + ExternalLink& rExtLink ); + +protected: + virtual ::oox::core::ContextHandlerRef onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ); + virtual void onCharacters( const ::rtl::OUString& rChars ); + virtual void onEndElement(); + + virtual ::oox::core::ContextHandlerRef onCreateRecordContext( sal_Int32 nRecId, SequenceInputStream& rStrm ); + + virtual const ::oox::core::RecordInfo* getRecordInfos() const; + +private: + ::oox::core::ContextHandlerRef createSheetDataContext( sal_Int32 nSheetId ); + +private: + ExternalLink& mrExtLink; + ExternalNameRef mxExtName; + ::rtl::OUString maResultValue; + sal_Int32 mnResultType; +}; + +// ============================================================================ +// ============================================================================ + +class BiffExternalSheetDataContext : public BiffWorkbookContextBase +{ +public: + explicit BiffExternalSheetDataContext( const WorkbookHelper& rHelper, bool bImportDefNames ); + virtual ~BiffExternalSheetDataContext(); + + /** Tries to import a record related to external links and defined names. */ + virtual void importRecord( BiffInputStream& rStrm ); + +private: + void importExternSheet( BiffInputStream& rStrm ); + void importExternalBook( BiffInputStream& rStrm ); + void importExternalName( BiffInputStream& rStrm ); + void importXct( BiffInputStream& rStrm ); + void importCrn( BiffInputStream& rStrm ); + void importDefinedName( BiffInputStream& rStrm ); + + /** Sets the passed cell value to the passed position in the sheet cache. */ + void setCellValue( const BinAddress& rBinAddr, const ::com::sun::star::uno::Any& rValue ); + +private: + ExternalLinkRef mxExtLink; /// Current external link. + ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XExternalSheetCache > + mxSheetCache; /// The sheet cache used to store external cell values. + bool mbImportDefNames; +}; + +// ============================================================================ + +class BiffExternalLinkFragment : public BiffWorkbookFragmentBase +{ +public: + explicit BiffExternalLinkFragment( const BiffWorkbookFragmentBase& rParent ); + + /** Imports all records related to external links. */ + virtual bool importFragment(); +}; + +// ============================================================================ +// ============================================================================ + +} // namespace xls +} // namespace oox + +#endif diff --git a/oox/inc/oox/xls/formulabase.hxx b/oox/inc/oox/xls/formulabase.hxx new file mode 100644 index 000000000000..013e63f3bf30 --- /dev/null +++ b/oox/inc/oox/xls/formulabase.hxx @@ -0,0 +1,924 @@ +/************************************************************************* + * + * 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_FORMULABASE_HXX +#define OOX_XLS_FORMULABASE_HXX + +#include <com/sun/star/sheet/FormulaOpCodeMapEntry.hpp> +#include <com/sun/star/sheet/FormulaToken.hpp> +#include <com/sun/star/table/CellAddress.hpp> +#include <com/sun/star/table/CellRangeAddress.hpp> +#include <com/sun/star/uno/Sequence.hxx> +#include "oox/helper/propertyset.hxx" +#include "oox/helper/refvector.hxx" +#include "oox/xls/addressconverter.hxx" + +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; } + +namespace oox { +namespace xls { + +// Constants ================================================================== + +const size_t BIFF_TOKARR_MAXLEN = 4096; /// Maximum size of a token array. + +// token class flags ---------------------------------------------------------- + +const sal_uInt8 BIFF_TOKCLASS_MASK = 0x60; +const sal_uInt8 BIFF_TOKCLASS_NONE = 0x00; /// 00-1F: Base tokens. +const sal_uInt8 BIFF_TOKCLASS_REF = 0x20; /// 20-3F: Reference class tokens. +const sal_uInt8 BIFF_TOKCLASS_VAL = 0x40; /// 40-5F: Value class tokens. +const sal_uInt8 BIFF_TOKCLASS_ARR = 0x60; /// 60-7F: Array class tokens. + +const sal_uInt8 BIFF_TOKFLAG_INVALID = 0x80; /// This bit must be null for a valid token identifier. + +// base token identifiers ----------------------------------------------------- + +const sal_uInt8 BIFF_TOKID_MASK = 0x1F; + +const sal_uInt8 BIFF_TOKID_NONE = 0x00; /// Placeholder for invalid token id. +const sal_uInt8 BIFF_TOKID_EXP = 0x01; /// Array or shared formula reference. +const sal_uInt8 BIFF_TOKID_TBL = 0x02; /// Multiple operation reference. +const sal_uInt8 BIFF_TOKID_ADD = 0x03; /// Addition operator. +const sal_uInt8 BIFF_TOKID_SUB = 0x04; /// Subtraction operator. +const sal_uInt8 BIFF_TOKID_MUL = 0x05; /// Multiplication operator. +const sal_uInt8 BIFF_TOKID_DIV = 0x06; /// Division operator. +const sal_uInt8 BIFF_TOKID_POWER = 0x07; /// Power operator. +const sal_uInt8 BIFF_TOKID_CONCAT = 0x08; /// String concatenation operator. +const sal_uInt8 BIFF_TOKID_LT = 0x09; /// Less than operator. +const sal_uInt8 BIFF_TOKID_LE = 0x0A; /// Less than or equal operator. +const sal_uInt8 BIFF_TOKID_EQ = 0x0B; /// Equal operator. +const sal_uInt8 BIFF_TOKID_GE = 0x0C; /// Greater than or equal operator. +const sal_uInt8 BIFF_TOKID_GT = 0x0D; /// Greater than operator. +const sal_uInt8 BIFF_TOKID_NE = 0x0E; /// Not equal operator. +const sal_uInt8 BIFF_TOKID_ISECT = 0x0F; /// Intersection operator. +const sal_uInt8 BIFF_TOKID_LIST = 0x10; /// List operator. +const sal_uInt8 BIFF_TOKID_RANGE = 0x11; /// Range operator. +const sal_uInt8 BIFF_TOKID_UPLUS = 0x12; /// Unary plus. +const sal_uInt8 BIFF_TOKID_UMINUS = 0x13; /// Unary minus. +const sal_uInt8 BIFF_TOKID_PERCENT = 0x14; /// Percent sign. +const sal_uInt8 BIFF_TOKID_PAREN = 0x15; /// Parentheses. +const sal_uInt8 BIFF_TOKID_MISSARG = 0x16; /// Missing argument. +const sal_uInt8 BIFF_TOKID_STR = 0x17; /// String constant. +const sal_uInt8 BIFF_TOKID_NLR = 0x18; /// Natural language reference (NLR). +const sal_uInt8 BIFF_TOKID_ATTR = 0x19; /// Special attribute. +const sal_uInt8 BIFF_TOKID_SHEET = 0x1A; /// Start of a sheet reference (BIFF2-BIFF4). +const sal_uInt8 BIFF_TOKID_ENDSHEET = 0x1B; /// End of a sheet reference (BIFF2-BIFF4). +const sal_uInt8 BIFF_TOKID_ERR = 0x1C; /// Error constant. +const sal_uInt8 BIFF_TOKID_BOOL = 0x1D; /// Boolean constant. +const sal_uInt8 BIFF_TOKID_INT = 0x1E; /// Integer constant. +const sal_uInt8 BIFF_TOKID_NUM = 0x1F; /// Floating-point constant. + +// base identifiers of classified tokens -------------------------------------- + +const sal_uInt8 BIFF_TOKID_ARRAY = 0x00; /// Array constant. +const sal_uInt8 BIFF_TOKID_FUNC = 0x01; /// Function, fixed number of arguments. +const sal_uInt8 BIFF_TOKID_FUNCVAR = 0x02; /// Function, variable number of arguments. +const sal_uInt8 BIFF_TOKID_NAME = 0x03; /// Defined name. +const sal_uInt8 BIFF_TOKID_REF = 0x04; /// 2D cell reference. +const sal_uInt8 BIFF_TOKID_AREA = 0x05; /// 2D area reference. +const sal_uInt8 BIFF_TOKID_MEMAREA = 0x06; /// Constant reference subexpression. +const sal_uInt8 BIFF_TOKID_MEMERR = 0x07; /// Deleted reference subexpression. +const sal_uInt8 BIFF_TOKID_MEMNOMEM = 0x08; /// Constant reference subexpression without result. +const sal_uInt8 BIFF_TOKID_MEMFUNC = 0x09; /// Variable reference subexpression. +const sal_uInt8 BIFF_TOKID_REFERR = 0x0A; /// Deleted 2D cell reference. +const sal_uInt8 BIFF_TOKID_AREAERR = 0x0B; /// Deleted 2D area reference. +const sal_uInt8 BIFF_TOKID_REFN = 0x0C; /// Relative 2D cell reference (in names). +const sal_uInt8 BIFF_TOKID_AREAN = 0x0D; /// Relative 2D area reference (in names). +const sal_uInt8 BIFF_TOKID_MEMAREAN = 0x0E; /// Reference subexpression (in names). +const sal_uInt8 BIFF_TOKID_MEMNOMEMN = 0x0F; /// Reference subexpression (in names) without result. +const sal_uInt8 BIFF_TOKID_FUNCCE = 0x18; +const sal_uInt8 BIFF_TOKID_NAMEX = 0x19; /// External reference. +const sal_uInt8 BIFF_TOKID_REF3D = 0x1A; /// 3D cell reference. +const sal_uInt8 BIFF_TOKID_AREA3D = 0x1B; /// 3D area reference. +const sal_uInt8 BIFF_TOKID_REFERR3D = 0x1C; /// Deleted 3D cell reference. +const sal_uInt8 BIFF_TOKID_AREAERR3D = 0x1D; /// Deleted 3D area reference + +// specific token constants --------------------------------------------------- + +const sal_uInt8 BIFF_TOK_ARRAY_DOUBLE = 0; /// Double value in an array. +const sal_uInt8 BIFF_TOK_ARRAY_STRING = 1; /// String value in an array. +const sal_uInt8 BIFF_TOK_ARRAY_BOOL = 2; /// Boolean value in an array. +const sal_uInt8 BIFF_TOK_ARRAY_ERROR = 4; /// Error code in an array. + +const sal_uInt8 BIFF_TOK_BOOL_FALSE = 0; /// FALSE value of a tBool token. +const sal_uInt8 BIFF_TOK_BOOL_TRUE = 1; /// TRUE value of a tBool token. + +const sal_uInt8 BIFF_TOK_ATTR_VOLATILE = 0x01; /// Volatile function. +const sal_uInt8 BIFF_TOK_ATTR_IF = 0x02; /// Start of true condition in IF function. +const sal_uInt8 BIFF_TOK_ATTR_CHOOSE = 0x04; /// Jump array of CHOOSE function. +const sal_uInt8 BIFF_TOK_ATTR_SKIP = 0x08; /// Skip tokens. +const sal_uInt8 BIFF_TOK_ATTR_SUM = 0x10; /// SUM function with one parameter. +const sal_uInt8 BIFF_TOK_ATTR_ASSIGN = 0x20; /// BASIC style assignment. +const sal_uInt8 BIFF_TOK_ATTR_SPACE = 0x40; /// Spaces in formula representation. +const sal_uInt8 BIFF_TOK_ATTR_SPACE_VOLATILE = 0x41; /// Leading spaces and volatile formula. +const sal_uInt8 BIFF_TOK_ATTR_IFERROR = 0x80; /// Start of condition in IFERROR function (BIFF12 only). + +const sal_uInt8 BIFF_TOK_ATTR_SPACE_SP = 0x00; /// Spaces before next token. +const sal_uInt8 BIFF_TOK_ATTR_SPACE_BR = 0x01; /// Line breaks before next token. +const sal_uInt8 BIFF_TOK_ATTR_SPACE_SP_OPEN = 0x02; /// Spaces before opening parenthesis. +const sal_uInt8 BIFF_TOK_ATTR_SPACE_BR_OPEN = 0x03; /// Line breaks before opening parenthesis. +const sal_uInt8 BIFF_TOK_ATTR_SPACE_SP_CLOSE = 0x04; /// Spaces before closing parenthesis. +const sal_uInt8 BIFF_TOK_ATTR_SPACE_BR_CLOSE = 0x05; /// Line breaks before closing parenthesis. +const sal_uInt8 BIFF_TOK_ATTR_SPACE_SP_PRE = 0x06; /// Spaces before formula (BIFF3). + +const sal_uInt16 BIFF_TOK_FUNCVAR_CMD = 0x8000; /// Macro command. +const sal_uInt16 BIFF_TOK_FUNCVAR_FUNCIDMASK = 0x7FFF; /// Mask for function/command index. +const sal_uInt8 BIFF_TOK_FUNCVAR_CMDPROMPT = 0x80; /// User prompt for macro commands. +const sal_uInt8 BIFF_TOK_FUNCVAR_COUNTMASK = 0x7F; /// Mask for parameter count. + +const sal_uInt16 BIFF12_TOK_REF_COLMASK = 0x3FFF; /// Mask to extract column from reference (BIFF12). +const sal_Int32 BIFF12_TOK_REF_ROWMASK = 0xFFFFF; /// Mask to extract row from reference (BIFF12). +const sal_uInt16 BIFF12_TOK_REF_COLREL = 0x4000; /// True = column is relative (BIFF12). +const sal_uInt16 BIFF12_TOK_REF_ROWREL = 0x8000; /// True = row is relative (BIFF12). + +const sal_uInt16 BIFF_TOK_REF_COLMASK = 0x00FF; /// Mask to extract BIFF8 column from reference. +const sal_uInt16 BIFF_TOK_REF_ROWMASK = 0x3FFF; /// Mask to extract BIFF2-BIFF5 row from reference. +const sal_uInt16 BIFF_TOK_REF_COLREL = 0x4000; /// True = column is relative. +const sal_uInt16 BIFF_TOK_REF_ROWREL = 0x8000; /// True = row is relative. + +const sal_uInt16 BIFF12_TOK_TABLE_COLUMN = 0x0001; /// Table reference: Single column. +const sal_uInt16 BIFF12_TOK_TABLE_COLRANGE = 0x0002; /// Table reference: Range of columns. +const sal_uInt16 BIFF12_TOK_TABLE_ALL = 0x0004; /// Table reference: Special [#All] range. +const sal_uInt16 BIFF12_TOK_TABLE_HEADERS = 0x0008; /// Table reference: Special [#Headers] range. +const sal_uInt16 BIFF12_TOK_TABLE_DATA = 0x0010; /// Table reference: Special [#Data] range. +const sal_uInt16 BIFF12_TOK_TABLE_TOTALS = 0x0020; /// Table reference: Special [#Totals] range. +const sal_uInt16 BIFF12_TOK_TABLE_THISROW = 0x0040; /// Table reference: Special [#This Row] range. +const sal_uInt16 BIFF12_TOK_TABLE_SP_BRACKETS = 0x0080; /// Table reference: Spaces in outer brackets. +const sal_uInt16 BIFF12_TOK_TABLE_SP_SEP = 0x0100; /// Table reference: Spaces after separators. +const sal_uInt16 BIFF12_TOK_TABLE_ROW = 0x0200; /// Table reference: Single row. +const sal_uInt16 BIFF12_TOK_TABLE_CELL = 0x0400; /// Table reference: Single cell. + +const sal_uInt8 BIFF_TOK_NLR_ERR = 0x01; /// NLR: Invalid/deleted. +const sal_uInt8 BIFF_TOK_NLR_ROWR = 0x02; /// NLR: Row index. +const sal_uInt8 BIFF_TOK_NLR_COLR = 0x03; /// NLR: Column index. +const sal_uInt8 BIFF_TOK_NLR_ROWV = 0x06; /// NLR: Value in row. +const sal_uInt8 BIFF_TOK_NLR_COLV = 0x07; /// NLR: Value in column. +const sal_uInt8 BIFF_TOK_NLR_RANGE = 0x0A; /// NLR: Range. +const sal_uInt8 BIFF_TOK_NLR_SRANGE = 0x0B; /// Stacked NLR: Range. +const sal_uInt8 BIFF_TOK_NLR_SROWR = 0x0C; /// Stacked NLR: Row index. +const sal_uInt8 BIFF_TOK_NLR_SCOLR = 0x0D; /// Stacked NLR: Column index. +const sal_uInt8 BIFF_TOK_NLR_SROWV = 0x0E; /// Stacked NLR: Value in row. +const sal_uInt8 BIFF_TOK_NLR_SCOLV = 0x0F; /// Stacked NLR: Value in column. +const sal_uInt8 BIFF_TOK_NLR_RANGEERR = 0x10; /// NLR: Invalid/deleted range. +const sal_uInt8 BIFF_TOK_NLR_SXNAME = 0x1D; /// NLR: Pivot table name. +const sal_uInt16 BIFF_TOK_NLR_REL = 0x8000; /// True = NLR is relative. +const sal_uInt16 BIFF_TOK_NLR_MASK = 0x3FFF; /// Mask to extract BIFF8 column from NLR. + +const sal_uInt32 BIFF_TOK_NLR_ADDREL = 0x80000000; /// NLR relative (in appended data). +const sal_uInt32 BIFF_TOK_NLR_ADDMASK = 0x3FFFFFFF; /// Mask for number of appended ranges. + +// function constants --------------------------------------------------------- + +const sal_uInt8 OOX_MAX_PARAMCOUNT = 255; /// Maximum parameter count for OOXML/BIFF12 files. +const sal_uInt8 BIFF_MAX_PARAMCOUNT = 30; /// Maximum parameter count for BIFF2-BIFF8 files. + +const sal_uInt16 BIFF_FUNC_IF = 1; /// Function identifier of the IF function. +const sal_uInt16 BIFF_FUNC_SUM = 4; /// Function identifier of the SUM function. +const sal_uInt16 BIFF_FUNC_TRUE = 34; /// Function identifier of the TRUE function. +const sal_uInt16 BIFF_FUNC_FALSE = 35; /// Function identifier of the FALSE function. +const sal_uInt16 BIFF_FUNC_ROWS = 76; /// Function identifier of the ROWS function. +const sal_uInt16 BIFF_FUNC_COLUMNS = 77; /// Function identifier of the COLUMNS function. +const sal_uInt16 BIFF_FUNC_OFFSET = 78; /// Function identifier of the OFFSET function. +const sal_uInt16 BIFF_FUNC_EXTERNCALL = 255; /// BIFF function id of the EXTERN.CALL function. +const sal_uInt16 BIFF_FUNC_FLOOR = 285; /// Function identifier of the FLOOR function. +const sal_uInt16 BIFF_FUNC_CEILING = 288; /// Function identifier of the CEILING function. +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 ========================================================== + +/** A 2D formula cell reference struct with relative flags. */ +struct BinSingleRef2d +{ + sal_Int32 mnCol; /// Column index. + sal_Int32 mnRow; /// Row index. + bool mbColRel; /// True = relative column reference. + bool mbRowRel; /// True = relative row reference. + + explicit BinSingleRef2d(); + + void setBiff12Data( sal_uInt16 nCol, sal_Int32 nRow, bool bRelativeAsOffset ); + void setBiff2Data( sal_uInt8 nCol, sal_uInt16 nRow, bool bRelativeAsOffset ); + void setBiff8Data( sal_uInt16 nCol, sal_uInt16 nRow, bool bRelativeAsOffset ); + + void readBiff12Data( SequenceInputStream& rStrm, bool bRelativeAsOffset ); + void readBiff2Data( BiffInputStream& rStrm, bool bRelativeAsOffset ); + void readBiff8Data( BiffInputStream& rStrm, bool bRelativeAsOffset ); +}; + +// ---------------------------------------------------------------------------- + +/** A 2D formula cell range reference struct with relative flags. */ +struct BinComplexRef2d +{ + BinSingleRef2d maRef1; /// Start (top-left) cell address. + BinSingleRef2d maRef2; /// End (bottom-right) cell address. + + void readBiff12Data( SequenceInputStream& rStrm, bool bRelativeAsOffset ); + void readBiff2Data( BiffInputStream& rStrm, bool bRelativeAsOffset ); + void readBiff8Data( BiffInputStream& rStrm, bool bRelativeAsOffset ); +}; + +// token vector, sequence ===================================================== + +typedef ::com::sun::star::sheet::FormulaToken ApiToken; +typedef ::com::sun::star::uno::Sequence< ApiToken > ApiTokenSequence; + +/** A vector of formula tokens with additional convenience functions. */ +class ApiTokenVector : public ::std::vector< ApiToken > +{ +public: + explicit ApiTokenVector(); + + /** Appends a new token with the passed op-code, returns its data field. */ + ::com::sun::star::uno::Any& + append( sal_Int32 nOpCode ); + + /** Appends a new token with the passed op-code and data. */ + template< typename Type > + inline void append( sal_Int32 nOpCode, const Type& rData ) { append( nOpCode ) <<= rData; } +}; + +// token sequence iterator ==================================================== + +/** Token sequence iterator that is able to skip space tokens. */ +class ApiTokenIterator +{ +public: + explicit ApiTokenIterator( const ApiTokenSequence& rTokens, sal_Int32 nSpacesOpCode, bool bSkipSpaces ); + /** Copy constructor that allows to change the skip spaces mode. */ + explicit ApiTokenIterator( const ApiTokenIterator& rIter, bool bSkipSpaces ); + + inline bool is() const { return mpToken != mpTokenEnd; } + inline const ApiToken* get() const { return mpToken; } + inline const ApiToken* operator->() const { return mpToken; } + inline const ApiToken& operator*() const { return *mpToken; } + + ApiTokenIterator& operator++(); + +private: + void skipSpaces(); + +private: + const ApiToken* mpToken; /// Pointer to current token of the token sequence. + const ApiToken* mpTokenEnd; /// Pointer behind last token of the token sequence. + const sal_Int32 mnSpacesOpCode; /// Op-code for whitespace tokens. + const bool mbSkipSpaces; /// true = Skip whitespace tokens. +}; + +// list of API op-codes ======================================================= + +/** Contains all API op-codes needed to build formulas with tokens. */ +struct ApiOpCodes +{ + // special + sal_Int32 OPCODE_UNKNOWN; /// Internal: function name unknown to mapper. + sal_Int32 OPCODE_EXTERNAL; /// External function call (e.g. add-ins). + // formula structure + sal_Int32 OPCODE_PUSH; /// Op-code for common value operands. + sal_Int32 OPCODE_MISSING; /// Placeholder for a missing function parameter. + sal_Int32 OPCODE_SPACES; /// Spaces between other formula tokens. + sal_Int32 OPCODE_NAME; /// Index of a defined name. + sal_Int32 OPCODE_DBAREA; /// Index of a database area. + sal_Int32 OPCODE_NLR; /// Natural language reference. + sal_Int32 OPCODE_DDE; /// DDE link function. + sal_Int32 OPCODE_MACRO; /// Macro function call. + sal_Int32 OPCODE_BAD; /// Bad token (unknown name, formula error). + sal_Int32 OPCODE_NONAME; /// Function style #NAME? error. + // separators + sal_Int32 OPCODE_OPEN; /// Opening parenthesis. + sal_Int32 OPCODE_CLOSE; /// Closing parenthesis. + sal_Int32 OPCODE_SEP; /// Function parameter separator. + // array separators + sal_Int32 OPCODE_ARRAY_OPEN; /// Opening brace for constant arrays. + sal_Int32 OPCODE_ARRAY_CLOSE; /// Closing brace for constant arrays. + sal_Int32 OPCODE_ARRAY_ROWSEP; /// Row separator in constant arrays. + sal_Int32 OPCODE_ARRAY_COLSEP; /// Column separator in constant arrays. + // unary operators + sal_Int32 OPCODE_PLUS_SIGN; /// Unary plus sign. + sal_Int32 OPCODE_MINUS_SIGN; /// Unary minus sign. + sal_Int32 OPCODE_PERCENT; /// Percent sign. + // binary operators + sal_Int32 OPCODE_ADD; /// Addition operator. + sal_Int32 OPCODE_SUB; /// Subtraction operator. + sal_Int32 OPCODE_MULT; /// Multiplication operator. + sal_Int32 OPCODE_DIV; /// Division operator. + sal_Int32 OPCODE_POWER; /// Power operator. + sal_Int32 OPCODE_CONCAT; /// String concatenation operator. + sal_Int32 OPCODE_EQUAL; /// Compare equal operator. + sal_Int32 OPCODE_NOT_EQUAL; /// Compare not equal operator. + sal_Int32 OPCODE_LESS; /// Compare less operator. + sal_Int32 OPCODE_LESS_EQUAL; /// Compare less or equal operator. + sal_Int32 OPCODE_GREATER; /// Compare greater operator. + sal_Int32 OPCODE_GREATER_EQUAL; /// Compare greater or equal operator. + sal_Int32 OPCODE_INTERSECT; /// Range intersection operator. + sal_Int32 OPCODE_LIST; /// Range list operator. + sal_Int32 OPCODE_RANGE; /// Range operator. +}; + +// Function parameter info ==================================================== + +/** Enumerates validity modes for a function parameter. */ +enum FuncParamValidity +{ + FUNC_PARAM_NONE = 0, /// Default for an unspecified entry in a C-array. + FUNC_PARAM_REGULAR, /// Parameter supported by Calc and Excel. + FUNC_PARAM_CALCONLY, /// Parameter supported by Calc only. + FUNC_PARAM_EXCELONLY /// Parameter supported by Excel only. +}; + +/** Enumerates different types of token class conversion in function parameters. */ +enum FuncParamConversion +{ + FUNC_PARAMCONV_ORG, /// Use original class of current token. + FUNC_PARAMCONV_VAL, /// Convert tokens to VAL class. + FUNC_PARAMCONV_ARR, /// Convert tokens to ARR class. + FUNC_PARAMCONV_RPT, /// Repeat parent conversion in VALTYPE parameters. + FUNC_PARAMCONV_RPX, /// Repeat parent conversion in REFTYPE parameters. + FUNC_PARAMCONV_RPO /// Repeat parent conversion in operands of operators. +}; + +/** Structure that contains all needed information for a parameter in a + function. + + The member meValid specifies which application supports the parameter. If + set to CALCONLY, import filters have to insert a default value for this + parameter, and export filters have to skip the parameter. If set to + EXCELONLY, import filters have to skip the parameter, and export filters + have to insert a default value for this parameter. + + The member mbValType specifies whether the parameter requires tokens to be + of value type (VAL or ARR class). + + If set to false, the parameter is called to be REFTYPE. Tokens with REF + default class can be inserted for the parameter (e.g. tAreaR tokens). + + If set to true, the parameter is called to be VALTYPE. Tokens with REF + class need to be converted to VAL tokens first (e.g. tAreaR will be + converted to tAreaV), and further conversion is done according to this + new token class. + + The member meConv specifies how to convert the current token class of the + token inserted for the parameter. If the token class is still REF this + means that the token has default REF class and the parameter is REFTYPE + (see member mbValType), the token will not be converted at all and remains + in REF class. Otherwise, token class conversion is depending on the actual + token class of the return value of the function containing this parameter. + The function may return REF class (tFuncR, tFuncVarR, tFuncCER), or it may + return VAL or ARR class (tFuncV, tFuncA, tFuncVarV, tFuncVarA, tFuncCEV, + tFuncCEA). Even if the function is able to return REF class, it may return + VAL or ARR class instead due to the VALTYPE data type of the parent + function parameter that calls the own function. Example: The INDIRECT + function returns REF class by default. But if called from a VALTYPE + function parameter, e.g. in the formula =ABS(INDIRECT("A1")), it returns + VAL or ARR class instead. Additionally, the repeating conversion types RPT + and RPX rely on the conversion executed for the function token class. + + 1) ORG: + Use the original class of the token (VAL or ARR), regardless of any + conversion done for the function return class. + + 2) VAL: + Convert ARR tokens to VAL class, regardless of any conversion done for + the function return class. + + 3) ARR: + Convert VAL tokens to ARR class, regardless of any conversion done for + the function return class. + + 4) RPT: + If the own function returns REF class (thus it is called from a REFTYPE + parameter, see above), and the parent conversion type (for the function + return class) was ORG, VAL, or ARR, ignore that conversion and always + use VAL conversion for the own token instead. If the parent conversion + type was RPT or RPX, repeat the conversion that would have been used if + the function would return value type. + If the own function returns value type (VAL or ARR class, see above), + and the parent conversion type (for the function return class) was ORG, + VAL, ARR, or RPT, repeat this conversion for the own token. If the + parent conversion type was RPX, always use ORG conversion type for the + own token instead. + + 5) RPX: + This type of conversion only occurs in functions returning VAL class by + default. If the own token is value type, and the VAL return class of + the own function has been changed to ARR class (due to direct ARR + conversion, or due to ARR conversion repeated by RPT or RPX), set the + own token to ARR type. Otherwise use the original token type (VAL + conversion from parent parameter will not be repeated at all). If + nested functions have RPT or value-type RPX parameters, they will not + repeat this conversion type, but will use ORG conversion instead (see + description of RPT above). + + 6) RPO: + This type of conversion is only used for the operands of all operators + (unary and binary arithmetic operators, comparison operators, and range + operators). It is not used for function parameters. On conversion, it + will be replaced by the last conversion type that was not the RPO + conversion. This leads to a slightly different behaviour than the RPT + conversion for operands in conjunction with a parent RPX conversion. + */ +struct FunctionParamInfo +{ + FuncParamValidity meValid; /// Parameter validity. + FuncParamConversion meConv; /// Token class conversion type. + bool mbValType; /// Data type (false = REFTYPE, true = VALTYPE). +}; + +// 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. +}; + +// ---------------------------------------------------------------------------- + +/** Represents information for a spreadsheet function. + + The member mpParamInfos points to an 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 + this array is used repeatedly for all following parameters supported by a + function. + */ +struct FunctionInfo +{ + ::rtl::OUString maOdfFuncName; /// ODF function name. + ::rtl::OUString maOoxFuncName; /// OOXML function name. + ::rtl::OUString maBiffMacroName; /// Expected macro name in EXTERN.CALL function. + ::rtl::OUString maExtProgName; /// Programmatic function name for external functions. + FunctionLibraryType meFuncLibType; /// The external library this function is part of. + sal_Int32 mnApiOpCode; /// API function opcode. + sal_uInt16 mnBiff12FuncId; /// BIFF12 function identifier. + sal_uInt16 mnBiffFuncId; /// BIFF2-BIFF8 function identifier. + sal_uInt8 mnMinParamCount; /// Minimum number of parameters. + 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 mbVolatile; /// True = volatile function. + bool mbExternal; /// True = external function in Calc. + bool mbMacroFunc; /// True = macro sheet function or command. + bool mbVarParam; /// True = use a tFuncVar token, also if min/max are equal. +}; + +typedef RefVector< FunctionInfo > FunctionInfoVector; + +// function info parameter class iterator ===================================== + +/** Iterator working on the mpParamInfos member of the FunctionInfo struct. + + This iterator can be used to iterate through the array containing the + token class conversion information of function parameters. This iterator + repeats the last valid structure in the array - it stops automatically + before the first empty array entry or before the end of the array, even for + repeated calls to the increment operator. + */ +class FunctionParamInfoIterator +{ +public: + explicit FunctionParamInfoIterator( const FunctionInfo& rFuncInfo ); + + const FunctionParamInfo& getParamInfo() const; + bool isCalcOnlyParam() const; + bool isExcelOnlyParam() const; + FunctionParamInfoIterator& operator++(); + +private: + const FunctionParamInfo* mpParamInfo; + const FunctionParamInfo* mpParamInfoEnd; + bool mbParamPairs; +}; + +// base function provider ===================================================== + +struct FunctionProviderImpl; + +/** Provides access to function info structs for all available sheet functions. + */ +class FunctionProvider // not derived from WorkbookHelper to make it usable in file dumpers +{ +public: + explicit FunctionProvider( FilterType eFilter, BiffType eBiff, bool bImportFilter ); + virtual ~FunctionProvider(); + + /** Returns the function info for an ODF function name, or 0 on error. */ + const FunctionInfo* getFuncInfoFromOdfFuncName( const ::rtl::OUString& rFuncName ) const; + + /** Returns the function info for an OOXML function name, or 0 on error. */ + const FunctionInfo* getFuncInfoFromOoxFuncName( const ::rtl::OUString& rFuncName ) const; + + /** Returns the function info for a BIFF12 function index, or 0 on error. */ + const FunctionInfo* getFuncInfoFromBiff12FuncId( sal_uInt16 nFuncId ) const; + + /** Returns the function info for a BIFF2-BIFF8 function index, or 0 on error. */ + const FunctionInfo* getFuncInfoFromBiffFuncId( sal_uInt16 nFuncId ) const; + + /** Returns the function info for a macro function referred by the + EXTERN.CALL function, or 0 on error. */ + const FunctionInfo* getFuncInfoFromMacroName( const ::rtl::OUString& rFuncName ) const; + + /** Returns the library type associated with the passed URL of a function + library (function add-in). */ + FunctionLibraryType getFuncLibTypeFromLibraryName( const ::rtl::OUString& rLibraryName ) const; + +protected: + /** Returns the list of all function infos. */ + const FunctionInfoVector& getFuncs() const; + +private: + typedef ::boost::shared_ptr< FunctionProviderImpl > FunctionProviderImplRef; + FunctionProviderImplRef mxFuncImpl; /// Shared implementation between all copies of the provider. +}; + +// op-code and function provider ============================================== + +struct OpCodeProviderImpl; + +/** Provides access to API op-codes for all available formula tokens and to + function info structs for all available sheet functions. + */ +class OpCodeProvider : public FunctionProvider // not derived from WorkbookHelper to make it usable as UNO service +{ +public: + explicit OpCodeProvider( + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& rxFactory, + FilterType eFilter, BiffType eBiff, bool bImportFilter ); + virtual ~OpCodeProvider(); + + /** Returns the structure containing all token op-codes for operators and + special tokens used by the Calc document and its formula parser. */ + const ApiOpCodes& getOpCodes() const; + + /** Returns the function info for an API token, or 0 on error. */ + const FunctionInfo* getFuncInfoFromApiToken( const ApiToken& rToken ) const; + + /** Returns the op-code map that is used by the OOXML formula parser. */ + ::com::sun::star::uno::Sequence< ::com::sun::star::sheet::FormulaOpCodeMapEntry > + getOoxParserMap() const; + +private: + typedef ::boost::shared_ptr< OpCodeProviderImpl > OpCodeProviderImplRef; + OpCodeProviderImplRef mxOpCodeImpl; /// Shared implementation between all copies of the provider. +}; + +// API formula parser wrapper ================================================= + +/** A wrapper around the FormulaParser service provided by the Calc document. */ +class ApiParserWrapper : public OpCodeProvider +{ +public: + explicit ApiParserWrapper( + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& rxFactory, + const OpCodeProvider& rOpCodeProv ); + + /** Returns read/write access to the formula parser property set. */ + inline PropertySet& getParserProperties() { return maParserProps; } + + /** Calls the XFormulaParser::parseFormula() function of the API parser. */ + ApiTokenSequence parseFormula( + const ::rtl::OUString& rFormula, + const ::com::sun::star::table::CellAddress& rRefPos ); + +private: + ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XFormulaParser > + mxParser; + 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 ============================== + +/** Base class for import formula parsers and export formula compilers. */ +class FormulaProcessorBase : public OpCodeProvider, protected ApiOpCodes, public WorkbookHelper +{ +public: + explicit FormulaProcessorBase( const WorkbookHelper& rHelper ); + + // ------------------------------------------------------------------------ + + /** Generates a cell address string in A1 notation from the passed cell + address. + + @param rAddress The cell address containing column and row index. + @param bAbsolute True = adds dollar signs before column and row. + */ + static ::rtl::OUString generateAddress2dString( + const ::com::sun::star::table::CellAddress& rAddress, + bool bAbsolute ); + + /** Generates a cell address string in A1 notation from the passed binary + cell address. + + @param rAddress The cell address containing column and row index. + @param bAbsolute True = adds dollar signs before column and row. + */ + static ::rtl::OUString generateAddress2dString( + const BinAddress& rAddress, + bool bAbsolute ); + + /** Generates a cell range string in A1:A1 notation from the passed cell + range address. + + @param rRange The cell range address containing column and row indexes. + @param bAbsolute True = adds dollar signs before columns and rows. + */ + static ::rtl::OUString generateRange2dString( + const ::com::sun::star::table::CellRangeAddress& rRange, + bool bAbsolute ); + + /** Generates a cell range string in A1:A1 notation from the passed binary + cell range address. + + @param rRange The cell range address containing column and row indexes. + @param bAbsolute True = adds dollar signs before columns and rows. + */ + static ::rtl::OUString generateRange2dString( + const BinRange& rRange, + bool bAbsolute ); + + /** Generates a cell range list string in A1:A1 notation from the passed + cell range addresses. May enclose multiple ranges into parentheses. + + @param rRanges The list of cell range addresses. + @param bAbsolute True = adds dollar signs before columns and rows. + @param cSeparator Separator character between ranges. + @param bEncloseMultiple True = enclose multiple ranges in parentheses. + */ + static ::rtl::OUString generateRangeList2dString( + const ApiCellRangeList& rRanges, + bool bAbsolute, + sal_Unicode cSeparator, + bool bEncloseMultiple ); + + // ------------------------------------------------------------------------ + + /** Generates a cell address string in Calc's absolute $Sheet.$A$1 notation + from the passed cell address. + + @param rAddress The cell address to be converted to a string. + */ + ::rtl::OUString generateApiAddressString( + const ::com::sun::star::table::CellAddress& rAddress ) const; + + /** Generates a cell range string in Calc's absolute $Sheet.$A$1:$A$ + notation from the passed cell range address. + + @param rRange The cell range address to be converted to a string. + */ + ::rtl::OUString generateApiRangeString( + const ::com::sun::star::table::CellRangeAddress& rRange ) const; + + /** Generates a cell range list string in Calc's absolute $Sheet.$A$1:$A$1 + notation from the passed cell range addresses. + + @param rRanges The list of cell ranges to be converted to a string. + */ + ::rtl::OUString generateApiRangeListString( const ApiCellRangeList& rRanges ) const; + + /** Generates a string in Calc formula notation from the passed string. + + @param rString The string value. + + @return The string enclosed in double quotes, where all contained + quote characters are doubled. + */ + static ::rtl::OUString generateApiString( const ::rtl::OUString& rString ); + + /** Generates an array string in Calc formula notation from the passed + matrix with Any's containing double values or strings. + + @param rMatrix The matrix containing double values or strings. + */ + static ::rtl::OUString generateApiArray( const Matrix< ::com::sun::star::uno::Any >& rMatrix ); + + // ------------------------------------------------------------------------ + + /** Tries to extract a single cell reference from a formula token sequence. + + @param rTokens The token sequence to be parsed. Should contain exactly + one address token or cell range address token. The token sequence + may contain whitespace tokens. + + @return If the token sequence is valid, this function returns an Any + containing a com.sun.star.sheet.SingleReference object, or a + com.sun.star.sheet.ComplexReference object. If the token sequence + contains too many, or unexpected tokens, an empty Any is returned. + */ + ::com::sun::star::uno::Any + extractReference( const ApiTokenSequence& rTokens ) const; + + /** Tries to extract a single cell address from a formula token sequence. + + @param orAddress (output parameter) If the token sequence is valid, + this parameter will contain the extracted cell address. If the + token sequence contains unexpected tokens, nothing meaningful is + inserted, and the function returns false. + + @param rTokens The token sequence to be parsed. Should contain exactly + one cell address token. The token sequence may contain whitespace + tokens. + + @param bAllowRelative True = it is allowed that rTokens contains + relative references (based on cell A1 of the current sheet). + False = only real absolute references will be accepted. + + @return True, if the token sequence contains a valid cell address + which has been extracted to orAddress, false otherwise. + */ + bool extractCellAddress( + ::com::sun::star::table::CellAddress& orAddress, + const ApiTokenSequence& rTokens, + bool bAllowRelative ) const; + + /** Tries to extract a cell range address from a formula token sequence. + + @param orAddress (output parameter) If the token sequence is valid, + this parameter will contain the extracted cell range address. If + the token sequence contains unexpected tokens, nothing meaningful + is inserted, and the function returns false. + + @param rTokens The token sequence to be parsed. Should contain exactly + one cell range address token. The token sequence may contain + whitespace tokens. + + @param bAllowRelative True = it is allowed that rTokens contains + relative references (based on cell A1 of the current sheet). + False = only real absolute references will be accepted. + + @return True, if the token sequence contains a valid cell range + address which has been extracted to orRange, false otherwise. + */ + bool extractCellRange( + ::com::sun::star::table::CellRangeAddress& orRange, + const ApiTokenSequence& rTokens, + bool bAllowRelative ) const; + + /** Tries to extract a cell range list from a formula token sequence. + + @param orRanges (output parameter) If the token sequence is valid, + this parameter will contain the extracted cell range list. Deleted + cells or cell ranges (shown as #REF! error in a formula) will be + skipped. If the token sequence contains unexpected tokens, an empty + list is returned here. + + @param rTokens The token sequence to be parsed. Should contain cell + address tokens or cell range address tokens, separated by the + standard function parameter separator token. The token sequence may + contain parentheses and whitespace tokens. + + @param bAllowRelative True = it is allowed that rTokens contains + relative references (based on cell A1 of the current sheet). + False = only real absolute references will be accepted. + + @param nFilterBySheet If non-negative, this function returns only cell + ranges located in the specified sheet, otherwise returns all cell + ranges contained in the token sequence. + */ + void extractCellRangeList( + ApiCellRangeList& orRanges, + const ApiTokenSequence& rTokens, + bool bAllowRelative, + sal_Int32 nFilterBySheet = -1 ) const; + + /** Tries to extract a string from a formula token sequence. + + @param orString (output parameter) The extracted string. + + @param rTokens The token sequence to be parsed. Should contain exactly + one string token, may contain whitespace tokens. + + @return True = token sequence is valid, output parameter orString + contains the string extracted from the token sequence. + */ + bool extractString( + ::rtl::OUString& orString, + const ApiTokenSequence& rTokens ) const; + + /** Converts a single string with separators in the passed formula token + sequence to a list of string tokens. + + @param orTokens (input/output parameter) Expects a single string token + in this token sequence (whitespace tokens are allowed). The string + is split into substrings. A list of string tokens separated with + parameter separator tokens is returned in this psrameter. + + @param cStringSep The separator character used to split the input + string. + + @param bTrimLeadingSpaces True = removes leading whitespace from all + substrings inserted into the formula token sequence. + */ + void convertStringToStringList( + ApiTokenSequence& orTokens, + sal_Unicode cStringSep, + bool bTrimLeadingSpaces ) const; +}; + +// ============================================================================ + +} // namespace xls +} // namespace oox + +#endif diff --git a/oox/inc/oox/xls/formulaparser.hxx b/oox/inc/oox/xls/formulaparser.hxx new file mode 100644 index 000000000000..c595993264d9 --- /dev/null +++ b/oox/inc/oox/xls/formulaparser.hxx @@ -0,0 +1,172 @@ +/************************************************************************* + * + * 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_FORMULAPARSER_HXX +#define OOX_XLS_FORMULAPARSER_HXX + +#include "oox/xls/formulabase.hxx" + +namespace oox { +namespace xls { + +// formula finalizer ========================================================== + +/** A generic formula token array finalizer. + + After building a formula token array from alien binary file formats, or + parsing an XML formula string using the com.sun.star.sheet.FormulaParser + service, the token array is still not ready to be put into the spreadsheet + document. There may be functions with a wrong number of parameters (missing + but required parameters, or unsupported parameters) or intermediate tokens + used to encode references to macro functions or add-in functions. This + helper processes a passed token array and builds a new compatible token + array. + + Derived classes may add more functionality by overwriting the virtual + functions. + */ +class FormulaFinalizer : public OpCodeProvider, protected ApiOpCodes +{ +public: + explicit FormulaFinalizer( const OpCodeProvider& rOpCodeProv ); + + /** Finalizes and returns the passed token array. */ + ApiTokenSequence finalizeTokenArray( const ApiTokenSequence& rTokens ); + +protected: + /** Derived classed may try to find a function info struct from the passed + string extracted from an OPCODE_BAD token. + + @param rTokenData The string that has been found in an OPCODE_BAD + token preceding the function parentheses. + */ + virtual const FunctionInfo* resolveBadFuncName( const ::rtl::OUString& rTokenData ) const; + + /** Derived classed may try to find the name of a defined name with the + passed index extracted from an OPCODE_NAME token. + + @param nTokenIndex The index of the defined name that has been found + in an OPCODE_NAME token preceding the function parentheses. + */ + virtual ::rtl::OUString resolveDefinedName( sal_Int32 nTokenIndex ) const; + +private: + typedef ::std::vector< const ApiToken* > ParameterPosVector; + + const FunctionInfo* getFunctionInfo( ApiToken& orFuncToken ); + const FunctionInfo* getExternCallInfo( ApiToken& orFuncToken, const ApiToken& rECToken ); + + void processTokens( const ApiToken* pToken, const ApiToken* pTokenEnd ); + const ApiToken* processParameters( const FunctionInfo& rFuncInfo, const ApiToken* pToken, const ApiToken* pTokenEnd ); + + bool isEmptyParameter( const ApiToken* pToken, const ApiToken* pTokenEnd ) const; + 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 appendCalcOnlyParameter( const FunctionInfo& rFuncInfo, size_t nParam ); + void appendRequiredParameters( const FunctionInfo& rFuncInfo, size_t nParamCount ); + + bool appendFinalToken( const ApiToken& rToken ); + +private: + ApiTokenVector maTokens; +}; + +// ============================================================================ + +class FormulaParserImpl; + +/** Import formula parser for OOXML and BIFF filters. + + This class implements formula import for the OOXML and BIFF filter. One + instance is contained in the global filter data to prevent construction and + destruction of internal buffers for every imported formula. + */ +class FormulaParser : public FormulaProcessorBase +{ +public: + explicit FormulaParser( const WorkbookHelper& rHelper ); + virtual ~FormulaParser(); + + /** Converts an OOXML formula string. */ + void importFormula( + FormulaContext& rContext, + const ::rtl::OUString& rFormulaString ) const; + + /** Imports and converts a BIFF12 token array from the passed stream. */ + void importFormula( + FormulaContext& rContext, + 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, + BiffInputStream& rStrm, + const sal_uInt16* pnFmlaSize = 0 ) const; + + /** Converts the passed BIFF error code to a similar formula. */ + void convertErrorToFormula( + FormulaContext& rContext, + 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; + + /** Converts the passed number into a HYPERLINK formula with the passed URL. */ + void convertNumberToHyperlink( + FormulaContext& rContext, + const ::rtl::OUString& rUrl, + double fValue ) const; + + /** Converts the passed XML formula to an OLE link target. */ + ::rtl::OUString importOleTargetLink( const ::rtl::OUString& rFormulaString ); + + /** Imports and converts an OLE link target from the passed stream. */ + ::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; + + /** Converts the passed formula to a macro name for a drawing shape. */ + ::rtl::OUString importMacroName( const ::rtl::OUString& rFormulaString ); + +private: + ::std::auto_ptr< FormulaParserImpl > mxImpl; +}; + +// ============================================================================ + +} // namespace xls +} // namespace oox + +#endif diff --git a/oox/inc/oox/xls/numberformatsbuffer.hxx b/oox/inc/oox/xls/numberformatsbuffer.hxx new file mode 100644 index 000000000000..768572a5839c --- /dev/null +++ b/oox/inc/oox/xls/numberformatsbuffer.hxx @@ -0,0 +1,138 @@ +/************************************************************************* + * + * 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_NUMBERFORMATSBUFFER_HXX +#define OOX_XLS_NUMBERFORMATSBUFFER_HXX + +#include <com/sun/star/lang/Locale.hpp> +#include "oox/xls/workbookhelper.hxx" + +namespace com { namespace sun { namespace star { + namespace util { class XNumberFormats; } +} } } + +namespace oox { class PropertyMap; } + +namespace oox { +namespace xls { + +// ============================================================================ + +struct NumFmtModel +{ + ::com::sun::star::lang::Locale maLocale; + ::rtl::OUString maFmtCode; + sal_Int16 mnPredefId; + + explicit NumFmtModel(); +}; + +// ---------------------------------------------------------------------------- + +/** Contains all API number format attributes. */ +struct ApiNumFmtData +{ + sal_Int32 mnIndex; /// API number format index. + + explicit ApiNumFmtData(); +}; + +// ---------------------------------------------------------------------------- + +/** Contains all data for a number format code. */ +class NumberFormat : public WorkbookHelper +{ +public: + explicit NumberFormat( const WorkbookHelper& rHelper ); + + /** Sets the passed format code. */ + void setFormatCode( const ::rtl::OUString& rFmtCode ); + /** Sets the passed format code, encoded in UTF-8. */ + void setFormatCode( + const ::com::sun::star::lang::Locale& rLocale, + const sal_Char* pcFmtCode ); + /** Sets the passed predefined format code identifier. */ + void setPredefinedId( + const ::com::sun::star::lang::Locale& rLocale, + sal_Int16 nPredefId ); + + /** Final processing after import of all style settings. Returns the API format index. */ + sal_Int32 finalizeImport( + const ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormats >& rxNumFmts, + const ::com::sun::star::lang::Locale& rFromLocale ); + + /** Writes the number format to the passed property map. */ + void writeToPropertyMap( PropertyMap& rPropMap ) const; + +private: + NumFmtModel maModel; + ApiNumFmtData maApiData; +}; + +typedef ::boost::shared_ptr< NumberFormat > NumberFormatRef; + +// ============================================================================ + +class NumberFormatsBuffer : public WorkbookHelper +{ +public: + explicit NumberFormatsBuffer( const WorkbookHelper& rHelper ); + + /** Inserts a new number format. */ + NumberFormatRef createNumFmt( sal_Int32 nNumFmtId, const ::rtl::OUString& rFmtCode ); + + /** Inserts a new number format code. */ + NumberFormatRef importNumFmt( const AttributeList& rAttribs ); + /** Inserts a new number format code from a NUMFMT record. */ + void importNumFmt( SequenceInputStream& rStrm ); + /** Inserts a new number format code from a FORMAT record. */ + void importFormat( BiffInputStream& rStrm ); + + /** Final processing after import of all style settings. */ + void finalizeImport(); + + /** Writes the specified number format to the passed property map. */ + void writeToPropertyMap( PropertyMap& rPropMap, sal_Int32 nNumFmtId ) const; + +private: + /** Inserts built-in number formats for the current system language. */ + void insertBuiltinFormats(); + +private: + typedef RefMap< sal_Int32, NumberFormat > NumberFormatMap; + + NumberFormatMap maNumFmts; /// List of number formats. + ::rtl::OUString maLocaleStr; /// Current office locale. + sal_Int32 mnNextBiffIndex; /// Format id counter for BIFF2-BIFF4. +}; + +// ============================================================================ + +} // namespace xls +} // namespace oox + +#endif diff --git a/oox/inc/oox/xls/ooxformulaparser.hxx b/oox/inc/oox/xls/ooxformulaparser.hxx new file mode 100644 index 000000000000..7bc1bbdd4909 --- /dev/null +++ b/oox/inc/oox/xls/ooxformulaparser.hxx @@ -0,0 +1,111 @@ +/************************************************************************* + * + * 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_OOXFORMULAPARSER_HXX +#define OOX_XLS_OOXFORMULAPARSER_HXX + +#include <boost/shared_ptr.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/lang/XInitialization.hpp> +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/sheet/XFilterFormulaParser.hpp> +#include <cppuhelper/implbase3.hxx> + +namespace oox { +namespace xls { + +class OOXMLFormulaParserImpl; +class OOXMLFormulaPrinterImpl; + +// ============================================================================ + +typedef ::cppu::WeakImplHelper3< + ::com::sun::star::lang::XServiceInfo, + ::com::sun::star::lang::XInitialization, + ::com::sun::star::sheet::XFilterFormulaParser > OOXMLFormulaParserBase; + +/** OOXML formula parser/compiler service for usage in ODF filters. */ +class OOXMLFormulaParser : public OOXMLFormulaParserBase +{ +public: + explicit OOXMLFormulaParser(); + virtual ~OOXMLFormulaParser(); + + // com.sun.star.lang.XServiceInfo interface ------------------------------- + + virtual ::rtl::OUString SAL_CALL + getImplementationName() throw( ::com::sun::star::uno::RuntimeException ); + + virtual sal_Bool SAL_CALL + supportsService( const ::rtl::OUString& rService ) + throw( ::com::sun::star::uno::RuntimeException ); + + virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL + getSupportedServiceNames() throw( ::com::sun::star::uno::RuntimeException ); + + // com.sun.star.lang.XInitialization interface ---------------------------- + + virtual void SAL_CALL initialize( + const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& rArgs ) + throw( ::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException ); + + // com.sun.star.sheet.XFilterFormulaParser interface ---------------------- + + virtual ::rtl::OUString SAL_CALL + getSupportedNamespace() + throw( ::com::sun::star::uno::RuntimeException ); + + // com.sun.star.sheet.XFormulaParser interface ---------------------------- + + virtual ::com::sun::star::uno::Sequence< ::com::sun::star::sheet::FormulaToken > SAL_CALL + parseFormula( + const ::rtl::OUString& rFormula, + const ::com::sun::star::table::CellAddress& rReferencePos ) + throw( ::com::sun::star::uno::RuntimeException ); + + virtual ::rtl::OUString SAL_CALL + printFormula( + const ::com::sun::star::uno::Sequence< ::com::sun::star::sheet::FormulaToken >& rTokens, + const ::com::sun::star::table::CellAddress& rReferencePos ) + throw( ::com::sun::star::uno::RuntimeException ); + +private: + typedef ::boost::shared_ptr< OOXMLFormulaParserImpl > ParserImplRef; + typedef ::boost::shared_ptr< OOXMLFormulaPrinterImpl > PrinterImplRef; + + ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > + mxComponent; + ParserImplRef mxParserImpl; /// Implementation of import parser. + PrinterImplRef mxPrinterImpl; /// Implementation of export printer. +}; + +// ============================================================================ + +} // namespace xls +} // namespace oox + +#endif diff --git a/oox/inc/oox/xls/pagesettings.hxx b/oox/inc/oox/xls/pagesettings.hxx new file mode 100644 index 000000000000..6ff896b1bb51 --- /dev/null +++ b/oox/inc/oox/xls/pagesettings.hxx @@ -0,0 +1,219 @@ +/************************************************************************* + * + * 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_PAGESETTINGS_HXX +#define OOX_XLS_PAGESETTINGS_HXX + +#include "oox/xls/worksheethelper.hxx" + +namespace oox { class PropertySet; } +namespace oox { namespace core { class Relations; } } + +namespace oox { +namespace xls { + +class HeaderFooterParser; + +// ============================================================================ + +/** Holds page style data for a single sheet. */ +struct PageSettingsModel +{ + ::rtl::OUString maGraphicUrl; /// URL of the graphic object. + ::rtl::OUString maBinSettPath; /// Relation identifier of binary printer settings. + ::rtl::OUString maOddHeader; /// Header string for odd pages. + ::rtl::OUString maOddFooter; /// Footer string for odd pages. + ::rtl::OUString maEvenHeader; /// Header string for even pages. + ::rtl::OUString maEvenFooter; /// Footer string for even pages. + ::rtl::OUString maFirstHeader; /// Header string for first page of the sheet. + ::rtl::OUString maFirstFooter; /// Footer string for first page of the sheet. + double mfLeftMargin; /// Margin between left edge of page and begin of sheet area. + double mfRightMargin; /// Margin between end of sheet area and right edge of page. + double mfTopMargin; /// Margin between top egde of page and begin of sheet area. + double mfBottomMargin; /// Margin between end of sheet area and bottom edge of page. + double mfHeaderMargin; /// Margin between top edge of page and begin of header. + double mfFooterMargin; /// Margin between end of footer and bottom edge of page. + sal_Int32 mnPaperSize; /// Paper size (enumeration). + sal_Int32 mnCopies; /// Number of copies to print. + sal_Int32 mnScale; /// Page scale (zoom in percent). + sal_Int32 mnFirstPage; /// First page number. + sal_Int32 mnFitToWidth; /// Fit to number of pages in horizontal direction. + sal_Int32 mnFitToHeight; /// Fit to number of pages in vertical direction. + sal_Int32 mnHorPrintRes; /// Horizontal printing resolution in DPI. + sal_Int32 mnVerPrintRes; /// Vertical printing resolution in DPI. + sal_Int32 mnOrientation; /// Landscape or portrait. + sal_Int32 mnPageOrder; /// Page order through sheet area (to left or down). + sal_Int32 mnCellComments; /// Cell comments printing mode. + sal_Int32 mnPrintErrors; /// Cell error printing mode. + bool mbUseEvenHF; /// True = use maEvenHeader/maEvenFooter. + bool mbUseFirstHF; /// True = use maFirstHeader/maFirstFooter. + bool mbValidSettings; /// True = use imported settings. + bool mbUseFirstPage; /// True = start page numbering with mnFirstPage. + bool mbBlackWhite; /// True = print black and white. + bool mbDraftQuality; /// True = print in draft quality. + bool mbFitToPages; /// True = Fit to width/height; false = scale in percent. + bool mbHorCenter; /// True = horizontally centered. + bool mbVerCenter; /// True = vertically centered. + bool mbPrintGrid; /// True = print grid lines. + bool mbPrintHeadings; /// True = print column/row headings. + + explicit PageSettingsModel(); + + /** Sets the BIFF print errors mode. */ + void setBiffPrintErrors( sal_uInt8 nPrintErrors ); +}; + +// ============================================================================ + +class PageSettings : public WorksheetHelper +{ +public: + explicit PageSettings( const WorksheetHelper& rHelper ); + + /** Imports printing options from a printOptions element. */ + void importPrintOptions( const AttributeList& rAttribs ); + /** Imports pageMarings element containing page margins. */ + void importPageMargins( const AttributeList& rAttribs ); + /** Imports pageSetup element for worksheets. */ + void importPageSetup( const ::oox::core::Relations& rRelations, const AttributeList& rAttribs ); + /** Imports pageSetup element for chart sheets. */ + void importChartPageSetup( const ::oox::core::Relations& rRelations, const AttributeList& rAttribs ); + /** Imports header and footer settings from a headerFooter element. */ + void importHeaderFooter( const AttributeList& rAttribs ); + /** Imports header/footer characters from a headerFooter element. */ + void importHeaderFooterCharacters( const ::rtl::OUString& rChars, sal_Int32 nElement ); + /** Imports the picture element. */ + void importPicture( const ::oox::core::Relations& rRelations, const AttributeList& rAttribs ); + + /** Imports the PRINTOPTIONS record from the passed stream. */ + void importPrintOptions( SequenceInputStream& rStrm ); + /** Imports the PAGEMARGINS record from the passed stream. */ + void importPageMargins( SequenceInputStream& rStrm ); + /** Imports the PAGESETUP record from the passed stream. */ + void importPageSetup( const ::oox::core::Relations& rRelations, SequenceInputStream& rStrm ); + /** Imports the CHARTPAGESETUP record from the passed stream. */ + void importChartPageSetup( const ::oox::core::Relations& rRelations, SequenceInputStream& rStrm ); + /** Imports the HEADERFOOTER record from the passed stream. */ + void importHeaderFooter( SequenceInputStream& rStrm ); + /** Imports the PICTURE record from the passed stream. */ + void importPicture( const ::oox::core::Relations& rRelations, SequenceInputStream& rStrm ); + + /** Imports the LEFTMARGIN record from the passed BIFF stream. */ + void importLeftMargin( BiffInputStream& rStrm ); + /** Imports the RIGHTMARGIN record from the passed BIFF stream. */ + void importRightMargin( BiffInputStream& rStrm ); + /** Imports the TOPMARGIN record from the passed BIFF stream. */ + void importTopMargin( BiffInputStream& rStrm ); + /** Imports the BOTTOMMARGIN record from the passed BIFF stream. */ + void importBottomMargin( BiffInputStream& rStrm ); + /** Imports the SETUP record from the passed BIFF stream. */ + void importPageSetup( BiffInputStream& rStrm ); + /** Imports the HCENTER record from the passed BIFF stream. */ + void importHorCenter( BiffInputStream& rStrm ); + /** Imports the VCENTER record from the passed BIFF stream. */ + void importVerCenter( BiffInputStream& rStrm ); + /** Imports the PRINTHEADERS record from the passed BIFF stream. */ + void importPrintHeaders( BiffInputStream& rStrm ); + /** Imports the PRINTGRIDLINES record from the passed BIFF stream. */ + void importPrintGridLines( BiffInputStream& rStrm ); + /** Imports the HEADER record from the passed BIFF stream. */ + void importHeader( BiffInputStream& rStrm ); + /** Imports the FOOTER record from the passed BIFF stream. */ + void importFooter( BiffInputStream& rStrm ); + /** Imports the PICTURE record from the passed BIFF stream. */ + void importPicture( BiffInputStream& rStrm ); + + /** Sets whether percentual scaling or fit to width/height scaling is used. */ + void setFitToPagesMode( bool bFitToPages ); + + /** Creates a page style for the spreadsheet and sets all page properties. */ + void finalizeImport(); + +private: + /** Imports the binary picture data from the fragment with the passed identifier. */ + void importPictureData( const ::oox::core::Relations& rRelations, const ::rtl::OUString& rRelId ); + +private: + PageSettingsModel maModel; +}; + +// ============================================================================ + +class PageSettingsConverter : public WorkbookHelper +{ +public: + explicit PageSettingsConverter( const WorkbookHelper& rHelper ); + virtual ~PageSettingsConverter(); + + /** Writes all properties to the passed property set of a page style object. */ + void writePageSettingsProperties( + PropertySet& rPropSet, + const PageSettingsModel& rModel, + WorksheetType eSheetType ); + +private: + struct HFHelperData + { + sal_Int32 mnLeftPropId; + sal_Int32 mnRightPropId; + sal_Int32 mnHeight; + sal_Int32 mnBodyDist; + bool mbHasContent; + bool mbShareOddEven; + bool mbDynamicHeight; + + explicit HFHelperData( sal_Int32 nLeftPropId, sal_Int32 nRightPropId ); + }; + +private: + void convertHeaderFooterData( + PropertySet& rPropSet, + HFHelperData& orHFData, + const ::rtl::OUString rOddContent, + const ::rtl::OUString rEvenContent, + bool bUseEvenContent, + double fPageMargin, + double fContentMargin ); + + sal_Int32 writeHeaderFooter( + PropertySet& rPropSet, + sal_Int32 nPropId, + const ::rtl::OUString& rContent ); + +private: + typedef ::std::auto_ptr< HeaderFooterParser > HeaderFooterParserPtr; + HeaderFooterParserPtr mxHFParser; + HFHelperData maHeaderData; + HFHelperData maFooterData; +}; + +// ============================================================================ + +} // namespace xls +} // namespace oox + +#endif diff --git a/oox/inc/oox/xls/pivotcachebuffer.hxx b/oox/inc/oox/xls/pivotcachebuffer.hxx new file mode 100644 index 000000000000..2e32d0faa7e5 --- /dev/null +++ b/oox/inc/oox/xls/pivotcachebuffer.hxx @@ -0,0 +1,510 @@ +/************************************************************************* + * + * 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_PIVOTCACHEBUFFER_HXX +#define OOX_XLS_PIVOTCACHEBUFFER_HXX + +#include <com/sun/star/table/CellAddress.hpp> +#include <com/sun/star/table/CellRangeAddress.hpp> +#include <com/sun/star/util/DateTime.hpp> +#include "oox/helper/refvector.hxx" +#include "oox/xls/workbookhelper.hxx" + +namespace com { namespace sun { namespace star { + namespace sheet { class XDataPilotField; } +} } } + +namespace oox { namespace core { class Relations; } } + +namespace oox { +namespace xls { + +class WorksheetHelper; + +// ============================================================================ + +class PivotCacheItem +{ +public: + explicit PivotCacheItem(); + + /** Reads the string value from a pivot cache item. */ + void readString( const AttributeList& rAttribs ); + /** Reads the double value from a pivot cache item. */ + void readNumeric( const AttributeList& rAttribs ); + /** Reads the date/time value from a pivot cache item. */ + void readDate( const AttributeList& rAttribs ); + /** Reads the boolean value from a pivot cache item. */ + void readBool( const AttributeList& rAttribs ); + /** Reads the error code value from a pivot cache item. */ + void readError( const AttributeList& rAttribs, const UnitConverter& rUnitConverter ); + /** Reads the index of a shared item. */ + void readIndex( const AttributeList& rAttribs ); + + /** Reads the string value from a pivot cache item. */ + void readString( SequenceInputStream& rStrm ); + /** Reads the double value from a pivot cache item. */ + void readDouble( SequenceInputStream& rStrm ); + /** Reads the date/time value from a pivot cache item. */ + void readDate( SequenceInputStream& rStrm ); + /** Reads the boolean value from a pivot cache item. */ + void readBool( SequenceInputStream& rStrm ); + /** Reads the error code value from a pivot cache item. */ + void readError( SequenceInputStream& rStrm ); + /** Reads the index of a shared item. */ + void readIndex( SequenceInputStream& rStrm ); + + /** Reads the string value from a pivot cache item. */ + void readString( BiffInputStream& rStrm, const WorkbookHelper& rHelper ); + /** Reads the double value from a pivot cache item. */ + void readDouble( BiffInputStream& rStrm ); + /** Reads the integer value from a pivot cache item. */ + void readInteger( BiffInputStream& rStrm ); + /** Reads the date/time value from a pivot cache item. */ + void readDate( BiffInputStream& rStrm ); + /** Reads the boolean value from a pivot cache item. */ + void readBool( BiffInputStream& rStrm ); + /** Reads the error code value from a pivot cache item. */ + void readError( BiffInputStream& rStrm ); + + /** Returns the type of the item. */ + inline sal_Int32 getType() const { return mnType; } + /** Returns the value of the item. */ + inline const ::com::sun::star::uno::Any& getValue() const { return maValue; } + /** Returns the string representation of the item. */ + ::rtl::OUString getName() const; + +private: + ::com::sun::star::uno::Any maValue; /// Value of the item. + sal_Int32 mnType; /// Value type (OOXML token identifier). +}; + +// ---------------------------------------------------------------------------- + +class PivotCacheItemList : public WorkbookHelper +{ +public: + explicit PivotCacheItemList( const WorkbookHelper& rHelper ); + + /** Imports the item from the passed attribute list. */ + void importItem( sal_Int32 nElement, const AttributeList& rAttribs ); + /** Imports the item from the passed stream and record. */ + void importItem( sal_Int32 nRecId, SequenceInputStream& rStrm ); + /** Imports a complete item list from the passed stream. */ + void importItemList( BiffInputStream& rStrm, sal_uInt16 nCount ); + + /** Returns true, if this item list is empty. */ + inline bool empty() const { return maItems.empty(); } + /** Returns the size of the item list. */ + inline size_t size() const { return maItems.size(); } + + /** Returns the specified item. */ + const PivotCacheItem* getCacheItem( sal_Int32 nItemIdx ) const; + /** Returns the names of all items. */ + void getCacheItemNames( ::std::vector< ::rtl::OUString >& orItemNames ) const; + +private: + /** Creates and returns a new item at the end of the items list. */ + PivotCacheItem& createItem(); + /** Imports an array of items from the PCITEM_ARRAY record */ + void importArray( SequenceInputStream& rStrm ); + +private: + typedef ::std::vector< PivotCacheItem > CacheItemVector; + CacheItemVector maItems; /// All items of this list. +}; + +// ============================================================================ + +struct PCFieldModel +{ + ::rtl::OUString maName; /// Fixed name of the cache field. + ::rtl::OUString maCaption; /// Caption of the ccahe field. + ::rtl::OUString maPropertyName; /// OLAP property name. + ::rtl::OUString maFormula; /// Formula of a calculated field. + sal_Int32 mnNumFmtId; /// Number format for all items. + sal_Int32 mnSqlType; /// Data type from ODBC data source. + sal_Int32 mnHierarchy; /// Hierarchy this field is part of. + sal_Int32 mnLevel; /// Hierarchy level this field is part of. + sal_Int32 mnMappingCount; /// Number of property mappings. + bool mbDatabaseField; /// True = field from source data; false = calculated field. + bool mbServerField; /// True = ODBC server-based page field. + bool mbUniqueList; /// True = list of unique ODBC items exists. + bool mbMemberPropField; /// True = contains OLAP member properties. + + explicit PCFieldModel(); +}; + +// ---------------------------------------------------------------------------- + +struct PCSharedItemsModel +{ + bool mbHasSemiMixed; /// True = has (blank|string|bool|error) item(s), maybe other types. + bool mbHasNonDate; /// True = has non-date item(s), maybe date items. + bool mbHasDate; /// True = has date item(s), maybe other types. + bool mbHasString; /// True = has (string|bool|error) item(s), maybe other types. + bool mbHasBlank; /// True = has blank item(s), maybe other types. + bool mbHasMixed; /// True = has [(string|bool|error) and (number|date)] or (number and date). + bool mbIsNumeric; /// True = has numeric item(s), maybe other types except date. + bool mbIsInteger; /// True = has numeric item(s) with only integers, maybe other types except date. + bool mbHasLongText; /// True = contains strings with >255 charascters. + bool mbHasLongIndexes; /// True = indexes to shared items are 16-bit (BIFF only). + + explicit PCSharedItemsModel(); +}; + +// ---------------------------------------------------------------------------- + +struct PCFieldGroupModel +{ + ::com::sun::star::util::DateTime maStartDate; /// Manual or calculated start date for range grouping. + ::com::sun::star::util::DateTime maEndDate; /// Manual or calculated end date for range grouping. + double mfStartValue; /// Manual or calculated start value for range grouping. + double mfEndValue; /// Manual or calculated end value for range grouping. + double mfInterval; /// Interval for numeric range grouping. + sal_Int32 mnParentField; /// Index of cache field that contains item groups based on this field. + sal_Int32 mnBaseField; /// Index of cache field this grouped field is based on. + sal_Int32 mnGroupBy; /// Type of numeric or date range grouping. + bool mbRangeGroup; /// True = items are grouped by numeric ranges or date ranges. + bool mbDateGroup; /// True = items are grouped by date ranges or by item names. + bool mbAutoStart; /// True = start value for range groups is calculated from source data. + bool mbAutoEnd; /// True = end value for range groups is calculated from source data. + + explicit PCFieldGroupModel(); + + /** Sets the group-by value for BIFF import. */ + void setBiffGroupBy( sal_uInt8 nGroupBy ); +}; + +// ---------------------------------------------------------------------------- + +/** Helper struct for mapping original item names from/to group item names. */ +struct PivotCacheGroupItem +{ + ::rtl::OUString maOrigName; + ::rtl::OUString maGroupName; + + inline explicit PivotCacheGroupItem( const ::rtl::OUString& rItemName ) : + maOrigName( rItemName ), maGroupName( rItemName ) {} +}; + +typedef ::std::vector< PivotCacheGroupItem > PivotCacheGroupItemVector; + +// ---------------------------------------------------------------------------- + +class PivotCacheField : public WorkbookHelper +{ +public: + explicit PivotCacheField( const WorkbookHelper& rHelper, bool bIsDatabaseField ); + + /** Imports pivot cache field settings from the cacheField element. */ + void importCacheField( const AttributeList& rAttribs ); + /** Imports shared items settings from the sharedItems element. */ + void importSharedItems( const AttributeList& rAttribs ); + /** Imports a shared item from the passed element. */ + void importSharedItem( sal_Int32 nElement, const AttributeList& rAttribs ); + /** Imports grouping settings from the fieldGroup element. */ + void importFieldGroup( const AttributeList& rAttribs ); + /** Imports numeric grouping settings from the rangePr element. */ + void importRangePr( const AttributeList& rAttribs ); + /** Imports an item of the mapping between group items and base items from the passed element. */ + void importDiscretePrItem( sal_Int32 nElement, const AttributeList& rAttribs ); + /** Imports a group item from the passed element. */ + void importGroupItem( sal_Int32 nElement, const AttributeList& rAttribs ); + + /** Imports pivot cache field settings from the PCDFIELD record. */ + void importPCDField( SequenceInputStream& rStrm ); + /** Imports shared items settings from the PCDFSHAREDITEMS record. */ + void importPCDFSharedItems( SequenceInputStream& rStrm ); + /** Imports one or more shared items from the passed record. */ + void importPCDFSharedItem( sal_Int32 nRecId, SequenceInputStream& rStrm ); + /** Imports grouping settings from the PCDFIELDGROUP record. */ + void importPCDFieldGroup( SequenceInputStream& rStrm ); + /** Imports numeric grouping settings from the PCDFRANGEPR record. */ + void importPCDFRangePr( SequenceInputStream& rStrm ); + /** Imports an item of the mapping between group items and base items from the passed record. */ + void importPCDFDiscretePrItem( sal_Int32 nRecId, SequenceInputStream& rStrm ); + /** Imports one or more group items from the passed record. */ + void importPCDFGroupItem( sal_Int32 nRecId, SequenceInputStream& rStrm ); + + /** Imports pivot cache field settings from the PCDFIELD record. */ + void importPCDField( BiffInputStream& rStrm ); + /** Imports numeric grouping settings from the PCDFRANGEPR record. */ + void importPCDFRangePr( BiffInputStream& rStrm ); + /** Imports the mapping between group items and base items from the PCDFDISCRETEPR record. */ + void importPCDFDiscretePr( BiffInputStream& rStrm ); + + /** Returns true, if the field is based on source data, or false if it is grouped or calculated. */ + inline bool isDatabaseField() const { return maFieldModel.mbDatabaseField; } + + /** Returns true, if the field contains a list of shared items. */ + inline bool hasSharedItems() const { return !maSharedItems.empty(); } + /** Returns true, if the field contains a list of grouping items. */ + inline bool hasGroupItems() const { return !maGroupItems.empty(); } + /** Returns true, if the field has inplace numeric grouping settings. */ + inline bool hasNumericGrouping() const { return maFieldGroupModel.mbRangeGroup && !maFieldGroupModel.mbDateGroup; } + /** Returns true, if the field has inplace date grouping settings. */ + inline bool hasDateGrouping() const { return maFieldGroupModel.mbRangeGroup && maFieldGroupModel.mbDateGroup; } + /** Returns true, if the field has a parent group field that groups the items of this field. */ + inline bool hasParentGrouping() const { return maFieldGroupModel.mnParentField >= 0; } + + /** Returns the name of the cache field. */ + inline const ::rtl::OUString& getName() const { return maFieldModel.maName; } + /** Returns the index of the parent group field that groups the items of this field. */ + inline sal_Int32 getParentGroupField() const { return maFieldGroupModel.mnParentField; } + /** Returns the index of the base field grouping is based on. */ + inline sal_Int32 getGroupBaseField() const { return maFieldGroupModel.mnBaseField; } + + /** Returns the shared or group item with the specified index. */ + const PivotCacheItem* getCacheItem( sal_Int32 nItemIdx ) const; + /** Returns the names of all shared or group items. */ + void getCacheItemNames( ::std::vector< ::rtl::OUString >& orItemNames ) const; + + /** Creates inplace numeric grouping settings. */ + void convertNumericGrouping( + const ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XDataPilotField >& rxDPField ) const; + /** Creates inplace date grouping settings or a new date group field. */ + ::rtl::OUString createDateGroupField( + const ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XDataPilotField >& rxBaseDPField ) const; + /** Creates a new grouped DataPilot field and returns its name. */ + ::rtl::OUString createParentGroupField( + const ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XDataPilotField >& rxBaseDPField, + PivotCacheGroupItemVector& orItemNames ) const; + + /** Writes the title of the field into the passed sheet at the passed address. */ + void writeSourceHeaderCell( WorksheetHelper& rSheetHelper, + sal_Int32 nCol, sal_Int32 nRow ) const; + /** Writes a source field item value into the passed sheet. */ + void writeSourceDataCell( WorksheetHelper& rSheetHelper, + sal_Int32 nCol, sal_Int32 nRow, + const PivotCacheItem& rItem ) const; + + /** Reads an item from the PCRECORD record and writes it to the passed sheet. */ + void importPCRecordItem( SequenceInputStream& rStrm, + WorksheetHelper& rSheetHelper, sal_Int32 nCol, sal_Int32 nRow ) const; + /** Reads an item index from the PCITEM_INDEXLIST record and writes the item to the passed sheet. */ + void importPCItemIndex( BiffInputStream& rStrm, + WorksheetHelper& rSheetHelper, sal_Int32 nCol, sal_Int32 nRow ) const; + + +private: + /** Tries to write the passed value to the passed sheet position. */ + void writeItemToSourceDataCell( WorksheetHelper& rSheetHelper, + sal_Int32 nCol, sal_Int32 nRow, const PivotCacheItem& rItem ) const; + /** Tries to write the value of a shared item to the passed sheet position. */ + void writeSharedItemToSourceDataCell( WorksheetHelper& rSheetHelper, + sal_Int32 nCol, sal_Int32 nRow, sal_Int32 nItemIdx ) const; + +private: + typedef ::std::vector< sal_Int32 > IndexVector; + + PivotCacheItemList maSharedItems; /// All shared items of this field. + PivotCacheItemList maGroupItems; /// All group items of this field. + IndexVector maDiscreteItems; /// Mapping between group and base items. + PCFieldModel maFieldModel; /// Settings for this cache field. + PCSharedItemsModel maSharedItemsModel; /// Settings for shared items. + PCFieldGroupModel maFieldGroupModel; /// Settings for item grouping. +}; + +// ============================================================================ + +struct PCDefinitionModel +{ + ::rtl::OUString maRelId; /// Relation identifier for cache records fragment. + ::rtl::OUString maRefreshedBy; /// Name of user who last refreshed the cache. + double mfRefreshedDate; /// Date/time of last refresh. + sal_Int32 mnRecords; /// Number of data records in the cache. + sal_Int32 mnMissItemsLimit; /// Limit for discarding unused items. + sal_uInt16 mnDatabaseFields; /// Number of database (source data) fields (BIFF only). + bool mbInvalid; /// True = cache needs refresh. + bool mbSaveData; /// True = cached item values are present. + bool mbRefreshOnLoad; /// True = try to refresh cache on load. + bool mbOptimizeMemory; /// True = application may optimize memory usage. + bool mbEnableRefresh; /// True = refreshing cache is enabled in UI. + bool mbBackgroundQuery; /// True = application queries data asynchonously. + bool mbUpgradeOnRefresh; /// True = application may upgrade cache version. + bool mbTupleCache; /// True = cache stores OLAP functions. + bool mbSupportSubquery; /// True = data source supports subqueries. + bool mbSupportDrill; /// True = data source supports drilldown. + + explicit PCDefinitionModel(); +}; + +// ---------------------------------------------------------------------------- + +struct PCSourceModel +{ + sal_Int32 mnSourceType; /// Type of the source data (sheet, consolidation, scenario, external). + sal_Int32 mnConnectionId; /// Connection identifier for external data source. + + explicit PCSourceModel(); +}; + +// ---------------------------------------------------------------------------- + +struct PCWorksheetSourceModel +{ + ::rtl::OUString maRelId; /// Relation identifier for an external document URL. + ::rtl::OUString maSheet; /// Sheet name for cell range or sheet-local defined names. + ::rtl::OUString maDefName; /// Defined name containing a cell range if present. + ::com::sun::star::table::CellRangeAddress + maRange; /// Source cell range of the data. + + explicit PCWorksheetSourceModel(); +}; + +// ---------------------------------------------------------------------------- + +class PivotCache : public WorkbookHelper +{ +public: + explicit PivotCache( const WorkbookHelper& rHelper ); + + /** Reads pivot cache global settings from the pivotCacheDefinition element. */ + void importPivotCacheDefinition( const AttributeList& rAttribs ); + /** Reads cache source settings from the cacheSource element. */ + void importCacheSource( const AttributeList& rAttribs ); + /** Reads sheet source settings from the worksheetSource element. */ + void importWorksheetSource( const AttributeList& rAttribs, const ::oox::core::Relations& rRelations ); + + /** Reads pivot cache global settings from the PCDEFINITION record. */ + void importPCDefinition( SequenceInputStream& rStrm ); + /** Reads cache source settings from the PCDSOURCE record. */ + void importPCDSource( SequenceInputStream& rStrm ); + /** Reads sheet source settings from the PCDSHEETSOURCE record. */ + void importPCDSheetSource( SequenceInputStream& rStrm, const ::oox::core::Relations& rRelations ); + + /** Reads cache source settings from the PCDSOURCE record. */ + void importPCDSource( BiffInputStream& rStrm ); + /** Reads pivot cache global settings from the PCDEFINITION record. */ + void importPCDefinition( BiffInputStream& rStrm ); + + /** Creates and returns a new pivot cache field. */ + PivotCacheField& createCacheField( bool bInitDatabaseField = false ); + /** Checks validity of source data and creates a dummy data sheet for external sheet sources. */ + void finalizeImport(); + + /** Returns true, if the pivot cache is based on a valid data source, so + that pivot tables can be created based on this pivot cache. */ + inline bool isValidDataSource() const { return mbValidSource; } + /** Returns true, if the pivot cache is based on a dummy sheet created in finalizeImport. */ + inline bool isBasedOnDummySheet() const { return mbDummySheet; } + /** Returns the internal cell range the cache is based on. */ + inline const ::com::sun::star::table::CellRangeAddress& + getSourceRange() const { return maSheetSrcModel.maRange; } + /** Returns the relation identifier of the pivot cache records fragment. */ + inline const ::rtl::OUString& getRecordsRelId() const { return maDefModel.maRelId; } + + /** Returns the number of pivot cache fields. */ + sal_Int32 getCacheFieldCount() const; + /** Returns the cache field with the specified index. */ + const PivotCacheField* getCacheField( sal_Int32 nFieldIdx ) const; + /** Returns the source column index of the field with the passed index. */ + sal_Int32 getCacheDatabaseIndex( sal_Int32 nFieldIdx ) const; + + /** Writes the titles of all source fields into the passed sheet. */ + 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, + 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; + /** Reads a PCITEM_INDEXLIST record and writes all item values to the passed sheet. */ + void importPCItemIndexList( BiffInputStream& rStrm, + WorksheetHelper& rSheetHelper, sal_Int32 nRow ) const; + +private: + /** Reads the worksheet source range from the DCONREF record. */ + void importDConRef( BiffInputStream& rStrm ); + /** Reads the defined name used for source data from the DCONNAME record. */ + void importDConName( BiffInputStream& rStrm ); + /** Reads the built-in defined name used for source data from the DCONBINAME record. */ + void importDConBIName( BiffInputStream& rStrm ); + /** Reads the sheet name and URL from the DCONREF, DCONNAME, or DCONBINAME records. */ + void importDConUrl( BiffInputStream& rStrm ); + + /** Finalizes the pivot cache if it is based on internal sheet data. */ + void finalizeInternalSheetSource(); + /** Finalizes the pivot cache if it is based on sheet data of an external spreadsheet document. */ + void finalizeExternalSheetSource(); + /** Creates a dummy sheet that will be filled with the pivot cache data. */ + void prepareSourceDataSheet(); + +private: + typedef RefVector< PivotCacheField > PivotCacheFieldVector; + typedef ::std::vector< sal_Int32 > IndexVector; + + PivotCacheFieldVector maFields; /// All pivot cache fields. + PivotCacheFieldVector maDatabaseFields; /// All cache fields that are based on source data. + IndexVector maDatabaseIndexes; /// Database field index for all fields. + PCDefinitionModel maDefModel; /// Global pivot cache settings. + PCSourceModel maSourceModel; /// Pivot cache source settings. + PCWorksheetSourceModel maSheetSrcModel; /// Sheet source data if cache type is sheet. + ::rtl::OUString maTargetUrl; /// URL of an external source document. + bool mbValidSource; /// True = pivot cache is based on supported data source. + bool mbDummySheet; /// True = pivot cache is based on a dummy sheet. +}; + +// ============================================================================ + +class PivotCacheBuffer : public WorkbookHelper +{ +public: + explicit PivotCacheBuffer( const WorkbookHelper& rHelper ); + + /** Registers a pivot cache definition fragment. The fragment will be loaded on demand (OOXML/BIFF12 only). */ + void registerPivotCacheFragment( sal_Int32 nCacheId, const ::rtl::OUString& rFragmentPath ); + /** Reads the reference to a pivot cache stream. The stream will be loaded on demand (BIFF2-BIFF8 only). */ + void importPivotCacheRef( BiffInputStream& rStrm ); + + /** Imports and stores a pivot cache definition fragment on first call, + returns the imported cache on subsequent calls with the same identifier. */ + PivotCache* importPivotCacheFragment( sal_Int32 nCacheId ); + +private: + /** Creates and returns a new pivot cache object with the passed identifier. */ + PivotCache& createPivotCache( sal_Int32 nCacheId ); + +private: + typedef ::std::map< sal_Int32, ::rtl::OUString > FragmentPathMap; + typedef RefMap< sal_Int32, PivotCache > PivotCacheMap; + typedef ::std::vector< sal_Int32 > PivotCacheIdVector; + + FragmentPathMap maFragmentPaths; + PivotCacheMap maCaches; + PivotCacheIdVector maCacheIds; +}; + +// ============================================================================ + +} // namespace xls +} // namespace oox + +#endif diff --git a/oox/inc/oox/xls/pivotcachefragment.hxx b/oox/inc/oox/xls/pivotcachefragment.hxx new file mode 100644 index 000000000000..34a833e26525 --- /dev/null +++ b/oox/inc/oox/xls/pivotcachefragment.hxx @@ -0,0 +1,155 @@ +/************************************************************************* + * + * 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_PIVOTCACHEFRAGMENT_HXX +#define OOX_XLS_PIVOTCACHEFRAGMENT_HXX + +#include "oox/xls/excelhandlers.hxx" + +namespace oox { +namespace xls { + +class PivotCache; +class PivotCacheField; + +// ============================================================================ + +class PivotCacheFieldContext : public WorkbookContextBase +{ +public: + explicit PivotCacheFieldContext( + WorkbookFragmentBase& rFragment, + PivotCacheField& rCacheField ); + +protected: + virtual ::oox::core::ContextHandlerRef onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ); + virtual void onStartElement( const AttributeList& rAttribs ); + virtual ::oox::core::ContextHandlerRef onCreateRecordContext( sal_Int32 nRecId, SequenceInputStream& rStrm ); + virtual void onStartRecord( SequenceInputStream& rStrm ); + +private: + PivotCacheField& mrCacheField; +}; + +// ============================================================================ + +class PivotCacheDefinitionFragment : public WorkbookFragmentBase +{ +public: + explicit PivotCacheDefinitionFragment( + const WorkbookHelper& rHelper, + const ::rtl::OUString& rFragmentPath, + PivotCache& rPivotCache ); + +protected: + virtual ::oox::core::ContextHandlerRef onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ); + virtual ::oox::core::ContextHandlerRef onCreateRecordContext( sal_Int32 nRecId, SequenceInputStream& rStrm ); + virtual const ::oox::core::RecordInfo* getRecordInfos() const; + virtual void finalizeImport(); + +private: + PivotCache& mrPivotCache; +}; + +// ============================================================================ + +class PivotCacheRecordsFragment : public WorksheetFragmentBase +{ +public: + explicit PivotCacheRecordsFragment( + const WorkbookHelper& rHelper, + const ::rtl::OUString& rFragmentPath, + const PivotCache& rPivotCache ); + +protected: + virtual ::oox::core::ContextHandlerRef onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ); + virtual ::oox::core::ContextHandlerRef onCreateRecordContext( sal_Int32 nRecId, SequenceInputStream& rStrm ); + virtual const ::oox::core::RecordInfo* getRecordInfos() const; + +private: + void startCacheRecord(); + void importPCRecord( SequenceInputStream& rStrm ); + void importPCRecordItem( sal_Int32 nRecId, SequenceInputStream& rStrm ); + +private: + const PivotCache& mrPivotCache; + sal_Int32 mnCol; + sal_Int32 mnRow; + bool mbInRecord; +}; + +// ============================================================================ +// ============================================================================ + +class BiffPivotCacheFragment : public BiffWorkbookFragmentBase +{ +public: + explicit BiffPivotCacheFragment( + const WorkbookHelper& rHelper, + const ::rtl::OUString& rStrmName, + PivotCache& rPivotCache ); + + /** Imports the entire fragment, returns true, if EOF record has been reached. */ + virtual bool importFragment(); + +private: + PivotCache& mrPivotCache; +}; + +// ============================================================================ + +class BiffPivotCacheRecordsContext : public BiffWorksheetContextBase +{ +public: + explicit BiffPivotCacheRecordsContext( + const WorkbookHelper& rHelper, + const PivotCache& rPivotCache ); + + /** Reads the current record from stream and tries to insert a cell into + the source data sheet. */ + virtual void importRecord( BiffInputStream& rStrm ); + +private: + void startNextRow(); + +private: + typedef ::std::vector< sal_Int32 > ColumnIndexVector; + + 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). + bool mbHasShared; /// True = pivot cache contains fields with shared items. + bool mbInRow; /// True = a data row has been started. +}; + +// ============================================================================ + +} // namespace xls +} // namespace oox + +#endif diff --git a/oox/inc/oox/xls/pivottablebuffer.hxx b/oox/inc/oox/xls/pivottablebuffer.hxx new file mode 100644 index 000000000000..7732037bd579 --- /dev/null +++ b/oox/inc/oox/xls/pivottablebuffer.hxx @@ -0,0 +1,448 @@ +/************************************************************************* + * + * 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_PIVOTTABLEBUFFER_HXX +#define OOX_XLS_PIVOTTABLEBUFFER_HXX + +#include <com/sun/star/table/CellRangeAddress.hpp> +#include "oox/xls/pivotcachebuffer.hxx" +#include "oox/xls/stylesbuffer.hxx" + +namespace com { namespace sun { namespace star { + namespace sheet { class XDataPilotDescriptor; } + namespace sheet { class XDataPilotField; } +} } } + +namespace oox { +namespace xls { + +class PivotTable; + +// ============================================================================ + +struct PTFieldItemModel +{ + sal_Int32 mnCacheItem; /// Index to shared item in pivot cache. + sal_Int32 mnType; /// Type of the item. + bool mbShowDetails; /// True = show item details (items of child fields). + bool mbHidden; /// True = item is hidden. + + explicit PTFieldItemModel(); + + /** Sets item type for BIFF import. */ + void setBiffType( sal_uInt16 nType ); +}; + +// ---------------------------------------------------------------------------- + +struct PTFieldModel +{ + sal_Int32 mnAxis; /// Axis this field is assigned to (none, row, column, page). + sal_Int32 mnNumFmtId; /// Number format for field items. + sal_Int32 mnAutoShowItems; /// Number of items (or percent/sum) to be shown in auto show filter. + sal_Int32 mnAutoShowRankBy; /// Index of the data field auto show filter is based on. + sal_Int32 mnSortType; /// Autosorting type. + sal_Int32 mnSortRefField; /// Reference field for autosorting. + sal_Int32 mnSortRefItem; /// Item in reference field for autosorting. + bool mbDataField; /// True = field appears in data area. + bool mbDefaultSubtotal; /// True = show default subtotals. + bool mbSumSubtotal; /// True = show sum subtotals. + bool mbCountASubtotal; /// True = show count all subtotals. + bool mbAverageSubtotal; /// True = show average subtotals. + bool mbMaxSubtotal; /// True = show maximum subtotals. + bool mbMinSubtotal; /// True = show minimum subtotals. + bool mbProductSubtotal; /// True = show product subtotals. + bool mbCountSubtotal; /// True = show count numbers subtotals. + bool mbStdDevSubtotal; /// True = show standard deviation subtotals. + bool mbStdDevPSubtotal; /// True = show standard deviation of population subtotals. + bool mbVarSubtotal; /// True = show variance subtotals. + bool mbVarPSubtotal; /// True = show variance of population subtotals. + bool mbShowAll; /// True = show items without data. + bool mbOutline; /// True = show in outline view, false = show in tabular view. + bool mbSubtotalTop; /// True = show subtotals on top of items in outline or compact mode. + bool mbInsertBlankRow; /// True = insert blank rows after items. + bool mbInsertPageBreak; /// True = insert page breaks after items. + bool mbAutoShow; /// True = auto show (top 10) filter enabled. + bool mbTopAutoShow; /// True = auto show filter shows top entries, false = bottom. + bool mbMultiPageItems; /// True = multiple items selectable in page diemsion. + + explicit PTFieldModel(); + + /** Sets axis type for BIFF import. */ + void setBiffAxis( sal_uInt8 nAxisFlags ); +}; + +// ---------------------------------------------------------------------------- + +struct PTPageFieldModel +{ + ::rtl::OUString maName; /// Unique name of the page field. + sal_Int32 mnField; /// Base pivot field. + sal_Int32 mnItem; /// Index of field item that is shown by the page field. + + explicit PTPageFieldModel(); +}; + +// ---------------------------------------------------------------------------- + +struct PTDataFieldModel +{ + ::rtl::OUString maName; /// Name of the data field. + sal_Int32 mnField; /// Base pivot field. + sal_Int32 mnSubtotal; /// Subtotal aggregation function. + sal_Int32 mnShowDataAs; /// Show data as, based on another field. + sal_Int32 mnBaseField; /// Base field for 'show data as'. + sal_Int32 mnBaseItem; /// Base item for 'show data as'. + sal_Int32 mnNumFmtId; /// Number format for the result. + + explicit PTDataFieldModel(); + + /** Sets the subtotal aggregation function for BIFF import. */ + void setBiffSubtotal( sal_Int32 nSubtotal ); + /** Sets the 'show data as' type for BIFF import. */ + void setBiffShowDataAs( sal_Int32 nShowDataAs ); +}; + +// ---------------------------------------------------------------------------- + +class PivotTableField : public WorkbookHelper +{ +public: + explicit PivotTableField( PivotTable& rPivotTable, sal_Int32 nFieldIndex ); + + /** Imports pivot field settings from the pivotField element. */ + void importPivotField( const AttributeList& rAttribs ); + /** Imports settings of an item in this pivot field from the item element. */ + void importItem( const AttributeList& rAttribs ); + /** Imports pivot field reference settings from the reference element. */ + void importReference( const AttributeList& rAttribs ); + /** Imports pivot field item reference settings from the x element. */ + void importReferenceItem( const AttributeList& rAttribs ); + + /** Imports pivot field settings from the PTFIELD record. */ + void importPTField( SequenceInputStream& rStrm ); + /** Imports settings of an item in this pivot field from the PTFITEM record. */ + void importPTFItem( SequenceInputStream& rStrm ); + /** Imports pivot field reference settings from the PTREFERENCE record. */ + void importPTReference( SequenceInputStream& rStrm ); + /** Imports pivot field item reference settings from the PTREFERENCEITEM record. */ + void importPTReferenceItem( SequenceInputStream& rStrm ); + + /** Imports pivot field settings from the PTFIELD and following records. */ + void importPTField( BiffInputStream& rStrm ); + /** Imports pivot field settings from the PTFIELD2 record. */ + void importPTField2( BiffInputStream& rStrm ); + /** Imports settings of an item in this pivot field from the PTFITEM record. */ + void importPTFItem( BiffInputStream& rStrm ); + + /** Finalizes the field after import, creates grouping and other settings. */ + void finalizeImport( + const ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XDataPilotDescriptor >& rxDPDesc ); + /** Finalizes the grouped date field after import. */ + void finalizeDateGroupingImport( + const ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XDataPilotField >& rxBaseDPField, + sal_Int32 nBaseFieldIdx ); + /** Finalizes the grouped field after import. */ + void finalizeParentGroupingImport( + const ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XDataPilotField >& rxBaseDPField, + PivotCacheGroupItemVector& orItemNames ); + + /** Returns the name of the DataPilot field in the fields collection. */ + inline const ::rtl::OUString& getDPFieldName() const { return maDPFieldName; } + + /** Converts dimension and other settings for a row field. */ + void convertRowField(); + /** Converts dimension and other settings for a column field. */ + void convertColField(); + /** Converts dimension and other settings for a hidden field. */ + void convertHiddenField(); + /** Converts dimension and other settings for a page field */ + void convertPageField( const PTPageFieldModel& rPageField ); + /** Converts dimension and other settings for a data field. */ + void convertDataField( const PTDataFieldModel& rDataField ); + +private: + /** Converts dimension and other settings for row, column, page, or hidden fields. */ + ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XDataPilotField > + convertRowColPageField( sal_Int32 nAxis ); + +private: + typedef ::std::vector< PTFieldItemModel > ItemModelVector; + + PivotTable& mrPivotTable; /// The parent pivot table object. + ItemModelVector maItems; /// All items of this field. + PTFieldModel maModel; /// Pivot field settings. + ::rtl::OUString maDPFieldName; /// Name of the field in DataPilot field collection. + sal_Int32 mnFieldIndex; /// Zero-based index of this field. +}; + +// ============================================================================ + +struct PTFilterModel +{ + ::rtl::OUString maName; /// Name of the field filter. + ::rtl::OUString maDescription; /// Description of the field filter. + ::rtl::OUString maStrValue1; /// First string value for label filter. + ::rtl::OUString maStrValue2; /// Second string value for label filter. + double mfValue; /// Number of items or percent or sum to be shown. + sal_Int32 mnField; /// Base pivot field. + sal_Int32 mnMemPropField; /// Member property field. + sal_Int32 mnType; /// Filter type. + sal_Int32 mnEvalOrder; /// Evaluation order index. + sal_Int32 mnId; /// Unique identifier. + sal_Int32 mnMeasureField; /// Data field for filter calculation. + sal_Int32 mnMeasureHier; /// Hierarchy for filter calculation. + bool mbTopFilter; /// True = filter shows top entries, false = bottom. + + explicit PTFilterModel(); +}; + +// ---------------------------------------------------------------------------- + +class PivotTableFilter : public WorkbookHelper +{ +public: + explicit PivotTableFilter( const PivotTable& rPivotTable ); + + /** Reads the settings of a field filter from the filter element. */ + void importFilter( const AttributeList& rAttribs ); + /** Reads additional settings of a field filter from the top10 element. */ + void importTop10( const AttributeList& rAttribs ); + + /** Reads the settings of a field filter from the PTFILTER record. */ + void importPTFilter( SequenceInputStream& rStrm ); + /** Reads additional settings of a field filter from the TOP10FILTER record. */ + void importTop10Filter( SequenceInputStream& rStrm ); + + /** Applies the filter to the associated pivot table field if possible. */ + void finalizeImport(); + +private: + const PivotTable& mrPivotTable; + PTFilterModel maModel; +}; + +// ============================================================================ + +struct PTDefinitionModel : public AutoFormatModel +{ + ::rtl::OUString maName; + ::rtl::OUString maDataCaption; + ::rtl::OUString maGrandTotalCaption; + ::rtl::OUString maRowHeaderCaption; + ::rtl::OUString maColHeaderCaption; + ::rtl::OUString maErrorCaption; + ::rtl::OUString maMissingCaption; + ::rtl::OUString maPageStyle; + ::rtl::OUString maPivotTableStyle; + ::rtl::OUString maVacatedStyle; + ::rtl::OUString maTag; + sal_Int32 mnCacheId; + sal_Int32 mnDataPosition; + sal_Int32 mnPageWrap; + sal_Int32 mnIndent; + sal_Int32 mnChartFormat; + sal_uInt16 mnRowFields; + sal_uInt16 mnColFields; + bool mbDataOnRows; + bool mbShowError; + bool mbShowMissing; + bool mbShowItems; + bool mbDisableFieldList; + bool mbShowCalcMembers; + bool mbVisualTotals; + bool mbShowDataDropDown; + bool mbShowDrill; + bool mbPrintDrill; + bool mbEnableDrill; + bool mbPreserveFormatting; + bool mbUseAutoFormat; + bool mbPageOverThenDown; + bool mbSubtotalHiddenItems; + bool mbRowGrandTotals; + bool mbColGrandTotals; + bool mbFieldPrintTitles; + bool mbItemPrintTitles; + bool mbMergeItem; + bool mbShowEmptyRow; + bool mbShowEmptyCol; + bool mbShowHeaders; + bool mbFieldListSortAsc; + bool mbCustomListSort; + + explicit PTDefinitionModel(); +}; + +// ---------------------------------------------------------------------------- + +struct PTLocationModel +{ + ::com::sun::star::table::CellRangeAddress + maRange; /// Target cell range for the pivot table. + sal_Int32 mnFirstHeaderRow; /// First row of header cells (relative in pivot table). + sal_Int32 mnFirstDataRow; /// First row of data cells (relative in pivot table). + sal_Int32 mnFirstDataCol; /// First column of data cells (relative in pivot table). + sal_Int32 mnRowPageCount; /// Number of rows in page filter area. + sal_Int32 mnColPageCount; /// Number of columns in page filter area. + + explicit PTLocationModel(); +}; + +// ---------------------------------------------------------------------------- + +class PivotTable : public WorkbookHelper +{ +public: + explicit PivotTable( const WorkbookHelper& rHelper ); + + /** Reads global pivot table settings from the pivotTableDefinition element. */ + void importPivotTableDefinition( const AttributeList& rAttribs ); + /** Reads the location of the pivot table from the location element. */ + void importLocation( const AttributeList& rAttribs, sal_Int16 nSheet ); + /** Reads the index of a field located in the row dimension. */ + void importRowField( const AttributeList& rAttribs ); + /** Reads the index of a field located in the column dimension. */ + void importColField( const AttributeList& rAttribs ); + /** Reads the settings of a field located in the page dimension from the pageField element. */ + void importPageField( const AttributeList& rAttribs ); + /** Reads the settings of a field located in the data dimension from the dataField element. */ + void importDataField( const AttributeList& rAttribs ); + + /** Reads global pivot table settings from the PTDEFINITION record. */ + void importPTDefinition( SequenceInputStream& rStrm ); + /** Reads the location of the pivot table from the PTLOCATION record. */ + void importPTLocation( SequenceInputStream& rStrm, sal_Int16 nSheet ); + /** Reads the indexes of all fields located in the row dimension from a PTROWFIELDS record. */ + void importPTRowFields( SequenceInputStream& rStrm ); + /** Reads the indexes of all fields located in the column dimension from a PTCOLFIELDS record. */ + void importPTColFields( SequenceInputStream& rStrm ); + /** Reads the settings of a field located in the page dimension from the PTPAGEFIELD record. */ + void importPTPageField( SequenceInputStream& rStrm ); + /** Reads the settings of a field located in the data dimension from the PTDATAFIELD record. */ + void importPTDataField( SequenceInputStream& rStrm ); + + /** Reads global pivot table settings from the PTDEFINITION record. */ + void importPTDefinition( BiffInputStream& rStrm, sal_Int16 nSheet ); + /** Reads additional global pivot table settings from the PTDEFINITION2 record. */ + void importPTDefinition2( BiffInputStream& rStrm ); + /** Reads the indexes of all fields located in the row or column dimension from a PTROWCOLFIELDS record. */ + void importPTRowColFields( BiffInputStream& rStrm ); + /** Reads the settings of all fields located in the page dimension from a PTPAGEFIELDS record. */ + void importPTPageFields( BiffInputStream& rStrm ); + /** Reads the settings of a field located in the data dimension from a PTDATAFIELD record. */ + void importPTDataField( BiffInputStream& rStrm ); + + /** Creates and returns a new pivot table field. */ + PivotTableField& createTableField(); + /** Creates and returns a new pivot table filter. */ + PivotTableFilter& createTableFilter(); + /** Inserts the pivot table into the sheet. */ + void finalizeImport(); + /** Creates all date group fields for the specified cache field after import. */ + void finalizeDateGroupingImport( + const ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XDataPilotField >& rxBaseDPField, + sal_Int32 nBaseFieldIdx ); + /** Creates all grouped fields for the specified cache field after import. */ + void finalizeParentGroupingImport( + const ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XDataPilotField >& rxBaseDPField, + const PivotCacheField& rBaseCacheField, + PivotCacheGroupItemVector& orItemNames ); + + /** Returns the associated data pilot field for the specified pivot table field. */ + ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XDataPilotField > + getDataPilotField( const ::rtl::OUString& rFieldName ) const; + /** Returns the associated data pilot field for the specified pivot table field. */ + ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XDataPilotField > + getDataPilotField( sal_Int32 nFieldIdx ) const; + /** Returns the data layout field used to store all data fields in row/col dimension. */ + ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XDataPilotField > + getDataLayoutField() const; + + /** Returns the cache field with the specified index. */ + const PivotCacheField* getCacheField( sal_Int32 nFieldIdx ) const; + /** Returns the base cache field of the data field item with the specified index. */ + const PivotCacheField* getCacheFieldOfDataField( sal_Int32 nDataItemIdx ) const; + /** Returns the source column index of the pivot field with the passed index, or -1. */ + sal_Int32 getCacheDatabaseIndex( sal_Int32 nFieldIdx ) const; + +private: + typedef RefVector< PivotTableField > PivotTableFieldVector; + typedef RefVector< PivotTableFilter > PivotTableFilterVector; + typedef ::std::vector< sal_Int32 > IndexVector; + typedef ::std::vector< PTPageFieldModel > PageFieldVector; + typedef ::std::vector< PTDataFieldModel > DataFieldVector; + +private: + /** Returns a pivot table field by its index. */ + PivotTableField* getTableField( sal_Int32 nFieldIdx ); + + /** Reads a field index for the row or column dimension. */ + static void importField( IndexVector& orFields, const AttributeList& rAttribs ); + /** Reads an array of field indexes for the row or column dimension. */ + static void importFields( IndexVector& orFields, SequenceInputStream& rStrm ); + /** Reads an array of field indexes for the row or column dimension. */ + static void importFields( IndexVector& orFields, BiffInputStream& rStrm, sal_Int32 nCount ); + +private: + PivotTableFieldVector maFields; /// All pivot table fields. + PivotTableField maDataField; /// Data layout field. + IndexVector maRowFields; /// Indexes to fields in row dimension. + IndexVector maColFields; /// Indexes to fields in column dimension. + PageFieldVector maPageFields; /// Settings for all fields in page dimension. + DataFieldVector maDataFields; /// Settings for all fields in data area. + PivotTableFilterVector maFilters; /// All field filters. + PTDefinitionModel maDefModel; /// Global pivot table settings. + PTLocationModel maLocationModel; /// Location settings of the pivot table. + const PivotCache* mpPivotCache; /// The pivot cache this table is based on. + ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XDataPilotDescriptor > + mxDPDescriptor; /// Descriptor of the DataPilot object. +}; + +// ============================================================================ + +class PivotTableBuffer : public WorkbookHelper +{ +public: + explicit PivotTableBuffer( const WorkbookHelper& rHelper ); + + /** Creates and returns a new pivot table. */ + PivotTable& createPivotTable(); + + /** Inserts all pivot tables into the sheet. */ + void finalizeImport(); + +private: + typedef RefVector< PivotTable > PivotTableVector; + PivotTableVector maTables; +}; + +// ============================================================================ + +} // namespace xls +} // namespace oox + +#endif diff --git a/oox/inc/oox/xls/pivottablefragment.hxx b/oox/inc/oox/xls/pivottablefragment.hxx new file mode 100644 index 000000000000..aafae063990c --- /dev/null +++ b/oox/inc/oox/xls/pivottablefragment.hxx @@ -0,0 +1,117 @@ +/************************************************************************* + * + * 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_PIVOTTABLEFRAGMENT_HXX +#define OOX_XLS_PIVOTTABLEFRAGMENT_HXX + +#include "oox/xls/excelhandlers.hxx" +#include "oox/xls/worksheethelper.hxx" + +namespace oox { +namespace xls { + +class PivotTable; +class PivotTableField; +class PivotTableFilter; + +// ============================================================================ + +class PivotTableFieldContext : public WorksheetContextBase +{ +public: + explicit PivotTableFieldContext( + WorksheetFragmentBase& rFragment, + PivotTableField& rTableField ); + +protected: + virtual ::oox::core::ContextHandlerRef onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ); + virtual void onStartElement( const AttributeList& rAttribs ); + virtual ::oox::core::ContextHandlerRef onCreateRecordContext( sal_Int32 nRecId, SequenceInputStream& rStrm ); + virtual void onStartRecord( SequenceInputStream& rStrm ); + +private: + PivotTableField& mrTableField; +}; + +// ============================================================================ + +class PivotTableFilterContext : public WorksheetContextBase +{ +public: + explicit PivotTableFilterContext( + WorksheetFragmentBase& rFragment, + PivotTableFilter& rTableFilter ); + +protected: + virtual ::oox::core::ContextHandlerRef onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ); + virtual void onStartElement( const AttributeList& rAttribs ); + virtual ::oox::core::ContextHandlerRef onCreateRecordContext( sal_Int32 nRecId, SequenceInputStream& rStrm ); + virtual void onStartRecord( SequenceInputStream& rStrm ); + +private: + PivotTableFilter& mrTableFilter; +}; + +// ============================================================================ + +class PivotTableFragment : public WorksheetFragmentBase +{ +public: + explicit PivotTableFragment( + const WorksheetHelper& rHelper, + const ::rtl::OUString& rFragmentPath ); + +protected: + virtual ::oox::core::ContextHandlerRef onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ); + virtual ::oox::core::ContextHandlerRef onCreateRecordContext( sal_Int32 nRecId, SequenceInputStream& rStrm ); + virtual const ::oox::core::RecordInfo* getRecordInfos() const; + +private: + PivotTable& mrPivotTable; +}; + +// ============================================================================ +// ============================================================================ + +class BiffPivotTableContext : public BiffWorksheetContextBase +{ +public: + explicit BiffPivotTableContext( const WorksheetHelper& rHelper ); + + /** Imports all records related to the current pivot table. */ + virtual void importRecord( BiffInputStream& rStrm ); + +private: + PivotTable& mrPivotTable; +}; + +// ============================================================================ + +} // namespace xls +} // namespace oox + +#endif diff --git a/oox/inc/oox/xls/querytablebuffer.hxx b/oox/inc/oox/xls/querytablebuffer.hxx new file mode 100644 index 000000000000..fa67ca8874c0 --- /dev/null +++ b/oox/inc/oox/xls/querytablebuffer.hxx @@ -0,0 +1,109 @@ +/************************************************************************* + * + * 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_QUERYTABLEBUFFER_HXX +#define OOX_XLS_QUERYTABLEBUFFER_HXX + +#include "oox/xls/stylesbuffer.hxx" +#include "oox/xls/worksheethelper.hxx" + +namespace oox { +namespace xls { + +// ============================================================================ + +struct QueryTableModel : public AutoFormatModel +{ + ::rtl::OUString maDefName; /// Defined name containing the target cell range. + sal_Int32 mnConnId; /// Identifier of the external connection used to query the data. + sal_Int32 mnGrowShrinkType; /// Behaviour when source data size changes. + bool mbHeaders; /// True = source data contains a header row. + bool mbRowNumbers; /// True = first column contains row numbers. + bool mbDisableRefresh; /// True = refreshing data disabled. + bool mbBackground; /// True = refresh asynchronously. + bool mbFirstBackground; /// True = first background refresh not yet finished. + bool mbRefreshOnLoad; /// True = refresh table after import. + bool mbFillFormulas; /// True = expand formulas next to range when source data grows. + bool mbRemoveDataOnSave; /// True = remove querried data before saving. + bool mbDisableEdit; /// True = connection locked for editing. + bool mbPreserveFormat; /// True = use existing formatting for new rows. + bool mbAdjustColWidth; /// True = adjust column widths after refresh. + bool mbIntermediate; /// True = query table defined but not built yet. + + explicit QueryTableModel(); +}; + +// ---------------------------------------------------------------------------- + +class QueryTable : public WorksheetHelper +{ +public: + explicit QueryTable( const WorksheetHelper& rHelper ); + + /** Imports query table settings from the queryTable element. */ + void importQueryTable( const AttributeList& rAttribs ); + /** Imports query table settings from the QUERYTABLE record. */ + void importQueryTable( SequenceInputStream& rStrm ); + + /** Imports query table settings from the QUERYTABLE record. */ + void importQueryTable( BiffInputStream& rStrm ); + /** Imports query table settings from the QUERYTABLEREFRESH record. */ + void importQueryTableRefresh( BiffInputStream& rStrm ); + /** Imports query table settings from the QUERYTABLESETTINGS record. */ + void importQueryTableSettings( BiffInputStream& rStrm ); + + /** Inserts a web query into the sheet. */ + void finalizeImport(); + +private: + QueryTableModel maModel; +}; + +// ============================================================================ + +class QueryTableBuffer : public WorksheetHelper +{ +public: + explicit QueryTableBuffer( const WorksheetHelper& rHelper ); + + /** Creates a new query table and stores it into the internal vector. */ + QueryTable& createQueryTable(); + + /** Inserts all web queries into the sheet. */ + void finalizeImport(); + +private: + typedef RefVector< QueryTable > QueryTableVector; + QueryTableVector maQueryTables; +}; + +// ============================================================================ + +} // namespace xls +} // namespace oox + +#endif diff --git a/oox/inc/oox/xls/querytablefragment.hxx b/oox/inc/oox/xls/querytablefragment.hxx new file mode 100644 index 000000000000..6eb561aa5a5e --- /dev/null +++ b/oox/inc/oox/xls/querytablefragment.hxx @@ -0,0 +1,76 @@ +/************************************************************************* + * + * 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_QUERYTABLEFRAGMENT_HXX +#define OOX_XLS_QUERYTABLEFRAGMENT_HXX + +#include "oox/xls/excelhandlers.hxx" + +namespace oox { +namespace xls { + +class QueryTable; + +// ============================================================================ + +class QueryTableFragment : public WorksheetFragmentBase +{ +public: + explicit QueryTableFragment( + const WorksheetHelper& rHelper, + const ::rtl::OUString& rFragmentPath ); + +protected: + virtual ::oox::core::ContextHandlerRef onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ); + virtual ::oox::core::ContextHandlerRef onCreateRecordContext( sal_Int32 nRecId, SequenceInputStream& rStrm ); + + virtual const ::oox::core::RecordInfo* getRecordInfos() const; + +private: + QueryTable& mrQueryTable; +}; + +// ============================================================================ + +class BiffQueryTableContext : public BiffWorksheetContextBase +{ +public: + explicit BiffQueryTableContext( const WorksheetHelper& rHelper ); + + /** Imports all records related to the current query table. */ + virtual void importRecord( BiffInputStream& rStrm ); + +private: + QueryTable& mrQueryTable; +}; + +// ============================================================================ + +} // namespace xls +} // namespace oox + +#endif diff --git a/oox/inc/oox/xls/richstring.hxx b/oox/inc/oox/xls/richstring.hxx new file mode 100644 index 000000000000..f21e2a021111 --- /dev/null +++ b/oox/inc/oox/xls/richstring.hxx @@ -0,0 +1,294 @@ +/************************************************************************* + * + * 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_RICHSTRING_HXX +#define OOX_XLS_RICHSTRING_HXX + +#include "oox/helper/refvector.hxx" +#include "oox/xls/stylesbuffer.hxx" + +namespace com { namespace sun { namespace star { + namespace text { class XText; } +} } } + +namespace oox { +namespace xls { + +// ============================================================================ + +/** Flags used to specify import/export mode of strings. */ +typedef sal_Int32 BiffStringFlags; + +const BiffStringFlags BIFF_STR_DEFAULT = 0x0000; /// Default string settings. +const BiffStringFlags BIFF_STR_FORCEUNICODE = 0x0001; /// Always use UCS-2 characters (default: try to compress). BIFF8 export only. +const BiffStringFlags BIFF_STR_8BITLENGTH = 0x0002; /// 8-bit string length field (default: 16-bit). +const BiffStringFlags BIFF_STR_SMARTFLAGS = 0x0004; /// Omit flags on empty string (default: read/write always). BIFF8 only. +const BiffStringFlags BIFF_STR_KEEPFONTS = 0x0008; /// Keep old fonts when reading unformatted string (default: clear fonts). Import only. +const BiffStringFlags BIFF_STR_EXTRAFONTS = 0x0010; /// Read trailing rich-string font array (default: nothing). BIFF2-BIFF5 import only. + +// ============================================================================ + +/** Contains text data and font attributes for a part of a rich formatted string. */ +class RichStringPortion : public WorkbookHelper +{ +public: + explicit RichStringPortion( const WorkbookHelper& rHelper ); + + /** Sets text data for this portion. */ + void setText( const ::rtl::OUString& rText ); + /** Creates and returns a new font formatting object. */ + FontRef createFont(); + /** Links this portion to a font object from the global font list. */ + void setFontId( sal_Int32 nFontId ); + + /** Final processing after import of all strings. */ + void finalizeImport(); + + /** Returns the text data of this portion. */ + inline const ::rtl::OUString& getText() const { return maText; } + + /** Converts the portion and appends it to the passed XText. */ + void convert( + const ::com::sun::star::uno::Reference< ::com::sun::star::text::XText >& rxText, + sal_Int32 nXfId ); + +private: + ::rtl::OUString maText; /// Portion text. + FontRef mxFont; /// Embedded portion font, may be empty. + sal_Int32 mnFontId; /// Link to global font list. +}; + +typedef ::boost::shared_ptr< RichStringPortion > RichStringPortionRef; + +// ---------------------------------------------------------------------------- + +enum BiffFontPortionMode +{ + BIFF_FONTPORTION_8BIT, /// Font portion with 8-bit values. + BIFF_FONTPORTION_16BIT, /// Font portion with 16-bit values. + BIFF_FONTPORTION_OBJ /// Font portion in OBJ or TXO record. +}; + +// ---------------------------------------------------------------------------- + +/** Represents a position in a rich-string containing current font identifier. + + This object stores the position of a formatted character in a rich-string + and the identifier of a font from the global font list used to format this + and the following characters. Used in binary filters only. + */ +struct FontPortionModel +{ + sal_Int32 mnPos; /// First character in the string. + sal_Int32 mnFontId; /// Font identifier for the next characters. + + explicit inline FontPortionModel() : mnPos( 0 ), mnFontId( -1 ) {} + explicit inline FontPortionModel( sal_Int32 nPos, sal_Int32 nFontId ) : + mnPos( nPos ), mnFontId( nFontId ) {} + + void read( SequenceInputStream& rStrm ); + void read( BiffInputStream& rStrm, BiffFontPortionMode eMode ); +}; + +// ---------------------------------------------------------------------------- + +/** A vector with all font portions in a rich-string. */ +class FontPortionModelList : public ::std::vector< FontPortionModel > +{ +public: + inline explicit FontPortionModelList() {} + + /** Appends a rich-string font identifier. */ + void appendPortion( const FontPortionModel& rPortion ); + /** Reads count and font identifiers from the passed stream. */ + void importPortions( SequenceInputStream& rStrm ); + /** Reads nCount font identifiers from the passed stream. */ + void importPortions( BiffInputStream& rStrm, sal_uInt16 nCount, BiffFontPortionMode eMode ); + /** Reads count and font identifiers from the passed stream. */ + void importPortions( BiffInputStream& rStrm, bool b16Bit ); +}; + +// ============================================================================ + +struct PhoneticDataModel +{ + sal_Int32 mnFontId; /// Font identifier for text formatting. + sal_Int32 mnType; /// Phonetic text type. + sal_Int32 mnAlignment; /// Phonetic portion alignment. + + explicit PhoneticDataModel(); + + /** Sets the passed data from binary import. */ + void setBiffData( sal_Int32 nType, sal_Int32 nAlignment ); +}; + +// ---------------------------------------------------------------------------- + +class PhoneticSettings : public WorkbookHelper +{ +public: + explicit PhoneticSettings( const WorkbookHelper& rHelper ); + + /** Imports phonetic settings from the phoneticPr element. */ + void importPhoneticPr( const AttributeList& rAttribs ); + /** Imports phonetic settings from the PHONETICPR record. */ + void importPhoneticPr( SequenceInputStream& rStrm ); + /** Imports phonetic settings from the PHONETICPR record. */ + void importPhoneticPr( BiffInputStream& rStrm ); + + /** Imports phonetic settings from a rich string. */ + void importStringData( SequenceInputStream& rStrm ); + /** Imports phonetic settings from a rich string. */ + void importStringData( BiffInputStream& rStrm ); + +private: + PhoneticDataModel maModel; +}; + +// ============================================================================ + +/** Contains text data and positioning information for a phonetic text portion. */ +class RichStringPhonetic : public WorkbookHelper +{ +public: + explicit RichStringPhonetic( const WorkbookHelper& rHelper ); + + /** Sets text data for this phonetic portion. */ + void setText( const ::rtl::OUString& rText ); + /** Imports attributes of a phonetic run (rPh element). */ + void importPhoneticRun( const AttributeList& rAttribs ); + /** Sets the associated range in base text for this phonetic portion. */ + void setBaseRange( sal_Int32 nBasePos, sal_Int32 nBaseEnd ); + +private: + ::rtl::OUString maText; /// Portion text. + sal_Int32 mnBasePos; /// Start position in base text. + sal_Int32 mnBaseEnd; /// One-past-end position in base text. +}; + +typedef ::boost::shared_ptr< RichStringPhonetic > RichStringPhoneticRef; + +// ---------------------------------------------------------------------------- + +/** Represents a phonetic text portion in a rich-string with phonetic text. + Used in binary filters only. */ +struct PhoneticPortionModel +{ + sal_Int32 mnPos; /// First character in phonetic text. + sal_Int32 mnBasePos; /// First character in base text. + sal_Int32 mnBaseLen; /// Number of characters in base text. + + explicit inline PhoneticPortionModel() : mnPos( -1 ), mnBasePos( -1 ), mnBaseLen( 0 ) {} + explicit inline PhoneticPortionModel( sal_Int32 nPos, sal_Int32 nBasePos, sal_Int32 nBaseLen ) : + mnPos( nPos ), mnBasePos( nBasePos ), mnBaseLen( nBaseLen ) {} + + void read( SequenceInputStream& rStrm ); + void read( BiffInputStream& rStrm ); +}; + +// ---------------------------------------------------------------------------- + +/** A vector with all phonetic portions in a rich-string. */ +class PhoneticPortionModelList : public ::std::vector< PhoneticPortionModel > +{ +public: + inline explicit PhoneticPortionModelList() {} + + /** Appends a rich-string phonetic portion. */ + void appendPortion( const PhoneticPortionModel& rPortion ); + /** Reads all phonetic portions from the passed stream. */ + void importPortions( SequenceInputStream& rStrm ); + /** Reads phonetic portion data from the passed stream. */ + ::rtl::OUString importPortions( BiffInputStream& rStrm, sal_Int32 nPhoneticSize ); +}; + +// ============================================================================ + +/** Contains string data and a list of formatting runs for a rich formatted string. */ +class RichString : public WorkbookHelper +{ +public: + explicit RichString( const WorkbookHelper& rHelper ); + + /** Appends and returns a portion object for a plain string (t element). */ + RichStringPortionRef importText( const AttributeList& rAttribs ); + /** Appends and returns a portion object for a new formatting run (r element). */ + RichStringPortionRef importRun( const AttributeList& rAttribs ); + /** Appends and returns a phonetic text object for a new phonetic run (rPh element). */ + RichStringPhoneticRef importPhoneticRun( const AttributeList& rAttribs ); + /** Imports phonetic settings from the rPhoneticPr element. */ + void importPhoneticPr( const AttributeList& rAttribs ); + + /** 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. */ + 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. */ + void convert( + const ::com::sun::star::uno::Reference< ::com::sun::star::text::XText >& rxText, + sal_Int32 nXfId ) const; + +private: + /** Creates, appends, and returns a new empty string portion. */ + RichStringPortionRef createPortion(); + /** Creates, appends, and returns a new empty phonetic text portion. */ + RichStringPhoneticRef createPhonetic(); + + /** Create base text portions from the passed string and character formatting. */ + void createFontPortions( const ::rtl::OString& rText, rtl_TextEncoding eDefaultTextEnc, FontPortionModelList& rPortions ); + /** Create base text portions from the passed string and character formatting. */ + void createFontPortions( 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; + + PortionVec maFontPortions; /// String portions with font data. + PhoneticSettings maPhonSettings; /// Phonetic settings for this string. + PhoneticVec maPhonPortions; /// Phonetic text portions. +}; + +typedef ::boost::shared_ptr< RichString > RichStringRef; + +// ============================================================================ + +} // namespace xls +} // namespace oox + +#endif diff --git a/oox/inc/oox/xls/richstringcontext.hxx b/oox/inc/oox/xls/richstringcontext.hxx new file mode 100644 index 000000000000..df3f412d87ec --- /dev/null +++ b/oox/inc/oox/xls/richstringcontext.hxx @@ -0,0 +1,71 @@ +/************************************************************************* + * + * 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_RICHSTRINGCONTEXT_HXX +#define OOX_XLS_RICHSTRINGCONTEXT_HXX + +#include "oox/xls/excelhandlers.hxx" +#include "oox/xls/richstring.hxx" + +namespace oox { +namespace xls { + +// ============================================================================ + +class RichStringContext : public WorkbookContextBase +{ +public: + template< typename ParentType > + explicit RichStringContext( ParentType& rParent, RichStringRef xString ); + +protected: + virtual ::oox::core::ContextHandlerRef onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ); + virtual void onCharacters( const ::rtl::OUString& rChars ); + +private: + RichStringRef mxString; /// Processed string. + RichStringPortionRef mxPortion; /// Processed portion in the string. + RichStringPhoneticRef mxPhonetic; /// Processed phonetic text portion. + FontRef mxFont; /// Processed font of the portion. +}; + +// ---------------------------------------------------------------------------- + +template< typename ParentType > +RichStringContext::RichStringContext( ParentType& rParent, RichStringRef xString ) : + WorkbookContextBase( rParent ), + mxString( xString ) +{ + OSL_ENSURE( mxString.get(), "RichStringContext::RichStringContext - missing string object" ); +} + +// ============================================================================ + +} // namespace xls +} // namespace oox + +#endif diff --git a/oox/inc/oox/xls/scenariobuffer.hxx b/oox/inc/oox/xls/scenariobuffer.hxx new file mode 100644 index 000000000000..ed8d4e919bd2 --- /dev/null +++ b/oox/inc/oox/xls/scenariobuffer.hxx @@ -0,0 +1,155 @@ +/************************************************************************* + * + * 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_SCENARIOBUFFER_HXX +#define OOX_XLS_SCENARIOBUFFER_HXX + +#include <com/sun/star/table/CellAddress.hpp> +#include "oox/helper/refmap.hxx" +#include "oox/helper/refvector.hxx" +#include "oox/xls/workbookhelper.hxx" + +namespace oox { +namespace xls { + +// ============================================================================ + +struct ScenarioCellModel +{ + ::com::sun::star::table::CellAddress maPos; + ::rtl::OUString maValue; + sal_Int32 mnNumFmtId; + bool mbDeleted; + + explicit ScenarioCellModel(); +}; + +// ---------------------------------------------------------------------------- + +struct ScenarioModel +{ + ::rtl::OUString maName; /// Name of the scenario. + ::rtl::OUString maComment; /// Comment. + ::rtl::OUString maUser; /// Name of user created the scenario. + bool mbLocked; /// True = input cell values locked. + bool mbHidden; /// True = scenario is hidden. + + explicit ScenarioModel(); +}; + +// ---------------------------------------------------------------------------- + +class Scenario : public WorkbookHelper +{ +public: + explicit Scenario( const WorkbookHelper& rHelper, sal_Int16 nSheet ); + + /** Imports a scenario definition from a scenario element. */ + void importScenario( const AttributeList& rAttribs ); + /** Imports a new cell for this scenario from a inputCells element. */ + void importInputCells( const AttributeList& rAttribs ); + + /** Imports a scenario definition from a SCENARIO record. */ + void importScenario( SequenceInputStream& rStrm ); + /** Imports a new cell for this scenario from a INPUTCELLS record. */ + void importInputCells( SequenceInputStream& rStrm ); + + /** Imports a scenario definition from a SCENARIO record. */ + void importScenario( BiffInputStream& rStrm ); + + /** Creates the scenario in the Calc document. */ + void finalizeImport(); + +private: + typedef ::std::vector< ScenarioCellModel > ScenarioCellVector; + + ScenarioCellVector maCells; /// Scenario cells. + ScenarioModel maModel; /// Scenario model data. + sal_Int16 mnSheet; /// Index of the sheet this scenario is based on. +}; + +// ============================================================================ + +struct SheetScenariosModel +{ + sal_Int32 mnCurrent; /// Selected scenario. + sal_Int32 mnShown; /// Visible scenario. + + explicit SheetScenariosModel(); +}; + +// ---------------------------------------------------------------------------- + +class SheetScenarios : public WorkbookHelper +{ +public: + explicit SheetScenarios( const WorkbookHelper& rHelper, sal_Int16 nSheet ); + + /** Imports sheet scenario settings from a scenarios element. */ + void importScenarios( const AttributeList& rAttribs ); + /** Imports sheet scenario settings from a SCENARIOS record. */ + void importScenarios( SequenceInputStream& rStrm ); + /** Imports sheet scenario settings from a SCENARIOS record. */ + void importScenarios( BiffInputStream& rStrm ); + + /** Creates and returns a new scenario in this collection. */ + Scenario& createScenario(); + + /** Creates all scenarios in the Calc sheet. */ + void finalizeImport(); + +private: + typedef RefVector< Scenario > ScenarioVector; + ScenarioVector maScenarios; + SheetScenariosModel maModel; + sal_Int16 mnSheet; +}; + +// ============================================================================ + +class ScenarioBuffer : public WorkbookHelper +{ +public: + explicit ScenarioBuffer( const WorkbookHelper& rHelper ); + + /** Creates and returns a scenario collection for the passed sheet. */ + SheetScenarios& createSheetScenarios( sal_Int16 nSheet ); + + /** Creates all scenarios in the Calc dcument. */ + void finalizeImport(); + +private: + typedef RefMap< sal_Int16, SheetScenarios, ::std::greater< sal_Int16 > > SheetScenariosMap; + SheetScenariosMap maSheetScenarios; +}; + +// ============================================================================ + +} // namespace xls +} // namespace oox + +#endif diff --git a/oox/inc/oox/xls/scenariocontext.hxx b/oox/inc/oox/xls/scenariocontext.hxx new file mode 100644 index 000000000000..3e6ccc5c22d6 --- /dev/null +++ b/oox/inc/oox/xls/scenariocontext.hxx @@ -0,0 +1,80 @@ +/************************************************************************* + * + * 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_SCENARIOCONTEXT_HXX +#define OOX_XLS_SCENARIOCONTEXT_HXX + +#include "oox/xls/excelhandlers.hxx" + +namespace oox { +namespace xls { + +class Scenario; +class SheetScenarios; + +// ============================================================================ + +class ScenarioContext : public WorksheetContextBase +{ +public: + explicit ScenarioContext( WorksheetContextBase& rParent, SheetScenarios& rSheetScenarios ); + +protected: + virtual ::oox::core::ContextHandlerRef onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ); + virtual void onStartElement( const AttributeList& rAttribs ); + + virtual ::oox::core::ContextHandlerRef onCreateRecordContext( sal_Int32 nRecId, SequenceInputStream& rStrm ); + virtual void onStartRecord( SequenceInputStream& rStrm ); + +private: + Scenario& mrScenario; +}; + +// ============================================================================ + +class ScenariosContext : public WorksheetContextBase +{ +public: + explicit ScenariosContext( WorksheetFragmentBase& rFragment ); + +protected: + virtual ::oox::core::ContextHandlerRef onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ); + virtual void onStartElement( const AttributeList& rAttribs ); + + virtual ::oox::core::ContextHandlerRef onCreateRecordContext( sal_Int32 nRecId, SequenceInputStream& rStrm ); + virtual void onStartRecord( SequenceInputStream& rStrm ); + +private: + SheetScenarios& mrSheetScenarios; +}; + +// ============================================================================ + +} // namespace xls +} // namespace oox + +#endif diff --git a/oox/inc/oox/xls/sharedformulabuffer.hxx b/oox/inc/oox/xls/sharedformulabuffer.hxx new file mode 100644 index 000000000000..94b7572dcfd9 --- /dev/null +++ b/oox/inc/oox/xls/sharedformulabuffer.hxx @@ -0,0 +1,111 @@ +/************************************************************************* + * + * 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 new file mode 100644 index 000000000000..eff8ab4e7738 --- /dev/null +++ b/oox/inc/oox/xls/sharedstringsbuffer.hxx @@ -0,0 +1,68 @@ +/************************************************************************* + * + * 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_SHAREDSTRINGSBUFFER_HXX +#define OOX_XLS_SHAREDSTRINGSBUFFER_HXX + +#include "oox/xls/richstring.hxx" + +namespace oox { +namespace xls { + +// ============================================================================ + +/** Collects all strings from the shared strings substream. */ +class SharedStringsBuffer : public WorkbookHelper +{ +public: + explicit SharedStringsBuffer( const WorkbookHelper& rHelper ); + + /** Creates and returns a new string entry. */ + RichStringRef createRichString(); + /** Imports the complete shared string table from a BIFF file. */ + void importSst( BiffInputStream& rStrm ); + + /** 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; + +private: + typedef RefVector< RichString > StringVec; + StringVec maStrings; +}; + +// ============================================================================ + +} // namespace xls +} // namespace oox + +#endif diff --git a/oox/inc/oox/xls/sharedstringsfragment.hxx b/oox/inc/oox/xls/sharedstringsfragment.hxx new file mode 100644 index 000000000000..bc3a23122d19 --- /dev/null +++ b/oox/inc/oox/xls/sharedstringsfragment.hxx @@ -0,0 +1,58 @@ +/************************************************************************* + * + * 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_SHAREDSTRINGSFRAGMENT_HXX +#define OOX_XLS_SHAREDSTRINGSFRAGMENT_HXX + +#include "oox/xls/excelhandlers.hxx" + +namespace oox { +namespace xls { + +// ============================================================================ + +class SharedStringsFragment : public WorkbookFragmentBase +{ +public: + explicit SharedStringsFragment( + const WorkbookHelper& rHelper, + const ::rtl::OUString& rFragmentPath ); + +protected: + virtual ::oox::core::ContextHandlerRef onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ); + virtual ::oox::core::ContextHandlerRef onCreateRecordContext( sal_Int32 nRecId, SequenceInputStream& rStrm ); + + virtual const ::oox::core::RecordInfo* getRecordInfos() const; + virtual void finalizeImport(); +}; + +// ============================================================================ + +} // namespace xls +} // namespace oox + +#endif diff --git a/oox/inc/oox/xls/sheetdatacontext.hxx b/oox/inc/oox/xls/sheetdatacontext.hxx new file mode 100644 index 000000000000..fdbc0ba21231 --- /dev/null +++ b/oox/inc/oox/xls/sheetdatacontext.hxx @@ -0,0 +1,172 @@ +/************************************************************************* + * + * 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_SHEETDATACONTEXT_HXX +#define OOX_XLS_SHEETDATACONTEXT_HXX + +#include "oox/xls/excelhandlers.hxx" +#include "oox/xls/richstring.hxx" + +namespace com { namespace sun { namespace star { + namespace table { class XCell; } +} } } + +namespace oox { +namespace xls { + +// ============================================================================ + +/** 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 +{ +public: + explicit SheetDataContext( WorksheetFragmentBase& rFragment ); + +protected: + virtual ::oox::core::ContextHandlerRef onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ); + virtual void onCharacters( const ::rtl::OUString& rChars ); + virtual void onEndElement(); + + virtual ::oox::core::ContextHandlerRef onCreateRecordContext( sal_Int32 nRecId, SequenceInputStream& rStrm ); + +private: + /** Different types of cell records. */ + enum CellType { CELLTYPE_VALUE, CELLTYPE_MULTI, CELLTYPE_FORMULA }; + + /** Imports row settings from a row element. */ + void importRow( const AttributeList& rAttribs ); + /** Imports cell settings from a c element. */ + void 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 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. */ + void importCellBool( SequenceInputStream& rStrm, CellType eCellType ); + /** Imports a numeric cell from a CELL_DOUBLE, MULTCELL_DOUBLE, or FORMULA_DOUBLE record. */ + void importCellDouble( SequenceInputStream& rStrm, CellType eCellType ); + /** Imports an error code cell from a CELL_ERROR, MULTCELL_ERROR, or FORMULA_ERROR record. */ + void importCellError( SequenceInputStream& rStrm, CellType eCellType ); + /** Imports an encoded numeric cell from a CELL_RK or MULTCELL_RK record. */ + void importCellRk( SequenceInputStream& rStrm, CellType eCellType ); + /** Imports a rich-string cell from a CELL_RSTRING or MULTCELL_RSTRING record. */ + void importCellRString( SequenceInputStream& rStrm, CellType eCellType ); + /** Imports a string cell from a CELL_SI or MULTCELL_SI record. */ + void importCellSi( SequenceInputStream& rStrm, CellType eCellType ); + /** 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 ); + +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. +}; + +// ============================================================================ + +/** This class implements importing row settings and all cells of a sheet. + */ +class BiffSheetDataContext : public BiffWorksheetContextBase +{ +public: + explicit BiffSheetDataContext( const WorksheetHelper& rHelper ); + + /** Tries to import a sheet data record. */ + virtual void importRecord( BiffInputStream& rStrm ); + +private: + /** Sets current cell according to the passed address. */ + void setCurrCell( const BinAddress& rAddr ); + + /** 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 ); + + /** Imports a BLANK record describing a blank but formatted cell. */ + void importBlank( BiffInputStream& rStrm ); + /** Imports a BOOLERR record describing a boolean or error code cell. */ + void importBoolErr( BiffInputStream& rStrm ); + /** Imports a FORMULA record describing a formula cell. */ + void importFormula( BiffInputStream& rStrm ); + /** Imports an INTEGER record describing a BIFF2 integer cell. */ + void importInteger( BiffInputStream& rStrm ); + /** Imports a LABEL record describing an unformatted string cell. */ + void importLabel( BiffInputStream& rStrm ); + /** Imports a LABELSST record describing a string cell using the shared string list. */ + void importLabelSst( BiffInputStream& rStrm ); + /** Imports a MULTBLANK record describing a range of blank but formatted cells. */ + void importMultBlank( BiffInputStream& rStrm ); + /** Imports a MULTRK record describing a range of numeric cells. */ + void importMultRk( BiffInputStream& rStrm ); + /** Imports a NUMBER record describing a floating-point cell. */ + void importNumber( BiffInputStream& rStrm ); + /** 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 ); + +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. +}; + +// ============================================================================ + +} // namespace xls +} // namespace oox + +#endif diff --git a/oox/inc/oox/xls/stylesbuffer.hxx b/oox/inc/oox/xls/stylesbuffer.hxx new file mode 100644 index 000000000000..64a56968aa37 --- /dev/null +++ b/oox/inc/oox/xls/stylesbuffer.hxx @@ -0,0 +1,1098 @@ +/************************************************************************* + * + * 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_STYLESBUFFER_HXX +#define OOX_XLS_STYLESBUFFER_HXX + +#include <com/sun/star/awt/FontDescriptor.hpp> +#include <com/sun/star/table/CellHoriJustify.hpp> +#include <com/sun/star/table/CellOrientation.hpp> +#include <com/sun/star/table/CellVertJustify.hpp> +#include <com/sun/star/table/TableBorder.hpp> +#include <com/sun/star/util/CellProtection.hpp> +#include "oox/drawingml/color.hxx" +#include "oox/helper/graphichelper.hxx" +#include "oox/helper/refmap.hxx" +#include "oox/helper/refvector.hxx" +#include "oox/xls/numberformatsbuffer.hxx" + +namespace com { namespace sun { namespace star { + namespace awt { struct FontDescrtiptor; } +} } } + +namespace oox { class PropertySet; } + +namespace oox { +namespace xls { + +// ============================================================================ + +const sal_Int32 OOX_COLOR_WINDOWTEXT3 = 24; /// System window text color (BIFF3-BIFF4). +const sal_Int32 OOX_COLOR_WINDOWBACK3 = 25; /// System window background color (BIFF3-BIFF4). +const sal_Int32 OOX_COLOR_WINDOWTEXT = 64; /// System window text color (BIFF5+). +const sal_Int32 OOX_COLOR_WINDOWBACK = 65; /// System window background color (BIFF5+). +const sal_Int32 OOX_COLOR_BUTTONBACK = 67; /// System button background color (face color). +const sal_Int32 OOX_COLOR_CHWINDOWTEXT = 77; /// System window text color (BIFF8 charts). +const sal_Int32 OOX_COLOR_CHWINDOWBACK = 78; /// System window background color (BIFF8 charts). +const sal_Int32 OOX_COLOR_CHBORDERAUTO = 79; /// Automatic frame border (BIFF8 charts). +const sal_Int32 OOX_COLOR_NOTEBACK = 80; /// Note background color. +const sal_Int32 OOX_COLOR_NOTETEXT = 81; /// Note text color. +const sal_Int32 OOX_COLOR_FONTAUTO = 0x7FFF; /// Font auto color (system window text color). + +// ---------------------------------------------------------------------------- + +const sal_Int16 API_LINE_NONE = 0; +const sal_Int16 API_LINE_HAIR = 2; +const sal_Int16 API_LINE_THIN = 35; +const sal_Int16 API_LINE_MEDIUM = 88; +const sal_Int16 API_LINE_THICK = 141; + +const sal_Int16 API_ESCAPE_NONE = 0; /// No escapement. +const sal_Int16 API_ESCAPE_SUPERSCRIPT = 101; /// Superscript: raise characters automatically (magic value 101). +const sal_Int16 API_ESCAPE_SUBSCRIPT = -101; /// Subscript: lower characters automatically (magic value -101). + +const sal_Int8 API_ESCAPEHEIGHT_NONE = 100; /// Relative character height if not escaped. +const sal_Int8 API_ESCAPEHEIGHT_DEFAULT = 58; /// Relative character height if escaped. + +// ============================================================================ + +/** Special implementation of the GraphicHelper for Excel palette and scheme + colors. + */ +class ExcelGraphicHelper : public GraphicHelper, public WorkbookHelper +{ +public: + explicit ExcelGraphicHelper( const WorkbookHelper& rHelper ); + + /** Derived classes may implement to resolve a scheme color from the passed XML token identifier. */ + virtual sal_Int32 getSchemeColor( sal_Int32 nToken ) const; + /** Derived classes may implement to resolve a palette index to an RGB color. */ + virtual sal_Int32 getPaletteColor( sal_Int32 nPaletteIdx ) const; +}; + +// ============================================================================ + +class Color : public ::oox::drawingml::Color +{ +public: + /** Sets the color to automatic. */ + void setAuto(); + /** Sets the color to the passed RGB value. */ + void setRgb( sal_Int32 nRgbValue, double fTint = 0.0 ); + /** Sets the color to the passed theme index. */ + void setTheme( sal_Int32 nThemeIdx, double fTint = 0.0 ); + /** Sets the color to the passed palette index. */ + void setIndexed( sal_Int32 nPaletteIdx, double fTint = 0.0 ); + + /** Imports the color from the passed attribute list. */ + void importColor( const AttributeList& rAttribs ); + + /** Imports a 64-bit color from the passed binary stream. */ + void importColor( SequenceInputStream& rStrm ); + /** Imports a 32-bit palette color identifier from the passed BIFF12 stream. */ + void importColorId( SequenceInputStream& rStrm ); + /** Imports a 32-bit RGBA color value from the passed BIFF12 stream. */ + void importColorRgb( SequenceInputStream& rStrm ); + + /** Imports an 8-bit or 16-bit palette color identifier from the passed BIFF stream. */ + void importColorId( BiffInputStream& rStrm, bool b16Bit = true ); + /** Imports a 32-bit RGBA color value from the passed BIFF stream. */ + void importColorRgb( BiffInputStream& rStrm ); + + /** Returns true, if the color is set to automatic. */ + inline bool isAuto() const { return isPlaceHolder(); } +}; + +// ---------------------------------------------------------------------------- + +SequenceInputStream& operator>>( SequenceInputStream& rStrm, Color& orColor ); + +// ============================================================================ + +/** Stores all colors of the color palette. */ +class ColorPalette : public WorkbookHelper +{ +public: + /** Constructs the color palette with predefined color values. */ + explicit ColorPalette( const WorkbookHelper& rHelper ); + + /** Appends a new color from the passed attributes. */ + void importPaletteColor( const AttributeList& rAttribs ); + /** Appends a new color from the passed RGBCOLOR record. */ + void importPaletteColor( SequenceInputStream& rStrm ); + /** Imports the PALETTE record from the passed stream. */ + void importPalette( BiffInputStream& rStrm ); + /** Imports a color palette from a UNO sequence in the passed any. */ + void importPalette( const ::com::sun::star::uno::Any& rPalette ); + + /** Rturns the RGB value of the color with the passed index. */ + sal_Int32 getColor( sal_Int32 nPaletteIdx ) const; + +private: + /** Appends the passed color. */ + void appendColor( sal_Int32 nRGBValue ); + +private: + ::std::vector< sal_Int32 > maColors; /// List of RGB values. + size_t mnAppendIndex; /// Index to append a new color. +}; + +// ============================================================================ + +/** Contains all XML font attributes, e.g. from a font or rPr element. */ +struct FontModel +{ + ::rtl::OUString maName; /// Font name. + Color maColor; /// Font color. + sal_Int32 mnScheme; /// Major/minor scheme font. + sal_Int32 mnFamily; /// Font family. + sal_Int32 mnCharSet; /// Windows font character set. + double mfHeight; /// Font height in points. + sal_Int32 mnUnderline; /// Underline style. + sal_Int32 mnEscapement; /// Escapement style. + bool mbBold; /// True = bold characters. + bool mbItalic; /// True = italic characters. + bool mbStrikeout; /// True = Strike out characters. + bool mbOutline; /// True = outlined characters. + bool mbShadow; /// True = shadowed chgaracters. + + explicit FontModel(); + + void setBiff12Scheme( sal_uInt8 nScheme ); + void setBiffHeight( sal_uInt16 nHeight ); + void setBiffWeight( sal_uInt16 nWeight ); + void setBiffUnderline( sal_uInt16 nUnderline ); + void setBiffEscapement( sal_uInt16 nEscapement ); +}; + +// ---------------------------------------------------------------------------- + +/** Enumerates different types of API font property sets. */ +enum FontPropertyType +{ + FONT_PROPTYPE_CELL, /// Font properties in a spreadsheet cell (table::Cell service). + FONT_PROPTYPE_TEXT /// Font properties in a text object (text::Text service). +}; + +// ---------------------------------------------------------------------------- + +/** Contains used flags for all API font attributes. */ +struct ApiFontUsedFlags +{ + bool mbNameUsed; /// True = font name/family/char set are used. + bool mbColorUsed; /// True = font color is used. + bool mbSchemeUsed; /// True = font scheme is used. + bool mbHeightUsed; /// True = font height is used. + bool mbUnderlineUsed; /// True = underline style is used. + bool mbEscapementUsed; /// True = escapement style is used. + bool mbWeightUsed; /// True = font weight (boldness) is used. + bool mbPostureUsed; /// True = font posture (italic) is used. + bool mbStrikeoutUsed; /// True = strike out style is used. + bool mbOutlineUsed; /// True = outline style is used. + bool mbShadowUsed; /// True = shadow style is used. + + explicit ApiFontUsedFlags( bool bAllUsed ); +}; + +// ---------------------------------------------------------------------------- + +/** Contains API font name, family, and charset for a script type. */ +struct ApiScriptFontName +{ + ::rtl::OUString maName; /// Font name. + sal_Int16 mnFamily; /// Font family. + sal_Int16 mnTextEnc; /// Font text encoding. + + explicit ApiScriptFontName(); +}; + +// ---------------------------------------------------------------------------- + +/** Contains all API font attributes. */ +struct ApiFontData +{ + typedef ::com::sun::star::awt::FontDescriptor ApiFontDescriptor; + + ApiScriptFontName maLatinFont; /// Font name for latin scripts. + ApiScriptFontName maAsianFont; /// Font name for east-asian scripts. + ApiScriptFontName maCmplxFont; /// Font name for complex scripts. + ApiFontDescriptor maDesc; /// Font descriptor (height in twips, weight in %). + sal_Int32 mnColor; /// Font color. + sal_Int16 mnEscapement; /// Escapement style. + sal_Int8 mnEscapeHeight; /// Escapement font height. + bool mbOutline; /// True = outlined characters. + bool mbShadow; /// True = shadowed chgaracters. + + explicit ApiFontData(); +}; + +// ============================================================================ + +class Font : public WorkbookHelper +{ +public: + explicit Font( const WorkbookHelper& rHelper, bool bDxf ); + explicit Font( const WorkbookHelper& rHelper, const FontModel& rModel ); + + /** Sets font formatting attributes for the passed element. */ + void importAttribs( sal_Int32 nElement, const AttributeList& rAttribs ); + + /** Imports the FONT record from the passed stream. */ + void importFont( SequenceInputStream& rStrm ); + /** Imports the font name from a DXF record. */ + void importDxfName( SequenceInputStream& rStrm ); + /** Imports the font color from a DXF record. */ + void importDxfColor( SequenceInputStream& rStrm ); + /** Imports the font scheme from a DXF record. */ + void importDxfScheme( SequenceInputStream& rStrm ); + /** Imports the font height from a DXF record. */ + void importDxfHeight( SequenceInputStream& rStrm ); + /** Imports the font weight from a DXF record. */ + void importDxfWeight( SequenceInputStream& rStrm ); + /** Imports the font underline style from a DXF record. */ + void importDxfUnderline( SequenceInputStream& rStrm ); + /** Imports the font escapement style from a DXF record. */ + void importDxfEscapement( SequenceInputStream& rStrm ); + /** Imports a font style flag from a DXF record. */ + void importDxfFlag( sal_Int32 nElement, SequenceInputStream& rStrm ); + + /** Imports the FONT record from the passed stream. */ + void importFont( BiffInputStream& rStrm ); + /** Imports the FONTCOLOR record from the passed stream. */ + void importFontColor( BiffInputStream& rStrm ); + /** Sets the font attributes from the font block of a CFRULE record. */ + void importCfRule( BiffInputStream& rStrm ); + + /** Returns the font model structure. This function can be called before + finalizeImport() has been called. */ + inline const FontModel& getModel() const { return maModel; } + /** Returns the text encoding for strings used with this font. This + function can be called before finalizeImport() has been called. */ + rtl_TextEncoding getFontEncoding() const; + + /** Final processing after import of all style settings. */ + void finalizeImport(); + + /** Returns an API font descriptor with own font information. */ + const ::com::sun::star::awt::FontDescriptor& getFontDescriptor() const; + /** Returns true, if the font requires rich text formatting in Calc. + @descr Example: Font escapement is a cell attribute in Excel, but Calc + needs an rich text cell for this attribute. */ + bool needsRichTextFormat() const; + + /** Writes all font attributes to the passed property map. */ + void writeToPropertyMap( + PropertyMap& rPropMap, + FontPropertyType ePropType ) const; + /** Writes all font attributes to the passed property set. */ + void writeToPropertySet( + PropertySet& rPropSet, + FontPropertyType ePropType ) const; + +private: + /** Reads and sets height and flags. */ + void importFontData2( BiffInputStream& rStrm ); + /** Reads and sets weight, escapement, underline, family, charset (BIFF5+). */ + void importFontData5( BiffInputStream& rStrm ); + + /** Reads and sets a byte string as font name. */ + void importFontName2( BiffInputStream& rStrm ); + /** Reads and sets a Unicode string as font name. */ + void importFontName8( BiffInputStream& rStrm ); + +private: + FontModel maModel; + ApiFontData maApiData; + ApiFontUsedFlags maUsedFlags; + bool mbDxf; +}; + +typedef ::boost::shared_ptr< Font > FontRef; + +// ============================================================================ + +/** Contains all XML cell alignment attributes, e.g. from an alignment element. */ +struct AlignmentModel +{ + sal_Int32 mnHorAlign; /// Horizontal alignment. + sal_Int32 mnVerAlign; /// Vertical alignment. + sal_Int32 mnTextDir; /// CTL text direction. + sal_Int32 mnRotation; /// Text rotation angle. + sal_Int32 mnIndent; /// Indentation. + bool mbWrapText; /// True = multi-line text. + bool mbShrink; /// True = shrink to fit cell size. + bool mbJustLastLine; /// True = justify last line in block text. + + explicit AlignmentModel(); + + /** Sets horizontal alignment from the passed BIFF data. */ + void setBiffHorAlign( sal_uInt8 nHorAlign ); + /** Sets vertical alignment from the passed BIFF data. */ + void setBiffVerAlign( sal_uInt8 nVerAlign ); + /** Sets rotation from the passed BIFF text orientation. */ + void setBiffTextOrient( sal_uInt8 nTextOrient ); +}; + +// ---------------------------------------------------------------------------- + +/** Contains all API cell alignment attributes. */ +struct ApiAlignmentData +{ + typedef ::com::sun::star::table::CellHoriJustify ApiCellHoriJustify; + typedef ::com::sun::star::table::CellVertJustify ApiCellVertJustify; + typedef ::com::sun::star::table::CellOrientation ApiCellOrientation; + + ApiCellHoriJustify meHorJustify; /// Horizontal alignment. + ApiCellVertJustify meVerJustify; /// Vertical alignment. + ApiCellOrientation meOrientation; /// Normal or stacked text. + sal_Int32 mnRotation; /// Text rotation angle. + sal_Int16 mnWritingMode; /// CTL text direction. + sal_Int16 mnIndent; /// Indentation. + bool mbWrapText; /// True = multi-line text. + bool mbShrink; /// True = shrink to fit cell size. + + explicit ApiAlignmentData(); +}; + +bool operator==( const ApiAlignmentData& rLeft, const ApiAlignmentData& rRight ); + +// ============================================================================ + +class Alignment : public WorkbookHelper +{ +public: + explicit Alignment( const WorkbookHelper& rHelper ); + + /** Sets all attributes from the alignment element. */ + void importAlignment( const AttributeList& rAttribs ); + + /** Sets the alignment attributes from the passed BIFF12 XF record data. */ + void setBiff12Data( sal_uInt32 nFlags ); + /** Sets the alignment attributes from the passed BIFF2 XF record data. */ + void setBiff2Data( sal_uInt8 nFlags ); + /** Sets the alignment attributes from the passed BIFF3 XF record data. */ + void setBiff3Data( sal_uInt16 nAlign ); + /** Sets the alignment attributes from the passed BIFF4 XF record data. */ + void setBiff4Data( sal_uInt16 nAlign ); + /** Sets the alignment attributes from the passed BIFF5 XF record data. */ + void setBiff5Data( sal_uInt16 nAlign ); + /** Sets the alignment attributes from the passed BIFF8 XF record data. */ + void setBiff8Data( sal_uInt16 nAlign, sal_uInt16 nMiscAttrib ); + + /** Final processing after import of all style settings. */ + void finalizeImport(); + + /** Returns the alignment model structure. */ + inline const AlignmentModel& getModel() const { return maModel; } + /** Returns the converted API alignment data struct. */ + inline const ApiAlignmentData& getApiData() const { return maApiData; } + + /** Writes all alignment attributes to the passed property map. */ + void writeToPropertyMap( PropertyMap& rPropMap ) const; + +private: + AlignmentModel maModel; /// Alignment model data. + ApiAlignmentData maApiData; /// Alignment data converted to API constants. +}; + +typedef ::boost::shared_ptr< Alignment > AlignmentRef; + +// ============================================================================ + +/** Contains all XML cell protection attributes, e.g. from a protection element. */ +struct ProtectionModel +{ + bool mbLocked; /// True = locked against editing. + bool mbHidden; /// True = formula is hidden. + + explicit ProtectionModel(); +}; + +// ---------------------------------------------------------------------------- + +/** Contains all API cell protection attributes. */ +struct ApiProtectionData +{ + typedef ::com::sun::star::util::CellProtection ApiCellProtection; + + ApiCellProtection maCellProt; + + explicit ApiProtectionData(); +}; + +bool operator==( const ApiProtectionData& rLeft, const ApiProtectionData& rRight ); + +// ============================================================================ + +class Protection : public WorkbookHelper +{ +public: + explicit Protection( const WorkbookHelper& rHelper ); + + /** Sets all attributes from the protection element. */ + void importProtection( const AttributeList& rAttribs ); + + /** Sets the protection attributes from the passed BIFF12 XF record data. */ + void setBiff12Data( sal_uInt32 nFlags ); + /** Sets the protection attributes from the passed BIFF2 XF record data. */ + void setBiff2Data( sal_uInt8 nNumFmt ); + /** Sets the protection attributes from the passed BIFF3-BIFF8 XF record data. */ + void setBiff3Data( sal_uInt16 nProt ); + + /** Final processing after import of all style settings. */ + void finalizeImport(); + + /** Returns the protection model structure. */ + inline const ProtectionModel& getModel() const { return maModel; } + /** Returns the converted API protection data struct. */ + inline const ApiProtectionData& getApiData() const { return maApiData; } + + /** Writes all protection attributes to the passed property map. */ + void writeToPropertyMap( PropertyMap& rPropMap ) const; + +private: + ProtectionModel maModel; /// Protection model data. + ApiProtectionData maApiData; /// Protection data converted to API constants. +}; + +typedef ::boost::shared_ptr< Protection > ProtectionRef; + +// ============================================================================ + +/** Contains XML attributes of a single border line. */ +struct BorderLineModel +{ + Color maColor; /// Borderline color. + sal_Int32 mnStyle; /// Border line style. + bool mbUsed; /// True = line format used. + + explicit BorderLineModel( bool bDxf ); + + /** Sets the passed BIFF line style. */ + void setBiffStyle( sal_Int32 nLineStyle ); + /** Sets line style and line color from the passed BIFF data. */ + void setBiffData( sal_uInt8 nLineStyle, sal_uInt16 nLineColor ); +}; + +// ---------------------------------------------------------------------------- + +/** Contains XML attributes of a complete cell border. */ +struct BorderModel +{ + BorderLineModel maLeft; /// Left line format. + BorderLineModel maRight; /// Right line format. + BorderLineModel maTop; /// Top line format. + BorderLineModel maBottom; /// Bottom line format. + BorderLineModel maDiagonal; /// Diagonal line format. + bool mbDiagTLtoBR; /// True = top-left to bottom-right on. + bool mbDiagBLtoTR; /// True = bottom-left to top-right on. + + explicit BorderModel( bool bDxf ); +}; + +// ---------------------------------------------------------------------------- + +/** Contains API attributes of a complete cell border. */ +struct ApiBorderData +{ + typedef ::com::sun::star::table::TableBorder ApiTableBorder; + typedef ::com::sun::star::table::BorderLine ApiBorderLine; + + ApiTableBorder maBorder; /// Left/right/top/bottom line format. + ApiBorderLine maTLtoBR; /// Diagonal top-left to bottom-right line format. + ApiBorderLine maBLtoTR; /// Diagonal bottom-left to top-right line format. + bool mbBorderUsed; /// True = left/right/top/bottom line format used. + bool mbDiagUsed; /// True = diagonal line format used. + + explicit ApiBorderData(); + + /** Returns true, if any of the outer border lines is visible. */ + bool hasAnyOuterBorder() const; +}; + +bool operator==( const ApiBorderData& rLeft, const ApiBorderData& rRight ); + +// ============================================================================ + +class Border : public WorkbookHelper +{ +public: + explicit Border( const WorkbookHelper& rHelper, bool bDxf ); + + /** Sets global border attributes from the border element. */ + void importBorder( const AttributeList& rAttribs ); + /** Sets border attributes for the border line with the passed element identifier. */ + void importStyle( sal_Int32 nElement, const AttributeList& rAttribs ); + /** Sets color attributes for the border line with the passed element identifier. */ + void importColor( sal_Int32 nElement, const AttributeList& rAttribs ); + + /** Imports the BORDER record from the passed stream. */ + void importBorder( SequenceInputStream& rStrm ); + /** Imports a border from a DXF record from the passed stream. */ + void importDxfBorder( sal_Int32 nElement, SequenceInputStream& rStrm ); + + /** Sets the border attributes from the passed BIFF2 XF record data. */ + void setBiff2Data( sal_uInt8 nFlags ); + /** Sets the border attributes from the passed BIFF3/BIFF4 XF record data. */ + void setBiff3Data( sal_uInt32 nBorder ); + /** Sets the border attributes from the passed BIFF5 XF record data. */ + void setBiff5Data( sal_uInt32 nBorder, sal_uInt32 nArea ); + /** Sets the border attributes from the passed BIFF8 XF record data. */ + void setBiff8Data( sal_uInt32 nBorder1, sal_uInt32 nBorder2 ); + /** Sets the border attributes from the border block of a CFRULE record. */ + void importCfRule( BiffInputStream& rStrm, sal_uInt32 nFlags ); + + /** Final processing after import of all style settings. */ + void finalizeImport(); + + /** Returns the border model structure. */ + inline const BorderModel& getModel() const { return maModel; } + /** Returns the converted API border data struct. */ + inline const ApiBorderData& getApiData() const { return maApiData; } + + /** Writes all border attributes to the passed property map. */ + void writeToPropertyMap( PropertyMap& rPropMap ) const; + +private: + /** Returns the border line struct specified by the passed XML token identifier. */ + BorderLineModel* getBorderLine( sal_Int32 nElement ); + + /** Converts border line data to an API struct, returns true, if the line is marked as used. */ + bool convertBorderLine( + ::com::sun::star::table::BorderLine& rBorderLine, + const BorderLineModel& rModel ); + +private: + BorderModel maModel; + ApiBorderData maApiData; + bool mbDxf; +}; + +typedef ::boost::shared_ptr< Border > BorderRef; + +// ============================================================================ + +/** Contains XML pattern fill attributes from the patternFill element. */ +struct PatternFillModel +{ + Color maPatternColor; /// Pattern foreground color. + Color maFillColor; /// Background fill color. + sal_Int32 mnPattern; /// Pattern identifier (e.g. solid). + bool mbPattColorUsed; /// True = pattern foreground color used. + bool mbFillColorUsed; /// True = background fill color used. + bool mbPatternUsed; /// True = pattern used. + + explicit PatternFillModel( bool bDxf ); + + /** Sets the passed BIFF pattern identifier. */ + void setBiffPattern( sal_Int32 nPattern ); + /** Sets the pattern and pattern colors from the passed BIFF data. */ + void setBiffData( sal_uInt16 nPatternColor, sal_uInt16 nFillColor, sal_uInt8 nPattern ); +}; + +// ---------------------------------------------------------------------------- + +/** Contains XML gradient fill attributes from the gradientFill element. */ +struct GradientFillModel +{ + typedef ::std::map< double, Color > ColorMap; + + sal_Int32 mnType; /// Gradient type, linear or path. + double mfAngle; /// Rotation angle for type linear. + double mfLeft; /// Left convergence for type path. + double mfRight; /// Right convergence for type path. + double mfTop; /// Top convergence for type path. + double mfBottom; /// Bottom convergence for type path. + ColorMap maColors; /// Gradient colors. + + explicit GradientFillModel(); + + /** Reads BIFF12 gradient settings from a FILL or DXF record. */ + void readGradient( SequenceInputStream& rStrm ); + /** Reads BIFF12 gradient stop settings from a FILL or DXF record. */ + void readGradientStop( SequenceInputStream& rStrm, bool bDxf ); +}; + +// ---------------------------------------------------------------------------- + +/** Contains API fill attributes. */ +struct ApiSolidFillData +{ + sal_Int32 mnColor; /// Fill color. + bool mbTransparent; /// True = transparent area. + bool mbUsed; /// True = fill data is valid. + + explicit ApiSolidFillData(); +}; + +bool operator==( const ApiSolidFillData& rLeft, const ApiSolidFillData& rRight ); + +// ============================================================================ + +/** Contains cell fill attributes, either a pattern fill or a gradient fill. */ +class Fill : public WorkbookHelper +{ +public: + explicit Fill( const WorkbookHelper& rHelper, bool bDxf ); + + /** Sets attributes of a patternFill element. */ + void importPatternFill( const AttributeList& rAttribs ); + /** Sets the pattern color from the fgColor element. */ + void importFgColor( const AttributeList& rAttribs ); + /** Sets the background color from the bgColor element. */ + void importBgColor( const AttributeList& rAttribs ); + /** Sets attributes of a gradientFill element. */ + void importGradientFill( const AttributeList& rAttribs ); + /** Sets a color from the color element in a gradient fill. */ + void importColor( const AttributeList& rAttribs, double fPosition ); + + /** Imports the FILL record from the passed stream. */ + void importFill( SequenceInputStream& rStrm ); + /** Imports the fill pattern from a DXF record. */ + void importDxfPattern( SequenceInputStream& rStrm ); + /** Imports the pattern color from a DXF record. */ + void importDxfFgColor( SequenceInputStream& rStrm ); + /** Imports the background color from a DXF record. */ + void importDxfBgColor( SequenceInputStream& rStrm ); + /** Imports gradient settings from a DXF record. */ + void importDxfGradient( SequenceInputStream& rStrm ); + /** Imports gradient stop settings from a DXF record. */ + void importDxfStop( SequenceInputStream& rStrm ); + + /** Sets the fill attributes from the passed BIFF2 XF record data. */ + void setBiff2Data( sal_uInt8 nFlags ); + /** Sets the fill attributes from the passed BIFF3/BIFF4 XF record data. */ + void setBiff3Data( sal_uInt16 nArea ); + /** Sets the fill attributes from the passed BIFF5 XF record data. */ + void setBiff5Data( sal_uInt32 nArea ); + /** Sets the fill attributes from the passed BIFF8 XF record data. */ + void setBiff8Data( sal_uInt32 nBorder2, sal_uInt16 nArea ); + /** Sets the fill attributes from the fill block of a CFRULE record. */ + void importCfRule( BiffInputStream& rStrm, sal_uInt32 nFlags ); + + /** Final processing after import of all style settings. */ + void finalizeImport(); + + /** Returns the fill pattern model structure, if extant. */ + inline const PatternFillModel* getPatternModel() const { return mxPatternModel.get(); } + /** Returns the fill gradient model structure, if extant. */ + inline const GradientFillModel* getGradientModel() const { return mxGradientModel.get(); } + /** Returns the converted API fill data struct. */ + inline const ApiSolidFillData& getApiData() const { return maApiData; } + + /** Writes all fill attributes to the passed property map. */ + void writeToPropertyMap( PropertyMap& rPropMap ) const; + +private: + typedef ::boost::shared_ptr< PatternFillModel > PatternModelRef; + typedef ::boost::shared_ptr< GradientFillModel > GradientModelRef; + + PatternModelRef mxPatternModel; + GradientModelRef mxGradientModel; + ApiSolidFillData maApiData; + bool mbDxf; +}; + +typedef ::boost::shared_ptr< Fill > FillRef; + +// ============================================================================ + +/** Contains all data for a cell format or cell style. */ +struct XfModel +{ + sal_Int32 mnStyleXfId; /// Index to parent style XF. + sal_Int32 mnFontId; /// Index to font data list. + sal_Int32 mnNumFmtId; /// Index to number format list. + sal_Int32 mnBorderId; /// Index to list of cell borders. + sal_Int32 mnFillId; /// Index to list of cell areas. + bool mbCellXf; /// True = cell XF, false = style XF. + bool mbFontUsed; /// True = font index used. + bool mbNumFmtUsed; /// True = number format used. + bool mbAlignUsed; /// True = alignment used. + bool mbProtUsed; /// True = cell protection used. + bool mbBorderUsed; /// True = border data used. + bool mbAreaUsed; /// True = area data used. + + explicit XfModel(); +}; + +// ============================================================================ + +/** Represents a cell format or a cell style (called XF, extended format). + + This class stores the type (cell/style), the index to the parent style (if + it is a cell format) and all "attribute used" flags, which reflect the + state of specific attribute groups (true = user has changed the attributes) + and all formatting data. + */ +class Xf : public WorkbookHelper +{ +public: + explicit Xf( const WorkbookHelper& rHelper ); + + /** Sets all "attribute used" flags to the passed state. */ + void setAllUsedFlags( bool bUsed ); + + /** Sets all attributes from the xf element. */ + void importXf( const AttributeList& rAttribs, bool bCellXf ); + /** Sets all attributes from the alignment element. */ + void importAlignment( const AttributeList& rAttribs ); + /** Sets all attributes from the protection element. */ + void importProtection( const AttributeList& rAttribs ); + + /** Imports the XF record from the passed stream. */ + void importXf( SequenceInputStream& rStrm, bool bCellXf ); + + /** Imports the XF record from the passed stream. */ + void importXf( BiffInputStream& rStrm ); + + /** Final processing after import of all style settings. */ + void finalizeImport(); + + /** Returns true, if the XF is a cell XF, and false, if it is a style XF. */ + inline bool isCellXf() const { return maModel.mbCellXf; } + + /** Returns the referred font object. */ + FontRef getFont() const; + /** Returns the alignment data of this style. */ + inline const Alignment& getAlignment() const { return maAlignment; } + /** Returns the cell protection data of this style. */ + inline const Protection& getProtection() const { return maProtection; } + /** Returns true, if any "attribute used" flags are ste in this XF. */ + bool hasAnyUsedFlags() const; + + /** Writes all formatting attributes to the passed property map. */ + void writeToPropertyMap( PropertyMap& rPropMap ) const; + /** Writes all formatting attributes to the passed property set. */ + void writeToPropertySet( PropertySet& rPropSet ) const; + +private: + /** Sets 'attribute used' flags from the passed BIFF bit field. */ + void setBiffUsedFlags( sal_uInt8 nUsedFlags ); + +private: + XfModel maModel; /// Cell XF or style XF model data. + Alignment maAlignment; /// Cell alignment data. + Protection maProtection; /// Cell protection data. + ::com::sun::star::table::CellVertJustify + meRotationRef; /// Rotation reference dependent on border. +}; + +typedef ::boost::shared_ptr< Xf > XfRef; + +// ============================================================================ + +class Dxf : public WorkbookHelper +{ +public: + explicit Dxf( const WorkbookHelper& rHelper ); + + /** Creates a new empty font object. */ + FontRef createFont( bool bAlwaysNew = true ); + /** Creates a new empty border object. */ + BorderRef createBorder( bool bAlwaysNew = true ); + /** Creates a new empty fill object. */ + FillRef createFill( bool bAlwaysNew = true ); + + /** Inserts a new number format code. */ + void importNumFmt( const AttributeList& rAttribs ); + /** Sets all attributes from the alignment element. */ + void importAlignment( const AttributeList& rAttribs ); + /** Sets all attributes from the protection element. */ + void importProtection( const AttributeList& rAttribs ); + + /** Imports the DXF record from the passed stream. */ + void importDxf( SequenceInputStream& rStrm ); + + /** Imports font, border, and fill settings from the CFRULE record. */ + void importCfRule( BiffInputStream& rStrm, sal_uInt32 nFlags ); + + /** Final processing after import of all style settings. */ + void finalizeImport(); + + /** Writes all formatting attributes to the passed property map. */ + void writeToPropertyMap( PropertyMap& rPropMap ) const; + /** Writes all formatting attributes to the passed property set. */ + void writeToPropertySet( PropertySet& rPropSet ) const; + +private: + FontRef mxFont; /// Font data. + NumberFormatRef mxNumFmt; /// Number format data. + AlignmentRef mxAlignment; /// Alignment data. + ProtectionRef mxProtection; /// Protection data. + BorderRef mxBorder; /// Border data. + FillRef mxFill; /// Fill data. +}; + +typedef ::boost::shared_ptr< Dxf > DxfRef; + +// ============================================================================ + +/** Contains attributes of a cell style, e.g. from the cellStyle element. */ +struct CellStyleModel +{ + ::rtl::OUString maName; /// Cell style name. + sal_Int32 mnXfId; /// Formatting for this cell style. + sal_Int32 mnBuiltinId; /// Identifier for builtin styles. + sal_Int32 mnLevel; /// Level for builtin column/row styles. + bool mbBuiltin; /// True = builtin style. + bool mbCustom; /// True = customized builtin style. + bool mbHidden; /// True = style not visible in GUI. + + explicit CellStyleModel(); + + /** Returns true, if this style is a builtin style. */ + bool isBuiltin() const; + /** Returns true, if this style represents the default document cell style. */ + bool isDefaultStyle() const; +}; + +// ============================================================================ + +class CellStyle : public WorkbookHelper +{ +public: + explicit CellStyle( const WorkbookHelper& rHelper ); + + /** Imports passed attributes from the cellStyle element. */ + void importCellStyle( const AttributeList& rAttribs ); + /** Imports style settings from a CELLSTYLE record. */ + void importCellStyle( SequenceInputStream& rStrm ); + /** Imports style settings from a STYLE record. */ + void importStyle( BiffInputStream& rStrm ); + + /** Creates the style sheet in the document described by this cell style object. */ + void createCellStyle(); + /** Stores tha passed final style name and creates the cell style, if it is + user-defined or modified built-in. */ + void finalizeImport( const ::rtl::OUString& rFinalName ); + + /** Returns the cell style model structure. */ + inline const CellStyleModel& getModel() const { return maModel; } + /** Returns the final style name used in the document. */ + inline const ::rtl::OUString& getFinalStyleName() const { return maFinalName; } + +private: + CellStyleModel maModel; + ::rtl::OUString maFinalName; /// Final style name used in API. + bool mbCreated; /// True = style sheet created. +}; + +typedef ::boost::shared_ptr< CellStyle > CellStyleRef; + +// ============================================================================ + +class CellStyleBuffer : public WorkbookHelper +{ +public: + explicit CellStyleBuffer( const WorkbookHelper& rHelper ); + + /** Appends and returns a new named cell style object. */ + CellStyleRef importCellStyle( const AttributeList& rAttribs ); + /** Imports the CELLSTYLE record from the passed stream. */ + CellStyleRef importCellStyle( SequenceInputStream& rStrm ); + /** Imports the STYLE record from the passed stream. */ + CellStyleRef importStyle( BiffInputStream& rStrm ); + + /** Final processing after import of all style settings. */ + void finalizeImport(); + + /** Returns the XF identifier associated to the default cell style. */ + sal_Int32 getDefaultXfId() const; + /** Returns the default style sheet for unused cells. */ + ::rtl::OUString getDefaultStyleName() const; + /** Creates the style sheet described by the style XF with the passed identifier. */ + ::rtl::OUString createCellStyle( sal_Int32 nXfId ) const; + +private: + /** Inserts the passed cell style object into the internal maps. */ + void insertCellStyle( CellStyleRef xCellStyle ); + /** Creates the style sheet described by the passed cell style object. */ + ::rtl::OUString createCellStyle( const CellStyleRef& rxCellStyle ) const; + +private: + typedef RefVector< CellStyle > CellStyleVector; + typedef RefMap< sal_Int32, CellStyle > CellStyleXfIdMap; + + CellStyleVector maBuiltinStyles; /// All built-in cell styles. + CellStyleVector maUserStyles; /// All user defined cell styles. + CellStyleXfIdMap maStylesByXf; /// All cell styles, mapped by XF identifier. + CellStyleRef mxDefStyle; /// Default cell style. +}; + +// ============================================================================ + +struct AutoFormatModel +{ + sal_Int32 mnAutoFormatId; /// Index of predefined autoformatting. + bool mbApplyNumFmt; /// True = apply number format from autoformatting. + bool mbApplyFont; /// True = apply font from autoformatting. + bool mbApplyAlignment; /// True = apply alignment from autoformatting. + bool mbApplyBorder; /// True = apply border from autoformatting. + bool mbApplyFill; /// True = apply fill from autoformatting. + bool mbApplyProtection; /// True = apply protection from autoformatting. + + explicit AutoFormatModel(); +}; + +// ============================================================================ + +class StylesBuffer : public WorkbookHelper +{ +public: + explicit StylesBuffer( const WorkbookHelper& rHelper ); + + /** Creates a new empty font object. + @param opnFontId (out-param) The identifier of the new font object. */ + FontRef createFont( sal_Int32* opnFontId = 0 ); + /** Creates a number format. */ + NumberFormatRef createNumFmt( sal_Int32 nNumFmtId, const ::rtl::OUString& rFmtCode ); + /** Creates a new empty border object. + @param opnBorderId (out-param) The identifier of the new border object. */ + BorderRef createBorder( sal_Int32* opnBorderId = 0 ); + /** Creates a new empty fill object. + @param opnFillId (out-param) The identifier of the new fill object. */ + FillRef createFill( sal_Int32* opnFillId = 0 ); + /** Creates a new empty cell formatting object. + @param opnXfId (out-param) The identifier of the new XF object. */ + XfRef createCellXf( sal_Int32* opnXfId = 0 ); + /** Creates a new empty style formatting object. + @param opnXfId (out-param) The identifier of the new XF object. */ + XfRef createStyleXf( sal_Int32* opnXfId = 0 ); + /** Creates a new empty differential formatting object. + @param opnDxfId (out-param) The identifier of the new DXF object. */ + DxfRef createDxf( sal_Int32* opnDxfId = 0 ); + + /** Appends a new color to the color palette. */ + void importPaletteColor( const AttributeList& rAttribs ); + /** Inserts a new number format code. */ + NumberFormatRef importNumFmt( const AttributeList& rAttribs ); + /** Appends and returns a new named cell style object. */ + CellStyleRef importCellStyle( const AttributeList& rAttribs ); + + /** Appends a new color to the color palette. */ + void importPaletteColor( SequenceInputStream& rStrm ); + /** Imports the NUMFMT record from the passed stream. */ + void importNumFmt( SequenceInputStream& rStrm ); + /** Imports the CELLSTYLE record from the passed stream. */ + void importCellStyle( SequenceInputStream& rStrm ); + + /** Imports the PALETTE record from the passed stream. */ + void importPalette( BiffInputStream& rStrm ); + /** Imports the FONT record from the passed stream. */ + void importFont( BiffInputStream& rStrm ); + /** Imports the FONTCOLOR record from the passed stream. */ + void importFontColor( BiffInputStream& rStrm ); + /** Imports the FORMAT record from the passed stream. */ + void importFormat( BiffInputStream& rStrm ); + /** Imports the XF record from the passed stream. */ + void importXf( BiffInputStream& rStrm ); + /** Imports the STYLE record from the passed stream. */ + void importStyle( BiffInputStream& rStrm ); + + /** Imports a color palette from a UNO sequence in the passed any. */ + void importPalette( const ::com::sun::star::uno::Any& rPalette ); + + /** Final processing after import of all style settings. */ + void finalizeImport(); + + /** Returns the palette color with the specified index. */ + sal_Int32 getPaletteColor( sal_Int32 nIndex ) const; + /** Returns the specified font object. */ + FontRef getFont( sal_Int32 nFontId ) const; + /** Returns the specified border object. */ + BorderRef getBorder( sal_Int32 nBorderId ) const; + /** Returns the specified cell format object. */ + XfRef getCellXf( sal_Int32 nXfId ) const; + /** Returns the specified style format object. */ + XfRef getStyleXf( sal_Int32 nXfId ) const; + /** Returns the specified diferential cell format object. */ + DxfRef getDxf( sal_Int32 nDxfId ) const; + + /** Returns the font object of the specified cell XF. */ + FontRef getFontFromCellXf( sal_Int32 nXfId ) const; + /** Returns the default application font (used in the "Normal" cell style). */ + FontRef getDefaultFont() const; + /** Returns the model of the default application font (used in the "Normal" cell style). */ + const FontModel& getDefaultFontModel() const; + + /** Returns true, if the specified borders are equal. */ + bool equalBorders( sal_Int32 nBorderId1, sal_Int32 nBorderId2 ) const; + /** Returns true, if the specified fills are equal. */ + bool equalFills( sal_Int32 nFillId1, sal_Int32 nFillId2 ) const; + + /** Returns the default style sheet for unused cells. */ + ::rtl::OUString getDefaultStyleName() const; + /** Creates the style sheet described by the style XF with the passed identifier. */ + ::rtl::OUString createCellStyle( sal_Int32 nXfId ) const; + /** Creates the style sheet described by the DXF with the passed identifier. */ + ::rtl::OUString createDxfStyle( sal_Int32 nDxfId ) const; + + /** Writes the font attributes of the specified font data to the passed property map. */ + void writeFontToPropertyMap( PropertyMap& rPropMap, sal_Int32 nFontId ) const; + /** Writes the specified number format to the passed property map. */ + void writeNumFmtToPropertyMap( PropertyMap& rPropMap, sal_Int32 nNumFmtId ) const; + /** Writes the border attributes of the specified border data to the passed property map. */ + void writeBorderToPropertyMap( PropertyMap& rPropMap, sal_Int32 nBorderId ) const; + /** Writes the fill attributes of the specified fill data to the passed property map. */ + void writeFillToPropertyMap( PropertyMap& rPropMap, sal_Int32 nFillId ) const; + /** Writes the cell formatting attributes of the specified XF to the passed property map. */ + void writeCellXfToPropertyMap( PropertyMap& rPropMap, sal_Int32 nXfId ) const; + /** Writes the cell formatting attributes of the specified style XF to the passed property map. */ + void writeStyleXfToPropertyMap( PropertyMap& rPropMap, sal_Int32 nXfId ) const; + + /** Writes the cell formatting attributes of the specified XF to the passed property set. */ + void writeCellXfToPropertySet( PropertySet& rPropSet, sal_Int32 nXfId ) const; + /** Writes the cell formatting attributes of the specified style XF to the passed property set. */ + void writeStyleXfToPropertySet( PropertySet& rPropSet, sal_Int32 nXfId ) const; + +private: + typedef RefVector< Font > FontVector; + typedef RefVector< Border > BorderVector; + typedef RefVector< Fill > FillVector; + typedef RefVector< Xf > XfVector; + typedef RefVector< Dxf > DxfVector; + typedef ::std::map< sal_Int32, ::rtl::OUString > DxfStyleMap; + + ColorPalette maPalette; /// Color palette. + FontVector maFonts; /// List of font objects. + NumberFormatsBuffer maNumFmts; /// List of all number format codes. + BorderVector maBorders; /// List of cell border objects. + FillVector maFills; /// List of cell area fill objects. + XfVector maCellXfs; /// List of cell formats. + XfVector maStyleXfs; /// List of cell styles. + CellStyleBuffer maCellStyles; /// All built-in and user defined cell styles. + DxfVector maDxfs; /// List of differential cell styles. + mutable DxfStyleMap maDxfStyles; /// Maps DXF identifiers to Calc style sheet names. +}; + +// ============================================================================ + +} // namespace xls +} // namespace oox + +#endif diff --git a/oox/inc/oox/xls/stylesfragment.hxx b/oox/inc/oox/xls/stylesfragment.hxx new file mode 100644 index 000000000000..eb1af53d9cdb --- /dev/null +++ b/oox/inc/oox/xls/stylesfragment.hxx @@ -0,0 +1,155 @@ +/************************************************************************* + * + * 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_STYLESFRAGMENT_HXX +#define OOX_XLS_STYLESFRAGMENT_HXX + +#include "oox/xls/excelhandlers.hxx" +#include "oox/xls/stylesbuffer.hxx" + +namespace oox { +namespace xls { + +// ============================================================================ + +class IndexedColorsContext : public WorkbookContextBase +{ +public: + explicit IndexedColorsContext( WorkbookFragmentBase& rFragment ); + +protected: + virtual ::oox::core::ContextHandlerRef onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ); + virtual ::oox::core::ContextHandlerRef onCreateRecordContext( sal_Int32 nRecId, SequenceInputStream& rStrm ); +}; + +// ============================================================================ + +class FontContext : public WorkbookContextBase +{ +public: + template< typename ParentType > + inline explicit FontContext( ParentType& rParent, const FontRef& rxFont ) : + WorkbookContextBase( rParent ), mxFont( rxFont ) {} + +protected: + virtual ::oox::core::ContextHandlerRef onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ); + +private: + FontRef mxFont; +}; + +// ============================================================================ + +class BorderContext : public WorkbookContextBase +{ +public: + template< typename ParentType > + inline explicit BorderContext( ParentType& rParent, const BorderRef& rxBorder ) : + WorkbookContextBase( rParent ), mxBorder( rxBorder ) {} + +protected: + virtual void onStartElement( const AttributeList& rAttribs ); + virtual ::oox::core::ContextHandlerRef onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ); + +private: + BorderRef mxBorder; +}; + +// ============================================================================ + +class FillContext : public WorkbookContextBase +{ +public: + template< typename ParentType > + inline explicit FillContext( ParentType& rParent, const FillRef& rxFill ) : + WorkbookContextBase( rParent ), mxFill( rxFill ), mfGradPos( -1.0 ) {} + +protected: + virtual ::oox::core::ContextHandlerRef onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ); + +private: + FillRef mxFill; + double mfGradPos; /// Gradient color position. +}; + +// ============================================================================ + +class XfContext : public WorkbookContextBase +{ +public: + template< typename ParentType > + inline explicit XfContext( ParentType& rParent, const XfRef& rxXf, bool bCellXf ) : + WorkbookContextBase( rParent ), mxXf( rxXf ), mbCellXf( bCellXf ) {} + +protected: + virtual void onStartElement( const AttributeList& rAttribs ); + virtual ::oox::core::ContextHandlerRef onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ); + +private: + XfRef mxXf; + bool mbCellXf; /// True = cell XF, false = style XF. +}; + +// ============================================================================ + +class DxfContext : public WorkbookContextBase +{ +public: + template< typename ParentType > + inline explicit DxfContext( ParentType& rParent, const DxfRef& rxDxf ) : + WorkbookContextBase( rParent ), mxDxf( rxDxf ) {} + +protected: + virtual ::oox::core::ContextHandlerRef onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ); + +private: + DxfRef mxDxf; +}; + +// ============================================================================ + +class StylesFragment : public WorkbookFragmentBase +{ +public: + explicit StylesFragment( + const WorkbookHelper& rHelper, + const ::rtl::OUString& rFragmentPath ); + +protected: + virtual ::oox::core::ContextHandlerRef onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ); + virtual ::oox::core::ContextHandlerRef onCreateRecordContext( sal_Int32 nRecId, SequenceInputStream& rStrm ); + + virtual const ::oox::core::RecordInfo* getRecordInfos() const; + virtual void finalizeImport(); +}; + +// ============================================================================ + +} // namespace xls +} // namespace oox + +#endif diff --git a/oox/inc/oox/xls/tablebuffer.hxx b/oox/inc/oox/xls/tablebuffer.hxx new file mode 100644 index 000000000000..d643fbc40728 --- /dev/null +++ b/oox/inc/oox/xls/tablebuffer.hxx @@ -0,0 +1,139 @@ +/************************************************************************* + * + * 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_TABLEBUFFER_HXX +#define OOX_XLS_TABLEBUFFER_HXX + +#include <com/sun/star/table/CellRangeAddress.hpp> +#include "oox/xls/autofilterbuffer.hxx" +#include "oox/xls/workbookhelper.hxx" + +namespace oox { +namespace xls { + +// ============================================================================ + +struct TableModel +{ + ::com::sun::star::table::CellRangeAddress + maRange; /// Original (unchecked) range of the table. + ::rtl::OUString maProgName; /// Programmatical name. + ::rtl::OUString maDisplayName; /// Display name. + sal_Int32 mnId; /// Unique table identifier. + sal_Int32 mnType; /// Table type (worksheet, query, etc.). + sal_Int32 mnHeaderRows; /// Number of header rows. + sal_Int32 mnTotalsRows; /// Number of totals rows. + + explicit TableModel(); +}; + +// ---------------------------------------------------------------------------- + +class Table : public WorkbookHelper +{ +public: + explicit Table( const WorkbookHelper& rHelper ); + + /** Imports a table definition from the passed attributes. */ + void importTable( const AttributeList& rAttribs, sal_Int16 nSheet ); + /** Imports a table definition from a TABLE record. */ + void importTable( SequenceInputStream& rStrm, sal_Int16 nSheet ); + /** Creates a new auto filter and stores it internally. */ + inline AutoFilter& createAutoFilter() { return maAutoFilters.createAutoFilter(); } + + /** Creates a database range from this tables. */ + void finalizeImport(); + + /** Returns the unique table identifier. */ + inline sal_Int32 getTableId() const { return maModel.mnId; } + /** Returns the token index used in API token arrays (com.sun.star.sheet.FormulaToken). */ + inline sal_Int32 getTokenIndex() const { return mnTokenIndex; } + /** Returns the original display name of the table. */ + inline const ::rtl::OUString& getDisplayName() const { return maModel.maDisplayName; } + + /** Returns the original (unchecked) total range of the table. */ + inline const ::com::sun::star::table::CellRangeAddress& getOriginalRange() const { return maModel.maRange; } + /** Returns the cell range of this table. */ + inline const ::com::sun::star::table::CellRangeAddress& getRange() const { return maDestRange; } + /** Returns the number of columns of this table. */ + inline sal_Int32 getWidth() const { return maDestRange.EndColumn - maDestRange.StartColumn + 1; } + /** Returns the number of rows of this table. */ + inline sal_Int32 getHeight() const { return maDestRange.EndRow - maDestRange.StartRow + 1; } + /** Returns the number of header rows in the table range. */ + inline sal_Int32 getHeaderRows() const { return maModel.mnHeaderRows; } + /** Returns the number of totals rows in the table range. */ + inline sal_Int32 getTotalsRows() const { return maModel.mnTotalsRows; } + +private: + TableModel maModel; + AutoFilterBuffer maAutoFilters; /// Filter settings for this table. + ::rtl::OUString maDBRangeName; /// Name of the databae range in the Calc document. + ::com::sun::star::table::CellRangeAddress + maDestRange; /// Validated range of the table in the worksheet. + sal_Int32 mnTokenIndex; /// Token index used in API token array. +}; + +typedef ::boost::shared_ptr< Table > TableRef; + +// ============================================================================ + +class TableBuffer : public WorkbookHelper +{ +public: + explicit TableBuffer( const WorkbookHelper& rHelper ); + + /** Creates a new empty table. */ + Table& createTable(); + + /** Creates database ranges from all imported tables. */ + void finalizeImport(); + + /** Returns a table by its identifier. */ + TableRef getTable( sal_Int32 nTableId ) const; + /** Returns a table by its display name. */ + TableRef getTable( const ::rtl::OUString& rDispName ) const; + +private: + /** Inserts the passed table into the maps according to its identifier and name. */ + void insertTableToMaps( const TableRef& rxTable ); + +private: + typedef RefVector< Table > TableVector; + typedef RefMap< sal_Int32, Table > TableIdMap; + typedef RefMap< ::rtl::OUString, Table > TableNameMap; + + TableVector maTables; + TableIdMap maIdTables; + TableNameMap maNameTables; +}; + +// ============================================================================ + +} // namespace xls +} // namespace oox + +#endif diff --git a/oox/inc/oox/xls/tablefragment.hxx b/oox/inc/oox/xls/tablefragment.hxx new file mode 100644 index 000000000000..9c2678405ee5 --- /dev/null +++ b/oox/inc/oox/xls/tablefragment.hxx @@ -0,0 +1,62 @@ +/************************************************************************* + * + * 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_TABLEFRAGMENT_HXX +#define OOX_XLS_TABLEFRAGMENT_HXX + +#include "oox/xls/excelhandlers.hxx" + +namespace oox { +namespace xls { + +class Table; + +// ============================================================================ + +class TableFragment : public WorksheetFragmentBase +{ +public: + explicit TableFragment( + const WorksheetHelper& rHelper, + const ::rtl::OUString& rFragmentPath ); + +protected: + virtual ::oox::core::ContextHandlerRef onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ); + virtual ::oox::core::ContextHandlerRef onCreateRecordContext( sal_Int32 nRecId, SequenceInputStream& rStrm ); + + virtual const ::oox::core::RecordInfo* getRecordInfos() const; + +private: + Table& mrTable; +}; + +// ============================================================================ + +} // namespace xls +} // namespace oox + +#endif diff --git a/oox/inc/oox/xls/themebuffer.hxx b/oox/inc/oox/xls/themebuffer.hxx new file mode 100644 index 000000000000..95d092198b95 --- /dev/null +++ b/oox/inc/oox/xls/themebuffer.hxx @@ -0,0 +1,63 @@ +/************************************************************************* + * + * 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_THEMEBUFFER_HXX +#define OOX_XLS_THEMEBUFFER_HXX + +#include "oox/drawingml/theme.hxx" +#include "oox/xls/workbookhelper.hxx" + +namespace oox { +namespace xls { + +struct FontModel; + +// ============================================================================ + +class ThemeBuffer : public ::oox::drawingml::Theme, public WorkbookHelper +{ +public: + explicit ThemeBuffer( const WorkbookHelper& rHelper ); + virtual ~ThemeBuffer(); + + /** Returns the theme color with the specified token identifier. */ + sal_Int32 getColorByToken( sal_Int32 nToken ) const; + + /** Returns the default font data for the current file type. */ + inline const FontModel& getDefaultFontModel() const { return *mxDefFontModel; } + +private: + typedef ::std::auto_ptr< FontModel > FontModelPtr; + FontModelPtr mxDefFontModel; +}; + +// ============================================================================ + +} // namespace xls +} // namespace oox + +#endif diff --git a/oox/inc/oox/xls/unitconverter.hxx b/oox/inc/oox/xls/unitconverter.hxx new file mode 100644 index 000000000000..1ea4180bc6fd --- /dev/null +++ b/oox/inc/oox/xls/unitconverter.hxx @@ -0,0 +1,123 @@ +/************************************************************************* + * + * 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_UNITCONVERTER_HXX +#define OOX_XLS_UNITCONVERTER_HXX + +#include <map> +#include <vector> +#include "oox/xls/workbookhelper.hxx" + +namespace com { namespace sun { namespace star { + namespace util { struct Date; struct DateTime; } +} } } + +namespace oox { +namespace xls { + +// ============================================================================ + +/** Units supported by the UnitConverter class. */ +enum Unit +{ + UNIT_INCH, /// Inches. + UNIT_POINT, /// Points. + UNIT_TWIP, /// Twips (1/20 point). + UNIT_EMU, /// English Metric Unit (1/360,000 cm). + UNIT_SCREENX, /// Horizontal screen pixels. + UNIT_SCREENY, /// Vertical screen pixels. + UNIT_REFDEVX, /// Horizontal pixels in Calc reference device. + UNIT_REFDEVY, /// Vertical pixels in Calc reference device. + UNIT_DIGIT, /// Digit width of document default font. + UNIT_SPACE, /// Space character width of document default font. + + UNIT_ENUM_SIZE +}; + +/** Helper class that provides functions to convert values from and to + different units. + + Provides functions to calculate the width of certain characters of the + default font of the imported/exported document. The default font is always + the first font in the styles font list, and is always referenced by the + default cell style ("Normal" style in Excel) which is used by all empty + unformatted cells in the document. To be able to calculate the charcter + width correctly, the default font must be known, which is the case after + the finalizeImport() or finalizeExport() functions have been called. Caller + must make sure to not call the character width conversion functions before. + */ +class UnitConverter : public WorkbookHelper +{ +public: + explicit UnitConverter( const WorkbookHelper& rHelper ); + + /** Final processing after import of all style settings. */ + void finalizeImport(); + /** Updates internal nulldate for date/serial conversion. */ + void finalizeNullDate( const ::com::sun::star::util::Date& rNullDate ); + + /** Converts the passed value between the passed units. */ + double scaleValue( double fValue, Unit eFromUnit, Unit eToUnit ) const; + + /** Converts the passed value to 1/100 millimeters. */ + sal_Int32 scaleToMm100( double fValue, Unit eUnit ) const; + /** Converts the passed value from 1/100 millimeters to the passed unit. */ + double scaleFromMm100( sal_Int32 nMm100, Unit eUnit ) const; + + /** Returns the serial value of the passed datetime, based on current nulldate. */ + double calcSerialFromDateTime( const ::com::sun::star::util::DateTime& rDateTime ) const; + /** Returns the datetime of the passed serial value, based on current nulldate. */ + ::com::sun::star::util::DateTime calcDateTimeFromSerial( double fSerial ) const; + + /** Returns an error string from the passed BIFF error code. */ + ::rtl::OUString calcOoxErrorCode( sal_uInt8 nErrorCode ) const; + /** Returns a BIFF error code from the passed error string. */ + sal_uInt8 calcBiffErrorCode( const ::rtl::OUString& rErrorCode ) const; + +private: + /** Adds an error code to the internal maps. */ + void addErrorCode( sal_uInt8 nErrorCode, const ::rtl::OUString& rErrorCode ); + /** Returns the conversion coefficient for the passed unit. */ + double getCoefficient( Unit eUnit ) const; + +private: + typedef ::std::vector< double > DoubleVector; + typedef ::std::map< ::rtl::OUString, sal_uInt8 > OoxErrorCodeMap; + typedef ::std::map< sal_uInt8, ::rtl::OUString > BiffErrorCodeMap; + + DoubleVector maCoeffs; /// Coefficients for unit conversion. + OoxErrorCodeMap maOoxErrCodes; /// Maps error code strings to BIFF error constants. + BiffErrorCodeMap maBiffErrCodes; /// Maps BIFF error constants to error code strings. + sal_Int32 mnNullDate; /// Nulldate of this workbook (number of days since 0000-01-01). +}; + +// ============================================================================ + +} // namespace xls +} // namespace oox + +#endif diff --git a/oox/inc/oox/xls/viewsettings.hxx b/oox/inc/oox/xls/viewsettings.hxx new file mode 100644 index 000000000000..c5880bf077fe --- /dev/null +++ b/oox/inc/oox/xls/viewsettings.hxx @@ -0,0 +1,232 @@ +/************************************************************************* + * + * 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_VIEWSETTINGS_HXX +#define OOX_XLS_VIEWSETTINGS_HXX + +#include <com/sun/star/table/CellAddress.hpp> +#include <com/sun/star/table/CellRangeAddress.hpp> +#include "oox/xls/addressconverter.hxx" +#include "oox/xls/stylesbuffer.hxx" +#include "oox/xls/worksheethelper.hxx" + +namespace oox { +namespace xls { + +// ============================================================================ + +/** Contains all settings for a selection in a single pane of a sheet. */ +struct PaneSelectionModel +{ + ::com::sun::star::table::CellAddress maActiveCell; /// Position of active cell (cursor). + ApiCellRangeList maSelection; /// Selected cell ranges. + sal_Int32 mnActiveCellId; /// Index of active cell in selection list. + + explicit PaneSelectionModel(); +}; + +// ---------------------------------------------------------------------------- + +/** Contains all view settings for a single sheet. */ +struct SheetViewModel +{ + typedef RefMap< sal_Int32, PaneSelectionModel > PaneSelectionModelMap; + + PaneSelectionModelMap maPaneSelMap; /// Selections of all panes. + Color maGridColor; /// Grid color. + ::com::sun::star::table::CellAddress maFirstPos; /// First visible cell. + ::com::sun::star::table::CellAddress maSecondPos; /// First visible cell in additional panes. + sal_Int32 mnWorkbookViewId; /// Index into list of workbookView elements. + sal_Int32 mnViewType; /// View type (normal, page break, layout). + sal_Int32 mnActivePaneId; /// Active pane (with cell cursor). + sal_Int32 mnPaneState; /// Pane state (frozen, split). + double mfSplitX; /// Split X position (twips), or number of frozen columns. + double mfSplitY; /// Split Y position (twips), or number of frozen rows. + sal_Int32 mnCurrentZoom; /// Zoom factor for current view. + sal_Int32 mnNormalZoom; /// Zoom factor for normal view. + sal_Int32 mnSheetLayoutZoom; /// Zoom factor for pagebreak preview. + sal_Int32 mnPageLayoutZoom; /// Zoom factor for page layout view. + bool mbSelected; /// True = sheet is selected. + bool mbRightToLeft; /// True = sheet in right-to-left mode. + bool mbDefGridColor; /// True = default grid color. + bool mbShowFormulas; /// True = show formulas instead of results. + bool mbShowGrid; /// True = show cell grid. + bool mbShowHeadings; /// True = show column/row headings. + bool mbShowZeros; /// True = show zero value zells. + bool mbShowOutline; /// True = show outlines. + bool mbZoomToFit; /// True = zoom chart sheet to fit window. + + explicit SheetViewModel(); + + /** Returns true, if page break preview is active. */ + bool isPageBreakPreview() const; + /** Returns the zoom in normal view (returns default, if current value is 0). */ + sal_Int32 getNormalZoom() const; + /** Returns the zoom in pagebreak preview (returns default, if current value is 0). */ + sal_Int32 getPageBreakZoom() const; + /** Returns the grid color as RGB value. */ + sal_Int32 getGridColor( const ::oox::core::FilterBase& rFilter ) const; + + /** Returns the selection data, if available, otherwise 0. */ + const PaneSelectionModel* getPaneSelection( sal_Int32 nPaneId ) const; + /** Returns the selection data of the active pane. */ + const PaneSelectionModel* getActiveSelection() const; + /** Returns read/write access to the selection data of the specified pane. */ + PaneSelectionModel& createPaneSelection( sal_Int32 nPaneId ); +}; + +typedef ::boost::shared_ptr< SheetViewModel > SheetViewModelRef; + +// ---------------------------------------------------------------------------- + +class SheetViewSettings : public WorksheetHelper +{ +public: + explicit SheetViewSettings( const WorksheetHelper& rHelper ); + + /** Imports the sheetView element containing sheet view settings. */ + void importSheetView( const AttributeList& rAttribs ); + /** Imports the pane element containing sheet pane settings. */ + void importPane( const AttributeList& rAttribs ); + /** Imports the selection element containing selection settings for a pane. */ + void importSelection( const AttributeList& rAttribs ); + /** Imports the sheetView element containing view settings of a chart sheet. */ + void importChartSheetView( const AttributeList& rAttribs ); + + /** Imports the SHEETVIEW record containing sheet view settings. */ + void importSheetView( SequenceInputStream& rStrm ); + /** Imports the PANE record containing sheet pane settings. */ + void importPane( SequenceInputStream& rStrm ); + /** Imports the SELECTION record containing selection settings for a pane. */ + void importSelection( SequenceInputStream& rStrm ); + /** Imports the CHARTSHEETVIEW record containing view settings of a chart sheet. */ + void importChartSheetView( SequenceInputStream& rStrm ); + + /** Imports the WINDOW2 record containing sheet view settings. */ + void importWindow2( BiffInputStream& rStrm ); + /** Imports the PANE record containing sheet pane settings. */ + void importPane( BiffInputStream& rStrm ); + /** Imports the SCL record containing sheet zoom settings. */ + void importScl( BiffInputStream& rStrm ); + /** Imports the SELECTION record containing selection settings for a pane. */ + void importSelection( BiffInputStream& rStrm ); + + /** Converts all imported sheet view settings. */ + void finalizeImport(); + + /** Returns true, if the sheet layout is set to right-to-left. */ + bool isSheetRightToLeft() const; + +private: + SheetViewModelRef createSheetView(); + +private: + typedef RefVector< SheetViewModel > SheetViewModelVec; + SheetViewModelVec maSheetViews; +}; + +// ============================================================================ + +/** Contains all view settings for the entire document. */ +struct WorkbookViewModel +{ + sal_Int32 mnWinX; /// X position of the workbook window (twips). + sal_Int32 mnWinY; /// Y position of the workbook window (twips). + sal_Int32 mnWinWidth; /// Width of the workbook window (twips). + sal_Int32 mnWinHeight; /// Height of the workbook window (twips). + sal_Int32 mnActiveSheet; /// Displayed (active) sheet. + sal_Int32 mnFirstVisSheet; /// First visible sheet in sheet tabbar. + sal_Int32 mnTabBarWidth; /// Width of sheet tabbar (1/1000 of window width). + sal_Int32 mnVisibility; /// Visibility state of workbook window. + bool mbShowTabBar; /// True = show sheet tabbar. + bool mbShowHorScroll; /// True = show horizontal sheet scrollbars. + bool mbShowVerScroll; /// True = show vertical sheet scrollbars. + bool mbMinimized; /// True = workbook window is minimized. + + explicit WorkbookViewModel(); +}; + +typedef ::boost::shared_ptr< WorkbookViewModel > WorkbookViewModelRef; + +// ---------------------------------------------------------------------------- + +class ViewSettings : public WorkbookHelper +{ +public: + explicit ViewSettings( const WorkbookHelper& rHelper ); + + /** Imports the workbookView element containing workbook view settings. */ + void importWorkbookView( const AttributeList& rAttribs ); + /** Imports the oleSize element containing the visible size of the workbook. */ + void importOleSize( const AttributeList& rAttribs ); + /** Imports the WORKBOOKVIEW record containing workbook view settings. */ + void importWorkbookView( SequenceInputStream& rStrm ); + /** Imports the OLESIZE record containing the visible size of the workbook. */ + void importOleSize( SequenceInputStream& rStrm ); + /** Imports the WINDOW1 record containing workbook view settings. */ + void importWindow1( BiffInputStream& rStrm ); + /** Imports the OLESIZE record containing the visible size of the workbook. */ + void importOleSize( BiffInputStream& rStrm ); + + /** Stores converted view settings for a specific worksheet. */ + void setSheetViewSettings( sal_Int16 nSheet, + const SheetViewModelRef& rxSheetView, + const ::com::sun::star::uno::Any& rProperties ); + /** Stores the used area for a specific worksheet. */ + void setSheetUsedArea( + const ::com::sun::star::table::CellRangeAddress& rUsedArea ); + + /** Converts all imported document view settings. */ + void finalizeImport(); + + /** Returns the Calc index of the active sheet. */ + sal_Int16 getActiveCalcSheet() const; + +private: + WorkbookViewModel& createWorkbookView(); + +private: + typedef RefVector< WorkbookViewModel > WorkbookViewModelVec; + typedef RefMap< sal_Int16, SheetViewModel > SheetViewModelMap; + typedef ::std::map< sal_Int16, ::com::sun::star::uno::Any > SheetPropertiesMap; + typedef ::std::map< sal_Int16, ::com::sun::star::table::CellRangeAddress > SheetUsedAreaMap; + + WorkbookViewModelVec maBookViews; /// Workbook view models. + SheetViewModelMap maSheetViews; /// Active view model for each sheet. + SheetPropertiesMap maSheetProps; /// Converted property sequences for each sheet. + SheetUsedAreaMap maSheetUsedAreas; /// Used area (cell range) of every sheet. + ::com::sun::star::table::CellRangeAddress + maOleSize; /// Visible area if this is an embedded OLE object. + bool mbValidOleSize; /// True = imported OLE size is a valid cell range. +}; + +// ============================================================================ + +} // namespace xls +} // namespace oox + +#endif diff --git a/oox/inc/oox/xls/workbookfragment.hxx b/oox/inc/oox/xls/workbookfragment.hxx new file mode 100644 index 000000000000..d0b0cadd416b --- /dev/null +++ b/oox/inc/oox/xls/workbookfragment.hxx @@ -0,0 +1,98 @@ +/************************************************************************* + * + * 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_WORKBOOKFRAGMENT_HXX +#define OOX_XLS_WORKBOOKFRAGMENT_HXX + +#include "oox/xls/defnamesbuffer.hxx" +#include "oox/xls/excelhandlers.hxx" + +namespace oox { +namespace xls { + +class ExternalLink; + +// ============================================================================ + +class WorkbookFragment : public WorkbookFragmentBase +{ +public: + explicit WorkbookFragment( + const WorkbookHelper& rHelper, + const ::rtl::OUString& rFragmentPath ); + +protected: + virtual ::oox::core::ContextHandlerRef onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ); + virtual void onCharacters( const ::rtl::OUString& rChars ); + + virtual ::oox::core::ContextHandlerRef onCreateRecordContext( sal_Int32 nRecId, SequenceInputStream& rStrm ); + + virtual const ::oox::core::RecordInfo* getRecordInfos() const; + virtual void finalizeImport(); + +private: + void importExternalReference( const AttributeList& rAttribs ); + void importDefinedName( const AttributeList& rAttribs ); + void importPivotCache( const AttributeList& rAttribs ); + + void importExternalRef( SequenceInputStream& rStrm ); + void importPivotCache( SequenceInputStream& rStrm ); + + void importExternalLinkFragment( ExternalLink& rExtLink ); + void importPivotCacheDefFragment( const ::rtl::OUString& rRelId, sal_Int32 nCacheId ); + +private: + DefinedNameRef mxCurrName; +}; + +// ============================================================================ + +class BiffWorkbookFragment : public BiffWorkbookFragmentBase +{ +public: + explicit BiffWorkbookFragment( const WorkbookHelper& rHelper, const ::rtl::OUString& rStrmName ); + + /** Imports the entire workbook stream, including all contained worksheets. */ + virtual bool importFragment(); + +private: + /** Imports a complete BIFF4 workspace fragment (with embedded sheets). */ + bool importWorkspaceFragment(); + /** Imports the workbook globals fragment from current stream position. */ + bool importGlobalsFragment( ISegmentProgressBar& rProgressBar ); + /** Imports a sheet fragment with passed type from current stream position. */ + bool importSheetFragment( + ISegmentProgressBar& rProgressBar, + BiffFragmentType eFragment, sal_Int16 nCalcSheet ); +}; + +// ============================================================================ + +} // namespace xls +} // namespace oox + +#endif diff --git a/oox/inc/oox/xls/workbookhelper.hxx b/oox/inc/oox/xls/workbookhelper.hxx new file mode 100644 index 000000000000..ecf824076ef5 --- /dev/null +++ b/oox/inc/oox/xls/workbookhelper.hxx @@ -0,0 +1,325 @@ +/************************************************************************* + * + * 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_WORKBOOKHELPER_HXX +#define OOX_XLS_WORKBOOKHELPER_HXX + +#include <boost/shared_ptr.hpp> +#include <rtl/ref.hxx> +#include "oox/helper/storagebase.hxx" +#include "oox/xls/biffhelper.hxx" + +namespace com { namespace sun { namespace star { + namespace container { class XNameAccess; } + namespace container { class XNameContainer; } + namespace lang { class XMultiServiceFactory; } + namespace sheet { class XDatabaseRange; } + namespace sheet { class XNamedRange; } + namespace sheet { class XSpreadsheet; } + namespace sheet { class XSpreadsheetDocument; } + namespace style { class XStyle; } + namespace table { struct CellAddress; } + namespace table { struct CellRangeAddress; } + namespace table { class XCell; } + namespace table { class XCellRange; } +} } } + +namespace oox { + class AttributeList; + class SegmentProgressBar; + class SequenceInputStream; +} + +namespace oox { namespace core { + class BinaryFilterBase; + class FilterBase; + class FragmentHandler; + class XmlFilterBase; +} } + +namespace oox { namespace drawingml { + class Theme; +} } + +namespace oox { +namespace xls { + +class ExcelFilter; +class ExcelBiffFilter; + +// ============================================================================ + +/** An enumeration for all supported spreadsheet filter types. */ +enum FilterType +{ + FILTER_OOXML, /// MS Excel OOXML (Office Open XML) or BIFF12. + FILTER_BIFF, /// MS Excel BIFF2-BIFF8 (Binary Interchange File Format). + FILTER_UNKNOWN /// Unknown filter type. +}; + +// ============================================================================ + +/** Functor for case-insensitive string comparison, usable in maps etc. */ +struct IgnoreCaseCompare +{ + bool operator()( const ::rtl::OUString& rName1, const ::rtl::OUString& rName2 ) const; +}; + +// ============================================================================ + +class AddressConverter; +class BiffCodecHelper; +class ConnectionsBuffer; +class DefinedNamesBuffer; +class ExcelChartConverter; +class ExternalLinkBuffer; +class FormulaParser; +class PageSettingsConverter; +class PivotCacheBuffer; +class PivotTableBuffer; +class ScenarioBuffer; +class SharedStringsBuffer; +class StylesBuffer; +class TableBuffer; +class ThemeBuffer; +class UnitConverter; +class ViewSettings; +class WorkbookData; +class WorkbookSettings; +class WorksheetBuffer; + +/** 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. + + 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. + */ +class WorkbookHelper +{ +public: + inline /*implicit*/ WorkbookHelper( WorkbookData& rBookData ) : mrBookData( rBookData ) {} + virtual ~WorkbookHelper(); + + // 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. */ + 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. */ + void setVbaProjectStorage( const StorageRef& rxVbaPrjStrg ); + /** Final conversion after importing the workbook. */ + void finalizeWorkbookImport(); + + // document model --------------------------------------------------------- + + /** 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 > + getSheetFromDoc( sal_Int16 nSheet ) const; + /** Returns a reference to the specified spreadsheet in the document model. */ + ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XSpreadsheet > + getSheetFromDoc( const ::rtl::OUString& rSheet ) const; + + /** Returns the XCell interface for the passed cell address. */ + ::com::sun::star::uno::Reference< ::com::sun::star::table::XCell > + getCellFromDoc( + 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 > + getCellRangeFromDoc( + const ::com::sun::star::table::CellRangeAddress& rRange ) const; + + /** Returns the cell or page styles container from the Calc document. */ + ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer > + getStyleFamily( bool bPageStyles ) const; + /** Returns the specified cell or page style from the Calc document. */ + ::com::sun::star::uno::Reference< ::com::sun::star::style::XStyle > + getStyleObject( const ::rtl::OUString& rStyleName, bool bPageStyle ) const; + + /** Creates and returns a defined name on-the-fly in the Calc document. + The name will not be buffered in the global defined names buffer. + @param orName (in/out-parameter) Returns the resulting used name. */ + ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XNamedRange > + createNamedRangeObject( + ::rtl::OUString& orName, + sal_Int32 nNameFlags = 0 ) const; + + /** Creates and returns a database range on-the-fly in the Calc document. + The range will not be buffered in the global table buffer. + @param orName (in/out-parameter) Returns the resulting used name. */ + ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XDatabaseRange > + createDatabaseRangeObject( + ::rtl::OUString& orName, + const ::com::sun::star::table::CellRangeAddress& rRangeAddr ) const; + + /** Creates and returns a com.sun.star.style.Style object for cells or pages. */ + ::com::sun::star::uno::Reference< ::com::sun::star::style::XStyle > + createStyleObject( + ::rtl::OUString& orStyleName, + bool bPageStyle ) const; + + // buffers ---------------------------------------------------------------- + + /** Returns the global workbook settings object. */ + WorkbookSettings& getWorkbookSettings() const; + /** Returns the workbook and sheet view settings object. */ + ViewSettings& getViewSettings() const; + /** Returns the worksheet buffer containing sheet names and properties. */ + WorksheetBuffer& getWorksheets() const; + /** Returns the office theme object read from the theme substorage. */ + ThemeBuffer& getTheme() const; + /** Returns all cell formatting objects read from the styles substream. */ + StylesBuffer& getStyles() const; + /** Returns the shared strings read from the shared strings substream. */ + SharedStringsBuffer& getSharedStrings() const; + /** Returns the external links read from the external links substream. */ + ExternalLinkBuffer& getExternalLinks() const; + /** Returns the defined names read from the workbook globals. */ + DefinedNamesBuffer& getDefinedNames() const; + /** Returns the tables collection (equivalent to Calc's database ranges). */ + TableBuffer& getTables() const; + /** Returns the scenarios collection. */ + ScenarioBuffer& getScenarios() const; + /** Returns the collection of external data connections. */ + ConnectionsBuffer& getConnections() const; + /** Returns the collection of pivot caches. */ + PivotCacheBuffer& getPivotCaches() const; + /** Returns the collection of pivot tables. */ + PivotTableBuffer& getPivotTables() const; + + // converters ------------------------------------------------------------- + + /** Returns the import formula parser (import filter only!). */ + FormulaParser& getFormulaParser() const; + /** Returns the measurement unit converter. */ + UnitConverter& getUnitConverter() const; + /** Returns the converter for string to cell address/range conversion. */ + AddressConverter& getAddressConverter() const; + /** Returns the chart object converter. */ + ExcelChartConverter& getChartConverter() const; + /** Returns the page and print settings converter. */ + PageSettingsConverter& getPageSettingsConverter() const; + + // OOXML/BIFF12 specific (MUST NOT be called in BIFF filter) -------------- + + /** Returns the base OOXML/BIFF12 filter object. + Must not be called, if current filter is not the OOXML/BIFF12 filter. */ + ::oox::core::XmlFilterBase& getOoxFilter() const; + + /** Imports a fragment using the passed fragment handler, which contains + the full path to the fragment stream. */ + bool importOoxFragment( const ::rtl::Reference< ::oox::core::FragmentHandler >& rxHandler ); + + // BIFF2-BIFF8 specific (MUST NOT be called in OOXML/BIFF12 filter) ------- + + /** Returns the base BIFF filter object. */ + ::oox::core::BinaryFilterBase& getBiffFilter() const; + /** Returns the BIFF type in binary filter. */ + BiffType getBiff() const; + + /** Returns the text encoding used to import/export byte strings. */ + rtl_TextEncoding getTextEncoding() const; + /** Sets the text encoding to import/export byte strings. */ + void setTextEncoding( rtl_TextEncoding eTextEnc ); + /** Sets code page read from a CODEPAGE record for byte string import. */ + void setCodePage( sal_uInt16 nCodePage ); + /** Sets text encoding from the default application font, if CODEPAGE record is missing. */ + void setAppFontEncoding( rtl_TextEncoding eAppFontEnc ); + + /** Enables workbook file mode, used for BIFF4 workspace files. */ + void setIsWorkbookFile(); + /** Recreates global buffers that are used per sheet in specific BIFF versions. */ + void createBuffersPerSheet( sal_Int16 nSheet ); + + /** Returns the codec helper that stores the encoder/decoder object. */ + 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& ); +}; + +// ============================================================================ + +} // namespace xls +} // namespace oox + +#endif diff --git a/oox/inc/oox/xls/workbooksettings.hxx b/oox/inc/oox/xls/workbooksettings.hxx new file mode 100644 index 000000000000..858e886df778 --- /dev/null +++ b/oox/inc/oox/xls/workbooksettings.hxx @@ -0,0 +1,164 @@ +/************************************************************************* + * + * 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_WORKBOOKSETTINGS_HXX +#define OOX_XLS_WORKBOOKSETTINGS_HXX + +#include "oox/xls/workbookhelper.hxx" + +namespace com { namespace sun { namespace star { namespace util { struct Date; } } } } + +namespace oox { +namespace xls { + +// ============================================================================ + +/** Settings for workbook write protection. */ +struct FileSharingModel +{ + ::rtl::OUString maUserName; /// User who added the write protection password. + sal_uInt16 mnPasswordHash; /// Hash value of the write protection password. + bool mbRecommendReadOnly; /// True = recommend read-only mode on opening. + + explicit FileSharingModel(); +}; + +// ============================================================================ + +/** Global workbook settings. */ +struct WorkbookSettingsModel +{ + ::rtl::OUString maCodeName; /// VBA codename for the workbook. + sal_Int32 mnShowObjectMode; /// Specifies how objects are shown. + sal_Int32 mnUpdateLinksMode; /// Specifies how external links are updated. + sal_Int32 mnDefaultThemeVer; /// Default theme version. + bool mbDateMode1904; /// True = null date is 1904-01-01. + bool mbSaveExtLinkValues; /// True = save cached cell values for external links. + + explicit WorkbookSettingsModel(); + + /** Sets BIFF object visibility mode. */ + void setBiffObjectMode( sal_uInt16 nObjMode ); +}; + +// ============================================================================ + +/** Workbook calculation settings. */ +struct CalcSettingsModel +{ + double mfIterateDelta; /// Minimum change in circular references. + sal_Int32 mnCalcId; /// Calculation engine identifier. + sal_Int32 mnRefMode; /// Cell reference mode: A1 or R1C1. + sal_Int32 mnCalcMode; /// Automatic or manual recalculation. + sal_Int32 mnIterateCount; /// Number of iterations in circular references. + sal_Int32 mnProcCount; /// Number of processors for concurrent calculation. + bool mbCalcOnSave; /// True = always recalculate formulas before save. + bool mbCalcCompleted; /// True = formulas have been recalculated before save. + bool mbFullPrecision; /// True = use full precision on calculation. + bool mbIterate; /// True = allow circular references. + bool mbConcurrent; /// True = concurrent calculation enabled. + bool mbUseNlr; /// True = use natural language references in formulas. + + explicit CalcSettingsModel(); +}; + +// ============================================================================ + +class WorkbookSettings : public WorkbookHelper +{ +public: + explicit WorkbookSettings( const WorkbookHelper& rHelper ); + + /** Imports the fileSharing element containing write protection settings. */ + void importFileSharing( const AttributeList& rAttribs ); + /** Imports the workbookPr element containing global workbook settings. */ + void importWorkbookPr( const AttributeList& rAttribs ); + /** Imports the calcPr element containing workbook calculation settings. */ + void importCalcPr( const AttributeList& rAttribs ); + + /** Imports the FILESHARING record containing write protection settings. */ + void importFileSharing( SequenceInputStream& rStrm ); + /** Imports the WORKBOOKPR record containing global workbook settings. */ + void importWorkbookPr( SequenceInputStream& rStrm ); + /** Imports the CALCPR record containing workbook calculation settings. */ + void importCalcPr( SequenceInputStream& rStrm ); + + /** Sets the save external linked values flag, e.g. from the WSBOOL record. */ + void setSaveExtLinkValues( bool bSaveExtLinks ); + /** Imports the BOOKBOOL record. */ + void importBookBool( BiffInputStream& rStrm ); + /** Imports the CALCCOUNT record. */ + void importCalcCount( BiffInputStream& rStrm ); + /** Imports the CALCMODE record. */ + void importCalcMode( BiffInputStream& rStrm ); + /** Imports the CODENAME record. */ + void importCodeName( BiffInputStream& rStrm ); + /** Imports the DATEMODE record. */ + void importDateMode( BiffInputStream& rStrm ); + /** Imports the DELTA record. */ + void importDelta( BiffInputStream& rStrm ); + /** Imports the FILESHARING record. */ + void importFileSharing( BiffInputStream& rStrm ); + /** Imports the HIDEOBJ record. */ + void importHideObj( BiffInputStream& rStrm ); + /** Imports the ITERATION record. */ + void importIteration( BiffInputStream& rStrm ); + /** Imports the PRECISION record. */ + void importPrecision( BiffInputStream& rStrm ); + /** Imports the REFMODE record. */ + void importRefMode( BiffInputStream& rStrm ); + /** Imports the SAVERECALC record. */ + void importSaveRecalc( BiffInputStream& rStrm ); + /** Imports the UNCALCED record. */ + void importUncalced( BiffInputStream& rStrm ); + /** Imports the USESELFS record. */ + void importUsesElfs( BiffInputStream& rStrm ); + + /** Converts the imported workbook settings. */ + void finalizeImport(); + + /** Returns the show objects mode (considered a view setting in Calc). */ + sal_Int16 getApiShowObjectMode() const; + /** Returns the nulldate of this workbook. */ + ::com::sun::star::util::Date getNullDate() const; + +private: + /** Updates date mode and unit converter nulldate. */ + void setDateMode( bool bDateMode1904 ); + +private: + FileSharingModel maFileSharing; + WorkbookSettingsModel maBookSettings; + CalcSettingsModel maCalcSettings; +}; + +// ============================================================================ + +} // namespace xls +} // namespace oox + +#endif diff --git a/oox/inc/oox/xls/worksheetbuffer.hxx b/oox/inc/oox/xls/worksheetbuffer.hxx new file mode 100644 index 000000000000..7c59cce988dd --- /dev/null +++ b/oox/inc/oox/xls/worksheetbuffer.hxx @@ -0,0 +1,133 @@ +/************************************************************************* + * + * 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_WORKSHEETBUFFER_HXX +#define OOX_XLS_WORKSHEETBUFFER_HXX + +#include <utility> +#include "oox/helper/refmap.hxx" +#include "oox/helper/refvector.hxx" +#include "oox/xls/workbookhelper.hxx" + +namespace com { namespace sun { namespace star { + namespace i18n { class XCharacterClassification; } +} } } + +namespace oox { +namespace xls { + +// ============================================================================ + +/** Contains data from the 'sheet' element describing a sheet in the workbook. */ +struct SheetInfoModel +{ + ::rtl::OUString maRelId; /// Relation identifier for the sheet substream. + ::rtl::OUString maName; /// Original name of the sheet. + sal_Int64 mnBiffHandle; /// BIFF record handle of the sheet substream. + sal_Int32 mnSheetId; /// Sheet identifier. + sal_Int32 mnState; /// Visibility state. + + explicit SheetInfoModel(); +}; + +// ============================================================================ + +/** Stores information about all sheets in a spreadsheet document. + + Information about sheets includes the sheet name, the visibility state, and + for the OOXML filter, the relation identifier of the sheet used to obtain + the related worksheet fragment. + */ +class WorksheetBuffer : public WorkbookHelper +{ +public: + explicit WorksheetBuffer( const WorkbookHelper& rHelper ); + + /** Returns the base file name without path and file extension. */ + static ::rtl::OUString getBaseFileName( const ::rtl::OUString& rUrl ); + + /** Initializes the buffer for single sheet files (BIFF2-BIFF4). */ + void initializeSingleSheet(); + + /** Imports the attributes of a sheet element. */ + void importSheet( const AttributeList& rAttribs ); + /** Imports the SHEET record from the passed BIFF12 stream. */ + void importSheet( SequenceInputStream& rStrm ); + /** Imports the SHEET record from the passed BIFF stream. */ + void importSheet( BiffInputStream& rStrm ); + /** Inserts a new empty sheet into the document. Looks for an unused name. + @return Index of the new sheet in the Calc document. */ + sal_Int16 insertEmptySheet( const ::rtl::OUString& rPreferredName, bool bVisible ); + + /** Returns the number of original sheets contained in the workbook. */ + sal_Int32 getWorksheetCount() const; + /** Returns the OOXML relation identifier of the specified worksheet. */ + ::rtl::OUString getWorksheetRelId( sal_Int32 nWorksheet ) const; + /** Returns the BIFF record handle of the associated sheet substream. */ + sal_Int64 getBiffRecordHandle( sal_Int32 nWorksheet ) const; + + /** Returns the Calc index of the specified worksheet. */ + sal_Int16 getCalcSheetIndex( sal_Int32 nWorksheet ) const; + /** Returns the finalized name of the specified worksheet. */ + ::rtl::OUString getCalcSheetName( sal_Int32 nWorksheet ) const; + + /** Returns the Calc index of the sheet with the passed original worksheet name. */ + sal_Int16 getCalcSheetIndex( const ::rtl::OUString& rWorksheetName ) const; + /** Returns the finalized name of the sheet with the passed worksheet name. */ + ::rtl::OUString getCalcSheetName( const ::rtl::OUString& rWorksheetName ) const; + +private: + struct SheetInfo : public SheetInfoModel + { + ::rtl::OUString maCalcName; + ::rtl::OUString maCalcQuotedName; + sal_Int16 mnCalcSheet; + + explicit SheetInfo( const SheetInfoModel& rModel, sal_Int16 nCalcSheet, const ::rtl::OUString& rCalcName ); + }; + + typedef ::std::pair< sal_Int16, ::rtl::OUString > IndexNamePair; + + /** Creates a new sheet in the Calc document. Does not insert anything in the own lists. */ + IndexNamePair createSheet( const ::rtl::OUString& rPreferredName, sal_Int32 nSheetPos, bool bVisible ); + /** Creates a new sheet in the Calc document and inserts the related SheetInfo. */ + void insertSheet( const SheetInfoModel& rModel ); + +private: + typedef RefVector< SheetInfo > SheetInfoVector; + SheetInfoVector maSheetInfos; + + typedef RefMap< ::rtl::OUString, SheetInfo, IgnoreCaseCompare > SheetInfoMap; + SheetInfoMap maSheetInfosByName; +}; + +// ============================================================================ + +} // namespace xls +} // namespace oox + +#endif diff --git a/oox/inc/oox/xls/worksheetfragment.hxx b/oox/inc/oox/xls/worksheetfragment.hxx new file mode 100644 index 000000000000..4fe3bf4240dd --- /dev/null +++ b/oox/inc/oox/xls/worksheetfragment.hxx @@ -0,0 +1,193 @@ +/************************************************************************* + * + * 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_WORKSHEETFRAGMENT_HXX +#define OOX_XLS_WORKSHEETFRAGMENT_HXX + +#include "oox/xls/excelhandlers.hxx" + +namespace oox { +namespace xls { + +// ============================================================================ + +class DataValidationsContext : public WorksheetContextBase +{ +public: + explicit DataValidationsContext( WorksheetFragmentBase& rFragment ); + +protected: + virtual ::oox::core::ContextHandlerRef onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ); + virtual void onCharacters( const ::rtl::OUString& rChars ); + virtual void onEndElement(); + + virtual ::oox::core::ContextHandlerRef onCreateRecordContext( sal_Int32 nRecId, SequenceInputStream& rStrm ); + +private: + /** Imports the dataValidation element containing data validation settings. */ + void importDataValidation( const AttributeList& rAttribs ); + /** Imports the DATAVALIDATION record containing data validation settings. */ + void importDataValidation( SequenceInputStream& rStrm ); + +private: + ::std::auto_ptr< ValidationModel > mxValModel; +}; + +// ============================================================================ + +class WorksheetFragment : public WorksheetFragmentBase +{ +public: + explicit WorksheetFragment( + const WorkbookHelper& rHelper, + const ::rtl::OUString& rFragmentPath, + const ISegmentProgressBarRef& rxProgressBar, + WorksheetType eSheetType, + sal_Int16 nSheet ); + +protected: + virtual ::oox::core::ContextHandlerRef onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ); + virtual void onCharacters( const ::rtl::OUString& rChars ); + + virtual ::oox::core::ContextHandlerRef onCreateRecordContext( sal_Int32 nRecId, SequenceInputStream& rStrm ); + + virtual const ::oox::core::RecordInfo* getRecordInfos() const; + virtual void initializeImport(); + virtual void finalizeImport(); + +private: + /** Imports page settings from a pageSetUpPr element. */ + void importPageSetUpPr( const AttributeList& rAttribs ); + /** Imports the dimension element containing the used area of the sheet. */ + void importDimension( const AttributeList& rAttribs ); + /** Imports sheet format properties from a sheetFormatPr element. */ + void importSheetFormatPr( const AttributeList& rAttribs ); + /** Imports column settings from a col element. */ + void importCol( const AttributeList& rAttribs ); + /** Imports a merged cell range from a mergeCell element. */ + void importMergeCell( const AttributeList& rAttribs ); + /** Imports the hyperlink element containing a hyperlink for a cell range. */ + void importHyperlink( const AttributeList& rAttribs ); + /** Imports individual break that is either within row or column break context. */ + void importBrk( const AttributeList& rAttribs, bool bRowBreak ); + /** Imports the the relation identifier for the DrawingML part. */ + void importDrawing( const AttributeList& rAttribs ); + /** Imports the the relation identifier for the legacy VML drawing part. */ + void importLegacyDrawing( const AttributeList& rAttribs ); + /** Imports additional data for an OLE object. */ + void importOleObject( const AttributeList& rAttribs ); + /** Imports additional data for an OCX form control. */ + void importControl( const AttributeList& rAttribs ); + + /** Imports the DIMENSION record containing the used area of the sheet. */ + void importDimension( SequenceInputStream& rStrm ); + /** Imports sheet format properties from a SHEETFORMATPR record. */ + void importSheetFormatPr( SequenceInputStream& rStrm ); + /** Imports column settings from a COL record. */ + void importCol( SequenceInputStream& rStrm ); + /** Imports a merged cell range from a MERGECELL record. */ + void importMergeCell( SequenceInputStream& rStrm ); + /** Imports a hyperlink for a cell range from a HYPERLINK record. */ + void importHyperlink( SequenceInputStream& rStrm ); + /** Imports the BRK record for an individual row or column page break. */ + void importBrk( SequenceInputStream& rStrm, bool bRowBreak ); + /** Imports the DRAWING record containing the relation identifier for the DrawingML part. */ + void importDrawing( SequenceInputStream& rStrm ); + /** Imports the LEGACYDRAWING record containing the relation identifier for the VML drawing part. */ + void importLegacyDrawing( SequenceInputStream& rStrm ); + /** Imports additional data for an OLE object. */ + void importOleObject( SequenceInputStream& rStrm ); + /** Imports additional data for an OCX form control. */ + void importControl( SequenceInputStream& rStrm ); + + /** Imports the binary data of an embedded OLE object from the fragment with the passed ID. */ + void importEmbeddedOleData( StreamDataSequence& orEmbeddedData, const ::rtl::OUString& rRelId ); +}; + +// ============================================================================ + +class BiffWorksheetFragment : public BiffWorksheetFragmentBase +{ +public: + explicit BiffWorksheetFragment( + const BiffWorkbookFragmentBase& rParent, + const ISegmentProgressBarRef& rxProgressBar, + WorksheetType eSheetType, + sal_Int16 nSheet ); + virtual ~BiffWorksheetFragment(); + + /** Imports the entire worksheet fragment, returns true, if EOF record has been reached. */ + virtual bool importFragment(); + +private: + /** Imports the AUTOFILTER and following records with auto filter settings. */ + void importAutoFilter( BiffInputStream& rStrm ); + /** Imports the COLINFO record and sets column properties and formatting. */ + void importColInfo( BiffInputStream& rStrm ); + /** Imports the BIFF2 COLUMNDEFAULT record and sets column default formatting. */ + void importColumnDefault( BiffInputStream& rStrm ); + /** Imports the BIFF2 COLWIDTH record and sets column width. */ + void importColWidth( BiffInputStream& rStrm ); + /** Imports the DATAVALIDATION record containing cell ranges with data validation settings. */ + void importDataValidation( BiffInputStream& rStrm ); + /** Imports the DATAVALIDATIONS record containing global data validation settings. */ + void importDataValidations( BiffInputStream& rStrm ); + /** Imports the DEFCOLWIDTH record and sets default column width. */ + void importDefColWidth( BiffInputStream& rStrm ); + /** Imports the DEFROWHEIGHT record and sets default row height and properties. */ + void importDefRowHeight( BiffInputStream& rStrm ); + /** Imports the DIMENSION record containing the used area of the sheet. */ + void importDimension( BiffInputStream& rStrm ); + /** Imports the HYPERLINK record and sets a cell hyperlink. */ + void importHyperlink( BiffInputStream& rStrm ); + /** Imports the LABELRANGES record and sets the imported label ranges. */ + void importLabelRanges( BiffInputStream& rStrm ); + /** Imports the MEREDCELLS record and merges all cells in the document. */ + void importMergedCells( BiffInputStream& rStrm ); + /** Imports the HORPAGEBREAKS or VERPAGEBREAKS record and inserts page breaks. */ + void importPageBreaks( BiffInputStream& rStrm, bool bRowBreak ); + /** Imports a pivot table. */ + void importPTDefinition( BiffInputStream& rStrm ); + /** Imports the QUERYTABLE and following records and inserts a web query. */ + void importQueryTable( BiffInputStream& rStrm ); + /** Imports the SCENARIOS record and the following scenarios. */ + void importScenarios( BiffInputStream& rStrm ); + /** Imports the SHAREDFEATHEAD record. */ + void importSharedFeatHead( BiffInputStream& rStrm ); + /** Imports the STANDARDWIDTH record and sets standard column width. */ + void importStandardWidth( BiffInputStream& rStrm ); + +private: + ::boost::shared_ptr< BiffWorksheetContextBase > mxContext; +}; + +// ============================================================================ + +} // namespace xls +} // namespace oox + +#endif diff --git a/oox/inc/oox/xls/worksheethelper.hxx b/oox/inc/oox/xls/worksheethelper.hxx new file mode 100644 index 000000000000..55bf1c044e30 --- /dev/null +++ b/oox/inc/oox/xls/worksheethelper.hxx @@ -0,0 +1,475 @@ +/************************************************************************* + * + * 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_WORKSHEETHELPER_HXX +#define OOX_XLS_WORKSHEETHELPER_HXX + +#include "oox/helper/progressbar.hxx" +#include "oox/ole/olehelper.hxx" +#include "oox/xls/addressconverter.hxx" +#include "oox/xls/formulabase.hxx" + +namespace com { namespace sun { namespace star { + namespace awt { struct Point; } + namespace awt { struct Rectangle; } + namespace awt { struct Size; } + namespace drawing { class XDrawPage; } + namespace sheet { class XSheetCellRanges; } + namespace sheet { class XSpreadsheet; } + namespace table { class XCell; } + namespace table { class XCellRange; } + namespace table { class XTableColumns; } + namespace table { class XTableRows; } + namespace util { struct DateTime; } +} } } + +namespace oox { +namespace xls { + +class AutoFilterBuffer; +struct BinAddress; +struct BinRange; +class BinRangeList; +class CommentsBuffer; +class CondFormatBuffer; +class PageSettings; +class QueryTableBuffer; +class SharedFormulaBuffer; +class SheetViewSettings; +class VmlDrawing; +class WorksheetSettings; + +// ============================================================================ +// ============================================================================ + +/** An enumeration for all types of sheets in a workbook. */ +enum WorksheetType +{ + SHEETTYPE_WORKSHEET, /// Worksheet. + SHEETTYPE_CHARTSHEET, /// Chart sheet. + SHEETTYPE_MACROSHEET, /// Macro sheet. + SHEETTYPE_DIALOGSHEET, /// Dialog sheet (BIFF5+). + SHEETTYPE_MODULESHEET, /// VB module sheet (BIFF5 only). + SHEETTYPE_EMPTYSHEET /// Other (unsupported) sheet type. +}; + +// ============================================================================ + +/** 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. */ +struct ColumnModel +{ + sal_Int32 mnFirstCol; /// 1-based (!) index of first column. + sal_Int32 mnLastCol; /// 1-based (!) index of last column. + double mfWidth; /// Column width in number of characters. + sal_Int32 mnXfId; /// Column default formatting. + sal_Int32 mnLevel; /// Column outline level. + bool mbShowPhonetic; /// True = cells in column show phonetic settings. + bool mbHidden; /// True = column is hidden. + bool mbCollapsed; /// True = column outline is collapsed. + + explicit ColumnModel(); + + /** Expands this entry with the passed column range, if column settings are equal. */ + bool tryExpand( const ColumnModel& rModel ); +}; + +// ---------------------------------------------------------------------------- + +/** Stores formatting data about a range of rows. */ +struct RowModel +{ + sal_Int32 mnFirstRow; /// 1-based (!) index of first row. + sal_Int32 mnLastRow; /// 1-based (!) index of last row. + double mfHeight; /// Row height in points. + sal_Int32 mnXfId; /// Row default formatting (see mbIsFormatted). + sal_Int32 mnLevel; /// Row outline level. + bool mbCustomHeight; /// True = row has custom height. + bool mbCustomFormat; /// True = cells in row have explicit formatting. + bool mbShowPhonetic; /// True = cells in row show phonetic settings. + bool mbHidden; /// True = row is hidden. + bool mbCollapsed; /// True = row outline is collapsed. + bool mbThickTop; /// True = row has extra space above text. + bool mbThickBottom; /// True = row has extra space below text. + + explicit RowModel(); + + /** Expands this entry with the passed row range, if row settings are equal. */ + bool tryExpand( const RowModel& rModel ); +}; + +// ---------------------------------------------------------------------------- + +/** Stores formatting data about a page break. */ +struct PageBreakModel +{ + sal_Int32 mnColRow; /// 0-based (!) index of column/row. + sal_Int32 mnMin; /// Start of limited break. + sal_Int32 mnMax; /// End of limited break. + bool mbManual; /// True = manual page break. + + explicit PageBreakModel(); +}; + +// ---------------------------------------------------------------------------- + +/** Stores data about a hyperlink range. */ +struct HyperlinkModel : public ::oox::ole::StdHlinkInfo +{ + ::com::sun::star::table::CellRangeAddress + maRange; /// The cell area containing the hyperlink. + ::rtl::OUString maTooltip; /// Additional tooltip text. + + explicit HyperlinkModel(); +}; + +// ---------------------------------------------------------------------------- + +/** Stores data about ranges with data validation settings. */ +struct ValidationModel +{ + ApiCellRangeList maRanges; + ApiTokenSequence maTokens1; + ApiTokenSequence maTokens2; + ::rtl::OUString maInputTitle; + ::rtl::OUString maInputMessage; + ::rtl::OUString maErrorTitle; + ::rtl::OUString maErrorMessage; + sal_Int32 mnType; + sal_Int32 mnOperator; + sal_Int32 mnErrorStyle; + bool mbShowInputMsg; + bool mbShowErrorMsg; + bool mbNoDropDown; + bool mbAllowBlank; + + explicit ValidationModel(); + + /** Sets the passed BIFF validation type. */ + void setBiffType( sal_uInt8 nType ); + /** Sets the passed BIFF operator. */ + void setBiffOperator( sal_uInt8 nOperator ); + /** Sets the passed BIFF error style. */ + void setBiffErrorStyle( sal_uInt8 nErrorStyle ); +}; + +// ============================================================================ +// ============================================================================ + +class WorksheetData; + +class WorksheetHelper : public WorkbookHelper +{ +public: + /*implicit*/ WorksheetHelper( WorksheetData& rSheetData ); + + /** Returns the type of this sheet. */ + WorksheetType getSheetType() const; + /** Returns the index of the current sheet. */ + sal_Int16 getSheetIndex() const; + /** Returns the XSpreadsheet interface of the current sheet. */ + const ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XSpreadsheet >& + getSheet() const; + + /** 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; + + /** 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; + + /** 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 + getCellAddress( + const ::com::sun::star::uno::Reference< ::com::sun::star::table::XCell >& rxCell ); + /** Returns the address of the passed cell range. The range reference must be valid. */ + static ::com::sun::star::table::CellRangeAddress + getRangeAddress( + const ::com::sun::star::uno::Reference< ::com::sun::star::table::XCellRange >& rxRange ); + + /** Returns the XCellRange interface for a column. */ + ::com::sun::star::uno::Reference< ::com::sun::star::table::XCellRange > + getColumn( sal_Int32 nCol ) const; + /** Returns the XCellRange interface for a row. */ + ::com::sun::star::uno::Reference< ::com::sun::star::table::XCellRange > + getRow( sal_Int32 nRow ) const; + + /** 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; + /** 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; + + /** Returns the XDrawPage interface of the draw page of the current sheet. */ + ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XDrawPage > + getDrawPage() const; + + /** Returns the absolute cell position in 1/100 mm. */ + ::com::sun::star::awt::Point getCellPosition( sal_Int32 nCol, sal_Int32 nRow ) const; + /** Returns the cell size in 1/100 mm. */ + ::com::sun::star::awt::Size getCellSize( sal_Int32 nCol, sal_Int32 nRow ) const; + /** 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 conditional formattings in this sheet. */ + CondFormatBuffer& getCondFormats() const; + /** Returns the buffer for all cell comments in this sheet. */ + CommentsBuffer& getComments() const; + /** Returns the auto filters for the sheet. */ + AutoFilterBuffer& getAutoFilters() const; + /** Returns the buffer for all web query tables in this sheet. */ + QueryTableBuffer& getQueryTables() 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. */ + 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; + + /** 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 ); + /** 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. */ + void setVmlDrawingPath( const ::rtl::OUString& rVmlDrawingPath ); + + /** Extends the used area of this sheet by the passed cell position. */ + void extendUsedArea( const ::com::sun::star::table::CellAddress& rAddress ); + /** Extends the used area of this sheet by the passed cell range. */ + void extendUsedArea( const ::com::sun::star::table::CellRangeAddress& rRange ); + /** Extends the shape bounding box by the position and size of the passed rectangle (in 1/100 mm). */ + void extendShapeBoundingBox( const ::com::sun::star::awt::Rectangle& rShapeRect ); + + /** Sets base width for all columns (without padding pixels). This value + is only used, if width has not been set with setDefaultColumnWidth(). */ + void setBaseColumnWidth( sal_Int32 nWidth ); + /** Sets default width for all columns. This function overrides the base + width set with the setBaseColumnWidth() function. */ + void setDefaultColumnWidth( double fWidth ); + /** Converts default cell formatting for a range of columns. */ + void setDefaultColumnFormat( sal_Int32 nFirstCol, sal_Int32 nLastCol, sal_Int32 nXfId ); + /** Sets column settings for a specific range of columns. + @descr Column default formatting is converted directly, other settings + are cached and converted in the finalizeWorksheetImport() call. */ + void setColumnModel( const ColumnModel& rModel ); + + /** Sets default height and hidden state for all unused rows in the sheet. */ + void setDefaultRowSettings( + double fHeight, bool bCustomHeight, + bool bHidden, bool bThickTop, bool bThickBottom ); + /** Sets row settings for a specific range of rows. + @descr Row default formatting is converted directly, other settings + are cached and converted in the finalizeWorksheetImport() call. */ + void setRowModel( const RowModel& rModel ); + + /** Initial conversion before importing the worksheet. */ + void initializeWorksheetImport(); + /** Final conversion after importing the worksheet. */ + 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& ); +}; + +// ============================================================================ +// ============================================================================ + +} // namespace xls +} // namespace oox + +#endif diff --git a/oox/inc/oox/xls/worksheetsettings.hxx b/oox/inc/oox/xls/worksheetsettings.hxx new file mode 100644 index 000000000000..6d6c8a4912d2 --- /dev/null +++ b/oox/inc/oox/xls/worksheetsettings.hxx @@ -0,0 +1,144 @@ +/************************************************************************* + * + * 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_WORKSHEETSETTINGS_HXX +#define OOX_XLS_WORKSHEETSETTINGS_HXX + +#include "oox/xls/richstring.hxx" +#include "oox/xls/worksheethelper.hxx" + +namespace oox { +namespace xls { + +// ============================================================================ + +/** Sheet and outline settings. */ +struct SheetSettingsModel +{ + ::rtl::OUString maCodeName; /// VBA module codename. + Color maTabColor; /// Sheet tab color. + bool mbFilterMode; /// True = sheet contains active filter. + bool mbApplyStyles; /// True = automatic styles when creating outlines. + bool mbSummaryBelow; /// True = row outline symbols below group. + bool mbSummaryRight; /// True = column outline symbols right of group. + + explicit SheetSettingsModel(); +}; + +// ============================================================================ + +/** Sheet protection settings. */ +struct SheetProtectionModel +{ + sal_uInt16 mnPasswordHash; /// Hash value from sheet protection password. + bool mbSheet; /// True = sheet protection enabled, locked cells are protcted. + bool mbObjects; /// True = objects locked. + bool mbScenarios; /// True = scenarios locked. + bool mbFormatCells; /// True = format cells locked. + bool mbFormatColumns; /// True = format columns locked. + bool mbFormatRows; /// True = format rows locked. + bool mbInsertColumns; /// True = insert columns locked. + bool mbInsertRows; /// True = insert rows locked. + bool mbInsertHyperlinks; /// True = insert hyperlinks locked. + bool mbDeleteColumns; /// True = delete columns locked. + bool mbDeleteRows; /// True = delete rows locked. + bool mbSelectLocked; /// True = select locked cells locked. + bool mbSort; /// True = sorting locked. + bool mbAutoFilter; /// True = autofilters locked. + bool mbPivotTables; /// True = pivot tables locked. + bool mbSelectUnlocked; /// True = select unlocked cells locked. + + explicit SheetProtectionModel(); +}; + +// ============================================================================ + +class WorksheetSettings : public WorksheetHelper +{ +public: + explicit WorksheetSettings( const WorksheetHelper& rHelper ); + + /** Imports sheet settings from the sheetPr element. */ + void importSheetPr( const AttributeList& rAttribs ); + /** Imports chart sheet settings from the sheetPr element. */ + void importChartSheetPr( const AttributeList& rAttribs ); + /** Imports the sheet tab color from the tabColor element. */ + void importTabColor( const AttributeList& rAttribs ); + /** Imports outline settings from the outlinePr element. */ + void importOutlinePr( const AttributeList& rAttribs ); + /** Imports protection settings from the sheetProtection element. */ + void importSheetProtection( const AttributeList& rAttribs ); + /** Imports protection settings from the sheetProtection element of a chart sheet. */ + void importChartProtection( const AttributeList& rAttribs ); + /** Imports phonetic settings from the phoneticPr element. */ + void importPhoneticPr( const AttributeList& rAttribs ); + + /** Imports sheet properties from the SHEETPR record. */ + void importSheetPr( SequenceInputStream& rStrm ); + /** Imports sheet properties from the CHARTSHEETPR record. */ + void importChartSheetPr( SequenceInputStream& rStrm ); + /** Imports sheet protection settings from the SHEETPROTECTION record. */ + void importSheetProtection( SequenceInputStream& rStrm ); + /** Imports chart sheet protection settings from the CHARTPROTECTION record. */ + void importChartProtection( SequenceInputStream& rStrm ); + /** Imports phonetic settings from the PHONETICPR record. */ + void importPhoneticPr( SequenceInputStream& rStrm ); + + /** Imports sheet properties from a SHEETEXT record. */ + void importSheetExt( BiffInputStream& rStrm ); + /** Imports sheet properties from a SHEETPR record. */ + void importSheetPr( BiffInputStream& rStrm ); + /** Imports protection status from the PROTECT record. */ + void importProtect( BiffInputStream& rStrm ); + /** Imports object protection status from the OBJECTPROTECT record. */ + void importObjectProtect( BiffInputStream& rStrm ); + /** Imports scenario protection status from the SCENPROTECT record. */ + void importScenProtect( BiffInputStream& rStrm ); + /** Imports sheet password hash from the PASSWORD record. */ + void importPassword( BiffInputStream& rStrm ); + /** Imports protection settings from the SHEETPROTECTION record. */ + void importSheetProtection( BiffInputStream& rStrm ); + /** Imports the VBA code module name from the CODENAME record. */ + void importCodeName( BiffInputStream& rStrm ); + /** Imports phonetic settings from the PHONETICPR record. */ + void importPhoneticPr( BiffInputStream& rStrm ); + + /** Converts the imported worksheet settings. */ + void finalizeImport(); + +private: + PhoneticSettings maPhoneticSett; + SheetSettingsModel maSheetSettings; + SheetProtectionModel maSheetProt; +}; + +// ============================================================================ + +} // namespace xls +} // namespace oox + +#endif |