Re: Question about widgets



Hello Vikram,

  It has an interesting thing which is, it has a
single widget 'button' 
assigned to 2 different button instances "Button 1"
and "Button 2". 

You see vikram the two buttons aren't assigned to
button variable at the same time.  Actually here the
button variable is used to hold the reference of the
widget for some time just to use it for calling other
functions.

Once the functions are called the reference as it is a
local reference is no longer required.  When the
callback is called a reference to the appropriate
button will always be passed to the callback function.

int main( int   argc,char *argv[] )
{
    GtkWidget *window;
    GtkWidget *button;
                 ^ This is local variable to hold ref
    GtkWidget *box1;
    
    gtk_init (&argc, &argv);

    window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
    gtk_signal_connect (GTK_OBJECT (window),
"delete_event",
                        GTK_SIGNAL_FUNC
(delete_event), NULL);
    gtk_container_set_border_width (GTK_CONTAINER
(window), 10);

    box1 = gtk_hbox_new(FALSE, 0);
    gtk_container_add (GTK_CONTAINER (window),
box1);

    button = gtk_button_new_with_label ("Button 1");
    gtk_signal_connect (GTK_OBJECT (button),
"clicked",
                   GTK_SIGNAL_FUNC (callback),
(gpointer) "button 1");
    gtk_box_pack_start(GTK_BOX(box1), button, TRUE,
TRUE, 0);
    gtk_widget_show(button);

     By the statement below the reference of the first
button will be lost and the new button's reference
will be obtained in the button variable.

    button = gtk_button_new_with_label ("Button 2");
    gtk_signal_connect (GTK_OBJECT (button),
"clicked",
                   GTK_SIGNAL_FUNC (callback),
(gpointer) "button 2");
    gtk_box_pack_start(GTK_BOX(box1), button, TRUE,
TRUE, 0);
    gtk_widget_show(button);

    gtk_widget_show(box1);
    gtk_widget_show (window);

    gtk_main ();
    return(0);
}


=====
Tushar Vijay Joshi
42/3 Ujjwal Nagar, Wardha Road, Nagpur 440 025
(0) 235940 (R) 260565 (M) 98222-20365
Email: tusharvjoshi yahoo com
<<No one can laugh at a person who can laugh at himself.
Smile anyway.  Success is never ending Failure is never Final.>>

__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com



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