Re: error in a GtkEditable
- From: Angelo Cano <acano systec com>
- To: gtk-app-devel-list gnome org
- Subject: Re: error in a GtkEditable
- Date: Thu, 29 Mar 2001 12:38:12 -0500
On Thu, Mar 29, 2001 at 10:29:33AM -0100, guigtk wrote:
I want limit the lenght of the text to 5.
The code works fine ¿?, but the program shows in the console:
Gtk-CRITICAL **: file gtktext.c: line 879 (gtk_text_set_point):
assertion `index <= TEXT_LENGTH (text)' failed.
¿What happens?
This is the code:
void
on_text1_insert_text (GtkEditable *editable,
gchar *new_text,
gint
new_text_length,
gint *position,
gpointer user_data)
{
gint a;
a=gtk_text_get_length(GTK_TEXT (editable));
if (a>5) {gtk_editable_delete_text(GTK_EDITABLE(editable), 5, 6);}
}
This function is called by a "insert_text" signal.
Thanks a million
Guillermo
___________________________________________________________________
Consigue tu e-mail gratuito TERRA.ES
Haz clic en http://www.terra.es/correo/
#include <gtk/gtk.h>
gint insert_text_cb (GtkWidget *editable,
const gchar *text,
gint length,
gint *position)
{
gint a;
a = gtk_text_get_length (GTK_TEXT (editable));
/* compare it to 'a + length' instead of just 'a' to handle cut and paste */
if (a + length > 5) {
gtk_signal_emit_stop_by_name (GTK_OBJECT (editable), "insert_text");
return TRUE;
}
return FALSE;
}
int main (int argc, char *argv[])
{
GtkWidget *window, *text;
gtk_init (&argc, &argv);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
text = gtk_text_new (NULL, NULL);
gtk_text_set_editable (GTK_TEXT (text), TRUE);
gtk_signal_connect (GTK_OBJECT (text),
"insert_text",
GTK_SIGNAL_FUNC (insert_text_cb),
NULL);
gtk_container_add (GTK_CONTAINER (window), text);
gtk_widget_show_all (window);
gtk_main ();
return 0;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]