Andrew E. Makeev wrote:
В Втр, 10/04/2007 в 15:02 -0400, Alan Ott пишет:
Hello,
So since the TreeView seems to be such a popular topic on this list, I
decided I'd throw some of my own TreeView questions in.
I want to make the items in the list "click on" and "click off" as
opposed to "click
on-but-also-remove-selection-from-the-rest-of-the-items." What I want is
the selection to act as though it were in SELECTION_MULTIPLE mode with
the control key held down during all the clicks. Of course without the
control key having to be held down all the time.
In Gtk::SelectionMode, we seem to have None, Single, Browse, Multiple,
and Extended. None of these seem to do what I'm looking for, and I can't
quite tell what the difference is between Multiple and Extended.
Then there's TreeSelection::on_select_function(). It seems to be in the
right direction, but I don't see how this function can help me. Maybe
I'm misunderstanding it. To use this function, I would want to return
true on the row that was clicked, and false on all other rows. The
problem is that the select function seems to get called for _every_ row
that's affected by a user interaction (click, keypress, etc), so I have
no way of knowing which row was the one clicked (because that's the
_only_ row that I want to change if I were to go this route).
So I'm kind of stumped here. I feel like there's probably something easy
that I've missed. Any help is appreciated.
You should go another way, I guess.
Connect to signal_button_press_event on Gtk::TreeView widget, then
manage selection by yourself. Don't forget to pass after = false.
Inside that callback you will have mouse coordinates, so, could
determine Gtk::TreePath, then just add or remove that from Selection
object, and return true from event handler.
Regards,
-andrew
Andrew,
Thanks for the help. This worked great. I had to add one other thing
though. I had to add a select function
(TreeSelection::set_select_function()) which disallowed the selecting
or unselecting of any list items except when my handler function is
active. If I don't do this, the items not clicked on still get
unselected because the click event is also handled by the TreeView
internally.
It's a little hacky to have to work around Gtk+ like this, but it works
well. This way I don't have to ship our delivered system (touch-screen
interface) with duct tape on the control key :)
Thanks,
Alan.
|