1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <com/sun/star/text/XText.hpp>
21 #include <com/sun/star/text/XParagraphAppend.hpp>
22 #include <com/sun/star/text/XRelativeTextContentRemove.hpp>
23 #include <xmloff/nmspmap.hxx>
24 #include <xmloff/xmlnmspe.hxx>
25 #include "XMLTextHeaderFooterContext.hxx"
26 #include <xmloff/XMLTextTableContext.hxx>
27 #include <xmloff/xmlimp.hxx>
31 using namespace ::com::sun::star
;
32 using namespace ::com::sun::star::uno
;
33 using namespace ::com::sun::star::xml::sax
;
34 using namespace ::com::sun::star::text
;
35 using namespace ::com::sun::star::beans
;
38 TYPEINIT1( XMLTextHeaderFooterContext
, SvXMLImportContext
);
40 XMLTextHeaderFooterContext::XMLTextHeaderFooterContext( SvXMLImport
& rImport
, sal_uInt16 nPrfx
,
41 const OUString
& rLName
,
43 xml::sax::XAttributeList
> &,
44 const Reference
< XPropertySet
> & rPageStylePropSet
,
45 bool bFooter
, bool bLft
, bool bFrst
) :
46 SvXMLImportContext( rImport
, nPrfx
, rLName
),
47 xPropSet( rPageStylePropSet
),
48 sOn( bFooter
? OUString("FooterIsOn") : OUString("HeaderIsOn") ),
49 sShareContent( bFooter
? OUString("FooterIsShared") : OUString("HeaderIsShared") ),
50 sShareContentFirst( "FirstIsShared" ),
51 sText( bFooter
? OUString("FooterText") : OUString("HeaderText") ),
52 sTextFirst(bFooter
? OUString("FooterTextFirst") : OUString("HeaderTextFirst")),
53 sTextLeft( bFooter
? OUString("FooterTextLeft") : OUString("HeaderTextLeft") ),
54 bInsertContent( true ),
58 // NOTE: if this ever handles XML_DISPLAY attr then beware of fdo#72850 !
63 aAny
= xPropSet
->getPropertyValue( sOn
);
64 bool bOn
= *static_cast<sal_Bool
const *>(aAny
.getValue());
70 aAny
= xPropSet
->getPropertyValue( sShareContent
);
72 if (!(aAny
>>= bShared
))
73 assert(false); // should return a value!
76 // Don't share headers any longer
78 aAny
.setValue( &bShared
, cppu::UnoType
<bool>::get() );
79 xPropSet
->setPropertyValue( sShareContent
, aAny
);
84 aAny
= xPropSet
->getPropertyValue( sShareContentFirst
);
86 if (!(aAny
>>= bSharedFirst
))
87 assert(false); // should return a value!
90 // Don't share first/right headers any longer
92 aAny
.setValue( &bSharedFirst
, cppu::UnoType
<bool>::get() );
93 xPropSet
->setPropertyValue( sShareContentFirst
, aAny
);
99 // If headers or footers are switched off, no content must be
101 bInsertContent
= false;
106 XMLTextHeaderFooterContext::~XMLTextHeaderFooterContext()
110 SvXMLImportContext
*XMLTextHeaderFooterContext::CreateChildContext(
112 const OUString
& rLocalName
,
113 const uno::Reference
< xml::sax::XAttributeList
> & xAttrList
)
115 SvXMLImportContext
*pContext
= 0;
118 if( !xOldTextCursor
.is() )
120 bool bRemoveContent
= true;
122 if( bLeft
|| bFirst
)
124 // Headers and footers are switched on already,
125 // and they aren't shared.
127 aAny
= xPropSet
->getPropertyValue( sTextLeft
);
129 aAny
= xPropSet
->getPropertyValue( sTextFirst
);
133 aAny
= xPropSet
->getPropertyValue( sOn
);
134 sal_Bool bOn
= *static_cast<sal_Bool
const *>(aAny
.getValue());
140 aAny
.setValue( &bOn
, cppu::UnoType
<bool>::get() );
141 xPropSet
->setPropertyValue( sOn
, aAny
);
143 // The content has not to be removed, because the header
144 // or footer is empty already.
145 bRemoveContent
= false;
148 // If a header or footer is not shared, share it now.
149 aAny
= xPropSet
->getPropertyValue( sShareContent
);
150 sal_Bool bShared
= *static_cast<sal_Bool
const *>(aAny
.getValue());
154 aAny
.setValue( &bShared
, cppu::UnoType
<bool>::get() );
155 xPropSet
->setPropertyValue( sShareContent
, aAny
);
158 aAny
= xPropSet
->getPropertyValue( sText
);
161 Reference
< XText
> xText
;
166 xText
->setString(OUString());
167 // fdo#82165 shapes anchored at the beginning or end survive
168 // setString("") - kill them the hard way: SwDoc::DelFullPara()
169 uno::Reference
<text::XParagraphAppend
> const xAppend(
170 xText
, uno::UNO_QUERY_THROW
);
171 uno::Reference
<lang::XComponent
> const xPara(
172 xAppend
->finishParagraph(
173 uno::Sequence
<beans::PropertyValue
>()),
174 uno::UNO_QUERY_THROW
);
178 rtl::Reference
< XMLTextImportHelper
> xTxtImport
=
179 GetImport().GetTextImport();
181 xOldTextCursor
= xTxtImport
->GetCursor();
182 xTxtImport
->SetCursor( xText
->createTextCursor() );
186 GetImport().GetTextImport()->CreateTextChildContext(
187 GetImport(), nPrefix
, rLocalName
, xAttrList
,
188 XML_TEXT_TYPE_HEADER_FOOTER
);
191 pContext
= new SvXMLImportContext( GetImport(), nPrefix
, rLocalName
);
196 void XMLTextHeaderFooterContext::EndElement()
198 if( xOldTextCursor
.is() )
200 GetImport().GetTextImport()->DeleteParagraph();
201 GetImport().GetTextImport()->SetCursor( xOldTextCursor
);
205 // If no content has been inserted inro the header or footer,
207 sal_Bool bOn
= sal_False
;
209 aAny
.setValue( &bOn
, cppu::UnoType
<bool>::get() );
210 xPropSet
->setPropertyValue( sOn
, aAny
);
214 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */