Mercurial > projects > dwt-linux
changeset 303:b72d84d1ba95
2 of 3 remaining modules to port before cyclical cleanup phase begins
author | John Reimer<terminal.node@gmail.com> |
---|---|
date | Wed, 13 Aug 2008 18:49:58 -0700 |
parents | bfe1c57259e3 |
children | 16ba3d9cb209 |
files | dwt/browser/PromptService2.d dwt/browser/WindowCreator2.d |
diffstat | 2 files changed, 60 insertions(+), 50 deletions(-) [+] |
line wrap: on
line diff
--- a/dwt/browser/PromptService2.d Tue Aug 12 21:11:17 2008 -0700 +++ b/dwt/browser/PromptService2.d Wed Aug 13 18:49:58 2008 -0700 @@ -557,7 +557,7 @@ //result2[0] = 0; //byte[] aContractID = MozillaDelegate.wcsToMbcs (null, XPCOM.NS_MEMORY_CONTRACTID, true); nsIMemory memory; - rc = serviceManager.GetServiceByContractID (XPCOM.NS_MEMORY_CONTRACTID, nsIMemory.NS_IMEMORY_IID, cast(void**)&memory); + rc = serviceManager.GetServiceByContractID (XPCOM.NS_MEMORY_CONTRACTID, nsIMemory.IID, cast(void**)&memory); if (rc !is XPCOM.NS_OK) DWT.error (rc); if (memory is null) DWT.error (XPCOM.NS_NOINTERFACE); serviceManager.Release (); @@ -589,7 +589,7 @@ //result2[0] = 0; //byte[] aContractID = MozillaDelegate.wcsToMbcs (null, XPCOM.NS_MEMORY_CONTRACTID, true); nsIMemory memory; - rc = serviceManager.GetServiceByContractID (XPCOM.NS_MEMORY_CONTRACTID, nsIMemory.NS_IMEMORY_IID, cast(void**)&memory); + rc = serviceManager.GetServiceByContractID (XPCOM.NS_MEMORY_CONTRACTID, nsIMemory.IID, cast(void**)&memory); if (rc !is XPCOM.NS_OK) DWT.error (rc); if (memory is null) DWT.error (XPCOM.NS_NOINTERFACE); serviceManager.Release ();
--- a/dwt/browser/WindowCreator2.d Tue Aug 12 21:11:17 2008 -0700 +++ b/dwt/browser/WindowCreator2.d Wed Aug 13 18:49:58 2008 -0700 @@ -47,27 +47,27 @@ } nsresult QueryInterface (nsID* riid, void** ppvObject) { - if (riid is 0 || ppvObject is 0) return XPCOM.NS_ERROR_NO_INTERFACE; - nsID guid = new nsID (); - XPCOM.memmove (guid, riid, nsID.sizeof); + if (riid is null || ppvObject is null) return XPCOM.NS_ERROR_NO_INTERFACE; + //nsID guid = new nsID (); + //XPCOM.memmove (guid, riid, nsID.sizeof); - if (guid.Equals (nsISupports.NS_ISUPPORTS_IID)) { - XPCOM.memmove (ppvObject, new int /*long*/[] {supports.getAddress ()}, C.PTR_SIZEOF); + if (*riid == nsISupports.IID) { + *ppvObject = cast(void*)cast(nsISupports)this; AddRef (); return XPCOM.NS_OK; } - if (guid.Equals (nsIWindowCreator.NS_IWINDOWCREATOR_IID)) { - XPCOM.memmove (ppvObject, new int /*long*/[] {windowCreator.getAddress ()}, C.PTR_SIZEOF); + if (*riid == nsIWindowCreator.IID) { + *ppvObject = cast(void*)cast(nsIWindowCreator)this; AddRef (); return XPCOM.NS_OK; } - if (guid.Equals (nsIWindowCreator2.NS_IWINDOWCREATOR2_IID)) { - XPCOM.memmove (ppvObject, new int /*long*/[] {windowCreator2.getAddress ()}, C.PTR_SIZEOF); + if (*riid == nsIWindowCreator2.IID) { + *ppvObject == cast(void*)cast(nsIWindowCreator2)this; AddRef (); return XPCOM.NS_OK; } - XPCOM.memmove (ppvObject, new int /*long*/[] {0}, C.PTR_SIZEOF); + *ppvObject = null; return XPCOM.NS_ERROR_NO_INTERFACE; } @@ -79,40 +79,40 @@ /* nsIWindowCreator */ -int CreateChromeWindow (int /*long*/ parent, int chromeFlags, int /*long*/ _retval) { - return CreateChromeWindow2 (parent, chromeFlags, 0, 0, 0, _retval); +nsresult CreateChromeWindow (nsIWebBrowserChrome parent, PRUint32 chromeFlags, nsIWebBrowserChrome* _retval) { + return CreateChromeWindow2 (parent, chromeFlags, 0, null, null, _retval); } /* nsIWindowCreator2 */ -int CreateChromeWindow2 (int /*long*/ parent, int chromeFlags, int contextFlags, int /*long*/ uri, int /*long*/ cancel, int /*long*/ _retval) { - if (parent is 0 && (chromeFlags & nsIWebBrowserChrome.CHROME_OPENAS_CHROME) is 0) { +nsresult CreateChromeWindow2 (nsIWebBrowserChrome parent, PRUint32 chromeFlags, PRUint32 contextFlags, nsIURI uri, PRBool* cancel, nsIWebBrowserChrome* _retval) { + if (parent is null && (chromeFlags & nsIWebBrowserChrome.CHROME_OPENAS_CHROME) is 0) { return XPCOM.NS_ERROR_NOT_IMPLEMENTED; } Browser src = null; - if (parent !is 0) { - nsIWebBrowserChrome browserChromeParent = new nsIWebBrowserChrome (parent); - int /*long*/[] aWebBrowser = new int /*long*/[1]; - int rc = browserChromeParent.GetWebBrowser (aWebBrowser); + if (parent !is null) { + //nsIWebBrowserChrome browserChromeParent = new nsIWebBrowserChrome (parent); + nsIWebBrowser webBrowser; + int rc = parent.GetWebBrowser (&webBrowser); if (rc !is XPCOM.NS_OK) Mozilla.error (rc); - if (aWebBrowser[0] is 0) Mozilla.error (XPCOM.NS_ERROR_NO_INTERFACE); + if (webBrowser is null) Mozilla.error (XPCOM.NS_ERROR_NO_INTERFACE); - nsIWebBrowser webBrowser = new nsIWebBrowser (aWebBrowser[0]); - int /*long*/[] result = new int /*long*/[1]; - rc = webBrowser.QueryInterface (nsIBaseWindow.NS_IBASEWINDOW_IID, result); + //nsIWebBrowser webBrowser = new nsIWebBrowser (aWebBrowser[0]); + nsIBaseWindow baseWindow; + rc = webBrowser.QueryInterface (nsIBaseWindow.IID, cast(void**)&baseWindow); if (rc !is XPCOM.NS_OK) Mozilla.error (rc); - if (result[0] is 0) Mozilla.error (XPCOM.NS_ERROR_NO_INTERFACE); + if (baseWindow is null) Mozilla.error (XPCOM.NS_ERROR_NO_INTERFACE); webBrowser.Release (); - nsIBaseWindow baseWindow = new nsIBaseWindow (result[0]); - result[0] = 0; - int /*long*/[] aParentNativeWindow = new int /*long*/[1]; - rc = baseWindow.GetParentNativeWindow (aParentNativeWindow); + //nsIBaseWindow baseWindow = new nsIBaseWindow (result[0]); + //result[0] = 0; + nativeWindow aParentNativeWindow; // nativeWindow is "void*" (represents GtkWidget*) + rc = baseWindow.GetParentNativeWindow (&aParentNativeWindow); if (rc !is XPCOM.NS_OK) Mozilla.error (rc); - if (aParentNativeWindow[0] is 0) Mozilla.error (XPCOM.NS_ERROR_NO_INTERFACE); + if (aParentNativeWindow is null) Mozilla.error (XPCOM.NS_ERROR_NO_INTERFACE); baseWindow.Release (); - src = Mozilla.findBrowser (aParentNativeWindow[0]); + src = Mozilla.findBrowser (aParentNativeWindow); } final Browser browser; bool doit = true; @@ -146,16 +146,16 @@ shell.close (); } }); - if (uri !is 0) { - nsIURI location = new nsIURI (uri); - int /*long*/ aSpec = XPCOM.nsEmbedCString_new (); - if (location.GetSpec (aSpec) is XPCOM.NS_OK) { - int length = XPCOM.nsEmbedCString_Length (aSpec); - if (length > 0) { - int /*long*/ buffer = XPCOM.nsEmbedCString_get (aSpec); - byte[] dest = new byte[length]; - XPCOM.memmove (dest, buffer, length); - browser.setUrl (new String (dest)); + if (uri !is null) { + //nsIURI location = new nsIURI (uri); + scope auto aSpec = new nsEmbedCString; + if (uri.GetSpec (cast(nsACString*)aSpec) is XPCOM.NS_OK) { + int span = aSpec.toString().length; + if (span > 0) { + //int /*long*/ buffer = XPCOM.nsEmbedCString_get (aSpec); + // byte[] dest = new byte[length]; + //XPCOM.memmove (dest, buffer, length); + browser.setUrl (aSpec.toString); } } XPCOM.nsEmbedCString_delete (aSpec); @@ -174,21 +174,31 @@ doit = browser !is null && !browser.isDisposed (); if (doit) { String platform = Platform.PLATFORM; - bool isMozillaNativePlatform = platform.equals ("gtk") || platform.equals ("motif"); //$NON-NLS-1$ //$NON-NLS-2$ + bool isMozillaNativePlatform = platform == "gtk" || platform == "motif"; //$NON-NLS-1$ //$NON-NLS-2$ doit = isMozillaNativePlatform || (browser.getStyle () & DWT.MOZILLA) !is 0; } } if (doit) { - Mozilla mozilla = (Mozilla)browser.webBrowser; + // STRANGE but TRUE: browser.webBrowser is always instantiated as Mozilla (on this platform), + // so it can be cast back to the subclass Mozilla safely. Looks very dangerous, though... + // considering the next few lines of code that cast the Mozilla class to the interface, + // nsIWebBrowserChrome. + // This is an ugly D conversion hack because interfaces are implemented differently than + // in the Java SWT version. Watch this code section carefully for errors/bugs. -JJR + Mozilla mozilla = cast(Mozilla)browser.webBrowser; mozilla.isChild = true; - int /*long*/ chromePtr = mozilla.webBrowserChrome.getAddress (); - nsIWebBrowserChrome webBrowserChrome = new nsIWebBrowserChrome (chromePtr); - webBrowserChrome.SetChromeFlags (chromeFlags); - webBrowserChrome.AddRef (); - XPCOM.memmove (_retval, new int /*long*/[] {chromePtr}, C.PTR_SIZEOF); + // And since Mozilla class implements the nsIWebBrowserChrome interface.... + nsIWebBrowserChrome chrome; + nsresult rc = mozilla.QueryInterface( nsIWebBrowserChrome.IID, cast(void**)&chrome); + if (rc !is XPCOM.NS_OK) Mozilla.error (rc); + //nsIWebBrowserChrome webBrowserChrome = new nsIWebBrowserChrome (chromePtr); + chrome.SetChromeFlags (chromeFlags); + //chrome.AddRef (); + //XPCOM.memmove (_retval, new int /*long*/[] {chromePtr}, C.PTR_SIZEOF); + *_retval = chrome; } else { - if (cancel !is 0) { - C.memmove (cancel, new int[] {1}, 4); /* PRBool */ + if (cancel !is null) { + *cancel = 1; /* PRBool */ } } return doit ? XPCOM.NS_OK : XPCOM.NS_ERROR_NOT_IMPLEMENTED;