1 |
elmex |
1.1 |
package GCE::AttrEdit; |
2 |
|
|
|
3 |
|
|
=head1 NAME |
4 |
|
|
|
5 |
|
|
GCE::AttrEdit - an edit wiget for attributes |
6 |
|
|
|
7 |
|
|
=cut |
8 |
|
|
|
9 |
|
|
use Gtk2; |
10 |
|
|
use Gtk2::Gdk::Keysyms; |
11 |
|
|
use Gtk2::SimpleList; |
12 |
|
|
|
13 |
elmex |
1.19 |
use GCE::Util; |
14 |
elmex |
1.15 |
use GCE::InventoryEditor; |
15 |
|
|
|
16 |
elmex |
1.30 |
use Glib::Object::Subclass Gtk2::HPaned; |
17 |
elmex |
1.3 |
|
18 |
|
|
use Crossfire; |
19 |
elmex |
1.1 |
|
20 |
elmex |
1.30 |
sub save_layout { |
21 |
|
|
my ($self) = @_; |
22 |
|
|
|
23 |
|
|
$::CFG->{attr_view_hpane_pos} = $self->get_position; |
24 |
|
|
} |
25 |
|
|
|
26 |
|
|
sub load_layout { |
27 |
|
|
my ($self) = @_; |
28 |
|
|
|
29 |
elmex |
1.33 |
$self->set_position ($::CFG->{attr_view_hpane_pos} || 350); |
30 |
elmex |
1.30 |
} |
31 |
|
|
|
32 |
elmex |
1.1 |
sub INIT_INSTANCE { |
33 |
|
|
my ($self) = @_; |
34 |
|
|
|
35 |
elmex |
1.23 |
my $pb = $self->{arch_pb} = new_arch_pb; |
36 |
|
|
|
37 |
elmex |
1.30 |
$self->add (my $topvb = Gtk2::VBox->new); |
38 |
|
|
$topvb->pack_start (my $hb2 = Gtk2::HBox->new, 0, 1, 0); |
39 |
|
|
$hb2->pack_start (my $img = $self->{arch_img} = (new_from_pixbuf Gtk2::Image $pb), 0, 0, 0); |
40 |
|
|
$img->set_alignment (0, 0.5); |
41 |
|
|
|
42 |
|
|
$hb2->pack_start (my $lbl = $self->{arch_name_lbl} = Gtk2::Label->new, 0, 0, 0); |
43 |
|
|
$lbl->set_alignment (0, 0.5); |
44 |
|
|
|
45 |
|
|
$hb2->pack_start (my $defbtn = Gtk2::Button->new ('reset to defaults'), 0, 0, 0); |
46 |
|
|
$defbtn->signal_connect (clicked => sub { |
47 |
elmex |
1.32 |
my $ar = $self->{archref}; |
48 |
|
|
$ar->reset_to_defaults; |
49 |
|
|
#XXXAR $self->set_arch ($arch, $self->{change_cb}); |
50 |
elmex |
1.30 |
}); |
51 |
|
|
|
52 |
|
|
$topvb->pack_start (my $docal = Gtk2::Alignment->new (0, 0.5, 0, 1), 0, 1, 0); |
53 |
|
|
$topvb->pack_start (my $usebtn = Gtk2::ToggleButton->new ('show use'), 0, 1, 0); |
54 |
|
|
$topvb->pack_start (my $useal = Gtk2::Alignment->new (0, 0.5, 0, 1), 0, 1, 0); |
55 |
|
|
$topvb->pack_start (my $ntbook = $self->{ntbook} = Gtk2::Notebook->new, 1, 1, 0); |
56 |
|
|
$ntbook->set_scrollable (1); |
57 |
|
|
$docal->add ($self->{doc_lbl} = Gtk2::Label->new); |
58 |
|
|
|
59 |
|
|
$usebtn->set_active (0); |
60 |
|
|
$self->{use_lbl} = Gtk2::Label->new; |
61 |
|
|
$usebtn->signal_connect (toggled => sub { |
62 |
|
|
my ($usebtn) = @_; |
63 |
|
|
|
64 |
|
|
$useal->remove ($_) for $useal->get_children; |
65 |
|
|
if ($usebtn->get_active) { |
66 |
|
|
$useal->add ($self->{use_lbl}); |
67 |
|
|
$self->{use_lbl}->show; |
68 |
elmex |
1.24 |
} |
69 |
|
|
}); |
70 |
elmex |
1.30 |
$self->{doc_lbl}->set_line_wrap (1); |
71 |
|
|
$self->{use_lbl}->set_line_wrap (1); |
72 |
elmex |
1.23 |
|
73 |
elmex |
1.30 |
$self->add2 (my $sw = Gtk2::ScrolledWindow->new); |
74 |
|
|
$sw->set_policy ('automatic', 'automatic'); |
75 |
|
|
$sw->add_with_viewport (my $inv = $self->{inv_edit} = GCE::InventoryEditor->new); |
76 |
elmex |
1.3 |
} |
77 |
|
|
|
78 |
elmex |
1.29 |
#sub spawn_editor { |
79 |
|
|
# my ($arch, $cb) = @_; |
80 |
|
|
# |
81 |
|
|
# my $w = Gtk2::Window->new; |
82 |
|
|
# $w->set_title ("gce - edit attrs"); |
83 |
|
|
# $w->add (my $ae = GCE::AttrEdit->new); |
84 |
|
|
# |
85 |
|
|
# main::set_pos_and_size ($w, $main::CFG->{attr_view}, 200, 200); |
86 |
|
|
# |
87 |
|
|
# $ae->set_arch ($arch, $cb); |
88 |
|
|
# $w->set_title ("gce - edit $arch->{_name}"); |
89 |
|
|
# |
90 |
|
|
# $w->show_all; |
91 |
|
|
#} |
92 |
elmex |
1.23 |
|
93 |
elmex |
1.3 |
sub update_arch { |
94 |
elmex |
1.32 |
my ($self, $ar, $key, $value) = @_; |
95 |
|
|
$ar->set ($key, $value); |
96 |
elmex |
1.1 |
} |
97 |
|
|
|
98 |
elmex |
1.5 |
sub set_attr { |
99 |
|
|
my ($self, $key, $value) = @_; |
100 |
|
|
|
101 |
elmex |
1.32 |
my $attr = $self->{archref}->get ($key); |
102 |
elmex |
1.5 |
|
103 |
|
|
unless (ref $attr) { |
104 |
|
|
|
105 |
elmex |
1.32 |
$self->{archref}->set ($key, $value); |
106 |
elmex |
1.5 |
} |
107 |
|
|
} |
108 |
|
|
|
109 |
elmex |
1.29 |
sub get_arch { |
110 |
|
|
my ($self) = @_; |
111 |
|
|
|
112 |
elmex |
1.32 |
$self->{archref} |
113 |
elmex |
1.29 |
} |
114 |
|
|
|
115 |
elmex |
1.32 |
#sub update { |
116 |
|
|
# my ($self, $narch) = @_; |
117 |
|
|
# |
118 |
|
|
# if (ref ($narch) ne 'GCE::ArchRef') { require Carp; Carp::confess ("NO ARCH REF!") } |
119 |
|
|
# |
120 |
|
|
# if ($narch) { |
121 |
|
|
# $self->set_arch ($narch); |
122 |
|
|
# } else { |
123 |
|
|
# $self->set_arch ($self->{archref}); |
124 |
|
|
# } |
125 |
|
|
#} |
126 |
elmex |
1.30 |
|
127 |
elmex |
1.2 |
sub set_arch { |
128 |
elmex |
1.32 |
my ($self, $ar, $clear_inv) = @_; |
129 |
elmex |
1.7 |
|
130 |
elmex |
1.32 |
if ((defined $self->{archref}) && ($self->{archref} != $ar)) { |
131 |
|
|
$self->{archref}->remove_on_change ('attredit') |
132 |
|
|
if defined $self->{archref}; |
133 |
|
|
$ar->add_on_change (attredit => sub { $self->set_arch ($_[0]) }); |
134 |
elmex |
1.26 |
|
135 |
elmex |
1.32 |
} elsif (not defined $self->{archref}) { |
136 |
|
|
$ar->add_on_change (attredit => sub { $self->set_arch ($_[0]) }); |
137 |
|
|
} |
138 |
elmex |
1.3 |
|
139 |
elmex |
1.4 |
|
140 |
elmex |
1.32 |
$self->{inv_edit}->clear_inv_hist if $clear_inv; |
141 |
|
|
$self->{inv_edit}->set_arch ($ar); |
142 |
elmex |
1.30 |
|
143 |
elmex |
1.32 |
$self->{archref} = $ar; |
144 |
elmex |
1.21 |
|
145 |
elmex |
1.32 |
$self->{arch_name_lbl}->set_text ($ar->longname); |
146 |
elmex |
1.8 |
|
147 |
elmex |
1.32 |
fill_pb_from_arch ($self->{arch_pb}, $ar->getarch); |
148 |
elmex |
1.23 |
$self->{arch_img}->set_from_pixbuf ($self->{arch_pb}); |
149 |
|
|
|
150 |
elmex |
1.32 |
# get current page (to remember it for later) |
151 |
|
|
my $pgnum = $self->{ntbook}->get_current_page; |
152 |
|
|
my $curwid = $self->{ntbook}->get_nth_page ($pgnum); |
153 |
|
|
my $curpage_text = defined $curwid ? $self->{ntbook}->get_tab_label_text ($curwid) : undef; |
154 |
|
|
|
155 |
|
|
my $al_arch = $ar->archetype; |
156 |
|
|
|
157 |
elmex |
1.18 |
$self->hide; |
158 |
|
|
$self->{ntbook}->remove ($_) |
159 |
|
|
for $self->{ntbook}->get_children; |
160 |
elmex |
1.8 |
|
161 |
elmex |
1.18 |
$self->{ttip} = Gtk2::Tooltips->new; |
162 |
elmex |
1.8 |
|
163 |
elmex |
1.32 |
my $type = $ar->type; |
164 |
|
|
|
165 |
|
|
for my $sec (@{$type->{section}}) { |
166 |
elmex |
1.18 |
my $secname = shift @$sec; |
167 |
elmex |
1.32 |
$self->add_section_edit_widgets ($self->{ntbook}, $secname, $ar, $sec); |
168 |
elmex |
1.18 |
} |
169 |
elmex |
1.8 |
|
170 |
elmex |
1.18 |
for my $key (qw/lore msg/) { |
171 |
|
|
$self->{ntbook}->append_page (my $v = Gtk2::VBox->new, $key); |
172 |
|
|
$v->pack_start (my $sw = Gtk2::ScrolledWindow->new, 1, 1, 0); |
173 |
|
|
$sw->set_policy ('automatic', 'automatic'); |
174 |
|
|
$sw->add (my $tb = $self->{"${key}_txt"} = Gtk2::TextView->new); |
175 |
|
|
my $buf = $tb->get_buffer; |
176 |
elmex |
1.32 |
$buf->set_text ($ar->get ($key)); |
177 |
elmex |
1.20 |
$buf->signal_connect (changed => sub { |
178 |
|
|
my ($buf) = @_; |
179 |
elmex |
1.32 |
$ar->set ($key, $buf->get_text ($buf->get_start_iter, $buf->get_end_iter, 0)) |
180 |
elmex |
1.20 |
}); |
181 |
elmex |
1.18 |
} |
182 |
elmex |
1.15 |
|
183 |
elmex |
1.32 |
my $desc = pseudohtml2txt $ar->get ('desc'); |
184 |
|
|
my $use = pseudohtml2txt $ar->get ('use'); |
185 |
elmex |
1.28 |
$self->{doc_lbl}->set_text ($desc); |
186 |
|
|
$self->{use_lbl}->set_text ($use); |
187 |
elmex |
1.25 |
|
188 |
elmex |
1.18 |
$self->{ttip}->enable; |
189 |
elmex |
1.3 |
|
190 |
elmex |
1.18 |
$self->show_all; |
191 |
elmex |
1.26 |
|
192 |
|
|
# reset the current page if found |
193 |
|
|
# XXX: it's braindamaged: it has to be done AFTER show all for some reason |
194 |
|
|
if (defined $curpage_text) { |
195 |
|
|
|
196 |
|
|
for (my $i = 0; $i <= $self->{ntbook}->get_n_pages; $i++) { |
197 |
|
|
my $w = $self->{ntbook}->get_nth_page ($i); |
198 |
|
|
|
199 |
|
|
if ($w && $self->{ntbook}->get_tab_label_text ($w) eq $curpage_text) { |
200 |
|
|
$self->{ntbook}->set_current_page ($i); |
201 |
|
|
last; |
202 |
|
|
} |
203 |
|
|
} |
204 |
|
|
} |
205 |
elmex |
1.8 |
} |
206 |
|
|
|
207 |
|
|
sub add_section_edit_widgets { |
208 |
elmex |
1.32 |
my ($self, $ntbook, $name, $ar, $section) = @_; |
209 |
elmex |
1.8 |
|
210 |
elmex |
1.13 |
$self->{ntbook}->append_page (my $sw = Gtk2::ScrolledWindow->new, $name); |
211 |
elmex |
1.27 |
$sw->set_policy ('automatic', 'automatic'); |
212 |
elmex |
1.13 |
$sw->add_with_viewport (my $vb = Gtk2::VBox->new); |
213 |
elmex |
1.8 |
$vb->pack_start (my $table = new Gtk2::Table (2, $cnt), 0, 1, 0); |
214 |
|
|
|
215 |
|
|
my $i = 0; |
216 |
elmex |
1.11 |
for my $sec (@$section) { |
217 |
elmex |
1.32 |
my ($key, $sec) = ($sec->[0], $sec->[1]); |
218 |
|
|
|
219 |
elmex |
1.28 |
next if grep { $key eq $_ } qw/msg lore/; |
220 |
elmex |
1.32 |
|
221 |
elmex |
1.11 |
my $bwid = Gtk2::EventBox->new; |
222 |
elmex |
1.32 |
$bwid->add (my $al = Gtk2::Alignment->new (0.0, 0.5, 0, 1)); |
223 |
|
|
$al->add (Gtk2::Label->new (def ($sec->{name}, $key))); |
224 |
|
|
|
225 |
elmex |
1.11 |
if ($sec->{desc} !~ m/^\s*$/s) { |
226 |
|
|
$self->{ttip}->set_tip ($bwid, $sec->{desc}); |
227 |
elmex |
1.9 |
} |
228 |
elmex |
1.32 |
|
229 |
elmex |
1.12 |
$table->attach ($bwid, 0, 1, $i, $i + 1, ['shrink','fill'], 'fill', 5, 0); |
230 |
elmex |
1.11 |
|
231 |
|
|
$al = Gtk2::Alignment->new (0.0, 0.5, 1, 0); |
232 |
elmex |
1.32 |
$table->attach ($al, 1, 2, $i, $i + 1, ['expand', 'fill'], 'expand', 0, 0); |
233 |
|
|
$al->add ($self->get_edit_widget ($key, $sec, $ar, $bwid)); |
234 |
|
|
|
235 |
elmex |
1.8 |
$i++; |
236 |
elmex |
1.3 |
} |
237 |
elmex |
1.8 |
} |
238 |
elmex |
1.3 |
|
239 |
elmex |
1.11 |
sub label_set_color_default { |
240 |
elmex |
1.32 |
my ($self, $lbl, $ar, $key, $val) = @_; |
241 |
|
|
require Carp; $ar or Carp::confess ("UNDEF"); |
242 |
|
|
my $al_arch = $ar->archetype; |
243 |
elmex |
1.9 |
|
244 |
elmex |
1.32 |
if ($ar->field_value_is_default ($key, $val)) { |
245 |
elmex |
1.12 |
for (qw/normal active prelight selected insensitive/) { |
246 |
|
|
$lbl->modify_bg ($_, $lbl->get_default_style->bg ('active')); |
247 |
|
|
$lbl->modify_fg ($_, $lbl->get_default_style->fg ('active')); |
248 |
|
|
} |
249 |
elmex |
1.32 |
|
250 |
elmex |
1.12 |
} else { |
251 |
|
|
for (qw/normal active prelight selected insensitive/) { |
252 |
|
|
$lbl->modify_bg ($_, $lbl->get_default_style->bg ($_)); |
253 |
|
|
} |
254 |
|
|
} |
255 |
elmex |
1.9 |
} |
256 |
|
|
|
257 |
elmex |
1.17 |
# XXX: Warning: Ugly code ahead: |
258 |
elmex |
1.8 |
sub get_edit_widget { |
259 |
elmex |
1.32 |
my ($self, $key, $edspec, $ar, $lbl) = @_; |
260 |
elmex |
1.4 |
|
261 |
elmex |
1.32 |
my $type = $edspec->{type}; |
262 |
|
|
my $al_arch = $ar->archetype; |
263 |
elmex |
1.3 |
|
264 |
elmex |
1.8 |
if ($type eq 'bool') { |
265 |
elmex |
1.19 |
my $boolval = def ($edspec->{value}, [0, 1]); |
266 |
elmex |
1.15 |
|
267 |
elmex |
1.32 |
|
268 |
|
|
$self->label_set_color_default ($lbl, $ar, $key, $ar->get_or_default ($key)); |
269 |
|
|
|
270 |
elmex |
1.19 |
my $chk = new Gtk2::CheckButton (def ($edspec->{name}, $key)); |
271 |
elmex |
1.32 |
$chk->set_active ($ar->get_or_default ($key) == $boolval->[1]); |
272 |
|
|
$chk->signal_connect (clicked => sub { |
273 |
|
|
my ($chk) = @_; |
274 |
|
|
|
275 |
|
|
$ar->set_silent ($key, $boolval->[$chk->get_active * 1]); |
276 |
|
|
|
277 |
|
|
$self->label_set_color_default ($lbl, $ar, $key, $boolval->[$chk->get_active * 1]); |
278 |
|
|
}); |
279 |
elmex |
1.15 |
|
280 |
elmex |
1.12 |
$self->{ttip}->set_tip ($chk, $al_arch->{$key} * 1); |
281 |
elmex |
1.15 |
|
282 |
elmex |
1.8 |
return $chk |
283 |
|
|
|
284 |
|
|
} elsif (grep { $type eq $_ } qw/string int treasurelist float/) { |
285 |
elmex |
1.32 |
$self->label_set_color_default ($lbl, $ar, $key, $ar->get_or_default ($key)); |
286 |
|
|
|
287 |
elmex |
1.8 |
my $entry = new Gtk2::Entry; |
288 |
elmex |
1.32 |
$entry->set_text ($ar->get_or_default ($key)); |
289 |
|
|
$entry->signal_connect (changed => sub { |
290 |
|
|
my ($entry) = @_; |
291 |
|
|
$self->label_set_color_default ($lbl, $ar, $key, $entry->get_text); |
292 |
|
|
$ar->set_silent ($key, $entry->get_text); |
293 |
|
|
1 |
294 |
|
|
}); |
295 |
|
|
|
296 |
|
|
$self->{ttip}->set_tip ($entry, $ar->archetype->{$key}); |
297 |
|
|
|
298 |
elmex |
1.8 |
return $entry |
299 |
|
|
|
300 |
|
|
} elsif ($type eq 'spell' or $type eq 'nz_spell') { # XXX: nz_spell bug in datafiles? |
301 |
|
|
my $comb = Gtk2::ComboBox->new_text; |
302 |
|
|
my $spells_idx = {}; |
303 |
|
|
my $spells_cmb_idx = {}; |
304 |
|
|
my $sp = \%Crossfire::Data::SPELL; |
305 |
|
|
|
306 |
|
|
$comb->append_text ("<none>"); |
307 |
|
|
|
308 |
|
|
my $idx = 1; # XXX: replace this idx with a more save/correct method? |
309 |
|
|
for (sort { $sp->{$a} cmp $sp->{$b} } keys %$sp) { |
310 |
|
|
$spells_cmd_idx{$idx} = $_; |
311 |
|
|
$spells_idx{$_} = $idx++; |
312 |
|
|
|
313 |
|
|
$comb->append_text ($sp->{$_}); |
314 |
|
|
} |
315 |
elmex |
1.12 |
#XXX: FIXME: $self->{ttip}->set_tip ($comb, $sp->{$al_arch->{$key}}); |
316 |
elmex |
1.32 |
|
317 |
|
|
$comb->set_active ($spells_idx{$ar->get_or_default ($key)}); |
318 |
|
|
$self->label_set_color_default ($lbl, $ar, $key, $ar->get_or_default ($key)); |
319 |
elmex |
1.8 |
|
320 |
|
|
$comb->signal_connect (changed => sub { |
321 |
|
|
my ($comb) = @_; |
322 |
elmex |
1.32 |
$self->label_set_color_default ($lbl, $ar, $key, $spells_cmd_idx{$comb->get_active}); |
323 |
|
|
$ar->set_silent ($key, $spells_cmd_idx{$comb->get_active}); |
324 |
elmex |
1.8 |
}); |
325 |
|
|
return $comb |
326 |
elmex |
1.3 |
|
327 |
elmex |
1.14 |
} elsif ($type eq 'bitmask') { |
328 |
elmex |
1.32 |
my $chval = $ar->get_or_default ($key); |
329 |
elmex |
1.14 |
my $btn = Gtk2::Button->new; |
330 |
elmex |
1.32 |
$btn->add (my $lblb = Gtk2::Label->new ("bitmask: " . ($chval * 1))); |
331 |
elmex |
1.14 |
$self->{ttip}->set_tip ($btn, $al_arch->{$key}); |
332 |
|
|
|
333 |
elmex |
1.32 |
my $menu = $self->create_bitmask_menu ($edspec->{value}, $lbl, $lblb, $ar, $key, \$chval); |
334 |
|
|
|
335 |
|
|
$self->label_set_color_default ($lbl, $ar, $key, $chval); |
336 |
elmex |
1.14 |
|
337 |
|
|
$btn->signal_connect (button_press_event => sub { |
338 |
|
|
my ($btn, $ev) = @_; |
339 |
|
|
$menu->popup (undef, undef, undef, undef, $ev->button, 0); |
340 |
|
|
}); |
341 |
elmex |
1.32 |
|
342 |
elmex |
1.14 |
return $btn; |
343 |
|
|
|
344 |
|
|
} elsif ($type eq 'list') { |
345 |
elmex |
1.32 |
my $lblb = Gtk2::Label->new ($edspec->{value}->{$ar->get_or_default ($key) * 1}); |
346 |
elmex |
1.14 |
my $btn = Gtk2::Button->new; |
347 |
|
|
$self->{ttip}->set_tip ($btn, $edspec->{value}->{$al_arch->{$key}}); |
348 |
|
|
$btn->add ($lblb); |
349 |
elmex |
1.32 |
my $menu = $self->create_list_menu ($edspec->{value}, $lbl, $lblb, $ar, $key); |
350 |
elmex |
1.14 |
|
351 |
elmex |
1.32 |
$self->label_set_color_default ($lbl, $ar, $key, $ar->get_or_default ($key)); |
352 |
elmex |
1.14 |
|
353 |
|
|
$btn->signal_connect (button_press_event => sub { |
354 |
|
|
my ($btn, $ev) = @_; |
355 |
|
|
$menu->popup (undef, undef, undef, undef, $ev->button, 0); |
356 |
|
|
}); |
357 |
|
|
return $btn; |
358 |
|
|
|
359 |
elmex |
1.8 |
} elsif ($type eq 'fixed') { |
360 |
|
|
return Gtk2::Label->new ("$edspec->{name} = $edspec->{value}"); |
361 |
elmex |
1.3 |
|
362 |
elmex |
1.9 |
} elsif ($type eq 'text') { |
363 |
elmex |
1.20 |
return Gtk2::Label->new ("<see $key tab>"); |
364 |
elmex |
1.9 |
|
365 |
elmex |
1.3 |
} else { |
366 |
elmex |
1.8 |
return Gtk2::Label->new ("$key => $edspec->{name} ($type)"); |
367 |
elmex |
1.2 |
|
368 |
elmex |
1.3 |
} |
369 |
elmex |
1.2 |
} |
370 |
|
|
|
371 |
elmex |
1.14 |
sub bitmask_to_list { |
372 |
|
|
my ($self, $bitlist, $bits) = @_; |
373 |
|
|
|
374 |
|
|
my @l; |
375 |
|
|
for (%$bitlist) { |
376 |
|
|
if ($bits & (1 << $_)) { |
377 |
|
|
push @l, $bitlist->{$_}; |
378 |
|
|
} |
379 |
|
|
} |
380 |
|
|
return @l; |
381 |
|
|
} |
382 |
|
|
|
383 |
|
|
sub create_list_menu { |
384 |
elmex |
1.32 |
my ($self, $list, $clbl, $lbl, $ar, $key) = @_; |
385 |
elmex |
1.14 |
|
386 |
|
|
my $menu = Gtk2::Menu->new; |
387 |
|
|
|
388 |
|
|
for my $item (sort keys %$list) { |
389 |
|
|
my $lbltxt = $list->{$item}; |
390 |
|
|
my $menuitem = Gtk2::MenuItem->new_with_label ($lbltxt); |
391 |
|
|
$menuitem->signal_connect (activate => sub { |
392 |
|
|
my ($menuitem) = @_; |
393 |
|
|
$lbl->set_text ($list->{$item}); |
394 |
elmex |
1.32 |
$self->label_set_color_default ($clbl, $ar, $key, $item); |
395 |
|
|
$ar->set_silent ($key, $item); |
396 |
elmex |
1.14 |
}); |
397 |
|
|
$menu->append ($menuitem); |
398 |
|
|
$menuitem->show; |
399 |
|
|
} |
400 |
|
|
|
401 |
|
|
return $menu; |
402 |
|
|
} |
403 |
|
|
|
404 |
|
|
sub create_bitmask_menu { |
405 |
elmex |
1.32 |
my ($self, $bits, $clbl, $lbl, $ar, $key, $rval) = @_; |
406 |
elmex |
1.14 |
|
407 |
|
|
my $menu = Gtk2::Menu->new; |
408 |
|
|
|
409 |
elmex |
1.29 |
for my $bit (sort { $a <=> $b } keys %$bits) { |
410 |
elmex |
1.14 |
my $lbltxt = $bits->{$bit}; |
411 |
|
|
my $menuitem = Gtk2::CheckMenuItem->new_with_label ($lbltxt); |
412 |
elmex |
1.15 |
if ($$rval & (1 << $bit)) { |
413 |
elmex |
1.14 |
$menuitem->set_active (1);#$arch->{$key} & (1 << $bit)); |
414 |
|
|
} |
415 |
|
|
$menuitem->signal_connect (toggled => sub { |
416 |
|
|
my ($menuitem) = @_; |
417 |
elmex |
1.32 |
my $newval = $ar->get ($key); |
418 |
elmex |
1.15 |
$$rval &= ~(1 << $bit); |
419 |
|
|
$$rval |= (1 << $bit) if $menuitem->get_active; |
420 |
|
|
$lbl->set_text ("bitmask: " . ($$rval * 1)); |
421 |
elmex |
1.32 |
$self->label_set_color_default ($clbl, $ar, $key, $$rval); |
422 |
|
|
$ar->set_silent ($key, $$rval); |
423 |
elmex |
1.14 |
}); |
424 |
|
|
$menu->append ($menuitem); |
425 |
|
|
$menuitem->show; |
426 |
|
|
} |
427 |
|
|
|
428 |
|
|
return $menu; |
429 |
|
|
} |
430 |
|
|
|
431 |
elmex |
1.1 |
|
432 |
|
|
=head1 AUTHOR |
433 |
|
|
|
434 |
|
|
Marc Lehmann <schmorp@schmorp.de> |
435 |
|
|
http://home.schmorp.de/ |
436 |
|
|
|
437 |
|
|
Robin Redeker <elmex@ta-sa.org> |
438 |
|
|
http://www.ta-sa.org/ |
439 |
|
|
|
440 |
|
|
=cut |
441 |
|
|
1; |