[PATCH 3/5] comdlg32: ::SetFileTypeIndex and ::GetFileTypeIndex uses a one-based index.
David Hedberg
david.hedberg at gmail.com
Sun Aug 31 08:08:03 CDT 2014
---
dlls/comdlg32/itemdlg.c | 12 +++++++-----
dlls/comdlg32/tests/itemdlg.c | 22 +++++++++++++++++-----
2 files changed, 24 insertions(+), 10 deletions(-)
diff --git a/dlls/comdlg32/itemdlg.c b/dlls/comdlg32/itemdlg.c
index c3197ab..a6b45f8 100644
--- a/dlls/comdlg32/itemdlg.c
+++ b/dlls/comdlg32/itemdlg.c
@@ -1880,10 +1880,9 @@ static HRESULT WINAPI IFileDialog2_fnSetFileTypeIndex(IFileDialog2 *iface, UINT
if(!This->filterspecs)
return E_FAIL;
- if(iFileType >= This->filterspec_count)
- This->filetypeindex = This->filterspec_count - 1;
- else
- This->filetypeindex = iFileType;
+ iFileType = max(iFileType, 1);
+ iFileType = min(iFileType, This->filterspec_count);
+ This->filetypeindex = iFileType-1;
return S_OK;
}
@@ -1896,7 +1895,10 @@ static HRESULT WINAPI IFileDialog2_fnGetFileTypeIndex(IFileDialog2 *iface, UINT
if(!piFileType)
return E_INVALIDARG;
- *piFileType = This->filetypeindex;
+ if(This->filterspec_count == 0)
+ *piFileType = 0;
+ else
+ *piFileType = This->filetypeindex + 1;
return S_OK;
}
diff --git a/dlls/comdlg32/tests/itemdlg.c b/dlls/comdlg32/tests/itemdlg.c
index 1c03e56..8147111 100644
--- a/dlls/comdlg32/tests/itemdlg.c
+++ b/dlls/comdlg32/tests/itemdlg.c
@@ -643,8 +643,6 @@ static void test_basics(void)
hr = IFileOpenDialog_SetFileTypes(pfod, 0, filterspec);
ok(hr == S_OK, "got 0x%08x.\n", hr);
- hr = IFileOpenDialog_SetFileTypeIndex(pfod, -1);
- ok(hr == E_FAIL, "got 0x%08x.\n", hr);
hr = IFileOpenDialog_SetFileTypeIndex(pfod, 0);
ok(hr == E_FAIL, "got 0x%08x.\n", hr);
hr = IFileOpenDialog_SetFileTypeIndex(pfod, 1);
@@ -655,25 +653,39 @@ static void test_basics(void)
ok(hr == E_UNEXPECTED, "got 0x%08x.\n", hr);
hr = IFileOpenDialog_SetFileTypeIndex(pfod, 0);
ok(hr == S_OK, "got 0x%08x.\n", hr);
+ hr = IFileOpenDialog_GetFileTypeIndex(pfod, &filetype);
+ ok(hr == S_OK, "got 0x%08x.\n", hr);
+ ok(filetype == 1, "got %d\n", filetype);
hr = IFileOpenDialog_SetFileTypeIndex(pfod, 100);
ok(hr == S_OK, "got 0x%08x.\n", hr);
+ hr = IFileOpenDialog_GetFileTypeIndex(pfod, &filetype);
+ ok(hr == S_OK, "got 0x%08x.\n", hr);
+ ok(filetype == 1, "got %d\n", filetype);
hr = IFileOpenDialog_SetFileTypes(pfod, 1, filterspec);
ok(hr == E_UNEXPECTED, "got 0x%08x.\n", hr);
hr = IFileOpenDialog_SetFileTypes(pfod, 1, &filterspec[1]);
ok(hr == E_UNEXPECTED, "got 0x%08x.\n", hr);
- hr = IFileSaveDialog_SetFileTypeIndex(pfsd, -1);
- ok(hr == E_FAIL, "got 0x%08x.\n", hr);
hr = IFileSaveDialog_SetFileTypeIndex(pfsd, 0);
ok(hr == E_FAIL, "got 0x%08x.\n", hr);
hr = IFileSaveDialog_SetFileTypeIndex(pfsd, 1);
ok(hr == E_FAIL, "got 0x%08x.\n", hr);
- hr = IFileSaveDialog_SetFileTypes(pfsd, 1, filterspec);
+ hr = IFileSaveDialog_SetFileTypes(pfsd, 2, filterspec);
ok(hr == S_OK, "got 0x%08x.\n", hr);
+ hr = IFileSaveDialog_GetFileTypeIndex(pfsd, &filetype);
+ ok(hr == S_OK, "got 0x%08x.\n", hr);
+ /* I hope noone relies on this one */
+ todo_wine ok(filetype == 0, "got %d\n", filetype);
hr = IFileSaveDialog_SetFileTypeIndex(pfsd, 0);
ok(hr == S_OK, "got 0x%08x.\n", hr);
+ hr = IFileSaveDialog_GetFileTypeIndex(pfsd, &filetype);
+ ok(hr == S_OK, "got 0x%08x.\n", hr);
+ ok(filetype == 1, "got %d\n", filetype);
hr = IFileSaveDialog_SetFileTypeIndex(pfsd, 100);
ok(hr == S_OK, "got 0x%08x.\n", hr);
+ hr = IFileSaveDialog_GetFileTypeIndex(pfsd, &filetype);
+ ok(hr == S_OK, "got 0x%08x.\n", hr);
+ ok(filetype == 2, "got %d\n", filetype);
hr = IFileSaveDialog_SetFileTypes(pfsd, 1, filterspec);
ok(hr == E_UNEXPECTED, "got 0x%08x.\n", hr);
hr = IFileSaveDialog_SetFileTypes(pfsd, 1, &filterspec[1]);
--
1.9.1
More information about the wine-patches
mailing list