summaryrefslogtreecommitdiffstats
path: root/tqtinterface/qt4/plugins/src/inputmethods/simple/tqsimpleinputcontext.cpp
diff options
context:
space:
mode:
authorTimothy Pearson <kb9vqf@pearsoncomputing.net>2011-07-23 17:13:36 -0500
committerTimothy Pearson <kb9vqf@pearsoncomputing.net>2011-07-23 17:13:36 -0500
commitd3f7a9d6f1b8f6e24fb49aaa8caeaa7623ae48b5 (patch)
treebaeeba639393f46abab749f4700a250091c3cc16 /tqtinterface/qt4/plugins/src/inputmethods/simple/tqsimpleinputcontext.cpp
parentd7be1694839bacae31e500ea9e36b3c13257ce28 (diff)
downloadexperimental-d3f7a9d6f1b8f6e24fb49aaa8caeaa7623ae48b5.tar.gz
experimental-d3f7a9d6f1b8f6e24fb49aaa8caeaa7623ae48b5.zip
Apply all Qt3.3.8d patches
NOTE: This will *likely* break compilation of TQt4 Please wait a few days for fixes to be committed as needed!
Diffstat (limited to 'tqtinterface/qt4/plugins/src/inputmethods/simple/tqsimpleinputcontext.cpp')
-rw-r--r--tqtinterface/qt4/plugins/src/inputmethods/simple/tqsimpleinputcontext.cpp285
1 files changed, 285 insertions, 0 deletions
diff --git a/tqtinterface/qt4/plugins/src/inputmethods/simple/tqsimpleinputcontext.cpp b/tqtinterface/qt4/plugins/src/inputmethods/simple/tqsimpleinputcontext.cpp
new file mode 100644
index 0000000..d717d74
--- /dev/null
+++ b/tqtinterface/qt4/plugins/src/inputmethods/simple/tqsimpleinputcontext.cpp
@@ -0,0 +1,285 @@
+/****************************************************************************
+** $Id$
+**
+** Implementation of TQSimpleInputContext class
+**
+** Copyright (C) 2004 immodule for TQt Project. All rights reserved.
+**
+** This file is written to contribute to Trolltech AS under their own
+** licence. You may use this file under your TQt license. Following
+** description is copied from their original file headers. Contact
+** immodule-qt@freedesktop.org if any conditions of this licensing are
+** not clear to you.
+**
+**
+** This file is part of the input method module of the TQt 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.TQPL 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 TQt Enterprise Edition or TQt Professional Edition
+** licenses may use this file in accordance with the TQt 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 sales@trolltech.com for
+** information about TQt Commercial License Agreements.
+** See http://www.trolltech.com/qpl/ for TQPL licensing information.
+** See http://www.trolltech.com/gpl/ for GPL licensing information.
+**
+** Contact info@trolltech.com if any conditions of this licensing are
+** not clear to you.
+**
+**********************************************************************/
+
+#include "tqsimpleinputcontext.h"
+
+#include <tqnamespace.h>
+#include <tqevent.h>
+#include <tqglobal.h>
+#include <algorithm>
+
+static const int ignoreKeys[] = {
+ TQt::Key_Shift,
+ TQt::Key_Control,
+ TQt::Key_Meta,
+ TQt::Key_Alt,
+ TQt::Key_CapsLock,
+ TQt::Key_Super_L,
+ TQt::Key_Super_R,
+ TQt::Key_Hyper_L,
+ TQt::Key_Hyper_R,
+ TQt::Key_Mode_switch
+};
+
+static const int composingKeys[] = {
+ TQt::Key_Multi_key,
+ TQt::Key_Dead_Grave,
+ TQt::Key_Dead_Acute,
+ TQt::Key_Dead_Circumflex,
+ TQt::Key_Dead_Tilde,
+ TQt::Key_Dead_Macron,
+ TQt::Key_Dead_Breve,
+ TQt::Key_Dead_Abovedot,
+ TQt::Key_Dead_Diaeresis,
+ TQt::Key_Dead_Abovering,
+ TQt::Key_Dead_Doubleacute,
+ TQt::Key_Dead_Caron,
+ TQt::Key_Dead_Cedilla,
+ TQt::Key_Dead_Ogonek,
+ TQt::Key_Dead_Iota,
+ TQt::Key_Dead_Voiced_Sound,
+ TQt::Key_Dead_Semivoiced_Sound,
+ TQt::Key_Dead_Belowdot,
+ TQt::Key_Dead_Hook,
+ TQt::Key_Dead_Horn
+};
+
+class Cmp
+{
+public:
+ bool operator () (const TQComposeTableElement &lhs, const TQComposeTableElement &rhs) const {
+ for ( size_t i=0; i < TQT_KEYSEQUENCE_MAX_LEN; i++ ) {
+ if ( lhs.keys[i] < rhs.keys[i] ) return TRUE;
+ else
+ if ( lhs.keys[i] > rhs.keys[i] ) return FALSE;
+ }
+ return FALSE;
+ }
+
+ bool operator () (const TQComposeTableElement &lhs, const uint rhs[TQT_KEYSEQUENCE_MAX_LEN]) const {
+ for ( size_t i=0; i < TQT_KEYSEQUENCE_MAX_LEN; i++ ) {
+ if ( lhs.keys[i] < rhs[i] ) return TRUE;
+ else
+ if ( lhs.keys[i] > rhs[i] ) return FALSE;
+ }
+ return FALSE;
+ }
+};
+
+TQSimpleInputContext::TQSimpleInputContext()
+ : TQInputContext()
+{
+ clearComposeBuffer();
+}
+
+TQSimpleInputContext::~TQSimpleInputContext()
+{
+ clearComposeBuffer();
+}
+
+bool TQSimpleInputContext::filterEvent( const TQEvent *event )
+{
+ if ( event->type() != TQEvent::KeyPress )
+ return FALSE;
+
+ TQKeyEvent *keyevent = (TQKeyEvent *)event;
+ int keyval = keyevent->key();
+ int val = 0;
+
+ if ( isIgnoreKeys( keyval ) )
+ return FALSE;
+
+ if ( isComposingKeys( keyval ) ) {
+ // If composing keys are pressed, use keyval directly
+ val = UNITIZE( keyval );
+ } else {
+ TQString text = keyevent->text();
+ if ( text.isEmpty() )
+ return FALSE;
+
+ // If not composing keys are pressed, use the character's tqunicode value
+ // NOTE : The contents of TQKeyEvent::text() is restricted to
+ // only one character. See description of
+ // TQInputContext::filterEvent() about key compression.
+ val = text[0].tqunicode();
+ // qDebug( "str = %s", (const char*)keyevent->text().local8Bit() );
+ }
+
+ // Store value
+ int nCompose = 0;
+ while ( composeBuffer[nCompose] != 0 && nCompose < TQT_KEYSEQUENCE_MAX_LEN )
+ nCompose++;
+
+ if ( nCompose == TQT_KEYSEQUENCE_MAX_LEN ) {
+ clearComposeBuffer();
+ nCompose = 0;
+ }
+
+ composeBuffer[nCompose] = val;
+
+ // check sequence
+ if( checkComposeTable( composeBuffer, &defaultComposeTable ) )
+ return TRUE;
+
+ return FALSE;
+}
+
+void TQSimpleInputContext::setFocus()
+{
+ //qDebug( "TQSimpleInputContext: %p->setFocus(), tqfocusWidget()=%p",
+ //this, tqfocusWidget() );
+}
+
+void TQSimpleInputContext::unsetFocus()
+{
+ //qDebug( "TQSimpleInputContext: %p->unsetFocus(), tqfocusWidget()=%p",
+ //this, tqfocusWidget() );
+ reset();
+}
+
+void TQSimpleInputContext::setMicroFocus( int x, int y, int w, int h, TQFont *f )
+{
+}
+
+void TQSimpleInputContext::mouseHandler( int x, TQEvent::Type type,
+ TQt::ButtonState button,
+ TQt::ButtonState state )
+{
+ switch ( type ) {
+ case TQEvent::MouseButtonPress:
+ case TQEvent::MouseButtonRelease:
+ case TQEvent::MouseButtonDblClick:
+ case TQEvent::MouseMove:
+ // qDebug( "TQSimpleInputContext::mouseHandler: "
+ // "x=%d, type=%d, button=%d, state=%d", x, type, button, state );
+ break;
+ default:
+ break;
+ }
+}
+
+
+void TQSimpleInputContext::reset()
+{
+ clearComposeBuffer();
+ TQInputContext::reset();
+}
+
+TQString TQSimpleInputContext::identifierName()
+{
+ return "simple";
+}
+
+TQString TQSimpleInputContext::language()
+{
+ return ""; // FIXME
+}
+
+bool TQSimpleInputContext::isIgnoreKeys( int keyval )
+{
+ for ( uint i = 0; i < (sizeof(ignoreKeys)/sizeof(ignoreKeys[0])); i++ )
+ if ( keyval == ignoreKeys[i] )
+ return TRUE;
+
+ return FALSE;
+}
+
+bool TQSimpleInputContext::isComposingKeys( int keyval )
+{
+ for ( uint i = 0; i < (sizeof(composingKeys)/sizeof(composingKeys[0])); i++ )
+ if ( keyval == composingKeys[i] )
+ return TRUE;
+
+ return FALSE;
+}
+
+bool TQSimpleInputContext::checkComposeTable( uint* composeBuffer, const TQComposeTable *composeTable )
+{
+ const TQComposeTableElement *p = std::lower_bound( composeTable->data,
+ composeTable->data + composeTable->size,
+ composeBuffer,
+ Cmp() );
+
+ // no entries were found
+ if ( p == composeTable->data + composeTable->size ) {
+ // qDebug( "no match" );
+ clearComposeBuffer();
+ return FALSE;
+ }
+
+ // check if compose buffer is matched
+ for ( int i=0; i < TQT_KEYSEQUENCE_MAX_LEN; i++ ) {
+
+ // check if partial match
+ if ( composeBuffer[i] == 0 && p->keys[i] ) {
+ // qDebug("partial match");
+ return TRUE;
+ }
+
+ if ( composeBuffer[i] != p->keys[i] ) {
+ // qDebug("different entry");
+ clearComposeBuffer();
+ return i!=0;
+ }
+ }
+
+ // qDebug("match exactly");
+
+ // match exactly
+ commitChar( p->value );
+ clearComposeBuffer();
+
+ return TRUE;
+}
+
+void TQSimpleInputContext::commitChar( uint c )
+{
+ sendIMEvent( TQEvent::IMStart );
+ sendIMEvent( TQEvent::IMEnd, TQString(TQChar(c)) );
+}
+
+void TQSimpleInputContext::clearComposeBuffer(void)
+{
+ for ( uint i=0; i < (sizeof(composeBuffer)/sizeof(int)); i++ )
+ composeBuffer[i] = 0;
+}
+