Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 65899
Collapse All | Expand All

(-)Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledText.java (-2 / +4 lines)
Lines 5419-5425 Link Here
5419
	TextLayout layout = renderer.getTextLayout(lineIndex);
5419
	TextLayout layout = renderer.getTextLayout(lineIndex);
5420
	if (lineLength != 0  && offsetInLine <= lineLength) {
5420
	if (lineLength != 0  && offsetInLine <= lineLength) {
5421
		if (offsetInLine == lineLength) {
5421
		if (offsetInLine == lineLength) {
5422
			point = layout.getLocation(offsetInLine - 1, true);
5422
			offsetInLine = layout.getPreviousOffset(offsetInLine, SWT.MOVEMENT_CLUSTER); 
5423
			point = layout.getLocation(offsetInLine, true);
5423
		} else {
5424
		} else {
5424
			switch (caretAlignment) {
5425
			switch (caretAlignment) {
5425
				case OFFSET_LEADING:
5426
				case OFFSET_LEADING:
Lines 5430-5436 Link Here
5430
					if (offsetInLine == 0) {
5431
					if (offsetInLine == 0) {
5431
						point = layout.getLocation(offsetInLine, false);
5432
						point = layout.getLocation(offsetInLine, false);
5432
					} else {
5433
					} else {
5433
						point = layout.getLocation(offsetInLine - 1, true);
5434
						offsetInLine = layout.getPreviousOffset(offsetInLine, SWT.MOVEMENT_CLUSTER); 
5435
						point = layout.getLocation(offsetInLine, true);
5434
					}
5436
					}
5435
					break;
5437
					break;
5436
			}
5438
			}
(-)Eclipse SWT PI/gtk/library/os.c (+60 lines)
Lines 4444-4449 Link Here
4444
}
4444
}
4445
#endif
4445
#endif
4446
4446
4447
#ifndef NO__1g_1utf16_1offset_1to_1pointer
4448
JNIEXPORT jintLong JNICALL OS_NATIVE(_1g_1utf16_1offset_1to_1pointer)
4449
	(JNIEnv *env, jclass that, jintLong arg0, jintLong arg1)
4450
{
4451
	jintLong rc = 0;
4452
	OS_NATIVE_ENTER(env, that, _1g_1utf16_1offset_1to_1pointer_FUNC);
4453
	rc = (jintLong)g_utf16_offset_to_pointer((const gchar *)arg0, arg1);
4454
	OS_NATIVE_EXIT(env, that, _1g_1utf16_1offset_1to_1pointer_FUNC);
4455
	return rc;
4456
}
4457
#endif
4458
4459
#ifndef NO__1g_1utf16_1offset_1to_1utf8_1offset
4460
JNIEXPORT jintLong JNICALL OS_NATIVE(_1g_1utf16_1offset_1to_1utf8_1offset)
4461
	(JNIEnv *env, jclass that, jintLong arg0, jintLong arg1)
4462
{
4463
	jintLong rc = 0;
4464
	OS_NATIVE_ENTER(env, that, _1g_1utf16_1offset_1to_1utf8_1offset_FUNC);
4465
	rc = (jintLong)g_utf16_offset_to_utf8_offset((const gchar *)arg0, arg1);
4466
	OS_NATIVE_EXIT(env, that, _1g_1utf16_1offset_1to_1utf8_1offset_FUNC);
4467
	return rc;
4468
}
4469
#endif
4470
4471
#ifndef NO__1g_1utf16_1pointer_1to_1offset
4472
JNIEXPORT jintLong JNICALL OS_NATIVE(_1g_1utf16_1pointer_1to_1offset)
4473
	(JNIEnv *env, jclass that, jintLong arg0, jintLong arg1)
4474
{
4475
	jintLong rc = 0;
4476
	OS_NATIVE_ENTER(env, that, _1g_1utf16_1pointer_1to_1offset_FUNC);
4477
	rc = (jintLong)g_utf16_pointer_to_offset((const gchar *)arg0, (const gchar *)arg1);
4478
	OS_NATIVE_EXIT(env, that, _1g_1utf16_1pointer_1to_1offset_FUNC);
4479
	return rc;
4480
}
4481
#endif
4482
4483
#ifndef NO__1g_1utf16_1strlen
4484
JNIEXPORT jintLong JNICALL OS_NATIVE(_1g_1utf16_1strlen)
4485
	(JNIEnv *env, jclass that, jintLong arg0, jintLong arg1)
4486
{
4487
	jintLong rc = 0;
4488
	OS_NATIVE_ENTER(env, that, _1g_1utf16_1strlen_FUNC);
4489
	rc = (jintLong)g_utf16_strlen((const gchar *)arg0, arg1);
4490
	OS_NATIVE_EXIT(env, that, _1g_1utf16_1strlen_FUNC);
4491
	return rc;
4492
}
4493
#endif
4494
4447
#ifndef NO__1g_1utf16_1to_1utf8
4495
#ifndef NO__1g_1utf16_1to_1utf8
4448
JNIEXPORT jintLong JNICALL OS_NATIVE(_1g_1utf16_1to_1utf8)
4496
JNIEXPORT jintLong JNICALL OS_NATIVE(_1g_1utf16_1to_1utf8)
4449
	(JNIEnv *env, jclass that, jcharArray arg0, jintLong arg1, jintLongArray arg2, jintLongArray arg3, jintLongArray arg4)
4497
	(JNIEnv *env, jclass that, jcharArray arg0, jintLong arg1, jintLongArray arg2, jintLongArray arg3, jintLongArray arg4)
Lines 4501-4506 Link Here
4501
}
4549
}
4502
#endif
4550
#endif
4503
4551
4552
#ifndef NO__1g_1utf8_1offset_1to_1utf16_1offset
4553
JNIEXPORT jintLong JNICALL OS_NATIVE(_1g_1utf8_1offset_1to_1utf16_1offset)
4554
	(JNIEnv *env, jclass that, jintLong arg0, jintLong arg1)
4555
{
4556
	jintLong rc = 0;
4557
	OS_NATIVE_ENTER(env, that, _1g_1utf8_1offset_1to_1utf16_1offset_FUNC);
4558
	rc = (jintLong)g_utf8_offset_to_utf16_offset((const gchar *)arg0, arg1);
4559
	OS_NATIVE_EXIT(env, that, _1g_1utf8_1offset_1to_1utf16_1offset_FUNC);
4560
	return rc;
4561
}
4562
#endif
4563
4504
#ifndef NO__1g_1utf8_1pointer_1to_1offset
4564
#ifndef NO__1g_1utf8_1pointer_1to_1offset
4505
JNIEXPORT jintLong JNICALL OS_NATIVE(_1g_1utf8_1pointer_1to_1offset)
4565
JNIEXPORT jintLong JNICALL OS_NATIVE(_1g_1utf8_1pointer_1to_1offset)
4506
	(JNIEnv *env, jclass that, jintLong arg0, jintLong arg1)
4566
	(JNIEnv *env, jclass that, jintLong arg0, jintLong arg1)
