[project @ 2005-02-08 23:34:56 by rjw]

Implement nodes being retained in memory after deletion, stop nodes being able to be moved within themselves.

svn path=/import/netsurf/; revision=1507
This commit is contained in:
Richard Wilson 2005-02-08 23:34:56 +00:00
parent 91ec410b7c
commit acb914b90a
3 changed files with 112 additions and 18 deletions

View File

@ -19,8 +19,6 @@
#include "netsurf/utils/log.h"
#include "netsurf/utils/utils.h"
static void tree_recalculate_node(struct node *node, bool recalculate_sizes);
static void tree_recalculate_node_positions(struct node *root);
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);
@ -463,10 +461,17 @@ struct node_element *tree_find_element(struct node *node, int user_type) {
*/
void tree_move_selected_nodes(struct tree *tree, struct node *destination, bool before) {
struct node *link;
struct node *test;
bool error;
tree_clear_processing(tree->root);
tree_selected_to_processing(tree->root);
if (destination->processing) {
/* the destination node cannot be a child of any node with the processing flag set */
error = destination->processing;
for (test = destination; test; test = test->parent)
error |= test->processing;
if (error) {
tree_clear_processing(tree->root);
return;
}
@ -778,7 +783,7 @@ void tree_link_node(struct node *link, struct node *node, bool before) {
assert(link);
assert(node);
if ((!link->folder) || (before)) {
node->parent = link->parent;
if (before) {
@ -808,6 +813,7 @@ void tree_link_node(struct node *link, struct node *node, bool before) {
node->parent = link;
node->next = NULL;
}
node->deleted = false;
}
@ -876,21 +882,25 @@ void tree_delete_node(struct tree *tree, struct node *node, bool siblings) {
next = node->next;
if (node->child)
tree_delete_node(tree, node->child, true);
node->child = NULL;
parent = node->parent;
tree_delink_node(node);
for (element = &node->data; element; element = element->next) {
if (element->text)
free(element->text);
if (element->sprite)
free(element->sprite); /* \todo platform specific bits */
if (!node->retain_in_memory) {
for (element = &node->data; element; element = element->next) {
if (element->text)
free(element->text);
if (element->sprite)
free(element->sprite); /* \todo platform specific bits */
}
while (node->data.next) {
element = node->data.next->next;
free(node->data.next);
node->data.next = element;
}
free(node);
} else {
node->deleted = true;
}
while (node->data.next) {
element = node->data.next->next;
free(node->data.next);
node->data.next = element;
}
free(node);
if (!siblings)
node = NULL;
else
@ -1010,6 +1020,51 @@ 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.
*
* \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
* \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 *node;
struct node_element *element;
assert(title);
assert(url);
node = tree_create_leaf_node(parent, title);
if (!node)
return NULL;
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;
}
tree_update_URL_node(node);
node->expanded = true;
tree_recalculate_node(node, true);
node->expanded = false;
return node;
}
/**
* Resets all selected URL nodes from the tree.
*

View File

@ -18,6 +18,7 @@
#define TREE_ELEMENT_ADDED 2
#define TREE_ELEMENT_LAST_VISIT 3
#define TREE_ELEMENT_VISITS 4
#define TREE_ELEMENT_VISITED 5
#define NODE_INSTEP 40
@ -55,6 +56,8 @@ struct node {
bool expanded; /* <-- Whether the node is expanded */
bool folder; /* <-- Whether the node is a folder */
bool editable; /* <-- Whether the node is editable */
bool retain_in_memory; /* <-- Whether the node remains in memory after deletion */
bool deleted; /* <-- Whether the node is currently deleted */
bool processing; /* <-- Internal flag used when moving */
struct node_element_box box; /* <-- Bounding box of all elements */
struct node_element data; /* <-- Data to display */
@ -89,6 +92,8 @@ void tree_handle_node_changed(struct tree *tree, struct node *node,
bool recalculate_sizes, bool expansion);
void tree_handle_node_element_changed(struct tree *tree,
struct node_element *element);
void tree_recalculate_node(struct node *node, bool recalculate_sizes);
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);
@ -107,6 +112,8 @@ void tree_set_node_sprite(struct node *node, const char *sprite,
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);
void tree_set_node_expanded(struct node *node, bool expanded);
void tree_set_node_selected(struct tree *tree, struct node *node,

View File

@ -466,6 +466,22 @@ void tree_update_URL_node(struct node *node) {
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"));
}
element->text = strdup(buffer);
}
element = tree_find_element(node, TREE_ELEMENT_VISITS);
if (element) {
if (element->text) {
@ -1213,10 +1229,13 @@ void ro_gui_tree_get_tree_coordinates(struct tree *tree, int x, int y,
* \param drag the drag box information
*/
void ro_gui_tree_move_drag_end(wimp_dragged *drag) {
struct gui_window *g;
wimp_pointer pointer;
wimp_auto_scroll_info scroll;
os_error *error;
struct node *node;
struct node *single;
struct node_element *element;
bool before;
int x, y;
@ -1232,11 +1251,24 @@ void ro_gui_tree_move_drag_end(wimp_dragged *drag) {
return;
}
/* todo: handle export */
if (pointer.w != (wimp_w)ro_gui_tree_current_drag_tree->handle)
if (pointer.w != (wimp_w)ro_gui_tree_current_drag_tree->handle) {
/* try to drop into a browser window */
single = tree_get_selected_node(ro_gui_tree_current_drag_tree->root->child);
element = tree_find_element(single, TREE_ELEMENT_URL);
if ((single) && (element)) {
g = ro_gui_window_lookup(pointer.w);
if (g)
browser_window_go(g->bw, element->text, 0);
return;
}
/* todo: handle export */
return;
}
/* internal drag */
if (!ro_gui_tree_current_drag_tree->movable)
return;
ro_gui_tree_get_tree_coordinates(ro_gui_tree_current_drag_tree,
drag->final.x0 + 34, drag->final.y0 + 34, &x, &y);
node = tree_get_link_details(ro_gui_tree_current_drag_tree, x, y, &before);