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 <string_view>
28 #include <tuple>
29 #include <vector>
30 #include <com/sun/star/container/XIndexReplace.hpp>
31 #include <xmloff/xmlictxt.hxx>
32 
33 class SvXMLImport;
37 
39 {
40  public:
42  XMLTextListsHelper(const XMLTextListsHelper&) = delete;
44 
46 
48  void PushListContext(XMLTextListBlockContext *i_pListBlock);
49  void PushListContext(XMLNumberedParaContext *i_pNumberedParagraph);
51  void PopListContext();
53  void ListContextTop(XMLTextListBlockContext*& o_pListBlockContext,
54  XMLTextListItemContext*& o_pListItemContext,
55  XMLNumberedParaContext*& o_pNumberedParagraphContext );
57  void SetListItem( XMLTextListItemContext *pListItem );
58 
59 
60  // keeping track of processed lists for import and export
61  // Add optional parameter <sListStyleDefaultListId> (#i92811#)
62  void KeepListAsProcessed( const OUString& sListId,
63  const OUString& sListStyleName,
64  const OUString& sContinueListId,
65  const OUString& sListStyleDefaultListId = OUString() );
66 
67  bool IsListProcessed( const OUString& sListId ) const;
69  const OUString& sListId ) const;
71  const OUString& sListId ) const;
72  const OUString& GetLastProcessedListId() const { return msLastProcessedListId;}
74 
75  OUString GenerateNewListId() const;
76 
77  // Provide list id for a certain list block for import (#i92811#)
78  OUString GetListIdForListBlock( XMLTextListBlockContext const & rListBlock );
79 
80  // keep track of continue list chain for export
81  void StoreLastContinuingList( const OUString& sListId,
82  const OUString& sContinuingListId );
83 
84  OUString GetLastContinuingListId( const OUString& sListId ) const;
85 
86  // keep track of opened list elements of a certain list for export
87  void PushListOnStack( const OUString& sListId,
88  const OUString& sListStyleName );
89  void PopListFromStack();
90  bool EqualsToTopListStyleOnStack( std::u16string_view sListId ) const;
91 
96  css::uno::Reference< css::container::XIndexReplace>
98  SvXMLImport & i_rImport,
99  const OUString& i_ListId,
100  sal_Int16 & io_rLevel, const OUString& i_StyleName);
101 
104  const sal_uInt16 i_Level,
105  std::u16string_view i_StyleName);
106 
116  static css::uno::Reference< css::container::XIndexReplace> MakeNumRule(
117  SvXMLImport & i_rImport,
118  const css::uno::Reference< css::container::XIndexReplace>& i_xNumRule,
119  std::u16string_view i_ParentStyleName,
120  const OUString& i_StyleName,
121  sal_Int16 & io_rLevel,
122  bool* o_pRestartNumbering = nullptr,
123  bool* io_pSetDefaults = nullptr);
124 
125  private:
126 
131  typedef std::tuple<SvXMLImportContextRef,
132  SvXMLImportContextRef, SvXMLImportContextRef> ListStackFrame_t;
133  std::stack< ListStackFrame_t > mListStack;
134 
135  // container type for processed lists:
136  // map with <ListId> as key and pair( <ListStyleName, ContinueListId> )
137  // as value
138  typedef ::std::map< OUString,
139  ::std::pair< OUString, OUString > > tMapForLists;
140  std::unique_ptr<tMapForLists> mpProcessedLists;
143 
144  /* additional container for processed lists.
145  map with <ListStyleName> as key and pair( <ListId, ListStyleDefaultListId> )
146  as value. (#i92811#)
147  */
148  std::unique_ptr<tMapForLists> mpMapListIdToListStyleDefaultListId;
149 
150  // container type to build up continue list chain:
151  // map with <ListId> of master list as key and <ListId> of last list
152  // continuing the master list as value
153  typedef ::std::map< OUString, OUString > tMapForContinuingLists;
154  std::unique_ptr<tMapForContinuingLists> mpContinuingLists;
155 
156  // stack type for opened list elements and its list style:
157  // vector with pair( <ListId>, <ListStyleName> ) as value
158  typedef ::std::vector< ::std::pair< OUString, OUString > >
160  std::unique_ptr<tStackForLists> mpListStack;
161 
164  typedef ::std::vector< ::std::pair< OUString, OUString > >
166 
168 
170  typedef ::std::vector<
171  ::std::pair<
172  OUString,
173  css::uno::Reference< css::container::XIndexReplace > > > NumParaList_t;
174  ::std::map< OUString, NumParaList_t > mNPLists;
175 
176 };
177 #endif
178 
179 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::unique_ptr< tMapForLists > mpMapListIdToListStyleDefaultListId
Definition: txtlists.hxx:148
std::stack< ListStackFrame_t > mListStack
Definition: txtlists.hxx:133
LastNumberedParagraphs_t mLastNumberedParagraphs
Definition: txtlists.hxx:167
::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:165
bool EqualsToTopListStyleOnStack(std::u16string_view sListId) const
Definition: txtlists.cxx:302
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:159
std::unique_ptr< tStackForLists > mpListStack
Definition: txtlists.hxx:160
XMLTextListsHelper & operator=(const XMLTextListsHelper &)=delete
OUString msListStyleOfLastProcessedList
Definition: txtlists.hxx:142
OUString GetNumberedParagraphListId(const sal_uInt16 i_Level, std::u16string_view i_StyleName)
get ID of the last numbered-paragraph iff it has given style-name
Definition: txtlists.cxx:308
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
const OUString & GetLastProcessedListId() const
Definition: txtlists.hxx:72
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:153
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:154
void PushListContext(XMLTextListBlockContext *i_pListBlock)
list stack for importing:
Definition: txtlists.cxx:51
::std::map< OUString, NumParaList_t > mNPLists
Definition: txtlists.hxx:174
OUString msLastProcessedListId
Definition: txtlists.hxx:141
::std::map< OUString,::std::pair< OUString, OUString > > tMapForLists
Definition: txtlists.hxx:139
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
::std::vector< ::std::pair< OUString, css::uno::Reference< css::container::XIndexReplace > > > NumParaList_t
numbered-paragraphs
Definition: txtlists.hxx:173
std::unique_ptr< tMapForLists > mpProcessedLists
Definition: txtlists.hxx:140
std::tuple< SvXMLImportContextRef, SvXMLImportContextRef, SvXMLImportContextRef > ListStackFrame_t
list context: list, list-item, numbered-paragraph XMLTextListBlockContext, XMLTextListItemContext, XMLNumberedParaContext
Definition: txtlists.hxx:132
OUString GetListIdForListBlock(XMLTextListBlockContext const &rListBlock)
Definition: txtlists.cxx:225
bool IsListProcessed(const OUString &sListId) const
Definition: txtlists.cxx:148
static css::uno::Reference< css::container::XIndexReplace > MakeNumRule(SvXMLImport &i_rImport, const css::uno::Reference< css::container::XIndexReplace > &i_xNumRule, std::u16string_view 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 & GetListStyleOfLastProcessedList() const
Definition: txtlists.hxx:73