gtk-demo: Improve the tag implementation

Add margins and make it so that clicking on margins next to
links does not activate them.
This commit is contained in:
Matthias Clasen 2016-02-10 00:07:37 -05:00
parent a3a5cf1087
commit 7ad6043478

View File

@ -44,7 +44,7 @@ show_page (GtkTextBuffer *buffer,
if (page == 1) if (page == 1)
{ {
gtk_text_buffer_insert (buffer, &iter, "Some text to show that simple ", -1); gtk_text_buffer_insert (buffer, &iter, "Some text to show that simple ", -1);
insert_link (buffer, &iter, "hypertext", 3); insert_link (buffer, &iter, "hyper text", 3);
gtk_text_buffer_insert (buffer, &iter, " can easily be realized with ", -1); gtk_text_buffer_insert (buffer, &iter, " can easily be realized with ", -1);
insert_link (buffer, &iter, "tags", 2); insert_link (buffer, &iter, "tags", 2);
gtk_text_buffer_insert (buffer, &iter, ".", -1); gtk_text_buffer_insert (buffer, &iter, ".", -1);
@ -173,8 +173,7 @@ event_after (GtkWidget *text_view,
GTK_TEXT_WINDOW_WIDGET, GTK_TEXT_WINDOW_WIDGET,
ex, ey, &x, &y); ex, ey, &x, &y);
gtk_text_view_get_iter_at_location (GTK_TEXT_VIEW (text_view), &iter, x, y); if (gtk_text_view_get_iter_at_location (GTK_TEXT_VIEW (text_view), &iter, x, y))
follow_if_link (text_view, &iter); follow_if_link (text_view, &iter);
return TRUE; return TRUE;
@ -197,8 +196,8 @@ set_cursor_if_appropriate (GtkTextView *text_view,
GtkTextIter iter; GtkTextIter iter;
gboolean hovering = FALSE; gboolean hovering = FALSE;
gtk_text_view_get_iter_at_location (text_view, &iter, x, y); if (gtk_text_view_get_iter_at_location (text_view, &iter, x, y))
{
tags = gtk_text_iter_get_tags (&iter); tags = gtk_text_iter_get_tags (&iter);
for (tagp = tags; tagp != NULL; tagp = tagp->next) for (tagp = tags; tagp != NULL; tagp = tagp->next)
{ {
@ -211,6 +210,7 @@ set_cursor_if_appropriate (GtkTextView *text_view,
break; break;
} }
} }
}
if (hovering != hovering_over_link) if (hovering != hovering_over_link)
{ {
@ -272,6 +272,8 @@ do_hypertext (GtkWidget *do_widget)
view = gtk_text_view_new (); view = gtk_text_view_new ();
gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (view), GTK_WRAP_WORD); gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (view), GTK_WRAP_WORD);
gtk_text_view_set_left_margin (GTK_TEXT_VIEW (view), 20);
gtk_text_view_set_right_margin (GTK_TEXT_VIEW (view), 20);
g_signal_connect (view, "key-press-event", g_signal_connect (view, "key-press-event",
G_CALLBACK (key_press_event), NULL); G_CALLBACK (key_press_event), NULL);
g_signal_connect (view, "event-after", g_signal_connect (view, "event-after",