Return "" for entry->invisible_char == 0, otherwise N copies of
Mon Oct 21 14:04:39 2002 Owen Taylor <otaylor@redhat.com> * gtk/gtkentry.c (gtk_entry_get_public_chars): Return "" for entry->invisible_char == 0, otherwise N copies of entry->invisible_char. (#95486, Vitaly Tishkov) * gtk/gtkentry.c: Fix a bunch of places where entry->text instead of layout->text was being used for computation of offsets/indices in the layout. Using layout->text is necessary because when the entry is invisible, it doesn't correspond to entry->text.
This commit is contained in:
12
ChangeLog
12
ChangeLog
@@ -1,3 +1,15 @@
|
|||||||
|
Mon Oct 21 14:04:39 2002 Owen Taylor <otaylor@redhat.com>
|
||||||
|
|
||||||
|
* gtk/gtkentry.c (gtk_entry_get_public_chars): Return
|
||||||
|
"" for entry->invisible_char == 0, otherwise N copies
|
||||||
|
of entry->invisible_char. (#95486, Vitaly Tishkov)
|
||||||
|
|
||||||
|
* gtk/gtkentry.c: Fix a bunch of places where entry->text
|
||||||
|
instead of layout->text was being used for computation
|
||||||
|
of offsets/indices in the layout. Using layout->text
|
||||||
|
is necessary because when the entry is invisible, it
|
||||||
|
doesn't correspond to entry->text.
|
||||||
|
|
||||||
Sun Oct 20 23:58:03 2002 Soeren Sandmann <sandmann@daimi.au.dk>
|
Sun Oct 20 23:58:03 2002 Soeren Sandmann <sandmann@daimi.au.dk>
|
||||||
|
|
||||||
* gtkmenu.c, gtkmenubar.c, gtkmenuitem.c, gtkmenushell.c,
|
* gtkmenu.c, gtkmenubar.c, gtkmenuitem.c, gtkmenushell.c,
|
||||||
|
|||||||
@@ -1,3 +1,15 @@
|
|||||||
|
Mon Oct 21 14:04:39 2002 Owen Taylor <otaylor@redhat.com>
|
||||||
|
|
||||||
|
* gtk/gtkentry.c (gtk_entry_get_public_chars): Return
|
||||||
|
"" for entry->invisible_char == 0, otherwise N copies
|
||||||
|
of entry->invisible_char. (#95486, Vitaly Tishkov)
|
||||||
|
|
||||||
|
* gtk/gtkentry.c: Fix a bunch of places where entry->text
|
||||||
|
instead of layout->text was being used for computation
|
||||||
|
of offsets/indices in the layout. Using layout->text
|
||||||
|
is necessary because when the entry is invisible, it
|
||||||
|
doesn't correspond to entry->text.
|
||||||
|
|
||||||
Sun Oct 20 23:58:03 2002 Soeren Sandmann <sandmann@daimi.au.dk>
|
Sun Oct 20 23:58:03 2002 Soeren Sandmann <sandmann@daimi.au.dk>
|
||||||
|
|
||||||
* gtkmenu.c, gtkmenubar.c, gtkmenuitem.c, gtkmenushell.c,
|
* gtkmenu.c, gtkmenubar.c, gtkmenuitem.c, gtkmenushell.c,
|
||||||
|
|||||||
@@ -1,3 +1,15 @@
|
|||||||
|
Mon Oct 21 14:04:39 2002 Owen Taylor <otaylor@redhat.com>
|
||||||
|
|
||||||
|
* gtk/gtkentry.c (gtk_entry_get_public_chars): Return
|
||||||
|
"" for entry->invisible_char == 0, otherwise N copies
|
||||||
|
of entry->invisible_char. (#95486, Vitaly Tishkov)
|
||||||
|
|
||||||
|
* gtk/gtkentry.c: Fix a bunch of places where entry->text
|
||||||
|
instead of layout->text was being used for computation
|
||||||
|
of offsets/indices in the layout. Using layout->text
|
||||||
|
is necessary because when the entry is invisible, it
|
||||||
|
doesn't correspond to entry->text.
|
||||||
|
|
||||||
Sun Oct 20 23:58:03 2002 Soeren Sandmann <sandmann@daimi.au.dk>
|
Sun Oct 20 23:58:03 2002 Soeren Sandmann <sandmann@daimi.au.dk>
|
||||||
|
|
||||||
* gtkmenu.c, gtkmenubar.c, gtkmenuitem.c, gtkmenushell.c,
|
* gtkmenu.c, gtkmenubar.c, gtkmenuitem.c, gtkmenushell.c,
|
||||||
|
|||||||
@@ -1,3 +1,15 @@
|
|||||||
|
Mon Oct 21 14:04:39 2002 Owen Taylor <otaylor@redhat.com>
|
||||||
|
|
||||||
|
* gtk/gtkentry.c (gtk_entry_get_public_chars): Return
|
||||||
|
"" for entry->invisible_char == 0, otherwise N copies
|
||||||
|
of entry->invisible_char. (#95486, Vitaly Tishkov)
|
||||||
|
|
||||||
|
* gtk/gtkentry.c: Fix a bunch of places where entry->text
|
||||||
|
instead of layout->text was being used for computation
|
||||||
|
of offsets/indices in the layout. Using layout->text
|
||||||
|
is necessary because when the entry is invisible, it
|
||||||
|
doesn't correspond to entry->text.
|
||||||
|
|
||||||
Sun Oct 20 23:58:03 2002 Soeren Sandmann <sandmann@daimi.au.dk>
|
Sun Oct 20 23:58:03 2002 Soeren Sandmann <sandmann@daimi.au.dk>
|
||||||
|
|
||||||
* gtkmenu.c, gtkmenubar.c, gtkmenuitem.c, gtkmenushell.c,
|
* gtkmenu.c, gtkmenubar.c, gtkmenuitem.c, gtkmenushell.c,
|
||||||
|
|||||||
@@ -1,3 +1,15 @@
|
|||||||
|
Mon Oct 21 14:04:39 2002 Owen Taylor <otaylor@redhat.com>
|
||||||
|
|
||||||
|
* gtk/gtkentry.c (gtk_entry_get_public_chars): Return
|
||||||
|
"" for entry->invisible_char == 0, otherwise N copies
|
||||||
|
of entry->invisible_char. (#95486, Vitaly Tishkov)
|
||||||
|
|
||||||
|
* gtk/gtkentry.c: Fix a bunch of places where entry->text
|
||||||
|
instead of layout->text was being used for computation
|
||||||
|
of offsets/indices in the layout. Using layout->text
|
||||||
|
is necessary because when the entry is invisible, it
|
||||||
|
doesn't correspond to entry->text.
|
||||||
|
|
||||||
Sun Oct 20 23:58:03 2002 Soeren Sandmann <sandmann@daimi.au.dk>
|
Sun Oct 20 23:58:03 2002 Soeren Sandmann <sandmann@daimi.au.dk>
|
||||||
|
|
||||||
* gtkmenu.c, gtkmenubar.c, gtkmenuitem.c, gtkmenushell.c,
|
* gtkmenu.c, gtkmenubar.c, gtkmenuitem.c, gtkmenushell.c,
|
||||||
|
|||||||
@@ -1,3 +1,15 @@
|
|||||||
|
Mon Oct 21 14:04:39 2002 Owen Taylor <otaylor@redhat.com>
|
||||||
|
|
||||||
|
* gtk/gtkentry.c (gtk_entry_get_public_chars): Return
|
||||||
|
"" for entry->invisible_char == 0, otherwise N copies
|
||||||
|
of entry->invisible_char. (#95486, Vitaly Tishkov)
|
||||||
|
|
||||||
|
* gtk/gtkentry.c: Fix a bunch of places where entry->text
|
||||||
|
instead of layout->text was being used for computation
|
||||||
|
of offsets/indices in the layout. Using layout->text
|
||||||
|
is necessary because when the entry is invisible, it
|
||||||
|
doesn't correspond to entry->text.
|
||||||
|
|
||||||
Sun Oct 20 23:58:03 2002 Soeren Sandmann <sandmann@daimi.au.dk>
|
Sun Oct 20 23:58:03 2002 Soeren Sandmann <sandmann@daimi.au.dk>
|
||||||
|
|
||||||
* gtkmenu.c, gtkmenubar.c, gtkmenuitem.c, gtkmenushell.c,
|
* gtkmenu.c, gtkmenubar.c, gtkmenuitem.c, gtkmenushell.c,
|
||||||
|
|||||||
105
gtk/gtkentry.c
105
gtk/gtkentry.c
@@ -2004,7 +2004,8 @@ get_better_cursor_x (GtkEntry *entry,
|
|||||||
gboolean split_cursor;
|
gboolean split_cursor;
|
||||||
|
|
||||||
PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
|
PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
|
||||||
gint index = g_utf8_offset_to_pointer (entry->text, offset) - entry->text;
|
const gchar *text = pango_layout_get_text (layout);
|
||||||
|
gint index = g_utf8_offset_to_pointer (text, offset) - text;
|
||||||
|
|
||||||
PangoRectangle strong_pos, weak_pos;
|
PangoRectangle strong_pos, weak_pos;
|
||||||
|
|
||||||
@@ -2826,9 +2827,12 @@ gtk_entry_find_position (GtkEntry *entry,
|
|||||||
gint index;
|
gint index;
|
||||||
gint pos;
|
gint pos;
|
||||||
gboolean trailing;
|
gboolean trailing;
|
||||||
gint cursor_index = g_utf8_offset_to_pointer (entry->text, entry->current_pos) - entry->text;
|
const gchar *text;
|
||||||
|
gint cursor_index;
|
||||||
|
|
||||||
layout = gtk_entry_ensure_layout (entry, TRUE);
|
layout = gtk_entry_ensure_layout (entry, TRUE);
|
||||||
|
text = pango_layout_get_text (layout);
|
||||||
|
cursor_index = g_utf8_offset_to_pointer (text, entry->current_pos) - text;
|
||||||
|
|
||||||
line = pango_layout_get_lines (layout)->data;
|
line = pango_layout_get_lines (layout)->data;
|
||||||
pango_layout_line_x_to_index (line, x * PANGO_SCALE, &index, &trailing);
|
pango_layout_line_x_to_index (line, x * PANGO_SCALE, &index, &trailing);
|
||||||
@@ -2844,7 +2848,7 @@ gtk_entry_find_position (GtkEntry *entry,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pos = g_utf8_pointer_to_offset (entry->text, entry->text + index);
|
pos = g_utf8_pointer_to_offset (text, text + index);
|
||||||
pos += trailing;
|
pos += trailing;
|
||||||
|
|
||||||
return pos;
|
return pos;
|
||||||
@@ -2856,30 +2860,49 @@ gtk_entry_get_cursor_locations (GtkEntry *entry,
|
|||||||
gint *strong_x,
|
gint *strong_x,
|
||||||
gint *weak_x)
|
gint *weak_x)
|
||||||
{
|
{
|
||||||
PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
|
if (!entry->visible && !entry->invisible_char)
|
||||||
const gchar *text;
|
|
||||||
PangoRectangle strong_pos, weak_pos;
|
|
||||||
gint index;
|
|
||||||
|
|
||||||
if (type == CURSOR_STANDARD)
|
|
||||||
{
|
{
|
||||||
text = pango_layout_get_text (layout);
|
if (strong_x)
|
||||||
index = g_utf8_offset_to_pointer (text, entry->current_pos + entry->preedit_cursor) - text;
|
*strong_x = 0;
|
||||||
}
|
|
||||||
else /* type == CURSOR_DND */
|
|
||||||
{
|
|
||||||
index = g_utf8_offset_to_pointer (entry->text, entry->dnd_position) - entry->text;
|
|
||||||
if (entry->dnd_position > entry->current_pos)
|
|
||||||
index += entry->preedit_length;
|
|
||||||
}
|
|
||||||
|
|
||||||
pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
|
if (weak_x)
|
||||||
|
*weak_x = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
|
||||||
|
const gchar *text = pango_layout_get_text (layout);
|
||||||
|
PangoRectangle strong_pos, weak_pos;
|
||||||
|
gint index;
|
||||||
|
|
||||||
|
if (type == CURSOR_STANDARD)
|
||||||
|
{
|
||||||
|
index = g_utf8_offset_to_pointer (text, entry->current_pos + entry->preedit_cursor) - text;
|
||||||
|
}
|
||||||
|
else /* type == CURSOR_DND */
|
||||||
|
{
|
||||||
|
index = g_utf8_offset_to_pointer (text, entry->dnd_position) - text;
|
||||||
|
|
||||||
if (strong_x)
|
if (entry->dnd_position > entry->current_pos)
|
||||||
*strong_x = strong_pos.x / PANGO_SCALE;
|
{
|
||||||
|
if (entry->visible)
|
||||||
if (weak_x)
|
index += entry->preedit_length;
|
||||||
*weak_x = weak_pos.x / PANGO_SCALE;
|
else
|
||||||
|
{
|
||||||
|
gint preedit_len_chars = g_utf8_strlen (text, -1) - entry->text_length;
|
||||||
|
index += preedit_len_chars * g_unichar_to_utf8 (entry->invisible_char, NULL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
|
||||||
|
|
||||||
|
if (strong_x)
|
||||||
|
*strong_x = strong_pos.x / PANGO_SCALE;
|
||||||
|
|
||||||
|
if (weak_x)
|
||||||
|
*weak_x = weak_pos.x / PANGO_SCALE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -3015,7 +3038,7 @@ gtk_entry_move_visually (GtkEntry *entry,
|
|||||||
index = new_index;
|
index = new_index;
|
||||||
|
|
||||||
while (new_trailing--)
|
while (new_trailing--)
|
||||||
index = g_utf8_next_char (entry->text + new_index) - entry->text;
|
index = g_utf8_next_char (text + new_index) - text;
|
||||||
}
|
}
|
||||||
|
|
||||||
return g_utf8_pointer_to_offset (text, text + index);
|
return g_utf8_pointer_to_offset (text, text + index);
|
||||||
@@ -3167,8 +3190,8 @@ gtk_entry_select_line (GtkEntry *entry)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Like gtk_editable_get_chars, but if the editable is not
|
* Like gtk_editable_get_chars, but handle not-visible entries
|
||||||
* visible, return asterisks; also convert result to UTF-8.
|
* correctly.
|
||||||
*/
|
*/
|
||||||
static char *
|
static char *
|
||||||
gtk_entry_get_public_chars (GtkEntry *entry,
|
gtk_entry_get_public_chars (GtkEntry *entry,
|
||||||
@@ -3180,20 +3203,14 @@ gtk_entry_get_public_chars (GtkEntry *entry,
|
|||||||
|
|
||||||
if (entry->visible)
|
if (entry->visible)
|
||||||
return gtk_editable_get_chars (GTK_EDITABLE (entry), start, end);
|
return gtk_editable_get_chars (GTK_EDITABLE (entry), start, end);
|
||||||
|
else if (!entry->invisible_char)
|
||||||
|
return g_strdup ("");
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
gchar *str;
|
GString *str = g_string_new (NULL);
|
||||||
gint i;
|
append_char (str, entry->invisible_char, end - start);
|
||||||
gint n_chars = end - start;
|
return g_string_free (str, FALSE);
|
||||||
|
|
||||||
str = g_malloc (n_chars + 1);
|
|
||||||
for (i = 0; i < n_chars; i++)
|
|
||||||
str[i] = '*';
|
|
||||||
str[i] = '\0';
|
|
||||||
|
|
||||||
return str;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -3708,11 +3725,15 @@ gint
|
|||||||
gtk_entry_layout_index_to_text_index (GtkEntry *entry,
|
gtk_entry_layout_index_to_text_index (GtkEntry *entry,
|
||||||
gint layout_index)
|
gint layout_index)
|
||||||
{
|
{
|
||||||
|
PangoLayout *layout;
|
||||||
|
const gchar *text;
|
||||||
gint cursor_index;
|
gint cursor_index;
|
||||||
|
|
||||||
g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
|
g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
|
||||||
|
|
||||||
cursor_index = g_utf8_offset_to_pointer (entry->text, entry->current_pos) - entry->text;
|
layout = gtk_entry_ensure_layout (entry, TRUE);
|
||||||
|
text = pango_layout_get_text (layout);
|
||||||
|
cursor_index = g_utf8_offset_to_pointer (text, entry->current_pos) - text;
|
||||||
|
|
||||||
if (layout_index >= cursor_index && entry->preedit_length)
|
if (layout_index >= cursor_index && entry->preedit_length)
|
||||||
{
|
{
|
||||||
@@ -3740,10 +3761,14 @@ gint
|
|||||||
gtk_entry_text_index_to_layout_index (GtkEntry *entry,
|
gtk_entry_text_index_to_layout_index (GtkEntry *entry,
|
||||||
gint text_index)
|
gint text_index)
|
||||||
{
|
{
|
||||||
|
PangoLayout *layout;
|
||||||
|
const gchar *text;
|
||||||
gint cursor_index;
|
gint cursor_index;
|
||||||
g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
|
g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
|
||||||
|
|
||||||
cursor_index = g_utf8_offset_to_pointer (entry->text, entry->current_pos) - entry->text;
|
layout = gtk_entry_ensure_layout (entry, TRUE);
|
||||||
|
text = pango_layout_get_text (layout);
|
||||||
|
cursor_index = g_utf8_offset_to_pointer (text, entry->current_pos) - text;
|
||||||
|
|
||||||
if (text_index > cursor_index)
|
if (text_index > cursor_index)
|
||||||
text_index += entry->preedit_length;
|
text_index += entry->preedit_length;
|
||||||
|
|||||||
Reference in New Issue
Block a user