Click to See Complete Forum and Search --> : grr... stuck with gtkmm double click issue.


Energon
05-20-2002, 11:50 PM
Okay, I've got a Gtk::Tree object in my GUI. And I want to know when an item is double clicked, so I do this:


item = manage(new Gtk::TreeItem(info.description));
item->button_press_event.connect(slot(itemButtonHandler ));


And this is the handler:


int itemButtonHandler(GdkEventButton* button)
{
switch(button->type)
{
case GDK_BUTTON_PRESS:
break;
case GDK_2BUTTON_PRESS:
switch(button->button)
{
case 1:
std::cout << "window - " << button->window->user_data << std::endl;
break;
default:
return false;
}
return true;
case GDK_3BUTTON_PRESS:
break;
default:
return false;
}
return false;
}


Which is absolutely grand... except that in the handler, I have no way of knowing which item was double clicked. The GdkEventButton object has a window pointer, but it's for the GdkWindow and not the Gtk widget (ie, the pointers don't match up). Is there a way I can overload the connect? I know it's possible, but I though that required me to pass the parameters, and I don't have the event parameter to pass...

Does anyone know of a way to get done what I'm trying to do? Thanks in advance, I really really appreciate it.

Stuka
05-21-2002, 10:16 AM
Per the gtkmm docs (http://gtkmm.sourceforge.net/tutorial/sec-tree-widgets.html), it looks like you want the functions set_selection_mode(GtkSelectionMode mode ) and SelectionList& selection()
Take a look at that page, under those functions - it tells you how to get at the selected item.

Energon
05-21-2002, 01:21 PM
But that's the problem, I don't have access to the tree or the item. I've only got the GdkEventButton and nothing else. That's why I need to see if I can force it to pass the item or the tree somehow.

Stuka
05-21-2002, 02:21 PM
Well, the GdkWindow class does have a get_children() method which returns a GList* - maybe you could find the tree there? (btw, this is just from huntin' the docs...I've never done this! ;))

Energon
05-21-2002, 08:17 PM
*sigh*. Nope. I print each item's address as I add them to the tree, and then I print the window and all of its children (there's only one) from the list and there all different addresses.Am I doing something wrong maybe?

I know from browsing gtkmm examples that you can use bind<>() to connect to functions with arguments, but I don't know if it's possible to use that when the function you're overloading already takes an argument. I think I'll go read up on what exactly that bind does and see if I can maybe use it even still.

Thanks for looking, I appreciate it. I think it may just be me doing something wrong.

Stuka
05-22-2002, 10:48 AM
Shouldn't the Tree be one of the window's children? Not a tree item, but the tree itself? If so, that would give you the tree, and then use the methods for it to get what you need... Sorry I couldn't be more help, I just ain't familiar with gtkmm.

Energon
05-22-2002, 06:00 PM
I appreciate the help. I haven't found the answer yet, but I know there has to be a way. Thanks for taking a look.

Energon
05-22-2002, 07:16 PM
Ha! Now I feel really stupid. I was hunting through some gtkmm messages on their mail list, and I actually found an example of exactly what I want. So what did they do? Made a new class that inherited the TreeItem class, which then has the ability to know when it as a single unit is clicked...

Again, thanks for the help, I appreciate it.

Stuka
05-23-2002, 09:44 AM
Glad to hear you solved it!