[project @ 2004-07-27 20:44:46 by jmb]

Language configuration menu
Make adjust clicks on font size arrows style guide compliant

svn path=/import/netsurf/; revision=1154
This commit is contained in:
John Mark Bell 2004-07-27 20:44:46 +00:00
parent 534b464bec
commit 67b0b7be62
7 changed files with 178 additions and 14 deletions

View File

@ -70,6 +70,8 @@ HelpInfo:User information
HelpInter:Interactive help
HelpAbout:About NetSurf
Languages:Language
ProxyAuth:Authentication
ProxyNone:None
ProxyBasic:Basic

View File

@ -70,6 +70,8 @@ HelpInfo:Information utilisateur
HelpInter:Aide interactive
HelpAbout:À propos de NetSurf
Languages:Language
ProxyAuth:Authentication
ProxyNone:None
ProxyBasic:Basic

View File

@ -47,6 +47,9 @@ static int ro_gui_choices_http_proxy_auth;
static char *theme_choice = 0;
static struct theme_entry *theme_list = 0;
static unsigned int theme_list_entries = 0;
static int config_br_icon = -1;
static const char *ro_gui_choices_lang = 0;
static const char *ro_gui_choices_alang = 0;
static const char *ro_gui_proxy_auth_name[] = {
"ProxyNone", "ProxyBasic", "ProxyNTLM"
@ -483,6 +486,16 @@ void ro_gui_dialog_config_set(void)
option_open_browser_at_startup = ro_gui_get_icon_selected_state(
dialog_config_br,
ICON_CONFIG_BR_OPENBROWSER);
if (ro_gui_choices_lang) {
free(option_language);
option_language = strdup(ro_gui_choices_lang);
ro_gui_choices_lang = 0;
}
if (ro_gui_choices_alang) {
free(option_accept_language);
option_accept_language = strdup(ro_gui_choices_alang);
ro_gui_choices_alang = 0;
}
/* proxy pane */
option_http_proxy = ro_gui_choices_http_proxy;
@ -584,11 +597,19 @@ void ro_gui_save_options(void)
void ro_gui_dialog_click_config_br(wimp_pointer *pointer)
{
int stepping = 1;
if (pointer->buttons == wimp_CLICK_ADJUST)
stepping = -stepping;
switch (pointer->i) {
case ICON_CONFIG_BR_FONTSIZE_DEC:
if (ro_gui_choices_font_size == 50)
break;
ro_gui_choices_font_size--;
ro_gui_choices_font_size -= stepping;
if (ro_gui_choices_font_size < 50)
ro_gui_choices_font_size = 50;
if (ro_gui_choices_font_size > 1000)
ro_gui_choices_font_size = 1000;
if (ro_gui_choices_font_size <
ro_gui_choices_font_min_size)
ro_gui_choices_font_min_size =
@ -596,30 +617,80 @@ void ro_gui_dialog_click_config_br(wimp_pointer *pointer)
ro_gui_dialog_update_config_br();
break;
case ICON_CONFIG_BR_FONTSIZE_INC:
if (ro_gui_choices_font_size == 1000)
break;
ro_gui_choices_font_size++;
ro_gui_choices_font_size += stepping;
if (ro_gui_choices_font_size < 50)
ro_gui_choices_font_size = 50;
if (ro_gui_choices_font_size > 1000)
ro_gui_choices_font_size = 1000;
ro_gui_dialog_update_config_br();
break;
case ICON_CONFIG_BR_MINSIZE_DEC:
if (ro_gui_choices_font_min_size == 10)
break;
ro_gui_choices_font_min_size--;
ro_gui_choices_font_min_size -= stepping;
if (ro_gui_choices_font_min_size < 10)
ro_gui_choices_font_min_size = 10;
if (ro_gui_choices_font_min_size > 500)
ro_gui_choices_font_min_size = 500;
ro_gui_dialog_update_config_br();
break;
case ICON_CONFIG_BR_MINSIZE_INC:
if (ro_gui_choices_font_min_size == 500)
break;
ro_gui_choices_font_min_size++;
ro_gui_choices_font_min_size += stepping;
if (ro_gui_choices_font_min_size < 10)
ro_gui_choices_font_min_size = 10;
if (ro_gui_choices_font_min_size > 500)
ro_gui_choices_font_min_size = 500;
if (ro_gui_choices_font_size <
ro_gui_choices_font_min_size)
ro_gui_choices_font_size =
ro_gui_choices_font_min_size;
ro_gui_dialog_update_config_br();
break;
case ICON_CONFIG_BR_LANG_PICK:
/* drop through */
case ICON_CONFIG_BR_ALANG_PICK:
config_br_icon = pointer->i;
ro_gui_popup_menu(languages_menu, dialog_config_br, pointer->i);
break;
}
}
/**
* Handle a selection from the language selection popup menu.
*
* \param lang The language name (as returned by messages_get)
*/
void ro_gui_dialog_languages_menu_selection(char *lang)
{
int offset = strlen("lang_");
const char *temp = messages_get_key(lang);
if (temp == NULL) {
warn_user("MiscError", "Failed to retrieve message key");
config_br_icon = -1;
return;
}
switch (config_br_icon) {
case ICON_CONFIG_BR_LANG_PICK:
ro_gui_choices_lang = temp + offset;
ro_gui_set_icon_string(dialog_config_br,
ICON_CONFIG_BR_LANG,
lang);
break;
case ICON_CONFIG_BR_ALANG_PICK:
ro_gui_choices_alang = temp + offset;
ro_gui_set_icon_string(dialog_config_br,
ICON_CONFIG_BR_ALANG,
lang);
break;
}
/* invalidate icon number and update window */
config_br_icon = -1;
ro_gui_dialog_update_config_br();
}
/**
* Update font size icons in browser choices pane.

View File

@ -30,7 +30,7 @@ extern wimp_w dialog_info, dialog_saveas, dialog_config, dialog_config_br,
extern wimp_w history_window;
extern wimp_w hotlist_window;
extern wimp_menu *iconbar_menu, *browser_menu, *combo_menu, *hotlist_menu,
*proxyauth_menu;
*proxyauth_menu, *languages_menu;
extern int iconbar_menu_height;
extern struct form_control *current_gadget;
extern bool gui_reformat_pending;
@ -133,6 +133,7 @@ void ro_gui_redraw_config_th_pane(wimp_draw *redraw);
void ro_gui_menu_prepare_hotlist(void);
void ro_gui_dialog_open_config(void);
void ro_gui_dialog_proxyauth_menu_selection(int item);
void ro_gui_dialog_languages_menu_selection(char *lang);
/* in download.c */
void ro_gui_download_init(void);

View File

@ -15,6 +15,7 @@
#include <stdlib.h>
#include <string.h>
#include "oslib/os.h"
#include "oslib/osgbpb.h"
#include "oslib/wimp.h"
#include "oslib/wimpspriteop.h"
#include "netsurf/desktop/gui.h"
@ -43,6 +44,7 @@
#define MENU_HELP 5
static void translate_menu(wimp_menu *menu);
static void build_languages_menu(void);
static void ro_gui_menu_prepare_images(void);
static void ro_gui_menu_prepare_window(void);
static void ro_gui_menu_prepare_toolbars(void);
@ -383,7 +385,7 @@ static wimp_MENU(4) hotlist_root = {
wimp_menu *hotlist_menu = (wimp_menu *)&hotlist_root;
/* Proxy auth popup menu (used in proxy Choices dialog
/* Proxy auth popup menu (used in proxy Choices dialog)
*/
static wimp_MENU(3) proxy_menu = {
{ "ProxyAuth" }, 7,2,7,0, 200, 44, 0,
@ -395,6 +397,9 @@ static wimp_MENU(3) proxy_menu = {
};
wimp_menu *proxyauth_menu = (wimp_menu *) &proxy_menu;
/* Languages popup menu (used in browser choices dialog)
*/
wimp_menu *languages_menu = NULL;
static wimp_menu *browser_page_menu = (wimp_menu *)&page_menu;
static wimp_menu *browser_export_menu = (wimp_menu *)&export_menu;
@ -455,6 +460,8 @@ void ro_gui_menus_init(void)
translate_menu(proxyauth_menu);
build_languages_menu();
iconbar_menu->entries[0].sub_menu = (wimp_menu *) dialog_info;
browser_page_menu->entries[0].sub_menu = (wimp_menu*) dialog_pageinfo;
browser_object_menu->entries[0].sub_menu = (wimp_menu*) dialog_objinfo;
@ -500,6 +507,67 @@ void translate_menu(wimp_menu *menu)
} while ((menu->entries[i - 1].menu_flags & wimp_MENU_LAST) == 0);
}
/**
* Builds the languages menu based on available translations
*/
void build_languages_menu(void)
{
int context = 0, read_count, entries = 0;
os_error *e;
osgbpb_INFO(100) info;
char lang[8] = {0};
char *lang_name;
void *temp;
languages_menu = calloc(1, wimp_SIZEOF_MENU(1));
if (!languages_menu) {
LOG(("No memory for languages menu"));
die("Insufficient memory for languages menu");
}
languages_menu->title_data.indirected_text.text = messages_get("Languages");
languages_menu->title_fg = wimp_COLOUR_BLACK;
languages_menu->title_bg = wimp_COLOUR_LIGHT_GREY;
languages_menu->work_fg = wimp_COLOUR_BLACK;
languages_menu->work_bg = wimp_COLOUR_WHITE;
languages_menu->width = 300;
languages_menu->height = 44;
languages_menu->gap = 0;
while (context != -1) {
e = xosgbpb_dir_entries_info("<NetSurf$Dir>.Resources", (osgbpb_info_list*)&info, 1, context, sizeof(info), 0, &read_count, &context);
if (e)
die(e->errmess);
if (read_count == 0)
continue;
if (info.obj_type != fileswitch_IS_DIR)
continue;
snprintf(lang, sizeof lang, "lang_%2s", info.name);
if ((lang_name = messages_get(lang)) == NULL ||
strlen(info.name) != 2)
continue;
temp = realloc(languages_menu, wimp_SIZEOF_MENU(entries+1));
if (!temp)
die("Insufficient memory for languages menu");
languages_menu = temp;
languages_menu->entries[entries].menu_flags = 0;
languages_menu->entries[entries].sub_menu = wimp_NO_SUB_MENU;
languages_menu->entries[entries].icon_flags = wimp_ICON_TEXT | wimp_ICON_FILLED | wimp_ICON_INDIRECTED | (wimp_COLOUR_BLACK << wimp_ICON_FG_COLOUR_SHIFT) | (wimp_COLOUR_WHITE << wimp_ICON_BG_COLOUR_SHIFT);
languages_menu->entries[entries].data.indirected_text.text = lang_name;
languages_menu->entries[entries].data.indirected_text.validation = (char *)-1;
languages_menu->entries[entries].data.indirected_text.size = strlen(lang_name) + 1;
entries++;
}
languages_menu->entries[0].menu_flags |= wimp_MENU_TITLE_INDIRECTED;
languages_menu->entries[entries-1].menu_flags |= wimp_MENU_LAST;
}
/**
* Display a menu.
@ -904,6 +972,8 @@ void ro_gui_menu_selection(wimp_selection *selection)
} else if (current_menu == proxyauth_menu) {
ro_gui_dialog_proxyauth_menu_selection(selection->items[0]);
} else if (current_menu == languages_menu) {
ro_gui_dialog_languages_menu_selection(languages_menu->entries[selection->items[0]].data.indirected_text.text);
}
if (pointer.buttons == wimp_CLICK_ADJUST) {

View File

@ -121,6 +121,23 @@ const char *messages_get(const char *key)
return entry->value;
}
/**
* Retrieve the key associated with a value
*
* \param value The value as returned by messages_get
* \return The key associated with the value or NULL if not found
*/
const char *messages_get_key(const char *value)
{
const char *key = value - MAX_KEY_LENGTH;
const char *temp_value = messages_get(key);
if (strcmp(value, temp_value) == 0)
return key;
return NULL;
}
/**
* Hash function for keys.

View File

@ -23,6 +23,7 @@
void messages_load(const char *path);
const char *messages_get(const char *key);
const char *messages_get_key(const char *value);
void messages_dump(void);
#endif