diff options
| author | Pietro Gagliardi <[email protected]> | 2015-12-11 20:37:59 -0500 |
|---|---|---|
| committer | Pietro Gagliardi <[email protected]> | 2015-12-11 20:37:59 -0500 |
| commit | f8e3f12ab02b528f2a05a4f713d7af7ea8e44b42 (patch) | |
| tree | 82dedf4d37f0f6d31e88ebb2ca1ce6499dead261 /prev/textbox_unix.go | |
| parent | e34c561ed5bedeb180437ec165882b98d70d38c1 (diff) | |
LET'S GET THIS FINAL REWRITE EVER STARTED
Diffstat (limited to 'prev/textbox_unix.go')
| -rw-r--r-- | prev/textbox_unix.go | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/prev/textbox_unix.go b/prev/textbox_unix.go new file mode 100644 index 0000000..37eb98f --- /dev/null +++ b/prev/textbox_unix.go @@ -0,0 +1,46 @@ +// +build !windows,!darwin + +// 23 october 2014 + +package ui + +import ( + "unsafe" +) + +// #include "gtk_unix.h" +import "C" + +type textbox struct { + *scroller + textview *C.GtkTextView +} + +func newTextbox() Textbox { + widget := C.gtk_text_view_new() + t := &textbox{ + scroller: newScroller(widget, true, true, false), // natively scrollable, has a border, no overlay + textview: (*C.GtkTextView)(unsafe.Pointer(widget)), + } + return t +} + +func (t *textbox) Text() string { + var start, end C.GtkTextIter + + buf := C.gtk_text_view_get_buffer(t.textview) + C.gtk_text_buffer_get_bounds(buf, &start, &end) + // include hidden chars even though there can't be one since Textbox is explicitly unformatted just to be safe + // don't worry about embedded pixbufs or widgets; those aren't allowed either + ctext := C.gtk_text_buffer_get_text(buf, &start, &end, C.TRUE) + // not explicitly documented: have to manually free this (thanks ste in irc.gimp.net/#gtk+) + defer C.g_free(C.gpointer(unsafe.Pointer(ctext))) + return fromgstr(ctext) +} + +func (t *textbox) SetText(text string) { + ctext := togstr(text) + defer freegstr(ctext) + buf := C.gtk_text_view_get_buffer(t.textview) + C.gtk_text_buffer_set_text(buf, ctext, -1) // null-terminated +} |
