Drag & Drop and CTree



  Hi,

I've made quite a few experiments with drag and drop operations on a
ctree,
which has already consumed more time than I thought :-)
Even if I've managed to do several things, it may be time for a few
questions now.
Hope it's the right list for that !

* Context and goal:

   Well, my needs are quite simple. I have a ctree with extended
selection mode. I like
the way you can select several rows by dragging the mouse. Much better
than hitting the
shift key altogether imho.
   Now, I want to be able to move a selection (single row, multiple
consecutive rows, groups of rows...)
in the tree.

* Problem:

   At first I tried to enable dnd with gtk_drag_source_set().
Well, it works. But then you HAVE to use the shift key to select
multiple rows.
I didn't feel comfortable with losing a great selection possibilty by
trying to add the drag feature.

   So I've gone through gtk's source code to understand what was
happening.
I've found two interesting things:
- multiple selection feature is broken by      gtk_object_set_data_full
(GTK_OBJECT (widget), "gtk-site-data",
    site, gtk_drag_source_site_destroy)   in   gtk_drag_source_set().
    I've not yet found the reason why.  By commenting this line
everything's fine, except you won't free memory allocated...
    Not very satisfying.
- gtk_drag_source_event_cb() is independent of the widget's type. Well,
it seems logical for me.
    But that brings two problems for me : first, it initiates the drag
as soon as mouse moves enough (it's based on Gdk events),
    so even if multiple selection were still possible (if not broken by
gtk_object_set_data_full) you couldn't select more than one
    row since it would initiate a drag; secondly, if you want to
initiate the drag with more accuracy, you need to know if the row
    on which you clicked was already selected, so your drag callback has
to know the widget's a CTree, which doesn't feel right...

* What I've done and questions:

   I ended up rewriting my own dnd_drag_source_event_cb which works only
on a CTree. I inserted a modified version of
gtk_drag_source_set with the gtk_object_set_data_full line commented out
(  awful way to bypass a problem :-(     )   .
   It doesn't feel right at all : I've had to copy data structures
internal to gtk, which may change in the future. My callback is
dependent of the widget's type, so it couldn't be integrated in gtk
(except by adding sort of a big IF (widget == ctree) ;-).

   The current behaviour is as follows : you can select multiple rows
just like a normal clist. Then when you click on an
already selected row, you initiate a drag. There's also a timer feature
which allows to drag a single row (if you don't move
enough for 2/10th of a second you initiate the drag on the single
row). It feels quite intuitive now imho.

   Even if it reacts like I want now, I would like to know how to do all
that in a better way. Writing my own widget ?
Maybe someone has already come with a better solution.
    I would also like to know why gtk_object_set_data_full   breaks the
selection mode. Bug ? I've not gone through
the gtk source enough to figure it out yet.
    As a last side question, is there a function such as
gtk_clist_highlight_row  (to have a row highlighted just as if it was
selected but without actually selecting it).  I've tried to use
gtk_clist_get_row_style and set_row_style but without much
success as of now. And going through gtk's source is a bit cumbersome to
do just that :-)

I'll be thanksfull for any help !
Renaud

PS: there's also a little bug in gtk_clist_get_selection_info  which
doesn't take into account column_title_area.height, I'll
check if it has already been submitted.





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