diff options
Diffstat (limited to 'riscos/configure/con_fonts.c')
-rw-r--r-- | riscos/configure/con_fonts.c | 110 |
1 files changed, 98 insertions, 12 deletions
diff --git a/riscos/configure/con_fonts.c b/riscos/configure/con_fonts.c index 410d7db89..b9bbdc64e 100644 --- a/riscos/configure/con_fonts.c +++ b/riscos/configure/con_fonts.c @@ -7,12 +7,15 @@ #include "netsurf/desktop/options.h" #include "netsurf/riscos/dialog.h" +#include "netsurf/riscos/gui.h" #include "netsurf/riscos/menus.h" #include "netsurf/riscos/options.h" #include "netsurf/riscos/wimp.h" #include "netsurf/riscos/wimp_event.h" #include "netsurf/riscos/configure.h" #include "netsurf/riscos/configure/configure.h" +#include "netsurf/utils/messages.h" +#include "netsurf/utils/utils.h" #define FONT_SANS_FIELD 3 @@ -37,10 +40,17 @@ #define FONT_CANCEL_BUTTON 33 #define FONT_OK_BUTTON 34 +/* This menu only ever gets created once */ +/** \todo The memory claimed for this menu should + * probably be released at some point */ +static wimp_menu *default_menu; + static void ro_gui_options_fonts_default(wimp_pointer *pointer); static bool ro_gui_options_fonts_ok(wimp_w w); +static bool ro_gui_options_fonts_init_menu(void); -bool ro_gui_options_fonts_initialise(wimp_w w) { +bool ro_gui_options_fonts_initialise(wimp_w w) +{ /* set the current values */ ro_gui_set_icon_decimal(w, FONT_DEFAULT_SIZE, option_font_size, 1); ro_gui_set_icon_decimal(w, FONT_MINIMUM_SIZE, option_font_min_size, 1); @@ -52,7 +62,10 @@ bool ro_gui_options_fonts_initialise(wimp_w w) { ro_gui_set_icon_string(w, FONT_DEFAULT_FIELD, css_font_family_name[option_font_default]); - /* initialise all functions for a newly created window */ + if (!ro_gui_options_fonts_init_menu()) + return false; + + /* initialise all functions for a newly created window */ ro_gui_wimp_event_register_menu_gright(w, FONT_SANS_FIELD, FONT_SANS_MENU, font_menu); ro_gui_wimp_event_register_menu_gright(w, FONT_SERIF_FIELD, @@ -63,7 +76,8 @@ bool ro_gui_options_fonts_initialise(wimp_w w) { FONT_CURSIVE_MENU, font_menu); ro_gui_wimp_event_register_menu_gright(w, FONT_FANTASY_FIELD, FONT_FANTASY_MENU, font_menu); - /* todo: default family menu */ + ro_gui_wimp_event_register_menu_gright(w, FONT_DEFAULT_FIELD, + FONT_DEFAULT_MENU, default_menu); ro_gui_wimp_event_register_numeric_field(w, FONT_DEFAULT_SIZE, FONT_DEFAULT_INC, FONT_DEFAULT_DEC, 50, 1000, 1, 1); ro_gui_wimp_event_register_numeric_field(w, FONT_MINIMUM_SIZE, @@ -79,20 +93,37 @@ bool ro_gui_options_fonts_initialise(wimp_w w) { } -void ro_gui_options_fonts_default(wimp_pointer *pointer) { +void ro_gui_options_fonts_default(wimp_pointer *pointer) +{ + const char *fallback = nsfont_fallback_font(); + /* set the default values */ ro_gui_set_icon_decimal(pointer->w, FONT_DEFAULT_SIZE, 100, 1); ro_gui_set_icon_decimal(pointer->w, FONT_MINIMUM_SIZE, 70, 1); - /* todo: default font families */ + ro_gui_set_icon_string(pointer->w, FONT_SANS_FIELD, + nsfont_exists("Homerton") ? "Homerton" : fallback); + ro_gui_set_icon_string(pointer->w, FONT_SERIF_FIELD, + nsfont_exists("Trinity") ? "Trinity" : fallback); + ro_gui_set_icon_string(pointer->w, FONT_MONOSPACE_FIELD, + nsfont_exists("Corpus") ? "Corpus" : fallback); + ro_gui_set_icon_string(pointer->w, FONT_CURSIVE_FIELD, + nsfont_exists("Churchill") ? "Churchill" : fallback); + ro_gui_set_icon_string(pointer->w, FONT_FANTASY_FIELD, + nsfont_exists("Sassoon") ? "Sassoon" : fallback); + ro_gui_set_icon_string(pointer->w, FONT_DEFAULT_FIELD, + css_font_family_name[1]); } -bool ro_gui_options_fonts_ok(wimp_w w) { - option_font_size = ro_gui_get_icon_decimal(w, FONT_DEFAULT_SIZE, 1); - option_font_min_size = ro_gui_get_icon_decimal(w, FONT_MINIMUM_SIZE, 1); - if (option_font_size < option_font_min_size) { - option_font_size = option_font_min_size; +bool ro_gui_options_fonts_ok(wimp_w w) +{ + unsigned int i; + + option_font_size = ro_gui_get_icon_decimal(w, FONT_DEFAULT_SIZE, 1); + option_font_min_size = ro_gui_get_icon_decimal(w, FONT_MINIMUM_SIZE, 1); + if (option_font_size < option_font_min_size) { + option_font_size = option_font_min_size; ro_gui_set_icon_decimal(w, FONT_DEFAULT_SIZE, option_font_size, 1); - } + } free(option_font_sans); option_font_sans = strdup(ro_gui_get_icon_string(w, FONT_SANS_FIELD)); free(option_font_serif); @@ -103,7 +134,62 @@ bool ro_gui_options_fonts_ok(wimp_w w) { option_font_cursive = strdup(ro_gui_get_icon_string(w, FONT_CURSIVE_FIELD)); free(option_font_fantasy); option_font_fantasy = strdup(ro_gui_get_icon_string(w, FONT_FANTASY_FIELD)); - /* todo: default family */ + + for (i = 0; i != 5; i++) { + if (!strcmp(css_font_family_name[i+1], + ro_gui_get_icon_string(w, + FONT_DEFAULT_FIELD))) + break; + } + if (i == 5) + /* this should never happen, but still */ + i = 0; + + option_font_default = i + 1; + ro_gui_save_options(); return true; } + +bool ro_gui_options_fonts_init_menu(void) +{ + unsigned int i; + + if (default_menu) + /* Already exists */ + return true; + + default_menu = malloc(wimp_SIZEOF_MENU(5)); + if (!default_menu) { + warn_user("NoMemory", 0); + return false; + } + default_menu->title_data.indirected_text.text = + messages_get("DefaultFonts"); + default_menu->title_fg = wimp_COLOUR_BLACK; + default_menu->title_bg = wimp_COLOUR_LIGHT_GREY; + default_menu->work_fg = wimp_COLOUR_BLACK; + default_menu->work_bg = wimp_COLOUR_WHITE; + default_menu->width = 200; + default_menu->height = wimp_MENU_ITEM_HEIGHT; + default_menu->gap = wimp_MENU_ITEM_GAP; + + for (i = 0; i != 5; i++) { + default_menu->entries[i].menu_flags = 0; + default_menu->entries[i].sub_menu = wimp_NO_SUB_MENU; + default_menu->entries[i].icon_flags = wimp_ICON_TEXT | + wimp_ICON_INDIRECTED | + (wimp_COLOUR_BLACK << wimp_ICON_FG_COLOUR_SHIFT) | + (wimp_COLOUR_WHITE << wimp_ICON_BG_COLOUR_SHIFT); + default_menu->entries[i].data.indirected_text.text = + css_font_family_name[i+1]; + default_menu->entries[i].data.indirected_text.validation = + (char *)-1; + default_menu->entries[i].data.indirected_text.size = + strlen(css_font_family_name[i+1]); + } + default_menu->entries[0].menu_flags = wimp_MENU_TITLE_INDIRECTED; + default_menu->entries[i-1].menu_flags |= wimp_MENU_LAST; + + return true; +} |