Fwd: How to unselect a row in the TreeView, when it is selected secondtime?



Forgot to include the list on this reply.

---------- Forwarded message ----------
From: Paul Davis <pjdavis engineering uiowa edu>
Date: Apr 24, 2007 5:19 AM
Subject: Re: How to unselect a row in the TreeView, when it is
selected secondtime?
To: SaiKamesh Rathinasabapathy <rsaikamesh gmail com>


Ok, so I've been playing with this for awhile now and I've come up
with something thats awfully hackish.

Ideally, the behavior would be, after every user action, all affected
rows would be toggled.

You might be able to accomplish this still by leveraging the
Gtk::TreeSelection::set_select_function()

Basically, I would just keep a set of paths for every call to the
select function, then in the selection_changed() call back, you would
go through and do the set math to figure out what needs to be
de/selected.

An extremely more hackish way to do this with quite a few less lines
of code is the following:

void
Foo::on_button_press( GdkEventButton* ev )
{
  if( ev->button == 1 )
  {
     ev->state |= Gdk::CONTROL_MASK ;
  }
}

//Notice the use of connect_notify() again.  This causes the function
to be executed
//prior to the default signal handlers and virtual methods.
void
Foo::setup()
{
   tree_view->signal_button_press().connect_notify( *this,
&Foo::on_button_press ) ) ;
}

Basically, what you're doing is modifying all left mouse clicks to the
tree view to act as if the Control key is held down.  This prevents
the simultaneous selection of multiple rows by holding the shift key
though.  And  you'll also run into issues if you want to have rows
that are reorderable.

I limited this behavior to the left mouse button ( all other buttons
behave normally ) because I also have a popup menu for the TreeView I
was working with.

I was thinking about adding this functionality to my program, but
after playing with it for a couple hours I decided its not really
worth it.  The proper way to do this would be to write a patch for gtk
and add a new selection mode.

HTH,
Paul Davis

On 4/24/07, Paul Davis <pjdavis engineering uiowa edu> wrote:
Update:

This sure isn't working.  I'll get back when I get it figured out a bit better.

Paul

On 4/24/07, Paul Davis <pjdavis engineering uiowa edu> wrote:
> SaiKamesh,
>
> You're gonna have to track the selection manually.  This will require
> you to connect to the signal_button_press.
>
> The basic outline will basically be something like:
>
> //Some necessary values.
> Gtk::TreeView* tree_view = ... ;
> Glib::RefPtr< Gtk::TreeSelection > selection = .... ;
>
> //Notice the connect_notify() as opposed to connect()
> tree_view->signal_button_press_event().connect_notify( ... )
>
> void
> on_button_press( GdkEventButton* ev )
> {
>       Gtk::TreeModel::Path p ;
>       Gtk::TreeViewColumn* tvc ;
>       int cx ;
>       int cy ;
>
>       if( ! tree_view->get_path_at_pos( ( int ) ev->x, ( int ) ev->y,
> p, tvc, cx, cy )
>      {
>          return ;
>      }
>
>       if( tree_selection->is_selected( p ) )
>      {
>          tree_selection->unselect( p ) ;
>       }
>       else
>       {
>           tree_selection->select( p ) ;
>       }
> }
>
> Should be pretty much it unless I'm forgetting something.
>
> Paul
>
> On 4/24/07, SaiKamesh Rathinasabapathy <rsaikamesh gmail com> wrote:
> > Hi,
> >
> > I have added a tree_view( Gtk::TreeView ) in a window.
> >
> > What I have to do is, if a row is selected at the first time, then it will
> > be highlighted. -> Actually we don't need to do anything for this. It will
> > automatically be highlighted.
> >
> > If the same row is clicked (or selected) at the second time, the row should
> > be unselected.
> >
> > if the same row is clicked (or selected) at the third time, then it sholud
> > again be highlighted.
> >
> > I tried to do the above several times. But I could not do it.  Please help
> > me out to do this!
> >
> > Thanks in advance!
> >
> > _______________________________________________
> > gtkmm-list mailing list
> > gtkmm-list gnome org
> > http://mail.gnome.org/mailman/listinfo/gtkmm-list
> >
> >
>




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