xref: /aoo41x/main/oox/inc/oox/xls/worksheetbuffer.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_WORKSHEETBUFFER_HXX
25cdf0e10cSrcweir #define OOX_XLS_WORKSHEETBUFFER_HXX
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <utility>
28cdf0e10cSrcweir #include "oox/helper/refmap.hxx"
29cdf0e10cSrcweir #include "oox/helper/refvector.hxx"
30cdf0e10cSrcweir #include "oox/xls/workbookhelper.hxx"
31cdf0e10cSrcweir 
32cdf0e10cSrcweir namespace com { namespace sun { namespace star {
33cdf0e10cSrcweir     namespace i18n { class XCharacterClassification; }
34cdf0e10cSrcweir } } }
35cdf0e10cSrcweir 
36cdf0e10cSrcweir namespace oox {
37cdf0e10cSrcweir namespace xls {
38cdf0e10cSrcweir 
39cdf0e10cSrcweir // ============================================================================
40cdf0e10cSrcweir 
41cdf0e10cSrcweir /** Contains data from the 'sheet' element describing a sheet in the workbook. */
42cdf0e10cSrcweir struct SheetInfoModel
43cdf0e10cSrcweir {
44cdf0e10cSrcweir     ::rtl::OUString     maRelId;        /// Relation identifier for the sheet substream.
45cdf0e10cSrcweir     ::rtl::OUString     maName;         /// Original name of the sheet.
46cdf0e10cSrcweir     sal_Int64           mnBiffHandle;   /// BIFF record handle of the sheet substream.
47cdf0e10cSrcweir     sal_Int32           mnSheetId;      /// Sheet identifier.
48cdf0e10cSrcweir     sal_Int32           mnState;        /// Visibility state.
49cdf0e10cSrcweir 
50cdf0e10cSrcweir     explicit            SheetInfoModel();
51cdf0e10cSrcweir };
52cdf0e10cSrcweir 
53cdf0e10cSrcweir // ============================================================================
54cdf0e10cSrcweir 
55cdf0e10cSrcweir /** Stores information about all sheets in a spreadsheet document.
56cdf0e10cSrcweir 
57cdf0e10cSrcweir     Information about sheets includes the sheet name, the visibility state, and
58cdf0e10cSrcweir     for the OOXML filter, the relation identifier of the sheet used to obtain
59cdf0e10cSrcweir     the related worksheet fragment.
60cdf0e10cSrcweir  */
61cdf0e10cSrcweir class WorksheetBuffer : public WorkbookHelper
62cdf0e10cSrcweir {
63cdf0e10cSrcweir public:
64cdf0e10cSrcweir     explicit            WorksheetBuffer( const WorkbookHelper& rHelper );
65cdf0e10cSrcweir 
66cdf0e10cSrcweir     /** Returns the base file name without path and file extension. */
67cdf0e10cSrcweir     static ::rtl::OUString getBaseFileName( const ::rtl::OUString& rUrl );
68cdf0e10cSrcweir 
69cdf0e10cSrcweir     /** Initializes the buffer for single sheet files (BIFF2-BIFF4). */
70cdf0e10cSrcweir     void                initializeSingleSheet();
71cdf0e10cSrcweir 
72cdf0e10cSrcweir     /** Imports the attributes of a sheet element. */
73cdf0e10cSrcweir     void                importSheet( const AttributeList& rAttribs );
74cdf0e10cSrcweir     /** Imports the SHEET record from the passed BIFF12 stream. */
75cdf0e10cSrcweir     void                importSheet( SequenceInputStream& rStrm );
76cdf0e10cSrcweir     /** Imports the SHEET record from the passed BIFF stream. */
77cdf0e10cSrcweir     void                importSheet( BiffInputStream& rStrm );
78cdf0e10cSrcweir     /** Inserts a new empty sheet into the document. Looks for an unused name.
79cdf0e10cSrcweir          @return  Index of the new sheet in the Calc document. */
80cdf0e10cSrcweir     sal_Int16           insertEmptySheet( const ::rtl::OUString& rPreferredName, bool bVisible );
81cdf0e10cSrcweir 
82cdf0e10cSrcweir     /** Returns the number of original sheets contained in the workbook. */
83cdf0e10cSrcweir     sal_Int32           getWorksheetCount() const;
84cdf0e10cSrcweir     /** Returns the OOXML relation identifier of the specified worksheet. */
85cdf0e10cSrcweir     ::rtl::OUString     getWorksheetRelId( sal_Int32 nWorksheet ) const;
86cdf0e10cSrcweir     /** Returns the BIFF record handle of the associated sheet substream. */
87cdf0e10cSrcweir     sal_Int64           getBiffRecordHandle( sal_Int32 nWorksheet ) const;
88cdf0e10cSrcweir 
89cdf0e10cSrcweir     /** Returns the Calc index of the specified worksheet. */
90cdf0e10cSrcweir     sal_Int16           getCalcSheetIndex( sal_Int32 nWorksheet ) const;
91cdf0e10cSrcweir     /** Returns the finalized name of the specified worksheet. */
92cdf0e10cSrcweir     ::rtl::OUString     getCalcSheetName( sal_Int32 nWorksheet ) const;
93cdf0e10cSrcweir 
94cdf0e10cSrcweir     /** Returns the Calc index of the sheet with the passed original worksheet name. */
95cdf0e10cSrcweir     sal_Int16           getCalcSheetIndex( const ::rtl::OUString& rWorksheetName ) const;
96cdf0e10cSrcweir     /** Returns the finalized name of the sheet with the passed worksheet name. */
97cdf0e10cSrcweir     ::rtl::OUString     getCalcSheetName( const ::rtl::OUString& rWorksheetName ) const;
98cdf0e10cSrcweir 
99cdf0e10cSrcweir private:
100cdf0e10cSrcweir     struct SheetInfo : public SheetInfoModel
101cdf0e10cSrcweir     {
102cdf0e10cSrcweir         ::rtl::OUString     maCalcName;
103cdf0e10cSrcweir         ::rtl::OUString     maCalcQuotedName;
104cdf0e10cSrcweir         sal_Int16           mnCalcSheet;
105cdf0e10cSrcweir 
106cdf0e10cSrcweir         explicit            SheetInfo( const SheetInfoModel& rModel, sal_Int16 nCalcSheet, const ::rtl::OUString& rCalcName );
107cdf0e10cSrcweir     };
108cdf0e10cSrcweir 
109cdf0e10cSrcweir     typedef ::std::pair< sal_Int16, ::rtl::OUString > IndexNamePair;
110cdf0e10cSrcweir 
111cdf0e10cSrcweir     /** Creates a new sheet in the Calc document. Does not insert anything in the own lists. */
112cdf0e10cSrcweir     IndexNamePair       createSheet( const ::rtl::OUString& rPreferredName, sal_Int32 nSheetPos, bool bVisible );
113cdf0e10cSrcweir     /** Creates a new sheet in the Calc document and inserts the related SheetInfo. */
114cdf0e10cSrcweir     void                insertSheet( const SheetInfoModel& rModel );
115cdf0e10cSrcweir 
116cdf0e10cSrcweir private:
117cdf0e10cSrcweir     typedef RefVector< SheetInfo > SheetInfoVector;
118cdf0e10cSrcweir     SheetInfoVector     maSheetInfos;
119cdf0e10cSrcweir 
120cdf0e10cSrcweir     typedef RefMap< ::rtl::OUString, SheetInfo, IgnoreCaseCompare > SheetInfoMap;
121cdf0e10cSrcweir     SheetInfoMap        maSheetInfosByName;
122cdf0e10cSrcweir };
123cdf0e10cSrcweir 
124cdf0e10cSrcweir // ============================================================================
125cdf0e10cSrcweir 
126cdf0e10cSrcweir } // namespace xls
127cdf0e10cSrcweir } // namespace oox
128cdf0e10cSrcweir 
129cdf0e10cSrcweir #endif
130