| 1 | package Gapp::RadioToolButton; | ||
| 2 | { | ||
| 3 | $Gapp::RadioToolButton::VERSION = '0.60'; | ||
| 4 | } | ||
| 5 | |||
| 6 | use Moose; | ||
| 7 | use MooseX::SemiAffordanceAccessor; | ||
| 8 | extends 'Gapp::ToggleToolButton'; | ||
| 9 | |||
| 10 | has '+gclass' => ( | ||
| 11 | default => 'Gtk2::RadioToolButton', | ||
| 12 | ); | ||
| 13 | |||
| 14 | has 'value' => ( | ||
| 15 | is => 'rw', | ||
| 16 | isa => 'Str', | ||
| 17 | default => '1', | ||
| 18 | ); | ||
| 19 | |||
| 20 | |||
| 21 | |||
| 22 | # create and set the actual gobject | ||
| 23 | sub _construct_gobject { | ||
| 24 | my ( $self ) = @_; | ||
| 25 | |||
| 26 | my $gtk_class = $self->gclass; | ||
| 27 | my $gtk_constructor = $self->constructor; | ||
| 28 | |||
| 29 | # determine the radio group | ||
| 30 | my $group = $self->field && $self->parent ? | ||
| 31 | $self->parent->{_rdo_groups}{ $self->field } : | ||
| 32 | undef; | ||
| 33 | |||
| 34 | # use any build-arguments if they exist | ||
| 35 | my $w = $gtk_class->$gtk_constructor( $group ); | ||
| 36 | $self->set_gobject( $w ); | ||
| 37 | |||
| 38 | # save the radio group in the parent | ||
| 39 | if ( $self->parent ) { | ||
| 40 | $self->parent->{_rdo_groups}{ $self->field } ||= $w->get_group; | ||
| 41 | } | ||
| 42 | |||
| 43 | return $w; | ||
| 44 | } | ||
| 45 | |||
| 46 | sub get_field_value { | ||
| 47 | my $self = shift; | ||
| 48 | my $state = $self->gobject->get_active; | ||
| 49 | if ( $state ) { | ||
| 50 | return $self->value; | ||
| 51 | } | ||
| 52 | } | ||
| 53 | |||
| 54 | sub widget_to_stash { | ||
| 55 | my ( $self, $stash ) = @_; | ||
| 56 | my $state = $self->gobject->get_active; | ||
| 57 | if ( $state ) { | ||
| 58 | $stash->store( $self->field, $self->get_field_value ); | ||
| 59 | } | ||
| 60 | } | ||
| 61 | |||
| 62 | sub stash_to_widget { | ||
| 63 | my ( $self, $stash ) = @_; | ||
| 64 | $self->set_field_value( $stash->fetch( $self->field ) ); | ||
| 65 | } | ||
| 66 | |||
| 67 | #sub _connect_changed_handler { | ||
| 68 | # my ( $self ) = @_; | ||
| 69 | # | ||
| 70 | # $self->gobject->signal_connect ( | ||
| 71 | # released => sub { $self->_widget_value_changed; } | ||
| 72 | # ); | ||
| 73 | #} | ||
| 74 | |||
| 75 | |||
| 76 | |||
| 77 | 1; | ||
| 78 | |||
| 79 | |||
| 80 | |||
| 81 | __END__ |