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 #ifndef _XMLOFF_TXTLISTS_HXX
21 #define _XMLOFF_TXTLISTS_HXX
23 #include <rtl/ustring.hxx>
24 #include <comphelper/stl_types.hxx>
28 #include <boost/utility.hpp>
29 #include <boost/tuple/tuple.hpp>
30 #include <com/sun/star/container/XIndexReplace.hpp>
31 #include <xmloff/xmlictxt.hxx>
34 class XMLTextListBlockContext
;
35 class XMLTextListItemContext
;
36 class XMLNumberedParaContext
;
38 class XMLTextListsHelper
: private boost::noncopyable
42 ~XMLTextListsHelper();
44 /// list stack for importing:
46 /// push a list context on the list context stack
47 void PushListContext(XMLTextListBlockContext
*i_pListBlock
= 0);
48 void PushListContext(XMLNumberedParaContext
*i_pNumberedParagraph
);
49 /// pop the list context stack
50 void PopListContext();
51 /// peek at the top of the list context stack
52 void ListContextTop(XMLTextListBlockContext
*& o_pListBlockContext
,
53 XMLTextListItemContext
*& o_pListItemContext
,
54 XMLNumberedParaContext
*& o_pNumberedParagraphContext
);
55 /// set list item on top of the list context stack
56 void SetListItem( XMLTextListItemContext
*pListItem
);
59 // keeping track of processed lists for import and export
60 // Add optional parameter <sListStyleDefaultListId> (#i92811#)
61 void KeepListAsProcessed( OUString sListId
,
62 OUString sListStyleName
,
63 OUString sContinueListId
,
64 OUString sListStyleDefaultListId
= OUString() );
66 sal_Bool
IsListProcessed( const OUString sListId
) const;
67 OUString
GetListStyleOfProcessedList(
68 const OUString sListId
) const;
69 OUString
GetContinueListIdOfProcessedList(
70 const OUString sListId
) const;
71 const OUString
& GetLastProcessedListId() const;
72 const OUString
& GetListStyleOfLastProcessedList() const;
74 OUString
GenerateNewListId() const;
76 // Provide list id for a certain list block for import (#i92811#)
77 OUString
GetListIdForListBlock( XMLTextListBlockContext
& rListBlock
);
79 // keep track of continue list chain for export
80 void StoreLastContinuingList( OUString sListId
,
81 OUString sContinuingListId
);
83 OUString
GetLastContinuingListId( OUString sListId
) const;
85 // keep track of opened list elements of a certain list for export
86 void PushListOnStack( OUString sListId
,
87 OUString sListStyleName
);
88 void PopListFromStack();
89 sal_Bool
EqualsToTopListStyleOnStack( const OUString sListId
) const;
91 /** for importing numbered-paragraph
92 note that the ID namespace for numbered-paragraph and regular list
93 is distinct; we never combine a list and a n-p
95 ::com::sun::star::uno::Reference
<
96 ::com::sun::star::container::XIndexReplace
>
97 EnsureNumberedParagraph(
98 SvXMLImport
& i_rImport
,
99 const OUString i_ListId
,
100 sal_Int16
& io_rLevel
, const OUString i_StyleName
);
102 /// get ID of the last numbered-paragraph iff it has given style-name
103 OUString
GetNumberedParagraphListId(
104 const sal_uInt16 i_Level
,
105 const OUString i_StyleName
);
107 /** Creates a NumRule from given style-name.
108 @param i_rImport the SvXMLImport
109 @param i_xNumRule parent num rule
110 @param i_ParentStyleName parent list style name
111 @param i_StyleName the list style name
112 @param io_rLevel the list level (may be reset if too large)
113 @param o_rRestartNumbering set to true if no style (defaulting)
114 @param io_rSetDefaults set to true if no style (defaulting)
116 static ::com::sun::star::uno::Reference
<
117 ::com::sun::star::container::XIndexReplace
> MakeNumRule(
118 SvXMLImport
& i_rImport
,
119 const ::com::sun::star::uno::Reference
<
120 ::com::sun::star::container::XIndexReplace
>& i_xNumRule
,
121 const OUString i_ParentStyleName
,
122 const OUString i_StyleName
,
123 sal_Int16
& io_rLevel
,
124 sal_Bool
* o_pRestartNumbering
= 0,
125 sal_Bool
* io_pSetDefaults
= 0);
129 /** list context: list, list-item, numbered-paragraph
130 XMLTextListBlockContext, XMLTextListItemContext,
131 XMLNumberedParaContext
133 typedef ::boost::tuple
<SvXMLImportContextRef
,
134 SvXMLImportContextRef
, SvXMLImportContextRef
> ListStackFrame_t
;
135 ::std::stack
< ListStackFrame_t
> mListStack
;
137 // container type for processed lists:
138 // map with <ListId> as key and pair( <ListStyleName, ContinueListId> )
140 typedef ::std::map
< OUString
,
141 ::std::pair
< OUString
, OUString
>,
142 ::comphelper::UStringLess
> tMapForLists
;
143 tMapForLists
* mpProcessedLists
;
144 OUString msLastProcessedListId
;
145 OUString msListStyleOfLastProcessedList
;
147 /* additional container for processed lists.
148 map with <ListStyleName> as key and pair( <ListId, ListStyleDefaultListId> )
151 tMapForLists
* mpMapListIdToListStyleDefaultListId
;
153 // container type to build up continue list chain:
154 // map with <ListId> of master list as key and <ListId> of last list
155 // continuing the master list as value
156 typedef ::std::map
< OUString
, OUString
,
157 ::comphelper::UStringLess
> tMapForContinuingLists
;
158 tMapForContinuingLists
* mpContinuingLists
;
160 // stack type for opened list elements and its list style:
161 // vector with pair( <ListId>, <ListStyleName> ) as value
162 typedef ::std::vector
< ::std::pair
< OUString
, OUString
> >
164 tStackForLists
* mpListStack
;
166 /// to connect numbered-paragraphs that have no list-id attribute:
167 /// vector of pair of style-name and list-id (indexed by level)
168 typedef ::std::vector
< ::std::pair
< OUString
, OUString
> >
169 LastNumberedParagraphs_t
;
171 LastNumberedParagraphs_t mLastNumberedParagraphs
;
173 /// numbered-paragraphs
174 typedef ::std::vector
< ::std::pair
< OUString
,
175 ::com::sun::star::uno::Reference
<
176 ::com::sun::star::container::XIndexReplace
> > > NumParaList_t
;
177 ::std::map
< OUString
, NumParaList_t
> mNPLists
;
182 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */