David Hedberg : comdlg32: Implement GetFileName and SetFileName for the item dialog.

Alexandre Julliard julliard at winehq.org
Fri Apr 1 09:41:05 CDT 2011


Module: wine
Branch: master
Commit: 36bf6e1afe0b4b21ecbc182df4e0419ea566462e
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=36bf6e1afe0b4b21ecbc182df4e0419ea566462e

Author: David Hedberg <david.hedberg at gmail.com>
Date:   Fri Apr  1 05:52:24 2011 +0200

comdlg32: Implement GetFileName and SetFileName for the item dialog.

---

 dlls/comdlg32/itemdlg.c       |   70 ++++++++++++++++++++++++++++++++++++++--
 dlls/comdlg32/tests/itemdlg.c |   14 +++++---
 2 files changed, 74 insertions(+), 10 deletions(-)

diff --git a/dlls/comdlg32/itemdlg.c b/dlls/comdlg32/itemdlg.c
index ef4bb9d..682f01b 100644
--- a/dlls/comdlg32/itemdlg.c
+++ b/dlls/comdlg32/itemdlg.c
@@ -80,9 +80,52 @@ typedef struct FileDialogImpl {
     HWND dlg_hwnd;
     IExplorerBrowser *peb;
     DWORD ebevents_cookie;
+
+    LPWSTR set_filename;
 } FileDialogImpl;
 
 /**************************************************************************
+ * Helper functions.
+ */
+static UINT get_file_name(FileDialogImpl *This, LPWSTR *str)
+{
+    HWND hwnd_edit = GetDlgItem(This->dlg_hwnd, IDC_FILENAME);
+    UINT len;
+
+    if(!hwnd_edit)
+    {
+        if(This->set_filename)
+        {
+            len = lstrlenW(This->set_filename);
+            *str = CoTaskMemAlloc(sizeof(WCHAR)*(len+1));
+            lstrcpyW(*str, This->set_filename);
+            return len;
+        }
+        return FALSE;
+    }
+
+    len = SendMessageW(hwnd_edit, WM_GETTEXTLENGTH, 0, 0);
+    *str = CoTaskMemAlloc(sizeof(WCHAR)*(len+1));
+    if(!*str)
+        return FALSE;
+
+    SendMessageW(hwnd_edit, WM_GETTEXT, len+1, (LPARAM)*str);
+    return len;
+}
+
+static BOOL set_file_name(FileDialogImpl *This, LPCWSTR str)
+{
+    HWND hwnd_edit = GetDlgItem(This->dlg_hwnd, IDC_FILENAME);
+
+    if(This->set_filename)
+        LocalFree(This->set_filename);
+
+    This->set_filename = StrDupW(str);
+
+    return SendMessageW(hwnd_edit, WM_SETTEXT, 0, (LPARAM)str);
+}
+
+/**************************************************************************
  * Window related functions.
  */
 static SIZE update_layout(FileDialogImpl *This)
@@ -320,6 +363,10 @@ static LRESULT on_wm_initdialog(HWND hwnd, LPARAM lParam)
     else
         ShowWindow(hitem, SW_HIDE);
 
+    if(This->set_filename &&
+       (hitem = GetDlgItem(This->dlg_hwnd, IDC_FILENAME)) )
+        SendMessageW(hitem, WM_SETTEXT, 0, (LPARAM)This->set_filename);
+
     init_explorerbrowser(This);
     update_layout(This);
 
@@ -533,6 +580,8 @@ static ULONG WINAPI IFileDialog2_fnRelease(IFileDialog2 *iface)
         if(This->psia_selection)    IShellItemArray_Release(This->psia_selection);
         if(This->psia_results)      IShellItemArray_Release(This->psia_results);
 
+        LocalFree(This->set_filename);
+
         HeapFree(GetProcessHeap(), 0, This);
     }
 
