-
Notifications
You must be signed in to change notification settings - Fork 1
/
gtkWebkitScrollTest.c
63 lines (48 loc) · 2.1 KB
/
gtkWebkitScrollTest.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
//
// gtkWebkitScrollTest.c
//
// A test of a scrollable container (horizontal and vertical) using GTK Webkit.
//
// Created by Nick Salerni on 2014-07-06.
//
#include <gtk/gtk.h>
#include <webkit/webkit.h>
static void destroyWindowCb(GtkWidget* widget, GtkWidget* window);
static gboolean closeWebViewCb(WebKitWebView* webView, GtkWidget* window);
int main(int argc, char* argv[])
{
// Initialize GTK+.
gtk_init(&argc, &argv);
// Create an 800 x 600 window that will contain the browser instance.
GtkWidget *main_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_default_size(GTK_WINDOW(main_window), 800, 600);
// Create a browser instance.
WebKitWebView *webView = WEBKIT_WEB_VIEW(webkit_web_view_new());
// Create a scrollable area, and add the browser instance to it.
GtkWidget *scrolledWindow = gtk_scrolled_window_new(NULL, NULL);
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledWindow), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
gtk_container_add(GTK_CONTAINER(scrolledWindow), GTK_WIDGET(webView));
// Set up callbacks so that if either the main window or the browser instance is closed, the program will exit.
g_signal_connect(main_window, "destroy", G_CALLBACK(destroyWindowCb), NULL);
g_signal_connect(webView, "close-web-view", G_CALLBACK(closeWebViewCb), main_window);
// Add the scrollable area to the main window.
gtk_container_add(GTK_CONTAINER(main_window), scrolledWindow);
// Load a web page into the browser instance.
webkit_web_view_load_uri(webView, "http://www.fsf.org/");
// Make sure that when the browser area becomes visible, it will accept mouse and keyboard events.
gtk_widget_grab_focus(GTK_WIDGET(webView));
// Make sure the main window and all its contents are visible.
gtk_widget_show_all(main_window);
// Run the main GTK+ event loop.
gtk_main();
return 0;
}
static void destroyWindowCb(GtkWidget* widget, GtkWidget* window)
{
gtk_main_quit();
}
static gboolean closeWebViewCb(WebKitWebView* webView, GtkWidget* window)
{
gtk_widget_destroy(window);
return TRUE;
}