# HG changeset patch # User John Reimer # Date 1225862503 28800 # Node ID 7f3013c93a9551a7abbf5f83cbd802a591ebef0f # Parent a3c5f744d03ff46bae34205fa5246bdd79779b3d Oops... Add new 3.4.1 files diff -r a3c5f744d03f -r 7f3013c93a95 dwt/browser/HelperAppLauncherDialog_1_9.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dwt/browser/HelperAppLauncherDialog_1_9.d Tue Nov 04 21:21:43 2008 -0800 @@ -0,0 +1,130 @@ +/******************************************************************************* + * Copyright (c) 2003, 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 + * Ported to the D Programming Language: + * John Reimer + *******************************************************************************/ +module dwt.browser.HelperAppLauncherDialog_1_9; + +import tango.text.convert.Utf; +import dwt.dwthelper.utils; + +import dwt.DWT; + +import dwt.internal.mozilla.Common; + +import XPCOM = dwt.internal.mozilla.XPCOM; + +import dwt.internal.mozilla.nsEmbedString; +import dwt.internal.mozilla.nsID; +import dwt.internal.mozilla.nsIHelperAppLauncherDialog_1_9; +import dwt.internal.mozilla.nsIHelperAppLauncher_1_9; +import dwt.internal.mozilla.nsILocalFile; +import dwt.internal.mozilla.nsISupports; +import dwt.internal.mozilla.nsStringAPI; +import dwt.internal.mozilla.nsEmbedString; + +import dwt.widgets.FileDialog; +import dwt.widgets.Shell; + +import dwt.browser.Mozilla; + +class HelperAppLauncherDialog_1_9 : nsIHelperAppLauncherDialog_1_9 { + + int refCount = 0; + +this () { +} + +extern(System) +nsrefcnt AddRef () { + refCount++; + return refCount; +} + +extern(System) +nsresult QueryInterface (nsID* riid, void** ppvObject) { + if (riid is null || ppvObject is null) return XPCOM.NS_ERROR_NO_INTERFACE; + + if (*riid is nsISupports.IID) { + *ppvObject = cast(void*)cast(nsIHelperAppLauncherDialog_1_9)this; + AddRef (); + return XPCOM.NS_OK; + } + if (*riid is nsIHelperAppLauncherDialog_1_9.IID) { + *ppvObject = cast(void*)cast(nsIHelperAppLauncherDialog_1_9)this; + AddRef (); + return XPCOM.NS_OK; + } + + *ppvObject = null; + return XPCOM.NS_ERROR_NO_INTERFACE; +} + +extern(System) +nsresult Release () { + refCount--; + /* + * Note. This instance lives as long as the download it is bound to. + * Its reference count is expected to go down to 0 when the download + * has completed or when it has been cancelled. E.g. when the user + * cancels the File Dialog, cancels or closes the Download Dialog + * and when the Download Dialog goes away after the download is completed. + */ + if (refCount is 0) return 0; + return refCount; +} + +/* nsIHelperAppLauncherDialog */ +extern(System) +nsresult Show (nsIHelperAppLauncher_1_9 aLauncher, nsISupports aContext, PRUint32 aReason) { + return aLauncher.SaveToDisk (null, 0); +} + +extern(System) +nsresult PromptForSaveToFile (nsIHelperAppLauncher_1_9 aLauncher, nsISupports aWindowContext, PRUnichar* aDefaultFileName, PRUnichar* aSuggestedFileExtension, PRBool aForcePrompt, nsILocalFile* _retval) { + //int length = XPCOM.strlen_PRUnichar (aDefaultFileName); + //char[] dest = new char[length]; + //XPCOM.memmove (dest, aDefaultFileName, length * 2); + String defaultFile = Utf.toString(fromString16z(aDefaultFileName)); + + //length = XPCOM.strlen_PRUnichar (aSuggestedFileExtension); + //dest = new char[length]; + //XPCOM.memmove (dest, aSuggestedFileExtension, length * 2); + String suggestedFileExtension = Utf.toString(fromString16z(aSuggestedFileExtension)); + + Shell shell = new Shell (); + FileDialog fileDialog = new FileDialog (shell, DWT.SAVE); + fileDialog.setFileName (defaultFile); + String[] tmp; + tmp ~= suggestedFileExtension; + fileDialog.setFilterExtensions (tmp); + String name = fileDialog.open (); + shell.close (); + if (name is null) { + //nsIHelperAppLauncher_1_9 launcher = new nsIHelperAppLauncher_1_9 (aLauncher); + int rc = aLauncher.Cancel (XPCOM.NS_BINDING_ABORTED); + if (rc !is XPCOM.NS_OK) Mozilla.error (rc,__FILE__,__LINE__); + return XPCOM.NS_ERROR_FAILURE; + } + scope auto path = new nsEmbedString (name.toString16()); + + nsILocalFile localFile; + int rc = XPCOM.NS_NewLocalFile (cast(nsAString*)path, 1, &localFile); + //path.dispose (); + if (rc !is XPCOM.NS_OK) Mozilla.error (rc,__FILE__,__LINE__); + if (localFile is null) Mozilla.error (XPCOM.NS_ERROR_NULL_POINTER,__FILE__,__LINE__); + /* Our own nsIDownload has been registered during the Browser initialization. It will be invoked by Mozilla. */ + *_retval = localFile; + //XPCOM.memmove (_retval, result, C.PTR_SIZEOF); + return XPCOM.NS_OK; +} +} + + diff -r a3c5f744d03f -r 7f3013c93a95 dwt/internal/mozilla/nsIHelperAppLauncherDialog_1_9.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dwt/internal/mozilla/nsIHelperAppLauncherDialog_1_9.d Tue Nov 04 21:21:43 2008 -0800 @@ -0,0 +1,28 @@ +module dwt.internal.mozilla.nsIHelperAppLauncherDialog_1_9; + +import dwt.internal.mozilla.Common; +import dwt.internal.mozilla.nsID; +import dwt.internal.mozilla.nsISupports; +import dwt.internal.mozilla.nsIHelperAppLauncher_1_9; +import dwt.internal.mozilla.nsILocalFile; + +const char[] NS_IHELPERAPPLAUNCHERDIALOG_1_9_IID_STR = "f3704fdc-8ae6-4eba-a3c3-f02958ac0649"; + +const nsIID NS_IHELPERAPPLAUNCHERDIALOG_1_9_IID= + { 0xf3704fdc, 0x8ae6, 0x4eba, [ 0xa3,0xc3,0xf0,0x29,0x58,0xac,0x06,0x49 ]}; + +interface nsIHelperAppLauncherDialog_1_9 : nsISupports { + + static const char[] IID_STR = NS_IHELPERAPPLAUNCHERDIALOG_1_9_IID_STR; + static const nsIID IID = NS_IHELPERAPPLAUNCHERDIALOG_1_9_IID; + + enum { REASON_CANTHANDLE = 0U }; + enum { REASON_SERVERREQUEST = 1U }; + enum { REASON_TYPESNIFFED = 2U }; + +extern(System): + nsresult Show(nsIHelperAppLauncher_1_9 aLauncher, nsISupports aContext, PRUint32 aReason); + nsresult PromptForSaveToFile(nsIHelperAppLauncher_1_9 aLauncher, nsISupports aWindowContext, PRUnichar *aDefaultFile, PRUnichar *aSuggestedFileExtension, PRBool aForcePrompt, nsILocalFile *_retval); + +} +