[gtk-server] Re: Multiple callbacks on the same widget

  • From: Peter van Eerten <administrator@xxxxxxxxxxxxxx>
  • To: gtk-server@xxxxxxxxxxxxx
  • Date: Tue, 21 Jun 2005 23:22:47 +0200

Hi Philippe,

It seems you are asking for 2 things :-).

1) Regarding the callback mechanism. The GTK-server configfile defines GTK
functions, each of which has certain properties. For example, the GTK function
which creates a GtkButton can be defined as follows:

GTK_LIB_FUNCTION = gtk_button_new, clicked, WIDGET, 0

As you can see, in this line the 'clicked' signal is mentioned and will be
recognized by the GTK-server as soon a mouseclick on a button occurs. In the
mainloop of your CLisp client program you can check on the ID of the button when
the function 'gtk_server_callback' returns, and take appropriate action.

At the same time these lines in the GTK-server configfile can only describe 1
callback signal per widget. Therefore, the GTK-server has the ability also to
define other signals for a particular widget. E.g. suppose you also want to
connect the 'enter' signal to the button, it can be done like this:

gtk_server_connect <widgetID> enter Blabla

The mainloop of your CLisp client catches the returnvalue of the
'gtk_server_callback' function, which, in the above example, returns "Blabla" in
case the mouse has entered the area of the GtkButton.

The AWK demo with STDIN on the GTK-server website demonstrates how this all
works: http://www.gtk-server.org/demo-stdin.awk.txt
Just rewrite in CLisp.

2) Now for the Drag and Drop stuff (DnD). Indeed it is necessary to connect
additional signals for DnD. However, the callback routines need information
which is passed to the callback function. This already is possible up to 4
arguments. For DnD implementations however, you need to read 8 arguments.

So how does it work anyway? For DnD, the signal "drag-data-received" need to be
connected to, for example, a list widget. This can be achieved with the
GTK-server function 'gtk_server_connect' as described above. Now, when the
"drag-data-received" signal occurs, 8 values are being set: the widget which
received the signal, the drag context, x and y coordinates where the drop
happened, the receive data, info, timestamp and some userdata (see
http://www.gtk.org/api/2.6/gtk/GtkWidget.html#GtkWidget-drag-data-received).

You must know these values in order to do something in your CLisp client
program. For example, in order to handle the dropped object, you must know which
object has been dropped; this is passed in the field 'userdata'.

The GTK-server currently knows how to retrieve the first 4 values, as follows:

gtk_server_callback_value 0

This will retrieve the first value, which in case of a "drag-data-received" is
the widget which received the signal. The argument '1' points to the drag
context (e.g. 'gtk_server_callback_value 1'), the value '2' points to the
x-coordinate and '3' points to the y-coordinate of the actual drop.

Unfortunaly, with the current release (2.0.2) it is not possible to get the last
4 values.

But this is easy to implement. The next release (2.0.3) will contain this
functionality. If all values of a "drag-data-received" can be retrieved, then it
should be possible to use DnD with the GTK-server and CLisp.

Br,
Peter


Citeren Philippe Lorin <palpalpalpal@xxxxxxxxx>:

> I'm trying to implement drag'n'drop using GTK-Server with CLisp. I
> have not much experience with GTK so feel free to point any mistakes,
> or any interesting document I may have missed.
>
> From what I've read, having callbacks for different signals is pretty
> much required for drag'n'drop. Also, you need to add callbacks to
> specific widgets, not just to every widget of some type (I think that
> GTK-server adds one callback at the widget's creation, depending on
> the GTK function called, am I right?).
>
> Now I can't see how to do this with GTK-server. I was happy with the
> default .cfg file until now; I looked into that but it seems that the
> documentation does not mention that it is possible to either 1) name
> several signals when describing an API function, 2) create a GCallback
> to pass to g_signal_connect (I'm not sure how that would be possible
> across languages anyway) or 3) call some special function of
> GTK-Server to add a callback to an existing widget.
>
> However, looking at the sources of GTK-Server, I see this entry in the
> change log:
>
> * - BUILD 1:  . Major changes in callback functionality by ideas of mr.
> Joe Armstrong; hence new releasenumber
> *                             . Ability to add extra signals per widget, each 
> with own identifier
>
> ...which makes me wonder. I browsed the docs throughly but did not
> find much info about callbacks... Can anybody enlighten me?
>
>


-- 
http://www.gtk-server.org

Other related posts: