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