Extending File Dialog to include unix file paths [4/4]

Michael Lin mlin at corvu.com.au
Thu May 12 23:05:56 CDT 2005


ChangeLog:
- define unix file path file dialog entry point
- hook in unix file path to file dialog

-------------- next part --------------
Index: include/windef.h
===================================================================
RCS file: /home/wine/wine/include/windef.h,v
retrieving revision 1.95
diff -u -r1.95 windef.h
--- include/windef.h	11 Apr 2005 12:50:19 -0000	1.95
+++ include/windef.h	13 May 2005 02:17:14 -0000
@@ -201,6 +201,12 @@
 # define DECL_WINELIB_TYPE_AW(type)  typedef WINELIB_NAME_AW(type) type;
 #endif  /* __WINESRC__ */
 
+#ifdef WINE_UNIX_PATHS
+#define WINELIB_NAME_AWU(func) WINELIB_NAME_AW(UnixFS##func)
+#else
+#define WINELIB_NAME_AWU(func) WINELIB_NAME_AW(func)
+#endif
+
 #include <winnt.h>
 
 /* Polymorphic types */
Index: include/commdlg.h
===================================================================
RCS file: /home/wine/wine/include/commdlg.h,v
retrieving revision 1.45
diff -u -r1.45 commdlg.h
--- include/commdlg.h	18 Apr 2005 10:01:07 -0000	1.45
+++ include/commdlg.h	13 May 2005 02:17:14 -0000
@@ -733,10 +733,14 @@
 #define GetFileTitle WINELIB_NAME_AW(GetFileTitle)
 BOOL  WINAPI GetOpenFileNameA(LPOPENFILENAMEA ofn);
 BOOL  WINAPI GetOpenFileNameW(LPOPENFILENAMEW ofn);
-#define GetOpenFileName WINELIB_NAME_AW(GetOpenFileName)
+BOOL  WINAPI UnixFSGetOpenFileNameA(LPOPENFILENAMEA ofn);
+BOOL  WINAPI UnixFSGetOpenFileNameW(LPOPENFILENAMEW ofn);
+#define GetOpenFileName WINELIB_NAME_AWU(GetOpenFileName)
 BOOL  WINAPI GetSaveFileNameA(LPOPENFILENAMEA ofn);
 BOOL  WINAPI GetSaveFileNameW(LPOPENFILENAMEW ofn);
-#define GetSaveFileName WINELIB_NAME_AW(GetSaveFileName)
+BOOL  WINAPI UnixFSGetSaveFileNameA(LPOPENFILENAMEA ofn);
+BOOL  WINAPI UnixFSGetSaveFileNameW(LPOPENFILENAMEW ofn);
+#define GetSaveFileName WINELIB_NAME_AWU(GetSaveFileName)
 BOOL WINAPI PageSetupDlgA( LPPAGESETUPDLGA );
 BOOL WINAPI PageSetupDlgW( LPPAGESETUPDLGW );
 #define PageSetupDlg WINELIB_NAME_AW(PageSetupDlg)
Index: dlls/commdlg/comdlg32.spec
===================================================================
RCS file: /home/wine/wine/dlls/commdlg/comdlg32.spec,v
retrieving revision 1.21
diff -u -r1.21 comdlg32.spec
--- dlls/commdlg/comdlg32.spec	20 Mar 2003 03:53:15 -0000	1.21
+++ dlls/commdlg/comdlg32.spec	13 May 2005 02:17:08 -0000
@@ -9,8 +9,12 @@
 @ stdcall GetFileTitleW(wstr ptr long)
 @ stdcall GetOpenFileNameA(ptr)
 @ stdcall GetOpenFileNameW(ptr)
+@ stdcall UnixFSGetOpenFileNameA(ptr)
+@ stdcall UnixFSGetOpenFileNameW(ptr)
 @ stdcall GetSaveFileNameA(ptr)
 @ stdcall GetSaveFileNameW(ptr)
+@ stdcall UnixFSGetSaveFileNameA(ptr)
+@ stdcall UnixFSGetSaveFileNameW(ptr)
 @ stub LoadAlterBitmap
 @ stdcall PageSetupDlgA(ptr)
 @ stdcall PageSetupDlgW(ptr)
