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