| 1 | package Gtk2::Ex::FormFactory::Container; | ||||||||||||||
| 2 | |||||||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 4 | |||||||||||||||
| 5 | 2 | ▶ | use base qw( Gtk2::Ex::FormFactory::Widget ); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 6 | |||||||||||||||
| 7 | 0 | ▶ | sub get_content { shift->{content} } | ||||||||||||
|
Subroutine
get_content: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 8 | 0 | ▶ | sub get_title { shift->{title} } | ||||||||||||
|
Subroutine
get_title: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 9 | |||||||||||||||
| 10 | 0 | ▶ | sub set_content { shift->{content} = $_[1] } | ||||||||||||
|
Subroutine
set_content: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 11 | 0 | ▶ | sub set_title { shift->{title} = $_[1] } | ||||||||||||
|
Subroutine
set_title: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 12 | |||||||||||||||
| 13 | 0 | ▶ | sub isa_container { 1 } | ||||||||||||
|
Subroutine
isa_container: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 14 | |||||||||||||||
| 15 | 0 | ▶ | sub new { | ||||||||||||
|
Subroutine
new: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||
| 16 | 0 | my $class = shift; | |||||||||||||
| 17 | 0 | my %par = @_; | |||||||||||||
| 18 | 0 | my ($content, $title) = @par{'content','title'}; | |||||||||||||
| 19 | |||||||||||||||
| 20 | 0 | my $self = $class->SUPER::new(@_); | |||||||||||||
| 21 | |||||||||||||||
| 22 | #-- Handle some defaults for 'content' parameter | ||||||||||||||
| 23 | 0 | ▶ | if ( not defined $content ) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 24 | 0 | $content = []; | |||||||||||||
| 25 | } elsif ( ref $content ne 'ARRAY' ) { | ||||||||||||||
| 26 | 0 | $content = [ $content ]; | |||||||||||||
| 27 | } | ||||||||||||||
| 28 | |||||||||||||||
| 29 | #-- For convenience the developer may write pairs of | ||||||||||||||
| 30 | #-- the Widget's short name and a hash ref with its | ||||||||||||||
| 31 | #-- attributes instead of adding real objects. This | ||||||||||||||
| 32 | #-- loop search for such non-objects and creates | ||||||||||||||
| 33 | #-- objects accordingly. | ||||||||||||||
| 34 | 0 | my @content_with_objects; | |||||||||||||
| 35 | 0 | ▶ | for ( my $i=0; $i < @{$content}; ++$i ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 36 | 0 | ▶ | if ( not defined $content->[$i] ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 37 | 0 | die "Child #$i of ".$self->get_type."/".$self->get_name. | |||||||||||||
| 38 | " is not defined"; | ||||||||||||||
| 39 | } | ||||||||||||||
| 40 | 0 | ▶ | if ( not ref $content->[$i] ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 41 | #-- No object, so derive the class name | ||||||||||||||
| 42 | #-- from the short name | ||||||||||||||
| 43 | 0 | my $class = $content->[$i]; | |||||||||||||
| 44 | 0 | $class =~ s/^(.)/uc($1)/e; | |||||||||||||
| 45 | 0 | $class =~ s/_(.)/uc($1)/eg; | |||||||||||||
| 46 | 0 | $class =~ s/_//g; | |||||||||||||
| 47 | 0 | $class = "Gtk2::Ex::FormFactory::$class"; | |||||||||||||
| 48 | |||||||||||||||
| 49 | #-- And create the object | ||||||||||||||
| 50 | 0 | my $object = $class->new(%{$content->[$i+1]}); | |||||||||||||
| 51 | 0 | push @content_with_objects, $object; | |||||||||||||
| 52 | |||||||||||||||
| 53 | #-- Skip next entry in @content | ||||||||||||||
| 54 | 0 | ++$i; | |||||||||||||
| 55 | |||||||||||||||
| 56 | } else { | ||||||||||||||
| 57 | #-- Regular objects are taken as is | ||||||||||||||
| 58 | 0 | push @content_with_objects, $content->[$i]; | |||||||||||||
| 59 | } | ||||||||||||||
| 60 | } | ||||||||||||||
| 61 | |||||||||||||||
| 62 | 0 | $self->set_content(\@content_with_objects); | |||||||||||||
| 63 | 0 | $self->set_title($title); | |||||||||||||
| 64 | |||||||||||||||
| 65 | 0 | return $self; | |||||||||||||
| 66 | } | ||||||||||||||
| 67 | |||||||||||||||
| 68 | 0 | ▶ | sub debug_dump { | ||||||||||||
|
Subroutine
debug_dump: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||
| 69 | 0 | my $self = shift; | |||||||||||||
| 70 | 0 | my ($level) = @_; | |||||||||||||
| 71 | |||||||||||||||
| 72 | 0 | $self->SUPER::debug_dump($level); | |||||||||||||
| 73 | |||||||||||||||
| 74 | 0 | foreach my $c ( @{$self->get_content} ) { | |||||||||||||
| 75 | 0 | ▶ | if ( $c ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 76 | 0 | $c->debug_dump($level+1); | |||||||||||||
| 77 | } | ||||||||||||||
| 78 | else { | ||||||||||||||
| 79 | 0 | print " "x($level+1),"UNDEF\n"; | |||||||||||||
| 80 | } | ||||||||||||||
| 81 | } | ||||||||||||||
| 82 | |||||||||||||||
| 83 | 0 | 1; | |||||||||||||
| 84 | } | ||||||||||||||
| 85 | |||||||||||||||
| 86 | 0 | ▶ | sub build { | ||||||||||||
|
Subroutine
build: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 87 | 0 | my $self = shift; | |||||||||||||
| 88 | |||||||||||||||
| 89 | #-- First build the widget itself | ||||||||||||||
| 90 | 0 | $self->SUPER::build(@_); | |||||||||||||
| 91 | |||||||||||||||
| 92 | #-- Now build the children | ||||||||||||||
| 93 | 0 | $self->build_children; | |||||||||||||
| 94 | |||||||||||||||
| 95 | 0 | 1; | |||||||||||||
| 96 | } | ||||||||||||||
| 97 | |||||||||||||||
| 98 | 0 | ▶ | sub build_children { | ||||||||||||
|
Subroutine
build_children: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||
| 99 | 0 | my $self = shift; | |||||||||||||
| 100 | |||||||||||||||
| 101 | 0 | ▶ | $Gtk2::Ex::FormFactory::DEBUG && | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 102 | print "$self->build_children\n"; | ||||||||||||||
| 103 | |||||||||||||||
| 104 | 0 | my $layouter = $self->get_form_factory->get_layouter; | |||||||||||||
| 105 | |||||||||||||||
| 106 | 0 | foreach my $child ( @{$self->get_content} ) { | |||||||||||||
| 107 | 0 | $child->set_parent($self); | |||||||||||||
| 108 | 0 | $child->set_form_factory($self->get_form_factory); | |||||||||||||
| 109 | 0 | $child->build; | |||||||||||||
| 110 | 0 | $layouter->add_widget_to_container ($child, $self); | |||||||||||||
| 111 | } | ||||||||||||||
| 112 | |||||||||||||||
| 113 | 0 | 1; | |||||||||||||
| 114 | } | ||||||||||||||
| 115 | |||||||||||||||
| 116 | 0 | ▶ | sub add_child_widget { | ||||||||||||
|
Subroutine
add_child_widget: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||
| 117 | 0 | my $self = shift; | |||||||||||||
| 118 | 0 | my ($child) = @_; | |||||||||||||
| 119 | |||||||||||||||
| 120 | 0 | push @{$self->get_content}, $child; | |||||||||||||
| 121 | |||||||||||||||
| 122 | 0 | ▶ | return unless $self->get_built; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 123 | |||||||||||||||
| 124 | 0 | my $form_factory = $self->get_form_factory; | |||||||||||||
| 125 | 0 | my $layouter = $form_factory->get_layouter; | |||||||||||||
| 126 | |||||||||||||||
| 127 | 0 | $form_factory->register_all_widgets($child); | |||||||||||||
| 128 | |||||||||||||||
| 129 | 0 | $child->set_parent($self); | |||||||||||||
| 130 | 0 | $child->set_form_factory($form_factory); | |||||||||||||
| 131 | 0 | $child->build; | |||||||||||||
| 132 | |||||||||||||||
| 133 | 0 | $layouter->add_widget_to_container($child, $self); | |||||||||||||
| 134 | |||||||||||||||
| 135 | 0 | $child->connect_signals; | |||||||||||||
| 136 | 0 | $child->update_all; | |||||||||||||
| 137 | 0 | $child->get_gtk_parent_widget->show_all; | |||||||||||||
| 138 | |||||||||||||||
| 139 | 0 | 1; | |||||||||||||
| 140 | } | ||||||||||||||
| 141 | |||||||||||||||
| 142 | 0 | ▶ | sub remove_child_widget { | ||||||||||||
|
Subroutine
remove_child_widget: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||
| 143 | 0 | my $self = shift; | |||||||||||||
| 144 | 0 | my ($child) = @_; | |||||||||||||
| 145 | |||||||||||||||
| 146 | 0 | my $found; | |||||||||||||
| 147 | 0 | my $i = 0; | |||||||||||||
| 148 | 0 | foreach my $c ( @{$self->get_content} ) { | |||||||||||||
| 149 | 0 | ▶ | $found = 1, last if $c eq $child; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 150 | 0 | ++$i; | |||||||||||||
| 151 | } | ||||||||||||||
| 152 | |||||||||||||||
| 153 | 0 | ▶ | die "Widget '".$child->get_name. | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 154 | "' no child of container '". | ||||||||||||||
| 155 | $self->get_name."'" unless $found; | ||||||||||||||
| 156 | |||||||||||||||
| 157 | 0 | splice @{$self->get_content}, $i, 1; | |||||||||||||
| 158 | |||||||||||||||
| 159 | 0 | ▶ | return unless $self->get_built; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 160 | |||||||||||||||
| 161 | 0 | my $child_gtk_widget = $child->get_gtk_parent_widget; | |||||||||||||
| 162 | 0 | my $gtk_widget = $self->get_gtk_widget; | |||||||||||||
| 163 | |||||||||||||||
| 164 | 0 | $gtk_widget->remove($child_gtk_widget); | |||||||||||||
| 165 | |||||||||||||||
| 166 | 0 | $child->cleanup; | |||||||||||||
| 167 | |||||||||||||||
| 168 | 0 | 1; | |||||||||||||
| 169 | } | ||||||||||||||
| 170 | |||||||||||||||
| 171 | 0 | ▶ | sub update_all { | ||||||||||||
|
Subroutine
update_all: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||
| 172 | 0 | my $self = shift; | |||||||||||||
| 173 | |||||||||||||||
| 174 | 0 | $self->SUPER::update(@_); | |||||||||||||
| 175 | 0 | foreach my $c ( @{$self->get_content} ) { | |||||||||||||
| 176 | 0 | $c->update_all; | |||||||||||||
| 177 | } | ||||||||||||||
| 178 | |||||||||||||||
| 179 | 0 | 1; | |||||||||||||
| 180 | } | ||||||||||||||
| 181 | |||||||||||||||
| 182 | 0 | ▶ | sub apply_changes_all { | ||||||||||||
|
Subroutine
apply_changes_all: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||
| 183 | 0 | my $self = shift; | |||||||||||||
| 184 | |||||||||||||||
| 185 | 0 | $self->SUPER::apply_changes(@_); | |||||||||||||
| 186 | |||||||||||||||
| 187 | 0 | foreach my $c ( @{$self->get_content} ) { | |||||||||||||
| 188 | 0 | $c->apply_changes_all; | |||||||||||||
| 189 | } | ||||||||||||||
| 190 | |||||||||||||||
| 191 | 0 | 1; | |||||||||||||
| 192 | } | ||||||||||||||
| 193 | |||||||||||||||
| 194 | 0 | ▶ | sub commit_proxy_buffers_all { | ||||||||||||
|
Subroutine
commit_proxy_buffers_all: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||
| 195 | 0 | my $self = shift; | |||||||||||||
| 196 | |||||||||||||||
| 197 | 0 | $self->SUPER::commit_proxy_buffers(@_); | |||||||||||||
| 198 | |||||||||||||||
| 199 | 0 | foreach my $c ( @{$self->get_content} ) { | |||||||||||||
| 200 | 0 | $c->commit_proxy_buffers_all; | |||||||||||||
| 201 | } | ||||||||||||||
| 202 | |||||||||||||||
| 203 | 0 | 1; | |||||||||||||
| 204 | } | ||||||||||||||
| 205 | |||||||||||||||
| 206 | 0 | ▶ | sub discard_proxy_buffers_all { | ||||||||||||
|
Subroutine
discard_proxy_buffers_all: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||
| 207 | 0 | my $self = shift; | |||||||||||||
| 208 | |||||||||||||||
| 209 | 0 | $self->SUPER::discard_proxy_buffers(@_); | |||||||||||||
| 210 | |||||||||||||||
| 211 | 0 | foreach my $c ( @{$self->get_content} ) { | |||||||||||||
| 212 | 0 | $c->discard_proxy_buffers_all; | |||||||||||||
| 213 | } | ||||||||||||||
| 214 | |||||||||||||||
| 215 | 0 | 1; | |||||||||||||
| 216 | } | ||||||||||||||
| 217 | |||||||||||||||
| 218 | 0 | ▶ | sub connect_signals { | ||||||||||||
|
Subroutine
connect_signals: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||
| 219 | 0 | my $self = shift; | |||||||||||||
| 220 | |||||||||||||||
| 221 | 0 | $self->SUPER::connect_signals(@_); | |||||||||||||
| 222 | |||||||||||||||
| 223 | 0 | foreach my $c ( @{$self->get_content} ) { | |||||||||||||
| 224 | 0 | $c->connect_signals; | |||||||||||||
| 225 | } | ||||||||||||||
| 226 | |||||||||||||||
| 227 | 0 | 1; | |||||||||||||
| 228 | } | ||||||||||||||
| 229 | |||||||||||||||
| 230 | 0 | ▶ | sub cleanup { | ||||||||||||
|
Subroutine
cleanup: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||
| 231 | 0 | my $self = shift; | |||||||||||||
| 232 | |||||||||||||||
| 233 | 0 | foreach my $c ( @{$self->get_content} ) { | |||||||||||||
| 234 | 0 | $c->cleanup; | |||||||||||||
| 235 | } | ||||||||||||||
| 236 | |||||||||||||||
| 237 | 0 | $self->SUPER::cleanup(@_); | |||||||||||||
| 238 | |||||||||||||||
| 239 | 0 | $self->set_content([]); | |||||||||||||
| 240 | |||||||||||||||
| 241 | 0 | 1; | |||||||||||||
| 242 | } | ||||||||||||||
| 243 | |||||||||||||||
| 244 | 2 | 1; | |||||||||||||
| 245 | |||||||||||||||
| 246 | __END__ | ||||||||||||||