1*ca5ec200SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*ca5ec200SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*ca5ec200SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*ca5ec200SAndrew Rist * distributed with this work for additional information 6*ca5ec200SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*ca5ec200SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*ca5ec200SAndrew Rist * "License"); you may not use this file except in compliance 9*ca5ec200SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*ca5ec200SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*ca5ec200SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*ca5ec200SAndrew Rist * software distributed under the License is distributed on an 15*ca5ec200SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*ca5ec200SAndrew Rist * KIND, either express or implied. See the License for the 17*ca5ec200SAndrew Rist * specific language governing permissions and limitations 18*ca5ec200SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*ca5ec200SAndrew Rist *************************************************************/ 21*ca5ec200SAndrew Rist 22*ca5ec200SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #include "ShapeContextHandler.hxx" 25cdf0e10cSrcweir #include "oox/vml/vmldrawingfragment.hxx" 26cdf0e10cSrcweir #include "oox/vml/vmlshape.hxx" 27cdf0e10cSrcweir #include "oox/vml/vmlshapecontainer.hxx" 28cdf0e10cSrcweir 29cdf0e10cSrcweir namespace oox { namespace shape { 30cdf0e10cSrcweir 31cdf0e10cSrcweir using namespace ::com::sun::star; 32cdf0e10cSrcweir using namespace core; 33cdf0e10cSrcweir using namespace drawingml; 34cdf0e10cSrcweir 35cdf0e10cSrcweir ::rtl::OUString SAL_CALL ShapeContextHandler_getImplementationName() 36cdf0e10cSrcweir { 37cdf0e10cSrcweir return CREATE_OUSTRING( "com.sun.star.comp.oox.ShapeContextHandler" ); 38cdf0e10cSrcweir } 39cdf0e10cSrcweir 40cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > SAL_CALL 41cdf0e10cSrcweir ShapeContextHandler_getSupportedServiceNames() 42cdf0e10cSrcweir { 43cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > s(1); 44cdf0e10cSrcweir s[0] = CREATE_OUSTRING( "com.sun.star.xml.sax.FastShapeContextHandler" ); 45cdf0e10cSrcweir return s; 46cdf0e10cSrcweir } 47cdf0e10cSrcweir 48cdf0e10cSrcweir uno::Reference< uno::XInterface > SAL_CALL 49cdf0e10cSrcweir ShapeContextHandler_createInstance( const uno::Reference< uno::XComponentContext > & context) 50cdf0e10cSrcweir SAL_THROW((uno::Exception)) 51cdf0e10cSrcweir { 52cdf0e10cSrcweir return static_cast< ::cppu::OWeakObject* >( new ShapeContextHandler(context) ); 53cdf0e10cSrcweir } 54cdf0e10cSrcweir 55cdf0e10cSrcweir 56cdf0e10cSrcweir ShapeContextHandler::ShapeContextHandler 57cdf0e10cSrcweir (uno::Reference< uno::XComponentContext > const & context) : 58cdf0e10cSrcweir mnStartToken(0), m_xContext(context) 59cdf0e10cSrcweir { 60cdf0e10cSrcweir try 61cdf0e10cSrcweir { 62cdf0e10cSrcweir mxFilterBase.set( new ShapeFilterBase(context) ); 63cdf0e10cSrcweir } 64cdf0e10cSrcweir catch( uno::Exception& ) 65cdf0e10cSrcweir { 66cdf0e10cSrcweir } 67cdf0e10cSrcweir } 68cdf0e10cSrcweir 69cdf0e10cSrcweir ShapeContextHandler::~ShapeContextHandler() 70cdf0e10cSrcweir { 71cdf0e10cSrcweir } 72cdf0e10cSrcweir 73cdf0e10cSrcweir uno::Reference<xml::sax::XFastContextHandler> 74cdf0e10cSrcweir ShapeContextHandler::getGraphicShapeContext(::sal_Int32 Element ) 75cdf0e10cSrcweir { 76cdf0e10cSrcweir if (! mxGraphicShapeContext.is()) 77cdf0e10cSrcweir { 78cdf0e10cSrcweir FragmentHandlerRef rFragmentHandler 79cdf0e10cSrcweir (new ShapeFragmentHandler(*mxFilterBase, msRelationFragmentPath)); 80cdf0e10cSrcweir ShapePtr pMasterShape; 81cdf0e10cSrcweir 82cdf0e10cSrcweir switch (Element & 0xffff) 83cdf0e10cSrcweir { 84cdf0e10cSrcweir case XML_graphic: 85cdf0e10cSrcweir mpShape.reset(new Shape("com.sun.star.drawing.GraphicObjectShape" )); 86cdf0e10cSrcweir mxGraphicShapeContext.set 87cdf0e10cSrcweir (new GraphicalObjectFrameContext(*rFragmentHandler, pMasterShape, mpShape, true)); 88cdf0e10cSrcweir break; 89cdf0e10cSrcweir case XML_pic: 90cdf0e10cSrcweir mpShape.reset(new Shape("com.sun.star.drawing.GraphicObjectShape" )); 91cdf0e10cSrcweir mxGraphicShapeContext.set 92cdf0e10cSrcweir (new GraphicShapeContext(*rFragmentHandler, pMasterShape, mpShape)); 93cdf0e10cSrcweir break; 94cdf0e10cSrcweir default: 95cdf0e10cSrcweir break; 96cdf0e10cSrcweir } 97cdf0e10cSrcweir } 98cdf0e10cSrcweir 99cdf0e10cSrcweir return mxGraphicShapeContext; 100cdf0e10cSrcweir } 101cdf0e10cSrcweir 102cdf0e10cSrcweir uno::Reference<xml::sax::XFastContextHandler> 103cdf0e10cSrcweir ShapeContextHandler::getDrawingShapeContext() 104cdf0e10cSrcweir { 105cdf0e10cSrcweir if (!mxDrawingFragmentHandler.is()) 106cdf0e10cSrcweir { 107cdf0e10cSrcweir mpDrawing.reset( new oox::vml::Drawing( *mxFilterBase, mxDrawPage, oox::vml::VMLDRAWING_WORD ) ); 108cdf0e10cSrcweir mxDrawingFragmentHandler.set 109cdf0e10cSrcweir (dynamic_cast<ContextHandler *> 110cdf0e10cSrcweir (new oox::vml::DrawingFragment 111cdf0e10cSrcweir ( *mxFilterBase, msRelationFragmentPath, *mpDrawing ))); 112cdf0e10cSrcweir } 113cdf0e10cSrcweir 114cdf0e10cSrcweir return mxDrawingFragmentHandler; 115cdf0e10cSrcweir } 116cdf0e10cSrcweir 117cdf0e10cSrcweir uno::Reference<xml::sax::XFastContextHandler> 118cdf0e10cSrcweir ShapeContextHandler::getContextHandler() 119cdf0e10cSrcweir { 120cdf0e10cSrcweir uno::Reference<xml::sax::XFastContextHandler> xResult; 121cdf0e10cSrcweir 122cdf0e10cSrcweir switch (getNamespace( mnStartToken )) 123cdf0e10cSrcweir { 124cdf0e10cSrcweir case NMSP_doc: 125cdf0e10cSrcweir case NMSP_vml: 126cdf0e10cSrcweir xResult.set(getDrawingShapeContext()); 127cdf0e10cSrcweir break; 128cdf0e10cSrcweir default: 129cdf0e10cSrcweir xResult.set(getGraphicShapeContext(mnStartToken)); 130cdf0e10cSrcweir break; 131cdf0e10cSrcweir } 132cdf0e10cSrcweir 133cdf0e10cSrcweir return xResult; 134cdf0e10cSrcweir } 135cdf0e10cSrcweir 136cdf0e10cSrcweir // ::com::sun::star::xml::sax::XFastContextHandler: 137cdf0e10cSrcweir void SAL_CALL ShapeContextHandler::startFastElement 138cdf0e10cSrcweir (::sal_Int32 Element, 139cdf0e10cSrcweir const uno::Reference< xml::sax::XFastAttributeList > & Attribs) 140cdf0e10cSrcweir throw (uno::RuntimeException, xml::sax::SAXException) 141cdf0e10cSrcweir { 142cdf0e10cSrcweir static const ::rtl::OUString sInputStream 143cdf0e10cSrcweir (RTL_CONSTASCII_USTRINGPARAM ("InputStream")); 144cdf0e10cSrcweir 145cdf0e10cSrcweir uno::Sequence<beans::PropertyValue> aSeq(1); 146cdf0e10cSrcweir aSeq[0].Name = sInputStream; 147cdf0e10cSrcweir aSeq[0].Value <<= mxInputStream; 148cdf0e10cSrcweir mxFilterBase->filter(aSeq); 149cdf0e10cSrcweir 150cdf0e10cSrcweir mpThemePtr.reset(new Theme()); 151cdf0e10cSrcweir 152cdf0e10cSrcweir uno::Reference<XFastContextHandler> xContextHandler(getContextHandler()); 153cdf0e10cSrcweir 154cdf0e10cSrcweir if (xContextHandler.is()) 155cdf0e10cSrcweir xContextHandler->startFastElement(Element, Attribs); 156cdf0e10cSrcweir } 157cdf0e10cSrcweir 158cdf0e10cSrcweir void SAL_CALL ShapeContextHandler::startUnknownElement 159cdf0e10cSrcweir (const ::rtl::OUString & Namespace, const ::rtl::OUString & Name, 160cdf0e10cSrcweir const uno::Reference< xml::sax::XFastAttributeList > & Attribs) 161cdf0e10cSrcweir throw (uno::RuntimeException, xml::sax::SAXException) 162cdf0e10cSrcweir { 163cdf0e10cSrcweir uno::Reference<XFastContextHandler> xContextHandler(getContextHandler()); 164cdf0e10cSrcweir 165cdf0e10cSrcweir if (xContextHandler.is()) 166cdf0e10cSrcweir xContextHandler->startUnknownElement(Namespace, Name, Attribs); 167cdf0e10cSrcweir } 168cdf0e10cSrcweir 169cdf0e10cSrcweir void SAL_CALL ShapeContextHandler::endFastElement(::sal_Int32 Element) 170cdf0e10cSrcweir throw (uno::RuntimeException, xml::sax::SAXException) 171cdf0e10cSrcweir { 172cdf0e10cSrcweir uno::Reference<XFastContextHandler> xContextHandler(getContextHandler()); 173cdf0e10cSrcweir 174cdf0e10cSrcweir if (xContextHandler.is()) 175cdf0e10cSrcweir xContextHandler->endFastElement(Element); 176cdf0e10cSrcweir } 177cdf0e10cSrcweir 178cdf0e10cSrcweir void SAL_CALL ShapeContextHandler::endUnknownElement 179cdf0e10cSrcweir (const ::rtl::OUString & Namespace, 180cdf0e10cSrcweir const ::rtl::OUString & Name) 181cdf0e10cSrcweir throw (uno::RuntimeException, xml::sax::SAXException) 182cdf0e10cSrcweir { 183cdf0e10cSrcweir uno::Reference<XFastContextHandler> xContextHandler(getContextHandler()); 184cdf0e10cSrcweir 185cdf0e10cSrcweir if (xContextHandler.is()) 186cdf0e10cSrcweir xContextHandler->endUnknownElement(Namespace, Name); 187cdf0e10cSrcweir } 188cdf0e10cSrcweir 189cdf0e10cSrcweir uno::Reference< xml::sax::XFastContextHandler > SAL_CALL 190cdf0e10cSrcweir ShapeContextHandler::createFastChildContext 191cdf0e10cSrcweir (::sal_Int32 Element, 192cdf0e10cSrcweir const uno::Reference< xml::sax::XFastAttributeList > & Attribs) 193cdf0e10cSrcweir throw (uno::RuntimeException, xml::sax::SAXException) 194cdf0e10cSrcweir { 195cdf0e10cSrcweir uno::Reference< xml::sax::XFastContextHandler > xResult; 196cdf0e10cSrcweir uno::Reference< xml::sax::XFastContextHandler > xContextHandler(getContextHandler()); 197cdf0e10cSrcweir 198cdf0e10cSrcweir if (xContextHandler.is()) 199cdf0e10cSrcweir xResult.set(xContextHandler->createFastChildContext 200cdf0e10cSrcweir (Element, Attribs)); 201cdf0e10cSrcweir 202cdf0e10cSrcweir return xResult; 203cdf0e10cSrcweir } 204cdf0e10cSrcweir 205cdf0e10cSrcweir uno::Reference< xml::sax::XFastContextHandler > SAL_CALL 206cdf0e10cSrcweir ShapeContextHandler::createUnknownChildContext 207cdf0e10cSrcweir (const ::rtl::OUString & Namespace, 208cdf0e10cSrcweir const ::rtl::OUString & Name, 209cdf0e10cSrcweir const uno::Reference< xml::sax::XFastAttributeList > & Attribs) 210cdf0e10cSrcweir throw (uno::RuntimeException, xml::sax::SAXException) 211cdf0e10cSrcweir { 212cdf0e10cSrcweir uno::Reference<XFastContextHandler> xContextHandler(getContextHandler()); 213cdf0e10cSrcweir 214cdf0e10cSrcweir if (xContextHandler.is()) 215cdf0e10cSrcweir return xContextHandler->createUnknownChildContext 216cdf0e10cSrcweir (Namespace, Name, Attribs); 217cdf0e10cSrcweir 218cdf0e10cSrcweir return uno::Reference< xml::sax::XFastContextHandler >(); 219cdf0e10cSrcweir } 220cdf0e10cSrcweir 221cdf0e10cSrcweir void SAL_CALL ShapeContextHandler::characters(const ::rtl::OUString & aChars) 222cdf0e10cSrcweir throw (uno::RuntimeException, xml::sax::SAXException) 223cdf0e10cSrcweir { 224cdf0e10cSrcweir uno::Reference<XFastContextHandler> xContextHandler(getContextHandler()); 225cdf0e10cSrcweir 226cdf0e10cSrcweir if (xContextHandler.is()) 227cdf0e10cSrcweir xContextHandler->characters(aChars); 228cdf0e10cSrcweir } 229cdf0e10cSrcweir 230cdf0e10cSrcweir // ::com::sun::star::xml::sax::XFastShapeContextHandler: 231cdf0e10cSrcweir uno::Reference< drawing::XShape > SAL_CALL 232cdf0e10cSrcweir ShapeContextHandler::getShape() throw (uno::RuntimeException) 233cdf0e10cSrcweir { 234cdf0e10cSrcweir uno::Reference< drawing::XShape > xResult; 235cdf0e10cSrcweir uno::Reference< drawing::XShapes > xShapes( mxDrawPage, uno::UNO_QUERY ); 236cdf0e10cSrcweir 237cdf0e10cSrcweir if (mxFilterBase.is() && xShapes.is()) 238cdf0e10cSrcweir { 239cdf0e10cSrcweir if (mpDrawing.get() != NULL) 240cdf0e10cSrcweir { 241cdf0e10cSrcweir mpDrawing->finalizeFragmentImport(); 242cdf0e10cSrcweir if( const ::oox::vml::ShapeBase* pShape = mpDrawing->getShapes().getFirstShape() ) 243cdf0e10cSrcweir xResult = pShape->convertAndInsert( xShapes ); 244cdf0e10cSrcweir } 245cdf0e10cSrcweir else if (mpShape.get() != NULL) 246cdf0e10cSrcweir { 247cdf0e10cSrcweir mpShape->addShape(*mxFilterBase, mpThemePtr.get(), xShapes); 248cdf0e10cSrcweir xResult.set(mpShape->getXShape()); 249cdf0e10cSrcweir mxGraphicShapeContext.clear( ); 250cdf0e10cSrcweir } 251cdf0e10cSrcweir } 252cdf0e10cSrcweir 253cdf0e10cSrcweir return xResult; 254cdf0e10cSrcweir } 255cdf0e10cSrcweir 256cdf0e10cSrcweir css::uno::Reference< css::drawing::XDrawPage > SAL_CALL 257cdf0e10cSrcweir ShapeContextHandler::getDrawPage() throw (css::uno::RuntimeException) 258cdf0e10cSrcweir { 259cdf0e10cSrcweir return mxDrawPage; 260cdf0e10cSrcweir } 261cdf0e10cSrcweir 262cdf0e10cSrcweir void SAL_CALL ShapeContextHandler::setDrawPage 263cdf0e10cSrcweir (const css::uno::Reference< css::drawing::XDrawPage > & the_value) 264cdf0e10cSrcweir throw (css::uno::RuntimeException) 265cdf0e10cSrcweir { 266cdf0e10cSrcweir mxDrawPage = the_value; 267cdf0e10cSrcweir } 268cdf0e10cSrcweir 269cdf0e10cSrcweir css::uno::Reference< css::frame::XModel > SAL_CALL 270cdf0e10cSrcweir ShapeContextHandler::getModel() throw (css::uno::RuntimeException) 271cdf0e10cSrcweir { 272cdf0e10cSrcweir if( !mxFilterBase.is() ) 273cdf0e10cSrcweir throw uno::RuntimeException(); 274cdf0e10cSrcweir return mxFilterBase->getModel(); 275cdf0e10cSrcweir } 276cdf0e10cSrcweir 277cdf0e10cSrcweir void SAL_CALL ShapeContextHandler::setModel 278cdf0e10cSrcweir (const css::uno::Reference< css::frame::XModel > & the_value) 279cdf0e10cSrcweir throw (css::uno::RuntimeException) 280cdf0e10cSrcweir { 281cdf0e10cSrcweir if( !mxFilterBase.is() ) 282cdf0e10cSrcweir throw uno::RuntimeException(); 283cdf0e10cSrcweir uno::Reference<lang::XComponent> xComp(the_value, uno::UNO_QUERY_THROW); 284cdf0e10cSrcweir mxFilterBase->setTargetDocument(xComp); 285cdf0e10cSrcweir } 286cdf0e10cSrcweir 287cdf0e10cSrcweir uno::Reference< io::XInputStream > SAL_CALL 288cdf0e10cSrcweir ShapeContextHandler::getInputStream() throw (uno::RuntimeException) 289cdf0e10cSrcweir { 290cdf0e10cSrcweir return mxInputStream; 291cdf0e10cSrcweir } 292cdf0e10cSrcweir 293cdf0e10cSrcweir void SAL_CALL ShapeContextHandler::setInputStream 294cdf0e10cSrcweir (const uno::Reference< io::XInputStream > & the_value) 295cdf0e10cSrcweir throw (uno::RuntimeException) 296cdf0e10cSrcweir { 297cdf0e10cSrcweir mxInputStream = the_value; 298cdf0e10cSrcweir } 299cdf0e10cSrcweir 300cdf0e10cSrcweir ::rtl::OUString SAL_CALL ShapeContextHandler::getRelationFragmentPath() 301cdf0e10cSrcweir throw (uno::RuntimeException) 302cdf0e10cSrcweir { 303cdf0e10cSrcweir return msRelationFragmentPath; 304cdf0e10cSrcweir } 305cdf0e10cSrcweir 306cdf0e10cSrcweir void SAL_CALL ShapeContextHandler::setRelationFragmentPath 307cdf0e10cSrcweir (const ::rtl::OUString & the_value) 308cdf0e10cSrcweir throw (uno::RuntimeException) 309cdf0e10cSrcweir { 310cdf0e10cSrcweir msRelationFragmentPath = the_value; 311cdf0e10cSrcweir } 312cdf0e10cSrcweir 313cdf0e10cSrcweir ::sal_Int32 SAL_CALL ShapeContextHandler::getStartToken() throw (::com::sun::star::uno::RuntimeException) 314cdf0e10cSrcweir { 315cdf0e10cSrcweir return mnStartToken; 316cdf0e10cSrcweir } 317cdf0e10cSrcweir 318cdf0e10cSrcweir void SAL_CALL ShapeContextHandler::setStartToken( ::sal_Int32 _starttoken ) throw (::com::sun::star::uno::RuntimeException) 319cdf0e10cSrcweir { 320cdf0e10cSrcweir mnStartToken = _starttoken; 321cdf0e10cSrcweir 322cdf0e10cSrcweir 323cdf0e10cSrcweir } 324cdf0e10cSrcweir 325cdf0e10cSrcweir ::rtl::OUString ShapeContextHandler::getImplementationName() 326cdf0e10cSrcweir throw (css::uno::RuntimeException) 327cdf0e10cSrcweir { 328cdf0e10cSrcweir return ShapeContextHandler_getImplementationName(); 329cdf0e10cSrcweir } 330cdf0e10cSrcweir 331cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > ShapeContextHandler::getSupportedServiceNames() 332cdf0e10cSrcweir throw (css::uno::RuntimeException) 333cdf0e10cSrcweir { 334cdf0e10cSrcweir return ShapeContextHandler_getSupportedServiceNames(); 335cdf0e10cSrcweir } 336cdf0e10cSrcweir 337cdf0e10cSrcweir ::sal_Bool SAL_CALL ShapeContextHandler::supportsService 338cdf0e10cSrcweir (const ::rtl::OUString & ServiceName) throw (css::uno::RuntimeException) 339cdf0e10cSrcweir { 340cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > aSeq = getSupportedServiceNames(); 341cdf0e10cSrcweir 342cdf0e10cSrcweir if (aSeq[0].equals(ServiceName)) 343cdf0e10cSrcweir return sal_True; 344cdf0e10cSrcweir 345cdf0e10cSrcweir return sal_False; 346cdf0e10cSrcweir } 347cdf0e10cSrcweir 348cdf0e10cSrcweir }} 349