(-)Eclipse SWT PI/gtk/library/os_custom.c (+69 lines)
Lines 118-120 Link Here
118
}
118
}
119
#endif
119
#endif
120
120
121
glong g_utf16_strlen(const gchar *str, glong max) {
122
	const gchar *s = str;
123
	guchar ch;
124
	glong offset = 0;
125
	if (!s || max == 0) return 0;
126
	if (max < 0) {
127
		while (*s) {
128
			if (0xf0 <= *(guchar*)s && *(guchar*)s <= 0xfd) offset++;
129
			s = g_utf8_next_char (s);
130
			offset++;
131
		}
132
		
133
	} else {
134
		while (*s) {
135
			ch = *(guchar*)s;
136
			s = g_utf8_next_char (s);
137
			if (s - str > max) break;
138
			if (0xf0 <= ch && ch <= 0xfd) offset++;
139
			offset++;
140
		}
141
	}
142
	return offset;
143
}
144
145
glong g_utf16_pointer_to_offset(const gchar *str, const gchar * pos) {
146
	const gchar *s = str;
147
	glong offset = 0;
148
	if (!s || !pos) return 0; 
149
	while (s < pos && *s) {
150
		if (0xf0 <= *(guchar*)s && *(guchar*)s <= 0xfd) offset++;
151
		s = g_utf8_next_char (s);
152
		offset++;
153
	}
154
	return offset;
155
}
156
157
gchar* g_utf16_offset_to_pointer(const gchar* str, glong offset) {
158
	const gchar *s = str;
159
	if (!s) return 0; 
160
	while (offset-- > 0 && *s) {
161
		if (0xf0 <= *(guchar*)s && *(guchar*)s <= 0xfd) offset--;
162
		s = g_utf8_next_char (s);
163
	}
164
	return (gchar *)s;
165
}
166
167
glong g_utf16_offset_to_utf8_offset(const gchar* str, glong offset) {
168
	glong r = 0;
169
	const gchar *s = str;
170
	if (!s) return 0;
171
	while (offset-- > 0 && *s) {
172
		if (0xf0 <= *(guchar*)s && *(guchar*)s <= 0xfd) offset--;
173
		s = g_utf8_next_char (s);
174
		r++;
175
	}
176
	return r;
177
}
178
179
glong g_utf8_offset_to_utf16_offset(const gchar* str, glong offset) {
180
	glong r = 0;
181
	const gchar *s = str;
182
	if (!s) return 0;
183
	while (offset-- > 0 && *s) {
184
		if (0xf0 <= *(guchar*)s && *(guchar*)s <= 0xfd) r++;
185
		s = g_utf8_next_char (s);
186
		r++;
187
	}
188
	return r;
189
}
(-)Eclipse SWT PI/gtk/library/os_custom.h (-1 / +5 lines)
Lines 353-356 Link Here
353
LOAD_FUNCTION(fp, gtk_status_icon_position_menu) \
353
LOAD_FUNCTION(fp, gtk_status_icon_position_menu) \
354
rc = (jintLong)fp;
354
rc = (jintLong)fp;
355
355
356
356
glong g_utf16_pointer_to_offset(const gchar*, const gchar*);
357
gchar* g_utf16_offset_to_pointer(const gchar*, glong);
358
glong g_utf16_strlen(const gchar*, glong max);
359
glong g_utf16_offset_to_utf8_offset(const gchar*, glong);
360
glong g_utf8_offset_to_utf16_offset(const gchar*, glong);
(-)Eclipse SWT PI/gtk/library/os_stats.c (-2 / +7 lines)
Lines 18-25 Link Here
18
18
19
#ifdef NATIVE_STATS
19
#ifdef NATIVE_STATS
20
20
21
int OS_nativeFunctionCount = 1384;
21
int OS_nativeFunctionCount = 1389;
22
int OS_nativeFunctionCallCount[1384];
22
int OS_nativeFunctionCallCount[1389];
23
char * OS_nativeFunctionNames[] = {
23
char * OS_nativeFunctionNames[] = {
24
#ifndef JNI64
24
#ifndef JNI64
25
	"Call__IIII",
25
	"Call__IIII",
Lines 390-397 Link Here
390
	"_1g_1type_1parent",
390
	"_1g_1type_1parent",
391
	"_1g_1type_1query",
391
	"_1g_1type_1query",
392
	"_1g_1type_1register_1static",
392
	"_1g_1type_1register_1static",
393
	"_1g_1utf16_1offset_1to_1pointer",
394
	"_1g_1utf16_1offset_1to_1utf8_1offset",
395
	"_1g_1utf16_1pointer_1to_1offset",
396
	"_1g_1utf16_1strlen",
393
	"_1g_1utf16_1to_1utf8",
397
	"_1g_1utf16_1to_1utf8",
394
	"_1g_1utf8_1offset_1to_1pointer",
398
	"_1g_1utf8_1offset_1to_1pointer",
399
	"_1g_1utf8_1offset_1to_1utf16_1offset",
395
	"_1g_1utf8_1pointer_1to_1offset",
400
	"_1g_1utf8_1pointer_1to_1offset",
396
	"_1g_1utf8_1strlen",
401
	"_1g_1utf8_1strlen",
397
#ifndef JNI64
402
#ifndef JNI64
(-)Eclipse SWT PI/gtk/library/os_stats.h (+5 lines)
Lines 398-405 Link Here
398
	_1g_1type_1parent_FUNC,
398
	_1g_1type_1parent_FUNC,
399
	_1g_1type_1query_FUNC,
399
	_1g_1type_1query_FUNC,
400
	_1g_1type_1register_1static_FUNC,
400
	_1g_1type_1register_1static_FUNC,
401
	_1g_1utf16_1offset_1to_1pointer_FUNC,
402
	_1g_1utf16_1offset_1to_1utf8_1offset_FUNC,
403
	_1g_1utf16_1pointer_1to_1offset_FUNC,
404
	_1g_1utf16_1strlen_FUNC,
401
	_1g_1utf16_1to_1utf8_FUNC,
405
	_1g_1utf16_1to_1utf8_FUNC,
402
	_1g_1utf8_1offset_1to_1pointer_FUNC,
406
	_1g_1utf8_1offset_1to_1pointer_FUNC,
407
	_1g_1utf8_1offset_1to_1utf16_1offset_FUNC,
403
	_1g_1utf8_1pointer_1to_1offset_FUNC,
408
	_1g_1utf8_1pointer_1to_1offset_FUNC,
404
	_1g_1utf8_1strlen_FUNC,
409
	_1g_1utf8_1strlen_FUNC,
405
#ifndef JNI64
410
#ifndef JNI64
(-)Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/OS.java (+53 lines)
Lines 3325-3330 Link Here
3325
	}
3325
	}
3326
}
3326
}
3327
/** @param str cast=(const gchar *) */
3327
/** @param str cast=(const gchar *) */
3328
public static final native int /*long*/ _g_utf16_offset_to_pointer(int /*long*/ str, int /*long*/ offset);
3329
public static final int /*long*/ g_utf16_offset_to_pointer(int /*long*/ str, int /*long*/ offset) {
3330
	lock.lock();
3331
	try {
3332
		return _g_utf16_offset_to_pointer(str, offset);
3333
	} finally {
3334
		lock.unlock();
3335
	}
3336
}
3337
/**
3338
 * @param str cast=(const gchar *)
3339
 * @param pos cast=(const gchar *)
3340
 */
