3
## Copyright (c) 1997-1998 Graham Barr. All rights reserved.
4
## This program is free software; you can redistribute it and/or modify it
5
## under the same terms as Perl itself.
8
## Base class for the creation of all cloth objects
11
## $Id: Cloth.pm,v 2.2 2001/08/08 09:06:16 eserte Exp $
16
use vars qw($VERSION);
18
$VERSION = sprintf("%d.%02d", q$Revision: 2.2 $ =~ /(\d+)\.(\d+)/);
20
package Tk::Cloth::Object;
22
use vars qw(*Construct *DelegateFor *privateData *TkHash *_OnDestroy);
24
# I cannot inherit from Tk::Widget as I am not a widget, but I do
25
# want to use some of the methods widgets have.
27
*Construct = Tk::Widget->can('Construct');
28
*DelegateFor = Tk::Widget->can('DelegateFor');
29
*privateData = Tk::Widget->can('privateData');
30
*TkHash = Tk::Widget->can('TkHash');
31
*_OnDestroy = Tk::Widget->can('_OnDestroy');
34
## base class for all cloth items
37
package Tk::Cloth::Item;
40
'addtag' => [qw(withtag above all below closest overlapping enclosed)],
41
'select' => [qw(adjust from to)];
43
# Tk::Derived::configure and ::cget call these, as they cannot call SUPER::
44
use vars qw(*configure_self *cget_self *destroy);
46
*configure_self = \&configure;
48
# Tk objects usually has a destroy method
57
my $cloth = $parent->isa('Tk::Cloth::Item')
58
? $parent->cloth : $parent;
62
my @args = $class->CreateArgs($cloth, \%args);
63
my $item = bless {}, $class;
64
my $tag = $class->create($cloth, @args);
66
$item->{'parent'} = $parent;
67
$item->{'cloth'} = $cloth;
68
$item->{'tag'} = $tag;
70
$cloth->{'item_tags'} ||= {};
71
$cloth->{'item_tags'}{$tag} = $item;
73
while($parent->isa('Tk::Cloth::Item')) {
74
$parent->addtagWithtag($item);
75
$parent = $parent->parent;
78
$item->InitObject(\%args);
79
$item->configure(%args) if (%args);
85
shift->cloth->DoWhenIdle(@_);
92
my($class,$cloth,$args) = @_;
94
my $coords = delete $args->{'-coords'};
96
push @args , @{$coords}
105
$cloth->create($class->Tk_type, @_);
108
sub tag { shift->{'tag'} }
109
sub parent { shift->{'parent'} }
110
sub cloth { shift->{'cloth'} }
116
foreach ($item->gettags) {
117
$_->forget($item) if defined $_;
120
$item->cloth->delete($item);
123
# Tk objects usually has a destroy method
131
sub addtag { $_[0]->cloth->addtag(@_) }
132
sub bbox { $_[0]->cloth->bbox(@_) }
133
sub coords { $_[0]->cloth->coords(@_) }
134
sub dchars { $_[0]->cloth->dchars(@_) }
135
sub dtag { $_[0]->cloth->dtag(@_) }
136
sub focus { $_[0]->cloth->itemfocus(@_) }
137
sub gettags { $_[0]->cloth->gettags(@_) }
138
sub icursor { $_[0]->cloth->icursor(@_) }
139
sub index { $_[0]->cloth->index(@_) }
140
sub insert { $_[0]->cloth->insert(@_) }
141
sub configure { $_[0]->cloth->itemconfigure(@_) }
142
sub cget { $_[0]->cloth->itemcget(@_) }
143
sub lower { $_[0]->cloth->itemlower(@_) }
144
sub move { $_[0]->cloth->move(@_) }
145
sub raise { $_[0]->cloth->itemraise(@_) }
146
sub scale { $_[0]->cloth->scale(@_) }
147
sub type { $_[0]->cloth->type(@_) }
148
sub select { $_[0]->cloth->select(@_) }
160
if(ref($cb) && UNIVERSAL::isa($cb,'ARRAY')) {
161
my $meth = shift @$cb;
167
sub { shift; shift->Call(@_)}, Tk::Callback->new($cb), @a
171
$item->cloth->itembind($item,@args);
174
package Tk::Cloth::Text;
175
use base qw(Tk::Cloth::Item);
176
Construct Tk::Cloth::Object 'Text';
177
sub Tk_type { 'text' }
179
package Tk::Cloth::Image;
180
use base qw(Tk::Cloth::Item);
181
Construct Tk::Cloth::Object 'Image';
182
sub Tk_type { 'image' }
184
package Tk::Cloth::Arc;
185
use base qw(Tk::Cloth::Item);
186
Construct Tk::Cloth::Object 'Arc';
187
sub Tk_type { 'arc' }
189
package Tk::Cloth::Bitmap;
190
use base qw(Tk::Cloth::Item);
191
Construct Tk::Cloth::Object 'Bitmap';
192
sub Tk_type { 'bitmap' }
194
package Tk::Cloth::Line;
195
use base qw(Tk::Cloth::Item);
196
Construct Tk::Cloth::Object 'Line';
197
sub Tk_type { 'line' }
199
package Tk::Cloth::Oval;
200
use base qw(Tk::Cloth::Item);
201
Construct Tk::Cloth::Object 'Oval';
202
sub Tk_type { 'oval' }
204
package Tk::Cloth::Polygon;
205
use base qw(Tk::Cloth::Item);
206
Construct Tk::Cloth::Object 'Polygon';
207
sub Tk_type { 'polygon' }
209
package Tk::Cloth::Rectangle;
210
use base qw(Tk::Cloth::Item);
211
Construct Tk::Cloth::Object 'Rectangle';
212
sub Tk_type { 'rectangle' }
214
package Tk::Cloth::Window;
215
use base qw(Tk::Cloth::Item);
216
Construct Tk::Cloth::Object 'Window';
217
sub Tk_type { 'window' }
219
package Tk::Cloth::Grid;
220
use base qw(Tk::Cloth::Item);
221
Construct Tk::Cloth::Object 'Grid';
222
sub Tk_type { 'grid' }
224
package Tk::Cloth::Tag;
225
# with Tk::Derived in @ISA, Tag did not work anymore
226
use base qw(Tk::Cloth::Item Tk::Cloth::Object);
227
Construct Tk::Cloth::Object 'Tag';
229
sub Tk_type { 'tag' }
230
sub BackTrace { shift->cloth->BackTrace(@_); }
233
shift->cloth->optionGet(@_);
240
my @ch = $del->children;
241
shift(@ch)->delete(@ch)
245
shift->cloth->delete(@_)
250
my($item,$subitem) = @_;
253
return unless exists $item->{SubWidget};
254
my $sw = $item->{SubWidget};
256
while(($k,$v) = each %$sw) {
257
next unless $v == $subitem;
272
my $DEFname = 'tag00000000';
278
my $name = $DEFname++;
279
my @args = ($name, 'withtag', '...none...');
286
$item->cloth->findWithtag($item)
293
shift->Subwidget(@_);
305
'addtag' => [qw(withtag above all below closest overlapping enclosed)],
306
'find' => [qw(withtag above all below closest overlapping enclosed)],
307
'select' => [qw(adjust clear from item to)];
309
Construct Tk::Widget 'Cloth';
311
# Make sure we can create items on the cloth
313
use vars qw(*bind *raise *lower *focus);
314
use base qw(Tk::Cloth::Object Tk::Derived Tk::Canvas);
316
*bind = Tk::Widget->can('bind');
317
*raise = Tk::Widget->can('raise');
318
*lower = Tk::Widget->can('lower');
319
*focus = Tk::Widget->can('focus');
323
my @args = map { ref($_) ? $_->tag : $_ } @_;
325
$cloth->SUPER::addtag(@args);
330
$cloth->SUPER::bbox(map { $_->tag } @_);
337
$cloth->SUPER::bind($item->tag,@_);
343
$cloth->SUPER::coords($item->tag, @_);
349
$cloth->SUPER::dchars($item->tag, @_);
358
push @tags, $item->tag;
359
foreach $parent ($item->gettags) {
360
$parent->forget($item) if defined $parent;
364
delete @{$cloth->{'item_tags'}}{@tags};
365
$cloth->SUPER::delete(@tags);
375
@tag = ( $tag->tag );
380
foreach $tag ($item->gettags) {
381
$tag->forget($item) if defined $tag;
385
$cloth->SUPER::dtag($item->tag, @tag);
390
my @tag = $cloth->SUPER::find(map { ref($_) ? $_->tag : $_ } @_);
391
@{$cloth->{'item_tags'}}{@tag};
396
my @args = @_ ? ( shift->tag ) : ();
397
$cloth->SUPER::focus(@args);
402
my @tag = $cloth->SUPER::gettags(shift->tag);
403
@{$cloth->{'item_tags'}}{@tag};
409
$cloth->SUPER::icursor($item->tag, @_);
415
$cloth->SUPER::index($item->tag, @_);
421
$cloth->SUPER::insert($item->tag, @_);
427
$cloth->SUPER::itemcget($item->tag, @_);
433
$cloth->SUPER::itemconfigure($item->tag, @_);
438
$cloth->SUPER::lower( map { $_->tag } @_);
444
$cloth->SUPER::move($item->tag, @_);
449
$cloth->SUPER::raise( map { $_->tag } @_);
454
my $r = $cloth->SUPER::select(map { ref($_) ? $_->tag : $_ } @_);
455
$r = $cloth->{'item_tags'}{$r}
456
if(defined($r) && exists $cloth->{'item_tags'}{$r});
463
$cloth->SUPER::scale($item->tag, @_);
469
$cloth->SUPER::type($item->tag);
478
Tk::Cloth - An OO Tk Canvas
484
$cloth = $parent->Cloth;
485
$cloth->pack(-fill => 'both', -expand => 1);
487
$rect = $cloth->Rectangle(
488
-coords => [ 0,0,100,100],
494
-coords => [10,10,100,100],
495
-foreground => 'black'
498
-coords => [50,50,100,100],
499
-foreground => 'black'
503
$tag->bind("<1>", [ &button1 ]);
507
B<Tk::Cloth> provides an object-orientated approach to a canvas and canvas
512
L<Tk::Canvas|Tk::Canvas>
516
Graham Barr E<lt>F<gbarr@pobox.com>E<gt>
518
Current maintainer is Slaven Rezic E<lt>F<slaven.rezic@berlin.de>E<gt>.
522
Copyright (c) 1997-1998 Graham Barr. All rights reserved.
523
This program is free software; you can redistribute it and/or modify it
524
under the same terms as Perl itself.