Hey,

On 9/6/05, Rafael Ferreira <[EMAIL PROTECTED]> wrote:
> Mario,
> 
> here's the updated patch. It took me some time to get this to you
> because I updated my docbrowser and monodoc sources so I had to merge
> the printing patch upstream. This time I basically edited the
> browser.glade file by hand, adding only the needed entries.
> 
> Let me know what you could use a hand with next.

I took your patch and worked a little bit with it. This are the things
I've changed:

- Since we already have an abstraction for separing Gecko and GtkHTML
with IHtmlRender and the two implementations (Gtk and Gecko), I've
moved all the printing logic to them, so we can get rif of
IPrintManager and GtkHTMLPrintManager. I do think is more sane now. I
have used a Print method only with a parameter, the html code, because
when using css, the html code returned by the HelpSource already has
the css.

- The print menu item is only clickable when you are not editing a node

- I've encountered problems because the two kinds of Url presents in
monodoc (with your patch, the browser crashed when printing a node
which was accesed through the treeview). I think now it works.

- The ecma provider was not tracking well the use_css variable. Now,
it will print the html according to it. (For the moment, everything
without css)

- I've left out the thing with gnome-stock-about and gtk-about because
I'm not sure it's really important now, try to open a bug in bugzilla.

By the way, I think the monodoc section of bugzilla is forgoten and
unmaintained. Miguel, can you give me permission to deal with it?

Comments?

Mario
Index: browser/ChangeLog
===================================================================
--- browser/ChangeLog	(revision 49472)
+++ browser/ChangeLog	(working copy)
@@ -1,3 +1,6 @@
+2005-09-08 Mario Sopena Novales <[EMAIL PROTECTED]>
+	* ecma-provider.cs: Track use_css better
+	
 2005-09-05 Mario Sopena Novales <[EMAIL PROTECTED]>
 	Implement basic searching capabilities
 	* provider.cs: 
Index: browser/ecma-provider.cs
===================================================================
--- browser/ecma-provider.cs	(revision 49472)
+++ browser/ecma-provider.cs	(working copy)
@@ -1024,20 +1024,26 @@
 		ecma_transform.Transform (ecma_xml, args, w, null);
 	}
 	
+	static XslTransform ecma_transform_css, ecma_transform_no_css;
 	static void EnsureTransform ()
 	{
 		if (ecma_transform == null) {
-			ecma_transform = new XslTransform ();
+			ecma_transform_css = new XslTransform ();
+			ecma_transform_no_css = new XslTransform ();
 			Assembly assembly = System.Reflection.Assembly.GetCallingAssembly ();
-			Stream stream;
-			if (use_css) 
-				stream = assembly.GetManifestResourceStream ("mono-ecma-css.xsl");
-			else 
-				stream = assembly.GetManifestResourceStream ("mono-ecma.xsl");
-
+			
+			Stream stream = assembly.GetManifestResourceStream ("mono-ecma-css.xsl");
 			XmlReader xml_reader = new XmlTextReader (stream);
-			ecma_transform.Load (xml_reader, null, null);
-		}
+			ecma_transform_css.Load (xml_reader, null, null);
+			
+			stream = assembly.GetManifestResourceStream ("mono-ecma.xsl");
+			xml_reader = new XmlTextReader (stream);
+			ecma_transform_no_css.Load (xml_reader, null, null);
+		}
+		if (use_css)
+			ecma_transform = ecma_transform_css;
+		else
+			ecma_transform = ecma_transform_no_css;
 	}
 
 	// This ExtensionObject stuff is used to check at run time whether
Index: docbrowser/IHtmlRender.cs
===================================================================
--- docbrowser/IHtmlRender.cs	(revision 48726)
+++ docbrowser/IHtmlRender.cs	(working copy)
@@ -32,6 +32,8 @@
 	string Url { get; }
 
 	Widget HtmlPanel { get; }
+
+	void Print (string Html);
 }
 
 
Index: docbrowser/GeckoHtmlRender.cs
===================================================================
--- docbrowser/GeckoHtmlRender.cs	(revision 49195)
+++ docbrowser/GeckoHtmlRender.cs	(working copy)
@@ -2,6 +2,7 @@
 // GeckoHtmlRender.cs: Implementation of IHtmlRender that uses Gecko
 //
 // Author: Mario Sopena
+// Author:	Rafael Ferreira <[EMAIL PROTECTED]>
 //
 using System;
 using System.Text;
