开发者

Display web page using libgtkhtml c c++

I want to display a very simple htm开发者_JAVA百科l 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.


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


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.


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


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);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