diff --git a/qt4/immodule/quiminputcontext.cpp b/qt4/immodule/quiminputcontext.cpp index 8a15f5b..8ac461d 100644 --- a/qt4/immodule/quiminputcontext.cpp +++ b/qt4/immodule/quiminputcontext.cpp @@ -79,9 +79,9 @@ static int unicodeToUKey(ushort c); // 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 ) + : QInputContext(), m_imname( imname ), m_lang( lang ), + candwinIsActive( false ), m_isComposing( false ), m_uc( 0 ), + focusedWidget( 0 ) { #ifdef ENABLE_DEBUG qDebug( "QUimInputContext()" ); @@ -123,6 +123,12 @@ QUimInputContext::~QUimInputContext() if ( m_uc ) uim_release_context( m_uc ); + delete cwin; + foreach ( const uim_context uc, m_ucHash ) + if ( uc ) + uim_release_context( uc ); + foreach ( const CandidateWindow* window, cwinHash ) + delete window; if ( this == focusedInputContext ) { @@ -367,11 +373,15 @@ void QUimInputContext::setFocus() qDebug( "QUimInputContext: %p->setFocus(), focusWidget()=%p", this, QApplication::focusWidget() ); #endif + focusedWidget = QApplication::focusWidget(); focusedInputContext = this; disableFocusedContext = false; - if ( candwinIsActive ) + if ( isPreeditPreservationEnabled() + && m_ucHash.contains( focusedWidget ) ) + restorePreedit(); + else if ( candwinIsActive ) cwin->popup(); m_HelperManager->checkHelperConnection(); @@ -392,13 +402,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,7 +464,18 @@ void QUimInputContext::reset() #endif candwinIsActive = false; + + // 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; + } cwin->hide(); + uim_reset_context( m_uc ); #ifdef Q_WS_X11 mCompose->reset(); @@ -645,6 +659,34 @@ void QUimInputContext::updatePreedit() } } +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(); +} + void QUimInputContext::saveContext() { // just send IMEnd and keep preedit string diff --git a/qt4/immodule/quiminputcontext.h b/qt4/immodule/quiminputcontext.h index 3aecc6b..04ab26f 100644 --- a/qt4/immodule/quiminputcontext.h +++ b/qt4/immodule/quiminputcontext.h @@ -116,6 +116,8 @@ protected: private: int getPreeditSelectionLength(); QList getPreeditAttrs(); + void savePreedit(); + void restorePreedit(); /* callbacks for uim */ static void commit_cb( void *ptr, const char *str ); @@ -162,13 +164,22 @@ private: protected: QString m_imname; QString m_lang; - uim_context m_uc; bool candwinIsActive; bool m_isComposing; + uim_context m_uc; + QHash m_ucHash; + QList psegs; + QHash > psegsHash; CandidateWindow *cwin; + QHash cwinHash; + + QHash visibleHash; + + QWidget *focusedWidget; + static QUimHelperManager *m_HelperManager; }; -- 1.6.4.2