summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent Sanders <vince@kyllikki.org>2019-08-31 23:53:51 +0100
committerDaniel Silverstone <dsilvers@digital-scurf.org>2019-09-21 10:53:41 +0100
commit2e8861dc05325c88cfb8130e7eddd0967e4d4b09 (patch)
treee2b97ebfd3f79f3045b0232e13d682bda5bc3b33
parente84990bc891c7a75930fddd614516d3eb170cd75 (diff)
downloadnetsurf-2e8861dc05325c88cfb8130e7eddd0967e4d4b09.tar.gz
netsurf-2e8861dc05325c88cfb8130e7eddd0967e4d4b09.tar.bz2
make web search icon setting work properly
-rw-r--r--desktop/searchweb.c35
-rw-r--r--desktop/searchweb.h11
-rw-r--r--frontends/gtk/gui.c1
-rw-r--r--frontends/gtk/scaffolding.c148
-rw-r--r--frontends/gtk/scaffolding.h8
-rw-r--r--frontends/gtk/toolbar.c53
-rw-r--r--frontends/gtk/toolbar.h4
-rw-r--r--frontends/gtk/window.c65
-rw-r--r--frontends/gtk/window.h1
9 files changed, 159 insertions, 167 deletions
diff --git a/desktop/searchweb.c b/desktop/searchweb.c
index 91a8118ca..2c0873de5 100644
--- a/desktop/searchweb.c
+++ b/desktop/searchweb.c
@@ -366,6 +366,33 @@ search_web_omni(const char *term,
}
/* exported interface documented in desktop/searchweb.h */
+nserror search_web_get_provider_bitmap(struct bitmap **bitmap_out)
+{
+ struct search_provider *provider;
+ struct bitmap *ico_bitmap = NULL;
+
+ /* must be initialised */
+ if (search_web_ctx.providers == NULL) {
+ return NSERROR_INIT_FAILED;
+ }
+
+ provider = &search_web_ctx.providers[search_web_ctx.current];
+
+ /* set the icon now (if we can) at least to the default */
+ if (provider->ico_handle != NULL) {
+ ico_bitmap = content_get_bitmap(provider->ico_handle);
+ }
+ if ((ico_bitmap == NULL) &&
+ (search_web_ctx.default_ico_handle != NULL)) {
+ ico_bitmap = content_get_bitmap(search_web_ctx.default_ico_handle);
+ }
+
+ *bitmap_out = ico_bitmap;
+ return NSERROR_OK;
+}
+
+
+/* exported interface documented in desktop/searchweb.h */
nserror search_web_select_provider(int selection)
{
struct search_provider *provider;
@@ -520,10 +547,14 @@ nserror search_web_init(const char *provider_fname)
}
/* get default search icon */
- ret = hlcache_handle_retrieve(icon_nsurl, 0, NULL, NULL,
+ ret = hlcache_handle_retrieve(icon_nsurl,
+ 0,
+ NULL,
+ NULL,
default_ico_callback,
&search_web_ctx,
- NULL, CONTENT_IMAGE,
+ NULL,
+ CONTENT_IMAGE,
&search_web_ctx.default_ico_handle);
nsurl_unref(icon_nsurl);
if (ret != NSERROR_OK) {
diff --git a/desktop/searchweb.h b/desktop/searchweb.h
index a96e7787b..69748b6d6 100644
--- a/desktop/searchweb.h
+++ b/desktop/searchweb.h
@@ -72,6 +72,17 @@ enum search_web_omni_flags {
*/
nserror search_web_omni(const char *term, enum search_web_omni_flags flags, struct nsurl **url_out);
+
+/**
+ * obtain the current providers bitmap
+ *
+ * obtain the icon representing the current web search provider
+ *
+ * \param bitmap_out recives the resulting bitmap which may be NULL
+ * \return NSERROR_OK on success or NSERROR_INIT_FAILED if not initialised
+ */
+nserror search_web_get_provider_bitmap(struct bitmap **bitmap_out);
+
/**
* Change the currently selected web search provider.
*
diff --git a/frontends/gtk/gui.c b/frontends/gtk/gui.c
index ba37413b3..d033a5735 100644
--- a/frontends/gtk/gui.c
+++ b/frontends/gtk/gui.c
@@ -304,6 +304,7 @@ static nserror nsgtk_init(int argc, char** argv, char **respath)
resource_filename);
free(resource_filename);
}
+ search_web_select_provider(nsoption_int(search_provider));
/* Default favicon */
res = nsgdk_pixbuf_new_from_resname("favicon.png", &favicon_pixbuf);
diff --git a/frontends/gtk/scaffolding.c b/frontends/gtk/scaffolding.c
index a7414ebbd..ccfe1a1f2 100644
--- a/frontends/gtk/scaffolding.c
+++ b/frontends/gtk/scaffolding.c
@@ -1449,135 +1449,6 @@ nserror nsgtk_scaffolding_throbber(struct gui_window* gw, bool active)
}
-static void
-nsgtk_scaffolding_set_websearch(struct nsgtk_scaffolding *g, const char *content)
-{
-#if 0
- /** \todo this code appears technically correct, though
- * currently has no effect at all.
- */
- PangoLayout *lo = gtk_entry_get_layout(GTK_ENTRY(g->webSearchEntry));
- if (lo != NULL) {
- pango_layout_set_font_description(lo, NULL);
- PangoFontDescription *desc = pango_font_description_new();
- if (desc != NULL) {
- pango_font_description_set_style(desc,
- PANGO_STYLE_ITALIC);
- pango_font_description_set_family(desc, "Arial");
- pango_font_description_set_weight(desc,
- PANGO_WEIGHT_ULTRALIGHT);
- pango_font_description_set_size(desc,
- 10 * PANGO_SCALE);
- pango_layout_set_font_description(lo, desc);
- }
-
- PangoAttrList *list = pango_attr_list_new();
- if (list != NULL) {
- PangoAttribute *italic = pango_attr_style_new(
- PANGO_STYLE_ITALIC);
- if (italic != NULL) {
- italic->start_index = 0;
- italic->end_index = strlen(content);
- }
- PangoAttribute *grey = pango_attr_foreground_new(
- 0x7777, 0x7777, 0x7777);
- if (grey != NULL) {
- grey->start_index = 0;
- grey->end_index = strlen(content);
- }
- pango_attr_list_insert(list, italic);
- pango_attr_list_insert(list, grey);
- pango_layout_set_attributes(lo, list);
- pango_attr_list_unref(list);
- }
- pango_layout_set_text(lo, content, -1);
- }
-/* an alternative method */
-/* char *parse = malloc(strlen(content) + 1);
- PangoAttrList *list = pango_layout_get_attributes(lo);
- char *markup = g_strconcat("<span foreground='#777777'><i>", content,
- "</i></span>", NULL);
- pango_parse_markup(markup, -1, 0, &list, &parse, NULL, NULL);
- gtk_widget_show_all(g->webSearchEntry);
-*/
- gtk_entry_set_visibility(GTK_ENTRY(g->webSearchEntry), TRUE);
- gtk_entry_set_text(GTK_ENTRY(g->webSearchEntry), content);
-#endif
-}
-
-
-/**
- * GTK UI callback when search provider details are updated.
- *
- * \param provider_name The providers name.
- * \param provider_bitmap The bitmap representing the provider.
- * \return NSERROR_OK on success else error code.
- */
-static nserror
-gui_search_web_provider_update(const char *provider_name,
- struct bitmap *provider_bitmap)
-{
- struct nsgtk_scaffolding *current;
- GdkPixbuf *srch_pixbuf = NULL;
- char *searchcontent;
-
- NSLOG(netsurf, INFO, "name:%s bitmap %p", provider_name,
- provider_bitmap);
-
- if (provider_bitmap != NULL) {
- srch_pixbuf = nsgdk_pixbuf_get_from_surface(provider_bitmap->surface, 16, 16);
-
- if (srch_pixbuf == NULL) {
- return NSERROR_NOMEM;
- }
- }
-
- /* setup the search content name */
- searchcontent = malloc(strlen(provider_name) + SLEN("Search ") + 1);
- if (searchcontent != NULL) {
- sprintf(searchcontent, "Search %s", provider_name);
- }
-#if 0
- /* set the search provider parameters up in each scaffold */
- for (current = scaf_list; current != NULL; current = current->next) {
- if (current->webSearchEntry == NULL) {
- continue;
- }
-
- /* add ico to each window's toolbar */
- if (srch_pixbuf != NULL) {
- nsgtk_entry_set_icon_from_pixbuf(current->webSearchEntry,
- GTK_ENTRY_ICON_PRIMARY,
- srch_pixbuf);
- } else {
- nsgtk_entry_set_icon_from_stock(current->webSearchEntry,
- GTK_ENTRY_ICON_PRIMARY,
- NSGTK_STOCK_FIND);
- }
-
- /* set search entry text */
- if (searchcontent != NULL) {
- nsgtk_scaffolding_set_websearch(current, searchcontent);
- } else {
- nsgtk_scaffolding_set_websearch(current, provider_name);
- }
- }
-#endif
- free(searchcontent);
-
- if (srch_pixbuf != NULL) {
- g_object_unref(srch_pixbuf);
- }
-
- return NSERROR_OK;
-}
-
-static struct gui_search_web_table search_web_table = {
- .provider_update = gui_search_web_provider_update,
-};
-
-struct gui_search_web_table *nsgtk_search_web_table = &search_web_table;
-
/* exported interface documented in gtk/scaffolding.h */
nserror nsgtk_scaffolding_destroy_all(void)
{
@@ -1618,12 +1489,6 @@ GtkWidget *nsgtk_scaffolding_urlbar(struct nsgtk_scaffolding *g)
}
/* exported interface documented in gtk/scaffolding.h */
-GtkWidget *nsgtk_scaffolding_websearch(struct nsgtk_scaffolding *g)
-{
- return NULL;//g->webSearchEntry;
-}
-
-/* exported interface documented in gtk/scaffolding.h */
GtkToolbar *nsgtk_scaffolding_toolbar(struct nsgtk_scaffolding *g)
{
return NULL;//g->tool_bar;
@@ -1658,15 +1523,6 @@ void nsgtk_scaffolding_reset_offset(struct nsgtk_scaffolding *g)
/* exported interface documented in gtk/scaffolding.h */
-void nsgtk_scaffolding_update_websearch_ref(struct nsgtk_scaffolding *g)
-{
-#if 0
- g->webSearchEntry = gtk_bin_get_child(GTK_BIN(
- g->buttons[WEBSEARCH_ITEM]->button));
-#endif
-}
-
-/* exported interface documented in gtk/scaffolding.h */
void nsgtk_scaffolding_toggle_search_bar_visibility(struct nsgtk_scaffolding *g)
{
gboolean vis;
@@ -1803,7 +1659,6 @@ struct nsgtk_scaffolding *nsgtk_new_scaffolding(struct gui_window *toplevel)
{
nserror res;
struct nsgtk_scaffolding *gs;
- int i;
GtkAccelGroup *group;
gs = calloc(1, sizeof(*gs));
@@ -1916,9 +1771,6 @@ struct nsgtk_scaffolding *nsgtk_new_scaffolding(struct gui_window *toplevel)
/* set icon images */
nsgtk_theme_implement(gs);
- /* set web search provider */
- search_web_select_provider(nsoption_int(search_provider));
-
/* finally, show the window. */
gtk_widget_show(GTK_WIDGET(gs->window));
diff --git a/frontends/gtk/scaffolding.h b/frontends/gtk/scaffolding.h
index a8cea20d2..825310fa1 100644
--- a/frontends/gtk/scaffolding.h
+++ b/frontends/gtk/scaffolding.h
@@ -28,7 +28,6 @@ struct gui_window;
struct gui_search_web_table;
struct nsurl;
-extern struct gui_search_web_table *nsgtk_search_web_table;
struct gtk_history_window {
@@ -98,11 +97,6 @@ GtkNotebook *nsgtk_scaffolding_notebook(struct nsgtk_scaffolding *g);
GtkWidget *nsgtk_scaffolding_urlbar(struct nsgtk_scaffolding *g);
/**
- * Get the gtk web search entry from a scaffold.
- */
-GtkWidget *nsgtk_scaffolding_websearch(struct nsgtk_scaffolding *g);
-
-/**
* Get the gtk toolbar from a scaffold.
*/
GtkToolbar *nsgtk_scaffolding_toolbar(struct nsgtk_scaffolding *g);
@@ -131,8 +125,6 @@ void nsgtk_scaffolding_reset_offset(struct nsgtk_scaffolding *g);
struct nsgtk_scaffolding *nsgtk_scaffolding_iterate(struct nsgtk_scaffolding *g);
-void nsgtk_scaffolding_update_websearch_ref(struct nsgtk_scaffolding *g);
-
void nsgtk_scaffolding_toggle_search_bar_visibility(struct nsgtk_scaffolding *g);
/**
diff --git a/frontends/gtk/toolbar.c b/frontends/gtk/toolbar.c
index 694c27109..ae87010a6 100644
--- a/frontends/gtk/toolbar.c
+++ b/frontends/gtk/toolbar.c
@@ -67,6 +67,8 @@
#include "gtk/hotlist.h"
#include "gtk/cookies.h"
#include "gtk/about.h"
+#include "gtk/gdk.h"
+#include "gtk/bitmap.h"
#include "gtk/toolbar.h"
/**
@@ -641,8 +643,12 @@ make_toolbar_item_websearch(void)
GTK_ICON_SIZE_LARGE_TOOLBAR)),
"[websearch]");
} else {
- GtkWidget *entry = nsgtk_entry_new();
+ nserror res;
+ GtkWidget *entry;
+ struct bitmap *bitmap;
+ GdkPixbuf *pixbuf = NULL;
+ entry = nsgtk_entry_new();
item = gtk_tool_item_new();
if ((entry == NULL) || (item == NULL)) {
@@ -651,9 +657,21 @@ make_toolbar_item_websearch(void)
gtk_widget_set_size_request(entry, NSGTK_WEBSEARCH_WIDTH, -1);
- nsgtk_entry_set_icon_from_stock(entry,
- GTK_ENTRY_ICON_PRIMARY,
- NSGTK_STOCK_INFO);
+ res = search_web_get_provider_bitmap(&bitmap);
+ if ((res == NSERROR_OK) && (bitmap != NULL)) {
+ pixbuf = nsgdk_pixbuf_get_from_surface(bitmap->surface,
+ 16, 16);
+ }
+
+ if (pixbuf != NULL) {
+ nsgtk_entry_set_icon_from_pixbuf(entry,
+ GTK_ENTRY_ICON_PRIMARY,
+ pixbuf);
+ } else {
+ nsgtk_entry_set_icon_from_stock(entry,
+ GTK_ENTRY_ICON_PRIMARY,
+ NSGTK_STOCK_INFO);
+ }
gtk_container_add(GTK_CONTAINER(item), entry);
}
@@ -3629,6 +3647,33 @@ nserror nsgtk_toolbar_set_url(struct nsgtk_toolbar *tb, nsurl *url)
/* exported interface documented in toolbar.h */
nserror
+nsgtk_toolbar_set_websearch_image(struct nsgtk_toolbar *tb, GdkPixbuf *pixbuf)
+{
+ GtkWidget *entry;
+
+ if (tb->buttons[WEBSEARCH_ITEM]->button == NULL) {
+ /* no toolbar item */
+ return NSERROR_INVALID;
+ }
+
+ entry = gtk_bin_get_child(GTK_BIN(tb->buttons[WEBSEARCH_ITEM]->button));
+
+ if (pixbuf != NULL) {
+ nsgtk_entry_set_icon_from_pixbuf(entry,
+ GTK_ENTRY_ICON_PRIMARY,
+ pixbuf);
+ } else {
+ nsgtk_entry_set_icon_from_stock(entry,
+ GTK_ENTRY_ICON_PRIMARY,
+ NSGTK_STOCK_INFO);
+ }
+
+ return NSERROR_OK;
+}
+
+
+/* exported interface documented in toolbar.h */
+nserror
nsgtk_toolbar_item_activate(struct nsgtk_toolbar *tb,
nsgtk_toolbar_button itemid)
{
diff --git a/frontends/gtk/toolbar.h b/frontends/gtk/toolbar.h
index b89774ba2..c302194eb 100644
--- a/frontends/gtk/toolbar.h
+++ b/frontends/gtk/toolbar.h
@@ -70,6 +70,10 @@ nserror nsgtk_toolbar_throbber(struct nsgtk_toolbar *tb, bool active);
*/
nserror nsgtk_toolbar_set_url(struct nsgtk_toolbar *tb, nsurl *url);
+/**
+ * set the websearch image
+ */
+nserror nsgtk_toolbar_set_websearch_image(struct nsgtk_toolbar *tb, GdkPixbuf *pixbuf);
/**
* activate the handler for a toolbar item
diff --git a/frontends/gtk/window.c b/frontends/gtk/window.c
index 666e6ea60..b43a0ec42 100644
--- a/frontends/gtk/window.c
+++ b/frontends/gtk/window.c
@@ -655,7 +655,8 @@ static gboolean nsgtk_window_size_allocate_event(GtkWidget *widget,
}
-/** when the pane position is changed update the user option
+/**
+ * when the pane position is changed update the user option
*
* The slightly awkward implementation with the first allocation flag
* is necessary because the initial window creation does not cause an
@@ -794,6 +795,7 @@ gui_window_create(struct browser_window *bw,
return NULL;
}
+
/* set a default favicon */
g_object_ref(favicon_pixbuf);
g->icon = favicon_pixbuf;
@@ -1196,8 +1198,10 @@ static void gui_window_set_pointer(struct gui_window *g,
}
-static void gui_window_place_caret(struct gui_window *g, int x, int y, int height,
- const struct rect *clip)
+static void
+gui_window_place_caret(struct gui_window *g,
+ int x, int y, int height,
+ const struct rect *clip)
{
nsgtk_redraw_caret(g);
@@ -1302,6 +1306,12 @@ static void gui_window_create_form_select_menu(struct gui_window *g,
nsgtk_menu_popup_at_pointer(GTK_MENU(select_menu), NULL);
}
+
+/**
+ * GTK window UI callback when core needs a file selection gadget
+ *
+ * \param g The gui window on which the gadget has been requested
+ */
static void
gui_window_file_gadget_open(struct gui_window *g,
struct hlcache_handle *hl,
@@ -1336,7 +1346,7 @@ gui_window_file_gadget_open(struct gui_window *g,
/**
- * process miscellaneous window events
+ * GTK window UI callback to process miscellaneous events
*
* \param gw The window receiving the event.
* \param event The event code.
@@ -1374,11 +1384,56 @@ gui_window_event(struct gui_window *gw, enum gui_window_event event)
return NSERROR_OK;
}
+
+/**
+ * GTK window UI callback when core changes the current url
+ *
+ * \param gw The gui window on which the url has been set.
+ * \param url The new url.
+ */
static nserror gui_window_set_url(struct gui_window *gw, nsurl *url)
{
return nsgtk_toolbar_set_url(gw->toolbar, url);
}
+
+/**
+ * GTK UI callback when search provider details are updated.
+ *
+ * \param name The providers name.
+ * \param bitmap The bitmap representing the provider.
+ * \return NSERROR_OK on success else error code.
+ */
+static nserror
+gui_search_web_provider_update(const char *name, struct bitmap *bitmap)
+{
+ struct gui_window *gw;
+ GdkPixbuf *pixbuf = NULL;
+
+ if (bitmap != NULL) {
+ pixbuf = nsgdk_pixbuf_get_from_surface(bitmap->surface, 16, 16);
+ }
+
+ for (gw = window_list; gw != NULL; gw = gw->next) {
+ nsgtk_toolbar_set_websearch_image(gw->toolbar, pixbuf);
+ }
+
+ return NSERROR_OK;
+}
+
+/**
+ * GTK frontend web search operation table
+ */
+static struct gui_search_web_table search_web_table = {
+ .provider_update = gui_search_web_provider_update,
+};
+
+struct gui_search_web_table *nsgtk_search_web_table = &search_web_table;
+
+
+/**
+ * GTK frontend browser window operation table
+ */
static struct gui_window_table window_table = {
.create = gui_window_create,
.destroy = gui_window_destroy,
@@ -1394,10 +1449,10 @@ static struct gui_window_table window_table = {
.place_caret = gui_window_place_caret,
.create_form_select_menu = gui_window_create_form_select_menu,
.file_gadget_open = gui_window_file_gadget_open,
+ .set_url = gui_window_set_url,
/* from scaffold */
.set_title = nsgtk_window_set_title,
- .set_url = gui_window_set_url,
};
struct gui_window_table *nsgtk_window_table = &window_table;
diff --git a/frontends/gtk/window.h b/frontends/gtk/window.h
index a991f0337..dd49c719f 100644
--- a/frontends/gtk/window.h
+++ b/frontends/gtk/window.h
@@ -20,6 +20,7 @@
#define NETSURF_GTK_WINDOW_H 1
extern struct gui_window_table *nsgtk_window_table;
+extern struct gui_search_web_table *nsgtk_search_web_table;
typedef enum nsgtk_window_signals {
NSGTK_WINDOW_SIGNAL_CLICK,