diff options
Diffstat (limited to 'riscos')
-rw-r--r-- | riscos/download.c | 10 | ||||
-rw-r--r-- | riscos/gui.h | 24 | ||||
-rw-r--r-- | riscos/menus.c | 482 | ||||
-rw-r--r-- | riscos/save.c | 126 | ||||
-rw-r--r-- | riscos/wimp.c | 34 | ||||
-rw-r--r-- | riscos/wimp.h | 1 | ||||
-rw-r--r-- | riscos/window.c | 28 |
7 files changed, 374 insertions, 331 deletions
diff --git a/riscos/download.c b/riscos/download.c index b1b6d7a7b..591ddce14 100644 --- a/riscos/download.c +++ b/riscos/download.c @@ -31,6 +31,7 @@ #include "netsurf/content/fetch.h" #include "netsurf/desktop/gui.h" #include "netsurf/riscos/gui.h" +#include "netsurf/riscos/wimp.h" #include "netsurf/utils/log.h" #include "netsurf/utils/messages.h" #include "netsurf/utils/url.h" @@ -181,15 +182,8 @@ struct gui_download_window *gui_download_window_create(const char *url, size = sizeof dw->status; sprintf(dw->sprite_name, "file_%.3x", dw->file_type); - error = xwimpspriteop_select_sprite(dw->sprite_name, 0); - if (error) { - if (error->errnum != error_SPRITE_OP_DOESNT_EXIST) { - LOG(("xwimpspriteop_select_sprite: 0x%x: %s", - error->errnum, error->errmess)); - warn_user("MiscError", error->errmess); - } + if (!ro_gui_wimp_sprite_exists(dw->sprite_name)) strcpy(dw->sprite_name, "file_xxx"); - } download_template->icons[ICON_DOWNLOAD_ICON].data.indirected_sprite.id = (osspriteop_id) dw->sprite_name; diff --git a/riscos/gui.h b/riscos/gui.h index 53f14bc24..d081782ad 100644 --- a/riscos/gui.h +++ b/riscos/gui.h @@ -41,13 +41,20 @@ extern struct toolbar *hotlist_toolbar; extern bool dialog_folder_add, dialog_entry_add, hotlist_insert; typedef enum { GUI_BROWSER_WINDOW } gui_window_type; -typedef enum { GUI_SAVE_SOURCE, GUI_SAVE_DRAW, GUI_SAVE_TEXT, - GUI_SAVE_COMPLETE, - GUI_SAVE_OBJECT_ORIG, GUI_SAVE_OBJECT_NATIVE, - GUI_SAVE_LINK_URI, GUI_SAVE_LINK_URL, - GUI_SAVE_LINK_TEXT, - GUI_HOTLIST_EXPORT_HTML} gui_save_type; -extern gui_save_type gui_current_save_type; + +typedef enum { + GUI_SAVE_SOURCE, + GUI_SAVE_DRAW, + GUI_SAVE_TEXT, + GUI_SAVE_COMPLETE, + GUI_SAVE_OBJECT_ORIG, + GUI_SAVE_OBJECT_NATIVE, + GUI_SAVE_LINK_URI, + GUI_SAVE_LINK_URL, + GUI_SAVE_LINK_TEXT, + GUI_SAVE_HOTLIST_EXPORT_HTML, +} gui_save_type; + typedef enum { GUI_DRAG_SELECTION, GUI_DRAG_DOWNLOAD_SAVE, GUI_DRAG_SAVE, GUI_DRAG_STATUS_RESIZE, GUI_DRAG_HOTLIST_SELECT, GUI_DRAG_HOTLIST_MOVE } gui_drag_type; @@ -110,7 +117,6 @@ void ro_gui_popup_menu(wimp_menu *menu, wimp_w w, wimp_i i); void ro_gui_menu_selection(wimp_selection* selection); void ro_gui_menu_warning(wimp_message_menu_warning *warning); void ro_gui_prepare_navigate(gui_window *gui); -void ro_gui_menu_prepare_save(struct content *c); void ro_gui_menu_prepare_scale(void); void ro_gui_menu_prepare_pageinfo(void); @@ -204,6 +210,8 @@ void ro_gui_hotlist_prepare_folder_dialog(bool selected); void ro_gui_hotlist_prepare_entry_dialog(bool selected); /* in save.c */ +void ro_gui_save_open(gui_save_type save_type, struct content *c, + bool sub_menu, int x, int y, wimp_w parent); void ro_gui_save_click(wimp_pointer *pointer); void ro_gui_drag_icon(wimp_pointer *pointer); void ro_gui_save_drag_end(wimp_dragged *drag); diff --git a/riscos/menus.c b/riscos/menus.c index 41fb46e42..8ccfe39ef 100644 --- a/riscos/menus.c +++ b/riscos/menus.c @@ -48,13 +48,13 @@ static void ro_gui_menu_prepare_help(int forced); static void ro_gui_menu_objectinfo(wimp_message_menu_warning *warning); static struct box *ro_gui_menu_find_object_box(void); static void ro_gui_menu_object_reload(void); +static void ro_gui_menu_browser_warning(wimp_message_menu_warning *warning); static void ro_gui_menu_hotlist_warning(wimp_message_menu_warning *warning); static void ro_gui_menu_prepare_hotlist(void); wimp_menu *current_menu; static int current_menu_x, current_menu_y; gui_window *current_gui; -struct content *save_content = 0; /* Default menu item flags */ @@ -546,12 +546,12 @@ void ro_gui_menu_selection(wimp_selection *selection) case 0: /* Hotlist-> */ switch (selection->items[1]) { case 0: /* New */ - break; + break; case 1: /* Save */ ro_gui_hotlist_save(); - break; + break; case 2: /* Export */ - break; + break; case 3: /* Expand */ ro_gui_hotlist_set_expanded(true, (selection->items[2] != 2), @@ -561,18 +561,18 @@ void ro_gui_menu_selection(wimp_selection *selection) ro_gui_hotlist_set_expanded(false, (selection->items[2] != 2), (selection->items[2] != 1)); - break; + break; } break; case 1: /* Selection-> */ switch (selection->items[1]) { case 0: /* Save */ - break; + break; case 1: /* Edit title-> */ - break; + break; case 2: /* Launch */ ro_gui_hotlist_keypress(wimp_KEY_RETURN); - break; + break; case 3: /* Delete */ ro_gui_hotlist_delete_selected(); break; @@ -811,7 +811,7 @@ void ro_gui_menu_selection(wimp_selection *selection) } else { if (current_menu == hotlist_menu) { ro_gui_hotlist_menu_closed(); - } + } } } @@ -819,302 +819,258 @@ void ro_gui_menu_selection(wimp_selection *selection) /** * Handle Message_MenuWarning. */ + void ro_gui_menu_warning(wimp_message_menu_warning *warning) { - struct content *c; - os_error *error = NULL; // No warnings - - if (current_menu == hotlist_menu) { + if (current_menu == browser_menu) + ro_gui_menu_browser_warning(warning); + else if (current_menu == hotlist_menu) ro_gui_menu_hotlist_warning(warning); - return; - } else if (current_menu != browser_menu) { - return; - } +} + + +/** + * Handle Message_MenuWarning for the browser menu. + */ + +void ro_gui_menu_browser_warning(wimp_message_menu_warning *warning) +{ + struct content *c; + struct box *box; + os_error *error = 0; c = current_gui->data.browser.bw->current_content; + switch (warning->selection.items[0]) { - case MENU_PAGE: /* Page -> */ - switch (warning->selection.items[1]) { - case 4: /* Save Link */ - switch (warning->selection.items[2]) { - case 0: /* URI */ - gui_current_save_type = GUI_SAVE_LINK_URI; - break; - - case 1: /* URL */ - gui_current_save_type = GUI_SAVE_LINK_URL; - break; - - case 2: /* Text */ - gui_current_save_type = GUI_SAVE_LINK_TEXT; - break; - } - break; - case 3: /* Export as -> */ - switch (warning->selection.items[2]) { - case 0: /* Draw */ - gui_current_save_type = GUI_SAVE_DRAW; - break; - - case 1: /* Text */ - gui_current_save_type = GUI_SAVE_TEXT; - break; - } - break; + case MENU_PAGE: /* Page -> */ + switch (warning->selection.items[1]) { + case 0: /* Page info */ + ro_gui_menu_prepare_pageinfo(); + error = xwimp_create_sub_menu( + (wimp_menu *) dialog_pageinfo, + warning->pos.x, warning->pos.y); + break; - case 2: /* Save complete */ - gui_current_save_type = GUI_SAVE_COMPLETE; - break; + case 1: /* Save */ + ro_gui_save_open(GUI_SAVE_SOURCE, c, true, + warning->pos.x, warning->pos.y, 0); + break; + case 2: /* Save complete */ + ro_gui_save_open(GUI_SAVE_COMPLETE, c, true, + warning->pos.x, warning->pos.y, 0); + break; - case 0: /* Page info */ - ro_gui_menu_prepare_pageinfo(); - error = xwimp_create_sub_menu((wimp_menu *) dialog_pageinfo, - warning->pos.x, warning->pos.y); - if (error) { - LOG(("0x%x: %s\n", error->errnum, error->errmess)); - warn_user("MenuError", error->errmess); - } - return; + case 3: /* Export as -> */ + switch (warning->selection.items[2]) { + case 0: /* Draw */ + ro_gui_save_open(GUI_SAVE_DRAW, c, true, + warning->pos.x, warning->pos.y, + 0); + break; - case 1: - default: /* Save */ - gui_current_save_type = GUI_SAVE_SOURCE; - break; + case 1: /* Text */ + ro_gui_save_open(GUI_SAVE_TEXT, c, true, + warning->pos.x, warning->pos.y, + 0); + break; } - ro_gui_menu_prepare_save(c); - error = xwimp_create_sub_menu((wimp_menu *) dialog_saveas, - warning->pos.x, warning->pos.y); break; - case MENU_OBJECT: /* Object -> */ - switch (warning->selection.items[1]) { - case 0: /* Object info */ - ro_gui_menu_objectinfo(warning); - return; - - case 1: /* Save */ - gui_current_save_type = GUI_SAVE_OBJECT_ORIG; - break; - case 2: /* Export */ - switch (warning->selection.items[2]) { - case 0: /* Sprite */ - gui_current_save_type = GUI_SAVE_OBJECT_NATIVE; - break; - } - break; - case 3: /* Save Link */ - switch (warning->selection.items[2]) { - case 0: /* URI */ - gui_current_save_type = GUI_SAVE_LINK_URI; - break; - - case 1: /* URL */ - gui_current_save_type = GUI_SAVE_LINK_URL; - break; - - case 2: /* Text */ - gui_current_save_type = GUI_SAVE_LINK_TEXT; - break; - } - break; - } - struct box *box = ro_gui_menu_find_object_box(); - if (box) { - ro_gui_menu_prepare_save(box->object); - error = xwimp_create_sub_menu((wimp_menu *) dialog_saveas, - warning->pos.x, warning->pos.y); + case 4: /* Save Link */ + switch (warning->selection.items[2]) { + case 0: /* URI */ + ro_gui_save_open(GUI_SAVE_LINK_URI, c, true, + warning->pos.x, warning->pos.y, + 0); + break; + + case 1: /* URL */ + ro_gui_save_open(GUI_SAVE_LINK_URL, c, true, + warning->pos.x, warning->pos.y, + 0); + break; + + case 2: /* Text */ + ro_gui_save_open(GUI_SAVE_LINK_TEXT, c, true, + warning->pos.x, warning->pos.y, + 0); + break; } break; - case MENU_NAVIGATE: /* Navigate -> */ - ro_gui_prepare_navigate(current_gui); - error = xwimp_create_sub_menu(browser_navigate_menu, - warning->pos.x, warning->pos.y); + } + break; + + case MENU_OBJECT: /* Object -> */ + /** \todo this is really dumb, the object should be the one + * that the user clicked menu over, not the one that happens to + * be under the menu now */ + box = ro_gui_menu_find_object_box(); + if (!box) break; - case MENU_VIEW: /* View -> */ - switch (warning->selection.items[1]) { - case 0: /* Scale view -> */ - ro_gui_menu_prepare_scale(); - error = xwimp_create_sub_menu((wimp_menu *) dialog_zoom, - warning->pos.x, warning->pos.y); - break; - case 1: /* Images -> */ - ro_gui_menu_prepare_images(); - error = xwimp_create_sub_menu(browser_image_menu, - warning->pos.x, warning->pos.y); - break; - case 2: /* Toolbars -> */ - ro_gui_menu_prepare_toolbars(); - error = xwimp_create_sub_menu(browser_toolbar_menu, - warning->pos.x, warning->pos.y); - break; - case 3: /* Window -> */ - ro_gui_menu_prepare_window(); - error = xwimp_create_sub_menu(browser_window_menu, - warning->pos.x, warning->pos.y); - break; + + switch (warning->selection.items[1]) { + case 0: /* Object info */ + ro_gui_menu_objectinfo(warning); + return; + + case 1: /* Save */ + ro_gui_save_open(GUI_SAVE_OBJECT_ORIG, box->object, + true, + warning->pos.x, warning->pos.y, 0); + break; + + case 2: /* Export */ + switch (warning->selection.items[2]) { + case 0: /* Sprite */ + ro_gui_save_open(GUI_SAVE_OBJECT_NATIVE, + box->object, true, + warning->pos.x, warning->pos.y, + 0); + break; } break; - case MENU_HELP: /* Help -> */ - ro_gui_menu_prepare_help(false); - error = xwimp_create_sub_menu(browser_help_menu, - warning->pos.x, warning->pos.y); - } + case 3: /* Save Link */ + switch (warning->selection.items[2]) { + case 0: /* URI */ + ro_gui_save_open(GUI_SAVE_LINK_URI, + box->object, true, + warning->pos.x, warning->pos.y, + 0); + break; - if (error) { - LOG(("0x%x: %s\n", error->errnum, error->errmess)); - warn_user("MenuError", error->errmess); - } -} + case 1: /* URL */ + ro_gui_save_open(GUI_SAVE_LINK_URL, + box->object, true, + warning->pos.x, warning->pos.y, + 0); + break; + case 2: /* Text */ + ro_gui_save_open(GUI_SAVE_LINK_TEXT, + box->object, true, + warning->pos.x, warning->pos.y, + 0); + break; + } + break; + } + break; + + case MENU_NAVIGATE: /* Navigate -> */ + ro_gui_prepare_navigate(current_gui); + error = xwimp_create_sub_menu(browser_navigate_menu, + warning->pos.x, warning->pos.y); + break; + + case MENU_VIEW: /* View -> */ + switch (warning->selection.items[1]) { + case 0: /* Scale view -> */ + ro_gui_menu_prepare_scale(); + error = xwimp_create_sub_menu((wimp_menu *) dialog_zoom, + warning->pos.x, warning->pos.y); + break; -/** - * Handle Message_MenuWarning for the hotlist menu. - */ -void ro_gui_menu_hotlist_warning(wimp_message_menu_warning *warning) { - os_error *error = NULL; // No warnings + case 1: /* Images -> */ + ro_gui_menu_prepare_images(); + error = xwimp_create_sub_menu(browser_image_menu, + warning->pos.x, warning->pos.y); + break; - switch (warning->selection.items[0]) { - case 0: /* Hotlist-> */ - switch (warning->selection.items[1]) { - case 0: /* New-> */ - hotlist_insert = true; - switch (warning->selection.items[2]) { - case 0: /* Folder */ - ro_gui_hotlist_prepare_folder_dialog(false); - error = xwimp_create_sub_menu((wimp_menu *) dialog_folder, - warning->pos.x, warning->pos.y); - break; - case 1: /* Entry */ - ro_gui_hotlist_prepare_entry_dialog(false); - error = xwimp_create_sub_menu((wimp_menu *) dialog_entry, - warning->pos.x, warning->pos.y); - } - break; - case 2: /* Export-> */ - gui_current_save_type = GUI_HOTLIST_EXPORT_HTML; - ro_gui_menu_prepare_save(NULL); - error = xwimp_create_sub_menu((wimp_menu *) dialog_saveas, - warning->pos.x, warning->pos.y); - break; - } + case 2: /* Toolbars -> */ + ro_gui_menu_prepare_toolbars(); + error = xwimp_create_sub_menu(browser_toolbar_menu, + warning->pos.x, warning->pos.y); break; - case 1: /* Selection-> */ - switch (warning->selection.items[1]) { - case -1: /* Root */ - ro_gui_menu_prepare_hotlist(); - error = xwimp_create_sub_menu(hotlist_select_menu, - warning->pos.x, warning->pos.y); - break; - case 0: /* Save-> */ - break; - case 1: /* Edit-> */ - hotlist_insert = true; - if (ro_gui_hotlist_get_selected(false) == 0) { - ro_gui_hotlist_prepare_folder_dialog(true); - error = xwimp_create_sub_menu((wimp_menu *) dialog_folder, - warning->pos.x, warning->pos.y); - } else { - ro_gui_hotlist_prepare_entry_dialog(true); - error = xwimp_create_sub_menu((wimp_menu *) dialog_entry, - warning->pos.x, warning->pos.y); - } - break; - } + + case 3: /* Window -> */ + ro_gui_menu_prepare_window(); + error = xwimp_create_sub_menu(browser_window_menu, + warning->pos.x, warning->pos.y); break; + } + break; + + case MENU_HELP: /* Help -> */ + ro_gui_menu_prepare_help(false); + error = xwimp_create_sub_menu(browser_help_menu, + warning->pos.x, warning->pos.y); } - + if (error) { - LOG(("0x%x: %s\n", error->errnum, error->errmess)); + LOG(("xwimp_create_sub_menu: 0x%x: %s", + error->errnum, error->errmess)); warn_user("MenuError", error->errmess); } } /** - * Prepares the save box to reflect gui_current_save_type and a content. - * - * \param c content to save + * Handle Message_MenuWarning for the hotlist menu. */ -void ro_gui_menu_prepare_save(struct content *c) +void ro_gui_menu_hotlist_warning(wimp_message_menu_warning *warning) { - char icon_buf[20] = "file_xxx"; - const char *icon = icon_buf; - const char *name = ""; - const char *nice; + os_error *error = 0; -/* We can't assert globally any more as hotlists have no content -*/ - if (gui_current_save_type != GUI_HOTLIST_EXPORT_HTML) { - assert(c); - } - - - switch (gui_current_save_type) { - case GUI_SAVE_SOURCE: - sprintf(icon_buf, "file_%x", ro_content_filetype(c)); - name = messages_get("SaveSource"); - break; - - case GUI_SAVE_DRAW: - icon = "file_aff"; - name = messages_get("SaveDraw"); - break; - - case GUI_SAVE_TEXT: - icon = "file_fff"; - name = messages_get("SaveText"); - break; - - case GUI_SAVE_COMPLETE: - icon = "file_faf"; - name = messages_get("SaveComplete"); - break; - case GUI_SAVE_OBJECT_ORIG: - if (c) - sprintf(icon_buf, "file_%x", - ro_content_filetype(c)); - name = messages_get("SaveObject"); - break; - case GUI_SAVE_OBJECT_NATIVE: - icon = "file_ff9"; - name = messages_get("SaveObject"); + switch (warning->selection.items[0]) { + case 0: /* Hotlist-> */ + switch (warning->selection.items[1]) { + case 0: /* New-> */ + hotlist_insert = true; + switch (warning->selection.items[2]) { + case 0: /* Folder */ + ro_gui_hotlist_prepare_folder_dialog(false); + error = xwimp_create_sub_menu( + (wimp_menu *) dialog_folder, + warning->pos.x, warning->pos.y); + break; + case 1: /* Entry */ + ro_gui_hotlist_prepare_entry_dialog(false); + error = xwimp_create_sub_menu( + (wimp_menu *) dialog_entry, + warning->pos.x, warning->pos.y); + } break; - case GUI_SAVE_LINK_URI: - icon = "file_f91"; - name = messages_get("SaveLink"); + case 2: /* Export-> */ + ro_gui_save_open(GUI_SAVE_HOTLIST_EXPORT_HTML, 0, true, + warning->pos.x, warning->pos.y, 0); break; - case GUI_SAVE_LINK_URL: - icon = "file_b28"; - name = messages_get("SaveLink"); + } + break; + case 1: /* Selection-> */ + switch (warning->selection.items[1]) { + case -1: /* Root */ + ro_gui_menu_prepare_hotlist(); + error = xwimp_create_sub_menu(hotlist_select_menu, + warning->pos.x, warning->pos.y); break; - case GUI_SAVE_LINK_TEXT: - icon = "file_fff"; - name = messages_get("SaveLink"); + case 0: /* Save-> */ break; - case GUI_HOTLIST_EXPORT_HTML: - icon = "file_faf"; - name = "Hotlist"; + case 1: /* Edit-> */ + hotlist_insert = true; + if (ro_gui_hotlist_get_selected(false) == 0) { + ro_gui_hotlist_prepare_folder_dialog(true); + error = xwimp_create_sub_menu( + (wimp_menu *) dialog_folder, + warning->pos.x, warning->pos.y); + } else { + ro_gui_hotlist_prepare_entry_dialog(true); + error = xwimp_create_sub_menu( + (wimp_menu *) dialog_entry, + warning->pos.x, warning->pos.y); + } break; + } + break; } - save_content = c; - if (c) { - if ((nice = url_nice(c->url))) name = nice; - } - - /* Ensure the correct icon exists - */ - if (xwimpspriteop_read_sprite_info(icon, 0, 0, 0, 0)) { - icon = "file_xxx"; + if (error) { + LOG(("xwimp_create_sub_menu: 0x%x: %s", + error->errnum, error->errmess)); + warn_user("MenuError", error->errmess); } - - /* Update the GUI - */ - ro_gui_set_icon_string(dialog_saveas, ICON_SAVE_ICON, icon); - ro_gui_set_icon_string(dialog_saveas, ICON_SAVE_PATH, name); } @@ -1328,11 +1284,11 @@ void ro_gui_menu_prepare_scale(void) { * Update hotlist menu (all of) */ void ro_gui_menu_prepare_hotlist(void) { - int selection; - int selection_full; + int selection; + int selection_full; selection = ro_gui_hotlist_get_selected(false); selection_full = ro_gui_hotlist_get_selected(true); - + if (selection_full == 0) { hotlist_menu->entries[1].icon_flags |= wimp_ICON_SHADED; hotlist_menu->entries[3].icon_flags |= wimp_ICON_SHADED; diff --git a/riscos/save.c b/riscos/save.c index 5518b2f4a..cd6c6be4f 100644 --- a/riscos/save.c +++ b/riscos/save.c @@ -27,11 +27,12 @@ #include "netsurf/riscos/wimp.h" #include "netsurf/utils/log.h" #include "netsurf/utils/messages.h" +#include "netsurf/utils/url.h" #include "netsurf/utils/utils.h" -gui_save_type gui_current_save_type; - -extern struct content *save_content; +static gui_save_type gui_save_current_type; +static struct content *gui_save_content = 0; +static int gui_save_filetype; typedef enum { LINK_ACORN, LINK_ANT, LINK_TEXT } link_format; @@ -40,6 +41,87 @@ static void ro_gui_save_object_native(struct content *c, char *path); static bool ro_gui_save_link(struct content *c, link_format format, char *path); +/** An entry in gui_save_table. */ +struct gui_save_table_entry { + int filetype; + const char *name; +}; + +/** Table of filetypes and default filenames. Must be in sync with + * gui_save_type (riscos/gui.h). A filetype of 0 indicates the content should + * be used. */ +struct gui_save_table_entry gui_save_table[] = { + /* GUI_SAVE_SOURCE, */ { 0, "SaveSource" }, + /* GUI_SAVE_DRAW, */ { 0xaff, "SaveDraw" }, + /* GUI_SAVE_TEXT, */ { 0xfff, "SaveText" }, + /* GUI_SAVE_COMPLETE, */ { 0xfaf, "SaveComplete" }, + /* GUI_SAVE_OBJECT_ORIG, */ { 0, "SaveObject" }, + /* GUI_SAVE_OBJECT_NATIVE, */ { 0xff9, "SaveObject" }, + /* GUI_SAVE_LINK_URI, */ { 0xf91, "SaveLink" }, + /* GUI_SAVE_LINK_URL, */ { 0xb28, "SaveLink" }, + /* GUI_SAVE_LINK_TEXT, */ { 0xfff, "SaveLink" }, + /* GUI_SAVE_HOTLIST_EXPORT_HTML, */ { 0xfaf, "Hotlist" }, +}; + + +/** + * Prepares the save box to reflect gui_save_type and a content, and + * opens it. + * + * \param save_type type of save + * \param c content to save + * \param sub_menu open dialog as a sub menu, otherwise persistent + * \param x x position, for sub_menu true only + * \param y y position, for sub_menu true only + * \param parent parent window for persistent box, for sub_menu false only + */ + +void ro_gui_save_open(gui_save_type save_type, struct content *c, + bool sub_menu, int x, int y, wimp_w parent) +{ + char icon_buf[20]; + const char *icon = icon_buf; + const char *name = ""; + const char *nice; + os_error *error; + + assert(save_type == GUI_SAVE_HOTLIST_EXPORT_HTML || c); + + gui_save_current_type = save_type; + gui_save_content = c; + gui_save_filetype = gui_save_table[save_type].filetype; + if (!gui_save_filetype) + gui_save_filetype = ro_content_filetype(c); + + /* icon */ + sprintf(icon_buf, "file_%.3x", gui_save_filetype); + if (!ro_gui_wimp_sprite_exists(icon_buf)) + icon = "file_xxx"; + ro_gui_set_icon_string(dialog_saveas, ICON_SAVE_ICON, icon); + + /* filename */ + name = gui_save_table[save_type].name; + if (c) { + if ((nice = url_nice(c->url))) + name = nice; + } + ro_gui_set_icon_string(dialog_saveas, ICON_SAVE_PATH, name); + + /* open sub menu or persistent dialog */ + if (sub_menu) { + error = xwimp_create_sub_menu((wimp_menu *) dialog_saveas, + x, y); + if (error) { + LOG(("xwimp_create_sub_menu: 0x%x: %s", + error->errnum, error->errmess)); + warn_user("MenuError", error->errmess); + } + } else { + ro_gui_dialog_open_persistant(parent, dialog_saveas); + } +} + + /** * Handle clicks in the save dialog. */ @@ -55,7 +137,7 @@ void ro_gui_save_click(wimp_pointer *pointer) xwimp_close_window(pointer->w); xwimp_create_menu((wimp_menu *)-1, 0, 0); } else if (pointer->buttons == wimp_CLICK_ADJUST) { - ro_gui_menu_prepare_save(save_content); +/* ro_gui_menu_prepare_save(gui_save_content); */ } break; case ICON_SAVE_ICON: @@ -122,27 +204,8 @@ void ro_gui_save_drag_end(wimp_dragged *drag) message.data.data_xfer.pos.x = pointer.pos.x; message.data.data_xfer.pos.y = pointer.pos.y; message.data.data_xfer.est_size = 1000; - - /* set the filetype correctly */ - message.data.data_xfer.file_type = 0xfaf; /* default = html */ - if (gui_current_save_type == GUI_SAVE_DRAW) - message.data.data_xfer.file_type = 0xaff; - else if (gui_current_save_type == GUI_SAVE_TEXT || - gui_current_save_type == GUI_SAVE_LINK_TEXT) - message.data.data_xfer.file_type = 0xfff; - else if (gui_current_save_type == GUI_SAVE_LINK_URI) - message.data.data_xfer.file_type = 0xf91; - else if (gui_current_save_type == GUI_SAVE_LINK_URL) - message.data.data_xfer.file_type = 0xb28; - /* object as native type. - * assume sprite here, although this isn't guaranteed - */ - else if (gui_current_save_type == GUI_SAVE_OBJECT_NATIVE) - message.data.data_xfer.file_type = 0xff9; - /* don't change the type as we've no idea what it is - else if (gui_current_save_type == GUI_SAVE_OBJECT_ORIG) - */ - if (gui_current_save_type == GUI_SAVE_COMPLETE) { + message.data.data_xfer.file_type = gui_save_filetype; + if (gui_save_current_type == GUI_SAVE_COMPLETE) { message.data.data_xfer.file_type = 0x2000; if (name[0] != '!') { message.data.data_xfer.file_name[0] = '!'; @@ -169,17 +232,18 @@ void ro_gui_save_drag_end(wimp_dragged *drag) void ro_gui_save_datasave_ack(wimp_message *message) { char *path = message->data.data_xfer.file_name; - struct content *c = save_content; + struct content *c = gui_save_content; os_error *error; - if (!save_content && gui_current_save_type != GUI_HOTLIST_EXPORT_HTML) { - LOG(("unexpected DataSaveAck: save_content not set")); + if (!gui_save_content && + gui_save_current_type != GUI_SAVE_HOTLIST_EXPORT_HTML) { + LOG(("unexpected DataSaveAck: gui_save_content not set")); return; } ro_gui_set_icon_string(dialog_saveas, ICON_SAVE_PATH, path); - switch (gui_current_save_type) { + switch (gui_save_current_type) { case GUI_SAVE_SOURCE: error = xosfile_save_stamped(path, ro_content_filetype(c), @@ -239,7 +303,7 @@ void ro_gui_save_datasave_ack(wimp_message *message) if (!ro_gui_save_link(c, LINK_TEXT, path)) return; break; - case GUI_HOTLIST_EXPORT_HTML: + case GUI_SAVE_HOTLIST_EXPORT_HTML: ro_gui_hotlist_save_as(path); break; } @@ -266,7 +330,7 @@ void ro_gui_save_datasave_ack(wimp_message *message) warn_user("MenuError", error->errmess); } - save_content = 0; + gui_save_content = 0; } diff --git a/riscos/wimp.c b/riscos/wimp.c index 3a6ee3fd4..40f26f686 100644 --- a/riscos/wimp.c +++ b/riscos/wimp.c @@ -10,14 +10,16 @@ */ #include <assert.h> -#include <string.h> +#include <stdbool.h> #include <stdlib.h> +#include <string.h> #include <stdio.h> #include "oslib/os.h" #include "oslib/osfile.h" #include "oslib/wimp.h" #include "oslib/wimpextend.h" #include "oslib/wimpreadsysinfo.h" +#include "oslib/wimpspriteop.h" #include "netsurf/desktop/gui.h" #include "netsurf/riscos/wimp.h" #include "netsurf/utils/log.h" @@ -248,7 +250,7 @@ int ro_gui_get_icon_selected_state(wimp_w w, wimp_i i) { void ro_gui_set_window_title(wimp_w w, const char *text) { wimp_window_info_base window; os_error *error; - + /* Get the window details */ window.w = w; @@ -259,14 +261,14 @@ void ro_gui_set_window_title(wimp_w w, const char *text) { warn_user("WimpError", error->errmess); return; } - + /* Set the title string */ strncpy(window.title_data.indirected_text.text, text, (unsigned int)window.title_data.indirected_text.size - 1); window.title_data.indirected_text.text[window.title_data.indirected_text.size - 1] = '\0'; } - + /** * Load a sprite file into memory. @@ -318,3 +320,27 @@ osspriteop_area *ro_gui_load_sprite_file(const char *pathname) return area; } + + +/** + * Check if a sprite is present in the Wimp sprite pool. + * + * \param sprite name of sprite + * \return true if the sprite is present + */ + +bool ro_gui_wimp_sprite_exists(const char *sprite) +{ + os_error *error; + + error = xwimpspriteop_select_sprite(sprite, 0); + if (error) { + if (error->errnum != error_SPRITE_OP_DOESNT_EXIST) { + LOG(("xwimpspriteop_select_sprite: 0x%x: %s", + error->errnum, error->errmess)); + warn_user("MiscError", error->errmess); + } + return false; + } + return true; +} diff --git a/riscos/wimp.h b/riscos/wimp.h index 763f00631..4936d1e42 100644 --- a/riscos/wimp.h +++ b/riscos/wimp.h @@ -42,5 +42,6 @@ int ro_gui_get_icon_selected_state(wimp_w w, wimp_i i); void ro_gui_set_window_title(wimp_w w, const char *title); osspriteop_area *ro_gui_load_sprite_file(const char *pathname); +bool ro_gui_wimp_sprite_exists(const char *sprite); #endif diff --git a/riscos/window.c b/riscos/window.c index 3609c9a40..7e3bbae24 100644 --- a/riscos/window.c +++ b/riscos/window.c @@ -748,11 +748,9 @@ void ro_gui_toolbar_click(gui_window* g, wimp_pointer* pointer) { case ICON_TOOLBAR_SAVE: current_gui = g; - gui_current_save_type = GUI_SAVE_SOURCE; - ro_gui_menu_prepare_save(g->data.browser.bw->current_content); - /** \todo make save window persistent */ - xwimp_create_menu((wimp_menu *) dialog_saveas, - pointer->pos.x, pointer->pos.y); + ro_gui_save_open(GUI_SAVE_SOURCE, + g->data.browser.bw->current_content, + false, 0, 0, g->window); break; } } @@ -999,30 +997,26 @@ bool ro_gui_window_keypress(gui_window *g, int key, bool toolbar) case wimp_KEY_F3: current_gui = g; - gui_current_save_type = GUI_SAVE_SOURCE; - ro_gui_menu_prepare_save(content); - ro_gui_dialog_open_persistant(g->window, dialog_saveas); + ro_gui_save_open(GUI_SAVE_SOURCE, content, + false, 0, 0, g->window); return true; case wimp_KEY_CONTROL + wimp_KEY_F3: current_gui = g; - gui_current_save_type = GUI_SAVE_TEXT; - ro_gui_menu_prepare_save(content); - ro_gui_dialog_open_persistant(g->window, dialog_saveas); + ro_gui_save_open(GUI_SAVE_TEXT, content, + false, 0, 0, g->window); return true; case wimp_KEY_SHIFT + wimp_KEY_F3: current_gui = g; - gui_current_save_type = GUI_SAVE_COMPLETE; - ro_gui_menu_prepare_save(content); - ro_gui_dialog_open_persistant(g->window, dialog_saveas); + ro_gui_save_open(GUI_SAVE_COMPLETE, content, + false, 0, 0, g->window); return true; case wimp_KEY_CONTROL + wimp_KEY_SHIFT + wimp_KEY_F3: current_gui = g; - gui_current_save_type = GUI_SAVE_DRAW; - ro_gui_menu_prepare_save(content); - ro_gui_dialog_open_persistant(g->window, dialog_saveas); + ro_gui_save_open(GUI_SAVE_DRAW, content, + false, 0, 0, g->window); return true; case wimp_KEY_RETURN: |