|
|
|
@ -19,11 +19,10 @@ using ICSharpCode.AvalonEdit.Rendering;
@@ -19,11 +19,10 @@ using ICSharpCode.AvalonEdit.Rendering;
|
|
|
|
|
|
|
|
|
|
namespace ICSharpCode.AvalonEdit.Editing |
|
|
|
|
{ |
|
|
|
|
class ImeSupport : IDisposable |
|
|
|
|
class ImeSupport |
|
|
|
|
{ |
|
|
|
|
TextArea textArea; |
|
|
|
|
readonly TextArea textArea; |
|
|
|
|
IntPtr currentContext; |
|
|
|
|
IntPtr previousContext; |
|
|
|
|
HwndSource hwndSource; |
|
|
|
|
|
|
|
|
|
public ImeSupport(TextArea textArea) |
|
|
|
@ -32,47 +31,29 @@ namespace ICSharpCode.AvalonEdit.Editing
@@ -32,47 +31,29 @@ namespace ICSharpCode.AvalonEdit.Editing
|
|
|
|
|
throw new ArgumentNullException("textArea"); |
|
|
|
|
this.textArea = textArea; |
|
|
|
|
InputMethod.SetIsInputMethodSuspended(this.textArea, true); |
|
|
|
|
textArea.GotKeyboardFocus += TextAreaGotKeyboardFocus; |
|
|
|
|
textArea.LostKeyboardFocus += TextAreaLostKeyboardFocus; |
|
|
|
|
textArea.OptionChanged += TextAreaOptionChanged; |
|
|
|
|
currentContext = IntPtr.Zero; |
|
|
|
|
previousContext = IntPtr.Zero; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void TextAreaOptionChanged(object sender, PropertyChangedEventArgs e) |
|
|
|
|
{ |
|
|
|
|
if (e.PropertyName == "EnableImeSupport" && textArea.IsKeyboardFocusWithin) { |
|
|
|
|
if (e.PropertyName == "EnableImeSupport" && textArea.IsKeyboardFocused) { |
|
|
|
|
CreateContext(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void Dispose() |
|
|
|
|
{ |
|
|
|
|
if (textArea != null) { |
|
|
|
|
textArea.GotKeyboardFocus -= TextAreaGotKeyboardFocus; |
|
|
|
|
textArea.LostKeyboardFocus -= TextAreaLostKeyboardFocus; |
|
|
|
|
textArea.OptionChanged -= TextAreaOptionChanged; |
|
|
|
|
textArea = null; |
|
|
|
|
} |
|
|
|
|
ClearContext(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void ClearContext() |
|
|
|
|
{ |
|
|
|
|
if (hwndSource != null) { |
|
|
|
|
hwndSource.RemoveHook(WndProc); |
|
|
|
|
ImeNativeWrapper.AssociateContext(hwndSource, previousContext); |
|
|
|
|
previousContext = IntPtr.Zero; |
|
|
|
|
ImeNativeWrapper.ReleaseContext(hwndSource, currentContext); |
|
|
|
|
hwndSource = null; |
|
|
|
|
currentContext = IntPtr.Zero; |
|
|
|
|
hwndSource.RemoveHook(WndProc); |
|
|
|
|
hwndSource = null; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void TextAreaGotKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e) |
|
|
|
|
public void OnGotFocus(KeyboardFocusChangedEventArgs e) |
|
|
|
|
{ |
|
|
|
|
if (e.OriginalSource != this.textArea) |
|
|
|
|
return; |
|
|
|
|
CreateContext(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -84,17 +65,15 @@ namespace ICSharpCode.AvalonEdit.Editing
@@ -84,17 +65,15 @@ namespace ICSharpCode.AvalonEdit.Editing
|
|
|
|
|
hwndSource = (HwndSource)PresentationSource.FromVisual(this.textArea); |
|
|
|
|
if (hwndSource != null) { |
|
|
|
|
currentContext = ImeNativeWrapper.GetContext(hwndSource); |
|
|
|
|
previousContext = ImeNativeWrapper.AssociateContext(hwndSource, currentContext); |
|
|
|
|
// ImeNativeWrapper.SetCompositionFont(hwndSource, currentContext, textArea);
|
|
|
|
|
hwndSource.AddHook(WndProc); |
|
|
|
|
// UpdateCompositionWindow() will be called by the caret becoming visible
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void TextAreaLostKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e) |
|
|
|
|
public void OnLostFocus(KeyboardFocusChangedEventArgs e) |
|
|
|
|
{ |
|
|
|
|
if (e.OriginalSource != this.textArea) |
|
|
|
|
return; |
|
|
|
|
if (currentContext != IntPtr.Zero) |
|
|
|
|
if (e.OldFocus == textArea && currentContext != IntPtr.Zero) |
|
|
|
|
ImeNativeWrapper.NotifyIme(currentContext); |
|
|
|
|
ClearContext(); |
|
|
|
|
} |
|
|
|
@ -103,6 +82,8 @@ namespace ICSharpCode.AvalonEdit.Editing
@@ -103,6 +82,8 @@ namespace ICSharpCode.AvalonEdit.Editing
|
|
|
|
|
{ |
|
|
|
|
switch (msg) { |
|
|
|
|
case ImeNativeWrapper.WM_INPUTLANGCHANGE: |
|
|
|
|
// Don't mark the message as handled; other windows
|
|
|
|
|
// might want to handle it as well.
|
|
|
|
|
ClearContext(); |
|
|
|
|
CreateContext(); |
|
|
|
|
break; |
|
|
|
@ -115,7 +96,7 @@ namespace ICSharpCode.AvalonEdit.Editing
@@ -115,7 +96,7 @@ namespace ICSharpCode.AvalonEdit.Editing
|
|
|
|
|
|
|
|
|
|
public void UpdateCompositionWindow() |
|
|
|
|
{ |
|
|
|
|
if (currentContext != IntPtr.Zero && textArea != null) { |
|
|
|
|
if (currentContext != IntPtr.Zero) { |
|
|
|
|
ImeNativeWrapper.SetCompositionWindow(hwndSource, currentContext, textArea); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|