Re: callbacks on a CTree node



On Mon, 2002-06-24 at 18:10, Ronald Roth wrote:
Hello,

      I have a CTree in my app, and when the user clicks on an item in that
tree, I need it to do something.  How do I connect a signal handler to
it?  I tried using simply:

gtk_signal_connect(GTK_OBJECT(node), "clicked",
GTK_SIGNAL_FUNC(on_foldertree_item_clicked), NULL);

but then when the program gets here, it complains about the GTK_OBJECT()
cast, saying that "node" isn't an object.  I thought all gtk_widgets
were also gtk_objects?  in any case, how do I do this?  And is there a
way to set something like this up in Glade?


Ronald,

I assume you tried connecting the signal to a GtkCTreeNode which is a
structure that anchors a GList and is not a subclass of GtkObject.

What you want is to connect the "button-press-event" to the GtkCList or
GtkCTree instead. You'll then have to determine which mouse button was
pressed and if its the one you want then determine which row it clicked.

As an example, here is the signal handler I use that handles a right
mouse click on a GtkCList or GtkCTree in my app that gets the row data
in order to present a context popup menu.

gboolean on_view_button_press_event (GtkWidget *widget, GdkEventButton
*event, gpointer user_data)
{
    gint      row;
    gint      col;
    gint      selection_in_range;
    GtkCList *clist = GTK_CLIST (widget);

    selection_in_range = gtk_clist_get_selection_info (clist, (gint)
event->x, 
                                                       (gint) event->y,
&row, &col);
    
    if (selection_in_range && event->button == RIGHT_MOUSE_BUTTON)
    {
        object_handle_t handle;
            
        handle = GPOINTER_TO_UINT (gtk_clist_get_row_data (clist, row));

        gtk_clist_select_row (clist, row, col);

        display_action_popup_menu_for_handle (handle, event->button,
event->time, NULL, NULL);
    }

    return FALSE;
}

-- 
regards,

Luciano Chavez

lnx1138 us ibm com          
http://evms.sourceforge.net




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