3341
public static final native int /*long*/ _g_utf16_pointer_to_offset(int /*long*/ str, int /*long*/ pos);
3342
public static final int /*long*/ g_utf16_pointer_to_offset(int /*long*/ str, int /*long*/ pos) {
3343
	lock.lock();
3344
	try {
3345
		return _g_utf16_pointer_to_offset(str, pos);
3346
	} finally {
3347
		lock.unlock();
3348
	}
3349
}
3350
/** @param str cast=(const gchar *) */
3351
public static final native int /*long*/ _g_utf16_strlen(int /*long*/ str, int /*long*/ max);
3352
public static final int /*long*/ g_utf16_strlen(int /*long*/ str, int /*long*/ max) {
3353
	lock.lock();
3354
	try {
3355
		return _g_utf16_strlen(str, max);
3356
	} finally {
3357
		lock.unlock();
3358
	}
3359
}
3360
/** @param str cast=(const gchar *) */
3361
public static final native int /*long*/ _g_utf8_offset_to_utf16_offset(int /*long*/ str, int /*long*/ offset);
3362
public static final int /*long*/ g_utf8_offset_to_utf16_offset(int /*long*/ str, int /*long*/ offset) {
3363
	lock.lock();
3364
	try {
3365
		return _g_utf8_offset_to_utf16_offset(str, offset);
3366
	} finally {
3367
		lock.unlock();
3368
	}
3369
}
3370
/** @param str cast=(const gchar *) */
3371
public static final native int /*long*/ _g_utf16_offset_to_utf8_offset(int /*long*/ str, int /*long*/ offset);
3372
public static final int /*long*/ g_utf16_offset_to_utf8_offset(int /*long*/ str, int /*long*/ offset) {
3373
	lock.lock();
3374
	try {
3375
		return _g_utf16_offset_to_utf8_offset(str, offset);
3376
	} finally {
3377
		lock.unlock();
3378
	}
3379
}
3380
/** @param str cast=(const gchar *) */
3328
public static final native int /*long*/ _g_utf8_strlen(int /*long*/ str, int /*long*/ max);
3381
public static final native int /*long*/ _g_utf8_strlen(int /*long*/ str, int /*long*/ max);
3329
public static final int /*long*/ g_utf8_strlen(int /*long*/ str, int /*long*/ max) {
3382
public static final int /*long*/ g_utf8_strlen(int /*long*/ str, int /*long*/ max) {
3330
	lock.lock();
3383
	lock.lock();
(-)Eclipse SWT/gtk/org/eclipse/swt/graphics/TextLayout.java (-35 / +52 lines)
Lines 142-148 Link Here
142
			attribute.end_index = bytePos + offset + 6;
142
			attribute.end_index = bytePos + offset + 6;
143
			OS.memmove (attr, attribute, PangoAttribute.sizeof);
143
			OS.memmove (attr, attribute, PangoAttribute.sizeof);
144
			OS.pango_attr_list_insert(attrList, attr);			
144
			OS.pango_attr_list_insert(attrList, attr);			
145
			int pos = (int)/*64*/OS.g_utf8_pointer_to_offset(ptr, ptr + bytePos);
145
			int pos = (int)/*64*/OS.g_utf16_pointer_to_offset(ptr, ptr + bytePos);
146
			chars[pos + lineIndex * 2] = ZWS;
146
			chars[pos + lineIndex * 2] = ZWS;
147
			chars[pos + lineIndex * 2 + 1] = ZWNBS;
147
			chars[pos + lineIndex * 2 + 1] = ZWNBS;
148
			segmentsText.getChars(oldPos, pos, chars,  oldPos + lineIndex * 2);
148
			segmentsText.getChars(oldPos, pos, chars,  oldPos + lineIndex * 2);
Lines 184-191 Link Here
184
		if (style == null) continue;
184
		if (style == null) continue;
185
		int start = translateOffset(styleItem.start);
185
		int start = translateOffset(styleItem.start);
186
		int end = translateOffset(styles[i+1].start - 1);
186
		int end = translateOffset(styles[i+1].start - 1);
187
		int byteStart = (int)/*64*/(OS.g_utf8_offset_to_pointer(ptr, start) - ptr);
187
		int byteStart = (int)/*64*/(OS.g_utf16_offset_to_pointer(ptr, start) - ptr);
188
		int byteEnd = (int)/*64*/(OS.g_utf8_offset_to_pointer(ptr, end + 1) - ptr);
188
		int byteEnd = (int)/*64*/(OS.g_utf16_offset_to_pointer(ptr, end + 1) - ptr);
189
		byteStart = Math.min(byteStart, strlen);
189
		byteStart = Math.min(byteStart, strlen);
190
		byteEnd = Math.min(byteEnd, strlen);
190
		byteEnd = Math.min(byteEnd, strlen);
191
		Font font = style.font;
191
		Font font = style.font;
Lines 430-438 Link Here
430
			OS.pango_layout_iter_get_line_extents(iter, null, rect);
430
			OS.pango_layout_iter_get_line_extents(iter, null, rect);
431
			if (OS.pango_layout_iter_next_line(iter)) {
431
			if (OS.pango_layout_iter_next_line(iter)) {
432
				int bytePos = OS.pango_layout_iter_get_index(iter);
432
				int bytePos = OS.pango_layout_iter_get_index(iter);
433
				lineEnd = (int)/*64*/OS.g_utf8_pointer_to_offset(ptr, ptr + bytePos);
433
				lineEnd = (int)/*64*/OS.g_utf16_pointer_to_offset(ptr, ptr + bytePos);
434
			} else {
434
			} else {
435
				lineEnd = (int)/*64*/OS.g_utf8_strlen(ptr, -1);
435
				lineEnd = (int)/*64*/OS.g_utf16_strlen(ptr, -1);
436
			}
436
			}
437
			boolean extent = false;
437
			boolean extent = false;
438
			if (lineIndex == lineCount - 1 && (flags & SWT.LAST_LINE_SELECTION) != 0) {
438
			if (lineIndex == lineCount - 1 && (flags & SWT.LAST_LINE_SELECTION) != 0) {
Lines 494-500 Link Here
494
	} else {
494
	} else {
495
		selectionStart = Math.min(Math.max(0, selectionStart), length - 1);
495
		selectionStart = Math.min(Math.max(0, selectionStart), length - 1);
496
		selectionEnd = Math.min(Math.max(0, selectionEnd), length - 1);
496
		selectionEnd = Math.min(Math.max(0, selectionEnd), length - 1);
497
		length = (int)/*64*/OS.g_utf8_strlen(OS.pango_layout_get_text(layout), -1);
497
		length = (int)/*64*/OS.g_utf16_strlen(OS.pango_layout_get_text(layout), -1);
498
		selectionStart = translateOffset(selectionStart);
498
		selectionStart = translateOffset(selectionStart);
499
		selectionEnd = translateOffset(selectionEnd);
499
		selectionEnd = translateOffset(selectionEnd);
500
		if (selectionForeground == null) selectionForeground = device.getSystemColor(SWT.COLOR_LIST_SELECTION_TEXT);
500
		if (selectionForeground == null) selectionForeground = device.getSystemColor(SWT.COLOR_LIST_SELECTION_TEXT);
Lines 518-525 Link Here
518
			}
518
			}
519
		} else {
519
		} else {
520
			int /*long*/ ptr = OS.pango_layout_get_text(layout);
520
			int /*long*/ ptr = OS.pango_layout_get_text(layout);
521
			int byteSelStart = (int)/*64*/(OS.g_utf8_offset_to_pointer(ptr, selectionStart) - ptr);
521
			int byteSelStart = (int)/*64*/(OS.g_utf16_offset_to_pointer(ptr, selectionStart) - ptr);
522
			int byteSelEnd = (int)/*64*/(OS.g_utf8_offset_to_pointer(ptr, selectionEnd + 1) - ptr);
522
			int byteSelEnd = (int)/*64*/(OS.g_utf16_offset_to_pointer(ptr, selectionEnd + 1) - ptr);
523
			int strlen = OS.strlen(ptr);
523
			int strlen = OS.strlen(ptr);
524
			byteSelStart = Math.min(byteSelStart, strlen);
524
			byteSelStart = Math.min(byteSelStart, strlen);
525
			byteSelEnd = Math.min(byteSelEnd, strlen);
525
			byteSelEnd = Math.min(byteSelEnd, strlen);
Lines 599-606 Link Here
599
			}
599
			}
600
			start = translateOffset(start);
600
			start = translateOffset(start);
601
			int end = translateOffset(styles[i+1].start - 1);
601
			int end = translateOffset(styles[i+1].start - 1);
602
			int byteStart = (int)/*64*/(OS.g_utf8_offset_to_pointer(ptr, start) - ptr);
602
			int byteStart = (int)/*64*/(OS.g_utf16_offset_to_pointer(ptr, start) - ptr);
603
			int byteEnd = (int)/*64*/(OS.g_utf8_offset_to_pointer(ptr, end + 1) - ptr);
603
			int byteEnd = (int)/*64*/(OS.g_utf16_offset_to_pointer(ptr, end + 1) - ptr);
604
			int[] ranges = new int[]{byteStart, byteEnd};
604
			int[] ranges = new int[]{byteStart, byteEnd};
605
			int /*long*/ rgn = OS.gdk_pango_layout_get_clip_region(layout, x, y, ranges, ranges.length / 2);
605
			int /*long*/ rgn = OS.gdk_pango_layout_get_clip_region(layout, x, y, ranges, ranges.length / 2);
606
			if (rgn != 0) {
606
			if (rgn != 0) {
Lines 677-684 Link Here
677
			}
677
			}
678
			start = translateOffset(start);
678
			start = translateOffset(start);
679
			int end = translateOffset(styles[i+1].start - 1);
679
			int end = translateOffset(styles[i+1].start - 1);
680
			int byteStart = (int)/*64*/(OS.g_utf8_offset_to_pointer(ptr, start) - ptr);
680
			int byteStart = (int)/*64*/(OS.g_utf16_offset_to_pointer(ptr, start) - ptr);
681
			int byteEnd = (int)/*64*/(OS.g_utf8_offset_to_pointer(ptr, end + 1) - ptr);
681
			int byteEnd = (int)/*64*/(OS.g_utf16_offset_to_pointer(ptr, end + 1) - ptr);
682
			int[] ranges = new int[]{byteStart, byteEnd};
682
			int[] ranges = new int[]{byteStart, byteEnd};
683
			int /*long*/ rgn = OS.gdk_pango_layout_get_clip_region(layout, x, y, ranges, ranges.length / 2);
683
			int /*long*/ rgn = OS.gdk_pango_layout_get_clip_region(layout, x, y, ranges, ranges.length / 2);
684
			if (rgn != 0) {
684
			if (rgn != 0) {
Lines 776-783 Link Here
776
			}
776
			}
777
			start = translateOffset(start);
777
			start = translateOffset(start);
778
			int end = translateOffset(styles[i+1].start - 1);
778
			int end = translateOffset(styles[i+1].start - 1);
779
			int byteStart = (int)/*64*/(OS.g_utf8_offset_to_pointer(ptr, start) - ptr);
779
			int byteStart = (int)/*64*/(OS.g_utf16_offset_to_pointer(ptr, start) - ptr);
780
			int byteEnd = (int)/*64*/(OS.g_utf8_offset_to_pointer(ptr, end + 1) - ptr);
780
			int byteEnd = (int)/*64*/(OS.g_utf16_offset_to_pointer(ptr, end + 1) - ptr);
781
			int[] ranges = new int[]{byteStart, byteEnd};
781
			int[] ranges = new int[]{byteStart, byteEnd};
782
			int /*long*/ rgn = OS.gdk_pango_layout_get_clip_region(layout, x, y, ranges, ranges.length / 2);
782
			int /*long*/ rgn = OS.gdk_pango_layout_get_clip_region(layout, x, y, ranges, ranges.length / 2);
