| 1 | # Copyright 2010, 2019 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 <http://www.gnu.org/licenses/>. | ||
| 17 | |||
| 18 | package Gtk2::Ex::Dashes::MenuItem; | ||
| 19 | 3 | ▶ | use 5.008; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 20 | 3 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 21 | 3 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 22 | 0 | ▶ | use Gtk2; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 23 | |||
| 24 | # uncomment this to run the commented-out ### lines | ||
| 25 | #use Smart::Comments; | ||
| 26 | |||
| 27 | our $VERSION = 3; | ||
| 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__ | ||