line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Copyright 2011, 2012 Kevin Ryde |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# This file is part of Gtk2-Ex-WidgetBits. |
4
|
|
|
|
|
|
|
# |
5
|
|
|
|
|
|
|
# Gtk2-Ex-WidgetBits 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-WidgetBits is distributed in the hope that it will be useful, |
11
|
|
|
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
12
|
|
|
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
13
|
|
|
|
|
|
|
# Public License for more details. |
14
|
|
|
|
|
|
|
# |
15
|
|
|
|
|
|
|
# You should have received a copy of the GNU General Public License along |
16
|
|
|
|
|
|
|
# with Gtk2-Ex-WidgetBits. If not, see . |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
package Gtk2::Ex::ToolItem::CheckButton; |
19
|
3
|
|
|
3
|
|
2725
|
use 5.008; |
|
3
|
|
|
|
|
32
|
|
|
3
|
|
|
|
|
130
|
|
20
|
3
|
|
|
3
|
|
178
|
use strict; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
112
|
|
21
|
3
|
|
|
3
|
|
16
|
use warnings; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
117
|
|
22
|
3
|
|
|
3
|
|
13379
|
use Gtk2; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
use Scalar::Util; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
# uncomment this to run the ### lines |
26
|
|
|
|
|
|
|
#use Smart::Comments; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
our $VERSION = 48; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
use Glib::Object::Subclass |
31
|
|
|
|
|
|
|
'Gtk2::ToolItem', |
32
|
|
|
|
|
|
|
interfaces => [ |
33
|
|
|
|
|
|
|
# Gtk2::Buildable new in Gtk 2.12, omit if not available |
34
|
|
|
|
|
|
|
Gtk2::Widget->isa('Gtk2::Buildable') ? 'Gtk2::Buildable' : (), |
35
|
|
|
|
|
|
|
], |
36
|
|
|
|
|
|
|
signals => { destroy => \&_do_destroy, |
37
|
|
|
|
|
|
|
notify => \&_do_notify, |
38
|
|
|
|
|
|
|
create_menu_proxy => \&_do_create_menu_proxy, |
39
|
|
|
|
|
|
|
}, |
40
|
|
|
|
|
|
|
properties => [ Glib::ParamSpec->string |
41
|
|
|
|
|
|
|
('active', |
42
|
|
|
|
|
|
|
'Active', |
43
|
|
|
|
|
|
|
'Blurb.', |
44
|
|
|
|
|
|
|
'', |
45
|
|
|
|
|
|
|
Glib::G_PARAM_READWRITE), |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
Glib::ParamSpec->string |
48
|
|
|
|
|
|
|
('label', |
49
|
|
|
|
|
|
|
'Label', |
50
|
|
|
|
|
|
|
'Blurb.', |
51
|
|
|
|
|
|
|
'', |
52
|
|
|
|
|
|
|
Glib::G_PARAM_READWRITE), |
53
|
|
|
|
|
|
|
]; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub INIT_INSTANCE { |
56
|
|
|
|
|
|
|
my ($self) = @_; |
57
|
|
|
|
|
|
|
my $checkbutton = Gtk2::CheckButton->new; |
58
|
|
|
|
|
|
|
$checkbutton->show; |
59
|
|
|
|
|
|
|
$checkbutton->signal_connect ('notify::active', |
60
|
|
|
|
|
|
|
\&_do_checkbutton_notify_active); |
61
|
|
|
|
|
|
|
$self->add ($checkbutton); |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub FINALIZE_INSTANCE { |
65
|
|
|
|
|
|
|
my ($self) = @_; |
66
|
|
|
|
|
|
|
### CheckButton FINALIZE_INSTANCE() ... |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
# must explicitly destroy MenuItem since it normally has a circular |
69
|
|
|
|
|
|
|
# reference between the MenuItem and its AccelLabel child |
70
|
|
|
|
|
|
|
if (my $menuitem = delete $self->{'menuitem'}) { |
71
|
|
|
|
|
|
|
$menuitem->destroy; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
sub _do_destroy { |
75
|
|
|
|
|
|
|
my ($self) = @_; |
76
|
|
|
|
|
|
|
### CheckButton _do_destroy()... |
77
|
|
|
|
|
|
|
FINALIZE_INSTANCE($self); # must explicitly destroy the menuitem |
78
|
|
|
|
|
|
|
$self->signal_chain_from_overridden; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub GET_PROPERTY { |
82
|
|
|
|
|
|
|
my ($self, $pspec) = @_; |
83
|
|
|
|
|
|
|
### ToolItem-CheckButton GET_PROPERTY: $pspec->get_name |
84
|
|
|
|
|
|
|
my $checkitem; |
85
|
|
|
|
|
|
|
return (($checkitem = $self->get_child) |
86
|
|
|
|
|
|
|
&& $checkitem->get($pspec->get_name)); |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
sub SET_PROPERTY { |
89
|
|
|
|
|
|
|
my ($self, $pspec, $newval) = @_; |
90
|
|
|
|
|
|
|
### ToolItem-CheckButton SET_PROPERTY: $pspec->get_name |
91
|
|
|
|
|
|
|
my $pname = $pspec->get_name; |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
if ($pname eq 'active' || $pname eq 'label') { |
94
|
|
|
|
|
|
|
foreach my $target ($self->get_child, $self->{'menuitem'}) { |
95
|
|
|
|
|
|
|
if ($target) { |
96
|
|
|
|
|
|
|
$target->set_property ($pname => $newval); |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
} else { |
101
|
|
|
|
|
|
|
$self->{$pname} = $newval; |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
# Not implemented yet, just using the toolitem label ... |
104
|
|
|
|
|
|
|
# if ($pname eq 'overflow_mnemonic') { |
105
|
|
|
|
|
|
|
# # propagate |
106
|
|
|
|
|
|
|
# if (my $menuitem = $self->{'menuitem'}) { |
107
|
|
|
|
|
|
|
# $menuitem->set_label (_mnemonic_text ($self)); |
108
|
|
|
|
|
|
|
# } |
109
|
|
|
|
|
|
|
# } |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
# 'notify' on self |
114
|
|
|
|
|
|
|
sub _do_notify { |
115
|
|
|
|
|
|
|
my ($self, $pspec) = @_; |
116
|
|
|
|
|
|
|
### CheckButton _do_notify() ... |
117
|
|
|
|
|
|
|
$self->signal_chain_from_overridden ($pspec); |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
my $pname = $pspec->get_name; |
120
|
|
|
|
|
|
|
if ($pname eq 'tooltip_text') { |
121
|
|
|
|
|
|
|
if (my $menuitem = $self->{'menuitem'}) { |
122
|
|
|
|
|
|
|
# if tooltip-text available on $self then is available on $menuitem |
123
|
|
|
|
|
|
|
$menuitem->set_property (tooltip_text => $self->get('tooltip-text')); |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
sub _do_checkbutton_notify_active { |
129
|
|
|
|
|
|
|
my ($checkbutton, $pspec, $ref_weak_self) = @_; |
130
|
|
|
|
|
|
|
my $self = $checkbutton->get_parent || return; |
131
|
|
|
|
|
|
|
### ToolItem-CheckButton _do_checkbutton_notify_active() ... |
132
|
|
|
|
|
|
|
if (my $menuitem = $self->{'menuitem'}) { |
133
|
|
|
|
|
|
|
$menuitem->set_active ($checkbutton->get_active); |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
$self->notify('active'); |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
sub _do_create_menu_proxy { |
139
|
|
|
|
|
|
|
my ($self) = @_; |
140
|
|
|
|
|
|
|
### ToolItem-CheckButton _do_create_menu_proxy() ... |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
my $menuitem; |
143
|
|
|
|
|
|
|
if (! ($menuitem = $self->{'menuitem'})) { |
144
|
|
|
|
|
|
|
my $label = $self->get_child->get('label'); |
145
|
|
|
|
|
|
|
$menuitem = $self->{'menuitem'} |
146
|
|
|
|
|
|
|
# CheckMenuItem->new() doesn't like undef, pass no args for that |
147
|
|
|
|
|
|
|
= Gtk2::CheckMenuItem->new (defined $label ? $label : ()); |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
# initial and subsequent sensitivity propagated by GtkToolItem |
150
|
|
|
|
|
|
|
if ($self->find_property('tooltip-text')) { # new in Gtk 2.12 |
151
|
|
|
|
|
|
|
$menuitem->set_property (tooltip_text => $self->get('tooltip-text')); |
152
|
|
|
|
|
|
|
} |
153
|
|
|
|
|
|
|
# or ConnectProperties ... |
154
|
|
|
|
|
|
|
Scalar::Util::weaken (my $weak_self = $self); |
155
|
|
|
|
|
|
|
$menuitem->signal_connect ('notify::active' => \&_do_menu_notify_active, |
156
|
|
|
|
|
|
|
\$weak_self); |
157
|
|
|
|
|
|
|
} |
158
|
|
|
|
|
|
|
$self->set_proxy_menu_item (__PACKAGE__, $menuitem); |
159
|
|
|
|
|
|
|
return 1; |
160
|
|
|
|
|
|
|
} |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
sub _do_menu_notify_active { |
164
|
|
|
|
|
|
|
my ($menuitem, $pspec, $ref_weak_self) = @_; |
165
|
|
|
|
|
|
|
### ToolItem-CheckButton _do_menu_notify_active()... |
166
|
|
|
|
|
|
|
my $self = $$ref_weak_self || return; |
167
|
|
|
|
|
|
|
my $checkitem = $self->get_child || return; |
168
|
|
|
|
|
|
|
$checkitem->set_active ($menuitem->get_active); |
169
|
|
|
|
|
|
|
} |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
sub get_active { |
172
|
|
|
|
|
|
|
my ($self) = @_; |
173
|
|
|
|
|
|
|
my $checkitem; |
174
|
|
|
|
|
|
|
return (($checkitem = $self->get_child) |
175
|
|
|
|
|
|
|
&& $checkitem->get_active); |
176
|
|
|
|
|
|
|
} |
177
|
|
|
|
|
|
|
sub set_active { |
178
|
|
|
|
|
|
|
my ($self, $active) = @_; |
179
|
|
|
|
|
|
|
if (my $checkitem = $self->get_child) { |
180
|
|
|
|
|
|
|
$checkitem->set_active ($active); |
181
|
|
|
|
|
|
|
} |
182
|
|
|
|
|
|
|
} |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
185
|
|
|
|
|
|
|
# Gtk2::Buildable interface |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
sub GET_INTERNAL_CHILD { |
188
|
|
|
|
|
|
|
my ($self, $builder, $name) = @_; |
189
|
|
|
|
|
|
|
if ($name eq 'checkbutton') { |
190
|
|
|
|
|
|
|
return $self->get_child; |
191
|
|
|
|
|
|
|
} |
192
|
|
|
|
|
|
|
if ($name eq 'overflow_menuitem') { |
193
|
|
|
|
|
|
|
$self->signal_emit ('create-menu-proxy'); |
194
|
|
|
|
|
|
|
return $self->retrieve_proxy_menu_item; |
195
|
|
|
|
|
|
|
} |
196
|
|
|
|
|
|
|
# ENHANCE-ME: Will Gtk2::Buildable expect anything for chaining up? |
197
|
|
|
|
|
|
|
return undef; |
198
|
|
|
|
|
|
|
} |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
1; |
201
|
|
|
|
|
|
|
__END__ |