… | |
… | |
40 | if (!$GRAB) { |
40 | if (!$GRAB) { |
41 | for (my $widget = $HOVER; $widget; $widget = $widget->{parent}) { |
41 | for (my $widget = $HOVER; $widget; $widget = $widget->{parent}) { |
42 | if (length $widget->{tooltip}) { |
42 | if (length $widget->{tooltip}) { |
43 | |
43 | |
44 | if ($TOOLTIP->{owner} != $widget) { |
44 | if ($TOOLTIP->{owner} != $widget) { |
|
|
45 | $TOOLTIP->hide; |
|
|
46 | |
45 | $TOOLTIP->{owner} = $widget; |
47 | $TOOLTIP->{owner} = $widget; |
46 | |
48 | |
47 | my $tip = $widget->{tooltip}; |
49 | my $tip = $widget->{tooltip}; |
48 | |
50 | |
49 | $tip = $tip->($widget) if CODE:: eq ref $tip; |
51 | $tip = $tip->($widget) if CODE:: eq ref $tip; |
50 | |
52 | |
51 | $TOOLTIP->set_tooltip_from ($widget); |
53 | $TOOLTIP->set_tooltip_from ($widget); |
52 | $TOOLTIP->show; |
54 | $TOOLTIP->show; |
53 | |
|
|
54 | my ($x, $y) = $widget->coord2global ($widget->{w}, 0); |
|
|
55 | |
|
|
56 | ($x, $y) = $widget->coord2global (-$TOOLTIP->{w}, 0) |
|
|
57 | if $x + $TOOLTIP->{w} > $::WIDTH; |
|
|
58 | |
|
|
59 | $TOOLTIP->move ($x, $y); |
|
|
60 | $TOOLTIP->realloc; |
|
|
61 | } |
55 | } |
62 | |
56 | |
63 | return; |
57 | return; |
64 | } |
58 | } |
65 | } |
59 | } |
… | |
… | |
257 | $self->{root} = $self->{parent}{root}; |
251 | $self->{root} = $self->{parent}{root}; |
258 | $self->{visible} = $self->{parent}{visible} + 1; |
252 | $self->{visible} = $self->{parent}{visible} + 1; |
259 | |
253 | |
260 | $self->emit (visibility_change => 1); |
254 | $self->emit (visibility_change => 1); |
261 | |
255 | |
262 | $self->realloc unless exists $self->{req_w}; |
256 | $self->realloc if !exists $self->{req_w}; |
263 | |
257 | |
264 | $_->set_visible for $self->children; |
258 | $_->set_visible for $self->children; |
265 | } |
259 | } |
266 | |
260 | |
267 | sub set_invisible { |
261 | sub set_invisible { |
… | |
… | |
469 | my ($self, $parent) = @_; |
463 | my ($self, $parent) = @_; |
470 | |
464 | |
471 | Scalar::Util::weaken ($self->{parent} = $parent); |
465 | Scalar::Util::weaken ($self->{parent} = $parent); |
472 | |
466 | |
473 | $self->set_visible if $parent->{visible}; |
467 | $self->set_visible if $parent->{visible}; |
474 | |
|
|
475 | $self->realloc; |
|
|
476 | } |
468 | } |
477 | |
469 | |
478 | sub connect { |
470 | sub connect { |
479 | my ($self, $signal, $cb) = @_; |
471 | my ($self, $signal, $cb) = @_; |
480 | |
472 | |
… | |
… | |
499 | } |
491 | } |
500 | |
492 | |
501 | sub realloc { |
493 | sub realloc { |
502 | my ($self) = @_; |
494 | my ($self) = @_; |
503 | |
495 | |
504 | return unless $self->{visible}; |
496 | if ($self->{visible}) { |
505 | |
|
|
506 | return if $self->{root}{realloc}{$self}; |
497 | return if $self->{root}{realloc}{$self}; |
507 | |
498 | |
508 | $self->{root}{realloc}{$self} = $self; |
499 | $self->{root}{realloc}{$self} = $self; |
509 | $self->{root}->update; |
500 | $self->{root}->update; |
|
|
501 | } else { |
|
|
502 | delete $self->{req_w}; |
|
|
503 | } |
510 | } |
504 | } |
511 | |
505 | |
512 | sub update { |
506 | sub update { |
513 | my ($self) = @_; |
507 | my ($self) = @_; |
514 | |
508 | |
… | |
… | |
1469 | |
1463 | |
1470 | $self->{layout} = new CFClient::Layout if $self->{layout}->is_rgba; |
1464 | $self->{layout} = new CFClient::Layout if $self->{layout}->is_rgba; |
1471 | $self->{layout}->set_text ($text); |
1465 | $self->{layout}->set_text ($text); |
1472 | |
1466 | |
1473 | $self->realloc; |
1467 | $self->realloc; |
|
|
1468 | $self->update; |
1474 | } |
1469 | } |
1475 | |
1470 | |
1476 | sub set_markup { |
1471 | sub set_markup { |
1477 | my ($self, $markup) = @_; |
1472 | my ($self, $markup) = @_; |
1478 | |
1473 | |
… | |
… | |
1483 | |
1478 | |
1484 | $self->{layout} = new CFClient::Layout $rgba if $self->{layout}->is_rgba != $rgba; |
1479 | $self->{layout} = new CFClient::Layout $rgba if $self->{layout}->is_rgba != $rgba; |
1485 | $self->{layout}->set_markup ($markup); |
1480 | $self->{layout}->set_markup ($markup); |
1486 | |
1481 | |
1487 | $self->realloc; |
1482 | $self->realloc; |
|
|
1483 | $self->update; |
1488 | } |
1484 | } |
1489 | |
1485 | |
1490 | sub size_request { |
1486 | sub size_request { |
1491 | my ($self) = @_; |
1487 | my ($self) = @_; |
1492 | |
1488 | |
… | |
… | |
2640 | return unless $changed; |
2636 | return unless $changed; |
2641 | |
2637 | |
2642 | $self->SUPER::size_allocate ($w - 4, $h - 4, $changed); |
2638 | $self->SUPER::size_allocate ($w - 4, $h - 4, $changed); |
2643 | } |
2639 | } |
2644 | |
2640 | |
|
|
2641 | sub visibility_change { |
|
|
2642 | my ($self, $visible) = @_; |
|
|
2643 | |
|
|
2644 | return unless $visible; |
|
|
2645 | |
|
|
2646 | $self->{root}->on_post_alloc ("move_$self" => sub { |
|
|
2647 | my $widget = $self->{owner} |
|
|
2648 | or return; |
|
|
2649 | |
|
|
2650 | my ($x, $y) = $widget->coord2global ($widget->{w}, 0); |
|
|
2651 | |
|
|
2652 | ($x, $y) = $widget->coord2global (-$self->{w}, 0) |
|
|
2653 | if $x + $self->{w} > $::WIDTH; |
|
|
2654 | |
|
|
2655 | $self->move ($x, $y); |
|
|
2656 | }); |
|
|
2657 | } |
|
|
2658 | |
2645 | sub _draw { |
2659 | sub _draw { |
2646 | my ($self) = @_; |
2660 | my ($self) = @_; |
2647 | |
2661 | |
2648 | glTranslate 0.375, 0.375; |
2662 | glTranslate 0.375, 0.375; |
2649 | |
2663 | |
… | |
… | |
2664 | glVertex $w, $h; |
2678 | glVertex $w, $h; |
2665 | glVertex $w, 0; |
2679 | glVertex $w, 0; |
2666 | glEnd; |
2680 | glEnd; |
2667 | |
2681 | |
2668 | glTranslate 2 - 0.375, 2 - 0.375; |
2682 | glTranslate 2 - 0.375, 2 - 0.375; |
|
|
2683 | |
2669 | $self->SUPER::_draw; |
2684 | $self->SUPER::_draw; |
2670 | } |
2685 | } |
2671 | |
2686 | |
2672 | ############################################################################# |
2687 | ############################################################################# |
2673 | |
2688 | |
… | |
… | |
3123 | Carp::confess "$widget: size_request is negative" if $w < 0 || $h < 0;#d# |
3138 | Carp::confess "$widget: size_request is negative" if $w < 0 || $h < 0;#d# |
3124 | |
3139 | |
3125 | $widget->{req_w} = $w; |
3140 | $widget->{req_w} = $w; |
3126 | $widget->{req_h} = $h; |
3141 | $widget->{req_h} = $h; |
3127 | |
3142 | |
3128 | $self->{size_alloc}{$widget} = [$widget, $widget->{w}, $widget->{h}]; |
3143 | $self->{size_alloc}{$widget} = [$widget, $widget->{w} || $w, $widget->{h} || $h]; |
3129 | |
3144 | |
3130 | push @queue, $widget->{parent} |
3145 | push @queue, $widget->{parent} |
3131 | if $widget->{parent}; |
3146 | if $widget->{parent}; |
3132 | } |
3147 | } |
3133 | } |
3148 | } |
… | |
… | |
3140 | my ($widget, $w, $h) = @{ pop @queue or last }; |
3155 | my ($widget, $w, $h) = @{ pop @queue or last }; |
3141 | |
3156 | |
3142 | $w = 0 if $w < 0; |
3157 | $w = 0 if $w < 0; |
3143 | $h = 0 if $h < 0; |
3158 | $h = 0 if $h < 0; |
3144 | |
3159 | |
|
|
3160 | my $changed = $widget->{w} != $w || $widget->{h} != $h; |
|
|
3161 | |
3145 | $widget->{w} = $w; |
3162 | $widget->{w} = $w; |
3146 | $widget->{h} = $h; |
3163 | $widget->{h} = $h; |
|
|
3164 | |
3147 | $widget->emit (size_allocate => $w, $h, 1); |
3165 | $widget->emit (size_allocate => $w, $h, $changed); |
3148 | } |
3166 | } |
3149 | } |
3167 | } |
3150 | |
3168 | |
3151 | while ($self->{post_alloc_hook}) { |
3169 | while ($self->{post_alloc_hook}) { |
3152 | $_->() |
3170 | $_->() |