LibreOffice Module sw (master) 1
xmlfmt.cxx
Go to the documentation of this file.
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 <rtl/ustrbuf.hxx>
21#include <sal/log.hxx>
22#include <osl/diagnose.h>
24#include <fmtcol.hxx>
25#include <hints.hxx>
26#include <doc.hxx>
27#include <docary.hxx>
29#include <unoprnms.hxx>
30#include <fmtpdsc.hxx>
31#include <pagedesc.hxx>
32#include <xmloff/maptype.hxx>
33#include <xmloff/xmlnumfi.hxx>
34#include <xmloff/xmlprmap.hxx>
36#include <xmloff/xmlstyle.hxx>
37#include <xmloff/txtstyli.hxx>
38#include <xmloff/txtimp.hxx>
39#include <xmloff/families.hxx>
46#include <com/sun/star/beans/XPropertySet.hpp>
47#include <com/sun/star/frame/XModel.hpp>
48#include <com/sun/star/lang/XMultiServiceFactory.hpp>
49#include "xmlimp.hxx"
50#include <cellatr.hxx>
51#include <SwStyleNameMapper.hxx>
52#include <ccoll.hxx>
53
54#include <memory>
55
56using namespace ::com::sun::star;
57using namespace ::com::sun::star::beans;
58using namespace ::com::sun::star::uno;
59using namespace ::xmloff::token;
60
61namespace {
62
63class SwXMLConditionParser_Impl
64{
65 OUString m_sInput;
66
67 Master_CollCondition m_nCondition;
68 sal_uInt32 m_nSubCondition;
69
70 sal_Int32 m_nPos;
71 sal_Int32 m_nLength;
72
73 inline bool SkipWS();
74 inline bool MatchChar( sal_Unicode c );
75 inline bool MatchName( OUString& rName );
76 inline bool MatchNumber( sal_uInt32& rNumber );
77
78public:
79
80 explicit SwXMLConditionParser_Impl( const OUString& rInp );
81
82 bool IsValid() const { return Master_CollCondition::NONE != m_nCondition; }
83
84 Master_CollCondition GetCondition() const { return m_nCondition; }
85 sal_uInt32 GetSubCondition() const { return m_nSubCondition; }
86};
87
88}
89
90inline bool SwXMLConditionParser_Impl::SkipWS()
91{
92 while( m_nPos < m_nLength && ' ' == m_sInput[m_nPos] )
93 m_nPos++;
94 return true;
95}
96
97inline bool SwXMLConditionParser_Impl::MatchChar( sal_Unicode c )
98{
99 bool bRet = false;
100 if( m_nPos < m_nLength && c == m_sInput[m_nPos] )
101 {
102 m_nPos++;
103 bRet = true;
104 }
105 return bRet;
106}
107
108inline bool SwXMLConditionParser_Impl::MatchName( OUString& rName )
109{
110 OUStringBuffer sBuffer( m_nLength );
111 while( m_nPos < m_nLength &&
112 ( ('a' <= m_sInput[m_nPos] && m_sInput[m_nPos] <= 'z') ||
113 '-' == m_sInput[m_nPos] ) )
114 {
115 sBuffer.append( m_sInput[m_nPos] );
116 m_nPos++;
117 }
118 rName = sBuffer.makeStringAndClear();
119 return !rName.isEmpty();
120}
121
122inline bool SwXMLConditionParser_Impl::MatchNumber( sal_uInt32& rNumber )
123{
124 OUStringBuffer sBuffer( m_nLength );
125 while( m_nPos < m_nLength && '0' <= m_sInput[m_nPos] && m_sInput[m_nPos] <= '9' )
126 {
127 sBuffer.append( m_sInput[m_nPos] );
128 m_nPos++;
129 }
130
131 OUString sNum( sBuffer.makeStringAndClear() );
132 if( !sNum.isEmpty() )
133 rNumber = sNum.toInt32();
134 return !sNum.isEmpty();
135}
136
137SwXMLConditionParser_Impl::SwXMLConditionParser_Impl( const OUString& rInp ) :
138 m_sInput( rInp ),
139 m_nCondition( Master_CollCondition::NONE ),
140 m_nSubCondition( 0 ),
141 m_nPos( 0 ),
142 m_nLength( rInp.getLength() )
143{
144 OUString sFunc;
145 bool bHasSub = false;
146 sal_uInt32 nSub = 0;
147 bool bOK = SkipWS() && MatchName( sFunc ) && SkipWS() &&
148 MatchChar( '(' ) && SkipWS() && MatchChar( ')' ) && SkipWS();
149 if( bOK && MatchChar( '=' ) )
150 {
151 bOK = SkipWS() && MatchNumber( nSub ) && SkipWS();
152 bHasSub = true;
153 }
154
155 bOK &= m_nPos == m_nLength;
156
157 if( !bOK )
158 return;
159
160 if( IsXMLToken( sFunc, XML_ENDNOTE ) && !bHasSub )
162 else if( IsXMLToken( sFunc, XML_FOOTER ) && !bHasSub )
164 else if( IsXMLToken( sFunc, XML_FOOTNOTE ) && !bHasSub )
166 else if( IsXMLToken( sFunc, XML_HEADER ) && !bHasSub )
168 else if( IsXMLToken( sFunc, XML_LIST_LEVEL) &&
169 nSub >=1 && nSub <= MAXLEVEL )
170 {
172 m_nSubCondition = nSub-1;
173 }
174 else if( IsXMLToken( sFunc, XML_OUTLINE_LEVEL) &&
175 nSub >=1 && nSub <= MAXLEVEL )
176 {
178 m_nSubCondition = nSub-1;
179 }
180 else if( IsXMLToken( sFunc, XML_SECTION ) && !bHasSub )
181 {
183 }
184 else if( IsXMLToken( sFunc, XML_TABLE ) && !bHasSub )
185 {
187 }
188 else if( IsXMLToken( sFunc, XML_TABLE_HEADER ) && !bHasSub )
189 {
191 }
192 else if( IsXMLToken( sFunc, XML_TEXT_BOX ) && !bHasSub )
193 {
195 }
196}
197
198namespace {
199
200class SwXMLConditionContext_Impl : public SvXMLImportContext
201{
202 Master_CollCondition m_nCondition;
203 sal_uInt32 m_nSubCondition;
204
205 OUString m_sApplyStyle;
206
207public:
208
209 SwXMLConditionContext_Impl(
210 SvXMLImport& rImport, sal_Int32 nElement,
211 const uno::Reference< xml::sax::XFastAttributeList > & xAttrList );
212
213 bool IsValid() const { return Master_CollCondition::NONE != m_nCondition; }
214
215 Master_CollCondition getCondition() const { return m_nCondition; }
216 sal_uInt32 getSubCondition() const { return m_nSubCondition; }
217 OUString const &getApplyStyle() const { return m_sApplyStyle; }
218};
219
220}
221
222SwXMLConditionContext_Impl::SwXMLConditionContext_Impl(
223 SvXMLImport& rImport, sal_Int32 /*nElement*/,
224 const uno::Reference< xml::sax::XFastAttributeList > & xAttrList ) :
225 SvXMLImportContext( rImport ),
226 m_nCondition( Master_CollCondition::NONE ),
227 m_nSubCondition( 0 )
228{
229 for (auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList ))
230 {
231 OUString sValue = aIter.toString();
232 switch (aIter.getToken())
233 {
234 case XML_ELEMENT(STYLE, XML_CONDITION):
235 {
236 SwXMLConditionParser_Impl aCondParser( sValue );
237 if( aCondParser.IsValid() )
238 {
239 m_nCondition = aCondParser.GetCondition();
240 m_nSubCondition = aCondParser.GetSubCondition();
241 }
242 break;
243 }
244 case XML_ELEMENT(STYLE, XML_APPLY_STYLE_NAME):
245 m_sApplyStyle = sValue;
246 break;
247 default:
248 XMLOFF_WARN_UNKNOWN("sw", aIter);
249 }
250 }
251}
252
253typedef std::vector<rtl::Reference<SwXMLConditionContext_Impl>> SwXMLConditions_Impl;
254
255namespace {
256
257class SwXMLTextStyleContext_Impl : public XMLTextStyleContext
258{
259 std::unique_ptr<SwXMLConditions_Impl> m_pConditions;
260
261protected:
262
263 virtual uno::Reference < style::XStyle > Create() override;
264 virtual void Finish( bool bOverwrite ) override;
265
266public:
267
268
269 SwXMLTextStyleContext_Impl( SwXMLImport& rImport,
270 XmlStyleFamily nFamily,
271 SvXMLStylesContext& rStyles );
272
273 virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(
274 sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& AttrList ) override;
275};
276
277}
278
279uno::Reference < style::XStyle > SwXMLTextStyleContext_Impl::Create()
280{
281 uno::Reference < style::XStyle > xNewStyle;
282 if( m_pConditions && XmlStyleFamily::TEXT_PARAGRAPH == GetFamily() )
283 {
284 uno::Reference< lang::XMultiServiceFactory > xFactory( GetImport().GetModel(),
285 uno::UNO_QUERY );
286 if( xFactory.is() )
287 {
288 uno::Reference < uno::XInterface > xIfc =
289 xFactory->createInstance( "com.sun.star.style.ConditionalParagraphStyle" );
290 if( xIfc.is() )
291 xNewStyle.set( xIfc, uno::UNO_QUERY );
292 }
293 }
294 else
295 {
296 xNewStyle = XMLTextStyleContext::Create();
297 }
298
299 return xNewStyle;
300}
301
302void
303SwXMLTextStyleContext_Impl::Finish( bool bOverwrite )
304{
305 if( m_pConditions && XmlStyleFamily::TEXT_PARAGRAPH == GetFamily() && GetStyle().is() )
306 {
307 CommandStruct const*const pCommands = SwCondCollItem::GetCmds();
308
309 Reference< XPropertySet > xPropSet( GetStyle(), UNO_QUERY );
310
311 uno::Sequence< beans::NamedValue > aSeq( m_pConditions->size() );
312 auto aSeqRange = asNonConstRange(aSeq);
313
314 for (std::vector<rtl::Reference<SwXMLConditionContext_Impl>>::size_type i = 0;
315 i < m_pConditions->size(); ++i)
316 {
317 assert((*m_pConditions)[i]->IsValid()); // checked before inserting
318 Master_CollCondition nCond = (*m_pConditions)[i]->getCondition();
319 sal_uInt32 nSubCond = (*m_pConditions)[i]->getSubCondition();
320
321 for (size_t j = 0; j < COND_COMMAND_COUNT; ++j)
322 {
323 if (pCommands[j].nCnd == nCond &&
324 pCommands[j].nSubCond == nSubCond)
325 {
326 aSeqRange[i].Name = GetCommandContextByIndex( j );
327 aSeqRange[i].Value <<= GetImport().GetStyleDisplayName(
328 GetFamily(), (*m_pConditions)[i]->getApplyStyle() );
329 break;
330 }
331 }
332 }
333
334 try
335 {
336 xPropSet->setPropertyValue(UNO_NAME_PARA_STYLE_CONDITIONS, uno::Any(aSeq));
337 }
338 catch (uno::Exception const&)
339 {
340 TOOLS_WARN_EXCEPTION("sw.xml", "exception when setting ParaStyleConditions");
341 }
342 }
343 XMLTextStyleContext::Finish( bOverwrite );
344}
345
346SwXMLTextStyleContext_Impl::SwXMLTextStyleContext_Impl( SwXMLImport& rImport,
347 XmlStyleFamily nFamily,
348 SvXMLStylesContext& rStyles ) :
349 XMLTextStyleContext( rImport, rStyles, nFamily )
350{
351}
352
353css::uno::Reference< css::xml::sax::XFastContextHandler > SwXMLTextStyleContext_Impl::createFastChildContext(
354 sal_Int32 nElement,
355 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
356{
357 if( nElement == XML_ELEMENT(STYLE, XML_MAP) )
358 {
360 new SwXMLConditionContext_Impl( GetImport(), nElement, xAttrList )};
361 if( xCond->IsValid() )
362 {
363 if( !m_pConditions )
364 m_pConditions = std::make_unique<SwXMLConditions_Impl>();
365 m_pConditions->push_back( xCond );
366 }
367 return xCond;
368 }
369
370 return XMLTextStyleContext::createFastChildContext( nElement, xAttrList );
371}
372
373namespace {
374
375class SwXMLCellStyleContext : public XMLPropStyleContext
376{
377 OUString m_sDataStyleName;
378 void AddDataFormat();
379public:
381 virtual void FillPropertySet(const css::uno::Reference<css::beans::XPropertySet>& rPropSet) override;
382 virtual void SetAttribute(sal_Int32 nElement, const OUString& rValue) override;
383};
384
385class SwXMLItemSetStyleContext_Impl : public SvXMLStyleContext
386{
387 OUString m_sMasterPageName;
388 std::optional<SfxItemSet> m_oItemSet;
389 SwXMLTextStyleContext_Impl *m_pTextStyle;
390 SvXMLStylesContext &m_rStyles;
391
392 OUString m_sDataStyleName;
393
394 bool m_bHasMasterPageName : 1;
395 bool m_bPageDescConnected : 1;
396 bool m_bDataStyleIsResolved;
397
398 SvXMLImportContext *CreateItemSetContext(
399 sal_Int32 nElement,
400 const uno::Reference< xml::sax::XFastAttributeList > & xAttrList);
401
402protected:
403
404 virtual void SetAttribute( sal_Int32 nElement,
405 const OUString& rValue ) override;
406
407 SwXMLImport& GetSwImport() { return static_cast<SwXMLImport&>(GetImport()); }
408
409public:
410
411
412 SwXMLItemSetStyleContext_Impl(
413 SwXMLImport& rImport,
414 SvXMLStylesContext& rStylesC,
415 XmlStyleFamily nFamily);
416
417 virtual void CreateAndInsert( bool bOverwrite ) override;
418
419 virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(
420 sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& AttrList ) override;
421
422 // The item set may be empty!
423 SfxItemSet *GetItemSet() { return m_oItemSet ? &*m_oItemSet : nullptr; }
424
425 bool HasMasterPageName() const { return m_bHasMasterPageName; }
426
427 bool IsPageDescConnected() const { return m_bPageDescConnected; }
428 void ConnectPageDesc();
429
430 bool ResolveDataStyleName();
431};
432
433}
434
435void SwXMLCellStyleContext::AddDataFormat()
436{
437 if (m_sDataStyleName.isEmpty() || IsDefaultStyle())
438 return;
439
440 const SvXMLNumFormatContext* pStyle = static_cast<const SvXMLNumFormatContext*>(
441 GetStyles()->FindStyleChildContext(XmlStyleFamily::DATA_STYLE, m_sDataStyleName, true));
442
443 if (!pStyle)
444 {
445 SAL_WARN("sw.xml", "not possible to get data style " << m_sDataStyleName);
446 return;
447 }
448
449 sal_Int32 nNumberFormat = const_cast<SvXMLNumFormatContext*>(pStyle)->GetKey();
450 if (nNumberFormat < 0)
451 return;
452
453 rtl::Reference<SvXMLImportPropertyMapper> xPropertyMapper(GetStyles()->GetImportPropertyMapper(GetFamily()));
454 if (!xPropertyMapper.is())
455 {
456 SAL_WARN("sw.xml", "there is no import prop mapper");
457 return;
458 }
459
460 const rtl::Reference<XMLPropertySetMapper>& xPropertySetMapper(xPropertyMapper->getPropertySetMapper());
461 sal_Int32 nIndex = xPropertySetMapper->GetEntryIndex(XML_NAMESPACE_STYLE, GetXMLToken(XML_DATA_STYLE_NAME), 0);
462 if (nIndex < 0)
463 {
464 SAL_WARN("sw.xml", "could not find id for " << GetXMLToken(XML_DATA_STYLE_NAME));
465 return;
466 }
467
468 auto aIter = std::find_if(GetProperties().begin(), GetProperties().end(),
469 [&nIndex](const XMLPropertyState& rProp) {
470 return rProp.mnIndex == nIndex;
471 });
472
473 if (aIter != GetProperties().end())
474 aIter->maValue <<= nNumberFormat;
475 else
476 GetProperties().push_back(XMLPropertyState(nIndex, Any(nNumberFormat)));
477}
478
479void SwXMLCellStyleContext::FillPropertySet(const css::uno::Reference<css::beans::XPropertySet>& rPropSet)
480{
481 AddDataFormat();
483}
484
485void SwXMLCellStyleContext::SetAttribute(sal_Int32 nElement, const OUString& rValue)
486{
487 if ((nElement & TOKEN_MASK) == XML_DATA_STYLE_NAME)
488 m_sDataStyleName = rValue;
489 else
490 XMLPropStyleContext::SetAttribute(nElement, rValue);
491}
492
493void SwXMLItemSetStyleContext_Impl::SetAttribute( sal_Int32 nElement,
494 const OUString& rValue )
495{
496 switch(nElement)
497 {
498 case XML_ELEMENT(STYLE, XML_MASTER_PAGE_NAME):
499 {
500 m_sMasterPageName = rValue;
501 m_bHasMasterPageName = true;
502 break;
503 }
504 case XML_ELEMENT(STYLE, XML_DATA_STYLE_NAME):
505 {
506 // if we have a valid data style name
507 if (!rValue.isEmpty())
508 {
509 m_sDataStyleName = rValue;
510 m_bDataStyleIsResolved = false; // needs to be resolved
511 }
512 break;
513 }
514 default:
515 SvXMLStyleContext::SetAttribute( nElement, rValue );
516 }
517}
518
519SvXMLImportContext *SwXMLItemSetStyleContext_Impl::CreateItemSetContext(
520 sal_Int32 nElement,
521 const uno::Reference< xml::sax::XFastAttributeList > & xAttrList )
522{
523 OSL_ENSURE( !m_oItemSet,
524 "SwXMLItemSetStyleContext_Impl::CreateItemSetContext: item set exists" );
525
526 SvXMLImportContext *pContext = nullptr;
527
528 SwDoc* pDoc = GetSwImport().getDoc();
529
530 SfxItemPool& rItemPool = pDoc->GetAttrPool();
531 switch( GetFamily() )
532 {
533 case XmlStyleFamily::TABLE_TABLE:
534 m_oItemSet.emplace( rItemPool, aTableSetRange );
535 break;
536 case XmlStyleFamily::TABLE_COLUMN:
537 m_oItemSet.emplace( rItemPool, svl::Items<RES_FRM_SIZE, RES_FRM_SIZE> );
538 break;
539 case XmlStyleFamily::TABLE_ROW:
540 m_oItemSet.emplace( rItemPool, aTableLineSetRange );
541 break;
542 case XmlStyleFamily::TABLE_CELL:
543 m_oItemSet.emplace( rItemPool, aTableBoxSetRange );
544 break;
545 default:
546 OSL_ENSURE( false,
547 "SwXMLItemSetStyleContext_Impl::CreateItemSetContext: unknown family" );
548 break;
549 }
550 if( m_oItemSet )
551 pContext = GetSwImport().CreateTableItemImportContext(
552 nElement, xAttrList, GetFamily(),
553 *m_oItemSet );
554 if( !pContext )
555 {
556 m_oItemSet.reset();
557 }
558
559 return pContext;
560}
561
562
563SwXMLItemSetStyleContext_Impl::SwXMLItemSetStyleContext_Impl( SwXMLImport& rImport,
564 SvXMLStylesContext& rStylesC,
565 XmlStyleFamily nFamily ) :
566 SvXMLStyleContext( rImport, nFamily ),
567 m_pTextStyle( nullptr ),
568 m_rStyles( rStylesC ),
569 m_bHasMasterPageName( false ),
570 m_bPageDescConnected( false ),
571 m_bDataStyleIsResolved( true )
572{
573}
574
575void SwXMLItemSetStyleContext_Impl::CreateAndInsert( bool bOverwrite )
576{
577 if( m_pTextStyle )
578 m_pTextStyle->CreateAndInsert( bOverwrite );
579}
580
581css::uno::Reference< css::xml::sax::XFastContextHandler > SwXMLItemSetStyleContext_Impl::createFastChildContext(
582 sal_Int32 nElement,
583 const uno::Reference< xml::sax::XFastAttributeList > & xAttrList )
584{
585 switch (nElement)
586 {
587 case XML_ELEMENT(STYLE, XML_TABLE_PROPERTIES):
591 return CreateItemSetContext( nElement, xAttrList );
592 case XML_ELEMENT(STYLE, XML_TEXT_PROPERTIES):
594 {
595 if( !m_pTextStyle )
596 {
597 m_pTextStyle = new SwXMLTextStyleContext_Impl( GetSwImport(), XmlStyleFamily::TEXT_PARAGRAPH, m_rStyles );
599 xTmpAttrList->add(XML_ELEMENT(STYLE, XML_NAME), GetName().toUtf8() );
600 m_pTextStyle->startFastElement( nElement, xTmpAttrList );
601 m_rStyles.AddStyle( *m_pTextStyle );
602 }
603 return m_pTextStyle->createFastChildContext( nElement, xAttrList );
604 }
605 default:
606 XMLOFF_WARN_UNKNOWN_ELEMENT("sw", nElement);
607 }
608
609 return nullptr;
610}
611
612void SwXMLItemSetStyleContext_Impl::ConnectPageDesc()
613{
614 if( m_bPageDescConnected || !HasMasterPageName() )
615 return;
616 m_bPageDescConnected = true;
617
618 SwDoc *pDoc = GetSwImport().getDoc();
619
620 // #i40788# - first determine the display name of the page style,
621 // then map this name to the corresponding user interface name.
622 OUString sName = GetImport().GetStyleDisplayName( XmlStyleFamily::MASTER_PAGE,
623 m_sMasterPageName );
625 sName,
627 SwPageDesc *pPageDesc = pDoc->FindPageDesc(sName);
628 if( !pPageDesc )
629 {
630 // If the page style is a pool style, then we maybe have to create it
631 // first if it hasn't been used by now.
633 if( USHRT_MAX != nPoolId )
634 pPageDesc = pDoc->getIDocumentStylePoolAccess().GetPageDescFromPool( nPoolId, false );
635 }
636
637 if( !pPageDesc )
638 return;
639
640 if( !m_oItemSet )
641 {
642 SfxItemPool& rItemPool = pDoc->GetAttrPool();
643 m_oItemSet.emplace( rItemPool, aTableSetRange );
644 }
645
646 std::unique_ptr<SwFormatPageDesc> pFormatPageDesc;
647 if( const SwFormatPageDesc* pItem = m_oItemSet->GetItemIfSet( RES_PAGEDESC, false ) )
648 {
649 if( pItem->GetPageDesc() != pPageDesc )
650 pFormatPageDesc.reset(new SwFormatPageDesc( *pItem ));
651 }
652 else
653 pFormatPageDesc.reset(new SwFormatPageDesc());
654
655 if( pFormatPageDesc )
656 {
657 pFormatPageDesc->RegisterToPageDesc( *pPageDesc );
658 m_oItemSet->Put( std::move(pFormatPageDesc) );
659 }
660}
661
662bool SwXMLItemSetStyleContext_Impl::ResolveDataStyleName()
663{
664 // resolve, if not already done
665 if (! m_bDataStyleIsResolved)
666 {
667 // get the format key
668 sal_Int32 nFormat =
669 GetImport().GetTextImport()->GetDataStyleKey(m_sDataStyleName);
670
671 // if the key is valid, insert Item into ItemSet
672 if( -1 != nFormat )
673 {
674 if( !m_oItemSet )
675 {
676 SwDoc *pDoc = GetSwImport().getDoc();
677
678 SfxItemPool& rItemPool = pDoc->GetAttrPool();
679 m_oItemSet.emplace( rItemPool, aTableBoxSetRange );
680 }
681 SwTableBoxNumFormat aNumFormatItem(nFormat);
682 m_oItemSet->Put(aNumFormatItem);
683 }
684
685 // now resolved
686 m_bDataStyleIsResolved = true;
687 return true;
688 }
689 else
690 {
691 // was already resolved; nothing to do
692 return false;
693 }
694}
695
696namespace {
697
698class SwXMLStylesContext_Impl : public SvXMLStylesContext
699{
700 SwXMLImport& GetSwImport() { return static_cast<SwXMLImport&>(GetImport()); }
701 const SwXMLImport& GetSwImport() const
702 { return static_cast<const SwXMLImport&>(GetImport()); }
703
704protected:
705
707 virtual SvXMLStyleContext *CreateStyleChildContext( sal_Int32 nElement,
708 const css::uno::Reference< css::xml::sax::XFastAttributeList > & xAttrList ) override;
709
712 sal_Int32 nElement,
713 const uno::Reference< xml::sax::XFastAttributeList > & xAttrList ) override;
716 XmlStyleFamily nFamily, sal_Int32 nElement,
717 const uno::Reference< xml::sax::XFastAttributeList > & xAttrList ) override;
718 // HACK
720 XmlStyleFamily nFamily ) const override;
721
722 virtual uno::Reference < container::XNameContainer >
723 GetStylesContainer( XmlStyleFamily nFamily ) const override;
724 virtual OUString GetServiceName( XmlStyleFamily nFamily ) const override;
725 // HACK
726
727public:
728
729 SwXMLStylesContext_Impl(
730 SwXMLImport& rImport,
731 bool bAuto );
732
733 virtual bool InsertStyleFamily( XmlStyleFamily nFamily ) const override;
734
735 virtual void SAL_CALL endFastElement(sal_Int32 nElement) override;
736};
737
738}
739
740SvXMLStyleContext *SwXMLStylesContext_Impl::CreateStyleChildContext(
741 sal_Int32 nElement,
742 const css::uno::Reference< css::xml::sax::XFastAttributeList > & xAttrList )
743{
744 SvXMLStyleContext* pContext = nullptr;
745
746 if(nElement == XML_ELEMENT(TABLE, XML_TABLE_TEMPLATE))
747 {
748 rtl::Reference<XMLTableImport> xTableImport = GetImport().GetShapeImport()->GetShapeTableImport();
749 pContext = xTableImport->CreateTableTemplateContext(nElement, xAttrList);
750 }
751 if (!pContext)
752 pContext = SvXMLStylesContext::CreateStyleChildContext(nElement, xAttrList);
753
754 return pContext;
755}
756
757SvXMLStyleContext *SwXMLStylesContext_Impl::CreateStyleStyleChildContext(
758 XmlStyleFamily nFamily, sal_Int32 nElement,
759 const uno::Reference< xml::sax::XFastAttributeList > & xAttrList )
760{
761 SvXMLStyleContext *pStyle = nullptr;
762
763 switch( nFamily )
764 {
765 case XmlStyleFamily::TEXT_PARAGRAPH:
766 pStyle = new SwXMLTextStyleContext_Impl( GetSwImport(), nFamily, *this );
767 break;
768 case XmlStyleFamily::TABLE_TABLE:
769 case XmlStyleFamily::TABLE_COLUMN:
770 case XmlStyleFamily::TABLE_ROW:
771 case XmlStyleFamily::TABLE_CELL:
772 // Distinguish real and automatic styles.
773 if (IsAutomaticStyle())
774 pStyle = new SwXMLItemSetStyleContext_Impl(GetSwImport(), *this, nFamily);
775 else if (nFamily == XmlStyleFamily::TABLE_CELL) // Real cell styles are used for table-template import.
776 pStyle = new SwXMLCellStyleContext(GetSwImport(), *this, nFamily);
777 else
778 SAL_WARN("sw.xml", "Context does not exists for non automatic table, column or row style.");
779 break;
780 case XmlStyleFamily::SD_GRAPHICS_ID:
781 // As long as there are no element items, we can use the text
782 // style class.
783 pStyle = new XMLTextShapeStyleContext( GetImport(), *this, nFamily );
784 break;
785 case XmlStyleFamily::SD_DRAWINGPAGE_ID:
786 pStyle = new XMLDrawingPageStyleContext(GetImport(),
787 *this, g_MasterPageContextIDs, g_MasterPageFamilies);
788 break;
789 default:
791 nElement,
792 xAttrList );
793 break;
794 }
795
796 return pStyle;
797}
798
799SvXMLStyleContext *SwXMLStylesContext_Impl::CreateDefaultStyleStyleChildContext(
800 XmlStyleFamily nFamily, sal_Int32 nElement,
801 const uno::Reference< xml::sax::XFastAttributeList > & xAttrList )
802{
803 SvXMLStyleContext *pStyle = nullptr;
804
805 switch( nFamily )
806 {
807 case XmlStyleFamily::TEXT_PARAGRAPH:
808 case XmlStyleFamily::TABLE_TABLE:
809 case XmlStyleFamily::TABLE_ROW:
810 pStyle = new XMLTextStyleContext( GetImport(),
811 *this, nFamily,
812 true );
813 break;
814 case XmlStyleFamily::SD_GRAPHICS_ID:
815 // There are no writer specific defaults for graphic styles!
816 pStyle = new XMLGraphicsDefaultStyle( GetImport(), *this );
817 break;
818 default:
820 nElement,
821 xAttrList );
822 break;
823 }
824
825 return pStyle;
826}
827
828SwXMLStylesContext_Impl::SwXMLStylesContext_Impl(
829 SwXMLImport& rImport,
830 bool bAuto ) :
831 SvXMLStylesContext( rImport, bAuto )
832{
833}
834
835bool SwXMLStylesContext_Impl::InsertStyleFamily( XmlStyleFamily nFamily ) const
836{
837 const SwXMLImport& rSwImport = GetSwImport();
838 const SfxStyleFamily nStyleFamilyMask = rSwImport.GetStyleFamilyMask();
839
840 bool bIns = true;
841 switch( nFamily )
842 {
843 case XmlStyleFamily::TEXT_PARAGRAPH:
844 bIns = bool(nStyleFamilyMask & SfxStyleFamily::Para);
845 break;
846 case XmlStyleFamily::TEXT_TEXT:
847 bIns = bool(nStyleFamilyMask & SfxStyleFamily::Char);
848 break;
849 case XmlStyleFamily::SD_GRAPHICS_ID:
850 bIns = bool(nStyleFamilyMask & SfxStyleFamily::Frame);
851 break;
852 case XmlStyleFamily::TEXT_LIST:
853 bIns = bool(nStyleFamilyMask & SfxStyleFamily::Pseudo);
854 break;
855 case XmlStyleFamily::TEXT_OUTLINE:
856 case XmlStyleFamily::TEXT_FOOTNOTECONFIG:
857 case XmlStyleFamily::TEXT_ENDNOTECONFIG:
858 case XmlStyleFamily::TEXT_LINENUMBERINGCONFIG:
859 case XmlStyleFamily::TEXT_BIBLIOGRAPHYCONFIG:
860 bIns = !(rSwImport.IsInsertMode() || rSwImport.IsStylesOnlyMode() ||
861 rSwImport.IsBlockMode());
862 break;
863 default:
865 break;
866 }
867
868 return bIns;
869}
870
871rtl::Reference < SvXMLImportPropertyMapper > SwXMLStylesContext_Impl::GetImportPropertyMapper(
872 XmlStyleFamily nFamily ) const
873{
875 if( nFamily == XmlStyleFamily::TABLE_TABLE )
877 const_cast<SwXMLStylesContext_Impl*>( this )->GetImport() );
878 else if( nFamily == XmlStyleFamily::TABLE_ROW )
880 const_cast<SwXMLStylesContext_Impl*>( this )->GetImport() );
881 else if( nFamily == XmlStyleFamily::TABLE_CELL )
883 const_cast<SwXMLStylesContext_Impl*>( this )->GetImport() );
884 else if (nFamily == XmlStyleFamily::SD_DRAWINGPAGE_ID)
885 {
887 const_cast<SwXMLStylesContext_Impl*>(this)->GetImport());
888 }
889 else
891 return xMapper;
892}
893
894uno::Reference < container::XNameContainer > SwXMLStylesContext_Impl::GetStylesContainer(
895 XmlStyleFamily nFamily ) const
896{
897 uno::Reference < container::XNameContainer > xStyles;
898 if( XmlStyleFamily::SD_GRAPHICS_ID == nFamily )
899 xStyles = const_cast<SvXMLImport *>(&GetImport())->GetTextImport()->GetFrameStyles();
900 else if( XmlStyleFamily::TABLE_CELL == nFamily )
901 xStyles = const_cast<SvXMLImport *>(&GetImport())->GetTextImport()->GetCellStyles();
902
903 if (!xStyles.is())
904 xStyles = SvXMLStylesContext::GetStylesContainer( nFamily );
905
906 return xStyles;
907}
908
909OUString SwXMLStylesContext_Impl::GetServiceName( XmlStyleFamily nFamily ) const
910{
911 if( XmlStyleFamily::SD_GRAPHICS_ID == nFamily )
912 return "com.sun.star.style.FrameStyle";
913 else if( XmlStyleFamily::TABLE_CELL == nFamily )
914 return "com.sun.star.style.CellStyle";
915
916 return SvXMLStylesContext::GetServiceName( nFamily );
917}
918
919void SwXMLStylesContext_Impl::endFastElement(sal_Int32 )
920{
921 GetSwImport().InsertStyles( IsAutomaticStyle() );
922}
923
924namespace {
925
926class SwXMLMasterStylesContext_Impl : public XMLTextMasterStylesContext
927{
928protected:
929 virtual bool InsertStyleFamily( XmlStyleFamily nFamily ) const override;
930
931 SwXMLImport& GetSwImport() { return static_cast<SwXMLImport&>(GetImport()); }
932 const SwXMLImport& GetSwImport() const
933 { return static_cast<const SwXMLImport&>(GetImport()); }
934
935public:
936
937
938 SwXMLMasterStylesContext_Impl( SwXMLImport& rImport );
939
940 virtual void SAL_CALL endFastElement(sal_Int32 nElement) override;
941};
942
943}
944
945SwXMLMasterStylesContext_Impl::SwXMLMasterStylesContext_Impl(
946 SwXMLImport& rImport ) :
948{
949}
950
951bool SwXMLMasterStylesContext_Impl::InsertStyleFamily( XmlStyleFamily nFamily ) const
952{
953 bool bIns;
954
955 const SwXMLImport& rSwImport = GetSwImport();
956 const SfxStyleFamily nStyleFamilyMask = rSwImport.GetStyleFamilyMask();
957 if( XmlStyleFamily::MASTER_PAGE == nFamily )
958 bIns = bool(nStyleFamilyMask & SfxStyleFamily::Page);
959 else
961
962 return bIns;
963}
964
965void SwXMLMasterStylesContext_Impl::endFastElement(sal_Int32 )
966{
967 FinishStyles( !GetSwImport().IsInsertMode() );
968 GetSwImport().FinishStyles();
969}
970
972 bool bAuto )
973{
974 SvXMLStylesContext *pContext = new SwXMLStylesContext_Impl( *this, bAuto );
975 if( bAuto )
976 SetAutoStyles( pContext );
977 else
978 SetStyles( pContext );
979
980 return pContext;
981}
982
984{
985 SvXMLStylesContext *pContext =
986 new SwXMLMasterStylesContext_Impl( *this );
987 SetMasterStyles( pContext );
988
989 return pContext;
990}
991
993{
994 if( bAuto && GetAutoStyles() )
996 if( !bAuto && GetStyles() )
997 GetStyles()->CopyStylesToDoc( !IsInsertMode(), false );
998}
999
1001{
1002 if( GetStyles() )
1004}
1005
1007{
1008 if( !pDoc )
1009 pDoc = getDoc();
1010
1011 const SwTextFormatColls& rColls = *pDoc->GetTextFormatColls();
1012 const size_t nCount = rColls.size();
1013 for( size_t i=0; i < nCount; ++i )
1014 {
1015 SwTextFormatColl *pColl = rColls[i];
1016 if( pColl && RES_CONDTXTFMTCOLL == pColl->Which() )
1017 {
1018 const SwFormatCollConditions& rConditions =
1019 static_cast<const SwConditionTextFormatColl *>(pColl)->GetCondColls();
1020 bool bSendModify = false;
1021 for( size_t j=0; j < rConditions.size() && !bSendModify; ++j )
1022 {
1023 const SwCollCondition& rCond = *rConditions[j];
1024 switch( rCond.GetCondition() )
1025 {
1030 bSendModify = true;
1031 break;
1032 default: break;
1033 }
1034 }
1035 if(bSendModify)
1036 pColl->GetNotifier().Broadcast(sw::CondCollCondChg(*pColl));
1037 }
1038 }
1039}
1040
1042 XmlStyleFamily nFamily,
1043 const OUString& rName,
1044 const SfxItemSet **ppItemSet ) const
1045{
1046 SwXMLItemSetStyleContext_Impl *pStyle = nullptr;
1047 if( GetAutoStyles() )
1048 {
1049 pStyle = const_cast<SwXMLItemSetStyleContext_Impl*>(dynamic_cast< const SwXMLItemSetStyleContext_Impl* >(
1050 GetAutoStyles()->
1051 FindStyleChildContext( nFamily, rName,
1052 true ) ) );
1053 if( pStyle )
1054 {
1055 if( ppItemSet )
1056 {
1057 if( XmlStyleFamily::TABLE_TABLE == pStyle->GetFamily() &&
1058 pStyle->HasMasterPageName() &&
1059 !pStyle->IsPageDescConnected() )
1060 pStyle->ConnectPageDesc();
1061 (*ppItemSet) = pStyle->GetItemSet();
1062
1063 // resolve data style name late
1064 if( XmlStyleFamily::TABLE_CELL == pStyle->GetFamily() &&
1065 pStyle->ResolveDataStyleName() )
1066 {
1067 (*ppItemSet) = pStyle->GetItemSet();
1068 }
1069
1070 }
1071 }
1072 }
1073
1074 return pStyle != nullptr;
1075}
1076
1077/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const sal_Int32 m_nLength
OUString GetCommandContextByIndex(sal_Int16 nIndex)
Definition: ccoll.cxx:74
#define COND_COMMAND_COUNT
Definition: ccoll.hxx:29
virtual SwPageDesc * GetPageDescFromPool(sal_uInt16 nId, bool bRegardLanguage=true)=0
Return required automatic page style.
const T & Put(std::unique_ptr< T > xItem, sal_uInt16 nWhich=0)
virtual void SAL_CALL endFastElement(sal_Int32 Element) override
SvXMLImport & GetImport()
virtual css::uno::Reference< XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 Element, const css::uno::Reference< css::xml::sax::XFastAttributeList > &Attribs) override
void SetMasterStyles(SvXMLStylesContext *pMasterStyles)
void SetAutoStyles(SvXMLStylesContext *pAutoStyles)
void SetStyles(SvXMLStylesContext *pStyles)
SvXMLStylesContext * GetStyles()
SvXMLStylesContext * GetAutoStyles()
virtual void SetAttribute(sal_Int32 nElement, const OUString &rValue)
virtual void CreateAndInsert(bool bOverwrite)
virtual css::uno::Reference< css::container::XNameContainer > GetStylesContainer(XmlStyleFamily nFamily) const
virtual SvXMLStyleContext * CreateDefaultStyleStyleChildContext(XmlStyleFamily nFamily, sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
virtual bool InsertStyleFamily(XmlStyleFamily nFamily) const
void CopyStylesToDoc(bool bOverwrite, bool bFinish=true)
virtual rtl::Reference< SvXMLImportPropertyMapper > GetImportPropertyMapper(XmlStyleFamily nFamily) const
virtual SvXMLStyleContext * CreateStyleChildContext(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
virtual SvXMLStyleContext * CreateStyleStyleChildContext(XmlStyleFamily nFamily, sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
void FinishStyles(bool bOverwrite)
virtual OUString GetServiceName(XmlStyleFamily nFamily) const
void CopyAutoStylesToDoc()
void Broadcast(const SfxHint &rHint)
Master_CollCondition GetCondition() const
Definition: fmtcol.hxx:227
static const CommandStruct * GetCmds()
Definition: ccoll.hxx:58
Definition: doc.hxx:194
SwPageDesc * FindPageDesc(const OUString &rName, size_t *pPos=nullptr) const
Definition: docdesc.cxx:947
const SwTextFormatColls * GetTextFormatColls() const
Definition: doc.hxx:786
IDocumentStylePoolAccess const & getIDocumentStylePoolAccess() const
Definition: doc.cxx:432
const SwAttrPool & GetAttrPool() const
Definition: doc.hxx:1326
Pagedescriptor Client of SwPageDesc that is "described" by the attribute.
Definition: fmtpdsc.hxx:36
sal_uInt16 Which() const
for Querying of Writer-functions.
Definition: format.hxx:82
static SW_DLLPUBLIC sal_uInt16 GetPoolIdFromUIName(const OUString &rName, SwGetPoolIdFromName)
static void FillUIName(const OUString &rName, OUString &rFillName, SwGetPoolIdFromName)
Represents the style of a paragraph.
Definition: fmtcol.hxx:59
size_t size() const
Definition: docary.hxx:87
const SwDoc * getDoc() const
Definition: xmlimp.cxx:1670
SvXMLImportContext * CreateStylesContext(bool bAuto)
Definition: xmlfmt.cxx:971
void UpdateTextCollConditions(SwDoc *pDoc)
Definition: xmlfmt.cxx:1006
SfxStyleFamily GetStyleFamilyMask() const
Definition: xmlimp.hxx:136
bool IsBlockMode() const
Definition: xmlimp.hxx:139
SvXMLImportContext * CreateMasterStylesContext()
Definition: xmlfmt.cxx:983
void InsertStyles(bool bAuto)
Definition: xmlfmt.cxx:992
bool IsInsertMode() const
Definition: xmlimp.hxx:137
bool FindAutomaticStyle(XmlStyleFamily nFamily, const OUString &rName, const SfxItemSet **ppItemSet) const
Definition: xmlfmt.cxx:1041
bool IsStylesOnlyMode() const
Definition: xmlimp.hxx:138
void FinishStyles()
Definition: xmlfmt.cxx:1000
virtual void FillPropertySet(const css::uno::Reference< css::beans::XPropertySet > &rPropSet)
XMLPropStyleContext(SvXMLImport &rImport, SvXMLStylesContext &rStyles, XmlStyleFamily nFamily, bool bDefaultStyle=false)
virtual css::uno::Reference< css::style::XStyle > Create()
virtual void SetAttribute(sal_Int32 nElement, const OUString &rValue) override
static SvXMLImportPropertyMapper * CreateTableRowDefaultExtPropMapper(SvXMLImport &)
static SvXMLImportPropertyMapper * CreateTableCellExtPropMapper(SvXMLImport &)
static SvXMLImportPropertyMapper * CreateDrawingPageExtPropMapper(SvXMLImport &)
static SvXMLImportPropertyMapper * CreateTableDefaultExtPropMapper(SvXMLImport &)
virtual bool InsertStyleFamily(XmlStyleFamily nFamily) const override
virtual void Finish(bool bOverwrite) override
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &AttrList) override
SvtBroadcaster & GetNotifier()
Definition: calbck.hxx:102
int nCount
#define TOOLS_WARN_EXCEPTION(area, stream)
virtual OUString GetName() const override
Reference< XSingleServiceFactory > xFactory
XmlStyleFamily
size_t m_nPos
Master_CollCondition
Conditional styles.
Definition: fmtcol.hxx:193
std::vector< std::unique_ptr< SwCollCondition > > SwFormatCollConditions
Definition: fmtcol.hxx:235
constexpr TypedWhichId< SwFormatPageDesc > RES_PAGEDESC(93)
constexpr TypedWhichId< SwConditionTextFormatColl > RES_CONDTXTFMTCOLL(160)
WhichRangesContainer const aTableSetRange(svl::Items< RES_FILL_ORDER, RES_FRM_SIZE, RES_LR_SPACE, RES_BREAK, RES_HORI_ORIENT, RES_HORI_ORIENT, RES_BACKGROUND, RES_SHADOW, RES_KEEP, RES_KEEP, RES_LAYOUT_SPLIT, RES_LAYOUT_SPLIT, RES_FRAMEDIR, RES_FRAMEDIR, RES_COLLAPSING_BORDERS, RES_COLLAPSING_BORDERS, RES_FRMATR_GRABBAG, RES_FRMATR_GRABBAG, RES_UNKNOWNATR_BEGIN, RES_UNKNOWNATR_END-1 >)
WhichRangesContainer const aTableLineSetRange(svl::Items< RES_FILL_ORDER, RES_FRM_SIZE, RES_LR_SPACE, RES_UL_SPACE, RES_PRINT, RES_PRINT, RES_PROTECT, RES_PROTECT, RES_VERT_ORIENT, RES_VERT_ORIENT, RES_BACKGROUND, RES_SHADOW, RES_ROW_SPLIT, RES_ROW_SPLIT, RES_FRMATR_GRABBAG, RES_FRMATR_GRABBAG, RES_UNKNOWNATR_BEGIN, RES_UNKNOWNATR_END-1 >)
WhichRangesContainer const aTableBoxSetRange(svl::Items< RES_FILL_ORDER, RES_FRM_SIZE, RES_LR_SPACE, RES_UL_SPACE, RES_PROTECT, RES_PROTECT, RES_VERT_ORIENT, RES_VERT_ORIENT, RES_BACKGROUND, RES_SHADOW, RES_FRAMEDIR, RES_FRAMEDIR, RES_FRMATR_GRABBAG, RES_FRMATR_GRABBAG, RES_BOXATR_BEGIN, RES_BOXATR_END-1, RES_UNKNOWNATR_BEGIN, RES_UNKNOWNATR_END-1 >)
sal_Int32 nIndex
Sequence< sal_Int8 > aSeq
#define SAL_WARN(area, stream)
const char * sName
const SfxItemSet * GetItemSet(const SfxPoolItem &rAttr)
Returns the item set associated with a character/inet/auto style.
Definition: atrstck.cxx:133
double getLength(const B2DPolygon &rCandidate)
int i
void Create(SwFormatVertOrient &rItem, SvStream &rStrm, sal_uInt16 nVersionAbusedAsSize)
Definition: legacyitem.cxx:32
enumrange< T >::Iterator begin(enumrange< T >)
end
FastAttributeList & castToFastAttributeList(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
XML_TABLE_CELL_PROPERTIES
XML_TABLE_COLUMN_PROPERTIES
XML_PARAGRAPH_PROPERTIES
XML_TABLE_ROW_PROPERTIES
bool IsXMLToken(std::u16string_view rString, enum XMLTokenEnum eToken)
const OUString & GetXMLToken(enum XMLTokenEnum eToken)
sal_Int32 mnIndex
SfxStyleFamily
constexpr sal_uInt8 MAXLEVEL
Definition: swtypes.hxx:92
sal_uInt16 sal_Unicode
#define UNO_NAME_PARA_STYLE_CONDITIONS
Definition: unoprnms.hxx:783
std::vector< rtl::Reference< SwXMLConditionContext_Impl > > SwXMLConditions_Impl
Definition: xmlfmt.cxx:253
#define XMLOFF_WARN_UNKNOWN_ELEMENT(area, token)
#define XMLOFF_WARN_UNKNOWN(area, rIter)
#define XML_ELEMENT(prefix, name)