summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFelipe Heidrich <fheidric>2011-03-23 19:14:54 +0000
committerFelipe Heidrich <fheidric>2011-03-23 19:14:54 +0000
commit55a22ab9240db91b3cefd3f1694927c9a71b6ad8 (patch)
treec0f0d91992237f5677665cfd409ce5b6dca0efc7
parent56201926f64ad6ea7f48b4affd1bb7e12a2c8db2 (diff)
downloadeclipse.platform.swt-55a22ab9240db91b3cefd3f1694927c9a71b6ad8.tar.gz
eclipse.platform.swt-55a22ab9240db91b3cefd3f1694927c9a71b6ad8.tar.xz
eclipse.platform.swt-55a22ab9240db91b3cefd3f1694927c9a71b6ad8.zip
Bug 65899 - [StyledText] StyledText Supplementary/Surrogate character navigation
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledText.java6
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.c60
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_custom.c69
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_custom.h6
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.c9
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.h5
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/OS.java53
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/TextLayout.java87
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Combo.java36
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/IME.java4
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Spinner.java16
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Text.java131
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Widget.java4
13 files changed, 379 insertions, 107 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledText.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledText.java
index 2cc14aabe2..5a3ed517c8 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledText.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledText.java
@@ -5419,7 +5419,8 @@ Point getPointAtOffset(int offset) {
TextLayout layout = renderer.getTextLayout(lineIndex);
if (lineLength != 0 && offsetInLine <= lineLength) {
if (offsetInLine == lineLength) {
- point = layout.getLocation(offsetInLine - 1, true);
+ offsetInLine = layout.getPreviousOffset(offsetInLine, SWT.MOVEMENT_CLUSTER);
+ point = layout.getLocation(offsetInLine, true);
} else {
switch (caretAlignment) {
case OFFSET_LEADING:
@@ -5430,7 +5431,8 @@ Point getPointAtOffset(int offset) {
if (offsetInLine == 0) {
point = layout.getLocation(offsetInLine, false);
} else {
- point = layout.getLocation(offsetInLine - 1, true);
+ offsetInLine = layout.getPreviousOffset(offsetInLine, SWT.MOVEMENT_CLUSTER);
+ point = layout.getLocation(offsetInLine, true);
}
break;
}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.c b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.c
index cd59c51dc7..bdb653e45d 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.c
+++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.c
@@ -4444,6 +4444,54 @@ fail:
}
#endif
+#ifndef NO__1g_1utf16_1offset_1to_1pointer
+JNIEXPORT jintLong JNICALL OS_NATIVE(_1g_1utf16_1offset_1to_1pointer)
+ (JNIEnv *env, jclass that, jintLong arg0, jintLong arg1)
+{
+ jintLong rc = 0;
+ OS_NATIVE_ENTER(env, that, _1g_1utf16_1offset_1to_1pointer_FUNC);
+ rc = (jintLong)g_utf16_offset_to_pointer((const gchar *)arg0, arg1);
+ OS_NATIVE_EXIT(env, that, _1g_1utf16_1offset_1to_1pointer_FUNC);
+ return rc;
+}
+#endif
+
+#ifndef NO__1g_1utf16_1offset_1to_1utf8_1offset
+JNIEXPORT jintLong JNICALL OS_NATIVE(_1g_1utf16_1offset_1to_1utf8_1offset)
+ (JNIEnv *env, jclass that, jintLong arg0, jintLong arg1)
+{
+ jintLong rc = 0;
+ OS_NATIVE_ENTER(env, that, _1g_1utf16_1offset_1to_1utf8_1offset_FUNC);
+ rc = (jintLong)g_utf16_offset_to_utf8_offset((const gchar *)arg0, arg1);
+ OS_NATIVE_EXIT(env, that, _1g_1utf16_1offset_1to_1utf8_1offset_FUNC);
+ return rc;
+}
+#endif
+
+#ifndef NO__1g_1utf16_1pointer_1to_1offset
+JNIEXPORT jintLong JNICALL OS_NATIVE(_1g_1utf16_1pointer_1to_1offset)
+ (JNIEnv *env, jclass that, jintLong arg0, jintLong arg1)
+{
+ jintLong rc = 0;
+ OS_NATIVE_ENTER(env, that, _1g_1utf16_1pointer_1to_1offset_FUNC);
+ rc = (jintLong)g_utf16_pointer_to_offset((const gchar *)arg0, (const gchar *)arg1);
+ OS_NATIVE_EXIT(env, that, _1g_1utf16_1pointer_1to_1offset_FUNC);
+ return rc;
+}
+#endif
+
+#ifndef NO__1g_1utf16_1strlen
+JNIEXPORT jintLong JNICALL OS_NATIVE(_1g_1utf16_1strlen)
+ (JNIEnv *env, jclass that, jintLong arg0, jintLong arg1)
+{
+ jintLong rc = 0;
+ OS_NATIVE_ENTER(env, that, _1g_1utf16_1strlen_FUNC);
+ rc = (jintLong)g_utf16_strlen((const gchar *)arg0, arg1);
+ OS_NATIVE_EXIT(env, that, _1g_1utf16_1strlen_FUNC);
+ return rc;
+}
+#endif
+
#ifndef NO__1g_1utf16_1to_1utf8
JNIEXPORT jintLong JNICALL OS_NATIVE(_1g_1utf16_1to_1utf8)
(JNIEnv *env, jclass that, jcharArray arg0, jintLong arg1, jintLongArray arg2, jintLongArray arg3, jintLongArray arg4)
@@ -4501,6 +4549,18 @@ JNIEXPORT jintLong JNICALL OS_NATIVE(_1g_1utf8_1offset_1to_1pointer)
}
#endif
+#ifndef NO__1g_1utf8_1offset_1to_1utf16_1offset
+JNIEXPORT jintLong JNICALL OS_NATIVE(_1g_1utf8_1offset_1to_1utf16_1offset)
+ (JNIEnv *env, jclass that, jintLong arg0, jintLong arg1)
+{
+ jintLong rc = 0;
+ OS_NATIVE_ENTER(env, that, _1g_1utf8_1offset_1to_1utf16_1offset_FUNC);
+ rc = (jintLong)g_utf8_offset_to_utf16_offset((const gchar *)arg0, arg1);
+ OS_NATIVE_EXIT(env, that, _1g_1utf8_1offset_1to_1utf16_1offset_FUNC);
+ return rc;
+}
+#endif
+
#ifndef NO__1g_1utf8_1pointer_1to_1offset
JNIEXPORT jintLong JNICALL OS_NATIVE(_1g_1utf8_1pointer_1to_1offset)
(JNIEnv *env, jclass that, jintLong arg0, jintLong arg1)
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_custom.c b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_custom.c
index 704af6cb66..38a2d98787 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_custom.c
+++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_custom.c
@@ -118,3 +118,72 @@ fail:
}
#endif
+glong g_utf16_strlen(const gchar *str, glong max) {
+ const gchar *s = str;
+ guchar ch;
+ glong offset = 0;
+ if (!s || max == 0) return 0;
+ if (max < 0) {
+ while (*s) {
+ if (0xf0 <= *(guchar*)s && *(guchar*)s <= 0xfd) offset++;
+ s = g_utf8_next_char (s);
+ offset++;
+ }
+
+ } else {
+ while (*s) {
+ ch = *(guchar*)s;
+ s = g_utf8_next_char (s);
+ if (s - str > max) break;
+ if (0xf0 <= ch && ch <= 0xfd) offset++;
+ offset++;
+ }
+ }
+ return offset;
+}
+
+glong g_utf16_pointer_to_offset(const gchar *str, const gchar * pos) {
+ const gchar *s = str;
+ glong offset = 0;
+ if (!s || !pos) return 0;
+ while (s < pos && *s) {
+ if (0xf0 <= *(guchar*)s && *(guchar*)s <= 0xfd) offset++;
+ s = g_utf8_next_char (s);
+ offset++;
+ }
+ return offset;
+}
+
+gchar* g_utf16_offset_to_pointer(const gchar* str, glong offset) {
+ const gchar *s = str;
+ if (!s) return 0;
+ while (offset-- > 0 && *s) {
+ if (0xf0 <= *(guchar*)s && *(guchar*)s <= 0xfd) offset--;
+ s = g_utf8_next_char (s);
+ }
+ return (gchar *)s;
+}
+
+glong g_utf16_offset_to_utf8_offset(const gchar* str, glong offset) {
+ glong r = 0;
+ const gchar *s = str;
+ if (!s) return 0;
+ while (offset-- > 0 && *s) {
+ if (0xf0 <= *(guchar*)s && *(guchar*)s <= 0xfd) offset--;
+ s = g_utf8_next_char (s);
+ r++;
+ }
+ return r;
+}
+
+glong g_utf8_offset_to_utf16_offset(const gchar* str, glong offset) {
+ glong r = 0;
+ const gchar *s = str;
+ if (!s) return 0;
+ while (offset-- > 0 && *s) {
+ if (0xf0 <= *(guchar*)s && *(guchar*)s <= 0xfd) r++;
+ s = g_utf8_next_char (s);
+ r++;
+ }
+ return r;
+} \ No newline at end of file
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_custom.h b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_custom.h
index eaf2f14675..7f9f605715 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_custom.h
+++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_custom.h
@@ -353,4 +353,8 @@
LOAD_FUNCTION(fp, gtk_status_icon_position_menu) \
rc = (jintLong)fp;
-
+glong g_utf16_pointer_to_offset(const gchar*, const gchar*);
+gchar* g_utf16_offset_to_pointer(const gchar*, glong);
+glong g_utf16_strlen(const gchar*, glong max);
+glong g_utf16_offset_to_utf8_offset(const gchar*, glong);
+glong g_utf8_offset_to_utf16_offset(const gchar*, glong);
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.c b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.c
index 6566378918..c0ebf1bd71 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.c
+++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.c
@@ -18,8 +18,8 @@
#ifdef NATIVE_STATS
-int OS_nativeFunctionCount = 1384;
-int OS_nativeFunctionCallCount[1384];
+int OS_nativeFunctionCount = 1389;
+int OS_nativeFunctionCallCount[1389];
char * OS_nativeFunctionNames[] = {
#ifndef JNI64
"Call__IIII",
@@ -390,8 +390,13 @@ char * OS_nativeFunctionNames[] = {
"_1g_1type_1parent",
"_1g_1type_1query",
"_1g_1type_1register_1static",
+ "_1g_1utf16_1offset_1to_1pointer",
+ "_1g_1utf16_1offset_1to_1utf8_1offset",
+ "_1g_1utf16_1pointer_1to_1offset",
+ "_1g_1utf16_1strlen",
"_1g_1utf16_1to_1utf8",
"_1g_1utf8_1offset_1to_1pointer",
+ "_1g_1utf8_1offset_1to_1utf16_1offset",
"_1g_1utf8_1pointer_1to_1offset",
"_1g_1utf8_1strlen",
#ifndef JNI64
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.h b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.h
index eadd592d3c..aa5dd9be37 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.h
+++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.h
@@ -398,8 +398,13 @@ typedef enum {
_1g_1type_1parent_FUNC,
_1g_1type_1query_FUNC,
_1g_1type_1register_1static_FUNC,
+ _1g_1utf16_1offset_1to_1pointer_FUNC,
+ _1g_1utf16_1offset_1to_1utf8_1offset_FUNC,
+ _1g_1utf16_1pointer_1to_1offset_FUNC,
+ _1g_1utf16_1strlen_FUNC,
_1g_1utf16_1to_1utf8_FUNC,
_1g_1utf8_1offset_1to_1pointer_FUNC,
+ _1g_1utf8_1offset_1to_1utf16_1offset_FUNC,
_1g_1utf8_1pointer_1to_1offset_FUNC,
_1g_1utf8_1strlen_FUNC,
#ifndef JNI64
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/OS.java b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/OS.java
index 8d6d1d1efd..53070ab2d0 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/OS.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/OS.java
@@ -3325,6 +3325,59 @@ public static final int /*long*/ g_utf8_pointer_to_offset(int /*long*/ str, int
}
}
/** @param str cast=(const gchar *) */
+public static final native int /*long*/ _g_utf16_offset_to_pointer(int /*long*/ str, int /*long*/ offset);
+public static final int /*long*/ g_utf16_offset_to_pointer(int /*long*/ str, int /*long*/ offset) {
+ lock.lock();
+ try {
+ return _g_utf16_offset_to_pointer(str, offset);
+ } finally {
+ lock.unlock();
+ }
+}
+/**
+ * @param str cast=(const gchar *)
+ * @param pos cast=(const gchar *)
+ */
+public static final native int /*long*/ _g_utf16_pointer_to_offset(int /*long*/ str, int /*long*/ pos);
+public static final int /*long*/ g_utf16_pointer_to_offset(int /*long*/ str, int /*long*/ pos) {
+ lock.lock();
+ try {
+ return _g_utf16_pointer_to_offset(str, pos);
+ } finally {
+ lock.unlock();
+ }
+}
+/** @param str cast=(const gchar *) */
+public static final native int /*long*/ _g_utf16_strlen(int /*long*/ str, int /*long*/ max);
+public static final int /*long*/ g_utf16_strlen(int /*long*/ str, int /*long*/ max) {
+ lock.lock();
+ try {
+ return _g_utf16_strlen(str, max);
+ } finally {
+ lock.unlock();
+ }
+}
+/** @param str cast=(const gchar *) */
+public static final native int /*long*/ _g_utf8_offset_to_utf16_offset(int /*long*/ str, int /*long*/ offset);
+public static final int /*long*/ g_utf8_offset_to_utf16_offset(int /*long*/ str, int /*long*/ offset) {
+ lock.lock();
+ try {
+ return _g_utf8_offset_to_utf16_offset(str, offset);
+ } finally {
+ lock.unlock();
+ }
+}
+/** @param str cast=(const gchar *) */
+public static final native int /*long*/ _g_utf16_offset_to_utf8_offset(int /*long*/ str, int /*long*/ offset);
+public static final int /*long*/ g_utf16_offset_to_utf8_offset(int /*long*/ str, int /*long*/ offset) {
+ lock.lock();
+ try {
+ return _g_utf16_offset_to_utf8_offset(str, offset);
+ } finally {
+ lock.unlock();
+ }
+}
+/** @param str cast=(const gchar *) */
public static final native int /*long*/ _g_utf8_strlen(int /*long*/ str, int /*long*/ max);
public static final int /*long*/ g_utf8_strlen(int /*long*/ str, int /*long*/ max) {
lock.lock();
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/TextLayout.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/TextLayout.java
index 6b05d5515d..d9b9f86d6a 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/TextLayout.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/TextLayout.java
@@ -142,7 +142,7 @@ void computeRuns () {
attribute.end_index = bytePos + offset + 6;
OS.memmove (attr, attribute, PangoAttribute.sizeof);
OS.pango_attr_list_insert(attrList, attr);
- int pos = (int)/*64*/OS.g_utf8_pointer_to_offset(ptr, ptr + bytePos);
+ int pos = (int)/*64*/OS.g_utf16_pointer_to_offset(ptr, ptr + bytePos);
chars[pos + lineIndex * 2] = ZWS;
chars[pos + lineIndex * 2 + 1] = ZWNBS;
segmentsText.getChars(oldPos, pos, chars, oldPos + lineIndex * 2);
@@ -184,8 +184,8 @@ void computeRuns () {
if (style == null) continue;
int start = translateOffset(styleItem.start);
int end = translateOffset(styles[i+1].start - 1);
- int byteStart = (int)/*64*/(OS.g_utf8_offset_to_pointer(ptr, start) - ptr);
- int byteEnd = (int)/*64*/(OS.g_utf8_offset_to_pointer(ptr, end + 1) - ptr);
+ int byteStart = (int)/*64*/(OS.g_utf16_offset_to_pointer(ptr, start) - ptr);
+ int byteEnd = (int)/*64*/(OS.g_utf16_offset_to_pointer(ptr, end + 1) - ptr);
byteStart = Math.min(byteStart, strlen);
byteEnd = Math.min(byteEnd, strlen);
Font font = style.font;
@@ -430,9 +430,9 @@ public void draw(GC gc, int x, int y, int selectionStart, int selectionEnd, Colo
OS.pango_layout_iter_get_line_extents(iter, null, rect);
if (OS.pango_layout_iter_next_line(iter)) {
int bytePos = OS.pango_layout_iter_get_index(iter);
- lineEnd = (int)/*64*/OS.g_utf8_pointer_to_offset(ptr, ptr + bytePos);
+ lineEnd = (int)/*64*/OS.g_utf16_pointer_to_offset(ptr, ptr + bytePos);
} else {
- lineEnd = (int)/*64*/OS.g_utf8_strlen(ptr, -1);
+ lineEnd = (int)/*64*/OS.g_utf16_strlen(ptr, -1);
}
boolean extent = false;
if (lineIndex == lineCount - 1 && (flags & SWT.LAST_LINE_SELECTION) != 0) {
@@ -494,7 +494,7 @@ public void draw(GC gc, int x, int y, int selectionStart, int selectionEnd, Colo
} else {
selectionStart = Math.min(Math.max(0, selectionStart), length - 1);
selectionEnd = Math.min(Math.max(0, selectionEnd), length - 1);
- length = (int)/*64*/OS.g_utf8_strlen(OS.pango_layout_get_text(layout), -1);
+ length = (int)/*64*/OS.g_utf16_strlen(OS.pango_layout_get_text(layout), -1);
selectionStart = translateOffset(selectionStart);
selectionEnd = translateOffset(selectionEnd);
if (selectionForeground == null) selectionForeground = device.getSystemColor(SWT.COLOR_LIST_SELECTION_TEXT);
@@ -518,8 +518,8 @@ public void draw(GC gc, int x, int y, int selectionStart, int selectionEnd, Colo
}
} else {
int /*long*/ ptr = OS.pango_layout_get_text(layout);
- int byteSelStart = (int)/*64*/(OS.g_utf8_offset_to_pointer(ptr, selectionStart) - ptr);
- int byteSelEnd = (int)/*64*/(OS.g_utf8_offset_to_pointer(ptr, selectionEnd + 1) - ptr);
+ int byteSelStart = (int)/*64*/(OS.g_utf16_offset_to_pointer(ptr, selectionStart) - ptr);
+ int byteSelEnd = (int)/*64*/(OS.g_utf16_offset_to_pointer(ptr, selectionEnd + 1) - ptr);
int strlen = OS.strlen(ptr);
byteSelStart = Math.min(byteSelStart, strlen);
byteSelEnd = Math.min(byteSelEnd, strlen);
@@ -599,8 +599,8 @@ void drawBorder(GC gc, int x, int y, GdkColor selectionColor) {
}
start = translateOffset(start);
int end = translateOffset(styles[i+1].start - 1);
- int byteStart = (int)/*64*/(OS.g_utf8_offset_to_pointer(ptr, start) - ptr);
- int byteEnd = (int)/*64*/(OS.g_utf8_offset_to_pointer(ptr, end + 1) - ptr);
+ int byteStart = (int)/*64*/(OS.g_utf16_offset_to_pointer(ptr, start) - ptr);
+ int byteEnd = (int)/*64*/(OS.g_utf16_offset_to_pointer(ptr, end + 1) - ptr);
int[] ranges = new int[]{byteStart, byteEnd};
int /*long*/ rgn = OS.gdk_pango_layout_get_clip_region(layout, x, y, ranges, ranges.length / 2);
if (rgn != 0) {
@@ -677,8 +677,8 @@ void drawBorder(GC gc, int x, int y, GdkColor selectionColor) {
}
start = translateOffset(start);
int end = translateOffset(styles[i+1].start - 1);
- int byteStart = (int)/*64*/(OS.g_utf8_offset_to_pointer(ptr, start) - ptr);
- int byteEnd = (int)/*64*/(OS.g_utf8_offset_to_pointer(ptr, end + 1) - ptr);
+ int byteStart = (int)/*64*/(OS.g_utf16_offset_to_pointer(ptr, start) - ptr);
+ int byteEnd = (int)/*64*/(OS.g_utf16_offset_to_pointer(ptr, end + 1) - ptr);
int[] ranges = new int[]{byteStart, byteEnd};
int /*long*/ rgn = OS.gdk_pango_layout_get_clip_region(layout, x, y, ranges, ranges.length / 2);
if (rgn != 0) {
@@ -776,8 +776,8 @@ void drawBorder(GC gc, int x, int y, GdkColor selectionColor) {
}
start = translateOffset(start);
int end = translateOffset(styles[i+1].start - 1);
- int byteStart = (int)/*64*/(OS.g_utf8_offset_to_pointer(ptr, start) - ptr);
- int byteEnd = (int)/*64*/(OS.g_utf8_offset_to_pointer(ptr, end + 1) - ptr);
+ int byteStart = (int)/*64*/(OS.g_utf16_offset_to_pointer(ptr, start) - ptr);
+ int byteEnd = (int)/*64*/(OS.g_utf16_offset_to_pointer(ptr, end + 1) - ptr);
int[] ranges = new int[]{byteStart, byteEnd};
int /*long*/ rgn = OS.gdk_pango_layout_get_clip_region(layout, x, y, ranges, ranges.length / 2);
if (rgn != 0) {
@@ -946,8 +946,8 @@ public Rectangle getBounds(int start, int end) {
start = translateOffset(start);
end = translateOffset(end);
int /*long*/ ptr = OS.pango_layout_get_text(layout);
- int byteStart = (int)/*64*/(OS.g_utf8_offset_to_pointer (ptr, start) - ptr);
- int byteEnd = (int)/*64*/(OS.g_utf8_offset_to_pointer (ptr, end + 1) - ptr);
+ int byteStart = (int)/*64*/(OS.g_utf16_offset_to_pointer (ptr, start) - ptr);
+ int byteEnd = (int)/*64*/(OS.g_utf16_offset_to_pointer (ptr, end + 1) - ptr);
int strlen = OS.strlen(ptr);
byteStart = Math.min(byteStart, strlen);
byteEnd = Math.min(byteEnd, strlen);
@@ -1086,7 +1086,7 @@ public int getLevel(int offset) {
PangoItem item = new PangoItem();
PangoLayoutRun run = new PangoLayoutRun();
int /*long*/ ptr = OS.pango_layout_get_text(layout);
- int /*long*/ byteOffset = OS.g_utf8_offset_to_pointer(ptr, offset) - ptr;
+ int /*long*/ byteOffset = OS.g_utf16_offset_to_pointer(ptr, offset) - ptr;
int strlen = OS.strlen(ptr);
byteOffset = Math.min(byteOffset, strlen);
do {
@@ -1180,7 +1180,7 @@ public int getLineIndex(int offset) {
offset = translateOffset(offset);
int line = 0;
int /*long*/ ptr = OS.pango_layout_get_text(layout);
- int /*long*/ byteOffset = OS.g_utf8_offset_to_pointer(ptr,offset) - ptr;
+ int /*long*/ byteOffset = OS.g_utf16_offset_to_pointer(ptr,offset) - ptr;
int strlen = OS.strlen(ptr);
byteOffset = Math.min(byteOffset, strlen);
int /*long*/ iter = OS.pango_layout_get_iter(layout);
@@ -1253,7 +1253,7 @@ public int[] getLineOffsets() {
for (int i = 0; i < lineCount; i++) {
int /*long*/ linePtr = OS.pango_layout_get_line(layout, i);
OS.memmove(line, linePtr, PangoLayoutLine.sizeof);
- int pos = (int)/*64*/OS.g_utf8_pointer_to_offset(ptr, ptr + line.start_index);
+ int pos = (int)/*64*/OS.g_utf16_pointer_to_offset(ptr, ptr + line.start_index);
offsets[i] = untranslateOffset(pos);
}
offsets[lineCount] = text.length();
@@ -1283,7 +1283,7 @@ public Point getLocation(int offset, boolean trailing) {
if (!(0 <= offset && offset <= length)) SWT.error(SWT.ERROR_INVALID_RANGE);
offset = translateOffset(offset);
int /*long*/ ptr = OS.pango_layout_get_text(layout);
- int byteOffset = (int)/*64*/(OS.g_utf8_offset_to_pointer(ptr, offset) - ptr);
+ int byteOffset = (int)/*64*/(OS.g_utf16_offset_to_pointer(ptr, offset) - ptr);
int strlen = OS.strlen(ptr);
byteOffset = Math.min(byteOffset, strlen);
PangoRectangle pos = new PangoRectangle();
@@ -1337,32 +1337,49 @@ int _getOffset (int offset, int movement, boolean forward) {
int[] nAttrs = new int[1];
OS.pango_layout_get_log_attrs(layout, attrs, nAttrs);
if (attrs[0] == 0) return offset + step;
- length = (int)/*64*/OS.g_utf8_strlen(OS.pango_layout_get_text(layout), -1);
- offset += step;
- int internalOffset = translateOffset(offset);
+
+ int /*long*/ ptr = OS.pango_layout_get_text(layout);
+ int utf8Offset = (int)/*64*/OS.g_utf16_offset_to_utf8_offset (ptr, translateOffset(offset));
+ int utf8Length = (int)/*64*/OS.g_utf8_strlen(ptr, -1);
+ utf8Offset += step;
PangoLogAttr logAttr = new PangoLogAttr();
- while (0 < internalOffset && internalOffset < length) {
- OS.memmove(logAttr, attrs[0] + internalOffset * PangoLogAttr.sizeof, PangoLogAttr.sizeof);
- if (((movement & SWT.MOVEMENT_CLUSTER) != 0) && logAttr.is_cursor_position) break;
+ while (0 <= utf8Offset && utf8Offset <= utf8Length) {
+ OS.memmove(logAttr, attrs[0] + utf8Offset * PangoLogAttr.sizeof, PangoLogAttr.sizeof);
+ boolean found = false;
+ if (((movement & SWT.MOVEMENT_CLUSTER) != 0) && logAttr.is_cursor_position) found = true;
if ((movement & SWT.MOVEMENT_WORD) != 0) {
if (forward) {
- if (logAttr.is_word_end) break;
+ if (logAttr.is_word_end) found = true;
} else {
- if (logAttr.is_word_start) break;
+ if (logAttr.is_word_start) found = true;
}
}
if ((movement & SWT.MOVEMENT_WORD_START) != 0) {
- if (logAttr.is_word_start) break;
- if (logAttr.is_sentence_end) break;
+ if (logAttr.is_word_start) found = true;
+ if (logAttr.is_sentence_end) found = true;
}
if ((movement & SWT.MOVEMENT_WORD_END) != 0) {
- if (logAttr.is_word_end) break;
+ if (logAttr.is_word_end) found = true;
+ }
+ if (found) {
+ int testOffset = (int)/*64*/OS.g_utf8_offset_to_utf16_offset (ptr, utf8Offset);
+ if (invalidOffsets != null) {
+ for (int i = 0; i < invalidOffsets.length; i++) {
+ if (testOffset == invalidOffsets[i]) {
+ found = false;
+ break;
+ }
+ }
+ }
+ if (found) {
+ offset = untranslateOffset(testOffset);
+ break;
+ }
}
- offset += step;
- internalOffset = translateOffset(offset);
+ utf8Offset += step;
}
OS.g_free(attrs[0]);
- return Math.min(Math.max(0, offset), text.length());
+ return Math.min(Math.max(0, offset), length);
}
/**
@@ -1454,7 +1471,7 @@ public int getOffset(int x, int y, int[] trailing) {
int[] piTrailing = new int[1];
OS.pango_layout_xy_to_index(layout, x * OS.PANGO_SCALE, y * OS.PANGO_SCALE, index, piTrailing);
int /*long*/ ptr = OS.pango_layout_get_text(layout);
- int offset = (int)/*64*/OS.g_utf8_pointer_to_offset(ptr, ptr + index[0]);
+ int offset = (int)/*64*/OS.g_utf16_pointer_to_offset(ptr, ptr + index[0]);
if (trailing != null) trailing[0] = piTrailing[0];
return untranslateOffset(offset);
}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Combo.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Combo.java
index ee9159ee8a..ecad9455b9 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Combo.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Combo.java
@@ -816,8 +816,10 @@ boolean dragDetect(int x, int y, boolean filter, boolean[] consume) {
OS.pango_layout_xy_to_index (layout, x * OS.PANGO_SCALE, y * OS.PANGO_SCALE, index, trailing);
int /*long*/ ptr = OS.pango_layout_get_text (layout);
int position = (int)/*64*/OS.g_utf8_pointer_to_offset (ptr, ptr + index[0]) + trailing[0];
- Point selection = getSelection ();
- if (selection.x <= position && position < selection.y) {
+ int [] start = new int [1];
+ int [] end = new int [1];
+ OS.gtk_editable_get_selection_bounds (entryHandle, start, end);
+ if (start [0] <= position && position < end [0]) {
if (super.dragDetect (x, y, filter, consume)) {
if (consume != null) consume [0] = true;
return true;
@@ -997,7 +999,7 @@ public Point getSelection () {
if (index != -1) length = getItem (index).length ();
} else {
int /*long*/ str = OS.gtk_entry_get_text (entryHandle);
- if (str != 0) length = (int)/*64*/OS.g_utf8_strlen (str, -1);
+ if (str != 0) length = (int)/*64*/OS.g_utf16_strlen (str, -1);
}
return new Point (0, length);
}
@@ -1005,6 +1007,9 @@ public Point getSelection () {
int [] end = new int [1];
if (entryHandle != 0) {
OS.gtk_editable_get_selection_bounds (entryHandle, start, end);
+ int /*long*/ ptr = OS.gtk_entry_get_text (entryHandle);
+ start[0] = (int)/*64*/OS.g_utf8_offset_to_utf16_offset (ptr, start[0]);
+ end[0] = (int)/*64*/OS.g_utf8_offset_to_utf16_offset (ptr, end[0]);
}
return new Point(start [0], end [0]);
}
@@ -1268,8 +1273,11 @@ int /*long*/ gtk_delete_text (int /*long*/ widget, int /*long*/ start_pos, int /
return 0;
}
if (!hooks (SWT.Verify) && !filters (SWT.Verify)) return 0;
- if (end_pos == -1) end_pos = OS.g_utf8_strlen (OS.gtk_entry_get_text (entryHandle), -1);
- String newText = verifyText ("", (int)/*64*/start_pos, (int)/*64*/end_pos);
+ int /*long*/ ptr = OS.gtk_entry_get_text (entryHandle);
+ if (end_pos == -1) end_pos = OS.g_utf8_strlen (ptr, -1);
+ int start = (int)/*64*/OS.g_utf8_offset_to_utf16_offset (ptr, start_pos);
+ int end = (int)/*64*/OS.g_utf8_offset_to_utf16_offset (ptr, end_pos);
+ String newText = verifyText ("", start, end);
if (newText == null) {
OS.g_signal_stop_emission_by_name (entryHandle, OS.delete_text);
} else {
@@ -1371,11 +1379,10 @@ int /*long*/ gtk_insert_text (int /*long*/ widget, int /*long*/ new_text, int /*
String oldText = new String (Converter.mbcsToWcs (null, buffer));
int [] pos = new int [1];
OS.memmove (pos, position, 4);
- if (pos [0] == -1) {
- int /*long*/ ptr = OS.gtk_entry_get_text (entryHandle);
- pos [0] = (int)/*64*/OS.g_utf8_strlen (ptr, -1);
- }
- String newText = verifyText (oldText, pos [0], pos [0]);
+ int /*long*/ ptr = OS.gtk_entry_get_text (entryHandle);
+ if (pos [0] == -1) pos [0] = (int)/*64*/OS.g_utf8_strlen (ptr, -1);
+ int start = (int)/*64*/OS.g_utf8_offset_to_utf16_offset (ptr, pos [0]);
+ String newText = verifyText (oldText, start, start);
if (newText != oldText) {
int [] newStart = new int [1], newEnd = new int [1];
OS.gtk_editable_get_selection_bounds (entryHandle, newStart, newEnd);
@@ -2113,8 +2120,11 @@ public void setSelection (Point selection) {
if (selection == null) error (SWT.ERROR_NULL_ARGUMENT);
if ((style & SWT.READ_ONLY) != 0) return;
if (entryHandle != 0) {
- OS.gtk_editable_set_position (entryHandle, selection.x);
- OS.gtk_editable_select_region (entryHandle, selection.x, selection.y);
+ int /*long*/ ptr = OS.gtk_entry_get_text (entryHandle);
+ int start = (int)/*64*/OS.g_utf16_offset_to_utf8_offset (ptr, selection.x);
+ int end = (int)/*64*/OS.g_utf16_offset_to_utf8_offset (ptr, selection.y);
+ OS.gtk_editable_set_position (entryHandle, start);
+ OS.gtk_editable_select_region (entryHandle, start, end);
}
}
@@ -2169,7 +2179,7 @@ public void setText (String string) {
*/
if (hooks (SWT.Verify) || filters (SWT.Verify)) {
int /*long*/ ptr = OS.gtk_entry_get_text (entryHandle);
- string = verifyText (string, 0, (int)/*64*/OS.g_utf8_strlen (ptr, -1));
+ string = verifyText (string, 0, (int)/*64*/OS.g_utf16_strlen (ptr, -1));
if (string == null) return;
}
byte [] buffer = Converter.wcsToMbcs (null, string, true);
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 cc0036e7c9..478aa3ef2c 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
@@ -309,8 +309,8 @@ int /*long*/ gtk_preedit_changed (int /*long*/ imcontext) {
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]) - 1;
+ ranges [i * 2] = (int)/*64*/OS.g_utf16_pointer_to_offset (preeditString [0], preeditString [0] + start [0]);
+ ranges [i * 2 + 1] = (int)/*64*/OS.g_utf16_pointer_to_offset (preeditString [0], preeditString [0] + end [0]) - 1;
styles [i] = new TextStyle (null, null, null);
int /*long*/ attr = OS.pango_attr_iterator_get (iterator, OS.PANGO_ATTR_FOREGROUND);
if (attr != 0) {
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Spinner.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Spinner.java
index 571a79122f..e64f86b890 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Spinner.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Spinner.java
@@ -647,8 +647,11 @@ int /*long*/ gtk_commit (int /*long*/ imContext, int /*long*/ text) {
int /*long*/ gtk_delete_text (int /*long*/ widget, int /*long*/ start_pos, int /*long*/ end_pos) {
if (!hooks (SWT.Verify) && !filters (SWT.Verify)) return 0;
- if (end_pos == -1) end_pos = OS.g_utf8_strlen (OS.gtk_entry_get_text (handle), -1);
- String newText = verifyText ("", (int)/*64*/start_pos, (int)/*64*/end_pos);
+ int /*long*/ ptr = OS.gtk_entry_get_text (handle);
+ if (end_pos == -1) end_pos = OS.g_utf8_strlen (ptr, -1);
+ int start = (int)/*64*/OS.g_utf8_offset_to_utf16_offset (ptr, start_pos);
+ int end = (int)/*64*/OS.g_utf8_offset_to_utf16_offset (ptr, end_pos);
+ String newText = verifyText ("", start, end);
if (newText == null) {
OS.g_signal_stop_emission_by_name (handle, OS.delete_text);
} else {
@@ -685,11 +688,10 @@ int /*long*/ gtk_insert_text (int /*long*/ widget, int /*long*/ new_text, int /*
String oldText = new String (Converter.mbcsToWcs (null, buffer));
int [] pos = new int [1];
OS.memmove (pos, position, 4);
- if (pos [0] == -1) {
- int /*long*/ ptr = OS.gtk_entry_get_text (handle);
- pos [0] = (int)/*64*/OS.g_utf8_strlen (ptr, -1);
- }
- String newText = verifyText (oldText, pos [0], pos [0]);
+ int /*long*/ ptr = OS.gtk_entry_get_text (handle);
+ if (pos [0] == -1) pos [0] = (int)/*64*/OS.g_utf8_strlen (ptr, -1);
+ int start = (int)/*64*/OS.g_utf16_pointer_to_offset (ptr, pos [0]);
+ String newText = verifyText (oldText, start, start);
if (newText != oldText) {
int [] newStart = new int [1], newEnd = new int [1];
OS.gtk_editable_get_selection_bounds (handle, newStart, newEnd);
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Text.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Text.java
index 164981043f..65a42fe5d5 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Text.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Text.java
@@ -670,12 +670,18 @@ public Point getCaretLocation () {
public int getCaretPosition () {
checkWidget ();
if ((style & SWT.SINGLE) != 0) {
- return OS.gtk_editable_get_position (handle);
+ int /*long*/ ptr = OS.gtk_entry_get_text (handle);
+ return (int)/*64*/OS.g_utf8_offset_to_utf16_offset (ptr, OS.gtk_editable_get_position (handle));
}
byte [] position = new byte [ITER_SIZEOF];
int /*long*/ mark = OS.gtk_text_buffer_get_insert (bufferHandle);
OS.gtk_text_buffer_get_iter_at_mark (bufferHandle, position, mark);
- return OS.gtk_text_iter_get_offset (position);
+ byte [] zero = new byte [ITER_SIZEOF];
+ OS.gtk_text_buffer_get_iter_at_offset(bufferHandle, zero, 0);
+ int /*long*/ ptr = OS.gtk_text_buffer_get_text (bufferHandle, zero, position, true);
+ int result = (int)/*64*/OS.g_utf8_offset_to_utf16_offset (ptr, OS.gtk_text_iter_get_offset (position));
+ OS.g_free (ptr);
+ return result;
}
/**
@@ -692,9 +698,15 @@ public int getCharCount () {
checkWidget ();
if ((style & SWT.SINGLE) != 0) {
int /*long*/ ptr = OS.gtk_entry_get_text (handle);
- return (int)/*64*/OS.g_utf8_strlen (ptr, -1);
- }
- return OS.gtk_text_buffer_get_char_count (bufferHandle);
+ return (int)/*64*/OS.g_utf16_strlen (ptr, -1);
+ }
+ byte [] startIter = new byte [ITER_SIZEOF];
+ byte [] endIter = new byte [ITER_SIZEOF];
+ OS.gtk_text_buffer_get_bounds (bufferHandle, startIter, endIter);
+ int /*long*/ ptr = OS.gtk_text_buffer_get_text (bufferHandle, startIter, endIter, true);
+ int result = (int)/*64*/OS.g_utf16_strlen(ptr, -1);
+ OS.g_free (ptr);
+ return result;
}
/**
@@ -862,11 +874,15 @@ public int getOrientation () {
int /*long*/ layout = OS.gtk_entry_get_layout (handle);
OS.pango_layout_xy_to_index (layout, point.x * OS.PANGO_SCALE, point.y * OS.PANGO_SCALE, index, trailing);
int /*long*/ ptr = OS.pango_layout_get_text (layout);
- position = (int)/*64*/OS.g_utf8_pointer_to_offset (ptr, ptr + index[0]) + trailing[0];
+ position = (int)/*64*/OS.g_utf16_pointer_to_offset (ptr, ptr + index[0]) + trailing[0];
} else {
byte [] p = new byte [ITER_SIZEOF];
OS.gtk_text_view_get_iter_at_location (handle, p, point.x, point.y);
- position = OS.gtk_text_iter_get_offset (p);
+ byte [] zero = new byte [ITER_SIZEOF];
+ OS.gtk_text_buffer_get_iter_at_offset(bufferHandle, zero, 0);
+ int /*long*/ ptr = OS.gtk_text_buffer_get_text (bufferHandle, zero, p, true);
+ position = (int)/*64*/OS.g_utf8_offset_to_utf16_offset (ptr, OS.gtk_text_iter_get_offset (p));
+ OS.g_free (ptr);
}
return position;
}
@@ -895,12 +911,21 @@ public Point getSelection () {
int [] start = new int [1];
int [] end = new int [1];
OS.gtk_editable_get_selection_bounds (handle, start, end);
+ int /*long*/ ptr = OS.gtk_entry_get_text (handle);
+ start[0] = (int)/*64*/OS.g_utf8_offset_to_utf16_offset (ptr, start[0]);
+ end[0] = (int)/*64*/OS.g_utf8_offset_to_utf16_offset (ptr, end[0]);
return new Point (start [0], end [0]);
}
- byte [] start = new byte [ITER_SIZEOF];
- byte [] end = new byte [ITER_SIZEOF];
- OS.gtk_text_buffer_get_selection_bounds (bufferHandle, start, end);
- return new Point (OS.gtk_text_iter_get_offset (start), OS.gtk_text_iter_get_offset (end));
+ byte [] startIter = new byte [ITER_SIZEOF];
+ byte [] endIter = new byte [ITER_SIZEOF];
+ OS.gtk_text_buffer_get_selection_bounds (bufferHandle, startIter, endIter);
+ byte [] zero = new byte [ITER_SIZEOF];
+ OS.gtk_text_buffer_get_iter_at_offset(bufferHandle, zero, 0);
+ int /*long*/ ptr = OS.gtk_text_buffer_get_text (bufferHandle, zero, endIter, true);
+ int start = (int)/*64*/OS.g_utf8_offset_to_utf16_offset (ptr, OS.gtk_text_iter_get_offset (startIter));
+ int end = (int)/*64*/OS.g_utf8_offset_to_utf16_offset (ptr, OS.gtk_text_iter_get_offset (endIter));
+ OS.g_free (ptr);
+ return new Point (start, end);
}
/**
@@ -1004,27 +1029,17 @@ public String getText () {
public String getText (int start, int end) {
checkWidget ();
if (!(start <= end && 0 <= end)) return "";
- int /*long*/ address;
- if ((style & SWT.SINGLE) != 0) {
- start = Math.max (0, start);
- address = OS.gtk_editable_get_chars (handle, start, end + 1);
- } else {
- int length = OS.gtk_text_buffer_get_char_count (bufferHandle);
- end = Math.min (end, length - 1);
- if (start > end) return "";
- start = Math.max (0, start);
- byte [] startIter = new byte [ITER_SIZEOF];
- byte [] endIter = new byte [ITER_SIZEOF];
- OS.gtk_text_buffer_get_iter_at_offset (bufferHandle, startIter, start);
- OS.gtk_text_buffer_get_iter_at_offset (bufferHandle, endIter, end + 1);
- address = OS.gtk_text_buffer_get_text (bufferHandle, startIter, endIter, true);
- }
- if (address == 0) error (SWT.ERROR_CANNOT_GET_TEXT);
- int length = OS.strlen (address);
- byte [] buffer = new byte [length];
- OS.memmove (buffer, address, length);
- OS.g_free (address);
- return new String (Converter.mbcsToWcs (null, buffer));
+ String str = getText ();
+ int length = str.length ();
+ end = Math.min (end, length - 1);
+ if (start > end) return "";
+ start = Math.max (0, start);
+ /*
+ * NOTE: The current implementation uses substring ()
+ * which can reference a potentially large character
+ * array.
+ */
+ return str.substring (start, end + 1);
}
/**
@@ -1188,7 +1203,7 @@ int /*long*/ gtk_changed (int /*long*/ widget) {
if ((style & SWT.SEARCH) != 0) {
if ((style & SWT.ICON_CANCEL) != 0) {
int /*long*/ ptr = OS.gtk_entry_get_text (handle);
- OS.gtk_entry_set_icon_sensitive (handle, OS.GTK_ENTRY_ICON_SECONDARY, OS.g_utf8_strlen (ptr, -1) > 0);
+ OS.gtk_entry_set_icon_sensitive (handle, OS.GTK_ENTRY_ICON_SECONDARY, OS.g_utf16_strlen (ptr, -1) > 0);
}
}
return 0;
@@ -1244,6 +1259,12 @@ int /*long*/ gtk_delete_range (int /*long*/ widget, int /*long*/ iter1, int /*lo
OS.memmove (endIter, iter2, endIter.length);
int start = OS.gtk_text_iter_get_offset (startIter);
int end = OS.gtk_text_iter_get_offset (endIter);
+ byte [] zero = new byte [ITER_SIZEOF];
+ OS.gtk_text_buffer_get_iter_at_offset(bufferHandle, zero, 0);
+ int /*long*/ ptr = OS.gtk_text_buffer_get_text (bufferHandle, zero, endIter, true);
+ start = (int)/*64*/OS.g_utf8_offset_to_utf16_offset (ptr, start);
+ end = (int)/*64*/OS.g_utf8_offset_to_utf16_offset (ptr, end);
+ OS.g_free (ptr);
String newText = verifyText ("", start, end);
if (newText == null) {
/* Remember the selection when the text was deleted */
@@ -1274,8 +1295,11 @@ int /*long*/ gtk_delete_range (int /*long*/ widget, int /*long*/ iter1, int /*lo
int /*long*/ gtk_delete_text (int /*long*/ widget, int /*long*/ start_pos, int /*long*/ end_pos) {
if (!hooks (SWT.Verify) && !filters (SWT.Verify)) return 0;
- if (end_pos == -1) end_pos = OS.g_utf8_strlen (OS.gtk_entry_get_text (handle), -1);
- String newText = verifyText ("", (int)/*64*/start_pos, (int)/*64*/end_pos);
+ int /*long*/ ptr = OS.gtk_entry_get_text (handle);
+ if (end_pos == -1) end_pos = OS.g_utf8_strlen (ptr, -1);
+ int start = (int)/*64*/OS.g_utf8_offset_to_utf16_offset (ptr, start_pos);
+ int end = (int)/*64*/OS.g_utf8_offset_to_utf16_offset (ptr, end_pos);
+ String newText = verifyText ("", start, end);
if (newText == null) {
/* Remember the selection when the text was deleted */
int [] newStart = new int [1], newEnd = new int [1];
@@ -1426,10 +1450,8 @@ int /*long*/ gtk_insert_text (int /*long*/ widget, int /*long*/ new_text, int /*
String oldText = new String (Converter.mbcsToWcs (null, buffer));
int [] pos = new int [1];
OS.memmove (pos, position, 4);
- if (pos [0] == -1) {
- int /*long*/ ptr = OS.gtk_entry_get_text (handle);
- pos [0] = (int)/*64*/OS.g_utf8_strlen (ptr, -1);
- }
+ int /*long*/ ptr = OS.gtk_entry_get_text (handle);
+ if (pos [0] == -1) pos [0] = (int)/*64*/OS.g_utf8_strlen (ptr, -1);
/* Use the selection when the text was deleted */
int start = pos [0], end = pos [0];
if (fixStart != -1 && fixEnd != -1) {
@@ -1437,6 +1459,8 @@ int /*long*/ gtk_insert_text (int /*long*/ widget, int /*long*/ new_text, int /*
end = fixEnd;
fixStart = fixEnd = -1;
}
+ start = (int)/*64*/OS.g_utf8_offset_to_utf16_offset (ptr, start);
+ end = (int)/*64*/OS.g_utf8_offset_to_utf16_offset (ptr, end);
String newText = verifyText (oldText, start, end);
if (newText != oldText) {
int [] newStart = new int [1], newEnd = new int [1];
@@ -1493,6 +1517,12 @@ int /*long*/ gtk_text_buffer_insert_text (int /*long*/ widget, int /*long*/ iter
end = fixEnd;
fixStart = fixEnd = -1;
}
+ byte [] zero = new byte [ITER_SIZEOF];
+ OS.gtk_text_buffer_get_iter_at_offset(bufferHandle, zero, 0);
+ int /*long*/ ptr = OS.gtk_text_buffer_get_text (bufferHandle, zero, position, true);
+ start = (int)/*64*/OS.g_utf8_offset_to_utf16_offset (ptr, start);
+ end = (int)/*64*/OS.g_utf8_offset_to_utf16_offset (ptr, end);
+ OS.g_free(ptr);
byte [] buffer = new byte [(int)/*64*/length];
OS.memmove (buffer, text, buffer.length);
String oldText = new String (Converter.mbcsToWcs (null, buffer));
@@ -1913,11 +1943,18 @@ public void setOrientation (int orientation) {
public void setSelection (int start) {
checkWidget ();
if ((style & SWT.SINGLE) != 0) {
+ int /*long*/ ptr = OS.gtk_entry_get_text (handle);
+ start = (int)/*64*/OS.g_utf16_offset_to_utf8_offset (ptr, start);
OS.gtk_editable_set_position (handle, start);
} else {
- byte [] position = new byte [ITER_SIZEOF];
- OS.gtk_text_buffer_get_iter_at_offset (bufferHandle, position, start);
- OS.gtk_text_buffer_place_cursor (bufferHandle, position);
+ byte [] startIter = new byte [ITER_SIZEOF];
+ byte [] endIter = new byte [ITER_SIZEOF];
+ OS.gtk_text_buffer_get_bounds (bufferHandle, startIter, endIter);
+ int /*long*/ ptr = OS.gtk_text_buffer_get_text (bufferHandle, startIter, endIter, true);
+ start = (int)/*64*/OS.g_utf16_offset_to_utf8_offset (ptr, start);
+ OS.g_free (ptr);
+ OS.gtk_text_buffer_get_iter_at_offset (bufferHandle, startIter, start);
+ OS.gtk_text_buffer_place_cursor (bufferHandle, startIter);
int /*long*/ mark = OS.gtk_text_buffer_get_insert (bufferHandle);
OS.gtk_text_view_scroll_mark_onscreen (handle, mark);
}
@@ -1950,12 +1987,20 @@ public void setSelection (int start) {
*/
public void setSelection (int start, int end) {
checkWidget ();
- if ((style & SWT.SINGLE) != 0) {
+ if ((style & SWT.SINGLE) != 0) {
+ int /*long*/ ptr = OS.gtk_entry_get_text (handle);
+ start = (int)/*64*/OS.g_utf16_offset_to_utf8_offset (ptr, start);
+ end = (int)/*64*/OS.g_utf16_offset_to_utf8_offset (ptr, end);
OS.gtk_editable_set_position (handle, start);
OS.gtk_editable_select_region (handle, start, end);
} else {
byte [] startIter = new byte [ITER_SIZEOF];
byte [] endIter = new byte [ITER_SIZEOF];
+ OS.gtk_text_buffer_get_bounds (bufferHandle, startIter, endIter);
+ int /*long*/ ptr = OS.gtk_text_buffer_get_text (bufferHandle, startIter, endIter, true);
+ start = (int)/*64*/OS.g_utf16_offset_to_utf8_offset (ptr, start);
+ end = (int)/*64*/OS.g_utf16_offset_to_utf8_offset (ptr, end);
+ OS.g_free (ptr);
OS.gtk_text_buffer_get_iter_at_offset (bufferHandle, startIter, start);
OS.gtk_text_buffer_get_iter_at_offset (bufferHandle, endIter, end);
int /*long*/ insertMark = OS.gtk_text_buffer_get_insert (bufferHandle);
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Widget.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Widget.java
index a4bec1c206..c12c4c3a2a 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Widget.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Widget.java
@@ -1287,7 +1287,7 @@ void sendEvent (int eventType, Event event, boolean send) {
boolean sendKeyEvent (int type, GdkEventKey keyEvent) {
int length = keyEvent.length;
- if (keyEvent.string == 0 || OS.g_utf8_strlen (keyEvent.string, length) <= 1) {
+ if (keyEvent.string == 0 || OS.g_utf16_strlen (keyEvent.string, length) <= 1) {
Event event = new Event ();
event.time = keyEvent.time;
if (!setKeyState (event, keyEvent)) return true;
@@ -1550,7 +1550,7 @@ boolean setInputState (Event event, int state) {
}
boolean setKeyState (Event event, GdkEventKey keyEvent) {
- if (keyEvent.string != 0 && OS.g_utf8_strlen (keyEvent.string, keyEvent.length) > 1) return false;
+ if (keyEvent.string != 0 && OS.g_utf16_strlen (keyEvent.string, keyEvent.length) > 1) return false;
boolean isNull = false;
event.keyCode = Display.translateKey (keyEvent.keyval);
switch (keyEvent.keyval) {