update dev300-m58
[ooovba.git] / xmloff / source / draw / ximppage.cxx
blobd0fa7f7279e2eb89a475b1bfbfb5cd9b0163e7ea
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ximppage.cxx,v $
10 * $Revision: 1.21 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_xmloff.hxx"
33 #include <tools/debug.hxx>
35 #include <cppuhelper/implbase1.hxx>
36 #include "XMLNumberStylesImport.hxx"
37 #include <xmloff/xmlstyle.hxx>
38 #include <xmloff/xmltoken.hxx>
39 #include <xmloff/xmlstyle.hxx>
40 #include "xmlnmspe.hxx"
41 #include "ximppage.hxx"
42 #include "ximpshap.hxx"
43 #include "animimp.hxx"
44 #include <xmloff/formsimp.hxx>
45 #include <xmloff/xmlictxt.hxx>
46 #include "ximpstyl.hxx"
47 #include <xmloff/prstylei.hxx>
48 #include "PropertySetMerger.hxx"
50 #include "unointerfacetouniqueidentifiermapper.hxx"
51 #include <xmloff/xmluconv.hxx>
53 using ::rtl::OUString;
54 using ::rtl::OUStringBuffer;
56 using namespace ::com::sun::star;
57 using namespace ::xmloff::token;
58 using namespace ::com::sun::star::uno;
59 using namespace ::com::sun::star::lang;
60 using namespace ::com::sun::star::beans;
61 using namespace ::com::sun::star::drawing;
62 using namespace ::com::sun::star::container;
64 //////////////////////////////////////////////////////////////////////////////
66 TYPEINIT1( SdXMLGenericPageContext, SvXMLImportContext );
68 SdXMLGenericPageContext::SdXMLGenericPageContext(
69 SvXMLImport& rImport,
70 USHORT nPrfx, const OUString& rLocalName,
71 const Reference< xml::sax::XAttributeList>& xAttrList,
72 Reference< drawing::XShapes >& rShapes)
73 : SvXMLImportContext( rImport, nPrfx, rLocalName ),
74 mxShapes( rShapes )
76 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
78 for(sal_Int16 i=0; i < nAttrCount; i++)
80 OUString sAttrName = xAttrList->getNameByIndex( i );
81 OUString aLocalName;
82 USHORT nPrefix = GetSdImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
83 if( (nPrefix == XML_NAMESPACE_DRAW) && IsXMLToken( aLocalName, XML_NAV_ORDER ) )
85 msNavOrder = xAttrList->getValueByIndex( i );
86 break;
91 //////////////////////////////////////////////////////////////////////////////
93 SdXMLGenericPageContext::~SdXMLGenericPageContext()
97 //////////////////////////////////////////////////////////////////////////////
99 void SdXMLGenericPageContext::StartElement( const Reference< ::com::sun::star::xml::sax::XAttributeList >& )
101 GetImport().GetShapeImport()->pushGroupForSorting( mxShapes );
103 #ifndef SVX_LIGHT
104 if( GetImport().IsFormsSupported() )
105 GetImport().GetFormImport()->startPage( Reference< drawing::XDrawPage >::query( mxShapes ) );
106 #endif
109 //////////////////////////////////////////////////////////////////////////////
111 SvXMLImportContext* SdXMLGenericPageContext::CreateChildContext( USHORT nPrefix,
112 const OUString& rLocalName,
113 const Reference< xml::sax::XAttributeList>& xAttrList )
115 SvXMLImportContext* pContext = 0L;
117 if( nPrefix == XML_NAMESPACE_PRESENTATION && IsXMLToken( rLocalName, XML_ANIMATIONS ) )
119 pContext = new XMLAnimationsContext( GetImport(), nPrefix, rLocalName, xAttrList );
121 else if( nPrefix == XML_NAMESPACE_OFFICE && IsXMLToken( rLocalName, XML_FORMS ) )
123 #ifndef SVX_LIGHT
124 if( GetImport().IsFormsSupported() )
125 pContext = GetImport().GetFormImport()->createOfficeFormsContext( GetImport(), nPrefix, rLocalName );
126 #endif
128 else
130 // call GroupChildContext function at common ShapeImport
131 pContext = GetImport().GetShapeImport()->CreateGroupChildContext(
132 GetImport(), nPrefix, rLocalName, xAttrList, mxShapes);
135 // call parent when no own context was created
136 if(!pContext)
137 pContext = SvXMLImportContext::CreateChildContext(nPrefix, rLocalName, xAttrList);
139 return pContext;
142 //////////////////////////////////////////////////////////////////////////////
144 void SdXMLGenericPageContext::EndElement()
146 GetImport().GetShapeImport()->popGroupAndSort();
148 if( GetImport().IsFormsSupported() )
149 GetImport().GetFormImport()->endPage();
151 if( maUseHeaderDeclName.getLength() || maUseFooterDeclName.getLength() || maUseDateTimeDeclName.getLength() )
155 Reference <beans::XPropertySet> xSet(mxShapes, uno::UNO_QUERY_THROW );
156 Reference< beans::XPropertySetInfo > xInfo( xSet->getPropertySetInfo() );
158 if( maUseHeaderDeclName.getLength() )
160 const OUString aStrHeaderTextProp( RTL_CONSTASCII_USTRINGPARAM( "HeaderText" ) );
161 if( xInfo->hasPropertyByName( aStrHeaderTextProp ) )
162 xSet->setPropertyValue( aStrHeaderTextProp,
163 makeAny( GetSdImport().GetHeaderDecl( maUseHeaderDeclName ) ) );
166 if( maUseFooterDeclName.getLength() )
168 const OUString aStrFooterTextProp( RTL_CONSTASCII_USTRINGPARAM( "FooterText" ) );
169 if( xInfo->hasPropertyByName( aStrFooterTextProp ) )
170 xSet->setPropertyValue( aStrFooterTextProp,
171 makeAny( GetSdImport().GetFooterDecl( maUseFooterDeclName ) ) );
174 if( maUseDateTimeDeclName.getLength() )
176 const OUString aStrDateTimeTextProp( RTL_CONSTASCII_USTRINGPARAM( "DateTimeText" ) );
177 if( xInfo->hasPropertyByName( aStrDateTimeTextProp ) )
179 sal_Bool bFixed;
180 OUString aDateTimeFormat;
181 const OUString aText( GetSdImport().GetDateTimeDecl( maUseDateTimeDeclName, bFixed, aDateTimeFormat ) );
183 xSet->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("IsDateTimeFixed") ),
184 makeAny( bFixed ) );
186 if( bFixed )
188 xSet->setPropertyValue( aStrDateTimeTextProp, makeAny( aText ) );
190 else if( aDateTimeFormat.getLength() )
192 const SdXMLStylesContext* pStyles = dynamic_cast< const SdXMLStylesContext* >( GetSdImport().GetShapeImport()->GetStylesContext() );
193 if( pStyles )
195 const SdXMLNumberFormatImportContext* pSdNumStyle =
196 dynamic_cast< const SdXMLNumberFormatImportContext* >( pStyles->FindStyleChildContext( XML_STYLE_FAMILY_DATA_STYLE, aDateTimeFormat, sal_True ) );
198 if( pSdNumStyle )
200 xSet->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("DateTimeFormat") ),
201 makeAny( pSdNumStyle->GetDrawKey() ) );
208 catch( uno::Exception& e )
210 (void)e;
211 DBG_ERROR("xmloff::SdXMLGenericPageContext::EndElement(), unexpected exception cought!");
215 SetNavigationOrder();
218 void SdXMLGenericPageContext::SetStyle( rtl::OUString& rStyleName )
220 // set PageProperties?
221 if(rStyleName.getLength())
225 const SvXMLImportContext* pContext = GetSdImport().GetShapeImport()->GetAutoStylesContext();
227 if( pContext && pContext->ISA( SvXMLStyleContext ) )
229 const SdXMLStylesContext* pStyles = (SdXMLStylesContext*)pContext;
230 if(pStyles)
232 const SvXMLStyleContext* pStyle = pStyles->FindStyleChildContext(
233 XML_STYLE_FAMILY_SD_DRAWINGPAGE_ID, rStyleName);
235 if(pStyle && pStyle->ISA(XMLPropStyleContext))
237 XMLPropStyleContext* pPropStyle = (XMLPropStyleContext*)pStyle;
239 Reference <beans::XPropertySet> xPropSet1(mxShapes, uno::UNO_QUERY);
240 if(xPropSet1.is())
242 Reference< beans::XPropertySet > xPropSet( xPropSet1 );
243 Reference< beans::XPropertySet > xBackgroundSet;
245 const OUString aBackground(RTL_CONSTASCII_USTRINGPARAM("Background"));
246 if( xPropSet1->getPropertySetInfo()->hasPropertyByName( aBackground ) )
248 Reference< beans::XPropertySetInfo > xInfo( xPropSet1->getPropertySetInfo() );
249 if( xInfo.is() && xInfo->hasPropertyByName( aBackground ) )
251 Reference< lang::XMultiServiceFactory > xServiceFact(GetSdImport().GetModel(), uno::UNO_QUERY);
252 if(xServiceFact.is())
254 xBackgroundSet = Reference< beans::XPropertySet >::query(
255 xServiceFact->createInstance(
256 OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.drawing.Background"))));
260 if( xBackgroundSet.is() )
261 xPropSet = PropertySetMerger_CreateInstance( xPropSet1, xBackgroundSet );
264 if(xPropSet.is())
266 pPropStyle->FillPropertySet(xPropSet);
268 if( xBackgroundSet.is() )
269 xPropSet1->setPropertyValue( aBackground, uno::makeAny( xBackgroundSet ) );
276 catch( uno::Exception )
278 DBG_ERROR( "SdXMLGenericPageContext::SetStyle(): uno::Exception catched!" );
283 void SdXMLGenericPageContext::SetLayout()
285 // set PresentationPageLayout?
286 if(GetSdImport().IsImpress() && maPageLayoutName.getLength())
288 sal_Int32 nType = -1;
290 const SvXMLImportContext* pContext = GetSdImport().GetShapeImport()->GetStylesContext();
292 if( pContext && pContext->ISA( SvXMLStyleContext ) )
294 const SdXMLStylesContext* pStyles = (SdXMLStylesContext*)pContext;
295 if(pStyles)
297 const SvXMLStyleContext* pStyle = pStyles->FindStyleChildContext( XML_STYLE_FAMILY_SD_PRESENTATIONPAGELAYOUT_ID, maPageLayoutName);
299 if(pStyle && pStyle->ISA(SdXMLPresentationPageLayoutContext))
301 SdXMLPresentationPageLayoutContext* pLayout = (SdXMLPresentationPageLayoutContext*)pStyle;
302 nType = pLayout->GetTypeId();
307 if( -1 == nType )
309 Reference< container::XNameAccess > xPageLayouts( GetSdImport().getPageLayouts() );
310 if( xPageLayouts.is() )
312 if( xPageLayouts->hasByName( maPageLayoutName ) )
313 xPageLayouts->getByName( maPageLayoutName ) >>= nType;
318 if( -1 != nType )
320 Reference <beans::XPropertySet> xPropSet(mxShapes, uno::UNO_QUERY);
321 if(xPropSet.is())
323 OUString aPropName(RTL_CONSTASCII_USTRINGPARAM("Layout"));
324 Reference< beans::XPropertySetInfo > xInfo( xPropSet->getPropertySetInfo() );
325 if( xInfo.is() && xInfo->hasPropertyByName( aPropName ) )
326 xPropSet->setPropertyValue(aPropName, uno::makeAny( (sal_Int16)nType ) );
332 void SdXMLGenericPageContext::DeleteAllShapes()
334 // now delete all up-to-now contained shapes; they have been created
335 // when setting the presentation page layout.
336 while(mxShapes->getCount())
338 Reference< drawing::XShape > xShape;
339 uno::Any aAny(mxShapes->getByIndex(0L));
341 aAny >>= xShape;
343 if(xShape.is())
345 mxShapes->remove(xShape);
350 void SdXMLGenericPageContext::SetPageMaster( OUString& rsPageMasterName )
352 if( GetSdImport().GetShapeImport()->GetStylesContext() )
354 // look for PageMaster with this name
356 // #80012# GetStylesContext() replaced with GetAutoStylesContext()
357 const SvXMLStylesContext* pAutoStyles = GetSdImport().GetShapeImport()->GetAutoStylesContext();
359 const SvXMLStyleContext* pStyle = pAutoStyles ? pAutoStyles->FindStyleChildContext(XML_STYLE_FAMILY_SD_PAGEMASTERCONEXT_ID, rsPageMasterName) : NULL;
361 if(pStyle && pStyle->ISA(SdXMLPageMasterContext))
363 const SdXMLPageMasterContext* pPageMaster = (SdXMLPageMasterContext*)pStyle;
364 const SdXMLPageMasterStyleContext* pPageMasterContext = pPageMaster->GetPageMasterStyle();
366 if(pPageMasterContext)
368 Reference< drawing::XDrawPage > xMasterPage(GetLocalShapesContext(), uno::UNO_QUERY);
369 if(xMasterPage.is())
371 // set sizes for this masterpage
372 Reference <beans::XPropertySet> xPropSet(xMasterPage, uno::UNO_QUERY);
373 if(xPropSet.is())
375 uno::Any aAny;
377 aAny <<= pPageMasterContext->GetBorderBottom();
378 xPropSet->setPropertyValue(
379 OUString(RTL_CONSTASCII_USTRINGPARAM("BorderBottom")), aAny);
381 aAny <<= pPageMasterContext->GetBorderLeft();
382 xPropSet->setPropertyValue(
383 OUString(RTL_CONSTASCII_USTRINGPARAM("BorderLeft")), aAny);
385 aAny <<= pPageMasterContext->GetBorderRight();
386 xPropSet->setPropertyValue(
387 OUString(RTL_CONSTASCII_USTRINGPARAM("BorderRight")), aAny);
389 aAny <<= pPageMasterContext->GetBorderTop();
390 xPropSet->setPropertyValue(
391 OUString(RTL_CONSTASCII_USTRINGPARAM("BorderTop")), aAny);
393 aAny <<= pPageMasterContext->GetWidth();
394 xPropSet->setPropertyValue(
395 OUString(RTL_CONSTASCII_USTRINGPARAM("Width")), aAny);
397 aAny <<= pPageMasterContext->GetHeight();
398 xPropSet->setPropertyValue(
399 OUString(RTL_CONSTASCII_USTRINGPARAM("Height")), aAny);
401 aAny <<= pPageMasterContext->GetOrientation();
402 xPropSet->setPropertyValue(
403 OUString(RTL_CONSTASCII_USTRINGPARAM("Orientation")), aAny);
412 class NavigationOrderAccess : public ::cppu::WeakImplHelper1< XIndexAccess >
414 public:
415 NavigationOrderAccess( std::vector< Reference< XShape > >& rShapes );
417 // XIndexAccess
418 virtual sal_Int32 SAL_CALL getCount( ) throw (RuntimeException);
419 virtual Any SAL_CALL getByIndex( sal_Int32 Index ) throw (IndexOutOfBoundsException, WrappedTargetException, RuntimeException);
421 // XElementAccess
422 virtual Type SAL_CALL getElementType( ) throw (RuntimeException);
423 virtual sal_Bool SAL_CALL hasElements( ) throw (RuntimeException);
425 private:
426 std::vector< Reference< XShape > > maShapes;
429 NavigationOrderAccess::NavigationOrderAccess( std::vector< Reference< XShape > >& rShapes )
431 maShapes.swap( rShapes );
434 // XIndexAccess
435 sal_Int32 SAL_CALL NavigationOrderAccess::getCount( ) throw (RuntimeException)
437 return static_cast< sal_Int32 >( maShapes.size() );
440 Any SAL_CALL NavigationOrderAccess::getByIndex( sal_Int32 Index ) throw (IndexOutOfBoundsException, WrappedTargetException, RuntimeException)
442 if( (Index < 0) || (Index > getCount()) )
443 throw IndexOutOfBoundsException();
445 return Any( maShapes[Index] );
448 // XElementAccess
449 Type SAL_CALL NavigationOrderAccess::getElementType( ) throw (RuntimeException)
451 return XShape::static_type();
454 sal_Bool SAL_CALL NavigationOrderAccess::hasElements( ) throw (RuntimeException)
456 return maShapes.empty() ? sal_False : sal_True;
459 void SdXMLGenericPageContext::SetNavigationOrder()
461 if( msNavOrder.getLength() != 0 ) try
463 sal_uInt32 nIndex;
464 const sal_uInt32 nCount = static_cast< sal_uInt32 >( mxShapes->getCount() );
465 std::vector< Reference< XShape > > aShapes( nCount );
467 ::comphelper::UnoInterfaceToUniqueIdentifierMapper& rIdMapper = GetSdImport().getInterfaceToIdentifierMapper();
468 SvXMLTokenEnumerator aEnumerator( msNavOrder );
469 OUString sId;
470 for( nIndex = 0; nIndex < nCount; ++nIndex )
472 if( !aEnumerator.getNextToken(sId) )
473 break;
475 aShapes[nIndex] = Reference< XShape >( rIdMapper.getReference( sId ), UNO_QUERY );
478 for( nIndex = 0; nIndex < nCount; ++nIndex )
480 if( !aShapes[nIndex].is() )
482 DBG_ERROR("xmloff::SdXMLGenericPageContext::SetNavigationOrder(), draw:nav-order attribute incomplete!");
483 // todo: warning?
484 return;
488 Reference< XPropertySet > xSet( mxShapes, UNO_QUERY_THROW );
489 xSet->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "NavigationOrder" ) ), Any( Reference< XIndexAccess >( new NavigationOrderAccess( aShapes ) ) ) );
491 catch( uno::Exception& )
493 DBG_ERROR("xmloff::SdXMLGenericPageContext::SetNavigationOrder(), unexpected exception cought while importing shape navigation order!");