Author: paulblokus
Date: Tue Jun 30 18:59:14 2009
New Revision: 8213
URL:
http://source.netsurf-browser.org?rev=8213&view=rev
Log:
simplify icon requiring
Modified:
branches/paulblokus/treeview/desktop/options.c
branches/paulblokus/treeview/desktop/options.h
branches/paulblokus/treeview/desktop/tree.c
branches/paulblokus/treeview/desktop/tree.h
branches/paulblokus/treeview/desktop/tree_url_node.c
branches/paulblokus/treeview/desktop/tree_url_node.h
branches/paulblokus/treeview/gtk/gtk_gui.c
branches/paulblokus/treeview/gtk/gtk_treeview.c
Modified: branches/paulblokus/treeview/desktop/options.c
URL:
http://source.netsurf-browser.org/branches/paulblokus/treeview/desktop/op...
==============================================================================
--- branches/paulblokus/treeview/desktop/options.c (original)
+++ branches/paulblokus/treeview/desktop/options.c Tue Jun 30 18:59:14 2009
@@ -146,6 +146,7 @@
unsigned int option_min_reflow_period = 25; /* time in cs */
#endif
char *option_recent_file = 0;
+char *option_tree_icons_dir = 0;
/** top margin of exported page*/
int option_margin_top = DEFAULT_MARGIN_TOP_MM;
/** bottom margin of exported page*/
@@ -246,6 +247,7 @@
{ "incremental_reflow", OPTION_BOOL, &option_incremental_reflow },
{ "min_reflow_period", OPTION_INTEGER, &option_min_reflow_period },
{ "recent_file", OPTION_STRING, &option_recent_file },
+ { "tree_icons_dir", OPTION_STRING, &option_tree_icons_dir },
/* Fetcher options */
{ "max_fetchers", OPTION_INTEGER, &option_max_fetchers },
{ "max_fetchers_per_host",
Modified: branches/paulblokus/treeview/desktop/options.h
URL:
http://source.netsurf-browser.org/branches/paulblokus/treeview/desktop/op...
==============================================================================
--- branches/paulblokus/treeview/desktop/options.h (original)
+++ branches/paulblokus/treeview/desktop/options.h Tue Jun 30 18:59:14 2009
@@ -84,6 +84,7 @@
extern bool option_incremental_reflow;
extern unsigned int option_min_reflow_period;
extern char *option_recent_file;
+extern char *option_tree_icons_dir;
extern int option_margin_top;
extern int option_margin_bottom;
Modified: branches/paulblokus/treeview/desktop/tree.c
URL:
http://source.netsurf-browser.org/branches/paulblokus/treeview/desktop/tr...
==============================================================================
--- branches/paulblokus/treeview/desktop/tree.c (original)
+++ branches/paulblokus/treeview/desktop/tree.c Tue Jun 30 18:59:14 2009
@@ -27,6 +27,7 @@
#include <stdlib.h>
#include <string.h>
#include "content/content.h"
+#include "content/fetchcache.h"
#include "desktop/browser.h"
#include "desktop/tree.h"
#include "desktop/options.h"
@@ -46,10 +47,13 @@
TREE_MOVE_DRAG
} tree_drag_type;
+
+#define MAXIMUM_URL_LENGTH 1024
+
#define NODE_INSTEP 20
#define TREE_TEXT_HEIGHT 20
-
#define FURNITURE_COLOUR 0x888888
+#define ICON_SIZE 16
struct toolbar;
struct node;
@@ -129,7 +133,9 @@
static void tree_delete_node_internal(struct tree *tree, struct node *node,
bool siblings);
-static void tree_sort_insert(struct node *parent, struct node *node);
+static void tree_node_icon_callback(content_msg msg, struct content *c,
+ intptr_t p1, intptr_t p2, union content_msg_data data);
+static void tree_sort_insert(struct node *parent, struct node *node);
static void tree_set_node_expanded_all(struct tree *tree, struct node *node,
bool expanded);
static bool tree_set_node_expanded_internal(struct tree *tree,
@@ -250,7 +256,6 @@
bool deleted, unsigned int flag)
{
struct node *node;
- struct content *bm;
assert(title);
@@ -268,8 +273,7 @@
node->sort = NULL;
node->user_callback = NULL;
- bm = tree_get_icon(tree, node, "small_dir", false);
- tree_set_node_icon(tree, node, bm);
+ tree_set_node_named_icon(tree, node, "small_dir", false);
if (parent != NULL)
tree_link_node(tree, parent, node, false);
else
@@ -456,10 +460,10 @@
*/
void tree_delete_node(struct tree *tree, struct node *node, bool siblings)
{
+ int y = node->box.y;
tree_delete_node_internal(tree, node, siblings);
tree_recalculate_node_positions(tree, tree->root);
- /* \todo correct area */
- tree_draw(tree, 0, 0, tree->width, tree->height);
+ tree_draw(tree, 0, y, tree->width, tree->height);
tree_recalculate_size(tree);
}
@@ -517,7 +521,6 @@
e->flag);
/* TODO the type of this field is platform
dependent */
- /* \todo platform specific bits */
if (!handled)
free(e->bitmap);
e->bitmap = NULL;
@@ -536,25 +539,39 @@
/**
- * Sets a node element as having a specific icon.
- *
- * \param tree the tree to which 'node' belongs, may be NULL
- * \param node the node to update
- * \param icon the icon to use
- */
-void tree_set_node_icon(struct tree *tree, struct node *node,
- struct content *icon)
-{
-
- assert(node);
- assert(icon);
-
- // this is done in tree_callback at the moment
- /*node->data.bitmap = icon;
- if (node->data.bitmap == NULL) return;*/
+ * Acquires a specific icon from the front end specified directory.
+ *
+ * \param tree The tree to which node belongs, may be NULL
+ * \param node The node for which the icon bitmap gets acquired. This
+ * is necessary at the moment as the pointer gets passed
+ * to tree_callback which actually sets the icon.
+ * \param icon the bitmap to use
+ * \param path If true 'icon' contains the full path under which the
+ * icon can be found
+ */
+void tree_set_node_named_icon(struct tree *tree, struct node *node,
+ const char *icon, bool path)
+{
+ /* TODO: something like bitmap_from_disk is needed here */
+
+ char icon_path[MAXIMUM_URL_LENGTH];
+
+ struct content *c;
+
+ if (path) {
+ sprintf(icon_path, icon);
+ }
+ else {
+ sprintf(icon_path, "%s%s%s%s", "file://", option_tree_icons_dir,
+ icon, ".bmp");
+ }
+ c = fetchcache(icon_path, tree_node_icon_callback, (intptr_t) tree,
+ (intptr_t) node, ICON_SIZE, ICON_SIZE, true, 0, 0, true,
+ false);
+ fetchcache_go(c, 0, tree_node_icon_callback, (intptr_t) tree,
+ (intptr_t) node, ICON_SIZE, ICON_SIZE, 0, 0, true, 0);
node->data.type = NODE_ELEMENT_TEXT_PLUS_ICON;
- tree_handle_node_element_changed(tree, &(node->data));
}
@@ -1094,12 +1111,14 @@
switch (element->type) {
case NODE_ELEMENT_TEXT_PLUS_ICON:
- /*TODO: the if is necessary as long as the bitmap gets fetched
- as a content*/
- //assert(element->bitmap);
+ /* TODO: the if is necessary as long as the bitmap gets fetched
+ as a content */
+ /* assert(element->bitmap); */
if (element->bitmap != NULL)
- content_redraw(element->bitmap, x, y + 3, 16,
- 16, x, y, x + 16, y + 16, 1, 0);
+ content_redraw(element->bitmap, x, y + 3,
+ ICON_SIZE, ICON_SIZE, x, y,
+ x + ICON_SIZE, y + ICON_SIZE, 1,
+ 0);
x += NODE_INSTEP;
/* fall through */
@@ -1269,7 +1288,7 @@
element = tree_get_node_element_at(tree->root->child, x, y, &furniture);
/* stop editing for anything but a drag */
-// if ((tree->editing) && /*(pointer->i != tree->edit_handle)
&&*/
+// if ((tree->editing) && /* (pointer->i != tree->edit_handle)
&& */
// !(mouse & BROWSER_MOUSE_DRAG_1))
// ro_gui_tree_stop_edit(tree);
@@ -1490,7 +1509,7 @@
* Callback for fetchcache(). Should be removed once bitmaps get loaded directly
* from disc
*/
-void tree_callback(content_msg msg, struct content *c,
+void tree_node_icon_callback(content_msg msg, struct content *c,
intptr_t p1, intptr_t p2, union content_msg_data data)
{
struct tree *tree = (struct tree *) p1;
@@ -1598,9 +1617,10 @@
switch (element->type) {
case NODE_ELEMENT_TEXT_PLUS_ICON:
- /*TODO: This assert can't be used as long as the bitmap
- gets fetched as a content*/
-// assert(element->bitmap);
+ /* TODO: This assert can't be used as long as the bitmap
+ gets fetched as a content */
+ /* assert(element->bitmap); */
+ /* fall through */
case NODE_ELEMENT_TEXT:
assert(element->text);
nsfont.font_width(&css_base_style, element->text,
Modified: branches/paulblokus/treeview/desktop/tree.h
URL:
http://source.netsurf-browser.org/branches/paulblokus/treeview/desktop/tr...
==============================================================================
--- branches/paulblokus/treeview/desktop/tree.h (original)
+++ branches/paulblokus/treeview/desktop/tree.h Tue Jun 30 18:59:14 2009
@@ -42,14 +42,14 @@
struct cookie_data;
typedef enum {
- NODE_ELEMENT_TEXT, /* <-- Text only */
- NODE_ELEMENT_TEXT_PLUS_ICON, /* <-- Text and icon */
- NODE_ELEMENT_BITMAP /* <-- Bitmap only */
+ NODE_ELEMENT_TEXT, /* Text only */
+ NODE_ELEMENT_TEXT_PLUS_ICON, /* Text and icon */
+ NODE_ELEMENT_BITMAP /* Bitmap only */
} node_element_type;
typedef enum {
- NODE_DELETE_ELEMENT,
- NODE_LAUNCH
+ NODE_DELETE_ELEMENT, /* An element of the node is deleted */
+ NODE_LAUNCH /* The node has been launched */
} node_msg;
typedef void (*tree_start_redraw_callback)(void *data);
@@ -60,8 +60,8 @@
/* Non-platform specific code */
-/* functions for creating/deleting tree primitives and tree structure
- manipulation*/
+/* Functions for creating/deleting tree primitives and for tree structure
+ manipulation */
struct tree *tree_create(unsigned int flags, int x, int y,
tree_start_redraw_callback start_redraw,
tree_end_redraw_callback end_redraw, void *redraw_data,
@@ -79,9 +79,9 @@
void tree_delink_node(struct tree *tree, struct node *node);
void tree_delete_node(struct tree *tree, struct node *node, bool siblings);
-/* setters and getters for properties and data*/
-void tree_set_node_icon(struct tree *tree, struct node *node,
- struct content *icon);
+/* setters and getters for properties and data */
+void tree_set_node_named_icon(struct tree *tree, struct node *node,
+ const char *icon, bool path);
void tree_set_node_expanded(struct tree *tree, struct node *node, bool expanded,
bool folder, bool leaf);
void tree_set_node_selected(struct tree *tree, struct node *node, bool all,
@@ -119,15 +119,10 @@
void tree_drag_end(struct tree *tree, browser_mouse_state mouse, int x0, int y0,
int x1, int y1);
-int tree_alphabetical_sort(struct node *, struct node *);
-void tree_callback(content_msg msg, struct content *c,
- intptr_t p1, intptr_t p2, union content_msg_data data);
+int tree_alphabetical_sort(struct node *, struct node *);
/* Platform specific code */
void tree_resized(struct tree *tree, int width, int height, void *data);
-struct content *tree_get_icon(struct tree *tree, struct node *node,
- const char *icon, bool path);
-void tree_icon_name_from_content_type(char *buffer, content_type type);
void tree_scroll_visible(struct tree *tree, struct node_element *element,
void *data);
#endif
Modified: branches/paulblokus/treeview/desktop/tree_url_node.c
URL:
http://source.netsurf-browser.org/branches/paulblokus/treeview/desktop/tr...
==============================================================================
--- branches/paulblokus/treeview/desktop/tree_url_node.c (original)
+++ branches/paulblokus/treeview/desktop/tree_url_node.c Tue Jun 30 18:59:14 2009
@@ -131,7 +131,6 @@
{
struct node_element *element;
char buffer[256];
- struct content *bm;
struct bitmap *bitmap = NULL;
assert(node);
@@ -157,9 +156,7 @@
tree_icon_name_from_content_type(buffer, data->type);
- bm = tree_get_icon(tree, node, buffer, false);
- tree_set_node_icon(tree, node, bm);
-
+ tree_set_node_named_icon(tree, node, buffer, false);
element = tree_node_find_element(node, TREE_ELEMENT_LAST_VISIT);
if (element != NULL) {
Modified: branches/paulblokus/treeview/desktop/tree_url_node.h
URL:
http://source.netsurf-browser.org/branches/paulblokus/treeview/desktop/tr...
==============================================================================
--- branches/paulblokus/treeview/desktop/tree_url_node.h (original)
+++ branches/paulblokus/treeview/desktop/tree_url_node.h Tue Jun 30 18:59:14 2009
@@ -44,4 +44,7 @@
void tree_update_URL_node(struct tree *tree,struct node *node,
const char *url, const struct url_data *data);
+/* front end specific */
+void tree_icon_name_from_content_type(char *buffer, content_type type);
+
#endif
Modified: branches/paulblokus/treeview/gtk/gtk_gui.c
URL:
http://source.netsurf-browser.org/branches/paulblokus/treeview/gtk/gtk_gu...
==============================================================================
--- branches/paulblokus/treeview/gtk/gtk_gui.c (original)
+++ branches/paulblokus/treeview/gtk/gtk_gui.c Tue Jun 30 18:59:14 2009
@@ -299,6 +299,16 @@
LOG(("Using '%s' as Recent file", buf));
option_recent_file = strdup(buf);
}
+ if (!option_recent_file)
+ die("Failed initialising recent URLs file option");
+
+ if (!option_tree_icons_dir) {
+ option_tree_icons_dir = strdup(res_dir_location);
+ LOG(("Using '%s' as Tree icons dir", option_tree_icons_dir));
+ }
+ if (!option_tree_icons_dir)
+ die("Failed initialising tree icons option");
+
find_resource(buf, "messages", "./gtk/res/messages");
LOG(("Using '%s' as Messages file", buf));
Modified: branches/paulblokus/treeview/gtk/gtk_treeview.c
URL:
http://source.netsurf-browser.org/branches/paulblokus/treeview/gtk/gtk_tr...
==============================================================================
--- branches/paulblokus/treeview/gtk/gtk_treeview.c (original)
+++ branches/paulblokus/treeview/gtk/gtk_treeview.c Tue Jun 30 18:59:14 2009
@@ -24,52 +24,13 @@
#include <gtk/gtk.h>
#include <stdio.h>
-#include "content/fetchcache.h"
-#include "desktop/gui.h"
#include "desktop/tree.h"
+#include "desktop/tree_url_node.h"
#include "desktop/plotters.h"
-#include "gtk/gtk_gui.h"
#include "gtk/gtk_plotters.h"
#include "gtk/gtk_treeview.h"
-#define MAXIMUM_URL_LENGTH 1024
-
static bool set = false;
-
-/**
- * Acquires a specific front end specified icon.
- *
- * \param tree The tree to which node belongs, may be NULL
- * \param node The node for which the icon bitmap gets acquired. This
- * is necessary at the moment as the pointer gets passed
- * to tree_callback which actually sets the icon.
- * \param icon the bitmap to use
- * \param path If true 'icon' contains the full path under which the
- * icon can be found
- */
-struct content *tree_get_icon(struct tree *tree, struct node *node,
- const char *icon, bool path)
-{
- /* TODO: something like bitmap_from_disk is needed here*/
-
- char icon_path[MAXIMUM_URL_LENGTH];
-
- struct content *c;
-
- if (path) {
- sprintf(icon_path, icon);
- }
- else {
- sprintf(icon_path, "%s%s%s%s", "file://", res_dir_location,
- icon, ".bmp");
- }
- c = fetchcache(icon_path, tree_callback, (intptr_t) tree,
- (intptr_t) node, 16, 16, true, 0, 0, true, false);
- fetchcache_go(c, 0, tree_callback, (intptr_t) tree, (intptr_t) node, 16,
- 16, 0, 0, true, 0);
-
- return c;
-}
/**
* Updates the tree owner following a tree resize