App-Chart

 view release on metacpan or  search on metacpan

lib/App/Chart/Gtk2/Symlist.pm  view on Meta::CPAN

    my $seq = App::Chart::Database::read_notes_single
      ('SELECT seq FROM symlist_content WHERE key=? AND symbol=?',
       $symlist->key, $symbol);
    if (! defined $seq) {
      $seq = App::Chart::Database::read_notes_single
        ('SELECT seq FROM symlist_content WHERE key=? AND symbol<=?
          ORDER BY symbol ASC LIMIT 1',
         $symlist->key, $symbol);
    }

    if (defined $seq && $seq > 0) {
      $seq--;
      $symbol = App::Chart::Database::read_notes_single
        ('SELECT symbol FROM symlist_content WHERE key=? AND seq=?',
         $symlist->key, $seq);
      if (defined $symbol) { goto FOUND; }
    }
  }

  my $symlist_num = App::Chart::Database::read_notes_single
      ('SELECT seq FROM symlist WHERE key=?', $symlist->key);
  if (! defined $symlist_num) { return (undef, undef); }

  for (;;) {
    $symlist_num--;
    if ($symlist_num < 0) { return (undef, undef); }

    my $key = App::Chart::Database::read_notes_single
      ('SELECT key FROM symlist WHERE seq=?', $symlist_num);
    if (! $key) { return (undef, undef); }
    $symlist = _new_from_known_key ($key);

    $symbol = App::Chart::Database::read_notes_single
      ('SELECT symbol FROM symlist_content WHERE key=? ORDER BY seq DESC LIMIT 1',
       $symlist->key);
    if ($symbol) { last; }
  }

 FOUND:
  if (! App::Chart::Database->symbol_exists ($symbol)) {
    goto AGAIN;
  }
 return ($symbol, $symlist);
}


#------------------------------------------------------------------------------
# drag source
#

# gtk_tree_drag_source_row_draggable ($self, $src_path)
sub ROW_DRAGGABLE {
  my ($self, $src_path) = @_;
  if (DEBUG) { print "Symlist ROW_DRAGGABLE path=",$src_path->to_string,"\n";
               print "  ",$self->can_edit?"yes":"no", ", can_edit\n"; }
  $self->can_edit or do {
    if (DEBUG) { print "  no, cannot edit\n"; }
    return undef;
  };
  if (DEBUG) { print "  super:\n"; }
  return $self->SUPER::ROW_DRAGGABLE ($src_path);
}

#------------------------------------------------------------------------------
# drag dest

# gtk_tree_drag_dest_row_drop_possible
#
sub ROW_DROP_POSSIBLE {
  my ($self, $dst_path, $sel) = @_;
  ### Symlist ROW_DROP_POSSIBLE
  ### to path: $dst_path->to_string
  ### type: $sel->type->name

  $self->can_edit or do {
    ### no, cannot edit
    return 0;
  };
  if ($dst_path->get_depth != 1) {
    ### no, dest path depth: $dst_path->get_depth
    return 0;
  }

  if (defined (my $str = $sel->get_text)) {
    ### yes, can drop text
    return 1;
  }

  if (my ($src_model, $src_path) = $sel->get_row_drag_data) {
    if ($src_model->isa('App::Chart::Gtk2::Symlist')) {
      ### yes, source model is a Symlist
      return 1;
    }
  }

  ### no, not text or symlist row
  return 0;
}

# gtk_tree_drag_dest_drag_data_received
#
sub DRAG_DATA_RECEIVED {
  my ($self, $dst_path, $sel) = @_;
  ### Symlist DRAG_DATA_RECEIVED
  ### to path: $dst_path->to_string
  ### type: $sel->type->name
  ### src model: (($sel->get_row_drag_data)[0])
  ### src path : (($sel->type->name eq 'GTK_TREE_MODEL_ROW') && ($sel->get_row_drag_data)[1]->to_string)

  ### get_text: $sel->get_text
  if (defined (my $str = $sel->get_text)) {
    if ($dst_path->get_depth != 1) {
      ### no, dest path depth: $dst_path->get_depth
      return 0;
    }
    my ($dst_index) = $dst_path->get_indices;
    eval { $self->insert_with_values ($dst_index, COL_SYMBOL, $str); 1 }
      or do {
        ### no, error from insert_with_values(): $@
        return 0;
      };
    ### yes, dropped text
    return 1;
  }

  ### go to SUPER
  return $self->SUPER::DRAG_DATA_RECEIVED ($dst_path, $sel);
}


1;
__END__

=for stopwords arrayref hashref

=head1 NAME

App::Chart::Gtk2::Symlist -- symbol list objects

=head1 SYNOPSIS

 use App::Chart::Gtk2::Symlist;

=head1 FUNCTIONS

=over 4

=item C<< $symlist->symbols() >>

=item C<< $symlist->symbol_listref() >>

=item C<< $symlist->hash() >>

Return the symbols in C<$symlist>, either as a list return, an arrayref, or
a hashref.

=back

=cut



( run in 0.519 second using v1.01-cache-2.11-cpan-0bb4e1dffa6 )