Files
libreoffice/xmloff/source/text/XMLTextHeaderFooterContext.cxx

205 lines
7.3 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-12 17:10:10 +00:00
#include <com/sun/star/text/XText.hpp>
2000-10-26 08:29:25 +00:00
#include <com/sun/star/text/XRelativeTextContentRemove.hpp>
#include <xmloff/nmspmap.hxx>
#include "xmloff/xmlnmspe.hxx"
2000-10-12 17:10:10 +00:00
#include "XMLTextHeaderFooterContext.hxx"
#include <xmloff/XMLTextTableContext.hxx>
#include <xmloff/xmlimp.hxx>
2000-10-12 17:10:10 +00:00
using ::rtl::OUString;
using ::rtl::OUStringBuffer;
2000-10-12 17:10:10 +00:00
using namespace ::com::sun::star;
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::xml::sax;
using namespace ::com::sun::star::text;
using namespace ::com::sun::star::beans;
TYPEINIT1( XMLTextHeaderFooterContext, SvXMLImportContext );
XMLTextHeaderFooterContext::XMLTextHeaderFooterContext( SvXMLImport& rImport, sal_uInt16 nPrfx,
const OUString& rLName,
const uno::Reference<
xml::sax::XAttributeList > &,
2000-10-12 17:10:10 +00:00
const Reference < XPropertySet > & rPageStylePropSet,
sal_Bool bFooter, sal_Bool bLft, sal_Bool bFrst ) :
2000-10-12 17:10:10 +00:00
SvXMLImportContext( rImport, nPrfx, rLName ),
xPropSet( rPageStylePropSet ),
sOn( bFooter ? OUString(RTL_CONSTASCII_USTRINGPARAM( "FooterIsOn" )) : OUString(RTL_CONSTASCII_USTRINGPARAM( "HeaderIsOn" )) ),
sShareContent( bFooter ? OUString(RTL_CONSTASCII_USTRINGPARAM( "FooterIsShared" ))
: OUString(RTL_CONSTASCII_USTRINGPARAM( "HeaderIsShared" )) ),
sShareContentFirst( "FirstIsShared" ),
sText( bFooter ? OUString(RTL_CONSTASCII_USTRINGPARAM( "FooterText" )) : OUString(RTL_CONSTASCII_USTRINGPARAM( "HeaderText" )) ),
sTextFirst(bFooter ? OUString("FooterTextFirst") : OUString("HeaderTextFirst")),
sTextLeft( bFooter ? OUString(RTL_CONSTASCII_USTRINGPARAM( "FooterTextLeft" ))
: OUString(RTL_CONSTASCII_USTRINGPARAM( "HeaderTextLeft" )) ),
2000-10-12 17:10:10 +00:00
bInsertContent( sal_True ),
bLeft( bLft ),
bFirst( bFrst )
2000-10-12 17:10:10 +00:00
{
if( bLeft || bFirst )
2000-10-12 17:10:10 +00:00
{
Any aAny;
aAny = xPropSet->getPropertyValue( sOn );
sal_Bool bOn = *(sal_Bool *)aAny.getValue();
if( bOn )
{
if (bLeft)
2000-10-12 17:10:10 +00:00
{
aAny = xPropSet->getPropertyValue( sShareContent );
sal_Bool bShared = *(sal_Bool *)aAny.getValue();
if( bShared )
{
// Don't share headers any longer
bShared = sal_False;
aAny.setValue( &bShared, ::getBooleanCppuType() );
xPropSet->setPropertyValue( sShareContent, aAny );
}
}
if (bFirst)
{
aAny = xPropSet->getPropertyValue( sShareContentFirst );
sal_Bool bSharedFirst = *(sal_Bool *)aAny.getValue();
if( bSharedFirst )
{
// Don't share first/right headers any longer
bSharedFirst = sal_False;
aAny.setValue( &bSharedFirst, ::getBooleanCppuType() );
xPropSet->setPropertyValue( sShareContentFirst, aAny );
}
2000-10-12 17:10:10 +00:00
}
}
else
{
// If headers or footers are switched off, no content must be
// inserted.
bInsertContent = sal_False;
}
}
}
XMLTextHeaderFooterContext::~XMLTextHeaderFooterContext()
{
}
SvXMLImportContext *XMLTextHeaderFooterContext::CreateChildContext(
sal_uInt16 nPrefix,
const OUString& rLocalName,
const uno::Reference< xml::sax::XAttributeList > & xAttrList )
{
SvXMLImportContext *pContext = 0;
if( bInsertContent )
{
if( !xOldTextCursor.is() )
{
sal_Bool bRemoveContent = sal_True;
Any aAny;
if( bLeft || bFirst )
2000-10-12 17:10:10 +00:00
{
// Headers and footers are switched on already,
// and they aren't shared.
if (bLeft)
aAny = xPropSet->getPropertyValue( sTextLeft );
else
aAny = xPropSet->getPropertyValue( sTextFirst );
2000-10-12 17:10:10 +00:00
}
else
{
aAny = xPropSet->getPropertyValue( sOn );
sal_Bool bOn = *(sal_Bool *)aAny.getValue();
if( !bOn )
{
// Switch header on
bOn = sal_True;
aAny.setValue( &bOn, ::getBooleanCppuType() );
xPropSet->setPropertyValue( sOn, aAny );
// The content has not to be removed, because the header
// or footer is empty already.
bRemoveContent = sal_False;
2000-10-12 17:10:10 +00:00
}
// If a header or footer is not shared, share it now.
aAny = xPropSet->getPropertyValue( sShareContent );
sal_Bool bShared = *(sal_Bool *)aAny.getValue();
if( !bShared )
{
bShared = sal_True;
aAny.setValue( &bShared, ::getBooleanCppuType() );
xPropSet->setPropertyValue( sShareContent, aAny );
}
aAny = xPropSet->getPropertyValue( sText );
}
Reference < XText > xText;
aAny >>= xText;
if( bRemoveContent )
{
OUString aText;
xText->setString( aText );
2000-10-12 17:10:10 +00:00
}
UniReference < XMLTextImportHelper > xTxtImport =
GetImport().GetTextImport();
xOldTextCursor = xTxtImport->GetCursor();
xTxtImport->SetCursor( xText->createTextCursor() );
}
pContext =
2000-10-26 08:29:25 +00:00
GetImport().GetTextImport()->CreateTextChildContext(
GetImport(), nPrefix, rLocalName, xAttrList,
XML_TEXT_TYPE_HEADER_FOOTER );
2000-10-12 17:10:10 +00:00
}
if( !pContext )
pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
return pContext;
}
void XMLTextHeaderFooterContext::EndElement()
{
if( xOldTextCursor.is() )
{
2001-03-09 06:23:23 +00:00
GetImport().GetTextImport()->DeleteParagraph();
2000-10-12 17:10:10 +00:00
GetImport().GetTextImport()->SetCursor( xOldTextCursor );
}
else if( !bLeft )
{
// If no content has been inserted inro the header or footer,
// switch it off.
sal_Bool bOn = sal_False;
Any aAny;
aAny.setValue( &bOn, ::getBooleanCppuType() );
xPropSet->setPropertyValue( sOn, aAny );
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */