Re: Dynamic Context Popup menus(ARGHHHH!!!)
- From: Darin Fisher <dfisher jagger me berkeley edu>
- To: Kristopher Kycia <kkycia hydrosoftenergie com>
- Cc: gtk-list gnome org
- Subject: Re: Dynamic Context Popup menus(ARGHHHH!!!)
- Date: Sat, 19 Aug 2000 14:28:14 -0500
The problem is with your gtk_signal_connect() call. You pass the
address
of a _temporary_ variable as the user_data parameter. I think what you
should really be doing is this:
gtk_signal_connect (GTK_OBJECT (sort_ascending1), "activate",
GTK_SIGNAL_FUNC (on_sort_ascending1_activate),
GINT_TO_POINTER (column));
Then in your handling of this signal:
void
on_sort_ascending1_activate (GtkMenuItem *menuitem,
gpointer user_data)
{
gint column;
cout << "IN SORT ASCENDING CODE..." << endl;
// Sort the column...
column = GPOINTER_TO_INT (user_data);
}
Darin
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);
> ...
> 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
> RETURNS SOME HUGE NUMBER! WHY?
> }
>
> I hope somebody can help... Sincerely,
>
> Kristopher Kycia
>
> _______________________________________________
> gtk-list mailing list
> gtk-list@gnome.org
> http://mail.gnome.org/mailman/listinfo/gtk-list
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]