File: ClutterContainer.t

package info (click to toggle)
libclutter-perl 1.002-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 728 kB
  • ctags: 98
  • sloc: perl: 1,503; ansic: 48; makefile: 9
file content (119 lines) | stat: -rw-r--r-- 2,522 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
package My::FooContainer::Meta;

use Clutter;

use Glib::Object::Subclass
    'Clutter::ChildMeta',
    properties => [
        Glib::ParamSpec->string(
            'foo-name',
            'Foo Name',
            'The name of the foo of a child of FooContainer',
            'blah',
            [ qw( readable writable ) ],
        ),
    ];

package My::FooContainer;

use Clutter;

use Glib::Object::Subclass
    'Clutter::Actor',
    interfaces => [ 'Clutter::Container', ],
    ;

sub ADD {
    my ($self, $child) = @_;

    push @{$self->{children}}, $child;
    $child->set_parent($self);

    $self->signal_emit('actor-added', $child);
    $self->queue_relayout();
}

sub REMOVE {
    my ($self, $child) = @_;

    my @children = ();

    foreach my $actor (@{$self->{children}}) {
        push @children, $actor unless $child eq $actor;
    }

    $self->{children} = \@children;
    $child->unparent();

    $self->signal_emit('actor-removed', $child);
    $self->queue_relayout();
}

sub FOREACH {
    my ($self, $callback, $data) = @_;

    foreach my $child (@{$self->{children}}) {
        &$callback ($child, $data);
    }
}

sub CREATE_CHILD_META {
    my ($self, $actor) = @_;

    my $meta = My::FooContainer::Meta->new();
    $meta->set_container($self);
    $meta->set_actor($actor);

    $self->{meta}->{$actor} = $meta;
}

sub DESTROY_CHILD_META {
    my ($self, $actor) = @_;

    delete $self->{meta}->{$actor};
}

sub GET_CHILD_META {
    my ($self, $actor) = @_;

    warn("No meta-data available for $actor")
        unless $self->{meta}->{$actor};

    return $self->{meta}->{$actor};
}

sub INIT_INSTANCE {
    my ($self) = @_;

    $self->{children} = [];
    $self->{meta}     = {};

    $self->set_child_meta_type('My::FooContainer::Meta');
}

package main;

use Clutter::TestHelper tests => 10;

my $foo = My::FooContainer->new();
isa_ok($foo, 'My::FooContainer');
is($foo->get_child_meta_type(), 'My::FooContainer::Meta');

my $rect = Clutter::Rectangle->new();
$foo->add($rect);
is($rect->get_parent(), $foo, 'parent set');

my $meta = $foo->get_child_meta($rect);
ok($meta, 'child meta');

isa_ok($meta, 'My::FooContainer::Meta', 'meta isa check 1');
isa_ok($meta, 'Clutter::ChildMeta', 'meta isa check 2');

is($meta->get_container(), $foo, 'container set');
is($meta->get_actor(), $rect, 'actor set');

is($foo->child_get($rect, 'foo-name'), 'blah', 'child_get');
$foo->child_set($rect, 'foo-name', 'baz');
is($foo->child_get($rect, 'foo-name'), 'baz', 'child_set');

$foo->destroy();