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 <xmloff/nmspmap.hxx>
22 #include <xmloff/xmlnmspe.hxx>
23 #include "XMLTableHeaderFooterContext.hxx"
24 #include <xmloff/xmltoken.hxx>
25 #include <comphelper/extract.hxx>
27 #include "unonames.hxx"
29 using namespace ::com::sun::star
;
30 using namespace ::com::sun::star::uno
;
31 using namespace ::com::sun::star::xml::sax
;
32 using namespace ::com::sun::star::text
;
33 using namespace ::com::sun::star::beans
;
34 using namespace xmloff::token
;
36 TYPEINIT1( XMLTableHeaderFooterContext
, SvXMLImportContext
);
38 XMLTableHeaderFooterContext::XMLTableHeaderFooterContext( SvXMLImport
& rImport
, sal_uInt16 nPrfx
,
39 const OUString
& rLName
,
41 xml::sax::XAttributeList
> & xAttrList
,
42 const Reference
< XPropertySet
> & rPageStylePropSet
,
43 bool bFooter
, bool bLft
) :
44 SvXMLImportContext( rImport
, nPrfx
, rLName
),
45 xPropSet( rPageStylePropSet
),
46 sOn( bFooter
? OUString(SC_UNO_PAGE_FTRON
) : OUString(SC_UNO_PAGE_HDRON
) ),
47 sShareContent( bFooter
? OUString(SC_UNO_PAGE_FTRSHARED
) : OUString(SC_UNO_PAGE_HDRSHARED
) ),
48 sContent( bFooter
? OUString(SC_UNO_PAGE_RIGHTFTRCON
) : OUString(SC_UNO_PAGE_RIGHTHDRCON
) ),
49 sContentLeft( bFooter
? OUString(SC_UNO_PAGE_LEFTFTRCONT
) : OUString(SC_UNO_PAGE_LEFTHDRCONT
) ),
53 bContainsRight(false),
54 bContainsCenter(false)
56 sal_Int16
nAttrCount(xAttrList
.is() ? xAttrList
->getLength() : 0);
57 for( sal_Int16 i
=0; i
< nAttrCount
; ++i
)
59 const OUString
& rAttrName(xAttrList
->getNameByIndex( i
));
61 sal_uInt16
nPrefix(GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName
, &aLName
));
62 const OUString
& rValue(xAttrList
->getValueByIndex( i
));
64 // TODO: use a map here
65 if( XML_NAMESPACE_STYLE
== nPrefix
)
67 if( IsXMLToken(aLName
, XML_DISPLAY
) )
68 bDisplay
= IsXMLToken(rValue
, XML_TRUE
);
73 bool bOn(::cppu::any2bool(xPropSet
->getPropertyValue( sOn
)));
77 if( ::cppu::any2bool(xPropSet
->getPropertyValue( sShareContent
)) )
78 // Don't share headers any longer
79 xPropSet
->setPropertyValue( sShareContent
, uno::makeAny(false) );
83 if( !::cppu::any2bool(xPropSet
->getPropertyValue( sShareContent
)) )
85 xPropSet
->setPropertyValue( sShareContent
, uno::makeAny(sal_True
) );
90 bool bOn(::cppu::any2bool(xPropSet
->getPropertyValue( sOn
)));
91 if ( bOn
!= bDisplay
)
92 xPropSet
->setPropertyValue( sOn
, uno::makeAny(bDisplay
) );
98 xPropSet
->getPropertyValue( sCont
) >>= xHeaderFooterContent
;
101 XMLTableHeaderFooterContext::~XMLTableHeaderFooterContext()
105 SvXMLImportContext
*XMLTableHeaderFooterContext::CreateChildContext(
107 const OUString
& rLocalName
,
108 const uno::Reference
< xml::sax::XAttributeList
> & xAttrList
)
110 SvXMLImportContext
*pContext(0);
112 if ((nPrefix
== XML_NAMESPACE_TEXT
) &&
113 IsXMLToken(rLocalName
, XML_P
))
115 if (!xTextCursor
.is())
117 if( xHeaderFooterContent
.is() )
119 uno::Reference
< text::XText
> xText(xHeaderFooterContent
->getCenterText());
120 xText
->setString(sEmpty
);
121 xTextCursor
.set(xText
->createTextCursor());
122 xOldTextCursor
.set(GetImport().GetTextImport()->GetCursor());
123 GetImport().GetTextImport()->SetCursor( xTextCursor
);
124 bContainsCenter
= true;
128 GetImport().GetTextImport()->CreateTextChildContext(GetImport(),
135 if (nPrefix
== XML_NAMESPACE_STYLE
)
137 if (xHeaderFooterContent
.is())
139 uno::Reference
< text::XText
> xText
;
140 if (IsXMLToken(rLocalName
, XML_REGION_LEFT
))
142 xText
.set(xHeaderFooterContent
->getLeftText());
143 bContainsLeft
= true;
145 else if (IsXMLToken(rLocalName
, XML_REGION_CENTER
))
147 xText
.set(xHeaderFooterContent
->getCenterText());
148 bContainsCenter
= true;
150 else if (IsXMLToken(rLocalName
, XML_REGION_RIGHT
))
152 xText
.set(xHeaderFooterContent
->getRightText());
153 bContainsRight
= true;
157 xText
->setString(sEmpty
);
158 //SvXMLImport aSvXMLImport( GetImport() );
159 uno::Reference
< text::XTextCursor
> xTempTextCursor(xText
->createTextCursor());
160 pContext
= new XMLHeaderFooterRegionContext( GetImport(), nPrefix
, rLocalName
, xAttrList
, xTempTextCursor
);
166 pContext
= new SvXMLImportContext( GetImport(), nPrefix
, rLocalName
);
171 void XMLTableHeaderFooterContext::EndElement()
173 if( GetImport().GetTextImport()->GetCursor().is() )
175 //GetImport().GetTextImport()->GetCursor()->gotoEnd(sal_False);
176 if( GetImport().GetTextImport()->GetCursor()->goLeft( 1, true ) )
178 GetImport().GetTextImport()->GetText()->insertString(
179 GetImport().GetTextImport()->GetCursorAsRange(), sEmpty
,
182 GetImport().GetTextImport()->ResetCursor();
184 if (xOldTextCursor
.is())
185 GetImport().GetTextImport()->SetCursor(xOldTextCursor
);
186 if (xHeaderFooterContent
.is())
189 xHeaderFooterContent
->getLeftText()->setString(sEmpty
);
190 if (!bContainsCenter
)
191 xHeaderFooterContent
->getCenterText()->setString(sEmpty
);
193 xHeaderFooterContent
->getRightText()->setString(sEmpty
);
195 xPropSet
->setPropertyValue( sCont
, uno::makeAny(xHeaderFooterContent
) );
199 TYPEINIT1( XMLHeaderFooterRegionContext
, SvXMLImportContext
);
201 XMLHeaderFooterRegionContext::XMLHeaderFooterRegionContext( SvXMLImport
& rImport
, sal_uInt16 nPrfx
,
202 const OUString
& rLName
,
203 const uno::Reference
<
204 xml::sax::XAttributeList
> & /* xAttrList */,
205 uno::Reference
< text::XTextCursor
>& xCursor
) :
206 SvXMLImportContext( rImport
, nPrfx
, rLName
),
207 xTextCursor ( xCursor
)
209 xOldTextCursor
.set(GetImport().GetTextImport()->GetCursor());
210 GetImport().GetTextImport()->SetCursor( xTextCursor
);
213 XMLHeaderFooterRegionContext::~XMLHeaderFooterRegionContext()
217 SvXMLImportContext
*XMLHeaderFooterRegionContext::CreateChildContext(
219 const OUString
& rLocalName
,
220 const uno::Reference
< xml::sax::XAttributeList
> & xAttrList
)
222 SvXMLImportContext
*pContext(0);
224 if ((nPrefix
== XML_NAMESPACE_TEXT
) &&
225 IsXMLToken(rLocalName
, XML_P
))
228 GetImport().GetTextImport()->CreateTextChildContext(GetImport(),
234 pContext
= new SvXMLImportContext( GetImport(), nPrefix
, rLocalName
);
239 void XMLHeaderFooterRegionContext::EndElement()
241 if( GetImport().GetTextImport()->GetCursor().is() )
243 //GetImport().GetTextImport()->GetCursor()->gotoEnd(sal_False);
244 if( GetImport().GetTextImport()->GetCursor()->goLeft( 1, true ) )
247 GetImport().GetTextImport()->GetText()->insertString(
248 GetImport().GetTextImport()->GetCursorAsRange(), sEmpty
,
251 GetImport().GetTextImport()->ResetCursor();
253 if (xOldTextCursor
.is())
254 GetImport().GetTextImport()->SetCursor(xOldTextCursor
);
257 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */