Golang gpointer示例

说明

golang gpointer示例是从最受好评的开源项目中提取的实现代码,你可以参考下面示例的使用方式。

编程语言: Golang

命名空间/包名称: C

示例#1
文件: window_unix.go 项目: NotBadPad/ui

func newWindow(title string, width int, height int, control Control) *window {
	widget := C.gtk_window_new(C.GTK_WINDOW_TOPLEVEL)
	ctitle := togstr(title)
	defer freegstr(ctitle)
	w := &window{
		widget:  widget,
		wc:      (*C.GtkContainer)(unsafe.Pointer(widget)),
		bin:     (*C.GtkBin)(unsafe.Pointer(widget)),
		window:  (*C.GtkWindow)(unsafe.Pointer(widget)),
		closing: newEvent(),
	}
	C.gtk_window_set_title(w.window, ctitle)
	g_signal_connect(
		C.gpointer(unsafe.Pointer(w.window)),
		"delete-event",
		C.GCallback(C.windowClosing),
		C.gpointer(unsafe.Pointer(w)))
	C.gtk_window_resize(w.window, C.gint(width), C.gint(height))
	w.container = newContainer(control)
	w.container.setParent(&controlParent{w.wc})
	// for dialogs; otherwise, they will be modal to all windows, not just this one
	w.group = C.gtk_window_group_new()
	C.gtk_window_group_add_window(w.group, w.window)
	return w
}

示例#2
文件: keyfile.go 项目: sqp/godock

// HasKey is a wrapper around g_key_file_has_key().
func (kf *KeyFile) HasKey(group string, key string) bool {
	cGroup := (*C.gchar)(C.CString(group))
	defer C.g_free(C.gpointer(cGroup))
	cKey := (*C.gchar)(C.CString(key))
	defer C.g_free(C.gpointer(cKey))
	return goBool(C.g_key_file_has_key(kf.cKey, cGroup, cKey, nil))
}

示例#3
文件: internet_address.go 项目: partkyle/go-gmime

func NewMailboxAddress(name string, email string) *MailboxAddress {
	var cName *C.char = C.CString(name)
	var cEmail *C.char = C.CString(email)
	defer C.free(unsafe.Pointer(cName))
	defer C.free(unsafe.Pointer(cEmail))
	ai := C.internet_address_mailbox_new(cName, cEmail)
	defer unref(C.gpointer(ai))
	return CastMailboxAddress((*C.InternetAddressMailbox)(C.gpointer(ai)))
}

示例#4
文件: gobject_class_types.go 项目: reusee/ggir

func NewParamSpecFromCPointer(p unsafe.Pointer) *ParamSpec {
	ret := &ParamSpec{
		NewTraitParamSpec(p),
		p,
	}
	C.g_object_ref_sink(C.gpointer(p))
	runtime.SetFinalizer(ret, func(p *ParamSpec) {
		C.g_object_unref(C.gpointer(unsafe.Pointer(p.CPointer)))
	})
	return ret
}

示例#5
文件: gobject_class_types.go 项目: reusee/ggir

func NewObjectFromCPointer(p unsafe.Pointer) *Object {
	ret := &Object{
		NewTraitObject(p),
		p,
	}
	C.g_object_ref_sink(C.gpointer(p))
	runtime.SetFinalizer(ret, func(p *Object) {
		C.g_object_unref(C.gpointer(unsafe.Pointer(p.CPointer)))
	})
	return ret
}

示例#6
文件: gdk_class_types.go 项目: reusee/ggir

func NewAppLaunchContextFromCPointer(p unsafe.Pointer) *AppLaunchContext {
	ret := &AppLaunchContext{
		NewTraitAppLaunchContext(p),
		p,
	}
	C.g_object_ref_sink(C.gpointer(p))
	runtime.SetFinalizer(ret, func(p *AppLaunchContext) {
		C.g_object_unref(C.gpointer(unsafe.Pointer(p.CPointer)))
	})
	return ret
}

示例#7
文件: glib.go 项目: leif/go-gtk

func (v *GObject) Set(name string, value interface{}) {
	ptr := C.CString(name)
	defer C.free_string(ptr)

	if _, ok := value.(WrappedObject); ok {
		value = value.(WrappedObject).GetInternalValue()
	}
	if _, ok := value.(GObject); ok {
		value = value.(GObject).Object
	}
	if _, ok := value.(GValue); ok {
		value = value.(GValue).Value
	}

	switch value.(type) {
	case bool:
		bval := bool2gboolean(value.(bool))
		C._g_object_set_addr(C.gpointer(v.Object), C.to_gcharptr(ptr), unsafe.Pointer(&bval))
	case byte:
		bval := C.gchar(value.(byte))
		C._g_object_set_addr(C.gpointer(v.Object), C.to_gcharptr(ptr), unsafe.Pointer(&bval))
		//C._g_object_set(C.gpointer(v.Object), C.to_gcharptr(ptr), unsafe.Pointer(reflect.ValueOf(C.gchar(value.(byte))).UnsafeAddr()))
	case int:
		ival := C.int(value.(int))
		C._g_object_set_addr(C.gpointer(v.Object), C.to_gcharptr(ptr), unsafe.Pointer(&ival))
	case uint:
		uval := C.guint(value.(uint))
		C._g_object_set_addr(C.gpointer(v.Object), C.to_gcharptr(ptr), unsafe.Pointer(&uval))
		//C._g_object_set(C.gpointer(v.Object), C.to_gcharptr(ptr), unsafe.Pointer(reflect.ValueOf(C.guint(value.(uint))).UnsafeAddr()))
	case float32:
		f32val := C.gfloat(value.(float32))
		C._g_object_set_addr(C.gpointer(v.Object), C.to_gcharptr(ptr), unsafe.Pointer(&f32val))
		//C._g_object_set(C.gpointer(v.Object), C.to_gcharptr(ptr), unsafe.Pointer(reflect.ValueOf(C.gfloat(value.(float64))).UnsafeAddr()))
	case float64:
		f64val := C.gfloat(value.(float64))
		C._g_object_set_addr(C.gpointer(v.Object), C.to_gcharptr(ptr), unsafe.Pointer(&f64val))
		//C._g_object_set(C.gpointer(v.Object), C.to_gcharptr(ptr), unsafe.Pointer(reflect.ValueOf(C.gfloat(value.(float64))).UnsafeAddr()))
	case string:
		pval := C.CString(value.(string))
		defer C.free_string(pval)
		C._g_object_set_addr(C.gpointer(v.Object), C.to_gcharptr(ptr), unsafe.Pointer(&pval))
	default:
		if pv, ok := value.(*[0]uint8); ok {
			C._g_object_set_ptr(C.gpointer(v.Object), C.to_gcharptr(ptr), unsafe.Pointer(pv))
		} else {
			av := reflect.ValueOf(value)
			if av.CanAddr() {
				C._g_object_set_addr(C.gpointer(v.Object), C.to_gcharptr(ptr), unsafe.Pointer(reflect.ValueOf(value).UnsafeAddr()))
			} else {
				C._g_object_set_ptr(C.gpointer(v.Object), C.to_gcharptr(ptr), value.(unsafe.Pointer))
			}
		}
	}
}

示例#8
文件: gio_class_types.go 项目: reusee/ggir

func NewAppInfoMonitorFromCPointer(p unsafe.Pointer) *AppInfoMonitor {
	ret := &AppInfoMonitor{
		NewTraitAppInfoMonitor(p),
		gobject.NewTraitObject(p),
		p,
	}
	C.g_object_ref_sink(C.gpointer(p))
	runtime.SetFinalizer(ret, func(p *AppInfoMonitor) {
		C.g_object_unref(C.gpointer(unsafe.Pointer(p.CPointer)))
	})
	return ret
}

示例#9
文件: gio_class_types.go 项目: reusee/ggir

