From 610fca368b4b438fd2868f8a4d6a39a45f823e6b Mon Sep 17 00:00:00 2001 From: Richard Wilson Date: Thu, 7 Apr 2005 20:46:22 +0000 Subject: [project @ 2005-04-07 20:46:22 by rjw] Update to the way menus are handled. Various GUI bug fixes. svn path=/import/netsurf/; revision=1603 --- riscos/global_history.c | 307 +++++++++++++++++++++++------------------------- 1 file changed, 149 insertions(+), 158 deletions(-) (limited to 'riscos/global_history.c') diff --git a/riscos/global_history.c b/riscos/global_history.c index 2dbd9410d..ac04a8141 100644 --- a/riscos/global_history.c +++ b/riscos/global_history.c @@ -21,6 +21,7 @@ #include "netsurf/desktop/tree.h" #include "netsurf/riscos/global_history.h" #include "netsurf/riscos/gui.h" +#include "netsurf/riscos/menus.h" #include "netsurf/riscos/theme.h" #include "netsurf/riscos/treeview.h" #include "netsurf/utils/messages.h" @@ -45,9 +46,10 @@ static char *global_history_recent_url[GLOBAL_HISTORY_RECENT_URLS]; static int global_history_recent_count = 0; static void ro_gui_global_history_initialise_nodes(void); -static void ro_gui_global_history_initialise_node(const char *title, time_t base, - int days_back); -static void ro_gui_global_history_add(char *title, char *url, int visit_date, int filetype); +static void ro_gui_global_history_initialise_node(const char *title, + time_t base, int days_back); +static void ro_gui_global_history_add(char *title, char *url, int visit_date, + int filetype); static void ro_gui_global_history_save_node(struct node *node, FILE *fp); /* A basic window for the history @@ -91,7 +93,7 @@ struct tree *global_history_tree; void ro_gui_global_history_initialise(void) { char s[MAXIMUM_URL_LENGTH]; FILE *fp; - const char *title; + const char *title; os_error *error; char *node_title; char *node_url; @@ -101,29 +103,32 @@ void ro_gui_global_history_initialise(void) { /* Create our window */ title = messages_get("GlobalHistory"); - history_window_definition.title_data.indirected_text.text = strdup(title); + history_window_definition.title_data.indirected_text.text = + strdup(title); history_window_definition.title_data.indirected_text.validation = (char *) -1; - history_window_definition.title_data.indirected_text.size = strlen(title); - error = xwimp_create_window(&history_window_definition, &global_history_window); + history_window_definition.title_data.indirected_text.size = + strlen(title); + error = xwimp_create_window(&history_window_definition, + &global_history_window); if (error) { LOG(("xwimp_create_window: 0x%x: %s", error->errnum, error->errmess)); die(error->errmess); } - + /* Create an empty tree */ global_history_tree = calloc(sizeof(struct tree), 1); if (!global_history_tree) { - warn_user("NoMemory", 0); + warn_user("NoMemory", 0); return; } global_history_tree->root = tree_create_folder_node(NULL, "Root"); if (!global_history_tree->root) { - warn_user("NoMemory", 0); - free(global_history_tree); - global_history_tree = NULL; + warn_user("NoMemory", 0); + free(global_history_tree); + global_history_tree = NULL; } global_history_tree->root->expanded = true; ro_gui_global_history_initialise_nodes(); @@ -138,66 +143,66 @@ void ro_gui_global_history_initialise(void) { if (global_history_tree->toolbar) ro_gui_theme_attach_toolbar(global_history_tree->toolbar, global_history_window); - - /* load recent URLs */ + + /* load recent URLs */ fp = fopen(GLOBAL_HISTORY_RECENT_READ, "r"); if (!fp) LOG(("Failed to open file '%s' for reading", GLOBAL_HISTORY_RECENT_READ)); else { while (fgets(s, MAXIMUM_URL_LENGTH, fp)) { - if (s[strlen(s) - 1] == '\n') - s[strlen(s) - 1] = '\0'; + if (s[strlen(s) - 1] == '\n') + s[strlen(s) - 1] = '\0'; global_history_add_recent(s); } fclose(fp); } - /* load global history */ + /* load global history */ fp = fopen(GLOBAL_HISTORY_READ, "r"); if (!fp) LOG(("Failed to open file '%s' for reading", GLOBAL_HISTORY_READ)); else { while (fgets(s, MAXIMUM_URL_LENGTH, fp)) { - if (s[strlen(s) - 1] == '\n') - s[strlen(s) - 1] = '\0'; - node_title = strdup(s); + if (s[strlen(s) - 1] == '\n') + s[strlen(s) - 1] = '\0'; + node_title = strdup(s); if (!fgets(s, MAXIMUM_URL_LENGTH, fp)) { - LOG(("Error reading global history")); - warn_user("HistoryCorrupt", 0); - fclose(fp); - return; + LOG(("Error reading global history")); + warn_user("HistoryCorrupt", 0); + fclose(fp); + return; } - if (s[strlen(s) - 1] == '\n') - s[strlen(s) - 1] = '\0'; + if (s[strlen(s) - 1] == '\n') + s[strlen(s) - 1] = '\0'; node_url = strdup(s); - if ((!node_title) || (!node_url)) { - LOG(("No memory to read global history node")); - warn_user("NoMemory", 0); - fclose(fp); - return; - } + if ((!node_title) || (!node_url)) { + LOG(("No memory to read global history node")); + warn_user("NoMemory", 0); + fclose(fp); + return; + } if (!fgets(s, MAXIMUM_URL_LENGTH, fp)) { - LOG(("Error reading global history")); - warn_user("HistoryCorrupt", 0); - fclose(fp); - return; + LOG(("Error reading global history")); + warn_user("HistoryCorrupt", 0); + fclose(fp); + return; } node_filetype = atoi(s); if (!fgets(s, MAXIMUM_URL_LENGTH, fp)) { - LOG(("Error reading global history")); - warn_user("HistoryCorrupt", 0); - fclose(fp); - return; + LOG(("Error reading global history")); + warn_user("HistoryCorrupt", 0); + fclose(fp); + return; } node_visited = atoi(s); - ro_gui_global_history_add(node_title, node_url, node_visited, - node_filetype); - free(node_title); - node_title = NULL; - free(node_url); - node_url = NULL; + ro_gui_global_history_add(node_title, node_url, + node_visited, node_filetype); + free(node_title); + node_title = NULL; + free(node_url); + node_url = NULL; } fclose(fp); } @@ -212,12 +217,12 @@ static void ro_gui_global_history_initialise_nodes(void) { time_t t; int weekday; int i; - + /* get the current time */ t = time(NULL); if (t == -1) return; - + /* get the time at the start of today */ full_time = localtime(&t); weekday = full_time->tm_wday; @@ -227,11 +232,11 @@ static void ro_gui_global_history_initialise_nodes(void) { t = mktime(full_time); if (t == -1) return; - + ro_gui_global_history_initialise_node(messages_get("DateToday"), t, 0); if (weekday > 0) - ro_gui_global_history_initialise_node(messages_get("DateYesterday"), - t, -1); + ro_gui_global_history_initialise_node( + messages_get("DateYesterday"), t, -1); for (i = 2; i <= weekday; i++) ro_gui_global_history_initialise_node(NULL, t, -i); ro_gui_global_history_initialise_node(messages_get("Date1Week"), @@ -242,12 +247,12 @@ static void ro_gui_global_history_initialise_nodes(void) { t, -weekday - 21); } -static void ro_gui_global_history_initialise_node(const char *title, time_t base, - int days_back) { +static void ro_gui_global_history_initialise_node(const char *title, + time_t base, int days_back) { struct tm *full_time; char buffer[64]; struct node *node; - + base += days_back * 60 * 60 * 24; if (!title) { full_time = localtime(&base); @@ -282,8 +287,10 @@ void ro_gui_global_history_save(void) { GLOBAL_HISTORY_RECENT_WRITE)); else { for (i = global_history_recent_count - 1; i >= 0; i--) - if (strlen(global_history_recent_url[i]) < MAXIMUM_URL_LENGTH) - fprintf(fp, "%s\n", global_history_recent_url[i]); + if (strlen(global_history_recent_url[i]) < + MAXIMUM_URL_LENGTH) + fprintf(fp, "%s\n", + global_history_recent_url[i]); fclose(fp); } @@ -304,17 +311,19 @@ void ro_gui_global_history_save(void) { */ void ro_gui_global_history_save_node(struct node *node, FILE *fp) { struct node_element *element; - + for (; node; node = node->next) { if (node->folder) { - ro_gui_global_history_save_node(node->child, fp); + ro_gui_global_history_save_node(node->child, fp); } else { element = tree_find_element(node, TREE_ELEMENT_URL); if (element) { fprintf(fp, "%s\n%s\n%i\n", node->data.text, - element->text, element->user_data); - - element = tree_find_element(node, TREE_ELEMENT_VISITED); + element->text, + element->user_data); + + element = tree_find_element(node, + TREE_ELEMENT_VISITED); if (element) fprintf(fp, "%i\n", element->user_data); else @@ -324,14 +333,6 @@ void ro_gui_global_history_save_node(struct node *node, FILE *fp) { } } -/** - * Shows the history window. - */ -void ro_gui_global_history_show(void) { - ro_gui_tree_show(global_history_tree); - ro_gui_menu_prepare_global_history(); -} - /** * Respond to a mouse click @@ -341,32 +342,10 @@ void ro_gui_global_history_show(void) { void ro_gui_global_history_click(wimp_pointer *pointer) { ro_gui_tree_click(pointer, global_history_tree); if (pointer->buttons == wimp_CLICK_MENU) - ro_gui_create_menu(global_history_menu, pointer->pos.x, - pointer->pos.y, NULL); + ro_gui_menu_create(global_history_menu, pointer->pos.x, + pointer->pos.y, pointer->w); else - ro_gui_menu_prepare_global_history(); -} - - -/** - * Respond to a keypress - * - * \param key the key pressed - */ -bool ro_gui_global_history_keypress(int key) { - bool result = ro_gui_tree_keypress(key, global_history_tree); - ro_gui_menu_prepare_global_history(); - return result; -} - - -/** - * Handles a menu closed event - */ -void ro_gui_global_history_menu_closed(void) { - ro_gui_tree_menu_closed(global_history_tree); - current_menu = NULL; - ro_gui_menu_prepare_global_history(); + ro_gui_menu_prepare_action(pointer->w, TREE_SELECTION, false); } @@ -389,74 +368,84 @@ int ro_gui_global_history_help(int x, int y) { */ void global_history_add(struct gui_window *g) { assert(g); - - if ((!g->bw->current_content) || (!global_history_tree)) - return; - - ro_gui_global_history_add(g->bw->current_content->title, g->bw->current_content->url, time(NULL), - ro_content_filetype(g->bw->current_content)); + + if ((!g->bw->current_content) || (!global_history_tree)) + return; + + ro_gui_global_history_add(g->bw->current_content->title, + g->bw->current_content->url, time(NULL), + ro_content_filetype(g->bw->current_content)); } /** * Adds to the global history * - * \param title the page title - * \param url the page URL + * \param title the page title + * \param url the page URL * \param visit_date the visit date */ -void ro_gui_global_history_add(char *title, char *url, int visit_date, int filetype) { - int i, j; - struct node *parent = NULL; - struct node *link; - struct node *node; - struct node_element *element; - bool before = false; - - /* Find/create the node to link into - */ - for (i = 0; i < global_history_base_node_count; i++) { - if (global_history_base_node_time[i] <= visit_date) { - parent = global_history_base_node[i]; - if (parent->deleted) { - link = global_history_tree->root; - for (j = 0; j < i; j++) { - if (!global_history_base_node[j]->deleted) { - link = global_history_base_node[j]; - before = true; - break; - } - } - tree_link_node(link, parent, before); - tree_recalculate_node_positions(global_history_tree->root); - tree_redraw_area(global_history_tree, 0, 0, 16384, 16384); } - break; - } - } - - if (parent) { - /* Add the node at the bottom - */ - node = tree_create_URL_node_brief(parent, title, url, filetype, visit_date); +void ro_gui_global_history_add(char *title, char *url, int visit_date, + int filetype) { + int i, j; + struct node *parent = NULL; + struct node *link; + struct node *node; + struct node_element *element; + bool before = false; + + /* Find/create the node to link into + */ + for (i = 0; i < global_history_base_node_count; i++) { + if (global_history_base_node_time[i] <= visit_date) { + parent = global_history_base_node[i]; + if (!parent->deleted) + break; + link = global_history_tree->root; + for (j = 0; j < i; j++) { + if (!global_history_base_node[j]->deleted) { + link = global_history_base_node[j]; + before = true; + break; + } + } + tree_link_node(link, parent, before); + tree_recalculate_node_positions( + global_history_tree->root); + tree_redraw_area(global_history_tree, + 0, 0, 16384, 16384); + break; + } + } + + if (parent) { + /* Add the node at the bottom + */ + node = tree_create_URL_node_brief(parent, title, url, filetype, + visit_date); if (node) { - tree_redraw_area(global_history_tree, node->box.x - NODE_INSTEP, + tree_redraw_area(global_history_tree, + node->box.x - NODE_INSTEP, 0, NODE_INSTEP, 16384); - tree_handle_node_changed(global_history_tree, node, false, - true); + tree_handle_node_changed(global_history_tree, node, + false, true); } - /* Remove any duplicate URL from within the parent node. This must be done after - the duplicate has been created as deleting all children of a child automatically - collapses the display. - */ - for (node = parent->child; node && (node->next); node = node->next) { - element = tree_find_element(node, TREE_ELEMENT_URL); - if ((element) && (!strcmp(url, element->text))) { - tree_delete_node(global_history_tree, node, false); - break; - } - } - } + /* Remove any duplicate URL from within the parent node. + * This must be done after the duplicate has been created as + * deleting all children of a child automatically collapses + * the display. + */ + for (node = parent->child; node && (node->next); + node = node->next) { + element = tree_find_element(node, TREE_ELEMENT_URL); + if ((element) && (!strcmp(url, element->text))) { + tree_delete_node(global_history_tree, node, + false); + break; + } + } + } } @@ -470,31 +459,33 @@ void global_history_add_recent(const char *url) { int i; int j = -1; char *current; - - /* by using the url_store, we get a central char* of the string that isn't - * going anywhere unless we tell it to */ + + /* by using the url_store, we get a central char* of the string that + * isn't going anywhere unless we tell it to */ data = url_store_find(url); if (!data) return; - + /* try to find a string already there */ for (i = 0; i < global_history_recent_count; i++) if (global_history_recent_url[i] == data->url) j = i; - + /* already at head of list */ if (j == 0) return; - + /* add to head of list */ if (j < 0) { memmove(&global_history_recent_url[1], &global_history_recent_url[0], - (GLOBAL_HISTORY_RECENT_URLS - 1) * sizeof(char *)); + (GLOBAL_HISTORY_RECENT_URLS - 1) * + sizeof(char *)); global_history_recent_url[0] = data->url; global_history_recent_count++; if (global_history_recent_count > GLOBAL_HISTORY_RECENT_URLS) - global_history_recent_count = GLOBAL_HISTORY_RECENT_URLS; + global_history_recent_count = + GLOBAL_HISTORY_RECENT_URLS; if (global_history_recent_count == 1) ro_gui_window_prepare_navigate_all(); } else { -- cgit v1.2.3