From 34d7b48a7cd44739611291ed07ba01c7f0ba318e Mon Sep 17 00:00:00 2001 From: "Hong Jen Yee (PCMan)" Date: Wed, 25 Sep 2013 10:40:04 +0800 Subject: [PATCH] Add Ime::TextService::onKeyboardStatusChanged() virtual function. --- ChewingTextService/ChewingTextService.cpp | 47 ++++++++++++----------- ChewingTextService/ChewingTextService.h | 3 ++ libIME/TextService.cpp | 6 +++ libIME/TextService.h | 3 ++ 4 files changed, 36 insertions(+), 23 deletions(-) diff --git a/ChewingTextService/ChewingTextService.cpp b/ChewingTextService/ChewingTextService.cpp index 5d54dc68a..385562e6d 100644 --- a/ChewingTextService/ChewingTextService.cpp +++ b/ChewingTextService/ChewingTextService.cpp @@ -544,33 +544,34 @@ void TextService::onCompartmentChanged(const GUID& key) { applyConfig(); // apply the latest config return; } - Ime::TextService::onCompartmentChanged(key); - if(::IsEqualIID(key, GUID_COMPARTMENT_KEYBOARD_OPENCLOSE)) { - // keyboard open/close state is changed - bool opened = isKeyboardOpened(); - if(opened) { // keyboard is closed - initChewingContext(); - } - else { // keyboard is opened - if(isComposing()) { - // end current composition if needed - ITfContext* context = currentContext(); - if(context) { - endComposition(context); - context->Release(); - } +} + +// called when the keyboard is opened or closed +// virtual +void TextService::onKeyboardStatusChanged(bool opened) { + Ime::TextService::onKeyboardStatusChanged(opened); + if(opened) { // keyboard is opened + initChewingContext(); + } + else { // keyboard is closed + if(isComposing()) { + // end current composition if needed + ITfContext* context = currentContext(); + if(context) { + endComposition(context); + context->Release(); } - if(showingCandidates()) // disable candidate window if it's opened - hideCandidates(); - hideMessage(); // hide message window, if there's any - freeChewingContext(); // IME is closed, chewingContext is not needed } - - if(imeModeIcon_) - imeModeIcon_->setEnabled(opened); - // FIXME: should we also disable other language bar buttons as well? + if(showingCandidates()) // disable candidate window if it's opened + hideCandidates(); + hideMessage(); // hide message window, if there's any + freeChewingContext(); // IME is closed, chewingContext is not needed } + + if(imeModeIcon_) + imeModeIcon_->setEnabled(opened); + // FIXME: should we also disable other language bar buttons as well? } void TextService::initChewingContext() { diff --git a/ChewingTextService/ChewingTextService.h b/ChewingTextService/ChewingTextService.h index 857e65525..49a8765b5 100644 --- a/ChewingTextService/ChewingTextService.h +++ b/ChewingTextService/ChewingTextService.h @@ -56,6 +56,9 @@ class TextService: public Ime::TextService { // called when a compartment value is changed virtual void onCompartmentChanged(const GUID& key); + // called when the keyboard is opened or closed + virtual void onKeyboardStatusChanged(bool opened); + ChewingContext* chewingContext() { return chewingContext_; } diff --git a/libIME/TextService.cpp b/libIME/TextService.cpp index 7e21c36bc..4c3dd0954 100644 --- a/libIME/TextService.cpp +++ b/libIME/TextService.cpp @@ -535,6 +535,7 @@ void TextService::onCompartmentChanged(const GUID& key) { // http://blogs.msdn.com/b/tsfaware/archive/2007/05/30/what-is-a-keyboard.aspx if(::IsEqualGUID(key, GUID_COMPARTMENT_KEYBOARD_OPENCLOSE)) { isKeyboardOpened_ = threadCompartmentValue(key) ? true : false; + onKeyboardStatusChanged(isKeyboardOpened_); } } @@ -542,6 +543,11 @@ void TextService::onCompartmentChanged(const GUID& key) { void TextService::onLangBarStatusChanged(int newStatus) { } +// called when the keyboard is opened or closed +// virtual +void TextService::onKeyboardStatusChanged(bool opened) { +} + // COM stuff // IUnknown diff --git a/libIME/TextService.h b/libIME/TextService.h index 5c99e80c1..703dbab92 100644 --- a/libIME/TextService.h +++ b/libIME/TextService.h @@ -159,6 +159,9 @@ class TextService: virtual void onLangBarStatusChanged(int newStatus); + // called when the keyboard is opened or closed + virtual void onKeyboardStatusChanged(bool opened); + // COM related stuff public: friend class DisplayAttributeInfoEnum;