2015-05-22 18:14:25 -05:00
|
|
|
// 22 may 2015
|
|
|
|
#include "uipriv_windows.h"
|
|
|
|
|
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)
|
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-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
|
|
|
{
|
2015-05-31 20:23:44 -05:00
|
|
|
IFileDialog *d;
|
2015-05-31 19:27:01 -05:00
|
|
|
FILEOPENDIALOGOPTIONS opts;
|
|
|
|
IShellItem *result;
|
|
|
|
WCHAR *wname;
|
|
|
|
char *name;
|
|
|
|
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));
|
2015-05-31 19:27:01 -05:00
|
|
|
if (hr != S_OK)
|
2015-05-31 20:23:44 -05:00
|
|
|
logHRESULT("error creating common item dialog in commonItemDialog()", hr);
|
|
|
|
hr = IFileDialog_GetOptions(d, &opts);
|
2015-05-31 19:27:01 -05:00
|
|
|
if (hr != S_OK)
|
2015-05-31 20:23:44 -05:00
|
|
|
logHRESULT("error getting current options in commonItemDialog()", hr);
|
|
|
|
opts |= optsadd;
|
|
|
|
hr = IFileDialog_SetOptions(d, opts);
|
2015-05-31 19:27:01 -05:00
|
|
|
if (hr != S_OK)
|
2015-05-31 20:23:44 -05:00
|
|
|
logHRESULT("error setting options in commonItemDialog()", hr);
|
2015-11-28 09:53:48 -06:00
|
|
|
hr = IFileDialog_Show(d, parent);
|
2015-05-31 19:27:01 -05:00
|
|
|
if (hr == HRESULT_FROM_WIN32(ERROR_CANCELLED)) {
|
2015-05-31 20:23:44 -05:00
|
|
|
IFileDialog_Release(d);
|
2015-05-22 18:14:25 -05:00
|
|
|
return NULL;
|
|
|
|
}
|
2015-05-31 19:27:01 -05:00
|
|
|
if (hr != S_OK)
|
2015-05-31 20:23:44 -05:00
|
|
|
logHRESULT("error showing dialog in commonItemDialog()", hr);
|
|
|
|
hr = IFileDialog_GetResult(d, &result);
|
2015-05-31 19:27:01 -05:00
|
|
|
if (hr != S_OK)
|
2015-05-31 20:23:44 -05:00
|
|
|
logHRESULT("error getting dialog result in commonItemDialog()", hr);
|
2015-05-31 19:27:01 -05:00
|
|
|
hr = IShellItem_GetDisplayName(result, SIGDN_FILESYSPATH, &wname);
|
|
|
|
if (hr != S_OK)
|
2015-05-31 20:23:44 -05:00
|
|
|
logHRESULT("error getting filename in commonItemDialog()", hr);
|
2015-05-31 19:27:01 -05:00
|
|
|
name = toUTF8(wname);
|
|
|
|
CoTaskMemFree(wname);
|
|
|
|
IShellItem_Release(result);
|
2015-05-31 20:23:44 -05:00
|
|
|
IFileDialog_Release(d);
|
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),
|
|
|
|
&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),
|
|
|
|
&CLSID_FileSaveDialog, &IID_IFileSaveDialog,
|
2015-05-31 20:23:44 -05:00
|
|
|
// TODO strip FOS_NOREADONLYRETURN?
|
|
|
|
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)
|
|
|
|
logHRESULT("error showing task dialog in msgbox()", 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
|
|
|
}
|