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

 

相关文章推荐

用C++写一个日历程序,要求输入年份,显示全年的日历

日历 C++

ListView显示出应用列表

  • 2017-10-10 11:24
  • 14.76MB
  • 下载

液晶显示产品使用规范

  • 2017-10-08 09:24
  • 191KB
  • 下载

浅析font-family属性及在不同浏览器显示差异问题

主要就在body中定义了字体样式但仍无法正确显示字体效果的问题进行了一系列的解决和调研...

OpenCV两种方法显示中文

  • 2017-10-07 16:58
  • 24.23MB
  • 下载

Android中自定义RatingBar,自定义星星间距,自定义样式,自定义显示效果

RatingBar是在等级,星级显示的时候,用的最多的,但是系统自带的效果,在星星间距大小上,以及将星星替换为其他造型上不能满足需求,所以需要自定义RatingBar;自定义RatingBar非常简单...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

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