[AD] Button callback function (was: Grabber - options dialog box)

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


(Just felt it would be more fitting to give this a new topic heading).

> > It'd be really nice if buttons could support callback functions, but
> > unfortunately, they don't (would it be ok to add one to Allegro? If
> > so, I think I have one laying around that could almost be merged in as
> > is).
>
> Can't you simply "derive" your custom button-with-callback widget from
> the stock button ?

Sure, but I thought this might be a useful addition, seeing how other 
dialog progs already have a callback function. On the other hand, people 
are already complaining about the GUI being bloated and useless.

Basically, I use

int d_button_callback(int msg, DIALOG *d, int c)
{
   int (*callback)(DIALOG *d) = d->dp3;

   if (msg == MSG_CLICK && callback)
      callback(d);
   return d_button_proc(msg, d, c);
}

(Not sure about the callback routine type declaration - I use a typedef). 
Right now, the return value of the callback function isn't used, but there 
also is a more serious problem. With this setup, the callback processes 
the message before the d_button_proc(), which in itself is trivial to fix, 
but it will also respond to immediately when the button is clicked, while 
it should wait until the mouse button is released.

(going into brainstorm mode)

Obviously, modifying the way the d_button_proc() works by adding a 
callback function could (would?) break backward compatibilty.

An alternative would be to duplicate the d_button_proc and have it call 
the callback only when the mouse is released, but duplicating code is 
obviously bad. In this instance, I'd go for moving the d_button_proc code 
to a new function with callback arguement and implement d_button_proc as a 
wrapper that screens the arguement. Also an ugly hack IMO.

Alternatively, would it be an idea to add a general callback field to the 
dialog structure after the dp3 field, so that all widgets could support 
callbacks?
Perhaps a new message, MSG_CALLBACK, could then also be added for good 
measure. Not sure if this would offer any advantage over directly calling 
the callback function, but it looks more structured to me :-)
Of course, this leaves open the question of what to do when a current 
widget already has a callback function.

Ok, I must now stop myself from rambling on any further.

-- 
Evert Glebbeek
e-mail: eglebbk@xxxxxxxxxx   ICQ: 48210348
www: http://www.science.uva.nl/~eglebbk/ 



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/