xref: /aoo4110/main/xmloff/inc/txtlists.hxx (revision b1cdbd2c)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _XMLOFF_TXTLISTS_HXX
25 #define _XMLOFF_TXTLISTS_HXX
26 
27 #include <rtl/ustring.hxx>
28 #include <comphelper/stl_types.hxx>
29 #include <map>
30 #include <vector>
31 #include <stack>
32 #include <boost/utility.hpp>
33 #include <boost/tuple/tuple.hpp>
34 #include <com/sun/star/container/XIndexReplace.hpp>
35 #include <xmloff/xmlictxt.hxx>
36 
37 class SvXMLImport;
38 class XMLTextListBlockContext;
39 class XMLTextListItemContext;
40 class XMLNumberedParaContext;
41 
42 class XMLTextListsHelper : private boost::noncopyable
43 {
44     public:
45         XMLTextListsHelper();
46         ~XMLTextListsHelper();
47 
48         /// list stack for importing:
49 
50         /// push a list context on the list context stack
51         void PushListContext(XMLTextListBlockContext *i_pListBlock = 0);
52         void PushListContext(XMLNumberedParaContext *i_pNumberedParagraph);
53         /// pop the list context stack
54         void PopListContext();
55         /// peek at the top of the list context stack
56         void ListContextTop(XMLTextListBlockContext*& o_pListBlockContext,
57             XMLTextListItemContext*& o_pListItemContext,
58             XMLNumberedParaContext*& o_pNumberedParagraphContext );
59         /// set list item on top of the list context stack
60         void SetListItem( XMLTextListItemContext *pListItem );
61 
62 
63         // keeping track of processed lists for import and export
64         // --> OD 2008-08-15 #i92811#
65         // - add optional parameter <sListStyleDefaultListId>
66         void KeepListAsProcessed( ::rtl::OUString sListId,
67                                   ::rtl::OUString sListStyleName,
68                                   ::rtl::OUString sContinueListId,
69                                   ::rtl::OUString sListStyleDefaultListId = ::rtl::OUString() );
70         // <--
71 
72         sal_Bool IsListProcessed( const ::rtl::OUString sListId ) const;
73         ::rtl::OUString GetListStyleOfProcessedList(
74                                         const ::rtl::OUString sListId ) const;
75         ::rtl::OUString GetContinueListIdOfProcessedList(
76                                         const ::rtl::OUString sListId ) const;
77         const ::rtl::OUString& GetLastProcessedListId() const;
78         const ::rtl::OUString& GetListStyleOfLastProcessedList() const;
79 
80         ::rtl::OUString GenerateNewListId() const;
81 
82         // --> OD 2008-08-15 #i92811#
83         // provide list id for a certain list block for import
84         ::rtl::OUString GetListIdForListBlock( XMLTextListBlockContext& rListBlock );
85         // <--
86 
87 
88         // keep track of continue list chain for export
89         void StoreLastContinuingList( ::rtl::OUString sListId,
90                                       ::rtl::OUString sContinuingListId );
91 
92         ::rtl::OUString GetLastContinuingListId( ::rtl::OUString sListId ) const;
93 
94         // keep track of opened list elements of a certain list for export
95         void PushListOnStack( ::rtl::OUString sListId,
96                               ::rtl::OUString sListStyleName );
97         void PopListFromStack();
98         sal_Bool EqualsToTopListStyleOnStack( const ::rtl::OUString sListId ) const;
99 
100         /** for importing numbered-paragraph
101             note that the ID namespace for numbered-paragraph and regular list
102             is distinct; we never combine a list and a n-p
103          */
104         ::com::sun::star::uno::Reference<
105                 ::com::sun::star::container::XIndexReplace>
106         EnsureNumberedParagraph(
107             SvXMLImport & i_rImport,
108             const ::rtl::OUString i_ListId,
109             sal_Int16 & io_rLevel, const ::rtl::OUString i_StyleName);
110 
111         /// get ID of the last numbered-paragraph iff it has given style-name
112         ::rtl::OUString GetNumberedParagraphListId(
113             const sal_uInt16 i_Level,
114             const ::rtl::OUString i_StyleName);
115 
116         /** Creates a NumRule from given style-name.
117             @param i_rImport        the SvXMLImport
118             @param i_xNumRule       parent num rule
119             @param i_ParentStyleName  parent list style name
120             @param i_StyleName      the list style name
121             @param io_rLevel        the list level (may be reset if too large)
122             @param o_rRestartNumbering   set to true if no style (defaulting)
123             @param io_rSetDefaults  set to true if no style (defaulting)
124          */
125         static ::com::sun::star::uno::Reference<
126                 ::com::sun::star::container::XIndexReplace> MakeNumRule(
127             SvXMLImport & i_rImport,
128             const ::com::sun::star::uno::Reference<
129                 ::com::sun::star::container::XIndexReplace>& i_xNumRule,
130             const ::rtl::OUString i_ParentStyleName,
131             const ::rtl::OUString i_StyleName,
132             sal_Int16 & io_rLevel,
133             sal_Bool* o_pRestartNumbering = 0,
134             sal_Bool* io_pSetDefaults = 0);
135 
136     private:
137 
138         /** list context: list, list-item, numbered-paragraph
139             XMLTextListBlockContext, XMLTextListItemContext,
140             XMLNumberedParaContext
141          */
142         typedef ::boost::tuple<SvXMLImportContextRef,
143             SvXMLImportContextRef, SvXMLImportContextRef> ListStackFrame_t;
144         ::std::stack< ListStackFrame_t > mListStack;
145 
146         // container type for processed lists:
147         // map with <ListId> as key and pair( <ListStyleName, ContinueListId> )
148         // as value
149         typedef ::std::map< ::rtl::OUString,
150                             ::std::pair< ::rtl::OUString, ::rtl::OUString >,
151                             ::comphelper::UStringLess > tMapForLists;
152         tMapForLists* mpProcessedLists;
153         ::rtl::OUString msLastProcessedListId;
154         ::rtl::OUString msListStyleOfLastProcessedList;
155 
156         // --> OD 2008-08-15 #i92811#
157         // additional container for processed lists.
158         // map with <ListStyleName> as key and pair( <ListId, ListStyleDefaultListId> )
159         // as value.
160         tMapForLists* mpMapListIdToListStyleDefaultListId;
161         // <--
162 
163         // container type to build up continue list chain:
164         // map with <ListId> of master list as key and <ListId> of last list
165         // continuing the master list as value
166         typedef ::std::map< ::rtl::OUString, ::rtl::OUString,
167                             ::comphelper::UStringLess > tMapForContinuingLists;
168         tMapForContinuingLists* mpContinuingLists;
169 
170         // stack type for opened list elements and its list style:
171         // vector with pair( <ListId>, <ListStyleName> ) as value
172         typedef ::std::vector< ::std::pair< ::rtl::OUString, ::rtl::OUString > >
173                                                                 tStackForLists;
174         tStackForLists* mpListStack;
175 
176         /// to connect numbered-paragraphs that have no list-id attribute:
177         /// vector of pair of style-name and list-id (indexed by level)
178         typedef ::std::vector< ::std::pair< ::rtl::OUString, ::rtl::OUString > >
179             LastNumberedParagraphs_t;
180 
181         LastNumberedParagraphs_t mLastNumberedParagraphs;
182 
183         /// numbered-paragraphs
184         typedef ::std::vector< ::std::pair< ::rtl::OUString,
185             ::com::sun::star::uno::Reference<
186                 ::com::sun::star::container::XIndexReplace > > > NumParaList_t;
187         ::std::map< ::rtl::OUString, NumParaList_t > mNPLists;
188 
189 };
190 #endif
191