Re: Equivalent to gtk_drag_get_source_widget()?



Chris Vine wrote:
The drag_data_received signal in GTK+ will pass the target widget as its first paramater. The gtkmm equivalent does not, but there is a good reason for that, namely that the receiving object knows what it is. The Gtk::Widget::on_drag_data_received() method will be called on the object which received the drag.

True.

You should not really need to know either what object the data was dragged from either.

I do, because I need some form of this check:

if (source == target)
   don't do anything;
else
   issue some operation

This is to prevent the user from issueing an operation on the same widget when it's only allowed from one widget to another.

My solution right now is to do as follows:
I have a member variable (an enum type) in my window class which identifies the source widget of the last drag. To the drag_begin signal which is always fired by the source widget I bind a value of this enum typ which identifies the source widget. When the signal handler is entered, I assign the member variable this value. I also bind such a value to a signal which is fired by the receiving widget, and can thereby check in its signal handler if this value equal the value which was stored in the member variable after the last drag.

> First, it may not be in the same address space as the process
receiving the drag (gtk_drag_get_source_widget() will return NULL in that case, and where it is in the same address space you can store it in a variable assessible to both widgets if you really need it). Secondly, if you want to notify the source object that the drag has been completed there are signals available for that, via gtk_drag_finish() (or the gtkmm equivalent).

Now that you name it, my "solution" might actually not work when someone drags something from another application into mine. I will have to look into that further.

Best regards,
Matthias Kaeppler





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