Bug #914 - ClutterEntry is confused about characters vs. bytes

* clutter/clutter-entry.c: (clutter_entry_ensure_layout),
        (clutter_entry_handle_key_event_internal),
        (clutter_entry_set_text):
        Fix mix-up of character and byte counts, handle unicode correctly.
        Use clutter_key_event_unicode() instead of
        clutter_keysym_to_unicode().

        * clutter/clutter-event.c: (clutter_key_event_unicode):
        Don't ignore ClutterKeyEvent.unicode_value

        * clutter/clutter-keysyms-table.h:
        Rename header define so as not to conflict with clutter-keysyms.h

        Patch originally by Emmanuele Bassi, with input from Tommi Komulainen.
This commit is contained in:
Chris Lord 2008-06-09 10:13:20 +00:00
parent 374022bc3d
commit db232dd5e7
4 changed files with 53 additions and 13 deletions

View File

@ -1,3 +1,22 @@
2008-06-09 Chris Lord <chris@openedhand.com>
Bug #914 - ClutterEntry is confused about characters vs. bytes
* clutter/clutter-entry.c: (clutter_entry_ensure_layout),
(clutter_entry_handle_key_event_internal),
(clutter_entry_set_text):
Fix mix-up of character and byte counts, handle unicode correctly.
Use clutter_key_event_unicode() instead of
clutter_keysym_to_unicode().
* clutter/clutter-event.c: (clutter_key_event_unicode):
Don't ignore ClutterKeyEvent.unicode_value
* clutter/clutter-keysyms-table.h:
Rename header define so as not to conflict with clutter-keysyms.h
Patch originally by Emmanuele Bassi, with input from Tommi Komulainen.
2008-06-07 Øyvind Kolås <pippin@o-hand.com> 2008-06-07 Øyvind Kolås <pippin@o-hand.com>
* clutter/clutter-texture.c: made the filter-quality proeprty also * clutter/clutter-texture.c: made the filter-quality proeprty also

View File

@ -104,7 +104,8 @@ struct _ClutterEntryPrivate
gint extents_height; gint extents_height;
gint width; gint width;
gint n_chars; gint n_chars; /* number of chars */
gint n_bytes; /* number of bytes */
guint alignment : 2; guint alignment : 2;
guint wrap : 1; guint wrap : 1;
@ -270,15 +271,23 @@ clutter_entry_ensure_layout (ClutterEntry *entry, gint width)
pango_layout_set_font_description (priv->layout, priv->desc); pango_layout_set_font_description (priv->layout, priv->desc);
if (priv->text_visible) if (priv->text_visible)
pango_layout_set_text (priv->layout, priv->text, priv->n_chars); pango_layout_set_text (priv->layout, priv->text, priv->n_bytes);
else else
{ {
gint len = g_utf8_strlen (priv->text, -1); GString *str = g_string_sized_new (priv->n_bytes);
gchar *invisible = g_strnfill (len, priv->priv_char); gunichar invisible_char;
gint i;
pango_layout_set_text (priv->layout, invisible, len); if (priv->priv_char != 0)
invisible_char = priv->priv_char;
g_free (invisible); else
invisible_char = '*';
for (i = 0; i < priv->n_chars; i++)
g_string_append_unichar (str, invisible_char);
pango_layout_set_text (priv->layout, str->str, str->len);
g_string_free (str, TRUE);
} }
if (priv->wrap) if (priv->wrap)
@ -499,6 +508,7 @@ static inline void
clutter_entry_handle_key_event_internal (ClutterEntry *entry, clutter_entry_handle_key_event_internal (ClutterEntry *entry,
ClutterKeyEvent *event) ClutterKeyEvent *event)
{ {
gunichar key_unichar;
ClutterEntryPrivate *priv = entry->priv; ClutterEntryPrivate *priv = entry->priv;
gint pos = priv->position; gint pos = priv->position;
gint len = 0; gint len = 0;
@ -567,8 +577,9 @@ clutter_entry_handle_key_event_internal (ClutterEntry *entry,
break; break;
default: default:
clutter_entry_insert_unichar (entry, key_unichar = clutter_key_event_unicode (event);
clutter_keysym_to_unicode (keyval)); if (g_unichar_validate (key_unichar))
clutter_entry_insert_unichar (entry, key_unichar);
break; break;
} }
} }
@ -1027,7 +1038,10 @@ clutter_entry_set_text (ClutterEntry *entry,
if (len < priv->max_length) if (len < priv->max_length)
{ {
g_free (priv->text); g_free (priv->text);
priv->text = g_strdup (text); priv->text = g_strdup (text);
priv->n_bytes = strlen (text);
priv->n_chars = len;
} }
else else
{ {
@ -1037,6 +1051,8 @@ clutter_entry_set_text (ClutterEntry *entry,
g_free (priv->text); g_free (priv->text);
priv->text = n; priv->text = n;
priv->n_bytes = strlen (n);
priv->n_chars = priv->max_length;
} }
} }
else else
@ -1044,6 +1060,7 @@ clutter_entry_set_text (ClutterEntry *entry,
g_free (priv->text); g_free (priv->text);
priv->text = g_strdup (text); priv->text = g_strdup (text);
priv->n_bytes = strlen (text);
priv->n_chars = g_utf8_strlen (priv->text, -1); priv->n_chars = g_utf8_strlen (priv->text, -1);
} }

View File

@ -27,6 +27,7 @@
#include "config.h" #include "config.h"
#endif #endif
#include "clutter-keysyms.h"
#include "clutter-keysyms-table.h" #include "clutter-keysyms-table.h"
#include "clutter-event.h" #include "clutter-event.h"
#include "clutter-private.h" #include "clutter-private.h"
@ -263,8 +264,11 @@ guint32
clutter_key_event_unicode (ClutterKeyEvent *keyev) clutter_key_event_unicode (ClutterKeyEvent *keyev)
{ {
g_return_val_if_fail (keyev != NULL, 0); g_return_val_if_fail (keyev != NULL, 0);
return clutter_keysym_to_unicode (keyev->keyval); if (keyev->unicode_value)
return keyev->unicode_value;
else
return clutter_keysym_to_unicode (keyev->keyval);
} }
/** /**

View File

@ -1,5 +1,5 @@
#ifndef __CLUTTER_KEYSYMS_H__ #ifndef __CLUTTER_KEYSYMS_TABLE_H__
#define __CLUTTER_KEYSYMS_H__ #define __CLUTTER_KEYSYMS_TABLE_H__
/* Code below from GDK, which contains following comment; /* Code below from GDK, which contains following comment;
* *