Small refactor to change icon names to being passed in from frontends instead of core treeview globals

svn path=/trunk/netsurf/; revision=11053
This commit is contained in:
Vincent Sanders 2010-12-14 00:18:24 +00:00
parent 67556f54fe
commit 60c840628f
29 changed files with 121 additions and 98 deletions

View File

@ -27,7 +27,9 @@ void ami_cookies_initialise(void)
if(!cookies_window) return;
cookies_initialise(ami_tree_get_tree(cookies_window));
cookies_initialise(ami_tree_get_tree(cookies_window),
tree_directory_icon_name,
tree_content_icon_name);
}
void ami_cookies_free()

View File

@ -560,7 +560,7 @@ static void gui_init2(int argc, char** argv)
ami_hotlist_initialise(option_hotlist_file);
ami_cookies_initialise();
ami_global_history_initialise();
sslcert_init();
sslcert_init(tree_content_icon_name);
search_web_provider_details(option_search_provider);

View File

@ -28,7 +28,8 @@ void ami_global_history_initialise(void)
if(!global_history_window) return;
history_global_initialise(ami_tree_get_tree(global_history_window));
history_global_initialise(ami_tree_get_tree(global_history_window),
tree_directory_icon_name);
}
void ami_global_history_free()

View File

@ -28,7 +28,8 @@ void ami_hotlist_initialise(const char *hotlist_file)
if(!hotlist_window) return;
hotlist_initialise(ami_tree_get_tree(hotlist_window),
hotlist_file);
hotlist_file,
tree_directory_icon_name);
}
void ami_hotlist_free(const char *hotlist_file)

View File

@ -25,6 +25,10 @@
#include "desktop/tree.h"
#include "desktop/sslcert.h"
/* defined in front end code */
extern const char tree_directory_icon_name[];
extern const char tree_content_icon_name[];
struct treeview_window;
enum

View File

