App-Chart

 view release on metacpan or  search on metacpan

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

  signals => { button_press_event => \&_do_button_press_event,

               menu_created => { param_types => ['Gtk2::Menu'],
                                 return_type => undef,
                               },
               menu_popup => { param_types   => ['Glib::Int',
                                                 'App::Chart::Gtk2::Ticker::menu_position'],
                               return_type   => undef,
                               class_closure => \&_do_menu_popup_action,
                               flags         => [ 'run-last', 'action' ],
                             },
             },
  properties => [Glib::ParamSpec->object
                 ('symlist',
                  'symlist',
                  'App::Chart::Gtk2::Symlist object for the symbols to display.',
                  # App::Chart::Gtk2::Symlist::Join is a ListModelConcat not
                  # a Symlist subclass, allow that by just Glib::Object here
                  'Glib::Object',
                  Glib::G_PARAM_READWRITE),
                ];
App::Chart::Gtk2::GUI::chart_style_class (__PACKAGE__);

# priority level "gtk" treating this as widget level default, for overriding
# by application or user RC
Gtk2::Rc->parse_string (<<'HERE');
binding "App__Chart__Gtk2__Ticker_keys" {
  bind "F10"             { "menu_popup" (0, centre) }
  bind "Pointer_Button3" { "menu_popup" (3, pointer) }
}
class "App__Chart__Gtk2__Ticker" binding:gtk "App__Chart__Gtk2__Ticker_keys"
HERE

sub INIT_INSTANCE {
  my ($self) = @_;
  $self->add_events (['button-press-mask', 'key-press-mask']);
  $self->set (fixed_height_mode => 1);
  $self->set_flags ('can-focus');

  my $renderer = Gtk2::CellRendererText->new;
  $renderer->set (xpad => Gtk2::Ex::Units::em($self));
  $self->pack_start ($renderer, 0);
  $self->set_attributes ($renderer, markup => 0);

  # default Favourites symlist, unless it's empty and All is not in which
  # case use All
  require App::Chart::Gtk2::Symlist::Favourites;
  my $symlist = App::Chart::Gtk2::Symlist::Favourites->instance;
  if ($symlist->is_empty) {
    require App::Chart::Gtk2::Symlist::All;
    my $all = App::Chart::Gtk2::Symlist::All->instance;
    if (! $all->is_empty) {
      $symlist = $all;
    }
  }
  $self->set (symlist => $symlist);
}

sub FINALIZE_INSTANCE {
  my ($self) = @_;
  # Gtk2::Menu doesn't go away just by weakening if currently popped-up
  # (because it's then a toplevel presumably); doing ->popdown() works, but
  # ->destroy() seems the best idea
  if (my $menu = $self->{'menu'}) {
    $menu->destroy;
  }
}

sub SET_PROPERTY {
  my ($self, $pspec, $newval) = @_;
  my $pname = $pspec->get_name;
  my $oldval = $self->{$pname};

  if ($pname eq 'symlist' && ($newval||0) != ($oldval||0)) {
    ### Ticker: "$self changed symlist"
    my $symlist = $newval;
    if (defined $symlist && ! $symlist->isa('App::Chart::Gtk2::Symlist')) {
      croak "App::Chart::Gtk2::Ticker.symlist must be an App::Chart::Gtk2::Symlist";
    }
    $self->{$pname} = $newval;  # per default GET_PROPERTY

    require App::Chart::Gtk2::TickerModel;
    my $model = $self->{'symlist_model'}
      = $symlist && App::Chart::Gtk2::TickerModel->new ($symlist);

    my $ref_weak_self = App::Chart::Glib::Ex::MoreUtils::ref_weak ($self);
    $self->{'symlist_model_ids'} = $model && do {
      Glib::Ex::SignalIds->new
          ($model,
           $model->signal_connect (row_deleted => \&_do_row_deleted,
                                   $ref_weak_self),
           $model->signal_connect (row_inserted => \&_do_row_inserted,
                                   $ref_weak_self))
        };

    $self->set (model => $model);
    $self->{'showing_empty'} = 0;
    _check_empty ($self);

  } else {
    $self->{$pname} = $newval;  # per default GET_PROPERTY
  }
}

# 'button-press-event' class closure
sub _do_button_press_event {
  my ($self, $event) = @_;
  require App::Chart::Gtk2::Ex::BindingBits;
  App::Chart::Gtk2::Ex::BindingBits::activate_button_event
      ('App__Chart__Gtk2__Ticker_keys', $event, $self);
  return shift->signal_chain_from_overridden(@_);
}

# 'menu-popup' action signal class closure
sub _do_menu_popup_action {
  my ($self, $button, $where) = @_;
  ### Ticker: "menu-popup action $button $where"

  my $position_func; # undef for mouse position if $where empty or undef
  if ($where && $where ne 'pointer') {
    $position_func = $self->can("menu_position_func_$where");



( run in 1.049 second using v1.01-cache-2.11-cpan-39bf76dae61 )