1

I am implementing a text service on windows. Things work fine. However when I shift window focus to another application and shift focus back to the original application, the selected text services gets de-activated (I notice a call to ITfTextInputProcessor::Deactivate). I think this call is unexpected. Post this call, The service has to be re-activated manually. I am surely doing something goofy. Just that I don't know what it is.

Pankaj Lal
  • 307
  • 1
  • 12

1 Answers1

1

Offhand, I'd say that you are indeed doing something goofy. :) In particular, I'd pay careful attention to your ITfThreadMgrEventSink::OnSetFocus implementation (and, obviously, you need to implement ITfThreadMgrEventSink in your text service and connect it via AdviseSink if you haven't already.)

After more research, I've figured out what’s happening:

When you set focus back to Word, TSF gets the current thread’s active keyboard layout (actually a locale ID). It then compares that keyboard layout with the language ID of the currently active text service.

If they’re different, TSF then activates the text service for the active keyboard layout, and deactivates any previously active text service.

I believe this behavior is different on Vista/Windows 7.

The fix would be to use LoadKeyboardLayout/ActivateKeyboardLayout to set the process keyboard layout in your ITfTextInputProcessor::Activate implementation. Apparently some apps also need you to call ITfInputProcessorProfiles::ChangeCurrentLanguage() as well.

Eric Brown
  • 13,774
  • 7
  • 30
  • 71
  • Well, It behaves pretty ok if I switch between two MS Word documents. I get all expected calls and don't get `DeActivate`. On the other hand MS Excel and Powerpoint behave like non tsf aware (`TF_SS_TRANSITORY` bit is set). When I shift focus to these apps and shift focus back to the original one, I dont get `OnSetFocus` Calls, just the `DeActivate`. By the way, This is Windows XP and Office 2007. – Pankaj Lal Feb 17 '12 at 08:02