func NewDBusMethodInvocationFromCPointer(p unsafe.Pointer) *DBusMethodInvocation {
	ret := &DBusMethodInvocation{
		NewTraitDBusMethodInvocation(p),
		gobject.NewTraitObject(p),
		p,
	}
	C.g_object_ref_sink(C.gpointer(p))
	runtime.SetFinalizer(ret, func(p *DBusMethodInvocation) {
		C.g_object_unref(C.gpointer(unsafe.Pointer(p.CPointer)))
	})
	return ret
}

示例#10
文件: gio_class_types.go 项目: reusee/ggir

func NewSimpleProxyResolverFromCPointer(p unsafe.Pointer) *SimpleProxyResolver {
	ret := &SimpleProxyResolver{
		NewTraitSimpleProxyResolver(p),
		gobject.NewTraitObject(p),
		p,
	}
	C.g_object_ref_sink(C.gpointer(p))
	runtime.SetFinalizer(ret, func(p *SimpleProxyResolver) {
		C.g_object_unref(C.gpointer(unsafe.Pointer(p.CPointer)))
	})
	return ret
}

示例#11
文件: gio_class_types.go 项目: reusee/ggir

func NewCredentialsFromCPointer(p unsafe.Pointer) *Credentials {
	ret := &Credentials{
		NewTraitCredentials(p),
		gobject.NewTraitObject(p),
		p,
	}
	C.g_object_ref_sink(C.gpointer(p))
	runtime.SetFinalizer(ret, func(p *Credentials) {
		C.g_object_unref(C.gpointer(unsafe.Pointer(p.CPointer)))
	})
	return ret
}

示例#12
文件: gio_class_types.go 项目: reusee/ggir

func NewInetAddressMaskFromCPointer(p unsafe.Pointer) *InetAddressMask {
	ret := &InetAddressMask{
		NewTraitInetAddressMask(p),
		gobject.NewTraitObject(p),
		p,
	}
	C.g_object_ref_sink(C.gpointer(p))
	runtime.SetFinalizer(ret, func(p *InetAddressMask) {
		C.g_object_unref(C.gpointer(unsafe.Pointer(p.CPointer)))
	})
	return ret
}

示例#13
文件: gio_class_types.go 项目: reusee/ggir

func NewApplicationCommandLineFromCPointer(p unsafe.Pointer) *ApplicationCommandLine {
	ret := &ApplicationCommandLine{
		NewTraitApplicationCommandLine(p),
		gobject.NewTraitObject(p),
		p,
	}
	C.g_object_ref_sink(C.gpointer(p))
	runtime.SetFinalizer(ret, func(p *ApplicationCommandLine) {
		C.g_object_unref(C.gpointer(unsafe.Pointer(p.CPointer)))
	})
	return ret
}

示例#14
文件: gio_class_types.go 项目: reusee/ggir

func NewTlsPasswordFromCPointer(p unsafe.Pointer) *TlsPassword {
	ret := &TlsPassword{
		NewTraitTlsPassword(p),
		gobject.NewTraitObject(p),
		p,
	}
	C.g_object_ref_sink(C.gpointer(p))
	runtime.SetFinalizer(ret, func(p *TlsPassword) {
		C.g_object_unref(C.gpointer(unsafe.Pointer(p.CPointer)))
	})
	return ret
}

示例#15
文件: gio_class_types.go 项目: reusee/ggir

func NewEmblemedIconFromCPointer(p unsafe.Pointer) *EmblemedIcon {
	ret := &EmblemedIcon{
		NewTraitEmblemedIcon(p),
		gobject.NewTraitObject(p),
		p,
	}
	C.g_object_ref_sink(C.gpointer(p))
	runtime.SetFinalizer(ret, func(p *EmblemedIcon) {
		C.g_object_unref(C.gpointer(unsafe.Pointer(p.CPointer)))
	})
	return ret
}

示例#16
文件: gio_class_types.go 项目: reusee/ggir

