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 
24 
25 // MARKER(update_precomp.py): autogen include statement, do not remove
26 #include "precompiled_svtools.hxx"
27 #include <svtools/svtdata.hxx>
28 #include <svtools/svtools.hrc>
29 #include <svtools/indexentryres.hxx>
30 
31 // -------------------------------------------------------------------------
32 //
33 //  wrapper for locale specific translations data of indexentry algorithm
34 //
35 // -------------------------------------------------------------------------
36 
37 class IndexEntryRessourceData
38 {
39 	friend class IndexEntryRessource;
40 	private: /* data */
41 		String 	ma_Name;
42 		String 	ma_Translation;
43 	private: /* member functions */
44 		IndexEntryRessourceData () {}
45 	public:
46 		IndexEntryRessourceData ( const String &r_Algorithm, const String &r_Translation)
47 				: ma_Name (r_Algorithm), ma_Translation (r_Translation) {}
48 
49 		const String&	GetAlgorithm () const { return ma_Name; }
50 
51 		const String&	GetTranslation () const { return ma_Translation; }
52 
53 		~IndexEntryRessourceData () {}
54 
55 		IndexEntryRessourceData& operator= (const IndexEntryRessourceData& r_From)
56 		{
57 			ma_Name 		= r_From.GetAlgorithm();
58 			ma_Translation 	= r_From.GetTranslation();
59 			return *this;
60 		}
61 };
62 
63 // -------------------------------------------------------------------------
64 //
65 //  implementation of the indexentry-algorithm-name translation
66 //
67 // -------------------------------------------------------------------------
68 
69 #define INDEXENTRY_RESSOURCE_COUNT (STR_SVT_INDEXENTRY_END - STR_SVT_INDEXENTRY_START + 1)
70 
71 IndexEntryRessource::IndexEntryRessource()
72 {
73         mp_Data = new IndexEntryRessourceData[INDEXENTRY_RESSOURCE_COUNT];
74 
75         #define ASCSTR(str) String(RTL_CONSTASCII_USTRINGPARAM(str))
76         #define RESSTR(rid) String(SvtResId(rid))
77 
78         mp_Data[STR_SVT_INDEXENTRY_ALPHANUMERIC - STR_SVT_INDEXENTRY_START] =
79 		IndexEntryRessourceData (ASCSTR("alphanumeric"), RESSTR(STR_SVT_INDEXENTRY_ALPHANUMERIC));
80         mp_Data[STR_SVT_INDEXENTRY_DICTIONARY - STR_SVT_INDEXENTRY_START] =
81 		IndexEntryRessourceData (ASCSTR("dict"), RESSTR(STR_SVT_INDEXENTRY_DICTIONARY));
82         mp_Data[STR_SVT_INDEXENTRY_PINYIN - STR_SVT_INDEXENTRY_START] =
83 		IndexEntryRessourceData (ASCSTR("pinyin"), RESSTR(STR_SVT_INDEXENTRY_PINYIN));
84         mp_Data[STR_SVT_INDEXENTRY_PINYIN - STR_SVT_INDEXENTRY_START] =
85 		IndexEntryRessourceData (ASCSTR("radical"), RESSTR(STR_SVT_INDEXENTRY_RADICAL));
86         mp_Data[STR_SVT_INDEXENTRY_STROKE - STR_SVT_INDEXENTRY_START] =
87 		IndexEntryRessourceData (ASCSTR("stroke"), RESSTR(STR_SVT_INDEXENTRY_STROKE));
88         mp_Data[STR_SVT_INDEXENTRY_STROKE - STR_SVT_INDEXENTRY_START] =
89 		IndexEntryRessourceData (ASCSTR("zhuyin"), RESSTR(STR_SVT_INDEXENTRY_ZHUYIN));
90         mp_Data[STR_SVT_INDEXENTRY_ZHUYIN - STR_SVT_INDEXENTRY_START] =
91 		IndexEntryRessourceData (ASCSTR("phonetic (alphanumeric first) (grouped by syllable)"),
92                     RESSTR(STR_SVT_INDEXENTRY_PHONETIC_FS));
93         mp_Data[STR_SVT_INDEXENTRY_PHONETIC_FS - STR_SVT_INDEXENTRY_START] =
94 		IndexEntryRessourceData (ASCSTR("phonetic (alphanumeric first) (grouped by consonant)"),
95                     RESSTR(STR_SVT_INDEXENTRY_PHONETIC_FC));
96         mp_Data[STR_SVT_INDEXENTRY_PHONETIC_FC - STR_SVT_INDEXENTRY_START] =
97 		IndexEntryRessourceData (ASCSTR("phonetic (alphanumeric last) (grouped by syllable)"),
98                     RESSTR(STR_SVT_INDEXENTRY_PHONETIC_LS));
99         mp_Data[STR_SVT_INDEXENTRY_PHONETIC_LS - STR_SVT_INDEXENTRY_START] =
100 		IndexEntryRessourceData (ASCSTR("phonetic (alphanumeric last) (grouped by consonant)"),
101                     RESSTR(STR_SVT_INDEXENTRY_PHONETIC_LC));
102 }
103 
104 IndexEntryRessource::~IndexEntryRessource()
105 {
106 	delete[] mp_Data;
107 }
108 
109 const String&
110 IndexEntryRessource::GetTranslation (const String &r_Algorithm)
111 {
112 	xub_StrLen nIndex = r_Algorithm.Search('.');
113 	String aLocaleFreeAlgorithm;
114 
115 	if (nIndex == STRING_NOTFOUND)
116 		aLocaleFreeAlgorithm = r_Algorithm;
117 	else {
118 		nIndex += 1;
119 		aLocaleFreeAlgorithm = String(r_Algorithm, nIndex, r_Algorithm.Len() - nIndex);
120 	}
121 
122 	for (sal_uInt32 i = 0; i < INDEXENTRY_RESSOURCE_COUNT; i++)
123 		if (aLocaleFreeAlgorithm == mp_Data[i].GetAlgorithm())
124 			return mp_Data[i].GetTranslation();
125 	return r_Algorithm;
126 }
127 
128