~ubuntu-branches/ubuntu/maverick/uim/maverick

« back to all changes in this revision

Viewing changes to qt/immodule-quiminputcontext.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Masahito Omote
  • Date: 2009-03-01 12:57:00 UTC
  • mfrom: (1.1.10 upstream)
  • Revision ID: james.westby@ubuntu.com-20090301125700-0ykjdq0zgj55e3n3
Tags: 1:1.5.5-1
New upstream release and final upload by current maintainter.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 
3
 
Copyright (c) 2003-2008 uim Project http://code.google.com/p/uim/
 
3
Copyright (c) 2003-2009 uim Project http://code.google.com/p/uim/
4
4
 
5
5
All rights reserved.
6
6
 
500
500
    ic->candidateSelect( index );
501
501
}
502
502
 
503
 
void QUimInputContext::cand_shift_page_cb( void *ptr, int direction )
 
503
void QUimInputContext::cand_shift_page_cb( void *ptr, int forward )
504
504
{
505
505
#ifdef ENABLE_DEBUG
506
506
    qDebug( "cand_shift_page_cb" );
507
507
#endif
508
508
 
509
509
    QUimInputContext *ic = ( QUimInputContext* ) ptr;
510
 
    CandidateWindow *cwin = ic->cwin;
511
 
 
512
 
    cwin->shiftPage( direction );
 
510
    ic->candidateShiftPage( (bool)forward );
513
511
}
514
512
 
515
513
void QUimInputContext::cand_deactivate_cb( void *ptr )
677
675
}
678
676
 
679
677
 
 
678
#if UIM_QT_USE_NEW_PAGE_HANDLING
 
679
void QUimInputContext::prepare_page_candidates( int page )
 
680
{
 
681
    QValueList<uim_candidate> list;
 
682
    list.clear();
 
683
 
 
684
    if ( page < 0 )
 
685
        return;
 
686
 
 
687
    if (pageFilled[ page ] )
 
688
        return;
 
689
 
 
690
    /* set page candidates */
 
691
    uim_candidate cand;
 
692
    int pageNr, start, nrCandidates, displayLimit;
 
693
 
 
694
    nrCandidates = cwin->nrCandidates;
 
695
    displayLimit = cwin->displayLimit;
 
696
    start = page * displayLimit;
 
697
 
 
698
    if ( displayLimit && ( nrCandidates - start ) > displayLimit )
 
699
        pageNr = displayLimit;
 
700
    else
 
701
        pageNr = nrCandidates - start;
 
702
 
 
703
    for ( int i = start; i < ( pageNr + start ); i++ )
 
704
    {
 
705
        cand = uim_get_candidate( m_uc, i, displayLimit ? i % displayLimit : i );
 
706
        list.append( cand );
 
707
    }
 
708
    pageFilled[ page ] = true;
 
709
    cwin->setPageCandidates( page, list );
 
710
}
 
711
#endif
 
712
 
680
713
void QUimInputContext::candidateActivate( int nr, int displayLimit )
681
714
{
682
715
    QValueList<uim_candidate> list;
683
716
    list.clear();
684
717
 
 
718
#if !UIM_QT_USE_NEW_PAGE_HANDLING
685
719
    cwin->activateCandwin( displayLimit );
686
720
 
687
721
    /* set candidates */
693
727
    }
694
728
    cwin->setCandidates( displayLimit, list );
695
729
 
 
730
#else /* !UIM_QT_USE_NEW_PAGE_HANDLING */
 
731
    nrPages = displayLimit ? ( nr - 1 ) / displayLimit + 1 : 1;
 
732
    pageFilled.clear();
 
733
    for ( int i = 0; i < nrPages; i++ )
 
734
        pageFilled.append( false );
 
735
 
 
736
    cwin->setNrCandidates( nr, displayLimit );
 
737
 
 
738
    // set page candidates
 
739
    prepare_page_candidates( 0 );
 
740
    cwin->setPage( 0 );
 
741
#endif /* !UIM_QT_USE_NEW_PAGE_HANDLING */
696
742
    cwin->popup();
697
743
    candwinIsActive = true;
698
744
}
699
745
 
700
746
void QUimInputContext::candidateSelect( int index )
701
747
{
 
748
#if UIM_QT_USE_NEW_PAGE_HANDLING
 
749
    int new_page;
 
750
 
 
751
    if ( index >= cwin->nrCandidates )
 
752
        index = 0;
 
753
 
 
754
    if ( index >= 0 && cwin->displayLimit )
 
755
        new_page = index / cwin->displayLimit;
 
756
    else
 
757
        new_page = cwin->pageIndex;
 
758
 
 
759
    prepare_page_candidates( new_page );
 
760
#endif
702
761
    cwin->setIndex( index );
703
762
}
704
763
 
 
764
void QUimInputContext::candidateShiftPage( bool forward )
 
765
{
 
766
#if UIM_QT_USE_NEW_PAGE_HANDLING
 
767
    int new_page, index;
 
768
 
 
769
    index = forward ? cwin->pageIndex + 1 : cwin->pageIndex - 1;
 
770
    if ( index < 0 )
 
771
        new_page = nrPages - 1;
 
772
    else if ( index >= nrPages )
 
773
        new_page = 0;
 
774
    else
 
775
        new_page = index;
 
776
 
 
777
    prepare_page_candidates( new_page );
 
778
#endif
 
779
    cwin->shiftPage( forward );
 
780
}
 
781
 
705
782
void QUimInputContext::candidateDeactivate()
706
783
{
707
784
    cwin->deactivateCandwin();