Re: [Gtk2forpascal-devel] Problem about gtkhtml-2 solved!
Brought to you by:
mgaertner
From: Mattias G. <nc-...@ne...> - 2002-11-05 21:32:03
|
On Tue, 5 Nov 2002 21:49:48 +0800 (CST) Zhong Wang <wan...@ya...> wrote: > Hi, Mattias > > Today I solved the problem about gtkhtml-2 > programing with > gtk2forpascal. > First, you should download > "gtkhtml2-2.0.1-3.i386.rpm" and > "gtkhtml2-devel-2.0.1-3.i386.rpm" from > www.rpmfind.net. The > first one contains two shared libs. The second one > contains > many header files and "libgtkhtml-2.a" and > "libgtkhtml-2.so", > and most important, it contains a file: > "/usr/lib/pkgconfig/libgtkhtml-2.0.pc" > You can also download "gtkhtml2-2.0.1-3.src.rpm" to > see its > source. This one is more easier to compile than > gtkhtml-1.1.4 > .tar.gz. From the source you will find that there's > really no > gtk_html_new() but a > html_view_new()+html_document_new(). So > the structure of "view+document" is very like the > structure > "view+buffer" in gtk2. > > Now I changed the declaration from: > >>>>> > const > gtkhtmllib = libgtkhtml-2.so'; > <<<<< > To: > >>>>> > const > gtkhtmllib = ''; > <<<<< > > And use the following shell script to compile the > test.pp: > (command: ./make.sh test.pp) > >>>>> make.sh > #!/bin/bash > make_linker_script () { > LibPath=`pkg-config libgtkhtml-2.0 --libs-only-L | > sed -e 's/-L//g'` > Libs=`pkg-config libgtkhtml-2.0 --libs-only-l` > > rm -f gtk2.link.res > > for SinglePath in $LibPath > do > printf "SEARCH_DIR($SinglePath)\n" >> > gtk2.link.res > done > printf "INPUT(\n$Libs\n)" >> gtk2.link.res > } > > DynamicOption="-XD > -k-dynamic-linker=/lib/ld-linux.so.2 -kgtk2.link.res" > > # UnitPath="../gtk2/" -----> Note: Here I move *.o and > *.ppu of gtk2forpascal > # to /usr/lib/fpc/1.0.7/units/linux/gtk2, so they > can be automatically > # found. > > make_linker_script > > ppc386 -g -Fu$UnitPath $DynamicOption $@ > > rm -f gtk2.link.res > <<<<< > > The test.pp file is as follows (very ugly and > unmature): > >>>>> > program test; > > {$H+} > {$mode objfpc} > > uses > glib2, gtk2, gdk2; > > const > gtkhtmllib = '';//libgtkhtml-2.so'; > > type > PHtmlDocument = ^THtmlDocument; > THtmlDocument = record > parent_instance: TGObject; > end;//THtmlDocument > > PHtmlView = ^THtmlView; > THtmlView = record > parent: TGtkLayout; > end;//THtmlView > > function html_document_new():PHtmlDocument;cdecl; > external gtkhtmllib; > procedure html_view_zoom_in(view: PHtmlView);cdecl; > external gtkhtmllib; > function html_view_new:PGtkWidget;cdecl; external > gtkhtmllib; > procedure html_view_set_document(view: PHtmlView; > document: PHtmlDocument);cdecl; external gtkhtmllib; > function html_document_open_stream(document: > PHtmlDocument;mime_type: pgchar):gboolean;cdecl; > external gtkhtmllib; > procedure html_document_write_stream(document: > PHtmlDocument;buffer: pgchar; len: gint);cdecl; > external gtkhtmllib; > procedure html_document_close_stream(document: > PHtmlDocument);cdecl; external gtkhtmllib; > > //=================== > var > window : PGtkWidget; > sw : PGtkWidget; > html : PGtkWidget; > document: PHtmlDocument; > > procedure destroy (window: PGtkWidget; data: > gpointer); cdecl; > begin > gtk_main_quit(); > end;//destroy > > var > s:String; > begin > gtk_init(@argc,@argv); > > window:=gtk_window_new(GTK_WINDOW_TOPLEVEL); > gtk_widget_set_size_request(window,500,400); > > gtk_window_set_position(PGtkWindow(window),GTK_WIN_POS_CENTER_ALWAYS); > gtk_window_set_title(PGtkWindow(window),'Test'); > > g_signal_connect(window,'destroy',TGCallback(@destroy),NULL); > > > sw:=gtk_scrolled_window_new(NULL,NULL); > gtk_widget_show(sw); > gtk_container_add(PGtkContainer(window),sw); > > document := html_document_new(); > html:=html_view_new(); > gtk_widget_show(html); > > gtk_scrolled_window_add_with_viewport(PGtkScrolledWindow(sw),html); > s:='<html><head><title>Hello, > World!</title></head>'+ > '<body text="#000000" bgcolor="#FFFFCC">'+ > '<center><h1><font size=7>Hello, > world!</font></h1></center>'+ > '</body></html>'; > html_document_open_stream(document,'text/html'); > > html_document_write_stream(document,PChar(s),length(s)); > html_document_close_stream(document); > html_view_set_document(PHtmlView(html), document); > > gtk_widget_show(window); > gtk_main(); > end.//program test > <<<<< > > Mattias, I write an interface for gtkhtml to > gtk2forpascal, but it's > a very simple one. It has only four widgets: > THtmlView, THtmlDocument, > THtmlStream and THtmlStreamBuffer. In the first two > widgets, some fields > are removed. So perhaps some important functionalities > are not included. > The reason why I remove them is because they use > functions of libxml, > I have no time to port so many packages. It remains to > be further work. > At present, I don't know how to show a picture in the > htmlview yet. > > Mattias, Do you think I can present those sources now? > if so, I will > send you those files. If they work, yes. :) Mattias |