changeset 449:787cc1e27897

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.
author mhessling@81767d24-ef19-dc11-ae90-00e081727c95
date Tue, 17 Jun 2003 01:45:58 +0000
parents e81af9e60697
children f9ba403b15ad
files dw.h gtk/dw.c win/dw.c
diffstat 3 files changed, 66 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- 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
--- 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.
--- 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 <windowsx.h>
 #include <commctrl.h>
 #include <shlwapi.h>
+#include <shlobj.h>
 #include <stdlib.h>
 #include <string.h>
 #include <stdio.h>
@@ -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;
 }