GtkHTML控件就可以显示HTML,Evolution就是用的这个。
1. gtk_html_begin_content(), then gtk_html_write(), at last gtk_html_end().
2. gtk_html_set_base(), gtk_html_jump_to_anchor(), gtk_html_load_empty().
3. Contructor: gtk_html_new()
Signals:
“url-requested“
“obj-requested“ (embedded objects)
“load-done“
“submit“
“size-changed“
“link-clicked“
“button-press-event“
“redirect“
“title-changed“
“on-url“
-D_REENTRANT -DORBIT2=1 -pthread -I/usr/include/libgtkhtml-3.14 -I/usr/include/gtk-2.0 -I/usr/include/libgnomeui-2.0 -I/usr/include/libglade-2.0 -I/usr/lib/gtk-2.0/include -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/pango-1.0 -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/usr/include/freetype2 -I/usr/include/directfb -I/usr/include/libpng12 -I/usr/include/pixman-1 -I/usr/include/libart-2.0 -I/usr/include/gconf/2 -I/usr/include/gnome-keyring-1 -I/usr/include/libgnome-2.0 -I/usr/include/libbonoboui-2.0 -I/usr/include/libgnomecanvas-2.0 -I/usr/include/gnome-vfs-2.0 -I/usr/lib/gnome-vfs-2.0/include -I/usr/include/orbit-2.0 -I/usr/include/libbonobo-2.0 -I/usr/include/bonobo-activation-2.0 -I/usr/include/libxml2 -I/usr/include/gail-1.0 -pthread -lgtkhtml-3.14 -lgnomeui-2 -lSM -lICE -lglade-2.0 -lbonoboui-2 -lgnomevfs-2 -lgnomecanvas-2 -lgnome-2 -lpopt -lbonobo-2 -lbonobo-activation -lORBit-2 -lart_lgpl_2 -lgconf-2 -lgthread-2.0 -lrt -lgtk-x11-2.0 -lxml2 -lgdk-x11-2.0 -latk-1.0 -lgdk_pixbuf-2.0 -lm -lpangocairo-1.0 -lpango-1.0 -lcairo -lgobject-2.0 -lgmodule-2.0 -ldl -lglib-2.0
需要的makefile为:
CC = gcc
CFLAGS = -Wall /
-DG_DISABLE_DEPRECATED /
-DGDK_DISABLE_DEPRECATED /
-DGDK_PIXBUF_DISABLE_DEPRECATED /
-DGTK_DISABLE_DEPRECATED
helloworld2: test.c
$(CC) test.c -o test $(CFLAGS) `pkg-config gtk+-2.0 libgtkhtml-3.14 --cflags --libs libgtkhtml-3.14`
clean:
rm -f *.o test
例子程序如下:可以打开网页,注意必须在指定目录下有html文件。
#if 1
#include <gtk/gtk.h>
#include <gtkhtml/gtkhtml.h>
#include <sys/stat.h>
const gchar *html_source = "<B><FONT COLOR=Blue>Hello world!</FONT></B>";
/* Our new improved callback. The data passed to this function
* is printed to stdout. */
static void callback (GtkWidget *widget,
gpointer data)
{
g_print ("Hello again - %s was pressed/n", (gchar *) data);
}
/* another callback */
static gboolean delete_event (GtkWidget *widget,
GdkEvent *event,
gpointer data)
{
gtk_main_quit ();
return TRUE;
}
int main (int argc,
char *argv[])
{
/* GtkWidget is the storage type for widgets */
GtkWidget *window;
GtkWidget *button;
GtkWidget *box1;
FILE *file;
gchar *buffer;
char filename[] = "/home/xudongcheng/gtk2-tut/book1.html";
//char filename[] = "/home/xudongcheng/s.html";
struct stat stats;
if (stat (filename, &stats) == -1)
return NULL;
if (!(file = fopen (filename, "rb")))
return NULL;
buffer = (gchar *)g_malloc (stats.st_size + 1);
fread (buffer, 1, stats.st_size, file);
/* if (fread (buffer, 1, stats.st_size, file) != stats.st_size)
{
g_free (buffer);
fclose (file);
return NULL;
}
*/
fclose (file);
buffer[stats.st_size] = '/0';
/* This is called in all GTK applications. Arguments are parsed
* from the command line and are returned to the application. */
gtk_init (&argc, &argv);
/* Create a new window */
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
/* This is a new call, which just sets the title of our
* new window to "Hello Buttons!" */
gtk_window_set_title (GTK_WINDOW (window), "Hello Monday!");
/* Here we just set a handler for delete_event that immediately
* exits GTK. */
g_signal_connect (window, "delete-event",
G_CALLBACK (delete_event), NULL);
/* Sets the border width of the window. */
gtk_container_set_border_width (GTK_CONTAINER (window), 10);
/* We create a box to pack widgets into. This is described in detail
* in the "packing" section. The box is not really visible, it
* is just used as a tool to arrange widgets. */
box1 = gtk_hbox_new (FALSE, 0);
/* Put the box into the main window. */
gtk_container_add (GTK_CONTAINER (window), box1);
/* Creates a new button with the label "Button 1". */
// button = gtk_button_new_with_label ("Button 1");
// g_signal_connect (button, "clicked", G_CALLBACK (callback), "button 1");
button = gtk_html_new_from_string (buffer, -1);
#if 1
/* 创建一个新的滚动窗口。 */
GtkWidget * scrolled = gtk_scrolled_window_new (NULL, NULL);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled),GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
gtk_container_add (GTK_CONTAINER (scrolled), button);
gtk_widget_show (scrolled);
gtk_box_pack_end (GTK_BOX (box1), scrolled, TRUE, TRUE, 0);
#else
/* Instead of gtk_container_add, we pack this button into the invisible
* box, which has been packed into the window. */
gtk_box_pack_end (GTK_BOX (box1), button, TRUE, TRUE, 0);
#endif
/* Always remember this step, this tells GTK that our preparation for
* this button is complete, and it can now be displayed. */
gtk_widget_show (button);
/* button = gtk_button_new_with_label ("Button 2");
g_signal_connect (button, "clicked",G_CALLBACK (callback), "button 2");
gtk_widget_show (button);
gtk_box_pack_start (GTK_BOX (box1), button, TRUE, TRUE, 0);*/
/* The order in which we show the buttons is not really important, but I
* recommend showing the window last, so it all pops up at once. */
gtk_widget_show (box1);
gtk_widget_show (window);
/* Rest in gtk_main and wait for the fun to begin! */
gtk_main ();
return 0;
}
#endif