@@ -752,15 +801,26 @@ static HRESULT WINAPI IFileDialog2_fnGetCurrentSelection(IFileDialog2 *iface, IS
 static HRESULT WINAPI IFileDialog2_fnSetFileName(IFileDialog2 *iface, LPCWSTR pszName)
 {
     FileDialogImpl *This = impl_from_IFileDialog2(iface);
-    FIXME("stub - %p (%p)\n", This, pszName);
-    return E_NOTIMPL;
+    TRACE("%p (%p)\n", iface, pszName);
+
+    set_file_name(This, pszName);
+
+    return S_OK;
 }
 
 static HRESULT WINAPI IFileDialog2_fnGetFileName(IFileDialog2 *iface, LPWSTR *pszName)
 {
     FileDialogImpl *This = impl_from_IFileDialog2(iface);
-    FIXME("stub - %p (%p)\n", This, pszName);
-    return E_NOTIMPL;
+    TRACE("%p (%p)\n", iface, pszName);
+
+    if(!pszName)
+        return E_INVALIDARG;
+
+    *pszName = NULL;
+    if(get_file_name(This, pszName))
+        return S_OK;
+    else
+        return E_FAIL;
 }
 
 static HRESULT WINAPI IFileDialog2_fnSetTitle(IFileDialog2 *iface, LPCWSTR pszTitle)
@@ -1705,6 +1765,8 @@ static HRESULT FileDialog_constructor(IUnknown *pUnkOuter, REFIID riid, void **p
     fdimpl->dlg_hwnd = NULL;
     fdimpl->peb = NULL;
 
+    fdimpl->set_filename = NULL;
+
     /* FIXME: The default folder setting should be restored for the
      * application if it was previously set. */
     SHGetDesktopFolder(&psf);
diff --git a/dlls/comdlg32/tests/itemdlg.c b/dlls/comdlg32/tests/itemdlg.c
index 8f031c2..e14bfaa 100644
--- a/dlls/comdlg32/tests/itemdlg.c
+++ b/dlls/comdlg32/tests/itemdlg.c
@@ -371,8 +371,6 @@ static void test_basics(void)
     }
 
     /* GetFileName */
-    todo_wine
-    {
     hr = IFileOpenDialog_GetFileName(pfod, NULL);
     ok(hr == E_INVALIDARG, "got 0x%08x.\n", hr);
     filename = (void*)0xdeadbeef;
@@ -385,7 +383,6 @@ static void test_basics(void)
     hr = IFileSaveDialog_GetFileName(pfsd, &filename);
     ok(hr == E_FAIL, "got 0x%08x.\n", hr);
     ok(filename == NULL, "got %p\n", filename);
-    }
 
     /* GetFileTypeIndex */
     hr = IFileOpenDialog_GetFileTypeIndex(pfod, NULL);
@@ -546,14 +543,16 @@ static void test_basics(void)
     }
 
     /* SetFileName */
-    todo_wine
-    {
     hr = IFileOpenDialog_SetFileName(pfod, NULL);
     ok(hr == S_OK, "got 0x%08x\n", hr);
     hr = IFileOpenDialog_SetFileName(pfod, null);
     ok(hr == S_OK, "got 0x%08x\n", hr);
     hr = IFileOpenDialog_SetFileName(pfod, txt);
     ok(hr == S_OK, "got 0x%08x\n", hr);
+    hr = IFileOpenDialog_GetFileName(pfod, &filename);
+    ok(hr == S_OK, "Got 0x%08x\n", hr);
+    ok(!lstrcmpW(filename, txt), "Strings do not match.\n");
+    CoTaskMemFree(filename);
 
     hr = IFileSaveDialog_SetFileName(pfsd, NULL);
     ok(hr == S_OK, "got 0x%08x\n", hr);
@@ -561,7 +560,10 @@ static void test_basics(void)
     ok(hr == S_OK, "got 0x%08x\n", hr);
     hr = IFileSaveDialog_SetFileName(pfsd, txt);
     ok(hr == S_OK, "got 0x%08x\n", hr);
-    }
+    hr = IFileSaveDialog_GetFileName(pfsd, &filename);
+    ok(hr == S_OK, "Got 0x%08x\n", hr);
+    ok(!lstrcmpW(filename, txt), "Strings do not match.\n");
+    CoTaskMemFree(filename);
 
     /* SetFileNameLabel */
     todo_wine




More information about the wine-cvs mailing list