func NewTlsCertificateFromCPointer(p unsafe.Pointer) *TlsCertificate {
	ret := &TlsCertificate{
		NewTraitTlsCertificate(p),
		gobject.NewTraitObject(p),
		p,
	}
	C.g_object_ref_sink(C.gpointer(p))
	runtime.SetFinalizer(ret, func(p *TlsCertificate) {
		C.g_object_unref(C.gpointer(unsafe.Pointer(p.CPointer)))
	})
	return ret
}

示例#17
文件: gio_class_types.go 项目: reusee/ggir

func NewCancellableFromCPointer(p unsafe.Pointer) *Cancellable {
	ret := &Cancellable{
		NewTraitCancellable(p),
		gobject.NewTraitObject(p),
		p,
	}
	C.g_object_ref_sink(C.gpointer(p))
	runtime.SetFinalizer(ret, func(p *Cancellable) {
		C.g_object_unref(C.gpointer(unsafe.Pointer(p.CPointer)))
	})
	return ret
}

示例#18
文件: gio_class_types.go 项目: reusee/ggir

func NewSubprocessLauncherFromCPointer(p unsafe.Pointer) *SubprocessLauncher {
	ret := &SubprocessLauncher{
		NewTraitSubprocessLauncher(p),
		gobject.NewTraitObject(p),
		p,
	}
	C.g_object_ref_sink(C.gpointer(p))
	runtime.SetFinalizer(ret, func(p *SubprocessLauncher) {
		C.g_object_unref(C.gpointer(unsafe.Pointer(p.CPointer)))
	})
	return ret
}

示例#19
文件: gio_class_types.go 项目: reusee/ggir

func NewSocketControlMessageFromCPointer(p unsafe.Pointer) *SocketControlMessage {
	ret := &SocketControlMessage{
		NewTraitSocketControlMessage(p),
		gobject.NewTraitObject(p),
		p,
	}
	C.g_object_ref_sink(C.gpointer(p))
	runtime.SetFinalizer(ret, func(p *SocketControlMessage) {
		C.g_object_unref(C.gpointer(unsafe.Pointer(p.CPointer)))
	})
	return ret
}

示例#20
文件: gio_class_types.go 项目: reusee/ggir

func NewSocketAddressEnumeratorFromCPointer(p unsafe.Pointer) *SocketAddressEnumerator {
	ret := &SocketAddressEnumerator{
		NewTraitSocketAddressEnumerator(p),
		gobject.NewTraitObject(p),
		p,
	}
	C.g_object_ref_sink(C.gpointer(p))
	runtime.SetFinalizer(ret, func(p *SocketAddressEnumerator) {
		C.g_object_unref(C.gpointer(unsafe.Pointer(p.CPointer)))
	})
	return ret
}

示例#21
文件: gio_class_types.go 项目: reusee/ggir

func NewDBusServerFromCPointer(p unsafe.Pointer) *DBusServer {
	ret := &DBusServer{
		NewTraitDBusServer(p),
		gobject.NewTraitObject(p),
		p,
	}
	C.g_object_ref_sink(C.gpointer(p))
	runtime.SetFinalizer(ret, func(p *DBusServer) {
		C.g_object_unref(C.gpointer(unsafe.Pointer(p.CPointer)))
	})
	return ret
}

示例#22
文件: gio_class_types.go 项目: reusee/ggir

func NewPropertyActionFromCPointer(p unsafe.Pointer) *PropertyAction {
	ret := &PropertyAction{
		NewTraitPropertyAction(p),
		gobject.NewTraitObject(p),
		p,
	}
	C.g_object_ref_sink(C.gpointer(p))
	runtime.SetFinalizer(ret, func(p *PropertyAction) {
		C.g_object_unref(C.gpointer(unsafe.Pointer(p.CPointer)))
	})
	return ret
}

示例#23
文件: gio_class_types.go 项目: reusee/ggir

func NewDesktopAppInfoFromCPointer(p unsafe.Pointer) *DesktopAppInfo {
	ret := &DesktopAppInfo{
		NewTraitDesktopAppInfo(p),
		gobject.NewTraitObject(p),
		p,
	}
	C.g_object_ref_sink(C.gpointer(p))
	runtime.SetFinalizer(ret, func(p *DesktopAppInfo) {
		C.g_object_unref(C.gpointer(unsafe.Pointer(p.CPointer)))
	})
	return ret
}

