summaryrefslogtreecommitdiff
path: root/desktop
diff options
context:
space:
mode:
authorRichard Wilson <rjw@netsurf-browser.org>2005-12-31 04:37:57 +0000
committerRichard Wilson <rjw@netsurf-browser.org>2005-12-31 04:37:57 +0000
commit39e41ea386dcb574d09352cd1a7110c845410088 (patch)
tree70cdb3394a2635136a98d7a474de555ec7517459 /desktop
parent442f0e2a2c8b57af092b765bdb843bd1c16fa976 (diff)
downloadnetsurf-39e41ea386dcb574d09352cd1a7110c845410088.tar.gz
netsurf-39e41ea386dcb574d09352cd1a7110c845410088.tar.bz2
[project @ 2005-12-31 04:37:56 by rjw]
Read URL data from url_store. Scroll items into view when expanding. svn path=/import/netsurf/; revision=1914
Diffstat (limited to 'desktop')
-rw-r--r--desktop/tree.c158
-rw-r--r--desktop/tree.h30
2 files changed, 68 insertions, 120 deletions
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 <stdio.h>
#include <stdlib.h>
#include <string.h>
+#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 <stdbool.h>
+#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);