RE: Correct signal handler to overload in a treeview to STOP the selection from changing



thanks for the answer Bob, in my code I do not propagage the event upon
failure,
I had thought this would do the trick and not allow the change, but I
think that
the change has already occurred in the on_cursor_changed event. I need
to trap
a signal that is saying something like the currently selected branch is
about to
loose focus?? Just can't find one.

Thanks for the feedback! 

-----Original Message-----
From: Bob Caryl [mailto:bob fis-cal com] 
Sent: Friday, February 03, 2006 6:41 AM
To: Huston, Bob
Cc: gtkmm-list gnome org
Subject: Re: Correct signal handler to overload in a treeview to STOP
the selection from changing

Huston, Bob wrote:

> I have a treeview derived class, in which when a branch in the tree
is 
> displayed I display a
> notebook derived class showing many GUI controls for information 
> gathering. When
> the user selects a different branch in the tree, I save off the 
> currently displayed notebook information
> and display a new notebook for the new branch that is selected.
>  
> I accomplish this by overloading the on_cursor_changed signal handler

> in the tree view class.
>  
> The issue I am having is that when I am switching notebooks being 
> displayed I validate any and all
> information on the current notebook, if the information is valid, I 
> want to warn the user via and keep the
> tree from switching views. 
>  
> I am not switching the notebooks when this occurs, however the tree
is 
> still switching which branch is selected.
>  
> My code basically is this:
>  
> void CMyTreeView::on_cursor_changed()
> {
>     // save/validate the current notebook:
>     if ( !SaveCurrentNotebook())
>         return;
>  
>     // put up the new notebook
>     .....
>     return Gtk::TreeView::on_cursor_changed();
> }
>  
> I need to know how to either return from this handler so that the 
> selection doesn't change, or a different handler
> to overload to do my processing prior to the selection change occurs.

> I thought that by not allowing the
> parent tree view class's version of on_cursor_changed to be called 
> that this would happen.
>  
> --Bob
>  
>
>----------------------------------------------------------------------
--
>
>_______________________________________________
>gtkmm-list mailing list
>gtkmm-list gnome org
>http://mail.gnome.org/mailman/listinfo/gtkmm-list
>  
>

Hey Bob,

I could not find a signal directly relating to the Gtk::TreeView to 
which you could connect in order to prevent the TreeView from changing 
rows in response to a mouse click (and remember, a row can also be 
changed with the arrow keys on the keyboard).  However, you might 
consider connecting to "Gtk::Main::signal_key_snooper" and looking for
a 
"GDK_BUTTON_PRESS" event (see GdkEventButton 
http://www.gtk.org/api/2.6/gdk/gdk-Event-Structures.html#GdkEventButton

<http://www.gtk.org/api/2.6/gdk/gdk-Event-Structures.html#GdkEventButto
n>).  
You can compare the GdkWindow pointer to the GdkWindow corresponding to

your Gtk::TreeView in your connected callback slot to determine whether

or not to allow the cursor to change depending on the validation of
your 
controls in your notebook page.

Connection code looks like this:

Gtk::Main::signal_key_snooper().connect(sigc::mem_fun(*this,&<your
class 
name here>::<your callback slot name here>));

I don't know if this will actually work, but I do know that you can 
choose to go ahead a propagate the event or not in your callback.  If 
you do propagate it, you must be sure to prevent catching that event a 
second (and third and fourth and so forth) time.

Hope this might help.

Bob Caryl




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