示例#24
文件: gio_class_types.go 项目: reusee/ggir

func NewCharsetConverterFromCPointer(p unsafe.Pointer) *CharsetConverter {
	ret := &CharsetConverter{
		NewTraitCharsetConverter(p),
		gobject.NewTraitObject(p),
		p,
	}
	C.g_object_ref_sink(C.gpointer(p))
	runtime.SetFinalizer(ret, func(p *CharsetConverter) {
		C.g_object_unref(C.gpointer(unsafe.Pointer(p.CPointer)))
	})
	return ret
}

示例#25
文件: gio_class_types.go 项目: reusee/ggir

func NewFilenameCompleterFromCPointer(p unsafe.Pointer) *FilenameCompleter {
	ret := &FilenameCompleter{
		NewTraitFilenameCompleter(p),
		gobject.NewTraitObject(p),
		p,
	}
	C.g_object_ref_sink(C.gpointer(p))
	runtime.SetFinalizer(ret, func(p *FilenameCompleter) {
		C.g_object_unref(C.gpointer(unsafe.Pointer(p.CPointer)))
	})
	return ret
}

示例#26
文件: gio_class_types.go 项目: reusee/ggir

func NewVfsFromCPointer(p unsafe.Pointer) *Vfs {
	ret := &Vfs{
		NewTraitVfs(p),
		gobject.NewTraitObject(p),
		p,
	}
	C.g_object_ref_sink(C.gpointer(p))
	runtime.SetFinalizer(ret, func(p *Vfs) {
		C.g_object_unref(C.gpointer(unsafe.Pointer(p.CPointer)))
	})
	return ret
}

示例#27
文件: gio_class_types.go 项目: reusee/ggir

func NewInputStreamFromCPointer(p unsafe.Pointer) *InputStream {
	ret := &InputStream{
		NewTraitInputStream(p),
		gobject.NewTraitObject(p),
		p,
	}
	C.g_object_ref_sink(C.gpointer(p))
	runtime.SetFinalizer(ret, func(p *InputStream) {
		C.g_object_unref(C.gpointer(unsafe.Pointer(p.CPointer)))
	})
	return ret
}

示例#28
文件: gio_class_types.go 项目: reusee/ggir

func NewZlibDecompressorFromCPointer(p unsafe.Pointer) *ZlibDecompressor {
	ret := &ZlibDecompressor{
		NewTraitZlibDecompressor(p),
		gobject.NewTraitObject(p),
		p,
	}
	C.g_object_ref_sink(C.gpointer(p))
	runtime.SetFinalizer(ret, func(p *ZlibDecompressor) {
		C.g_object_unref(C.gpointer(unsafe.Pointer(p.CPointer)))
	})
	return ret
}

示例#29
文件: gio_class_types.go 项目: reusee/ggir

func NewUnixFDListFromCPointer(p unsafe.Pointer) *UnixFDList {
	ret := &UnixFDList{
		NewTraitUnixFDList(p),
		gobject.NewTraitObject(p),
		p,
	}
	C.g_object_ref_sink(C.gpointer(p))
	runtime.SetFinalizer(ret, func(p *UnixFDList) {
		C.g_object_unref(C.gpointer(unsafe.Pointer(p.CPointer)))
	})
	return ret
}

示例#30
文件: gio_class_types.go 项目: reusee/ggir

func NewSimpleActionGroupFromCPointer(p unsafe.Pointer) *SimpleActionGroup {
	ret := &SimpleActionGroup{
		NewTraitSimpleActionGroup(p),
		gobject.NewTraitObject(p),
		p,
	}
	C.g_object_ref_sink(C.gpointer(p))
	runtime.SetFinalizer(ret, func(p *SimpleActionGroup) {
		C.g_object_unref(C.gpointer(unsafe.Pointer(p.CPointer)))
	})
	return ret
}

展开阅读全文