Files
libreoffice/xmloff/source/draw/ximpbody.cxx

364 lines
13 KiB
C++
Raw Normal View History

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
re-base on ALv2 code. Includes: Patches contributed by: Armin Le Grand. #118558# Correcting OLE attributes of LO3.4 at load time by loading as OOo3.3, details see task. http://svn.apache.org/viewvc?view=revision&revision=1195906 #118485# - Styles for OLEs are not saved. http://svn.apache.org/viewvc?view=revision&revision=1182166 #118898# Adapted ImpGraphic::ImplGetBitmap to correctly convert metafiles http://svn.apache.org/viewvc?view=revision&revision=1293316 #119337# Solves the wrong get/setPropertyValue calls in SvxShapeText (and thus in SvxOle2Shape) http://svn.apache.org/viewvc?view=revision&revision=1344156 Patches contributed by Mathias Bauer (and others) gnumake4 work variously http://svn.apache.org/viewvc?view=revision&revision=1394707 http://svn.apache.org/viewvc?view=revision&revision=1394326 cws mba34issues01: #i117717#: remove wrong assertion http://svn.apache.org/viewvc?view=revision&revision=1172349 Patch contributed by Herbert Duerr goodbye Registration and License dialogs, don't let the door hit you http://svn.apache.org/viewvc?view=revision&revision=1172613 help gcc 4.6.0 on 32bit ubuntu 11.10" http://svn.apache.org/viewvc?view=revision&revision=1245357 Do not add targets for junit tests when junit is disabled. Patch contributed by Andre Fischer http://svn.apache.org/viewvc?view=revision&revision=1241508 Revert "sb140: #i117082# avoid unncessary static class data members commit 21d97438e2944861e26e4984195f959a0cce1e41. remove obsolete FreeBSD visibility special case. retain consolidated BSD bridge code, remove OS/2 pieces.
2012-11-12 17:21:24 +00:00
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
2000-09-18 16:07:07 +00:00
#include "ximpbody.hxx"
#include <xmloff/prstylei.hxx>
2000-09-18 16:07:07 +00:00
#include "ximpnote.hxx"
#include <com/sun/star/drawing/XDrawPage.hpp>
#include <com/sun/star/drawing/XDrawPages.hpp>
#include <com/sun/star/container/XNamed.hpp>
#include <com/sun/star/presentation/XPresentationPage.hpp>
2000-09-18 16:07:07 +00:00
#include "ximpstyl.hxx"
#include <com/sun/star/drawing/XMasterPageTarget.hpp>
#include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/animations/XAnimationNodeSupplier.hpp>
#include <xmloff/unointerfacetouniqueidentifiermapper.hxx>
#include <xmloff/xmluconv.hxx>
#include <xmloff/xmlprmap.hxx>
#include <xmloff/families.hxx>
2000-12-19 15:23:48 +00:00
#include "ximpshow.hxx"
2000-11-08 11:19:53 +00:00
#include "PropertySetMerger.hxx"
#include "animationimport.hxx"
#include <tools/debug.hxx>
2000-09-18 16:07:07 +00:00
using namespace ::com::sun::star;
SdXMLDrawPageContext::SdXMLDrawPageContext( SdXMLImport& rImport,
sal_uInt16 nPrfx, const OUString& rLocalName,
2000-09-18 16:07:07 +00:00
const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList,
uno::Reference< drawing::XShapes >& rShapes)
: SdXMLGenericPageContext( rImport, nPrfx, rLocalName, xAttrList, rShapes )
, mbHadSMILNodes( false )
2000-09-18 16:07:07 +00:00
{
bool bHaveXmlId( false );
OUString sXmlId;
2000-09-18 16:07:07 +00:00
sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
for(sal_Int16 i=0; i < nAttrCount; i++)
{
OUString sAttrName = xAttrList->getNameByIndex( i );
OUString aLocalName;
sal_uInt16 nPrefix = GetSdImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
2000-09-18 16:07:07 +00:00
OUString sValue = xAttrList->getValueByIndex( i );
const SvXMLTokenMap& rAttrTokenMap = GetSdImport().GetDrawPageAttrTokenMap();
switch(rAttrTokenMap.Get(nPrefix, aLocalName))
{
case XML_TOK_DRAWPAGE_NAME:
{
maName = sValue;
break;
}
case XML_TOK_DRAWPAGE_STYLE_NAME:
{
maStyleName = sValue;
2000-09-18 16:07:07 +00:00
break;
}
case XML_TOK_DRAWPAGE_MASTER_PAGE_NAME:
{
maMasterPageName = sValue;
break;
}
case XML_TOK_DRAWPAGE_PAGE_LAYOUT_NAME:
{
maPageLayoutName = sValue;
2000-09-18 16:07:07 +00:00
break;
}
case XML_TOK_DRAWPAGE_USE_HEADER_NAME:
{
maUseHeaderDeclName = sValue;
break;
}
case XML_TOK_DRAWPAGE_USE_FOOTER_NAME:
{
maUseFooterDeclName = sValue;
break;
}
case XML_TOK_DRAWPAGE_USE_DATE_TIME_NAME:
{
maUseDateTimeDeclName = sValue;
break;
}
case XML_TOK_DRAWPAGE_DRAWID:
2000-12-19 15:23:48 +00:00
{
if (!bHaveXmlId) { sXmlId = sValue; }
2001-12-17 14:54:45 +00:00
}
break;
case XML_TOK_DRAWPAGE_XMLID:
{
sXmlId = sValue;
bHaveXmlId = true;
}
break;
2001-12-17 14:54:45 +00:00
case XML_TOK_DRAWPAGE_HREF:
{
maHREF = sValue;
break;
2000-12-19 15:23:48 +00:00
}
2000-09-18 16:07:07 +00:00
}
}
if (!sXmlId.isEmpty())
{
uno::Reference< uno::XInterface > const xRef( rShapes.get() );
GetImport().getInterfaceToIdentifierMapper().registerReference(
sXmlId, xRef );
}
GetImport().GetShapeImport()->startPage( rShapes );
uno::Reference< drawing::XDrawPage > xShapeDrawPage(rShapes, uno::UNO_QUERY);
2000-12-19 15:23:48 +00:00
2000-09-18 16:07:07 +00:00
// set PageName?
if(!maName.isEmpty())
2000-09-18 16:07:07 +00:00
{
if(xShapeDrawPage.is())
2000-09-18 16:07:07 +00:00
{
uno::Reference < container::XNamed > xNamed(xShapeDrawPage, uno::UNO_QUERY);
2000-09-18 16:07:07 +00:00
if(xNamed.is())
xNamed->setName(maName);
}
}
// set MasterPage?
if(!maMasterPageName.isEmpty())
{
// #85906# Code for setting masterpage needs complete rework
// since GetSdImport().GetMasterStylesContext() gives always ZERO
// because of content/style file split. Now the nechanism is to
// compare the wanted masterpage-name with the existing masterpages
// which were loaded and created in the styles section loading.
uno::Reference< drawing::XDrawPages > xMasterPages(GetSdImport().GetLocalMasterPages(), uno::UNO_QUERY);
uno::Reference < drawing::XMasterPageTarget > xDrawPage(rShapes, uno::UNO_QUERY);
uno::Reference< drawing::XDrawPage > xMasterPage;
if(xDrawPage.is() && xMasterPages.is())
{
bool bDone(false);
OUString sDisplayName( rImport.GetStyleDisplayName(
XML_STYLE_FAMILY_MASTER_PAGE, maMasterPageName ) );
for(sal_Int32 a = 0; !bDone && a < xMasterPages->getCount(); a++)
{
uno::Any aAny(xMasterPages->getByIndex(a));
aAny >>= xMasterPage;
if(xMasterPage.is())
{
uno::Reference < container::XNamed > xMasterNamed(xMasterPage, uno::UNO_QUERY);
if(xMasterNamed.is())
{
OUString sMasterPageName = xMasterNamed->getName();
if(!sMasterPageName.isEmpty() && sMasterPageName.equals(sDisplayName))
{
xDrawPage->setMasterPage(xMasterPage);
bDone = true;
}
}
}
}
DBG_ASSERT( bDone, "xmloff::SdXMLDrawPageContext::SdXMLDrawPageContext(), could not find a slide master!" );
}
}
SetStyle( maStyleName );
if( !maHREF.isEmpty() )
2001-12-17 14:54:45 +00:00
{
uno::Reference< beans::XPropertySet > xProps( xShapeDrawPage, uno::UNO_QUERY );
2001-12-17 14:54:45 +00:00
if( xProps.is() )
{
sal_Int32 nIndex = maHREF.lastIndexOf( (sal_Unicode)'#' );
if( nIndex != -1 )
{
OUString aFileName( maHREF.copy( 0, nIndex ) );
OUString aBookmarkName( maHREF.copy( nIndex+1 ) );
maHREF = GetImport().GetAbsoluteReference( aFileName );
2012-01-29 21:05:26 +00:00
maHREF += OUString(static_cast<sal_Unicode>('#'));
2001-12-17 14:54:45 +00:00
maHREF += aBookmarkName;
}
xProps->setPropertyValue("BookmarkURL", uno::makeAny( maHREF ) );
2001-12-17 14:54:45 +00:00
}
}
2001-05-28 12:32:20 +00:00
SetLayout();
2000-09-18 16:07:07 +00:00
2001-05-28 12:32:20 +00:00
DeleteAllShapes();
2000-09-18 16:07:07 +00:00
}
SdXMLDrawPageContext::~SdXMLDrawPageContext()
{
}
SvXMLImportContext *SdXMLDrawPageContext::CreateChildContext( sal_uInt16 nPrefix,
2000-09-18 16:07:07 +00:00
const OUString& rLocalName,
const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList )
{
SvXMLImportContext *pContext = 0L;
const SvXMLTokenMap& rTokenMap = GetSdImport().GetDrawPageElemTokenMap();
// some special objects inside draw:page context
switch(rTokenMap.Get(nPrefix, rLocalName))
{
case XML_TOK_DRAWPAGE_NOTES:
{
if( GetSdImport().IsImpress() )
{
// get notes page
uno::Reference< presentation::XPresentationPage > xPresPage(GetLocalShapesContext(), uno::UNO_QUERY);
if(xPresPage.is())
{
uno::Reference< drawing::XDrawPage > xNotesDrawPage(xPresPage->getNotesPage(), uno::UNO_QUERY);
if(xNotesDrawPage.is())
{
uno::Reference< drawing::XShapes > xNewShapes(xNotesDrawPage, uno::UNO_QUERY);
if(xNewShapes.is())
{
// presentation:notes inside draw:page context
pContext = new SdXMLNotesContext( GetSdImport(), nPrefix, rLocalName, xAttrList, xNewShapes);
}
}
}
}
break;
2000-09-18 16:07:07 +00:00
}
case XML_TOK_DRAWPAGE_PAR:
case XML_TOK_DRAWPAGE_SEQ:
{
if( GetSdImport().IsImpress() )
{
uno::Reference< animations::XAnimationNodeSupplier > xNodeSupplier(GetLocalShapesContext(), uno::UNO_QUERY);
if(xNodeSupplier.is())
{
pContext = new xmloff::AnimationNodeContext( xNodeSupplier->getAnimationNode(), GetSdImport(), nPrefix, rLocalName, xAttrList );
mbHadSMILNodes = true;
}
}
break;
}
2000-09-18 16:07:07 +00:00
}
// call parent when no own context was created
if(!pContext)
pContext = SdXMLGenericPageContext::CreateChildContext(nPrefix, rLocalName, xAttrList);
2000-09-18 16:07:07 +00:00
return pContext;
}
void SdXMLDrawPageContext::EndElement()
{
SdXMLGenericPageContext::EndElement();
GetImport().GetShapeImport()->endPage(GetLocalShapesContext());
if( mbHadSMILNodes )
{
uno::Reference< animations::XAnimationNodeSupplier > xNodeSupplier(GetLocalShapesContext(), uno::UNO_QUERY);
uno::Reference< beans::XPropertySet > xPageProps( GetLocalShapesContext(), uno::UNO_QUERY );
if(xNodeSupplier.is())
xmloff::AnimationNodeContext::postProcessRootNode( GetSdImport(), xNodeSupplier->getAnimationNode(), xPageProps );
}
}
2000-09-18 16:07:07 +00:00
SdXMLBodyContext::SdXMLBodyContext( SdXMLImport& rImport,
sal_uInt16 nPrfx, const OUString& rLocalName )
2000-09-18 16:07:07 +00:00
: SvXMLImportContext( rImport, nPrfx, rLocalName )
{
}
SdXMLBodyContext::~SdXMLBodyContext()
{
}
SvXMLImportContext *SdXMLBodyContext::CreateChildContext(
sal_uInt16 nPrefix,
2000-09-18 16:07:07 +00:00
const OUString& rLocalName,
const uno::Reference< xml::sax::XAttributeList>& xAttrList )
{
SvXMLImportContext *pContext = 0L;
const SvXMLTokenMap& rTokenMap = GetSdImport().GetBodyElemTokenMap();
switch(rTokenMap.Get(nPrefix, rLocalName))
{
case XML_TOK_BODY_HEADER_DECL:
case XML_TOK_BODY_FOOTER_DECL:
case XML_TOK_BODY_DATE_TIME_DECL:
{
pContext = new SdXMLHeaderFooterDeclContext( GetImport(), nPrefix, rLocalName, xAttrList );
break;
}
2000-09-18 16:07:07 +00:00
case XML_TOK_BODY_PAGE:
{
// only read the first page in preview mode
if( (GetSdImport().GetNewPageCount() == 0) || !GetSdImport().IsPreview() )
2000-09-18 16:07:07 +00:00
{
// import this page
uno::Reference< drawing::XDrawPage > xNewDrawPage;
uno::Reference< drawing::XDrawPages > xDrawPages(GetSdImport().GetLocalDrawPages(), uno::UNO_QUERY);
if( !xDrawPages.is() )
break;
if(GetSdImport().GetNewPageCount() + 1 > xDrawPages->getCount())
{
// new page, create and insert
xNewDrawPage = xDrawPages->insertNewByIndex(xDrawPages->getCount());
}
else
{
// existing page, use it
uno::Any aAny(xDrawPages->getByIndex(GetSdImport().GetNewPageCount()));
aAny >>= xNewDrawPage;
}
2000-09-18 16:07:07 +00:00
// increment global import page counter
GetSdImport().IncrementNewPageCount();
2000-09-18 16:07:07 +00:00
if(xNewDrawPage.is())
2000-09-18 16:07:07 +00:00
{
uno::Reference< drawing::XShapes > xNewShapes(xNewDrawPage, uno::UNO_QUERY);
if(xNewShapes.is())
{
// draw:page inside office:body context
pContext = new SdXMLDrawPageContext(GetSdImport(), nPrefix, rLocalName, xAttrList,
xNewShapes);
}
2000-09-18 16:07:07 +00:00
}
}
break;
}
2001-02-15 16:35:27 +00:00
case XML_TOK_BODY_SETTINGS:
2000-12-19 15:23:48 +00:00
{
pContext = new SdXMLShowsContext( GetSdImport(), nPrefix, rLocalName, xAttrList );
}
2000-09-18 16:07:07 +00:00
}
// call parent when no own context was created
if(!pContext)
pContext = SvXMLImportContext::CreateChildContext(nPrefix, rLocalName, xAttrList);
return pContext;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */