Merged in v 26.12.
[AROS-Contrib.git] / mui / classes / thebar / mcp / locale.c
blobbf1bed926fba9057b4e9d3105323e3994f5423d2
1 /***************************************************************************
3 TheBar.mcc - Next Generation Toolbar MUI Custom Class
4 Copyright (C) 2003-2005 Alfonso Ranieri
5 Copyright (C) 2005-2013 by TheBar.mcc Open Source Team
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or (at your option) any later version.
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
17 TheBar class Support Site: http://www.sf.net/projects/thebar
19 $Id$
21 ***************************************************************************/
23 #define CATCOMP_ARRAY
24 #include "class.h"
26 /***********************************************************************/
28 struct Catalog *
29 openCatalogVR(CONST_STRPTR name,ULONG minVer,ULONG minRev)
31 if ((lib_cat = OpenCatalog(NULL,(STRPTR)name,OC_BuiltInLanguage,(IPTR)"english",TAG_DONE)))
33 ULONG ver = lib_cat->cat_Version;
35 if ((ver<minVer) ? TRUE : ((ver==minVer) ? (lib_cat->cat_Revision<minRev) : FALSE))
37 CloseCatalog(lib_cat);
38 lib_cat = NULL;
42 return lib_cat;
45 /***********************************************************************/
47 STRPTR
48 tr(ULONG id)
50 int low, high;
52 for (low = 0, high = (sizeof(CatCompArray)/sizeof(CatCompArray[0]))-1; low<=high; )
54 int mid = (low+high) / 2, cond;
55 struct CatCompArrayType *cca = (struct CatCompArrayType *)CatCompArray+mid;
57 cond = id - cca->cca_ID;
59 if(cond == 0)
60 return lib_cat ? (STRPTR)GetCatalogStr(lib_cat, id, cca->cca_Str) : cca->cca_Str;
61 else if(cond<0)
62 high = mid-1;
63 else
64 low = mid+1;
67 return (STRPTR)"";
70 /****************************************************************************/
72 #define IDSSIZE(ids) (sizeof(ids)/sizeof(ids[0]))
74 static const ULONG regIDs[] =
76 Msg_Reg_Colors,
77 Msg_Reg_Appearance,
78 Msg_Reg_Spacing,
79 Msg_Reg_Options,
82 STRPTR regs[IDSSIZE(regIDs)];
84 static const ULONG frameIDs[] =
86 Msg_FrameStyle_Recessed,
87 Msg_FrameStyle_Normal,
90 STRPTR frames[IDSSIZE(frameIDs)];
92 static const ULONG precisionIDs[] =
94 Msg_Precision_Gui,
95 Msg_Precision_Icon,
96 Msg_Precision_Image,
97 Msg_Precision_Exact,
100 STRPTR precisions[IDSSIZE(precisionIDs)];
102 static const ULONG dismodeIDs[] =
104 Msg_DisMode_Shape,
105 Msg_DisMode_Grid,
106 Msg_DisMode_FullGrid,
107 Msg_DisMode_Sunny,
108 Msg_DisMode_Blend,
109 Msg_DisMode_BlendGrey,
112 STRPTR dismodes[IDSSIZE(dismodeIDs)];
114 static const ULONG spacersSizeIDs[] =
116 Msg_SpacersSize_Quarter,
117 Msg_SpacersSize_Half,
118 Msg_SpacersSize_One,
119 Msg_SpacersSize_None,
120 Msg_SpacersSize_OnePoint,
121 Msg_SpacersSize_TwoPoint,
124 STRPTR spacersSizes[IDSSIZE(spacersSizeIDs)];
126 static const ULONG viewModeIDs[] =
128 Msg_TextGfx,
129 Msg_Gfx,
130 Msg_Text,
133 STRPTR viewModes[IDSSIZE(viewModeIDs)];
135 static const ULONG labelPosIDs[] =
137 Msg_LabelPos_Bottom,
138 Msg_LabelPos_Top,
139 Msg_LabelPos_Right,
140 Msg_LabelPos_Left,
143 STRPTR labelPoss[IDSSIZE(labelPosIDs)];
145 void
146 localizeArray(STRPTR *strings, const ULONG *ids)
148 while (*ids)
149 *strings++ = tr(*ids++);
150 // make sure the translated string array is NULL terminated
151 *strings = NULL;
154 void
155 initStrings(void)
157 if (openCatalogVR((CONST_STRPTR)"TheBar_mcp.catalog",0,0))
159 struct CatCompArrayType *cca;
160 int cnt;
162 for (cnt = (sizeof(CatCompArray)/sizeof(CatCompArray[0]))-1, cca = (struct CatCompArrayType *)CatCompArray+cnt;
163 cnt>=0;
164 cnt--, cca--)
166 STRPTR s;
168 if ((s = (STRPTR)GetCatalogStr(lib_cat, cca->cca_ID, cca->cca_Str)))
169 cca->cca_Str = s;
173 localizeArray(regs,regIDs);
174 localizeArray(frames,frameIDs);
175 localizeArray(precisions,precisionIDs);
176 localizeArray(dismodes,dismodeIDs);
177 localizeArray(spacersSizes,spacersSizeIDs);
178 localizeArray(viewModes,viewModeIDs);
179 localizeArray(labelPoss,labelPosIDs);
181 #if !defined(__MORPHOS__) && !defined(__amigaos4__) && !defined(__AROS__)
182 dismodes[4] = NULL;
183 #endif
186 /***********************************************************************/
188 ULONG
189 getKeyChar(STRPTR string)
191 ULONG res = 0;
193 if (string)
195 for (; *string && *string!='_'; string++);
196 if (*string++)
197 res = ToLower(*string);
200 return res;
203 /***********************************************************************/