Re: Putting text with links in a TreeView



Aristotle Pagaltzis wrote:

Do you have an idea how I could emulate SexyUrlLabel then? As in,
duplicate the behaviour that some area of the text can be clicked
to invoke a signal?

Making text blue and underlined is no problem, I assume.  The hard part
will be to change the cursor when it's over a link and to make clicks on
a link do something.  I think you will have to use motion notify events:

  sub is_over_link {
    my ($view, $event) = @_;

    return FALSE unless $event->window == $view->get_bin_window;

    my ($path, $column, $cell_x, $cell_y) =
      $view->get_path_at_pos ($event->x, $event->y);

    return FALSE unless
      $column == $view->get_column (COLUMN_WITH_LINKS);

    my $model = $view->get_model;
    my $target = $model->get($model->get_iter ($path), COLUMN_TARGET);
    return defined $target;
  }

  my $link_cursor = Gtk2::Gdk::Cursor->new ('hand2');
  my $default_cursor = Gtk2::Gdk::Cursor->new ('xterm');
  $view->signal_connect (motion_notify_event => sub {
    my ($view, $event) = @_;

    my $cursor = is_over_link ($view, $event)
      ? $link_cursor
      : $default_cursor;
    $view->get_bin_window->set_cursor ($cursor);
  });

  $view->signal_connect (button_release_event => sub {
    my ($view, $event) = @_;

    if (is_over_link ($view, $event)) {
      warn "following link";
      return TRUE;
    }

    return FALSE;
  });

This will make the whole cell clickable.  There might be a way to only
make the text inside the cell clickable via $cell_x and $cell_y, but I
don't know how offhand -- I assume this won't be possible without a
custom cell renderer, though.

-- 
Bye,
-Torsten



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]