diff options
author | nyamatongwe <devnull@localhost> | 2006-05-31 03:44:21 +0000 |
---|---|---|
committer | nyamatongwe <devnull@localhost> | 2006-05-31 03:44:21 +0000 |
commit | 09d1c6709acb5d91e4ee6752e12ec5caf7492b9e (patch) | |
tree | f3a1ee657892391ca72badf3d4eb601edbb19e67 | |
parent | 91e3f27acbba0ec299467ae66ec6b9113a356bcb (diff) | |
download | scintilla-mirror-09d1c6709acb5d91e4ee6752e12ec5caf7492b9e.tar.gz |
Attempting to move all keyboard input on GTK+ 2.x to using input method.
-rw-r--r-- | gtk/ScintillaGTK.cxx | 145 |
1 files changed, 34 insertions, 111 deletions
diff --git a/gtk/ScintillaGTK.cxx b/gtk/ScintillaGTK.cxx index 2afe3f43e..fafc12b99 100644 --- a/gtk/ScintillaGTK.cxx +++ b/gtk/ScintillaGTK.cxx @@ -176,7 +176,6 @@ private: virtual void NotifyParent(SCNotification scn); void NotifyKey(int key, int modifiers); void NotifyURIDropped(const char *list); - bool UseInputMethod() const; const char *CharacterSetID() const; virtual int KeyDefault(int key, int modifiers); virtual void CopyToClipboard(const SelectionText &selectedText); @@ -1209,117 +1208,19 @@ void ScintillaGTK::NotifyURIDropped(const char *list) { NotifyParent(scn); } -bool ScintillaGTK::UseInputMethod() const { - switch (vs.styles[STYLE_DEFAULT].characterSet) { - case SC_CHARSET_CHINESEBIG5: - case SC_CHARSET_GB2312: - case SC_CHARSET_HANGUL: - case SC_CHARSET_SHIFTJIS: - case SC_CHARSET_JOHAB: - case SC_CHARSET_HEBREW: - case SC_CHARSET_ARABIC: - case SC_CHARSET_VIETNAMESE: - case SC_CHARSET_THAI: - return true; - default: - return false; - } -} - const char *CharacterSetID(int characterSet); const char *ScintillaGTK::CharacterSetID() const { return ::CharacterSetID(vs.styles[STYLE_DEFAULT].characterSet); } -#if GTK_MAJOR_VERSION >= 2 -#define IS_ACC(x) \ - ((x) >= 65103 && (x) <= 65111) -#define IS_CHAR(x) \ - ((x) >= 0 && (x) <= 128) - -#define IS_ACC_OR_CHAR(x) \ - (IS_CHAR(x)) || (IS_ACC(x)) - -static int MakeAccent(int key, int acc) { - const char *conv[] = { - "aeiounc AEIOUNC", - "ãeiõuñc~ÃEIÕUÑC", - "áéíóúnç'ÁÉÍÓÚNÇ", - "àèìòùnc`ÀÈÌÒÙNC", - "âêîôûnc^ÂÊÎÔÛNC", - "äëïöünc¨ÄËÏÖÜNC" - }; - int idx; - for (idx = 0; idx < 15; ++idx) { - if (char(key) == conv[0][idx]) { - break; - } - } - if (idx == 15) { - return key; - } - if (acc == GDK_dead_tilde) { // ~ - return int((unsigned char)(conv[1][idx])); - } else if (acc == GDK_dead_acute) { // ' - return int((unsigned char)(conv[2][idx])); - } else if (acc == GDK_dead_grave) { // ` - return int((unsigned char)(conv[3][idx])); - } else if (acc == GDK_dead_circumflex) { // ^ - return int((unsigned char)(conv[4][idx])); - } else if (acc == GDK_dead_diaeresis) { // " - return int((unsigned char)(conv[5][idx])); - } - return key; -} -#endif - int ScintillaGTK::KeyDefault(int key, int modifiers) { if (!(modifiers & SCI_CTRL) && !(modifiers & SCI_ALT)) { -#if GTK_MAJOR_VERSION >= 2 - if (!UseInputMethod()) { - char utfVal[4]="\0\0\0"; - wchar_t wcs[2]; - if (IS_CHAR(key) && IS_ACC(lastKey)) { - lastKey = key = MakeAccent(key, lastKey); - } - if (IS_ACC_OR_CHAR(key)) { - lastKey = key; - } - wcs[0] = gdk_keyval_to_unicode(key); - wcs[1] = 0; - UTF8FromUCS2(wcs, 1, utfVal, 3); - if (key <= 0xFE00) { - if (IsUnicodeMode()) { - AddCharUTF(utfVal,strlen(utfVal)); - return 1; - } else { - const char *source = CharacterSetID(); - if (*source) { - Converter conv(source, "UTF-8"); - if (conv) { - char localeVal[4]="\0\0\0"; - char *pin = utfVal; - size_t inLeft = strlen(utfVal); - char *pout = localeVal; - size_t outLeft = sizeof(localeVal); - size_t conversions = conv.Convert(&pin, &inLeft, &pout, &outLeft); - if (conversions != ((size_t)(-1))) { - *pout = '\0'; - for (int i=0; localeVal[i]; i++) { - AddChar(localeVal[i]); - } - return 1; - } - } - } - } - } - } -#endif if (key < 256) { - AddChar(key); - return 1; + NotifyKey(key, modifiers); + return 0; + //~ AddChar(key); + //~ return 1; } else { // Pass up to container in case it is an accelerator NotifyKey(key, modifiers); @@ -2036,13 +1937,11 @@ static int KeyTranslate(int keyIn) { } gboolean ScintillaGTK::KeyThis(GdkEventKey *event) { - //Platform::DebugPrintf("SC-key: %d %x [%s]\n", + //fprintf(stderr, "SC-key: %d %x [%s]\n", // event->keyval, event->state, (event->length > 0) ? event->string : "empty"); #if GTK_MAJOR_VERSION >= 2 - if (UseInputMethod()) { - if (gtk_im_context_filter_keypress(im_context, event)) { - return 1; - } + if (gtk_im_context_filter_keypress(im_context, event)) { + return 1; } #endif if (!event->keyval) { @@ -2072,7 +1971,7 @@ gboolean ScintillaGTK::KeyThis(GdkEventKey *event) { 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); + //fprintf(stderr, "SK-key: %d %x %x\n",event->keyval, event->state, consumed); if (event->keyval == 0xffffff && event->length > 0) { ClearSelection(); if (pdoc->InsertString(CurrentPosition(), event->string)) { @@ -2131,8 +2030,32 @@ void ScintillaGTK::Commit(GtkIMContext *, char *str, ScintillaGTK *sciThis) { sciThis->CommitThis(str); } -void ScintillaGTK::CommitThis(char *str) { - AddCharUTF(str, strlen(str)); +void ScintillaGTK::CommitThis(char *utfVal) { + //~ fprintf(stderr, "Commit '%s'\n", utfVal); + if (IsUnicodeMode()) { + AddCharUTF(utfVal,strlen(utfVal)); + } else { + const char *source = CharacterSetID(); + if (*source) { + Converter conv(source, "UTF-8"); + if (conv) { + char localeVal[4]="\0\0\0"; + char *pin = utfVal; + size_t inLeft = strlen(utfVal); + char *pout = localeVal; + size_t outLeft = sizeof(localeVal); + size_t conversions = conv.Convert(&pin, &inLeft, &pout, &outLeft); + if (conversions != ((size_t)(-1))) { + *pout = '\0'; + for (int i=0; localeVal[i]; i++) { + AddChar(localeVal[i]); + } + } else { + fprintf(stderr, "Conversion failed '%s'\n", utfVal); + } + } + } + } } void ScintillaGTK::PreeditChanged(GtkIMContext *, ScintillaGTK *sciThis) { |