Filedialog: support lpstrCustomFilter

Wolfgang Schwotzer wolfgang.schwotzer at gmx.net
Sun May 2 11:33:22 CDT 2004


Description: Add lpstrCustomFilter to file extension select box.
   Return current selected file extension after closing dialog.
ChangeLog:  Support lpstrCustomFilter in FileDialog
-------------- next part --------------
Index: dlls/commdlg/filedlg.c
===================================================================
RCS file: /home/wine/wine/dlls/commdlg/filedlg.c,v
retrieving revision 1.77
diff -u -r1.77 filedlg.c
--- dlls/commdlg/filedlg.c	20 Apr 2004 01:12:18 -0000	1.77
+++ dlls/commdlg/filedlg.c	2 May 2004 16:52:54 -0000
@@ -32,8 +32,6 @@
  *
  * FIXME: old style hook messages are not implemented (except FILEOKSTRING)
  *
- * FIXME: lpstrCustomFilter not handled
- *
  * FIXME: if the size of lpstrFile (nMaxFile) is too small the first
  * two bytes of lpstrFile should contain the needed size
  *
@@ -382,10 +380,10 @@
     LPCSTR s;
     int n, len;
 
-    /* filter is a list...  title\0ext\0......\0\0 */
+    /* customfilter contains a pair of strings...  title\0ext\0 */
     s = ofn->lpstrCustomFilter;
-    while (*s) s = s+strlen(s)+1;
-    s++;
+    if (*s) s = s+strlen(s)+1;
+    if (*s) s = s+strlen(s)+1;
     n = s - ofn->lpstrCustomFilter;
     len = MultiByteToWideChar( CP_ACP, 0, ofn->lpstrCustomFilter, n, NULL, 0 );
     customfilter = MemAlloc(len*sizeof(WCHAR));
@@ -441,8 +439,6 @@
  * Copy the OPENFILENAMEW structure in a FileOpenDlgInfos structure.
  * Call GetFileName95 with this structure and clean the memory.
  *
- * FIXME: lpstrCustomFilter has to be converted back
- *
  */
 BOOL  WINAPI GetFileDialog95W(LPOPENFILENAMEW ofn,UINT iDlgType)
 {
@@ -1980,6 +1976,27 @@
             }
 	  }
 
+          /* copy currently selected filter to lpstrCustomFilter */
+          if (fodInfos->ofnInfos->lpstrCustomFilter)
+          {
+            LPOPENFILENAMEA ofn = fodInfos->ofnInfos;
+            int len;
+            char currentFilter[MAX_PATH];
+
+            WideCharToMultiByte(CP_ACP, 0,
+              fodInfos->ShellInfos.lpstrCurrentFilter,
+              -1, currentFilter, MAX_PATH, NULL, NULL);
+            len = 1 + strlen(ofn->lpstrCustomFilter) +
+            strlen(currentFilter);
+            if (len <= ofn->nMaxCustFilter)
+            {
+              LPSTR s = ofn->lpstrCustomFilter;
+              s += strlen(ofn->lpstrCustomFilter)+1;
+              strcpy(s, currentFilter);
+            }
+          }
+
+
           if ( !FILEDLG95_SendFileOK(hwnd, fodInfos) )
 	      goto ret;
 
@@ -2141,9 +2158,31 @@
 
   TRACE("\n");
 
+  int nFilters = 0;	/* number of filters */
+
+  if(fodInfos->customfilter)
+  {
+      /* customfilter has one entry...  title\0ext\0
+       * Set first entry of combo box item with customfilter
+       */
+      LPWSTR  lpstrExt;
+      LPCWSTR lpstrPos = fodInfos->customfilter;
+
+      /* Get the title */
+      lpstrPos += strlenW(fodInfos->customfilter) + 1;
+
+      /* Copy the extensions */
+      if (! *lpstrPos) return E_FAIL;	/* malformed filter */
+      if (!(lpstrExt = MemAlloc((strlenW(lpstrPos)+1)*sizeof(WCHAR)))) return E_FAIL;
+      strcpyW(lpstrExt,lpstrPos);
+
+      /* Add the item at the end of the combo */
+      CBAddStringW(fodInfos->DlgInfos.hwndFileTypeCB, fodInfos->customfilter);
+      CBSetItemDataPtr(fodInfos->DlgInfos.hwndFileTypeCB, nFilters, lpstrExt);
+      nFilters++;
+  }
   if(fodInfos->filter)
   {
-    int nFilters = 0;	/* number of filters */
     LPWSTR lpstrFilter;
     LPCWSTR lpstrPos = fodInfos->filter;
 
@@ -2175,12 +2214,13 @@
     /*
      * Set the current filter to the one specified
      * in the initialisation structure
-     * FIXME: lpstrCustomFilter not handled at all
      */
 
     /* set default filter index */
     if(fodInfos->ofnInfos->nFilterIndex == 0 && fodInfos->customfilter == NULL)
       fodInfos->ofnInfos->nFilterIndex = 1;
+    else if(fodInfos->customfilter != NULL)
+      fodInfos->ofnInfos->nFilterIndex++; /* customfilter is first filter */
 
     /* First, check to make sure our index isn't out of bounds. */
     if ( fodInfos->ofnInfos->nFilterIndex > nFilters )


More information about the wine-patches mailing list