fix favicon display

svn path=/trunk/netsurf/; revision=13460
This commit is contained in:
Vincent Sanders 2012-02-21 20:54:31 +00:00
parent 8e3e8f2ca1
commit ea0c028cac
5 changed files with 95 additions and 61 deletions

View File

@ -494,7 +494,7 @@ static gboolean nsgtk_window_tool_bar_clicked(GtkToolbar *toolbar,
/** /**
* Update the menus when the number of tabs changes. * Update the menus when the number of tabs changes.
*/ */
static void nsgtk_window_tabs_num_changed(GtkNotebook *notebook, static void nsgtk_window_tabs_add(GtkNotebook *notebook,
GtkWidget *page, guint page_num, struct gtk_scaffolding *g) GtkWidget *page, guint page_num, struct gtk_scaffolding *g)
{ {
gboolean visible = gtk_notebook_get_show_tabs(g->notebook); gboolean visible = gtk_notebook_get_show_tabs(g->notebook);
@ -506,6 +506,26 @@ static void nsgtk_window_tabs_num_changed(GtkNotebook *notebook,
nsgtk_scaffolding_set_sensitivity(g); nsgtk_scaffolding_set_sensitivity(g);
} }
/**
* Update the menus when the number of tabs changes.
*/
static void nsgtk_window_tabs_remove(GtkNotebook *notebook,
GtkWidget *page, guint page_num, struct gtk_scaffolding *g)
{
if (gtk_notebook_get_n_pages(notebook) == 0) {
nsgtk_scaffolding_destroy(g);
} else {
gboolean visible = gtk_notebook_get_show_tabs(g->notebook);
g_object_set(g->menu_bar->view_submenu->tabs_menuitem, "visible", visible, NULL);
g_object_set(g->menu_popup->view_submenu->tabs_menuitem, "visible", visible, NULL);
g->buttons[NEXTTAB_BUTTON]->sensitivity = visible;
g->buttons[PREVTAB_BUTTON]->sensitivity = visible;
g->buttons[CLOSETAB_BUTTON]->sensitivity = visible;
nsgtk_scaffolding_set_sensitivity(g);
}
}
/** /**
* Handle opening a file path. * Handle opening a file path.
*/ */
@ -1844,9 +1864,9 @@ nsgtk_scaffolding *nsgtk_new_scaffolding(struct gui_window *toplevel)
gtk_widget_hide_on_delete, NULL); gtk_widget_hide_on_delete, NULL);
g_signal_connect_after(g->notebook, "page-added", g_signal_connect_after(g->notebook, "page-added",
G_CALLBACK(nsgtk_window_tabs_num_changed), g); G_CALLBACK(nsgtk_window_tabs_add), g);
g_signal_connect_after(g->notebook, "page-removed", g_signal_connect_after(g->notebook, "page-removed",
G_CALLBACK(nsgtk_window_tabs_num_changed), g); G_CALLBACK(nsgtk_window_tabs_remove), g);
/* connect signals to handlers. */ /* connect signals to handlers. */
CONNECT(g->window, "delete-event", nsgtk_window_delete_event, g); CONNECT(g->window, "delete-event", nsgtk_window_delete_event, g);
@ -1935,13 +1955,9 @@ void gui_window_set_title(struct gui_window *_g, const char *title)
nsgtk_tab_set_title(_g, title); nsgtk_tab_set_title(_g, title);
if (g->top_level == _g) { if (g->top_level == _g) {
if (title == NULL || title[0] == '\0') if (title == NULL || title[0] == '\0') {
{
gtk_window_set_title(g->window, "NetSurf"); gtk_window_set_title(g->window, "NetSurf");
} else {
}
else
{
strcpy(nt, title); strcpy(nt, title);
strcat(nt, suffix); strcat(nt, suffix);
gtk_window_set_title(g->window, nt); gtk_window_set_title(g->window, nt);
@ -1994,42 +2010,23 @@ void gui_window_stop_throbber(struct gui_window* _g)
/** /**
* set favicon * set favicon
*/ */
void gui_window_set_icon(struct gui_window *_g, hlcache_handle *icon) void
nsgtk_scaffolding_set_icon(struct gui_window *gw)
{ {
struct gtk_scaffolding *g = nsgtk_get_scaffold(_g); struct gtk_scaffolding *sc = nsgtk_get_scaffold(gw);
struct bitmap *icon_bitmap = NULL; GdkPixbuf *icon_pixbuf = nsgtk_get_icon(gw);
GdkPixbuf *icon_pixbuf = NULL;
if (g->top_level != _g) { /* check icon needs to be shown */
if ((icon_pixbuf == NULL) ||
(sc->top_level != gw)) {
return; return;
} }
if (icon != NULL) { nsgtk_entry_set_icon_from_pixbuf(sc->url_bar,
icon_bitmap = content_get_bitmap(icon);
if (icon_bitmap != NULL) {
LOG(("Using %p bitmap", icon_bitmap));
icon_pixbuf = nsgdk_pixbuf_get_from_surface(icon_bitmap->surface, 16, 16);
}
}
if (icon_pixbuf == NULL) {
LOG(("Using default favicon"));
g_object_ref(favicon_pixbuf);
icon_pixbuf = favicon_pixbuf;
}
if (icon_pixbuf == NULL) {
return;
}
nsgtk_entry_set_icon_from_pixbuf(g->url_bar,
GTK_ENTRY_ICON_PRIMARY, GTK_ENTRY_ICON_PRIMARY,
icon_pixbuf); icon_pixbuf);
gtk_widget_show_all(GTK_WIDGET(g->buttons[URL_BAR_ITEM]->button)); gtk_widget_show_all(GTK_WIDGET(sc->buttons[URL_BAR_ITEM]->button));
g_object_unref(icon_pixbuf);
} }
void gui_window_set_search_ico(hlcache_handle *ico) void gui_window_set_search_ico(hlcache_handle *ico)
@ -2224,15 +2221,25 @@ struct gui_window *nsgtk_scaffolding_top_level(nsgtk_scaffolding *g)
return g->top_level; return g->top_level;
} }
void nsgtk_scaffolding_set_top_level (struct gui_window *gw) /* set the current active top level gui window */
void nsgtk_scaffolding_set_top_level(struct gui_window *gw)
{ {
nsgtk_get_scaffold(gw)->top_level = gw; struct browser_window *bw;
struct browser_window *bw = nsgtk_get_browser_window(gw); nsgtk_scaffolding *sc;
assert(gw != NULL);
bw = nsgtk_get_browser_window(gw);
assert(bw != NULL); assert(bw != NULL);
sc = nsgtk_get_scaffold(gw);
assert(sc != NULL);
sc->top_level = gw;
/* Synchronise the history (will also update the URL bar) */ /* Synchronise the history (will also update the URL bar) */
nsgtk_window_update_back_forward(nsgtk_get_scaffold(gw)); nsgtk_window_update_back_forward(sc);
/* clear effects of potential searches */ /* clear effects of potential searches */
browser_window_search_destroy_context(bw); browser_window_search_destroy_context(bw);
@ -2240,6 +2247,8 @@ void nsgtk_scaffolding_set_top_level (struct gui_window *gw)
nsgtk_search_set_forward_state(true, bw); nsgtk_search_set_forward_state(true, bw);
nsgtk_search_set_back_state(true, bw); nsgtk_search_set_back_state(true, bw);
nsgtk_scaffolding_set_icon(gw);
/* Ensure the window's title bar is updated */ /* Ensure the window's title bar is updated */
if (bw->current_content != NULL) { if (bw->current_content != NULL) {
gui_window_set_title(gw, content_get_title(bw->current_content)); gui_window_set_title(gw, content_get_title(bw->current_content));

View File

@ -150,6 +150,7 @@ void nsgtk_scaffolding_popup_menu(struct gtk_scaffolding *g, gdouble x,
gdouble y); gdouble y);
void nsgtk_scaffolding_toolbar_size_allocate(GtkWidget *widget, void nsgtk_scaffolding_toolbar_size_allocate(GtkWidget *widget,
GtkAllocation *alloc, gpointer data); GtkAllocation *alloc, gpointer data);
void nsgtk_scaffolding_set_icon(struct gui_window *gw);
gboolean nsgtk_window_url_activate_event(GtkWidget *, gpointer); gboolean nsgtk_window_url_activate_event(GtkWidget *, gpointer);
gboolean nsgtk_window_url_changed(GtkWidget *, GdkEventKey *, gpointer); gboolean nsgtk_window_url_changed(GtkWidget *, GdkEventKey *, gpointer);

View File

@ -111,17 +111,9 @@ static void nsgtk_tab_page_changed(GtkNotebook *notebook, gpointer *page,
GtkWidget *window = gtk_notebook_get_nth_page(notebook, page_num); GtkWidget *window = gtk_notebook_get_nth_page(notebook, page_num);
struct gui_window *gw = g_object_get_data(G_OBJECT(window), struct gui_window *gw = g_object_get_data(G_OBJECT(window),
"gui_window"); "gui_window");
if (gw == NULL) if (gw != NULL) {
return; nsgtk_scaffolding_set_top_level(gw);
struct browser_window *bw = nsgtk_get_browser_window(gw); }
if (bw == NULL)
return;
browser_window_search_destroy_context(bw);
nsgtk_search_set_forward_state(true, bw);
nsgtk_search_set_back_state(true, bw);
nsgtk_scaffolding_set_top_level(gw);
} }
static void static void

View File

@ -39,6 +39,8 @@
#include "gtk/plotters.h" #include "gtk/plotters.h"
#include "gtk/schedule.h" #include "gtk/schedule.h"
#include "gtk/tabs.h" #include "gtk/tabs.h"
#include "gtk/bitmap.h"
#include "gtk/gdk.h"
#include "utils/log.h" #include "utils/log.h"
#include "utils/utils.h" #include "utils/utils.h"
@ -46,7 +48,7 @@ struct gui_window {
/** The gtk scaffold object containing menu, buttons, url bar, [tabs], /** The gtk scaffold object containing menu, buttons, url bar, [tabs],
* drawing area, etc that may contain one or more gui_windows. * drawing area, etc that may contain one or more gui_windows.
*/ */
nsgtk_scaffolding *scaffold; nsgtk_scaffolding *scaffold;
/** The 'content' window that is rendered in the gui_window */ /** The 'content' window that is rendered in the gui_window */
struct browser_window *bw; struct browser_window *bw;
@ -86,6 +88,9 @@ struct gui_window {
/** to allow disactivation / resume of normal window behaviour */ /** to allow disactivation / resume of normal window behaviour */
gulong signalhandler[NSGTK_WINDOW_SIGNAL_COUNT]; gulong signalhandler[NSGTK_WINDOW_SIGNAL_COUNT];
/** The icon this window should have */
GdkPixbuf *icon;
/** list for cleanup */ /** list for cleanup */
struct gui_window *next, *prev; struct gui_window *next, *prev;
}; };
@ -98,6 +103,11 @@ nsgtk_scaffolding *nsgtk_get_scaffold(struct gui_window *g)
return g->scaffold; return g->scaffold;
} }
GdkPixbuf *nsgtk_get_icon(struct gui_window *gw)
{
return gw->icon;
}
struct browser_window *nsgtk_get_browser_window(struct gui_window *g) struct browser_window *nsgtk_get_browser_window(struct gui_window *g)
{ {
return g->bw; return g->bw;
@ -692,16 +702,37 @@ void gui_window_destroy(struct gui_window *g)
/* tab => remove tab */ /* tab => remove tab */
gtk_widget_destroy(gtk_widget_get_parent(GTK_WIDGET(g->layout))); gtk_widget_destroy(gtk_widget_get_parent(GTK_WIDGET(g->layout)));
/* if it was the last tab, destroy scaffold too */
if (gtk_notebook_get_n_pages(nsgtk_scaffolding_notebook(g->scaffold)) == 0) {
nsgtk_scaffolding_destroy(g->scaffold);
}
free(g);
} }
/**
* set favicon
*/
void gui_window_set_icon(struct gui_window *gw, hlcache_handle *icon)
{
struct bitmap *icon_bitmap = NULL;
/* free any existing icon */
if (gw->icon != NULL) {
g_object_unref(gw->icon);
gw->icon = NULL;
}
if (icon != NULL) {
icon_bitmap = content_get_bitmap(icon);
if (icon_bitmap != NULL) {
LOG(("Using %p bitmap", icon_bitmap));
gw->icon = nsgdk_pixbuf_get_from_surface(icon_bitmap->surface, 16, 16);
}
}
if (gw->icon == NULL) {
LOG(("Using default favicon"));
g_object_ref(favicon_pixbuf);
gw->icon = favicon_pixbuf;
}
nsgtk_scaffolding_set_icon(gw);
}
static void nsgtk_redraw_caret(struct gui_window *g) static void nsgtk_redraw_caret(struct gui_window *g)
{ {

View File

@ -36,6 +36,7 @@ extern int temp_open_background;
struct browser_window *nsgtk_get_browser_window(struct gui_window *g); struct browser_window *nsgtk_get_browser_window(struct gui_window *g);
nsgtk_scaffolding *nsgtk_get_scaffold(struct gui_window *g); nsgtk_scaffolding *nsgtk_get_scaffold(struct gui_window *g);
GdkPixbuf *nsgtk_get_icon(struct gui_window *gw);
void nsgtk_reflow_all_windows(void); void nsgtk_reflow_all_windows(void);
void nsgtk_window_process_reformats(void); void nsgtk_window_process_reformats(void);
float nsgtk_get_scale_for_gui(struct gui_window *g); float nsgtk_get_scale_for_gui(struct gui_window *g);