[Vala] Default signal handlers.



Dear all,

The default signal handler is a vfunc member in the object class
structure, invoked by GSignal  when the signal is emitted.
It is provided as the fourth parameter in g_signal_new.

Currently, this feature is not achievable with vala. I propose two
ways, without breaking the current vala syntax, to make use of this
feature:

(1) Via CCode attributes:
vfunc_name: specifies the cname of the default handler in the class
structure. (similar to vfunc_name in methods). default: null.
flags: a c constant, can be G_SIGNAL_RUN_LAST or G_SIGNAL_RUN_FIRST.
default: G_SIGNAL_RUN_LAST.

if vfunc_name is null, the fourth parameter is left 0. if not null,
the fourth parameter is filled with G_STRUCT_OFFSET(class,
vfunc_name).
flags is used to fill in the third parameter of g_signal_new.

I've made a patch and the example code for this approach in
http://bugzilla.gnome.org/show_bug.cgi?id=571685

(2) Hybrid: function bodies for signal, plus the CCode attribute flags.
instead of using an existing vfunc, vala declares a new vfunc for the
default signal handler, if there is a function body; if there is no
function body, no default handler is produced.

The flags attribute is used to determine when to invoke the default
handler as in (1).

class SomeClass {
  public void signal last(int para) {
    message("default for last");
  }
}
class SomeSubClass {
  public override void last(int para) {
    message("subclass default for last");
    base.last(para);
  }
}

The second approach looks more similar to GTK than the first one. But
making a patch for (2) is beyond my abilities.

Any comments on this topic?

Yu



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