Re: gboolean and structure problem...



If its neither true or false then it must be NULL, surely.

I think your problem is that your "clicked" signal connect is within a
procedure called by the clicked event. That is, the clicked event calls
format_data() and that calls draw_format_button() which is where you put
your signal connect.

As a general rule I put the signal connects just after creation of the
widgets, ie in draw_formatter() in your case.

You'll probably find that the button is fine until you click it the
first time. Add a g_print("format_state is %d\n",
formatter->format_state) to the beginning of the format_data() procedure
and see how it changes when you click the button.

Or you can run it through xxgdb to track the value of the format_state

Simon
Network Engineer.

On Sat, 2001-09-08 at 10:05, Randy wrote:
> Greetings,
> 
> I was not sure where to post this, but I figured that maybe this mailing list
> could help me.  Here's snippets of my code, perhaps someone can tell me why
> formatter->format_state is not working. Apparently, it is neither TRUE nor
> FALSE. Thanks.
> 
> Sincerely,
> Randy
> 
> #####################
> 
> typedef struct {
>         gboolean format_state;  // tells whether to draw the format button or
> clear button
>         GtkWidget *formatter_table;
>         GtkWidget *text_box;
>         gint type_of_format;
> } formatter_t;
> 
> void draw_format_button( formatter_t *formatter, gboolean format_or_clear );
> 
> void
> format_data( formatter_t *formatter )
> {
>         if( formatter->format_state == TRUE ) {
>               draw_format_button( formatter, FALSE );
>         }
>         else if( formatter->format_state == FALSE ) {
>                   draw_format_button( formatter, TRUE );
>         }
>         else {
> 	    /* this is where I always end up */
>                 g_print( "You shouldn't be here right now...\n" );
>         }
> }
> 
> void
> draw_format_button( formatter_t *formatter, gboolean format_or_clear )
> {
>         static GtkWidget *format_label;
>         static GtkWidget *format_button;
> 
>         if( !format_label ) {
>                 format_label = gtk_label_new( "Format" );
>                 format_button = gtk_button_new();
>                 gtk_container_add( GTK_CONTAINER(format_button), format_label
> );
>                 gtk_signal_connect( GTK_OBJECT(format_button), "clicked",
> GTK_SIGNAL_FUNC(format_data), formatter );
>                gtk_table_attach( GTK_TABLE(formatter->formatter_table),
> format_button, 8, 9, 0, 1, GTK_FILL, GTK_FILL, 8, 2 );
>         }
> 
>        if( format_or_clear == TRUE ) {
>                 formatter->format_state = TRUE;
>                 gtk_label_set_text( GTK_LABEL(format_label), "Format" );
>         }
>         else {
>                 formatter->format_state = FALSE;
>                 gtk_label_set_text( GTK_LABEL(format_label), "Clear" );
>         }
> }
> 
> 
> void
> draw_formatter( formatter_t *formatter )
> {
>         formatter->text_box = gtk_text_new( NULL, NULL );
>         gtk_text_set_editable( GTK_TEXT(formatter->text_box), TRUE );
>         gtk_table_attach(GTK_TABLE(formatter->formatter_table),
> formatter->text_box, 0, 5, 0, 9, GTK_EXPAND | GTK_SHRINK | GTK_FILL,
> GTK_EXPAND | GTK_SHRINK | GTK_FILL, 1, 1);
> 
> draw_format_button( formatter, TRUE );
> }
> 
> main()
> {
>         formatter_t formatter;
>         formatter.formatter_table = gtk_table_new( 15, 15, FALSE );
>         formatter.format_state = TRUE;
>         draw_formatter( &formatter );
> }
> 
> _______________________________________________
> gtk-list mailing list
> gtk-list gnome org
> http://mail.gnome.org/mailman/listinfo/gtk-list
> 






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