diff --git a/desktop/tree.c b/desktop/tree.c index df3cb92ca..346f64ec1 100644 --- a/desktop/tree.c +++ b/desktop/tree.c @@ -14,6 +14,7 @@ #include #include #include +#include "netsurf/content/url_store.h" #include "netsurf/desktop/tree.h" #include "netsurf/desktop/options.h" #include "netsurf/utils/log.h" @@ -21,10 +22,9 @@ static void tree_draw_node(struct tree *tree, struct node *node, int clip_x, int clip_y, int clip_width, int clip_height); -static struct node_element *tree_create_node_element(struct node *parent, int user_type); +static struct node_element *tree_create_node_element(struct node *parent, node_element_data data); static int tree_get_node_width(struct node *node); static int tree_get_node_height(struct node *node); -static void tree_reset_URL_node(struct tree *tree, struct node *node); static void tree_handle_selection_area_node(struct tree *tree, struct node *node, int x, int y, int width, int height, bool invert); static void tree_selected_to_processing(struct node *node); @@ -448,10 +448,10 @@ struct node_element *tree_get_node_element_at(struct node *node, int x, int y, * \param user_type the user_type to check for * \return the corresponding element */ -struct node_element *tree_find_element(struct node *node, int user_type) { +struct node_element *tree_find_element(struct node *node, node_element_data data) { struct node_element *element; for (element = &node->data; element; element = element->next) - if (element->user_type == user_type) return element; + if (element->data == data) return element; return NULL; } @@ -891,8 +891,13 @@ void tree_delete_node(struct tree *tree, struct node *node, bool siblings) { tree_delink_node(node); if (!node->retain_in_memory) { for (element = &node->data; element; element = element->next) { - if (element->text) - free(element->text); + if (element->text) { + /* we don't free non-editable titles or URLs */ + if ((node->editable) || + ((node->data.data != TREE_ELEMENT_TITLE) && + (node->data.data != TREE_ELEMENT_URL))) + free(element->text); + } if (element->sprite) free(element->sprite); /* \todo platform specific bits */ } @@ -961,6 +966,7 @@ struct node *tree_create_leaf_node(struct node *parent, const char *title) { node->data.parent = node; node->data.type = NODE_ELEMENT_TEXT; node->data.text = squash_whitespace(title); + node->data.data = TREE_ELEMENT_TITLE; if (parent) tree_link_node(parent, node, false); return node; @@ -969,51 +975,38 @@ struct node *tree_create_leaf_node(struct node *parent, const char *title) { /** * Creates a tree entry for a URL, and links it into the tree + * * * \param parent the node to link to - * \param title the node title - * \param url the node URL - * \param filetype the node filetype - * \param add_date the date added - * \param last_date the last visited date - * \param visits the number of visits + * \param data the URL data to use + * \param title the custom title to use * \return the node created, or NULL for failure */ -struct node *tree_create_URL_node(struct node *parent, const char *title, - const char *url, int filetype, int add_date, int last_date, int visits) { +struct node *tree_create_URL_node(struct node *parent, struct url_content *data, + char *title) { struct node *node; struct node_element *element; - assert(url); - if (!title) - title = url; + assert(data); + if (!title) { + if (data->title) + title = strdup(data->title); + else + title = strdup(data->url); + if (!title) + return NULL; + } node = tree_create_leaf_node(parent, title); if (!node) return NULL; node->editable = true; element = tree_create_node_element(node, TREE_ELEMENT_URL); - if (element) { - element->user_data = filetype; - element->type = NODE_ELEMENT_TEXT; - element->text = strdup(url); - } - element = tree_create_node_element(node, TREE_ELEMENT_ADDED); - if (element) { - element->type = NODE_ELEMENT_TEXT; - element->user_data = add_date; - } - element = tree_create_node_element(node, TREE_ELEMENT_LAST_VISIT); - if (element) { - element->type = NODE_ELEMENT_TEXT; - element->user_data = last_date; - } - element = tree_create_node_element(node, TREE_ELEMENT_VISITS); - if (element) { - element->type = NODE_ELEMENT_TEXT; - element->user_data = visits; - } + if (element) + element->text = strdup(data->url); + tree_create_node_element(node, TREE_ELEMENT_LAST_VISIT); + tree_create_node_element(node, TREE_ELEMENT_VISITS); element = tree_create_node_element(node, TREE_ELEMENT_THUMBNAIL); if (element) element->type = NODE_ELEMENT_THUMBNAIL; @@ -1027,43 +1020,40 @@ struct node *tree_create_URL_node(struct node *parent, const char *title, /** * Creates a tree entry for a URL, and links it into the tree. + * + * All information is used directly from the url_content, and as such cannot be + * edited and should never be freed. * * \param parent the node to link to - * \param title the node title - * \param url the node URL - * \param filetype the node filetype - * \param visit_date the date visited + * \param data the URL data to use * \return the node created, or NULL for failure */ -struct node *tree_create_URL_node_brief(struct node *parent, const char *title, - const char *url, int filetype, int visit_date) { +struct node *tree_create_URL_node_shared(struct node *parent, struct url_content *data) { struct node *node; struct node_element *element; + char *title; - assert(url); - if (!title) - title = url; + assert(data); + if (data->title) + title = data->title; + else + title = data->url; node = tree_create_leaf_node(parent, title); if (!node) return NULL; + free(node->data.text); + node->data.text = title; node->editable = false; element = tree_create_node_element(node, TREE_ELEMENT_URL); - if (element) { - element->user_data = filetype; - element->type = NODE_ELEMENT_TEXT; - element->text = squash_whitespace(url); - } - element = tree_create_node_element(node, TREE_ELEMENT_VISITED); - if (element) { - element->type = NODE_ELEMENT_TEXT; - element->user_data = visit_date; - } + if (element) + element->text = data->url; + tree_create_node_element(node, TREE_ELEMENT_LAST_VISIT); + tree_create_node_element(node, TREE_ELEMENT_VISITS); element = tree_create_node_element(node, TREE_ELEMENT_THUMBNAIL); - if (element) { + if (element) element->type = NODE_ELEMENT_THUMBNAIL; - } tree_update_URL_node(node); tree_recalculate_node(node, false); @@ -1073,56 +1063,13 @@ struct node *tree_create_URL_node_brief(struct node *parent, const char *title, /** - * Resets all selected URL nodes from the tree. - * - * \param tree the tree to reset from - * \param node the node to reset - * \param selected whether to only reset selected nodes - */ -void tree_reset_URL_nodes(struct tree *tree, struct node *node, bool selected) { - for (; node; node = node->next) { - if (((node->selected) || (!selected)) && (!node->folder)) - tree_reset_URL_node(tree, node); - if (node->child) - tree_reset_URL_nodes(tree, node->child, - ((!node->selected) && selected)); - } -} - - -/** - * Resets a tree entry for a URL - */ -void tree_reset_URL_node(struct tree *tree, struct node *node) { - struct node_element *element; - - assert(tree); - assert(node); - - element = tree_find_element(node, TREE_ELEMENT_LAST_VISIT); - if (element) - element->user_data = -1; - element = tree_find_element(node, TREE_ELEMENT_VISITS); - if (element) - element->user_data = 0; - tree_update_URL_node(node); - tree_recalculate_node(node, true); - - if (node->expanded) - tree_redraw_area(tree, node->box.x, node->box.y + node->data.box.height, - node->box.width, node->box.height - node->data.box.height); - -} - - -/** - * Creates an empty node element and links it to a node. + * Creates an empty text node element and links it to a node. * * \param parent the parent node * \param user_type the required user_type * \return the newly created element. */ -struct node_element *tree_create_node_element(struct node *parent, int user_type) { +struct node_element *tree_create_node_element(struct node *parent, node_element_data data) { struct node_element *element; struct node_element *link; @@ -1131,9 +1078,10 @@ struct node_element *tree_create_node_element(struct node *parent, int user_type element = calloc(sizeof(struct node_element), 1); if (!element) return NULL; element->parent = parent; - element->user_type = user_type; + element->data = data; + element->type = NODE_ELEMENT_TEXT; - for (link = parent->data.next; ((link) && (link->user_type < user_type)); + for (link = parent->data.next; ((link) && (link->data < data)); link = link->next); if (link) { element->next = link->next; diff --git a/desktop/tree.h b/desktop/tree.h index 9f0749b5d..1c92b9f2f 100644 --- a/desktop/tree.h +++ b/desktop/tree.h @@ -13,13 +13,17 @@ #define _NETSURF_DESKTOP_TREE_H_ #include +#include "netsurf/content/url_store.h" -#define TREE_ELEMENT_URL 1 -#define TREE_ELEMENT_ADDED 2 -#define TREE_ELEMENT_LAST_VISIT 3 -#define TREE_ELEMENT_VISITS 4 -#define TREE_ELEMENT_VISITED 5 -#define TREE_ELEMENT_THUMBNAIL 6 +typedef enum { + TREE_ELEMENT_URL, + TREE_ELEMENT_ADDED, + TREE_ELEMENT_LAST_VISIT, + TREE_ELEMENT_VISITS, + TREE_ELEMENT_VISITED, + TREE_ELEMENT_THUMBNAIL, + TREE_ELEMENT_TITLE +} node_element_data; #define NODE_INSTEP 40 @@ -49,8 +53,7 @@ struct node_element { char *text; /* <-- Text for the element */ struct node_sprite *sprite; /* <-- Sprite for the element */ struct node_element *next; /* <-- Next node element */ - int user_data; /* <-- Private user data */ - int user_type; /* <-- Private user data */ + node_element_data data; /* <-- Data being represented */ }; @@ -101,7 +104,7 @@ void tree_recalculate_node_positions(struct node *root); struct node *tree_get_node_at(struct node *root, int x, int y, bool *furniture); struct node_element *tree_get_node_element_at(struct node *node, int x, int y, bool *furniture); -struct node_element *tree_find_element(struct node *node, int user_type); +struct node_element *tree_find_element(struct node *node, node_element_data data); void tree_move_selected_nodes(struct tree *tree, struct node *destination, bool before); bool tree_has_selection(struct node *node); @@ -113,12 +116,9 @@ struct node *tree_create_folder_node(struct node *parent, const char *title); struct node *tree_create_leaf_node(struct node *parent, const char *title); void tree_set_node_sprite(struct node *node, const char *sprite, const char *expanded); -struct node *tree_create_URL_node(struct node *parent, const char *title, - const char *url, int filetype, int add_date, int last_date, - int visits); -struct node *tree_create_URL_node_brief(struct node *parent, const char *title, - const char *url, int filetype, int visit_date); -void tree_reset_URL_nodes(struct tree *tree, struct node *node, bool selected); +struct node *tree_create_URL_node(struct node *parent, struct url_content *data, + char *title); +struct node *tree_create_URL_node_shared(struct node *parent, struct url_content *data); void tree_set_node_expanded(struct node *node, bool expanded); void tree_set_node_selected(struct tree *tree, struct node *node, bool selected); diff --git a/riscos/treeview.c b/riscos/treeview.c index 5a1a77752..fdb7d229d 100644 --- a/riscos/treeview.c +++ b/riscos/treeview.c @@ -24,6 +24,7 @@ #include "netsurf/desktop/browser.h" #include "netsurf/desktop/tree.h" #include "netsurf/riscos/bitmap.h" +#include "netsurf/riscos/dialog.h" #include "netsurf/riscos/gui.h" #include "netsurf/riscos/image.h" #include "netsurf/riscos/menus.h" @@ -31,6 +32,7 @@ #include "netsurf/riscos/tinct.h" #include "netsurf/riscos/treeview.h" #include "netsurf/riscos/wimp.h" +#include "netsurf/riscos/wimp_event.h" #include "netsurf/utils/log.h" #include "netsurf/utils/messages.h" #include "netsurf/utils/utils.h" @@ -458,8 +460,12 @@ void tree_recalculate_node_element(struct node_element *element) { if (url_element) bitmap = url_store_get_thumbnail(url_element->text); if (bitmap) { +/* if ((bitmap->width == 0) && (bitmap->height == 0)) + frame = bitmap_get_buffer(bitmap); element->box.width = bitmap->width * 2 + 2; element->box.height = bitmap->height * 2 + 4; +*/ element->box.width = THUMBNAIL_WIDTH * 2 + 2; + element->box.height = THUMBNAIL_HEIGHT * 2 + 4; } else { element->box.width = 0; element->box.height = 0; @@ -510,76 +516,52 @@ void tree_set_node_sprite_folder(struct node *node) { * \param node the node to update */ void tree_update_URL_node(struct node *node) { + struct url_content *data; struct node_element *element; char buffer[256]; - + assert(node); - + element = tree_find_element(node, TREE_ELEMENT_URL); + if (!element) + return; + data = url_store_find(element->text); + if (!data) + return; + + /* data may have moved */ + if (!node->editable) { + if (data->title) + node->data.text = data->title; + else + node->data.text = data->url; + } if (element) { - sprintf(buffer, "small_%.3x", element->user_data); + sprintf(buffer, "small_%.3x", ro_content_filetype_from_type(data->type)); if (ro_gui_wimp_sprite_exists(buffer)) tree_set_node_sprite(node, buffer, buffer); else tree_set_node_sprite(node, "small_xxx", "small_xxx"); } - element = tree_find_element(node, TREE_ELEMENT_ADDED); - if (element) { - if (element->text) { - free(element->text); - element->text = NULL; - } - if (element->user_data > 0) { - snprintf(buffer, 256, messages_get("TreeAdded"), - ctime((time_t *)&element->user_data)); - } else { - snprintf(buffer, 256, messages_get("TreeAdded"), - messages_get("TreeUnknown")); - } - element->text = strdup(buffer); - } - element = tree_find_element(node, TREE_ELEMENT_LAST_VISIT); if (element) { - if (element->text) { - free(element->text); - element->text = NULL; - } - if (element->user_data > 0) { + if (data->last_visit > 0) { snprintf(buffer, 256, messages_get("TreeLast"), - ctime((time_t *)&element->user_data)); + ctime((time_t *)&data->last_visit)); } else { snprintf(buffer, 256, messages_get("TreeLast"), messages_get("TreeUnknown")); } - element->text = strdup(buffer); - } - - element = tree_find_element(node, TREE_ELEMENT_VISITED); - if (element) { - if (element->text) { - free(element->text); - element->text = NULL; - } - if (element->user_data > 0) { - snprintf(buffer, 256, messages_get("TreeVisited"), - ctime((time_t *)&element->user_data)); - } else { - snprintf(buffer, 256, messages_get("TreeVisited"), - messages_get("TreeUnknown")); - } + free(element->text); element->text = strdup(buffer); } element = tree_find_element(node, TREE_ELEMENT_VISITS); if (element) { - if (element->text) { - free(element->text); - element->text = NULL; - } snprintf(buffer, 256, messages_get("TreeVisits"), - element->user_data); + data->visits); + free(element->text); element->text = strdup(buffer); } } @@ -606,7 +588,7 @@ void tree_resized(struct tree *tree) { return; } if (state.flags & wimp_WINDOW_OPEN) - ro_gui_tree_open((wimp_open *)&state, tree); + ro_gui_tree_open((wimp_open *)&state); } @@ -616,10 +598,14 @@ void tree_resized(struct tree *tree) { * \param redraw the area to redraw * \param tree the tree to redraw */ -void ro_gui_tree_redraw(wimp_draw *redraw, struct tree *tree) { +void ro_gui_tree_redraw(wimp_draw *redraw) { + struct tree *tree; osbool more; int clip_x0, clip_x1, clip_y0, clip_y1, origin_x, origin_y; + tree = (struct tree *)ro_gui_wimp_event_get_user_data(redraw->w); + + assert(tree); more = wimp_redraw_window(redraw); while (more) { @@ -644,11 +630,12 @@ void ro_gui_tree_redraw(wimp_draw *redraw, struct tree *tree) { * * \param pointer the pointer state * \param tree the tree to handle a click for - * \return whether the click was handled# + * \return whether the click was handled */ bool ro_gui_tree_click(wimp_pointer *pointer, struct tree *tree) { bool furniture; struct node *node; + struct node *last; struct node_element *element; int x, y; int alt_pressed = 0; @@ -769,6 +756,24 @@ bool ro_gui_tree_click(wimp_pointer *pointer, struct tree *tree) { if (!furniture) node->selected = false; tree_handle_node_changed(tree, node, false, true); + + /* find the last child node if expanded */ + last = node; + if ((last->child) && (last->expanded)) { + last = last->child; + while ((last->next) || ((last->child) && (last->expanded))) { + if (last->next) + last = last->next; + else + last = last->child; + } + } + /* scroll to the bottom element then back to the top */ + element = &last->data; + if (last->expanded) + for (; element->next; element = element->next); + ro_gui_tree_scroll_visible(tree, element); + ro_gui_tree_scroll_visible(tree, &node->data); return true; } @@ -777,8 +782,9 @@ bool ro_gui_tree_click(wimp_pointer *pointer, struct tree *tree) { return true; /* single/double alt+click starts editing */ - if ((node->editable) && (!tree->editing) && ((element->user_type == 0) || - (element->user_type == TREE_ELEMENT_URL)) && + if ((node->editable) && (!tree->editing) && + ((element->data == TREE_ELEMENT_URL) || + (element->data == TREE_ELEMENT_TITLE)) && ((pointer->buttons == wimp_CLICK_SELECT) || (pointer->buttons == (wimp_CLICK_SELECT << 8)))) { xosbyte1(osbyte_SCAN_KEYBOARD, 2 ^ 0x80, 0, &alt_pressed); @@ -795,7 +801,7 @@ bool ro_gui_tree_click(wimp_pointer *pointer, struct tree *tree) { if (!ro_gui_tree_launch_node(node)) return false; if (pointer->buttons == wimp_CLICK_ADJUST) - ro_gui_tree_keypress(wimp_KEY_CONTROL + wimp_KEY_F2, tree); + ro_gui_dialog_close((wimp_w)tree->handle); return true; } @@ -849,13 +855,9 @@ bool ro_gui_tree_click(wimp_pointer *pointer, struct tree *tree) { else sprintf(ro_gui_tree_drag_name, "directory"); } else { - element = tree_find_element(node, TREE_ELEMENT_URL); - if (element) { - sprintf(ro_gui_tree_drag_name, "file_%.3x", - element->user_data); - } else { - sprintf(ro_gui_tree_drag_name, "file_xxx"); - } + /* small_xxx -> file_xxx */ + sprintf(ro_gui_tree_drag_name, "file_%s", + node->data.sprite->name + 6); if (!ro_gui_wimp_sprite_exists(ro_gui_tree_drag_name)) sprintf(ro_gui_tree_drag_name, "file_xxx"); } @@ -902,20 +904,27 @@ void ro_gui_tree_menu_closed(struct tree *tree) { * * \param pointer the pointer state */ -void ro_gui_tree_toolbar_click(wimp_pointer* pointer, struct tree *tree) { +bool ro_gui_tree_toolbar_click(wimp_pointer* pointer) { struct node *node; + struct toolbar *toolbar = + (struct toolbar *)ro_gui_wimp_event_get_user_data(pointer->w); + assert(toolbar); + struct tree *tree = + (struct tree *)ro_gui_wimp_event_get_user_data(toolbar->parent_handle); + assert(tree); + ro_gui_tree_stop_edit(tree); if (pointer->buttons == wimp_CLICK_MENU) { ro_gui_menu_create(tree_toolbar_menu, pointer->pos.x, pointer->pos.y, (wimp_w)tree->handle); - return; + return true; } if (tree->toolbar->editor) { ro_gui_theme_toolbar_editor_click(tree->toolbar, pointer); - return; + return true; } switch (pointer->i) { @@ -938,14 +947,15 @@ void ro_gui_tree_toolbar_click(wimp_pointer* pointer, struct tree *tree) { false, true); break; case ICON_TOOLBAR_DELETE: - tree_delete_selected_nodes(tree, - tree->root); + ro_gui_menu_handle_action((wimp_w)tree->handle, + TREE_SELECTION_DELETE, false); break; case ICON_TOOLBAR_LAUNCH: - ro_gui_tree_launch_selected(tree); + ro_gui_menu_handle_action((wimp_w)tree->handle, + TREE_SELECTION_LAUNCH, false); break; } - ro_gui_menu_prepare_action((wimp_w)tree->handle, TREE_SELECTION, false); + return true; } @@ -962,6 +972,7 @@ void ro_gui_tree_start_edit(struct tree *tree, struct node_element *element, wimp_window_state state; struct node *parent; int toolbar_height = 0; + int caret_x, caret_height, caret_index; assert(tree); assert(element); @@ -1006,15 +1017,17 @@ void ro_gui_tree_start_edit(struct tree *tree, struct node_element *element, if (error) LOG(("xwimp_get_window_state: 0x%x: %s", error->errnum, error->errmess)); - error = xwimp_set_caret_position((wimp_w)tree->handle, - (wimp_i)tree->edit_handle, - pointer->pos.x - state.visible.x0, 0, - element->box.height, -1); + caret_x = pointer->pos.x - state.visible.x0; + caret_height = element->box.height; + caret_index = -1; } else { - error = xwimp_set_caret_position((wimp_w)tree->handle, - (wimp_i)tree->edit_handle, - 0, 0, -1, strlen(tree->edit_buffer)); + caret_x = 0; + caret_height = -1; + caret_index = strlen(tree->edit_buffer); } + error = xwimp_set_caret_position((wimp_w)tree->handle, + (wimp_i)tree->edit_handle, + caret_x, 0, caret_height, caret_index); if (error) LOG(("xwimp_set_caret_position: 0x%x: %s", error->errnum, error->errmess)); @@ -1090,7 +1103,7 @@ void ro_gui_tree_scroll_visible(struct tree *tree, struct node_element *element) state.yscroll = state.visible.y1 - state.visible.y0 - tree->offset_y - toolbar_height - (element->box.y + element->box.height); - ro_gui_tree_open((wimp_open *)&state, tree); + ro_gui_tree_open((wimp_open *)&state); } @@ -1098,73 +1111,24 @@ void ro_gui_tree_scroll_visible(struct tree *tree, struct node_element *element) * Shows the a tree window. */ void ro_gui_tree_show(struct tree *tree) { - os_error *error; - int screen_width, screen_height; - wimp_window_state state; - int dimension; - int scroll_width; struct toolbar *toolbar; - /* We may have failed to initialise - */ + /* we may have failed to initialise */ if (!tree) return; toolbar = tree->toolbar; - /* Get the window state - */ - state.w = (wimp_w)tree->handle; - error = xwimp_get_window_state(&state); - if (error) { - warn_user("WimpError", error->errmess); - return; - } - - /* If we're open we jump to the top of the stack, if not then we - open in the centre of the screen. - */ - if (!(state.flags & wimp_WINDOW_OPEN)) { - - /* Cancel any editing - */ - if ((tree->toolbar) && (tree->toolbar->editor)) - ro_gui_theme_toggle_edit(tree->toolbar); + /* handle first time opening */ + if (!ro_gui_dialog_open_top((wimp_w)tree->handle, toolbar, 600, 800)) { ro_gui_tree_stop_edit(tree); - - /* Set the default state - */ if (tree->root->child) { tree_set_node_selected(tree, tree->root, false); tree_handle_node_changed(tree, tree->root, false, true); } - - /* Get the current screen size - */ - ro_gui_screen_size(&screen_width, &screen_height); - - /* Move to the centre - */ - dimension = 600; /*state.visible.x1 - state.visible.x0;*/ - scroll_width = ro_get_vscroll_width((wimp_w)tree->handle); - state.visible.x0 = (screen_width - (dimension + scroll_width)) / 2; - state.visible.x1 = state.visible.x0 + dimension; - dimension = 800; /*state.visible.y1 - state.visible.y0;*/ - state.visible.y0 = (screen_height - dimension) / 2; - state.visible.y1 = state.visible.y0 + dimension; - state.xscroll = 0; - state.yscroll = 0; - if (toolbar) - state.yscroll = ro_gui_theme_toolbar_height(toolbar); } - /* Open the window at the top of the stack - */ - state.next = wimp_TOP; - ro_gui_tree_open((wimp_open*)&state, tree); - - /* Set the caret position - */ - xwimp_set_caret_position(state.w, -1, -100, -100, 32, -1); + /* set the caret position */ + xwimp_set_caret_position((wimp_w)tree->handle, -1, -100, -100, 32, -1); } @@ -1172,14 +1136,16 @@ void ro_gui_tree_show(struct tree *tree) { * Handles a window open request * * \param open the window state - * \param tree the tree to handle a request for */ -void ro_gui_tree_open(wimp_open *open, struct tree *tree) { +void ro_gui_tree_open(wimp_open *open) { + struct tree *tree; os_error *error; int width; int height; int toolbar_height = 0; + tree = (struct tree *)ro_gui_wimp_event_get_user_data(open->w); + if (!tree) return; if (tree->toolbar) @@ -1223,34 +1189,28 @@ void ro_gui_tree_open(wimp_open *open, struct tree *tree) { * \param tree the tree to handle a keypress for * \return whether the key was processed */ -bool ro_gui_tree_keypress(int key, struct tree *tree) { - os_error *error; +bool ro_gui_tree_keypress(wimp_key *key) { char *new_string; + struct tree *tree; + + tree = (struct tree *)ro_gui_wimp_event_get_user_data(key->w); + if (!tree) + return false; /* Handle basic keys */ - switch (key) { + switch (key->c) { case 1: /* CTRL+A */ - ro_gui_tree_stop_edit(tree); - if (tree->root->child) { - tree->temp_selection = NULL; - tree_set_node_selected(tree, tree->root, true); - } - ro_gui_menu_prepare_action((wimp_w)tree->handle, - TREE_SELECTION, true); + ro_gui_menu_handle_action((wimp_w)tree->handle, + TREE_SELECT_ALL, false); return true; case 24: /* CTRL+X */ - ro_gui_tree_stop_edit(tree); - tree_delete_selected_nodes(tree, tree->root); - ro_gui_menu_prepare_action((wimp_w)tree->handle, - TREE_SELECTION, true); + ro_gui_menu_handle_action((wimp_w)tree->handle, + TREE_SELECTION_DELETE, false); return true; case 26: /* CTRL+Z */ - tree->temp_selection = NULL; - ro_gui_tree_stop_edit(tree); - tree_set_node_selected(tree, tree->root, false); - ro_gui_menu_prepare_action((wimp_w)tree->handle, - TREE_SELECTION, true); + ro_gui_menu_handle_action((wimp_w)tree->handle, + TREE_CLEAR_SELECTION, false); return true; case wimp_KEY_RETURN: if (tree->editing) { @@ -1268,18 +1228,13 @@ bool ro_gui_tree_keypress(int key, struct tree *tree) { ro_gui_tree_launch_selected(tree); } return true; - case wimp_KEY_CONTROL + wimp_KEY_F2: - error = xwimp_close_window((wimp_w)tree->handle); - if (error) - LOG(("xwimp_close_window: 0x%x: %s", - error->errnum, error->errmess)); - return true; case wimp_KEY_ESCAPE: if (tree->editing) { ro_gui_tree_stop_edit(tree); } else { /* \todo cancel drags etc. */ } + return true; } return false; } diff --git a/riscos/treeview.h b/riscos/treeview.h index 40ee3fbe1..3be34c4e3 100644 --- a/riscos/treeview.h +++ b/riscos/treeview.h @@ -28,14 +28,14 @@ struct node_sprite { }; bool ro_gui_tree_initialise(void); -void ro_gui_tree_redraw(wimp_draw *redraw, struct tree *tree); +void ro_gui_tree_redraw(wimp_draw *redraw); bool ro_gui_tree_click(wimp_pointer *pointer, struct tree *tree); void ro_gui_tree_menu_closed(struct tree *tree); -void ro_gui_tree_toolbar_click(wimp_pointer* pointer, struct tree *tree); +bool ro_gui_tree_toolbar_click(wimp_pointer* pointer); void ro_gui_tree_stop_edit(struct tree *tree); -void ro_gui_tree_open(wimp_open *open, struct tree *tree); +void ro_gui_tree_open(wimp_open *open); void ro_gui_tree_show(struct tree *tree); -bool ro_gui_tree_keypress(int key, struct tree *tree); +bool ro_gui_tree_keypress(wimp_key *key); void ro_gui_tree_selection_drag_end(wimp_dragged *drag); void ro_gui_tree_move_drag_end(wimp_dragged *drag); void ro_gui_tree_launch_selected(struct tree *tree);