GtkHTML显示

转载 2011年01月24日 22:11:00

GtkHTML控件就可以显示HTMLEvolution就是用的这个。

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“

代码:
sudo apt-get install libgtkhtml3.14-dev


代码:
pkg-config --cflags --libs libgtkhtml-3.14

-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

 

GtkHTML programming guide

http://primates.ximian.com/~rodo/programing_with_gtkhtml_tutorial/guadec.htmlSome useful functions o...
  • findsun
  • findsun
  • 2004年08月05日 01:51
  • 2232

LWJGL显示一 显示

LWJGL基础1(显示) 介绍 LWJGL库使用它自己的轻量级本地窗口(显示),并有其自己的输入系统。 这提供了一种创建快速,小范围内,可借鉴,可实现低延迟的输入现代游戏的一个坚实的基础。...
  • Mynoob
  • Mynoob
  • 2012年08月08日 16:10
  • 913

显示全部内容OR显示部分内容

效果图:     http://www.w3.org/1999/xhtml">                     //等待DOM加载完毕        ...
  • u011686207
  • u011686207
  • 2014年02月26日 13:31
  • 640

显示

更多内容: C++Primer 第四版 部分习题解答 经典算法设计方法大杂烩 俄罗斯方块VC++的设计与实现 中国象棋对战程序C语言源代码 Linux文件系统 华容道游戏与算法 论金融电子化系统建设及...
  • bigbigf
  • bigbigf
  • 2008年06月14日 11:36
  • 190

字符显示——显示ASCII

我们来在lcd上显示一个ASCII码 int main(void) { int fb_fd; int screen_size; fb_fd = open("/dev/fb0",O_...
  • zhang648462189
  • zhang648462189
  • 2014年10月24日 17:38
  • 199

地图显示----地图显示

概述: 主要学习一下高德的JS API demo,有很多理解不到位,请求多多指正 参考:http://lbs.amap.com/api/javascript-api/example/map/click...
  • m0_37355951
  • m0_37355951
  • 2017年07月04日 11:47
  • 91

Mac显示/关闭显示 隐藏文件

显示隐藏文件  defaults write com.apple.finder AppleShowAllFiles -bool true   如果想恢复隐藏,可以用这个命令:   defaults w...
  • u013767495
  • u013767495
  • 2017年01月13日 15:14
  • 69

OpenGL显示文字--显示英文

本文转自:http://blog.sina.com.cn/s/blog_4ff085000100devp.html   OpenGL并没有直接提供显示文字的功能,并且,OpenGL也没有自带专...
  • Wadejr
  • Wadejr
  • 2009年11月23日 15:45
  • 8974

adduser 显示和不显示

添加用户                                                                                         ...
  • w983798109
  • w983798109
  • 2017年09月29日 18:12
  • 30

点击显示下拉层显示

var $ = function(i) {    return document.getElementById(i)};function moreshow() {    var e = $('more...
  • qq254331474
  • qq254331474
  • 2016年09月01日 17:44
  • 43
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:GtkHTML显示
举报原因:
原因补充:

(最多只允许输入30个字)