From 60c840628f4f2aebc86adea495258be1ecc738e8 Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Tue, 14 Dec 2010 00:18:24 +0000 Subject: Small refactor to change icon names to being passed in from frontends instead of core treeview globals svn path=/trunk/netsurf/; revision=11053 --- amiga/cookies.c | 4 +- amiga/gui.c | 2 +- amiga/history.c | 3 +- amiga/hotlist.c | 3 +- amiga/tree.h | 4 ++ desktop/cookies.c | 6 +-- desktop/cookies.h | 2 +- desktop/history_global_core.c | 6 +-- desktop/history_global_core.h | 2 +- desktop/hotlist.c | 8 +-- desktop/hotlist.h | 10 +++- desktop/sslcert.c | 4 +- desktop/sslcert.h | 2 +- desktop/tree.h | 4 -- desktop/tree_url_node.c | 4 +- desktop/tree_url_node.h | 2 +- framebuffer/tree.c | 4 +- gtk/gtk_cookies.c | 4 +- gtk/gtk_gui.c | 2 +- gtk/gtk_history.c | 3 +- gtk/gtk_hotlist.c | 3 +- gtk/gtk_treeview.c | 114 ++++++++++++++++++++---------------------- gtk/gtk_treeview.h | 4 ++ riscos/cookies.c | 4 +- riscos/global_history.c | 3 +- riscos/hotlist.c | 3 +- riscos/sslcert.c | 2 +- riscos/treeview.h | 4 ++ windows/tree.c | 3 +- 29 files changed, 121 insertions(+), 98 deletions(-) diff --git a/amiga/cookies.c b/amiga/cookies.c index 76e2173f2..4ee463751 100755 --- a/amiga/cookies.c +++ b/amiga/cookies.c @@ -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() diff --git a/amiga/gui.c b/amiga/gui.c index 23889d0b6..1427403c4 100755 --- a/amiga/gui.c +++ b/amiga/gui.c @@ -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); diff --git a/amiga/history.c b/amiga/history.c index 19ba9aff9..cc161d03f 100755 --- a/amiga/history.c +++ b/amiga/history.c @@ -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() diff --git a/amiga/hotlist.c b/amiga/hotlist.c index f90f3645e..6469cbd90 100755 --- a/amiga/hotlist.c +++ b/amiga/hotlist.c @@ -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) diff --git a/amiga/tree.h b/amiga/tree.h index 315938d0d..0a0c29e87 100755 --- a/amiga/tree.h +++ b/amiga/tree.h @@ -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 diff --git a/desktop/cookies.c b/desktop/cookies.c index 09aa079a9..e22dcc289 100644 --- a/desktop/cookies.c +++ b/desktop/cookies.c @@ -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; diff --git a/desktop/cookies.h b/desktop/cookies.h index 06278c006..9e0d79fbb 100644 --- a/desktop/cookies.h +++ b/desktop/cookies.h @@ -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); /** diff --git a/desktop/history_global_core.c b/desktop/history_global_core.c index 3589346ed..771928467 100644 --- a/desktop/history_global_core.c +++ b/desktop/history_global_core.c @@ -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; diff --git a/desktop/history_global_core.h b/desktop/history_global_core.h index 97c578f3d..1bb343dd6 100644 --- a/desktop/history_global_core.h +++ b/desktop/history_global_core.h @@ -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); diff --git a/desktop/hotlist.c b/desktop/hotlist.c index 74b071d8e..cb5362050 100644 --- a/desktop/hotlist.c +++ b/desktop/hotlist.c @@ -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; diff --git a/desktop/hotlist.h b/desktop/hotlist.h index 84f573a90..efce84696 100644 --- a/desktop/hotlist.h +++ b/desktop/hotlist.h @@ -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); diff --git a/desktop/sslcert.c b/desktop/sslcert.c index 2d10b4719..9aff25700 100644 --- a/desktop/sslcert.c +++ b/desktop/sslcert.c @@ -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); } diff --git a/desktop/sslcert.h b/desktop/sslcert.h index bc1b8bef8..8fe534846 100644 --- a/desktop/sslcert.h +++ b/desktop/sslcert.h @@ -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); diff --git a/desktop/tree.h b/desktop/tree.h index aaf82af83..1703c3784 100644 --- a/desktop/tree.h +++ b/desktop/tree.h @@ -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; diff --git a/desktop/tree_url_node.c b/desktop/tree_url_node.c index ff21d97bf..182c9332d 100644 --- a/desktop/tree_url_node.c +++ b/desktop/tree_url_node.c @@ -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 { diff --git a/desktop/tree_url_node.h b/desktop/tree_url_node.h index 4bee73ebc..fbecf7f28 100644 --- a/desktop/tree_url_node.h +++ b/desktop/tree_url_node.h @@ -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); diff --git a/framebuffer/tree.c b/framebuffer/tree.c index 67082a42c..0f028b926 100644 --- a/framebuffer/tree.c +++ b/framebuffer/tree.c @@ -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"; - +*/ diff --git a/gtk/gtk_cookies.c b/gtk/gtk_cookies.c index 1576290ad..e9528320b 100644 --- a/gtk/gtk_cookies.c +++ b/gtk/gtk_cookies.c @@ -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(); } diff --git a/gtk/gtk_gui.c b/gtk/gtk_gui.c index be6e4afe2..739462060 100644 --- a/gtk/gtk_gui.c +++ b/gtk/gtk_gui.c @@ -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; diff --git a/gtk/gtk_history.c b/gtk/gtk_history.c index 75b392fb3..62cc798e5 100644 --- a/gtk/gtk_history.c +++ b/gtk/gtk_history.c @@ -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(); diff --git a/gtk/gtk_hotlist.c b/gtk/gtk_hotlist.c index 905050260..bf700a047 100644 --- a/gtk/gtk_hotlist.c +++ b/gtk/gtk_hotlist.c @@ -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(); } diff --git a/gtk/gtk_treeview.c b/gtk/gtk_treeview.c index 20562e3d5..e3915501c 100644 --- a/gtk/gtk_treeview.c +++ b/gtk/gtk_treeview.c @@ -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; +} diff --git a/gtk/gtk_treeview.h b/gtk/gtk_treeview.h index 655f8223d..c7520465e 100644 --- a/gtk/gtk_treeview.h +++ b/gtk/gtk_treeview.h @@ -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, diff --git a/riscos/cookies.c b/riscos/cookies.c index 51b1f5f25..5eb2191d2 100644 --- a/riscos/cookies.c +++ b/riscos/cookies.c @@ -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. */ diff --git a/riscos/global_history.c b/riscos/global_history.c index 2f4f8a1b5..d46600005 100644 --- a/riscos/global_history.c +++ b/riscos/global_history.c @@ -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. */ diff --git a/riscos/hotlist.c b/riscos/hotlist.c index 4c2c084d2..42976b893 100644 --- a/riscos/hotlist.c +++ b/riscos/hotlist.c @@ -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. */ diff --git a/riscos/sslcert.c b/riscos/sslcert.c index 990c2501c..f2af924a0 100644 --- a/riscos/sslcert.c +++ b/riscos/sslcert.c @@ -95,7 +95,7 @@ void ro_gui_cert_postinitialise(void) { /* Initialise the SSL module. */ - sslcert_init(); + sslcert_init(tree_content_icon_name); } /** diff --git a/riscos/treeview.h b/riscos/treeview.h index 2b87d57e8..7ad6fb0fa 100644 --- a/riscos/treeview.h +++ b/riscos/treeview.h @@ -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 { diff --git a/windows/tree.c b/windows/tree.c index 78182fbd6..9a448005f 100644 --- a/windows/tree.c +++ b/windows/tree.c @@ -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 -- cgit v1.2.3