Skip to content

Commit

Permalink
InsertWithTag() is a wrapper around gtk_text_buffer_insert_with_tags(…
Browse files Browse the repository at this point in the history
…) that supports only one tag

as cgo does not support functions with variable-argument lists (see golang/go#975)
  • Loading branch information
alpicoid committed May 4, 2019
1 parent ff571eb commit 8b37baa
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
8 changes: 8 additions & 0 deletions gtk/gtk.go
Original file line number Diff line number Diff line change
Expand Up @@ -7658,6 +7658,14 @@ func (v *TextBuffer) InsertAtCursor(text string) {
C.gtk_text_buffer_insert_at_cursor(v.native(), (*C.gchar)(cstr), C.gint(len(text)))
}

// InsertWithTag() is a wrapper around gtk_text_buffer_insert_with_tags() that supports only one tag
// as cgo does not support functions with variable-argument lists (see https://github.com/golang/go/issues/975)
func (v *TextBuffer) InsertWithTag(iter *TextIter, text string, tag *TextTag) {
cstr := C.CString(text)
defer C.free(unsafe.Pointer(cstr))
C._gtk_text_buffer_insert_with_tag(v.native(), (*C.GtkTextIter)(iter), (*C.gchar)(cstr), C.gint(len(text)), tag.native())
}

// RemoveTag() is a wrapper around gtk_text_buffer_remove_tag().
func (v *TextBuffer) RemoveTag(tag *TextTag, start, end *TextIter) {
C.gtk_text_buffer_remove_tag(v.native(), tag.native(), (*C.GtkTextIter)(start), (*C.GtkTextIter)(end))
Expand Down
4 changes: 4 additions & 0 deletions gtk/gtk.go.h
Original file line number Diff line number Diff line change
Expand Up @@ -927,3 +927,7 @@ extern gboolean goTreeModelFilterFuncs (GtkTreeModel *model, GtkTreeIter *iter,
static inline void _gtk_tree_model_filter_set_visible_func(GtkTreeModelFilter *filter, gpointer user_data) {
gtk_tree_model_filter_set_visible_func(filter, (GtkTreeModelFilterVisibleFunc)(goTreeModelFilterFuncs), user_data, NULL);
}

static inline void _gtk_text_buffer_insert_with_tag(GtkTextBuffer* buffer, GtkTextIter* iter, const gchar* text, gint len, GtkTextTag* tag) {
gtk_text_buffer_insert_with_tags(buffer, iter, text, len, tag, NULL);
}

0 comments on commit 8b37baa

Please sign in to comment.