Generate language popup from language file
This commit is contained in:
parent
1ebe82139e
commit
65ebba7b51
|
@ -281,6 +281,6 @@ void gemtk_obj_mouse_sprite(OBJECT *tree, int index);
|
|||
OBJECT *gemtk_obj_tree_copy(OBJECT *tree);
|
||||
OBJECT * gemtk_obj_create_popup_tree(const char **items, int nitems,
|
||||
char * selected, bool horizontal,
|
||||
int max_width);
|
||||
int max_width, int max_height);
|
||||
void gemtk_obj_destroy_popup_tree(OBJECT * popup);
|
||||
#endif // GEMTK_H_INCLUDED
|
||||
|
|
|
@ -372,7 +372,7 @@ OBJECT *gemtk_obj_tree_copy(OBJECT *tree)
|
|||
|
||||
OBJECT * gemtk_obj_create_popup_tree(const char **items, int nitems,
|
||||
char * selected, bool horizontal,
|
||||
int max_width)
|
||||
int max_width, int max_height)
|
||||
{
|
||||
OBJECT * popup = NULL;
|
||||
int box_width = 0;
|
||||
|
@ -394,14 +394,16 @@ OBJECT * gemtk_obj_create_popup_tree(const char **items, int nitems,
|
|||
int len = strlen(items[i]);
|
||||
|
||||
if (horizontal && (max_width<1)) {
|
||||
box_width += len * char_width;
|
||||
box_width += (len * char_width)+4;
|
||||
}
|
||||
else if (!horizontal){
|
||||
/* Detect max width, used for vertical rendering: */
|
||||
if(len*char_width > box_width){
|
||||
box_width = (len+2) * char_width;
|
||||
}
|
||||
box_height += item_height;
|
||||
//if (max_height < 1) {
|
||||
box_height += item_height;
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -412,6 +414,10 @@ OBJECT * gemtk_obj_create_popup_tree(const char **items, int nitems,
|
|||
if (horizontal) {
|
||||
box_height = item_height;
|
||||
}
|
||||
else if(max_height > 0){
|
||||
// TODO: validate max_height, shrink values larger than screen height
|
||||
//box_height = max_height;
|
||||
}
|
||||
|
||||
/*
|
||||
printf("popup height: %d, popup width: %d\n", box_height, box_width);
|
||||
|
@ -453,8 +459,7 @@ OBJECT * gemtk_obj_create_popup_tree(const char **items, int nitems,
|
|||
flags |= OF_LASTOB;
|
||||
}
|
||||
|
||||
item_width = (horizontal) ? ((int)strlen(items[i])*char_width) : box_width;
|
||||
|
||||
item_width = (horizontal) ? ((int)strlen(items[i])*char_width)+2 : box_width;
|
||||
/*
|
||||
printf("addin popup item \"%s\" (w: %d, h: %d, flags: %x) at %d/%d\n", items[i],
|
||||
item_width, item_height, flags,
|
||||
|
|
116
atari/settings.c
116
atari/settings.c
|
@ -35,6 +35,8 @@ static unsigned int tmp_option_max_fetchers_per_host;
|
|||
static unsigned int tmp_option_max_cached_fetch_handles;
|
||||
static colour tmp_option_atari_toolbar_bg;
|
||||
|
||||
static int num_locales = 0;
|
||||
static char **locales = NULL;
|
||||
static short h_aes_win = 0;
|
||||
static short edit_obj = -1;
|
||||
static short any_obj = -1;
|
||||
|
@ -126,6 +128,50 @@ static void toggle_objects(void)
|
|||
FORMEVENT(SETTINGS_BT_SEL_FONT_RENDERER);
|
||||
}
|
||||
|
||||
static char **read_locales()
|
||||
{
|
||||
char buf[PATH_MAX];
|
||||
char tmp_locale[16];
|
||||
char **locales = NULL;
|
||||
|
||||
FILE * fp_locales = NULL;
|
||||
|
||||
atari_find_resource(buf, "languages", "./res/languages");
|
||||
|
||||
fp_locales = fopen(buf, "r");
|
||||
|
||||
if (fp_locales == NULL) {
|
||||
warn_user("Failed to load locales: %s",buf);
|
||||
return(NULL);
|
||||
} else {
|
||||
LOG(("Reading locales from: %s...", buf));
|
||||
}
|
||||
|
||||
/* Count items: */
|
||||
num_locales = 0;
|
||||
while (fgets(tmp_locale, 16, fp_locales) != NULL) {
|
||||
num_locales++;
|
||||
}
|
||||
|
||||
locales = malloc(sizeof(char*)*num_locales);
|
||||
|
||||
rewind(fp_locales);
|
||||
int i = 0;
|
||||
while (fgets(tmp_locale, 16, fp_locales) != NULL) {
|
||||
int len = strlen(tmp_locale);
|
||||
tmp_locale[len-1] = 0;
|
||||
len--;
|
||||
locales[i] = malloc(len+1);
|
||||
// do not copy the last \n
|
||||
snprintf(locales[i], 16, "%s", tmp_locale);
|
||||
i++;
|
||||
}
|
||||
|
||||
fclose(fp_locales);
|
||||
|
||||
return(locales);
|
||||
}
|
||||
|
||||
|
||||
static void save_settings(void)
|
||||
{
|
||||
|
@ -276,11 +322,6 @@ static void form_event(int index, int external)
|
|||
char * tmp;
|
||||
MENU pop_menu, me_data;
|
||||
|
||||
/*
|
||||
Just a small collection of locales, each country has at least one
|
||||
ATARI-clone user! :)
|
||||
*/
|
||||
int num_locales = 15;
|
||||
short x, y;
|
||||
int choice, i;
|
||||
|
||||
|
@ -333,36 +374,19 @@ static void form_event(int index, int external)
|
|||
case SETTINGS_BT_SEL_FONT_RENDERER:
|
||||
if( external ) {
|
||||
objc_offset(dlgtree, SETTINGS_BT_SEL_FONT_RENDERER, &x, &y);
|
||||
tmp = gemtk_obj_get_text(dlgtree, SETTINGS_BT_SEL_FONT_RENDERER);
|
||||
// point mn_tree tree to font renderer popup:
|
||||
pop_menu.mn_tree = gemtk_obj_create_popup_tree(font_engines,
|
||||
NOF_ELEMENTS(font_engines), NULL, false,-1);
|
||||
NOF_ELEMENTS(font_engines), tmp, false,
|
||||
-1, -1);
|
||||
|
||||
assert(pop_menu.mn_tree != NULL);
|
||||
|
||||
pop_menu.mn_menu = 0;
|
||||
pop_menu.mn_item = 1; // POP_FONT_RENDERER_INTERNAL;
|
||||
pop_menu.mn_item = 1;
|
||||
pop_menu.mn_scroll = SCROLL_NO;
|
||||
pop_menu.mn_keystate = 0;
|
||||
|
||||
|
||||
/* Get font renderer value currently displayed in the dialog: */
|
||||
tmp = gemtk_obj_get_text(dlgtree, SETTINGS_BT_SEL_FONT_RENDERER);
|
||||
|
||||
// find the selected menu item and uncheck others:
|
||||
for(i=pop_menu.mn_item; i<=(short)NOF_ELEMENTS(font_engines); i++) {
|
||||
/* Get string of menu item: */
|
||||
get_string(pop_menu.mn_tree, i, spare);
|
||||
|
||||
/* Compare menu item text with the text currently displayed in GUI: */
|
||||
if (strcasecmp(&spare[2], tmp)) {
|
||||
menu_icheck(pop_menu.mn_tree, i, 0);
|
||||
} else {
|
||||
/* set menu item selected: */
|
||||
menu_icheck(pop_menu.mn_tree, i, 1);
|
||||
}
|
||||
set_string(pop_menu.mn_tree, i, spare);
|
||||
}
|
||||
|
||||
/* Show the popup: */
|
||||
menu_popup(&pop_menu, x, y, &me_data);
|
||||
choice = me_data.mn_item;
|
||||
|
@ -389,33 +413,33 @@ static void form_event(int index, int external)
|
|||
case SETTINGS_BT_SEL_LOCALE:
|
||||
objc_offset(dlgtree, SETTINGS_BT_SEL_LOCALE, &x, &y);
|
||||
|
||||
// point mn_tree tree to states popup:
|
||||
pop_menu.mn_tree = gemtk_obj_get_tree(POP_LANGUAGE);
|
||||
pop_menu.mn_menu = 0;
|
||||
pop_menu.mn_item = POP_LANGUAGE_CS;
|
||||
pop_menu.mn_scroll = SCROLL_NO;
|
||||
pop_menu.mn_keystate = 0;
|
||||
|
||||
// find the selected menu item and uncheck others:
|
||||
for(i=pop_menu.mn_item; i<=num_locales; i++) {
|
||||
get_string(pop_menu.mn_tree, i, spare);
|
||||
tmp = gemtk_obj_get_text(dlgtree, SETTINGS_BT_SEL_LOCALE);
|
||||
if (strcasecmp(&spare[2], tmp)) {
|
||||
menu_icheck(pop_menu.mn_tree, i, 0);
|
||||
} else {
|
||||
menu_icheck(pop_menu.mn_tree, i, 1);
|
||||
}
|
||||
set_string(pop_menu.mn_tree, i, spare);
|
||||
if(num_locales < 1 || locales == NULL){
|
||||
locales = read_locales();
|
||||
}
|
||||
|
||||
if (num_locales < 1 || locales == NULL) {
|
||||
// point mn_tree tree to states popup:
|
||||
num_locales = 15;
|
||||
pop_menu.mn_tree = gemtk_obj_get_tree(POP_LANGUAGE);
|
||||
pop_menu.mn_item = POP_LANGUAGE_CS;
|
||||
} else {
|
||||
// point mn_tree tree to dynamic list:
|
||||
tmp = gemtk_obj_get_text(dlgtree, SETTINGS_BT_SEL_LOCALE);
|
||||
pop_menu.mn_tree = gemtk_obj_create_popup_tree((const char**)locales,
|
||||
num_locales, tmp, false,
|
||||
-1, 100);
|
||||
|
||||
pop_menu.mn_item = 0;
|
||||
}
|
||||
|
||||
pop_menu.mn_menu = 0;
|
||||
pop_menu.mn_scroll = SCROLL_YES;
|
||||
pop_menu.mn_keystate = 0;
|
||||
|
||||
menu_popup(&pop_menu, x, y, &me_data);
|
||||
choice = me_data.mn_item;
|
||||
if( choice > 0 && choice <= num_locales ) {
|
||||
get_string(pop_menu.mn_tree, choice, spare);
|
||||
for(i=2; i<(int)strlen(spare); i++) {
|
||||
spare[i]= (char)tolower(spare[i]);
|
||||
}
|
||||
set_text(SETTINGS_BT_SEL_LOCALE, (char*)&spare[2], 5);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue