Commit 8a8d1b93 authored by Dmitry Timoshkov's avatar Dmitry Timoshkov Committed by Alexandre Julliard

Added support for CP_UNIXCP.

parent 37da1e67
......@@ -43,7 +43,60 @@ WINE_DEFAULT_DEBUG_CHANNEL(nls);
#define LOCALE_LOCALEINFOFLAGSMASK (LOCALE_NOUSEROVERRIDE|LOCALE_USE_CP_ACP|LOCALE_RETURN_NUMBER)
extern void CODEPAGE_Init( UINT ansi, UINT oem, UINT mac, LCID lcid );
extern void CODEPAGE_Init( UINT ansi_cp, UINT oem_cp, UINT mac_cp, UINT unix_cp, LCID lcid );
/* Charset to codepage map, sorted by name. */
static const struct charset_entry
{
const char *charset_name;
UINT codepage;
} charset_names[] =
{
{ "CP1250", 1250 },
{ "CP1251", 1251 },
{ "CP1252", 1252 },
{ "CP1253", 1253 },
{ "CP1254", 1254 },
{ "CP1255", 1255 },
{ "CP1256", 1256 },
{ "CP1257", 1257 },
{ "CP1258", 1258 },
{ "IBM037", 37 },
{ "IBM1026", 1026 },
{ "IBM424", 424 },
{ "IBM437", 437 },
{ "IBM500", 500 },
{ "IBM850", 850 },
{ "IBM852", 852 },
{ "IBM855", 855 },
{ "IBM857", 857 },
{ "IBM860", 860 },
{ "IBM861", 861 },
{ "IBM862", 862 },
{ "IBM863", 863 },
{ "IBM864", 864 },
{ "IBM865", 865 },
{ "IBM866", 866 },
{ "IBM869", 869 },
{ "IBM874", 874 },
{ "IBM875", 875 },
{ "ISO-8859-1", 28591 },
{ "ISO-8859-10", 28600 },
{ "ISO-8859-13", 28603 },
{ "ISO-8859-14", 28604 },
{ "ISO-8859-15", 28605 },
{ "ISO-8859-2", 28592 },
{ "ISO-8859-3", 28593 },
{ "ISO-8859-4", 28594 },
{ "ISO-8859-5", 28595 },
{ "ISO-8859-6", 28596 },
{ "ISO-8859-7", 28597 },
{ "ISO-8859-8", 28598 },
{ "ISO-8859-9", 28599 },
{ "KOI8-R", 20866 },
{ "KOI8-U", 20866 },
{ "UTF-8", CP_UTF8 }
};
#define NLS_MAX_LANGUAGES 20
typedef struct {
......@@ -334,9 +387,18 @@ END:
/***********************************************************************
* charset_cmp (internal)
*/
static int charset_cmp( const void *name, const void *entry )
{
const struct charset_entry *charset = (struct charset_entry *)entry;
return strcasecmp( (char *)name, charset->charset_name );
}
/***********************************************************************
* init_default_lcid
*/
static LCID init_default_lcid(void)
static LCID init_default_lcid( UINT *unix_cp )
{
char buf[256];
char *lang,*country,*charset,*dialect,*next;
......@@ -359,6 +421,19 @@ static LCID init_default_lcid(void)
country=strchr(lang,'_'); if (country) *country++='\0';
ret = get_language_id(lang, country, charset, dialect);
if (ret && charset)
{
const struct charset_entry *entry;
entry = bsearch( charset, charset_names, sizeof(charset_names)/sizeof(charset_names[0]),
sizeof(charset_names[0]), charset_cmp );
if (entry)
{
*unix_cp = entry->codepage;
TRACE("charset %s was mapped to cp %u\n", charset, *unix_cp);
}
else
FIXME("charset %s was not recognized\n", charset);
}
lang=next;
} while (lang && !ret);
......@@ -1316,20 +1391,23 @@ int WINAPI lstrcmpiW(LPCWSTR str1, LPCWSTR str2)
*/
void LOCALE_Init(void)
{
UINT ansi = 1252, oem = 437, mac = 10000;
LCID lcid = init_default_lcid();
UINT ansi_cp = 1252, oem_cp = 437, mac_cp = 10000, unix_cp = -1;
LCID lcid = init_default_lcid( &unix_cp );
NtSetDefaultLocale( FALSE, lcid );
NtSetDefaultLocale( TRUE, lcid );
GetLocaleInfoW( lcid, LOCALE_IDEFAULTANSICODEPAGE | LOCALE_RETURN_NUMBER,
(LPWSTR)&ansi, sizeof(ansi)/sizeof(WCHAR) );
(LPWSTR)&ansi_cp, sizeof(ansi_cp)/sizeof(WCHAR) );
GetLocaleInfoW( lcid, LOCALE_IDEFAULTMACCODEPAGE | LOCALE_RETURN_NUMBER,
(LPWSTR)&mac, sizeof(mac)/sizeof(WCHAR) );
(LPWSTR)&mac_cp, sizeof(mac_cp)/sizeof(WCHAR) );
GetLocaleInfoW( lcid, LOCALE_IDEFAULTCODEPAGE | LOCALE_RETURN_NUMBER,
(LPWSTR)&oem, sizeof(oem)/sizeof(WCHAR) );
(LPWSTR)&oem_cp, sizeof(oem_cp)/sizeof(WCHAR) );
if (unix_cp == -1)
GetLocaleInfoW( lcid, LOCALE_IDEFAULTUNIXCODEPAGE | LOCALE_RETURN_NUMBER,
(LPWSTR)&unix_cp, sizeof(unix_cp)/sizeof(WCHAR) );
CODEPAGE_Init( ansi, oem, mac, lcid );
CODEPAGE_Init( ansi_cp, oem_cp, mac_cp, unix_cp, lcid );
update_registry( lcid );
}
......
......@@ -955,7 +955,6 @@ HANDLE X11DRV_CLIPBOARD_ImportXAString(LPBYTE lpdata, UINT cBytes)
if ((lpstr = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, cBytes + inlcount + 1)))
{
UINT count;
UINT text_cp = CP_ACP;
for (i = 0, inlcount = 0; i <= cBytes; i++)
{
......@@ -965,16 +964,13 @@ HANDLE X11DRV_CLIPBOARD_ImportXAString(LPBYTE lpdata, UINT cBytes)
lpstr[inlcount++] = lpdata[i];
}
GetLocaleInfoW(LOCALE_SYSTEM_DEFAULT, LOCALE_IDEFAULTUNIXCODEPAGE |
LOCALE_RETURN_NUMBER, (WCHAR *)&text_cp, (sizeof(UINT)/sizeof(WCHAR)));
count = MultiByteToWideChar(text_cp, 0, lpstr, -1, NULL, 0);
count = MultiByteToWideChar(CP_UNIXCP, 0, lpstr, -1, NULL, 0);
hUnicodeText = GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE, count * sizeof(WCHAR));
if(hUnicodeText)
{
WCHAR *textW = GlobalLock(hUnicodeText);
MultiByteToWideChar(text_cp, 0, lpstr, -1, textW, count);
MultiByteToWideChar(CP_UNIXCP, 0, lpstr, -1, textW, count);
GlobalUnlock(hUnicodeText);
}
......@@ -1104,21 +1100,17 @@ HANDLE X11DRV_CLIPBOARD_ExportXAString(LPWINE_CLIPDATA lpData, LPDWORD lpBytes)
UINT size;
LPWSTR uni_text;
LPSTR text, lpstr;
UINT text_cp = CP_ACP;
*lpBytes = 0; /* Assume return has zero bytes */
GetLocaleInfoW(LOCALE_SYSTEM_DEFAULT, LOCALE_IDEFAULTUNIXCODEPAGE |
LOCALE_RETURN_NUMBER, (WCHAR *)&text_cp, (sizeof(UINT)/sizeof(WCHAR)));
uni_text = GlobalLock(lpData->hData32);
size = WideCharToMultiByte(text_cp, 0, uni_text, -1, NULL, 0, NULL, NULL);
size = WideCharToMultiByte(CP_UNIXCP, 0, uni_text, -1, NULL, 0, NULL, NULL);
text = HeapAlloc(GetProcessHeap(), 0, size);
if (!text)
return None;
WideCharToMultiByte(text_cp, 0, uni_text, -1, text, size, NULL, NULL);
WideCharToMultiByte(CP_UNIXCP, 0, uni_text, -1, text, size, NULL, NULL);
/* remove carriage returns */
......
......@@ -794,36 +794,19 @@ BOOL X11DRV_SetWindowText( HWND hwnd, LPCWSTR text )
UINT count;
char *buffer;
char *utf8_buffer;
static UINT text_cp = (UINT)-1;
Window win;
XTextProperty prop;
if ((win = X11DRV_get_whole_window( hwnd )))
{
if (text_cp == (UINT)-1)
{
HKEY hkey;
/* default value */
text_cp = CP_ACP;
if(!RegOpenKeyA(HKEY_LOCAL_MACHINE, "Software\\Wine\\Wine\\Config\\x11drv", &hkey))
{
char buffer[20];
DWORD type, count = sizeof(buffer);
if(!RegQueryValueExA(hkey, "TextCP", 0, &type, buffer, &count))
text_cp = atoi(buffer);
RegCloseKey(hkey);
}
TRACE("text_cp = %u\n", text_cp);
}
/* allocate new buffer for window text */
count = WideCharToMultiByte(text_cp, 0, text, -1, NULL, 0, NULL, NULL);
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 FALSE;
}
WideCharToMultiByte(text_cp, 0, text, -1, buffer, count, NULL, NULL);
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 )))
......
......@@ -2851,18 +2851,6 @@ with the <literal>GraphicsDriver</literal> option in the
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>TextCP</term>
<listitem>
<para>
Codepage to be used for rendering the text in X11
output. Some sample values would be 437 (USA, Canada),
850 (Europe), 852 (Central/Eastern Europe), 855
(Cyrillic). For additional suitable values, see e.g. the Linux
kernel's codepage configuration page.
</para>
</listitem>
</varlistentry>
</variablelist>
</sect3>
</sect2>
......
......@@ -135,9 +135,6 @@ WINE REGISTRY Version 2
; Create the desktop window with a double-buffered visual
; (useful to play OpenGL games)
"DesktopDoubleBuffered" = "N"
; Code page used for captions in managed mode
; 0 means default ANSI code page (CP_ACP == 0)
"TextCP" = "0"
; Use this if you have more than one port for video on your setup
; (Wine uses for now the first 'input image' it finds).
;; "XVideoPort" = "43"
......
......@@ -176,6 +176,8 @@ extern "C" {
#define CP_UTF7 65000
#define CP_UTF8 65001
#define CP_UNIXCP 65010 /* Wine extension */
#define WC_DISCARDNS 0x00000010
#define WC_SEPCHARS 0x00000020
#define WC_DEFAULTCHAR 0x00000040
......
......@@ -36,6 +36,7 @@ WINE_DEFAULT_DEBUG_CHANNEL(string);
static const union cptable *ansi_cptable;
static const union cptable *oem_cptable;
static const union cptable *mac_cptable;
static const union cptable *unix_cptable; /* NULL if UTF8 */
static LCID default_lcid = MAKELCID( MAKELANGID(LANG_ENGLISH,SUBLANG_DEFAULT), SORT_DEFAULT );
/* setup default codepage info before we can get at the locale stuff */
......@@ -44,9 +45,11 @@ static void init_codepages(void)
ansi_cptable = wine_cp_get_table( 1252 );
oem_cptable = wine_cp_get_table( 437 );
mac_cptable = wine_cp_get_table( 10000 );
unix_cptable = wine_cp_get_table( 28591 );
assert( ansi_cptable );
assert( oem_cptable );
assert( mac_cptable );
assert( unix_cptable );
}
/* find the table for a given codepage, handling CP_ACP etc. pseudo-codepages */
......@@ -83,21 +86,27 @@ static const union cptable *get_codepage_table( unsigned int codepage )
/* initialize default code pages from locale info */
/* FIXME: should be done in init_codepages, but it can't right now */
/* since it needs KERNEL32 to be loaded for the locale info. */
void CODEPAGE_Init( UINT ansi, UINT oem, UINT mac, LCID lcid )
void CODEPAGE_Init( UINT ansi_cp, UINT oem_cp, UINT mac_cp, UINT unix_cp, LCID lcid )
{
extern void __wine_init_codepages( const union cptable *ansi, const union cptable *oem );
extern void __wine_init_codepages( const union cptable *ansi_cp, const union cptable *oem_cp );
const union cptable *table;
default_lcid = lcid;
if (!ansi_cptable) init_codepages(); /* just in case */
if ((table = wine_cp_get_table( ansi ))) ansi_cptable = table;
if ((table = wine_cp_get_table( oem ))) oem_cptable = table;
if ((table = wine_cp_get_table( mac ))) mac_cptable = table;
if ((table = wine_cp_get_table( ansi_cp ))) ansi_cptable = table;
if ((table = wine_cp_get_table( oem_cp ))) oem_cptable = table;
if ((table = wine_cp_get_table( mac_cp ))) mac_cptable = table;
if (unix_cp == CP_UTF8)
unix_cptable = NULL;
else if ((table = wine_cp_get_table( unix_cp )))
unix_cptable = table;
__wine_init_codepages( ansi_cptable, oem_cptable );
TRACE( "ansi=%03d oem=%03d mac=%03d\n", ansi_cptable->info.codepage,
oem_cptable->info.codepage, mac_cptable->info.codepage );
TRACE( "ansi=%03d oem=%03d mac=%03d unix=%03d\n",
ansi_cptable->info.codepage, oem_cptable->info.codepage,
mac_cptable->info.codepage, unix_cp );
}
/******************************************************************************
......@@ -336,9 +345,16 @@ INT WINAPI MultiByteToWideChar( UINT page, DWORD flags, LPCSTR src, INT srclen,
switch(page)
{
case CP_UTF7:
FIXME("UTF not supported\n");
FIXME("UTF-7 not supported\n");
SetLastError( ERROR_CALL_NOT_IMPLEMENTED );
return 0;
case CP_UNIXCP:
if (unix_cptable)
{
ret = wine_cp_mbstowcs( unix_cptable, flags, src, srclen, dst, dstlen );
break;
}
/* fall through */
case CP_UTF8:
ret = wine_utf8_mbstowcs( flags, src, srclen, dst, dstlen );
break;
......@@ -412,6 +428,14 @@ INT WINAPI WideCharToMultiByte( UINT page, DWORD flags, LPCWSTR src, INT srclen,
FIXME("UTF-7 not supported\n");
SetLastError( ERROR_CALL_NOT_IMPLEMENTED );
return 0;
case CP_UNIXCP:
if (unix_cptable)
{
ret = wine_cp_wcstombs( unix_cptable, flags, src, srclen, dst, dstlen,
defchar, used ? &used_tmp : NULL );
break;
}
/* fall through */
case CP_UTF8:
ret = wine_utf8_wcstombs( src, srclen, dst, dstlen );
break;
......
......@@ -68,7 +68,6 @@ typedef struct
int nTakeFocus;
int nDXGrab;
int nDoubleBuffered;
int nTextCP;
int nXVideoPort;
int nSynchronous;
} X11DRV_DESC;
......
......@@ -214,7 +214,6 @@ int loadConfig (WINECFG_DESC* pCfg)
pCfg->sX11Drv.nTakeFocus = 1;
pCfg->sX11Drv.nDXGrab = 0;
pCfg->sX11Drv.nDoubleBuffered = 0;
pCfg->sX11Drv.nTextCP = 0;
pCfg->sX11Drv.nXVideoPort = 43;
pCfg->sX11Drv.nSynchronous = 1;
......
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