1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: txtlists.hxx,v $
10 * $Revision: 1.2.24.2 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef _XMLOFF_TXTLISTS_HXX
32 #define _XMLOFF_TXTLISTS_HXX
34 #include <rtl/ustring.hxx>
35 #include <comphelper/stl_types.hxx>
39 #include <boost/utility.hpp>
40 #include <boost/tuple/tuple.hpp>
41 #include <com/sun/star/container/XIndexReplace.hpp>
42 #include <xmloff/xmlictxt.hxx>
45 class XMLTextListBlockContext
;
46 class XMLTextListItemContext
;
47 class XMLNumberedParaContext
;
49 class XMLTextListsHelper
: private boost::noncopyable
53 ~XMLTextListsHelper();
55 /// list stack for importing:
57 /// push a list context on the list context stack
58 void PushListContext(XMLTextListBlockContext
*i_pListBlock
= 0);
59 void PushListContext(XMLNumberedParaContext
*i_pNumberedParagraph
);
60 /// pop the list context stack
61 void PopListContext();
62 /// peek at the top of the list context stack
63 void ListContextTop(XMLTextListBlockContext
*& o_pListBlockContext
,
64 XMLTextListItemContext
*& o_pListItemContext
,
65 XMLNumberedParaContext
*& o_pNumberedParagraphContext
);
66 /// set list item on top of the list context stack
67 void SetListItem( XMLTextListItemContext
*pListItem
);
70 // keeping track of processed lists for import and export
71 // --> OD 2008-08-15 #i92811#
72 // - add optional parameter <sListStyleDefaultListId>
73 void KeepListAsProcessed( ::rtl::OUString sListId
,
74 ::rtl::OUString sListStyleName
,
75 ::rtl::OUString sContinueListId
,
76 ::rtl::OUString sListStyleDefaultListId
= ::rtl::OUString() );
79 sal_Bool
IsListProcessed( const ::rtl::OUString sListId
) const;
80 ::rtl::OUString
GetListStyleOfProcessedList(
81 const ::rtl::OUString sListId
) const;
82 ::rtl::OUString
GetContinueListIdOfProcessedList(
83 const ::rtl::OUString sListId
) const;
84 const ::rtl::OUString
& GetLastProcessedListId() const;
85 const ::rtl::OUString
& GetListStyleOfLastProcessedList() const;
87 ::rtl::OUString
GenerateNewListId() const;
89 // --> OD 2008-08-15 #i92811#
90 // provide list id for a certain list block for import
91 ::rtl::OUString
GetListIdForListBlock( XMLTextListBlockContext
& rListBlock
);
95 // keep track of continue list chain for export
96 void StoreLastContinuingList( ::rtl::OUString sListId
,
97 ::rtl::OUString sContinuingListId
);
99 ::rtl::OUString
GetLastContinuingListId( ::rtl::OUString sListId
) const;
101 // keep track of opened list elements of a certain list for export
102 void PushListOnStack( ::rtl::OUString sListId
,
103 ::rtl::OUString sListStyleName
);
104 void PopListFromStack();
105 sal_Bool
EqualsToTopListStyleOnStack( const ::rtl::OUString sListId
) const;
107 /** for importing numbered-paragraph
108 note that the ID namespace for numbered-paragraph and regular list
109 is distinct; we never combine a list and a n-p
111 ::com::sun::star::uno::Reference
<
112 ::com::sun::star::container::XIndexReplace
>
113 EnsureNumberedParagraph(
114 SvXMLImport
& i_rImport
,
115 const ::rtl::OUString i_ListId
,
116 sal_Int16
& io_rLevel
, const ::rtl::OUString i_StyleName
);
118 /// get ID of the last numbered-paragraph iff it has given style-name
119 ::rtl::OUString
GetNumberedParagraphListId(
120 const sal_uInt16 i_Level
,
121 const ::rtl::OUString i_StyleName
);
123 /** Creates a NumRule from given style-name.
124 @param i_rImport the SvXMLImport
125 @param i_xNumRule parent num rule
126 @param i_ParentStyleName parent list style name
127 @param i_StyleName the list style name
128 @param io_rLevel the list level (may be reset if too large)
129 @param o_rRestartNumbering set to true if no style (defaulting)
130 @param io_rSetDefaults set to true if no style (defaulting)
132 static ::com::sun::star::uno::Reference
<
133 ::com::sun::star::container::XIndexReplace
> MakeNumRule(
134 SvXMLImport
& i_rImport
,
135 const ::com::sun::star::uno::Reference
<
136 ::com::sun::star::container::XIndexReplace
>& i_xNumRule
,
137 const ::rtl::OUString i_ParentStyleName
,
138 const ::rtl::OUString i_StyleName
,
139 sal_Int16
& io_rLevel
,
140 sal_Bool
* o_pRestartNumbering
= 0,
141 sal_Bool
* io_pSetDefaults
= 0);
145 /** list context: list, list-item, numbered-paragraph
146 XMLTextListBlockContext, XMLTextListItemContext,
147 XMLNumberedParaContext
149 typedef ::boost::tuple
<SvXMLImportContextRef
,
150 SvXMLImportContextRef
, SvXMLImportContextRef
> ListStackFrame_t
;
151 ::std::stack
< ListStackFrame_t
> mListStack
;
153 // container type for processed lists:
154 // map with <ListId> as key and pair( <ListStyleName, ContinueListId> )
156 typedef ::std::map
< ::rtl::OUString
,
157 ::std::pair
< ::rtl::OUString
, ::rtl::OUString
>,
158 ::comphelper::UStringLess
> tMapForLists
;
159 tMapForLists
* mpProcessedLists
;
160 ::rtl::OUString msLastProcessedListId
;
161 ::rtl::OUString msListStyleOfLastProcessedList
;
163 // --> OD 2008-08-15 #i92811#
164 // additional container for processed lists.
165 // map with <ListStyleName> as key and pair( <ListId, ListStyleDefaultListId> )
167 tMapForLists
* mpMapListIdToListStyleDefaultListId
;
170 // container type to build up continue list chain:
171 // map with <ListId> of master list as key and <ListId> of last list
172 // continuing the master list as value
173 typedef ::std::map
< ::rtl::OUString
, ::rtl::OUString
,
174 ::comphelper::UStringLess
> tMapForContinuingLists
;
175 tMapForContinuingLists
* mpContinuingLists
;
177 // stack type for opened list elements and its list style:
178 // vector with pair( <ListId>, <ListStyleName> ) as value
179 typedef ::std::vector
< ::std::pair
< ::rtl::OUString
, ::rtl::OUString
> >
181 tStackForLists
* mpListStack
;
183 /// to connect numbered-paragraphs that have no list-id attribute:
184 /// vector of pair of style-name and list-id (indexed by level)
185 typedef ::std::vector
< ::std::pair
< ::rtl::OUString
, ::rtl::OUString
> >
186 LastNumberedParagraphs_t
;
188 LastNumberedParagraphs_t mLastNumberedParagraphs
;
190 /// numbered-paragraphs
191 typedef ::std::vector
< ::std::pair
< ::rtl::OUString
,
192 ::com::sun::star::uno::Reference
<
193 ::com::sun::star::container::XIndexReplace
> > > NumParaList_t
;
194 ::std::map
< ::rtl::OUString
, NumParaList_t
> mNPLists
;