Mercurial > projects > dwt-mac
comparison dwt/browser/FilePicker.d @ 45:d8635bb48c7c
Merge with SWT 3.5
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Mon, 01 Dec 2008 17:07:00 +0100 |
parents | e831403a80a9 |
children | 5583f8eeee6c |
comparison
equal
deleted
inserted
replaced
44:ca5e494f2bbf | 45:d8635bb48c7c |
---|---|
1 /******************************************************************************* | 1 /******************************************************************************* |
2 * Copyright (c) 2003, 2007 IBM Corporation and others. | 2 * Copyright (c) 2003, 2008 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 * |
16 import dwt.internal.C; | 16 import dwt.internal.C; |
17 import dwt.internal.mozilla.XPCOM; | 17 import dwt.internal.mozilla.XPCOM; |
18 import dwt.internal.mozilla.XPCOMObject; | 18 import dwt.internal.mozilla.XPCOMObject; |
19 import dwt.internal.mozilla.nsEmbedString; | 19 import dwt.internal.mozilla.nsEmbedString; |
20 import dwt.internal.mozilla.nsID; | 20 import dwt.internal.mozilla.nsID; |
21 import dwt.internal.mozilla.nsIDOMWindow; | |
21 import dwt.internal.mozilla.nsIFilePicker; | 22 import dwt.internal.mozilla.nsIFilePicker; |
22 import dwt.internal.mozilla.nsIFilePicker_1_8; | 23 import dwt.internal.mozilla.nsIFilePicker_1_8; |
23 import dwt.internal.mozilla.nsILocalFile; | 24 import dwt.internal.mozilla.nsILocalFile; |
24 import dwt.internal.mozilla.nsISupports; | 25 import dwt.internal.mozilla.nsISupports; |
25 import dwt.widgets.DirectoryDialog; | 26 import dwt.widgets.DirectoryDialog; |
26 import dwt.widgets.Display; | |
27 import dwt.widgets.FileDialog; | 27 import dwt.widgets.FileDialog; |
28 import dwt.widgets.Shell; | 28 import dwt.widgets.Shell; |
29 | 29 |
30 class FilePicker { | 30 class FilePicker { |
31 XPCOMObject supports; | 31 XPCOMObject supports; |
122 refCount--; | 122 refCount--; |
123 if (refCount is 0) disposeCOMInterfaces (); | 123 if (refCount is 0) disposeCOMInterfaces (); |
124 return refCount; | 124 return refCount; |
125 } | 125 } |
126 | 126 |
127 Browser getBrowser (int /*long*/ aDOMWindow) { | |
128 if (aDOMWindow is 0) return null; | |
129 nsIDOMWindow window = new nsIDOMWindow (aDOMWindow); | |
130 return Mozilla.findBrowser (window); | |
131 } | |
132 | |
127 /* | 133 /* |
128 * As of Mozilla 1.8 some of nsIFilePicker's string arguments changed type. This method | 134 * As of Mozilla 1.8 some of nsIFilePicker's string arguments changed type. This method |
129 * answers a java string based on the type of string that is appropriate for the Mozilla | 135 * answers a java string based on the type of string that is appropriate for the Mozilla |
130 * version being used. | 136 * version being used. |
131 */ | 137 */ |
151 } | 157 } |
152 | 158 |
153 /* picking a file */ | 159 /* picking a file */ |
154 int style = mode is nsIFilePicker.modeSave ? DWT.SAVE : DWT.OPEN; | 160 int style = mode is nsIFilePicker.modeSave ? DWT.SAVE : DWT.OPEN; |
155 if (mode is nsIFilePicker.modeOpenMultiple) style |= DWT.MULTI; | 161 if (mode is nsIFilePicker.modeOpenMultiple) style |= DWT.MULTI; |
156 Display display = Display.getCurrent (); | 162 Browser browser = getBrowser (parentHandle); |
157 Shell parent = null; // TODO compute parent | 163 Shell parent = null; |
158 if (parent is null) { | 164 if (browser !is null) { |
159 parent = new Shell (display); | 165 parent = browser.getShell (); |
166 } else { | |
167 parent = new Shell (); | |
160 } | 168 } |
161 FileDialog dialog = new FileDialog (parent, style); | 169 FileDialog dialog = new FileDialog (parent, style); |
162 if (title !is null) dialog.setText (title); | 170 if (title !is null) dialog.setText (title); |
163 if (directory !is null) dialog.setFilterPath (directory); | 171 if (directory !is null) dialog.setFilterPath (directory); |
164 if (masks !is null) dialog.setFilterExtensions (masks); | 172 if (masks !is null) dialog.setFilterExtensions (masks); |
172 XPCOM.memmove (_retval, new short[] {cast(short)result}, 2); /* PRInt16 */ | 180 XPCOM.memmove (_retval, new short[] {cast(short)result}, 2); /* PRInt16 */ |
173 return XPCOM.NS_OK; | 181 return XPCOM.NS_OK; |
174 } | 182 } |
175 | 183 |
176 int showDirectoryPicker () { | 184 int showDirectoryPicker () { |
177 Display display = Display.getCurrent (); | 185 Browser browser = getBrowser (parentHandle); |
178 Shell parent = null; // TODO compute parent | 186 Shell parent = null; |
179 if (parent is null) { | 187 if (browser !is null) { |
180 parent = new Shell (display); | 188 parent = browser.getShell (); |
189 } else { | |
190 parent = new Shell (); | |
181 } | 191 } |
182 DirectoryDialog dialog = new DirectoryDialog (parent, DWT.NONE); | 192 DirectoryDialog dialog = new DirectoryDialog (parent, DWT.NONE); |
183 if (title !is null) dialog.setText (title); | 193 if (title !is null) dialog.setText (title); |
184 if (directory !is null) dialog.setFilterPath (directory); | 194 if (directory !is null) dialog.setFilterPath (directory); |
185 directory = dialog.open (); | 195 directory = dialog.open (); |
224 directory = new String (chars); | 234 directory = new String (chars); |
225 return XPCOM.NS_OK; | 235 return XPCOM.NS_OK; |
226 } | 236 } |
227 | 237 |
228 int GetDisplayDirectory (int /*long*/ aDisplayDirectory) { | 238 int GetDisplayDirectory (int /*long*/ aDisplayDirectory) { |
229 String directoryName = directory !is null ? directory : ""; //$NON-NLS-1$ | 239 String directoryName = directory !is null ? directory : ""; //$NON-NLS-1$ |
230 nsEmbedString path = new nsEmbedString (directoryName); | 240 nsEmbedString path = new nsEmbedString (directoryName); |
231 int /*long*/[] file = new int /*long*/[1]; | 241 int /*long*/[] file = new int /*long*/[1]; |
232 int rc = XPCOM.NS_NewLocalFile (path.getAddress (), 1, file); | 242 int rc = XPCOM.NS_NewLocalFile (path.getAddress (), 1, file); |
233 path.dispose (); | 243 path.dispose (); |
234 if (rc !is XPCOM.NS_OK) Mozilla.error (rc); | 244 if (rc !is XPCOM.NS_OK) Mozilla.error (rc); |