| 1 | # Copyright 2010, 2011, 2012 Kevin Ryde | ||
| 2 | |||
| 3 | # This file is part of Glib-Ex-ConnectProperties. | ||
| 4 | # | ||
| 5 | # Glib-Ex-ConnectProperties is free software; you can redistribute it and/or | ||
| 6 | # modify it under the terms of the GNU General Public License as published | ||
| 7 | # by the Free Software Foundation; either version 3, or (at your option) any | ||
| 8 | # later version. | ||
| 9 | # | ||
| 10 | # Glib-Ex-ConnectProperties is distributed in the hope that it will be | ||
| 11 | # useful, but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General | ||
| 13 | # Public License for more details. | ||
| 14 | # | ||
| 15 | # You should have received a copy of the GNU General Public License along | ||
| 16 | # with Glib-Ex-ConnectProperties. If not, see <http://www.gnu.org/licenses/>. | ||
| 17 | |||
| 18 | |||
| 19 | package Glib::Ex::ConnectProperties::Element::widget_allocation; | ||
| 20 | use 5.008; | ||
| 21 | use strict; | ||
| 22 | use warnings; | ||
| 23 | use Glib; | ||
| 24 | use Gtk2; # for Gtk2::Gdk::Rectangle class | ||
| 25 | use base 'Glib::Ex::ConnectProperties::Element'; | ||
| 26 | |||
| 27 | our $VERSION = 20; | ||
| 28 | |||
| 29 | # uncomment this to run the ### lines | ||
| 30 | #use Smart::Comments; | ||
| 31 | |||
| 32 | |||
| 33 | use constant pspec_hash => | ||
| 34 | do { | ||
| 35 | # dummy names and dummy range, just want an "int" type | ||
| 36 | # note paramspec names cannot be empty strings | ||
| 37 | # width/height min is actually 1, but that that doesn't matter as it's | ||
| 38 | # read-only | ||
| 39 | my $pspec = Glib::ParamSpec->int ('x', # name | ||
| 40 | '', # nick | ||
| 41 | '', # blurb | ||
| 42 | -32768, # min | ||
| 43 | 32767, # max | ||
| 44 | 0, # default | ||
| 45 | 'readable'); | ||
| 46 | ({ | ||
| 47 | x => $pspec, | ||
| 48 | y => $pspec, | ||
| 49 | width => $pspec, | ||
| 50 | height => $pspec, | ||
| 51 | rectangle => Glib::ParamSpec->boxed ('rectangle', # name | ||
| 52 | '', # nick | ||
| 53 | '', # blurb | ||
| 54 | 'Gtk2::Gdk::Rectangle', | ||
| 55 | 'readable'), | ||
| 56 | }) | ||
| 57 | }; | ||
| 58 | |||
| 59 | use constant read_signal => 'size-allocate'; | ||
| 60 | |||
| 61 | sub get_value { | ||
| 62 | my ($self) = @_; | ||
| 63 | ### widget_allocation get_value() | ||
| 64 | my $pname = $self->{'pname'}; | ||
| 65 | my $rect = $self->{'object'}->allocation; | ||
| 66 | ### rect: $rect->values | ||
| 67 | if ($pname eq 'rectangle') { | ||
| 68 | return $rect->copy; | ||
| 69 | } | ||
| 70 | return $rect->$pname; | ||
| 71 | } | ||
| 72 | |||
| 73 | 1; | ||
| 74 | __END__ |