static void follow_if_link(GtkWidget * widget, GtkTextIter * iter) { GSList *tags = NULL, *tagp = NULL; MarkdownTextView *self = MARKDOWN_TEXTVIEW(widget); tags = gtk_text_iter_get_tags(iter); for (tagp = tags; tagp != NULL; tagp = tagp->next) { GtkTextTag *tag = tagp->data; gint is_underline = 0; gchar *lang = NULL; g_object_get(G_OBJECT(tag), "underline", &is_underline, "language", &lang, NULL); if (is_underline == 1 && lang) { gchar *link = egg_markdown_get_link_uri(self->markdown, atoi(lang)); if (link) { g_signal_emit(self, markdown_textview_signals[LINK_CLICKED], 0, link); g_free(link); } g_free(lang); break; } g_free(lang); } if (tags) g_slist_free(tags); }
/* Links can also be activated by clicking */ static void follow_if_link (GtkWidget *text_view, GtkTextIter *iter) { GSList *tags = NULL, *tagp = NULL; tags = gtk_text_iter_get_tags (iter); for (tagp = tags; tagp != NULL; tagp = tagp->next) { gchar *tag_name; GtkTextTag *tag = tagp->data; g_object_get (G_OBJECT (tag), "name", &tag_name, NULL); if ( g_ascii_strcasecmp(tag_name, "link") == 0) { GtkTextIter iter_end = *iter; GtkTextIter iter_start = iter_end; gtk_text_iter_backward_sentence_start(&iter_start); gtk_text_iter_forward_to_line_end(&iter_end); char *result = \ escape(gtk_text_buffer_get_text(buffer, &iter_start, &iter_end, 0)); gtk_show_uri(NULL, result, GDK_CURRENT_TIME, NULL); g_free(result); } } if(tags) g_slist_free (tags); }
static void follow_if_link (GucharmapCharmap *charmap, GtkTextIter *iter) { GucharmapCharmapPrivate *priv = charmap->priv; GSList *tags = NULL, *tagp = NULL; tags = gtk_text_iter_get_tags (iter); for (tagp = tags; tagp != NULL; tagp = tagp->next) { GtkTextTag *tag = tagp->data; gunichar uc; /* subtract 1 because U+0000 is a character; see above where we set * "link-character" */ uc = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (tag), "link-character")) - 1; if (uc != (gunichar)(-1)) { g_signal_emit (charmap, gucharmap_charmap_signals[LINK_CLICKED], 0, gucharmap_chartable_get_active_character (priv->chartable), uc); gucharmap_charmap_set_active_character (charmap, uc); break; } } if (tags) g_slist_free (tags); }
static void set_cursor_if_appropriate (GtkTextView *text_view, gint x, gint y) { GSList *tags = NULL; GSList *tagp = NULL; GtkTextIter iter; gboolean hovering = FALSE; gtk_text_view_get_iter_at_location (text_view, &iter, x, y); tags = gtk_text_iter_get_tags (&iter); for (tagp = tags; tagp != NULL; tagp = tagp->next) { GtkTextTag *tag = tagp->data; gchar *url = (gchar*)(g_object_get_data (G_OBJECT (tag), "url")); if (url) { hovering = TRUE; break; } } if (hovering != hovering_over_link) { hovering_over_link = hovering; if (hovering_over_link) gdk_window_set_cursor (gtk_text_view_get_window (text_view, GTK_TEXT_WINDOW_TEXT), hand_cursor); else gdk_window_set_cursor (gtk_text_view_get_window (text_view, GTK_TEXT_WINDOW_TEXT), regular_cursor); } if (tags) g_slist_free (tags); }
static gboolean link_clicked (GtkWidget *widget, GdkEventButton *event, EventLog *log) { int x, y; GtkTextIter iter; GSList *tags, *l; if (event->button != 1 || event->type != GDK_2BUTTON_PRESS) return FALSE; gtk_text_view_window_to_buffer_coords (GTK_TEXT_VIEW (log->text_view), GTK_TEXT_WINDOW_WIDGET, event->x, event->y, &x, &y); gtk_text_view_get_iter_at_location (GTK_TEXT_VIEW (log->text_view), &iter, x, y); for (l = tags = gtk_text_iter_get_tags (&iter); l; l = l->next) { Accessible *accessible; if ((accessible = g_object_get_data (l->data, "accessible"))) { poke (accessible); return TRUE; } } g_slist_free (tags); return FALSE; }
/* Looks at all tags covering the position (x, y) in the text view, * and if one of them is a link, change the cursor to the "hands" cursor * typically used by web browsers. */ static void set_cursor_if_appropriate (GtkTextView *text_view, gint x, gint y) { GSList *tags = NULL, *tagp = NULL; GtkTextIter iter; gboolean hovering = FALSE; gtk_text_view_get_iter_at_location (text_view, &iter, x, y); tags = gtk_text_iter_get_tags (&iter); for (tagp = tags; tagp != NULL; tagp = tagp->next) { gchar *tag_name; GtkTextTag *tag = tagp->data; g_object_get (G_OBJECT (tag), "name", &tag_name, NULL); if ( g_ascii_strcasecmp(tag_name, "link") == 0) { hovering = TRUE; break; } } GdkCursor *cursor; if (hovering) cursor = gdk_cursor_new (GDK_LEFT_PTR); else cursor = gdk_cursor_new (GDK_XTERM); gdk_window_set_cursor (gtk_text_view_get_window (text_view, GTK_TEXT_WINDOW_TEXT), cursor); gdk_cursor_unref (cursor); if (tags) g_slist_free (tags); }
static void load_images(MarkdownTextView * self) { GtkTextBuffer *buffer; GtkTextIter iter; GSList *tags, *tagp; gchar *image_path; buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(self)); gtk_text_buffer_get_start_iter(buffer, &iter); do { tags = gtk_text_iter_get_tags(&iter); for (tagp = tags; tagp != NULL; tagp = tagp->next) { GtkTextTag *tag = tagp->data; gint is_underline = 0; gchar *lang = NULL; g_object_get(G_OBJECT(tag), "underline", &is_underline, "language", &lang, NULL); if (is_underline == 2 && lang) { GdkPixbuf *pixbuf; gchar *path; image_path = egg_markdown_get_link_uri(self->markdown, atoi(lang)); path = g_build_filename(self->image_directory, image_path, NULL); pixbuf = gdk_pixbuf_new_from_file(path, NULL); if (pixbuf) { GtkTextMark *mark; GtkTextIter start; mark = gtk_text_buffer_create_mark(buffer, NULL, &iter, FALSE); gtk_text_buffer_get_iter_at_mark(buffer, &start, mark); gtk_text_iter_forward_to_tag_toggle(&iter, tag); gtk_text_buffer_delete(buffer, &start, &iter); gtk_text_buffer_insert_pixbuf(buffer, &iter, pixbuf); g_object_unref(pixbuf); gtk_text_buffer_delete_mark(buffer, mark); } g_free(image_path); g_free(lang); g_free(path); break; } g_free(lang); } if (tags) g_slist_free(tags); } while (gtk_text_iter_forward_to_tag_toggle(&iter, NULL)); }
static void set_cursor_if_appropriate(MarkdownTextView * self, gint x, gint y) { GSList *tags = NULL, *tagp = NULL; GtkTextIter iter; gboolean hovering = FALSE; gchar *link_uri = NULL; gtk_text_view_get_iter_at_location(GTK_TEXT_VIEW(self), &iter, x, y); tags = gtk_text_iter_get_tags(&iter); for (tagp = tags; tagp != NULL; tagp = tagp->next) { GtkTextTag *tag = tagp->data; gint is_underline = 0; gchar *lang = NULL; g_object_get(G_OBJECT(tag), "underline", &is_underline, "language", &lang, NULL); if (is_underline == 1 && lang) { link_uri = egg_markdown_get_link_uri(self->markdown, atoi(lang)); g_free(lang); hovering = TRUE; break; } g_free(lang); } if (hovering != self->hovering_over_link) { self->hovering_over_link = hovering; if (self->hovering_over_link) { g_signal_emit(self, markdown_textview_signals[HOVERING_OVER_LINK], 0, link_uri); gdk_window_set_cursor(gtk_text_view_get_window (GTK_TEXT_VIEW(self), GTK_TEXT_WINDOW_TEXT), hand_cursor); } else { g_signal_emit(self, markdown_textview_signals[HOVERING_OVER_TEXT], 0); gdk_window_set_cursor(gtk_text_view_get_window (GTK_TEXT_VIEW(self), GTK_TEXT_WINDOW_TEXT), NULL); } } if (link_uri) g_free(link_uri); if (tags) g_slist_free(tags); }
/************************************************************************** Set the "hand" cursor when moving over a link. **************************************************************************/ static void set_cursor_if_appropriate(GtkTextView *text_view, gint x, gint y) { static gboolean hovering_over_link = FALSE; static GdkCursor *hand_cursor = NULL; static GdkCursor *regular_cursor = NULL; GSList *tags, *tagp; GtkTextIter iter; gboolean hovering = FALSE; /* Initialize the cursors. */ if (!hand_cursor) { hand_cursor = gdk_cursor_new_for_display( gdk_screen_get_display(gdk_screen_get_default()), GDK_HAND2); } if (!regular_cursor) { regular_cursor = gdk_cursor_new_for_display( gdk_screen_get_display(gdk_screen_get_default()), GDK_XTERM); } gtk_text_view_get_iter_at_location(text_view, &iter, x, y); tags = gtk_text_iter_get_tags(&iter); for (tagp = tags; tagp; tagp = tagp->next) { enum text_link_type type = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(tagp->data), "type")); if (type != 0) { hovering = TRUE; break; } } if (hovering != hovering_over_link) { hovering_over_link = hovering; if (hovering_over_link) { gdk_window_set_cursor(gtk_text_view_get_window(text_view, GTK_TEXT_WINDOW_TEXT), hand_cursor); } else { gdk_window_set_cursor(gtk_text_view_get_window(text_view, GTK_TEXT_WINDOW_TEXT), regular_cursor); } } if (tags) { g_slist_free(tags); } }
gint gimp_text_buffer_get_iter_index (GimpTextBuffer *buffer, GtkTextIter *iter, gboolean layout_index) { GtkTextIter start; gchar *string; gint index; g_return_val_if_fail (GIMP_IS_TEXT_BUFFER (buffer), 0); gtk_text_buffer_get_start_iter (GTK_TEXT_BUFFER (buffer), &start); string = gtk_text_buffer_get_text (GTK_TEXT_BUFFER (buffer), &start, iter, TRUE); index = strlen (string); g_free (string); if (layout_index) { do { GSList *tags = gtk_text_iter_get_tags (&start); GSList *list; for (list = tags; list; list = g_slist_next (list)) { GtkTextTag *tag = list->data; if (g_list_find (buffer->kerning_tags, tag)) { index += WORD_JOINER_LENGTH; break; } } g_slist_free (tags); gtk_text_iter_forward_char (&start); /* We might have moved too far */ if (gtk_text_iter_compare (&start, iter) > 0) start = *iter; } while (! gtk_text_iter_equal (&start, iter)); } return index; }
/* Links can also be activated by clicking. */ static gboolean event_after (GtkWidget* text_view, GdkEvent* ev, UgBanner* banner) { GtkTextIter start, end, iter; GtkTextBuffer *buffer; GdkEventButton *event; gint x, y; GSList* slist; if (ev->type != GDK_BUTTON_RELEASE) return FALSE; event = (GdkEventButton *)ev; if (event->button != GDK_BUTTON_PRIMARY) return FALSE; buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (text_view)); /* we shouldn't follow a link if the user has selected something */ gtk_text_buffer_get_selection_bounds (buffer, &start, &end); if (gtk_text_iter_get_offset (&start) != gtk_text_iter_get_offset (&end)) return FALSE; gtk_text_view_window_to_buffer_coords (GTK_TEXT_VIEW (text_view), GTK_TEXT_WINDOW_WIDGET, event->x, event->y, &x, &y); gtk_text_view_get_iter_at_location (GTK_TEXT_VIEW (text_view), &iter, x, y); slist = gtk_text_iter_get_tags (&iter); if (slist) { switch (banner->status) { case UG_BANNER_DONATION: // ug_launch_uri ("https://sourceforge.net/p/urlget/donate/?source=navbar"); ug_launch_uri ("http://ugetdm.com/donate"); break; case UG_BANNER_SURVEY: ug_launch_uri ("http://ugetdm.com/survey"); break; } } if (slist) g_slist_free (slist); return FALSE; }
/* FIXME: total horror */ static gboolean char_is_invisible (const GtkTextIter *iter) { GSList *tags; gboolean invisible = FALSE; tags = gtk_text_iter_get_tags (iter); while (tags) { gboolean this_invisible, invisible_set; g_object_get (tags->data, "invisible", &this_invisible, "invisible-set", &invisible_set, NULL); if (invisible_set) invisible = this_invisible; tags = g_slist_delete_link (tags, tags); } return invisible; }
gboolean utl_gui_url_event_after (GtkWidget *textview, GdkEvent *ev, GSList **links_list) { GtkTextIter start, end, iter; GtkTextBuffer *buffer; GdkEventButton *event; gint x, y; GSList *tags = NULL, *tagp = NULL; GtkTextTag *tag; gchar *link; gint slink; gchar tmpbuf[BUFFER_SIZE]; if (ev->type != GDK_BUTTON_RELEASE) return FALSE; event = (GdkEventButton *) ev; if (event->button != 1) return FALSE; buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (textview)); gtk_text_buffer_get_selection_bounds (buffer, &start, &end); if (gtk_text_iter_get_offset (&start) != gtk_text_iter_get_offset (&end)) return FALSE; gtk_text_view_window_to_buffer_coords (GTK_TEXT_VIEW (textview), GTK_TEXT_WINDOW_WIDGET, event->x, event->y, &x, &y); gtk_text_view_get_iter_at_location (GTK_TEXT_VIEW (textview), &iter, x, y); tags = gtk_text_iter_get_tags (&iter); for (tagp = tags; tagp != NULL; tagp = tagp->next) { tag = tagp->data; slink = (gint) g_object_get_data (G_OBJECT (tag), "link"); if (slink != 0) { link = g_slist_nth_data (*links_list, slink-1); g_snprintf (tmpbuf, BUFFER_SIZE, "\"%s\"", link); utl_run_helper (tmpbuf, utl_get_link_type (link)); break; } } if (tags) g_slist_free (tags); return FALSE; }
/* Looks at all tags covering the position of iter in the text view, * and if one of them is a link, follow it by showing the page identified * by the data attached to it. */ static void follow_if_link (G_GNUC_UNUSED GtkWidget *text_view, GtkTextIter *iter, ClassProperties *cprop) { GSList *tags = NULL, *tagp = NULL; tags = gtk_text_iter_get_tags (iter); for (tagp = tags; tagp != NULL; tagp = tagp->next) { GtkTextTag *tag = tagp->data; const gchar *dn; dn = g_object_get_data (G_OBJECT (tag), "class"); if (dn) g_signal_emit (cprop, class_properties_signals [OPEN_CLASS], 0, dn); } if (tags) g_slist_free (tags); }
/* Looks at all tags covering the position (x, y) in the text view, * and if one of them is a link, change the cursor to the "hands" cursor * typically used by web browsers. */ static void set_cursor_if_appropriate (GtkTextView * text_view, gint x, gint y, GtrContextPanel *panel) { GSList *tags = NULL, *tagp = NULL; GtkTextIter iter; GtrContextPanelPrivate *priv; gboolean hovering = FALSE; priv = gtr_context_panel_get_instance_private(panel); gtk_text_view_get_iter_at_location (text_view, &iter, x, y); tags = gtk_text_iter_get_tags (&iter); for (tagp = tags; tagp != NULL; tagp = tagp->next) { GtkTextTag *tag = tagp->data; gint *is_path = g_object_get_data (G_OBJECT (tag), "is_path"); if (is_path) { hovering = TRUE; break; } } if (hovering != priv->hovering_over_link) { priv->hovering_over_link = hovering; if (priv->hovering_over_link) gdk_window_set_cursor (gtk_text_view_get_window (text_view, GTK_TEXT_WINDOW_TEXT), priv->hand_cursor); else gdk_window_set_cursor (gtk_text_view_get_window (text_view, GTK_TEXT_WINDOW_TEXT), priv->regular_cursor); } if (tags) g_slist_free (tags); }
/* Looks at all tags covering the position of iter in the text view, * and if one of them is a link, follow it by showing the page identified * by the data attached to it. */ static void follow_if_link (G_GNUC_UNUSED GtkWidget *text_view, GtkTextIter *iter, GdauiCloud *cloud) { GSList *tags = NULL, *tagp; tags = gtk_text_iter_get_tags (iter); for (tagp = tags; tagp; tagp = tagp->next) { GtkTextTag *tag = tagp->data; gint row; row = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (tag), "row")) - 1; if (row >= 0) { row_clicked (cloud, row, tag); break; } } if (tags) g_slist_free (tags); }
static gboolean motion_cb (GtkWidget *w, GdkEventMotion *ev, gpointer d) { gint x, y; GSList *tags = NULL, *tagp = NULL; GtkTextIter iter; gboolean hovering = FALSE; gtk_text_view_window_to_buffer_coords (GTK_TEXT_VIEW (w), GTK_TEXT_WINDOW_WIDGET, ev->x, ev->y, &x, &y); gtk_text_view_get_iter_at_location (GTK_TEXT_VIEW (w), &iter, x, y); tags = gtk_text_iter_get_tags (&iter); for (tagp = tags; tagp != NULL; tagp = tagp->next) { GtkTextTag *tag = tagp->data; gint link = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (tag), "is_link")); if (link) { hovering = TRUE; break; } } if (hovering != hovering_over_link) { hovering_over_link = hovering; if (hovering_over_link) gdk_window_set_cursor (gtk_text_view_get_window (GTK_TEXT_VIEW (w), GTK_TEXT_WINDOW_TEXT), hand); else gdk_window_set_cursor (gtk_text_view_get_window (GTK_TEXT_VIEW (w), GTK_TEXT_WINDOW_TEXT), normal); } if (tags) g_slist_free (tags); gdk_window_get_pointer (gtk_widget_get_window (w), NULL, NULL, NULL); return FALSE; }
static void set_cursor_if_appropriate (GucharmapCharmap *charmap, gint x, gint y) { GucharmapCharmapPrivate *priv = charmap->priv; GSList *tags = NULL, *tagp = NULL; GtkTextIter iter; gboolean hovering_over_link = FALSE; gtk_text_view_get_iter_at_location (priv->details_view, &iter, x, y); tags = gtk_text_iter_get_tags (&iter); for (tagp = tags; tagp != NULL; tagp = tagp->next) { GtkTextTag *tag = tagp->data; gunichar uc; /* subtract 1 because U+0000 is a character; see above where we set * "link-character" */ uc = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (tag), "link-character")) - 1; if (uc != (gunichar)(-1)) { hovering_over_link = TRUE; break; } } if (hovering_over_link != priv->hovering_over_link) { priv->hovering_over_link = hovering_over_link; if (hovering_over_link) gdk_window_set_cursor (gtk_text_view_get_window (priv->details_view, GTK_TEXT_WINDOW_TEXT), priv->hand_cursor); else gdk_window_set_cursor (gtk_text_view_get_window (priv->details_view, GTK_TEXT_WINDOW_TEXT), priv->regular_cursor); } if (tags) g_slist_free (tags); }
static gboolean _text_view_click_handler(GtkWidget *widget, GdkEvent *event) { GtkTextView *text_view = GTK_TEXT_VIEW(widget); if (event->type == GDK_BUTTON_RELEASE) { GdkEventButton *button_event = GDK_EVENT_BUTTON(event); if (button_event->button == 1) { GtkTextBuffer *text_buffer = gtk_text_view_get_buffer(text_view); gint x; gint y; GtkTextIter text_iter; gtk_text_view_window_to_buffer_coords(text_view, GTK_TEXT_WINDOW_WIDGET, button_event->x, button_event->y, &x, &y); gtk_text_view_get_iter_at_location(text_view, &text_iter, x, y); { GSList *text_tag_list = gtk_text_iter_get_tags(&text_iter); GSList *text_tag_list_item; for (text_tag_list_item = text_tag_list; text_tag_list_item != NULL; text_tag_list_item = text_tag_list_item->next) { GtkTextTag *text_tag = GTK_TEXT_TAG(text_tag_list_item->data); if (g_object_get_data(G_OBJECT(text_tag), "column_type") != NULL) { gtk_text_buffer_place_cursor(text_buffer); break; } } if (text_tag_list != NULL) g_slist_free(text_tag_list); } return TRUE; } } return FALSE; }
/* Looks at all tags covering the position (x, y) in the text view, * and if one of them is a link, change the cursor to the "hands" cursor * typically used by web browsers. */ static void set_cursor_if_appropriate (GtkTextView *text_view, gint x, gint y, EntryProperties *eprop) { GSList *tags = NULL, *tagp = NULL; GtkTextIter iter; gboolean hovering = FALSE; gtk_text_view_get_iter_at_location (text_view, &iter, x, y); tags = gtk_text_iter_get_tags (&iter); for (tagp = tags; tagp != NULL; tagp = tagp->next) { GtkTextTag *tag = tagp->data; if (g_object_get_data (G_OBJECT (tag), "dn") || g_object_get_data (G_OBJECT (tag), "class")) { hovering = TRUE; break; } } if (hovering != eprop->priv->hovering_over_link) { eprop->priv->hovering_over_link = hovering; if (eprop->priv->hovering_over_link) { if (! hand_cursor) hand_cursor = gdk_cursor_new (GDK_HAND2); gdk_window_set_cursor (gtk_text_view_get_window (text_view, GTK_TEXT_WINDOW_TEXT), hand_cursor); } else { if (!regular_cursor) regular_cursor = gdk_cursor_new (GDK_XTERM); gdk_window_set_cursor (gtk_text_view_get_window (text_view, GTK_TEXT_WINDOW_TEXT), regular_cursor); } } if (tags) g_slist_free (tags); }
/* on_view_event_after */ static gboolean _on_view_event_after(GtkWidget * widget, GdkEvent * event, gpointer data) { GHtml * ghtml = data; GdkEventButton * eb; GtkTextIter start; GtkTextIter end; gint x; gint y; GtkTextIter iter; GSList * tags; GSList * p; char * link = NULL; gchar * url; if(event->type != GDK_BUTTON_RELEASE || event->button.button != 1) return FALSE; eb = &event->button; gtk_text_buffer_get_selection_bounds(ghtml->tbuffer, &start, &end); if(gtk_text_iter_get_offset(&start) != gtk_text_iter_get_offset(&end)) return FALSE; gtk_text_view_window_to_buffer_coords(GTK_TEXT_VIEW(widget), GTK_TEXT_WINDOW_WIDGET, eb->x, eb->y, &x, &y); gtk_text_view_get_iter_at_location(GTK_TEXT_VIEW(widget), &iter, x, y); tags = gtk_text_iter_get_tags(&iter); for(p = tags; p != NULL; p = p->next) if((link = g_object_get_data(G_OBJECT(p->data), "link")) != NULL) break; if(tags != NULL) g_slist_free(tags); if(link == NULL) return FALSE; url = (ghtml->base != NULL) ? ghtml->base : _history_get_location( ghtml->current); if((url = _ghtml_make_url(url, link)) != NULL) surfer_open(ghtml->surfer, url); else surfer_open(ghtml->surfer, link); g_free(url); return FALSE; }
/* Looks at all tags covering the position (x, y) in the text view, * and if one of them is a link, change the cursor to the "hands" cursor * typically used by web browsers. */ static void set_cursor_if_appropriate (GtkTextView *text_view, gint x, gint y, GdauiCloud *cloud) { GSList *tags = NULL, *tagp; GtkTextIter iter; gboolean hovering = FALSE; gtk_text_view_get_iter_at_location (text_view, &iter, x, y); tags = gtk_text_iter_get_tags (&iter); for (tagp = tags; tagp; tagp = tagp->next) { GtkTextTag *tag = tagp->data; gint row; row = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (tag), "row")) - 1; if (row >= 0) { hovering = TRUE; break; } } if (hovering != cloud->priv->hovering_over_link) { cloud->priv->hovering_over_link = hovering; if (cloud->priv->hovering_over_link) { if (! hand_cursor) hand_cursor = gdk_cursor_new (GDK_HAND2); gdk_window_set_cursor (gtk_text_view_get_window (text_view, GTK_TEXT_WINDOW_TEXT), hand_cursor); } else { if (!regular_cursor) regular_cursor = gdk_cursor_new (GDK_XTERM); gdk_window_set_cursor (gtk_text_view_get_window (text_view, GTK_TEXT_WINDOW_TEXT), regular_cursor); } } if (tags) g_slist_free (tags); }
static void follow_if_link (GtrContextPanel *panel, GtkWidget *text_view, GtkTextIter *iter) { GSList *tags = NULL, *tagp = NULL; tags = gtk_text_iter_get_tags (iter); for (tagp = tags; tagp != NULL; tagp = tagp->next) { GtkTextTag *tag = tagp->data; gint *is_path = g_object_get_data (G_OBJECT (tag), "is_path"); if (is_path) { setup_notes_edition (panel); break; } } if (tags) g_slist_free (tags); }
void utl_gui_url_set_cursor_if_appropriate (GtkTextView *textview, gint x, gint y, GUI *appGUI) { GSList *tags = NULL, *tagp = NULL; GtkTextBuffer *buffer; GtkTextIter iter; gboolean hovering = FALSE; GtkTextTag *tag; int *slink; buffer = gtk_text_view_get_buffer (textview); gtk_text_view_get_iter_at_location (textview, &iter, x, y); tags = gtk_text_iter_get_tags (&iter); for (tagp = tags; tagp != NULL; tagp = tagp->next) { tag = tagp->data; slink = g_object_get_data (G_OBJECT (tag), "link"); if (slink != 0) { hovering = TRUE; break; } } if (hovering != appGUI->hovering_over_link) { appGUI->hovering_over_link = hovering; if (appGUI->hovering_over_link) { gdk_window_set_cursor (gtk_text_view_get_window (textview, GTK_TEXT_WINDOW_TEXT), appGUI->hand_cursor); } else { gdk_window_set_cursor (gtk_text_view_get_window (textview, GTK_TEXT_WINDOW_TEXT), appGUI->regular_cursor); } } if (tags) { g_slist_free (tags); } }
void gimp_text_buffer_pre_serialize (GimpTextBuffer *buffer, GtkTextBuffer *content) { GtkTextIter iter; g_return_if_fail (GIMP_IS_TEXT_BUFFER (buffer)); g_return_if_fail (GTK_IS_TEXT_BUFFER (content)); gtk_text_buffer_get_start_iter (content, &iter); do { GSList *tags = gtk_text_iter_get_tags (&iter); GSList *list; for (list = tags; list; list = g_slist_next (list)) { GtkTextTag *tag = list->data; if (g_list_find (buffer->kerning_tags, tag)) { GtkTextIter end; gtk_text_buffer_insert_with_tags (content, &iter, WORD_JOINER, -1, tag, NULL); end = iter; gtk_text_iter_forward_char (&end); gtk_text_buffer_remove_tag (content, tag, &iter, &end); break; } } g_slist_free (tags); } while (gtk_text_iter_forward_char (&iter)); }
/* Looks at all tags covering the position of iter in the text view, * and if one of them is a link, follow it by showing the page identified * by the data attached to it. */ static void follow_if_link (GtkWidget *text_view, GtkTextIter *iter) { GSList *tags = NULL, *tagp = NULL; tags = gtk_text_iter_get_tags (iter); for (tagp = tags; tagp != NULL; tagp = tagp->next) { GtkTextTag *tag = tagp->data; gint page = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (tag), "page")); if (page != 0) { show_page (gtk_text_view_get_buffer (GTK_TEXT_VIEW (text_view)), page); break; } } if (tags) g_slist_free (tags); }
void gimp_text_buffer_post_deserialize (GimpTextBuffer *buffer, GtkTextBuffer *content) { GtkTextIter iter; g_return_if_fail (GIMP_IS_TEXT_BUFFER (buffer)); g_return_if_fail (GTK_IS_TEXT_BUFFER (content)); gtk_text_buffer_get_start_iter (content, &iter); do { GSList *tags = gtk_text_iter_get_tags (&iter); GSList *list; for (list = tags; list; list = g_slist_next (list)) { GtkTextTag *tag = list->data; if (g_list_find (buffer->kerning_tags, tag)) { GtkTextIter end; gtk_text_iter_forward_char (&iter); gtk_text_buffer_backspace (content, &iter, FALSE, TRUE); end = iter; gtk_text_iter_forward_char (&end); gtk_text_buffer_apply_tag (content, tag, &iter, &end); break; } } g_slist_free (tags); } while (gtk_text_iter_forward_char (&iter)); }
static void follow_if_link (GtkWidget *text_view, GtkTextIter *iter) { GSList *tags = NULL, *tagp = NULL; tags = gtk_text_iter_get_tags (iter); for (tagp = tags; tagp != NULL; tagp = tagp->next) { GtkTextTag *tag = tagp->data; gchar *url = (gchar*)(g_object_get_data (G_OBJECT (tag), "url")); if (url) { if(fork() == 0) execlp("xdg-open" , "xdg-open" , url , (char**)NULL); break; } } if (tags) g_slist_free (tags); }
gboolean gimp_text_buffer_has_markup (GimpTextBuffer *buffer) { GtkTextIter iter; g_return_val_if_fail (GIMP_IS_TEXT_BUFFER (buffer), FALSE); gtk_text_buffer_get_start_iter (GTK_TEXT_BUFFER (buffer), &iter); do { GSList *tags = gtk_text_iter_get_tags (&iter); if (tags) { g_slist_free (tags); return TRUE; } } while (gtk_text_iter_forward_char (&iter)); return FALSE; }
/* * Gets the url string we had added while parsing the html */ void get_url_at_location(gchar **return_val, GtkTextView *text_view, gint x, gint y) { GSList *tags = NULL, *curr_tag = NULL; GtkTextIter iter; gchar *url = NULL; gtk_text_view_get_iter_at_location(text_view, &iter, x, y); tags = gtk_text_iter_get_tags(&iter); for (curr_tag = tags; curr_tag != NULL; curr_tag = curr_tag->next) { GtkTextTag *tag = curr_tag->data; url = g_object_get_data(G_OBJECT(tag), "href"); if (url != NULL) break; } *return_val = url; if (tags) g_slist_free(tags); }