1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 #ifndef SW_TXMSRT_HXX 24 #define SW_TXMSRT_HXX 25 26 #include <i18npool/lang.h> 27 #include <tox.hxx> 28 29 #include <com/sun/star/lang/Locale.hpp> 30 31 32 class CharClass; 33 class SwCntntNode; 34 class SwTxtNode; 35 class SwTxtTOXMark; 36 class SwIndex; 37 class SwFmtFld; 38 class IndexEntrySupplierWrapper; 39 40 enum TOXSortType 41 { 42 TOX_SORT_INDEX, 43 TOX_SORT_CUSTOM, 44 TOX_SORT_CONTENT, 45 TOX_SORT_PARA, 46 TOX_SORT_TABLE, 47 TOX_SORT_AUTHORITY 48 }; 49 50 struct SwTOXSource 51 { 52 const SwCntntNode* pNd; 53 xub_StrLen nPos; 54 sal_Bool bMainEntry; 55 56 SwTOXSource() : pNd(0), nPos(0), bMainEntry(sal_False) {} 57 SwTOXSource( const SwCntntNode* pNode, xub_StrLen n, sal_Bool bMain ) 58 : pNd(pNode), nPos(n), bMainEntry(bMain) 59 {} 60 }; 61 62 SV_DECL_VARARR( SwTOXSources, SwTOXSource, 0, 10 ) 63 64 class SwTOXInternational 65 { 66 IndexEntrySupplierWrapper* pIndexWrapper; 67 CharClass* pCharClass; 68 LanguageType eLang; 69 String sSortAlgorithm; 70 sal_uInt16 nOptions; 71 72 void Init(); 73 74 public: 75 SwTOXInternational( LanguageType nLang, sal_uInt16 nOptions, 76 const String& rSortAlgorithm ); 77 SwTOXInternational( const SwTOXInternational& ); 78 ~SwTOXInternational(); 79 80 sal_Int32 Compare( const String& rTxt1, const String& rTxtReading1, 81 const ::com::sun::star::lang::Locale& rLocale1, 82 const String& rTxt2, const String& rTxtReading2, 83 const ::com::sun::star::lang::Locale& rLocale2 ) const; 84 85 inline sal_Bool IsEqual( const String& rTxt1, const String& rTxtReading1, 86 const ::com::sun::star::lang::Locale& rLocale1, 87 const String& rTxt2, const String& rTxtReading2, 88 const ::com::sun::star::lang::Locale& rLocale2 ) const 89 { 90 return 0 == Compare( rTxt1, rTxtReading1, rLocale1, 91 rTxt2, rTxtReading2, rLocale2 ); 92 } 93 94 inline sal_Bool IsLess( const String& rTxt1, const String& rTxtReading1, 95 const ::com::sun::star::lang::Locale& rLocale1, 96 const String& rTxt2, const String& rTxtReading2, 97 const ::com::sun::star::lang::Locale& rLocale2 ) const 98 { 99 return -1 == Compare( rTxt1, rTxtReading1, rLocale1, 100 rTxt2, rTxtReading2, rLocale2 ); 101 } 102 103 String GetIndexKey( const String& rTxt, const String& rTxtReading, 104 const ::com::sun::star::lang::Locale& rLcl ) const; 105 106 String GetFollowingText( sal_Bool bMorePages ) const; 107 108 String ToUpper( const String& rStr, xub_StrLen nPos ) const; 109 inline sal_Bool IsNumeric( const String& rStr ) const; 110 }; 111 112 /*-------------------------------------------------------------------- 113 Beschreibung: Klassen fuer die Sortierung der Verzeichnisse 114 --------------------------------------------------------------------*/ 115 116 struct SwTOXSortTabBase 117 { 118 SwTOXSources aTOXSources; 119 ::com::sun::star::lang::Locale aLocale; 120 const SwTxtNode* pTOXNd; 121 const SwTxtTOXMark* pTxtMark; 122 const SwTOXInternational* pTOXIntl; 123 sal_uLong nPos; 124 xub_StrLen nCntPos; 125 sal_uInt16 nType; 126 static sal_uInt16 nOpt; 127 128 SwTOXSortTabBase( TOXSortType nType, 129 const SwCntntNode* pTOXSrc, 130 const SwTxtTOXMark* pTxtMark, 131 const SwTOXInternational* pIntl, 132 const ::com::sun::star::lang::Locale* pLocale = NULL ); 133 virtual ~SwTOXSortTabBase() {} 134 135 sal_uInt16 GetType() const { return nType; } 136 sal_uInt16 GetOptions() const { return nOpt; } 137 138 virtual void FillText( SwTxtNode& rNd, const SwIndex& rInsPos, sal_uInt16 nAuthField = 0) const; 139 virtual sal_uInt16 GetLevel() const = 0; 140 virtual sal_Bool operator==( const SwTOXSortTabBase& ); 141 virtual sal_Bool operator<( const SwTOXSortTabBase& ); 142 143 virtual String GetURL() const; 144 145 inline void GetTxt( String&, String& ) const; 146 inline const ::com::sun::star::lang::Locale& GetLocale() const; 147 148 private: 149 sal_Bool bValidTxt; 150 String sSortTxt; 151 String sSortTxtReading; 152 153 virtual void GetText_Impl( String&, String& ) const = 0; 154 }; 155 156 inline void SwTOXSortTabBase::GetTxt( String& rSortTxt, 157 String& rSortTxtReading ) const 158 { 159 if( !bValidTxt ) 160 { 161 SwTOXSortTabBase* pThis = (SwTOXSortTabBase*)this; 162 pThis->GetText_Impl( pThis->sSortTxt, pThis->sSortTxtReading ); 163 pThis->bValidTxt = sal_True; 164 } 165 166 rSortTxt = sSortTxt; 167 rSortTxtReading = sSortTxtReading; 168 } 169 170 inline const ::com::sun::star::lang::Locale& SwTOXSortTabBase::GetLocale() const 171 { 172 return aLocale; 173 } 174 175 /*-------------------------------------------------------------------- 176 Beschreibung: fuer Sortierung nach Text 177 --------------------------------------------------------------------*/ 178 179 struct SwTOXIndex : public SwTOXSortTabBase 180 { 181 SwTOXIndex( const SwTxtNode&, const SwTxtTOXMark*, sal_uInt16 nOptions, sal_uInt8 nKeyLevel, 182 const SwTOXInternational& rIntl, 183 const ::com::sun::star::lang::Locale& rLocale ); 184 virtual ~SwTOXIndex() {} 185 186 187 virtual void FillText( SwTxtNode& rNd, const SwIndex& rInsPos, sal_uInt16 nAuthField = 0 ) const; 188 virtual sal_uInt16 GetLevel() const; 189 virtual sal_Bool operator==( const SwTOXSortTabBase& ); 190 virtual sal_Bool operator<( const SwTOXSortTabBase& ); 191 192 private: 193 virtual void GetText_Impl( String&, String& ) const; 194 195 sal_uInt8 nKeyLevel; 196 }; 197 198 struct SwTOXCustom : public SwTOXSortTabBase 199 { 200 SwTOXCustom( const String& rKey, const String& rReading, sal_uInt16 nLevel, 201 const SwTOXInternational& rIntl, 202 const ::com::sun::star::lang::Locale& rLocale ); 203 virtual ~SwTOXCustom() {} 204 205 virtual sal_uInt16 GetLevel() const; 206 virtual sal_Bool operator==( const SwTOXSortTabBase& ); 207 virtual sal_Bool operator<( const SwTOXSortTabBase& ); 208 209 private: 210 virtual void GetText_Impl( String&, String& ) const; 211 212 String aKey; 213 String sReading; 214 sal_uInt16 nLev; 215 }; 216 217 /*-------------------------------------------------------------------- 218 Beschreibung: fuer Sortierung nach Position 219 --------------------------------------------------------------------*/ 220 221 struct SwTOXContent : public SwTOXSortTabBase 222 { 223 SwTOXContent( const SwTxtNode&, const SwTxtTOXMark*, 224 const SwTOXInternational& rIntl ); 225 virtual ~SwTOXContent() {} 226 227 virtual void FillText( SwTxtNode& rNd, const SwIndex& rInsPos, sal_uInt16 nAuthField = 0 ) const; 228 virtual sal_uInt16 GetLevel() const; 229 private: 230 virtual void GetText_Impl( String&, String& ) const; 231 232 }; 233 234 struct SwTOXPara : public SwTOXSortTabBase 235 { 236 SwTOXPara( const SwCntntNode&, SwTOXElement, sal_uInt16 nLevel = FORM_ALPHA_DELIMITTER ); 237 virtual ~SwTOXPara() {} 238 239 void SetStartIndex( xub_StrLen nSet) { nStartIndex = nSet;} 240 void SetEndIndex( xub_StrLen nSet ) { nEndIndex = nSet;} 241 242 virtual void FillText( SwTxtNode& rNd, const SwIndex& rInsPos, sal_uInt16 nAuthField = 0 ) const; 243 virtual sal_uInt16 GetLevel() const; 244 245 virtual String GetURL() const; 246 private: 247 virtual void GetText_Impl( String&, String& ) const; 248 249 SwTOXElement eType; 250 sal_uInt16 m_nLevel; 251 xub_StrLen nStartIndex; 252 xub_StrLen nEndIndex; 253 }; 254 255 struct SwTOXTable : public SwTOXSortTabBase 256 { 257 SwTOXTable( const SwCntntNode& rNd ); 258 virtual ~SwTOXTable() {} 259 260 void SetLevel(sal_uInt16 nSet){nLevel = nSet;} 261 262 virtual sal_uInt16 GetLevel() const; 263 264 virtual String GetURL() const; 265 private: 266 virtual void GetText_Impl( String&, String& ) const; 267 268 sal_uInt16 nLevel; 269 }; 270 271 struct SwTOXAuthority : public SwTOXSortTabBase 272 { 273 private: 274 SwFmtFld& m_rField; 275 virtual void FillText( SwTxtNode& rNd, const SwIndex& rInsPos, sal_uInt16 nAuthField = 0 ) const; 276 virtual void GetText_Impl( String&, String& ) const; 277 278 public: 279 SwTOXAuthority( const SwCntntNode& rNd, SwFmtFld& rField, const SwTOXInternational& rIntl ); 280 virtual ~SwTOXAuthority() {} 281 282 SwFmtFld& GetFldFmt() {return m_rField;} 283 284 virtual sal_Bool operator==( const SwTOXSortTabBase& ); 285 virtual sal_Bool operator<( const SwTOXSortTabBase& ); 286 virtual sal_uInt16 GetLevel() const; 287 }; 288 289 290 #endif // SW_TXMSRT_HXX 291