Re: text with links



No, actually, GtkLinkButton is a new widget in 2.10 I think.
Sad, as I remember, starting from some version gtk+ supports only
windows > windows 98, and I suppose 2.10 is this version.

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:

Great.

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

The last problem is, if you trys example, you see that
in line "aaa Link",
the "Link" and "aaa" is not on the same line,
can GtkTextView care about anchors automaticaly, or I should do it by my self?
I don't find API to get height of line in GtkTextView to resize button to it,
and interesting what happend if there are no text, only anchors on line,
is it climb on the next line?

Here is updated example:


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

static void on_link(GtkButton *button, gpointer) { 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));
 GtkLabel *lab = GTK_LABEL(gtk_label_new(NULL));
 gtk_label_set_markup(GTK_LABEL(lab),
                       "<span underline=\"single\" foreground=\"blue\">Link</span>");
 GtkButton *bt = GTK_BUTTON(gtk_button_new());
 gtk_container_add(GTK_CONTAINER(bt), GTK_WIDGET(lab));
 gtk_button_set_relief(bt, GTK_RELIEF_NONE);
 g_signal_connect(G_OBJECT(bt), "clicked", G_CALLBACK(on_link), NULL);
//  gtk_container_add(GTK_CONTAINER(topLevelWindow), GTK_WIDGET(bt));

 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;
}




On 9/6/06, Lance Dillon <riffraff169 yahoo com> wrote:


----- 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.


_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list




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