diff options
author | Vincent Sanders <vince@netsurf-browser.org> | 2013-06-25 19:01:41 +0100 |
---|---|---|
committer | Vincent Sanders <vince@netsurf-browser.org> | 2013-06-25 19:01:41 +0100 |
commit | 59dc2931565c56ee2d037568758db23bf4893169 (patch) | |
tree | cad3c4e02ad981bdabd309225b33b38a9c44ed49 | |
parent | 6358290e78e340ee82c26ab8e327b48db1f8c43e (diff) | |
download | netsurf-59dc2931565c56ee2d037568758db23bf4893169.tar.gz netsurf-59dc2931565c56ee2d037568758db23bf4893169.tar.bz2 |
fix status/toolbar bottom split position and setting user option in gtk
-rw-r--r-- | gtk/scaffolding.c | 63 | ||||
-rw-r--r-- | gtk/window.c | 110 |
2 files changed, 104 insertions, 69 deletions
diff --git a/gtk/scaffolding.c b/gtk/scaffolding.c index 566197dcd..016e24fcd 100644 --- a/gtk/scaffolding.c +++ b/gtk/scaffolding.c @@ -127,7 +127,6 @@ struct gtk_scaffolding { GtkImage *throbber; struct gtk_search *search; GtkWidget *webSearchEntry; - GtkPaned *status_pane; int offset; int toolbarmem; @@ -545,7 +544,7 @@ static void nsgtk_window_tabs_remove(GtkNotebook *notebook, */ static void nsgtk_openfile_open(const char *filename) { - struct browser_window *bw; + struct browser_window *bw; char *urltxt; nsurl *url; nserror error; @@ -639,11 +638,11 @@ MULTIHANDLER(newtab) } else if (nsoption_bool(new_blank)) { /** @todo what the heck is this for? */ GtkWidget *window = gtk_notebook_get_nth_page(g->notebook, -1); - nsgtk_widget_override_background_color(window, - GTK_STATE_NORMAL, + nsgtk_widget_override_background_color(window, + GTK_STATE_NORMAL, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF); } - + return TRUE; } @@ -1016,7 +1015,7 @@ MENUHANDLER(link_openwin) } if (error != NSERROR_OK) { warn_user(messages_get_errorcode(error), 0); - } + } return TRUE; } @@ -1050,7 +1049,7 @@ MENUHANDLER(link_opentab) } if (error != NSERROR_OK) { warn_user(messages_get_errorcode(error), 0); - } + } temp_open_background = -1; @@ -1285,10 +1284,6 @@ MULTIHANDLER(savewindowsize) { int x,y,w,h; - if (GTK_IS_PANED(g->status_pane)) { - nsoption_set_int(toolbar_status_size, - gtk_paned_get_position(g->status_pane)); - } gtk_window_get_position(g->window, &x, &y); gtk_window_get_size(g->window, &w, &h); @@ -1682,7 +1677,7 @@ BUTTONHANDLER(history) #if GTK_CHECK_VERSION(3,0,0) -static gboolean +static gboolean nsgtk_history_draw_event(GtkWidget *widget, cairo_t *cr, gpointer data) { struct rect clip; @@ -1721,7 +1716,7 @@ nsgtk_history_draw_event(GtkWidget *widget, cairo_t *cr, gpointer data) #else /* signal handler functions for the local history window */ -static gboolean +static gboolean nsgtk_history_draw_event(GtkWidget *widget, GdkEventExpose *event, gpointer g) { struct rect clip; @@ -1820,25 +1815,25 @@ static bool nsgtk_new_scaffolding_popup(struct gtk_scaffolding *g, GtkAccelGroup SIG_CONNECT(nmenu->popup_menu, "hide", nsgtk_window_popup_menu_hidden, g); - g_signal_connect(nmenu->savelink_menuitem, "activate", + g_signal_connect(nmenu->savelink_menuitem, "activate", G_CALLBACK(nsgtk_on_savelink_activate_menu), g); - g_signal_connect(nmenu->opentab_menuitem, "activate", + g_signal_connect(nmenu->opentab_menuitem, "activate", G_CALLBACK(nsgtk_on_link_opentab_activate_menu), g); - g_signal_connect(nmenu->openwin_menuitem, "activate", + g_signal_connect(nmenu->openwin_menuitem, "activate", G_CALLBACK(nsgtk_on_link_openwin_activate_menu), g); - g_signal_connect(nmenu->cut_menuitem, "activate", + g_signal_connect(nmenu->cut_menuitem, "activate", G_CALLBACK(nsgtk_on_cut_activate_menu), g); - g_signal_connect(nmenu->copy_menuitem, "activate", + g_signal_connect(nmenu->copy_menuitem, "activate", G_CALLBACK(nsgtk_on_copy_activate_menu), g); - g_signal_connect(nmenu->paste_menuitem, "activate", + g_signal_connect(nmenu->paste_menuitem, "activate", G_CALLBACK(nsgtk_on_paste_activate_menu), g); - g_signal_connect(nmenu->customize_menuitem, "activate", + g_signal_connect(nmenu->customize_menuitem, "activate", G_CALLBACK(nsgtk_on_customize_activate_menu), g); /* set initial popup menu visibility */ @@ -1942,10 +1937,10 @@ nsgtk_scaffolding *nsgtk_new_scaffolding(struct gui_window *toplevel) * or some sensible default if they're not set yet. */ if (nsoption_int(window_width) > 0) { - gtk_window_move(g->window, - nsoption_int(window_x), + gtk_window_move(g->window, + nsoption_int(window_x), nsoption_int(window_y)); - gtk_window_resize(g->window, + gtk_window_resize(g->window, nsoption_int(window_width), nsoption_int(window_height)); } else { @@ -1962,7 +1957,7 @@ nsgtk_scaffolding *nsgtk_new_scaffolding(struct gui_window *toplevel) GtkIconSize tooliconsize; GtkToolbarStyle toolbarstyle; - g_object_get(settings, + g_object_get(settings, "gtk-toolbar-icon-size", &tooliconsize, "gtk-toolbar-style", &toolbarstyle, NULL); @@ -2077,8 +2072,8 @@ nsgtk_scaffolding *nsgtk_new_scaffolding(struct gui_window *toplevel) g_signal_connect(G_OBJECT(obj), (sig), G_CALLBACK(callback), (ptr)) /* connect history window signals to their handlers */ - nsgtk_connect_draw_event(GTK_WIDGET(g->history_window->drawing_area), - G_CALLBACK(nsgtk_history_draw_event), + nsgtk_connect_draw_event(GTK_WIDGET(g->history_window->drawing_area), + G_CALLBACK(nsgtk_history_draw_event), g->history_window); /*CONNECT(g->history_window->drawing_area, "motion_notify_event", nsgtk_history_motion_notify_event, g->history_window);*/ @@ -2107,12 +2102,10 @@ nsgtk_scaffolding *nsgtk_new_scaffolding(struct gui_window *toplevel) CONNECT(g->search->entry, "key-press-event", nsgtk_search_entry_key, g); CONNECT(g->search->buttons[2], "clicked", nsgtk_search_close_button_clicked, g); - CONNECT(g->search->caseSens, "toggled", nsgtk_search_entry_changed, - g); - + CONNECT(g->search->caseSens, "toggled", nsgtk_search_entry_changed, g); CONNECT(g->tool_bar, "popup-context-menu", - nsgtk_window_tool_bar_clicked, g); + nsgtk_window_tool_bar_clicked, g); /* create popup menu */ nsgtk_new_scaffolding_popup(g, group); @@ -2242,13 +2235,13 @@ nsgtk_scaffolding_set_icon(struct gui_window *gw) GdkPixbuf *icon_pixbuf = nsgtk_get_icon(gw); /* check icon needs to be shown */ - if ((icon_pixbuf == NULL) || + if ((icon_pixbuf == NULL) || (sc->top_level != gw)) { return; } - nsgtk_entry_set_icon_from_pixbuf(sc->url_bar, - GTK_ENTRY_ICON_PRIMARY, + nsgtk_entry_set_icon_from_pixbuf(sc->url_bar, + GTK_ENTRY_ICON_PRIMARY, icon_pixbuf); gtk_widget_show_all(GTK_WIDGET(sc->buttons[URL_BAR_ITEM]->button)); @@ -2260,7 +2253,7 @@ void gui_window_set_search_ico(hlcache_handle *ico) nsgtk_scaffolding *current; GdkPixbuf *srch_pixbuf; - if ((ico == NULL) && + if ((ico == NULL) && (ico = search_web_ico()) == NULL) { return; } @@ -2278,7 +2271,7 @@ void gui_window_set_search_ico(hlcache_handle *ico) /* add ico to each window's toolbar */ for (current = scaf_list; current != NULL; current = current->next) { - nsgtk_entry_set_icon_from_pixbuf(current->webSearchEntry, + nsgtk_entry_set_icon_from_pixbuf(current->webSearchEntry, GTK_ENTRY_ICON_PRIMARY, srch_pixbuf); } diff --git a/gtk/window.c b/gtk/window.c index 5edace8f3..6a5cce160 100644 --- a/gtk/window.c +++ b/gtk/window.c @@ -44,6 +44,10 @@ #include "utils/log.h" #include "utils/utils.h" +/* helper macro to conenct signals to callbacks */ +#define CONNECT(obj, sig, callback, ptr) \ + g_signal_connect(G_OBJECT(obj), (sig), G_CALLBACK(callback), (ptr)) + extern const GdkPixdata menu_cursor_pixdata; struct gui_window { @@ -83,9 +87,12 @@ struct gui_window { /** statusbar */ GtkLabel *status_bar; - /** scrollbar paned */ + /** status pane */ GtkPaned *paned; + /** has the status pane had its first size operation yet? */ + bool paned_sized; + /** to allow disactivation / resume of normal window behaviour */ gulong signalhandler[NSGTK_WINDOW_SIGNAL_COUNT]; @@ -147,7 +154,7 @@ float nsgtk_get_scale_for_gui(struct gui_window *g) #if GTK_CHECK_VERSION(3,0,0) -static gboolean +static gboolean nsgtk_window_draw_event(GtkWidget *widget, cairo_t *cr, gpointer data) { struct gui_window *gw = data; @@ -202,7 +209,7 @@ nsgtk_window_draw_event(GtkWidget *widget, cairo_t *cr, gpointer data) #else -static gboolean +static gboolean nsgtk_window_draw_event(GtkWidget *widget, GdkEventExpose *event, gpointer data) { struct gui_window *gw = data; @@ -480,7 +487,7 @@ static gboolean nsgtk_window_keypress_event(GtkWidget *widget, if (browser_window_key_press(g->bw, nskey)) return TRUE; - if ((event->state & 0x7) != 0) + if ((event->state & 0x7) != 0) return TRUE; double value; @@ -591,17 +598,49 @@ static gboolean nsgtk_window_size_allocate_event(GtkWidget *widget, g->bw->reformat_pending = true; browser_reformat_pending = true; - if (g->paned != NULL) { - /* Set status bar / scroll bar proportion according to - * option_toolbar_status_size */ - /* TODO: Probably want to detect when the user adjusts the - * status bar width, remember that proportion for the - * window, and use that here. */ - gtk_paned_set_position(g->paned, - (nsoption_int(toolbar_status_size) * - allocation->width) / 10000); + + return TRUE; +} + + +/** 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 + * allocate-event signal so the position value in the pane is incorrect + * and we cannot know what it should be until after the allocation + * (which did not generate a signal) is done as the user position is a + * percentage of pane total width not an absolute value. + */ +static void +nsgtk_paned_notify__position(GObject *gobject, GParamSpec *pspec, gpointer data) +{ + struct gui_window *g = data; + GtkAllocation pane_alloc; + + gtk_widget_get_allocation(GTK_WIDGET(g->paned), &pane_alloc); + + if (g->paned_sized == false) + { + g->paned_sized = true; + gtk_paned_set_position(g->paned, + (nsoption_int(toolbar_status_size) * pane_alloc.width) / 10000); + return; } + nsoption_set_int(toolbar_status_size, + ((gtk_paned_get_position(g->paned) * 10000) / (pane_alloc.width - 1))); +} + +/** Set status bar / scroll bar proportion according to user option + * when pane is resized. + */ +static gboolean nsgtk_paned_size_allocate_event(GtkWidget *widget, + GtkAllocation *allocation, gpointer data) +{ + gtk_paned_set_position(GTK_PANED(widget), + (nsoption_int(toolbar_status_size) * allocation->width) / 10000); + return TRUE; } @@ -611,6 +650,7 @@ struct gui_window *gui_create_browser_window(struct browser_window *bw, bool new_tab) { struct gui_window *g; /**< what we're creating to return */ + GError* error = NULL; g = calloc(1, sizeof(*g)); if (!g) { @@ -621,7 +661,6 @@ struct gui_window *gui_create_browser_window(struct browser_window *bw, LOG(("Creating gui window %p for browser window %p", g, bw)); g->bw = bw; - g->paned = NULL; g->mouse.state = 0; g->current_pointer = GUI_POINTER_DEFAULT; if (clone != NULL) { @@ -630,8 +669,7 @@ struct gui_window *gui_create_browser_window(struct browser_window *bw, bw->scale = (float) nsoption_int(scale) / 100.0; } - g->careth = 0; - + /* attach scaffold */ if (new_tab) { assert(clone != NULL); g->scaffold = clone->window->scaffold; @@ -639,7 +677,6 @@ struct gui_window *gui_create_browser_window(struct browser_window *bw, /* Now construct and attach a scaffold */ g->scaffold = nsgtk_new_scaffolding(g); } - if (g->scaffold == NULL) { warn_user("NoMemory", 0); free(g); @@ -649,10 +686,9 @@ struct gui_window *gui_create_browser_window(struct browser_window *bw, /* Construct our primary elements */ /* top-level document (not a frame) => create a new tab */ - GError* error = NULL; GtkBuilder* xml = gtk_builder_new(); - if (!gtk_builder_add_from_file(xml, - glade_file_location->tabcontents, + if (!gtk_builder_add_from_file(xml, + glade_file_location->tabcontents, &error)) { g_warning ("Couldn't load builder file: %s", error->message); g_error_free(error); @@ -706,28 +742,35 @@ struct gui_window *gui_create_browser_window(struct browser_window *bw, nsgtk_widget_set_can_focus(GTK_WIDGET(g->layout), TRUE); /* set the default background colour of the drawing area to white. */ - nsgtk_widget_override_background_color(GTK_WIDGET(g->layout), + nsgtk_widget_override_background_color(GTK_WIDGET(g->layout), GTK_STATE_NORMAL, 0, 0xffff, 0xffff, 0xffff); - nsgtk_connect_draw_event(GTK_WIDGET(g->layout), G_CALLBACK(nsgtk_window_draw_event), g); + nsgtk_connect_draw_event(GTK_WIDGET(g->layout), + G_CALLBACK(nsgtk_window_draw_event), g); -#define CONNECT(obj, sig, callback, ptr) \ - g_signal_connect(G_OBJECT(obj), (sig), G_CALLBACK(callback), (ptr)) - - CONNECT(g->layout, "motion_notify_event", + /* layout signals */ + CONNECT(g->layout, "motion-notify-event", nsgtk_window_motion_notify_event, g); g->signalhandler[NSGTK_WINDOW_SIGNAL_CLICK] = - CONNECT(g->layout, "button_press_event", + CONNECT(g->layout, "button-press-event", nsgtk_window_button_press_event, g); - CONNECT(g->layout, "button_release_event", + CONNECT(g->layout, "button-release-event", nsgtk_window_button_release_event, g); - CONNECT(g->layout, "key_press_event", + CONNECT(g->layout, "key-press-event", nsgtk_window_keypress_event, g); - CONNECT(g->layout, "size_allocate", + CONNECT(g->layout, "size-allocate", nsgtk_window_size_allocate_event, g); CONNECT(g->layout, "scroll-event", nsgtk_window_scroll_event, g); + + /* status pane signals */ + CONNECT(g->paned, "size-allocate", + nsgtk_paned_size_allocate_event, g); + + CONNECT(g->paned, "notify::position", + nsgtk_paned_notify__position, g); + return g; } @@ -813,8 +856,8 @@ void gui_window_set_icon(struct gui_window *gw, hlcache_handle *icon) if (icon_bitmap != NULL) { LOG(("Using %p bitmap", icon_bitmap)); gw->icon = nsgdk_pixbuf_get_from_surface(icon_bitmap->surface, 16, 16); - } - } + } + } if (gw->icon == NULL) { LOG(("Using default favicon")); @@ -1029,7 +1072,7 @@ void gui_window_set_pointer(struct gui_window *g, gui_pointer_shape shape) gtk_widget_get_display( GTK_WIDGET(g->layout)), cursortype); - gdk_window_set_cursor(nsgtk_widget_get_window(GTK_WIDGET(g->layout)), + gdk_window_set_cursor(nsgtk_widget_get_window(GTK_WIDGET(g->layout)), cursor); if (!nullcursor) @@ -1100,4 +1143,3 @@ void gui_window_get_dimensions(struct gui_window *g, int *width, int *height, LOG(("width: %i", *width)); LOG(("height: %i", *height)); } - |