diff dwt/browser/FilePickerFactory.d @ 298:eec6ddb07873

More xpcom/mozilla port
author John Reimer<terminal.node@gmail.com>
date Sun, 10 Aug 2008 22:25:43 -0700
parents 44258e0b6687
children 942da4b6558a
line wrap: on
line diff
--- a/dwt/browser/FilePickerFactory.d	Fri Aug 08 15:25:08 2008 +0200
+++ b/dwt/browser/FilePickerFactory.d	Sun Aug 10 22:25:43 2008 -0700
@@ -7,32 +7,34 @@
  *
  * Contributors:
  *     IBM Corporation - initial API and implementation
+ * Port to the D programming language:
+ *      John Reimer <terminal.node@gmail.com>
  *******************************************************************************/
 module dwt.browser.FilePickerFactory;
 
 import dwt.dwthelper.utils;
 
-import dwt.internal.C;
+//import dwt.internal.C;
 import dwt.internal.mozilla.XPCOM;
-import dwt.internal.mozilla.XPCOMObject;
+//import dwt.internal.mozilla.XPCOMObject;
 import dwt.internal.mozilla.nsID;
 import dwt.internal.mozilla.nsIFactory;
 import dwt.internal.mozilla.nsISupports;
 
-class FilePickerFactory {
-    XPCOMObject supports;
-    XPCOMObject factory;
+class FilePickerFactory : IFactory {
+    //XPCOMObject supports;
+    //XPCOMObject factory;
     int refCount = 0;
 
-FilePickerFactory () {
-    createCOMInterfaces ();
+this () {
+//   createCOMInterfaces ();
 }
 
-int AddRef () {
+nsrefcnt AddRef () {
     refCount++;
     return refCount;
 }
-
+/+
 void createCOMInterfaces () {
     /* Create each of the interfaces that this object implements */
     supports = new XPCOMObject (new int[] {2, 0, 0}) {
@@ -64,43 +66,48 @@
 int /*long*/ getAddress () {
     return factory.getAddress ();
 }
-
-int QueryInterface (int /*long*/ riid, int /*long*/ ppvObject) {
-    if (riid is 0 || ppvObject is 0) return XPCOM.NS_ERROR_NO_INTERFACE;
-    nsID guid = new nsID ();
-    XPCOM.memmove (guid, riid, nsID.sizeof);
++/
+nsresult QueryInterface (nsID* riid, void** ppvObject) {
+    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 (nsIFactory.NS_IFACTORY_IID)) {
-        XPCOM.memmove (ppvObject, new int /*long*/[] {factory.getAddress ()}, C.PTR_SIZEOF);
+    if (*riid == nsIFactory.IID) {
+        *ppvObject = cast(void*)cast(nsIFactory)this;
         AddRef ();
         return XPCOM.NS_OK;
     }
     
-    XPCOM.memmove (ppvObject, new int /*long*/[] {0}, C.PTR_SIZEOF);
+    *ppvObject = null;
     return XPCOM.NS_ERROR_NO_INTERFACE;
 }
 
-int Release () {
+nsrefcnt Release () {
     refCount--;
-    if (refCount is 0) disposeCOMInterfaces ();
+    //if (refCount is 0) disposeCOMInterfaces ();
     return refCount;
 }
     
 /* nsIFactory */
 
-int CreateInstance (int /*long*/ aOuter, int /*long*/ iid, int /*long*/ result) {
-    FilePicker picker = new FilePicker ();
-    picker.AddRef ();
-    XPCOM.memmove (result, new int /*long*/[] {picker.getAddress ()}, C.PTR_SIZEOF);
-    return XPCOM.NS_OK;
+nsresult CreateInstance (nsISupports aOuter, nsID* iid, void** result) { 
+     if (result is null) 
+        return XPCOM.NS_ERROR_INVALID_ARG;
+    auto picker = new FilePicker;
+    nsresult rv = picker.QueryInterface( iid, result );
+    if (XPCOM.NS_FAILED(rv)) {
+        *result = null;
+        delete picker;
+    }
+    return rv;
 }
 
-int LockFactory (int lock) {
+nsresult LockFactory (PRBool lock) {
     return XPCOM.NS_OK;
 }
 }