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/XRelativeTextContentRemove.hpp>
22 #include <xmloff/nmspmap.hxx>
23 #include "xmloff/xmlnmspe.hxx"
24 #include "XMLTextHeaderFooterContext.hxx"
25 #include <xmloff/XMLTextTableContext.hxx>
26 #include <xmloff/xmlimp.hxx>
30 using namespace ::com::sun::star
;
31 using namespace ::com::sun::star::uno
;
32 using namespace ::com::sun::star::xml::sax
;
33 using namespace ::com::sun::star::text
;
34 using namespace ::com::sun::star::beans
;
37 TYPEINIT1( XMLTextHeaderFooterContext
, SvXMLImportContext
);
39 XMLTextHeaderFooterContext::XMLTextHeaderFooterContext( SvXMLImport
& rImport
, sal_uInt16 nPrfx
,
40 const OUString
& rLName
,
42 xml::sax::XAttributeList
> &,
43 const Reference
< XPropertySet
> & rPageStylePropSet
,
44 sal_Bool bFooter
, sal_Bool bLft
, sal_Bool bFrst
) :
45 SvXMLImportContext( rImport
, nPrfx
, rLName
),
46 xPropSet( rPageStylePropSet
),
47 sOn( bFooter
? OUString("FooterIsOn") : OUString("HeaderIsOn") ),
48 sShareContent( bFooter
? OUString("FooterIsShared") : OUString("HeaderIsShared") ),
49 sShareContentFirst( "FirstIsShared" ),
50 sText( bFooter
? OUString("FooterText") : OUString("HeaderText") ),
51 sTextFirst(bFooter
? OUString("FooterTextFirst") : OUString("HeaderTextFirst")),
52 sTextLeft( bFooter
? OUString("FooterTextLeft") : OUString("HeaderTextLeft") ),
53 bInsertContent( sal_True
),
57 // NOTE: if this ever handles XML_DISPLAY attr then beware of fdo#72850 !
62 aAny
= xPropSet
->getPropertyValue( sOn
);
63 sal_Bool bOn
= *(sal_Bool
*)aAny
.getValue();
69 aAny
= xPropSet
->getPropertyValue( sShareContent
);
70 sal_Bool bShared
= *(sal_Bool
*)aAny
.getValue();
73 // Don't share headers any longer
75 aAny
.setValue( &bShared
, ::getBooleanCppuType() );
76 xPropSet
->setPropertyValue( sShareContent
, aAny
);
81 aAny
= xPropSet
->getPropertyValue( sShareContentFirst
);
82 sal_Bool bSharedFirst
= aAny
.has
<sal_Bool
>() && *(sal_Bool
*)aAny
.getValue();
85 // Don't share first/right headers any longer
86 bSharedFirst
= sal_False
;
87 aAny
.setValue( &bSharedFirst
, ::getBooleanCppuType() );
88 xPropSet
->setPropertyValue( sShareContentFirst
, aAny
);
94 // If headers or footers are switched off, no content must be
96 bInsertContent
= sal_False
;
101 XMLTextHeaderFooterContext::~XMLTextHeaderFooterContext()
105 SvXMLImportContext
*XMLTextHeaderFooterContext::CreateChildContext(
107 const OUString
& rLocalName
,
108 const uno::Reference
< xml::sax::XAttributeList
> & xAttrList
)
110 SvXMLImportContext
*pContext
= 0;
113 if( !xOldTextCursor
.is() )
115 sal_Bool bRemoveContent
= sal_True
;
117 if( bLeft
|| bFirst
)
119 // Headers and footers are switched on already,
120 // and they aren't shared.
122 aAny
= xPropSet
->getPropertyValue( sTextLeft
);
124 aAny
= xPropSet
->getPropertyValue( sTextFirst
);
128 aAny
= xPropSet
->getPropertyValue( sOn
);
129 sal_Bool bOn
= *(sal_Bool
*)aAny
.getValue();
135 aAny
.setValue( &bOn
, ::getBooleanCppuType() );
136 xPropSet
->setPropertyValue( sOn
, aAny
);
138 // The content has not to be removed, because the header
139 // or footer is empty already.
140 bRemoveContent
= sal_False
;
143 // If a header or footer is not shared, share it now.
144 aAny
= xPropSet
->getPropertyValue( sShareContent
);
145 sal_Bool bShared
= *(sal_Bool
*)aAny
.getValue();
149 aAny
.setValue( &bShared
, ::getBooleanCppuType() );
150 xPropSet
->setPropertyValue( sShareContent
, aAny
);
153 aAny
= xPropSet
->getPropertyValue( sText
);
156 Reference
< XText
> xText
;
162 xText
->setString( aText
);
165 UniReference
< XMLTextImportHelper
> xTxtImport
=
166 GetImport().GetTextImport();
168 xOldTextCursor
= xTxtImport
->GetCursor();
169 xTxtImport
->SetCursor( xText
->createTextCursor() );
173 GetImport().GetTextImport()->CreateTextChildContext(
174 GetImport(), nPrefix
, rLocalName
, xAttrList
,
175 XML_TEXT_TYPE_HEADER_FOOTER
);
178 pContext
= new SvXMLImportContext( GetImport(), nPrefix
, rLocalName
);
183 void XMLTextHeaderFooterContext::EndElement()
185 if( xOldTextCursor
.is() )
187 GetImport().GetTextImport()->DeleteParagraph();
188 GetImport().GetTextImport()->SetCursor( xOldTextCursor
);
192 // If no content has been inserted inro the header or footer,
194 sal_Bool bOn
= sal_False
;
196 aAny
.setValue( &bOn
, ::getBooleanCppuType() );
197 xPropSet
->setPropertyValue( sOn
, aAny
);
201 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */