}
};
-#ifdef WIN32
-
-class Win32Filters
-{
- const FileTypeList& m_types;
- Array<char> m_filters;
-public:
- Win32Filters(const FileTypeList& typeList) : m_types(typeList)
- {
- std::size_t len = 0;
- for(FileTypeList::const_iterator i = m_types.begin(); i != m_types.end(); ++i)
- {
- len = len + strlen((*i).m_name.c_str()) + strlen((*i).m_pattern.c_str()) * 2 + 5;
- }
- m_filters.resize(len + 1); // length + null char
- char *w = m_filters.data();
- for(FileTypeList::const_iterator i = m_types.begin(); i != m_types.end(); ++i)
- {
- for(const char *r = (*i).m_name.c_str(); *r!='\0'; r++, w++)
- {
- *w = *r;
- }
- *w++ = ' ';
- *w++ = '(';
- for(const char *r = (*i).m_pattern.c_str(); *r!='\0'; r++, w++)
- {
- *w = *r;
- }
- *w++ = ')';
- *w++ = '\0';
- for(const char *r = (*i).m_pattern.c_str(); *r!='\0'; r++, w++)
- {
- *w = (*r == ',') ? ';' : *r;
- }
- *w++ = '\0';
- }
- m_filters[len] = '\0';
- }
- filetype_pair_t getType(const char *filter) const
- {
- for(FileTypeList::const_iterator i = m_types.begin(); i != m_types.end(); ++i)
- {
- if(string_equal((*i).m_pattern.c_str(), filter))
- {
- return filetype_pair_t((*i).m_moduleName.c_str(), filetype_t((*i).m_name.c_str(), (*i).m_pattern.c_str()));
- }
- }
- return filetype_pair_t();
- }
- const char* getFilters() const
- {
- return m_filters.data();
- }
-};
-
-#define WIN32_LEAN_AND_MEAN
-#include <gdk/gdkwin32.h>
-#include <commdlg.h>
-
-static char szFile[MAX_PATH]; /* filename string */
-
-
-#define FILEDLG_CUSTOM_FILTER_LENGTH 64
-// to be used with the advanced file selector
-
-const char* file_dialog_show_win32(GtkWidget* parent, bool open, const char* title, const char* path, const char* pattern)
-{
- const char* r;
- char* w;
- filetype_t type;
- FileTypeList typelist;
-
- if(pattern == 0)
- {
- pattern = "*";
- }
-
- GlobalFiletypes().getTypeList(pattern, &typelist);
-
- Win32Filters filters(typelist);
-
- // win32 dialog stores the selected "save as type" extension in the second null-terminated string
- char customfilter[FILEDLG_CUSTOM_FILTER_LENGTH];
-
- static OPENFILENAME ofn; /* common dialog box structure */
- static char szDirName[MAX_PATH]; /* directory string */
- static char szFile[MAX_PATH]; /* filename string */
- static char szFileTitle[MAX_PATH]; /* file title string */
- static int i, cbString; /* integer count variables */
- static HANDLE hf; /* file handle */
-
- // do that the native way
- /* Place the terminating null character in the szFile. */
- szFile[0] = '\0';
- customfilter[0] = customfilter[1] = customfilter[2] = '\0';
-
- /* Set the members of the OPENFILENAME structure. */
- ofn.lStructSize = sizeof(OPENFILENAME);
- ofn.hwndOwner = (HWND)GDK_WINDOW_HWND(parent->window);
- ofn.nFilterIndex = 0;
- ofn.lpstrFilter = filters.getFilters();
- ofn.lpstrCustomFilter = customfilter;
- ofn.nMaxCustFilter = sizeof(customfilter);
- ofn.lpstrFile = szFile;
- ofn.nMaxFile = sizeof(szFile);
- ofn.lpstrFileTitle = 0; // we don't need to get the name of the file
- if(path)
- {
- // szDirName: Radiant uses unix convention for paths internally
- // Win32 (of course) and Gtk (who would have thought) expect the '\\' convention
- // copy path, replacing dir separators as appropriate
- for(r=path, w=szDirName; *r!='\0'; r++)
- *w++ = (*r=='/') ? '\\' : *r;
- // terminate string
- *w = '\0';
- ofn.lpstrInitialDir = szDirName;
- }
- else ofn.lpstrInitialDir = 0;
- ofn.lpstrTitle = title;
- ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
-
- /* Display the Open dialog box. */
- // it's open or close depending on 'open' parameter
- if (open)
- {
- if (!GetOpenFileName(&ofn))
- return 0; // canceled
- }
- else
- {
- if (!GetSaveFileName(&ofn))
- return 0; // canceled
- }
-
- if(!string_equal(pattern, "*"))
- {
- type = filters.getType(customfilter+1).m_type;
- }
-
- // don't return an empty filename
- if(szFile[0] == '\0') return 0;
-
- // convert back to unix format
- for(w=szFile; *w!='\0'; w++)
- {
- if(*w=='\\')
- {
- *w = '/';
- }
- }
- // when saving, force an extension depending on filetype
- /* \todo SPoG - file_dialog should return filetype information separately.. not force file extension.. */
- if(!open && !string_equal(pattern, "*"))
- {
- // last ext separator
- const char* extension = path_get_extension(szFile);
- // no extension
- if(string_empty(extension))
- {
- strcat(szFile, type.pattern+1);
- }
- else
- {
- strcpy(szFile + (extension - szFile), type.pattern+2);
- }
- }
-
- return szFile;
-}
-
-#endif
-
class GTKMasks
{
return filename;
}
-
-#ifdef WIN32
-bool g_FileChooser_nativeGUI = true;
-#endif
-
const char* file_dialog(GtkWidget* parent, bool open, const char* title, const char* path, const char* pattern)
{
for(;;)
{
- const char* file =
-#ifdef WIN32
- g_FileChooser_nativeGUI
- ? file_dialog_show_win32(parent, open, title, path, pattern) :
-#endif
- file_dialog_show(parent, open, title, path, pattern);
+ const char* file = file_dialog_show(parent, open, title, path, pattern);
if(open
|| file == 0