LCOV - code coverage report
Current view: top level - libreoffice/sc/source/filter/inc - worksheethelper.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 2 4 50.0 %
Date: 2012-12-27 Functions: 6 11 54.5 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #ifndef OOX_XLS_WORKSHEETHELPER_HXX
      21             : #define OOX_XLS_WORKSHEETHELPER_HXX
      22             : 
      23             : #include "oox/helper/containerhelper.hxx"
      24             : #include "oox/helper/progressbar.hxx"
      25             : #include "oox/ole/olehelper.hxx"
      26             : #include "addressconverter.hxx"
      27             : #include "formulabase.hxx"
      28             : 
      29             : namespace com { namespace sun { namespace star {
      30             :     namespace awt { struct Point; }
      31             :     namespace awt { struct Rectangle; }
      32             :     namespace awt { struct Size; }
      33             :     namespace drawing { class XDrawPage; }
      34             :     namespace sheet { class XSheetCellRanges; }
      35             :     namespace sheet { class XSpreadsheet; }
      36             :     namespace table { class XCell; }
      37             :     namespace table { class XCell2; }
      38             :     namespace table { class XCellRange; }
      39             :     namespace table { class XTableColumns; }
      40             :     namespace table { class XTableRows; }
      41             : } } }
      42             : 
      43             : namespace oox {
      44             : namespace xls {
      45             : 
      46             : class AutoFilterBuffer;
      47             : struct BinAddress;
      48             : struct BinRange;
      49             : class CommentsBuffer;
      50             : class CondFormatBuffer;
      51             : class Font;
      52             : class PageSettings;
      53             : class QueryTableBuffer;
      54             : class RichString;
      55             : class SheetDataBuffer;
      56             : class SheetViewSettings;
      57             : class VmlDrawing;
      58             : class WorksheetSettings;
      59             : 
      60             : typedef ::std::map< rtl::OUString, void* >  ExtLst;
      61             : // ============================================================================
      62             : // ============================================================================
      63             : 
      64             : typedef ::std::map< BinAddress, sal_Int32 > SharedFormulaMap;
      65             : 
      66             : /** An enumeration for all types of sheets in a workbook. */
      67             : enum WorksheetType
      68             : {
      69             :     SHEETTYPE_WORKSHEET,            /// Worksheet.
      70             :     SHEETTYPE_CHARTSHEET,           /// Chart sheet.
      71             :     SHEETTYPE_MACROSHEET,           /// Macro sheet.
      72             :     SHEETTYPE_DIALOGSHEET,          /// Dialog sheet (BIFF5+).
      73             :     SHEETTYPE_MODULESHEET,          /// VB module sheet (BIFF5 only).
      74             :     SHEETTYPE_EMPTYSHEET            /// Other (unsupported) sheet type.
      75             : };
      76             : 
      77             : // ============================================================================
      78             : 
      79             : /** Stores settings and formatting data about a range of sheet columns. */
      80             : struct ColumnModel
      81             : {
      82             :     ValueRange          maRange;            /// 1-based (!) range of the described columns.
      83             :     double              mfWidth;            /// Column width in number of characters.
      84             :     sal_Int32           mnXfId;             /// Column default formatting.
      85             :     sal_Int32           mnLevel;            /// Column outline level.
      86             :     bool                mbShowPhonetic;     /// True = cells in column show phonetic settings.
      87             :     bool                mbHidden;           /// True = column is hidden.
      88             :     bool                mbCollapsed;        /// True = column outline is collapsed.
      89             : 
      90             :     explicit            ColumnModel();
      91             : 
      92             :     /** Returns true, if this entry can be merged with the passed column range (column settings are equal). */
      93             :     bool                isMergeable( const ColumnModel& rModel ) const;
      94             : };
      95             : 
      96             : // ----------------------------------------------------------------------------
      97             : 
      98             : /** Stores settings and formatting data about a sheet row. */
      99         554 : struct RowModel
     100             : {
     101             :     sal_Int32           mnRow;              /// 1-based (!) index of the described row.
     102             :     ValueRangeSet       maColSpans;         /// 0-based (!) column ranges of used cells.
     103             :     double              mfHeight;           /// Row height in points.
     104             :     sal_Int32           mnXfId;             /// Row default formatting (see mbIsFormatted).
     105             :     sal_Int32           mnLevel;            /// Row outline level.
     106             :     bool                mbCustomHeight;     /// True = row has custom height.
     107             :     bool                mbCustomFormat;     /// True = cells in row have explicit formatting.
     108             :     bool                mbShowPhonetic;     /// True = cells in row show phonetic settings.
     109             :     bool                mbHidden;           /// True = row is hidden.
     110             :     bool                mbCollapsed;        /// True = row outline is collapsed.
     111             :     bool                mbThickTop;         /// True = row has extra space above text.
     112             :     bool                mbThickBottom;      /// True = row has extra space below text.
     113             : 
     114             :     explicit            RowModel();
     115             : 
     116             :     /** Inserts the passed column span into the row model. */
     117             :     void                insertColSpan( const ValueRange& rColSpan );
     118             :     /** Returns true, if this entry can be merged with the passed row range (row settings are equal). */
     119             :     bool                isMergeable( const RowModel& rModel ) const;
     120             : };
     121             : 
     122             : // ----------------------------------------------------------------------------
     123             : 
     124             : /** Stores formatting data about a page break. */
     125             : struct PageBreakModel
     126             : {
     127             :     sal_Int32           mnColRow;           /// 0-based (!) index of column/row.
     128             :     sal_Int32           mnMin;              /// Start of limited break.
     129             :     sal_Int32           mnMax;              /// End of limited break.
     130             :     bool                mbManual;           /// True = manual page break.
     131             : 
     132             :     explicit            PageBreakModel();
     133             : };
     134             : 
     135             : // ----------------------------------------------------------------------------
     136             : 
     137             : /** Stores data about a hyperlink range. */
     138           0 : struct HyperlinkModel : public ::oox::ole::StdHlinkInfo
     139             : {
     140             :     ::com::sun::star::table::CellRangeAddress
     141             :                         maRange;            /// The cell area containing the hyperlink.
     142             :     ::rtl::OUString     maTooltip;          /// Additional tooltip text.
     143             : 
     144             :     explicit            HyperlinkModel();
     145             : };
     146             : 
     147             : // ----------------------------------------------------------------------------
     148             : 
     149             : /** Stores data about ranges with data validation settings. */
     150           0 : struct ValidationModel
     151             : {
     152             :     ApiCellRangeList    maRanges;
     153             :     ApiTokenSequence    maTokens1;
     154             :     ApiTokenSequence    maTokens2;
     155             :     ::rtl::OUString     maInputTitle;
     156             :     ::rtl::OUString     maInputMessage;
     157             :     ::rtl::OUString     maErrorTitle;
     158             :     ::rtl::OUString     maErrorMessage;
     159             :     sal_Int32           mnType;
     160             :     sal_Int32           mnOperator;
     161             :     sal_Int32           mnErrorStyle;
     162             :     bool                mbShowInputMsg;
     163             :     bool                mbShowErrorMsg;
     164             :     bool                mbNoDropDown;
     165             :     bool                mbAllowBlank;
     166             : 
     167             :     explicit            ValidationModel();
     168             : 
     169             :     /** Sets the passed BIFF validation type. */
     170             :     void                setBiffType( sal_uInt8 nType );
     171             :     /** Sets the passed BIFF operator. */
     172             :     void                setBiffOperator( sal_uInt8 nOperator );
     173             :     /** Sets the passed BIFF error style. */
     174             :     void                setBiffErrorStyle( sal_uInt8 nErrorStyle );
     175             : };
     176             : 
     177             : // ============================================================================
     178             : // ============================================================================
     179             : 
     180             : class WorksheetGlobals;
     181             : typedef ::boost::shared_ptr< WorksheetGlobals > WorksheetGlobalsRef;
     182             : 
     183         985 : class WorksheetHelper : public WorkbookHelper
     184             : {
     185             : public:
     186             :     /*implicit*/        WorksheetHelper( WorksheetGlobals& rSheetGlob );
     187             : 
     188             :     static WorksheetGlobalsRef constructGlobals(
     189             :                             const WorkbookHelper& rHelper,
     190             :                             const ISegmentProgressBarRef& rxProgressBar,
     191             :                             WorksheetType eSheetType,
     192             :                             sal_Int16 nSheet );
     193             : 
     194             :     // ------------------------------------------------------------------------
     195             : 
     196             :     /** Returns the type of this sheet. */
     197             :     WorksheetType       getSheetType() const;
     198             :     /** Returns the index of the current sheet. */
     199             :     sal_Int16           getSheetIndex() const;
     200             :     /** Returns the XSpreadsheet interface of the current sheet. */
     201             :     const ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XSpreadsheet >&
     202             :                         getSheet() const;
     203             : 
     204             :     /** Returns the XCell interface for the passed cell address. */
     205             :     ::com::sun::star::uno::Reference< ::com::sun::star::table::XCell >
     206             :                         getCell( const ::com::sun::star::table::CellAddress& rAddress ) const;
     207             :     /** Returns the XCellRange interface for the passed cell range address. */
     208             :     ::com::sun::star::uno::Reference< ::com::sun::star::table::XCellRange >
     209             :                         getCellRange( const ::com::sun::star::table::CellRangeAddress& rRange ) const;
     210             : 
     211             :     /** Returns the XDrawPage interface of the draw page of the current sheet. */
     212             :     ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XDrawPage >
     213             :                         getDrawPage() const;
     214             : 
     215             :     /** Returns the absolute cell position in 1/100 mm. */
     216             :     ::com::sun::star::awt::Point getCellPosition( sal_Int32 nCol, sal_Int32 nRow ) const;
     217             :     /** Returns the cell size in 1/100 mm. */
     218             :     ::com::sun::star::awt::Size getCellSize( sal_Int32 nCol, sal_Int32 nRow ) const;
     219             :     /** Returns the size of the entire drawing page in 1/100 mm. */
     220             :     ::com::sun::star::awt::Size getDrawPageSize() const;
     221             : 
     222             :     /** Returns the buffer for cell contents and cell formatting. */
     223             :     SheetDataBuffer&    getSheetData() const;
     224             :     /** Returns the conditional formatting in this sheet. */
     225             :     CondFormatBuffer&   getCondFormats() const;
     226             :     /** Returns the buffer for all cell comments in this sheet. */
     227             :     CommentsBuffer&     getComments() const;
     228             :     /** Returns the auto filters for the sheet. */
     229             :     AutoFilterBuffer&   getAutoFilters() const;
     230             :     /** Returns the buffer for all web query tables in this sheet. */
     231             :     QueryTableBuffer&   getQueryTables() const;
     232             :     /** Returns the worksheet settings object. */
     233             :     WorksheetSettings&  getWorksheetSettings() const;
     234             :     /** Returns the page/print settings for this sheet. */
     235             :     PageSettings&       getPageSettings() const;
     236             :     /** Returns the view settings for this sheet. */
     237             :     SheetViewSettings&  getSheetViewSettings() const;
     238             :     /** Returns the VML drawing page for this sheet (OOXML/BIFF12 only). */
     239             :     VmlDrawing&         getVmlDrawing() const;
     240             : 
     241             :     ExtLst&             getExtLst() const;
     242             : 
     243             :     /** Sets a column or row page break described in the passed struct. */
     244             :     void                setPageBreak( const PageBreakModel& rModel, bool bRowBreak );
     245             :     /** Inserts the hyperlink URL into the spreadsheet. */
     246             :     void                setHyperlink( const HyperlinkModel& rModel );
     247             :     /** Inserts the data validation settings into the spreadsheet. */
     248             :     void                setValidation( const ValidationModel& rModel );
     249             :     /** Sets the path to the DrawingML fragment of this sheet. */
     250             :     void                setDrawingPath( const ::rtl::OUString& rDrawingPath );
     251             :     /** Sets the path to the legacy VML drawing fragment of this sheet. */
     252             :     void                setVmlDrawingPath( const ::rtl::OUString& rVmlDrawingPath );
     253             : 
     254             :     /** Extends the used area of this sheet by the passed cell position. */
     255             :     void                extendUsedArea( const ::com::sun::star::table::CellAddress& rAddress );
     256             :     /** Extends the used area of this sheet by the passed cell range. */
     257             :     void                extendUsedArea( const ::com::sun::star::table::CellRangeAddress& rRange );
     258             :     /** Extends the shape bounding box by the position and size of the passed rectangle (in 1/100 mm). */
     259             :     void                extendShapeBoundingBox( const ::com::sun::star::awt::Rectangle& rShapeRect );
     260             : 
     261             :     /** Sets base width for all columns (without padding pixels). This value
     262             :         is only used, if width has not been set with setDefaultColumnWidth(). */
     263             :     void                setBaseColumnWidth( sal_Int32 nWidth );
     264             :     /** Sets default width for all columns. This function overrides the base
     265             :         width set with the setBaseColumnWidth() function. */
     266             :     void                setDefaultColumnWidth( double fWidth );
     267             :     /** Sets column settings for a specific range of columns.
     268             :         @descr  Column default formatting is converted directly, other settings
     269             :         are cached and converted in the finalizeWorksheetImport() call. */
     270             :     void                setColumnModel( const ColumnModel& rModel );
     271             : 
     272             :     /** Sets default height and hidden state for all unused rows in the sheet. */
     273             :     void                setDefaultRowSettings(
     274             :                             double fHeight, bool bCustomHeight,
     275             :                             bool bHidden, bool bThickTop, bool bThickBottom );
     276             :     /** Sets row settings for a specific range of rows.
     277             :         @descr  Row default formatting is converted directly, other settings
     278             :         are cached and converted in the finalizeWorksheetImport() call. */
     279             :     void                setRowModel( const RowModel& rModel );
     280             :     /** Specifies that the passed row needs to set its height manually. */
     281             :     void                setManualRowHeight( sal_Int32 nRow );
     282             : 
     283             :     /** Inserts a value cell directly into the Calc sheet. */
     284             :     void                putValue(
     285             :                             const ::com::sun::star::table::CellAddress& rAddress,
     286             :                             double fValue ) const;
     287             : 
     288             :     /** Inserts a string cell directly into the Calc sheet. */
     289             :     void                putString(
     290             :                             const ::com::sun::star::table::CellAddress& rAddress,
     291             :                             const ::rtl::OUString& rText ) const;
     292             :     /** Inserts a rich-string cell directly into the Calc sheet. */
     293             :     void                putRichString(
     294             :                             const ::com::sun::star::table::CellAddress& rAddress,
     295             :                             const RichString& rString,
     296             :                             const Font* pFirstPortionFont ) const;
     297             :     /** Inserts a formula cell directly into the Calc sheet. */
     298             :     void                putFormulaTokens(
     299             :                             const ::com::sun::star::table::CellAddress& rAddress,
     300             :                             const ApiTokenSequence& rTokens ) const;
     301             : 
     302             :     /** Initial conversion before importing the worksheet. */
     303             :     void                initializeWorksheetImport();
     304             :     /** Final conversion after importing the worksheet. */
     305             :     void                finalizeWorksheetImport();
     306             : 
     307             :     void                setCellFormula( const ::com::sun::star::table::CellAddress& rTokenAddress, const rtl::OUString&  );
     308             :     void                setCellFormula( const ::com::sun::star::table::CellAddress& rTokenAddress, sal_Int32  );
     309             :     void                setCellArrayFormula( const ::com::sun::star::table::CellRangeAddress& rRangeAddress, const ::com::sun::star::table::CellAddress& rTokenAddress, const rtl::OUString&  );
     310             :     void                createSharedFormulaMapEntry( const ::com::sun::star::table::CellAddress& rAddress, sal_Int32 nSharedId, const rtl::OUString& rTokens );
     311             :     void                setCellFormulaValue( const ::com::sun::star::table::CellAddress& rAddress,
     312             :                             double fValue  );
     313             : private:
     314             :     WorksheetGlobals&   mrSheetGlob;
     315             : };
     316             : 
     317             : // ============================================================================
     318             : // ============================================================================
     319             : 
     320             : } // namespace xls
     321             : } // namespace oox
     322             : 
     323             : #endif
     324             : 
     325             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10