1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <xmloff/xmlimp.hxx>
21 #include <xmloff/namespacemap.hxx>
22 #include <xmloff/xmlnamespace.hxx>
23 #include <xmloff/xmltoken.hxx>
24 #include "txtparai.hxx"
25 #include <txtlists.hxx>
26 #include "XMLTextListBlockContext.hxx"
27 #include <xmloff/txtimp.hxx>
28 #include <com/sun/star/container/XNameContainer.hpp>
29 #include <com/sun/star/beans/XPropertySet.hpp>
30 #include <com/sun/star/style/XStyle.hpp>
31 #include <xmloff/xmlnumi.hxx>
32 #include <xmloff/ProgressBarHelper.hxx>
33 #include "XMLTextListItemContext.hxx"
34 #include <sal/log.hxx>
37 using namespace ::com::sun::star
;
38 using namespace ::com::sun::star::uno
;
39 using namespace ::xmloff::token
;
42 XMLTextListItemContext::XMLTextListItemContext(
44 XMLTextImportHelper
& rTxtImp
,
45 const Reference
< xml::sax::XFastAttributeList
> & xAttrList
,
46 const bool bIsHeader
)
47 : SvXMLImportContext( rImport
),
48 rTxtImport( rTxtImp
),
52 for( auto& aIter
: sax_fastparser::castToFastAttributeList(xAttrList
) )
54 if( !bIsHeader
&& aIter
.getToken() == XML_ELEMENT(TEXT
, XML_START_VALUE
) )
56 sal_Int32 nTmp
= aIter
.toInt32();
57 if( nTmp
>= 0 && nTmp
<= SHRT_MAX
)
58 nStartValue
= static_cast<sal_Int16
>(nTmp
);
60 else if ( aIter
.getToken() == XML_ELEMENT(TEXT
, XML_STYLE_OVERRIDE
) )
62 OUString sListStyleOverrideName
= aIter
.toString();
63 if ( !sListStyleOverrideName
.isEmpty() )
65 OUString
sDisplayStyleName(
66 GetImport().GetStyleDisplayName( XmlStyleFamily::TEXT_LIST
,
67 sListStyleOverrideName
) );
68 const Reference
< container::XNameContainer
>& rNumStyles
=
69 rTxtImp
.GetNumberingStyles();
70 if( rNumStyles
.is() && rNumStyles
->hasByName( sDisplayStyleName
) )
72 Reference
< style::XStyle
> xStyle
;
73 Any aAny
= rNumStyles
->getByName( sDisplayStyleName
);
76 uno::Reference
< beans::XPropertySet
> xPropSet( xStyle
, UNO_QUERY
);
77 aAny
= xPropSet
->getPropertyValue("NumberingRules");
78 aAny
>>= mxNumRulesOverride
;
82 const SvxXMLListStyleContext
* pListStyle
=
83 rTxtImp
.FindAutoListStyle( sListStyleOverrideName
);
86 mxNumRulesOverride
= pListStyle
->GetNumRules();
87 if( !mxNumRulesOverride
.is() )
89 pListStyle
->CreateAndInsertAuto();
90 mxNumRulesOverride
= pListStyle
->GetNumRules();
96 else if ( aIter
.getToken() == XML_ELEMENT(XML
, XML_ID
) )
98 //FIXME: there is no UNO API for list items
101 XMLOFF_WARN_UNKNOWN("xmloff", aIter
);
104 // If this is a <text:list-item> element, then remember it as a sign
105 // that a bullet has to be generated.
107 rTxtImport
.GetTextListHelper().SetListItem( this );
112 XMLTextListItemContext::~XMLTextListItemContext()
116 void XMLTextListItemContext::endFastElement(sal_Int32
)
118 // finish current list item
119 rTxtImport
.GetTextListHelper().SetListItem( nullptr );
122 css::uno::Reference
< css::xml::sax::XFastContextHandler
> XMLTextListItemContext::createFastChildContext(
124 const css::uno::Reference
< css::xml::sax::XFastAttributeList
>& xAttrList
)
126 SvXMLImportContext
*pContext
= nullptr;
130 case XML_ELEMENT(TEXT
, XML_H
):
131 case XML_ELEMENT(TEXT
, XML_P
):
132 case XML_ELEMENT(LO_EXT
, XML_P
):
133 pContext
= new XMLParaContext( GetImport(), nElement
,
135 if (rTxtImport
.IsProgress())
136 GetImport().GetProgressBarHelper()->Increment();
139 case XML_ELEMENT(TEXT
, XML_LIST
):
141 pContext
= new XMLTextListBlockContext( GetImport(), rTxtImport
,
143 (mnSubListCount
> 1) );
146 XMLOFF_WARN_UNKNOWN_ELEMENT("xmloff", nElement
);
152 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */