From f123ed101f6651b15175a9cf33038bf54975dd8b Mon Sep 17 00:00:00 2001 From: Chris Young Date: Tue, 3 Feb 2015 19:48:28 +0000 Subject: Lazy bitmap font rendered text for slow hardware (non-working) --- amiga/Makefile.target | 3 ++- amiga/font.c | 72 ++++++++++++++++++++++++++++++++++++--------------- amiga/font.h | 14 ++++++++++ amiga/options.h | 1 + 4 files changed, 68 insertions(+), 22 deletions(-) diff --git a/amiga/Makefile.target b/amiga/Makefile.target index 7d858ef8a..902770722 100644 --- a/amiga/Makefile.target +++ b/amiga/Makefile.target @@ -74,7 +74,8 @@ S_AMIGA := gui.c tree.c history.c hotlist.c schedule.c file.c \ sslcert.c gui_options.c print.c theme.c drag.c icon.c libs.c \ datatypes.c dt_picture.c dt_anim.c dt_sound.c plugin_hack.c \ stringview/stringview.c stringview/urlhistory.c rtg.c \ - agclass/amigaguide_class.c fs_backing_store.c os3support.c + agclass/amigaguide_class.c fs_backing_store.c os3support.c \ + font_bitmap.c S_AMIGA := $(addprefix amiga/,$(S_AMIGA)) # This is the final source build list diff --git a/amiga/font.c b/amiga/font.c index 435e75992..80e34bd10 100644 --- a/amiga/font.c +++ b/amiga/font.c @@ -160,26 +160,8 @@ struct OutlineFont *ami_open_outline_font(const plot_font_style_t *fstyle, const uint16 *codepoint); static void ami_font_cleanup(struct MinList *ami_font_list); -static bool nsfont_width(const plot_font_style_t *fstyle, - const char *string, size_t length, - int *width); - -static bool nsfont_position_in_string(const plot_font_style_t *fstyle, - const char *string, size_t length, - int x, size_t *char_offset, int *actual_x); - -static bool nsfont_split(const plot_font_style_t *fstyle, - const char *string, size_t length, - int x, size_t *char_offset, int *actual_x); -const struct font_functions nsfont = { - nsfont_width, - nsfont_position_in_string, - nsfont_split -}; - - -bool nsfont_width(const plot_font_style_t *fstyle, +static bool amiga_nsfont_width(const plot_font_style_t *fstyle, const char *string, size_t length, int *width) { @@ -202,7 +184,7 @@ bool nsfont_width(const plot_font_style_t *fstyle, * \return true on success, false on error and error reported */ -bool nsfont_position_in_string(const plot_font_style_t *fstyle, +static bool amiga_nsfont_position_in_string(const plot_font_style_t *fstyle, const char *string, size_t length, int x, size_t *char_offset, int *actual_x) { @@ -289,7 +271,7 @@ bool nsfont_position_in_string(const plot_font_style_t *fstyle, * Returning char_offset == length means no split possible */ -bool nsfont_split(const plot_font_style_t *fstyle, +static bool amiga_nsfont_split(const plot_font_style_t *fstyle, const char *string, size_t length, int x, size_t *char_offset, int *actual_x) { @@ -752,6 +734,10 @@ ULONG ami_unicode_text(struct RastPort *rp, const char *string, ULONG length, if(!string || string[0]=='\0') return 0; if(!length) return 0; + if(nsoption_bool(use_diskfont) == true) { + return ami_font_bm_text(rp, string, length, fstyle, dx, dy); + } + if(utf8_to_enc(string,"UTF-16",length,(char **)&utf16) != NSERROR_OK) return 0; outf16 = utf16; if(!(ofont = ami_open_outline_font(fstyle, 0))) return 0; @@ -949,3 +935,47 @@ void ami_font_close_disk_font(struct TextFont *tfont) { CloseFont(tfont); } + + +/* Stub entry points */ +static bool nsfont_width(const plot_font_style_t *fstyle, + const char *string, size_t length, + int *width) +{ + if(nsoption_bool(use_diskfont) == false) { + return amiga_nsfont_width(fstyle, string, length, width); + } else { + return amiga_bm_nsfont_width(fstyle, string, length, width); + } +} + +static bool nsfont_position_in_string(const plot_font_style_t *fstyle, + const char *string, size_t length, + int x, size_t *char_offset, int *actual_x) +{ + if(nsoption_bool(use_diskfont) == false) { + return amiga_nsfont_position_in_string(fstyle, string, length, x, + char_offset, actual_x); + } else { + return amiga_bm_nsfont_position_in_string(fstyle, string, length, x, + char_offset, actual_x); + } +} + +static bool nsfont_split(const plot_font_style_t *fstyle, + const char *string, size_t length, + int x, size_t *char_offset, int *actual_x) +{ + if(nsoption_bool(use_diskfont) == false) { + return amiga_nsfont_split(fstyle, string, length, x, char_offset, actual_x); + } else { + return amiga_bm_nsfont_split(fstyle, string, length, x, char_offset, actual_x); + } +} + +const struct font_functions nsfont = { + nsfont_width, + nsfont_position_in_string, + nsfont_split +}; + diff --git a/amiga/font.h b/amiga/font.h index 10137f777..6c600abe4 100755 --- a/amiga/font.h +++ b/amiga/font.h @@ -40,4 +40,18 @@ void ami_font_savescanner(void); /* Simple diskfont functions for graphics.library use (not page rendering) */ struct TextFont *ami_font_open_disk_font(struct TextAttr *tattr); void ami_font_close_disk_font(struct TextFont *tfont); + +/* In font_bitmap.c */ +bool amiga_bm_nsfont_width(const plot_font_style_t *fstyle, + const char *string, size_t length, int *width); +bool amiga_bm_nsfont_position_in_string(const plot_font_style_t *fstyle, + const char *string, size_t length, + int x, size_t *char_offset, int *actual_x); +bool amiga_bm_nsfont_split(const plot_font_style_t *fstyle, + const char *string, size_t length, + int x, size_t *char_offset, int *actual_x); +ULONG ami_font_bm_text(struct RastPort *rp, const char *string, ULONG length, + const plot_font_style_t *fstyle, ULONG dx, ULONG dy); + #endif + diff --git a/amiga/options.h b/amiga/options.h index 868e28fdb..b94242085 100644 --- a/amiga/options.h +++ b/amiga/options.h @@ -63,6 +63,7 @@ NSOPTION_STRING(font_unicode, NULL) NSOPTION_STRING(font_unicode_file, NULL) NSOPTION_BOOL(font_unicode_only, false) NSOPTION_BOOL(font_antialiasing, true) +NSOPTION_BOOL(use_diskfont, false) NSOPTION_BOOL(drag_save_icons, true) NSOPTION_INTEGER(hotlist_window_xpos, 0) NSOPTION_INTEGER(hotlist_window_ypos, 0) -- cgit v1.2.3 From 5bd9b45758a91f7b792d7da5657cfcec9b081481 Mon Sep 17 00:00:00 2001 From: Chris Young Date: Tue, 3 Feb 2015 19:51:55 +0000 Subject: File missing from previous commit --- amiga/font_bitmap.c | 215 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 215 insertions(+) create mode 100644 amiga/font_bitmap.c diff --git a/amiga/font_bitmap.c b/amiga/font_bitmap.c new file mode 100644 index 000000000..d620ea90c --- /dev/null +++ b/amiga/font_bitmap.c @@ -0,0 +1,215 @@ +/* + * Copyright 2008 - 2015 Chris Young + * + * This file is part of NetSurf, http://www.netsurf-browser.org/ + * + * NetSurf is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * NetSurf is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "amiga/os3support.h" + +#include + +#include +#include +#include +#include +#include + +#include + +#include "utils/log.h" +#include "utils/utf8.h" +#include "utils/utils.h" +#include "utils/nsoption.h" +#include "desktop/browser.h" +#include "desktop/font.h" +#include "desktop/gui_window.h" + +#include "amiga/font.h" +#include "amiga/gui.h" +#include "amiga/utf8.h" + +static struct TextFont *ami_font_bm_open(struct RastPort *rp, const plot_font_style_t *fstyle) +{ + struct TextFont *bmfont = NULL; + struct TextAttr tattr; + char *fontname, font; + + if(rp == NULL) return NULL; + + switch(fstyle->family) + { + case PLOT_FONT_FAMILY_SANS_SERIF: + fontname = nsoption_charp(font_sans); + break; + case PLOT_FONT_FAMILY_SERIF: + fontname = nsoption_charp(font_serif); + break; + case PLOT_FONT_FAMILY_MONOSPACE: + fontname = nsoption_charp(font_mono); + break; + case PLOT_FONT_FAMILY_CURSIVE: + fontname = nsoption_charp(font_cursive); + break; + case PLOT_FONT_FAMILY_FANTASY: + fontname = nsoption_charp(font_fantasy); + break; + default: + return NULL; + break; + } + + tattr.ta_Style = FS_NORMAL; + + if (fstyle->flags & FONTF_OBLIQUE) + tattr.ta_Style = FSF_ITALIC; + + if (fstyle->flags & FONTF_ITALIC) + tattr.ta_Style = FSF_ITALIC; + + if (fstyle->weight >= 700) + tattr.ta_Style |= FSF_BOLD; + + if(font = ASPrintf("%s.font", fontname)) { + tattr.ta_Name = font; + tattr.ta_YSize = fstyle->size / FONT_SIZE_SCALE; + + if(bmfont = OpenDiskFont(&tattr)) { + SetRPAttrs(rp, RPTAG_Font, bmfont, TAG_DONE); + } + FreeVec(font); + } + + return bmfont; +} + +static void ami_font_bm_close(struct TextFont *bmfont) +{ + CloseFont(bmfont); +} + +bool amiga_bm_nsfont_width(const plot_font_style_t *fstyle, + const char *string, size_t length, + int *width) +{ + struct TextFont *bmfont = ami_font_bm_open(glob->rp, fstyle); +// convert to local charset + *width = TextLength(glob->rp, string, length); + ami_font_bm_close(bmfont); + + return true; +} + +/** + * Find the position in a string where an x coordinate falls. + * + * \param fstyle style for this text + * \param string UTF-8 string to measure + * \param length length of string + * \param x x coordinate to search for + * \param char_offset updated to offset in string of actual_x, [0..length] + * \param actual_x updated to x coordinate of character closest to x + * \return true on success, false on error and error reported + */ + +bool amiga_bm_nsfont_position_in_string(const plot_font_style_t *fstyle, + const char *string, size_t length, + int x, size_t *char_offset, int *actual_x) +{ + struct TextExtent extent; + struct TextFont *bmfont; + + bmfont = ami_font_bm_open(glob->rp, fstyle); + + // convert to local charset + *char_offset = TextFit(glob->rp, string, length, + &extent, NULL, 1, x, 32767); + + *actual_x = extent.te_Extent.MaxX; + + ami_font_bm_close(bmfont); + + return true; +} + + +/** + * Find where to split a string to make it fit a width. + * + * \param fstyle style for this text + * \param string UTF-8 string to measure + * \param length length of string + * \param x width available + * \param char_offset updated to offset in string of actual_x, [1..length] + * \param actual_x updated to x coordinate of character closest to x + * \return true on success, false on error and error reported + * + * On exit, char_offset indicates first character after split point. + * + * Note: char_offset of 0 should never be returned. + * + * Returns: + * char_offset giving split point closest to x, where actual_x <= x + * else + * char_offset giving split point closest to x, where actual_x > x + * + * Returning char_offset == length means no split possible + */ + +bool amiga_bm_nsfont_split(const plot_font_style_t *fstyle, + const char *string, size_t length, + int x, size_t *char_offset, int *actual_x) +{ + struct TextExtent extent; + ULONG co; + char *charp; + struct TextFont *bmfont = ami_font_bm_open(glob->rp, fstyle); + + co = TextFit(glob->rp, string, length, + &extent, NULL, 1, x, 32767); + + charp = string + co; + + while(((*charp != ' ')) && (charp > string)) { + charp--; + co--; + } + + *char_offset = co; + if(string && co) { + *actual_x = TextLength(glob->rp, string, co); + } else { + *actual_x = 0; + } + + ami_font_bm_close(bmfont); + + return true; +} + +ULONG ami_font_bm_text(struct RastPort *rp, const char *string, ULONG length, + const plot_font_style_t *fstyle, ULONG dx, ULONG dy) +{ + struct TextFont *bmfont = ami_font_bm_open(rp, fstyle); + char *localtext = NULL; + if(bmfont == NULL) return 0; + if(utf8_to_local_encoding(string, length, &localtext) == NSERROR_OK) { + Move(rp, dx, dy); + Text(rp, localtext, length); + free(localtext); + } + + return 0; +} + -- cgit v1.2.3 From 5d43025adfa9eb6317515fcce80ee410f30558ee Mon Sep 17 00:00:00 2001 From: Chris Young Date: Sun, 22 Feb 2015 16:50:41 +0000 Subject: Mostly working bitmap font support --- amiga/font.c | 5 +++++ amiga/font_bitmap.c | 20 ++++++++++++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/amiga/font.c b/amiga/font.c index 80e34bd10..5e4c9fc63 100644 --- a/amiga/font.c +++ b/amiga/font.c @@ -891,6 +891,11 @@ void ami_font_setdevicedpi(int id) ULONG ydpi = nsoption_int(screen_ydpi); ULONG xdpi = nsoption_int(screen_ydpi); + if(nsoption_bool(use_diskfont) == true) { + LOG(("WARNING: Using diskfont.library for text. Forcing DPI to 72.")); + nsoption_int(screen_ydpi) = 72; + } + browser_set_dpi(nsoption_int(screen_ydpi)); if(id && (nsoption_int(monitor_aspect_x) != 0) && (nsoption_int(monitor_aspect_y) != 0)) diff --git a/amiga/font_bitmap.c b/amiga/font_bitmap.c index d620ea90c..2bf411209 100644 --- a/amiga/font_bitmap.c +++ b/amiga/font_bitmap.c @@ -44,7 +44,7 @@ static struct TextFont *ami_font_bm_open(struct RastPort *rp, const plot_font_st { struct TextFont *bmfont = NULL; struct TextAttr tattr; - char *fontname, font; + char *fontname, *font; if(rp == NULL) return NULL; @@ -84,7 +84,7 @@ static struct TextFont *ami_font_bm_open(struct RastPort *rp, const plot_font_st if(font = ASPrintf("%s.font", fontname)) { tattr.ta_Name = font; tattr.ta_YSize = fstyle->size / FONT_SIZE_SCALE; - +LOG(("font: %s/%d", tattr.ta_Name, tattr.ta_YSize)); if(bmfont = OpenDiskFont(&tattr)) { SetRPAttrs(rp, RPTAG_Font, bmfont, TAG_DONE); } @@ -103,7 +103,14 @@ bool amiga_bm_nsfont_width(const plot_font_style_t *fstyle, const char *string, size_t length, int *width) { + *width = length; + + if((glob == NULL) || (glob->rp == NULL)) return false; + struct TextFont *bmfont = ami_font_bm_open(glob->rp, fstyle); + + if(bmfont == NULL) return false; + // convert to local charset *width = TextLength(glob->rp, string, length); ami_font_bm_close(bmfont); @@ -130,8 +137,12 @@ bool amiga_bm_nsfont_position_in_string(const plot_font_style_t *fstyle, struct TextExtent extent; struct TextFont *bmfont; + if((glob == NULL) || (glob->rp == NULL)) return false; + bmfont = ami_font_bm_open(glob->rp, fstyle); + if(bmfont == NULL) return false; + // convert to local charset *char_offset = TextFit(glob->rp, string, length, &extent, NULL, 1, x, 32767); @@ -174,8 +185,13 @@ bool amiga_bm_nsfont_split(const plot_font_style_t *fstyle, struct TextExtent extent; ULONG co; char *charp; + + if((glob == NULL) || (glob->rp == NULL)) return false; + struct TextFont *bmfont = ami_font_bm_open(glob->rp, fstyle); + if(bmfont == NULL) return false; + co = TextFit(glob->rp, string, length, &extent, NULL, 1, x, 32767); -- cgit v1.2.3 From 6fda772b892c18f100c066bd9207156716b43f32 Mon Sep 17 00:00:00 2001 From: Chris Young Date: Mon, 23 Feb 2015 18:44:47 +0000 Subject: Avoid clobbering the PPC pipeline --- amiga/font.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/amiga/font.c b/amiga/font.c index 5e4c9fc63..254f0567e 100644 --- a/amiga/font.c +++ b/amiga/font.c @@ -152,16 +152,16 @@ lwc_string *glypharray[0xffff + 1]; ULONG ami_devicedpi; ULONG ami_xdpi; -int32 ami_font_plot_glyph(struct OutlineFont *ofont, struct RastPort *rp, +static int32 ami_font_plot_glyph(struct OutlineFont *ofont, struct RastPort *rp, uint16 *char1, uint16 *char2, uint32 x, uint32 y, uint32 emwidth, bool aa); -int32 ami_font_width_glyph(struct OutlineFont *ofont, +static int32 ami_font_width_glyph(struct OutlineFont *ofont, const uint16 *char1, const uint16 *char2, uint32 emwidth); -struct OutlineFont *ami_open_outline_font(const plot_font_style_t *fstyle, +static struct OutlineFont *ami_open_outline_font(const plot_font_style_t *fstyle, const uint16 *codepoint); static void ami_font_cleanup(struct MinList *ami_font_list); -static bool amiga_nsfont_width(const plot_font_style_t *fstyle, +static inline bool amiga_nsfont_width(const plot_font_style_t *fstyle, const char *string, size_t length, int *width) { @@ -184,7 +184,7 @@ static bool amiga_nsfont_width(const plot_font_style_t *fstyle, * \return true on success, false on error and error reported */ -static bool amiga_nsfont_position_in_string(const plot_font_style_t *fstyle, +static inline bool amiga_nsfont_position_in_string(const plot_font_style_t *fstyle, const char *string, size_t length, int x, size_t *char_offset, int *actual_x) { @@ -271,7 +271,7 @@ static bool amiga_nsfont_position_in_string(const plot_font_style_t *fstyle, * Returning char_offset == length means no split possible */ -static bool amiga_nsfont_split(const plot_font_style_t *fstyle, +static inline bool amiga_nsfont_split(const plot_font_style_t *fstyle, const char *string, size_t length, int x, size_t *char_offset, int *actual_x) { @@ -410,7 +410,7 @@ static struct ami_font_node *ami_font_open(const char *font) * \param codepoint open a default font instead of the one specified by fstyle * \return outline font or NULL on error */ -struct OutlineFont *ami_open_outline_font(const plot_font_style_t *fstyle, +static struct OutlineFont *ami_open_outline_font(const plot_font_style_t *fstyle, const uint16 *codepoint) { struct ami_font_node *node; @@ -549,7 +549,7 @@ struct OutlineFont *ami_open_outline_font(const plot_font_style_t *fstyle, return NULL; } -int32 ami_font_plot_glyph(struct OutlineFont *ofont, struct RastPort *rp, +static int32 ami_font_plot_glyph(struct OutlineFont *ofont, struct RastPort *rp, uint16 *char1, uint16 *char2, uint32 x, uint32 y, uint32 emwidth, bool aa) { struct GlyphMap *glyph; @@ -640,7 +640,7 @@ int32 ami_font_plot_glyph(struct OutlineFont *ofont, struct RastPort *rp, return char_advance; } -int32 ami_font_width_glyph(struct OutlineFont *ofont, +static int32 ami_font_width_glyph(struct OutlineFont *ofont, const uint16 *char1, const uint16 *char2, uint32 emwidth) { int32 char_advance = 0; @@ -947,7 +947,7 @@ static bool nsfont_width(const plot_font_style_t *fstyle, const char *string, size_t length, int *width) { - if(nsoption_bool(use_diskfont) == false) { + if(__builtin_expect(nsoption_bool(use_diskfont) == false, 1)) { return amiga_nsfont_width(fstyle, string, length, width); } else { return amiga_bm_nsfont_width(fstyle, string, length, width); @@ -958,7 +958,7 @@ static bool nsfont_position_in_string(const plot_font_style_t *fstyle, const char *string, size_t length, int x, size_t *char_offset, int *actual_x) { - if(nsoption_bool(use_diskfont) == false) { + if(__builtin_expect(nsoption_bool(use_diskfont) == false, 1)) { return amiga_nsfont_position_in_string(fstyle, string, length, x, char_offset, actual_x); } else { @@ -971,7 +971,7 @@ static bool nsfont_split(const plot_font_style_t *fstyle, const char *string, size_t length, int x, size_t *char_offset, int *actual_x) { - if(nsoption_bool(use_diskfont) == false) { + if(__builtin_expect(nsoption_bool(use_diskfont) == false, 1)) { return amiga_nsfont_split(fstyle, string, length, x, char_offset, actual_x); } else { return amiga_bm_nsfont_split(fstyle, string, length, x, char_offset, actual_x); -- cgit v1.2.3 From 85df94f47a32ecea89e6905fb43af69a0a392fc6 Mon Sep 17 00:00:00 2001 From: Chris Young Date: Mon, 23 Feb 2015 18:47:58 +0000 Subject: more microoptimisation --- amiga/font.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/amiga/font.c b/amiga/font.c index 254f0567e..f930f77d6 100644 --- a/amiga/font.c +++ b/amiga/font.c @@ -734,7 +734,7 @@ ULONG ami_unicode_text(struct RastPort *rp, const char *string, ULONG length, if(!string || string[0]=='\0') return 0; if(!length) return 0; - if(nsoption_bool(use_diskfont) == true) { + if(__builtin_expect(nsoption_bool(use_diskfont) == true, 0)) { return ami_font_bm_text(rp, string, length, fstyle, dx, dy); } -- cgit v1.2.3 From 805c1a2dca04cee55cfb73ae99ae86f32c5733ca Mon Sep 17 00:00:00 2001 From: Chris Young Date: Mon, 23 Feb 2015 22:58:57 +0000 Subject: Convert hook function definitions to macros in gui.c --- amiga/gui.c | 21 ++++++--------------- amiga/gui.h | 6 ++++++ 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/amiga/gui.c b/amiga/gui.c index 753f6901f..184c5b01a 100644 --- a/amiga/gui.c +++ b/amiga/gui.c @@ -204,10 +204,8 @@ void ami_get_vscroll_pos(struct gui_window_2 *gwin, ULONG *ys); void ami_quit_netsurf_delayed(void); Object *ami_gui_splash_open(void); void ami_gui_splash_close(Object *win_obj); -static uint32 ami_set_favicon_render_hook(struct Hook *hook, APTR space, - struct gpRender *msg); -static uint32 ami_set_throbber_render_hook(struct Hook *hook, APTR space, - struct gpRender *msg); +HOOKF(uint32, ami_set_favicon_render_hook, APTR, space, struct gpRender *); +HOOKF(uint32, ami_set_throbber_render_hook, APTR, space, struct gpRender *); bool ami_gui_map_filename(char **remapped, const char *path, const char *file, const char *map); static void ami_gui_window_update_box_deferred(struct gui_window *g, bool draw); @@ -687,7 +685,7 @@ static nsurl *gui_get_resource_url(const char *path) return url; } -static void ami_gui_newprefs_hook(struct Hook *hook, APTR window, APTR reserved) +HOOKF(void, ami_gui_newprefs_hook, APTR, window, APTR) { ami_set_screen_defaults(scrn); } @@ -3644,11 +3642,7 @@ static void ami_refresh_window(struct gui_window_2 *gwin) ami_reset_pointer(gwin); } -#ifdef __amigaos4__ -static void ami_scroller_hook(struct Hook *hook,Object *object,struct IntuiMessage *msg) -#else -static ASM void ami_scroller_hook(REG(a0, struct Hook *hook),REG(a2, Object *object), REG(a1, struct IntuiMessage *msg)) -#endif +HOOKF(void, ami_scroller_hook, Object *, object, struct IntuiMessage *) { ULONG gid; struct gui_window_2 *gwin = hook->h_Data; @@ -4996,9 +4990,7 @@ static nserror gui_window_set_url(struct gui_window *g, nsurl *url) return NSERROR_OK; } - -static uint32 ami_set_favicon_render_hook(struct Hook *hook, APTR space, - struct gpRender *msg) +HOOKF(uint32, ami_set_favicon_render_hook, APTR, space, struct gpRender *) { ami_schedule(0, ami_gui_refresh_favicon, hook->h_Data); return 0; @@ -5066,8 +5058,7 @@ static nserror gui_search_web_provider_update(const char *provider_name, return NSERROR_OK; } -static uint32 ami_set_throbber_render_hook(struct Hook *hook, APTR space, - struct gpRender *msg) +HOOKF(uint32, ami_set_throbber_render_hook, APTR, space, struct gpRender *) { struct gui_window_2 *gwin = hook->h_Data; ami_throbber_redraw_schedule(0, gwin->gw); diff --git a/amiga/gui.h b/amiga/gui.h index 246d75124..4d8344be6 100755 --- a/amiga/gui.h +++ b/amiga/gui.h @@ -28,6 +28,12 @@ #include "amiga/plotters.h" #include "amiga/menu.h" +#ifdef __amigaos4__ +#define HOOKF(ret,func,type,ptr,msgtype) static ret func(struct Hook *hook, type ptr, msgtype msg) +#else +#define HOOKF(ret,func,type,ptr) static ASM ret func(REG(a0, struct Hook *hook),REG(a2, type ptr), REG(a1, msgtype msg)) +#endif + enum { OID_MAIN = 0, -- cgit v1.2.3 From 28a6a63b4f5c3e2a50561199305976db1dcb81fa Mon Sep 17 00:00:00 2001 From: Chris Young Date: Mon, 23 Feb 2015 23:00:16 +0000 Subject: fix warnings --- amiga/font_bitmap.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/amiga/font_bitmap.c b/amiga/font_bitmap.c index 2bf411209..0b5b7ce85 100644 --- a/amiga/font_bitmap.c +++ b/amiga/font_bitmap.c @@ -81,11 +81,11 @@ static struct TextFont *ami_font_bm_open(struct RastPort *rp, const plot_font_st if (fstyle->weight >= 700) tattr.ta_Style |= FSF_BOLD; - if(font = ASPrintf("%s.font", fontname)) { + if((font = ASPrintf("%s.font", fontname))) { tattr.ta_Name = font; tattr.ta_YSize = fstyle->size / FONT_SIZE_SCALE; -LOG(("font: %s/%d", tattr.ta_Name, tattr.ta_YSize)); - if(bmfont = OpenDiskFont(&tattr)) { + LOG(("font: %s/%d", tattr.ta_Name, tattr.ta_YSize)); + if((bmfont = OpenDiskFont(&tattr))) { SetRPAttrs(rp, RPTAG_Font, bmfont, TAG_DONE); } FreeVec(font); -- cgit v1.2.3 From ce060f3c133eb4e36ab0fa5777c779df74c18f34 Mon Sep 17 00:00:00 2001 From: Chris Young Date: Mon, 23 Feb 2015 23:07:52 +0000 Subject: Convert menu.c to use macros for hook functions --- amiga/menu.c | 70 ++++++++++++++++++++++++++++++------------------------------ 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/amiga/menu.c b/amiga/menu.c index aa8203740..e898c1554 100644 --- a/amiga/menu.c +++ b/amiga/menu.c @@ -786,7 +786,7 @@ void ami_menu_update_disabled(struct gui_window *g, hlcache_handle *c) * The below functions are called automatically by window.class when menu items are selected. */ -static void ami_menu_item_project_newwin(struct Hook *hook, APTR window, struct IntuiMessage *msg) +HOOKF(void, ami_menu_item_project_newwin, APTR, window, struct IntuiMessage *) { nsurl *url; nserror error; @@ -805,7 +805,7 @@ static void ami_menu_item_project_newwin(struct Hook *hook, APTR window, struct } } -static void ami_menu_item_project_newtab(struct Hook *hook, APTR window, struct IntuiMessage *msg) +HOOKF(void, ami_menu_item_project_newtab, APTR, window, struct IntuiMessage *) { struct gui_window_2 *gwin; nserror error; @@ -814,7 +814,7 @@ static void ami_menu_item_project_newtab(struct Hook *hook, APTR window, struct error = ami_gui_new_blank_tab(gwin); } -static void ami_menu_item_project_open(struct Hook *hook, APTR window, struct IntuiMessage *msg) +HOOKF(void, ami_menu_item_project_open, APTR, window, struct IntuiMessage *) { struct gui_window_2 *gwin; GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); @@ -822,7 +822,7 @@ static void ami_menu_item_project_open(struct Hook *hook, APTR window, struct In ami_file_open(gwin); } -static void ami_menu_item_project_save(struct Hook *hook, APTR window, struct IntuiMessage *msg) +HOOKF(void, ami_menu_item_project_save, APTR, window, struct IntuiMessage *) { struct gui_window_2 *gwin; ULONG type = (ULONG)hook->h_Data; @@ -832,7 +832,7 @@ static void ami_menu_item_project_save(struct Hook *hook, APTR window, struct In ami_file_save_req(type, gwin, browser_window_get_content(gwin->gw->bw)); } -static void ami_menu_item_project_closetab(struct Hook *hook, APTR window, struct IntuiMessage *msg) +HOOKF(void, ami_menu_item_project_closetab, APTR, window, struct IntuiMessage *) { struct gui_window_2 *gwin; GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); @@ -840,7 +840,7 @@ static void ami_menu_item_project_closetab(struct Hook *hook, APTR window, struc browser_window_destroy(gwin->gw->bw); } -static void ami_menu_item_project_closewin(struct Hook *hook, APTR window, struct IntuiMessage *msg) +HOOKF(void, ami_menu_item_project_closewin, APTR, window, struct IntuiMessage *) { struct gui_window_2 *gwin; GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); @@ -848,7 +848,7 @@ static void ami_menu_item_project_closewin(struct Hook *hook, APTR window, struc ami_menu_window_close = gwin; } -static void ami_menu_item_project_print(struct Hook *hook, APTR window, struct IntuiMessage *msg) +HOOKF(void, ami_menu_item_project_print, APTR, window, struct IntuiMessage *) { struct gui_window_2 *gwin; GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); @@ -858,7 +858,7 @@ static void ami_menu_item_project_print(struct Hook *hook, APTR window, struct I ami_reset_pointer(gwin); } -static void ami_menu_item_project_about(struct Hook *hook, APTR window, struct IntuiMessage *msg) +HOOKF(void, ami_menu_item_project_about, APTR, window, struct IntuiMessage *) { struct gui_window_2 *gwin; char *temp, *temp2; @@ -916,12 +916,12 @@ static void ami_menu_item_project_about(struct Hook *hook, APTR window, struct I ami_reset_pointer(gwin); } -static void ami_menu_item_project_quit(struct Hook *hook, APTR window, struct IntuiMessage *msg) +HOOKF(void, ami_menu_item_project_quit, APTR, window, struct IntuiMessage *) { ami_menu_window_close = AMI_MENU_WINDOW_CLOSE_ALL; } -static void ami_menu_item_edit_cut(struct Hook *hook, APTR window, struct IntuiMessage *msg) +HOOKF(void, ami_menu_item_edit_cut, APTR, window, struct IntuiMessage *) { struct gui_window_2 *gwin; GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); @@ -929,7 +929,7 @@ static void ami_menu_item_edit_cut(struct Hook *hook, APTR window, struct IntuiM browser_window_key_press(gwin->gw->bw, KEY_CUT_SELECTION); } -static void ami_menu_item_edit_copy(struct Hook *hook, APTR window, struct IntuiMessage *msg) +HOOKF(void, ami_menu_item_edit_copy, APTR, window, struct IntuiMessage *) { struct bitmap *bm; struct gui_window_2 *gwin; @@ -955,7 +955,7 @@ static void ami_menu_item_edit_copy(struct Hook *hook, APTR window, struct Intui #endif } -static void ami_menu_item_edit_paste(struct Hook *hook, APTR window, struct IntuiMessage *msg) +HOOKF(void, ami_menu_item_edit_paste, APTR, window, struct IntuiMessage *) { struct gui_window_2 *gwin; GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); @@ -963,7 +963,7 @@ static void ami_menu_item_edit_paste(struct Hook *hook, APTR window, struct Intu browser_window_key_press(gwin->gw->bw, KEY_PASTE); } -static void ami_menu_item_edit_selectall(struct Hook *hook, APTR window, struct IntuiMessage *msg) +HOOKF(void, ami_menu_item_edit_selectall, APTR, window, struct IntuiMessage *) { struct gui_window_2 *gwin; GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); @@ -972,7 +972,7 @@ static void ami_menu_item_edit_selectall(struct Hook *hook, APTR window, struct gui_start_selection(gwin->gw); } -static void ami_menu_item_edit_clearsel(struct Hook *hook, APTR window, struct IntuiMessage *msg) +HOOKF(void, ami_menu_item_edit_clearsel, APTR, window, struct IntuiMessage *) { struct gui_window_2 *gwin; GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); @@ -980,7 +980,7 @@ static void ami_menu_item_edit_clearsel(struct Hook *hook, APTR window, struct I browser_window_key_press(gwin->gw->bw, KEY_CLEAR_SELECTION); } -static void ami_menu_item_edit_undo(struct Hook *hook, APTR window, struct IntuiMessage *msg) +HOOKF(void, ami_menu_item_edit_undo, APTR, window, struct IntuiMessage *) { struct gui_window_2 *gwin; GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); @@ -988,7 +988,7 @@ static void ami_menu_item_edit_undo(struct Hook *hook, APTR window, struct Intui browser_window_key_press(gwin->gw->bw, KEY_UNDO); } -static void ami_menu_item_edit_redo(struct Hook *hook, APTR window, struct IntuiMessage *msg) +HOOKF(void, ami_menu_item_edit_redo, APTR, window, struct IntuiMessage *) { struct gui_window_2 *gwin; GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); @@ -996,7 +996,7 @@ static void ami_menu_item_edit_redo(struct Hook *hook, APTR window, struct Intui browser_window_key_press(gwin->gw->bw, KEY_REDO); } -static void ami_menu_item_browser_find(struct Hook *hook, APTR window, struct IntuiMessage *msg) +HOOKF(void, ami_menu_item_browser_find, APTR, window, struct IntuiMessage *) { struct gui_window_2 *gwin; GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); @@ -1004,7 +1004,7 @@ static void ami_menu_item_browser_find(struct Hook *hook, APTR window, struct In ami_search_open(gwin->gw); } -static void ami_menu_item_browser_localhistory(struct Hook *hook, APTR window, struct IntuiMessage *msg) +HOOKF(void, ami_menu_item_browser_localhistory, APTR, window, struct IntuiMessage *) { struct gui_window_2 *gwin; GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); @@ -1012,17 +1012,17 @@ static void ami_menu_item_browser_localhistory(struct Hook *hook, APTR window, s ami_history_open(gwin->gw); } -static void ami_menu_item_browser_globalhistory(struct Hook *hook, APTR window, struct IntuiMessage *msg) +HOOKF(void, ami_menu_item_browser_globalhistory, APTR, window, struct IntuiMessage *) { ami_tree_open(global_history_window,AMI_TREE_HISTORY); } -static void ami_menu_item_browser_cookies(struct Hook *hook, APTR window, struct IntuiMessage *msg) +HOOKF(void, ami_menu_item_browser_cookies, APTR, window, struct IntuiMessage *) { ami_tree_open(cookies_window,AMI_TREE_COOKIES); } -static void ami_menu_item_browser_foreimg(struct Hook *hook, APTR window, struct IntuiMessage *msg) +HOOKF(void, ami_menu_item_browser_foreimg, APTR, window, struct IntuiMessage *) { struct Menu *menustrip; bool checked = false; @@ -1034,7 +1034,7 @@ static void ami_menu_item_browser_foreimg(struct Hook *hook, APTR window, struct ami_menu_check_toggled = true; } -static void ami_menu_item_browser_backimg(struct Hook *hook, APTR window, struct IntuiMessage *msg) +HOOKF(void, ami_menu_item_browser_backimg, APTR, window, struct IntuiMessage *) { struct Menu *menustrip; bool checked = false; @@ -1046,7 +1046,7 @@ static void ami_menu_item_browser_backimg(struct Hook *hook, APTR window, struct ami_menu_check_toggled = true; } -static void ami_menu_item_browser_enablejs(struct Hook *hook, APTR window, struct IntuiMessage *msg) +HOOKF(void, ami_menu_item_browser_enablejs, APTR, window, struct IntuiMessage *) { struct Menu *menustrip; bool checked = false; @@ -1058,7 +1058,7 @@ static void ami_menu_item_browser_enablejs(struct Hook *hook, APTR window, struc ami_menu_check_toggled = true; } -static void ami_menu_item_browser_scale_decrease(struct Hook *hook, APTR window, struct IntuiMessage *msg) +HOOKF(void, ami_menu_item_browser_scale_decrease, APTR, window, struct IntuiMessage *) { struct gui_window_2 *gwin; GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); @@ -1067,7 +1067,7 @@ static void ami_menu_item_browser_scale_decrease(struct Hook *hook, APTR window, ami_gui_set_scale(gwin->gw, gwin->gw->scale - 0.1); } -static void ami_menu_item_browser_scale_normal(struct Hook *hook, APTR window, struct IntuiMessage *msg) +HOOKF(void, ami_menu_item_browser_scale_normal, APTR, window, struct IntuiMessage *) { struct gui_window_2 *gwin; GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); @@ -1075,7 +1075,7 @@ static void ami_menu_item_browser_scale_normal(struct Hook *hook, APTR window, s ami_gui_set_scale(gwin->gw, 1.0); } -static void ami_menu_item_browser_scale_increase(struct Hook *hook, APTR window, struct IntuiMessage *msg) +HOOKF(void, ami_menu_item_browser_scale_increase, APTR, window, struct IntuiMessage *) { struct gui_window_2 *gwin; GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); @@ -1083,7 +1083,7 @@ static void ami_menu_item_browser_scale_increase(struct Hook *hook, APTR window, ami_gui_set_scale(gwin->gw, gwin->gw->scale + 0.1); } -static void ami_menu_item_browser_redraw(struct Hook *hook, APTR window, struct IntuiMessage *msg) +HOOKF(void, ami_menu_item_browser_redraw, APTR, window, struct IntuiMessage *) { struct gui_window_2 *gwin; GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); @@ -1092,7 +1092,7 @@ static void ami_menu_item_browser_redraw(struct Hook *hook, APTR window, struct gwin->new_content = true; } -static void ami_menu_item_hotlist_add(struct Hook *hook, APTR window, struct IntuiMessage *msg) +HOOKF(void, ami_menu_item_hotlist_add, APTR, window, struct IntuiMessage *) { struct browser_window *bw; struct gui_window_2 *gwin; @@ -1107,12 +1107,12 @@ static void ami_menu_item_hotlist_add(struct Hook *hook, APTR window, struct Int ami_gui_update_hotlist_button(gwin); } -static void ami_menu_item_hotlist_show(struct Hook *hook, APTR window, struct IntuiMessage *msg) +HOOKF(void, ami_menu_item_hotlist_show, APTR, window, struct IntuiMessage *) { ami_tree_open(hotlist_window, AMI_TREE_HOTLIST); } -static void ami_menu_item_hotlist_entries(struct Hook *hook, APTR window, struct IntuiMessage *msg) +HOOKF(void, ami_menu_item_hotlist_entries, APTR, window, struct IntuiMessage *) { nsurl *url = hook->h_Data; struct gui_window_2 *gwin; @@ -1129,12 +1129,12 @@ static void ami_menu_item_hotlist_entries(struct Hook *hook, APTR window, struct NULL); } -static void ami_menu_item_settings_edit(struct Hook *hook, APTR window, struct IntuiMessage *msg) +HOOKF(void, ami_menu_item_settings_edit, APTR, window, struct IntuiMessage *) { ami_gui_opts_open(); } -static void ami_menu_item_settings_snapshot(struct Hook *hook, APTR window, struct IntuiMessage *msg) +HOOKF(void, ami_menu_item_settings_snapshot, APTR, window, struct IntuiMessage *) { struct gui_window_2 *gwin; GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); @@ -1145,12 +1145,12 @@ static void ami_menu_item_settings_snapshot(struct Hook *hook, APTR window, stru nsoption_set_int(window_height, gwin->win->Height); } -static void ami_menu_item_settings_save(struct Hook *hook, APTR window, struct IntuiMessage *msg) +HOOKF(void, ami_menu_item_settings_save, APTR, window, struct IntuiMessage *) { nsoption_write(current_user_options, NULL, NULL); } -static void ami_menu_item_arexx_execute(struct Hook *hook, APTR window, struct IntuiMessage *msg) +HOOKF(void, ami_menu_item_arexx_execute, APTR, window, struct IntuiMessage *) { char *temp; struct gui_window_2 *gwin; @@ -1174,7 +1174,7 @@ static void ami_menu_item_arexx_execute(struct Hook *hook, APTR window, struct I } } -static void ami_menu_item_arexx_entries(struct Hook *hook, APTR window, struct IntuiMessage *msg) +HOOKF(void, ami_menu_item_arexx_entries, APTR, window, struct IntuiMessage *) { char *script = hook->h_Data; char *temp; -- cgit v1.2.3 From 68c6ba3a708c98ab8ab77e1d30f9d9f0e632acd3 Mon Sep 17 00:00:00 2001 From: Chris Young Date: Mon, 23 Feb 2015 23:16:34 +0000 Subject: fix OS3 build, avoid forward declarations --- amiga/gui.h | 2 +- amiga/menu.c | 1725 ++++++++++++++++++++++++++++------------------------------ 2 files changed, 846 insertions(+), 881 deletions(-) diff --git a/amiga/gui.h b/amiga/gui.h index 4d8344be6..adad63d4f 100755 --- a/amiga/gui.h +++ b/amiga/gui.h @@ -31,7 +31,7 @@ #ifdef __amigaos4__ #define HOOKF(ret,func,type,ptr,msgtype) static ret func(struct Hook *hook, type ptr, msgtype msg) #else -#define HOOKF(ret,func,type,ptr) static ASM ret func(REG(a0, struct Hook *hook),REG(a2, type ptr), REG(a1, msgtype msg)) +#define HOOKF(ret,func,type,ptr,msgtype) static ASM ret func(REG(a0, struct Hook *hook),REG(a2, type ptr), REG(a1, msgtype msg)) #endif enum diff --git a/amiga/menu.c b/amiga/menu.c index e898c1554..fbb6af336 100644 --- a/amiga/menu.c +++ b/amiga/menu.c @@ -96,1101 +96,1066 @@ bool menu_glyphs_loaded = false; static nserror ami_menu_scan(struct tree *tree, struct gui_window_2 *gwin); void ami_menu_arexx_scan(struct gui_window_2 *gwin); -/* Functions for menu selections */ -static void ami_menu_item_project_newwin(struct Hook *hook, APTR window, struct IntuiMessage *msg); -static void ami_menu_item_project_newtab(struct Hook *hook, APTR window, struct IntuiMessage *msg); -static void ami_menu_item_project_open(struct Hook *hook, APTR window, struct IntuiMessage *msg); -static void ami_menu_item_project_save(struct Hook *hook, APTR window, struct IntuiMessage *msg); -static void ami_menu_item_project_closetab(struct Hook *hook, APTR window, struct IntuiMessage *msg); -static void ami_menu_item_project_closewin(struct Hook *hook, APTR window, struct IntuiMessage *msg); -static void ami_menu_item_project_print(struct Hook *hook, APTR window, struct IntuiMessage *msg); -static void ami_menu_item_project_about(struct Hook *hook, APTR window, struct IntuiMessage *msg); -static void ami_menu_item_project_quit(struct Hook *hook, APTR window, struct IntuiMessage *msg); -static void ami_menu_item_edit_cut(struct Hook *hook, APTR window, struct IntuiMessage *msg); -static void ami_menu_item_edit_copy(struct Hook *hook, APTR window, struct IntuiMessage *msg); -static void ami_menu_item_edit_paste(struct Hook *hook, APTR window, struct IntuiMessage *msg); -static void ami_menu_item_edit_selectall(struct Hook *hook, APTR window, struct IntuiMessage *msg); -static void ami_menu_item_edit_clearsel(struct Hook *hook, APTR window, struct IntuiMessage *msg); -static void ami_menu_item_edit_undo(struct Hook *hook, APTR window, struct IntuiMessage *msg); -static void ami_menu_item_edit_redo(struct Hook *hook, APTR window, struct IntuiMessage *msg); -static void ami_menu_item_browser_find(struct Hook *hook, APTR window, struct IntuiMessage *msg); -static void ami_menu_item_browser_localhistory(struct Hook *hook, APTR window, struct IntuiMessage *msg); -static void ami_menu_item_browser_globalhistory(struct Hook *hook, APTR window, struct IntuiMessage *msg); -static void ami_menu_item_browser_cookies(struct Hook *hook, APTR window, struct IntuiMessage *msg); -static void ami_menu_item_browser_foreimg(struct Hook *hook, APTR window, struct IntuiMessage *msg); -static void ami_menu_item_browser_backimg(struct Hook *hook, APTR window, struct IntuiMessage *msg); -static void ami_menu_item_browser_enablejs(struct Hook *hook, APTR window, struct IntuiMessage *msg); -static void ami_menu_item_browser_scale_decrease(struct Hook *hook, APTR window, struct IntuiMessage *msg); -static void ami_menu_item_browser_scale_normal(struct Hook *hook, APTR window, struct IntuiMessage *msg); -static void ami_menu_item_browser_scale_increase(struct Hook *hook, APTR window, struct IntuiMessage *msg); -static void ami_menu_item_browser_redraw(struct Hook *hook, APTR window, struct IntuiMessage *msg); -static void ami_menu_item_hotlist_add(struct Hook *hook, APTR window, struct IntuiMessage *msg); -static void ami_menu_item_hotlist_show(struct Hook *hook, APTR window, struct IntuiMessage *msg); -static void ami_menu_item_hotlist_entries(struct Hook *hook, APTR window, struct IntuiMessage *msg); -static void ami_menu_item_settings_edit(struct Hook *hook, APTR window, struct IntuiMessage *msg); -static void ami_menu_item_settings_snapshot(struct Hook *hook, APTR window, struct IntuiMessage *msg); -static void ami_menu_item_settings_save(struct Hook *hook, APTR window, struct IntuiMessage *msg); -static void ami_menu_item_arexx_execute(struct Hook *hook, APTR window, struct IntuiMessage *msg); -static void ami_menu_item_arexx_entries(struct Hook *hook, APTR window, struct IntuiMessage *msg); - +/* + * The below functions are called automatically by window.class when menu items are selected. + */ -void ami_free_menulabs(struct gui_window_2 *gwin) +HOOKF(void, ami_menu_item_project_newwin, APTR, window, struct IntuiMessage *) { - int i; - - for(i=0;i<=AMI_MENU_AREXX_MAX;i++) - { - if(gwin->menulab[i] && (gwin->menulab[i] != NM_BARLABEL)) - { - if(gwin->menutype[i] & MENU_IMAGE) - { - DisposeObject(gwin->menuobj[i]); - } - - ami_utf8_free(gwin->menulab[i]); - - if(i >= AMI_MENU_AREXX) - { - if(gwin->menu_hook[i].h_Data) free(gwin->menu_hook[i].h_Data); - } - } + nsurl *url; + nserror error; - gwin->menulab[i] = NULL; - gwin->menuobj[i] = NULL; - gwin->menukey[i] = 0; + error = nsurl_create(nsoption_charp(homepage_url), &url); + if (error == NSERROR_OK) { + error = browser_window_create(BW_CREATE_HISTORY, + url, + NULL, + NULL, + NULL); + nsurl_unref(url); + } + if (error != NSERROR_OK) { + warn_user(messages_get_errorcode(error), 0); } - - FreeVec(gwin->menutype); - FreeVec(gwin->menu); - - gwin->menutype = NULL; - gwin->menu = NULL; } -static void ami_menu_alloc_item(struct gui_window_2 *gwin, int num, UBYTE type, - const char *label, char key, char *icon, void *func, void *hookdata) +HOOKF(void, ami_menu_item_project_newtab, APTR, window, struct IntuiMessage *) { - char menu_icon[1024]; + struct gui_window_2 *gwin; + nserror error; - gwin->menutype[num] = type; + GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); + error = ami_gui_new_blank_tab(gwin); +} - if((label == NM_BARLABEL) || (strcmp(label, "--") == 0)) { - gwin->menulab[num] = NM_BARLABEL; - } else { - if((num >= AMI_MENU_HOTLIST) && (num <= AMI_MENU_HOTLIST_MAX)) { - gwin->menulab[num] = ami_utf8_easy(label); - } else if((num >= AMI_MENU_AREXX) && (num <= AMI_MENU_AREXX_MAX)) { - gwin->menulab[num] = strdup(label); - } else { - gwin->menulab[num] = ami_utf8_easy(messages_get(label)); - } - } - - gwin->menuicon[num] = NULL; - if(key) gwin->menukey[num] = key; - if(func) gwin->menu_hook[num].h_Entry = (HOOKFUNC)func; - if(hookdata) gwin->menu_hook[num].h_Data = hookdata; +HOOKF(void, ami_menu_item_project_open, APTR, window, struct IntuiMessage *) +{ + struct gui_window_2 *gwin; + GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); - if(icon) { - if(ami_locate_resource(menu_icon, icon) == true) - gwin->menuicon[num] = (char *)strdup(menu_icon); - } + ami_file_open(gwin); } -static void ami_init_menulabs(struct gui_window_2 *gwin) +HOOKF(void, ami_menu_item_project_save, APTR, window, struct IntuiMessage *) { - int i; + struct gui_window_2 *gwin; + ULONG type = (ULONG)hook->h_Data; - gwin->menutype = ami_misc_allocvec_clear(AMI_MENU_AREXX_MAX + 1, 0); + GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); - for(i=0;i <= AMI_MENU_AREXX_MAX;i++) - { - gwin->menutype[i] = NM_IGNORE; - gwin->menulab[i] = NULL; - gwin->menuobj[i] = NULL; - } + ami_file_save_req(type, gwin, browser_window_get_content(gwin->gw->bw)); +} - ami_menu_alloc_item(gwin, M_PROJECT, NM_TITLE, "Project", 0, NULL, NULL, NULL); - ami_menu_alloc_item(gwin, M_NEWWIN, NM_ITEM, "NewWindowNS", 'N', NULL, - ami_menu_item_project_newwin, NULL); - ami_menu_alloc_item(gwin, M_NEWTAB, NM_ITEM, "NewTab", 'T', NULL, - ami_menu_item_project_newtab, NULL); - ami_menu_alloc_item(gwin, M_BAR_P1, NM_ITEM, NM_BARLABEL, 0, NULL, NULL, NULL); - ami_menu_alloc_item(gwin, M_OPEN, NM_ITEM, "OpenFile", 'O', NULL, - ami_menu_item_project_open, NULL); - ami_menu_alloc_item(gwin, M_SAVEAS, NM_ITEM, "SaveAsNS", 0, NULL, NULL, NULL); - ami_menu_alloc_item(gwin, M_SAVESRC, NM_SUB, "Source", 'S', NULL, - ami_menu_item_project_save, (void *)AMINS_SAVE_SOURCE); - ami_menu_alloc_item(gwin, M_SAVETXT, NM_SUB, "TextNS", 0, NULL, - ami_menu_item_project_save, (void *)AMINS_SAVE_TEXT); - ami_menu_alloc_item(gwin, M_SAVECOMP, NM_SUB, "SaveCompNS", 0, NULL, - ami_menu_item_project_save, (void *)AMINS_SAVE_COMPLETE); -#ifdef WITH_PDF_EXPORT - ami_menu_alloc_item(gwin, M_SAVEPDF, NM_SUB, "PDFNS", 0, NULL, - ami_menu_item_project_save, (void *)AMINS_SAVE_PDF); -#endif - ami_menu_alloc_item(gwin, M_SAVEIFF, NM_SUB, "IFF", 0, NULL, - ami_menu_item_project_save, (void *)AMINS_SAVE_IFF); - ami_menu_alloc_item(gwin, M_BAR_P2, NM_ITEM, NM_BARLABEL, 0, NULL, NULL, NULL); - ami_menu_alloc_item(gwin, M_PRINT, NM_ITEM, "PrintNS", 'P', NULL, - ami_menu_item_project_print, NULL); - ami_menu_alloc_item(gwin, M_BAR_P3, NM_ITEM, NM_BARLABEL, 0, NULL, NULL, NULL); - ami_menu_alloc_item(gwin, M_CLOSETAB, NM_ITEM, "CloseTab", 'K', NULL, - ami_menu_item_project_closetab, NULL); - ami_menu_alloc_item(gwin, M_CLOSEWIN, NM_ITEM, "CloseWindow", 0, NULL, - ami_menu_item_project_closewin, NULL); - ami_menu_alloc_item(gwin, M_BAR_P4, NM_ITEM, NM_BARLABEL, 0, NULL, NULL, NULL); - ami_menu_alloc_item(gwin, M_ABOUT, NM_ITEM, "About", '?', NULL, - ami_menu_item_project_about, NULL); - ami_menu_alloc_item(gwin, M_BAR_P5, NM_ITEM, NM_BARLABEL, 0, NULL, NULL, NULL); - ami_menu_alloc_item(gwin, M_QUIT, NM_ITEM, "Quit", 'Q', NULL, - ami_menu_item_project_quit, NULL); +HOOKF(void, ami_menu_item_project_closetab, APTR, window, struct IntuiMessage *) +{ + struct gui_window_2 *gwin; + GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); - ami_menu_alloc_item(gwin, M_EDIT, NM_TITLE, "Edit", 0, NULL, NULL, NULL); - ami_menu_alloc_item(gwin, M_CUT, NM_ITEM, "CutNS", 'X', NULL, - ami_menu_item_edit_cut, NULL); - ami_menu_alloc_item(gwin, M_COPY, NM_ITEM, "CopyNS", 'C', NULL, - ami_menu_item_edit_copy, NULL); - ami_menu_alloc_item(gwin, M_PASTE, NM_ITEM, "PasteNS", 'V', NULL, - ami_menu_item_edit_paste, NULL); - ami_menu_alloc_item(gwin, M_BAR_E1, NM_ITEM, NM_BARLABEL, 0, NULL, NULL, NULL); - ami_menu_alloc_item(gwin, M_SELALL, NM_ITEM, "SelectAllNS", 'A', NULL, - ami_menu_item_edit_selectall, NULL); - ami_menu_alloc_item(gwin, M_CLEAR, NM_ITEM, "ClearNS", 0, NULL, - ami_menu_item_edit_clearsel, NULL); - ami_menu_alloc_item(gwin, M_BAR_E2, NM_ITEM, NM_BARLABEL, 0, NULL, NULL, NULL); - ami_menu_alloc_item(gwin, M_UNDO, NM_ITEM, "Undo", 'Z', NULL, - ami_menu_item_edit_undo, NULL); - ami_menu_alloc_item(gwin, M_REDO, NM_ITEM, "Redo", 'Y', NULL, - ami_menu_item_edit_redo, NULL); + browser_window_destroy(gwin->gw->bw); +} - ami_menu_alloc_item(gwin, M_BROWSER, NM_TITLE, "Browser", 0, NULL, NULL, NULL); - ami_menu_alloc_item(gwin, M_FIND, NM_ITEM, "FindTextNS", 'F', NULL, - ami_menu_item_browser_find, NULL); - ami_menu_alloc_item(gwin, M_BAR_B1, NM_ITEM, NM_BARLABEL, 0, NULL, NULL, NULL); - ami_menu_alloc_item(gwin, M_HISTLOCL, NM_ITEM, "HistLocalNS", 0, NULL, - ami_menu_item_browser_localhistory, NULL); - ami_menu_alloc_item(gwin, M_HISTGLBL, NM_ITEM, "HistGlobalNS", 0, NULL, - ami_menu_item_browser_globalhistory, NULL); - ami_menu_alloc_item(gwin, M_BAR_B2, NM_ITEM, NM_BARLABEL, 0, NULL, NULL, NULL); - ami_menu_alloc_item(gwin, M_COOKIES, NM_ITEM, "ShowCookiesNS", 0, NULL, - ami_menu_item_browser_cookies, NULL); - ami_menu_alloc_item(gwin, M_BAR_B3, NM_ITEM, NM_BARLABEL, 0, NULL, NULL, NULL); - ami_menu_alloc_item(gwin, M_SCALE, NM_ITEM, "ScaleNS", 0, NULL, NULL, NULL); - ami_menu_alloc_item(gwin, M_SCALEDEC, NM_SUB, "ScaleDec", '-', NULL, - ami_menu_item_browser_scale_decrease, NULL); - ami_menu_alloc_item(gwin, M_SCALENRM, NM_SUB, "ScaleNorm", '=', NULL, - ami_menu_item_browser_scale_normal, NULL); - ami_menu_alloc_item(gwin, M_SCALEDEC, NM_SUB, "ScaleDec", '-', NULL, - ami_menu_item_browser_scale_decrease, NULL); - ami_menu_alloc_item(gwin, M_SCALEINC, NM_SUB, "ScaleInc", '+', NULL, - ami_menu_item_browser_scale_increase, NULL); - ami_menu_alloc_item(gwin, M_IMAGES, NM_ITEM, "Images", 0, NULL, NULL, NULL); - ami_menu_alloc_item(gwin, M_IMGFORE, NM_SUB, "ForeImg", 0, NULL, - ami_menu_item_browser_foreimg, NULL); - ami_menu_alloc_item(gwin, M_IMGBACK, NM_SUB, "BackImg", 0, NULL, - ami_menu_item_browser_backimg, NULL); -#if defined(WITH_JS) || defined(WITH_MOZJS) - ami_menu_alloc_item(gwin, M_JS, NM_ITEM, "EnableJS", 0, NULL, - ami_menu_item_browser_enablejs, NULL); -#endif - ami_menu_alloc_item(gwin, M_BAR_B4, NM_ITEM, NM_BARLABEL, 0, NULL, NULL, NULL); - ami_menu_alloc_item(gwin, M_REDRAW, NM_ITEM, "Redraw", 0, NULL, - ami_menu_item_browser_redraw, NULL); +HOOKF(void, ami_menu_item_project_closewin, APTR, window, struct IntuiMessage *) +{ + struct gui_window_2 *gwin; + GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); - ami_menu_alloc_item(gwin, M_HOTLIST, NM_TITLE, "Hotlist", 0, NULL, NULL, NULL); - ami_menu_alloc_item(gwin, M_HLADD, NM_ITEM, "HotlistAdd", 'B', NULL, - ami_menu_item_hotlist_add, NULL); - ami_menu_alloc_item(gwin, M_HLSHOW, NM_ITEM,"HotlistShowNS",'H', NULL, - ami_menu_item_hotlist_show, NULL); - ami_menu_alloc_item(gwin, M_BAR_H1, NM_ITEM, NM_BARLABEL, 0, NULL, NULL, NULL); + ami_menu_window_close = gwin; +} - ami_menu_alloc_item(gwin, M_PREFS, NM_TITLE, "Settings", 0, NULL, NULL, NULL); - ami_menu_alloc_item(gwin, M_PREDIT, NM_ITEM, "SettingsEdit", 0, NULL, - ami_menu_item_settings_edit, NULL); - ami_menu_alloc_item(gwin, M_BAR_S1, NM_ITEM, NM_BARLABEL, 0, NULL, NULL, NULL); - ami_menu_alloc_item(gwin, M_SNAPSHOT, NM_ITEM, "SnapshotWindow",0, NULL, - ami_menu_item_settings_snapshot, NULL); - ami_menu_alloc_item(gwin, M_PRSAVE, NM_ITEM, "SettingsSave", 0, NULL, - ami_menu_item_settings_save, NULL); +HOOKF(void, ami_menu_item_project_print, APTR, window, struct IntuiMessage *) +{ + struct gui_window_2 *gwin; + GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); - ami_menu_alloc_item(gwin, M_AREXX, NM_TITLE, "ARexx", 0, NULL, NULL, NULL); - ami_menu_alloc_item(gwin, M_AREXXEX, NM_ITEM, "ARexxExecute",'E', NULL, - ami_menu_item_arexx_execute, NULL); - ami_menu_alloc_item(gwin, M_BAR_A1, NM_ITEM, NM_BARLABEL, 0, NULL, NULL, NULL); - gwin->menutype[AMI_MENU_AREXX_MAX] = NM_END; + ami_set_pointer(gwin, GUI_POINTER_WAIT, false); + ami_print_ui(browser_window_get_content(gwin->gw->bw)); + ami_reset_pointer(gwin); } -/* Menu refresh for hotlist */ -void ami_menu_refresh(struct gui_window_2 *gwin) +HOOKF(void, ami_menu_item_project_about, APTR, window, struct IntuiMessage *) { - SetAttrs(gwin->objects[OID_MAIN], + struct gui_window_2 *gwin; + char *temp, *temp2; + int sel; + nsurl *url = NULL; + nserror error = NSERROR_OK; + + GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); + + ami_set_pointer(gwin, GUI_POINTER_WAIT, false); + + temp = ASPrintf("%s|%s|%s", messages_get("OK"), + messages_get("HelpCredits"), + messages_get("HelpLicence")); + + temp2 = ami_utf8_easy(temp); + FreeVec(temp); #ifdef __amigaos4__ - WINDOW_NewMenu, NULL, + sel = TimedDosRequesterTags(TDR_ImageType,TDRIMAGE_INFO, + TDR_TitleString, messages_get("NetSurf"), + TDR_Window, gwin->win, + TDR_GadgetString, temp2, + TDR_FormatString,"NetSurf %s\nBuild date %s\n\nhttp://www.netsurf-browser.org", + TDR_Arg1,netsurf_version, + TDR_Arg2,verdate, + TAG_DONE); #else - WINDOW_MenuStrip, NULL, + /*\todo proper requester for OS3 + * at the moment menus are disabled so won't get here anyway */ + printf("NetSurf %s\nBuild date %s\n", netsurf_version, verdate); + sel = 0; #endif - TAG_DONE); + free(temp2); -#ifndef __amigaos4__ - ami_menu_free_os3(gwin->menu_os3); -#endif - ami_free_menulabs(gwin); - ami_create_menu(gwin); -#ifndef __amigaos4__ - gwin->menu_os3 = ami_menu_create_os3(gwin, gwin->menu); -#endif + if(sel == 2) { + error = nsurl_create("about:credits", &url); + } else if(sel == 0) { + error = nsurl_create("about:licence", &url); + } - SetAttrs(gwin->objects[OID_MAIN], -#ifdef __amigaos4__ - WINDOW_NewMenu, gwin->menu, -#else - WINDOW_MenuStrip, gwin->menu_os3, -#endif - TAG_DONE); + if(url) { + if (error == NSERROR_OK) { + error = browser_window_create(BW_CREATE_HISTORY, + url, + NULL, + NULL, + NULL); + nsurl_unref(url); + } + if (error != NSERROR_OK) { + warn_user(messages_get_errorcode(error), 0); + } + } + + ami_reset_pointer(gwin); } -static void ami_menu_load_glyphs(struct DrawInfo *dri) +HOOKF(void, ami_menu_item_project_quit, APTR, window, struct IntuiMessage *) { -#ifdef __amigaos4__ - for(int i = 0; i < NSA_GLYPH_MAX; i++) - menu_glyph[i] = NULL; - - menu_glyph[NSA_GLYPH_SUBMENU] = NewObject(NULL, "sysiclass", - SYSIA_Which, MENUSUB, - SYSIA_DrawInfo, dri, - TAG_DONE); - menu_glyph[NSA_GLYPH_AMIGAKEY] = NewObject(NULL, "sysiclass", - SYSIA_Which, AMIGAKEY, - SYSIA_DrawInfo, dri, - TAG_DONE); - GetAttr(IA_Width, menu_glyph[NSA_GLYPH_SUBMENU], - (ULONG *)&menu_glyph_width[NSA_GLYPH_SUBMENU]); - GetAttr(IA_Width, menu_glyph[NSA_GLYPH_AMIGAKEY], - (ULONG *)&menu_glyph_width[NSA_GLYPH_AMIGAKEY]); - - menu_glyphs_loaded = true; -#endif + ami_menu_window_close = AMI_MENU_WINDOW_CLOSE_ALL; } -void ami_menu_free_glyphs(void) +HOOKF(void, ami_menu_item_edit_cut, APTR, window, struct IntuiMessage *) { -#ifdef __amigaos4__ - int i; - if(menu_glyphs_loaded == false) return; - - for(i = 0; i < NSA_GLYPH_MAX; i++) { - if(menu_glyph[i]) DisposeObject(menu_glyph[i]); - menu_glyph[i] = NULL; - }; - - menu_glyphs_loaded = false; -#endif + struct gui_window_2 *gwin; + GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); + + browser_window_key_press(gwin->gw->bw, KEY_CUT_SELECTION); } -static int ami_menu_calc_item_width(struct gui_window_2 *gwin, int j, struct RastPort *rp) +HOOKF(void, ami_menu_item_edit_copy, APTR, window, struct IntuiMessage *) { - int space_width = TextLength(rp, " ", 1); - int item_size; - - item_size = TextLength(rp, gwin->menulab[j], strlen(gwin->menulab[j])); - item_size += space_width; + struct bitmap *bm; + struct gui_window_2 *gwin; + GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); - if(gwin->menukey[j]) { - item_size += TextLength(rp, &gwin->menukey[j], 1); - item_size += menu_glyph_width[NSA_GLYPH_AMIGAKEY]; - /**TODO: take account of the size of other imagery too + if(browser_window_can_select(gwin->gw->bw)) { + browser_window_key_press(gwin->gw->bw, KEY_COPY_SELECTION); + browser_window_key_press(gwin->gw->bw, KEY_CLEAR_SELECTION); + } + else if((bm = content_get_bitmap(browser_window_get_content(gwin->gw->bw)))) { + /** @todo It should be checked that the lifetime of + * the objects containing the values returned (and the + * constness cast away) is safe. */ + bm->url = (char *)nsurl_access(browser_window_get_url(gwin->gw->bw)); + bm->title = (char *)browser_window_get_title(gwin->gw->bw); + ami_easy_clipboard_bitmap(bm); + } +#ifdef WITH_NS_SVG + else if(ami_mime_compare(browser_window_get_content(gwin->gw->bw), "svg") == true) { + ami_easy_clipboard_svg(browser_window_get_content(gwin->gw->bw)); } +#endif +} - return item_size; +HOOKF(void, ami_menu_item_edit_paste, APTR, window, struct IntuiMessage *) +{ + struct gui_window_2 *gwin; + GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); + + browser_window_key_press(gwin->gw->bw, KEY_PASTE); } +HOOKF(void, ami_menu_item_edit_selectall, APTR, window, struct IntuiMessage *) +{ + struct gui_window_2 *gwin; + GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); + + browser_window_key_press(gwin->gw->bw, KEY_SELECT_ALL); + gui_start_selection(gwin->gw); +} -static struct gui_window_2 *ami_menu_layout(struct gui_window_2 *gwin) +HOOKF(void, ami_menu_item_edit_clearsel, APTR, window, struct IntuiMessage *) { - int i, j; - int txtlen = 0, subtxtlen = 0; - int left_posn; - struct RastPort *rp = &scrn->RastPort; - struct DrawInfo *dri = GetScreenDrawInfo(scrn); - int space_width = TextLength(rp, " ", 1); + struct gui_window_2 *gwin; + GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); - if(menu_glyphs_loaded == false) - ami_menu_load_glyphs(dri); + browser_window_key_press(gwin->gw->bw, KEY_CLEAR_SELECTION); +} - for(i=0; i <= AMI_MENU_AREXX_MAX; i++) - { - if(gwin->menutype[i] == NM_TITLE) { - j = i + 1; - txtlen = 0; - do { - if(gwin->menulab[j] != NM_BARLABEL) { - if(gwin->menutype[j] == NM_ITEM) { - int item_size = ami_menu_calc_item_width(gwin, j, rp); - if(item_size > txtlen) { - txtlen = item_size; - } - } - } - j++; - } while((gwin->menutype[j] != NM_TITLE) && (gwin->menutype[j] != 0)); - } -#ifdef __amigaos4__ - if(LIB_IS_AT_LEAST((struct Library *)GadToolsBase, 53, 6)) { - /* GadTools 53.6+ only. For now we will only create the menu - using label.image if there's a bitmap associated with the item. */ - if((gwin->menuicon[i] != NULL) && (gwin->menulab[i] != NM_BARLABEL)) { - int icon_width = 0; - Object *blank_space = NULL; - Object *submenuarrow = NULL; - Object *icon = BitMapObj, - BITMAP_Screen, scrn, - BITMAP_SourceFile, gwin->menuicon[i], - BITMAP_Masking, TRUE, - BitMapEnd; +HOOKF(void, ami_menu_item_edit_undo, APTR, window, struct IntuiMessage *) +{ + struct gui_window_2 *gwin; + GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); - /* \todo make this scale the bitmap to these dimensions */ - SetAttrs(icon, - BITMAP_Width, 16, - BITMAP_Height, 16, - TAG_DONE); + browser_window_key_press(gwin->gw->bw, KEY_UNDO); +} - GetAttr(IA_Width, icon, (ULONG *)&icon_width); +HOOKF(void, ami_menu_item_edit_redo, APTR, window, struct IntuiMessage *) +{ + struct gui_window_2 *gwin; + GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); - if(gwin->menutype[i] == NM_SUB) { - left_posn = subtxtlen; - } else { - left_posn = txtlen; - } + browser_window_key_press(gwin->gw->bw, KEY_REDO); +} - left_posn = left_posn - - TextLength(rp, gwin->menulab[i], strlen(gwin->menulab[i])) - - icon_width - space_width; +HOOKF(void, ami_menu_item_browser_find, APTR, window, struct IntuiMessage *) +{ + struct gui_window_2 *gwin; + GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); - if((gwin->menutype[i] == NM_ITEM) && (gwin->menutype[i+1] == NM_SUB)) { - left_posn -= menu_glyph_width[NSA_GLYPH_SUBMENU]; + ami_search_open(gwin->gw); +} - submenuarrow = NewObject(NULL, "sysiclass", - SYSIA_Which, MENUSUB, - SYSIA_DrawInfo, dri, - IA_Left, left_posn, - TAG_DONE); +HOOKF(void, ami_menu_item_browser_localhistory, APTR, window, struct IntuiMessage *) +{ + struct gui_window_2 *gwin; + GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); - j = i + 1; - subtxtlen = 0; - do { - if(gwin->menulab[j] != NM_BARLABEL) { - if(gwin->menutype[j] == NM_SUB) { - int item_size = ami_menu_calc_item_width(gwin, j, rp); - if(item_size > subtxtlen) { - subtxtlen = item_size; - } - } - } - j++; - } while((gwin->menutype[j] == NM_SUB)); - } + ami_history_open(gwin->gw); +} - /**TODO: Checkmark/MX images and keyboard shortcuts - */ +HOOKF(void, ami_menu_item_browser_globalhistory, APTR, window, struct IntuiMessage *) +{ + ami_tree_open(global_history_window,AMI_TREE_HISTORY); +} - if(gwin->menutype[i] == NM_SUB) { - blank_space = NewObject(NULL, "fillrectclass", - IA_Height, 0, - IA_Width, left_posn + icon_width, - TAG_DONE); - } - - gwin->menuobj[i] = LabelObj, - LABEL_MenuMode, TRUE, - LABEL_DrawInfo, dri, - LABEL_DisposeImage, TRUE, - LABEL_Image, icon, - LABEL_Text, " ", - LABEL_Text, gwin->menulab[i], - LABEL_DisposeImage, TRUE, - LABEL_Image, blank_space, - LABEL_DisposeImage, TRUE, - LABEL_Image, submenuarrow, - LabelEnd; +HOOKF(void, ami_menu_item_browser_cookies, APTR, window, struct IntuiMessage *) +{ + ami_tree_open(cookies_window,AMI_TREE_COOKIES); +} - if(gwin->menuobj[i]) gwin->menutype[i] |= MENU_IMAGE; - } - } -#endif - gwin->menu[i].nm_Type = gwin->menutype[i]; - - if(gwin->menuobj[i]) - gwin->menu[i].nm_Label = (void *)gwin->menuobj[i]; - else - gwin->menu[i].nm_Label = gwin->menulab[i]; +HOOKF(void, ami_menu_item_browser_foreimg, APTR, window, struct IntuiMessage *) +{ + struct Menu *menustrip; + bool checked = false; - if(gwin->menukey[i]) gwin->menu[i].nm_CommKey = &gwin->menukey[i]; - gwin->menu[i].nm_Flags = 0; - if(gwin->menu_hook[i].h_Entry) gwin->menu[i].nm_UserData = &gwin->menu_hook[i]; - - if(gwin->menuicon[i]) { - free(gwin->menuicon[i]); - gwin->menuicon[i] = NULL; - } - } - - FreeScreenDrawInfo(scrn, dri); + GetAttr(WINDOW_MenuStrip, (Object *)window, (ULONG *)&menustrip); + if(ItemAddress(menustrip, msg->Code)->Flags & CHECKED) checked = true; - return gwin; + nsoption_set_bool(foreground_images, checked); + ami_menu_check_toggled = true; } -#ifndef __amigaos4__ -void ami_menu_free_os3(struct gui_window_2 *gwin) +HOOKF(void, ami_menu_item_browser_backimg, APTR, window, struct IntuiMessage *) { - FreeMenus(gwin->menu_os3); - FreeVisualInfo(gwin->vi); + struct Menu *menustrip; + bool checked = false; + + GetAttr(WINDOW_MenuStrip, (Object *)window, (ULONG *)&menustrip); + if(ItemAddress(menustrip, msg->Code)->Flags & CHECKED) checked = true; + + nsoption_set_bool(background_images, checked); + ami_menu_check_toggled = true; } -struct Menu *ami_menu_create_os3(struct gui_window_2 *gwin, struct NewMenu *newmenu) +HOOKF(void, ami_menu_item_browser_enablejs, APTR, window, struct IntuiMessage *) { - gwin->vi = GetVisualInfo(scrn, TAG_DONE); - gwin->menu_os3 = CreateMenus(newmenu, TAG_DONE); - LayoutMenus(gwin->menu_os3, gwin->vi, - GTMN_NewLookMenus, TRUE, TAG_DONE); + struct Menu *menustrip; + bool checked = false; - return gwin->menu_os3; + GetAttr(WINDOW_MenuStrip, (Object *)window, (ULONG *)&menustrip); + if(ItemAddress(menustrip, msg->Code)->Flags & CHECKED) checked = true; + + nsoption_set_bool(enable_javascript, checked); + ami_menu_check_toggled = true; } -#endif -struct NewMenu *ami_create_menu(struct gui_window_2 *gwin) +HOOKF(void, ami_menu_item_browser_scale_decrease, APTR, window, struct IntuiMessage *) { - gwin->menu = ami_misc_allocvec_clear(sizeof(struct NewMenu) * (AMI_MENU_AREXX_MAX + 1), 0); - ami_init_menulabs(gwin); - ami_menu_scan(ami_tree_get_tree(hotlist_window), gwin); - ami_menu_arexx_scan(gwin); - gwin = ami_menu_layout(gwin); - -#if defined(WITH_JS) || defined(WITH_MOZJS) - gwin->menu[M_JS].nm_Flags = CHECKIT | MENUTOGGLE; - if(nsoption_bool(enable_javascript) == true) - gwin->menu[M_JS].nm_Flags |= CHECKED; -#endif + struct gui_window_2 *gwin; + GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); - gwin->menu[M_PRINT].nm_Flags = NM_ITEMDISABLED; + if(gwin->gw->scale > 0.1) + ami_gui_set_scale(gwin->gw, gwin->gw->scale - 0.1); +} - gwin->menu[M_IMGFORE].nm_Flags = CHECKIT | MENUTOGGLE; - if(nsoption_bool(foreground_images) == true) - gwin->menu[M_IMGFORE].nm_Flags |= CHECKED; - gwin->menu[M_IMGBACK].nm_Flags = CHECKIT | MENUTOGGLE; - if(nsoption_bool(background_images) == true) - gwin->menu[M_IMGBACK].nm_Flags |= CHECKED; +HOOKF(void, ami_menu_item_browser_scale_normal, APTR, window, struct IntuiMessage *) +{ + struct gui_window_2 *gwin; + GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); - return(gwin->menu); + ami_gui_set_scale(gwin->gw, 1.0); } -void ami_menu_arexx_scan(struct gui_window_2 *gwin) +HOOKF(void, ami_menu_item_browser_scale_increase, APTR, window, struct IntuiMessage *) { - int item = AMI_MENU_AREXX; - BPTR lock = 0; - UBYTE *buffer; - struct ExAllControl *ctrl; - char matchpatt[16]; - LONG cont; - struct ExAllData *ead; - char *menu_lab; + struct gui_window_2 *gwin; + GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); - if((lock = Lock(nsoption_charp(arexx_dir), SHARED_LOCK))) { - if((buffer = AllocVecTagList(1024, NULL))) { - if((ctrl = AllocDosObject(DOS_EXALLCONTROL,NULL))) { - ctrl->eac_LastKey = 0; + ami_gui_set_scale(gwin->gw, gwin->gw->scale + 0.1); +} - if(ParsePatternNoCase("#?.nsrx",(char *)&matchpatt,16) != -1) { - ctrl->eac_MatchString = (char *)&matchpatt; - } +HOOKF(void, ami_menu_item_browser_redraw, APTR, window, struct IntuiMessage *) +{ + struct gui_window_2 *gwin; + GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); - do { - cont = ExAll(lock,(struct ExAllData *)buffer,1024,ED_COMMENT,ctrl); - if((!cont) && (IoErr() != ERROR_NO_MORE_ENTRIES)) break; - if(!ctrl->eac_Entries) continue; + ami_schedule_redraw(gwin, true); + gwin->new_content = true; +} - for(ead = (struct ExAllData *)buffer; ead; ead = ead->ed_Next) { - if(item >= AMI_MENU_AREXX_MAX) continue; - if(EAD_IS_FILE(ead)) { - gwin->menu[item].nm_Type = NM_ITEM; - if(ead->ed_Comment[0] != '\0') - menu_lab = ead->ed_Comment; - else - menu_lab = ead->ed_Name; +HOOKF(void, ami_menu_item_hotlist_add, APTR, window, struct IntuiMessage *) +{ + struct browser_window *bw; + struct gui_window_2 *gwin; + GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); - ami_menu_alloc_item(gwin, item, NM_ITEM, menu_lab, 0, NULL, - ami_menu_item_arexx_entries, (void *)strdup(ead->ed_Name)); + bw = gwin->gw->bw; - item++; - } - } - } while(cont); - FreeDosObject(DOS_EXALLCONTROL,ctrl); - } - FreeVec(buffer); - } - UnLock(lock); - } + if (bw == NULL || browser_window_has_content(bw) == false) + return; - gwin->menu[item].nm_Type = NM_END; - gwin->menu[item].nm_Label = NULL; + hotlist_add_url(browser_window_get_url(bw)); + ami_gui_update_hotlist_button(gwin); } -static bool ami_menu_hotlist_add(void *userdata, int level, int item, const char *title, nsurl *url, bool is_folder) +HOOKF(void, ami_menu_item_hotlist_show, APTR, window, struct IntuiMessage *) { - UBYTE type; - STRPTR icon; - struct gui_window_2 *gw = (struct gui_window_2 *)userdata; - - if(item >= AMI_MENU_HOTLIST_MAX) return false; - - switch(level) { - case 1: - type = NM_ITEM; - break; - case 2: - type = NM_SUB; - break; - default: - /* entries not at level 1 or 2 are not able to be added - * \todo apparently this is possible with 4.1FE, need SDK! */ - return false; - break; - } - - if(is_folder == true) { - icon = ASPrintf("icons/directory.png"); - } else { - icon = ami_gui_get_cache_favicon_name(url, true); - if (icon == NULL) icon = ASPrintf("icons/content.png"); - } + ami_tree_open(hotlist_window, AMI_TREE_HOTLIST); +} - ami_menu_alloc_item(gw, item, type, title, - 0, icon, ami_menu_item_hotlist_entries, (void *)url); - if((is_folder == true) && (type == NM_SUB)) - gw->menu[item].nm_Flags = NM_ITEMDISABLED; +HOOKF(void, ami_menu_item_hotlist_entries, APTR, window, struct IntuiMessage *) +{ + nsurl *url = hook->h_Data; + struct gui_window_2 *gwin; + GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); - if(icon) FreeVec(icon); + if(url == NULL) return; - return true; + browser_window_navigate(gwin->gw->bw, + url, + NULL, + BW_NAVIGATE_HISTORY, + NULL, + NULL, + NULL); } -static nserror ami_menu_scan(struct tree *tree, struct gui_window_2 *gwin) +HOOKF(void, ami_menu_item_settings_edit, APTR, window, struct IntuiMessage *) { - return ami_hotlist_scan((void *)gwin, AMI_MENU_HOTLIST, messages_get("HotlistMenu"), ami_menu_hotlist_add); + ami_gui_opts_open(); } -void ami_menu_update_checked(struct gui_window_2 *gwin) +HOOKF(void, ami_menu_item_settings_snapshot, APTR, window, struct IntuiMessage *) { - struct Menu *menustrip; - - GetAttr(WINDOW_MenuStrip, gwin->objects[OID_MAIN], (ULONG *)&menustrip); - if(!menustrip) return; -#if defined(WITH_JS) || defined(WITH_MOZJS) - if(nsoption_bool(enable_javascript) == true) { - if((ItemAddress(menustrip, AMI_MENU_JS)->Flags & CHECKED) == 0) - ItemAddress(menustrip, AMI_MENU_JS)->Flags ^= CHECKED; - } else { - if(ItemAddress(menustrip, AMI_MENU_JS)->Flags & CHECKED) - ItemAddress(menustrip, AMI_MENU_JS)->Flags ^= CHECKED; - } -#endif - if(nsoption_bool(foreground_images) == true) { - if((ItemAddress(menustrip, AMI_MENU_FOREIMG)->Flags & CHECKED) == 0) - ItemAddress(menustrip, AMI_MENU_FOREIMG)->Flags ^= CHECKED; - } else { - if(ItemAddress(menustrip, AMI_MENU_FOREIMG)->Flags & CHECKED) - ItemAddress(menustrip, AMI_MENU_FOREIMG)->Flags ^= CHECKED; - } - - if(nsoption_bool(background_images) == true) { - if((ItemAddress(menustrip, AMI_MENU_BACKIMG)->Flags & CHECKED) == 0) - ItemAddress(menustrip, AMI_MENU_BACKIMG)->Flags ^= CHECKED; - } else { - if(ItemAddress(menustrip, AMI_MENU_BACKIMG)->Flags & CHECKED) - ItemAddress(menustrip, AMI_MENU_BACKIMG)->Flags ^= CHECKED; - } + struct gui_window_2 *gwin; + GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); - ResetMenuStrip(gwin->win, menustrip); + nsoption_set_int(window_x, gwin->win->LeftEdge); + nsoption_set_int(window_y, gwin->win->TopEdge); + nsoption_set_int(window_width, gwin->win->Width); + nsoption_set_int(window_height, gwin->win->Height); } -void ami_menu_update_disabled(struct gui_window *g, hlcache_handle *c) +HOOKF(void, ami_menu_item_settings_save, APTR, window, struct IntuiMessage *) { - struct Window *win = g->shared->win; + nsoption_write(current_user_options, NULL, NULL); +} - if(nsoption_bool(kiosk_mode) == true) return; +HOOKF(void, ami_menu_item_arexx_execute, APTR, window, struct IntuiMessage *) +{ + char *temp; + struct gui_window_2 *gwin; + GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); - if(content_get_type(c) <= CONTENT_CSS) - { - OnMenu(win,AMI_MENU_SAVEAS_TEXT); - OnMenu(win,AMI_MENU_SAVEAS_COMPLETE); -#ifdef WITH_PDF_EXPORT - OnMenu(win,AMI_MENU_SAVEAS_PDF); -#endif - if(browser_window_get_editor_flags(g->bw) & BW_EDITOR_CAN_COPY) - { - OnMenu(win,AMI_MENU_COPY); - OnMenu(win,AMI_MENU_CLEAR); - } else { - OffMenu(win,AMI_MENU_COPY); - OffMenu(win,AMI_MENU_CLEAR); - } - - if(browser_window_get_editor_flags(g->bw) & BW_EDITOR_CAN_CUT) - OnMenu(win,AMI_MENU_CUT); - else - OffMenu(win,AMI_MENU_CUT); - - if(browser_window_get_editor_flags(g->bw) & BW_EDITOR_CAN_PASTE) - OnMenu(win,AMI_MENU_PASTE); - else - OffMenu(win,AMI_MENU_PASTE); - - OnMenu(win,AMI_MENU_SELECTALL); - OnMenu(win,AMI_MENU_FIND); - OffMenu(win,AMI_MENU_SAVEAS_IFF); - } - else - { - OffMenu(win,AMI_MENU_CUT); - OffMenu(win,AMI_MENU_PASTE); - OffMenu(win,AMI_MENU_CLEAR); - - OffMenu(win,AMI_MENU_SAVEAS_TEXT); - OffMenu(win,AMI_MENU_SAVEAS_COMPLETE); -#ifdef WITH_PDF_EXPORT - OffMenu(win,AMI_MENU_SAVEAS_PDF); -#endif - OffMenu(win,AMI_MENU_SELECTALL); - OffMenu(win,AMI_MENU_FIND); - -#ifdef WITH_NS_SVG - if(content_get_bitmap(c) || (ami_mime_compare(c, "svg") == true)) -#else - if(content_get_bitmap(c)) -#endif - { - OnMenu(win,AMI_MENU_COPY); - OnMenu(win,AMI_MENU_SAVEAS_IFF); - } - else - { - OffMenu(win,AMI_MENU_COPY); - OffMenu(win,AMI_MENU_SAVEAS_IFF); + if(AslRequestTags(filereq, + ASLFR_Window, gwin->win, + ASLFR_SleepWindow, TRUE, + ASLFR_TitleText, messages_get("NetSurf"), + ASLFR_Screen, scrn, + ASLFR_DoSaveMode, FALSE, + ASLFR_InitialDrawer, nsoption_charp(arexx_dir), + ASLFR_InitialPattern, "#?.nsrx", + TAG_DONE)) { + if((temp = AllocVecTagList(1024, NULL))) { + strlcpy(temp, filereq->fr_Drawer, 1024); + AddPart(temp, filereq->fr_File, 1024); + ami_arexx_execute(temp); + FreeVec(temp); } } } -/* - * The below functions are called automatically by window.class when menu items are selected. - */ - -HOOKF(void, ami_menu_item_project_newwin, APTR, window, struct IntuiMessage *) +HOOKF(void, ami_menu_item_arexx_entries, APTR, window, struct IntuiMessage *) { - nsurl *url; - nserror error; + char *script = hook->h_Data; + char *temp; + struct gui_window_2 *gwin; + GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); - error = nsurl_create(nsoption_charp(homepage_url), &url); - if (error == NSERROR_OK) { - error = browser_window_create(BW_CREATE_HISTORY, - url, - NULL, - NULL, - NULL); - nsurl_unref(url); - } - if (error != NSERROR_OK) { - warn_user(messages_get_errorcode(error), 0); + if(script) { + if((temp = AllocVecTagList(1024, NULL))) { + BPTR lock; + if((lock = Lock(nsoption_charp(arexx_dir), SHARED_LOCK))) { + DevNameFromLock(lock, temp, 1024, DN_FULLPATH); + AddPart(temp, script, 1024); + ami_arexx_execute(temp); + FreeVec(temp); + UnLock(lock); + } + } } } -HOOKF(void, ami_menu_item_project_newtab, APTR, window, struct IntuiMessage *) -{ - struct gui_window_2 *gwin; - nserror error; - GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); - error = ami_gui_new_blank_tab(gwin); -} +/* menu creation code */ -HOOKF(void, ami_menu_item_project_open, APTR, window, struct IntuiMessage *) +void ami_free_menulabs(struct gui_window_2 *gwin) { - struct gui_window_2 *gwin; - GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); + int i; - ami_file_open(gwin); -} + for(i=0;i<=AMI_MENU_AREXX_MAX;i++) + { + if(gwin->menulab[i] && (gwin->menulab[i] != NM_BARLABEL)) + { + if(gwin->menutype[i] & MENU_IMAGE) + { + DisposeObject(gwin->menuobj[i]); + } -HOOKF(void, ami_menu_item_project_save, APTR, window, struct IntuiMessage *) -{ - struct gui_window_2 *gwin; - ULONG type = (ULONG)hook->h_Data; + ami_utf8_free(gwin->menulab[i]); - GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); + if(i >= AMI_MENU_AREXX) + { + if(gwin->menu_hook[i].h_Data) free(gwin->menu_hook[i].h_Data); + } + } - ami_file_save_req(type, gwin, browser_window_get_content(gwin->gw->bw)); -} + gwin->menulab[i] = NULL; + gwin->menuobj[i] = NULL; + gwin->menukey[i] = 0; + } -HOOKF(void, ami_menu_item_project_closetab, APTR, window, struct IntuiMessage *) -{ - struct gui_window_2 *gwin; - GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); + FreeVec(gwin->menutype); + FreeVec(gwin->menu); - browser_window_destroy(gwin->gw->bw); + gwin->menutype = NULL; + gwin->menu = NULL; } -HOOKF(void, ami_menu_item_project_closewin, APTR, window, struct IntuiMessage *) +static void ami_menu_alloc_item(struct gui_window_2 *gwin, int num, UBYTE type, + const char *label, char key, char *icon, void *func, void *hookdata) { - struct gui_window_2 *gwin; - GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); + char menu_icon[1024]; - ami_menu_window_close = gwin; -} + gwin->menutype[num] = type; -HOOKF(void, ami_menu_item_project_print, APTR, window, struct IntuiMessage *) -{ - struct gui_window_2 *gwin; - GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); + if((label == NM_BARLABEL) || (strcmp(label, "--") == 0)) { + gwin->menulab[num] = NM_BARLABEL; + } else { + if((num >= AMI_MENU_HOTLIST) && (num <= AMI_MENU_HOTLIST_MAX)) { + gwin->menulab[num] = ami_utf8_easy(label); + } else if((num >= AMI_MENU_AREXX) && (num <= AMI_MENU_AREXX_MAX)) { + gwin->menulab[num] = strdup(label); + } else { + gwin->menulab[num] = ami_utf8_easy(messages_get(label)); + } + } + + gwin->menuicon[num] = NULL; + if(key) gwin->menukey[num] = key; + if(func) gwin->menu_hook[num].h_Entry = (HOOKFUNC)func; + if(hookdata) gwin->menu_hook[num].h_Data = hookdata; - ami_set_pointer(gwin, GUI_POINTER_WAIT, false); - ami_print_ui(browser_window_get_content(gwin->gw->bw)); - ami_reset_pointer(gwin); + if(icon) { + if(ami_locate_resource(menu_icon, icon) == true) + gwin->menuicon[num] = (char *)strdup(menu_icon); + } } -HOOKF(void, ami_menu_item_project_about, APTR, window, struct IntuiMessage *) +static void ami_init_menulabs(struct gui_window_2 *gwin) { - struct gui_window_2 *gwin; - char *temp, *temp2; - int sel; - nsurl *url = NULL; - nserror error = NSERROR_OK; + int i; - GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); + gwin->menutype = ami_misc_allocvec_clear(AMI_MENU_AREXX_MAX + 1, 0); - ami_set_pointer(gwin, GUI_POINTER_WAIT, false); + for(i=0;i <= AMI_MENU_AREXX_MAX;i++) + { + gwin->menutype[i] = NM_IGNORE; + gwin->menulab[i] = NULL; + gwin->menuobj[i] = NULL; + } - temp = ASPrintf("%s|%s|%s", messages_get("OK"), - messages_get("HelpCredits"), - messages_get("HelpLicence")); + ami_menu_alloc_item(gwin, M_PROJECT, NM_TITLE, "Project", 0, NULL, NULL, NULL); + ami_menu_alloc_item(gwin, M_NEWWIN, NM_ITEM, "NewWindowNS", 'N', NULL, + ami_menu_item_project_newwin, NULL); + ami_menu_alloc_item(gwin, M_NEWTAB, NM_ITEM, "NewTab", 'T', NULL, + ami_menu_item_project_newtab, NULL); + ami_menu_alloc_item(gwin, M_BAR_P1, NM_ITEM, NM_BARLABEL, 0, NULL, NULL, NULL); + ami_menu_alloc_item(gwin, M_OPEN, NM_ITEM, "OpenFile", 'O', NULL, + ami_menu_item_project_open, NULL); + ami_menu_alloc_item(gwin, M_SAVEAS, NM_ITEM, "SaveAsNS", 0, NULL, NULL, NULL); + ami_menu_alloc_item(gwin, M_SAVESRC, NM_SUB, "Source", 'S', NULL, + ami_menu_item_project_save, (void *)AMINS_SAVE_SOURCE); + ami_menu_alloc_item(gwin, M_SAVETXT, NM_SUB, "TextNS", 0, NULL, + ami_menu_item_project_save, (void *)AMINS_SAVE_TEXT); + ami_menu_alloc_item(gwin, M_SAVECOMP, NM_SUB, "SaveCompNS", 0, NULL, + ami_menu_item_project_save, (void *)AMINS_SAVE_COMPLETE); +#ifdef WITH_PDF_EXPORT + ami_menu_alloc_item(gwin, M_SAVEPDF, NM_SUB, "PDFNS", 0, NULL, + ami_menu_item_project_save, (void *)AMINS_SAVE_PDF); +#endif + ami_menu_alloc_item(gwin, M_SAVEIFF, NM_SUB, "IFF", 0, NULL, + ami_menu_item_project_save, (void *)AMINS_SAVE_IFF); + ami_menu_alloc_item(gwin, M_BAR_P2, NM_ITEM, NM_BARLABEL, 0, NULL, NULL, NULL); + ami_menu_alloc_item(gwin, M_PRINT, NM_ITEM, "PrintNS", 'P', NULL, + ami_menu_item_project_print, NULL); + ami_menu_alloc_item(gwin, M_BAR_P3, NM_ITEM, NM_BARLABEL, 0, NULL, NULL, NULL); + ami_menu_alloc_item(gwin, M_CLOSETAB, NM_ITEM, "CloseTab", 'K', NULL, + ami_menu_item_project_closetab, NULL); + ami_menu_alloc_item(gwin, M_CLOSEWIN, NM_ITEM, "CloseWindow", 0, NULL, + ami_menu_item_project_closewin, NULL); + ami_menu_alloc_item(gwin, M_BAR_P4, NM_ITEM, NM_BARLABEL, 0, NULL, NULL, NULL); + ami_menu_alloc_item(gwin, M_ABOUT, NM_ITEM, "About", '?', NULL, + ami_menu_item_project_about, NULL); + ami_menu_alloc_item(gwin, M_BAR_P5, NM_ITEM, NM_BARLABEL, 0, NULL, NULL, NULL); + ami_menu_alloc_item(gwin, M_QUIT, NM_ITEM, "Quit", 'Q', NULL, + ami_menu_item_project_quit, NULL); - temp2 = ami_utf8_easy(temp); - FreeVec(temp); -#ifdef __amigaos4__ - sel = TimedDosRequesterTags(TDR_ImageType,TDRIMAGE_INFO, - TDR_TitleString, messages_get("NetSurf"), - TDR_Window, gwin->win, - TDR_GadgetString, temp2, - TDR_FormatString,"NetSurf %s\nBuild date %s\n\nhttp://www.netsurf-browser.org", - TDR_Arg1,netsurf_version, - TDR_Arg2,verdate, - TAG_DONE); -#else - /*\todo proper requester for OS3 - * at the moment menus are disabled so won't get here anyway */ - printf("NetSurf %s\nBuild date %s\n", netsurf_version, verdate); - sel = 0; + ami_menu_alloc_item(gwin, M_EDIT, NM_TITLE, "Edit", 0, NULL, NULL, NULL); + ami_menu_alloc_item(gwin, M_CUT, NM_ITEM, "CutNS", 'X', NULL, + ami_menu_item_edit_cut, NULL); + ami_menu_alloc_item(gwin, M_COPY, NM_ITEM, "CopyNS", 'C', NULL, + ami_menu_item_edit_copy, NULL); + ami_menu_alloc_item(gwin, M_PASTE, NM_ITEM, "PasteNS", 'V', NULL, + ami_menu_item_edit_paste, NULL); + ami_menu_alloc_item(gwin, M_BAR_E1, NM_ITEM, NM_BARLABEL, 0, NULL, NULL, NULL); + ami_menu_alloc_item(gwin, M_SELALL, NM_ITEM, "SelectAllNS", 'A', NULL, + ami_menu_item_edit_selectall, NULL); + ami_menu_alloc_item(gwin, M_CLEAR, NM_ITEM, "ClearNS", 0, NULL, + ami_menu_item_edit_clearsel, NULL); + ami_menu_alloc_item(gwin, M_BAR_E2, NM_ITEM, NM_BARLABEL, 0, NULL, NULL, NULL); + ami_menu_alloc_item(gwin, M_UNDO, NM_ITEM, "Undo", 'Z', NULL, + ami_menu_item_edit_undo, NULL); + ami_menu_alloc_item(gwin, M_REDO, NM_ITEM, "Redo", 'Y', NULL, + ami_menu_item_edit_redo, NULL); + + ami_menu_alloc_item(gwin, M_BROWSER, NM_TITLE, "Browser", 0, NULL, NULL, NULL); + ami_menu_alloc_item(gwin, M_FIND, NM_ITEM, "FindTextNS", 'F', NULL, + ami_menu_item_browser_find, NULL); + ami_menu_alloc_item(gwin, M_BAR_B1, NM_ITEM, NM_BARLABEL, 0, NULL, NULL, NULL); + ami_menu_alloc_item(gwin, M_HISTLOCL, NM_ITEM, "HistLocalNS", 0, NULL, + ami_menu_item_browser_localhistory, NULL); + ami_menu_alloc_item(gwin, M_HISTGLBL, NM_ITEM, "HistGlobalNS", 0, NULL, + ami_menu_item_browser_globalhistory, NULL); + ami_menu_alloc_item(gwin, M_BAR_B2, NM_ITEM, NM_BARLABEL, 0, NULL, NULL, NULL); + ami_menu_alloc_item(gwin, M_COOKIES, NM_ITEM, "ShowCookiesNS", 0, NULL, + ami_menu_item_browser_cookies, NULL); + ami_menu_alloc_item(gwin, M_BAR_B3, NM_ITEM, NM_BARLABEL, 0, NULL, NULL, NULL); + ami_menu_alloc_item(gwin, M_SCALE, NM_ITEM, "ScaleNS", 0, NULL, NULL, NULL); + ami_menu_alloc_item(gwin, M_SCALEDEC, NM_SUB, "ScaleDec", '-', NULL, + ami_menu_item_browser_scale_decrease, NULL); + ami_menu_alloc_item(gwin, M_SCALENRM, NM_SUB, "ScaleNorm", '=', NULL, + ami_menu_item_browser_scale_normal, NULL); + ami_menu_alloc_item(gwin, M_SCALEDEC, NM_SUB, "ScaleDec", '-', NULL, + ami_menu_item_browser_scale_decrease, NULL); + ami_menu_alloc_item(gwin, M_SCALEINC, NM_SUB, "ScaleInc", '+', NULL, + ami_menu_item_browser_scale_increase, NULL); + ami_menu_alloc_item(gwin, M_IMAGES, NM_ITEM, "Images", 0, NULL, NULL, NULL); + ami_menu_alloc_item(gwin, M_IMGFORE, NM_SUB, "ForeImg", 0, NULL, + ami_menu_item_browser_foreimg, NULL); + ami_menu_alloc_item(gwin, M_IMGBACK, NM_SUB, "BackImg", 0, NULL, + ami_menu_item_browser_backimg, NULL); +#if defined(WITH_JS) || defined(WITH_MOZJS) + ami_menu_alloc_item(gwin, M_JS, NM_ITEM, "EnableJS", 0, NULL, + ami_menu_item_browser_enablejs, NULL); #endif - free(temp2); + ami_menu_alloc_item(gwin, M_BAR_B4, NM_ITEM, NM_BARLABEL, 0, NULL, NULL, NULL); + ami_menu_alloc_item(gwin, M_REDRAW, NM_ITEM, "Redraw", 0, NULL, + ami_menu_item_browser_redraw, NULL); - if(sel == 2) { - error = nsurl_create("about:credits", &url); - } else if(sel == 0) { - error = nsurl_create("about:licence", &url); - } + ami_menu_alloc_item(gwin, M_HOTLIST, NM_TITLE, "Hotlist", 0, NULL, NULL, NULL); + ami_menu_alloc_item(gwin, M_HLADD, NM_ITEM, "HotlistAdd", 'B', NULL, + ami_menu_item_hotlist_add, NULL); + ami_menu_alloc_item(gwin, M_HLSHOW, NM_ITEM,"HotlistShowNS",'H', NULL, + ami_menu_item_hotlist_show, NULL); + ami_menu_alloc_item(gwin, M_BAR_H1, NM_ITEM, NM_BARLABEL, 0, NULL, NULL, NULL); - if(url) { - if (error == NSERROR_OK) { - error = browser_window_create(BW_CREATE_HISTORY, - url, - NULL, - NULL, - NULL); - nsurl_unref(url); - } - if (error != NSERROR_OK) { - warn_user(messages_get_errorcode(error), 0); - } - } + ami_menu_alloc_item(gwin, M_PREFS, NM_TITLE, "Settings", 0, NULL, NULL, NULL); + ami_menu_alloc_item(gwin, M_PREDIT, NM_ITEM, "SettingsEdit", 0, NULL, + ami_menu_item_settings_edit, NULL); + ami_menu_alloc_item(gwin, M_BAR_S1, NM_ITEM, NM_BARLABEL, 0, NULL, NULL, NULL); + ami_menu_alloc_item(gwin, M_SNAPSHOT, NM_ITEM, "SnapshotWindow",0, NULL, + ami_menu_item_settings_snapshot, NULL); + ami_menu_alloc_item(gwin, M_PRSAVE, NM_ITEM, "SettingsSave", 0, NULL, + ami_menu_item_settings_save, NULL); - ami_reset_pointer(gwin); + ami_menu_alloc_item(gwin, M_AREXX, NM_TITLE, "ARexx", 0, NULL, NULL, NULL); + ami_menu_alloc_item(gwin, M_AREXXEX, NM_ITEM, "ARexxExecute",'E', NULL, + ami_menu_item_arexx_execute, NULL); + ami_menu_alloc_item(gwin, M_BAR_A1, NM_ITEM, NM_BARLABEL, 0, NULL, NULL, NULL); + gwin->menutype[AMI_MENU_AREXX_MAX] = NM_END; } -HOOKF(void, ami_menu_item_project_quit, APTR, window, struct IntuiMessage *) +/* Menu refresh for hotlist */ +void ami_menu_refresh(struct gui_window_2 *gwin) { - ami_menu_window_close = AMI_MENU_WINDOW_CLOSE_ALL; -} + SetAttrs(gwin->objects[OID_MAIN], +#ifdef __amigaos4__ + WINDOW_NewMenu, NULL, +#else + WINDOW_MenuStrip, NULL, +#endif + TAG_DONE); -HOOKF(void, ami_menu_item_edit_cut, APTR, window, struct IntuiMessage *) -{ - struct gui_window_2 *gwin; - GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); +#ifndef __amigaos4__ + ami_menu_free_os3(gwin->menu_os3); +#endif + ami_free_menulabs(gwin); + ami_create_menu(gwin); +#ifndef __amigaos4__ + gwin->menu_os3 = ami_menu_create_os3(gwin, gwin->menu); +#endif - browser_window_key_press(gwin->gw->bw, KEY_CUT_SELECTION); + SetAttrs(gwin->objects[OID_MAIN], +#ifdef __amigaos4__ + WINDOW_NewMenu, gwin->menu, +#else + WINDOW_MenuStrip, gwin->menu_os3, +#endif + TAG_DONE); } -HOOKF(void, ami_menu_item_edit_copy, APTR, window, struct IntuiMessage *) +static void ami_menu_load_glyphs(struct DrawInfo *dri) { - struct bitmap *bm; - struct gui_window_2 *gwin; - GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); +#ifdef __amigaos4__ + for(int i = 0; i < NSA_GLYPH_MAX; i++) + menu_glyph[i] = NULL; - if(browser_window_can_select(gwin->gw->bw)) { - browser_window_key_press(gwin->gw->bw, KEY_COPY_SELECTION); - browser_window_key_press(gwin->gw->bw, KEY_CLEAR_SELECTION); - } - else if((bm = content_get_bitmap(browser_window_get_content(gwin->gw->bw)))) { - /** @todo It should be checked that the lifetime of - * the objects containing the values returned (and the - * constness cast away) is safe. - */ - bm->url = (char *)nsurl_access(browser_window_get_url(gwin->gw->bw)); - bm->title = (char *)browser_window_get_title(gwin->gw->bw); - ami_easy_clipboard_bitmap(bm); - } -#ifdef WITH_NS_SVG - else if(ami_mime_compare(browser_window_get_content(gwin->gw->bw), "svg") == true) { - ami_easy_clipboard_svg(browser_window_get_content(gwin->gw->bw)); - } + menu_glyph[NSA_GLYPH_SUBMENU] = NewObject(NULL, "sysiclass", + SYSIA_Which, MENUSUB, + SYSIA_DrawInfo, dri, + TAG_DONE); + menu_glyph[NSA_GLYPH_AMIGAKEY] = NewObject(NULL, "sysiclass", + SYSIA_Which, AMIGAKEY, + SYSIA_DrawInfo, dri, + TAG_DONE); + GetAttr(IA_Width, menu_glyph[NSA_GLYPH_SUBMENU], + (ULONG *)&menu_glyph_width[NSA_GLYPH_SUBMENU]); + GetAttr(IA_Width, menu_glyph[NSA_GLYPH_AMIGAKEY], + (ULONG *)&menu_glyph_width[NSA_GLYPH_AMIGAKEY]); + + menu_glyphs_loaded = true; #endif } -HOOKF(void, ami_menu_item_edit_paste, APTR, window, struct IntuiMessage *) +void ami_menu_free_glyphs(void) { - struct gui_window_2 *gwin; - GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); - - browser_window_key_press(gwin->gw->bw, KEY_PASTE); +#ifdef __amigaos4__ + int i; + if(menu_glyphs_loaded == false) return; + + for(i = 0; i < NSA_GLYPH_MAX; i++) { + if(menu_glyph[i]) DisposeObject(menu_glyph[i]); + menu_glyph[i] = NULL; + }; + + menu_glyphs_loaded = false; +#endif } -HOOKF(void, ami_menu_item_edit_selectall, APTR, window, struct IntuiMessage *) +static int ami_menu_calc_item_width(struct gui_window_2 *gwin, int j, struct RastPort *rp) { - struct gui_window_2 *gwin; - GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); + int space_width = TextLength(rp, " ", 1); + int item_size; - browser_window_key_press(gwin->gw->bw, KEY_SELECT_ALL); - gui_start_selection(gwin->gw); -} + item_size = TextLength(rp, gwin->menulab[j], strlen(gwin->menulab[j])); + item_size += space_width; -HOOKF(void, ami_menu_item_edit_clearsel, APTR, window, struct IntuiMessage *) -{ - struct gui_window_2 *gwin; - GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); + if(gwin->menukey[j]) { + item_size += TextLength(rp, &gwin->menukey[j], 1); + item_size += menu_glyph_width[NSA_GLYPH_AMIGAKEY]; + /**TODO: take account of the size of other imagery too + */ + } - browser_window_key_press(gwin->gw->bw, KEY_CLEAR_SELECTION); + return item_size; } -HOOKF(void, ami_menu_item_edit_undo, APTR, window, struct IntuiMessage *) + +static struct gui_window_2 *ami_menu_layout(struct gui_window_2 *gwin) { - struct gui_window_2 *gwin; - GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); + int i, j; + int txtlen = 0, subtxtlen = 0; + int left_posn; + struct RastPort *rp = &scrn->RastPort; + struct DrawInfo *dri = GetScreenDrawInfo(scrn); + int space_width = TextLength(rp, " ", 1); - browser_window_key_press(gwin->gw->bw, KEY_UNDO); -} + if(menu_glyphs_loaded == false) + ami_menu_load_glyphs(dri); -HOOKF(void, ami_menu_item_edit_redo, APTR, window, struct IntuiMessage *) -{ - struct gui_window_2 *gwin; - GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); + for(i=0; i <= AMI_MENU_AREXX_MAX; i++) + { + if(gwin->menutype[i] == NM_TITLE) { + j = i + 1; + txtlen = 0; + do { + if(gwin->menulab[j] != NM_BARLABEL) { + if(gwin->menutype[j] == NM_ITEM) { + int item_size = ami_menu_calc_item_width(gwin, j, rp); + if(item_size > txtlen) { + txtlen = item_size; + } + } + } + j++; + } while((gwin->menutype[j] != NM_TITLE) && (gwin->menutype[j] != 0)); + } +#ifdef __amigaos4__ + if(LIB_IS_AT_LEAST((struct Library *)GadToolsBase, 53, 6)) { + /* GadTools 53.6+ only. For now we will only create the menu + using label.image if there's a bitmap associated with the item. */ + if((gwin->menuicon[i] != NULL) && (gwin->menulab[i] != NM_BARLABEL)) { + int icon_width = 0; + Object *blank_space = NULL; + Object *submenuarrow = NULL; + Object *icon = BitMapObj, + BITMAP_Screen, scrn, + BITMAP_SourceFile, gwin->menuicon[i], + BITMAP_Masking, TRUE, + BitMapEnd; - browser_window_key_press(gwin->gw->bw, KEY_REDO); -} + /* \todo make this scale the bitmap to these dimensions */ + SetAttrs(icon, + BITMAP_Width, 16, + BITMAP_Height, 16, + TAG_DONE); -HOOKF(void, ami_menu_item_browser_find, APTR, window, struct IntuiMessage *) -{ - struct gui_window_2 *gwin; - GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); + GetAttr(IA_Width, icon, (ULONG *)&icon_width); - ami_search_open(gwin->gw); -} + if(gwin->menutype[i] == NM_SUB) { + left_posn = subtxtlen; + } else { + left_posn = txtlen; + } -HOOKF(void, ami_menu_item_browser_localhistory, APTR, window, struct IntuiMessage *) -{ - struct gui_window_2 *gwin; - GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); + left_posn = left_posn - + TextLength(rp, gwin->menulab[i], strlen(gwin->menulab[i])) - + icon_width - space_width; - ami_history_open(gwin->gw); -} + if((gwin->menutype[i] == NM_ITEM) && (gwin->menutype[i+1] == NM_SUB)) { + left_posn -= menu_glyph_width[NSA_GLYPH_SUBMENU]; -HOOKF(void, ami_menu_item_browser_globalhistory, APTR, window, struct IntuiMessage *) -{ - ami_tree_open(global_history_window,AMI_TREE_HISTORY); -} + submenuarrow = NewObject(NULL, "sysiclass", + SYSIA_Which, MENUSUB, + SYSIA_DrawInfo, dri, + IA_Left, left_posn, + TAG_DONE); -HOOKF(void, ami_menu_item_browser_cookies, APTR, window, struct IntuiMessage *) -{ - ami_tree_open(cookies_window,AMI_TREE_COOKIES); -} + j = i + 1; + subtxtlen = 0; + do { + if(gwin->menulab[j] != NM_BARLABEL) { + if(gwin->menutype[j] == NM_SUB) { + int item_size = ami_menu_calc_item_width(gwin, j, rp); + if(item_size > subtxtlen) { + subtxtlen = item_size; + } + } + } + j++; + } while((gwin->menutype[j] == NM_SUB)); + } -HOOKF(void, ami_menu_item_browser_foreimg, APTR, window, struct IntuiMessage *) -{ - struct Menu *menustrip; - bool checked = false; + /**TODO: Checkmark/MX images and keyboard shortcuts + */ - GetAttr(WINDOW_MenuStrip, (Object *)window, (ULONG *)&menustrip); - if(ItemAddress(menustrip, msg->Code)->Flags & CHECKED) checked = true; - - nsoption_set_bool(foreground_images, checked); - ami_menu_check_toggled = true; -} + if(gwin->menutype[i] == NM_SUB) { + blank_space = NewObject(NULL, "fillrectclass", + IA_Height, 0, + IA_Width, left_posn + icon_width, + TAG_DONE); + } + + gwin->menuobj[i] = LabelObj, + LABEL_MenuMode, TRUE, + LABEL_DrawInfo, dri, + LABEL_DisposeImage, TRUE, + LABEL_Image, icon, + LABEL_Text, " ", + LABEL_Text, gwin->menulab[i], + LABEL_DisposeImage, TRUE, + LABEL_Image, blank_space, + LABEL_DisposeImage, TRUE, + LABEL_Image, submenuarrow, + LabelEnd; -HOOKF(void, ami_menu_item_browser_backimg, APTR, window, struct IntuiMessage *) -{ - struct Menu *menustrip; - bool checked = false; + if(gwin->menuobj[i]) gwin->menutype[i] |= MENU_IMAGE; + } + } +#endif + gwin->menu[i].nm_Type = gwin->menutype[i]; + + if(gwin->menuobj[i]) + gwin->menu[i].nm_Label = (void *)gwin->menuobj[i]; + else + gwin->menu[i].nm_Label = gwin->menulab[i]; - GetAttr(WINDOW_MenuStrip, (Object *)window, (ULONG *)&menustrip); - if(ItemAddress(menustrip, msg->Code)->Flags & CHECKED) checked = true; + if(gwin->menukey[i]) gwin->menu[i].nm_CommKey = &gwin->menukey[i]; + gwin->menu[i].nm_Flags = 0; + if(gwin->menu_hook[i].h_Entry) gwin->menu[i].nm_UserData = &gwin->menu_hook[i]; + + if(gwin->menuicon[i]) { + free(gwin->menuicon[i]); + gwin->menuicon[i] = NULL; + } + } - nsoption_set_bool(background_images, checked); - ami_menu_check_toggled = true; + FreeScreenDrawInfo(scrn, dri); + + return gwin; } -HOOKF(void, ami_menu_item_browser_enablejs, APTR, window, struct IntuiMessage *) +#ifndef __amigaos4__ +void ami_menu_free_os3(struct gui_window_2 *gwin) { - struct Menu *menustrip; - bool checked = false; - - GetAttr(WINDOW_MenuStrip, (Object *)window, (ULONG *)&menustrip); - if(ItemAddress(menustrip, msg->Code)->Flags & CHECKED) checked = true; - - nsoption_set_bool(enable_javascript, checked); - ami_menu_check_toggled = true; + FreeMenus(gwin->menu_os3); + FreeVisualInfo(gwin->vi); } -HOOKF(void, ami_menu_item_browser_scale_decrease, APTR, window, struct IntuiMessage *) +struct Menu *ami_menu_create_os3(struct gui_window_2 *gwin, struct NewMenu *newmenu) { - struct gui_window_2 *gwin; - GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); + gwin->vi = GetVisualInfo(scrn, TAG_DONE); + gwin->menu_os3 = CreateMenus(newmenu, TAG_DONE); + LayoutMenus(gwin->menu_os3, gwin->vi, + GTMN_NewLookMenus, TRUE, TAG_DONE); - if(gwin->gw->scale > 0.1) - ami_gui_set_scale(gwin->gw, gwin->gw->scale - 0.1); + return gwin->menu_os3; } +#endif -HOOKF(void, ami_menu_item_browser_scale_normal, APTR, window, struct IntuiMessage *) +struct NewMenu *ami_create_menu(struct gui_window_2 *gwin) { - struct gui_window_2 *gwin; - GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); + gwin->menu = ami_misc_allocvec_clear(sizeof(struct NewMenu) * (AMI_MENU_AREXX_MAX + 1), 0); + ami_init_menulabs(gwin); + ami_menu_scan(ami_tree_get_tree(hotlist_window), gwin); + ami_menu_arexx_scan(gwin); + gwin = ami_menu_layout(gwin); + +#if defined(WITH_JS) || defined(WITH_MOZJS) + gwin->menu[M_JS].nm_Flags = CHECKIT | MENUTOGGLE; + if(nsoption_bool(enable_javascript) == true) + gwin->menu[M_JS].nm_Flags |= CHECKED; +#endif + + gwin->menu[M_PRINT].nm_Flags = NM_ITEMDISABLED; + + gwin->menu[M_IMGFORE].nm_Flags = CHECKIT | MENUTOGGLE; + if(nsoption_bool(foreground_images) == true) + gwin->menu[M_IMGFORE].nm_Flags |= CHECKED; + gwin->menu[M_IMGBACK].nm_Flags = CHECKIT | MENUTOGGLE; + if(nsoption_bool(background_images) == true) + gwin->menu[M_IMGBACK].nm_Flags |= CHECKED; - ami_gui_set_scale(gwin->gw, 1.0); + return(gwin->menu); } -HOOKF(void, ami_menu_item_browser_scale_increase, APTR, window, struct IntuiMessage *) +void ami_menu_arexx_scan(struct gui_window_2 *gwin) { - struct gui_window_2 *gwin; - GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); + int item = AMI_MENU_AREXX; + BPTR lock = 0; + UBYTE *buffer; + struct ExAllControl *ctrl; + char matchpatt[16]; + LONG cont; + struct ExAllData *ead; + char *menu_lab; - ami_gui_set_scale(gwin->gw, gwin->gw->scale + 0.1); -} + if((lock = Lock(nsoption_charp(arexx_dir), SHARED_LOCK))) { + if((buffer = AllocVecTagList(1024, NULL))) { + if((ctrl = AllocDosObject(DOS_EXALLCONTROL,NULL))) { + ctrl->eac_LastKey = 0; -HOOKF(void, ami_menu_item_browser_redraw, APTR, window, struct IntuiMessage *) -{ - struct gui_window_2 *gwin; - GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); + if(ParsePatternNoCase("#?.nsrx",(char *)&matchpatt,16) != -1) { + ctrl->eac_MatchString = (char *)&matchpatt; + } - ami_schedule_redraw(gwin, true); - gwin->new_content = true; -} + do { + cont = ExAll(lock,(struct ExAllData *)buffer,1024,ED_COMMENT,ctrl); + if((!cont) && (IoErr() != ERROR_NO_MORE_ENTRIES)) break; + if(!ctrl->eac_Entries) continue; -HOOKF(void, ami_menu_item_hotlist_add, APTR, window, struct IntuiMessage *) -{ - struct browser_window *bw; - struct gui_window_2 *gwin; - GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); + for(ead = (struct ExAllData *)buffer; ead; ead = ead->ed_Next) { + if(item >= AMI_MENU_AREXX_MAX) continue; + if(EAD_IS_FILE(ead)) { + gwin->menu[item].nm_Type = NM_ITEM; + if(ead->ed_Comment[0] != '\0') + menu_lab = ead->ed_Comment; + else + menu_lab = ead->ed_Name; - bw = gwin->gw->bw; + ami_menu_alloc_item(gwin, item, NM_ITEM, menu_lab, 0, NULL, + ami_menu_item_arexx_entries, (void *)strdup(ead->ed_Name)); - if (bw == NULL || browser_window_has_content(bw) == false) - return; + item++; + } + } + } while(cont); + FreeDosObject(DOS_EXALLCONTROL,ctrl); + } + FreeVec(buffer); + } + UnLock(lock); + } - hotlist_add_url(browser_window_get_url(bw)); - ami_gui_update_hotlist_button(gwin); + gwin->menu[item].nm_Type = NM_END; + gwin->menu[item].nm_Label = NULL; } -HOOKF(void, ami_menu_item_hotlist_show, APTR, window, struct IntuiMessage *) +static bool ami_menu_hotlist_add(void *userdata, int level, int item, const char *title, nsurl *url, bool is_folder) { - ami_tree_open(hotlist_window, AMI_TREE_HOTLIST); -} + UBYTE type; + STRPTR icon; + struct gui_window_2 *gw = (struct gui_window_2 *)userdata; + + if(item >= AMI_MENU_HOTLIST_MAX) return false; + + switch(level) { + case 1: + type = NM_ITEM; + break; + case 2: + type = NM_SUB; + break; + default: + /* entries not at level 1 or 2 are not able to be added + * \todo apparently this is possible with 4.1FE, need SDK! */ + return false; + break; + } -HOOKF(void, ami_menu_item_hotlist_entries, APTR, window, struct IntuiMessage *) -{ - nsurl *url = hook->h_Data; - struct gui_window_2 *gwin; - GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); + if(is_folder == true) { + icon = ASPrintf("icons/directory.png"); + } else { + icon = ami_gui_get_cache_favicon_name(url, true); + if (icon == NULL) icon = ASPrintf("icons/content.png"); + } - if(url == NULL) return; + ami_menu_alloc_item(gw, item, type, title, + 0, icon, ami_menu_item_hotlist_entries, (void *)url); + if((is_folder == true) && (type == NM_SUB)) + gw->menu[item].nm_Flags = NM_ITEMDISABLED; - browser_window_navigate(gwin->gw->bw, - url, - NULL, - BW_NAVIGATE_HISTORY, - NULL, - NULL, - NULL); + if(icon) FreeVec(icon); + + return true; } -HOOKF(void, ami_menu_item_settings_edit, APTR, window, struct IntuiMessage *) +static nserror ami_menu_scan(struct tree *tree, struct gui_window_2 *gwin) { - ami_gui_opts_open(); + return ami_hotlist_scan((void *)gwin, AMI_MENU_HOTLIST, messages_get("HotlistMenu"), ami_menu_hotlist_add); } -HOOKF(void, ami_menu_item_settings_snapshot, APTR, window, struct IntuiMessage *) +void ami_menu_update_checked(struct gui_window_2 *gwin) { - struct gui_window_2 *gwin; - GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); + struct Menu *menustrip; - nsoption_set_int(window_x, gwin->win->LeftEdge); - nsoption_set_int(window_y, gwin->win->TopEdge); - nsoption_set_int(window_width, gwin->win->Width); - nsoption_set_int(window_height, gwin->win->Height); -} + GetAttr(WINDOW_MenuStrip, gwin->objects[OID_MAIN], (ULONG *)&menustrip); + if(!menustrip) return; +#if defined(WITH_JS) || defined(WITH_MOZJS) + if(nsoption_bool(enable_javascript) == true) { + if((ItemAddress(menustrip, AMI_MENU_JS)->Flags & CHECKED) == 0) + ItemAddress(menustrip, AMI_MENU_JS)->Flags ^= CHECKED; + } else { + if(ItemAddress(menustrip, AMI_MENU_JS)->Flags & CHECKED) + ItemAddress(menustrip, AMI_MENU_JS)->Flags ^= CHECKED; + } +#endif + if(nsoption_bool(foreground_images) == true) { + if((ItemAddress(menustrip, AMI_MENU_FOREIMG)->Flags & CHECKED) == 0) + ItemAddress(menustrip, AMI_MENU_FOREIMG)->Flags ^= CHECKED; + } else { + if(ItemAddress(menustrip, AMI_MENU_FOREIMG)->Flags & CHECKED) + ItemAddress(menustrip, AMI_MENU_FOREIMG)->Flags ^= CHECKED; + } -HOOKF(void, ami_menu_item_settings_save, APTR, window, struct IntuiMessage *) -{ - nsoption_write(current_user_options, NULL, NULL); + if(nsoption_bool(background_images) == true) { + if((ItemAddress(menustrip, AMI_MENU_BACKIMG)->Flags & CHECKED) == 0) + ItemAddress(menustrip, AMI_MENU_BACKIMG)->Flags ^= CHECKED; + } else { + if(ItemAddress(menustrip, AMI_MENU_BACKIMG)->Flags & CHECKED) + ItemAddress(menustrip, AMI_MENU_BACKIMG)->Flags ^= CHECKED; + } + + ResetMenuStrip(gwin->win, menustrip); } -HOOKF(void, ami_menu_item_arexx_execute, APTR, window, struct IntuiMessage *) +void ami_menu_update_disabled(struct gui_window *g, hlcache_handle *c) { - char *temp; - struct gui_window_2 *gwin; - GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); + struct Window *win = g->shared->win; - if(AslRequestTags(filereq, - ASLFR_Window, gwin->win, - ASLFR_SleepWindow, TRUE, - ASLFR_TitleText, messages_get("NetSurf"), - ASLFR_Screen, scrn, - ASLFR_DoSaveMode, FALSE, - ASLFR_InitialDrawer, nsoption_charp(arexx_dir), - ASLFR_InitialPattern, "#?.nsrx", - TAG_DONE)) { - if((temp = AllocVecTagList(1024, NULL))) { - strlcpy(temp, filereq->fr_Drawer, 1024); - AddPart(temp, filereq->fr_File, 1024); - ami_arexx_execute(temp); - FreeVec(temp); + if(nsoption_bool(kiosk_mode) == true) return; + + if(content_get_type(c) <= CONTENT_CSS) + { + OnMenu(win,AMI_MENU_SAVEAS_TEXT); + OnMenu(win,AMI_MENU_SAVEAS_COMPLETE); +#ifdef WITH_PDF_EXPORT + OnMenu(win,AMI_MENU_SAVEAS_PDF); +#endif + if(browser_window_get_editor_flags(g->bw) & BW_EDITOR_CAN_COPY) + { + OnMenu(win,AMI_MENU_COPY); + OnMenu(win,AMI_MENU_CLEAR); + } else { + OffMenu(win,AMI_MENU_COPY); + OffMenu(win,AMI_MENU_CLEAR); } + + if(browser_window_get_editor_flags(g->bw) & BW_EDITOR_CAN_CUT) + OnMenu(win,AMI_MENU_CUT); + else + OffMenu(win,AMI_MENU_CUT); + + if(browser_window_get_editor_flags(g->bw) & BW_EDITOR_CAN_PASTE) + OnMenu(win,AMI_MENU_PASTE); + else + OffMenu(win,AMI_MENU_PASTE); + + OnMenu(win,AMI_MENU_SELECTALL); + OnMenu(win,AMI_MENU_FIND); + OffMenu(win,AMI_MENU_SAVEAS_IFF); } -} + else + { + OffMenu(win,AMI_MENU_CUT); + OffMenu(win,AMI_MENU_PASTE); + OffMenu(win,AMI_MENU_CLEAR); -HOOKF(void, ami_menu_item_arexx_entries, APTR, window, struct IntuiMessage *) -{ - char *script = hook->h_Data; - char *temp; - struct gui_window_2 *gwin; - GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); + OffMenu(win,AMI_MENU_SAVEAS_TEXT); + OffMenu(win,AMI_MENU_SAVEAS_COMPLETE); +#ifdef WITH_PDF_EXPORT + OffMenu(win,AMI_MENU_SAVEAS_PDF); +#endif + OffMenu(win,AMI_MENU_SELECTALL); + OffMenu(win,AMI_MENU_FIND); - if(script) { - if((temp = AllocVecTagList(1024, NULL))) { - BPTR lock; - if((lock = Lock(nsoption_charp(arexx_dir), SHARED_LOCK))) { - DevNameFromLock(lock, temp, 1024, DN_FULLPATH); - AddPart(temp, script, 1024); - ami_arexx_execute(temp); - FreeVec(temp); - UnLock(lock); - } +#ifdef WITH_NS_SVG + if(content_get_bitmap(c) || (ami_mime_compare(c, "svg") == true)) +#else + if(content_get_bitmap(c)) +#endif + { + OnMenu(win,AMI_MENU_COPY); + OnMenu(win,AMI_MENU_SAVEAS_IFF); + } + else + { + OffMenu(win,AMI_MENU_COPY); + OffMenu(win,AMI_MENU_SAVEAS_IFF); } } } -- cgit v1.2.3 From 1ea747196ea9f1b01dcb29fedac62372ca0e300b Mon Sep 17 00:00:00 2001 From: Chris Young Date: Tue, 24 Feb 2015 19:51:51 +0000 Subject: Fix more hook functions --- amiga/agclass/amigaguide_class.c | 11 ++++++++--- amiga/context_menu.c | 10 +++++----- amiga/file.c | 7 +++---- amiga/history_local.c | 4 ++-- amiga/tree.c | 2 +- 5 files changed, 19 insertions(+), 15 deletions(-) diff --git a/amiga/agclass/amigaguide_class.c b/amiga/agclass/amigaguide_class.c index 556445e1b..2b80223ca 100644 --- a/amiga/agclass/amigaguide_class.c +++ b/amiga/agclass/amigaguide_class.c @@ -7,7 +7,11 @@ #include "amiga/os3support.h" #include "amigaguide_class.h" - +#ifdef __amigaos4__ +#define DISPATCHHOOK(func) static uint32 func(Class *cl, Object *o, Msg msg) +#else +#define DISPATCHHOOK(func) static ASM uint32 func(REG(a0, Class *cl),REG(a2, Object *o), REG(a1, Msg msg)) +#endif struct localObjectData { @@ -24,7 +28,8 @@ struct AmigaGuideIFace *IAmigaGuide = NULL; /* ********************************** function prototypes ************************************ */ -static uint32 dispatchAGClass(Class *, Object *, Msg); +DISPATCHHOOK(dispatchAGClass); + // class methods uint32 om_new(Class *, Object *, struct opSet *); @@ -89,7 +94,7 @@ BOOL freeAGClass(Class *cl) /* ************************************** class dispatcher ************************************ */ -static uint32 dispatchAGClass(Class *cl, Object *o, Msg msg) +DISPATCHHOOK(dispatchAGClass) { switch (msg->MethodID) diff --git a/amiga/context_menu.c b/amiga/context_menu.c index b74affb11..970490e16 100644 --- a/amiga/context_menu.c +++ b/amiga/context_menu.c @@ -52,12 +52,12 @@ #include "amiga/context_menu.h" -static uint32 ami_context_menu_hook(struct Hook *hook, Object *item, APTR reserved); +HOOKF(uint32, ami_context_menu_hook, Object *, item, APTR); +HOOKF(uint32, ami_popup_hook, Object *, item, APTR); + static bool ami_context_menu_history(const struct browser_window *bw, int x0, int y0, int x1, int y1, const struct history_entry *entry, void *user_data); -static uint32 ami_popup_hook(struct Hook *hook,Object *item,APTR reserved); - enum { CMID_SELECTFILE, CMID_COPYURL, @@ -695,7 +695,7 @@ void ami_context_menu_show(struct gui_window_2 *gwin,int x,int y) IDoMethod(ctxmenuobj, PM_OPEN, gwin->win); } -static uint32 ami_context_menu_hook(struct Hook *hook,Object *item,APTR reserved) +HOOKF(uint32, ami_context_menu_hook, Object *, item, APTR) { int32 itemid = 0; struct gui_window_2 *gwin = hook->h_Data; @@ -1255,7 +1255,7 @@ static bool ami_context_menu_history(const struct browser_window *bw, return true; } -static uint32 ami_popup_hook(struct Hook *hook,Object *item,APTR reserved) +HOOKF(uint32, ami_popup_hook, Object *, item, APTR) { uint32 itemid = 0; struct gui_window *gwin = hook->h_Data; diff --git a/amiga/file.c b/amiga/file.c index 733c9c780..e7f1fd356 100644 --- a/amiga/file.c +++ b/amiga/file.c @@ -46,8 +46,7 @@ static struct Hook aslhookfunc; -static ULONG ami_file_asl_mime_hook(struct Hook *mh, - struct FileRequester *fr, struct AnchorPathOld *ap) +HOOKF(ULONG, ami_file_asl_mime_hook, struct FileRequester *, fr, struct AnchorPathOld *) { char fname[1024]; BOOL ret = FALSE; @@ -56,10 +55,10 @@ static ULONG ami_file_asl_mime_hook(struct Hook *mh, lwc_error lerror; content_type ct; - if(ap->ap_Info.fib_DirEntryType > 0) return(TRUE); + if(msg->ap_Info.fib_DirEntryType > 0) return(TRUE); strcpy(fname,fr->fr_Drawer); - AddPart(fname,ap->ap_Info.fib_FileName,1024); + AddPart(fname, msg->ap_Info.fib_FileName,1024); mt = strdup(fetch_filetype(fname)); lerror = lwc_intern_string(mt, strlen(mt), &lwc_mt); diff --git a/amiga/history_local.c b/amiga/history_local.c index b56293d48..39456496c 100755 --- a/amiga/history_local.c +++ b/amiga/history_local.c @@ -57,7 +57,7 @@ #include "amiga/history_local.h" void ami_history_update_extent(struct history_window *hw); -static void ami_history_scroller_hook(struct Hook *hook,Object *object,struct IntuiMessage *msg); +HOOKF(void, ami_history_scroller_hook, Object *, object, struct IntuiMessage *); /** * Redraw history window. @@ -323,7 +323,7 @@ void ami_history_update_extent(struct history_window *hw) ami_gui_free_space_box(bbox); } -void ami_history_scroller_hook(struct Hook *hook,Object *object,struct IntuiMessage *msg) +HOOKF(void, ami_history_scroller_hook, Object *, object, struct IntuiMessage *) { ULONG gid; struct history_window *hw = hook->h_Data; diff --git a/amiga/tree.c b/amiga/tree.c index 4f2c28630..cba5375b6 100644 --- a/amiga/tree.c +++ b/amiga/tree.c @@ -524,7 +524,7 @@ static void ami_tree_drag_end(struct treeview_window *twin, int x, int y) } } -static void ami_tree_scroller_hook(struct Hook *hook,Object *object,struct IntuiMessage *msg) +HOOKF(void, ami_tree_scroller_hook, Object *, object, struct IntuiMessage *) { ULONG gid; struct treeview_window *twin = hook->h_Data; -- cgit v1.2.3 From df25135a4d2007510b03487b517dad13b23f1a98 Mon Sep 17 00:00:00 2001 From: Chris Young Date: Sat, 28 Feb 2015 12:41:50 +0000 Subject: micro-optimisation --- amiga/font.c | 14 +++++++------- amiga/font_bitmap.c | 7 ++++--- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/amiga/font.c b/amiga/font.c index f930f77d6..1f3269e5c 100644 --- a/amiga/font.c +++ b/amiga/font.c @@ -549,7 +549,7 @@ static struct OutlineFont *ami_open_outline_font(const plot_font_style_t *fstyle return NULL; } -static int32 ami_font_plot_glyph(struct OutlineFont *ofont, struct RastPort *rp, +static inline int32 ami_font_plot_glyph(struct OutlineFont *ofont, struct RastPort *rp, uint16 *char1, uint16 *char2, uint32 x, uint32 y, uint32 emwidth, bool aa) { struct GlyphMap *glyph; @@ -562,12 +562,12 @@ static int32 ami_font_plot_glyph(struct OutlineFont *ofont, struct RastPort *rp, struct BulletBase *BulletBase = ofont->BulletBase; #endif - if ((*char1 >= 0xD800) && (*char1 <= 0xDBFF)) { + if (__builtin_expect(((*char1 >= 0xD800) && (*char1 <= 0xDBFF)), 0)) { /* We don't support UTF-16 surrogates yet, so just return. */ return 0; } - if ((*char2 >= 0xD800) && (*char2 <= 0xDBFF)) { + if (__builtin_expect(((*char2 >= 0xD800) && (*char2 <= 0xDBFF)), 0)) { /* Don't attempt to kern a UTF-16 surrogate */ *char2 = 0; } @@ -640,7 +640,7 @@ static int32 ami_font_plot_glyph(struct OutlineFont *ofont, struct RastPort *rp, return char_advance; } -static int32 ami_font_width_glyph(struct OutlineFont *ofont, +static inline int32 ami_font_width_glyph(struct OutlineFont *ofont, const uint16 *char1, const uint16 *char2, uint32 emwidth) { int32 char_advance = 0; @@ -653,12 +653,12 @@ static int32 ami_font_width_glyph(struct OutlineFont *ofont, struct BulletBase *BulletBase = ofont->BulletBase; #endif - if ((*char1 >= 0xD800) && (*char1 <= 0xDBFF)) { + if (__builtin_expect(((*char1 >= 0xD800) && (*char1 <= 0xDBFF)), 0)) { /* We don't support UTF-16 surrogates yet, so just return. */ return 0; } - - if ((*char2 >= 0xD800) && (*char2 <= 0xDBFF)) { + + if (__builtin_expect(((*char2 >= 0xD800) && (*char2 <= 0xDBFF)), 0)) { /* Don't attempt to kern a UTF-16 surrogate */ skip_c2 = true; } diff --git a/amiga/font_bitmap.c b/amiga/font_bitmap.c index 0b5b7ce85..8f142ae6b 100644 --- a/amiga/font_bitmap.c +++ b/amiga/font_bitmap.c @@ -202,11 +202,12 @@ bool amiga_bm_nsfont_split(const plot_font_style_t *fstyle, co--; } - *char_offset = co; - if(string && co) { + if(co > 0) { *actual_x = TextLength(glob->rp, string, co); + *char_offset = co; } else { - *actual_x = 0; + *actual_x = x; + *char_offset = length; } ami_font_bm_close(bmfont); -- cgit v1.2.3 From 947c466c4ba63ad84c0121453975a34935d0c1e8 Mon Sep 17 00:00:00 2001 From: Chris Young Date: Sat, 28 Feb 2015 13:01:16 +0000 Subject: Split plotting and widthing functions up --- amiga/font.c | 103 ++++++++++++++++++++++++++++++++++++++----------------- amiga/font.h | 2 +- amiga/plotters.c | 2 +- 3 files changed, 74 insertions(+), 33 deletions(-) diff --git a/amiga/font.c b/amiga/font.c index 1f3269e5c..32f12f272 100644 --- a/amiga/font.c +++ b/amiga/font.c @@ -152,20 +152,21 @@ lwc_string *glypharray[0xffff + 1]; ULONG ami_devicedpi; ULONG ami_xdpi; -static int32 ami_font_plot_glyph(struct OutlineFont *ofont, struct RastPort *rp, +static inline int32 ami_font_plot_glyph(struct OutlineFont *ofont, struct RastPort *rp, uint16 *char1, uint16 *char2, uint32 x, uint32 y, uint32 emwidth, bool aa); -static int32 ami_font_width_glyph(struct OutlineFont *ofont, +static inline int32 ami_font_width_glyph(struct OutlineFont *ofont, const uint16 *char1, const uint16 *char2, uint32 emwidth); static struct OutlineFont *ami_open_outline_font(const plot_font_style_t *fstyle, const uint16 *codepoint); static void ami_font_cleanup(struct MinList *ami_font_list); - +static inline ULONG ami_font_unicode_width(const char *string, ULONG length, + const plot_font_style_t *fstyle, ULONG x, ULONG y, bool aa); static inline bool amiga_nsfont_width(const plot_font_style_t *fstyle, const char *string, size_t length, int *width) { - *width = ami_unicode_text(NULL, string, length, fstyle, 0, 0, false); + *width = ami_font_unicode_width(string, length, fstyle, 0, 0, false); if(*width <= 0) *width == length; // fudge @@ -719,7 +720,7 @@ static const uint16 *ami_font_translate_smallcaps(uint16 *utf16char) return utf16char; } -ULONG ami_unicode_text(struct RastPort *rp, const char *string, ULONG length, +ULONG ami_font_unicode_text(struct RastPort *rp, const char *string, ULONG length, const plot_font_style_t *fstyle, ULONG dx, ULONG dy, bool aa) { uint16 *utf16 = NULL, *outf16 = NULL; @@ -733,6 +734,7 @@ ULONG ami_unicode_text(struct RastPort *rp, const char *string, ULONG length, if(!string || string[0]=='\0') return 0; if(!length) return 0; + if(rp == NULL) return 0; if(__builtin_expect(nsoption_bool(use_diskfont) == true, 0)) { return ami_font_bm_text(rp, string, length, fstyle, dx, dy); @@ -756,22 +758,14 @@ ULONG ami_unicode_text(struct RastPort *rp, const char *string, ULONG length, utf16charsc = (uint16 *)ami_font_translate_smallcaps(utf16); utf16nextsc = (uint16 *)ami_font_translate_smallcaps(utf16next); - if(rp) { - tempx = ami_font_plot_glyph(ofont, rp, utf16charsc, utf16nextsc, + tempx = ami_font_plot_glyph(ofont, rp, utf16charsc, utf16nextsc, dx + x, dy, emwidth, aa); - } else { - tempx = ami_font_width_glyph(ofont, utf16charsc, utf16nextsc, emwidth); - } } else tempx = 0; if(tempx == 0) { - if(rp) { - tempx = ami_font_plot_glyph(ofont, rp, utf16, utf16next, + tempx = ami_font_plot_glyph(ofont, rp, utf16, utf16next, dx + x, dy, emwidth, aa); - } else { - tempx = ami_font_width_glyph(ofont, utf16, utf16next, emwidth); - } } if(tempx == 0) @@ -781,26 +775,73 @@ ULONG ami_unicode_text(struct RastPort *rp, const char *string, ULONG length, ufont = ami_open_outline_font(fstyle, utf16); } - if(ufont) + if(ufont) { + tempx = ami_font_plot_glyph(ufont, rp, utf16, utf16next, + dx + x, dy, emwidth, aa); + } + } + + x += tempx; + + utf16 += utf16charlen; + } + + free(outf16); + return x; +} + +static inline ULONG ami_font_unicode_width(const char *string, ULONG length, + const plot_font_style_t *fstyle, ULONG dx, ULONG dy, bool aa) +{ + uint16 *utf16 = NULL, *outf16 = NULL; + uint16 *utf16charsc = 0, *utf16nextsc = 0; + uint16 *utf16next = 0; + int utf16charlen; + struct OutlineFont *ofont, *ufont = NULL; + uint32 x=0; + int32 tempx = 0; + ULONG emwidth = (ULONG)NSA_FONT_EMWIDTH(fstyle->size); + + if(!string || string[0]=='\0') return 0; + if(!length) return 0; + + if(utf8_to_enc(string,"UTF-16",length,(char **)&utf16) != NSERROR_OK) return 0; + outf16 = utf16; + if(!(ofont = ami_open_outline_font(fstyle, 0))) return 0; + + while(*utf16 != 0) + { + if ((*utf16 < 0xD800) || (0xDBFF < *utf16)) + utf16charlen = 1; + else + utf16charlen = 2; + + utf16next = &utf16[utf16charlen]; + + if(fstyle->flags & FONTF_SMALLCAPS) + { + utf16charsc = (uint16 *)ami_font_translate_smallcaps(utf16); + utf16nextsc = (uint16 *)ami_font_translate_smallcaps(utf16next); + + tempx = ami_font_width_glyph(ofont, utf16charsc, utf16nextsc, emwidth); + } + else tempx = 0; + + if(tempx == 0) { + tempx = ami_font_width_glyph(ofont, utf16, utf16next, emwidth); + } + + if(tempx == 0) + { + if(ufont == NULL) { - if(rp) { - tempx = ami_font_plot_glyph(ufont, rp, utf16, utf16next, - dx + x, dy, emwidth, aa); - } else { - tempx = ami_font_width_glyph(ufont, utf16, utf16next, emwidth); - } + ufont = ami_open_outline_font(fstyle, utf16); } -/* - if(tempx == 0) + + if(ufont) { - if(rp) { - tempx = ami_font_plot_glyph(ofont, rp, 0xfffd, utf16next, - dx + x, dy, emwidth, aa); - } else { - tempx = ami_font_width_glyph(ofont, 0xfffd, utf16next, emwidth); - } + tempx = ami_font_width_glyph(ufont, utf16, utf16next, emwidth); } -*/ } x += tempx; diff --git a/amiga/font.h b/amiga/font.h index 6c600abe4..375e15032 100755 --- a/amiga/font.h +++ b/amiga/font.h @@ -25,7 +25,7 @@ struct ami_font_node; -ULONG ami_unicode_text(struct RastPort *rp, const char *string, +ULONG ami_font_unicode_text(struct RastPort *rp, const char *string, ULONG length, const plot_font_style_t *fstyle, ULONG x, ULONG y, bool aa); void ami_font_setdevicedpi(int id); void ami_init_fonts(void); diff --git a/amiga/plotters.c b/amiga/plotters.c index 443077b58..660dea74d 100644 --- a/amiga/plotters.c +++ b/amiga/plotters.c @@ -414,7 +414,7 @@ static bool ami_text(int x, int y, const char *text, size_t length, aa = false; ami_plot_setapen(glob->rp, fstyle->foreground); - ami_unicode_text(glob->rp, text, length, fstyle, x, y, aa); + ami_font_unicode_text(glob->rp, text, length, fstyle, x, y, aa); return true; } -- cgit v1.2.3