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_TABLEBUFFER_HXX
21 : #define OOX_XLS_TABLEBUFFER_HXX
22 :
23 : #include <com/sun/star/table/CellRangeAddress.hpp>
24 : #include "autofilterbuffer.hxx"
25 : #include "workbookhelper.hxx"
26 :
27 : namespace oox {
28 : namespace xls {
29 :
30 0 : struct TableModel
31 : {
32 : ::com::sun::star::table::CellRangeAddress
33 : maRange; /// Original (unchecked) range of the table.
34 : OUString maProgName; /// Programmatical name.
35 : OUString maDisplayName; /// Display name.
36 : sal_Int32 mnId; /// Unique table identifier.
37 : sal_Int32 mnType; /// Table type (worksheet, query, etc.).
38 : sal_Int32 mnHeaderRows; /// Number of header rows.
39 : sal_Int32 mnTotalsRows; /// Number of totals rows.
40 :
41 : explicit TableModel();
42 : };
43 :
44 0 : class Table : public WorkbookHelper
45 : {
46 : public:
47 : explicit Table( const WorkbookHelper& rHelper );
48 :
49 : /** Imports a table definition from the passed attributes. */
50 : void importTable( const AttributeList& rAttribs, sal_Int16 nSheet );
51 : /** Imports a table definition from a TABLE record. */
52 : void importTable( SequenceInputStream& rStrm, sal_Int16 nSheet );
53 : /** Creates a new auto filter and stores it internally. */
54 0 : inline AutoFilter& createAutoFilter() { return maAutoFilters.createAutoFilter(); }
55 :
56 : /** Creates a database range from this tables. */
57 : void finalizeImport();
58 : void applyAutoFilters();
59 :
60 : /** Returns the unique table identifier. */
61 0 : inline sal_Int32 getTableId() const { return maModel.mnId; }
62 : /** Returns the token index used in API token arrays (com.sun.star.sheet.FormulaToken). */
63 0 : inline sal_Int32 getTokenIndex() const { return mnTokenIndex; }
64 : /** Returns the original display name of the table. */
65 0 : inline const OUString& getDisplayName() const { return maModel.maDisplayName; }
66 :
67 : /** Returns the original (unchecked) total range of the table. */
68 0 : inline const ::com::sun::star::table::CellRangeAddress& getOriginalRange() const { return maModel.maRange; }
69 : /** Returns the cell range of this table. */
70 0 : inline const ::com::sun::star::table::CellRangeAddress& getRange() const { return maDestRange; }
71 : /** Returns the number of columns of this table. */
72 0 : inline sal_Int32 getWidth() const { return maDestRange.EndColumn - maDestRange.StartColumn + 1; }
73 : /** Returns the number of rows of this table. */
74 0 : inline sal_Int32 getHeight() const { return maDestRange.EndRow - maDestRange.StartRow + 1; }
75 : /** Returns the number of header rows in the table range. */
76 0 : inline sal_Int32 getHeaderRows() const { return maModel.mnHeaderRows; }
77 : /** Returns the number of totals rows in the table range. */
78 0 : inline sal_Int32 getTotalsRows() const { return maModel.mnTotalsRows; }
79 :
80 : private:
81 : TableModel maModel;
82 : AutoFilterBuffer maAutoFilters; /// Filter settings for this table.
83 : OUString maDBRangeName; /// Name of the databae range in the Calc document.
84 : ::com::sun::star::table::CellRangeAddress
85 : maDestRange; /// Validated range of the table in the worksheet.
86 : sal_Int32 mnTokenIndex; /// Token index used in API token array.
87 : };
88 :
89 : typedef ::boost::shared_ptr< Table > TableRef;
90 :
91 0 : class TableBuffer : public WorkbookHelper
92 : {
93 : public:
94 : explicit TableBuffer( const WorkbookHelper& rHelper );
95 :
96 : /** Creates a new empty table. */
97 : Table& createTable();
98 :
99 : /** Creates database ranges from all imported tables. */
100 : void finalizeImport();
101 : /** Applies autofilters from created database range ( requires finalizeImport to have run before being called */
102 : void applyAutoFilters();
103 : /** Returns a table by its identifier. */
104 : TableRef getTable( sal_Int32 nTableId ) const;
105 : /** Returns a table by its display name. */
106 : TableRef getTable( const OUString& rDispName ) const;
107 :
108 : private:
109 : /** Inserts the passed table into the maps according to its identifier and name. */
110 : void insertTableToMaps( const TableRef& rxTable );
111 :
112 : private:
113 : typedef RefVector< Table > TableVector;
114 : typedef RefMap< sal_Int32, Table > TableIdMap;
115 : typedef RefMap< OUString, Table > TableNameMap;
116 :
117 : TableVector maTables;
118 : TableIdMap maIdTables;
119 : TableNameMap maNameTables;
120 : };
121 :
122 : } // namespace xls
123 : } // namespace oox
124 :
125 : #endif
126 :
127 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|