Migrated stddialogs.c.
This commit is contained in:
parent
02b5285aa0
commit
9e90475e11
|
@ -1,5 +1,5 @@
|
||||||
// 22 may 2015
|
// 22 may 2015
|
||||||
#include "uipriv_windows.h"
|
#include "uipriv_windows.hpp"
|
||||||
|
|
||||||
// notes:
|
// notes:
|
||||||
// - FOS_SUPPORTSTREAMABLEITEMS doesn't seem to be supported on windows vista, or at least not with the flags we use
|
// - FOS_SUPPORTSTREAMABLEITEMS doesn't seem to be supported on windows vista, or at least not with the flags we use
|
||||||
|
@ -14,56 +14,73 @@
|
||||||
|
|
||||||
char *commonItemDialog(HWND parent, REFCLSID clsid, REFIID iid, FILEOPENDIALOGOPTIONS optsadd)
|
char *commonItemDialog(HWND parent, REFCLSID clsid, REFIID iid, FILEOPENDIALOGOPTIONS optsadd)
|
||||||
{
|
{
|
||||||
IFileDialog *d;
|
IFileDialog *d = NULL;
|
||||||
FILEOPENDIALOGOPTIONS opts;
|
FILEOPENDIALOGOPTIONS opts;
|
||||||
IShellItem *result;
|
IShellItem *result = NULL;
|
||||||
WCHAR *wname;
|
WCHAR *wname = NULL;
|
||||||
char *name;
|
char *name = NULL;
|
||||||
HRESULT hr;
|
HRESULT hr;
|
||||||
|
|
||||||
hr = CoCreateInstance(clsid,
|
hr = CoCreateInstance(clsid,
|
||||||
NULL, CLSCTX_INPROC_SERVER,
|
NULL, CLSCTX_INPROC_SERVER,
|
||||||
iid, (LPVOID *) (&d));
|
iid, (LPVOID *) (&d));
|
||||||
if (hr != S_OK)
|
if (hr != S_OK) {
|
||||||
logHRESULT("error creating common item dialog in commonItemDialog()", hr);
|
logHRESULT(L"error creating common item dialog", hr);
|
||||||
hr = IFileDialog_GetOptions(d, &opts);
|
// always return NULL on error
|
||||||
if (hr != S_OK)
|
goto out;
|
||||||
logHRESULT("error getting current options in commonItemDialog()", hr);
|
}
|
||||||
opts |= optsadd;
|
hr = d->GetOptions(&opts);
|
||||||
hr = IFileDialog_SetOptions(d, opts);
|
if (hr != S_OK) {
|
||||||
if (hr != S_OK)
|
logHRESULT(L"error getting current options", hr);
|
||||||
logHRESULT("error setting options in commonItemDialog()", hr);
|
goto out;
|
||||||
hr = IFileDialog_Show(d, parent);
|
}
|
||||||
if (hr == HRESULT_FROM_WIN32(ERROR_CANCELLED)) {
|
opts |= optsadd;
|
||||||
IFileDialog_Release(d);
|
hr = d->SetOptions(opts);
|
||||||
return NULL;
|
if (hr != S_OK) {
|
||||||
|
logHRESULT(L"error setting options", hr);
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
hr = d->Show(parent);
|
||||||
|
if (hr == HRESULT_FROM_WIN32(ERROR_CANCELLED))
|
||||||
|
// cancelled; return NULL like we have ready
|
||||||
|
goto out;
|
||||||
|
if (hr != S_OK) {
|
||||||
|
logHRESULT(L"error showing dialog", hr);
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
hr = d->GetResult(&result);
|
||||||
|
if (hr != S_OK) {
|
||||||
|
logHRESULT(L"error getting dialog result", hr);
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
hr = result->GetDisplayName(SIGDN_FILESYSPATH, &wname);
|
||||||
|
if (hr != S_OK) {
|
||||||
|
logHRESULT(L"error getting filename", hr);
|
||||||
|
goto out;
|
||||||
}
|
}
|
||||||
if (hr != S_OK)
|
|
||||||
logHRESULT("error showing dialog in commonItemDialog()", hr);
|
|
||||||
hr = IFileDialog_GetResult(d, &result);
|
|
||||||
if (hr != S_OK)
|
|
||||||
logHRESULT("error getting dialog result in commonItemDialog()", hr);
|
|
||||||
hr = IShellItem_GetDisplayName(result, SIGDN_FILESYSPATH, &wname);
|
|
||||||
if (hr != S_OK)
|
|
||||||
logHRESULT("error getting filename in commonItemDialog()", hr);
|
|
||||||
name = toUTF8(wname);
|
name = toUTF8(wname);
|
||||||
CoTaskMemFree(wname);
|
|
||||||
IShellItem_Release(result);
|
out:
|
||||||
IFileDialog_Release(d);
|
if (wname != NULL)
|
||||||
|
CoTaskMemFree(wname);
|
||||||
|
if (result != NULL)
|
||||||
|
result->Release();
|
||||||
|
if (d != NULL)
|
||||||
|
d->Release();
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *uiOpenFile(uiWindow *parent)
|
char *uiOpenFile(uiWindow *parent)
|
||||||
{
|
{
|
||||||
return commonItemDialog(windowHWND(parent),
|
return commonItemDialog(windowHWND(parent),
|
||||||
&CLSID_FileOpenDialog, &IID_IFileOpenDialog,
|
CLSID_FileOpenDialog, IID_IFileOpenDialog,
|
||||||
FOS_NOCHANGEDIR | FOS_ALLNONSTORAGEITEMS | FOS_NOVALIDATE | FOS_PATHMUSTEXIST | FOS_FILEMUSTEXIST | FOS_SHAREAWARE | FOS_NOTESTFILECREATE | FOS_NODEREFERENCELINKS | FOS_FORCESHOWHIDDEN | FOS_DEFAULTNOMINIMODE);
|
FOS_NOCHANGEDIR | FOS_ALLNONSTORAGEITEMS | FOS_NOVALIDATE | FOS_PATHMUSTEXIST | FOS_FILEMUSTEXIST | FOS_SHAREAWARE | FOS_NOTESTFILECREATE | FOS_NODEREFERENCELINKS | FOS_FORCESHOWHIDDEN | FOS_DEFAULTNOMINIMODE);
|
||||||
}
|
}
|
||||||
|
|
||||||
char *uiSaveFile(uiWindow *parent)
|
char *uiSaveFile(uiWindow *parent)
|
||||||
{
|
{
|
||||||
return commonItemDialog(windowHWND(parent),
|
return commonItemDialog(windowHWND(parent),
|
||||||
&CLSID_FileSaveDialog, &IID_IFileSaveDialog,
|
CLSID_FileSaveDialog, IID_IFileSaveDialog,
|
||||||
// TODO strip FOS_NOREADONLYRETURN?
|
// TODO strip FOS_NOREADONLYRETURN?
|
||||||
FOS_OVERWRITEPROMPT | FOS_NOCHANGEDIR | FOS_ALLNONSTORAGEITEMS | FOS_NOVALIDATE | FOS_SHAREAWARE | FOS_NOTESTFILECREATE | FOS_NODEREFERENCELINKS | FOS_FORCESHOWHIDDEN | FOS_DEFAULTNOMINIMODE);
|
FOS_OVERWRITEPROMPT | FOS_NOCHANGEDIR | FOS_ALLNONSTORAGEITEMS | FOS_NOVALIDATE | FOS_SHAREAWARE | FOS_NOTESTFILECREATE | FOS_NODEREFERENCELINKS | FOS_FORCESHOWHIDDEN | FOS_DEFAULTNOMINIMODE);
|
||||||
}
|
}
|
||||||
|
@ -80,7 +97,7 @@ static void msgbox(HWND parent, const char *title, const char *description, TASK
|
||||||
|
|
||||||
hr = TaskDialog(parent, NULL, NULL, wtitle, wdescription, buttons, icon, NULL);
|
hr = TaskDialog(parent, NULL, NULL, wtitle, wdescription, buttons, icon, NULL);
|
||||||
if (hr != S_OK)
|
if (hr != S_OK)
|
||||||
logHRESULT("error showing task dialog in msgbox()", hr);
|
logHRESULT(L"error showing task dialog", hr);
|
||||||
|
|
||||||
uiFree(wdescription);
|
uiFree(wdescription);
|
||||||
uiFree(wtitle);
|
uiFree(wtitle);
|
Loading…
Reference in New Issue