Filedialog: support lpstrCustomFilter and return nFilterIndex

Wolfgang Schwotzer wolfgang.schwotzer at gmx.net
Wed May 5 09:06:06 CDT 2004


Description: Add lpstrCustomFilter to file extension select box.
   Return current selected file extension and nFilterIndex after closing dialog.
ChangeLog:  support lpstrCustomFilter and return nFilterIndex in FileDialog


-------------- next part --------------
Index: dlls/commdlg/filedlg.c
===================================================================
RCS file: /home/wine/wine/dlls/commdlg/filedlg.c,v
retrieving revision 1.78
diff -u -r1.78 filedlg.c
--- dlls/commdlg/filedlg.c	3 May 2004 20:09:09 -0000	1.78
+++ dlls/commdlg/filedlg.c	4 May 2004 21:12:48 -0000
@@ -32,8 +32,14 @@
  *
  * FIXME: old style hook messages are not implemented (except FILEOKSTRING)
  *
+<<<<<<< filedlg.c
+ * FIXME: if the size of lpstrFile (nMaxFile) is too small the first
+ * two bytes of lpstrFile should contain the needed size
+ *
+=======
  * FIXME: lpstrCustomFilter not handled
  *
+>>>>>>> 1.78
  * FIXME: algorithm for selecting the initial directory is too simple
  *
  * FIXME: add to recent docs
@@ -379,10 +385,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));
@@ -438,8 +444,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)
 {
@@ -1977,6 +1981,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;
 
@@ -2145,10 +2170,32 @@
 
   TRACE("\n");
 
+  int nFilters = 0;	/* number of filters */
+  int nFilterIndexCB;
+
+  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;
 
     for(;;)
@@ -2176,26 +2223,36 @@
       CBSetItemDataPtr(fodInfos->DlgInfos.hwndFileTypeCB, nFilters, lpstrExt);
       nFilters++;
     }
-    /*
-     * Set the current filter to the one specified
-     * in the initialisation structure
-     * FIXME: lpstrCustomFilter not handled at all
-     */
+  }
+
+  /*
+   * Set the current filter to the one specified
+   * in the initialisation structure
+   */
+  if (fodInfos->filter || fodInfos->customfilter)
+  {
+    LPWSTR lpstrFilter;
+
+    /* Check to make sure our index isn't out of bounds. */
+    if ( fodInfos->ofnInfos->nFilterIndex >
+         nFilters - (fodInfos->customfilter == NULL ? 0 : 1) )
+      fodInfos->ofnInfos->nFilterIndex = (fodInfos->customfilter == NULL ? 1 : 0);
 
     /* set default filter index */
     if(fodInfos->ofnInfos->nFilterIndex == 0 && fodInfos->customfilter == NULL)
       fodInfos->ofnInfos->nFilterIndex = 1;
 
-    /* First, check to make sure our index isn't out of bounds. */
-    if ( fodInfos->ofnInfos->nFilterIndex > nFilters )
-      fodInfos->ofnInfos->nFilterIndex = nFilters;
+    /* calculate index of Combo Box item */
+    nFilterIndexCB = fodInfos->ofnInfos->nFilterIndex;
+    if (fodInfos->customfilter == NULL)
+      nFilterIndexCB--;
 
     /* Set the current index selection. */
-    CBSetCurSel(fodInfos->DlgInfos.hwndFileTypeCB, fodInfos->ofnInfos->nFilterIndex-1);
+    CBSetCurSel(fodInfos->DlgInfos.hwndFileTypeCB, nFilterIndexCB);
 
     /* Get the corresponding text string from the combo box. */
     lpstrFilter = (LPWSTR) CBGetItemDataPtr(fodInfos->DlgInfos.hwndFileTypeCB,
-                                             fodInfos->ofnInfos->nFilterIndex-1);
+                                             nFilterIndexCB);
 
     if ((INT)lpstrFilter == CB_ERR)  /* control is empty */
       lpstrFilter = NULL;
@@ -2208,7 +2265,9 @@
       fodInfos->ShellInfos.lpstrCurrentFilter = MemAlloc( len * sizeof(WCHAR) );
       strcpyW(fodInfos->ShellInfos.lpstrCurrentFilter,lpstrFilter);
     }
-  }
+  } else
+      fodInfos->ofnInfos->nFilterIndex = 0;
+
   return NOERROR;
 }
 
@@ -2231,8 +2290,9 @@
       /* Get the current item of the filetype combo box */
       int iItem = CBGetCurSel(fodInfos->DlgInfos.hwndFileTypeCB);
 
-      /* set the current filter index - indexed from 1 */
-      fodInfos->ofnInfos->nFilterIndex = iItem + 1;
+      /* set the current filter index */
+      fodInfos->ofnInfos->nFilterIndex = iItem +
+        (fodInfos->customfilter == NULL ? 1 : 0);
 
       /* Set the current filter with the current selection */
       if(fodInfos->ShellInfos.lpstrCurrentFilter)


More information about the wine-patches mailing list