diff --git a/widget/macbuild/widget.mcp b/widget/macbuild/widget.mcp index acad6202dcee..51208217b6f6 100644 Binary files a/widget/macbuild/widget.mcp and b/widget/macbuild/widget.mcp differ diff --git a/widget/src/build/nsGTKWidgetFactory.cpp b/widget/src/build/nsGTKWidgetFactory.cpp index 73f88edcfa17..27869d0df5d9 100644 --- a/widget/src/build/nsGTKWidgetFactory.cpp +++ b/widget/src/build/nsGTKWidgetFactory.cpp @@ -32,6 +32,7 @@ #include "nsTextWidget.h" #include "nsTextAreaWidget.h" #include "nsFileWidget.h" +#include "nsFileSpecWithUIImpl.h" #include "nsListBox.h" #include "nsComboBox.h" #include "nsLookAndFeel.h" @@ -250,6 +251,10 @@ nsresult nsWidgetFactory::CreateInstance(nsISupports *aOuter, else if (mClassID.Equals(kCDragService)) { inst = (nsISupports*) (nsIDragService *) new nsDragService(); } + else if (mClassID.Equals(nsIFileSpecWithUI::GetIID())) + { + inst = (nsISupports*) (nsIFileSpecWithUI *) new nsFileSpecWithUIImpl; + } else { printf("nsWidgetFactory::CreateInstance(), unhandled class.\n"); } diff --git a/widget/src/build/nsPhWidgetFactory.cpp b/widget/src/build/nsPhWidgetFactory.cpp index 7deae97b3347..26584ee40e0f 100644 --- a/widget/src/build/nsPhWidgetFactory.cpp +++ b/widget/src/build/nsPhWidgetFactory.cpp @@ -27,6 +27,7 @@ #include "nsITextAreaWidget.h" #include "nsIListBox.h" #include "nsIFileWidget.h" +#include "nsFileSpecWithUIImpl.h" #include "nsIComboBox.h" #include "nsWidgetsCID.h" @@ -265,6 +266,11 @@ PR_LOG(PhWidLog, PR_LOG_DEBUG,("nsWidgetFactory::CreateInstance\n")); printf( "Creating nsXIFFormatConverter instance.\n" ); inst = (nsISupports*)new nsXIFFormatConverter(); } + else if (mClassID.Equals(nsIFileSpecWithUI::GetIID())) + { + printf( "Creating nsFileSpecWithUIImpl instance.\n" ); + inst = (nsISupports*) (nsIFileSpecWithUI *) new nsFileSpecWithUIImpl; + } else if (mClassID.Equals(kCTransferable)) { printf( "Creating nsTransferable instance.\n" ); inst = (nsISupports*)new nsTransferable(); diff --git a/widget/src/build/nsWinWidgetFactory.cpp b/widget/src/build/nsWinWidgetFactory.cpp index 5ac7b89339ab..7de49d475757 100644 --- a/widget/src/build/nsWinWidgetFactory.cpp +++ b/widget/src/build/nsWinWidgetFactory.cpp @@ -25,6 +25,7 @@ #include "nsCheckButton.h" #include "nsComboBox.h" #include "nsFileWidget.h" +#include "nsFileSpecWithUIImpl.h" #include "nsListBox.h" #include "nsLookAndFeel.h" #include "nsRadioButton.h" @@ -241,6 +242,10 @@ nsresult nsWidgetFactory::CreateInstance( nsISupports* aOuter, NS_NewSound(&aSound); inst = (nsISupports*) aSound; } + else if (mClassID.Equals(nsIFileSpecWithUI::GetIID())) + { + inst = (nsISupports*) (nsIFileSpecWithUI *) new nsFileSpecWithUIImpl; + } else if (mClassID.Equals(kCTransferable)) { inst = (nsISupports*)new nsTransferable(); } diff --git a/widget/src/mac/nsWidgetFactory.cpp b/widget/src/mac/nsWidgetFactory.cpp index 084db9b0fab1..ed8ac472c16d 100644 --- a/widget/src/mac/nsWidgetFactory.cpp +++ b/widget/src/mac/nsWidgetFactory.cpp @@ -32,6 +32,7 @@ #include "nsTextWidget.h" #include "nsLabel.h" #include "nsFileWidget.h" +#include "nsFileSpecWithUIImpl.h" #include "nsScrollbar.h" #include "nsMenuBar.h" #include "nsMenu.h" @@ -259,6 +260,10 @@ nsresult nsWidgetFactory::CreateInstance(nsISupports *aOuter, NS_NewSound(&aSound); inst = (nsISupports*) aSound; } + else if (mClassID.Equals(nsIFileSpecWithUI::GetIID())) + { + inst = (nsISupports*) (nsIFileSpecWithUI *) new nsFileSpecWithUIImpl; + } else if (mClassID.Equals(kCTransferable)) { inst = (nsISupports*)new nsTransferable(); } diff --git a/widget/src/xpwidgets/nsFileSpecWithUIImpl.cpp b/widget/src/xpwidgets/nsFileSpecWithUIImpl.cpp index 85b64f323789..5b988dbe64ae 100644 --- a/widget/src/xpwidgets/nsFileSpecWithUIImpl.cpp +++ b/widget/src/xpwidgets/nsFileSpecWithUIImpl.cpp @@ -16,212 +16,16 @@ * Reserved. */ -#include "nsIFileSpecWithUI.h" // Always first, to ensure that it compiles alone. +#include "nsFileSpecWithUIImpl.h" -#include "nsFileSpecImpl.h" #include "nsIFileWidget.h" #include "nsWidgetsCID.h" -#include "nsCOMPtr.h" +#include "nsIComponentManager.h" #undef NS_FILE_FAILURE #define NS_FILE_FAILURE NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_FILES,(0xFFFF)) -//======================================================================================== -class nsFileSpecWithUIImpl -//======================================================================================== - : public nsFileSpecImpl - , public nsIFileSpecWithUI -{ - - public: - - NS_DECL_ISUPPORTS_INHERITED - - nsFileSpecWithUIImpl(); - virtual ~nsFileSpecWithUIImpl(); - - NS_IMETHOD chooseOutputFile(const char *windowTitle, const char *suggestedLeafName); - - NS_IMETHOD chooseInputFile( - const char *title, - nsIFileSpecWithUI::StandardFilterMask standardFilterMask, - const char *extraFilterTitle, const char *extraFilter); - - NS_IMETHOD chooseDirectory(const char *title); - - //------------------ - // INHERITED/FORWARDED METHODS - //------------------ - - NS_IMETHOD fromFileSpec(const nsIFileSpec *original) - { return nsFileSpecImpl::fromFileSpec(original); } - - NS_IMETHOD GetURLString(char * *aURLString) - { return nsFileSpecImpl::GetURLString(aURLString); } - NS_IMETHOD SetURLString(char * aURLString) - { return nsFileSpecImpl::SetURLString(aURLString); } - - /* attribute string UnixStyleFilePath; */ - NS_IMETHOD GetUnixStyleFilePath(char * *aUnixStyleFilePath) - { return nsFileSpecImpl::GetUnixStyleFilePath(aUnixStyleFilePath); } - NS_IMETHOD SetUnixStyleFilePath(char * aUnixStyleFilePath) - { return nsFileSpecImpl::SetUnixStyleFilePath(aUnixStyleFilePath); } - - /* attribute string PersistentDescriptorString; */ - NS_IMETHOD GetPersistentDescriptorString(char * *aPersistentDescriptorString) - { return nsFileSpecImpl::GetPersistentDescriptorString(aPersistentDescriptorString); } - NS_IMETHOD SetPersistentDescriptorString(char * aPersistentDescriptorString) - { return nsFileSpecImpl::SetPersistentDescriptorString(aPersistentDescriptorString); } - - /* attribute string NativePath; */ - NS_IMETHOD GetNativePath(char * *aNativePath) - { return nsFileSpecImpl::GetNativePath(aNativePath); } - NS_IMETHOD SetNativePath(char * aNativePath) - { return nsFileSpecImpl::SetNativePath(aNativePath); } - - /* readonly attribute string NSPRPath; */ - NS_IMETHOD GetNSPRPath(char * *aNSPRPath) - { return nsFileSpecImpl::GetNSPRPath(aNSPRPath); } - - /* readonly attribute nsresult Error; */ - NS_IMETHOD error() - { return nsFileSpecImpl::error(); } - - /* boolean isValid (); */ - NS_IMETHOD isValid(PRBool *_retval) - { return nsFileSpecImpl::isValid(_retval); } - - /* boolean failed (); */ - NS_IMETHOD failed(PRBool *_retval) - { return nsFileSpecImpl::failed(_retval); } - - /* attribute string LeafName; */ - NS_IMETHOD GetLeafName(char * *aLeafName) - { return nsFileSpecImpl::GetLeafName(aLeafName); } - NS_IMETHOD SetLeafName(char * aLeafName) - { return nsFileSpecImpl::SetLeafName(aLeafName); } - - /* readonly attribute nsIFileSpec Parent; */ - NS_IMETHOD GetParent(nsIFileSpec * *aParent) - { return nsFileSpecImpl::GetParent(aParent); } - - /* nsIFileSpec makeUnique (); */ - NS_IMETHOD makeUnique() - { return nsFileSpecImpl::makeUnique(); } - - /* nsIFileSpec makeUniqueWithSuggestedName (in string suggestedName); */ - NS_IMETHOD makeUniqueWithSuggestedName(const char* inSuggestedLeafName) - { return nsFileSpecImpl::makeUniqueWithSuggestedName(inSuggestedLeafName); } - - /* readonly attribute unsigned long ModDate; */ - NS_IMETHOD GetModDate(PRUint32 *aModDate) - { return nsFileSpecImpl::GetModDate(aModDate); } - - /* boolean modDateChanged (in unsigned long oldStamp); */ - NS_IMETHOD modDateChanged(PRUint32 oldStamp, PRBool *_retval) - { return nsFileSpecImpl::modDateChanged(oldStamp, _retval); } - - /* boolean isDirectory (); */ - NS_IMETHOD isDirectory(PRBool *_retval) - { return nsFileSpecImpl::isDirectory(_retval); } - - /* boolean isFile (); */ - NS_IMETHOD isFile(PRBool *_retval) - { return nsFileSpecImpl::isFile(_retval); } - - /* boolean exists (); */ - NS_IMETHOD exists(PRBool *_retval) - { return nsFileSpecImpl::exists(_retval); } - - /* readonly attribute unsigned long FileSize; */ - NS_IMETHOD GetFileSize(PRUint32 *aFileSize) - { return nsFileSpecImpl::GetFileSize(aFileSize); } - - /* readonly attribute unsigned long DiskSpaceAvailable; */ - NS_IMETHOD GetDiskSpaceAvailable(PRUint32 *aDiskSpaceAvailable) - { return nsFileSpecImpl::GetDiskSpaceAvailable(aDiskSpaceAvailable); } - - /* nsIFileSpec AppendRelativeUnixPath (in string relativePath); */ - NS_IMETHOD AppendRelativeUnixPath(const char *relativePath) - { return nsFileSpecImpl::AppendRelativeUnixPath(relativePath); } - - /* void createDir (); */ - NS_IMETHOD createDir() - { return nsFileSpecImpl::createDir(); } - - /* void rename ([const] in string newLeafName); */ - NS_IMETHOD rename(const char *newLeafName) - { return nsFileSpecImpl::rename(newLeafName); } - - /* void copyToDir ([const] in nsIFileSpec newParentDir); */ - NS_IMETHOD copyToDir(const nsIFileSpec *newParentDir) - { return nsFileSpecImpl::copyToDir(newParentDir); } - - /* void moveToDir ([const] in nsIFileSpec newParentDir); */ - NS_IMETHOD moveToDir(const nsIFileSpec *newParentDir) - { return nsFileSpecImpl::moveToDir(newParentDir); } - - /* void execute ([const] in string args); */ - NS_IMETHOD execute(const char *args) - { return nsFileSpecImpl::execute(args); } - - /* void openStreamForReading (); */ - NS_IMETHOD openStreamForReading() - { return nsFileSpecImpl::openStreamForReading(); } - - /* void openStreamForWriting (); */ - NS_IMETHOD openStreamForWriting() - { return nsFileSpecImpl::openStreamForWriting(); } - - /* void openStreamForReadingAndWriting (); */ - NS_IMETHOD openStreamForReadingAndWriting() - { return nsFileSpecImpl::openStreamForReadingAndWriting(); } - - /* void close (); */ - NS_IMETHOD closeStream() - { return nsFileSpecImpl::closeStream(); } - - /* boolean isOpen (); */ - NS_IMETHOD isStreamOpen(PRBool *_retval) - { return nsFileSpecImpl::isStreamOpen(_retval); } - - /* boolean eof (); */ - NS_IMETHOD eof(PRBool *_retval) - { return nsFileSpecImpl::eof(_retval); } - - NS_IMETHOD read(char** buffer, PRInt32 requestedCount, PRInt32 *_retval) - { return nsFileSpecImpl::read(buffer, requestedCount, _retval); } - - NS_IMETHOD readLine(char** line, PRInt32 bufferSize, PRBool *wasTruncated) - { return nsFileSpecImpl::readLine(line, bufferSize, wasTruncated); } - // Check eof() before each call. - // CAUTION: false result only indicates line was truncated - // to fit buffer, or an error occurred (OTHER THAN eof). - - - NS_IMETHOD write(const char* data, PRInt32 requestedCount, PRInt32 *_retval) - { return nsFileSpecImpl::write(data, requestedCount, _retval); } - - /* void flush (); */ - NS_IMETHOD flush() - { return nsFileSpecImpl::flush(); } - - /* void seek (in long offset); */ - NS_IMETHOD seek(PRInt32 offset) - { return nsFileSpecImpl::seek(offset); } - - /* long tell (); */ - NS_IMETHOD tell(PRInt32 *_retval) - { return nsFileSpecImpl::tell(_retval); } - - /* void endline (); */ - NS_IMETHOD endline() - { return nsFileSpecImpl::endline(); } - - -}; // class nsFileSpecWithUIImpl - -NS_IMPL_ISUPPORTS_INHERITED(nsFileSpecWithUIImpl, nsFileSpecImpl, nsIFileSpecWithUI) +NS_IMPL_ISUPPORTS(nsFileSpecWithUIImpl, nsIFileSpecWithUI::GetIID()) static NS_DEFINE_IID(kCFileWidgetCID, NS_FILEWIDGET_CID); @@ -231,6 +35,13 @@ static NS_DEFINE_IID(kCFileWidgetCID, NS_FILEWIDGET_CID); nsFileSpecWithUIImpl::nsFileSpecWithUIImpl() //---------------------------------------------------------------------------------------- { + NS_INIT_REFCNT(); + nsresult rv = nsComponentManager::CreateInstance( + (const char*)NS_FILESPEC_PROGID, + (nsISupports*)nsnull, + (const nsID&)nsIFileSpec::GetIID(), + (void**)getter_AddRefs(mBaseFileSpec)); + NS_ASSERTION(NS_SUCCEEDED(rv), "ERROR: Could not make a file spec."); } //---------------------------------------------------------------------------------------- @@ -245,6 +56,8 @@ NS_IMETHODIMP nsFileSpecWithUIImpl::chooseOutputFile( const char *suggestedLeafName) //---------------------------------------------------------------------------------------- { + if (!mBaseFileSpec) + return NS_ERROR_NULL_POINTER; nsCOMPtr fileWidget; nsresult rv = nsComponentManager::CreateInstance( kCFileWidgetCID, @@ -255,12 +68,13 @@ NS_IMETHODIMP nsFileSpecWithUIImpl::chooseOutputFile( return rv; fileWidget->SetDefaultString(suggestedLeafName); - nsFileDlgResults result = fileWidget->PutFile(nsnull, windowTitle, mFileSpec); - if ( result != nsFileDlgResults_OK) + nsFileSpec spec; + nsFileDlgResults result = fileWidget->PutFile(nsnull, windowTitle, spec); + if (result != nsFileDlgResults_OK) return NS_FILE_FAILURE; - if (mFileSpec.Exists() && result != nsFileDlgResults_Replace) + if (spec.Exists() && result != nsFileDlgResults_Replace) return NS_FILE_FAILURE; - return NS_OK; + return mBaseFileSpec->setFromFileSpec(spec); } // nsFileSpecImpl::chooseOutputFile //---------------------------------------------------------------------------------------- @@ -270,9 +84,12 @@ NS_IMETHODIMP nsFileSpecWithUIImpl::chooseInputFile( const char *inExtraFilterTitle, const char *inExtraFilter) //---------------------------------------------------------------------------------------- { + if (!mBaseFileSpec) + return NS_ERROR_NULL_POINTER; nsresult rv = NS_OK; nsString* nextTitle; nsString* nextFilter; + nsFileSpec spec; nsCOMPtr fileWidget; rv = nsComponentManager::CreateInstance( kCFileWidgetCID, @@ -329,8 +146,9 @@ NS_IMETHODIMP nsFileSpecWithUIImpl::chooseInputFile( } fileWidget->SetFilterList(nextFilter - filters, titles, filters); - if (fileWidget->GetFile(nsnull, inTitle, mFileSpec) != nsFileDlgResults_OK) + if (fileWidget->GetFile(nsnull, inTitle, spec) != nsFileDlgResults_OK) rv = NS_FILE_FAILURE; + rv = mBaseFileSpec->setFromFileSpec(spec); Clean: delete [] titles; @@ -342,6 +160,8 @@ Clean: NS_IMETHODIMP nsFileSpecWithUIImpl::chooseDirectory(const char *title) //---------------------------------------------------------------------------------------- { + if (!mBaseFileSpec) + return NS_ERROR_NULL_POINTER; nsCOMPtr fileWidget; nsresult rv = nsComponentManager::CreateInstance( kCFileWidgetCID, @@ -350,20 +170,9 @@ NS_IMETHODIMP nsFileSpecWithUIImpl::chooseDirectory(const char *title) (void**)getter_AddRefs(fileWidget)); if (NS_FAILED(rv)) return rv; - if (fileWidget->GetFolder(nsnull, title, mFileSpec) != nsFileDlgResults_OK) + nsFileSpec spec; + if (fileWidget->GetFolder(nsnull, title, spec) != nsFileDlgResults_OK) rv = NS_FILE_FAILURE; - return NS_OK; + return mBaseFileSpec->setFromFileSpec(spec); } // nsFileSpecWithUIImpl::chooseDirectory -//---------------------------------------------------------------------------------------- -NS_WIDGET nsresult NS_NewFileSpecWithUI(nsIFileSpecWithUI** result) -//---------------------------------------------------------------------------------------- -{ - if (!result) - return NS_ERROR_NULL_POINTER; - nsFileSpecWithUIImpl* it = new nsFileSpecWithUIImpl; - if (!it) - return NS_ERROR_OUT_OF_MEMORY; - return it->QueryInterface(nsIFileSpecWithUI::GetIID(), (void **) result); -} -