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