# HG changeset patch # User mhessling@81767d24-ef19-dc11-ae90-00e081727c95 # Date 1055814358 0 # Node ID 787cc1e27897204b0ed90c7fd339aa511d367f9e # Parent e81af9e60697a018f790f150b9f2682b71620d00 Add support for directory browsing under Win32. DW_DIRECTORY_OPEN can be passed as a flag to dw_file_open() and under Windows a folder select dialog is displayed. No change for GTK; don't know about OS/2 or MAC. diff -r e81af9e60697 -r 787cc1e27897 dw.h --- a/dw.h Mon Jun 09 08:14:59 2003 +0000 +++ b/dw.h Tue Jun 17 01:45:58 2003 +0000 @@ -797,8 +797,9 @@ #define DW_EXEC_CON 0 #define DW_EXEC_GUI 1 -#define DW_FILE_OPEN 0 -#define DW_FILE_SAVE 1 +#define DW_FILE_OPEN 0 +#define DW_FILE_SAVE 1 +#define DW_DIRECTORY_OPEN 2 #define DW_HORZ 0 #define DW_VERT 1 diff -r e81af9e60697 -r 787cc1e27897 gtk/dw.c --- a/gtk/dw.c Mon Jun 09 08:14:59 2003 +0000 +++ b/gtk/dw.c Tue Jun 17 01:45:58 2003 +0000 @@ -7592,7 +7592,7 @@ * title: Title bar text for dialog. * defpath: The default path of the open dialog. * ext: Default file extention. - * flags: DW_FILE_OPEN or DW_FILE_SAVE. + * flags: DW_FILE_OPEN or DW_FILE_SAVE or DW_DIRECTORY_OPEN * Returns: * NULL on error. A malloced buffer containing * the file path on success. diff -r e81af9e60697 -r 787cc1e27897 win/dw.c --- a/win/dw.c Mon Jun 09 08:14:59 2003 +0000 +++ b/win/dw.c Tue Jun 17 01:45:58 2003 +0000 @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -4226,6 +4227,7 @@ SetWindowLongPtr(tmp, GWLP_USERDATA, (LONG_PTR)cinfo); dw_window_set_font(tmp, DefaultFont); + SetWindowText(tmp, text); return tmp; } @@ -7699,7 +7701,7 @@ * title: Title bar text for dialog. * defpath: The default path of the open dialog. * ext: Default file extention. - * flags: DW_FILE_OPEN or DW_FILE_SAVE. + * flags: DW_FILE_OPEN or DW_FILE_SAVE or DW_DIRECTORY_OPEN. * Returns: * NULL on error. A malloced buffer containing * the file path on success. @@ -7711,32 +7713,66 @@ char filenamebuf[1001] = ""; int rc; - if(ext) - { - strcpy(filenamebuf, "*."); - strcat(filenamebuf, ext); - } - - memset(&of, 0, sizeof(OPENFILENAME)); - - of.lStructSize = sizeof(OPENFILENAME); - of.hwndOwner = HWND_DESKTOP; - of.hInstance = DWInstance; - of.lpstrInitialDir = defpath; - of.lpstrTitle = title; - of.lpstrFile = filenamebuf; - of.nMaxFile = 1000; - of.lpstrDefExt = ext; - of.Flags = 0; - - if(flags & DW_FILE_SAVE) - rc = GetSaveFileName(&of); + BROWSEINFO bi; + TCHAR szDir[MAX_PATH]; + LPITEMIDLIST pidl; + LPMALLOC pMalloc; + + if(flags==DW_DIRECTORY_OPEN) + { + if (SUCCEEDED(SHGetMalloc(&pMalloc))) + { + ZeroMemory(&bi,sizeof(bi)); + bi.hwndOwner = NULL; + bi.pszDisplayName = 0; + bi.pidlRoot = 0; + bi.lpszTitle = title; + bi.ulFlags = BIF_RETURNONLYFSDIRS | BIF_STATUSTEXT; + bi.lpfn = NULL; /*BrowseCallbackProc*/ + + pidl = SHBrowseForFolder(&bi); + if (pidl) + { + if (SHGetPathFromIDList(pidl,szDir)) + { + strcpy(filenamebuf,szDir); + } + + // In C++: pMalloc->Free(pidl); pMalloc->Release(); + pMalloc->lpVtbl->Free(pMalloc,pidl); + pMalloc->lpVtbl->Release(pMalloc); + return strdup(filenamebuf); + } + } + } else - rc = GetOpenFileName(&of); - - if(rc) - return strdup(of.lpstrFile); - + { + if(ext) + { + strcpy(filenamebuf, "*."); + strcat(filenamebuf, ext); + } + + memset(&of, 0, sizeof(OPENFILENAME)); + + of.lStructSize = sizeof(OPENFILENAME); + of.hwndOwner = HWND_DESKTOP; + of.hInstance = DWInstance; + of.lpstrInitialDir = defpath; + of.lpstrTitle = title; + of.lpstrFile = filenamebuf; + of.nMaxFile = 1000; + of.lpstrDefExt = ext; + of.Flags = 0; + + if(flags & DW_FILE_SAVE) + rc = GetSaveFileName(&of); + else + rc = GetOpenFileName(&of); + + if(rc) + return strdup(of.lpstrFile); + } return NULL; }