Re: text with links





----- Original Message ----
From: Paul Drynoff <pauldrynoff gmail com>
To: Lance Dillon <riffraff169 yahoo com>
Cc: gtk-app-devel-list gnome org
Sent: Wednesday, September 6, 2006 12:31:20 PM
Subject: Re: text with links

On 9/6/06, Lance Dillon <riffraff169 yahoo com> wrote:
The easiest and quickest way I can think of is create a TextView, add some
TextAnchors, define some LinkButtons, and anchor the LinkButtons to the
TextAnchors.

Thanks, without your help I never catch this feature of GtkTextView,
but there is some minor thing, what about "LinkButton", I don't find
such component,
I have to write it?
--------
No, actually, GtkLinkButton is a new widget in 2.10 I think.  If you are using gtk<2.10, then just a plain 
GtkButton, perhaps marked up with an underline so it looks like a standard hypertext link.
--------

I used GtkButton, but it is appered above the other text, and I can
not find method to make text in it it "blue" and underlined, here is
code:

------
What I would probably do is create a blank button, create a label with markup, then add the label to the 
button, since a button is just a container:

GtkLabel *lab=gtk_label_new();
gtk_label_set_markup(GTK_LABEL(lab),"<span underline=\"single\" foreground=\"blue\">Link</span>");
GtkButton *gb=gtk_button_new();
gtk_container_add(GTK_CONTAINER(gb),lab);

----------


#include <cstdlib>
#include <gtk/gtk.h>

static void on_link(GtkButton *button, gpointer user_data)
{
    g_debug("on_link\n");
}

int main(int argc, char *argv[])
{
  gtk_init(&argc, &argv);

  GtkWidget *topLevelWindow=gtk_window_new(GTK_WINDOW_TOPLEVEL);

  g_signal_connect(G_OBJECT(topLevelWindow), "delete_event",
                   G_CALLBACK(gtk_false), NULL);
  g_signal_connect(G_OBJECT(topLevelWindow), "destroy",
           G_CALLBACK(gtk_main_quit), NULL);
  GtkTextView *tv = GTK_TEXT_VIEW(gtk_text_view_new());
  gtk_container_add(GTK_CONTAINER(topLevelWindow), GTK_WIDGET(tv));
  GtkButton *bt = GTK_BUTTON(gtk_button_new_with_label("link"));
  gtk_button_set_relief(bt, GTK_RELIEF_NONE);
  g_signal_connect(G_OBJECT(bt), "clicked", G_CALLBACK(on_link), NULL);

  GtkTextBuffer *buffer = gtk_text_view_get_buffer(tv);
  GtkTextIter iter;
  gtk_text_buffer_get_iter_at_offset(
    buffer, &iter, 0
  );
  gtk_text_buffer_insert(buffer, &iter, "aaa ", -1);
  GtkTextChildAnchor *anchor =
      gtk_text_buffer_create_child_anchor(buffer, &iter);
  gtk_text_buffer_insert(buffer, &iter, "\nbbb", -1);
  gtk_text_view_set_editable(tv, FALSE);
  gtk_text_view_add_child_at_anchor(tv, GTK_WIDGET(bt), anchor);

  gtk_widget_show_all(topLevelWindow);
  gtk_main();

  return EXIT_SUCCESS;
}




------------------

I would have to test this.  I think the gtk example does some anchors inline.





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