2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
9 /*********************************************************************************************/
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
;
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
;
46 h
= dri
->dri_Font
->tf_YSize
+ BUTTON_EXTRAHEIGHT
;
48 h
+= dri
->dri_Font
->tf_YSize
* 8;
52 DeinitRastPort(&temprp
);
57 /*********************************************************************************************/
59 static LONG
language_makegadgets(void)
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
);
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
,
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
,
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)
108 struct Window
*winparam
= page_active
? win
: NULL
;
110 GT_SetGadgetAttrs(availgad
, winparam
, NULL
, GTLV_Labels
, (IPTR
) NULL
,
113 GT_SetGadgetAttrs(prefgad
, winparam
, NULL
, GTLV_Labels
, (IPTR
) NULL
,
118 /*********************************************************************************************/
120 static void reset_listviews(void)
124 struct Window
*winparam
= page_active
? win
: NULL
;
126 GT_SetGadgetAttrs(availgad
, winparam
, NULL
, GTLV_Labels
, (IPTR
)&language_list
,
129 GT_SetGadgetAttrs(prefgad
, winparam
, NULL
, GTLV_Labels
, (IPTR
)&pref_language_list
,
134 /*********************************************************************************************/
136 static void clear_languages(void)
138 struct Node
*node
, *node2
;
140 ForeachNodeSafe(&pref_language_list
, node
, node2
)
143 SortInNode(&language_list
, node
);
147 /*********************************************************************************************/
149 static void update_prefs(void)
151 struct LanguageEntry
*entry
;
154 ForeachNode(&pref_language_list
, entry
)
156 strcpy(localeprefs
.lp_PreferredLanguages
[i
], entry
->lve
.realname
);
161 if (i
< 10) localeprefs
.lp_PreferredLanguages
[i
][0] = '\0';
164 /*********************************************************************************************/
166 static LONG
language_input(struct IntuiMessage
*msg
)
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
)))
183 AddTail(&pref_language_list
, node
);
192 case MSG_GAD_PREF_LANGUAGES
:
193 if ((node
= FindListNode(&pref_language_list
, msg
->Code
)))
198 SortInNode(&language_list
, node
);
207 case MSG_GAD_CLEAR_LANGUAGES
:
218 else if (msg
->Class
== IDCMP_RAWKEY
)
224 case RAWKEY_NM_WHEEL_UP
:
228 case RAWKEY_NM_WHEEL_DOWN
:
239 struct Gadget
*lvgad
= NULL
;
241 if ((win
->MouseX
>= availleft
) &&
242 (win
->MouseY
>= availtop
) &&
243 (win
->MouseX
< availleft
+ availwidth
) &&
244 (win
->MouseY
< availtop
+ availheight
))
248 else if ((win
->MouseX
>= prefleft
) &&
249 (win
->MouseY
>= preftop
) &&
250 (win
->MouseX
< prefleft
+ prefwidth
) &&
251 (win
->MouseY
< preftop
+ prefheight
))
258 ScrollListview(lvgad
, delta
);
268 /*********************************************************************************************/
270 static void language_cleanup(void)
272 if (gadlist
) FreeGadgets(gadlist
);
276 /*********************************************************************************************/
278 static void language_prefs_changed(void)
280 struct LanguageEntry
*entry
, *entry2
;
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
);
305 /*********************************************************************************************/
307 LONG
page_language_handler(LONG cmd
, IPTR param
)
317 retval
= language_layout();
320 case PAGECMD_GETMINWIDTH
:
324 case PAGECMD_GETMINHEIGHT
:
328 case PAGECMD_SETDOMLEFT
:
332 case PAGECMD_SETDOMTOP
:
336 case PAGECMD_SETDOMWIDTH
:
340 case PAGECMD_SETDOMHEIGHT
:
344 case PAGECMD_MAKEGADGETS
:
345 retval
= language_makegadgets();
348 case PAGECMD_ADDGADGETS
:
351 AddGList(win
, gadlist
, -1, -1, NULL
);
352 GT_RefreshWindow(win
, NULL
);
353 RefreshGList(gadlist
, win
, NULL
, -1);
359 case PAGECMD_REMGADGETS
:
362 if (gadlist
) RemoveGList(win
, gadlist
, -1);
368 case PAGECMD_HANDLEINPUT
:
369 retval
= language_input((struct IntuiMessage
*)param
);
372 case PAGECMD_PREFS_CHANGING
:
375 case PAGECMD_PREFS_CHANGED
:
376 language_prefs_changed();
379 case PAGECMD_CLEANUP
: