From dace6363292a09129fd44dfb8117f930b162a01d Mon Sep 17 00:00:00 2001 From: James Bursa Date: Thu, 24 Feb 2005 22:00:41 +0000 Subject: [project @ 2005-02-24 22:00:40 by bursa] Reimplement font family support, part 2 (font menus in choices). svn path=/import/netsurf/; revision=1525 --- riscos/dialog.c | 41 ++++++------------ riscos/font.c | 45 +++++++++++++++++++ riscos/gui.h | 5 ++- riscos/menus.c | 132 +++++++++++++------------------------------------------- 4 files changed, 93 insertions(+), 130 deletions(-) (limited to 'riscos') diff --git a/riscos/dialog.c b/riscos/dialog.c index ab14b1039..96ca05328 100644 --- a/riscos/dialog.c +++ b/riscos/dialog.c @@ -3,7 +3,7 @@ * Licensed under the GNU General Public License, * http://www.opensource.org/licenses/gpl-license * Copyright 2003 Phil Mellor - * Copyright 2004 James Bursa + * Copyright 2005 James Bursa * Copyright 2003 John M Bell * Copyright 2004 Richard Wilson * Copyright 2004 Andrew Timmins @@ -18,6 +18,7 @@ #include "oslib/osgbpb.h" #include "oslib/osspriteop.h" #include "oslib/wimp.h" +#include "rufl.h" #include "netsurf/utils/config.h" #include "netsurf/desktop/netsurf.h" #include "netsurf/render/font.h" @@ -1117,15 +1118,19 @@ void ro_gui_dialog_click_config_font(wimp_pointer *pointer) ro_gui_choices_font_min_size; ro_gui_dialog_update_config_font(); break; + case ICON_CONFIG_FONT_SANS: case ICON_CONFIG_FONT_SANS_PICK: + case ICON_CONFIG_FONT_SERIF: case ICON_CONFIG_FONT_SERIF_PICK: + case ICON_CONFIG_FONT_MONO: case ICON_CONFIG_FONT_MONO_PICK: + case ICON_CONFIG_FONT_CURS: case ICON_CONFIG_FONT_CURS_PICK: + case ICON_CONFIG_FONT_FANT: case ICON_CONFIG_FONT_FANT_PICK: - /*config_font_icon = pointer->i - 1; - ro_gui_display_font_menu(ro_gui_get_icon_string( - dialog_config_font, pointer->i - 1), - dialog_config_font, pointer->i);*/ + config_font_icon = pointer->i & ~1; + ro_gui_popup_menu(font_menu, dialog_config_font, + pointer->i | 1); break; case ICON_CONFIG_FONT_DEF_PICK: break; @@ -1137,30 +1142,12 @@ void ro_gui_dialog_click_config_font(wimp_pointer *pointer) * Handle font menu selections. */ -void ro_gui_dialog_font_menu_selection(char *name) +void ro_gui_dialog_font_menu_selection(int item) { - char *n, *fn; - int len; - - if (strlen(name) <= 3 || config_font_icon < 0) - return; - - n = name + 2; /* \F */ - - len = strcspn(n, "\\"); - - fn = calloc(len+1, sizeof(char)); - if (!fn) { - LOG(("malloc failed")); + if (item < 0 || rufl_family_list_entries <= (unsigned int) item) return; - } - - strncpy(fn, n, len); - ro_gui_set_icon_string(dialog_config_font, config_font_icon, fn); - - free(fn); - - config_font_icon = -1; + ro_gui_set_icon_string(dialog_config_font, config_font_icon, + rufl_family_list[item]); } diff --git a/riscos/font.c b/riscos/font.c index ee9229b7d..c3986b2db 100644 --- a/riscos/font.c +++ b/riscos/font.c @@ -13,6 +13,7 @@ #include #include +#include "oslib/wimp.h" #include "rufl.h" #include "netsurf/css/css.h" #include "netsurf/render/font.h" @@ -23,11 +24,15 @@ #include "netsurf/utils/utils.h" +wimp_menu *font_menu; + + static void nsfont_check_option(char **option, const char *family, const char *fallback); static bool nsfont_exists(const char *font_family); static int nsfont_list_cmp(const void *keyval, const void *datum); static void nsfont_check_fonts(void); +static void nsfont_init_menu(void); static void nsfont_read_style(const struct css_style *style, const char **font_family, unsigned int *font_size, rufl_style *font_style); @@ -77,6 +82,8 @@ void nsfont_init(void) option_font_default != CSS_FONT_FAMILY_CURSIVE && option_font_default != CSS_FONT_FAMILY_FANTASY) option_font_default = CSS_FONT_FAMILY_SANS_SERIF; + + nsfont_init_menu(); } @@ -167,6 +174,44 @@ void nsfont_check_fonts(void) } +/** + * Prepare the menu of font families. + */ + +void nsfont_init_menu(void) +{ + unsigned int i; + + font_menu = malloc(wimp_SIZEOF_MENU(rufl_family_list_entries)); + if (!font_menu) + die("NoMemory"); + font_menu->title_data.indirected_text.text = messages_get("Fonts"); + font_menu->title_fg = wimp_COLOUR_BLACK; + font_menu->title_bg = wimp_COLOUR_LIGHT_GREY; + font_menu->work_fg = wimp_COLOUR_BLACK; + font_menu->work_bg = wimp_COLOUR_WHITE; + font_menu->width = 200; + font_menu->height = wimp_MENU_ITEM_HEIGHT; + font_menu->gap = wimp_MENU_ITEM_GAP; + for (i = 0; i != rufl_family_list_entries; i++) { + font_menu->entries[i].menu_flags = 0; + font_menu->entries[i].sub_menu = wimp_NO_SUB_MENU; + font_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); + font_menu->entries[i].data.indirected_text.text = + rufl_family_list[i]; + font_menu->entries[i].data.indirected_text.validation = + (char *) -1; + font_menu->entries[i].data.indirected_text.size = + strlen(rufl_family_list[i]); + } + font_menu->entries[0].menu_flags = wimp_MENU_TITLE_INDIRECTED; + font_menu->entries[i - 1].menu_flags |= wimp_MENU_LAST; +} + + /** * Measure the width of a string. * diff --git a/riscos/gui.h b/riscos/gui.h index 85e9ea391..47844115e 100644 --- a/riscos/gui.h +++ b/riscos/gui.h @@ -35,7 +35,8 @@ extern wimp_w dialog_info, dialog_saveas, dialog_config, dialog_config_br, extern wimp_w history_window; extern wimp_menu *iconbar_menu, *browser_menu, *combo_menu, *hotlist_menu, *proxyauth_menu, *languages_menu, *toolbar_menu, - *image_quality_menu, *global_history_menu, *url_suggest_menu; + *image_quality_menu, *global_history_menu, *url_suggest_menu, + *font_menu; extern int iconbar_menu_height; extern struct form_control *current_gadget; extern bool gui_reformat_pending; @@ -142,7 +143,7 @@ void ro_gui_dialog_open_config(void); void ro_gui_dialog_proxyauth_menu_selection(int item); void ro_gui_dialog_image_menu_selection(int item); void ro_gui_dialog_languages_menu_selection(char *lang); -void ro_gui_dialog_font_menu_selection(char *name); +void ro_gui_dialog_font_menu_selection(int item); void ro_gui_dialog_redraw(wimp_draw *redraw); /* in download.c */ diff --git a/riscos/menus.c b/riscos/menus.c index 15c0987d3..44ad4a6db 100644 --- a/riscos/menus.c +++ b/riscos/menus.c @@ -3,7 +3,7 @@ * Licensed under the GNU General Public License, * http://www.opensource.org/licenses/gpl-license * Copyright 2003 Phil Mellor - * Copyright 2004 James Bursa + * Copyright 2005 James Bursa * Copyright 2003 John M Bell * Copyright 2005 Richard Wilson */ @@ -62,7 +62,6 @@ static void ro_gui_menu_object_reload(void); static void ro_gui_menu_browser_warning(wimp_message_menu_warning *warning); static void ro_gui_menu_hotlist_warning(wimp_message_menu_warning *warning); static void ro_gui_menu_global_history_warning(wimp_message_menu_warning *warning); -static void ro_gui_font_menu_selection(wimp_selection *selection); struct gui_window *current_gui; wimp_menu *current_menu; @@ -509,11 +508,6 @@ wimp_menu *languages_menu = NULL; */ wimp_menu *toolbar_icon_menu = NULL; -/* Font popup menu (used in font choices dialog) -*/ -static wimp_menu *font_menu = NULL; -static byte *font_menu_data = NULL; - /* URL suggestion menu */ static wimp_MENU(GLOBAL_HISTORY_RECENT_URLS) url_suggest; @@ -709,11 +703,11 @@ bool ro_gui_menu_prepare_url_suggest(void) { char **suggest_text; int suggestions; int i; - + suggest_text = global_history_get_recent(&suggestions); if (suggestions < 1) return false; - + url_suggest_menu->title_data.indirected_text.text = messages_get("URLSuggest"); url_suggest_menu->title_fg = wimp_COLOUR_BLACK; url_suggest_menu->title_bg = wimp_COLOUR_LIGHT_GREY; @@ -822,20 +816,41 @@ void ro_gui_create_menu(wimp_menu *menu, int x, int y, struct gui_window *g) /** * Display a pop-up menu next to the specified icon. + * + * \param menu menu to open + * \param w window handle + * \param i icon handle */ void ro_gui_popup_menu(wimp_menu *menu, wimp_w w, wimp_i i) { wimp_window_state state; wimp_icon_state icon_state; + os_error *error; + state.w = w; icon_state.w = w; icon_state.i = i; - wimp_get_window_state(&state); - wimp_get_icon_state(&icon_state); + error = xwimp_get_window_state(&state); + if (error) { + LOG(("xwimp_get_window_state: 0x%x: %s", + error->errnum, error->errmess)); + warn_user("MenuError", error->errmess); + return; + } + + error = xwimp_get_icon_state(&icon_state); + if (error) { + LOG(("xwimp_get_icon_state: 0x%x: %s", + error->errnum, error->errmess)); + warn_user("MenuError", error->errmess); + return; + } + ro_gui_create_menu(menu, state.visible.x0 + icon_state.icon.extent.x1 + 64, - state.visible.y1 + icon_state.icon.extent.y1 - state.yscroll, current_gui); + state.visible.y1 + icon_state.icon.extent.y1 - + state.yscroll, current_gui); } @@ -1292,9 +1307,11 @@ void ro_gui_menu_selection(wimp_selection *selection) } else if (current_menu == image_quality_menu) { ro_gui_dialog_image_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); + ro_gui_dialog_languages_menu_selection(languages_menu-> + entries[selection->items[0]]. + data.indirected_text.text); } else if (current_menu == font_menu) { - ro_gui_font_menu_selection(selection); + ro_gui_dialog_font_menu_selection(selection->items[0]); } if (pointer.buttons == wimp_CLICK_ADJUST) { @@ -2309,90 +2326,3 @@ void gui_create_form_select_menu(struct browser_window *bw, ro_gui_create_menu(gui_form_select_menu, pointer.pos.x, pointer.pos.y, bw->window); } - -/** - * Create and display a menu listing all fonts present in the system. - * - * \param tick The name of the currently selected font - * \param w The dialog containing the clicked icon - * \param i The clicked icon. - */ -void ro_gui_display_font_menu(const char *tick, wimp_w w, wimp_i i) -{ - int size1, size2; - os_error *error; - - error = xfont_list_fonts(0, font_RETURN_FONT_MENU | font_GIVEN_TICK, - 0, 0, 0, tick, 0, &size1, &size2); - if (error) { - LOG(("xfont_list_fonts: 0x%x: %s", - error->errnum, error->errmess)); - return; - } - - /* free previous menu */ - if (font_menu) - free(font_menu); - if (font_menu_data) - free(font_menu_data); - - font_menu = calloc(size1, sizeof(byte)); - if (!font_menu) { - LOG(("malloc failed")); - return; - } - font_menu_data = calloc(size2, sizeof(byte)); - if (!font_menu_data) { - LOG(("malloc failed")); - return; - } - - error = xfont_list_fonts((byte*)font_menu, - font_RETURN_FONT_MENU | font_GIVEN_TICK, - size1, font_menu_data, size2, tick, 0, 0, 0); - if (error) { - LOG(("xfont_list_fonts: 0x%x: %s", - error->errnum, error->errmess)); - return; - } - - ro_gui_popup_menu(font_menu, w, i); -} - -/** - * Handle a selection in the font menu - * - * \param selection The selection block - */ -void ro_gui_font_menu_selection(wimp_selection *selection) -{ - int buf_size; - char *buf; - os_error *error; - - error = xfont_decode_menu(0, (byte*)font_menu, (byte*)selection, - 0, 0, 0, &buf_size); - if (error) { - LOG(("xfont_decode_menu: 0x%x: %s", - error->errnum, error->errmess)); - return; - } - - buf = calloc(buf_size, sizeof(char)); - if (!buf) { - LOG(("malloc failed")); - return; - } - - error = xfont_decode_menu(0, (byte*)font_menu, (byte*)selection, - buf, buf_size, 0, 0); - if (error) { - LOG(("xfont_decode_menu: 0x%x: %s", - error->errnum, error->errmess)); - return; - } - - ro_gui_dialog_font_menu_selection(buf); - - free(buf); -} -- cgit v1.2.3