ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/gde/GCE/AttrEdit.pm
Revision: 1.43
Committed: Sun Jun 24 08:09:34 2007 UTC (16 years, 11 months ago) by elmex
Branch: MAIN
Changes since 1.42: +39 -29 lines
Log Message:
moved the buttons in the attribute editor into a menu and
added a button which displays the source of the selected
archetype for now until some better mechanism is found.

File Contents

# User Rev Content
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 elmex 1.37 use GCE::AttachEditor;
16 elmex 1.15
17 elmex 1.37 use Glib::Object::Subclass
18     Gtk2::HPaned;
19 elmex 1.3
20     use Crossfire;
21 elmex 1.34 use strict;
22 elmex 1.1
23 elmex 1.30 sub save_layout {
24     my ($self) = @_;
25    
26     $::CFG->{attr_view_hpane_pos} = $self->get_position;
27 elmex 1.35 $::CFG->{attr_view_show_use} = $self->{use_btn}->get_active * 1;
28 elmex 1.37
29     $self->{attach_editor}->save_layout
30     if $self->{attach_editor};
31 elmex 1.30 }
32    
33     sub load_layout {
34     my ($self) = @_;
35    
36 elmex 1.33 $self->set_position ($::CFG->{attr_view_hpane_pos} || 350);
37 elmex 1.35 $self->{use_btn}->set_active ($::CFG->{attr_view_show_use} * 1);
38    
39     $self->{use_al}->remove ($_) for $self->{use_al}->get_children;
40     if ($self->{use_btn}->get_active) {
41     $self->{use_al}->add ($self->{use_lbl});
42     $self->{use_lbl}->show;
43     }
44 elmex 1.30 }
45    
46 elmex 1.1 sub INIT_INSTANCE {
47     my ($self) = @_;
48    
49 elmex 1.23 my $pb = $self->{arch_pb} = new_arch_pb;
50    
51 elmex 1.30 $self->add (my $topvb = Gtk2::VBox->new);
52 elmex 1.43 $topvb->pack_start (my $menubar = Gtk2::MenuBar->new, 0, 0, 0);
53     $menubar->append (my $actions_menu = Gtk2::MenuItem->new ('Actions'));
54     my $actmenu = Gtk2::Menu->new;
55     $actmenu->append (my $defitm = Gtk2::MenuItem->new ('reset to defaults'));
56     $defitm->signal_connect (activate => sub {
57     my $ar = $self->{archref};
58     $ar->reset_to_defaults;
59     #XXXAR $self->set_arch ($arch, $self->{change_cb});
60     });
61    
62     $actmenu->append (my $attitm = Gtk2::MenuItem->new ('attach'));
63     $attitm->signal_connect (activate => sub {
64     my $ar = $self->{archref};
65     return unless $ar;
66     unless ($self->{attach_editor}) {
67     my $w = GCE::AttachEditor->new;
68     $w->set_attachment (
69     $ar->get ('attach'),
70     sub {
71     if (@{$_[0]}) {
72     $ar->set_silent (attach => $_[0])
73     } else {
74     $ar->set_silent (attach => undef)
75     }
76     }
77     );
78     $self->{attach_editor} = $w;
79     $w->signal_connect (destroy => sub { delete $self->{attach_editor} });
80     $w->show_all;
81     }
82     });
83    
84     $actions_menu->set_submenu ($actmenu);
85     $actmenu->show_all;
86    
87 elmex 1.30 $topvb->pack_start (my $hb2 = Gtk2::HBox->new, 0, 1, 0);
88     $hb2->pack_start (my $img = $self->{arch_img} = (new_from_pixbuf Gtk2::Image $pb), 0, 0, 0);
89     $img->set_alignment (0, 0.5);
90    
91     $hb2->pack_start (my $lbl = $self->{arch_name_lbl} = Gtk2::Label->new, 0, 0, 0);
92     $lbl->set_alignment (0, 0.5);
93    
94 elmex 1.43 $hb2->pack_start (my $statbtn = $self->{arch_stat_btn} = Gtk2::Button->new, 0, 0, 0);
95 elmex 1.37
96 elmex 1.30 $topvb->pack_start (my $docal = Gtk2::Alignment->new (0, 0.5, 0, 1), 0, 1, 0);
97 elmex 1.35 $topvb->pack_start (my $usebtn = $self->{use_btn} = Gtk2::ToggleButton->new ('show use'), 0, 1, 0);
98     $topvb->pack_start (my $useal = $self->{use_al} = Gtk2::Alignment->new (0, 0.5, 0, 1), 0, 1, 0);
99 elmex 1.30 $topvb->pack_start (my $ntbook = $self->{ntbook} = Gtk2::Notebook->new, 1, 1, 0);
100     $ntbook->set_scrollable (1);
101     $docal->add ($self->{doc_lbl} = Gtk2::Label->new);
102    
103     $usebtn->set_active (0);
104     $self->{use_lbl} = Gtk2::Label->new;
105     $usebtn->signal_connect (toggled => sub {
106     my ($usebtn) = @_;
107    
108     $useal->remove ($_) for $useal->get_children;
109     if ($usebtn->get_active) {
110     $useal->add ($self->{use_lbl});
111     $self->{use_lbl}->show;
112 elmex 1.24 }
113     });
114 elmex 1.30 $self->{doc_lbl}->set_line_wrap (1);
115     $self->{use_lbl}->set_line_wrap (1);
116 elmex 1.23
117 elmex 1.30 $self->add2 (my $sw = Gtk2::ScrolledWindow->new);
118     $sw->set_policy ('automatic', 'automatic');
119     $sw->add_with_viewport (my $inv = $self->{inv_edit} = GCE::InventoryEditor->new);
120 elmex 1.3 }
121    
122 elmex 1.29 #sub spawn_editor {
123     # my ($arch, $cb) = @_;
124     #
125     # my $w = Gtk2::Window->new;
126     # $w->set_title ("gce - edit attrs");
127     # $w->add (my $ae = GCE::AttrEdit->new);
128     #
129     # main::set_pos_and_size ($w, $main::CFG->{attr_view}, 200, 200);
130     #
131     # $ae->set_arch ($arch, $cb);
132     # $w->set_title ("gce - edit $arch->{_name}");
133     #
134     # $w->show_all;
135     #}
136 elmex 1.23
137 elmex 1.3 sub update_arch {
138 elmex 1.32 my ($self, $ar, $key, $value) = @_;
139     $ar->set ($key, $value);
140 elmex 1.1 }
141    
142 elmex 1.5 sub set_attr {
143     my ($self, $key, $value) = @_;
144    
145 elmex 1.32 my $attr = $self->{archref}->get ($key);
146 elmex 1.5
147     unless (ref $attr) {
148    
149 elmex 1.32 $self->{archref}->set ($key, $value);
150 elmex 1.5 }
151     }
152    
153 elmex 1.29 sub get_arch {
154     my ($self) = @_;
155    
156 elmex 1.32 $self->{archref}
157 elmex 1.29 }
158    
159 elmex 1.32 #sub update {
160     # my ($self, $narch) = @_;
161     #
162     # if (ref ($narch) ne 'GCE::ArchRef') { require Carp; Carp::confess ("NO ARCH REF!") }
163     #
164     # if ($narch) {
165     # $self->set_arch ($narch);
166     # } else {
167     # $self->set_arch ($self->{archref});
168     # }
169     #}
170 elmex 1.30
171 elmex 1.2 sub set_arch {
172 elmex 1.32 my ($self, $ar, $clear_inv) = @_;
173 elmex 1.7
174 elmex 1.32 if ((defined $self->{archref}) && ($self->{archref} != $ar)) {
175     $self->{archref}->remove_on_change ('attredit')
176     if defined $self->{archref};
177     $ar->add_on_change (attredit => sub { $self->set_arch ($_[0]) });
178 elmex 1.38 $self->{attach_editor}->destroy if $self->{attach_editor};
179 elmex 1.26
180 elmex 1.32 } elsif (not defined $self->{archref}) {
181     $ar->add_on_change (attredit => sub { $self->set_arch ($_[0]) });
182     }
183 elmex 1.3
184 elmex 1.32 $self->{inv_edit}->clear_inv_hist if $clear_inv;
185     $self->{inv_edit}->set_arch ($ar);
186 elmex 1.30
187 elmex 1.32 $self->{archref} = $ar;
188 elmex 1.21
189 elmex 1.32 $self->{arch_name_lbl}->set_text ($ar->longname);
190 elmex 1.8
191 elmex 1.32 fill_pb_from_arch ($self->{arch_pb}, $ar->getarch);
192 elmex 1.23 $self->{arch_img}->set_from_pixbuf ($self->{arch_pb});
193 elmex 1.43 $self->label_set_color ($self->{arch_name_lbl}, 0);
194    
195     $self->{arch_stat_btn}->set_label ($ar->{source});
196 elmex 1.23
197 elmex 1.32 # get current page (to remember it for later)
198     my $pgnum = $self->{ntbook}->get_current_page;
199     my $curwid = $self->{ntbook}->get_nth_page ($pgnum);
200     my $curpage_text = defined $curwid ? $self->{ntbook}->get_tab_label_text ($curwid) : undef;
201    
202     my $al_arch = $ar->archetype;
203    
204 elmex 1.18 $self->hide;
205     $self->{ntbook}->remove ($_)
206     for $self->{ntbook}->get_children;
207 elmex 1.8
208 elmex 1.18 $self->{ttip} = Gtk2::Tooltips->new;
209 elmex 1.8
210 elmex 1.32 my $type = $ar->type;
211    
212     for my $sec (@{$type->{section}}) {
213 elmex 1.18 my $secname = shift @$sec;
214 elmex 1.32 $self->add_section_edit_widgets ($self->{ntbook}, $secname, $ar, $sec);
215 elmex 1.18 }
216 elmex 1.8
217 elmex 1.18 for my $key (qw/lore msg/) {
218     $self->{ntbook}->append_page (my $v = Gtk2::VBox->new, $key);
219     $v->pack_start (my $sw = Gtk2::ScrolledWindow->new, 1, 1, 0);
220     $sw->set_policy ('automatic', 'automatic');
221     $sw->add (my $tb = $self->{"${key}_txt"} = Gtk2::TextView->new);
222     my $buf = $tb->get_buffer;
223 elmex 1.32 $buf->set_text ($ar->get ($key));
224 elmex 1.20 $buf->signal_connect (changed => sub {
225     my ($buf) = @_;
226 elmex 1.36 my $txt = $buf->get_text ($buf->get_start_iter, $buf->get_end_iter, 0);
227     if ($txt ne $ar->get ($key)) {
228     $ar->set_silent ($key, $txt);
229     }
230     1
231 elmex 1.20 });
232 elmex 1.18 }
233 elmex 1.15
234 elmex 1.34 my $desc = pseudohtml2txt $type->{desc};
235     my $use = pseudohtml2txt $type->{use};
236 elmex 1.28 $self->{doc_lbl}->set_text ($desc);
237     $self->{use_lbl}->set_text ($use);
238 elmex 1.25
239 elmex 1.18 $self->{ttip}->enable;
240 elmex 1.3
241 elmex 1.18 $self->show_all;
242 elmex 1.26
243     # reset the current page if found
244     # XXX: it's braindamaged: it has to be done AFTER show all for some reason
245     if (defined $curpage_text) {
246    
247     for (my $i = 0; $i <= $self->{ntbook}->get_n_pages; $i++) {
248     my $w = $self->{ntbook}->get_nth_page ($i);
249    
250     if ($w && $self->{ntbook}->get_tab_label_text ($w) eq $curpage_text) {
251     $self->{ntbook}->set_current_page ($i);
252     last;
253     }
254     }
255     }
256 elmex 1.8 }
257    
258     sub add_section_edit_widgets {
259 elmex 1.32 my ($self, $ntbook, $name, $ar, $section) = @_;
260 elmex 1.8
261 elmex 1.13 $self->{ntbook}->append_page (my $sw = Gtk2::ScrolledWindow->new, $name);
262 elmex 1.27 $sw->set_policy ('automatic', 'automatic');
263 elmex 1.13 $sw->add_with_viewport (my $vb = Gtk2::VBox->new);
264 elmex 1.34 $vb->pack_start (my $table = new Gtk2::Table (2, (scalar @$section) + 1), 0, 1, 0);
265 elmex 1.8
266     my $i = 0;
267 elmex 1.11 for my $sec (@$section) {
268 elmex 1.32 my ($key, $sec) = ($sec->[0], $sec->[1]);
269    
270 elmex 1.28 next if grep { $key eq $_ } qw/msg lore/;
271 elmex 1.32
272 elmex 1.11 my $bwid = Gtk2::EventBox->new;
273 elmex 1.32 $bwid->add (my $al = Gtk2::Alignment->new (0.0, 0.5, 0, 1));
274     $al->add (Gtk2::Label->new (def ($sec->{name}, $key)));
275    
276 elmex 1.11 if ($sec->{desc} !~ m/^\s*$/s) {
277     $self->{ttip}->set_tip ($bwid, $sec->{desc});
278 elmex 1.9 }
279 elmex 1.32
280 elmex 1.12 $table->attach ($bwid, 0, 1, $i, $i + 1, ['shrink','fill'], 'fill', 5, 0);
281 elmex 1.11
282     $al = Gtk2::Alignment->new (0.0, 0.5, 1, 0);
283 elmex 1.32 $table->attach ($al, 1, 2, $i, $i + 1, ['expand', 'fill'], 'expand', 0, 0);
284     $al->add ($self->get_edit_widget ($key, $sec, $ar, $bwid));
285    
286 elmex 1.8 $i++;
287 elmex 1.3 }
288 elmex 1.8 }
289 elmex 1.3
290 elmex 1.41 sub label_set_color {
291     my ($self, $lbl, $dark) = @_;
292     if ($dark) {
293 elmex 1.12 for (qw/normal active prelight selected insensitive/) {
294     $lbl->modify_bg ($_, $lbl->get_default_style->bg ('active'));
295     $lbl->modify_fg ($_, $lbl->get_default_style->fg ('active'));
296     }
297 elmex 1.32
298 elmex 1.12 } else {
299     for (qw/normal active prelight selected insensitive/) {
300     $lbl->modify_bg ($_, $lbl->get_default_style->bg ($_));
301     }
302     }
303 elmex 1.41
304     }
305    
306     sub label_set_color_default {
307     my ($self, $lbl, $ar, $key, $val) = @_;
308     require Carp; $ar or Carp::confess ("UNDEF");
309     my $al_arch = $ar->archetype;
310     $self->label_set_color ($lbl, $ar->field_value_is_default ($key, $val));
311    
312 elmex 1.9 }
313    
314 elmex 1.17 # XXX: Warning: Ugly code ahead:
315 elmex 1.8 sub get_edit_widget {
316 elmex 1.32 my ($self, $key, $edspec, $ar, $lbl) = @_;
317 elmex 1.4
318 elmex 1.32 my $type = $edspec->{type};
319     my $al_arch = $ar->archetype;
320 elmex 1.3
321 elmex 1.8 if ($type eq 'bool') {
322 elmex 1.19 my $boolval = def ($edspec->{value}, [0, 1]);
323 elmex 1.15
324 elmex 1.32
325     $self->label_set_color_default ($lbl, $ar, $key, $ar->get_or_default ($key));
326    
327 elmex 1.19 my $chk = new Gtk2::CheckButton (def ($edspec->{name}, $key));
328 elmex 1.32 $chk->set_active ($ar->get_or_default ($key) == $boolval->[1]);
329     $chk->signal_connect (clicked => sub {
330     my ($chk) = @_;
331    
332     $ar->set_silent ($key, $boolval->[$chk->get_active * 1]);
333    
334     $self->label_set_color_default ($lbl, $ar, $key, $boolval->[$chk->get_active * 1]);
335     });
336 elmex 1.15
337 elmex 1.12 $self->{ttip}->set_tip ($chk, $al_arch->{$key} * 1);
338 elmex 1.15
339 elmex 1.8 return $chk
340    
341     } elsif (grep { $type eq $_ } qw/string int treasurelist float/) {
342 elmex 1.32 $self->label_set_color_default ($lbl, $ar, $key, $ar->get_or_default ($key));
343    
344 elmex 1.8 my $entry = new Gtk2::Entry;
345 elmex 1.32 $entry->set_text ($ar->get_or_default ($key));
346     $entry->signal_connect (changed => sub {
347     my ($entry) = @_;
348     $self->label_set_color_default ($lbl, $ar, $key, $entry->get_text);
349     $ar->set_silent ($key, $entry->get_text);
350     1
351     });
352    
353     $self->{ttip}->set_tip ($entry, $ar->archetype->{$key});
354    
355 elmex 1.8 return $entry
356    
357     } elsif ($type eq 'spell' or $type eq 'nz_spell') { # XXX: nz_spell bug in datafiles?
358     my $comb = Gtk2::ComboBox->new_text;
359     my $spells_idx = {};
360 elmex 1.34 my $spells_cmd_idx = {};
361 elmex 1.8 my $sp = \%Crossfire::Data::SPELL;
362    
363     $comb->append_text ("<none>");
364    
365     my $idx = 1; # XXX: replace this idx with a more save/correct method?
366     for (sort { $sp->{$a} cmp $sp->{$b} } keys %$sp) {
367 elmex 1.34 $spells_cmd_idx->{$idx} = $_;
368     $spells_idx->{$_} = $idx++;
369 elmex 1.8
370     $comb->append_text ($sp->{$_});
371     }
372 elmex 1.12 #XXX: FIXME: $self->{ttip}->set_tip ($comb, $sp->{$al_arch->{$key}});
373 elmex 1.32
374 elmex 1.34 $comb->set_active ($spells_idx->{$ar->get_or_default ($key)});
375 elmex 1.32 $self->label_set_color_default ($lbl, $ar, $key, $ar->get_or_default ($key));
376 elmex 1.8
377     $comb->signal_connect (changed => sub {
378     my ($comb) = @_;
379 elmex 1.34 $self->label_set_color_default ($lbl, $ar, $key, $spells_cmd_idx->{$comb->get_active});
380     $ar->set_silent ($key, $spells_cmd_idx->{$comb->get_active});
381 elmex 1.8 });
382     return $comb
383 elmex 1.3
384 elmex 1.14 } elsif ($type eq 'bitmask') {
385 elmex 1.32 my $chval = $ar->get_or_default ($key);
386 elmex 1.14 my $btn = Gtk2::Button->new;
387 elmex 1.32 $btn->add (my $lblb = Gtk2::Label->new ("bitmask: " . ($chval * 1)));
388 elmex 1.14 $self->{ttip}->set_tip ($btn, $al_arch->{$key});
389    
390 elmex 1.32 my $menu = $self->create_bitmask_menu ($edspec->{value}, $lbl, $lblb, $ar, $key, \$chval);
391    
392     $self->label_set_color_default ($lbl, $ar, $key, $chval);
393 elmex 1.14
394     $btn->signal_connect (button_press_event => sub {
395     my ($btn, $ev) = @_;
396     $menu->popup (undef, undef, undef, undef, $ev->button, 0);
397     });
398 elmex 1.32
399 elmex 1.14 return $btn;
400    
401     } elsif ($type eq 'list') {
402 elmex 1.32 my $lblb = Gtk2::Label->new ($edspec->{value}->{$ar->get_or_default ($key) * 1});
403 elmex 1.14 my $btn = Gtk2::Button->new;
404     $self->{ttip}->set_tip ($btn, $edspec->{value}->{$al_arch->{$key}});
405     $btn->add ($lblb);
406 elmex 1.32 my $menu = $self->create_list_menu ($edspec->{value}, $lbl, $lblb, $ar, $key);
407 elmex 1.14
408 elmex 1.32 $self->label_set_color_default ($lbl, $ar, $key, $ar->get_or_default ($key));
409 elmex 1.14
410     $btn->signal_connect (button_press_event => sub {
411     my ($btn, $ev) = @_;
412     $menu->popup (undef, undef, undef, undef, $ev->button, 0);
413     });
414     return $btn;
415    
416 elmex 1.8 } elsif ($type eq 'fixed') {
417     return Gtk2::Label->new ("$edspec->{name} = $edspec->{value}");
418 elmex 1.3
419 elmex 1.9 } elsif ($type eq 'text') {
420 elmex 1.20 return Gtk2::Label->new ("<see $key tab>");
421 elmex 1.9
422 elmex 1.41 } elsif ($type eq 'movement_type') { # ok... this is quite a big one... awww
423 elmex 1.42 my $a = Gtk2::Alignment->new (0, 0, 0, 0);
424     $a->add (my $v = Gtk2::VBox->new (0, 0));
425     $a->set_padding (4, 4, 0, 0);
426 elmex 1.41 my $btns1 = Gtk2::HButtonBox->new;
427     my $btns2 = Gtk2::HButtonBox->new;
428     $btns1->set_layout ('start');
429     $btns2->set_layout ('start');
430    
431     $v->pack_start ($btns1, 0, 1, 0);
432     $v->pack_start ($btns2, 0, 1, 0);
433    
434     my @lblbtns;
435     my $calc_lbl = sub { # update callback for the buttons
436     for (@lblbtns) {
437     my $btn = $_->[0];
438     my $lbl = $_->[1];
439    
440     if (defined $ar->get ($key)) {
441     my $res = $ar->get ($key) >= $lbl;
442    
443     if (defined $res) {
444     $self->label_set_color ($btn, 0);
445     $lbl = ($res ? "+" : "-") . $lbl;
446    
447     } else {
448     $self->label_set_color ($btn, 1);
449     $lbl = "$lbl?";
450     }
451     } else {
452     $self->label_set_color ($btn, 1);
453     $lbl = "$lbl?";
454     }
455    
456     $btn->set_label ($lbl);
457     }
458     };
459    
460     $self->label_set_color_default ($lbl, $ar, $key, $ar->get_or_default ($key));
461    
462     my $mid = (scalar @Crossfire::MOVE_TYPE) / 2;
463     my $cnt = 0;
464     my $box = $btns1;
465    
466 elmex 1.40 for my $mty (@Crossfire::MOVE_TYPE) {
467 elmex 1.41 $box->pack_start (my $btn = Gtk2::Button->new ($calc_lbl->()), 0, 1, 0);
468     push @lblbtns, [$btn, $mty];
469    
470     $self->{ttip}->set_tip ($btn, $ar->archetype->{$key});
471     $btn->signal_connect (clicked => sub {
472     my $v = $ar->get ($key) || Crossfire::MoveType->new;
473    
474     $v x= $mty;
475     $v = $v eq '' ? undef : $v;
476     $ar->set_silent ($key, $v);
477    
478     $self->label_set_color_default ($lbl, $ar, $key, $v);
479     $calc_lbl->();
480     });
481    
482     if (++$cnt >= $mid) { $box = $btns2 } # for wrapping into the second button box
483 elmex 1.40 }
484 elmex 1.41 $calc_lbl->();
485    
486 elmex 1.42 return $a;
487 elmex 1.40
488 elmex 1.3 } else {
489 elmex 1.8 return Gtk2::Label->new ("$key => $edspec->{name} ($type)");
490 elmex 1.2
491 elmex 1.3 }
492 elmex 1.2 }
493    
494 elmex 1.14 sub bitmask_to_list {
495     my ($self, $bitlist, $bits) = @_;
496    
497     my @l;
498     for (%$bitlist) {
499     if ($bits & (1 << $_)) {
500     push @l, $bitlist->{$_};
501     }
502     }
503     return @l;
504     }
505    
506     sub create_list_menu {
507 elmex 1.32 my ($self, $list, $clbl, $lbl, $ar, $key) = @_;
508 elmex 1.14
509     my $menu = Gtk2::Menu->new;
510    
511     for my $item (sort keys %$list) {
512     my $lbltxt = $list->{$item};
513     my $menuitem = Gtk2::MenuItem->new_with_label ($lbltxt);
514     $menuitem->signal_connect (activate => sub {
515     my ($menuitem) = @_;
516     $lbl->set_text ($list->{$item});
517 elmex 1.32 $self->label_set_color_default ($clbl, $ar, $key, $item);
518     $ar->set_silent ($key, $item);
519 elmex 1.14 });
520     $menu->append ($menuitem);
521     $menuitem->show;
522     }
523    
524     return $menu;
525     }
526    
527     sub create_bitmask_menu {
528 elmex 1.32 my ($self, $bits, $clbl, $lbl, $ar, $key, $rval) = @_;
529 elmex 1.14
530     my $menu = Gtk2::Menu->new;
531    
532 elmex 1.29 for my $bit (sort { $a <=> $b } keys %$bits) {
533 elmex 1.14 my $lbltxt = $bits->{$bit};
534     my $menuitem = Gtk2::CheckMenuItem->new_with_label ($lbltxt);
535 elmex 1.15 if ($$rval & (1 << $bit)) {
536 elmex 1.14 $menuitem->set_active (1);#$arch->{$key} & (1 << $bit));
537     }
538     $menuitem->signal_connect (toggled => sub {
539     my ($menuitem) = @_;
540 elmex 1.32 my $newval = $ar->get ($key);
541 elmex 1.15 $$rval &= ~(1 << $bit);
542     $$rval |= (1 << $bit) if $menuitem->get_active;
543     $lbl->set_text ("bitmask: " . ($$rval * 1));
544 elmex 1.32 $self->label_set_color_default ($clbl, $ar, $key, $$rval);
545     $ar->set_silent ($key, $$rval);
546 elmex 1.14 });
547     $menu->append ($menuitem);
548     $menuitem->show;
549     }
550    
551     return $menu;
552     }
553    
554 elmex 1.1
555     =head1 AUTHOR
556    
557     Marc Lehmann <schmorp@schmorp.de>
558     http://home.schmorp.de/
559    
560     Robin Redeker <elmex@ta-sa.org>
561     http://www.ta-sa.org/
562    
563     =cut
564     1;