| 1 | package Gtk2::Ex::FormFactory::DialogButtons; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | |||
| 5 | use base qw( Gtk2::Ex::FormFactory::Widget ); | ||
| 6 | |||
| 7 | sub get_type { "dialog_buttons" } | ||
| 8 | |||
| 9 | sub get_buttons { shift->{buttons} } | ||
| 10 | sub get_clicked_hook_before { shift->{clicked_hook_before} } | ||
| 11 | sub get_clicked_hook_after { shift->{clicked_hook_after} } | ||
| 12 | |||
| 13 | sub set_buttons { shift->{buttons} = $_[1] } | ||
| 14 | sub set_clicked_hook_before { shift->{clicked_hook_before} = $_[1] } | ||
| 15 | sub set_clicked_hook_after { shift->{clicked_hook_after} = $_[1] } | ||
| 16 | |||
| 17 | sub get_gtk_ok_button { shift->{gtk_ok_button} } | ||
| 18 | sub get_gtk_cancel_button { shift->{gtk_cancel_button} } | ||
| 19 | sub get_gtk_apply_button { shift->{gtk_apply_button} } | ||
| 20 | |||
| 21 | sub set_gtk_ok_button { shift->{gtk_ok_button} = $_[1] } | ||
| 22 | sub set_gtk_cancel_button { shift->{gtk_cancel_button} = $_[1] } | ||
| 23 | sub set_gtk_apply_button { shift->{gtk_apply_button} = $_[1] } | ||
| 24 | |||
| 25 | sub new { | ||
| 26 | my $class = shift; | ||
| 27 | my %par = @_; | ||
| 28 | my ($buttons, $clicked_hook_before, $clicked_hook_after) = | ||
| 29 | @par{'buttons','clicked_hook_before','clicked_hook_after'}; | ||
| 30 | |||
| 31 | my $self = $class->SUPER::new(@_); | ||
| 32 | |||
| 33 | $buttons ||= { ok => 1, cancel => 1 }; | ||
| 34 | |||
| 35 | $self->set_buttons($buttons); | ||
| 36 | $self->set_clicked_hook_before($clicked_hook_before); | ||
| 37 | $self->set_clicked_hook_after($clicked_hook_after); | ||
| 38 | |||
| 39 | return $self; | ||
| 40 | } | ||
| 41 | |||
| 42 | sub cleanup { | ||
| 43 | my $self = shift; | ||
| 44 | |||
| 45 | $self->SUPER::cleanup(@_); | ||
| 46 | |||
| 47 | $self->set_gtk_ok_button(undef); | ||
| 48 | $self->set_gtk_cancel_button(undef); | ||
| 49 | $self->set_gtk_apply_button(undef); | ||
| 50 | |||
| 51 | 1; | ||
| 52 | } | ||
| 53 | |||
| 54 | |||
| 55 | sub object_to_widget { | ||
| 56 | my $self = shift; | ||
| 57 | |||
| 58 | my $buttons; | ||
| 59 | $buttons = $self->get_object_value if $self->get_attr; | ||
| 60 | $buttons ||= "all"; | ||
| 61 | |||
| 62 | foreach my $button ( keys %{$self->get_buttons} ) { | ||
| 63 | my $active = $buttons eq 'all' || $buttons->{$button}; | ||
| 64 | my $gtk_widget = $self->{"gtk_".$button."_button"}; | ||
| 65 | next if not $gtk_widget; | ||
| 66 | if ( $self->get_inactive eq 'invisible' ) { | ||
| 67 | if ( $active ) { | ||
| 68 | $gtk_widget->show; | ||
| 69 | } else { | ||
| 70 | $gtk_widget->hide; | ||
| 71 | } | ||
| 72 | } else { | ||
| 73 | $gtk_widget->set_sensitive($active); | ||
| 74 | } | ||
| 75 | } | ||
| 76 | |||
| 77 | 1; | ||
| 78 | } | ||
| 79 | |||
| 80 | sub cancel_button_clicked { | ||
| 81 | my $self = shift; | ||
| 82 | |||
| 83 | my $clicked_hook_before = $self->get_clicked_hook_before; | ||
| 84 | my $clicked_hook_after = $self->get_clicked_hook_after; | ||
| 85 | my $default_handler = 1; | ||
| 86 | $default_handler = &$clicked_hook_before("cancel") | ||
| 87 | if $clicked_hook_before; | ||
| 88 | return if not $default_handler; | ||
| 89 | $self->get_form_factory->cancel; | ||
| 90 | &$clicked_hook_after("cancel") | ||
| 91 | if $clicked_hook_after; | ||
| 92 | 1; | ||
| 93 | } | ||
| 94 | |||
| 95 | sub apply_button_clicked { | ||
| 96 | my $self = shift; | ||
| 97 | |||
| 98 | my $clicked_hook_before = $self->get_clicked_hook_before; | ||
| 99 | my $clicked_hook_after = $self->get_clicked_hook_after; | ||
| 100 | my $default_handler = 1; | ||
| 101 | $default_handler = &$clicked_hook_before("apply") | ||
| 102 | if $clicked_hook_before; | ||
| 103 | return if not $default_handler; | ||
| 104 | $self->get_form_factory->apply; | ||
| 105 | &$clicked_hook_after("apply") | ||
| 106 | if $clicked_hook_after; | ||
| 107 | 1; | ||
| 108 | } | ||
| 109 | |||
| 110 | sub ok_button_clicked { | ||
| 111 | my $self = shift; | ||
| 112 | |||
| 113 | my $clicked_hook_before = $self->get_clicked_hook_before; | ||
| 114 | my $clicked_hook_after = $self->get_clicked_hook_after; | ||
| 115 | my $default_handler = 1; | ||
| 116 | $default_handler = &$clicked_hook_before("ok") | ||
| 117 | if $clicked_hook_before; | ||
| 118 | return if not $default_handler; | ||
| 119 | $self->get_form_factory->ok | ||
| 120 | if $self->get_form_factory; | ||
| 121 | &$clicked_hook_after("ok") | ||
| 122 | if $clicked_hook_after; | ||
| 123 | |||
| 124 | 1; | ||
| 125 | } | ||
| 126 | |||
| 127 | 1; | ||
| 128 | __END__ |