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 8 : SwTOXSource( const SwCntntNode* pNode, sal_Int32 n, bool bMain )
52 8 : : pNd(pNode), nPos(n), bMainEntry(bMain)
53 : {
54 8 : }
55 : };
56 :
57 : typedef std::vector<SwTOXSource> SwTOXSources;
58 :
59 48 : struct TextAndReading
60 : {
61 : OUString sText;
62 : OUString sReading;
63 :
64 14 : TextAndReading() {}
65 :
66 6 : TextAndReading(const OUString& sTxt, const OUString& sRdng)
67 : : sText(sTxt)
68 6 : , sReading(sRdng)
69 6 : {}
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 : * Class for sorting directories
120 : */
121 : struct SW_DLLPUBLIC SwTOXSortTabBase
122 : {
123 : SwTOXSources aTOXSources;
124 : ::com::sun::star::lang::Locale aLocale;
125 : const SwTxtNode* pTOXNd;
126 : const SwTxtTOXMark* pTxtMark;
127 : const SwTOXInternational* pTOXIntl;
128 : sal_uLong nPos;
129 : sal_Int32 nCntPos;
130 : sal_uInt16 nType;
131 : static sal_uInt16 nOpt;
132 :
133 : SwTOXSortTabBase( TOXSortType nType,
134 : const SwCntntNode* pTOXSrc,
135 : const SwTxtTOXMark* pTxtMark,
136 : const SwTOXInternational* pIntl,
137 : const ::com::sun::star::lang::Locale* pLocale = NULL );
138 12 : virtual ~SwTOXSortTabBase() {}
139 :
140 8 : sal_uInt16 GetType() const { return nType; }
141 6 : sal_uInt16 GetOptions() const { return nOpt; }
142 :
143 : virtual void FillText( SwTxtNode& rNd, const SwIndex& rInsPos, sal_uInt16 nAuthField = 0) const;
144 : virtual sal_uInt16 GetLevel() const = 0;
145 : virtual bool operator==( const SwTOXSortTabBase& );
146 : virtual bool operator<( const SwTOXSortTabBase& );
147 :
148 : virtual OUString GetURL() const;
149 :
150 : inline TextAndReading GetTxt() const;
151 : inline const ::com::sun::star::lang::Locale& GetLocale() const;
152 :
153 : private:
154 : mutable bool bValidTxt;
155 : mutable TextAndReading m_aSort;
156 :
157 : virtual TextAndReading GetText_Impl() const = 0;
158 : };
159 :
160 10 : inline TextAndReading SwTOXSortTabBase::GetTxt() const
161 : {
162 10 : if( !bValidTxt )
163 : {
164 : // 'this' is 'SwTOXSortTabBase const*', so the virtual
165 : // mechanism will call the derived class' GetText_Impl
166 8 : m_aSort = GetText_Impl();
167 8 : bValidTxt = true;
168 : }
169 10 : return m_aSort;
170 : }
171 :
172 2 : inline const ::com::sun::star::lang::Locale& SwTOXSortTabBase::GetLocale() const
173 : {
174 2 : return aLocale;
175 : }
176 :
177 : /**
178 : * For sorting by text
179 : */
180 : struct SwTOXIndex : public SwTOXSortTabBase
181 : {
182 : SwTOXIndex( const SwTxtNode&, const SwTxtTOXMark*, sal_uInt16 nOptions, sal_uInt8 nKeyLevel,
183 : const SwTOXInternational& rIntl,
184 : const ::com::sun::star::lang::Locale& rLocale );
185 4 : virtual ~SwTOXIndex() {}
186 :
187 : virtual void FillText( SwTxtNode& rNd, const SwIndex& rInsPos, sal_uInt16 nAuthField = 0 ) const SAL_OVERRIDE;
188 : virtual sal_uInt16 GetLevel() const SAL_OVERRIDE;
189 : virtual bool operator==( const SwTOXSortTabBase& ) SAL_OVERRIDE;
190 : virtual bool operator<( const SwTOXSortTabBase& ) SAL_OVERRIDE;
191 :
192 : private:
193 : virtual TextAndReading GetText_Impl() const SAL_OVERRIDE;
194 :
195 : sal_uInt8 nKeyLevel;
196 : };
197 :
198 : struct SwTOXCustom : public SwTOXSortTabBase
199 : {
200 : SwTOXCustom( const TextAndReading& rKey, sal_uInt16 nLevel,
201 : const SwTOXInternational& rIntl,
202 : const ::com::sun::star::lang::Locale& rLocale );
203 0 : virtual ~SwTOXCustom() {}
204 :
205 : virtual sal_uInt16 GetLevel() const SAL_OVERRIDE;
206 : virtual bool operator==( const SwTOXSortTabBase& ) SAL_OVERRIDE;
207 : virtual bool operator<( const SwTOXSortTabBase& ) SAL_OVERRIDE;
208 :
209 : private:
210 : virtual TextAndReading GetText_Impl() const SAL_OVERRIDE;
211 :
212 : TextAndReading m_aKey;
213 : sal_uInt16 nLev;
214 : };
215 :
216 : /**
217 : * For sorting by position
218 : */
219 : struct SwTOXContent : public SwTOXSortTabBase
220 : {
221 : SwTOXContent( const SwTxtNode&, const SwTxtTOXMark*,
222 : const SwTOXInternational& rIntl );
223 0 : virtual ~SwTOXContent() {}
224 :
225 : virtual void FillText( SwTxtNode& rNd, const SwIndex& rInsPos, sal_uInt16 nAuthField = 0 ) const SAL_OVERRIDE;
226 : virtual sal_uInt16 GetLevel() const SAL_OVERRIDE;
227 : private:
228 : virtual TextAndReading GetText_Impl() const SAL_OVERRIDE;
229 :
230 : };
231 :
232 : struct SwTOXPara : public SwTOXSortTabBase
233 : {
234 : SwTOXPara( const SwCntntNode&, SwTOXElement, sal_uInt16 nLevel = FORM_ALPHA_DELIMITTER, const OUString& sSeqName = OUString() );
235 12 : virtual ~SwTOXPara() {}
236 :
237 0 : void SetStartIndex(sal_Int32 nSet) { nStartIndex = nSet; }
238 0 : void SetEndIndex(sal_Int32 nSet) { nEndIndex = nSet; }
239 :
240 : virtual void FillText( SwTxtNode& rNd, const SwIndex& rInsPos, sal_uInt16 nAuthField = 0 ) const SAL_OVERRIDE;
241 : virtual sal_uInt16 GetLevel() const SAL_OVERRIDE;
242 :
243 : virtual OUString GetURL() const SAL_OVERRIDE;
244 : private:
245 : virtual TextAndReading GetText_Impl() const SAL_OVERRIDE;
246 :
247 : SwTOXElement eType;
248 : sal_uInt16 m_nLevel;
249 : sal_Int32 nStartIndex;
250 : sal_Int32 nEndIndex;
251 : OUString m_sSequenceName;
252 : };
253 :
254 : struct SwTOXTable : public SwTOXSortTabBase
255 : {
256 : SwTOXTable( const SwCntntNode& rNd );
257 0 : virtual ~SwTOXTable() {}
258 :
259 0 : void SetLevel(sal_uInt16 nSet){nLevel = nSet;}
260 :
261 : virtual sal_uInt16 GetLevel() const SAL_OVERRIDE;
262 :
263 : virtual OUString GetURL() const SAL_OVERRIDE;
264 : private:
265 : virtual TextAndReading GetText_Impl() const SAL_OVERRIDE;
266 :
267 : sal_uInt16 nLevel;
268 : };
269 :
270 : struct SwTOXAuthority : public SwTOXSortTabBase
271 : {
272 : private:
273 : SwFmtFld& m_rField;
274 : virtual void FillText( SwTxtNode& rNd, const SwIndex& rInsPos, sal_uInt16 nAuthField = 0 ) const SAL_OVERRIDE;
275 : virtual TextAndReading GetText_Impl() const SAL_OVERRIDE;
276 :
277 : public:
278 : SwTOXAuthority( const SwCntntNode& rNd, SwFmtFld& rField, const SwTOXInternational& rIntl );
279 0 : virtual ~SwTOXAuthority() {}
280 :
281 0 : SwFmtFld& GetFldFmt() {return m_rField;}
282 :
283 : virtual bool operator==( const SwTOXSortTabBase& ) SAL_OVERRIDE;
284 : virtual bool operator<( const SwTOXSortTabBase& ) SAL_OVERRIDE;
285 : virtual sal_uInt16 GetLevel() const SAL_OVERRIDE;
286 : };
287 :
288 : #endif // INCLUDED_SW_SOURCE_CORE_INC_TXMSRT_HXX
289 :
290 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|