1
1
abstract GObjectI
2
2
typealias GObject GObjectI
3
3
4
+ typealias Enum Int32
5
+ typealias GType Csize_t
6
+ immutable GParamSpec
7
+ g_type_instance:: Ptr{Void}
8
+ name:: Ptr{Uint8}
9
+ flags:: Cint
10
+ value_type:: GType
11
+ owner_type:: GType
12
+ end
13
+
14
+ const fundamental_types = (
15
+ # (:name, Ctype, JuliaType, g_value_fn)
16
+ # (:invalid, Void, Void, :error),
17
+ # (:void, Nothing, Nothing, :error),
18
+ # (:GInterface, Ptr{Void}, None, :???),
19
+ (:gchar , Int8, Int8, :schar ),
20
+ (:guchar , Uint8, Uint8, :uchar ),
21
+ (:gboolean , Cint, Bool, :boolean ),
22
+ (:gint , Cint, None, :int ),
23
+ (:guint , Cuint, None, :uint ),
24
+ (:glong , Clong, None, :long ),
25
+ (:gulong , Culong, None, :ulong ),
26
+ (:gint64 , Int64, Signed, :int64 ),
27
+ (:guint64 , Uint64, Unsigned, :uint64 ),
28
+ (:GEnum , Enum, None, :enum ),
29
+ (:GFlags , Enum, None, :flags ),
30
+ (:gfloat , Float32, Float32, :float ),
31
+ (:gdouble , Float64, FloatingPoint, :double ),
32
+ (:gchararray , Ptr{Uint8}, String, :string ),
33
+ (:gpointer , Ptr{Void}, Ptr, :pointer ),
34
+ (:GBoxed , Ptr{Void}, None, :boxed ),
35
+ (:GParam , Ptr{GParamSpec}, Ptr{GParamSpec},:param ),
36
+ (:GObject , Ptr{GObject}, GObject, :object ),
37
+ (:GType , Int, None, :gtype ),
38
+ # (:GVariant, Ptr{GVariant}, GVariant, :variant),
39
+ )
40
+ # NOTE: in general do not cache ids, except for the fundamental values
41
+ g_type_from_name (name:: Symbol ) = ccall ((:g_type_from_name ,libgobject),Int,(Ptr{Uint8},),name)
42
+ # these constants are used elsewhere
43
+ const gvoid_id = g_type_from_name (:void )
44
+ const gboxed_id = g_type_from_name (:GBoxed )
45
+ const gobject_id = g_type_from_name (:GObject )
46
+ const gstring_id = g_type_from_name (:gchararray )
47
+
48
+ G_TYPE_FROM_CLASS (w:: Ptr{Void} ) = unsafe_load (convert (Ptr{GType},w))
49
+ G_OBJECT_GET_CLASS (w:: GObject ) = G_OBJECT_GET_CLASS (w. handle)
50
+ G_OBJECT_GET_CLASS (hnd:: Ptr{GObjectI} ) = unsafe_load (convert (Ptr{Ptr{Void}},hnd))
51
+ G_OBJECT_CLASS_TYPE (w) = G_TYPE_FROM_CLASS (G_OBJECT_GET_CLASS (w))
52
+
53
+ g_type_parent (child:: GType ) = ccall ((:g_type_parent , libgobject), GType, (GType,), child)
54
+ g_type_name (g_type:: GType ) = bytestring (ccall ((:g_type_name ,libgobject),Ptr{Uint8},(GType,),g_type))
55
+
56
+ g_type_test_flags (g_type:: GType , flag) = ccall ((:g_type_test_flags ,libgobject), Bool, (GType,Enum), g_type, flag)
57
+ const G_TYPE_FLAG_CLASSED = 1 << 0
58
+ const G_TYPE_FLAG_INSTANTIATABLE = 1 << 1
59
+ const G_TYPE_FLAG_DERIVABLE = 1 << 2
60
+ const G_TYPE_FLAG_DEEP_DERIVABLE = 1 << 3
4
61
# Alternative object construction style. This would let us share constructors
5
62
# by creating const aliases: `const Z = GObject{:Z}`
6
63
type GObjectAny{Name} <: GObjectI
11
68
# handle::Ptr{GObject}
12
69
# GtkWidgetAny(handle::Ptr{GObject}) = gc_ref(new(handle))
13
70
# end
14
- # type GtkContainerAny{T} <: GtkContainerI
15
- # handle::Ptr{GObject}
16
- # GtkContainerAny(handle::Ptr{GObject}) = gc_ref(new(handle))
17
- # end
18
- # type GtkBinAny{T} <: GtkBinI
19
- # handle::Ptr{GObject}
20
- # GtkBinAny(handle::Ptr{GObject}) = gc_ref(new(handle))
21
- # end
22
- # type GtkBoxAny{T} <: GtkBoxI
23
- # handle::Ptr{GObject}
24
- # GtkBoxAny(handle::Ptr{GObject}) = gc_ref(new(handle))
25
- # end
26
71
27
- macro GType (gname)
28
- if isa (gname,Expr)
29
- @assert (gname. head == :comparison && length (gname. args) == 3 && gname. args[2 ] == :< :, " invalid GType expr" )
30
- super = gname. args[3 ]
31
- gname = gname. args[1 ]
32
- else
33
- super = :GObject
72
+ const gtype_ifaces = Dict {Symbol,Type} ()
73
+ const gtype_wrappers = Dict {Symbol,Type} ()
74
+
75
+ gtype_ifaces[:GObject ] = GObjectI
76
+
77
+ function get_iface (name:: Symbol ,g_type)
78
+ if haskey (gtype_ifaces,name)
79
+ return gtype_ifaces[name]
34
80
end
35
- gname = gname:: Symbol
36
- quote
37
- type $ (esc (gname)) <: $ (esc (symbol (string (super,' I' ))))
81
+ parent = g_type_parent (g_type)
82
+ pname = g_type_name (parent)
83
+ piface = get_iface (symbol (pname),parent)
84
+ iname = symbol (" $(name) I" )
85
+ iface = eval (:(abstract ($ iname) <: $ (piface); $ iname))
86
+ gtype_ifaces[name] = iface
87
+ iface
88
+ end
89
+
90
+ function get_wrapper (name,g_type)
91
+ if haskey (gtype_wrappers,name)
92
+ return gtype_wrappers[name]
93
+ end
94
+ if ! g_type_test_flags (g_type, G_TYPE_FLAG_CLASSED)
95
+ error (" not implemented yet" )
96
+ end
97
+ iface = get_iface (name,g_type)
98
+
99
+ wrapper = eval (quote
100
+ # TODO : check if instantiable
101
+ type ($ name) <: ($iface)
38
102
handle:: Ptr{GObjectI}
39
- $ (esc (gname))(handle:: Ptr{GObjectI} ) = (handle != C_NULL ? gc_ref (new (handle)) : error (" Cannot construct $gname with a NULL pointer" ))
40
- end
103
+ $ name (handle:: Ptr{GObjectI} ) = (handle != C_NULL ? GLib. gc_ref (new (handle)) : error ($ (" Cannot construct $name with a NULL pointer" )))
104
+ end # FIXME
105
+ $ name
106
+ end )
107
+ gtype_wrappers[name] = wrapper
108
+ wrapper
109
+ end
110
+
111
+ macro Gtype (name,lib,symname)
112
+ iname = symbol (" $(name) I" )
113
+ quote
114
+ g_type = ccall (($ (" $(symname) _get_type" ), $ lib), GType, ())
115
+ const $ (esc (iname)) = get_iface ($ (Meta. quot (name)),g_type)
116
+ const $ (esc (name)) = get_wrapper ($ (Meta. quot (name)),g_type)
117
+ end
118
+ end
119
+
120
+ macro Gabstract (name,lib,symname)
121
+ @assert endswith (string (name)," I" )
122
+ typename = symbol (string (name)[1 : end - 1 ])
123
+ quote
124
+ g_type = ccall (($ (" $(symname) _get_type" ), $ lib), GType, ())
125
+ const $ (esc (name)) = get_iface ($ (Meta. quot (typename)),g_type)
41
126
end
42
127
end
43
128
@@ -64,7 +149,6 @@ show(io::IO, w::GObjectI) = print(io,typeof(w))
64
149
65
150
66
151
# ## Miscellaneous types
67
- typealias Enum Int32
68
152
baremodule GConnectFlags
69
153
const AFTER = 1
70
154
const SWAPPED = 2
0 commit comments