… | |
… | |
26 | [default => { foreground => "black" }], |
26 | [default => { foreground => "black" }], |
27 | [node => { foreground => "#0000b0", event => 1 }], |
27 | [node => { foreground => "#0000b0", event => 1 }], |
28 | [move => { foreground => "#0000b0", event => 1 }], |
28 | [move => { foreground => "#0000b0", event => 1 }], |
29 | [user => { foreground => "#0000b0", event => 1 }], |
29 | [user => { foreground => "#0000b0", event => 1 }], |
30 | [coord => { foreground => "#0000b0", event => 1 }], |
30 | [coord => { foreground => "#0000b0", event => 1 }], |
|
|
31 | [score => { foreground => "#0000b0", event => 1 }], |
31 | [error => { foreground => "#ff0000", event => 1 }], |
32 | [error => { foreground => "#ff0000", event => 1 }], |
32 | [header => { weight => 800, pixels_above_lines => 6 }], |
33 | [header => { weight => 800, pixels_above_lines => 6 }], |
|
|
34 | [undo => { foreground => "#ffff00", background => "#ff0000", weight => 800, pixels_above_lines => 6 }], |
33 | [challenge => { weight => 800, pixels_above_lines => 6, background => "#ffffb0" }], |
35 | [challenge => { weight => 800, pixels_above_lines => 6, background => "#ffffb0" }], |
34 | [description => { weight => 800, foreground => "blue" }], |
36 | [description => { weight => 800, foreground => "blue" }], |
35 | [infoblock => { weight => 700, foreground => "blue" }], |
37 | [infoblock => { weight => 700, foreground => "blue" }], |
36 | ); |
38 | ); |
37 | |
39 | |
… | |
… | |
105 | } |
107 | } |
106 | |
108 | |
107 | $self->signal_emit (command => $cmd, $arg); |
109 | $self->signal_emit (command => $cmd, $arg); |
108 | }); |
110 | }); |
109 | |
111 | |
110 | $self->{end} = $self->{buffer}->create_mark (undef, $self->{buffer}->get_end_iter, 0); |
112 | #$self->{end} = $self->{buffer}->create_mark (undef, $self->{buffer}->get_end_iter, 0);#d##todo# use this one for gtk-1.050+ |
|
|
113 | $self->{end} = $self->{buffer}->create_mark (++$USELESSNAME, $self->{buffer}->get_end_iter, 0); # workaround for gtk-perl bug |
111 | |
114 | |
112 | $self->set_end; |
115 | $self->set_end; |
113 | } |
116 | } |
114 | |
117 | |
115 | sub do_command { |
118 | sub do_command { |
… | |
… | |
197 | my $self = bless { |
200 | my $self = bless { |
198 | buffer => $self->{buffer}, |
201 | buffer => $self->{buffer}, |
199 | parent => $self, |
202 | parent => $self, |
200 | }, superchat::inlay; |
203 | }, superchat::inlay; |
201 | |
204 | |
|
|
205 | # $USELESSNAME is a Gtk-perl < 1.042 workaround |
202 | $self->{l} = $self->{buffer}->create_mark (undef, $end, 1); |
206 | $self->{l} = $self->{buffer}->create_mark (++$USELESSNAME, $end, 1); |
203 | $self->{buffer}->insert ($end, "\x{200d}"); |
207 | $self->{buffer}->insert ($end, "\x{200d}"); |
204 | $self->{r} = $self->{buffer}->create_mark (undef, $self->{buffer}->get_iter_at_mark ($self->{l}), 0); |
208 | $self->{r} = $self->{buffer}->create_mark (++$USELESSNAME, $self->{buffer}->get_iter_at_mark ($self->{l}), 0); |
205 | |
209 | |
206 | Scalar::Util::weaken $self->{buffer}; |
210 | Scalar::Util::weaken $self->{buffer}; |
207 | Scalar::Util::weaken $self->{parent}; |
211 | Scalar::Util::weaken $self->{parent}; |
208 | $self; |
212 | $self; |
209 | } |
213 | } |
… | |
… | |
216 | my $tag = $self->new_eventtag (sub { |
220 | my $tag = $self->new_eventtag (sub { |
217 | my ($tag, $view, $event, $iter) = @_; |
221 | my ($tag, $view, $event, $iter) = @_; |
218 | |
222 | |
219 | if ($event->type eq "button-press") { |
223 | if ($event->type eq "button-press") { |
220 | $inlay->set_visible (!$inlay->{visible}); |
224 | $inlay->set_visible (!$inlay->{visible}); |
|
|
225 | return 1; |
221 | } |
226 | } |
222 | |
227 | |
223 | 1; |
228 | 0; |
224 | }); |
229 | }); |
225 | |
230 | |
226 | $tag->set (background => "#e0e0ff"); |
231 | $tag->set (background => "#e0e0ff"); |
227 | |
232 | |
228 | $inlay = $self->new_inlay; |
233 | $inlay = $self->new_inlay; |
229 | |
234 | |
230 | $inlay->{visible} = 0; |
235 | $inlay->{visible} = $visible; |
231 | $inlay->{header} = $header; |
236 | $inlay->{header} = $header; |
232 | $inlay->{tag} = $tag; |
237 | $inlay->{tag} = $tag; |
233 | $inlay->{cb} = $cb; |
238 | $inlay->{cb} = $cb; |
234 | |
239 | |
235 | Scalar::Util::weaken $inlay->{tag}; |
240 | Scalar::Util::weaken $inlay->{tag}; |
236 | |
241 | |
237 | $inlay->set_visible ($visible); |
242 | $inlay->refresh; |
238 | |
243 | |
239 | $inlay; |
244 | $inlay; |
240 | } |
245 | } |
241 | |
246 | |
242 | package superchat::inlay; |
247 | package superchat::inlay; |
… | |
… | |
253 | my ($self, $text) = @_; |
258 | my ($self, $text) = @_; |
254 | |
259 | |
255 | $self->{parent}->_append_text ($self->{r}, $text); |
260 | $self->{parent}->_append_text ($self->{r}, $text); |
256 | } |
261 | } |
257 | |
262 | |
|
|
263 | sub append_widget { |
|
|
264 | my ($self, $widget) = @_; |
|
|
265 | |
|
|
266 | $widget->show_all; |
|
|
267 | |
|
|
268 | my $anchor = $self->{buffer}->create_child_anchor ($self->riter); |
|
|
269 | $self->{parent}{view}->add_child_at_anchor ($widget, $anchor); |
|
|
270 | } |
|
|
271 | |
|
|
272 | sub append_optionmenu { |
|
|
273 | my ($self, $ref, @entry) = @_; |
|
|
274 | |
|
|
275 | my @vals; |
|
|
276 | |
|
|
277 | my $widget = new Gtk2::OptionMenu; |
|
|
278 | $widget->set (menu => my $menu = new Gtk2::Menu); |
|
|
279 | |
|
|
280 | my $idx = 0; |
|
|
281 | |
|
|
282 | while (@entry >= 2) { |
|
|
283 | my $value = shift @entry; |
|
|
284 | my $label = shift @entry; |
|
|
285 | |
|
|
286 | $menu->append (new Gtk2::MenuItem $label); |
|
|
287 | push @vals, $value; |
|
|
288 | |
|
|
289 | if ($value eq $$ref && $idx >= 0) { |
|
|
290 | $widget->set_history ($idx); |
|
|
291 | $idx = -1e6; |
|
|
292 | } |
|
|
293 | $idx++; |
|
|
294 | } |
|
|
295 | |
|
|
296 | my $cb = shift @entry; |
|
|
297 | |
|
|
298 | $widget->signal_connect (changed => sub { |
|
|
299 | my $new = $vals[$_[0]->get_history]; |
|
|
300 | |
|
|
301 | if ($new ne $$ref) { |
|
|
302 | $$ref = $new; |
|
|
303 | $cb->($new) if $cb; |
|
|
304 | } |
|
|
305 | }); |
|
|
306 | |
|
|
307 | $self->append_widget ($widget); |
|
|
308 | |
|
|
309 | $widget; |
|
|
310 | } |
|
|
311 | |
|
|
312 | sub append_entry { |
|
|
313 | my ($self, $ref, $width, $cb) = @_; |
|
|
314 | |
|
|
315 | my $widget = new Gtk2::Entry; |
|
|
316 | $widget->set (text => $$ref, width_chars => $width); |
|
|
317 | eval { $widget->set (xalign => 1) }; # workaround für 2.2 |
|
|
318 | $widget->signal_connect (changed => sub { |
|
|
319 | $$ref = $_[0]->get_text; |
|
|
320 | $cb->($$ref) if $cb; |
|
|
321 | }); |
|
|
322 | |
|
|
323 | $self->append_widget ($widget); |
|
|
324 | $widget; |
|
|
325 | } |
|
|
326 | |
|
|
327 | sub append_button { |
|
|
328 | my ($self, $label, $cb) = @_; |
|
|
329 | |
|
|
330 | my $widget = new_with_label Gtk2::Button $label; |
|
|
331 | $widget->signal_connect (clicked => sub { $cb->() if $cb }); |
|
|
332 | |
|
|
333 | $self->append_widget ($widget); |
|
|
334 | $widget; |
|
|
335 | } |
|
|
336 | |
258 | sub visible { $_[0]{visible} } |
337 | sub visible { $_[0]{visible} } |
|
|
338 | |
259 | sub set_visible { |
339 | sub set_visible { |
260 | my ($self, $visible) = @_; |
340 | my ($self, $visible) = @_; |
261 | |
341 | |
262 | return if $self->{visible} == $visible; |
342 | return if $self->{visible} == $visible; |
263 | $self->{visible} = $visible; |
343 | $self->{visible} = $visible; |
… | |
… | |
278 | return unless $self->{visible}; |
358 | return unless $self->{visible}; |
279 | |
359 | |
280 | $self->{cb}->($self); |
360 | $self->{cb}->($self); |
281 | } |
361 | } |
282 | |
362 | |
|
|
363 | sub destroy { |
|
|
364 | my ($self) = @_; |
|
|
365 | |
|
|
366 | return if !$self->{l} || !$self->{buffer} || $self->{l}->get_deleted; |
|
|
367 | |
|
|
368 | $self->clear if $self->{buffer}; |
|
|
369 | |
|
|
370 | delete $self->{parent}; |
|
|
371 | delete $self->{buffer}; |
|
|
372 | delete $self->{l}; |
|
|
373 | delete $self->{r}; |
|
|
374 | } |
|
|
375 | |
283 | sub DESTROY { |
376 | sub DESTROY { |
284 | my ($self) = @_; |
377 | my $self = shift; |
285 | |
378 | |
286 | $self->{parent}{tagtable}->remove (delete $self->{tag}) if $self->{tag}; |
379 | $self->{parent}{tagtable}->remove (delete $self->{tag}) if $self->{tag} && $self->{parent}; |
|
|
380 | #&destroy; |
287 | } |
381 | } |
288 | |
382 | |
289 | 1; |
383 | 1; |
290 | |
384 | |