Mercurial > projects > dwt-mac
comparison dwt/browser/HelperAppLauncherDialogFactory.d @ 125:5583f8eeee6c
Synced mozilla with dwt-linux
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Fri, 16 Jan 2009 12:49:08 +0100 |
parents | d8635bb48c7c |
children |
comparison
equal
deleted
inserted
replaced
124:540fa4e9974a | 125:5583f8eeee6c |
---|---|
1 /******************************************************************************* | 1 /******************************************************************************* |
2 * Copyright (c) 2003, 2007 IBM Corporation and others. | 2 * Copyright (c) 2003, 2007 IBM Corporation and others. |
3 * All rights reserved. This program and the accompanying materials | 3 * All rights reserved. This program and the accompanying materials |
4 * are made available under the terms of the Eclipse Public License v1.0 | 4 * are made available under the terms of the Eclipse Public License v1.0 |
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.HelperAppLauncherDialogFactory; | 13 module dwt.browser.HelperAppLauncherDialogFactory; |
12 | 14 |
13 import dwt.dwthelper.utils; | 15 import dwt.dwthelper.utils; |
14 | 16 |
15 import dwt.internal.C; | 17 import XPCOM = dwt.internal.mozilla.XPCOM; |
16 import dwt.internal.mozilla.XPCOM; | 18 |
17 import dwt.internal.mozilla.XPCOMObject; | 19 import dwt.internal.mozilla.Common; |
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; |
21 | 23 |
22 class HelperAppLauncherDialogFactory { | 24 import dwt.browser.HelperAppLauncherDialog; |
23 XPCOMObject supports; | 25 import dwt.browser.HelperAppLauncherDialog_1_9; |
24 XPCOMObject factory; | 26 |
27 class HelperAppLauncherDialogFactory : nsIFactory { | |
25 int refCount = 0; | 28 int refCount = 0; |
26 bool isPre_1_9 = true; | 29 bool isPre_1_9 = true; |
27 | 30 |
31 | |
28 this () { | 32 this () { |
29 createCOMInterfaces (); | |
30 } | 33 } |
31 | 34 |
32 int AddRef () { | 35 extern(System) |
36 nsrefcnt AddRef () { | |
33 refCount++; | 37 refCount++; |
34 return refCount; | 38 return refCount; |
35 } | 39 } |
36 | 40 |
37 void createCOMInterfaces () { | 41 extern(System) |
38 /* Create each of the interfaces that this object implements */ | 42 nsresult QueryInterface (nsID* riid, void** ppvObject) { |
39 supports = new XPCOMObject (new int[] {2, 0, 0}) { | 43 if (riid is null || ppvObject is null) return XPCOM.NS_ERROR_NO_INTERFACE; |
40 public int /*long*/ method0 (int /*long*/[] args) {return QueryInterface (args[0], args[1]);} | |
41 public int /*long*/ method1 (int /*long*/[] args) {return AddRef ();} | |
42 public int /*long*/ method2 (int /*long*/[] args) {return Release ();} | |
43 }; | |
44 | 44 |
45 factory = new XPCOMObject (new int[] {2, 0, 0, 3, 1}) { | 45 if (*riid == nsISupports.IID) { |
46 public int /*long*/ method0 (int /*long*/[] args) {return QueryInterface (args[0], args[1]);} | 46 *ppvObject = cast(void*)cast(nsISupports)this; |
47 public int /*long*/ method1 (int /*long*/[] args) {return AddRef ();} | |
48 public int /*long*/ method2 (int /*long*/[] args) {return Release ();} | |
49 public int /*long*/ method3 (int /*long*/[] args) {return CreateInstance (args[0], args[1], args[2]);} | |
50 public int /*long*/ method4 (int /*long*/[] args) {return LockFactory (cast(int)/*64*/args[0]);} | |
51 }; | |
52 } | |
53 | |
54 void disposeCOMInterfaces () { | |
55 if (supports !is null) { | |
56 supports.dispose (); | |
57 supports = null; | |
58 } | |
59 if (factory !is null) { | |
60 factory.dispose (); | |
61 factory = null; | |
62 } | |
63 } | |
64 | |
65 int /*long*/ getAddress () { | |
66 return factory.getAddress (); | |
67 } | |
68 | |
69 int QueryInterface (int /*long*/ riid, int /*long*/ ppvObject) { | |
70 if (riid is 0 || ppvObject is 0) return XPCOM.NS_ERROR_NO_INTERFACE; | |
71 nsID guid = new nsID (); | |
72 XPCOM.memmove (guid, riid, nsID.sizeof); | |
73 | |
74 if (guid.Equals (nsISupports.NS_ISUPPORTS_IID)) { | |
75 XPCOM.memmove (ppvObject, new int /*long*/[] {supports.getAddress ()}, C.PTR_SIZEOF); | |
76 AddRef (); | 47 AddRef (); |
77 return XPCOM.NS_OK; | 48 return XPCOM.NS_OK; |
78 } | 49 } |
79 if (guid.Equals (nsIFactory.NS_IFACTORY_IID)) { | 50 if (*riid == nsIFactory.IID) { |
80 XPCOM.memmove (ppvObject, new int /*long*/[] {factory.getAddress ()}, C.PTR_SIZEOF); | 51 *ppvObject = cast(void*)cast(nsIFactory)this; |
81 AddRef (); | 52 AddRef (); |
82 return XPCOM.NS_OK; | 53 return XPCOM.NS_OK; |
83 } | 54 } |
84 | 55 |
85 XPCOM.memmove (ppvObject, new int /*long*/[] {0}, C.PTR_SIZEOF); | 56 *ppvObject = null; |
86 return XPCOM.NS_ERROR_NO_INTERFACE; | 57 return XPCOM.NS_ERROR_NO_INTERFACE; |
87 } | 58 } |
88 | 59 |
89 int Release () { | 60 extern(System) |
61 nsrefcnt Release () { | |
90 refCount--; | 62 refCount--; |
91 if (refCount is 0) disposeCOMInterfaces (); | 63 if (refCount is 0) return 0; |
92 return refCount; | 64 return refCount; |
93 } | 65 } |
94 | 66 |
95 /* nsIFactory */ | 67 /* nsIFactory */ |
96 | 68 |
97 int CreateInstance (int /*long*/ aOuter, int /*long*/ iid, int /*long*/ result) { | 69 extern(System) |
70 nsresult CreateInstance (nsISupports aOuter, nsID* iid, void** result) { | |
98 if (isPre_1_9) { | 71 if (isPre_1_9) { |
99 HelperAppLauncherDialog helperAppLauncherDialog = new HelperAppLauncherDialog (); | 72 if (result is null) |
100 helperAppLauncherDialog.AddRef (); | 73 return XPCOM.NS_ERROR_INVALID_ARG; |
101 XPCOM.memmove (result, new int /*long*/[] {helperAppLauncherDialog.getAddress ()}, C.PTR_SIZEOF); | 74 auto helperAppLauncherDialog = new HelperAppLauncherDialog; |
102 } else { | 75 nsresult rv = helperAppLauncherDialog.QueryInterface( iid, result ); |
103 HelperAppLauncherDialog_1_9 helperAppLauncherDialog = new HelperAppLauncherDialog_1_9 (); | 76 if (XPCOM.NS_FAILED(rv)) { |
104 helperAppLauncherDialog.AddRef (); | 77 *result = null; |
105 XPCOM.memmove (result, new int /*long*/[] {helperAppLauncherDialog.getAddress ()}, C.PTR_SIZEOF); | 78 delete helperAppLauncherDialog; |
79 } else { | |
80 if (result is null) | |
81 return XPCOM.NS_ERROR_INVALID_ARG; | |
82 auto helperAppLauncherDialog19 = new HelperAppLauncherDialog_1_9; | |
83 rv = helperAppLauncherDialog19.QueryInterface( iid, result ); | |
84 if (XPCOM.NS_FAILED(rv)) { | |
85 *result = null; | |
86 delete helperAppLauncherDialog19; | |
87 } | |
88 return rv; | |
89 } | |
106 } | 90 } |
107 return XPCOM.NS_OK; | |
108 } | 91 } |
109 | 92 |
110 int LockFactory (int lock) { | 93 extern(System) |
94 nsresult LockFactory (PRBool lock) { | |
111 return XPCOM.NS_OK; | 95 return XPCOM.NS_OK; |
112 } | 96 } |
113 } | 97 } |