diff --git a/riscos/gui.c b/riscos/gui.c index 8ae1fd26c..49c71f77e 100644 --- a/riscos/gui.c +++ b/riscos/gui.c @@ -71,13 +71,14 @@ static clock_t gui_last_poll; /**< Time of last wimp_poll. */ osspriteop_area *gui_sprites; /**< Sprite area containing pointer and hotlist sprites */ /** Accepted wimp user messages. */ -static wimp_MESSAGE_LIST(28) task_messages = { { +static wimp_MESSAGE_LIST(29) task_messages = { { message_HELP_REQUEST, message_DATA_SAVE, message_DATA_SAVE_ACK, message_DATA_LOAD, message_DATA_OPEN, message_MENU_WARNING, + message_MENUS_DELETED, #ifdef WITH_URI message_URI_PROCESS, message_URI_RETURN_RESULT, @@ -386,6 +387,7 @@ void ro_gui_check_resolvers(void) void gui_quit(void) { + ro_gui_hotlist_save(); ro_gui_history_quit(); free(gui_sprites); wimp_close_down(task_handle); @@ -834,6 +836,11 @@ void ro_gui_user_message(wimp_event_no event, wimp_message *message) ro_gui_menu_warning((wimp_message_menu_warning *) &message->data); break; + case message_MENUS_DELETED: + if (current_menu == hotlist_menu) { + ro_gui_hotlist_menu_closed(); + } + break; #ifdef WITH_URI case message_URI_PROCESS: diff --git a/riscos/gui.h b/riscos/gui.h index 2ab06f165..3980ba2eb 100644 --- a/riscos/gui.h +++ b/riscos/gui.h @@ -27,7 +27,7 @@ extern wimp_w dialog_info, dialog_saveas, dialog_config, dialog_config_br, dialog_debug; extern wimp_w history_window; extern wimp_w hotlist_window; -extern wimp_menu *iconbar_menu, *browser_menu, *combo_menu; +extern wimp_menu *iconbar_menu, *browser_menu, *combo_menu, *hotlist_menu; extern int iconbar_menu_height; extern struct form_control *current_gadget; extern gui_window *window_list; @@ -177,6 +177,7 @@ void ro_gui_history_mouse_at(wimp_pointer *pointer); /* in hotlist.c */ void ro_gui_hotlist_init(void); +void ro_gui_hotlist_save(void); void ro_gui_hotlist_show(void); void ro_gui_hotlist_add(char *title, struct content *content); void ro_gui_hotlist_redraw(wimp_draw *redraw); @@ -184,6 +185,7 @@ void ro_gui_hotlist_click(wimp_pointer *pointer); void ro_gui_hotlist_selection_drag_end(wimp_dragged *drag); void ro_gui_hotlist_move_drag_end(wimp_dragged *drag); bool ro_gui_hotlist_keypress(int key); +void ro_gui_hotlist_menu_closed(void); /* in save.c */ void ro_gui_save_click(wimp_pointer *pointer); diff --git a/riscos/hotlist.c b/riscos/hotlist.c index f791d24aa..96297a62e 100644 --- a/riscos/hotlist.c +++ b/riscos/hotlist.c @@ -33,6 +33,13 @@ #define HOTLIST_TEXT_BUFFER 256 +#define HOTLIST_LEAF_INSET 32 +#define HOTLIST_ICON_WIDTH 36 +#define HOTLIST_LINE_HEIGHT 44 +#define HOTLIST_TEXT_PADDING 16 + +#define HOTLIST_LOAD_BUFFER 1024 + struct hotlist_entry { /** The next hotlist entry at this level, or NULL for no more @@ -120,7 +127,7 @@ static wimp_window hotlist_window_definition = { 1, 1, {"Hotlist"}, - 0, + 0 }; /* An icon to plot text with @@ -165,11 +172,17 @@ static osspriteop_trans_tab *pixel_table; */ wimp_mouse_state drag_buttons; +/* Whether the current selection was from a menu click +*/ +bool menu_selection = false; + +/* Hotlist loading buffer +*/ +char *load_buf; static bool ro_gui_hotlist_load(void); -static void ro_gui_hotlist_save(void); -static bool ro_gui_hotlist_save_entry(FILE *fp, struct hotlist_entry entry); -static bool ro_gui_hotlist_load_entry(FILE *fp, struct hotlist_entry entry); +static bool ro_gui_hotlist_save_entry(FILE *fp, struct hotlist_entry *entry); +static bool ro_gui_hotlist_load_entry(FILE *fp, struct hotlist_entry *entry); static void ro_gui_hotlist_link_entry(struct hotlist_entry *parent, struct hotlist_entry *entry); static void ro_gui_hotlist_visited_update(struct content *content, struct hotlist_entry *entry); static int ro_gui_hotlist_redraw_tree(struct hotlist_entry *entry, int level, int x0, int y0); @@ -184,18 +197,14 @@ static void ro_gui_hotlist_selection_drag(struct hotlist_entry *entry, bool toggle, bool redraw); static int ro_gui_hotlist_selection_count(struct hotlist_entry *entry); static void ro_gui_hotlist_update_expansion(struct hotlist_entry *entry, bool only_selected, - bool expand, bool contract); + bool folders, bool links, bool expand, bool contract); +static void ro_gui_hotlist_launch_selection(struct hotlist_entry *entry); static char *last_visit_to_string(time_t last_visit); void ro_gui_hotlist_init(void) { os_error *error; - /* Ensure we have a directory to save to later. - */ - xosfile_create_dir(".WWW", 0); - xosfile_create_dir(".WWW.NetSurf", 0); - /* Set the initial root options */ root.next_entry = NULL; @@ -206,7 +215,7 @@ void ro_gui_hotlist_init(void) { /* Load the hotlist */ if (!ro_gui_hotlist_load()) { - return; +// return; } /* Get our sprite ids for faster plotting. This could be done in a @@ -291,7 +300,7 @@ void ro_gui_hotlist_show(void) { if (!(state.flags & wimp_WINDOW_OPEN)) { /* Clear the selection/expansion states */ - ro_gui_hotlist_update_expansion(root.child_entry, false, false, true); + ro_gui_hotlist_update_expansion(root.child_entry, false, true, true, false, true); ro_gui_hotlist_selection_state(root.child_entry, false, false); /* Get the current screen size @@ -324,7 +333,8 @@ bool ro_gui_hotlist_load(void) { fileswitch_object_type obj_type = 0; struct hotlist_entry *netsurf; struct hotlist_entry *entry; - bool success; + bool success = true; + bool found = false; /* Check if we have an initial hotlist. OS_File does funny things relating to errors, so we use the object type to determine success @@ -340,9 +350,34 @@ bool ro_gui_hotlist_load(void) { return false; } + /* Get some memory to work with + */ + load_buf = malloc(HOTLIST_LOAD_BUFFER); + if (!load_buf) { + warn_user("HotlistLoadError", 0); + fclose(fp); + return false; + } + + /* Check for the opening to vaguely validate our file + */ + if ((fgets(load_buf, HOTLIST_LOAD_BUFFER, fp) == NULL) || + (strncmp("", load_buf, 6) != 0)) { + warn_user("HotlistLoadError", 0); + free(load_buf); + fclose(fp); + return false; + } + + /* Keep reading until we get to a