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