GTK: When 0 + 1 = 0



Hello
I've walked into one of these unsummountable mountains that people go through
occastionally when learning a new programming enviroment.

I'm writing a GTK program in C and I have a window with 2 radio buttons and 2 GtkEditable 
text entry boxes.

I want to validate the data by my own code (no spin button) and the code looks like this
for my callback function:


static void validate_weight(GtkWidget *widget,gpointer a){
        gint pos = 0;
        gint len = 0;
        gint i = 0;
        lbw.weight = 0;
        
        GtkWidget * dialog;
        
        pos = gtk_editable_get_position(GTK_EDITABLE(widget));
        len = pos + 1;
        gchar* text = g_new(gchar,len);
        text = gtk_editable_get_chars (GTK_EDITABLE(widget), 0, -1);
        g_print("POS: %d\n",pos);
        g_print("TEXT: %s\n",text);

        
        for( i=0; i<len; i++){
               g_print("THIS CHAR=> %c\n This is INDEX=> %d",text[i],i);
               if(!isdigit(text[i])){

                         dialog = gtk_message_dialog_new (GTK_WINDOW(widget), GTK_DIALOG_MODAL, 
GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, "Entry Digits for Weight in Pounds");
                         g_signal_connect_swapped (GTK_OBJECT (dialog), "response", G_CALLBACK 
(gtk_widget_destroy), GTK_OBJECT (dialog));
                         g_signal_handlers_block_by_func (GTK_OBJECT (widget), validate_weight, a);
                         gtk_widget_show(dialog);
                         gtk_editable_insert_text (GTK_EDITABLE(widget), NULL, 0, 0);
                         g_signal_handlers_unblock_by_func (GTK_OBJECT (widget), validate_weight, a);

                         g_signal_stop_emission_by_name (GTK_OBJECT (widget), "validate_weight"); 

                         g_free (text);
                         return;
               }
        }

        lbw.weight = atoi(text);
}


void lbw_calc(GtkWidget * widget, gpointer a){
        return;
}

Originally I have the line:

 for( i=0; i<len; i++)

as 
 for( i=0; i<pos; i++)

and the result was that this code never checked the first entered charactor into the box.  

When I run this through the debugger, it gets to the line:

len = pos + 1;

and it displays that pos is zero and len is zero.  In fact, it just swings through this code
completely out of order.  I have no idea what gtk_main is doing, but when I code len = pos +0 and pos is
zero, I expect len to be 1.

Also, it seems that the line 

 pos = gtk_editable_get_position(GTK_EDITABLE(widget));

returns a huge number.  I'm completely confused at this point.  There must be a reason that this behavior is 
happening, but I have no clue as to why.

I've tarred up this entire program and put it at http:///www.nylxs.com/images/clinical.tgz if anyone want to
look at it and help.


Ruben

-- 
__________________________
Brooklyn Linux Solutions

So many immigrant groups have swept through our town 
that Brooklyn, like Atlantis, reaches mythological 
proportions in the mind of the world  - RI Safir 1998

DRM is THEFT - We are the STAKEHOLDERS - RI Safir 2002
http://fairuse.nylxs.com

http://www.mrbrklyn.com - Consulting
http://www.inns.net <-- Happy Clients
http://www.nylxs.com - Leadership Development in Free Software
http://www2.mrbrklyn.com/resources - Unpublished Archive or stories and articles from around the net
http://www2.mrbrklyn.com/downtown.html - See the New Downtown Brooklyn....

1-718-382-0585



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