static void X11DRV_ImmSetInternalString(DWORD dwOffset, DWORD selLength, LPWSTR lpComp, DWORD dwCompLen) { /* Composition strings are edited in chunks */ unsigned int byte_length = dwCompLen * sizeof(WCHAR); unsigned int byte_offset = dwOffset * sizeof(WCHAR); unsigned int byte_selection = selLength * sizeof(WCHAR); int byte_expansion = byte_length - byte_selection; LPBYTE ptr_new; TRACE("( %i, %i, %p, %d):\n", dwOffset, selLength, lpComp, dwCompLen ); if (byte_expansion + dwCompStringLength >= dwCompStringSize) { if (CompositionString) ptr_new = HeapReAlloc(GetProcessHeap(), 0, CompositionString, dwCompStringSize + byte_expansion); else ptr_new = HeapAlloc(GetProcessHeap(), 0, dwCompStringSize + byte_expansion); if (ptr_new == NULL) { ERR("Couldn't expand composition string buffer\n"); return; } CompositionString = ptr_new; dwCompStringSize += byte_expansion; } ptr_new = CompositionString + byte_offset; memmove(ptr_new + byte_length, ptr_new + byte_selection, dwCompStringLength - byte_offset - byte_selection); if (lpComp) memcpy(ptr_new, lpComp, byte_length); dwCompStringLength += byte_expansion; IME_SetCompositionString(SCS_SETSTR, CompositionString, dwCompStringLength, NULL, 0); }
static BOOL X11DRV_ImmSetInternalString(DWORD dwIndex, DWORD dwOffset, DWORD selLength, LPWSTR lpComp, DWORD dwCompLen) { /* Composition strings are edited in chunks */ unsigned int byte_length = dwCompLen * sizeof(WCHAR); unsigned int byte_offset = dwOffset * sizeof(WCHAR); unsigned int byte_selection = selLength * sizeof(WCHAR); BOOL rc = FALSE; TRACE("( %i, %i, %d, %p, %d):\n", dwOffset, selLength, dwIndex, lpComp, dwCompLen ); if (dwIndex == GCS_COMPSTR) { unsigned int i,j; LPBYTE ptr_new; LPBYTE ptr_old; if ((dwCompLen == 0) && (selLength == 0)) { /* DO Nothing */ } /* deletion occurred */ else if ((dwCompLen== 0) && (selLength != 0)) { if (dwCompStringLength) { for (i = 0; i < byte_selection; i++) { if (byte_offset+byte_selection+i < dwCompStringLength) { CompositionString[byte_offset + i] = CompositionString[byte_offset + byte_selection + i]; } else CompositionString[byte_offset + i] = 0; } /* clean up the end */ dwCompStringLength -= byte_selection; i = dwCompStringLength; while (i < dwCompStringSize) { CompositionString[i++] = 0; } } } else { int byte_expansion = byte_length - byte_selection; if (byte_expansion + dwCompStringLength >= dwCompStringSize) { if (CompositionString) CompositionString = HeapReAlloc(GetProcessHeap(), 0, CompositionString, dwCompStringSize + byte_expansion); else CompositionString = HeapAlloc(GetProcessHeap(), 0, dwCompStringSize + byte_expansion); memset(&(CompositionString[dwCompStringSize]), 0, byte_expansion); dwCompStringSize += byte_expansion; } ptr_new = ((LPBYTE)lpComp); ptr_old = CompositionString + byte_offset + byte_selection; dwCompStringLength += byte_expansion; for (j=0,i = byte_offset; i < dwCompStringSize; i++) { if (j < byte_length) { CompositionString[i] = ptr_new[j++]; } else { if (ptr_old < CompositionString + dwCompStringSize) { CompositionString[i] = *ptr_old; ptr_old++; } else CompositionString[i] = 0; } } } rc = IME_SetCompositionString(SCS_SETSTR, (LPWSTR)CompositionString, dwCompStringLength, NULL, 0); } else if ((dwIndex == GCS_RESULTSTR) && (lpComp) && (dwCompLen)) { if (dwResultStringSize) HeapFree(GetProcessHeap(),0,ResultString); dwResultStringSize= byte_length; ResultString= HeapAlloc(GetProcessHeap(),0,byte_length); memcpy(ResultString,lpComp,byte_length); rc = IME_SetCompositionString(SCS_SETSTR, (LPWSTR)ResultString, dwResultStringSize, NULL, 0); IME_NotifyIME( NI_COMPOSITIONSTR, CPS_COMPLETE, 0); } return rc; }