tags:

views:

124

answers:

4

I want to display a very simple html page from the web, using libgtkhtml. Can you give an example please? Or some documentation/resources? I found nothing. (C preferred, but C++ also acceptable). Thanks in advance.

+2  A: 

If you want to view online content, you might be better off using gtkmozembed (Gecko) or WebkitGTK+ (Webkit)

Martin
A: 

Here is a (fairly old) tutorial: http://primates.ximian.com/~rodo/programing_with_gtkhtml_tutorial/guadec.html

You also need to know that GtkHTML doesn't load from the web, so you have to use another library to fetch the HTML page yourself and feed it to GtkHTML.

ptomato
This is very old and doesn't work, I tried that before posting here.
Levo
Well, `gnome_init()` and `gnome-config` are deprecated and you should use `gtk_init()` and `pkg-config` instead, but what the tutorial explains about the basics of how GtkHTML works should still apply. What exactly doesn't work?
ptomato
A: 

Why don't you adapt the test programs distributed with the tarball?

fetasail
A: 

Something like this should do it quickly. Just put the info info widget into a GtkScrolledWindow for example.

#include <gtkhtml/gtkhtml.h>
#include <gtkhtml/gtkhtml-stream.h>

#define WRITE_HTML(html, args...) \
    { gchar *ph; \
    ph=g_markup_printf_escaped(html, ##args); \
    gtk_html_write(GTK_HTML(info), s, ph, strlen(ph)); \
    g_free(ph); }

{
GtkWidget *info;
GtkHTMLStream *s;

info=gtk_html_new();
gtk_html_set_editable(GTK_HTML(info), FALSE);
gtk_html_allow_selection(GTK_HTML(info), TRUE);

/* Optional, connect signals for link clicks, url load requests, etc */
#if 0
g_signal_connect(G_OBJECT(info), "link_clicked", G_CALLBACK(info_url_clicked_cb), NULL);
g_signal_connect(G_OBJECT(info), "url_requested", G_CALLBACK(info_url_requested_cb), NULL);
g_signal_connect(G_OBJECT(info), "title_changed", G_CALLBACK(info_title_cb), NULL);
#endif

s=gtk_html_begin(GTK_HTML(info));

WRITE_HTML("<html><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">" \
    "<head><title>Testing</title></head><body><h1>GtkHTML</h3><p>Example</p>");
WRITE_HTML("<p>Postal Code: %s</p>", some_random_data);
WRITE_HTML("</body></html>");

gtk_html_end(GTK_HTML(info), s, GTK_HTML_STREAM_OK);
}
onion