作者:hwc
项目:go-gt
func (this Type) String() string {
cname := C.g_type_name(C.GType(this))
if cname == nil {
return ""
}
return C.GoString((*C.char)(cname))
}
作者:vvanp
项目:gotk
// Emit is a wrapper around g_signal_emitv() and emits the signal
// specified by the string s to an Object. Arguments to callback
// functions connected to this signal must be specified in args. Emit()
// returns an interface{} which must be type asserted as the Go
// equivalent type to the return value for native C callback.
//
// Note that this code is unsafe in that the types of values in args are
// not checked against whether they are suitable for the callback.
func (v *Object) Emit(s string, args ...interface{}) (interface{}, error) {
cstr := C.CString(s)
defer C.free(unsafe.Pointer(cstr))
// Create array of this instance and arguments
valv := C.alloc_gvalue_list(C.int(len(args)) + 1)
defer C.free(unsafe.Pointer(valv))
// Add args and valv
val, err := GValue(v)
if err != nil {
return nil, errors.New("Error converting Object to GValue: " + err.Error())
}
C.val_list_insert(valv, C.int(0), val.native())
for i := range args {
val, err := GValue(args[i])
if err != nil {
return nil, fmt.Errorf("Error converting arg %d to GValue: %s", i, err.Error())
}
C.val_list_insert(valv, C.int(i+1), val.native())
}
t := v.TypeFromInstance()
// TODO: use just the signal name
id := C.g_signal_lookup((*C.gchar)(cstr), C.GType(t))
ret, err := ValueAlloc()
if err != nil {
return nil, errors.New("Error creating Value for return value")
}
C.g_signal_emitv(valv, id, C.GQuark(0), ret.native())
return ret.GoValue()
}
作者:vvanp
项目:gotk
// ValueInit is a wrapper around g_value_init() and allocates and
// initializes a new Value with the Type t. A runtime finalizer is set
// to call g_value_unset() on the underlying GValue after leaving scope.
// ValueInit() returns a non-nil error if the allocation failed.
func ValueInit(t Type) (*Value, error) {
c := C._g_value_init(C.GType(t))
if c == nil {
return nil, errNilPtr
}
v := &Value{*c}
runtime.SetFinalizer(v, (*Value).unset)
return v, nil
}
作者:naps
项目:go-gtk
func New(typ GType, properties map[string]interface{}) ObjectLike {
obj := gobject{}
obj.object = C.new_GObject(C.GType(typ))
Set(obj, properties)
return obj
}
作者:naps
项目:go-gtk
func (self *Widget) GetAncestor(widget_type gobject.GType) WidgetLike {
w := C.gtk_widget_get_ancestor(self.object, C.GType(widget_type))
if w == nil {
return nil
}
if par, err := gobject.ConvertToGo(unsafe.Pointer(&w)); err == nil {
return par.(WidgetLike)
}
return nil
}
作者:naps
项目:go-gtk
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
}
作者:vvanp
项目:gotk
// IsA is a wrapper around g_type_is_a().
func (v *Object) IsA(typ Type) bool {
return gobool(C.g_type_is_a(C.GType(v.TypeFromInstance()), C.GType(typ)))
}
作者:vvanp
项目:gotk
// Parent is a wrapper around g_type_parent().
func (t Type) Parent() Type {
return Type(C.g_type_parent(C.GType(t)))
}
作者:vvanp
项目:gotk
// Depth is a wrapper around g_type_depth().
func (t Type) Depth() uint {
return uint(C.g_type_depth(C.GType(t)))
}
作者:vvanp
项目:gotk
// Name is a wrapper around g_type_name().
func (t Type) Name() string {
return C.GoString((*C.char)(C.g_type_name(C.GType(t))))
}
作者:seokheonba
项目:gli
func (t Type) g() C.GType {
return C.GType(t)
}
作者:jamesbjackso
项目:gs
func (o *GstObj) ImplementsInterfaceCast(typ glib.Type) glib.Pointer {
return glib.Pointer(C.gst_implements_interface_cast(C.gpointer(o.GetPtr()),
C.GType(typ)))
}
作者:jamesbjackso
项目:gs
func (o *GstObj) ImplementsInterfaceCheck(typ glib.Type) bool {
return C.gst_implements_interface_check(C.gpointer(o.GetPtr()),
C.GType(typ)) != 0
}
作者:naps
项目:go-gtk
func SignalLookup(name string, objectType GType) uint32 {
n := GString(name)
defer n.Free()
s := C.g_signal_lookup((*C.gchar)(n.GetPtr()), C.GType(objectType))
return uint32(s)
}
作者:hwc
项目:go-gt
func (this Type) asC() C.GType {
return C.GType(this)
}
作者:hwc
项目:go-gt
func (this Type) IsA(other Type) bool {
return C.g_type_is_a(C.GType(this), C.GType(other)) != 0
}