App-Chart
view release on metacpan or search on metacpan
lib/App/Chart/Gtk2/Ex/TreeRowPosition.pm view on Meta::CPAN
Glib::G_PARAM_READWRITE),
Glib::ParamSpec->boxed
('path',
'path',
'Current position as a Gtk2::TreePath.',
'Gtk2::TreePath',
Glib::G_PARAM_READWRITE),
Glib::ParamSpec->enum
('type',
'type',
'Position type.',
'App::Chart::Gtk2::Ex::TreeRowPosition::Type',
'start',
Glib::G_PARAM_READWRITE),
Glib::ParamSpec->int
('key-column',
'key-column',
'Column number in the model which is a unique key to identify a row.',
-1, POSIX::INT_MAX(),
-1,
Glib::G_PARAM_READWRITE),
];
sub INIT_INSTANCE {
my ($self) = @_;
$self->{'type'} = 'start'; # defaults
$self->{'path'} = Gtk2::TreePath->new;
$self->{'key_column'} = -1;
### INIT_INSTANCE: $self->{'path'}->to_string, $self->{'type'}
}
sub FINALIZE_INSTANCE {
my ($self) = @_;
### FINALIZE_INSTANCE: "$self"
if (my $model = $self->{'model'}) {
if (my $h = $model->{__PACKAGE__.'.instances'}) {
delete $h->{refaddr($self)};
if (! %$h) {
### no more instances, disconnect model
delete $model->{__PACKAGE__.'.instances'};
delete $model->{__PACKAGE__.'.ids'};
}
}
}
}
sub SET_PROPERTY {
my ($self, $pspec, $newval) = @_;
my $pname = $pspec->get_name;
### SET_PROPERTY: $pname, $newval
if ($pname eq 'path') {
### pathstr: $newval->to_string
$newval = $newval->copy;
} elsif ($pname eq 'model') {
FINALIZE_INSTANCE($self);
if ($newval) {
Scalar::Util::weaken ($newval->{__PACKAGE__.'.instances'}->{refaddr($self)} = $self);
$newval->{__PACKAGE__.'.ids'} ||= Glib::Ex::SignalIds->new
($newval,
$newval->signal_connect (row_changed => \&_do_row_changed),
$newval->signal_connect (row_deleted => \&_do_row_deleted),
$newval->signal_connect (row_inserted => \&_do_row_inserted),
$newval->signal_connect (rows_reordered => \&_do_rows_reordered));
}
}
$self->{$pname} = $newval;
if ($pname eq 'type'
|| $pname eq 'path'
|| $pname eq 'key_column') {
if ($self->{'type'} eq 'at') {
_at_key ($self, $self->{'path'}); # record key
}
}
### pathstr now: $self->{'path'}->to_string
}
sub _default_key_compare {
my ($self, $key1, $key2) = @_;
### _default_key_compare: $key1,$key2
return ($key1 eq $key2);
}
sub _do_row_changed {
my ($model, $chg_path, $chg_iter) = @_;
### TreeRowPosition row_changed, pathstr: $chg_path->to_string
foreach my $self (values %{$model->{__PACKAGE__.'.instances'}}) {
$self || next;
if ($self->{'type'} eq 'at' && $chg_path->compare($self->{'path'}) == 0) {
# when current row changes remember its possibly changed key
$self->{'at_key'} = _get_key ($self, $chg_path, $chg_iter);
} elsif (exists $self->{'want_key'}) {
# when seeking 'want_key' see if newly changed row matches
my $this_key = _get_key ($self, $chg_path, $chg_iter);
if (_match_key ($self, $self->{'want_key'}, $this_key)) {
_at_key ($self, $chg_path->copy, $this_key);
}
}
}
}
my %_on_row_offsets = (start => 1,
end => 1,
before => 0,
at => 1,
after => 1);
sub _do_row_inserted {
my ($model, $ins_path, $ins_iter) = @_;
### TreeRowPosition row_inserted, pathstr: $ins_path->to_string
INSTANCE: foreach my $self (values %{$model->{__PACKAGE__.'.instances'}}) {
$self || next;
( run in 0.697 second using v1.01-cache-2.11-cpan-39bf76dae61 )