NAME

App::Chart::Gtk2::Ex::ListStore::DragByCopy -- drag and drop copying between ListStores

SYNOPSIS

package MyStore;
use Gtk2;
use base 'App::Chart::Gtk2::Ex::ListStore::DragByCopy';
use Glib::Object::Subclass
  'Gtk2::ListStore',
  interfaces => [ 'Gtk2::TreeDragSource',
                  'Gtk2::TreeDragDest' ];

DESCRIPTION

App::Chart::Gtk2::Ex::ListStore::DragByCopy is designed as a multi-inheritance mix-in for Perl sub-classes of Gtk2::ListStore. It provides versions of the following methods which allow drag-and-drop between different models.

ROW_DRAGGABLE
DRAG_DATA_GET
DRAG_DATA_DELETE

ROW_DROP_POSSIBLE
DRAG_DATA_RECEIVED

Normally ListStore restricts drag and drop to re-ordering rows within a single model. With this mix-in rows can be copied to or from any compatible model, though still only within the same running program.

FUNCTIONS

$bool = ROW_DRAGGABLE ($liststore, $src_path)
$bool = DRAG_DATA_GET ($liststore, $src_path, $selection)
$bool = DRAG_DATA_DELETE ($liststore, $src_path)

The drag methods offer a row as data and delete it with remove when dragged.

If you want to impose extra conditions on dragging you can write your own versions of these functions and chain up. For example if only the first three rows of the model are draggable then

sub ROW_DRAGGABLE {
  my ($self, $path) = @_;
  my ($index) = $path->get_indices;
  if ($index >= 3) { return 0; } # not draggable
  return $self->SUPER::ROW_DRAGGABLE ($path);
}
$bool = ROW_DROP_POSSIBLE ($liststore, $dst_path, $selection)
$bool = DRAG_DATA_RECEIVED ($self, $dst_path, $selection)

The drop methods accept a row from any TreeModel. They get the row data with $src->get and store it with $dst->insert_with_values.

SEE ALSO

Gtk2::ListStore