tags:

views:

32

answers:

2

I'm writing a plugin that's modifying an existing UI. One thing I want to do is change what an existing menu item does.

This is all using the Gtk library.

The menu item (a GtkItem) is created from a GtkItemFactoryEntry (which is out of my control), and has its current behaviour defined by the callback in the GtkItemFactoryEntry.

I can get handle on the menu item using gtk_item_factory_get_widget() and attach further actions to the menu item using gtk_signal_connect(), but I can't seem to disconnect the original callback using gtk_signal_disconnect() or gtk_signal_disconnect_by_func().

Is there any way I can remove or replace the original callback?

A: 

g_signal_handlers_disconnect_matched() offers more options with which to match the callback you wish to disconnect.

ptomato
Unfortunately, I'm stuck with a legacy library, so this isn't an option. Also, since `gtk_item_factory_create_item` wraps the callback I give with a different callback (I read the source), looking up by callback won't work.
rampion
+1  A: 

So the hack I came up with was that, since signal handlers are id'ed by a one-up counter, and I get a handler id for the callback I want to attach with gtk_signal_connect() to just run gtk_signal_disconnect() on every handler id from zero to one less than my new handler id.

It's ugly, but it works. And since no other signals are hung on the item, it doesn't break anything.

rampion