Debian Codegraph @

pkg/glibobject/gobject.go

raw
1 /*
2 * Copyright (c) 2013 Conformal Systems <[email protected]>
3 *
4 * This file originated from: http://opensource.conformal.com/
5 *
6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18
19 package glibobject
20
21 // #cgo pkg-config: glib-2.0 gobject-2.0
22 // #include <glib.h>
23 // #include <glib-object.h>
24 // #include <gio/gio.h>
25 // #include "glibobject.go.h"
26 // #include <stdlib.h>
27 import "C"
28 import (
29 "unsafe"
30 )
31
32 /*
33 * GObject
34 */
35
36 // IObject is an interface type implemented by Object and all types which embed
37 // an Object. It is meant to be used as a type for function arguments which
38 // require GObjects or any subclasses thereof.
39 type IObject interface {
40 toGObject() *C.GObject
41 ToObject() *GObject
42 }
43
44 // GObject is a representation of GLib's GObject.
45 type GObject struct {
46 ptr unsafe.Pointer
47 }
48
49 func (v *GObject) Ptr() unsafe.Pointer {
50 return v.ptr
51 }
52
53 func (v *GObject) native() *C.GObject {
54 if v == nil {
55 return nil
56 }
57 return (*C.GObject)(v.ptr)
58 }
59
60 func (v *GObject) Ref() {
61 C.g_object_ref(C.gpointer(v.Ptr()))
62 }
63
64 func (v *GObject) Unref() {
65 C.g_object_unref(C.gpointer(v.Ptr()))
66 }
67
68 func (v *GObject) RefSink() {
69 C.g_object_ref_sink(C.gpointer(v.native()))
70 }
71
72 func (v *GObject) IsFloating() bool {
73 c := C.g_object_is_floating(C.gpointer(v.native()))
74 return GoBool(GBoolean(c))
75 }
76
77 func (v *GObject) ForceFloating() {
78 C.g_object_force_floating(v.native())
79 }