App/Chart/Gtk2/Ex/MenuBits.pm untested

filter: Statementstmt 0.0% 0 / 28 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 52 CC 3 SCAR 16.7
CC
3
Cov
0%
menu_popup_for_event
12.0
position_screen_centre
2.0
event_is_button_press
2.0
CRAP 5.3
1 # centre of screen instead of under mouse ?
2  
3  
4 # Copyright 2007, 2008, 2009, 2010, 2011, 2015 Kevin Ryde
5  
6 # This file is part of Chart.
7 #
8 # Chart is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by the
10 # Free Software Foundation; either version 3, or (at your option) any later
11 # version.
12 #
13 # Chart is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 # for more details.
17 #
18 # You should have received a copy of the GNU General Public License along
19 # with Chart. If not, see <http://www.gnu.org/licenses/>.
20  
21 package App::Chart::Gtk2::Ex::MenuBits;
22 use 5.008;
23 use strict;
24 use warnings;
25 use Gtk2 1.200; # for Gtk2::GDK_CURRENT_TIME()
26  
27 # uncomment this to run the ### lines
28 #use Smart::Comments;
29  
30 sub position_screen_centre {
31 my ($menu) = @_;
32 ### position_screen_centre()
33  
34 my $menu_req = $menu->requisition;
35 my $screen = $menu->get_screen;
36  
37 # returning $push_in==1 will move these if negative due to menu bigger
38 # than screen
39 my $x = int (($screen->get_width - $menu_req->width)/ 2);
40 my $y = int (($screen->get_height - $menu_req->height) / 2);
41 ### $x
42 ### $y
43 return ($x, $y, 1);
44 }
45  
46 # usually $event->button, $event->time is enough ...
47 #
48 sub menu_popup_for_event {
49 my ($menu, $event) = @_;
50 my $button = (Scalar::Util::blessed($event) && event_is_button_press($event)
51 ? $event->button : 0);
52 my $time = (Scalar::Util::blessed($event) && $event->can('time')
53 ? $event->time
54 : Gtk2::GDK_CURRENT_TIME); # 1.200 or something
55 $menu->popup (undef, # parent menushell
56 undef, # parent menuitem
57 undef, # position func
58 undef, # data
59 $button,
60 $time);
61 }
62  
63 my %event_types_button_press = ('button-press' => 1,
64 '2button-press' => 1,
65 '3button-press' => 1);
66  
67 # return true if $event is a button press, either a plain press or a double
68 # or triple click
69 sub event_is_button_press {
70 my ($event) = @_;
71 return $event_types_button_press{$event->type};
72 }
73  
74 1;
75 __END__