added concrete implementations of putc(), getc(), getchar() and gets()
[tangerine.git] / workbench / prefs / locale / page_language.c
blob76361da03159df416b9512ec6543c9939565d4a2
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc:
6 Lang: English
7 */
9 /*********************************************************************************************/
11 #include "global.h"
13 #include <string.h>
15 /*********************************************************************************************/
17 static struct Gadget *gadlist, *availgad, *prefgad, *cleargad, *gad;
18 static WORD domleft, domtop, domwidth, domheight;
19 static WORD availleft, availtop, availwidth, availheight;
20 static WORD prefleft, preftop, prefwidth, prefheight;
21 static WORD minwidth, minheight;
22 static BOOL page_active;
24 /*********************************************************************************************/
26 static LONG language_layout(void)
28 struct RastPort temprp;
29 WORD w, h, maxw = 0;
31 InitRastPort(&temprp);
32 SetFont(&temprp, dri->dri_Font);
34 maxw = TextLength(&temprp, MSG(MSG_GAD_AVAIL_LANGUAGES), strlen(MSG(MSG_GAD_AVAIL_LANGUAGES)));
35 w = TextLength(&temprp, MSG(MSG_GAD_PREF_LANGUAGES), strlen(MSG(MSG_GAD_PREF_LANGUAGES)));
36 if (w > maxw) maxw = w;
38 maxw = maxw * 2 + SPACE_X;
40 w = TextLength(&temprp, MSG(MSG_GAD_CLEAR_LANGUAGES), strlen(MSG(MSG_GAD_CLEAR_LANGUAGES)));
41 w += BUTTON_EXTRAWIDTH;
42 if (w > maxw) maxw = w;
44 minwidth = maxw;
46 h = dri->dri_Font->tf_YSize + BUTTON_EXTRAHEIGHT;
47 h += SPACE_Y;
48 h += dri->dri_Font->tf_YSize * 8;
50 minheight = h;
52 DeinitRastPort(&temprp);
54 return TRUE;
57 /*********************************************************************************************/
59 static LONG language_makegadgets(void)
61 struct NewGadget ng;
62 WORD labelheight;
64 gad = CreateContext(&gadlist);
66 labelheight = dri->dri_Font->tf_YSize + 2;
68 ng.ng_LeftEdge = availleft = domleft;
69 ng.ng_TopEdge = availtop = preftop = domtop + labelheight;
70 ng.ng_Width = availwidth = prefwidth = (domwidth - SPACE_X) / 2;
71 ng.ng_Height = availheight = prefheight = domheight - dri->dri_Font->tf_YSize -
72 BUTTON_EXTRAHEIGHT - SPACE_Y - labelheight;
73 ng.ng_GadgetText = MSG(MSG_GAD_AVAIL_LANGUAGES);
74 ng.ng_TextAttr = 0;
75 ng.ng_GadgetID = MSG_GAD_AVAIL_LANGUAGES;
76 ng.ng_Flags = PLACETEXT_ABOVE;
77 ng.ng_VisualInfo = vi;
79 gad = availgad = CreateGadget(LISTVIEW_KIND, gad, &ng, GTLV_Labels, (IPTR)&language_list,
80 TAG_DONE);
82 ng.ng_LeftEdge = prefleft = domleft + domwidth - ng.ng_Width;
83 ng.ng_GadgetText = MSG(MSG_GAD_PREF_LANGUAGES);
84 ng.ng_GadgetID = MSG_GAD_PREF_LANGUAGES;
86 gad = prefgad = CreateGadget(LISTVIEW_KIND, gad, &ng, GTLV_Labels, (IPTR)&pref_language_list,
87 TAG_DONE);
89 ng.ng_LeftEdge = domleft;
90 ng.ng_TopEdge = ng.ng_TopEdge + ng.ng_Height + SPACE_Y;
91 ng.ng_Width = domwidth;
92 ng.ng_Height = dri->dri_Font->tf_YSize + BUTTON_EXTRAHEIGHT;
93 ng.ng_GadgetText = MSG(MSG_GAD_CLEAR_LANGUAGES);
94 ng.ng_GadgetID = MSG_GAD_CLEAR_LANGUAGES;
95 ng.ng_Flags = PLACETEXT_IN;
97 gad = cleargad = CreateGadgetA(BUTTON_KIND, gad, &ng, NULL);
99 return gad ? TRUE : FALSE;
102 /*********************************************************************************************/
104 static void empty_listviews(void)
106 if (gadlist)
108 struct Window *winparam = page_active ? win : NULL;
110 GT_SetGadgetAttrs(availgad, winparam, NULL, GTLV_Labels, (IPTR) NULL,
111 TAG_DONE);
113 GT_SetGadgetAttrs(prefgad, winparam, NULL, GTLV_Labels, (IPTR) NULL,
114 TAG_DONE);
118 /*********************************************************************************************/
120 static void reset_listviews(void)
122 if (gadlist)
124 struct Window *winparam = page_active ? win : NULL;
126 GT_SetGadgetAttrs(availgad, winparam, NULL, GTLV_Labels, (IPTR)&language_list,
127 TAG_DONE);
129 GT_SetGadgetAttrs(prefgad, winparam, NULL, GTLV_Labels, (IPTR)&pref_language_list,
130 TAG_DONE);
134 /*********************************************************************************************/
136 static void clear_languages(void)
138 struct Node *node, *node2;
140 ForeachNodeSafe(&pref_language_list, node, node2)
142 Remove(node);
143 SortInNode(&language_list, node);
147 /*********************************************************************************************/
149 static void update_prefs(void)
151 struct LanguageEntry *entry;
152 WORD i = 0;
154 ForeachNode(&pref_language_list, entry)
156 strcpy(localeprefs.lp_PreferredLanguages[i], entry->lve.realname);
157 i++;
158 if (i == 10) break;
161 if (i < 10) localeprefs.lp_PreferredLanguages[i][0] = '\0';
164 /*********************************************************************************************/
166 static LONG language_input(struct IntuiMessage *msg)
168 struct Node *node;
169 LONG retval = FALSE;
171 if (msg->Class == IDCMP_GADGETUP)
173 struct Gadget *gad = (struct Gadget *)msg->IAddress;
175 switch(gad->GadgetID)
177 case MSG_GAD_AVAIL_LANGUAGES:
178 if ((node = FindListNode(&language_list, msg->Code)))
180 empty_listviews();
182 Remove(node);
183 AddTail(&pref_language_list, node);
185 reset_listviews();
187 update_prefs();
189 retval = TRUE;
190 break;
192 case MSG_GAD_PREF_LANGUAGES:
193 if ((node = FindListNode(&pref_language_list, msg->Code)))
195 empty_listviews();
197 Remove(node);
198 SortInNode(&language_list, node);
200 reset_listviews();
202 update_prefs();
204 retval = TRUE;
205 break;
207 case MSG_GAD_CLEAR_LANGUAGES:
208 empty_listviews();
209 clear_languages();
210 reset_listviews();
212 update_prefs();
213 retval = TRUE;
214 break;
218 else if (msg->Class == IDCMP_RAWKEY)
220 WORD delta;
222 switch(msg->Code)
224 case RAWKEY_NM_WHEEL_UP:
225 delta = -1;
226 break;
228 case RAWKEY_NM_WHEEL_DOWN:
229 delta = 1;
230 break;
232 default:
233 delta = 0;
234 break;
237 if (delta)
239 struct Gadget *lvgad = NULL;
241 if ((win->MouseX >= availleft) &&
242 (win->MouseY >= availtop) &&
243 (win->MouseX < availleft + availwidth) &&
244 (win->MouseY < availtop + availheight))
246 lvgad = availgad;
248 else if ((win->MouseX >= prefleft) &&
249 (win->MouseY >= preftop) &&
250 (win->MouseX < prefleft + prefwidth) &&
251 (win->MouseY < preftop + prefheight))
253 lvgad = prefgad;
256 if (lvgad)
258 ScrollListview(lvgad, delta);
265 return retval;
268 /*********************************************************************************************/
270 static void language_cleanup(void)
272 if (gadlist) FreeGadgets(gadlist);
273 gadlist = NULL;
276 /*********************************************************************************************/
278 static void language_prefs_changed(void)
280 struct LanguageEntry *entry, *entry2;
281 WORD i;
283 empty_listviews();
285 clear_languages();
287 for(i = 0; i < 10; i++)
289 if (localeprefs.lp_PreferredLanguages[i][0] == '\0') break;
291 ForeachNodeSafe(&language_list, entry, entry2)
293 if (Stricmp(localeprefs.lp_PreferredLanguages[i], entry->lve.realname) == 0)
295 Remove(&entry->lve.node);
296 AddTail(&pref_language_list, &entry->lve.node);
301 reset_listviews();
305 /*********************************************************************************************/
307 LONG page_language_handler(LONG cmd, IPTR param)
309 LONG retval = TRUE;
311 switch(cmd)
313 case PAGECMD_INIT:
314 break;
316 case PAGECMD_LAYOUT:
317 retval = language_layout();
318 break;
320 case PAGECMD_GETMINWIDTH:
321 retval = minwidth;
322 break;
324 case PAGECMD_GETMINHEIGHT:
325 retval = minheight;
326 break;
328 case PAGECMD_SETDOMLEFT:
329 domleft = param;
330 break;
332 case PAGECMD_SETDOMTOP:
333 domtop = param;
334 break;
336 case PAGECMD_SETDOMWIDTH:
337 domwidth = param;
338 break;
340 case PAGECMD_SETDOMHEIGHT:
341 domheight = param;
342 break;
344 case PAGECMD_MAKEGADGETS:
345 retval = language_makegadgets();
346 break;
348 case PAGECMD_ADDGADGETS:
349 if (!page_active)
351 AddGList(win, gadlist, -1, -1, NULL);
352 GT_RefreshWindow(win, NULL);
353 RefreshGList(gadlist, win, NULL, -1);
355 page_active = TRUE;
357 break;
359 case PAGECMD_REMGADGETS:
360 if (page_active)
362 if (gadlist) RemoveGList(win, gadlist, -1);
364 page_active = FALSE;
366 break;
368 case PAGECMD_HANDLEINPUT:
369 retval = language_input((struct IntuiMessage *)param);
370 break;
372 case PAGECMD_PREFS_CHANGING:
373 break;
375 case PAGECMD_PREFS_CHANGED:
376 language_prefs_changed();
377 break;
379 case PAGECMD_CLEANUP:
380 language_cleanup();
381 break;
384 return retval;