Mercurial > projects > dynamin
comparison dynamin/c/glib.d @ 18:836a064828e8
Implement FileDialog/DirectoryDialog with GTK
and start a glib/gdk/gtk binding. Add invoke/invokeNow stubs to fix build on X.
author | Jordan Miner <jminer7@gmail.com> |
---|---|
date | Fri, 24 Jul 2009 00:35:42 -0500 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
17:ef81af74a306 | 18:836a064828e8 |
---|---|
1 module dynamin.c.glib; | |
2 | |
3 /* | |
4 * A binding to at least the part of Glib that Dynamin uses. | |
5 */ | |
6 | |
7 import tango.sys.SharedLib; | |
8 | |
9 extern(C): | |
10 | |
11 //{{{ gtypes | |
12 static if((void*).sizeof == 4) { | |
13 alias uint gsize; | |
14 } else static if((void*).sizeof == 8) { | |
15 alias ulong gsize; | |
16 } | |
17 alias char gchar; | |
18 alias short gshort; | |
19 alias int glong; | |
20 alias int gint; | |
21 alias gint gboolean; | |
22 | |
23 alias ubyte guchar; | |
24 alias ushort gushort; | |
25 alias uint gulong; | |
26 alias uint guint; | |
27 | |
28 alias float gfloat; | |
29 alias double gdouble; | |
30 | |
31 alias byte gint8; | |
32 alias ubyte guint8; | |
33 alias short gint16; | |
34 alias ushort guint16; | |
35 alias int gint32; | |
36 alias uint guint32; | |
37 alias long gint64; | |
38 alias ulong guint64; | |
39 | |
40 enum : gint8 { | |
41 G_MININT8 = cast(gint8)0x80, | |
42 G_MAXINT8 = 0x7f | |
43 } | |
44 enum : guint8 { | |
45 G_MAXUINT8 = 0xff | |
46 } | |
47 enum : gint16 { | |
48 G_MININT16 = cast(gint16)0x8000, | |
49 G_MAXINT16 = 0x7fff | |
50 } | |
51 enum : guint16 { | |
52 G_MAXUINT16 = 0xffff | |
53 } | |
54 | |
55 enum : gint32 { | |
56 G_MININT32 = 0x80000000, | |
57 G_MAXINT32 = 0x7fffffff | |
58 } | |
59 enum : guint32 { | |
60 G_MAXUINT32 = 0xffffffff | |
61 } | |
62 | |
63 enum : gint64 { | |
64 G_MININT64 = 0x8000000000000000, | |
65 G_MAXINT64 = 0x7fffffffffffffff | |
66 } | |
67 enum : guint64 { | |
68 G_MAXUINT64 = 0xffffffffffffffffU | |
69 } | |
70 | |
71 | |
72 alias void* gpointer; | |
73 alias /*const*/ void* gconstpointer; | |
74 | |
75 alias gint function(gconstpointer a, gconstpointer b) GCompareFunc; | |
76 alias gint function(gconstpointer a, gconstpointer b, | |
77 gpointer user_data) GCompareDataFunc; | |
78 alias gboolean function(gconstpointer a, gconstpointer b) GEqualFunc; | |
79 alias void function(gpointer data) GDestroyNotify; | |
80 alias void function(gpointer data, gpointer user_data) GFunc; | |
81 alias guint function(gconstpointer key) GHashFunc; | |
82 alias void function(gpointer key, gpointer value, | |
83 gpointer user_data) GHFunc; | |
84 alias void function(gpointer data) GFreeFunc; | |
85 alias /*const*/ gchar* function(/*const*/ gchar* str, | |
86 gpointer data) GTranslateFunc; | |
87 | |
88 const real G_E = 2.7182818284590452353602874713526624977572470937000; | |
89 const real G_LN2 = 0.69314718055994530941723212145817656807550013436026; | |
90 const real G_LN10 = 2.3025850929940456840179914546843642076011014886288; | |
91 const real G_PI = 3.1415926535897932384626433832795028841971693993751; | |
92 const real G_PI_2 = 1.5707963267948966192313216916397514420985846996876; | |
93 const real G_PI_4 = 0.78539816339744830961566084581987572104929234984378; | |
94 const real G_SQRT2 = 1.4142135623730950488016887242096980785696718753769; | |
95 | |
96 version(LittleEndian) { | |
97 enum { | |
98 G_BYTE_ORDER = 1234 | |
99 } | |
100 } else { | |
101 enum { | |
102 G_BYTE_ORDER = 4321 | |
103 } | |
104 } | |
105 enum { | |
106 G_LITTLE_ENDIAN = 1234, | |
107 G_BIG_ENDIAN = 4321 | |
108 } | |
109 //}}} | |
110 | |
111 //{{{ gtype | |
112 const G_TYPE_FUNDAMENTAL_SHIFT = 2; | |
113 const G_TYPE_FUNDAMENTAL_MAX = 255 << G_TYPE_FUNDAMENTAL_SHIFT; | |
114 GType G_TYPE_MAKE_FUNDAMENTAL(uint x) { | |
115 return x << G_TYPE_FUNDAMENTAL_SHIFT; | |
116 } | |
117 enum { | |
118 G_TYPE_INVALID = 0 << G_TYPE_FUNDAMENTAL_SHIFT, | |
119 G_TYPE_NONE = 1 << G_TYPE_FUNDAMENTAL_SHIFT, | |
120 G_TYPE_INTERFACE = 2 << G_TYPE_FUNDAMENTAL_SHIFT, | |
121 G_TYPE_CHAR = 3 << G_TYPE_FUNDAMENTAL_SHIFT, | |
122 G_TYPE_UCHAR = 4 << G_TYPE_FUNDAMENTAL_SHIFT, | |
123 G_TYPE_BOOLEAN = 5 << G_TYPE_FUNDAMENTAL_SHIFT, | |
124 G_TYPE_INT = 6 << G_TYPE_FUNDAMENTAL_SHIFT, | |
125 G_TYPE_UINT = 7 << G_TYPE_FUNDAMENTAL_SHIFT, | |
126 G_TYPE_LONG = 8 << G_TYPE_FUNDAMENTAL_SHIFT, | |
127 G_TYPE_ULONG = 9 << G_TYPE_FUNDAMENTAL_SHIFT, | |
128 G_TYPE_INT64 = 10 << G_TYPE_FUNDAMENTAL_SHIFT, | |
129 G_TYPE_UINT64 = 11 << G_TYPE_FUNDAMENTAL_SHIFT, | |
130 G_TYPE_ENUM = 12 << G_TYPE_FUNDAMENTAL_SHIFT, | |
131 G_TYPE_FLAGS = 13 << G_TYPE_FUNDAMENTAL_SHIFT, | |
132 G_TYPE_FLOAT = 14 << G_TYPE_FUNDAMENTAL_SHIFT, | |
133 G_TYPE_DOUBLE = 15 << G_TYPE_FUNDAMENTAL_SHIFT, | |
134 G_TYPE_STRING = 16 << G_TYPE_FUNDAMENTAL_SHIFT, | |
135 G_TYPE_POINTER = 17 << G_TYPE_FUNDAMENTAL_SHIFT, | |
136 G_TYPE_BOXED = 18 << G_TYPE_FUNDAMENTAL_SHIFT, | |
137 G_TYPE_PARAM = 19 << G_TYPE_FUNDAMENTAL_SHIFT, | |
138 G_TYPE_OBJECT = 20 << G_TYPE_FUNDAMENTAL_SHIFT, | |
139 } | |
140 const G_TYPE_RESERVED_GLIB_FIRST = 21; | |
141 const G_TYPE_RESERVED_GLIB_LAST = 31; | |
142 const G_TYPE_RESERVED_BSE_FIRST = 32; | |
143 const G_TYPE_RESERVED_BSE_LAST = 48; | |
144 const G_TYPE_RESERVED_USER_FIRST = 49; | |
145 | |
146 bool G_TYPE_IS_FUNDAMENTAL(GType type) { | |
147 return type <= G_TYPE_FUNDAMENTAL_MAX; | |
148 } | |
149 bool G_TYPE_IS_DERIVED(GType type) { | |
150 return type > G_TYPE_FUNDAMENTAL_MAX; | |
151 } | |
152 /*bool G_TYPE_IS_INTERFACE(GType type) { | |
153 return G_TYPE_FUNDAMENTAL(type) == G_TYPE_INTERFACE; | |
154 } | |
155 bool G_TYPE_IS_CLASSED(GType type) { | |
156 return g_type_test_flags(type, G_TYPE_FLAG_CLASSED); | |
157 } | |
158 bool G_TYPE_IS_INSTANTIATABLE(GType type) { | |
159 return g_type_test_flags(type, G_TYPE_FLAG_INSTANTIATABLE); | |
160 } | |
161 bool G_TYPE_IS_DERIVABLE(GType type) { | |
162 return g_type_test_flags(type, G_TYPE_FLAG_DERIVABLE); | |
163 } | |
164 bool G_TYPE_IS_DEEP_DERIVABLE(GType type) { | |
165 return g_type_test_flags(type, G_TYPE_FLAG_DEEP_DERIVABLE); | |
166 } | |
167 bool G_TYPE_IS_ABSTRACT(GType type) { | |
168 return g_type_test_flags(type, G_TYPE_FLAG_ABSTRACT); | |
169 } | |
170 bool G_TYPE_IS_VALUE_ABSTRACT(GType type) { | |
171 return g_type_test_flags(type, G_TYPE_FLAG_VALUE_ABSTRACT); | |
172 } | |
173 bool G_TYPE_IS_VALUE_TYPE(GType type) { | |
174 return g_type_check_is_value_type(type); | |
175 } | |
176 bool G_TYPE_HAS_VALUE_TABLE(GType type) { | |
177 return g_type_value_table_peek(type) != NULL; | |
178 } | |
179 */ | |
180 alias gsize GType; | |
181 | |
182 struct GTypeClass { | |
183 GType g_type; | |
184 } | |
185 struct GTypeInstance { | |
186 GTypeClass* g_class; | |
187 } | |
188 struct GTypeInterface { | |
189 GType g_type; | |
190 GType g_instance_type; | |
191 } | |
192 struct GTypeQuery { | |
193 GType type; | |
194 /*const*/ gchar* type_name; | |
195 guint class_size; | |
196 guint instance_size; | |
197 } | |
198 | |
199 // plus a lot more | |
200 //GType function(GType type_id) g_type_fundamental; | |
201 //alias g_type_fundamental G_TYPE_FUNDAMENTAL; | |
202 gboolean function(GType type, guint flags) g_type_test_flags; | |
203 //}}} | |
204 | |
205 //{{{ gquark | |
206 typedef guint32 GQuark; | |
207 | |
208 GQuark function(/*const*/ gchar* string) g_quark_try_string; | |
209 GQuark function(/*const*/ gchar* string) g_quark_from_static_string; | |
210 GQuark function(/*const*/ gchar* string) g_quark_from_string; | |
211 gchar* function(GQuark quark) g_quark_to_string; | |
212 | |
213 gchar* function(/*const*/ gchar* string) g_intern_string; | |
214 gchar* function(/*const*/ gchar* string) g_intern_static_string; | |
215 //}}} | |
216 | |
217 //{{{ gerror | |
218 struct GError { | |
219 GQuark domain; | |
220 gint code; | |
221 gchar* message; | |
222 } | |
223 | |
224 GError* function(GQuark domain, | |
225 gint code, | |
226 /*const*/ gchar* format, | |
227 ...) g_error_new; | |
228 | |
229 GError* function(GQuark domain, | |
230 gint code, | |
231 /*const*/ gchar* message) g_error_new_literal; | |
232 | |
233 void function(GError* error) g_error_free; | |
234 GError* function(/*const*/ GError* error) g_error_copy; | |
235 | |
236 gboolean function(/*const*/ GError* error, | |
237 GQuark domain, | |
238 gint code) g_error_matches; | |
239 | |
240 void function(GError** err, | |
241 GQuark domain, | |
242 gint code, | |
243 /*const*/ gchar* format, | |
244 ...) g_set_error; | |
245 | |
246 void function(GError** err, | |
247 GQuark domain, | |
248 gint code, | |
249 /*const*/ gchar* message) g_set_error_literal; | |
250 | |
251 void function(GError** dest, | |
252 GError* src) g_propagate_error; | |
253 | |
254 void function(GError** err) g_clear_error; | |
255 | |
256 void function(GError** err, | |
257 /*const*/ gchar* format, | |
258 ...) g_prefix_error; | |
259 | |
260 void function(GError** dest, | |
261 GError* src, | |
262 /*const*/ gchar* format, | |
263 ...) g_propagate_prefixed_error; | |
264 //}}} | |
265 | |
266 //{{{ gslist | |
267 struct GSList { | |
268 gpointer data; | |
269 GSList* next; | |
270 } | |
271 | |
272 GSList* function() g_slist_alloc; | |
273 void function(GSList* list) g_slist_free; | |
274 void function(GSList* list) g_slist_free_1; | |
275 alias g_slist_free_1 g_slist_free1; | |
276 GSList* function(GSList* list, gpointer data) g_slist_append; | |
277 GSList* function(GSList* list, gpointer data) g_slist_prepend; | |
278 GSList* function(GSList* list, gpointer data, gint position) g_slist_insert; | |
279 GSList* function(GSList* list, gpointer data, GCompareFunc func) g_slist_insert_sorted; | |
280 GSList* function( | |
281 GSList* list, | |
282 gpointer data, | |
283 GCompareDataFunc func, | |
284 gpointer user_data) g_slist_insert_sorted_with_data; | |
285 GSList* function(GSList* slist, GSList* sibling, gpointer data) g_slist_insert_before; | |
286 GSList* function(GSList* list1, GSList* list2) g_slist_concat; | |
287 GSList* function(GSList* list, gconstpointer data) g_slist_remove; | |
288 GSList* function(GSList* list, gconstpointer data) g_slist_remove_all; | |
289 GSList* function(GSList* list, GSList* link_) g_slist_remove_link; | |
290 GSList* function(GSList* list, GSList* link_) g_slist_delete_link; | |
291 GSList* function(GSList* list) g_slist_reverse; | |
292 GSList* function(GSList* list) g_slist_copy; | |
293 GSList* function(GSList* list, guint n) g_slist_nth; | |
294 GSList* function(GSList* list, gconstpointer data) g_slist_find; | |
295 GSList* function( | |
296 GSList* list, | |
297 gconstpointer data, | |
298 GCompareFunc func) g_slist_find_custom; | |
299 gint function(GSList* list, GSList* llink) g_slist_position; | |
300 gint function(GSList* list, gconstpointer data) g_slist_index; | |
301 GSList* function(GSList* list) g_slist_last; | |
302 guint function(GSList* list) g_slist_length; | |
303 void function(GSList* list, GFunc func, gpointer user_data) g_slist_foreach; | |
304 GSList* function(GSList* list, GCompareFunc compare_func) g_slist_sort; | |
305 GSList* function(GSList* list, | |
306 GCompareDataFunc compare_func, | |
307 gpointer user_data) g_slist_sort_with_data; | |
308 gpointer function(GSList* list, guint n) g_slist_nth_data; | |
309 | |
310 GSList* g_slist_next(GSList* slist) { | |
311 return slist ? slist.next : null; | |
312 } | |
313 //}}} | |
314 | |
315 //{{{ gmem | |
316 gpointer function(gsize n_bytes) g_malloc; | |
317 gpointer function(gsize n_bytes) g_malloc0; | |
318 gpointer function(gpointer mem, | |
319 gsize n_bytes) g_realloc; | |
320 void function(gpointer mem) g_free; | |
321 gpointer function(gsize n_bytes) g_try_malloc; | |
322 gpointer function(gsize n_bytes) g_try_malloc0; | |
323 gpointer function(gpointer mem, | |
324 gsize n_bytes) g_try_realloc; | |
325 //}}} | |
326 | |
327 static this() { | |
328 auto lib = SharedLib.load("libglib-2.0.so.0"); | |
329 | |
330 //{{{ gtype | |
331 //g_type_fundamental = cast(typeof(g_type_fundamental))lib.getSymbol("g_type_fundamental"); | |
332 //g_type_test_flags = cast(typeof(g_type_test_flags))lib.getSymbol("g_type_test_flags"); | |
333 //}}} | |
334 | |
335 //{{{ gquark | |
336 g_quark_try_string = cast(typeof(g_quark_try_string))lib.getSymbol("g_quark_try_string"); | |
337 g_quark_from_static_string = cast(typeof(g_quark_from_static_string))lib.getSymbol("g_quark_from_static_string"); | |
338 g_quark_from_string = cast(typeof(g_quark_from_string))lib.getSymbol("g_quark_from_string"); | |
339 g_quark_to_string = cast(typeof(g_quark_to_string))lib.getSymbol("g_quark_to_string"); | |
340 g_intern_string = cast(typeof(g_intern_string))lib.getSymbol("g_intern_string"); | |
341 g_intern_static_string = cast(typeof(g_intern_static_string))lib.getSymbol("g_intern_static_string"); | |
342 //}}} | |
343 | |
344 //{{{ gerror | |
345 g_error_new = cast(typeof(g_error_new))lib.getSymbol("g_error_new"); | |
346 g_error_new_literal = cast(typeof(g_error_new_literal))lib.getSymbol("g_error_new_literal"); | |
347 g_error_free = cast(typeof(g_error_free))lib.getSymbol("g_error_free"); | |
348 g_error_copy = cast(typeof(g_error_copy))lib.getSymbol("g_error_copy"); | |
349 g_error_matches = cast(typeof(g_error_matches))lib.getSymbol("g_error_matches"); | |
350 g_set_error = cast(typeof(g_set_error))lib.getSymbol("g_set_error"); | |
351 //g_set_error_literal = cast(typeof(g_set_error_literal))lib.getSymbol("g_set_error_literal"); | |
352 g_propagate_error = cast(typeof(g_propagate_error))lib.getSymbol("g_propagate_error"); | |
353 g_clear_error = cast(typeof(g_clear_error))lib.getSymbol("g_clear_error"); | |
354 //g_prefix_error = cast(typeof(g_prefix_error))lib.getSymbol("g_prefix_error"); | |
355 //g_propagate_prefixed_error = cast(typeof(g_propagate_prefixed_error))lib.getSymbol("g_propagate_prefixed_error"); | |
356 //}}} | |
357 | |
358 //{{{ gslist | |
359 g_slist_alloc = cast(typeof(g_slist_alloc))lib.getSymbol("g_slist_alloc"); | |
360 g_slist_free = cast(typeof(g_slist_free))lib.getSymbol("g_slist_free"); | |
361 g_slist_free_1 = cast(typeof(g_slist_free_1))lib.getSymbol("g_slist_free_1"); | |
362 g_slist_append = cast(typeof(g_slist_append))lib.getSymbol("g_slist_append"); | |
363 g_slist_prepend = cast(typeof(g_slist_prepend))lib.getSymbol("g_slist_prepend"); | |
364 g_slist_insert = cast(typeof(g_slist_insert))lib.getSymbol("g_slist_insert"); | |
365 g_slist_insert_sorted = cast(typeof(g_slist_insert_sorted))lib.getSymbol("g_slist_insert_sorted"); | |
366 g_slist_insert_sorted_with_data = cast(typeof(g_slist_insert_sorted_with_data))lib.getSymbol("g_slist_insert_sorted_with_data"); | |
367 g_slist_insert_before = cast(typeof(g_slist_insert_before))lib.getSymbol("g_slist_insert_before"); | |
368 g_slist_concat = cast(typeof(g_slist_concat))lib.getSymbol("g_slist_concat"); | |
369 g_slist_remove = cast(typeof(g_slist_remove))lib.getSymbol("g_slist_remove"); | |
370 g_slist_remove_all = cast(typeof(g_slist_remove_all))lib.getSymbol("g_slist_remove_all"); | |
371 g_slist_remove_link = cast(typeof(g_slist_remove_link))lib.getSymbol("g_slist_remove_link"); | |
372 g_slist_delete_link = cast(typeof(g_slist_delete_link))lib.getSymbol("g_slist_delete_link"); | |
373 g_slist_reverse = cast(typeof(g_slist_reverse))lib.getSymbol("g_slist_reverse"); | |
374 g_slist_copy = cast(typeof(g_slist_copy))lib.getSymbol("g_slist_copy"); | |
375 g_slist_nth = cast(typeof(g_slist_nth))lib.getSymbol("g_slist_nth"); | |
376 g_slist_find = cast(typeof(g_slist_find))lib.getSymbol("g_slist_find"); | |
377 g_slist_find_custom = cast(typeof(g_slist_find_custom))lib.getSymbol("g_slist_find_custom"); | |
378 g_slist_position = cast(typeof(g_slist_position))lib.getSymbol("g_slist_position"); | |
379 g_slist_index = cast(typeof(g_slist_index))lib.getSymbol("g_slist_index"); | |
380 g_slist_last = cast(typeof(g_slist_last))lib.getSymbol("g_slist_last"); | |
381 g_slist_length = cast(typeof(g_slist_length))lib.getSymbol("g_slist_length"); | |
382 g_slist_foreach = cast(typeof(g_slist_foreach))lib.getSymbol("g_slist_foreach"); | |
383 g_slist_sort = cast(typeof(g_slist_sort))lib.getSymbol("g_slist_sort"); | |
384 g_slist_sort_with_data = cast(typeof(g_slist_sort_with_data))lib.getSymbol("g_slist_sort_with_data"); | |
385 g_slist_nth_data = cast(typeof(g_slist_nth_data))lib.getSymbol("g_slist_nth_data"); | |
386 //}}} | |
387 | |
388 //{{{ gmem | |
389 g_malloc = cast(typeof(g_malloc))lib.getSymbol("g_malloc"); | |
390 g_malloc0 = cast(typeof(g_malloc0))lib.getSymbol("g_malloc0"); | |
391 g_realloc = cast(typeof(g_realloc))lib.getSymbol("g_realloc"); | |
392 g_free = cast(typeof(g_free))lib.getSymbol("g_free"); | |
393 g_try_malloc = cast(typeof(g_try_malloc))lib.getSymbol("g_try_malloc"); | |
394 g_try_malloc0 = cast(typeof(g_try_malloc0))lib.getSymbol("g_try_malloc0"); | |
395 g_try_realloc = cast(typeof(g_try_realloc))lib.getSymbol("g_try_realloc"); | |
396 //}}} | |
397 } |