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