File Coverage

blib/lib/Gtk2/Ex/Dashes/MenuItem.pm
Criterion Covered Total %
statement 10 12 83.3
branch n/a
condition n/a
subroutine 4 4 100.0
pod n/a
total 14 16 87.5


line stmt bran cond sub pod time code
1             # Copyright 2010 Kevin Ryde
2              
3             # This file is part of Gtk2-Ex-Dashes.
4             #
5             # Gtk2-Ex-Dashes is free software; you can redistribute it and/or modify it
6             # under the terms of the GNU General Public License as published by the Free
7             # Software Foundation; either version 3, or (at your option) any later
8             # version.
9             #
10             # Gtk2-Ex-Dashes 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-Dashes. If not, see .
17              
18             package Gtk2::Ex::Dashes::MenuItem;
19 2     2   34547 use 5.008;
  2         6  
  2         64  
20 2     2   10 use strict;
  2         3  
  2         49  
21 2     2   8 use warnings;
  2         3  
  2         41  
22 2     2   2566 use Gtk2;
  0            
  0            
23              
24             # uncomment this to run the commented-out ### lines
25             #use Smart::Comments;
26              
27             our $VERSION = 2;
28              
29             use Glib::Object::Subclass
30             'Gtk2::MenuItem',
31             signals => { direction_changed => \&_do_direction_changed };
32              
33             sub INIT_INSTANCE {
34             my ($self) = @_;
35              
36             require Gtk2::Ex::Dashes;
37             my $dashes = Gtk2::Ex::Dashes->new (visible => 1,
38             xalign => 0);
39             $self->add ($dashes);
40              
41             # Is it necessary to set the initial direction, or will the initial be the
42             # same for the two widgets anyway?
43             ### initial child set_direction
44             $self->get_child->set_direction ($self->get_direction);
45              
46             # The initial style is just the default, a real style is set later when
47             # MenuItem gets into a toplevel tree, so must signal_connect() to set ypad
48             # from the real thickness. Or would a fixed 2 pixels be enough anyway?
49             #
50             ### initial _ypad_from_style_ythickness
51             $dashes->signal_connect (style_set => \&_ypad_from_style_ythickness);
52             _ypad_from_style_ythickness ($dashes); # initial setting
53              
54             ### done INIT_INSTANCE
55             }
56              
57             sub _ypad_from_style_ythickness {
58             my ($dashes) = @_;
59             ### Dashes-MenuItem _ypad_from_style_ythickness(): $dashes->style->ythickness
60             $dashes->set (ypad => $dashes->style->ythickness);
61             }
62              
63             # Not certain if it's a great idea to propagate the direction from the
64             # parent to the child. If the child is thought of as a display detail it
65             # makes sense, but not if it's supposed to be independently controlled.
66             #
67             sub _do_direction_changed {
68             my ($self) = @_; # ($self, $prev_direction)
69             ### Dashes-MenuItem _do_direction_changed(): $self->get_direction
70             $self->get_child->set_direction ($self->get_direction);
71             return shift->signal_chain_from_overridden(@_);
72             }
73              
74             1;
75             __END__