gboolean and structure problem...



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 );
}




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