xref: /aoo41x/main/sw/source/core/inc/txmsrt.hxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 #ifndef SW_TXMSRT_HXX
28 #define SW_TXMSRT_HXX
29 
30 #include <i18npool/lang.h>
31 #include <tox.hxx>
32 
33 #include <com/sun/star/lang/Locale.hpp>
34 
35 
36 class CharClass;
37 class SwCntntNode;
38 class SwTxtNode;
39 class SwTxtTOXMark;
40 class SwIndex;
41 class SwFmtFld;
42 class IndexEntrySupplierWrapper;
43 
44 enum TOXSortType
45 {
46 	TOX_SORT_INDEX,
47 	TOX_SORT_CUSTOM,
48 	TOX_SORT_CONTENT,
49 	TOX_SORT_PARA,
50 	TOX_SORT_TABLE,
51 	TOX_SORT_AUTHORITY
52 };
53 
54 struct SwTOXSource
55 {
56 	const SwCntntNode* pNd;
57 	xub_StrLen nPos;
58 	sal_Bool bMainEntry;
59 
60 	SwTOXSource() : pNd(0), nPos(0), bMainEntry(sal_False) {}
61 	SwTOXSource( const SwCntntNode* pNode, xub_StrLen n, sal_Bool bMain )
62 		: pNd(pNode), nPos(n), bMainEntry(bMain)
63 	{}
64 };
65 
66 SV_DECL_VARARR( SwTOXSources, SwTOXSource, 0, 10 )
67 
68 class SwTOXInternational
69 {
70 	IndexEntrySupplierWrapper* pIndexWrapper;
71 	CharClass* pCharClass;
72 	LanguageType eLang;
73     String sSortAlgorithm;
74     sal_uInt16 nOptions;
75 
76 	void Init();
77 
78 public:
79     SwTOXInternational( LanguageType nLang, sal_uInt16 nOptions,
80                         const String& rSortAlgorithm );
81 	SwTOXInternational( const SwTOXInternational& );
82 	~SwTOXInternational();
83 
84     sal_Int32 Compare( const String& rTxt1, const String& rTxtReading1,
85                        const ::com::sun::star::lang::Locale& rLocale1,
86                        const String& rTxt2, const String& rTxtReading2,
87                        const ::com::sun::star::lang::Locale& rLocale2 ) const;
88 
89     inline sal_Bool IsEqual( const String& rTxt1, const String& rTxtReading1,
90                          const ::com::sun::star::lang::Locale& rLocale1,
91                          const String& rTxt2, const String& rTxtReading2,
92                          const ::com::sun::star::lang::Locale& rLocale2 ) const
93 	{
94         return 0 == Compare( rTxt1, rTxtReading1, rLocale1,
95                              rTxt2, rTxtReading2, rLocale2 );
96 	}
97 
98     inline sal_Bool IsLess( const String& rTxt1, const String& rTxtReading1,
99                         const ::com::sun::star::lang::Locale& rLocale1,
100                         const String& rTxt2, const String& rTxtReading2,
101                         const ::com::sun::star::lang::Locale& rLocale2 ) const
102 	{
103         return -1 == Compare( rTxt1, rTxtReading1, rLocale1,
104                               rTxt2, rTxtReading2, rLocale2 );
105 	}
106 
107     String GetIndexKey( const String& rTxt, const String& rTxtReading,
108                         const ::com::sun::star::lang::Locale& rLcl ) const;
109 
110 	String GetFollowingText( sal_Bool bMorePages ) const;
111 
112 	String ToUpper( const String& rStr, xub_StrLen nPos ) const;
113 	inline sal_Bool IsNumeric( const String& rStr ) const;
114 };
115 
116 /*--------------------------------------------------------------------
117 	 Beschreibung: Klassen fuer die Sortierung der Verzeichnisse
118  --------------------------------------------------------------------*/
119 
120 struct SwTOXSortTabBase
121 {
122 	SwTOXSources aTOXSources;
123     ::com::sun::star::lang::Locale aLocale;
124 	const SwTxtNode* pTOXNd;
125 	const SwTxtTOXMark* pTxtMark;
126 	const SwTOXInternational* pTOXIntl;
127 	sal_uLong nPos;
128 	xub_StrLen nCntPos;
129     sal_uInt16 nType;
130 	static sal_uInt16 nOpt;
131 
132 	SwTOXSortTabBase( TOXSortType nType,
133 					  const SwCntntNode* pTOXSrc,
134 					  const SwTxtTOXMark* pTxtMark,
135                       const SwTOXInternational* pIntl,
136                       const ::com::sun::star::lang::Locale* pLocale = NULL );
137     virtual ~SwTOXSortTabBase() {}
138 
139 	sal_uInt16	GetType() const 		{ return nType; }
140 	sal_uInt16	GetOptions() const		{ return nOpt; }
141 
142 	virtual void 	FillText( SwTxtNode& rNd, const SwIndex& rInsPos, sal_uInt16 nAuthField = 0) const;
143 	virtual sal_uInt16  GetLevel() 	const = 0;
144 	virtual sal_Bool 	operator==( const SwTOXSortTabBase& );
145 	virtual sal_Bool 	operator<( const SwTOXSortTabBase& );
146 
147 	virtual String 	GetURL() const;
148 
149     inline void GetTxt( String&, String& ) const;
150     inline const ::com::sun::star::lang::Locale& GetLocale() const;
151 
152 private:
153 	sal_Bool bValidTxt;
154     String sSortTxt;
155     String sSortTxtReading;
156 
157     virtual void GetText_Impl( String&, String& ) const = 0;
158 };
159 
160 inline void SwTOXSortTabBase::GetTxt( String& rSortTxt,
161                                       String& rSortTxtReading ) const
162 {
163 	if( !bValidTxt )
164 	{
165 		SwTOXSortTabBase* pThis = (SwTOXSortTabBase*)this;
166         pThis->GetText_Impl( pThis->sSortTxt, pThis->sSortTxtReading );
167 		pThis->bValidTxt = sal_True;
168 	}
169 
170     rSortTxt = sSortTxt;
171     rSortTxtReading = sSortTxtReading;
172 }
173 
174 inline const ::com::sun::star::lang::Locale& SwTOXSortTabBase::GetLocale() const
175 {
176     return aLocale;
177 }
178 
179 /*--------------------------------------------------------------------
180 	 Beschreibung: fuer Sortierung nach Text
181  --------------------------------------------------------------------*/
182 
183 struct SwTOXIndex : public SwTOXSortTabBase
184 {
185 	SwTOXIndex( const SwTxtNode&, const SwTxtTOXMark*, sal_uInt16 nOptions, sal_uInt8 nKeyLevel,
186                 const SwTOXInternational& rIntl,
187                 const ::com::sun::star::lang::Locale& rLocale );
188     virtual ~SwTOXIndex() {}
189 
190 
191 	virtual void 	FillText( SwTxtNode& rNd, const SwIndex& rInsPos, sal_uInt16 nAuthField = 0 ) const;
192 	virtual sal_uInt16  GetLevel() const;
193 	virtual sal_Bool 	operator==( const SwTOXSortTabBase& );
194 	virtual sal_Bool 	operator<( const SwTOXSortTabBase& );
195 
196 private:
197     virtual void GetText_Impl( String&, String& ) const;
198 
199 	sal_uInt8	nKeyLevel;
200 };
201 
202 struct SwTOXCustom : public SwTOXSortTabBase
203 {
204     SwTOXCustom( const String& rKey, const String& rReading, sal_uInt16 nLevel,
205                  const SwTOXInternational& rIntl,
206                  const ::com::sun::star::lang::Locale& rLocale );
207     virtual ~SwTOXCustom() {}
208 
209 	virtual sal_uInt16 GetLevel() const;
210 	virtual sal_Bool   operator==( const SwTOXSortTabBase& );
211 	virtual sal_Bool   operator<( const SwTOXSortTabBase& );
212 
213 private:
214     virtual void GetText_Impl( String&, String& ) const;
215 
216 	String  aKey;
217     String  sReading;
218 	sal_uInt16  nLev;
219 };
220 
221 /*--------------------------------------------------------------------
222 	 Beschreibung: fuer Sortierung nach Position
223  --------------------------------------------------------------------*/
224 
225 struct SwTOXContent : public SwTOXSortTabBase
226 {
227 	SwTOXContent( const SwTxtNode&, const SwTxtTOXMark*,
228 				const SwTOXInternational& rIntl );
229     virtual ~SwTOXContent() {}
230 
231 	virtual void 	FillText( SwTxtNode& rNd, const SwIndex& rInsPos, sal_uInt16 nAuthField = 0 ) const;
232 	virtual sal_uInt16  GetLevel() const;
233 private:
234     virtual void GetText_Impl( String&, String& ) const;
235 
236 };
237 
238 struct SwTOXPara : public SwTOXSortTabBase
239 {
240 	SwTOXPara( const SwCntntNode&, SwTOXElement, sal_uInt16 nLevel = FORM_ALPHA_DELIMITTER );
241     virtual ~SwTOXPara() {}
242 
243 	void	SetStartIndex( xub_StrLen nSet) 	{ nStartIndex = nSet;}
244 	void 	SetEndIndex( xub_StrLen nSet ) 		{ nEndIndex = nSet;}
245 
246 	virtual void 	FillText( SwTxtNode& rNd, const SwIndex& rInsPos, sal_uInt16 nAuthField = 0 ) const;
247 	virtual sal_uInt16  GetLevel() const;
248 
249 	virtual String 	GetURL() const;
250 private:
251     virtual void GetText_Impl( String&, String& ) const;
252 
253 	SwTOXElement eType;
254 	sal_uInt16 m_nLevel;
255 	xub_StrLen nStartIndex;
256 	xub_StrLen nEndIndex;
257 };
258 
259 struct SwTOXTable : public SwTOXSortTabBase
260 {
261 	SwTOXTable( const SwCntntNode& rNd );
262     virtual ~SwTOXTable() {}
263 
264 	void	SetLevel(sal_uInt16 nSet){nLevel = nSet;}
265 
266 	virtual sal_uInt16  GetLevel() const;
267 
268 	virtual String 	GetURL() const;
269 private:
270     virtual void GetText_Impl( String&, String& ) const;
271 
272 	sal_uInt16 nLevel;
273 };
274 
275 struct SwTOXAuthority : public SwTOXSortTabBase
276 {
277 private:
278 	SwFmtFld& m_rField;
279 	virtual void 	FillText( SwTxtNode& rNd, const SwIndex& rInsPos, sal_uInt16 nAuthField = 0 ) const;
280     virtual void GetText_Impl( String&, String& ) const;
281 
282 public:
283 	SwTOXAuthority( const SwCntntNode& rNd, SwFmtFld& rField, const SwTOXInternational& rIntl );
284     virtual ~SwTOXAuthority() {}
285 
286 	SwFmtFld& GetFldFmt() {return m_rField;}
287 
288 	virtual sal_Bool 	operator==( const SwTOXSortTabBase& );
289 	virtual sal_Bool 	operator<( const SwTOXSortTabBase& );
290 	virtual sal_uInt16  GetLevel() const;
291 };
292 
293 
294 #endif // SW_TXMSRT_HXX
295