Revision: 6418
Author: nogu.dev
Date: Sat Jun  5 16:14:58 2010
Log: * 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 to fix bug #13910.
  - (QUimInputContext):
    * Remove 2nd argument "lang" in constructor.
    * Add savePreedit() and restorePreedit().
http://code.google.com/p/uim/source/detail?r=6418

Modified:
 /trunk/qt4/immodule/plugin.cpp
 /trunk/qt4/immodule/quiminfomanager.cpp
 /trunk/qt4/immodule/quiminfomanager.h
 /trunk/qt4/immodule/quiminputcontext.cpp
 /trunk/qt4/immodule/quiminputcontext.h

=======================================
--- /trunk/qt4/immodule/plugin.cpp      Sun Apr  4 20:35:54 2010
+++ /trunk/qt4/immodule/plugin.cpp      Sat Jun  5 16:14:58 2010
@@ -79,9 +79,7 @@
     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;
 }
=======================================
--- /trunk/qt4/immodule/quiminfomanager.cpp     Sun Apr  4 20:35:54 2010
+++ /trunk/qt4/immodule/quiminfomanager.cpp     Sat Jun  5 16:14:58 2010
@@ -44,7 +44,7 @@
 }

 QList<uimInfo>
-QUimInfoManager::getUimInfo()
+QUimInfoManager::getUimInfo() const
 {
     return info;
 }
@@ -69,12 +69,9 @@
 }

 QString
-QUimInfoManager::imLang( const QString &imname )
-{
-    int i, n;
-
-    n = info.count();
-    for (i = 0; i < n; i++) {
+QUimInfoManager::imLang( const QString &imname ) const
+{
+    for (int i = 0, n = info.count(); i < n; i++) {
         if ( info[i].name == imname )
             return info[i].lang;
     }
=======================================
--- /trunk/qt4/immodule/quiminfomanager.h       Sun Apr  4 20:35:54 2010
+++ /trunk/qt4/immodule/quiminfomanager.h       Sat Jun  5 16:14:58 2010
@@ -50,8 +50,8 @@
     ~QUimInfoManager();

     void initUimInfo();
-    QList<uimInfo> getUimInfo();
-    QString imLang( const QString &imname );
+    QList<uimInfo> getUimInfo() const;
+    QString imLang( const QString &imname ) const;

 private:
     QList<uimInfo> info;
=======================================
--- /trunk/qt4/immodule/quiminputcontext.cpp    Wed Apr 28 18:24:41 2010
+++ /trunk/qt4/immodule/quiminputcontext.cpp    Sat Jun  5 16:14:58 2010
@@ -78,10 +78,12 @@
 // 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 @@

     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 @@
     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 @@

     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 @@
 #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::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
@@ -644,6 +669,36 @@
         commitString( "" );
     }
 }
+
+#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()
 {
=======================================
--- /trunk/qt4/immodule/quiminputcontext.h      Wed Apr 28 18:24:41 2010
+++ /trunk/qt4/immodule/quiminputcontext.h      Sat Jun  5 16:14:58 2010
@@ -68,11 +68,13 @@
     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 @@
 private:
     int getPreeditSelectionLength();
     QList<QInputMethodEvent::Attribute> 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 @@

 protected:
     QString m_imname;
-    QString m_lang;
-    uim_context m_uc;
     bool candwinIsActive;
     bool m_isComposing;

+    uim_context m_uc;
     QList<PreeditSegment> psegs;
-
     CandidateWindow *cwin;
+
+#ifdef WORKAROUND_BROKEN_RESET_IN_QT4
+    QHash<QWidget*, uim_context> m_ucHash;
+    QHash<QWidget*, QList<PreeditSegment> > psegsHash;
+    QHash<QWidget*, CandidateWindow*> cwinHash;
+    QHash<QWidget*, bool> visibleHash;
+
+    QWidget *focusedWidget;
+#endif
+
     static QUimHelperManager *m_HelperManager;
 };

Reply via email to