Re: Simple GtkHTML question?



> I would like to know a simple way in which I could make a GtkHTML Widget
> for previewing a code of HTML. What I have in mind is something like this
> 
> html = gtk_html_new ();
> /*
>  * Code for feeding the html data
>  */
> gtk_widget_show (html);
> 
> Now what I want is the part which I commented. What is the minimal number
> of functions required to do so.

Try this:

GtkWidget *html;
GtkWidget *scrolled_window;
GtkHTMLStream *stream;
char *text;

html = gtk_html_new();
scrolled_window = gtk_scrolled_window_new(NULL, NULL);
gtk_container_add(GTK_CONTAINER(scrolled_window), html);

/*
 * Here's the part you asked for
 */
stream = gtk_html_begin(GTK_HTML(html));
text = "<html><body><h1>foo</h1></body></html>";
gtk_html_write(GTK_HTML(html), stream, text, strlen(text));
gtk_html_end(GTK_HTML(html), stream, GTK_HTML_STREAM_OK);

gtk_widget_show_all(scrolled_window);

I do the scrolled window stuff because I think the HTML widget needs to be
inside of one. At least, it did in the old days. :)

Of course, the above only does the simple text stuff. You'll have to
connect to various signals on the widget if you want to load images, do
iframes, etc.

Joe





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]