@ -371,14 +371,14 @@ static void cookies_schedule_callback(void *scheduled_data)
* \param end_redraw callback function called after every redraw
* \return true on success, false on memory exhaustion
*/
bool cookies_initialise(struct tree *tree)
bool cookies_initialise(struct tree *tree, const char* folder_icon_name, const char* cookie_icon_name)
{
if (tree == NULL)
return false;
folder_icon = tree_load_icon(tree_directory_icon_name);
cookie_icon = tree_load_icon(tree_content_icon_name);
folder_icon = tree_load_icon(folder_icon_name);
cookie_icon = tree_load_icon(cookie_icon_name);
/* Create an empty tree */
cookies_tree = tree;

View File

@ -29,7 +29,7 @@
struct cookie_data;
bool cookies_initialise(struct tree *tree);
bool cookies_initialise(struct tree *tree, const char* folder_icon_name, const char* cookie_icon_name);
unsigned int cookies_get_tree_flags(void);
/**

View File

@ -278,10 +278,10 @@ static bool history_global_initialise_nodes(void)
* \param end_redraw callback function called after every redraw
* \return true on success, false on memory exhaustion
*/
bool history_global_initialise(struct tree *tree)
bool history_global_initialise(struct tree *tree, const char* folder_icon_name)
{
folder_icon = tree_load_icon(tree_directory_icon_name);
tree_url_node_init();
folder_icon = tree_load_icon(folder_icon_name);
tree_url_node_init(folder_icon_name);
if (tree == NULL)
return false;

View File

@ -24,7 +24,7 @@
#include "desktop/tree.h"
bool history_global_initialise(struct tree *tree);
bool history_global_initialise(struct tree *tree, const char* folder_icon_name);
unsigned int history_global_get_tree_flags(void);
void history_global_cleanup(void);

View File

@ -111,8 +111,8 @@ static node_callback_resp hotlist_node_callback(void *user_data,
return NODE_CALLBACK_NOT_HANDLED;
}
bool hotlist_initialise(struct tree *tree, const char *hotlist_path)
/* exported interface documented in hotlist.h */
bool hotlist_initialise(struct tree *tree, const char *hotlist_path, const char* folder_icon_name)
{
struct node *node;
const struct url_data *url_data;
@ -123,9 +123,9 @@ bool hotlist_initialise(struct tree *tree, const char *hotlist_path)
creating_node = false;
folder_icon = tree_load_icon(tree_directory_icon_name);
folder_icon = tree_load_icon(folder_icon_name);
tree_url_node_init();
tree_url_node_init(folder_icon_name);
if (tree == NULL)
return false;

View File

@ -30,7 +30,15 @@
#include "desktop/tree.h"
bool hotlist_initialise(struct tree *tree, const char *hotlist_path);
/**
* Initialise the hotlist from a frontend.
*
* \param tree The tree object which holds the hotlist.
* \param hotlist_path The file path to initialise the hotlist entries from.
* \param folder_icon_name The name to use for folder icons.
*/
bool hotlist_initialise(struct tree *tree, const char *hotlist_path, const char* folder_icon_name);
unsigned int hotlist_get_tree_flags(void);
void hotlist_cleanup(const char *hotlist_path);

View File

@ -59,9 +59,9 @@ struct sslcert_session_data {
static hlcache_handle *sslcert_icon;
/** Initialise ssl certificate window. */
void sslcert_init(void)
void sslcert_init(const char* icon_name)
{
sslcert_icon = tree_load_icon(tree_content_icon_name);
sslcert_icon = tree_load_icon(icon_name);
}

View File

@ -26,7 +26,7 @@
struct sslcert_session_data;
void sslcert_init(void);
void sslcert_init(const char* icon_name);
unsigned int sslcert_get_tree_flags(void);
void sslcert_cleanup(void);

View File

@ -55,10 +55,6 @@ enum tree_flags {
*/
#define TREE_ELEMENT_TITLE 0x00
/* these should be defined in front end code */
extern const char tree_directory_icon_name[];
extern const char tree_content_icon_name[];
struct tree;
struct node;
struct node_element;

View File

@ -103,7 +103,7 @@ struct icon_entry icon_table[] = {
};
void tree_url_node_init(void)
void tree_url_node_init(const char *folder_icon_name)
{
struct icon_entry *entry;
char icon_name[MAX_ICON_NAME_LEN];
@ -112,7 +112,7 @@ void tree_url_node_init(void)
return;
initialised = true;
folder_icon = tree_load_icon(tree_directory_icon_name);
folder_icon = tree_load_icon(folder_icon_name);
entry = icon_table;
do {

View File

@ -27,7 +27,7 @@
#include "desktop/tree.h"
void tree_url_node_init(void);
void tree_url_node_init(const char *folder_icon_name);
struct node *tree_create_URL_node(struct tree *tree,
struct node *parent, const char *url, const char *title,
tree_node_user_callback, void *callback_data);

View File

@ -19,9 +19,9 @@
#include "desktop/tree.h"
#include "desktop/tree_url_node.h"
const char tree_directory_icon_name[] = "directory.png";
/*const char tree_directory_icon_name[] = "directory.png";
const char tree_content_icon_name[] = "content.png";
*/

View File

@ -118,7 +118,9 @@ void nsgtk_cookies_init(void)
CONNECT(window, "delete_event", gtk_widget_hide_on_delete, NULL);
CONNECT(window, "hide", nsgtk_tree_window_hide, cookies_window);
cookies_initialise(nsgtk_treeview_get_tree(cookies_window));
cookies_initialise(nsgtk_treeview_get_tree(cookies_window),
tree_directory_icon_name,
tree_content_icon_name);
nsgtk_cookies_init_menu();
}

View File

@ -500,7 +500,7 @@ static void gui_init(int argc, char** argv, char **respath)
nsgtk_cookies_init();
nsgtk_hotlist_init();
sslcert_init();
sslcert_init(tree_content_icon_name);
if (option_homepage_url != NULL && option_homepage_url[0] != '\0')
addr = option_homepage_url;

View File

@ -128,7 +128,8 @@ bool nsgtk_history_init(void)
CONNECT(window, "hide", nsgtk_tree_window_hide, global_history_window);
history_global_initialise(
nsgtk_treeview_get_tree(global_history_window));
nsgtk_treeview_get_tree(global_history_window),
tree_directory_icon_name);
nsgtk_history_init_menu();

View File

@ -132,7 +132,8 @@ void nsgtk_hotlist_init()
CONNECT(window, "hide", nsgtk_tree_window_hide, hotlist_window);
hotlist_initialise(nsgtk_treeview_get_tree(hotlist_window),
option_hotlist_path);
option_hotlist_path,
tree_directory_icon_name);
nsgtk_hotlist_init_menu();
}

View File

@ -48,62 +48,6 @@ struct nsgtk_treeview {
const char tree_directory_icon_name[] = "directory.png";
const char tree_content_icon_name[] = "content.png";
static void nsgtk_tree_redraw_request(int x, int y, int width, int height,
void *data);
static void nsgtk_tree_resized(struct tree *tree, int width, int height, void *data);
static void nsgtk_tree_scroll_visible(int y, int height, void *data);
static void nsgtk_tree_get_window_dimensions(int *width, int *height, void *data);
static const struct treeview_table nsgtk_tree_callbacks = {
.redraw_request = nsgtk_tree_redraw_request,
.resized = nsgtk_tree_resized,
.scroll_visible = nsgtk_tree_scroll_visible,
.get_window_dimensions = nsgtk_tree_get_window_dimensions
};
struct nsgtk_treeview *nsgtk_treeview_create(unsigned int flags,
GtkWindow *window, GtkScrolledWindow *scrolled,
GtkDrawingArea *drawing_area)
{
struct nsgtk_treeview *tv;
tv = malloc(sizeof(struct nsgtk_treeview));
if (tv == NULL) {
LOG(("malloc failed"));
warn_user("NoMemory", 0);
return NULL;
}
tv->window = window;
tv->scrolled = scrolled;
tv->drawing_area = drawing_area;
tv->tree = tree_create(flags, &nsgtk_tree_callbacks, tv);
tv->mouse_state = 0;
gtk_widget_modify_bg(GTK_WIDGET(drawing_area), GTK_STATE_NORMAL,
&((GdkColor) { 0, 0xffff, 0xffff, 0xffff } ));
#define CONNECT(obj, sig, callback, ptr) \
g_signal_connect(G_OBJECT(obj), (sig), G_CALLBACK(callback), (ptr))
CONNECT(drawing_area, "expose_event",
nsgtk_tree_window_expose_event,
tv->tree);
CONNECT(drawing_area, "button_press_event",
nsgtk_tree_window_button_press_event,
tv);
CONNECT(drawing_area, "button_release_event",
nsgtk_tree_window_button_release_event,
tv);
CONNECT(drawing_area, "motion_notify_event",
nsgtk_tree_window_motion_notify_event,
tv);
CONNECT(drawing_area, "key_press_event",
nsgtk_tree_window_keypress_event,
tv);
return tv;
}
void nsgtk_treeview_destroy(struct nsgtk_treeview *tv)
{
tree_delete(tv->tree);
@ -116,7 +60,7 @@ struct tree *nsgtk_treeview_get_tree(struct nsgtk_treeview *tv)
return tv->tree;
}
void nsgtk_tree_redraw_request(int x, int y, int width, int height, void *data)
static void nsgtk_tree_redraw_request(int x, int y, int width, int height, void *data)
{
struct nsgtk_treeview *tw = data;
@ -130,7 +74,7 @@ void nsgtk_tree_redraw_request(int x, int y, int width, int height, void *data)
*
* \param tree the tree to update the owner of
*/
void nsgtk_tree_resized(struct tree *tree, int width, int height, void *data)
static void nsgtk_tree_resized(struct tree *tree, int width, int height, void *data)
{
struct nsgtk_treeview *tw = data;
@ -194,7 +138,7 @@ void tree_icon_name_from_content_type(char *buffer, content_type type)
* \param height height of the element
* \param data user data assigned to the tree on tree creation
*/
void nsgtk_tree_scroll_visible(int y, int height, void *data)
static void nsgtk_tree_scroll_visible(int y, int height, void *data)
{
int y0, y1;
gdouble page;
@ -225,7 +169,7 @@ void nsgtk_tree_scroll_visible(int y, int height, void *data)
* \param width will be updated to window width if not NULL
* \param height will be updated to window height if not NULL
*/
void nsgtk_tree_get_window_dimensions(int *width, int *height, void *data)
static void nsgtk_tree_get_window_dimensions(int *width, int *height, void *data)
{
struct nsgtk_treeview *tw = data;
GtkAdjustment *vadj;
@ -540,3 +484,53 @@ gboolean nsgtk_tree_window_keypress_event(GtkWidget *widget, GdkEventKey *event,
return TRUE;
}
static const struct treeview_table nsgtk_tree_callbacks = {
.redraw_request = nsgtk_tree_redraw_request,
.resized = nsgtk_tree_resized,
.scroll_visible = nsgtk_tree_scroll_visible,
.get_window_dimensions = nsgtk_tree_get_window_dimensions
};
struct nsgtk_treeview *nsgtk_treeview_create(unsigned int flags,
GtkWindow *window, GtkScrolledWindow *scrolled,
GtkDrawingArea *drawing_area)
{
struct nsgtk_treeview *tv;
tv = malloc(sizeof(struct nsgtk_treeview));
if (tv == NULL) {
LOG(("malloc failed"));
warn_user("NoMemory", 0);
return NULL;
}
tv->window = window;
tv->scrolled = scrolled;
tv->drawing_area = drawing_area;
tv->tree = tree_create(flags, &nsgtk_tree_callbacks, tv);
tv->mouse_state = 0;
gtk_widget_modify_bg(GTK_WIDGET(drawing_area), GTK_STATE_NORMAL,
&((GdkColor) { 0, 0xffff, 0xffff, 0xffff } ));
#define CONNECT(obj, sig, callback, ptr) \
g_signal_connect(G_OBJECT(obj), (sig), G_CALLBACK(callback), (ptr))
CONNECT(drawing_area, "expose_event",
nsgtk_tree_window_expose_event,
tv->tree);
CONNECT(drawing_area, "button_press_event",
nsgtk_tree_window_button_press_event,
tv);
CONNECT(drawing_area, "button_release_event",
nsgtk_tree_window_button_release_event,
tv);
CONNECT(drawing_area, "motion_notify_event",
nsgtk_tree_window_motion_notify_event,
tv);
CONNECT(drawing_area, "key_press_event",
nsgtk_tree_window_keypress_event,
tv);
return tv;
}

View File

@ -26,6 +26,10 @@
#include "desktop/browser.h"
/* defined in front end code */
extern const char tree_directory_icon_name[];
extern const char tree_content_icon_name[];
struct nsgtk_treeview;
struct nsgtk_treeview *nsgtk_treeview_create(unsigned int flags,

View File

@ -93,7 +93,9 @@ void ro_gui_cookies_postinitialise(void)
/* Initialise the cookies into the tree. */
cookies_initialise(ro_treeview_get_tree(cookies_window.tv));
cookies_initialise(ro_treeview_get_tree(cookies_window.tv),
tree_directory_icon_name,
tree_content_icon_name);
/* Build the cookies window menu. */

View File

@ -99,7 +99,8 @@ void ro_gui_global_history_postinitialise(void)
/* Initialise the global history into the tree. */
history_global_initialise(
ro_treeview_get_tree(global_history_window.tv));
ro_treeview_get_tree(global_history_window.tv),
tree_directory_icon_name);
/* Build the global history window menu. */

View File

@ -97,7 +97,8 @@ void ro_gui_hotlist_postinitialise(void)
/* Initialise the hotlist into the tree. */
hotlist_initialise(ro_treeview_get_tree(hotlist_window.tv),
option_hotlist_path);
option_hotlist_path,
tree_directory_icon_name);
/* Build the hotlist window menu. */

View File

@ -95,7 +95,7 @@ void ro_gui_cert_postinitialise(void)
{
/* Initialise the SSL module. */
sslcert_init();
sslcert_init(tree_content_icon_name);
}
/**

View File

@ -30,6 +30,10 @@
#include "desktop/tree.h"
/* defined in front end code */
extern const char tree_directory_icon_name[];
extern const char tree_content_icon_name[];
typedef struct ro_treeview ro_treeview;
struct ro_treeview_table {

View File

@ -19,9 +19,10 @@
#include "desktop/tree.h"
#include "desktop/tree_url_node.h"
/*
const char tree_directory_icon_name[] = "directory.png";
const char tree_content_icon_name[] = "content.png";
*/
/**
* Translates a content_type to the name of a respective icon