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