Re: widgets/callbacks



Matt Hillebrand wrote:

Hi,

MH> I cannot figure out how to access widgets from within callback
MH> functions. For example, how do I make a second window appear when a button
MH> on the main window is clicked?

It's quite simple. Add this in the caller function :

gtk_signal_connect (GTK_OBJECT (button),
                    "clicked",
                    GTK_SIGNAL_FUNC (create_window),
                    NULL);

Then,   create  a  function create_window (GtkButton *button, gpointer
user_data)  (here user_data is NULL, but it's not always the case, see
further), which has the convenient (R)(TM)(C) code to create another window.
It should look like :

void
create_window (GtkButton *button, gpointer user_data)
{
    GtkWidget *window;
    ... /* The widgets you want in the window */

    window  =  gtk_window_new  (GTK_WINDOW_DIALOG);  /*  If you want a
    dialog */
    gtk_widget_show (window);
    ...
    gtk_main (); /* Shouldn't be gtk_main, but that's so simple :-) */
}


MH> Also, I would like to access widgets such as the scrolled window's labels
MH> of one window from callbacks associated with buttons on other windows.

In  this  case,  you  should pass the scrolled_window (or directly the
label)  to  the  callback  through  the  gpointer  (equivalent to void
pointer) user_data :

gtk_signal_connect (GTK_OBJECT (obj),
                    "signal",
                    GTK_SIGNAL_FUNC (func),
                    (gpointer)sw);

where sw is the scrolled window.

Then, declare the callback function:

void
func (GtkButton *button, gpointer user_data) /* Assuming the obj is button */
{
     GtkWidget *sw = GTK_WIDGET (user_data);
     ..
}

Note that GtkWidget could be GtkScrolledWindow.

MH> Thanks!


MH> Matthew P. Hillebrand


Hope this helps,


--
mmenal
                                 ____               _    _                    _
         __  __ _ __  __  __    / ___| ___  _   _  | |  ( )_ __  _   ___  __ | |
(o-      \ \/ /(_)\ \/ /  _ \  | |  _ /'_ \| | | | | |  | | '_ \| | | \ \/ / | |
/\        \  / | | \  / | __/  | |_| | | | | |_| | | |__| | | | | |_| |>  <  |_|
L_/_       \/  |_|  \/  \___|  \_____|_| |_|\__,_/ |____|_|_| |_|\__,_/_/\_\ (_)


 
______________________________________________________________________________
Vous avez un site perso ?
2 millions de francs à gagner sur i(france) !
Webmasters : ZE CONCOURS ! http://www.ifrance.com/_reloc/concours.emailif






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