mirror of
https://github.com/netsurf-browser/netsurf
synced 2024-12-22 04:02:34 +03:00
make web search icon setting work properly
This commit is contained in:
parent
e84990bc89
commit
2e8861dc05
@ -365,6 +365,33 @@ search_web_omni(const char *term,
|
||||
return NSERROR_OK;
|
||||
}
|
||||
|
||||
/* 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)
|
||||
{
|
||||
@ -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) {
|
||||
|
@ -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.
|
||||
*
|
||||
|
@ -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);
|
||||
|
@ -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)
|
||||
{
|
||||
@ -1617,12 +1488,6 @@ GtkWidget *nsgtk_scaffolding_urlbar(struct nsgtk_scaffolding *g)
|
||||
return NULL;//g->url_bar;
|
||||
}
|
||||
|
||||
/* 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)
|
||||
{
|
||||
@ -1657,15 +1522,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)
|
||||
{
|
||||
@ -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));
|
||||
|
||||
|
@ -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 {
|
||||
@ -97,11 +96,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.
|
||||
*/
|
||||
@ -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);
|
||||
|
||||
/**
|
||||
|
@ -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);
|
||||
}
|
||||
@ -3627,6 +3645,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,
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user