Mercurial > projects > dwt-mac
comparison dwt/browser/SimpleEnumerator.d @ 0:380af2bdd8e5
Upload of whole dwt tree
author | Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com> |
---|---|
date | Sat, 09 Aug 2008 17:00:02 +0200 |
parents | |
children | 1a8b3cb347e0 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:380af2bdd8e5 |
---|---|
1 /******************************************************************************* | |
2 * Copyright (c) 2003, 2007 IBM Corporation and others. | |
3 * All rights reserved. This program and the accompanying materials | |
4 * are made available under the terms of the Eclipse Public License v1.0 | |
5 * which accompanies this distribution, and is available at | |
6 * http://www.eclipse.org/legal/epl-v10.html | |
7 * | |
8 * Contributors: | |
9 * IBM Corporation - initial API and implementation | |
10 *******************************************************************************/ | |
11 module dwt.browser.SimpleEnumerator; | |
12 | |
13 import dwt.dwthelper.utils; | |
14 | |
15 import dwt.internal.C; | |
16 import dwt.internal.mozilla.XPCOM; | |
17 import dwt.internal.mozilla.XPCOMObject; | |
18 import dwt.internal.mozilla.nsID; | |
19 import dwt.internal.mozilla.nsISimpleEnumerator; | |
20 import dwt.internal.mozilla.nsISupports; | |
21 | |
22 class SimpleEnumerator { | |
23 XPCOMObject supports; | |
24 XPCOMObject simpleEnumerator; | |
25 int refCount = 0; | |
26 nsISupports[] values; | |
27 int index = 0; | |
28 | |
29 SimpleEnumerator (nsISupports[] values) { | |
30 this.values = values; | |
31 for (int i = 0; i < values.length; i++) { | |
32 values[i].AddRef (); | |
33 } | |
34 createCOMInterfaces (); | |
35 } | |
36 | |
37 int AddRef () { | |
38 refCount++; | |
39 return refCount; | |
40 } | |
41 | |
42 void createCOMInterfaces () { | |
43 /* Create each of the interfaces that this object implements */ | |
44 supports = new XPCOMObject (new int[] {2, 0, 0}) { | |
45 public int /*long*/ method0 (int /*long*/[] args) {return QueryInterface (args[0], args[1]);} | |
46 public int /*long*/ method1 (int /*long*/[] args) {return AddRef ();} | |
47 public int /*long*/ method2 (int /*long*/[] args) {return Release ();} | |
48 }; | |
49 | |
50 simpleEnumerator = new XPCOMObject (new int[] {2, 0, 0, 1, 1}) { | |
51 public int /*long*/ method0 (int /*long*/[] args) {return QueryInterface (args[0], args[1]);} | |
52 public int /*long*/ method1 (int /*long*/[] args) {return AddRef ();} | |
53 public int /*long*/ method2 (int /*long*/[] args) {return Release ();} | |
54 public int /*long*/ method3 (int /*long*/[] args) {return HasMoreElements (args[0]);} | |
55 public int /*long*/ method4 (int /*long*/[] args) {return GetNext (args[0]);} | |
56 }; | |
57 } | |
58 | |
59 void disposeCOMInterfaces () { | |
60 if (supports !is null) { | |
61 supports.dispose (); | |
62 supports = null; | |
63 } | |
64 if (simpleEnumerator !is null) { | |
65 simpleEnumerator.dispose (); | |
66 simpleEnumerator = null; | |
67 } | |
68 if (values !is null) { | |
69 for (int i = 0; i < values.length; i++) { | |
70 values[i].Release (); | |
71 } | |
72 values = null; | |
73 } | |
74 } | |
75 | |
76 int /*long*/ getAddress () { | |
77 return simpleEnumerator.getAddress (); | |
78 } | |
79 | |
80 int QueryInterface (int /*long*/ riid, int /*long*/ ppvObject) { | |
81 if (riid is 0 || ppvObject is 0) return XPCOM.NS_ERROR_NO_INTERFACE; | |
82 nsID guid = new nsID (); | |
83 XPCOM.memmove (guid, riid, nsID.sizeof); | |
84 | |
85 if (guid.Equals (nsISupports.NS_ISUPPORTS_IID)) { | |
86 XPCOM.memmove (ppvObject, new int /*long*/[] {supports.getAddress ()}, C.PTR_SIZEOF); | |
87 AddRef (); | |
88 return XPCOM.NS_OK; | |
89 } | |
90 if (guid.Equals (nsISimpleEnumerator.NS_ISIMPLEENUMERATOR_IID)) { | |
91 XPCOM.memmove (ppvObject, new int /*long*/[] {simpleEnumerator.getAddress ()}, C.PTR_SIZEOF); | |
92 AddRef (); | |
93 return XPCOM.NS_OK; | |
94 } | |
95 | |
96 XPCOM.memmove (ppvObject, new int /*long*/[] {0}, C.PTR_SIZEOF); | |
97 return XPCOM.NS_ERROR_NO_INTERFACE; | |
98 } | |
99 | |
100 int Release () { | |
101 refCount--; | |
102 if (refCount is 0) disposeCOMInterfaces (); | |
103 return refCount; | |
104 } | |
105 | |
106 int HasMoreElements (int /*long*/ _retval) { | |
107 bool more = values !is null && index < values.length; | |
108 XPCOM.memmove (_retval, new int[] {more ? 1 : 0}, 4); /*PRBool */ | |
109 return XPCOM.NS_OK; | |
110 } | |
111 | |
112 int GetNext (int /*long*/ _retval) { | |
113 if (values is null || index is values.length) return XPCOM.NS_ERROR_UNEXPECTED; | |
114 nsISupports value = values[index++]; | |
115 value.AddRef (); | |
116 XPCOM.memmove (_retval, new int /*long*/[] {value.getAddress ()}, C.PTR_SIZEOF); | |
117 return XPCOM.NS_OK; | |
118 } | |
119 } | |
120 |