update dev300-m58
[ooovba.git] / sc / source / filter / xml / XMLTableHeaderFooterContext.cxx
blobe9396d2caa138839eb7d959b564c3b4d9e9bbc88
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: XMLTableHeaderFooterContext.cxx,v $
10 * $Revision: 1.14 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
33 #include <com/sun/star/text/XText.hpp>
34 #include <xmloff/nmspmap.hxx>
35 #include <xmloff/xmlnmspe.hxx>
36 #include "XMLTableHeaderFooterContext.hxx"
37 #include <xmloff/xmltoken.hxx>
38 #include <comphelper/extract.hxx>
40 #include "unonames.hxx"
42 using ::rtl::OUString;
43 using namespace ::com::sun::star;
44 using namespace ::com::sun::star::uno;
45 using namespace ::com::sun::star::xml::sax;
46 using namespace ::com::sun::star::text;
47 using namespace ::com::sun::star::beans;
48 using namespace xmloff::token;
51 TYPEINIT1( XMLTableHeaderFooterContext, SvXMLImportContext );
53 XMLTableHeaderFooterContext::XMLTableHeaderFooterContext( SvXMLImport& rImport, sal_uInt16 nPrfx,
54 const OUString& rLName,
55 const uno::Reference<
56 xml::sax::XAttributeList > & xAttrList,
57 const Reference < XPropertySet > & rPageStylePropSet,
58 sal_Bool bFooter, sal_Bool bLft ) :
59 SvXMLImportContext( rImport, nPrfx, rLName ),
60 xPropSet( rPageStylePropSet ),
61 sOn( OUString::createFromAscii( bFooter ? SC_UNO_PAGE_FTRON : SC_UNO_PAGE_HDRON ) ),
62 sShareContent( OUString::createFromAscii( bFooter ? SC_UNO_PAGE_FTRSHARED : SC_UNO_PAGE_HDRSHARED ) ),
63 sContent( OUString::createFromAscii( bFooter ? SC_UNO_PAGE_RIGHTFTRCON : SC_UNO_PAGE_RIGHTHDRCON ) ),
64 sContentLeft( OUString::createFromAscii( bFooter ? SC_UNO_PAGE_LEFTFTRCONT : SC_UNO_PAGE_LEFTHDRCONT ) ),
65 bDisplay( sal_True ),
66 bInsertContent( sal_True ),
67 bLeft( bLft ),
68 bContainsLeft(sal_False),
69 bContainsRight(sal_False),
70 bContainsCenter(sal_False)
72 sal_Int16 nAttrCount(xAttrList.is() ? xAttrList->getLength() : 0);
73 for( sal_Int16 i=0; i < nAttrCount; ++i )
75 const OUString& rAttrName(xAttrList->getNameByIndex( i ));
76 OUString aLName;
77 sal_uInt16 nPrefix(GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName, &aLName ));
78 const OUString& rValue(xAttrList->getValueByIndex( i ));
80 // TODO: use a map here
81 if( XML_NAMESPACE_STYLE == nPrefix )
83 if( IsXMLToken(aLName, XML_DISPLAY ) )
84 bDisplay = IsXMLToken(rValue, XML_TRUE);
87 if( bLeft )
89 sal_Bool bOn(::cppu::any2bool(xPropSet->getPropertyValue( sOn )));
91 if( bOn && bDisplay )
93 if( ::cppu::any2bool(xPropSet->getPropertyValue( sShareContent )) )
94 // Don't share headers any longer
95 xPropSet->setPropertyValue( sShareContent, uno::makeAny(sal_False) );
97 else
99 if( !::cppu::any2bool(xPropSet->getPropertyValue( sShareContent )) )
100 // share headers
101 xPropSet->setPropertyValue( sShareContent, uno::makeAny(sal_True) );
104 else
106 sal_Bool bOn(::cppu::any2bool(xPropSet->getPropertyValue( sOn )));
107 if ( bOn != bDisplay )
108 xPropSet->setPropertyValue( sOn, uno::makeAny(bDisplay) );
110 if (bLeft)
111 sCont = sContentLeft;
112 else
113 sCont = sContent;
114 xPropSet->getPropertyValue( sCont ) >>= xHeaderFooterContent;
117 XMLTableHeaderFooterContext::~XMLTableHeaderFooterContext()
121 SvXMLImportContext *XMLTableHeaderFooterContext::CreateChildContext(
122 sal_uInt16 nPrefix,
123 const OUString& rLocalName,
124 const uno::Reference< xml::sax::XAttributeList > & xAttrList )
126 SvXMLImportContext *pContext(0);
128 if ((nPrefix == XML_NAMESPACE_TEXT) &&
129 IsXMLToken(rLocalName, XML_P))
131 if (!xTextCursor.is())
133 if( xHeaderFooterContent.is() )
135 uno::Reference < text::XText > xText(xHeaderFooterContent->getCenterText());
136 xText->setString(sEmpty);
137 xTextCursor.set(xText->createTextCursor());
138 xOldTextCursor.set(GetImport().GetTextImport()->GetCursor());
139 GetImport().GetTextImport()->SetCursor( xTextCursor );
140 bContainsCenter = sal_True;
143 pContext =
144 GetImport().GetTextImport()->CreateTextChildContext(GetImport(),
145 nPrefix,
146 rLocalName,
147 xAttrList);
149 else
151 if (nPrefix == XML_NAMESPACE_STYLE)
153 if (xHeaderFooterContent.is())
155 uno::Reference < text::XText > xText;
156 if (IsXMLToken(rLocalName, XML_REGION_LEFT ))
158 xText.set(xHeaderFooterContent->getLeftText());
159 bContainsLeft = sal_True;
161 else if (IsXMLToken(rLocalName, XML_REGION_CENTER ))
163 xText.set(xHeaderFooterContent->getCenterText());
164 bContainsCenter = sal_True;
166 else if (IsXMLToken(rLocalName, XML_REGION_RIGHT ))
168 xText.set(xHeaderFooterContent->getRightText());
169 bContainsRight = sal_True;
171 if (xText.is())
173 xText->setString(sEmpty);
174 //SvXMLImport aSvXMLImport( GetImport() );
175 uno::Reference < text::XTextCursor > xTempTextCursor(xText->createTextCursor());
176 pContext = new XMLHeaderFooterRegionContext( GetImport(), nPrefix, rLocalName, xAttrList, xTempTextCursor);
181 if( !pContext )
182 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
184 return pContext;
187 void XMLTableHeaderFooterContext::EndElement()
189 if( GetImport().GetTextImport()->GetCursor().is() )
191 //GetImport().GetTextImport()->GetCursor()->gotoEnd(sal_False);
192 if( GetImport().GetTextImport()->GetCursor()->goLeft( 1, sal_True ) )
194 GetImport().GetTextImport()->GetText()->insertString(
195 GetImport().GetTextImport()->GetCursorAsRange(), sEmpty,
196 sal_True );
198 GetImport().GetTextImport()->ResetCursor();
200 if (xOldTextCursor.is())
201 GetImport().GetTextImport()->SetCursor(xOldTextCursor);
202 if (xHeaderFooterContent.is())
204 if (!bContainsLeft)
205 xHeaderFooterContent->getLeftText()->setString(sEmpty);
206 if (!bContainsCenter)
207 xHeaderFooterContent->getCenterText()->setString(sEmpty);
208 if (!bContainsRight)
209 xHeaderFooterContent->getRightText()->setString(sEmpty);
211 xPropSet->setPropertyValue( sCont, uno::makeAny(xHeaderFooterContent) );
215 TYPEINIT1( XMLHeaderFooterRegionContext, SvXMLImportContext );
217 XMLHeaderFooterRegionContext::XMLHeaderFooterRegionContext( SvXMLImport& rImport, sal_uInt16 nPrfx,
218 const OUString& rLName,
219 const uno::Reference<
220 xml::sax::XAttributeList > & /* xAttrList */,
221 uno::Reference< text::XTextCursor >& xCursor ) :
222 SvXMLImportContext( rImport, nPrfx, rLName ),
223 xTextCursor ( xCursor )
225 xOldTextCursor.set(GetImport().GetTextImport()->GetCursor());
226 GetImport().GetTextImport()->SetCursor( xTextCursor );
229 XMLHeaderFooterRegionContext::~XMLHeaderFooterRegionContext()
233 SvXMLImportContext *XMLHeaderFooterRegionContext::CreateChildContext(
234 sal_uInt16 nPrefix,
235 const OUString& rLocalName,
236 const uno::Reference< xml::sax::XAttributeList > & xAttrList )
238 SvXMLImportContext *pContext(0);
240 if ((nPrefix == XML_NAMESPACE_TEXT) &&
241 IsXMLToken(rLocalName, XML_P))
243 pContext =
244 GetImport().GetTextImport()->CreateTextChildContext(GetImport(),
245 nPrefix,
246 rLocalName,
247 xAttrList);
249 if( !pContext )
250 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
252 return pContext;
255 void XMLHeaderFooterRegionContext::EndElement()
257 if( GetImport().GetTextImport()->GetCursor().is() )
259 //GetImport().GetTextImport()->GetCursor()->gotoEnd(sal_False);
260 if( GetImport().GetTextImport()->GetCursor()->goLeft( 1, sal_True ) )
262 OUString sEmpty;
263 GetImport().GetTextImport()->GetText()->insertString(
264 GetImport().GetTextImport()->GetCursorAsRange(), sEmpty,
265 sal_True );
267 GetImport().GetTextImport()->ResetCursor();
269 if (xOldTextCursor.is())
270 GetImport().GetTextImport()->SetCursor(xOldTextCursor);