Ejemplo n.º 1
0
//export goTableModel_do_get_value
func goTableModel_do_get_value(data unsafe.Pointer, row C.gint, col C.gint, value *C.GValue) {
	t := (*table)(data)
	t.RLock()
	defer t.RUnlock()
	d := reflect.Indirect(reflect.ValueOf(t.data))
	datum := d.Index(int(row)).Field(int(col))
	switch {
	case datum.Type() == reflect.TypeOf((*image.RGBA)(nil)):
		d := datum.Interface().(*image.RGBA)
		pixbuf := toIconSizedGdkPixbuf(d)
		C.g_value_init(value, C.gdk_pixbuf_get_type())
		object := C.gpointer(unsafe.Pointer(pixbuf))
		// use g_value_take_object() so the GtkTreeView becomes the pixbuf's owner
		C.g_value_take_object(value, object)
	case datum.Kind() == reflect.Bool:
		d := datum.Interface().(bool)
		C.g_value_init(value, C.G_TYPE_BOOLEAN)
		C.g_value_set_boolean(value, togbool(d))
	default:
		s := fmt.Sprintf("%v", datum)
		str := togstr(s)
		defer freegstr(str)
		C.g_value_init(value, C.G_TYPE_STRING)
		C.g_value_set_string(value, str)
	}
}
Ejemplo n.º 2
0
Archivo: gst.go Proyecto: reusee/oplay
func toGValue(v interface{}) *C.GValue {
	value := C.gvalue_new()
	switch reflect.TypeOf(v).Kind() {
	case reflect.String:
		C.g_value_init(value, C.G_TYPE_STRING)
		cStr := C.CString(v.(string))
		defer C.free(unsafe.Pointer(cStr))
		C.g_value_set_string(value, (*C.gchar)(unsafe.Pointer(cStr)))
	case reflect.Int:
		C.g_value_init(value, C.G_TYPE_INT)
		C.g_value_set_int(value, C.gint(v.(int)))
	case reflect.Struct:
		switch rv := v.(type) {
		case Fraction:
			C.g_value_init(value, C.gst_fraction_get_type())
			C.gst_value_set_fraction(value, C.gint(rv.N), C.gint(rv.D))
		default:
			p("unknown struct type %v\n", v)
			panic("fixme") //TODO
		}
	case reflect.Ptr:
		switch reflect.TypeOf(v) {
		case gstCapsType:
			C.g_value_init(value, C.gst_caps_get_type())
			C.gst_value_set_caps(value, v.(*C.GstCaps))
		default:
			panic(fmt.Sprintf("unknown type %v", v)) //TODO
		}
	default:
		panic(fmt.Sprintf("unknown type %v", v)) //TODO
	}
	return value
}
Ejemplo n.º 3
0
//export goTableModel_do_get_value
func goTableModel_do_get_value(data unsafe.Pointer, row C.gint, col C.gint, value *C.GValue) {
	t := (*table)(data)
	t.RLock()
	defer t.RUnlock()
	d := reflect.Indirect(reflect.ValueOf(t.data))
	datum := d.Index(int(row)).Field(int(col))
	switch {
	case datum.Type() == reflect.TypeOf(ImageIndex(0)):
		d := datum.Interface().(ImageIndex)
		C.g_value_init(value, C.gdk_pixbuf_get_type())
		C.g_value_set_object(value, C.gpointer(unsafe.Pointer(t.pixbufs[d])))
	case datum.Kind() == reflect.Bool:
		d := datum.Interface().(bool)
		C.g_value_init(value, C.G_TYPE_BOOLEAN)
		C.g_value_set_boolean(value, togbool(d))
	default:
		s := fmt.Sprintf("%v", datum)
		str := togstr(s)
		defer freegstr(str)
		C.g_value_init(value, C.G_TYPE_STRING)
		C.g_value_set_string(value, str)
	}
}
Ejemplo n.º 4
0
func toGValue(v interface{}) *C.GValue {
	value := C.gvalue_new()
	switch reflect.TypeOf(v).Kind() {
	case reflect.String:
		C.g_value_init(value, C.G_TYPE_STRING)
		cStr := C.CString(v.(string))
		defer C.free(unsafe.Pointer(cStr))
		C.g_value_set_string(value, (*C.gchar)(unsafe.Pointer(cStr)))
	case reflect.Int:
		C.g_value_init(value, C.G_TYPE_INT)
		C.g_value_set_int(value, C.gint(v.(int)))
	case reflect.Ptr, reflect.UnsafePointer:
		p := unsafe.Pointer(reflect.ValueOf(v).Pointer())
		if IsObject(p) {
			C.g_value_init(value, C.G_TYPE_OBJECT)
			C.g_value_set_object(value, C.gpointer(p))
		} else {
			panic(fmt.Sprintf("unknown pointer type %v", v))
		}
	default:
		panic(fmt.Sprintf("unknown type %v", v)) //TODO
	}
	return value
}
Ejemplo n.º 5
0
Archivo: glib.go Proyecto: vvanpo/gotk3
// SetString is a wrapper around g_value_set_string().
func (v *Value) SetString(val string) {
	cstr := C.CString(val)
	defer C.free(unsafe.Pointer(cstr))
	C.g_value_set_string(v.native(), (*C.gchar)(cstr))
}