783
			if (rgn != 0) {
783
			if (rgn != 0) {
Lines 946-953 Link Here
946
	start = translateOffset(start);
946
	start = translateOffset(start);
947
	end = translateOffset(end);
947
	end = translateOffset(end);
948
	int /*long*/ ptr = OS.pango_layout_get_text(layout);
948
	int /*long*/ ptr = OS.pango_layout_get_text(layout);
949
	int byteStart = (int)/*64*/(OS.g_utf8_offset_to_pointer (ptr, start) - ptr);
949
	int byteStart = (int)/*64*/(OS.g_utf16_offset_to_pointer (ptr, start) - ptr);
950
	int byteEnd = (int)/*64*/(OS.g_utf8_offset_to_pointer (ptr, end + 1) - ptr);
950
	int byteEnd = (int)/*64*/(OS.g_utf16_offset_to_pointer (ptr, end + 1) - ptr);
951
	int strlen = OS.strlen(ptr);
951
	int strlen = OS.strlen(ptr);
952
	byteStart = Math.min(byteStart, strlen);
952
	byteStart = Math.min(byteStart, strlen);
953
	byteEnd = Math.min(byteEnd, strlen);
953
	byteEnd = Math.min(byteEnd, strlen);
Lines 1086-1092 Link Here
1086
	PangoItem item = new PangoItem();
1086
	PangoItem item = new PangoItem();
1087
	PangoLayoutRun run = new PangoLayoutRun();
1087
	PangoLayoutRun run = new PangoLayoutRun();
1088
	int /*long*/ ptr = OS.pango_layout_get_text(layout);
1088
	int /*long*/ ptr = OS.pango_layout_get_text(layout);
1089
	int /*long*/ byteOffset = OS.g_utf8_offset_to_pointer(ptr, offset) - ptr;
1089
	int /*long*/ byteOffset = OS.g_utf16_offset_to_pointer(ptr, offset) - ptr;
1090
	int strlen = OS.strlen(ptr);
1090
	int strlen = OS.strlen(ptr);
1091
	byteOffset = Math.min(byteOffset, strlen);
1091
	byteOffset = Math.min(byteOffset, strlen);
1092
	do {
1092
	do {
Lines 1180-1186 Link Here
1180
	offset = translateOffset(offset);
1180
	offset = translateOffset(offset);
1181
	int line = 0;
1181
	int line = 0;
1182
	int /*long*/ ptr = OS.pango_layout_get_text(layout);
1182
	int /*long*/ ptr = OS.pango_layout_get_text(layout);
1183
	int /*long*/ byteOffset = OS.g_utf8_offset_to_pointer(ptr,offset) - ptr;
1183
	int /*long*/ byteOffset = OS.g_utf16_offset_to_pointer(ptr,offset) - ptr;
1184
	int strlen = OS.strlen(ptr);
1184
	int strlen = OS.strlen(ptr);
1185
	byteOffset = Math.min(byteOffset, strlen);
1185
	byteOffset = Math.min(byteOffset, strlen);
1186
	int /*long*/ iter = OS.pango_layout_get_iter(layout);
1186
	int /*long*/ iter = OS.pango_layout_get_iter(layout);
Lines 1253-1259 Link Here
1253
	for (int i = 0; i < lineCount; i++) {
1253
	for (int i = 0; i < lineCount; i++) {
1254
		int /*long*/ linePtr = OS.pango_layout_get_line(layout, i);
1254
		int /*long*/ linePtr = OS.pango_layout_get_line(layout, i);
1255
		OS.memmove(line, linePtr, PangoLayoutLine.sizeof);
1255
		OS.memmove(line, linePtr, PangoLayoutLine.sizeof);
1256
		int pos = (int)/*64*/OS.g_utf8_pointer_to_offset(ptr, ptr + line.start_index);
1256
		int pos = (int)/*64*/OS.g_utf16_pointer_to_offset(ptr, ptr + line.start_index);
1257
		offsets[i] = untranslateOffset(pos);
1257
		offsets[i] = untranslateOffset(pos);
1258
	}
1258
	}
1259
	offsets[lineCount] = text.length();
1259
	offsets[lineCount] = text.length();
Lines 1283-1289 Link Here
1283
	if (!(0 <= offset && offset <= length)) SWT.error(SWT.ERROR_INVALID_RANGE);
1283
	if (!(0 <= offset && offset <= length)) SWT.error(SWT.ERROR_INVALID_RANGE);
1284
	offset = translateOffset(offset);
1284
	offset = translateOffset(offset);
1285
	int /*long*/ ptr = OS.pango_layout_get_text(layout);
1285
	int /*long*/ ptr = OS.pango_layout_get_text(layout);
1286
	int byteOffset = (int)/*64*/(OS.g_utf8_offset_to_pointer(ptr, offset) - ptr);
1286
	int byteOffset = (int)/*64*/(OS.g_utf16_offset_to_pointer(ptr, offset) - ptr);
1287
	int strlen = OS.strlen(ptr);
1287
	int strlen = OS.strlen(ptr);
1288
	byteOffset = Math.min(byteOffset, strlen);
1288
	byteOffset = Math.min(byteOffset, strlen);
1289
	PangoRectangle pos = new PangoRectangle();
1289
	PangoRectangle pos = new PangoRectangle();
Lines 1337-1368 Link Here
1337
	int[] nAttrs = new int[1];
1337
	int[] nAttrs = new int[1];
1338
	OS.pango_layout_get_log_attrs(layout, attrs, nAttrs);
1338
	OS.pango_layout_get_log_attrs(layout, attrs, nAttrs);
1339
	if (attrs[0] == 0) return offset + step;
1339
	if (attrs[0] == 0) return offset + step;
1340
	length = (int)/*64*/OS.g_utf8_strlen(OS.pango_layout_get_text(layout), -1);
1340
	
1341
	offset += step;
1341
	int /*long*/ ptr = OS.pango_layout_get_text(layout);
1342
	int internalOffset = translateOffset(offset);
1342
	int utf8Offset = (int)/*64*/OS.g_utf16_offset_to_utf8_offset (ptr, translateOffset(offset));
1343
	int utf8Length = (int)/*64*/OS.g_utf8_strlen(ptr, -1);
1344
	utf8Offset += step;
1343
	PangoLogAttr logAttr = new PangoLogAttr();
1345
	PangoLogAttr logAttr = new PangoLogAttr();
1344
	while (0 < internalOffset && internalOffset < length) {
1346
	while (0 <= utf8Offset && utf8Offset <= utf8Length) {
1345
		OS.memmove(logAttr, attrs[0] + internalOffset * PangoLogAttr.sizeof, PangoLogAttr.sizeof);
1347
		OS.memmove(logAttr, attrs[0] + utf8Offset * PangoLogAttr.sizeof, PangoLogAttr.sizeof);
1346
		if (((movement & SWT.MOVEMENT_CLUSTER) != 0) && logAttr.is_cursor_position) break; 
1348
		boolean found = false;
1349
		if (((movement & SWT.MOVEMENT_CLUSTER) != 0) && logAttr.is_cursor_position) found = true; 
1347
		if ((movement & SWT.MOVEMENT_WORD) != 0) {
1350
		if ((movement & SWT.MOVEMENT_WORD) != 0) {
1348
			if (forward) {
1351
			if (forward) {
1349
				if (logAttr.is_word_end) break;
1352
				if (logAttr.is_word_end) found = true;
1350
			} else {
1353
			} else {
1351
				if (logAttr.is_word_start) break;
1354
				if (logAttr.is_word_start) found = true;
1352
			}
1355
			}
1353
		}
1356
		}
1354
		if ((movement & SWT.MOVEMENT_WORD_START) != 0) {
1357
		if ((movement & SWT.MOVEMENT_WORD_START) != 0) {
1355
			if (logAttr.is_word_start) break;
1358
			if (logAttr.is_word_start) found = true;
1356
			if (logAttr.is_sentence_end) break;
1359
			if (logAttr.is_sentence_end) found = true;
1357
		}
1360
		}
1358
		if ((movement & SWT.MOVEMENT_WORD_END) != 0) {
1361
		if ((movement & SWT.MOVEMENT_WORD_END) != 0) {
1359
			if (logAttr.is_word_end) break;
1362
			if (logAttr.is_word_end) found = true;
1363
		}
1364
		if (found) {
1365
			int testOffset = (int)/*64*/OS.g_utf8_offset_to_utf16_offset (ptr, utf8Offset); 
1366
			if (invalidOffsets != null) {
1367
				for (int i = 0; i < invalidOffsets.length; i++) {
1368
					if (testOffset == invalidOffsets[i]) {
1369
						found = false;
1370
						break;
1371
					}
1372
				}
1373
			}
1374
			if (found) {
1375
				offset = untranslateOffset(testOffset);
1376
				break;
1377
			}
1360
		}
1378
		}
1361
		offset += step;
1379
		utf8Offset += step;
1362
		internalOffset = translateOffset(offset);
1363
	}
1380
	}
1364
	OS.g_free(attrs[0]);
1381
	OS.g_free(attrs[0]);
1365
	return Math.min(Math.max(0, offset), text.length());
1382
	return Math.min(Math.max(0, offset), length);
1366
}
1383
}
1367
1384
1368
/**
1385
/**
Lines 1454-1460 Link Here
1454
	int[] piTrailing = new int[1];
1471
	int[] piTrailing = new int[1];
1455
	OS.pango_layout_xy_to_index(layout, x * OS.PANGO_SCALE, y * OS.PANGO_SCALE, index, piTrailing);
1472
	OS.pango_layout_xy_to_index(layout, x * OS.PANGO_SCALE, y * OS.PANGO_SCALE, index, piTrailing);
1456
	int /*long*/ ptr = OS.pango_layout_get_text(layout);
1473
	int /*long*/ ptr = OS.pango_layout_get_text(layout);
1457
	int offset = (int)/*64*/OS.g_utf8_pointer_to_offset(ptr, ptr + index[0]);
1474
	int offset = (int)/*64*/OS.g_utf16_pointer_to_offset(ptr, ptr + index[0]);
1458
	if (trailing != null) trailing[0] = piTrailing[0];
1475
	if (trailing != null) trailing[0] = piTrailing[0];
1459
	return untranslateOffset(offset);
1476
	return untranslateOffset(offset);
1460
}
1477
}
(-)Eclipse SWT/gtk/org/eclipse/swt/widgets/Combo.java (-13 / +23 lines)
Lines 816-823 Link Here
816
		OS.pango_layout_xy_to_index (layout, x * OS.PANGO_SCALE, y * OS.PANGO_SCALE, index, trailing);
