different callbacks for left and right button using "button_press_event"



Hi,

First of all this is quite I long question, just put it in your Trahs folder
if you don't have time to read it :)))

Next, my problem.. for days.. :)

I want to connect two different callbacks (_callback and _btn3callback) to a
button, one for the left button and another for the right one.

I'm using C++ and GTK+. Please don't tell me to use gtk--. It's to late ;)
(You can see part of my classes specifications at the end of this mail)

When I connect the callback in my void ParameterButton::CreateParameter()
this way, it works fine for the left button:

    gtk_signal_connect (GTK_OBJECT (_button), "clicked",
   GTK_SIGNAL_FUNC(_callback), (gpointer) _calldata);


The problem is i want to connect the right button also. Therefore I've
written this callback, connected to  "button_press_event":


void ParameterButton::CB_Button(GtkWidget* widget, GdkEventButton* event,
gpointer cd)
{
  ParameterButton * pb = (ParameterButton *) cd;
  switch (event->button) {
  case 1:
    g_print("CB_Button, left button\n");
    if(pb->_callback != NULL) {
      void (*pf) (gpointer) = (void (*) (gpointer)) pb->_callback;
 pf(pb->_calldata);
    }
    break;
    case 3:
    g_print("CB_Button, right button\n");
    if(pb->_btn3callback != NULL){
      void (*pf) (gpointer) = (void (*) (gpointer)) pb->_btn3callback;
      pf(pb->_btn3data);
    }
    break;
    }
} //ParameterButton::CB_Button()

This is suppose to call my _callback for the left button and my
_btn3callback for the right one.

I've used

    gtk_signal_connect (GTK_OBJECT (_button), "button_press_event",
   GTK_SIGNAL_FUNC(CB_Button), (gpointer) this);

in my void ParameterButton::CreateParameter() function, but the program
breaks.

Using gdb I get this output:

Program received signal SIGSEGV, Segmentation fault.
0x8055fae in ParameterKernel::FixVisible ()
(gdb) bt
#0  0x8055fae in ParameterKernel::FixVisible ()
#1  0x804dcf9 in cb_xpm_button ()
#2  0x804f6e1 in ParameterButton::CB_Button ()
#3  0x400ae9ff in gtk_marshal_BOOL__POINTER () at gtkmarshal.c:124
#4  0x400dfce8 in gtk_handlers_run (handlers=0x808d080, signal=0xbffff358,
    object=0x808edb8, params=0xbffff3ac, after=0) at gtksignal.c:1917
#5  0x400df0bf in gtk_signal_real_emit (object=0x808edb8, signal_id=20,
    params=0xbffff3ac) at gtksignal.c:1477
#6  0x400dd017 in gtk_signal_emit () at gtksignal.c:234
#7  0x4011596c in gtk_widget_event () at gtkwidget.c:2707
#8  0x400ae955 in gtk_propagate_event () at gtkmain.c:1270
#9  0x400ada4f in gtk_main_do_event () at gtkmain.c:807
#10 0x40160a34 in gdk_event_dispatch (source_data=0x0,
current_time=0xbffff7a4,
    user_data=0x0) at gdkevents.c:2129
#11 0x40191c06 in g_main_dispatch (dispatch_time=0xbffff7a4) at gmain.c:656
#12 0x40192233 in g_main_iterate (block=1, dispatch=1) at gmain.c:877
#13 0x401923fc in g_main_run () at gmain.c:884
#14 0x400ad30c in gtk_main () at gtkmain.c:807
#15 0x804e682 in main ()
#16 0x4035da8e in __libc_start_main () at ../sysdeps/generic/libc-start.c:93

I've also noticed that using

    gtk_signal_connect (GTK_OBJECT (_button), "button_press_event",
   GTK_SIGNAL_FUNC(_callback), (gpointer) _calldata);

returns me no error in FixVisible but in a function used after it:

Program received signal SIGSEGV, Segmentation fault.
0x40112403 in gtk_widget_hide () at gtkwidget.c:1468
1468    gtkwidget.c: File not found
(gdb) bt
#0  0x40112403 in gtk_widget_hide () at gtkwidget.c:1468
#1  0x80514e6 in ParameterFloat::UnManage ()
#2  0x804dd08 in cb_xpm_button ()

Not only this... if I modify my callback this way:

void ParameterButton::CB_Button(GtkWidget* widget, gpointer cd)
{
  ParameterButton * pb = (ParameterButton *) cd;
  g_print("CB_Button, left button\n");
  if(pb->_callback != NULL) {
    void (*pf) (gpointer) = (void (*) (gpointer)) pb->_callback;
 pf(pb->_calldata);
  }
} //ParameterButton::CB_Button()

and connect it so:
    gtk_signal_connect (GTK_OBJECT (_button), "clicked",
   GTK_SIGNAL_FUNC(CB_Button), (gpointer) this);

I get the Segmentation fault in another different function, which has been
working fine since now (and i haven't make no changes to it, i promise :))

Program received signal SIGSEGV, Segmentation fault.
0x8055f26 in ParameterKernel::Visible ()
(gdb) bt
#0  0x8055f26 in ParameterKernel::Visible ()
#1  0x804dcd2 in cb_xpm_button ()
#2  0x804f6be in ParameterButton::CB_Button ()
#3  0x400aee93 in gtk_marshal_NONE__NONE () at gtkmarshal.c:124
#4  0x400dfce8 in gtk_handlers_run (handlers=0x808d040, signal=0xbfffebe8,
    object=0x808ed78, params=0xbfffec3c, after=0) at gtksignal.c:1917
#5  0x400df0bf in gtk_signal_real_emit (object=0x808ed78, signal_id=63,
    params=0xbfffec3c) at gtksignal.c:1477
#6  0x400dd017 in gtk_signal_emit () at gtksignal.c:234

Anyone got an idea what's going wrong?

Thanks for all


--------------------------------------------------
Here you can see part of my classes
--------------------------------------------------
class ParameterKernel
{

 protected:
  GtkWidget* _parent;

  GtkWidget* _widget;

  gboolean _visible;
  gboolean _value_changed;

  gpointer _callback;
  gpointer _calldata;
...
 public:
  gboolean Visible() { return _visible; }
  void FixVisible(gboolean visible) {
 g_print("This g_print is shown\n");
 _visible = visible;
 g_print("BUT THIS ONE ISN'T\n");
 }
}

-·-

class ParameterButton: public ParameterKernel
{
  GtkWidget*  _box;

  GtkWidget*  _button;

  gpointer    _btn3callback;
  gpointer    _btn3data;

 ....

}





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