Index: dlls/commdlg/filedlg.c
===================================================================
RCS file: /home/wine/wine/dlls/commdlg/filedlg.c,v
retrieving revision 1.103
diff -u -r1.103 filedlg.c
--- dlls/commdlg/filedlg.c	9 May 2005 19:33:24 -0000	1.103
+++ dlls/commdlg/filedlg.c	13 May 2005 02:17:08 -0000
@@ -182,10 +182,10 @@
  */
 
 /* Internal functions used by the dialog */
-static LRESULT FILEDLG95_FillControls(HWND hwnd, WPARAM wParam, LPARAM lParam);
-static LRESULT FILEDLG95_OnWMCommand(HWND hwnd, WPARAM wParam, LPARAM lParam);
+static LRESULT FILEDLG95_FillControls(HWND hwnd, WPARAM wParam, LPARAM lParam, BOOL bUnixFS);
+static LRESULT FILEDLG95_OnWMCommand(HWND hwnd, WPARAM wParam, LPARAM lParam, BOOL bUnixFS);
 static LRESULT FILEDLG95_OnWMGetIShellBrowser(HWND hwnd);
-       BOOL    FILEDLG95_OnOpen(HWND hwnd);
+       BOOL    FILEDLG95_OnOpen(HWND hwnd, BOOL bUnixFS);
 static LRESULT FILEDLG95_InitControls(HWND hwnd);
 static void    FILEDLG95_Clean(HWND hwnd);
 
@@ -203,7 +203,7 @@
 static void    FILEDLG95_FILETYPE_Clean(HWND hwnd);
 
 /* Functions used by the Look In combo box */
-static HRESULT FILEDLG95_LOOKIN_Init(HWND hwndCombo);
+static HRESULT FILEDLG95_LOOKIN_Init(HWND hwndCombo, BOOL bUnixFS);
 static LRESULT FILEDLG95_LOOKIN_DrawItem(LPDRAWITEMSTRUCT pDIStruct);
 static BOOL    FILEDLG95_LOOKIN_OnCommand(HWND hwnd, WORD wNotifyCode);
 static int     FILEDLG95_LOOKIN_AddItem(HWND hwnd,LPITEMIDLIST pidl, int iInsertId);
@@ -224,9 +224,11 @@
 static void *MemAlloc(UINT size);
 static void MemFree(void *mem);
 