816
		OS.pango_layout_xy_to_index (layout, x * OS.PANGO_SCALE, y * OS.PANGO_SCALE, index, trailing);
817
		int /*long*/ ptr = OS.pango_layout_get_text (layout);
817
		int /*long*/ ptr = OS.pango_layout_get_text (layout);
818
		int position = (int)/*64*/OS.g_utf8_pointer_to_offset (ptr, ptr + index[0]) + trailing[0];
818
		int position = (int)/*64*/OS.g_utf8_pointer_to_offset (ptr, ptr + index[0]) + trailing[0];
819
		Point selection = getSelection ();
819
		int [] start = new int [1];
820
		if (selection.x <= position && position < selection.y) {
820
		int [] end = new int [1];
821
		OS.gtk_editable_get_selection_bounds (entryHandle, start, end);
822
		if (start [0] <= position && position < end [0]) {
821
			if (super.dragDetect (x, y, filter, consume)) {
823
			if (super.dragDetect (x, y, filter, consume)) {
822
				if (consume != null) consume [0] = true;
824
				if (consume != null) consume [0] = true;
823
				return true;
825
				return true;
Lines 997-1003 Link Here
997
			if (index != -1) length = getItem (index).length ();
999
			if (index != -1) length = getItem (index).length ();
998
		} else {
1000
		} else {
999
			int /*long*/ str = OS.gtk_entry_get_text (entryHandle);
1001
			int /*long*/ str = OS.gtk_entry_get_text (entryHandle);
1000
			if (str != 0) length = (int)/*64*/OS.g_utf8_strlen (str, -1);
1002
			if (str != 0) length = (int)/*64*/OS.g_utf16_strlen (str, -1);
1001
		}
1003
		}
1002
		return new Point (0, length);
1004
		return new Point (0, length);
1003
	}
1005
	}
Lines 1005-1010 Link Here
1005
	int [] end = new int [1];
1007
	int [] end = new int [1];
1006
	if (entryHandle != 0) {
1008
	if (entryHandle != 0) {
1007
		OS.gtk_editable_get_selection_bounds (entryHandle, start, end);
1009
		OS.gtk_editable_get_selection_bounds (entryHandle, start, end);
1010
		int /*long*/ ptr = OS.gtk_entry_get_text (entryHandle);
1011
		start[0] = (int)/*64*/OS.g_utf8_offset_to_utf16_offset (ptr, start[0]);
1012
		end[0] = (int)/*64*/OS.g_utf8_offset_to_utf16_offset (ptr, end[0]);
1008
	}
1013
	}
1009
	return new Point(start [0], end [0]);
1014
	return new Point(start [0], end [0]);
1010
}
1015
}
Lines 1268-1275 Link Here
1268
		return 0;
1273
		return 0;
1269
	}
1274
	}
1270
	if (!hooks (SWT.Verify) && !filters (SWT.Verify)) return 0;
1275
	if (!hooks (SWT.Verify) && !filters (SWT.Verify)) return 0;
1271
	if (end_pos == -1) end_pos = OS.g_utf8_strlen (OS.gtk_entry_get_text (entryHandle), -1);
1276
	int /*long*/ ptr = OS.gtk_entry_get_text (entryHandle);
1272
	String newText = verifyText ("", (int)/*64*/start_pos, (int)/*64*/end_pos);
1277
	if (end_pos == -1) end_pos = OS.g_utf8_strlen (ptr, -1);
1278
	int start = (int)/*64*/OS.g_utf8_offset_to_utf16_offset (ptr, start_pos);
1279
	int end = (int)/*64*/OS.g_utf8_offset_to_utf16_offset (ptr, end_pos);
1280
	String newText = verifyText ("", start, end);
