winex11: Set hints for the existing window text when creating the whole window.

This commit is contained in:
Alexandre Julliard 2008-01-23 16:32:55 +01:00
parent 395928dfb1
commit 3ba20257ce
1 changed files with 49 additions and 42 deletions

View File

@ -259,6 +259,49 @@ static void sync_window_region( Display *display, struct x11drv_win_data *data,
} }
/***********************************************************************
* sync_window_text
*/
static void sync_window_text( Display *display, Window win, const WCHAR *text )
{
UINT count;
char *buffer, *utf8_buffer;
XTextProperty prop;
/* allocate new buffer for window text */
count = WideCharToMultiByte(CP_UNIXCP, 0, text, -1, NULL, 0, NULL, NULL);
if (!(buffer = HeapAlloc( GetProcessHeap(), 0, count ))) return;
WideCharToMultiByte(CP_UNIXCP, 0, text, -1, buffer, count, NULL, NULL);
count = WideCharToMultiByte(CP_UTF8, 0, text, strlenW(text), NULL, 0, NULL, NULL);
if (!(utf8_buffer = HeapAlloc( GetProcessHeap(), 0, count )))
{
HeapFree( GetProcessHeap(), 0, buffer );
return;
}
WideCharToMultiByte(CP_UTF8, 0, text, strlenW(text), utf8_buffer, count, NULL, NULL);
wine_tsx11_lock();
if (XmbTextListToTextProperty( display, &buffer, 1, XStdICCTextStyle, &prop ) == Success)
{
XSetWMName( display, win, &prop );
XSetWMIconName( display, win, &prop );
XFree( prop.value );
}
/*
Implements a NET_WM UTF-8 title. It should be without a trailing \0,
according to the standard
( http://www.pps.jussieu.fr/~jch/software/UTF8_STRING/UTF8_STRING.text ).
*/
XChangeProperty( display, win, x11drv_atom(_NET_WM_NAME), x11drv_atom(UTF8_STRING),
8, PropModeReplace, (unsigned char *) utf8_buffer, count);
wine_tsx11_unlock();
HeapFree( GetProcessHeap(), 0, utf8_buffer );
HeapFree( GetProcessHeap(), 0, buffer );
}
/*********************************************************************** /***********************************************************************
* X11DRV_set_win_format * X11DRV_set_win_format
*/ */
@ -1051,6 +1094,7 @@ static Window create_whole_window( Display *display, struct x11drv_win_data *dat
int cx, cy, mask; int cx, cy, mask;
XSetWindowAttributes attr; XSetWindowAttributes attr;
XIM xim; XIM xim;
WCHAR text[1024];
HRGN hrgn; HRGN hrgn;
if (!(cx = data->window_rect.right - data->window_rect.left)) cx = 1; if (!(cx = data->window_rect.right - data->window_rect.left)) cx = 1;
@ -1091,6 +1135,10 @@ static Window create_whole_window( Display *display, struct x11drv_win_data *dat
SetPropA( data->hwnd, whole_window_prop, (HANDLE)data->whole_window ); SetPropA( data->hwnd, whole_window_prop, (HANDLE)data->whole_window );
/* set the window text */
if (!InternalGetWindowText( data->hwnd, text, sizeof(text)/sizeof(WCHAR) )) text[0] = 0;
sync_window_text( display, data->whole_window, text );
/* set the window region */ /* set the window region */
if ((hrgn = CreateRectRgn( 0, 0, 0, 0 ))) if ((hrgn = CreateRectRgn( 0, 0, 0, 0 )))
{ {
@ -1139,51 +1187,10 @@ static void destroy_whole_window( Display *display, struct x11drv_win_data *data
void X11DRV_SetWindowText( HWND hwnd, LPCWSTR text ) void X11DRV_SetWindowText( HWND hwnd, LPCWSTR text )
{ {
Display *display = thread_display(); Display *display = thread_display();
UINT count;
char *buffer;
char *utf8_buffer;
Window win; Window win;
XTextProperty prop;
if ((win = X11DRV_get_whole_window( hwnd )) && win != DefaultRootWindow(display)) if ((win = X11DRV_get_whole_window( hwnd )) && win != DefaultRootWindow(display))
{ sync_window_text( display, win, text );
/* allocate new buffer for window text */
count = WideCharToMultiByte(CP_UNIXCP, 0, text, -1, NULL, 0, NULL, NULL);
if (!(buffer = HeapAlloc( GetProcessHeap(), 0, count )))
{
ERR("Not enough memory for window text\n");
return;
}
WideCharToMultiByte(CP_UNIXCP, 0, text, -1, buffer, count, NULL, NULL);
count = WideCharToMultiByte(CP_UTF8, 0, text, strlenW(text), NULL, 0, NULL, NULL);
if (!(utf8_buffer = HeapAlloc( GetProcessHeap(), 0, count )))
{
ERR("Not enough memory for window text in UTF-8\n");
HeapFree( GetProcessHeap(), 0, buffer );
return;
}
WideCharToMultiByte(CP_UTF8, 0, text, strlenW(text), utf8_buffer, count, NULL, NULL);
wine_tsx11_lock();
if (XmbTextListToTextProperty( display, &buffer, 1, XStdICCTextStyle, &prop ) == Success)
{
XSetWMName( display, win, &prop );
XSetWMIconName( display, win, &prop );
XFree( prop.value );
}
/*
Implements a NET_WM UTF-8 title. It should be without a trailing \0,
according to the standard
( http://www.pps.jussieu.fr/~jch/software/UTF8_STRING/UTF8_STRING.text ).
*/
XChangeProperty( display, win, x11drv_atom(_NET_WM_NAME), x11drv_atom(UTF8_STRING),
8, PropModeReplace, (unsigned char *) utf8_buffer, count);
wine_tsx11_unlock();
HeapFree( GetProcessHeap(), 0, utf8_buffer );
HeapFree( GetProcessHeap(), 0, buffer );
}
} }