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

262 lines
9.6 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>
New o3tl::try/doGet to obtain value from Any ...in an attempt to reduce usage of type-unsafe void const * css::uno::Any::getValue() These new functions are often more convenient to use than the existing ">>=" and Any::get<T>. Note how they are careful to provide a pointer directly into the given Any, instead of creating temporaries. As an example, replaced most calls of getValue across xmloff: * Cases that first check for a specific type (via getValueType etc.) and then call getValue can instead call tryGet. (But beware that tryGet supports some conversions, which a check for a specific type may have missed---either intentionally or by accident. Also beware the somewhat common idiom of checking for TypeClass_ENUM and then using getValue to obtain a sal_Int32; this cannot be replaced with a call to tryGet.) * Cases that seem confident that the Any is of the correct type when calling getValue (but apparently are confident due to some higher-layer protocol, as the surrounding code does not do any checking via getValueType or similar) can instead call doGet. It throws an exception if it turns out the confidence wasn't warranted. (Many of the existing calls that directly dereferenced the return value of getValue as sal_Bool look suspicious, in that the author might have thought the given code would also cover a VOID Any---which technically it even would have happened to do. If any RuntimeExceptions thrown from these doGet calls start to crop up, these changes need to be revisited. Some may even be rewritten as uses of ">>=". But at least "make check" did not show any such problems. Also note that casting the value obtained from getValue to any css::uno::Reference<X> with X being anything but the base css::uno::XInterface was always prone to producing a bad pointer, in case the interface actually stored in the Any derived from X via multiple inheritance.) * Should there ever be cases where an Any is known to be of the requested type, some additional forceGet could be introduced (which would assert instead of throwing an exception). Change-Id: I2d8739e86314eff73abfcafe01d806f5bc5c34db
2016-06-02 15:06:06 +02:00
#include <o3tl/any.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 )
{
SAL_WARN_IF( !xPageMasterPropSetMapper.is(), "xmloff", "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( !*o3tl::doAccess<bool>(aAny) )
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 );
SAL_WARN_IF( !xFamiliesSupp.is(), "xmloff",
2000-10-11 06:51:24 +00:00
"No XStyleFamiliesSupplier from XModel for export!" );
if( xFamiliesSupp.is() )
{
Reference< XNameAccess > xFamilies( xFamiliesSupp->getStyleFamilies() );
SAL_WARN_IF( !xFamiliesSupp.is(), "xmloff",
2000-10-11 06:51:24 +00:00
"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
SAL_WARN_IF( !xPageStyles.is(), "xmloff",
2000-10-11 06:51:24 +00:00
"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);
2000-10-20 04:36:28 +00:00
}
void XMLPageExport::exportDefaultStyle()
{
Reference < lang::XMultiServiceFactory > xFactory (GetExport().GetModel(), UNO_QUERY);
if (xFactory.is())
{
Reference < XPropertySet > xPropSet (xFactory->createInstance ( "com.sun.star.text.Defaults" ), 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: */