summaryrefslogtreecommitdiffstats
path: root/plugins/src/inputmethods/imsw-multi
diff options
context:
space:
mode:
authorTimothy Pearson <[email protected]>2011-07-10 15:24:15 -0500
committerTimothy Pearson <[email protected]>2011-07-10 15:24:15 -0500
commitbd0f3345a938b35ce6a12f6150373b0955b8dd12 (patch)
tree7a520322212d48ebcb9fbe1087e7fca28b76185c /plugins/src/inputmethods/imsw-multi
downloadqt3-bd0f3345a938b35ce6a12f6150373b0955b8dd12.tar.gz
qt3-bd0f3345a938b35ce6a12f6150373b0955b8dd12.zip
Add Qt3 development HEAD version
Diffstat (limited to 'plugins/src/inputmethods/imsw-multi')
-rw-r--r--plugins/src/inputmethods/imsw-multi/imsw-multi.pro14
-rw-r--r--plugins/src/inputmethods/imsw-multi/qmultiinputcontext.cpp379
-rw-r--r--plugins/src/inputmethods/imsw-multi/qmultiinputcontext.h124
-rw-r--r--plugins/src/inputmethods/imsw-multi/qmultiinputcontextplugin.cpp88
-rw-r--r--plugins/src/inputmethods/imsw-multi/qmultiinputcontextplugin.h63
5 files changed, 668 insertions, 0 deletions
diff --git a/plugins/src/inputmethods/imsw-multi/imsw-multi.pro b/plugins/src/inputmethods/imsw-multi/imsw-multi.pro
new file mode 100644
index 0000000..a333916
--- /dev/null
+++ b/plugins/src/inputmethods/imsw-multi/imsw-multi.pro
@@ -0,0 +1,14 @@
+TEMPLATE = lib
+TARGET = qimsw-multi
+DESTDIR = ../../../inputmethods
+
+INCLUDEPATH += .
+CONFIG += qt warn_on debug plugin
+target.path += $$plugins.path/inputmethods
+INSTALLS += target
+
+# Input
+HEADERS += qmultiinputcontext.h \
+ qmultiinputcontextplugin.h
+SOURCES += qmultiinputcontext.cpp \
+ qmultiinputcontextplugin.cpp
diff --git a/plugins/src/inputmethods/imsw-multi/qmultiinputcontext.cpp b/plugins/src/inputmethods/imsw-multi/qmultiinputcontext.cpp
new file mode 100644
index 0000000..42791a4
--- /dev/null
+++ b/plugins/src/inputmethods/imsw-multi/qmultiinputcontext.cpp
@@ -0,0 +1,379 @@
+/****************************************************************************
+** $Id$
+**
+** Implementation of QMultiInputContext class
+**
+** Copyright (C) 2004 immodule for Qt Project. All rights reserved.
+**
+** This file is written to contribute to Trolltech AS under their own
+** licence. You may use this file under your Qt license. Following
+** description is copied from their original file headers. Contact
+** [email protected] if any conditions of this licensing are
+** not clear to you.
+**
+**
+** This file is part of the input method module of the Qt GUI Toolkit.
+**
+** This file may be distributed under the terms of the Q Public License
+** as defined by Trolltech AS of Norway and appearing in the file
+** LICENSE.QPL included in the packaging of this file.
+**
+** This file may be distributed and/or modified under the terms of the
+** GNU General Public License version 2 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file.
+**
+** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
+** licenses may use this file in accordance with the Qt Commercial License
+** Agreement provided with the Software.
+**
+** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
+** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+**
+** See http://www.trolltech.com/pricing.html or email [email protected] for
+** information about Qt Commercial License Agreements.
+** See http://www.trolltech.com/qpl/ for QPL licensing information.
+** See http://www.trolltech.com/gpl/ for GPL licensing information.
+**
+** Contact [email protected] if any conditions of this licensing are
+** not clear to you.
+**
+**********************************************************************/
+
+#ifndef QT_NO_IM
+#include "qmultiinputcontext.h"
+#include <qinputcontextfactory.h>
+#include <qstringlist.h>
+#include <qpopupmenu.h>
+#ifndef QT_NO_IM_EXTENSIONS
+#include <qsettings.h>
+#endif
+
+#include <cstdlib>
+
+#define QT_NO_IM_QMULTIINPUTCONTEXT_IMINDEX
+
+QMultiInputContext::QMultiInputContext()
+ : QInputContext(), _slave( 0 ), imIndex( 0 ), cachedFocus( FALSE ),
+ cachedFocusWidget( 0 ), cachedHolderWidget( 0 ),
+ beIndirectlyConnected( FALSE ), popup( NULL ), currentIMKey( QString::null )
+{
+ keyDict.setAutoDelete( true );
+ keyDict.clear();
+
+ if ( getenv( "QT_IM_MODULE" ) ) {
+ currentIMKey = getenv( "QT_IM_MODULE" );
+ } else {
+#ifndef QT_NO_IM_EXTENSIONS
+ QSettings settings;
+ currentIMKey = settings.readEntry( "/qt/DefaultInputMethod", "xim" );
+#else
+ currentIMKey = "xim";
+#endif
+ }
+}
+
+QMultiInputContext::~QMultiInputContext()
+{
+ keyDict.clear();
+}
+
+
+QString QMultiInputContext::identifierName()
+{
+ return ( slave() ) ? slave()->identifierName() : "";
+}
+
+QString QMultiInputContext::language()
+{
+ return ( slave() ) ? slave()->language() : "";
+}
+
+
+#if defined(Q_WS_X11)
+bool QMultiInputContext::x11FilterEvent( QWidget *keywidget, XEvent *event )
+{
+ return ( slave() ) ? slave()->x11FilterEvent( keywidget, event ) : FALSE;
+}
+#endif // Q_WS_X11
+
+
+bool QMultiInputContext::filterEvent( const QEvent *event )
+{
+#if !defined(QT_NO_IM_QMULTIINPUTCONTEXT_IMINDEX)
+ if ( event->type() == QEvent::KeyPress ) {
+ QKeyEvent *keyevent = (QKeyEvent *)event;
+
+ // filter selection key
+ // Control+Alt+Key_Down: change to next input method
+ // Control+Alt+Key_Up: change to previous input method
+ if ( ( keyevent->state() & Qt::ControlButton ) &&
+ ( keyevent->state() & Qt::AltButton ) ) {
+ if ( keyevent->key() == Qt::Key_Up ) {
+ changeInputMethod( --imIndex );
+ return TRUE;
+ } else if ( keyevent->key() == Qt::Key_Down ) {
+ changeInputMethod( ++imIndex );
+ return TRUE;
+ }
+ }
+ }
+#endif
+
+ return ( slave() ) ? slave()->filterEvent( event ) : FALSE;
+}
+
+void QMultiInputContext::reset()
+{
+ if ( slave() )
+ slave()->reset();
+}
+
+
+void QMultiInputContext::setFocus()
+{
+ cachedFocus = TRUE;
+ if ( slave() )
+ slave()->setFocus();
+}
+
+void QMultiInputContext::unsetFocus()
+{
+ cachedFocus = FALSE;
+ if ( slave() )
+ slave()->unsetFocus();
+}
+
+void QMultiInputContext::setMicroFocus( int x, int y, int w, int h, QFont *f )
+{
+ if ( slave() )
+ slave()->setMicroFocus( x, y, w, h, f );
+}
+
+void QMultiInputContext::mouseHandler( int x, QEvent::Type type,
+ Qt::ButtonState button,
+ Qt::ButtonState state )
+{
+ if ( slave() )
+ slave()->mouseHandler( x, type, button, state );
+}
+
+QFont QMultiInputContext::font() const
+{
+ return ( slave() ) ? slave()->font() : QInputContext::font();
+}
+
+void QMultiInputContext::destroyInputContext()
+{
+ if ( _slave ) {
+ // _slave->reset() may not properly work in the case, so we
+ // manually resets the composing state of text widget
+ if ( _slave->focusWidget() ) {
+ QIMEvent *terminator = new QIMEvent( QEvent::IMEnd, QString::null, -1 );
+ emit imEventGenerated( _slave->focusWidget(), terminator );
+ }
+ _slave->deleteLater();
+ _slave = 0;
+ }
+}
+
+
+/*!
+ This function is a placeholder for future experiment or extension
+ such as commit string snooping. set beIndirectlyConnected = TRUE
+ to activate this virtual function.
+*/
+void QMultiInputContext::postIMEvent( QObject *receiver, QIMEvent *event )
+{
+ emit imEventGenerated( receiver, event );
+}
+
+
+#if defined(Q_WS_X11)
+QWidget *QMultiInputContext::focusWidget() const
+{
+ return ( slave() ) ? slave()->focusWidget() : 0;
+}
+
+QWidget *QMultiInputContext::holderWidget() const
+{
+ return ( slave() ) ? slave()->holderWidget() : 0;
+}
+
+
+void QMultiInputContext::setFocusWidget( QWidget *w )
+{
+ cachedFocusWidget = w;
+ if ( slave() )
+ slave()->setFocusWidget( w );
+}
+
+void QMultiInputContext::setHolderWidget( QWidget *w )
+{
+ cachedHolderWidget = w;
+ if ( slave() )
+ slave()->setHolderWidget( w );
+}
+
+void QMultiInputContext::releaseComposingWidget( QWidget *w )
+{
+ if ( slave() )
+ slave()->releaseComposingWidget( w );
+}
+
+#endif
+
+bool QMultiInputContext::isComposing() const
+{
+ return ( slave() ) ? slave()->isComposing() : FALSE;
+}
+
+bool QMultiInputContext::isPreeditRelocationEnabled()
+{
+ return ( slave() ) ? slave()->isPreeditRelocationEnabled() : FALSE;
+}
+
+QInputContext *QMultiInputContext::slave()
+{
+ if ( ! _slave ) {
+#if !defined(QT_NO_IM_QMULTIINPUTCONTEXT_IMINDEX)
+ changeInputMethod( imIndex );
+#else
+ changeInputMethod( currentIMKey );
+#endif
+ }
+
+ return _slave;
+}
+
+const QInputContext *QMultiInputContext::slave() const
+{
+ return _slave;
+}
+
+void QMultiInputContext::changeInputMethod( int newIndex )
+{
+#if !defined(QT_NO_IM_QMULTIINPUTCONTEXT_IMINDEX)
+ QStringList keys = QInputContextFactory::keys();
+ if ( keys.size() == 0 )
+ return;
+
+ if ( newIndex >= (int)keys.size() ) {
+ imIndex = 0;
+ } else if ( newIndex < 0 ) {
+ imIndex = keys.size() - 1;
+ } else {
+ imIndex = newIndex;
+ }
+
+ changeInputMethod( keys[imIndex] );
+#endif
+}
+
+void QMultiInputContext::changeInputMethod( QString key )
+{
+ QStringList keys = QInputContextFactory::keys();
+ if ( keys.size() == 0 )
+ return;
+
+ if ( key.isEmpty() )
+ key = keys[0];
+
+ if ( _slave ) {
+ _slave->reset();
+ delete _slave;
+ }
+
+ _slave = QInputContextFactory::create( key, cachedHolderWidget );
+ if ( _slave ) {
+ insertChild( _slave );
+
+ const char *method;
+ if ( beIndirectlyConnected ) {
+ method = SLOT(imEventReceived(QObject *,QIMEvent *));
+ } else {
+ method = SIGNAL(imEventGenerated(QObject *,QIMEvent *));
+ }
+ connect( _slave, SIGNAL(imEventGenerated(QObject *,QIMEvent *)),
+ this, method );
+ connect( _slave, SIGNAL(deletionRequested()),
+ this, SLOT(destroyInputContext()) );
+
+ if ( cachedFocus ) {
+ _slave->setFocus();
+ _slave->setFocusWidget( cachedFocusWidget );
+ }
+
+ currentIMKey = key;
+
+ //qDebug( "QMultiInputContext::changeInputMethod(): index=%d, slave=%s",
+ // imIndex, (const char *)_slave->identifierName() );
+ }
+}
+
+QPtrList<QInputContextMenu> *QMultiInputContext::menus()
+{
+ QInputContextMenu *imSelMenu = new QInputContextMenu;
+ imSelMenu->title = tr( "Select Input &Method" );
+ imSelMenu->popup = createImSelPopup();
+
+ QPtrList<QInputContextMenu> *result = new QPtrList<QInputContextMenu>;
+ result->append( imSelMenu );
+
+ QPtrList<QInputContextMenu> *slaveMenus = ( slave() ) ? slave()->menus() : 0;
+ if ( slaveMenus ) {
+ for ( QPtrList<QInputContextMenu>::Iterator it = slaveMenus->begin();
+ it != slaveMenus->end();
+ ++it ) {
+ QInputContextMenu *slaveMenu = *it;
+ result->append( slaveMenu );
+ }
+ delete slaveMenus;
+ }
+
+ return result;
+}
+
+QPopupMenu *QMultiInputContext::createImSelPopup()
+{
+ if ( popup )
+ delete popup;
+
+ popup = new QPopupMenu();
+ keyDict.clear();
+
+ QStringList keys = QInputContextFactory::keys();
+ for ( uint i=0; i < keys.size(); i++ ) {
+ QString idName = keys[i];
+ bool isIMSwitcher = idName.startsWith( "imsw-" );
+
+ if ( ! isIMSwitcher ) {
+ QString dispName = QInputContextFactory::displayName( idName );
+ if ( dispName.isEmpty() )
+ dispName = idName;
+
+ int id = popup->insertItem( dispName );
+ keyDict.insert( (long)id, new QString( idName ) );
+
+ if ( idName == currentIMKey )
+ popup->setItemChecked( id, true );
+
+ QString descriptionStr = QInputContextFactory::description( idName );
+ if ( ! descriptionStr.isEmpty() )
+ popup->setWhatsThis( id, descriptionStr );
+ }
+ }
+
+ QObject::connect( popup, SIGNAL(activated(int)),
+ this, SLOT(changeInputMethodWithMenuId(int)) );
+
+ return popup;
+}
+
+void QMultiInputContext::changeInputMethodWithMenuId( int menuid )
+{
+ QString *key = keyDict.find( (long)menuid );
+ changeInputMethod( (*key) );
+}
+
+#endif
diff --git a/plugins/src/inputmethods/imsw-multi/qmultiinputcontext.h b/plugins/src/inputmethods/imsw-multi/qmultiinputcontext.h
new file mode 100644
index 0000000..05eebe5
--- /dev/null
+++ b/plugins/src/inputmethods/imsw-multi/qmultiinputcontext.h
@@ -0,0 +1,124 @@
+/****************************************************************************
+** $Id$
+**
+** Definition of QMultiInputContext class
+**
+** Copyright (C) 2004 immodule for Qt Project. All rights reserved.
+**
+** This file is written to contribute to Trolltech AS under their own
+** licence. You may use this file under your Qt license. Following
+** description is copied from their original file headers. Contact
+** [email protected] if any conditions of this licensing are
+** not clear to you.
+**
+**
+** This file is part of the input method module of the Qt GUI Toolkit.
+**
+** This file may be distributed under the terms of the Q Public License
+** as defined by Trolltech AS of Norway and appearing in the file
+** LICENSE.QPL included in the packaging of this file.
+**
+** This file may be distributed and/or modified under the terms of the
+** GNU General Public License version 2 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file.
+**
+** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
+** licenses may use this file in accordance with the Qt Commercial License
+** Agreement provided with the Software.
+**
+** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
+** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+**
+** See http://www.trolltech.com/pricing.html or email [email protected] for
+** information about Qt Commercial License Agreements.
+** See http://www.trolltech.com/qpl/ for QPL licensing information.
+** See http://www.trolltech.com/gpl/ for GPL licensing information.
+**
+** Contact [email protected] if any conditions of this licensing are
+** not clear to you.
+**
+**********************************************************************/
+
+#ifndef QMULTIINPUTCONTEXT_H
+#define QMULTIINPUTCONTEXT_H
+
+#ifndef QT_NO_IM
+
+#include <qnamespace.h>
+#include <qwidget.h>
+#include <qinputcontext.h>
+#include <qguardedptr.h>
+#include <qintdict.h>
+
+class QPopupMenu;
+
+class QMultiInputContext : public QInputContext
+{
+ Q_OBJECT
+public:
+ QMultiInputContext();
+ ~QMultiInputContext();
+
+ QString identifierName();
+ QString language();
+
+#if defined(Q_WS_X11)
+ bool x11FilterEvent( QWidget *keywidget, XEvent *event );
+#endif // Q_WS_X11
+ bool filterEvent( const QEvent *event );
+ void reset();
+
+ void setFocus();
+ void unsetFocus();
+ void setMicroFocus( int x, int y, int w, int h, QFont *f = 0 );
+ void mouseHandler( int x, QEvent::Type type,
+ Qt::ButtonState button, Qt::ButtonState state );
+ QFont font() const;
+ bool isComposing() const;
+ bool isPreeditRelocationEnabled();
+
+#if (QT_VERSION-0 >= 0x040000)
+ QPtrList<QMenu> *qt4menus();
+#endif
+ QPtrList<QInputContextMenu> *menus();
+ QPopupMenu *createImSelPopup();
+
+#if defined(Q_WS_X11)
+ QWidget *focusWidget() const;
+ QWidget *holderWidget() const;
+
+ void setFocusWidget( QWidget *w );
+ void setHolderWidget( QWidget *w );
+ void releaseComposingWidget( QWidget *w );
+#endif
+
+public slots:
+ virtual void destroyInputContext();
+ virtual void postIMEvent( QObject *receiver, QIMEvent *event );
+
+protected slots:
+ void changeInputMethodWithMenuId( int menuid );
+
+protected:
+ QInputContext *slave();
+ const QInputContext *slave() const;
+
+ void changeInputMethod( int newIndex );
+ void changeInputMethod( QString name );
+
+ QInputContext *_slave;
+ int imIndex;
+ bool cachedFocus;
+ QWidget *cachedFocusWidget;
+ QWidget *cachedHolderWidget;
+ bool beIndirectlyConnected;
+
+ QIntDict<QString> keyDict;
+ QGuardedPtr<QPopupMenu> popup;
+ QString currentIMKey;
+};
+
+#endif //Q_NO_IM
+
+#endif // QMULTIINPUTCONTEXT_H
diff --git a/plugins/src/inputmethods/imsw-multi/qmultiinputcontextplugin.cpp b/plugins/src/inputmethods/imsw-multi/qmultiinputcontextplugin.cpp
new file mode 100644
index 0000000..7527297
--- /dev/null
+++ b/plugins/src/inputmethods/imsw-multi/qmultiinputcontextplugin.cpp
@@ -0,0 +1,88 @@
+/****************************************************************************
+** $Id$
+**
+** Implementation of QMultiInputContextPlugin class
+**
+** Copyright (C) 2004 immodule for Qt Project. All rights reserved.
+**
+** This file is written to contribute to Trolltech AS under their own
+** licence. You may use this file under your Qt license. Following
+** description is copied from their original file headers. Contact
+** [email protected] if any conditions of this licensing are
+** not clear to you.
+**
+**
+** This file is part of the input method module of the Qt GUI Toolkit.
+**
+** This file may be distributed under the terms of the Q Public License
+** as defined by Trolltech AS of Norway and appearing in the file
+** LICENSE.QPL included in the packaging of this file.
+**
+** This file may be distributed and/or modified under the terms of the
+** GNU General Public License version 2 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file.
+**
+** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
+** licenses may use this file in accordance with the Qt Commercial License
+** Agreement provided with the Software.
+**
+** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
+** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+**
+** See http://www.trolltech.com/pricing.html or email [email protected] for
+** information about Qt Commercial License Agreements.
+** See http://www.trolltech.com/qpl/ for QPL licensing information.
+** See http://www.trolltech.com/gpl/ for GPL licensing information.
+**
+** Contact [email protected] if any conditions of this licensing are
+** not clear to you.
+**
+**********************************************************************/
+
+#ifndef QT_NO_IM
+#include "qmultiinputcontext.h"
+#include "qmultiinputcontextplugin.h"
+#include <qinputcontextplugin.h>
+#include <qstringlist.h>
+
+
+QMultiInputContextPlugin::QMultiInputContextPlugin()
+{
+}
+
+QMultiInputContextPlugin::~QMultiInputContextPlugin()
+{
+}
+
+QStringList QMultiInputContextPlugin::keys() const
+{
+ // input method switcher should named with "imsw-" prefix to
+ // prevent to be listed in ordinary input method list.
+ return QStringList( "imsw-multi" );
+}
+
+QInputContext *QMultiInputContextPlugin::create( const QString &key )
+{
+ return new QMultiInputContext;
+}
+
+QStringList QMultiInputContextPlugin::languages( const QString &key )
+{
+ return QStringList( "" );
+}
+
+QString QMultiInputContextPlugin::displayName( const QString &key )
+{
+ return tr( "Multiple Input Method Switcher" );
+}
+
+QString QMultiInputContextPlugin::description( const QString &key )
+{
+ return tr( "Multiple input method switcher that uses the context menu of the text widgets" );
+}
+
+
+Q_EXPORT_PLUGIN( QMultiInputContextPlugin )
+
+#endif
diff --git a/plugins/src/inputmethods/imsw-multi/qmultiinputcontextplugin.h b/plugins/src/inputmethods/imsw-multi/qmultiinputcontextplugin.h
new file mode 100644
index 0000000..a93ded4
--- /dev/null
+++ b/plugins/src/inputmethods/imsw-multi/qmultiinputcontextplugin.h
@@ -0,0 +1,63 @@
+/****************************************************************************
+** $Id$
+**
+** Definition of QMultiInputContextPlugin class
+**
+** Copyright (C) 2004 immodule for Qt Project. All rights reserved.
+**
+** This file is written to contribute to Trolltech AS under their own
+** licence. You may use this file under your Qt license. Following
+** description is copied from their original file headers. Contact
+** [email protected] if any conditions of this licensing are
+** not clear to you.
+**
+**
+** This file is part of the input method module of the Qt GUI Toolkit.
+**
+** This file may be distributed under the terms of the Q Public License
+** as defined by Trolltech AS of Norway and appearing in the file
+** LICENSE.QPL included in the packaging of this file.
+**
+** This file may be distributed and/or modified under the terms of the
+** GNU General Public License version 2 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file.
+**
+** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
+** licenses may use this file in accordance with the Qt Commercial License
+** Agreement provided with the Software.
+**
+** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
+** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+**
+** See http://www.trolltech.com/pricing.html or email [email protected] for
+** information about Qt Commercial License Agreements.
+** See http://www.trolltech.com/qpl/ for QPL licensing information.
+** See http://www.trolltech.com/gpl/ for GPL licensing information.
+**
+** Contact [email protected] if any conditions of this licensing are
+** not clear to you.
+**
+**********************************************************************/
+
+#ifndef QT_NO_IM
+#include "qmultiinputcontext.h"
+#include <qinputcontextplugin.h>
+#include <qstringlist.h>
+
+
+class QMultiInputContextPlugin : public QInputContextPlugin
+{
+ Q_OBJECT
+public:
+ QMultiInputContextPlugin();
+ ~QMultiInputContextPlugin();
+
+ QStringList keys() const;
+ QInputContext *create( const QString &key );
+ QStringList languages( const QString &key );
+ QString displayName( const QString &key );
+ QString description( const QString &key );
+};
+
+#endif