Implemented Table.OnSelected() on the GTK+ backend.
This commit is contained in:
parent
b964c564e7
commit
607b49482e
|
@ -1,4 +1,4 @@
|
||||||
Window.SetSize()
|
Window.SetSize()
|
||||||
Window.Center() (only really effective on Mac OS X)
|
Window.Center() (only really effective on Mac OS X)
|
||||||
Control.Show()/Control.Hide() (too much effort to get right)
|
Control.Show()/Control.Hide() (too much effort to get right)
|
||||||
Multiple selection Tables (Windows event handling is some wacky dumb thing; will reconsider if I can write a good replacement)
|
Multiple selection Tables (Windows and GTK+ event handling is some wacky dumb thing; could reconsider for Windows if I can write a good replacement but GTK+ still kills it)
|
||||||
|
|
|
@ -12,6 +12,7 @@ import (
|
||||||
|
|
||||||
// #include "gtk_unix.h"
|
// #include "gtk_unix.h"
|
||||||
// extern void goTableModel_toggled(GtkCellRendererToggle *, gchar *, gpointer);
|
// extern void goTableModel_toggled(GtkCellRendererToggle *, gchar *, gpointer);
|
||||||
|
// extern void tableSelectionChanged(GtkTreeSelection *, gpointer);
|
||||||
import "C"
|
import "C"
|
||||||
|
|
||||||
type table struct {
|
type table struct {
|
||||||
|
@ -27,6 +28,8 @@ type table struct {
|
||||||
|
|
||||||
pixbufs []*C.GdkPixbuf
|
pixbufs []*C.GdkPixbuf
|
||||||
|
|
||||||
|
selected *event
|
||||||
|
|
||||||
// stuff required by GtkTreeModel
|
// stuff required by GtkTreeModel
|
||||||
nColumns C.gint
|
nColumns C.gint
|
||||||
old C.gint
|
old C.gint
|
||||||
|
@ -48,11 +51,17 @@ func finishNewTable(b *tablebase, ty reflect.Type) Table {
|
||||||
_widget: widget,
|
_widget: widget,
|
||||||
treeview: (*C.GtkTreeView)(unsafe.Pointer(widget)),
|
treeview: (*C.GtkTreeView)(unsafe.Pointer(widget)),
|
||||||
crtocol: make(map[*C.GtkCellRendererToggle]int),
|
crtocol: make(map[*C.GtkCellRendererToggle]int),
|
||||||
|
selected: newEvent(),
|
||||||
}
|
}
|
||||||
model := C.newTableModel(unsafe.Pointer(t))
|
model := C.newTableModel(unsafe.Pointer(t))
|
||||||
t.model = model
|
t.model = model
|
||||||
t.modelgtk = (*C.GtkTreeModel)(unsafe.Pointer(model))
|
t.modelgtk = (*C.GtkTreeModel)(unsafe.Pointer(model))
|
||||||
t.selection = C.gtk_tree_view_get_selection(t.treeview)
|
t.selection = C.gtk_tree_view_get_selection(t.treeview)
|
||||||
|
g_signal_connect(
|
||||||
|
C.gpointer(unsafe.Pointer(t.selection)),
|
||||||
|
"changed",
|
||||||
|
C.GCallback(C.tableSelectionChanged),
|
||||||
|
C.gpointer(unsafe.Pointer(t)))
|
||||||
C.gtk_tree_view_set_model(t.treeview, t.modelgtk)
|
C.gtk_tree_view_set_model(t.treeview, t.modelgtk)
|
||||||
for i := 0; i < ty.NumField(); i++ {
|
for i := 0; i < ty.NumField(); i++ {
|
||||||
cname := togstr(ty.Field(i).Name)
|
cname := togstr(ty.Field(i).Name)
|
||||||
|
@ -139,6 +148,10 @@ func (t *table) Select(index int) {
|
||||||
C.gtk_tree_selection_select_path(t.selection, path)
|
C.gtk_tree_selection_select_path(t.selection, path)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (t *table) OnSelected(f func()) {
|
||||||
|
t.selected.set(f)
|
||||||
|
}
|
||||||
|
|
||||||
//export goTableModel_get_n_columns
|
//export goTableModel_get_n_columns
|
||||||
func goTableModel_get_n_columns(model *C.GtkTreeModel) C.gint {
|
func goTableModel_get_n_columns(model *C.GtkTreeModel) C.gint {
|
||||||
tm := (*C.goTableModel)(unsafe.Pointer(model))
|
tm := (*C.goTableModel)(unsafe.Pointer(model))
|
||||||
|
@ -204,6 +217,12 @@ func goTableModel_toggled(cr *C.GtkCellRendererToggle, pathstr *C.gchar, data C.
|
||||||
datum.SetBool(!datum.Bool())
|
datum.SetBool(!datum.Bool())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//export tableSelectionChanged
|
||||||
|
func tableSelectionChanged(sel *C.GtkTreeSelection, data C.gpointer) {
|
||||||
|
t := (*table)(unsafe.Pointer(data))
|
||||||
|
t.selected.fire()
|
||||||
|
}
|
||||||
|
|
||||||
func (t *table) widget() *C.GtkWidget {
|
func (t *table) widget() *C.GtkWidget {
|
||||||
return t._widget
|
return t._widget
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue