#!/usr/bin/perl
use strict;
use warnings;
use Glib qw(TRUE FALSE);
use Gtk2 -init;

my $store = Gtk2::TreeStore->new (qw/Glib::String Glib::Int64/);
my $parent = $store->append (undef);
$store->set ($parent, 0 => 'Parent', 1 => 1);
my $child = $store->append ($parent);
$store->set ($child, 0 => 'Child 1', 1 => 23);
$child = $store->append ($parent);
$store->set ($child, 0 => 'Child 2', 1 => 42);

my $view = Gtk2::TreeView->new ($store);
$view->insert_column_with_attributes (
  0 => 'String', Gtk2::CellRendererText->new, text => 0);
$view->insert_column_with_attributes (
  1 => 'Int64', Gtk2::CellRendererText->new, text => 1);
$view->set_reorderable (TRUE);

$view->signal_connect(drag_data_received => sub {
  my ($view, $context, $x, $y, $data, $info, $time) = @_;

  my ($model, $src) = $data->get_row_drag_data;
  my ($dest, $pos) = $view->get_drag_dest_row;

  return unless defined $dest;

  if ($src->get_depth != $dest->get_depth ||
      ($pos ne 'after' && $pos ne 'before'))
  {
    $context->status ([], $time);
    $view->set_drag_dest_row (undef, 'before');
    return;
  }
});

my $window = Gtk2::Window->new;
$window->add ($view);
$window->show_all;

Gtk2->main;
