… | |
… | |
3642 | @_, |
3642 | @_, |
3643 | can_events => 0, |
3643 | can_events => 0, |
3644 | ) |
3644 | ) |
3645 | } |
3645 | } |
3646 | |
3646 | |
|
|
3647 | # expand, as good as possible |
|
|
3648 | sub _expand_doclets { |
|
|
3649 | my ($tip) = @_; |
|
|
3650 | |
|
|
3651 | $tip =~ s{#\(([^)]+)\)}{ |
|
|
3652 | if ($::CONN) { |
|
|
3653 | exists $::CONN->{doclet}{$1} |
|
|
3654 | ? $::CONN->{doclet}{$1} |
|
|
3655 | : "(waiting for server to show full text)" |
|
|
3656 | } else { |
|
|
3657 | "(unable to show full text without server connection)" |
|
|
3658 | } |
|
|
3659 | }ge; |
|
|
3660 | |
|
|
3661 | $tip =~ s/^\n+//; |
|
|
3662 | $tip =~ s/\n+$//; |
|
|
3663 | |
|
|
3664 | $tip |
|
|
3665 | } |
|
|
3666 | |
|
|
3667 | # expands a tooltip, potentially multiple times remotely |
|
|
3668 | # and returns a guard. clals the clalback each time the text changes. |
|
|
3669 | sub expand_tooltip { |
|
|
3670 | my ($tip, $cb) = @_; |
|
|
3671 | |
|
|
3672 | # first expand #name tooltips from local pod |
|
|
3673 | $tip = DC::Pod::section_label tooltip => $1 |
|
|
3674 | if $tip =~ /^#([^(].*)$/; |
|
|
3675 | |
|
|
3676 | my $active; # true if any remote requests outstanding |
|
|
3677 | |
|
|
3678 | if ($::CONN && $::CONN->{addme_success}) { |
|
|
3679 | # now find all doclet references |
|
|
3680 | for my $doclet ($tip =~ /#\(([^)]+)\)/g) { |
|
|
3681 | unless (exists $::CONN->{doclet}{$doclet}) { |
|
|
3682 | # need to ask the server |
|
|
3683 | # we don't try to avoid duplicate requests |
|
|
3684 | |
|
|
3685 | $active = 1; |
|
|
3686 | $::CONN->send_exti_req (doclet => (split /\//, $doclet, 2), sub { |
|
|
3687 | $::CONN->{doclet}{$doclet} = $_[0]; |
|
|
3688 | $cb->(_expand_doclets $tip) if $active; |
|
|
3689 | }); |
|
|
3690 | } |
|
|
3691 | } |
|
|
3692 | } |
|
|
3693 | |
|
|
3694 | $cb->(_expand_doclets $tip); |
|
|
3695 | |
|
|
3696 | $active and Guard::guard { undef $active } |
|
|
3697 | } |
|
|
3698 | |
3647 | sub set_tooltip_from { |
3699 | sub set_tooltip_from { |
3648 | my ($self, $widget) = @_; |
3700 | my ($self, $widget) = @_; |
3649 | |
3701 | |
3650 | my $tip = $widget->{tooltip}; |
3702 | my $tip = $widget->{tooltip}; |
3651 | $tip = $tip->($widget) if "CODE" eq ref $tip; |
3703 | $tip = $tip->($widget) if "CODE" eq ref $tip; |
3652 | |
|
|
3653 | $tip = DC::Pod::section_label tooltip => $1 |
|
|
3654 | if $tip =~ /^#(.*)$/; |
|
|
3655 | |
|
|
3656 | if ($ENV{CFPLUS_DEBUG} & 2) { |
|
|
3657 | $tip .= "\n\n" . (ref $widget) . "\n" |
|
|
3658 | . "$widget->{x} $widget->{y} $widget->{w} $widget->{h}\n" |
|
|
3659 | . "req $widget->{req_w} $widget->{req_h}\n" |
|
|
3660 | . "visible $widget->{visible}"; |
|
|
3661 | } |
|
|
3662 | |
|
|
3663 | $tip =~ s/^\n+//; |
|
|
3664 | $tip =~ s/\n+$//; |
|
|
3665 | |
3704 | |
3666 | $self->add (new DC::UI::Label |
3705 | $self->add (new DC::UI::Label |
3667 | fg => $DC::THEME{tooltip_fg}, |
3706 | fg => $DC::THEME{tooltip_fg}, |
3668 | markup => $tip, |
|
|
3669 | max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH, |
3707 | max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH, |
3670 | align => 0, |
3708 | align => 0, |
3671 | fontsize => 0.8, |
3709 | fontsize => 0.8, |
3672 | style => $DC::THEME{tooltip_style}, # FLAG_INVERSE |
3710 | style => $DC::THEME{tooltip_style}, # FLAG_INVERSE |
3673 | ellipsise => 0, |
3711 | ellipsise => 0, |
3674 | font => ($widget->{tooltip_font} || $::FONT_PROP), |
3712 | font => ($widget->{tooltip_font} || $::FONT_PROP), |
3675 | ); |
3713 | ); |
|
|
3714 | |
|
|
3715 | $self->{tooltip_expand} = expand_tooltip $tip, sub { |
|
|
3716 | my ($tip) = @_; |
|
|
3717 | |
|
|
3718 | if ($ENV{CFPLUS_DEBUG} & 2) { |
|
|
3719 | $tip .= "\n\n" . (ref $widget) . "\n" |
|
|
3720 | . "$widget->{x} $widget->{y} $widget->{w} $widget->{h}\n" |
|
|
3721 | . "req $widget->{req_w} $widget->{req_h}\n" |
|
|
3722 | . "visible $widget->{visible}"; |
|
|
3723 | } |
|
|
3724 | |
|
|
3725 | $self->{children}[0]->set_markup ($tip); |
|
|
3726 | }; |
3676 | } |
3727 | } |
3677 | |
3728 | |
3678 | sub size_request { |
3729 | sub size_request { |
3679 | my ($self) = @_; |
3730 | my ($self) = @_; |
3680 | |
3731 | |