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 28 29 // MARKER(update_precomp.py): autogen include statement, do not remove 30 #include "precompiled_svtools.hxx" 31 #include <svtools/svtdata.hxx> 32 #include <svtools/svtools.hrc> 33 #include <svtools/collatorres.hxx> 34 35 // ------------------------------------------------------------------------- 36 // 37 // wrapper for locale specific translations data of collator algorithm 38 // 39 // ------------------------------------------------------------------------- 40 41 class CollatorRessourceData 42 { 43 friend class CollatorRessource; 44 private: /* data */ 45 String ma_Name; 46 String ma_Translation; 47 private: /* member functions */ 48 CollatorRessourceData () {} 49 public: 50 CollatorRessourceData ( const String &r_Algorithm, const String &r_Translation) 51 : ma_Name (r_Algorithm), ma_Translation (r_Translation) {} 52 53 const String& GetAlgorithm () const { return ma_Name; } 54 55 const String& GetTranslation () const { return ma_Translation; } 56 57 ~CollatorRessourceData () {} 58 59 CollatorRessourceData& operator= (const CollatorRessourceData& r_From) 60 { 61 ma_Name = r_From.GetAlgorithm(); 62 ma_Translation = r_From.GetTranslation(); 63 return *this; 64 } 65 }; 66 67 // ------------------------------------------------------------------------- 68 // 69 // implementation of the collator-algorithm-name translation 70 // 71 // ------------------------------------------------------------------------- 72 73 #define COLLATOR_RESSOURCE_COUNT (STR_SVT_COLLATE_END - STR_SVT_COLLATE_START + 1) 74 75 CollatorRessource::CollatorRessource() 76 { 77 mp_Data = new CollatorRessourceData[COLLATOR_RESSOURCE_COUNT]; 78 79 #define ASCSTR(str) String(RTL_CONSTASCII_USTRINGPARAM(str)) 80 #define RESSTR(rid) String(SvtResId(rid)) 81 82 83 mp_Data[0] = CollatorRessourceData (ASCSTR("alphanumeric"), RESSTR(STR_SVT_COLLATE_ALPHANUMERIC)); 84 mp_Data[1] = CollatorRessourceData (ASCSTR("charset"), RESSTR(STR_SVT_COLLATE_CHARSET)); 85 mp_Data[2] = CollatorRessourceData (ASCSTR("dict"), RESSTR(STR_SVT_COLLATE_DICTIONARY)); 86 mp_Data[3] = CollatorRessourceData (ASCSTR("normal"), RESSTR(STR_SVT_COLLATE_NORMAL)); 87 mp_Data[4] = CollatorRessourceData (ASCSTR("pinyin"), RESSTR(STR_SVT_COLLATE_PINYIN)); 88 mp_Data[5] = CollatorRessourceData (ASCSTR("radical"), RESSTR(STR_SVT_COLLATE_RADICAL)); 89 mp_Data[6] = CollatorRessourceData (ASCSTR("stroke"), RESSTR(STR_SVT_COLLATE_STROKE)); 90 mp_Data[7] = CollatorRessourceData (ASCSTR("unicode"), RESSTR(STR_SVT_COLLATE_UNICODE)); 91 mp_Data[8] = CollatorRessourceData (ASCSTR("zhuyin"), RESSTR(STR_SVT_COLLATE_ZHUYIN)); 92 mp_Data[9] = CollatorRessourceData (ASCSTR("phonebook"), RESSTR(STR_SVT_COLLATE_PHONEBOOK)); 93 mp_Data[10] = CollatorRessourceData (ASCSTR("phonetic (alphanumeric first)"), RESSTR(STR_SVT_COLLATE_PHONETIC_F)); 94 mp_Data[11] = CollatorRessourceData (ASCSTR("phonetic (alphanumeric last)"), RESSTR(STR_SVT_COLLATE_PHONETIC_L)); 95 } 96 97 CollatorRessource::~CollatorRessource() 98 { 99 delete[] mp_Data; 100 } 101 102 const String& 103 CollatorRessource::GetTranslation (const String &r_Algorithm) 104 { 105 xub_StrLen nIndex = r_Algorithm.Search('.'); 106 String aLocaleFreeAlgorithm; 107 108 if (nIndex == STRING_NOTFOUND) 109 { 110 aLocaleFreeAlgorithm = r_Algorithm; 111 } 112 else 113 { 114 nIndex += 1; 115 aLocaleFreeAlgorithm = String(r_Algorithm, nIndex, r_Algorithm.Len() - nIndex); 116 } 117 118 for (sal_uInt32 i = 0; i < COLLATOR_RESSOURCE_COUNT; i++) 119 { 120 if (aLocaleFreeAlgorithm == mp_Data[i].GetAlgorithm()) 121 return mp_Data[i].GetTranslation(); 122 } 123 124 return r_Algorithm; 125 } 126 127