1273
	if (newText == null) {
1281
	if (newText == null) {
1274
		OS.g_signal_stop_emission_by_name (entryHandle, OS.delete_text);
1282
		OS.g_signal_stop_emission_by_name (entryHandle, OS.delete_text);
1275
	} else {
1283
	} else {
Lines 1371-1381 Link Here
1371
	String oldText = new String (Converter.mbcsToWcs (null, buffer));
1379
	String oldText = new String (Converter.mbcsToWcs (null, buffer));
1372
	int [] pos = new int [1];
1380
	int [] pos = new int [1];
1373
	OS.memmove (pos, position, 4);
1381
	OS.memmove (pos, position, 4);
1374
	if (pos [0] == -1) {
1382
	int /*long*/ ptr = OS.gtk_entry_get_text (entryHandle);
1375
		int /*long*/ ptr = OS.gtk_entry_get_text (entryHandle);
1383
	if (pos [0] == -1) pos [0] = (int)/*64*/OS.g_utf8_strlen (ptr, -1);
1376
		pos [0] = (int)/*64*/OS.g_utf8_strlen (ptr, -1);
1384
	int start = (int)/*64*/OS.g_utf8_offset_to_utf16_offset (ptr, pos [0]);
1377
	}
1385
	String newText = verifyText (oldText, start, start);
1378
	String newText = verifyText (oldText, pos [0], pos [0]);
1379
	if (newText != oldText) {
1386
	if (newText != oldText) {
1380
		int [] newStart = new int [1], newEnd = new int [1];
1387
		int [] newStart = new int [1], newEnd = new int [1];
1381
		OS.gtk_editable_get_selection_bounds (entryHandle, newStart, newEnd);
1388
		OS.gtk_editable_get_selection_bounds (entryHandle, newStart, newEnd);
Lines 2113-2120 Link Here
2113
	if (selection == null) error (SWT.ERROR_NULL_ARGUMENT);
2120
	if (selection == null) error (SWT.ERROR_NULL_ARGUMENT);
2114
	if ((style & SWT.READ_ONLY) != 0) return;
2121
	if ((style & SWT.READ_ONLY) != 0) return;
2115
	if (entryHandle != 0) {
2122
	if (entryHandle != 0) {
2116
		OS.gtk_editable_set_position (entryHandle, selection.x);
2123
		int /*long*/ ptr = OS.gtk_entry_get_text (entryHandle);
2117
		OS.gtk_editable_select_region (entryHandle, selection.x, selection.y);
2124
		int start = (int)/*64*/OS.g_utf16_offset_to_utf8_offset (ptr, selection.x);
2125
		int end = (int)/*64*/OS.g_utf16_offset_to_utf8_offset (ptr, selection.y);
2126
		OS.gtk_editable_set_position (entryHandle, start);
2127
		OS.gtk_editable_select_region (entryHandle, start, end);
2118
	}
2128
	}
2119
}
2129
}
2120
2130
Lines 2169-2175 Link Here
2169
	*/
2179
	*/
2170
	if (hooks (SWT.Verify) || filters (SWT.Verify)) {
2180
	if (hooks (SWT.Verify) || filters (SWT.Verify)) {
2171
		int /*long*/ ptr = OS.gtk_entry_get_text (entryHandle);
2181
		int /*long*/ ptr = OS.gtk_entry_get_text (entryHandle);
2172
		string = verifyText (string, 0, (int)/*64*/OS.g_utf8_strlen (ptr, -1));
2182
		string = verifyText (string, 0, (int)/*64*/OS.g_utf16_strlen (ptr, -1));
2173
		if (string == null) return;
2183
		if (string == null) return;
2174
	}
2184
	}
2175
	byte [] buffer = Converter.wcsToMbcs (null, string, true);
2185
	byte [] buffer = Converter.wcsToMbcs (null, string, true);
(-)Eclipse SWT/gtk/org/eclipse/swt/widgets/IME.java (-2 / +2 lines)
Lines 309-316 Link Here
309
			int [] end = new int [1];
309
			int [] end = new int [1];
310
			for (int i = 0; i < count; i++) {
310
			for (int i = 0; i < count; i++) {
311
				OS.pango_attr_iterator_range (iterator, start, end);
311
				OS.pango_attr_iterator_range (iterator, start, end);
312
				ranges [i * 2] = (int)/*64*/OS.g_utf8_pointer_to_offset (preeditString [0], preeditString [0] + start [0]);
312
				ranges [i * 2] = (int)/*64*/OS.g_utf16_pointer_to_offset (preeditString [0], preeditString [0] + start [0]);
313
				ranges [i * 2 + 1] = (int)/*64*/OS.g_utf8_pointer_to_offset (preeditString [0], preeditString [0] + end [0]) - 1;
313
				ranges [i * 2 + 1] = (int)/*64*/OS.g_utf16_pointer_to_offset (preeditString [0], preeditString [0] + end [0]) - 1;
314
				styles [i] = new TextStyle (null, null, null);
314
				styles [i] = new TextStyle (null, null, null);
315
				int /*long*/ attr = OS.pango_attr_iterator_get (iterator, OS.PANGO_ATTR_FOREGROUND);
315
				int /*long*/ attr = OS.pango_attr_iterator_get (iterator, OS.PANGO_ATTR_FOREGROUND);
316
				if (attr != 0) {
316
				if (attr != 0) {
(-)Eclipse SWT/gtk/org/eclipse/swt/widgets/Spinner.java (-7 / +9 lines)
Lines 647-654 Link Here
647
647
648
int /*long*/ gtk_delete_text (int /*long*/ widget, int /*long*/ start_pos, int /*long*/ end_pos) {
648
int /*long*/ gtk_delete_text (int /*long*/ widget, int /*long*/ start_pos, int /*long*/ end_pos) {
649
	if (!hooks (SWT.Verify) && !filters (SWT.Verify)) return 0;
649
	if (!hooks (SWT.Verify) && !filters (SWT.Verify)) return 0;
650
	if (end_pos == -1) end_pos = OS.g_utf8_strlen (OS.gtk_entry_get_text (handle), -1);
650
	int /*long*/ ptr = OS.gtk_entry_get_text (handle);
651
	String newText = verifyText ("", (int)/*64*/start_pos, (int)/*64*/end_pos);
651
	if (end_pos == -1) end_pos = OS.g_utf8_strlen (ptr, -1);
652
	int start = (int)/*64*/OS.g_utf8_offset_to_utf16_offset (ptr, start_pos);
653
	int end = (int)/*64*/OS.g_utf8_offset_to_utf16_offset (ptr, end_pos);
654
	String newText = verifyText ("", start, end);
652
	if (newText == null) {
655
	if (newText == null) {
653
		OS.g_signal_stop_emission_by_name (handle, OS.delete_text);
656
		OS.g_signal_stop_emission_by_name (handle, OS.delete_text);
654
	} else {
657
	} else {
Lines 685-695 Link Here
685
	String oldText = new String (Converter.mbcsToWcs (null, buffer));
688
	String oldText = new String (Converter.mbcsToWcs (null, buffer));
686
	int [] pos = new int [1];
689
	int [] pos = new int [1];
687
	OS.memmove (pos, position, 4);
690
	OS.memmove (pos, position, 4);
688
	if (pos [0] == -1) {
691
	int /*long*/ ptr = OS.gtk_entry_get_text (handle);
689
		int /*long*/ ptr = OS.gtk_entry_get_text (handle);
692
	if (pos [0] == -1) pos [0] = (int)/*64*/OS.g_utf8_strlen (ptr, -1);
690
		pos [0] = (int)/*64*/OS.g_utf8_strlen (ptr, -1);
693
	int start = (int)/*64*/OS.g_utf16_pointer_to_offset (ptr, pos [0]);
691
	}
694
	String newText = verifyText (oldText, start, start);
692
	String newText = verifyText (oldText, pos [0], pos [0]);
693
	if (newText != oldText) {
695
	if (newText != oldText) {
694
		int [] newStart = new int [1], newEnd = new int [1];
696
		int [] newStart = new int [1], newEnd = new int [1];
695
		OS.gtk_editable_get_selection_bounds (handle, newStart, newEnd);
697
		OS.gtk_editable_get_selection_bounds (handle, newStart, newEnd);
(-)Eclipse SWT/gtk/org/eclipse/swt/widgets/Text.java (-42 / +87 lines)
Lines 670-681 Link Here
670
public int getCaretPosition () {
670
public int getCaretPosition () {
671
	checkWidget ();
671
	checkWidget ();
672
	if ((style & SWT.SINGLE) != 0)  {
672
	if ((style & SWT.SINGLE) != 0)  {
673
		return OS.gtk_editable_get_position (handle);
673
		int /*long*/ ptr = OS.gtk_entry_get_text (handle);
674
		return (int)/*64*/OS.g_utf8_offset_to_utf16_offset (ptr, OS.gtk_editable_get_position (handle));
674
	}
675
	}
675
	byte [] position = new byte [ITER_SIZEOF];
676
	byte [] position = new byte [ITER_SIZEOF];
676
	int /*long*/ mark = OS.gtk_text_buffer_get_insert (bufferHandle);
677
	int /*long*/ mark = OS.gtk_text_buffer_get_insert (bufferHandle);
677
	OS.gtk_text_buffer_get_iter_at_mark (bufferHandle, position, mark);
678
	OS.gtk_text_buffer_get_iter_at_mark (bufferHandle, position, mark);
678
	return OS.gtk_text_iter_get_offset (position);
679
	byte [] zero = new byte [ITER_SIZEOF];
680
	OS.gtk_text_buffer_get_iter_at_offset(bufferHandle, zero, 0);
681
	int /*long*/ ptr = OS.gtk_text_buffer_get_text (bufferHandle, zero, position, true);
682
	int result = (int)/*64*/OS.g_utf8_offset_to_utf16_offset (ptr, OS.gtk_text_iter_get_offset (position));
683
	OS.g_free (ptr);
684
	return result;
679
}
685
}
680
686
681
/**
687
/**
Lines 692-700 Link Here
692
	checkWidget ();
698
	checkWidget ();
693
	if ((style & SWT.SINGLE) != 0) {
699
	if ((style & SWT.SINGLE) != 0) {
694
		int /*long*/ ptr = OS.gtk_entry_get_text (handle);
700
		int /*long*/ ptr = OS.gtk_entry_get_text (handle);
695
		return (int)/*64*/OS.g_utf8_strlen (ptr, -1);
701
		return (int)/*64*/OS.g_utf16_strlen (ptr, -1);
696
	}
702
	}
697
	return OS.gtk_text_buffer_get_char_count (bufferHandle);
703
	byte [] startIter =  new byte [ITER_SIZEOF];
704
	byte [] endIter =  new byte [ITER_SIZEOF];
705
	OS.gtk_text_buffer_get_bounds (bufferHandle, startIter, endIter);
706
	int /*long*/ ptr = OS.gtk_text_buffer_get_text (bufferHandle, startIter, endIter, true);
707
	int result = (int)/*64*/OS.g_utf16_strlen(ptr, -1);
708
	OS.g_free (ptr);
709
	return result;
698
}
710
}
699
711
700
/**
712
/**
Lines 862-872 Link Here
862
		int /*long*/ layout = OS.gtk_entry_get_layout (handle);
874
		int /*long*/ layout = OS.gtk_entry_get_layout (handle);
863
		OS.pango_layout_xy_to_index (layout, point.x * OS.PANGO_SCALE, point.y * OS.PANGO_SCALE, index, trailing);
875
		OS.pango_layout_xy_to_index (layout, point.x * OS.PANGO_SCALE, point.y * OS.PANGO_SCALE, index, trailing);
864
		int /*long*/ ptr = OS.pango_layout_get_text (layout);
876
		int /*long*/ ptr = OS.pango_layout_get_text (layout);
865
		position = (int)/*64*/OS.g_utf8_pointer_to_offset (ptr, ptr + index[0]) + trailing[0];
877
		position = (int)/*64*/OS.g_utf16_pointer_to_offset (ptr, ptr + index[0]) + trailing[0];
866
	} else {
878
	} else {
867
		byte [] p = new byte [ITER_SIZEOF];
879
		byte [] p = new byte [ITER_SIZEOF];
868
		OS.gtk_text_view_get_iter_at_location (handle, p, point.x, point.y);
880
		OS.gtk_text_view_get_iter_at_location (handle, p, point.x, point.y);
869
		position = OS.gtk_text_iter_get_offset (p);
881
		byte [] zero = new byte [ITER_SIZEOF];
882
		OS.gtk_text_buffer_get_iter_at_offset(bufferHandle, zero, 0);
883
		int /*long*/ ptr = OS.gtk_text_buffer_get_text (bufferHandle, zero, p, true);
884
		position = (int)/*64*/OS.g_utf8_offset_to_utf16_offset (ptr, OS.gtk_text_iter_get_offset (p));
885
		OS.g_free (ptr);
870
	}
886
	}
871
	return position;
887
	return position;
872
}
888
}
Lines 895-906 Link Here
895
		int [] start = new int [1];
911
		int [] start = new int [1];
896
		int [] end = new int [1];
912
		int [] end = new int [1];
897
		OS.gtk_editable_get_selection_bounds (handle, start, end);
913
		OS.gtk_editable_get_selection_bounds (handle, start, end);
914
		int /*long*/ ptr = OS.gtk_entry_get_text (handle);
915
		start[0] = (int)/*64*/OS.g_utf8_offset_to_utf16_offset (ptr, start[0]);
916
		end[0] = (int)/*64*/OS.g_utf8_offset_to_utf16_offset (ptr, end[0]);
898
		return new Point (start [0], end [0]);
917
		return new Point (start [0], end [0]);
899
	}
918
	}
900
	byte [] start =  new byte [ITER_SIZEOF];
919
	byte [] startIter =  new byte [ITER_SIZEOF];
901
	byte [] end =  new byte [ITER_SIZEOF];
920
	byte [] endIter =  new byte [ITER_SIZEOF];
902
	OS.gtk_text_buffer_get_selection_bounds (bufferHandle, start, end);
921
	OS.gtk_text_buffer_get_selection_bounds (bufferHandle, startIter, endIter);
903
	return new Point (OS.gtk_text_iter_get_offset (start), OS.gtk_text_iter_get_offset (end));
922
	byte [] zero = new byte [ITER_SIZEOF];
923
	OS.gtk_text_buffer_get_iter_at_offset(bufferHandle, zero, 0);
924
	int /*long*/ ptr = OS.gtk_text_buffer_get_text (bufferHandle, zero, endIter, true);
925
	int start = (int)/*64*/OS.g_utf8_offset_to_utf16_offset (ptr, OS.gtk_text_iter_get_offset (startIter));
926
	int end = (int)/*64*/OS.g_utf8_offset_to_utf16_offset (ptr, OS.gtk_text_iter_get_offset (endIter));
927
	OS.g_free (ptr);
928
	return new Point (start, end);
904
}
929
}
905
930
906
/**
931
/**
Lines 1004-1030 Link Here
1004
public String getText (int start, int end) {
1029
public String getText (int start, int end) {
1005
	checkWidget ();
1030
	checkWidget ();
1006
	if (!(start <= end && 0 <= end)) return "";
1031
	if (!(start <= end && 0 <= end)) return "";
1007
	int /*long*/ address;
