Index: browser.cs
===================================================================
--- browser.cs	(revision 38975)
+++ browser.cs	(working copy)
@@ -10,8 +10,17 @@
 //   Add support for printing.
 //   Add search facility
 //
+#if WIN32
+#define GECKO
+using Microsoft.Win32;
+using System.Runtime.InteropServices;
+//Force GECKO on Win32
+#endif
 using Gtk;
 using Glade;
+#if GECKO
+using Gecko;
+#endif
 using System;
 using System.IO;
 using System.Reflection;
@@ -21,8 +30,47 @@
 
 namespace Monodoc {
 class Driver {
+#if WIN32
+	[DllImport("kernel32.dll", SetLastError=true)]
+	public static extern bool SetEnvironmentVariable( string lpName, string lpValue );
+#endif
+	
 	static int Main (string [] args)
 	{
+#if WIN32
+		string pathVar = System.Environment.GetEnvironmentVariable("path");
+		string grePath = "";
+		try 
+		{
+			//Open the key where the GRE is stored
+			RegistryKey regKey = Registry.LocalMachine.OpenSubKey("SOFTWARE").OpenSubKey("mozilla.org").OpenSubKey("GRE");
+			//Lets go ahead and check for gtkembedmoz.dll
+			//We need to open the key for each version and check its ones install directory
+			foreach (String keyName in regKey.GetSubKeyNames())
+			{
+				RegistryKey subKey = regKey.OpenSubKey(keyName);
+				grePath = (string)subKey.GetValue("GreHome");
+				string[] files = System.IO.Directory.GetFiles(grePath,"gtkembedmoz.dll");
+				if (files.Length > 0) // We must have found the right dll here.
+					pathVar = grePath +  ";" + pathVar;
+#if DEBUG
+				Console.WriteLine("Checked the path: {0}", grePath);
+				Console.WriteLine("Current path variable is: {0}", pathVar);
+#endif				
+			}
+		}
+		catch(System.Exception regException)
+		{
+			
+#if DEBUG
+			Console.WriteLine("ERROR IN LOADING GRE PATH: \n{0}", regException.ToString());
+			
+#endif
+			
+		}
+		SetEnvironmentVariable("path",pathVar);
+		WebControl.CompPath = grePath;
+#endif
 		string topic = null;
 		
 		for (int i = 0; i < args.Length; i++){
@@ -91,12 +139,16 @@
 		SettingsHandler.CheckUpgrade ();
 		
 		Settings.RunningGUI = true;
+#if !GECKO
 		Application.Init ();
+#endif
 		Browser browser = new Browser ();
 		
 		if (topic != null)
 			browser.LoadUrl (topic);
+#if !GECKO
 		Application.Run ();
+#endif
 		return 0;
 	}
 }
@@ -145,12 +197,19 @@
 
 	public History history;
 
+#if !GECKO
 	// Where we render the contents
 	HTML html;
 
 	// Our HTML preview during editing.
 	HTML html_preview;
+#else
+	// Where we render the contents
+	WebControl html;
 
+	// Our HTML preview during editing.
+	WebControl html_preview;
+#endif
         //
 	// Left-hand side Browsers
 	//
@@ -179,6 +238,9 @@
 
 	public Browser ()
 	{
+#if GECKO
+		Application.Init ();
+#endif
 		ui = new Glade.XML (null, "browser.glade", "window1", null);
 		ui.Autoconnect (this);
 
@@ -221,21 +283,56 @@
 		//
 		// Setup the HTML rendering area
 		//
+#if !GECKO
 		html = new HTML ();
+#else
+#if !WIN32
+		html = new WebControl("/tmp/monodoc", "MonoDoc");
+#else
+		// TODO: FIX HACK
+		// HACK: Hack for profiling issues. Might later 
+		// prepend something in the gecko# code later
+		html = new WebControl("/tmp/monodoc" + 
+				System.Guid.NewGuid().ToString("N"), 
+				"MonoDoc");
+#endif
+#endif
 		html.Show ();
+#if !GECKO
 		html_container.Add (html);
                 html.LinkClicked += new LinkClickedHandler (LinkClicked);
 		html.OnUrl += new OnUrlHandler (OnUrlMouseOver);
 		html.UrlRequested += new UrlRequestedHandler (UrlRequested);
+#else
+		//VBox mybox = new VBox (true, 1);
+		//mybox.PackStart(html,false,false,1);
+		
+		html_container.AddWithViewport(html);
+		html.OpenUri += new OpenUriHandler (LinkClicked);
+		html.LinkMsg += new EventHandler (OnUrlMouseOver);
+#endif
 		context_id = statusbar.GetContextId ("");
 
 		//
 		// Text editor (for editing the documentation).
 		//
 		html_and_editor_notebook.ShowTabs = false;
+#if !GECKO
 		html_preview = new HTML ();
+#else
+#if !WIN32
+		html_preview = new WebControl("/tmp/monodoc_preview", "MonoDoc");
+#else
+		// TODO: FIX HACK
+		// HACK: Hack for profiling issues. Might later 
+		// prepend something in the gecko# code later
+		html_preview = new WebControl("/tmp/monodoc_preview" + 
+				System.Guid.NewGuid().ToString("N"), 
+				"MonoDoc");
+#endif
+#endif
 		html_preview.Show ();
-		html_preview_container.Add (html_preview);
+		html_preview_container.AddWithViewport (html_preview);
 
 		text_editor.Buffer.Changed += new EventHandler (EditedTextChanged);
 		text_editor.WrapMode = WrapMode.Word;
@@ -256,6 +353,9 @@
 			Render (s, match, "root:");
 			history.AppendHistory (new Browser.LinkPageVisit (this, "root:"));
 		}
+#if GECKO
+		Application.Run ();
+#endif
 	}
 
 	public enum Mode {
@@ -301,6 +401,7 @@
 		return s;
 	}
 
+#if !GECKO
 	void UrlRequested (object sender, UrlRequestedArgs args)
 	{
 		Console.WriteLine ("Image requested: " + args.Url);
@@ -316,6 +417,7 @@
 		}
 		args.Handle.Close (HTMLStreamStatus.Ok);
 	}
