示例#1
0
文件: helper.go 项目: reusee/g-helper
func fromGValue(v *C.GValue) (ret interface{}) {
	valueType := C.gvalue_get_type(v)
	fundamentalType := C.gtype_get_fundamental(valueType)
	switch fundamentalType {
	case C.G_TYPE_OBJECT:
		ret = unsafe.Pointer(C.g_value_get_object(v))
	case C.G_TYPE_STRING:
		ret = fromGStr(C.g_value_get_string(v))
	case C.G_TYPE_UINT:
		ret = int(C.g_value_get_uint(v))
	case C.G_TYPE_BOXED:
		ret = unsafe.Pointer(C.g_value_get_boxed(v))
	case C.G_TYPE_BOOLEAN:
		ret = C.g_value_get_boolean(v) == C.gboolean(1)
	case C.G_TYPE_ENUM:
		ret = int(C.g_value_get_enum(v))
	default:
		panic(fmt.Sprintf("from type %s %T", fromGStr(C.g_type_name(fundamentalType)), v))
	}
	return
}
示例#2
0
文件: pango.go 项目: envoker/gotk3
func marshalWrapMode(p uintptr) (interface{}, error) {
	c := C.g_value_get_enum((*C.GValue)(unsafe.Pointer(p)))
	return WrapMode(c), nil
}
示例#3
0
func marshalStateChangeReturn(p uintptr) (interface{}, error) {
	c := C.g_value_get_enum((*C.GValue)(unsafe.Pointer(p)))
	return StateChangeReturn(c), nil
}
示例#4
0
func marshalSeekFlags(p uintptr) (interface{}, error) {
	c := C.g_value_get_enum((*C.GValue)(unsafe.Pointer(p)))
	return SeekFlags(c), nil
}
示例#5
0
func marshalPadLinkReturn(p uintptr) (interface{}, error) {
	c := C.g_value_get_enum((*C.GValue)(unsafe.Pointer(p)))
	return PadLinkReturn(c), nil
}
示例#6
0
func marshalMessageType(p uintptr) (interface{}, error) {
	c := C.g_value_get_enum((*C.GValue)(unsafe.Pointer(p)))
	return MessageType(c), nil
}
示例#7
0
文件: cairo.go 项目: raichu/gotk3
func marshalOperator(p uintptr) (interface{}, error) {
	c := C.g_value_get_enum((*C.GValue)(unsafe.Pointer(p)))
	return Operator(c), nil
}
示例#8
0
文件: gtk_3_10.go 项目: vvanpo/gotk3
func marshalStackTransitionType(p uintptr) (interface{}, error) {
	c := C.g_value_get_enum((*C.GValue)(unsafe.Pointer(p)))
	return StackTransitionType(c), nil
}
示例#9
0
func marshalAlignment(p uintptr) (interface{}, error) {
	c := C.g_value_get_enum((*C.GValue)(unsafe.Pointer(p)))
	return Alignment(c), nil
}
示例#10
0
func marshalTLSErrorsPolicy(p uintptr) (interface{}, error) {
	c := C.g_value_get_enum((*C.GValue)(unsafe.Pointer(p)))
	return TLSErrorsPolicy(c), nil
}
示例#11
0
func marshalProcessModel(p uintptr) (interface{}, error) {
	c := C.g_value_get_enum((*C.GValue)(unsafe.Pointer(p)))
	return ProcessModel(c), nil
}
示例#12
0
文件: glib.go 项目: pmcoder/gotk3
// GoValue() converts a Value to comparable Go type.  GoValue()
// returns a non-nil error if the conversion was unsuccessful.  The
// returned interface{} must be type asserted as the actual Go
// representation of the Value.
//
// This function is a wrapper around the many g_value_get_*()
// functions, depending on the type of the Value.
func (v *Value) GoValue() (interface{}, error) {
	_, fundamental, err := v.Type()
	if err != nil {
		return nil, err
	}

	// TODO: verify that all of these cases are indeed fundamental types
	switch fundamental {
	case TYPE_INVALID:
		return nil, errors.New("invalid type")

	case TYPE_NONE:
		return nil, nil

	case TYPE_INTERFACE:
		return nil, errors.New("interface conversion not yet implemented")

	case TYPE_CHAR:
		c := C.g_value_get_schar(v.Native())
		return int8(c), nil

	case TYPE_UCHAR:
		c := C.g_value_get_uchar(v.Native())
		return uint8(c), nil

	case TYPE_BOOLEAN:
		c := C.g_value_get_boolean(v.Native())
		return gobool(c), nil

	// TODO: TYPE_INT should probably be a Go int32.
	case TYPE_INT, TYPE_LONG:
		c := C.g_value_get_int(v.Native())
		return int(c), nil

	case TYPE_ENUM:
		c := C.g_value_get_enum(v.Native())
		return int(c), nil

	case TYPE_INT64:
		c := C.g_value_get_int64(v.Native())
		return int64(c), nil

	// TODO: TYPE_UINT should probably be a Go uint32.
	case TYPE_UINT, TYPE_ULONG, TYPE_FLAGS:
		c := C.g_value_get_uint(v.Native())
		return uint(c), nil

	case TYPE_UINT64:
		c := C.g_value_get_uint64(v.Native())
		return uint64(c), nil

	case TYPE_FLOAT:
		c := C.g_value_get_float(v.Native())
		return float32(c), nil

	case TYPE_DOUBLE:
		c := C.g_value_get_double(v.Native())
		return float64(c), nil

	case TYPE_STRING:
		c := C.g_value_get_string(v.Native())
		return C.GoString((*C.char)(c)), nil

	case TYPE_POINTER:
		c := C.g_value_get_pointer(v.Native())
		return unsafe.Pointer(c), nil

	case TYPE_OBJECT:
		c := C.g_value_get_object(v.Native())
		// TODO: need to try and return an actual pointer to the correct object type
		// this may require an additional cast()-like method for each module
		return ObjectNew(unsafe.Pointer(c)), nil

	case TYPE_VARIANT:
		return nil, errors.New("variant conversion not yet implemented")

	default:
		return nil, errors.New("type conversion not supported")
	}
}
示例#13
0
文件: gdk.go 项目: raichu/gotk3
func marshalDragAction(p uintptr) (interface{}, error) {
	c := C.g_value_get_enum((*C.GValue)(unsafe.Pointer(p)))
	return DragAction(c), nil
}
示例#14
0
文件: gdk.go 项目: raichu/gotk3
func marshalEventMask(p uintptr) (interface{}, error) {
	c := C.g_value_get_enum((*C.GValue)(unsafe.Pointer(p)))
	return EventMask(c), nil
}