[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]
Re: Help, I need filter text in function
- From: Thomas Mailund <mailund mailund dk>
- To: GTK+ App devel list <gtk-app-devel-list gnome org>
- Subject: Re: Help, I need filter text in function
- Date: 31 Aug 2001 10:16:31 +0930
On Fri, 2001-08-31 at 03:28, javiercmx@correo.unam.mx wrote:
> Hi list
>
> I write a function it admit numbers, the function is:
>
> void edit_clv_plt(GtkWidget *widget, gpointer data) {
> char *tmpplt;
> char ch = *((char *) data);
> char *str;
>
> str = (char *) data;
>
> if(isdigit (ch) && strlen (str) == 1) { /*introducing a number*/
> g_free(host.plt);
>
> /*it obtains the chain*/
> tmpplt=gtk_editable_get_chars(GTK_EDITABLE(widget),0 ,-1);
> host.plt=g_strdup(tmpplt);
>
> } else {
> Messages("Error","Write the number"); /*Function for Show Messages*/
> }
> }
I don't know what your data element is, so I can't really tell you what
is wrong with your code.
> The user write the numbers, in GtkEntry, the text is not allowed, the max digits
> is 3, but when running the program write a text, call function Messages, if
> write a number, call a function Messages, where this the error
I've attached a program that only allows you to type in digits, and only
up to three of those. It is not a particullar good example, 'cause you
cant delete chars or move the cursor since these keys are also aborted,
but perhaps you can use it to get where you want.
/mailund
--
I used up all my sick days, so I'm calling in dead.
#include <gtk/gtk.h>
#include <ctype.h>
#include <string.h>
static gboolean
key_event (GtkWidget *entry, GdkEvent * event)
{
if ((strlen (gtk_entry_get_text (GTK_ENTRY (entry))) < 3)
&& isdigit(event->key.keyval))
{
// don't abort
return FALSE;
}
// abort event
gtk_signal_emit_stop_by_name (GTK_OBJECT (entry), "key_press_event");
return TRUE;
}
int
main (int argc, char *argv[])
{
GtkWidget *win;
GtkWidget *entry;
gtk_init (&argc, &argv);
win = gtk_window_new (GTK_WINDOW_TOPLEVEL);
entry = gtk_entry_new ();
gtk_container_add (GTK_CONTAINER (win), entry);
gtk_signal_connect (GTK_OBJECT (entry), "key_press_event",
GTK_SIGNAL_FUNC (key_event), entry);
gtk_widget_show_all (win);
gtk_main ();
return 0;
}
PGP signature
[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]