ConnectProperties/Element/widget.pm untested

filter: Statementstmt 0.0% 0 / 51 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 10 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 0.0% 0 / 12 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 94 CC 3 SCAR 11.5
CC
3
Cov
0%
find_property
6.0
_widget_get_toplevel
6.0
read_signal
2.0
CRAP 3.1
1 # Copyright 2010, 2011, 2012, 2017 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;
20 use 5.008;
21 use strict;
22 use warnings;
23 use Carp;
24 use Glib;
25 use Gtk2;
26 use base 'Glib::Ex::ConnectProperties::Element';
27  
28 our $VERSION = 20;
29  
30  
31 # For reference, among the various "-set" and "-changed" signals,
32 #
33 # parent-set - already a "parent" property
34 #
35 # Other possibilities:
36 # widget#screen-nodefault only when has-screen
37 #
38 # widget#mapped
39 # widget-flags#mapped
40 # change on map-event, unmap-event, or unmap action?
41 #
42 # widget-style#pname style-set prop readable
43 # widget-style#fg.normal writable modify-fg
44 # widget-style#property.foo
45 # widget-style-property#pname style-set prop readable
46 #
47  
48 my %pspecs = (direction => Glib::ParamSpec->enum ('direction',
49 'direction',
50 '', # blurb
51 'Gtk2::TextDirection',
52 'none', # default, unused
53 Glib::G_PARAM_READWRITE),
54 state => Glib::ParamSpec->enum ('state',
55 'state',
56 '', # blurb
57 'Gtk2::StateType',
58 'normal', # default, unused
59 Glib::G_PARAM_READWRITE),
60 toplevel => Glib::ParamSpec->object ('toplevel',
61 'toplevel',
62 '', # blurb
63 'Gtk2::Widget',
64 'readable'),
65 );
66 my $pspec_screen_writable;
67 if (Gtk2::Widget->can('get_screen')) {
68 # get_screen() new in Gtk 2.2
69 $pspecs{'screen'} = Glib::ParamSpec->object ('screen',
70 'screen',
71 '', # blurb
72 'Gtk2::Gdk::Screen',
73 'readable');
74 $pspec_screen_writable = Glib::ParamSpec->object ('screen',
75 'screen',
76 '', # blurb
77 'Gtk2::Gdk::Screen',
78 Glib::G_PARAM_READWRITE);
79 }
80 if (Gtk2::Widget->can('has_screen')) {
81 # has_screen() new in Gtk 2.2
82 $pspecs{'has-screen'} = Glib::ParamSpec->boolean ('has-screen',
83 'has-screen',
84 '', # blurb
85 0, # default
86 'readable');
87 }
88 sub find_property {
89 my ($self) = @_;
90 my $pname = $self->{'pname'};
91 if ($pname eq 'screen' && $self->{'object'}->can('set_screen')) {
92 return $pspec_screen_writable;
93 }
94 return $pspecs{$pname};
95 }
96  
97 my %read_signal = ('has-screen' => 'screen-changed',
98 toplevel => 'hierarchy-changed');
99 sub read_signal {
100 my ($self) = @_;
101 my $pname = $self->{'pname'};
102 return ($read_signal{$pname} || "$pname-changed");
103 }
104  
105 my %get_method = ('has-screen' => 'has_screen',
106 toplevel => \&_widget_get_toplevel,
107 (Gtk2::Widget->can('get_state') # new in Gtk 2.18
108 ? ()
109 : (state => 'state')), # otherwise field directly
110 );
111  
112 sub get_value {
113 my ($self) = @_;
114 my $pname = $self->{'pname'};
115 my $get_method = $get_method{$pname} || "get_$pname";
116 return $self->{'object'}->$get_method;
117 }
118 sub set_value {
119 my ($self, $newval) = @_;
120 my $set_method = "set_$self->{'pname'}";
121 return $self->{'object'}->$set_method ($newval);
122 }
123  
124 sub _widget_get_toplevel {
125 my ($widget) = @_;
126 my $toplevel;
127 return (($toplevel = $widget->get_toplevel) && $toplevel->flags & 'toplevel'
128 ? $toplevel
129 : undef);
130 }
131  
132 1;
133 __END__