summaryrefslogtreecommitdiff
path: root/frontends/gtk
diff options
context:
space:
mode:
authorVincent Sanders <vince@kyllikki.org>2019-08-15 23:02:04 +0100
committerVincent Sanders <vince@kyllikki.org>2019-08-15 23:02:04 +0100
commit01f3879b647e69684ef8cbcc53f44b2c9b7b5df8 (patch)
tree52d332866e4d87fd6dda1d7ebf133d1007683271 /frontends/gtk
parent44f3846727d35ab17be3f779caa4a33548cdc152 (diff)
downloadnetsurf-01f3879b647e69684ef8cbcc53f44b2c9b7b5df8.tar.gz
netsurf-01f3879b647e69684ef8cbcc53f44b2c9b7b5df8.tar.bz2
Move favicon from url entry widget to notebook tab label
Diffstat (limited to 'frontends/gtk')
-rw-r--r--frontends/gtk/scaffolding.c24
-rw-r--r--frontends/gtk/scaffolding.h2
-rw-r--r--frontends/gtk/tabs.c136
-rw-r--r--frontends/gtk/tabs.h25
-rw-r--r--frontends/gtk/toolbar.c4
-rw-r--r--frontends/gtk/window.c17
-rw-r--r--frontends/gtk/window.h7
7 files changed, 133 insertions, 82 deletions
diff --git a/frontends/gtk/scaffolding.c b/frontends/gtk/scaffolding.c
index 619498900..e39efc43f 100644
--- a/frontends/gtk/scaffolding.c
+++ b/frontends/gtk/scaffolding.c
@@ -2378,28 +2378,6 @@ void gui_window_stop_throbber(struct gui_window* _g)
}
-/**
- * set favicon
- */
-void
-nsgtk_scaffolding_set_icon(struct gui_window *gw)
-{
- struct nsgtk_scaffolding *sc = nsgtk_get_scaffold(gw);
- GdkPixbuf *icon_pixbuf = nsgtk_get_icon(gw);
-
- /* check icon needs to be shown */
- if ((icon_pixbuf == NULL) ||
- (sc->top_level != gw)) {
- return;
- }
-
- nsgtk_entry_set_icon_from_pixbuf(sc->url_bar,
- GTK_ENTRY_ICON_PRIMARY,
- icon_pixbuf);
-
- gtk_widget_show_all(GTK_WIDGET(sc->buttons[URL_BAR_ITEM]->button));
-}
-
static void
nsgtk_scaffolding_set_websearch(struct nsgtk_scaffolding *g, const char *content)
{
@@ -2662,8 +2640,6 @@ void nsgtk_scaffolding_set_top_level(struct gui_window *gw)
/* clear effects of potential searches */
browser_window_search_clear(bw);
- nsgtk_scaffolding_set_icon(gw);
-
/* Ensure the window's title bar is updated */
nsgtk_window_set_title(gw, browser_window_get_title(bw));
diff --git a/frontends/gtk/scaffolding.h b/frontends/gtk/scaffolding.h
index e1fd9bf2a..7f7657e1b 100644
--- a/frontends/gtk/scaffolding.h
+++ b/frontends/gtk/scaffolding.h
@@ -226,8 +226,6 @@ void nsgtk_scaffolding_context_menu(struct nsgtk_scaffolding *g, gdouble x, gdou
void nsgtk_scaffolding_toolbar_size_allocate(GtkWidget *widget, 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_changed(GtkWidget *, GdkEventKey *, gpointer);
diff --git a/frontends/gtk/tabs.c b/frontends/gtk/tabs.c
index f99b2403b..9e5c1b39e 100644
--- a/frontends/gtk/tabs.c
+++ b/frontends/gtk/tabs.c
@@ -20,7 +20,7 @@
#include <string.h>
#include "utils/nsoption.h"
-#include "utils/messages.h"
+#include "utils/log.h"
#include "netsurf/browser_window.h"
#include "desktop/search.h"
@@ -32,9 +32,15 @@
#define TAB_WIDTH_N_CHARS 15
-/** callback to update sizes when style-set gtk signal */
-static void nsgtk_tab_update_size(GtkWidget *hbox, GtkStyle *previous_style,
- GtkWidget *close_button)
+static gint srcpagenum;
+
+/**
+ * callback to update sizes when style-set gtk signal
+ */
+static void
+nsgtk_tab_update_size(GtkWidget *hbox,
+ GtkStyle *previous_style,
+ GtkWidget *close_button)
{
PangoFontMetrics *metrics;
PangoContext *context;
@@ -63,20 +69,35 @@ static void nsgtk_tab_update_size(GtkWidget *hbox, GtkStyle *previous_style,
gtk_widget_set_size_request(close_button, w + 4, h + 4);
}
-/** Create a notebook tab label */
-static GtkWidget *nsgtk_tab_label_setup(struct gui_window *window)
+
+/**
+ * Create a notebook tab label
+ */
+static GtkWidget *
+nsgtk_tab_label_setup(struct gui_window *window,
+ const char *title,
+ GdkPixbuf *icon_pixbuf)
{
- GtkWidget *hbox, *label, *button, *close;
+ GtkWidget *hbox, *favicon, *label, *button, *close;
+
+ /* horizontal box */
+ hbox = nsgtk_hbox_new(FALSE, 3);
- hbox = nsgtk_hbox_new(FALSE, 2);
+ /* construct a favicon */
+ favicon = gtk_image_new();
+ if (icon_pixbuf != NULL) {
+ gtk_image_set_from_pixbuf(GTK_IMAGE(favicon), icon_pixbuf);
+ }
- label = gtk_label_new(messages_get("NewTab"));
+ /* construct a label */
+ label = gtk_label_new(title);
gtk_label_set_ellipsize(GTK_LABEL(label), PANGO_ELLIPSIZE_END);
gtk_label_set_single_line_mode(GTK_LABEL(label), TRUE);
nsgtk_widget_set_alignment(label, GTK_ALIGN_START, GTK_ALIGN_CENTER);
nsgtk_widget_set_margins(label, 0, 0);
gtk_widget_show(label);
+ /* construct a close button and attach signals */
button = gtk_button_new();
close = nsgtk_image_new_from_stock(NSGTK_STOCK_CLOSE,
@@ -86,40 +107,37 @@ static GtkWidget *nsgtk_tab_label_setup(struct gui_window *window)
gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE);
gtk_widget_set_tooltip_text(button, "Close this tab.");
-#ifdef FIXME
- GtkRcStyle *rcstyle;
- rcstyle = gtk_rc_style_new();
- rcstyle->xthickness = rcstyle->ythickness = 0;
- gtk_widget_modify_style(button, rcstyle);
- g_object_unref(rcstyle);
-#endif
-
g_signal_connect_swapped(button, "clicked",
G_CALLBACK(nsgtk_window_destroy_browser), window);
g_signal_connect(hbox, "style-set",
G_CALLBACK(nsgtk_tab_update_size), button);
+ /* pack the widgets into the label box */
+ gtk_box_pack_start(GTK_BOX(hbox), favicon, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE, 0);
gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0);
+ g_object_set_data(G_OBJECT(hbox), "favicon", favicon);
g_object_set_data(G_OBJECT(hbox), "label", label);
g_object_set_data(G_OBJECT(hbox), "close-button", button);
-
gtk_widget_show_all(hbox);
+
return hbox;
}
-#include "utils/log.h"
-
-/** callback when page is switched */
-static gint srcpagenum;
-/** The switch-page signal handler
+/**
+ * The before switch-page gtk signal handler
*
* This signal is handled both before and after delivery to work round
* issue that setting the selected tab during the switch-page signal
* fails
+ *
+ * \param notebook The notebook being changed
+ * \param page The notebook page being switched to
+ * \param selpagenum The currently selected page number
+ * \param user_data Unused
*/
static void
nsgtk_tab_switch_page(GtkNotebook *notebook,
@@ -130,6 +148,15 @@ nsgtk_tab_switch_page(GtkNotebook *notebook,
srcpagenum = gtk_notebook_get_current_page(notebook);
}
+
+/**
+ * The after switch-page gtk signal handler
+ *
+ * \param notebook The notebook being changed
+ * \param selpage The notebook page selected
+ * \param selpagenum The currently selected page number
+ * \param user_data Unused
+ */
static void
nsgtk_tab_switch_page_after(GtkNotebook *notebook,
GtkWidget *selpage,
@@ -169,10 +196,18 @@ nsgtk_tab_switch_page_after(GtkNotebook *notebook,
}
}
-static void nsgtk_tab_page_reordered(GtkNotebook *notebook,
- GtkWidget *child,
- guint page_num,
- gpointer user_data)
+/**
+ * The tab reordered gtk signal handler
+ *
+ * \param notebook The notebook being changed
+ * \param page_num The currently selected page number
+ * \param user_data Unused
+ */
+static void
+nsgtk_tab_page_reordered(GtkNotebook *notebook,
+ GtkWidget *child,
+ guint page_num,
+ gpointer user_data)
{
gint pages;
GtkWidget *addpage;
@@ -187,6 +222,13 @@ static void nsgtk_tab_page_reordered(GtkNotebook *notebook,
}
}
+/**
+ * The tab orientation signal handler
+ *
+ * \param notebook The notebook being changed
+ * \param page_num The currently selected page number
+ * \param user_data Unused
+ */
static void
nsgtk_tab_orientation(GtkNotebook *notebook)
{
@@ -210,7 +252,9 @@ nsgtk_tab_orientation(GtkNotebook *notebook)
}
}
-/** adds a "new tab" tab */
+/**
+ * adds a "new tab" tab
+ */
static GtkWidget *
nsgtk_tab_add_newtab(GtkNotebook *notebook)
{
@@ -238,7 +282,10 @@ nsgtk_tab_add_newtab(GtkNotebook *notebook)
return tablabel;
}
-/** callback to alter tab visibility when pages are added or removed */
+
+/**
+ * callback to alter tab visibility when pages are added or removed
+ */
static void
nsgtk_tab_visibility_update(GtkNotebook *notebook, GtkWidget *child, guint page)
{
@@ -260,6 +307,7 @@ nsgtk_tab_visibility_update(GtkNotebook *notebook, GtkWidget *child, guint page)
}
}
+
/* exported interface documented in gtk/tabs.h */
void nsgtk_tab_options_changed(GtkNotebook *notebook)
{
@@ -296,7 +344,9 @@ void nsgtk_tab_init(struct nsgtk_scaffolding *gs)
/* exported interface documented in gtk/tabs.h */
void nsgtk_tab_add(struct gui_window *gw,
GtkWidget *tab_contents,
- bool background)
+ bool background,
+ const char *title,
+ GdkPixbuf *icon_pixbuf)
{
GtkNotebook *notebook;
GtkWidget *tabBox;
@@ -308,7 +358,7 @@ void nsgtk_tab_add(struct gui_window *gw,
notebook = nsgtk_scaffolding_notebook(nsgtk_get_scaffold(gw));
- tabBox = nsgtk_tab_label_setup(gw);
+ tabBox = nsgtk_tab_label_setup(gw, title, icon_pixbuf);
nsgtk_window_set_tab(gw, tabBox);
@@ -332,6 +382,30 @@ void nsgtk_tab_add(struct gui_window *gw,
nsgtk_get_scaffold(gw))));
}
+
+/* exported interface documented in gtk/tabs.h */
+nserror nsgtk_tab_set_icon(struct gui_window *gw, GdkPixbuf *pixbuf)
+{
+ GtkWidget *favicon;
+ GtkWidget *tab;
+
+ if (pixbuf == NULL) {
+ return NSERROR_INVALID;
+ }
+
+ tab = nsgtk_window_get_tab(gw);
+ if (tab == NULL) {
+ return NSERROR_INVALID;
+ }
+
+ favicon = g_object_get_data(G_OBJECT(tab), "favicon");
+
+ gtk_image_set_from_pixbuf(GTK_IMAGE(favicon), pixbuf);
+
+ return NSERROR_OK;
+}
+
+
/* exported interface documented in gtk/tabs.h */
void nsgtk_tab_set_title(struct gui_window *g, const char *title)
{
diff --git a/frontends/gtk/tabs.h b/frontends/gtk/tabs.h
index 440d61336..4e9e2c84d 100644
--- a/frontends/gtk/tabs.h
+++ b/frontends/gtk/tabs.h
@@ -16,15 +16,20 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#ifndef _NETSURF_GTK_TABS_H_
-#define _NETSURF_GTK_TABS_H_
+#ifndef NETSURF_GTK_TABS_H_
+#define NETSURF_GTK_TABS_H_
struct gui_window;
void nsgtk_tab_init(struct nsgtk_scaffolding *gs);
-void nsgtk_tab_add(struct gui_window *window, GtkWidget *tab_contents, bool background);
-/** set the tab title
+/**
+ * Add new tab to notebook.
+ */
+void nsgtk_tab_add(struct gui_window *window, GtkWidget *tab_contents, bool background, const char *title, GdkPixbuf *icon_pixbuf);
+
+/**
+ * set the tab title
*
* The tab title will be set to the parameter
*
@@ -34,6 +39,18 @@ void nsgtk_tab_add(struct gui_window *window, GtkWidget *tab_contents, bool back
* \param title The title text which may not be NULL.
*/
void nsgtk_tab_set_title(struct gui_window *g, const char *title);
+
+/**
+ * set the tab icon
+ *
+ * The tab icon will be set to the \a pixbuf parameter
+ *
+ * \param gw The gui window to set teh tab icon for.
+ * \param pixbuf The pixbuf to set the icon to.
+ * \return NSERROR_OK on sucess else appropriate code.
+ */
+nserror nsgtk_tab_set_icon(struct gui_window *gw, GdkPixbuf *pixbuf);
+
void nsgtk_tab_options_changed(GtkNotebook *notebook);
nserror nsgtk_tab_close_current(GtkNotebook *notebook);
nserror nsgtk_tab_prev(GtkNotebook *notebook);
diff --git a/frontends/gtk/toolbar.c b/frontends/gtk/toolbar.c
index d5510f41e..d1b129afd 100644
--- a/frontends/gtk/toolbar.c
+++ b/frontends/gtk/toolbar.c
@@ -472,10 +472,6 @@ nsgtk_toolbar_make_widget(struct nsgtk_scaffolding *g,
return NULL;
}
- nsgtk_entry_set_icon_from_pixbuf(entry,
- GTK_ENTRY_ICON_PRIMARY,
- favicon_pixbuf);
-
gtk_container_add(GTK_CONTAINER(w), entry);
gtk_tool_item_set_expand(GTK_TOOL_ITEM(w), TRUE);
break;
diff --git a/frontends/gtk/window.c b/frontends/gtk/window.c
index e6581c7eb..766ae4173 100644
--- a/frontends/gtk/window.c
+++ b/frontends/gtk/window.c
@@ -35,6 +35,7 @@
#include "utils/log.h"
#include "utils/utf8.h"
#include "utils/nsoption.h"
+#include "utils/messages.h"
#include "netsurf/content.h"
#include "netsurf/browser_window.h"
#include "netsurf/mouse.h"
@@ -136,11 +137,6 @@ struct nsgtk_scaffolding *nsgtk_get_scaffold(struct gui_window *g)
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)
{
return g->bw;
@@ -720,8 +716,8 @@ static void window_destroy(GtkWidget *widget, gpointer data)
*/
static struct gui_window *
gui_window_create(struct browser_window *bw,
- struct gui_window *existing,
- gui_window_create_flags flags)
+ struct gui_window *existing,
+ gui_window_create_flags flags)
{
struct gui_window *g; /* what is being created to return */
bool tempback;
@@ -865,7 +861,7 @@ gui_window_create(struct browser_window *bw,
tempback = true;
break;
}
- nsgtk_tab_add(g, g->container, tempback);
+ nsgtk_tab_add(g, g->container, tempback, messages_get("NewTab"), g->icon);
/* safe to drop the reference to the tab_builder as the container is
* referenced by the notebook now.
@@ -918,7 +914,8 @@ static void gui_window_destroy(struct gui_window *g)
* \param gw gtk gui window to set favicon on.
* \param icon A handle to the new favicon content.
*/
-static void gui_window_set_icon(struct gui_window *gw, struct hlcache_handle *icon)
+static void
+gui_window_set_icon(struct gui_window *gw, struct hlcache_handle *icon)
{
struct bitmap *icon_bitmap = NULL;
@@ -942,7 +939,7 @@ static void gui_window_set_icon(struct gui_window *gw, struct hlcache_handle *ic
gw->icon = favicon_pixbuf;
}
- nsgtk_scaffolding_set_icon(gw);
+ nsgtk_tab_set_icon(gw, gw->icon);
}
static bool gui_window_get_scroll(struct gui_window *g, int *sx, int *sy)
diff --git a/frontends/gtk/window.h b/frontends/gtk/window.h
index 4bedea428..462ed17a8 100644
--- a/frontends/gtk/window.h
+++ b/frontends/gtk/window.h
@@ -45,13 +45,6 @@ struct browser_window *nsgtk_get_browser_window(struct gui_window *gw);
struct nsgtk_scaffolding *nsgtk_get_scaffold(struct gui_window *gw);
/**
- * get gdk pixbuf of favicon from gui window handle
- *
- * \param gw gui window handle
- */
-GdkPixbuf *nsgtk_get_icon(struct gui_window *gw);
-
-/**
* cause all windows be be reflowed
*/
void nsgtk_reflow_all_windows(void);