Revision: 6011
Author: ek.kato
Date: Sat Sep 26 11:30:24 2009
Log: * configure.ac
  - (default-toolkit) : Add qt4.
  - (use_qt4) : Add target for uim-candwin-qt4.
* qt4/candwin/uim-candwin-qt4.pro.in : New.
* qt4/candwin/Makefile.am : Ditto.
* qt4/candwin/qt4.cpp : Ported from qt3 candwin.
* qt4/candwin/qt4.h : Ditto.
* qt4/Makefile.am (SUBDIRS) : Add candwin.
* xim/canddisp.cpp : Support qt4 candwin.
* xim/Makefile.am : Ditto.

http://code.google.com/p/uim/source/detail?r=6011

Added:
 /trunk/qt4/candwin
 /trunk/qt4/candwin/Makefile.am
 /trunk/qt4/candwin/qt4.cpp
 /trunk/qt4/candwin/qt4.h
 /trunk/qt4/candwin/uim-candwin-qt4.pro.in
Modified:
 /trunk/configure.ac
 /trunk/qt4/Makefile.am
 /trunk/xim/Makefile.am
 /trunk/xim/canddisp.cpp

=======================================
--- /dev/null
+++ /trunk/qt4/candwin/Makefile.am      Sat Sep 26 11:30:24 2009
@@ -0,0 +1,22 @@
+.PHONY: mocclean FORCE
+
+# Makefile.qmake is only exist when --enable-qt4
+if QT4
+all clean mocclean install uninstall:
+       $(MAKE) $(AM_MAKEFLAGS) -f Makefile.qmake INSTALL_ROOT=$(DESTDIR) $@
+
+# *.pro is required to run Makefile.qmake. So distclean-am is deferred.
+distclean:
+       $(MAKE) $(AM_MAKEFLAGS) -f Makefile.qmake $@
+       $(MAKE) $(AM_MAKEFLAGS) distclean-am
+       -rm -f Makefile uim-candwin-qt4.pro
+else
+distclean:
+       -rm -f Makefile uim-candwin-qt4.pro
+endif
+
+FORCE:
+
+EXTRA_DIST =  uim-candwin-qt4.pro.in \
+            qt4.h \
+            qt4.cpp
=======================================
--- /dev/null
+++ /trunk/qt4/candwin/qt4.cpp  Sat Sep 26 11:30:24 2009
@@ -0,0 +1,585 @@
+/*
+
+ Copyright (c) 2003-2009 uim Project http://code.google.com/p/uim/
+
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+
+ 1. Redistributions of source code must retain the above copyright
+    notice, this list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright
+    notice, this list of conditions and the following disclaimer in the
+    documentation and/or other materials provided with the distribution.
+ 3. Neither the name of authors nor the names of its contributors
+    may be used to endorse or promote products derived from this software
+    without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ SUCH DAMAGE.
+
+*/
+#include <config.h>
+
+#include <qapplication.h>
+#include <QDesktopWidget>
+#include <qlabel.h>
+#include <qwidget.h>
+#include <Q3Header>
+#include <qsocketnotifier.h>
+#include <qstringlist.h>
+#include <qtextcodec.h>
+#include <qrect.h>
+
+#include <locale.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <stdlib.h>
+
+
+#include "qtgettext.h"
+#include "qt4.h"
+
+static const int NR_CANDIDATES = 10;
+static const int MIN_CAND_WIDTH = 80;
+
+const Qt::WFlags candidateFlag = ( Qt::Window
+                                   | Qt::WindowStaysOnTopHint
+                                   | Qt::FramelessWindowHint
+                                   | Qt::Tool
+#if defined(Q_WS_X11)
+                                   | Qt::X11BypassWindowManagerHint
+#endif
+                                 );
+static QSocketNotifier *notifier = NULL;
+
+CandidateWindow::CandidateWindow( QWidget *parent, const char * name )
+        : Q3VBox( parent, name, candidateFlag )
+{
+    setFrameStyle( Raised | NoFrame );
+    setFocusPolicy( Qt::NoFocus );
+
+    //setup CandidateList
+    cList = new CandidateListView( this, "candidateListView" );
+    cList->setSorting( -1 );
+    cList->setSelectionMode( Q3ListView::Single );
+    cList->addColumn( "1" );
+    cList->setColumnWidthMode( 0, Q3ListView::Maximum );
+    cList->addColumn( "2" );
+    cList->setColumnWidthMode( 1, Q3ListView::Maximum );
+    cList->header() ->hide();
+    cList->setVScrollBarMode( Q3ScrollView::AlwaysOff );
+    cList->setHScrollBarMode( Q3ScrollView::AlwaysOff );
+    cList->setAllColumnsShowFocus( true );
+    QObject::connect( cList, SIGNAL( clicked( Q3ListViewItem * ) ),
+ this , SLOT( slotCandidateSelected( Q3ListViewItem * ) ) );
+
+    //setup NumberLabel
+    numLabel = new QLabel( this, "candidateLabel" );
+    numLabel->setFocusPolicy( Qt::NoFocus );
+
+    nrCandidates = 0;
+    candidateIndex = 0;
+    displayLimit = NR_CANDIDATES;
+    pageIndex = -1;
+
+    isActive = false;
+
+    notifier = new QSocketNotifier( 0, QSocketNotifier::Read );
+    QObject::connect( notifier, SIGNAL( activated( int ) ),
+                      this, SLOT( slotStdinActivated( int ) ) );
+    hide();
+}
+
+CandidateWindow::~CandidateWindow()
+{
+    if ( !stores.isEmpty() )
+        stores.clear();
+}
+
+void CandidateWindow::activateCand( const QStringList &list )
+{
+#if defined(ENABLE_DEBUG)
+    qDebug( "uim-helper-candwin-qt: activateCand()" );
+#endif
+    /**
+ * format: activate\ncharset=$charset\ndisplay_limit=$value\nhead1\tcand1\nhead2\tcand2\nhead3\tcand3\n
+     */
+
+    // remove old data
+    cList->clear();
+    stores.clear();
+
+    // get charset and create codec
+    QTextCodec *codec = NULL;
+    if ( !list[ 1 ].isEmpty() && list[ 1 ].startsWith( "charset" ) )
+    {
+        const QStringList l = QStringList::split( "=", list[ 1 ] );
+        codec = QTextCodec::codecForName( l[ 1 ] );
+    }
+
+    // get display_limit
+    if ( !list[ 2 ].isEmpty() && list[ 2 ].startsWith( "display_limit" ) )
+    {
+        const QStringList l = QStringList::split( "=", list[ 2 ] );
+        displayLimit = l[ 1 ].toInt();
+    }
+
+    for ( int i = 3; !list[ i ].isNull(); i++ )
+    {
+        // case list[i] = ""
+        if ( list[ i ].isEmpty() )
+            break;
+
+        // split heading_label and cand_str
+        QStringList l = QStringList::split( "\t", list [ i ], true );
+
+        // store data
+        CandData d;
+        QString headString;
+        if ( codec )
+            headString = codec->toUnicode( l [ 0 ] );
+        else
+            headString = l [ 0 ];
+
+        d.label = headString;
+
+       // XXX Current prime (0.4.6) may return candidate string
+       // containing "\t", and we can't handle annotation in another
+       // window yet.
+       l.pop_front();
+       QString candString = l.join( "\t" );
+
+        if ( codec )
+            d.str = codec->toUnicode( candString );
+        else
+            d.str = candString;
+
+        stores.append( d );
+    }
+
+    // set default value
+    candidateIndex = -1;
+    nrCandidates = stores.count();
+
+    // shift to default page
+    setPage( 0 );
+
+    adjustCandidateWindowSize();
+    show();
+
+    isActive = true;
+}
+void CandidateWindow::selectCand( const QStringList &list )
+{
+#if defined(ENABLE_DEBUG)
+    qDebug( "uim-helper-candwin-qt: selectCand()" );
+#endif
+    const int index = list[ 1 ].toInt();
+    needHilite = (list[ 2 ].toInt() == 1) ? TRUE : FALSE;
+    setIndex( index );
+
+    updateLabel();
+}
+
+void CandidateWindow::moveCand( const QStringList &list )
+{
+#if defined(ENABLE_DEBUG)
+    qDebug( "uim-helper-candwin-qt: moveCand()" );
+#endif
+    if ( list[ 1 ].isEmpty() || list[ 2 ].isEmpty() )
+        return ;
+
+    const int topwin_x = list[ 1 ].toInt();
+    const int topwin_y = list[ 2 ].toInt();
+    const int cw_wi = width();
+    const int cw_he = height();
+    const int sc_wi = QApplication::desktop() ->screenGeometry().width();
+    const int sc_he = QApplication::desktop() ->screenGeometry().height();
+
+    int x, y;
+    if ( sc_wi < topwin_x + cw_wi )
+    {
+        x = topwin_x - cw_wi;
+    }
+    else
+    {
+        x = topwin_x;
+    }
+
+    if ( sc_he < topwin_y + cw_he )
+    {
+        /* FIXME : How can I determine the preedit height? */
+        y = topwin_y - cw_he - 20;
+    }
+    else
+    {
+        y = topwin_y;
+    }
+
+    move( x, y );
+}
+
+void CandidateWindow::showCand()
+{
+#if defined(ENABLE_DEBUG)
+    qDebug( "uim-helper-candwin-qt: showCand()" );
+#endif
+    if ( isActive )
+        show();
+}
+void CandidateWindow::deactivateCand()
+{
+#if defined(ENABLE_DEBUG)
+    qDebug( "uim-helper-candwin-qt: deactivateCand()" );
+#endif
+    hide();
+    isActive = false;
+}
+void CandidateWindow::setNrCandidates( const QStringList &list )
+{
+#if defined(ENABLE_DEBUG)
+    qDebug( "uim-candwin-qt: setNrCandidates()" );
+#endif
+    if ( list[ 1 ].isEmpty() || list[ 2 ].isEmpty() )
+        return ;
+
+    // remove old data
+    cList->clear();
+    stores.clear();
+
+    // set default value
+    candidateIndex = -1;
+    nrCandidates = list[ 1 ].toInt();
+    displayLimit = list[ 2 ].toInt();
+    needHilite = false;
+    isActive = true;
+
+    // setup dummy stores
+    for ( int i = 0; i < nrCandidates; i++ ) {
+       CandData d;
+       stores.append( d );
+    }
+}
+void CandidateWindow::setPageCandidates( const QStringList &list )
+{
+#if defined(ENABLE_DEBUG)
+    qDebug( "uim-candwin-qt: setPageCandidates()" );
+#endif
+    /**
+ * format: set_page_candidates\ncharset=$charset\npage=$value\nhead1\tcand1\nhead2\tcand2\nhead3\tcand3\n
+     */
+
+    int page = 0;
+
+    // get charset and create codec
+    QTextCodec *codec = NULL;
+    if ( !list[ 1 ].isEmpty() && list[ 1 ].startsWith( "charset" ) )
+    {
+        const QStringList l = QStringList::split( "=", list[ 1 ] );
+        codec = QTextCodec::codecForName( l[ 1 ] );
+    }
+
+    // get page
+    if ( !list[ 2 ].isEmpty() && list[ 2 ].startsWith( "page" ) )
+    {
+        const QStringList l = QStringList::split( "=", list[ 2 ] );
+        page = l[ 1 ].toInt();
+    }
+
+    int len = list.length();
+    for ( int i = 3; i < len; i++ )
+    {
+        // case list[i] = ""
+        if ( list[ i ].isEmpty() )
+            break;
+
+        // split heading_label and cand_str
+        QStringList l = QStringList::split( "\t", list [ i ], true );
+
+        // store data
+        CandData &d = stores[page * displayLimit + i - 3];
+        QString headString;
+        if ( codec )
+            headString = codec->toUnicode( l [ 0 ] );
+        else
+            headString = l [ 0 ];
+
+        d.label = headString;
+
+       // XXX Current prime (0.4.6) may return candidate string
+       // containing "\t", and we can't handle annotation in another
+       // window yet.
+       l.pop_front();
+       QString candString = l.join( "\t" );
+
+        if ( codec )
+            d.str = codec->toUnicode( candString );
+        else
+            d.str = candString;
+    }
+}
+void CandidateWindow::showPage( const QStringList &list )
+{
+#if defined(ENABLE_DEBUG)
+    qDebug( "uim-candwin-qt: showPage()" );
+#endif
+    const int page = list[ 1 ].toInt();
+
+    setPage( page );
+    adjustCandidateWindowSize();
+    show();
+}
+void CandidateWindow::slotStdinActivated( int fd )
+{
+    char buf[ 4096 ];
+    char *read_buf = strdup( "" );
+    int n;
+
+    while (uim_helper_fd_readable( fd ) > 0) {
+        n = read( fd, buf, 4096 - 1 );
+        if ( n == 0 )
+        {
+            close( fd );
+            exit( 1 );
+        }
+        if ( n == -1 )
+            return ;
+        buf[ n ] = '\0';
+       read_buf = (char *)realloc( read_buf, strlen( read_buf ) + n + 1 );
+       strcat( read_buf, buf );
+    }
+
+ QStringList msgList = QStringList::split( "\n\n", QString( read_buf ) );
+
+    QStringList::Iterator it = msgList.begin();
+    const QStringList::Iterator end = msgList.end();
+    for ( ; it != end; ++it )
+        strParse( ( *it ) );
+    free( read_buf );
+}
+
+void CandidateWindow::strParse( const QString& str )
+{
+#if defined(ENABLE_DEBUG)
+    qDebug( "str = %s", ( const char* ) str.local8Bit() );
+#endif
+    QStringList list = QStringList::split( "\n", str );
+
+    QStringList::Iterator it = list.begin();
+    const QStringList::Iterator end = list.end();
+    for ( ; it != end; ++it )
+    {
+        if ( QString::compare( "activate", ( *it ) ) == 0 )
+            activateCand( list );
+        else if ( QString::compare( "select", ( *it ) ) == 0 )
+            selectCand( list );
+        else if ( QString::compare( "show", ( *it ) ) == 0 )
+            showCand();
+        else if ( QString::compare( "hide", ( *it ) ) == 0 )
+            hide();
+        else if ( QString::compare( "move", ( *it ) ) == 0 )
+            moveCand( list );
+        else if ( QString::compare( "deactivate", ( *it ) ) == 0 )
+            deactivateCand();
+        else if ( QString::compare( "set_nr_candidates", ( *it ) ) == 0 )
+            setNrCandidates( list );
+        else if ( QString::compare( "set_page_candidates", ( *it ) ) == 0 )
+            setPageCandidates( list );
+        else if ( QString::compare( "show_page", ( *it ) ) == 0 )
+            showPage( list );
+    }
+}
+
+void CandidateWindow::slotCandidateSelected( Q3ListViewItem * item )
+{
+ candidateIndex = ( pageIndex * displayLimit ) + cList->itemIndex( item );
+
+    // write message
+    fprintf( stdout, "index\n" );
+    fprintf( stdout, "%d\n\n", candidateIndex );
+    fflush( stdout );
+
+    updateLabel();
+}
+
+void CandidateWindow::adjustCandidateWindowSize()
+{
+#if defined(ENABLE_DEBUG)
+    qDebug( "adjustCandidateWindowSize()" );
+#endif
+    int width = 0;
+    int height = 0;
+    Q3ListViewItem *item = cList->firstChild();
+    if ( item )
+        height = item->height() * ( cList->childCount() + 1 );
+
+    // 2004-08-02 Kazuki Ohta <[email protected]>
+    // FIXME!:
+ // There may be more proper way. Now width is adjusted by indeterminal 3 spaces.
+    //    Using QWidget::adjustSize() seems not to work properly...
+    unsigned int maxCharIndex = 0, maxCharCount = 0;
+    for ( int i = 0; i < cList->childCount(); i++ )
+    {
+        if ( maxCharCount < cList->itemAtIndex( i ) ->text( 1 ).length() )
+        {
+            maxCharIndex = i;
+            maxCharCount = cList->itemAtIndex( i ) ->text( 1 ).length();
+        }
+    }
+    QFontMetrics fm( cList->font() );
+ width = fm.width( cList->itemAtIndex( maxCharIndex ) ->text( 0 ) + " " + cList->itemAtIndex( maxCharIndex ) ->text( 1 ) );
+    if ( width < MIN_CAND_WIDTH )
+        width = MIN_CAND_WIDTH;
+
+    resize( width, height );
+}
+
+void CandidateWindow::setPage( int page )
+{
+    // clear items
+    cList->clear();
+
+    // calculate page
+    int newpage, lastpage;
+    if ( displayLimit )
+        lastpage = nrCandidates / displayLimit;
+    else
+        lastpage = 0;
+
+    if ( page < 0 )
+    {
+        newpage = lastpage;
+    }
+    else if ( page > lastpage )
+    {
+        newpage = 0;
+    }
+    else
+    {
+        newpage = page;
+    }
+
+    pageIndex = newpage;
+
+    // calculate index
+    int newindex;
+    if ( displayLimit )
+    {
+        if ( candidateIndex >= 0 )
+ newindex = ( newpage * displayLimit ) + ( candidateIndex % displayLimit );
+        else
+            newindex = -1;
+    }
+    else
+    {
+        newindex = candidateIndex;
+    }
+
+    if ( newindex >= nrCandidates )
+        newindex = nrCandidates - 1;
+
+    // set cand items
+    //
+    // If we switch to last page, the number of items to be added
+    // is lower than displayLimit.
+    //
+    // ex. if nrCandidate==14 and displayLimit==10, the number of
+    //     last page's item==4
+    int ncandidates = displayLimit;
+    if ( newpage == lastpage )
+        ncandidates = nrCandidates - displayLimit * lastpage;
+    for ( int i = ncandidates - 1; i >=0 ; i-- )
+    {
+        QString headString = stores[ displayLimit * newpage + i ].label;
+        QString candString = stores[ displayLimit * newpage + i ].str;
+
+        // insert new item to the candidate list
+        new Q3ListViewItem( cList, headString, candString );
+    }
+
+    // set index
+    if ( newindex != candidateIndex )
+        setIndex( newindex );
+    else
+        updateLabel();
+
+    // set candwin size
+    adjustCandidateWindowSize();
+}
+
+void CandidateWindow::setIndex( int index )
+{
+#if defined(ENABLE_DEBUG)
+    qDebug( "setIndex : index = %d", index );
+#endif
+    // validity check
+    if ( index < 0 )
+        candidateIndex = nrCandidates - 1;
+    else if ( index >= nrCandidates )
+        candidateIndex = 0;
+    else
+        candidateIndex = index;
+
+    // set page
+    int newpage = 0;
+    if ( displayLimit )
+        newpage = ( int ) candidateIndex / displayLimit;
+    if ( pageIndex != newpage )
+        setPage( newpage );
+
+    // select item
+    if ( candidateIndex >= 0 && needHilite )
+    {
+        int pos = index;
+        if ( displayLimit )
+            pos = candidateIndex % displayLimit;
+
+ if ( cList->itemAtIndex( pos ) && ! ( cList->itemAtIndex( pos ) ->isSelected() ) )
+            cList->setSelected( cList->itemAtIndex( pos ), true );
+    }
+    else
+    {
+        cList->clearSelection();
+    }
+
+    updateLabel();
+}
+
+void CandidateWindow::updateLabel()
+{
+    QString indexString = QString::null;
+    if ( candidateIndex >= 0 && needHilite )
+ indexString = QString::number( candidateIndex + 1 ) + " / " + QString::number( nrCandidates );
+    else
+        indexString = "- / " + QString::number( nrCandidates );
+
+    numLabel->setText( indexString );
+}
+
+int main( int argc, char *argv[] )
+{
+    setlocale(LC_ALL, "");
+    bindtextdomain(PACKAGE, LOCALEDIR);
+    textdomain(PACKAGE);
+ bind_textdomain_codeset(PACKAGE, "UTF-8"); // ensure code encoding is UTF8-
+
+    QApplication a( argc, argv );
+
+    CandidateWindow b;
+    a.setMainWidget( &b );
+
+    return a.exec();
+}
=======================================
--- /dev/null
+++ /trunk/qt4/candwin/qt4.h    Sat Sep 26 11:30:24 2009
@@ -0,0 +1,143 @@
+/*
+
+ Copyright (c) 2003-2009 uim Project http://code.google.com/p/uim/
+
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+
+ 1. Redistributions of source code must retain the above copyright
+    notice, this list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright
+    notice, this list of conditions and the following disclaimer in the
+    documentation and/or other materials provided with the distribution.
+ 3. Neither the name of authors nor the names of its contributors
+    may be used to endorse or promote products derived from this software
+    without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ SUCH DAMAGE.
+
+*/
+#ifndef UIM_QT4_CANDWIN_QT_H
+#define UIM_QT4_CANDWIN_QT_H
+
+#include <uim/uim.h>
+#include <uim/uim-helper.h>
+
+#include <Q3VBox>
+#include <Q3ListView>
+#include <Q3ValueList>
+
+class QLabel;
+class CandidateListView;
+class QStringList;
+class QPoint;
+
+struct CandData
+{
+    QString label;
+    QString str;
+};
+
+class CandidateWindow : public Q3VBox
+{
+    Q_OBJECT
+public:
+    CandidateWindow( QWidget *parent = 0, const char * name = 0 );
+    ~CandidateWindow();
+
+    void activateCand( const QStringList &list );
+    void selectCand( const QStringList &list );
+    void moveCand( const QStringList &list );
+    void showCand();
+    void deactivateCand();
+
+    void setNrCandidates( const QStringList &list );
+    void setPageCandidates( const QStringList &list );
+    void showPage( const QStringList &list );
+
+public slots:
+    void slotStdinActivated( int );
+    void slotCandidateSelected( Q3ListViewItem* );
+
+protected:
+    void strParse( const QString& str );
+    void adjustCandidateWindowSize();
+
+    void setPage( int page );
+    void setIndex( int index );
+
+    void updateLabel();
+
+protected:
+    CandidateListView *cList;
+    QLabel *numLabel;
+
+    Q3ValueList<CandData> stores;
+
+    int nrCandidates;
+    int candidateIndex;
+    int displayLimit;
+    int pageIndex;
+
+    bool isActive;
+    bool needHilite;
+};
+
+class CandidateListView : public Q3ListView
+{
+    Q_OBJECT
+
+public:
+ CandidateListView( QWidget *parent, const char *name = 0, Qt::WFlags f = 0 ) : Q3ListView( parent, name, f ) {}
+    ~CandidateListView() {}
+
+
+    int itemIndex( const Q3ListViewItem *item ) const
+    {
+        if ( !item )
+            return -1;
+
+        if ( item == firstChild() )
+            return 0;
+        else
+        {
+            Q3ListViewItemIterator it( firstChild() );
+            uint j = 0;
+            for ( ; it.current() && it.current() != item; ++it, ++j ) ;
+
+            if ( !it.current() )
+                return -1;
+            return j;
+        }
+    }
+
+    Q3ListViewItem* itemAtIndex( int index )
+    {
+        if ( index < 0 )
+            return 0;
+
+        int j = 0;
+ for ( Q3ListViewItemIterator it = firstChild(); it.current(); ++it )
+        {
+            if ( j == index )
+                return it.current();
+            j++;
+        };
+        return 0;
+    }
+};
+
+#endif  /* UIM_QT4_CANDWIN_QT_H */
=======================================
--- /dev/null
+++ /trunk/qt4/candwin/uim-candwin-qt4.pro.in   Sat Sep 26 11:30:24 2009
@@ -0,0 +1,23 @@
+TEMPLATE = app
+CONFIG += @QT_CONFIG_OPTS@
+QT += qt3support
+
+INCLUDEPATH += @abs_top_builddir@ @abs_top_builddir@/uim \
+               @abs_top_builddir@/replace ..
+QMAKE_LIBDIR += @abs_top_builddir@/uim
+QMAKE_LIBDIR += @abs_top_builddir@/replace
+LIBS += -lreplace -luim -luim-scm -luim-x-util
+
+QMAKE_CFLAGS_DEBUG     += @CFLAGS@   @X_CFLAGS@
+QMAKE_CFLAGS_RELEASE   += @CFLAGS@   @X_CFLAGS@
+QMAKE_CXXFLAGS_DEBUG   += @CXXFLAGS@ @X_CFLAGS@
+QMAKE_CXXFLAGS_RELEASE += @CXXFLAGS@ @X_CFLAGS@
+
+# Input
+HEADERS += qt4.h
+SOURCES += qt4.cpp
+
+TARGET = uim-candwin-qt4
+
+target.path += @DESTDIR@@exec_prefix@/libexec
+INSTALLS    += target
=======================================
--- /trunk/configure.ac Fri Sep 25 08:58:23 2009
+++ /trunk/configure.ac Sat Sep 26 11:30:24 2009
@@ -892,7 +892,7 @@
 default_toolkit="gtk"
 AC_ARG_ENABLE(default-toolkit,
   AC_HELP_STRING([--enable-default-toolkit],
-                 [Determine default toolkit (gtk or qt)
+                 [Determine default toolkit (gtk, qt, or qt4)
                  @<:@default=gtk@:>@]),
   [
if test x"$enable_default_toolkit" = "xgtk" && test x"$use_gtk2" = "xyes"; then
@@ -901,6 +901,9 @@
if test x"$enable_default_toolkit" = "xqt" && test x"$use_qt" = "xyes"; then
      default_toolkit="qt"
   fi
+ if test x"$enable_default_toolkit" = "xqt4" && test x"$use_qt4" = "xyes"; then
+     default_toolkit="qt4"
+  fi
   ],
   [])

@@ -1076,6 +1079,7 @@
 AM_CONDITIONAL(GTK2_4, test x$use_gtk2_4 = xyes)
 AM_CONDITIONAL(DEFAULT_TOOLKIT_GTK, test x$default_toolkit = xgtk)
 AM_CONDITIONAL(DEFAULT_TOOLKIT_QT,  test x$default_toolkit = xqt)
+AM_CONDITIONAL(DEFAULT_TOOLKIT_QT4, test x$default_toolkit = xqt4)
 AM_CONDITIONAL(APPLET_GNOME, test x$use_applet_gnome = xyes)
 AM_CONDITIONAL(UIM_FEP, test x$use_uim_fep = xyes)
 AM_CONDITIONAL(UIM_EL, test x$use_uim_el = xyes)
@@ -1339,13 +1343,15 @@
        if test x"$default_toolkit" = "xgtk" && \
           test x"$use_gtk2_4" = "xyes"; then
          use_pref="yes"
+       elif test x"$default_toolkit" = "xqt" && \
+            test x"$use_qt" = "xyes"; then
+         use_pref="yes"
+       elif test x"$default_toolkit" = "xqt4" && \
+            test x"$use_qt4" = "xyes"; then
+         use_pref="yes"
        else
-         if test x"$default_toolkit" = "xqt" && test x"$use_qt" = "xyes"; then
-           use_pref="yes"
-         else
-           use_pref="no"
-           AC_MSG_WARN([uim-pref needs Gtk+ or Qt toolkit, disabled...])
-         fi
+         use_pref="no"
+         AC_MSG_WARN([uim-pref needs Gtk+ or Qt toolkit, disabled...])
        fi
        ;;
     esac ],
