コード例 #1
0
ファイル: table_unix.go プロジェクト: sjn1978/ui
//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)
	}
}
コード例 #2
0
ファイル: value.go プロジェクト: ziutek/glib
// Set value to i
func (v *Value) Set(i interface{}) {
	if vg, ok := i.(ValueGetter); ok {
		vg.Value().Copy(v)
		return
	}
	// Other types
	r := reflect.ValueOf(i)
	switch r.Kind() {
	case reflect.Invalid:
		C.g_value_reset(v.g())

	case reflect.Bool:
		C.g_value_set_boolean(v.g(), gBoolean(r.Bool()))

	case reflect.Int:
		C.g_value_set_long(v.g(), C.glong(i.(int)))

	case reflect.Int8:
		C.g_value_set_schar(v.g(), C.gint8(i.(int8)))

	case reflect.Int32:
		C.g_value_set_int(v.g(), C.gint(i.(int32)))

	case reflect.Int64:
		C.g_value_set_int64(v.g(), C.gint64(i.(int64)))

	case reflect.Uint:
		C.g_value_set_ulong(v.g(), C.gulong(i.(uint)))

	case reflect.Uint8:
		C.g_value_set_uchar(v.g(), C.guchar(i.(uint8)))

	case reflect.Uint32:
		C.g_value_set_uint(v.g(), C.guint(i.(uint32)))

	case reflect.Uint64:
		C.g_value_set_uint64(v.g(), C.guint64(i.(uint64)))

	case reflect.Float32:
		C.g_value_set_float(v.g(), C.gfloat(i.(float32)))

	case reflect.Float64:
		C.g_value_set_double(v.g(), C.gdouble(i.(float64)))

	case reflect.Ptr:
		C.g_value_set_pointer(v.g(), C.gpointer(r.Pointer()))

	case reflect.String:
		C.g_value_set_static_string(v.g(), (*C.gchar)(C.CString(r.String())))

	default:
		panic("Can't represent Go value in Glib type system.")
	}
}
コード例 #3
0
ファイル: gtype.go プロジェクト: napsy/go-gtk3
func CreateCGValue(tn GType, object ...unsafe.Pointer) *GValue {
	var cv C.GValue
	C.g_value_init(&cv, C.GType(tn))

	// If no data, then return Gvalue initialized with default
	if len(object) == 0 {
		gv := GValue{tn, &cv}
		return &gv
	}
	obj := object[0]

	// Foundamental types are special
	// TODO: Handle more cases, like creating GValue from GdkEvents
	switch tn {
	case G_TYPE_STRING:
		C.g_value_take_string(&cv, (*C.gchar)(obj))
	case G_TYPE_BOOLEAN:
		C.g_value_set_boolean(&cv, *((*C.gboolean)(obj)))
	case G_TYPE_CHAR:
		C.g_value_set_char(&cv, *((*C.gchar)(obj)))
	case G_TYPE_INT:
		C.g_value_set_int(&cv, *((*C.gint)(obj)))
	case G_TYPE_LONG:
		C.g_value_set_long(&cv, *((*C.glong)(obj)))
	case G_TYPE_INT64:
		C.g_value_set_int64(&cv, *((*C.gint64)(obj)))
	case G_TYPE_UCHAR:
		C.g_value_set_uchar(&cv, *((*C.guchar)(obj)))
	case G_TYPE_UINT:
		C.g_value_set_uint(&cv, *((*C.guint)(obj)))
	case G_TYPE_ULONG:
		C.g_value_set_ulong(&cv, *((*C.gulong)(obj)))
	case G_TYPE_UINT64:
		C.g_value_set_uint64(&cv, *((*C.guint64)(obj)))
	case G_TYPE_FLOAT:
		C.g_value_set_float(&cv, *((*C.gfloat)(obj)))
	case G_TYPE_DOUBLE:
		C.g_value_set_double(&cv, *((*C.gdouble)(obj)))
	default:
		C.g_value_set_object(&cv, C.gpointer(obj))
	}

	gv := GValue{tn, &cv}
	return &gv
}
コード例 #4
0
ファイル: table_unix.go プロジェクト: NotBadPad/ui
//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)
	}
}
コード例 #5
0
ファイル: glib.go プロジェクト: vvanpo/gotk3
// SetBool is a wrapper around g_value_set_boolean().
func (v *Value) SetBool(val bool) {
	C.g_value_set_boolean(v.native(), gbool(val))
}
コード例 #6
0
ファイル: gobj.go プロジェクト: hwch/go-gtk
// g_value_set_boolean
func (this *Value) SetBool(v bool) {
	C.g_value_set_boolean(this.asC(), C.gboolean(_GoBoolToCBool(v)))
}