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.36 |
my $txt = $buf->get_text ($buf->get_start_iter, $buf->get_end_iter, 0); |
189 |
|
|
if ($txt ne $ar->get ($key)) { |
190 |
|
|
$ar->set_silent ($key, $txt); |
191 |
|
|
} |
192 |
|
|
1 |
193 |
elmex |
1.20 |
}); |
194 |
elmex |
1.18 |
} |
195 |
elmex |
1.15 |
|
196 |
elmex |
1.34 |
my $desc = pseudohtml2txt $type->{desc}; |
197 |
|
|
my $use = pseudohtml2txt $type->{use}; |
198 |
elmex |
1.28 |
$self->{doc_lbl}->set_text ($desc); |
199 |
|
|
$self->{use_lbl}->set_text ($use); |
200 |
elmex |
1.25 |
|
201 |
elmex |
1.18 |
$self->{ttip}->enable; |
202 |
elmex |
1.3 |
|
203 |
elmex |
1.18 |
$self->show_all; |
204 |
elmex |
1.26 |
|
205 |
|
|
# reset the current page if found |
206 |
|
|
# XXX: it's braindamaged: it has to be done AFTER show all for some reason |
207 |
|
|
if (defined $curpage_text) { |
208 |
|
|
|
209 |
|
|
for (my $i = 0; $i <= $self->{ntbook}->get_n_pages; $i++) { |
210 |
|
|
my $w = $self->{ntbook}->get_nth_page ($i); |
211 |
|
|
|
212 |
|
|
if ($w && $self->{ntbook}->get_tab_label_text ($w) eq $curpage_text) { |
213 |
|
|
$self->{ntbook}->set_current_page ($i); |
214 |
|
|
last; |
215 |
|
|
} |
216 |
|
|
} |
217 |
|
|
} |
218 |
elmex |
1.8 |
} |
219 |
|
|
|
220 |
|
|
sub add_section_edit_widgets { |
221 |
elmex |
1.32 |
my ($self, $ntbook, $name, $ar, $section) = @_; |
222 |
elmex |
1.8 |
|
223 |
elmex |
1.13 |
$self->{ntbook}->append_page (my $sw = Gtk2::ScrolledWindow->new, $name); |
224 |
elmex |
1.27 |
$sw->set_policy ('automatic', 'automatic'); |
225 |
elmex |
1.13 |
$sw->add_with_viewport (my $vb = Gtk2::VBox->new); |
226 |
elmex |
1.34 |
$vb->pack_start (my $table = new Gtk2::Table (2, (scalar @$section) + 1), 0, 1, 0); |
227 |
elmex |
1.8 |
|
228 |
|
|
my $i = 0; |
229 |
elmex |
1.11 |
for my $sec (@$section) { |
230 |
elmex |
1.32 |
my ($key, $sec) = ($sec->[0], $sec->[1]); |
231 |
|
|
|
232 |
elmex |
1.28 |
next if grep { $key eq $_ } qw/msg lore/; |
233 |
elmex |
1.32 |
|
234 |
elmex |
1.11 |
my $bwid = Gtk2::EventBox->new; |
235 |
elmex |
1.32 |
$bwid->add (my $al = Gtk2::Alignment->new (0.0, 0.5, 0, 1)); |
236 |
|
|
$al->add (Gtk2::Label->new (def ($sec->{name}, $key))); |
237 |
|
|
|
238 |
elmex |
1.11 |
if ($sec->{desc} !~ m/^\s*$/s) { |
239 |
|
|
$self->{ttip}->set_tip ($bwid, $sec->{desc}); |
240 |
elmex |
1.9 |
} |
241 |
elmex |
1.32 |
|
242 |
elmex |
1.12 |
$table->attach ($bwid, 0, 1, $i, $i + 1, ['shrink','fill'], 'fill', 5, 0); |
243 |
elmex |
1.11 |
|
244 |
|
|
$al = Gtk2::Alignment->new (0.0, 0.5, 1, 0); |
245 |
elmex |
1.32 |
$table->attach ($al, 1, 2, $i, $i + 1, ['expand', 'fill'], 'expand', 0, 0); |
246 |
|
|
$al->add ($self->get_edit_widget ($key, $sec, $ar, $bwid)); |
247 |
|
|
|
248 |
elmex |
1.8 |
$i++; |
249 |
elmex |
1.3 |
} |
250 |
elmex |
1.8 |
} |
251 |
elmex |
1.3 |
|
252 |
elmex |
1.11 |
sub label_set_color_default { |
253 |
elmex |
1.32 |
my ($self, $lbl, $ar, $key, $val) = @_; |
254 |
|
|
require Carp; $ar or Carp::confess ("UNDEF"); |
255 |
|
|
my $al_arch = $ar->archetype; |
256 |
elmex |
1.9 |
|
257 |
elmex |
1.32 |
if ($ar->field_value_is_default ($key, $val)) { |
258 |
elmex |
1.12 |
for (qw/normal active prelight selected insensitive/) { |
259 |
|
|
$lbl->modify_bg ($_, $lbl->get_default_style->bg ('active')); |
260 |
|
|
$lbl->modify_fg ($_, $lbl->get_default_style->fg ('active')); |
261 |
|
|
} |
262 |
elmex |
1.32 |
|
263 |
elmex |
1.12 |
} else { |
264 |
|
|
for (qw/normal active prelight selected insensitive/) { |
265 |
|
|
$lbl->modify_bg ($_, $lbl->get_default_style->bg ($_)); |
266 |
|
|
} |
267 |
|
|
} |
268 |
elmex |
1.9 |
} |
269 |
|
|
|
270 |
elmex |
1.17 |
# XXX: Warning: Ugly code ahead: |
271 |
elmex |
1.8 |
sub get_edit_widget { |
272 |
elmex |
1.32 |
my ($self, $key, $edspec, $ar, $lbl) = @_; |
273 |
elmex |
1.4 |
|
274 |
elmex |
1.32 |
my $type = $edspec->{type}; |
275 |
|
|
my $al_arch = $ar->archetype; |
276 |
elmex |
1.3 |
|
277 |
elmex |
1.8 |
if ($type eq 'bool') { |
278 |
elmex |
1.19 |
my $boolval = def ($edspec->{value}, [0, 1]); |
279 |
elmex |
1.15 |
|
280 |
elmex |
1.32 |
|
281 |
|
|
$self->label_set_color_default ($lbl, $ar, $key, $ar->get_or_default ($key)); |
282 |
|
|
|
283 |
elmex |
1.19 |
my $chk = new Gtk2::CheckButton (def ($edspec->{name}, $key)); |
284 |
elmex |
1.32 |
$chk->set_active ($ar->get_or_default ($key) == $boolval->[1]); |
285 |
|
|
$chk->signal_connect (clicked => sub { |
286 |
|
|
my ($chk) = @_; |
287 |
|
|
|
288 |
|
|
$ar->set_silent ($key, $boolval->[$chk->get_active * 1]); |
289 |
|
|
|
290 |
|
|
$self->label_set_color_default ($lbl, $ar, $key, $boolval->[$chk->get_active * 1]); |
291 |
|
|
}); |
292 |
elmex |
1.15 |
|
293 |
elmex |
1.12 |
$self->{ttip}->set_tip ($chk, $al_arch->{$key} * 1); |
294 |
elmex |
1.15 |
|
295 |
elmex |
1.8 |
return $chk |
296 |
|
|
|
297 |
|
|
} elsif (grep { $type eq $_ } qw/string int treasurelist float/) { |
298 |
elmex |
1.32 |
$self->label_set_color_default ($lbl, $ar, $key, $ar->get_or_default ($key)); |
299 |
|
|
|
300 |
elmex |
1.8 |
my $entry = new Gtk2::Entry; |
301 |
elmex |
1.32 |
$entry->set_text ($ar->get_or_default ($key)); |
302 |
|
|
$entry->signal_connect (changed => sub { |
303 |
|
|
my ($entry) = @_; |
304 |
|
|
$self->label_set_color_default ($lbl, $ar, $key, $entry->get_text); |
305 |
|
|
$ar->set_silent ($key, $entry->get_text); |
306 |
|
|
1 |
307 |
|
|
}); |
308 |
|
|
|
309 |
|
|
$self->{ttip}->set_tip ($entry, $ar->archetype->{$key}); |
310 |
|
|
|
311 |
elmex |
1.8 |
return $entry |
312 |
|
|
|
313 |
|
|
} elsif ($type eq 'spell' or $type eq 'nz_spell') { # XXX: nz_spell bug in datafiles? |
314 |
|
|
my $comb = Gtk2::ComboBox->new_text; |
315 |
|
|
my $spells_idx = {}; |
316 |
elmex |
1.34 |
my $spells_cmd_idx = {}; |
317 |
elmex |
1.8 |
my $sp = \%Crossfire::Data::SPELL; |
318 |
|
|
|
319 |
|
|
$comb->append_text ("<none>"); |
320 |
|
|
|
321 |
|
|
my $idx = 1; # XXX: replace this idx with a more save/correct method? |
322 |
|
|
for (sort { $sp->{$a} cmp $sp->{$b} } keys %$sp) { |
323 |
elmex |
1.34 |
$spells_cmd_idx->{$idx} = $_; |
324 |
|
|
$spells_idx->{$_} = $idx++; |
325 |
elmex |
1.8 |
|
326 |
|
|
$comb->append_text ($sp->{$_}); |
327 |
|
|
} |
328 |
elmex |
1.12 |
#XXX: FIXME: $self->{ttip}->set_tip ($comb, $sp->{$al_arch->{$key}}); |
329 |
elmex |
1.32 |
|
330 |
elmex |
1.34 |
$comb->set_active ($spells_idx->{$ar->get_or_default ($key)}); |
331 |
elmex |
1.32 |
$self->label_set_color_default ($lbl, $ar, $key, $ar->get_or_default ($key)); |
332 |
elmex |
1.8 |
|
333 |
|
|
$comb->signal_connect (changed => sub { |
334 |
|
|
my ($comb) = @_; |
335 |
elmex |
1.34 |
$self->label_set_color_default ($lbl, $ar, $key, $spells_cmd_idx->{$comb->get_active}); |
336 |
|
|
$ar->set_silent ($key, $spells_cmd_idx->{$comb->get_active}); |
337 |
elmex |
1.8 |
}); |
338 |
|
|
return $comb |
339 |
elmex |
1.3 |
|
340 |
elmex |
1.14 |
} elsif ($type eq 'bitmask') { |
341 |
elmex |
1.32 |
my $chval = $ar->get_or_default ($key); |
342 |
elmex |
1.14 |
my $btn = Gtk2::Button->new; |
343 |
elmex |
1.32 |
$btn->add (my $lblb = Gtk2::Label->new ("bitmask: " . ($chval * 1))); |
344 |
elmex |
1.14 |
$self->{ttip}->set_tip ($btn, $al_arch->{$key}); |
345 |
|
|
|
346 |
elmex |
1.32 |
my $menu = $self->create_bitmask_menu ($edspec->{value}, $lbl, $lblb, $ar, $key, \$chval); |
347 |
|
|
|
348 |
|
|
$self->label_set_color_default ($lbl, $ar, $key, $chval); |
349 |
elmex |
1.14 |
|
350 |
|
|
$btn->signal_connect (button_press_event => sub { |
351 |
|
|
my ($btn, $ev) = @_; |
352 |
|
|
$menu->popup (undef, undef, undef, undef, $ev->button, 0); |
353 |
|
|
}); |
354 |
elmex |
1.32 |
|
355 |
elmex |
1.14 |
return $btn; |
356 |
|
|
|
357 |
|
|
} elsif ($type eq 'list') { |
358 |
elmex |
1.32 |
my $lblb = Gtk2::Label->new ($edspec->{value}->{$ar->get_or_default ($key) * 1}); |
359 |
elmex |
1.14 |
my $btn = Gtk2::Button->new; |
360 |
|
|
$self->{ttip}->set_tip ($btn, $edspec->{value}->{$al_arch->{$key}}); |
361 |
|
|
$btn->add ($lblb); |
362 |
elmex |
1.32 |
my $menu = $self->create_list_menu ($edspec->{value}, $lbl, $lblb, $ar, $key); |
363 |
elmex |
1.14 |
|
364 |
elmex |
1.32 |
$self->label_set_color_default ($lbl, $ar, $key, $ar->get_or_default ($key)); |
365 |
elmex |
1.14 |
|
366 |
|
|
$btn->signal_connect (button_press_event => sub { |
367 |
|
|
my ($btn, $ev) = @_; |
368 |
|
|
$menu->popup (undef, undef, undef, undef, $ev->button, 0); |
369 |
|
|
}); |
370 |
|
|
return $btn; |
371 |
|
|
|
372 |
elmex |
1.8 |
} elsif ($type eq 'fixed') { |
373 |
|
|
return Gtk2::Label->new ("$edspec->{name} = $edspec->{value}"); |
374 |
elmex |
1.3 |
|
375 |
elmex |
1.9 |
} elsif ($type eq 'text') { |
376 |
elmex |
1.20 |
return Gtk2::Label->new ("<see $key tab>"); |
377 |
elmex |
1.9 |
|
378 |
elmex |
1.3 |
} else { |
379 |
elmex |
1.8 |
return Gtk2::Label->new ("$key => $edspec->{name} ($type)"); |
380 |
elmex |
1.2 |
|
381 |
elmex |
1.3 |
} |
382 |
elmex |
1.2 |
} |
383 |
|
|
|
384 |
elmex |
1.14 |
sub bitmask_to_list { |
385 |
|
|
my ($self, $bitlist, $bits) = @_; |
386 |
|
|
|
387 |
|
|
my @l; |
388 |
|
|
for (%$bitlist) { |
389 |
|
|
if ($bits & (1 << $_)) { |
390 |
|
|
push @l, $bitlist->{$_}; |
391 |
|
|
} |
392 |
|
|
} |
393 |
|
|
return @l; |
394 |
|
|
} |
395 |
|
|
|
396 |
|
|
sub create_list_menu { |
397 |
elmex |
1.32 |
my ($self, $list, $clbl, $lbl, $ar, $key) = @_; |
398 |
elmex |
1.14 |
|
399 |
|
|
my $menu = Gtk2::Menu->new; |
400 |
|
|
|
401 |
|
|
for my $item (sort keys %$list) { |
402 |
|
|
my $lbltxt = $list->{$item}; |
403 |
|
|
my $menuitem = Gtk2::MenuItem->new_with_label ($lbltxt); |
404 |
|
|
$menuitem->signal_connect (activate => sub { |
405 |
|
|
my ($menuitem) = @_; |
406 |
|
|
$lbl->set_text ($list->{$item}); |
407 |
elmex |
1.32 |
$self->label_set_color_default ($clbl, $ar, $key, $item); |
408 |
|
|
$ar->set_silent ($key, $item); |
409 |
elmex |
1.14 |
}); |
410 |
|
|
$menu->append ($menuitem); |
411 |
|
|
$menuitem->show; |
412 |
|
|
} |
413 |
|
|
|
414 |
|
|
return $menu; |
415 |
|
|
} |
416 |
|
|
|
417 |
|
|
sub create_bitmask_menu { |
418 |
elmex |
1.32 |
my ($self, $bits, $clbl, $lbl, $ar, $key, $rval) = @_; |
419 |
elmex |
1.14 |
|
420 |
|
|
my $menu = Gtk2::Menu->new; |
421 |
|
|
|
422 |
elmex |
1.29 |
for my $bit (sort { $a <=> $b } keys %$bits) { |
423 |
elmex |
1.14 |
my $lbltxt = $bits->{$bit}; |
424 |
|
|
my $menuitem = Gtk2::CheckMenuItem->new_with_label ($lbltxt); |
425 |
elmex |
1.15 |
if ($$rval & (1 << $bit)) { |
426 |
elmex |
1.14 |
$menuitem->set_active (1);#$arch->{$key} & (1 << $bit)); |
427 |
|
|
} |
428 |
|
|
$menuitem->signal_connect (toggled => sub { |
429 |
|
|
my ($menuitem) = @_; |
430 |
elmex |
1.32 |
my $newval = $ar->get ($key); |
431 |
elmex |
1.15 |
$$rval &= ~(1 << $bit); |
432 |
|
|
$$rval |= (1 << $bit) if $menuitem->get_active; |
433 |
|
|
$lbl->set_text ("bitmask: " . ($$rval * 1)); |
434 |
elmex |
1.32 |
$self->label_set_color_default ($clbl, $ar, $key, $$rval); |
435 |
|
|
$ar->set_silent ($key, $$rval); |
436 |
elmex |
1.14 |
}); |
437 |
|
|
$menu->append ($menuitem); |
438 |
|
|
$menuitem->show; |
439 |
|
|
} |
440 |
|
|
|
441 |
|
|
return $menu; |
442 |
|
|
} |
443 |
|
|
|
444 |
elmex |
1.1 |
|
445 |
|
|
=head1 AUTHOR |
446 |
|
|
|
447 |
|
|
Marc Lehmann <schmorp@schmorp.de> |
448 |
|
|
http://home.schmorp.de/ |
449 |
|
|
|
450 |
|
|
Robin Redeker <elmex@ta-sa.org> |
451 |
|
|
http://www.ta-sa.org/ |
452 |
|
|
|
453 |
|
|
=cut |
454 |
|
|
1; |