Skip to content
Browse files

Add back, forward and refresh buttons.

  • Loading branch information...
1 parent 50219e1 commit 6f46cab6d560d5de5f30b3106fe672f89285156c @thomaslee committed May 26, 2012
Showing with 75 additions and 2 deletions.
  1. +72 −2 browserwindow.c
  2. +3 −0 browserwindow.h
View
74 browserwindow.c
@@ -95,15 +95,57 @@ browser_window_key_release_event (
}
}
+static void
+browser_window_back_button_clicked (
+ GtkWidget *widget, gpointer user_data)
+{
+ BrowserWindow *w = (BrowserWindow *) user_data;
+ if (webkit_web_view_can_go_back (WEBKIT_WEB_VIEW (w->view))) {
+ webkit_web_view_go_back (WEBKIT_WEB_VIEW (w->view));
+ }
+}
+
+static void
+browser_window_forward_button_clicked (
+ GtkWidget *widget, gpointer user_data)
+{
+ BrowserWindow *w = (BrowserWindow *) user_data;
+ if (webkit_web_view_can_go_back (WEBKIT_WEB_VIEW (w->view))) {
+ webkit_web_view_go_forward (WEBKIT_WEB_VIEW (w->view));
+ }
+}
+
+static void
+browser_window_refresh_button_clicked (
+ GtkWidget *widget, gpointer user_data)
+{
+ BrowserWindow *w = (BrowserWindow *) user_data;
+ webkit_web_view_reload_bypass_cache (WEBKIT_WEB_VIEW (w->view));
+}
+
+static GtkWidget *
+browser_window_new_nav_button (const gchar *stock_id)
+{
+ GtkWidget *image =
+ gtk_image_new_from_stock (stock_id, GTK_ICON_SIZE_SMALL_TOOLBAR);
+ GtkWidget *button = gtk_button_new ();
+ gtk_button_set_image (GTK_BUTTON (button), image);
+ g_object_set (button, "relief", GTK_RELIEF_NONE, NULL);
+ return button;
+}
+
gboolean
browser_window_init(BrowserWindow *bw)
{
- GtkWidget *vbox;
+ GtkWidget *vbox, *hbox;
bw->window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
bw->view = browser_view_new ();
bw->scrolled = gtk_scrolled_window_new (NULL, NULL);
bw->entry = gtk_entry_new ();
+ bw->back_button = browser_window_new_nav_button (GTK_STOCK_GO_BACK);
+ bw->forward_button = browser_window_new_nav_button (GTK_STOCK_GO_FORWARD);
+ bw->refresh_button = browser_window_new_nav_button (GTK_STOCK_REFRESH);
gtk_container_add (GTK_CONTAINER (bw->scrolled), bw->view);
gtk_scrolled_window_set_policy (
@@ -112,8 +154,15 @@ browser_window_init(BrowserWindow *bw)
GTK_POLICY_AUTOMATIC
);
+ hbox = gtk_hbox_new (FALSE, 0);
+ gtk_box_pack_start (GTK_BOX (hbox), bw->back_button, FALSE, FALSE, 0);
+ gtk_box_pack_start (GTK_BOX (hbox), bw->forward_button, FALSE, FALSE, 0);
+ gtk_box_pack_start (GTK_BOX (hbox), bw->refresh_button, FALSE, FALSE, 0);
+ gtk_box_pack_start (GTK_BOX (hbox), bw->entry, TRUE, TRUE, 0);
+
+
vbox = gtk_vbox_new (FALSE, 0);
- gtk_box_pack_start (GTK_BOX (vbox), bw->entry, FALSE, FALSE, 5);
+ gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 5);
gtk_box_pack_start (GTK_BOX (vbox), bw->scrolled, TRUE, TRUE, 0);
gtk_container_add (GTK_CONTAINER (bw->window), vbox);
@@ -139,6 +188,27 @@ browser_window_init(BrowserWindow *bw)
);
g_signal_connect (
+ bw->back_button,
+ "clicked",
+ G_CALLBACK (browser_window_back_button_clicked),
+ bw
+ );
+
+ g_signal_connect (
+ bw->forward_button,
+ "clicked",
+ G_CALLBACK (browser_window_forward_button_clicked),
+ bw
+ );
+
+ g_signal_connect (
+ bw->refresh_button,
+ "clicked",
+ G_CALLBACK (browser_window_refresh_button_clicked),
+ bw
+ );
+
+ g_signal_connect (
bw->view,
"title-changed",
G_CALLBACK (browser_window_title_changed),
View
3 browserwindow.h
@@ -8,6 +8,9 @@ typedef struct _BrowserWindow {
GtkWidget *view;
GtkWidget *scrolled;
GtkWidget *entry;
+ GtkWidget *back_button;
+ GtkWidget *forward_button;
+ GtkWidget *refresh_button;
} BrowserWindow;
gboolean

0 comments on commit 6f46cab

Please sign in to comment.
Something went wrong with that request. Please try again.