Files
libreoffice/xmloff/source/style/XMLPageExport.cxx

266 lines
9.7 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-10-11 06:51:24 +00:00
#include <xmloff/XMLPageExport.hxx>
2000-10-11 06:51:24 +00:00
#include <tools/debug.hxx>
#include <xmloff/xmlnmspe.hxx>
#include <xmloff/xmltoken.hxx>
2000-10-11 06:51:24 +00:00
#include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
#include <com/sun/star/style/XStyle.hpp>
#include <com/sun/star/container/XNameContainer.hpp>
#include <com/sun/star/container/XIndexReplace.hpp>
#include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
#include <xmloff/families.hxx>
#include <xmloff/xmlexp.hxx>
#include "PageMasterPropHdlFactory.hxx"
#include <xmloff/PageMasterStyleMap.hxx>
2000-10-18 10:32:20 +00:00
#include "PageMasterPropMapper.hxx"
#include "PageMasterExportPropMapper.hxx"
2000-10-11 06:51:24 +00:00
using namespace ::com::sun::star;
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::style;
using namespace ::com::sun::star::container;
using namespace ::com::sun::star::beans;
using namespace ::xmloff::token;
2000-10-11 06:51:24 +00:00
bool XMLPageExport::findPageMasterName( const OUString& rStyleName, OUString& rPMName ) const
2000-10-11 06:51:24 +00:00
{
for( ::std::vector< XMLPageExportNameEntry >::const_iterator pEntry = aNameVector.begin();
2011-07-30 23:51:40 +02:00
pEntry != aNameVector.end(); ++pEntry )
2000-10-18 10:32:20 +00:00
{
if( pEntry->sStyleName == rStyleName )
2000-10-18 10:32:20 +00:00
{
rPMName = pEntry->sPageMasterName;
return true;
2000-10-18 10:32:20 +00:00
}
}
return false;
}
void XMLPageExport::collectPageMasterAutoStyle(
const Reference < XPropertySet > & rPropSet,
OUString& rPageMasterName )
{
DBG_ASSERT( xPageMasterPropSetMapper.is(), "page master family/XMLPageMasterPropSetMapper not found" );
if( xPageMasterPropSetMapper.is() )
{
::std::vector<XMLPropertyState> aPropStates = xPageMasterExportPropMapper->Filter( rPropSet );
if( !aPropStates.empty())
{
OUString sParent;
rPageMasterName = rExport.GetAutoStylePool()->Find( XML_STYLE_FAMILY_PAGE_MASTER, sParent, aPropStates );
if (rPageMasterName.isEmpty())
rPageMasterName = rExport.GetAutoStylePool()->Add(XML_STYLE_FAMILY_PAGE_MASTER, sParent, aPropStates);
}
}
2000-10-11 06:51:24 +00:00
}
void XMLPageExport::exportMasterPageContent(
const Reference < XPropertySet > &,
bool /*bAutoStyles*/ )
2000-10-11 06:51:24 +00:00
{
2000-10-18 10:32:20 +00:00
2000-10-11 06:51:24 +00:00
}
bool XMLPageExport::exportStyle(
2000-10-11 06:51:24 +00:00
const Reference< XStyle >& rStyle,
bool bAutoStyles )
2000-10-11 06:51:24 +00:00
{
Reference< XPropertySet > xPropSet( rStyle, UNO_QUERY );
Reference< XPropertySetInfo > xPropSetInfo = xPropSet->getPropertySetInfo();
// Don't export styles that aren't existing really. This may be the
// case for StarOffice Writer's pool styles.
if( xPropSetInfo->hasPropertyByName( sIsPhysical ) )
{
Any aAny = xPropSet->getPropertyValue( sIsPhysical );
if( !*static_cast<sal_Bool const *>(aAny.getValue()) )
return false;
2000-10-11 06:51:24 +00:00
}
if( bAutoStyles )
{
XMLPageExportNameEntry aEntry;
collectPageMasterAutoStyle( xPropSet, aEntry.sPageMasterName );
aEntry.sStyleName = rStyle->getName();
aNameVector.push_back( aEntry );
exportMasterPageContent( xPropSet, true );
2000-10-11 06:51:24 +00:00
}
else
{
OUString sName( rStyle->getName() );
bool bEncoded = false;
GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_NAME,
GetExport().EncodeStyleName( sName, &bEncoded ) );
if ( xPropSetInfo->hasPropertyByName( "Hidden" ) )
{
uno::Any aValue = xPropSet->getPropertyValue( "Hidden" );
bool bHidden = false;
if ( ( aValue >>= bHidden ) && bHidden && GetExport( ).getDefaultVersion( ) == SvtSaveOptions::ODFVER_LATEST )
GetExport( ).AddAttribute( XML_NAMESPACE_STYLE, XML_HIDDEN, "true" );
}
if( bEncoded )
GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_DISPLAY_NAME,
sName);
2000-10-11 06:51:24 +00:00
OUString sPMName;
if( findPageMasterName( sName, sPMName ) )
GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_PAGE_LAYOUT_NAME, GetExport().EncodeStyleName( sPMName ) );
Reference<XPropertySetInfo> xInfo = xPropSet->getPropertySetInfo();
if ( xInfo.is() && xInfo->hasPropertyByName(sFollowStyle) )
2000-10-11 06:51:24 +00:00
{
OUString sNextName;
xPropSet->getPropertyValue( sFollowStyle ) >>= sNextName;
if( sName != sNextName && !sNextName.isEmpty() )
{
GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_NEXT_STYLE_NAME,
GetExport().EncodeStyleName( sNextName ) );
}
2000-10-11 06:51:24 +00:00
}
SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_STYLE,
XML_MASTER_PAGE, true, true );
2000-10-11 06:51:24 +00:00
exportMasterPageContent( xPropSet, false );
2000-10-11 06:51:24 +00:00
}
return true;
2000-10-11 06:51:24 +00:00
}
XMLPageExport::XMLPageExport( SvXMLExport& rExp ) :
rExport( rExp ),
sIsPhysical( "IsPhysical" ),
sFollowStyle( "FollowStyle" )
2000-10-11 06:51:24 +00:00
{
xPageMasterPropHdlFactory = new XMLPageMasterPropHdlFactory;
xPageMasterPropSetMapper = new XMLPageMasterPropSetMapper(
aXMLPageMasterStyleMap,
xPageMasterPropHdlFactory );
xPageMasterExportPropMapper = new XMLPageMasterExportPropMapper(
xPageMasterPropSetMapper, rExp);
rExport.GetAutoStylePool()->AddFamily( XML_STYLE_FAMILY_PAGE_MASTER, XML_STYLE_FAMILY_PAGE_MASTER_NAME,
xPageMasterExportPropMapper, XML_STYLE_FAMILY_PAGE_MASTER_PREFIX, false );
2000-10-11 06:51:24 +00:00
Reference< XStyleFamiliesSupplier > xFamiliesSupp( GetExport().GetModel(),
UNO_QUERY );
DBG_ASSERT( xFamiliesSupp.is(),
"No XStyleFamiliesSupplier from XModel for export!" );
if( xFamiliesSupp.is() )
{
Reference< XNameAccess > xFamilies( xFamiliesSupp->getStyleFamilies() );
DBG_ASSERT( xFamiliesSupp.is(),
"getStyleFamilies() from XModel failed for export!" );
if( xFamilies.is() )
{
const OUString aPageStyleName("PageStyles");
2000-10-11 06:51:24 +00:00
if( xFamilies->hasByName( aPageStyleName ) )
{
xPageStyles.set(xFamilies->getByName( aPageStyleName ),uno::UNO_QUERY);
2000-10-11 06:51:24 +00:00
DBG_ASSERT( xPageStyles.is(),
"Page Styles not found for export!" );
}
}
}
}
XMLPageExport::~XMLPageExport()
{
}
void XMLPageExport::exportStyles( bool bUsed, bool bAutoStyles )
2000-10-11 06:51:24 +00:00
{
if( xPageStyles.is() )
{
uno::Sequence< OUString> aSeq = xPageStyles->getElementNames();
const OUString* pIter = aSeq.getConstArray();
const OUString* pEnd = pIter + aSeq.getLength();
for(;pIter != pEnd;++pIter)
2000-10-11 06:51:24 +00:00
{
Reference< XStyle > xStyle(xPageStyles->getByName( *pIter ),uno::UNO_QUERY);
2000-10-11 06:51:24 +00:00
if( !bUsed || xStyle->isInUse() )
exportStyle( xStyle, bAutoStyles );
}
}
}
2000-10-20 04:36:28 +00:00
void XMLPageExport::exportAutoStyles()
{
rExport.GetAutoStylePool()->exportXML(XML_STYLE_FAMILY_PAGE_MASTER
, rExport.GetDocHandler(), rExport.GetMM100UnitConverter(),
rExport.GetNamespaceMap()
);
2000-10-20 04:36:28 +00:00
}
void XMLPageExport::exportDefaultStyle()
{
Reference < lang::XMultiServiceFactory > xFactory (GetExport().GetModel(), UNO_QUERY);
if (xFactory.is())
{
OUString sTextDefaults ( "com.sun.star.text.Defaults" );
Reference < XPropertySet > xPropSet (xFactory->createInstance ( sTextDefaults ), UNO_QUERY);
if (xPropSet.is())
{
// <style:default-style ...>
GetExport().CheckAttrList();
::std::vector< XMLPropertyState > aPropStates =
xPageMasterExportPropMapper->FilterDefaults( xPropSet );
bool bExport = false;
rtl::Reference < XMLPropertySetMapper > aPropMapper(xPageMasterExportPropMapper->getPropertySetMapper());
for( ::std::vector< XMLPropertyState >::iterator aIter = aPropStates.begin(); aIter != aPropStates.end(); ++aIter )
{
XMLPropertyState *pProp = &(*aIter);
sal_Int16 nContextId = aPropMapper->GetEntryContextId( pProp->mnIndex );
if( nContextId == CTF_PM_STANDARD_MODE )
{
bExport = true;
break;
}
}
if( bExport )
{
assert(GetExport().getDefaultVersion()
>= SvtSaveOptions::ODFVER_012);
//<style:default-page-layout>
SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_STYLE,
XML_DEFAULT_PAGE_LAYOUT,
true, true );
xPageMasterExportPropMapper->exportXML( GetExport(), aPropStates,
SvXmlExportFlags::IGN_WS );
}
}
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */