Gtk2-Ex-Spinner

 view release on metacpan or  search on metacpan

lib/Gtk2/Ex/Spinner/CellRenderer.pm  view on Meta::CPAN

      Gtk2::CellRenderer
        Gtk2::CellRendererText
          Gtk2::Ex::Spinner::CellRenderer

=head1 DESCRIPTION

C<Gtk2::Ex::Spinner::CellRenderer> is based on a great L<Gtk2::Ex::DateSpinner::CellRenderer>, so
in most cases documentation is the same. License is (of course) the same too :-).

C<Spinner::CellRenderer> displays an integer as a
text field.  Editing the field presents both a C<Gtk2::Entry> and a popup
C<Gtk2::Ex::Spinner>.

    +------------+
    |         99 |
    +------------+
    +------------------------------+
    | +-----+     +----+ +------+  |
    | |  99 |^    | Ok | |Cancel|  |
    | +-----+v    +----+ +------+  |
    +------------------------------+

The popup allows mouse clicks or arrow keys to increment or decrement the
value.  This is good if you often just want to bump a value up or
down a bit.  

=head2 Details

The value to display, and edit, is taken from the renderer C<text> property
and must an integer.  A new edited value is passed to the
C<edited> signal emitted on the renderer in the usual way (see
L<Gtk2::CellRenderer>).  Text renderer properties affect the display.
C<xalign> is copied to the Entry widget to have it left, right or centred

lib/Gtk2/Ex/Spinner/CellRenderer.pm  view on Meta::CPAN

pairs set initial properties as per C<< Glib::Object->new >>.  Eg.

    my $renderer = Gtk2::Ex::Spinner::CellRenderer->new
                     (editable => 1);

=back

=head1 OTHER NOTES

As with the plain CellRendererText, Spinner::CellRenderer creates a new
editable widget for every edit, including a new popup window every time.
Both are destroyed when accepted or cancelled.  That's a little wasteful,
but it's usually fast enough for casual editing and it might save some
memory in between.

The code for the popup and entry is in the
C<Gtk2::Ex::Spinner::PopupForEntry> and
C<Gtk2::Ex::Spinner::EntryWithCancel> components.  They're not loaded
until the first edit.  They're only meant for internal use as yet.

=head1 SEE ALSO

L<Gtk2::Ex::DateSpinner>, L<Gtk2::CellRendererText>

Gtk2-Perl F<examples/cellrenderer_date.pl> does a similar display/edit
popping up a C<Gtk2::Calendar>.  See

lib/Gtk2/Ex/Spinner/PopupForEntry.pm  view on Meta::CPAN

  if ($self->{'change_in_progress'}) { return; }
  my $entry = $self->{'entry'} || return;

  local $self->{'change_in_progress'} = 1;
  $entry->set_text ($spinner->get_value);
}

sub _do_entry_editing_done {
  my ($entry, $ref_weak_self) = @_;
  my $self = $$ref_weak_self || return;
  if (DEBUG) { print "PopupForEntry: _do_entry_editing_done, hide popup\n"; }
  $self->hide;
}

# 'activate' on the spin buttons
# 'clicked' on the 'gtk-ok' button
#
sub _do_activate {
  my ($widget) = @_;
  if (DEBUG) { print "PopupForEntry _do_activate\n"; }
  my $self = $widget->get_toplevel;

lib/Gtk2/Ex/Spinner/PopupForEntry.pm  view on Meta::CPAN

  if (DEBUG) { print "PopupForEntry _do_cancel_button\n"; }
  my $self = $button->get_toplevel;

  $self->hide;
  my $entry = $self->{'entry'} || return;  # maybe already gone
  $entry->cancel;
}

# 'size-allocate' on the entry widget
#
# Finding the right time to position the popup is a bit painful.
# GtkTreeView and GtkIconView add the editable to themselves and map it with
# default height 1, then focus to it, then size_allocate it up to the cell
# size.  So to position underneath it we only know the right height after
# that size-allocate.  Positioning earlier at the map or the focus state
# ends up with an unattractive visible move of the popup window downwards.
#
# FIXME: Depending on the sequence of actions in TreeView is a bit nasty,
# maybe it'd at least be worth a recheck of the position on getting to
# Glib::Idle after a start_editing.
#
sub _do_position {
  my ($entry) = @_;
  my $ref_weak_self = $_[-1];
  my $self = $$ref_weak_self || return;
  if (DEBUG) {

lib/Gtk2/Ex/Spinner/PopupForEntry.pm  view on Meta::CPAN

    # below is past bottom of screen, try above
    $win_y = $y - $req->height;
    if ($win_y < 0) {
      # above is past top of screen, clamp to top
      $win_y = 0;
    }
  }

  # 'gravity' (GdkGravity) doesn't really help to position above a selected
  # position for a one-off move, it only works if set and left.  Could be ok
  # since this popup is supposed to be private, but a bit easier to stay
  # default north-west for now.
  #
  $toplevel->move ($win_x, $win_y);
}

1;

__END__

=head1 NAME

Gtk2::Ex::Spinner::PopupForEntry -- popup Spinner for a Gtk2::Entry

=head1 SYNOPSIS

 use Gtk2::Ex::Spinner::PopupForEntry;
 my $entry = Gtk2::Ex::Spinner::PopupForEntry->new;

=head1 WIDGET HIERARCHY

C<Gtk2::Ex::Spinner::PopupForEntry> is a subclass of C<Gtk2::Window>.

lib/Gtk2/Ex/Spinner/PopupForEntry.pm  view on Meta::CPAN

          Gtk2::Window
            Gtk2::Ex::Spinner::PopupForEntry

=head1 DESCRIPTION

C<Gtk2::Ex::Spinner::PopupForEntry> is based on a great 
L<Gtk2::Ex::DateSpinner::PopupForEntry>, so in most cases documentation 
is the same. License is (of course) the same too :-).

B<Caution: This is internals of C<Gtk2::Ex::Spinner::CellRenderer>.  The
idea of a popup under an edited cell might be split out under a new name at
some time though, or even the idea of a DateSpinner popup standing alone.>

C<Spinner::PopupForEntry> holds a C<Gtk2::Ex::Spinner> and Ok and
Cancel buttons.  It positions itself under a given C<Gtk2::Entry> (or
subclass of C<Gtk2::Entry>) and communicates its value back and forward with
that Entry for dual editing.  Only a weak reference is held on the Entry and
when the entry is destroyed the PopupForEntry is closed and destroyed too.

=head1 PROPERTIES

=over 4



( run in 3.717 seconds using v1.01-cache-2.11-cpan-364913b4093 )