1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #ifndef OOX_XLS_WORKSHEETBUFFER_HXX 29 #define OOX_XLS_WORKSHEETBUFFER_HXX 30 31 #include <utility> 32 #include "oox/helper/refmap.hxx" 33 #include "oox/helper/refvector.hxx" 34 #include "oox/xls/workbookhelper.hxx" 35 36 namespace com { namespace sun { namespace star { 37 namespace i18n { class XCharacterClassification; } 38 } } } 39 40 namespace oox { 41 namespace xls { 42 43 // ============================================================================ 44 45 /** Contains data from the 'sheet' element describing a sheet in the workbook. */ 46 struct SheetInfoModel 47 { 48 ::rtl::OUString maRelId; /// Relation identifier for the sheet substream. 49 ::rtl::OUString maName; /// Original name of the sheet. 50 sal_Int64 mnBiffHandle; /// BIFF record handle of the sheet substream. 51 sal_Int32 mnSheetId; /// Sheet identifier. 52 sal_Int32 mnState; /// Visibility state. 53 54 explicit SheetInfoModel(); 55 }; 56 57 // ============================================================================ 58 59 /** Stores information about all sheets in a spreadsheet document. 60 61 Information about sheets includes the sheet name, the visibility state, and 62 for the OOXML filter, the relation identifier of the sheet used to obtain 63 the related worksheet fragment. 64 */ 65 class WorksheetBuffer : public WorkbookHelper 66 { 67 public: 68 explicit WorksheetBuffer( const WorkbookHelper& rHelper ); 69 70 /** Returns the base file name without path and file extension. */ 71 static ::rtl::OUString getBaseFileName( const ::rtl::OUString& rUrl ); 72 73 /** Initializes the buffer for single sheet files (BIFF2-BIFF4). */ 74 void initializeSingleSheet(); 75 76 /** Imports the attributes of a sheet element. */ 77 void importSheet( const AttributeList& rAttribs ); 78 /** Imports the SHEET record from the passed BIFF12 stream. */ 79 void importSheet( SequenceInputStream& rStrm ); 80 /** Imports the SHEET record from the passed BIFF stream. */ 81 void importSheet( BiffInputStream& rStrm ); 82 /** Inserts a new empty sheet into the document. Looks for an unused name. 83 @return Index of the new sheet in the Calc document. */ 84 sal_Int16 insertEmptySheet( const ::rtl::OUString& rPreferredName, bool bVisible ); 85 86 /** Returns the number of original sheets contained in the workbook. */ 87 sal_Int32 getWorksheetCount() const; 88 /** Returns the OOXML relation identifier of the specified worksheet. */ 89 ::rtl::OUString getWorksheetRelId( sal_Int32 nWorksheet ) const; 90 /** Returns the BIFF record handle of the associated sheet substream. */ 91 sal_Int64 getBiffRecordHandle( sal_Int32 nWorksheet ) const; 92 93 /** Returns the Calc index of the specified worksheet. */ 94 sal_Int16 getCalcSheetIndex( sal_Int32 nWorksheet ) const; 95 /** Returns the finalized name of the specified worksheet. */ 96 ::rtl::OUString getCalcSheetName( sal_Int32 nWorksheet ) const; 97 98 /** Returns the Calc index of the sheet with the passed original worksheet name. */ 99 sal_Int16 getCalcSheetIndex( const ::rtl::OUString& rWorksheetName ) const; 100 /** Returns the finalized name of the sheet with the passed worksheet name. */ 101 ::rtl::OUString getCalcSheetName( const ::rtl::OUString& rWorksheetName ) const; 102 103 private: 104 struct SheetInfo : public SheetInfoModel 105 { 106 ::rtl::OUString maCalcName; 107 ::rtl::OUString maCalcQuotedName; 108 sal_Int16 mnCalcSheet; 109 110 explicit SheetInfo( const SheetInfoModel& rModel, sal_Int16 nCalcSheet, const ::rtl::OUString& rCalcName ); 111 }; 112 113 typedef ::std::pair< sal_Int16, ::rtl::OUString > IndexNamePair; 114 115 /** Creates a new sheet in the Calc document. Does not insert anything in the own lists. */ 116 IndexNamePair createSheet( const ::rtl::OUString& rPreferredName, sal_Int32 nSheetPos, bool bVisible ); 117 /** Creates a new sheet in the Calc document and inserts the related SheetInfo. */ 118 void insertSheet( const SheetInfoModel& rModel ); 119 120 private: 121 typedef RefVector< SheetInfo > SheetInfoVector; 122 SheetInfoVector maSheetInfos; 123 124 typedef RefMap< ::rtl::OUString, SheetInfo, IgnoreCaseCompare > SheetInfoMap; 125 SheetInfoMap maSheetInfosByName; 126 }; 127 128 // ============================================================================ 129 130 } // namespace xls 131 } // namespace oox 132 133 #endif 134