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"
36 using namespace ::com::sun::star
;
37 using namespace ::com::sun::star::uno
;
38 using namespace ::xmloff::token
;
41 XMLTextListItemContext::XMLTextListItemContext(
43 XMLTextImportHelper
& rTxtImp
,
44 const sal_uInt16 nPrfx
,
45 const OUString
& rLName
,
46 const Reference
< xml::sax::XAttributeList
> & xAttrList
,
47 const bool bIsHeader
)
48 : SvXMLImportContext( rImport
, nPrfx
, rLName
),
49 rTxtImport( rTxtImp
),
54 sal_Int16 nAttrCount
= xAttrList
.is() ? xAttrList
->getLength() : 0;
55 for( sal_Int16 i
=0; i
< nAttrCount
; i
++ )
57 const OUString
& rAttrName
= xAttrList
->getNameByIndex( i
);
58 const OUString
& rValue
= xAttrList
->getValueByIndex( i
);
62 GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName
,
64 if( !bIsHeader
&& XML_NAMESPACE_TEXT
== nPrefix
&&
65 IsXMLToken( aLocalName
, XML_START_VALUE
) )
67 sal_Int32 nTmp
= rValue
.toInt32();
68 if( nTmp
>= 0 && nTmp
<= SHRT_MAX
)
69 nStartValue
= static_cast<sal_Int16
>(nTmp
);
71 else if ( nPrefix
== XML_NAMESPACE_TEXT
&&
72 IsXMLToken( aLocalName
, XML_STYLE_OVERRIDE
) )
74 const OUString
& sListStyleOverrideName
= rValue
;
75 if ( !sListStyleOverrideName
.isEmpty() )
77 OUString
sDisplayStyleName(
78 GetImport().GetStyleDisplayName( XmlStyleFamily::TEXT_LIST
,
79 sListStyleOverrideName
) );
80 const Reference
< container::XNameContainer
>& rNumStyles
=
81 rTxtImp
.GetNumberingStyles();
82 if( rNumStyles
.is() && rNumStyles
->hasByName( sDisplayStyleName
) )
84 Reference
< style::XStyle
> xStyle
;
85 Any aAny
= rNumStyles
->getByName( sDisplayStyleName
);
88 uno::Reference
< beans::XPropertySet
> xPropSet( xStyle
, UNO_QUERY
);
89 aAny
= xPropSet
->getPropertyValue("NumberingRules");
90 aAny
>>= mxNumRulesOverride
;
94 const SvxXMLListStyleContext
* pListStyle
=
95 rTxtImp
.FindAutoListStyle( sListStyleOverrideName
);
98 mxNumRulesOverride
= pListStyle
->GetNumRules();
99 if( !mxNumRulesOverride
.is() )
101 pListStyle
->CreateAndInsertAuto();
102 mxNumRulesOverride
= pListStyle
->GetNumRules();
108 else if ( (XML_NAMESPACE_XML
== nPrefix
) &&
109 IsXMLToken(aLocalName
, XML_ID
) )
111 //FIXME: there is no UNO API for list items
115 // If this is a <text:list-item> element, then remember it as a sign
116 // that a bullet has to be generated.
118 rTxtImport
.GetTextListHelper().SetListItem( this );
123 XMLTextListItemContext::~XMLTextListItemContext()
127 void XMLTextListItemContext::endFastElement(sal_Int32
)
129 // finish current list item
130 rTxtImport
.GetTextListHelper().SetListItem( nullptr );
133 SvXMLImportContextRef
XMLTextListItemContext::CreateChildContext(
135 const OUString
& rLocalName
,
136 const Reference
< xml::sax::XAttributeList
> & xAttrList
)
138 SvXMLImportContext
*pContext
= nullptr;
140 const SvXMLTokenMap
& rTokenMap
= rTxtImport
.GetTextElemTokenMap();
141 bool bHeading
= false;
142 switch( rTokenMap
.Get( nPrefix
, rLocalName
) )
148 pContext
= new XMLParaContext( GetImport(),
150 xAttrList
, bHeading
);
151 if (rTxtImport
.IsProgress())
152 GetImport().GetProgressBarHelper()->Increment();
155 case XML_TOK_TEXT_LIST
:
157 pContext
= new XMLTextListBlockContext( GetImport(), rTxtImport
,
160 (mnSubListCount
> 1) );
167 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */