From 65d169da106d159d9fb53ceb55a5b5899cc0762f Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Sun, 18 Aug 2019 10:21:44 +0100 Subject: [PATCH] get the code to at least compile again. toolbar is completely broken --- frontends/gtk/scaffolding.c | 384 ++++++------ frontends/gtk/toolbar.c | 1033 +++++++++++++++++---------------- frontends/gtk/toolbar_items.h | 10 + 3 files changed, 742 insertions(+), 685 deletions(-) diff --git a/frontends/gtk/scaffolding.c b/frontends/gtk/scaffolding.c index c739b3e9c..f142d106e 100644 --- a/frontends/gtk/scaffolding.c +++ b/frontends/gtk/scaffolding.c @@ -312,12 +312,12 @@ scaffolding_window_delete_event(GtkWidget *widget, static void scaffolding_update_context(struct nsgtk_scaffolding *g) { struct browser_window *bw = nsgtk_get_browser_window(g->top_level); - +#if 0 g->buttons[BACK_BUTTON]->sensitivity = - browser_window_history_back_available(bw); - g->buttons[FORWARD_BUTTON]->sensitivity = - browser_window_history_forward_available(bw); - + browser_window_history_back_available(bw); + g->buttons[FORWARD_BUTTON]->sensitivity = + browser_window_history_forward_available(bw); +#endif nsgtk_scaffolding_set_sensitivity(g); /* update the url bar, particularly necessary when tabbing */ @@ -336,6 +336,7 @@ static void scaffolding_update_context(struct nsgtk_scaffolding *g) */ static void nsgtk_throb(void *p) { +#if 0 nserror res; GdkPixbuf *pixbuf; struct nsgtk_scaffolding *g = p; @@ -352,6 +353,7 @@ static void nsgtk_throb(void *p) } nsgtk_schedule(100, nsgtk_throb, p); +#endif } @@ -364,6 +366,7 @@ static guint nsgtk_scaffolding_update_edit_actions_sensitivity( struct nsgtk_scaffolding *g) { +#if 0 GtkWidget *widget = gtk_window_get_focus(g->window); gboolean has_selection; @@ -392,6 +395,9 @@ nsgtk_scaffolding_update_edit_actions_sensitivity( return ((g->buttons[COPY_BUTTON]->sensitivity) | (g->buttons[CUT_BUTTON]->sensitivity) | (g->buttons[PASTE_BUTTON]->sensitivity)); +#else + return 0; +#endif } @@ -404,10 +410,11 @@ static void nsgtk_scaffolding_enable_edit_actions_sensitivity( struct nsgtk_scaffolding *g) { - +#if 0 g->buttons[PASTE_BUTTON]->sensitivity = true; g->buttons[COPY_BUTTON]->sensitivity = true; g->buttons[CUT_BUTTON]->sensitivity = true; +#endif nsgtk_scaffolding_set_sensitivity(g); popup_menu_show(g->menu_popup, false, false, true, false); @@ -464,6 +471,7 @@ static gboolean nsgtk_window_popup_menu_hidden(GtkWidget *widget, /* exported interface documented in gtk/scaffolding.h */ gboolean nsgtk_window_url_activate_event(GtkWidget *widget, gpointer data) { +#if 0 struct nsgtk_scaffolding *g = data; nserror ret; nsurl *url; @@ -480,7 +488,7 @@ gboolean nsgtk_window_url_activate_event(GtkWidget *widget, gpointer data) if (ret != NSERROR_OK) { nsgtk_warning(messages_get_errorcode(ret), 0); } - +#endif return TRUE; } @@ -550,9 +558,11 @@ nsgtk_window_tabs_add(GtkNotebook *notebook, "visible", visible, NULL); g_object_set(g->menu_popup->view_submenu->tabs_menuitem, "visible", visible, NULL); +#if 0 g->buttons[NEXTTAB_BUTTON]->sensitivity = visible; g->buttons[PREVTAB_BUTTON]->sensitivity = visible; g->buttons[CLOSETAB_BUTTON]->sensitivity = visible; +#endif nsgtk_scaffolding_set_sensitivity(g); } @@ -588,9 +598,11 @@ nsgtk_window_tabs_remove(GtkNotebook *notebook, gboolean visible = gtk_notebook_get_show_tabs(gs->notebook); g_object_set(gs->menu_bar->view_submenu->tabs_menuitem, "visible", visible, NULL); g_object_set(gs->menu_popup->view_submenu->tabs_menuitem, "visible", visible, NULL); +#if 0 gs->buttons[NEXTTAB_BUTTON]->sensitivity = visible; gs->buttons[PREVTAB_BUTTON]->sensitivity = visible; gs->buttons[CLOSETAB_BUTTON]->sensitivity = visible; +#endif nsgtk_scaffolding_set_sensitivity(gs); } @@ -1162,7 +1174,8 @@ MULTIHANDLER(cut) /* If the url bar has focus, let gtk handle it */ if (GTK_IS_EDITABLE (focused)) - gtk_editable_cut_clipboard (GTK_EDITABLE(g->url_bar)); + //gtk_editable_cut_clipboard (GTK_EDITABLE(g->url_bar)); + ; else browser_window_key_press(bw, NS_KEY_CUT_SELECTION); @@ -1176,7 +1189,8 @@ MULTIHANDLER(copy) /* If the url bar has focus, let gtk handle it */ if (GTK_IS_EDITABLE (focused)) - gtk_editable_copy_clipboard(GTK_EDITABLE(g->url_bar)); + //gtk_editable_copy_clipboard(GTK_EDITABLE(g->url_bar)); + ; else browser_window_key_press(bw, NS_KEY_COPY_SELECTION); @@ -1212,15 +1226,17 @@ MENUHANDLER(customize) MULTIHANDLER(selectall) { struct browser_window *bw = nsgtk_get_browser_window(g->top_level); - +#if 0 if (nsgtk_widget_has_focus(GTK_WIDGET(g->url_bar))) { NSLOG(netsurf, INFO, "Selecting all URL bar text"); gtk_editable_select_region(GTK_EDITABLE(g->url_bar), 0, -1); } else { +#endif NSLOG(netsurf, INFO, "Selecting all document text"); browser_window_key_press(bw, NS_KEY_SELECT_ALL); +#if 0 } - +#endif return TRUE; } @@ -1358,7 +1374,7 @@ MENUHANDLER(toolbar) == FALSE) gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(w), TRUE); - gtk_widget_show(GTK_WIDGET(g->tool_bar)); + //gtk_widget_show(GTK_WIDGET(g->tool_bar)); } else { w = GTK_WIDGET(g->menu_popup->view_submenu->toolbars_submenu->toolbar_menuitem); if (gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(w))) @@ -1368,7 +1384,7 @@ MENUHANDLER(toolbar) if (gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(w))) gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(w), FALSE); - gtk_widget_hide(GTK_WIDGET(g->tool_bar)); + //gtk_widget_hide(GTK_WIDGET(g->tool_bar)); } return TRUE; @@ -1630,7 +1646,9 @@ MULTIHANDLER(showcookies) MULTIHANDLER(openlocation) { + #if 0 gtk_widget_grab_focus(GTK_WIDGET(g->url_bar)); + #endif return TRUE; } @@ -1739,6 +1757,7 @@ BUTTONHANDLER(history) static void nsgtk_attach_menu_handlers(struct nsgtk_scaffolding *g) { + #if 0 for (int i = BACK_BUTTON; i < PLACEHOLDER_BUTTON; i++) { if (g->buttons[i]->main != NULL) { g_signal_connect(g->buttons[i]->main, "activate", @@ -1759,7 +1778,7 @@ static void nsgtk_attach_menu_handlers(struct nsgtk_scaffolding *g) CONNECT_CHECK(menubar); CONNECT_CHECK(toolbar); #undef CONNECT_CHECK - +#endif } /** @@ -1845,7 +1864,7 @@ struct nsgtk_scaffolding *nsgtk_current_scaffolding(void) } return scaf_current; } - +#if 0 /** * init the array g->buttons[] */ @@ -1937,6 +1956,7 @@ static void nsgtk_scaffolding_toolbar_init(struct nsgtk_scaffolding *g) } + static void nsgtk_scaffolding_initial_sensitivity(struct nsgtk_scaffolding *g) { for (int i = BACK_BUTTON; i < PLACEHOLDER_BUTTON; i++) { @@ -1960,7 +1980,7 @@ static void nsgtk_scaffolding_initial_sensitivity(struct nsgtk_scaffolding *g) } gtk_widget_set_sensitive(GTK_WIDGET(g->menu_bar->view_submenu->images_menuitem), FALSE); } - +#endif /** * update search toolbar size and style */ @@ -2023,7 +2043,7 @@ nsgtk_search_create(GtkBuilder *builder, struct gtk_search **search_out) search->caseSens = GTK_CHECK_BUTTON(gtk_builder_get_object( builder,"caseSensButton")); - nsgtk_search_update(search); + nsgtk_search_update(search); *search_out = search; return NSERROR_OK; @@ -2038,154 +2058,6 @@ void nsgtk_scaffolding_toolbars(struct nsgtk_scaffolding *g) } -/* exported interface documented in gtk/scaffolding.h */ -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)); - if (gs == NULL) { - return NULL; - } - - NSLOG(netsurf, INFO, - "Constructing a scaffold of %p for gui_window %p", gs, toplevel); - - gs->top_level = toplevel; - - /* Construct UI widgets */ - if (nsgtk_builder_new_from_resname("netsurf", &gs->builder) != NSERROR_OK) { - free(gs); - return NULL; - } - - gtk_builder_connect_signals(gs->builder, NULL); - - gs->window = GTK_WINDOW(gtk_builder_get_object(builder, "wndBrowser")); - gs->notebook = GTK_NOTEBOOK(gtk_builder_get_object(builder, "notebook")); - - res = nsgtk_toolbar_create(&gs->toolbar); - if (res != NSERROR_OK) { - free(gs); - return NULL; - } - - res = nsgtk_search_create(&gs->search); - if (res != NSERROR_OK) { - free(gs); - return NULL; - } - - group = gtk_accel_group_new(); - gtk_window_add_accel_group(gs->window, group); - - gs->menu_bar = nsgtk_menu_bar_create(GTK_MENU_SHELL(gtk_builder_get_object(gs->builder, "menubar")), group); - - /* set this window's size and position to what's in the options, or - * or some sensible default if they're not set yet. - */ - if (nsoption_int(window_width) > 0) { - gtk_window_move(gs->window, - nsoption_int(window_x), - nsoption_int(window_y)); - gtk_window_resize(gs->window, - nsoption_int(window_width), - nsoption_int(window_height)); - } else { - /* Set to 1000x700, so we're very likely to fit even on - * 1024x768 displays, not being able to take into account - * window furniture or panels. - */ - gtk_window_set_default_size(gs->window, 1000, 700); - } - - - nsgtk_tab_init(gs); - - - - - g_signal_connect_after(gs->notebook, "page-added", - G_CALLBACK(nsgtk_window_tabs_add), gs); - g_signal_connect_after(gs->notebook, "page-removed", - G_CALLBACK(nsgtk_window_tabs_remove), gs); - -#define CONNECT(obj, sig, callback, ptr) \ - g_signal_connect(G_OBJECT(obj), (sig), G_CALLBACK(callback), (ptr)) - - /* connect main window signals to their handlers. */ - CONNECT(gs->window, "delete-event", - scaffolding_window_delete_event, gs); - - CONNECT(gs->window, "destroy", scaffolding_window_destroy, gs); - - /* toolbar URL bar menu bar search bar signal handlers */ - CONNECT(gs->menu_bar->edit_submenu->edit, "show", - nsgtk_window_edit_menu_shown, gs); - CONNECT(gs->menu_bar->edit_submenu->edit, "hide", - nsgtk_window_edit_menu_hidden, gs); - - CONNECT(gs->search->buttons[1], "clicked", - nsgtk_search_forward_button_clicked, gs); - - CONNECT(gs->search->buttons[0], "clicked", - nsgtk_search_back_button_clicked, gs); - - CONNECT(gs->search->entry, "changed", nsgtk_search_entry_changed, gs); - - CONNECT(gs->search->entry, "activate", nsgtk_search_entry_activate, gs); - - CONNECT(gs->search->entry, "key-press-event", - nsgtk_search_entry_key, gs); - - CONNECT(gs->search->buttons[2], "clicked", - nsgtk_search_close_button_clicked, gs); - - CONNECT(gs->search->caseSens, "toggled", - nsgtk_search_entry_changed, gs); - - /** \todo fix popup menu */ - //CONNECT(gs->tool_bar, "popup-context-menu", - // nsgtk_window_tool_bar_clicked, gs); - - /* create popup menu */ - gs->menu_popup = nsgtk_new_scaffolding_popup(gs, group); - - gs->link_menu = nsgtk_new_scaffolding_link_popup(gs, group); - - /* set up the menu signal handlers */ - nsgtk_scaffolding_toolbar_init(gs); - nsgtk_toolbar_connect_all(gs); - nsgtk_attach_menu_handlers(gs); - - nsgtk_scaffolding_initial_sensitivity(gs); - - gs->fullscreen = false; - - /* attach to the list */ - if (scaf_list) { - scaf_list->prev = gs; - } - gs->next = scaf_list; - gs->prev = NULL; - scaf_list = gs; - - /* 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)); - - NSLOG(netsurf, INFO, "creation complete"); - - return gs; -} /* exported function documented in gtk/scaffolding.h */ void nsgtk_window_set_title(struct gui_window *gw, const char *title) @@ -2234,19 +2106,21 @@ nserror gui_window_set_url(struct gui_window *gw, nsurl *url) if (nsurl_get_utf8(url, &idn_url_s, &idn_url_l) != NSERROR_OK) idn_url_s = NULL; } - +#if 0 gtk_entry_set_text(GTK_ENTRY(g->url_bar), idn_url_s ? idn_url_s : nsurl_access(url)); +#endif if(idn_url_s) free(idn_url_s); - gtk_editable_set_position(GTK_EDITABLE(g->url_bar), -1); + //gtk_editable_set_position(GTK_EDITABLE(g->url_bar), -1); } return NSERROR_OK; } void gui_window_start_throbber(struct gui_window* _g) { +#if 0 struct nsgtk_scaffolding *g = nsgtk_get_scaffold(_g); g->buttons[STOP_BUTTON]->sensitivity = true; g->buttons[RELOAD_BUTTON]->sensitivity = false; @@ -2255,10 +2129,12 @@ void gui_window_start_throbber(struct gui_window* _g) scaffolding_update_context(g); nsgtk_schedule(100, nsgtk_throb, g); +#endif } void gui_window_stop_throbber(struct gui_window* _g) { +#if 0 nserror res; GdkPixbuf *pixbuf; struct nsgtk_scaffolding *g = nsgtk_get_scaffold(_g); @@ -2284,12 +2160,14 @@ void gui_window_stop_throbber(struct gui_window* _g) (g->throbber != NULL)) { gtk_image_set_from_pixbuf(g->throbber, pixbuf); } +#endif } 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. */ @@ -2339,6 +2217,7 @@ nsgtk_scaffolding_set_websearch(struct nsgtk_scaffolding *g, const char *content */ gtk_entry_set_visibility(GTK_ENTRY(g->webSearchEntry), TRUE); gtk_entry_set_text(GTK_ENTRY(g->webSearchEntry), content); +#endif } /** @@ -2372,7 +2251,7 @@ gui_search_web_provider_update(const char *provider_name, 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) { @@ -2397,7 +2276,7 @@ gui_search_web_provider_update(const char *provider_name, nsgtk_scaffolding_set_websearch(current, provider_name); } } - +#endif free(searchcontent); if (srch_pixbuf != NULL) { @@ -2428,19 +2307,19 @@ GtkNotebook* nsgtk_scaffolding_notebook(struct nsgtk_scaffolding *g) /* exported interface documented in gtk/scaffolding.h */ GtkWidget *nsgtk_scaffolding_urlbar(struct nsgtk_scaffolding *g) { - return g->url_bar; + return NULL;//g->url_bar; } /* exported interface documented in gtk/scaffolding.h */ GtkWidget *nsgtk_scaffolding_websearch(struct nsgtk_scaffolding *g) { - return g->webSearchEntry; + return NULL;//g->webSearchEntry; } /* exported interface documented in gtk/scaffolding.h */ GtkToolbar *nsgtk_scaffolding_toolbar(struct nsgtk_scaffolding *g) { - return g->tool_bar; + return NULL;//g->tool_bar; } /* exported interface documented in gtk/scaffolding.h */ @@ -2467,22 +2346,26 @@ struct nsgtk_scaffolding *nsgtk_scaffolding_iterate(struct nsgtk_scaffolding *g) /* exported interface documented in gtk/scaffolding.h */ void nsgtk_scaffolding_reset_offset(struct nsgtk_scaffolding *g) { - g->offset = 0; + //g->offset = 0; } /* exported interface documented in gtk/scaffolding.h */ void nsgtk_scaffolding_update_throbber_ref(struct nsgtk_scaffolding *g) { +#if 0 g->throbber = GTK_IMAGE(gtk_bin_get_child( GTK_BIN(g->buttons[THROBBER_ITEM]->button))); +#endif } /* 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 */ @@ -2541,6 +2424,7 @@ void nsgtk_scaffolding_set_top_level(struct gui_window *gw) /* exported interface documented in scaffolding.h */ void nsgtk_scaffolding_set_sensitivity(struct nsgtk_scaffolding *g) { +#if 0 int i; #define SENSITIVITY(q)\ i = q##_BUTTON;\ @@ -2573,6 +2457,7 @@ void nsgtk_scaffolding_set_sensitivity(struct nsgtk_scaffolding *g) SENSITIVITY(PREVTAB) SENSITIVITY(CLOSETAB) #undef SENSITIVITY +#endif } @@ -2596,7 +2481,7 @@ void nsgtk_scaffolding_context_menu(struct nsgtk_scaffolding *g, gtkmenu = g->menu_popup->popup_menu; nsgtk_scaffolding_update_edit_actions_sensitivity(g); - +#if 0 if (!(g->buttons[COPY_BUTTON]->sensitivity)) { gtk_widget_hide(GTK_WIDGET(g->menu_popup->copy_menuitem)); } else { @@ -2614,7 +2499,7 @@ void nsgtk_scaffolding_context_menu(struct nsgtk_scaffolding *g, } else { gtk_widget_show(GTK_WIDGET(g->menu_popup->paste_menuitem)); } - +#endif /* hide customise */ popup_menu_hide(g->menu_popup, false, false, false, true); } @@ -2629,6 +2514,7 @@ void nsgtk_scaffolding_context_menu(struct nsgtk_scaffolding *g, void nsgtk_scaffolding_toolbar_size_allocate(GtkWidget *widget, GtkAllocation *alloc, gpointer data) { + #if 0 struct nsgtk_scaffolding *g = (struct nsgtk_scaffolding *)data; int i = nsgtk_toolbar_get_id_from_widget(widget, g); if (i == -1) @@ -2654,4 +2540,152 @@ void nsgtk_scaffolding_toolbar_size_allocate(GtkWidget *widget, } g->toolbarmem = alloc->x; gtk_widget_size_allocate(widget, alloc); + #endif +} + + +/* exported interface documented in gtk/scaffolding.h */ +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)); + if (gs == NULL) { + return NULL; + } + + NSLOG(netsurf, INFO, + "Constructing a scaffold of %p for gui_window %p", gs, toplevel); + + gs->top_level = toplevel; + + /* Construct UI widgets */ + if (nsgtk_builder_new_from_resname("netsurf", &gs->builder) != NSERROR_OK) { + free(gs); + return NULL; + } + + gtk_builder_connect_signals(gs->builder, NULL); + + gs->window = GTK_WINDOW(gtk_builder_get_object(gs->builder, "wndBrowser")); + gs->notebook = GTK_NOTEBOOK(gtk_builder_get_object(gs->builder, "notebook")); + + res = nsgtk_toolbar_create(gs->builder, &gs->toolbar); + if (res != NSERROR_OK) { + free(gs); + return NULL; + } + + res = nsgtk_search_create(gs->builder, &gs->search); + if (res != NSERROR_OK) { + free(gs); + return NULL; + } + + group = gtk_accel_group_new(); + gtk_window_add_accel_group(gs->window, group); + + gs->menu_bar = nsgtk_menu_bar_create(GTK_MENU_SHELL(gtk_builder_get_object(gs->builder, "menubar")), group); + + /* set this window's size and position to what's in the options, or + * or some sensible default if they're not set yet. + */ + if (nsoption_int(window_width) > 0) { + gtk_window_move(gs->window, + nsoption_int(window_x), + nsoption_int(window_y)); + gtk_window_resize(gs->window, + nsoption_int(window_width), + nsoption_int(window_height)); + } else { + /* Set to 1000x700, so we're very likely to fit even on + * 1024x768 displays, not being able to take into account + * window furniture or panels. + */ + gtk_window_set_default_size(gs->window, 1000, 700); + } + + + nsgtk_tab_init(gs); + + g_signal_connect_after(gs->notebook, "page-added", + G_CALLBACK(nsgtk_window_tabs_add), gs); + g_signal_connect_after(gs->notebook, "page-removed", + G_CALLBACK(nsgtk_window_tabs_remove), gs); + +#define CONNECT(obj, sig, callback, ptr) \ + g_signal_connect(G_OBJECT(obj), (sig), G_CALLBACK(callback), (ptr)) + + /* connect main window signals to their handlers. */ + CONNECT(gs->window, "delete-event", + scaffolding_window_delete_event, gs); + + CONNECT(gs->window, "destroy", scaffolding_window_destroy, gs); + + /* toolbar URL bar menu bar search bar signal handlers */ + CONNECT(gs->menu_bar->edit_submenu->edit, "show", + nsgtk_window_edit_menu_shown, gs); + CONNECT(gs->menu_bar->edit_submenu->edit, "hide", + nsgtk_window_edit_menu_hidden, gs); + + CONNECT(gs->search->buttons[1], "clicked", + nsgtk_search_forward_button_clicked, gs); + + CONNECT(gs->search->buttons[0], "clicked", + nsgtk_search_back_button_clicked, gs); + + CONNECT(gs->search->entry, "changed", nsgtk_search_entry_changed, gs); + + CONNECT(gs->search->entry, "activate", nsgtk_search_entry_activate, gs); + + CONNECT(gs->search->entry, "key-press-event", + nsgtk_search_entry_key, gs); + + CONNECT(gs->search->buttons[2], "clicked", + nsgtk_search_close_button_clicked, gs); + + CONNECT(gs->search->caseSens, "toggled", + nsgtk_search_entry_changed, gs); + + /** \todo fix popup menu */ + //CONNECT(gs->tool_bar, "popup-context-menu", + // nsgtk_window_tool_bar_clicked, gs); + + /* create popup menu */ + gs->menu_popup = nsgtk_new_scaffolding_popup(gs, group); + + gs->link_menu = nsgtk_new_scaffolding_link_popup(gs, group); + + /* set up the menu signal handlers */ + //nsgtk_scaffolding_toolbar_init(gs); + //nsgtk_toolbar_connect_all(gs); + nsgtk_attach_menu_handlers(gs); + + //nsgtk_scaffolding_initial_sensitivity(gs); + + gs->fullscreen = false; + + /* attach to the list */ + if (scaf_list) { + scaf_list->prev = gs; + } + gs->next = scaf_list; + gs->prev = NULL; + scaf_list = gs; + + /* 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)); + + NSLOG(netsurf, INFO, "creation complete"); + + return gs; } diff --git a/frontends/gtk/toolbar.c b/frontends/gtk/toolbar.c index 02b1e66d4..724e3735d 100644 --- a/frontends/gtk/toolbar.c +++ b/frontends/gtk/toolbar.c @@ -187,490 +187,6 @@ nsgtk_toolbar_##name##_data_minus(GtkWidget *widget, \ #undef TOOLBAR_ITEM -/** - * Apply the user toolbar button settings from configuration - * - * GTK specific user option string is a set of fields arranged as - * [itemreference];[itemlocation]|[itemreference];[itemlocation]| etc - * - * \param tb The toolbar to apply customization to - * \param NSERROR_OK on success else error code. - */ -static nserror -apply_user_button_customization(struct nsgtk_toolbar *tb) -{ - int i, ii; - char *buffer; - char *buffer1, *subbuffer, *ptr = NULL, *pter = NULL; - - /* set all button locations to inactive */ - for (i = BACK_BUTTON; i < PLACEHOLDER_BUTTON; i++) { - tb->buttons[i]->location = INACTIVE_LOCATION; - } - - /* if no user config is present apply the defaults */ - if (nsoption_charp(toolbar_order) == NULL) { - tb->buttons[BACK_BUTTON]->location = 0; - tb->buttons[HISTORY_BUTTON]->location = 1; - tb->buttons[FORWARD_BUTTON]->location = 2; - tb->buttons[STOP_BUTTON]->location = 3; - tb->buttons[RELOAD_BUTTON]->location = 4; - tb->buttons[URL_BAR_ITEM]->location = 5; - tb->buttons[WEBSEARCH_ITEM]->location = 6; - tb->buttons[THROBBER_ITEM]->location = 7; - - return NSERROR_OK; - } - - buffer = strdup(nsoption_charp(toolbar_order)); - if (buffer == NULL) { - return NSERROR_NOMEM; - } - - i = BACK_BUTTON; - ii = BACK_BUTTON; - buffer1 = strtok_r(buffer, "|", &ptr); - while (buffer1 != NULL) { - subbuffer = strtok_r(buffer1, ";", &pter); - if (subbuffer != NULL) { - i = atoi(subbuffer); - subbuffer = strtok_r(NULL, ";", &pter); - if (subbuffer != NULL) { - ii = atoi(subbuffer); - if ((i >= BACK_BUTTON) && - (i < PLACEHOLDER_BUTTON) && - (ii >= -1) && - (ii < PLACEHOLDER_BUTTON)) { - tb->buttons[i]->location = ii; - } - } - } - buffer1 = strtok_r(NULL, "|", &ptr); - } - - free(buffer); - return NSERROR_OK; -} - - -/** - * widget factory for creation of toolbar item widgets - * - * \param i the id of the widget - * \param theme the theme to make the widgets from - * \return gtk widget - */ -static GtkWidget * -make_toolbar_item(nsgtk_toolbar_button i, struct nsgtk_theme *theme) -{ - GtkWidget *w = NULL; - - switch(i) { - -/* gtk_tool_button_new() accepts NULL args */ -#define MAKE_STOCKBUTTON(p, q) \ - case p##_BUTTON: { \ - GtkStockItem item; \ - char *label = NULL; \ - if (nsgtk_stock_lookup(q, &item) && \ - (item.label != NULL) && \ - ((label = remove_underscores(item.label, false)) != NULL)) { \ - w = GTK_WIDGET(gtk_tool_button_new(GTK_WIDGET( \ - theme->image[p##_BUTTON]), label)); \ - free(label); \ - } else { \ - w = GTK_WIDGET(gtk_tool_button_new(GTK_WIDGET( \ - theme->image[p##_BUTTON]), q)); \ - } \ - break; \ - } - - MAKE_STOCKBUTTON(HOME, NSGTK_STOCK_HOME) - MAKE_STOCKBUTTON(BACK, NSGTK_STOCK_GO_BACK) - MAKE_STOCKBUTTON(FORWARD, NSGTK_STOCK_GO_FORWARD) - MAKE_STOCKBUTTON(STOP, NSGTK_STOCK_STOP) - MAKE_STOCKBUTTON(RELOAD, NSGTK_STOCK_REFRESH) -#undef MAKE_STOCKBUTTON - - case HISTORY_BUTTON: - w = GTK_WIDGET(gtk_tool_button_new(GTK_WIDGET( - theme->image[HISTORY_BUTTON]), "H")); - break; - - case URL_BAR_ITEM: { - GtkWidget *entry = nsgtk_entry_new(); - w = GTK_WIDGET(gtk_tool_item_new()); - - if ((entry == NULL) || (w == NULL)) { - nsgtk_warning(messages_get("NoMemory"), 0); - return NULL; - } - - gtk_container_add(GTK_CONTAINER(w), entry); - gtk_tool_item_set_expand(GTK_TOOL_ITEM(w), TRUE); - break; - } - - case THROBBER_ITEM: { - nserror res; - GdkPixbuf *pixbuf; - res = nsgtk_throbber_get_frame(0, &pixbuf); - if (res != NSERROR_OK) { - return NULL; - } - - if (edit_mode) { - w = GTK_WIDGET(gtk_tool_button_new( - GTK_WIDGET(gtk_image_new_from_pixbuf(pixbuf)), - "[throbber]")); - } else { - GtkWidget *image; - - w = GTK_WIDGET(gtk_tool_item_new()); - - image = gtk_image_new_from_pixbuf(pixbuf); - if (image != NULL) { - nsgtk_widget_set_alignment(image, - GTK_ALIGN_CENTER, - GTK_ALIGN_CENTER); - nsgtk_widget_set_margins(image, 3, 0); - - gtk_container_add(GTK_CONTAINER(w), image); - } - } - break; - } - - case WEBSEARCH_ITEM: { - if (edit_mode) - return GTK_WIDGET(gtk_tool_button_new(GTK_WIDGET( - nsgtk_image_new_from_stock(NSGTK_STOCK_FIND, - GTK_ICON_SIZE_LARGE_TOOLBAR)), - "[websearch]")); - - GtkWidget *entry = nsgtk_entry_new(); - - w = GTK_WIDGET(gtk_tool_item_new()); - - if ((entry == NULL) || (w == NULL)) { - nsgtk_warning(messages_get("NoMemory"), 0); - return NULL; - } - - gtk_widget_set_size_request(entry, NSGTK_WEBSEARCH_WIDTH, -1); - - nsgtk_entry_set_icon_from_stock(entry, GTK_ENTRY_ICON_PRIMARY, - NSGTK_STOCK_INFO); - - gtk_container_add(GTK_CONTAINER(w), entry); - break; - } - -/* gtk_tool_button_new accepts NULL args */ -#define MAKE_MENUBUTTON(p, q) \ - case p##_BUTTON: { \ - char *label = NULL; \ - label = remove_underscores(messages_get(#q), false); \ - w = GTK_WIDGET(gtk_tool_button_new(GTK_WIDGET( \ - theme->image[p##_BUTTON]), label)); \ - if (label != NULL) \ - free(label); \ - break; \ - } - - MAKE_MENUBUTTON(NEWWINDOW, gtkNewWindow) - MAKE_MENUBUTTON(NEWTAB, gtkNewTab) - MAKE_MENUBUTTON(OPENFILE, gtkOpenFile) - MAKE_MENUBUTTON(CLOSETAB, gtkCloseTab) - MAKE_MENUBUTTON(CLOSEWINDOW, gtkCloseWindow) - MAKE_MENUBUTTON(SAVEPAGE, gtkSavePage) - MAKE_MENUBUTTON(PRINTPREVIEW, gtkPrintPreview) - MAKE_MENUBUTTON(PRINT, gtkPrint) - MAKE_MENUBUTTON(QUIT, gtkQuitMenu) - MAKE_MENUBUTTON(CUT, gtkCut) - MAKE_MENUBUTTON(COPY, gtkCopy) - MAKE_MENUBUTTON(PASTE, gtkPaste) - MAKE_MENUBUTTON(DELETE, gtkDelete) - MAKE_MENUBUTTON(SELECTALL, gtkSelectAll) - MAKE_MENUBUTTON(PREFERENCES, gtkPreferences) - MAKE_MENUBUTTON(ZOOMPLUS, gtkZoomPlus) - MAKE_MENUBUTTON(ZOOMMINUS, gtkZoomMinus) - MAKE_MENUBUTTON(ZOOMNORMAL, gtkZoomNormal) - MAKE_MENUBUTTON(FULLSCREEN, gtkFullScreen) - MAKE_MENUBUTTON(VIEWSOURCE, gtkViewSource) - MAKE_MENUBUTTON(CONTENTS, gtkContents) - MAKE_MENUBUTTON(ABOUT, gtkAbout) - MAKE_MENUBUTTON(PDF, gtkPDF) - MAKE_MENUBUTTON(PLAINTEXT, gtkPlainText) - MAKE_MENUBUTTON(DRAWFILE, gtkDrawFile) - MAKE_MENUBUTTON(POSTSCRIPT, gtkPostScript) - MAKE_MENUBUTTON(FIND, gtkFind) - MAKE_MENUBUTTON(DOWNLOADS, gtkDownloads) - MAKE_MENUBUTTON(SAVEWINDOWSIZE, gtkSaveWindowSize) - MAKE_MENUBUTTON(TOGGLEDEBUGGING, gtkToggleDebugging) - MAKE_MENUBUTTON(SAVEBOXTREE, gtkDebugBoxTree) - MAKE_MENUBUTTON(SAVEDOMTREE, gtkDebugDomTree) - MAKE_MENUBUTTON(LOCALHISTORY, gtkLocalHistory) - MAKE_MENUBUTTON(GLOBALHISTORY, gtkGlobalHistory) - MAKE_MENUBUTTON(ADDBOOKMARKS, gtkAddBookMarks) - MAKE_MENUBUTTON(SHOWBOOKMARKS, gtkShowBookMarks) - MAKE_MENUBUTTON(SHOWCOOKIES, gtkShowCookies) - MAKE_MENUBUTTON(OPENLOCATION, gtkOpenLocation) - MAKE_MENUBUTTON(NEXTTAB, gtkNextTab) - MAKE_MENUBUTTON(PREVTAB, gtkPrevTab) - MAKE_MENUBUTTON(GUIDE, gtkGuide) - MAKE_MENUBUTTON(INFO, gtkUserInformation) -#undef MAKE_MENUBUTTON - - default: - break; - - } - return w; -} - - -/** - * append item to gtk toolbar container - * - * \param tb toolbar - * \param theme in use - * \param location item location being appended - * \return NSERROR_OK on success else error code. - */ -static nserror -append_item_to_toolbar(struct nsgtk_toolbar *tb, - struct nsgtk_theme *theme, - int location) -{ - int bidx; /* button index */ - - for (bidx = BACK_BUTTON; bidx < PLACEHOLDER_BUTTON; bidx++) { - - if (tb->buttons[bidx]->location == location) { - - tb->buttons[bidx]->button = GTK_TOOL_ITEM( - make_toolbar_item(bidx, theme)); - - gtk_toolbar_insert(tb->widget, - tb->buttons[bidx]->button, - location); - break; - } - } - return NSERROR_OK; -} - - -/** - * callback function to remove a widget from a container - */ -static void container_remove_widget(GtkWidget *widget, gpointer data) -{ - GtkContainer *container = GTK_CONTAINER(data); - gtk_container_remove(container, widget); -} - - -/** - * populates the gtk toolbar container with widgets in correct order - */ -static nserror populate_gtk_toolbar_widget(struct nsgtk_toolbar *tb) -{ - struct nsgtk_theme *theme; /* internal theme context */ - int lidx; /* location index */ - - theme = nsgtk_theme_load(GTK_ICON_SIZE_LARGE_TOOLBAR, false); - if (theme == NULL) { - return NSERROR_NOMEM; - } - - /* clear the toolbar container of all widgets */ - gtk_container_foreach(GTK_CONTAINER(tb->widget), - container_remove_widget, - tb->widget); - - /* add widgets to toolbar */ - for (lidx = 0; lidx < PLACEHOLDER_BUTTON; lidx++) { - add_item_to_toolbar(tb, theme, lidx); - } - - gtk_widget_show_all(GTK_WIDGET(tb->widget)); - free(theme); - - return NSERROR_OK; -} - -/** - * create a toolbar item - * - * create a toolbar item and set up its default handlers - */ -static nserror -toolbar_item_create(nsgtk_toolbar_button id, - struct nsgtk_toolbar_item **item_out) -{ - struct nsgtk_toolbar_item *item; - item = calloc(1, sizeof(struct nsgtk_toolbar_item)); - if (item == NULL) { - return NSERROR_NOMEM; - } - item->location = INACTIVE_LOCATION; - - switch (id) { -#define TOOLBAR_ITEM(identifier, name, snstvty) \ - case identifier: \ - item->sensitivity = snstvty; \ - item->dataplus = nsgtk_toolbar_##name##_data_plus; \ - item->dataminus = nsgtk_toolbar_##name##_data_minus; \ - break; -#include "gtk/toolbar_items.h" -#undef TOOLBAR_ITEM - } - - *item_out = item; - return NSERROR_OK; -} - -/* exported interface documented in toolbar.h */ -nserror nsgtk_toolbar_create(GtkBuilder *builder, struct nsgtk_toolbar **tb_out) -{ - nserror res; - struct nsgtk_toolbar *tb; - int bidx; /* button index */ - - tb = calloc(1, sizeof(struct nsgtk_toolbar)); - if (tb == NULL) { - return NSERROR_NOMEM; - } - - tb->widget = GTK_TOOLBAR(gtk_builder_get_object(builder, "toolbar")); - - /* allocate button contexts */ - for (bidx = BACK_BUTTON; bidx < PLACEHOLDER_BUTTON; bidx++) { - res = toolbar_item_create(bidx, &tb->buttons[bidx]); - if (res != NSERROR_OK) { - for (bidx-- ; bidx >= BACK_BUTTON; bidx--) { - free(tb->buttons[bidx]); - } - free(tb); - return res; - } - } - - res = apply_user_button_customization(tb); - if (res != NSERROR_OK) { - free(tb); - return res; - } - - res = populate_gtk_toolbar_widget(tb); - if (res != NSERROR_OK) { - free(tb); - return res; - } - - res = nsgtk_toolbar_update(tb); - if (res != NSERROR_OK) { - free(tb); - return res; - } - - gtk_toolbar_set_show_arrow(tb->widget, TRUE); - gtk_widget_show_all(GTK_WIDGET(tb->widget)); - - /* if there is a history widget set its size */ - if (tb->buttons[HISTORY_BUTTON]->button != NULL) { - gtk_widget_set_size_request(GTK_WIDGET( - tb->buttons[HISTORY_BUTTON]->button), 20, -1); - } - - /* set up the throbber. */ - tb->throb_frame = 0; - - /* set up URL bar completion */ - tb->url_bar_completion = nsgtk_url_entry_completion_new(gs); - - *tb_out = tb; - return NSERROR_OK; -} - - -/* exported interface documented in toolbar.h */ -nserror nsgtk_toolbar_destroy(struct nsgtk_toolbar *tb) -{ - /** \todo free buttons and destroy toolbar container (and widgets) */ - free(tb); - return NSERROR_OK; -} - -/* exported interface documented in toolbar.h */ -nserror nsgtk_toolbar_update(struct nsgtk_toolbar *tb) -{ - switch (nsoption_int(button_type)) { - - case 1: /* Small icons */ - gtk_toolbar_set_style(GTK_TOOLBAR(tb->widget), - GTK_TOOLBAR_ICONS); - gtk_toolbar_set_icon_size(GTK_TOOLBAR(tb->widget), - GTK_ICON_SIZE_SMALL_TOOLBAR); - break; - - case 2: /* Large icons */ - gtk_toolbar_set_style(GTK_TOOLBAR(g->tool_bar), - GTK_TOOLBAR_ICONS); - gtk_toolbar_set_icon_size(GTK_TOOLBAR(g->tool_bar), - GTK_ICON_SIZE_LARGE_TOOLBAR); - break; - - case 3: /* Large icons with text */ - gtk_toolbar_set_style(GTK_TOOLBAR(g->tool_bar), - GTK_TOOLBAR_BOTH); - gtk_toolbar_set_icon_size(GTK_TOOLBAR(g->tool_bar), - GTK_ICON_SIZE_LARGE_TOOLBAR); - break; - - case 4: /* Text icons only */ - gtk_toolbar_set_style(GTK_TOOLBAR(g->tool_bar), - GTK_TOOLBAR_TEXT); - break; - - default: - break; - } - - return NSERROR_OK; -} - - -/** - * returns a string without its underscores - * - * \param s The string to change. - * \param replacespace true to insert a space where there was an underscore - * \return The altered string - */ -static char *remove_underscores(const char *s, bool replacespace) -{ - size_t i, ii, len; - char *ret; - len = strlen(s); - ret = malloc(len + 1); - if (ret == NULL) { - return NULL; - } - for (i = 0, ii = 0; i < len; i++) { - if (s[i] != '_') { - ret[ii++] = s[i]; - } else if (replacespace) { - ret[ii++] = ' '; - } - } - ret[ii] = '\0'; - return ret; -} - - /** * get default image for buttons / menu items from gtk stock items. * @@ -820,7 +336,11 @@ static struct nsgtk_theme *nsgtk_theme_load(GtkIconSize iconsize, bool usedef) return theme; } - +static struct nsgtk_toolbar_item * +nsgtk_scaffolding_button(struct nsgtk_scaffolding *g, int i) +{ + return NULL; +} /* exported function documented in gtk/toolbar.h */ void nsgtk_theme_implement(struct nsgtk_scaffolding *g) @@ -969,6 +489,212 @@ nsgtk_toolbar_get_id_at_location(struct nsgtk_scaffolding *g, int i) } +/** + * returns a string without its underscores + * + * \param s The string to change. + * \param replacespace true to insert a space where there was an underscore + * \return The altered string + */ +static char *remove_underscores(const char *s, bool replacespace) +{ + size_t i, ii, len; + char *ret; + len = strlen(s); + ret = malloc(len + 1); + if (ret == NULL) { + return NULL; + } + for (i = 0, ii = 0; i < len; i++) { + if (s[i] != '_') { + ret[ii++] = s[i]; + } else if (replacespace) { + ret[ii++] = ' '; + } + } + ret[ii] = '\0'; + return ret; +} + + +/** + * widget factory for creation of toolbar item widgets + * + * \param i the id of the widget + * \param theme the theme to make the widgets from + * \return gtk widget + */ +static GtkWidget * +make_toolbar_item(nsgtk_toolbar_button i, struct nsgtk_theme *theme) +{ + GtkWidget *w = NULL; + + switch(i) { + +/* gtk_tool_button_new() accepts NULL args */ +#define MAKE_STOCKBUTTON(p, q) \ + case p##_BUTTON: { \ + GtkStockItem item; \ + char *label = NULL; \ + if (nsgtk_stock_lookup(q, &item) && \ + (item.label != NULL) && \ + ((label = remove_underscores(item.label, false)) != NULL)) { \ + w = GTK_WIDGET(gtk_tool_button_new(GTK_WIDGET( \ + theme->image[p##_BUTTON]), label)); \ + free(label); \ + } else { \ + w = GTK_WIDGET(gtk_tool_button_new(GTK_WIDGET( \ + theme->image[p##_BUTTON]), q)); \ + } \ + break; \ + } + + MAKE_STOCKBUTTON(HOME, NSGTK_STOCK_HOME) + MAKE_STOCKBUTTON(BACK, NSGTK_STOCK_GO_BACK) + MAKE_STOCKBUTTON(FORWARD, NSGTK_STOCK_GO_FORWARD) + MAKE_STOCKBUTTON(STOP, NSGTK_STOCK_STOP) + MAKE_STOCKBUTTON(RELOAD, NSGTK_STOCK_REFRESH) +#undef MAKE_STOCKBUTTON + + case HISTORY_BUTTON: + w = GTK_WIDGET(gtk_tool_button_new(GTK_WIDGET( + theme->image[HISTORY_BUTTON]), "H")); + break; + + case URL_BAR_ITEM: { + GtkWidget *entry = nsgtk_entry_new(); + w = GTK_WIDGET(gtk_tool_item_new()); + + if ((entry == NULL) || (w == NULL)) { + nsgtk_warning(messages_get("NoMemory"), 0); + return NULL; + } + + gtk_container_add(GTK_CONTAINER(w), entry); + gtk_tool_item_set_expand(GTK_TOOL_ITEM(w), TRUE); + break; + } + + case THROBBER_ITEM: { + nserror res; + GdkPixbuf *pixbuf; + + res = nsgtk_throbber_get_frame(0, &pixbuf); + if (res != NSERROR_OK) { + return NULL; + } + + if (edit_mode) { + w = GTK_WIDGET(gtk_tool_button_new( + GTK_WIDGET(gtk_image_new_from_pixbuf(pixbuf)), + "[throbber]")); + } else { + GtkWidget *image; + + w = GTK_WIDGET(gtk_tool_item_new()); + + image = gtk_image_new_from_pixbuf(pixbuf); + if (image != NULL) { + nsgtk_widget_set_alignment(image, + GTK_ALIGN_CENTER, + GTK_ALIGN_CENTER); + nsgtk_widget_set_margins(image, 3, 0); + + gtk_container_add(GTK_CONTAINER(w), image); + } + } + break; + } + + case WEBSEARCH_ITEM: { + if (edit_mode) + return GTK_WIDGET(gtk_tool_button_new(GTK_WIDGET( + nsgtk_image_new_from_stock(NSGTK_STOCK_FIND, + GTK_ICON_SIZE_LARGE_TOOLBAR)), + "[websearch]")); + + GtkWidget *entry = nsgtk_entry_new(); + + w = GTK_WIDGET(gtk_tool_item_new()); + + if ((entry == NULL) || (w == NULL)) { + nsgtk_warning(messages_get("NoMemory"), 0); + return NULL; + } + + gtk_widget_set_size_request(entry, NSGTK_WEBSEARCH_WIDTH, -1); + + nsgtk_entry_set_icon_from_stock(entry, GTK_ENTRY_ICON_PRIMARY, + NSGTK_STOCK_INFO); + + gtk_container_add(GTK_CONTAINER(w), entry); + break; + } + +/* gtk_tool_button_new accepts NULL args */ +#define MAKE_MENUBUTTON(p, q) \ + case p##_BUTTON: { \ + char *label = NULL; \ + label = remove_underscores(messages_get(#q), false); \ + w = GTK_WIDGET(gtk_tool_button_new(GTK_WIDGET( \ + theme->image[p##_BUTTON]), label)); \ + if (label != NULL) \ + free(label); \ + break; \ + } + + MAKE_MENUBUTTON(NEWWINDOW, gtkNewWindow) + MAKE_MENUBUTTON(NEWTAB, gtkNewTab) + MAKE_MENUBUTTON(OPENFILE, gtkOpenFile) + MAKE_MENUBUTTON(CLOSETAB, gtkCloseTab) + MAKE_MENUBUTTON(CLOSEWINDOW, gtkCloseWindow) + MAKE_MENUBUTTON(SAVEPAGE, gtkSavePage) + MAKE_MENUBUTTON(PRINTPREVIEW, gtkPrintPreview) + MAKE_MENUBUTTON(PRINT, gtkPrint) + MAKE_MENUBUTTON(QUIT, gtkQuitMenu) + MAKE_MENUBUTTON(CUT, gtkCut) + MAKE_MENUBUTTON(COPY, gtkCopy) + MAKE_MENUBUTTON(PASTE, gtkPaste) + MAKE_MENUBUTTON(DELETE, gtkDelete) + MAKE_MENUBUTTON(SELECTALL, gtkSelectAll) + MAKE_MENUBUTTON(PREFERENCES, gtkPreferences) + MAKE_MENUBUTTON(ZOOMPLUS, gtkZoomPlus) + MAKE_MENUBUTTON(ZOOMMINUS, gtkZoomMinus) + MAKE_MENUBUTTON(ZOOMNORMAL, gtkZoomNormal) + MAKE_MENUBUTTON(FULLSCREEN, gtkFullScreen) + MAKE_MENUBUTTON(VIEWSOURCE, gtkViewSource) + MAKE_MENUBUTTON(CONTENTS, gtkContents) + MAKE_MENUBUTTON(ABOUT, gtkAbout) + MAKE_MENUBUTTON(PDF, gtkPDF) + MAKE_MENUBUTTON(PLAINTEXT, gtkPlainText) + MAKE_MENUBUTTON(DRAWFILE, gtkDrawFile) + MAKE_MENUBUTTON(POSTSCRIPT, gtkPostScript) + MAKE_MENUBUTTON(FIND, gtkFind) + MAKE_MENUBUTTON(DOWNLOADS, gtkDownloads) + MAKE_MENUBUTTON(SAVEWINDOWSIZE, gtkSaveWindowSize) + MAKE_MENUBUTTON(TOGGLEDEBUGGING, gtkToggleDebugging) + MAKE_MENUBUTTON(SAVEBOXTREE, gtkDebugBoxTree) + MAKE_MENUBUTTON(SAVEDOMTREE, gtkDebugDomTree) + MAKE_MENUBUTTON(LOCALHISTORY, gtkLocalHistory) + MAKE_MENUBUTTON(GLOBALHISTORY, gtkGlobalHistory) + MAKE_MENUBUTTON(ADDBOOKMARKS, gtkAddBookMarks) + MAKE_MENUBUTTON(SHOWBOOKMARKS, gtkShowBookMarks) + MAKE_MENUBUTTON(SHOWCOOKIES, gtkShowCookies) + MAKE_MENUBUTTON(OPENLOCATION, gtkOpenLocation) + MAKE_MENUBUTTON(NEXTTAB, gtkNextTab) + MAKE_MENUBUTTON(PREVTAB, gtkPrevTab) + MAKE_MENUBUTTON(GUIDE, gtkGuide) + MAKE_MENUBUTTON(INFO, gtkUserInformation) +#undef MAKE_MENUBUTTON + + default: + break; + + } + return w; +} + + /** * called when a widget is dropped onto the toolbar */ @@ -1190,6 +916,33 @@ static void nsgtk_toolbar_close(struct nsgtk_scaffolding *g) search_web_select_provider(-1); } + +/** + * set toolbar logical -> physical; physically visible toolbar buttons are made + * to correspond to the logically stored schema in terms of location + * visibility etc + */ +static void nsgtk_toolbar_set_physical(struct nsgtk_scaffolding *g) +{ + int i; + struct nsgtk_theme *theme; + + theme = nsgtk_theme_load(GTK_ICON_SIZE_LARGE_TOOLBAR, false); + if (theme == NULL) { + nsgtk_warning(messages_get("NoMemory"), 0); + return; + } + /* simplest is to clear the toolbar then reload it from memory */ + gtk_container_foreach(GTK_CONTAINER(nsgtk_scaffolding_toolbar(g)), + nsgtk_toolbar_clear_toolbar, g); + for (i = BACK_BUTTON; i < PLACEHOLDER_BUTTON; i++) { + nsgtk_toolbar_add_item_to_toolbar(g, i, theme); + } + gtk_widget_show_all(GTK_WIDGET(nsgtk_scaffolding_toolbar(g))); + free(theme); +} + + /** * when cancel button is clicked */ @@ -1617,30 +1370,6 @@ void nsgtk_toolbar_customization_init(struct nsgtk_scaffolding *g) nsgtk_toolbar_window_open(g); } -/** - * set toolbar logical -> physical; physically visible toolbar buttons are made - * to correspond to the logically stored schema in terms of location - * visibility etc - */ -void nsgtk_toolbar_set_physical(struct nsgtk_scaffolding *g) -{ - int i; - struct nsgtk_theme *theme; - - theme = nsgtk_theme_load(GTK_ICON_SIZE_LARGE_TOOLBAR, false); - if (theme == NULL) { - nsgtk_warning(messages_get("NoMemory"), 0); - return; - } - /* simplest is to clear the toolbar then reload it from memory */ - gtk_container_foreach(GTK_CONTAINER(nsgtk_scaffolding_toolbar(g)), - nsgtk_toolbar_clear_toolbar, g); - for (i = BACK_BUTTON; i < PLACEHOLDER_BUTTON; i++) { - nsgtk_toolbar_add_item_to_toolbar(g, i, theme); - } - gtk_widget_show_all(GTK_WIDGET(nsgtk_scaffolding_toolbar(g))); - free(theme); -} /** * \return toolbar item id when a widget is an element of the scaffolding @@ -1661,13 +1390,15 @@ int nsgtk_toolbar_get_id_from_widget(GtkWidget *widget, } /* exported interface documented in gtk/scaffolding.h */ -void nsgtk_scaffolding_update_url_bar_ref(struct nsgtk_scaffolding *g) +static void nsgtk_scaffolding_update_url_bar_ref(struct nsgtk_scaffolding *g) { + #if 0 g->url_bar = GTK_WIDGET(gtk_bin_get_child(GTK_BIN( g->buttons[URL_BAR_ITEM]->button))); gtk_entry_set_completion(GTK_ENTRY(g->url_bar), g->url_bar_completion); + #endif } /** @@ -1737,3 +1468,285 @@ void nsgtk_toolbar_connect_all(struct nsgtk_scaffolding *g) } +/** + * Apply the user toolbar button settings from configuration + * + * GTK specific user option string is a set of fields arranged as + * [itemreference];[itemlocation]|[itemreference];[itemlocation]| etc + * + * \param tb The toolbar to apply customization to + * \param NSERROR_OK on success else error code. + */ +static nserror +apply_user_button_customization(struct nsgtk_toolbar *tb) +{ + int i, ii; + char *buffer; + char *buffer1, *subbuffer, *ptr = NULL, *pter = NULL; + + /* set all button locations to inactive */ + for (i = BACK_BUTTON; i < PLACEHOLDER_BUTTON; i++) { + tb->buttons[i]->location = INACTIVE_LOCATION; + } + + /* if no user config is present apply the defaults */ + if (nsoption_charp(toolbar_order) == NULL) { + tb->buttons[BACK_BUTTON]->location = 0; + tb->buttons[HISTORY_BUTTON]->location = 1; + tb->buttons[FORWARD_BUTTON]->location = 2; + tb->buttons[STOP_BUTTON]->location = 3; + tb->buttons[RELOAD_BUTTON]->location = 4; + tb->buttons[URL_BAR_ITEM]->location = 5; + tb->buttons[WEBSEARCH_ITEM]->location = 6; + tb->buttons[THROBBER_ITEM]->location = 7; + + return NSERROR_OK; + } + + buffer = strdup(nsoption_charp(toolbar_order)); + if (buffer == NULL) { + return NSERROR_NOMEM; + } + + i = BACK_BUTTON; + ii = BACK_BUTTON; + buffer1 = strtok_r(buffer, "|", &ptr); + while (buffer1 != NULL) { + subbuffer = strtok_r(buffer1, ";", &pter); + if (subbuffer != NULL) { + i = atoi(subbuffer); + subbuffer = strtok_r(NULL, ";", &pter); + if (subbuffer != NULL) { + ii = atoi(subbuffer); + if ((i >= BACK_BUTTON) && + (i < PLACEHOLDER_BUTTON) && + (ii >= -1) && + (ii < PLACEHOLDER_BUTTON)) { + tb->buttons[i]->location = ii; + } + } + } + buffer1 = strtok_r(NULL, "|", &ptr); + } + + free(buffer); + return NSERROR_OK; +} + + +/** + * append item to gtk toolbar container + * + * \param tb toolbar + * \param theme in use + * \param location item location being appended + * \return NSERROR_OK on success else error code. + */ +static nserror +add_item_to_toolbar(struct nsgtk_toolbar *tb, + struct nsgtk_theme *theme, + int location) +{ + int bidx; /* button index */ + + for (bidx = BACK_BUTTON; bidx < PLACEHOLDER_BUTTON; bidx++) { + + if (tb->buttons[bidx]->location == location) { + + tb->buttons[bidx]->button = GTK_TOOL_ITEM( + make_toolbar_item(bidx, theme)); + + gtk_toolbar_insert(tb->widget, + tb->buttons[bidx]->button, + location); + break; + } + } + return NSERROR_OK; +} + + +/** + * callback function to remove a widget from a container + */ +static void container_remove_widget(GtkWidget *widget, gpointer data) +{ + GtkContainer *container = GTK_CONTAINER(data); + gtk_container_remove(container, widget); +} + + +/** + * populates the gtk toolbar container with widgets in correct order + */ +static nserror populate_gtk_toolbar_widget(struct nsgtk_toolbar *tb) +{ + struct nsgtk_theme *theme; /* internal theme context */ + int lidx; /* location index */ + + theme = nsgtk_theme_load(GTK_ICON_SIZE_LARGE_TOOLBAR, false); + if (theme == NULL) { + return NSERROR_NOMEM; + } + + /* clear the toolbar container of all widgets */ + gtk_container_foreach(GTK_CONTAINER(tb->widget), + container_remove_widget, + tb->widget); + + /* add widgets to toolbar */ + for (lidx = 0; lidx < PLACEHOLDER_BUTTON; lidx++) { + add_item_to_toolbar(tb, theme, lidx); + } + + gtk_widget_show_all(GTK_WIDGET(tb->widget)); + free(theme); + + return NSERROR_OK; +} + +/** + * create a toolbar item + * + * create a toolbar item and set up its default handlers + */ +static nserror +toolbar_item_create(nsgtk_toolbar_button id, + struct nsgtk_toolbar_item **item_out) +{ + struct nsgtk_toolbar_item *item; + item = calloc(1, sizeof(struct nsgtk_toolbar_item)); + if (item == NULL) { + return NSERROR_NOMEM; + } + item->location = INACTIVE_LOCATION; + + switch (id) { +#define TOOLBAR_ITEM(identifier, name, snstvty) \ + case identifier: \ + item->sensitivity = snstvty; \ + item->dataplus = nsgtk_toolbar_##name##_data_plus; \ + item->dataminus = nsgtk_toolbar_##name##_data_minus; \ + break; +#include "gtk/toolbar_items.h" +#undef TOOLBAR_ITEM + + case PLACEHOLDER_BUTTON: + free(item); + return NSERROR_INVALID; + } + + *item_out = item; + return NSERROR_OK; +} + +/* exported interface documented in toolbar.h */ +nserror nsgtk_toolbar_create(GtkBuilder *builder, struct nsgtk_toolbar **tb_out) +{ + nserror res; + struct nsgtk_toolbar *tb; + int bidx; /* button index */ + + tb = calloc(1, sizeof(struct nsgtk_toolbar)); + if (tb == NULL) { + return NSERROR_NOMEM; + } + + tb->widget = GTK_TOOLBAR(gtk_builder_get_object(builder, "toolbar")); + + /* allocate button contexts */ + for (bidx = BACK_BUTTON; bidx < PLACEHOLDER_BUTTON; bidx++) { + res = toolbar_item_create(bidx, &tb->buttons[bidx]); + if (res != NSERROR_OK) { + for (bidx-- ; bidx >= BACK_BUTTON; bidx--) { + free(tb->buttons[bidx]); + } + free(tb); + return res; + } + } + + res = apply_user_button_customization(tb); + if (res != NSERROR_OK) { + free(tb); + return res; + } + + res = populate_gtk_toolbar_widget(tb); + if (res != NSERROR_OK) { + free(tb); + return res; + } + + res = nsgtk_toolbar_update(tb); + if (res != NSERROR_OK) { + free(tb); + return res; + } + + gtk_toolbar_set_show_arrow(tb->widget, TRUE); + gtk_widget_show_all(GTK_WIDGET(tb->widget)); + + /* if there is a history widget set its size */ + if (tb->buttons[HISTORY_BUTTON]->button != NULL) { + gtk_widget_set_size_request(GTK_WIDGET( + tb->buttons[HISTORY_BUTTON]->button), 20, -1); + } + + /* set up the throbber. */ + tb->throb_frame = 0; + + /* set up URL bar completion */ + /** \todo sort out completion */ + //tb->url_bar_completion = nsgtk_url_entry_completion_new(gs); + + *tb_out = tb; + return NSERROR_OK; +} + + +/* exported interface documented in toolbar.h */ +nserror nsgtk_toolbar_destroy(struct nsgtk_toolbar *tb) +{ + /** \todo free buttons and destroy toolbar container (and widgets) */ + free(tb); + return NSERROR_OK; +} + +/* exported interface documented in toolbar.h */ +nserror nsgtk_toolbar_update(struct nsgtk_toolbar *tb) +{ + switch (nsoption_int(button_type)) { + + case 1: /* Small icons */ + gtk_toolbar_set_style(GTK_TOOLBAR(tb->widget), + GTK_TOOLBAR_ICONS); + gtk_toolbar_set_icon_size(GTK_TOOLBAR(tb->widget), + GTK_ICON_SIZE_SMALL_TOOLBAR); + break; + + case 2: /* Large icons */ + gtk_toolbar_set_style(GTK_TOOLBAR(tb->widget), + GTK_TOOLBAR_ICONS); + gtk_toolbar_set_icon_size(GTK_TOOLBAR(tb->widget), + GTK_ICON_SIZE_LARGE_TOOLBAR); + break; + + case 3: /* Large icons with text */ + gtk_toolbar_set_style(GTK_TOOLBAR(tb->widget), + GTK_TOOLBAR_BOTH); + gtk_toolbar_set_icon_size(GTK_TOOLBAR(tb->widget), + GTK_ICON_SIZE_LARGE_TOOLBAR); + break; + + case 4: /* Text icons only */ + gtk_toolbar_set_style(GTK_TOOLBAR(tb->widget), + GTK_TOOLBAR_TEXT); + break; + + default: + break; + } + + return NSERROR_OK; +} diff --git a/frontends/gtk/toolbar_items.h b/frontends/gtk/toolbar_items.h index fd01103d8..0e1eae4fa 100644 --- a/frontends/gtk/toolbar_items.h +++ b/frontends/gtk/toolbar_items.h @@ -83,6 +83,11 @@ typedef enum { * item initial visibility */ +#ifndef TOOLBAR_ITEM +#define TOOLBAR_ITEM(a, b, c) +#define TOOLBAR_ITEM_SET +#endif + TOOLBAR_ITEM(BACK_BUTTON, back, false) TOOLBAR_ITEM(HISTORY_BUTTON, history, true) TOOLBAR_ITEM(FORWARD_BUTTON, forward, false) @@ -134,3 +139,8 @@ TOOLBAR_ITEM(CONTENTS_BUTTON, contents, true) TOOLBAR_ITEM(GUIDE_BUTTON, guide, true) TOOLBAR_ITEM(INFO_BUTTON, info, true) TOOLBAR_ITEM(ABOUT_BUTTON, about, true) + +#ifdef TOOLBAR_ITEM_SET +#undef TOOLBAR_ITEM +#undef TOOLBAR_ITEM_SET +#endif