Subscribed unsubscribe Subscribe Subscribe

GtkHTMLでHTMLな文字列をさらっと表示するためのサンプル

GtkHTML 3.x用。GtkHTML 4.xは未確認。

#include <string.h>
#include <glib.h>
#include <gtk/gtk.h>
#include <gtkhtml/gtkhtml.h>

static gboolean delete_event( GtkWidget *widget,
                              GdkEvent  *event,
                              gpointer   data )
{
    g_print ("delete event occurred\n");
    return FALSE;
}

static void destroy( GtkWidget *widget,
                     gpointer   data )
{
    gtk_main_quit ();
}

static const gchar *html_string = "<html><body><h1>title</h1><p>Hello, GtkHTML!</p></body></html>";
int main(int argc, char *argv[])
{
  GtkWidget *window;
  GtkWidget *html;

  gtk_init(&argc, &argv);
  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  
  g_thread_init(NULL);

  g_signal_connect (window, "destroy",
		  G_CALLBACK (destroy), NULL);

  html = gtk_html_new();
  
  gtk_html_load_from_string(GTK_HTML(html),
			    html_string,
			    strlen(html_string));

  gtk_container_add(GTK_CONTAINER(window), html);

  gtk_widget_show_all(window);
  gtk_main();
  return 0;
}