Same as https://gitlab.winehq.org/wine/wine/-/merge_requests/2563 but on winex11 side.
From: Rémi Bernon rbernon@codeweavers.com
--- dlls/winex11.drv/ime.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-)
diff --git a/dlls/winex11.drv/ime.c b/dlls/winex11.drv/ime.c index 9c0894717ad..c494aaed2be 100644 --- a/dlls/winex11.drv/ime.c +++ b/dlls/winex11.drv/ime.c @@ -987,7 +987,7 @@ static void PaintDefaultIMEWnd(HIMC hIMC, HWND hwnd) INT offX=0, offY=0; LPINPUTCONTEXT lpIMC;
- lpIMC = LockRealIMC(hIMC); + lpIMC = ImmLockIMC(hIMC); if (lpIMC == NULL) return;
@@ -1101,7 +1101,7 @@ static void PaintDefaultIMEWnd(HIMC hIMC, HWND hwnd) ImmUnlockIMCC(lpIMC->hCompStr);
EndPaint(hwnd,&ps); - UnlockRealIMC(hIMC); + ImmUnlockIMC(hIMC); }
static void UpdateDefaultIMEWindow(HIMC hIMC, HWND hwnd) @@ -1109,7 +1109,7 @@ static void UpdateDefaultIMEWindow(HIMC hIMC, HWND hwnd) LPCOMPOSITIONSTRING compstr; LPINPUTCONTEXT lpIMC;
- lpIMC = LockRealIMC(hIMC); + lpIMC = ImmLockIMC(hIMC); if (lpIMC == NULL) return;
@@ -1130,7 +1130,7 @@ static void UpdateDefaultIMEWindow(HIMC hIMC, HWND hwnd) ImmUnlockIMCC(lpIMC->hCompStr);
lpIMC->hWnd = GetFocus(); - UnlockRealIMC(hIMC); + ImmUnlockIMC(hIMC); }
static void DefaultIMEComposition(HIMC hIMC, HWND hwnd, LPARAM lParam) @@ -1214,8 +1214,6 @@ static LRESULT WINAPI IME_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, */
hIMC = (HIMC)GetWindowLongPtrW(hwnd,IMMGWL_IMC); - if (!hIMC) - hIMC = RealIMC(FROM_X11);
/* if we have no hIMC there are many messages we cannot process */ if (hIMC == NULL) @@ -1244,14 +1242,14 @@ static LRESULT WINAPI IME_WindowProc(HWND hwnd, UINT msg, WPARAM wParam,
SetWindowTextA(hwnd,"Wine Ime Active");
- lpIMC = LockRealIMC(hIMC); + lpIMC = ImmLockIMC(hIMC); if (lpIMC) { myPrivate = ImmLockIMCC(lpIMC->hPrivate); myPrivate->hwndDefault = hwnd; ImmUnlockIMCC(lpIMC->hPrivate); } - UnlockRealIMC(hIMC); + ImmUnlockIMC(hIMC);
return TRUE; }
From: Rémi Bernon rbernon@codeweavers.com
--- dlls/winex11.drv/ime.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-)
diff --git a/dlls/winex11.drv/ime.c b/dlls/winex11.drv/ime.c index c494aaed2be..8c7dac56251 100644 --- a/dlls/winex11.drv/ime.c +++ b/dlls/winex11.drv/ime.c @@ -1104,14 +1104,9 @@ static void PaintDefaultIMEWnd(HIMC hIMC, HWND hwnd) ImmUnlockIMC(hIMC); }
-static void UpdateDefaultIMEWindow(HIMC hIMC, HWND hwnd) +static void UpdateDefaultIMEWindow(INPUTCONTEXT *lpIMC, HWND hwnd) { LPCOMPOSITIONSTRING compstr; - LPINPUTCONTEXT lpIMC; - - lpIMC = ImmLockIMC(hIMC); - if (lpIMC == NULL) - return;
if (lpIMC->hCompStr) compstr = ImmLockIMCC(lpIMC->hCompStr); @@ -1130,20 +1125,25 @@ static void UpdateDefaultIMEWindow(HIMC hIMC, HWND hwnd) ImmUnlockIMCC(lpIMC->hCompStr);
lpIMC->hWnd = GetFocus(); - ImmUnlockIMC(hIMC); }
static void DefaultIMEComposition(HIMC hIMC, HWND hwnd, LPARAM lParam) { + INPUTCONTEXT *ctx; TRACE("IME message WM_IME_COMPOSITION 0x%Ix\n", lParam); - if (!(lParam & GCS_RESULTSTR)) - UpdateDefaultIMEWindow(hIMC, hwnd); + if (lParam & GCS_RESULTSTR) return; + if (!(ctx = ImmLockIMC( hIMC ))) return; + UpdateDefaultIMEWindow( ctx, hwnd ); + ImmUnlockIMC(hIMC); }
static void DefaultIMEStartComposition(HIMC hIMC, HWND hwnd ) { + INPUTCONTEXT *ctx; TRACE("IME message WM_IME_STARTCOMPOSITION\n"); - UpdateDefaultIMEWindow(hIMC, hwnd); + if (!(ctx = ImmLockIMC( hIMC ))) return; + UpdateDefaultIMEWindow( ctx, hwnd ); + ImmUnlockIMC(hIMC); }
static LRESULT ImeHandleNotify(HIMC hIMC, HWND hwnd, UINT msg, WPARAM wParam,
From: Rémi Bernon rbernon@codeweavers.com
--- dlls/winex11.drv/ime.c | 60 +++++++++++++++++++++++------------------- 1 file changed, 33 insertions(+), 27 deletions(-)
diff --git a/dlls/winex11.drv/ime.c b/dlls/winex11.drv/ime.c index 8c7dac56251..050f273cf88 100644 --- a/dlls/winex11.drv/ime.c +++ b/dlls/winex11.drv/ime.c @@ -70,6 +70,27 @@ static UINT WM_MSIME_RECONVERT; static UINT WM_MSIME_QUERYPOSITION; static UINT WM_MSIME_DOCUMENTFEED;
+static WCHAR *input_context_get_comp_str( INPUTCONTEXT *ctx, BOOL result, UINT *length ) +{ + COMPOSITIONSTRING *string; + WCHAR *text = NULL; + UINT len, off; + + if (!(string = ImmLockIMCC( ctx->hCompStr ))) return NULL; + len = result ? string->dwResultStrLen : string->dwCompStrLen; + off = result ? string->dwResultStrOffset : string->dwCompStrOffset; + + if (len && off && (text = malloc( (len + 1) * sizeof(WCHAR) ))) + { + memcpy( text, (BYTE *)string + off, len * sizeof(WCHAR) ); + text[len] = 0; + *length = len; + } + + ImmUnlockIMCC( ctx->hCompStr ); + return text; +} + static LRESULT WINAPI IME_WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
@@ -659,11 +680,9 @@ BOOL WINAPI NotifyIME(HIMC hIMC, DWORD dwAction, DWORD dwIndex, DWORD dwValue) case CPS_COMPLETE: { HIMCC newCompStr; - DWORD cplen = 0; - LPWSTR cpstr; - LPCOMPOSITIONSTRING cs = NULL; - LPBYTE cdata = NULL; LPIMEPRIVATE myPrivate; + WCHAR *str; + UINT len;
TRACE("CPS_COMPLETE\n");
@@ -673,20 +692,12 @@ BOOL WINAPI NotifyIME(HIMC hIMC, DWORD dwAction, DWORD dwIndex, DWORD dwValue) ImmDestroyIMCC(lpIMC->hCompStr); lpIMC->hCompStr = newCompStr;
- if (lpIMC->hCompStr) - { - cdata = ImmLockIMCC(lpIMC->hCompStr); - cs = (LPCOMPOSITIONSTRING)cdata; - cplen = cs->dwCompStrLen; - cpstr = (LPWSTR)&(cdata[cs->dwCompStrOffset]); - ImmUnlockIMCC(lpIMC->hCompStr); - } myPrivate = ImmLockIMCC(lpIMC->hPrivate); - if (cplen > 0) + if ((str = input_context_get_comp_str( lpIMC, FALSE, &len ))) { - WCHAR param = cpstr[0]; + WCHAR param = str[0];
- newCompStr = updateResultStr(lpIMC->hCompStr, cpstr, cplen); + newCompStr = updateResultStr( lpIMC->hCompStr, str, len ); ImmDestroyIMCC(lpIMC->hCompStr); lpIMC->hCompStr = newCompStr; newCompStr = updateCompStr(lpIMC->hCompStr, NULL, 0); @@ -700,6 +711,7 @@ BOOL WINAPI NotifyIME(HIMC hIMC, DWORD dwAction, DWORD dwIndex, DWORD dwValue) GCS_RESULTSTR|GCS_RESULTCLAUSE);
GenerateIMEMessage(hIMC,WM_IME_ENDCOMPOSITION, 0, 0); + free( str ); } else if (myPrivate->bInComposition) GenerateIMEMessage(hIMC,WM_IME_ENDCOMPOSITION, 0, 0); @@ -980,12 +992,12 @@ static void PaintDefaultIMEWnd(HIMC hIMC, HWND hwnd) PAINTSTRUCT ps; RECT rect; HDC hdc; - LPCOMPOSITIONSTRING compstr; - LPBYTE compdata = NULL; HMONITOR monitor; MONITORINFO mon_info; INT offX=0, offY=0; LPINPUTCONTEXT lpIMC; + WCHAR *str; + UINT len;
lpIMC = ImmLockIMC(hIMC); if (lpIMC == NULL) @@ -996,18 +1008,13 @@ static void PaintDefaultIMEWnd(HIMC hIMC, HWND hwnd) GetClientRect(hwnd,&rect); FillRect(hdc, &rect, (HBRUSH)(COLOR_WINDOW + 1));
- compdata = ImmLockIMCC(lpIMC->hCompStr); - compstr = (LPCOMPOSITIONSTRING)compdata; - - if (compstr->dwCompStrLen && compstr->dwCompStrOffset) + if ((str = input_context_get_comp_str( lpIMC, FALSE, &len ))) { SIZE size; POINT pt; HFONT oldfont = NULL; - LPWSTR CompString; LPIMEPRIVATE myPrivate;
- CompString = (LPWSTR)(compdata + compstr->dwCompStrOffset); myPrivate = ImmLockIMCC(lpIMC->hPrivate);
if (myPrivate->textfont) @@ -1015,7 +1022,7 @@ static void PaintDefaultIMEWnd(HIMC hIMC, HWND hwnd)
ImmUnlockIMCC(lpIMC->hPrivate);
- GetTextExtentPoint32W(hdc, CompString, compstr->dwCompStrLen, &size); + GetTextExtentPoint32W( hdc, str, len, &size ); pt.x = size.cx; pt.y = size.cy; LPtoDP(hdc,&pt,1); @@ -1092,14 +1099,13 @@ static void PaintDefaultIMEWnd(HIMC hIMC, HWND hwnd)
SetWindowPos(hwnd, HWND_TOPMOST, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, SWP_NOACTIVATE);
- TextOutW(hdc, offX,offY, CompString, compstr->dwCompStrLen); + TextOutW( hdc, offX, offY, str, len );
if (oldfont) SelectObject(hdc,oldfont); + free( str ); }
- ImmUnlockIMCC(lpIMC->hCompStr); - EndPaint(hwnd,&ps); ImmUnlockIMC(hIMC); }
From: Rémi Bernon rbernon@codeweavers.com
--- dlls/winex11.drv/ime.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-)
diff --git a/dlls/winex11.drv/ime.c b/dlls/winex11.drv/ime.c index 050f273cf88..a499c8d9dd6 100644 --- a/dlls/winex11.drv/ime.c +++ b/dlls/winex11.drv/ime.c @@ -49,7 +49,8 @@ WINE_DEFAULT_DEBUG_CHANNEL(imm);
#define FROM_X11 ((HIMC)0xcafe1337)
-typedef struct _IMEPRIVATE { +typedef struct ime_private +{ BOOL bInComposition; BOOL bInternalState; HFONT textfont; @@ -91,6 +92,16 @@ static WCHAR *input_context_get_comp_str( INPUTCONTEXT *ctx, BOOL result, UINT * return text; }
+static HFONT input_context_select_ui_font( INPUTCONTEXT *ctx, HDC hdc ) +{ + struct ime_private *priv; + HFONT font = NULL; + if (!(priv = ImmLockIMCC( ctx->hPrivate ))) return NULL; + if (priv->textfont) font = SelectObject( hdc, priv->textfont ); + ImmUnlockIMCC( ctx->hPrivate ); + return font; +} + static LRESULT WINAPI IME_WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
@@ -1010,17 +1021,9 @@ static void PaintDefaultIMEWnd(HIMC hIMC, HWND hwnd)
if ((str = input_context_get_comp_str( lpIMC, FALSE, &len ))) { + HFONT font = input_context_select_ui_font( lpIMC, hdc ); SIZE size; POINT pt; - HFONT oldfont = NULL; - LPIMEPRIVATE myPrivate; - - myPrivate = ImmLockIMCC(lpIMC->hPrivate); - - if (myPrivate->textfont) - oldfont = SelectObject(hdc,myPrivate->textfont); - - ImmUnlockIMCC(lpIMC->hPrivate);
GetTextExtentPoint32W( hdc, str, len, &size ); pt.x = size.cx; @@ -1101,8 +1104,7 @@ static void PaintDefaultIMEWnd(HIMC hIMC, HWND hwnd)
TextOutW( hdc, offX, offY, str, len );
- if (oldfont) - SelectObject(hdc,oldfont); + if (font) SelectObject( hdc, font ); free( str ); }
The plan here, and with https://gitlab.winehq.org/wine/wine/-/merge_requests/2563 is to create the helpers now to use the opportunity of cleaning up a bit the code where they are used, in order to minimize the diff when moving code to imm32.