Began the implementation of Table on GTK+.

This commit is contained in:
Pietro Gagliardi 2014-07-29 01:06:56 -04:00
parent 74756e3086
commit a501c5678d
3 changed files with 83 additions and 2 deletions

View File

@ -1,7 +1,5 @@
/* 16 march 2014 */ /* 16 march 2014 */
/* This header file is a convenience to ensure that the compatibility flags below are included in all Go files that include <gtk/gtk.h> */
/* /*
MIN_REQUIRED signals that programs are expected to run on at least GLib 2.32/GTK+ 3.4 and thus deprectation warnings for newer versions (such as gtk_scrolled_window_add_with_viewport() being deprecated in GTK+ 3.8) should be suppressed. MIN_REQUIRED signals that programs are expected to run on at least GLib 2.32/GTK+ 3.4 and thus deprectation warnings for newer versions (such as gtk_scrolled_window_add_with_viewport() being deprecated in GTK+ 3.8) should be suppressed.
MAX_ALLOWED signals that programs will not use features introduced in newer versions of GLib/GTK+ and that the compiler should warn us if we slip. MAX_ALLOWED signals that programs will not use features introduced in newer versions of GLib/GTK+ and that the compiler should warn us if we slip.
@ -20,3 +18,6 @@ Thanks to desrt in irc.gimp.net/#gtk+
#include <stdlib.h> #include <stdlib.h>
#include <gtk/gtk.h> #include <gtk/gtk.h>
/* table_unix.c */
extern void tableAppendColumn(GtkTreeView *, gchar *);

16
redo/table_unix.c Normal file
View File

@ -0,0 +1,16 @@
/* 29 july 2014 */
#include "gtk_unix.h"
#include "_cgo_export.h"
void tableAppendColumn(GtkTreeView *table, gchar *name)
{
GtkTreeViewColumn *col;
GtkCellRenderer *renderer;
renderer = gtk_cell_renderer_text_new();
col = gtk_tree_view_column_new_with_attributes(name, renderer,
/* TODO */
NULL);
gtk_tree_view_append_column(table, col);
}

64
redo/table_unix.go Normal file
View File

@ -0,0 +1,64 @@
// 29 july 2014
package ui
import (
// "fmt"
"reflect"
"unsafe"
)
// #include "gtk_unix.h"
import "C"
type table struct {
*widgetbase
*tablebase
treewidget *C.GtkWidget
treeview *C.GtkTreeView
scrollc *C.GtkContainer
scrollwindow *C.GtkScrolledWindow
}
func finishNewTable(b *tablebase, ty reflect.Type) Table {
widget := C.gtk_tree_view_new()
scroller := C.gtk_scrolled_window_new(nil, nil)
t := &table{
// TODO kludge
widgetbase: newWidget(scroller),
tablebase: b,
treewidget: widget,
treeview: (*C.GtkTreeView)(unsafe.Pointer(widget)),
scrollc: (*C.GtkContainer)(unsafe.Pointer(scroller)),
scrollwindow: (*C.GtkScrolledWindow)(unsafe.Pointer(scroller)),
}
// give the scrolled window a border (thanks to jlindgren in irc.gimp.net/#gtk+)
C.gtk_scrolled_window_set_shadow_type(t.scrollwindow, C.GTK_SHADOW_IN)
C.gtk_container_add(t.scrollc, t.treewidget)
// TODO model
for i := 0; i < ty.NumField(); i++ {
cname := togstr(ty.Field(i).Name)
C.tableAppendColumn(t.treeview, cname)
freegstr(cname) // free now (not deferred) to conserve memory
}
return t
}
func (t *table) preferredSize(d *sizing) (width int, height int) {
var r C.GtkRequisition
C.gtk_widget_get_preferred_size(t.treewidget, nil, &r)
return int(r.width), int(r.height)
}
func (t *table) Unlock() {
t.unlock()
// TODO RACE CONDITION HERE
// not sure about this one...
t.RLock()
defer t.RUnlock()
// TODO
}