1032
	String str = getText ();
1008
	if ((style & SWT.SINGLE) != 0) {
1033
	int length = str.length ();
1009
		start = Math.max (0, start);
1034
	end = Math.min (end, length - 1);
1010
		address = OS.gtk_editable_get_chars (handle, start, end + 1);
1035
	if (start > end) return "";
1011
	} else {
1036
	start = Math.max (0, start);
1012
		int length = OS.gtk_text_buffer_get_char_count (bufferHandle);
1037
	/*
1013
		end = Math.min (end, length - 1);
1038
	* NOTE: The current implementation uses substring ()
1014
		if (start > end) return "";
1039
	* which can reference a potentially large character
1015
		start = Math.max (0, start);
1040
	* array.
1016
		byte [] startIter =  new byte [ITER_SIZEOF];
1041
	*/
1017
		byte [] endIter =  new byte [ITER_SIZEOF];
1042
	return str.substring (start, end + 1);
1018
		OS.gtk_text_buffer_get_iter_at_offset (bufferHandle, startIter, start);
1019
		OS.gtk_text_buffer_get_iter_at_offset (bufferHandle, endIter, end + 1);
1020
		address = OS.gtk_text_buffer_get_text (bufferHandle, startIter, endIter, true);
1021
	}
1022
	if (address == 0) error (SWT.ERROR_CANNOT_GET_TEXT);
1023
	int length = OS.strlen (address);
1024
	byte [] buffer = new byte [length];
1025
	OS.memmove (buffer, address, length);
1026
	OS.g_free (address);
1027
	return new String (Converter.mbcsToWcs (null, buffer));
1028
}
1043
}
1029
1044
1030
/**
1045
/**
Lines 1188-1194 Link Here
1188
	if ((style & SWT.SEARCH) != 0) {
1203
	if ((style & SWT.SEARCH) != 0) {
1189
		if ((style & SWT.ICON_CANCEL) != 0) {
1204
		if ((style & SWT.ICON_CANCEL) != 0) {
1190
			int /*long*/ ptr = OS.gtk_entry_get_text (handle);
1205
			int /*long*/ ptr = OS.gtk_entry_get_text (handle);
1191
			OS.gtk_entry_set_icon_sensitive (handle, OS.GTK_ENTRY_ICON_SECONDARY, OS.g_utf8_strlen (ptr, -1) > 0);
1206
			OS.gtk_entry_set_icon_sensitive (handle, OS.GTK_ENTRY_ICON_SECONDARY, OS.g_utf16_strlen (ptr, -1) > 0);
1192
		}
1207
		}
1193
	}
1208
	}
1194
	return 0;
1209
	return 0;
Lines 1244-1249 Link Here
1244
	OS.memmove (endIter, iter2, endIter.length);
1259
	OS.memmove (endIter, iter2, endIter.length);
1245
	int start = OS.gtk_text_iter_get_offset (startIter);
1260
	int start = OS.gtk_text_iter_get_offset (startIter);
1246
	int end = OS.gtk_text_iter_get_offset (endIter);
1261
	int end = OS.gtk_text_iter_get_offset (endIter);
1262
	byte [] zero = new byte [ITER_SIZEOF];
1263
	OS.gtk_text_buffer_get_iter_at_offset(bufferHandle, zero, 0);
1264
	int /*long*/ ptr = OS.gtk_text_buffer_get_text (bufferHandle, zero, endIter, true);
1265
	start = (int)/*64*/OS.g_utf8_offset_to_utf16_offset (ptr, start);
1266
	end = (int)/*64*/OS.g_utf8_offset_to_utf16_offset (ptr, end);
1267
	OS.g_free (ptr);
1247
	String newText = verifyText ("", start, end);
1268
	String newText = verifyText ("", start, end);
