In Idle cannot access RichTextControl or IME will not work
Asked Answered
S

0

1

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.

Surreptitious answered 22/12, 2014 at 9:40 Comment(2)
You referenced this question in this answer that was referenced here. Anyways, have you tried using the Text Object Model (TOM) interfaces to access this info? I don't have the setup to test it, so I don't know if it would work. It may be worth a try if you are still looking for a solution. Another thought is that maybe related to the RTB using the old RichEdit20W class vs the RichEdit50W class.Rosel
@Tn I don't work on that any more but I should give it a try, I never found a good solution for this. Thanks!Surreptitious

© 2022 - 2024 — McMap. All rights reserved.