GtkEditable and utf8 question



Hello,

I would like to force an entry to insert only digit characters. I have
tried to modify the insert_text_handler example that is in the GtkEditable
API. The result is:

static void
_insert_numeric (GtkEditable *editable,
                 const gchar *text,
                 gint         length,
                 gint        *position,
                 gpointer     data)
{
  gint i;
  gint j;
  gchar *result;

  result = (gchar *)g_malloc (sizeof (gchar) * (length + 1));
  if (!result)
    return;

  for (i = 0, j = 0; i < length; i++)
    {
      if (g_ascii_isdigit (text[i]))
        {
          result[j] = text[i];
          j++;
        }
    }
  result[j] = '\0';

  g_signal_handlers_block_by_func (editable,
				   (gpointer) _insert_numeric, data);
  gtk_editable_insert_text (editable, result, length, position);
  g_signal_handlers_unblock_by_func (editable,
                                     (gpointer) _insert_numeric, data);

  g_signal_stop_emission_by_name (editable, "insert-text");

  g_free (result);
}

but, each time I insert something in the entry, I get the following
warning:

(avisynth_test:13311): Pango-WARNING **: Invalid UTF-8 string passed to
pango_layout_set_text()

I know almost nothing about utf8 and pango. I've tried to use the g_utf8*
functions, but, in the best case (when it works a bit), I always have that
warning.

Can someone tell me what is the correct way of inserting digit char ?

thank you

Vincent Torri



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]