@@ -9,6 +10,7 @@
 using System.Collections;
 using Gecko;
 using Gtk;
+using Gnome;
 
 namespace Monodoc {
 public class GeckoHtmlRender : IHtmlRender {
@@ -152,5 +154,43 @@
 		return html.ToString();
 	}
 
+	public void Print (string Html) {
+		
+		if (Html == null) {
+			Console.WriteLine ("empty print");
+			return;
+		}
+
+		string Caption = "Monodoc Printing";
+
+		PrintJob pj = new PrintJob (PrintConfig.Default ());
+		PrintDialog dialog = new PrintDialog (pj, Caption, 0);
+
+		Gtk.HTML gtk_html = new Gtk.HTML (Html);
+		gtk_html.PrintSetMaster (pj);
+			
+		PrintContext ctx = pj.Context;
+		gtk_html.Print (ctx);
+
+		pj.Close ();
+
+		// hello user
+		int response = dialog.Run ();
+		
+		if (response == (int) PrintButtons.Cancel) {
+			dialog.Hide ();
+			dialog.Dispose ();
+			return;
+		} else if (response == (int) PrintButtons.Print) {
+			pj.Print ();
+		} else if (response == (int) PrintButtons.Preview) {
+			new PrintJobPreview (pj, Caption).Show ();
+		}
+		
+		ctx.Close ();
+		dialog.Hide ();
+		dialog.Dispose ();
+		return;
+	}
 }
 }
Index: docbrowser/browser.cs
===================================================================
--- docbrowser/browser.cs	(revision 49473)
+++ docbrowser/browser.cs	(working copy)
@@ -124,6 +124,7 @@
 	[Glade.Widget] CheckMenuItem comments1;
 	[Glade.Widget] MenuItem postcomment;
 	[Glade.Widget] public MenuItem paste1;
+	[Glade.Widget] public MenuItem print;
 	public Notebook tabs_nb;
 	public Tab CurrentTab;
 	bool HoldCtrl;
@@ -333,8 +334,10 @@
 		if (CurrentTab.Tab_mode == Mode.Viewer) {
 			CurrentTab.history.ActivateCurrent();
 			paste1.Sensitive = false;
+			print.Sensitive = true;
 		} else {
 			paste1.Sensitive = true;
+			print.Sensitive = false;
 		}
 		
 		if (tree_browser.SelectedNode != CurrentTab.CurrentNode)
@@ -707,6 +710,33 @@
 	{
 		Application.Quit ();
 	}
