Vincent Torri wrote:
Hello,
Hi,
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);
gtk_editable_insert_text (editable, result, j, position); /* You've passed the incorrect string's length */
g_signal_handlers_unblock_by_func (editable, (gpointer) _insert_numeric, data); g_signal_stop_emission_by_name (editable, "insert-text"); g_free (result); }
Olexiy _______________________________________________ gtk-list@xxxxxxxxx http://mail.gnome.org/mailman/listinfo/gtk-list