+#endif
 	
 	public class LinkPageVisit : PageVisit {
 		Browser browser;
@@ -336,9 +438,23 @@
 		}
 	}
 	
+#if !GECKO
 	void LinkClicked (object o, LinkClickedArgs args)
+#else
+	void LinkClicked (object o, OpenUriArgs args)
+#endif	
 	{
+#if !GECKO
 		LoadUrl (args.Url);
+#else
+		LoadUrl (args.AURI);
+		// Mozilla needs a TRUE return value here.
+		// This stops Gecko from processing the URI
+		// Note, this needs fixing.  Should return a bool
+		// type, not an int.  Argh!
+		//SignalArgs sa = (SignalArgs) args;
+		//sa.RetVal = 1;
+#endif
 	}
 
 	private System.Xml.XmlNode edit_node;
@@ -349,7 +465,9 @@
 		if (url.StartsWith("#"))
 		{
 			// FIXME: This doesn't deal with whether anchor jumps should go in the history
+#if !GECKO
 			html.JumpToAnchor(url.Substring(1));
+#endif
 			return;
 		}
 
@@ -391,13 +509,25 @@
 	public void Render (string text, Node matched_node, string url)
 	{
 		CurrentUrl = url;
-
+#if !GECKO
 		Gtk.HTMLStream stream = html.Begin ("text/html");
-
 		stream.Write ("<html><body>");
 		stream.Write (text);
 		stream.Write ("</body></html>");
+#endif
+
+#if GECKO
+		string hdr = "<html><title></title><body>";
+		string ftr = "</body></html>";
+
+		html.OpenStream("file://", "text/html");
+		html.AppendData(hdr);//, (uint)hdr.Length);
+		html.AppendData(text);//, (uint)text.Length);
+		html.AppendData(ftr);//, (uint)ftr.Length);
+		html.CloseStream();
+#else	
 		html.End (stream, HTMLStreamStatus.Ok);
+#endif
 		if (matched_node != null) {
 			if (tree_browser.SelectedNode != matched_node)
 				tree_browser.ShowNode (matched_node);
@@ -426,10 +556,17 @@
 	// Invoked when the mouse is over a link
 	//
 	string last_url = "";
+#if !GECKO
 	void OnUrlMouseOver (object o, OnUrlArgs args)
+#else
+	void OnUrlMouseOver (object o, EventArgs args)
+#endif
 	{
+#if !GECKO
 		string new_url = args.Url;
-
+#else
+		string new_url = html.LinkMessage;
+#endif
 		if (new_url == null)
 			new_url = "";
 		
@@ -573,12 +710,16 @@
 	//
 	void OnCopyActivate (object sender, EventArgs a)
 	{
+#if !GECKO
 		if (BrowserMode == Mode.Viewer)
 			html.Copy ();
 		else {
+#endif
 			Clipboard cb = Clipboard.Get (Gdk.Selection.Clipboard);
 			text_editor.Buffer.CopyClipboard (cb);
+#if !GECKO
 		}
+#endif
 	}
 
 	//
@@ -1110,7 +1251,9 @@
 	//
 	void OnSelectAllActivate (object sender, EventArgs a)
 	{
+#if !GECKO
 		html.SelectAll ();
+#endif	
 	}
 
 	void BookmarkHandle (object obj, EventArgs args)
@@ -1240,9 +1383,16 @@
 		}
 		statusbar.Pop (context_id);
 		statusbar.Push (context_id, "XML OK");
+#if !GECKO
 		Gtk.HTMLStream s = html_preview.Begin ("text/html");
 		s.Write (sw.ToString ());
 		html_preview.End (s, HTMLStreamStatus.Ok);
+#else
+		html.OpenStream("file://", "text/html");
+		html.AppendData(sw.ToString());
+		html.CloseStream();
+#endif
+		
 	}
 
 	class BookmarkEdit {
