diff options
-rw-r--r-- | gtk/ScintillaGTK.cxx | 64 |
1 files changed, 62 insertions, 2 deletions
diff --git a/gtk/ScintillaGTK.cxx b/gtk/ScintillaGTK.cxx index 21b938a69..74d3b976b 100644 --- a/gtk/ScintillaGTK.cxx +++ b/gtk/ScintillaGTK.cxx @@ -52,9 +52,7 @@ #include "ExternalLexer.h" #endif -#if GTK_MAJOR_VERSION < 2 #define INTERNATIONAL_INPUT -#endif #if !PLAT_GTK_WIN32 #include <iconv.h> @@ -106,9 +104,13 @@ class ScintillaGTK : public ScintillaBase { CLIPFORMAT cfColumnSelect; #endif #ifdef INTERNATIONAL_INPUT +#if GTK_MAJOR_VERSION < 2 // Input context used for supporting internationalized key entry GdkIC *ic; GdkICAttr *ic_attr; +#else + GtkIMContext *im_context; +#endif #endif // Wheel mouse support unsigned int linesPerScroll; @@ -198,6 +200,10 @@ private: gint KeyThis(GdkEventKey *event); static gint KeyPress(GtkWidget *widget, GdkEventKey *event); static gint KeyRelease(GtkWidget *widget, GdkEventKey *event); +#if GTK_MAJOR_VERSION >= 2 + static void Commit(GtkIMContext *context, char *str, ScintillaGTK *sciThis); + void CommitThis(char *str); +#endif static void Destroy(GtkObject *object); static void SelectionReceived(GtkWidget *widget, GtkSelectionData *selection_data, guint time); @@ -264,8 +270,12 @@ ScintillaGTK::ScintillaGTK(_ScintillaObject *sci_) : capturedMouse(false), dragWasDropped(false), lastKey(0), parentClass(0), #ifdef INTERNATIONAL_INPUT +#if GTK_MAJOR_VERSION < 2 ic(NULL), ic_attr(NULL), +#else + im_context(NULL), +#endif #endif lastWheelMouseDirection(0), wheelMouseIntensity(0) { @@ -323,6 +333,7 @@ void ScintillaGTK::RealizeThis(GtkWidget *widget) { gdk_window_show(widget->window); gdk_cursor_destroy(cursor); #ifdef INTERNATIONAL_INPUT +#if GTK_MAJOR_VERSION < 2 if (gdk_im_ready() && (ic_attr = gdk_ic_attr_new()) != NULL) { gint width, height; GdkColormap *colormap; @@ -379,6 +390,12 @@ void ScintillaGTK::RealizeThis(GtkWidget *widget) { gdk_im_begin(ic, widget->window); } } +#else + im_context = gtk_im_multicontext_new(); + g_signal_connect(im_context, "commit", + G_CALLBACK(Commit), this); + gtk_im_context_set_client_window(im_context, widget->window); +#endif #endif gtk_widget_realize(PWidget(wText)); gtk_widget_realize(PWidget(scrollbarv)); @@ -399,6 +416,7 @@ void ScintillaGTK::UnRealizeThis(GtkWidget *widget) { gtk_widget_unrealize(PWidget(scrollbarv)); gtk_widget_unrealize(PWidget(scrollbarh)); #ifdef INTERNATIONAL_INPUT +#if GTK_MAJOR_VERSION < 2 if (ic) { gdk_ic_destroy(ic); ic = NULL; @@ -407,6 +425,9 @@ void ScintillaGTK::UnRealizeThis(GtkWidget *widget) { gdk_ic_attr_destroy(ic_attr); ic_attr = NULL; } +#else + g_object_unref(im_context); +#endif #endif if (GTK_WIDGET_CLASS(parentClass)->unrealize) GTK_WIDGET_CLASS(parentClass)->unrealize(widget); @@ -474,12 +495,21 @@ void ScintillaGTK::MainForAll(GtkContainer *container, gboolean include_internal #ifdef INTERNATIONAL_INPUT gint ScintillaGTK::CursorMoved(GtkWidget *widget, int xoffset, int yoffset, ScintillaGTK *sciThis) { +#if GTK_MAJOR_VERSION < 2 if (GTK_WIDGET_HAS_FOCUS(widget) && gdk_im_ready() && sciThis->ic && (gdk_ic_get_style (sciThis->ic) & GDK_IM_PREEDIT_POSITION)) { sciThis->ic_attr->spot_location.x = xoffset; sciThis->ic_attr->spot_location.y = yoffset; gdk_ic_set_attr (sciThis->ic, sciThis->ic_attr, GDK_IC_SPOT_LOCATION); } +#else + GdkRectangle area; + area.x = xoffset; + area.y = yoffset; + area.width = 1; + area.height = 1; + gtk_im_context_set_cursor_location(sciThis->im_context, &area); +#endif return FALSE; } #else @@ -495,8 +525,12 @@ gint ScintillaGTK::FocusIn(GtkWidget *widget, GdkEventFocus * /*event*/) { sciThis->SetFocusState(true); #ifdef INTERNATIONAL_INPUT +#if GTK_MAJOR_VERSION < 2 if (sciThis->ic) gdk_im_begin(sciThis->ic, widget->window); +#else + gtk_im_context_focus_in(sciThis->im_context); +#endif #endif return FALSE; @@ -509,7 +543,11 @@ gint ScintillaGTK::FocusOut(GtkWidget *widget, GdkEventFocus * /*event*/) { sciThis->SetFocusState(false); #ifdef INTERNATIONAL_INPUT +#if GTK_MAJOR_VERSION < 2 gdk_im_end(); +#else + gtk_im_context_focus_out(sciThis->im_context); +#endif #endif return FALSE; @@ -537,6 +575,7 @@ void ScintillaGTK::SizeAllocate(GtkWidget *widget, GtkAllocation *allocation) { sciThis->Resize(allocation->width, allocation->height); #ifdef INTERNATIONAL_INPUT +#if GTK_MAJOR_VERSION < 2 if (sciThis->ic && (gdk_ic_get_style (sciThis->ic) & GDK_IM_PREEDIT_POSITION)) { gint width, height; @@ -547,6 +586,7 @@ void ScintillaGTK::SizeAllocate(GtkWidget *widget, GtkAllocation *allocation) { gdk_ic_set_attr(sciThis->ic, sciThis->ic_attr, GDK_IC_PREEDIT_AREA); } #endif +#endif } void ScintillaGTK::Initialise() { @@ -966,6 +1006,7 @@ static int MakeAccent(int key, int acc) { int ScintillaGTK::KeyDefault(int key, int modifiers) { if (!(modifiers & SCI_CTRL) && !(modifiers & SCI_ALT)) { +#ifndef INTERNATIONAL_INPUT #if GTK_MAJOR_VERSION >= 2 char utfVal[4]="\0\0\0"; wchar_t wcs[2]; @@ -1007,6 +1048,7 @@ int ScintillaGTK::KeyDefault(int key, int modifiers) { } } #endif +#endif if (key < 256) { AddChar(key); return 1; @@ -1710,6 +1752,10 @@ gint ScintillaGTK::KeyThis(GdkEventKey *event) { if (!event->keyval) { return true; } +#if GTK_MAJOR_VERSION >= 2 + if (gtk_im_context_filter_keypress(im_context, event)) + return 1; +#endif bool shift = (event->state & GDK_SHIFT_MASK) != 0; bool ctrl = (event->state & GDK_CONTROL_MASK) != 0; @@ -1754,6 +1800,20 @@ gint ScintillaGTK::KeyRelease(GtkWidget *, GdkEventKey * /*event*/) { return FALSE; } +#if GTK_MAJOR_VERSION >= 2 +void ScintillaGTK::Commit(GtkIMContext *context, + char *str, + ScintillaGTK *sciThis) +{ + sciThis->CommitThis(str); +} + +void ScintillaGTK::CommitThis(char *str) +{ + AddCharUTF(str, strlen(str)); +} +#endif + void ScintillaGTK::Destroy(GtkObject* object) { ScintillaObject *scio = reinterpret_cast<ScintillaObject *>(object); // This avoids a double destruction |