Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 :
21 : /*todo: Change characters and tcharacters to accumulate the characters together
22 : into one string, xml parser hands them to us line by line rather than all in
23 : one go*/
24 :
25 : #include <com/sun/star/xml/sax/XErrorHandler.hpp>
26 : #include <com/sun/star/xml/sax/XEntityResolver.hpp>
27 : #include <com/sun/star/xml/sax/InputSource.hpp>
28 : #include <com/sun/star/xml/sax/XDTDHandler.hpp>
29 : #include <com/sun/star/xml/sax/Parser.hpp>
30 : #include <com/sun/star/io/XActiveDataSource.hpp>
31 : #include <com/sun/star/io/XActiveDataControl.hpp>
32 : #include <com/sun/star/document/XDocumentProperties.hpp>
33 : #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
34 : #include <com/sun/star/packages/zip/ZipIOException.hpp>
35 : #include <com/sun/star/task/XStatusIndicatorFactory.hpp>
36 : #include <com/sun/star/beans/PropertyAttribute.hpp>
37 : #include <com/sun/star/container/XNameAccess.hpp>
38 : #include <com/sun/star/embed/ElementModes.hpp>
39 : #include <com/sun/star/uno/Any.h>
40 :
41 : #include <comphelper/genericpropertyset.hxx>
42 : #include <comphelper/processfactory.hxx>
43 : #include <comphelper/servicehelper.hxx>
44 : #include <comphelper/string.hxx>
45 : #include <rtl/math.hxx>
46 : #include <sfx2/frame.hxx>
47 : #include <sfx2/docfile.hxx>
48 : #include <osl/diagnose.h>
49 : #include <svtools/sfxecode.hxx>
50 : #include <unotools/saveopt.hxx>
51 : #include <svl/stritem.hxx>
52 : #include <svl/itemprop.hxx>
53 : #include <unotools/streamwrap.hxx>
54 : #include <sax/tools/converter.hxx>
55 : #include <xmloff/xmlnmspe.hxx>
56 : #include <xmloff/xmltoken.hxx>
57 : #include <xmloff/nmspmap.hxx>
58 : #include <xmloff/attrlist.hxx>
59 : #include <xmloff/xmluconv.hxx>
60 : #include <xmloff/xmlmetai.hxx>
61 : #include <osl/mutex.hxx>
62 :
63 : #include <memory>
64 :
65 : #include "mathmlimport.hxx"
66 : #include <starmath.hrc>
67 : #include <unomodel.hxx>
68 : #include <document.hxx>
69 : #include <utility.hxx>
70 :
71 : using namespace ::com::sun::star::beans;
72 : using namespace ::com::sun::star::container;
73 : using namespace ::com::sun::star::document;
74 : using namespace ::com::sun::star::lang;
75 : using namespace ::com::sun::star::uno;
76 : using namespace ::com::sun::star;
77 : using namespace ::xmloff::token;
78 :
79 :
80 : #define IMPORT_SVC_NAME "com.sun.star.xml.XMLImportFilter"
81 :
82 : #undef WANTEXCEPT
83 :
84 : ////////////////////////////////////////////////////////////
85 :
86 : namespace {
87 : template < typename T >
88 0 : T* lcl_popOrZero( ::std::stack<T*> & rStack )
89 : {
90 0 : if (rStack.empty())
91 0 : return 0;
92 0 : T* pTmp = rStack.top();
93 0 : rStack.pop();
94 0 : return pTmp;
95 : }
96 : }
97 :
98 0 : sal_uLong SmXMLImportWrapper::Import(SfxMedium &rMedium)
99 : {
100 0 : sal_uLong nError = ERRCODE_SFX_DOLOADFAILED;
101 :
102 0 : uno::Reference<uno::XComponentContext> xContext( comphelper::getProcessComponentContext() );
103 :
104 : //Make a model component from our SmModel
105 0 : uno::Reference< lang::XComponent > xModelComp( xModel, uno::UNO_QUERY );
106 : OSL_ENSURE( xModelComp.is(), "XMLReader::Read: got no model" );
107 :
108 : // try to get an XStatusIndicator from the Medium
109 0 : uno::Reference<task::XStatusIndicator> xStatusIndicator;
110 :
111 0 : sal_Bool bEmbedded = sal_False;
112 0 : uno::Reference <lang::XUnoTunnel> xTunnel;
113 0 : xTunnel = uno::Reference <lang::XUnoTunnel> (xModel,uno::UNO_QUERY);
114 : SmModel *pModel = reinterpret_cast<SmModel *>
115 0 : (xTunnel->getSomething(SmModel::getUnoTunnelId()));
116 :
117 : SmDocShell *pDocShell = pModel ?
118 0 : static_cast<SmDocShell*>(pModel->GetObjectShell()) : 0;
119 0 : if (pDocShell)
120 : {
121 : OSL_ENSURE( pDocShell->GetMedium() == &rMedium,
122 : "different SfxMedium found" );
123 :
124 0 : SfxItemSet* pSet = rMedium.GetItemSet();
125 0 : if (pSet)
126 : {
127 : const SfxUnoAnyItem* pItem = static_cast<const SfxUnoAnyItem*>(
128 0 : pSet->GetItem(SID_PROGRESS_STATUSBAR_CONTROL) );
129 0 : if (pItem)
130 0 : pItem->GetValue() >>= xStatusIndicator;
131 : }
132 :
133 0 : if ( SFX_CREATE_MODE_EMBEDDED == pDocShell->GetCreateMode() )
134 0 : bEmbedded = sal_True;
135 : }
136 :
137 : comphelper::PropertyMapEntry aInfoMap[] =
138 : {
139 : { "PrivateData", sizeof("PrivateData")-1, 0,
140 0 : &::getCppuType( (Reference<XInterface> *)0 ),
141 : beans::PropertyAttribute::MAYBEVOID, 0 },
142 : { "BaseURI", sizeof("BaseURI")-1, 0,
143 0 : &::getCppuType( (OUString *)0 ),
144 : beans::PropertyAttribute::MAYBEVOID, 0 },
145 : { "StreamRelPath", sizeof("StreamRelPath")-1, 0,
146 0 : &::getCppuType( (OUString *)0 ),
147 : beans::PropertyAttribute::MAYBEVOID, 0 },
148 : { "StreamName", sizeof("StreamName")-1, 0,
149 0 : &::getCppuType( (OUString *)0 ),
150 : beans::PropertyAttribute::MAYBEVOID, 0 },
151 : { NULL, 0, 0, NULL, 0, 0 }
152 0 : };
153 : uno::Reference< beans::XPropertySet > xInfoSet(
154 : comphelper::GenericPropertySet_CreateInstance(
155 0 : new comphelper::PropertySetInfo( aInfoMap ) ) );
156 :
157 : // Set base URI
158 0 : OUString sPropName( "BaseURI" );
159 0 : xInfoSet->setPropertyValue( sPropName, makeAny( rMedium.GetBaseURL() ) );
160 :
161 0 : sal_Int32 nSteps=3;
162 0 : if ( !(rMedium.IsStorage()))
163 0 : nSteps = 1;
164 :
165 0 : sal_Int32 nProgressRange(nSteps);
166 0 : if (xStatusIndicator.is())
167 : {
168 0 : xStatusIndicator->start(SM_RESSTR(STR_STATSTR_READING), nProgressRange);
169 : }
170 :
171 0 : nSteps=0;
172 0 : if (xStatusIndicator.is())
173 0 : xStatusIndicator->setValue(nSteps++);
174 :
175 0 : if ( rMedium.IsStorage())
176 : {
177 : // TODO/LATER: handle the case of embedded links gracefully
178 0 : if ( bEmbedded ) // && !rMedium.GetStorage()->IsRoot() )
179 : {
180 0 : OUString aName( "dummyObjName" );
181 0 : if ( rMedium.GetItemSet() )
182 : {
183 : const SfxStringItem* pDocHierarchItem = static_cast<const SfxStringItem*>(
184 0 : rMedium.GetItemSet()->GetItem(SID_DOC_HIERARCHICALNAME) );
185 0 : if ( pDocHierarchItem )
186 0 : aName = pDocHierarchItem->GetValue();
187 : }
188 :
189 0 : if ( !aName.isEmpty() )
190 : {
191 0 : sPropName = "StreamRelPath";
192 0 : xInfoSet->setPropertyValue( sPropName, makeAny( aName ) );
193 0 : }
194 : }
195 :
196 0 : sal_Bool bOASIS = ( SotStorage::GetVersion( rMedium.GetStorage() ) > SOFFICE_FILEFORMAT_60 );
197 0 : if (xStatusIndicator.is())
198 0 : xStatusIndicator->setValue(nSteps++);
199 :
200 : sal_uLong nWarn = ReadThroughComponent(
201 : rMedium.GetStorage(), xModelComp, "meta.xml", "Meta.xml",
202 : xContext, xInfoSet,
203 : (bOASIS ? "com.sun.star.comp.Math.XMLOasisMetaImporter"
204 0 : : "com.sun.star.comp.Math.XMLMetaImporter") );
205 :
206 0 : if ( nWarn != ERRCODE_IO_BROKENPACKAGE )
207 : {
208 0 : if (xStatusIndicator.is())
209 0 : xStatusIndicator->setValue(nSteps++);
210 :
211 : nWarn = ReadThroughComponent(
212 : rMedium.GetStorage(), xModelComp, "settings.xml", 0,
213 : xContext, xInfoSet,
214 : (bOASIS ? "com.sun.star.comp.Math.XMLOasisSettingsImporter"
215 0 : : "com.sun.star.comp.Math.XMLSettingsImporter" ) );
216 :
217 0 : if ( nWarn != ERRCODE_IO_BROKENPACKAGE )
218 : {
219 0 : if (xStatusIndicator.is())
220 0 : xStatusIndicator->setValue(nSteps++);
221 :
222 : nError = ReadThroughComponent(
223 : rMedium.GetStorage(), xModelComp, "content.xml", "Content.xml",
224 0 : xContext, xInfoSet, "com.sun.star.comp.Math.XMLImporter" );
225 : }
226 : else
227 0 : nError = ERRCODE_IO_BROKENPACKAGE;
228 : }
229 : else
230 0 : nError = ERRCODE_IO_BROKENPACKAGE;
231 : }
232 : else
233 : {
234 : Reference<io::XInputStream> xInputStream =
235 0 : new utl::OInputStreamWrapper(rMedium.GetInStream());
236 :
237 0 : if (xStatusIndicator.is())
238 0 : xStatusIndicator->setValue(nSteps++);
239 :
240 : nError = ReadThroughComponent( xInputStream, xModelComp,
241 0 : xContext, xInfoSet, "com.sun.star.comp.Math.XMLImporter", false );
242 : }
243 :
244 0 : if (xStatusIndicator.is())
245 0 : xStatusIndicator->end();
246 0 : return nError;
247 : }
248 :
249 :
250 : /// read a component (file + filter version)
251 0 : sal_uLong SmXMLImportWrapper::ReadThroughComponent(
252 : Reference<io::XInputStream> xInputStream,
253 : Reference<XComponent> xModelComponent,
254 : Reference<uno::XComponentContext> & rxContext,
255 : Reference<beans::XPropertySet> & rPropSet,
256 : const sal_Char* pFilterName,
257 : sal_Bool bEncrypted )
258 : {
259 0 : sal_uLong nError = ERRCODE_SFX_DOLOADFAILED;
260 : OSL_ENSURE(xInputStream.is(), "input stream missing");
261 : OSL_ENSURE(xModelComponent.is(), "document missing");
262 : OSL_ENSURE(rxContext.is(), "factory missing");
263 : OSL_ENSURE(NULL != pFilterName,"I need a service name for the component!");
264 :
265 : // prepare ParserInputSrouce
266 0 : xml::sax::InputSource aParserInput;
267 0 : aParserInput.aInputStream = xInputStream;
268 :
269 : // get parser
270 0 : Reference< xml::sax::XParser > xParser = xml::sax::Parser::create(rxContext);
271 :
272 0 : Sequence<Any> aArgs( 1 );
273 0 : aArgs[0] <<= rPropSet;
274 :
275 : // get filter
276 : Reference< xml::sax::XDocumentHandler > xFilter(
277 0 : rxContext->getServiceManager()->createInstanceWithArgumentsAndContext(
278 0 : OUString::createFromAscii(pFilterName), aArgs, rxContext),
279 0 : UNO_QUERY );
280 : OSL_ENSURE( xFilter.is(), "Can't instantiate filter component." );
281 0 : if ( !xFilter.is() )
282 0 : return nError;
283 :
284 : // connect parser and filter
285 0 : xParser->setDocumentHandler( xFilter );
286 :
287 : // connect model and filter
288 0 : Reference < XImporter > xImporter( xFilter, UNO_QUERY );
289 0 : xImporter->setTargetDocument( xModelComponent );
290 :
291 : // finally, parser the stream
292 : try
293 : {
294 0 : xParser->parseStream( aParserInput );
295 :
296 0 : uno::Reference<lang::XUnoTunnel> xFilterTunnel;
297 0 : xFilterTunnel = uno::Reference<lang::XUnoTunnel>
298 0 : ( xFilter, uno::UNO_QUERY );
299 : SmXMLImport *pFilter = reinterpret_cast< SmXMLImport * >(
300 : sal::static_int_cast< sal_uIntPtr >(
301 0 : xFilterTunnel->getSomething( SmXMLImport::getUnoTunnelId() )));
302 0 : if ( pFilter && pFilter->GetSuccess() )
303 0 : nError = 0;
304 : }
305 0 : catch( xml::sax::SAXParseException& r )
306 : {
307 : // sax parser sends wrapped exceptions,
308 : // try to find the original one
309 0 : xml::sax::SAXException aSaxEx = *(xml::sax::SAXException*)(&r);
310 0 : sal_Bool bTryChild = sal_True;
311 :
312 0 : while( bTryChild )
313 : {
314 0 : xml::sax::SAXException aTmp;
315 0 : if ( aSaxEx.WrappedException >>= aTmp )
316 0 : aSaxEx = aTmp;
317 : else
318 0 : bTryChild = sal_False;
319 0 : }
320 :
321 0 : packages::zip::ZipIOException aBrokenPackage;
322 0 : if ( aSaxEx.WrappedException >>= aBrokenPackage )
323 0 : return ERRCODE_IO_BROKENPACKAGE;
324 :
325 0 : if ( bEncrypted )
326 0 : nError = ERRCODE_SFX_WRONGPASSWORD;
327 0 : }
328 0 : catch( const xml::sax::SAXException& r )
329 : {
330 0 : packages::zip::ZipIOException aBrokenPackage;
331 0 : if ( r.WrappedException >>= aBrokenPackage )
332 0 : return ERRCODE_IO_BROKENPACKAGE;
333 :
334 0 : if ( bEncrypted )
335 0 : nError = ERRCODE_SFX_WRONGPASSWORD;
336 0 : }
337 0 : catch( packages::zip::ZipIOException& )
338 : {
339 0 : nError = ERRCODE_IO_BROKENPACKAGE;
340 : }
341 0 : catch( io::IOException& )
342 : {
343 : }
344 :
345 0 : return nError;
346 : }
347 :
348 :
349 0 : sal_uLong SmXMLImportWrapper::ReadThroughComponent(
350 : const uno::Reference< embed::XStorage >& xStorage,
351 : Reference<XComponent> xModelComponent,
352 : const sal_Char* pStreamName,
353 : const sal_Char* pCompatibilityStreamName,
354 : Reference<uno::XComponentContext> & rxContext,
355 : Reference<beans::XPropertySet> & rPropSet,
356 : const sal_Char* pFilterName )
357 : {
358 : OSL_ENSURE(xStorage.is(), "Need storage!");
359 : OSL_ENSURE(NULL != pStreamName, "Please, please, give me a name!");
360 :
361 : // open stream (and set parser input)
362 0 : OUString sStreamName = OUString::createFromAscii(pStreamName);
363 0 : uno::Reference < container::XNameAccess > xAccess( xStorage, uno::UNO_QUERY );
364 0 : if ( !xAccess->hasByName(sStreamName) || !xStorage->isStreamElement(sStreamName) )
365 : {
366 : // stream name not found! Then try the compatibility name.
367 : // do we even have an alternative name?
368 0 : if ( pCompatibilityStreamName )
369 0 : sStreamName = OUString::createFromAscii(pCompatibilityStreamName);
370 : }
371 :
372 : // get input stream
373 : try
374 : {
375 0 : uno::Reference < io::XStream > xEventsStream = xStorage->openStreamElement( sStreamName, embed::ElementModes::READ );
376 :
377 : // determine if stream is encrypted or not
378 0 : uno::Reference < beans::XPropertySet > xProps( xEventsStream, uno::UNO_QUERY );
379 0 : Any aAny = xProps->getPropertyValue( "Encrypted" );
380 0 : sal_Bool bEncrypted = sal_False;
381 0 : if ( aAny.getValueType() == ::getBooleanCppuType() )
382 0 : aAny >>= bEncrypted;
383 :
384 : // set Base URL
385 0 : if ( rPropSet.is() )
386 : {
387 0 : OUString sPropName( "StreamName");
388 0 : rPropSet->setPropertyValue( sPropName, makeAny( sStreamName ) );
389 : }
390 :
391 :
392 0 : Reference < io::XInputStream > xStream = xEventsStream->getInputStream();
393 0 : return ReadThroughComponent( xStream, xModelComponent, rxContext, rPropSet, pFilterName, bEncrypted );
394 : }
395 0 : catch ( packages::WrongPasswordException& )
396 : {
397 0 : return ERRCODE_SFX_WRONGPASSWORD;
398 : }
399 0 : catch( packages::zip::ZipIOException& )
400 : {
401 0 : return ERRCODE_IO_BROKENPACKAGE;
402 : }
403 0 : catch ( uno::Exception& )
404 : {
405 : }
406 :
407 0 : return ERRCODE_SFX_DOLOADFAILED;
408 : }
409 :
410 : ////////////////////////////////////////////////////////////
411 :
412 6 : SmXMLImport::SmXMLImport(
413 : const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > xContext,
414 : sal_uInt16 nImportFlags)
415 : : SvXMLImport( xContext, nImportFlags ),
416 : pPresLayoutElemTokenMap(0),
417 : pPresLayoutAttrTokenMap(0),
418 : pFencedAttrTokenMap(0),
419 : pOperatorAttrTokenMap(0),
420 : pAnnotationAttrTokenMap(0),
421 : pPresElemTokenMap(0),
422 : pPresScriptEmptyElemTokenMap(0),
423 : pPresTableElemTokenMap(0),
424 : pColorTokenMap(0),
425 6 : bSuccess(sal_False)
426 : {
427 6 : }
428 :
429 : namespace
430 : {
431 : class theSmXMLImportUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theSmXMLImportUnoTunnelId> {};
432 : }
433 :
434 0 : const uno::Sequence< sal_Int8 > & SmXMLImport::getUnoTunnelId() throw()
435 : {
436 0 : return theSmXMLImportUnoTunnelId::get().getSeq();
437 : }
438 :
439 21 : OUString SAL_CALL SmXMLImport_getImplementationName() throw()
440 : {
441 21 : return OUString( "com.sun.star.comp.Math.XMLImporter" );
442 : }
443 :
444 1 : uno::Sequence< OUString > SAL_CALL SmXMLImport_getSupportedServiceNames()
445 : throw()
446 : {
447 1 : const OUString aServiceName( IMPORT_SVC_NAME );
448 1 : const uno::Sequence< OUString > aSeq( &aServiceName, 1 );
449 1 : return aSeq;
450 : }
451 :
452 2 : uno::Reference< uno::XInterface > SAL_CALL SmXMLImport_createInstance(
453 : const uno::Reference< lang::XMultiServiceFactory > & rSMgr)
454 : throw( uno::Exception )
455 : {
456 2 : return (cppu::OWeakObject*)new SmXMLImport(comphelper::getComponentContext(rSMgr), IMPORT_ALL);
457 : }
458 :
459 : ////////////////////////////////////////////////////////////
460 :
461 19 : OUString SAL_CALL SmXMLImportMeta_getImplementationName() throw()
462 : {
463 19 : return OUString( "com.sun.star.comp.Math.XMLOasisMetaImporter" );
464 : }
465 :
466 1 : uno::Sequence< OUString > SAL_CALL SmXMLImportMeta_getSupportedServiceNames()
467 : throw()
468 : {
469 1 : const OUString aServiceName( IMPORT_SVC_NAME );
470 1 : const uno::Sequence< OUString > aSeq( &aServiceName, 1 );
471 1 : return aSeq;
472 : }
473 :
474 2 : uno::Reference< uno::XInterface > SAL_CALL SmXMLImportMeta_createInstance(
475 : const uno::Reference< lang::XMultiServiceFactory > & rSMgr)
476 : throw( uno::Exception )
477 : {
478 2 : return (cppu::OWeakObject*)new SmXMLImport( comphelper::getComponentContext(rSMgr), IMPORT_META );
479 : }
480 :
481 : ////////////////////////////////////////////////////////////
482 :
483 17 : OUString SAL_CALL SmXMLImportSettings_getImplementationName() throw()
484 : {
485 17 : return OUString( "com.sun.star.comp.Math.XMLOasisSettingsImporter" );
486 : }
487 :
488 1 : uno::Sequence< OUString > SAL_CALL SmXMLImportSettings_getSupportedServiceNames()
489 : throw()
490 : {
491 1 : const OUString aServiceName( IMPORT_SVC_NAME );
492 1 : const uno::Sequence< OUString > aSeq( &aServiceName, 1 );
493 1 : return aSeq;
494 : }
495 :
496 2 : uno::Reference< uno::XInterface > SAL_CALL SmXMLImportSettings_createInstance(
497 : const uno::Reference< lang::XMultiServiceFactory > & rSMgr)
498 : throw( uno::Exception )
499 : {
500 2 : return (cppu::OWeakObject*)new SmXMLImport( comphelper::getComponentContext(rSMgr), IMPORT_SETTINGS );
501 : }
502 :
503 : ////////////////////////////////////////////////////////////
504 :
505 : // XServiceInfo
506 : // override empty method from parent class
507 0 : OUString SAL_CALL SmXMLImport::getImplementationName()
508 : throw(uno::RuntimeException)
509 : {
510 0 : OUString aTxt;
511 0 : switch( getImportFlags() )
512 : {
513 : case IMPORT_META:
514 0 : aTxt = SmXMLImportMeta_getImplementationName();
515 0 : break;
516 : case IMPORT_SETTINGS:
517 0 : aTxt = SmXMLImportSettings_getImplementationName();
518 0 : break;
519 : case IMPORT_ALL:
520 : default:
521 0 : aTxt = SmXMLImport_getImplementationName();
522 0 : break;
523 : }
524 0 : return aTxt;
525 : }
526 :
527 :
528 0 : sal_Int64 SAL_CALL SmXMLImport::getSomething(
529 : const uno::Sequence< sal_Int8 >&rId )
530 : throw(uno::RuntimeException)
531 : {
532 0 : if ( rId.getLength() == 16 &&
533 0 : 0 == memcmp( getUnoTunnelId().getConstArray(),
534 0 : rId.getConstArray(), 16 ) )
535 0 : return sal::static_int_cast< sal_Int64 >(reinterpret_cast< sal_uIntPtr >(this));
536 :
537 0 : return SvXMLImport::getSomething( rId );
538 : }
539 :
540 0 : void SmXMLImport::endDocument(void)
541 : throw(xml::sax::SAXException, uno::RuntimeException)
542 : {
543 : //Set the resulted tree into the SmDocShell where it belongs
544 : SmNode *pTree;
545 0 : if (NULL != (pTree = GetTree()))
546 : {
547 0 : uno::Reference <frame::XModel> xModel = GetModel();
548 0 : uno::Reference <lang::XUnoTunnel> xTunnel;
549 0 : xTunnel = uno::Reference <lang::XUnoTunnel> (xModel,uno::UNO_QUERY);
550 : SmModel *pModel = reinterpret_cast<SmModel *>
551 0 : (xTunnel->getSomething(SmModel::getUnoTunnelId()));
552 :
553 0 : if (pModel)
554 : {
555 : SmDocShell *pDocShell =
556 0 : static_cast<SmDocShell*>(pModel->GetObjectShell());
557 0 : pDocShell->SetFormulaTree(pTree);
558 0 : if (0 == aText.Len()) //If we picked up no annotation text
559 : {
560 : // Get text from imported formula
561 0 : pTree->CreateTextFromNode(aText);
562 0 : aText = comphelper::string::stripEnd(aText, ' ');
563 : }
564 :
565 : // Convert symbol names
566 0 : SmParser &rParser = pDocShell->GetParser();
567 0 : bool bVal = rParser.IsImportSymbolNames();
568 0 : rParser.SetImportSymbolNames( true );
569 0 : SmNode *pTmpTree = rParser.Parse( aText );
570 0 : aText = rParser.GetText();
571 0 : delete pTmpTree;
572 0 : rParser.SetImportSymbolNames( bVal );
573 :
574 0 : pDocShell->SetText( aText );
575 : }
576 : OSL_ENSURE(pModel,"So there *was* a uno problem after all");
577 :
578 0 : bSuccess = sal_True;
579 : }
580 :
581 0 : SvXMLImport::endDocument();
582 0 : }
583 :
584 : ////////////////////////////////////////////////////////////
585 :
586 0 : class SmXMLImportContext: public SvXMLImportContext
587 : {
588 : public:
589 0 : SmXMLImportContext( SmXMLImport &rImport, sal_uInt16 nPrfx,
590 : const OUString& rLName)
591 0 : : SvXMLImportContext(rImport, nPrfx, rLName) {}
592 :
593 : const SmXMLImport& GetSmImport() const
594 : {
595 : return (const SmXMLImport&)GetImport();
596 : }
597 :
598 0 : SmXMLImport& GetSmImport()
599 : {
600 0 : return (SmXMLImport&)GetImport();
601 : }
602 :
603 : virtual void TCharacters(const OUString & /*rChars*/);
604 : virtual void Characters(const OUString &rChars);
605 : virtual SvXMLImportContext *CreateChildContext(sal_uInt16 /*nPrefix*/, const OUString& /*rLocalName*/, const uno::Reference< xml::sax::XAttributeList > & /*xAttrList*/);
606 : };
607 :
608 0 : void SmXMLImportContext::TCharacters(const OUString & /*rChars*/)
609 : {
610 0 : }
611 :
612 0 : void SmXMLImportContext::Characters(const OUString &rChars)
613 : {
614 : /*
615 : Whitespace occurring within the content of token elements is "trimmed"
616 : from the ends (i.e. all whitespace at the beginning and end of the
617 : content is removed), and "collapsed" internally (i.e. each sequence of
618 : 1 or more whitespace characters is replaced with one blank character).
619 : */
620 : //collapsing not done yet!
621 0 : const OUString &rChars2 = rChars.trim();
622 0 : if (!rChars2.isEmpty())
623 0 : TCharacters(rChars2/*.collapse()*/);
624 0 : }
625 :
626 0 : SvXMLImportContext * SmXMLImportContext::CreateChildContext(sal_uInt16 /*nPrefix*/,
627 : const OUString& /*rLocalName*/,
628 : const uno::Reference< xml::sax::XAttributeList > & /*xAttrList*/)
629 : {
630 0 : return 0;
631 : }
632 :
633 : ////////////////////////////////////////////////////////////
634 :
635 0 : struct SmXMLContext_Helper
636 : {
637 : sal_Int8 nIsBold;
638 : sal_Int8 nIsItalic;
639 : double nFontSize;
640 : sal_Bool bFontNodeNeeded;
641 : OUString sFontFamily;
642 : OUString sColor;
643 :
644 : SmXMLImportContext rContext;
645 :
646 0 : SmXMLContext_Helper(SmXMLImportContext &rImport) :
647 0 : nIsBold(-1), nIsItalic(-1), nFontSize(0.0), rContext(rImport) {}
648 :
649 : void RetrieveAttrs(const uno::Reference< xml::sax::XAttributeList > &xAttrList );
650 : void ApplyAttrs();
651 : };
652 :
653 0 : void SmXMLContext_Helper::RetrieveAttrs(const uno::Reference<
654 : xml::sax::XAttributeList > & xAttrList )
655 : {
656 0 : sal_Int8 nOldIsBold=nIsBold;
657 0 : sal_Int8 nOldIsItalic=nIsItalic;
658 0 : double nOldFontSize=nFontSize;
659 0 : sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
660 0 : OUString sOldFontFamily = sFontFamily;
661 0 : for (sal_Int16 i=0;i<nAttrCount;i++)
662 : {
663 0 : OUString sAttrName = xAttrList->getNameByIndex(i);
664 0 : OUString aLocalName;
665 0 : sal_uInt16 nPrefix = rContext.GetSmImport().GetNamespaceMap().
666 0 : GetKeyByAttrName(sAttrName,&aLocalName);
667 0 : OUString sValue = xAttrList->getValueByIndex(i);
668 : const SvXMLTokenMap &rAttrTokenMap =
669 0 : rContext.GetSmImport().GetPresLayoutAttrTokenMap();
670 0 : switch(rAttrTokenMap.Get(nPrefix,aLocalName))
671 : {
672 : case XML_TOK_FONTWEIGHT:
673 0 : nIsBold = sValue.equals(GetXMLToken(XML_BOLD));
674 0 : break;
675 : case XML_TOK_FONTSTYLE:
676 0 : nIsItalic = sValue.equals(GetXMLToken(XML_ITALIC));
677 0 : break;
678 : case XML_TOK_FONTSIZE:
679 0 : ::sax::Converter::convertDouble(nFontSize, sValue);
680 0 : rContext.GetSmImport().GetMM100UnitConverter().
681 0 : SetXMLMeasureUnit(util::MeasureUnit::POINT);
682 0 : if (-1 == sValue.indexOf(GetXMLToken(XML_UNIT_PT)))
683 : {
684 0 : if (-1 == sValue.indexOf('%'))
685 0 : nFontSize=0.0;
686 : else
687 : {
688 0 : rContext.GetSmImport().GetMM100UnitConverter().
689 0 : SetXMLMeasureUnit(util::MeasureUnit::PERCENT);
690 : }
691 : }
692 0 : break;
693 : case XML_TOK_FONTFAMILY:
694 0 : sFontFamily = sValue;
695 0 : break;
696 : case XML_TOK_COLOR:
697 0 : sColor = sValue;
698 0 : break;
699 : default:
700 0 : break;
701 : }
702 0 : }
703 :
704 0 : if ((nOldIsBold!=nIsBold) || (nOldIsItalic!=nIsItalic) ||
705 0 : (nOldFontSize!=nFontSize) || (sOldFontFamily!=sFontFamily)
706 0 : || !sColor.isEmpty())
707 0 : bFontNodeNeeded=sal_True;
708 : else
709 0 : bFontNodeNeeded=sal_False;
710 0 : }
711 :
712 0 : void SmXMLContext_Helper::ApplyAttrs()
713 : {
714 0 : SmNodeStack &rNodeStack = rContext.GetSmImport().GetNodeStack();
715 :
716 0 : if (bFontNodeNeeded)
717 : {
718 0 : SmToken aToken;
719 0 : aToken.cMathChar = '\0';
720 0 : aToken.nLevel = 5;
721 :
722 0 : if (nIsBold != -1)
723 : {
724 0 : if (nIsBold)
725 0 : aToken.eType = TBOLD;
726 : else
727 0 : aToken.eType = TNBOLD;
728 : SmStructureNode *pFontNode = static_cast<SmStructureNode *>
729 0 : (new SmFontNode(aToken));
730 0 : pFontNode->SetSubNodes(0,lcl_popOrZero(rNodeStack));
731 0 : rNodeStack.push(pFontNode);
732 : }
733 0 : if (nIsItalic != -1)
734 : {
735 0 : if (nIsItalic)
736 0 : aToken.eType = TITALIC;
737 : else
738 0 : aToken.eType = TNITALIC;
739 : SmStructureNode *pFontNode = static_cast<SmStructureNode *>
740 0 : (new SmFontNode(aToken));
741 0 : pFontNode->SetSubNodes(0,lcl_popOrZero(rNodeStack));
742 0 : rNodeStack.push(pFontNode);
743 : }
744 0 : if (nFontSize != 0.0)
745 : {
746 0 : aToken.eType = TSIZE;
747 0 : SmFontNode *pFontNode = new SmFontNode(aToken);
748 :
749 0 : if (util::MeasureUnit::PERCENT == rContext.GetSmImport()
750 0 : .GetMM100UnitConverter().GetXMLMeasureUnit())
751 : {
752 0 : if (nFontSize < 100.00)
753 : pFontNode->SetSizeParameter(Fraction(100.00/nFontSize),
754 0 : FNTSIZ_DIVIDE);
755 : else
756 : pFontNode->SetSizeParameter(Fraction(nFontSize/100.00),
757 0 : FNTSIZ_MULTIPLY);
758 : }
759 : else
760 0 : pFontNode->SetSizeParameter(Fraction(nFontSize),FNTSIZ_ABSOLUT);
761 :
762 0 : pFontNode->SetSubNodes(0,lcl_popOrZero(rNodeStack));
763 0 : rNodeStack.push(pFontNode);
764 : }
765 0 : if (!sFontFamily.isEmpty())
766 : {
767 0 : if (sFontFamily.equalsIgnoreAsciiCase(GetXMLToken(XML_FIXED)))
768 0 : aToken.eType = TFIXED;
769 0 : else if (sFontFamily.equalsIgnoreAsciiCase("sans"))
770 0 : aToken.eType = TSANS;
771 0 : else if (sFontFamily.equalsIgnoreAsciiCase("serif"))
772 0 : aToken.eType = TSERIF;
773 : else //Just give up, we need to extend our font mechanism to be
774 : //more general
775 0 : return;
776 :
777 0 : aToken.aText = sFontFamily;
778 0 : SmFontNode *pFontNode = new SmFontNode(aToken);
779 0 : pFontNode->SetSubNodes(0,lcl_popOrZero(rNodeStack));
780 0 : rNodeStack.push(pFontNode);
781 : }
782 0 : if (!sColor.isEmpty())
783 : {
784 : //Again we can only handle a small set of colours in
785 : //StarMath for now.
786 : const SvXMLTokenMap& rTokenMap =
787 0 : rContext.GetSmImport().GetColorTokenMap();
788 0 : sal_uInt16 tok = rTokenMap.Get(XML_NAMESPACE_MATH, sColor);
789 0 : if (tok != XML_TOK_UNKNOWN)
790 : {
791 0 : aToken.eType = static_cast<SmTokenType>(tok);
792 0 : SmFontNode *pFontNode = new SmFontNode(aToken);
793 0 : pFontNode->SetSubNodes(0,lcl_popOrZero(rNodeStack));
794 0 : rNodeStack.push(pFontNode);
795 : }
796 0 : }
797 :
798 : }
799 : }
800 :
801 : ////////////////////////////////////////////////////////////
802 :
803 0 : class SmXMLDocContext_Impl : public SmXMLImportContext
804 : {
805 : public:
806 0 : SmXMLDocContext_Impl( SmXMLImport &rImport, sal_uInt16 nPrfx,
807 : const OUString& rLName)
808 0 : : SmXMLImportContext(rImport,nPrfx,rLName) {}
809 :
810 : virtual SvXMLImportContext *CreateChildContext(sal_uInt16 nPrefix, const OUString& rLocalName, const uno::Reference< xml::sax::XAttributeList > &xAttrList);
811 :
812 : void EndElement();
813 : };
814 :
815 : ////////////////////////////////////////////////////////////
816 :
817 : /*avert thy gaze from the proginator*/
818 0 : class SmXMLRowContext_Impl : public SmXMLDocContext_Impl
819 : {
820 : protected:
821 : sal_uLong nElementCount;
822 :
823 : public:
824 0 : SmXMLRowContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix,
825 : const OUString& rLName)
826 0 : : SmXMLDocContext_Impl(rImport,nPrefix,rLName)
827 0 : { nElementCount = GetSmImport().GetNodeStack().size(); }
828 :
829 : virtual SvXMLImportContext *CreateChildContext(sal_uInt16 nPrefix, const OUString& rLocalName, const uno::Reference< xml::sax::XAttributeList > &xAttrList);
830 :
831 : SvXMLImportContext *StrictCreateChildContext(sal_uInt16 nPrefix,
832 : const OUString& rLocalName,
833 : const uno::Reference< xml::sax::XAttributeList > &xAttrList);
834 :
835 : void EndElement();
836 : };
837 :
838 : ////////////////////////////////////////////////////////////
839 :
840 0 : class SmXMLEncloseContext_Impl : public SmXMLRowContext_Impl
841 : {
842 : public:
843 : // TODO/LATER: convert <menclose notation="horizontalstrike"> into
844 : // "overstrike{}" and extend the Math syntax to support more notations
845 0 : SmXMLEncloseContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix,
846 : const OUString& rLName)
847 0 : : SmXMLRowContext_Impl(rImport,nPrefix,rLName) {}
848 :
849 : void EndElement();
850 : };
851 :
852 0 : void SmXMLEncloseContext_Impl::EndElement()
853 : {
854 : /*
855 : <menclose> accepts any number of arguments; if this number is not 1, its
856 : contents are treated as a single "inferred <mrow>" containing its
857 : arguments
858 : */
859 0 : if (GetSmImport().GetNodeStack().size() - nElementCount > 1)
860 0 : SmXMLRowContext_Impl::EndElement();
861 0 : }
862 :
863 : ////////////////////////////////////////////////////////////
864 :
865 0 : class SmXMLFracContext_Impl : public SmXMLRowContext_Impl
866 : {
867 : public:
868 : // TODO/LATER: convert <mfrac bevelled="true"> into "wideslash{}{}"
869 0 : SmXMLFracContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix,
870 : const OUString& rLName)
871 0 : : SmXMLRowContext_Impl(rImport,nPrefix,rLName) {}
872 :
873 : void EndElement();
874 : };
875 :
876 : ////////////////////////////////////////////////////////////
877 :
878 0 : class SmXMLSqrtContext_Impl : public SmXMLRowContext_Impl
879 : {
880 : public:
881 0 : SmXMLSqrtContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix,
882 : const OUString& rLName)
883 0 : : SmXMLRowContext_Impl(rImport,nPrefix,rLName) {}
884 :
885 : void EndElement();
886 : };
887 :
888 : ////////////////////////////////////////////////////////////
889 :
890 0 : class SmXMLRootContext_Impl : public SmXMLRowContext_Impl
891 : {
892 : public:
893 0 : SmXMLRootContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix,
894 : const OUString& rLName)
895 0 : : SmXMLRowContext_Impl(rImport,nPrefix,rLName) {}
896 :
897 : void EndElement();
898 : };
899 :
900 : ////////////////////////////////////////////////////////////
901 :
902 0 : class SmXMLStyleContext_Impl : public SmXMLRowContext_Impl
903 : {
904 : protected:
905 : SmXMLContext_Helper aStyleHelper;
906 :
907 : public:
908 : /*Right now the style tag is completely ignored*/
909 0 : SmXMLStyleContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix,
910 : const OUString& rLName) : SmXMLRowContext_Impl(rImport,nPrefix,rLName),
911 0 : aStyleHelper(*this) {}
912 :
913 : void EndElement();
914 : void StartElement(const uno::Reference< xml::sax::XAttributeList > &xAttrList );
915 : };
916 :
917 0 : void SmXMLStyleContext_Impl::StartElement(const uno::Reference<
918 : xml::sax::XAttributeList > & xAttrList )
919 : {
920 0 : aStyleHelper.RetrieveAttrs(xAttrList);
921 0 : }
922 :
923 :
924 0 : void SmXMLStyleContext_Impl::EndElement()
925 : {
926 : /*
927 : <mstyle> accepts any number of arguments; if this number is not 1, its
928 : contents are treated as a single "inferred <mrow>" containing its
929 : arguments
930 : */
931 0 : SmNodeStack &rNodeStack = GetSmImport().GetNodeStack();
932 0 : if (rNodeStack.size() - nElementCount > 1)
933 0 : SmXMLRowContext_Impl::EndElement();
934 0 : aStyleHelper.ApplyAttrs();
935 0 : }
936 :
937 : ////////////////////////////////////////////////////////////
938 :
939 0 : class SmXMLPaddedContext_Impl : public SmXMLRowContext_Impl
940 : {
941 : public:
942 : /*Right now the style tag is completely ignored*/
943 0 : SmXMLPaddedContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix,
944 : const OUString& rLName)
945 0 : : SmXMLRowContext_Impl(rImport,nPrefix,rLName) {}
946 :
947 : void EndElement();
948 : };
949 :
950 0 : void SmXMLPaddedContext_Impl::EndElement()
951 : {
952 : /*
953 : <mpadded> accepts any number of arguments; if this number is not 1, its
954 : contents are treated as a single "inferred <mrow>" containing its
955 : arguments
956 : */
957 0 : if (GetSmImport().GetNodeStack().size() - nElementCount > 1)
958 0 : SmXMLRowContext_Impl::EndElement();
959 0 : }
960 :
961 : ////////////////////////////////////////////////////////////
962 :
963 0 : class SmXMLPhantomContext_Impl : public SmXMLRowContext_Impl
964 : {
965 : public:
966 : /*Right now the style tag is completely ignored*/
967 0 : SmXMLPhantomContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix,
968 : const OUString& rLName)
969 0 : : SmXMLRowContext_Impl(rImport,nPrefix,rLName) {}
970 :
971 : void EndElement();
972 : };
973 :
974 0 : void SmXMLPhantomContext_Impl::EndElement()
975 : {
976 : /*
977 : <mphantom> accepts any number of arguments; if this number is not 1, its
978 : contents are treated as a single "inferred <mrow>" containing its
979 : arguments
980 : */
981 0 : if (GetSmImport().GetNodeStack().size() - nElementCount > 1)
982 0 : SmXMLRowContext_Impl::EndElement();
983 :
984 0 : SmToken aToken;
985 0 : aToken.cMathChar = '\0';
986 0 : aToken.nLevel = 5;
987 0 : aToken.eType = TPHANTOM;
988 :
989 : SmStructureNode *pPhantom = static_cast<SmStructureNode *>
990 0 : (new SmFontNode(aToken));
991 0 : SmNodeStack &rNodeStack = GetSmImport().GetNodeStack();
992 0 : pPhantom->SetSubNodes(0,lcl_popOrZero(rNodeStack));
993 0 : rNodeStack.push(pPhantom);
994 0 : }
995 :
996 : ////////////////////////////////////////////////////////////
997 :
998 0 : class SmXMLFencedContext_Impl : public SmXMLRowContext_Impl
999 : {
1000 : protected:
1001 : sal_Unicode cBegin;
1002 : sal_Unicode cEnd;
1003 :
1004 : public:
1005 0 : SmXMLFencedContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix,
1006 : const OUString& rLName)
1007 : : SmXMLRowContext_Impl(rImport,nPrefix,rLName),
1008 0 : cBegin('('), cEnd(')') {}
1009 :
1010 : void StartElement(const uno::Reference< xml::sax::XAttributeList > & xAttrList );
1011 : void EndElement();
1012 : };
1013 :
1014 :
1015 0 : void SmXMLFencedContext_Impl::StartElement(const uno::Reference<
1016 : xml::sax::XAttributeList > & xAttrList )
1017 : {
1018 0 : sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
1019 0 : for (sal_Int16 i=0;i<nAttrCount;i++)
1020 : {
1021 0 : OUString sAttrName = xAttrList->getNameByIndex(i);
1022 0 : OUString aLocalName;
1023 0 : sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
1024 0 : GetKeyByAttrName(sAttrName,&aLocalName);
1025 0 : OUString sValue = xAttrList->getValueByIndex(i);
1026 : const SvXMLTokenMap &rAttrTokenMap =
1027 0 : GetSmImport().GetFencedAttrTokenMap();
1028 0 : switch(rAttrTokenMap.Get(nPrefix,aLocalName))
1029 : {
1030 : //temp, starmath cannot handle multichar brackets (I think)
1031 : case XML_TOK_OPEN:
1032 0 : cBegin = sValue[0];
1033 0 : break;
1034 : case XML_TOK_CLOSE:
1035 0 : cEnd = sValue[0];
1036 0 : break;
1037 : default:
1038 : /*Go to superclass*/
1039 0 : break;
1040 : }
1041 0 : }
1042 0 : }
1043 :
1044 :
1045 0 : void SmXMLFencedContext_Impl::EndElement()
1046 : {
1047 0 : SmToken aToken;
1048 0 : aToken.cMathChar = '\0';
1049 0 : aToken.aText = ",";
1050 0 : aToken.eType = TLEFT;
1051 0 : aToken.nLevel = 5;
1052 :
1053 0 : aToken.eType = TLPARENT;
1054 0 : aToken.cMathChar = cBegin;
1055 0 : SmStructureNode *pSNode = new SmBraceNode(aToken);
1056 0 : SmNode *pLeft = new SmMathSymbolNode(aToken);
1057 :
1058 0 : aToken.cMathChar = cEnd;
1059 0 : aToken.eType = TRPARENT;
1060 0 : SmNode *pRight = new SmMathSymbolNode(aToken);
1061 :
1062 0 : SmNodeArray aRelationArray;
1063 0 : SmNodeStack &rNodeStack = GetSmImport().GetNodeStack();
1064 :
1065 0 : aToken.cMathChar = '\0';
1066 0 : aToken.aText = ",";
1067 0 : aToken.eType = TIDENT;
1068 :
1069 0 : sal_uLong i = rNodeStack.size() - nElementCount;
1070 0 : if (rNodeStack.size() - nElementCount > 1)
1071 0 : i += rNodeStack.size() - 1 - nElementCount;
1072 0 : aRelationArray.resize(i);
1073 0 : while (rNodeStack.size() > nElementCount)
1074 : {
1075 0 : aRelationArray[--i] = rNodeStack.top();
1076 0 : rNodeStack.pop();
1077 0 : if (i > 1 && rNodeStack.size() > 1)
1078 0 : aRelationArray[--i] = new SmGlyphSpecialNode(aToken);
1079 : }
1080 :
1081 0 : SmToken aDummy;
1082 0 : SmStructureNode *pBody = new SmExpressionNode(aDummy);
1083 0 : pBody->SetSubNodes(aRelationArray);
1084 :
1085 :
1086 0 : pSNode->SetSubNodes(pLeft,pBody,pRight);
1087 0 : pSNode->SetScaleMode(SCALE_HEIGHT);
1088 0 : GetSmImport().GetNodeStack().push(pSNode);
1089 0 : }
1090 :
1091 :
1092 : ////////////////////////////////////////////////////////////
1093 :
1094 0 : class SmXMLErrorContext_Impl : public SmXMLRowContext_Impl
1095 : {
1096 : public:
1097 0 : SmXMLErrorContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix,
1098 : const OUString& rLName)
1099 0 : : SmXMLRowContext_Impl(rImport,nPrefix,rLName) {}
1100 :
1101 : void EndElement();
1102 : };
1103 :
1104 0 : void SmXMLErrorContext_Impl::EndElement()
1105 : {
1106 : /*Right now the error tag is completely ignored, what
1107 : can I do with it in starmath, ?, maybe we need a
1108 : report window ourselves, do a test for validity of
1109 : the xml input, use merrors, and then generate
1110 : the markup inside the merror with a big red colour
1111 : of something. For now just throw them all away.
1112 : */
1113 0 : SmNodeStack &rNodeStack = GetSmImport().GetNodeStack();
1114 0 : while (rNodeStack.size() > nElementCount)
1115 : {
1116 0 : delete rNodeStack.top();
1117 0 : rNodeStack.pop();
1118 : }
1119 0 : }
1120 :
1121 : ////////////////////////////////////////////////////////////
1122 :
1123 0 : class SmXMLNumberContext_Impl : public SmXMLImportContext
1124 : {
1125 : protected:
1126 : SmToken aToken;
1127 :
1128 : public:
1129 0 : SmXMLNumberContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix,
1130 : const OUString& rLName)
1131 0 : : SmXMLImportContext(rImport,nPrefix,rLName)
1132 : {
1133 0 : aToken.cMathChar = '\0';
1134 0 : aToken.nLevel = 5;
1135 0 : aToken.eType = TNUMBER;
1136 0 : }
1137 :
1138 : virtual void TCharacters(const OUString &rChars);
1139 :
1140 : void EndElement();
1141 : };
1142 :
1143 0 : void SmXMLNumberContext_Impl::TCharacters(const OUString &rChars)
1144 : {
1145 0 : aToken.aText = rChars;
1146 0 : }
1147 :
1148 0 : void SmXMLNumberContext_Impl::EndElement()
1149 : {
1150 0 : GetSmImport().GetNodeStack().push(new SmTextNode(aToken,FNT_NUMBER));
1151 0 : }
1152 :
1153 : ////////////////////////////////////////////////////////////
1154 :
1155 0 : class SmXMLAnnotationContext_Impl : public SmXMLImportContext
1156 : {
1157 : sal_Bool bIsStarMath;
1158 :
1159 : public:
1160 0 : SmXMLAnnotationContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix,
1161 : const OUString& rLName)
1162 0 : : SmXMLImportContext(rImport,nPrefix,rLName), bIsStarMath(sal_False) {}
1163 :
1164 : virtual void Characters(const OUString &rChars);
1165 :
1166 : void StartElement(const uno::Reference<xml::sax::XAttributeList > & xAttrList );
1167 : };
1168 :
1169 0 : void SmXMLAnnotationContext_Impl::StartElement(const uno::Reference<
1170 : xml::sax::XAttributeList > & xAttrList )
1171 : {
1172 0 : sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
1173 0 : for (sal_Int16 i=0;i<nAttrCount;i++)
1174 : {
1175 0 : OUString sAttrName = xAttrList->getNameByIndex(i);
1176 0 : OUString aLocalName;
1177 0 : sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
1178 0 : GetKeyByAttrName(sAttrName,&aLocalName);
1179 :
1180 0 : OUString sValue = xAttrList->getValueByIndex(i);
1181 : const SvXMLTokenMap &rAttrTokenMap =
1182 0 : GetSmImport().GetAnnotationAttrTokenMap();
1183 0 : switch(rAttrTokenMap.Get(nPrefix,aLocalName))
1184 : {
1185 : case XML_TOK_ENCODING:
1186 0 : bIsStarMath= sValue == "StarMath 5.0";
1187 0 : break;
1188 : default:
1189 0 : break;
1190 : }
1191 0 : }
1192 0 : }
1193 :
1194 0 : void SmXMLAnnotationContext_Impl::Characters(const OUString &rChars)
1195 : {
1196 0 : if (bIsStarMath)
1197 0 : GetSmImport().GetText().Append(String(rChars));
1198 0 : }
1199 :
1200 : ////////////////////////////////////////////////////////////
1201 :
1202 0 : class SmXMLTextContext_Impl : public SmXMLImportContext
1203 : {
1204 : protected:
1205 : SmToken aToken;
1206 :
1207 : public:
1208 0 : SmXMLTextContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix,
1209 : const OUString& rLName)
1210 0 : : SmXMLImportContext(rImport,nPrefix,rLName)
1211 : {
1212 0 : aToken.cMathChar = '\0';
1213 0 : aToken.nLevel = 5;
1214 0 : aToken.eType = TTEXT;
1215 0 : }
1216 :
1217 : virtual void TCharacters(const OUString &rChars);
1218 :
1219 : void EndElement();
1220 : };
1221 :
1222 0 : void SmXMLTextContext_Impl::TCharacters(const OUString &rChars)
1223 : {
1224 0 : aToken.aText = rChars;
1225 0 : }
1226 :
1227 0 : void SmXMLTextContext_Impl::EndElement()
1228 : {
1229 0 : GetSmImport().GetNodeStack().push(new SmTextNode(aToken,FNT_TEXT));
1230 0 : }
1231 :
1232 : ////////////////////////////////////////////////////////////
1233 :
1234 0 : class SmXMLStringContext_Impl : public SmXMLImportContext
1235 : {
1236 : protected:
1237 : SmToken aToken;
1238 :
1239 : public:
1240 0 : SmXMLStringContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix,
1241 : const OUString& rLName)
1242 0 : : SmXMLImportContext(rImport,nPrefix,rLName)
1243 : {
1244 0 : aToken.cMathChar = '\0';
1245 0 : aToken.nLevel = 5;
1246 0 : aToken.eType = TTEXT;
1247 0 : }
1248 :
1249 : virtual void TCharacters(const OUString &rChars);
1250 :
1251 : void EndElement();
1252 : };
1253 :
1254 0 : void SmXMLStringContext_Impl::TCharacters(const OUString &rChars)
1255 : {
1256 : /*
1257 : The content of <ms> elements should be rendered with visible "escaping" of
1258 : certain characters in the content, including at least "double quote"
1259 : itself, and preferably whitespace other than individual blanks. The intent
1260 : is for the viewer to see that the expression is a string literal, and to
1261 : see exactly which characters form its content. For example, <ms>double
1262 : quote is "</ms> might be rendered as "double quote is \"".
1263 :
1264 : Obviously this isn't fully done here.
1265 : */
1266 0 : aToken.aText = "\"" + rChars + "\"";
1267 0 : }
1268 :
1269 0 : void SmXMLStringContext_Impl::EndElement()
1270 : {
1271 0 : GetSmImport().GetNodeStack().push(new SmTextNode(aToken,FNT_FIXED));
1272 0 : }
1273 :
1274 : ////////////////////////////////////////////////////////////
1275 :
1276 0 : class SmXMLIdentifierContext_Impl : public SmXMLImportContext
1277 : {
1278 : protected:
1279 : SmXMLContext_Helper aStyleHelper;
1280 : SmToken aToken;
1281 :
1282 : public:
1283 0 : SmXMLIdentifierContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix,
1284 : const OUString& rLName)
1285 0 : : SmXMLImportContext(rImport,nPrefix,rLName),aStyleHelper(*this)
1286 : {
1287 0 : aToken.cMathChar = '\0';
1288 0 : aToken.nLevel = 5;
1289 0 : aToken.eType = TIDENT;
1290 0 : }
1291 :
1292 : void TCharacters(const OUString &rChars);
1293 0 : void StartElement(const uno::Reference< xml::sax::XAttributeList > & xAttrList )
1294 : {
1295 0 : aStyleHelper.RetrieveAttrs(xAttrList);
1296 0 : };
1297 : void EndElement();
1298 : };
1299 :
1300 0 : void SmXMLIdentifierContext_Impl::EndElement()
1301 : {
1302 0 : SmTextNode *pNode = 0;
1303 : //we will handle identifier italic/normal here instead of with a standalone
1304 : //font node
1305 0 : if (((aStyleHelper.nIsItalic == -1) && (aToken.aText.getLength() > 1))
1306 0 : || ((aStyleHelper.nIsItalic == 0) && (aToken.aText.getLength() == 1)))
1307 : {
1308 0 : pNode = new SmTextNode(aToken,FNT_FUNCTION);
1309 0 : pNode->GetFont().SetItalic(ITALIC_NONE);
1310 0 : aStyleHelper.nIsItalic = -1;
1311 : }
1312 : else
1313 0 : pNode = new SmTextNode(aToken,FNT_VARIABLE);
1314 0 : if (aStyleHelper.bFontNodeNeeded && aStyleHelper.nIsItalic != -1)
1315 : {
1316 0 : if (aStyleHelper.nIsItalic)
1317 0 : pNode->GetFont().SetItalic(ITALIC_NORMAL);
1318 : else
1319 0 : pNode->GetFont().SetItalic(ITALIC_NONE);
1320 : }
1321 :
1322 0 : if ((-1!=aStyleHelper.nIsBold) || (0.0!=aStyleHelper.nFontSize) ||
1323 0 : (!aStyleHelper.sFontFamily.isEmpty()) ||
1324 0 : !aStyleHelper.sColor.isEmpty())
1325 0 : aStyleHelper.bFontNodeNeeded=sal_True;
1326 : else
1327 0 : aStyleHelper.bFontNodeNeeded=sal_False;
1328 0 : if (aStyleHelper.bFontNodeNeeded)
1329 0 : aStyleHelper.ApplyAttrs();
1330 0 : GetSmImport().GetNodeStack().push(pNode);
1331 0 : }
1332 :
1333 0 : void SmXMLIdentifierContext_Impl::TCharacters(const OUString &rChars)
1334 : {
1335 0 : aToken.aText = rChars;
1336 0 : }
1337 :
1338 : ////////////////////////////////////////////////////////////
1339 :
1340 0 : class SmXMLOperatorContext_Impl : public SmXMLImportContext
1341 : {
1342 : sal_Bool bIsStretchy;
1343 :
1344 : protected:
1345 : SmToken aToken;
1346 :
1347 : public:
1348 0 : SmXMLOperatorContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix,
1349 : const OUString& rLName)
1350 0 : : SmXMLImportContext(rImport,nPrefix,rLName), bIsStretchy(sal_False)
1351 : {
1352 0 : aToken.eType = TSPECIAL;
1353 0 : aToken.nLevel = 5;
1354 0 : }
1355 :
1356 : void TCharacters(const OUString &rChars);
1357 : void StartElement(const uno::Reference< xml::sax::XAttributeList > &xAttrList );
1358 : void EndElement();
1359 : };
1360 :
1361 0 : void SmXMLOperatorContext_Impl::TCharacters(const OUString &rChars)
1362 : {
1363 0 : aToken.cMathChar = rChars[0];
1364 0 : }
1365 :
1366 0 : void SmXMLOperatorContext_Impl::EndElement()
1367 : {
1368 0 : SmMathSymbolNode *pNode = new SmMathSymbolNode(aToken);
1369 : //For stretchy scaling the scaling must be retrieved from this node
1370 : //and applied to the expression itself so as to get the expression
1371 : //to scale the operator to the height of the expression itself
1372 0 : if (bIsStretchy)
1373 0 : pNode->SetScaleMode(SCALE_HEIGHT);
1374 0 : GetSmImport().GetNodeStack().push(pNode);
1375 0 : }
1376 :
1377 :
1378 :
1379 0 : void SmXMLOperatorContext_Impl::StartElement(const uno::Reference<
1380 : xml::sax::XAttributeList > & xAttrList )
1381 : {
1382 0 : sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
1383 0 : for (sal_Int16 i=0;i<nAttrCount;i++)
1384 : {
1385 0 : OUString sAttrName = xAttrList->getNameByIndex(i);
1386 0 : OUString aLocalName;
1387 0 : sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
1388 0 : GetKeyByAttrName(sAttrName,&aLocalName);
1389 :
1390 0 : OUString sValue = xAttrList->getValueByIndex(i);
1391 : const SvXMLTokenMap &rAttrTokenMap =
1392 0 : GetSmImport().GetOperatorAttrTokenMap();
1393 0 : switch(rAttrTokenMap.Get(nPrefix,aLocalName))
1394 : {
1395 : case XML_TOK_STRETCHY:
1396 : bIsStretchy = sValue.equals(
1397 0 : GetXMLToken(XML_TRUE));
1398 0 : break;
1399 : default:
1400 0 : break;
1401 : }
1402 0 : }
1403 0 : }
1404 :
1405 :
1406 : ////////////////////////////////////////////////////////////
1407 :
1408 0 : class SmXMLSpaceContext_Impl : public SmXMLImportContext
1409 : {
1410 : public:
1411 0 : SmXMLSpaceContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix,
1412 : const OUString& rLName)
1413 0 : : SmXMLImportContext(rImport,nPrefix,rLName) {}
1414 :
1415 : void StartElement(const uno::Reference< xml::sax::XAttributeList >& xAttrList );
1416 : };
1417 :
1418 0 : void SmXMLSpaceContext_Impl::StartElement(
1419 : const uno::Reference<xml::sax::XAttributeList > & /*xAttrList*/ )
1420 : {
1421 : // There is not any syntax in Math to specify blank nodes of arbitrary
1422 : // size. Hence we always interpret an <mspace> as a large gap "~".
1423 0 : SmToken aToken;
1424 0 : aToken.cMathChar = '\0';
1425 0 : aToken.eType = TBLANK;
1426 0 : aToken.nLevel = 5;
1427 0 : SmBlankNode *pBlank = new SmBlankNode(aToken);
1428 0 : pBlank->IncreaseBy(aToken);
1429 0 : GetSmImport().GetNodeStack().push(pBlank);
1430 0 : }
1431 :
1432 : ////////////////////////////////////////////////////////////
1433 :
1434 0 : class SmXMLSubContext_Impl : public SmXMLRowContext_Impl
1435 : {
1436 : protected:
1437 : void GenericEndElement(SmTokenType eType,SmSubSup aSubSup);
1438 :
1439 : public:
1440 0 : SmXMLSubContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix,
1441 : const OUString& rLName)
1442 0 : : SmXMLRowContext_Impl(rImport,nPrefix,rLName) {}
1443 :
1444 0 : void EndElement()
1445 : {
1446 0 : GenericEndElement(TRSUB,RSUB);
1447 0 : }
1448 : };
1449 :
1450 :
1451 0 : void SmXMLSubContext_Impl::GenericEndElement(SmTokenType eType, SmSubSup eSubSup)
1452 : {
1453 : /*The <msub> element requires exactly 2 arguments.*/
1454 0 : const bool bNodeCheck = GetSmImport().GetNodeStack().size() - nElementCount == 2;
1455 : OSL_ENSURE( bNodeCheck, "Sub has not two arguments" );
1456 0 : if (!bNodeCheck)
1457 0 : return;
1458 :
1459 0 : SmToken aToken;
1460 0 : aToken.cMathChar = '\0';
1461 0 : aToken.eType = eType;
1462 0 : SmSubSupNode *pNode = new SmSubSupNode(aToken);
1463 0 : SmNodeStack &rNodeStack = GetSmImport().GetNodeStack();
1464 :
1465 : // initialize subnodes array
1466 0 : SmNodeArray aSubNodes;
1467 0 : aSubNodes.resize(1 + SUBSUP_NUM_ENTRIES);
1468 0 : for (sal_uLong i = 1; i < aSubNodes.size(); i++)
1469 0 : aSubNodes[i] = NULL;
1470 :
1471 0 : aSubNodes[eSubSup+1] = lcl_popOrZero(rNodeStack);
1472 0 : aSubNodes[0] = lcl_popOrZero(rNodeStack);
1473 0 : pNode->SetSubNodes(aSubNodes);
1474 0 : rNodeStack.push(pNode);
1475 : }
1476 :
1477 : ////////////////////////////////////////////////////////////
1478 :
1479 0 : class SmXMLSupContext_Impl : public SmXMLSubContext_Impl
1480 : {
1481 : public:
1482 0 : SmXMLSupContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix,
1483 : const OUString& rLName)
1484 0 : : SmXMLSubContext_Impl(rImport,nPrefix,rLName) {}
1485 :
1486 0 : void EndElement()
1487 : {
1488 0 : GenericEndElement(TRSUP,RSUP);
1489 0 : }
1490 : };
1491 :
1492 : ////////////////////////////////////////////////////////////
1493 :
1494 0 : class SmXMLSubSupContext_Impl : public SmXMLRowContext_Impl
1495 : {
1496 : protected:
1497 : void GenericEndElement(SmTokenType eType, SmSubSup aSub,SmSubSup aSup);
1498 :
1499 : public:
1500 0 : SmXMLSubSupContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix,
1501 : const OUString& rLName)
1502 0 : : SmXMLRowContext_Impl(rImport,nPrefix,rLName) {}
1503 :
1504 0 : void EndElement()
1505 : {
1506 0 : GenericEndElement(TRSUB,RSUB,RSUP);
1507 0 : }
1508 : };
1509 :
1510 0 : void SmXMLSubSupContext_Impl::GenericEndElement(SmTokenType eType,
1511 : SmSubSup aSub,SmSubSup aSup)
1512 : {
1513 : /*The <msub> element requires exactly 3 arguments.*/
1514 0 : const bool bNodeCheck = GetSmImport().GetNodeStack().size() - nElementCount == 3;
1515 : OSL_ENSURE( bNodeCheck, "SubSup has not three arguments" );
1516 0 : if (!bNodeCheck)
1517 0 : return;
1518 :
1519 0 : SmToken aToken;
1520 0 : aToken.cMathChar = '\0';
1521 0 : aToken.eType = eType;
1522 0 : SmSubSupNode *pNode = new SmSubSupNode(aToken);
1523 0 : SmNodeStack &rNodeStack = GetSmImport().GetNodeStack();
1524 :
1525 : // initialize subnodes array
1526 0 : SmNodeArray aSubNodes;
1527 0 : aSubNodes.resize(1 + SUBSUP_NUM_ENTRIES);
1528 0 : for (sal_uLong i = 1; i < aSubNodes.size(); i++)
1529 0 : aSubNodes[i] = NULL;
1530 :
1531 0 : aSubNodes[aSup+1] = lcl_popOrZero(rNodeStack);
1532 0 : aSubNodes[aSub+1] = lcl_popOrZero(rNodeStack);
1533 0 : aSubNodes[0] = lcl_popOrZero(rNodeStack);
1534 0 : pNode->SetSubNodes(aSubNodes);
1535 0 : rNodeStack.push(pNode);
1536 : }
1537 :
1538 : ////////////////////////////////////////////////////////////
1539 :
1540 0 : class SmXMLUnderContext_Impl : public SmXMLSubContext_Impl
1541 : {
1542 : protected:
1543 : sal_Int16 nAttrCount;
1544 :
1545 : public:
1546 0 : SmXMLUnderContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix,
1547 : const OUString& rLName)
1548 0 : : SmXMLSubContext_Impl(rImport,nPrefix,rLName) {}
1549 :
1550 : void StartElement(const uno::Reference< xml::sax::XAttributeList > &xAttrList );
1551 : void EndElement();
1552 : void HandleAccent();
1553 : };
1554 :
1555 0 : void SmXMLUnderContext_Impl::StartElement(const uno::Reference<
1556 : xml::sax::XAttributeList > & xAttrList )
1557 : {
1558 0 : nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
1559 0 : }
1560 :
1561 0 : void SmXMLUnderContext_Impl::HandleAccent()
1562 : {
1563 0 : const bool bNodeCheck = GetSmImport().GetNodeStack().size() - nElementCount == 2;
1564 : OSL_ENSURE( bNodeCheck, "Sub has not two arguments" );
1565 0 : if (!bNodeCheck)
1566 0 : return;
1567 :
1568 : /*Just one special case for the underline thing*/
1569 0 : SmNodeStack &rNodeStack = GetSmImport().GetNodeStack();
1570 0 : SmNode *pTest = lcl_popOrZero(rNodeStack);
1571 0 : SmToken aToken;
1572 0 : aToken.cMathChar = '\0';
1573 0 : aToken.eType = TUNDERLINE;
1574 :
1575 :
1576 0 : SmNodeArray aSubNodes;
1577 0 : aSubNodes.resize(2);
1578 :
1579 0 : SmStructureNode *pNode = new SmAttributNode(aToken);
1580 0 : if ((pTest->GetToken().cMathChar & 0x0FFF) == 0x0332)
1581 : {
1582 0 : aSubNodes[0] = new SmRectangleNode(aToken);
1583 0 : delete pTest;
1584 : }
1585 : else
1586 0 : aSubNodes[0] = pTest;
1587 :
1588 0 : aSubNodes[1] = lcl_popOrZero(rNodeStack);
1589 0 : pNode->SetSubNodes(aSubNodes);
1590 0 : pNode->SetScaleMode(SCALE_WIDTH);
1591 0 : rNodeStack.push(pNode);
1592 : }
1593 :
1594 :
1595 0 : void SmXMLUnderContext_Impl::EndElement()
1596 : {
1597 0 : if (!nAttrCount)
1598 0 : GenericEndElement(TCSUB,CSUB);
1599 : else
1600 0 : HandleAccent();
1601 0 : }
1602 :
1603 : ////////////////////////////////////////////////////////////
1604 :
1605 0 : class SmXMLOverContext_Impl : public SmXMLSubContext_Impl
1606 : {
1607 : protected:
1608 : sal_Int16 nAttrCount;
1609 :
1610 : public:
1611 0 : SmXMLOverContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix,
1612 : const OUString& rLName)
1613 0 : : SmXMLSubContext_Impl(rImport,nPrefix,rLName), nAttrCount(0) {}
1614 :
1615 : void EndElement();
1616 : void StartElement(const uno::Reference< xml::sax::XAttributeList > &xAttrList );
1617 : void HandleAccent();
1618 : };
1619 :
1620 :
1621 0 : void SmXMLOverContext_Impl::StartElement(const uno::Reference<
1622 : xml::sax::XAttributeList > & xAttrList )
1623 : {
1624 0 : nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
1625 0 : }
1626 :
1627 :
1628 0 : void SmXMLOverContext_Impl::EndElement()
1629 : {
1630 0 : if (!nAttrCount)
1631 0 : GenericEndElement(TCSUP,CSUP);
1632 : else
1633 0 : HandleAccent();
1634 0 : }
1635 :
1636 :
1637 0 : void SmXMLOverContext_Impl::HandleAccent()
1638 : {
1639 0 : const bool bNodeCheck = GetSmImport().GetNodeStack().size() - nElementCount == 2;
1640 : OSL_ENSURE (bNodeCheck, "Sub has not two arguments");
1641 0 : if (!bNodeCheck)
1642 0 : return;
1643 :
1644 0 : SmToken aToken;
1645 0 : aToken.cMathChar = '\0';
1646 0 : aToken.eType = TACUTE;
1647 :
1648 0 : SmAttributNode *pNode = new SmAttributNode(aToken);
1649 0 : SmNodeStack &rNodeStack = GetSmImport().GetNodeStack();
1650 :
1651 0 : SmNodeArray aSubNodes;
1652 0 : aSubNodes.resize(2);
1653 0 : aSubNodes[0] = lcl_popOrZero(rNodeStack);
1654 0 : aSubNodes[1] = lcl_popOrZero(rNodeStack);
1655 0 : pNode->SetSubNodes(aSubNodes);
1656 0 : pNode->SetScaleMode(SCALE_WIDTH);
1657 0 : rNodeStack.push(pNode);
1658 :
1659 : }
1660 :
1661 : ////////////////////////////////////////////////////////////
1662 :
1663 0 : class SmXMLUnderOverContext_Impl : public SmXMLSubSupContext_Impl
1664 : {
1665 : public:
1666 0 : SmXMLUnderOverContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix,
1667 : const OUString& rLName)
1668 0 : : SmXMLSubSupContext_Impl(rImport,nPrefix,rLName) {}
1669 :
1670 0 : void EndElement()
1671 : {
1672 0 : GenericEndElement(TCSUB,CSUB,CSUP);
1673 0 : }
1674 : };
1675 :
1676 : ////////////////////////////////////////////////////////////
1677 :
1678 0 : class SmXMLMultiScriptsContext_Impl : public SmXMLSubSupContext_Impl
1679 : {
1680 : bool bHasPrescripts;
1681 :
1682 : void ProcessSubSupPairs(bool bIsPrescript);
1683 :
1684 : public:
1685 0 : SmXMLMultiScriptsContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix,
1686 : const OUString& rLName) :
1687 : SmXMLSubSupContext_Impl(rImport,nPrefix,rLName),
1688 0 : bHasPrescripts(false) {}
1689 :
1690 : void EndElement();
1691 : SvXMLImportContext *CreateChildContext(sal_uInt16 nPrefix,
1692 : const OUString& rLocalName,
1693 : const uno::Reference< xml::sax::XAttributeList > &xAttrList);
1694 : };
1695 :
1696 : ////////////////////////////////////////////////////////////
1697 :
1698 0 : class SmXMLNoneContext_Impl : public SmXMLImportContext
1699 : {
1700 : public:
1701 0 : SmXMLNoneContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix,
1702 : const OUString& rLName)
1703 0 : : SmXMLImportContext(rImport,nPrefix,rLName) {}
1704 :
1705 : void EndElement();
1706 : };
1707 :
1708 :
1709 0 : void SmXMLNoneContext_Impl::EndElement(void)
1710 : {
1711 0 : SmToken aToken;
1712 0 : aToken.cMathChar = '\0';
1713 0 : aToken.aText = "";
1714 0 : aToken.nLevel = 5;
1715 0 : aToken.eType = TIDENT;
1716 0 : GetSmImport().GetNodeStack().push(
1717 0 : new SmTextNode(aToken,FNT_VARIABLE));
1718 0 : }
1719 :
1720 : ////////////////////////////////////////////////////////////
1721 :
1722 0 : class SmXMLPrescriptsContext_Impl : public SmXMLImportContext
1723 : {
1724 : public:
1725 0 : SmXMLPrescriptsContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix,
1726 : const OUString& rLName)
1727 0 : : SmXMLImportContext(rImport,nPrefix,rLName) {}
1728 : };
1729 :
1730 : ////////////////////////////////////////////////////////////
1731 :
1732 0 : class SmXMLTableRowContext_Impl : public SmXMLRowContext_Impl
1733 : {
1734 : public:
1735 0 : SmXMLTableRowContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix,
1736 : const OUString& rLName) :
1737 0 : SmXMLRowContext_Impl(rImport,nPrefix,rLName)
1738 0 : {}
1739 :
1740 : SvXMLImportContext *CreateChildContext(sal_uInt16 nPrefix,
1741 : const OUString& rLocalName,
1742 : const uno::Reference< xml::sax::XAttributeList > &xAttrList);
1743 : };
1744 :
1745 :
1746 : ////////////////////////////////////////////////////////////
1747 :
1748 0 : class SmXMLTableContext_Impl : public SmXMLTableRowContext_Impl
1749 : {
1750 : public:
1751 0 : SmXMLTableContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix,
1752 : const OUString& rLName) :
1753 0 : SmXMLTableRowContext_Impl(rImport,nPrefix,rLName)
1754 0 : {}
1755 :
1756 : void EndElement();
1757 : SvXMLImportContext *CreateChildContext(sal_uInt16 nPrefix,
1758 : const OUString& rLocalName,
1759 : const uno::Reference< xml::sax::XAttributeList > &xAttrList);
1760 : };
1761 :
1762 :
1763 : ////////////////////////////////////////////////////////////
1764 :
1765 0 : class SmXMLTableCellContext_Impl : public SmXMLRowContext_Impl
1766 : {
1767 : public:
1768 0 : SmXMLTableCellContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix,
1769 : const OUString& rLName) :
1770 0 : SmXMLRowContext_Impl(rImport,nPrefix,rLName)
1771 0 : {}
1772 : };
1773 :
1774 : ////////////////////////////////////////////////////////////
1775 :
1776 0 : class SmXMLAlignGroupContext_Impl : public SmXMLRowContext_Impl
1777 : {
1778 : public:
1779 0 : SmXMLAlignGroupContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix,
1780 : const OUString& rLName) :
1781 0 : SmXMLRowContext_Impl(rImport,nPrefix,rLName)
1782 0 : {}
1783 :
1784 : /*Don't do anything with alignment for now*/
1785 0 : void EndElement()
1786 : {
1787 0 : }
1788 : };
1789 :
1790 : ////////////////////////////////////////////////////////////
1791 :
1792 0 : class SmXMLActionContext_Impl : public SmXMLRowContext_Impl
1793 : {
1794 : public:
1795 0 : SmXMLActionContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix,
1796 : const OUString& rLName) :
1797 0 : SmXMLRowContext_Impl(rImport,nPrefix,rLName)
1798 0 : {}
1799 :
1800 : void EndElement();
1801 : };
1802 :
1803 : ////////////////////////////////////////////////////////////
1804 :
1805 : // NB: virtually inherit so we can multiply inherit properly
1806 : // in SmXMLFlatDocContext_Impl
1807 0 : class SmXMLOfficeContext_Impl : public virtual SvXMLImportContext
1808 : {
1809 : public:
1810 0 : SmXMLOfficeContext_Impl( SmXMLImport &rImport, sal_uInt16 nPrfx,
1811 : const OUString& rLName)
1812 0 : : SvXMLImportContext(rImport,nPrfx,rLName) {}
1813 :
1814 : virtual SvXMLImportContext *CreateChildContext(sal_uInt16 nPrefix, const OUString& rLocalName, const uno::Reference< xml::sax::XAttributeList > &xAttrList);
1815 : };
1816 :
1817 0 : SvXMLImportContext *SmXMLOfficeContext_Impl::CreateChildContext(sal_uInt16 nPrefix,
1818 : const OUString& rLocalName,
1819 : const uno::Reference< xml::sax::XAttributeList > &xAttrList)
1820 : {
1821 0 : SvXMLImportContext *pContext = 0;
1822 0 : if ( XML_NAMESPACE_OFFICE == nPrefix &&
1823 0 : rLocalName == GetXMLToken(XML_META) )
1824 : {
1825 : OSL_FAIL("XML_TOK_DOC_META: should not have come here, maybe document is invalid?");
1826 : }
1827 0 : else if ( XML_NAMESPACE_OFFICE == nPrefix &&
1828 0 : rLocalName == GetXMLToken(XML_SETTINGS) )
1829 : {
1830 0 : pContext = new XMLDocumentSettingsContext( GetImport(),
1831 : XML_NAMESPACE_OFFICE, rLocalName,
1832 0 : xAttrList );
1833 : }
1834 : else
1835 0 : pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
1836 :
1837 0 : return pContext;
1838 : }
1839 :
1840 : ////////////////////////////////////////////////////////////
1841 :
1842 : // context for flat file xml format
1843 : class SmXMLFlatDocContext_Impl
1844 : : public SmXMLOfficeContext_Impl, public SvXMLMetaDocumentContext
1845 : {
1846 : public:
1847 : SmXMLFlatDocContext_Impl( SmXMLImport& i_rImport,
1848 : sal_uInt16 i_nPrefix, const OUString & i_rLName,
1849 : const uno::Reference<document::XDocumentProperties>& i_xDocProps);
1850 :
1851 : virtual ~SmXMLFlatDocContext_Impl();
1852 :
1853 : virtual SvXMLImportContext *CreateChildContext(sal_uInt16 i_nPrefix, const OUString& i_rLocalName, const uno::Reference<xml::sax::XAttributeList>& i_xAttrList);
1854 : };
1855 :
1856 0 : SmXMLFlatDocContext_Impl::SmXMLFlatDocContext_Impl( SmXMLImport& i_rImport,
1857 : sal_uInt16 i_nPrefix, const OUString & i_rLName,
1858 : const uno::Reference<document::XDocumentProperties>& i_xDocProps) :
1859 : SvXMLImportContext(i_rImport, i_nPrefix, i_rLName),
1860 : SmXMLOfficeContext_Impl(i_rImport, i_nPrefix, i_rLName),
1861 : SvXMLMetaDocumentContext(i_rImport, i_nPrefix, i_rLName,
1862 0 : i_xDocProps)
1863 : {
1864 0 : }
1865 :
1866 0 : SmXMLFlatDocContext_Impl::~SmXMLFlatDocContext_Impl()
1867 : {
1868 0 : }
1869 :
1870 0 : SvXMLImportContext *SmXMLFlatDocContext_Impl::CreateChildContext(
1871 : sal_uInt16 i_nPrefix, const OUString& i_rLocalName,
1872 : const uno::Reference<xml::sax::XAttributeList>& i_xAttrList)
1873 : {
1874 : // behave like meta base class iff we encounter office:meta
1875 0 : if ( XML_NAMESPACE_OFFICE == i_nPrefix &&
1876 0 : i_rLocalName == GetXMLToken(XML_META) )
1877 : {
1878 : return SvXMLMetaDocumentContext::CreateChildContext(
1879 0 : i_nPrefix, i_rLocalName, i_xAttrList );
1880 : }
1881 : else
1882 : {
1883 : return SmXMLOfficeContext_Impl::CreateChildContext(
1884 0 : i_nPrefix, i_rLocalName, i_xAttrList );
1885 : }
1886 : }
1887 :
1888 : ////////////////////////////////////////////////////////////
1889 :
1890 : static SvXMLTokenMapEntry aPresLayoutElemTokenMap[] =
1891 : {
1892 : { XML_NAMESPACE_MATH, XML_SEMANTICS, XML_TOK_SEMANTICS },
1893 : { XML_NAMESPACE_MATH, XML_MATH, XML_TOK_MATH },
1894 : { XML_NAMESPACE_MATH, XML_MSTYLE, XML_TOK_MSTYLE },
1895 : { XML_NAMESPACE_MATH, XML_MERROR, XML_TOK_MERROR },
1896 : { XML_NAMESPACE_MATH, XML_MPHANTOM, XML_TOK_MPHANTOM },
1897 : { XML_NAMESPACE_MATH, XML_MROW, XML_TOK_MROW },
1898 : { XML_NAMESPACE_MATH, XML_MENCLOSE, XML_TOK_MENCLOSE },
1899 : { XML_NAMESPACE_MATH, XML_MFRAC, XML_TOK_MFRAC },
1900 : { XML_NAMESPACE_MATH, XML_MSQRT, XML_TOK_MSQRT },
1901 : { XML_NAMESPACE_MATH, XML_MROOT, XML_TOK_MROOT },
1902 : { XML_NAMESPACE_MATH, XML_MSUB, XML_TOK_MSUB },
1903 : { XML_NAMESPACE_MATH, XML_MSUP, XML_TOK_MSUP },
1904 : { XML_NAMESPACE_MATH, XML_MSUBSUP, XML_TOK_MSUBSUP },
1905 : { XML_NAMESPACE_MATH, XML_MUNDER, XML_TOK_MUNDER },
1906 : { XML_NAMESPACE_MATH, XML_MOVER, XML_TOK_MOVER },
1907 : { XML_NAMESPACE_MATH, XML_MUNDEROVER, XML_TOK_MUNDEROVER },
1908 : { XML_NAMESPACE_MATH, XML_MMULTISCRIPTS, XML_TOK_MMULTISCRIPTS },
1909 : { XML_NAMESPACE_MATH, XML_MTABLE, XML_TOK_MTABLE },
1910 : { XML_NAMESPACE_MATH, XML_MACTION, XML_TOK_MACTION },
1911 : { XML_NAMESPACE_MATH, XML_MFENCED, XML_TOK_MFENCED },
1912 : { XML_NAMESPACE_MATH, XML_MPADDED, XML_TOK_MPADDED },
1913 : XML_TOKEN_MAP_END
1914 : };
1915 :
1916 : static SvXMLTokenMapEntry aPresLayoutAttrTokenMap[] =
1917 : {
1918 : { XML_NAMESPACE_MATH, XML_FONTWEIGHT, XML_TOK_FONTWEIGHT },
1919 : { XML_NAMESPACE_MATH, XML_FONTSTYLE, XML_TOK_FONTSTYLE },
1920 : { XML_NAMESPACE_MATH, XML_FONTSIZE, XML_TOK_FONTSIZE },
1921 : { XML_NAMESPACE_MATH, XML_FONTFAMILY, XML_TOK_FONTFAMILY },
1922 : { XML_NAMESPACE_MATH, XML_COLOR, XML_TOK_COLOR },
1923 : XML_TOKEN_MAP_END
1924 : };
1925 :
1926 : static SvXMLTokenMapEntry aFencedAttrTokenMap[] =
1927 : {
1928 : { XML_NAMESPACE_MATH, XML_OPEN, XML_TOK_OPEN },
1929 : { XML_NAMESPACE_MATH, XML_CLOSE, XML_TOK_CLOSE },
1930 : XML_TOKEN_MAP_END
1931 : };
1932 :
1933 : static SvXMLTokenMapEntry aOperatorAttrTokenMap[] =
1934 : {
1935 : { XML_NAMESPACE_MATH, XML_STRETCHY, XML_TOK_STRETCHY },
1936 : XML_TOKEN_MAP_END
1937 : };
1938 :
1939 : static SvXMLTokenMapEntry aAnnotationAttrTokenMap[] =
1940 : {
1941 : { XML_NAMESPACE_MATH, XML_ENCODING, XML_TOK_ENCODING },
1942 : XML_TOKEN_MAP_END
1943 : };
1944 :
1945 :
1946 : static SvXMLTokenMapEntry aPresElemTokenMap[] =
1947 : {
1948 : { XML_NAMESPACE_MATH, XML_ANNOTATION, XML_TOK_ANNOTATION },
1949 : { XML_NAMESPACE_MATH, XML_MI, XML_TOK_MI },
1950 : { XML_NAMESPACE_MATH, XML_MN, XML_TOK_MN },
1951 : { XML_NAMESPACE_MATH, XML_MO, XML_TOK_MO },
1952 : { XML_NAMESPACE_MATH, XML_MTEXT, XML_TOK_MTEXT },
1953 : { XML_NAMESPACE_MATH, XML_MSPACE,XML_TOK_MSPACE },
1954 : { XML_NAMESPACE_MATH, XML_MS, XML_TOK_MS },
1955 : { XML_NAMESPACE_MATH, XML_MALIGNGROUP, XML_TOK_MALIGNGROUP },
1956 : XML_TOKEN_MAP_END
1957 : };
1958 :
1959 : static SvXMLTokenMapEntry aPresScriptEmptyElemTokenMap[] =
1960 : {
1961 : { XML_NAMESPACE_MATH, XML_MPRESCRIPTS, XML_TOK_MPRESCRIPTS },
1962 : { XML_NAMESPACE_MATH, XML_NONE, XML_TOK_NONE },
1963 : XML_TOKEN_MAP_END
1964 : };
1965 :
1966 : static SvXMLTokenMapEntry aPresTableElemTokenMap[] =
1967 : {
1968 : { XML_NAMESPACE_MATH, XML_MTR, XML_TOK_MTR },
1969 : { XML_NAMESPACE_MATH, XML_MTD, XML_TOK_MTD },
1970 : XML_TOKEN_MAP_END
1971 : };
1972 :
1973 : static SvXMLTokenMapEntry aColorTokenMap[] =
1974 : {
1975 : { XML_NAMESPACE_MATH, XML_BLACK, TBLACK},
1976 : { XML_NAMESPACE_MATH, XML_WHITE, TWHITE},
1977 : { XML_NAMESPACE_MATH, XML_RED, TRED},
1978 : { XML_NAMESPACE_MATH, XML_GREEN, TGREEN},
1979 : { XML_NAMESPACE_MATH, XML_BLUE, TBLUE},
1980 : { XML_NAMESPACE_MATH, XML_AQUA, TCYAN},
1981 : { XML_NAMESPACE_MATH, XML_FUCHSIA, TMAGENTA},
1982 : { XML_NAMESPACE_MATH, XML_YELLOW, TYELLOW},
1983 : XML_TOKEN_MAP_END
1984 : };
1985 :
1986 :
1987 : ////////////////////////////////////////////////////////////
1988 :
1989 0 : const SvXMLTokenMap& SmXMLImport::GetPresLayoutElemTokenMap()
1990 : {
1991 0 : if (!pPresLayoutElemTokenMap)
1992 0 : pPresLayoutElemTokenMap = new SvXMLTokenMap(aPresLayoutElemTokenMap);
1993 0 : return *pPresLayoutElemTokenMap;
1994 : }
1995 :
1996 0 : const SvXMLTokenMap& SmXMLImport::GetPresLayoutAttrTokenMap()
1997 : {
1998 0 : if (!pPresLayoutAttrTokenMap)
1999 0 : pPresLayoutAttrTokenMap = new SvXMLTokenMap(aPresLayoutAttrTokenMap);
2000 0 : return *pPresLayoutAttrTokenMap;
2001 : }
2002 :
2003 :
2004 0 : const SvXMLTokenMap& SmXMLImport::GetFencedAttrTokenMap()
2005 : {
2006 0 : if (!pFencedAttrTokenMap)
2007 0 : pFencedAttrTokenMap = new SvXMLTokenMap(aFencedAttrTokenMap);
2008 0 : return *pFencedAttrTokenMap;
2009 : }
2010 :
2011 0 : const SvXMLTokenMap& SmXMLImport::GetOperatorAttrTokenMap()
2012 : {
2013 0 : if (!pOperatorAttrTokenMap)
2014 0 : pOperatorAttrTokenMap = new SvXMLTokenMap(aOperatorAttrTokenMap);
2015 0 : return *pOperatorAttrTokenMap;
2016 : }
2017 :
2018 0 : const SvXMLTokenMap& SmXMLImport::GetAnnotationAttrTokenMap()
2019 : {
2020 0 : if (!pAnnotationAttrTokenMap)
2021 0 : pAnnotationAttrTokenMap = new SvXMLTokenMap(aAnnotationAttrTokenMap);
2022 0 : return *pAnnotationAttrTokenMap;
2023 : }
2024 :
2025 0 : const SvXMLTokenMap& SmXMLImport::GetPresElemTokenMap()
2026 : {
2027 0 : if (!pPresElemTokenMap)
2028 0 : pPresElemTokenMap = new SvXMLTokenMap(aPresElemTokenMap);
2029 0 : return *pPresElemTokenMap;
2030 : }
2031 :
2032 0 : const SvXMLTokenMap& SmXMLImport::GetPresScriptEmptyElemTokenMap()
2033 : {
2034 0 : if (!pPresScriptEmptyElemTokenMap)
2035 : pPresScriptEmptyElemTokenMap = new
2036 0 : SvXMLTokenMap(aPresScriptEmptyElemTokenMap);
2037 0 : return *pPresScriptEmptyElemTokenMap;
2038 : }
2039 :
2040 0 : const SvXMLTokenMap& SmXMLImport::GetPresTableElemTokenMap()
2041 : {
2042 0 : if (!pPresTableElemTokenMap)
2043 0 : pPresTableElemTokenMap = new SvXMLTokenMap(aPresTableElemTokenMap);
2044 0 : return *pPresTableElemTokenMap;
2045 : }
2046 :
2047 0 : const SvXMLTokenMap& SmXMLImport::GetColorTokenMap()
2048 : {
2049 0 : if (!pColorTokenMap)
2050 0 : pColorTokenMap = new SvXMLTokenMap(aColorTokenMap);
2051 0 : return *pColorTokenMap;
2052 : }
2053 :
2054 : ////////////////////////////////////////////////////////////
2055 :
2056 0 : SvXMLImportContext *SmXMLDocContext_Impl::CreateChildContext(
2057 : sal_uInt16 nPrefix,
2058 : const OUString& rLocalName,
2059 : const uno::Reference<xml::sax::XAttributeList>& xAttrList)
2060 : {
2061 0 : SvXMLImportContext* pContext = 0L;
2062 :
2063 0 : const SvXMLTokenMap& rTokenMap = GetSmImport().GetPresLayoutElemTokenMap();
2064 :
2065 0 : switch(rTokenMap.Get(nPrefix, rLocalName))
2066 : {
2067 : //Consider semantics a dummy except for any starmath annotations
2068 : case XML_TOK_SEMANTICS:
2069 0 : pContext = GetSmImport().CreateRowContext(nPrefix,rLocalName,
2070 0 : xAttrList);
2071 0 : break;
2072 : /*General Layout Schemata*/
2073 : case XML_TOK_MROW:
2074 0 : pContext = GetSmImport().CreateRowContext(nPrefix,rLocalName,
2075 0 : xAttrList);
2076 0 : break;
2077 : case XML_TOK_MENCLOSE:
2078 0 : pContext = GetSmImport().CreateEncloseContext(nPrefix,rLocalName,
2079 0 : xAttrList);
2080 0 : break;
2081 : case XML_TOK_MFRAC:
2082 0 : pContext = GetSmImport().CreateFracContext(nPrefix,rLocalName,
2083 0 : xAttrList);
2084 0 : break;
2085 : case XML_TOK_MSQRT:
2086 0 : pContext = GetSmImport().CreateSqrtContext(nPrefix,rLocalName,
2087 0 : xAttrList);
2088 0 : break;
2089 : case XML_TOK_MROOT:
2090 0 : pContext = GetSmImport().CreateRootContext(nPrefix,rLocalName,
2091 0 : xAttrList);
2092 0 : break;
2093 : case XML_TOK_MSTYLE:
2094 0 : pContext = GetSmImport().CreateStyleContext(nPrefix,rLocalName,
2095 0 : xAttrList);
2096 0 : break;
2097 : case XML_TOK_MERROR:
2098 0 : pContext = GetSmImport().CreateErrorContext(nPrefix,rLocalName,
2099 0 : xAttrList);
2100 0 : break;
2101 : case XML_TOK_MPADDED:
2102 0 : pContext = GetSmImport().CreatePaddedContext(nPrefix,rLocalName,
2103 0 : xAttrList);
2104 0 : break;
2105 : case XML_TOK_MPHANTOM:
2106 0 : pContext = GetSmImport().CreatePhantomContext(nPrefix,rLocalName,
2107 0 : xAttrList);
2108 0 : break;
2109 : case XML_TOK_MFENCED:
2110 0 : pContext = GetSmImport().CreateFencedContext(nPrefix,rLocalName,
2111 0 : xAttrList);
2112 0 : break;
2113 : /*Script and Limit Schemata*/
2114 : case XML_TOK_MSUB:
2115 0 : pContext = GetSmImport().CreateSubContext(nPrefix,rLocalName,
2116 0 : xAttrList);
2117 0 : break;
2118 : case XML_TOK_MSUP:
2119 0 : pContext = GetSmImport().CreateSupContext(nPrefix,rLocalName,
2120 0 : xAttrList);
2121 0 : break;
2122 : case XML_TOK_MSUBSUP:
2123 0 : pContext = GetSmImport().CreateSubSupContext(nPrefix,rLocalName,
2124 0 : xAttrList);
2125 0 : break;
2126 : case XML_TOK_MUNDER:
2127 0 : pContext = GetSmImport().CreateUnderContext(nPrefix,rLocalName,
2128 0 : xAttrList);
2129 0 : break;
2130 : case XML_TOK_MOVER:
2131 0 : pContext = GetSmImport().CreateOverContext(nPrefix,rLocalName,
2132 0 : xAttrList);
2133 0 : break;
2134 : case XML_TOK_MUNDEROVER:
2135 0 : pContext = GetSmImport().CreateUnderOverContext(nPrefix,rLocalName,
2136 0 : xAttrList);
2137 0 : break;
2138 : case XML_TOK_MMULTISCRIPTS:
2139 0 : pContext = GetSmImport().CreateMultiScriptsContext(nPrefix,
2140 0 : rLocalName, xAttrList);
2141 0 : break;
2142 : case XML_TOK_MTABLE:
2143 0 : pContext = GetSmImport().CreateTableContext(nPrefix,
2144 0 : rLocalName, xAttrList);
2145 0 : break;
2146 : case XML_TOK_MACTION:
2147 0 : pContext = GetSmImport().CreateActionContext(nPrefix,
2148 0 : rLocalName, xAttrList);
2149 0 : break;
2150 : default:
2151 : /*Basically theres an implicit mrow around certain bare
2152 : *elements, use a RowContext to see if this is one of
2153 : *those ones*/
2154 0 : SmXMLRowContext_Impl aTempContext(GetSmImport(),nPrefix,
2155 0 : GetXMLToken(XML_MROW));
2156 :
2157 : pContext = aTempContext.StrictCreateChildContext(nPrefix,
2158 0 : rLocalName, xAttrList);
2159 0 : break;
2160 : }
2161 0 : return pContext;
2162 : }
2163 :
2164 0 : void SmXMLDocContext_Impl::EndElement()
2165 : {
2166 0 : SmNodeArray ContextArray;
2167 0 : ContextArray.resize(1);
2168 0 : SmNodeStack &rNodeStack = GetSmImport().GetNodeStack();
2169 :
2170 0 : ContextArray[0] = lcl_popOrZero(rNodeStack);
2171 :
2172 0 : SmToken aDummy;
2173 0 : SmStructureNode *pSNode = new SmLineNode(aDummy);
2174 0 : pSNode->SetSubNodes(ContextArray);
2175 0 : rNodeStack.push(pSNode);
2176 :
2177 0 : SmNodeArray LineArray;
2178 0 : sal_uLong n = rNodeStack.size();
2179 0 : LineArray.resize(n);
2180 0 : for (sal_uLong j = 0; j < n; j++)
2181 : {
2182 0 : LineArray[n - (j + 1)] = rNodeStack.top();
2183 0 : rNodeStack.pop();
2184 : }
2185 0 : SmStructureNode *pSNode2 = new SmTableNode(aDummy);
2186 0 : pSNode2->SetSubNodes(LineArray);
2187 0 : rNodeStack.push(pSNode2);
2188 0 : }
2189 :
2190 0 : void SmXMLFracContext_Impl::EndElement()
2191 : {
2192 0 : SmNodeStack &rNodeStack = GetSmImport().GetNodeStack();
2193 0 : const bool bNodeCheck = rNodeStack.size() - nElementCount == 2;
2194 : OSL_ENSURE( bNodeCheck, "Fraction (mfrac) tag is missing component" );
2195 0 : if (!bNodeCheck)
2196 0 : return;
2197 :
2198 0 : SmToken aToken;
2199 0 : aToken.cMathChar = '\0';
2200 0 : aToken.eType = TOVER;
2201 0 : SmStructureNode *pSNode = new SmBinVerNode(aToken);
2202 0 : SmNode *pOper = new SmRectangleNode(aToken);
2203 0 : SmNode *pSecond = lcl_popOrZero(rNodeStack);
2204 0 : SmNode *pFirst = lcl_popOrZero(rNodeStack);
2205 0 : pSNode->SetSubNodes(pFirst,pOper,pSecond);
2206 0 : rNodeStack.push(pSNode);
2207 : }
2208 :
2209 0 : void SmXMLRootContext_Impl::EndElement()
2210 : {
2211 : /*The <mroot> element requires exactly 2 arguments.*/
2212 0 : const bool bNodeCheck = GetSmImport().GetNodeStack().size() - nElementCount == 2;
2213 : OSL_ENSURE( bNodeCheck, "Root tag is missing component");
2214 0 : if (!bNodeCheck)
2215 0 : return;
2216 :
2217 0 : SmToken aToken;
2218 0 : aToken.cMathChar = MS_SQRT; //Temporary: alert, based on StarSymbol font
2219 0 : aToken.eType = TNROOT;
2220 0 : SmStructureNode *pSNode = new SmRootNode(aToken);
2221 0 : SmNode *pOper = new SmRootSymbolNode(aToken);
2222 0 : SmNodeStack &rNodeStack = GetSmImport().GetNodeStack();
2223 0 : SmNode *pIndex = lcl_popOrZero(rNodeStack);
2224 0 : SmNode *pBase = lcl_popOrZero(rNodeStack);
2225 0 : pSNode->SetSubNodes(pIndex,pOper,pBase);
2226 0 : rNodeStack.push(pSNode);
2227 : }
2228 :
2229 0 : void SmXMLSqrtContext_Impl::EndElement()
2230 : {
2231 : /*
2232 : <msqrt> accepts any number of arguments; if this number is not 1, its
2233 : contents are treated as a single "inferred <mrow>" containing its
2234 : arguments
2235 : */
2236 0 : if (GetSmImport().GetNodeStack().size() - nElementCount > 1)
2237 0 : SmXMLRowContext_Impl::EndElement();
2238 :
2239 0 : SmToken aToken;
2240 0 : aToken.cMathChar = MS_SQRT; //Temporary: alert, based on StarSymbol font
2241 0 : aToken.eType = TSQRT;
2242 0 : SmStructureNode *pSNode = new SmRootNode(aToken);
2243 0 : SmNode *pOper = new SmRootSymbolNode(aToken);
2244 0 : SmNodeStack &rNodeStack = GetSmImport().GetNodeStack();
2245 0 : pSNode->SetSubNodes(0,pOper,lcl_popOrZero(rNodeStack));
2246 0 : rNodeStack.push(pSNode);
2247 0 : }
2248 :
2249 0 : void SmXMLRowContext_Impl::EndElement()
2250 : {
2251 0 : SmNodeArray aRelationArray;
2252 0 : SmNodeStack &rNodeStack = GetSmImport().GetNodeStack();
2253 0 : sal_uLong nSize = rNodeStack.size()-nElementCount;
2254 :
2255 0 : if (nSize > 0)
2256 : {
2257 0 : aRelationArray.resize(nSize);
2258 0 : for (sal_uLong j=nSize;j > 0;j--)
2259 : {
2260 0 : aRelationArray[j-1] = rNodeStack.top();
2261 0 : rNodeStack.pop();
2262 : }
2263 :
2264 : //If the first or last element is an operator with stretchyness
2265 : //set then we must create a brace node here from those elements,
2266 : //removing the stretchness from the operators and applying it to
2267 : //ourselves, and creating the appropriate dummy StarMath none bracket
2268 : //to balance the arrangement
2269 0 : if (((aRelationArray[0]->GetScaleMode() == SCALE_HEIGHT)
2270 0 : && (aRelationArray[0]->GetType() == NMATH))
2271 0 : || ((aRelationArray[nSize-1]->GetScaleMode() == SCALE_HEIGHT)
2272 0 : && (aRelationArray[nSize-1]->GetType() == NMATH)))
2273 : {
2274 0 : SmToken aToken;
2275 0 : aToken.cMathChar = '\0';
2276 0 : aToken.nLevel = 5;
2277 :
2278 0 : int nLeft=0,nRight=0;
2279 0 : if ((aRelationArray[0]->GetScaleMode() == SCALE_HEIGHT)
2280 0 : && (aRelationArray[0]->GetType() == NMATH))
2281 : {
2282 0 : aToken = aRelationArray[0]->GetToken();
2283 0 : nLeft=1;
2284 : }
2285 : else
2286 0 : aToken.cMathChar = '\0';
2287 :
2288 0 : aToken.eType = TLPARENT;
2289 0 : SmNode *pLeft = new SmMathSymbolNode(aToken);
2290 :
2291 0 : if ((aRelationArray[nSize-1]->GetScaleMode() == SCALE_HEIGHT)
2292 0 : && (aRelationArray[nSize-1]->GetType() == NMATH))
2293 : {
2294 0 : aToken = aRelationArray[nSize-1]->GetToken();
2295 0 : nRight=1;
2296 : }
2297 : else
2298 0 : aToken.cMathChar = '\0';
2299 :
2300 0 : aToken.eType = TRPARENT;
2301 0 : SmNode *pRight = new SmMathSymbolNode(aToken);
2302 :
2303 0 : SmNodeArray aRelationArray2;
2304 :
2305 : //!! nSize-nLeft-nRight may be < 0 !!
2306 0 : int nRelArrSize = nSize-nLeft-nRight;
2307 0 : if (nRelArrSize > 0)
2308 : {
2309 0 : aRelationArray2.resize(nRelArrSize);
2310 0 : for (int i=0;i < nRelArrSize;i++)
2311 0 : aRelationArray2[i] = aRelationArray[i+nLeft];
2312 : }
2313 :
2314 0 : SmToken aDummy;
2315 0 : SmStructureNode *pSNode = new SmBraceNode(aToken);
2316 0 : SmStructureNode *pBody = new SmExpressionNode(aDummy);
2317 0 : pBody->SetSubNodes(aRelationArray2);
2318 :
2319 0 : pSNode->SetSubNodes(pLeft,pBody,pRight);
2320 0 : pSNode->SetScaleMode(SCALE_HEIGHT);
2321 0 : rNodeStack.push(pSNode);
2322 0 : return;
2323 : }
2324 : }
2325 : else //Multiple newlines result in empty row elements
2326 : {
2327 0 : aRelationArray.resize(1);
2328 0 : SmToken aToken;
2329 0 : aToken.cMathChar = '\0';
2330 0 : aToken.nLevel = 5;
2331 0 : aToken.eType = TNEWLINE;
2332 0 : aRelationArray[0] = new SmLineNode(aToken);
2333 : }
2334 :
2335 0 : SmToken aDummy;
2336 0 : SmStructureNode *pSNode = new SmExpressionNode(aDummy);
2337 0 : pSNode->SetSubNodes(aRelationArray);
2338 0 : rNodeStack.push(pSNode);
2339 : }
2340 :
2341 :
2342 0 : SvXMLImportContext *SmXMLRowContext_Impl::StrictCreateChildContext(
2343 : sal_uInt16 nPrefix,
2344 : const OUString& rLocalName,
2345 : const uno::Reference<xml::sax::XAttributeList>& xAttrList)
2346 : {
2347 0 : SvXMLImportContext* pContext = 0L;
2348 :
2349 0 : const SvXMLTokenMap& rTokenMap = GetSmImport().GetPresElemTokenMap();
2350 0 : switch(rTokenMap.Get(nPrefix, rLocalName))
2351 : {
2352 : /*Note that these should accept malignmark subelements, but do not*/
2353 : case XML_TOK_MN:
2354 0 : pContext = GetSmImport().CreateNumberContext(nPrefix,rLocalName,
2355 0 : xAttrList);
2356 0 : break;
2357 : case XML_TOK_MI:
2358 0 : pContext = GetSmImport().CreateIdentifierContext(nPrefix,rLocalName,
2359 0 : xAttrList);
2360 0 : break;
2361 : case XML_TOK_MO:
2362 0 : pContext = GetSmImport().CreateOperatorContext(nPrefix,rLocalName,
2363 0 : xAttrList);
2364 0 : break;
2365 : case XML_TOK_MTEXT:
2366 0 : pContext = GetSmImport().CreateTextContext(nPrefix,rLocalName,
2367 0 : xAttrList);
2368 0 : break;
2369 : case XML_TOK_MSPACE:
2370 0 : pContext = GetSmImport().CreateSpaceContext(nPrefix,rLocalName,
2371 0 : xAttrList);
2372 0 : break;
2373 : case XML_TOK_MS:
2374 0 : pContext = GetSmImport().CreateStringContext(nPrefix,rLocalName,
2375 0 : xAttrList);
2376 0 : break;
2377 :
2378 : /*Note: The maligngroup should only be seen when the row
2379 : * (or decendants) are in a table*/
2380 : case XML_TOK_MALIGNGROUP:
2381 0 : pContext = GetSmImport().CreateAlignGroupContext(nPrefix,rLocalName,
2382 0 : xAttrList);
2383 0 : break;
2384 :
2385 : case XML_TOK_ANNOTATION:
2386 0 : pContext = GetSmImport().CreateAnnotationContext(nPrefix,rLocalName,
2387 0 : xAttrList);
2388 0 : break;
2389 :
2390 : default:
2391 0 : break;
2392 : }
2393 0 : return pContext;
2394 : }
2395 :
2396 :
2397 0 : SvXMLImportContext *SmXMLRowContext_Impl::CreateChildContext(
2398 : sal_uInt16 nPrefix,
2399 : const OUString& rLocalName,
2400 : const uno::Reference<xml::sax::XAttributeList>& xAttrList)
2401 : {
2402 : SvXMLImportContext* pContext = StrictCreateChildContext(nPrefix,
2403 0 : rLocalName, xAttrList);
2404 :
2405 0 : if (!pContext)
2406 : {
2407 : //Hmm, unrecognized for this level, check to see if its
2408 : //an element that can have an implicit schema around it
2409 : pContext = SmXMLDocContext_Impl::CreateChildContext(nPrefix,
2410 0 : rLocalName,xAttrList);
2411 : }
2412 0 : return pContext;
2413 : }
2414 :
2415 :
2416 0 : SvXMLImportContext *SmXMLMultiScriptsContext_Impl::CreateChildContext(
2417 : sal_uInt16 nPrefix,
2418 : const OUString& rLocalName,
2419 : const uno::Reference<xml::sax::XAttributeList>& xAttrList)
2420 : {
2421 0 : SvXMLImportContext* pContext = 0L;
2422 :
2423 0 : const SvXMLTokenMap& rTokenMap = GetSmImport().
2424 0 : GetPresScriptEmptyElemTokenMap();
2425 0 : switch(rTokenMap.Get(nPrefix, rLocalName))
2426 : {
2427 : case XML_TOK_MPRESCRIPTS:
2428 0 : bHasPrescripts = true;
2429 0 : ProcessSubSupPairs(false);
2430 0 : pContext = GetSmImport().CreatePrescriptsContext(nPrefix,
2431 0 : rLocalName, xAttrList);
2432 0 : break;
2433 : case XML_TOK_NONE:
2434 0 : pContext = GetSmImport().CreateNoneContext(nPrefix,rLocalName,
2435 0 : xAttrList);
2436 0 : break;
2437 : default:
2438 : pContext = SmXMLRowContext_Impl::CreateChildContext(nPrefix,
2439 0 : rLocalName,xAttrList);
2440 0 : break;
2441 : }
2442 0 : return pContext;
2443 : }
2444 :
2445 0 : void SmXMLMultiScriptsContext_Impl::ProcessSubSupPairs(bool bIsPrescript)
2446 : {
2447 0 : SmNodeStack &rNodeStack = GetSmImport().GetNodeStack();
2448 :
2449 0 : if (rNodeStack.size() <= nElementCount)
2450 0 : return;
2451 :
2452 0 : sal_uLong nCount = rNodeStack.size() - nElementCount - 1;
2453 0 : if (nCount == 0)
2454 0 : return;
2455 :
2456 0 : if (nCount % 2 == 0)
2457 : {
2458 0 : SmToken aToken;
2459 0 : aToken.cMathChar = '\0';
2460 0 : aToken.eType = bIsPrescript ? TLSUB : TRSUB;
2461 :
2462 0 : SmNodeStack aReverseStack;
2463 0 : for (sal_uLong i = 0; i < nCount + 1; i++)
2464 : {
2465 0 : aReverseStack.push(rNodeStack.top());
2466 0 : rNodeStack.pop();
2467 : }
2468 :
2469 0 : SmSubSup eSub = bIsPrescript ? LSUB : RSUB;
2470 0 : SmSubSup eSup = bIsPrescript ? LSUP : RSUP;
2471 :
2472 0 : for (sal_uLong i = 0; i < nCount; i += 2)
2473 : {
2474 0 : SmSubSupNode *pNode = new SmSubSupNode(aToken);
2475 :
2476 : // initialize subnodes array
2477 0 : SmNodeArray aSubNodes(1 + SUBSUP_NUM_ENTRIES);
2478 :
2479 : /*On each loop the base and its sub sup pair becomes the
2480 : base for the next loop to which the next sub sup pair is
2481 : attached, i.e. wheels within wheels*/
2482 0 : aSubNodes[0] = lcl_popOrZero(aReverseStack);
2483 :
2484 0 : SmNode *pScriptNode = lcl_popOrZero(aReverseStack);
2485 :
2486 0 : if (pScriptNode && ((pScriptNode->GetToken().eType != TIDENT) ||
2487 0 : (!pScriptNode->GetToken().aText.isEmpty())))
2488 0 : aSubNodes[eSub+1] = pScriptNode;
2489 0 : pScriptNode = lcl_popOrZero(aReverseStack);
2490 0 : if (pScriptNode && ((pScriptNode->GetToken().eType != TIDENT) ||
2491 0 : (!pScriptNode->GetToken().aText.isEmpty())))
2492 0 : aSubNodes[eSup+1] = pScriptNode;
2493 :
2494 0 : pNode->SetSubNodes(aSubNodes);
2495 0 : aReverseStack.push(pNode);
2496 0 : }
2497 0 : rNodeStack.push(lcl_popOrZero(aReverseStack));
2498 : }
2499 : else
2500 : {
2501 : // Ignore odd number of elements.
2502 0 : for (sal_uLong i = 0; i < nCount; i++)
2503 : {
2504 0 : delete rNodeStack.top();
2505 0 : rNodeStack.pop();
2506 : }
2507 : }
2508 : }
2509 :
2510 :
2511 0 : void SmXMLTableContext_Impl::EndElement()
2512 : {
2513 0 : SmNodeArray aExpressionArray;
2514 0 : SmNodeStack &rNodeStack = GetSmImport().GetNodeStack();
2515 0 : SmNodeStack aReverseStack;
2516 0 : aExpressionArray.resize(rNodeStack.size()-nElementCount);
2517 :
2518 0 : sal_uLong nRows = rNodeStack.size()-nElementCount;
2519 0 : sal_uInt16 nCols = 0;
2520 :
2521 : SmStructureNode *pArray;
2522 0 : for (sal_uLong i=nRows;i > 0;i--)
2523 : {
2524 0 : pArray = (SmStructureNode *)rNodeStack.top();
2525 0 : rNodeStack.pop();
2526 0 : if (pArray->GetNumSubNodes() == 0)
2527 : {
2528 : //This is a little tricky, it is possible that there was
2529 : //be elements that were not inside a <mtd> pair, in which
2530 : //case they will not be in a row, i.e. they will not have
2531 : //SubNodes, so we have to wait until here before we can
2532 : //resolve the situation. Implicitsurrounding tags are
2533 : //surprisingly difficult to get right within this
2534 : //architecture
2535 :
2536 0 : SmNodeArray aRelationArray;
2537 0 : aRelationArray.resize(1);
2538 0 : aRelationArray[0] = pArray;
2539 0 : SmToken aDummy;
2540 0 : pArray = new SmExpressionNode(aDummy);
2541 0 : pArray->SetSubNodes(aRelationArray);
2542 : }
2543 :
2544 0 : if (pArray->GetNumSubNodes() > nCols)
2545 0 : nCols = pArray->GetNumSubNodes();
2546 0 : aReverseStack.push(pArray);
2547 : }
2548 0 : aExpressionArray.resize(nCols*nRows);
2549 0 : sal_uLong j=0;
2550 0 : while ( !aReverseStack.empty() )
2551 : {
2552 0 : pArray = (SmStructureNode *)aReverseStack.top();
2553 0 : aReverseStack.pop();
2554 0 : for (sal_uInt16 i=0;i<pArray->GetNumSubNodes();i++)
2555 0 : aExpressionArray[j++] = pArray->GetSubNode(i);
2556 : }
2557 :
2558 0 : SmToken aToken;
2559 0 : aToken.cMathChar = '\0';
2560 0 : aToken.nGroup = TRGROUP;
2561 0 : aToken.eType = TMATRIX;
2562 0 : SmMatrixNode *pSNode = new SmMatrixNode(aToken);
2563 0 : pSNode->SetSubNodes(aExpressionArray);
2564 0 : pSNode->SetRowCol(static_cast<sal_uInt16>(nRows),nCols);
2565 0 : rNodeStack.push(pSNode);
2566 0 : }
2567 :
2568 0 : SvXMLImportContext *SmXMLTableRowContext_Impl::CreateChildContext(
2569 : sal_uInt16 nPrefix,
2570 : const OUString& rLocalName,
2571 : const uno::Reference<xml::sax::XAttributeList>& xAttrList)
2572 : {
2573 0 : SvXMLImportContext* pContext = 0L;
2574 :
2575 0 : const SvXMLTokenMap& rTokenMap = GetSmImport().
2576 0 : GetPresTableElemTokenMap();
2577 0 : switch(rTokenMap.Get(nPrefix, rLocalName))
2578 : {
2579 : case XML_TOK_MTD:
2580 0 : pContext = GetSmImport().CreateTableCellContext(nPrefix,
2581 0 : rLocalName, xAttrList);
2582 0 : break;
2583 : default:
2584 : pContext = SmXMLRowContext_Impl::CreateChildContext(nPrefix,
2585 0 : rLocalName,xAttrList);
2586 0 : break;
2587 : }
2588 0 : return pContext;
2589 : }
2590 :
2591 0 : SvXMLImportContext *SmXMLTableContext_Impl::CreateChildContext(
2592 : sal_uInt16 nPrefix,
2593 : const OUString& rLocalName,
2594 : const uno::Reference<xml::sax::XAttributeList>& xAttrList)
2595 : {
2596 0 : SvXMLImportContext* pContext = 0L;
2597 :
2598 0 : const SvXMLTokenMap& rTokenMap = GetSmImport().
2599 0 : GetPresTableElemTokenMap();
2600 0 : switch(rTokenMap.Get(nPrefix, rLocalName))
2601 : {
2602 : case XML_TOK_MTR:
2603 0 : pContext = GetSmImport().CreateTableRowContext(nPrefix,rLocalName,
2604 0 : xAttrList);
2605 0 : break;
2606 : default:
2607 : pContext = SmXMLTableRowContext_Impl::CreateChildContext(nPrefix,
2608 0 : rLocalName,xAttrList);
2609 0 : break;
2610 : }
2611 0 : return pContext;
2612 : }
2613 :
2614 0 : void SmXMLMultiScriptsContext_Impl::EndElement()
2615 : {
2616 0 : ProcessSubSupPairs(bHasPrescripts);
2617 0 : }
2618 :
2619 0 : void SmXMLActionContext_Impl::EndElement()
2620 : {
2621 : /*For now we will just assume that the
2622 : selected attribute is one, and then just display
2623 : that expression alone, i.e. remove all expect the
2624 : first pushed one*/
2625 :
2626 0 : SmNodeStack &rNodeStack = GetSmImport().GetNodeStack();
2627 0 : for (sal_uLong i=rNodeStack.size()-nElementCount;i > 1;i--)
2628 : {
2629 0 : delete rNodeStack.top();
2630 0 : rNodeStack.pop();
2631 : }
2632 0 : }
2633 :
2634 0 : SvXMLImportContext *SmXMLImport::CreateContext(sal_uInt16 nPrefix,
2635 : const OUString &rLocalName,
2636 : const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/)
2637 : {
2638 0 : if ( XML_NAMESPACE_OFFICE == nPrefix )
2639 : {
2640 0 : if ( (IsXMLToken(rLocalName, XML_DOCUMENT) ||
2641 0 : IsXMLToken(rLocalName, XML_DOCUMENT_META)))
2642 : {
2643 : uno::Reference<document::XDocumentPropertiesSupplier> xDPS(
2644 0 : GetModel(), uno::UNO_QUERY_THROW);
2645 0 : return IsXMLToken(rLocalName, XML_DOCUMENT_META)
2646 : ? new SvXMLMetaDocumentContext(*this,
2647 : XML_NAMESPACE_OFFICE, rLocalName,
2648 0 : xDPS->getDocumentProperties())
2649 : // flat OpenDocument file format -- this has not been tested...
2650 : : new SmXMLFlatDocContext_Impl( *this, nPrefix, rLocalName,
2651 0 : xDPS->getDocumentProperties());
2652 : }
2653 : else
2654 : {
2655 0 : return new SmXMLOfficeContext_Impl( *this,nPrefix,rLocalName);
2656 : }
2657 : }
2658 : else
2659 0 : return new SmXMLDocContext_Impl(*this,nPrefix,rLocalName);
2660 : }
2661 :
2662 0 : SvXMLImportContext *SmXMLImport::CreateRowContext(sal_uInt16 nPrefix,
2663 : const OUString &rLocalName,
2664 : const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/)
2665 : {
2666 0 : return new SmXMLRowContext_Impl(*this,nPrefix,rLocalName);
2667 : }
2668 :
2669 0 : SvXMLImportContext *SmXMLImport::CreateTextContext(sal_uInt16 nPrefix,
2670 : const OUString &rLocalName,
2671 : const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/)
2672 : {
2673 0 : return new SmXMLTextContext_Impl(*this,nPrefix,rLocalName);
2674 : }
2675 :
2676 0 : SvXMLImportContext *SmXMLImport::CreateAnnotationContext(sal_uInt16 nPrefix,
2677 : const OUString &rLocalName,
2678 : const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/)
2679 : {
2680 0 : return new SmXMLAnnotationContext_Impl(*this,nPrefix,rLocalName);
2681 : }
2682 :
2683 0 : SvXMLImportContext *SmXMLImport::CreateStringContext(sal_uInt16 nPrefix,
2684 : const OUString &rLocalName,
2685 : const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/)
2686 : {
2687 0 : return new SmXMLStringContext_Impl(*this,nPrefix,rLocalName);
2688 : }
2689 :
2690 0 : SvXMLImportContext *SmXMLImport::CreateNumberContext(sal_uInt16 nPrefix,
2691 : const OUString &rLocalName,
2692 : const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/)
2693 : {
2694 0 : return new SmXMLNumberContext_Impl(*this,nPrefix,rLocalName);
2695 : }
2696 :
2697 0 : SvXMLImportContext *SmXMLImport::CreateIdentifierContext(sal_uInt16 nPrefix,
2698 : const OUString &rLocalName,
2699 : const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/)
2700 : {
2701 0 : return new SmXMLIdentifierContext_Impl(*this,nPrefix,rLocalName);
2702 : }
2703 :
2704 0 : SvXMLImportContext *SmXMLImport::CreateOperatorContext(sal_uInt16 nPrefix,
2705 : const OUString &rLocalName,
2706 : const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/)
2707 : {
2708 0 : return new SmXMLOperatorContext_Impl(*this,nPrefix,rLocalName);
2709 : }
2710 :
2711 0 : SvXMLImportContext *SmXMLImport::CreateSpaceContext(sal_uInt16 nPrefix,
2712 : const OUString &rLocalName,
2713 : const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/)
2714 : {
2715 0 : return new SmXMLSpaceContext_Impl(*this,nPrefix,rLocalName);
2716 : }
2717 :
2718 :
2719 0 : SvXMLImportContext *SmXMLImport::CreateEncloseContext(sal_uInt16 nPrefix,
2720 : const OUString &rLocalName,
2721 : const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/)
2722 : {
2723 0 : return new SmXMLEncloseContext_Impl(*this,nPrefix,rLocalName);
2724 : }
2725 :
2726 0 : SvXMLImportContext *SmXMLImport::CreateFracContext(sal_uInt16 nPrefix,
2727 : const OUString &rLocalName,
2728 : const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/)
2729 : {
2730 0 : return new SmXMLFracContext_Impl(*this,nPrefix,rLocalName);
2731 : }
2732 :
2733 0 : SvXMLImportContext *SmXMLImport::CreateSqrtContext(sal_uInt16 nPrefix,
2734 : const OUString &rLocalName,
2735 : const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/)
2736 : {
2737 0 : return new SmXMLSqrtContext_Impl(*this,nPrefix,rLocalName);
2738 : }
2739 :
2740 0 : SvXMLImportContext *SmXMLImport::CreateRootContext(sal_uInt16 nPrefix,
2741 : const OUString &rLocalName,
2742 : const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/)
2743 : {
2744 0 : return new SmXMLRootContext_Impl(*this,nPrefix,rLocalName);
2745 : }
2746 :
2747 0 : SvXMLImportContext *SmXMLImport::CreateStyleContext(sal_uInt16 nPrefix,
2748 : const OUString &rLocalName,
2749 : const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/)
2750 : {
2751 0 : return new SmXMLStyleContext_Impl(*this,nPrefix,rLocalName);
2752 : }
2753 :
2754 0 : SvXMLImportContext *SmXMLImport::CreatePaddedContext(sal_uInt16 nPrefix,
2755 : const OUString &rLocalName,
2756 : const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/)
2757 : {
2758 0 : return new SmXMLPaddedContext_Impl(*this,nPrefix,rLocalName);
2759 : }
2760 :
2761 0 : SvXMLImportContext *SmXMLImport::CreatePhantomContext(sal_uInt16 nPrefix,
2762 : const OUString &rLocalName,
2763 : const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/)
2764 : {
2765 0 : return new SmXMLPhantomContext_Impl(*this,nPrefix,rLocalName);
2766 : }
2767 :
2768 0 : SvXMLImportContext *SmXMLImport::CreateFencedContext(sal_uInt16 nPrefix,
2769 : const OUString &rLocalName,
2770 : const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/)
2771 : {
2772 0 : return new SmXMLFencedContext_Impl(*this,nPrefix,rLocalName);
2773 : }
2774 :
2775 0 : SvXMLImportContext *SmXMLImport::CreateErrorContext(sal_uInt16 nPrefix,
2776 : const OUString &rLocalName,
2777 : const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/)
2778 : {
2779 0 : return new SmXMLErrorContext_Impl(*this,nPrefix,rLocalName);
2780 : }
2781 :
2782 0 : SvXMLImportContext *SmXMLImport::CreateSubContext(sal_uInt16 nPrefix,
2783 : const OUString &rLocalName,
2784 : const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/)
2785 : {
2786 0 : return new SmXMLSubContext_Impl(*this,nPrefix,rLocalName);
2787 : }
2788 :
2789 0 : SvXMLImportContext *SmXMLImport::CreateSubSupContext(sal_uInt16 nPrefix,
2790 : const OUString &rLocalName,
2791 : const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/)
2792 : {
2793 0 : return new SmXMLSubSupContext_Impl(*this,nPrefix,rLocalName);
2794 : }
2795 :
2796 0 : SvXMLImportContext *SmXMLImport::CreateSupContext(sal_uInt16 nPrefix,
2797 : const OUString &rLocalName,
2798 : const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/)
2799 : {
2800 0 : return new SmXMLSupContext_Impl(*this,nPrefix,rLocalName);
2801 : }
2802 :
2803 0 : SvXMLImportContext *SmXMLImport::CreateUnderContext(sal_uInt16 nPrefix,
2804 : const OUString &rLocalName,
2805 : const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/)
2806 : {
2807 0 : return new SmXMLUnderContext_Impl(*this,nPrefix,rLocalName);
2808 : }
2809 :
2810 0 : SvXMLImportContext *SmXMLImport::CreateOverContext(sal_uInt16 nPrefix,
2811 : const OUString &rLocalName,
2812 : const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/)
2813 : {
2814 0 : return new SmXMLOverContext_Impl(*this,nPrefix,rLocalName);
2815 : }
2816 :
2817 0 : SvXMLImportContext *SmXMLImport::CreateUnderOverContext(sal_uInt16 nPrefix,
2818 : const OUString &rLocalName,
2819 : const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/)
2820 : {
2821 0 : return new SmXMLUnderOverContext_Impl(*this,nPrefix,rLocalName);
2822 : }
2823 :
2824 0 : SvXMLImportContext *SmXMLImport::CreateMultiScriptsContext(sal_uInt16 nPrefix,
2825 : const OUString &rLocalName,
2826 : const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/)
2827 : {
2828 0 : return new SmXMLMultiScriptsContext_Impl(*this,nPrefix,rLocalName);
2829 : }
2830 :
2831 0 : SvXMLImportContext *SmXMLImport::CreateTableContext(sal_uInt16 nPrefix,
2832 : const OUString &rLocalName,
2833 : const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/)
2834 : {
2835 0 : return new SmXMLTableContext_Impl(*this,nPrefix,rLocalName);
2836 : }
2837 0 : SvXMLImportContext *SmXMLImport::CreateTableRowContext(sal_uInt16 nPrefix,
2838 : const OUString &rLocalName,
2839 : const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/)
2840 : {
2841 0 : return new SmXMLTableRowContext_Impl(*this,nPrefix,rLocalName);
2842 : }
2843 0 : SvXMLImportContext *SmXMLImport::CreateTableCellContext(sal_uInt16 nPrefix,
2844 : const OUString &rLocalName,
2845 : const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/)
2846 : {
2847 0 : return new SmXMLTableCellContext_Impl(*this,nPrefix,rLocalName);
2848 : }
2849 :
2850 0 : SvXMLImportContext *SmXMLImport::CreateNoneContext(sal_uInt16 nPrefix,
2851 : const OUString &rLocalName,
2852 : const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/)
2853 : {
2854 0 : return new SmXMLNoneContext_Impl(*this,nPrefix,rLocalName);
2855 : }
2856 :
2857 0 : SvXMLImportContext *SmXMLImport::CreatePrescriptsContext(sal_uInt16 nPrefix,
2858 : const OUString &rLocalName,
2859 : const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/)
2860 : {
2861 0 : return new SmXMLPrescriptsContext_Impl(*this,nPrefix,rLocalName);
2862 : }
2863 :
2864 0 : SvXMLImportContext *SmXMLImport::CreateAlignGroupContext(sal_uInt16 nPrefix,
2865 : const OUString &rLocalName,
2866 : const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/)
2867 : {
2868 0 : return new SmXMLAlignGroupContext_Impl(*this,nPrefix,rLocalName);
2869 : }
2870 :
2871 0 : SvXMLImportContext *SmXMLImport::CreateActionContext(sal_uInt16 nPrefix,
2872 : const OUString &rLocalName,
2873 : const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/)
2874 : {
2875 0 : return new SmXMLActionContext_Impl(*this,nPrefix,rLocalName);
2876 : }
2877 :
2878 18 : SmXMLImport::~SmXMLImport() throw ()
2879 : {
2880 6 : delete pPresLayoutElemTokenMap;
2881 6 : delete pPresElemTokenMap;
2882 6 : delete pPresScriptEmptyElemTokenMap;
2883 6 : delete pPresTableElemTokenMap;
2884 6 : delete pPresLayoutAttrTokenMap;
2885 6 : delete pFencedAttrTokenMap;
2886 6 : delete pColorTokenMap;
2887 6 : delete pOperatorAttrTokenMap;
2888 6 : delete pAnnotationAttrTokenMap;
2889 12 : }
2890 :
2891 0 : void SmXMLImport::SetViewSettings(const Sequence<PropertyValue>& aViewProps)
2892 : {
2893 0 : uno::Reference <frame::XModel> xModel = GetModel();
2894 0 : if ( !xModel.is() )
2895 0 : return;
2896 :
2897 0 : uno::Reference <lang::XUnoTunnel> xTunnel;
2898 0 : xTunnel = uno::Reference <lang::XUnoTunnel> (xModel,uno::UNO_QUERY);
2899 : SmModel *pModel = reinterpret_cast<SmModel *>
2900 0 : (xTunnel->getSomething(SmModel::getUnoTunnelId()));
2901 :
2902 0 : if ( !pModel )
2903 0 : return;
2904 :
2905 : SmDocShell *pDocShell =
2906 0 : static_cast<SmDocShell*>(pModel->GetObjectShell());
2907 0 : if ( !pDocShell )
2908 0 : return;
2909 :
2910 0 : Rectangle aRect( pDocShell->GetVisArea() );
2911 :
2912 0 : sal_Int32 nCount = aViewProps.getLength();
2913 0 : const PropertyValue *pValue = aViewProps.getConstArray();
2914 :
2915 0 : long nTmp = 0;
2916 :
2917 0 : for (sal_Int32 i = 0; i < nCount ; i++)
2918 : {
2919 0 : if (pValue->Name == "ViewAreaTop" )
2920 : {
2921 0 : pValue->Value >>= nTmp;
2922 0 : aRect.setY( nTmp );
2923 : }
2924 0 : else if (pValue->Name == "ViewAreaLeft" )
2925 : {
2926 0 : pValue->Value >>= nTmp;
2927 0 : aRect.setX( nTmp );
2928 : }
2929 0 : else if (pValue->Name == "ViewAreaWidth" )
2930 : {
2931 0 : pValue->Value >>= nTmp;
2932 0 : Size aSize( aRect.GetSize() );
2933 0 : aSize.Width() = nTmp;
2934 0 : aRect.SetSize( aSize );
2935 : }
2936 0 : else if (pValue->Name == "ViewAreaHeight" )
2937 : {
2938 0 : pValue->Value >>= nTmp;
2939 0 : Size aSize( aRect.GetSize() );
2940 0 : aSize.Height() = nTmp;
2941 0 : aRect.SetSize( aSize );
2942 : }
2943 0 : pValue++;
2944 : }
2945 :
2946 0 : pDocShell->SetVisArea ( aRect );
2947 : }
2948 :
2949 0 : void SmXMLImport::SetConfigurationSettings(const Sequence<PropertyValue>& aConfProps)
2950 : {
2951 0 : uno::Reference < XPropertySet > xProps ( GetModel(), UNO_QUERY );
2952 0 : if ( xProps.is() )
2953 : {
2954 0 : Reference < XPropertySetInfo > xInfo ( xProps->getPropertySetInfo() );
2955 0 : if (xInfo.is() )
2956 : {
2957 0 : sal_Int32 nCount = aConfProps.getLength();
2958 0 : const PropertyValue* pValues = aConfProps.getConstArray();
2959 :
2960 0 : const OUString sFormula ( "Formula" );
2961 0 : const OUString sBasicLibraries ( "BasicLibraries" );
2962 0 : const OUString sDialogLibraries ( "DialogLibraries" );
2963 0 : while ( nCount-- )
2964 : {
2965 0 : if (pValues->Name != sFormula &&
2966 0 : pValues->Name != sBasicLibraries &&
2967 0 : pValues->Name != sDialogLibraries)
2968 : {
2969 : try
2970 : {
2971 0 : if ( xInfo->hasPropertyByName( pValues->Name ) )
2972 0 : xProps->setPropertyValue( pValues->Name, pValues->Value );
2973 : }
2974 0 : catch (const beans::PropertyVetoException &)
2975 : {
2976 : // dealing with read-only properties here. Nothing to do...
2977 : }
2978 0 : catch( Exception& )
2979 : {
2980 : OSL_FAIL( "SmXMLImport::SetConfigurationSettings: Exception!" );
2981 : }
2982 : }
2983 :
2984 0 : pValues++;
2985 0 : }
2986 0 : }
2987 0 : }
2988 21 : }
2989 :
2990 :
2991 : ////////////////////////////////////////////////////////////
2992 :
2993 :
2994 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|