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_SHEETDATACONTEXT_HXX
21 : #define OOX_XLS_SHEETDATACONTEXT_HXX
22 :
23 : #include "excelhandlers.hxx"
24 : #include "richstring.hxx"
25 : #include "sheetdatabuffer.hxx"
26 :
27 : namespace oox {
28 : namespace xls {
29 :
30 : // ============================================================================
31 :
32 : /** Used as base for sheet data context classes. Provides fast access to often
33 : used converter objects and sheet index, to improve performance.
34 : */
35 : struct SheetDataContextBase
36 : {
37 : AddressConverter& mrAddressConv; /// The address converter.
38 : FormulaParser& mrFormulaParser; /// The formula parser.
39 : SheetDataBuffer& mrSheetData; /// The sheet data buffer for cell content and formatting.
40 : CellModel maCellData; /// Position, contents, formatting of current imported cell.
41 : CellFormulaModel maFmlaData; /// Settings for a cell formula.
42 : sal_Int16 mnSheet; /// Index of the current sheet.
43 :
44 : explicit SheetDataContextBase( const WorksheetHelper& rHelper );
45 : virtual ~SheetDataContextBase();
46 : };
47 :
48 : // ============================================================================
49 :
50 : /** This class implements importing the sheetData element.
51 :
52 : The sheetData element contains all row settings and all cells in a single
53 : sheet of a spreadsheet document.
54 : */
55 50 : class SheetDataContext : public WorksheetContextBase, private SheetDataContextBase
56 : {
57 : public:
58 : explicit SheetDataContext( WorksheetFragmentBase& rFragment );
59 :
60 : protected:
61 : virtual ::oox::core::ContextHandlerRef onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs );
62 : virtual void onCharacters( const ::rtl::OUString& rChars );
63 : virtual void onEndElement();
64 :
65 : virtual ::oox::core::ContextHandlerRef onCreateRecordContext( sal_Int32 nRecId, SequenceInputStream& rStrm );
66 :
67 : private:
68 : /** Different types of cell records. */
69 : enum CellType { CELLTYPE_VALUE, CELLTYPE_MULTI, CELLTYPE_FORMULA };
70 :
71 : /** Imports row settings from a row element. */
72 : void importRow( const AttributeList& rAttribs );
73 : /** Imports cell settings from a c element. */
74 : bool importCell( const AttributeList& rAttribs );
75 : /** Imports cell settings from an f element. */
76 : void importFormula( const AttributeList& rAttribs );
77 :
78 : /** Imports row settings from a ROW record. */
79 : void importRow( SequenceInputStream& rStrm );
80 :
81 : /** Reads a cell address and the following XF identifier. */
82 : bool readCellHeader( SequenceInputStream& rStrm, CellType eCellType );
83 : /** Reads a cell formula for the current cell. */
84 : ApiTokenSequence readCellFormula( SequenceInputStream& rStrm );
85 : /** Reads the formula range used by shared formulas, arrays, and data tables. */
86 : bool readFormulaRef( SequenceInputStream& rStrm );
87 :
88 : /** Imports an empty cell from a CELL_BLANK or MULTCELL_BLANK record. */
89 : void importCellBlank( SequenceInputStream& rStrm, CellType eCellType );
90 : /** Imports a boolean cell from a CELL_BOOL, MULTCELL_BOOL, or FORMULA_BOOL record. */
91 : void importCellBool( SequenceInputStream& rStrm, CellType eCellType );
92 : /** Imports a numeric cell from a CELL_DOUBLE, MULTCELL_DOUBLE, or FORMULA_DOUBLE record. */
93 : void importCellDouble( SequenceInputStream& rStrm, CellType eCellType );
94 : /** Imports an error code cell from a CELL_ERROR, MULTCELL_ERROR, or FORMULA_ERROR record. */
95 : void importCellError( SequenceInputStream& rStrm, CellType eCellType );
96 : /** Imports an encoded numeric cell from a CELL_RK or MULTCELL_RK record. */
97 : void importCellRk( SequenceInputStream& rStrm, CellType eCellType );
98 : /** Imports a rich-string cell from a CELL_RSTRING or MULTCELL_RSTRING record. */
99 : void importCellRString( SequenceInputStream& rStrm, CellType eCellType );
100 : /** Imports a string cell from a CELL_SI or MULTCELL_SI record. */
101 : void importCellSi( SequenceInputStream& rStrm, CellType eCellType );
102 : /** Imports a string cell from a CELL_STRING, MULTCELL_STRING, or FORMULA_STRING record. */
103 : void importCellString( SequenceInputStream& rStrm, CellType eCellType );
104 :
105 : /** Imports an array formula from an ARRAY record. */
106 : void importArray( SequenceInputStream& rStrm );
107 : /** Imports table operation from a DATATABLE record. */
108 : void importDataTable( SequenceInputStream& rStrm );
109 : /** Imports a shared formula from a SHAREDFORMULA record. */
110 : void importSharedFmla( SequenceInputStream& rStrm );
111 :
112 : private:
113 : ::rtl::OUString maCellValue; /// Cell value string (OOXML only).
114 : RichStringRef mxInlineStr; /// Inline rich string (OOXML only).
115 : ::rtl::OUString maFormulaStr;
116 : DataTableModel maTableData; /// Settings for table operations.
117 : BinAddress maCurrPos; /// Current cell position (BIFF12 only).
118 : bool mbHasFormula; /// True = current cell has formula data (OOXML only).
119 : bool mbValidRange; /// True = maFmlaData.maFormulaRef is valid (OOXML only).
120 : };
121 :
122 : // ============================================================================
123 :
124 :
125 : } // namespace xls
126 : } // namespace oox
127 :
128 : #endif
129 :
130 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|