Re: typecasting -- GtkItemFactoryEntry->callback_action



Actually, isn't the integer after the callback simply a numerical
reference to the type of callback function you want that item to
implement.


struct GtkItemFactoryEntry
{
  gchar *path;
  gchar *accelerator;   
  GtkItemFactoryCallback callback;
  guint callback_action;                <--------------------- int 

/* possible values for *item_type:
   * NULL-> "<Item>"
   * ""-> "<Item>"
   * "<Title>"-> create a title item
   * "<Item>"-> create a simple item
   * "<CheckItem>"-> create a check item
   * "<ToggleItem>"-> create a toggle item
   * "<RadioItem>"-> create a radio item
   * <path>-> path of a radio item to link against
   * "<Separator>"-> create a separator
   * "<Branch>"-> create an item to hold sub items
   * "<LastBranch>"-> create a right justified item to hold sub items
   */
  gchar *item_type;
};


void        (*GtkItemFactoryCallback)       ();
void        (*GtkItemFactoryCallback1)      (gpointer callback_data,
                                             guint callback_action,
                                             GtkWidget *widget);
void        (*GtkItemFactoryCallback2)      (GtkWidget *widget,
                                             gpointer callback_data,
                                             guint callback_action);


-john

On Thu, Aug 09, 2001 at 08:04:23PM -0400, Russell Francis wrote:
I am using ItemFactory to build a menu system and it is working great, I
just have a question about the "proper" way to do something?

I wish for the activated menu item to call a function with a pointer
as a variable not a guint like the ItemFactory structure wants.  

void function(GtkWidget *widget, gpointer data);    NOT
void function(GtkWidget *widget, guint data);

The GtkItemFactoryEntry->callback_action is a guint so I have been
typecasting a gpointer to guint when initializing the GtkItemFactoryEntry
and then typecasting back to gpointer in the callback function.  This is
working because (void *) and guint are the same size. I can't help but
think there is a better [and less likly to break :-] way to do this. 

Does anyone have any suggestions?  I am not subscribed to the list so
please respond to this e-mail address.

Thanks in advance,
Russell Francis 


_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list




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