[PATCH v2 2/6] win32u: Move WM_GETTEXT implementation from user32.

Jacek Caban wine at gitlab.winehq.org
Tue Jun 21 08:09:59 CDT 2022


From: Jacek Caban <jacek at codeweavers.com>

Signed-off-by: Jacek Caban <jacek at codeweavers.com>
---
 dlls/user32/defwnd.c | 71 --------------------------------------------
 dlls/win32u/defwnd.c | 34 +++++++++++++++++++++
 2 files changed, 34 insertions(+), 71 deletions(-)

diff --git a/dlls/user32/defwnd.c b/dlls/user32/defwnd.c
index c72789ac963..d29846ad623 100644
--- a/dlls/user32/defwnd.c
+++ b/dlls/user32/defwnd.c
@@ -30,8 +30,6 @@
 #include "win.h"
 #include "user_private.h"
 #include "controls.h"
-#include "wine/server.h"
-#include "wine/exception.h"
 #include "wine/debug.h"
 
 WINE_DEFAULT_DEBUG_CHANNEL(win);
@@ -73,28 +71,6 @@ HBRUSH DEFWND_ControlColor( HDC hDC, UINT ctlType )
 }
 
 
-static LPARAM DEFWND_GetTextA( WND *wndPtr, LPSTR dest, WPARAM wParam )
-{
-    LPARAM result = 0;
-
-    __TRY
-    {
-        if (wndPtr->text)
-        {
-            if (!WideCharToMultiByte( CP_ACP, 0, wndPtr->text, -1,
-                                      dest, wParam, NULL, NULL )) dest[wParam-1] = 0;
-            result = strlen( dest );
-        }
-        else dest[0] = '\0';
-    }
-    __EXCEPT_PAGE_FAULT
-    {
-        return 0;
-    }
-    __ENDTRY
-    return result;
-}
-
 /***********************************************************************
  *              DefWindowProcA (USER32.@)
  *
@@ -145,19 +121,6 @@ LRESULT WINAPI DefWindowProcA( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam
         result = NC_HandleSysCommand( hwnd, wParam, lParam );
         break;
 
-    case WM_GETTEXT:
-        if (wParam)
-        {
-            LPSTR dest = (LPSTR)lParam;
-            WND *wndPtr = WIN_GetPtr( hwnd );
-
-            if (!wndPtr) break;
-            result = DEFWND_GetTextA( wndPtr, dest, wParam );
-
-            WIN_ReleasePtr( wndPtr );
-        }
-        break;
-
     case WM_IME_CHAR:
         if (HIBYTE(wParam)) PostMessageA( hwnd, WM_CHAR, HIBYTE(wParam), lParam );
         PostMessageA( hwnd, WM_CHAR, LOBYTE(wParam), lParam );
@@ -236,28 +199,6 @@ LRESULT WINAPI DefWindowProcA( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam
 }
 
 
-static LPARAM DEFWND_GetTextW( WND *wndPtr, LPWSTR dest, WPARAM wParam )
-{
-    LPARAM result = 0;
-
-    __TRY
-    {
-        if (wndPtr->text)
-        {
-            lstrcpynW( dest, wndPtr->text, wParam );
-            result = lstrlenW( dest );
-        }
-        else dest[0] = '\0';
-    }
-    __EXCEPT_PAGE_FAULT
-    {
-        return 0;
-    }
-    __ENDTRY
-
-    return result;
-}
-
 /***********************************************************************
  *              DefWindowProcW (USER32.@) Calls default window message handler
  *
@@ -315,18 +256,6 @@ LRESULT WINAPI DefWindowProcW(
         result = NC_HandleSysCommand( hwnd, wParam, lParam );
         break;
 
-    case WM_GETTEXT:
-        if (wParam)
-        {
-            LPWSTR dest = (LPWSTR)lParam;
-            WND *wndPtr = WIN_GetPtr( hwnd );
-
-            if (!wndPtr) break;
-            result = DEFWND_GetTextW( wndPtr, dest, wParam );
-            WIN_ReleasePtr( wndPtr );
-        }
-        break;
-
     case WM_IME_CHAR:
         PostMessageW( hwnd, WM_CHAR, wParam, lParam );
         break;
diff --git a/dlls/win32u/defwnd.c b/dlls/win32u/defwnd.c
index c54dbdb710c..af51b933d49 100644
--- a/dlls/win32u/defwnd.c
+++ b/dlls/win32u/defwnd.c
@@ -2519,6 +2519,40 @@ LRESULT default_window_proc( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
         }
         break;
 
+    case WM_GETTEXT:
+        if (wparam)
+        {
+            WND *win;
+
+            if (!(win = get_win_ptr( hwnd ))) break;
+
+            __TRY
+            {
+                if (ansi)
+                {
+                    char *dest = (char *)lparam;
+                    if (win->text)
+                        result = win32u_wctomb( &ansi_cp, dest, wparam - 1,
+                                                win->text, wcslen( win->text ));
+                    dest[result] = 0;
+                }
+                else
+                {
+                    WCHAR *dest = (WCHAR *)lparam;
+                    if (win->text) result = min( wcslen( win->text ), wparam - 1 );
+                    if (result) memcpy( dest, win->text, result * sizeof(WCHAR) );
+                    dest[result] = 0;
+                }
+            }
+            __EXCEPT
+            {
+            }
+            __ENDTRY
+
+            release_win_ptr( win );
+        }
+        break;
+
     case WM_SETICON:
         result = (LRESULT)set_window_icon( hwnd, wparam, (HICON)lparam );
         if ((get_window_long( hwnd, GWL_STYLE ) & WS_CAPTION) == WS_CAPTION)
-- 
GitLab


https://gitlab.winehq.org/wine/wine/-/merge_requests/294



More information about the wine-devel mailing list