? patch.diff
Index: dlls/commdlg/filedlg.c
===================================================================
RCS file: /home/wine/wine/dlls/commdlg/filedlg.c,v
retrieving revision 1.80
diff -u -r1.80 filedlg.c
--- dlls/commdlg/filedlg.c	12 May 2004 00:12:04 -0000	1.80
+++ dlls/commdlg/filedlg.c	16 Jun 2004 20:08:13 -0000
@@ -1869,35 +1869,51 @@
     case ONOPEN_OPEN:   /* fill in the return struct and close the dialog */
       TRACE("ONOPEN_OPEN %s\n", debugstr_w(lpstrPathAndFile));
       {
+        WCHAR *ext = NULL;
+
         /* update READONLY check box flag */
 	if ((SendMessageA(GetDlgItem(hwnd,IDC_OPENREADONLY),BM_GETCHECK,0,0) & 0x03) == BST_CHECKED)
 	  fodInfos->ofnInfos->Flags |= OFN_READONLY;
 	else
 	  fodInfos->ofnInfos->Flags &= ~OFN_READONLY;
 
-	/* add default extension */
-	if (fodInfos->defext)
-	{
-	  WCHAR *ext = PathFindExtensionW(lpstrPathAndFile);
-	  
-	  if (! *ext)
-	  {
-	    /* only add "." in case a default extension does exist */
-	    if (*fodInfos->defext != '\0')
-	    {
-                static const WCHAR szwDot[] = {'.',0};
-		int PathLength = strlenW(lpstrPathAndFile);
-
-	        strcatW(lpstrPathAndFile, szwDot);
-	        strcatW(lpstrPathAndFile, fodInfos->defext);
-
-		/* In Open dialog: if file does not exist try without extension */
-		if (!(fodInfos->DlgInfos.dwDlgProp & FODPROP_SAVEDLG)
-		    && !PathFileExistsW(lpstrPathAndFile))
-		  lpstrPathAndFile[PathLength] = '\0';
-	    }
-	  }
+        /* Attach the file extension with file name*/
+        ext = PathFindExtensionW(lpstrPathAndFile);
+        if (! *ext)
+        {
+            /* if no extension is specified with file name, then */
+            /* attach the extension from file filter or default one */
+            
+            WCHAR *filterExt = NULL;
+            LPWSTR lpstrFilter = NULL;
+            static const WCHAR szwDot[] = {'.',0};
+            int PathLength = strlenW(lpstrPathAndFile);
+
+            /* Attach the dot*/
+            strcatW(lpstrPathAndFile, szwDot);
+    
+            /*Get the file extension from file type filter*/
+            lpstrFilter = (LPWSTR) CBGetItemDataPtr(fodInfos->DlgInfos.hwndFileTypeCB,
+                                             fodInfos->ofnInfos->nFilterIndex-1);
 
+            if ((INT)lpstrFilter != CB_ERR)  /* control is not empty */
+            {
+                CharLowerW(lpstrFilter); /* lowercase */
+                filterExt = PathFindExtensionW(lpstrFilter);
+            }
+            
+            if ( *filterExt ) /* attach the file extension from file type filter*/
+                strcatW(lpstrPathAndFile, filterExt + 1);
+            else if ( fodInfos->defext ) /* attach the default file extension*/
+                strcatW(lpstrPathAndFile, fodInfos->defext);
+
+            /* In Open dialog: if file does not exist try without extension */
+            if (!(fodInfos->DlgInfos.dwDlgProp & FODPROP_SAVEDLG) && !PathFileExistsW(lpstrPathAndFile))
+                  lpstrPathAndFile[PathLength] = '\0';
+        }
+
+	if (fodInfos->defext) /* add default extension */
+	{
 	  /* Set/clear the output OFN_EXTENSIONDIFFERENT flag */
 	  if (*ext)
 	    ext++;
