Author: ek.kato
Date: Tue Oct 7 03:49:19 2008
New Revision: 5582
Modified:
trunk/qt4/immodule/candidatewindow.cpp
trunk/qt4/immodule/candidatewindow.h
trunk/qt4/immodule/quiminputcontext.cpp
trunk/qt4/immodule/quiminputcontext.h
Log:
* qt4/immodule/quiminputcontext.h : Define
UIM_QT_USE_NEW_PAGE_HANDLING for the optimized candidates
handling as in r5577 for GTK+ bridge.
* qt4/immodule/quiminputcontext.cpp
- (QUimInputContext::cand_shift_page_cb) : Use
candidateShiftPage().
- (QUimInputContext::prepare_page_candidates) : New.
- (QUimInputContext::candidateActivate) : Set the first page
only when UIM_QT_USE_NEW_PAGE_HANDLING is defined.
- (UimInputContext::candidateSelect) : Add check for the new
page with UIM_QT_USE_NEW_PAGE_HANDLING.
- (QUimInputContext::candidateShiftPage) : New. Add check for
the new page with UIM_QT_USE_NEW_PAGE_HANDLING.
* qt4/immodule/candidatewindow.cpp
- (CandidateWindow::clearCandidates) : Add sanity check.
- (CandidateWindow::setNrCandidates) : New.
- (CandidateWindow::setPageCandidates) : Ditto.
* qt4/immodule/candidatewindow.h
- (nrCandidates)
- (displayLimit)
- (caniddateIndex)
- (pageIndex)
- Exposing as a public member variable.
Modified: trunk/qt4/immodule/candidatewindow.cpp
==============================================================================
--- trunk/qt4/immodule/candidatewindow.cpp (original)
+++ trunk/qt4/immodule/candidatewindow.cpp Tue Oct 7 03:49:19 2008
@@ -152,7 +152,10 @@
// clear stored candidate datas
for ( int i = 0; i < stores.size(); i++ )
- uim_candidate_free( stores[ i ] );
+ {
+ if ( stores[ i ] )
+ uim_candidate_free( stores[ i ] );
+ }
stores.clear();
}
@@ -181,6 +184,56 @@
// 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 candidate
+ 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
Q3ValueList<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/qt4/immodule/candidatewindow.h
==============================================================================
--- trunk/qt4/immodule/candidatewindow.h (original)
+++ trunk/qt4/immodule/candidatewindow.h Tue Oct 7 03:49:19 2008
@@ -70,10 +70,17 @@
void setIndex( int totalindex );
void setIndexInPage( int index );
+ void setNrCandidates( int nrCands, int dLimit );
+ void setPageCandidates( int page, const Q3ValueList<uim_candidate>
&candidates );
+
void setQUimInputContext( QUimInputContext* m_ic ) { ic = m_ic; }
QSize sizeHint(void) const;
+ int nrCandidates;
+ int displayLimit;
+ int candidateIndex;
+ int pageIndex;
protected slots:
void slotCandidateSelected( Q3ListViewItem* );
void slotHookSubwindow( Q3ListViewItem* );
@@ -92,10 +99,6 @@
Q3ValueList<uim_candidate> stores;
- int nrCandidates;
- int candidateIndex;
- int displayLimit;
- int pageIndex;
bool isAlwaysLeft;
Modified: trunk/qt4/immodule/quiminputcontext.cpp
==============================================================================
--- trunk/qt4/immodule/quiminputcontext.cpp (original)
+++ trunk/qt4/immodule/quiminputcontext.cpp Tue Oct 7 03:49:19 2008
@@ -548,14 +548,12 @@
ic->candidateSelect( index );
}
-void QUimInputContext::cand_shift_page_cb( void *ptr, int direction )
+void QUimInputContext::cand_shift_page_cb( void *ptr, int forward )
{
qDebug( "cand_shift_page_cb" );
QUimInputContext *ic = ( QUimInputContext* ) ptr;
- CandidateWindow *cwin = ic->cwin;
-
- cwin->shiftPage( direction );
+ ic->candidateShiftPage( (bool)forward );
}
void QUimInputContext::cand_deactivate_cb( void *ptr )
@@ -778,12 +776,47 @@
return attrs;
}
+#if UIM_QT_USE_NEW_PAGE_HANDLING
+void QUimInputContext::prepare_page_candidates( int page )
+{
+ QList<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 /* UIM_QT_USE_NEW_PAGE_HANDLING */
void QUimInputContext::candidateActivate( int nr, int displayLimit )
{
QList<uim_candidate> list;
list.clear();
+#if !UIM_QT_USE_NEW_PAGE_HANDLING
cwin->activateCandwin( displayLimit );
// set candidates
@@ -795,14 +828,58 @@
}
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 /* UIM_QT_USE_NEW_PAGE_HANDLING */
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 /* UIM_QT_USE_NEW_PAGE_HANDLING */
+ cwin->shiftPage( forward );
+}
+
void QUimInputContext::candidateDeactivate()
{
Modified: trunk/qt4/immodule/quiminputcontext.h
==============================================================================
--- trunk/qt4/immodule/quiminputcontext.h (original)
+++ trunk/qt4/immodule/quiminputcontext.h Tue Oct 7 03:49:19 2008
@@ -41,6 +41,7 @@
#ifdef Q_WS_X11
#define UIM_QT_USE_JAPANESE_KANA_KEYBOARD_HACK 1
#endif
+#define UIM_QT_USE_NEW_PAGE_HANDLING 1
#include <uim/uim.h>
#include <uim/uim-helper.h>
@@ -139,11 +140,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;
@@ -172,6 +177,11 @@
CandidateWindow *cwin;
static QUimHelperManager *m_HelperManager;
+
+#if UIM_QT_USE_NEW_PAGE_HANDLING
+ QList<bool> pageFilled;
+ int nrPages;
+#endif
};
#endif /* Not def: UIM_QT4_IMMODULE_QUIMINPUTCONTEXT_H */