From 1548c232caffc716d66b04c0bf8bd3dd9ecfe9aa Mon Sep 17 00:00:00 2001 From: James Bursa Date: Wed, 27 Aug 2003 20:09:57 +0000 Subject: [project @ 2003-08-27 20:09:57 by bursa] Fix negative dimensions, more gui cleanup. svn path=/import/netsurf/; revision=252 --- !NetSurf/!Run,feb | 2 +- !NetSurf/Resources/IconNames | 36 --- !NetSurf/Resources/Messages | 28 --- !NetSurf/Themes/Default/Sprites,ff9 | Bin 66580 -> 66356 bytes !NetSurf/Themes/Default/Templates,fec | Bin 1532 -> 1525 bytes css/ruleset.c | 21 +- desktop/gui.h | 2 - render/box.c | 20 +- riscos/dialog.c | 382 ++++++++++++++++++++++++++++- riscos/gui.c | 450 ---------------------------------- riscos/gui.h | 10 +- riscos/menus.c | 2 +- 12 files changed, 402 insertions(+), 551 deletions(-) delete mode 100644 !NetSurf/Resources/IconNames delete mode 100644 !NetSurf/Resources/Messages diff --git a/!NetSurf/!Run,feb b/!NetSurf/!Run,feb index f5a9332ba..8107181a4 100644 --- a/!NetSurf/!Run,feb +++ b/!NetSurf/!Run,feb @@ -15,7 +15,7 @@ RMEnsure UtilityModule 3.70 RMEnsure CallASWI 0.02 Error NetSurf requires the Ca | Ensure SharedUnixLibrary is installed | http://www.chocky.org/unix/usage.html RMEnsure SharedUnixLibrary 1.02 RMLoad System:Modules.SharedULib -RMEnsure SharedUnixLibrary 1.02 Error NetSurf requires SharedUnixLibrary 1.00 or later +RMEnsure SharedUnixLibrary 1.02 Error NetSurf requires SharedUnixLibrary 1.02 or later | Load AcornURI if it isn't already | http://sudden.recoil.org/ diff --git a/!NetSurf/Resources/IconNames b/!NetSurf/Resources/IconNames deleted file mode 100644 index 482463e3a..000000000 --- a/!NetSurf/Resources/IconNames +++ /dev/null @@ -1,36 +0,0 @@ -# icon numbers -INFO_VERSION:6 -INFO_URL:8 -SAVEAS_FILEICON:0 -SAVEAS_PATH:1 -SAVEAS_SAVE:2 -SAVEAS_CANCEL:3 -CONFIG_OK:0 -CONFIG_CANCEL:1 -CONFIG_BROWSER:2 -CONFIG_PROXY:3 -CONFIG_THEME:4 -CONFIG_SAVE:5 -CONFIG_BR_OK:0 -CONFIG_BR_CANCEL:1 -CONFIG_BR_DEFAULT:2 -CONFIG_BR_FORM:3 -CONFIG_BR_GESTURES:4 -CONFIG_BR_EXPLAIN:5 -CONFIG_BR_TEXT:6 -CONFIG_BR_TOOLBAR:7 -CONFIG_BR_PREVIEW:8 -CONFIG_PROX_OK:0 -CONFIG_PROX_CANCEL:1 -CONFIG_PROX_DEFAULT:2 -CONFIG_PROX_HTTP:3 -CONFIG_PROX_HTTPHOST:4 -CONFIG_PROX_HTTPPORT:5 -CONFIG_TH_OK:0 -CONFIG_TH_CANCEL:1 -CONFIG_TH_DEFAULT:2 -CONFIG_TH_NAME:4 -CONFIG_TH_PICK:5 -CONFIG_TH_PREVIEW:7 -CONFIG_TH_GET:8 -CONFIG_TH_MANAGE:9 diff --git a/!NetSurf/Resources/Messages b/!NetSurf/Resources/Messages deleted file mode 100644 index da8589a6d..000000000 --- a/!NetSurf/Resources/Messages +++ /dev/null @@ -1,28 +0,0 @@ -# Menu items -# Display -MDISPLAY1:Toolbar -MDISPLAY2:Antialias -# Save -MSAVE1:Source -MSAVE2:Text -MSAVE3:URL -# Selection -MSELECT1:Copy to clipboard -MSELECT2:Clear -MSELECT3:Save -# Navigate -MNAVIG1:Open URL... -MNAVIG2:Home -MNAVIG3:Back -MNAVIG4:Forward -MNAVIG5:History -# Browser -MBROWSE1:Display -MBROWSE2:Save -MBROWSE3:Selection -MBROWSE4:Navigate -# Iconbar -MICONBAR1:Info -MICONBAR2:Choices... -MICONBAR3:Quit - diff --git a/!NetSurf/Themes/Default/Sprites,ff9 b/!NetSurf/Themes/Default/Sprites,ff9 index 4387af9f9..6dcc03e90 100644 Binary files a/!NetSurf/Themes/Default/Sprites,ff9 and b/!NetSurf/Themes/Default/Sprites,ff9 differ diff --git a/!NetSurf/Themes/Default/Templates,fec b/!NetSurf/Themes/Default/Templates,fec index be93daf7c..34f9184e6 100644 Binary files a/!NetSurf/Themes/Default/Templates,fec and b/!NetSurf/Themes/Default/Templates,fec differ diff --git a/css/ruleset.c b/css/ruleset.c index 714e541c3..3cdfc56cf 100644 --- a/css/ruleset.c +++ b/css/ruleset.c @@ -6,6 +6,7 @@ */ #include +#include #include #include #define CSS_INTERNALS @@ -33,7 +34,8 @@ struct font_size_entry { static int compare_selectors(struct node *n0, struct node *n1); -static int parse_length(struct css_length * const length, const struct node * const v); +static int parse_length(struct css_length * const length, + const struct node * const v, bool non_negative); static colour parse_colour(const struct node * const v); static void parse_background_color(struct css_style * const s, const struct node * const v); static void parse_clear(struct css_style * const s, const struct node * const v); @@ -228,16 +230,21 @@ int compare_selectors(struct node *n0, struct node *n1) /* TODO: consider NODE_NUMBER whenever a value may be '0' */ -int parse_length(struct css_length * const length, const struct node * const v) +int parse_length(struct css_length * const length, + const struct node * const v, bool non_negative) { css_unit u; + float value; if (v->type != NODE_DIMENSION) return 1; u = css_unit_parse(v->data + strspn(v->data, "0123456789+-.")); if (u == CSS_UNIT_UNKNOWN) return 1; + value = atof(v->data); + if (non_negative && value < 0) + return 1; length->unit = u; - length->value = atof(v->data); + length->value = value; return 0; } @@ -360,7 +367,7 @@ void parse_font_size(struct css_style * const s, const struct node * const v) break; case NODE_DIMENSION: - if (parse_length(&s->font_size.value.length, v) == 0) + if (parse_length(&s->font_size.value.length, v, true) == 0) s->font_size.size = CSS_FONT_SIZE_LENGTH; break; @@ -392,7 +399,7 @@ void parse_height(struct css_style * const s, const struct node * const v) { if (v->type == NODE_IDENT && strcasecmp(v->data, "auto") == 0) s->height.height = CSS_HEIGHT_AUTO; - else if (v->type == NODE_DIMENSION && parse_length(&s->height.length, v) == 0) + else if (v->type == NODE_DIMENSION && parse_length(&s->height.length, v, true) == 0) s->height.height = CSS_HEIGHT_LENGTH; } @@ -405,7 +412,7 @@ void parse_line_height(struct css_style * const s, const struct node * const v) s->line_height.size = CSS_LINE_HEIGHT_PERCENT; s->line_height.value.percent = atof(v->data); } else if (v->type == NODE_DIMENSION && - parse_length(&s->line_height.value.length, v) == 0) { + parse_length(&s->line_height.value.length, v, true) == 0) { s->line_height.size = CSS_LINE_HEIGHT_LENGTH; } else if (v->type == NODE_NUMBER) { s->line_height.size = CSS_LINE_HEIGHT_ABSOLUTE; @@ -431,6 +438,6 @@ void parse_width(struct css_style * const s, const struct node * const v) s->width.width = CSS_WIDTH_PERCENT; s->width.value.percent = atof(v->data); } else if (v->type == NODE_DIMENSION && - parse_length(&s->width.value.length, v) == 0) + parse_length(&s->width.value.length, v, true) == 0) s->width.width = CSS_WIDTH_LENGTH; } diff --git a/desktop/gui.h b/desktop/gui.h index 6d1ef5045..8438e8ee0 100644 --- a/desktop/gui.h +++ b/desktop/gui.h @@ -58,6 +58,4 @@ void gui_gadget_combo(struct browser_window* bw, struct gui_gadget* g, unsigned void gui_edit_textarea(struct browser_window* bw, struct gui_gadget* g); void gui_edit_textbox(struct browser_window* bw, struct gui_gadget* g); -void gui_show_choices(void); - #endif diff --git a/render/box.c b/render/box.c index f4b5e317a..0f9938f14 100644 --- a/render/box.c +++ b/render/box.c @@ -493,13 +493,16 @@ struct css_style * box_get_style(struct content ** stylesheet, } if ((s = (char *) xmlGetProp(n, (const xmlChar *) "height"))) { - if (strrchr(s, '%')) { + float value = atof(s); + if (value < 0) { + /* ignore negative values */ + } else if (strrchr(s, '%')) { /*the specification doesn't make clear what * percentage heights mean, so ignore them */ } else { - style->height.height = CSS_HEIGHT_LENGTH; - style->height.length.unit = CSS_UNIT_PX; - style->height.length.value = atof(s); + style->height.height = CSS_HEIGHT_LENGTH; + style->height.length.unit = CSS_UNIT_PX; + style->height.length.value = value; } xmlFree(s); } @@ -516,13 +519,16 @@ struct css_style * box_get_style(struct content ** stylesheet, } if ((s = (char *) xmlGetProp(n, (const xmlChar *) "width"))) { - if (strrchr(s, '%')) { + float value = atof(s); + if (value < 0) { + /* ignore negative values */ + } else if (strrchr(s, '%')) { style->width.width = CSS_WIDTH_PERCENT; - style->width.value.percent = atof(s); + style->width.value.percent = value; } else { style->width.width = CSS_WIDTH_LENGTH; style->width.value.length.unit = CSS_UNIT_PX; - style->width.value.length.value = atof(s); + style->width.value.length.value = value; } xmlFree(s); } diff --git a/riscos/dialog.c b/riscos/dialog.c index bca085cd8..99f18e83e 100644 --- a/riscos/dialog.c +++ b/riscos/dialog.c @@ -9,9 +9,14 @@ #include #include +#include "oslib/colourtrans.h" +#include "oslib/osfile.h" +#include "oslib/osgbpb.h" +#include "oslib/osspriteop.h" #include "oslib/wimp.h" #include "netsurf/riscos/gui.h" #include "netsurf/riscos/options.h" +#include "netsurf/utils/log.h" #include "netsurf/utils/utils.h" @@ -21,6 +26,12 @@ wimp_w dialog_info, dialog_saveas, dialog_config, dialog_config_br, dialog_config_prox, dialog_config_th; +wimp_menu* theme_menu = NULL; + +static struct ro_choices choices; +static struct browser_choices browser_choices; +static struct proxy_choices proxy_choices; +static struct theme_choices theme_choices; static wimp_w ro_gui_dialog_create(const char *template_name); @@ -28,6 +39,21 @@ static void ro_gui_dialog_click_config(wimp_pointer *pointer); static void ro_gui_dialog_click_config_br(wimp_pointer *pointer); static void ro_gui_dialog_click_config_prox(wimp_pointer *pointer); static void ro_gui_dialog_click_config_th(wimp_pointer *pointer); +static void set_browser_choices(struct browser_choices* newchoices); +static void get_browser_choices(struct browser_choices* newchoices); +static void set_proxy_choices(struct proxy_choices* newchoices); +static void get_proxy_choices(struct proxy_choices* newchoices); +static void load_theme_preview(char* thname); +static void set_theme_choices(struct theme_choices* newchoices); +static void get_theme_choices(struct theme_choices* newchoices); +static void ro_gui_destroy_theme_menu(void); +static void ro_gui_build_theme_menu(void); +static int file_exists(const char* base, const char* dir, const char* leaf, bits ftype); +static void set_icon_state(wimp_w w, wimp_i i, int state); +static int get_icon_state(wimp_w w, wimp_i i); +static void set_icon_string(wimp_w w, wimp_i i, char* text); +static char* get_icon_string(wimp_w w, wimp_i i); +static void set_icon_string_i(wimp_w w, wimp_i i, int num); /** @@ -44,6 +70,11 @@ void ro_gui_dialog_init(void) dialog_config_prox = ro_gui_dialog_create("config_prox"); dialog_config_th = ro_gui_dialog_create("config_th"); wimp_close_template(); + + options_to_ro(&OPTIONS, &choices); + set_browser_choices(&choices.browser); + set_proxy_choices(&choices.proxy); + set_theme_choices(&choices.theme); } @@ -82,6 +113,38 @@ wimp_w ro_gui_dialog_create(const char *template_name) } +/** + * Open a dialog box, centered on the screen. + */ + +void ro_gui_dialog_open(wimp_w w) +{ + int xeig_factor, yeig_factor, xwind_limit, ywind_limit, + screen_x, screen_y, dx, dy; + wimp_window_state open; + + /* find screen centre in os units */ + os_read_mode_variable(os_CURRENT_MODE, os_MODEVAR_XEIG_FACTOR, &xeig_factor); + os_read_mode_variable(os_CURRENT_MODE, os_MODEVAR_YEIG_FACTOR, &yeig_factor); + os_read_mode_variable(os_CURRENT_MODE, os_MODEVAR_XWIND_LIMIT, &xwind_limit); + os_read_mode_variable(os_CURRENT_MODE, os_MODEVAR_YWIND_LIMIT, &ywind_limit); + screen_x = (xwind_limit + 1) << (xeig_factor - 1); + screen_y = (ywind_limit + 1) << (yeig_factor - 1); + + /* centre and open */ + open.w = w; + wimp_get_window_state(&open); + dx = (open.visible.x1 - open.visible.x0) / 2; + dy = (open.visible.y1 - open.visible.y0) / 2; + open.visible.x0 = screen_x - dx; + open.visible.x1 = screen_x + dx; + open.visible.y0 = screen_y - dy; + open.visible.y1 = screen_y + dy; + open.next = wimp_TOP; + wimp_open_window((wimp_open *) &open); +} + + /** * Handle clicks in one of the dialog boxes. */ @@ -130,13 +193,13 @@ void ro_gui_dialog_click_config(wimp_pointer *pointer) } break; case ICON_CONFIG_BROWSER: - ro_gui_show_browser_choices(); + ro_gui_dialog_open(dialog_config_br); break; case ICON_CONFIG_PROXY: - ro_gui_show_proxy_choices(); + ro_gui_dialog_open(dialog_config_prox); break; case ICON_CONFIG_THEME: - ro_gui_show_theme_choices(); + ro_gui_dialog_open(dialog_config_th); break; } } @@ -241,16 +304,311 @@ void ro_gui_dialog_click_config_th(wimp_pointer *pointer) void ro_gui_dialog_close(wimp_w close) { - if (close == dialog_config) - config_open = 0; - else if (close == dialog_config_br) - config_br_open = 0; - else if (close == dialog_config_prox) - config_prox_open = 0; - else if (close == dialog_config_th) { - config_th_open = 0; + wimp_close_window(close); +} + + + +void set_browser_choices(struct browser_choices* newchoices) +{ + memcpy(&browser_choices, newchoices, sizeof(struct browser_choices)); + set_icon_state(dialog_config_br, ICON_CONFIG_BR_GESTURES, browser_choices.use_mouse_gestures); + set_icon_state(dialog_config_br, ICON_CONFIG_BR_FORM, browser_choices.use_riscos_elements); + set_icon_state(dialog_config_br, ICON_CONFIG_BR_TEXT, browser_choices.allow_text_selection); + set_icon_state(dialog_config_br, ICON_CONFIG_BR_TOOLBAR, browser_choices.show_toolbar); + set_icon_state(dialog_config_br, ICON_CONFIG_BR_PREVIEW, browser_choices.show_print_preview); +} + +void get_browser_choices(struct browser_choices* newchoices) +{ + newchoices->use_mouse_gestures = get_icon_state(dialog_config_br, ICON_CONFIG_BR_GESTURES); + newchoices->use_riscos_elements = get_icon_state(dialog_config_br, ICON_CONFIG_BR_FORM); + newchoices->allow_text_selection = get_icon_state(dialog_config_br, ICON_CONFIG_BR_TEXT); + newchoices->show_toolbar = get_icon_state(dialog_config_br, ICON_CONFIG_BR_TOOLBAR); + newchoices->show_print_preview = get_icon_state(dialog_config_br, ICON_CONFIG_BR_PREVIEW); +} + +void set_proxy_choices(struct proxy_choices* newchoices) +{ + memcpy(&proxy_choices, newchoices, sizeof(struct proxy_choices)); + set_icon_state(dialog_config_prox, ICON_CONFIG_PROX_HTTP, proxy_choices.http); + set_icon_string(dialog_config_prox, ICON_CONFIG_PROX_HTTPHOST, proxy_choices.http_proxy); + set_icon_string_i(dialog_config_prox, ICON_CONFIG_PROX_HTTPPORT, proxy_choices.http_port); +} + +void get_proxy_choices(struct proxy_choices* newchoices) +{ + newchoices->http = get_icon_state(dialog_config_prox, ICON_CONFIG_PROX_HTTP); + strncpy(newchoices->http_proxy, get_icon_string(dialog_config_prox, ICON_CONFIG_PROX_HTTPHOST), 255); + newchoices->http_port = atoi(get_icon_string(dialog_config_prox, ICON_CONFIG_PROX_HTTPPORT)); +} + +osspriteop_area* theme_preview = NULL; + +void load_theme_preview(char* thname) +{ +if (theme_preview != NULL) + xfree(theme_preview); + +theme_preview = NULL; + + if (file_exists(THEMES_DIR, thname, "Preview", 0xff9)) + { +char filename[256]; +FILE* fp; +int size; + + + sprintf(filename, "%s.%s.Preview", THEMES_DIR, thname); + fp = fopen(filename, "rb"); + if (fp == 0) return; + if (fseek(fp, 0, SEEK_END) != 0) die("fseek() failed"); + if ((size = (int) ftell(fp)) == -1) die("ftell() failed"); + fclose(fp); + + theme_preview = xcalloc(size + 16, 1); + if (theme_preview == NULL) + return; + + theme_preview->size = size + 16; + theme_preview->sprite_count = 0; + theme_preview->first = 16; + theme_preview->used = 16; + osspriteop_clear_sprites(osspriteop_USER_AREA, theme_preview); + osspriteop_load_sprite_file(osspriteop_USER_AREA, theme_preview, filename); + + + } +} + +void ro_gui_redraw_config_th(wimp_draw* redraw) +{ + int x, y, size; + osbool more; + wimp_icon_state preview; + wimp_window_state win; + osspriteop_trans_tab* trans_tab; + + win.w = dialog_config_th; + wimp_get_window_state(&win); + + preview.w = dialog_config_th; + preview.i = ICON_CONFIG_TH_PREVIEW; + wimp_get_icon_state(&preview); + + if (theme_preview != NULL) + { + x = preview.icon.extent.x0 + win.visible.x0 + 4; + y = preview.icon.extent.y0 + win.visible.y1 + 4; + + xcolourtrans_generate_table_for_sprite(theme_preview, "preview", -1, -1, 0, 0, 0, 0, &size); + trans_tab = malloc(size + 32); + xcolourtrans_generate_table_for_sprite(theme_preview, "preview", -1, -1, trans_tab, 0, 0, 0, &size); + + more = wimp_redraw_window(redraw); + while (more) + { + xosspriteop_put_sprite_scaled(osspriteop_NAME, theme_preview, "preview", x, y, 0, 0, trans_tab); + more = wimp_get_rectangle(redraw); + } + + xfree(trans_tab); + } + else + { + preview.icon.flags = wimp_ICON_TEXT | wimp_ICON_INDIRECTED | wimp_ICON_HCENTRED | wimp_ICON_VCENTRED | (wimp_COLOUR_BLACK << wimp_ICON_FG_COLOUR_SHIFT) | (wimp_COLOUR_VERY_LIGHT_GREY << wimp_ICON_BG_COLOUR_SHIFT); + preview.icon.data.indirected_text.text = "No preview available"; + preview.icon.data.indirected_text.size = 21; + + more = wimp_redraw_window(redraw); + while (more) + { + wimp_plot_icon(&preview.icon); + more = wimp_get_rectangle(redraw); + } + + } + return; + +} + +void set_theme_choices(struct theme_choices* newchoices) +{ + memcpy(&theme_choices, newchoices, sizeof(struct theme_choices)); + set_icon_string(dialog_config_th, ICON_CONFIG_TH_NAME, theme_choices.name); + load_theme_preview(theme_choices.name); +} + +void get_theme_choices(struct theme_choices* newchoices) +{ + strncpy(newchoices->name, get_icon_string(dialog_config_th, ICON_CONFIG_TH_NAME), 255); +} + + +void ro_gui_destroy_theme_menu(void) +{ + int i = 0; + LOG(("destroy?")); + + if (theme_menu == NULL) + return; + + LOG(("enumerating")); + while ((theme_menu->entries[i].menu_flags & wimp_MENU_LAST) == 0) + { + xfree(theme_menu->entries[i].data.indirected_text.text); + LOG(("freed")); + i++; + } + + LOG(("freeing menu")); + xfree(theme_menu); + theme_menu = NULL; + LOG(("destroyed")); +} + +void ro_gui_build_theme_menu(void) +{ + wimp_menu* m; + int num = 0; + int i; + char* name[256]; + char buffer[256]; + osgbpb_system_info* info; + int context = 0, count = 1; + + LOG(("check for destroy")); + if (theme_menu != NULL) ro_gui_destroy_theme_menu(); + + LOG(("enumerate themes")); + context = osgbpb_dir_entries_system_info(THEMES_DIR, buffer, 1, context, 256, 0, &count); + while (context != -1) + { + LOG(("called")); + info = (osgbpb_system_info*) buffer; + if (info->obj_type == 2 /* directory */) + { + if (file_exists(THEMES_DIR, info->name, "Templates", 0xfec) && + file_exists(THEMES_DIR, info->name, "Sprites", 0xff9) && + file_exists(THEMES_DIR, info->name, "IconNames", 0xfff) && + file_exists(THEMES_DIR, info->name, "IconSizes", 0xfff)) + { + LOG(("found")); + name[num] = malloc(strlen(info->name) + 2); + strcpy(name[num], info->name); + num++; + } + } + context = osgbpb_dir_entries_system_info(THEMES_DIR, buffer, 1, context, 256, 0, &count); } - wimp_close_window(close); + LOG(("mallocing")); + + m = malloc(sizeof(wimp_menu_base) + (num*2) * sizeof(wimp_menu_entry)); + strcpy(m->title_data.text, "Themes"); + m->title_fg = wimp_COLOUR_BLACK; + m->title_bg = wimp_COLOUR_LIGHT_GREY; + m->work_fg = wimp_COLOUR_BLACK; + m->work_bg = wimp_COLOUR_WHITE; + m->width = 256; + m->height = 44; + m->gap = 0; + + LOG(("building entries")); + for (i = 0; i < num; i++) + { + if (i < num - 1) + m->entries[i].menu_flags = 0; + else + { + LOG(("last one")); + m->entries[i].menu_flags = wimp_MENU_LAST; + } + + if (strcmp(name[i], theme_choices.name) == 0) + m->entries[i].menu_flags |= wimp_MENU_TICKED; + + m->entries[i].sub_menu = wimp_NO_SUB_MENU; + m->entries[i].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)); + m->entries[i].data.indirected_text.text = name[i]; + m->entries[i].data.indirected_text.validation = -1; + m->entries[i].data.indirected_text.size = strlen(name[i]) + 1; + LOG(("entry %d", i)); + } + + LOG(("done")); + + theme_menu = m; +} + +void ro_gui_theme_menu_selection(char *theme) +{ + strcpy(theme_choices.name, theme); + set_icon_string(dialog_config_th, ICON_CONFIG_TH_NAME, theme_choices.name); + load_theme_preview(theme_choices.name); + wimp_set_icon_state(dialog_config_th, ICON_CONFIG_TH_NAME, 0, 0); + wimp_set_icon_state(dialog_config_th, ICON_CONFIG_TH_PREVIEW, 0, 0); + +} + +int file_exists(const char* base, const char* dir, const char* leaf, bits ftype) +{ + char buffer[256]; + fileswitch_object_type type; + bits load, exec; + int size; + fileswitch_attr attr; + bits file_type; + + snprintf(buffer, 255, "%s.%s.%s", base, dir, leaf); + LOG(("checking %s", buffer)); + if (xosfile_read_stamped_no_path(buffer, &type, &load, &exec, &size, &attr, &file_type) == NULL) + { + return (type == 1 && ftype == file_type); + } + + return 0; +} + +void set_icon_state(wimp_w w, wimp_i i, int state) +{ + if (state) + wimp_set_icon_state(w,i, wimp_ICON_SELECTED, wimp_ICON_SELECTED); + else + wimp_set_icon_state(w,i, 0, wimp_ICON_SELECTED); +} + +int get_icon_state(wimp_w w, wimp_i i) +{ + wimp_icon_state ic; + ic.w = w; + ic.i = i; + wimp_get_icon_state(&ic); + return (ic.icon.flags & wimp_ICON_SELECTED) != 0; +} + +void set_icon_string(wimp_w w, wimp_i i, char* text) +{ + wimp_icon_state ic; + ic.w = w; + ic.i = i; + wimp_get_icon_state(&ic); + strncpy(ic.icon.data.indirected_text.text, text, ic.icon.data.indirected_text.size); +} + +char* get_icon_string(wimp_w w, wimp_i i) +{ + wimp_icon_state ic; + ic.w = w; + ic.i = i; + wimp_get_icon_state(&ic); + return ic.icon.data.indirected_text.text; +} + +void set_icon_string_i(wimp_w w, wimp_i i, int num) +{ + char buffer[255]; + sprintf(buffer, "%d", num); + set_icon_string(w, i, buffer); } diff --git a/riscos/gui.c b/riscos/gui.c index f5da4663d..f1305d036 100644 --- a/riscos/gui.c +++ b/riscos/gui.c @@ -43,19 +43,6 @@ int gadget_subtract_x; int gadget_subtract_y; const char* HOME_URL = "file:///%3CNetSurf$Dir%3E/Resources/intro"; -wimp_menu* theme_menu = NULL; - - -struct ro_choices choices; -struct browser_choices browser_choices; -struct proxy_choices proxy_choices; -struct theme_choices theme_choices; - -int config_open = 0; -int config_br_open = 0; -int config_prox_open = 0; -int config_th_open = 0; - struct ro_gui_drag_info; typedef enum { mouseaction_NONE, @@ -240,86 +227,12 @@ gui_window* create_gui_browser_window(struct browser_window* bw) if ((bw->flags & browser_TOOLBAR) != 0) { ro_theme_window create_toolbar; -/* - struct wimp_window toolbar; - wimp_icon_create status_icon; - wimp_icon_create url_icon; - - toolbar.visible.x0 = 0; - toolbar.visible.y0 = 0; - toolbar.visible.x1 = 4096; - toolbar.visible.y1 = TOOLBAR_HEIGHT; - toolbar.xscroll = 0; - toolbar.yscroll = 0; - toolbar.next = wimp_TOP; - toolbar.flags = - wimp_WINDOW_MOVEABLE | wimp_WINDOW_NEW_FORMAT | - wimp_WINDOW_AUTO_REDRAW | wimp_WINDOW_FURNITURE_WINDOW; - toolbar.title_fg = wimp_COLOUR_BLACK; - toolbar.title_bg = wimp_COLOUR_LIGHT_GREY; - toolbar.work_fg = wimp_COLOUR_LIGHT_GREY; - toolbar.work_bg = wimp_COLOUR_VERY_LIGHT_GREY; - toolbar.scroll_outer = wimp_COLOUR_DARK_GREY; - toolbar.scroll_inner = wimp_COLOUR_MID_LIGHT_GREY; - toolbar.highlight_bg = wimp_COLOUR_CREAM; - toolbar.extra_flags = 0; - toolbar.extent.x0 = 0; - toolbar.extent.y0 = -TOOLBAR_HEIGHT; - toolbar.extent.x1 = 4096; - if ((bw->flags & browser_TOOLBAR) != 0) - { - toolbar.extent.y1 = TOOLBAR_HEIGHT; - } - else - { - toolbar.extent.y1 = 0; - } - toolbar.title_flags = wimp_ICON_TEXT; - toolbar.work_flags = wimp_BUTTON_CLICK_DRAG << wimp_ICON_BUTTON_TYPE_SHIFT; - toolbar.sprite_area = NULL; - toolbar.icon_count = 0; - toolbar.xmin = 0; - toolbar.ymin = 2; - g->data.browser.toolbar = wimp_create_window(&toolbar);*/ create_toolbar.type = THEME_TOOLBAR; create_toolbar.data.toolbar.indirected_url = g->url; create_toolbar.data.toolbar.indirected_status = g->status; g->data.browser.toolbar = ro_theme_create_window(current_theme, &create_toolbar); g->data.browser.toolbar_width = -1; - fprintf(stderr, "Created toolbar!"); -/* - status_icon.w = g->data.browser.toolbar; - status_icon.icon.extent.x0 = 0; - status_icon.icon.extent.y0 = -128; - status_icon.icon.extent.x1 = 4096; - status_icon.icon.extent.y1 = -64; - status_icon.icon.flags = - wimp_ICON_TEXT | wimp_ICON_BORDER | wimp_ICON_VCENTRED | - wimp_ICON_INDIRECTED | wimp_ICON_FILLED | - (wimp_BUTTON_NEVER << wimp_ICON_BUTTON_TYPE_SHIFT) | - (wimp_COLOUR_BLACK << wimp_ICON_FG_COLOUR_SHIFT) | - (wimp_COLOUR_VERY_LIGHT_GREY << wimp_ICON_BG_COLOUR_SHIFT); - status_icon.icon.data.indirected_text.text = g->status; - status_icon.icon.data.indirected_text.validation = "R2;"; - status_icon.icon.data.indirected_text.size = 255; - wimp_create_icon(&status_icon); - - url_icon.w = g->data.browser.toolbar; - url_icon.icon.extent.x0 = 0; - url_icon.icon.extent.y0 = -64; - url_icon.icon.extent.x1 = 4096; - url_icon.icon.extent.y1 = 0; - url_icon.icon.flags = - wimp_ICON_TEXT | wimp_ICON_BORDER | wimp_ICON_VCENTRED | - wimp_ICON_INDIRECTED | wimp_ICON_FILLED | - (wimp_BUTTON_WRITE_CLICK_DRAG << wimp_ICON_BUTTON_TYPE_SHIFT) | - (wimp_COLOUR_BLACK << wimp_ICON_FG_COLOUR_SHIFT) | - (wimp_COLOUR_WHITE << wimp_ICON_BG_COLOUR_SHIFT); - url_icon.icon.data.indirected_text.text = g->url; - url_icon.icon.data.indirected_text.validation = "Pptr_write;"; - url_icon.icon.data.indirected_text.size = 255; - wimp_create_icon(&url_icon);*/ } g->redraw_safety = SAFE; @@ -2294,366 +2207,3 @@ void gui_remove_gadget(struct gui_gadget* g) } } - -void gui_show_choices() -{ - wimp_window_state open; - - if (!config_open) - options_to_ro(&OPTIONS, &choices); - - open.w = dialog_config; - wimp_get_window_state(&open); - open.next = wimp_TOP; - wimp_open_window(&open); - config_open = 1; - return; -} - -void set_icon_state(wimp_w w, wimp_i i, int state) -{ - if (state) - wimp_set_icon_state(w,i, wimp_ICON_SELECTED, wimp_ICON_SELECTED); - else - wimp_set_icon_state(w,i, 0, wimp_ICON_SELECTED); -} - -int get_icon_state(wimp_w w, wimp_i i) -{ - wimp_icon_state ic; - ic.w = w; - ic.i = i; - wimp_get_icon_state(&ic); - return (ic.icon.flags & wimp_ICON_SELECTED) != 0; -} - -void set_icon_string(wimp_w w, wimp_i i, char* text) -{ - wimp_icon_state ic; - ic.w = w; - ic.i = i; - wimp_get_icon_state(&ic); - strncpy(ic.icon.data.indirected_text.text, text, ic.icon.data.indirected_text.size); -} - -char* get_icon_string(wimp_w w, wimp_i i) -{ - wimp_icon_state ic; - ic.w = w; - ic.i = i; - wimp_get_icon_state(&ic); - return ic.icon.data.indirected_text.text; -} - -void set_icon_string_i(wimp_w w, wimp_i i, int num) -{ - char buffer[255]; - sprintf(buffer, "%d", num); - set_icon_string(w, i, buffer); -} - -void set_browser_choices(struct browser_choices* newchoices) -{ - memcpy(&browser_choices, newchoices, sizeof(struct browser_choices)); - set_icon_state(dialog_config_br, ICON_CONFIG_BR_GESTURES, browser_choices.use_mouse_gestures); - set_icon_state(dialog_config_br, ICON_CONFIG_BR_FORM, browser_choices.use_riscos_elements); - set_icon_state(dialog_config_br, ICON_CONFIG_BR_TEXT, browser_choices.allow_text_selection); - set_icon_state(dialog_config_br, ICON_CONFIG_BR_TOOLBAR, browser_choices.show_toolbar); - set_icon_state(dialog_config_br, ICON_CONFIG_BR_PREVIEW, browser_choices.show_print_preview); -} - -void get_browser_choices(struct browser_choices* newchoices) -{ - newchoices->use_mouse_gestures = get_icon_state(dialog_config_br, ICON_CONFIG_BR_GESTURES); - newchoices->use_riscos_elements = get_icon_state(dialog_config_br, ICON_CONFIG_BR_FORM); - newchoices->allow_text_selection = get_icon_state(dialog_config_br, ICON_CONFIG_BR_TEXT); - newchoices->show_toolbar = get_icon_state(dialog_config_br, ICON_CONFIG_BR_TOOLBAR); - newchoices->show_print_preview = get_icon_state(dialog_config_br, ICON_CONFIG_BR_PREVIEW); -} - -void set_proxy_choices(struct proxy_choices* newchoices) -{ - memcpy(&proxy_choices, newchoices, sizeof(struct proxy_choices)); - set_icon_state(dialog_config_prox, ICON_CONFIG_PROX_HTTP, proxy_choices.http); - set_icon_string(dialog_config_prox, ICON_CONFIG_PROX_HTTPHOST, proxy_choices.http_proxy); - set_icon_string_i(dialog_config_prox, ICON_CONFIG_PROX_HTTPPORT, proxy_choices.http_port); -} - -void get_proxy_choices(struct proxy_choices* newchoices) -{ - newchoices->http = get_icon_state(dialog_config_prox, ICON_CONFIG_PROX_HTTP); - strncpy(newchoices->http_proxy, get_icon_string(dialog_config_prox, ICON_CONFIG_PROX_HTTPHOST), 255); - newchoices->http_port = atoi(get_icon_string(dialog_config_prox, ICON_CONFIG_PROX_HTTPPORT)); -} - -osspriteop_area* theme_preview = NULL; - -void load_theme_preview(char* thname) -{ -if (theme_preview != NULL) - xfree(theme_preview); - -theme_preview = NULL; - - if (file_exists(THEMES_DIR, thname, "Preview", 0xff9)) - { -char filename[256]; -FILE* fp; -int size; - - - sprintf(filename, "%s.%s.Preview", THEMES_DIR, thname); - fp = fopen(filename, "rb"); - if (fp == 0) return; - if (fseek(fp, 0, SEEK_END) != 0) die("fseek() failed"); - if ((size = (int) ftell(fp)) == -1) die("ftell() failed"); - fclose(fp); - - theme_preview = xcalloc(size + 16, 1); - if (theme_preview == NULL) - return; - - theme_preview->size = size + 16; - theme_preview->sprite_count = 0; - theme_preview->first = 16; - theme_preview->used = 16; - osspriteop_clear_sprites(osspriteop_USER_AREA, theme_preview); - osspriteop_load_sprite_file(osspriteop_USER_AREA, theme_preview, filename); - - - } -} - -void set_theme_choices(struct theme_choices* newchoices) -{ - memcpy(&theme_choices, newchoices, sizeof(struct theme_choices)); - set_icon_string(dialog_config_th, ICON_CONFIG_TH_NAME, theme_choices.name); - load_theme_preview(theme_choices.name); -} - -void get_theme_choices(struct theme_choices* newchoices) -{ - strncpy(newchoices->name, get_icon_string(dialog_config_th, ICON_CONFIG_TH_NAME), 255); -} - -void ro_gui_show_browser_choices() -{ - wimp_window_state open; - - if (!config_br_open) - set_browser_choices(&choices.browser); - - open.w = dialog_config_br; - wimp_get_window_state(&open); - open.next = wimp_TOP; - wimp_open_window(&open); - config_br_open = 1; -} - -void ro_gui_show_proxy_choices() -{ - wimp_window_state open; - - if (!config_prox_open) - set_proxy_choices(&choices.proxy); - - open.w = dialog_config_prox; - wimp_get_window_state(&open); - open.next = wimp_TOP; - wimp_open_window(&open); - config_prox_open = 1; -} - -void ro_gui_show_theme_choices() -{ - wimp_window_state open; - - if (!config_th_open) - { - set_theme_choices(&choices.theme); - } - - open.w = dialog_config_th; - wimp_get_window_state(&open); - open.next = wimp_TOP; - wimp_open_window(&open); - config_th_open = 1; -} - - -void ro_gui_destroy_theme_menu() -{ - int i = 0; - LOG(("destroy?")); - - if (theme_menu == NULL) - return; - - LOG(("enumerating")); - while ((theme_menu->entries[i].menu_flags & wimp_MENU_LAST) == 0) - { - xfree(theme_menu->entries[i].data.indirected_text.text); - LOG(("freed")); - i++; - } - - LOG(("freeing menu")); - xfree(theme_menu); - theme_menu = NULL; - LOG(("destroyed")); -} - -int file_exists(char* base, char* dir, char* leaf, bits ftype) -{ - char buffer[256]; - fileswitch_object_type type; - bits load, exec; - int size; - fileswitch_attr attr; - bits file_type; - - snprintf(buffer, 255, "%s.%s.%s", base, dir, leaf); - LOG(("checking %s", buffer)); - if (xosfile_read_stamped_no_path(buffer, &type, &load, &exec, &size, &attr, &file_type) == NULL) - { - return (type == 1 && ftype == file_type); - } - - return 0; -} - -void ro_gui_build_theme_menu() -{ - wimp_menu* m; - int num = 0; - int i; - char* name[256]; - char buffer[256]; - osgbpb_system_info* info; - int context = 0, count = 1; - - LOG(("check for destroy")); - if (theme_menu != NULL) - ro_gui_destroy_theme_menu(); - - LOG(("enumerate themes")); - context = osgbpb_dir_entries_system_info(THEMES_DIR, buffer, 1, context, 256, 0, &count); - while (context != -1) - { - LOG(("called")); - info = (osgbpb_system_info*) buffer; - if (info->obj_type == 2 /* directory */) - { - if (file_exists(THEMES_DIR, info->name, "Templates", 0xfec) && - file_exists(THEMES_DIR, info->name, "Sprites", 0xff9) && - file_exists(THEMES_DIR, info->name, "IconNames", 0xfff) && - file_exists(THEMES_DIR, info->name, "IconSizes", 0xfff)) - { - LOG(("found")); - name[num] = malloc(strlen(info->name) + 2); - strcpy(name[num], info->name); - num++; - } - } - context = osgbpb_dir_entries_system_info(THEMES_DIR, buffer, 1, context, 256, 0, &count); - } - LOG(("mallocing")); - - m = malloc(sizeof(wimp_menu_base) + (num*2) * sizeof(wimp_menu_entry)); - strcpy(m->title_data.text, "Themes"); - m->title_fg = wimp_COLOUR_BLACK; - m->title_bg = wimp_COLOUR_LIGHT_GREY; - m->work_fg = wimp_COLOUR_BLACK; - m->work_bg = wimp_COLOUR_WHITE; - m->width = 256; - m->height = 44; - m->gap = 0; - - LOG(("building entries")); - for (i = 0; i < num; i++) - { - if (i < num - 1) - m->entries[i].menu_flags = 0; - else - { - LOG(("last one")); - m->entries[i].menu_flags = wimp_MENU_LAST; - } - - if (strcmp(name[i], theme_choices.name) == 0) - m->entries[i].menu_flags |= wimp_MENU_TICKED; - - m->entries[i].sub_menu = wimp_NO_SUB_MENU; - m->entries[i].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)); - m->entries[i].data.indirected_text.text = name[i]; - m->entries[i].data.indirected_text.validation = BROWSER_VALIDATION; - m->entries[i].data.indirected_text.size = strlen(name[i]) + 1; - LOG(("entry %d", i)); - } - - LOG(("done")); - - theme_menu = m; -} - -void ro_gui_redraw_config_th(wimp_draw* redraw) -{ - int x, y, size; - osbool more; - wimp_icon_state preview; - wimp_window_state win; - osspriteop_trans_tab* trans_tab; - - win.w = dialog_config_th; - wimp_get_window_state(&win); - - preview.w = dialog_config_th; - preview.i = ICON_CONFIG_TH_PREVIEW; - wimp_get_icon_state(&preview); - - if (theme_preview != NULL) - { - x = preview.icon.extent.x0 + win.visible.x0 + 4; - y = preview.icon.extent.y0 + win.visible.y1 + 4; - - xcolourtrans_generate_table_for_sprite(theme_preview, "preview", -1, -1, 0, 0, 0, 0, &size); - trans_tab = malloc(size + 32); - xcolourtrans_generate_table_for_sprite(theme_preview, "preview", -1, -1, trans_tab, 0, 0, 0, &size); - - more = wimp_redraw_window(redraw); - while (more) - { - xosspriteop_put_sprite_scaled(osspriteop_NAME, theme_preview, "preview", x, y, 0, 0, trans_tab); - more = wimp_get_rectangle(redraw); - } - - xfree(trans_tab); - } - else - { - preview.icon.flags = wimp_ICON_TEXT | wimp_ICON_INDIRECTED | wimp_ICON_HCENTRED | wimp_ICON_VCENTRED | (wimp_COLOUR_BLACK << wimp_ICON_FG_COLOUR_SHIFT) | (wimp_COLOUR_VERY_LIGHT_GREY << wimp_ICON_BG_COLOUR_SHIFT); - preview.icon.data.indirected_text.text = "No preview available"; - preview.icon.data.indirected_text.size = 21; - - more = wimp_redraw_window(redraw); - while (more) - { - wimp_plot_icon(&preview.icon); - more = wimp_get_rectangle(redraw); - } - - } - return; - -} - -void ro_gui_theme_menu_selection(char *theme) -{ - strcpy(theme_choices.name, theme); - set_icon_string(dialog_config_th, ICON_CONFIG_TH_NAME, theme_choices.name); - load_theme_preview(theme_choices.name); - wimp_set_icon_state(dialog_config_th, ICON_CONFIG_TH_NAME, 0, 0); - wimp_set_icon_state(dialog_config_th, ICON_CONFIG_TH_PREVIEW, 0, 0); - -} - diff --git a/riscos/gui.h b/riscos/gui.h index 29547287e..2758272da 100644 --- a/riscos/gui.h +++ b/riscos/gui.h @@ -24,12 +24,6 @@ extern int current_menu_x, current_menu_y, iconbar_menu_height; extern struct gui_gadget *current_gadget; extern const char *HOME_URL; -extern struct ro_choices choices; -extern struct browser_choices browser_choices; -extern struct proxy_choices proxy_choices; -extern struct theme_choices theme_choices; -extern int config_open, config_br_open, config_prox_open, config_th_open; - struct ro_gui_window { @@ -59,7 +53,6 @@ struct ro_gui_window /* in gui.c */ void ro_gui_copy_selection(gui_window* g); -void ro_gui_theme_menu_selection(char *theme); /* in menus.c */ void ro_gui_menus_init(void); @@ -68,8 +61,11 @@ void ro_gui_menu_selection(wimp_selection* selection); /* in dialog.c */ void ro_gui_dialog_init(void); +void ro_gui_dialog_open(wimp_w w); void ro_gui_dialog_click(wimp_pointer *pointer); void ro_gui_dialog_close(wimp_w close); +void ro_gui_redraw_config_th(wimp_draw* redraw); +void ro_gui_theme_menu_selection(char *theme); /* icon numbers */ #define ICON_CONFIG_SAVE 0 diff --git a/riscos/menus.c b/riscos/menus.c index e771abe2c..484459839 100644 --- a/riscos/menus.c +++ b/riscos/menus.c @@ -166,7 +166,7 @@ void ro_gui_menu_selection(wimp_selection *selection) pointer.pos.x, pointer.pos.y, 0); break; case 1: /* Choices */ - gui_show_choices(); + ro_gui_dialog_open(dialog_config); break; case 2: /* Quit */ netsurf_quit = 1; -- cgit v1.2.3