summaryrefslogtreecommitdiff
path: root/textbox_unix.go
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2014-10-23 18:13:00 -0400
committerPietro Gagliardi <[email protected]>2014-10-23 18:13:00 -0400
commitcbcf77fb6d2729fa377e820238672b30c564c43f (patch)
tree71b7871c8f51a66c962bcdd592313978d647d960 /textbox_unix.go
parent92c7598d9d0b1ec8a68f55c8a8a9e46ca1a1db50 (diff)
Implemented Textbox on GTK+.
Diffstat (limited to 'textbox_unix.go')
-rw-r--r--textbox_unix.go46
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
+}