Re: [gtk-list] Re: gtk-- tutorial?



Kevin Handy wrote:

> I have a quetion on it. How do you attach commands into the menufactory
> under gtk--? Do they have to be non-class functions or does it handle
> using class functions (which would require passing/using 'this' somehow).

 You can define the static array just like the example in GTK tutorial:

static GtkMenuEntry _atMenuItems[] =
{
  {"<Main>/File/Open", 0, open_callback, 0},
  {"<Main>/File/Exit", 0, exit_callback, 0}
};

static size_t _zMenuItems = sizeof (_atMenuItems) /
                            sizeof (_atMenuItems[0]);

 Where open_callback and exit_callback are normal C functions, that get
a pointer to an object in a user_data parameter:

void open_callback (GtkWidget* ptWIDGET, gpointer pDATA)
{

  SomeClass*   ptObj = (SomeClass*) pDATA;
  
  ptObj->open();
  
}  /* open_callback() */

 Then, before creating this menu, fill the callback_data with the
pointer to the right class:

for (size_t J = 0; ( J < _zMenuItems ) ;J++)
{
  _atMenuItems[J].callback_data = (gpointer) this;
}
  
 I'm using this to add the same menu to several instances of a window
class, and it is working quite well.

 I think the GTK-- people are working in a better interface for menu
factories (at least it is in the TODO list).

 Angel.



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