wintab32[4/4]: store the context internally as Unicode, implement WTOpenW and WTGetW

Mikolaj Zalewski mikolajz at google.com
Fri Aug 31 13:14:33 CDT 2007


-------------- next part --------------
From b860cb7c4f4eec7ecde2b88acbbafd3897842da3 Mon Sep 17 00:00:00 2001
From: Mikolaj Zalewski <mikolaj at zalewski.pl>
Date: Fri, 31 Aug 2007 11:04:45 -0700
Subject: [PATCH] wintab32: store the context internally as Unicode, implement WTOpenW and WTGetW
---
 dlls/wintab32/context.c         |   55 ++++++++++++++++++++++++++++-----------
 dlls/wintab32/wintab_internal.h |    2 +
 2 files changed, 40 insertions(+), 17 deletions(-)

diff --git a/dlls/wintab32/context.c b/dlls/wintab32/context.c
index aaa6744..a1fc2a4 100644
--- a/dlls/wintab32/context.c
+++ b/dlls/wintab32/context.c
@@ -27,6 +27,7 @@ #include <stdarg.h>
 #include "windef.h"
 #include "winerror.h"
 #include "winbase.h"
+#include "winnls.h"
 #include "winuser.h"
 
 #include "wintab.h"
@@ -45,6 +46,22 @@ static BOOL gLoaded;
 static LPOPENCONTEXT gOpenContexts;
 static HCTX gTopContext = (HCTX)0xc00;
 
+static void LOGCONTEXTAtoW(const LOGCONTEXTA *in, LOGCONTEXTW *out)
+{
+    MultiByteToWideChar(CP_ACP, 0, in->lcName, LCNAMELEN, out->lcName, LCNAMELEN);
+    out->lcName[LCNAMELEN - 1] = 0;
+    /* we use the fact that the fields after lcName are the same in LOGCONTEXTA and W */
+    memcpy(&out->lcOptions, &in->lcOptions, sizeof(LOGCONTEXTA) - FIELD_OFFSET(LOGCONTEXTA, lcOptions));
+}
+
+static void LOGCONTEXTWtoA(const LOGCONTEXTW *in, LOGCONTEXTA *out)
+{
+    WideCharToMultiByte(CP_ACP, 0, in->lcName, LCNAMELEN, out->lcName, LCNAMELEN, NULL, NULL);
+    out->lcName[LCNAMELEN - 1] = 0;
+    /* we use the fact that the fields after lcName are the same in LOGCONTEXTA and W */
+    memcpy(&out->lcOptions, &in->lcOptions, sizeof(LOGCONTEXTW) - FIELD_OFFSET(LOGCONTEXTW, lcOptions));
+}
+
 static char* DUMPBITS(int x, char* buf)
 {
     strcpy(buf,"{");
@@ -87,7 +104,7 @@ static inline void DUMPPACKET(WTPACKET p
         packet.pkRotation.roRoll, packet.pkRotation.roYaw);
 }
 