+	void on_print_activate (object sender, EventArgs e) 
+	{
+		 // desactivate css temporary
+		 if (UseGecko)
+		 	HelpSource.use_css = false;
+		 
+		string url = CurrentUrl;
+		string html;
+		Node cur = CurrentTab.CurrentNode;
+		Node n; 
+
+		// deal with the two types of urls
+		if (cur.tree.HelpSource != null) {
+			html = cur.tree.HelpSource.GetText (url, out n);
+			if (html == null)
+				html = help_tree.RenderUrl (url, out n);
+		} else {
+			html = help_tree.RenderUrl (url, out n);
+		}
+
+		// sending Html to be printed. 
+		if (html != null)
+			CurrentTab.html.Print (html);
+
+		if (UseGecko)
+			HelpSource.use_css = true;
+	}
 
 	void OnCommentsActivate (object o, EventArgs args)
 	{
@@ -2222,10 +2252,12 @@
 		if (m == Mode.Viewer) {
 			this.Page = 0;
 			browser.paste1.Sensitive = false;
+			browser.print.Sensitive = true;
 			EditImg.Visible = false;
 		} else {
 			this.Page = 1;
 			browser.paste1.Sensitive = true;
+			browser.print.Sensitive = false;
 			EditImg.Visible = true;
 		}
 
Index: docbrowser/ChangeLog
===================================================================
--- docbrowser/ChangeLog	(revision 49473)
+++ docbrowser/ChangeLog	(working copy)
@@ -1,3 +1,19 @@
+2005-09-08 Rafael Ferreira <[EMAIL PROTECTED]>, Mario Sopena <[EMAIL PROTECTED]>
+
+	Landed monodoc's simple printing subsystem
+	
+	* IHtmlRender.cs: new Print method 
+	* GeckoHtmlRender.cs: implemented new Print method with GtkHtml widget
+	* GtkHtmlHtmlRender.cs: implemented Print method
+	* browser.cs: 
+		- add printing support
+		- activate/deactivate print menu item when in view/edit mode
+	* browser.glade: 
+		- Added print menu option 
+		- Update Contributors list
+	* Makefile.am:
+		- Fixed GeckoHtmlRender.dl.mdb clean up
+
 2005-09-05 Mario Sopena Novales <[EMAIL PROTECTED]>
 	Implement basic searching capabilities
 	* browser.cs:
Index: docbrowser/browser.glade
===================================================================
--- docbrowser/browser.glade	(revision 49473)
+++ docbrowser/browser.glade	(working copy)
@@ -91,6 +91,13 @@
 		      <accelerator key="U" modifiers="GDK_CONTROL_MASK" signal="activate"/>
 		    </widget>
 		  </child>
+		    <widget class="GtkImageMenuItem" id="print">
+		      <property name="visible">True</property>
+		      <property name="label">gtk-print</property>
+		      <property name="use_stock">True</property>
+		      <signal name="activate" handler="on_print_activate" last_modification_time="Tue, 30 Aug 2005 05:02:29 GMT"/>
+		    </widget>
+		  </child>
 
 		  <child>
 		    <widget class="GtkImageMenuItem" id="quit1">
@@ -1108,7 +1115,9 @@
    Piers Haken
    John Luke ([EMAIL PROTECTED])
    Ben Maurer
-Mario Sopena novales</property>
+   Mario Sopena Novales ([EMAIL PROTECTED])
+   Rafael Ferreira ([EMAIL PROTECTED])
+   </property>
 	      <property name="use_underline">False</property>
 	      <property name="use_markup">True</property>
 	      <property name="justify">GTK_JUSTIFY_LEFT</property>
Index: docbrowser/GtkHtmlHtmlRender.cs
===================================================================
--- docbrowser/GtkHtmlHtmlRender.cs	(revision 48726)
+++ docbrowser/GtkHtmlHtmlRender.cs	(working copy)
@@ -3,9 +3,11 @@
 // GtkHtmlHtmlRender.cs: Implementation of IHtmlRender that uses Gtk.HTML
 //
 // Author: Mario Sopena
+// Author:	Rafael Ferreira <[EMAIL PROTECTED]>
 //
 using System;
 using Gtk;
+using Gnome;
 using System.IO;
 
 namespace Monodoc {
@@ -88,5 +90,43 @@
 		args.Handle.Close (HTMLStreamStatus.Ok);
 	}
 	
+	public void Print (string Html) {
+		
+		if (Html == null) {
+			Console.WriteLine ("empty print");
+			return;
+		}
+
+		string Caption = "Monodoc Printing";
+
+		PrintJob pj = new PrintJob (PrintConfig.Default ());
+		PrintDialog dialog = new PrintDialog (pj, Caption, 0);
+
+		Gtk.HTML gtk_html = new Gtk.HTML (Html);
+		gtk_html.PrintSetMaster (pj);
+			
+		PrintContext ctx = pj.Context;
+		gtk_html.Print (ctx);
+
+		pj.Close ();
+
+		// hello user
+		int response = dialog.Run ();
+		
+		if (response == (int) PrintButtons.Cancel) {
+			dialog.Hide ();
+			dialog.Dispose ();
+			return;
+		} else if (response == (int) PrintButtons.Print) {
+			pj.Print ();
+		} else if (response == (int) PrintButtons.Preview) {
+			new PrintJobPreview (pj, Caption).Show ();
+		}
+		
+		ctx.Close ();
+		dialog.Hide ();
+		dialog.Dispose ();
+		return;
+	}
 }
 }
Index: docbrowser/Makefile.am
===================================================================
--- docbrowser/Makefile.am	(revision 48726)
+++ docbrowser/Makefile.am	(working copy)
@@ -3,7 +3,7 @@
 
 
 if ENABLE_GECKO
-CLEANFILES = browser.exe browser.exe.mdb admin.exe admin.exe.mdb GeckoHtmlRender.dll 
+CLEANFILES = browser.exe browser.exe.mdb admin.exe admin.exe.mdb GeckoHtmlRender.dll GeckoHtmlRender.dll.mdb
 monodoc_DATA = browser.exe GeckoHtmlRender.dll 
 else
 CLEANFILES = browser.exe browser.exe.mdb admin.exe admin.exe.mdb 
_______________________________________________
Mono-docs-list maillist  -  Mono-docs-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-docs-list

Reply via email to