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