From 0bb08cc5d2a2c66b77c3ec19db244c57a270a009 Mon Sep 17 00:00:00 2001 From: Chris Young Date: Sat, 1 Jun 2013 14:57:49 +0100 Subject: Macros for setting default options and updating user options if they are "as default" --- utils/nsoption.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/utils/nsoption.h b/utils/nsoption.h index 868e077bd..b6ab860b1 100644 --- a/utils/nsoption.h +++ b/utils/nsoption.h @@ -270,5 +270,20 @@ int nsoption_snoptionf(char *string, size_t size, enum nsoption_e option, const } \ } while (0) +/* accessors for default options - user option is updated if it is set as per default */ +#define nsoption_default_set_bool(OPTION, VALUE) \ + if (nsoptions_default[NSOPTION_##OPTION].value.b == nsoptions[NSOPTION_##OPTION].value.b) \ + nsoptions[NSOPTION_##OPTION].value.b = VALUE; \ + nsoptions_default[NSOPTION_##OPTION].value.b = VALUE + +#define nsoption_default_set_int(OPTION, VALUE) \ + if (nsoptions_default[NSOPTION_##OPTION].value.i == nsoptions[NSOPTION_##OPTION].value.i) \ + nsoptions[NSOPTION_##OPTION].value.i = VALUE; \ + nsoptions_default[NSOPTION_##OPTION].value.i = VALUE + +#define nsoption_default_set_colour(OPTION, VALUE) \ + if (nsoptions_default[NSOPTION_##OPTION].value.c == nsoptions[NSOPTION_##OPTION].value.c) \ + nsoptions[NSOPTION_##OPTION].value.c = VALUE; \ + nsoptions_default[NSOPTION_##OPTION].value.c = VALUE #endif -- cgit v1.2.3 From fe78657b081c68d4e82ce0d526defaefbe1a0677 Mon Sep 17 00:00:00 2001 From: Chris Young Date: Sat, 1 Jun 2013 14:58:51 +0100 Subject: Use default macros for updating window size --- amiga/gui.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/amiga/gui.c b/amiga/gui.c index 536981c56..eab208f34 100644 --- a/amiga/gui.c +++ b/amiga/gui.c @@ -445,15 +445,10 @@ colour_option_from_pen(struct nsoption_s *opts, static void ami_set_screen_defaults(struct Screen *scrn) { - if((nsoption_int(window_x) == 0) && - (nsoption_int(window_y) == 0) && - (nsoption_int(window_width) == 0) && - (nsoption_int(window_height) == 0)) { - nsoption_set_int(window_x, 0); - nsoption_set_int(window_y, scrn->BarHeight + 1); - nsoption_set_int(window_width, scrn->Width); - nsoption_set_int(window_height, scrn->Height - scrn->BarHeight - 1); - } + nsoption_default_set_int(window_x, 0); + nsoption_default_set_int(window_y, scrn->BarHeight + 1); + nsoption_default_set_int(window_width, scrn->Width); + nsoption_default_set_int(window_height, scrn->Height - scrn->BarHeight - 1); /* TODO: Update screen colour defaults here */ } -- cgit v1.2.3 From 8179e51a758843949987dc3e4a89dbeaf619a149 Mon Sep 17 00:00:00 2001 From: Chris Young Date: Sat, 1 Jun 2013 15:11:26 +0100 Subject: Set default colours when screen changes --- amiga/gui.c | 66 +++++++++++++++++++++++++++++++------------------------------ 1 file changed, 34 insertions(+), 32 deletions(-) diff --git a/amiga/gui.c b/amiga/gui.c index eab208f34..efeeed3c4 100644 --- a/amiga/gui.c +++ b/amiga/gui.c @@ -438,19 +438,51 @@ colour_option_from_pen(struct nsoption_s *opts, } } - opts[option].value.c = def_colour; + if (nsoptions_default[option].value.c == nsoptions[option].value.c) + nsoptions[option].value.c = def_colour; + nsoptions_default[option].value.c = def_colour; return NSERROR_OK; } static void ami_set_screen_defaults(struct Screen *scrn) { + struct nsoption_s *defaults = nsoptions_default; + nsoption_default_set_int(window_x, 0); nsoption_default_set_int(window_y, scrn->BarHeight + 1); nsoption_default_set_int(window_width, scrn->Width); nsoption_default_set_int(window_height, scrn->Height - scrn->BarHeight - 1); - /* TODO: Update screen colour defaults here */ + /* set system colours for amiga ui */ + colour_option_from_pen(defaults, FILLPEN, NSOPTION_sys_colour_ActiveBorder, 0x00000000); + colour_option_from_pen(defaults, FILLPEN, NSOPTION_sys_colour_ActiveCaption, 0x00dddddd); + colour_option_from_pen(defaults, BACKGROUNDPEN, NSOPTION_sys_colour_AppWorkspace, 0x00eeeeee); + colour_option_from_pen(defaults, BACKGROUNDPEN, NSOPTION_sys_colour_Background, 0x00aa0000); + colour_option_from_pen(defaults, FOREGROUNDPEN, NSOPTION_sys_colour_ButtonFace, 0x00aaaaaa); + colour_option_from_pen(defaults, FORESHINEPEN, NSOPTION_sys_colour_ButtonHighlight, 0x00cccccc); + colour_option_from_pen(defaults, FORESHADOWPEN, NSOPTION_sys_colour_ButtonShadow, 0x00bbbbbb); + colour_option_from_pen(defaults, TEXTPEN, NSOPTION_sys_colour_ButtonText, 0x00000000); + colour_option_from_pen(defaults, FILLTEXTPEN, NSOPTION_sys_colour_CaptionText, 0x00000000); + colour_option_from_pen(defaults, DISABLEDTEXTPEN, NSOPTION_sys_colour_GrayText, 0x00777777); + colour_option_from_pen(defaults, SELECTPEN, NSOPTION_sys_colour_Highlight, 0x00ee0000); + colour_option_from_pen(defaults, SELECTTEXTPEN, NSOPTION_sys_colour_HighlightText, 0x00000000); + colour_option_from_pen(defaults, INACTIVEFILLPEN, NSOPTION_sys_colour_InactiveBorder, 0x00000000); + colour_option_from_pen(defaults, INACTIVEFILLPEN, NSOPTION_sys_colour_InactiveCaption, 0x00ffffff); + colour_option_from_pen(defaults, INACTIVEFILLTEXTPEN, NSOPTION_sys_colour_InactiveCaptionText, 0x00cccccc); + colour_option_from_pen(defaults, BACKGROUNDPEN, NSOPTION_sys_colour_InfoBackground, 0x00aaaaaa);/* This is wrong, HelpHint backgrounds are pale yellow but doesn't seem to be a DrawInfo pen defined for it. */ + colour_option_from_pen(defaults, TEXTPEN, NSOPTION_sys_colour_InfoText, 0x00000000); + colour_option_from_pen(defaults, MENUBACKGROUNDPEN, NSOPTION_sys_colour_Menu, 0x00aaaaaa); + colour_option_from_pen(defaults, MENUTEXTPEN, NSOPTION_sys_colour_MenuText, 0x00000000); + colour_option_from_pen(defaults, AMINS_SCROLLERPEN, NSOPTION_sys_colour_Scrollbar, 0x00aaaaaa); + colour_option_from_pen(defaults, FORESHADOWPEN, NSOPTION_sys_colour_ThreeDDarkShadow, 0x00555555); + colour_option_from_pen(defaults, FOREGROUNDPEN, NSOPTION_sys_colour_ThreeDFace, 0x00dddddd); + colour_option_from_pen(defaults, FORESHINEPEN, NSOPTION_sys_colour_ThreeDHighlight, 0x00aaaaaa); + colour_option_from_pen(defaults, HALFSHINEPEN, NSOPTION_sys_colour_ThreeDLightShadow, 0x00999999); + colour_option_from_pen(defaults, HALFSHADOWPEN, NSOPTION_sys_colour_ThreeDShadow, 0x00777777); + colour_option_from_pen(defaults, BACKGROUNDPEN, NSOPTION_sys_colour_Window, 0x00aaaaaa); + colour_option_from_pen(defaults, INACTIVEFILLPEN, NSOPTION_sys_colour_WindowFrame, 0x00000000); + colour_option_from_pen(defaults, TEXTPEN, NSOPTION_sys_colour_WindowText, 0x00000000); } @@ -549,36 +581,6 @@ static nserror ami_set_options(struct nsoption_s *defaults) nsoption_set_bool(truecolour_mouse_pointers, false); #endif - /* set system colours for amiga ui */ - colour_option_from_pen(defaults, FILLPEN, NSOPTION_sys_colour_ActiveBorder, 0x00000000); - colour_option_from_pen(defaults, FILLPEN, NSOPTION_sys_colour_ActiveCaption, 0x00dddddd); - colour_option_from_pen(defaults, BACKGROUNDPEN, NSOPTION_sys_colour_AppWorkspace, 0x00eeeeee); - colour_option_from_pen(defaults, BACKGROUNDPEN, NSOPTION_sys_colour_Background, 0x00aa0000); - colour_option_from_pen(defaults, FOREGROUNDPEN, NSOPTION_sys_colour_ButtonFace, 0x00aaaaaa); - colour_option_from_pen(defaults, FORESHINEPEN, NSOPTION_sys_colour_ButtonHighlight, 0x00cccccc); - colour_option_from_pen(defaults, FORESHADOWPEN, NSOPTION_sys_colour_ButtonShadow, 0x00bbbbbb); - colour_option_from_pen(defaults, TEXTPEN, NSOPTION_sys_colour_ButtonText, 0x00000000); - colour_option_from_pen(defaults, FILLTEXTPEN, NSOPTION_sys_colour_CaptionText, 0x00000000); - colour_option_from_pen(defaults, DISABLEDTEXTPEN, NSOPTION_sys_colour_GrayText, 0x00777777); - colour_option_from_pen(defaults, SELECTPEN, NSOPTION_sys_colour_Highlight, 0x00ee0000); - colour_option_from_pen(defaults, SELECTTEXTPEN, NSOPTION_sys_colour_HighlightText, 0x00000000); - colour_option_from_pen(defaults, INACTIVEFILLPEN, NSOPTION_sys_colour_InactiveBorder, 0x00000000); - colour_option_from_pen(defaults, INACTIVEFILLPEN, NSOPTION_sys_colour_InactiveCaption, 0x00ffffff); - colour_option_from_pen(defaults, INACTIVEFILLTEXTPEN, NSOPTION_sys_colour_InactiveCaptionText, 0x00cccccc); - colour_option_from_pen(defaults, BACKGROUNDPEN, NSOPTION_sys_colour_InfoBackground, 0x00aaaaaa);/* This is wrong, HelpHint backgrounds are pale yellow but doesn't seem to be a DrawInfo pen defined for it. */ - colour_option_from_pen(defaults, TEXTPEN, NSOPTION_sys_colour_InfoText, 0x00000000); - colour_option_from_pen(defaults, MENUBACKGROUNDPEN, NSOPTION_sys_colour_Menu, 0x00aaaaaa); - colour_option_from_pen(defaults, MENUTEXTPEN, NSOPTION_sys_colour_MenuText, 0x00000000); - colour_option_from_pen(defaults, AMINS_SCROLLERPEN, NSOPTION_sys_colour_Scrollbar, 0x00aaaaaa); - colour_option_from_pen(defaults, FORESHADOWPEN, NSOPTION_sys_colour_ThreeDDarkShadow, 0x00555555); - colour_option_from_pen(defaults, FOREGROUNDPEN, NSOPTION_sys_colour_ThreeDFace, 0x00dddddd); - colour_option_from_pen(defaults, FORESHINEPEN, NSOPTION_sys_colour_ThreeDHighlight, 0x00aaaaaa); - colour_option_from_pen(defaults, HALFSHINEPEN, NSOPTION_sys_colour_ThreeDLightShadow, 0x00999999); - colour_option_from_pen(defaults, HALFSHADOWPEN, NSOPTION_sys_colour_ThreeDShadow, 0x00777777); - colour_option_from_pen(defaults, BACKGROUNDPEN, NSOPTION_sys_colour_Window, 0x00aaaaaa); - colour_option_from_pen(defaults, INACTIVEFILLPEN, NSOPTION_sys_colour_WindowFrame, 0x00000000); - colour_option_from_pen(defaults, TEXTPEN, NSOPTION_sys_colour_WindowText, 0x00000000); - return NSERROR_OK; } -- cgit v1.2.3 From 173bfe3d3dd3d29a6fe37f9f6db542494dfe3f35 Mon Sep 17 00:00:00 2001 From: Chris Young Date: Sat, 1 Jun 2013 15:18:09 +0100 Subject: Fix the new prefs hook --- amiga/gui.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/amiga/gui.c b/amiga/gui.c index efeeed3c4..119fa18b2 100644 --- a/amiga/gui.c +++ b/amiga/gui.c @@ -674,8 +674,7 @@ void gui_init(int argc, char** argv) static void ami_gui_newprefs_hook(struct Hook *hook, APTR window, APTR reserved) { - gui_system_colour_finalize(); - gui_system_colour_init(); + ami_set_screen_defaults(scrn); } void ami_openscreen(void) -- cgit v1.2.3 From 3b971bb1a7883b4eaee965e65daa58d0258caed5 Mon Sep 17 00:00:00 2001 From: Chris Young Date: Sat, 1 Jun 2013 15:21:08 +0100 Subject: Remove bool default setter as the user will struggle to override it --- utils/nsoption.h | 5 ----- 1 file changed, 5 deletions(-) diff --git a/utils/nsoption.h b/utils/nsoption.h index b6ab860b1..bafcfb95a 100644 --- a/utils/nsoption.h +++ b/utils/nsoption.h @@ -271,11 +271,6 @@ int nsoption_snoptionf(char *string, size_t size, enum nsoption_e option, const } while (0) /* accessors for default options - user option is updated if it is set as per default */ -#define nsoption_default_set_bool(OPTION, VALUE) \ - if (nsoptions_default[NSOPTION_##OPTION].value.b == nsoptions[NSOPTION_##OPTION].value.b) \ - nsoptions[NSOPTION_##OPTION].value.b = VALUE; \ - nsoptions_default[NSOPTION_##OPTION].value.b = VALUE - #define nsoption_default_set_int(OPTION, VALUE) \ if (nsoptions_default[NSOPTION_##OPTION].value.i == nsoptions[NSOPTION_##OPTION].value.i) \ nsoptions[NSOPTION_##OPTION].value.i = VALUE; \ -- cgit v1.2.3 From 40682a899e157969a67062430a87cf43cacd1186 Mon Sep 17 00:00:00 2001 From: Chris Young Date: Sat, 1 Jun 2013 15:27:29 +0100 Subject: Remove unneeded parameter --- amiga/gui.c | 63 +++++++++++++++++++++++++++++-------------------------------- 1 file changed, 30 insertions(+), 33 deletions(-) diff --git a/amiga/gui.c b/amiga/gui.c index 119fa18b2..f47a728de 100644 --- a/amiga/gui.c +++ b/amiga/gui.c @@ -406,8 +406,7 @@ static UWORD ami_system_colour_scrollbar_fgpen(struct DrawInfo *drinfo) * set option from pen */ static nserror -colour_option_from_pen(struct nsoption_s *opts, - UWORD pen, +colour_option_from_pen(UWORD pen, enum nsoption_e option, colour def_colour) { @@ -416,7 +415,7 @@ colour_option_from_pen(struct nsoption_s *opts, if((option < NSOPTION_SYS_COLOUR_START) || (option > NSOPTION_SYS_COLOUR_END) || - (opts[option].type != OPTION_COLOUR)) { + (nsoptions[option].type != OPTION_COLOUR)) { return NSERROR_BAD_PARAMETER; } @@ -447,42 +446,40 @@ colour_option_from_pen(struct nsoption_s *opts, static void ami_set_screen_defaults(struct Screen *scrn) { - struct nsoption_s *defaults = nsoptions_default; - nsoption_default_set_int(window_x, 0); nsoption_default_set_int(window_y, scrn->BarHeight + 1); nsoption_default_set_int(window_width, scrn->Width); nsoption_default_set_int(window_height, scrn->Height - scrn->BarHeight - 1); /* set system colours for amiga ui */ - colour_option_from_pen(defaults, FILLPEN, NSOPTION_sys_colour_ActiveBorder, 0x00000000); - colour_option_from_pen(defaults, FILLPEN, NSOPTION_sys_colour_ActiveCaption, 0x00dddddd); - colour_option_from_pen(defaults, BACKGROUNDPEN, NSOPTION_sys_colour_AppWorkspace, 0x00eeeeee); - colour_option_from_pen(defaults, BACKGROUNDPEN, NSOPTION_sys_colour_Background, 0x00aa0000); - colour_option_from_pen(defaults, FOREGROUNDPEN, NSOPTION_sys_colour_ButtonFace, 0x00aaaaaa); - colour_option_from_pen(defaults, FORESHINEPEN, NSOPTION_sys_colour_ButtonHighlight, 0x00cccccc); - colour_option_from_pen(defaults, FORESHADOWPEN, NSOPTION_sys_colour_ButtonShadow, 0x00bbbbbb); - colour_option_from_pen(defaults, TEXTPEN, NSOPTION_sys_colour_ButtonText, 0x00000000); - colour_option_from_pen(defaults, FILLTEXTPEN, NSOPTION_sys_colour_CaptionText, 0x00000000); - colour_option_from_pen(defaults, DISABLEDTEXTPEN, NSOPTION_sys_colour_GrayText, 0x00777777); - colour_option_from_pen(defaults, SELECTPEN, NSOPTION_sys_colour_Highlight, 0x00ee0000); - colour_option_from_pen(defaults, SELECTTEXTPEN, NSOPTION_sys_colour_HighlightText, 0x00000000); - colour_option_from_pen(defaults, INACTIVEFILLPEN, NSOPTION_sys_colour_InactiveBorder, 0x00000000); - colour_option_from_pen(defaults, INACTIVEFILLPEN, NSOPTION_sys_colour_InactiveCaption, 0x00ffffff); - colour_option_from_pen(defaults, INACTIVEFILLTEXTPEN, NSOPTION_sys_colour_InactiveCaptionText, 0x00cccccc); - colour_option_from_pen(defaults, BACKGROUNDPEN, NSOPTION_sys_colour_InfoBackground, 0x00aaaaaa);/* This is wrong, HelpHint backgrounds are pale yellow but doesn't seem to be a DrawInfo pen defined for it. */ - colour_option_from_pen(defaults, TEXTPEN, NSOPTION_sys_colour_InfoText, 0x00000000); - colour_option_from_pen(defaults, MENUBACKGROUNDPEN, NSOPTION_sys_colour_Menu, 0x00aaaaaa); - colour_option_from_pen(defaults, MENUTEXTPEN, NSOPTION_sys_colour_MenuText, 0x00000000); - colour_option_from_pen(defaults, AMINS_SCROLLERPEN, NSOPTION_sys_colour_Scrollbar, 0x00aaaaaa); - colour_option_from_pen(defaults, FORESHADOWPEN, NSOPTION_sys_colour_ThreeDDarkShadow, 0x00555555); - colour_option_from_pen(defaults, FOREGROUNDPEN, NSOPTION_sys_colour_ThreeDFace, 0x00dddddd); - colour_option_from_pen(defaults, FORESHINEPEN, NSOPTION_sys_colour_ThreeDHighlight, 0x00aaaaaa); - colour_option_from_pen(defaults, HALFSHINEPEN, NSOPTION_sys_colour_ThreeDLightShadow, 0x00999999); - colour_option_from_pen(defaults, HALFSHADOWPEN, NSOPTION_sys_colour_ThreeDShadow, 0x00777777); - colour_option_from_pen(defaults, BACKGROUNDPEN, NSOPTION_sys_colour_Window, 0x00aaaaaa); - colour_option_from_pen(defaults, INACTIVEFILLPEN, NSOPTION_sys_colour_WindowFrame, 0x00000000); - colour_option_from_pen(defaults, TEXTPEN, NSOPTION_sys_colour_WindowText, 0x00000000); + colour_option_from_pen(FILLPEN, NSOPTION_sys_colour_ActiveBorder, 0x00000000); + colour_option_from_pen(FILLPEN, NSOPTION_sys_colour_ActiveCaption, 0x00dddddd); + colour_option_from_pen(BACKGROUNDPEN, NSOPTION_sys_colour_AppWorkspace, 0x00eeeeee); + colour_option_from_pen(BACKGROUNDPEN, NSOPTION_sys_colour_Background, 0x00aa0000); + colour_option_from_pen(FOREGROUNDPEN, NSOPTION_sys_colour_ButtonFace, 0x00aaaaaa); + colour_option_from_pen(FORESHINEPEN, NSOPTION_sys_colour_ButtonHighlight, 0x00cccccc); + colour_option_from_pen(FORESHADOWPEN, NSOPTION_sys_colour_ButtonShadow, 0x00bbbbbb); + colour_option_from_pen(TEXTPEN, NSOPTION_sys_colour_ButtonText, 0x00000000); + colour_option_from_pen(FILLTEXTPEN, NSOPTION_sys_colour_CaptionText, 0x00000000); + colour_option_from_pen(DISABLEDTEXTPEN, NSOPTION_sys_colour_GrayText, 0x00777777); + colour_option_from_pen(SELECTPEN, NSOPTION_sys_colour_Highlight, 0x00ee0000); + colour_option_from_pen(SELECTTEXTPEN, NSOPTION_sys_colour_HighlightText, 0x00000000); + colour_option_from_pen(INACTIVEFILLPEN, NSOPTION_sys_colour_InactiveBorder, 0x00000000); + colour_option_from_pen(INACTIVEFILLPEN, NSOPTION_sys_colour_InactiveCaption, 0x00ffffff); + colour_option_from_pen(INACTIVEFILLTEXTPEN, NSOPTION_sys_colour_InactiveCaptionText, 0x00cccccc); + colour_option_from_pen(BACKGROUNDPEN, NSOPTION_sys_colour_InfoBackground, 0x00aaaaaa);/* This is wrong, HelpHint backgrounds are pale yellow but doesn't seem to be a DrawInfo pen defined for it. */ + colour_option_from_pen(TEXTPEN, NSOPTION_sys_colour_InfoText, 0x00000000); + colour_option_from_pen(MENUBACKGROUNDPEN, NSOPTION_sys_colour_Menu, 0x00aaaaaa); + colour_option_from_pen(MENUTEXTPEN, NSOPTION_sys_colour_MenuText, 0x00000000); + colour_option_from_pen(AMINS_SCROLLERPEN, NSOPTION_sys_colour_Scrollbar, 0x00aaaaaa); + colour_option_from_pen(FORESHADOWPEN, NSOPTION_sys_colour_ThreeDDarkShadow, 0x00555555); + colour_option_from_pen(FOREGROUNDPEN, NSOPTION_sys_colour_ThreeDFace, 0x00dddddd); + colour_option_from_pen(FORESHINEPEN, NSOPTION_sys_colour_ThreeDHighlight, 0x00aaaaaa); + colour_option_from_pen(HALFSHINEPEN, NSOPTION_sys_colour_ThreeDLightShadow, 0x00999999); + colour_option_from_pen(HALFSHADOWPEN, NSOPTION_sys_colour_ThreeDShadow, 0x00777777); + colour_option_from_pen(BACKGROUNDPEN, NSOPTION_sys_colour_Window, 0x00aaaaaa); + colour_option_from_pen(INACTIVEFILLPEN, NSOPTION_sys_colour_WindowFrame, 0x00000000); + colour_option_from_pen(TEXTPEN, NSOPTION_sys_colour_WindowText, 0x00000000); } -- cgit v1.2.3 From 9ad5b98fcda6e99007741d80ad29674c3b26bc77 Mon Sep 17 00:00:00 2001 From: Chris Young Date: Sat, 1 Jun 2013 15:31:39 +0100 Subject: Don't read the state of gadgets which don't exist --- amiga/gui_options.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/amiga/gui_options.c b/amiga/gui_options.c index a68a4ecb6..e436cd2e9 100755 --- a/amiga/gui_options.c +++ b/amiga/gui_options.c @@ -1818,6 +1818,7 @@ void ami_gui_opts_use(bool save) nsoption_set_bool(hide_docky_icon, true); } +#ifdef WITH_PDF_EXPORT GetAttr(INTEGER_Number,gow->objects[GID_OPTS_MARGIN_TOP],(ULONG *)&nsoption_int(margin_top)); GetAttr(INTEGER_Number,gow->objects[GID_OPTS_MARGIN_LEFT],(ULONG *)&nsoption_int(margin_left)); @@ -1862,6 +1863,7 @@ void ami_gui_opts_use(bool save) } else { nsoption_set_bool(enable_PDF_password, false); } +#endif if(rescan_fonts == true) { ami_font_finiscanner(); -- cgit v1.2.3 From 31e3b27fad73dc5424017d55f918b383502d5d0e Mon Sep 17 00:00:00 2001 From: Chris Young Date: Sat, 1 Jun 2013 15:37:26 +0100 Subject: Set redraw tile size to default on screen change --- amiga/gui.c | 5 ++++- amiga/plotters.c | 2 -- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/amiga/gui.c b/amiga/gui.c index f47a728de..4ec0ea1d7 100644 --- a/amiga/gui.c +++ b/amiga/gui.c @@ -450,7 +450,10 @@ static void ami_set_screen_defaults(struct Screen *scrn) nsoption_default_set_int(window_y, scrn->BarHeight + 1); nsoption_default_set_int(window_width, scrn->Width); nsoption_default_set_int(window_height, scrn->Height - scrn->BarHeight - 1); - + + nsoption_default_set_int(redraw_tile_size_x, scrn->Width); + nsoption_default_set_int(redraw_tile_size_y, scrn->Height); + /* set system colours for amiga ui */ colour_option_from_pen(FILLPEN, NSOPTION_sys_colour_ActiveBorder, 0x00000000); colour_option_from_pen(FILLPEN, NSOPTION_sys_colour_ActiveCaption, 0x00dddddd); diff --git a/amiga/plotters.c b/amiga/plotters.c index d95915cc5..bf1c2bf69 100755 --- a/amiga/plotters.c +++ b/amiga/plotters.c @@ -154,8 +154,6 @@ void ami_init_layers(struct gui_globals *gg, ULONG width, ULONG height) palette_mapped = false; } - if(nsoption_int(redraw_tile_size_x) <= 0) nsoption_set_int(redraw_tile_size_x, scrn->Width); - if(nsoption_int(redraw_tile_size_y) <= 0) nsoption_set_int(redraw_tile_size_y, scrn->Height); if(!width) width = nsoption_int(redraw_tile_size_x); if(!height) height = nsoption_int(redraw_tile_size_y); -- cgit v1.2.3 From 9bd296987684788c32dd346b2d67671ed5dfe7a0 Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Sat, 1 Jun 2013 16:05:51 +0100 Subject: amiga is the only user of the very odd usage of the options API --- amiga/gui.c | 6 ++++++ utils/nsoption.h | 11 ----------- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/amiga/gui.c b/amiga/gui.c index 4ec0ea1d7..a26c0f7f7 100644 --- a/amiga/gui.c +++ b/amiga/gui.c @@ -196,6 +196,12 @@ static void ami_gui_window_update_box_deferred(struct gui_window *g, bool draw); static void ami_do_redraw(struct gui_window_2 *g); static void ami_schedule_redraw_remove(struct gui_window_2 *gwin); +/* accessors for default options - user option is updated if it is set as per default */ +#define nsoption_default_set_int(OPTION, VALUE) \ + if (nsoptions_default[NSOPTION_##OPTION].value.i == nsoptions[NSOPTION_##OPTION].value.i) \ + nsoptions[NSOPTION_##OPTION].value.i = VALUE; \ + nsoptions_default[NSOPTION_##OPTION].value.i = VALUE + STRPTR ami_locale_langs(void) { struct Locale *locale; diff --git a/utils/nsoption.h b/utils/nsoption.h index bafcfb95a..15ecee3c9 100644 --- a/utils/nsoption.h +++ b/utils/nsoption.h @@ -270,15 +270,4 @@ int nsoption_snoptionf(char *string, size_t size, enum nsoption_e option, const } \ } while (0) -/* accessors for default options - user option is updated if it is set as per default */ -#define nsoption_default_set_int(OPTION, VALUE) \ - if (nsoptions_default[NSOPTION_##OPTION].value.i == nsoptions[NSOPTION_##OPTION].value.i) \ - nsoptions[NSOPTION_##OPTION].value.i = VALUE; \ - nsoptions_default[NSOPTION_##OPTION].value.i = VALUE - -#define nsoption_default_set_colour(OPTION, VALUE) \ - if (nsoptions_default[NSOPTION_##OPTION].value.c == nsoptions[NSOPTION_##OPTION].value.c) \ - nsoptions[NSOPTION_##OPTION].value.c = VALUE; \ - nsoptions_default[NSOPTION_##OPTION].value.c = VALUE - #endif -- cgit v1.2.3 From bccaa05fdb50a1d5f481cf34f6af906638dfc68c Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Sat, 1 Jun 2013 15:49:17 +0100 Subject: add finalisation to options and document the API better --- framebuffer/gui.c | 7 +- gtk/gui.c | 15 +++- monkey/main.c | 8 +- utils/nsoption.c | 232 +++++++++++++++++++++++++++++++++++++++++------------- utils/nsoption.h | 136 ++++++++++++++++++++++++-------- 5 files changed, 301 insertions(+), 97 deletions(-) diff --git a/framebuffer/gui.c b/framebuffer/gui.c index 024ab283f..d9e78d7a8 100644 --- a/framebuffer/gui.c +++ b/framebuffer/gui.c @@ -568,9 +568,9 @@ main(int argc, char** argv) die("Options failed to initialise"); } options = filepath_find(respaths, "Choices"); - nsoption_read(options, NULL); + nsoption_read(options, nsoptions); free(options); - nsoption_commandline(&argc, argv, NULL); + nsoption_commandline(&argc, argv, nsoptions); /* common initialisation */ messages = filepath_find(respaths, "Messages"); @@ -625,6 +625,9 @@ main(int argc, char** argv) netsurf_exit(); + /* finalise options */ + nsoption_finalise(nsoptions, nsoptions_default); + return 0; } diff --git a/gtk/gui.c b/gtk/gui.c index ac743c5d0..01f9688e3 100644 --- a/gtk/gui.c +++ b/gtk/gui.c @@ -554,12 +554,14 @@ int main(int argc, char** argv) /* user options setup */ ret = nsoption_init(set_defaults, &nsoptions, &nsoptions_default); if (ret != NSERROR_OK) { - die("Options failed to initialise"); + fprintf(stderr, "Options failed to initialise (%s)\n", + messages_get_errorcode(ret)); + return 1; } options = filepath_find(respaths, "Choices"); - nsoption_read(options, NULL); + nsoption_read(options, nsoptions); free(options); - nsoption_commandline(&argc, argv, NULL); + nsoption_commandline(&argc, argv, nsoptions); check_options(respaths); /* check user options */ /* common initialisation */ @@ -567,7 +569,9 @@ int main(int argc, char** argv) ret = netsurf_init(messages); free(messages); if (ret != NSERROR_OK) { - die("NetSurf failed to initialise"); + fprintf(stderr, "NetSurf core failed to initialise (%s)\n", + messages_get_errorcode(ret)); + return 1; } /* run the browser */ @@ -581,6 +585,9 @@ int main(int argc, char** argv) /* common finalisation */ netsurf_exit(); + /* finalise options */ + nsoption_finalise(nsoptions, nsoptions_default); + return 0; } diff --git a/monkey/main.c b/monkey/main.c index 0a9826a3c..e806b0eb3 100644 --- a/monkey/main.c +++ b/monkey/main.c @@ -142,9 +142,9 @@ main(int argc, char **argv) die("Options failed to initialise"); } options = filepath_find(respaths, "Choices"); - nsoption_read(options, NULL); + nsoption_read(options, nsoptions); free(options); - nsoption_commandline(&argc, argv, NULL); + nsoption_commandline(&argc, argv, nsoptions); /* common initialisation */ messages = filepath_find(respaths, "Messages"); @@ -173,5 +173,9 @@ main(int argc, char **argv) netsurf_exit(); fprintf(stdout, "GENERIC FINISHED\n"); + + /* finalise options */ + nsoption_finalise(nsoptions, nsoptions_default); + return 0; } diff --git a/utils/nsoption.c b/utils/nsoption.c index a9264de6d..f6244cd48 100644 --- a/utils/nsoption.c +++ b/utils/nsoption.c @@ -54,7 +54,8 @@ struct nsoption_s *nsoptions_default = NULL; #define NSOPTION_COLOUR(NAME, DEFAULT) \ { #NAME, sizeof(#NAME) - 1, OPTION_COLOUR, { .c = DEFAULT } }, -struct nsoption_s defaults[] = { +/** The table of compiled in default options */ +static struct nsoption_s defaults[] = { #include "desktop/options.h" #if defined(riscos) @@ -160,11 +161,11 @@ static void nsoption_validate(struct nsoption_s *opts, struct nsoption_s *defs) /* to aid migration from old, broken, configuration files this * checks to see if all the system colours are set to black - * and returns them to defaults instead + * and returns them to defaults instead */ - for (cloop = NSOPTION_SYS_COLOUR_START; - cloop <= NSOPTION_SYS_COLOUR_END; + for (cloop = NSOPTION_SYS_COLOUR_START; + cloop <= NSOPTION_SYS_COLOUR_END; cloop++) { if (opts[cloop].value.c != 0) { black = false; @@ -172,18 +173,26 @@ static void nsoption_validate(struct nsoption_s *opts, struct nsoption_s *defs) } } if (black == true) { - for (cloop = NSOPTION_SYS_COLOUR_START; - cloop <= NSOPTION_SYS_COLOUR_END; + for (cloop = NSOPTION_SYS_COLOUR_START; + cloop <= NSOPTION_SYS_COLOUR_END; cloop++) { opts[cloop].value.c = defs[cloop].value.c; } } } -static bool -nsoption_is_set(struct nsoption_s *opts, - struct nsoption_s *defs, - enum nsoption_e entry) +/** + * Determines if an option is different between two option tables. + * + * @param opts The first table to compare. + * @param defs The second table to compare. + * @param entry The option to compare. + * @return true if the option differs false if not. + */ +static bool +nsoption_is_set(const struct nsoption_s *opts, + const struct nsoption_s *defs, + const enum nsoption_e entry) { bool ret = false; @@ -232,11 +241,12 @@ nsoption_is_set(struct nsoption_s *opts, return ret; } -/** Output choices to file stream +/** + * Output choices to file stream * - * @param fp the file stream to write to - * @param opts The options table to write - * @param defs the default value table to compare with. + * @param fp The file stream to write to. + * @param opts The options table to write. + * @param defs The default value table to compare with. * @param all Output all entries not just ones changed from defaults */ static nserror @@ -245,14 +255,12 @@ nsoption_output(FILE *fp, struct nsoption_s *defs, bool all) { - unsigned int entry; - bool show; + unsigned int entry; /* index to option being output */ colour rgbcolour; /* RRGGBB */ for (entry = 0; entry < NSOPTION_LISTEND; entry++) { - show = all || nsoption_is_set(opts, defs, entry); - - if (show == false) { + if ((all == false) && + (nsoption_is_set(opts, defs, entry) == false)) { continue; } @@ -302,11 +310,11 @@ nsoption_output(FILE *fp, /** * Output an option value into a string, in HTML format. * - * \param option The option to output the value of. - * \param size The size of the string buffer. - * \param pos The current position in string - * \param string The string in which to output the value. - * \return The number of bytes written to string or -1 on error + * @param option The option to output the value of. + * @param size The size of the string buffer. + * @param pos The current position in string + * @param string The string in which to output the value. + * @return The number of bytes written to string or -1 on error */ static size_t nsoption_output_value_html(struct nsoption_s *option, @@ -372,11 +380,11 @@ nsoption_output_value_html(struct nsoption_s *option, /** * Output an option value into a string, in plain text format. * - * \param option The option to output the value of. - * \param size The size of the string buffer. - * \param pos The current position in string - * \param string The string in which to output the value. - * \return The number of bytes written to string or -1 on error + * @param option The option to output the value of. + * @param size The size of the string buffer. + * @param pos The current position in string + * @param string The string in which to output the value. + * @return The number of bytes written to string or -1 on error */ static size_t nsoption_output_value_text(struct nsoption_s *option, @@ -429,6 +437,69 @@ nsoption_output_value_text(struct nsoption_s *option, return slen; } +/** + * Duplicates an option table. + * + * Allocates a new option table and copies an existing one into it. + * + * @param src The source table to copy + */ +static nserror +nsoption_dup(struct nsoption_s *src, struct nsoption_s **pdst) +{ + struct nsoption_s *dst; + dst = malloc(sizeof(defaults)); + if (dst == NULL) { + return NSERROR_NOMEM; + } + *pdst = dst; + + /* copy the source table into the destination table */ + memcpy(dst, src, sizeof(defaults)); + + while (src->key != NULL) { + if ((src->type == OPTION_STRING) && + (src->value.s != NULL)) { + dst->value.s = strdup(src->value.s); + } + src++; + dst++; + } + + return NSERROR_OK; +} + +/** + * frees an option table. + * + * Iterates through an option table a freeing resources as required + * finally freeing the option table itself. + * + * @param opts The option table to free. + */ +static nserror +nsoption_free(struct nsoption_s *opts) +{ + struct nsoption_s *cur; /* option being freed */ + + if (opts == NULL) { + return NSERROR_BAD_PARAMETER; + } + + cur = opts; + + while (cur->key != NULL) { + if ((cur->type == OPTION_STRING) && (cur->value.s != NULL)) { + free(cur->value.s); + } + cur++; + } + free(opts); + + return NSERROR_OK; +} + + /* exported interface documented in utils/nsoption.h */ nserror nsoption_init(nsoption_set_default_t *set_defaults, @@ -436,38 +507,37 @@ nsoption_init(nsoption_set_default_t *set_defaults, struct nsoption_s **pdefs) { nserror ret; - struct nsoption_s *src; - struct nsoption_s *dst; + struct nsoption_s *defs; struct nsoption_s *opts; + ret = nsoption_dup(&defaults[0], &defs); + if (ret != NSERROR_OK) { + return ret; + } + /* update the default table */ if (set_defaults != NULL) { - nsoptions = &defaults[0]; - ret = set_defaults(&defaults[0]); + /** @todo it would be better if the frontends actually + * set values in the passed in table instead of + * assuming the global one. + */ + opts = nsoptions; + nsoptions = defs; + + ret = set_defaults(defs); if (ret != NSERROR_OK) { - nsoptions = NULL; + nsoptions = opts; + nsoption_free(defs); return ret; } } - opts = malloc(sizeof(defaults)); - if (opts == NULL) { - return NSERROR_NOMEM; - } - /* copy the default values into the working set */ - src = &defaults[0]; - dst = opts; - - memcpy(dst, src, sizeof(defaults)); - - while (src->key != NULL) { - if ((src->type == OPTION_STRING) && (src->value.s != NULL)) { - dst->value.s = strdup(src->value.s); - } - src++; - dst++; + ret = nsoption_dup(defs, &opts); + if (ret != NSERROR_OK) { + nsoption_free(defs); + return ret; } /* return values if wanted */ @@ -478,13 +548,33 @@ nsoption_init(nsoption_set_default_t *set_defaults, } if (pdefs != NULL) { - *pdefs = &defaults[0]; + *pdefs = defs; + } else { + nsoptions_default = defs; } return NSERROR_OK; } +/* exported interface documented in utils/nsoption.h */ +nserror nsoption_finalise(struct nsoption_s *opts, struct nsoption_s *defs) +{ + /* check to see if global table selected */ + if (opts == NULL) { + opts = nsoptions; + } + nsoption_free(opts); + + /* check to see if global table selected */ + if (defs == NULL) { + defs = nsoptions_default; + } + + nsoption_free(defs); + + return NSERROR_OK; +} /* exported interface documented in utils/nsoption.h */ nserror @@ -503,8 +593,8 @@ nsoption_read(const char *path, struct nsoption_s *opts) opts = nsoptions; } - /* @todo is this and API bug not being a parameter */ - defs = nsoptions_default; + /** @todo is this and API bug not being a parameter */ + defs = nsoptions_default; fp = fopen(path, "r"); if (!fp) { @@ -569,7 +659,7 @@ nsoption_write(const char *path, /* check to see if global table selected */ if (defs == NULL) { - defs = &defaults[0]; + defs = nsoptions_default; } fp = fopen(path, "w"); @@ -699,8 +789,8 @@ nsoption_snoptionf(char *string, break; case 'p': - if (nsoption_is_set(nsoptions, - nsoptions_default, + if (nsoption_is_set(nsoptions, + nsoptions_default, option_idx)) { slen += snprintf(string + slen, size - slen, @@ -774,3 +864,33 @@ nsoption_snoptionf(char *string, return slen; } + +/* exported interface documented in options.h */ +nserror +nsoption_set_tbl_charp(struct nsoption_s *opts, + enum nsoption_e option_idx, + char *s) +{ + struct nsoption_s *option; + + option = &opts[option_idx]; + + /* ensure it is a string option */ + if (option->type != OPTION_STRING) { + return NSERROR_BAD_PARAMETER; + } + + /* free any existing string */ + if (option->value.s != NULL) { + free(option->value.s); + } + + option->value.s = s; + + /* check for empty string */ + if ((option->value.s != NULL) && (*option->value.s == 0)) { + free(option->value.s); + option->value.s = NULL; + } + return NSERROR_OK; +} diff --git a/utils/nsoption.h b/utils/nsoption.h index 15ecee3c9..d111729aa 100644 --- a/utils/nsoption.h +++ b/utils/nsoption.h @@ -34,7 +34,7 @@ * pointer to the active options table and be implemented as functions * within nsoptions.c * - * Indirect acees would have an impact on performance of NetSurf as + * Indirect access would have an impact on performance of NetSurf as * the expected option lookup cost is currently that of a simple * dereference (which this current implementation keeps). */ @@ -91,15 +91,17 @@ enum { OPTION_HTTP_PROXY_AUTH_NONE = 0, #define DEFAULT_EXPORT_SCALE 0.7 #ifndef DEFAULT_REFLOW_PERIOD -#define DEFAULT_REFLOW_PERIOD 25 /* time in cs */ +/** Default reflow time in cs */ +#define DEFAULT_REFLOW_PERIOD 25 #endif +/** The options type. */ enum nsoption_type_e { - OPTION_BOOL, - OPTION_INTEGER, - OPTION_UINT, - OPTION_STRING, - OPTION_COLOUR + OPTION_BOOL, /**< Option is a boolean. */ + OPTION_INTEGER, /**< Option is an integer. */ + OPTION_UINT, /**< Option is an unsigned integer */ + OPTION_STRING, /**< option is a heap allocated string. */ + OPTION_COLOUR /**< Option is a netsurf colour. */ }; struct nsoption_s { @@ -149,17 +151,24 @@ enum nsoption_e { #undef NSOPTION_UINT #undef NSOPTION_COLOUR -/* global option table */ +/** + * global active option table. + */ extern struct nsoption_s *nsoptions; -/* global default option table */ +/** + * global default option table. + */ extern struct nsoption_s *nsoptions_default; -/* default setting callback */ +/** + * default setting callback. + */ typedef nserror(nsoption_set_default_t)(struct nsoption_s *defaults); -/** Initialise option system. +/** + * Initialise option system. * * @param set_default callback to allow the customisation of the default * options. @@ -170,7 +179,20 @@ typedef nserror(nsoption_set_default_t)(struct nsoption_s *defaults); nserror nsoption_init(nsoption_set_default_t *set_default, struct nsoption_s **popts, struct nsoption_s **pdefs); -/** Read choices file and set them in the passed table +/** + * Finalise option system + * + * Releases all resources allocated in the initialisation. + * + * @param opts the options table or NULL to use global table. + * @param defs the default options table to use or NULL to use global table + * return The error status + */ +nserror nsoption_finalise(struct nsoption_s *opts, struct nsoption_s *defs); + + +/** + * Read choices file and set them in the passed table * * @param path The path to read the file from * @param opts The options table to enerate values from or NULL to use global @@ -179,7 +201,8 @@ nserror nsoption_init(nsoption_set_default_t *set_default, struct nsoption_s **p nserror nsoption_read(const char *path, struct nsoption_s *opts); -/** Write options that have changed from the defaults to a file. +/** + * Write options that have changed from the defaults to a file. * * The \a nsoption_dump can be used to output all entries not just * changed ones. @@ -201,6 +224,7 @@ nserror nsoption_write(const char *path, struct nsoption_s *opts, struct nsoptio */ nserror nsoption_dump(FILE *outf, struct nsoption_s *opts); + /** * Process commandline and set options approriately. * @@ -211,6 +235,7 @@ nserror nsoption_dump(FILE *outf, struct nsoption_s *opts); */ nserror nsoption_commandline(int *pargc, char **argv, struct nsoption_s *opts); + /** * Fill a buffer with an option using a format. * @@ -231,40 +256,85 @@ nserror nsoption_commandline(int *pargc, char **argv, struct nsoption_s *opts); int nsoption_snoptionf(char *string, size_t size, enum nsoption_e option, const char *fmt); +/** + * Get the value of a boolean option. + * + * Gets the value of an option assuming it is a boolean type. + * @note option type is unchecked so care must be taken in caller. + */ +#define nsoption_bool(OPTION) (nsoptions[NSOPTION_##OPTION].value.b) -/* value acessors - caution should be taken with type as this is not verified */ -#define nsoption_bool(OPTION) (nsoptions[NSOPTION_##OPTION].value.b) +/** + * Get the value of an integer option. + * + * Gets the value of an option assuming it is a integer type. + * @note option type is unchecked so care must be taken in caller. + */ #define nsoption_int(OPTION) (nsoptions[NSOPTION_##OPTION].value.i) + + +/** + * Get the value of an unsigned integer option. + * + * Gets the value of an option assuming it is a integer type. + * @note option type is unchecked so care must be taken in caller. + */ #define nsoption_uint(OPTION) (nsoptions[NSOPTION_##OPTION].value.u) + + +/** + * Get the value of a string option. + * + * Gets the value of an option assuming it is a string type. + * @note option type is unchecked so care must be taken in caller. + */ #define nsoption_charp(OPTION) (nsoptions[NSOPTION_##OPTION].value.s) + + +/** + * Get the value of a netsurf colour option. + * + * Gets the value of an option assuming it is a colour type. + * @note option type is unchecked so care must be taken in caller. + */ #define nsoption_colour(OPTION) (nsoptions[NSOPTION_##OPTION].value.c) + +/** set a boolean option in the default table */ #define nsoption_set_bool(OPTION, VALUE) nsoptions[NSOPTION_##OPTION].value.b = VALUE + + +/** set an integer option in the default table */ #define nsoption_set_int(OPTION, VALUE) nsoptions[NSOPTION_##OPTION].value.i = VALUE + + +/** set a colour option in the default table */ #define nsoption_set_colour(OPTION, VALUE) nsoptions[NSOPTION_##OPTION].value.c = VALUE -#define nsoption_set_charp(OPTION, VALUE) \ - do { \ - if (nsoptions[NSOPTION_##OPTION].value.s != NULL) { \ - free(nsoptions[NSOPTION_##OPTION].value.s); \ - } \ - nsoptions[NSOPTION_##OPTION].value.s = VALUE; \ - if ((nsoptions[NSOPTION_##OPTION].value.s != NULL) && \ - (*nsoptions[NSOPTION_##OPTION].value.s == 0)) { \ - free(nsoptions[NSOPTION_##OPTION].value.s); \ - nsoptions[NSOPTION_##OPTION].value.s = NULL; \ - } \ - } while (0) -/* if a string option is unset set it otherwise leave it set */ + +/** + * Set string option in specified table. + * + * Sets the string option to the value given freeing any resources + * currently allocated to the option. If the passed string is empty it + * is converted to the NULL value. + * + * @param opts The table to set option in + * @param option_idx The option + * @param s The string to set. This is used directly and not copied. + */ +nserror nsoption_set_tbl_charp(struct nsoption_s *opts, enum nsoption_e option_idx, char *s); + +/** set string option in default table */ +#define nsoption_set_charp(OPTION, VALUE) \ + nsoption_set_tbl_charp(nsoptions, NSOPTION_##OPTION, VALUE) + +/** set string option in default table if currently unset */ #define nsoption_setnull_charp(OPTION, VALUE) \ do { \ if (nsoptions[NSOPTION_##OPTION].value.s == NULL) { \ - nsoptions[NSOPTION_##OPTION].value.s = VALUE; \ - if (*nsoptions[NSOPTION_##OPTION].value.s == 0) { \ - free(nsoptions[NSOPTION_##OPTION].value.s); \ - nsoptions[NSOPTION_##OPTION].value.s = NULL; \ - } \ + nsoption_set_tbl_charp(nsoptions, NSOPTION_##OPTION, VALUE); \ } else { \ free(VALUE); \ } \ -- cgit v1.2.3 From 94dc0795c1b59476c50da3f4d8861675a37fcb33 Mon Sep 17 00:00:00 2001 From: Chris Young Date: Sat, 1 Jun 2013 18:56:53 +0100 Subject: Ensure treeview gets a palette rather than the built-in defaults --- amiga/gui.c | 88 +++++++++++++++++++++++++++++++++++-------------------------- 1 file changed, 50 insertions(+), 38 deletions(-) diff --git a/amiga/gui.c b/amiga/gui.c index a26c0f7f7..f5bd11aee 100644 --- a/amiga/gui.c +++ b/amiga/gui.c @@ -414,6 +414,7 @@ static UWORD ami_system_colour_scrollbar_fgpen(struct DrawInfo *drinfo) static nserror colour_option_from_pen(UWORD pen, enum nsoption_e option, + struct Screen *screen, colour def_colour) { ULONG colour[3]; @@ -425,21 +426,21 @@ colour_option_from_pen(UWORD pen, return NSERROR_BAD_PARAMETER; } - if(scrn != NULL) { - drinfo = GetScreenDrawInfo(scrn); + if(screen != NULL) { + drinfo = GetScreenDrawInfo(screen); if(drinfo != NULL) { if(pen == AMINS_SCROLLERPEN) pen = ami_system_colour_scrollbar_fgpen(drinfo); /* Get the colour of the pen being used for "pen" */ - GetRGB32(scrn->ViewPort.ColorMap, drinfo->dri_Pens[pen], 1, (ULONG *)&colour); + GetRGB32(screen->ViewPort.ColorMap, drinfo->dri_Pens[pen], 1, (ULONG *)&colour); /* convert it to a color */ def_colour = ((colour[0] & 0xff000000) >> 24) | ((colour[1] & 0xff000000) >> 16) | ((colour[2] & 0xff000000) >> 8); - FreeScreenDrawInfo(scrn, drinfo); + FreeScreenDrawInfo(screen, drinfo); } } @@ -450,45 +451,45 @@ colour_option_from_pen(UWORD pen, return NSERROR_OK; } -static void ami_set_screen_defaults(struct Screen *scrn) +static void ami_set_screen_defaults(struct Screen *screen) { nsoption_default_set_int(window_x, 0); - nsoption_default_set_int(window_y, scrn->BarHeight + 1); - nsoption_default_set_int(window_width, scrn->Width); - nsoption_default_set_int(window_height, scrn->Height - scrn->BarHeight - 1); + nsoption_default_set_int(window_y, screen->BarHeight + 1); + nsoption_default_set_int(window_width, screen->Width); + nsoption_default_set_int(window_height, screen->Height - screen->BarHeight - 1); - nsoption_default_set_int(redraw_tile_size_x, scrn->Width); - nsoption_default_set_int(redraw_tile_size_y, scrn->Height); + nsoption_default_set_int(redraw_tile_size_x, screen->Width); + nsoption_default_set_int(redraw_tile_size_y, screen->Height); /* set system colours for amiga ui */ - colour_option_from_pen(FILLPEN, NSOPTION_sys_colour_ActiveBorder, 0x00000000); - colour_option_from_pen(FILLPEN, NSOPTION_sys_colour_ActiveCaption, 0x00dddddd); - colour_option_from_pen(BACKGROUNDPEN, NSOPTION_sys_colour_AppWorkspace, 0x00eeeeee); - colour_option_from_pen(BACKGROUNDPEN, NSOPTION_sys_colour_Background, 0x00aa0000); - colour_option_from_pen(FOREGROUNDPEN, NSOPTION_sys_colour_ButtonFace, 0x00aaaaaa); - colour_option_from_pen(FORESHINEPEN, NSOPTION_sys_colour_ButtonHighlight, 0x00cccccc); - colour_option_from_pen(FORESHADOWPEN, NSOPTION_sys_colour_ButtonShadow, 0x00bbbbbb); - colour_option_from_pen(TEXTPEN, NSOPTION_sys_colour_ButtonText, 0x00000000); - colour_option_from_pen(FILLTEXTPEN, NSOPTION_sys_colour_CaptionText, 0x00000000); - colour_option_from_pen(DISABLEDTEXTPEN, NSOPTION_sys_colour_GrayText, 0x00777777); - colour_option_from_pen(SELECTPEN, NSOPTION_sys_colour_Highlight, 0x00ee0000); - colour_option_from_pen(SELECTTEXTPEN, NSOPTION_sys_colour_HighlightText, 0x00000000); - colour_option_from_pen(INACTIVEFILLPEN, NSOPTION_sys_colour_InactiveBorder, 0x00000000); - colour_option_from_pen(INACTIVEFILLPEN, NSOPTION_sys_colour_InactiveCaption, 0x00ffffff); - colour_option_from_pen(INACTIVEFILLTEXTPEN, NSOPTION_sys_colour_InactiveCaptionText, 0x00cccccc); - colour_option_from_pen(BACKGROUNDPEN, NSOPTION_sys_colour_InfoBackground, 0x00aaaaaa);/* This is wrong, HelpHint backgrounds are pale yellow but doesn't seem to be a DrawInfo pen defined for it. */ - colour_option_from_pen(TEXTPEN, NSOPTION_sys_colour_InfoText, 0x00000000); - colour_option_from_pen(MENUBACKGROUNDPEN, NSOPTION_sys_colour_Menu, 0x00aaaaaa); - colour_option_from_pen(MENUTEXTPEN, NSOPTION_sys_colour_MenuText, 0x00000000); - colour_option_from_pen(AMINS_SCROLLERPEN, NSOPTION_sys_colour_Scrollbar, 0x00aaaaaa); - colour_option_from_pen(FORESHADOWPEN, NSOPTION_sys_colour_ThreeDDarkShadow, 0x00555555); - colour_option_from_pen(FOREGROUNDPEN, NSOPTION_sys_colour_ThreeDFace, 0x00dddddd); - colour_option_from_pen(FORESHINEPEN, NSOPTION_sys_colour_ThreeDHighlight, 0x00aaaaaa); - colour_option_from_pen(HALFSHINEPEN, NSOPTION_sys_colour_ThreeDLightShadow, 0x00999999); - colour_option_from_pen(HALFSHADOWPEN, NSOPTION_sys_colour_ThreeDShadow, 0x00777777); - colour_option_from_pen(BACKGROUNDPEN, NSOPTION_sys_colour_Window, 0x00aaaaaa); - colour_option_from_pen(INACTIVEFILLPEN, NSOPTION_sys_colour_WindowFrame, 0x00000000); - colour_option_from_pen(TEXTPEN, NSOPTION_sys_colour_WindowText, 0x00000000); + colour_option_from_pen(FILLPEN, NSOPTION_sys_colour_ActiveBorder, screen, 0x00000000); + colour_option_from_pen(FILLPEN, NSOPTION_sys_colour_ActiveCaption, screen, 0x00dddddd); + colour_option_from_pen(BACKGROUNDPEN, NSOPTION_sys_colour_AppWorkspace, screen, 0x00eeeeee); + colour_option_from_pen(BACKGROUNDPEN, NSOPTION_sys_colour_Background, screen, 0x00aa0000); + colour_option_from_pen(FOREGROUNDPEN, NSOPTION_sys_colour_ButtonFace, screen, 0x00aaaaaa); + colour_option_from_pen(FORESHINEPEN, NSOPTION_sys_colour_ButtonHighlight, screen, 0x00cccccc); + colour_option_from_pen(FORESHADOWPEN, NSOPTION_sys_colour_ButtonShadow, screen, 0x00bbbbbb); + colour_option_from_pen(TEXTPEN, NSOPTION_sys_colour_ButtonText, screen, 0x00000000); + colour_option_from_pen(FILLTEXTPEN, NSOPTION_sys_colour_CaptionText, screen, 0x00000000); + colour_option_from_pen(DISABLEDTEXTPEN, NSOPTION_sys_colour_GrayText, screen, 0x00777777); + colour_option_from_pen(SELECTPEN, NSOPTION_sys_colour_Highlight, screen, 0x00ee0000); + colour_option_from_pen(SELECTTEXTPEN, NSOPTION_sys_colour_HighlightText, screen, 0x00000000); + colour_option_from_pen(INACTIVEFILLPEN, NSOPTION_sys_colour_InactiveBorder, screen, 0x00000000); + colour_option_from_pen(INACTIVEFILLPEN, NSOPTION_sys_colour_InactiveCaption, screen, 0x00ffffff); + colour_option_from_pen(INACTIVEFILLTEXTPEN, NSOPTION_sys_colour_InactiveCaptionText, screen, 0x00cccccc); + colour_option_from_pen(BACKGROUNDPEN, NSOPTION_sys_colour_InfoBackground, screen, 0x00aaaaaa);/* This is wrong, HelpHint backgrounds are pale yellow but doesn't seem to be a DrawInfo pen defined for it. */ + colour_option_from_pen(TEXTPEN, NSOPTION_sys_colour_InfoText, screen, 0x00000000); + colour_option_from_pen(MENUBACKGROUNDPEN, NSOPTION_sys_colour_Menu, screen, 0x00aaaaaa); + colour_option_from_pen(MENUTEXTPEN, NSOPTION_sys_colour_MenuText, screen, 0x00000000); + colour_option_from_pen(AMINS_SCROLLERPEN, NSOPTION_sys_colour_Scrollbar, screen, 0x00aaaaaa); + colour_option_from_pen(FORESHADOWPEN, NSOPTION_sys_colour_ThreeDDarkShadow, screen, 0x00555555); + colour_option_from_pen(FOREGROUNDPEN, NSOPTION_sys_colour_ThreeDFace, screen, 0x00dddddd); + colour_option_from_pen(FORESHINEPEN, NSOPTION_sys_colour_ThreeDHighlight, screen, 0x00aaaaaa); + colour_option_from_pen(HALFSHINEPEN, NSOPTION_sys_colour_ThreeDLightShadow, screen, 0x00999999); + colour_option_from_pen(HALFSHADOWPEN, NSOPTION_sys_colour_ThreeDShadow, screen, 0x00777777); + colour_option_from_pen(BACKGROUNDPEN, NSOPTION_sys_colour_Window, screen, 0x00aaaaaa); + colour_option_from_pen(INACTIVEFILLPEN, NSOPTION_sys_colour_WindowFrame, screen, 0x00000000); + colour_option_from_pen(TEXTPEN, NSOPTION_sys_colour_WindowText, screen, 0x00000000); } @@ -774,6 +775,7 @@ void ami_openscreenfirst(void) static void gui_init2(int argc, char** argv) { + struct Screen *screen; nsurl *url; nserror error; struct browser_window *bw = NULL; @@ -793,6 +795,16 @@ static void gui_init2(int argc, char** argv) /* Treeview init code ends up calling a font function which needs this */ glob = &browserglob; + + /* ...and this ensures the treeview at least gets the WB colour palette to work with */ + if(scrn == NULL) { + if(screen = LockPubScreen("Workbench")) { + ami_set_screen_defaults(screen); + UnlockPubScreen(NULL, screen); + } + } else { + ami_set_screen_defaults(scrn); + } /**/ ami_hotlist_initialise(nsoption_charp(hotlist_file)); -- cgit v1.2.3 From f31ab148cb99cb83a919046fd74f3895589b6878 Mon Sep 17 00:00:00 2001 From: Chris Young Date: Sun, 2 Jun 2013 16:07:59 +0100 Subject: Better logging for resource searching --- amiga/gui.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/amiga/gui.c b/amiga/gui.c index f5bd11aee..663c51315 100644 --- a/amiga/gui.c +++ b/amiga/gui.c @@ -291,6 +291,8 @@ bool ami_gui_check_resource(char *fullpath, const char *file) ami_gui_map_filename(&remapped, fullpath, file, "Resource.map"); path_add_part(fullpath, 1024, remapped); + LOG(("Checking for %s", fullpath)); + if(lock = Lock(fullpath, ACCESS_READ)) { UnLock(lock); -- cgit v1.2.3 From f2a6d645ae24ab49828d2d0ceb672bb7a80501c2 Mon Sep 17 00:00:00 2001 From: Chris Young Date: Sun, 2 Jun 2013 16:26:25 +0100 Subject: If a new browser window opens, bring the screen NetSurf is running on to the front --- amiga/gui.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/amiga/gui.c b/amiga/gui.c index 663c51315..a5cac9dfc 100644 --- a/amiga/gui.c +++ b/amiga/gui.c @@ -917,7 +917,7 @@ static void gui_init2(int argc, char** argv) } } - nsoption_setnull_charp(homepage_url, (char *)strdup(NETSURF_HOMEPAGE)); + nsoption_setnull_charp(homepage_url, (char *)strdup(NETSURF_HOMEPAGE)); if(!notalreadyrunning) { @@ -933,7 +933,6 @@ static void gui_init2(int argc, char** argv) sendcmd = ASPrintf("OPEN \"%s\" NEW",nsoption_charp(homepage_url)); } IDoMethod(arexx_obj,AM_EXECUTE,sendcmd,"NETSURF",NULL,NULL,NULL,NULL); - IDoMethod(arexx_obj,AM_EXECUTE,"TOFRONT","NETSURF",NULL,NULL,NULL,NULL); FreeVec(sendcmd); netsurf_quit=true; @@ -3746,6 +3745,8 @@ struct gui_window *gui_create_browser_window(struct browser_window *bw, if(locked_screen) UnlockPubScreen(NULL,scrn); search_web_retrieve_ico(false); + ScreenToFront(scrn); + return g; } -- cgit v1.2.3 From ae6058c15c4dbf1c067fac45cd092afeefa68a53 Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Sun, 2 Jun 2013 20:58:57 +0100 Subject: create objects from window on demand an keep them as simple unshared objects update prototype handling to keep GC refs --- javascript/WebIDL/console.idl | 4 + javascript/jsapi.h | 16 +-- javascript/jsapi/htmldocument.bnd | 1 + javascript/jsapi/window.bnd | 266 +++++++++++++++++++++++++------------- 4 files changed, 190 insertions(+), 97 deletions(-) diff --git a/javascript/WebIDL/console.idl b/javascript/WebIDL/console.idl index 309b976da..5a3d9eb27 100644 --- a/javascript/WebIDL/console.idl +++ b/javascript/WebIDL/console.idl @@ -17,4 +17,8 @@ interface Console { void timeEnd(DOMString timerName); void trace(); void warn(DOMString msg, Substitition... subst); +}; + +partial interface Window { + readonly attribute Console console; }; \ No newline at end of file diff --git a/javascript/jsapi.h b/javascript/jsapi.h index 8f9affd02..d8dcb360f 100644 --- a/javascript/jsapi.h +++ b/javascript/jsapi.h @@ -359,21 +359,19 @@ JS_NewCompartmentAndGlobalObject(JSContext *cx, #define JSAPI_CLASS_NO_INTERNAL_MEMBERS JSCLASS_NO_INTERNAL_MEMBERS /* GC marking */ -#ifdef JSCLASS_MARK_IS_TRACE -/* mark requires casting */ -#define JSAPI_JSCLASS_MARK_IS_TRACE JSCLASS_MARK_IS_TRACE -#define JSAPI_JSCLASS_MARKOP(x) ((JSMarkOp)x) -#else -/* mark does not require casting */ + +/* mark API is always JSTraceOp now */ #define JSAPI_JSCLASS_MARK_IS_TRACE 0 #define JSAPI_JSCLASS_MARKOP(x) (x) -#endif -#define JSAPI_MARKOP(name) JSBool name(JSTracer *trc, JSObject *obj) +#define JSAPI_MARKOP(name) void name(JSTracer *trc, JSObject *obj) #define JSAPI_MARKCX trc->context -#define JSAPI_GCMARK(thing) JS_CallTracer(trc, thing, JSTRACE_OBJECT); +#define JSAPI_GCMARK(thing) JS_CallTracer(trc, JSVAL_TO_TRACEABLE(OBJECT_TO_JSVAL(thing)), JSTRACE_OBJECT); + + + /* Macros for manipulating GC root */ #define JSAPI_ADD_OBJECT_ROOT(cx, obj) JS_AddObjectRoot(cx, obj) diff --git a/javascript/jsapi/htmldocument.bnd b/javascript/jsapi/htmldocument.bnd index 6e7f56528..bd65d7cb5 100644 --- a/javascript/jsapi/htmldocument.bnd +++ b/javascript/jsapi/htmldocument.bnd @@ -60,6 +60,7 @@ binding document { } api finalise %{ + LOG(("jscontext:%p jsobject:%p private:%p", cx, obj, private)); if (private != NULL) { JSLOG("dom_document %p in content %p", private->node, private->htmlc); diff --git a/javascript/jsapi/window.bnd b/javascript/jsapi/window.bnd index b334cc7cc..d06e7d478 100644 --- a/javascript/jsapi/window.bnd +++ b/javascript/jsapi/window.bnd @@ -11,6 +11,7 @@ webidlfile "html.idl"; webidlfile "dom.idl"; +webidlfile "console.idl"; hdrcomment "Copyright 2012 Vincent Sanders "; hdrcomment "This file is part of NetSurf, http://www.netsurf-browser.org/"; @@ -61,6 +62,72 @@ struct browser_window *jsapi_get_browser_window(JSContext *cx) return NULL; } +static bool +init_user_prototypes(JSContext *cx, + struct jsclass_private *private, + JSObject *parent) +{ + /* Initialises all the user javascript classes to make their + * prototypes available. + */ + /** @todo should we be managing these prototype objects ourselves */ + private->prototype_Document = jsapi_InitClass_Document(cx, parent); + if (private->prototype_Document == NULL) { + return false; + } + + private->prototype_Navigator = jsapi_InitClass_Navigator(cx, parent); + if (private->prototype_Navigator == NULL) { + return false; + } + + private->prototype_Location = jsapi_InitClass_Location(cx, parent); + if (private->prototype_Location == NULL) { + return false; + } + + private->prototype_Console = jsapi_InitClass_Console(cx, parent); + if (private->prototype_Console == NULL) { + return false; + } + + private->prototype_HTMLElement = jsapi_InitClass_HTMLElement(cx, parent); + if (private->prototype_HTMLElement == NULL) { + return false; + } + + private->prototype_HTMLCollection = jsapi_InitClass_HTMLCollection(cx, parent); + if (private->prototype_HTMLCollection == NULL) { + return false; + } + + private->prototype_NodeList = jsapi_InitClass_NodeList(cx, parent); + if (private->prototype_NodeList == NULL) { + return false; + } + + private->prototype_Text = jsapi_InitClass_Text(cx, parent); + if (private->prototype_Text == NULL) { + return false; + } + + private->prototype_Comment = jsapi_InitClass_Comment(cx, parent); + if (private->prototype_Comment == NULL) { + return false; + } + + private->prototype_Node = jsapi_InitClass_Node(cx, parent); + if (private->prototype_Node == NULL) { + return false; + } + + private->prototype_Event = jsapi_InitClass_Event(cx, parent); + if (private->prototype_Event == NULL) { + return false; + } + return true; +} + %} binding window { @@ -71,23 +138,83 @@ binding window { private "struct browser_window *" bw; private "struct html_content *" htmlc; - internal "JSObject *" document; - internal "JSObject *" navigator; - internal "JSObject *" console; + /* prototypes held in this object */ + internal "JSObject *" prototype_Document; + internal "JSObject *" prototype_Navigator; + internal "JSObject *" prototype_Location; + internal "JSObject *" prototype_Console; + internal "JSObject *" prototype_HTMLElement; + internal "JSObject *" prototype_HTMLCollection; + internal "JSObject *" prototype_NodeList; + internal "JSObject *" prototype_Text; + internal "JSObject *" prototype_Comment; + internal "JSObject *" prototype_Node; + internal "JSObject *" prototype_Event; + /** document instantiated on first use */ + property unshared document; + + /** navigator instantiated on first use */ + property unshared navigator; + + /** console instantiated on first use */ + property unshared console; + + /** location is unshared */ + property unshared location; + + /** @todo instantiate forms, history etc. attributes */ + + /* events through a single interface */ property unshared type EventHandler; } api mark %{ + + LOG(("jscontext:%p jsobject:%p private:%p", JSAPI_MARKCX, obj, private)); if (private != NULL) { - if (private->document != NULL) { - JSAPI_GCMARK(private->document); + if (private->prototype_Document != NULL) { + JSAPI_GCMARK(private->prototype_Document); + } + + if (private->prototype_Navigator != NULL) { + JSAPI_GCMARK(private->prototype_Navigator); + } + + if (private->prototype_Location != NULL) { + JSAPI_GCMARK(private->prototype_Location); } - if (private->navigator != NULL) { - JSAPI_GCMARK(private->navigator); + + if (private->prototype_Console != NULL) { + JSAPI_GCMARK(private->prototype_Console); } - if (private->console != NULL) { - JSAPI_GCMARK(private->console); + + if (private->prototype_HTMLElement != NULL) { + JSAPI_GCMARK(private->prototype_HTMLElement); + } + + if (private->prototype_HTMLCollection != NULL) { + JSAPI_GCMARK(private->prototype_HTMLCollection); + } + + if (private->prototype_NodeList != NULL) { + JSAPI_GCMARK(private->prototype_NodeList); + } + + if (private->prototype_Text != NULL) { + JSAPI_GCMARK(private->prototype_Text); + } + + if (private->prototype_Comment != NULL) { + JSAPI_GCMARK(private->prototype_Comment); + } + + if (private->prototype_Node != NULL) { + JSAPI_GCMARK(private->prototype_Node); + } + + if (private->prototype_Event != NULL) { + JSAPI_GCMARK(private->prototype_Event); } } %} @@ -96,8 +223,6 @@ api global %{ %} api init %{ - JSObject *user_proto; - prototype = JS_NewCompartmentAndGlobalObject(cx, &JSClass_Window, NULL); if (prototype == NULL) { return NULL; @@ -127,66 +252,6 @@ api init %{ /* add properties to prototype */ if (!JS_DefineProperties(cx, prototype, jsclass_properties)) return NULL; - - /* Initialises all the user javascript classes to make their - * prototypes available. - */ - /** @todo should we be managing these prototype objects ourselves */ - user_proto = jsapi_InitClass_Document(cx, prototype); - if (user_proto == NULL) { - return NULL; - } - - user_proto = jsapi_InitClass_Navigator(cx, prototype); - if (user_proto == NULL) { - return NULL; - } - - user_proto = jsapi_InitClass_Location(cx, prototype); - if (user_proto == NULL) { - return NULL; - } - - user_proto = jsapi_InitClass_Console(cx, prototype); - if (user_proto == NULL) { - return NULL; - } - - user_proto = jsapi_InitClass_HTMLElement(cx, prototype); - if (user_proto == NULL) { - return NULL; - } - - user_proto = jsapi_InitClass_HTMLCollection(cx, prototype); - if (user_proto == NULL) { - return NULL; - } - - user_proto = jsapi_InitClass_NodeList(cx, prototype); - if (user_proto == NULL) { - return NULL; - } - - user_proto = jsapi_InitClass_Text(cx, prototype); - if (user_proto == NULL) { - return NULL; - } - - user_proto = jsapi_InitClass_Comment(cx, prototype); - if (user_proto == NULL) { - return NULL; - } - - user_proto = jsapi_InitClass_Node(cx, prototype); - if (user_proto == NULL) { - return NULL; - } - - user_proto = jsapi_InitClass_Event(cx, prototype); - if (user_proto == NULL) { - return NULL; - } - %} api new %{ @@ -196,32 +261,45 @@ api new %{ /* the window object is the global so its prototype *is* the instance */ newobject = prototype; - /* instantiate the subclasses off the window global */ - private->document = jsapi_new_Document(cx, - NULL, - newobject, - (dom_document *)dom_node_ref(htmlc->document), - htmlc); - if (private->document == NULL) { + if (init_user_prototypes(cx, private, prototype) == false) { + /* prototype initialisation failed */ free(private); return NULL; } - private->navigator = jsapi_new_Navigator(cx, NULL, newobject); - if (private->navigator == NULL) { - free(private); - return NULL; + LOG(("Created new window object %p", newobject)); +%} + +getter document %{ + if (!JSVAL_IS_VOID(JSAPI_PROP_RVAL(cx, vp))) { + /* already created - return it */ + return JS_TRUE; } - private->console = jsapi_new_Console(cx, NULL, newobject); - if (private->console == NULL) { - free(private); - return NULL; + /* instantiate the subclasses off the window global */ + jsret = jsapi_new_Document(cx, + NULL, + NULL, + (dom_document *)dom_node_ref(private->htmlc->document), + private->htmlc); +%} + +getter navigator %{ + if (!JSVAL_IS_VOID(JSAPI_PROP_RVAL(cx, vp))) { + /* already created - return it */ + return JS_TRUE; } - /** @todo forms, history */ + jsret = jsapi_new_Navigator(cx, NULL, NULL); +%} - LOG(("Created new window object %p", newobject)); +getter console %{ + if (!JSVAL_IS_VOID(JSAPI_PROP_RVAL(cx, vp))) { + /* already created - return it */ + return JS_TRUE; + } + + jsret = jsapi_new_Console(cx, NULL, NULL); %} operation confirm %{ @@ -273,9 +351,21 @@ operation dispatchEvent %{ %} getter location %{ + if (!JSVAL_IS_VOID(JSAPI_PROP_RVAL(cx, vp))) { + /* already created - return it */ + return JS_TRUE; + } + +/* should get the docuemnts location jsval loc; JS_GetProperty(cx, private->document, "location", &loc); jsret = JSVAL_TO_OBJECT(loc); +*/ + + jsret = jsapi_new_Location(cx, + NULL, + NULL, + llcache_handle_get_url(private->htmlc->base.llcache)); %} getter window %{ -- cgit v1.2.3 From 6397fedb2b221aab93d697ed9fc0530dd1415233 Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Mon, 3 Jun 2013 11:07:32 +0100 Subject: Turns out there are still two different compiles of the 1.8.5 API about --- javascript/jsapi.h | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/javascript/jsapi.h b/javascript/jsapi.h index d8dcb360f..5b544b8fd 100644 --- a/javascript/jsapi.h +++ b/javascript/jsapi.h @@ -23,7 +23,7 @@ #ifndef _NETSURF_JAVASCRIPT_JSAPI_H_ #define _NETSURF_JAVASCRIPT_JSAPI_H_ -/* include teh correct header */ +/* include the correct header */ #ifdef WITH_MOZJS #include "js/jsapi.h" #else @@ -155,8 +155,10 @@ JS_NewCompartmentAndGlobalObject(JSContext *cx, #define JSAPI_GCMARK(thing) JS_MarkGCThing(cx, thing, "object", arg) -/* Macros for manipulating GC root */ +#define JSAPI_MARKOP_RETURN(value) return value + +/* Macros for manipulating GC root */ #define JSAPI_ADD_OBJECT_ROOT(cx, obj) JS_AddRoot(cx, obj) #define JSAPI_REMOVE_OBJECT_ROOT(cx, obj) JS_RemoveRoot(cx, obj) @@ -270,6 +272,8 @@ JS_NewCompartmentAndGlobalObject(JSContext *cx, #define JSAPI_GCMARK(thing) JS_CallTracer(trc, thing, JSTRACE_OBJECT); +#define JSAPI_MARKOP_RETURN(value) return value + /* Macros for manipulating GC root */ #define JSAPI_ADD_OBJECT_ROOT(cx, obj) JS_AddRoot(cx, obj) #define JSAPI_REMOVE_OBJECT_ROOT(cx, obj) JS_RemoveRoot(cx, obj) @@ -359,18 +363,23 @@ JS_NewCompartmentAndGlobalObject(JSContext *cx, #define JSAPI_CLASS_NO_INTERNAL_MEMBERS JSCLASS_NO_INTERNAL_MEMBERS /* GC marking */ - -/* mark API is always JSTraceOp now */ +#ifdef JSCLASS_MARK_IS_TRACE +/* mark function pointer requires casting */ +#define JSAPI_JSCLASS_MARK_IS_TRACE JSCLASS_MARK_IS_TRACE +#define JSAPI_JSCLASS_MARKOP(x) ((JSMarkOp)x) +#else +/* mark function pointer does not require casting */ #define JSAPI_JSCLASS_MARK_IS_TRACE 0 #define JSAPI_JSCLASS_MARKOP(x) (x) +#endif #define JSAPI_MARKOP(name) void name(JSTracer *trc, JSObject *obj) #define JSAPI_MARKCX trc->context -#define JSAPI_GCMARK(thing) JS_CallTracer(trc, JSVAL_TO_TRACEABLE(OBJECT_TO_JSVAL(thing)), JSTRACE_OBJECT); - +#define JSAPI_GCMARK(thing) JS_CallTracer(trc, thing, JSTRACE_OBJECT); +#define JSAPI_MARKOP_RETURN(value) /* Macros for manipulating GC root */ -- cgit v1.2.3 From 8d57bb30af6e5f72664c1176155c55ed7198f60e Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Mon, 3 Jun 2013 11:55:37 +0100 Subject: forcing a GC when the new global is created improves memory usage with scripts enabled --- javascript/jsapi/window.bnd | 3 +++ 1 file changed, 3 insertions(+) diff --git a/javascript/jsapi/window.bnd b/javascript/jsapi/window.bnd index d06e7d478..5de0e5bf0 100644 --- a/javascript/jsapi/window.bnd +++ b/javascript/jsapi/window.bnd @@ -252,6 +252,9 @@ api init %{ /* add properties to prototype */ if (!JS_DefineProperties(cx, prototype, jsclass_properties)) return NULL; + + /* as the global just got changed, force a GC run */ + JS_GC(cx); %} api new %{ -- cgit v1.2.3 From 3aba4b778aa416c7a8e86f85610dbf4efb758555 Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Mon, 3 Jun 2013 15:16:38 +0100 Subject: enable trace logging in binding generation --- javascript/Makefile | 2 +- javascript/jsapi/window.bnd | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/javascript/Makefile b/javascript/Makefile index ac73ee716..693ed6541 100644 --- a/javascript/Makefile +++ b/javascript/Makefile @@ -35,7 +35,7 @@ D_JSAPI_BINDING += $(patsubst %.c,%.d,$(2)) $(2): $(1) $(OBJROOT)/created $$(VQ)echo " GENBIND: $(1)" - $(Q)nsgenbind -I javascript/WebIDL -d $(patsubst %.c,%.d,$(2)) -h $(3) -o $(2) $(1) + $(Q)nsgenbind -g -I javascript/WebIDL -d $(patsubst %.c,%.d,$(2)) -h $(3) -o $(2) $(1) $(3): $(2) diff --git a/javascript/jsapi/window.bnd b/javascript/jsapi/window.bnd index 5de0e5bf0..199fcec9c 100644 --- a/javascript/jsapi/window.bnd +++ b/javascript/jsapi/window.bnd @@ -171,7 +171,6 @@ binding window { api mark %{ - LOG(("jscontext:%p jsobject:%p private:%p", JSAPI_MARKCX, obj, private)); if (private != NULL) { if (private->prototype_Document != NULL) { JSAPI_GCMARK(private->prototype_Document); -- cgit v1.2.3