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