From e71691bae890040b83cfd54a2d9a1097d5026866 Mon Sep 17 00:00:00 2001 From: John Mark Bell Date: Fri, 6 May 2011 20:40:09 +0000 Subject: Merge branches/jmb/content-factory to trunk svn path=/trunk/netsurf/; revision=12283 --- riscos/artworks.c | 220 ++++++++++++++++++++----- riscos/artworks.h | 26 ++- riscos/draw.c | 156 ++++++++++++++++-- riscos/draw.h | 20 +-- riscos/filetype.c | 92 ++++++----- riscos/gui.c | 11 ++ riscos/gui.h | 2 + riscos/gui/url_bar.c | 6 +- riscos/plugin.c | 444 +++++++++++++++++++++++++++++---------------------- riscos/plugin.h | 20 --- riscos/print.c | 15 +- riscos/save.c | 121 +++++--------- riscos/sprite.c | 148 +++++++++++++++-- riscos/sprite.h | 25 ++- riscos/treeview.c | 30 +--- riscos/window.c | 56 ++----- 16 files changed, 872 insertions(+), 520 deletions(-) (limited to 'riscos') diff --git a/riscos/artworks.c b/riscos/artworks.c index 45bba1a13..2be64a633 100644 --- a/riscos/artworks.c +++ b/riscos/artworks.c @@ -32,14 +32,15 @@ #include "oslib/os.h" #include "oslib/wimp.h" #include "utils/config.h" -#include "desktop/plotters.h" #include "content/content_protected.h" +#include "desktop/plotters.h" #include "riscos/artworks.h" #include "riscos/gui.h" #include "riscos/wimputils.h" -#include "utils/utils.h" -#include "utils/messages.h" #include "utils/log.h" +#include "utils/messages.h" +#include "utils/talloc.h" +#include "utils/utils.h" #define AWRender_FileInitAddress 0x46080 #define AWRender_RenderAddress 0x46081 @@ -53,6 +54,20 @@ #define INITIAL_BLOCK_SIZE 0x1000 +typedef struct artworks_content { + struct content base; + + int x0, y0, x1, y1; + + void *render_routine; + void *render_workspace; + + /* dynamically-resizable block required by + ArtWorksRenderer rendering routine */ + + void *block; + size_t size; +} artworks_content; struct awinfo_block { int ditherx; @@ -72,12 +87,12 @@ struct awinfo_block { /* Assembler routines for interfacing with the ArtworksRenderer module */ -os_error *awrender_init(const char **doc, +extern os_error *awrender_init(const char **doc, unsigned long *doc_size, void *routine, void *workspace); -os_error *awrender_render(const char *doc, +extern os_error *awrender_render(const char *doc, const struct awinfo_block *info, const os_trfm *trans, const int *vdu_vars, @@ -89,7 +104,105 @@ os_error *awrender_render(const char *doc, void *routine, void *workspace); +static nserror artworks_create(const content_handler *handler, + lwc_string *imime_type, const http_parameter *params, + llcache_handle *llcache, const char *fallback_charset, + bool quirks, struct content **c); +static bool artworks_convert(struct content *c); +static void artworks_destroy(struct content *c); +static bool artworks_redraw(struct content *c, int x, int y, + int width, int height, const struct rect *clip, + float scale, colour background_colour); +static nserror artworks_clone(const struct content *old, struct content **newc); +static content_type artworks_content_type(lwc_string *mime_type); + +static const content_handler artworks_content_handler = { + artworks_create, + NULL, + artworks_convert, + NULL, + artworks_destroy, + NULL, + NULL, + NULL, + artworks_redraw, + NULL, + NULL, + NULL, + artworks_clone, + NULL, + artworks_content_type, + false +}; +static const char *artworks_types[] = { + "image/x-artworks" +}; + +static lwc_string *artworks_mime_types[NOF_ELEMENTS(artworks_types)]; + +nserror artworks_init(void) +{ + uint32_t i; + lwc_error lerror; + nserror error; + + for (i = 0; i < NOF_ELEMENTS(artworks_mime_types); i++) { + lerror = lwc_intern_string(artworks_types[i], + strlen(artworks_types[i]), + &artworks_mime_types[i]); + if (lerror != lwc_error_ok) { + error = NSERROR_NOMEM; + goto error; + } + + error = content_factory_register_handler(artworks_mime_types[i], + &artworks_content_handler); + if (error != NSERROR_OK) + goto error; + } + + return NSERROR_OK; + +error: + artworks_fini(); + + return error; +} + +void artworks_fini(void) +{ + uint32_t i; + + for (i = 0; i < NOF_ELEMENTS(artworks_mime_types); i++) { + if (artworks_mime_types[i] != NULL) + lwc_string_unref(artworks_mime_types[i]); + } +} + +nserror artworks_create(const content_handler *handler, + lwc_string *imime_type, const http_parameter *params, + llcache_handle *llcache, const char *fallback_charset, + bool quirks, struct content **c) +{ + artworks_content *aw; + nserror error; + + aw = talloc_zero(0, artworks_content); + if (aw == NULL) + return NSERROR_NOMEM; + + error = content__init(&aw->base, handler, imime_type, params, + llcache, fallback_charset, quirks); + if (error != NSERROR_OK) { + talloc_free(aw); + return error; + } + + *c = (struct content *) aw; + + return NSERROR_OK; +} /** * Convert a CONTENT_ARTWORKS for display. @@ -100,6 +213,7 @@ os_error *awrender_render(const char *doc, bool artworks_convert(struct content *c) { + artworks_content *aw = (artworks_content *) c; union content_msg_data msg_data; const char *source_data; unsigned long source_size; @@ -142,8 +256,8 @@ bool artworks_convert(struct content *c) } error = (os_error*)_swix(AWRender_RenderAddress, _OUT(0) | _OUT(1), - &c->data.artworks.render_routine, - &c->data.artworks.render_workspace); + &aw->render_routine, + &aw->render_workspace); if (error) { LOG(("AWRender_RenderAddress: 0x%x: %s", error->errnum, error->errmess)); @@ -165,12 +279,13 @@ bool artworks_convert(struct content *c) return false; } - error = (os_error*)_swix(AWRender_DocBounds, _IN(0) | _OUT(2) | _OUT(3) | _OUT(4) | _OUT(5), + error = (os_error*)_swix(AWRender_DocBounds, + _IN(0) | _OUT(2) | _OUT(3) | _OUT(4) | _OUT(5), source_data, - &c->data.artworks.x0, - &c->data.artworks.y0, - &c->data.artworks.x1, - &c->data.artworks.y1); + &aw->x0, + &aw->y0, + &aw->x1, + &aw->y1); if (error) { LOG(("AWRender_DocBounds: 0x%x: %s", @@ -180,24 +295,22 @@ bool artworks_convert(struct content *c) return false; } - LOG(("bounding box: %d,%d,%d,%d", - c->data.artworks.x0, c->data.artworks.y0, - c->data.artworks.x1, c->data.artworks.y1)); + LOG(("bounding box: %d,%d,%d,%d", aw->x0, aw->y0, aw->x1, aw->y1)); /* create the resizable workspace required by the ArtWorksRenderer rendering routine */ - c->data.artworks.size = INITIAL_BLOCK_SIZE; - c->data.artworks.block = malloc(INITIAL_BLOCK_SIZE); - if (!c->data.artworks.block) { + aw->size = INITIAL_BLOCK_SIZE; + aw->block = malloc(INITIAL_BLOCK_SIZE); + if (!aw->block) { LOG(("failed to create block for ArtworksRenderer")); msg_data.error = messages_get("NoMemory"); content_broadcast(c, CONTENT_MSG_ERROR, msg_data); return false; } - c->width = (c->data.artworks.x1 - c->data.artworks.x0) / 512; - c->height = (c->data.artworks.y1 - c->data.artworks.y0) / 512; + c->width = (aw->x1 - aw->x0) / 512; + c->height = (aw->y1 - aw->y0) / 512; snprintf(title, sizeof(title), messages_get("ArtWorksTitle"), c->width, c->height, source_size); @@ -216,7 +329,9 @@ bool artworks_convert(struct content *c) void artworks_destroy(struct content *c) { - free(c->data.artworks.block); + artworks_content *aw = (artworks_content *) c; + + free(aw->block); } @@ -236,6 +351,7 @@ bool artworks_redraw(struct content *c, int x, int y, os_VDUVAR_END_LIST } }; + artworks_content *aw = (artworks_content *) c; struct awinfo_block info; const char *source_data; unsigned long source_size; @@ -254,8 +370,8 @@ bool artworks_redraw(struct content *c, int x, int y, /* pick up render addresses again in case they've changed (eg. newer AWRender module loaded since we first loaded this file) */ (void)_swix(AWRender_RenderAddress, _OUT(0) | _OUT(1), - &c->data.artworks.render_routine, - &c->data.artworks.render_workspace); + &aw->render_routine, + &aw->render_workspace); /* Scaled image. Transform units (65536*OS units) */ matrix.entries[0][0] = width * 65536 / c->width; @@ -264,9 +380,9 @@ bool artworks_redraw(struct content *c, int x, int y, matrix.entries[1][1] = height * 65536 / c->height; /* Draw units. (x,y) = bottom left */ matrix.entries[2][0] = ro_plot_origin_x * 256 + x * 512 - - c->data.artworks.x0 * width / c->width; + aw->x0 * width / c->width; matrix.entries[2][1] = ro_plot_origin_y * 256 - (y + height) * 512 - - c->data.artworks.y0 * height / c->height; + aw->y0 * height / c->height; info.ditherx = ro_plot_origin_x; info.dithery = ro_plot_origin_y; @@ -277,16 +393,16 @@ bool artworks_redraw(struct content *c, int x, int y, clip_y1 -= y; if (scale == 1.0) { - info.clip_x0 = (clip_x0 * 512) + c->data.artworks.x0 - 511; - info.clip_y0 = ((c->height - clip_y1) * 512) + c->data.artworks.y0 - 511; - info.clip_x1 = (clip_x1 * 512) + c->data.artworks.x0 + 511; - info.clip_y1 = ((c->height - clip_y0) * 512) + c->data.artworks.y0 + 511; + info.clip_x0 = (clip_x0 * 512) + aw->x0 - 511; + info.clip_y0 = ((c->height - clip_y1) * 512) + aw->y0 - 511; + info.clip_x1 = (clip_x1 * 512) + aw->x0 + 511; + info.clip_y1 = ((c->height - clip_y0) * 512) + aw->y0 + 511; } else { - info.clip_x0 = (clip_x0 * 512 / scale) + c->data.artworks.x0 - 511; - info.clip_y0 = ((c->height - (clip_y1 / scale)) * 512) + c->data.artworks.y0 - 511; - info.clip_x1 = (clip_x1 * 512 / scale) + c->data.artworks.x0 + 511; - info.clip_y1 = ((c->height - (clip_y0 / scale)) * 512) + c->data.artworks.y0 + 511; + info.clip_x0 = (clip_x0 * 512 / scale) + aw->x0 - 511; + info.clip_y0 = ((c->height - (clip_y1 / scale)) * 512) + aw->y0 - 511; + info.clip_x1 = (clip_x1 * 512 / scale) + aw->x0 + 511; + info.clip_y1 = ((c->height - (clip_y0 / scale)) * 512) + aw->y0 + 511; } info.print_lowx = 0; @@ -314,13 +430,13 @@ bool artworks_redraw(struct content *c, int x, int y, &info, &matrix, vals, - &c->data.artworks.block, - &c->data.artworks.size, + &aw->block, + &aw->size, 110, /* fully anti-aliased */ 0, source_size, - c->data.artworks.render_routine, - c->data.artworks.render_workspace); + aw->render_routine, + aw->render_workspace); if (error) { LOG(("awrender_render: 0x%x: %s", @@ -331,16 +447,38 @@ bool artworks_redraw(struct content *c, int x, int y, return true; } -bool artworks_clone(const struct content *old, struct content *new_content) +nserror artworks_clone(const struct content *old, struct content **newc) { + artworks_content *aw; + nserror error; + + aw = talloc_zero(0, artworks_content); + if (aw == NULL) + return NSERROR_NOMEM; + + error = content__clone(old, &aw->base); + if (error != NSERROR_OK) { + content_destroy(&aw->base); + return error; + } + /* Simply re-run convert */ if (old->status == CONTENT_STATUS_READY || old->status == CONTENT_STATUS_DONE) { - if (artworks_convert(new_content) == false) - return false; + if (artworks_convert(&aw->base) == false) { + content_destroy(&aw->base); + return NSERROR_CLONE_FAILED; + } } - return true; + *newc = (struct content *) aw; + + return NSERROR_OK; +} + +content_type artworks_content_type(lwc_string *mime_type) +{ + return CONTENT_IMAGE; } #endif diff --git a/riscos/artworks.h b/riscos/artworks.h index 5acd463ee..4a339cc84 100644 --- a/riscos/artworks.h +++ b/riscos/artworks.h @@ -23,27 +23,19 @@ #ifndef _NETSURF_RISCOS_ARTWORKS_H_ #define _NETSURF_RISCOS_ARTWORKS_H_ -struct content; -struct rect; +#include "utils/config.h" +#include "utils/errors.h" -struct content_artworks_data { - int x0, y0, x1, y1; +#ifdef WITH_ARTWORKS - void *render_routine; - void *render_workspace; +nserror artworks_init(void); +void artworks_fini(void); - /* dunamically-resizable block required by - ArtWorksRenderer rendering routine */ +#else - void *block; - size_t size; -}; +#define artworks_init() NSERROR_OK +#define artworks_fini() ((void) 0) -bool artworks_convert(struct content *c); -void artworks_destroy(struct content *c); -bool artworks_redraw(struct content *c, int x, int y, - int width, int height, const struct rect *clip, - float scale, colour background_colour); -bool artworks_clone(const struct content *old, struct content *new_content); +#endif #endif diff --git a/riscos/draw.c b/riscos/draw.c index 76bda452f..d2773439a 100644 --- a/riscos/draw.c +++ b/riscos/draw.c @@ -29,13 +29,123 @@ #include #include "oslib/drawfile.h" #include "utils/config.h" -#include "desktop/plotters.h" #include "content/content_protected.h" +#include "desktop/plotters.h" #include "riscos/draw.h" #include "riscos/gui.h" -#include "utils/utils.h" -#include "utils/messages.h" #include "utils/log.h" +#include "utils/messages.h" +#include "utils/talloc.h" +#include "utils/utils.h" + +typedef struct draw_content { + struct content base; + + int x0, y0; +} draw_content; + +static nserror draw_create(const content_handler *handler, + lwc_string *imime_type, const http_parameter *params, + llcache_handle *llcache, const char *fallback_charset, + bool quirks, struct content **c); +static bool draw_convert(struct content *c); +static void draw_destroy(struct content *c); +static bool draw_redraw(struct content *c, int x, int y, + int width, int height, const struct rect *clip, + float scale, colour background_colour); +static nserror draw_clone(const struct content *old, struct content **newc); +static content_type draw_content_type(lwc_string *mime_type); + +static const content_handler draw_content_handler = { + draw_create, + NULL, + draw_convert, + NULL, + draw_destroy, + NULL, + NULL, + NULL, + draw_redraw, + NULL, + NULL, + NULL, + draw_clone, + NULL, + draw_content_type, + false +}; + +static const char *draw_types[] = { + "application/drawfile", + "application/x-drawfile", + "image/drawfile", + "image/x-drawfile" +}; + +static lwc_string *draw_mime_types[NOF_ELEMENTS(draw_types)]; + +nserror draw_init(void) +{ + uint32_t i; + lwc_error lerror; + nserror error; + + for (i = 0; i < NOF_ELEMENTS(draw_mime_types); i++) { + lerror = lwc_intern_string(draw_types[i], + strlen(draw_types[i]), + &draw_mime_types[i]); + if (lerror != lwc_error_ok) { + error = NSERROR_NOMEM; + goto error; + } + + error = content_factory_register_handler(draw_mime_types[i], + &draw_content_handler); + if (error != NSERROR_OK) + goto error; + } + + return NSERROR_OK; + +error: + draw_fini(); + + return error; +} + +void draw_fini(void) +{ + uint32_t i; + + for (i = 0; i < NOF_ELEMENTS(draw_mime_types); i++) { + if (draw_mime_types[i] != NULL) + lwc_string_unref(draw_mime_types[i]); + } +} + +nserror draw_create(const content_handler *handler, + lwc_string *imime_type, const http_parameter *params, + llcache_handle *llcache, const char *fallback_charset, + bool quirks, struct content **c) +{ + draw_content *draw; + nserror error; + + draw = talloc_zero(0, draw_content); + if (draw == NULL) + return NSERROR_NOMEM; + + error = content__init(&draw->base, handler, imime_type, params, + llcache, fallback_charset, quirks); + if (error != NSERROR_OK) { + talloc_free(draw); + return error; + } + + *c = (struct content *) draw; + + return NSERROR_OK; +} /** * Convert a CONTENT_DRAW for display. @@ -46,6 +156,7 @@ bool draw_convert(struct content *c) { + draw_content *draw = (draw_content *) c; union content_msg_data msg_data; const char *source_data; unsigned long source_size; @@ -78,8 +189,8 @@ bool draw_convert(struct content *c) /* invalid/undefined bounding box */ c->height = c->width = 0; - c->data.draw.x0 = bbox.x0; - c->data.draw.y0 = bbox.y0; + draw->x0 = bbox.x0; + draw->y0 = bbox.y0; snprintf(title, sizeof(title), messages_get("DrawTitle"), c->width, c->height, source_size); content__set_title(c, title); @@ -109,6 +220,7 @@ bool draw_redraw(struct content *c, int x, int y, int width, int height, const struct rect *clip, float scale, colour background_colour) { + draw_content *draw = (draw_content *) c; os_trfm matrix; const char *source_data; unsigned long source_size; @@ -131,9 +243,9 @@ bool draw_redraw(struct content *c, int x, int y, matrix.entries[1][1] = height * 65536 / c->height; /* Draw units. (x,y) = bottom left */ matrix.entries[2][0] = ro_plot_origin_x * 256 + x * 512 - - c->data.draw.x0 * width / c->width; + draw->x0 * width / c->width; matrix.entries[2][1] = ro_plot_origin_y * 256 - (y + height) * 512 - - c->data.draw.y0 * height / c->height; + draw->y0 * height / c->height; error = xdrawfile_render(0, (drawfile_diagram *) data, (int) source_size, &matrix, 0, 0); @@ -150,16 +262,38 @@ bool draw_redraw(struct content *c, int x, int y, * Clone a CONTENT_DRAW */ -bool draw_clone(const struct content *old, struct content *new_content) +nserror draw_clone(const struct content *old, struct content **newc) { + draw_content *draw; + nserror error; + + draw = talloc_zero(0, draw_content); + if (draw == NULL) + return NSERROR_NOMEM; + + error = content__clone(old, &draw->base); + if (error != NSERROR_OK) { + content_destroy(&draw->base); + return error; + } + /* Simply rerun convert */ if (old->status == CONTENT_STATUS_READY || old->status == CONTENT_STATUS_DONE) { - if (draw_convert(new_content) == false) - return false; + if (draw_convert(&draw->base) == false) { + content_destroy(&draw->base); + return NSERROR_CLONE_FAILED; + } } - return true; + *newc = (struct content *) draw; + + return NSERROR_OK; +} + +content_type draw_content_type(lwc_string *mime_type) +{ + return CONTENT_IMAGE; } #endif diff --git a/riscos/draw.h b/riscos/draw.h index f7a014844..a0843202a 100644 --- a/riscos/draw.h +++ b/riscos/draw.h @@ -24,23 +24,17 @@ #define _NETSURF_RISCOS_DRAW_H_ #include "utils/config.h" -#ifdef WITH_DRAW +#include "utils/errors.h" -#include +#ifdef WITH_DRAW -struct content; -struct rect; +nserror draw_init(void); +void draw_fini(void); -struct content_draw_data { - int x0, y0; -}; +#else -bool draw_convert(struct content *c); -void draw_destroy(struct content *c); -bool draw_redraw(struct content *c, int x, int y, - int width, int height, const struct rect *clip, - float scale, colour background_colour); -bool draw_clone(const struct content *old, struct content *new_content); +#define draw_init() NSERROR_OK +#define draw_fini() ((void) 0) #endif /* WITH_DRAW */ diff --git a/riscos/filetype.c b/riscos/filetype.c index 2c8ac76d9..5c539a1d6 100644 --- a/riscos/filetype.c +++ b/riscos/filetype.c @@ -253,22 +253,69 @@ int cmp_type(const void *x, const void *y) */ int ro_content_filetype(hlcache_handle *c) { + lwc_string *mime_type; int file_type; - os_error *error; file_type = ro_content_filetype_from_type(content_get_type(c)); if (file_type != 0) return file_type; + mime_type = content_get_mime_type(c); + + file_type = ro_content_filetype_from_mime_type(mime_type); + + lwc_string_unref(mime_type); + + return file_type; +} + +/** + * Determine the native RISC OS filetype to export a content as + * + * \param c The content to examine + * \return Native RISC OS filetype for export + */ +int ro_content_native_type(hlcache_handle *c) +{ + switch (ro_content_filetype(c)) { + case 0xc85: /* jpeg */ + case 0xf78: /* jng */ + case 0xf83: /* mng */ + case 0x695: /* gif */ + case 0x69c: /* bmp */ + case 0x132: /* ico */ + case 0xb90: /* png */ + case 0xff9: /* sprite */ + return osfile_TYPE_SPRITE; + case 0xaad: /* svg */ + case 0xaff: /* draw */ + return osfile_TYPE_DRAW; + default: + break; + } + + return osfile_TYPE_DATA; +} + +/** + * Determine the RISC OS filetype for a MIME type + * + * \param mime_type MIME type to consider + * \return Corresponding RISC OS filetype + */ +int ro_content_filetype_from_mime_type(lwc_string *mime_type) +{ + int file_type; + os_error *error; + error = xmimemaptranslate_mime_type_to_filetype( - content_get_mime_type(c), (bits *) &file_type); + lwc_string_data(mime_type), (bits *) &file_type); if (error) - return 0xffd; + file_type = 0xffd; return file_type; } - /** * Determine the RISC OS filetype from a content type. * @@ -277,39 +324,10 @@ int ro_content_filetype(hlcache_handle *c) */ int ro_content_filetype_from_type(content_type type) { switch (type) { - case CONTENT_HTML: return 0xfaf; - case CONTENT_TEXTPLAIN: return 0xfff; - case CONTENT_CSS: return 0xf79; -#if defined(WITH_MNG) || defined(WITH_PNG) - case CONTENT_PNG: return 0xb60; -#endif -#ifdef WITH_MNG - case CONTENT_JNG: return 0xf78; - case CONTENT_MNG: return 0xf84; -#endif -#ifdef WITH_JPEG - case CONTENT_JPEG: return 0xc85; -#endif -#ifdef WITH_GIF - case CONTENT_GIF: return 0x695; -#endif -#ifdef WITH_BMP - case CONTENT_BMP: return 0x69c; - case CONTENT_ICO: return 0x132; -#endif -#ifdef WITH_SPRITE - case CONTENT_SPRITE: return 0xff9; -#endif -#ifdef WITH_DRAW - case CONTENT_DRAW: return 0xaff; -#endif -#ifdef WITH_ARTWORKS - case CONTENT_ARTWORKS: return 0xd94; -#endif -#ifdef WITH_NS_SVG - case CONTENT_SVG: return 0xaad; -#endif - default: break; + case CONTENT_HTML: return 0xfaf; + case CONTENT_TEXTPLAIN: return 0xfff; + case CONTENT_CSS: return 0xf79; + default: break; } return 0; } diff --git a/riscos/gui.c b/riscos/gui.c index 230d30db2..9d162f6f5 100644 --- a/riscos/gui.c +++ b/riscos/gui.c @@ -67,10 +67,12 @@ #include "render/box.h" #include "render/font.h" #include "render/html.h" +#include "riscos/artworks.h" #include "riscos/bitmap.h" #include "riscos/buffer.h" #include "riscos/cookies.h" #include "riscos/dialog.h" +#include "riscos/draw.h" #include "riscos/global_history.h" #include "riscos/gui.h" #include "riscos/help.h" @@ -86,6 +88,7 @@ #include "riscos/query.h" #include "riscos/save.h" #include "riscos/sslcert.h" +#include "riscos/sprite.h" #include "riscos/system_colour.h" #include "riscos/textselection.h" #include "riscos/theme.h" @@ -774,6 +777,10 @@ int main(int argc, char** argv) netsurf_init(&argc, &argv, "NetSurf:Choices", NULL); + artworks_init(); + draw_init(); + sprite_init(); + /* Choose the interface language to use */ ro_gui_choose_language(); @@ -793,6 +800,10 @@ int main(int argc, char** argv) netsurf_exit(); + sprite_fini(); + draw_fini(); + artworks_fini(); + return 0; } diff --git a/riscos/gui.h b/riscos/gui.h index dcfb6a0ce..d64764c2d 100644 --- a/riscos/gui.h +++ b/riscos/gui.h @@ -171,6 +171,8 @@ void ro_gui_history_mouse_at(wimp_pointer *pointer); /* in filetype.c */ int ro_content_filetype(struct hlcache_handle *c); +int ro_content_native_type(struct hlcache_handle *c); +int ro_content_filetype_from_mime_type(lwc_string *mime_type); int ro_content_filetype_from_type(content_type type); bits ro_filetype_from_unix_path(const char *unix_path); diff --git a/riscos/gui/url_bar.c b/riscos/gui/url_bar.c index 4a3b4b232..aadc0e36f 100644 --- a/riscos/gui/url_bar.c +++ b/riscos/gui/url_bar.c @@ -875,7 +875,7 @@ bool ro_gui_url_bar_test_for_text_field_keypress(struct url_bar *url_bar, bool ro_gui_url_bar_set_site_favicon(struct url_bar *url_bar, struct hlcache_handle *h) { - content_type type = CONTENT_OTHER; + content_type type = CONTENT_NONE; if (url_bar == NULL) return false; @@ -885,7 +885,7 @@ bool ro_gui_url_bar_set_site_favicon(struct url_bar *url_bar, // \TODO -- Maybe test for CONTENT_ICO ??? - if (type != CONTENT_OTHER && type != CONTENT_UNKNOWN) { + if (type == CONTENT_IMAGE) { url_bar->favicon_content = h; url_bar->favicon_width = content_get_width(h); url_bar->favicon_height = content_get_height(h); @@ -938,7 +938,7 @@ bool ro_gui_url_bar_set_content_favicon(struct url_bar *url_bar, return false; if (h != NULL) - type = ro_content_filetype_from_type(content_get_type(h)); + type = ro_content_filetype(h); if (type != 0) { snprintf(sprite, URLBAR_FAVICON_NAME_LENGTH, diff --git a/riscos/plugin.c b/riscos/plugin.c index b70083831..d39944d07 100644 --- a/riscos/plugin.c +++ b/riscos/plugin.c @@ -53,9 +53,8 @@ #include "oslib/plugin.h" #include "oslib/wimp.h" #include "utils/config.h" -#include "content/content.h" +#include "content/content_protected.h" #include "content/fetch.h" -#include "content/fetchcache.h" #include "desktop/browser.h" #include "desktop/gui.h" #include "render/html.h" @@ -66,9 +65,31 @@ #include "riscos/toolbar.h" #include "utils/log.h" #include "utils/messages.h" +#include "utils/schedule.h" +#include "utils/talloc.h" #include "utils/url.h" #include "utils/utils.h" +struct plugin_stream; + +/* We have one content per instance of a plugin */ +typedef struct plugin_content { + struct content base; + + struct browser_window *bw; /* window containing this content */ + struct content *page; /* parent content */ + struct box *box; /* box containing this content */ + char *taskname; /* plugin task to launch */ + char *filename; /* filename of parameters file */ + bool opened; /* has this plugin been opened? */ + int repeated; /* indication of opening state */ + unsigned int browser; /* browser handle */ + unsigned int plugin; /* plugin handle */ + unsigned int plugin_task; /* plugin task handle */ + bool reformat_pending; /* is a reformat pending? */ + int width, height; /* reformat width & height */ + struct plugin_stream *streams; /* list of active streams */ +} plugin_content; typedef enum { PLUGIN_PARAMETER_DATA = 1, @@ -96,8 +117,8 @@ struct plugin_param_item { struct plugin_stream { struct plugin_stream *next; /* next in list */ - struct content *plugin; /* the plugin content */ - struct content *c; /* the content being fetched for + plugin_content *plugin; /* the plugin content */ + plugin_content *c; /* the content being fetched for * this stream (may be the same as * plugin iff we've been asked to * fetch the data resource for the @@ -148,9 +169,26 @@ struct plugin_stream { #define HELPER_PREFIX "Alias$@HelperType_" #define SYSVAR_BUF_SIZE (25) /* size of buffer to hold system variable */ -static bool plugin_create_sysvar(const char *mime_type, char* sysvar, +static nserror plugin_create(const content_handler *handler, + lwc_string *imime_type, const http_parameter *params, + llcache_handle *llcache, const char *fallback_charset, + bool quirks, struct content **c); +static nserror plugin_create_plugin_data(plugin_content *c); +static bool plugin_convert(struct content *c); +static void plugin_reformat(struct content *c, int width, int height); +static void plugin_destroy(struct content *c); +static bool plugin_redraw(struct content *c, int x, int y, + int width, int height, const struct rect *clip, + float scale, colour background_colour); +static void plugin_open(struct content *c, struct browser_window *bw, + struct content *page, struct box *box, + struct object_params *params); +static void plugin_close(struct content *c); +static nserror plugin_clone(const struct content *old, struct content **newc); + +static bool plugin_create_sysvar(lwc_string *mime_type, char *sysvar, bool helper); -static void plugin_create_stream(struct content *plugin, struct content *c, +static void plugin_create_stream(plugin_content *plugin, plugin_content *c, const char *url); static bool plugin_send_stream_new(struct plugin_stream *p); static void plugin_write_stream(struct plugin_stream *p, @@ -160,7 +198,7 @@ static void plugin_stream_as_file_callback(void *p); static void plugin_write_stream_as_file(struct plugin_stream *p); static void plugin_destroy_stream(struct plugin_stream *p, plugin_stream_destroy_reason reason); -static bool plugin_write_parameters_file(struct content *c, +static bool plugin_write_parameters_file(plugin_content *c, struct object_params *params, const char *base); static int plugin_calculate_rsize(const char* name, const char* data, const char* mime); @@ -176,32 +214,61 @@ static void plugin_stream_callback(content_msg msg, struct content *c, static void plugin_fetch_callback(fetch_msg msg, void *p, const void *data, unsigned long size); +nserror plugin_create(const content_handler *handler, + lwc_string *imime_type, const http_parameter *params, + llcache_handle *llcache, const char *fallback_charset, + bool quirks, struct content **c) +{ + plugin_content *plugin; + nserror error; + + plugin = talloc_zero(0, plugin_content); + if (plugin == NULL) + return NSERROR_NOMEM; + + error = content__init(&plugin->base, handler, imime_type, params, + llcache, fallback_charset, quirks); + if (error != NSERROR_OK) { + talloc_free(plugin); + return error; + } + + error = plugin_create_plugin_data(plugin); + if (error != NSERROR_OK) { + talloc_free(plugin); + return error; + } + + *c = (struct content *) plugin; + + return NSERROR_OK; +} + /** * Initialises plugin system in readiness for receiving object data * * \param c The content to hold the data - * \param params Parameters associated with the content - * \return true on success, false otherwise + * \return NSERROR_OK on success, appropriate error otherwise */ -bool plugin_create(struct content *c, const http_parameter *params) +nserror plugin_create_plugin_data(plugin_content *c) { LOG(("plugin_create")); - c->data.plugin.bw = 0; - c->data.plugin.page = 0; - c->data.plugin.box = 0; - c->data.plugin.taskname = 0; - c->data.plugin.filename = 0; - c->data.plugin.opened = false; - c->data.plugin.repeated = 0; - c->data.plugin.browser = 0; - c->data.plugin.plugin = 0; - c->data.plugin.plugin_task = 0; - c->data.plugin.reformat_pending = false; - c->data.plugin.width = 0; - c->data.plugin.height = 0; - c->data.plugin.streams = 0; - - return true; + c->bw = 0; + c->page = 0; + c->box = 0; + c->taskname = 0; + c->filename = 0; + c->opened = false; + c->repeated = 0; + c->browser = 0; + c->plugin = 0; + c->plugin_task = 0; + c->reformat_pending = false; + c->width = 0; + c->height = 0; + c->streams = 0; + + return NSERROR_OK; } /** @@ -229,11 +296,13 @@ bool plugin_convert(struct content *c) */ void plugin_destroy(struct content *c) { + plugin_content *plugin = (plugin_content *) c; + LOG(("plugin_destroy")); - if (c->data.plugin.taskname) - free(c->data.plugin.taskname); - if (c->data.plugin.filename) - free(c->data.plugin.filename); + if (plugin->taskname) + free(plugin->taskname); + if (plugin->filename) + free(plugin->filename); } /** @@ -271,6 +340,7 @@ void plugin_open(struct content *c, struct browser_window *bw, struct content *page, struct box *box, struct object_params *params) { + plugin_content *plugin = (plugin_content *) c; bool standalone = false, helper = false; const char *base; char sysvar[SYSVAR_BUF_SIZE]; @@ -278,10 +348,13 @@ void plugin_open(struct content *c, struct browser_window *bw, plugin_full_message_open pmo; wimp_window_state state; os_error *error; + lwc_string *mime_type; if (option_no_plugins) return; + mime_type = content__get_mime_type(c); + if (!params) { /* this is a standalone plugin, so fudge the parameters */ params = calloc(1, sizeof(struct object_params)); @@ -290,12 +363,14 @@ void plugin_open(struct content *c, struct browser_window *bw, goto error; } - params->data = strdup(c->url); + params->data = strdup(content__get_url(c)); if (!params->data) { warn_user("NoMemory", 0); goto error; } - params->type = strdup(c->mime_type); + + params->type = strndup(lwc_string_data(mime_type), + lwc_string_length(mime_type)); if (!params->type) { warn_user("NoMemory", 0); goto error; @@ -305,9 +380,9 @@ void plugin_open(struct content *c, struct browser_window *bw, /* we only do this here because the box is needed by * write_parameters_file. Ideally it would be at the - * end of this function with the other writes to c->data.plugin + * end of this function with the other writes to plugin */ - c->data.plugin.box = box; + plugin->box = box; if (params->codebase) base = params->codebase; @@ -317,11 +392,11 @@ void plugin_open(struct content *c, struct browser_window *bw, base = c->url; LOG(("writing parameters file")); - if (!plugin_write_parameters_file(c, params, base)) + if (!plugin_write_parameters_file(plugin, params, base)) goto error; /* get contents of Alias$@PlugInType_xxx variable */ - if (!plugin_create_sysvar(c->mime_type, sysvar, false)) + if (!plugin_create_sysvar(mime_type, sysvar, false)) goto error; varval = getenv(sysvar); @@ -340,14 +415,14 @@ void plugin_open(struct content *c, struct browser_window *bw, } /* The browser instance handle is the content struct pointer */ - c->data.plugin.browser = (unsigned int)c; + plugin->browser = (unsigned int)c; pmo.size = 60; pmo.your_ref = 0; pmo.action = message_PLUG_IN_OPEN; pmo.flags = helper ? plugin_OPEN_AS_HELPER : 0; pmo.reserved = 0; - pmo.browser = (plugin_b)c->data.plugin.browser; + pmo.browser = (plugin_b)plugin->browser; pmo.parent_window = bw->window->window; /* initial position/dimensions */ @@ -371,14 +446,14 @@ void plugin_open(struct content *c, struct browser_window *bw, pmo.bbox.y1 = 100; } - error = xmimemaptranslate_mime_type_to_filetype(c->mime_type, - &pmo.file_type); + error = xmimemaptranslate_mime_type_to_filetype( + lwc_string_data(mime_type), &pmo.file_type); if (error) { goto error; } - pmo.filename.pointer = c->data.plugin.filename; + pmo.filename.pointer = plugin->filename; - c->data.plugin.repeated = 0; + plugin->repeated = 0; LOG(("sending message")); error = xwimp_send_message(wimp_USER_MESSAGE_RECORDED, @@ -389,9 +464,9 @@ void plugin_open(struct content *c, struct browser_window *bw, goto error; } - c->data.plugin.bw = bw; - c->data.plugin.page = page; - c->data.plugin.taskname = strdup(varval); + plugin->bw = bw; + plugin->page = page; + plugin->taskname = strdup(varval); error: /* clean up standalone stuff */ @@ -401,6 +476,8 @@ error: free(params); } + lwc_string_unref(mime_type); + LOG(("done")); } @@ -412,17 +489,18 @@ error: */ void plugin_close(struct content *c) { + plugin_content *plugin = (plugin_content *) c; struct plugin_stream *p, *q; plugin_full_message_close pmc; os_error *error; LOG(("plugin_close")); - if (!plugin_active(c) || !c->data.plugin.opened) + if (!plugin_active(c) || !plugin->opened) return; /* destroy all active streams */ - for (p = c->data.plugin.streams; p; p = q) { + for (p = plugin->streams; p; p = q) { q = p->next; plugin_destroy_stream(p, plugin_STREAM_DESTROY_USER_REQUEST); @@ -432,18 +510,18 @@ void plugin_close(struct content *c) pmc.your_ref = 0; pmc.action = message_PLUG_IN_CLOSE; pmc.flags = 0; - pmc.browser = (plugin_b)c->data.plugin.browser; - pmc.plugin = (plugin_p)c->data.plugin.plugin; + pmc.browser = (plugin_b)plugin->browser; + pmc.plugin = (plugin_p)plugin->plugin; LOG(("sending message")); error = xwimp_send_message(wimp_USER_MESSAGE_RECORDED, - (wimp_message *)&pmc, (wimp_t)c->data.plugin.plugin_task); + (wimp_message *)&pmc, (wimp_t)plugin->plugin_task); if (error) { return; } /* delete any temporary files */ - for (p = c->data.plugin.streams; p; p = q) { + for (p = plugin->streams; p; p = q) { q = p->next; assert(p->type == AS_FILE); @@ -458,7 +536,7 @@ void plugin_close(struct content *c) } /* paranoia */ - c->data.plugin.streams = 0; + plugin->streams = 0; } /** @@ -470,6 +548,7 @@ void plugin_close(struct content *c) */ void plugin_reformat(struct content *c, int width, int height) { + plugin_content *plugin = (plugin_content *) c; plugin_full_message_reshape pmr; int x, y; os_error *error; @@ -480,26 +559,26 @@ void plugin_reformat(struct content *c, int width, int height) return; /* if the plugin hasn't yet been opened, queue the reformat */ - if (!c->data.plugin.opened) { + if (!plugin->opened) { LOG(("queuing")); - c->data.plugin.reformat_pending = true; - c->data.plugin.width = width; - c->data.plugin.height = height; + plugin->reformat_pending = true; + plugin->width = width; + plugin->height = height; return; } - c->data.plugin.reformat_pending = false; + plugin->reformat_pending = false; /* top left of plugin area, relative to top left of browser window */ - if (c->data.plugin.box) { - box_coords(c->data.plugin.box, &x, &y); + if (plugin->box) { + box_coords(plugin->box, &x, &y); } else { /* standalone */ x = 10 / 2; /* avoid toolbar */ y = (10 + ro_toolbar_height( - c->data.plugin.bw->window->toolbar0)) / 2; + plugin->bw->window->toolbar)) / 2; } pmr.size = 52; @@ -507,15 +586,15 @@ void plugin_reformat(struct content *c, int width, int height) pmr.action = message_PLUG_IN_RESHAPE; pmr.flags = 0; - pmr.plugin = (plugin_p)c->data.plugin.plugin; - pmr.browser = (plugin_b)c->data.plugin.browser; - pmr.parent_window = c->data.plugin.bw->window->window; + pmr.plugin = (plugin_p)plugin->plugin; + pmr.browser = (plugin_b)plugin->browser; + pmr.parent_window = plugin->bw->window->window; pmr.bbox.x0 = x * 2; pmr.bbox.y1 = -y * 2; - if (c->data.plugin.box) { - pmr.bbox.x1 = pmr.bbox.x0 + c->data.plugin.box->width * 2; - pmr.bbox.y0 = pmr.bbox.y1 - c->data.plugin.box->height * 2; + if (plugin->box) { + pmr.bbox.x1 = pmr.bbox.x0 + plugin->box->width * 2; + pmr.bbox.y0 = pmr.bbox.y1 - plugin->box->height * 2; } else { /* standalone */ @@ -525,27 +604,46 @@ void plugin_reformat(struct content *c, int width, int height) LOG(("sending message")); error = xwimp_send_message(wimp_USER_MESSAGE, (wimp_message *) &pmr, - (wimp_t)c->data.plugin.plugin_task); + (wimp_t)plugin->plugin_task); if (error) { return; } } -bool plugin_clone(const struct content *old, struct content *new_content) +nserror plugin_clone(const struct content *old, struct content **newc) { + plugin_content *plugin; + nserror error; + LOG(("plugin_clone")); + + plugin = talloc_zero(0, plugin_content); + if (plugin == NULL) + return NSERROR_NOMEM; + + error = content__clone(old, &plugin->base); + if (error != NSERROR_OK) { + content_destroy(&plugin->base); + return error; + } + /* We "clone" the old content by replaying creation and conversion */ - if (plugin_create(new_content, NULL) == false) - return false; + error = plugin_create_plugin_data(plugin); + if (error != NSERROR_OK) { + content_destroy(&plugin->base); + return error; + } if (old->status == CONTENT_STATUS_READY || old->status == CONTENT_STATUS_DONE) { - if (plugin_convert(new_content) == false) - return false; + if (plugin_convert(&plugin->base) == false) { + content_destroy(&plugin->base); + return NSERROR_CLONE_FAILED; + } } - return true; + return NSERROR_OK; } @@ -558,12 +656,13 @@ bool plugin_clone(const struct content *old, struct content *new_content) * \param helper Whether we're interested in the helper variable * \return true on success, false otherwise. */ -bool plugin_create_sysvar(const char *mime_type, char* sysvar, bool helper) +bool plugin_create_sysvar(lwc_string *mime_type, char* sysvar, bool helper) { unsigned int *fv; os_error *e; - e = xmimemaptranslate_mime_type_to_filetype(mime_type, (bits *) &fv); + e = xmimemaptranslate_mime_type_to_filetype( + lwc_string_data(mime_type), (bits *) &fv); if (e) { return false; } @@ -575,34 +674,6 @@ bool plugin_create_sysvar(const char *mime_type, char* sysvar, bool helper) return true; } -/** - * Determines whether a content is handleable by a plugin - * - * \param mime_type The mime type of the content - * \return true if the content is handleable, false otherwise - */ -bool plugin_handleable(const char *mime_type) -{ - char sysvar[SYSVAR_BUF_SIZE]; - - /* Look for Alias$@PluginType_xxx */ - if (plugin_create_sysvar(mime_type, sysvar, false)) { - if (getenv(sysvar) != 0) { - return true; - } - } -#if 0 - /* Look for Alias$@HelperType_xxx */ - if (plugin_create_sysvar(mime_type, sysvar, true)) { - if (getenv(sysvar) != 0) { - return true; - } - } -#endif - return false; -} - - /** * Handle a bounced plugin_open message * @@ -610,31 +681,31 @@ bool plugin_handleable(const char *mime_type) */ void plugin_open_msg(wimp_message *message) { - struct content *c; + plugin_content *c; os_error *error; plugin_message_open *pmo = (plugin_message_open *)&message->data; /* retrieve our content */ - c = (struct content *)pmo->browser; + c = (plugin_content *)pmo->browser; /* check we expect this message */ - if (!c || !plugin_active(c)) + if (!c || !plugin_active(&c->base)) return; LOG(("bounced")); /* bail if we've already tried twice */ - if (c->data.plugin.repeated >= 1) + if (c->repeated >= 1) return; /* start plugin app */ - error = xwimp_start_task((char const*)c->data.plugin.taskname, 0); + error = xwimp_start_task((char const*)c->taskname, 0); if (error) { return; } /* indicate we've already sent this message once */ - c->data.plugin.repeated++; + c->repeated++; /* and resend the message */ LOG(("resending")); @@ -653,29 +724,28 @@ void plugin_open_msg(wimp_message *message) */ void plugin_opening(wimp_message *message) { - struct content *c; + plugin_content *c; plugin_message_opening *pmo = (plugin_message_opening *)&message->data; /* retrieve our content */ - c = (struct content *)pmo->browser; + c = (plugin_content *)pmo->browser; /* check we expect this message */ - if (!c || !plugin_active(c)) + if (!c || !plugin_active(&c->base)) return; - c->data.plugin.repeated = 2; /* make sure open_msg does nothing */ - c->data.plugin.plugin = (unsigned int)pmo->plugin; - c->data.plugin.plugin_task = (unsigned int)message->sender; - c->data.plugin.opened = true; + c->repeated = 2; /* make sure open_msg does nothing */ + c->plugin = (unsigned int)pmo->plugin; + c->plugin_task = (unsigned int)message->sender; + c->opened = true; LOG(("opening")); /* if there's a reformat pending, do so now */ - if (c->data.plugin.reformat_pending) { + if (c->reformat_pending) { LOG(("do pending reformat")); - plugin_reformat(c, c->data.plugin.width, - c->data.plugin.height); + plugin_reformat(&c->base, c->width, c->height); } if (pmo->flags & plugin_OPENING_WANTS_DATA_FETCHING) { @@ -686,7 +756,7 @@ void plugin_opening(wimp_message *message) if (!(pmo->flags & plugin_OPENING_WILL_DELETE_PARAMETERS)) { LOG(("we delete file")); /* we don't care if this fails */ - xosfile_delete(c->data.plugin.filename, 0, 0, 0, 0, 0); + xosfile_delete(c->filename, 0, 0, 0, 0, 0); } } @@ -709,25 +779,24 @@ void plugin_close_msg(wimp_message *message) */ void plugin_closed(wimp_message *message) { - struct content *c; + plugin_content *c; plugin_message_closed *pmc = (plugin_message_closed *)&message->data; /* retrieve our content */ - c = (struct content*)pmc->browser; + c = (plugin_content*)pmc->browser; /* check we expect this message */ - if (!c || !plugin_active(c)) + if (!c || !plugin_active(&c->base)) return; LOG(("died")); - c->data.plugin.opened = false; + c->opened = false; if (pmc->flags & plugin_CLOSED_WITH_ERROR) { LOG(("plugin_closed: 0x%x: %s", pmc->error_number, pmc->error_text)); /* not really important enough to do a warn_user */ - gui_window_set_status(c->data.plugin.bw->window, - pmc->error_text); + gui_window_set_status(c->bw->window, pmc->error_text); } } @@ -738,16 +807,16 @@ void plugin_closed(wimp_message *message) */ void plugin_reshape_request(wimp_message *message) { - struct content *c; + plugin_content *c; struct box *b; union content_msg_data data; plugin_message_reshape_request *pmrr = (plugin_message_reshape_request*)&message->data; /* retrieve our content */ - c = (struct content *)pmrr->browser; + c = (plugin_content *)pmrr->browser; /* check we expect this message */ - if (!c || !plugin_active(c)) + if (!c || !plugin_active(&c->base)) return; LOG(("handling reshape request")); @@ -756,28 +825,26 @@ void plugin_reshape_request(wimp_message *message) * so we set it up here. This is ok as the content won't change * under us. However, the box may not exist (if we're standalone) */ - if (c->data.plugin.box) - c->data.plugin.box->object = c; + if (c->box) + c->box->object = c; /* should probably shift by x and y eig values here */ - c->width = pmrr->size.x / 2; - c->height = pmrr->size.y / 2; + c->base.width = pmrr->size.x / 2; + c->base.height = pmrr->size.y / 2; - if (c->data.plugin.box) + if (c->box) /* invalidate parent box widths */ - for (b = c->data.plugin.box->parent; b; b = b->parent) + for (b = c->box->parent; b; b = b->parent) b->max_width = UNKNOWN_MAX_WIDTH; - if (c->data.plugin.page) + if (c->page) /* force a reformat of the parent */ - content_reformat(c->data.plugin.page, - c->data.plugin.page->available_width, 0); + content__reformat(c->page, c->page->available_width, 0); /* redraw the window */ - content_broadcast(c->data.plugin.bw->current_content, - CONTENT_MSG_REFORMAT, data); + content_broadcast(c->bw->current_content, CONTENT_MSG_REFORMAT, data); /* reshape the plugin */ - plugin_reformat(c, c->width, c->height); + plugin_reformat(&c->base, c->base.width, c->base.height); } /** @@ -787,17 +854,17 @@ void plugin_reshape_request(wimp_message *message) */ void plugin_status(wimp_message *message) { - struct content *c; + plugin_content *c; plugin_message_status *pms = (plugin_message_status*)&message->data; /* retrieve our content */ - c = (struct content *)pms->browser; + c = (plugin_content *)pms->browser; /* check we expect this message */ - if (!c || !plugin_active(c)) + if (!c || !plugin_active(&c->base)) return; - gui_window_set_status(c->data.plugin.bw->window, + gui_window_set_status(c->bw->window, (const char*)plugin_get_string_value(pms->message, (char*)pms)); } @@ -819,7 +886,7 @@ void plugin_stream_new(wimp_message *message) p = (struct plugin_stream *)pmsn->browser_stream; /* check we expect this message */ - if (!p || !p->plugin || !plugin_active(p->plugin)) + if (!p || !p->plugin || !plugin_active(&p->plugin->base)) return; /* response to a message we sent */ @@ -884,7 +951,7 @@ void plugin_stream_written(wimp_message *message) p = (struct plugin_stream *)pmsw->browser_stream; /* check we expect this message */ - if (!p || !p->plugin || !plugin_active(p->plugin)) + if (!p || !p->plugin || !plugin_active(&p->plugin->base)) return; LOG(("got written")); @@ -899,7 +966,7 @@ void plugin_stream_written(wimp_message *message) */ void plugin_url_access(wimp_message *message) { - struct content *c; + plugin_content *c; plugin_full_message_notify pmn; os_error *error; plugin_message_url_access *pmua = @@ -913,10 +980,10 @@ void plugin_url_access(wimp_message *message) file = (pmua->flags & plugin_URL_ACCESS_POST_FILE); /* retrieve our content */ - c = (struct content *)pmua->browser; + c = (plugin_content *)pmua->browser; /* check we expect this message */ - if (!c || !plugin_active(c)) + if (!c || !plugin_active(&c->base)) return; /* fetch url to window */ @@ -930,7 +997,7 @@ void plugin_url_access(wimp_message *message) */ if (!post) { /* GET request */ if (strcasecmp(url, - c->data.plugin.bw->current_content->url) && + c->bw->current_content->url) && (strcasecmp(window, "_self") == 0 || strcasecmp(window, "_parent") == 0 || strcasecmp(window, "_top") == 0 || @@ -940,7 +1007,7 @@ void plugin_url_access(wimp_message *message) * end up in an infinite loop of fetching * the same page */ - browser_window_go(c->data.plugin.bw, url, 0, true); + browser_window_go(c->bw, url, 0, true); } else if (!option_block_popups && strcasecmp(window, "_blank") == 0) { @@ -992,13 +1059,12 @@ void plugin_url_access(wimp_message *message) * \param c The content being fetched, or NULL. * \param url The url of the resource to fetch, or NULL if content provided. */ -void plugin_create_stream(struct content *plugin, struct content *c, +void plugin_create_stream(plugin_content *plugin, plugin_content *c, const char *url) { struct plugin_stream *p; - assert(plugin && plugin->type == CONTENT_PLUGIN && - ((c && !url) || (!c && url))); + assert(plugin && ((c && !url) || (!c && url))); p = malloc(sizeof(struct plugin_stream)); if (!p) @@ -1019,8 +1085,8 @@ void plugin_create_stream(struct content *plugin, struct content *c, p->stream.normal.consumed = 0; /* add to head of list */ - p->next = plugin->data.plugin.streams; - plugin->data.plugin.streams = p; + p->next = plugin->streams; + plugin->streams = p; if (url) /* we'll send this later, once some data is arriving */ @@ -1044,11 +1110,11 @@ bool plugin_send_stream_new(struct plugin_stream *p) pmsn.your_ref = 0; pmsn.action = message_PLUG_IN_STREAM_NEW; pmsn.flags = 0; - pmsn.plugin = (plugin_p)p->plugin->data.plugin.plugin; - pmsn.browser = (plugin_b)p->plugin->data.plugin.browser; + pmsn.plugin = (plugin_p)p->plugin->plugin; + pmsn.browser = (plugin_b)p->plugin->browser; pmsn.stream = (plugin_s)0; pmsn.browser_stream = (plugin_bs)p; - pmsn.url.pointer = p->c->url; + pmsn.url.pointer = (char *) content__get_url(&p->c->base); pmsn.end = p->c->total_size; pmsn.last_modified_date = 0; pmsn.notify_data = 0; @@ -1058,7 +1124,7 @@ bool plugin_send_stream_new(struct plugin_stream *p) LOG(("Sending message &4D548")); error = xwimp_send_message(wimp_USER_MESSAGE_RECORDED, (wimp_message*)&pmsn, - (wimp_t)p->plugin->data.plugin.plugin_task); + (wimp_t)p->plugin->plugin_task); if (error) { plugin_stream_free(p); return false; @@ -1086,11 +1152,11 @@ void plugin_write_stream(struct plugin_stream *p, unsigned int consumed) pmsw.your_ref = 0; pmsw.action = message_PLUG_IN_STREAM_WRITE; pmsw.flags = 0; - pmsw.plugin = (plugin_p)p->plugin->data.plugin.plugin; - pmsw.browser = (plugin_b)p->plugin->data.plugin.browser; + pmsw.plugin = (plugin_p)p->plugin->plugin; + pmsw.browser = (plugin_b)p->plugin->browser; pmsw.stream = (plugin_s)p->pluginh; pmsw.browser_stream = (plugin_bs)p; - pmsw.url.pointer = p->c->url; + pmsw.url.pointer = (char *) content__get_url(&p->c->base); /* end of stream is p->c->total_size * (which is conveniently 0 if unknown) */ @@ -1116,7 +1182,7 @@ void plugin_write_stream(struct plugin_stream *p, unsigned int consumed) LOG(("Sending message &4D54A")); error = xwimp_send_message(wimp_USER_MESSAGE_RECORDED, (wimp_message *)&pmsw, - (wimp_t)p->plugin->data.plugin.plugin_task); + (wimp_t)p->plugin->plugin_task); if (error) { plugin_destroy_stream(p, plugin_STREAM_DESTROY_ERROR); @@ -1166,7 +1232,8 @@ void plugin_stream_as_file_callback(void *p) schedule_remove(plugin_stream_as_file_callback, p); if (s->c->source_size < s->c->total_size || - s->c->status != CONTENT_STATUS_DONE) { + content__get_status(&s->c->base) != + CONTENT_STATUS_DONE) { /* not got all the data so wait some more */ schedule(PLUGIN_SCHEDULE_WAIT, plugin_stream_as_file_callback, p); @@ -1211,11 +1278,11 @@ void plugin_write_stream_as_file(struct plugin_stream *p) pmsaf.your_ref = 0; pmsaf.action = message_PLUG_IN_STREAM_AS_FILE; pmsaf.flags = 0; - pmsaf.plugin = (plugin_p)p->plugin->data.plugin.plugin; - pmsaf.browser = (plugin_b)p->plugin->data.plugin.browser; + pmsaf.plugin = (plugin_p)p->plugin->plugin; + pmsaf.browser = (plugin_b)p->plugin->browser; pmsaf.stream = (plugin_s)p->pluginh; pmsaf.browser_stream = (plugin_bs)p; - pmsaf.url.pointer = p->c->url; + pmsaf.url.pointer = (char *) content__get_url(&p->c->base); pmsaf.end = p->c->total_size; pmsaf.last_modified_date = 0; pmsaf.notify_data = 0; @@ -1239,7 +1306,7 @@ void plugin_write_stream_as_file(struct plugin_stream *p) LOG(("Sending message &4D54C")); error = xwimp_send_message(wimp_USER_MESSAGE, (wimp_message *)&pmsaf, - (wimp_t)p->plugin->data.plugin.plugin_task); + (wimp_t)p->plugin->plugin_task); if (error) { plugin_destroy_stream(p, plugin_STREAM_DESTROY_ERROR); return; @@ -1274,11 +1341,11 @@ void plugin_destroy_stream(struct plugin_stream *p, pmsd.your_ref = 0; pmsd.action = message_PLUG_IN_STREAM_DESTROY; pmsd.flags = 0; - pmsd.plugin = (plugin_p)p->plugin->data.plugin.plugin; - pmsd.browser = (plugin_b)p->plugin->data.plugin.browser; + pmsd.plugin = (plugin_p)p->plugin->plugin; + pmsd.browser = (plugin_b)p->plugin->browser; pmsd.stream = (plugin_s)p->pluginh; pmsd.browser_stream = (plugin_bs)p; - pmsd.url.pointer = p->c->url; + pmsd.url.pointer = (char *) content__get_url(&p->c->base); pmsd.end = p->c->total_size; pmsd.last_modified_date = 0; pmsd.notify_data = 0; @@ -1287,7 +1354,7 @@ void plugin_destroy_stream(struct plugin_stream *p, LOG(("Sending message &4D549")); error = xwimp_send_message(wimp_USER_MESSAGE, (wimp_message *)&pmsd, - (wimp_t)p->plugin->data.plugin.plugin_task); + (wimp_t)p->plugin->plugin_task); if (error) { LOG(("0x%x %s", error->errnum, error->errmess)); } @@ -1303,7 +1370,7 @@ void plugin_destroy_stream(struct plugin_stream *p, * \param base base URL for object * \return true on success, false otherwise */ -bool plugin_write_parameters_file(struct content *c, +bool plugin_write_parameters_file(plugin_content *c, struct object_params *params, const char *base) { struct object_param *p; @@ -1316,17 +1383,17 @@ bool plugin_write_parameters_file(struct content *c, xosfile_create_dir(".WWW", 77); xosfile_create_dir(".WWW.NetSurf", 77); /* path + filename + terminating NUL */ - c->data.plugin.filename = + c->filename = calloc(strlen(getenv("Wimp$ScrapDir"))+13+10, sizeof(char)); - if (!c->data.plugin.filename) { + if (!c->filename) { LOG(("malloc failed")); warn_user("NoMemory", 0); return false; } - sprintf(c->data.plugin.filename, "%s.WWW.NetSurf.p%x", + sprintf(c->filename, "%s.WWW.NetSurf.p%x", getenv("Wimp$ScrapDir"), (unsigned int)params); - LOG(("filename: %s", c->data.plugin.filename)); + LOG(("filename: %s", c->filename)); /* Write object attributes first */ @@ -1413,11 +1480,10 @@ bool plugin_write_parameters_file(struct content *c, goto error; /* BGCOLOR */ - if (c->data.plugin.box && c->data.plugin.box->style && - c->data.plugin.box->style->background_color - <= 0xFFFFFF) + if (c->box && c->box->style && + c->box->style->background_color <= 0xFFFFFF) sprintf(bgcolor, "%X00", - (unsigned int)c->data.plugin.box->style->background_color); + (unsigned int)c->box->style->background_color); else sprintf(bgcolor, "FFFFFF"); if (!plugin_add_item_to_pilist(&pilist, PLUGIN_PARAMETER_SPECIAL, @@ -1427,7 +1493,7 @@ bool plugin_write_parameters_file(struct content *c, goto error; /* Write file */ - fp = fopen(c->data.plugin.filename, "wb+"); + fp = fopen(c->filename, "wb+"); while (pilist != 0) { fwrite(&pilist->type, sizeof(int), 1, fp); @@ -1481,8 +1547,8 @@ error: ppi = 0; } - free(c->data.plugin.filename); - c->data.plugin.filename = 0; + free(c->filename); + c->filename = 0; return false; } @@ -1634,14 +1700,14 @@ void plugin_stream_free(struct plugin_stream *p) /* free normal stream context. file streams get freed later */ if (p->type == NORMAL) { struct plugin_stream *q; - for (q = p->plugin->data.plugin.streams; q && q->next != p; + for (q = p->plugin->streams; q && q->next != p; q = q->next) /* do nothing */; - assert(q || p == p->plugin->data.plugin.streams); + assert(q || p == p->plugin->streams); if (q) q->next = p->next; else - p->plugin->data.plugin.streams = p->next; + p->plugin->streams = p->next; free(p); } diff --git a/riscos/plugin.h b/riscos/plugin.h index a3586b284..87b59edca 100644 --- a/riscos/plugin.h +++ b/riscos/plugin.h @@ -22,30 +22,10 @@ #include "utils/config.h" #ifdef WITH_PLUGIN -#include "desktop/plugin.h" #include #include "oslib/plugin.h" #include "oslib/wimp.h" -struct plugin_stream; - -/* We have one content per instance of a plugin */ -struct content_plugin_data { - struct browser_window *bw; /* window containing this content */ - struct content *page; /* parent content */ - struct box *box; /* box containing this content */ - char *taskname; /* plugin task to launch */ - char *filename; /* filename of parameters file */ - bool opened; /* has this plugin been opened? */ - int repeated; /* indication of opening state */ - unsigned int browser; /* browser handle */ - unsigned int plugin; /* plugin handle */ - unsigned int plugin_task; /* plugin task handle */ - bool reformat_pending; /* is a reformat pending? */ - int width, height; /* reformat width & height */ - struct plugin_stream *streams; /* list of active streams */ -}; - /* message handlers */ void plugin_open_msg(wimp_message *message); void plugin_opening(wimp_message *message); diff --git a/riscos/print.c b/riscos/print.c index a1e940f4d..486742c64 100644 --- a/riscos/print.c +++ b/riscos/print.c @@ -33,10 +33,6 @@ #include "content/content.h" #include "content/hlcache.h" #include "desktop/plotters.h" -#include "render/box.h" -#include "render/font.h" -#include "render/html.h" -#include "render/layout.h" #include "riscos/dialog.h" #include "riscos/menus.h" #include "riscos/print.h" @@ -592,8 +588,7 @@ bool print_document(struct gui_window *g, const char *filename) saved_width = content_get_width(h); saved_height = content_get_height(h); if (content_get_type(h) == CONTENT_HTML) - /* TODO: Front end code shouldn't see contents */ - layout_document(hlcache_handle_get_content(h), width, height); + content_reformat(h, width, height); /* open printer file */ error = xosfind_openoutw(osfind_NO_PATH | osfind_ERROR_IF_DIR | @@ -763,9 +758,7 @@ bool print_document(struct gui_window *g, const char *filename) /* restore document layout and redraw browser window */ if (content_get_type(h) == CONTENT_HTML) - /* TODO: Front end code shouldn't see contents */ - layout_document(hlcache_handle_get_content(h), - saved_width, saved_height); + content_reformat(h, saved_width, saved_height); gui_window_redraw_window(g); @@ -785,9 +778,7 @@ error: /* restore document layout */ if (content_get_type(h) == CONTENT_HTML) - /* TODO: Front end code shouldn't see contents */ - layout_document(hlcache_handle_get_content(h), - saved_width, saved_height); + content_reformat(h, saved_width, saved_height); return false; } diff --git a/riscos/save.c b/riscos/save.c index a47de318f..b1b743e59 100644 --- a/riscos/save.c +++ b/riscos/save.c @@ -1013,7 +1013,7 @@ void ro_gui_save_done(void) */ bool save_complete_gui_save(const char *path, const char *filename, size_t len, - const char *sourcedata, content_type type) + const char *sourcedata, lwc_string *mime_type) { char *fullpath; os_error *error; @@ -1025,7 +1025,7 @@ bool save_complete_gui_save(const char *path, const char *filename, size_t len, return false; } snprintf(fullpath, namelen, "%s.%s", path, filename); - rotype = ro_content_filetype_from_type(type); + rotype = ro_content_filetype_from_mime_type(mime_type); error = xosfile_save_stamped(fullpath, rotype, (byte *) sourcedata, (byte *) sourcedata + len); free(fullpath); @@ -1162,63 +1162,43 @@ bool ro_gui_save_complete(hlcache_handle *h, char *path) bool ro_gui_save_object_native(hlcache_handle *h, char *path) { - const char *source_data; - unsigned long source_size; + int file_type = ro_content_filetype(h); - switch (content_get_type(h)) { -#ifdef WITH_JPEG - case CONTENT_JPEG: -#endif -#if defined(WITH_MNG) || defined(WITH_PNG) - case CONTENT_PNG: -#endif -#ifdef WITH_MNG - case CONTENT_JNG: - case CONTENT_MNG: -#endif -#ifdef WITH_GIF - case CONTENT_GIF: -#endif -#ifdef WITH_BMP - case CONTENT_BMP: - case CONTENT_ICO: -#endif + if (file_type == osfile_TYPE_SPRITE || file_type == osfile_TYPE_DRAW) { + /* Native sprite or drawfile */ + const char *source_data; + unsigned long source_size; + os_error *error; + + source_data = content_get_source_data(h, &source_size); + error = xosfile_save_stamped(path, file_type, + (byte *) source_data, + (byte *) source_data + source_size); + if (error != NULL) { + LOG(("xosfile_save_stamped: 0x%x: %s", + error->errnum, error->errmess)); + warn_user("SaveError", error->errmess); + return false; + } + } else { + /* Non-native type: export */ + switch (ro_content_native_type(h)) { + case osfile_TYPE_SPRITE: { unsigned flags = (os_version == 0xA9) ? BITMAP_SAVE_FULL_ALPHA : 0; bitmap_save(content_get_bitmap(h), path, flags); - return true; } - break; -#ifdef WITH_SPRITE - case CONTENT_SPRITE: -#endif -#ifdef WITH_DRAW - case CONTENT_DRAW: -#endif - { - os_error *error; - source_data = content_get_source_data(h, &source_size); - error = xosfile_save_stamped(path, - ro_content_filetype(h), - (byte *) source_data, - (byte *) source_data + source_size); - if (error) { - LOG(("xosfile_save_stamped: 0x%x: %s", - error->errnum, error->errmess)); - warn_user("SaveError", error->errmess); - return false; - } - return true; - } - break; -#if defined(WITH_NS_SVG) || defined(WITH_RSVG) - case CONTENT_SVG: + break; + case osfile_TYPE_DRAW: + /* Must be SVG */ return save_as_draw(h, path); -#endif default: return false; + } } + + return true; } @@ -1306,40 +1286,15 @@ void ro_gui_save_set_state(hlcache_handle *h, gui_save_type save_type, gui_save_filetype = gui_save_table[save_type].filetype; if (!gui_save_filetype && h) { if (save_type == GUI_SAVE_OBJECT_NATIVE) { - switch (content_get_type(h)) { - /* bitmap images */ -#ifdef WITH_JPEG - case CONTENT_JPEG: -#endif -#if defined(WITH_MNG) || defined(WITH_PNG) - case CONTENT_PNG: -#endif -#ifdef WITH_MNG - case CONTENT_JNG: - case CONTENT_MNG: -#endif -#ifdef WITH_GIF - case CONTENT_GIF: -#endif -#ifdef WITH_BMP - case CONTENT_BMP: - case CONTENT_ICO: -#endif - gui_save_filetype = osfile_TYPE_SPRITE; - break; - /* vector formats */ -#if defined(WITH_NS_SVG) || defined(WITH_RSVG) - case CONTENT_SVG: - gui_save_filetype = osfile_TYPE_DRAW; - break; -#endif -#ifdef WITH_DRAW - case CONTENT_DRAW: - gui_save_filetype = osfile_TYPE_DRAW; - break; -#endif - default: - break; + switch (ro_content_native_type(h)) { + case osfile_TYPE_SPRITE: + gui_save_filetype = osfile_TYPE_SPRITE; + break; + case osfile_TYPE_DRAW: + gui_save_filetype = osfile_TYPE_DRAW; + break; + default: + break; } } if (!gui_save_filetype) diff --git a/riscos/sprite.c b/riscos/sprite.c index 55afa6f98..e14f8b19a 100644 --- a/riscos/sprite.c +++ b/riscos/sprite.c @@ -21,27 +21,130 @@ * * No conversion is necessary: we can render RISC OS sprites directly under * RISC OS. - * - * Unfortunately we have to make a copy of the bitmap data, because sprite areas - * need a length word at the start. */ #include #include #include "oslib/osspriteop.h" #include "utils/config.h" -#include "desktop/plotters.h" #include "content/content_protected.h" +#include "desktop/plotters.h" #include "riscos/gui.h" #include "riscos/image.h" #include "riscos/sprite.h" #include "utils/config.h" #include "utils/log.h" #include "utils/messages.h" +#include "utils/talloc.h" #include "utils/utils.h" #ifdef WITH_SPRITE +typedef struct sprite_content { + struct content base; + + void *data; +} sprite_content; + +static nserror sprite_create(const content_handler *handler, + lwc_string *imime_type, const http_parameter *params, + llcache_handle *llcache, const char *fallback_charset, + bool quirks, struct content **c); +static bool sprite_convert(struct content *c); +static void sprite_destroy(struct content *c); +static bool sprite_redraw(struct content *c, int x, int y, + int width, int height, const struct rect *clip, + float scale, colour background_colour); +static nserror sprite_clone(const struct content *old, struct content **newc); +static content_type sprite_content_type(lwc_string *mime_type); + +static const content_handler sprite_content_handler = { + sprite_create, + NULL, + sprite_convert, + NULL, + sprite_destroy, + NULL, + NULL, + NULL, + sprite_redraw, + NULL, + NULL, + NULL, + sprite_clone, + NULL, + sprite_content_type, + false +}; + +static const char *sprite_types[] = { + "image/x-riscos-sprite" +}; + +static lwc_string *sprite_mime_types[NOF_ELEMENTS(sprite_types)]; + +nserror sprite_init(void) +{ + uint32_t i; + lwc_error lerror; + nserror error; + + for (i = 0; i < NOF_ELEMENTS(sprite_mime_types); i++) { + lerror = lwc_intern_string(sprite_types[i], + strlen(sprite_types[i]), + &sprite_mime_types[i]); + if (lerror != lwc_error_ok) { + error = NSERROR_NOMEM; + goto error; + } + + error = content_factory_register_handler(sprite_mime_types[i], + &sprite_content_handler); + if (error != NSERROR_OK) + goto error; + } + + return NSERROR_OK; + +error: + sprite_fini(); + + return error; +} + +void sprite_fini(void) +{ + uint32_t i; + + for (i = 0; i < NOF_ELEMENTS(sprite_mime_types); i++) { + if (sprite_mime_types[i] != NULL) + lwc_string_unref(sprite_mime_types[i]); + } +} + +nserror sprite_create(const content_handler *handler, + lwc_string *imime_type, const http_parameter *params, + llcache_handle *llcache, const char *fallback_charset, + bool quirks, struct content **c) +{ + sprite_content *sprite; + nserror error; + + sprite = talloc_zero(0, sprite_content); + if (sprite == NULL) + return NSERROR_NOMEM; + + error = content__init(&sprite->base, handler, imime_type, params, + llcache, fallback_charset, quirks); + if (error != NSERROR_OK) { + talloc_free(sprite); + return error; + } + + *c = (struct content *) sprite; + + return NSERROR_OK; +} /** * Convert a CONTENT_SPRITE for display. @@ -51,6 +154,7 @@ bool sprite_convert(struct content *c) { + sprite_content *sprite = (sprite_content *) c; os_error *error; int w, h; union content_msg_data msg_data; @@ -63,7 +167,7 @@ bool sprite_convert(struct content *c) sprite_data = source_data - 4; osspriteop_area *area = (osspriteop_area*) sprite_data; - c->data.sprite.data = area; + sprite->data = area; /* check for bad data */ if ((int)source_size + 4 != area->used) { @@ -116,10 +220,12 @@ bool sprite_redraw(struct content *c, int x, int y, int width, int height, const struct rect *clip, float scale, colour background_colour) { + sprite_content *sprite = (sprite_content *) c; + if (plot.flush && !plot.flush()) return false; - return image_redraw(c->data.sprite.data, + return image_redraw(sprite->data, ro_plot_origin_x + x * 2, ro_plot_origin_y - y * 2, width, height, @@ -130,16 +236,38 @@ bool sprite_redraw(struct content *c, int x, int y, IMAGE_PLOT_OS); } -bool sprite_clone(const struct content *old, struct content *new_content) +nserror sprite_clone(const struct content *old, struct content **newc) { + sprite_content *sprite; + nserror error; + + sprite = talloc_zero(0, sprite_content); + if (sprite == NULL) + return NSERROR_NOMEM; + + error = content__clone(old, &sprite->base); + if (error != NSERROR_OK) { + content_destroy(&sprite->base); + return error; + } + /* Simply rerun convert */ if (old->status == CONTENT_STATUS_READY || old->status == CONTENT_STATUS_DONE) { - if (sprite_convert(new_content) == false) - return false; + if (sprite_convert(&sprite->base) == false) { + content_destroy(&sprite->base); + return NSERROR_CLONE_FAILED; + } } - return true; + *newc = (struct content *) sprite; + + return NSERROR_OK; +} + +content_type sprite_content_type(lwc_string *mime_type) +{ + return CONTENT_IMAGE; } #endif diff --git a/riscos/sprite.h b/riscos/sprite.h index a0b071425..79e02f44b 100644 --- a/riscos/sprite.h +++ b/riscos/sprite.h @@ -23,24 +23,19 @@ #ifndef _NETSURF_RISCOS_SPRITE_H_ #define _NETSURF_RISCOS_SPRITE_H_ -#include -#include "oslib/osspriteop.h" #include "utils/config.h" +#include "utils/errors.h" #ifdef WITH_SPRITE -struct content; -struct rect; - -struct content_sprite_data { - void *data; -}; - -bool sprite_convert(struct content *c); -void sprite_destroy(struct content *c); -bool sprite_redraw(struct content *c, int x, int y, - int width, int height, const struct rect *clip, - float scale, colour background_colour); -bool sprite_clone(const struct content *old, struct content *new_content); + +nserror sprite_init(void); +void sprite_fini(void); + +#else + +#define sprite_init() NSERROR_OK +#define sprite_fini() ((void) 0) + #endif byte sprite_bpp(const osspriteop_header *s); diff --git a/riscos/treeview.c b/riscos/treeview.c index 8cc3ea12b..0206a7c29 100644 --- a/riscos/treeview.c +++ b/riscos/treeview.c @@ -1241,35 +1241,7 @@ void tree_icon_name_from_content_type(char *buffer, content_type type) case CONTENT_HTML: case CONTENT_TEXTPLAIN: case CONTENT_CSS: -#if defined(WITH_MNG) || defined(WITH_PNG) - case CONTENT_PNG: -#endif -#ifdef WITH_MNG - case CONTENT_JNG: - case CONTENT_MNG: -#endif -#ifdef WITH_JPEG - case CONTENT_JPEG: -#endif -#ifdef WITH_GIF - case CONTENT_GIF: -#endif -#ifdef WITH_BMP - case CONTENT_BMP: - case CONTENT_ICO: -#endif -#ifdef WITH_SPRITE - case CONTENT_SPRITE: -#endif -#ifdef WITH_DRAW - case CONTENT_DRAW: -#endif -#ifdef WITH_ARTWORKS - case CONTENT_ARTWORKS: -#endif -#ifdef WITH_NS_SVG - case CONTENT_SVG: -#endif + case CONTENT_IMAGE: default: sprintf(buffer, tree_content_icon_name); break; diff --git a/riscos/window.c b/riscos/window.c index 7c2cfd8f1..5ad6db981 100644 --- a/riscos/window.c +++ b/riscos/window.c @@ -3893,46 +3893,20 @@ bool ro_gui_window_content_export_types(hlcache_handle *h, if (export_sprite != NULL) *export_sprite = false; - if (h != NULL) { - switch (content_get_type(h)) { - /* bitmap types (Sprite export possible) */ -#ifdef WITH_JPEG - case CONTENT_JPEG: -#endif -#ifdef WITH_MNG - case CONTENT_JNG: - case CONTENT_MNG: -#endif -#ifdef WITH_GIF - case CONTENT_GIF: -#endif -#ifdef WITH_BMP - case CONTENT_BMP: - case CONTENT_ICO: -#endif -#if defined(WITH_MNG) || defined(WITH_PNG) - case CONTENT_PNG: -#endif -#ifdef WITH_SPRITE - case CONTENT_SPRITE: -#endif + if (h != NULL && content_get_type(h) == CONTENT_IMAGE) { + switch (ro_content_native_type(h)) { + case osfile_TYPE_SPRITE: + /* bitmap types (Sprite export possible) */ found_type = true; if (export_sprite != NULL) *export_sprite = true; break; - - /* vector types (Draw export possible) */ -#if defined(WITH_NS_SVG) || defined(WITH_RSVG) - case CONTENT_SVG: -#endif -#ifdef WITH_DRAW - case CONTENT_DRAW: -#endif + case osfile_TYPE_DRAW: + /* vector types (Draw export possible) */ found_type = true; if (export_draw != NULL) *export_draw = true; break; - default: break; } @@ -3988,7 +3962,8 @@ void ro_gui_window_prepare_pageinfo(struct gui_window *g) char enc_buf[40]; char enc_token[10] = "Encoding0"; const char *icon = icon_buf; - const char *title, *url, *mime; + const char *title, *url; + lwc_string *mime; const char *enc = "-"; assert(h); @@ -4000,8 +3975,6 @@ void ro_gui_window_prepare_pageinfo(struct gui_window *g) if (url == NULL) url = "-"; mime = content_get_mime_type(h); - if (mime == NULL) - mime = "-"; sprintf(icon_buf, "file_%x", ro_content_filetype(h)); if (!ro_gui_wimp_sprite_exists(icon_buf)) @@ -4028,7 +4001,9 @@ void ro_gui_window_prepare_pageinfo(struct gui_window *g) ro_gui_set_icon_string(dialog_pageinfo, ICON_PAGEINFO_ENC, enc, true); ro_gui_set_icon_string(dialog_pageinfo, ICON_PAGEINFO_TYPE, - mime, true); + lwc_string_data(mime), true); + + lwc_string_unref(mime); } @@ -4042,7 +4017,8 @@ void ro_gui_window_prepare_pageinfo(struct gui_window *g) void ro_gui_window_prepare_objectinfo(hlcache_handle *object, const char *href) { char icon_buf[20] = "file_xxx"; - const char *url, *mime; + const char *url; + lwc_string *mime; const char *target = "-"; sprintf(icon_buf, "file_%.3x", @@ -4054,8 +4030,6 @@ void ro_gui_window_prepare_objectinfo(hlcache_handle *object, const char *href) if (url == NULL) url = "-"; mime = content_get_mime_type(object); - if (mime == NULL) - mime = "-"; if (href) target = href; @@ -4067,7 +4041,9 @@ void ro_gui_window_prepare_objectinfo(hlcache_handle *object, const char *href) ro_gui_set_icon_string(dialog_objinfo, ICON_OBJINFO_TARGET, target, true); ro_gui_set_icon_string(dialog_objinfo, ICON_OBJINFO_TYPE, - mime, true); + lwc_string_data(mime), true); + + lwc_string_unref(mime); } -- cgit v1.2.3