[gtkada] Disabling Tree Collapse-Expand signal during double- click

Wells, Larisa lwells at dcscorp.com
Fri Apr 6 20:08:16 CEST 2001


Thank you both for your responses, but I am having trouble with both
solutions.  And after further work, I think, as we say over on this side of
the pond, "you can't get there from here!"

Jean-Etiennne:  I actually already had the function callback returning a
true boolean value when I started, so that didn't seem to work for me.
Could you point me in the direction of some documentation on the usage of
the return variable in callbacks?  This would help me out in the future. I
had pretty much just blindly used an example, as the comments in
gtk-handlers didn't seem to address this.

Emmanuel:  Using "tree_select_row" I was getting the error message
"Gtk-WARNING **: gtk_singal_emit_stop(): no current emission (92) for object
`GtkCtree' ", so instead I stopped the "button_press_event", and that
certainly does work to stop the default actions.

The reason I imply that it is not solvable, is that the "Button_Press" event
(single click) occurs BEFORE the "2Button_Press" (in fact twice, as you
might expect).  So there is no way for me to distinguish between a user's
request to collapse/expand the tree versus activating the node.  In most
applications, that's probably not a problem since it is most likely a leaf
that would be activated (such as in a folder/file tree). 

Here is what my callback looks like with the added Emit_Stop_By_Name which
works beautifully, except that the expand/collapse features are not longer
available.

   package Ctree_Return_Callback is new
      Gtk.Handlers.Return_Callback
         (Widget_Type => Gtk.Ctree.Gtk_Ctree_Record, Return_Type =>
Boolean);
   <...>
   Ctree_Return_Callback.Connect
     (Widget => Ctree,
      Name   => "button_press_event",
      Marsh  => Ctree_Return_Callback.To_Marshaller
                (On_Double_Click_CB'Access));
   <...>
 ------------------------------
 -- On_Double_Click_CB --
 ------------------------------
   function On_Double_Click_CB
     (Object : access Gtk.Ctree.Gtk_Ctree_Record'Class;
      Event  : Gdk.Event.Gdk_Event) return Boolean is

      Selected_Row    : Glib.Guint;
      Selected_Node   : Gtk.Ctree.Gtk_Ctree_Node;
   begin
 --
 -- Check for a double-click
 --
      if Gdk.Event.Get_Event_Type (Event) = Gdk.Types.Gdk_2button_Press then
 
         Selected_Row  := Glib.Guint(Gtk.Ctree.Get_Focus_Row (Object));
         Selected_Node := Gtk.Ctree.Node_Nth (Object, Selected_Row); 

         Activate_Node (Selected_Node); -- application operation
      end if;
 --
 -- Stop the select row signal, which would cause tree collapse/expand
 --
      Gtk.Handlers.Emit_Stop_By_Name (Object, "button_press_event");
      return True;

   end On_Double_Click;

Any further ideas would be appreciated.  Thanks again for your help.

-Larisa
      
-----Original Message-----
From: Emmanuel Briot [mailto:briot at gnat.com]
Sent: Friday, April 06, 2001 5:08 AM
To: gtkada at gtkada.eu.org
Subject: Re: [gtkada] Disabling Tree Collapse-Expand signal during
double-click


Jean-Etienne Doucet writes:
 > | I am using a double click on a file tree node to spawn an editing
session on
 > | that file.  Does anyone know how I can effectively keep the tree node
from
 > | collapsing/expanding on a Gdk_2button_Press event?  I am accomplishing
that
 > | now by using Toggle_Expansion in my double-click callback, but the
method is
 > | kind of ugly and it flickers as it quickly expands and collapses.  I
need to
 > | keep the tree_expand and tree_collapse signal functionality for a
selection
 > | (single-click).
 > | 
 > 
 > You should try a (function) callback that returns the boolean value True;
 > this keeps Gtk from executing its usual duty (e.g. collapse/expand) after
 > execution of your callback.


You might also want to simply block the propagation of the signal in your
callback by using a call similar to:

   Gtk.Handlers.Emit_Stop_By_Name (My_Tree, "select_row");

This is in fact a more general technics, that is always applicable, whereas
the
function callback suggested by Jean-Etienne will only apply for some
specific
signals.

Emmanuel

_______________________________________________
gtkada mailing list
gtkada at gtkada.eu.org
http://gtkada.eu.org/mailman/listinfo/gtkada




More information about the gtkada mailing list