Re: Point button_press_event to the same function.



One option is to use sigc::bind to pass an extra parameter to your
handler function.  Something like this:

pWidget->signal_button_press_event().connect(sigc::bind(sigc::mem_fun(*this,
pFunc), widgetId);

And then your handler would be something like

bool MainWindow::onClickMenu(GdkEventButton *event, some_type id);

So you could pass a different ID for each widget you connected.  For
example, connect widget2 like so:

pWidget2->signal_button_press_event().connect(sigc::bind(sigc::mem_fun(*this,
pFunc), widgetId2);

Then you'd know that widget2 was clicked because when the handler is
called, it uses widgetId2 instead of widgetId as the second argument. 
Of course, you could pass anything as the extra parameter, such as a
pointer to the widget that was clicked, or whatever else you wanted.

If you haven't yet read it, I'd recommend reading through the tutorial
for libsigc++ (http://libsigc.sourceforge.net/libsigc2/docs/manual/html/index.html).
 It's pretty short, but it covers most things you'd want to do with
libsigc++.

Jonner


On 2/26/06, Carlos Garces <carlos garces gmail com> wrote:
> Hi.
>
> I what to point all the button_press_event of my menu to the same function
>
> Something like this
> pWidget->signal_button_press_event().connect(sigc::mem_fun(*this, pFunc));
>
> And the function:
>
> bool MainWindow::onClickMenu(GdkEventButton *event)
> {
>     printf ("Button %d\n", event->button);
> }
>
> But I can determine the button (EventBox) that I have clicked.
>
> ¿Any
> _______________________________________________
> gtkmm-list mailing list
> gtkmm-list gnome org
> http://mail.gnome.org/mailman/listinfo/gtkmm-list
>



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