From 634c4cd939fa6c419dfaf87ead839906e781d79f Mon Sep 17 00:00:00 2001 From: Felipe Heidrich Date: Mon, 24 Sep 2007 21:48:29 +0000 Subject: refactoring --- .../gtk/org/eclipse/swt/widgets/IME.java | 238 ++++++++++----------- 1 file changed, 116 insertions(+), 122 deletions(-) (limited to 'bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/IME.java') diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/IME.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/IME.java index 33400b42dd..d0abcbe437 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/IME.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/IME.java @@ -81,45 +81,41 @@ public String getText () { return text; } -public boolean getWideCaret() { +public boolean getWideCaret () { checkWidget (); return false; } int /*long*/ gtk_button_press_event (int /*long*/ widget, int /*long*/ event) { - if (isInlineIMEEnabled ()) { - int /*long*/ imHandle = imHandle (); - if (imHandle != 0) { - OS.gtk_im_context_reset (imHandle); - } - } + if (!isInlineEnabled ()) return 0; + int /*long*/ imHandle = imHandle (); + if (imHandle != 0) OS.gtk_im_context_reset (imHandle); return 0; } int /*long*/ gtk_commit (int /*long*/ imcontext, int /*long*/ textPtr) { + if (!isInlineEnabled ()) return 0; boolean doit = true; - if (isInlineIMEEnabled ()) { - ranges = null; - styles = null; - caretOffset = commitCount = 0; - if (textPtr != 0 && inComposition) { - int length = OS.strlen (textPtr); - if (length != 0) { - byte [] buffer = new byte [length]; - OS.memmove (buffer, textPtr, length); - char [] chars = Converter.mbcsToWcs (null, buffer); - Event event = new Event(); - event.detail = SWT.COMPOSITION_CHANGED; - event.start = startOffset; - event.end = startOffset + text.length (); - event.text = text = chars != null ? new String (chars) : ""; - commitCount = text.length(); - sendEvent(SWT.ImeComposition, event); - doit = event.doit; - text = ""; - startOffset = -1; - commitCount = 0; - } + ranges = null; + styles = null; + caretOffset = commitCount = 0; + if (textPtr != 0 && inComposition) { + int length = OS.strlen (textPtr); + if (length != 0) { + byte [] buffer = new byte [length]; + OS.memmove (buffer, textPtr, length); + char [] chars = Converter.mbcsToWcs (null, buffer); + Event event = new Event(); + event.detail = SWT.COMPOSITION_CHANGED; + event.start = startOffset; + event.end = startOffset + text.length (); + event.text = text = chars != null ? new String (chars) : ""; + commitCount = text.length(); + sendEvent (SWT.ImeComposition, event); + doit = event.doit; + text = ""; + startOffset = -1; + commitCount = 0; } } inComposition = false; @@ -127,113 +123,111 @@ int /*long*/ gtk_commit (int /*long*/ imcontext, int /*long*/ textPtr) { } int /*long*/ gtk_preedit_changed (int /*long*/ imcontext) { - if (isInlineIMEEnabled ()) { - ranges = null; - styles = null; - commitCount = 0; - int /*long*/ imHandle = imHandle (); - int /*long*/ [] preeditString = new int /*long*/ [1]; - int /*long*/ [] pangoAttrs = new int /*long*/ [1]; - int [] cursorPos = new int [1]; - OS.gtk_im_context_get_preedit_string (imHandle, preeditString, pangoAttrs, cursorPos); - caretOffset = cursorPos [0]; - char [] chars = null; - if (preeditString [0] != 0) { - int length = OS.strlen (preeditString [0]); - byte [] buffer = new byte [length]; - OS.memmove (buffer, preeditString [0], length); - chars = Converter.mbcsToWcs (null, buffer); - if (pangoAttrs [0] != 0) { - int count = 0; - int /*long*/ iterator = OS.pango_attr_list_get_iterator (pangoAttrs [0]); - while (OS.pango_attr_iterator_next (iterator)) count++; - OS.pango_attr_iterator_destroy (iterator); - ranges = new int [count * 2]; - styles = new TextStyle [count]; - iterator = OS.pango_attr_list_get_iterator (pangoAttrs [0]); - PangoAttrColor attrColor = new PangoAttrColor (); - PangoAttrInt attrInt = new PangoAttrInt (); - int [] start = new int [1]; - int [] end = new int [1]; - for (int i = 0; i < count; i++) { - OS.pango_attr_iterator_range (iterator, start, end); - ranges [i * 2] = (int)/*64*/OS.g_utf8_pointer_to_offset (preeditString [0], preeditString [0] + start [0]); - ranges [i * 2 + 1] = (int)/*64*/OS.g_utf8_pointer_to_offset (preeditString [0], preeditString [0] + end [0]) - ranges [i * 2]; - styles [i] = new TextStyle (null, null, null); - int /*long*/ attr = OS.pango_attr_iterator_get (iterator, OS.PANGO_ATTR_FOREGROUND); - if (attr != 0) { - OS.memmove (attrColor, attr, PangoAttrColor.sizeof); - GdkColor color = new GdkColor (); - color.red = attrColor.color_red; - color.green = attrColor.color_green; - color.blue = attrColor.color_blue; - styles [i].foreground = Color.gtk_new (display, color); - } - attr = OS.pango_attr_iterator_get (iterator, OS.PANGO_ATTR_BACKGROUND); - if (attr != 0) { - OS.memmove (attrColor, attr, PangoAttrColor.sizeof); - GdkColor color = new GdkColor (); - color.red = attrColor.color_red; - color.green = attrColor.color_green; - color.blue = attrColor.color_blue; - styles [i].background = Color.gtk_new (display, color); + if (!isInlineEnabled ()) return 0; + ranges = null; + styles = null; + commitCount = 0; + int /*long*/ imHandle = imHandle (); + int /*long*/ [] preeditString = new int /*long*/ [1]; + int /*long*/ [] pangoAttrs = new int /*long*/ [1]; + int [] cursorPos = new int [1]; + OS.gtk_im_context_get_preedit_string (imHandle, preeditString, pangoAttrs, cursorPos); + caretOffset = cursorPos [0]; + char [] chars = null; + if (preeditString [0] != 0) { + int length = OS.strlen (preeditString [0]); + byte [] buffer = new byte [length]; + OS.memmove (buffer, preeditString [0], length); + chars = Converter.mbcsToWcs (null, buffer); + if (pangoAttrs [0] != 0) { + int count = 0; + int /*long*/ iterator = OS.pango_attr_list_get_iterator (pangoAttrs [0]); + while (OS.pango_attr_iterator_next (iterator)) count++; + OS.pango_attr_iterator_destroy (iterator); + ranges = new int [count * 2]; + styles = new TextStyle [count]; + iterator = OS.pango_attr_list_get_iterator (pangoAttrs [0]); + PangoAttrColor attrColor = new PangoAttrColor (); + PangoAttrInt attrInt = new PangoAttrInt (); + int [] start = new int [1]; + int [] end = new int [1]; + for (int i = 0; i < count; i++) { + OS.pango_attr_iterator_range (iterator, start, end); + ranges [i * 2] = (int)/*64*/OS.g_utf8_pointer_to_offset (preeditString [0], preeditString [0] + start [0]); + ranges [i * 2 + 1] = (int)/*64*/OS.g_utf8_pointer_to_offset (preeditString [0], preeditString [0] + end [0]) - ranges [i * 2]; + styles [i] = new TextStyle (null, null, null); + int /*long*/ attr = OS.pango_attr_iterator_get (iterator, OS.PANGO_ATTR_FOREGROUND); + if (attr != 0) { + OS.memmove (attrColor, attr, PangoAttrColor.sizeof); + GdkColor color = new GdkColor (); + color.red = attrColor.color_red; + color.green = attrColor.color_green; + color.blue = attrColor.color_blue; + styles [i].foreground = Color.gtk_new (display, color); + } + attr = OS.pango_attr_iterator_get (iterator, OS.PANGO_ATTR_BACKGROUND); + if (attr != 0) { + OS.memmove (attrColor, attr, PangoAttrColor.sizeof); + GdkColor color = new GdkColor (); + color.red = attrColor.color_red; + color.green = attrColor.color_green; + color.blue = attrColor.color_blue; + styles [i].background = Color.gtk_new (display, color); + } + attr = OS.pango_attr_iterator_get (iterator, OS.PANGO_ATTR_UNDERLINE); + if (attr != 0) { + OS.memmove (attrInt, attr, PangoAttrInt.sizeof); + styles [i].underline = attrInt.value != OS.PANGO_UNDERLINE_NONE;; + styles [i].underlineStyle = SWT.UNDERLINE_SINGLE; + switch (attrInt.value) { + case OS.PANGO_UNDERLINE_DOUBLE: + styles [i].underlineStyle = SWT.UNDERLINE_DOUBLE; + break; + case OS.PANGO_UNDERLINE_ERROR: + styles [i].underlineStyle = SWT.UNDERLINE_ERROR; + break; } - attr = OS.pango_attr_iterator_get (iterator, OS.PANGO_ATTR_UNDERLINE); - if (attr != 0) { - OS.memmove (attrInt, attr, PangoAttrInt.sizeof); - styles [i].underline = attrInt.value != OS.PANGO_UNDERLINE_NONE;; - styles [i].underlineStyle = SWT.UNDERLINE_SINGLE; - switch (attrInt.value) { - case OS.PANGO_UNDERLINE_DOUBLE: - styles [i].underlineStyle = SWT.UNDERLINE_DOUBLE; - break; - case OS.PANGO_UNDERLINE_ERROR: - styles [i].underlineStyle = SWT.UNDERLINE_ERROR; - break; - } - if (styles [i].underline) { - attr = OS.pango_attr_iterator_get(iterator, OS.PANGO_ATTR_UNDERLINE_COLOR); - if (attr != 0) { - OS.memmove (attrColor, attr, PangoAttrColor.sizeof); - GdkColor color = new GdkColor (); - color.red = attrColor.color_red; - color.green = attrColor.color_green; - color.blue = attrColor.color_blue; - styles [i].underlineColor = Color.gtk_new (display, color); - } + if (styles [i].underline) { + attr = OS.pango_attr_iterator_get(iterator, OS.PANGO_ATTR_UNDERLINE_COLOR); + if (attr != 0) { + OS.memmove (attrColor, attr, PangoAttrColor.sizeof); + GdkColor color = new GdkColor (); + color.red = attrColor.color_red; + color.green = attrColor.color_green; + color.blue = attrColor.color_blue; + styles [i].underlineColor = Color.gtk_new (display, color); } } - OS.pango_attr_iterator_next (iterator); } - OS.pango_attr_iterator_destroy (iterator); - OS.pango_attr_list_unref (pangoAttrs [0]); + OS.pango_attr_iterator_next (iterator); } - OS.g_free (preeditString [0]); + OS.pango_attr_iterator_destroy (iterator); + OS.pango_attr_list_unref (pangoAttrs [0]); } - if (chars != null) { - if (text.length() == 0) startOffset = -1; - if (startOffset == -1) { - Caret caret = parent.getCaret (); - startOffset = caret != null ? caret.getOffset () : 0; - } - inComposition = true; - Event event = new Event (); - event.detail = SWT.COMPOSITION_CHANGED; - event.start = startOffset; - event.end = startOffset + text.length (); - event.text = text = chars != null ? new String (chars) : ""; - sendEvent (SWT.ImeComposition, event); + OS.g_free (preeditString [0]); + } + if (chars != null) { + if (text.length() == 0) startOffset = -1; + if (startOffset == -1) { + Caret caret = parent.getCaret (); + startOffset = caret != null ? caret.getOffset () : 0; } - return 1; + inComposition = true; + Event event = new Event (); + event.detail = SWT.COMPOSITION_CHANGED; + event.start = startOffset; + event.end = startOffset + text.length (); + event.text = text = chars != null ? new String (chars) : ""; + sendEvent (SWT.ImeComposition, event); } - return 0; + return 1; } int /*long*/ imHandle () { return parent.imHandle (); } -boolean isInlineIMEEnabled () { +boolean isInlineEnabled () { return hooks (SWT.ImeComposition); } -- cgit