2015-05-22 18:14:25 -05:00
|
|
|
// 22 may 2015
|
2016-04-22 16:49:14 -05:00
|
|
|
#include "uipriv_windows.hpp"
|
2015-05-22 18:14:25 -05:00
|
|
|
|
2015-06-03 11:10:08 -05:00
|
|
|
// notes:
|
|
|
|
// - FOS_SUPPORTSTREAMABLEITEMS doesn't seem to be supported on windows vista, or at least not with the flags we use
|
|
|
|
// - even with FOS_NOVALIDATE the dialogs will reject invalid filenames (at least on Vista, anyway)
|
2016-05-06 15:06:55 -05:00
|
|
|
// - lack of FOS_NOREADONLYRETURN doesn't seem to matter on Windows 7
|
2015-06-01 12:46:22 -05:00
|
|
|
|
2015-11-23 18:12:11 -06:00
|
|
|
// TODO
|
|
|
|
// - http://blogs.msdn.com/b/wpfsdk/archive/2006/10/26/uncommon-dialogs--font-chooser-and-color-picker-dialogs.aspx
|
2015-11-28 09:53:48 -06:00
|
|
|
// - when a dialog is active, tab navigation in other windows stops working
|
2015-11-30 08:12:56 -06:00
|
|
|
// - when adding uiOpenFolder(), use IFileDialog as well - https://msdn.microsoft.com/en-us/library/windows/desktop/bb762115%28v=vs.85%29.aspx
|
2015-11-23 18:12:11 -06:00
|
|
|
|
2015-11-28 09:53:48 -06:00
|
|
|
#define windowHWND(w) ((HWND) uiControlHandle(uiControl(w)))
|
|
|
|
|
|
|
|
char *commonItemDialog(HWND parent, REFCLSID clsid, REFIID iid, FILEOPENDIALOGOPTIONS optsadd)
|
2015-05-22 18:14:25 -05:00
|
|
|
{
|
2016-04-22 16:49:14 -05:00
|
|
|
IFileDialog *d = NULL;
|
2015-05-31 19:27:01 -05:00
|
|
|
FILEOPENDIALOGOPTIONS opts;
|
2016-04-22 16:49:14 -05:00
|
|
|
IShellItem *result = NULL;
|
|
|
|
WCHAR *wname = NULL;
|
|
|
|
char *name = NULL;
|
2015-05-31 19:27:01 -05:00
|
|
|
HRESULT hr;
|
2015-05-22 18:14:25 -05:00
|
|
|
|
2015-05-31 20:23:44 -05:00
|
|
|
hr = CoCreateInstance(clsid,
|
2015-05-31 19:27:01 -05:00
|
|
|
NULL, CLSCTX_INPROC_SERVER,
|
2015-05-31 20:23:44 -05:00
|
|
|
iid, (LPVOID *) (&d));
|
2016-04-22 16:49:14 -05:00
|
|
|
if (hr != S_OK) {
|
|
|
|
logHRESULT(L"error creating common item dialog", hr);
|
|
|
|
// always return NULL on error
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
hr = d->GetOptions(&opts);
|
|
|
|
if (hr != S_OK) {
|
|
|
|
logHRESULT(L"error getting current options", hr);
|
|
|
|
goto out;
|
|
|
|
}
|
2015-05-31 20:23:44 -05:00
|
|
|
opts |= optsadd;
|
2016-05-06 15:06:55 -05:00
|
|
|
// the other platforms don't check read-only; we won't either
|
|
|
|
opts &= ~FOS_NOREADONLYRETURN;
|
2016-04-22 16:49:14 -05:00
|
|
|
hr = d->SetOptions(opts);
|
|
|
|
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;
|
2015-05-22 18:14:25 -05:00
|
|
|
}
|
2015-05-31 19:27:01 -05:00
|
|
|
name = toUTF8(wname);
|
2016-04-22 16:49:14 -05:00
|
|
|
|
|
|
|
out:
|
|
|
|
if (wname != NULL)
|
|
|
|
CoTaskMemFree(wname);
|
|
|
|
if (result != NULL)
|
|
|
|
result->Release();
|
|
|
|
if (d != NULL)
|
|
|
|
d->Release();
|
2015-05-31 19:27:01 -05:00
|
|
|
return name;
|
2015-05-22 18:14:25 -05:00
|
|
|
}
|
2015-05-22 20:59:32 -05:00
|
|
|
|
2015-11-28 09:53:48 -06:00
|
|
|
char *uiOpenFile(uiWindow *parent)
|
2015-05-22 20:59:32 -05:00
|
|
|
{
|
2015-11-28 09:53:48 -06:00
|
|
|
return commonItemDialog(windowHWND(parent),
|
2016-04-22 16:49:14 -05:00
|
|
|
CLSID_FileOpenDialog, IID_IFileOpenDialog,
|
2015-05-31 20:23:44 -05:00
|
|
|
FOS_NOCHANGEDIR | FOS_ALLNONSTORAGEITEMS | FOS_NOVALIDATE | FOS_PATHMUSTEXIST | FOS_FILEMUSTEXIST | FOS_SHAREAWARE | FOS_NOTESTFILECREATE | FOS_NODEREFERENCELINKS | FOS_FORCESHOWHIDDEN | FOS_DEFAULTNOMINIMODE);
|
|
|
|
}
|
2015-05-22 20:59:32 -05:00
|
|
|
|
2015-11-28 09:53:48 -06:00
|
|
|
char *uiSaveFile(uiWindow *parent)
|
2015-05-31 20:23:44 -05:00
|
|
|
{
|
2015-11-28 09:53:48 -06:00
|
|
|
return commonItemDialog(windowHWND(parent),
|
2016-04-22 16:49:14 -05:00
|
|
|
CLSID_FileSaveDialog, IID_IFileSaveDialog,
|
2015-05-31 20:23:44 -05:00
|
|
|
FOS_OVERWRITEPROMPT | FOS_NOCHANGEDIR | FOS_ALLNONSTORAGEITEMS | FOS_NOVALIDATE | FOS_SHAREAWARE | FOS_NOTESTFILECREATE | FOS_NODEREFERENCELINKS | FOS_FORCESHOWHIDDEN | FOS_DEFAULTNOMINIMODE);
|
2015-05-22 20:59:32 -05:00
|
|
|
}
|
2015-05-23 14:07:16 -05:00
|
|
|
|
2015-11-28 09:53:48 -06:00
|
|
|
// TODO switch to TaskDialogIndirect()?
|
|
|
|
|
|
|
|
static void msgbox(HWND parent, const char *title, const char *description, TASKDIALOG_COMMON_BUTTON_FLAGS buttons, PCWSTR icon)
|
2015-05-23 14:07:16 -05:00
|
|
|
{
|
|
|
|
WCHAR *wtitle, *wdescription;
|
2015-05-31 18:17:35 -05:00
|
|
|
HRESULT hr;
|
|
|
|
|
2015-05-23 14:07:16 -05:00
|
|
|
wtitle = toUTF16(title);
|
|
|
|
wdescription = toUTF16(description);
|
|
|
|
|
2015-11-28 09:53:48 -06:00
|
|
|
hr = TaskDialog(parent, NULL, NULL, wtitle, wdescription, buttons, icon, NULL);
|
2015-05-31 18:17:35 -05:00
|
|
|
if (hr != S_OK)
|
2016-04-22 16:49:14 -05:00
|
|
|
logHRESULT(L"error showing task dialog", hr);
|
2015-05-23 14:07:16 -05:00
|
|
|
|
|
|
|
uiFree(wdescription);
|
|
|
|
uiFree(wtitle);
|
|
|
|
}
|
|
|
|
|
2015-11-28 09:53:48 -06:00
|
|
|
void uiMsgBox(uiWindow *parent, const char *title, const char *description)
|
2015-05-23 14:07:16 -05:00
|
|
|
{
|
2015-11-28 09:53:48 -06:00
|
|
|
msgbox(windowHWND(parent), title, description, TDCBF_OK_BUTTON, NULL);
|
2015-05-23 14:07:16 -05:00
|
|
|
}
|
|
|
|
|
2015-11-28 09:53:48 -06:00
|
|
|
void uiMsgBoxError(uiWindow *parent, const char *title, const char *description)
|
2015-05-23 14:07:16 -05:00
|
|
|
{
|
2015-11-28 09:53:48 -06:00
|
|
|
msgbox(windowHWND(parent), title, description, TDCBF_OK_BUTTON, TD_ERROR_ICON);
|
2015-05-23 14:07:16 -05:00
|
|
|
}
|