fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / xmloff / source / text / XMLTextHeaderFooterContext.cxx
blob335d95bac5ed78e8ef8f3a181c48082bc0b44b24
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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,
41 const uno::Reference<
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 ),
54 bLeft( bLft ),
55 bFirst( bFrst )
57 // NOTE: if this ever handles XML_DISPLAY attr then beware of fdo#72850 !
58 if( bLeft || bFirst )
60 Any aAny;
62 aAny = xPropSet->getPropertyValue( sOn );
63 sal_Bool bOn = *(sal_Bool *)aAny.getValue();
65 if( bOn )
67 if (bLeft)
69 aAny = xPropSet->getPropertyValue( sShareContent );
70 sal_Bool bShared = *(sal_Bool *)aAny.getValue();
71 if( bShared )
73 // Don't share headers any longer
74 bShared = sal_False;
75 aAny.setValue( &bShared, ::getBooleanCppuType() );
76 xPropSet->setPropertyValue( sShareContent, aAny );
79 if (bFirst)
81 aAny = xPropSet->getPropertyValue( sShareContentFirst );
82 sal_Bool bSharedFirst = aAny.has<sal_Bool>() && *(sal_Bool *)aAny.getValue();
83 if( bSharedFirst )
85 // Don't share first/right headers any longer
86 bSharedFirst = sal_False;
87 aAny.setValue( &bSharedFirst, ::getBooleanCppuType() );
88 xPropSet->setPropertyValue( sShareContentFirst, aAny );
92 else
94 // If headers or footers are switched off, no content must be
95 // inserted.
96 bInsertContent = sal_False;
101 XMLTextHeaderFooterContext::~XMLTextHeaderFooterContext()
105 SvXMLImportContext *XMLTextHeaderFooterContext::CreateChildContext(
106 sal_uInt16 nPrefix,
107 const OUString& rLocalName,
108 const uno::Reference< xml::sax::XAttributeList > & xAttrList )
110 SvXMLImportContext *pContext = 0;
111 if( bInsertContent )
113 if( !xOldTextCursor.is() )
115 sal_Bool bRemoveContent = sal_True;
116 Any aAny;
117 if( bLeft || bFirst )
119 // Headers and footers are switched on already,
120 // and they aren't shared.
121 if (bLeft)
122 aAny = xPropSet->getPropertyValue( sTextLeft );
123 else
124 aAny = xPropSet->getPropertyValue( sTextFirst );
126 else
128 aAny = xPropSet->getPropertyValue( sOn );
129 sal_Bool bOn = *(sal_Bool *)aAny.getValue();
131 if( !bOn )
133 // Switch header on
134 bOn = sal_True;
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();
146 if( !bShared )
148 bShared = sal_True;
149 aAny.setValue( &bShared, ::getBooleanCppuType() );
150 xPropSet->setPropertyValue( sShareContent, aAny );
153 aAny = xPropSet->getPropertyValue( sText );
156 Reference < XText > xText;
157 aAny >>= xText;
159 if( bRemoveContent )
161 OUString aText;
162 xText->setString( aText );
165 UniReference < XMLTextImportHelper > xTxtImport =
166 GetImport().GetTextImport();
168 xOldTextCursor = xTxtImport->GetCursor();
169 xTxtImport->SetCursor( xText->createTextCursor() );
172 pContext =
173 GetImport().GetTextImport()->CreateTextChildContext(
174 GetImport(), nPrefix, rLocalName, xAttrList,
175 XML_TEXT_TYPE_HEADER_FOOTER );
177 if( !pContext )
178 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
180 return pContext;
183 void XMLTextHeaderFooterContext::EndElement()
185 if( xOldTextCursor.is() )
187 GetImport().GetTextImport()->DeleteParagraph();
188 GetImport().GetTextImport()->SetCursor( xOldTextCursor );
190 else if( !bLeft )
192 // If no content has been inserted inro the header or footer,
193 // switch it off.
194 sal_Bool bOn = sal_False;
195 Any aAny;
196 aAny.setValue( &bOn, ::getBooleanCppuType() );
197 xPropSet->setPropertyValue( sOn, aAny );
201 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */