// Code generated by cmd/cgo; DO NOT EDIT. //line /home/josie/.cache/paru/clone/wiiudownloader/src/pkg/mod/github.com/gotk3/gotk3@v0.6.5-0.20240618185848-ff349ae13f56/glib/glib.go:1:1 // Copyright (c) 2013-2014 Conformal Systems // // This file originated from: http://opensource.conformal.com/ // // Permission to use, copy, modify, and distribute this software for any // purpose with or without fee is hereby granted, provided that the above // copyright notice and this permission notice appear in all copies. // // THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES // WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF // MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR // ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES // WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN // ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF // OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. // Package glib provides Go bindings for GLib 2. It supports version 2.36 and // later. package glib // #cgo pkg-config: gio-2.0 glib-2.0 gobject-2.0 // #include // #include // #include // #include // #include "glib.go.h" import _ "unsafe" import ( "errors" "fmt" "reflect" "runtime" "unsafe" "github.com/gotk3/gotk3/internal/callback" "github.com/gotk3/gotk3/internal/closure" ) /* * Type conversions */ func gbool(b bool) /*line :44:20*/_Ctype_gboolean /*line :44:30*/ { if b { return /*line :46:10*/_Ctype_gboolean /*line :46:20*/(1) } return /*line :48:9*/_Ctype_gboolean /*line :48:19*/(0) } func gobool(b /*line :51:15*/_Ctype_gboolean /*line :51:25*/) bool { if b != 0 { return true } return false } /* * Unexported vars */ var nilPtrErr = errors.New("cgo returned unexpected nil pointer") /* * Constants */ // Type is a representation of GLib's GType. type Type uint const ( TYPE_INVALID Type = ( /*line :72:24*/_Ciconst_G_TYPE_INVALID /*line :72:39*/) TYPE_NONE Type = ( /*line :73:24*/_Ciconst_G_TYPE_NONE /*line :73:36*/) TYPE_INTERFACE Type = ( /*line :74:24*/_Ciconst_G_TYPE_INTERFACE /*line :74:41*/) TYPE_CHAR Type = ( /*line :75:24*/_Ciconst_G_TYPE_CHAR /*line :75:36*/) TYPE_UCHAR Type = ( /*line :76:24*/_Ciconst_G_TYPE_UCHAR /*line :76:37*/) TYPE_BOOLEAN Type = ( /*line :77:24*/_Ciconst_G_TYPE_BOOLEAN /*line :77:39*/) TYPE_INT Type = ( /*line :78:24*/_Ciconst_G_TYPE_INT /*line :78:35*/) TYPE_UINT Type = ( /*line :79:24*/_Ciconst_G_TYPE_UINT /*line :79:36*/) TYPE_LONG Type = ( /*line :80:24*/_Ciconst_G_TYPE_LONG /*line :80:36*/) TYPE_ULONG Type = ( /*line :81:24*/_Ciconst_G_TYPE_ULONG /*line :81:37*/) TYPE_INT64 Type = ( /*line :82:24*/_Ciconst_G_TYPE_INT64 /*line :82:37*/) TYPE_UINT64 Type = ( /*line :83:24*/_Ciconst_G_TYPE_UINT64 /*line :83:38*/) TYPE_ENUM Type = ( /*line :84:24*/_Ciconst_G_TYPE_ENUM /*line :84:36*/) TYPE_FLAGS Type = ( /*line :85:24*/_Ciconst_G_TYPE_FLAGS /*line :85:37*/) TYPE_FLOAT Type = ( /*line :86:24*/_Ciconst_G_TYPE_FLOAT /*line :86:37*/) TYPE_DOUBLE Type = ( /*line :87:24*/_Ciconst_G_TYPE_DOUBLE /*line :87:38*/) TYPE_STRING Type = ( /*line :88:24*/_Ciconst_G_TYPE_STRING /*line :88:38*/) TYPE_POINTER Type = ( /*line :89:24*/_Ciconst_G_TYPE_POINTER /*line :89:39*/) TYPE_BOXED Type = ( /*line :90:24*/_Ciconst_G_TYPE_BOXED /*line :90:37*/) TYPE_PARAM Type = ( /*line :91:24*/_Ciconst_G_TYPE_PARAM /*line :91:37*/) TYPE_OBJECT Type = ( /*line :92:24*/_Ciconst_G_TYPE_OBJECT /*line :92:38*/) TYPE_VARIANT Type = ( /*line :93:24*/_Ciconst_G_TYPE_VARIANT /*line :93:39*/) ) // IsValue checks whether the passed in type can be used for g_value_init(). func (t Type) IsValue() bool { return gobool(( /*line :98:16*/_Cfunc__g_type_is_value /*line :98:33*/)( /*line :98:35*/_Ctype_GType /*line :98:42*/(t))) } // Name is a wrapper around g_type_name(). func (t Type) Name() string { return ( /*line :103:9*/_Cfunc_GoString /*line :103:18*/)((* /*line :103:22*/_Ctype_char /*line :103:28*/)(( /*line :103:30*/_Cfunc_g_type_name /*line :103:42*/)( /*line :103:44*/_Ctype_GType /*line :103:51*/(t)))) } // Depth is a wrapper around g_type_depth(). func (t Type) Depth() uint { return uint(( /*line :108:14*/_Cfunc_g_type_depth /*line :108:27*/)( /*line :108:29*/_Ctype_GType /*line :108:36*/(t))) } // Parent is a wrapper around g_type_parent(). func (t Type) Parent() Type { return Type(( /*line :113:14*/_Cfunc_g_type_parent /*line :113:28*/)( /*line :113:30*/_Ctype_GType /*line :113:37*/(t))) } // IsA is a wrapper around g_type_is_a(). func (t Type) IsA(isAType Type) bool { return gobool(( /*line :118:16*/_Cfunc_g_type_is_a /*line :118:28*/)( /*line :118:30*/_Ctype_GType /*line :118:37*/(t), /*line :118:42*/_Ctype_GType /*line :118:49*/(isAType))) } // TypeFromName is a wrapper around g_type_from_name func TypeFromName(typeName string) Type { cstr := (* /*line :123:12*/_Ctype_gchar /*line :123:19*/)(( /*line :123:21*/_Cfunc_CString /*line :123:29*/)(typeName)) defer func() func() { _cgo0 := /*line :124:15*/unsafe.Pointer(cstr); return func() { _cgoCheckPointer(_cgo0, nil); /*line :124:36*/_Cfunc_free(_cgo0); }}()() return Type(( /*line :125:14*/_Cfunc_g_type_from_name /*line :125:31*/)(cstr)) } //TypeNextBase is a wrapper around g_type_next_base func TypeNextBase(leafType, rootType Type) Type { return Type(( /*line :130:14*/_Cfunc_g_type_next_base /*line :130:31*/)( /*line :130:33*/_Ctype_GType /*line :130:40*/(leafType), /*line :130:52*/_Ctype_GType /*line :130:59*/(rootType))) } // SettingsBindFlags is a representation of GLib's GSettingsBindFlags. type SettingsBindFlags int const ( SETTINGS_BIND_DEFAULT SettingsBindFlags = ( /*line :137:51*/_Ciconst_G_SETTINGS_BIND_DEFAULT /*line :137:75*/) SETTINGS_BIND_GET SettingsBindFlags = ( /*line :138:51*/_Ciconst_G_SETTINGS_BIND_GET /*line :138:71*/) SETTINGS_BIND_SET SettingsBindFlags = ( /*line :139:51*/_Ciconst_G_SETTINGS_BIND_SET /*line :139:71*/) SETTINGS_BIND_NO_SENSITIVITY SettingsBindFlags = ( /*line :140:51*/_Ciconst_G_SETTINGS_BIND_NO_SENSITIVITY /*line :140:82*/) SETTINGS_BIND_GET_NO_CHANGES SettingsBindFlags = ( /*line :141:51*/_Ciconst_G_SETTINGS_BIND_GET_NO_CHANGES /*line :141:82*/) SETTINGS_BIND_INVERT_BOOLEAN SettingsBindFlags = ( /*line :142:51*/_Ciconst_G_SETTINGS_BIND_INVERT_BOOLEAN /*line :142:82*/) ) // UserDirectory is a representation of GLib's GUserDirectory. type UserDirectory int const ( USER_DIRECTORY_DESKTOP UserDirectory = ( /*line :149:46*/_Ciconst_G_USER_DIRECTORY_DESKTOP /*line :149:71*/) USER_DIRECTORY_DOCUMENTS UserDirectory = ( /*line :150:46*/_Ciconst_G_USER_DIRECTORY_DOCUMENTS /*line :150:73*/) USER_DIRECTORY_DOWNLOAD UserDirectory = ( /*line :151:46*/_Ciconst_G_USER_DIRECTORY_DOWNLOAD /*line :151:72*/) USER_DIRECTORY_MUSIC UserDirectory = ( /*line :152:46*/_Ciconst_G_USER_DIRECTORY_MUSIC /*line :152:69*/) USER_DIRECTORY_PICTURES UserDirectory = ( /*line :153:46*/_Ciconst_G_USER_DIRECTORY_PICTURES /*line :153:72*/) USER_DIRECTORY_PUBLIC_SHARE UserDirectory = ( /*line :154:46*/_Ciconst_G_USER_DIRECTORY_PUBLIC_SHARE /*line :154:76*/) USER_DIRECTORY_TEMPLATES UserDirectory = ( /*line :155:46*/_Ciconst_G_USER_DIRECTORY_TEMPLATES /*line :155:73*/) USER_DIRECTORY_VIDEOS UserDirectory = ( /*line :156:46*/_Ciconst_G_USER_DIRECTORY_VIDEOS /*line :156:70*/) ) const USER_N_DIRECTORIES int = ( /*line :159:32*/_Ciconst_G_USER_N_DIRECTORIES /*line :159:53*/) /* * GApplicationFlags */ type ApplicationFlags int const ( APPLICATION_FLAGS_NONE ApplicationFlags = ( /*line :168:54*/_Ciconst_G_APPLICATION_FLAGS_NONE /*line :168:79*/) APPLICATION_IS_SERVICE ApplicationFlags = ( /*line :169:54*/_Ciconst_G_APPLICATION_IS_SERVICE /*line :169:79*/) APPLICATION_HANDLES_OPEN ApplicationFlags = ( /*line :170:54*/_Ciconst_G_APPLICATION_HANDLES_OPEN /*line :170:81*/) APPLICATION_HANDLES_COMMAND_LINE ApplicationFlags = ( /*line :171:54*/_Ciconst_G_APPLICATION_HANDLES_COMMAND_LINE /*line :171:89*/) APPLICATION_SEND_ENVIRONMENT ApplicationFlags = ( /*line :172:54*/_Ciconst_G_APPLICATION_SEND_ENVIRONMENT /*line :172:85*/) APPLICATION_NON_UNIQUE ApplicationFlags = ( /*line :173:54*/_Ciconst_G_APPLICATION_NON_UNIQUE /*line :173:79*/) ) // goMarshal is called by the GLib runtime when a closure needs to be invoked. // The closure will be invoked with as many arguments as it can take, from 0 to // the full amount provided by the call. If the closure asks for more parameters // than there are to give, then a runtime panic will occur. // //export goMarshal func goMarshal( gclosure * /*line :183:12*/_Ctype_GClosure /*line :183:22*/, retValue * /*line :184:12*/_Ctype_GValue /*line :184:20*/, nParams /*line :185:10*/_Ctype_guint /*line :185:17*/, params * /*line :186:10*/_Ctype_GValue /*line :186:18*/, invocationHint /*line :187:17*/_Ctype_gpointer /*line :187:27*/, marshalData * /*line :188:15*/_Ctype_GValue /*line :188:23*/) { // Get the function value associated with this callback closure. fs := closure.Get(unsafe.Pointer(gclosure)) if !fs.IsValid() { // Possible data race, bail. return } fsType := fs.Func.Type() // Get number of parameters passed in. nGLibParams := int(nParams) nTotalParams := nGLibParams // Reflect may panic, so we defer recover here to re-panic with our trace. defer fs.TryRepanic() // Get number of parameters from the callback closure. If this exceeds // the total number of marshaled parameters, trigger a runtime panic. nCbParams := fsType.NumIn() if nCbParams > nTotalParams { fs.Panicf("too many closure args: have %d, max %d", nCbParams, nTotalParams) } // Create a slice of reflect.Values as arguments to call the function. gValues := gValueSlice(params, nCbParams) args := make([]reflect.Value, 0, nCbParams) // Fill beginning of args, up to the minimum of the total number of callback // parameters and parameters from the glib runtime. for i := 0; i < nCbParams && i < nGLibParams; i++ { v := Value{&gValues[i]} val, err := v.GoValue() if err != nil { fs.Panicf("no suitable Go value for arg %d: %v", i, err) } // Parameters that are descendants of GObject come wrapped in another // GObject. For C applications, the default marshaller // (g_cclosure_marshal_VOID__VOID in gmarshal.c in the GTK glib library) // 'peeks' into the enclosing object and passes the wrapped object to // the handler. Use the *Object.goValue function to emulate that for Go // signal handlers. switch objVal := val.(type) { case *Object: if innerVal, err := objVal.goValue(); err == nil { val = innerVal } case *Variant: switch ts := objVal.TypeString(); ts { case "s": val = objVal.GetString() case "b": val = gobool(func() _Ctype_gboolean{ _cgo0 := /*line :244:42*/objVal.native(); _cgoCheckPointer(_cgo0, nil); return /*line :244:58*/_Cfunc_g_variant_get_boolean(_cgo0); }()) case "d": val = float64(func() _Ctype_gdouble{ _cgo0 := /*line :246:42*/objVal.native(); _cgoCheckPointer(_cgo0, nil); return /*line :246:58*/_Cfunc_g_variant_get_double(_cgo0); }()) case "n": val = int16(func() _Ctype_gint16{ _cgo0 := /*line :248:39*/objVal.native(); _cgoCheckPointer(_cgo0, nil); return /*line :248:55*/_Cfunc_g_variant_get_int16(_cgo0); }()) case "i": val = int32(func() _Ctype_gint32{ _cgo0 := /*line :250:39*/objVal.native(); _cgoCheckPointer(_cgo0, nil); return /*line :250:55*/_Cfunc_g_variant_get_int32(_cgo0); }()) case "x": val = int64(func() _Ctype_gint64{ _cgo0 := /*line :252:39*/objVal.native(); _cgoCheckPointer(_cgo0, nil); return /*line :252:55*/_Cfunc_g_variant_get_int64(_cgo0); }()) case "y": val = uint8(func() _Ctype_guint8{ _cgo0 := /*line :254:38*/objVal.native(); _cgoCheckPointer(_cgo0, nil); return /*line :254:54*/_Cfunc_g_variant_get_byte(_cgo0); }()) case "q": val = uint16(func() _Ctype_guint16{ _cgo0 := /*line :256:41*/objVal.native(); _cgoCheckPointer(_cgo0, nil); return /*line :256:57*/_Cfunc_g_variant_get_uint16(_cgo0); }()) case "u": val = uint32(func() _Ctype_guint32{ _cgo0 := /*line :258:41*/objVal.native(); _cgoCheckPointer(_cgo0, nil); return /*line :258:57*/_Cfunc_g_variant_get_uint32(_cgo0); }()) case "t": val = uint64(func() _Ctype_guint64{ _cgo0 := /*line :260:41*/objVal.native(); _cgoCheckPointer(_cgo0, nil); return /*line :260:57*/_Cfunc_g_variant_get_uint64(_cgo0); }()) default: fs.Panicf("variant conversion not yet implemented for type %s", ts) } } args = append(args, reflect.ValueOf(val).Convert(fsType.In(i))) } // Call closure with args. If the callback returns one or more values, save // the GValue equivalent of the first. rv := fs.Func.Call(args) if retValue != nil && len(rv) > 0 { g, err := GValue(rv[0].Interface()) if err != nil { fs.Panicf("cannot save callback return value: %v", err) } t, _, err := g.Type() if err != nil { fs.Panicf("cannot determine callback return value: %v", err) } // Explicitly copy the return value as it may point to go-owned memory. ( /*line :284:3*/_Cfunc_g_value_unset /*line :284:17*/)(retValue) ( /*line :285:3*/_Cfunc_g_value_init /*line :285:16*/)(retValue, /*line :285:28*/_Ctype_GType /*line :285:35*/(t)) ( /*line :286:3*/_Cfunc_g_value_copy /*line :286:16*/)(g.native(), retValue) } } // gValueSlice converts a C array of GValues to a Go slice. func gValueSlice(values * /*line :291:26*/_Ctype_GValue /*line :291:34*/, nValues int) (slice [] /*line :291:58*/_Ctype_GValue /*line :291:66*/) { header := (*reflect.SliceHeader)((unsafe.Pointer(&slice))) header.Cap = nValues header.Len = nValues header.Data = uintptr(unsafe.Pointer(values)) return } /* * Main event loop */ // Priority is the enumerated type for GLib priority event sources. type Priority int const ( PRIORITY_HIGH Priority = ( /*line :307:35*/_Ciconst_G_PRIORITY_HIGH /*line :307:51*/) PRIORITY_DEFAULT Priority = ( /*line :308:35*/_Ciconst_G_PRIORITY_DEFAULT /*line :308:54*/) // TimeoutAdd PRIORITY_HIGH_IDLE Priority = ( /*line :309:35*/_Ciconst_G_PRIORITY_HIGH_IDLE /*line :309:56*/) PRIORITY_DEFAULT_IDLE Priority = ( /*line :310:35*/_Ciconst_G_PRIORITY_DEFAULT_IDLE /*line :310:59*/) // IdleAdd PRIORITY_LOW Priority = ( /*line :311:35*/_Ciconst_G_PRIORITY_LOW /*line :311:50*/) ) type SourceHandle uint // sourceFunc is the callback for g_idle_add_full and g_timeout_add_full that // replaces the GClosure API. // //export sourceFunc func sourceFunc(data /*line :320:22*/_Ctype_gpointer /*line :320:32*/) /*line :320:34*/_Ctype_gboolean /*line :320:44*/ { v := callback.Get(uintptr(data)) fs := v.(closure.FuncStack) rv := fs.Func.Call(nil) if len(rv) == 1 && rv[0].Bool() { return ( /*line :326:10*/_Ciconst_TRUE /*line :326:15*/) } return ( /*line :329:9*/_Ciconst_FALSE /*line :329:15*/) } //export removeSourceFunc func removeSourceFunc(data /*line :333:28*/_Ctype_gpointer /*line :333:38*/) { callback.Delete(uintptr(data)) } var ( _sourceFunc = (*[0]byte)(( /*line :338:33*/_Cgo_ptr(_Cfpvar_fp_sourceFunc) /*line :338:44*/)) _removeSourceFunc = (*[0]byte)(( /*line :339:33*/_Cgo_ptr(_Cfpvar_fp_removeSourceFunc) /*line :339:50*/)) ) // IdleAdd adds an idle source to the default main event loop context with the // DefaultIdle priority. If f is not a function with no parameter, then IdleAdd // will panic. // // After running once, the source func will be removed from the main event loop, // unless f returns a single bool true. func IdleAdd(f interface{}) SourceHandle { return idleAdd(PRIORITY_DEFAULT_IDLE, f) } // IdleAddPriority adds an idle source to the default main event loop context // with the given priority. Its behavior is the same as IdleAdd. func IdleAddPriority(priority Priority, f interface{}) SourceHandle { return idleAdd(priority, f) } func idleAdd(priority Priority, f interface{}) SourceHandle { fs := closure.NewIdleFuncStack(f, 2) id := /*line :360:8*/_Ctype_gpointer /*line :360:18*/(callback.Assign(fs)) h := func() _Ctype_guint{ var _cgo0 _Ctype_gint = _Ctype_gint /*line :361:31*/(priority); var _cgo1 *[0]byte = /*line :361:43*/_sourceFunc; _cgo2 := /*line :361:56*/id; var _cgo3 *[0]byte = /*line :361:60*/_removeSourceFunc; _cgoCheckPointer(_cgo2, nil); return /*line :361:78*/_Cfunc_g_idle_add_full(_cgo0, _cgo1, _cgo2, _cgo3); }() return SourceHandle(h) } // TimeoutAdd adds an timeout source to the default main event loop context. // Timeout is in milliseconds. If f is not a function with no parameter, then it // will panic. // // After running once, the source func will be removed from the main event loop, // unless f returns a single bool true. func TimeoutAdd(milliseconds uint, f interface{}) SourceHandle { return timeoutAdd(milliseconds, false, PRIORITY_DEFAULT, f) } // TimeoutAddPriority is similar to TimeoutAdd with the given priority. Refer to // TimeoutAdd for more information. func TimeoutAddPriority(milliseconds uint, priority Priority, f interface{}) SourceHandle { return timeoutAdd(milliseconds, false, priority, f) } // TimeoutSecondsAdd is similar to TimeoutAdd, except with seconds granularity. func TimeoutSecondsAdd(seconds uint, f interface{}) SourceHandle { return timeoutAdd(seconds, true, PRIORITY_DEFAULT, f) } // TimeoutSecondsAddPriority adds a timeout source with the given priority. // Refer to TimeoutSecondsAdd for more information. func TimeoutSecondsAddPriority(seconds uint, priority Priority, f interface{}) SourceHandle { return timeoutAdd(seconds, true, priority, f) } func timeoutAdd(time uint, sec bool, priority Priority, f interface{}) SourceHandle { fs := closure.NewIdleFuncStack(f, 2) id := /*line :395:8*/_Ctype_gpointer /*line :395:18*/(callback.Assign(fs)) var h /*line :397:8*/_Ctype_guint /*line :397:15*/ if sec { h = func() _Ctype_guint{ var _cgo0 _Ctype_gint = _Ctype_gint /*line :399:42*/(priority); var _cgo1 _Ctype_guint = _Ctype_guint /*line :399:61*/(time); var _cgo2 *[0]byte = /*line :399:69*/_sourceFunc; _cgo3 := /*line :399:82*/id; var _cgo4 *[0]byte = /*line :399:86*/_removeSourceFunc; _cgoCheckPointer(_cgo3, nil); return /*line :399:104*/_Cfunc_g_timeout_add_seconds_full(_cgo0, _cgo1, _cgo2, _cgo3, _cgo4); }() } else { h = func() _Ctype_guint{ var _cgo0 _Ctype_gint = _Ctype_gint /*line :401:34*/(priority); var _cgo1 _Ctype_guint = _Ctype_guint /*line :401:53*/(time); var _cgo2 *[0]byte = /*line :401:61*/_sourceFunc; _cgo3 := /*line :401:74*/id; var _cgo4 *[0]byte = /*line :401:78*/_removeSourceFunc; _cgoCheckPointer(_cgo3, nil); return /*line :401:96*/_Cfunc_g_timeout_add_full(_cgo0, _cgo1, _cgo2, _cgo3, _cgo4); }() } return SourceHandle(h) } // Destroy is a wrapper around g_source_destroy() func (v *Source) Destroy() { func() { _cgo0 := /*line :409:21*/v.native(); _cgoCheckPointer(_cgo0, nil); /*line :409:32*/_Cfunc_g_source_destroy(_cgo0); }() } // IsDestroyed is a wrapper around g_source_is_destroyed() func (v *Source) IsDestroyed() bool { return gobool(func() _Ctype_gboolean{ _cgo0 := /*line :414:40*/v.native(); _cgoCheckPointer(_cgo0, nil); return /*line :414:51*/_Cfunc_g_source_is_destroyed(_cgo0); }()) } // Unref is a wrapper around g_source_unref() func (v *Source) Unref() { func() { _cgo0 := /*line :419:19*/v.native(); _cgoCheckPointer(_cgo0, nil); /*line :419:30*/_Cfunc_g_source_unref(_cgo0); }() } // Ref is a wrapper around g_source_ref() func (v *Source) Ref() *Source { c := func() *_Ctype_struct__GSource{ _cgo0 := /*line :424:22*/v.native(); _cgoCheckPointer(_cgo0, nil); return /*line :424:33*/_Cfunc_g_source_ref(_cgo0); }() if c == nil { return nil } return (*Source)(c) } // SourceRemove is a wrapper around g_source_remove() func SourceRemove(src SourceHandle) bool { return gobool(( /*line :433:16*/_Cfunc_g_source_remove /*line :433:32*/)( /*line :433:34*/_Ctype_guint /*line :433:41*/(src))) } /* * Miscellaneous Utility Functions */ // GetHomeDir is a wrapper around g_get_home_dir(). func GetHomeDir() string { c := ( /*line :442:7*/_Cfunc_g_get_home_dir /*line :442:22*/)() return ( /*line :443:9*/_Cfunc_GoString /*line :443:18*/)((* /*line :443:22*/_Ctype_char /*line :443:28*/)(c)) } // GetUserCacheDir is a wrapper around g_get_user_cache_dir(). func GetUserCacheDir() string { c := ( /*line :448:7*/_Cfunc_g_get_user_cache_dir /*line :448:28*/)() return ( /*line :449:9*/_Cfunc_GoString /*line :449:18*/)((* /*line :449:22*/_Ctype_char /*line :449:28*/)(c)) } // GetUserDataDir is a wrapper around g_get_user_data_dir(). func GetUserDataDir() string { c := ( /*line :454:7*/_Cfunc_g_get_user_data_dir /*line :454:27*/)() return ( /*line :455:9*/_Cfunc_GoString /*line :455:18*/)((* /*line :455:22*/_Ctype_char /*line :455:28*/)(c)) } // GetUserConfigDir is a wrapper around g_get_user_config_dir(). func GetUserConfigDir() string { c := ( /*line :460:7*/_Cfunc_g_get_user_config_dir /*line :460:29*/)() return ( /*line :461:9*/_Cfunc_GoString /*line :461:18*/)((* /*line :461:22*/_Ctype_char /*line :461:28*/)(c)) } // GetUserRuntimeDir is a wrapper around g_get_user_runtime_dir(). func GetUserRuntimeDir() string { c := ( /*line :466:7*/_Cfunc_g_get_user_runtime_dir /*line :466:30*/)() return ( /*line :467:9*/_Cfunc_GoString /*line :467:18*/)((* /*line :467:22*/_Ctype_char /*line :467:28*/)(c)) } // GetUserSpecialDir is a wrapper around g_get_user_special_dir(). A // non-nil error is returned in the case that g_get_user_special_dir() // returns NULL to differentiate between NULL and an empty string. func GetUserSpecialDir(directory UserDirectory) (string, error) { c := ( /*line :474:7*/_Cfunc_g_get_user_special_dir /*line :474:30*/)( /*line :474:32*/_Ctype_GUserDirectory /*line :474:48*/(directory)) if c == nil { return "", nilPtrErr } return ( /*line :478:9*/_Cfunc_GoString /*line :478:18*/)((* /*line :478:22*/_Ctype_char /*line :478:28*/)(c)), nil } // FormatSize is a wrapper around g_format_size(). func FormatSize(size uint64) string { char := ( /*line :483:10*/_Cfunc_g_format_size /*line :483:24*/)( /*line :483:26*/_Ctype_guint64 /*line :483:35*/(size)) defer func() func() { _cgo0 := /*line :484:15*/unsafe.Pointer(char); return func() { _cgoCheckPointer(_cgo0, nil); /*line :484:36*/_Cfunc_free(_cgo0); }}()() return ( /*line :486:9*/_Cfunc_GoString /*line :486:18*/)(char) } // FormatSizeFlags are flags to modify the format of the string returned by // FormatSizeFull. type FormatSizeFlags int const ( FORMAT_SIZE_DEFAULT FormatSizeFlags = ( /*line :494:44*/_Ciconst_G_FORMAT_SIZE_DEFAULT /*line :494:66*/) FORMAT_SIZE_LONG_FORMAT FormatSizeFlags = ( /*line :495:44*/_Ciconst_G_FORMAT_SIZE_LONG_FORMAT /*line :495:70*/) FORMAT_SIZE_IEC_UNITS FormatSizeFlags = ( /*line :496:44*/_Ciconst_G_FORMAT_SIZE_IEC_UNITS /*line :496:68*/) ) // FormatSizeFull is a wrapper around g_format_size_full(). func FormatSizeFull(size uint64, flags FormatSizeFlags) string { char := ( /*line :501:10*/_Cfunc_g_format_size_full /*line :501:29*/)( /*line :501:31*/_Ctype_guint64 /*line :501:40*/(size), /*line :501:48*/_Ctype_GFormatSizeFlags /*line :501:66*/(flags)) defer func() func() { _cgo0 := /*line :502:15*/unsafe.Pointer(char); return func() { _cgoCheckPointer(_cgo0, nil); /*line :502:36*/_Cfunc_free(_cgo0); }}()() return ( /*line :504:9*/_Cfunc_GoString /*line :504:18*/)(char) } // SpacedPrimesClosest is a wrapper around g_spaced_primes_closest(). func SpacedPrimesClosest(num uint) uint { return uint(( /*line :509:14*/_Cfunc_g_spaced_primes_closest /*line :509:38*/)( /*line :509:40*/_Ctype_guint /*line :509:47*/(num))) } /* * GObject */ // IObject is an interface type implemented by Object and all types which embed // an Object. It is meant to be used as a type for function arguments which // require GObjects or any subclasses thereof. type IObject interface { toGObject() * /*line :520:15*/_Ctype_GObject /*line :520:24*/ toObject() *Object } // Object is a representation of GLib's GObject. type Object struct { GObject * /*line :526:11*/_Ctype_GObject /*line :526:20*/ } func (v *Object) toGObject() * /*line :529:31*/_Ctype_GObject /*line :529:40*/ { if v == nil { return nil } return v.native() } func (v *Object) toObject() *Object { return v } // newObject creates a new Object from a GObject pointer. func newObject(p * /*line :541:19*/_Ctype_GObject /*line :541:28*/) *Object { if p == nil { return nil } return &Object{GObject: p} } // native returns a pointer to the underlying GObject. func (v *Object) native() * /*line :549:28*/_Ctype_GObject /*line :549:37*/ { if v == nil || v.GObject == nil { return nil } p := unsafe.Pointer(v.GObject) return func() *_Ctype_struct__GObject{ _cgo0 := /*line :554:21*/p; _cgoCheckPointer(_cgo0, nil); return /*line :554:23*/_Cfunc_toGObject(_cgo0); }() } // goValue converts a *Object to a Go type (e.g. *Object => *gtk.Entry). // It is used in goMarshal to convert generic GObject parameters to // signal handlers to the actual types expected by the signal handler. func (v *Object) goValue() (interface{}, error) { objType := Type(func() _Ctype_GType{ _cgo0 := _Ctype_gpointer /*line :561:52*/(v.native()); _cgoCheckPointer(_cgo0, nil); return /*line :561:65*/_Cfunc__g_type_from_instance(_cgo0); }()) f, err := gValueMarshalers.lookupType(objType) if err != nil { return nil, err } // The marshalers expect Values, not Objects val, err := ValueInit(objType) if err != nil { return nil, err } val.SetInstance(uintptr(unsafe.Pointer(v.GObject))) rv, err := f(uintptr(unsafe.Pointer(val.native()))) return rv, err } // Take wraps a unsafe.Pointer as a glib.Object, taking ownership of it. // This function is exported for visibility in other gotk3 packages and // is not meant to be used by applications. // // To be clear, this should mostly be used when Gtk says "transfer none". Refer // to AssumeOwnership for more details. func Take(ptr unsafe.Pointer) *Object { obj := newObject(ToGObject(ptr)) if obj == nil { return nil } obj.RefSink() runtime.SetFinalizer(obj, func(v *Object) { FinalizerStrategy(v.Unref) }) return obj } // AssumeOwnership is similar to Take, except the function does not take a // reference. This is usually used for newly constructed objects that for some // reason does not have an initial floating reference. // // To be clear, this should often be used when Gtk says "transfer full", as it // means the ownership is transferred to the caller, so we can assume that much. // This is in contrary to Take, which is used when Gtk says "transfer none", as // we're now referencing an object that might possibly be kept, so we should // mark as such. func AssumeOwnership(ptr unsafe.Pointer) *Object { obj := newObject(ToGObject(ptr)) runtime.SetFinalizer(obj, func(v *Object) { FinalizerStrategy(v.Unref) }) return obj } // Native returns a pointer to the underlying GObject. func (v *Object) Native() uintptr { return uintptr(unsafe.Pointer(v.native())) } // IsA is a wrapper around g_type_is_a(). func (v *Object) IsA(typ Type) bool { return gobool(( /*line :616:16*/_Cfunc_g_type_is_a /*line :616:28*/)( /*line :616:30*/_Ctype_GType /*line :616:37*/(v.TypeFromInstance()), /*line :616:61*/_Ctype_GType /*line :616:68*/(typ))) } // TypeFromInstance is a wrapper around g_type_from_instance(). func (v *Object) TypeFromInstance() Type { c := func() _Ctype_GType{ _cgo0 := _Ctype_gpointer /*line :621:41*/(unsafe.Pointer(v.native())); _cgoCheckPointer(_cgo0, nil); return /*line :621:70*/_Cfunc__g_type_from_instance(_cgo0); }() return Type(c) } // ToGObject type converts an unsafe.Pointer as a native C GObject. // This function is exported for visibility in other gotk3 packages and // is not meant to be used by applications. func ToGObject(p unsafe.Pointer) * /*line :628:35*/_Ctype_GObject /*line :628:44*/ { return (* /*line :629:11*/_Ctype_GObject /*line :629:20*/)(p) // return C.toGObject(p) } // Ref is a wrapper around g_object_ref(). func (v *Object) Ref() { func() _Ctype_gpointer{ _cgo0 := _Ctype_gpointer /*line :635:27*/(v.GObject); _cgoCheckPointer(_cgo0, nil); return /*line :635:39*/_Cfunc_g_object_ref(_cgo0); }() } // Unref is a wrapper around g_object_unref(). func (v *Object) Unref() { func() { _cgo0 := _Ctype_gpointer /*line :640:29*/(v.GObject); _cgoCheckPointer(_cgo0, nil); /*line :640:41*/_Cfunc_g_object_unref(_cgo0); }() } // RefSink is a wrapper around g_object_ref_sink(). func (v *Object) RefSink() { func() _Ctype_gpointer{ _cgo0 := _Ctype_gpointer /*line :645:32*/(v.GObject); _cgoCheckPointer(_cgo0, nil); return /*line :645:44*/_Cfunc_g_object_ref_sink(_cgo0); }() } // IsFloating is a wrapper around g_object_is_floating(). func (v *Object) IsFloating() bool { c := func() _Ctype_gboolean{ _cgo0 := _Ctype_gpointer /*line :650:40*/(v.GObject); _cgoCheckPointer(_cgo0, nil); return /*line :650:52*/_Cfunc_g_object_is_floating(_cgo0); }() return gobool(c) } // ForceFloating is a wrapper around g_object_force_floating(). func (v *Object) ForceFloating() { func() { _cgo0 := /*line :656:28*/v.GObject; _cgoCheckPointer(_cgo0, nil); /*line :656:38*/_Cfunc_g_object_force_floating(_cgo0); }() } // StopEmission is a wrapper around g_signal_stop_emission_by_name(). func (v *Object) StopEmission(s string) { cstr := ( /*line :661:10*/_Cfunc_CString /*line :661:18*/)(s) defer func() func() { _cgo0 := /*line :662:15*/unsafe.Pointer(cstr); return func() { _cgoCheckPointer(_cgo0, nil); /*line :662:36*/_Cfunc_free(_cgo0); }}()() func() { _cgo0 := /*line :663:35*/(_Ctype_gpointer /*line :663:46*/)(v.GObject); var _cgo1 *_Ctype_gchar = /*line :664:3*/(*_Ctype_gchar /*line :664:12*/)(cstr); _cgoCheckPointer(_cgo0, nil); /*line :664:20*/_Cfunc_g_signal_stop_emission_by_name(_cgo0, _cgo1); }() } // Set calls SetProperty. func (v *Object) Set(name string, value interface{}) error { return v.SetProperty(name, value) } // GetPropertyType returns the Type of a property of the underlying GObject. // If the property is missing it will return TYPE_INVALID and an error. func (v *Object) GetPropertyType(name string) (Type, error) { cstr := ( /*line :675:10*/_Cfunc_CString /*line :675:18*/)(name) defer func() func() { _cgo0 := /*line :676:15*/unsafe.Pointer(cstr); return func() { _cgoCheckPointer(_cgo0, nil); /*line :676:36*/_Cfunc_free(_cgo0); }}()() paramSpec := func() *_Ctype_struct__GParamSpec{ _cgo0 := func() *_Ctype_struct__GObjectClass{ _cgo0 := /*line :678:68*/v.native(); _cgoCheckPointer(_cgo0, nil); return /*line :678:79*/_Cfunc__g_object_get_class(_cgo0); }(); var _cgo1 *_Ctype_gchar = /*line :678:81*/(*_Ctype_gchar /*line :678:90*/)(cstr); _cgoCheckPointer(_cgo0, nil); return /*line :678:98*/_Cfunc_g_object_class_find_property(_cgo0, _cgo1); }() if paramSpec == nil { return TYPE_INVALID, errors.New("couldn't find Property") } return Type(paramSpec.value_type), nil } // GetProperty is a wrapper around g_object_get_property(). func (v *Object) GetProperty(name string) (interface{}, error) { cstr := ( /*line :687:10*/_Cfunc_CString /*line :687:18*/)(name) defer func() func() { _cgo0 := /*line :688:15*/unsafe.Pointer(cstr); return func() { _cgoCheckPointer(_cgo0, nil); /*line :688:36*/_Cfunc_free(_cgo0); }}()() t, err := v.GetPropertyType(name) if err != nil { return nil, err } p, err := ValueInit(t) if err != nil { return nil, errors.New("unable to allocate value") } func() { _cgo0 := /*line :699:26*/v.GObject; var _cgo1 *_Ctype_gchar = /*line :699:37*/(*_Ctype_gchar /*line :699:46*/)(cstr); var _cgo2 *_Ctype_struct__GValue = /*line :699:55*/p.native(); _cgoCheckPointer(_cgo0, nil); /*line :699:66*/_Cfunc_g_object_get_property(_cgo0, _cgo1, _cgo2); }() return p.GoValue() } // SetProperty is a wrapper around g_object_set_property(). func (v *Object) SetProperty(name string, value interface{}) error { cstr := ( /*line :705:10*/_Cfunc_CString /*line :705:18*/)(name) defer func() func() { _cgo0 := /*line :706:15*/unsafe.Pointer(cstr); return func() { _cgoCheckPointer(_cgo0, nil); /*line :706:36*/_Cfunc_free(_cgo0); }}()() if _, ok := value.(Object); ok { value = value.(Object).GObject } p, err := GValue(value) if err != nil { return errors.New("Unable to perform type conversion") } func() { _cgo0 := /*line :716:26*/v.GObject; var _cgo1 *_Ctype_gchar = /*line :716:37*/(*_Ctype_gchar /*line :716:46*/)(cstr); var _cgo2 *_Ctype_struct__GValue = /*line :716:55*/p.native(); _cgoCheckPointer(_cgo0, nil); /*line :716:66*/_Cfunc_g_object_set_property(_cgo0, _cgo1, _cgo2); }() return nil } /* * GObject Signals */ // 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, retType Type, args ...interface{}) (interface{}, error) { cstr := ( /*line :733:10*/_Cfunc_CString /*line :733:18*/)(s) defer func() func() { _cgo0 := /*line :734:15*/unsafe.Pointer(cstr); return func() { _cgoCheckPointer(_cgo0, nil); /*line :734:36*/_Cfunc_free(_cgo0); }}()() // Create array of this instance and arguments valv := ( /*line :737:10*/_Cfunc_alloc_gvalue_list /*line :737:28*/)( /*line :737:30*/_Ctype_int /*line :737:35*/(len(args)) + 1) defer func() func() { _cgo0 := /*line :738:15*/unsafe.Pointer(valv); return func() { _cgoCheckPointer(_cgo0, nil); /*line :738:36*/_Cfunc_free(_cgo0); }}()() // Add args and valv val, err := GValue(v) if err != nil { return nil, errors.New("Error converting Object to GValue: " + err.Error()) } ( /*line :745:2*/_Cfunc_val_list_insert /*line :745:18*/)(valv, /*line :745:26*/_Ctype_int /*line :745:31*/(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()) } ( /*line :751:3*/_Cfunc_val_list_insert /*line :751:19*/)(valv, /*line :751:27*/_Ctype_int /*line :751:32*/(i+1), val.native()) } t := v.TypeFromInstance() // TODO: use just the signal name id := ( /*line :756:8*/_Cfunc_g_signal_lookup /*line :756:24*/)((* /*line :756:28*/_Ctype_gchar /*line :756:35*/)(cstr), /*line :756:44*/_Ctype_GType /*line :756:51*/(t)) var ret *Value if retType == TYPE_NONE { ret, err = ValueAlloc() } else { ret, err = ValueInit(retType) } if err != nil { return nil, errors.New("Error creating Value for return value") } ( /*line :768:2*/_Cfunc_g_signal_emitv /*line :768:17*/)(valv, id, /*line :768:29*/_Ctype_GQuark /*line :768:37*/(0), ret.native()) return ret.GoValue() } // HandlerBlock is a wrapper around g_signal_handler_block(). func (v *Object) HandlerBlock(handle SignalHandle) { func() { _cgo0 := _Ctype_gpointer /*line :775:37*/(v.GObject); var _cgo1 _Ctype_gulong = _Ctype_gulong /*line :775:58*/(handle); _cgoCheckPointer(_cgo0, nil); /*line :775:67*/_Cfunc_g_signal_handler_block(_cgo0, _cgo1); }() } // HandlerUnblock is a wrapper around g_signal_handler_unblock(). func (v *Object) HandlerUnblock(handle SignalHandle) { func() { _cgo0 := _Ctype_gpointer /*line :780:39*/(v.GObject); var _cgo1 _Ctype_gulong = _Ctype_gulong /*line :780:60*/(handle); _cgoCheckPointer(_cgo0, nil); /*line :780:69*/_Cfunc_g_signal_handler_unblock(_cgo0, _cgo1); }() } // HandlerDisconnect is a wrapper around g_signal_handler_disconnect(). func (v *Object) HandlerDisconnect(handle SignalHandle) { // Ensure that Gtk will not use the closure beforehand. func() { _cgo0 := _Ctype_gpointer /*line :786:42*/(v.GObject); var _cgo1 _Ctype_gulong = _Ctype_gulong /*line :786:63*/(handle); _cgoCheckPointer(_cgo0, nil); /*line :786:72*/_Cfunc_g_signal_handler_disconnect(_cgo0, _cgo1); }() closure.DisconnectSignal(uint(handle)) } // Wrapper function for new objects with reference management. func wrapObject(ptr unsafe.Pointer) *Object { return Take(ptr) } /* * GInitiallyUnowned */ // InitiallyUnowned is a representation of GLib's GInitiallyUnowned. type InitiallyUnowned struct { // This must be a pointer so copies of the ref-sinked object // do not outlive the original object, causing an unref // finalizer to prematurely run. *Object } // Native returns a pointer to the underlying GObject. This is implemented // here rather than calling Native on the embedded Object to prevent a nil // pointer dereference. func (v *InitiallyUnowned) Native() uintptr { if v == nil || v.Object == nil { return uintptr(unsafe.Pointer(nil)) } return v.Object.Native() } /* * GValue */ // Value is a representation of GLib's GValue. // // Don't allocate Values on the stack or heap manually as they may not // be properly unset when going out of scope. Instead, use ValueAlloc(), // which will set the runtime finalizer to unset the Value after it has // left scope. type Value struct { GValue * /*line :828:10*/_Ctype_GValue /*line :828:18*/ } // native returns a pointer to the underlying GValue. func (v *Value) native() * /*line :832:27*/_Ctype_GValue /*line :832:35*/ { return v.GValue } // Native returns a pointer to the underlying GValue. func (v *Value) Native() uintptr { return uintptr(unsafe.Pointer(v.native())) } // IsValue checks if value is a valid and initialized GValue structure. func (v *Value) IsValue() bool { return gobool(( /*line :843:16*/_Cfunc__g_is_value /*line :843:28*/)(v.native())) } // TypeName gets the type name of value. func (v *Value) TypeName() string { return ( /*line :848:9*/_Cfunc_GoString /*line :848:18*/)((* /*line :848:22*/_Ctype_char /*line :848:28*/)(( /*line :848:30*/_Cfunc__g_value_type_name /*line :848:49*/)(v.native()))) } // ValueAlloc allocates a Value and sets a runtime finalizer to call // g_value_unset() on the underlying GValue after leaving scope. // ValueAlloc() returns a non-nil error if the allocation failed. func ValueAlloc() (*Value, error) { c := ( /*line :855:7*/_Cfunc__g_value_alloc /*line :855:22*/)() if c == nil { return nil, nilPtrErr } v := &Value{c} //An allocated GValue is not guaranteed to hold a value that can be unset //We need to double check before unsetting, to prevent: //`g_value_unset: assertion 'G_IS_VALUE (value)' failed` runtime.SetFinalizer(v, func(f *Value) { FinalizerStrategy(func() { if !f.IsValue() { func() { _cgo0 := _Ctype_gpointer /*line :868:24*/(f.native()); _cgoCheckPointer(_cgo0, nil); /*line :868:37*/_Cfunc_g_free(_cgo0); }() return } f.unset() }) }) return v, nil } // 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 := ( /*line :884:7*/_Cfunc__g_value_init /*line :884:21*/)( /*line :884:23*/_Ctype_GType /*line :884:30*/(t)) if c == nil { return nil, nilPtrErr } v := &Value{c} runtime.SetFinalizer(v, func(vv *Value) { FinalizerStrategy(vv.unset) }) return v, nil } // ValueFromNative returns a type-asserted pointer to the Value. func ValueFromNative(l unsafe.Pointer) *Value { //TODO why it does not add finalizer to the value? return &Value{(* /*line :898:18*/_Ctype_GValue /*line :898:26*/)(l)} } func (v *Value) unset() { ( /*line :902:2*/_Cfunc_g_value_unset /*line :902:16*/)(v.native()) } // Unset is wrapper for g_value_unset func (v *Value) Unset() { v.unset() } // Type is a wrapper around the G_VALUE_HOLDS_GTYPE() macro and // the g_value_get_gtype() function. GetType() returns TYPE_INVALID if v // does not hold a Type, or otherwise returns the Type of v. func (v *Value) Type() (actual Type, fundamental Type, err error) { if !v.IsValue() { return actual, fundamental, errors.New("invalid GValue") } cActual := ( /*line :917:13*/_Cfunc__g_value_type /*line :917:27*/)(v.native()) cFundamental := ( /*line :918:18*/_Cfunc__g_value_fundamental /*line :918:39*/)(cActual) return Type(cActual), Type(cFundamental), nil } // GValue converts a Go type to a comparable GValue. GValue() // returns a non-nil error if the conversion was unsuccessful. func GValue(v interface{}) (gvalue *Value, err error) { if v == nil { val, err := ValueInit(TYPE_POINTER) if err != nil { return nil, err } val.SetPointer(uintptr(unsafe.Pointer(nil))) return val, nil } switch e := v.(type) { case bool: val, err := ValueInit(TYPE_BOOLEAN) if err != nil { return nil, err } val.SetBool(e) return val, nil case int8: val, err := ValueInit(TYPE_CHAR) if err != nil { return nil, err } val.SetSChar(e) return val, nil case int64: val, err := ValueInit(TYPE_INT64) if err != nil { return nil, err } val.SetInt64(e) return val, nil case int: val, err := ValueInit(TYPE_INT) if err != nil { return nil, err } val.SetInt(e) return val, nil case uint8: val, err := ValueInit(TYPE_UCHAR) if err != nil { return nil, err } val.SetUChar(e) return val, nil case uint64: val, err := ValueInit(TYPE_UINT64) if err != nil { return nil, err } val.SetUInt64(e) return val, nil case uint: val, err := ValueInit(TYPE_UINT) if err != nil { return nil, err } val.SetUInt(e) return val, nil case float32: val, err := ValueInit(TYPE_FLOAT) if err != nil { return nil, err } val.SetFloat(e) return val, nil case float64: val, err := ValueInit(TYPE_DOUBLE) if err != nil { return nil, err } val.SetDouble(e) return val, nil case string: val, err := ValueInit(TYPE_STRING) if err != nil { return nil, err } val.SetString(e) return val, nil case *Object: val, err := ValueInit(TYPE_OBJECT) if err != nil { return nil, err } val.SetInstance(uintptr(unsafe.Pointer(e.GObject))) return val, nil default: /* Try this since above doesn't catch constants under other types */ rval := reflect.ValueOf(v) switch rval.Kind() { case reflect.Int8: val, err := ValueInit(TYPE_CHAR) if err != nil { return nil, err } val.SetSChar(int8(rval.Int())) return val, nil case reflect.Int16: return nil, errors.New("Type not implemented") case reflect.Int32: return nil, errors.New("Type not implemented") case reflect.Int64: val, err := ValueInit(TYPE_INT64) if err != nil { return nil, err } val.SetInt64(rval.Int()) return val, nil case reflect.Int: val, err := ValueInit(TYPE_INT) if err != nil { return nil, err } val.SetInt(int(rval.Int())) return val, nil case reflect.Uintptr, reflect.Ptr: val, err := ValueInit(TYPE_POINTER) if err != nil { return nil, err } val.SetPointer(rval.Pointer()) return val, nil } } return nil, errors.New("Type not implemented") } // GValueMarshaler is a marshal function to convert a GValue into an // appropriate Go type. The uintptr parameter is a *C.GValue. type GValueMarshaler func(uintptr) (interface{}, error) // TypeMarshaler represents an actual type and it's associated marshaler. type TypeMarshaler struct { T Type F GValueMarshaler } // RegisterGValueMarshalers adds marshalers for several types to the // internal marshalers map. Once registered, calling GoValue on any // Value with a registered type will return the data returned by the // marshaler. func RegisterGValueMarshalers(tm []TypeMarshaler) { gValueMarshalers.register(tm) } type marshalMap map[Type]GValueMarshaler // gValueMarshalers is a map of Glib types to functions to marshal a // GValue to a native Go type. var gValueMarshalers = marshalMap{ TYPE_INVALID: marshalInvalid, TYPE_NONE: marshalNone, TYPE_INTERFACE: marshalInterface, TYPE_CHAR: marshalChar, TYPE_UCHAR: marshalUchar, TYPE_BOOLEAN: marshalBoolean, TYPE_INT: marshalInt, TYPE_LONG: marshalLong, TYPE_ENUM: marshalEnum, TYPE_INT64: marshalInt64, TYPE_UINT: marshalUint, TYPE_ULONG: marshalUlong, TYPE_FLAGS: marshalFlags, TYPE_UINT64: marshalUint64, TYPE_FLOAT: marshalFloat, TYPE_DOUBLE: marshalDouble, TYPE_STRING: marshalString, TYPE_POINTER: marshalPointer, TYPE_BOXED: marshalBoxed, TYPE_OBJECT: marshalObject, TYPE_VARIANT: marshalVariant, } func (m marshalMap) register(tm []TypeMarshaler) { for i := range tm { m[tm[i].T] = tm[i].F } } func (m marshalMap) lookup(v *Value) (GValueMarshaler, error) { actual, fundamental, err := v.Type() if err != nil { return nil, err } if f, ok := m[actual]; ok { return f, nil } if f, ok := m[fundamental]; ok { return f, nil } return nil, errors.New("missing marshaler for type") } func (m marshalMap) lookupType(t Type) (GValueMarshaler, error) { if f, ok := m[Type(t)]; ok { return f, nil } return nil, errors.New("missing marshaler for type") } func marshalInvalid(uintptr) (interface{}, error) { return nil, errors.New("invalid type") } func marshalNone(uintptr) (interface{}, error) { return nil, nil } func marshalInterface(uintptr) (interface{}, error) { return nil, errors.New("interface conversion not yet implemented") } func marshalChar(p uintptr) (interface{}, error) { c := ( /*line :1157:7*/_Cfunc_g_value_get_schar /*line :1157:25*/)((* /*line :1157:29*/_Ctype_GValue /*line :1157:37*/)(unsafe.Pointer(p))) return int8(c), nil } func marshalUchar(p uintptr) (interface{}, error) { c := ( /*line :1162:7*/_Cfunc_g_value_get_uchar /*line :1162:25*/)((* /*line :1162:29*/_Ctype_GValue /*line :1162:37*/)(unsafe.Pointer(p))) return uint8(c), nil } func marshalBoolean(p uintptr) (interface{}, error) { c := ( /*line :1167:7*/_Cfunc_g_value_get_boolean /*line :1167:27*/)((* /*line :1167:31*/_Ctype_GValue /*line :1167:39*/)(unsafe.Pointer(p))) return gobool(c), nil } func marshalInt(p uintptr) (interface{}, error) { c := ( /*line :1172:7*/_Cfunc_g_value_get_int /*line :1172:23*/)((* /*line :1172:27*/_Ctype_GValue /*line :1172:35*/)(unsafe.Pointer(p))) return int(c), nil } func marshalLong(p uintptr) (interface{}, error) { c := ( /*line :1177:7*/_Cfunc_g_value_get_long /*line :1177:24*/)((* /*line :1177:28*/_Ctype_GValue /*line :1177:36*/)(unsafe.Pointer(p))) return int(c), nil } func marshalEnum(p uintptr) (interface{}, error) { c := ( /*line :1182:7*/_Cfunc_g_value_get_enum /*line :1182:24*/)((* /*line :1182:28*/_Ctype_GValue /*line :1182:36*/)(unsafe.Pointer(p))) return int(c), nil } func marshalInt64(p uintptr) (interface{}, error) { c := ( /*line :1187:7*/_Cfunc_g_value_get_int64 /*line :1187:25*/)((* /*line :1187:29*/_Ctype_GValue /*line :1187:37*/)(unsafe.Pointer(p))) return int64(c), nil } func marshalUint(p uintptr) (interface{}, error) { c := ( /*line :1192:7*/_Cfunc_g_value_get_uint /*line :1192:24*/)((* /*line :1192:28*/_Ctype_GValue /*line :1192:36*/)(unsafe.Pointer(p))) return uint(c), nil } func marshalUlong(p uintptr) (interface{}, error) { c := ( /*line :1197:7*/_Cfunc_g_value_get_ulong /*line :1197:25*/)((* /*line :1197:29*/_Ctype_GValue /*line :1197:37*/)(unsafe.Pointer(p))) return uint(c), nil } func marshalFlags(p uintptr) (interface{}, error) { c := ( /*line :1202:7*/_Cfunc_g_value_get_flags /*line :1202:25*/)((* /*line :1202:29*/_Ctype_GValue /*line :1202:37*/)(unsafe.Pointer(p))) return uint(c), nil } func marshalUint64(p uintptr) (interface{}, error) { c := ( /*line :1207:7*/_Cfunc_g_value_get_uint64 /*line :1207:26*/)((* /*line :1207:30*/_Ctype_GValue /*line :1207:38*/)(unsafe.Pointer(p))) return uint64(c), nil } func marshalFloat(p uintptr) (interface{}, error) { c := ( /*line :1212:7*/_Cfunc_g_value_get_float /*line :1212:25*/)((* /*line :1212:29*/_Ctype_GValue /*line :1212:37*/)(unsafe.Pointer(p))) return float32(c), nil } func marshalDouble(p uintptr) (interface{}, error) { c := ( /*line :1217:7*/_Cfunc_g_value_get_double /*line :1217:26*/)((* /*line :1217:30*/_Ctype_GValue /*line :1217:38*/)(unsafe.Pointer(p))) return float64(c), nil } func marshalString(p uintptr) (interface{}, error) { c := ( /*line :1222:7*/_Cfunc_g_value_get_string /*line :1222:26*/)((* /*line :1222:30*/_Ctype_GValue /*line :1222:38*/)(unsafe.Pointer(p))) return ( /*line :1223:9*/_Cfunc_GoString /*line :1223:18*/)((* /*line :1223:22*/_Ctype_char /*line :1223:28*/)(c)), nil } func marshalBoxed(p uintptr) (interface{}, error) { c := ( /*line :1227:7*/_Cfunc_g_value_get_boxed /*line :1227:25*/)((* /*line :1227:29*/_Ctype_GValue /*line :1227:37*/)(unsafe.Pointer(p))) return uintptr(unsafe.Pointer(c)), nil } func marshalPointer(p uintptr) (interface{}, error) { c := ( /*line :1232:7*/_Cfunc_g_value_get_pointer /*line :1232:27*/)((* /*line :1232:31*/_Ctype_GValue /*line :1232:39*/)(unsafe.Pointer(p))) return unsafe.Pointer(c), nil } func marshalObject(p uintptr) (interface{}, error) { c := ( /*line :1237:7*/_Cfunc_g_value_get_object /*line :1237:26*/)((* /*line :1237:30*/_Ctype_GValue /*line :1237:38*/)(unsafe.Pointer(p))) return newObject((* /*line :1238:21*/_Ctype_GObject /*line :1238:30*/)(c)), nil } func marshalVariant(p uintptr) (interface{}, error) { c := ( /*line :1242:7*/_Cfunc_g_value_get_variant /*line :1242:27*/)((* /*line :1242:31*/_Ctype_GValue /*line :1242:39*/)(unsafe.Pointer(p))) return newVariant((* /*line :1243:22*/_Ctype_GVariant /*line :1243:32*/)(c)), nil } // 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) { f, err := gValueMarshalers.lookup(v) if err != nil { return nil, err } //No need to add finalizer because it is already done by ValueAlloc and ValueInit rv, err := f(uintptr(unsafe.Pointer(v.native()))) return rv, err } // SetBool is a wrapper around g_value_set_boolean(). func (v *Value) SetBool(val bool) { ( /*line :1266:2*/_Cfunc_g_value_set_boolean /*line :1266:22*/)(v.native(), gbool(val)) } // SetSChar is a wrapper around g_value_set_schar(). func (v *Value) SetSChar(val int8) { ( /*line :1271:2*/_Cfunc_g_value_set_schar /*line :1271:20*/)(v.native(), /*line :1271:34*/_Ctype_gint8 /*line :1271:41*/(val)) } // SetInt64 is a wrapper around g_value_set_int64(). func (v *Value) SetInt64(val int64) { ( /*line :1276:2*/_Cfunc_g_value_set_int64 /*line :1276:20*/)(v.native(), /*line :1276:34*/_Ctype_gint64 /*line :1276:42*/(val)) } // SetInt is a wrapper around g_value_set_int(). func (v *Value) SetInt(val int) { ( /*line :1281:2*/_Cfunc_g_value_set_int /*line :1281:18*/)(v.native(), /*line :1281:32*/_Ctype_gint /*line :1281:38*/(val)) } // SetUChar is a wrapper around g_value_set_uchar(). func (v *Value) SetUChar(val uint8) { ( /*line :1286:2*/_Cfunc_g_value_set_uchar /*line :1286:20*/)(v.native(), /*line :1286:34*/_Ctype_guchar /*line :1286:42*/(val)) } // SetUInt64 is a wrapper around g_value_set_uint64(). func (v *Value) SetUInt64(val uint64) { ( /*line :1291:2*/_Cfunc_g_value_set_uint64 /*line :1291:21*/)(v.native(), /*line :1291:35*/_Ctype_guint64 /*line :1291:44*/(val)) } // SetUInt is a wrapper around g_value_set_uint(). func (v *Value) SetUInt(val uint) { ( /*line :1296:2*/_Cfunc_g_value_set_uint /*line :1296:19*/)(v.native(), /*line :1296:33*/_Ctype_guint /*line :1296:40*/(val)) } // SetFloat is a wrapper around g_value_set_float(). func (v *Value) SetFloat(val float32) { ( /*line :1301:2*/_Cfunc_g_value_set_float /*line :1301:20*/)(v.native(), /*line :1301:34*/_Ctype_gfloat /*line :1301:42*/(val)) } // SetDouble is a wrapper around g_value_set_double(). func (v *Value) SetDouble(val float64) { ( /*line :1306:2*/_Cfunc_g_value_set_double /*line :1306:21*/)(v.native(), /*line :1306:35*/_Ctype_gdouble /*line :1306:44*/(val)) } // SetString is a wrapper around g_value_set_string(). func (v *Value) SetString(val string) { cstr := ( /*line :1311:10*/_Cfunc_CString /*line :1311:18*/)(val) defer func() func() { _cgo0 := /*line :1312:15*/unsafe.Pointer(cstr); return func() { _cgoCheckPointer(_cgo0, nil); /*line :1312:36*/_Cfunc_free(_cgo0); }}()() ( /*line :1313:2*/_Cfunc_g_value_set_string /*line :1313:21*/)(v.native(), (* /*line :1313:37*/_Ctype_gchar /*line :1313:44*/)(cstr)) } // SetInstance is a wrapper around g_value_set_instance(). func (v *Value) SetInstance(instance uintptr) { func() { var _cgo0 *_Ctype_struct__GValue = /*line :1318:25*/v.native(); _cgo1 := _Ctype_gpointer /*line :1318:47*/(instance); _cgoCheckPointer(_cgo1, nil); /*line :1318:58*/_Cfunc_g_value_set_instance(_cgo0, _cgo1); }() } // SetPointer is a wrapper around g_value_set_pointer(). func (v *Value) SetPointer(p uintptr) { func() { var _cgo0 *_Ctype_struct__GValue = /*line :1323:24*/v.native(); _cgo1 := _Ctype_gpointer /*line :1323:46*/(p); _cgoCheckPointer(_cgo1, nil); /*line :1323:50*/_Cfunc_g_value_set_pointer(_cgo0, _cgo1); }() } // GetPointer is a wrapper around g_value_get_pointer(). func (v *Value) GetPointer() unsafe.Pointer { return unsafe.Pointer(( /*line :1328:24*/_Cfunc_g_value_get_pointer /*line :1328:44*/)(v.native())) } // GetString is a wrapper around g_value_get_string(). GetString() // returns a non-nil error if g_value_get_string() returned a NULL // pointer to distinguish between returning a NULL pointer and returning // an empty string. func (v *Value) GetString() (string, error) { c := ( /*line :1336:7*/_Cfunc_g_value_get_string /*line :1336:26*/)(v.native()) if c == nil { return "", nilPtrErr } return ( /*line :1340:9*/_Cfunc_GoString /*line :1340:18*/)((* /*line :1340:22*/_Ctype_char /*line :1340:28*/)(c)), nil } type Signal struct { name string signalId /*line :1345:11*/_Ctype_guint /*line :1345:18*/ } func SignalNew(signalName string) (*Signal, error) { cstr := ( /*line :1349:10*/_Cfunc_CString /*line :1349:18*/)(signalName) defer func() func() { _cgo0 := /*line :1350:15*/unsafe.Pointer(cstr); return func() { _cgoCheckPointer(_cgo0, nil); /*line :1350:36*/_Cfunc_free(_cgo0); }}()() signalId := ( /*line :1352:14*/_Cfunc__g_signal_new /*line :1352:28*/)((* /*line :1352:32*/_Ctype_gchar /*line :1352:39*/)(cstr)) if signalId == 0 { return nil, fmt.Errorf("invalid signal name: %s", signalName) } return &Signal{ name: signalName, signalId: signalId, }, nil } // SignalNewV is a wrapper around g_signal_newv(). // // Parameters: // - signalName : The name for the signal. // - returnType : The type of return value, or TYPE_NONE for a signal without a return value. // - nParams : Amount of extra parameters the signal is going to recieve (the object who emits the signal does not count). // - paramsTypes... : Datatypes of the parameters (amount of elements must match nParams, except when nParams is 0). // If nParams is 0 then paramsTypes has to be TYPE_NONE. // If nParams is 1 then paramsTypes has to be different from TYPE_NONE. func SignalNewV( signalName string, returnType Type, nParams uint, paramsTypes ...Type, ) (*Signal, error) { if nParams == 0 { if paramsTypes[0] != TYPE_NONE || len(paramsTypes) != 1 { return nil, fmt.Errorf("invalid Types: the amount of parameters is %d, paramsTypes must be TYPE_NONE", nParams) } } else if nParams == 1 { if paramsTypes[0] == TYPE_NONE || len(paramsTypes) != 1 { return nil, fmt.Errorf("invalid Types: the amount of parameters is %d, paramsTypes must be different from TYPE_NONE", nParams) } } else { if len(paramsTypes) != int(nParams) { return nil, fmt.Errorf("invalid Types: The amount of elements of paramsTypes has to be equal to %d", nParams) } } cstr := ( /*line :1393:10*/_Cfunc_CString /*line :1393:18*/)(signalName) defer func() func() { _cgo0 := /*line :1394:15*/unsafe.Pointer(cstr); return func() { _cgoCheckPointer(_cgo0, nil); /*line :1394:36*/_Cfunc_free(_cgo0); }}()() var sliceOfGTypes [] /*line :1396:22*/_Ctype_GType /*line :1396:29*/ for _, paramType := range paramsTypes { sliceOfGTypes = append(sliceOfGTypes, /*line :1398:41*/_Ctype_gsize /*line :1398:48*/(paramType)) } signalId := ( /*line :1401:14*/_Cfunc__g_signal_newv /*line :1401:29*/)((* /*line :1401:33*/_Ctype_gchar /*line :1401:40*/)(cstr), /*line :1401:49*/_Ctype_gsize /*line :1401:56*/(returnType), /*line :1401:70*/_Ctype_guint /*line :1401:77*/(nParams), (* /*line :1401:90*/_Ctype_GType /*line :1401:97*/)(&sliceOfGTypes[0])) if signalId == 0 { return nil, fmt.Errorf("invalid signal name: %s", signalName) } return &Signal{ name: signalName, signalId: signalId, }, nil } func (s *Signal) String() string { return s.name } type Quark uint32 // GetPrgname is a wrapper around g_get_prgname(). func GetPrgname() string { c := ( /*line :1421:7*/_Cfunc_g_get_prgname /*line :1421:21*/)() return ( /*line :1423:9*/_Cfunc_GoString /*line :1423:18*/)((* /*line :1423:22*/_Ctype_char /*line :1423:28*/)(c)) } // SetPrgname is a wrapper around g_set_prgname(). func SetPrgname(name string) { cstr := (* /*line :1428:12*/_Ctype_gchar /*line :1428:19*/)(( /*line :1428:21*/_Cfunc_CString /*line :1428:29*/)(name)) defer func() func() { _cgo0 := /*line :1429:15*/unsafe.Pointer(cstr); return func() { _cgoCheckPointer(_cgo0, nil); /*line :1429:36*/_Cfunc_free(_cgo0); }}()() ( /*line :1431:2*/_Cfunc_g_set_prgname /*line :1431:16*/)(cstr) } // GetApplicationName is a wrapper around g_get_application_name(). func GetApplicationName() string { c := ( /*line :1436:7*/_Cfunc_g_get_application_name /*line :1436:30*/)() return ( /*line :1438:9*/_Cfunc_GoString /*line :1438:18*/)((* /*line :1438:22*/_Ctype_char /*line :1438:28*/)(c)) } // SetApplicationName is a wrapper around g_set_application_name(). func SetApplicationName(name string) { cstr := (* /*line :1443:12*/_Ctype_gchar /*line :1443:19*/)(( /*line :1443:21*/_Cfunc_CString /*line :1443:29*/)(name)) defer func() func() { _cgo0 := /*line :1444:15*/unsafe.Pointer(cstr); return func() { _cgoCheckPointer(_cgo0, nil); /*line :1444:36*/_Cfunc_free(_cgo0); }}()() ( /*line :1446:2*/_Cfunc_g_set_application_name /*line :1446:25*/)(cstr) } // InitI18n initializes the i18n subsystem. func InitI18n(domain string, dir string) { domainStr := ( /*line :1451:15*/_Cfunc_CString /*line :1451:23*/)(domain) defer func() func() { _cgo0 := /*line :1452:15*/unsafe.Pointer(domainStr); return func() { _cgoCheckPointer(_cgo0, nil); /*line :1452:41*/_Cfunc_free(_cgo0); }}()() dirStr := ( /*line :1454:12*/_Cfunc_CString /*line :1454:20*/)(dir) defer func() func() { _cgo0 := /*line :1455:15*/unsafe.Pointer(dirStr); return func() { _cgoCheckPointer(_cgo0, nil); /*line :1455:38*/_Cfunc_free(_cgo0); }}()() ( /*line :1457:2*/_Cfunc_init_i18n /*line :1457:12*/)(domainStr, dirStr) } // Local localizes a string using gettext func Local(input string) string { cstr := ( /*line :1462:10*/_Cfunc_CString /*line :1462:18*/)(input) defer func() func() { _cgo0 := /*line :1463:15*/unsafe.Pointer(cstr); return func() { _cgoCheckPointer(_cgo0, nil); /*line :1463:36*/_Cfunc_free(_cgo0); }}()() return ( /*line :1465:9*/_Cfunc_GoString /*line :1465:18*/)(( /*line :1465:20*/_Cfunc_localize /*line :1465:29*/)(cstr)) } // MarkupEscapeText will escape the given text func MarkupEscapeText(input string) string { cstr := ( /*line :1470:10*/_Cfunc_CString /*line :1470:18*/)(input) defer func() func() { _cgo0 := /*line :1471:15*/unsafe.Pointer(cstr); return func() { _cgoCheckPointer(_cgo0, nil); /*line :1471:36*/_Cfunc_free(_cgo0); }}()() return ( /*line :1473:9*/_Cfunc_GoString /*line :1473:18*/)(( /*line :1473:20*/_Cfunc_g_markup_escape_text /*line :1473:41*/)(cstr, -1)) }