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/nmspmap.hxx>
22 #include <xmloff/xmlnmspe.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/style/XStyle.hpp>
30 #include <xmloff/xmlnumi.hxx>
31 #include "XMLTextListItemContext.hxx"
34 using namespace ::com::sun::star
;
35 using namespace ::com::sun::star::uno
;
36 using namespace ::xmloff::token
;
38 TYPEINIT1( XMLTextListItemContext
, SvXMLImportContext
);
40 XMLTextListItemContext::XMLTextListItemContext(
42 XMLTextImportHelper
& rTxtImp
,
43 const sal_uInt16 nPrfx
,
44 const OUString
& rLName
,
45 const Reference
< xml::sax::XAttributeList
> & xAttrList
,
46 const bool bIsHeader
)
47 : SvXMLImportContext( rImport
, nPrfx
, rLName
),
48 rTxtImport( rTxtImp
),
53 static const char s_NumberingRules
[] = "NumberingRules";
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
= (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( XML_STYLE_FAMILY_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(s_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
) )
112 //FIXME: there is no UNO API for list items
116 // If this is a <text:list-item> element, then remember it as a sign
117 // that a bullet has to be generated.
119 rTxtImport
.GetTextListHelper().SetListItem( this );
124 XMLTextListItemContext::~XMLTextListItemContext()
128 void XMLTextListItemContext::EndElement()
130 // finish current list item
131 rTxtImport
.GetTextListHelper().SetListItem( 0 );
134 SvXMLImportContext
*XMLTextListItemContext::CreateChildContext(
136 const OUString
& rLocalName
,
137 const Reference
< xml::sax::XAttributeList
> & xAttrList
)
139 SvXMLImportContext
*pContext
= 0;
141 const SvXMLTokenMap
& rTokenMap
= rTxtImport
.GetTextElemTokenMap();
142 bool bHeading
= false;
143 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) );
165 pContext
= new SvXMLImportContext( GetImport(), nPrefix
, rLocalName
);
170 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */