summaryrefslogtreecommitdiff
path: root/sw/source/core/inc/txmsrt.hxx
blob: ac89aab96c1bdc71f2c051e44fe05df6a8285d05 (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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
/* -*- 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 .
 */
#ifndef INCLUDED_SW_SOURCE_CORE_INC_TXMSRT_HXX
#define INCLUDED_SW_SOURCE_CORE_INC_TXMSRT_HXX

#include <i18nlangtag/lang.h>
#include <tox.hxx>

#include <com/sun/star/lang/Locale.hpp>

class CharClass;
class SwContentNode;
class SwTextNode;
class SwTextTOXMark;
class SwIndex;
class SwFormatField;
class SwRootFrame;
class IndexEntrySupplierWrapper;

enum TOXSortType
{
    TOX_SORT_INDEX,
    TOX_SORT_CUSTOM,
    TOX_SORT_CONTENT,
    TOX_SORT_PARA,
    TOX_SORT_TABLE,
    TOX_SORT_AUTHORITY
};

struct SwTOXSource
{
    const SwContentNode* pNd;
    sal_Int32 nPos;
    bool bMainEntry;

    SwTOXSource( const SwContentNode* pNode, sal_Int32 n, bool bMain )
        : pNd(pNode), nPos(n), bMainEntry(bMain)
    {
    }
};

struct TextAndReading
{
    OUString sText;
    OUString sReading;

    TextAndReading() {}

    TextAndReading(const OUString& rText, const OUString& rReading)
    : sText(rText)
    , sReading(rReading)
    {}
};

class SwTOXInternational
{
    std::unique_ptr<IndexEntrySupplierWrapper> m_pIndexWrapper;
    std::unique_ptr<CharClass>                 m_pCharClass;
    LanguageType               m_eLang;
    OUString                   m_sSortAlgorithm;
    SwTOIOptions               m_nOptions;

    void Init();

public:
    SwTOXInternational( LanguageType nLang, SwTOIOptions nOptions,
                        const OUString& rSortAlgorithm );
    SwTOXInternational( const SwTOXInternational& );
    ~SwTOXInternational();

    sal_Int32 Compare( const TextAndReading& rTaR1,
                       const css::lang::Locale& rLocale1,
                       const TextAndReading& rTaR2,
                       const css::lang::Locale& rLocale2 ) const;

    bool IsEqual( const TextAndReading& rTaR1,
                         const css::lang::Locale& rLocale1,
                         const TextAndReading& rTaR2,
                         const css::lang::Locale& rLocale2 ) const
    {
        return 0 == Compare( rTaR1, rLocale1, rTaR2, rLocale2 );
    }

    bool IsLess( const TextAndReading& rTaR1,
                        const css::lang::Locale& rLocale1,
                        const TextAndReading& rTaR2,
                        const css::lang::Locale& rLocale2 ) const
    {
        return -1 == Compare( rTaR1, rLocale1, rTaR2, rLocale2 );
    }

    OUString GetIndexKey( const TextAndReading& rTaR,
                        const css::lang::Locale& rLcl ) const;

    OUString GetFollowingText( bool bMorePages ) const;

    OUString ToUpper( const OUString& rStr, sal_Int32 nPos ) const;
    inline bool IsNumeric( const OUString& rStr ) const;
};

/**
 * Class for sorting directories
 */
struct SwTOXSortTabBase
{
    bool operator==(const SwTOXSortTabBase&) const = delete;
    bool operator<(const SwTOXSortTabBase&) const = delete;

    std::vector<SwTOXSource>       aTOXSources;
    css::lang::Locale aLocale;
    const SwTextNode* pTOXNd;
    const SwTextTOXMark* pTextMark;
    const SwTOXInternational* pTOXIntl;
    sal_uLong nPos;
    sal_Int32 nCntPos;
    sal_uInt16 nType;
    static SwTOIOptions nOpt;

    SwTOXSortTabBase( TOXSortType nType,
                      const SwContentNode* pTOXSrc,
                      const SwTextTOXMark* pTextMark,
                      const SwTOXInternational* pIntl,
                      const css::lang::Locale* pLocale = nullptr );
    virtual ~SwTOXSortTabBase() {}

    sal_uInt16  GetType() const         { return nType; }
    static SwTOIOptions  GetOptions()   { return nOpt; }

    virtual void    FillText(SwTextNode& rNd, const SwIndex& rInsPos,
            sal_uInt16 nAuthField, SwRootFrame const* pLayout) const;
    virtual sal_uInt16  GetLevel()  const = 0;
    virtual bool    equivalent( const SwTOXSortTabBase& );
    virtual bool    sort_lt( const SwTOXSortTabBase& );

    virtual std::pair<OUString, bool> GetURL(SwRootFrame const*const pLayout) const;

    virtual bool IsFullPara() const;

    // must be called
    inline void InitText(SwRootFrame const*const pLayout);
    inline TextAndReading const & GetText() const;
    inline const css::lang::Locale& GetLocale() const;

private:
    bool m_bValidText;
    TextAndReading m_aSort;

    virtual TextAndReading GetText_Impl(SwRootFrame const* pLayout) const = 0;
};

inline void SwTOXSortTabBase::InitText(SwRootFrame const*const pLayout)
{
        // 'this' is 'SwTOXSortTabBase const*', so the virtual
        // mechanism will call the derived class' GetText_Impl
    assert(!m_bValidText);
    m_aSort = GetText_Impl(pLayout);
    m_bValidText = true;
}

inline TextAndReading const & SwTOXSortTabBase::GetText() const
{
    assert(m_bValidText);
    return m_aSort;
}

inline const css::lang::Locale& SwTOXSortTabBase::GetLocale() const
{
    return aLocale;
}

/**
 * For sorting by text
 */
struct SwTOXIndex final : public SwTOXSortTabBase
{
    SwTOXIndex( const SwTextNode&, const SwTextTOXMark*, SwTOIOptions nOptions, sal_uInt8 nKeyLevel,
                const SwTOXInternational& rIntl,
                const css::lang::Locale& rLocale );

    virtual void    FillText(SwTextNode& rNd, const SwIndex& rInsPos,
            sal_uInt16 nAuthField, SwRootFrame const* pLayout) const override;
    virtual sal_uInt16  GetLevel() const override;
    virtual bool    equivalent( const SwTOXSortTabBase& ) override;
    virtual bool    sort_lt( const SwTOXSortTabBase& ) override;

private:
    virtual TextAndReading GetText_Impl(SwRootFrame const* pLayout) const override;

    sal_uInt8   nKeyLevel;
};

struct SwTOXCustom final : public SwTOXSortTabBase
{
    SwTOXCustom( const TextAndReading& rKey, sal_uInt16 nLevel,
                 const SwTOXInternational& rIntl,
                 const css::lang::Locale& rLocale );

    virtual sal_uInt16 GetLevel() const override;
    virtual bool   equivalent( const SwTOXSortTabBase& ) override;
    virtual bool   sort_lt( const SwTOXSortTabBase& ) override;

private:
    virtual TextAndReading GetText_Impl(SwRootFrame const* pLayout) const override;

    TextAndReading m_aKey;
    sal_uInt16  nLev;
};

/**
 * For sorting by position
 */
struct SwTOXContent final : public SwTOXSortTabBase
{
    SwTOXContent( const SwTextNode&, const SwTextTOXMark*,
                const SwTOXInternational& rIntl );

    virtual void    FillText(SwTextNode& rNd, const SwIndex& rInsPos,
            sal_uInt16 nAuthField, SwRootFrame const* pLayout) const override;
    virtual sal_uInt16  GetLevel() const override;
private:
    virtual TextAndReading GetText_Impl(SwRootFrame const* pLayout) const override;

};

struct SwTOXPara final : public SwTOXSortTabBase
{
    SwTOXPara(SwContentNode&, SwTOXElement,
              sal_uInt16 nLevel = FORM_ALPHA_DELIMITER,
              const OUString& sSeqName = OUString());

    void    SetStartIndex(sal_Int32 nSet)    { nStartIndex = nSet; }
    void    SetEndIndex(sal_Int32 nSet)      { nEndIndex = nSet; }

    virtual void    FillText(SwTextNode& rNd, const SwIndex& rInsPos,
            sal_uInt16 nAuthField, SwRootFrame const* pLayout) const override;
    virtual sal_uInt16  GetLevel() const override;

    virtual std::pair<OUString, bool> GetURL(SwRootFrame const*const pLayout) const override;
    virtual bool IsFullPara() const override;
private:
    virtual TextAndReading GetText_Impl(SwRootFrame const* pLayout) const override;

    SwTOXElement eType;
    sal_uInt16 m_nLevel;
    sal_Int32 nStartIndex;
    sal_Int32 nEndIndex;
    OUString m_sSequenceName;
};

struct SwTOXTable final : public SwTOXSortTabBase
{
    SwTOXTable( const SwContentNode& rNd );

    void    SetLevel(sal_uInt16 nSet){nLevel = nSet;}

    virtual sal_uInt16  GetLevel() const override;

    virtual std::pair<OUString, bool> GetURL(SwRootFrame const*const pLayout) const override;

private:
    virtual TextAndReading GetText_Impl(SwRootFrame const* pLayout) const override;

    sal_uInt16 nLevel;
};

/// Represents one row in the bibliography table.
struct SwTOXAuthority final : public SwTOXSortTabBase
{
private:
    SwFormatField& m_rField;
    virtual void    FillText(SwTextNode& rNd, const SwIndex& rInsPos,
            sal_uInt16 nAuthField, SwRootFrame const* pLayout) const override;
    virtual TextAndReading GetText_Impl(SwRootFrame const* pLayout) const override;

public:
    SwTOXAuthority( const SwContentNode& rNd, SwFormatField& rField, const SwTOXInternational& rIntl );

    SwFormatField& GetFieldFormat() {return m_rField;}

    virtual bool    equivalent( const SwTOXSortTabBase& ) override;
    virtual bool    sort_lt( const SwTOXSortTabBase& ) override;
    virtual sal_uInt16  GetLevel() const override;
    OUString GetText(sal_uInt16 nAuthField, const SwRootFrame* pLayout) const;

    /// Gets the URL of the underlying SwAuthEntry, ignoring its page number.
    OUString GetSourceURL(const OUString& rText) const;
};

#endif // INCLUDED_SW_SOURCE_CORE_INC_TXMSRT_HXX

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