LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/xmloff/source/draw - ximppage.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 135 274 49.3 %
Date: 2013-07-09 Functions: 10 28 35.7 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <com/sun/star/geometry/RealPoint2D.hpp>
      21             : #include <com/sun/star/text/XTextCursor.hpp>
      22             : #include <com/sun/star/util/DateTime.hpp>
      23             : #include <cppuhelper/implbase1.hxx>
      24             : #include <sax/tools/converter.hxx>
      25             : #include "XMLNumberStylesImport.hxx"
      26             : #include <xmloff/xmlstyle.hxx>
      27             : #include <xmloff/xmltoken.hxx>
      28             : #include "xmloff/xmlnmspe.hxx"
      29             : #include "ximppage.hxx"
      30             : #include "ximpshap.hxx"
      31             : #include "animimp.hxx"
      32             : #include "XMLStringBufferImportContext.hxx"
      33             : #include <xmloff/xmlictxt.hxx>
      34             : #include "ximpstyl.hxx"
      35             : #include <xmloff/prstylei.hxx>
      36             : #include "PropertySetMerger.hxx"
      37             : 
      38             : #include <xmloff/unointerfacetouniqueidentifiermapper.hxx>
      39             : #include <xmloff/xmluconv.hxx>
      40             : 
      41             : 
      42             : using namespace ::com::sun::star;
      43             : using namespace ::xmloff::token;
      44             : using namespace ::com::sun::star::uno;
      45             : using namespace ::com::sun::star::lang;
      46             : using namespace ::com::sun::star::text;
      47             : using namespace ::com::sun::star::util;
      48             : using namespace ::com::sun::star::beans;
      49             : using namespace ::com::sun::star::drawing;
      50             : using namespace ::com::sun::star::container;
      51             : using namespace ::com::sun::star::office;
      52             : using namespace ::com::sun::star::xml::sax;
      53             : using namespace ::com::sun::star::geometry;
      54             : 
      55             : 
      56             : //////////////////////////////////////////////////////////////////////////////
      57             : 
      58           0 : class DrawAnnotationContext : public SvXMLImportContext
      59             : {
      60             : 
      61             : public:
      62             :     DrawAnnotationContext( SvXMLImport& rImport, sal_uInt16 nPrfx, const OUString& rLocalName,const Reference< xml::sax::XAttributeList>& xAttrList, const Reference< XAnnotationAccess >& xAnnotationAccess );
      63             : 
      64             :     virtual SvXMLImportContext * CreateChildContext( sal_uInt16 nPrefix, const OUString& rLocalName, const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList );
      65             :     virtual void EndElement();
      66             : 
      67             : private:
      68             :     Reference< XAnnotation > mxAnnotation;
      69             :     Reference< XTextCursor > mxCursor;
      70             : 
      71             :     OUStringBuffer maAuthorBuffer;
      72             :     OUStringBuffer maDateBuffer;
      73             : };
      74             : 
      75           0 : DrawAnnotationContext::DrawAnnotationContext( SvXMLImport& rImport, sal_uInt16 nPrfx, const OUString& rLocalName,const Reference< xml::sax::XAttributeList>& xAttrList, const Reference< XAnnotationAccess >& xAnnotationAccess )
      76             : : SvXMLImportContext( rImport, nPrfx, rLocalName )
      77           0 : , mxAnnotation( xAnnotationAccess->createAndInsertAnnotation() )
      78             : {
      79           0 :     if( mxAnnotation.is() )
      80             :     {
      81           0 :         sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
      82             : 
      83           0 :         RealPoint2D aPosition;
      84           0 :         RealSize2D aSize;
      85             : 
      86           0 :         for(sal_Int16 i=0; i < nAttrCount; i++)
      87             :         {
      88           0 :             OUString sValue( xAttrList->getValueByIndex( i ) );
      89           0 :             OUString sAttrName( xAttrList->getNameByIndex( i ) );
      90           0 :             OUString aLocalName;
      91           0 :             switch( GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName ) )
      92             :             {
      93             :             case XML_NAMESPACE_SVG:
      94           0 :                 if( IsXMLToken( aLocalName, XML_X ) )
      95             :                 {
      96             :                     sal_Int32 x;
      97           0 :                     GetImport().GetMM100UnitConverter().convertMeasureToCore(
      98           0 :                             x, sValue);
      99           0 :                     aPosition.X = static_cast<double>(x) / 100.0;
     100             :                 }
     101           0 :                 else if( IsXMLToken( aLocalName, XML_Y ) )
     102             :                 {
     103             :                     sal_Int32 y;
     104           0 :                     GetImport().GetMM100UnitConverter().convertMeasureToCore(
     105           0 :                             y, sValue);
     106           0 :                     aPosition.Y = static_cast<double>(y) / 100.0;
     107             :                 }
     108           0 :                 else if( IsXMLToken( aLocalName, XML_WIDTH ) )
     109             :                 {
     110             :                     sal_Int32 w;
     111           0 :                     GetImport().GetMM100UnitConverter().convertMeasureToCore(
     112           0 :                             w, sValue);
     113           0 :                     aSize.Width = static_cast<double>(w) / 100.0;
     114             :                 }
     115           0 :                 else if( IsXMLToken( aLocalName, XML_HEIGHT ) )
     116             :                 {
     117             :                     sal_Int32 h;
     118           0 :                     GetImport().GetMM100UnitConverter().convertMeasureToCore(
     119           0 :                             h, sValue);
     120           0 :                     aSize.Height = static_cast<double>(h) / 100.0;
     121             :                 }
     122           0 :                 break;
     123             :             default:
     124           0 :                 break;
     125             :             }
     126           0 :         }
     127             : 
     128           0 :         mxAnnotation->setPosition( aPosition );
     129           0 :         mxAnnotation->setSize( aSize );
     130             :     }
     131           0 : }
     132             : 
     133           0 : SvXMLImportContext * DrawAnnotationContext::CreateChildContext( sal_uInt16 nPrefix, const OUString& rLocalName, const Reference< XAttributeList >& xAttrList )
     134             : {
     135           0 :     SvXMLImportContext * pContext = NULL;
     136             : 
     137           0 :     if( mxAnnotation.is() )
     138             :     {
     139           0 :         if( XML_NAMESPACE_DC == nPrefix )
     140             :         {
     141           0 :             if( IsXMLToken( rLocalName, XML_CREATOR ) )
     142           0 :                 pContext = new XMLStringBufferImportContext(GetImport(), nPrefix, rLocalName, maAuthorBuffer);
     143           0 :             else if( IsXMLToken( rLocalName, XML_DATE ) )
     144           0 :                 pContext = new XMLStringBufferImportContext(GetImport(), nPrefix, rLocalName, maDateBuffer);
     145             :         }
     146             :         else
     147             :         {
     148             :             // create text cursor on demand
     149           0 :             if( !mxCursor.is() )
     150             :             {
     151           0 :                 uno::Reference< text::XText > xText( mxAnnotation->getTextRange() );
     152           0 :                 if( xText.is() )
     153             :                 {
     154           0 :                     UniReference < XMLTextImportHelper > xTxtImport = GetImport().GetTextImport();
     155           0 :                     mxCursor = xText->createTextCursor();
     156           0 :                     if( mxCursor.is() )
     157           0 :                         xTxtImport->SetCursor( mxCursor );
     158           0 :                 }
     159             :             }
     160             : 
     161             :             // if we have a text cursor, lets  try to import some text
     162           0 :             if( mxCursor.is() )
     163             :             {
     164           0 :                 pContext = GetImport().GetTextImport()->CreateTextChildContext( GetImport(), nPrefix, rLocalName, xAttrList );
     165             :             }
     166             :         }
     167             :     }
     168             : 
     169             :     // call parent for content
     170           0 :     if(!pContext)
     171           0 :         pContext = SvXMLImportContext::CreateChildContext( nPrefix, rLocalName, xAttrList );
     172             : 
     173           0 :     return pContext;
     174             : }
     175             : 
     176           0 : void DrawAnnotationContext::EndElement()
     177             : {
     178           0 :     if(mxCursor.is())
     179             :     {
     180             :         // delete addition newline
     181           0 :         const OUString aEmpty;
     182           0 :         mxCursor->gotoEnd( sal_False );
     183           0 :         mxCursor->goLeft( 1, sal_True );
     184           0 :         mxCursor->setString( aEmpty );
     185             : 
     186             :         // reset cursor
     187           0 :         GetImport().GetTextImport()->ResetCursor();
     188             :     }
     189             : 
     190           0 :     if( mxAnnotation.is() )
     191             :     {
     192           0 :         mxAnnotation->setAuthor( maAuthorBuffer.makeStringAndClear() );
     193             : 
     194           0 :         util::DateTime aDateTime;
     195           0 :         if (::sax::Converter::convertDateTime(aDateTime,
     196           0 :                 maDateBuffer.makeStringAndClear()))
     197             :         {
     198           0 :             mxAnnotation->setDateTime(aDateTime);
     199             :         }
     200             :     }
     201           0 : }
     202             : 
     203             : //////////////////////////////////////////////////////////////////////////////
     204             : 
     205           0 : TYPEINIT1( SdXMLGenericPageContext, SvXMLImportContext );
     206             : 
     207          40 : SdXMLGenericPageContext::SdXMLGenericPageContext(
     208             :     SvXMLImport& rImport,
     209             :     sal_uInt16 nPrfx, const OUString& rLocalName,
     210             :     const Reference< xml::sax::XAttributeList>& xAttrList,
     211             :     Reference< drawing::XShapes >& rShapes)
     212             : : SvXMLImportContext( rImport, nPrfx, rLocalName )
     213             : , mxShapes( rShapes )
     214          40 : , mxAnnotationAccess( rShapes, UNO_QUERY )
     215             : {
     216          40 :     sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
     217             : 
     218         140 :     for(sal_Int16 i=0; i < nAttrCount; i++)
     219             :     {
     220         100 :         OUString sAttrName = xAttrList->getNameByIndex( i );
     221         200 :         OUString aLocalName;
     222         100 :         sal_uInt16 nPrefix = GetSdImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
     223         100 :         if( (nPrefix == XML_NAMESPACE_DRAW) && IsXMLToken( aLocalName, XML_NAV_ORDER ) )
     224             :         {
     225           0 :             msNavOrder = xAttrList->getValueByIndex( i );
     226           0 :             break;
     227             :         }
     228         100 :     }
     229          40 : }
     230             : 
     231             : //////////////////////////////////////////////////////////////////////////////
     232             : 
     233          40 : SdXMLGenericPageContext::~SdXMLGenericPageContext()
     234             : {
     235          40 : }
     236             : 
     237             : //////////////////////////////////////////////////////////////////////////////
     238             : 
     239          40 : void SdXMLGenericPageContext::StartElement( const Reference< ::com::sun::star::xml::sax::XAttributeList >& )
     240             : {
     241          40 :     GetImport().GetShapeImport()->pushGroupForSorting( mxShapes );
     242             : 
     243          40 :     if( GetImport().IsFormsSupported() )
     244          40 :         GetImport().GetFormImport()->startPage( Reference< drawing::XDrawPage >::query( mxShapes ) );
     245          40 : }
     246             : 
     247             : //////////////////////////////////////////////////////////////////////////////
     248             : 
     249         188 : SvXMLImportContext* SdXMLGenericPageContext::CreateChildContext( sal_uInt16 nPrefix,
     250             :     const OUString& rLocalName,
     251             :     const Reference< xml::sax::XAttributeList>& xAttrList )
     252             : {
     253         188 :     SvXMLImportContext* pContext = 0L;
     254             : 
     255         188 :     if( nPrefix == XML_NAMESPACE_PRESENTATION && IsXMLToken( rLocalName, XML_ANIMATIONS ) )
     256             :     {
     257           0 :         pContext = new XMLAnimationsContext( GetImport(), nPrefix, rLocalName, xAttrList );
     258             :     }
     259         188 :     else if( nPrefix == XML_NAMESPACE_OFFICE && IsXMLToken( rLocalName, XML_FORMS ) )
     260             :     {
     261           2 :         if( GetImport().IsFormsSupported() )
     262           2 :             pContext = GetImport().GetFormImport()->createOfficeFormsContext( GetImport(), nPrefix, rLocalName );
     263             :     }
     264         186 :     else if( ((nPrefix == XML_NAMESPACE_OFFICE) || (nPrefix == XML_NAMESPACE_OFFICE_EXT)) && IsXMLToken( rLocalName, XML_ANNOTATION ) )
     265             :     {
     266           0 :         if( mxAnnotationAccess.is() )
     267           0 :             pContext = new DrawAnnotationContext( GetImport(), nPrefix, rLocalName, xAttrList, mxAnnotationAccess );
     268             :     }
     269             :     else
     270             :     {
     271             :         // call GroupChildContext function at common ShapeImport
     272         186 :         pContext = GetImport().GetShapeImport()->CreateGroupChildContext(
     273         372 :             GetImport(), nPrefix, rLocalName, xAttrList, mxShapes);
     274             :     }
     275             : 
     276             :     // call parent when no own context was created
     277         188 :     if(!pContext)
     278           0 :         pContext = SvXMLImportContext::CreateChildContext(nPrefix, rLocalName, xAttrList);
     279             : 
     280         188 :     return pContext;
     281             : }
     282             : 
     283             : //////////////////////////////////////////////////////////////////////////////
     284             : 
     285          40 : void SdXMLGenericPageContext::EndElement()
     286             : {
     287          40 :     GetImport().GetShapeImport()->popGroupAndSort();
     288             : 
     289          40 :     if( GetImport().IsFormsSupported() )
     290          40 :         GetImport().GetFormImport()->endPage();
     291             : 
     292          40 :     if( !maUseHeaderDeclName.isEmpty() || !maUseFooterDeclName.isEmpty() || !maUseDateTimeDeclName.isEmpty() )
     293             :     {
     294             :         try
     295             :         {
     296           0 :             Reference <beans::XPropertySet> xSet(mxShapes, uno::UNO_QUERY_THROW );
     297           0 :             Reference< beans::XPropertySetInfo > xInfo( xSet->getPropertySetInfo() );
     298             : 
     299           0 :             if( !maUseHeaderDeclName.isEmpty() )
     300             :             {
     301           0 :                 const OUString aStrHeaderTextProp( "HeaderText" );
     302           0 :                 if( xInfo->hasPropertyByName( aStrHeaderTextProp ) )
     303           0 :                     xSet->setPropertyValue( aStrHeaderTextProp,
     304           0 :                                             makeAny( GetSdImport().GetHeaderDecl( maUseHeaderDeclName ) ) );
     305             :             }
     306             : 
     307           0 :             if( !maUseFooterDeclName.isEmpty() )
     308             :             {
     309           0 :                 const OUString aStrFooterTextProp( "FooterText" );
     310           0 :                 if( xInfo->hasPropertyByName( aStrFooterTextProp ) )
     311           0 :                     xSet->setPropertyValue( aStrFooterTextProp,
     312           0 :                                         makeAny( GetSdImport().GetFooterDecl( maUseFooterDeclName ) ) );
     313             :             }
     314             : 
     315           0 :             if( !maUseDateTimeDeclName.isEmpty() )
     316             :             {
     317           0 :                 const OUString aStrDateTimeTextProp( "DateTimeText" );
     318           0 :                 if( xInfo->hasPropertyByName( aStrDateTimeTextProp ) )
     319             :                 {
     320             :                     sal_Bool bFixed;
     321           0 :                     OUString aDateTimeFormat;
     322           0 :                     const OUString aText( GetSdImport().GetDateTimeDecl( maUseDateTimeDeclName, bFixed, aDateTimeFormat ) );
     323             : 
     324           0 :                     xSet->setPropertyValue("IsDateTimeFixed",
     325           0 :                                         makeAny( bFixed ) );
     326             : 
     327           0 :                     if( bFixed )
     328             :                     {
     329           0 :                         xSet->setPropertyValue( aStrDateTimeTextProp, makeAny( aText ) );
     330             :                     }
     331           0 :                     else if( !aDateTimeFormat.isEmpty() )
     332             :                     {
     333           0 :                         const SdXMLStylesContext* pStyles = dynamic_cast< const SdXMLStylesContext* >( GetSdImport().GetShapeImport()->GetStylesContext() );
     334           0 :                         if( !pStyles )
     335           0 :                             pStyles = dynamic_cast< const SdXMLStylesContext* >( GetSdImport().GetShapeImport()->GetAutoStylesContext() );
     336             : 
     337           0 :                         if( pStyles )
     338             :                         {
     339             :                             const SdXMLNumberFormatImportContext* pSdNumStyle =
     340           0 :                                 dynamic_cast< const SdXMLNumberFormatImportContext* >( pStyles->FindStyleChildContext( XML_STYLE_FAMILY_DATA_STYLE, aDateTimeFormat, sal_True ) );
     341             : 
     342           0 :                             if( pSdNumStyle )
     343             :                             {
     344           0 :                                 xSet->setPropertyValue("DateTimeFormat",
     345           0 :                                                                     makeAny( pSdNumStyle->GetDrawKey() ) );
     346             :                             }
     347             :                         }
     348           0 :                     }
     349           0 :                 }
     350           0 :             }
     351             :         }
     352           0 :         catch(const uno::Exception&)
     353             :         {
     354             :             OSL_FAIL("xmloff::SdXMLGenericPageContext::EndElement(), unexpected exception cought!");
     355             :         }
     356             :     }
     357             : 
     358          40 :     SetNavigationOrder();
     359          40 : }
     360             : 
     361          40 : void SdXMLGenericPageContext::SetStyle( OUString& rStyleName )
     362             : {
     363             :     // set PageProperties?
     364          40 :     if(!rStyleName.isEmpty())
     365             :     {
     366             :         try
     367             :         {
     368          36 :             const SvXMLImportContext* pContext = GetSdImport().GetShapeImport()->GetAutoStylesContext();
     369             : 
     370          36 :             if( pContext && pContext->ISA( SvXMLStyleContext ) )
     371             :             {
     372          36 :                 const SdXMLStylesContext* pStyles = (SdXMLStylesContext*)pContext;
     373          36 :                 if(pStyles)
     374             :                 {
     375             :                     const SvXMLStyleContext* pStyle = pStyles->FindStyleChildContext(
     376          36 :                         XML_STYLE_FAMILY_SD_DRAWINGPAGE_ID, rStyleName);
     377             : 
     378          36 :                     if(pStyle && pStyle->ISA(XMLPropStyleContext))
     379             :                     {
     380          36 :                         XMLPropStyleContext* pPropStyle = (XMLPropStyleContext*)pStyle;
     381             : 
     382          36 :                         Reference <beans::XPropertySet> xPropSet1(mxShapes, uno::UNO_QUERY);
     383          36 :                         if(xPropSet1.is())
     384             :                         {
     385          36 :                             Reference< beans::XPropertySet > xPropSet( xPropSet1 );
     386          72 :                             Reference< beans::XPropertySet > xBackgroundSet;
     387             : 
     388          72 :                             const OUString aBackground("Background");
     389          36 :                             if( xPropSet1->getPropertySetInfo()->hasPropertyByName( aBackground ) )
     390             :                             {
     391          21 :                                 Reference< beans::XPropertySetInfo > xInfo( xPropSet1->getPropertySetInfo() );
     392          21 :                                 if( xInfo.is() && xInfo->hasPropertyByName( aBackground ) )
     393             :                                 {
     394          21 :                                     Reference< lang::XMultiServiceFactory > xServiceFact(GetSdImport().GetModel(), uno::UNO_QUERY);
     395          21 :                                     if(xServiceFact.is())
     396             :                                     {
     397          42 :                                         xBackgroundSet = Reference< beans::XPropertySet >::query(
     398          21 :                                             xServiceFact->createInstance(
     399          42 :                                             OUString("com.sun.star.drawing.Background")));
     400          21 :                                     }
     401             :                                 }
     402             : 
     403          21 :                                 if( xBackgroundSet.is() )
     404          21 :                                     xPropSet = PropertySetMerger_CreateInstance( xPropSet1, xBackgroundSet );
     405             :                             }
     406             : 
     407          36 :                             if(xPropSet.is())
     408             :                             {
     409          36 :                                 pPropStyle->FillPropertySet(xPropSet);
     410             : 
     411          36 :                                 if( xBackgroundSet.is() )
     412          21 :                                     xPropSet1->setPropertyValue( aBackground, uno::makeAny( xBackgroundSet ) );
     413          36 :                             }
     414          36 :                         }
     415             :                     }
     416             :                 }
     417             :             }
     418             :         }
     419           0 :         catch (const uno::Exception&)
     420             :         {
     421             :             OSL_FAIL( "SdXMLGenericPageContext::SetStyle(): uno::Exception caught!" );
     422             :         }
     423             :     }
     424          40 : }
     425             : 
     426          25 : void SdXMLGenericPageContext::SetLayout()
     427             : {
     428             :     // set PresentationPageLayout?
     429          25 :     if(GetSdImport().IsImpress() && !maPageLayoutName.isEmpty())
     430             :     {
     431          14 :         sal_Int32 nType = -1;
     432             : 
     433          14 :         const SvXMLImportContext* pContext = GetSdImport().GetShapeImport()->GetStylesContext();
     434             : 
     435          14 :         if( pContext && pContext->ISA( SvXMLStyleContext ) )
     436             :         {
     437           4 :             const SdXMLStylesContext* pStyles = (SdXMLStylesContext*)pContext;
     438           4 :             if(pStyles)
     439             :             {
     440           4 :                 const SvXMLStyleContext* pStyle = pStyles->FindStyleChildContext( XML_STYLE_FAMILY_SD_PRESENTATIONPAGELAYOUT_ID, maPageLayoutName);
     441             : 
     442           4 :                 if(pStyle && pStyle->ISA(SdXMLPresentationPageLayoutContext))
     443             :                 {
     444           4 :                     SdXMLPresentationPageLayoutContext* pLayout = (SdXMLPresentationPageLayoutContext*)pStyle;
     445           4 :                     nType = pLayout->GetTypeId();
     446             :                 }
     447             :             }
     448             : 
     449             :         }
     450          14 :         if( -1 == nType )
     451             :         {
     452          10 :             Reference< container::XNameAccess > xPageLayouts( GetSdImport().getPageLayouts() );
     453          10 :             if( xPageLayouts.is() )
     454             :             {
     455          10 :                 if( xPageLayouts->hasByName( maPageLayoutName ) )
     456          10 :                     xPageLayouts->getByName( maPageLayoutName ) >>= nType;
     457          10 :             }
     458             : 
     459             :         }
     460             : 
     461          14 :         if( -1 != nType )
     462             :         {
     463          14 :             Reference <beans::XPropertySet> xPropSet(mxShapes, uno::UNO_QUERY);
     464          14 :             if(xPropSet.is())
     465             :             {
     466          14 :                 OUString aPropName("Layout");
     467          28 :                 Reference< beans::XPropertySetInfo > xInfo( xPropSet->getPropertySetInfo() );
     468          14 :                 if( xInfo.is() && xInfo->hasPropertyByName( aPropName ) )
     469          28 :                     xPropSet->setPropertyValue(aPropName, uno::makeAny( (sal_Int16)nType ) );
     470          14 :             }
     471             :         }
     472             :     }
     473          25 : }
     474             : 
     475          25 : void SdXMLGenericPageContext::DeleteAllShapes()
     476             : {
     477             :     // now delete all up-to-now contained shapes; they have been created
     478             :     // when setting the presentation page layout.
     479         139 :     while(mxShapes->getCount())
     480             :     {
     481          89 :         Reference< drawing::XShape > xShape;
     482         178 :         uno::Any aAny(mxShapes->getByIndex(0L));
     483             : 
     484          89 :         aAny >>= xShape;
     485             : 
     486          89 :         if(xShape.is())
     487             :         {
     488          89 :             mxShapes->remove(xShape);
     489             :         }
     490          89 :     }
     491          25 : }
     492             : 
     493          15 : void SdXMLGenericPageContext::SetPageMaster( OUString& rsPageMasterName )
     494             : {
     495          15 :     if( GetSdImport().GetShapeImport()->GetStylesContext() )
     496             :     {
     497             :         // look for PageMaster with this name
     498             : 
     499             :         // #80012# GetStylesContext() replaced with GetAutoStylesContext()
     500          15 :         const SvXMLStylesContext* pAutoStyles = GetSdImport().GetShapeImport()->GetAutoStylesContext();
     501             : 
     502          15 :         const SvXMLStyleContext* pStyle = pAutoStyles ? pAutoStyles->FindStyleChildContext(XML_STYLE_FAMILY_SD_PAGEMASTERCONEXT_ID, rsPageMasterName) : NULL;
     503             : 
     504          15 :         if(pStyle && pStyle->ISA(SdXMLPageMasterContext))
     505             :         {
     506          15 :             const SdXMLPageMasterContext* pPageMaster = (SdXMLPageMasterContext*)pStyle;
     507          15 :             const SdXMLPageMasterStyleContext* pPageMasterContext = pPageMaster->GetPageMasterStyle();
     508             : 
     509          15 :             if(pPageMasterContext)
     510             :             {
     511          15 :                 Reference< drawing::XDrawPage > xMasterPage(GetLocalShapesContext(), uno::UNO_QUERY);
     512          15 :                 if(xMasterPage.is())
     513             :                 {
     514             :                     // set sizes for this masterpage
     515          15 :                     Reference <beans::XPropertySet> xPropSet(xMasterPage, uno::UNO_QUERY);
     516          15 :                     if(xPropSet.is())
     517             :                     {
     518          15 :                         uno::Any aAny;
     519             : 
     520          15 :                         aAny <<= pPageMasterContext->GetBorderBottom();
     521          15 :                         xPropSet->setPropertyValue("BorderBottom", aAny);
     522             : 
     523          15 :                         aAny <<= pPageMasterContext->GetBorderLeft();
     524          15 :                         xPropSet->setPropertyValue("BorderLeft", aAny);
     525             : 
     526          15 :                         aAny <<= pPageMasterContext->GetBorderRight();
     527          15 :                         xPropSet->setPropertyValue("BorderRight", aAny);
     528             : 
     529          15 :                         aAny <<= pPageMasterContext->GetBorderTop();
     530          15 :                         xPropSet->setPropertyValue("BorderTop", aAny);
     531             : 
     532          15 :                         aAny <<= pPageMasterContext->GetWidth();
     533          15 :                         xPropSet->setPropertyValue("Width", aAny);
     534             : 
     535          15 :                         aAny <<= pPageMasterContext->GetHeight();
     536          15 :                         xPropSet->setPropertyValue("Height", aAny);
     537             : 
     538          15 :                         aAny <<= pPageMasterContext->GetOrientation();
     539          15 :                         xPropSet->setPropertyValue("Orientation", aAny);
     540          15 :                     }
     541          15 :                 }
     542             :             }
     543             :         }
     544             : 
     545             :     }
     546          15 : }
     547             : 
     548           0 : class XoNavigationOrderAccess : public ::cppu::WeakImplHelper1< XIndexAccess >
     549             : {
     550             : public:
     551             :     XoNavigationOrderAccess( std::vector< Reference< XShape > >& rShapes );
     552             : 
     553             :     // XIndexAccess
     554             :     virtual sal_Int32 SAL_CALL getCount(  ) throw (RuntimeException);
     555             :     virtual Any SAL_CALL getByIndex( sal_Int32 Index ) throw (IndexOutOfBoundsException, WrappedTargetException, RuntimeException);
     556             : 
     557             :     // XElementAccess
     558             :     virtual Type SAL_CALL getElementType(  ) throw (RuntimeException);
     559             :     virtual sal_Bool SAL_CALL hasElements(  ) throw (RuntimeException);
     560             : 
     561             : private:
     562             :     std::vector< Reference< XShape > > maShapes;
     563             : };
     564             : 
     565           0 : XoNavigationOrderAccess::XoNavigationOrderAccess( std::vector< Reference< XShape > >& rShapes )
     566             : {
     567           0 :     maShapes.swap( rShapes );
     568           0 : }
     569             : 
     570             : // XIndexAccess
     571           0 : sal_Int32 SAL_CALL XoNavigationOrderAccess::getCount(  ) throw (RuntimeException)
     572             : {
     573           0 :     return static_cast< sal_Int32 >( maShapes.size() );
     574             : }
     575             : 
     576           0 : Any SAL_CALL XoNavigationOrderAccess::getByIndex( sal_Int32 Index ) throw (IndexOutOfBoundsException, WrappedTargetException, RuntimeException)
     577             : {
     578           0 :     if( (Index < 0) || (Index > getCount()) )
     579           0 :         throw IndexOutOfBoundsException();
     580             : 
     581           0 :     return Any( maShapes[Index] );
     582             : }
     583             : 
     584             : // XElementAccess
     585           0 : Type SAL_CALL XoNavigationOrderAccess::getElementType(  ) throw (RuntimeException)
     586             : {
     587           0 :     return XShape::static_type();
     588             : }
     589             : 
     590           0 : sal_Bool SAL_CALL XoNavigationOrderAccess::hasElements(  ) throw (RuntimeException)
     591             : {
     592           0 :     return maShapes.empty() ? sal_False : sal_True;
     593             : }
     594             : 
     595          40 : void SdXMLGenericPageContext::SetNavigationOrder()
     596             : {
     597          40 :     if( !msNavOrder.isEmpty() ) try
     598             :     {
     599             :         sal_uInt32 nIndex;
     600           0 :         const sal_uInt32 nCount = static_cast< sal_uInt32 >( mxShapes->getCount() );
     601           0 :         std::vector< Reference< XShape > > aShapes( nCount );
     602             : 
     603           0 :         ::comphelper::UnoInterfaceToUniqueIdentifierMapper& rIdMapper = GetSdImport().getInterfaceToIdentifierMapper();
     604           0 :         SvXMLTokenEnumerator aEnumerator( msNavOrder );
     605           0 :         OUString sId;
     606           0 :         for( nIndex = 0; nIndex < nCount; ++nIndex )
     607             :         {
     608           0 :             if( !aEnumerator.getNextToken(sId) )
     609           0 :                 break;
     610             : 
     611           0 :             aShapes[nIndex] = Reference< XShape >( rIdMapper.getReference( sId ), UNO_QUERY );
     612             :         }
     613             : 
     614           0 :         for( nIndex = 0; nIndex < nCount; ++nIndex )
     615             :         {
     616           0 :             if( !aShapes[nIndex].is() )
     617             :             {
     618             :                 OSL_FAIL("xmloff::SdXMLGenericPageContext::SetNavigationOrder(), draw:nav-order attribute incomplete!");
     619             :                 // todo: warning?
     620          40 :                 return;
     621             :             }
     622             :         }
     623             : 
     624           0 :         Reference< XPropertySet > xSet( mxShapes, UNO_QUERY_THROW );
     625           0 :         xSet->setPropertyValue("NavigationOrder", Any( Reference< XIndexAccess >( new XoNavigationOrderAccess( aShapes ) ) ) );
     626             :     }
     627           0 :     catch(const uno::Exception&)
     628             :     {
     629             :         OSL_FAIL("xmloff::SdXMLGenericPageContext::SetNavigationOrder(), unexpected exception cought while importing shape navigation order!");
     630             :     }
     631             : }
     632             : 
     633             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10