ComboBox/Text.pm

filter: Statementstmt 85.7% 12 / 14 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 5 / 5 Podpod n/a totaltotal 89.4% 17 / 19 CC 1 SCAR 0.6
CC
1
Cov
86%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
« ComboBox/PixbufType.pm ↑ Summary
1 # Copyright 2010, 2011 Kevin Ryde
2  
3 # This file is part of Gtk2-Ex-ComboBoxBits.
4 #
5 # Gtk2-Ex-ComboBoxBits 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 # Gtk2-Ex-ComboBoxBits is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 # for more details.
14 #
15 # You should have received a copy of the GNU General Public License along
16 # with Gtk2-Ex-ComboBoxBits. If not, see <http://www.gnu.org/licenses/>.
17  
18 package Gtk2::Ex::ComboBox::Text;
19 1 ▶use 5.008;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 0 ▶use Gtk2;
Subroutine BEGIN: called CC=1 SCAR=2.6
24 use Scalar::Util;
25 use Gtk2::Ex::ComboBoxBits 'set_active_text';
26  
27 # uncomment this to run the ### lines
28 #use Smart::Comments;
29  
30 our $VERSION = 32;
31  
32 use Glib::Object::Subclass
33 'Gtk2::ComboBox',
34 signals => { notify => \&_do_notify },
35 properties => [ Glib::ParamSpec->string
36 ('active-text',
37 'Active text',
38 'The selected text value.',
39 (eval {Glib->VERSION(1.240);1}
40 ? undef # default
41 : ''), # no undef/NULL before Perl-Glib 1.240
42 Glib::G_PARAM_READWRITE),
43  
44  
45 # these are not gettable, so the default doesn't matter,
46 # but give undef
47 #
48 Glib::ParamSpec->string
49 ('append-text',
50 'append-text',
51 'Append a text string.',
52 (eval {Glib->VERSION(1.240);1}
53 ? undef # default
54 : ''), # no undef/NULL before Perl-Glib 1.240
55 ['writable']),
56  
57 Glib::ParamSpec->string
58 ('prepend-text',
59 'prepend-text',
60 'Prepend a text string.',
61 (eval {Glib->VERSION(1.240);1}
62 ? undef # default
63 : ''), # no undef/NULL before Perl-Glib 1.240
64 ['writable']),
65 ];
66  
67 # Gtk2::ComboBox::new_text creates a Gtk2::ComboBox, must override to get a
68 # subclass Gtk2::Ex::ComboBoxBits
69 # could think about offering this as a ComboBox::Subclass mix-in
70 sub new_text {
71 return shift->new(@_);
72 }
73  
74 my $renderer = Gtk2::CellRendererText->new;
75  
76 sub INIT_INSTANCE {
77 my ($self) = @_;
78  
79 # same as gtk_combo_box_new_text(), which alas it doesn't make available
80 # for general use
81 $self->set_model (Gtk2::ListStore->new ('Glib::String'));
82 $self->pack_start ($renderer, 1);
83 $self->set_attributes ($renderer, text => 0);
84 }
85  
86 sub GET_PROPERTY {
87 my ($self) = @_;
88 ### Text GET_PROPERTY: $_[1]->get_name
89  
90 # my $pname = $pspec->get_name;
91 # if ($pname eq 'active_text') {
92 return $self->get_active_text;
93 }
94  
95 sub SET_PROPERTY {
96 my ($self, $pspec, $newval) = @_;
97 ### Text SET_PROPERTY: $pspec->get_name, $newval
98  
99 my $pname = $pspec->get_name;
100 if ($pname eq 'active_text') {
101 $self->set_active_text ($newval);
102 } else {
103 # append_text or prepend_text
104 $self->$pname ($newval);
105 }
106 }
107  
108 # 'notify' class closure
109 sub _do_notify {
110 my ($self, $pspec) = @_;
111 ### ComboBox-Test _do_notify()
112 shift->signal_chain_from_overridden (@_);
113  
114 if ($pspec->get_name eq 'active') {
115 $self->notify ('active-text');
116 }
117 }
118  
119 1;
120 __END__
« ComboBox/PixbufType.pm ↑ Summary