summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gtk/compat.c45
-rw-r--r--gtk/compat.h13
-rw-r--r--gtk/scaffolding.c92
-rw-r--r--gtk/toolbar.c37
4 files changed, 107 insertions, 80 deletions
diff --git a/gtk/compat.c b/gtk/compat.c
index 86b87d4cb..8d8ac698b 100644
--- a/gtk/compat.c
+++ b/gtk/compat.c
@@ -124,3 +124,48 @@ gchar *nsgtk_combo_box_text_get_active_text(GtkWidget *combo_box)
return gtk_combo_box_get_active_text(GTK_COMBO_BOX(combo_box));
#endif
}
+
+GtkWidget *nsgtk_entry_new(void)
+{
+#if GTK_CHECK_VERSION(2,16,0)
+ return gtk_entry_new();
+#else
+ return GTK_WIDGET(sexy_icon_entry_new());
+#endif
+}
+
+void nsgtk_entry_set_icon_from_pixbuf(GtkWidget *entry, GtkEntryIconPosition icon_pos, GdkPixbuf *pixbuf)
+{
+#if GTK_CHECK_VERSION(2,16,0)
+ gtk_entry_set_icon_from_pixbuf(GTK_ENTRY(entry), icon_pos, pixbuf);
+#else
+ GtkImage *image = GTK_IMAGE(gtk_image_new_from_pixbuf(pixbuf));
+
+ if (image != NULL) {
+ sexy_icon_entry_set_icon(SEXY_ICON_ENTRY(entry),
+ (SexyIconEntryPosition)icon_pos,
+ image);
+
+ g_object_unref(image);
+ }
+
+#endif
+}
+
+void nsgtk_entry_set_icon_from_stock(GtkWidget *entry, GtkEntryIconPosition icon_pos, const gchar *stock_id)
+{
+#if GTK_CHECK_VERSION(2,16,0)
+ gtk_entry_set_icon_from_stock(GTK_ENTRY(entry), icon_pos, stock_id);
+#else
+ GtkImage *image = GTK_IMAGE(gtk_image_new_from_stock(stock_id,
+ GTK_ICON_SIZE_LARGE_TOOLBAR));
+
+ if (image != NULL) {
+ sexy_icon_entry_set_icon(SEXY_ICON_ENTRY(entry),
+ (SexyIconEntryPosition)icon_pos,
+ image);
+ g_object_unref(image);
+ }
+
+#endif
+}
diff --git a/gtk/compat.h b/gtk/compat.h
index 3b0dd497e..ee95c6dd5 100644
--- a/gtk/compat.h
+++ b/gtk/compat.h
@@ -37,4 +37,17 @@ GtkWidget *nsgtk_combo_box_text_new(void);
void nsgtk_combo_box_text_append_text(GtkWidget *combo_box, const gchar *text);
gchar *nsgtk_combo_box_text_get_active_text(GtkWidget *combo_box);
+GtkWidget *nsgtk_entry_new(void);
+void nsgtk_entry_set_icon_from_pixbuf(GtkWidget *entry, GtkEntryIconPosition icon_pos, GdkPixbuf *pixbuf);
+void nsgtk_entry_set_icon_from_stock(GtkWidget *entry, GtkEntryIconPosition icon_pos, const gchar *stock_id);
+
+#if !GTK_CHECK_VERSION(2,16,0)
+#include "gtk/sexy_icon_entry.h"
+
+typedef enum {
+ GTK_ENTRY_ICON_PRIMARY = SEXY_ICON_ENTRY_PRIMARY,
+ GTK_ENTRY_ICON_SECONDARY = SEXY_ICON_ENTRY_SECONDARY
+} GtkEntryIconPosition;
+#endif
+
#endif /* NETSURF_GTK_COMPAT_H */
diff --git a/gtk/scaffolding.c b/gtk/scaffolding.c
index 7d2814165..53c8a4fc2 100644
--- a/gtk/scaffolding.c
+++ b/gtk/scaffolding.c
@@ -74,7 +74,6 @@
#include "gtk/treeview.h"
#include "gtk/window.h"
#include "gtk/options.h"
-#include "gtk/sexy_icon_entry.h"
#include "gtk/compat.h"
#include "gtk/gdk.h"
#include "image/ico.h"
@@ -135,9 +134,7 @@ struct gtk_scaffolding {
GtkToolbar *tool_bar;
struct nsgtk_button_connect *buttons[PLACEHOLDER_BUTTON];
GtkImage *throbber;
- GtkImage *icoFav;
struct gtk_search *search;
- GtkImage *webSearchIco;
GtkWidget *webSearchEntry;
GtkPaned *status_pane;
@@ -1993,22 +1990,6 @@ void gui_window_stop_throbber(struct gui_window* _g)
gtk_image_set_from_pixbuf(g->throbber, nsgtk_throbber->framedata[0]);
}
-static GtkImage *
-nsgtk_image_new_from_surface(cairo_surface_t *surface, int w, int h)
-{
- GdkPixbuf *pixbuf;
- GtkImage *image = NULL;
-
- pixbuf = nsgdk_pixbuf_get_from_surface(surface, w, h);
-
- if (pixbuf != NULL) {
- image = GTK_IMAGE(gtk_image_new_from_pixbuf(pixbuf));
- }
-
- g_object_unref(pixbuf);
-
- return image;
-}
/**
* set favicon
@@ -2016,76 +1997,71 @@ nsgtk_image_new_from_surface(cairo_surface_t *surface, int w, int h)
void gui_window_set_icon(struct gui_window *_g, hlcache_handle *icon)
{
struct gtk_scaffolding *g = nsgtk_get_scaffold(_g);
- struct bitmap *icon_bitmap;
- GtkImage *iconImage = NULL;
+ struct bitmap *icon_bitmap = NULL;
+ GdkPixbuf *icon_pixbuf;
if (g->top_level != _g) {
return;
}
- icon_bitmap = (icon != NULL) ? content_get_bitmap(icon) : NULL;
- if (icon_bitmap != NULL) {
- iconImage = nsgtk_image_new_from_surface(icon_bitmap->surface, 16, 16);
- }
+ if (icon != NULL) {
+ icon_bitmap = content_get_bitmap(icon);
+ if (icon_bitmap != NULL) {
+ icon_pixbuf = nsgdk_pixbuf_get_from_surface(icon_bitmap->surface, 16, 16);
+ }
+ }
- if (iconImage == NULL) {
+ if (icon_pixbuf == NULL) {
char imagepath[strlen(res_dir_location) +
SLEN("favicon.png") + 1];
sprintf(imagepath, "%sfavicon.png", res_dir_location);
- iconImage = GTK_IMAGE(gtk_image_new_from_file(imagepath));
+ icon_pixbuf = gdk_pixbuf_new_from_file(imagepath, NULL);
}
- if (iconImage == NULL)
+ if (icon_pixbuf == NULL) {
return;
-
- if (g->icoFav != NULL) {
- g_object_unref(g->icoFav);
}
- g->icoFav = iconImage;
+ nsgtk_entry_set_icon_from_pixbuf(g->url_bar,
+ GTK_ENTRY_ICON_PRIMARY,
+ icon_pixbuf);
- sexy_icon_entry_set_icon(SEXY_ICON_ENTRY(g->url_bar),
- SEXY_ICON_ENTRY_PRIMARY, GTK_IMAGE(g->icoFav));
gtk_widget_show_all(GTK_WIDGET(g->buttons[URL_BAR_ITEM]->button));
+
+ g_object_unref(icon_pixbuf);
+
}
void gui_window_set_search_ico(hlcache_handle *ico)
{
- GdkPixbuf *pbico = NULL;
- GtkImage *searchico;
- struct bitmap *ico_bitmap;
+ struct bitmap *srch_bitmap;
nsgtk_scaffolding *current;
+ GdkPixbuf *srch_pixbuf;
- if (ico == NULL && (ico = search_web_ico()) == NULL)
+ if ((ico == NULL) &&
+ (ico = search_web_ico()) == NULL) {
return;
+ }
- ico_bitmap = content_get_bitmap(ico);
- if (ico_bitmap == NULL)
+ srch_bitmap = content_get_bitmap(ico);
+ if (srch_bitmap == NULL) {
return;
+ }
+
+ srch_pixbuf = nsgdk_pixbuf_get_from_surface(srch_bitmap->surface, 16, 16);
- pbico = nsgdk_pixbuf_get_from_surface(ico_bitmap->surface, 16, 16);
- if (pbico == NULL) {
+ if (srch_pixbuf == NULL) {
return;
}
- searchico = GTK_IMAGE(gtk_image_new_from_pixbuf(pbico));
-
/* add ico to each window's toolbar */
for (current = scaf_list; current != NULL; current = current->next) {
- if (searchico != NULL) {
- /** \todo Are we leaking webSearchIco here? */
- current->webSearchIco = searchico;
- sexy_icon_entry_set_icon(SEXY_ICON_ENTRY(
- current->webSearchEntry),
- SEXY_ICON_ENTRY_PRIMARY,
- current->webSearchIco);
- }
-
- searchico = GTK_IMAGE(gtk_image_new_from_pixbuf(pbico));
+ nsgtk_entry_set_icon_from_pixbuf(current->webSearchEntry,
+ GTK_ENTRY_ICON_PRIMARY,
+ srch_pixbuf);
}
- g_object_unref(pbico);
-
+ g_object_unref(srch_pixbuf);
}
bool nsgtk_scaffolding_is_busy(nsgtk_scaffolding *g)
@@ -2156,8 +2132,6 @@ void nsgtk_scaffolding_update_url_bar_ref(nsgtk_scaffolding *g)
{
g->url_bar = GTK_WIDGET(gtk_bin_get_child(GTK_BIN(
nsgtk_scaffolding_button(g, URL_BAR_ITEM)->button)));
- g->icoFav = sexy_icon_entry_get_icon(SEXY_ICON_ENTRY(g->url_bar),
- SEXY_ICON_ENTRY_PRIMARY);
gtk_entry_set_completion(GTK_ENTRY(g->url_bar),
g->url_bar_completion);
@@ -2172,8 +2146,6 @@ void nsgtk_scaffolding_update_websearch_ref(nsgtk_scaffolding *g)
{
g->webSearchEntry = gtk_bin_get_child(GTK_BIN(
g->buttons[WEBSEARCH_ITEM]->button));
- g->webSearchIco = sexy_icon_entry_get_icon(SEXY_ICON_ENTRY(
- g->webSearchEntry), SEXY_ICON_ENTRY_PRIMARY);
}
void nsgtk_scaffolding_set_websearch(nsgtk_scaffolding *g, const char *content)
diff --git a/gtk/toolbar.c b/gtk/toolbar.c
index 9866becb1..3d2fe64cd 100644
--- a/gtk/toolbar.c
+++ b/gtk/toolbar.c
@@ -17,7 +17,12 @@
*/
#include <gtk/gtk.h>
+
#include "desktop/searchweb.h"
+#include "utils/log.h"
+#include "utils/messages.h"
+#include "utils/utils.h"
+
#include "gtk/toolbar.h"
#include "gtk/gui.h"
#include "gtk/scaffolding.h"
@@ -25,10 +30,7 @@
#include "gtk/theme.h"
#include "gtk/throbber.h"
#include "gtk/window.h"
-#include "gtk/sexy_icon_entry.h"
-#include "utils/log.h"
-#include "utils/messages.h"
-#include "utils/utils.h"
+#include "gtk/compat.h"
static GtkTargetEntry entry = {(char *)"nsgtk_button_data",
GTK_TARGET_SAME_APP, 0};
@@ -705,9 +707,8 @@ GtkWidget *nsgtk_toolbar_make_widget(nsgtk_scaffolding *g,
char imagefile[strlen(res_dir_location) + SLEN("favicon.png")
+ 1];
sprintf(imagefile, "%sfavicon.png", res_dir_location);
- GtkWidget *image = GTK_WIDGET(gtk_image_new_from_file(
- imagefile));
- GtkWidget *entry = GTK_WIDGET(sexy_icon_entry_new());
+ GdkPixbuf *iconbuf = gdk_pixbuf_new_from_file(imagefile, NULL);
+ GtkWidget *entry = nsgtk_entry_new();
GtkWidget *w = GTK_WIDGET(gtk_tool_item_new());
if ((entry == NULL) || (w == NULL)) {
@@ -715,10 +716,9 @@ GtkWidget *nsgtk_toolbar_make_widget(nsgtk_scaffolding *g,
return NULL;
}
- if (image != NULL)
- sexy_icon_entry_set_icon(SEXY_ICON_ENTRY(entry),
- SEXY_ICON_ENTRY_PRIMARY,
- GTK_IMAGE(image));
+ if (iconbuf != NULL) {
+ nsgtk_entry_set_icon_from_pixbuf(entry, GTK_ENTRY_ICON_PRIMARY, iconbuf);
+ }
gtk_container_add(GTK_CONTAINER(w), entry);
gtk_tool_item_set_expand(GTK_TOOL_ITEM(w), TRUE);
@@ -754,9 +754,9 @@ GtkWidget *nsgtk_toolbar_make_widget(nsgtk_scaffolding *g,
gtk_image_new_from_stock("gtk-find",
GTK_ICON_SIZE_LARGE_TOOLBAR)),
"[websearch]"));
- GtkWidget *image = GTK_WIDGET(gtk_image_new_from_stock(
- "gtk-info", GTK_ICON_SIZE_LARGE_TOOLBAR));
- GtkWidget *entry = GTK_WIDGET(sexy_icon_entry_new());
+
+ GtkWidget *entry = nsgtk_entry_new();
+
GtkWidget *w = GTK_WIDGET(gtk_tool_item_new());
if ((entry == NULL) || (w == NULL)) {
@@ -764,12 +764,9 @@ GtkWidget *nsgtk_toolbar_make_widget(nsgtk_scaffolding *g,
return NULL;
}
- gtk_widget_set_size_request(entry, NSGTK_WEBSEARCH_WIDTH,
- -1);
- if (image != NULL)
- sexy_icon_entry_set_icon(SEXY_ICON_ENTRY(entry),
- SEXY_ICON_ENTRY_PRIMARY,
- GTK_IMAGE(image));
+ gtk_widget_set_size_request(entry, NSGTK_WEBSEARCH_WIDTH, -1);
+
+ nsgtk_entry_set_icon_from_stock(entry, GTK_ENTRY_ICON_PRIMARY, "gtk-info");
gtk_container_add(GTK_CONTAINER(w), entry);
return w;