-2

I am experimenting a bit with monodevelop/c#/gdk and I was able to create a window with a DrawingArea correctly handling the expose event.

The mouse down events however are not dispatched and I don't understand why. The delegates have been set up in the code autogenerated by the gui designer:

this.da.ExposeEvent += new global::Gtk.ExposeEventHandler (this.OnDAExposeEvent);
this.da.ButtonPressEvent += new global::Gtk.ButtonPressEventHandler (this.OnDAButtonPressEvent);
this.da.MotionNotifyEvent += new global::Gtk.MotionNotifyEventHandler (this.OnDAMotionNotifyEvent);

and this is my initialization code:

public MainWindow () : base (Gtk.WindowType.Toplevel)
    {
        Build ();
        Gdk.Color col = new Gdk.Color();
        col.Red = col.Green = col.Blue = 0x8888;
        da.ModifyBg(StateType.Normal, col);
        var p = "wr/wn/wb/wq/wk/wp/br/bn/bb/bq/bk/bp".Split ('/');
        for (int i = 0; i < p.Length; i++) {
            pieces[p[i]] = new ImageSurface("/home/agriffini/x/chessboard/i" + p [i] + ".png");
        }
        da.Events |= (Gdk.EventMask.ButtonPressMask
                      | Gdk.EventMask.ButtonReleaseMask
                      | Gdk.EventMask.KeyPressMask
                      | Gdk.EventMask.PointerMotionMask);
    }

however the handler function OnDAButtonPressEvent never gets called (checked by placing a breakpoint there).

What is the part that is missing?

6502
  • 112,025
  • 15
  • 165
  • 265
  • 1
    In my case I had a composite custom widget (a table that held a label and two butons with various levels of attachments). It would trigger on ButtonPressEvent when I pressed the Buttons. The signals didnt seem to be handled. I could only handle on Gdk.ExposeEvent. I believe this is because it was no longer not considered an individual widget/ For anyone that googles this – LFMekz Jan 05 '20 at 16:35

1 Answers1

0

Found the problem by looking at console output.

The issue is that event mask must be set before the widget is realized.

This means that when using monodevelop and the gui designer you must set event handlers using the gui in widget->properties->events because the autogenerated Build method will set the event mask at the proper time before realization.

Setting the event mask in the code before calling Build wouldn't work (widget have not been created yet); setting the mask after that call wouldn't work either (they've been already realized).

6502
  • 112,025
  • 15
  • 165
  • 265