1 static BrowserWindow _BrowserWindow;
3 public class BrowserWindow : Object
6 private BrowserWindow _this;
8 public static BrowserWindow singleton()
10 if (_BrowserWindow == null) {
11 _BrowserWindow= new BrowserWindow();
13 return _BrowserWindow;
15 public Xcls_scrolled_window scrolled_window;
16 public Xcls_view view;
21 public BrowserWindow()
24 this.el = new Gtk.Window( Gtk.WindowType.TOPLEVEL );
29 var child_0 = new Xcls_scrolled_window( _this );
31 this.el.add ( child_0.el );
34 this.el.destroy.connect( () => {
37 this.el.show.connect( () => {
39 print("resizing window\n");
40 var w = webkitpdf.opt_width > 0 ? webkitpdf.opt_width : 1200;
41 var h = webkitpdf.opt_height > 0 ? webkitpdf.opt_height : 500;
45 print("loading url\n");
46 this.view.el.load_uri(webkitpdf.opt_url);
48 // if we have not finished in 25 seconds
50 GLib.Timeout.add_seconds(25, () => {
59 // user defined functions
60 public class Xcls_scrolled_window : Object
62 public Gtk.ScrolledWindow el;
63 private BrowserWindow _this;
69 public Xcls_scrolled_window(BrowserWindow _owner )
72 _this.scrolled_window = this;
73 this.el = new Gtk.ScrolledWindow( null, null );
78 var child_0 = new Xcls_view( _this );
80 this.el.add ( child_0.el );
85 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
89 // user defined functions
91 public class Xcls_view : Object
93 public WebKit.WebView el;
94 private BrowserWindow _this;
98 public bool print_started;
101 public Xcls_view(BrowserWindow _owner )
105 this.el = new WebKit.WebView();
108 this.print_started = false;
110 // set gobject values
120 this.el.resource_request_starting.connect( (p0, webres, netreq ) => {
121 print("resource req. started %s\n", netreq.uri);
128 this.el.load_finished.connect( ( ) => {
135 // user defined functions
136 public void printit () {
137 print("load_finsihed\n");
139 if (this.print_started) {
140 print("load_finsihed - already printing..\n");
144 this.print_started = true; // flag to stop double call.
147 // inject any javascript if needed..
148 if (webkitpdf.opt_inject_js != null) {
150 print("injecting javascript files \n");
151 foreach(var inject_js in webkitpdf.opt_inject_js) {
152 print("inject? %s\n", inject_js);
155 FileUtils.get_contents( inject_js, out str);
156 } catch(FileError e) {
157 print("Failed to inject %s\n", inject_js);
160 this.el.execute_script(str);
166 print("calling print in %d seconds\n", (int)webkitpdf.opt_delay);
167 if (webkitpdf.opt_target_pdf != null) {
168 GLib.Timeout.add_seconds(webkitpdf.opt_delay, () => {
172 }, GLib.Priority.DEFAULT);
177 GLib.Timeout.add_seconds(webkitpdf.opt_delay, () => {
180 // ----------------- JPEG
181 // resize the window...
182 // window.document.documentElement.scrollHeight
183 var scroll_height = (int) _this.view.el.get_dom_document().document_element.scroll_height;
184 print("Scroll height %d\n", scroll_height);
185 if (scroll_height> 1024 || webkitpdf.opt_width > 0 || webkitpdf.opt_height > 0 ) {
186 var w = webkitpdf.opt_width > 0 ? webkitpdf.opt_width : 1200;
187 var h = int.min(scroll_height, 6000);
188 _this.scrolled_window.el.set_size_request( w, h);
189 _this.el.resize (w+50, h+50);
190 print("Resize to %d, %d\n", w,h);
191 GLib.Timeout.add_seconds(webkitpdf.opt_delay > 0 ? webkitpdf.opt_delay : 1 , () => {
194 }, GLib.Priority.DEFAULT);
199 }, GLib.Priority.DEFAULT);
205 public bool printpdf () {
207 var pe = new Gtk.PrintOperation();
208 pe.export_filename = webkitpdf.opt_target_pdf;
209 print("got callback for print\n");
211 /*pe.failed.connect(() => {
212 print("print failed\n");
217 pe.done.connect(() => {
218 print("print completed\n");
223 //pe.run_dialog(_this.el);
226 var list = Gtk.PaperSize.get_paper_sizes(false);
227 var psetup = new Gtk.PageSetup();
228 for(var i = 0; i < list.length(); i++ ) {
229 var entry = list.nth_data(i).copy();
230 if (entry.get_name() == "iso_a2") {
231 psetup.set_paper_size(entry);
237 pe.set_default_page_setup(psetup);
238 print("Calling Print?\n");
239 //pe.run_dialog(_this.el);
241 this.el.get_main_frame().print_full(pe,Gtk.PrintOperationAction.EXPORT);
250 public void printpng () {
251 //var filename = "/tmp/test.pdf";
252 //print("load_changed %d ?= %d\n", le, LoadEvent.FINISHED);
254 //if (le != LoadEvent.FINISHED) {
258 // what size is the documet.
260 print("making screenshot\n");
262 // fix vapi - get_snapshot add '?' to all null.
263 var pixmap = _this.view.el.get_snapshot( null );
269 // add out to gdkpixmap.get_size
270 pixmap.get_size( out w , out h);
271 var pixbuf = Gdk.pixbuf_get_from_drawable(null, pixmap, null , 0, 0, 0, 0, w, h);
272 print("pixbuf size: %d x %d\n ", w,h);
276 pixbuf.save(webkitpdf.opt_target_png, "png");
277 print("Saved to %s\n", webkitpdf.opt_target_png);
278 //view.get_snapshot.begin(WebKit.SnapshotRegion.FULL_DOCUMENT, WebKit.SnapshotOptions.NONE, null, (obj, res) => {
279 // var sf = view.get_snapshot.end(res);
281 // sf.write_to_png(Browser.opt_target_png);