nss: upgrade to release 3.73
[LibreOffice.git] / sc / source / filter / xml / XMLTableHeaderFooterContext.cxx
bloba728b6427a70d2c684f672bfd0cbbf5e55f294bf
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/beans/XPropertySet.hpp>
21 #include <com/sun/star/text/XText.hpp>
22 #include <com/sun/star/sheet/XHeaderFooterContent.hpp>
23 #include <xmloff/namespacemap.hxx>
24 #include <xmloff/xmlnamespace.hxx>
25 #include <xmloff/xmlimp.hxx>
26 #include "XMLTableHeaderFooterContext.hxx"
27 #include <xmloff/xmltoken.hxx>
28 #include <comphelper/extract.hxx>
29 #include <sal/log.hxx>
31 #include <unonames.hxx>
33 using namespace ::com::sun::star;
34 using namespace ::com::sun::star::uno;
35 using namespace ::com::sun::star::xml::sax;
36 using namespace ::com::sun::star::text;
37 using namespace ::com::sun::star::beans;
38 using namespace xmloff::token;
41 XMLTableHeaderFooterContext::XMLTableHeaderFooterContext( SvXMLImport& rImport, sal_Int32 /*nElement*/,
42 const uno::Reference<
43 xml::sax::XFastAttributeList > & xAttrList,
44 const Reference < XPropertySet > & rPageStylePropSet,
45 bool bFooter, bool bLeft ) :
46 SvXMLImportContext( rImport ),
47 xPropSet( rPageStylePropSet ),
48 bContainsLeft(false),
49 bContainsRight(false),
50 bContainsCenter(false)
52 OUString sOn( bFooter ? OUString(SC_UNO_PAGE_FTRON) : OUString(SC_UNO_PAGE_HDRON) );
53 OUString sContent( bFooter ? OUString(SC_UNO_PAGE_RIGHTFTRCON) : OUString(SC_UNO_PAGE_RIGHTHDRCON) );
54 OUString sContentLeft( bFooter ? OUString(SC_UNO_PAGE_LEFTFTRCONT) : OUString(SC_UNO_PAGE_LEFTHDRCONT) );
55 OUString sShareContent( bFooter ? OUString(SC_UNO_PAGE_FTRSHARED) : OUString(SC_UNO_PAGE_HDRSHARED) );
56 bool bDisplay( true );
57 for( auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList ) )
59 if( aIter.getToken() == XML_ELEMENT(STYLE, XML_DISPLAY) )
60 bDisplay = IsXMLToken(aIter.toString(), XML_TRUE);
61 else
62 XMLOFF_WARN_UNKNOWN("sc", aIter);
64 if( bLeft )
66 bool bOn(::cppu::any2bool(xPropSet->getPropertyValue( sOn )));
68 if( bOn && bDisplay )
70 if( ::cppu::any2bool(xPropSet->getPropertyValue( sShareContent )) )
71 // Don't share headers any longer
72 xPropSet->setPropertyValue( sShareContent, uno::makeAny(false) );
74 else
76 if( !::cppu::any2bool(xPropSet->getPropertyValue( sShareContent )) )
77 // share headers
78 xPropSet->setPropertyValue( sShareContent, uno::makeAny(true) );
81 else
83 bool bOn(::cppu::any2bool(xPropSet->getPropertyValue( sOn )));
84 if ( bOn != bDisplay )
85 xPropSet->setPropertyValue( sOn, uno::makeAny(bDisplay) );
87 if (bLeft)
88 sCont = sContentLeft;
89 else
90 sCont = sContent;
91 xPropSet->getPropertyValue( sCont ) >>= xHeaderFooterContent;
94 XMLTableHeaderFooterContext::~XMLTableHeaderFooterContext()
98 css::uno::Reference< css::xml::sax::XFastContextHandler > XMLTableHeaderFooterContext::createFastChildContext(
99 sal_Int32 nElement,
100 const css::uno::Reference< css::xml::sax::XFastAttributeList >& /*xAttrList*/ )
102 if (xHeaderFooterContent.is())
104 uno::Reference < text::XText > xText;
105 switch (nElement)
107 case XML_ELEMENT(STYLE, XML_REGION_LEFT):
108 xText.set(xHeaderFooterContent->getLeftText());
109 bContainsLeft = true;
110 break;
111 case XML_ELEMENT(STYLE, XML_REGION_CENTER):
112 xText.set(xHeaderFooterContent->getCenterText());
113 bContainsCenter = true;
114 break;
115 case XML_ELEMENT(STYLE, XML_REGION_RIGHT):
116 xText.set(xHeaderFooterContent->getRightText());
117 bContainsRight = true;
118 break;
119 default: break;
121 if (xText.is())
123 xText->setString("");
124 uno::Reference < text::XTextCursor > xTempTextCursor(xText->createTextCursor());
125 return new XMLHeaderFooterRegionContext( GetImport(), xTempTextCursor);
128 return nullptr;
131 SvXMLImportContextRef XMLTableHeaderFooterContext::CreateChildContext(
132 sal_uInt16 nPrefix,
133 const OUString& rLocalName,
134 const uno::Reference< xml::sax::XAttributeList > & xAttrList )
136 SvXMLImportContext *pContext(nullptr);
138 if ((nPrefix == XML_NAMESPACE_TEXT) &&
139 IsXMLToken(rLocalName, XML_P))
141 if (!xTextCursor.is())
143 if( xHeaderFooterContent.is() )
145 uno::Reference < text::XText > xText(xHeaderFooterContent->getCenterText());
146 xText->setString("");
147 xTextCursor.set(xText->createTextCursor());
148 xOldTextCursor.set(GetImport().GetTextImport()->GetCursor());
149 GetImport().GetTextImport()->SetCursor( xTextCursor );
150 bContainsCenter = true;
153 pContext =
154 GetImport().GetTextImport()->CreateTextChildContext(GetImport(),
155 nPrefix,
156 rLocalName,
157 xAttrList);
160 return pContext;
163 void XMLTableHeaderFooterContext::endFastElement(sal_Int32 )
165 if( GetImport().GetTextImport()->GetCursor().is() )
167 //GetImport().GetTextImport()->GetCursor()->gotoEnd(sal_False);
168 if( GetImport().GetTextImport()->GetCursor()->goLeft( 1, true ) )
170 GetImport().GetTextImport()->GetText()->insertString(
171 GetImport().GetTextImport()->GetCursorAsRange(), "",
172 true );
174 GetImport().GetTextImport()->ResetCursor();
176 if (xOldTextCursor.is())
177 GetImport().GetTextImport()->SetCursor(xOldTextCursor);
178 if (xHeaderFooterContent.is())
180 if (!bContainsLeft)
181 xHeaderFooterContent->getLeftText()->setString("");
182 if (!bContainsCenter)
183 xHeaderFooterContent->getCenterText()->setString("");
184 if (!bContainsRight)
185 xHeaderFooterContent->getRightText()->setString("");
187 xPropSet->setPropertyValue( sCont, uno::makeAny(xHeaderFooterContent) );
192 XMLHeaderFooterRegionContext::XMLHeaderFooterRegionContext( SvXMLImport& rImport,
193 uno::Reference< text::XTextCursor >& xCursor ) :
194 SvXMLImportContext( rImport ),
195 xTextCursor ( xCursor )
197 xOldTextCursor.set(GetImport().GetTextImport()->GetCursor());
198 GetImport().GetTextImport()->SetCursor( xTextCursor );
201 XMLHeaderFooterRegionContext::~XMLHeaderFooterRegionContext()
205 SvXMLImportContextRef XMLHeaderFooterRegionContext::CreateChildContext(
206 sal_uInt16 nPrefix,
207 const OUString& rLocalName,
208 const uno::Reference< xml::sax::XAttributeList > & xAttrList )
210 SvXMLImportContext *pContext(nullptr);
212 if ((nPrefix == XML_NAMESPACE_TEXT) &&
213 IsXMLToken(rLocalName, XML_P))
215 pContext =
216 GetImport().GetTextImport()->CreateTextChildContext(GetImport(),
217 nPrefix,
218 rLocalName,
219 xAttrList);
222 return pContext;
225 void XMLHeaderFooterRegionContext::endFastElement(sal_Int32 )
227 if( GetImport().GetTextImport()->GetCursor().is() )
229 //GetImport().GetTextImport()->GetCursor()->gotoEnd(sal_False);
230 if( GetImport().GetTextImport()->GetCursor()->goLeft( 1, true ) )
232 GetImport().GetTextImport()->GetText()->insertString(
233 GetImport().GetTextImport()->GetCursorAsRange(), "",
234 true );
236 GetImport().GetTextImport()->ResetCursor();
238 if (xOldTextCursor.is())
239 GetImport().GetTextImport()->SetCursor(xOldTextCursor);
242 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */