xref: /trunk/main/oox/inc/oox/xls/tablebuffer.hxx (revision e3508121)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef OOX_XLS_TABLEBUFFER_HXX
25 #define OOX_XLS_TABLEBUFFER_HXX
26 
27 #include <com/sun/star/table/CellRangeAddress.hpp>
28 #include "oox/xls/autofilterbuffer.hxx"
29 #include "oox/xls/workbookhelper.hxx"
30 
31 namespace oox {
32 namespace xls {
33 
34 // ============================================================================
35 
36 struct TableModel
37 {
38     ::com::sun::star::table::CellRangeAddress
39                         maRange;            /// Original (unchecked) range of the table.
40     ::rtl::OUString     maProgName;         /// Programmatical name.
41     ::rtl::OUString     maDisplayName;      /// Display name.
42     sal_Int32           mnId;               /// Unique table identifier.
43     sal_Int32           mnType;             /// Table type (worksheet, query, etc.).
44     sal_Int32           mnHeaderRows;       /// Number of header rows.
45     sal_Int32           mnTotalsRows;       /// Number of totals rows.
46 
47     explicit            TableModel();
48 };
49 
50 // ----------------------------------------------------------------------------
51 
52 class Table : public WorkbookHelper
53 {
54 public:
55     explicit            Table( const WorkbookHelper& rHelper );
56 
57     /** Imports a table definition from the passed attributes. */
58     void                importTable( const AttributeList& rAttribs, sal_Int16 nSheet );
59     /** Imports a table definition from a TABLE record. */
60     void                importTable( SequenceInputStream& rStrm, sal_Int16 nSheet );
61     /** Creates a new auto filter and stores it internally. */
createAutoFilter()62     inline AutoFilter&  createAutoFilter() { return maAutoFilters.createAutoFilter(); }
63 
64     /** Creates a database range from this tables. */
65     void                finalizeImport();
66 
67     /** Returns the unique table identifier. */
getTableId() const68     inline sal_Int32    getTableId() const { return maModel.mnId; }
69     /** Returns the token index used in API token arrays (com.sun.star.sheet.FormulaToken). */
getTokenIndex() const70     inline sal_Int32    getTokenIndex() const { return mnTokenIndex; }
71     /** Returns the original display name of the table. */
getDisplayName() const72     inline const ::rtl::OUString& getDisplayName() const { return maModel.maDisplayName; }
73 
74     /** Returns the original (unchecked) total range of the table. */
getOriginalRange() const75     inline const ::com::sun::star::table::CellRangeAddress& getOriginalRange() const { return maModel.maRange; }
76     /** Returns the cell range of this table. */
getRange() const77     inline const ::com::sun::star::table::CellRangeAddress& getRange() const { return maDestRange; }
78     /** Returns the number of columns of this table. */
getWidth() const79     inline sal_Int32    getWidth() const { return maDestRange.EndColumn - maDestRange.StartColumn + 1; }
80     /** Returns the number of rows of this table. */
getHeight() const81     inline sal_Int32    getHeight() const { return maDestRange.EndRow - maDestRange.StartRow + 1; }
82     /** Returns the number of header rows in the table range. */
getHeaderRows() const83     inline sal_Int32    getHeaderRows() const { return maModel.mnHeaderRows; }
84     /** Returns the number of totals rows in the table range. */
getTotalsRows() const85     inline sal_Int32    getTotalsRows() const { return maModel.mnTotalsRows; }
86 
87 private:
88     TableModel          maModel;
89     AutoFilterBuffer    maAutoFilters;      /// Filter settings for this table.
90     ::rtl::OUString     maDBRangeName;      /// Name of the databae range in the Calc document.
91     ::com::sun::star::table::CellRangeAddress
92                         maDestRange;        /// Validated range of the table in the worksheet.
93     sal_Int32           mnTokenIndex;       /// Token index used in API token array.
94 };
95 
96 typedef ::boost::shared_ptr< Table > TableRef;
97 
98 // ============================================================================
99 
100 class TableBuffer : public WorkbookHelper
101 {
102 public:
103     explicit            TableBuffer( const WorkbookHelper& rHelper );
104 
105     /** Creates a new empty table. */
106     Table&              createTable();
107 
108     /** Creates database ranges from all imported tables. */
109     void                finalizeImport();
110 
111     /** Returns a table by its identifier. */
112     TableRef            getTable( sal_Int32 nTableId ) const;
113     /** Returns a table by its display name. */
114     TableRef            getTable( const ::rtl::OUString& rDispName ) const;
115 
116 private:
117     /** Inserts the passed table into the maps according to its identifier and name. */
118     void                insertTableToMaps( const TableRef& rxTable );
119 
120 private:
121     typedef RefVector< Table >                  TableVector;
122     typedef RefMap< sal_Int32, Table >          TableIdMap;
123     typedef RefMap< ::rtl::OUString, Table >    TableNameMap;
124 
125     TableVector         maTables;
126     TableIdMap          maIdTables;
127     TableNameMap        maNameTables;
128 };
129 
130 // ============================================================================
131 
132 } // namespace xls
133 } // namespace oox
134 
135 #endif
136