Mercurial > projects > dwt-mac
comparison dwt/browser/WindowCreator2.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.WindowCreator2; | |
12 | |
13 import dwt.dwthelper.utils; | |
14 | |
15 import dwt.DWT; | |
16 import dwt.graphics.Point; | |
17 import dwt.internal.C; | |
18 import dwt.internal.Platform; | |
19 import dwt.internal.mozilla.XPCOM; | |
20 import dwt.internal.mozilla.XPCOMObject; | |
21 import dwt.internal.mozilla.nsIBaseWindow; | |
22 import dwt.internal.mozilla.nsID; | |
23 import dwt.internal.mozilla.nsISupports; | |
24 import dwt.internal.mozilla.nsIURI; | |
25 import dwt.internal.mozilla.nsIWebBrowser; | |
26 import dwt.internal.mozilla.nsIWebBrowserChrome; | |
27 import dwt.internal.mozilla.nsIWindowCreator; | |
28 import dwt.internal.mozilla.nsIWindowCreator2; | |
29 import dwt.layout.FillLayout; | |
30 import dwt.widgets.Shell; | |
31 | |
32 class WindowCreator2 { | |
33 XPCOMObject supports; | |
34 XPCOMObject windowCreator; | |
35 XPCOMObject windowCreator2; | |
36 int refCount = 0; | |
37 | |
38 WindowCreator2 () { | |
39 createCOMInterfaces (); | |
40 } | |
41 | |
42 int AddRef () { | |
43 refCount++; | |
44 return refCount; | |
45 } | |
46 | |
47 void createCOMInterfaces () { | |
48 /* Create each of the interfaces that this object implements */ | |
49 supports = new XPCOMObject (new int[] {2, 0, 0}) { | |
50 public int /*long*/ method0 (int /*long*/[] args) {return QueryInterface (args[0], args[1]);} | |
51 public int /*long*/ method1 (int /*long*/[] args) {return AddRef ();} | |
52 public int /*long*/ method2 (int /*long*/[] args) {return Release ();} | |
53 }; | |
54 | |
55 windowCreator = new XPCOMObject (new int[] {2, 0, 0, 3}) { | |
56 public int /*long*/ method0 (int /*long*/[] args) {return QueryInterface (args[0], args[1]);} | |
57 public int /*long*/ method1 (int /*long*/[] args) {return AddRef ();} | |
58 public int /*long*/ method2 (int /*long*/[] args) {return Release ();} | |
59 public int /*long*/ method3 (int /*long*/[] args) {return CreateChromeWindow (args[0], (int)/*64*/args[1], args[2]);} | |
60 }; | |
61 | |
62 windowCreator2 = new XPCOMObject (new int[] {2, 0, 0, 3, 6}) { | |
63 public int /*long*/ method0 (int /*long*/[] args) {return QueryInterface (args[0], args[1]);} | |
64 public int /*long*/ method1 (int /*long*/[] args) {return AddRef ();} | |
65 public int /*long*/ method2 (int /*long*/[] args) {return Release ();} | |
66 public int /*long*/ method3 (int /*long*/[] args) {return CreateChromeWindow (args[0], (int)/*64*/args[1], args[2]);} | |
67 public int /*long*/ method4 (int /*long*/[] args) {return CreateChromeWindow2 (args[0], (int)/*64*/args[1], (int)/*64*/args[2], args[3], args[4], args[5]);} | |
68 }; | |
69 } | |
70 | |
71 void disposeCOMInterfaces () { | |
72 if (supports !is null) { | |
73 supports.dispose (); | |
74 supports = null; | |
75 } | |
76 if (windowCreator !is null) { | |
77 windowCreator.dispose (); | |
78 windowCreator = null; | |
79 } | |
80 | |
81 if (windowCreator2 !is null) { | |
82 windowCreator2.dispose (); | |
83 windowCreator2 = null; | |
84 } | |
85 } | |
86 | |
87 int /*long*/ getAddress () { | |
88 return windowCreator.getAddress (); | |
89 } | |
90 | |
91 int QueryInterface (int /*long*/ riid, int /*long*/ ppvObject) { | |
92 if (riid is 0 || ppvObject is 0) return XPCOM.NS_ERROR_NO_INTERFACE; | |
93 nsID guid = new nsID (); | |
94 XPCOM.memmove (guid, riid, nsID.sizeof); | |
95 | |
96 if (guid.Equals (nsISupports.NS_ISUPPORTS_IID)) { | |
97 XPCOM.memmove (ppvObject, new int /*long*/[] {supports.getAddress ()}, C.PTR_SIZEOF); | |
98 AddRef (); | |
99 return XPCOM.NS_OK; | |
100 } | |
101 if (guid.Equals (nsIWindowCreator.NS_IWINDOWCREATOR_IID)) { | |
102 XPCOM.memmove (ppvObject, new int /*long*/[] {windowCreator.getAddress ()}, C.PTR_SIZEOF); | |
103 AddRef (); | |
104 return XPCOM.NS_OK; | |
105 } | |
106 if (guid.Equals (nsIWindowCreator2.NS_IWINDOWCREATOR2_IID)) { | |
107 XPCOM.memmove (ppvObject, new int /*long*/[] {windowCreator2.getAddress ()}, C.PTR_SIZEOF); | |
108 AddRef (); | |
109 return XPCOM.NS_OK; | |
110 } | |
111 | |
112 XPCOM.memmove (ppvObject, new int /*long*/[] {0}, C.PTR_SIZEOF); | |
113 return XPCOM.NS_ERROR_NO_INTERFACE; | |
114 } | |
115 | |
116 int Release () { | |
117 refCount--; | |
118 if (refCount is 0) disposeCOMInterfaces (); | |
119 return refCount; | |
120 } | |
121 | |
122 /* nsIWindowCreator */ | |
123 | |
124 int CreateChromeWindow (int /*long*/ parent, int chromeFlags, int /*long*/ _retval) { | |
125 return CreateChromeWindow2 (parent, chromeFlags, 0, 0, 0, _retval); | |
126 } | |
127 | |
128 /* nsIWindowCreator2 */ | |
129 | |
130 int CreateChromeWindow2 (int /*long*/ parent, int chromeFlags, int contextFlags, int /*long*/ uri, int /*long*/ cancel, int /*long*/ _retval) { | |
131 if (parent is 0 && (chromeFlags & nsIWebBrowserChrome.CHROME_OPENAS_CHROME) is 0) { | |
132 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; | |
133 } | |
134 Browser src = null; | |
135 if (parent !is 0) { | |
136 nsIWebBrowserChrome browserChromeParent = new nsIWebBrowserChrome (parent); | |
137 int /*long*/[] aWebBrowser = new int /*long*/[1]; | |
138 int rc = browserChromeParent.GetWebBrowser (aWebBrowser); | |
139 if (rc !is XPCOM.NS_OK) Mozilla.error (rc); | |
140 if (aWebBrowser[0] is 0) Mozilla.error (XPCOM.NS_ERROR_NO_INTERFACE); | |
141 | |
142 nsIWebBrowser webBrowser = new nsIWebBrowser (aWebBrowser[0]); | |
143 int /*long*/[] result = new int /*long*/[1]; | |
144 rc = webBrowser.QueryInterface (nsIBaseWindow.NS_IBASEWINDOW_IID, result); | |
145 if (rc !is XPCOM.NS_OK) Mozilla.error (rc); | |
146 if (result[0] is 0) Mozilla.error (XPCOM.NS_ERROR_NO_INTERFACE); | |
147 webBrowser.Release (); | |
148 | |
149 nsIBaseWindow baseWindow = new nsIBaseWindow (result[0]); | |
150 result[0] = 0; | |
151 int /*long*/[] aParentNativeWindow = new int /*long*/[1]; | |
152 rc = baseWindow.GetParentNativeWindow (aParentNativeWindow); | |
153 if (rc !is XPCOM.NS_OK) Mozilla.error (rc); | |
154 if (aParentNativeWindow[0] is 0) Mozilla.error (XPCOM.NS_ERROR_NO_INTERFACE); | |
155 baseWindow.Release (); | |
156 | |
157 src = Mozilla.findBrowser (aParentNativeWindow[0]); | |
158 } | |
159 final Browser browser; | |
160 bool doit = true; | |
161 if ((chromeFlags & nsIWebBrowserChrome.CHROME_OPENAS_CHROME) !is 0) { | |
162 /* | |
163 * Mozilla will request a new Browser in a modal window in order to emulate a native | |
164 * dialog that is not available to it (eg.- a print dialog on Linux). For this | |
165 * reason modal requests are handled here so that the user is not exposed to them. | |
166 */ | |
167 int style = DWT.DIALOG_TRIM; | |
168 if ((chromeFlags & nsIWebBrowserChrome.CHROME_MODAL) !is 0) style |= DWT.APPLICATION_MODAL; | |
169 final Shell shell = src is null ? | |
170 new Shell (style) : | |
171 new Shell (src.getShell(), style); | |
172 shell.setLayout (new FillLayout ()); | |
173 browser = new Browser (shell, src is null ? DWT.MOZILLA : src.getStyle () & DWT.MOZILLA); | |
174 browser.addVisibilityWindowListener (new VisibilityWindowListener () { | |
175 public void hide (WindowEvent event) { | |
176 } | |
177 public void show (WindowEvent event) { | |
178 if (event.location !is null) shell.setLocation (event.location); | |
179 if (event.size !is null) { | |
180 Point size = event.size; | |
181 shell.setSize (shell.computeSize (size.x, size.y)); | |
182 } | |
183 shell.open (); | |
184 } | |
185 }); | |
186 browser.addCloseWindowListener (new CloseWindowListener () { | |
187 public void close (WindowEvent event) { | |
188 shell.close (); | |
189 } | |
190 }); | |
191 if (uri !is 0) { | |
192 nsIURI location = new nsIURI (uri); | |
193 int /*long*/ aSpec = XPCOM.nsEmbedCString_new (); | |
194 if (location.GetSpec (aSpec) is XPCOM.NS_OK) { | |
195 int length = XPCOM.nsEmbedCString_Length (aSpec); | |
196 if (length > 0) { | |
197 int /*long*/ buffer = XPCOM.nsEmbedCString_get (aSpec); | |
198 byte[] dest = new byte[length]; | |
199 XPCOM.memmove (dest, buffer, length); | |
200 browser.setUrl (new String (dest)); | |
201 } | |
202 } | |
203 XPCOM.nsEmbedCString_delete (aSpec); | |
204 } | |
205 } else { | |
206 WindowEvent event = new WindowEvent (src); | |
207 event.display = src.getDisplay (); | |
208 event.widget = src; | |
209 event.required = true; | |
210 for (int i = 0; i < src.webBrowser.openWindowListeners.length; i++) { | |
211 src.webBrowser.openWindowListeners[i].open (event); | |
212 } | |
213 browser = event.browser; | |
214 | |
215 /* Ensure that the Browser provided by the client is valid for use */ | |
216 doit = browser !is null && !browser.isDisposed (); | |
217 if (doit) { | |
218 String platform = Platform.PLATFORM; | |
219 bool isMozillaNativePlatform = platform.equals ("gtk") || platform.equals ("motif"); //$NON-NLS-1$ //$NON-NLS-2$ | |
220 doit = isMozillaNativePlatform || (browser.getStyle () & DWT.MOZILLA) !is 0; | |
221 } | |
222 } | |
223 if (doit) { | |
224 Mozilla mozilla = (Mozilla)browser.webBrowser; | |
225 mozilla.isChild = true; | |
226 int /*long*/ chromePtr = mozilla.webBrowserChrome.getAddress (); | |
227 nsIWebBrowserChrome webBrowserChrome = new nsIWebBrowserChrome (chromePtr); | |
228 webBrowserChrome.SetChromeFlags (chromeFlags); | |
229 webBrowserChrome.AddRef (); | |
230 XPCOM.memmove (_retval, new int /*long*/[] {chromePtr}, C.PTR_SIZEOF); | |
231 } else { | |
232 if (cancel !is 0) { | |
233 C.memmove (cancel, new int[] {1}, 4); /* PRBool */ | |
234 } | |
235 } | |
236 return doit ? XPCOM.NS_OK : XPCOM.NS_ERROR_NOT_IMPLEMENTED; | |
237 } | |
238 } |