[PATCH 1/6] win32u: Move WM_GETTEXTLENGTH implementation from user32.
Jacek Caban
wine at gitlab.winehq.org
Tue Jun 21 07:03:38 CDT 2022
From: Jacek Caban <jacek at codeweavers.com>
Signed-off-by: Jacek Caban <jacek at codeweavers.com>
---
dlls/user32/defwnd.c | 18 ------------------
dlls/win32u/defwnd.c | 14 ++++++++++++++
dlls/win32u/font.c | 22 ++++++++++++++++++++++
dlls/win32u/tests/win32u.c | 9 +++++++++
dlls/win32u/win32u_private.h | 1 +
5 files changed, 46 insertions(+), 18 deletions(-)
diff --git a/dlls/user32/defwnd.c b/dlls/user32/defwnd.c
index 16442b6899e..c72789ac963 100644
--- a/dlls/user32/defwnd.c
+++ b/dlls/user32/defwnd.c
@@ -145,16 +145,6 @@ LRESULT WINAPI DefWindowProcA( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam
result = NC_HandleSysCommand( hwnd, wParam, lParam );
break;
- case WM_GETTEXTLENGTH:
- {
- WND *wndPtr = WIN_GetPtr( hwnd );
- if (wndPtr && wndPtr->text)
- result = WideCharToMultiByte( CP_ACP, 0, wndPtr->text, lstrlenW(wndPtr->text),
- NULL, 0, NULL, NULL );
- WIN_ReleasePtr( wndPtr );
- }
- break;
-
case WM_GETTEXT:
if (wParam)
{
@@ -325,14 +315,6 @@ LRESULT WINAPI DefWindowProcW(
result = NC_HandleSysCommand( hwnd, wParam, lParam );
break;
- case WM_GETTEXTLENGTH:
- {
- WND *wndPtr = WIN_GetPtr( hwnd );
- if (wndPtr && wndPtr->text) result = (LRESULT)lstrlenW(wndPtr->text);
- WIN_ReleasePtr( wndPtr );
- }
- break;
-
case WM_GETTEXT:
if (wParam)
{
diff --git a/dlls/win32u/defwnd.c b/dlls/win32u/defwnd.c
index 90323e304fc..c54dbdb710c 100644
--- a/dlls/win32u/defwnd.c
+++ b/dlls/win32u/defwnd.c
@@ -2505,6 +2505,20 @@ LRESULT default_window_proc( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
handle_nc_paint( hwnd , (HRGN)1 ); /* repaint caption */
break;
+ case WM_GETTEXTLENGTH:
+ {
+ WND *win = get_win_ptr( hwnd );
+ if (win && win->text)
+ {
+ if (ansi)
+ result = win32u_wctomb_size( &ansi_cp, win->text, wcslen( win->text ));
+ else
+ result = wcslen( win->text );
+ }
+ 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)
diff --git a/dlls/win32u/font.c b/dlls/win32u/font.c
index 39b195fe25a..5bf59903308 100644
--- a/dlls/win32u/font.c
+++ b/dlls/win32u/font.c
@@ -3230,6 +3230,28 @@ DWORD win32u_wctomb( CPTABLEINFO *info, char *dst, DWORD dstlen, const WCHAR *sr
return ret;
}
+DWORD win32u_wctomb_size( CPTABLEINFO *info, const WCHAR *src, DWORD srclen )
+{
+ DWORD ret;
+
+ if (info->CodePage == CP_UTF8)
+ {
+ RtlUnicodeToUTF8N( NULL, 0, &ret, src, srclen * sizeof(WCHAR) );
+ }
+ else if(info->DBCSCodePage)
+ {
+ WCHAR *uni2cp = info->WideCharTable;
+ for (ret = srclen; srclen; srclen--, src++)
+ if (uni2cp[*src] & 0xff00) ret++;
+ }
+ else
+ {
+ ret = srclen;
+ }
+
+ return ret;
+}
+
DWORD win32u_mbtowc( CPTABLEINFO *info, WCHAR *dst, DWORD dstlen, const char *src, DWORD srclen )
{
DWORD ret;
diff --git a/dlls/win32u/tests/win32u.c b/dlls/win32u/tests/win32u.c
index 11820859358..dc1638f37ab 100644
--- a/dlls/win32u/tests/win32u.c
+++ b/dlls/win32u/tests/win32u.c
@@ -494,6 +494,12 @@ static void test_window_text(void)
ok( len == 4, "len = %d\n", len );
ok( !lstrcmpW( buf, L"test" ), "buf = %s\n", wine_dbgstr_w(buf) );
+ res = NtUserMessageCall( hwnd, WM_GETTEXTLENGTH, 0, 0, 0, NtUserDefWindowProc, TRUE );
+ ok( res == 4, "res = %Id\n", res );
+
+ res = NtUserMessageCall( hwnd, WM_GETTEXTLENGTH, 0, 0, 0, NtUserDefWindowProc, FALSE );
+ ok( res == 4, "res = %Id\n", res );
+
res = NtUserMessageCall( hwnd, WM_SETTEXT, 0, (LPARAM)"TestA", 0, NtUserDefWindowProc, TRUE );
ok( res == 1, "res = %Id\n", res );
@@ -502,6 +508,9 @@ static void test_window_text(void)
ok( len == 5, "len = %d\n", len );
ok( !lstrcmpW( buf, L"TestA" ), "buf = %s\n", wine_dbgstr_w(buf) );
+ res = NtUserMessageCall( hwnd, WM_GETTEXTLENGTH, 0, 0, 0, NtUserDefWindowProc, TRUE );
+ ok( res == 5, "res = %Id\n", res );
+
DestroyWindow( hwnd );
}
diff --git a/dlls/win32u/win32u_private.h b/dlls/win32u/win32u_private.h
index 808d3f83e37..468375f1ddf 100644
--- a/dlls/win32u/win32u_private.h
+++ b/dlls/win32u/win32u_private.h
@@ -575,6 +575,7 @@ DWORD win32u_mbtowc( CPTABLEINFO *info, WCHAR *dst, DWORD dstlen, const char *sr
DWORD srclen ) DECLSPEC_HIDDEN;
DWORD win32u_wctomb( CPTABLEINFO *info, char *dst, DWORD dstlen, const WCHAR *src,
DWORD srclen ) DECLSPEC_HIDDEN;
+DWORD win32u_wctomb_size( CPTABLEINFO *info, const WCHAR *src, DWORD srclen ) DECLSPEC_HIDDEN;
static inline WCHAR *win32u_wcsdup( const WCHAR *str )
{
--
GitLab
https://gitlab.winehq.org/wine/wine/-/merge_requests/294
More information about the wine-devel
mailing list