Re: [AD] Button callback function (was: Grabber - options dialog box) |
[ Thread Index |
Date Index
| More lists.liballeg.org/allegro-developers Archives
]
- To: Allegro Developers list <conductors@xxxxxxxxxx>
- Subject: Re: [AD] Button callback function (was: Grabber - options dialog box)
- From: Peter Wang <tjaden@xxxxxxxxxx>
- Date: Wed, 22 May 2002 11:33:31 +1000
On 2002-05-21, Evert Glebbeek <eglebbk@xxxxxxxxxx> wrote:
> >
> > Can't you simply "derive" your custom button-with-callback widget from
> > the stock button ?
...
> 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.
I use this (in AGUP):
int d_agtk_push_proc(int msg, DIALOG *d, int c)
{
int ret = D_O_K;
d->flags |= D_EXIT;
ret |= d_agtk_button_proc(msg, d, c);
if (ret & D_CLOSE) {
ret &= ~D_CLOSE;
REDRAW(d);
if (d->dp3)
ret |= ((int (*)(DIALOG *))d->dp3)(d);
}
return ret;
}
Seems a bit hackish now that I read it :-) It makes D_EXIT unusable
for that widget type, but I think D_EXIT was only useful for
d_button_proc because it didn't support callbacks. It would be easy
enough to remember the original D_EXIT setting and let it flow out the
return (I think).
> Obviously, modifying the way the d_button_proc() works by adding a
> callback function could (would?) break backward compatibilty.
Yes, because dp3 is then taken away from the user.