1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: chartsheetfragment.cxx,v $
10 * $Revision: 1.4.4.2 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include "oox/xls/chartsheetfragment.hxx"
32 #include "oox/helper/attributelist.hxx"
33 #include "oox/helper/recordinputstream.hxx"
34 #include "oox/xls/biffinputstream.hxx"
35 #include "oox/xls/pagesettings.hxx"
36 #include "oox/xls/viewsettings.hxx"
37 #include "oox/xls/workbooksettings.hxx"
38 #include "oox/xls/worksheetsettings.hxx"
40 using ::rtl::OUString
;
41 using ::oox::core::ContextHandlerRef
;
42 using ::oox::core::RecordInfo
;
47 // ============================================================================
49 OoxChartsheetFragment::OoxChartsheetFragment( const WorkbookHelper
& rHelper
,
50 const OUString
& rFragmentPath
, ISegmentProgressBarRef xProgressBar
, sal_Int16 nSheet
) :
51 OoxWorksheetFragmentBase( rHelper
, rFragmentPath
, xProgressBar
, SHEETTYPE_CHARTSHEET
, nSheet
)
55 // oox.core.ContextHandler2Helper interface -----------------------------------
57 ContextHandlerRef
OoxChartsheetFragment::onCreateContext( sal_Int32 nElement
, const AttributeList
& rAttribs
)
59 switch( getCurrentElement() )
61 case XML_ROOT_CONTEXT
:
62 if( nElement
== XLS_TOKEN( chartsheet
) ) return this;
65 case XLS_TOKEN( chartsheet
):
68 case XLS_TOKEN( sheetViews
): return this;
70 case XLS_TOKEN( sheetPr
): getWorksheetSettings().importChartSheetPr( rAttribs
); break;
71 case XLS_TOKEN( sheetProtection
): getWorksheetSettings().importChartProtection( rAttribs
); break;
72 case XLS_TOKEN( pageMargins
): getPageSettings().importPageMargins( rAttribs
); break;
73 case XLS_TOKEN( pageSetup
): getPageSettings().importChartPageSetup( getRelations(), rAttribs
); break;
74 case XLS_TOKEN( headerFooter
): getPageSettings().importHeaderFooter( rAttribs
); return this;
75 case XLS_TOKEN( picture
): getPageSettings().importPicture( getRelations(), rAttribs
); break;
76 case XLS_TOKEN( drawing
): importDrawing( rAttribs
); break;
80 case XLS_TOKEN( sheetViews
):
81 if( nElement
== XLS_TOKEN( sheetView
) ) getSheetViewSettings().importChartSheetView( rAttribs
);
84 case XLS_TOKEN( headerFooter
):
87 case XLS_TOKEN( firstHeader
):
88 case XLS_TOKEN( firstFooter
):
89 case XLS_TOKEN( oddHeader
):
90 case XLS_TOKEN( oddFooter
):
91 case XLS_TOKEN( evenHeader
):
92 case XLS_TOKEN( evenFooter
): return this; // collect contents in onEndElement()
99 void OoxChartsheetFragment::onEndElement( const OUString
& rChars
)
101 switch( getCurrentElement() )
103 case XLS_TOKEN( firstHeader
):
104 case XLS_TOKEN( firstFooter
):
105 case XLS_TOKEN( oddHeader
):
106 case XLS_TOKEN( oddFooter
):
107 case XLS_TOKEN( evenHeader
):
108 case XLS_TOKEN( evenFooter
):
109 getPageSettings().importHeaderFooterCharacters( rChars
, getCurrentElement() );
114 ContextHandlerRef
OoxChartsheetFragment::onCreateRecordContext( sal_Int32 nRecId
, RecordInputStream
& rStrm
)
116 switch( getCurrentElement() )
118 case XML_ROOT_CONTEXT
:
119 if( nRecId
== OOBIN_ID_WORKSHEET
) return this;
122 case OOBIN_ID_WORKSHEET
:
125 case OOBIN_ID_CHARTSHEETVIEWS
: return this;
127 case OOBIN_ID_CHARTSHEETPR
: getWorksheetSettings().importChartSheetPr( rStrm
); break;
128 case OOBIN_ID_CHARTPROTECTION
: getWorksheetSettings().importChartProtection( rStrm
); break;
129 case OOBIN_ID_PAGEMARGINS
: getPageSettings().importPageMargins( rStrm
); break;
130 case OOBIN_ID_CHARTPAGESETUP
: getPageSettings().importChartPageSetup( getRelations(), rStrm
); break;
131 case OOBIN_ID_HEADERFOOTER
: getPageSettings().importHeaderFooter( rStrm
); break;
132 case OOBIN_ID_PICTURE
: getPageSettings().importPicture( getRelations(), rStrm
); break;
133 case OOBIN_ID_DRAWING
: importDrawing( rStrm
); break;
137 case OOBIN_ID_CHARTSHEETVIEWS
:
138 if( nRecId
== OOBIN_ID_CHARTSHEETVIEW
) getSheetViewSettings().importChartSheetView( rStrm
);
144 // oox.core.FragmentHandler2 interface ----------------------------------------
146 const RecordInfo
* OoxChartsheetFragment::getRecordInfos() const
148 static const RecordInfo spRecInfos
[] =
150 { OOBIN_ID_CHARTSHEETVIEW
, OOBIN_ID_CHARTSHEETVIEW
+ 1 },
151 { OOBIN_ID_CHARTSHEETVIEWS
, OOBIN_ID_CHARTSHEETVIEWS
+ 1 },
152 { OOBIN_ID_CUSTOMCHARTVIEW
, OOBIN_ID_CUSTOMCHARTVIEW
+ 1 },
153 { OOBIN_ID_CUSTOMCHARTVIEWS
, OOBIN_ID_CUSTOMCHARTVIEWS
+ 1 },
154 { OOBIN_ID_HEADERFOOTER
, OOBIN_ID_HEADERFOOTER
+ 1 },
155 { OOBIN_ID_WORKSHEET
, OOBIN_ID_WORKSHEET
+ 1 },
161 void OoxChartsheetFragment::initializeImport()
163 // initial processing in base class WorksheetHelper
164 initializeWorksheetImport();
167 void OoxChartsheetFragment::finalizeImport()
169 // final processing in base class WorksheetHelper
170 finalizeWorksheetImport();
173 // private --------------------------------------------------------------------
175 void OoxChartsheetFragment::importDrawing( const AttributeList
& rAttribs
)
177 setDrawingPath( getFragmentPathFromRelId( rAttribs
.getString( R_TOKEN( id
), OUString() ) ) );
180 void OoxChartsheetFragment::importDrawing( RecordInputStream
& rStrm
)
182 setDrawingPath( getFragmentPathFromRelId( rStrm
.readString() ) );
185 // ============================================================================
187 BiffChartsheetFragment::BiffChartsheetFragment( const BiffWorkbookFragmentBase
& rParent
,
188 ISegmentProgressBarRef xProgressBar
, sal_Int16 nSheet
) :
189 BiffWorksheetFragmentBase( rParent
, xProgressBar
, SHEETTYPE_CHARTSHEET
, nSheet
)
193 bool BiffChartsheetFragment::importFragment()
195 // initial processing in base class WorksheetHelper
196 initializeWorksheetImport();
198 WorksheetSettings
& rWorksheetSett
= getWorksheetSettings();
199 SheetViewSettings
& rSheetViewSett
= getSheetViewSettings();
200 PageSettings
& rPageSett
= getPageSettings();
202 // process all record in this sheet fragment
203 while( mrStrm
.startNextRecord() && (mrStrm
.getRecId() != BIFF_ID_EOF
) )
207 // skip unknown embedded fragments (BOF/EOF blocks)
212 sal_uInt16 nRecId
= mrStrm
.getRecId();
215 // records in all BIFF versions
216 case BIFF_ID_BOTTOMMARGIN
: rPageSett
.importBottomMargin( mrStrm
); break;
217 case BIFF_ID_CHBEGIN
: skipRecordBlock( BIFF_ID_CHEND
); break;
218 case BIFF_ID_FOOTER
: rPageSett
.importFooter( mrStrm
); break;
219 case BIFF_ID_HEADER
: rPageSett
.importHeader( mrStrm
); break;
220 case BIFF_ID_LEFTMARGIN
: rPageSett
.importLeftMargin( mrStrm
); break;
221 case BIFF_ID_PASSWORD
: rWorksheetSett
.importPassword( mrStrm
); break;
222 case BIFF_ID_PROTECT
: rWorksheetSett
.importProtect( mrStrm
); break;
223 case BIFF_ID_RIGHTMARGIN
: rPageSett
.importRightMargin( mrStrm
); break;
224 case BIFF_ID_TOPMARGIN
: rPageSett
.importTopMargin( mrStrm
); break;
226 // BIFF specific records
227 default: switch( getBiff() )
229 case BIFF2
: switch( nRecId
)
231 case BIFF2_ID_WINDOW2
: rSheetViewSett
.importWindow2( mrStrm
); break;
235 case BIFF3
: switch( nRecId
)
237 case BIFF_ID_HCENTER
: rPageSett
.importHorCenter( mrStrm
); break;
238 case BIFF_ID_OBJECTPROTECT
: rWorksheetSett
.importObjectProtect( mrStrm
); break;
239 case BIFF_ID_VCENTER
: rPageSett
.importVerCenter( mrStrm
); break;
240 case BIFF3_ID_WINDOW2
: rSheetViewSett
.importWindow2( mrStrm
); break;
245 case BIFF4
: switch( nRecId
)
247 case BIFF_ID_HCENTER
: rPageSett
.importHorCenter( mrStrm
); break;
248 case BIFF_ID_OBJECTPROTECT
: rWorksheetSett
.importObjectProtect( mrStrm
); break;
249 case BIFF_ID_PAGESETUP
: rPageSett
.importPageSetup( mrStrm
); break;
250 case BIFF_ID_VCENTER
: rPageSett
.importVerCenter( mrStrm
); break;
251 case BIFF3_ID_WINDOW2
: rSheetViewSett
.importWindow2( mrStrm
); break;
255 case BIFF5
: switch( nRecId
)
257 case BIFF_ID_HCENTER
: rPageSett
.importHorCenter( mrStrm
); break;
258 case BIFF_ID_OBJECTPROTECT
: rWorksheetSett
.importObjectProtect( mrStrm
); break;
259 case BIFF_ID_PAGESETUP
: rPageSett
.importPageSetup( mrStrm
); break;
260 case BIFF_ID_SCENPROTECT
: rWorksheetSett
.importScenProtect( mrStrm
); break;
261 case BIFF_ID_SCL
: rSheetViewSett
.importScl( mrStrm
); break;
262 case BIFF_ID_VCENTER
: rPageSett
.importVerCenter( mrStrm
); break;
263 case BIFF3_ID_WINDOW2
: rSheetViewSett
.importWindow2( mrStrm
); break;
267 case BIFF8
: switch( nRecId
)
269 case BIFF_ID_HCENTER
: rPageSett
.importHorCenter( mrStrm
); break;
270 case BIFF_ID_OBJECTPROTECT
: rWorksheetSett
.importObjectProtect( mrStrm
); break;
271 case BIFF_ID_PICTURE
: rPageSett
.importPicture( mrStrm
); break;
272 case BIFF_ID_PAGESETUP
: rPageSett
.importPageSetup( mrStrm
); break;
273 case BIFF_ID_SCL
: rSheetViewSett
.importScl( mrStrm
); break;
274 case BIFF_ID_VCENTER
: rPageSett
.importVerCenter( mrStrm
); break;
275 case BIFF3_ID_WINDOW2
: rSheetViewSett
.importWindow2( mrStrm
); break;
279 case BIFF_UNKNOWN
: break;
285 // final processing in base class WorksheetHelper
286 finalizeWorksheetImport();
287 return mrStrm
.getRecId() == BIFF_ID_EOF
;
290 // ============================================================================