App/Chart/Gtk2/Ex/ToplevelBits.pm

filter: Statementstmt 33.3% 18 / 54 Branchbran 0.0% 0 / 30 Conditioncond 0.0% 0 / 23 MC/DCmcdc 0.0% 0 / 13 Subroutinesub 60.0% 6 / 10 Podpod 100% 1 / 1 totaltotal 19.0% 25 / 131 CC 24 SCAR 43.0
CC
24
Cov
17%
popup
156.0
_screen
56.0
__ANON__
20.0
CRAP 73.6
« App/Chart/Gtk2/Symlist/Alphabetical.pm ↑ Summary App/Chart/Glib/Ex/DirBroadcast.pm »
1 # parent => $widget ?
2  
3 # Copyright 2007, 2008, 2009, 2010 Kevin Ryde
4  
5 # This file is part of Chart.
6 #
7 # Chart is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by the
9 # Free Software Foundation; either version 3, or (at your option) any later
10 # version.
11 #
12 # Chart is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 # for more details.
16 #
17 # You should have received a copy of the GNU General Public License along
18 # with Chart. If not, see <http://www.gnu.org/licenses/>.
19  
20 package App::Chart::Gtk2::Ex::ToplevelBits;
21 1 ▶use 5.008;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 1 ▶use List::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 1 ▶use App::Chart::Gtk2::Ex::ToplevelSingleton;
Subroutine BEGIN: called CC=1 SCAR=0.0
27  
28 # uncomment this to run the ### lines
29 #use Smart::Comments;
30  
31 # screen
32 # parent
33 # with_properties
34 # init_properties
35 # modal
36 # hide_on_delete
37  
38 sub popup {
39 0 ▶ my ($class, %options) = @_;
Subroutine popup: not called CC=12 SCAR=50.5
Pod documented
40 ### ToplevelBits popup(): $class
41  
42 0 ▶ my $properties = $options{'properties'} || {};
Condition0%0/2
$options{'properties'} || {}
l!l
00
MC/DC0%0/1
$options{'properties'} || {}
$options{'properties'}
Truth table0%0/2
A
A= $options{'properties'}
Aresult
11
00
43 my $screen = _screen
44 0 ▶ ($options{'transient_for'} || $options{'parent'} || $options{'screen'});
Condition0%0/6
$options{'transient_for'} || $options{'parent'} || $options{'screen'}
l!l&&r!l&&!r
000
$options{"transient_for"} or $options{"parent"}
l!l&&r!l&&!r
000
MC/DC0%0/3
$options{'transient_for'} || $options{'parent'} || $options{'screen'}
$options{"transient_for"} $options{"parent"} $options{'screen'}
Truth table0%0/4
A or B || C
A= $options{"transient_for"}B= $options{"parent"}C= $options{'screen'}
ABCresult
1XX1
01X1
0011
0000
45  
46 my $dialog = List::Util::first
47 0 ▶ {$_->isa($class)
Subroutine __ANON__: not called CC=4 SCAR=30.0
Branch: 1 branch
BranchTrueFalseTotal
$_->isa($class) and !defined($screen) || $_->get_screen == $screen and _object_properties_equal($_, $properties) 0 0 0
Condition0%0/6
$_->isa($class) and !defined($screen) || $_->get_screen == $screen
!ll&&!rl&&r
000
not defined $screen or $_->get_screen == $screen
l!l&&r!l&&!r
000
MC/DC0%0/3
$_->isa($class) and !defined($screen) || $_->get_screen == $screen
$_->isa($class) not defined $screen $_->get_screen == $screen
Truth table0%0/4
A and not(B) or C
A= $_->isa($class)B= not defined $screenC= $_->get_screen == $screen
ABCresult
0XX0
1000
11X1
1011
48 && (! defined $screen || $_->get_screen == $screen)
49 && _object_properties_equal($_,$properties)}
50 0 Gtk2::Window->list_toplevels;
51 ### ToplevelBits found: $dialog
52  
53 0 ▶ if ($dialog) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dialog) { } 0 0 0
54 0 ▶ if (exists $options{'modal'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $options{"modal"}) 0 0 0
55 0 $dialog->set_modal ($options{'modal'});
56 }
57 0 ▶ if (exists $options{'transient_for'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $options{"transient_for"}) 0 0 0
58 0 $dialog->set_transient_for ($options{'transient_for'});
59 }
60  
61 } else {
62 ### new dialog $class
63 0 ▶ if (eval { require Gtk2::Ex::WidgetCursor }) {
Branch: 1 branch
BranchTrueFalseTotal
if (eval { do { require Gtk2::Ex::WidgetCursor } }) 0 0 0
64 0 Gtk2::Ex::WidgetCursor->busy;
65 }
66  
67 0 require Module::Load;
68 0 Module::Load::load ($class);
69 $dialog = $class->Glib::Object::new
70 ((defined $screen ? (screen => $screen) : ()),
71 (exists $options{'modal'} ? (modal => $options{'modal'}) : ()),
72 0 ▶ (exists $options{'transient_for'} ? (transient_for => $options{'transient_for'}) : ()),
Branch: 3 branches
BranchTrueFalseTotal
defined $screen ? : 0 0 0
exists $options{'modal'} ? : 0 0 0
exists $options{'transient_for'} ? : 0 0 0
73 %$properties);
74 0 ▶ if ($options{'hide_on_delete'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($options{"hide_on_delete"}) 0 0 0
75 0 $dialog->signal_connect (delete_event => \&Gtk2::Widget::hide_on_delete);
76 }
77 }
78  
79 # if (! $dialog->visible) {
80 # if (my $func = $options{'newly_visible_func'}) {
81 # $func->($dialog);
82 # }
83 # }
84 0 $dialog->present;
85 0 return $dialog;
86 }
87  
88 sub _screen {
89 0 ▶ my ($obj) = @_;
Subroutine _screen: not called CC=7 SCAR=40.3
90 0 ▶ if (! defined $obj) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $obj) 0 0 0
91 0 return Gtk2::Gdk::Screen->get_default;
92 }
93 # don't want $display->get_screen($screennum)
94 0 ▶ if ($obj->isa('Gtk2::Gdk::Display')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($obj->isa("Gtk2::Gdk::Display")) 0 0 0
95 0 return $obj->get_default_screen;
96 }
97 0 ▶ if (my $func = $obj->can('get_screen')) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $func = $obj->can("get_screen")) 0 0 0
98 0 ▶ return $obj->$func || croak "No screen for target $obj";
Condition0%0/3
$obj->$func || croak("No screen for target $obj")
l!l&&r!l&&!r
000
MC/DC0%0/2
$obj->$func || croak("No screen for target $obj")
$obj->$func croak("No screen for target $obj")
Truth table0%0/3
A || B
A= $obj->$funcB= croak("No screen for target $obj")
ABresult
1X1
011
000
99 }
100 0 ▶ if (my $func = $obj->can('get_default_screen')) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $func = $obj->can("get_default_screen")) 0 0 0
101 0 ▶ return $obj->$func || croak "No default screen for target $obj";
Condition0%0/3
$obj->$func || croak("No default screen for target $obj")
l!l&&r!l&&!r
000
MC/DC0%0/2
$obj->$func || croak("No default screen for target $obj")
$obj->$func croak("No default screen for target $obj")
Truth table0%0/3
A || B
A= $obj->$funcB= croak("No default screen for target $obj")
ABresult
1X1
011
000
102 }
103 0 return $obj;
104 }
105  
106 sub _object_properties_equal {
107 0 ▶ my ($obj, $properties) = @_;
Subroutine _object_properties_equal: not called CC=4 SCAR=30.0
108 0 ▶ while (my ($pname, $value) = each %$properties) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$properties) 0 0 0
109 0 ▶ my $pspec = $obj->find_property ($pname)
Condition0%0/3
$obj->find_property($pname) || croak(q[No such property '], $pname, q['])
l!l&&r!l&&!r
000
MC/DC0%0/2
$obj->find_property($pname) || croak(q[No such property '], $pname, q['])
$obj->find_property($pname) croak(q[No such property '], $pname, q['])
Truth table0%0/3
A || B
A= $obj->find_property($pname)B= croak(q[No such property '], $pname, q['])
ABresult
1X1
011
000
110 || croak "No such property '",$pname,"'";
111 0 ▶ if ($pspec->values_cmp ($value, $obj->get($pname)) != 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pspec->values_cmp($value, $obj->get($pname)) != 0) 0 0 0
112 0 return 0;
113 }
114 }
115 0 return 1;
116 }
117  
118 1 1;
119 __END__
120  
121 =for stopwords Ryde Chart
122  
123 =head1 NAME
124  
125 App::Chart::Gtk2::Ex::ToplevelBits -- helpers for Gtk2::Window toplevel widgets
126  
127 =head1 SYNOPSIS
128  
129 use App::Chart::Gtk2::Ex::ToplevelBits;
130  
131 =head1 FUNCTIONS
132  
133 =over 4
134  
135 =item C<< $toplevel = App::Chart::Gtk2::Ex::ToplevelBits::popup ($class, key => value, ...) >>
136  
137 Create or raise a dialog.
138  
139 =over
140  
141 =item C<< screen => $screen >>
142  
143 =item C<< screen => $widget >>
144  
145 =item C<< screen => $display >>
146  
147 The screen on which the dialog should appear, either an existing dialog on
148 that screen or by creating a new one on it.
149  
150 =item C<< properties => $hashref >>
151  
152 Property settings an existing dialog must have, or to be applied on a newly
153 created dialog.
154  
155 =item C<< transient_for => $toplevel >>
156  
157 Set the dialog's C<transient-for> property to the given toplevel
158 C<Gtk2::Window>. This normally makes the window manager keep the dialog on
159 top of the C<$toplevel>.
160  
161 =item C<< modal => $bool >>
162  
163 Set the dialog to modal, or not. Modal forces the user to interact only
164 with this window or dialog, not any of the other application windows.
165  
166 =item C<< hide_on_delete => $bool >>
167  
168 When creating a new dialog, make it do a C<< $dialog->hide >> on a "delete"
169 request from the window manager. This is done in the usual way by
170 connecting C<Gtk2::Widget::hide_on_delete> as a handler for the
171 C<delete-event> signal. The default is to destroy the dialog on delete.
172  
173 =back
174  
175 =back
176  
177 =head1 SEE ALSO
178  
179 L<Gtk2::Window>, L<Gtk2::Dialog>, L<Gtk2::Ex::WidgetBits>
180  
181 =head1 HOME PAGE
182  
183 L<http://user42.tuxfamily.org/chart/index.html>
184  
185 =head1 LICENSE
186  
187 Copyright 2008, 2009, 2010 Kevin Ryde
188  
189 Chart is free software; you can redistribute it and/or modify
190 it under the terms of the GNU General Public License as published by the
191 Free Software Foundation; either version 3, or (at your option) any later
192 version.
193  
194 Chart is distributed in the hope that it will be useful, but
195 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
196 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
197 more details.
198  
199 You should have received a copy of the GNU General Public License along with
200 Chart. If not, see L<http://www.gnu.org/licenses/>.
201  
202 =cut
« App/Chart/Gtk2/Symlist/Alphabetical.pm ↑ Summary App/Chart/Glib/Ex/DirBroadcast.pm »