LibreOffice Module xmloff (master)  1
txtlists.hxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  * Licensed to the Apache Software Foundation (ASF) under one or more
12  * contributor license agreements. See the NOTICE file distributed
13  * with this work for additional information regarding copyright
14  * ownership. The ASF licenses this file to you under the Apache
15  * License, Version 2.0 (the "License"); you may not use this file
16  * except in compliance with the License. You may obtain a copy of
17  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #ifndef INCLUDED_XMLOFF_INC_TXTLISTS_HXX
21 #define INCLUDED_XMLOFF_INC_TXTLISTS_HXX
22 
23 #include <rtl/ustring.hxx>
24 #include <map>
25 #include <memory>
26 #include <stack>
27 #include <tuple>
28 #include <vector>
29 #include <com/sun/star/container/XIndexReplace.hpp>
30 #include <xmloff/xmlictxt.hxx>
31 
32 class SvXMLImport;
36 
38 {
39  public:
41  XMLTextListsHelper(const XMLTextListsHelper&) = delete;
43 
45 
47  void PushListContext(XMLTextListBlockContext *i_pListBlock);
48  void PushListContext(XMLNumberedParaContext *i_pNumberedParagraph);
50  void PopListContext();
52  void ListContextTop(XMLTextListBlockContext*& o_pListBlockContext,
53  XMLTextListItemContext*& o_pListItemContext,
54  XMLNumberedParaContext*& o_pNumberedParagraphContext );
56  void SetListItem( XMLTextListItemContext *pListItem );
57 
58 
59  // keeping track of processed lists for import and export
60  // Add optional parameter <sListStyleDefaultListId> (#i92811#)
61  void KeepListAsProcessed( const OUString& sListId,
62  const OUString& sListStyleName,
63  const OUString& sContinueListId,
64  const OUString& sListStyleDefaultListId = OUString() );
65 
66  bool IsListProcessed( const OUString& sListId ) const;
68  const OUString& sListId ) const;
70  const OUString& sListId ) const;
71  const OUString& GetLastProcessedListId() const { return msLastProcessedListId;}
73 
74  OUString GenerateNewListId() const;
75 
76  // Provide list id for a certain list block for import (#i92811#)
77  OUString GetListIdForListBlock( XMLTextListBlockContext const & rListBlock );
78 
79  // keep track of continue list chain for export
80  void StoreLastContinuingList( const OUString& sListId,
81  const OUString& sContinuingListId );
82 
83  OUString GetLastContinuingListId( const OUString& sListId ) const;
84 
85  // keep track of opened list elements of a certain list for export
86  void PushListOnStack( const OUString& sListId,
87  const OUString& sListStyleName );
88  void PopListFromStack();
89  bool EqualsToTopListStyleOnStack( const OUString& sListId ) const;
90 
95  css::uno::Reference< css::container::XIndexReplace>
97  SvXMLImport & i_rImport,
98  const OUString& i_ListId,
99  sal_Int16 & io_rLevel, const OUString& i_StyleName);
100 
103  const sal_uInt16 i_Level,
104  const OUString& i_StyleName);
105 
115  static css::uno::Reference< css::container::XIndexReplace> MakeNumRule(
116  SvXMLImport & i_rImport,
117  const css::uno::Reference< css::container::XIndexReplace>& i_xNumRule,
118  const OUString& i_ParentStyleName,
119  const OUString& i_StyleName,
120  sal_Int16 & io_rLevel,
121  bool* o_pRestartNumbering = nullptr,
122  bool* io_pSetDefaults = nullptr);
123 
124  private:
125 
130  typedef std::tuple<SvXMLImportContextRef,
131  SvXMLImportContextRef, SvXMLImportContextRef> ListStackFrame_t;
132  std::stack< ListStackFrame_t > mListStack;
133 
134  // container type for processed lists:
135  // map with <ListId> as key and pair( <ListStyleName, ContinueListId> )
136  // as value
137  typedef ::std::map< OUString,
138  ::std::pair< OUString, OUString > > tMapForLists;
139  std::unique_ptr<tMapForLists> mpProcessedLists;
142 
143  /* additional container for processed lists.
144  map with <ListStyleName> as key and pair( <ListId, ListStyleDefaultListId> )
145  as value. (#i92811#)
146  */
147  std::unique_ptr<tMapForLists> mpMapListIdToListStyleDefaultListId;
148 
149  // container type to build up continue list chain:
150  // map with <ListId> of master list as key and <ListId> of last list
151  // continuing the master list as value
152  typedef ::std::map< OUString, OUString > tMapForContinuingLists;
153  std::unique_ptr<tMapForContinuingLists> mpContinuingLists;
154 
155  // stack type for opened list elements and its list style:
156  // vector with pair( <ListId>, <ListStyleName> ) as value
157  typedef ::std::vector< ::std::pair< OUString, OUString > >
159  std::unique_ptr<tStackForLists> mpListStack;
160 
163  typedef ::std::vector< ::std::pair< OUString, OUString > >
165 
167 
169  typedef ::std::vector<
170  ::std::pair<
171  OUString,
172  css::uno::Reference< css::container::XIndexReplace > > > NumParaList_t;
173  ::std::map< OUString, NumParaList_t > mNPLists;
174 
175 };
176 #endif
177 
178 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::unique_ptr< tMapForLists > mpMapListIdToListStyleDefaultListId
Definition: txtlists.hxx:147
std::stack< ListStackFrame_t > mListStack
Definition: txtlists.hxx:132
LastNumberedParagraphs_t mLastNumberedParagraphs
Definition: txtlists.hxx:166
::std::vector< ::std::pair< OUString, OUString > > LastNumberedParagraphs_t
to connect numbered-paragraphs that have no list-id attribute: vector of pair of style-name and list-...
Definition: txtlists.hxx:164
void StoreLastContinuingList(const OUString &sListId, const OUString &sContinuingListId)
Definition: txtlists.cxx:255
OUString GetListStyleOfProcessedList(const OUString &sListId) const
Definition: txtlists.cxx:158
::std::vector< ::std::pair< OUString, OUString > > tStackForLists
Definition: txtlists.hxx:158
std::unique_ptr< tStackForLists > mpListStack
Definition: txtlists.hxx:159
XMLTextListsHelper & operator=(const XMLTextListsHelper &)=delete
OUString msListStyleOfLastProcessedList
Definition: txtlists.hxx:141
OUString GenerateNewListId() const
Definition: txtlists.cxx:189
OUString GetContinueListIdOfProcessedList(const OUString &sListId) const
Definition: txtlists.cxx:173
void ListContextTop(XMLTextListBlockContext *&o_pListBlockContext, XMLTextListItemContext *&o_pListItemContext, XMLNumberedParaContext *&o_pNumberedParagraphContext)
peek at the top of the list context stack
Definition: txtlists.cxx:74
static css::uno::Reference< css::container::XIndexReplace > MakeNumRule(SvXMLImport &i_rImport, const css::uno::Reference< css::container::XIndexReplace > &i_xNumRule, const OUString &i_ParentStyleName, const OUString &i_StyleName, sal_Int16 &io_rLevel, bool *o_pRestartNumbering=nullptr, bool *io_pSetDefaults=nullptr)
Creates a NumRule from given style-name.
Definition: txtlists.cxx:402
const OUString & GetLastProcessedListId() const
Definition: txtlists.hxx:71
void KeepListAsProcessed(const OUString &sListId, const OUString &sListStyleName, const OUString &sContinueListId, const OUString &sListStyleDefaultListId=OUString())
Definition: txtlists.cxx:105
void PopListFromStack()
Definition: txtlists.cxx:293
void PushListOnStack(const OUString &sListId, const OUString &sListStyleName)
Definition: txtlists.cxx:282
OUString GetLastContinuingListId(const OUString &sListId) const
Definition: txtlists.cxx:266
::std::map< OUString, OUString > tMapForContinuingLists
Definition: txtlists.hxx:152
bool EqualsToTopListStyleOnStack(const OUString &sListId) const
Definition: txtlists.cxx:302
css::uno::Reference< css::container::XIndexReplace > EnsureNumberedParagraph(SvXMLImport &i_rImport, const OUString &i_ListId, sal_Int16 &io_rLevel, const OUString &i_StyleName)
for importing numbered-paragraph note that the ID namespace for numbered-paragraph and regular list i...
Definition: txtlists.cxx:341
std::unique_ptr< tMapForContinuingLists > mpContinuingLists
Definition: txtlists.hxx:153
void PushListContext(XMLTextListBlockContext *i_pListBlock)
list stack for importing:
Definition: txtlists.cxx:51
::std::map< OUString, NumParaList_t > mNPLists
Definition: txtlists.hxx:173
OUString msLastProcessedListId
Definition: txtlists.hxx:140
::std::map< OUString,::std::pair< OUString, OUString > > tMapForLists
Definition: txtlists.hxx:138
rtl::Reference< SvXMLImportContext > SvXMLImportContextRef
Definition: xmlictxt.hxx:37
void SetListItem(XMLTextListItemContext *pListItem)
set list item on top of the list context stack
Definition: txtlists.cxx:89
void PopListContext()
pop the list context stack
Definition: txtlists.cxx:67
OUString GetNumberedParagraphListId(const sal_uInt16 i_Level, const OUString &i_StyleName)
get ID of the last numbered-paragraph iff it has given style-name
Definition: txtlists.cxx:308
::std::vector< ::std::pair< OUString, css::uno::Reference< css::container::XIndexReplace > > > NumParaList_t
numbered-paragraphs
Definition: txtlists.hxx:172
std::unique_ptr< tMapForLists > mpProcessedLists
Definition: txtlists.hxx:139
std::tuple< SvXMLImportContextRef, SvXMLImportContextRef, SvXMLImportContextRef > ListStackFrame_t
list context: list, list-item, numbered-paragraph XMLTextListBlockContext, XMLTextListItemContext, XMLNumberedParaContext
Definition: txtlists.hxx:131
OUString GetListIdForListBlock(XMLTextListBlockContext const &rListBlock)
Definition: txtlists.cxx:225
bool IsListProcessed(const OUString &sListId) const
Definition: txtlists.cxx:148
const OUString & GetListStyleOfLastProcessedList() const
Definition: txtlists.hxx:72