From eed0eb6a476d54ce19aeff137984aa981d9e3976 Mon Sep 17 00:00:00 2001 From: Pixel Date: Tue, 15 Jun 2010 00:59:57 -0700 Subject: Upgrading to iup 3.1 --- iup/src/win/iupwin_filedlg.c | 72 +++++++++++++++++++++++++++++++++----------- 1 file changed, 55 insertions(+), 17 deletions(-) (limited to 'iup/src/win/iupwin_filedlg.c') diff --git a/iup/src/win/iupwin_filedlg.c b/iup/src/win/iupwin_filedlg.c index da66b4b..26994e5 100755 --- a/iup/src/win/iupwin_filedlg.c +++ b/iup/src/win/iupwin_filedlg.c @@ -63,7 +63,7 @@ static INT CALLBACK winFileDlgBrowseCallback(HWND hWnd, UINT uMsg, LPARAM lParam } else if (uMsg == BFFM_SELCHANGED) { - char* buffer = iupStrGetMemory(MAX_FILENAME_SIZE); + char buffer[MAX_FILENAME_SIZE]; ITEMIDLIST* selecteditem = (ITEMIDLIST*)lParam; buffer[0] = 0; SHGetPathFromIDList(selecteditem, buffer); @@ -90,7 +90,7 @@ static void winFileDlgGetFolder(Ihandle *ih) browseinfo.pszDisplayName = buffer; browseinfo.lpfn = winFileDlgBrowseCallback; browseinfo.lParam = (LPARAM)ih; - browseinfo.ulFlags = BIF_NEWDIALOGSTYLE; + browseinfo.ulFlags = IupGetGlobal("_IUPWIN_COINIT_MULTITHREADED")? 0: BIF_NEWDIALOGSTYLE; browseinfo.hwndOwner = parent; selecteditem = SHBrowseForFolder(&browseinfo); @@ -112,6 +112,37 @@ static void winFileDlgGetFolder(Ihandle *ih) /************************************************************************************************/ +static int winFileDlgGetSelectedFile(Ihandle* ih, HWND hWnd, char* filename) +{ + int ret = CommDlg_OpenSave_GetFilePath(GetParent(hWnd), filename, MAX_FILENAME_SIZE); + if (ret < 0) + return 0; + + if (iupAttribGetBoolean(ih, "MULTIPLEFILES")) + { + /* check if there are more than 1 files and return only the first one */ + int found = 0; + while(*filename != 0) + { + if (*filename == '"') + { + if (!found) + found = 1; + else + { + *(filename-1) = 0; + return 1; + } + } + if (found) + *filename = *(filename+1); + filename++; + } + } + + return 1; +} + static UINT_PTR CALLBACK winFileDlgSimpleHook(HWND hWnd, UINT uiMsg, WPARAM wParam, LPARAM lParam) { (void)wParam; @@ -152,16 +183,15 @@ static UINT_PTR CALLBACK winFileDlgSimpleHook(HWND hWnd, UINT uiMsg, WPARAM wPar IFnss cb = (IFnss)IupGetCallback(ih, "FILE_CB"); if (cb) { - char* filename = iupStrGetMemory(MAX_FILENAME_SIZE); - if (CommDlg_OpenSave_GetFilePath(GetParent(hWnd), filename, MAX_FILENAME_SIZE) <= MAX_FILENAME_SIZE) + char filename[MAX_FILENAME_SIZE]; + if (winFileDlgGetSelectedFile(ih, hWnd, filename)) { int ret; char* file_msg; if (!iupdrvIsFile(filename)) - break; - - if (pofn->hdr.code == CDN_FILEOK) + file_msg = "OTHER"; + else if (pofn->hdr.code == CDN_FILEOK) file_msg = "OK"; else file_msg = "SELECT"; @@ -267,9 +297,9 @@ static UINT_PTR CALLBACK winFileDlgPreviewHook(HWND hWnd, UINT uiMsg, WPARAM wPa LPDRAWITEMSTRUCT lpDrawItem = (LPDRAWITEMSTRUCT)lParam; Ihandle* ih = (Ihandle*)GetWindowLongPtr(hWnd, DWLP_USER); IFnss cb = (IFnss)IupGetCallback(ih, "FILE_CB"); - char* filename = iupStrGetMemory(MAX_FILENAME_SIZE); + char filename[MAX_FILENAME_SIZE]; iupAttribSetStr(ih, "PREVIEWDC", (char*)lpDrawItem->hDC); - if (CommDlg_OpenSave_GetFilePath(GetParent(hWnd), filename, MAX_FILENAME_SIZE) <= MAX_FILENAME_SIZE) + if (winFileDlgGetSelectedFile(ih, hWnd, filename)) { if (iupdrvIsFile(filename)) cb(ih, filename, "PAINT"); @@ -324,16 +354,15 @@ static UINT_PTR CALLBACK winFileDlgPreviewHook(HWND hWnd, UINT uiMsg, WPARAM wPa case CDN_SELCHANGE: { HWND hWndPreview = GetDlgItem(hWnd, IUP_PREVIEWCANVAS); - char* filename = iupStrGetMemory(MAX_FILENAME_SIZE); - if (CommDlg_OpenSave_GetFilePath(GetParent(hWnd), filename, MAX_FILENAME_SIZE) <= MAX_FILENAME_SIZE) + char filename[MAX_FILENAME_SIZE]; + if (winFileDlgGetSelectedFile(ih, hWnd, filename)) { int ret; char* file_msg; if (!iupdrvIsFile(filename)) - break; - - if (pofn->hdr.code == CDN_FILEOK) + file_msg = "OTHER"; + else if (pofn->hdr.code == CDN_FILEOK) file_msg = "OK"; else file_msg = "SELECT"; @@ -520,9 +549,14 @@ static int winFileDlgPopup(Ihandle *ih, int x, int y) if (iupAttribGetBoolean(ih, "MULTIPLEFILES")) { int i = 0; - + + char* dir = iupStrFileGetPath(openfilename.lpstrFile); /* the first part is the directory already */ + iupAttribStoreStr(ih, "DIRECTORY", dir); + free(dir); + /* If there is more than one file, replace terminator by the separator */ - if (openfilename.lpstrFile && openfilename.lpstrFile[openfilename.nFileOffset-1] == 0 && openfilename.nFileOffset>0) + if (openfilename.lpstrFile[openfilename.nFileOffset-1] == 0 && + openfilename.nFileOffset>0) { while (openfilename.lpstrFile[i] != 0 || openfilename.lpstrFile[i+1] != 0) { @@ -534,12 +568,16 @@ static int winFileDlgPopup(Ihandle *ih, int x, int y) } iupAttribSetStr(ih, "STATUS", "0"); - iupAttribSetStr(ih, "FILEEXIST", NULL); + iupAttribSetStr(ih, "FILEEXIST", "YES"); } else { if (iupdrvIsFile(openfilename.lpstrFile)) /* check if file exists */ { + char* dir = iupStrFileGetPath(openfilename.lpstrFile); + iupAttribStoreStr(ih, "DIRECTORY", dir); + free(dir); + iupAttribSetStr(ih, "FILEEXIST", "YES"); iupAttribSetStr(ih, "STATUS", "0"); } -- cgit v1.2.3