|
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); |