summaryrefslogtreecommitdiff
path: root/gdk/quartz
diff options
context:
space:
mode:
authorEk Kato <ek.kato@gmail.com>2013-08-16 09:54:34 -0700
committerJohn Ralls <jralls@ceridwen.us>2013-08-16 11:18:29 -0700
commit08042ea830da88aa192e3e8d99aa7af8863aeb16 (patch)
tree278758c9b1835066795d47ce40e71083a6741562 /gdk/quartz
parent77059dbaba04dfaf234032d7ea9ca53c137096ca (diff)
downloadgtk+-08042ea830da88aa192e3e8d99aa7af8863aeb16.tar.gz
Bug 705750 Quartz input method doesn't work correctly for Chinese characters
Modified from original for Gtk3.
Diffstat (limited to 'gdk/quartz')
-rw-r--r--gdk/quartz/GdkQuartzView.c35
-rw-r--r--gdk/quartz/GdkQuartzView.h1
-rw-r--r--gdk/quartz/gdkevents-quartz.c18
-rw-r--r--gdk/quartz/gdkprivate-quartz.h1
4 files changed, 51 insertions, 4 deletions
diff --git a/gdk/quartz/GdkQuartzView.c b/gdk/quartz/GdkQuartzView.c
index 1d125d3b99..a2ed1f58d1 100644
--- a/gdk/quartz/GdkQuartzView.c
+++ b/gdk/quartz/GdkQuartzView.c
@@ -167,6 +167,13 @@
GDK_NOTE (EVENTS, g_print ("setMarkedText: set %s (%p, nsview %p): %s\n",
TIC_MARKED_TEXT, gdk_window, self,
str ? str : "(empty)"));
+
+ /* handle text input changes by mouse events */
+ if (!GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (gdk_window),
+ TIC_IN_KEY_DOWN)))
+ {
+ _gdk_quartz_synthesize_null_key_event(gdk_window);
+ }
}
-(void)doCommandBySelector: (SEL)aSelector
@@ -180,19 +187,32 @@
{
GDK_NOTE (EVENTS, g_print ("insertText\n"));
const char *str;
+ NSString *string;
gchar *prev_str;
if ([self hasMarkedText])
[self unmarkText];
if ([aString isKindOfClass: [NSAttributedString class]])
- {
- str = [[aString string] UTF8String];
- }
+ string = [aString string];
else
+ string = aString;
+
+ NSCharacterSet *ctrlChars = [NSCharacterSet controlCharacterSet];
+ NSCharacterSet *wsnlChars = [NSCharacterSet whitespaceAndNewlineCharacterSet];
+ if ([string rangeOfCharacterFromSet:ctrlChars].length &&
+ [string rangeOfCharacterFromSet:wsnlChars].length == 0)
{
- str = [aString UTF8String];
+ /* discard invalid text input with Chinese input methods */
+ str = "";
+ [self unmarkText];
+ NSInputManager *currentInputManager = [NSInputManager currentInputManager];
+ [currentInputManager markedTextAbandoned:self];
}
+ else
+ {
+ str = [string UTF8String];
+ }
prev_str = g_object_get_data (G_OBJECT (gdk_window), TIC_INSERT_TEXT);
if (prev_str)
@@ -204,6 +224,13 @@
g_object_set_data (G_OBJECT (gdk_window), GIC_FILTER_KEY,
GUINT_TO_POINTER (GIC_FILTER_FILTERED));
+
+ /* handle text input changes by mouse events */
+ if (!GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (gdk_window),
+ TIC_IN_KEY_DOWN)))
+ {
+ _gdk_quartz_synthesize_null_key_event(gdk_window);
+ }
}
-(void)deleteBackward: (id)sender
diff --git a/gdk/quartz/GdkQuartzView.h b/gdk/quartz/GdkQuartzView.h
index 83455c31e2..732c677ee5 100644
--- a/gdk/quartz/GdkQuartzView.h
+++ b/gdk/quartz/GdkQuartzView.h
@@ -24,6 +24,7 @@
#define TIC_SELECTED_POS "tic-selected-pos"
#define TIC_SELECTED_LEN "tic-selected-len"
#define TIC_INSERT_TEXT "tic-insert-text"
+#define TIC_IN_KEY_DOWN "tic-in-key-down"
/* GtkIMContext */
#define GIC_CURSOR_RECT "gic-cursor-rect"
diff --git a/gdk/quartz/gdkevents-quartz.c b/gdk/quartz/gdkevents-quartz.c
index bfd043012e..90bcdb97da 100644
--- a/gdk/quartz/gdkevents-quartz.c
+++ b/gdk/quartz/gdkevents-quartz.c
@@ -1156,6 +1156,24 @@ synthesize_crossing_event (GdkWindow *window,
return FALSE;
}
+void
+_gdk_quartz_synthesize_null_key_event (GdkWindow *window)
+{
+ GdkEvent *event;
+ GdkQuartzDeviceManagerCore *device_manager;
+
+ event = gdk_event_new (GDK_KEY_PRESS);
+ event->any.type = GDK_KEY_PRESS;
+ event->key.window = window;
+ event->key.state = 0;
+ event->key.hardware_keycode = 0;
+ event->key.group = 0;
+ event->key.keyval = GDK_KEY_VoidSymbol;
+ device_manager = GDK_QUARTZ_DEVICE_MANAGER_CORE (_gdk_display->device_manager);
+ gdk_event_set_device (event, device_manager->core_keyboard);
+ append_event(event, FALSE);
+}
+
GdkModifierType
_gdk_quartz_events_get_current_keyboard_modifiers (void)
{
diff --git a/gdk/quartz/gdkprivate-quartz.h b/gdk/quartz/gdkprivate-quartz.h
index 2f9059b2c3..365dcbb187 100644
--- a/gdk/quartz/gdkprivate-quartz.h
+++ b/gdk/quartz/gdkprivate-quartz.h
@@ -74,6 +74,7 @@ void _gdk_quartz_event_loop_release_event (NSEvent *event);
/* Keys */
GdkEventType _gdk_quartz_keys_event_type (NSEvent *event);
gboolean _gdk_quartz_keys_is_modifier (guint keycode);
+void _gdk_quartz_synthesize_null_key_event (GdkWindow *window);
/* Drag and Drop */
void _gdk_quartz_window_register_dnd (GdkWindow *window);