summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Mark Bell <jmb@netsurf-browser.org>2004-07-27 20:44:46 +0000
committerJohn Mark Bell <jmb@netsurf-browser.org>2004-07-27 20:44:46 +0000
commit67b0b7be62caf2adba38d5e7d7690eed7f72edb4 (patch)
tree449b63f55332a966e64f28190170ff9219753ce5
parent534b464becb6c429b5976695bfe142690f45b779 (diff)
downloadnetsurf-67b0b7be62caf2adba38d5e7d7690eed7f72edb4.tar.gz
netsurf-67b0b7be62caf2adba38d5e7d7690eed7f72edb4.tar.bz2
[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
-rw-r--r--!NetSurf/Resources/en/Messages2
-rw-r--r--!NetSurf/Resources/fr/Messages2
-rw-r--r--riscos/dialog.c95
-rw-r--r--riscos/gui.h3
-rw-r--r--riscos/menus.c72
-rw-r--r--utils/messages.c17
-rw-r--r--utils/messages.h1
7 files changed, 178 insertions, 14 deletions
diff --git a/!NetSurf/Resources/en/Messages b/!NetSurf/Resources/en/Messages
index 4d80fe981..e1c2e03d5 100644
--- a/!NetSurf/Resources/en/Messages
+++ b/!NetSurf/Resources/en/Messages
@@ -70,6 +70,8 @@ HelpInfo:User information
HelpInter:Interactive help
HelpAbout:About NetSurf
+Languages:Language
+
ProxyAuth:Authentication
ProxyNone:None
ProxyBasic:Basic
diff --git a/!NetSurf/Resources/fr/Messages b/!NetSurf/Resources/fr/Messages
index 82da1bdb9..c8192f5ec 100644
--- a/!NetSurf/Resources/fr/Messages
+++ b/!NetSurf/Resources/fr/Messages
@@ -70,6 +70,8 @@ HelpInfo:Information utilisateur
HelpInter:Aide interactive
HelpAbout: propos de NetSurf
+Languages:Language
+
ProxyAuth:Authentication
ProxyNone:None
ProxyBasic:Basic
diff --git a/riscos/dialog.c b/riscos/dialog.c
index bb46258ca..aa7eb598f 100644
--- a/riscos/dialog.c
+++ b/riscos/dialog.c
@@ -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.
diff --git a/riscos/gui.h b/riscos/gui.h
index 54c4215ca..5374ce91f 100644
--- a/riscos/gui.h
+++ b/riscos/gui.h
@@ -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);
diff --git a/riscos/menus.c b/riscos/menus.c
index ad35df084..079c01c5f 100644
--- a/riscos/menus.c
+++ b/riscos/menus.c
@@ -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) {
diff --git a/utils/messages.c b/utils/messages.c
index 4d07a47ef..f2ed3e037 100644
--- a/utils/messages.c
+++ b/utils/messages.c
@@ -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.
diff --git a/utils/messages.h b/utils/messages.h
index 4ca079293..33b2fc3f4 100644
--- a/utils/messages.h
+++ b/utils/messages.h
@@ -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