Author: ek.kato
Date: Tue Oct  7 03:53:52 2008
New Revision: 5583

Modified:
   trunk/qt/immodule-candidatewindow.cpp
   trunk/qt/immodule-candidatewindow.h
   trunk/qt/immodule-quiminputcontext.cpp
   trunk/qt/immodule-quiminputcontext.h

Log:
* qt/immodule-quiminputcontext.h
* qt/immodule-candidatewindow.h
* qt/immodule-quiminputcontext.cpp
* qt/immodule-candidatewindow.cpp
  - Port qt4 immodule page handling changes in r5581 to qt3
    immodule.


Modified: trunk/qt/immodule-candidatewindow.cpp
==============================================================================
--- trunk/qt/immodule-candidatewindow.cpp       (original)
+++ trunk/qt/immodule-candidatewindow.cpp       Tue Oct  7 03:53:52 2008
@@ -105,7 +105,10 @@
     {
         // clear stored candidate datas
         for ( unsigned int i = 0; i < stores.size(); i++ )
-            uim_candidate_free( stores[ i ] );
+       {
+           if ( stores[ i ] )
+               uim_candidate_free( stores[ i ] );
+       }
         stores.clear();
     }
 }
@@ -143,7 +146,10 @@

     // clear stored candidate datas
     for ( unsigned int i = 0; i < stores.size(); i++ )
-        uim_candidate_free( stores[ i ] );
+    {
+       if ( stores[ i ] )
+           uim_candidate_free( stores[ i ] );
+    }
     stores.clear();
 }

@@ -172,6 +178,55 @@
     // shift to default page
     setPage( 0 );
 }
+
+#if UIM_QT_USE_NEW_PAGE_HANDLING
+void CandidateWindow::setNrCandidates( int nrCands, int dLimit )
+{
+#ifdef ENABLE_DEBUG
+    qDebug( "setNrCandidates" );
+#endif
+    // remove old data
+    if ( !stores.isEmpty() )
+       clearCandidates();
+
+    candidateIndex = -1;
+    displayLimit = dLimit;
+    nrCandidates = nrCands;
+    pageIndex = 0;
+
+    // setup dummy candidates
+    for ( int i = 0; i < nrCandidates; i++ )
+    {
+       uim_candidate d = NULL;
+       stores.append( d );
+    }
+
+    if ( !subWin )
+       subWin = new SubWindow( this );
+}
+
+void CandidateWindow::setPageCandidates( int page, const QValueList<uim_candidate> &candidates )
+{
+#ifdef ENABLE_DEBUG
+    qDebug( "setPageCandidates" );
+#endif
+
+    if ( candidates.isEmpty() )
+       return;
+
+    // set candidates
+    int i, start, pageNr;
+    start = page * displayLimit;
+
+    if ( displayLimit && ( nrCandidates - start ) > displayLimit )
+       pageNr = displayLimit;
+    else
+       pageNr = nrCandidates - start;
+
+    for ( i = 0; i < pageNr; i++ )
+       stores[ start + i ] = candidates[ i ];
+}
+#endif /* UIM_QT_USE_NEW_PAGE_HANDLING */

 void CandidateWindow::setPage( int page )
 {

Modified: trunk/qt/immodule-candidatewindow.h
==============================================================================
--- trunk/qt/immodule-candidatewindow.h (original)
+++ trunk/qt/immodule-candidatewindow.h Tue Oct  7 03:53:52 2008
@@ -70,10 +70,17 @@
     void setIndex( int totalindex );
     void setIndexInPage( int index );

+    void setNrCandidates( int nrCands, int dLimit );
+ void setPageCandidates( int page, const QValueList<uim_candidate> &candidates );
+
     void setQUimInputContext( QUimInputContext* m_ic ) { ic = m_ic; }

     QSize sizeHint(void) const;

+    int nrCandidates;
+    int candidateIndex;
+    int displayLimit;
+    int pageIndex;
 protected slots:
     void slotCandidateSelected( QListViewItem* );
     void slotHookSubwindow( QListViewItem* );
@@ -91,11 +98,6 @@
     QLabel *numLabel;

     QValueList<uim_candidate> stores;
-
-    int nrCandidates;
-    int candidateIndex;
-    int displayLimit;
-    int pageIndex;

     bool isAlwaysLeft;


Modified: trunk/qt/immodule-quiminputcontext.cpp
==============================================================================
--- trunk/qt/immodule-quiminputcontext.cpp      (original)
+++ trunk/qt/immodule-quiminputcontext.cpp      Tue Oct  7 03:53:52 2008
@@ -500,16 +500,14 @@
     ic->candidateSelect( index );
 }

-void QUimInputContext::cand_shift_page_cb( void *ptr, int direction )
+void QUimInputContext::cand_shift_page_cb( void *ptr, int forward )
 {
 #ifdef ENABLE_DEBUG
     qDebug( "cand_shift_page_cb" );
 #endif

     QUimInputContext *ic = ( QUimInputContext* ) ptr;
-    CandidateWindow *cwin = ic->cwin;
-
-    cwin->shiftPage( direction );
+    ic->candidateShiftPage( (bool)forward );
 }

 void QUimInputContext::cand_deactivate_cb( void *ptr )
