Commit 27cfcaa2 authored by Jacek Caban's avatar Jacek Caban Committed by Alexandre Julliard

win32u: Move default window text setting to from user32.

parent b7f108ed
......@@ -75,89 +75,6 @@ static void DEFWND_HandleWindowPosChanged( HWND hwnd, const WINDOWPOS *winpos )
/***********************************************************************
* DEFWND_SetTextA
*
* Set the window text.
*/
static LRESULT DEFWND_SetTextA( HWND hwnd, LPCSTR text )
{
int count;
WCHAR *textW;
WND *wndPtr;
/* check for string, as static icons, bitmaps (SS_ICON, SS_BITMAP)
* may have child window IDs instead of window name */
if (text && IS_INTRESOURCE(text))
return 0;
if (!text) text = "";
count = MultiByteToWideChar( CP_ACP, 0, text, -1, NULL, 0 );
if (!(wndPtr = WIN_GetPtr( hwnd ))) return 0;
if ((textW = HeapAlloc(GetProcessHeap(), 0, count * sizeof(WCHAR))))
{
HeapFree(GetProcessHeap(), 0, wndPtr->text);
wndPtr->text = textW;
MultiByteToWideChar( CP_ACP, 0, text, -1, textW, count );
SERVER_START_REQ( set_window_text )
{
req->handle = wine_server_user_handle( hwnd );
wine_server_add_data( req, textW, (count-1) * sizeof(WCHAR) );
wine_server_call( req );
}
SERVER_END_REQ;
}
else
ERR("Not enough memory for window text\n");
WIN_ReleasePtr( wndPtr );
USER_Driver->pSetWindowText( hwnd, textW );
return 1;
}
/***********************************************************************
* DEFWND_SetTextW
*
* Set the window text.
*/
static LRESULT DEFWND_SetTextW( HWND hwnd, LPCWSTR text )
{
WND *wndPtr;
int count;
/* check for string, as static icons, bitmaps (SS_ICON, SS_BITMAP)
* may have child window IDs instead of window name */
if (text && IS_INTRESOURCE(text))
return 0;
if (!text) text = L"";
count = lstrlenW(text) + 1;
if (!(wndPtr = WIN_GetPtr( hwnd ))) return 0;
HeapFree(GetProcessHeap(), 0, wndPtr->text);
if ((wndPtr->text = HeapAlloc(GetProcessHeap(), 0, count * sizeof(WCHAR))))
{
lstrcpyW( wndPtr->text, text );
SERVER_START_REQ( set_window_text )
{
req->handle = wine_server_user_handle( hwnd );
wine_server_add_data( req, wndPtr->text, (count-1) * sizeof(WCHAR) );
wine_server_call( req );
}
SERVER_END_REQ;
}
else
ERR("Not enough memory for window text\n");
text = wndPtr->text;
WIN_ReleasePtr( wndPtr );
USER_Driver->pSetWindowText( hwnd, text );
return 1;
}
/***********************************************************************
* DEFWND_ControlColor
*
* Default colors for control painting.
......@@ -346,16 +263,7 @@ static LRESULT DEFWND_DefWinProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPa
return NC_HandleNCActivate( hwnd, wParam, lParam );
case WM_NCDESTROY:
{
WND *wndPtr = WIN_GetPtr( hwnd );
if (!wndPtr) return 0;
HeapFree( GetProcessHeap(), 0, wndPtr->text );
wndPtr->text = NULL;
HeapFree( GetProcessHeap(), 0, wndPtr->pScroll );
wndPtr->pScroll = NULL;
WIN_ReleasePtr( wndPtr );
return 0;
}
return NtUserMessageCall( hwnd, msg, wParam, lParam, 0, FNID_DEFWINDOWPROC, FALSE );
case WM_PRINT:
DEFWND_Print(hwnd, (HDC)wParam, lParam);
......@@ -802,8 +710,7 @@ LRESULT WINAPI DefWindowProcA( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam
{
CREATESTRUCTA *cs = (CREATESTRUCTA *)lParam;
DEFWND_SetTextA( hwnd, cs->lpszName );
result = 1;
result = NtUserMessageCall( hwnd, msg, wParam, lParam, 0, FNID_DEFWINDOWPROC, TRUE );
if(cs->style & (WS_HSCROLL | WS_VSCROLL))
{
......@@ -838,11 +745,9 @@ LRESULT WINAPI DefWindowProcA( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam
break;
case WM_SETTEXT:
if (!DEFWND_SetTextA( hwnd, (LPCSTR)lParam ))
break;
if( (GetWindowLongW( hwnd, GWL_STYLE ) & WS_CAPTION) == WS_CAPTION )
result = NtUserMessageCall( hwnd, msg, wParam, lParam, 0, FNID_DEFWINDOWPROC, TRUE );
if (result && (GetWindowLongW( hwnd, GWL_STYLE ) & WS_CAPTION) == WS_CAPTION)
NC_HandleNCPaint( hwnd , (HRGN)1 ); /* Repaint caption */
result = 1; /* success. FIXME: check text length */
break;
case WM_IME_CHAR:
......@@ -987,8 +892,7 @@ LRESULT WINAPI DefWindowProcW(
{
CREATESTRUCTW *cs = (CREATESTRUCTW *)lParam;
DEFWND_SetTextW( hwnd, cs->lpszName );
result = 1;
result = NtUserMessageCall( hwnd, msg, wParam, lParam, 0, FNID_DEFWINDOWPROC, FALSE );
if(cs->style & (WS_HSCROLL | WS_VSCROLL))
{
......@@ -1020,11 +924,9 @@ LRESULT WINAPI DefWindowProcW(
break;
case WM_SETTEXT:
if (!DEFWND_SetTextW( hwnd, (LPCWSTR)lParam ))
break;
if( (GetWindowLongW( hwnd, GWL_STYLE ) & WS_CAPTION) == WS_CAPTION )
result = NtUserMessageCall( hwnd, msg, wParam, lParam, 0, FNID_DEFWINDOWPROC, FALSE );
if (result && (GetWindowLongW( hwnd, GWL_STYLE ) & WS_CAPTION) == WS_CAPTION)
NC_HandleNCPaint( hwnd , (HRGN)1 ); /* Repaint caption */
result = 1; /* success. FIXME: check text length */
break;
case WM_IME_CHAR:
......
......@@ -73,10 +73,6 @@ static void CDECL nulldrv_SetWindowIcon( HWND hwnd, UINT type, HICON icon )
{
}
static void CDECL nulldrv_SetWindowText( HWND hwnd, LPCWSTR text )
{
}
static LRESULT CDECL nulldrv_SysCommand( HWND hwnd, WPARAM wparam, LPARAM lparam )
{
return -1;
......@@ -136,7 +132,7 @@ static struct user_driver_funcs lazy_load_driver =
NULL,
nulldrv_SetWindowIcon,
NULL,
nulldrv_SetWindowText,
NULL,
NULL,
nulldrv_SysCommand,
NULL,
......@@ -171,7 +167,6 @@ void CDECL __wine_set_user_driver( const struct user_driver_funcs *funcs, UINT v
SET_USER_FUNC(UpdateClipboard);
SET_USER_FUNC(SetWindowIcon);
SET_USER_FUNC(SetWindowText);
SET_USER_FUNC(SysCommand);
#undef SET_USER_FUNC
......
......@@ -153,7 +153,6 @@ static void WINAPI unregister_imm( HWND hwnd )
static void CDECL free_win_ptr( WND *win )
{
HeapFree( GetProcessHeap(), 0, win->text );
HeapFree( GetProcessHeap(), 0, win->pScroll );
}
......
......@@ -18,6 +18,7 @@ C_SRCS = \
cursoricon.c \
dc.c \
dce.c \
defwnd.c \
dib.c \
dibdrv/bitblt.c \
dibdrv/dc.c \
......
/*
* Default window procedure
*
* Copyright 1993, 1996 Alexandre Julliard
* Copyright 1995 Alex Korobka
* Copyright 2022 Jacek Caban for CodeWeavers
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
#if 0
#pragma makedep unix
#endif
#include "win32u_private.h"
#include "ntuser_private.h"
#include "wine/server.h"
WINE_DEFAULT_DEBUG_CHANNEL(win);
static BOOL set_window_text( HWND hwnd, const void *text, BOOL ansi )
{
static const WCHAR emptyW[] = { 0 };
WCHAR *str;
WND *win;
/* check for string, as static icons, bitmaps (SS_ICON, SS_BITMAP)
* may have child window IDs instead of window name */
if (text && IS_INTRESOURCE(text)) return FALSE;
if (text)
{
if (ansi) str = towstr( text );
else str = wcsdup( text );
if (!str) return FALSE;
}
else str = NULL;
TRACE( "%s\n", debugstr_w(str) );
if (!(win = get_win_ptr( hwnd )))
{
free( str );
return FALSE;
}
free( win->text );
win->text = str;
SERVER_START_REQ( set_window_text )
{
req->handle = wine_server_user_handle( hwnd );
if (str) wine_server_add_data( req, str, lstrlenW( str ) * sizeof(WCHAR) );
wine_server_call( req );
}
SERVER_END_REQ;
release_win_ptr( win );
user_driver->pSetWindowText( hwnd, str ? str : emptyW );
return TRUE;
}
LRESULT default_window_proc( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam, BOOL ansi )
{
LRESULT result = 0;
switch (msg)
{
case WM_NCCREATE:
if (lparam)
{
CREATESTRUCTW *cs = (CREATESTRUCTW *)lparam;
set_window_text( hwnd, cs->lpszName, ansi );
result = 1;
}
break;
case WM_NCDESTROY:
{
WND *win = get_win_ptr( hwnd );
if (!win) return 0;
free( win->text );
win->text = NULL;
if (user_callbacks) user_callbacks->free_win_ptr( win );
win->pScroll = NULL;
release_win_ptr( win );
return 0;
}
case WM_SETTEXT:
result = set_window_text( hwnd, (void *)lparam, ansi );
break;
}
return result;
}
......@@ -2847,6 +2847,8 @@ LRESULT WINAPI NtUserMessageCall( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lpa
{
switch (type)
{
case FNID_DEFWINDOWPROC:
return default_window_proc( hwnd, msg, wparam, lparam, ansi );
case FNID_CALLWNDPROC:
return init_win_proc_params( (struct win_proc_params *)result_info, hwnd, msg,
wparam, lparam, ansi );
......
......@@ -472,6 +472,39 @@ static void test_message_call(void)
UnregisterClassW( L"TestClass", NULL );
}
static void test_window_text(void)
{
WCHAR buf[512];
LRESULT res;
int len;
HWND hwnd;
hwnd = CreateWindowExW( 0, L"static", NULL, WS_POPUP, 0,0,0,0,0,0,0, NULL );
memset( buf, 0xcc, sizeof(buf) );
len = NtUserInternalGetWindowText( hwnd, buf, ARRAYSIZE(buf) );
ok( len == 0, "len = %d\n", len );
ok( !buf[0], "buf = %s\n", wine_dbgstr_w(buf) );
res = NtUserMessageCall( hwnd, WM_SETTEXT, 0, (LPARAM)L"test", 0, FNID_DEFWINDOWPROC, FALSE );
ok( res == 1, "res = %Id\n", res );
memset( buf, 0xcc, sizeof(buf) );
len = NtUserInternalGetWindowText( hwnd, buf, ARRAYSIZE(buf) );
ok( len == 4, "len = %d\n", len );
ok( !lstrcmpW( buf, L"test" ), "buf = %s\n", wine_dbgstr_w(buf) );
res = NtUserMessageCall( hwnd, WM_SETTEXT, 0, (LPARAM)"TestA", 0, FNID_DEFWINDOWPROC, TRUE );
ok( res == 1, "res = %Id\n", res );
memset( buf, 0xcc, sizeof(buf) );
len = NtUserInternalGetWindowText( hwnd, buf, ARRAYSIZE(buf) );
ok( len == 5, "len = %d\n", len );
ok( !lstrcmpW( buf, L"TestA" ), "buf = %s\n", wine_dbgstr_w(buf) );
DestroyWindow( hwnd );
}
START_TEST(win32u)
{
/* native win32u.dll fails if user32 is not loaded, so make sure it's fully initialized */
......@@ -483,6 +516,7 @@ START_TEST(win32u)
test_NtUserBuildHwndList();
test_cursoricon();
test_message_call();
test_window_text();
test_NtUserCloseWindowStation();
}
......@@ -331,6 +331,10 @@ extern void move_window_bits_parent( HWND hwnd, HWND parent, const RECT *window_
extern void register_window_surface( struct window_surface *old,
struct window_surface *new ) DECLSPEC_HIDDEN;
/* defwnd.c */
extern LRESULT default_window_proc( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
BOOL ansi ) DECLSPEC_HIDDEN;
/* hook.c */
extern LRESULT call_current_hook( HHOOK hhook, INT code, WPARAM wparam, LPARAM lparam ) DECLSPEC_HIDDEN;
extern LRESULT call_hooks( INT id, INT code, WPARAM wparam, LPARAM lparam, BOOL unicode ) DECLSPEC_HIDDEN;
......
......@@ -4272,6 +4272,7 @@ static void free_window_handle( HWND hwnd )
SERVER_END_REQ;
user_unlock();
if (user_callbacks) user_callbacks->free_win_ptr( win );
free( win->text );
free( win );
}
}
......@@ -4475,6 +4476,7 @@ void destroy_thread_windows(void)
window_surface_release( win->surface );
}
if (user_callbacks) user_callbacks->free_win_ptr( win );
free( win->text );
free( win );
}
}
......
......@@ -238,6 +238,7 @@ enum
/* NtUserMessageCall codes */
enum
{
FNID_DEFWINDOWPROC = 0x029e,
FNID_CALLWNDPROC = 0x02ab,
FNID_SENDMESSAGE = 0x02b1,
FNID_SENDMESSAGEWTOOPTION = 0x02b3,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment