Re: [gtk-list] using a callback as a normal function



Aaron Walker wrote:
> 
> Hello,
> 
> Is it possible to use a callback also as a normal function?
> For example, I have a program that can either open files from a
> FileSelection dialog or from the command line.  Instead of having two
> separate functions for each, I want to have just one universal function:
> 
> void file_open(GtkWidget *widget, gint method)
> {
>         if(method == 1)
>             /* do this if it is called from the cmd line */
>         else if(method == 2)
>             /* do this if it is called from the FileSelection */
> }

If you are going to wrap the code up in an IF statement like this,
I don't see what advantage having one function will gain you.

> Now say I want to use this function as a callback for a menu item:
> 
> static GtkItemFactoryEntry menu_items[] =
> {
>      {"/_File", NULL, NULL, 0, "<Branch>"},
>      {"/File/_New", "<control>N", NULL, 0, NULL},
>      {"/File/_Open", "<control>O", file_open, 0, NULL},
>      ....
> };
> 
> how do I pass arguments to this?

I'd create file_open function(s) that could be used by the callback
or the command line processing, and not try to save on
'function name' space. The code tends to get ugly when you start
to do that (usually appears as excessive 'IF' statements everywhere).



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