@@ -677,11 +675,47 @@
 }


+#if UIM_QT_USE_NEW_PAGE_HANDLING
+void QUimInputContext::prepare_page_candidates( int page )
+{
+    QValueList<uim_candidate> list;
+    list.clear();
+
+    if ( page < 0 )
+       return;
+
+    if (pageFilled[ page ] )
+       return;
+
+    /* set page candidates */
+    uim_candidate cand;
+    int pageNr, start, nrCandidates, displayLimit;
+
+    nrCandidates = cwin->nrCandidates;
+    displayLimit = cwin->displayLimit;
+    start = page * displayLimit;
+
+    if ( displayLimit && ( nrCandidates - start ) > displayLimit )
+       pageNr = displayLimit;
+    else
+       pageNr = nrCandidates - start;
+
+    for ( int i = start; i < ( pageNr + start ); i++ )
+    {
+ cand = uim_get_candidate( m_uc, i, displayLimit ? i % displayLimit : i );
+        list.append( cand );
+    }
+    pageFilled[ page ] = true;
+    cwin->setPageCandidates( page, list );
+}
+#endif
+
 void QUimInputContext::candidateActivate( int nr, int displayLimit )
 {
     QValueList<uim_candidate> list;
     list.clear();

+#if !UIM_QT_USE_NEW_PAGE_HANDLING
     cwin->activateCandwin( displayLimit );

     /* set candidates */
@@ -693,13 +727,56 @@
     }
     cwin->setCandidates( displayLimit, list );

+#else /* !UIM_QT_USE_NEW_PAGE_HANDLING */
+    nrPages = displayLimit ? ( nr - 1 ) / displayLimit + 1 : 1;
+    pageFilled.clear();
+    for ( int i = 0; i < nrPages; i++ )
+       pageFilled.append( false );
+
+    cwin->setNrCandidates( nr, displayLimit );
+
+    // set page candidates
+    prepare_page_candidates( 0 );
+    cwin->setPage( 0 );
+#endif /* !UIM_QT_USE_NEW_PAGE_HANDLING */
     cwin->popup();
     candwinIsActive = true;
 }

 void QUimInputContext::candidateSelect( int index )
 {
+#if UIM_QT_USE_NEW_PAGE_HANDLING
+    int new_page;
+
+    if ( index >= cwin->nrCandidates )
+       index = 0;
+
+    if ( index >= 0 && cwin->displayLimit )
+       new_page = index / cwin->displayLimit;
+    else
+       new_page = cwin->pageIndex;
+
+    prepare_page_candidates( new_page );
+#endif
     cwin->setIndex( index );
+}
+
+void QUimInputContext::candidateShiftPage( bool forward )
+{
+#if UIM_QT_USE_NEW_PAGE_HANDLING
+    int new_page, index;
+
+    index = forward ? cwin->pageIndex + 1 : cwin->pageIndex - 1;
+    if ( index < 0 )
+       new_page = nrPages - 1;
+    else if ( index >= nrPages )
+       new_page = 0;
+    else
+       new_page = index;
+
+    prepare_page_candidates( new_page );
+#endif
+    cwin->shiftPage( forward );
 }

 void QUimInputContext::candidateDeactivate()

Modified: trunk/qt/immodule-quiminputcontext.h
==============================================================================
--- trunk/qt/immodule-quiminputcontext.h        (original)
+++ trunk/qt/immodule-quiminputcontext.h        Tue Oct  7 03:53:52 2008
@@ -39,6 +39,7 @@
 #ifdef Q_WS_X11
 #define UIM_QT_USE_JAPANESE_KANA_KEYBOARD_HACK 1
 #endif
+#define UIM_QT_USE_NEW_PAGE_HANDLING 1

 class QString;

@@ -129,11 +130,15 @@
     //candidate
     void candidateActivate( int nr, int displayLimit );
     void candidateSelect( int index );
+    void candidateShiftPage( bool forward );
     void candidateDeactivate();
     //imsw
     void switch_app_global_im( const char *str );
     void switch_system_global_im( const char *str );

+#if UIM_QT_USE_NEW_PAGE_HANDLING
+    void prepare_page_candidates( int page );
+#endif
 #ifdef Q_WS_X11
     // for X11 Compose
     static DefTree *mTreeTop;
@@ -161,6 +166,11 @@

     CandidateWindow *cwin;
     static QUimHelperManager *m_HelperManager;
+
+#if UIM_QT_USE_NEW_PAGE_HANDLING
+    QValueList<bool> pageFilled;
+    int nrPages;
+#endif
 };

 #endif /* Not def: UIM_QT_IMMODULE_QUIMINPUTCONTEXT_H */

Reply via email to