Update ooo320-m1
[ooovba.git] / xmloff / source / text / XMLTextHeaderFooterContext.cxx
blob44588316e8ed401c3d0b10da6ab94806ea7a1e21
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: XMLTextHeaderFooterContext.cxx,v $
10 * $Revision: 1.13 $
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 <com/sun/star/text/XText.hpp>
34 #include <com/sun/star/text/XRelativeTextContentRemove.hpp>
35 #include <xmloff/nmspmap.hxx>
36 #include "xmlnmspe.hxx"
37 #include "XMLTextHeaderFooterContext.hxx"
38 #ifndef _XMLOFF_TEXTTABLECONTEXT_HXX_
39 #include <xmloff/XMLTextTableContext.hxx>
40 #endif
41 #include <xmloff/xmlimp.hxx>
44 using ::rtl::OUString;
45 using ::rtl::OUStringBuffer;
47 using namespace ::com::sun::star;
48 using namespace ::com::sun::star::uno;
49 using namespace ::com::sun::star::xml::sax;
50 //using namespace ::com::sun::star::style;
51 using namespace ::com::sun::star::text;
52 using namespace ::com::sun::star::beans;
53 //using namespace ::com::sun::star::container;
54 //using namespace ::com::sun::star::lang;
55 //using namespace ::com::sun::star::text;
58 TYPEINIT1( XMLTextHeaderFooterContext, SvXMLImportContext );
60 XMLTextHeaderFooterContext::XMLTextHeaderFooterContext( SvXMLImport& rImport, sal_uInt16 nPrfx,
61 const OUString& rLName,
62 const uno::Reference<
63 xml::sax::XAttributeList > &,
64 const Reference < XPropertySet > & rPageStylePropSet,
65 sal_Bool bFooter, sal_Bool bLft ) :
66 SvXMLImportContext( rImport, nPrfx, rLName ),
67 xPropSet( rPageStylePropSet ),
68 sOn( OUString::createFromAscii( bFooter ? "FooterIsOn" : "HeaderIsOn" ) ),
69 sShareContent( OUString::createFromAscii( bFooter ? "FooterIsShared"
70 : "HeaderIsShared" ) ),
71 sText( OUString::createFromAscii( bFooter ? "FooterText" : "HeaderText" ) ),
72 sTextLeft( OUString::createFromAscii( bFooter ? "FooterTextLeft"
73 : "HeaderTextLeft" ) ),
74 bInsertContent( sal_True ),
75 bLeft( bLft )
77 if( bLeft )
79 Any aAny;
81 aAny = xPropSet->getPropertyValue( sOn );
82 sal_Bool bOn = *(sal_Bool *)aAny.getValue();
84 if( bOn )
86 aAny = xPropSet->getPropertyValue( sShareContent );
87 sal_Bool bShared = *(sal_Bool *)aAny.getValue();
88 if( bShared )
90 // Don't share headers any longer
91 bShared = sal_False;
92 aAny.setValue( &bShared, ::getBooleanCppuType() );
93 xPropSet->setPropertyValue( sShareContent, aAny );
96 else
98 // If headers or footers are switched off, no content must be
99 // inserted.
100 bInsertContent = sal_False;
105 XMLTextHeaderFooterContext::~XMLTextHeaderFooterContext()
109 SvXMLImportContext *XMLTextHeaderFooterContext::CreateChildContext(
110 sal_uInt16 nPrefix,
111 const OUString& rLocalName,
112 const uno::Reference< xml::sax::XAttributeList > & xAttrList )
114 SvXMLImportContext *pContext = 0;
115 if( bInsertContent )
117 if( !xOldTextCursor.is() )
119 sal_Bool bRemoveContent = sal_True;
120 Any aAny;
121 if( bLeft )
123 // Headers and footers are switched on already,
124 // and they aren't shared.
125 aAny = xPropSet->getPropertyValue( sTextLeft );
127 else
129 aAny = xPropSet->getPropertyValue( sOn );
130 sal_Bool bOn = *(sal_Bool *)aAny.getValue();
132 if( !bOn )
134 // Switch header on
135 bOn = sal_True;
136 aAny.setValue( &bOn, ::getBooleanCppuType() );
137 xPropSet->setPropertyValue( sOn, aAny );
139 // The content has not to be removed, because the header
140 // or footer is empty already.
141 bRemoveContent = sal_False;
144 // If a header or footer is not shared, share it now.
145 aAny = xPropSet->getPropertyValue( sShareContent );
146 sal_Bool bShared = *(sal_Bool *)aAny.getValue();
147 if( !bShared )
149 bShared = sal_True;
150 aAny.setValue( &bShared, ::getBooleanCppuType() );
151 xPropSet->setPropertyValue( sShareContent, aAny );
154 aAny = xPropSet->getPropertyValue( sText );
157 Reference < XText > xText;
158 aAny >>= xText;
160 if( bRemoveContent )
162 OUString aText;
163 xText->setString( aText );
166 UniReference < XMLTextImportHelper > xTxtImport =
167 GetImport().GetTextImport();
169 xOldTextCursor = xTxtImport->GetCursor();
170 xTxtImport->SetCursor( xText->createTextCursor() );
173 pContext =
174 GetImport().GetTextImport()->CreateTextChildContext(
175 GetImport(), nPrefix, rLocalName, xAttrList,
176 XML_TEXT_TYPE_HEADER_FOOTER );
178 if( !pContext )
179 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
181 return pContext;
184 void XMLTextHeaderFooterContext::EndElement()
186 if( xOldTextCursor.is() )
188 GetImport().GetTextImport()->DeleteParagraph();
189 GetImport().GetTextImport()->SetCursor( xOldTextCursor );
191 else if( !bLeft )
193 // If no content has been inserted inro the header or footer,
194 // switch it off.
195 sal_Bool bOn = sal_False;
196 Any aAny;
197 aAny.setValue( &bOn, ::getBooleanCppuType() );
198 xPropSet->setPropertyValue( sOn, aAny );