]> Pileus Git - ~andy/gtk/commitdiff
Return "" for entry->invisible_char == 0, otherwise N copies of
authorOwen Taylor <otaylor@redhat.com>
Mon, 21 Oct 2002 19:04:18 +0000 (19:04 +0000)
committerOwen Taylor <otaylor@src.gnome.org>
Mon, 21 Oct 2002 19:04:18 +0000 (19:04 +0000)
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.

ChangeLog
ChangeLog.pre-2-10
ChangeLog.pre-2-2
ChangeLog.pre-2-4
ChangeLog.pre-2-6
ChangeLog.pre-2-8
gtk/gtkentry.c

index ee0c086a870de3691bbdb3a9aa750c31d7cf65e8..e561d0561163277a5293a1763712cb73e63c1a27 100644 (file)
--- a/ChangeLog
+++ b/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>
 
        * gtkmenu.c, gtkmenubar.c, gtkmenuitem.c, gtkmenushell.c,
index ee0c086a870de3691bbdb3a9aa750c31d7cf65e8..e561d0561163277a5293a1763712cb73e63c1a27 100644 (file)
@@ -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>
 
        * gtkmenu.c, gtkmenubar.c, gtkmenuitem.c, gtkmenushell.c,
index ee0c086a870de3691bbdb3a9aa750c31d7cf65e8..e561d0561163277a5293a1763712cb73e63c1a27 100644 (file)
@@ -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>
 
        * gtkmenu.c, gtkmenubar.c, gtkmenuitem.c, gtkmenushell.c,
index ee0c086a870de3691bbdb3a9aa750c31d7cf65e8..e561d0561163277a5293a1763712cb73e63c1a27 100644 (file)
@@ -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>
 
        * gtkmenu.c, gtkmenubar.c, gtkmenuitem.c, gtkmenushell.c,
index ee0c086a870de3691bbdb3a9aa750c31d7cf65e8..e561d0561163277a5293a1763712cb73e63c1a27 100644 (file)
@@ -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>
 
        * gtkmenu.c, gtkmenubar.c, gtkmenuitem.c, gtkmenushell.c,
index ee0c086a870de3691bbdb3a9aa750c31d7cf65e8..e561d0561163277a5293a1763712cb73e63c1a27 100644 (file)
@@ -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>
 
        * gtkmenu.c, gtkmenubar.c, gtkmenuitem.c, gtkmenushell.c,
index 2c18e28411ce47057568a5e452c90e9ac465fbb7..2dda007d53cb3fb599ffd9e0d0933757c843fbfb 100644 (file)
@@ -2004,7 +2004,8 @@ get_better_cursor_x (GtkEntry *entry,
   gboolean split_cursor;
   
   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;
   
@@ -2826,9 +2827,12 @@ gtk_entry_find_position (GtkEntry *entry,
   gint index;
   gint pos;
   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);
+  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;
   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;
 
   return pos;
@@ -2856,30 +2860,49 @@ gtk_entry_get_cursor_locations (GtkEntry   *entry,
                                gint       *strong_x,
                                gint       *weak_x)
 {
-  PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
-  const gchar *text;
-  PangoRectangle strong_pos, weak_pos;
-  gint index;
-  
-  if (type == CURSOR_STANDARD)
+  if (!entry->visible && !entry->invisible_char)
     {
-      text = pango_layout_get_text (layout);
-      index = g_utf8_offset_to_pointer (text, entry->current_pos + entry->preedit_cursor) - text;
+      if (strong_x)
+       *strong_x = 0;
+      
+      if (weak_x)
+       *weak_x = 0;
     }
-  else /* type == CURSOR_DND */
+  else
     {
-      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 (strong_x)
-    *strong_x = strong_pos.x / PANGO_SCALE;
+      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 (weak_x)
-    *weak_x = weak_pos.x / PANGO_SCALE;
+         if (entry->dnd_position > entry->current_pos)
+           {
+             if (entry->visible)
+               index += entry->preedit_length;
+             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
@@ -3015,7 +3038,7 @@ gtk_entry_move_visually (GtkEntry *entry,
       index = new_index;
       
       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);
@@ -3167,8 +3190,8 @@ gtk_entry_select_line (GtkEntry *entry)
 }
 
 /*
- * Like gtk_editable_get_chars, but if the editable is not
- * visible, return asterisks; also convert result to UTF-8.
+ * Like gtk_editable_get_chars, but handle not-visible entries
+ * correctly.
  */
 static char *    
 gtk_entry_get_public_chars (GtkEntry *entry,
@@ -3180,20 +3203,14 @@ gtk_entry_get_public_chars (GtkEntry *entry,
   
   if (entry->visible)
     return gtk_editable_get_chars (GTK_EDITABLE (entry), start, end);
+  else if (!entry->invisible_char)
+    return g_strdup ("");
   else
     {
-      gchar *str;
-      gint i;
-      gint n_chars = end - start;
-       
-      str = g_malloc (n_chars + 1);
-      for (i = 0; i < n_chars; i++)
-       str[i] = '*';
-      str[i] = '\0';
-      
-      return str;
+      GString *str = g_string_new (NULL);
+      append_char (str, entry->invisible_char, end - start);
+      return g_string_free (str, FALSE);
     }
-
 }
 
 static void
@@ -3708,11 +3725,15 @@ gint
 gtk_entry_layout_index_to_text_index (GtkEntry *entry,
                                       gint      layout_index)
 {
+  PangoLayout *layout;
+  const gchar *text;
   gint cursor_index;
   
   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)
     {
@@ -3740,10 +3761,14 @@ gint
 gtk_entry_text_index_to_layout_index (GtkEntry *entry,
                                       gint      text_index)
 {
+  PangoLayout *layout;
+  const gchar *text;
   gint cursor_index;
   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)
     text_index += entry->preedit_length;