-BOOL WINAPI GetFileName95(FileOpenDlgInfos *fodInfos);
+BOOL WINAPI GetFileName95(FileOpenDlgInfos *fodInfos, BOOL bUnixFS);
 INT_PTR CALLBACK FileOpenDlgProc95(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
+INT_PTR CALLBACK UnixFSFileOpenDlgProc95(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
 HRESULT SendCustomDlgNotificationMessage(HWND hwndParentDlg, UINT uCode);
+HRESULT FILEDLG95_HandleCommonDialogMessages(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL bUnixFS);
 HRESULT FILEDLG95_HandleCustomDialogMessages(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
 BOOL FILEDLG95_OnOpenMultipleFiles(HWND hwnd, LPWSTR lpstrFileList, UINT nFileCount, UINT sizeUsed);
 static BOOL BrowseSelectedFolder(HWND hwnd);
@@ -241,7 +243,7 @@
  * OUT : TRUE on success
  *       FALSE on cancel, error, close or filename-does-not-fit-in-buffer.
  */
-BOOL WINAPI GetFileName95(FileOpenDlgInfos *fodInfos)
+BOOL WINAPI GetFileName95(FileOpenDlgInfos *fodInfos, BOOL bUnixFS)
 {
 
     LRESULT lRes;
@@ -279,11 +281,18 @@
       fodInfos->HookMsg.sharevistring = RegisterWindowMessageA(SHAREVISTRINGA);
     }
 
-    lRes = DialogBoxIndirectParamA(COMDLG32_hInstance,
+    if (!bUnixFS)
+        lRes = DialogBoxIndirectParamA(COMDLG32_hInstance,
                                   (LPDLGTEMPLATEA) template,
                                   fodInfos->ofnInfos->hwndOwner,
                                   FileOpenDlgProc95,
                                   (LPARAM) fodInfos);
+    else
+        lRes = DialogBoxIndirectParamA(COMDLG32_hInstance,
+                                  (LPDLGTEMPLATEA) template,
+                                  fodInfos->ofnInfos->hwndOwner,
+                                  UnixFSFileOpenDlgProc95,
+                                  (LPARAM) fodInfos);
 
     /* Unable to create the dialog */
     if( lRes == -1)
@@ -300,7 +309,7 @@
  * IN  : The OPENFILENAMEA initialisation structure passed to
  *       GetOpenFileNameA win api function (see filedlg.c)
  */
-BOOL  WINAPI GetFileDialog95A(LPOPENFILENAMEA ofn,UINT iDlgType)
+BOOL  WINAPI GetFileDialog95A(LPOPENFILENAMEA ofn,UINT iDlgType, BOOL bUnixFS)
 {
   BOOL ret;
   FileOpenDlgInfos fodInfos;
@@ -399,11 +408,11 @@
   switch(iDlgType)
   {
     case OPEN_DIALOG :
-      ret = GetFileName95(&fodInfos);
+      ret = GetFileName95(&fodInfos, bUnixFS);
       break;
     case SAVE_DIALOG :
       fodInfos.DlgInfos.dwDlgProp |= FODPROP_SAVEDLG;
-      ret = GetFileName95(&fodInfos);
+      ret = GetFileName95(&fodInfos, bUnixFS);
       break;
     default :
       ret = 0;
@@ -441,7 +450,7 @@
  * Call GetFileName95 with this structure and clean the memory.
  *
  */
-BOOL  WINAPI GetFileDialog95W(LPOPENFILENAMEW ofn,UINT iDlgType)
+BOOL  WINAPI GetFileDialog95W(LPOPENFILENAMEW ofn,UINT iDlgType, BOOL bUnixFS)
 {
   BOOL ret;
   FileOpenDlgInfos fodInfos;
@@ -489,11 +498,11 @@
   switch(iDlgType)
   {
   case OPEN_DIALOG :
-      ret = GetFileName95(&fodInfos);
+      ret = GetFileName95(&fodInfos, bUnixFS);
       break;
   case SAVE_DIALOG :
       fodInfos.DlgInfos.dwDlgProp |= FODPROP_SAVEDLG;
-      ret = GetFileName95(&fodInfos);
+      ret = GetFileName95(&fodInfos, bUnixFS);
       break;
   default :
       ret = 0;
@@ -984,6 +993,26 @@
   TRACE("0x%04x 0x%04x\n", hwnd, uMsg);
 #endif
 
+  return FILEDLG95_HandleCommonDialogMessages(hwnd, uMsg, wParam, lParam, FALSE);
+}
+
+/***********************************************************************
+ *          UnixFSFileOpenDlgProc95
+ *
+ * Unix file sytem file open dialog procedure
+ */
+INT_PTR CALLBACK UnixFSFileOpenDlgProc95(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
+{
+  return FILEDLG95_HandleCommonDialogMessages(hwnd, uMsg, wParam, lParam, TRUE);
+}
+
+/***********************************************************************
+ *       FILEDLG95_HandleCommonDialogMessages   
+ *
+ * File open dialog common message handler
+ */
+HRESULT FILEDLG95_HandleCommonDialogMessages(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL bUnixFS)
+{
   switch(uMsg)
   {
     case WM_INITDIALOG:
@@ -1003,7 +1032,7 @@
              ArrangeCtrlPositions(fodInfos->DlgInfos.hwndCustomDlg, hwnd,
                  (fodInfos->ofnInfos->Flags & (OFN_HIDEREADONLY | OFN_SHOWHELP)) == OFN_HIDEREADONLY);
 
-      	 FILEDLG95_FillControls(hwnd, wParam, lParam);
+      	 FILEDLG95_FillControls(hwnd, wParam, lParam, bUnixFS);
 
          SendCustomDlgNotificationMessage(hwnd,CDN_INITDONE);
          SendCustomDlgNotificationMessage(hwnd,CDN_FOLDERCHANGE);
@@ -1011,7 +1040,7 @@
          return 0;
        }
     case WM_COMMAND:
-      return FILEDLG95_OnWMCommand(hwnd, wParam, lParam);
+      return FILEDLG95_OnWMCommand(hwnd, wParam, lParam, bUnixFS);
     case WM_DRAWITEM:
       {
         switch(((LPDRAWITEMSTRUCT)lParam)->CtlID)
@@ -1408,7 +1437,7 @@
  *
  * WM_INITDIALOG message handler (after hook notification)
  */
-static LRESULT FILEDLG95_FillControls(HWND hwnd, WPARAM wParam, LPARAM lParam)
+static LRESULT FILEDLG95_FillControls(HWND hwnd, WPARAM wParam, LPARAM lParam, BOOL bUnixFS)
 {
   LPITEMIDLIST pidlItemId = NULL;
 
@@ -1431,7 +1460,7 @@
   FILEDLG95_SHELL_Init(hwnd);
 
   /* Initialize the Look In combo box */
-  FILEDLG95_LOOKIN_Init(fodInfos->DlgInfos.hwndLookInCB);
+  FILEDLG95_LOOKIN_Init(fodInfos->DlgInfos.hwndLookInCB, bUnixFS);
 
   /* Initialize the filter combo box */
   FILEDLG95_FILETYPE_Init(hwnd);
@@ -1460,17 +1489,16 @@
  *
  * WM_COMMAND message handler
  */
-static LRESULT FILEDLG95_OnWMCommand(HWND hwnd, WPARAM wParam, LPARAM lParam)
+static LRESULT FILEDLG95_OnWMCommand(HWND hwnd, WPARAM wParam, LPARAM lParam, BOOL bUnixFS)
 {
   WORD wNotifyCode = HIWORD(wParam); /* notification code */
   WORD wID = LOWORD(wParam);         /* item, control, or accelerator identifier */
   FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
-
   switch(wID)
   {
     /* OK button */
   case IDOK:
-    FILEDLG95_OnOpen(hwnd);
+    FILEDLG95_OnOpen(hwnd, bUnixFS);
     break;
     /* Cancel button */
   case IDCANCEL:
@@ -1700,7 +1728,7 @@
   MessageBoxW(hwnd,strMsgText, strMsgTitle, MB_OK | MB_ICONHAND);
 }
 
-BOOL FILEDLG95_OnOpen(HWND hwnd)
+BOOL FILEDLG95_OnOpen(HWND hwnd, BOOL bUnixFS)
 {
   LPWSTR lpstrFileList;
   UINT nFileCount = 0;
@@ -1751,7 +1779,8 @@
       GetCurrentDirectoryW(MAX_PATH, lpstrPathAndFile);
     }
   }
-  PathAddBackslashW(lpstrPathAndFile);
+  if (!PathIsUnixAbsoluteW(lpstrPathAndFile)) 
+    PathAddBackslashW(lpstrPathAndFile);
 
   TRACE("current directory=%s\n", debugstr_w(lpstrPathAndFile));
 
@@ -1762,8 +1791,8 @@
   }
   else
   {
-    /* does the path have a drive letter? */
-    if (PathGetDriveNumberW(lpstrFileList) == -1)
+    /* check for absolute Unix path and check if the path have a drive letter? */
+    if (!PathIsUnixAbsoluteW(lpstrFileList) && PathGetDriveNumberW(lpstrFileList) == -1)
       strcpyW(lpstrPathAndFile+2, lpstrFileList);
     else
       strcpyW(lpstrPathAndFile, lpstrFileList);
@@ -1793,12 +1822,17 @@
   {
     LPWSTR lpszTemp, lpszTemp1;
     LPITEMIDLIST pidl = NULL;
-    static const WCHAR szwInvalid[] = { '/',':','<','>','|', 0};
-
+    static WCHAR szwInvalid[] = {':','<','>','|', '/', 0};
+    if (bUnixFS)
+      szwInvalid[4] = 0;
+    
     /* check for invalid chars */
     if((strpbrkW(lpstrPathAndFile+3, szwInvalid) != NULL) && !(fodInfos->ofnInfos->Flags & OFN_NOVALIDATE))
     {
-      FILEDLG95_OnOpenMessage(hwnd, IDS_INVALID_FILENAME_TITLE, IDS_INVALID_FILENAME);
+      if (!bUnixFS)
+        FILEDLG95_OnOpenMessage(hwnd, IDS_INVALID_FILENAME_TITLE, IDS_INVALID_FILENAME);
+      else
+        FILEDLG95_OnOpenMessage(hwnd, IDS_INVALID_FILENAME_TITLE, IDS_INVALID_UNIX_FILENAME);
       ret = FALSE;
       goto ret;
     }
@@ -2465,11 +2499,14 @@
  *
  * Initialisation of the look in combo box
  */
-static HRESULT FILEDLG95_LOOKIN_Init(HWND hwndCombo)
+static HRESULT FILEDLG95_LOOKIN_Init(HWND hwndCombo, BOOL bUnixFS)
 {
   IShellFolder	*psfRoot, *psfDrives;
   IEnumIDList	*lpeRoot, *lpeDrives;
-  LPITEMIDLIST	pidlDrives, pidlTmp, pidlTmp1, pidlAbsTmp;
+  LPITEMIDLIST	pidlDrives, pidlTmp, pidlTmp1, pidlAbsTmp, pidlUnixRoot;
+  static WCHAR wszUnixRootDisplayName[] = 
+        { ':',':','{','C','C','7','0','2','E','B','2','-','7','D','C','5','-','1','1','D','9','-',
+          'C','6','8','7','-','0','0','0','4','2','3','8','A','0','1','C','D','}', 0 };
 
   LookInInfos *liInfos = MemAlloc(sizeof(LookInInfos));
 
@@ -2528,6 +2565,15 @@
       }
       IEnumIDList_Release(lpeRoot);
     }
+    if (bUnixFS)
+    {
+      if (SUCCEEDED(psfRoot->lpVtbl->ParseDisplayName(psfRoot, NULL, NULL, wszUnixRootDisplayName, NULL, 
+                                                    &pidlUnixRoot, NULL)))
+      {
+        FILEDLG95_LOOKIN_AddItem(hwndCombo, pidlUnixRoot,LISTEND);
+        COMDLG32_SHFree(pidlUnixRoot);
+      }
+    }
     IShellFolder_Release(psfRoot);
   }
 
@@ -3726,7 +3772,7 @@
     if (win16look)
         return GetFileName31A(ofn, OPEN_DIALOG);
     else
-        return GetFileDialog95A(ofn, OPEN_DIALOG);
+        return GetFileDialog95A(ofn, OPEN_DIALOG, FALSE);
 }
 
 /***********************************************************************
@@ -3750,9 +3796,60 @@
     if (win16look)
         return GetFileName31W(ofn, OPEN_DIALOG);
     else
-        return GetFileDialog95W(ofn, OPEN_DIALOG);
+        return GetFileDialog95W(ofn, OPEN_DIALOG, FALSE);
 }
 
+/***********************************************************************
+ *            UnixFSGetOpenFileNameA (COMDLG32.@)
+ *
+ * Creates a dialog box for the user to select a file to open in unix
+ * file system.
+ *
+ * RETURNS
+ *    TRUE on success: user enters a valid file
+ *    FALSE on cancel, error, close or filename-does-not-fit-in-buffer.
+ *
+ */
+BOOL  WINAPI UnixFSGetOpenFileNameA(LPOPENFILENAMEA ofn)
+{
+    BOOL win16look = FALSE;
+
+    /* OFN_FILEMUSTEXIST implies OFN_PATHMUSTEXIST */
+    if (ofn->Flags & OFN_FILEMUSTEXIST)
+        ofn->Flags |= OFN_PATHMUSTEXIST;
+
+    if (ofn->Flags & (OFN_ALLOWMULTISELECT|OFN_ENABLEHOOK|OFN_ENABLETEMPLATE))
+        win16look = (ofn->Flags & OFN_EXPLORER) ? FALSE : TRUE;
+
+    if (win16look)
+        return GetFileName31A(ofn, OPEN_DIALOG);
+    else
+        return GetFileDialog95A(ofn, OPEN_DIALOG, TRUE);
+}
+
+/***********************************************************************
+ *            UnixFSGetOpenFileNameW (COMDLG32.@)
+ *
+ * Creates a dialog box for the user to select a file to open in unix
+ * file system.
+ * 
+ * RETURNS
+ *    TRUE on success: user enters a valid file
+ *    FALSE on cancel, error, close or filename-does-not-fit-in-buffer.
+ *
+ */
+BOOL  WINAPI UnixFSGetOpenFileNameW(LPOPENFILENAMEW ofn)
+{
+    BOOL win16look = FALSE;
+
+    if (ofn->Flags & (OFN_ALLOWMULTISELECT|OFN_ENABLEHOOK|OFN_ENABLETEMPLATE))
+        win16look = (ofn->Flags & OFN_EXPLORER) ? FALSE : TRUE;
+
+    if (win16look)
+        return GetFileName31W(ofn, OPEN_DIALOG);
+    else
+        return GetFileDialog95W(ofn, OPEN_DIALOG, TRUE);
+}
 
 /***********************************************************************
  *            GetSaveFileNameA  (COMDLG32.@)
@@ -3775,7 +3872,7 @@
     if (win16look)
         return GetFileName31A(ofn, SAVE_DIALOG);
     else
-        return GetFileDialog95A(ofn, SAVE_DIALOG);
+        return GetFileDialog95A(ofn, SAVE_DIALOG, FALSE);
 }
 
 /***********************************************************************
@@ -3799,5 +3896,53 @@
     if (win16look)
         return GetFileName31W(ofn, SAVE_DIALOG);
     else
-        return GetFileDialog95W(ofn, SAVE_DIALOG);
+        return GetFileDialog95W(ofn, SAVE_DIALOG, FALSE);
+}
+
+/***********************************************************************
+ *            UnixFSGetSaveFileNameA  (COMDLG32.@)
+ *
+ * Creates a dialog box for the user to select a file to save.
+ *
+ * RETURNS
+ *    TRUE on success: user enters a valid file
+ *    FALSE on cancel, error, close or filename-does-not-fit-in-buffer.
+ *
+ */
+BOOL WINAPI UnixFSGetSaveFileNameA(
+	LPOPENFILENAMEA ofn) /* [in/out] address of init structure */
+{
+    BOOL win16look = FALSE;
+
+    if (ofn->Flags & (OFN_ALLOWMULTISELECT|OFN_ENABLEHOOK|OFN_ENABLETEMPLATE))
+        win16look = (ofn->Flags & OFN_EXPLORER) ? FALSE : TRUE;
+
+    if (win16look)
+        return GetFileName31A(ofn, SAVE_DIALOG);
+    else
+        return GetFileDialog95A(ofn, SAVE_DIALOG, TRUE);
+}
+
+/***********************************************************************
+ *            UnixFSGetSaveFileNameW  (COMDLG32.@)
+ *
+ * Creates a dialog box for the user to select a file to save.
+ *
+ * RETURNS
+ *    TRUE on success: user enters a valid file
+ *    FALSE on cancel, error, close or filename-does-not-fit-in-buffer.
+ *
+ */
+BOOL WINAPI UnixFSGetSaveFileNameW(
+	LPOPENFILENAMEW ofn) /* [in/out] address of init structure */
+{
+    BOOL win16look = FALSE;
+
+    if (ofn->Flags & (OFN_ALLOWMULTISELECT|OFN_ENABLEHOOK|OFN_ENABLETEMPLATE))
+        win16look = (ofn->Flags & OFN_EXPLORER) ? FALSE : TRUE;
+
+    if (win16look)
+        return GetFileName31W(ofn, SAVE_DIALOG);
+    else
+        return GetFileDialog95W(ofn, SAVE_DIALOG, TRUE);
 }


More information about the wine-patches mailing list