Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.
  • Root
  • » GTK+
  • » GtkEditable and utf8 question [RSS Feed]

#1 Nov. 20, 2005 13:08:00

Vincent T.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

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))
{
result = text;
j++;
}
}
result = '\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
_______________________________________________
gtk-list mailing list
gtk-list@gnome.orghttp://mail.gnome.org/mailman/listinfo/gtk-list

Offline

#2 Nov. 21, 2005 08:24:26

Olexiy A.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

GtkEditable and utf8 question


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))
{
result = text;
j++;
}
}
result = '\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 mailing list
gtk-list@gnome.orghttp://mail.gnome.org/mailman/listinfo/gtk-list

Offline

#3 Nov. 21, 2005 09:26:39

Martyn R.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

GtkEditable and utf8 question


On Sat, 2005-11-19 at 08:35 +0100, Vincent Torri wrote:
> 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))
> {
> result = text;
> j++;
> }
> }
> result = '\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 ?

I would recommend this method, it reads a little cleaner and is better
than calling gtk_editable_insert_text() with blocking functions.

static void
insert_text_cb (GtkEditable *editable,
gchar *new_text,
gint len,
gint *position,
gpointer user_data)
{
gint i;

for (i = 0; i < len; ++i) {
gchar *ch = new_text + i;
if (!isdigit (*ch)) {
g_signal_stop_emission_by_name (editable,
"insert-text");
return;
}
}
}

--
Regards,
Martyn

_______________________________________________
gtk-list mailing list
gtk-list@gnome.orghttp://mail.gnome.org/mailman/listinfo/gtk-list

Offline

  • Root
  • » GTK+
  • » GtkEditable and utf8 question [RSS Feed]

Board footer

Moderator control

Enjoy the 20th of January
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support