Bug 751729 - File dialogs don't open with Visual Themes disabled in Windows 7 fix. r=jimm

This commit is contained in:
Brian R. Bondy 2012-07-03 10:38:09 -04:00
parent b8d40b05f7
commit 45f24fb0bf
2 changed files with 46 additions and 15 deletions

View File

@ -564,14 +564,26 @@ nsFilePicker::ShowXPFolderPicker(const nsString& aInitialDir)
return result;
}
/*
* Show a folder picker post Windows XP
*
* @param aInitialDir The initial directory, the last used directory will be
* used if left blank.
* @param aWasInitError Out parameter will hold true if there was an error
* before the folder picker is shown.
* @return true if a file was selected successfully.
*/
bool
nsFilePicker::ShowFolderPicker(const nsString& aInitialDir)
nsFilePicker::ShowFolderPicker(const nsString& aInitialDir, bool &aWasInitError)
{
nsRefPtr<IFileOpenDialog> dialog;
if (FAILED(CoCreateInstance(CLSID_FileOpenDialog, NULL, CLSCTX_INPROC,
IID_IFileOpenDialog,
getter_AddRefs(dialog))))
getter_AddRefs(dialog)))) {
aWasInitError = true;
return false;
}
aWasInitError = false;
// hook up event callbacks
dialog->Advise(this, &mFDECookie);
@ -840,21 +852,35 @@ nsFilePicker::ShowXPFilePicker(const nsString& aInitialDir)
return true;
}
/*
* Show a file picker post Windows XP
*
* @param aInitialDir The initial directory, the last used directory will be
* used if left blank.
* @param aWasInitError Out parameter will hold true if there was an error
* before the file picker is shown.
* @return true if a file was selected successfully.
*/
bool
nsFilePicker::ShowFilePicker(const nsString& aInitialDir)
nsFilePicker::ShowFilePicker(const nsString& aInitialDir, bool &aWasInitError)
{
nsRefPtr<IFileDialog> dialog;
if (mMode != modeSave) {
if (FAILED(CoCreateInstance(CLSID_FileOpenDialog, NULL, CLSCTX_INPROC,
IID_IFileOpenDialog,
getter_AddRefs(dialog))))
getter_AddRefs(dialog)))) {
aWasInitError = true;
return false;
}
} else {
if (FAILED(CoCreateInstance(CLSID_FileSaveDialog, NULL, CLSCTX_INPROC,
IID_IFileSaveDialog,
getter_AddRefs(dialog))))
getter_AddRefs(dialog)))) {
aWasInitError = true;
return false;
}
}
aWasInitError = false;
// hook up event callbacks
dialog->Advise(this, &mFDECookie);
@ -1017,18 +1043,23 @@ nsFilePicker::ShowW(PRInt16 *aReturnVal)
mUnicodeFile.Truncate();
mFiles.Clear();
bool result = false;
if (mMode == modeGetFolder) {
// Launch the XP file/folder picker on XP and as a fallback on Vista+.
// The CoCreateInstance call to CLSID_FileOpenDialog fails with "(0x80040111)
// ClassFactory cannot supply requested class" when the checkbox for
// Disable Visual Themes is on in the compatability tab within the shortcut
// properties.
bool result = false, wasInitError = true;
if (mMode == modeGetFolder) {
if (WinUtils::GetWindowsVersion() >= WinUtils::VISTA_VERSION)
result = ShowFolderPicker(initialDir);
else
result = ShowFolderPicker(initialDir, wasInitError);
if (!result && wasInitError)
result = ShowXPFolderPicker(initialDir);
} else {
} else {
if (WinUtils::GetWindowsVersion() >= WinUtils::VISTA_VERSION)
result = ShowFilePicker(initialDir);
else
result = ShowFilePicker(initialDir, wasInitError);
if (!result && wasInitError)
result = ShowXPFilePicker(initialDir);
}
}
// exit, and return returnCancel in aReturnVal
if (!result)

View File

@ -91,8 +91,8 @@ protected:
bool FilePickerWrapper(OPENFILENAMEW* ofn, PickerType aType);
bool ShowXPFolderPicker(const nsString& aInitialDir);
bool ShowXPFilePicker(const nsString& aInitialDir);
bool ShowFolderPicker(const nsString& aInitialDir);
bool ShowFilePicker(const nsString& aInitialDir);
bool ShowFolderPicker(const nsString& aInitialDir, bool &aWasInitError);
bool ShowFilePicker(const nsString& aInitialDir, bool &aWasInitError);
void AppendXPFilter(const nsAString& aTitle, const nsAString& aFilter);
void RememberLastUsedDirectory();
bool IsPrivacyModeEnabled();