winex11.drv/wintab32[2/5]: Store WTInfo strings as Unicode
internally (resend)
Mikolaj Zalewski
mikolajz at google.com
Wed Sep 12 12:15:10 CDT 2007
-------------- next part --------------
From 41b03c3301a5d922ea64911d7924fc381517d9c9 Mon Sep 17 00:00:00 2001
From: =?utf-8?q?Miko=C5=82aj_Zalewski?= <mikolaj at zalewski.pl>
Date: Wed, 5 Sep 2007 16:37:04 -0700
Subject: [PATCH] winex11.drv/wintab32: Store WTInfo strings as Unicode internally
---
dlls/winex11.drv/winex11.drv.spec | 2 +-
dlls/winex11.drv/wintab.c | 72 +++++++++++++++++++++++++------------
dlls/wintab32/context.c | 14 +++++++-
dlls/wintab32/wintab32.c | 4 +-
dlls/wintab32/wintab_internal.h | 2 +-
5 files changed, 66 insertions(+), 28 deletions(-)
diff --git a/dlls/winex11.drv/winex11.drv.spec b/dlls/winex11.drv/winex11.drv.spec
index b4fcb9b..bf8e21c 100644
--- a/dlls/winex11.drv/winex11.drv.spec
+++ b/dlls/winex11.drv/winex11.drv.spec
@@ -119,7 +119,7 @@
@ cdecl AttachEventQueueToTablet(long) X11DRV_AttachEventQueueToTablet
@ cdecl GetCurrentPacket(ptr) X11DRV_GetCurrentPacket
@ cdecl LoadTabletInfo(long) X11DRV_LoadTabletInfo
-@ cdecl WTInfoA(long long ptr ptr) X11DRV_WTInfoA
+@ cdecl WTInfoW(long long ptr ptr) X11DRV_WTInfoW
# X11 locks
@ cdecl -norelay wine_tsx11_lock()
diff --git a/dlls/winex11.drv/wintab.c b/dlls/winex11.drv/wintab.c
index 8a9ac4a..820a584 100644
--- a/dlls/winex11.drv/wintab.c
+++ b/dlls/winex11.drv/wintab.c
@@ -22,18 +22,24 @@
#include "wine/port.h"
#include <stdlib.h>
+#include <stdarg.h>
#include "windef.h"
+#include "winbase.h"
+#include "winnls.h"
#include "x11drv.h"
#include "wine/library.h"
+#include "wine/unicode.h"
#include "wine/debug.h"
#include "wintab.h"
WINE_DEFAULT_DEBUG_CHANNEL(wintab32);
+#define WT_MAX_NAME_LEN 256
+
typedef struct tagWTI_CURSORS_INFO
{
- CHAR NAME[256];
+ WCHAR NAME[WT_MAX_NAME_LEN];
/* a displayable zero-terminated string containing the name of the
* cursor.
*/
@@ -47,7 +53,8 @@ typedef struct tagWTI_CURSORS_INFO
/* the number of buttons on this cursor. */
BYTE BUTTONBITS;
/* the number of bits of raw button data returned by the hardware.*/
- CHAR BTNNAMES[1024]; /* FIXME: make this dynamic */
+ DWORD cchBTNNAMES;
+ WCHAR *BTNNAMES;
/* a list of zero-terminated strings containing the names of the
* cursor's buttons. The number of names in the list is the same as the
* number of buttons on the cursor. The names are separated by a single
@@ -129,7 +136,7 @@ typedef struct tagWTI_CURSORS_INFO
typedef struct tagWTI_DEVICES_INFO
{
- CHAR NAME[256];
+ WCHAR NAME[WT_MAX_NAME_LEN];
/* a displayable null- terminated string describing the device,
* manufacturer, and revision level.
*/
@@ -191,7 +198,7 @@ typedef struct tagWTI_DEVICES_INFO
/* a 3-element array describing the tablet's rotation range and
* resolution capabilities.
*/
- CHAR PNPID[256];
+ WCHAR PNPID[WT_MAX_NAME_LEN];
/* a null-terminated string containing the devices Plug and Play ID.*/
} WTI_DEVICES_INFO, *LPWTI_DEVICES_INFO;
@@ -233,7 +240,7 @@ static INT button_state[10];
#define CURSORMAX 10
-static LOGCONTEXTA gSysContext;
+static LOGCONTEXTW gSysContext;
static WTI_DEVICES_INFO gSysDevice;
static WTI_CURSORS_INFO gSysCursor[CURSORMAX];
static INT gNumCursors;
@@ -305,8 +312,8 @@ void X11DRV_LoadTabletInfo(HWND hwnddefault)
hwndTabletDefault = hwnddefault;
/* Do base initializaion */
- strcpy(gSysContext.lcName, "Wine Tablet Context");
- strcpy(gSysDevice.NAME,"Wine Tablet Device");
+ MultiByteToWideChar(CP_UTF8, 0, "Wine Tablet Context", -1, gSysContext.lcName, WT_MAX_NAME_LEN);
+ MultiByteToWideChar(CP_UTF8, 0, "Wine Tablet Device", -1, gSysDevice.NAME, WT_MAX_NAME_LEN);
gSysContext.lcOptions = CXO_SYSTEM;
gSysContext.lcLocks = CXL_INSIZE | CXL_INASPECT | CXL_MARGIN |
@@ -337,7 +344,7 @@ void X11DRV_LoadTabletInfo(HWND hwnddefault)
gSysDevice.PKTDATA =
PK_CONTEXT | PK_STATUS | PK_SERIAL_NUMBER| PK_TIME | PK_CURSOR |
PK_BUTTONS | PK_X | PK_Y | PK_NORMAL_PRESSURE | PK_ORIENTATION;
- strcpy(gSysDevice.PNPID,"non-pluginplay");
+ MultiByteToWideChar(CP_UTF8, 0, "non-pluginplay", -1, gSysDevice.PNPID, WT_MAX_NAME_LEN);
wine_tsx11_lock();
@@ -395,7 +402,8 @@ void X11DRV_LoadTabletInfo(HWND hwnddefault)
continue;
}
- strcpy(cursor->NAME,target->name);
+ MultiByteToWideChar(CP_UNIXCP, 0, target->name, -1, cursor->NAME, WT_MAX_NAME_LEN);
+ cursor->NAME[WT_MAX_NAME_LEN - 1] = 0;
cursor->ACTIVE = 1;
cursor->PKTDATA = PK_TIME | PK_CURSOR | PK_BUTTONS | PK_X | PK_Y |
@@ -407,9 +415,9 @@ void X11DRV_LoadTabletInfo(HWND hwnddefault)
cursor->NPBTNMARKS[0] = 0 ;
cursor->NPBTNMARKS[1] = 1 ;
cursor->CAPABILITIES = CRC_MULTIMODE;
- if (strcasecmp(cursor->NAME,"stylus")==0)
+ if (strcasecmp(target->name,"stylus")==0)
cursor->TYPE = 0x4825;
- if (strcasecmp(cursor->NAME,"eraser")==0)
+ if (strcasecmp(target->name,"eraser")==0)
cursor->TYPE = 0xc85a;
@@ -488,16 +496,29 @@ void X11DRV_LoadTabletInfo(HWND hwnddefault)
break;
case ButtonClass:
{
- CHAR *ptr = cursor->BTNNAMES;
+ int cchBuf = 512;
+ int cchPos = 0;
int i;
Button = (XButtonInfoPtr) any;
cursor->BUTTONS = Button->num_buttons;
+ cursor->BTNNAMES = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR)*cchBuf);
for (i = 0; i < cursor->BUTTONS; i++)
{
- strcpy(ptr,cursor->NAME);
- ptr+=8;
+ /* FIXME - these names are probably incorrect */
+ int cch = strlenW(cursor->NAME) + 1;
+ while (cch > cchBuf - cchPos - 1) /* we want one extra byte for the last NUL */
+ {
+ cchBuf *= 2;
+ cursor->BTNNAMES = HeapReAlloc(GetProcessHeap(), 0, cursor->BTNNAMES, sizeof(WCHAR)*cchBuf);
+ }
+
+ strcpyW(cursor->BTNNAMES + cchPos, cursor->NAME);
+ cchPos += cch;
}
+ cursor->BTNNAMES[cchPos++] = 0;
+ cursor->BTNNAMES = HeapReAlloc(GetProcessHeap(), 0, cursor->BTNNAMES, sizeof(WCHAR)*cchPos);
+ cursor->cchBTNNAMES = cchPos;
}
break;
}
@@ -695,10 +716,12 @@ int X11DRV_AttachEventQueueToTablet(HWND hOwner)
X11DRV_expect_error(data->display,Tablet_ErrorHandler,NULL);
for (cur_loop=0; cur_loop < gNumCursors; cur_loop++)
{
+ char cursorNameA[WT_MAX_NAME_LEN];
int event_number=0;
+ WideCharToMultiByte(CP_UNIXCP, 0, gSysCursor[cur_loop].NAME, -1, cursorNameA, WT_MAX_NAME_LEN, NULL, NULL);
for (loop=0; loop < num_devices; loop ++)
- if (strcmp(devices[loop].name,gSysCursor[cur_loop].NAME)==0)
+ if (strncmp(devices[loop].name, cursorNameA, WT_MAX_NAME_LEN)==0)
target = &devices[loop];
TRACE("Opening cursor %i id %i\n",cur_loop,(INT)target->id);
@@ -764,16 +787,16 @@ static inline int CopyTabletData(LPVOID target, LPCVOID src, INT size)
return(size);
}
-static inline int CopyTabletString(LPVOID target, LPCSTR src, INT cchChars, DWORD *cchOnlyCountString)
+static inline int CopyTabletString(LPVOID target, LPCWSTR src, INT cchChars, DWORD *cchOnlyCountString)
{
if (cchChars == -1)
- cchChars = strlen(src)+1;
+ cchChars = strlenW(src)+1;
if (cchOnlyCountString != NULL)
{
*cchOnlyCountString = cchChars;
return 0;
}
- return CopyTabletData(target, src, cchChars * sizeof(CHAR));
+ return CopyTabletData(target, src, cchChars * sizeof(WCHAR));
}
/***********************************************************************
@@ -793,7 +816,7 @@ static inline int CopyTabletString(LPVOID target, LPCSTR src, INT cchChars, DWOR
* lpOutput == NULL signifies the user only wishes to find the size of
* the data.
*/
-UINT X11DRV_WTInfoA(UINT wCategory, UINT nIndex, LPVOID lpOutput, DWORD *cchOnlyCountString)
+UINT X11DRV_WTInfoW(UINT wCategory, UINT nIndex, LPVOID lpOutput, DWORD *cchOnlyCountString)
{
int rc = 0;
LPWTI_CURSORS_INFO tgtcursor;
@@ -819,8 +842,11 @@ UINT X11DRV_WTInfoA(UINT wCategory, UINT nIndex, LPVOID lpOutput, DWORD *cchOnly
rc = sizeof(DWORD);
break;
case IFC_WINTABID:
- rc = CopyTabletString(lpOutput, "Wine Wintab 1.1", -1, cchOnlyCountString);
+ {
+ WCHAR SZ_DRIVER[] = {'W','i','n','e',' ','W','i','n','t','a','b',' ','1','.','1',0};
+ rc = CopyTabletString(lpOutput, SZ_DRIVER, -1, cchOnlyCountString);
break;
+ }
case IFC_SPECVERSION:
version = (0x01) | (0x01 << 8);
rc = CopyTabletData(lpOutput, &version,sizeof(WORD));
@@ -1021,7 +1047,7 @@ UINT X11DRV_WTInfoA(UINT wCategory, UINT nIndex, LPVOID lpOutput, DWORD *cchOnly
break;
case CSR_BTNNAMES:
FIXME("Button Names not returned correctly\n");
- rc = CopyTabletString(lpOutput, tgtcursor->BTNNAMES, -1, cchOnlyCountString);
+ rc = CopyTabletString(lpOutput, tgtcursor->BTNNAMES, tgtcursor->cchBTNNAMES, cchOnlyCountString);
break;
case CSR_BUTTONMAP:
rc = CopyTabletData(lpOutput,&tgtcursor->BUTTONMAP,
@@ -1217,9 +1243,9 @@ void X11DRV_LoadTabletInfo(HWND hwnddefault)
}
/***********************************************************************
- * WTInfoA (X11DRV.@)
+ * WTInfoW (X11DRV.@)
*/
-UINT X11DRV_WTInfoA(UINT wCategory, UINT nIndex, LPVOID lpOutput)
+UINT X11DRV_WTInfoW(UINT wCategory, UINT nIndex, LPVOID lpOutput)
{
return 0;
}
diff --git a/dlls/wintab32/context.c b/dlls/wintab32/context.c
index 1410849..c34c17e 100644
--- a/dlls/wintab32/context.c
+++ b/dlls/wintab32/context.c
@@ -28,6 +28,7 @@
#include "winerror.h"
#include "winbase.h"
#include "winuser.h"
+#include "winnls.h"
#include "wintab.h"
#include "wintab_internal.h"
@@ -353,6 +354,9 @@ static BOOL is_logcontext_category(UINT wCategory)
static UINT get_wtinfo_field(UINT wCategory, UINT nIndex, LPVOID lpOutput)
{
+ DWORD cchString = 0;
+ UINT ret;
+
/* Handle system extents here, as we can use user32.dll code to set them */
if(wCategory == WTI_DEFSYSCTX)
{
@@ -370,7 +374,15 @@ static UINT get_wtinfo_field(UINT wCategory, UINT nIndex, LPVOID lpOutput)
}
}
- return pWTInfoA(wCategory, nIndex, lpOutput, NULL);
+ ret = pWTInfoW(wCategory, nIndex, lpOutput, &cchString);
+ if (cchString > 0)
+ {
+ WCHAR *buf = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR)*cchString);
+ pWTInfoW(wCategory, nIndex, buf, NULL);
+ ret = WideCharToMultiByte(CP_ACP, 0, buf, cchString, lpOutput, lpOutput ? 2*cchString: 0, NULL, NULL);
+ HeapFree(GetProcessHeap(), 0, buf);
+ }
+ return ret;
}
/***********************************************************************
diff --git a/dlls/wintab32/wintab32.c b/dlls/wintab32/wintab32.c
index ba9db9c..3719add 100644
--- a/dlls/wintab32/wintab32.c
+++ b/dlls/wintab32/wintab32.c
@@ -39,7 +39,7 @@ CRITICAL_SECTION csTablet;
int (*pLoadTabletInfo)(HWND hwnddefault) = NULL;
int (*pGetCurrentPacket)(LPWTPACKET packet) = NULL;
int (*pAttachEventQueueToTablet)(HWND hOwner) = NULL;
-UINT (*pWTInfoA)(UINT wCategory, UINT nIndex, LPVOID lpOutput, DWORD *cchOnlyCountString) = NULL;
+UINT (*pWTInfoW)(UINT wCategory, UINT nIndex, LPVOID lpOutput, DWORD *cchOnlyCountString) = NULL;
static LRESULT WINAPI TABLET_WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam,
LPARAM lParam);
@@ -81,7 +81,7 @@ BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpReserved)
pLoadTabletInfo = (void *)GetProcAddress(hx11drv, "LoadTabletInfo");
pAttachEventQueueToTablet = (void *)GetProcAddress(hx11drv, "AttachEventQueueToTablet");
pGetCurrentPacket = (void *)GetProcAddress(hx11drv, "GetCurrentPacket");
- pWTInfoA = (void *)GetProcAddress(hx11drv, "WTInfoA");
+ pWTInfoW = (void *)GetProcAddress(hx11drv, "WTInfoW");
TABLET_Register();
hwndDefault = CreateWindowW(WC_TABLETCLASSNAME, name,
WS_POPUPWINDOW,0,0,0,0,0,0,hInstDLL,0);
diff --git a/dlls/wintab32/wintab_internal.h b/dlls/wintab32/wintab_internal.h
index b1c6297..ad06a16 100644
--- a/dlls/wintab32/wintab_internal.h
+++ b/dlls/wintab32/wintab_internal.h
@@ -155,7 +155,7 @@ LPOPENCONTEXT FindOpenContext(HWND hwnd);
extern int (*pLoadTabletInfo)(HWND hwnddefault);
extern int (*pGetCurrentPacket)(LPWTPACKET packet);
extern int (*pAttachEventQueueToTablet)(HWND hOwner);
-extern UINT (*pWTInfoA)(UINT wCategory, UINT nIndex, LPVOID lpOutput, DWORD *cchOnlyCountString);
+extern UINT (*pWTInfoW)(UINT wCategory, UINT nIndex, LPVOID lpOutput, DWORD *cchOnlyCountString);
extern HWND hwndDefault;
extern CRITICAL_SECTION csTablet;
--
1.4.4.2
More information about the wine-patches
mailing list