win32u: Move WM_GETTEXTLENGTH implementation from user32.

Signed-off-by: Jacek Caban <jacek@codeweavers.com>
This commit is contained in:
Jacek Caban 2022-06-20 17:58:21 +02:00 committed by Alexandre Julliard
parent 99e2f4caca
commit 9260d114b1
5 changed files with 46 additions and 18 deletions

View file

@ -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)
{

View file

@ -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)

View file

@ -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;

View file

@ -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 );
}

View file

@ -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 )
{