Re: FW: [gtkmm] drag and drop with multiple targets
- From: pks timing com
- To: gtkmm-list gnome org
- Subject: Re: FW: [gtkmm] drag and drop with multiple targets
- Date: Fri, 6 Feb 2004 01:47:11 -0700
I messed up replying to the mailing list ... here it is
Callum Prentice writes:
>
> in the example i have, the data is set in the event handler method using
> gtk_selection_data_set () but all widgets trigger the same method and (as far as i can tell)
> there is nothing passed in that allows me to differentiate between widgets.
that's were subclassing your widget and overriding the virtual functions
that correspond to the signal_drag_data_get() and signal_drag_data_received()
signals, that is on_drag_data_get() and on_drag_data_received() comes in ...
in on_drag_data_get() the this pointer will be the source widget,
and in on_drag_data_received() the this pointer will be target widget ...
if subclassing the widget you will have hundreds of still doesn't sound
appealing, and
> need to know which widget was dropped onto
is the only thing standing in your way, just bind the destination widget
using the signal system using SigC::bind(). Here is a really simple
example using signal_show() and signal_hide():
//-----------------------------------------------------------------------
#include <gtkmm.h>
#include <iostream>
using namespace std;
class Example : public Gtk::Window
{
public:
Example();
Gtk::VBox _vbox;
Gtk::Label *_lbls[5];
// neither the show signal, nor the hide signal usually
// provide any params ... but we'll bind a label (per
// signal handler connection) to the show signal
void OnLabelHide();
void OnLabelShow(Gtk::Label *lbl);
};
Example::Example()
: Gtk::Window(),
_vbox(false, 5)
{
for (int i = 0; i < 5; i++)
{
_lbls[i] = new Gtk::Label("foo");
_vbox.pack_start(*_lbls[i], false, false);
cout << "_lbls[" << i << "] = " << _lbls[i] << endl;
// attach the hide signal handler as always
_lbls[i]->signal_hide().connect(
SigC::slot(*this, &Example::OnLabelHide));
// as we attach the signal handler, we bind the label's
// address to the connection
_lbls[i]->signal_show().connect(
SigC::bind(SigC::slot(*this, &Example::OnLabelShow), _lbls[i]));
}
cout << endl;
add(_vbox);
show_all();
}
void
Example::OnLabelShow(Gtk::Label *lbl)
{
cout << "label " << lbl << " is being shown" << endl;
}
void
Example::OnLabelHide()
{
cout << "\tsome label is being hidden" << endl;
}
int
main(int argc, char *argv[])
{
Gtk::Main kit(argc, argv);
Example example;
kit.run(example);
return 0;
}
//--------------------------------------------------------------------
you can bind the destination widget address to the drag drop signals
in the same way:
*) make the parameter to be bound the last one in the signature
*) SigC::bind the parameters value
or subclass, and have the "this" pointer at your disposal ;)
hope this helps
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]