summaryrefslogtreecommitdiffstats
path: root/xmloff/inc/txtlists.hxx
blob: dda522c441f9354ea88c92871f0cdcfdeabda451 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */

#pragma once

#include <rtl/ustring.hxx>
#include <map>
#include <memory>
#include <stack>
#include <string_view>
#include <tuple>
#include <vector>
#include <com/sun/star/container/XIndexReplace.hpp>
#include <xmloff/xmlictxt.hxx>

class SvXMLImport;
class XMLTextListBlockContext;
class XMLTextListItemContext;
class XMLNumberedParaContext;

class XMLTextListsHelper
{
    public:
        XMLTextListsHelper();
        XMLTextListsHelper(const XMLTextListsHelper&) = delete;
        XMLTextListsHelper& operator=(const XMLTextListsHelper&) = delete;

        /// list stack for importing:

        /// push a list context on the list context stack
        void PushListContext(XMLTextListBlockContext *i_pListBlock);
        void PushListContext(XMLNumberedParaContext *i_pNumberedParagraph);
        /// pop the list context stack
        void PopListContext();
        /// peek at the top of the list context stack
        void ListContextTop(XMLTextListBlockContext*& o_pListBlockContext,
            XMLTextListItemContext*& o_pListItemContext,
            XMLNumberedParaContext*& o_pNumberedParagraphContext );
        /// set list item on top of the list context stack
        void SetListItem( XMLTextListItemContext *pListItem );


        // keeping track of processed lists for import and export
        // Add optional parameter <sListStyleDefaultListId> (#i92811#)
        void KeepListAsProcessed( const OUString& sListId,
                                  const OUString& sListStyleName,
                                  const OUString& sContinueListId,
                                  const OUString& sListStyleDefaultListId = OUString() );

        bool IsListProcessed( const OUString& sListId ) const;
        OUString GetListStyleOfProcessedList(
                                        const OUString& sListId ) const;
        OUString GetContinueListIdOfProcessedList(
                                        const OUString& sListId ) const;
        const OUString& GetLastProcessedListId() const { return msLastProcessedListId;}
        const OUString& GetListStyleOfLastProcessedList() const { return msListStyleOfLastProcessedList;}

        OUString GenerateNewListId() const;

        // Provide list id for a certain list block for import (#i92811#)
        OUString GetListIdForListBlock( XMLTextListBlockContext const & rListBlock );

        // keep track of continue list chain for export
        void StoreLastContinuingList( const OUString& sListId,
                                      const OUString& sContinuingListId );

        OUString GetLastContinuingListId( const OUString& sListId ) const;

        // keep track of opened list elements of a certain list for export
        void PushListOnStack( const OUString& sListId,
                              const OUString& sListStyleName );
        void PopListFromStack();
        bool EqualsToTopListStyleOnStack( std::u16string_view sListId ) const;

        /** for importing numbered-paragraph
            note that the ID namespace for numbered-paragraph and regular list
            is distinct; we never combine a list and a n-p
         */
        css::uno::Reference< css::container::XIndexReplace>
        EnsureNumberedParagraph(
            SvXMLImport & i_rImport,
            const OUString& i_ListId,
            sal_Int16 & io_rLevel, const OUString& i_StyleName);

        /// get ID of the last numbered-paragraph iff it has given style-name
        OUString GetNumberedParagraphListId(
            const sal_uInt16 i_Level,
            std::u16string_view i_StyleName);

        /** Creates a NumRule from given style-name.
            @param i_rImport        the SvXMLImport
            @param i_xNumRule       parent num rule
            @param i_ParentStyleName  parent list style name
            @param i_StyleName      the list style name
            @param io_rLevel        the list level (may be reset if too large)
            @param o_rRestartNumbering   set to true if no style (defaulting)
            @param io_rSetDefaults  set to true if no style (defaulting)
         */
        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);

        /// Looks up the last list id of a given list style, by name.
        OUString GetLastIdOfStyleName(const OUString& sListStyleName) const;

    private:

        /** list context: list, list-item, numbered-paragraph
            XMLTextListBlockContext, XMLTextListItemContext,
            XMLNumberedParaContext
         */
        typedef std::tuple<SvXMLImportContextRef,
            SvXMLImportContextRef, SvXMLImportContextRef> ListStackFrame_t;
        std::stack< ListStackFrame_t > mListStack;

        // container type for processed lists:
        // map with <ListId> as key and pair( <ListStyleName, ContinueListId> )
        // as value
        typedef ::std::map< OUString,
                            ::std::pair< OUString, OUString > > tMapForLists;
        std::unique_ptr<tMapForLists> mpProcessedLists;
        OUString msLastProcessedListId;
        OUString msListStyleOfLastProcessedList;

        /* additional container for processed lists.
           map with <ListStyleName> as key and pair( <ListId, ListStyleDefaultListId> )
           as value. (#i92811#)
        */
        std::unique_ptr<tMapForLists> mpMapListIdToListStyleDefaultListId;

        // container type to build up continue list chain:
        // map with <ListId> of master list as key and <ListId> of last list
        // continuing the master list as value
        typedef ::std::map< OUString, OUString > tMapForContinuingLists;
        std::unique_ptr<tMapForContinuingLists> mpContinuingLists;

        std::unique_ptr<std::map<OUString, OUString>> mpStyleNameLastListIds;

        // stack type for opened list elements and its list style:
        // vector with pair( <ListId>, <ListStyleName> ) as value
        typedef ::std::vector< ::std::pair< OUString, OUString > >
                                                                tStackForLists;
        std::unique_ptr<tStackForLists> mpListStack;

        /// to connect numbered-paragraphs that have no list-id attribute:
        /// vector of pair of style-name and list-id (indexed by level)
        typedef ::std::vector< ::std::pair< OUString, OUString > >
            LastNumberedParagraphs_t;

        LastNumberedParagraphs_t mLastNumberedParagraphs;

        /// numbered-paragraphs
        typedef ::std::vector<
                    ::std::pair<
                        OUString,
                        css::uno::Reference< css::container::XIndexReplace > > > NumParaList_t;
        ::std::map< OUString, NumParaList_t > mNPLists;

};

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */