Re: [gtk-list] Fundamental Problems...



The theory behind callbacks isn't really hard. When an event occurs
(like a mouse button is pressed) the apropiate widget emits the signal,
so shouting out to everything "Hey the button was clicked!" Gtk then
checks which callbacks are attached (who listens to this shouting) and
excecutes all these functions. That's all. 

The function prototype of a signal is always the same for that signal.
The first argument is always the pointer to the emitting structure (the
widget in the above example), additionaly some other variabels
containing data about the event and the user_data. If your function
needs data, this is the way to deliver it to your function. This data is
set at-connect-time, meaning it is set when you gtk_signal_connect(). 

Return values of callbacks are for internal use of Gtk only, they are
never used by the programmer to give something back to it's own program,
because the function is never called by the program itself, only Gtk
calles the function. Most functions don't have return values. A return
value is (almost) always a gboolean. If a callback function returns TRUE
,no other callbacks that are connected to the signal, but aren't yet
excecuted will be excecuted, the emission stops. So it means the event
was handled and shouldn't be handled anymore. FALSE means you handled
the event, but other events may also handle it. 

Generally the callback function contains that code you want to excecute
as a RESPONSE to actions of the GUI (most of the time via the user of
your program). During the excecution of you're program, it just sits
there and waits for events. Only if such an event occurs your code is
excecuted, the rest of the time is just a wast of CPU cycles...

Jeroen


Ankit Mohan wrote:
> 
> I am new to gtk prog. and am facing a few problems. It would be great if
> someone could clarify the following doubts for me :
> 
> a) How do I pass two or more parameters to a call back function.
> 
> b) Call back functions of which signals/events accept how many
> parameters? Is this fixed? Where can I find more help on this?
> 
> c) While using ItemFactory to make a menubar, how do I send user
> parameters to the callback functions? Also, how do I take care of the
> value returned by the functions (Is this possible???)
> 
> d) While using ItemFactory to make menus, what is the function
> definition of the callback function? I tried to look in sample programs,
> and found different formats of the function definition in different
> places. They all seem to work...
> 
> As you can see, I am basically having trouble understanding the theory
> behind callback functions.
> 
> Thanks in advance,
> 
> Ankit Mohan
>



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