1248
	if (newText == null) {
1269
	if (newText == null) {
1249
		/* Remember the selection when the text was deleted */
1270
		/* Remember the selection when the text was deleted */
Lines 1274-1281 Link Here
1274
1295
1275
int /*long*/ gtk_delete_text (int /*long*/ widget, int /*long*/ start_pos, int /*long*/ end_pos) {
1296
int /*long*/ gtk_delete_text (int /*long*/ widget, int /*long*/ start_pos, int /*long*/ end_pos) {
1276
	if (!hooks (SWT.Verify) && !filters (SWT.Verify)) return 0;
1297
	if (!hooks (SWT.Verify) && !filters (SWT.Verify)) return 0;
1277
	if (end_pos == -1) end_pos = OS.g_utf8_strlen (OS.gtk_entry_get_text (handle), -1);
1298
	int /*long*/ ptr = OS.gtk_entry_get_text (handle);
1278
	String newText = verifyText ("", (int)/*64*/start_pos, (int)/*64*/end_pos);
1299
	if (end_pos == -1) end_pos = OS.g_utf8_strlen (ptr, -1);
1300
	int start = (int)/*64*/OS.g_utf8_offset_to_utf16_offset (ptr, start_pos);
1301
	int end = (int)/*64*/OS.g_utf8_offset_to_utf16_offset (ptr, end_pos);
1302
	String newText = verifyText ("", start, end);
1279
	if (newText == null) {
1303
	if (newText == null) {
1280
		/* Remember the selection when the text was deleted */
1304
		/* Remember the selection when the text was deleted */
1281
		int [] newStart = new int [1], newEnd = new int [1];
1305
		int [] newStart = new int [1], newEnd = new int [1];
Lines 1426-1435 Link Here
1426
	String oldText = new String (Converter.mbcsToWcs (null, buffer));
1450
	String oldText = new String (Converter.mbcsToWcs (null, buffer));
1427
	int [] pos = new int [1];
1451
	int [] pos = new int [1];
1428
	OS.memmove (pos, position, 4);
1452
	OS.memmove (pos, position, 4);
1429
	if (pos [0] == -1) {
1453
	int /*long*/ ptr = OS.gtk_entry_get_text (handle);
1430
		int /*long*/ ptr = OS.gtk_entry_get_text (handle);
1454
	if (pos [0] == -1) pos [0] = (int)/*64*/OS.g_utf8_strlen (ptr, -1);
1431
		pos [0] = (int)/*64*/OS.g_utf8_strlen (ptr, -1);
1432
	}
1433
	/* Use the selection when the text was deleted */
1455
	/* Use the selection when the text was deleted */
1434
	int start = pos [0], end = pos [0];
1456
	int start = pos [0], end = pos [0];
1435
	if (fixStart != -1 && fixEnd != -1) {
1457
	if (fixStart != -1 && fixEnd != -1) {
Lines 1437-1442 Link Here
1437
		end = fixEnd;
1459
		end = fixEnd;
1438
		fixStart = fixEnd = -1;
1460
		fixStart = fixEnd = -1;
1439
	}
1461
	}
1462
	start = (int)/*64*/OS.g_utf8_offset_to_utf16_offset (ptr, start);
1463
	end = (int)/*64*/OS.g_utf8_offset_to_utf16_offset (ptr, end);
1440
	String newText = verifyText (oldText, start, end);
1464
	String newText = verifyText (oldText, start, end);
1441
	if (newText != oldText) {
1465
	if (newText != oldText) {
1442
		int [] newStart = new int [1], newEnd = new int [1];
1466
		int [] newStart = new int [1], newEnd = new int [1];
Lines 1493-1498 Link Here
1493
		end = fixEnd;
1517
		end = fixEnd;
1494
		fixStart = fixEnd = -1;
1518
		fixStart = fixEnd = -1;
1495
	}
1519
	}
1520
	byte [] zero = new byte [ITER_SIZEOF];
1521
	OS.gtk_text_buffer_get_iter_at_offset(bufferHandle, zero, 0);
1522
	int /*long*/ ptr = OS.gtk_text_buffer_get_text (bufferHandle, zero, position, true);
1523
	start = (int)/*64*/OS.g_utf8_offset_to_utf16_offset (ptr, start);
1524
	end = (int)/*64*/OS.g_utf8_offset_to_utf16_offset (ptr, end);
1525
	OS.g_free(ptr);
1496
	byte [] buffer = new byte [(int)/*64*/length];
1526
	byte [] buffer = new byte [(int)/*64*/length];
1497
	OS.memmove (buffer, text, buffer.length);
1527
	OS.memmove (buffer, text, buffer.length);
1498
	String oldText = new String (Converter.mbcsToWcs (null, buffer));
1528
	String oldText = new String (Converter.mbcsToWcs (null, buffer));
Lines 1913-1923 Link Here
1913
public void setSelection (int start) {
1943
public void setSelection (int start) {
1914
	checkWidget ();
1944
	checkWidget ();
1915
	if ((style & SWT.SINGLE) != 0) {
1945
	if ((style & SWT.SINGLE) != 0) {
1946
		int /*long*/ ptr = OS.gtk_entry_get_text (handle);
1947
		start = (int)/*64*/OS.g_utf16_offset_to_utf8_offset (ptr, start);
1916
		OS.gtk_editable_set_position (handle, start);
1948
		OS.gtk_editable_set_position (handle, start);
1917
	} else {
1949
	} else {
1918
		byte [] position =  new byte [ITER_SIZEOF];
1950
		byte [] startIter =  new byte [ITER_SIZEOF];
1919
		OS.gtk_text_buffer_get_iter_at_offset (bufferHandle, position, start);
1951
		byte [] endIter =  new byte [ITER_SIZEOF];
1920
		OS.gtk_text_buffer_place_cursor (bufferHandle, position);
1952
		OS.gtk_text_buffer_get_bounds (bufferHandle, startIter, endIter);
1953
		int /*long*/ ptr = OS.gtk_text_buffer_get_text (bufferHandle, startIter, endIter, true);
1954
		start = (int)/*64*/OS.g_utf16_offset_to_utf8_offset (ptr, start);
1955
		OS.g_free (ptr);
1956
		OS.gtk_text_buffer_get_iter_at_offset (bufferHandle, startIter, start);
1957
		OS.gtk_text_buffer_place_cursor (bufferHandle, startIter);
1921
		int /*long*/ mark = OS.gtk_text_buffer_get_insert (bufferHandle);
1958
		int /*long*/ mark = OS.gtk_text_buffer_get_insert (bufferHandle);
1922
		OS.gtk_text_view_scroll_mark_onscreen (handle, mark);
1959
		OS.gtk_text_view_scroll_mark_onscreen (handle, mark);
1923
	}
1960
	}
Lines 1950-1961 Link Here
1950
 */
1987
 */
1951
public void setSelection (int start, int end) {
1988
public void setSelection (int start, int end) {
1952
	checkWidget ();
1989
	checkWidget ();
1953
	if ((style & SWT.SINGLE) != 0) { 
1990
	if ((style & SWT.SINGLE) != 0) {
1991
		int /*long*/ ptr = OS.gtk_entry_get_text (handle);
1992
		start = (int)/*64*/OS.g_utf16_offset_to_utf8_offset (ptr, start);
1993
		end = (int)/*64*/OS.g_utf16_offset_to_utf8_offset (ptr, end);
1954
		OS.gtk_editable_set_position (handle, start);
1994
		OS.gtk_editable_set_position (handle, start);
1955
		OS.gtk_editable_select_region (handle, start, end);
1995
		OS.gtk_editable_select_region (handle, start, end);
1956
	} else {
1996
	} else {
1957
		byte [] startIter =  new byte [ITER_SIZEOF];
1997
		byte [] startIter =  new byte [ITER_SIZEOF];
1958
		byte [] endIter =  new byte [ITER_SIZEOF];
1998
		byte [] endIter =  new byte [ITER_SIZEOF];
1999
		OS.gtk_text_buffer_get_bounds (bufferHandle, startIter, endIter);
2000
		int /*long*/ ptr = OS.gtk_text_buffer_get_text (bufferHandle, startIter, endIter, true);
2001
		start = (int)/*64*/OS.g_utf16_offset_to_utf8_offset (ptr, start);
2002
		end = (int)/*64*/OS.g_utf16_offset_to_utf8_offset (ptr, end);
2003
		OS.g_free (ptr);
1959
		OS.gtk_text_buffer_get_iter_at_offset (bufferHandle, startIter, start);
2004
		OS.gtk_text_buffer_get_iter_at_offset (bufferHandle, startIter, start);
1960
		OS.gtk_text_buffer_get_iter_at_offset (bufferHandle, endIter, end);
2005
		OS.gtk_text_buffer_get_iter_at_offset (bufferHandle, endIter, end);
1961
		int /*long*/ insertMark = OS.gtk_text_buffer_get_insert (bufferHandle);
2006
		int /*long*/ insertMark = OS.gtk_text_buffer_get_insert (bufferHandle);
(-)Eclipse SWT/gtk/org/eclipse/swt/widgets/Widget.java (-2 / +2 lines)
Lines 1287-1293 Link Here
1287
1287
1288
boolean sendKeyEvent (int type, GdkEventKey keyEvent) {
1288
boolean sendKeyEvent (int type, GdkEventKey keyEvent) {
1289
	int length = keyEvent.length;
1289
	int length = keyEvent.length;
1290
	if (keyEvent.string == 0 || OS.g_utf8_strlen (keyEvent.string, length) <= 1) {
1290
	if (keyEvent.string == 0 || OS.g_utf16_strlen (keyEvent.string, length) <= 1) {
1291
		Event event = new Event ();
1291
		Event event = new Event ();
1292
		event.time = keyEvent.time;
1292
		event.time = keyEvent.time;
1293
		if (!setKeyState (event, keyEvent)) return true;
1293
		if (!setKeyState (event, keyEvent)) return true;
Lines 1550-1556 Link Here
1550
}
1550
}
1551
1551
1552
boolean setKeyState (Event event, GdkEventKey keyEvent) {
1552
boolean setKeyState (Event event, GdkEventKey keyEvent) {
1553
	if (keyEvent.string != 0 && OS.g_utf8_strlen (keyEvent.string, keyEvent.length) > 1) return false;
1553
	if (keyEvent.string != 0 && OS.g_utf16_strlen (keyEvent.string, keyEvent.length) > 1) return false;
1554
	boolean isNull = false;
1554
	boolean isNull = false;
1555
	event.keyCode = Display.translateKey (keyEvent.keyval);
1555
	event.keyCode = Display.translateKey (keyEvent.keyval);
1556
	switch (keyEvent.keyval) {
1556
	switch (keyEvent.keyval) {

Return to bug 65899