drag and drop with clist


I'm trying to use drag and drop in a Clist with GtkPerl 1.2.10.

The approach I've taken so far is:

$clist->signal_connect('drag_begin', \&DragBegin );
$clist->signal_connect('drag_end', \&DragDrop );

sub DragBegin {
  my ($bw, $context) = @_;
  my ($x,$y) = $bw->get_pointer();
  my $adjy=$y-71;                       # size of titles fixme
  ($row_drag_from) = $bw->get_selection_info($x, $adjy);

sub DragDrop {
  my ($clist_widget, $drag_context, $selectiondata, $info, $time) = @_;
  my ($x,$y) = $clist_widget->get_pointer();
  my $adjy=$y-47;                       # size of titles fixme
  my ($row) = $clist_widget->get_selection_info($x, $adjy);
  print "move from $row_drag_from to $row\n";

The "set_reorderable" part works fine, I can drag items in the clist.
I need to know the row dragged from and to to be able to reorder
my application data.
The technique I'm using is to get the pointer position and then
use get_selection_info to convert that pointer position into a
row number.

One problem is that get_selection_info wants the pointer position to
be relative to the Clist data, but get_pointer is relative to the Clist
including the title.
I looked at the logic in Mandrake's MenuDrake
(which is written in C and it gets
the position of the row like this:

  y -= (GTK_CONTAINER (clist)->border_width +
        widget->style->ythickness +
#define ROW_TOP_YPIXEL(clist, row) (((clist)->row_height * (row)) + \
                                    (((row) + 1) * CELL_SPACING) + \
  dest_info.cell.row = ROW_FROM_YPIXEL (clist, y);

So, MenuDrake seems to be subtracting things like border widths
and title heights to adjust the pointer value before using it
to index the row.

Is there any way to access things like the border width or clist title
height from gtk perl?

The pointer value at DragBegin is interesting.
I did some debugging and the pointer values were always like this:

Row Pointer
0   71
1   95
2  119

but if I drag upward, the pointer values run like this:

Row Pointer
0   47
1   71
2   95

The numbers are always 24 apart, regardless of where the pointer
is at the start of the drag.
Whats weird is the different numbers depending on the direction.
I guess the number comes from when the pointer crosses some
I suppose I can deal with that by delaying the calculations
until the drop and adjusting the numbers based on the
drop location being lower than the drag location, but that
seems like a weird thing to have to do.

Its also a bit strange, using xmag, it looks like the 47 includes the clist
title but not the border which doesn't match up with Menudrake.
I haven't studied Menudrake too closely maybe I'm misreading it.
Its also working with a Ctree which might be somewhat different.

I've seen earlier discussions of this in these 2 threads:


but the way the threads concluded, it didn't seem like there
was a satisfactory conclusion.

Am I misunderstanding the correct approach?
Does the above information seem correct?

I really need to get the title height into my calcuations, I don't
want to hard code a number, because I assume the title height will
vary depending on the font being used.

Thanks in advance for any help.
Dan Espen                               E-mail: dane mk telcordia com

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