Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <com/sun/star/text/XText.hpp>
30 : : #include <xmloff/nmspmap.hxx>
31 : : #include <xmloff/xmlnmspe.hxx>
32 : : #include "XMLTableHeaderFooterContext.hxx"
33 : : #include <xmloff/xmltoken.hxx>
34 : : #include <comphelper/extract.hxx>
35 : :
36 : : #include "unonames.hxx"
37 : :
38 : : using ::rtl::OUString;
39 : : using namespace ::com::sun::star;
40 : : using namespace ::com::sun::star::uno;
41 : : using namespace ::com::sun::star::xml::sax;
42 : : using namespace ::com::sun::star::text;
43 : : using namespace ::com::sun::star::beans;
44 : : using namespace xmloff::token;
45 : :
46 : : using rtl::OUString;
47 : :
48 [ # # ][ # # ]: 0 : TYPEINIT1( XMLTableHeaderFooterContext, SvXMLImportContext );
49 : :
50 : 748 : XMLTableHeaderFooterContext::XMLTableHeaderFooterContext( SvXMLImport& rImport, sal_uInt16 nPrfx,
51 : : const OUString& rLName,
52 : : const uno::Reference<
53 : : xml::sax::XAttributeList > & xAttrList,
54 : : const Reference < XPropertySet > & rPageStylePropSet,
55 : : bool bFooter, bool bLft ) :
56 : : SvXMLImportContext( rImport, nPrfx, rLName ),
57 : : xPropSet( rPageStylePropSet ),
58 : : sOn( bFooter ? OUString(SC_UNO_PAGE_FTRON) : OUString(SC_UNO_PAGE_HDRON) ),
59 : : sShareContent( bFooter ? OUString(SC_UNO_PAGE_FTRSHARED) : OUString(SC_UNO_PAGE_HDRSHARED) ),
60 : : sContent( bFooter ? OUString(SC_UNO_PAGE_RIGHTFTRCON) : OUString(SC_UNO_PAGE_RIGHTHDRCON) ),
61 : : sContentLeft( bFooter ? OUString(SC_UNO_PAGE_LEFTFTRCONT) : OUString(SC_UNO_PAGE_LEFTHDRCONT) ),
62 : : bDisplay( true ),
63 : : bInsertContent( true ),
64 : : bLeft( bLft ),
65 : : bContainsLeft(false),
66 : : bContainsRight(false),
67 [ + + ][ + + ]: 748 : bContainsCenter(false)
[ + + ][ + + ]
[ + + ][ + + ]
[ + + ][ + + ]
[ + + ][ + + ]
[ + + ][ + + ]
68 : : {
69 [ + - ][ + - ]: 748 : sal_Int16 nAttrCount(xAttrList.is() ? xAttrList->getLength() : 0);
[ + - ]
70 [ + + ]: 1112 : for( sal_Int16 i=0; i < nAttrCount; ++i )
71 : : {
72 [ + - ][ + - ]: 364 : const OUString& rAttrName(xAttrList->getNameByIndex( i ));
73 : 364 : OUString aLName;
74 [ + - ]: 364 : sal_uInt16 nPrefix(GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName, &aLName ));
75 [ + - ][ + - ]: 364 : const OUString& rValue(xAttrList->getValueByIndex( i ));
76 : :
77 : : // TODO: use a map here
78 [ + - ]: 364 : if( XML_NAMESPACE_STYLE == nPrefix )
79 : : {
80 [ + - ][ + - ]: 364 : if( IsXMLToken(aLName, XML_DISPLAY ) )
81 [ + - ]: 364 : bDisplay = IsXMLToken(rValue, XML_TRUE);
82 : : }
83 : 364 : }
84 [ + + ]: 748 : if( bLeft )
85 : : {
86 [ + - ][ + - ]: 364 : bool bOn(::cppu::any2bool(xPropSet->getPropertyValue( sOn )));
[ + - ]
87 : :
88 [ - + ][ + - ]: 364 : if( bOn && bDisplay )
89 : : {
90 [ # # ][ # # ]: 0 : if( ::cppu::any2bool(xPropSet->getPropertyValue( sShareContent )) )
[ # # ][ # # ]
91 : : // Don't share headers any longer
92 [ # # ][ # # ]: 0 : xPropSet->setPropertyValue( sShareContent, uno::makeAny(false) );
[ # # ]
93 : : }
94 : : else
95 : : {
96 [ + - ][ + - ]: 364 : if( !::cppu::any2bool(xPropSet->getPropertyValue( sShareContent )) )
[ + - ][ - + ]
97 : : // share headers
98 [ # # ][ # # ]: 364 : xPropSet->setPropertyValue( sShareContent, uno::makeAny(sal_True) );
[ # # ]
99 : : }
100 : : }
101 : : else
102 : : {
103 [ + - ][ + - ]: 384 : bool bOn(::cppu::any2bool(xPropSet->getPropertyValue( sOn )));
[ + - ]
104 [ - + ]: 384 : if ( bOn != bDisplay )
105 [ # # ][ # # ]: 0 : xPropSet->setPropertyValue( sOn, uno::makeAny(bDisplay) );
[ # # ]
106 : : }
107 [ + + ]: 748 : if (bLeft)
108 : 364 : sCont = sContentLeft;
109 : : else
110 : 384 : sCont = sContent;
111 [ + - ][ + - ]: 748 : xPropSet->getPropertyValue( sCont ) >>= xHeaderFooterContent;
[ + - ]
112 : 748 : }
113 : :
114 : 748 : XMLTableHeaderFooterContext::~XMLTableHeaderFooterContext()
115 : : {
116 [ - + ]: 1496 : }
117 : :
118 : 489 : SvXMLImportContext *XMLTableHeaderFooterContext::CreateChildContext(
119 : : sal_uInt16 nPrefix,
120 : : const OUString& rLocalName,
121 : : const uno::Reference< xml::sax::XAttributeList > & xAttrList )
122 : : {
123 : 489 : SvXMLImportContext *pContext(0);
124 : :
125 [ + + + - ]: 792 : if ((nPrefix == XML_NAMESPACE_TEXT) &&
[ + + ]
126 : 303 : IsXMLToken(rLocalName, XML_P))
127 : : {
128 [ + - ]: 303 : if (!xTextCursor.is())
129 : : {
130 [ + - ]: 303 : if( xHeaderFooterContent.is() )
131 : : {
132 [ + - ][ + - ]: 303 : uno::Reference < text::XText > xText(xHeaderFooterContent->getCenterText());
133 [ + - ][ + - ]: 303 : xText->setString(sEmpty);
134 [ + - ][ + - ]: 303 : xTextCursor.set(xText->createTextCursor());
[ + - ]
135 [ + - ][ + - ]: 303 : xOldTextCursor.set(GetImport().GetTextImport()->GetCursor());
[ + - ][ + - ]
[ + - ]
136 [ + - ][ + - ]: 303 : GetImport().GetTextImport()->SetCursor( xTextCursor );
[ + - ][ + - ]
137 : 303 : bContainsCenter = true;
138 : : }
139 : : }
140 : : pContext =
141 : 303 : GetImport().GetTextImport()->CreateTextChildContext(GetImport(),
142 : : nPrefix,
143 : : rLocalName,
144 [ + - ][ + - ]: 303 : xAttrList);
145 : : }
146 : : else
147 : : {
148 [ + - ]: 186 : if (nPrefix == XML_NAMESPACE_STYLE)
149 : : {
150 [ + - ]: 186 : if (xHeaderFooterContent.is())
151 : : {
152 : 186 : uno::Reference < text::XText > xText;
153 [ + + ][ + - ]: 186 : if (IsXMLToken(rLocalName, XML_REGION_LEFT ))
154 : : {
155 [ + - ][ + - ]: 93 : xText.set(xHeaderFooterContent->getLeftText());
[ + - ]
156 : 93 : bContainsLeft = true;
157 : : }
158 [ + - ][ - + ]: 93 : else if (IsXMLToken(rLocalName, XML_REGION_CENTER ))
159 : : {
160 [ # # ][ # # ]: 0 : xText.set(xHeaderFooterContent->getCenterText());
[ # # ]
161 : 0 : bContainsCenter = true;
162 : : }
163 [ + - ][ + - ]: 93 : else if (IsXMLToken(rLocalName, XML_REGION_RIGHT ))
164 : : {
165 [ + - ][ + - ]: 93 : xText.set(xHeaderFooterContent->getRightText());
[ + - ]
166 : 93 : bContainsRight = true;
167 : : }
168 [ + - ]: 186 : if (xText.is())
169 : : {
170 [ + - ][ + - ]: 186 : xText->setString(sEmpty);
171 : : //SvXMLImport aSvXMLImport( GetImport() );
172 [ + - ][ + - ]: 186 : uno::Reference < text::XTextCursor > xTempTextCursor(xText->createTextCursor());
173 [ + - ][ + - ]: 186 : pContext = new XMLHeaderFooterRegionContext( GetImport(), nPrefix, rLocalName, xAttrList, xTempTextCursor);
174 : 186 : }
175 : : }
176 : : }
177 : : }
178 [ - + ]: 489 : if( !pContext )
179 [ # # ]: 0 : pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
180 : :
181 : 489 : return pContext;
182 : : }
183 : :
184 : 748 : void XMLTableHeaderFooterContext::EndElement()
185 : : {
186 [ + - ][ + - ]: 748 : if( GetImport().GetTextImport()->GetCursor().is() )
[ + + ]
187 : : {
188 : : //GetImport().GetTextImport()->GetCursor()->gotoEnd(sal_False);
189 [ + - ][ + - ]: 303 : if( GetImport().GetTextImport()->GetCursor()->goLeft( 1, true ) )
[ + - ][ + - ]
[ + - ]
190 : : {
191 [ + - ][ + - ]: 606 : GetImport().GetTextImport()->GetText()->insertString(
[ + - ]
192 [ + - ][ + - ]: 606 : GetImport().GetTextImport()->GetCursorAsRange(), sEmpty,
[ + - ][ + - ]
193 [ + - ]: 303 : true );
194 : : }
195 [ + - ][ + - ]: 303 : GetImport().GetTextImport()->ResetCursor();
196 : : }
197 [ - + ]: 748 : if (xOldTextCursor.is())
198 [ # # ][ # # ]: 0 : GetImport().GetTextImport()->SetCursor(xOldTextCursor);
199 [ + - ]: 748 : if (xHeaderFooterContent.is())
200 : : {
201 [ + + ]: 748 : if (!bContainsLeft)
202 [ + - ][ + - ]: 655 : xHeaderFooterContent->getLeftText()->setString(sEmpty);
203 [ + + ]: 748 : if (!bContainsCenter)
204 [ + - ][ + - ]: 445 : xHeaderFooterContent->getCenterText()->setString(sEmpty);
205 [ + + ]: 748 : if (!bContainsRight)
206 [ + - ][ + - ]: 655 : xHeaderFooterContent->getRightText()->setString(sEmpty);
207 : :
208 [ + - ]: 748 : xPropSet->setPropertyValue( sCont, uno::makeAny(xHeaderFooterContent) );
209 : : }
210 : 748 : }
211 : :
212 [ # # ][ # # ]: 0 : TYPEINIT1( XMLHeaderFooterRegionContext, SvXMLImportContext );
213 : :
214 : 186 : XMLHeaderFooterRegionContext::XMLHeaderFooterRegionContext( SvXMLImport& rImport, sal_uInt16 nPrfx,
215 : : const OUString& rLName,
216 : : const uno::Reference<
217 : : xml::sax::XAttributeList > & /* xAttrList */,
218 : : uno::Reference< text::XTextCursor >& xCursor ) :
219 : : SvXMLImportContext( rImport, nPrfx, rLName ),
220 : 186 : xTextCursor ( xCursor )
221 : : {
222 [ + - ][ + - ]: 186 : xOldTextCursor.set(GetImport().GetTextImport()->GetCursor());
[ + - ][ + - ]
[ + - ]
223 [ + - ][ + - ]: 186 : GetImport().GetTextImport()->SetCursor( xTextCursor );
[ + - ][ + - ]
224 : 186 : }
225 : :
226 : 186 : XMLHeaderFooterRegionContext::~XMLHeaderFooterRegionContext()
227 : : {
228 [ - + ]: 372 : }
229 : :
230 : 186 : SvXMLImportContext *XMLHeaderFooterRegionContext::CreateChildContext(
231 : : sal_uInt16 nPrefix,
232 : : const OUString& rLocalName,
233 : : const uno::Reference< xml::sax::XAttributeList > & xAttrList )
234 : : {
235 : 186 : SvXMLImportContext *pContext(0);
236 : :
237 [ + - + - ]: 372 : if ((nPrefix == XML_NAMESPACE_TEXT) &&
[ + - ]
238 : 186 : IsXMLToken(rLocalName, XML_P))
239 : : {
240 : : pContext =
241 : 186 : GetImport().GetTextImport()->CreateTextChildContext(GetImport(),
242 : : nPrefix,
243 : : rLocalName,
244 [ + - ][ + - ]: 186 : xAttrList);
245 : : }
246 [ - + ]: 186 : if( !pContext )
247 [ # # ]: 0 : pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
248 : :
249 : 186 : return pContext;
250 : : }
251 : :
252 : 186 : void XMLHeaderFooterRegionContext::EndElement()
253 : : {
254 [ + - ][ + - ]: 186 : if( GetImport().GetTextImport()->GetCursor().is() )
[ + - ]
255 : : {
256 : : //GetImport().GetTextImport()->GetCursor()->gotoEnd(sal_False);
257 [ + - ][ + - ]: 186 : if( GetImport().GetTextImport()->GetCursor()->goLeft( 1, true ) )
[ + - ][ + - ]
[ + - ]
258 : : {
259 : 186 : OUString sEmpty;
260 [ + - ][ + - ]: 372 : GetImport().GetTextImport()->GetText()->insertString(
[ + - ][ + - ]
[ + - ]
261 [ + - ][ + - ]: 372 : GetImport().GetTextImport()->GetCursorAsRange(), sEmpty,
[ + - ][ + - ]
262 [ + - ]: 372 : true );
263 : : }
264 [ + - ][ + - ]: 186 : GetImport().GetTextImport()->ResetCursor();
265 : : }
266 [ - + ]: 186 : if (xOldTextCursor.is())
267 [ # # ][ # # ]: 0 : GetImport().GetTextImport()->SetCursor(xOldTextCursor);
268 : 186 : }
269 : :
270 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|