And what makes you think the widget can't give this information to the user of the library which would Then invoke the IME/whatever input system and give the result back to the widget in an platform independent input/character event?
// pseudo-interface
class TextWidget {
...
WidgetEvent HandleMouseEvent(const MouseEvent& m, ...);
WidgetEvent HandleKeyboardEvent(const KeyboardEvent& k, ...),
WidgetEvent InputEvent(const InputEvent& i, ...);
};
// client code.
PlatformMsg msg;
while (GetMessage(&msg, ...)) {
WidgetEvent event;
if (IsKeyboard(msg)) {
event=widgets.DispatchEvent(MapKeyboardMsg(msg),...);
} ... {
if (NeedsIMEInput(event)) {
OpenIME(ExtractDetails(event));
}
}
The client application interfaces with the native/platform/synthesizer API/wrapper library to read/generate events from apps message queue/script/internet/whatever and maps those into platform agonistic events supported by the widget library and dispatches them into the library where the library decides which widget will receive them etc. The widget will react to the event and in the case of the text input widget will return back an event with the relevant information for invoking some IME system (in this example). The client code interfaces again with the native/platform/synthesizer to do what is asked and then dispatches the result back to the widget which will update its state.
This design will basically have the same functionality but will split the responsibilities so that the widget system would not depend on the input system. This allows the two to vary independently and remain agnostic of each other thus promoting reuse and testing and simplifying the implementation (IMHO).
The question is not about how to invoke some IME, it's about how to separate these concerns and de-couple the widget system from the input system by delegating the invocation (and required details) to somewhere else. I don't see any real reason that warrants tight coupling.