@@ -1619,6 +1625,8 @@
                 qt/test/Makefile
                 qt/uimapplet.desktop
                 qt4/Makefile
+                qt4/candwin/Makefile
+                qt4/candwin/uim-candwin-qt4.pro
                 qt4/chardict/Makefile
                 qt4/chardict/uim-chardict-qt4.pro
                 qt4/chardict/po/Makefile.in
@@ -1653,6 +1661,8 @@

 # Generate Makefiles for Qt4 by qmake
 if test x$use_qt4 = xyes; then
+    ${QMAKE4} -o ${ac_abs_top_builddir}/qt4/candwin/Makefile.qmake \
+                ${ac_abs_top_srcdir}/qt4/candwin/uim-candwin-qt4.pro
     ${QMAKE4} -o ${ac_abs_top_builddir}/qt4/chardict/Makefile.qmake \
                 ${ac_abs_top_srcdir}/qt4/chardict/uim-chardict-qt4.pro
     ${QMAKE4} -o ${ac_abs_top_builddir}/qt4/pref/Makefile.qmake \
=======================================
--- /trunk/qt4/Makefile.am      Fri Sep 25 08:52:02 2009
+++ /trunk/qt4/Makefile.am      Sat Sep 26 11:30:24 2009
@@ -1,3 +1,3 @@
-SUBDIRS = chardict edittest immodule pref switcher toolbar
+SUBDIRS = candwin chardict edittest immodule pref switcher toolbar

 EXTRA_DIST = qtgettext.h
