* qt4/immodule/quiminfomanager.h - (UimInputContextPlugin::create): Follow change in QUimInputContext. * qt4/immodule/quiminfomanager.cpp - (QUimInfoManager::getUimInfo): Mark this getter as const. - (QUimInfoManager::imLang): * Mark this function as const. * Make "i" and "n" loop variables. * qt4/immodule/quiminfomanager.h - (QUimInfoManager::getUimInfo): Mark this getter as const. - (QUimInfoManager::imLang): Mark this function as const. * qt4/immodule/quiminputcontext.cpp - (QUimInputContext::QUimInputContext): * Remove 2nd argument "lang". * Sort variables in list. - (QUimInputContext::~QUimInputContext): Delete contents of hashes. - (QUimInputContext::setFocus): Restore preedit text if it exists. - (QUimInputContext::unsetFocus): Don't call reset(). reset() is always called on focus out. - (QUimInputContext::reset): Keep preedit text when preedit text exists and isPreeditPreservationEnabled() is true. - (QUimInputContext::language): Return language of input method. Without this change, this function always returns "ja" and isPreeditPreservationEnabled() always returns true. - (QUimInputContext::savePreedit): New function. - (QUimInputContext::restorePreedit): New function. * qt4/immodule/quiminputcontext.h - Define WORKAROUND_BROKEN_RESET_IN_QT4 to enable hack. - (QUimInputContext): * Remove 2nd argument "lang" in constructor. * Add savePreedit() and restorePreedit(). --- qt4/immodule/plugin.cpp | 4 +- qt4/immodule/quiminfomanager.cpp | 9 +--- qt4/immodule/quiminfomanager.h | 4 +- qt4/immodule/quiminputcontext.cpp | 79 +++++++++++++++++++++++++++++++------ qt4/immodule/quiminputcontext.h | 22 ++++++++-- 5 files changed, 91 insertions(+), 27 deletions(-) diff --git a/qt4/immodule/plugin.cpp b/qt4/immodule/plugin.cpp index 7beae96..089f089 100644 --- a/qt4/immodule/plugin.cpp +++ b/qt4/immodule/plugin.cpp @@ -79,9 +79,7 @@ QInputContext *UimInputContextPlugin::create( const QString & key ) if ( key == "uim" ) imname = uim_get_default_im_name( setlocale( LC_ALL, 0 ) ); - QStringList langs = createLanguageList( key ); - QUimInputContext *uic = new QUimInputContext( imname.toUtf8().data(), - langs[ 0 ].toUtf8().data() ); + QUimInputContext *uic = new QUimInputContext( imname.toUtf8().data() ); return uic; } diff --git a/qt4/immodule/quiminfomanager.cpp b/qt4/immodule/quiminfomanager.cpp index 604f4a9..bc4c3b5 100644 --- a/qt4/immodule/quiminfomanager.cpp +++ b/qt4/immodule/quiminfomanager.cpp @@ -44,7 +44,7 @@ QUimInfoManager::~QUimInfoManager() } QList -QUimInfoManager::getUimInfo() +QUimInfoManager::getUimInfo() const { return info; } @@ -69,12 +69,9 @@ QUimInfoManager::initUimInfo() } QString -QUimInfoManager::imLang( const QString &imname ) +QUimInfoManager::imLang( const QString &imname ) const { - int i, n; - - n = info.count(); - for (i = 0; i < n; i++) { + for (int i = 0, n = info.count(); i < n; i++) { if ( info[i].name == imname ) return info[i].lang; } diff --git a/qt4/immodule/quiminfomanager.h b/qt4/immodule/quiminfomanager.h index 676d617..018ecd5 100644 --- a/qt4/immodule/quiminfomanager.h +++ b/qt4/immodule/quiminfomanager.h @@ -50,8 +50,8 @@ public: ~QUimInfoManager(); void initUimInfo(); - QList getUimInfo(); - QString imLang( const QString &imname ); + QList getUimInfo() const; + QString imLang( const QString &imname ) const; private: QList info; diff --git a/qt4/immodule/quiminputcontext.cpp b/qt4/immodule/quiminputcontext.cpp index 8a15f5b..739d540 100644 --- a/qt4/immodule/quiminputcontext.cpp +++ b/qt4/immodule/quiminputcontext.cpp @@ -78,10 +78,12 @@ static int unicodeToUKey(ushort c); // input method name is useless and should be redesigned. I will // suggest the change in future. -- YamaKen 2004-07-28 -QUimInputContext::QUimInputContext( const char *imname, const char *lang ) - : QInputContext(), m_imname( imname ), m_lang( lang ), m_uc( 0 ), - candwinIsActive( false ), - m_isComposing( false ) +QUimInputContext::QUimInputContext( const char *imname ) + : QInputContext(), m_imname( imname ), + candwinIsActive( false ), m_isComposing( false ), m_uc( 0 ) +#ifdef WORKAROUND_BROKEN_RESET_IN_QT4 + , focusedWidget( 0 ) +#endif { #ifdef ENABLE_DEBUG qDebug( "QUimInputContext()" ); @@ -123,6 +125,14 @@ QUimInputContext::~QUimInputContext() if ( m_uc ) uim_release_context( m_uc ); + delete cwin; +#ifdef WORKAROUND_BROKEN_RESET_IN_QT4 + foreach ( const uim_context uc, m_ucHash ) + if ( uc ) + uim_release_context( uc ); + foreach ( const CandidateWindow* window, cwinHash ) + delete window; +#endif if ( this == focusedInputContext ) { @@ -371,6 +381,13 @@ void QUimInputContext::setFocus() focusedInputContext = this; disableFocusedContext = false; +#ifdef WORKAROUND_BROKEN_RESET_IN_QT4 + focusedWidget = QApplication::focusWidget(); + if ( isPreeditPreservationEnabled() + && m_ucHash.contains( focusedWidget ) ) + restorePreedit(); + else +#endif if ( candwinIsActive ) cwin->popup(); @@ -392,13 +409,6 @@ void QUimInputContext::unsetFocus() uim_focus_out_context( m_uc ); - // Don't reset Japanese input context here. Japanese input context - // sometimes contains a whole paragraph and has minutes of - // lifetime different to ephemeral one in other languages. The - // input context should be survived until focused again. - if ( ! isPreeditPreservationEnabled() ) - reset(); - cwin->hide(); m_indicator->hide(); @@ -461,6 +471,18 @@ void QUimInputContext::reset() #endif candwinIsActive = false; + +#ifdef WORKAROUND_BROKEN_RESET_IN_QT4 + // Japanese input context sometimes contains a whole paragraph + // and has minutes of lifetime different to ephemeral one + // in other languages. The input context should be survived + // until focused again. + if ( isPreeditPreservationEnabled() + && !m_ucHash.contains( focusedWidget ) ) { + psegs.isEmpty() ? cwin->hide() : savePreedit(); + return; + } +#endif cwin->hide(); uim_reset_context( m_uc ); #ifdef Q_WS_X11 @@ -494,7 +516,10 @@ QString QUimInputContext::identifierName() QString QUimInputContext::language() { - return m_lang; + const QUimInfoManager *manager + = UimInputContextPlugin::getQUimInfoManager(); + const QString name = QString::fromUtf8( uim_get_current_im_name( m_uc ) ); + return manager->imLang( name ); } // callbacks for uim @@ -645,6 +670,36 @@ void QUimInputContext::updatePreedit() } } +#ifdef WORKAROUND_BROKEN_RESET_IN_QT4 +void QUimInputContext::savePreedit() +{ + m_ucHash.insert( focusedWidget, m_uc ); + psegsHash.insert( focusedWidget, psegs ); + cwinHash.insert( focusedWidget, cwin ); + visibleHash.insert( focusedWidget, cwin->isVisible() ); + cwin->hide(); + + if ( !m_imname.isEmpty() ) + m_uc = createUimContext( m_imname.toAscii().data() ); + psegs.clear(); + cwin = new CandidateWindow( 0 ); + cwin->setQUimInputContext( this ); + cwin->hide(); +} + +void QUimInputContext::restorePreedit() +{ + if ( m_uc ) + uim_release_context( m_uc ); + delete cwin; + m_uc = m_ucHash.take( focusedWidget ); + psegs = psegsHash.take( focusedWidget ); + cwin = cwinHash.take( focusedWidget ); + if ( visibleHash.take( focusedWidget ) ) + cwin->popup(); +} +#endif + void QUimInputContext::saveContext() { // just send IMEnd and keep preedit string diff --git a/qt4/immodule/quiminputcontext.h b/qt4/immodule/quiminputcontext.h index 3aecc6b..1c157c7 100644 --- a/qt4/immodule/quiminputcontext.h +++ b/qt4/immodule/quiminputcontext.h @@ -68,11 +68,13 @@ public: QString str; }; +#define WORKAROUND_BROKEN_RESET_IN_QT4 + class QUimInputContext : public QInputContext { Q_OBJECT public: - explicit QUimInputContext( const char *imname = 0, const char *lang = 0 ); + explicit QUimInputContext( const char *imname = 0 ); ~QUimInputContext(); virtual QString identifierName(); @@ -116,6 +118,10 @@ protected: private: int getPreeditSelectionLength(); QList getPreeditAttrs(); +#ifdef WORKAROUND_BROKEN_RESET_IN_QT4 + void savePreedit(); + void restorePreedit(); +#endif /* callbacks for uim */ static void commit_cb( void *ptr, const char *str ); @@ -161,14 +167,22 @@ private: protected: QString m_imname; - QString m_lang; - uim_context m_uc; bool candwinIsActive; bool m_isComposing; + uim_context m_uc; QList psegs; - CandidateWindow *cwin; + +#ifdef WORKAROUND_BROKEN_RESET_IN_QT4 + QHash m_ucHash; + QHash > psegsHash; + QHash cwinHash; + QHash visibleHash; + + QWidget *focusedWidget; +#endif + static QUimHelperManager *m_HelperManager; }; -- 1.6.4.2