Mercurial > projects > dwt-linux
changeset 293:3dfa75c74ed2
merge
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Thu, 07 Aug 2008 15:16:09 +0200 |
parents | 695802b523c0 (current diff) b0bd1789106b (diff) |
children | e6020acd846e |
files | dwt/internal/mozilla/nsEmbedString2.d dwt/internal/mozilla/nsIDownload.d dwt/internal/mozilla/nsIInputStream.d dwt/internal/mozilla/nsILocalFile.d dwt/internal/mozilla/nsIProgressDialog.d dwt/internal/mozilla/nsISupports.d dwt/internal/mozilla/nsStringAPI.d dwt/internal/mozilla/nsXPCOM.d |
diffstat | 31 files changed, 1548 insertions(+), 1404 deletions(-) [+] |
line wrap: on
line diff
--- a/dwt/browser/AppFileLocProvider.d Thu Aug 07 15:02:44 2008 +0200 +++ b/dwt/browser/AppFileLocProvider.d Thu Aug 07 15:16:09 2008 +0200 @@ -7,103 +7,91 @@ * * Contributors: * IBM Corporation - initial API and implementation - * Port to the D programming language: - * John Reimer <terminal.node@gmail.com> + * Port to the D programming language: + * John Reimer <terminal.node@gmail.com> *******************************************************************************/ +module dwt.browser.AppFileLocProvider; -module dwt.browser.AppFileLocProvider; +import tango.sys.Environment; +import tango.text.Util; import dwt.dwthelper.utils; import dwt.internal.Compatibility; - +import dwt.internal.mozilla.XPCOM; +import dwt.internal.mozilla.XPCOMObject; import dwt.internal.mozilla.nsEmbedString; import dwt.internal.mozilla.nsID; -import dwt.internal.mozilla.nsIDirectoryService; +import dwt.internal.mozilla.nsIDirectoryServiceProvider; +import dwt.internal.mozilla.nsIDirectoryServiceProvider2; import dwt.internal.mozilla.nsIFile; import dwt.internal.mozilla.nsILocalFile; import dwt.internal.mozilla.nsISupports; -class AppFileLocProvider : nsISupports, nsIDirectoryServiceProvider2 -{ - // XPCOMObject supports; - // XPCOMObject directoryServiceProvider; - // XPCOMObject directoryServiceProvider2; - nsrefcnt _refCount = 0; - String mozillaPath, profilePath; +class AppFileLocProvider : directoryServiceProvider2 { + int refCount = 0; + String mozillaPath, profilePath; String[] pluginDirs; - bool isXULRunner; + bool isXULRunner; - static String SEPARATOR_OS = System.getProperty ("file.separator"); //$NON-NLS-1$ - static String CHROME_DIR = "chrome"; //$NON-NLS-1$ - static String COMPONENTS_DIR = "components"; //$NON-NLS-1$ - static String HISTORY_FILE = "history.dat"; //$NON-NLS-1$ - static String LOCALSTORE_FILE = "localstore.rdf"; //$NON-NLS-1$ - static String MIMETYPES_FILE = "mimeTypes.rdf"; //$NON-NLS-1$ - static String PLUGINS_DIR = "plugins"; //$NON-NLS-1$ - static String USER_PLUGINS_DIR = ".mozilla" + SEPARATOR_OS + "plugins"; //$NON-NLS-1$ //$NON-NLS-2$ - static String PREFERENCES_FILE = "prefs.js"; //$NON-NLS-1$ + static final String SEPARATOR_OS = System.getProperty ("file.separator"); //$NON-NLS-1$ + static final String CHROME_DIR = "chrome"; //$NON-NLS-1$ + static final String COMPONENTS_DIR = "components"; //$NON-NLS-1$ + static final String HISTORY_FILE = "history.dat"; //$NON-NLS-1$ + static final String LOCALSTORE_FILE = "localstore.rdf"; //$NON-NLS-1$ + static final String MIMETYPES_FILE = "mimeTypes.rdf"; //$NON-NLS-1$ + static final String PLUGINS_DIR = "plugins"; //$NON-NLS-1$ + static final String USER_PLUGINS_DIR = ".mozilla" ~ SEPARATOR_OS ~ "plugins"; //$NON-NLS-1$ //$NON-NLS-2$ + static final String PREFERENCES_FILE = "prefs.js"; //$NON-NLS-1$ -AppFileLocProvider (String path) { - mozillaPath = path + SEPARATOR_OS; - createCOMInterfaces (); +this (String path) { + mozillaPath = path ~ SEPARATOR_OS;f +} + +int AddRef () { + refCount++; + return refCount; } - int AddRef () - { - refCount++; - return refCount; - } - - nsresult QueryInterface ( nsIID* riid, void** ppvObject) - { - if (riid is null || ppvObject is null) - return NS_ERROR_NO_INTERFACE; - - if (riid == nsISupports.IID) - { - *ppvObject =cast(void*)cast(nsISupports)this; - AddRef (); - return NS_OK; - } +int QueryInterface (nsID* riid, int void** ppvObject) { + if (riid is null || ppvObject is null) return XPCOM.NS_ERROR_NO_INTERFACE; - if (riid == nsIDirectoryServiceProvider.IID) - { - *ppvObject = cast(void*)cast(nsIDirectoryServiceProvider)this; - AddRef (); - return NS_OK; - } + if (*riid == nsISupports.IID)) { + *ppvObject = cast(void*)cast(nsISupports)this; + AddRef (); + return XPCOM.NS_OK; + } + if (*riid == nsIDirectoryServiceProvider.IID) { + *ppvObject = cast(void*)cast(nsIDirectoryServiceProvider)this; + AddRef (); + return XPCOM.NS_OK; + } + if (*riid == nsIDirectoryServiceProvider2.IID) { + *ppvObject = cast(void*)cast(nsIDirectoryServiceProvider2)this; + AddRef (); + return XPCOM.NS_OK; + } + + *ppvObject = null; + return XPCOM.NS_ERROR_NO_INTERFACE; +} - if (riid == nsDirectoryServiceProvider2.IID) { - *ppvObject = cast(void*)cast(nsIDirectoryServiceProvider2)this; - AddRef (); - return NS_OK; - } - - *ppvObject = null; - return NS_ERROR_NO_INTERFACE; - } - - nsrefcnt Release () - { - _refCount--; - if (_refCount is 0) - return 0; - return _refCount; - } +int Release () { + refCount--; + if (refCount is 0) return 0; + return refCount; +} void setProfilePath (String path) { profilePath = path; if (!Compatibility.fileExists (path, "")) { //$NON-NLS-1$ - int /*long*/[] result = new int /*long*/[1]; - nsEmbedString pathString = new nsEmbedString (path); - int rc = XPCOM.NS_NewLocalFile (pathString.getAddress (), 1, result); + nsILocalFile result; + scope auto nsEmbedString pathString = new nsEmbedString (path); + int rc = XPCOM.NS_NewLocalFile (cast(nsAString*)pathString, 1, &result); if (rc !is XPCOM.NS_OK) Mozilla.error (rc); - if (result[0] is 0) Mozilla.error (XPCOM.NS_ERROR_NULL_POINTER); - pathString.dispose (); + if (result is null) Mozilla.error (XPCOM.NS_ERROR_NULL_POINTER); - nsILocalFile file = new nsILocalFile (result [0]); - rc = file.Create (nsILocalFile.DIRECTORY_TYPE, 0700); + rc = result.Create (nsILocalFile.DIRECTORY_TYPE, 0700); if (rc !is XPCOM.NS_OK) Mozilla.error (rc); file.Release (); } @@ -111,43 +99,20 @@ /* nsIDirectoryServiceProvider2 */ -int getFiles (int /*long*/ prop, int /*long*/ _retval) { - int size = XPCOM.strlen (prop); - byte[] bytes = new byte[size]; - XPCOM.memmove (bytes, prop, size); - String propertyName = new String (MozillaDelegate.mbcsToWcs (null, bytes)); +nsresult GetFiles (char* prop, nsISimpleEnumerator* _retval) { + String propertyName = tango.stdc.stringz.fromStringz( prop ); String[] propertyValues = null; - if (propertyName.equals (XPCOM.NS_APP_PLUGINS_DIR_LIST)) { + if (propertyName == XPCOM.NS_APP_PLUGINS_DIR_LIST) { if (pluginDirs is null) { int index = 0; /* set the first value(s) to the MOZ_PLUGIN_PATH environment variable value if it's defined */ - int /*long*/ ptr = C.getenv (MozillaDelegate.wcsToMbcs (null, XPCOM.MOZILLA_PLUGIN_PATH, true)); - if (ptr !is 0) { - int length = C.strlen (ptr); - byte[] buffer = new byte[length]; - C.memmove (buffer, ptr, length); - String value = new String (MozillaDelegate.mbcsToWcs (null, buffer)); - if (value.length () > 0) { + String value = Environment.get (XPCOM.MOZILLA_PLUGIN_PATH); + if (ptr !is null) { + if (value.length > 0) { String separator = System.getProperty ("path.separator"); // $NON-NLS-1$ - Vector segments = new Vector (); - int start, end = -1; - do { - start = end + 1; - end = value.indexOf (separator, start); - String segment; - if (end is -1) { - segment = value.substring (start); - } else { - segment = value.substring (start, end); - } - if (segment.length () > 0) segments.addElement (segment); - } while (end !is -1); - int segmentsSize = segments.size (); - pluginDirs = new String [segmentsSize + 2]; - for (index = 0; index < segmentsSize; index++) { - pluginDirs[index] = (String)segments.elementAt (index); - } + foreach (segment; delimiter(value, separator)) + pluginDirs ~= segment; } } if (pluginDirs is null) { @@ -155,39 +120,36 @@ } /* set the next value to the GRE path + "plugins" */ - pluginDirs[index++] = mozillaPath + PLUGINS_DIR; + pluginDirs ~= mozillaPath ~ PLUGINS_DIR; /* set the next value to the home directory + "/.mozilla/plugins" */ - pluginDirs[index++] = System.getProperty("user.home") + SEPARATOR_OS + USER_PLUGINS_DIR; + pluginDirs ~= System.getProperty("user.home") ~ SEPARATOR_OS ~ USER_PLUGINS_DIR; } propertyValues = pluginDirs; } - XPCOM.memmove(_retval, new int /*long*/[] {0}, C.PTR_SIZEOF); + *_retval = null; + //XPCOM.memmove(_retval, new int /*long*/[] {0}, C.PTR_SIZEOF); if (propertyValues !is null) { - int /*long*/[] result = new int /*long*/[1]; + nsILocalFile localFile; + nsIFile file; nsISupports[] files = new nsISupports [propertyValues.length]; int index = 0; for (int i = 0; i < propertyValues.length; i++) { - nsEmbedString pathString = new nsEmbedString (propertyValues[i]); - int rc = XPCOM.NS_NewLocalFile (pathString.getAddress (), 1, result); + scope auto pathString = new nsEmbedString (propertyValues[i]); + int rc = XPCOM.NS_NewLocalFile (cast(nsAString*)pathString, 1, &(cast(void*)localFile)); if (rc !is XPCOM.NS_ERROR_FILE_UNRECOGNIZED_PATH) { /* value appears to be a valid pathname */ if (rc !is XPCOM.NS_OK) Mozilla.error (rc); - if (result[0] is 0) Mozilla.error (XPCOM.NS_ERROR_NULL_POINTER); + if (localFile is null) Mozilla.error (XPCOM.NS_ERROR_NULL_POINTER); - nsILocalFile localFile = new nsILocalFile (result[0]); - result[0] = 0; - rc = localFile.QueryInterface (nsIFile.NS_IFILE_IID, result); + rc = localFile.QueryInterface (nsIFile.NS_IFILE_IID, &(cast(void*)file)); if (rc !is XPCOM.NS_OK) Mozilla.error (rc); - if (result[0] is 0) Mozilla.error (XPCOM.NS_ERROR_NO_INTERFACE); + if (file is null) Mozilla.error (XPCOM.NS_ERROR_NO_INTERFACE); localFile.Release (); - nsIFile file = new nsIFile (result[0]); - files[index++] = file; + files[index++] = cast(nsISupports)file; } - pathString.dispose (); - result[0] = 0; } if (index < propertyValues.length) { @@ -197,9 +159,9 @@ files = temp; } - SimpleEnumerator enumerator = new SimpleEnumerator (files); + auto enumerator = new SimpleEnumerator (files); enumerator.AddRef (); - XPCOM.memmove (_retval, new int /*long*/[] {enumerator.getAddress ()}, C.PTR_SIZEOF); + *_retval = cast(nsISimpleEnumerator)enumerator; return XPCOM.NS_OK; } @@ -208,46 +170,43 @@ /* nsIDirectoryServiceProvider implementation */ -int getFile(int /*long*/ prop, int /*long*/ persistent, int /*long*/ _retval) { - int size = XPCOM.strlen (prop); - byte[] bytes = new byte[size]; - XPCOM.memmove (bytes, prop, size); - String propertyName = new String (MozillaDelegate.mbcsToWcs (null, bytes)); +nsresult GetFile(char* prop, PRBool* persistent, nsIFile* _retval) { + String propertyName = tango.stdc.stringz.fromStringz( prop ); String propertyValue = null; - if (propertyName.equals (XPCOM.NS_APP_HISTORY_50_FILE)) { - propertyValue = profilePath + HISTORY_FILE; - } else if (propertyName.equals (XPCOM.NS_APP_USER_MIMETYPES_50_FILE)) { - propertyValue = profilePath + MIMETYPES_FILE; - } else if (propertyName.equals (XPCOM.NS_APP_PREFS_50_FILE)) { - propertyValue = profilePath + PREFERENCES_FILE; - } else if (propertyName.equals (XPCOM.NS_APP_PREFS_50_DIR)) { + if (propertyName == (XPCOM.NS_APP_HISTORY_50_FILE)) { + propertyValue = profilePath ~ HISTORY_FILE; + } else if (propertyName == (XPCOM.NS_APP_USER_MIMETYPES_50_FILE)) { + propertyValue = profilePath ~ MIMETYPES_FILE; + } else if (propertyName == (XPCOM.NS_APP_PREFS_50_FILE)) { + propertyValue = profilePath ~ PREFERENCES_FILE; + } else if (propertyName == (XPCOM.NS_APP_PREFS_50_DIR)) { propertyValue = profilePath; - } else if (propertyName.equals (XPCOM.NS_APP_USER_CHROME_DIR)) { - propertyValue = profilePath + CHROME_DIR; - } else if (propertyName.equals (XPCOM.NS_APP_USER_PROFILE_50_DIR)) { + } else if (propertyName == (XPCOM.NS_APP_USER_CHROME_DIR)) { + propertyValue = profilePath ~ CHROME_DIR; + } else if (propertyName == (XPCOM.NS_APP_USER_PROFILE_50_DIR)) { propertyValue = profilePath; - } else if (propertyName.equals (XPCOM.NS_APP_LOCALSTORE_50_FILE)) { - propertyValue = profilePath + LOCALSTORE_FILE; - } else if (propertyName.equals (XPCOM.NS_APP_CACHE_PARENT_DIR)) { + } else if (propertyName == (XPCOM.NS_APP_LOCALSTORE_50_FILE)) { + propertyValue = profilePath ~ LOCALSTORE_FILE; + } else if (propertyName == (XPCOM.NS_APP_CACHE_PARENT_DIR)) { propertyValue = profilePath; - } else if (propertyName.equals (XPCOM.NS_OS_HOME_DIR)) { + } else if (propertyName == (XPCOM.NS_OS_HOME_DIR)) { propertyValue = System.getProperty("user.home"); //$NON-NLS-1$ - } else if (propertyName.equals (XPCOM.NS_OS_TEMP_DIR)) { + } else if (propertyName == (XPCOM.NS_OS_TEMP_DIR)) { propertyValue = System.getProperty("java.io.tmpdir"); //$NON-NLS-1$ - } else if (propertyName.equals (XPCOM.NS_GRE_DIR)) { + } else if (propertyName == (XPCOM.NS_GRE_DIR)) { propertyValue = mozillaPath; - } else if (propertyName.equals (XPCOM.NS_GRE_COMPONENT_DIR)) { - propertyValue = mozillaPath + COMPONENTS_DIR; - } else if (propertyName.equals (XPCOM.NS_XPCOM_INIT_CURRENT_PROCESS_DIR)) { + } else if (propertyName == (XPCOM.NS_GRE_COMPONENT_DIR)) { + propertyValue = mozillaPath ~ COMPONENTS_DIR; + } else if (propertyName == (XPCOM.NS_XPCOM_INIT_CURRENT_PROCESS_DIR)) { propertyValue = mozillaPath; - } else if (propertyName.equals (XPCOM.NS_OS_CURRENT_PROCESS_DIR)) { + } else if (propertyName == (XPCOM.NS_OS_CURRENT_PROCESS_DIR)) { propertyValue = mozillaPath; - } else if (propertyName.equals (XPCOM.NS_XPCOM_COMPONENT_DIR)) { - propertyValue = mozillaPath + COMPONENTS_DIR; - } else if (propertyName.equals (XPCOM.NS_XPCOM_CURRENT_PROCESS_DIR)) { + } else if (propertyName == (XPCOM.NS_XPCOM_COMPONENT_DIR)) { + propertyValue = mozillaPath ~ COMPONENTS_DIR; + } else if (propertyName == (XPCOM.NS_XPCOM_CURRENT_PROCESS_DIR)) { propertyValue = mozillaPath; - } else if (propertyName.equals (XPCOM.NS_APP_PREF_DEFAULTS_50_DIR)) { + } else if (propertyName == (XPCOM.NS_APP_PREF_DEFAULTS_50_DIR)) { /* * Answering a value for this property causes problems in Mozilla versions * < 1.7. Unfortunately this property is queried early enough in the @@ -261,23 +220,21 @@ if (isXULRunner) propertyValue = profilePath; } - XPCOM.memmove (persistent, new int[] {1}, 4); /* PRBool */ - XPCOM.memmove (_retval, new int /*long*/[] {0}, C.PTR_SIZEOF); - if (propertyValue !is null && propertyValue.length () > 0) { - int /*long*/[] result = new int /*long*/[1]; - nsEmbedString pathString = new nsEmbedString (propertyValue); - int rc = XPCOM.NS_NewLocalFile (pathString.getAddress (), 1, result); + *persistent = true; /* PRBool */ + *_retval = null; + if (propertyValue !is null && propertyValue.length > 0) { + nsILocalFile localFile; + scope auto pathString = new nsEmbedString (propertyValue); + int rc = XPCOM.NS_NewLocalFile (cast(nsAString*)pathString, 1, &(cast(void*)localFile)); if (rc !is XPCOM.NS_OK) Mozilla.error (rc); - if (result[0] is 0) Mozilla.error (XPCOM.NS_ERROR_NULL_POINTER); - pathString.dispose (); + if (localFile is null) Mozilla.error (XPCOM.NS_ERROR_NULL_POINTER); - nsILocalFile localFile = new nsILocalFile (result [0]); - result[0] = 0; - rc = localFile.QueryInterface (nsIFile.NS_IFILE_IID, result); + nsIFile file; + rc = localFile.QueryInterface (nsIFile.IID, &(cast(void*)file)); if (rc !is XPCOM.NS_OK) Mozilla.error (rc); - if (result[0] is 0) Mozilla.error (XPCOM.NS_ERROR_NO_INTERFACE); + if (file is null) Mozilla.error (XPCOM.NS_ERROR_NO_INTERFACE); - XPCOM.memmove (_retval, new int /*long*/[] {result[0]}, C.PTR_SIZEOF); + *_retval = file; localFile.Release (); return XPCOM.NS_OK; }
--- a/dwt/browser/Browser.d Thu Aug 07 15:02:44 2008 +0200 +++ b/dwt/browser/Browser.d Thu Aug 07 15:16:09 2008 +0200 @@ -7,6 +7,8 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Port to the D programming language: + * John Reimer <terminal.node@gmail.com> *******************************************************************************/ module dwt.browser.Browser; @@ -40,7 +42,7 @@ * @since 3.0 */ -public class Browser extends Composite { +public class Browser : Composite { WebBrowser webBrowser; int userStyle; @@ -77,40 +79,23 @@ * * @since 3.0 */ -public Browser (Composite parent, int style) { +public this (Composite parent, int style) { super (checkParent (parent), checkStyle (style)); userStyle = style; String platform = DWT.getPlatform (); Display display = parent.getDisplay (); - if ("gtk".equals (platform)) display.setData (NO_INPUT_METHOD, null); //$NON-NLS-1$ + if ("gtk" == platform) display.setData (NO_INPUT_METHOD, null); //$NON-NLS-1$ + /* String className = null; if ((style & DWT.MOZILLA) !is 0) { className = "dwt.browser.Mozilla"; //$NON-NLS-1$ } else { - if ("win32".equals (platform) || "wpf".equals (platform)) { //$NON-NLS-1$ $NON-NLS-2$ - className = "dwt.browser.IE"; //$NON-NLS-1$ - } else if ("motif".equals (platform)) { //$NON-NLS-1$ - className = "dwt.browser.Mozilla"; //$NON-NLS-1$ - } else if ("gtk".equals (platform)) { //$NON-NLS-1$ - className = "dwt.browser.Mozilla"; //$NON-NLS-1$ - } else if ("carbon".equals (platform) || "cocoa".equals (platform)) { //$NON-NLS-1$ - className = "dwt.browser.Safari"; //$NON-NLS-1$ - } else if ("photon".equals (platform)) { //$NON-NLS-1$ - className = "dwt.browser.Voyager"; //$NON-NLS-1$ - } else { - dispose (); - DWT.error (DWT.ERROR_NO_HANDLES); - } + dispose(); + DWT.error(DWT.ERROR_NO_HANDLES); } - - try { - Class clazz = Class.forName (className); - webBrowser = (WebBrowser)clazz.newInstance (); - } catch (ClassNotFoundException e) { - } catch (IllegalAccessException e) { - } catch (InstantiationException e) { - } + */ + auto webBrowser = new Mozilla; if (webBrowser is null) { dispose (); DWT.error (DWT.ERROR_NO_HANDLES); @@ -122,7 +107,7 @@ static Composite checkParent (Composite parent) { String platform = DWT.getPlatform (); - if (!"gtk".equals (platform)) return parent; //$NON-NLS-1$ + if (!("gtk" == platform)) return parent; //$NON-NLS-1$ /* * Note. Mozilla provides all IM support needed for text input in web pages. @@ -144,18 +129,18 @@ static int checkStyle(int style) { String platform = DWT.getPlatform (); if ((style & DWT.MOZILLA) !is 0) { - if ("carbon".equals (platform)) return style | DWT.EMBEDDED; //$NON-NLS-1$ - if ("motif".equals (platform)) return style | DWT.EMBEDDED; //$NON-NLS-1$ + if ("carbon" == platform) return style | DWT.EMBEDDED; //$NON-NLS-1$ + if ("motif" == platform) return style | DWT.EMBEDDED; //$NON-NLS-1$ return style; } - if ("win32".equals (platform)) { //$NON-NLS-1$ + if ("win32" == platform) { //$NON-NLS-1$ /* * For IE on win32 the border is supplied by the embedded browser, so remove * the style so that the parent Composite will not draw a second border. */ return style & ~DWT.BORDER; - } else if ("motif".equals (platform)) { //$NON-NLS-1$ + } else if ("motif" == platform) { //$NON-NLS-1$ return style | DWT.EMBEDDED; } return style; @@ -371,9 +356,10 @@ } protected void checkSubclass () { - String name = getClass ().getName (); - int index = name.lastIndexOf ('.'); - if (!name.substring (0, index + 1).equals (PACKAGE_PREFIX)) { + String name = this.classinfo.name; + + int index = tango.text.Util.locatePrior(name, '.'); + if (!(name[0 .. index + 1] == PACKAGE_PREFIX)) { DWT.error (DWT.ERROR_INVALID_SUBCLASS); } }
--- a/dwt/browser/CloseWindowListener.d Thu Aug 07 15:02:44 2008 +0200 +++ b/dwt/browser/CloseWindowListener.d Thu Aug 07 15:16:09 2008 +0200 @@ -7,11 +7,11 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Port to the D programming language: + * John Reimer <terminal.node@gmail.com> *******************************************************************************/ module dwt.browser.CloseWindowListener; -import dwt.dwthelper.utils; - import dwt.internal.DWTEventListener; /** @@ -47,5 +47,5 @@ * * @since 3.0 */ - public void close(WindowEvent event); +public void close(WindowEvent event); }
--- a/dwt/browser/Download.d Thu Aug 07 15:02:44 2008 +0200 +++ b/dwt/browser/Download.d Thu Aug 07 15:16:09 2008 +0200 @@ -8,14 +8,14 @@ * Contributors: * IBM Corporation - initial API and implementation * Port to the D programming language: - * John Reimer <terminal.node@gmail.com> + * John Reimer <terminal.node@gmail.com> *******************************************************************************/ module dwt.browser.Download; import dwt.dwthelper.utils; import dwt.DWT; -import dwt.internal.C; + import dwt.internal.Compatibility; import dwt.internal.mozilla.XPCOM; import dwt.internal.mozilla.XPCOMObject; @@ -35,11 +35,7 @@ import dwt.widgets.Listener; import dwt.widgets.Shell; -class Download { - XPCOMObject supports; - XPCOMObject download; - XPCOMObject progressDialog; - XPCOMObject webProgressListener; +class Download : nsIProgressDialog { nsIHelperAppLauncher helperAppLauncher; int refCount = 0; @@ -47,8 +43,7 @@ Label status; Button cancel; -Download () { - createCOMInterfaces (); +this () { } int AddRef () { @@ -56,134 +51,46 @@ return refCount; } -void createCOMInterfaces () { - /* Create each of the interfaces that this object implements */ - supports = new XPCOMObject (new int[] {2, 0, 0}) { - public int /*long*/ method0 (int /*long*/[] args) {return QueryInterface (args[0], args[1]);} - public int /*long*/ method1 (int /*long*/[] args) {return AddRef ();} - public int /*long*/ method2 (int /*long*/[] args) {return Release ();} - }; - - download = new XPCOMObject (new int[] {2, 0, 0, 7, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1}) { - public int /*long*/ method0 (int /*long*/[] args) {return QueryInterface (args[0], args[1]);} - public int /*long*/ method1 (int /*long*/[] args) {return AddRef ();} - public int /*long*/ method2 (int /*long*/[] args) {return Release ();} - public int /*long*/ method3 (int /*long*/[] args) {return Init (args[0], args[1], args[2], args[3], args[4], args[5], args[6]);} - public int /*long*/ method4 (int /*long*/[] args) {return GetSource (args[0]);} - public int /*long*/ method5 (int /*long*/[] args) {return GetTarget (args[0]);} - public int /*long*/ method6 (int /*long*/[] args) {return GetPersist (args[0]);} - public int /*long*/ method7 (int /*long*/[] args) {return GetPercentComplete (args[0]);} - public int /*long*/ method8 (int /*long*/[] args) {return GetDisplayName (args[0]);} - public int /*long*/ method9 (int /*long*/[] args) {return SetDisplayName (args[0]);} - public int /*long*/ method10 (int /*long*/[] args) {return GetStartTime (args[0]);} - public int /*long*/ method11 (int /*long*/[] args) {return GetMIMEInfo (args[0]);} - public int /*long*/ method12 (int /*long*/[] args) {return GetListener (args[0]);} - public int /*long*/ method13 (int /*long*/[] args) {return SetListener (args[0]);} - public int /*long*/ method14 (int /*long*/[] args) {return GetObserver (args[0]);} - public int /*long*/ method15 (int /*long*/[] args) {return SetObserver (args[0]);} - }; - - progressDialog = new XPCOMObject (new int[] {2, 0, 0, 7, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}) { - public int /*long*/ method0 (int /*long*/[] args) {return QueryInterface (args[0], args[1]);} - public int /*long*/ method1 (int /*long*/[] args) {return AddRef ();} - public int /*long*/ method2 (int /*long*/[] args) {return Release ();} - public int /*long*/ method3 (int /*long*/[] args) {return Init (args[0], args[1], args[2], args[3], args[4], args[5], args[6]);} - public int /*long*/ method4 (int /*long*/[] args) {return GetSource (args[0]);} - public int /*long*/ method5 (int /*long*/[] args) {return GetTarget (args[0]);} - public int /*long*/ method6 (int /*long*/[] args) {return GetPersist (args[0]);} - public int /*long*/ method7 (int /*long*/[] args) {return GetPercentComplete (args[0]);} - public int /*long*/ method8 (int /*long*/[] args) {return GetDisplayName (args[0]);} - public int /*long*/ method9 (int /*long*/[] args) {return SetDisplayName (args[0]);} - public int /*long*/ method10 (int /*long*/[] args) {return GetStartTime (args[0]);} - public int /*long*/ method11 (int /*long*/[] args) {return GetMIMEInfo (args[0]);} - public int /*long*/ method12 (int /*long*/[] args) {return GetListener (args[0]);} - public int /*long*/ method13 (int /*long*/[] args) {return SetListener (args[0]);} - public int /*long*/ method14 (int /*long*/[] args) {return GetObserver (args[0]);} - public int /*long*/ method15 (int /*long*/[] args) {return SetObserver (args[0]);} - public int /*long*/ method16 (int /*long*/[] args) {return Open (args[0]);} - public int /*long*/ method17 (int /*long*/[] args) {return GetCancelDownloadOnClose (args[0]);} - public int /*long*/ method18 (int /*long*/[] args) {return SetCancelDownloadOnClose ((int)/*64*/args[0]);} - public int /*long*/ method19 (int /*long*/[] args) {return GetDialog (args[0]);} - public int /*long*/ method20 (int /*long*/[] args) {return SetDialog (args[0]);} - }; - - webProgressListener = new XPCOMObject (new int[] {2, 0, 0, 4, 6, 3, 4, 3}) { - public int /*long*/ method0 (int /*long*/[] args) {return QueryInterface (args[0], args[1]);} - public int /*long*/ method1 (int /*long*/[] args) {return AddRef ();} - public int /*long*/ method2 (int /*long*/[] args) {return Release ();} - public int /*long*/ method3 (int /*long*/[] args) {return OnStateChange (args[0], args[1], (int)/*64*/args[2], (int)/*64*/args[3]);} - public int /*long*/ method4 (int /*long*/[] args) {return OnProgressChange (args[0], args[1], (int)/*64*/args[2], (int)/*64*/args[3], (int)/*64*/args[4], (int)/*64*/args[5]);} - public int /*long*/ method5 (int /*long*/[] args) {return OnLocationChange (args[0], args[1], args[2]);} - public int /*long*/ method6 (int /*long*/[] args) {return OnStatusChange (args[0], args[1], (int)/*64*/args[2], args[3]);} - public int /*long*/ method7 (int /*long*/[] args) {return OnSecurityChange (args[0], args[1], (int)/*64*/args[2]);} - }; -} - -void disposeCOMInterfaces () { - if (supports !is null) { - supports.dispose (); - supports = null; - } - if (download !is null) { - download.dispose (); - download = null; - } - if (progressDialog !is null) { - progressDialog.dispose (); - progressDialog = null; - } - if (webProgressListener !is null) { - webProgressListener.dispose (); - webProgressListener = null; - } -} - -int /*long*/ getAddress () { - return progressDialog.getAddress (); -} - -int QueryInterface (int /*long*/ riid, int /*long*/ ppvObject) { - if (riid is 0 || ppvObject is 0) return XPCOM.NS_ERROR_NO_INTERFACE; - nsID guid = new nsID (); - XPCOM.memmove (guid, riid, nsID.sizeof); - - if (guid.Equals (nsISupports.NS_ISUPPORTS_IID)) { - XPCOM.memmove (ppvObject, new int /*long*/[] {supports.getAddress ()}, C.PTR_SIZEOF); +int QueryInterface (nsID* riid, void** ppvObject) { + if (riid is null || ppvObject is null) return XPCOM.NS_ERROR_NO_INTERFACE; + + if (*riid == nsISupports.IID)) { + *ppvObject = cast(void*)cast(nsISupports)this; AddRef(); return XPCOM.NS_OK; } - if (guid.Equals (nsIDownload.NS_IDOWNLOAD_IID)) { - XPCOM.memmove (ppvObject, new int /*long*/[] {download.getAddress ()}, C.PTR_SIZEOF); + if (*riid == nsIDownload.IID) { + *ppvObject = cast(void*)cast(nsIDownload)this; AddRef(); return XPCOM.NS_OK; } - if (guid.Equals (nsIProgressDialog.NS_IPROGRESSDIALOG_IID)) { - XPCOM.memmove (ppvObject, new int /*long*/[] {progressDialog.getAddress ()}, C.PTR_SIZEOF); + if (*riid == nsIProgressDialog.IID) { + *ppvObject = cast(void*)cast(nsIProgressDialog)this; AddRef(); return XPCOM.NS_OK; } - if (guid.Equals (nsIWebProgressListener.NS_IWEBPROGRESSLISTENER_IID)) { - XPCOM.memmove (ppvObject, new int /*long*/[] {webProgressListener.getAddress ()}, C.PTR_SIZEOF); + if (*riid == nsIWebProgressListener.IID) { + *ppvObject = cast(void*)cast(nsIWebProgressListener)this; AddRef(); return XPCOM.NS_OK; } - XPCOM.memmove (ppvObject, new int /*long*/[] {0}, C.PTR_SIZEOF); + *ppvObject = null; return XPCOM.NS_ERROR_NO_INTERFACE; } int Release () { refCount--; - if (refCount is 0) disposeCOMInterfaces (); + if (refCount is 0) return 0; return refCount; } /* nsIDownload */ /* Note. The argument startTime is defined as a PRInt64. This translates into two java ints. */ -int Init (int /*long*/ aSource, int /*long*/ aTarget, int /*long*/ aDisplayName, int /*long*/ aMIMEInfo, int /*long*/ startTime1, int /*long*/ startTime2, int /*long*/ aPersist) { +int Init (nsIURI aSource, nsIURI aTarget, nsAString* aDisplayName, nsIMIMEInfo aMIMEInfo, PRTime startTime, PRBool aPersist) { nsIURI source = new nsIURI (aSource); - int /*long*/ aSpec = XPCOM.nsEmbedCString_new (); - int rc = source.GetHost (aSpec); + scope auto aSpec = new nsEmbedString; + int rc = source.GetHost (cast(nsAString*)aSpec); if (rc !is XPCOM.NS_OK) Mozilla.error (rc); int length = XPCOM.nsEmbedCString_Length (aSpec); int /*long*/ buffer = XPCOM.nsEmbedCString_get (aSpec); @@ -280,7 +187,7 @@ return XPCOM.NS_ERROR_NOT_IMPLEMENTED; } -int GetPersist (int /*long*/ aPersist) { +int GetPersist (PRBool* aPersist) { return XPCOM.NS_ERROR_NOT_IMPLEMENTED; } @@ -312,11 +219,11 @@ return XPCOM.NS_ERROR_NOT_IMPLEMENTED; } -int GetObserver (int /*long*/ aObserver) { +nsresult GetObserver (nsIObserver* aObserver) { return XPCOM.NS_ERROR_NOT_IMPLEMENTED; } -int SetObserver (int /*long*/ aObserver) { +nsresult SetObserver (nsIOBserver aObserver) { if (aObserver !is 0) { nsISupports supports = new nsISupports (aObserver); int /*long*/[] result = new int /*long*/[1]; @@ -329,7 +236,7 @@ } /* nsIProgressDialog */ -int Open (int /*long*/ aParent) { +nsresult Open (int /*long*/ aParent) { return XPCOM.NS_ERROR_NOT_IMPLEMENTED; }
--- a/dwt/browser/DownloadFactory.d Thu Aug 07 15:02:44 2008 +0200 +++ b/dwt/browser/DownloadFactory.d Thu Aug 07 15:16:09 2008 +0200 @@ -7,72 +7,100 @@ * * Contributors: * IBM Corporation - initial API and implementation - * Port to the D programming language: - * John Reimer <terminal.node@gmail.com> *******************************************************************************/ module dwt.browser.DownloadFactory; import dwt.dwthelper.utils; -import dwt.browser.Download; - +import dwt.internal.C; +import dwt.internal.mozilla.XPCOM; +import dwt.internal.mozilla.XPCOMObject; import dwt.internal.mozilla.nsID; import dwt.internal.mozilla.nsIFactory; import dwt.internal.mozilla.nsISupports; -class DownloadFactory : nsIFactory -{ - int _refCount = 0; +class DownloadFactory { + XPCOMObject supports; + XPCOMObject factory; + int refCount = 0; + +DownloadFactory () { + createCOMInterfaces (); +} + +int AddRef () { + refCount++; + return refCount; +} - nsrefcnt AddRef () - { - _refCount++; - return _refCount; - } +void createCOMInterfaces () { + /* Create each of the interfaces that this object implements */ + supports = new XPCOMObject (new int[] {2, 0, 0}) { + public int /*long*/ method0 (int /*long*/[] args) {return QueryInterface (args[0], args[1]);} + public int /*long*/ method1 (int /*long*/[] args) {return AddRef ();} + public int /*long*/ method2 (int /*long*/[] args) {return Release ();} + }; + + factory = new XPCOMObject (new int[] {2, 0, 0, 3, 1}) { + public int /*long*/ method0 (int /*long*/[] args) {return QueryInterface (args[0], args[1]);} + public int /*long*/ method1 (int /*long*/[] args) {return AddRef ();} + public int /*long*/ method2 (int /*long*/[] args) {return Release ();} + public int /*long*/ method3 (int /*long*/[] args) {return CreateInstance (args[0], args[1], args[2]);} + public int /*long*/ method4 (int /*long*/[] args) {return LockFactory ((int)/*64*/args[0]);} + }; +} - int QueryInterface ( ref nsIID riid, void** ppvObject) - { - if (riid is null || ppvObject is null) - return NS_ERROR_NO_INTERFACE; - - if ( riid == nsISupports.IID) - { - *ppvObject = cast(void*)cast(nsISupports)this; - AddRef (); - return NS_OK; - } +void disposeCOMInterfaces () { + if (supports !is null) { + supports.dispose (); + supports = null; + } + if (factory !is null) { + factory.dispose (); + factory = null; + } +} + +int /*long*/ getAddress () { + return factory.getAddress (); +} - if ( riid == nsIFactory.IID) - { - *ppvObject = cast(void*)cast(nsIFactory)this; - AddRef (); - return NS_OK; - } +int QueryInterface (int /*long*/ riid, int /*long*/ ppvObject) { + if (riid is 0 || ppvObject is 0) return XPCOM.NS_ERROR_NO_INTERFACE; + nsID guid = new nsID (); + XPCOM.memmove (guid, riid, nsID.sizeof); - *ppvObject = null; - return NS_ERROR_NO_INTERFACE; + if (guid.Equals (nsISupports.NS_ISUPPORTS_IID)) { + XPCOM.memmove (ppvObject, new int /*long*/[] {supports.getAddress ()}, C.PTR_SIZEOF); + AddRef (); + return XPCOM.NS_OK; } + if (guid.Equals (nsIFactory.NS_IFACTORY_IID)) { + XPCOM.memmove (ppvObject, new int /*long*/[] {factory.getAddress ()}, C.PTR_SIZEOF); + AddRef (); + return XPCOM.NS_OK; + } + + XPCOM.memmove (ppvObject, new int /*long*/[] {0}, C.PTR_SIZEOF); + return XPCOM.NS_ERROR_NO_INTERFACE; +} - nsrefcnt Release () - { - _refCount--; - if (_refCount is 0) - _refCount = 0; - return _refCount; - } +int Release () { + refCount--; + if (refCount is 0) disposeCOMInterfaces (); + return refCount; +} /* nsIFactory */ - nsresult CreateInstance ( nsISupports aOuter, nsIID* iid, void** result) - { - Download download = new Download (); - download.AddRef (); - nsresult rv = download.QueryInterface( iid, result ); - return rv; - } +int CreateInstance (int /*long*/ aOuter, int /*long*/ iid, int /*long*/ result) { + Download download = new Download (); + download.AddRef (); + XPCOM.memmove (result, new int /*long*/[] {download.getAddress ()}, C.PTR_SIZEOF); + return XPCOM.NS_OK; +} - nsresult LockFactory (int lock) - { - return NS_OK; - } +int LockFactory (int lock) { + return XPCOM.NS_OK; } +}
--- a/dwt/browser/Download_1_8.d Thu Aug 07 15:02:44 2008 +0200 +++ b/dwt/browser/Download_1_8.d Thu Aug 07 15:16:09 2008 +0200 @@ -7,16 +7,17 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Port to the D programming language: + * John Reimer <terminal.node@gmail.com> *******************************************************************************/ module dwt.browser.Download_1_8; import dwt.dwthelper.utils; import dwt.DWT; -import dwt.internal.C; + import dwt.internal.Compatibility; import dwt.internal.mozilla.XPCOM; -import dwt.internal.mozilla.XPCOMObject; import dwt.internal.mozilla.nsICancelable; import dwt.internal.mozilla.nsID; import dwt.internal.mozilla.nsIDownload_1_8; @@ -32,11 +33,7 @@ import dwt.widgets.Listener; import dwt.widgets.Shell; -class Download_1_8 { - XPCOMObject supports; - XPCOMObject download; - XPCOMObject progressDialog; - XPCOMObject webProgressListener; +class Download_1_8 : nsIProgressDialog_1_8 { nsICancelable cancelable; int refCount = 0; @@ -44,10 +41,9 @@ Label status; Button cancel; - static final bool is32 = C.PTR_SIZEOF is 4; + //static final bool is32 = C.PTR_SIZEOF is 4; //determine if 32 or 64 bit platform? -Download_1_8 () { - createCOMInterfaces (); +this () { } int AddRef () { @@ -55,174 +51,52 @@ return refCount; } -void createCOMInterfaces () { - /* Create each of the interfaces that this object implements */ - supports = new XPCOMObject (new int[] {2, 0, 0}) { - public int /*long*/ method0 (int /*long*/[] args) {return QueryInterface (args[0], args[1]);} - public int /*long*/ method1 (int /*long*/[] args) {return AddRef ();} - public int /*long*/ method2 (int /*long*/[] args) {return Release ();} - }; - - download = new XPCOMObject (new int[] {2, 0, 0, 4, 6, 3, 4, 3, is32 ? 10 : 6, is32 ? 8 : 7, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}) { - public int /*long*/ method0 (int /*long*/[] args) {return QueryInterface (args[0], args[1]);} - public int /*long*/ method1 (int /*long*/[] args) {return AddRef ();} - public int /*long*/ method2 (int /*long*/[] args) {return Release ();} - public int /*long*/ method3 (int /*long*/[] args) {return OnStateChange (args[0], args[1], (int)/*64*/args[2], (int)/*64*/args[3]);} - public int /*long*/ method4 (int /*long*/[] args) {return OnProgressChange (args[0], args[1], (int)/*64*/args[2], (int)/*64*/args[3], (int)/*64*/args[4], (int)/*64*/args[5]);} - public int /*long*/ method5 (int /*long*/[] args) {return OnLocationChange (args[0], args[1], args[2]);} - public int /*long*/ method6 (int /*long*/[] args) {return OnStatusChange (args[0], args[1], (int)/*64*/args[2], args[3]);} - public int /*long*/ method7 (int /*long*/[] args) {return OnSecurityChange (args[0], args[1], (int)/*64*/args[2]);} - public int /*long*/ method8 (int /*long*/[] args) { - if (args.length is 10) { - return OnProgressChange64_32 (args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9]); - } else { - return OnProgressChange64 (args[0], args[1], args[2], args[3], args[4], args[5]); - } - } - public int /*long*/ method9 (int /*long*/[] args) { - if (args.length is 8) { - return Init_32 (args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7]); - } else { - return Init (args[0], args[1], args[2], args[3], args[4], args[5], args[6]); - } - } - public int /*long*/ method10 (int /*long*/[] args) {return GetTargetFile (args[0]);} - public int /*long*/ method11 (int /*long*/[] args) {return GetPercentComplete (args[0]);} - public int /*long*/ method12 (int /*long*/[] args) {return GetAmountTransferred (args[0]);} - public int /*long*/ method13 (int /*long*/[] args) {return GetSize (args[0]);} - public int /*long*/ method14 (int /*long*/[] args) {return GetSource (args[0]);} - public int /*long*/ method15 (int /*long*/[] args) {return GetTarget (args[0]);} - public int /*long*/ method16 (int /*long*/[] args) {return GetCancelable (args[0]);} - public int /*long*/ method17 (int /*long*/[] args) {return GetDisplayName (args[0]);} - public int /*long*/ method18 (int /*long*/[] args) {return GetStartTime (args[0]);} - public int /*long*/ method19 (int /*long*/[] args) {return GetMIMEInfo (args[0]);} - }; - - progressDialog = new XPCOMObject (new int[] {2, 0, 0, 4, 6, 3, 4, 3, is32 ? 10 : 6, is32 ? 8 : 7, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}) { - public int /*long*/ method0 (int /*long*/[] args) {return QueryInterface (args[0], args[1]);} - public int /*long*/ method1 (int /*long*/[] args) {return AddRef ();} - public int /*long*/ method2 (int /*long*/[] args) {return Release ();} - public int /*long*/ method3 (int /*long*/[] args) {return OnStateChange (args[0], args[1], (int)/*64*/args[2], (int)/*64*/args[3]);} - public int /*long*/ method4 (int /*long*/[] args) {return OnProgressChange (args[0], args[1], (int)/*64*/args[2], (int)/*64*/args[3], (int)/*64*/args[4], (int)/*64*/args[5]);} - public int /*long*/ method5 (int /*long*/[] args) {return OnLocationChange (args[0], args[1], args[2]);} - public int /*long*/ method6 (int /*long*/[] args) {return OnStatusChange (args[0], args[1], (int)/*64*/args[2], args[3]);} - public int /*long*/ method7 (int /*long*/[] args) {return OnSecurityChange (args[0], args[1], (int)/*64*/args[2]);} - public int /*long*/ method8 (int /*long*/[] args) { - if (args.length is 10) { - return OnProgressChange64_32 (args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9]); - } else { - return OnProgressChange64 (args[0], args[1], args[2], args[3], args[4], args[5]); - } - } - public int /*long*/ method9 (int /*long*/[] args) { - if (args.length is 8) { - return Init_32 (args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7]); - } else { - return Init (args[0], args[1], args[2], args[3], args[4], args[5], args[6]); - } - } - public int /*long*/ method10 (int /*long*/[] args) {return GetTargetFile (args[0]);} - public int /*long*/ method11 (int /*long*/[] args) {return GetPercentComplete (args[0]);} - public int /*long*/ method12 (int /*long*/[] args) {return GetAmountTransferred (args[0]);} - public int /*long*/ method13 (int /*long*/[] args) {return GetSize (args[0]);} - public int /*long*/ method14 (int /*long*/[] args) {return GetSource (args[0]);} - public int /*long*/ method15 (int /*long*/[] args) {return GetTarget (args[0]);} - public int /*long*/ method16 (int /*long*/[] args) {return GetCancelable (args[0]);} - public int /*long*/ method17 (int /*long*/[] args) {return GetDisplayName (args[0]);} - public int /*long*/ method18 (int /*long*/[] args) {return GetStartTime (args[0]);} - public int /*long*/ method19 (int /*long*/[] args) {return GetMIMEInfo (args[0]);} - public int /*long*/ method20 (int /*long*/[] args) {return Open (args[0]);} - public int /*long*/ method21 (int /*long*/[] args) {return GetCancelDownloadOnClose (args[0]);} - public int /*long*/ method22 (int /*long*/[] args) {return SetCancelDownloadOnClose ((int)/*64*/args[0]);} - public int /*long*/ method23 (int /*long*/[] args) {return GetObserver (args[0]);} - public int /*long*/ method24 (int /*long*/[] args) {return SetObserver (args[0]);} - public int /*long*/ method25 (int /*long*/[] args) {return GetDialog (args[0]);} - public int /*long*/ method26 (int /*long*/[] args) {return SetDialog (args[0]);} - }; - - webProgressListener = new XPCOMObject (new int[] {2, 0, 0, 4, 6, 3, 4, 3}) { - public int /*long*/ method0 (int /*long*/[] args) {return QueryInterface (args[0], args[1]);} - public int /*long*/ method1 (int /*long*/[] args) {return AddRef ();} - public int /*long*/ method2 (int /*long*/[] args) {return Release ();} - public int /*long*/ method3 (int /*long*/[] args) {return OnStateChange (args[0], args[1], (int)/*64*/args[2], (int)/*64*/args[3]);} - public int /*long*/ method4 (int /*long*/[] args) {return OnProgressChange (args[0], args[1], (int)/*64*/args[2], (int)/*64*/args[3], (int)/*64*/args[4], (int)/*64*/args[5]);} - public int /*long*/ method5 (int /*long*/[] args) {return OnLocationChange (args[0], args[1], args[2]);} - public int /*long*/ method6 (int /*long*/[] args) {return OnStatusChange (args[0], args[1], (int)/*64*/args[2], args[3]);} - public int /*long*/ method7 (int /*long*/[] args) {return OnSecurityChange (args[0], args[1], (int)/*64*/args[2]);} - }; -} - -void disposeCOMInterfaces() { - if (supports !is null) { - supports.dispose (); - supports = null; - } - if (download !is null) { - download.dispose (); - download = null; - } - if (progressDialog !is null) { - progressDialog.dispose (); - progressDialog = null; - } - if (webProgressListener !is null) { - webProgressListener.dispose (); - webProgressListener = null; - } -} - -int /*long*/ getAddress () { - return progressDialog.getAddress (); -} - -int QueryInterface (int /*long*/ riid, int /*long*/ ppvObject) { - if (riid is 0 || ppvObject is 0) return XPCOM.NS_ERROR_NO_INTERFACE; - nsID guid = new nsID (); - XPCOM.memmove (guid, riid, nsID.sizeof); - - if (guid.Equals (nsISupports.NS_ISUPPORTS_IID)) { - XPCOM.memmove (ppvObject, new int /*long*/[] {supports.getAddress ()}, C.PTR_SIZEOF); +int QueryInterface ( nsID* riid, void** ppvObject) { + if (riid is null || ppvObject is null) return XPCOM.NS_ERROR_NO_INTERFACE; + + if (*riid == nsISupports.IID)) { + *ppvObject = cast(void*)cast(nsISupports)this; AddRef(); return XPCOM.NS_OK; } - if (guid.Equals (nsIDownload_1_8.NS_IDOWNLOAD_IID)) { - XPCOM.memmove (ppvObject, new int /*long*/[] {download.getAddress ()}, C.PTR_SIZEOF); + if (*riid == nsIDownload_1_8.IID)) { + *ppvObject = cast(void*)cast(nsIDownload_1_8)this; AddRef(); return XPCOM.NS_OK; } - if (guid.Equals (nsIProgressDialog_1_8.NS_IPROGRESSDIALOG_IID)) { - XPCOM.memmove (ppvObject, new int /*long*/[] {progressDialog.getAddress ()}, C.PTR_SIZEOF); + if (*riid == nsIProgressDialog_1_8.IID) { + *ppvObject = cast(void*)cast(nsIProgressDialog_1_8)this; AddRef(); return XPCOM.NS_OK; } - if (guid.Equals (nsIWebProgressListener.NS_IWEBPROGRESSLISTENER_IID)) { - XPCOM.memmove (ppvObject, new int /*long*/[] {webProgressListener.getAddress ()}, C.PTR_SIZEOF); + if (*riid == nsIWebProgressListener.IID) { + *ppvObject = cast(void*)cast(nsIWebProgressListener)this; AddRef(); return XPCOM.NS_OK; } - XPCOM.memmove (ppvObject, new int /*long*/[] {0}, C.PTR_SIZEOF); + *ppvObject = null; return XPCOM.NS_ERROR_NO_INTERFACE; } int Release () { refCount--; - if (refCount is 0) disposeCOMInterfaces (); + if (refCount is 0) return 0; return refCount; } /* nsIDownload */ /* Note. The argument startTime is defined as a PRInt64. This translates into two java ints. */ -int Init_32 (int /*long*/ aSource, int /*long*/ aTarget, int /*long*/ aDisplayName, int /*long*/ aMIMEInfo, int /*long*/ startTime1, int /*long*/ startTime2, int /*long*/ aTempFile, int /*long*/ aCancelable) { +int Init_32 (nsIURI aSource, nsIURI aTarget, nsAstring* aDisplayName, nsIMIMEInfo aMIMEInfo, PRInt32 startTime1, PRIn32 startTime2, nsILocalFile aTempFile, nsICancelable aCancelable) { long startTime = (startTime2 << 32) + startTime1; return Init (aSource, aTarget, aDisplayName, aMIMEInfo, startTime, aTempFile, aCancelable); } -int Init (int /*long*/ aSource, int /*long*/ aTarget, int /*long*/ aDisplayName, int /*long*/ aMIMEInfo, long startTime, int /*long*/ aTempFile, int /*long*/ aCancelable) { - cancelable = new nsICancelable (aCancelable); - nsIURI source = new nsIURI (aSource); - int /*long*/ aSpec = XPCOM.nsEmbedCString_new (); - int rc = source.GetHost (aSpec); +int Init (nsIURI aSource, nsIURI aTarget, nsAstring* aDisplayName, nsIMIMEInfo aMIMEInfo, PRTime startTime, nsILocalFile aTempFile, nsICancelable aCancelable) { + // cancelable = new nsICancelable (aCancelable); + // nsIURI source = new nsIURI (aSource); + scope auto aSpec = new nsEmbedCString; + int rc = source.GetHost (cast(nsaSpec); if (rc !is XPCOM.NS_OK) Mozilla.error(rc); int length = XPCOM.nsEmbedCString_Length (aSpec); int /*long*/ buffer = XPCOM.nsEmbedCString_get (aSpec);
--- a/dwt/browser/FilePicker.d Thu Aug 07 15:02:44 2008 +0200 +++ b/dwt/browser/FilePicker.d Thu Aug 07 15:16:09 2008 +0200 @@ -8,446 +8,235 @@ * Contributors: * IBM Corporation - initial API and implementation * Port to the D programming language: - * John Reimer <terminal.node@gmail.com> + * John Reimer <terminal.node@gmail.com> *******************************************************************************/ - module dwt.browser.FilePicker; -import tango.io.model.IFile; -import Utf = tango.text.convert.Utf; - import dwt.dwthelper.utils; import dwt.DWT; -import XPCOM = dwt.internal.mozilla.nsXPCOM; - -import dwt.browser.Mozilla; -import dwt.browser.MozillaDelegate; - import dwt.internal.mozilla.nsEmbedString; -import dwt.internal.mozilla.nsIDOMWindow; import dwt.internal.mozilla.nsID; import dwt.internal.mozilla.nsIFilePicker; +import dwt.internal.mozilla.nsIFilePicker_1_8; import dwt.internal.mozilla.nsILocalFile; import dwt.internal.mozilla.nsISupports; -import dwt.internal.mozilla.nsSimpleEnumerator; -import dwt.internal.mozilla.nsStringAPI; -import dwt.internal.mozilla.nsError; - import dwt.widgets.DirectoryDialog; import dwt.widgets.Display; import dwt.widgets.FileDialog; import dwt.widgets.Shell; - -class FilePicker : nsISupports, nsIFilePicker -{ - /************************************************************************** - - **************************************************************************/ - - private - { - int _refCount = 0; - short _mode; - - nsIDOMWindow _parent; - - String[] _files; - String _masks; - String _defaultFilename, - _directory, - _title; - } - /************************************************************************** - - **************************************************************************/ - - static final String SEPARATOR = FileConst.FileSeparatorChar; - - /************************************************************************** - - **************************************************************************/ - - this () - { - } - - /************************************************************************** - - **************************************************************************/ +class FilePicker : nsIFilePicker { - nsrefcnt AddRef () - { - _refCount++; - return _refCount; - } - - /************************************************************************** - - **************************************************************************/ + int refCount = 0; + short mode; + nsIDOMWindow parentHandle; + String[] files, masks; + String defaultFilename, directory, title; - nsresult QueryInterface ( inout nsID riid, void** ppvObject) - { - if (riid is null || ppvObject is null) - return NS_ERROR_NO_INTERFACE; - - if (riid == nsISupports.IID) - { - *ppvObject = cast(void*)cast(nsISupports) this; - AddRef (); - return NS_OK; - } - - if (riid == nsIFilePicker.IID)) - { - *ppvObject = cast(void*)cast(nsIFilePicker) this; - AddRef (); - return NS_OK; - } - - if (riid == nsIFilePicker_1_8.IID) - { - *ppvObject = cast(void*)cast(nsIFilePicker_1_8) this; - AddRef (); - return NS_OK; - } - - *ppvObject = null; - return NS_ERROR_NO_INTERFACE; - } - - /************************************************************************** - - **************************************************************************/ + static final String SEPARATOR = System.getProperty ("file.separator"); //$NON-NLS-1$ - nsrefcnt Release () - { - _refCount--; - - if (_refCount is 0) - // No big deal here; just allow the GC to reap this object - // once all references are expired. -JJR - // delete this; - return 0; - - return _refCount; - } - - /************************************************************************** - - **************************************************************************/ - - /* SWT Comment: - * - * As of Mozilla 1.8 some of nsIFilePicker's string arguments changed type. This method - * answers a java string based on the type of string that is appropriate for the Mozilla - * version being used. - */ - - override String parseAString (nsEmbedString str) - { - return null; - } - - /************************************************************************** - - **************************************************************************/ - - /* nsIFilePicker */ - - nsresult Init (nsIDOMWindow parent, nsAString* title, PRInt16 mode) - { - _parent = parent; - _mode = mode; - _title = parseAString (title); - return XPCOM; - } - - /************************************************************************** - - **************************************************************************/ +this () { +} - nsresult Show (PRUint32* retval) - { - if (_mode is nsIFilePicker.modeGetFolder) - { - /* picking a directory */ - int result = this.showDirectoryPicker (); - *retval = result; - return NS_OK; - } - - /* picking a file */ - int style = _mode is nsIFilePicker.modeSave ? DWT.SAVE : DWT.OPEN; - - if (_mode is nsIFilePicker.modeOpenMultiple) - style |= DWT.MULTI; - - Display display = Display.getCurrent (); - Shell parent = null; // TODO compute parent - - if (parent is null) - { - parent = new Shell (display); - } +nsrefcnt AddRef () { + refCount++; + return refCount; +} - FileDialog dialog = new FileDialog (parent, style); - - if (_title !is null) - dialog.setText (_title); - - if (_directory !is null) - dialog.setFilterPath (_directory); - - if (_masks !is null) { - String[] str ~= _masks; - dialog.setFilterExtensions ( str ); - } - - if (_defaultFilename !is null) - dialog.setFileName (_defaultFilename); - - String filename = dialog.open (); - files = dialog.getFileNames (); - _directory = dialog.getFilterPath (); - _title = _defaultFilename = null; - _masks = null; - int result = filename is null ? nsIFilePicker.returnCancel : nsIFilePicker.returnOK; - *retval = result; +nsresult QueryInterface (nsID* riid, void** ppvObject) { + if (riid is null || ppvObject is null) return NS_ERROR_NO_INTERFACE; + + if (riid == nsISupports.IID) { + *ppvObject = cast(void*)cast(nsISupports) this; + AddRef (); return NS_OK; } - - /************************************************************************** - - **************************************************************************/ + if (riid == nsIFilePicker.IID)) { + *ppvObject = cast(void*)cast(nsIFilePicker) this; + AddRef (); + return NS_OK; + } + if (riid == nsIFilePicker_1_8.IID) { + *ppvObject = cast(void*)cast(nsIFilePicker_1_8) this; + AddRef (); + return NS_OK; + } + *ppvObject = null; + return NS_ERROR_NO_INTERFACE; +} + +nsrefcnt Release () { + refCount--; + if (refCount is 0) return 0; + return refCount; +} - int showDirectoryPicker () - { - Display display = Display.getCurrent (); - Shell parent = null; // TODO compute parent - - if (parent is null) - { - parent = new Shell (display); - } - - DirectoryDialog dialog = new DirectoryDialog (parent, DWT.NONE); - - if (_title !is null) - dialog.setText (_title); - if (_directory !is null) - dialog.setFilterPath (_directory); - _directory = dialog.open (); - _title = _defaultFilename = null; - _files = _masks = null; - return _directory is null ? nsIFilePicker.returnCancel : nsIFilePicker.returnOK; +/* + * As of Mozilla 1.8 some of nsIFilePicker's string arguments changed type. This method + * answers a java string based on the type of string that is appropriate for the Mozilla + * version being used. + */ +override String parseAString (nsAString* string) { + return null; +} + +/* nsIFilePicker */ + +nsresult Init (nsIDOMWindow parent, nsAString* title, PRInt16 mode) { + parentHandle = parent; + this.mode = mode; + this.title = parseAString (title); + return XPCOM.NS_OK; +} + +nsresult Show (PRUint32* _retval) { + if (mode is nsIFilePicker.modeGetFolder) { + /* picking a directory */ + int result = showDirectoryPicker (); + *_retval = cast(int)cast(short)result; /* PRInt16 */ + return XPCOM.NS_OK; } - /************************************************************************** - - **************************************************************************/ - - nsresult GetFiles ( nsISimpleEnumerator* aFiles) - { - return NS_ERROR_NOT_IMPLEMENTED; - } - - /************************************************************************** - - **************************************************************************/ - - nsresult GetFileURL (nsIFileURL aFileURL) - { - return NS_ERROR_NOT_IMPLEMENTED; + /* picking a file */ + int style = mode is nsIFilePicker.modeSave ? DWT.SAVE : DWT.OPEN; + if (mode is nsIFilePicker.modeOpenMultiple) style |= DWT.MULTI; + Display display = Display.getCurrent (); + Shell parent = null; // TODO compute parent + if (parent is null) { + parent = new Shell (display); } - - /************************************************************************** - - **************************************************************************/ - - nsresult GetFile (nsILocalFile* aFile) - { - String filename = ""; //$NON-NLS-1$ - - if (_directory !is null) - filename ~= _directory ~ SEPARATOR; - if (_files !is null && _files.length > 0) - filename ~= _files[0]; - - // Create a nsEmbedString which will be automatically disposed - // at the end of scope. - scope auto path = new nsEmbedString( filename ); - - nsresult rc = XPCOM.NS_NewLocalFile ( cast(nsAString*)path, 1, aFile); - - if (rc !is NS_OK) - Mozilla.error (rc); - if (aFile is null) - Mozilla.error (NS_ERROR_NULL_POINTER); - - return NS_OK; - } - - /************************************************************************** - - **************************************************************************/ + FileDialog dialog = new FileDialog (parent, style); + if (title !is null) dialog.setText (title); + if (directory !is null) dialog.setFilterPath (directory); + if (masks !is null) dialog.setFilterExtensions (masks); + if (defaultFilename !is null) dialog.setFileName (defaultFilename); + String filename = dialog.open (); + files = dialog.getFileNames (); + directory = dialog.getFilterPath (); + title = defaultFilename = null; + masks = null; + int result = filename is null ? nsIFilePicker.returnCancel : nsIFilePicker.returnOK; + *_retval = cast(int)cast(short)result;; /* PRInt16 */ + return XPCOM.NS_OK; +} - nsresult SetDisplayDirectory (nsILocalFile aDisplayDirectory) - { - if (aDisplayDirectory is null) - return NS_OK; - - scope auto pathname = new nsEmbedCString; - aDisplayDirectory.GetNativePath ( cast(nsACString*)pathname ); - // TODO: CHECK IF THIS DOES CORRECT STRING CONVERSION -JJR - char[] buffer = pathname.toString(); - char[] chars = MozillaDelegate.mbcsToWcs (null, buffer); - // "buffer" contains a dup'ed string so we can safely reuse - // it's memory for the _directory member. -JJR - _directory = buffer; - return NS_OK; +int showDirectoryPicker () { + Display display = Display.getCurrent (); + Shell parent = null; // TODO compute parent + if (parent is null) { + parent = new Shell (display); } + DirectoryDialog dialog = new DirectoryDialog (parent, DWT.NONE); + if (title !is null) dialog.setText (title); + if (directory !is null) dialog.setFilterPath (directory); + directory = dialog.open (); + title = defaultFilename = null; + files = masks = null; + return directory is null ? nsIFilePicker.returnCancel : nsIFilePicker.returnOK; +} - /************************************************************************** - - **************************************************************************/ +nsresult GetFiles (nsISimpleEnumerator* aFiles) { + return XPCOM.NS_ERROR_NOT_IMPLEMENTED; +} - nsresult GetDisplayDirectory (nsILocalFile* aDisplayDirectory) - { - String directoryName = _directory !is null ? _directory : ""; //$NON-NLS-1$ - scope auto path = new nsEmbedString (directoryName); - nsresult rc = XPCOM.NS_NewLocalFile ( cast(nsAString*)path, 1, aDisplayDirectory); - - if (rc !is NS_OK) - Mozilla.error (rc); - if (aDisplayDirectory is null) - Mozilla.error (NS_ERROR_NULL_POINTER); - return NS_OK; - } - - /************************************************************************** +nsresult GetFileURL ( nsIFileURL aFileURL ) { + return XPCOM.NS_ERROR_NOT_IMPLEMENTED; +} - **************************************************************************/ - - nsresult SetFilterIndex (PRInt32 aFilterIndex) - { - return NS_ERROR_NOT_IMPLEMENTED; - } - - /************************************************************************** +nsresult GetFile (nsILocalFile* aFile) { + String filename = ""; //$NON-NLS-1$ + if (directory !is null) filename ~= directory ~ SEPARATOR; + if (files !is null && files.length > 0) filename ~= files[0]; + scope auto path = new nsEmbedString (filename); + int rc = XPCOM.NS_NewLocalFile (cast(nsAString*)path, 1, aFile); + if (rc !is XPCOM.NS_OK) Mozilla.error (rc); + if (aFile is null) Mozilla.error (XPCOM.NS_ERROR_NULL_POINTER); + return XPCOM.NS_OK; +} - **************************************************************************/ - - nresult GetFilterIndex (PRInt32* aFilterIndex) - { - return NS_ERROR_NOT_IMPLEMENTED; - } - - /************************************************************************** +nsresult SetDisplayDirectory (nsILocalFile aDisplayDirectory) { + if (aDisplayDirectory is null) return XPCOM.NS_OK; + scope auto pathname = new nsEmbedCString(); + aDisplayDirectory.GetNativePath (cast(nsACString*)pathname); + // wchar[] chars = MozillaDelegate.mbcsToWcs (null, bytes); + directory = pathname.toString; + return XPCOM.NS_OK; +} - **************************************************************************/ - - int SetDefaultExtension (nsAString* aDefaultExtension) - { - /* note that the type of argument 1 changed as of Mozilla 1.8 */ - return NS_ERROR_NOT_IMPLEMENTED; - } - - /************************************************************************** +nsresult GetDisplayDirectory (nsILocalFile* aDisplayDirectory) { + String directoryName = directory !is null ? directory : ""; //$NON-NLS-1$ + scope auto path = new nsEmbedString (Utf.toString16(directoryName)); + int rc = XPCOM.NS_NewLocalFile (cast(nsAString*)path, 1, aDisplayDirectory); + if (rc !is XPCOM.NS_OK) Mozilla.error (rc); + if (aDisplayDirectory is null) Mozilla.error (XPCOM.NS_ERROR_NULL_POINTER); + return XPCOM.NS_OK; +} - **************************************************************************/ +nsresult SetFilterIndex (PRInt32 aFilterIndex) { + return XPCOM.NS_ERROR_NOT_IMPLEMENTED; +} - int GetDefaultExtension (nsAString* aDefaultExtension) - { - /* note that the type of argument 1 changed as of Mozilla 1.8 */ - return NS_ERROR_NOT_IMPLEMENTED; - } - - /************************************************************************** - - **************************************************************************/ +nsresult GetFilterIndex (PRInt32* aFilterIndex) { + return XPCOM.NS_ERROR_NOT_IMPLEMENTED; +} - nresult SetDefaultString (nsAString* aDefaultString) - { - defaultFilename = parseAString (aDefaultString); - return NS_OK; - } +nsresult SetDefaultExtension (nsAString* aDefaultExtension) { + /* note that the type of argument 1 changed as of Mozilla 1.8 */ + return XPCOM.NS_ERROR_NOT_IMPLEMENTED; +} - /************************************************************************** - - **************************************************************************/ +nsresult GetDefaultExtension (nsAString* aDefaultExtension) { + /* note that the type of argument 1 changed as of Mozilla 1.8 */ + return XPCOM.NS_ERROR_NOT_IMPLEMENTED; +} - nresult GetDefaultString (nsAString* aDefaultString) - { - /* note that the type of argument 1 changed as of Mozilla 1.8 */ - return NS_ERROR_NOT_IMPLEMENTED; - } - - /************************************************************************** - - **************************************************************************/ +nsresult SetDefaultString (nsAString* aDefaultString) { + defaultFilename = parseAString (aDefaultString); + return XPCOM.NS_OK; +} - nresult AppendFilter (nsAString* title, nsAString* filter) - { - /* note that the type of arguments 1 and 2 changed as of Mozilla 1.8 */ - return NS_ERROR_NOT_IMPLEMENTED; - } - - /************************************************************************** - - **************************************************************************/ +nsresult GetDefaultString (nsAString* aDefaultString) { + /* note that the type of argument 1 changed as of Mozilla 1.8 */ + return XPCOM.NS_ERROR_NOT_IMPLEMENTED; +} - nresult AppendFilters (PRInt32 filterMask) - { - String addFilters; - - switch (filterMask) - { - case nsIFilePicker.filterAll: - case nsIFilePicker.filterApps: - _masks = null; /* this is equivalent to no filter */ - break; - case nsIFilePicker.filterHTML: - addFilters = "*.htm;*.html" ; - break; - case nsIFilePicker.filterImages: - addFilters = "*.gif;*.jpeg;*.jpg;*.png"; - break; - case nsIFilePicker.filterText: - addFilters = "*.txt"; - break; - case nsIFilePicker.filterXML: - addFilters = "*.xml"; - break; - case nsIFilePicker.filterXUL: - addFilters = "*.xul"; - break; +nsresult AppendFilter (nsAString* title, nsAString* filter) { + /* note that the type of arguments 1 and 2 changed as of Mozilla 1.8 */ + return XPCOM.NS_ERROR_NOT_IMPLEMENTED; +} + +nsresult AppendFilters (PRInt32 filterMask) { + String[] addFilters = null; + switch (filterMask) { + case nsIFilePicker.filterAll: + case nsIFilePicker.filterApps: + masks = null; /* this is equivalent to no filter */ + break; + case nsIFilePicker.filterHTML: + addFilters[0] = "*.htm;*.html"; //$NON-NLS-1$ + break; + case nsIFilePicker.filterImages: + addFilters[0] = "*.gif;*.jpeg;*.jpg;*.png"; //$NON-NLS-1$ + break; + case nsIFilePicker.filterText: + addFilters[0] = "*.txt"; //$NON-NLS-1$ + break; + case nsIFilePicker.filterXML: + addFilters[0] = "*.xml"; //$NON-NLS-1$ + break; + case nsIFilePicker.filterXUL: + addFilters[0] = "*.xul"; //$NON-NLS-1$ + break; + } + if (masks is null) { + masks = addFilters; + } else { + if (addFilters !is null) { + masks ~= addFilters; } - - if (_masks is null) - { - _masks = addFilters; - } else { - if (addFilters !is null) - _masks ~= addFilters; - } - return NS_OK; } - -/****************************************************************************** - - FilePicker for Mozilla Version 1.8 - -******************************************************************************/ - -class FilePicker_1_8 : FilePicker -{ - String parseAString (nsEmbedString str) - { - if (str is null) - return null; - return Utf.toString( str.toString16() ); - } -} \ No newline at end of file + return XPCOM.NS_OK; +} +}
--- a/dwt/browser/FilePickerFactory.d Thu Aug 07 15:02:44 2008 +0200 +++ b/dwt/browser/FilePickerFactory.d Thu Aug 07 15:16:09 2008 +0200 @@ -7,121 +7,100 @@ * * Contributors: * IBM Corporation - initial API and implementation - * Port to the D programming language: - * John Reimer <terminal.node@gmail.com> *******************************************************************************/ - module dwt.browser.FilePickerFactory; import dwt.dwthelper.utils; +import dwt.internal.C; +import dwt.internal.mozilla.XPCOM; +import dwt.internal.mozilla.XPCOMObject; import dwt.internal.mozilla.nsID; -import dwt.internal.mozilla. import dwt.internal.mozilla.nsIFactory; import dwt.internal.mozilla.nsISupports; -class FilePickerFactory : nsISupports, nsIFactory -{ - - /************************************************************************** - - **************************************************************************/ - - int _refCount = 0; - - /************************************************************************** - - **************************************************************************/ +class FilePickerFactory { + XPCOMObject supports; + XPCOMObject factory; + int refCount = 0; - this () - { - } - - /************************************************************************** - - **************************************************************************/ +FilePickerFactory () { + createCOMInterfaces (); +} - nsrefcnt AddRef () - { - _refCount++; - return _refCount; - } - - /************************************************************************** - - **************************************************************************/ +int AddRef () { + refCount++; + return refCount; +} - int QueryInterface ( ref nsID riid, void** ppvObject) - { - if (riid is null || ppvObject is null) - return NS_ERROR_NO_INTERFACE; - - if (guid == nsISupports.IID)) - { - *ppvObject = cast(void*)cast(nsISupports) this; - AddRef (); - return NS_OK; - } +void createCOMInterfaces () { + /* Create each of the interfaces that this object implements */ + supports = new XPCOMObject (new int[] {2, 0, 0}) { + public int /*long*/ method0 (int /*long*/[] args) {return QueryInterface (args[0], args[1]);} + public int /*long*/ method1 (int /*long*/[] args) {return AddRef ();} + public int /*long*/ method2 (int /*long*/[] args) {return Release ();} + }; - if (guid == nsIFactory.IID) - { - *ppvObject = cast(void*)cast(nsIFactory) this; - AddRef (); - return NS_OK; - } - - *ppvObject = null; - return NS_ERROR_NO_INTERFACE; - } + factory = new XPCOMObject (new int[] {2, 0, 0, 3, 1}) { + public int /*long*/ method0 (int /*long*/[] args) {return QueryInterface (args[0], args[1]);} + public int /*long*/ method1 (int /*long*/[] args) {return AddRef ();} + public int /*long*/ method2 (int /*long*/[] args) {return Release ();} + public int /*long*/ method3 (int /*long*/[] args) {return CreateInstance (args[0], args[1], args[2]);} + public int /*long*/ method4 (int /*long*/[] args) {return LockFactory ((int)/*64*/args[0]);} + }; +} - /************************************************************************** +void disposeCOMInterfaces () { + if (supports !is null) { + supports.dispose (); + supports = null; + } + if (factory !is null) { + factory.dispose (); + factory = null; + } +} - **************************************************************************/ +int /*long*/ getAddress () { + return factory.getAddress (); +} - nsrefcnt Release () - { - _refCount--; - if (_refCount is 0) - return 0; - return _refCount; +int QueryInterface (int /*long*/ riid, int /*long*/ ppvObject) { + if (riid is 0 || ppvObject is 0) return XPCOM.NS_ERROR_NO_INTERFACE; + nsID guid = new nsID (); + XPCOM.memmove (guid, riid, nsID.sizeof); + + if (guid.Equals (nsISupports.NS_ISUPPORTS_IID)) { + XPCOM.memmove (ppvObject, new int /*long*/[] {supports.getAddress ()}, C.PTR_SIZEOF); + AddRef (); + return XPCOM.NS_OK; + } + if (guid.Equals (nsIFactory.NS_IFACTORY_IID)) { + XPCOM.memmove (ppvObject, new int /*long*/[] {factory.getAddress ()}, C.PTR_SIZEOF); + AddRef (); + return XPCOM.NS_OK; } - /************************************************************************** - - **************************************************************************/ - - /* nsIFactory */ + XPCOM.memmove (ppvObject, new int /*long*/[] {0}, C.PTR_SIZEOF); + return XPCOM.NS_ERROR_NO_INTERFACE; +} - nsresult CreateInstance (nsISupports aOuter, nsIID* iid, void** result) - { - if (result is null) - return NS_ERROR_INVALID_ARG; - - FilePicker picker = new FilePicker (); - picker.AddRef (); +int Release () { + refCount--; + if (refCount is 0) disposeCOMInterfaces (); + return refCount; +} + +/* nsIFactory */ - nsresult rv = picker.QueryInterface( iid, result ); - - // TODO: If the query fails, the error should be checked and the - // newly created object deleted. In C++, this is done - // like so: - // - // if (NS_FAILED(rv)) { - // *result = nsnull; - // delete picker; - // } - // - // Deletion of the object really isn't critical here for D, but - // it may be considered "good habit" to do anyway for XPCOM objects. - // For now, just return the rv value. NS_FAILED needs to be - // ported first. -JJR +int CreateInstance (int /*long*/ aOuter, int /*long*/ iid, int /*long*/ result) { + FilePicker picker = new FilePicker (); + picker.AddRef (); + XPCOM.memmove (result, new int /*long*/[] {picker.getAddress ()}, C.PTR_SIZEOF); + return XPCOM.NS_OK; +} - return rv; - } - - nsresult LockFactory (int lock) - { - return NS_OK; - } - -} \ No newline at end of file +int LockFactory (int lock) { + return XPCOM.NS_OK; +} +}
--- a/dwt/browser/FilePicker_1_8.d Thu Aug 07 15:02:44 2008 +0200 +++ b/dwt/browser/FilePicker_1_8.d Thu Aug 07 15:16:09 2008 +0200 @@ -7,57 +7,21 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Port to the D programming language: + * John Reimer <terminal.node@gmail.com> *******************************************************************************/ module dwt.browser.FilePicker_1_8; import dwt.dwthelper.utils; +import dwt.browser.FilePicker; import dwt.internal.mozilla.XPCOM; -import dwt.internal.mozilla.XPCOMObject; - -class FilePicker_1_8 extends FilePicker { - -void createCOMInterfaces () { - /* Create each of the interfaces that this object implements */ - supports = new XPCOMObject (new int[] {2, 0, 0}) { - public int /*long*/ method0 (int /*long*/[] args) {return QueryInterface (args[0], args[1]);} - public int /*long*/ method1 (int /*long*/[] args) {return AddRef ();} - public int /*long*/ method2 (int /*long*/[] args) {return Release ();} - }; +import dwt.internal.mozilla.nsStringAPI; - filePicker = new XPCOMObject (new int[] {2, 0, 0, 3, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}) { - public int /*long*/ method0 (int /*long*/[] args) {return QueryInterface (args[0], args[1]);} - public int /*long*/ method1 (int /*long*/[] args) {return AddRef ();} - public int /*long*/ method2 (int /*long*/[] args) {return Release ();} - public int /*long*/ method3 (int /*long*/[] args) {return Init (args[0], args[1], (short)args[2]);} - public int /*long*/ method4 (int /*long*/[] args) {return AppendFilters ((int)/*64*/args[0]);} - public int /*long*/ method5 (int /*long*/[] args) {return AppendFilter (args[0], args[1]);} - public int /*long*/ method6 (int /*long*/[] args) {return GetDefaultString (args[0]);} - public int /*long*/ method7 (int /*long*/[] args) {return SetDefaultString (args[0]);} - public int /*long*/ method8 (int /*long*/[] args) {return GetDefaultExtension (args[0]);} - public int /*long*/ method9 (int /*long*/[] args) {return SetDefaultExtension (args[0]);} - public int /*long*/ method10 (int /*long*/[] args) {return GetFilterIndex (args[0]);} - public int /*long*/ method11 (int /*long*/[] args) {return SetFilterIndex ((int)/*64*/args[0]);} - public int /*long*/ method12 (int /*long*/[] args) {return GetDisplayDirectory (args[0]);} - public int /*long*/ method13 (int /*long*/[] args) {return SetDisplayDirectory (args[0]);} - public int /*long*/ method14 (int /*long*/[] args) {return GetFile (args[0]);} - public int /*long*/ method15 (int /*long*/[] args) {return GetFileURL (args[0]);} - public int /*long*/ method16 (int /*long*/[] args) {return GetFiles (args[0]);} - public int /*long*/ method17 (int /*long*/[] args) {return Show (args[0]);} - }; -} +class FilePicker_1_8 : FilePicker { -/* - * As of Mozilla 1.8 some of nsIFilePicker's string arguments changed type. This method - * answers a java string based on the type of string that is appropriate for the Mozilla - * version being used. - */ -String parseAString (int /*long*/ string) { - if (string is 0) return null; - int length = XPCOM.nsEmbedString_Length (string); - int /*long*/ buffer = XPCOM.nsEmbedString_get (string); - char[] chars = new char[length]; - XPCOM.memmove (chars, buffer, length * 2); - return new String (chars); +String parseAString (nsAString* string) { + if (string is null) return null; + return Utf.toString(nsAString.getString16(string)); } }
--- a/dwt/browser/InputStream.d Thu Aug 07 15:02:44 2008 +0200 +++ b/dwt/browser/InputStream.d Thu Aug 07 15:16:09 2008 +0200 @@ -7,171 +7,129 @@ * * Contributors: * IBM Corporation - initial API and implementation - * Port to the D programming language: - * John Reimer <terminal.node@gmail.com> *******************************************************************************/ - module dwt.browser.InputStream; import dwt.dwthelper.utils; -import dwt.internal.mozilla.nsError; +import dwt.internal.C; +import dwt.internal.mozilla.XPCOM; +import dwt.internal.mozilla.XPCOMObject; import dwt.internal.mozilla.nsID; import dwt.internal.mozilla.nsIInputStream; import dwt.internal.mozilla.nsISupports; -import Math = tango.math.Math; - -/****************************************************************************** - - COMMENTS: SWT implements this class as a replacement for the XPCOM - implementation; it may be possible to use the XPCOM one instead - (which also may be safer for D), but for now we'll follow SWT's example - and use this reimplementation of InputStream. It should be trivial to - move over to strict XPCOM implementation should the need arise. It appears - that the Java SWT source uses many workarounds in order to use the XPCOM - interface. For D, I remove much of the Java layered callback - approach since it is no longer necessary. -JJR - -******************************************************************************/ +class InputStream { + XPCOMObject inputStream; + int refCount = 0; -class InputStream : nsIInputStream -{ - int _refCount = 0; - int _index = 0; - byte[] _buffer; - - /************************************************************************** - - **************************************************************************/ + byte[] buffer; + int index = 0; + +InputStream (byte[] buffer) { + this.buffer = buffer; + index = 0; + createCOMInterfaces (); +} - this (byte[] buffer) - { - this._buffer = buffer; - index = 0; - } - - /************************************************************************** - - **************************************************************************/ +int AddRef () { + refCount++; + return refCount; +} - nsrefcnt AddRef () - { - _refCount++; - return _refCount; - } - - /************************************************************************** - - **************************************************************************/ +void createCOMInterfaces () { + /* Create each of the interfaces that this object implements */ + inputStream = new XPCOMObject (new int[] {2, 0, 0, 0, 1, 3, 4, 1}) { + public int /*long*/ method0 (int /*long*/[] args) {return QueryInterface (args[0], args[1]);} + public int /*long*/ method1 (int /*long*/[] args) {return AddRef ();} + public int /*long*/ method2 (int /*long*/[] args) {return Release ();} + public int /*long*/ method3 (int /*long*/[] args) {return Close ();} + public int /*long*/ method4 (int /*long*/[] args) {return Available (args[0]);} + public int /*long*/ method5 (int /*long*/[] args) {return Read (args[0], (int)/*64*/args[1], args[2]);} + public int /*long*/ method6 (int /*long*/[] args) {return ReadSegments (args[0], args[1], (int)/*64*/args[2], args[3]);} + public int /*long*/ method7 (int /*long*/[] args) {return IsNonBlocking (args[0]);} + }; +} - nsresult QueryInterface ( inout nsID riid, void** ppvObject) - { - if (riid is null || ppvObject is null) - return NS_ERROR_NO_INTERFACE; - - nsID guid = riid; - - if (guid == nsISupports.NS_ISUPPORTS_IID) - { - *ppvObject = cast(void*)cast(nsISupports) this; - this.AddRef (); - return NS_OK; - } +void disposeCOMInterfaces () { + if (inputStream !is null) { + inputStream.dispose (); + inputStream = null; + } +} - if (guid == nsIInputStream.NS_IINPUTSTREAM_IID) - { - *ppvObject = cast(void*)cast(nsIInputStream) this; - this.AddRef (); - return NS_OK; - } - - *ppvObject = null; - return NS_ERROR_NO_INTERFACE; - } - - /************************************************************************** - - **************************************************************************/ +int /*long*/ getAddress () { + return inputStream.getAddress (); +} - nsrefcnt Release () - { - _refCount--; - if (_refCount is 0) - return 0 - // delete this; - return _refCount; +int QueryInterface (int /*long*/ riid, int /*long*/ ppvObject) { + if (riid is 0 || ppvObject is 0) return XPCOM.NS_ERROR_NO_INTERFACE; + nsID guid = new nsID (); + XPCOM.memmove (guid, riid, nsID.sizeof); + + if (guid.Equals (nsISupports.NS_ISUPPORTS_IID)) { + XPCOM.memmove (ppvObject, new int /*long*/[] {inputStream.getAddress ()}, C.PTR_SIZEOF); + AddRef (); + return XPCOM.NS_OK; } + if (guid.Equals (nsIInputStream.NS_IINPUTSTREAM_IID)) { + XPCOM.memmove (ppvObject, new int /*long*/[] {inputStream.getAddress ()}, C.PTR_SIZEOF); + AddRef (); + return XPCOM.NS_OK; + } + XPCOM.memmove (ppvObject, new int /*long*/[] {0}, C.PTR_SIZEOF); + return XPCOM.NS_ERROR_NO_INTERFACE; +} + +int Release () { + refCount--; + if (refCount is 0) disposeCOMInterfaces (); + return refCount; +} - /************************************************************************** - - **************************************************************************/ +/* nsIInputStream implementation */ - nsresult Close () - { - _buffer = null; - _index = 0; - return NS_OK; - } - - /************************************************************************** - - **************************************************************************/ - - nsresult Available ( PRUint32* retval) - { - PRUint32 available = buffer is null ? 0 : buffer.length - _index; - *retval = available; - return NS_OK; - } - - /************************************************************************** - - **************************************************************************/ +int Close () { + buffer = null; + index = 0; + return XPCOM.NS_OK; +} - nsresult Read(byte* aBuf, PRUint32 aCount, PRUint32* retval) - { - int max = Math.min (aCount, _buffer is null ? 0 : _buffer.length - _index); - - if (max > 0) - { - aBuf[0..max] = _buffer[_index..$]; - _index += max; - } +int Available (int /*long*/ _retval) { + int available = buffer is null ? 0 : buffer.length - index; + XPCOM.memmove (_retval, new int[] {available}, 4); + return XPCOM.NS_OK; +} - *retval = max; - return NS_OK; +int Read(int /*long*/ aBuf, int aCount, int /*long*/ _retval) { + int max = Math.min (aCount, buffer is null ? 0 : buffer.length - index); + if (max > 0) { + byte[] src = new byte[max]; + System.arraycopy (buffer, index, src, 0, max); + XPCOM.memmove (aBuf, src, max); + index += max; } - - /************************************************************************** - - **************************************************************************/ + XPCOM.memmove(_retval, new int[] {max}, 4); + return XPCOM.NS_OK; +} - nsresult ReadSegments (nsWriteSegmentFun aWriter, void* aClosure, PRUint32 aCount, PRUint32* retval) - { - int max = Math.min (aCount, buffer is null ? 0 : buffer.length - _index); - PRUint32 cnt = max; - - while (cnt > 0) - { - PRUint32 aWriteCount; - nsresult rc = aWriter ( cast(nsIInputStream)this, aClosure, buffer.ptr, _index, cnt, &aWriteCount); - if (rc !is NS_OK) break; - _index += aWriteCount; - cnt -= aWriteCount; - } +int ReadSegments (int /*long*/ aWriter, int /*long*/ aClosure, int aCount, int /*long*/ _retval) { + int max = Math.min (aCount, buffer is null ? 0 : buffer.length - index); + int cnt = max; + while (cnt > 0) { + int[] aWriteCount = new int[1]; + int /*long*/ rc = XPCOM.Call (aWriter, getAddress (), aClosure, buffer, index, cnt, aWriteCount); + if (rc !is XPCOM.NS_OK) break; + index += aWriteCount[0]; + cnt -= aWriteCount[0]; + } + XPCOM.memmove (_retval, new int[] {max - cnt}, 4); + return XPCOM.NS_OK; +} - *retval = (max - cnt); - return NS_OK; - } - - /************************************************************************** - - **************************************************************************/ - - nsresult IsNonBlocking ( PRUint32* retval) - { - *retval = 0; - return NS_OK; - } +int IsNonBlocking (int /*long*/ _retval) { + /* blocking */ + XPCOM.memmove (_retval, new int[] {0}, 4); + return XPCOM.NS_OK; +} }
--- a/dwt/browser/LocationAdapter.d Thu Aug 07 15:02:44 2008 +0200 +++ b/dwt/browser/LocationAdapter.d Thu Aug 07 15:16:09 2008 +0200 @@ -7,13 +7,9 @@ * * Contributors: * IBM Corporation - initial API and implementation - * Port to the D programming language: - * John Reimer <terminal.node@gmail.com> *******************************************************************************/ module dwt.browser.LocationAdapter; -import dwt.browser.LocationListener; -import dwt.browser.LocationEvent; import dwt.dwthelper.utils; /** @@ -27,11 +23,11 @@ * * @since 3.0 */ -public abstract class LocationAdapter : LocationListener { +public abstract class LocationAdapter implements LocationListener { - public void changing(LocationEvent event) { - } +public void changing(LocationEvent event) { +} - public void changed(LocationEvent event) { - } +public void changed(LocationEvent event) { } +}
--- a/dwt/browser/LocationEvent.d Thu Aug 07 15:02:44 2008 +0200 +++ b/dwt/browser/LocationEvent.d Thu Aug 07 15:16:09 2008 +0200 @@ -8,7 +8,7 @@ * Contributors: * IBM Corporation - initial API and implementation * Port to the D programming language: - * John Reimer <terminal.node@gmail.com> + * John Reimer <terminal.node@gmail.com> *******************************************************************************/ module dwt.browser.LocationEvent; @@ -55,12 +55,8 @@ * * @return a string representation of the event */ -public String toString() { - String string = super.toString (); - return string.substring (0, string.length() - 1) // remove trailing '}' - + " location=" + location - + " top=" + top - + " doit=" + doit - + "}"; +public override String toString() { + return Format( "{} {location = {}, top = {}, doit = {}}", + super.toString[1 .. $-2], location, top, doit ); } }
--- a/dwt/browser/Mozilla.d Thu Aug 07 15:02:44 2008 +0200 +++ b/dwt/browser/Mozilla.d Thu Aug 07 15:16:09 2008 +0200 @@ -7,13 +7,19 @@ * * Contributors: * IBM Corporation - initial API and implementation - * Port to the D programming language: - * John Reimer <terminal.node@gmail.com> *******************************************************************************/ module dwt.browser.Mozilla; import dwt.dwthelper.utils; +//import java.io.UnsupportedEncodingException; +//import java.lang.reflect.Constructor; +//import java.lang.reflect.InvocationTargetException; +//import java.lang.reflect.Method; +//import java.util.Enumeration; +//import java.util.Locale; +//import java.util.Vector; + import dwt.DWT; import dwt.DWTError; import dwt.graphics.Device; @@ -24,9 +30,10 @@ import dwt.internal.LONG; import dwt.internal.Library; +import dwt.internal.mozilla.XPCOM; +import dwt.internal.mozilla.XPCOMInit; + import dwt.internal.mozilla.nsEmbedString; -import dwt.internal.mozilla.nsError; - import dwt.internal.mozilla.nsIAppShell; import dwt.internal.mozilla.nsIBaseWindow; import dwt.internal.mozilla.nsICategoryManager; @@ -59,6 +66,7 @@ import dwt.internal.mozilla.nsIPrefLocalizedString; import dwt.internal.mozilla.nsIPrefService; import dwt.internal.mozilla.nsIProperties; +import dwt.internal.mozilla.nsIRequest; import dwt.internal.mozilla.nsIServiceManager; import dwt.internal.mozilla.nsISimpleEnumerator; import dwt.internal.mozilla.nsISupports; @@ -76,7 +84,6 @@ import dwt.internal.mozilla.nsIWebProgress; import dwt.internal.mozilla.nsIWebProgressListener; import dwt.internal.mozilla.nsIWindowWatcher; - import dwt.layout.FillLayout; import dwt.widgets.Composite; import dwt.widgets.Display; @@ -86,28 +93,45 @@ import dwt.widgets.Menu; import dwt.widgets.Shell; -class Mozilla : nsIWebBrowser, nsIWeakReference, - nsIWebProgressListener, nsIWebBrowserChrome, - nsIWebBrowserChromeFocus, nsIEmbeddingSiteWindow, - nsIInterfaceRequestor, nsISupportsWeakReference, - nsIContextMenuListener, nsIUriContentListener, - nsIToolTipListener, nsIDOMEventListener -{ - int /*long*/ embedHandle; - nsIWebBrowser webBrowser; - Object webBrowserObject; +class Mozilla : WebBrowser, + nsIWeakReference, + nsIWebProgressListener, + nsIWebBrowserChrome, + nsIWebBrowserFocus, + nsIEmbeddingSiteWindow, + nsIInterfaceRequestor, + nsISupportsWeakReference, + nsIContextMenuListener, + nsIUriContextListener, + nsITooltipListener, + nsIDomEventListener { + + GtkWidget* embedHandle; + nsIWebBrowser webBrowser; + Object webBrowserObject; MozillaDelegate mozDelegate; + /* Interfaces for this Mozilla embedding notification */ +// XPCOMObject supports; +// XPCOMObject weakReference; +// XPCOMObject webProgressListener; +// XPCOMObject webBrowserChrome; +// XPCOMObject webBrowserChromeFocus; +// XPCOMObject embeddingSiteWindow; +// XPCOMObject interfaceRequestor; +// XPCOMObject supportsWeakReference; +// XPCOMObject contextMenuListener; +// XPCOMObject uriContentListener; +// XPCOMObject tooltipListener; +// XPCOMObject domEventListener; int chromeFlags = nsIWebBrowserChrome.CHROME_DEFAULT; int refCount, lastKeyCode, lastCharCode; - int /*long*/ request; + nsIRequest request; Point location, size; bool visible, isChild, ignoreDispose, awaitingNavigate; Shell tip = null; Listener listener; - - // replace with appropriate D/Tango data structure - Vector unhookedDOMWindows = new Vector (); + nsIDOMWindow[] unhookedDOMWindows; static nsIAppShell AppShell; static AppFileLocProvider LocationProvider; @@ -154,7 +178,7 @@ // TEMPORARY CODE static final String GRE_INITIALIZED = "dwt.browser.XULRunnerInitialized"; //$NON-NLS-1$ - static { + static this () { MozillaClearSessions = new Runnable () { public void run () { if (!Initialized) return; @@ -2045,68 +2069,65 @@ /* nsISupports */ -int QueryInterface (int /*long*/ riid, int /*long*/ ppvObject) { - if (riid is 0 || ppvObject is 0) return XPCOM.NS_ERROR_NO_INTERFACE; +int QueryInterface (nsID* riid, void** ppvObject) { + if (riid is null || ppvObject is null) return XPCOM.NS_ERROR_NO_INTERFACE; - nsID guid = new nsID (); - XPCOM.memmove (guid, riid, nsID.sizeof); - - if (guid.Equals (nsISupports.NS_ISUPPORTS_IID)) { - XPCOM.memmove (ppvObject, new int /*long*/[] {supports.getAddress ()}, C.PTR_SIZEOF); + if (*riid == nsISupports.IID) { + *ppvObject = cast(void*)cast(nsISupports)this; + AddRef (); + return XPCOM.NS_OK; + } + if (*riid == nsIWeakReference.IID) { + *ppvObject = cast(void*)cast(nsIWeakReference)this; AddRef (); return XPCOM.NS_OK; } - if (guid.Equals (nsIWeakReference.NS_IWEAKREFERENCE_IID)) { - XPCOM.memmove (ppvObject, new int /*long*/[] {weakReference.getAddress ()}, C.PTR_SIZEOF); + if (*riid == nsIWebProgressListener.IID) { + *ppvObject = cast(void*)cast(nsIWebProgressListener)this; AddRef (); return XPCOM.NS_OK; } - if (guid.Equals (nsIWebProgressListener.NS_IWEBPROGRESSLISTENER_IID)) { - XPCOM.memmove (ppvObject, new int /*long*/[] {webProgressListener.getAddress ()}, C.PTR_SIZEOF); + if (*riid == nsIWebBrowserChrome.IID) { + *ppvObject = cast(void*)cast(nsIWebBrowserChrome)this; AddRef (); return XPCOM.NS_OK; } - if (guid.Equals (nsIWebBrowserChrome.NS_IWEBBROWSERCHROME_IID)) { - XPCOM.memmove (ppvObject, new int /*long*/[] {webBrowserChrome.getAddress ()}, C.PTR_SIZEOF); - AddRef (); - return XPCOM.NS_OK; - } - if (guid.Equals (nsIWebBrowserChromeFocus.NS_IWEBBROWSERCHROMEFOCUS_IID)) { - XPCOM.memmove (ppvObject, new int /*long*/[] {webBrowserChromeFocus.getAddress ()}, C.PTR_SIZEOF); + if (*riid == nsIWebBrowserChromeFocus.IID) { + *ppvObject = cast(void*)cast(nsIWebBrowserChromeFocus)this; AddRef (); return XPCOM.NS_OK; } - if (guid.Equals (nsIEmbeddingSiteWindow.NS_IEMBEDDINGSITEWINDOW_IID)) { - XPCOM.memmove (ppvObject, new int /*long*/[] {embeddingSiteWindow.getAddress ()}, C.PTR_SIZEOF); + if (*riid == nsIEmbeddingSiteWindow.IID) { + *ppvObject = cast(void*)cast(nsIEmbeddingSiteWindow)this; AddRef (); return XPCOM.NS_OK; } - if (guid.Equals (nsIInterfaceRequestor.NS_IINTERFACEREQUESTOR_IID)) { - XPCOM.memmove (ppvObject, new int /*long*/[] {interfaceRequestor.getAddress ()}, C.PTR_SIZEOF); + if (*riid == nsIInterfaceRequestor.IID) { + *ppvObject = cast(void*)cast(nsIInterfaceRequestor)this; AddRef (); return XPCOM.NS_OK; } - if (guid.Equals (nsISupportsWeakReference.NS_ISUPPORTSWEAKREFERENCE_IID)) { - XPCOM.memmove (ppvObject, new int /*long*/[] {supportsWeakReference.getAddress ()}, C.PTR_SIZEOF); + if (*riid == nsISupportsWeakReference.IID) { + *ppvObject = cast(void*)cast(nsISupportsWeakReference)this; AddRef (); return XPCOM.NS_OK; } - if (guid.Equals (nsIContextMenuListener.NS_ICONTEXTMENULISTENER_IID)) { - XPCOM.memmove (ppvObject, new int /*long*/[] {contextMenuListener.getAddress ()}, C.PTR_SIZEOF); + if (*riid == nsIContextMenuListener.IID) { + *ppvObject = cast(void*)cast(nsIContextMenuListener)this; AddRef (); return XPCOM.NS_OK; } - if (guid.Equals (nsIURIContentListener.NS_IURICONTENTLISTENER_IID)) { - XPCOM.memmove (ppvObject, new int /*long*/[] {uriContentListener.getAddress ()}, C.PTR_SIZEOF); + if (*riid == nsIURIContentListener.IID) { + *ppvObject = cast(void*)cast(nsIUriContentListener)this; AddRef (); return XPCOM.NS_OK; } - if (guid.Equals (nsITooltipListener.NS_ITOOLTIPLISTENER_IID)) { - XPCOM.memmove (ppvObject, new int /*long*/[] {tooltipListener.getAddress ()}, C.PTR_SIZEOF); + if (*riid == nsITooltipListener.IID)) { + *ppvObject = cast(void*)cast(nsITooltipListener)this; AddRef (); return XPCOM.NS_OK; } - XPCOM.memmove (ppvObject, new int /*long*/[] {0}, C.PTR_SIZEOF); + *ppvObject = null; return XPCOM.NS_ERROR_NO_INTERFACE; } @@ -2117,19 +2138,19 @@ int Release () { refCount--; - if (refCount is 0) disposeCOMInterfaces (); + if (refCount is 0) return 0; return refCount; } /* nsIWeakReference */ -int QueryReferent (int /*long*/ riid, int /*long*/ ppvObject) { +int QueryReferent (nsID* riid, void** ppvObject) { return QueryInterface (riid, ppvObject); } /* nsIInterfaceRequestor */ -int GetInterface (int /*long*/ riid, int /*long*/ ppvObject) { +int GetInterface ( nsID* riid, void** ppvObject) { if (riid is 0 || ppvObject is 0) return XPCOM.NS_ERROR_NO_INTERFACE; nsID guid = new nsID (); XPCOM.memmove (guid, riid, nsID.sizeof);
--- a/dwt/browser/MozillaDelegate.d Thu Aug 07 15:02:44 2008 +0200 +++ b/dwt/browser/MozillaDelegate.d Thu Aug 07 15:16:09 2008 +0200 @@ -7,6 +7,8 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Port to the D programming language: + * John Reimer <terminal.node@gmail.com> *******************************************************************************/ module dwt.browser.MozillaDelegate; @@ -24,20 +26,21 @@ class MozillaDelegate { Browser browser; - int /*long*/ mozillaHandle, embedHandle; + gpointer mozillaHandle; + GtkWidget* embedHandle; bool hasFocus; Listener listener; - static Callback eventCallback; - static int /*long*/ eventProc; - static final int STOP_PROPOGATE = 1; + //static Callback eventCallback; + // static int /*long*/ eventProc; + static const gpointer STOP_PROPOGATE = cast(gpointer)1; static bool IsLinux; - static { - String osName = System.getProperty ("os.name").toLowerCase (); //$NON-NLS-1$ - IsLinux = osName.startsWith ("linux"); //$NON-NLS-1$ + static this { + String osName = System.getProperty ("os.name"); //$NON-NLS-1$ + IsLinux = tango.text.Util.containsPattern(osName, "linux"); //$NON-NLS-1$ } -MozillaDelegate (Browser browser) { +this (Browser browser) { super (); if (!IsLinux) { browser.dispose (); @@ -46,27 +49,27 @@ this.browser = browser; } -static int /*long*/ eventProc (int /*long*/ handle, int /*long*/ gdkEvent, int /*long*/ pointer) { - int /*long*/ parent = OS.gtk_widget_get_parent (handle); +static extern(C) int eventProc (GtkWidget* handle, GdkEvent* gdkEvent, gpointer pointer) { + GtkWidget* parent = OS.gtk_widget_get_parent (handle); parent = OS.gtk_widget_get_parent (parent); - if (parent is 0) return 0; + if (parent is null) return 0; Widget widget = Display.getCurrent ().findWidget (parent); - if (widget !is null && widget instanceof Browser) { - return ((Mozilla)((Browser)widget).webBrowser).delegate.gtk_event (handle, gdkEvent, pointer); + if (widget !is null && (cast(Browser)widget !is null) { + return (cast(Mozilla)(cast(Browser)widget).webBrowser).mozDelegate.gtk_event (handle, gdkEvent, pointer); } return 0; } -static Browser findBrowser (int /*long*/ handle) { +static Browser findBrowser (GtkWidget* handle) { /* * Note. On GTK, Mozilla is embedded into a GtkHBox handle * and not directly into the parent Composite handle. */ - int /*long*/ parent = OS.gtk_widget_get_parent (handle); + GtkWidget* parent = OS.gtk_widget_get_parent (handle); Display display = Display.getCurrent (); - return (Browser)display.findWidget (parent); + return cast(Browser)display.findWidget (parent); } - +/* static char[] mbcsToWcs (String codePage, byte [] buffer) { return Converter.mbcsToWcs (codePage, buffer); } @@ -74,8 +77,8 @@ static byte[] wcsToMbcs (String codePage, String string, bool terminate) { return Converter.wcsToMbcs (codePage, string, terminate); } - -int /*long*/ getHandle () { +*/ +GtkWidget* getHandle () { /* * Bug in Mozilla Linux GTK. Embedding Mozilla into a GtkFixed * handle causes problems with some Mozilla plug-ins. For some @@ -96,13 +99,13 @@ return "libxpcom.so"; //$NON-NLS-1$ } +/* String getSWTInitLibraryName () { return "swt-xpcominit"; //$NON-NLS-1$ } +*/ -int /*long*/ gtk_event (int /*long*/ handle, int /*long*/ gdkEvent, int /*long*/ pointer) { - GdkEvent event = new GdkEvent (); - OS.memmove (event, gdkEvent, GdkEvent.sizeof); +int gtk_event (GtkWidget* handle, GdkEvent* event, gpointer pointer) { if (event.type is OS.GDK_BUTTON_PRESS) { if (!hasFocus) browser.setFocus (); } @@ -121,7 +124,7 @@ listener = new Listener () { public void handleEvent (Event event) { if (event.widget is browser) return; - ((Mozilla)browser.webBrowser).Deactivate (); + (cast(Mozilla)(browser.webBrowser)).Deactivate (); hasFocus = false; browser.getDisplay ().removeFilter (DWT.FocusIn, this); browser.getShell ().removeListener (DWT.Deactivate, this); @@ -138,7 +141,7 @@ browser.getDisplay ().asyncExec (new Runnable () { public void run () { if (browser is null || browser.isDisposed ()) return; - ((Mozilla)browser.webBrowser).Activate (); + (cast(Mozilla)(browser.webBrowser)).Activate (); } }); } @@ -148,15 +151,15 @@ return false; } -void init () { +void init () { /* if (eventCallback is null) { eventCallback = new Callback (getClass (), "eventProc", 3); //$NON-NLS-1$ eventProc = eventCallback.getAddress (); - if (eventProc is 0) { + if (eventProc is null) { browser.dispose (); Mozilla.error (DWT.ERROR_NO_MORE_CALLBACKS); } - } + } */ /* * Feature in Mozilla. GtkEvents such as key down, key pressed may be consumed @@ -166,14 +169,14 @@ * forward the event to the parent embedder before Mozilla received and consumed * them. */ - int /*long*/ list = OS.gtk_container_get_children (embedHandle); - if (list !is 0) { + GList* list = OS.gtk_container_get_children (embedHandle); + if (list !is null) { mozillaHandle = OS.g_list_data (list); OS.g_list_free (list); - if (mozillaHandle !is 0) { + if (mozillaHandle !is null) { /* Note. Callback to get events before Mozilla receives and consumes them. */ - OS.g_signal_connect (mozillaHandle, OS.event, eventProc, 0); + OS.g_signal_connect (mozillaHandle, OS.event, cast(GCallback)&eventProc, null); /* * Note. Callback to get the events not consumed by Mozilla - and to block @@ -181,9 +184,9 @@ * This hook is set after Mozilla and is therefore called after Mozilla's * handler because GTK dispatches events in their order of registration. */ - OS.g_signal_connect (mozillaHandle, OS.key_press_event, eventProc, STOP_PROPOGATE); - OS.g_signal_connect (mozillaHandle, OS.key_release_event, eventProc, STOP_PROPOGATE); - OS.g_signal_connect (mozillaHandle, OS.button_press_event, eventProc, STOP_PROPOGATE); + OS.g_signal_connect (mozillaHandle, OS.key_press_event, cast(GCallback)&eventProc, STOP_PROPOGATE); + OS.g_signal_connect (mozillaHandle, OS.key_release_event, cast(GCallback)&eventProc, STOP_PROPOGATE); + OS.g_signal_connect (mozillaHandle, OS.button_press_event, cast(GCallback)&eventProc, STOP_PROPOGATE); } } } @@ -201,7 +204,7 @@ browser = null; } -void setSize (int /*long*/ embedHandle, int width, int height) { +void setSize (GtkWidget* embedHandle, int width, int height) { OS.gtk_widget_set_size_request (embedHandle, width, height); }
--- a/dwt/browser/ProgressEvent.d Thu Aug 07 15:02:44 2008 +0200 +++ b/dwt/browser/ProgressEvent.d Thu Aug 07 15:16:09 2008 +0200 @@ -7,8 +7,6 @@ * * Contributors: * IBM Corporation - initial API and implementation - * Port to the D programming language: - * John Reimer <terminal.node@gmail.com> *******************************************************************************/ module dwt.browser.ProgressEvent; @@ -25,7 +23,7 @@ * * @since 3.0 */ -public class ProgressEvent : TypedEvent { +public class ProgressEvent extends TypedEvent { /** current value */ public int current; /** total value */ @@ -33,19 +31,21 @@ static final long serialVersionUID = 3977018427045393972L; - this(Widget w) { - super(w); - } +ProgressEvent(Widget w) { + super(w); +} - /** - * Returns a string containing a concise, human-readable - * description of the receiver. - * - * @return a string representation of the event - */ - - public override String toString () { - return Format( "ProgressEvent { current={} total={} }", - current, total ); - } +/** + * Returns a string containing a concise, human-readable + * description of the receiver. + * + * @return a string representation of the event + */ +public String toString() { + String string = super.toString (); + return string.substring (0, string.length() - 1) // remove trailing '}' + + " current=" + current + + " total=" + total + + "}"; } +}
--- a/dwt/browser/PromptDialog.d Thu Aug 07 15:02:44 2008 +0200 +++ b/dwt/browser/PromptDialog.d Thu Aug 07 15:16:09 2008 +0200 @@ -7,6 +7,8 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Port to the D programming language: + * John Reimer <terminal.node@gmail.com> *******************************************************************************/ module dwt.browser.PromptDialog; @@ -27,19 +29,19 @@ import dwt.widgets.Text; import dwt.widgets.Widget; -class PromptDialog extends Dialog { +class PromptDialog : Dialog { - PromptDialog(Shell parent, int style) { + this(Shell parent, int style) { super(parent, style); } - PromptDialog(Shell parent) { + this(Shell parent) { this(parent, 0); } - void alertCheck(String title, String text, String check, final int[] checkValue) { + void alertCheck(String title, String text, String check, /* final */ int[] checkValue) { Shell parent = getParent(); - final Shell shell = new Shell(parent, DWT.DIALOG_TRIM | DWT.APPLICATION_MODAL); + /* final */ Shell shell = new Shell(parent, DWT.DIALOG_TRIM | DWT.APPLICATION_MODAL); if (title !is null) shell.setText(title); GridLayout gridLayout = new GridLayout(); shell.setLayout(gridLayout); @@ -82,9 +84,9 @@ } } - void confirmEx(String title, String text, String check, String button0, String button1, String button2, int defaultIndex, final int[] checkValue, final int[] result) { + void confirmEx(String title, String text, String check, String button0, String button1, String button2, int defaultIndex, /* final */ int[] checkValue, /* final */ int[] result) { Shell parent = getParent(); - final Shell shell = new Shell(parent, DWT.DIALOG_TRIM | DWT.APPLICATION_MODAL); + /* final */ Shell shell = new Shell(parent, DWT.DIALOG_TRIM | DWT.APPLICATION_MODAL); shell.setText(title); GridLayout gridLayout = new GridLayout(); shell.setLayout(gridLayout); @@ -162,9 +164,9 @@ } } - void prompt(String title, String text, String check, final String[] value, final int[] checkValue, final int[] result) { + void prompt(String title, String text, String check, /* final */ String[] value, /* final */ int[] checkValue, /* final */ int[] result) { Shell parent = getParent(); - final Shell shell = new Shell(parent, DWT.DIALOG_TRIM | DWT.APPLICATION_MODAL); + /* final */ Shell shell = new Shell(parent, DWT.DIALOG_TRIM | DWT.APPLICATION_MODAL); if (title !is null) shell.setText(title); GridLayout gridLayout = new GridLayout(); shell.setLayout(gridLayout); @@ -227,9 +229,9 @@ } } - void promptUsernameAndPassword(String title, String text, String check, final String[] user, final String[] pass, final int[] checkValue, final int[] result) { + void promptUsernameAndPassword(String title, String text, String check, /* final */ String[] user, /* final */ String[] pass, /* final */ int[] checkValue, /* final */ int[] result) { Shell parent = getParent(); - final Shell shell = new Shell(parent, DWT.DIALOG_TRIM | DWT.APPLICATION_MODAL); + /* final */ Shell shell = new Shell(parent, DWT.DIALOG_TRIM | DWT.APPLICATION_MODAL); shell.setText(title); GridLayout gridLayout = new GridLayout(); shell.setLayout(gridLayout);
--- a/dwt/browser/WebBrowser.d Thu Aug 07 15:02:44 2008 +0200 +++ b/dwt/browser/WebBrowser.d Thu Aug 07 15:16:09 2008 +0200 @@ -7,6 +7,8 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Port to the D programming language: + * John Reimer <terminal.node@gmail.com> *******************************************************************************/ module dwt.browser.WebBrowser; @@ -17,13 +19,13 @@ abstract class WebBrowser { Browser browser; - CloseWindowListener[] closeWindowListeners = new CloseWindowListener[0]; - LocationListener[] locationListeners = new LocationListener[0]; - OpenWindowListener[] openWindowListeners = new OpenWindowListener[0]; - ProgressListener[] progressListeners = new ProgressListener[0]; - StatusTextListener[] statusTextListeners = new StatusTextListener[0]; - TitleListener[] titleListeners = new TitleListener[0]; - VisibilityWindowListener[] visibilityWindowListeners = new VisibilityWindowListener[0]; + CloseWindowListener[] closeWindowListeners; + LocationListener[] locationListeners; + OpenWindowListener[] openWindowListeners; + ProgressListener[] progressListeners; + StatusTextListener[] statusTextListeners; + TitleListener[] titleListeners; + VisibilityWindowListener[] visibilityWindowListeners; static Runnable MozillaClearSessions; static Runnable NativeClearSessions;
--- a/dwt/browser/WindowCreator2.d Thu Aug 07 15:02:44 2008 +0200 +++ b/dwt/browser/WindowCreator2.d Thu Aug 07 15:16:09 2008 +0200 @@ -7,16 +7,17 @@ * * Contributors: * IBM Corporation - initial API and implementation - * Port to the D programming language: - * John Reimer <terminal.node@gmail.com> *******************************************************************************/ module dwt.browser.WindowCreator2; import dwt.dwthelper.utils; +import dwt.DWT; +import dwt.graphics.Point; +import dwt.internal.C; import dwt.internal.Platform; - import dwt.internal.mozilla.XPCOM; +import dwt.internal.mozilla.XPCOMObject; import dwt.internal.mozilla.nsIBaseWindow; import dwt.internal.mozilla.nsID; import dwt.internal.mozilla.nsISupports; @@ -24,9 +25,7 @@ import dwt.internal.mozilla.nsIWebBrowser; import dwt.internal.mozilla.nsIWebBrowserChrome; import dwt.internal.mozilla.nsIWindowCreator; - -import dwt.DWT; -import dwt.graphics.Point; +import dwt.internal.mozilla.nsIWindowCreator2; import dwt.layout.FillLayout; import dwt.widgets.Shell;
--- a/dwt/browser/WindowEvent.d Thu Aug 07 15:02:44 2008 +0200 +++ b/dwt/browser/WindowEvent.d Thu Aug 07 15:16:09 2008 +0200 @@ -8,7 +8,7 @@ * Contributors: * IBM Corporation - initial API and implementation * Port to the D programming language: - * John Reimer <terminal.node@gmail.com> + * John Reimer <terminal.node@gmail.com> *******************************************************************************/ module dwt.browser.WindowEvent; @@ -125,7 +125,6 @@ * * @since 3.0 */ - public class WindowEvent : TypedEvent { /** @@ -189,19 +188,22 @@ static final long serialVersionUID = 3617851997387174969L; - this(Widget w) { - super(w); - } +WindowEvent(Widget w) { + super(w); +} - /** - * Returns a string containing a concise, human-readable - * description of the receiver. - * - * @return a string representation of the event - */ +/** + * Returns a string containing a concise, human-readable + * description of the receiver. + * + * @return a string representation of the event + */ - public override String toString () { - return Format( "WindowEvent {required={} browser={} location={} size={} addressBar={} menuBar={} statusBar={} toolBar={} }", - required, browser, location, size, addressBar, menuBar, statusBar, tooBar ); - } +public String toString() { + return Format( "{} {required = {}, browser = {}, location = {}, size = {}, addressbar = {}, menubar = {}, statusbar = {}, toobar = {}}", + super.toString[1 .. $-2], + required, browser, + location, size, addressbar, + menubar, statusbar, toolbar ); } +}
--- a/dwt/internal/mozilla/nsEmbedString2.d Thu Aug 07 15:02:44 2008 +0200 +++ b/dwt/internal/mozilla/nsEmbedString2.d Thu Aug 07 15:16:09 2008 +0200 @@ -4,7 +4,7 @@ import dwt.internal.mozilla.nsStringAPI; class nsEmbedString -{ +{ this(wchar[] s) { nsresult result; @@ -31,11 +31,10 @@ wchar* buffer = null; PRBool terminated; uint len = NS_StringGetData(cast(nsAString*)&str, &buffer, &terminated); - wchar[] result = buffer[0 .. len].dup; - return result; + return buffer[0 .. len].dup; } - - ~this() + + ~this() { NS_StringContainerFinish(&str); } @@ -72,8 +71,7 @@ char* buffer = null; PRBool terminated; uint len = NS_CStringGetData(cast(nsACString*)&str, &buffer, &terminated); - char[] result = buffer[0 .. len].dup; - return result; + return buffer[0 .. len].dup; } ~this()
--- a/dwt/internal/mozilla/nsIDownload.d Thu Aug 07 15:02:44 2008 +0200 +++ b/dwt/internal/mozilla/nsIDownload.d Thu Aug 07 15:16:09 2008 +0200 @@ -17,38 +17,22 @@ extern(System) -interface nsIDownload : nsITransfer { +interface nsIDownload : nsISuppports { static const char[] IID_STR = NS_IDOWNLOAD_IID_STR; static const nsIID IID = NS_IDOWNLOAD_IID; - - nsresult GetTargetFile(nsILocalFile *aTargetFile); - nsresult GetPercentComplete(PRInt32 *aPercentComplete); - nsresult GetAmountTransferred(PRUint64 *aAmountTransferred); - nsresult GetSize(PRUint64 *aSize); + + nsresult Init(nsIURI aSource, nsIURI aTarget, nsAString* aDisplayName, nsIMIMEInfo aMIMEInfo, PRTime startTime, int /*long*/ aPersist); nsresult GetSource(nsIURI *aSource); nsresult GetTarget(nsIURI *aTarget); - nsresult GetCancelable(nsICancelable *aCancelable); + nsresult GetPersist(int *aPersist); + nsresult GetPercentComplete(PRInt32 *aPercentComplete); nsresult GetDisplayName(PRUnichar * *aDisplayName); + nsresult SetDisplayName(char[] aDisplayName); nsresult GetStartTime(PRInt64 *aStartTime); nsresult GetMIMEInfo(nsIMIMEInfo *aMIMEInfo); - + nsresult GetListener(int * aListener); + nsresult SetListener(int aListener); + nsresult GetObserver(int * aObserver); + nsresult SetObserver(int aObserver); } - -const char[] NS_IDOWNLOAD_MOZILLA_1_8_BRANCH_IID_STR = "ff76f0c7-caaf-4e64-8896-154348322696"; - -const nsIID NS_IDOWNLOAD_MOZILLA_1_8_BRANCH_IID= - {0xff76f0c7, 0xcaaf, 0x4e64, - [ 0x88, 0x96, 0x15, 0x43, 0x48, 0x32, 0x26, 0x96 ]}; - -extern(System) - -interface nsIDownload_MOZILLA_1_8_BRANCH : nsIDownload { - - static const char[] IID_STR = NS_IDOWNLOAD_MOZILLA_1_8_BRANCH_IID_STR; - static const nsIID IID = NS_IDOWNLOAD_MOZILLA_1_8_BRANCH_IID; - - nsresult GetSpeed(double *aSpeed); - -} -
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dwt/internal/mozilla/nsIDownload_1_8.d Thu Aug 07 15:16:09 2008 +0200 @@ -0,0 +1,36 @@ +module dwt.internal.mozilla.nsIDownload; + +import dwt.internal.mozilla.Common; +import dwt.internal.mozilla.nsID; +import dwt.internal.mozilla.nsITransfer; +import dwt.internal.mozilla.nsIURI; +import dwt.internal.mozilla.nsILocalFile; +import dwt.internal.mozilla.nsIObserver; +import dwt.internal.mozilla.nsICancelable; +import dwt.internal.mozilla.nsIMIMEInfo; + +const char[] NS_IDOWNLOAD_IID_STR = "9e1fd9f2-9727-4926-85cd-f16c375bba6d"; + +const nsIID NS_IDOWNLOAD_IID= + {0x9e1fd9f2, 0x9727, 0x4926, + [ 0x85, 0xcd, 0xf1, 0x6c, 0x37, 0x5b, 0xba, 0x6d ]}; + +extern(System) + +interface nsIDownload_1_8 : nsITransfer { + + static const char[] IID_STR = NS_IDOWNLOAD_IID_STR; + static const nsIID IID = NS_IDOWNLOAD_IID; + + nsresult GetTargetFile(nsILocalFile *aTargetFile); + nsresult GetPercentComplete(PRInt32 *aPercentComplete); + nsresult GetAmountTransferred(PRUint64 *aAmountTransferred); + nsresult GetSize(PRUint64 *aSize); + nsresult GetSource(nsIURI *aSource); + nsresult GetTarget(nsIURI *aTarget); + nsresult GetCancelable(nsICancelable *aCancelable); + nsresult GetDisplayName(PRUnichar * *aDisplayName); + nsresult GetStartTime(PRInt64 *aStartTime); + nsresult GetMIMEInfo(nsIMIMEInfo *aMIMEInfo); + +} \ No newline at end of file
--- a/dwt/internal/mozilla/nsIProgressDialog.d Thu Aug 07 15:02:44 2008 +0200 +++ b/dwt/internal/mozilla/nsIProgressDialog.d Thu Aug 07 15:16:09 2008 +0200 @@ -7,11 +7,11 @@ import dwt.internal.mozilla.nsIDOMWindow; import dwt.internal.mozilla.nsIObserver; -const char[] NS_IPROGRESSDIALOG_IID_STR = "20e790a2-76c6-462d-851a-22ab6cbbe48b"; +const char[] NS_IPROGRESSDIALOG_IID_STR = "88a478b3-af65-440a-94dc-ed9b154d2990"; const nsIID NS_IPROGRESSDIALOG_IID= - {0x20e790a2, 0x76c6, 0x462d, - [ 0x85, 0x1a, 0x22, 0xab, 0x6c, 0xbb, 0xe4, 0x8b ]}; + {0x88a478b3, 0xaf65, 0x440a, + [ 0x94, 0xdc, 0xed, 0x9b, 0x15, 0x4d, 0x29, 0x90 ]}; extern(System) @@ -23,8 +23,6 @@ nsresult Open(nsIDOMWindow aParent); nsresult GetCancelDownloadOnClose(PRBool *aCancelDownloadOnClose); nsresult SetCancelDownloadOnClose(PRBool aCancelDownloadOnClose); - nsresult GetObserver(nsIObserver *aObserver); - nsresult SetObserver(nsIObserver aObserver); nsresult GetDialog(nsIDOMWindow *aDialog); nsresult SetDialog(nsIDOMWindow aDialog);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dwt/internal/mozilla/nsIProgressDialog_1_8.d Thu Aug 07 15:16:09 2008 +0200 @@ -0,0 +1,32 @@ +module dwt.internal.mozilla.nsIProgressDialog_1_8; + +import dwt.internal.mozilla.Common; +import dwt.internal.mozilla.nsID; +import dwt.internal.mozilla.nsISupports; +import dwt.internal.mozilla.nsIDownload; +import dwt.internal.mozilla.nsIDOMWindow; +import dwt.internal.mozilla.nsIObserver; + +const char[] NS_IPROGRESSDIALOG_IID_STR = "20e790a2-76c6-462d-851a-22ab6cbbe48b"; + +const nsIID NS_IPROGRESSDIALOG_IID= + {0x20e790a2, 0x76c6, 0x462d, + [ 0x85, 0x1a, 0x22, 0xab, 0x6c, 0xbb, 0xe4, 0x8b ]}; + +extern(System) + +interface nsIProgressDialog_1_8 : nsIDownload_1_8 { + + static const char[] IID_STR = NS_IPROGRESSDIALOG_IID_STR; + static const nsIID IID = NS_IPROGRESSDIALOG_IID; + + nsresult Open(nsIDOMWindow aParent); + nsresult GetCancelDownloadOnClose(PRBool *aCancelDownloadOnClose); + nsresult SetCancelDownloadOnClose(PRBool aCancelDownloadOnClose); + nsresult GetObserver(nsIObserver *aObserver); + nsresult SetObserver(nsIObserver aObserver); + nsresult GetDialog(nsIDOMWindow *aDialog); + nsresult SetDialog(nsIDOMWindow aDialog); + +} +
--- a/dwt/internal/mozilla/nsISupports.d Thu Aug 07 15:02:44 2008 +0200 +++ b/dwt/internal/mozilla/nsISupports.d Thu Aug 07 15:16:09 2008 +0200 @@ -16,7 +16,7 @@ static const char[] IID_STR = NS_ISUPPORTS_IID_STR; static const nsIID IID = NS_ISUPPORTS_IID; - nsresult QueryInterface(nsIID * uuid, void **result); + nsresult QueryInterface(ref nsIID uuid, void **result); nsrefcnt AddRef(); nsrefcnt Release();
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dwt/internal/mozilla/nsISupports.d~ Thu Aug 07 15:16:09 2008 +0200 @@ -0,0 +1,31 @@ +module dwt.internal.mozilla.nsISupports; + +import dwt.internal.mozilla.Common; +import dwt.internal.mozilla.nsID; + +const char[] NS_ISUPPORTS_IID_STR = "00000000-0000-0000-c000-000000000046"; + +const nsIID NS_ISUPPORTS_IID= + { 0x00000000, 0x0000, 0x0000, + [ 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46 ] }; + +extern(System) + +interface IUnknown +{ + static const char[] IID_STR = NS_ISUPPORTS_IID_STR; + static const nsIID IID = NS_ISUPPORTS_IID; + + nsresult QueryInterface(nsIID * uuid, void **result); + + nsrefcnt AddRef(); + nsrefcnt Release(); +} + +// WHY WE USE COM's IUnknown for XPCOM: +// +// The IUnknown interface is special-cased in D and is specifically designed to be +// compatible with MS COM. XPCOM's nsISupports interface is the exact equivalent +// of IUnknown so we alias it here to take advantage of D's COM support. -JJR + +alias IUnknown nsISupports; \ No newline at end of file
--- a/dwt/internal/mozilla/nsStringAPI.d Thu Aug 07 15:02:44 2008 +0200 +++ b/dwt/internal/mozilla/nsStringAPI.d Thu Aug 07 15:16:09 2008 +0200 @@ -80,6 +80,14 @@ return result; } + static wchar[] getString16( nsAString* str ) + { + wchar* buffer = null; + PRBool terminated; + uint len = NS_StringGetData(str, &buffer, &terminated); + return buffer[0 .. len].dup; + } + private: void *v; } @@ -174,3 +182,14 @@ struct nsDependentSubstring_external{} struct nsDependentCSubstring_external{} +/****************************************************************************** + +******************************************************************************/ + +PRUint32 strlen_PRUnichar ( PRUnichar* str ) +{ + PRUint32 len = 0; + if (str !is null) + while (*(lparg0++) != 0) len++; + ret len; +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dwt/internal/mozilla/nsStringAPI.d~ Thu Aug 07 15:16:09 2008 +0200 @@ -0,0 +1,187 @@ +module dwt.internal.mozilla.nsStringAPI; + +import dwt.internal.mozilla.Common; + +extern (System): + +/****************************************************************************** + +******************************************************************************/ + +enum +{ + NS_STRING_CONTAINER_INIT_DEPEND = 2, + NS_STRING_CONTAINER_INIT_ADOPT = 4, + NS_STRING_CONTAINER_INIT_SUBSTRING = 8, +} + +nsresult NS_StringContainerInit ( nsStringContainer *aContainer ); +nsresult NS_StringContainerInit2( nsStringContainer *aContainer, PRUnichar *aData, PRUint32 aDataLength, PRUint32 aFlags ); +void NS_StringContainerFinish(nsStringContainer *aContainer); +PRUint32 NS_StringGetData(nsAString *aStr, PRUnichar **aData, PRBool *aTerminated); +PRUint32 NS_StringGetMutableData(nsAString *aStr, PRUint32 aDataLength, PRUnichar **aData); +PRUnichar * NS_StringCloneData(nsAString *aStr); +nsresult NS_StringSetData(nsAString *aStr, PRUnichar *aData, PRUint32 aDataLength); +nsresult NS_StringSetDataRange( nsAString *aStr, PRUint32 aCutOffset, PRUint32 aCutLength, PRUnichar *aData, PRUint32 aDataLength ); +nsresult NS_StringCopy(nsAString *aDestStr, nsAString *aSrcStr); + +/****************************************************************************** + +******************************************************************************/ + +enum +{ + NS_CSTRING_CONTAINER_INIT_DEPEND = 2, + NS_CSTRING_CONTAINER_INIT_ADOPT = 4, + NS_CSTRING_CONTAINER_INIT_SUBSTRING = 8, +} + +nsresult NS_CStringContainerInit( nsCStringContainer *aContainer ); +nsresult NS_CStringContainerInit2( nsCStringContainer *aContainer, char *aData, PRUint32 aDataLength, PRUint32 aFlags ); +void NS_CStringContainerFinish( nsCStringContainer *aContainer ); +PRUint32 NS_CStringGetData( nsACString *aStr, char **aData, PRBool *aTerminated ); +PRUint32 NS_CStringGetMutableData( nsACString *aStr, PRUint32 aDataLength, char **aData ); +char * NS_CStringCloneData( nsACString *aStr); +nsresult NS_CStringSetData( nsACString *aStr, char *aData, PRUint32 aDataLength ); +nsresult NS_CStringSetDataRange( nsACString *aStr, PRUint32 aCutOffset, + PRUint32 aCutLength, char *aData, PRUint32 aDataLength ); +nsresult NS_CStringCopy( nsACString *aDestStr, nsACString *aSrcStr ); + +/****************************************************************************** + +******************************************************************************/ + +enum nsCStringEncoding +{ + NS_CSTRING_ENCODING_ASCII, + NS_CSTRING_ENCODING_UTF8, + NS_CSTRING_ENCODING_NATIVE_FILESYSTEM, +} + +nsresult NS_CStringToUTF16( nsACString *aSource, int aSrcEncoding, nsAString *aDest ); +nsresult NS_UTF16ToCString( nsAString *aSource, int aDestEncoding, nsACString *aDest ); + +/****************************************************************************** + +******************************************************************************/ + +alias nsAString nsAString_external; +alias nsACString nsACString_external; + +alias nsAString nsEmbedString; +alias nsACString nsEmbedCString; + +struct nsAString +{ + static nsAString opCall(wchar[] s) + { + nsAString result; + NS_StringSetData(&result, cast(PRUnichar*)s, uint.max); + return result; + } + + private: + void *v; +} + +struct nsACString +{ + static nsACString opCall(char[] s) + { + nsACString result; + NS_CStringSetData(&result, cast(char*)s, uint.max); + return result; + } + + private: + void *v; +} + +/****************************************************************************** + +******************************************************************************/ + +struct nsStringContainer// : public nsAString +{ +private: + void* v; + void* d1; + uint d2; + void* d3; +} + +struct nsCStringContainer// : public nsACString +{ +private: + void* v; + void* d1; + uint d2; + void* d3; +} + +/****************************************************************************** + +******************************************************************************/ + +// import mozilla.xpcom.nsDebug; + +alias nsString_external nsString; +alias nsCString_external nsCString; +alias nsDependentString_external nsDependentString; +alias nsDependentCString_external nsDependentCString; +alias NS_ConvertASCIItoUTF16_external NS_ConvertASCIItoUTF16; +alias NS_ConvertUTF8toUTF16_external NS_ConvertUTF8toUTF16; +alias NS_ConvertUTF16toUTF8_external NS_ConvertUTF16toUTF8; +alias NS_LossyConvertUTF16toASCII_external NS_LossyConvertUTF16toASCII; +alias nsGetterCopies_external nsGetterCopies; +alias nsCGetterCopies_external nsCGetterCopies; +alias nsDependentSubstring_external nsDependentSubstring; +alias nsDependentCSubstring_external nsDependentCSubstring; + +struct nsString_external{} +struct nsCString_external{} +struct nsDependentString_external{} +struct nsDependentCString_external{} +struct NS_ConvertASCIItoUTF16_external{} +struct NS_ConvertUTF8toUTF16_external{} +struct NS_ConvertUTF16toUTF8_external{} +struct NS_LossyConvertUTF16toASCII_external{} + +/****************************************************************************** + +******************************************************************************/ + +struct nsGetterCopies_external +{ + private: + alias PRUnichar char_type; + nsString_external *mString; + char_type *mData; +} + +struct nsCGetterCopies_external +{ + private: + alias char char_type; + nsCString_external *mString; + char_type *mData; +} + +/****************************************************************************** + +******************************************************************************/ + +struct nsDependentSubstring_external{} +struct nsDependentCSubstring_external{} + +/****************************************************************************** + +******************************************************************************/ + +PRUint32 strlen_PRUnichar ( PRUnichar* str ) +{ + PRUint32 len = 0; + if (str !is null) + while (*lparg0++ != 0) len++; + ret len; +} \ No newline at end of file
--- a/dwt/internal/mozilla/nsXPCOM.d Thu Aug 07 15:02:44 2008 +0200 +++ b/dwt/internal/mozilla/nsXPCOM.d Thu Aug 07 15:16:09 2008 +0200 @@ -1,4 +1,3 @@ -/****************************************************************************** module dwt.internal.mozilla.nsXPCOM; @@ -45,10 +44,10 @@ nsresult NS_GetComponentManager(nsIComponentManager *result); nsresult NS_GetComponentRegistrar(nsIComponentRegistrar *result); nsresult NS_GetMemoryManager(nsIMemory *result); -nsresult NS_NewLocalFile(inout nsAString path, PRBool followLinks, nsILocalFile** result); -nsresult NS_NewNativeLocalFile(inout nsACString path, PRBool followLinks, nsILocalFile** result); +nsresult NS_NewLocalFile(inout nsAString path, PRBool followLinks, nsILocalFile* result); +nsresult NS_NewNativeLocalFile(inout nsACString path, PRBool followLinks, nsILocalFile* result); void * NS_Alloc(PRSize size); void * NS_Realloc(void *ptr, PRSize size); void NS_Free(void *ptr); -nsresult NS_GetDebug(nsIDebug **result); +nsresult NS_GetDebug(nsIDebug *result); nsresult NS_GetTraceRefcnt(nsITraceRefcnt *result);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dwt/internal/mozilla/nsXPCOM.d~ Thu Aug 07 15:16:09 2008 +0200 @@ -0,0 +1,54 @@ +/****************************************************************************** + +module dwt.internal.mozilla.nsXPCOM; + +import dwt.internal.mozilla.Common; +import dwt.internal.mozilla.nsStringAPI; +import dwt.internal.mozilla.nsIModule; +import dwt.internal.mozilla.nsIComponentManager; +import dwt.internal.mozilla.nsIComponentRegistrar; +import dwt.internal.mozilla.nsIServiceManager; +import dwt.internal.mozilla.nsIFile; +import dwt.internal.mozilla.nsILocalFile; +import dwt.internal.mozilla.nsIDirectoryService; +import dwt.internal.mozilla.nsIMemory; +import dwt.internal.mozilla.nsIDebug; +import dwt.internal.mozilla.nsITraceRefcnt; + +/****************************************************************************** + +******************************************************************************/ + +extern (System): + +struct nsStaticModuleInfo +{ + char *name; + nsGetModuleProc getModule; +} + +alias nsresult function (nsIComponentManager, nsIFile, nsIModule*) nsGetModuleProc; + +/****************************************************************************** + +******************************************************************************/ + +nsresult NS_InitXPCOM2( nsIServiceManager *result, nsIFile binDirectory, + nsIDirectoryServiceProvider appFileLocationProvider ); +nsresult NS_InitXPCOM3( nsIServiceManager *result, nsIFile binDirectory, + nsIDirectoryServiceProvider appFileLocationProvider, + nsStaticModuleInfo* staticComponents, + PRUint32 componentCount ); + +nsresult NS_ShutdownXPCOM(nsIServiceManager servMgr); +nsresult NS_GetServiceManager(nsIServiceManager *result); +nsresult NS_GetComponentManager(nsIComponentManager *result); +nsresult NS_GetComponentRegistrar(nsIComponentRegistrar *result); +nsresult NS_GetMemoryManager(nsIMemory *result); +nsresult NS_NewLocalFile(inout nsAString path, PRBool followLinks, nsILocalFile** result); +nsresult NS_NewNativeLocalFile(inout nsACString path, PRBool followLinks, nsILocalFile** result); +void * NS_Alloc(PRSize size); +void * NS_Realloc(void *ptr, PRSize size); +void NS_Free(void *ptr); +nsresult NS_GetDebug(nsIDebug **result); +nsresult NS_GetTraceRefcnt(nsITraceRefcnt *result);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dwt/widgets/DirectoryDialog.d~ Thu Aug 07 15:16:09 2008 +0200 @@ -0,0 +1,343 @@ +/******************************************************************************* + * Copyright (c) 2000, 2008 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * Port to the D programming language: + * Frank Benoit <benoit@tionex.de> + *******************************************************************************/ +module dwt.widgets.DirectoryDialog; + +import dwt.dwthelper.utils; + + + +import dwt.DWT; +import dwt.DWTException; +import dwt.internal.gtk.OS; +import dwt.widgets.Dialog; +import dwt.widgets.Shell; +import dwt.widgets.Display; + +version(TANGOSVN) { + static import tango.io.model.IFile; +} +else{ + static import tango.io.FileConst; +} +static import tango.text.Util; + +/** + * Instances of this class allow the user to navigate + * the file system and select a directory. + * <dl> + * <dt><b>Styles:</b></dt> + * <dd>(none)</dd> + * <dt><b>Events:</b></dt> + * <dd>(none)</dd> + * </dl> + * <p> + * IMPORTANT: This class is intended to be subclassed <em>only</em> + * within the DWT implementation. + * </p> + * + * @see <a href="http://www.eclipse.org/swt/snippets/#directorydialog">DirectoryDialog snippets</a> + * @see <a href="http://www.eclipse.org/swt/examples.php">DWT Example: ControlExample, Dialog tab</a> + * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> + */ +public class DirectoryDialog : Dialog { + String message = "", filterPath = ""; +version(TANGOSVN) { + static const String SEPARATOR = tango.io.model.IFile.FileConst.PathSeparatorString; +} +else{ + static const String SEPARATOR = tango.io.FileConst.FileConst.PathSeparatorString; +} + +/** + * Constructs a new instance of this class given only its parent. + * + * @param parent a shell which will be the parent of the new instance + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> + * </ul> + * @exception DWTException <ul> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> + * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> + * </ul> + */ +public this (Shell parent) { + this (parent, DWT.APPLICATION_MODAL); +} +/** + * Constructs a new instance of this class given its parent + * and a style value describing its behavior and appearance. + * <p> + * The style value is either one of the style constants defined in + * class <code>DWT</code> which is applicable to instances of this + * class, or must be built by <em>bitwise OR</em>'ing together + * (that is, using the <code>int</code> "|" operator) two or more + * of those <code>DWT</code> style constants. The class description + * lists the style constants that are applicable to the class. + * Style bits are also inherited from superclasses. + * </p> + * + * @param parent a shell which will be the parent of the new instance + * @param style the style of dialog to construct + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> + * </ul> + * @exception DWTException <ul> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> + * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> + * </ul> + */ +public this (Shell parent, int style) { + super (parent, checkStyle (parent, style)); + checkSubclass (); +} +/** + * Returns the path which the dialog will use to filter + * the directories it shows. + * + * @return the filter path + * + * @see #setFilterPath + */ +public String getFilterPath () { + return filterPath; +} +/** + * Returns the dialog's message, which is a description of + * the purpose for which it was opened. This message will be + * visible on the dialog while it is open. + * + * @return the message + */ +public String getMessage () { + return message; +} +/** + * Makes the dialog visible and brings it to the front + * of the display. + * + * @return a string describing the absolute path of the selected directory, + * or null if the dialog was cancelled or an error occurred + * + * @exception DWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the dialog has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the dialog</li> + * </ul> + */ +public String open () { + bool useChooserDialog = OS.GTK_VERSION >= OS.buildVERSION (2, 4, 10); + if (useChooserDialog) { + return openChooserDialog (); + } else { + return openClassicDialog (); + } +} +String openChooserDialog () { + char* titleBytes = toStringz(title); + auto shellHandle = parent.topHandle (); + auto handle = OS.gtk_file_chooser_dialog_new2 ( + titleBytes, + shellHandle, + OS.GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, + OS.GTK_STOCK_CANCEL (), OS.GTK_RESPONSE_CANCEL, + OS.GTK_STOCK_OK (), OS.GTK_RESPONSE_OK ); + auto pixbufs = OS.gtk_window_get_icon_list (shellHandle); + if (pixbufs !is null) { + OS.gtk_window_set_icon_list (handle, pixbufs); + OS.g_list_free (pixbufs); + } + if (filterPath !is null && filterPath.length > 0) { + String p; + /* filename must be a full path */ + if ( filterPath[ 0 .. SEPARATOR.length ] != SEPARATOR ) { + p ~= SEPARATOR; + p ~= filterPath; + } + else{ + p = filterPath; + } + char* buffer = toStringz(p); + /* + * Bug in GTK. GtkFileChooser may crash on GTK versions 2.4.10 to 2.6 + * when setting a file name that is not a true canonical path. + * The fix is to use the canonical path. + */ + char* ptr = OS.realpath (buffer, null); + if (ptr !is null) { + OS.gtk_file_chooser_set_current_folder (handle, ptr); + OS.g_free (ptr); + } + } + if (message.length > 0) { + char* buffer = toStringz(message); + auto box = OS.gtk_hbox_new (false, 0); + if (box is null) error (DWT.ERROR_NO_HANDLES); + auto label = OS.gtk_label_new (buffer); + if (label is null) error (DWT.ERROR_NO_HANDLES); + OS.gtk_container_add (box, label); + OS.gtk_widget_show (label); + OS.gtk_label_set_line_wrap (label, true); + OS.gtk_label_set_justify (label, OS.GTK_JUSTIFY_CENTER); + OS.gtk_file_chooser_set_extra_widget (handle, box); + } + String answer = null; + Display display = parent !is null ? parent.getDisplay (): Display.getCurrent (); + display.addIdleProc (); + Dialog oldModal = null; + if (OS.gtk_window_get_modal (handle)) { + oldModal = display.getModalDialog (); + display.setModalDialog (this); + } + int signalId = 0; + int /*long*/ hookId = 0; + CallbackData emissionData; + emissionData.display = display; + emissionData.data = handle; + if ((style & DWT.RIGHT_TO_LEFT) !is 0) { + signalId = OS.g_signal_lookup (OS.map.ptr, OS.GTK_TYPE_WIDGET()); + hookId = OS.g_signal_add_emission_hook (signalId, 0, &Display.emissionFunc, &emissionData, null); + } + int response = OS.gtk_dialog_run (handle); + if ((style & DWT.RIGHT_TO_LEFT) !is 0) { + OS.g_signal_remove_emission_hook (signalId, hookId); + } + if (OS.gtk_window_get_modal (handle)) { + display.setModalDialog (oldModal); + } + if (response is OS.GTK_RESPONSE_OK) { + auto path = OS.gtk_file_chooser_get_filename (handle); + if (path !is null) { + uint items_written; + auto utf8Ptr = OS.g_filename_to_utf8 (path, -1, null, &items_written, null); + OS.g_free (path); + if (utf8Ptr !is null) { + answer = utf8Ptr[ 0 .. items_written ].dup; + filterPath = answer; + OS.g_free (utf8Ptr); + } + } + } + display.removeIdleProc (); + OS.gtk_widget_destroy (handle); + return answer; +} +String openClassicDialog () { + char* titleBytes = toStringz(title); + auto handle = OS.gtk_file_selection_new (titleBytes); + if (parent !is null) { + auto shellHandle = parent.topHandle (); + OS.gtk_window_set_transient_for (handle, shellHandle); + auto pixbufs = OS.gtk_window_get_icon_list (shellHandle); + if (pixbufs !is null) { + OS.gtk_window_set_icon_list (handle, pixbufs); + OS.g_list_free (pixbufs); + } + } + String answer = null; + if (filterPath !is null) { + String path = filterPath; + if (path.length > 0 && path[ $-1 .. $ ] != SEPARATOR ) { + path ~= SEPARATOR; + } + char* fileNamePtr = OS.g_filename_from_utf8 (toStringz(path), -1, null, null, null); + OS.gtk_file_selection_set_filename (handle, fileNamePtr); + OS.g_free (fileNamePtr); + } + GtkFileSelection* selection = cast(GtkFileSelection*)handle; + OS.gtk_file_selection_hide_fileop_buttons (handle); + auto fileListParent = OS.gtk_widget_get_parent (selection.file_list); + OS.gtk_widget_hide (selection.file_list); + OS.gtk_widget_hide (fileListParent); + if (message.length > 0) { + auto labelHandle = OS.gtk_label_new (toStringz(message)); + OS.gtk_label_set_line_wrap (labelHandle, true); + OS.gtk_misc_set_alignment (labelHandle, 0.0f, 0.0f); + OS.gtk_container_add (selection.main_vbox, labelHandle); + OS.gtk_box_set_child_packing ( + selection.main_vbox, labelHandle, false, false, 0, OS.GTK_PACK_START); + OS.gtk_widget_show (labelHandle); + } + Display display = parent !is null ? parent.getDisplay (): Display.getCurrent (); + display.addIdleProc (); + Dialog oldModal = null; + if (OS.gtk_window_get_modal (handle)) { + oldModal = display.getModalDialog (); + display.setModalDialog (this); + } + int signalId = 0; + int /*long*/ hookId = 0; + CallbackData emissionData; + emissionData.display = display; + emissionData.data = handle; + if ((style & DWT.RIGHT_TO_LEFT) !is 0) { + signalId = OS.g_signal_lookup (OS.map.ptr, OS.GTK_TYPE_WIDGET()); + hookId = OS.g_signal_add_emission_hook (signalId, 0, &Display.emissionFunc, &emissionData, null); + } + int response = OS.gtk_dialog_run (handle); + if ((style & DWT.RIGHT_TO_LEFT) !is 0) { + OS.g_signal_remove_emission_hook (signalId, hookId); + } + if (OS.gtk_window_get_modal (handle)) { + display.setModalDialog (oldModal); + } + if (response is OS.GTK_RESPONSE_OK) { + char* fileNamePtr = OS.gtk_file_selection_get_filename (handle); + uint items_written; + char* utf8Ptr = OS.g_filename_to_utf8 (fileNamePtr, -1, null, &items_written, null); + if (utf8Ptr !is null) { + String osAnswer = utf8Ptr[ 0 .. items_written ]; + if (osAnswer.length !is 0) { + /* remove trailing separator, unless root directory */ + if ( osAnswer != SEPARATOR && osAnswer[ $-1 .. $ ] == SEPARATOR ) { + osAnswer = osAnswer[ 0 .. $ - 1 ]; + } + answer = filterPath = osAnswer.dup; + } + OS.g_free (utf8Ptr); + } + } + display.removeIdleProc (); + OS.gtk_widget_destroy (handle); + return answer; +} +/** + * Sets the path that the dialog will use to filter + * the directories it shows to the argument, which may + * be null. If the string is null, then the operating + * system's default filter path will be used. + * <p> + * Note that the path string is platform dependent. + * For convenience, either '/' or '\' can be used + * as a path separator. + * </p> + * + * @param string the filter path + */ +public void setFilterPath (String string) { + filterPath = string.dup; +} +/** + * Sets the dialog's message, which is a description of + * the purpose for which it was opened. This message will be + * visible on the dialog while it is open. + * + * @param string the message + * + */ +public void setMessage (String string) { + // DWT extension: allow null for zero length string + //if (string is null) error (DWT.ERROR_NULL_ARGUMENT); + message = string.dup; +} +}