When reading some RichTextControl
properties inside Application.Idle
some IME won't work.
Given this simple code:
_richTextControl = new RichTextControl();
Application.Idle += delegate(object sender, EventArgs e) {
btnCopy.Enabled = _richTextControl.SelectionLength > 0;
btnPaste.Enabled = _richTextControl.CanPaste();
};
It'll work fine with most IME I tried but, at least, for Chinese (Traditional, Taiwan) with Microsoft Chinese Traditional Array (6.0) and Chinese Traditional DaYi (6.0) it'll prevent IME to work properly (I tried only with Windows 7, in English and Taiwanese). You can start typing but when Idle
code is executed (reading SelectionLength
property and invoking CanPaste()
method, here I wrote them both but each one is enough to reproduce this) it'll stop working (you type but pop-up window is closed immediately and nothing is sent to RichTextControl
).
I checked MSDN about EM_GETSELTEXT
and EM_CANPASTE
but it says nothing about this issue. I also tried to replace SelectionLength
property manually sending EM_GETSELTEXT
with SendMessage()
but it doesn't change this odd behavior (however I checked WordPad - which uses rich editor - and it works properly even if (AFAIK) MFC commands use idle time to update UI status).
Of course I can move some code into SelectionChanged
event and update UI both from Idle
and from SelectionChanged
(and it'll work) or I may update some flags in SelectionChanged
and change UI in Idle
but this will break existing code and it'll force a big change in UI library (all commands have not knowledge of Idle
or SelectionChanged
, they simply return true in a CanExecute()
method when their target control allows their execution). If nothing else is viable then I may derive a class from RichTextControl
to make these methods/properties callable in Idle
(using flags updated elsewhere) but (to avoid a big refactoring) I would know if it's a knows issue, a bug related to IME itself or if there is something else I missed.