« blib/lib/Gtk2/Ex/MindMapView/HotSpot/GripFactory.pm
↑ Summary
blib/lib/Gtk2/Ex/MindMapView/Connection.pm »
| 1 | package Gtk2::Ex::MindMapView::Content; | ||
| 2 | |||
| 3 | our $VERSION = '0.000001'; | ||
| 4 | |||
| 5 | use warnings; | ||
| 6 | use strict; | ||
| 7 | use Carp; | ||
| 8 | |||
| 9 | use List::Util; | ||
| 10 | |||
| 11 | use Gnome2::Canvas; | ||
| 12 | |||
| 13 | use constant MIN_WIDTH=>10; | ||
| 14 | use constant MIN_HEIGHT=>10; | ||
| 15 | |||
| 16 | use Gtk2::Ex::MindMapView::ArgUtils; | ||
| 17 | |||
| 18 | sub new | ||
| 19 | { | ||
| 20 | my $class = shift(@_); | ||
| 21 | |||
| 22 | my $self = {}; | ||
| 23 | |||
| 24 | bless $self, $class; | ||
| 25 | |||
| 26 | my %attributes = @_; | ||
| 27 | |||
| 28 | args_required(\%attributes, 'group'); | ||
| 29 | |||
| 30 | args_store($self, \%attributes); | ||
| 31 | |||
| 32 | arg_default($self, "x", 0); | ||
| 33 | |||
| 34 | arg_default($self, "y", 0); | ||
| 35 | |||
| 36 | arg_default($self, "height", MIN_HEIGHT); | ||
| 37 | |||
| 38 | arg_default($self, "width", MIN_WIDTH); | ||
| 39 | |||
| 40 | arg_default($self, "min_width", MIN_WIDTH); | ||
| 41 | |||
| 42 | arg_default($self, "min_height", MIN_HEIGHT); | ||
| 43 | |||
| 44 | return $self; | ||
| 45 | } | ||
| 46 | |||
| 47 | |||
| 48 | # my $image = $content->content_get_image(); | ||
| 49 | |||
| 50 | sub content_get_image | ||
| 51 | { | ||
| 52 | my $self = shift(@_); | ||
| 53 | |||
| 54 | croak "You must supply a content image by overriding 'content_get_image'.\n"; | ||
| 55 | } | ||
| 56 | |||
| 57 | |||
| 58 | # $self->content_set_x($value); | ||
| 59 | |||
| 60 | sub content_set_x | ||
| 61 | { | ||
| 62 | my ($self, $value) = @_; | ||
| 63 | |||
| 64 | croak "You must set the content x coordinate by overriding 'content_set_x'.\n"; | ||
| 65 | } | ||
| 66 | |||
| 67 | |||
| 68 | # $self->content_set_y($value); | ||
| 69 | |||
| 70 | sub content_set_y | ||
| 71 | { | ||
| 72 | my ($self, $value) = @_; | ||
| 73 | |||
| 74 | croak "You must set the content y coordinate by overriding 'content_set_y'.\n"; | ||
| 75 | } | ||
| 76 | |||
| 77 | |||
| 78 | # $self->content_set_width($value); | ||
| 79 | |||
| 80 | sub content_set_width | ||
| 81 | { | ||
| 82 | my ($self, $value) = @_; | ||
| 83 | |||
| 84 | croak "You must set the content width by overriding 'content_set_width'.\n"; | ||
| 85 | } | ||
| 86 | |||
| 87 | |||
| 88 | # $self->content_set_height($value); | ||
| 89 | |||
| 90 | sub content_set_height | ||
| 91 | { | ||
| 92 | my ($self, $value) = @_; | ||
| 93 | |||
| 94 | croak "You must set the content height by overriding 'content_set_height'.\n"; | ||
| 95 | } | ||
| 96 | |||
| 97 | |||
| 98 | # $self->content_set_param($param_name, $value); | ||
| 99 | |||
| 100 | sub content_set_param | ||
| 101 | { | ||
| 102 | my ($self, $param_name, $value) = @_; | ||
| 103 | } | ||
| 104 | |||
| 105 | |||
| 106 | # my @values = $content->get(qw(x y width height)); | ||
| 107 | |||
| 108 | sub get | ||
| 109 | { | ||
| 110 | my $self = shift(@_); | ||
| 111 | |||
| 112 | return undef if (scalar @_ == 0); | ||
| 113 | |||
| 114 | return _get($self, shift(@_)) if (scalar @_ == 1); | ||
| 115 | |||
| 116 | my @values = (); | ||
| 117 | |||
| 118 | foreach my $param_name (@_) { push @values, _get($self, $param_name); } | ||
| 119 | |||
| 120 | return @values; | ||
| 121 | } | ||
| 122 | |||
| 123 | # $canvas->reparent($group); | ||
| 124 | |||
| 125 | sub reparent | ||
| 126 | { | ||
| 127 | my ($self, $group) = @_; | ||
| 128 | |||
| 129 | $self->{group} = $group; | ||
| 130 | |||
| 131 | #FIXME: shouldn't reference image here...?? | ||
| 132 | $self->{image}->reparent($group); | ||
| 133 | } | ||
| 134 | |||
| 135 | # $content->set(x=>0, y=>10, width=>20, height=>30); | ||
| 136 | |||
| 137 | sub set | ||
| 138 | { | ||
| 139 | my $self = shift(@_); | ||
| 140 | |||
| 141 | my %attributes = @_; | ||
| 142 | |||
| 143 | foreach my $param_name (keys %attributes) | ||
| 144 | { | ||
| 145 | my $value = $attributes{$param_name}; | ||
| 146 | |||
| 147 | if ($param_name eq 'x') | ||
| 148 | { | ||
| 149 | next if ($self->{x} == $value); | ||
| 150 | |||
| 151 | $self->{x} = $value; | ||
| 152 | |||
| 153 | $self->content_set_x($value); | ||
| 154 | |||
| 155 | next; | ||
| 156 | } | ||
| 157 | |||
| 158 | if ($param_name eq 'y') | ||
| 159 | { | ||
| 160 | next if ($self->{y} == $value); | ||
| 161 | |||
| 162 | $self->{y} = $value; | ||
| 163 | |||
| 164 | $self->content_set_y($value); | ||
| 165 | |||
| 166 | next; | ||
| 167 | } | ||
| 168 | |||
| 169 | if ($param_name eq 'height') | ||
| 170 | { | ||
| 171 | next if ($self->{height} == $value); | ||
| 172 | |||
| 173 | $self->{height} = $value; | ||
| 174 | |||
| 175 | $self->content_set_height($value); | ||
| 176 | |||
| 177 | next; | ||
| 178 | } | ||
| 179 | |||
| 180 | if ($param_name eq 'width') | ||
| 181 | { | ||
| 182 | next if ($self->{width} == $value); | ||
| 183 | |||
| 184 | $self->{width} = $value; | ||
| 185 | |||
| 186 | $self->content_set_width($value); | ||
| 187 | |||
| 188 | next; | ||
| 189 | } | ||
| 190 | |||
| 191 | $self->content_set_param($param_name, $value); | ||
| 192 | } | ||
| 193 | } | ||
| 194 | |||
| 195 | |||
| 196 | sub get_min_height | ||
| 197 | { | ||
| 198 | my $self = shift(@_); | ||
| 199 | |||
| 200 | return $self->{min_height}; | ||
| 201 | } | ||
| 202 | |||
| 203 | |||
| 204 | sub get_min_width | ||
| 205 | { | ||
| 206 | my $self = shift(@_); | ||
| 207 | |||
| 208 | return $self->{min_width}; | ||
| 209 | } | ||
| 210 | |||
| 211 | |||
| 212 | sub _get | ||
| 213 | { | ||
| 214 | my ($self, $param_name) = @_; | ||
| 215 | |||
| 216 | my $value = $self->{$param_name}; | ||
| 217 | |||
| 218 | croak "Undefined value for key $param_name.\n" if (!defined $value); | ||
| 219 | |||
| 220 | return $value; | ||
| 221 | } | ||
| 222 | |||
| 223 | |||
| 224 | |||
| 225 | 1; # Magic true value required at end of module | ||
| 226 | __END__ |