Move foreign library loading to gobject.init.lisp; separated gobject.type-info packag...
[cl-gtk2.git] / glib / gobject.gobject-query.lisp
1 (in-package :gobject)
2
3 (defstruct g-class-property-definition
4   "Structure describing property of a GObject class.
5
6 See accessor functions:
7 @itemize{
8 @item{@fun{g-class-property-definition-name}}
9 @item{@fun{g-class-property-definition-type}}
10 @item{@fun{g-class-property-definition-readable}}
11 @item{@fun{g-class-property-definition-writable}}
12 @item{@fun{g-class-property-definition-constructor}}
13 @item{@fun{g-class-property-definition-constructor-only}}
14 @item{@fun{g-class-property-definition-owner-type}}
15 }
16 "
17   name
18   type
19   readable
20   writable
21   constructor
22   constructor-only
23   owner-type)
24
25 (setf (documentation 'g-class-property-definition-name 'function)
26       "Name of GObject class property. See @class{g-class-property-definition}.
27 @return{a string}")
28
29 (setf (documentation 'g-class-property-definition-type 'function)
30       "Type of GObject class property. See @class{g-class-property-definition}.
31 @return{a GType (integer)}")
32
33 (setf (documentation 'g-class-property-definition-readable 'function)
34       "Whether the GObject class property is readable. See @class{g-class-property-definition}.
35 @return{a boolean}")
36
37 (setf (documentation 'g-class-property-definition-writable 'function)
38       "Whether the GObject class property is writable. See @class{g-class-property-definition}.
39 @return{a boolean}")
40
41 (setf (documentation 'g-class-property-definition-constructor 'function)
42       "Whether the GObject class property can be set at object construction time. See @class{g-class-property-definition}.
43 @return{a boolean}")
44
45 (setf (documentation 'g-class-property-definition-constructor-only 'function)
46       "Whether the GObject class property can only be set at object construction time. See @class{g-class-property-definition}.
47 @return{a boolean}")
48
49 (setf (documentation 'g-class-property-definition-owner-type 'function)
50       "The GType on which this GObject class property was defined. See @class{g-class-property-definition}.
51 @return{a GType (integer)}")
52
53 (defun parse-g-param-spec (param)
54   (let ((flags (foreign-slot-value param 'g-param-spec 'flags)))
55     (make-g-class-property-definition
56      :name (foreign-slot-value param 'g-param-spec
57                                'name)
58      :type (foreign-slot-value param 'g-param-spec
59                                'value-type)
60      :readable (not (null (member :readable flags)))
61      :writable (not (null (member :writable flags)))
62      :constructor (not (null (member :construct flags)))
63      :constructor-only (not (null (member :construct-only flags)))
64      :owner-type (foreign-slot-value param 'g-param-spec
65                                      'owner-type))))
66
67 (defun class-properties (g-type)
68   "@return{list of properties of GObject class @code{g-type}. Each property is described by an object of type @class{g-class-property-definition}.}
69 @arg[g-type]{an integer or a string specifying the GType}"
70   (setf g-type (ensure-g-type g-type))
71   (let ((g-class (g-type-class-ref g-type)))
72     (unwind-protect
73          (with-foreign-object (n-properties :uint)
74            (let ((params (g-object-class-list-properties g-class n-properties)))
75              (unwind-protect
76                   (loop
77                      for i from 0 below (mem-ref n-properties :uint)
78                      for param = (mem-aref params :pointer i)
79                      collect (parse-g-param-spec param))
80                (g-free params))))
81       (g-type-class-unref g-class))))
82
83 (defun class-parent (type)
84   (g-type-parent (ensure-g-type type)))
85
86 (defun interface-properties (g-type)
87 "@return{list of properties of GObject interface @code{g-type}. Each property is described by an object of type @class{g-class-property-definition}.}
88 @arg[g-type]{an integer or a string specifying the GType}"
89   (setf g-type (ensure-g-type g-type))
90   (let ((g-iface (g-type-default-interface-ref g-type)))
91     (unwind-protect
92          (with-foreign-object (n-properties :uint)
93            (let ((params (g-object-interface-list-properties g-iface n-properties)))
94              (unwind-protect
95                   (loop
96                      for i from 0 below (mem-ref n-properties :uint)
97                      for param = (mem-aref params :pointer i)
98                      for flags = (foreign-slot-value param 'g-param-spec 'flags)
99                      collect (make-g-class-property-definition
100                               :name (foreign-slot-value param 'g-param-spec
101                                                         'name)
102                               :type (foreign-slot-value param 'g-param-spec
103                                                         'value-type)
104                               :readable (not (null (member :readable flags)))
105                               :writable (not (null (member :writable flags)))
106                               :constructor (not (null (member :construct flags)))
107                               :constructor-only (not (null (member :construct-only flags)))
108                               :owner-type (foreign-slot-value param 'g-param-spec
109                                                               'owner-type)))
110                (g-free params))))
111       (g-type-default-interface-unref g-iface))))
112
113 (defstruct enum-item
114   "A structure describing a single enumeration item.
115
116 See accessor functions:
117 @itemize{
118 @item{@fun{enum-item-name}}
119 @item{@fun{enum-item-value}}
120 @item{@fun{enum-item-nick}}
121 }"
122   name value nick)
123
124 (setf (documentation 'enum-item-name 'function)
125       "The C name of enum item, e.g. \"GTK_WINDOW_TOPLEVEL\".
126 @return{a string}")
127
128 (setf (documentation 'enum-item-value 'function)
129       "The numeric value of enum item.
130 @return{an integer}")
131
132 (setf (documentation 'enum-item-nick 'function)
133       "The \"nickname\" of enum item. Nickname is a short name of enum item. E.g., \"toplevel\".
134 @return{a string}")
135
136 (defun get-enum-items (type)
137   "Gets the list of enum items that belong to GEnum type @code{type}
138 @arg[type]{a string or an integer specifying GEnum type}
139 @return{a list of @class{enum-item} objects}"
140   (let ((g-class (g-type-class-ref (ensure-g-type type))))
141     (unwind-protect
142          (loop
143             with n = (foreign-slot-value g-class 'g-enum-class 'n-values)
144             with values = (foreign-slot-value g-class 'g-enum-class 'values)
145             for i from 0 below n
146             for enum-value = (mem-aref values 'g-enum-value i)
147             collect (make-enum-item
148                      :name (foreign-slot-value enum-value 'g-enum-value
149                                                'name)
150                      :value (foreign-slot-value enum-value 'g-enum-value
151                                                 'value)
152                      :nick (foreign-slot-value enum-value 'g-enum-value
153                                                'nick)))
154       (g-type-class-unref g-class))))
155
156 (defstruct flags-item
157   "A structure describing a single flags item.
158
159 See accessor functions:
160 @itemize{
161 @item{@fun{flags-item-name}}
162 @item{@fun{flags-item-value}}
163 @item{@fun{flags-item-nick}}
164 }"
165   name value nick)
166
167 (setf (documentation 'flags-item-name 'function)
168       "The C name of flags item, e.g. \"GDK_PROPERTY_CHANGE_MASK\".
169 @return{a string}")
170
171 (setf (documentation 'flags-item-value 'function)
172       "The numeric value of flags item.
173 @return{an integer}")
174
175 (setf (documentation 'flags-item-nick 'function)
176       "The \"nickname\" of flags item. Nickname is a short name of flags item. E.g., \"property-change-mask\".
177 @return{a string}")
178
179 (defun get-flags-items (type)
180   "Gets the list of flags items that belong to GFlags type @code{type}
181 @arg[type]{a string or an integer specifying GFlags type}
182 @return{a list of @class{flags-item} objects}"
183   (let ((g-class (g-type-class-ref (ensure-g-type type))))
184     (unwind-protect
185          (loop
186             with n = (foreign-slot-value g-class 'g-flags-class 'n-values)
187             with values = (foreign-slot-value g-class 'g-flags-class 'values)
188             for i from 0 below n
189             for flags-value = (mem-aref values 'g-flags-value i)
190             collect (make-flags-item
191                      :name (foreign-slot-value flags-value 'g-flags-value
192                                                'name)
193                      :value (foreign-slot-value flags-value 'g-flags-value
194                                                 'value)
195                      :nick (foreign-slot-value flags-value 'g-flags-value
196                                                'nick)))
197       (g-type-class-unref g-class))))