Solving the awful mess with callbacks ?




	Hi there !

I hope that my post is not off-topic, but I'd like to suggest you the
following point, because working with gtk callbacks is _really_ a pain.

You will easily understand that without a strict type-checking,
programmers easily make mistakes and loose their time, and of course you
don't want that. Furthermore, if there is an evident need to
change the parameters of a callback, it is obvious that the compiler
won't see anything, so you will have to check every call to signal_connect
& Co, and you also don't want to do it.

Now, what I propose, is to replace, for example, the "infamous"
code:

gtk_signal_connect( GTK_OBJECT( g_pDetail ),
                    "select_row",
                    GTK_SIGNAL_FUNC( CB_TreeSelectRow ),
                    (gpointer)data );

with:
gtk_signal_connect_new( GTK_OBJECT( g_pDetail ),
                        select_row,
                        CB_TreeSelectRow,
                        data );

where gtk_signal_connect_new would be a macro like :
#define gtk_signal_connect_new( object, signame, callback, data ) \
   gtk_signal_connect( object,                                    \
                       ##signame,                                 \
                       check_cb_#signame(callback),               \
                       (gpointer)data )

And where, in the appropriate gtk header, has been defined :

typedef void(*pcb_select_row)( GtkWidget *,
                               GtkCTreeNode *,
                               gint,
                               GdkEvent*,
                               gpointer );

inline GtkSignalFunc check_cb_selectrow( pcb_select_row pfunc )
{
  return (GtkSignalFunc)pfunc;
}

which should in fact we the expansion of a macro call like :
DECLARE_SIGNAL( select_row, GtkCTreeNode*, gint, GdkEvent* )

  This solution is of course fully compatible with all the current gtk
code. I'll not expose the source for the others calls to set callbacks,
because it'll be a bit boring...

The main problem, but I'm not sure, is that for the moment you possibly
could have to different callbacks declaration with the same signal name,
but I'm not sure that it is really true in the 1.1.8...

	Anyway, tell me, that would be nice :)

		Bye,

			Eric

 ("`-''-/").___..--''"`-._
  `6_ 6  )   `-.  (    ).`-.__.`) Eric Estievenart
  (_Y_.)'  ._   )  `._ `.``-..-'  VIA - Centrale Reseaux
 _..`--'_..-_/  /--'_.' ,'        eric@via.ecp.fr
(il),-''  (li),'  ((!.-'




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