On Mar 12, 7:29 pm, "Grant Gayed" <[EMAIL PROTECTED]> wrote:
> If you want to do this with swt's Browser:
> - requires:
>   - xulrunner 1.8.1.2 (I see that you have this already)
>   - a very recent 3.3 stream swt 
> (eg.-http://download.eclipse.org/downloads/drops/I20070306-1200/index.php)
>
> Example snippet:
>
> import org.eclipse.swt.SWT;
> import org.eclipse.swt.browser.Browser;
> import org.eclipse.swt.widgets.*;
> import org.mozilla.interfaces.*;
>
> public class Main {
>     public static void main(String [] args) {
>         System.setProperty(
>             "org.eclipse.swt.browser.XULRunnerPath",
>             <stringPathToYourXULRunner1812install>);
>         Display display = new Display();
>         final Shell shell = new Shell(display);
>         shell.setBounds(10,10,400,400);
>         final Browser browser = new Browser(shell, SWT.MOZILLA);
>         browser.setUrl("http://www.google.ca";);
>         browser.setBounds(10,10,300,300);
>         Button button = new Button(shell, SWT.PUSH);
>         button.setBounds(10,330,360,30);
>         button.setText("Push to turn on design mode");
>         button.addListener(SWT.Selection, new Listener() {
>             public void handleEvent(Event event) {
>                 nsIWebBrowser webBrowser =
> (nsIWebBrowser)browser.getWebBrowser();
>                 if (webBrowser == null) {
>                     System.out.println("Could not get the nsIWebBrowser from
> the Browser widget");
>                     return;
>                 }
>                 nsIDOMWindow window = webBrowser.getContentDOMWindow();
>                 nsIDOMDocument document = window.getDocument();
>                 nsIDOMNSHTMLDocument nsDocument =
> (nsIDOMNSHTMLDocument)document.queryInterface(nsIDOMNSHTMLDocument.NS_IDOMNS
> HTMLDOCUMENT_IID);
>                 nsDocument.setDesignMode("on");
>             }
>         });
>         shell.open();
>         while (!shell.isDisposed()) {
>             if (!display.readAndDispatch()) display.sleep();
>         }
>         display.dispose();
>     }
>
> }
>
> Note that the first line (the System.setProperty) is a temporary measure to
> ensure that an earlier XULRunner is not picked up by the Browser (if an
> earlier one is found then the browser.getWebBrowser() call will answer
> null).  You don't need this first line if your XULRunner 1.8.1.2 is properly
> registered with the system  and you don't have an earlier XULRunner
> installed.
>
> Grant
>
> "krithika" <[EMAIL PROTECTED]> wrote in message
>
> news:[EMAIL PROTECTED]
>
> > On Mar 8, 8:49 am, "timeless" <[EMAIL PROTECTED]> wrote:
> > > On Mar 7, 2:46 pm, "krithika" <[EMAIL PROTECTED]> wrote:
>
> > > > Hi folks,
>
> > > > We are trying to embed gecko from java using javaxpcom in Linux.I have
> > > > not been successful so far.
>
> > > > We do a JNI call which create a GTKWidget as shown below.This
> > > > GtkWidget handle is being given to baseWindow.initWindow from my java
> > > > code.
>
> > > > This is not working?
>
> > > > Can someone throw some light as to whether this is possible in the
> > > > first place.
>
> > > > gtk_init(NULL,NULL);
> > > >  window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
> > > >  /*-- Display the window --*/
> > > > gtk_widget_realize(window);
> > > >  area=gtk_hbox_new (FALSE, 10);
> > > >  gtk_container_add(GTK_CONTAINER(window),area);
> > > >  gtk_widget_realize(area);
> > > >  gtk_widget_show(area);
> > > >  gtk_main();
>
> > > > and return area to the java code via JNI.
>
> > > I don't understand your use of gtk_main()
>
> > >http://mxr.landfill.bugzilla.org/gnome/source/libgtk-java/src/java/or...
>
> > > Seems to indicate you're using it wrong. And given that
> > > java.org.gnu.gtk.Gtk exists, I have to ask why you don't just use it.
>
> > I just moved on to try swt package for gettting baseWindow handle.But
> > webNavigation is not happening.This is what I have done.Using
> > xulrunner1.8.1.2 jars / eclipse3.2.2 and swt package.
>
> >         Display display = new Display();
> > Shell shell = new Shell(display);
> > shell.setBounds(300, 300, 300, 300);
> > shell.setText("Main Window");
> > TestGTK gtk =  new TestGTK(shell,SWT.EMBEDDED);
> > gtk.initDisplay(shell);
>
> > shell.open();
> > gtk.test();
> > while (!shell.isDisposed())
> > {
> > if (!display.readAndDispatch())
> > display.sleep();
> > }
>
> > display.dispose();
>
> > }
> > void initDisplay(Composite parent)
> > {
> >     Display display = parent.getDisplay();
> >     display.setData(NO_INPUT_METHOD, null);
> > }
>
> > public void test()
> > {
> >                        // gre initialization
> > Mozilla mozilla = Mozilla.getInstance();
> > mozilla.initialize(grePath);
> > mozilla.initEmbedding(grePath, grePath, locProvider);
> > componentManager =mozilla.getComponentManager();
> > System.out.println("Step0: componentManager "+componentManager);
>
> > serviceManager = mozilla.getServiceManager();
> > System.out.println("Step1: serviceManager "+serviceManager);
>
> > proxy =
>
> (nsIProxyObjectManager)componentManager.createInstanceByContractID("@mozilla
> .org/> xpcomproxy;1",null,nsIProxyObjectManager.NS_IPROXYOBJECTMANAGER_IID);
>
> > appStartup
> > =(nsIAppStartup)serviceManager.getServiceByContractID("@mozilla.org/
> > toolkit/app-startup;1",nsIAppStartup.NS_IAPPSTARTUP_IID);
> > System.out.println("Step2: nsIAppStartup appStartup =
> > "+appStartup);
>
> > nsIWindowCreator windowCreator
>
> =(nsIWindowCreator)appStartup.queryInterface(nsIWindowCreator.NS_IWINDOWCREA
> TOR_IID);
>
> > System.out.println("Step3: nsIWindowCreator windowCreator
> > ="+windowCreator);
>
> > windowWatcher =
> > (nsIWindowWatcher)serviceManager.getServiceByContractID("@mozilla.org/
> > embedcomp/window-watcher;1", nsIWindowWatcher.NS_IWINDOWWATCHER_IID);
> > System.out.println("Step4: nsIWindowWatcher windowWatcher
> > ="+windowWatcher);
>
> > windowWatcher.setWindowCreator(windowCreator);
> > System.out.println("Step5: setWindowCreator(windowCreator)");
>
> > browser =
> > (nsIWebBrowser)componentManager.createInstanceByContractID("@mozilla.org/
> > embedding/browser/nsWebBrowser;
> > 1",null,nsIWebBrowser.NS_IWEBBROWSER_IID);
> > System.out.println("Step6: nsIWebBrowser "+browser);
>
> > int hwnd = createWindowHandle();
> > System.out.println("createWindowHandle "+hwnd);
> > nsIBaseWindow baseWindow = (nsIBaseWindow)
>
> > browser.queryInterface(nsIBaseWindow.NS_IBASEWINDOW_IID);
> >         baseWindow.initWindow(hwnd, 0, 0, 0, 1024, 768);
> > baseWindow.create();
> > baseWindow.setVisibility(true);
>
> > webNavigation = (nsIWebNavigation)
> > browser.queryInterface(nsIWebNavigation.NS_IWEBNAVIGATION_IID);
> > System.out.println("Step8: nsIWebNavigation "+webNavigation);
>
> > webNavigation.loadURI(urlToLoad,nsIWebNavigation.LOAD_FLAGS_NONE,
> > null, null, null);
> > System.out.println("Step9: nsIWebNavigation url "+urlToLoad);
> > listener=new WebProgressListener();
> > progress=
> > (nsIWebProgress)serviceManager.getServiceByContractID("@mozilla.org/
> > docloaderservice;1", nsIWebProgress.NS_IWEBPROGRESS_IID);
> > System.out.println("Step7: nsIWebProgress "+progress);
>
> progress.addProgressListener((nsIWebProgressListener)listener,nsIWebProgress
> .NOTIFY_ALL);
>
>
>
>
>
> > System.out.println("Step7: nsIWebProgressListener added ");
>
> > //appStartup.run();
>
> > }
>
> > int createWindowHandle()
> > {
> > String osname=System.getProperty("os.name");
> > System.out.println("osname "+osname);
> >           int embed_handle = OS.gtk_hbox_new (false, 0);
> >         OS.gtk_container_add (this.handle, embed_handle);
> >         OS.gtk_widget_show (embed_handle);
> >        return embed_handle;
> > }
>
> > Need help.I have no exceptions or errors.
>
> > regards,
> > Krith

Thanks for your inputs.I just created a GTKWindow and passed
gtkwidget* via JNI to my java code and everything works fine now.

regards,
Krith

_______________________________________________
dev-embedding mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-embedding

Reply via email to