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 <rtl/ustrbuf.hxx>
30 : :
31 : : #include <xmloff/nmspmap.hxx>
32 : : #include <format.hxx>
33 : : #include <fmtcol.hxx>
34 : : #include <hints.hxx>
35 : : #include <poolfmt.hxx>
36 : : #include <charfmt.hxx>
37 : : #include <paratr.hxx>
38 : : #include <doc.hxx>
39 : : #include "docary.hxx"
40 : : #include "unostyle.hxx"
41 : : #include "fmtpdsc.hxx"
42 : : #include "pagedesc.hxx"
43 : : #include <xmloff/xmlnmspe.hxx>
44 : : #include <xmloff/i18nmap.hxx>
45 : : #include <xmloff/xmltkmap.hxx>
46 : : #include "xmlitem.hxx"
47 : : #include <xmloff/xmlstyle.hxx>
48 : : #include <xmloff/txtstyli.hxx>
49 : : #include <xmloff/txtimp.hxx>
50 : : #include <xmloff/families.hxx>
51 : : #include <xmloff/XMLTextMasterStylesContext.hxx>
52 : : #include <xmloff/XMLTextShapeStyleContext.hxx>
53 : : #include <xmloff/XMLGraphicsDefaultStyle.hxx>
54 : : #include "xmlimp.hxx"
55 : : #include "xmltbli.hxx"
56 : : #include "cellatr.hxx"
57 : : #include <SwStyleNameMapper.hxx>
58 : : #include <xmloff/attrlist.hxx>
59 : : #include <unotxdoc.hxx>
60 : : #include <docsh.hxx>
61 : :
62 : :
63 : : using namespace ::com::sun::star;
64 : : using ::rtl::OUString;
65 : : using ::rtl::OUStringBuffer;
66 : : using namespace ::xmloff::token;
67 : :
68 : 0 : class SwXMLConditionParser_Impl
69 : : {
70 : : OUString sInput;
71 : :
72 : : sal_uInt32 nCondition;
73 : : sal_uInt32 nSubCondition;
74 : :
75 : : sal_Int32 nPos;
76 : : sal_Int32 nLength;
77 : :
78 : : inline sal_Bool SkipWS();
79 : : inline sal_Bool MatchChar( sal_Unicode c );
80 : : inline sal_Bool MatchName( OUString& rName );
81 : : inline sal_Bool MatchNumber( sal_uInt32& rNumber );
82 : :
83 : : public:
84 : :
85 : : SwXMLConditionParser_Impl( const OUString& rInp );
86 : :
87 : 0 : sal_Bool IsValid() const { return 0 != nCondition; }
88 : :
89 : 0 : sal_uInt32 GetCondition() const { return nCondition; }
90 : 0 : sal_uInt32 GetSubCondition() const { return nSubCondition; }
91 : : };
92 : :
93 : 0 : inline sal_Bool SwXMLConditionParser_Impl::SkipWS()
94 : : {
95 [ # # ][ # # ]: 0 : while( nPos < nLength && ' ' == sInput[nPos] )
[ # # ]
96 : 0 : nPos++;
97 : 0 : return sal_True;
98 : : }
99 : :
100 : 0 : inline sal_Bool SwXMLConditionParser_Impl::MatchChar( sal_Unicode c )
101 : : {
102 : 0 : sal_Bool bRet = sal_False;
103 [ # # ][ # # ]: 0 : if( nPos < nLength && c == sInput[nPos] )
[ # # ]
104 : : {
105 : 0 : nPos++;
106 : 0 : bRet = sal_True;
107 : : }
108 : 0 : return bRet;
109 : : }
110 : :
111 : 0 : inline sal_Bool SwXMLConditionParser_Impl::MatchName( OUString& rName )
112 : : {
113 : 0 : OUStringBuffer sBuffer( nLength );
114 [ # # # # : 0 : while( nPos < nLength &&
# # # # ]
[ # # ]
115 : 0 : ( ('a' <= sInput[nPos] && sInput[nPos] <= 'z') ||
116 : 0 : '-' == sInput[nPos] ) )
117 : : {
118 [ # # ]: 0 : sBuffer.append( sInput[nPos] );
119 : 0 : nPos++;
120 : : }
121 [ # # ]: 0 : rName = sBuffer.makeStringAndClear();
122 : 0 : return !rName.isEmpty();
123 : : }
124 : :
125 : 0 : inline sal_Bool SwXMLConditionParser_Impl::MatchNumber( sal_uInt32& rNumber )
126 : : {
127 : 0 : OUStringBuffer sBuffer( nLength );
128 [ # # ][ # # ]: 0 : while( nPos < nLength && '0' <= sInput[nPos] && sInput[nPos] <= '9' )
[ # # ][ # # ]
129 : : {
130 [ # # ]: 0 : sBuffer.append( sInput[nPos] );
131 : 0 : nPos++;
132 : : }
133 : :
134 [ # # ]: 0 : OUString sNum( sBuffer.makeStringAndClear() );
135 [ # # ]: 0 : if( !sNum.isEmpty() )
136 : 0 : rNumber = sNum.toInt32();
137 : 0 : return !sNum.isEmpty();
138 : : }
139 : :
140 : 0 : SwXMLConditionParser_Impl::SwXMLConditionParser_Impl( const OUString& rInp ) :
141 : : sInput( rInp ),
142 : : nCondition( 0 ),
143 : : nSubCondition( 0 ),
144 : : nPos( 0 ),
145 : 0 : nLength( rInp.getLength() )
146 : : {
147 : 0 : OUString sFunc;
148 : 0 : sal_Bool bHasSub = sal_False;
149 : 0 : sal_uInt32 nSub = 0;
150 [ # # ]: 0 : sal_Bool bOK = SkipWS() && MatchName( sFunc ) && SkipWS() &&
151 [ # # # # ]: 0 : MatchChar( '(' ) && SkipWS() && MatchChar( ')' ) && SkipWS();
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
152 [ # # ][ # # ]: 0 : if( bOK && MatchChar( '=' ) )
[ # # ]
153 : : {
154 [ # # ][ # # ]: 0 : bOK = SkipWS() && MatchNumber( nSub ) && SkipWS();
[ # # ][ # # ]
155 : 0 : bHasSub = sal_True;
156 : : }
157 : :
158 : 0 : bOK &= nPos == nLength;
159 : :
160 [ # # ]: 0 : if( bOK )
161 : : {
162 [ # # ][ # # ]: 0 : if( IsXMLToken( sFunc, XML_ENDNOTE ) && !bHasSub )
[ # # ][ # # ]
163 : 0 : nCondition = PARA_IN_ENDNOTE;
164 [ # # ][ # # ]: 0 : else if( IsXMLToken( sFunc, XML_FOOTER ) && !bHasSub )
[ # # ][ # # ]
165 : 0 : nCondition = PARA_IN_FOOTER;
166 [ # # ][ # # ]: 0 : else if( IsXMLToken( sFunc, XML_FOOTNOTE ) && !bHasSub )
[ # # ][ # # ]
167 : 0 : nCondition = PARA_IN_FOOTENOTE;
168 [ # # ][ # # ]: 0 : else if( IsXMLToken( sFunc, XML_HEADER ) && !bHasSub )
[ # # ][ # # ]
169 : 0 : nCondition = PARA_IN_HEADER;
170 [ # # ][ # # ]: 0 : else if( IsXMLToken( sFunc, XML_LIST_LEVEL) &&
[ # # ][ # # ]
[ # # ]
171 : : nSub >=1 && nSub <= MAXLEVEL )
172 : : {
173 : 0 : nCondition = PARA_IN_LIST;
174 : 0 : nSubCondition = nSub-1;
175 : : }
176 [ # # ][ # # ]: 0 : else if( IsXMLToken( sFunc, XML_OUTLINE_LEVEL) &&
[ # # ][ # # ]
[ # # ]
177 : : nSub >=1 && nSub <= MAXLEVEL )
178 : : {
179 : 0 : nCondition = PARA_IN_OUTLINE;
180 : 0 : nSubCondition = nSub-1;
181 : : }
182 [ # # ][ # # ]: 0 : else if( IsXMLToken( sFunc, XML_SECTION ) && !bHasSub )
[ # # ][ # # ]
183 : : {
184 : 0 : nCondition = PARA_IN_SECTION;
185 : : }
186 [ # # ][ # # ]: 0 : else if( IsXMLToken( sFunc, XML_TABLE ) && !bHasSub )
[ # # ][ # # ]
187 : : {
188 : 0 : nCondition = PARA_IN_TABLEBODY;
189 : : }
190 [ # # ][ # # ]: 0 : else if( IsXMLToken( sFunc, XML_TABLE_HEADER ) && !bHasSub )
[ # # ][ # # ]
191 : : {
192 : 0 : nCondition = PARA_IN_TABLEHEAD;
193 : : }
194 [ # # ][ # # ]: 0 : else if( IsXMLToken( sFunc, XML_TEXT_BOX ) && !bHasSub )
[ # # ][ # # ]
195 : : {
196 : 0 : nCondition = PARA_IN_FRAME;
197 : : }
198 : 0 : }
199 : 0 : }
200 : :
201 : : // ---------------------------------------------------------------------
202 : :
203 : : class SwXMLConditionContext_Impl : public SvXMLImportContext
204 : : {
205 : : sal_uInt32 nCondition;
206 : : sal_uInt32 nSubCondition;
207 : :
208 : : OUString sApplyStyle;
209 : :
210 : : void ParseCondition( const OUString& rCond );
211 : :
212 : : public:
213 : :
214 : : SwXMLConditionContext_Impl(
215 : : SvXMLImport& rImport, sal_uInt16 nPrfx,
216 : : const OUString& rLName,
217 : : const uno::Reference< xml::sax::XAttributeList > & xAttrList );
218 : : virtual ~SwXMLConditionContext_Impl();
219 : :
220 : : TYPEINFO();
221 : :
222 : 0 : sal_Bool IsValid() const { return 0 != nCondition; }
223 : :
224 : 0 : sal_uInt32 GetCondition() const { return nCondition; }
225 : 0 : sal_uInt32 GetSubCondition() const { return nSubCondition; }
226 : 0 : const OUString& GetApplyStyle() const { return sApplyStyle; }
227 : : };
228 : :
229 : 0 : SwXMLConditionContext_Impl::SwXMLConditionContext_Impl(
230 : : SvXMLImport& rImport, sal_uInt16 nPrfx,
231 : : const OUString& rLName,
232 : : const uno::Reference< xml::sax::XAttributeList > & xAttrList ) :
233 : : SvXMLImportContext( rImport, nPrfx, rLName ),
234 : : nCondition( 0 ),
235 : 0 : nSubCondition( 0 )
236 : : {
237 [ # # ][ # # ]: 0 : sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
[ # # ]
238 [ # # ]: 0 : for( sal_Int16 i=0; i < nAttrCount; i++ )
239 : : {
240 [ # # ][ # # ]: 0 : const OUString& rAttrName = xAttrList->getNameByIndex( i );
241 : 0 : OUString aLocalName;
242 : : sal_uInt16 nPrefix =
243 : 0 : GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName,
244 [ # # ]: 0 : &aLocalName );
245 [ # # ][ # # ]: 0 : const OUString& rValue = xAttrList->getValueByIndex( i );
246 : :
247 : : // TODO: use a map here
248 [ # # ]: 0 : if( XML_NAMESPACE_STYLE == nPrefix )
249 : : {
250 [ # # ][ # # ]: 0 : if( IsXMLToken( aLocalName, XML_CONDITION ) )
251 : : {
252 [ # # ]: 0 : SwXMLConditionParser_Impl aCondParser( rValue );
253 [ # # ]: 0 : if( aCondParser.IsValid() )
254 : : {
255 : 0 : nCondition = aCondParser.GetCondition();
256 : 0 : nSubCondition = aCondParser.GetSubCondition();
257 : 0 : }
258 : : }
259 [ # # ][ # # ]: 0 : else if( IsXMLToken( aLocalName, XML_APPLY_STYLE_NAME ) )
260 : : {
261 : 0 : sApplyStyle = rValue;
262 : : }
263 : : }
264 : 0 : }
265 : 0 : }
266 : :
267 : 0 : SwXMLConditionContext_Impl::~SwXMLConditionContext_Impl()
268 : : {
269 [ # # ]: 0 : }
270 : :
271 [ # # ][ # # ]: 0 : TYPEINIT1( SwXMLConditionContext_Impl, XMLTextStyleContext );
272 : :
273 : : // ---------------------------------------------------------------------
274 : :
275 : : typedef std::vector<SwXMLConditionContext_Impl*> SwXMLConditions_Impl;
276 : :
277 : : class SwXMLTextStyleContext_Impl : public XMLTextStyleContext
278 : : {
279 : : SwXMLConditions_Impl *pConditions;
280 : :
281 : : protected:
282 : :
283 : : virtual uno::Reference < style::XStyle > Create();
284 : :
285 : : public:
286 : :
287 : : TYPEINFO();
288 : :
289 : : SwXMLTextStyleContext_Impl( SwXMLImport& rImport, sal_uInt16 nPrfx,
290 : : const OUString& rLName,
291 : : const uno::Reference< xml::sax::XAttributeList > & xAttrList,
292 : : sal_uInt16 nFamily,
293 : : SvXMLStylesContext& rStyles );
294 : : virtual ~SwXMLTextStyleContext_Impl();
295 : :
296 : : virtual SvXMLImportContext *CreateChildContext(
297 : : sal_uInt16 nPrefix,
298 : : const OUString& rLocalName,
299 : : const uno::Reference< xml::sax::XAttributeList > & xAttrList );
300 : :
301 : : virtual void Finish( sal_Bool bOverwrite );
302 : : };
303 : :
304 [ - + ][ + - ]: 879 : TYPEINIT1( SwXMLTextStyleContext_Impl, XMLTextStyleContext );
305 : :
306 : 92 : uno::Reference < style::XStyle > SwXMLTextStyleContext_Impl::Create()
307 : : {
308 : 92 : uno::Reference < style::XStyle > xNewStyle;
309 : :
310 [ # # ][ - + ]: 92 : if( pConditions && XML_STYLE_FAMILY_TEXT_PARAGRAPH == GetFamily() )
[ - + ]
311 : : {
312 : 0 : uno::Reference< lang::XMultiServiceFactory > xFactory( GetImport().GetModel(),
313 [ # # ]: 0 : uno::UNO_QUERY );
314 [ # # ]: 0 : if( xFactory.is() )
315 : : {
316 : : OUString sServiceName( RTL_CONSTASCII_USTRINGPARAM(
317 [ # # ]: 0 : "com.sun.star.style.ConditionalParagraphStyle" ) );
318 : : uno::Reference < uno::XInterface > xIfc =
319 [ # # ][ # # ]: 0 : xFactory->createInstance( sServiceName );
320 [ # # ]: 0 : if( xIfc.is() )
321 [ # # ][ # # ]: 0 : xNewStyle = uno::Reference < style::XStyle >( xIfc, uno::UNO_QUERY );
322 : 0 : }
323 : : }
324 : : else
325 : : {
326 [ + - ][ + - ]: 92 : xNewStyle = XMLTextStyleContext::Create();
327 : : }
328 : :
329 : 92 : return xNewStyle;
330 : : }
331 : :
332 : 726 : SwXMLTextStyleContext_Impl::SwXMLTextStyleContext_Impl( SwXMLImport& rImport,
333 : : sal_uInt16 nPrfx, const OUString& rLName,
334 : : const uno::Reference< xml::sax::XAttributeList > & xAttrList,
335 : : sal_uInt16 nFamily,
336 : : SvXMLStylesContext& rStyles ) :
337 : : XMLTextStyleContext( rImport, nPrfx, rLName, xAttrList, rStyles, nFamily ),
338 : 726 : pConditions( 0 )
339 : : {
340 : 726 : }
341 : :
342 : 726 : SwXMLTextStyleContext_Impl::~SwXMLTextStyleContext_Impl()
343 : : {
344 [ - + ]: 726 : if( pConditions )
345 : : {
346 [ # # ]: 0 : while( !pConditions->empty() )
347 : : {
348 [ # # ]: 0 : SwXMLConditionContext_Impl *pCond = &*pConditions->back();
349 [ # # ]: 0 : pConditions->pop_back();
350 [ # # ]: 0 : pCond->ReleaseRef();
351 : : }
352 [ # # ]: 0 : delete pConditions;
353 : : }
354 [ - + ]: 1452 : }
355 : :
356 : 960 : SvXMLImportContext *SwXMLTextStyleContext_Impl::CreateChildContext(
357 : : sal_uInt16 nPrefix,
358 : : const OUString& rLocalName,
359 : : const uno::Reference< xml::sax::XAttributeList > & xAttrList )
360 : : {
361 : 960 : SvXMLImportContext *pContext = 0;
362 : :
363 [ + - ][ - + ]: 960 : if( XML_NAMESPACE_STYLE == nPrefix && IsXMLToken( rLocalName, XML_MAP ) )
[ - + ]
364 : : {
365 : : SwXMLConditionContext_Impl *pCond =
366 : 0 : new SwXMLConditionContext_Impl( GetImport(), nPrefix,
367 [ # # ][ # # ]: 0 : rLocalName, xAttrList );
368 [ # # ]: 0 : if( pCond->IsValid() )
369 : : {
370 [ # # ]: 0 : if( !pConditions )
371 [ # # ][ # # ]: 0 : pConditions = new SwXMLConditions_Impl;
372 [ # # ]: 0 : pConditions->push_back( pCond );
373 : 0 : pCond->AddRef();
374 : : }
375 : 0 : pContext = pCond;
376 : : }
377 : :
378 [ + - ]: 960 : if( !pContext )
379 : : pContext = XMLTextStyleContext::CreateChildContext( nPrefix, rLocalName,
380 : 960 : xAttrList );
381 : :
382 : 960 : return pContext;
383 : : }
384 : :
385 : 611 : void SwXMLTextStyleContext_Impl::Finish( sal_Bool bOverwrite )
386 : : {
387 [ + - ]: 611 : XMLTextStyleContext::Finish( bOverwrite );
388 : :
389 [ - + ][ # # ]: 611 : if( !pConditions || XML_STYLE_FAMILY_TEXT_PARAGRAPH != GetFamily() )
[ - + ]
390 : : return;
391 : :
392 : 0 : uno::Reference < style::XStyle > xStyle = GetStyle();
393 [ # # ]: 0 : if( !xStyle.is() )
394 : : return;
395 : :
396 : 0 : const SwXStyle* pStyle = 0;
397 [ # # ]: 0 : uno::Reference<lang::XUnoTunnel> xStyleTunnel( xStyle, uno::UNO_QUERY);
398 [ # # ]: 0 : if( xStyleTunnel.is() )
399 : : {
400 : : pStyle = reinterpret_cast< SwXStyle * >(
401 [ # # ][ # # ]: 0 : sal::static_int_cast< sal_IntPtr >( xStyleTunnel->getSomething( SwXStyle::getUnoTunnelId() )));
[ # # ]
402 : : }
403 [ # # ]: 0 : if( !pStyle )
404 : : return;
405 : :
406 : 0 : const SwDoc *pDoc = pStyle->GetDoc();
407 : :
408 [ # # ]: 0 : SwTxtFmtColl *pColl = pDoc->FindTxtFmtCollByName( pStyle->GetStyleName() );
409 : : OSL_ENSURE( pColl, "Text collection not found" );
410 [ # # ][ # # ]: 0 : if( !pColl || RES_CONDTXTFMTCOLL != pColl->Which() )
[ # # ]
411 : : return;
412 : :
413 : 0 : sal_uInt16 nCount = pConditions->size();
414 [ # # ]: 0 : String aString;
415 : 0 : OUString sName;
416 [ # # ]: 0 : for( sal_uInt16 i = 0; i < nCount; i++ )
417 : : {
418 : 0 : const SwXMLConditionContext_Impl *pCond = (*pConditions)[i];
419 : : OUString aDisplayName(
420 : 0 : GetImport().GetStyleDisplayName( XML_STYLE_FAMILY_TEXT_PARAGRAPH,
421 [ # # ]: 0 : pCond->GetApplyStyle() ) );
422 : : SwStyleNameMapper::FillUIName( aDisplayName,
423 : : aString,
424 : : nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL,
425 [ # # ][ # # ]: 0 : sal_True);
[ # # ]
426 [ # # ]: 0 : sName = aString;
427 [ # # ][ # # ]: 0 : SwTxtFmtColl* pCondColl = pDoc->FindTxtFmtCollByName( sName );
[ # # ]
428 : : OSL_ENSURE( pCondColl,
429 : : "SwXMLItemSetStyleContext_Impl::ConnectConditions: cond coll missing" );
430 [ # # ]: 0 : if( pCondColl )
431 : : {
432 : : SwCollCondition aCond( pCondColl, pCond->GetCondition(),
433 [ # # ]: 0 : pCond->GetSubCondition() );
434 [ # # ][ # # ]: 0 : ((SwConditionTxtFmtColl*)pColl)->InsertCondition( aCond );
435 : : }
436 [ # # ][ # # ]: 611 : }
[ # # ]
437 : : }
438 : :
439 : : // ---------------------------------------------------------------------
440 : :
441 : : class SwXMLItemSetStyleContext_Impl : public SvXMLStyleContext
442 : : {
443 : : OUString sMasterPageName;
444 : : SfxItemSet *pItemSet;
445 : : SwXMLTextStyleContext_Impl *pTextStyle;
446 : : SvXMLStylesContext &rStyles;
447 : :
448 : : OUString sDataStyleName;
449 : :
450 : : sal_Bool bHasMasterPageName : 1;
451 : : sal_Bool bPageDescConnected : 1;
452 : : sal_Bool bDataStyleIsResolved;
453 : :
454 : : SvXMLImportContext *CreateItemSetContext(
455 : : sal_uInt16 nPrefix,
456 : : const OUString& rLName,
457 : : const uno::Reference< xml::sax::XAttributeList > & xAttrList);
458 : :
459 : : protected:
460 : :
461 : : virtual void SetAttribute( sal_uInt16 nPrefixKey,
462 : : const OUString& rLocalName,
463 : : const OUString& rValue );
464 : :
465 : : const SwXMLImport& GetSwImport() const
466 : : { return (const SwXMLImport&)GetImport(); }
467 : 114 : SwXMLImport& GetSwImport() { return (SwXMLImport&)GetImport(); }
468 : :
469 : : public:
470 : :
471 : : TYPEINFO();
472 : :
473 : : SwXMLItemSetStyleContext_Impl(
474 : : SwXMLImport& rImport, sal_uInt16 nPrfx,
475 : : const OUString& rLName,
476 : : const uno::Reference< xml::sax::XAttributeList > & xAttrList,
477 : : SvXMLStylesContext& rStylesC,
478 : : sal_uInt16 nFamily);
479 : : virtual ~SwXMLItemSetStyleContext_Impl();
480 : :
481 : : virtual void CreateAndInsert( sal_Bool bOverwrite );
482 : : virtual SvXMLImportContext *CreateChildContext(
483 : : sal_uInt16 nPrefix,
484 : : const OUString& rLocalName,
485 : : const uno::Reference< xml::sax::XAttributeList > & xAttrList );
486 : :
487 : : // The item set may be empty!
488 : 57 : SfxItemSet *GetItemSet() { return pItemSet; }
489 : : const SfxItemSet *GetItemSet() const { return pItemSet; }
490 : :
491 : 0 : const OUString& GetMasterPageName() const { return sMasterPageName; }
492 : 3 : sal_Bool HasMasterPageName() const { return bHasMasterPageName; }
493 : :
494 : 0 : sal_Bool IsPageDescConnected() const { return bPageDescConnected; }
495 : : void ConnectPageDesc();
496 : :
497 : : sal_Bool ResolveDataStyleName();
498 : : };
499 : :
500 : 114 : void SwXMLItemSetStyleContext_Impl::SetAttribute( sal_uInt16 nPrefixKey,
501 : : const OUString& rLocalName,
502 : : const OUString& rValue )
503 : : {
504 [ + - ]: 114 : if( XML_NAMESPACE_STYLE == nPrefixKey )
505 : : {
506 [ - + ]: 114 : if ( IsXMLToken( rLocalName, XML_MASTER_PAGE_NAME ) )
507 : : {
508 : 0 : sMasterPageName = rValue;
509 : 0 : bHasMasterPageName = sal_True;
510 : : }
511 [ - + ]: 114 : else if ( IsXMLToken( rLocalName, XML_DATA_STYLE_NAME ) )
512 : : {
513 : : // if we have a valid data style name
514 [ # # ]: 0 : if (!rValue.isEmpty())
515 : : {
516 : 0 : sDataStyleName = rValue;
517 : 0 : bDataStyleIsResolved = sal_False; // needs to be resolved
518 : : }
519 : : }
520 : : else
521 : : {
522 : 114 : SvXMLStyleContext::SetAttribute( nPrefixKey, rLocalName, rValue );
523 : : }
524 : : }
525 : : else
526 : : {
527 : 0 : SvXMLStyleContext::SetAttribute( nPrefixKey, rLocalName, rValue );
528 : : }
529 : 114 : }
530 : :
531 : 57 : SvXMLImportContext *SwXMLItemSetStyleContext_Impl::CreateItemSetContext(
532 : : sal_uInt16 nPrefix, const OUString& rLName,
533 : : const uno::Reference< xml::sax::XAttributeList > & xAttrList )
534 : : {
535 : : OSL_ENSURE( !pItemSet,
536 : : "SwXMLItemSetStyleContext_Impl::CreateItemSetContext: item set exists" );
537 : :
538 : 57 : SvXMLImportContext *pContext = 0;
539 : :
540 : 57 : SwDoc* pDoc = SwImport::GetDocFromXMLImport( GetSwImport() );
541 : :
542 : 57 : SfxItemPool& rItemPool = pDoc->GetAttrPool();
543 [ + + - + : 57 : switch( GetFamily() )
- ]
544 : : {
545 : : case XML_STYLE_FAMILY_TABLE_TABLE:
546 [ + - ]: 3 : pItemSet = new SfxItemSet( rItemPool, aTableSetRange );
547 : 3 : break;
548 : : case XML_STYLE_FAMILY_TABLE_COLUMN:
549 [ + - ]: 3 : pItemSet = new SfxItemSet( rItemPool, RES_FRM_SIZE, RES_FRM_SIZE, 0 );
550 : 3 : break;
551 : : case XML_STYLE_FAMILY_TABLE_ROW:
552 [ # # ]: 0 : pItemSet = new SfxItemSet( rItemPool, aTableLineSetRange );
553 : 0 : break;
554 : : case XML_STYLE_FAMILY_TABLE_CELL:
555 [ + - ]: 51 : pItemSet = new SfxItemSet( rItemPool, aTableBoxSetRange );
556 : 51 : break;
557 : : default:
558 : : OSL_ENSURE( !this,
559 : : "SwXMLItemSetStyleContext_Impl::CreateItemSetContext: unknown family" );
560 : 0 : break;
561 : : }
562 [ + - ]: 57 : if( pItemSet )
563 : 57 : pContext = GetSwImport().CreateTableItemImportContext(
564 : 57 : nPrefix, rLName, xAttrList, GetFamily(),
565 : 57 : *pItemSet );
566 [ - + ]: 57 : if( !pContext )
567 : : {
568 [ # # ]: 0 : delete pItemSet;
569 : 0 : pItemSet = 0;
570 : : }
571 : :
572 : 57 : return pContext;
573 : : }
574 : :
575 [ + - ][ # # ]: 228 : TYPEINIT1( SwXMLItemSetStyleContext_Impl, SvXMLStyleContext );
576 : :
577 : 57 : SwXMLItemSetStyleContext_Impl::SwXMLItemSetStyleContext_Impl( SwXMLImport& rImport,
578 : : sal_uInt16 nPrfx, const OUString& rLName,
579 : : const uno::Reference< xml::sax::XAttributeList > & xAttrList,
580 : : SvXMLStylesContext& rStylesC,
581 : : sal_uInt16 nFamily ) :
582 : : SvXMLStyleContext( rImport, nPrfx, rLName, xAttrList, nFamily ),
583 : : pItemSet( 0 ),
584 : : pTextStyle( 0 ),
585 : : rStyles( rStylesC ),
586 : : bHasMasterPageName( sal_False ),
587 : : bPageDescConnected( sal_False ),
588 : 57 : bDataStyleIsResolved( sal_True )
589 : : {
590 : 57 : }
591 : :
592 : 57 : SwXMLItemSetStyleContext_Impl::~SwXMLItemSetStyleContext_Impl()
593 : : {
594 [ + - ][ + - ]: 57 : delete pItemSet;
595 [ - + ]: 114 : }
596 : :
597 : 51 : void SwXMLItemSetStyleContext_Impl::CreateAndInsert( sal_Bool bOverwrite )
598 : : {
599 [ - + ]: 51 : if( pTextStyle )
600 : 0 : pTextStyle->CreateAndInsert( bOverwrite );
601 : 51 : }
602 : :
603 : 57 : SvXMLImportContext *SwXMLItemSetStyleContext_Impl::CreateChildContext(
604 : : sal_uInt16 nPrefix,
605 : : const OUString& rLocalName,
606 : : const uno::Reference< xml::sax::XAttributeList > & xAttrList )
607 : : {
608 : 57 : SvXMLImportContext *pContext = 0;
609 : :
610 [ + - ]: 57 : if( XML_NAMESPACE_STYLE == nPrefix )
611 : : {
612 [ + + + + : 213 : if( IsXMLToken( rLocalName, XML_TABLE_PROPERTIES ) ||
+ - + - ]
[ + - ]
613 : 54 : IsXMLToken( rLocalName, XML_TABLE_COLUMN_PROPERTIES ) ||
614 : 51 : IsXMLToken( rLocalName, XML_TABLE_ROW_PROPERTIES ) ||
615 : 51 : IsXMLToken( rLocalName, XML_TABLE_CELL_PROPERTIES ) )
616 : : {
617 : 57 : pContext = CreateItemSetContext( nPrefix, rLocalName, xAttrList );
618 : : }
619 [ # # # # ]: 0 : else if( IsXMLToken( rLocalName, XML_TEXT_PROPERTIES ) ||
[ # # ]
620 : 0 : IsXMLToken( rLocalName, XML_PARAGRAPH_PROPERTIES ))
621 : : {
622 [ # # ]: 0 : if( !pTextStyle )
623 : : {
624 [ # # ]: 0 : SvXMLAttributeList *pTmp = new SvXMLAttributeList;
625 [ # # ][ # # ]: 0 : OUString aStr = GetImport().GetNamespaceMap().GetQNameByKey( nPrefix, GetXMLToken(XML_NAME) );
626 [ # # ]: 0 : pTmp->AddAttribute( aStr, GetName() );
627 [ # # ][ # # ]: 0 : uno::Reference <xml::sax::XAttributeList> xTmpAttrList = pTmp;
628 : : pTextStyle = new SwXMLTextStyleContext_Impl( GetSwImport(), nPrefix,
629 [ # # ][ # # ]: 0 : rLocalName, xTmpAttrList, XML_STYLE_FAMILY_TEXT_PARAGRAPH, rStyles );
630 [ # # ]: 0 : pTextStyle->StartElement( xTmpAttrList );
631 [ # # ]: 0 : rStyles.AddStyle( *pTextStyle );
632 : : }
633 : 0 : pContext = pTextStyle->CreateChildContext( nPrefix, rLocalName, xAttrList );
634 : : }
635 : : }
636 : :
637 [ - + ]: 57 : if( !pContext )
638 : : pContext = SvXMLStyleContext::CreateChildContext( nPrefix, rLocalName,
639 : 0 : xAttrList );
640 : :
641 : 57 : return pContext;
642 : : }
643 : :
644 : 0 : void SwXMLItemSetStyleContext_Impl::ConnectPageDesc()
645 : : {
646 [ # # ][ # # ]: 0 : if( bPageDescConnected || !HasMasterPageName() )
[ # # ]
647 : : return;
648 : 0 : bPageDescConnected = sal_True;
649 : :
650 [ # # ]: 0 : SwDoc *pDoc = SwImport::GetDocFromXMLImport( GetSwImport() );
651 : :
652 [ # # ]: 0 : String sName;
653 : : // #i40788# - first determine the display name of the page style,
654 : : // then map this name to the corresponding user interface name.
655 : 0 : sName = GetImport().GetStyleDisplayName( XML_STYLE_FAMILY_MASTER_PAGE,
656 [ # # ][ # # ]: 0 : GetMasterPageName() );
657 : : SwStyleNameMapper::FillUIName( sName,
658 : : sName,
659 : : nsSwGetPoolIdFromName::GET_POOLID_PAGEDESC,
660 [ # # ]: 0 : sal_True);
661 [ # # ]: 0 : SwPageDesc *pPageDesc = pDoc->FindPageDescByName( sName );
662 [ # # ]: 0 : if( !pPageDesc )
663 : : {
664 : : // If the page style is a pool style, then we maybe have to create it
665 : : // first if it hasn't been used by now.
666 [ # # ]: 0 : sal_uInt16 nPoolId = SwStyleNameMapper::GetPoolIdFromUIName( sName, nsSwGetPoolIdFromName::GET_POOLID_PAGEDESC );
667 [ # # ]: 0 : if( USHRT_MAX != nPoolId )
668 [ # # ]: 0 : pPageDesc = pDoc->GetPageDescFromPool( nPoolId, false );
669 : : }
670 : :
671 [ # # ]: 0 : if( !pPageDesc )
672 : : return;
673 : :
674 [ # # ]: 0 : if( !pItemSet )
675 : : {
676 : 0 : SfxItemPool& rItemPool = pDoc->GetAttrPool();
677 [ # # ][ # # ]: 0 : pItemSet = new SfxItemSet( rItemPool, aTableSetRange );
678 : : }
679 : :
680 : : const SfxPoolItem *pItem;
681 : 0 : SwFmtPageDesc *pFmtPageDesc = 0;
682 [ # # ]: 0 : if( SFX_ITEM_SET == pItemSet->GetItemState( RES_PAGEDESC, sal_False,
683 [ # # ]: 0 : &pItem ) )
684 : : {
685 [ # # ]: 0 : if( ((SwFmtPageDesc *)pItem)->GetPageDesc() != pPageDesc )
686 [ # # ][ # # ]: 0 : pFmtPageDesc = new SwFmtPageDesc( *(SwFmtPageDesc *)pItem );
687 : : }
688 : : else
689 [ # # ][ # # ]: 0 : pFmtPageDesc = new SwFmtPageDesc();
690 : :
691 [ # # ]: 0 : if( pFmtPageDesc )
692 : : {
693 [ # # ]: 0 : pFmtPageDesc->RegisterToPageDesc( *pPageDesc );
694 [ # # ]: 0 : pItemSet->Put( *pFmtPageDesc );
695 [ # # ][ # # ]: 0 : delete pFmtPageDesc;
696 [ # # ][ # # ]: 0 : }
697 : : }
698 : :
699 : 51 : sal_Bool SwXMLItemSetStyleContext_Impl::ResolveDataStyleName()
700 : : {
701 : : // resolve, if not already done
702 [ - + ]: 51 : if (! bDataStyleIsResolved)
703 : : {
704 : : // get the format key
705 : : sal_Int32 nFormat =
706 [ # # ][ # # ]: 0 : GetImport().GetTextImport()->GetDataStyleKey(sDataStyleName);
707 : :
708 : : // if the key is valid, insert Item into ItemSet
709 [ # # ]: 0 : if( -1 != nFormat )
710 : : {
711 [ # # ]: 0 : if( !pItemSet )
712 : : {
713 [ # # ]: 0 : SwDoc *pDoc = SwImport::GetDocFromXMLImport( GetSwImport() );
714 : :
715 : 0 : SfxItemPool& rItemPool = pDoc->GetAttrPool();
716 [ # # ][ # # ]: 0 : pItemSet = new SfxItemSet( rItemPool, aTableBoxSetRange );
717 : : }
718 [ # # ]: 0 : SwTblBoxNumFormat aNumFormatItem(nFormat);
719 [ # # ][ # # ]: 0 : pItemSet->Put(aNumFormatItem);
720 : : }
721 : :
722 : : // now resolved
723 : 0 : bDataStyleIsResolved = sal_True;
724 : 0 : return sal_True;
725 : : }
726 : : else
727 : : {
728 : : // was already resolved; nothing to do
729 : 51 : return sal_False;
730 : : }
731 : : }
732 : :
733 : : // ---------------------------------------------------------------------
734 : : //
735 : : class SwXMLStylesContext_Impl : public SvXMLStylesContext
736 : : {
737 : : SwXMLItemSetStyleContext_Impl *GetSwStyle( sal_uInt16 i ) const;
738 : :
739 : 972 : SwXMLImport& GetSwImport() { return (SwXMLImport&)GetImport(); }
740 : 3267 : const SwXMLImport& GetSwImport() const
741 : 3267 : { return (const SwXMLImport&)GetImport(); }
742 : :
743 : : protected:
744 : :
745 : : virtual SvXMLStyleContext *CreateStyleStyleChildContext( sal_uInt16 nFamily,
746 : : sal_uInt16 nPrefix, const OUString& rLocalName,
747 : : const uno::Reference< xml::sax::XAttributeList > & xAttrList );
748 : : virtual SvXMLStyleContext *CreateDefaultStyleStyleChildContext(
749 : : sal_uInt16 nFamily, sal_uInt16 nPrefix, const OUString& rLocalName,
750 : : const uno::Reference< xml::sax::XAttributeList > & xAttrList );
751 : : // HACK
752 : : virtual UniReference < SvXMLImportPropertyMapper > GetImportPropertyMapper(
753 : : sal_uInt16 nFamily ) const;
754 : :
755 : : virtual uno::Reference < container::XNameContainer >
756 : : GetStylesContainer( sal_uInt16 nFamily ) const;
757 : : virtual ::rtl::OUString GetServiceName( sal_uInt16 nFamily ) const;
758 : : // HACK
759 : :
760 : : public:
761 : :
762 : : TYPEINFO();
763 : :
764 : : SwXMLStylesContext_Impl(
765 : : SwXMLImport& rImport, sal_uInt16 nPrfx,
766 : : const OUString& rLName ,
767 : : const uno::Reference< xml::sax::XAttributeList > & xAttrList,
768 : : sal_Bool bAuto );
769 : : virtual ~SwXMLStylesContext_Impl();
770 : :
771 : : virtual sal_Bool InsertStyleFamily( sal_uInt16 nFamily ) const;
772 : :
773 : : virtual void EndElement();
774 : : };
775 : :
776 [ # # ][ # # ]: 0 : TYPEINIT1( SwXMLStylesContext_Impl, SvXMLStylesContext );
777 : :
778 : : inline SwXMLItemSetStyleContext_Impl *SwXMLStylesContext_Impl::GetSwStyle(
779 : : sal_uInt16 i ) const
780 : : {
781 : : return PTR_CAST( SwXMLItemSetStyleContext_Impl, GetStyle( i ) );
782 : : }
783 : :
784 : 1039 : SvXMLStyleContext *SwXMLStylesContext_Impl::CreateStyleStyleChildContext(
785 : : sal_uInt16 nFamily, sal_uInt16 nPrefix, const OUString& rLocalName,
786 : : const uno::Reference< xml::sax::XAttributeList > & xAttrList )
787 : : {
788 : 1039 : SvXMLStyleContext *pStyle = 0;
789 : :
790 [ + + + + ]: 1039 : switch( nFamily )
791 : : {
792 : : case XML_STYLE_FAMILY_TEXT_PARAGRAPH:
793 : : pStyle = new SwXMLTextStyleContext_Impl( GetSwImport(), nPrefix,
794 [ + - ]: 726 : rLocalName, xAttrList, nFamily, *this );
795 : 726 : break;
796 : : case XML_STYLE_FAMILY_TABLE_TABLE:
797 : : case XML_STYLE_FAMILY_TABLE_COLUMN:
798 : : case XML_STYLE_FAMILY_TABLE_ROW:
799 : : case XML_STYLE_FAMILY_TABLE_CELL:
800 : : pStyle = new SwXMLItemSetStyleContext_Impl( GetSwImport(), nPrefix,
801 [ + - ]: 57 : rLocalName, xAttrList, *this, nFamily );
802 : 57 : break;
803 : : case XML_STYLE_FAMILY_SD_GRAPHICS_ID:
804 : : // As long as there are no element items, we can use the text
805 : : // style class.
806 : 40 : pStyle = new XMLTextShapeStyleContext( GetImport(), nPrefix,
807 [ + - ]: 40 : rLocalName, xAttrList, *this, nFamily );
808 : 40 : break;
809 : : default:
810 : : pStyle = SvXMLStylesContext::CreateStyleStyleChildContext( nFamily,
811 : : nPrefix,
812 : : rLocalName,
813 : 216 : xAttrList );
814 : 216 : break;
815 : : }
816 : :
817 : 1039 : return pStyle;
818 : : }
819 : :
820 : 252 : SvXMLStyleContext *SwXMLStylesContext_Impl::CreateDefaultStyleStyleChildContext(
821 : : sal_uInt16 nFamily, sal_uInt16 nPrefix, const OUString& rLocalName,
822 : : const uno::Reference< xml::sax::XAttributeList > & xAttrList )
823 : : {
824 : 252 : SvXMLStyleContext *pStyle = 0;
825 : :
826 [ + + - ]: 252 : switch( nFamily )
827 : : {
828 : : case XML_STYLE_FAMILY_TEXT_PARAGRAPH:
829 : : case XML_STYLE_FAMILY_TABLE_TABLE:
830 : : case XML_STYLE_FAMILY_TABLE_ROW:
831 : 189 : pStyle = new XMLTextStyleContext( GetImport(), nPrefix, rLocalName,
832 : : xAttrList, *this, nFamily,
833 [ + - ]: 189 : sal_True );
834 : 189 : break;
835 : : case XML_STYLE_FAMILY_SD_GRAPHICS_ID:
836 : : // There are no writer specific defaults for graphic styles!
837 : 63 : pStyle = new XMLGraphicsDefaultStyle( GetImport(), nPrefix,
838 [ + - ]: 63 : rLocalName, xAttrList, *this );
839 : 63 : break;
840 : : default:
841 : : pStyle = SvXMLStylesContext::CreateDefaultStyleStyleChildContext( nFamily,
842 : : nPrefix,
843 : : rLocalName,
844 : 0 : xAttrList );
845 : 0 : break;
846 : : }
847 : :
848 : 252 : return pStyle;
849 : : }
850 : :
851 : :
852 : 189 : SwXMLStylesContext_Impl::SwXMLStylesContext_Impl(
853 : : SwXMLImport& rImport, sal_uInt16 nPrfx, const OUString& rLName,
854 : : const uno::Reference< xml::sax::XAttributeList > & xAttrList,
855 : : sal_Bool bAuto ) :
856 : 189 : SvXMLStylesContext( rImport, nPrfx, rLName, xAttrList, bAuto )
857 : : {
858 : 189 : }
859 : :
860 : 189 : SwXMLStylesContext_Impl::~SwXMLStylesContext_Impl()
861 : : {
862 [ - + ]: 378 : }
863 : :
864 : 3267 : sal_Bool SwXMLStylesContext_Impl::InsertStyleFamily( sal_uInt16 nFamily ) const
865 : : {
866 : 3267 : const SwXMLImport& rSwImport = GetSwImport();
867 : 3267 : sal_uInt16 nStyleFamilyMask = rSwImport.GetStyleFamilyMask();
868 : :
869 : 3267 : sal_Bool bIns = sal_True;
870 [ + + + + : 3267 : switch( nFamily )
+ - ]
871 : : {
872 : : case XML_STYLE_FAMILY_TEXT_PARAGRAPH:
873 : 1833 : bIns = (nStyleFamilyMask & SFX_STYLE_FAMILY_PARA) != 0;
874 : 1833 : break;
875 : : case XML_STYLE_FAMILY_TEXT_TEXT:
876 : 510 : bIns = (nStyleFamilyMask & SFX_STYLE_FAMILY_CHAR) != 0;
877 : 510 : break;
878 : : case XML_STYLE_FAMILY_SD_GRAPHICS_ID:
879 : 60 : bIns = (nStyleFamilyMask & SFX_STYLE_FAMILY_FRAME) != 0;
880 : 60 : break;
881 : : case XML_STYLE_FAMILY_TEXT_LIST:
882 : 96 : bIns = (nStyleFamilyMask & SFX_STYLE_FAMILY_PSEUDO) != 0;
883 : 96 : break;
884 : : case XML_STYLE_FAMILY_TEXT_OUTLINE:
885 : : case XML_STYLE_FAMILY_TEXT_FOOTNOTECONFIG:
886 : : case XML_STYLE_FAMILY_TEXT_ENDNOTECONFIG:
887 : : case XML_STYLE_FAMILY_TEXT_LINENUMBERINGCONFIG:
888 : : case XML_STYLE_FAMILY_TEXT_BIBLIOGRAPHYCONFIG:
889 : 1536 : bIns = !(rSwImport.IsInsertMode() || rSwImport.IsStylesOnlyMode() ||
890 [ + - ]: 1536 : rSwImport.IsBlockMode());
[ + - + - ]
891 : 768 : break;
892 : : default:
893 : 0 : bIns = SvXMLStylesContext::InsertStyleFamily( nFamily );
894 : 0 : break;
895 : : }
896 : :
897 : 3267 : return bIns;
898 : : }
899 : :
900 : 4473 : UniReference < SvXMLImportPropertyMapper > SwXMLStylesContext_Impl::GetImportPropertyMapper(
901 : : sal_uInt16 nFamily ) const
902 : : {
903 : 4473 : UniReference < SvXMLImportPropertyMapper > xMapper;
904 [ + + ]: 4473 : if( nFamily == XML_STYLE_FAMILY_TABLE_TABLE )
905 : : xMapper = XMLTextImportHelper::CreateTableDefaultExtPropMapper(
906 [ + - ][ + - ]: 126 : const_cast<SwXMLStylesContext_Impl*>( this )->GetImport() );
907 [ + + ]: 4347 : else if( nFamily == XML_STYLE_FAMILY_TABLE_ROW )
908 : : xMapper = XMLTextImportHelper::CreateTableRowDefaultExtPropMapper(
909 [ + - ][ + - ]: 126 : const_cast<SwXMLStylesContext_Impl*>( this )->GetImport() );
910 : : else
911 [ + - ][ + - ]: 4221 : xMapper = SvXMLStylesContext::GetImportPropertyMapper( nFamily );
[ + - ]
912 : 4473 : return xMapper;
913 : : }
914 : :
915 : 1602 : uno::Reference < container::XNameContainer > SwXMLStylesContext_Impl::GetStylesContainer(
916 : : sal_uInt16 nFamily ) const
917 : : {
918 : 1602 : uno::Reference < container::XNameContainer > xStyles;
919 [ + + ]: 1602 : if( XML_STYLE_FAMILY_SD_GRAPHICS_ID == nFamily )
920 [ + - ][ + - ]: 40 : xStyles = ((SvXMLImport *)&GetImport())->GetTextImport()->GetFrameStyles();
[ + - ][ + - ]
[ + - ]
921 : : else
922 [ + - ][ + - ]: 1562 : xStyles = SvXMLStylesContext::GetStylesContainer( nFamily );
923 : :
924 : 1602 : return xStyles;
925 : : }
926 : :
927 : 208 : OUString SwXMLStylesContext_Impl::GetServiceName( sal_uInt16 nFamily ) const
928 : : {
929 [ + - ]: 208 : String sServiceName;
930 [ - + ]: 208 : if( XML_STYLE_FAMILY_SD_GRAPHICS_ID == nFamily )
931 [ # # ][ # # ]: 0 : sServiceName = OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.style.FrameStyle") );
932 : : else
933 [ + - ][ + - ]: 208 : sServiceName = SvXMLStylesContext::GetServiceName( nFamily );
934 : :
935 [ + - ][ + - ]: 208 : return sServiceName;
936 : : }
937 : :
938 : 189 : void SwXMLStylesContext_Impl::EndElement()
939 : : {
940 : 189 : GetSwImport().InsertStyles( IsAutomaticStyle() );
941 : 189 : }
942 : :
943 : : // ---------------------------------------------------------------------
944 : : //
945 : : class SwXMLMasterStylesContext_Impl : public XMLTextMasterStylesContext
946 : : {
947 : : protected:
948 : : virtual sal_Bool InsertStyleFamily( sal_uInt16 nFamily ) const;
949 : :
950 : 126 : SwXMLImport& GetSwImport() { return (SwXMLImport&)GetImport(); }
951 : 238 : const SwXMLImport& GetSwImport() const
952 : 238 : { return (const SwXMLImport&)GetImport(); }
953 : :
954 : : public:
955 : :
956 : : TYPEINFO();
957 : :
958 : : SwXMLMasterStylesContext_Impl(
959 : : SwXMLImport& rImport, sal_uInt16 nPrfx,
960 : : const OUString& rLName ,
961 : : const uno::Reference< xml::sax::XAttributeList > & xAttrList );
962 : : virtual ~SwXMLMasterStylesContext_Impl();
963 : : virtual void EndElement();
964 : : };
965 : :
966 [ # # ][ # # ]: 0 : TYPEINIT1( SwXMLMasterStylesContext_Impl, XMLTextMasterStylesContext );
967 : :
968 : 63 : SwXMLMasterStylesContext_Impl::SwXMLMasterStylesContext_Impl(
969 : : SwXMLImport& rImport, sal_uInt16 nPrfx,
970 : : const OUString& rLName ,
971 : : const uno::Reference< xml::sax::XAttributeList > & xAttrList ) :
972 : 63 : XMLTextMasterStylesContext( rImport, nPrfx, rLName, xAttrList )
973 : : {
974 : 63 : }
975 : :
976 : 63 : SwXMLMasterStylesContext_Impl::~SwXMLMasterStylesContext_Impl()
977 : : {
978 [ - + ]: 126 : }
979 : :
980 : 238 : sal_Bool SwXMLMasterStylesContext_Impl::InsertStyleFamily( sal_uInt16 nFamily ) const
981 : : {
982 : : sal_Bool bIns;
983 : :
984 : 238 : const SwXMLImport& rSwImport = GetSwImport();
985 : 238 : sal_uInt16 nStyleFamilyMask = rSwImport.GetStyleFamilyMask();
986 [ + - ]: 238 : if( XML_STYLE_FAMILY_MASTER_PAGE == nFamily )
987 : 238 : bIns = (nStyleFamilyMask & SFX_STYLE_FAMILY_PAGE) != 0;
988 : : else
989 : 0 : bIns = XMLTextMasterStylesContext::InsertStyleFamily( nFamily );
990 : :
991 : 238 : return bIns;
992 : : }
993 : :
994 : 63 : void SwXMLMasterStylesContext_Impl::EndElement()
995 : : {
996 : 63 : FinishStyles( !GetSwImport().IsInsertMode() );
997 : 63 : GetSwImport().FinishStyles();
998 : 63 : }
999 : : // ---------------------------------------------------------------------
1000 : :
1001 : 189 : SvXMLImportContext *SwXMLImport::CreateStylesContext(
1002 : : const OUString& rLocalName,
1003 : : const uno::Reference< xml::sax::XAttributeList > & xAttrList,
1004 : : sal_Bool bAuto )
1005 : : {
1006 : : SvXMLStylesContext *pContext =
1007 : : new SwXMLStylesContext_Impl( *this, XML_NAMESPACE_OFFICE, rLocalName,
1008 [ + - ]: 189 : xAttrList, bAuto );
1009 [ + + ]: 189 : if( bAuto )
1010 : 126 : SetAutoStyles( pContext );
1011 : : else
1012 : 63 : SetStyles( pContext );
1013 : :
1014 : 189 : return pContext;
1015 : : }
1016 : :
1017 : 63 : SvXMLImportContext *SwXMLImport::CreateMasterStylesContext(
1018 : : const OUString& rLocalName,
1019 : : const uno::Reference< xml::sax::XAttributeList > & xAttrList )
1020 : : {
1021 : : SvXMLStylesContext *pContext =
1022 : : new SwXMLMasterStylesContext_Impl( *this, XML_NAMESPACE_OFFICE, rLocalName,
1023 [ + - ]: 63 : xAttrList );
1024 : 63 : SetMasterStyles( pContext );
1025 : :
1026 : 63 : return pContext;
1027 : : }
1028 : :
1029 : 189 : void SwXMLImport::InsertStyles( sal_Bool bAuto )
1030 : : {
1031 [ + + ][ + - ]: 189 : if( bAuto && GetAutoStyles() )
[ + + ]
1032 : 126 : GetAutoStyles()->CopyAutoStylesToDoc();
1033 [ + + ][ + - ]: 189 : if( !bAuto && GetStyles() )
[ + + ]
1034 : 63 : GetStyles()->CopyStylesToDoc( !IsInsertMode(), sal_False );
1035 : 189 : }
1036 : :
1037 : 63 : void SwXMLImport::FinishStyles()
1038 : : {
1039 [ + - ]: 63 : if( GetStyles() )
1040 : 63 : GetStyles()->FinishStyles( !IsInsertMode() );
1041 : 63 : }
1042 : :
1043 : 65 : void SwXMLImport::UpdateTxtCollConditions( SwDoc *pDoc )
1044 : : {
1045 [ - + ]: 65 : if( !pDoc )
1046 : 0 : pDoc = SwImport::GetDocFromXMLImport( *this );
1047 : :
1048 : 65 : const SwTxtFmtColls& rColls = *pDoc->GetTxtFmtColls();
1049 : 65 : sal_uInt16 nCount = rColls.size();
1050 [ + + ]: 753 : for( sal_uInt16 i=0; i < nCount; i++ )
1051 : : {
1052 : 688 : SwTxtFmtColl *pColl = rColls[i];
1053 [ + + ][ + + ]: 688 : if( pColl && RES_CONDTXTFMTCOLL == pColl->Which() )
[ + - ]
1054 : : {
1055 : : const SwFmtCollConditions& rConditions =
1056 : 65 : ((const SwConditionTxtFmtColl *)pColl)->GetCondColls();
1057 : 65 : sal_Bool bSendModify = sal_False;
1058 [ - + ][ # # ]: 65 : for( sal_uInt16 j=0; j < rConditions.size() && !bSendModify; j++ )
[ - + ]
1059 : : {
1060 : 0 : const SwCollCondition& rCond = rConditions[j];
1061 [ # # ]: 0 : switch( rCond.GetCondition() )
1062 : : {
1063 : : case PARA_IN_TABLEHEAD:
1064 : : case PARA_IN_TABLEBODY:
1065 : : case PARA_IN_FOOTER:
1066 : : case PARA_IN_HEADER:
1067 : 0 : bSendModify = sal_True;
1068 : 0 : break;
1069 : : }
1070 : : }
1071 [ - + ]: 65 : if( bSendModify )
1072 : : {
1073 [ # # ]: 0 : SwCondCollCondChg aMsg( pColl );
1074 [ # # ][ # # ]: 0 : pColl->ModifyNotification( &aMsg, &aMsg );
1075 : : }
1076 : : }
1077 : : }
1078 : 65 : }
1079 : :
1080 : 57 : sal_Bool SwXMLImport::FindAutomaticStyle(
1081 : : sal_uInt16 nFamily,
1082 : : const OUString& rName,
1083 : : const SfxItemSet **ppItemSet,
1084 : : OUString *pParent ) const
1085 : : {
1086 : 57 : SwXMLItemSetStyleContext_Impl *pStyle = 0;
1087 [ + - ]: 57 : if( GetAutoStyles() )
1088 : : {
1089 : 171 : pStyle = PTR_CAST( SwXMLItemSetStyleContext_Impl,
1090 : : GetAutoStyles()->
1091 : : FindStyleChildContext( nFamily, rName,
1092 [ + - + - ]: 171 : sal_True ) );
1093 [ + - ]: 57 : if( pStyle )
1094 : : {
1095 [ + - ]: 57 : if( ppItemSet )
1096 : : {
1097 [ + + - + : 60 : if( XML_STYLE_FAMILY_TABLE_TABLE == pStyle->GetFamily() &&
# # ][ - + ]
1098 : 3 : pStyle->HasMasterPageName() &&
1099 : 0 : !pStyle->IsPageDescConnected() )
1100 : 0 : pStyle->ConnectPageDesc();
1101 : 57 : (*ppItemSet) = pStyle->GetItemSet();
1102 : :
1103 : : // resolve data style name late
1104 [ - + ]: 108 : if( XML_STYLE_FAMILY_TABLE_CELL == pStyle->GetFamily() &&
[ + + - + ]
1105 : 51 : pStyle->ResolveDataStyleName() )
1106 : : {
1107 : 0 : (*ppItemSet) = pStyle->GetItemSet();
1108 : : }
1109 : :
1110 : : }
1111 : :
1112 [ - + ]: 57 : if( pParent )
1113 : 0 : *pParent = pStyle->GetParentName();
1114 : : }
1115 : : }
1116 : :
1117 : 57 : return pStyle != 0;
1118 : : }
1119 : :
1120 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|