Line data Source code
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 : #ifndef INCLUDED_SW_SOURCE_CORE_INC_TXMSRT_HXX
20 : #define INCLUDED_SW_SOURCE_CORE_INC_TXMSRT_HXX
21 :
22 : #include <i18nlangtag/lang.h>
23 : #include <tox.hxx>
24 :
25 : #include <com/sun/star/lang/Locale.hpp>
26 :
27 : class CharClass;
28 : class SwCntntNode;
29 : class SwTxtNode;
30 : class SwTxtTOXMark;
31 : class SwIndex;
32 : class SwFmtFld;
33 : class IndexEntrySupplierWrapper;
34 :
35 : enum TOXSortType
36 : {
37 : TOX_SORT_INDEX,
38 : TOX_SORT_CUSTOM,
39 : TOX_SORT_CONTENT,
40 : TOX_SORT_PARA,
41 : TOX_SORT_TABLE,
42 : TOX_SORT_AUTHORITY
43 : };
44 :
45 : struct SwTOXSource
46 : {
47 : const SwCntntNode* pNd;
48 : sal_Int32 nPos;
49 : bool bMainEntry;
50 :
51 0 : SwTOXSource( const SwCntntNode* pNode, sal_Int32 n, bool bMain )
52 0 : : pNd(pNode), nPos(n), bMainEntry(bMain)
53 : {
54 0 : }
55 : };
56 :
57 : typedef std::vector<SwTOXSource> SwTOXSources;
58 :
59 0 : struct TextAndReading
60 : {
61 : OUString sText;
62 : OUString sReading;
63 :
64 0 : TextAndReading() {}
65 :
66 0 : TextAndReading(const OUString& sTxt, const OUString& sRdng)
67 : : sText(sTxt)
68 0 : , sReading(sRdng)
69 0 : {}
70 : };
71 :
72 : class SwTOXInternational
73 : {
74 : IndexEntrySupplierWrapper* pIndexWrapper;
75 : CharClass* pCharClass;
76 : LanguageType eLang;
77 : OUString sSortAlgorithm;
78 : sal_uInt16 nOptions;
79 :
80 : void Init();
81 :
82 : public:
83 : SwTOXInternational( LanguageType nLang, sal_uInt16 nOptions,
84 : const OUString& rSortAlgorithm );
85 : SwTOXInternational( const SwTOXInternational& );
86 : ~SwTOXInternational();
87 :
88 : sal_Int32 Compare( const TextAndReading& rTaR1,
89 : const ::com::sun::star::lang::Locale& rLocale1,
90 : const TextAndReading& rTaR2,
91 : const ::com::sun::star::lang::Locale& rLocale2 ) const;
92 :
93 0 : inline bool IsEqual( const TextAndReading& rTaR1,
94 : const ::com::sun::star::lang::Locale& rLocale1,
95 : const TextAndReading& rTaR2,
96 : const ::com::sun::star::lang::Locale& rLocale2 ) const
97 : {
98 0 : return 0 == Compare( rTaR1, rLocale1, rTaR2, rLocale2 );
99 : }
100 :
101 0 : inline bool IsLess( const TextAndReading& rTaR1,
102 : const ::com::sun::star::lang::Locale& rLocale1,
103 : const TextAndReading& rTaR2,
104 : const ::com::sun::star::lang::Locale& rLocale2 ) const
105 : {
106 0 : return -1 == Compare( rTaR1, rLocale1, rTaR2, rLocale2 );
107 : }
108 :
109 : OUString GetIndexKey( const TextAndReading& rTaR,
110 : const ::com::sun::star::lang::Locale& rLcl ) const;
111 :
112 : OUString GetFollowingText( bool bMorePages ) const;
113 :
114 : OUString ToUpper( const OUString& rStr, sal_Int32 nPos ) const;
115 : inline bool IsNumeric( const OUString& rStr ) const;
116 : };
117 :
118 : /*--------------------------------------------------------------------
119 : Beschreibung: Klassen fuer die Sortierung der Verzeichnisse
120 : --------------------------------------------------------------------*/
121 :
122 : struct SwTOXSortTabBase
123 : {
124 : SwTOXSources aTOXSources;
125 : ::com::sun::star::lang::Locale aLocale;
126 : const SwTxtNode* pTOXNd;
127 : const SwTxtTOXMark* pTxtMark;
128 : const SwTOXInternational* pTOXIntl;
129 : sal_uLong nPos;
130 : sal_Int32 nCntPos;
131 : sal_uInt16 nType;
132 : static sal_uInt16 nOpt;
133 :
134 : SwTOXSortTabBase( TOXSortType nType,
135 : const SwCntntNode* pTOXSrc,
136 : const SwTxtTOXMark* pTxtMark,
137 : const SwTOXInternational* pIntl,
138 : const ::com::sun::star::lang::Locale* pLocale = NULL );
139 0 : virtual ~SwTOXSortTabBase() {}
140 :
141 0 : sal_uInt16 GetType() const { return nType; }
142 0 : sal_uInt16 GetOptions() const { return nOpt; }
143 :
144 : virtual void FillText( SwTxtNode& rNd, const SwIndex& rInsPos, sal_uInt16 nAuthField = 0) const;
145 : virtual sal_uInt16 GetLevel() const = 0;
146 : virtual bool operator==( const SwTOXSortTabBase& );
147 : virtual bool operator<( const SwTOXSortTabBase& );
148 :
149 : virtual OUString GetURL() const;
150 :
151 : inline TextAndReading GetTxt() const;
152 : inline const ::com::sun::star::lang::Locale& GetLocale() const;
153 :
154 : private:
155 : mutable bool bValidTxt;
156 : mutable TextAndReading m_aSort;
157 :
158 : virtual TextAndReading GetText_Impl() const = 0;
159 : };
160 :
161 0 : inline TextAndReading SwTOXSortTabBase::GetTxt() const
162 : {
163 0 : if( !bValidTxt )
164 : {
165 : // 'this' is 'SwTOXSortTabBase const*', so the virtual
166 : // mechanism will call the derived class' GetText_Impl
167 0 : m_aSort = GetText_Impl();
168 0 : bValidTxt = true;
169 : }
170 0 : return m_aSort;
171 : }
172 :
173 0 : inline const ::com::sun::star::lang::Locale& SwTOXSortTabBase::GetLocale() const
174 : {
175 0 : return aLocale;
176 : }
177 :
178 : /*--------------------------------------------------------------------
179 : Beschreibung: fuer Sortierung nach Text
180 : --------------------------------------------------------------------*/
181 :
182 : struct SwTOXIndex : public SwTOXSortTabBase
183 : {
184 : SwTOXIndex( const SwTxtNode&, const SwTxtTOXMark*, sal_uInt16 nOptions, sal_uInt8 nKeyLevel,
185 : const SwTOXInternational& rIntl,
186 : const ::com::sun::star::lang::Locale& rLocale );
187 0 : virtual ~SwTOXIndex() {}
188 :
189 : virtual void FillText( SwTxtNode& rNd, const SwIndex& rInsPos, sal_uInt16 nAuthField = 0 ) const SAL_OVERRIDE;
190 : virtual sal_uInt16 GetLevel() const SAL_OVERRIDE;
191 : virtual bool operator==( const SwTOXSortTabBase& ) SAL_OVERRIDE;
192 : virtual bool operator<( const SwTOXSortTabBase& ) SAL_OVERRIDE;
193 :
194 : private:
195 : virtual TextAndReading GetText_Impl() const SAL_OVERRIDE;
196 :
197 : sal_uInt8 nKeyLevel;
198 : };
199 :
200 : struct SwTOXCustom : public SwTOXSortTabBase
201 : {
202 : SwTOXCustom( const TextAndReading& rKey, sal_uInt16 nLevel,
203 : const SwTOXInternational& rIntl,
204 : const ::com::sun::star::lang::Locale& rLocale );
205 0 : virtual ~SwTOXCustom() {}
206 :
207 : virtual sal_uInt16 GetLevel() const SAL_OVERRIDE;
208 : virtual bool operator==( const SwTOXSortTabBase& ) SAL_OVERRIDE;
209 : virtual bool operator<( const SwTOXSortTabBase& ) SAL_OVERRIDE;
210 :
211 : private:
212 : virtual TextAndReading GetText_Impl() const SAL_OVERRIDE;
213 :
214 : TextAndReading m_aKey;
215 : sal_uInt16 nLev;
216 : };
217 :
218 : /*--------------------------------------------------------------------
219 : Beschreibung: fuer Sortierung nach Position
220 : --------------------------------------------------------------------*/
221 :
222 : struct SwTOXContent : public SwTOXSortTabBase
223 : {
224 : SwTOXContent( const SwTxtNode&, const SwTxtTOXMark*,
225 : const SwTOXInternational& rIntl );
226 0 : virtual ~SwTOXContent() {}
227 :
228 : virtual void FillText( SwTxtNode& rNd, const SwIndex& rInsPos, sal_uInt16 nAuthField = 0 ) const SAL_OVERRIDE;
229 : virtual sal_uInt16 GetLevel() const SAL_OVERRIDE;
230 : private:
231 : virtual TextAndReading GetText_Impl() const SAL_OVERRIDE;
232 :
233 : };
234 :
235 : struct SwTOXPara : public SwTOXSortTabBase
236 : {
237 : SwTOXPara( const SwCntntNode&, SwTOXElement, sal_uInt16 nLevel = FORM_ALPHA_DELIMITTER, const OUString& sSeqName = OUString() );
238 0 : virtual ~SwTOXPara() {}
239 :
240 0 : void SetStartIndex(sal_Int32 nSet) { nStartIndex = nSet; }
241 0 : void SetEndIndex(sal_Int32 nSet) { nEndIndex = nSet; }
242 :
243 : virtual void FillText( SwTxtNode& rNd, const SwIndex& rInsPos, sal_uInt16 nAuthField = 0 ) const SAL_OVERRIDE;
244 : virtual sal_uInt16 GetLevel() const SAL_OVERRIDE;
245 :
246 : virtual OUString GetURL() const SAL_OVERRIDE;
247 : private:
248 : virtual TextAndReading GetText_Impl() const SAL_OVERRIDE;
249 :
250 : SwTOXElement eType;
251 : sal_uInt16 m_nLevel;
252 : sal_Int32 nStartIndex;
253 : sal_Int32 nEndIndex;
254 : OUString m_sSequenceName;
255 : };
256 :
257 : struct SwTOXTable : public SwTOXSortTabBase
258 : {
259 : SwTOXTable( const SwCntntNode& rNd );
260 0 : virtual ~SwTOXTable() {}
261 :
262 0 : void SetLevel(sal_uInt16 nSet){nLevel = nSet;}
263 :
264 : virtual sal_uInt16 GetLevel() const SAL_OVERRIDE;
265 :
266 : virtual OUString GetURL() const SAL_OVERRIDE;
267 : private:
268 : virtual TextAndReading GetText_Impl() const SAL_OVERRIDE;
269 :
270 : sal_uInt16 nLevel;
271 : };
272 :
273 : struct SwTOXAuthority : public SwTOXSortTabBase
274 : {
275 : private:
276 : SwFmtFld& m_rField;
277 : virtual void FillText( SwTxtNode& rNd, const SwIndex& rInsPos, sal_uInt16 nAuthField = 0 ) const SAL_OVERRIDE;
278 : virtual TextAndReading GetText_Impl() const SAL_OVERRIDE;
279 :
280 : public:
281 : SwTOXAuthority( const SwCntntNode& rNd, SwFmtFld& rField, const SwTOXInternational& rIntl );
282 0 : virtual ~SwTOXAuthority() {}
283 :
284 0 : SwFmtFld& GetFldFmt() {return m_rField;}
285 :
286 : virtual bool operator==( const SwTOXSortTabBase& ) SAL_OVERRIDE;
287 : virtual bool operator<( const SwTOXSortTabBase& ) SAL_OVERRIDE;
288 : virtual sal_uInt16 GetLevel() const SAL_OVERRIDE;
289 : };
290 :
291 : #endif // INCLUDED_SW_SOURCE_CORE_INC_TXMSRT_HXX
292 :
293 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|