diff options
| author | nyamatongwe <unknown> | 2003-03-13 12:52:57 +0000 | 
|---|---|---|
| committer | nyamatongwe <unknown> | 2003-03-13 12:52:57 +0000 | 
| commit | 3712f66d6b8eb6b1fdb5947a51f2b9cf12a72e6c (patch) | |
| tree | d403baa3d727ad6053879ce4f2f26c03f3d02f25 | |
| parent | 10421345bc397d87316f66f88cf57e7431a87cbb (diff) | |
| download | scintilla-mirror-3712f66d6b8eb6b1fdb5947a51f2b9cf12a72e6c.tar.gz | |
Handling Unicode keys by transforming to UTF-8.
| -rw-r--r-- | gtk/ScintillaGTK.cxx | 47 | 
1 files changed, 36 insertions, 11 deletions
| diff --git a/gtk/ScintillaGTK.cxx b/gtk/ScintillaGTK.cxx index e0fd95a99..f4de1f772 100644 --- a/gtk/ScintillaGTK.cxx +++ b/gtk/ScintillaGTK.cxx @@ -41,6 +41,7 @@  #include "Editor.h"  #include "SString.h"  #include "ScintillaBase.h" +#include "UniConversion.h"  #include "gtk/gtksignal.h"  #include "gtk/gtkmarshal.h" @@ -169,6 +170,7 @@ private:  	static gint ScrollEvent(GtkWidget *widget, GdkEventScroll *event);  #endif  	static gint Motion(GtkWidget *widget, GdkEventMotion *event); +	gint KeyThis(GdkEventKey *event);  	static gint KeyPress(GtkWidget *widget, GdkEventKey *event);  	static gint KeyRelease(GtkWidget *widget, GdkEventKey *event);  	static void Destroy(GtkObject *object); @@ -827,9 +829,26 @@ void ScintillaGTK::NotifyURIDropped(const char *list) {  }  int ScintillaGTK::KeyDefault(int key, int modifiers) { -	if (!(modifiers & SCI_CTRL) && !(modifiers & SCI_ALT) && (key < 256)) { -		AddChar(key); -		return 1; +	if (!(modifiers & SCI_CTRL) && !(modifiers & SCI_ALT)) { +#if GTK_MAJOR_VERSION >= 2 +		if (IsUnicodeMode() && (key <= 0xFE00)) { +			char utfval[4]="\0\0\0"; +			wchar_t wcs[2]; +			wcs[0] = gdk_keyval_to_unicode(key); +			wcs[1] = 0; +			UTF8FromUCS2(wcs, 1, utfval, 3); +			AddCharUTF(utfval,strlen(utfval)); +			return 1; +		} +#endif +		if (key < 256) { +			AddChar(key); +			return 1; +		} else { +			// Pass up to container in case it is an accelerator +			NotifyKey(key, modifiers); +			return 0; +		}  	} else {  		// Pass up to container in case it is an accelerator  		NotifyKey(key, modifiers); @@ -1416,8 +1435,7 @@ static int KeyTranslate(int keyIn) {  	}  } -gint ScintillaGTK::KeyPress(GtkWidget *widget, GdkEventKey *event) { -	ScintillaGTK *sciThis = ScintillaFromWidget(widget); +gint ScintillaGTK::KeyThis(GdkEventKey *event) {  	//Platform::DebugPrintf("SC-key: %d %x [%s]\n",  	//	event->keyval, event->state, (event->length > 0) ? event->string : "empty");  	bool shift = (event->state & GDK_SHIFT_MASK) != 0; @@ -1430,25 +1448,32 @@ gint ScintillaGTK::KeyPress(GtkWidget *widget, GdkEventKey *event) {  		key &= 0x7F;  	// Hack for keys over 256 and below command keys but makes Hungarian work.  	// This will have to change for Unicode +	else if (key >= 0xFE00) +		key = KeyTranslate(key); +	else if (IsUnicodeMode()) +		;	// No operation  	else if ((key >= 0x100) && (key < 0x1000))  		key &= 0xff; -	else -		key = KeyTranslate(key);  	bool consumed = false; -	bool added = sciThis->KeyDown(key, shift, ctrl, alt, &consumed) != 0; +	bool added = KeyDown(key, shift, ctrl, alt, &consumed) != 0;  	if (!consumed)  		consumed = added;  	//Platform::DebugPrintf("SK-key: %d %x %x\n",event->keyval, event->state, consumed);  	if (event->keyval == 0xffffff && event->length > 0) { -		sciThis->ClearSelection(); -		if (sciThis->pdoc->InsertString(sciThis->CurrentPosition(), event->string)) { -			sciThis->MovePositionTo(sciThis->CurrentPosition() + event->length); +		ClearSelection(); +		if (pdoc->InsertString(CurrentPosition(), event->string)) { +			MovePositionTo(CurrentPosition() + event->length);  		}  	}  	return consumed;  } +gint ScintillaGTK::KeyPress(GtkWidget *widget, GdkEventKey *event) { +	ScintillaGTK *sciThis = ScintillaFromWidget(widget); +	return sciThis->KeyThis(event); +} +  gint ScintillaGTK::KeyRelease(GtkWidget *, GdkEventKey * /*event*/) {  	//Platform::DebugPrintf("SC-keyrel: %d %x %3s\n",event->keyval, event->state, event->string);  	return FALSE; | 
