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