-static inline void DUMPCONTEXT(LOGCONTEXTA lc)
+static inline void DUMPCONTEXT(LOGCONTEXTW lc)
 {
         CHAR mmsg[4000];
         CHAR bits[100];
@@ -95,7 +112,7 @@ static inline void DUMPCONTEXT(LOGCONTEX
         CHAR bits2[100];
 
         sprintf(mmsg,"%s, %x, %x, %x, %x, %x, %x, %x%s, %x%s, %x%s, %x, %x, %i, %i, %i, %i ,%i, %i, %i, %i, %i,%i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i %i %i",
-    debugstr_a(lc.lcName), lc.lcOptions, lc.lcStatus, lc.lcLocks, lc.lcMsgBase,
+    wine_dbgstr_w(lc.lcName), lc.lcOptions, lc.lcStatus, lc.lcLocks, lc.lcMsgBase,
 lc.lcDevice, lc.lcPktRate, (UINT)lc.lcPktData, DUMPBITS(lc.lcPktData,bits),
 (UINT)lc.lcPktMode, DUMPBITS(lc.lcPktMode,bits1), (UINT)lc.lcMoveMask,
 DUMPBITS(lc.lcMoveMask,bits2), (INT)lc.lcBtnDnMask, (INT)lc.lcBtnUpMask,
@@ -416,9 +433,9 @@ UINT WINAPI WTInfoW(UINT wCategory, UINT
 }
 
 /***********************************************************************
- *		WTOpenA (WINTAB32.21)
+ *		WTOpenW (WINTAB32.2021)
  */
-HCTX WINAPI WTOpenA(HWND hWnd, LPLOGCONTEXTA lpLogCtx, BOOL fEnable)
+HCTX WINAPI WTOpenW(HWND hWnd, LPLOGCONTEXTW lpLogCtx, BOOL fEnable)
 {
     LPOPENCONTEXT newcontext;
 
@@ -426,7 +443,7 @@ HCTX WINAPI WTOpenA(HWND hWnd, LPLOGCONT
     DUMPCONTEXT(*lpLogCtx);
 
     newcontext = HeapAlloc(GetProcessHeap(), 0 , sizeof(OPENCONTEXT));
-    memcpy(&(newcontext->context),lpLogCtx,sizeof(LOGCONTEXTA));
+    memcpy(&(newcontext->context),lpLogCtx,sizeof(LOGCONTEXTW));
     newcontext->hwndOwner = hWnd;
     newcontext->enabled = fEnable;
     newcontext->ActiveCursor = -1;
@@ -455,15 +472,14 @@ HCTX WINAPI WTOpenA(HWND hWnd, LPLOGCONT
 }
 
 /***********************************************************************
- *		WTOpenW (WINTAB32.1021)
+ *		WTOpenA (WINTAB32.21)
  */
-HCTX WINAPI WTOpenW(HWND hWnd, LPLOGCONTEXTW lpLogCtx, BOOL fEnable)
+HCTX WINAPI WTOpenA(HWND hWnd, LPLOGCONTEXTA lpLogCtx, BOOL fEnable)
 {
-    FIXME("(%p, %p, %u): stub\n", hWnd, lpLogCtx, fEnable);
-
-    SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
-
-    return NULL;
+    LOGCONTEXTW logCtxW;
+    
+    LOGCONTEXTAtoW(lpLogCtx, &logCtxW);
+    return WTOpenW(hWnd, &logCtxW, fEnable);
 }
 
 /***********************************************************************
@@ -650,7 +666,7 @@ BOOL WINAPI WTGetA(HCTX hCtx, LPLOGCONTE
 
     EnterCriticalSection(&csTablet);
     context = TABLET_FindOpenContext(hCtx);
-    memmove(lpLogCtx,&context->context,sizeof(LOGCONTEXTA));
+    LOGCONTEXTWtoA(&context->context, lpLogCtx);
     LeaveCriticalSection(&csTablet);
 
     return TRUE;
@@ -661,11 +677,18 @@ BOOL WINAPI WTGetA(HCTX hCtx, LPLOGCONTE
  */
 BOOL WINAPI WTGetW(HCTX hCtx, LPLOGCONTEXTW lpLogCtx)
 {
-    FIXME("(%p, %p): stub\n", hCtx, lpLogCtx);
+    LPOPENCONTEXT context;
 
-    SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
+    TRACE("(%p, %p)\n", hCtx, lpLogCtx);
 
-    return FALSE;
+    if (!hCtx) return 0;
+
+    EnterCriticalSection(&csTablet);
+    context = TABLET_FindOpenContext(hCtx);
+    memmove(lpLogCtx,&context->context,sizeof(LOGCONTEXTW));
+    LeaveCriticalSection(&csTablet);
+
+    return TRUE;
 }
 
 /***********************************************************************
diff --git a/dlls/wintab32/wintab_internal.h b/dlls/wintab32/wintab_internal.h
index 5db60d3..44cff3c 100644
--- a/dlls/wintab32/wintab_internal.h
+++ b/dlls/wintab32/wintab_internal.h
@@ -136,7 +136,7 @@ typedef struct tagWTPACKET {
 typedef struct tagOPENCONTEXT
 {
     HCTX        handle;
-    LOGCONTEXTA context;
+    LOGCONTEXTW context;
     HWND        hwndOwner;
     BOOL        enabled;
     INT         ActiveCursor;
-- 
1.4.1


More information about the wine-patches mailing list