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 #include "oox/xls/chartsheetfragment.hxx" 29 30 #include "oox/helper/attributelist.hxx" 31 #include "oox/xls/biffinputstream.hxx" 32 #include "oox/xls/pagesettings.hxx" 33 #include "oox/xls/viewsettings.hxx" 34 #include "oox/xls/workbooksettings.hxx" 35 #include "oox/xls/worksheetsettings.hxx" 36 37 namespace oox { 38 namespace xls { 39 40 // ============================================================================ 41 42 using namespace ::oox::core; 43 44 using ::rtl::OUString; 45 46 // ============================================================================ 47 48 ChartsheetFragment::ChartsheetFragment( const WorksheetHelper& rHelper, const OUString& rFragmentPath ) : 49 WorksheetFragmentBase( rHelper, rFragmentPath ) 50 { 51 } 52 53 ContextHandlerRef ChartsheetFragment::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ) 54 { 55 switch( getCurrentElement() ) 56 { 57 case XML_ROOT_CONTEXT: 58 if( nElement == XLS_TOKEN( chartsheet ) ) return this; 59 break; 60 61 case XLS_TOKEN( chartsheet ): 62 switch( nElement ) 63 { 64 case XLS_TOKEN( sheetViews ): return this; 65 66 case XLS_TOKEN( sheetPr ): getWorksheetSettings().importChartSheetPr( rAttribs ); break; 67 case XLS_TOKEN( sheetProtection ): getWorksheetSettings().importChartProtection( rAttribs ); break; 68 case XLS_TOKEN( pageMargins ): getPageSettings().importPageMargins( rAttribs ); break; 69 case XLS_TOKEN( pageSetup ): getPageSettings().importChartPageSetup( getRelations(), rAttribs ); break; 70 case XLS_TOKEN( headerFooter ): getPageSettings().importHeaderFooter( rAttribs ); return this; 71 case XLS_TOKEN( picture ): getPageSettings().importPicture( getRelations(), rAttribs ); break; 72 case XLS_TOKEN( drawing ): importDrawing( rAttribs ); break; 73 } 74 break; 75 76 case XLS_TOKEN( sheetViews ): 77 if( nElement == XLS_TOKEN( sheetView ) ) getSheetViewSettings().importChartSheetView( rAttribs ); 78 break; 79 80 case XLS_TOKEN( headerFooter ): 81 switch( nElement ) 82 { 83 case XLS_TOKEN( firstHeader ): 84 case XLS_TOKEN( firstFooter ): 85 case XLS_TOKEN( oddHeader ): 86 case XLS_TOKEN( oddFooter ): 87 case XLS_TOKEN( evenHeader ): 88 case XLS_TOKEN( evenFooter ): return this; // collect contents in onCharacters() 89 } 90 break; 91 } 92 return 0; 93 } 94 95 void ChartsheetFragment::onCharacters( const OUString& rChars ) 96 { 97 switch( getCurrentElement() ) 98 { 99 case XLS_TOKEN( firstHeader ): 100 case XLS_TOKEN( firstFooter ): 101 case XLS_TOKEN( oddHeader ): 102 case XLS_TOKEN( oddFooter ): 103 case XLS_TOKEN( evenHeader ): 104 case XLS_TOKEN( evenFooter ): 105 getPageSettings().importHeaderFooterCharacters( rChars, getCurrentElement() ); 106 break; 107 } 108 } 109 110 ContextHandlerRef ChartsheetFragment::onCreateRecordContext( sal_Int32 nRecId, SequenceInputStream& rStrm ) 111 { 112 switch( getCurrentElement() ) 113 { 114 case XML_ROOT_CONTEXT: 115 if( nRecId == BIFF12_ID_WORKSHEET ) return this; 116 break; 117 118 case BIFF12_ID_WORKSHEET: 119 switch( nRecId ) 120 { 121 case BIFF12_ID_CHARTSHEETVIEWS: return this; 122 123 case BIFF12_ID_CHARTSHEETPR: getWorksheetSettings().importChartSheetPr( rStrm ); break; 124 case BIFF12_ID_CHARTPROTECTION: getWorksheetSettings().importChartProtection( rStrm ); break; 125 case BIFF12_ID_PAGEMARGINS: getPageSettings().importPageMargins( rStrm ); break; 126 case BIFF12_ID_CHARTPAGESETUP: getPageSettings().importChartPageSetup( getRelations(), rStrm ); break; 127 case BIFF12_ID_HEADERFOOTER: getPageSettings().importHeaderFooter( rStrm ); break; 128 case BIFF12_ID_PICTURE: getPageSettings().importPicture( getRelations(), rStrm ); break; 129 case BIFF12_ID_DRAWING: importDrawing( rStrm ); break; 130 } 131 break; 132 133 case BIFF12_ID_CHARTSHEETVIEWS: 134 if( nRecId == BIFF12_ID_CHARTSHEETVIEW ) getSheetViewSettings().importChartSheetView( rStrm ); 135 break; 136 } 137 return 0; 138 } 139 140 const RecordInfo* ChartsheetFragment::getRecordInfos() const 141 { 142 static const RecordInfo spRecInfos[] = 143 { 144 { BIFF12_ID_CHARTSHEETVIEW, BIFF12_ID_CHARTSHEETVIEW + 1 }, 145 { BIFF12_ID_CHARTSHEETVIEWS, BIFF12_ID_CHARTSHEETVIEWS + 1 }, 146 { BIFF12_ID_CUSTOMCHARTVIEW, BIFF12_ID_CUSTOMCHARTVIEW + 1 }, 147 { BIFF12_ID_CUSTOMCHARTVIEWS, BIFF12_ID_CUSTOMCHARTVIEWS + 1 }, 148 { BIFF12_ID_HEADERFOOTER, BIFF12_ID_HEADERFOOTER + 1 }, 149 { BIFF12_ID_WORKSHEET, BIFF12_ID_WORKSHEET + 1 }, 150 { -1, -1 } 151 }; 152 return spRecInfos; 153 } 154 155 void ChartsheetFragment::initializeImport() 156 { 157 // initial processing in base class WorksheetHelper 158 initializeWorksheetImport(); 159 } 160 161 void ChartsheetFragment::finalizeImport() 162 { 163 // final processing in base class WorksheetHelper 164 finalizeWorksheetImport(); 165 } 166 167 // private -------------------------------------------------------------------- 168 169 void ChartsheetFragment::importDrawing( const AttributeList& rAttribs ) 170 { 171 setDrawingPath( getFragmentPathFromRelId( rAttribs.getString( R_TOKEN( id ), OUString() ) ) ); 172 } 173 174 void ChartsheetFragment::importDrawing( SequenceInputStream& rStrm ) 175 { 176 setDrawingPath( getFragmentPathFromRelId( BiffHelper::readString( rStrm ) ) ); 177 } 178 179 // ============================================================================ 180 181 BiffChartsheetFragment::BiffChartsheetFragment( const WorksheetHelper& rHelper, const BiffWorkbookFragmentBase& rParent ) : 182 BiffWorksheetFragmentBase( rHelper, rParent ) 183 { 184 } 185 186 bool BiffChartsheetFragment::importFragment() 187 { 188 // initial processing in base class WorksheetHelper 189 initializeWorksheetImport(); 190 191 WorksheetSettings& rWorksheetSett = getWorksheetSettings(); 192 SheetViewSettings& rSheetViewSett = getSheetViewSettings(); 193 PageSettings& rPageSett = getPageSettings(); 194 195 // process all record in this sheet fragment 196 BiffInputStream& rStrm = getInputStream(); 197 while( rStrm.startNextRecord() && (rStrm.getRecId() != BIFF_ID_EOF) ) 198 { 199 if( BiffHelper::isBofRecord( rStrm ) ) 200 { 201 // skip unknown embedded fragments (BOF/EOF blocks) 202 skipFragment(); 203 } 204 else 205 { 206 sal_uInt16 nRecId = rStrm.getRecId(); 207 switch( nRecId ) 208 { 209 // records in all BIFF versions 210 case BIFF_ID_BOTTOMMARGIN: rPageSett.importBottomMargin( rStrm ); break; 211 case BIFF_ID_CHBEGIN: BiffHelper::skipRecordBlock( rStrm, BIFF_ID_CHEND ); break; 212 case BIFF_ID_FOOTER: rPageSett.importFooter( rStrm ); break; 213 case BIFF_ID_HEADER: rPageSett.importHeader( rStrm ); break; 214 case BIFF_ID_LEFTMARGIN: rPageSett.importLeftMargin( rStrm ); break; 215 case BIFF_ID_PASSWORD: rWorksheetSett.importPassword( rStrm ); break; 216 case BIFF_ID_PROTECT: rWorksheetSett.importProtect( rStrm ); break; 217 case BIFF_ID_RIGHTMARGIN: rPageSett.importRightMargin( rStrm ); break; 218 case BIFF_ID_TOPMARGIN: rPageSett.importTopMargin( rStrm ); break; 219 220 // BIFF specific records 221 default: switch( getBiff() ) 222 { 223 case BIFF2: switch( nRecId ) 224 { 225 case BIFF2_ID_WINDOW2: rSheetViewSett.importWindow2( rStrm ); break; 226 } 227 break; 228 229 case BIFF3: switch( nRecId ) 230 { 231 case BIFF_ID_HCENTER: rPageSett.importHorCenter( rStrm ); break; 232 case BIFF_ID_OBJECTPROTECT: rWorksheetSett.importObjectProtect( rStrm ); break; 233 case BIFF_ID_VCENTER: rPageSett.importVerCenter( rStrm ); break; 234 case BIFF3_ID_WINDOW2: rSheetViewSett.importWindow2( rStrm ); break; 235 236 } 237 break; 238 239 case BIFF4: switch( nRecId ) 240 { 241 case BIFF_ID_HCENTER: rPageSett.importHorCenter( rStrm ); break; 242 case BIFF_ID_OBJECTPROTECT: rWorksheetSett.importObjectProtect( rStrm ); break; 243 case BIFF_ID_PAGESETUP: rPageSett.importPageSetup( rStrm ); break; 244 case BIFF_ID_VCENTER: rPageSett.importVerCenter( rStrm ); break; 245 case BIFF3_ID_WINDOW2: rSheetViewSett.importWindow2( rStrm ); break; 246 } 247 break; 248 249 case BIFF5: switch( nRecId ) 250 { 251 case BIFF_ID_HCENTER: rPageSett.importHorCenter( rStrm ); break; 252 case BIFF_ID_OBJECTPROTECT: rWorksheetSett.importObjectProtect( rStrm ); break; 253 case BIFF_ID_PAGESETUP: rPageSett.importPageSetup( rStrm ); break; 254 case BIFF_ID_SCENPROTECT: rWorksheetSett.importScenProtect( rStrm ); break; 255 case BIFF_ID_SCL: rSheetViewSett.importScl( rStrm ); break; 256 case BIFF_ID_VCENTER: rPageSett.importVerCenter( rStrm ); break; 257 case BIFF3_ID_WINDOW2: rSheetViewSett.importWindow2( rStrm ); break; 258 } 259 break; 260 261 case BIFF8: switch( nRecId ) 262 { 263 case BIFF_ID_CODENAME: rWorksheetSett.importCodeName( rStrm ); break; 264 case BIFF_ID_HCENTER: rPageSett.importHorCenter( rStrm ); break; 265 case BIFF_ID_OBJECTPROTECT: rWorksheetSett.importObjectProtect( rStrm ); break; 266 case BIFF_ID_PICTURE: rPageSett.importPicture( rStrm ); break; 267 case BIFF_ID_PAGESETUP: rPageSett.importPageSetup( rStrm ); break; 268 case BIFF_ID_SCL: rSheetViewSett.importScl( rStrm ); break; 269 case BIFF_ID_SHEETEXT: rWorksheetSett.importSheetExt( rStrm ); break; 270 case BIFF_ID_VCENTER: rPageSett.importVerCenter( rStrm ); break; 271 case BIFF3_ID_WINDOW2: rSheetViewSett.importWindow2( rStrm ); break; 272 } 273 break; 274 275 case BIFF_UNKNOWN: break; 276 } 277 } 278 } 279 } 280 281 // final processing in base class WorksheetHelper 282 finalizeWorksheetImport(); 283 return rStrm.getRecId() == BIFF_ID_EOF; 284 } 285 286 // ============================================================================ 287 288 } // namespace xls 289 } // namespace oox 290