diff --git a/qt4/immodule/quiminputcontext.cpp b/qt4/immodule/quiminputcontext.cpp index 8a15f5b..3a02914 100644 --- a/qt4/immodule/quiminputcontext.cpp +++ b/qt4/immodule/quiminputcontext.cpp @@ -79,9 +79,8 @@ 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 ) { #ifdef ENABLE_DEBUG qDebug( "QUimInputContext()" ); @@ -123,6 +122,11 @@ QUimInputContext::~QUimInputContext() if ( m_uc ) uim_release_context( m_uc ); + foreach ( uim_context uc, m_ucHash ) + if ( uc ) + uim_release_context( uc ); + foreach ( CandidateWindow* window, cwinHash ) + delete window; if ( this == focusedInputContext ) { @@ -367,12 +371,17 @@ void QUimInputContext::setFocus() qDebug( "QUimInputContext: %p->setFocus(), focusWidget()=%p", this, QApplication::focusWidget() ); #endif + focusedWidget = QApplication::focusWidget(); focusedInputContext = this; disableFocusedContext = false; - if ( candwinIsActive ) + if ( psegsHash.contains( focusedWidget ) ) { + restorePreedit(); cwin->popup(); + } else if ( candwinIsActive ) { + cwin->popup(); + } m_HelperManager->checkHelperConnection(); @@ -392,13 +401,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(); @@ -462,6 +464,17 @@ void QUimInputContext::reset() candwinIsActive = false; cwin->hide(); + + // 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() ) { + if ( !psegs.isEmpty() ) + savePreedit(); + return; + } + uim_reset_context( m_uc ); #ifdef Q_WS_X11 mCompose->reset(); @@ -645,6 +658,30 @@ void QUimInputContext::updatePreedit() } } +void QUimInputContext::savePreedit() +{ + m_ucHash.insert( focusedWidget, m_uc ); + psegsHash.insert( focusedWidget, psegs ); + cwinHash.insert( focusedWidget, cwin ); + + 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() +{ + uim_release_context( m_uc ); + delete cwin; + + m_uc = m_ucHash.take( focusedWidget ); + psegs = psegsHash.take( focusedWidget ); + cwin = cwinHash.take( focusedWidget ); +} + void QUimInputContext::saveContext() { // just send IMEnd and keep preedit string diff --git a/qt4/immodule/quiminputcontext.h b/qt4/immodule/quiminputcontext.h index 3aecc6b..791d23e 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,20 @@ 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; + + QWidget *focusedWidget; + static QUimHelperManager *m_HelperManager; };