comparison dwt/browser/FilePickerFactory.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.FilePickerFactory;
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.nsIFactory;
20 import dwt.internal.mozilla.nsISupports;
21
22 class FilePickerFactory {
23 XPCOMObject supports;
24 XPCOMObject factory;
25 int refCount = 0;
26
27 FilePickerFactory () {
28 createCOMInterfaces ();
29 }
30
31 int AddRef () {
32 refCount++;
33 return refCount;
34 }
35
36 void createCOMInterfaces () {
37 /* Create each of the interfaces that this object implements */
38 supports = new XPCOMObject (new int[] {2, 0, 0}) {
39 public int /*long*/ method0 (int /*long*/[] args) {return QueryInterface (args[0], args[1]);}
40 public int /*long*/ method1 (int /*long*/[] args) {return AddRef ();}
41 public int /*long*/ method2 (int /*long*/[] args) {return Release ();}
42 };
43
44 factory = new XPCOMObject (new int[] {2, 0, 0, 3, 1}) {
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 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 ();
76 return XPCOM.NS_OK;
77 }
78 if (guid.Equals (nsIFactory.NS_IFACTORY_IID)) {
79 XPCOM.memmove (ppvObject, new int /*long*/[] {factory.getAddress ()}, C.PTR_SIZEOF);
80 AddRef ();
81 return XPCOM.NS_OK;
82 }
83
84 XPCOM.memmove (ppvObject, new int /*long*/[] {0}, C.PTR_SIZEOF);
85 return XPCOM.NS_ERROR_NO_INTERFACE;
86 }
87
88 int Release () {
89 refCount--;
90 if (refCount is 0) disposeCOMInterfaces ();
91 return refCount;
92 }
93
94 /* nsIFactory */
95
96 int CreateInstance (int /*long*/ aOuter, int /*long*/ iid, int /*long*/ result) {
97 FilePicker picker = new FilePicker ();
98 picker.AddRef ();
99 XPCOM.memmove (result, new int /*long*/[] {picker.getAddress ()}, C.PTR_SIZEOF);
100 return XPCOM.NS_OK;
101 }
102
103 int LockFactory (int lock) {
104 return XPCOM.NS_OK;
105 }
106 }