Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
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>
26 :
27 : #include "unonames.hxx"
28 :
29 : using ::rtl::OUString;
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;
35 : using namespace xmloff::token;
36 :
37 : using rtl::OUString;
38 :
39 0 : TYPEINIT1( XMLTableHeaderFooterContext, SvXMLImportContext );
40 :
41 552 : XMLTableHeaderFooterContext::XMLTableHeaderFooterContext( SvXMLImport& rImport, sal_uInt16 nPrfx,
42 : const OUString& rLName,
43 : const uno::Reference<
44 : xml::sax::XAttributeList > & xAttrList,
45 : const Reference < XPropertySet > & rPageStylePropSet,
46 : bool bFooter, bool bLft ) :
47 : SvXMLImportContext( rImport, nPrfx, rLName ),
48 : xPropSet( rPageStylePropSet ),
49 : sOn( bFooter ? OUString(SC_UNO_PAGE_FTRON) : OUString(SC_UNO_PAGE_HDRON) ),
50 : sShareContent( bFooter ? OUString(SC_UNO_PAGE_FTRSHARED) : OUString(SC_UNO_PAGE_HDRSHARED) ),
51 : sContent( bFooter ? OUString(SC_UNO_PAGE_RIGHTFTRCON) : OUString(SC_UNO_PAGE_RIGHTHDRCON) ),
52 : sContentLeft( bFooter ? OUString(SC_UNO_PAGE_LEFTFTRCONT) : OUString(SC_UNO_PAGE_LEFTHDRCONT) ),
53 : bDisplay( true ),
54 : bLeft( bLft ),
55 : bContainsLeft(false),
56 : bContainsRight(false),
57 552 : bContainsCenter(false)
58 : {
59 552 : sal_Int16 nAttrCount(xAttrList.is() ? xAttrList->getLength() : 0);
60 828 : for( sal_Int16 i=0; i < nAttrCount; ++i )
61 : {
62 276 : const OUString& rAttrName(xAttrList->getNameByIndex( i ));
63 276 : OUString aLName;
64 276 : sal_uInt16 nPrefix(GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName, &aLName ));
65 276 : const OUString& rValue(xAttrList->getValueByIndex( i ));
66 :
67 : // TODO: use a map here
68 276 : if( XML_NAMESPACE_STYLE == nPrefix )
69 : {
70 276 : if( IsXMLToken(aLName, XML_DISPLAY ) )
71 276 : bDisplay = IsXMLToken(rValue, XML_TRUE);
72 : }
73 276 : }
74 552 : if( bLeft )
75 : {
76 276 : bool bOn(::cppu::any2bool(xPropSet->getPropertyValue( sOn )));
77 :
78 276 : if( bOn && bDisplay )
79 : {
80 0 : if( ::cppu::any2bool(xPropSet->getPropertyValue( sShareContent )) )
81 : // Don't share headers any longer
82 0 : xPropSet->setPropertyValue( sShareContent, uno::makeAny(false) );
83 : }
84 : else
85 : {
86 276 : if( !::cppu::any2bool(xPropSet->getPropertyValue( sShareContent )) )
87 : // share headers
88 0 : xPropSet->setPropertyValue( sShareContent, uno::makeAny(sal_True) );
89 : }
90 : }
91 : else
92 : {
93 276 : bool bOn(::cppu::any2bool(xPropSet->getPropertyValue( sOn )));
94 276 : if ( bOn != bDisplay )
95 0 : xPropSet->setPropertyValue( sOn, uno::makeAny(bDisplay) );
96 : }
97 552 : if (bLeft)
98 276 : sCont = sContentLeft;
99 : else
100 276 : sCont = sContent;
101 552 : xPropSet->getPropertyValue( sCont ) >>= xHeaderFooterContent;
102 552 : }
103 :
104 1104 : XMLTableHeaderFooterContext::~XMLTableHeaderFooterContext()
105 : {
106 1104 : }
107 :
108 354 : SvXMLImportContext *XMLTableHeaderFooterContext::CreateChildContext(
109 : sal_uInt16 nPrefix,
110 : const OUString& rLocalName,
111 : const uno::Reference< xml::sax::XAttributeList > & xAttrList )
112 : {
113 354 : SvXMLImportContext *pContext(0);
114 :
115 576 : if ((nPrefix == XML_NAMESPACE_TEXT) &&
116 222 : IsXMLToken(rLocalName, XML_P))
117 : {
118 222 : if (!xTextCursor.is())
119 : {
120 222 : if( xHeaderFooterContent.is() )
121 : {
122 222 : uno::Reference < text::XText > xText(xHeaderFooterContent->getCenterText());
123 222 : xText->setString(sEmpty);
124 222 : xTextCursor.set(xText->createTextCursor());
125 222 : xOldTextCursor.set(GetImport().GetTextImport()->GetCursor());
126 222 : GetImport().GetTextImport()->SetCursor( xTextCursor );
127 222 : bContainsCenter = true;
128 : }
129 : }
130 : pContext =
131 222 : GetImport().GetTextImport()->CreateTextChildContext(GetImport(),
132 : nPrefix,
133 : rLocalName,
134 444 : xAttrList);
135 : }
136 : else
137 : {
138 132 : if (nPrefix == XML_NAMESPACE_STYLE)
139 : {
140 132 : if (xHeaderFooterContent.is())
141 : {
142 132 : uno::Reference < text::XText > xText;
143 132 : if (IsXMLToken(rLocalName, XML_REGION_LEFT ))
144 : {
145 66 : xText.set(xHeaderFooterContent->getLeftText());
146 66 : bContainsLeft = true;
147 : }
148 66 : else if (IsXMLToken(rLocalName, XML_REGION_CENTER ))
149 : {
150 0 : xText.set(xHeaderFooterContent->getCenterText());
151 0 : bContainsCenter = true;
152 : }
153 66 : else if (IsXMLToken(rLocalName, XML_REGION_RIGHT ))
154 : {
155 66 : xText.set(xHeaderFooterContent->getRightText());
156 66 : bContainsRight = true;
157 : }
158 132 : if (xText.is())
159 : {
160 132 : xText->setString(sEmpty);
161 : //SvXMLImport aSvXMLImport( GetImport() );
162 132 : uno::Reference < text::XTextCursor > xTempTextCursor(xText->createTextCursor());
163 132 : pContext = new XMLHeaderFooterRegionContext( GetImport(), nPrefix, rLocalName, xAttrList, xTempTextCursor);
164 132 : }
165 : }
166 : }
167 : }
168 354 : if( !pContext )
169 0 : pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
170 :
171 354 : return pContext;
172 : }
173 :
174 552 : void XMLTableHeaderFooterContext::EndElement()
175 : {
176 552 : if( GetImport().GetTextImport()->GetCursor().is() )
177 : {
178 : //GetImport().GetTextImport()->GetCursor()->gotoEnd(sal_False);
179 222 : if( GetImport().GetTextImport()->GetCursor()->goLeft( 1, true ) )
180 : {
181 444 : GetImport().GetTextImport()->GetText()->insertString(
182 444 : GetImport().GetTextImport()->GetCursorAsRange(), sEmpty,
183 444 : true );
184 : }
185 222 : GetImport().GetTextImport()->ResetCursor();
186 : }
187 552 : if (xOldTextCursor.is())
188 0 : GetImport().GetTextImport()->SetCursor(xOldTextCursor);
189 552 : if (xHeaderFooterContent.is())
190 : {
191 552 : if (!bContainsLeft)
192 486 : xHeaderFooterContent->getLeftText()->setString(sEmpty);
193 552 : if (!bContainsCenter)
194 330 : xHeaderFooterContent->getCenterText()->setString(sEmpty);
195 552 : if (!bContainsRight)
196 486 : xHeaderFooterContent->getRightText()->setString(sEmpty);
197 :
198 552 : xPropSet->setPropertyValue( sCont, uno::makeAny(xHeaderFooterContent) );
199 : }
200 552 : }
201 :
202 0 : TYPEINIT1( XMLHeaderFooterRegionContext, SvXMLImportContext );
203 :
204 132 : XMLHeaderFooterRegionContext::XMLHeaderFooterRegionContext( SvXMLImport& rImport, sal_uInt16 nPrfx,
205 : const OUString& rLName,
206 : const uno::Reference<
207 : xml::sax::XAttributeList > & /* xAttrList */,
208 : uno::Reference< text::XTextCursor >& xCursor ) :
209 : SvXMLImportContext( rImport, nPrfx, rLName ),
210 132 : xTextCursor ( xCursor )
211 : {
212 132 : xOldTextCursor.set(GetImport().GetTextImport()->GetCursor());
213 132 : GetImport().GetTextImport()->SetCursor( xTextCursor );
214 132 : }
215 :
216 264 : XMLHeaderFooterRegionContext::~XMLHeaderFooterRegionContext()
217 : {
218 264 : }
219 :
220 132 : SvXMLImportContext *XMLHeaderFooterRegionContext::CreateChildContext(
221 : sal_uInt16 nPrefix,
222 : const OUString& rLocalName,
223 : const uno::Reference< xml::sax::XAttributeList > & xAttrList )
224 : {
225 132 : SvXMLImportContext *pContext(0);
226 :
227 264 : if ((nPrefix == XML_NAMESPACE_TEXT) &&
228 132 : IsXMLToken(rLocalName, XML_P))
229 : {
230 : pContext =
231 132 : GetImport().GetTextImport()->CreateTextChildContext(GetImport(),
232 : nPrefix,
233 : rLocalName,
234 264 : xAttrList);
235 : }
236 132 : if( !pContext )
237 0 : pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
238 :
239 132 : return pContext;
240 : }
241 :
242 132 : void XMLHeaderFooterRegionContext::EndElement()
243 : {
244 132 : if( GetImport().GetTextImport()->GetCursor().is() )
245 : {
246 : //GetImport().GetTextImport()->GetCursor()->gotoEnd(sal_False);
247 132 : if( GetImport().GetTextImport()->GetCursor()->goLeft( 1, true ) )
248 : {
249 132 : OUString sEmpty;
250 264 : GetImport().GetTextImport()->GetText()->insertString(
251 264 : GetImport().GetTextImport()->GetCursorAsRange(), sEmpty,
252 396 : true );
253 : }
254 132 : GetImport().GetTextImport()->ResetCursor();
255 : }
256 132 : if (xOldTextCursor.is())
257 0 : GetImport().GetTextImport()->SetCursor(xOldTextCursor);
258 132 : }
259 :
260 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|