=======================================
--- /trunk/xim/Makefile.am      Mon Sep 17 05:00:12 2007
+++ /trunk/xim/Makefile.am      Sat Sep 26 11:30:24 2009
@@ -18,6 +18,9 @@
 if DEFAULT_TOOLKIT_QT
 uim_xim_CPPFLAGS += -DUSE_QT_CANDWIN
 endif
+if DEFAULT_TOOLKIT_QT4
+uim_xim_CPPFLAGS += -DUSE_QT4_CANDWIN
+endif

 if WITH_XFT
 uim_xim_CFLAGS += @XFT_CFLAGS@
=======================================
--- /trunk/xim/canddisp.cpp     Tue Jan 20 18:11:15 2009
+++ /trunk/xim/canddisp.cpp     Sat Sep 26 11:30:24 2009
@@ -53,6 +53,8 @@

 #if defined(USE_QT_CANDWIN)
   #define DEFAULT_CANDWIN_PROG (UIM_LIBEXECDIR "/uim-candwin-qt")
+#elif defined(USE_QT4_CANDWIN)
+  #define DEFAULT_CANDWIN_PROG (UIM_LIBEXECDIR "/uim-candwin-qt4")
 #elif defined(USE_GTK_CANDWIN) && defined(USE_GTK2)
   #define DEFAULT_CANDWIN_PROG (UIM_LIBEXECDIR "/uim-candwin-gtk")
 #else

Reply via email to