| 1 | package Gapp::Entry; | ||
| 2 | { | ||
| 3 | $Gapp::Entry::VERSION = '0.60'; | ||
| 4 | } | ||
| 5 | |||
| 6 | use Moose; | ||
| 7 | use MooseX::SemiAffordanceAccessor; | ||
| 8 | |||
| 9 | extends 'Gapp::Widget'; | ||
| 10 | with 'Gapp::Meta::Widget::Native::Role::FormField'; | ||
| 11 | |||
| 12 | has '+gclass' => ( | ||
| 13 | default => 'Gtk2::Entry', | ||
| 14 | ); | ||
| 15 | |||
| 16 | sub BUILDARGS { | ||
| 17 | my $class = shift; | ||
| 18 | my %args = @_ == 1 && is_HashRef( $_[0] ) ? %{$_[0]} : @_; | ||
| 19 | |||
| 20 | for my $att ( qw( activates_default caps_lock_warning max_length invisible_char overwrite_mode text visibility width_chars xalign ) ) { | ||
| 21 | $args{properties}{$att} = delete $args{$att} if exists $args{$att}; | ||
| 22 | } | ||
| 23 | |||
| 24 | __PACKAGE__->SUPER::BUILDARGS( %args ); | ||
| 25 | } | ||
| 26 | |||
| 27 | # returns the value of the widget | ||
| 28 | sub get_field_value { | ||
| 29 | $_[0]->gobject->get_text; | ||
| 30 | } | ||
| 31 | |||
| 32 | sub set_field_value { | ||
| 33 | my ( $self, $value ) = @_; | ||
| 34 | $self->gobject->set_text( defined $value ? $value : '' ); | ||
| 35 | } | ||
| 36 | |||
| 37 | sub widget_to_stash { | ||
| 38 | my ( $self, $stash ) = @_; | ||
| 39 | $stash->store( $self->field, $self->get_field_value ); | ||
| 40 | } | ||
| 41 | |||
| 42 | sub stash_to_widget { | ||
| 43 | my ( $self, $stash ) = @_; | ||
| 44 | $self->set_field_value( $stash->fetch( $self->field ) ); | ||
| 45 | } | ||
| 46 | |||
| 47 | sub _connect_changed_handler { | ||
| 48 | my ( $self ) = @_; | ||
| 49 | |||
| 50 | $self->gobject->signal_connect ( | ||
| 51 | changed => sub { $self->_widget_value_changed }, | ||
| 52 | ); | ||
| 53 | } | ||
| 54 | |||
| 55 | 1; | ||
| 56 | |||
| 57 | |||
| 58 | __END__ |