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