From ea91ed098968dcee6c6e0bd028b8f2e2c9870547 Mon Sep 17 00:00:00 2001 From: Olga Rodimina Date: Mon, 1 Dec 2003 20:23:50 +0000 Subject: [PATCH] 2003-12-01 Olga Rodimina * java/awt/TextComponent.java: (getSelectionStart): Updated javadocs. (getSelectionEnd): Ditto. * jni/gtk-peer/gnu_java_awt_peer_gtk_GtkTextComponentPeer: (getSelectionStart): Changed to return caret position if no text is selected (getSelectionEnd): Ditto. From-SVN: r74124 --- libjava/ChangeLog | 10 ++++++++++ libjava/java/awt/TextComponent.java | 4 ++-- ...u_java_awt_peer_gtk_GtkTextComponentPeer.c | 20 +++++++++++++++++++ 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/libjava/ChangeLog b/libjava/ChangeLog index 0b541eb2a21..28c4a204e46 100644 --- a/libjava/ChangeLog +++ b/libjava/ChangeLog @@ -1,3 +1,13 @@ +2003-12-01 Olga Rodimina + + * java/awt/TextComponent.java: + (getSelectionStart): Updated javadocs. + (getSelectionEnd): Ditto. + * jni/gtk-peer/gnu_java_awt_peer_gtk_GtkTextComponentPeer: + (getSelectionStart): Changed to return caret position if no + text is selected + (getSelectionEnd): Ditto. + 2003-12-01 Thomas Fitzsimmons * gnu/awt/gtk/GtkButtonPeer.java, gnu/awt/gtk/gtkcommon.cc, diff --git a/libjava/java/awt/TextComponent.java b/libjava/java/awt/TextComponent.java index cbe7dc9169d..c193b9ef8b3 100644 --- a/libjava/java/awt/TextComponent.java +++ b/libjava/java/awt/TextComponent.java @@ -163,7 +163,7 @@ getSelectedText() /** * Returns the starting position of the selected text region. - * // FIXME: What is returned if there is no selected text? + * If the text is not selected then caret position is returned. * * @return The starting position of the selected text region. */ @@ -196,7 +196,7 @@ setSelectionStart(int selectionStart) /** * Returns the ending position of the selected text region. - * // FIXME: What is returned if there is no selected text. + * If the text is not selected, then caret position is returned * * @return The ending position of the selected text region. */ diff --git a/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkTextComponentPeer.c b/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkTextComponentPeer.c index 95e114ebd10..7e6d02f178a 100644 --- a/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkTextComponentPeer.c +++ b/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkTextComponentPeer.c @@ -194,6 +194,8 @@ Java_gnu_java_awt_peer_gtk_GtkTextComponentPeer_getSelectionStart GtkTextIter start; GtkTextIter end; int starti, endi; + GtkTextMark *mark; + GtkTextIter iter; ptr = NSA_GET_PTR (env, obj); @@ -204,6 +206,8 @@ Java_gnu_java_awt_peer_gtk_GtkTextComponentPeer_getSelectionStart editable = GTK_EDITABLE (ptr); if (gtk_editable_get_selection_bounds (editable, &starti, &endi)) pos = starti; + else + pos = gtk_editable_get_position (editable); } else { @@ -221,6 +225,12 @@ Java_gnu_java_awt_peer_gtk_GtkTextComponentPeer_getSelectionStart buf = gtk_text_view_get_buffer (GTK_TEXT_VIEW (text)); if (gtk_text_buffer_get_selection_bounds(buf, &start, &end)) pos = gtk_text_iter_get_offset (&start); + else + { + mark = gtk_text_buffer_get_insert (buf); + gtk_text_buffer_get_iter_at_mark (buf, &iter, mark); + pos = gtk_text_iter_get_offset (&iter); + } } } @@ -241,6 +251,8 @@ Java_gnu_java_awt_peer_gtk_GtkTextComponentPeer_getSelectionEnd GtkTextIter start; GtkTextIter end; int starti, endi; + GtkTextMark *mark; + GtkTextIter iter; ptr = NSA_GET_PTR (env, obj); @@ -251,6 +263,8 @@ Java_gnu_java_awt_peer_gtk_GtkTextComponentPeer_getSelectionEnd editable = GTK_EDITABLE (ptr); if (gtk_editable_get_selection_bounds (editable, &starti, &endi)) pos = endi; + else + pos = gtk_editable_get_position (editable); } else { @@ -268,6 +282,12 @@ Java_gnu_java_awt_peer_gtk_GtkTextComponentPeer_getSelectionEnd buf = gtk_text_view_get_buffer (GTK_TEXT_VIEW (text)); if (gtk_text_buffer_get_selection_bounds(buf, &start, &end)) pos = gtk_text_iter_get_offset (&end); + else + { + mark = gtk_text_buffer_get_insert (buf); + gtk_text_buffer_get_iter_at_mark (buf, &iter, mark); + pos = gtk_text_iter_get_offset (&iter); + } } }