1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include <com/sun/star/text/XText.hpp>
30 #include <com/sun/star/text/XRelativeTextContentRemove.hpp>
31 #include <xmloff/nmspmap.hxx>
32 #include "xmloff/xmlnmspe.hxx"
33 #include "XMLTextHeaderFooterContext.hxx"
34 #include <xmloff/XMLTextTableContext.hxx>
35 #include <xmloff/xmlimp.hxx>
38 using ::rtl::OUString
;
39 using ::rtl::OUStringBuffer
;
41 using namespace ::com::sun::star
;
42 using namespace ::com::sun::star::uno
;
43 using namespace ::com::sun::star::xml::sax
;
44 using namespace ::com::sun::star::text
;
45 using namespace ::com::sun::star::beans
;
48 TYPEINIT1( XMLTextHeaderFooterContext
, SvXMLImportContext
);
50 XMLTextHeaderFooterContext::XMLTextHeaderFooterContext( SvXMLImport
& rImport
, sal_uInt16 nPrfx
,
51 const OUString
& rLName
,
53 xml::sax::XAttributeList
> &,
54 const Reference
< XPropertySet
> & rPageStylePropSet
,
55 sal_Bool bFooter
, sal_Bool bLft
) :
56 SvXMLImportContext( rImport
, nPrfx
, rLName
),
57 xPropSet( rPageStylePropSet
),
58 sOn( bFooter
? OUString(RTL_CONSTASCII_USTRINGPARAM( "FooterIsOn" )) : OUString(RTL_CONSTASCII_USTRINGPARAM( "HeaderIsOn" )) ),
59 sShareContent( bFooter
? OUString(RTL_CONSTASCII_USTRINGPARAM( "FooterIsShared" ))
60 : OUString(RTL_CONSTASCII_USTRINGPARAM( "HeaderIsShared" )) ),
61 sText( bFooter
? OUString(RTL_CONSTASCII_USTRINGPARAM( "FooterText" )) : OUString(RTL_CONSTASCII_USTRINGPARAM( "HeaderText" )) ),
62 sTextLeft( bFooter
? OUString(RTL_CONSTASCII_USTRINGPARAM( "FooterTextLeft" ))
63 : OUString(RTL_CONSTASCII_USTRINGPARAM( "HeaderTextLeft" )) ),
64 bInsertContent( sal_True
),
71 aAny
= xPropSet
->getPropertyValue( sOn
);
72 sal_Bool bOn
= *(sal_Bool
*)aAny
.getValue();
76 aAny
= xPropSet
->getPropertyValue( sShareContent
);
77 sal_Bool bShared
= *(sal_Bool
*)aAny
.getValue();
80 // Don't share headers any longer
82 aAny
.setValue( &bShared
, ::getBooleanCppuType() );
83 xPropSet
->setPropertyValue( sShareContent
, aAny
);
88 // If headers or footers are switched off, no content must be
90 bInsertContent
= sal_False
;
95 XMLTextHeaderFooterContext::~XMLTextHeaderFooterContext()
99 SvXMLImportContext
*XMLTextHeaderFooterContext::CreateChildContext(
101 const OUString
& rLocalName
,
102 const uno::Reference
< xml::sax::XAttributeList
> & xAttrList
)
104 SvXMLImportContext
*pContext
= 0;
107 if( !xOldTextCursor
.is() )
109 sal_Bool bRemoveContent
= sal_True
;
113 // Headers and footers are switched on already,
114 // and they aren't shared.
115 aAny
= xPropSet
->getPropertyValue( sTextLeft
);
119 aAny
= xPropSet
->getPropertyValue( sOn
);
120 sal_Bool bOn
= *(sal_Bool
*)aAny
.getValue();
126 aAny
.setValue( &bOn
, ::getBooleanCppuType() );
127 xPropSet
->setPropertyValue( sOn
, aAny
);
129 // The content has not to be removed, because the header
130 // or footer is empty already.
131 bRemoveContent
= sal_False
;
134 // If a header or footer is not shared, share it now.
135 aAny
= xPropSet
->getPropertyValue( sShareContent
);
136 sal_Bool bShared
= *(sal_Bool
*)aAny
.getValue();
140 aAny
.setValue( &bShared
, ::getBooleanCppuType() );
141 xPropSet
->setPropertyValue( sShareContent
, aAny
);
144 aAny
= xPropSet
->getPropertyValue( sText
);
147 Reference
< XText
> xText
;
153 xText
->setString( aText
);
156 UniReference
< XMLTextImportHelper
> xTxtImport
=
157 GetImport().GetTextImport();
159 xOldTextCursor
= xTxtImport
->GetCursor();
160 xTxtImport
->SetCursor( xText
->createTextCursor() );
164 GetImport().GetTextImport()->CreateTextChildContext(
165 GetImport(), nPrefix
, rLocalName
, xAttrList
,
166 XML_TEXT_TYPE_HEADER_FOOTER
);
169 pContext
= new SvXMLImportContext( GetImport(), nPrefix
, rLocalName
);
174 void XMLTextHeaderFooterContext::EndElement()
176 if( xOldTextCursor
.is() )
178 GetImport().GetTextImport()->DeleteParagraph();
179 GetImport().GetTextImport()->SetCursor( xOldTextCursor
);
183 // If no content has been inserted inro the header or footer,
185 sal_Bool bOn
= sal_False
;
187 aAny
.setValue( &bOn
, ::getBooleanCppuType() );
188 xPropSet
->setPropertyValue( sOn
, aAny
);
192 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */