public static bool GetResult(IntPtr hwnd, uint lParam, out string text) { var hIMC = ImeNative.ImmGetContext(hwnd); var ret = GetString(hIMC, lParam, ImeNative.GCS_RESULTSTR, out text); ImeNative.ImmReleaseContext(hwnd, hIMC); return(ret); }
public static bool GetComposition(IntPtr hwnd, uint lParam, List <CompositionUnderline> underlines, ref int compositionStart, out string text) { var hIMC = ImeNative.ImmGetContext(hwnd); bool ret = GetString(hIMC, lParam, ImeNative.GCS_COMPSTR, out text); if (ret) { GetCompositionInfo(hwnd, lParam, text, underlines, ref compositionStart); } ImeNative.ImmReleaseContext(hwnd, hIMC); return(ret); }
private static void GetCompositionInfo(IntPtr hwnd, uint lParam, string text, List <CompositionUnderline> underlines, ref int compositionStart) { var hIMC = ImeNative.ImmGetContext(hwnd); underlines.Clear(); int targetStart = text.Length; int targetEnd = text.Length; if (IsParam(lParam, ImeNative.GCS_COMPATTR)) { GetCompositionSelectionRange(hIMC, ref targetStart, ref targetEnd); } // Retrieve the selection range information. If CS_NOMOVECARET is specified // it means the cursor should not be moved and we therefore place the caret at // the beginning of the composition string. Otherwise we should honour the // GCS_CURSORPOS value if it's available. if (!IsParam(lParam, ImeNative.CS_NOMOVECARET) && IsParam(lParam, ImeNative.GCS_CURSORPOS)) { // IMM32 does not support non-zero-width selection in a composition. So // always use the caret position as selection range. int cursor = (int)ImeNative.ImmGetCompositionString(hIMC, ImeNative.GCS_CURSORPOS, null, 0); compositionStart = cursor; } else { compositionStart = 0; } if (IsParam(lParam, ImeNative.GCS_COMPCLAUSE)) { GetCompositionUnderlines(hIMC, targetStart, targetEnd, underlines); } if (underlines.Count == 0) { var range = new Range(); bool thick = false; if (targetStart > 0) { range = new Range(0, targetStart); } if (targetEnd > targetStart) { range = new Range(targetStart, targetEnd); thick = true; } if (targetEnd < text.Length) { range = new Range(targetEnd, text.Length); } underlines.Add(new CompositionUnderline(range, ColorUNDERLINE, ColorBKCOLOR, thick)); } ImeNative.ImmReleaseContext(hwnd, hIMC); }
private static void GetCompositionInfo(IntPtr hwnd, uint lParam, string text, List <CompositionUnderline> underlines, ref int compositionStart) { var hIMC = ImeNative.ImmGetContext(hwnd); underlines.Clear(); byte[] attributes = null; int targetStart = text.Length; int targetEnd = text.Length; if (IsParam(lParam, ImeNative.GCS_COMPATTR)) { attributes = GetCompositionSelectionRange(hIMC, ref targetStart, ref targetEnd); } // Retrieve the selection range information. If CS_NOMOVECARET is specified // it means the cursor should not be moved and we therefore place the caret at // the beginning of the composition string. Otherwise we should honour the // GCS_CURSORPOS value if it's available. if (!IsParam(lParam, ImeNative.CS_NOMOVECARET) && IsParam(lParam, ImeNative.GCS_CURSORPOS)) { // IMM32 does not support non-zero-width selection in a composition. So // always use the caret position as selection range. int cursor = (int)ImeNative.ImmGetCompositionString(hIMC, ImeNative.GCS_CURSORPOS, null, 0); compositionStart = cursor; } else { compositionStart = 0; } if (attributes != null && // character before ((compositionStart > 0 && (compositionStart - 1) < attributes.Length && attributes[compositionStart - 1] == ImeNative.ATTR_INPUT) || // character after (compositionStart >= 0 && compositionStart < attributes.Length && attributes[compositionStart] == ImeNative.ATTR_INPUT))) { // as MS does with their ime implementation we should only use the GCS_CURSORPOS if the character // before or after is new input. // https://referencesource.microsoft.com/#PresentationFramework/src/Framework/System/windows/Documents/ImmComposition.cs,1079 } else { compositionStart = text.Length; } if (IsParam(lParam, ImeNative.GCS_COMPCLAUSE)) { GetCompositionUnderlines(hIMC, targetStart, targetEnd, underlines); } if (underlines.Count == 0) { var range = new Range(); bool thick = false; if (targetStart > 0) { range = new Range(0, targetStart); } if (targetEnd > targetStart) { range = new Range(targetStart, targetEnd); thick = true; } if (targetEnd < text.Length) { range = new Range(targetEnd, text.Length); } underlines.Add(new CompositionUnderline(range, ColorUNDERLINE, ColorBKCOLOR, thick)); } ImeNative.ImmReleaseContext(hwnd, hIMC); }