Re: Dynamic Context Popup menus(ARGHHHH!!!)



On Fri, 18 Aug 2000, Kristopher Kycia wrote:

> Hello all,
> 
> How do you display a dynamic context popup menu?  I have a GtkCList with
> columns...  I want to be able to click on the column and have a context
> menu appear.  I need to use a event box for each column and the call a
> function display_popup_menu(gint column).  My problem is that whenever I
> get into one of the signal handlers... the column is ALWAYS invalid.  3
> Developers have looked at this code and nobody understand why this does
> NOT work!!!
> 
> Sample code:
> 
> GtkObject create_popup_menu(gint column)
> { // Create my context menu
> ...
>   // Attach signal handlers
>   gtk_signal_connect (GTK_OBJECT (sort_ascending1), "activate",
>                       GTK_SIGNAL_FUNC (on_sort_ascending1_activate),
>                       &column);

  You are taking the address of some value on the stack. Change previous line
to (and see the fix for on_sort_ascending1_activate below)
		  GINT_TO_POINTER(column));

> ...
>   return popupmenu;
> }
> 
> gboolean
> display_popup_menu                    (GtkWidget      *widget,
>                                        GdkEventButton *event,
>                                        gint           column)
> {
>   mPopupMenu = create_popup_menu(column);
>   gtk_menu_popup(GTK_MENU (mPopupMenu), NULL, NULL, NULL, NULL,
>                  event->button, event->time);
> }
> 
> gboolean
> on_eventbox1_button_press_event        (GtkWidget       *widget,
>                                         GdkEventButton  *event,
>                                         gpointer         user_data)
> {
>   return display_popup_menu(widget, event, 0);
> }
> 
> // gpointer = void *
> void
> on_sort_ascending1_activate            (GtkMenuItem     *menuitem,
>                                         gpointer         user_data)
> {
>   gint column;
> cout << "IN SORT ASCENDING CODE..." << endl;
>   // Sort the column... 
>   column = *((gint *) user_data); // <---  THIS NEVER WORKS!!! ALWAYS

  Previous line should become 

    column = GPOINTER_TO_INT(user_data);

> RETURNS SOME HUGE NUMBER! WHY?
> }
> 
> I hope somebody can help...  Sincerely,


 Cheers to you and three developers :)
 
> Kristopher Kycia

 Best regards,
  -Vlad






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