fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / filter / oox / externallinkfragment.cxx
blob31854efa4ab9f6a469578bc8338e150cbe9e1c15
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "externallinkfragment.hxx"
22 #include <com/sun/star/sheet/XExternalSheetCache.hpp>
23 #include <oox/helper/attributelist.hxx>
24 #include "biffinputstream.hxx"
25 #include "defnamesbuffer.hxx"
26 #include "sheetdatacontext.hxx"
27 #include "unitconverter.hxx"
29 namespace oox {
30 namespace xls {
32 using namespace ::com::sun::star::sheet;
33 using namespace ::com::sun::star::table;
34 using namespace ::com::sun::star::uno;
35 using namespace ::oox::core;
37 ExternalSheetDataContext::ExternalSheetDataContext(
38 WorkbookFragmentBase& rFragment, const Reference< XExternalSheetCache >& rxSheetCache )
39 : WorkbookContextBase(rFragment)
40 , mxSheetCache(rxSheetCache)
41 , mnCurrType(XML_TOKEN_INVALID)
43 OSL_ENSURE( mxSheetCache.is(), "ExternalSheetDataContext::ExternalSheetDataContext - missing sheet cache" );
46 ContextHandlerRef ExternalSheetDataContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
48 switch( getCurrentElement() )
50 case XLS_TOKEN( sheetData ):
51 if( nElement == XLS_TOKEN( row ) ) return this;
52 break;
53 case XLS_TOKEN( row ):
54 if( nElement == XLS_TOKEN( cell ) ) { importCell( rAttribs ); return this; }
55 break;
56 case XLS_TOKEN( cell ):
57 if( nElement == XLS_TOKEN( v ) ) return this; // collect characters in onCharacters()
58 break;
60 return 0;
63 void ExternalSheetDataContext::onCharacters( const OUString& rChars )
65 if( isCurrentElement( XLS_TOKEN( v ) ) )
67 switch( mnCurrType )
69 case XML_b:
70 case XML_n:
71 setCellValue( Any( rChars.toDouble() ) );
72 break;
73 case XML_e:
74 setCellValue( Any( BiffHelper::calcDoubleFromError( getUnitConverter().calcBiffErrorCode( rChars ) ) ) );
75 break;
76 case XML_str:
77 setCellValue( Any( rChars ) );
78 break;
80 mnCurrType = XML_TOKEN_INVALID;
84 ContextHandlerRef ExternalSheetDataContext::onCreateRecordContext( sal_Int32 nRecId, SequenceInputStream& rStrm )
86 switch( getCurrentElement() )
88 case BIFF12_ID_EXTSHEETDATA:
89 if( nRecId == BIFF12_ID_EXTROW ) { maCurrPos.Row = rStrm.readInt32(); return this; }
90 break;
91 case BIFF12_ID_EXTROW:
92 switch( nRecId )
94 case BIFF12_ID_EXTCELL_BLANK: importExtCellBlank( rStrm ); break;
95 case BIFF12_ID_EXTCELL_BOOL: importExtCellBool( rStrm ); break;
96 case BIFF12_ID_EXTCELL_DOUBLE: importExtCellDouble( rStrm ); break;
97 case BIFF12_ID_EXTCELL_ERROR: importExtCellError( rStrm ); break;
98 case BIFF12_ID_EXTCELL_STRING: importExtCellString( rStrm ); break;
100 break;
102 return 0;
105 // private --------------------------------------------------------------------
107 void ExternalSheetDataContext::importCell( const AttributeList& rAttribs )
109 if( getAddressConverter().convertToCellAddress( maCurrPos, rAttribs.getString( XML_r, OUString() ), 0, false ) )
110 mnCurrType = rAttribs.getToken( XML_t, XML_n );
111 else
112 mnCurrType = XML_TOKEN_INVALID;
115 void ExternalSheetDataContext::importExtCellBlank( SequenceInputStream& rStrm )
117 maCurrPos.Column = rStrm.readInt32();
118 setCellValue( Any( OUString() ) );
121 void ExternalSheetDataContext::importExtCellBool( SequenceInputStream& rStrm )
123 maCurrPos.Column = rStrm.readInt32();
124 double fValue = (rStrm.readuInt8() == 0) ? 0.0 : 1.0;
125 setCellValue( Any( fValue ) );
128 void ExternalSheetDataContext::importExtCellDouble( SequenceInputStream& rStrm )
130 maCurrPos.Column = rStrm.readInt32();
131 setCellValue( Any( rStrm.readDouble() ) );
134 void ExternalSheetDataContext::importExtCellError( SequenceInputStream& rStrm )
136 maCurrPos.Column = rStrm.readInt32();
137 setCellValue( Any( BiffHelper::calcDoubleFromError( rStrm.readuInt8() ) ) );
140 void ExternalSheetDataContext::importExtCellString( SequenceInputStream& rStrm )
142 maCurrPos.Column = rStrm.readInt32();
143 setCellValue( Any( BiffHelper::readString( rStrm ) ) );
146 void ExternalSheetDataContext::setCellValue( const Any& rValue )
148 if( mxSheetCache.is() && getAddressConverter().checkCellAddress( maCurrPos, false ) ) try
150 mxSheetCache->setCellValue( maCurrPos.Column, maCurrPos.Row, rValue );
152 catch( Exception& )
157 ExternalLinkFragment::ExternalLinkFragment( const WorkbookHelper& rHelper,
158 const OUString& rFragmentPath, ExternalLink& rExtLink ) :
159 WorkbookFragmentBase( rHelper, rFragmentPath ),
160 mrExtLink( rExtLink ),
161 mnResultType( XML_TOKEN_INVALID )
165 ContextHandlerRef ExternalLinkFragment::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
167 switch( getCurrentElement() )
169 case XML_ROOT_CONTEXT:
170 if( nElement == XLS_TOKEN( externalLink ) ) return this;
171 break;
173 case XLS_TOKEN( externalLink ):
174 switch( nElement )
176 case XLS_TOKEN( externalBook ): mrExtLink.importExternalBook( getRelations(), rAttribs ); return this;
177 case XLS_TOKEN( ddeLink ): mrExtLink.importDdeLink( rAttribs ); return this;
178 case XLS_TOKEN( oleLink ): mrExtLink.importOleLink( getRelations(), rAttribs ); return this;
180 break;
182 case XLS_TOKEN( externalBook ):
183 switch( nElement )
185 case XLS_TOKEN( sheetNames ):
186 case XLS_TOKEN( definedNames ):
187 case XLS_TOKEN( sheetDataSet ): return this;
189 break;
191 case XLS_TOKEN( sheetNames ):
192 if( nElement == XLS_TOKEN( sheetName ) ) mrExtLink.importSheetName( rAttribs );
193 break;
194 case XLS_TOKEN( definedNames ):
195 if( nElement == XLS_TOKEN( definedName ) ) mrExtLink.importDefinedName( rAttribs );
196 break;
197 case XLS_TOKEN( sheetDataSet ):
198 if( (nElement == XLS_TOKEN( sheetData )) && (mrExtLink.getLinkType() == LINKTYPE_EXTERNAL) )
199 return createSheetDataContext( rAttribs.getInteger( XML_sheetId, -1 ) );
200 break;
202 case XLS_TOKEN( ddeLink ):
203 if( nElement == XLS_TOKEN( ddeItems ) ) return this;
204 break;
205 case XLS_TOKEN( ddeItems ):
206 if( nElement == XLS_TOKEN( ddeItem ) )
208 mxExtName = mrExtLink.importDdeItem( rAttribs );
209 return this;
211 break;
212 case XLS_TOKEN( ddeItem ):
213 if( nElement == XLS_TOKEN( values ) )
215 if( mxExtName.get() ) mxExtName->importValues( rAttribs );
216 return this;
218 break;
219 case XLS_TOKEN( values ):
220 if( nElement == XLS_TOKEN( value ) )
222 mnResultType = rAttribs.getToken( XML_t, XML_n );
223 return this;
225 break;
226 case XLS_TOKEN( value ):
227 if( nElement == XLS_TOKEN( val ) ) return this; // collect value in onCharacters()
228 break;
230 case XLS_TOKEN( oleLink ):
231 if( nElement == XLS_TOKEN( oleItems ) ) return this;
232 break;
233 case XLS_TOKEN( oleItems ):
234 if( nElement == XLS_TOKEN( oleItem ) ) mxExtName = mrExtLink.importOleItem( rAttribs );
235 break;
237 return 0;
240 void ExternalLinkFragment::onCharacters( const OUString& rChars )
242 if( isCurrentElement( XLS_TOKEN( val ) ) )
243 maResultValue = rChars;
246 void ExternalLinkFragment::onEndElement()
248 if( isCurrentElement( XLS_TOKEN( value ) ) && mxExtName.get() ) switch( mnResultType )
250 case XML_b:
251 mxExtName->appendResultValue( maResultValue.toDouble() );
252 break;
253 case XML_e:
254 mxExtName->appendResultValue( BiffHelper::calcDoubleFromError( getUnitConverter().calcBiffErrorCode( maResultValue ) ) );
255 break;
256 case XML_n:
257 mxExtName->appendResultValue( maResultValue.toDouble() );
258 break;
259 case XML_str:
260 mxExtName->appendResultValue( maResultValue );
261 break;
262 default:
263 mxExtName->appendResultValue( BiffHelper::calcDoubleFromError( BIFF_ERR_NA ) );
267 ContextHandlerRef ExternalLinkFragment::onCreateRecordContext( sal_Int32 nRecId, SequenceInputStream& rStrm )
269 switch( getCurrentElement() )
271 case XML_ROOT_CONTEXT:
272 if( nRecId == BIFF12_ID_EXTERNALBOOK )
274 mrExtLink.importExternalBook( getRelations(), rStrm );
275 return this;
277 break;
279 case BIFF12_ID_EXTERNALBOOK:
280 switch( nRecId )
282 case BIFF12_ID_EXTSHEETDATA:
283 if( mrExtLink.getLinkType() == LINKTYPE_EXTERNAL )
284 return createSheetDataContext( rStrm.readInt32() );
285 break;
287 case BIFF12_ID_EXTSHEETNAMES: mrExtLink.importExtSheetNames( rStrm ); break;
288 case BIFF12_ID_EXTERNALNAME: mxExtName = mrExtLink.importExternalName( rStrm ); return this;
290 break;
292 case BIFF12_ID_EXTERNALNAME:
293 switch( nRecId )
295 case BIFF12_ID_EXTERNALNAMEFLAGS: if( mxExtName.get() ) mxExtName->importExternalNameFlags( rStrm ); break;
296 case BIFF12_ID_DDEITEMVALUES: if( mxExtName.get() ) mxExtName->importDdeItemValues( rStrm ); return this;
298 break;
300 case BIFF12_ID_DDEITEMVALUES:
301 switch( nRecId )
303 case BIFF12_ID_DDEITEM_BOOL: if( mxExtName.get() ) mxExtName->importDdeItemBool( rStrm ); break;
304 case BIFF12_ID_DDEITEM_DOUBLE: if( mxExtName.get() ) mxExtName->importDdeItemDouble( rStrm ); break;
305 case BIFF12_ID_DDEITEM_ERROR: if( mxExtName.get() ) mxExtName->importDdeItemError( rStrm ); break;
306 case BIFF12_ID_DDEITEM_STRING: if( mxExtName.get() ) mxExtName->importDdeItemString( rStrm ); break;
308 break;
310 return 0;
313 ContextHandlerRef ExternalLinkFragment::createSheetDataContext( sal_Int32 nSheetId )
315 return new ExternalSheetDataContext( *this, mrExtLink.getSheetCache( nSheetId ) );
318 const RecordInfo* ExternalLinkFragment::getRecordInfos() const
320 static const RecordInfo spRecInfos[] =
322 { BIFF12_ID_DDEITEMVALUES, BIFF12_ID_DDEITEMVALUES + 1 },
323 { BIFF12_ID_EXTERNALBOOK, BIFF12_ID_EXTERNALBOOK + 228 },
324 { BIFF12_ID_EXTERNALNAME, BIFF12_ID_EXTERNALNAME + 10 },
325 { BIFF12_ID_EXTROW, -1 },
326 { BIFF12_ID_EXTSHEETDATA, BIFF12_ID_EXTSHEETDATA + 1 },
327 { -1, -1 }
329 return spRecInfos;
332 } // namespace xls
333 } // namespace oox
335 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */