Merge 4768cad824
into fea45b2d5b
This commit is contained in:
commit
d7dc7b9edc
|
@ -32,7 +32,7 @@ static char *runSavePanel(NSWindow *parent, NSSavePanel *s)
|
||||||
return filename;
|
return filename;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *uiOpenFile(uiWindow *parent)
|
char *uiOpenFile(uiWindow *parent, char* filter)
|
||||||
{
|
{
|
||||||
NSOpenPanel *o;
|
NSOpenPanel *o;
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ char *uiOpenFile(uiWindow *parent)
|
||||||
return runSavePanel(windowWindow(parent), o);
|
return runSavePanel(windowWindow(parent), o);
|
||||||
}
|
}
|
||||||
|
|
||||||
char *uiSaveFile(uiWindow *parent)
|
char *uiSaveFile(uiWindow *parent, char* filter)
|
||||||
{
|
{
|
||||||
NSSavePanel *s;
|
NSSavePanel *s;
|
||||||
|
|
||||||
|
|
6
ui.h
6
ui.h
|
@ -130,7 +130,7 @@ _UI_EXTERN void uiWindowSetBorderless(uiWindow *w, int borderless);
|
||||||
_UI_EXTERN void uiWindowSetChild(uiWindow *w, uiControl *child);
|
_UI_EXTERN void uiWindowSetChild(uiWindow *w, uiControl *child);
|
||||||
_UI_EXTERN int uiWindowMargined(uiWindow *w);
|
_UI_EXTERN int uiWindowMargined(uiWindow *w);
|
||||||
_UI_EXTERN void uiWindowSetMargined(uiWindow *w, int margined);
|
_UI_EXTERN void uiWindowSetMargined(uiWindow *w, int margined);
|
||||||
_UI_EXTERN uiWindow *uiNewWindow(const char *title, int width, int height, int hasMenubar);
|
_UI_EXTERN uiWindow *uiNewWindow(const char *title, int width, int height, int hasMenubar, int resizable);
|
||||||
|
|
||||||
typedef struct uiButton uiButton;
|
typedef struct uiButton uiButton;
|
||||||
#define uiButton(this) ((uiButton *) (this))
|
#define uiButton(this) ((uiButton *) (this))
|
||||||
|
@ -292,8 +292,8 @@ _UI_EXTERN uiMenuItem *uiMenuAppendAboutItem(uiMenu *m);
|
||||||
_UI_EXTERN void uiMenuAppendSeparator(uiMenu *m);
|
_UI_EXTERN void uiMenuAppendSeparator(uiMenu *m);
|
||||||
_UI_EXTERN uiMenu *uiNewMenu(const char *name);
|
_UI_EXTERN uiMenu *uiNewMenu(const char *name);
|
||||||
|
|
||||||
_UI_EXTERN char *uiOpenFile(uiWindow *parent);
|
_UI_EXTERN char *uiOpenFile(uiWindow *parent, char* filter);
|
||||||
_UI_EXTERN char *uiSaveFile(uiWindow *parent);
|
_UI_EXTERN char *uiSaveFile(uiWindow *parent, char* filter);
|
||||||
_UI_EXTERN void uiMsgBox(uiWindow *parent, const char *title, const char *description);
|
_UI_EXTERN void uiMsgBox(uiWindow *parent, const char *title, const char *description);
|
||||||
_UI_EXTERN void uiMsgBoxError(uiWindow *parent, const char *title, const char *description);
|
_UI_EXTERN void uiMsgBoxError(uiWindow *parent, const char *title, const char *description);
|
||||||
|
|
||||||
|
|
|
@ -4,20 +4,58 @@
|
||||||
// LONGTERM figure out why, and describe, that this is the desired behavior
|
// LONGTERM figure out why, and describe, that this is the desired behavior
|
||||||
// LONGTERM also point out that font and color buttons also work like this
|
// LONGTERM also point out that font and color buttons also work like this
|
||||||
|
|
||||||
#define windowWindow(w) (GTK_WINDOW(uiControlHandle(uiControl(w))))
|
#define windowWindow(w) ((w)?(GTK_WINDOW(uiControlHandle(uiControl(w)))):NULL)
|
||||||
|
|
||||||
static char *filedialog(GtkWindow *parent, GtkFileChooserAction mode, const gchar *confirm)
|
static char *filedialog(GtkWindow *parent, GtkFileChooserAction mode, const gchar *confirm, char* filter)
|
||||||
{
|
{
|
||||||
GtkWidget *fcd;
|
GtkWidget *fcd;
|
||||||
GtkFileChooser *fc;
|
GtkFileChooser *fc;
|
||||||
gint response;
|
gint response;
|
||||||
char *filename;
|
char *filename;
|
||||||
|
|
||||||
|
GtkFileFilter *filter;
|
||||||
|
gchar _filter[256];
|
||||||
|
gchar* fp = &_filter[0];
|
||||||
|
gchar* fname;
|
||||||
|
gchar *j;
|
||||||
|
int i;
|
||||||
|
int s;
|
||||||
|
|
||||||
fcd = gtk_file_chooser_dialog_new(NULL, parent, mode,
|
fcd = gtk_file_chooser_dialog_new(NULL, parent, mode,
|
||||||
"_Cancel", GTK_RESPONSE_CANCEL,
|
"_Cancel", GTK_RESPONSE_CANCEL,
|
||||||
confirm, GTK_RESPONSE_ACCEPT,
|
confirm, GTK_RESPONSE_ACCEPT,
|
||||||
NULL);
|
NULL);
|
||||||
fc = GTK_FILE_CHOOSER(fcd);
|
fc = GTK_FILE_CHOOSER(fcd);
|
||||||
|
|
||||||
|
for (i = s = 0; i < 255; i++) {
|
||||||
|
if (filter[i] == '|' || filter[i] == '\0') {
|
||||||
|
_filter[i] = '\0';
|
||||||
|
if (s & 1) {
|
||||||
|
filter = gtk_file_filter_new();
|
||||||
|
gtk_file_filter_set_name(filter, fname);
|
||||||
|
for (j = fp; ; j++) {
|
||||||
|
if (*j == ';') {
|
||||||
|
*j = '\0';
|
||||||
|
gtk_file_filter_add_pattern(filter, fp);
|
||||||
|
fp = j + 1;
|
||||||
|
} else if (*j == '\0') {
|
||||||
|
gtk_file_filter_add_pattern(filter, fp);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
gtk_file_chooser_add_filter(fc, filter);
|
||||||
|
} else {
|
||||||
|
fname = fp;
|
||||||
|
}
|
||||||
|
fp = &_filter[i + 1];
|
||||||
|
s++;
|
||||||
|
if (s >= 8) break;
|
||||||
|
if (filter[i] == '\0') break;
|
||||||
|
} else {
|
||||||
|
_filter[i] = filter[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
gtk_file_chooser_set_local_only(fc, FALSE);
|
gtk_file_chooser_set_local_only(fc, FALSE);
|
||||||
gtk_file_chooser_set_select_multiple(fc, FALSE);
|
gtk_file_chooser_set_select_multiple(fc, FALSE);
|
||||||
gtk_file_chooser_set_show_hidden(fc, TRUE);
|
gtk_file_chooser_set_show_hidden(fc, TRUE);
|
||||||
|
@ -33,14 +71,14 @@ static char *filedialog(GtkWindow *parent, GtkFileChooserAction mode, const gcha
|
||||||
return filename;
|
return filename;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *uiOpenFile(uiWindow *parent)
|
char *uiOpenFile(uiWindow *parent, char* filter)
|
||||||
{
|
{
|
||||||
return filedialog(windowWindow(parent), GTK_FILE_CHOOSER_ACTION_OPEN, "_Open");
|
return filedialog(windowWindow(parent), GTK_FILE_CHOOSER_ACTION_OPEN, "_Open", filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
char *uiSaveFile(uiWindow *parent)
|
char *uiSaveFile(uiWindow *parent, char* filter)
|
||||||
{
|
{
|
||||||
return filedialog(windowWindow(parent), GTK_FILE_CHOOSER_ACTION_SAVE, "_Save");
|
return filedialog(windowWindow(parent), GTK_FILE_CHOOSER_ACTION_SAVE, "_Save", filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void msgbox(GtkWindow *parent, const char *title, const char *description, GtkMessageType type, GtkButtonsType buttons)
|
static void msgbox(GtkWindow *parent, const char *title, const char *description, GtkMessageType type, GtkButtonsType buttons)
|
||||||
|
|
|
@ -229,7 +229,7 @@ void uiWindowSetMargined(uiWindow *w, int margined)
|
||||||
uiprivSetMargined(w->childHolderContainer, w->margined);
|
uiprivSetMargined(w->childHolderContainer, w->margined);
|
||||||
}
|
}
|
||||||
|
|
||||||
uiWindow *uiNewWindow(const char *title, int width, int height, int hasMenubar)
|
uiWindow *uiNewWindow(const char *title, int width, int height, int hasMenubar, int resizable)
|
||||||
{
|
{
|
||||||
uiWindow *w;
|
uiWindow *w;
|
||||||
|
|
||||||
|
@ -275,5 +275,7 @@ uiWindow *uiNewWindow(const char *title, int width, int height, int hasMenubar)
|
||||||
// TODO we really need to clean this up, especially since see uiWindowDestroy() above
|
// TODO we really need to clean this up, especially since see uiWindowDestroy() above
|
||||||
g_object_ref(w->widget);
|
g_object_ref(w->widget);
|
||||||
|
|
||||||
|
gtk_window_set_resizable(w->window, resizable?TRUE:FALSE);
|
||||||
|
|
||||||
return w;
|
return w;
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,9 +14,9 @@
|
||||||
// - when a dialog is active, tab navigation in other windows stops working
|
// - when a dialog is active, tab navigation in other windows stops working
|
||||||
// - when adding uiOpenFolder(), use IFileDialog as well - https://msdn.microsoft.com/en-us/library/windows/desktop/bb762115%28v=vs.85%29.aspx
|
// - when adding uiOpenFolder(), use IFileDialog as well - https://msdn.microsoft.com/en-us/library/windows/desktop/bb762115%28v=vs.85%29.aspx
|
||||||
|
|
||||||
#define windowHWND(w) ((HWND) uiControlHandle(uiControl(w)))
|
#define windowHWND(w) (w ? (HWND) uiControlHandle(uiControl(w)) : NULL)
|
||||||
|
|
||||||
char *commonItemDialog(HWND parent, REFCLSID clsid, REFIID iid, FILEOPENDIALOGOPTIONS optsadd)
|
char *commonItemDialog(HWND parent, REFCLSID clsid, REFIID iid, char* filter, FILEOPENDIALOGOPTIONS optsadd)
|
||||||
{
|
{
|
||||||
IFileDialog *d = NULL;
|
IFileDialog *d = NULL;
|
||||||
FILEOPENDIALOGOPTIONS opts;
|
FILEOPENDIALOGOPTIONS opts;
|
||||||
|
@ -25,6 +25,13 @@ char *commonItemDialog(HWND parent, REFCLSID clsid, REFIID iid, FILEOPENDIALOGOP
|
||||||
char *name = NULL;
|
char *name = NULL;
|
||||||
HRESULT hr;
|
HRESULT hr;
|
||||||
|
|
||||||
|
COMDLG_FILTERSPEC filterspec[8];
|
||||||
|
wchar_t _filter[256];
|
||||||
|
wchar_t* fp = &_filter[0];
|
||||||
|
wchar_t* fname;
|
||||||
|
int i;
|
||||||
|
int s = 0;
|
||||||
|
|
||||||
hr = CoCreateInstance(clsid,
|
hr = CoCreateInstance(clsid,
|
||||||
NULL, CLSCTX_INPROC_SERVER,
|
NULL, CLSCTX_INPROC_SERVER,
|
||||||
iid, (LPVOID *) (&d));
|
iid, (LPVOID *) (&d));
|
||||||
|
@ -46,6 +53,26 @@ char *commonItemDialog(HWND parent, REFCLSID clsid, REFIID iid, FILEOPENDIALOGOP
|
||||||
logHRESULT(L"error setting options", hr);
|
logHRESULT(L"error setting options", hr);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (i = s = 0; i < 255; i++) {
|
||||||
|
if (filter[i] == '|' || filter[i] == '\0') {
|
||||||
|
_filter[i] = '\0';
|
||||||
|
if (s & 1) {
|
||||||
|
filterspec[s>>1].pszName = fname;
|
||||||
|
filterspec[s>>1].pszSpec = fp;
|
||||||
|
} else {
|
||||||
|
fname = fp;
|
||||||
|
}
|
||||||
|
fp = &_filter[i + 1];
|
||||||
|
s++;
|
||||||
|
if (s >= 8) break;
|
||||||
|
if (filter[i] == '\0') break;
|
||||||
|
} else {
|
||||||
|
_filter[i] = filter[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
d->SetFileTypes(s >> 1, filterspec);
|
||||||
|
|
||||||
hr = d->Show(parent);
|
hr = d->Show(parent);
|
||||||
if (hr == HRESULT_FROM_WIN32(ERROR_CANCELLED))
|
if (hr == HRESULT_FROM_WIN32(ERROR_CANCELLED))
|
||||||
// cancelled; return NULL like we have ready
|
// cancelled; return NULL like we have ready
|
||||||
|
@ -76,26 +103,28 @@ out:
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *uiOpenFile(uiWindow *parent)
|
char *uiOpenFile(uiWindow *parent, char* filter)
|
||||||
{
|
{
|
||||||
char *res;
|
char *res;
|
||||||
|
|
||||||
disableAllWindowsExcept(parent);
|
disableAllWindowsExcept(parent);
|
||||||
res = commonItemDialog(windowHWND(parent),
|
res = 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);
|
filter,
|
||||||
|
FOS_NOCHANGEDIR | FOS_FORCEFILESYSTEM | FOS_NOVALIDATE | FOS_PATHMUSTEXIST | FOS_FILEMUSTEXIST | FOS_SHAREAWARE | FOS_NOTESTFILECREATE | FOS_FORCESHOWHIDDEN | FOS_DEFAULTNOMINIMODE);
|
||||||
enableAllWindowsExcept(parent);
|
enableAllWindowsExcept(parent);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *uiSaveFile(uiWindow *parent)
|
char *uiSaveFile(uiWindow *parent, char* filter)
|
||||||
{
|
{
|
||||||
char *res;
|
char *res;
|
||||||
|
|
||||||
disableAllWindowsExcept(parent);
|
disableAllWindowsExcept(parent);
|
||||||
res = commonItemDialog(windowHWND(parent),
|
res = commonItemDialog(windowHWND(parent),
|
||||||
CLSID_FileSaveDialog, IID_IFileSaveDialog,
|
CLSID_FileSaveDialog, IID_IFileSaveDialog,
|
||||||
FOS_OVERWRITEPROMPT | FOS_NOCHANGEDIR | FOS_ALLNONSTORAGEITEMS | FOS_NOVALIDATE | FOS_SHAREAWARE | FOS_NOTESTFILECREATE | FOS_NODEREFERENCELINKS | FOS_FORCESHOWHIDDEN | FOS_DEFAULTNOMINIMODE);
|
filter,
|
||||||
|
FOS_OVERWRITEPROMPT | FOS_NOCHANGEDIR | FOS_FORCEFILESYSTEM | FOS_NOVALIDATE | FOS_SHAREAWARE | FOS_NOTESTFILECREATE | FOS_FORCESHOWHIDDEN | FOS_DEFAULTNOMINIMODE);
|
||||||
enableAllWindowsExcept(parent);
|
enableAllWindowsExcept(parent);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
|
@ -452,7 +452,7 @@ static void setClientSize(uiWindow *w, int width, int height, BOOL hasMenubar, D
|
||||||
logLastError(L"error resizing window");
|
logLastError(L"error resizing window");
|
||||||
}
|
}
|
||||||
|
|
||||||
uiWindow *uiNewWindow(const char *title, int width, int height, int hasMenubar)
|
uiWindow *uiNewWindow(const char *title, int width, int height, int hasMenubar, int resizable)
|
||||||
{
|
{
|
||||||
uiWindow *w;
|
uiWindow *w;
|
||||||
WCHAR *wtitle;
|
WCHAR *wtitle;
|
||||||
|
@ -465,8 +465,11 @@ uiWindow *uiNewWindow(const char *title, int width, int height, int hasMenubar)
|
||||||
hasMenubarBOOL = TRUE;
|
hasMenubarBOOL = TRUE;
|
||||||
w->hasMenubar = hasMenubarBOOL;
|
w->hasMenubar = hasMenubarBOOL;
|
||||||
|
|
||||||
#define style WS_OVERLAPPEDWINDOW
|
int style = WS_OVERLAPPEDWINDOW;
|
||||||
#define exstyle 0
|
int exstyle = 0;
|
||||||
|
|
||||||
|
if (!resizable)
|
||||||
|
style &= ~(WS_THICKFRAME | WS_MAXIMIZEBOX);
|
||||||
|
|
||||||
wtitle = toUTF16(title);
|
wtitle = toUTF16(title);
|
||||||
w->hwnd = CreateWindowExW(exstyle,
|
w->hwnd = CreateWindowExW(exstyle,
|
||||||
|
|
Loading…
Reference in New Issue