Mercurial > projects > dwt-linux
comparison dwt/browser/PromptService2Factory.d @ 302:bfe1c57259e3
More browser code ported
author | John Reimer<terminal.node@gmail.com> |
---|---|
date | Tue, 12 Aug 2008 21:11:17 -0700 |
parents | 93409d9838c5 |
children | 942da4b6558a |
comparison
equal
deleted
inserted
replaced
301:d1474e6bb509 | 302:bfe1c57259e3 |
---|---|
5 * which accompanies this distribution, and is available at | 5 * which accompanies this distribution, and is available at |
6 * http://www.eclipse.org/legal/epl-v10.html | 6 * http://www.eclipse.org/legal/epl-v10.html |
7 * | 7 * |
8 * Contributors: | 8 * Contributors: |
9 * IBM Corporation - initial API and implementation | 9 * IBM Corporation - initial API and implementation |
10 * Port to the D programming language: | |
11 * John Reimer <terminal.node@gmail.com> | |
10 *******************************************************************************/ | 12 *******************************************************************************/ |
11 module dwt.browser.PromptService2Factory; | 13 module dwt.browser.PromptService2Factory; |
12 | 14 |
13 import dwt.dwthelper.utils; | 15 //import dwt.dwthelper.utils; |
14 | 16 |
15 import dwt.internal.C; | 17 //import dwt.internal.C; |
16 import dwt.internal.mozilla.XPCOM; | 18 import dwt.internal.mozilla.XPCOM; |
17 import dwt.internal.mozilla.XPCOMObject; | 19 //import dwt.internal.mozilla.XPCOMObject; |
18 import dwt.internal.mozilla.nsID; | 20 import dwt.internal.mozilla.nsID; |
19 import dwt.internal.mozilla.nsIFactory; | 21 import dwt.internal.mozilla.nsIFactory; |
20 import dwt.internal.mozilla.nsISupports; | 22 import dwt.internal.mozilla.nsISupports; |
23 import dwt.browser.PromptService2; | |
21 | 24 |
22 class PromptService2Factory { | 25 class PromptService2Factory : nsIFactory { |
23 XPCOMObject supports; | 26 // XPCOMObject supports; |
24 XPCOMObject factory; | 27 // XPCOMObject factory; |
25 int refCount = 0; | 28 int refCount = 0; |
26 | 29 |
27 PromptService2Factory () { | 30 this () { |
28 createCOMInterfaces (); | 31 // createCOMInterfaces (); |
29 } | 32 } |
30 | 33 |
31 int AddRef () { | 34 nsrefcnt AddRef () { |
32 refCount++; | 35 refCount++; |
33 return refCount; | 36 return refCount; |
34 } | 37 } |
35 | 38 |
36 void createCOMInterfaces () { | 39 nsresult QueryInterface (nsID* riid, void** ppvObject) { |
37 /* Create each of the interfaces that this object implements */ | 40 if (riid is null || ppvObject is null) return XPCOM.NS_ERROR_NO_INTERFACE; |
38 supports = new XPCOMObject (new int[] {2, 0, 0}) { | 41 //nsID guid = new nsID (); |
39 public int /*long*/ method0 (int /*long*/[] args) {return QueryInterface (args[0], args[1]);} | 42 //XPCOM.memmove (guid, riid, nsID.sizeof); |
40 public int /*long*/ method1 (int /*long*/[] args) {return AddRef ();} | |
41 public int /*long*/ method2 (int /*long*/[] args) {return Release ();} | |
42 }; | |
43 | 43 |
44 factory = new XPCOMObject (new int[] {2, 0, 0, 3, 1}) { | 44 if (*riid == nsISupports.IID) { |
45 public int /*long*/ method0 (int /*long*/[] args) {return QueryInterface (args[0], args[1]);} | 45 *ppvObject = cast(void*)cast(nsISupports)this; |
46 public int /*long*/ method1 (int /*long*/[] args) {return AddRef ();} | |
47 public int /*long*/ method2 (int /*long*/[] args) {return Release ();} | |
48 public int /*long*/ method3 (int /*long*/[] args) {return CreateInstance (args[0], args[1], args[2]);} | |
49 public int /*long*/ method4 (int /*long*/[] args) {return LockFactory ((int)/*64*/args[0]);} | |
50 }; | |
51 } | |
52 | |
53 void disposeCOMInterfaces () { | |
54 if (supports !is null) { | |
55 supports.dispose (); | |
56 supports = null; | |
57 } | |
58 if (factory !is null) { | |
59 factory.dispose (); | |
60 factory = null; | |
61 } | |
62 } | |
63 | |
64 int /*long*/ getAddress () { | |
65 return factory.getAddress (); | |
66 } | |
67 | |
68 int QueryInterface (int /*long*/ riid, int /*long*/ ppvObject) { | |
69 if (riid is 0 || ppvObject is 0) return XPCOM.NS_ERROR_NO_INTERFACE; | |
70 nsID guid = new nsID (); | |
71 XPCOM.memmove (guid, riid, nsID.sizeof); | |
72 | |
73 if (guid.Equals (nsISupports.NS_ISUPPORTS_IID)) { | |
74 XPCOM.memmove (ppvObject, new int /*long*/[] {supports.getAddress ()}, C.PTR_SIZEOF); | |
75 AddRef (); | 46 AddRef (); |
76 return XPCOM.NS_OK; | 47 return XPCOM.NS_OK; |
77 } | 48 } |
78 if (guid.Equals (nsIFactory.NS_IFACTORY_IID)) { | 49 if (*riid == nsIFactory.IID) { |
79 XPCOM.memmove (ppvObject, new int /*long*/[] {factory.getAddress ()}, C.PTR_SIZEOF); | 50 *ppvObject = cast(void*)cast(nsIFactory)this; |
80 AddRef (); | 51 AddRef (); |
81 return XPCOM.NS_OK; | 52 return XPCOM.NS_OK; |
82 } | 53 } |
83 | 54 |
84 XPCOM.memmove (ppvObject, new int /*long*/[] {0}, C.PTR_SIZEOF); | 55 *ppvObject = null; |
85 return XPCOM.NS_ERROR_NO_INTERFACE; | 56 return XPCOM.NS_ERROR_NO_INTERFACE; |
86 } | 57 } |
87 | 58 |
88 int Release () { | 59 nsrefcnt Release () { |
89 refCount--; | 60 refCount--; |
90 if (refCount is 0) disposeCOMInterfaces (); | 61 //if (refCount is null) disposeCOMInterfaces (); |
91 return refCount; | 62 return refCount; |
92 } | 63 } |
93 | 64 |
94 /* nsIFactory */ | 65 /* nsIFactory */ |
95 | 66 |
96 int CreateInstance (int /*long*/ aOuter, int /*long*/ iid, int /*long*/ result) { | 67 nsresult CreateInstance (nsISupports aOuter, nsIID* iid, void** result) { |
97 PromptService2 promptService = new PromptService2 (); | 68 if (result is null) |
98 promptService.AddRef (); | 69 return XPCOM.NS_ERROR_INVALID_ARG; |
99 XPCOM.memmove (result, new int /*long*/[] {promptService.getAddress ()}, C.PTR_SIZEOF); | 70 auto promptService = new PromptService2; |
100 return XPCOM.NS_OK; | 71 nsresult rv = promptService.QueryInterface( iid, result ); |
72 if (XPCOM.NS_FAILED(rv)) { | |
73 *result = null; | |
74 delete promptService; | |
75 } | |
76 return rv; | |
101 } | 77 } |
102 | 78 |
103 int LockFactory (int lock) { | 79 nsresult LockFactory (PRBool lock) { |
104 return XPCOM.NS_OK; | 80 return XPCOM.NS_OK; |
105 } | 81 } |
106 } | 82 } |