diff options
| author | Pietro Gagliardi <[email protected]> | 2014-10-23 18:13:00 -0400 |
|---|---|---|
| committer | Pietro Gagliardi <[email protected]> | 2014-10-23 18:13:00 -0400 |
| commit | cbcf77fb6d2729fa377e820238672b30c564c43f (patch) | |
| tree | 71b7871c8f51a66c962bcdd592313978d647d960 | |
| parent | 92c7598d9d0b1ec8a68f55c8a8a9e46ca1a1db50 (diff) | |
Implemented Textbox on GTK+.
| -rw-r--r-- | textbox_unix.go | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/textbox_unix.go b/textbox_unix.go new file mode 100644 index 0000000..37eb98f --- /dev/null +++ b/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 +} |
