Filedialog: support lpstrCustomFilter and return nFilterIndex
Wolfgang Schwotzer
wolfgang.schwotzer at gmx.net
Fri May 7 10:00:55 CDT 2004
Next try :-) based on filedlg.c 1.79:
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.79
diff -u -r1.79 filedlg.c
--- dlls/commdlg/filedlg.c 5 May 2004 23:49:39 -0000 1.79
+++ dlls/commdlg/filedlg.c 7 May 2004 19:43:54 -0000
@@ -32,8 +32,6 @@
*
* FIXME: old style hook messages are not implemented (except FILEOKSTRING)
*
- * FIXME: lpstrCustomFilter not handled
- *
* FIXME: algorithm for selecting the initial directory is too simple
*
* FIXME: add to recent docs
@@ -379,10 +377,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 +436,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)
{
@@ -1983,6 +1979,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;
@@ -2151,10 +2168,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(;;)
@@ -2182,26 +2221,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;
@@ -2214,7 +2263,9 @@
fodInfos->ShellInfos.lpstrCurrentFilter = MemAlloc( len * sizeof(WCHAR) );
strcpyW(fodInfos->ShellInfos.lpstrCurrentFilter,lpstrFilter);
}
- }
+ } else
+ fodInfos->ofnInfos->nFilterIndex = 0;
+
return NOERROR;
}
@@ -2237,8 +2288,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