/* gcc `pkg-config --cflags --libs gtk+-3.0 webkit2gtk-4.0` test-wk2.c -g -O0 -o test-wk2 && ./test-wk2 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <gtk/gtk.h>
#include <webkit2/webkit2.h>

static GtkWidget *
create_web_view (const gchar *html)
{
	WebKitWebView *web_view;
	WebKitSettings *settings;

	g_return_val_if_fail (html != NULL, NULL);

	web_view = WEBKIT_WEB_VIEW (webkit_web_view_new ());

	webkit_web_view_set_size_request_mode (web_view, WEBKIT_SIZE_REQUEST_CONTENTS_HEIGHT);

	webkit_web_view_load_html (web_view, html, "none-local://");

	settings = webkit_web_view_get_settings (web_view);

	webkit_settings_set_enable_frame_flattening (settings, TRUE);

	g_object_set (G_OBJECT (web_view),
		"hexpand", TRUE,
		"halign", GTK_ALIGN_FILL,
		"vexpand", FALSE,
		"valign", GTK_ALIGN_START,
		NULL);

	return GTK_WIDGET (web_view);
}

static const gchar *html_1st =
	"<html><head></head><body>The first text which may not have as that much long text in it</body></html>";
static const gchar *html_2nd =
	"<html><head></head><body>Certain text with short and loooooooooooooooooong words which may or may not wrap</body></html>";

int main (int argc, char *argv[])
{
	GtkWidget *dialog, *container, *widget;

	gtk_init (&argc, &argv);

	dialog = gtk_dialog_new_with_buttons ("wk2", NULL, 0, "_Cancel", GTK_RESPONSE_CANCEL, NULL);
	gtk_window_set_default_size (GTK_WINDOW (dialog), 640, 480);

	container = gtk_dialog_get_content_area (GTK_DIALOG (dialog));

	widget = gtk_paned_new (GTK_ORIENTATION_HORIZONTAL);
	g_object_set (G_OBJECT (widget),
		"hexpand", TRUE,
		"halign", GTK_ALIGN_FILL,
		"vexpand", TRUE,
		"valign", GTK_ALIGN_FILL,
		"position", 123,
		"wide-handle", TRUE,
		NULL);
	gtk_container_add (GTK_CONTAINER (container), widget);

	container = widget;

	widget = gtk_text_view_new ();
	gtk_paned_pack1 (GTK_PANED (container), widget, FALSE, FALSE);

	widget = gtk_scrolled_window_new (NULL, NULL);
	gtk_scrolled_window_set_policy (
		GTK_SCROLLED_WINDOW (widget),
		GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
	g_object_set (G_OBJECT (widget),
		"hexpand", TRUE,
		"halign", GTK_ALIGN_FILL,
		"vexpand", TRUE,
		"valign", GTK_ALIGN_FILL,
		NULL);
	gtk_paned_pack2 (GTK_PANED (container), widget, FALSE, FALSE);

	container = widget;

	widget = gtk_box_new (GTK_ORIENTATION_VERTICAL, 4);
	g_object_set (G_OBJECT (widget),
		"hexpand", TRUE,
		"halign", GTK_ALIGN_FILL,
		"vexpand", TRUE,
		"valign", GTK_ALIGN_FILL,
		NULL);
	gtk_container_add (GTK_CONTAINER (container), widget);

	container = widget;

	widget = create_web_view (html_1st);
	gtk_box_pack_start (GTK_BOX (container), widget, FALSE, FALSE, 0);

	widget = create_web_view (html_2nd);
	gtk_box_pack_start (GTK_BOX (container), widget, FALSE, FALSE, 0);

	gtk_widget_show_all (gtk_dialog_get_content_area (GTK_DIALOG (dialog)));
	gtk_dialog_run (GTK_DIALOG (dialog));

	gtk_widget_destroy (dialog);

	return 0;
}
