1 11 package org.eclipse.swt.browser; 12 13 import org.eclipse.swt.internal.C; 14 import org.eclipse.swt.internal.mozilla.*; 15 16 class SimpleEnumerator { 17 XPCOMObject supports; 18 XPCOMObject simpleEnumerator; 19 int refCount = 0; 20 nsISupports[] values; 21 int index = 0; 22 23 public SimpleEnumerator (nsISupports[] values) { 24 this.values = values; 25 for (int i = 0; i < values.length; i++) { 26 values[i].AddRef (); 27 } 28 createCOMInterfaces (); 29 } 30 31 int AddRef () { 32 refCount++; 33 return refCount; 34 } 35 36 void createCOMInterfaces () { 37 38 supports = new XPCOMObject (new int[] {2, 0, 0}) { 39 public int method0 (int [] args) {return queryInterface (args[0], args[1]);} 40 public int method1 (int [] args) {return AddRef ();} 41 public int method2 (int [] args) {return Release ();} 42 }; 43 44 simpleEnumerator = new XPCOMObject (new int[] {2, 0, 0, 1, 1}) { 45 public int method0 (int [] args) {return queryInterface (args[0], args[1]);} 46 public int method1 (int [] args) {return AddRef ();} 47 public int method2 (int [] args) {return Release ();} 48 public int method3 (int [] args) {return HasMoreElements (args[0]);} 49 public int method4 (int [] args) {return GetNext (args[0]);} 50 }; 51 } 52 53 void disposeCOMInterfaces () { 54 if (supports != null) { 55 supports.dispose (); 56 supports = null; 57 } 58 if (simpleEnumerator != null) { 59 simpleEnumerator.dispose (); 60 simpleEnumerator = null; 61 } 62 if (values != null) { 63 for (int i = 0; i < values.length; i++) { 64 values[i].Release (); 65 } 66 values = null; 67 } 68 } 69 70 int getAddress () { 71 return simpleEnumerator.getAddress (); 72 } 73 74 int queryInterface (int riid, int ppvObject) { 75 if (riid == 0 || ppvObject == 0) return XPCOM.NS_ERROR_NO_INTERFACE; 76 nsID guid = new nsID (); 77 XPCOM.memmove (guid, riid, nsID.sizeof); 78 79 if (guid.Equals (nsISupports.NS_ISUPPORTS_IID)) { 80 XPCOM.memmove (ppvObject, new int [] {supports.getAddress ()}, C.PTR_SIZEOF); 81 AddRef (); 82 return XPCOM.NS_OK; 83 } 84 if (guid.Equals (nsISimpleEnumerator.NS_ISIMPLEENUMERATOR_IID)) { 85 XPCOM.memmove (ppvObject, new int [] {simpleEnumerator.getAddress ()}, C.PTR_SIZEOF); 86 AddRef (); 87 return XPCOM.NS_OK; 88 } 89 90 XPCOM.memmove (ppvObject, new int [] {0}, C.PTR_SIZEOF); 91 return XPCOM.NS_ERROR_NO_INTERFACE; 92 } 93 94 int Release () { 95 refCount--; 96 if (refCount == 0) disposeCOMInterfaces (); 97 return refCount; 98 } 99 100 int HasMoreElements (int _retval) { 101 boolean more = values != null && index < values.length; 102 XPCOM.memmove (_retval, new int[] {more ? 1 : 0}, 4); 103 return XPCOM.NS_OK; 104 } 105 106 int GetNext (int _retval) { 107 if (values == null || index == values.length) return XPCOM.NS_ERROR_UNEXPECTED; 108 nsISupports value = values[index++]; 109 value.AddRef (); 110 XPCOM.memmove (_retval, new int [] {value.getAddress ()}, C.PTR_SIZEOF); 111 return XPCOM.NS_OK; 112 } 113 } 114 115 | Popular Tags |