Add relevent extensions to allow treeviews to be used as an embedded list component.

svn path=/trunk/netsurf/; revision=2753
This commit is contained in:
Richard Wilson 2006-07-15 15:39:33 +00:00
parent 4c564c28bf
commit 546bf17a7f
5 changed files with 102 additions and 75 deletions

View File

@ -49,12 +49,12 @@ void tree_initialise(struct tree *tree) {
assert(tree);
tree_set_node_expanded(tree->root, true);
tree_initialise_nodes(tree->root);
tree_recalculate_node_positions(tree->root);
tree_set_node_expanded(tree->root, false);
tree_set_node_expanded(tree, tree->root, true);
tree_initialise_nodes(tree, tree->root);
tree_recalculate_node_positions(tree, tree->root);
tree_set_node_expanded(tree, tree->root, false);
tree->root->expanded = true;
tree_recalculate_node_positions(tree->root);
tree_recalculate_node_positions(tree, tree->root);
tree_recalculate_size(tree);
}
@ -64,22 +64,22 @@ void tree_initialise(struct tree *tree) {
*
* \param root the root node to update from
*/
void tree_initialise_nodes(struct node *root) {
void tree_initialise_nodes(struct tree *tree, struct node *root) {
struct node *node;
assert(root);
tree_initialising++;
for (node = root; node; node = node->next) {
tree_recalculate_node(node, true);
tree_recalculate_node(tree, node, true);
if (node->child) {
tree_initialise_nodes(node->child);
tree_initialise_nodes(tree, node->child);
}
}
tree_initialising--;
if (tree_initialising == 0)
tree_recalculate_node_positions(root);
tree_recalculate_node_positions(tree, root);
}
@ -98,16 +98,16 @@ void tree_handle_node_changed(struct tree *tree, struct node *node,
assert(node);
if ((expansion) && (node->expanded) && (node->child)) {
tree_set_node_expanded(node->child, false);
tree_set_node_expanded(tree, node->child, false);
tree_set_node_selected(tree, node->child, false);
}
width = node->box.width;
height = node->box.height;
if ((recalculate_sizes) || (expansion))
tree_recalculate_node(node, true);
tree_recalculate_node(tree, node, true);
if ((node->box.height != height) || (expansion)) {
tree_recalculate_node_positions(tree->root);
tree_recalculate_node_positions(tree, tree->root);
tree_redraw_area(tree, 0, node->box.y, 16384, 16384);
} else {
width = (width > node->box.width) ? width : node->box.width;
@ -135,11 +135,11 @@ void tree_handle_node_element_changed(struct tree *tree, struct node_element *el
tree_recalculate_node_element(element);
if (element->box.height != height) {
tree_recalculate_node(element->parent, false);
tree_recalculate_node(tree, element->parent, false);
tree_redraw_area(tree, 0, element->box.y, 16384, 16384);
} else {
if (element->box.width != width)
tree_recalculate_node(element->parent, false);
tree_recalculate_node(tree, element->parent, false);
width = (width > element->box.width) ? width :
element->box.width;
tree_redraw_area(tree, element->box.x, element->box.y, width, element->box.height);
@ -153,7 +153,7 @@ void tree_handle_node_element_changed(struct tree *tree, struct node_element *el
* \param node the node to update
* \param recalculate_sizes whether the node elements have changed
*/
void tree_recalculate_node(struct node *node, bool recalculate_sizes) {
void tree_recalculate_node(struct tree *tree, struct node *node, bool recalculate_sizes) {
struct node_element *element;
int width, height;
@ -186,7 +186,7 @@ void tree_recalculate_node(struct node *node, bool recalculate_sizes) {
if (height != node->box.height) {
for (; node->parent; node = node->parent);
if (tree_initialising == 0)
tree_recalculate_node_positions(node);
tree_recalculate_node_positions(tree, node);
}
}
@ -196,7 +196,7 @@ void tree_recalculate_node(struct node *node, bool recalculate_sizes) {
*
* \param root the root node to update from
*/
void tree_recalculate_node_positions(struct node *root) {
void tree_recalculate_node_positions(struct tree *tree, struct node *root) {
struct node *parent;
struct node *node;
struct node *child;
@ -216,14 +216,14 @@ void tree_recalculate_node_positions(struct node *root) {
child = child->next)
node->box.y += child->box.height;
} else {
node->box.x = 0;
node->box.x = tree->no_furniture ? -NODE_INSTEP + 8 : 0;
node->box.y = -40;
}
if (node->expanded) {
if (node->folder) {
node->data.box.x = node->box.x;
node->data.box.y = node->box.y;
tree_recalculate_node_positions(node->child);
tree_recalculate_node_positions(tree, node->child);
} else {
y = node->box.y;
for (element = &node->data; element;
@ -305,14 +305,14 @@ int tree_get_node_height(struct node *node) {
* \param node the node to set all siblings and descendants of
* \param expanded the expansion state to set
*/
void tree_set_node_expanded(struct node *node, bool expanded) {
void tree_set_node_expanded(struct tree *tree, struct node *node, bool expanded) {
for (; node; node = node->next) {
if (node->expanded != expanded) {
node->expanded = expanded;
tree_recalculate_node(node, false);
tree_recalculate_node(tree, node, false);
}
if ((node->child) && (node->expanded))
tree_set_node_expanded(node->child, expanded);
tree_set_node_expanded(tree, node->child, expanded);
}
}
@ -337,18 +337,18 @@ bool tree_handle_expansion(struct tree *tree, struct node *node, bool expanded,
((folder && (node->folder)) || (leaf && (!node->folder)))) {
node->expanded = expanded;
if (node->child)
tree_set_node_expanded(node->child, false);
tree_set_node_expanded(tree, node->child, false);
if ((node->data.next) && (node->data.next->box.height == 0))
tree_recalculate_node(node, true);
tree_recalculate_node(tree, node, true);
else
tree_recalculate_node(node, false);
tree_recalculate_node(tree, node, false);
redraw = true;
}
if ((node->child) && (node->expanded))
redraw |= tree_handle_expansion(tree, node->child, expanded, folder, leaf);
}
if ((entry == tree->root) && (redraw)) {
tree_recalculate_node_positions(tree->root);
tree_recalculate_node_positions(tree, tree->root);
tree_redraw_area(tree, 0, 0, 16384, 16384);
tree_recalculate_size(tree);
}
@ -493,7 +493,7 @@ void tree_move_selected_nodes(struct tree *tree, struct node *destination, bool
link = tree_move_processing_node(tree->root, link, false, false);
tree_clear_processing(tree->root);
tree_recalculate_node_positions(tree->root);
tree_recalculate_node_positions(tree, tree->root);
tree_redraw_area(tree, 0, 0, 16384, 16384);
}
@ -718,28 +718,30 @@ void tree_draw_node(struct tree *tree, struct node *node, int clip_x, int clip_y
for (; node; node = node->next) {
if (node->box.y > y_max) return;
if (node->next)
if ((node->next) && (!tree->no_furniture))
tree_draw_line(node->box.x - (NODE_INSTEP / 2),
node->box.y + (40 / 2), 0,
node->next->box.y - node->box.y);
if ((node->box.x < x_max) && (node->box.y < y_max) &&
(node->box.x + node->box.width + NODE_INSTEP >= clip_x) &&
(node->box.y + node->box.height >= clip_y)) {
if ((node->expanded) && (node->child))
tree_draw_line(node->box.x + (NODE_INSTEP / 2),
node->data.box.y + node->data.box.height, 0,
(40 / 2));
if ((node->parent) && (node->parent != tree->root) &&
(node->parent->child == node))
tree_draw_line(node->parent->box.x + (NODE_INSTEP / 2),
if (!tree->no_furniture) {
if ((node->expanded) && (node->child))
tree_draw_line(node->box.x + (NODE_INSTEP / 2),
node->data.box.y + node->data.box.height, 0,
(40 / 2));
if ((node->parent) && (node->parent != tree->root) &&
(node->parent->child == node))
tree_draw_line(node->parent->box.x + (NODE_INSTEP / 2),
node->parent->data.box.y +
node->parent->data.box.height, 0,
(40 / 2));
tree_draw_line(node->box.x - (NODE_INSTEP / 2),
node->data.box.y +
node->data.box.height - (40 / 2),
(NODE_INSTEP / 2) - 4, 0);
tree_draw_node_expansion(tree, node);
(40 / 2));
tree_draw_line(node->box.x - (NODE_INSTEP / 2),
node->data.box.y +
node->data.box.height - (40 / 2),
(NODE_INSTEP / 2) - 4, 0);
tree_draw_node_expansion(tree, node);
}
if (node->expanded)
for (element = &node->data; element;
element = element->next)
@ -935,7 +937,7 @@ void tree_delete_node(struct tree *tree, struct node *node, bool siblings) {
if (siblings && next)
tree_delete_node(tree, next, true);
tree_recalculate_node_positions(tree->root);
tree_recalculate_node_positions(tree, tree->root);
tree_redraw_area(tree, 0, 0, 16384, 16384); /* \todo correct area */
tree_recalculate_size(tree);
}
@ -964,7 +966,6 @@ struct node *tree_create_folder_node(struct node *parent, const char *title) {
tree_set_node_sprite_folder(node);
if (parent)
tree_link_node(parent, node, false);
tree_recalculate_node(node, true);
return node;
}
@ -1061,7 +1062,6 @@ struct node *tree_create_URL_node(struct node *parent,
element->text = strdup(url);
tree_update_URL_node(node, url, NULL);
tree_recalculate_node(node, false);
return node;
}
@ -1104,7 +1104,6 @@ struct node *tree_create_URL_node_shared(struct node *parent,
element->text = url;
tree_update_URL_node(node, url, data);
tree_recalculate_node(node, false);
return node;
}
@ -1113,8 +1112,8 @@ struct node *tree_create_URL_node_shared(struct node *parent,
/**
* Creates a tree entry for a cookie, and links it into the tree.
*
* All information is used directly from the cookie_data, and as such cannot
* be edited and should never be freed.
* All information is copied from the cookie_data, and as such can
* be edited and should be freed.
*
* \param parent the node to link to
* \param url the URL
@ -1201,10 +1200,7 @@ struct node *tree_create_cookie_node(struct node *parent,
element->text = strdup(buffer);
}
/* add version, last_used, expires,
* path, domain, comment, value */
tree_set_node_sprite(node, "small_xxx", "small_xxx");
tree_recalculate_node(node, false);
return node;
}

View File

@ -96,6 +96,9 @@ struct tree {
int height; /* <-- Tree height */
int window_width; /* <-- Tree window width */
int window_height; /* <-- Tree window height */
bool no_vscroll; /* <-- Tree has a vertical scroll only when needed */
bool no_furniture; /* <-- Tree does not have connecting lines */
bool single_selection; /* <-- There can only be one item selected */
int edit_handle; /* <-- Handle for editing information */
uintptr_t textarea_handle; /* <-- Handle for UTF-8 textarea */
bool movable; /* <-- Whether nodes can be moved */
@ -107,13 +110,13 @@ struct tree {
/* Non-platform specific code */
void tree_initialise(struct tree *tree);
void tree_initialise_nodes(struct node *root);
void tree_initialise_nodes(struct tree *tree, struct node *root);
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);
void tree_recalculate_node(struct tree *tree, struct node *node, bool recalculate_sizes);
void tree_recalculate_node_positions(struct tree *tree, 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);
@ -135,7 +138,7 @@ struct node *tree_create_URL_node_shared(struct node *parent,
const char *url, const struct url_data *data);
struct node *tree_create_cookie_node(struct node *parent,
const struct cookie_data *data);
void tree_set_node_expanded(struct node *node, bool expanded);
void tree_set_node_expanded(struct tree *tree, struct node *node, bool expanded);
void tree_set_node_selected(struct tree *tree, struct node *node,
bool selected);
void tree_handle_selection_area(struct tree *tree, int x, int y, int width,

View File

@ -314,7 +314,7 @@ bool global_history_add_internal(const char *url,
tree_link_node(link, parent, before);
if (!global_history_init) {
tree_recalculate_node_positions(
tree_recalculate_node_positions(global_history_tree,
global_history_tree->root);
tree_redraw_area(global_history_tree,
0, 0, 16384, 16384);

View File

@ -344,23 +344,25 @@ void tree_draw_node_element(struct tree *tree, struct node_element *element) {
0xffffff,
false, false, false,
IMAGE_PLOT_TINCT_OPAQUE);
tree_draw_line(element->box.x,
element->box.y,
element->box.width - 1,
0);
tree_draw_line(element->box.x,
element->box.y,
0,
element->box.height - 3);
tree_draw_line(element->box.x,
element->box.y + element->box.height - 3,
element->box.width - 1,
0);
tree_draw_line(element->box.x + element->box.width - 1,
element->box.y,
0,
element->box.height - 3);
}
if (!tree->no_furniture) {
tree_draw_line(element->box.x,
element->box.y,
element->box.width - 1,
0);
tree_draw_line(element->box.x,
element->box.y,
0,
element->box.height - 3);
tree_draw_line(element->box.x,
element->box.y + element->box.height - 3,
element->box.width - 1,
0);
tree_draw_line(element->box.x + element->box.width - 1,
element->box.y,
0,
element->box.height - 3);
}
}
break;
}
}
@ -716,6 +718,10 @@ bool ro_gui_tree_click(wimp_pointer *pointer, struct tree *tree) {
/* no item either means cancel selection on (select) click or a drag */
if (!element) {
if (tree->single_selection) {
tree_set_node_selected(tree, tree->root->child, false);
return true;
}
if ((pointer->buttons == (wimp_CLICK_SELECT << 4)) ||
(pointer->buttons == (wimp_CLICK_SELECT << 8)))
tree_set_node_selected(tree, tree->root->child, false);
@ -824,7 +830,9 @@ bool ro_gui_tree_click(wimp_pointer *pointer, struct tree *tree) {
}
/* single click (select) cancels current selection and selects item */
if (pointer->buttons == (wimp_CLICK_SELECT << 8)) {
if ((pointer->buttons == (wimp_CLICK_SELECT << 8)) ||
((pointer->buttons == (wimp_CLICK_ADJUST << 8)) &&
(tree->single_selection))) {
if (!node->selected) {
tree_set_node_selected(tree, tree->root->child, false);
node->selected = true;
@ -843,6 +851,8 @@ bool ro_gui_tree_click(wimp_pointer *pointer, struct tree *tree) {
/* drag starts a drag operation */
if ((!tree->editing) && ((pointer->buttons == (wimp_CLICK_SELECT << 4)) ||
(pointer->buttons == (wimp_CLICK_ADJUST << 4)))) {
if (tree->single_selection)
return true;
if (!node->selected) {
node->selected = true;
@ -1159,6 +1169,7 @@ void ro_gui_tree_open(wimp_open *open) {
int width;
int height;
int toolbar_height = 0;
bool vscroll;
tree = (struct tree *)ro_gui_wimp_event_get_user_data(open->w);
@ -1182,6 +1193,21 @@ void ro_gui_tree_open(wimp_open *open) {
error->errnum, error->errmess));
warn_user("WimpError", error->errmess);
}
/* hide the scroll bar? */
if ((tree->no_vscroll) && (height != tree->window_height)) {
vscroll = (tree->height > height);
if (ro_gui_wimp_check_window_furniture(open->w,
wimp_WINDOW_VSCROLL) != vscroll) {
ro_gui_wimp_update_window_furniture(open->w,
0, wimp_WINDOW_VSCROLL);
if (vscroll)
open->visible.x1 -= ro_get_vscroll_width(open->w);
else
open->visible.x1 += ro_get_vscroll_width(open->w);
}
}
tree->window_width = width;
tree->window_height = height;
}

View File

@ -868,11 +868,13 @@ void ro_gui_user_redraw(wimp_draw *redraw, bool user_fill,
void ro_gui_wimp_update_window_furniture(wimp_w w, wimp_window_flags bic_mask,
wimp_window_flags xor_mask) {
wimp_window_state state;
wimp_w parent;
bits linkage;
os_error *error;
bool open;
state.w = w;
error = xwimp_get_window_state(&state);
error = xwimp_get_window_state_and_nesting(&state, &parent, &linkage);
if (error) {
LOG(("xwimp_get_window_state: 0x%x: %s",
error->errnum, error->errmess));
@ -886,7 +888,7 @@ void ro_gui_wimp_update_window_furniture(wimp_w w, wimp_window_flags bic_mask,
state.flags ^= xor_mask;
if (!open)
state.next = wimp_HIDDEN;
error = xwimp_open_window_nested_with_flags(&state, (wimp_w)-1, 0);
error = xwimp_open_window_nested_with_flags(&state, parent, linkage);
if (error) {
LOG(("xwimp_open_window: 0x%x: %s",
error->errnum, error->errmess));