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