[Gtk-sharp-list] Problem with drag and drop expand-on-hover for a TreeView

Michael Hutchinson m.j.hutchinson at gmail.com
Wed Mar 3 19:00:30 EST 2010


On Wed, Mar 3, 2010 at 4:57 PM, Matthew Pirocchi
<matthew.pirocchi at gmail.com> wrote:
> I have a handler that looks like this in my TreeView:
>
> [GLib.ConnectBefore]
> void HandleDragMotion (object o, DragMotionArgs args)
> {
>        TreePath path;
>        TreeViewDropPosition pos;
>        if (!GetDestRowAtPos (args.X, args.Y, out path, out pos))
>                return;
>
>        if (pos == TreeViewDropPosition.Before)
>                SetDragDestRow (path, TreeViewDropPosition.IntoOrBefore);
>        else if (pos == TreeViewDropPosition.After)
>                SetDragDestRow (path, TreeViewDropPosition.IntoOrAfter);
>
>        Gdk.Drag.Status (args.Context, args.Context.SuggestedAction, args.Time);
>
>        args.RetVal = true;
> }
>
> ...
>
> DragMotion += HandleDragMotion;
>
>
> Basically all it does is make sure you can only drop ON rows, not
> BETWEEN them. My problem is that this disables expand-on-hover for
> drag and drop. If I get rid of the last line (args.RetVal = true;),
> expand-on-hover is enabled again, but so is dropping between rows.
>
> Is there any way to achieve both of these things? Theoretically, I
> should be able to just implement the expand-on-hover myself, but I
> can't find any code for what it's supposed to look like. I tried using
> the ExpandHover property (turing it on on DragBegin, and off on
> DragEnd), but it only expands the first row that you hover over, then
> stops working.

The args.RetVal = true prevents the default handler being called.
Presumably the default handler is what handles the expand. So maybe
you could only suppress it in some cases...


[GLib.ConnectBefore]
void HandleDragMotion (object o, DragMotionArgs args)
{
       TreePath path;
       TreeViewDropPosition pos;
       if (!GetDestRowAtPos (args.X, args.Y, out path, out pos))
               return;

       TreeViewDropPosition overrideDrop;
       if (pos == TreeViewDropPosition.Before) {
               overrideDrop = TreeViewDropPosition.IntoOrBefore;
        } else if (pos == TreeViewDropPosition.After) {
               overrideDrop = TreeViewDropPosition.IntoOrAfter;
        } else {
               //it's an "Into" action so fall though to the default handler
               return;
        }

        SetDragDestRow (path, overrideDrop);
        Gdk.Drag.Status (args.Context, args.Context.SuggestedAction, args.Time);
        args.RetVal = true;
}

-- 
Michael Hutchinson
http://mjhutchinson.com


More information about the Gtk-sharp-list mailing list